@chenpu17/cc-gw 0.9.1 → 0.10.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/package.json +5 -5
- package/src/web/dist/assets/{About-BSEe89Db.js → About-BxrAYtQE.js} +1 -1
- package/src/web/dist/assets/{ApiKeys-BSd06Z1F.js → ApiKeys-DNQRKCib.js} +1 -1
- package/src/web/dist/assets/{ConfirmDialog-MHzJAg_R.js → ConfirmDialog-Bcxn6dph.js} +1 -1
- package/src/web/dist/assets/{Dashboard-BTnS3Joq.js → Dashboard-B6ICHOzw.js} +1 -1
- package/src/web/dist/assets/{Events-DbCJcwIJ.js → Events-C2uIO71I.js} +1 -1
- package/src/web/dist/assets/{Help-BsB7et-K.js → Help-DNYnXBdr.js} +1 -1
- package/src/web/dist/assets/{Login-C8phChBf.js → Login-BG51iO51.js} +1 -1
- package/src/web/dist/assets/Logs-DFsyxG6w.js +1 -0
- package/src/web/dist/assets/{ProvidersWorkbench-Bb3ZnLKq.js → ProvidersWorkbench-CQs_hU5D.js} +1 -1
- package/src/web/dist/assets/{Settings-DE727ml-.js → Settings-BxLEMKHc.js} +1 -1
- package/src/web/dist/assets/{Setup-DPWSztq9.js → Setup-xJZtt7MZ.js} +1 -1
- package/src/web/dist/assets/{apiKeys-Ysiv6YG4.js → apiKeys-CdpEo7b1.js} +1 -1
- package/src/web/dist/assets/app-yrdXegKB.js +61 -0
- package/src/web/dist/assets/{gateway-D48923x2.js → gateway-BGQ7-G-T.js} +1 -1
- package/src/web/dist/assets/{landing-CXAblwjd.js → landing-CYc---DE.js} +1 -1
- package/src/web/dist/assets/package-CR4pXT18.js +1 -0
- package/src/web/dist/assets/{shared-BzrM3juK.js → shared-Cj-4uVgO.js} +1 -1
- package/src/web/dist/assets/{useAppMutation-B4G9utID.js → useAppMutation-CaROpU2i.js} +1 -1
- package/src/web/dist/assets/useProviderForm-BDM7-9ut.js +1 -0
- package/src/web/dist/index.html +1 -1
- package/src/web/dist/landing.html +2 -2
- package/src/web/dist/assets/Logs-Cj6iucOs.js +0 -1
- package/src/web/dist/assets/app-ClWj0qTa.js +0 -61
- package/src/web/dist/assets/package-C1LS7ceb.js +0 -1
- package/src/web/dist/assets/useProviderForm-Bh-rUNZP.js +0 -1
|
@@ -0,0 +1 @@
|
|
|
1
|
+
import{r as w,j as s,$ as de}from"./vendor-CITafuNQ.js";import{u as ne}from"./query-DZF7K6hv.js";import{a as oe,c as ie,q as G,e as ce,i as V,d as O,B as A}from"./app-yrdXegKB.js";import{g as ue}from"./gateway-BGQ7-G-T.js";import{u as P}from"./i18n-PeX9kBVO.js";import{c as T}from"./global-CHsQhrWl.js";import{D as X}from"./disclosure-DtTSMZlG.js";import{L as M,I as C}from"./label-D10XnuKJ.js";import{S as me,a as pe,b as he,c as xe,d as L}from"./select-Csn9x4DW.js";import{S as Q}from"./switch-CgcoKdbt.js";import{B as fe}from"./badge-BYKFKxPI.js";const ze=["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"],qe=["gpt-4o-mini","gpt-4o","o4-mini","o4-large","gpt-5-codex"];function be(){return typeof crypto<"u"&&typeof crypto.randomUUID=="function"?crypto.randomUUID():Math.random().toString(36).slice(2,10)}function R(e,a){var t;return(t=e==null?void 0:e.customEndpoints)!=null&&t.length?e.customEndpoints:a}function B(e){return e?Object.entries(e).map(([a,t])=>({id:be(),source:a,target:t})):[]}function Ge(e,a){var r,n,p;if(!e)return{};const t={},o=e.endpointRouting??{};t.anthropic=B(((r=o.anthropic)==null?void 0:r.modelRoutes)??e.modelRoutes??{}),t.openai=B(((n=o.openai)==null?void 0:n.modelRoutes)??{});for(const u of R(e,a))(p=u.routing)!=null&&p.modelRoutes?t[u.id]=B(u.routing.modelRoutes):t[u.id]=[];return t}function ge(e,a,t){var n,p,u;const o=R(e,a).find(y=>y.id===t);if(o)return((n=o.routing)==null?void 0:n.modelRoutes)??{};const r=e.endpointRouting??{};return t==="anthropic"?((p=r.anthropic)==null?void 0:p.modelRoutes)??e.modelRoutes??{}:t==="openai"?((u=r.openai)==null?void 0:u.modelRoutes)??{}:{}}function F(e,a,t){var r,n,p;if(t==="anthropic"||t==="openai")return((n=(r=e.endpointRouting)==null?void 0:r[t])==null?void 0:n.defaults)??e.defaults;const o=R(e,a).find(u=>u.id===t);return((p=o==null?void 0:o.routing)==null?void 0:p.defaults)??{completion:null,reasoning:null,background:null,longContextThreshold:e.defaults.longContextThreshold}}function Qe(e,a){if(!e)return{};const t={anthropic:F(e,a,"anthropic"),openai:F(e,a,"openai")};for(const o of R(e,a))t[o.id]=F(e,a,o.id);return t}function ve(e){const a={};for(const t of e){const o=t.source.trim(),r=t.target.trim();o&&r&&(a[o]=r)}return a}function Je(e,a){return JSON.stringify(ve(e))!==JSON.stringify(a)}function Xe(e,a,t){var r,n,p;if(!a)return;if(e==="anthropic"||e==="openai")return(n=(r=a.endpointRouting)==null?void 0:r[e])==null?void 0:n.compatibility;const o=R(a,t).find(u=>u.id===e);return(p=o==null?void 0:o.routing)==null?void 0:p.compatibility}function Ye(e,a){var o,r;const t={anthropic:((o=e.routingPresets)==null?void 0:o.anthropic)??[],openai:((r=e.routingPresets)==null?void 0:r.openai)??[]};for(const n of R(e,a))t[n.id]=n.routingPresets??[];return t}function ye(e,a){const t=[{key:"providers",label:e("modelManagement.tabs.providers"),description:e("modelManagement.tabs.providersDesc"),isSystem:!0,canDelete:!1},{key:"anthropic",label:e("modelManagement.tabs.anthropic"),description:e("modelManagement.tabs.anthropicDesc"),isSystem:!0,canDelete:!1,protocols:["anthropic"]},{key:"openai",label:e("modelManagement.tabs.openai"),description:e("modelManagement.tabs.openaiDesc"),isSystem:!0,canDelete:!1,protocols:["openai-auto","openai-chat","openai-responses"]}],o=a.map(r=>{let n=e("modelManagement.tabs.customEndpoint"),p=[];if(r.paths&&r.paths.length>0)n=`${e("modelManagement.tabs.customEndpoint")}: ${r.paths.map(u=>`${u.path} (${u.protocol})`).join(", ")}`,p=[...new Set(r.paths.map(u=>u.protocol))];else if(r.path){const u=r.protocol||"anthropic";n=`${e("modelManagement.tabs.customEndpoint")}: ${r.path} (${u})`,p=[u]}return{key:r.id,label:r.label||r.id,description:n,isSystem:!1,canDelete:r.deletable!==!1,protocols:p}});return[...t,...o]}function We(e){return e.label&&e.label.trim().length>0?`${e.label} (${e.id})`:e.id}function je(e,a){if(!e)return!1;const[t]=e.split(":");return t===a||e===a}function Ne(e,a,t){if(!e)return[];const o=["anthropic","openai",...R(e,a).map(n=>n.id)],r=[];for(const n of o){const p=ge(e,a,n);for(const[u,y]of Object.entries(p))je(y,t)&&r.push({endpoint:n,source:u,target:y})}return r}function Ze(e,a,t){return Ne(e,a,t).length}function es(){var N;const{t:e}=P(),{pushToast:a}=oe(),t=ie(G.config.full(),ue.configRequest()),o=ne({queryKey:G.customEndpoints.all(),queryFn:ce.list,refetchInterval:1e4}),r=w.useMemo(()=>{var g;return((g=o.data)==null?void 0:g.endpoints)??[]},[(N=o.data)==null?void 0:N.endpoints]),n=w.useMemo(()=>ye(e,r),[r,e]),[p,u]=w.useState(null);return w.useEffect(()=>{t.data&&u(t.data)},[t.data]),w.useEffect(()=>{!t.isError||!t.error||a({title:e("providers.toast.loadFailure",{message:t.error.message}),variant:"error"})},[t.error,t.isError,a,e]),{t:e,pushToast:a,config:p,setConfig:u,configQuery:t,customEndpoints:r,customEndpointsQuery:o,tabs:n,ensureConfig:()=>p?!0:(a({title:e("settings.toast.missingConfig"),variant:"error"}),t.refetch(),!1)}}const ss={savePreset(e,a){return V(O.post(`/api/routing-presets/${e}`,{name:a}))},applyPreset(e,a){return V(O.post(`/api/routing-presets/${e}/apply`,{name:a}))},deletePreset(e,a){return V(O.delete(`/api/routing-presets/${e}/${encodeURIComponent(a)}`))},testProvider(e,a){return V(O.post(`/api/providers/${e}/test`,a??{}))}},we={complete:"border-primary bg-primary text-primary-foreground",current:"border-primary bg-card text-primary ring-2 ring-primary/20",error:"border-destructive bg-card text-destructive ring-2 ring-destructive/20",upcoming:"border-border bg-card text-muted-foreground"},Se={complete:"text-foreground",current:"text-foreground font-medium",error:"text-destructive font-medium",upcoming:"text-muted-foreground"};function rs({steps:e,current:a,onSelect:t,className:o}){return s.jsx("nav",{"aria-label":"steps",className:T("flex items-start",o),children:e.map((r,n)=>{const p=t&&(r.status==="complete"||r.status==="current"),u=n===e.length-1,y=r.status==="complete"?"bg-primary/40":"bg-border",N=s.jsx("span",{className:T("motion-surface flex h-7 w-7 shrink-0 items-center justify-center rounded-lg border text-xs font-semibold",we[r.status]),"aria-current":r.id===a?"step":void 0,children:r.status==="complete"?s.jsx(de,{className:"h-3.5 w-3.5","aria-hidden":!0}):n+1}),g=`stepnav-${r.id}-label`;return s.jsxs("div",{className:"flex flex-1 items-start",children:[s.jsxs("div",{className:"flex min-w-0 flex-col items-center gap-1.5",children:[p?s.jsx("button",{type:"button",onClick:()=>t==null?void 0:t(r.id),"aria-labelledby":g,className:"rounded-lg outline-none focus-visible:ring-2 focus-visible:ring-primary focus-visible:ring-offset-2 focus-visible:ring-offset-background motion-surface",children:N}):N,s.jsx("span",{id:g,className:T("text-center text-[11px] leading-tight",Se[r.status]),children:r.label})]}),u?null:s.jsx("span",{"aria-hidden":!0,className:T("mx-1.5 mt-3.5 h-px flex-1",y)})]},r.id)})})}function Me({result:e,className:a}){const{t}=P();return s.jsxs("div",{className:T("flex flex-wrap items-center gap-2 rounded-lg px-3 py-2 text-xs",e.ok?"bg-success-bg text-success":"bg-destructive/10 text-destructive",a),children:[s.jsx(fe,{variant:e.ok?"success":"destructive",className:"shrink-0",children:e.ok?t("workbench.testResult.success"):t("workbench.testResult.failure")}),e.status?s.jsx("span",{className:"shrink-0",children:t("workbench.testResult.status",{status:e.status})}):null,e.durationMs?s.jsx("span",{className:"shrink-0",children:t("workbench.testResult.duration",{duration:`${e.durationMs} ms`})}):null,e.message?s.jsx("span",{className:"min-w-0 truncate",title:e.message,children:e.message}):null]})}function D(){return typeof globalThis.crypto<"u"&&typeof globalThis.crypto.randomUUID=="function"?globalThis.crypto.randomUUID():Math.random().toString(36).slice(2,10)}function ke(){return{_key:D(),id:"",label:""}}function Ce(){return{_key:D(),name:"",value:""}}const K={openai:{baseUrl:"https://api.openai.com/v1"},deepseek:{baseUrl:"https://api.deepseek.com/v1"},huawei:{baseUrl:"https://api.modelarts-maas.com/v1"},kimi:{baseUrl:"https://api.moonshot.cn/v1"},anthropic:{baseUrl:"https://api.anthropic.com/v1"},custom:{}},Ue=[{value:"openai",label:"OpenAI"},{value:"deepseek",label:"DeepSeek"},{value:"huawei",label:"Huawei Cloud"},{value:"kimi",label:"Kimi"},{value:"anthropic",label:"Anthropic"},{value:"custom",label:"Custom"}],as=[{id:"basics",labelKey:"providers.drawer.steps.basics"},{id:"models",labelKey:"providers.drawer.steps.modelsVerify"}];function _(e){return e==="anthropic"?"authToken":"apiKey"}function Re(e,a,t){return t(a==="authToken"?"providers.drawer.fields.authModeAuthToken":a==="xAuthToken"?"providers.drawer.fields.authModeXAuthToken":e==="anthropic"?"providers.drawer.fields.authModeApiKey":"providers.drawer.fields.authModeProviderDefault")}function J(e){return e?{id:e.id,label:e.label??e.id,baseUrl:e.baseUrl,apiKey:e.apiKey??"",type:e.type??"custom",defaultModel:e.defaultModel??"",models:(e.models??[]).map(a=>({...a,_key:D()})),authMode:e.authMode??_(e.type??"custom"),nonStreamViaStream:e.nonStreamViaStream??!1,useAbsoluteUrl:e.useAbsoluteUrl??!1,extraHeaders:Object.entries(e.extraHeaders??{}).map(([a,t])=>({name:a,value:t,_key:D()}))}:{id:"",label:"",baseUrl:"",apiKey:"",type:"custom",defaultModel:"",models:[],authMode:_("custom"),nonStreamViaStream:!1,useAbsoluteUrl:!1,extraHeaders:[]}}function Te(e){return{_key:D(),id:e.id,label:e.label,nonStreamViaStream:e.nonStreamViaStream}}function ts({form:e,errors:a,isCreate:t,advancedOpen:o,onAdvancedOpenChange:r,idInputRef:n,onProviderIdChange:p,onFieldChange:u,onTypeChange:y,onAuthModeChange:N,onNonStreamViaStreamChange:g,onUseAbsoluteUrlChange:m,onAddHeader:E,onRemoveHeader:j,onHeaderChange:S}){const{t:i}=P();return s.jsxs("div",{className:"space-y-8",children:[s.jsxs("section",{className:"space-y-5","aria-labelledby":"provider-type-fields",children:[s.jsxs("div",{className:"space-y-1",children:[s.jsx("h3",{id:"provider-type-fields",className:"text-sm font-semibold",children:i("providers.drawer.sections.type")}),s.jsx("p",{className:"text-xs text-muted-foreground",children:i("providers.drawer.hints.type")})]}),s.jsx("div",{className:"grid gap-2 md:grid-cols-3",children:Ue.map(b=>{var k;const U=b.value===e.type;return s.jsxs("button",{type:"button",onClick:()=>y(b.value),className:T("rounded-2xl border px-4 py-3 text-left transition focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-ring focus-visible:ring-offset-2",U?"border-primary bg-primary/10 text-primary":"border-border bg-card text-foreground hover:border-primary/20 hover:bg-accent/50"),children:[s.jsx("div",{className:"text-sm font-semibold",children:b.label}),s.jsx("div",{className:"mt-1 text-xs text-muted-foreground",children:((k=K[b.value??"custom"])==null?void 0:k.baseUrl)??i("providers.drawer.hints.customProvider")})]},b.value??"custom")})})]}),s.jsxs("section",{className:"space-y-4","aria-labelledby":"provider-basic-info",children:[s.jsxs("div",{className:"space-y-1",children:[s.jsx("h3",{id:"provider-basic-info",className:"text-sm font-semibold",children:i("providers.drawer.sections.basic")}),s.jsx("p",{className:"text-xs text-muted-foreground",children:i("providers.drawer.hints.basic")})]}),s.jsxs("div",{className:"grid gap-4 md:grid-cols-2",children:[s.jsxs(M,{className:"flex flex-col gap-2 text-sm",children:[s.jsx("span",{className:"text-xs text-muted-foreground",children:i("providers.drawer.fields.id")}),s.jsx(C,{value:e.id,ref:n,onChange:b=>p(b.target.value),disabled:!t,placeholder:i("providers.drawer.fields.idPlaceholder"),"aria-invalid":!!a.id}),a.id?s.jsx("span",{className:"text-xs text-destructive",children:a.id}):null]}),s.jsxs(M,{className:"flex flex-col gap-2 text-sm",children:[s.jsx("span",{className:"text-xs text-muted-foreground",children:i("providers.drawer.fields.label")}),s.jsx(C,{value:e.label,onChange:b=>u("label")(b.target.value),placeholder:i("providers.drawer.fields.labelPlaceholder")})]})]}),s.jsxs(M,{className:"flex flex-col gap-2 text-sm",children:[s.jsx("span",{className:"text-xs text-muted-foreground",children:i("providers.drawer.fields.baseUrl")}),s.jsx(C,{value:e.baseUrl,onChange:b=>u("baseUrl")(b.target.value),placeholder:i("providers.drawer.fields.baseUrlPlaceholder"),"aria-invalid":!!a.baseUrl}),a.baseUrl?s.jsx("span",{className:"text-xs text-destructive",children:a.baseUrl}):null]})]}),s.jsxs("section",{className:"space-y-4","aria-labelledby":"provider-auth-fields",children:[s.jsxs("div",{className:"space-y-1",children:[s.jsx("h3",{id:"provider-auth-fields",className:"text-sm font-semibold",children:i("providers.drawer.sections.auth")}),s.jsx("p",{className:"text-xs text-muted-foreground",children:i("providers.drawer.hints.auth")})]}),s.jsxs(M,{className:"flex flex-col gap-2 text-sm",children:[s.jsx("span",{className:"text-xs text-muted-foreground",children:i("providers.drawer.fields.apiKey")}),s.jsx(C,{value:e.apiKey,onChange:b=>u("apiKey")(b.target.value),placeholder:i("providers.drawer.fields.apiKeyPlaceholder")})]}),s.jsxs("fieldset",{className:"grid gap-2 rounded-xl border border-transparent bg-card p-4 text-xs shadow-[var(--surface-shadow)]",children:[s.jsx("legend",{className:"px-1 text-muted-foreground",children:i("providers.drawer.fields.authMode")}),s.jsx("p",{className:"text-[11px] text-muted-foreground",children:i("providers.drawer.fields.authModeHint")}),s.jsxs("label",{className:"flex cursor-pointer items-start gap-3 rounded-xl border border-transparent px-3 py-2 transition hover:bg-accent focus-within:bg-accent",children:[s.jsx("input",{type:"radio",name:"provider-auth-mode",value:"apiKey",checked:e.authMode==="apiKey",onChange:()=>N("apiKey"),className:"mt-0.5 h-4 w-4 accent-primary"}),s.jsx("span",{children:Re(e.type,"apiKey",i)})]}),s.jsxs("label",{className:"flex cursor-pointer items-start gap-3 rounded-xl border border-transparent px-3 py-2 transition hover:bg-accent focus-within:bg-accent",children:[s.jsx("input",{type:"radio",name:"provider-auth-mode",value:"authToken",checked:e.authMode==="authToken",onChange:()=>N("authToken"),className:"mt-0.5 h-4 w-4 accent-primary"}),s.jsx("span",{children:i("providers.drawer.fields.authModeAuthToken")})]}),s.jsxs("label",{className:"flex cursor-pointer items-start gap-3 rounded-xl border border-transparent px-3 py-2 transition hover:bg-accent focus-within:bg-accent",children:[s.jsx("input",{type:"radio",name:"provider-auth-mode",value:"xAuthToken",checked:e.authMode==="xAuthToken",onChange:()=>N("xAuthToken"),className:"mt-0.5 h-4 w-4 accent-primary"}),s.jsx("span",{children:i("providers.drawer.fields.authModeXAuthToken")})]})]}),s.jsxs(X,{open:o,onOpenChange:r,summary:i("providers.drawer.fields.advancedOptions"),className:"rounded-xl border border-transparent bg-card shadow-[var(--surface-shadow)]",summaryClassName:"px-4 py-3 text-sm font-medium",contentClassName:"border-t border-border px-4 py-4",children:[s.jsxs("div",{className:"flex items-start justify-between gap-4",children:[s.jsxs("div",{className:"space-y-1",children:[s.jsx("p",{className:"text-sm font-medium",children:i("providers.drawer.fields.nonStreamViaStream")}),s.jsx("p",{className:"text-xs leading-relaxed text-muted-foreground",children:i("providers.drawer.fields.nonStreamViaStreamHint")})]}),s.jsx(Q,{checked:e.nonStreamViaStream,onCheckedChange:g,"aria-label":i("providers.drawer.fields.nonStreamViaStream")})]}),s.jsx("div",{className:"mt-4 border-t border-border pt-4",children:s.jsxs("div",{className:"flex items-start justify-between gap-4",children:[s.jsxs("div",{className:"space-y-1",children:[s.jsx("p",{className:"text-sm font-medium",children:i("providers.drawer.fields.useAbsoluteUrl")}),s.jsx("p",{className:"text-xs leading-relaxed text-muted-foreground",children:i("providers.drawer.fields.useAbsoluteUrlHint")})]}),s.jsx(Q,{checked:e.useAbsoluteUrl,onCheckedChange:m,"aria-label":i("providers.drawer.fields.useAbsoluteUrl")})]})}),s.jsxs("div",{className:"mt-4 border-t border-border pt-4",children:[s.jsxs("div",{className:"flex items-start justify-between gap-4",children:[s.jsxs("div",{className:"space-y-1",children:[s.jsx("p",{className:"text-sm font-medium",children:i("providers.drawer.fields.extraHeaders")}),s.jsx("p",{className:"text-xs leading-relaxed text-muted-foreground",children:i("providers.drawer.fields.extraHeadersHint")})]}),s.jsx(A,{type:"button",variant:"outline",size:"sm",onClick:E,className:"bg-card text-xs",children:i("providers.drawer.fields.addHeader")})]}),a.extraHeaders?s.jsx("p",{className:"mt-2 text-xs text-destructive",children:a.extraHeaders}):null,e.extraHeaders.length>0?s.jsx("div",{className:"mt-3 space-y-3",children:e.extraHeaders.map((b,U)=>s.jsxs("div",{className:"rounded-xl border border-transparent bg-secondary/40 p-3",children:[s.jsxs("div",{className:"grid gap-3 md:grid-cols-2",children:[s.jsxs(M,{className:"flex flex-col gap-1.5 text-sm",children:[s.jsx("span",{className:"text-xs text-muted-foreground",children:i("providers.drawer.fields.headerName")}),s.jsx(C,{value:b.name,onChange:k=>S(U,{name:k.target.value}),placeholder:i("providers.drawer.fields.headerNamePlaceholder")})]}),s.jsxs(M,{className:"flex flex-col gap-1.5 text-sm",children:[s.jsx("span",{className:"text-xs text-muted-foreground",children:i("providers.drawer.fields.headerValue")}),s.jsx(C,{value:b.value,onChange:k=>S(U,{value:k.target.value}),placeholder:i("providers.drawer.fields.headerValuePlaceholder")})]})]}),s.jsx("div",{className:"mt-2 flex justify-end",children:s.jsx(A,{type:"button",variant:"ghost",size:"sm",className:"h-auto px-2 text-destructive",onClick:()=>j(U),children:i("providers.drawer.fields.removeHeader")})})]},b._key))}):null]})]})]})]})}function ls({form:e,errors:a,advancedOpen:t,onAdvancedOpenChange:o,onModelIdChange:r,onModelChange:n,onAddModel:p,onRemoveModel:u,onModelNonStreamViaStreamChange:y,onSetDefaultModel:N,testVerification:g}){const{t:m}=P(),E=e.models.filter(j=>j.id.trim().length>0);return s.jsxs("div",{className:"space-y-8",children:[s.jsxs("section",{className:"space-y-4","aria-labelledby":"provider-model-fields",children:[s.jsxs("div",{className:"flex items-start justify-between gap-4",children:[s.jsxs("div",{className:"space-y-1",children:[s.jsx("h3",{id:"provider-model-fields",className:"text-sm font-semibold",children:m("providers.drawer.fields.models")}),s.jsx("p",{className:"text-xs text-muted-foreground",children:m("providers.drawer.modelsDescription")})]}),s.jsx(A,{type:"button",variant:"outline",size:"sm",onClick:p,className:"bg-card text-xs",children:m("providers.drawer.fields.addModel")})]}),a.models?s.jsx("p",{className:"text-xs text-destructive",children:a.models}):null,s.jsxs("div",{className:"space-y-4",children:[e.models.map((j,S)=>s.jsxs("div",{className:"rounded-xl border border-transparent bg-card p-4 shadow-[var(--surface-shadow)]",children:[s.jsx("div",{className:"grid gap-4 md:grid-cols-2",children:s.jsxs(M,{className:"flex flex-col gap-2 text-sm",children:[s.jsx("span",{className:"text-xs text-muted-foreground",children:m("providers.drawer.fields.modelId")}),s.jsx(C,{value:j.id,onChange:i=>r(S,i.target.value),placeholder:m("providers.drawer.fields.modelIdPlaceholder")})]})}),s.jsxs(X,{open:t,onOpenChange:o,summary:m("providers.drawer.fields.advancedOptions"),className:"mt-4 rounded-xl bg-secondary/50",summaryClassName:"px-3 py-2 text-xs font-medium",contentClassName:"space-y-4 px-3 py-3",children:[s.jsxs(M,{className:"flex flex-col gap-2 text-sm",children:[s.jsx("span",{className:"text-xs text-muted-foreground",children:m("providers.drawer.fields.modelLabel")}),s.jsx(C,{value:j.label??"",onChange:i=>n(S,{label:i.target.value}),placeholder:m("providers.drawer.fields.modelLabelPlaceholder")})]}),s.jsxs(M,{className:"flex flex-col gap-2 text-sm",children:[s.jsx("span",{className:"text-xs text-muted-foreground",children:m("providers.drawer.fields.modelNonStreamViaStream")}),s.jsxs(me,{value:j.nonStreamViaStream===void 0?"inherit":j.nonStreamViaStream?"enabled":"disabled",onValueChange:i=>y(S,i),children:[s.jsx(pe,{children:s.jsx(he,{})}),s.jsxs(xe,{children:[s.jsx(L,{value:"inherit",children:m("providers.drawer.fields.modelNonStreamViaStreamInherit")}),s.jsx(L,{value:"enabled",children:m("providers.drawer.fields.modelNonStreamViaStreamEnabled")}),s.jsx(L,{value:"disabled",children:m("providers.drawer.fields.modelNonStreamViaStreamDisabled")})]})]})]})]}),s.jsxs("div",{className:"mt-3 flex flex-wrap items-center justify-between gap-3 text-xs",children:[s.jsxs("label",{className:"flex items-center gap-2 text-muted-foreground",children:[s.jsx("input",{type:"radio",name:"defaultModel",value:j.id,"aria-label":m("providers.drawer.fields.setDefault"),checked:e.defaultModel===j.id,onChange:()=>N(j.id),disabled:j.id.trim().length===0,className:"h-4 w-4 accent-primary"}),m("providers.drawer.fields.setDefault")]}),s.jsx(A,{type:"button",variant:"ghost",size:"sm",className:"h-auto px-2 text-destructive",onClick:()=>u(S),disabled:e.models.length===0,children:m("providers.drawer.fields.removeModel")})]})]},j._key)),e.models.length===0?s.jsx("div",{className:"rounded-xl border border-warning/30 bg-warning-bg p-5",children:s.jsxs("div",{className:"space-y-2",children:[s.jsx("p",{className:"text-sm font-semibold text-warning",children:m("providers.drawer.noModelsTitle")}),s.jsx("p",{className:"text-xs leading-relaxed text-warning",children:m("providers.drawer.noModelsHint",{providerId:e.id||"provider-id"})}),s.jsxs("div",{className:"rounded-lg bg-secondary/50 p-2.5",children:[s.jsx("p",{className:"mb-1.5 text-xs font-medium text-foreground",children:m("providers.drawer.routeExample")}),s.jsxs("code",{className:"block rounded-lg border border-transparent bg-card px-2.5 py-1.5 font-mono text-xs text-foreground shadow-[var(--surface-shadow)]",children:['"claude-*": "',(e.id||"provider-id").trim()||"provider-id",':*"']})]})]})}):null]}),E.length>1?s.jsx("div",{className:"text-xs text-muted-foreground",children:m("providers.drawer.defaultHint",{model:e.defaultModel||m("providers.card.noDefault")})}):null]}),g?s.jsxs("section",{className:"space-y-3","aria-labelledby":"provider-verify-fields",children:[s.jsxs("div",{className:"space-y-1",children:[s.jsx("h3",{id:"provider-verify-fields",className:"text-sm font-semibold",children:m("workbench.drawer.verifyTitle")}),s.jsx("p",{className:"text-xs text-muted-foreground",children:m("workbench.drawer.verifyHint")})]}),g.available?s.jsxs("div",{className:"space-y-3 rounded-xl border border-transparent bg-card p-4 shadow-[var(--surface-shadow)]",children:[s.jsx(A,{type:"button",variant:"outline",size:"sm",onClick:g.onTest,disabled:g.testing,children:g.testing?m("common.actions.testingConnection"):m("workbench.drawer.verifyRun")}),g.result?s.jsx(Me,{result:g.result}):null]}):s.jsx("p",{className:"rounded-xl bg-secondary/50 px-4 py-3 text-xs text-muted-foreground",children:m("workbench.drawer.verifySaveFirst")})]}):null]})}const Ee=/^[!#$%&'*+\-.^_`|~0-9A-Za-z]+$/;function ds({mode:e,provider:a,existingProviderIds:t}){const{t:o}=P(),[r,n]=w.useState(()=>J(a)),[p,u]=w.useState({}),[y,N]=w.useState(e==="edit"),g=w.useRef(null),m=w.useCallback(()=>{n(J(a)),u({}),N(e==="edit")},[a,e]),E=l=>d=>{n(h=>({...h,[l]:d}))},j=l=>{n(d=>{const c=!y||d.label.trim().length===0||d.label===d.id?l:d.label;return{...d,id:l,label:c}})},S=l=>{n(d=>{var q;const c=K[l??"custom"]??K.custom,x=_(d.type),f=_(l),v=Object.values(K).map(H=>H.baseUrl).filter(H=>!!H),$=!d.baseUrl||v.includes(d.baseUrl),le=e==="create"&&(d.models.length===0||d.models.every(H=>H.id.trim().length===0)),I={...d,type:l,authMode:d.authMode===x?f:d.authMode};return c!=null&&c.baseUrl&&$&&(I.baseUrl=c.baseUrl),c!=null&&c.models&&le&&(I.models=c.models.map(Te),I.defaultModel=c.defaultModel??((q=c.models[0])==null?void 0:q.id)??""),I})},i=(l,d)=>{n(h=>{const c=[...h.models];return c[l]={...c[l],...d},{...h,models:c}})},b=(l,d)=>{n(h=>{const c=[...h.models],x=c[l];if(!x)return h;const f=!y||!x.label||x.label===x.id,v={...x,id:d,label:f?d:x.label};c[l]=v;const $=h.defaultModel===x.id?d:h.defaultModel;return{...h,models:c,defaultModel:$}})},U=l=>{n(d=>{if(l<0||l>=d.models.length)return d;const h=d.models.filter((x,f)=>f!==l);let c=d.defaultModel;return h.some(x=>x.id===c)||(c=""),{...d,models:h,defaultModel:c}})},k=()=>{n(l=>({...l,models:[...l.models,ke()]}))},Y=(l,d)=>{n(h=>{const c=[...h.extraHeaders];return c[l]={...c[l],...d},{...h,extraHeaders:c}})},W=()=>{n(l=>({...l,extraHeaders:[...l.extraHeaders,Ce()]}))},Z=l=>{n(d=>{if(l<0||l>=d.extraHeaders.length)return d;const h=d.extraHeaders.filter((c,x)=>x!==l);return{...d,extraHeaders:h}})},ee=l=>{n(d=>({...d,authMode:l}))},se=l=>{n(d=>({...d,nonStreamViaStream:l}))},re=l=>{n(d=>({...d,useAbsoluteUrl:l}))},ae=(l,d)=>{i(l,{nonStreamViaStream:d==="inherit"?void 0:d==="enabled"})},te=l=>{n(d=>({...d,defaultModel:l}))},z=()=>{const l={},d=r.id.trim(),h=r.baseUrl.trim();if(e==="create"&&(d.length===0?l.id=o("providers.drawer.errors.idRequired"):t.includes(d)&&(l.id=o("providers.drawer.errors.idDuplicate"))),e==="edit"&&d.length===0&&(l.id=o("providers.drawer.errors.idRequired")),h.length===0)l.baseUrl=o("providers.drawer.errors.baseUrlInvalid");else try{new URL(h)}catch{l.baseUrl=o("providers.drawer.errors.baseUrlInvalid")}if(r.models.length>0){const c=new Set;r.models.some(f=>{const v=f.id.trim();return v.length===0||c.has(v)?!0:(c.add(v),!1)})&&(l.models=o("providers.drawer.errors.modelInvalid"))}if(r.defaultModel&&!r.models.some(c=>c.id===r.defaultModel)&&(l.models=o("providers.drawer.errors.defaultInvalid")),r.extraHeaders.length>0){const c=new Set;for(const x of r.extraHeaders){const f=x.name.trim();if(f.length===0)continue;if(!Ee.test(f)){l.extraHeaders=o("providers.drawer.errors.headerNameInvalid");break}const v=f.toLowerCase();if(c.has(v)){l.extraHeaders=o("providers.drawer.errors.headerNameDuplicate");break}c.add(v)}}return u(l),l};return{form:r,errors:p,advancedOpen:y,setAdvancedOpen:N,providerIdRef:g,isCreate:e==="create",resetForm:m,validate:()=>Object.keys(z()).length===0,validateErrors:z,serialize:()=>{const l=r.models.map(f=>{var v;return{id:f.id.trim(),label:(v=f.label)!=null&&v.trim()?f.label.trim():void 0,nonStreamViaStream:f.nonStreamViaStream}}).filter(f=>f.id.length>0),d={};for(const f of r.extraHeaders){const v=f.name.trim();v.length>0&&(d[v]=f.value)}const h=Object.keys(d).length>0,c=r.authMode==="apiKey"&&r.type!=="anthropic"?void 0:r.authMode,x={id:r.id.trim(),label:r.label.trim()||r.id.trim(),baseUrl:r.baseUrl.trim(),apiKey:r.apiKey.trim()||void 0,type:r.type??"custom",defaultModel:r.defaultModel||void 0,models:l.length>0?l:void 0,extraHeaders:h?d:void 0,authMode:c};return r.nonStreamViaStream&&(x.nonStreamViaStream=!0),r.useAbsoluteUrl&&(x.useAbsoluteUrl=!0),x},handleFieldChange:E,handleProviderIdChange:j,handleTypeChange:S,handleModelChange:i,handleModelIdChange:b,handleRemoveModel:U,handleAddModel:k,handleHeaderChange:Y,handleAddHeader:W,handleRemoveHeader:Z,handleAuthModeChange:ee,handleProviderNonStreamViaStreamChange:se,handleUseAbsoluteUrlChange:re,handleModelNonStreamViaStreamChange:ae,handleSetDefaultModel:te}}export{ts as B,ze as C,ls as M,qe as O,Ue as P,rs as S,Me as T,Je as a,Qe as b,F as c,Ge as d,Ye as e,be as f,ge as g,We as h,Re as i,as as j,Ne as k,Xe as l,ss as m,es as n,Ze as o,je as r,ds as u};
|
package/src/web/dist/index.html
CHANGED
|
@@ -14,7 +14,7 @@
|
|
|
14
14
|
rel="stylesheet"
|
|
15
15
|
/>
|
|
16
16
|
<title>cc-gw 控制台</title>
|
|
17
|
-
<script type="module" crossorigin src="/assets/app-
|
|
17
|
+
<script type="module" crossorigin src="/assets/app-yrdXegKB.js"></script>
|
|
18
18
|
<link rel="modulepreload" crossorigin href="/assets/vendor-CITafuNQ.js">
|
|
19
19
|
<link rel="modulepreload" crossorigin href="/assets/global-CHsQhrWl.js">
|
|
20
20
|
<link rel="modulepreload" crossorigin href="/assets/query-DZF7K6hv.js">
|
|
@@ -42,11 +42,11 @@
|
|
|
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-
|
|
45
|
+
<script type="module" crossorigin src="/assets/landing-CYc---DE.js"></script>
|
|
46
46
|
<link rel="modulepreload" crossorigin href="/assets/vendor-CITafuNQ.js">
|
|
47
47
|
<link rel="modulepreload" crossorigin href="/assets/global-CHsQhrWl.js">
|
|
48
48
|
<link rel="modulepreload" crossorigin href="/assets/clipboard-BnAnBk_-.js">
|
|
49
|
-
<link rel="modulepreload" crossorigin href="/assets/package-
|
|
49
|
+
<link rel="modulepreload" crossorigin href="/assets/package-CR4pXT18.js">
|
|
50
50
|
<link rel="stylesheet" crossorigin href="/assets/global-B_aXL20T.css">
|
|
51
51
|
</head>
|
|
52
52
|
<body class="bg-slate-50 text-slate-900">
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
import{r as x,j as e,o as is,ar as ds,aj as cs,as as ms,ak as Re,at as De,aq as us,au as ps,Z as xs,T as gs,P as fs}from"./vendor-CITafuNQ.js";import{P as hs}from"./PageToolbar-BdMtFJ0X.js";import{c as E}from"./global-CHsQhrWl.js";import{B as R,d as ys,a as ge,c as G,q as H,s as q,t as bs,b as $}from"./app-ClWj0qTa.js";import{B as V}from"./badge-BYKFKxPI.js";import{C as Fe,a as Te}from"./card-BzBD4ugM.js";import{L as B,I as pe}from"./label-D10XnuKJ.js";import{S as te,a as le,b as ae,c as re,d as I}from"./select-Csn9x4DW.js";import{u as O}from"./i18n-PeX9kBVO.js";import{D as js,A as vs,a as Ns,b as ws,c as ks,d as Ss}from"./DialogShell-Dadn4IyM.js";import{P as Cs,a as X}from"./PageState-BfMFsTrq.js";import{T as Ls,a as _s,b as Es,c as Rs}from"./tabs-BkwWF2Pt.js";import{c as Ds}from"./clipboard-BnAnBk_-.js";import{a as Fs,g as fe,b as Ke,f as A,c as he,d as Ts,e as M,h as Me,i as Pe,j as Ks,T as Ms}from"./utils-CERcr-xC.js";import{P as Ps,a as qs,b as zs}from"./popover-CVazrITd.js";import{S as As}from"./segmented-control-BDDSq6CX.js";import{L as qe}from"./router-BoBrmro7.js";import{a as Os}from"./query-DZF7K6hv.js";import{g as Le}from"./gateway-D48923x2.js";import"./radix-Bux_1C5J.js";function Is({apiKeys:s,selected:l,onChange:p,disabled:a,className:o}){const{t}=O(),i=x.useId(),[y,b]=x.useState(!1),[d,v]=x.useState(null),u=x.useRef(null),N=x.useRef(null),f=x.useRef(null),w=()=>{const g=N.current;if(!g)return;const j=g.getBoundingClientRect(),k=Math.max(j.width,256),n=window.innerWidth-12;v({left:Math.min(j.left,n-k),top:j.bottom+8,width:k})};x.useEffect(()=>{if(!y)return;const g=k=>{var C,D;const n=k.target;!((C=u.current)!=null&&C.contains(n))&&!((D=f.current)!=null&&D.contains(n))&&b(!1)},j=k=>{var n;k.key==="Escape"&&(b(!1),(n=N.current)==null||n.focus())};return window.addEventListener("mousedown",g),window.addEventListener("keydown",j),()=>{window.removeEventListener("mousedown",g),window.removeEventListener("keydown",j)}},[y]),x.useEffect(()=>{if(y)return w(),window.addEventListener("resize",w),window.addEventListener("scroll",w,!0),()=>{window.removeEventListener("resize",w),window.removeEventListener("scroll",w,!0)}},[y]);const r=x.useMemo(()=>{if(l.length===0)return[];const g=new Map;for(const j of s)g.set(j.id,j);return l.map(j=>{const k=g.get(j);return k?k.isWildcard?t("apiKeys.wildcard"):k.name:null}).filter(j=>!!j)},[s,l,t]),h=l.length===0?t("logs.filters.apiKeyAll"):t("logs.filters.apiKeySelected",{count:l.length}),L=g=>{l.includes(g)?p(l.filter(j=>j!==g)):p([...l,g])};return e.jsxs("div",{className:E("relative space-y-2",o),ref:u,children:[e.jsx(B,{htmlFor:i,children:t("logs.filters.apiKey")}),e.jsxs("button",{ref:N,id:i,type:"button",onClick:()=>{w(),b(g=>!g)},disabled:a||s.length===0,title:t("logs.filters.apiKeyHint"),className:E("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",l.length>0&&"border-primary",y&&"ring-2 ring-ring ring-offset-2"),children:[e.jsxs("span",{className:"truncate",children:[h,r.length>0&&e.jsx("span",{className:"ml-1 text-xs text-muted-foreground",children:r.join(", ")})]}),e.jsx("svg",{className:E("h-4 w-4 opacity-50 transition-transform",y&&"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"})})]}),y&&d&&is.createPortal(e.jsxs("div",{ref:f,className:"fixed z-50 rounded-lg border bg-popover p-2 shadow-[var(--surface-shadow-lg)]",style:d,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:h}),e.jsx("button",{type:"button",onClick:()=>p([]),disabled:l.length===0,className:"text-primary hover:underline disabled:opacity-40",children:t("common.actions.reset")})]}),e.jsxs("div",{className:"max-h-56 overflow-y-auto py-2",children:[s.map(g=>{const j=g.isWildcard?t("apiKeys.wildcard"):g.name,k=l.includes(g.id);return e.jsxs("label",{className:E("flex cursor-pointer items-center gap-3 rounded-xl px-3 py-2 text-sm transition hover:bg-primary/5",k&&"bg-primary/10 text-primary"),children:[e.jsx("input",{type:"checkbox",className:"h-4 w-4 rounded border-border",checked:k,onChange:()=>L(g.id)}),e.jsx("span",{className:"truncate",children:j})]},g.id)}),s.length===0&&e.jsx("p",{className:"px-2 py-2 text-xs text-muted-foreground",children:t("logs.filters.apiKeyAll")})]})]}),document.body)]})}function $s(s){const{t:l}=O(),{activeFilters:p,filtersExpanded:a,setFiltersExpanded:o,handleResetFilters:t,activeQuickView:i,applyQuickView:y,providerFilter:b,setProviderFilter:d,endpointFilter:v,setEndpointFilter:u,selectedApiKeys:N,setSelectedApiKeys:f,modelFilter:w,setModelFilter:r,statusFilter:h,setStatusFilter:L,fromDate:g,setFromDate:j,toDate:k,setToDate:n,providerOptions:C,apiKeys:D,apiKeysLoading:F,customEndpoints:_}=s;return e.jsx(Fe,{"data-testid":"logs-filters-card",className:"overflow-hidden",children:e.jsxs(Te,{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:l("logs.filtersTitle")}),p.length>0&&e.jsx(V,{variant:"outline",className:"rounded-full border-transparent bg-primary/10 px-2.5 py-0.5 text-[11px] font-semibold text-primary",children:l("common.filters.activeCount",{count:p.length})})]}),e.jsx("p",{className:"text-xs text-muted-foreground",children:l("logs.filtersDescription")})]}),e.jsxs("div",{className:"flex items-center gap-1.5",children:[p.length>0&&e.jsx(R,{variant:"ghost",size:"sm",onClick:t,className:"h-8 rounded-full px-3 text-xs",children:l("common.actions.reset")}),e.jsx(R,{variant:"ghost",size:"sm",onClick:()=>o(c=>!c),className:"h-8 rounded-full px-3 text-xs",children:a?e.jsxs(e.Fragment,{children:[l("common.filters.collapse"),e.jsx(ds,{className:"ml-1 h-4 w-4"})]}):e.jsxs(e.Fragment,{children:[l("common.filters.expand"),e.jsx(cs,{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-lg bg-secondary px-3 py-2",children:p.length>0?e.jsx("div",{className:"flex flex-wrap items-center gap-2",children:p.map(c=>e.jsxs(V,{variant:"outline",role:"button",tabIndex:0,className:"flex cursor-pointer items-center gap-1 rounded-full border border-border bg-card px-2.5 py-1 text-[11px] font-semibold text-foreground/90 transition hover:bg-secondary",onClick:c.onRemove,onKeyDown:z=>{(z.key==="Enter"||z.key===" ")&&(z.preventDefault(),c.onRemove())},children:[c.label,e.jsx(ms,{className:"h-3 w-3","aria-hidden":"true"})]},c.key))}):e.jsx("span",{className:"text-xs text-muted-foreground",children:l("common.filters.allRequests")})}),e.jsxs("div",{className:"flex flex-wrap items-center gap-1.5 lg:justify-end",children:[e.jsx(xe,{label:l("logs.filters.apiKey"),value:N.length.toString()}),e.jsx(xe,{label:l("logs.filters.provider"),value:b==="all"?"0":"1"}),e.jsx(xe,{label:l("logs.filters.endpoint"),value:v==="all"?"0":"1"})]})]}),e.jsx("div",{className:"flex flex-wrap items-center gap-1.5 rounded-lg bg-secondary px-2 py-1.5",children:["all","errors","today","anthropic","openai"].map(c=>e.jsx(R,{variant:"ghost",size:"sm",className:E("h-7 rounded-full px-3 text-[11px] font-semibold transition-colors",i===c?"bg-card text-foreground shadow-[var(--surface-shadow)]":"text-muted-foreground"),onClick:()=>y(c),children:l(`logs.quickViews.${c}`)},c))})]}),a&&e.jsxs("div",{className:"mt-3 grid gap-3 rounded-xl bg-secondary 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(B,{children:l("logs.filters.provider")}),e.jsxs(te,{value:b,onValueChange:d,children:[e.jsx(le,{children:e.jsx(ae,{})}),e.jsxs(re,{children:[e.jsx(I,{value:"all",children:l("logs.filters.providerAll")}),C.map(c=>e.jsx(I,{value:c.id,children:c.label??c.id},c.id))]})]})]}),e.jsxs("div",{className:"space-y-2",children:[e.jsx(B,{children:l("logs.filters.endpoint")}),e.jsxs(te,{value:v,onValueChange:u,children:[e.jsx(le,{children:e.jsx(ae,{})}),e.jsxs(re,{children:[e.jsx(I,{value:"all",children:l("logs.filters.endpointAll")}),e.jsx(I,{value:"anthropic",children:l("logs.filters.endpointAnthropic")}),e.jsx(I,{value:"openai",children:l("logs.filters.endpointOpenAI")}),_==null?void 0:_.map(c=>e.jsx(I,{value:c.id,children:c.label||c.id},c.id))]})]})]}),e.jsx(Is,{className:"md:col-span-2",apiKeys:D,selected:N,disabled:F,onChange:f}),e.jsxs("div",{className:"space-y-2",children:[e.jsx(B,{children:l("logs.filters.modelId")}),e.jsx(pe,{value:w,onChange:c=>r(c.target.value),placeholder:l("logs.filters.modelPlaceholder")})]}),e.jsxs("div",{className:"space-y-2",children:[e.jsx(B,{children:l("logs.filters.status")}),e.jsxs(te,{value:h,onValueChange:c=>L(c),children:[e.jsx(le,{children:e.jsx(ae,{})}),e.jsxs(re,{children:[e.jsx(I,{value:"all",children:l("logs.filters.statusAll")}),e.jsx(I,{value:"success",children:l("logs.filters.statusSuccess")}),e.jsx(I,{value:"error",children:l("logs.filters.statusError")})]})]})]}),e.jsxs("div",{className:"space-y-2",children:[e.jsx(B,{children:l("logs.filters.startDate")}),e.jsx(pe,{type:"date",value:g,onChange:c=>j(c.target.value)})]}),e.jsxs("div",{className:"space-y-2",children:[e.jsx(B,{children:l("logs.filters.endDate")}),e.jsx(pe,{type:"date",value:k,onChange:c=>n(c.target.value)})]})]})]})})}function xe({label:s,value:l}){return e.jsxs("div",{className:"inline-flex items-center gap-1.5 rounded-full border border-border/60 bg-card px-2.5 py-1 text-[11px] text-muted-foreground",children:[e.jsx("span",{children:s}),e.jsx("span",{className:"metric-number font-semibold text-foreground",children:l})]})}const ye={listRequest(s){return{url:"/api/logs",method:"GET",params:s}},detailRequest(s){return{url:s===null?"":`/api/logs/${s}`,method:"GET"}},async exportArchive(s,l){const p=await ys.post("/api/logs/export",s,{responseType:"blob",timeout:l});return new Blob([p.data],{type:"application/zip"})}};function ze({apiKeyMap:s,logId:l,open:p,providerLabelMap:a}){var w;const{t:o}=O(),{pushToast:t}=ge(),i=G(H.logs.detail(l),ye.detailRequest(l),{enabled:p&&l!==null,staleTime:3e4,gcTime:15e3,placeholderData:void 0});x.useEffect(()=>{!i.isError||!i.error||t({title:o("logs.detail.loadError"),description:i.error.message,variant:"error"})},[i.error,i.isError,t,o]);const y=x.useCallback(async(r,h,L)=>{if(!h){t({title:o("logs.detail.copy.empty",{label:r}),variant:"info"});return}try{await Ds(h),t({title:o(L),variant:"success"})}catch(g){t({title:o("logs.detail.copy.failure"),description:g instanceof Error?g.message:o("logs.detail.copy.failureFallback"),variant:"error"})}},[t,o]),b=x.useCallback((r,h)=>{if(!h){t({title:o("logs.detail.copy.empty",{label:r}),variant:"info"});return}const L=new Blob([h],{type:"application/json;charset=utf-8"}),g=URL.createObjectURL(L),j=document.createElement("a"),k=new Date().toISOString().replace(/[:.]/g,"-"),n=r.trim().toLowerCase().replace(/[^a-z0-9\u4e00-\u9fa5]+/gi,"-").replace(/^-+|-+$/g,"")||"payload";j.href=g,j.download=`cc-gw-log-${l??"payload"}-${n}-${k}.json`,document.body.appendChild(j),j.click(),document.body.removeChild(j),URL.revokeObjectURL(g)},[l,t,o]),d=i.data,v=d?a.get(d.provider)??d.provider:"",u=d&&d.api_key_id!=null?s.get(d.api_key_id):void 0,N=d?Fs(d,o):null,f=d?fe(d,o):null;return{apiKeyMeta:u,errorSourceMeta:N,errorMessage:i.isError?((w=i.error)==null?void 0:w.message)??null:null,handleCopy:y,handleDownloadPayload:b,isError:i.isError,isPending:i.isPending,providerLabel:v,refetch:i.refetch,record:d,statusMeta:f}}function Qs({open:s,logId:l,onClose:p,providerLabelMap:a,apiKeyMap:o}){var g,j,k;const{t}=O(),{apiKeyMeta:i,errorSourceMeta:y,errorMessage:b,handleCopy:d,handleDownloadPayload:v,isError:u,isPending:N,providerLabel:f,refetch:w,record:r,statusMeta:h}=ze({apiKeyMap:o,logId:l,open:s,providerLabelMap:a}),L=x.useMemo(()=>{var C,D,F,_;return r?[{key:"client-request",title:t("logs.detail.payload.clientRequest"),value:((C=r.payload)==null?void 0:C.client_request)??null,emptyLabel:t("logs.detail.payload.emptyRequest"),copyToast:"logs.detail.copy.requestSuccess"},...(D=r.payload)!=null&&D.upstream_request?[{key:"upstream-request",title:t("logs.detail.payload.upstreamRequest"),value:r.payload.upstream_request,emptyLabel:t("logs.detail.payload.emptyRequest"),copyToast:"logs.detail.copy.requestSuccess"}]:[],...(F=r.payload)!=null&&F.upstream_response?[{key:"upstream-response",title:t("logs.detail.payload.upstreamResponse"),value:r.payload.upstream_response,emptyLabel:t("logs.detail.payload.emptyResponse"),copyToast:"logs.detail.copy.responseSuccess"}]:[],{key:"client-response",title:t("logs.detail.payload.clientResponse"),value:((_=r.payload)==null?void 0:_.client_response)??null,emptyLabel:t("logs.detail.payload.emptyResponse"),copyToast:"logs.detail.copy.responseSuccess"}].map(c=>({...c,display:Ke(c.value,c.emptyLabel)})):[]},[r,t]);return e.jsx(js,{open:s,onOpenChange:n=>{n||p()},children:e.jsxs(vs,{className:"w-[min(96vw,1200px)] max-w-[1200px]",children:[e.jsxs(Ns,{className:"pr-14",children:[e.jsx(ws,{children:t("logs.detail.title")}),e.jsx(ks,{children:r?t("logs.detail.id",{id:r.id}):t("logs.detail.loadError")})]}),e.jsx(Ss,{className:"max-h-[78vh]",children:N?e.jsx(Cs,{compact:!0,className:"min-h-[240px]",label:t("common.loading")}):u?e.jsx(X,{compact:!0,className:"min-h-[240px]",tone:"danger",title:t("logs.detail.loadError"),description:b??t("common.unknownError"),action:e.jsx(R,{variant:"outline",onClick:()=>void w(),children:t("common.actions.refresh")})}):r?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:t("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:t("logs.detail.summary.route",{from:r.client_model??t("logs.detail.info.noRequestedModel"),to:r.model})}),e.jsx("span",{className:"text-muted-foreground",children:t("logs.detail.summary.latency",{value:A(r.latency_ms,t("common.units.ms"))})}),r.ttft_ms!==null?e.jsxs("span",{className:"text-muted-foreground",children:["TTFT: ",A(r.ttft_ms,t("common.units.ms"))]}):null]})]}),e.jsxs("div",{className:"flex flex-wrap items-center gap-2",children:[e.jsx(V,{variant:h==null?void 0:h.variant,children:(h==null?void 0:h.label)??"-"}),e.jsx(V,{variant:"outline",children:r.stream?t("logs.stream.streaming"):t("logs.stream.single")})]})]}),e.jsxs("div",{className:"grid gap-3 md:grid-cols-5",children:[e.jsx(Q,{label:t("logs.detail.info.latency"),value:A(r.latency_ms,t("common.units.ms"))}),e.jsx(Q,{label:t("logs.detail.info.ttft"),value:A(r.ttft_ms,t("common.units.ms"))}),e.jsx(Q,{label:t("logs.detail.info.tpot"),value:A(r.tpot_ms,t("common.units.msPerToken"))}),e.jsx(Q,{label:t("logs.detail.info.status"),value:(h==null?void 0:h.label)??"-"}),e.jsx(Q,{label:t("logs.detail.info.errorSource"),value:(y==null?void 0:y.label)??"-"})]}),e.jsxs("dl",{className:"grid gap-x-4 gap-y-3 md:grid-cols-2 xl:grid-cols-4",children:[e.jsx(K,{label:t("logs.detail.info.time"),value:he(r.timestamp)}),e.jsx(K,{label:t("logs.detail.info.sessionId"),value:r.session_id??"-"}),e.jsx(K,{label:t("logs.detail.info.endpoint"),value:r.endpoint||"-"}),e.jsx(K,{label:t("logs.detail.info.provider"),value:f}),e.jsx(K,{label:t("logs.detail.info.requestedModel"),value:r.client_model??t("logs.detail.info.noRequestedModel")}),e.jsx(K,{label:t("logs.detail.info.model"),value:r.model}),e.jsx(K,{label:t("logs.detail.info.stream"),value:Ts(r.stream)}),e.jsx(K,{label:t("logs.detail.info.status"),value:(h==null?void 0:h.label)??"-"}),e.jsx(K,{label:t("logs.detail.info.errorSource"),value:(y==null?void 0:y.label)??"-"})]}),e.jsxs("div",{className:"grid gap-3 sm:grid-cols-2 xl:grid-cols-4",children:[e.jsx(Q,{label:t("logs.detail.info.inputTokens"),value:M(r.input_tokens)}),e.jsx(Q,{label:t("logs.detail.info.cacheReadTokens"),value:M(r.cache_read_tokens)}),e.jsx(Q,{label:t("logs.detail.info.cacheCreationTokens"),value:M(r.cache_creation_tokens)}),e.jsx(Q,{label:t("logs.detail.info.outputTokens"),value:M(r.output_tokens)})]}),r.error?e.jsxs("div",{className:"space-y-1",children:[e.jsx("p",{className:"text-xs text-muted-foreground",children:t("logs.detail.info.error")}),e.jsx("p",{className:"rounded-xl border border-destructive/50 bg-destructive/10 p-3 text-xs text-destructive",children:r.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:t("logs.detail.apiKey.title")}),e.jsxs("dl",{className:"grid gap-x-4 gap-y-3 sm:grid-cols-2",children:[e.jsx(K,{label:t("logs.detail.apiKey.name"),value:r.api_key_id==null&&!r.api_key_name?t("logs.detail.apiKey.missing"):i!=null&&i.isWildcard?t("apiKeys.wildcard"):(i==null?void 0:i.name)??r.api_key_name??t("logs.detail.apiKey.missing")}),e.jsx(K,{label:t("logs.detail.apiKey.identifier"),value:r.api_key_id??t("common.noData")}),e.jsx(K,{label:t("logs.detail.apiKey.masked"),value:i!=null&&i.isWildcard?t("apiKeys.wildcard"):(i==null?void 0:i.maskedKey)??r.api_key_name??t("logs.detail.apiKey.maskedUnavailable")}),e.jsx(K,{label:t("logs.detail.apiKey.lastUsed"),value:i!=null&&i.lastUsedAt?new Date(i.lastUsedAt).toLocaleString():t("common.noData")})]}),e.jsxs("div",{className:"rounded-lg border bg-secondary p-3 text-xs",children:[e.jsx("p",{className:"font-medium",children:t("logs.detail.apiKey.rawMasked")}),e.jsx("p",{className:"mt-1 break-all font-mono",children:r.api_key_value_available?r.api_key_value_masked??t("logs.detail.apiKey.rawUnavailable"):t("logs.detail.apiKey.rawUnavailable")}),e.jsx("p",{className:"mt-2 text-[11px] text-muted-foreground",children:t("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:t("logs.detail.payload.title")}),e.jsx("p",{className:"text-xs text-muted-foreground",children:(g=r.payload)!=null&&g.upstream_request||(j=r.payload)!=null&&j.upstream_response?t("logs.detail.payload.helperWithUpstream"):t("logs.detail.payload.helperClientOnly")})]}),e.jsxs(Ls,{defaultValue:(k=L[0])==null?void 0:k.key,children:[e.jsx(_s,{className:"w-full justify-start overflow-x-auto",children:L.map(n=>e.jsx(Es,{value:n.key,children:n.title},n.key))}),L.map(n=>e.jsx(Rs,{value:n.key,children:e.jsx(Vs,{title:n.title,display:n.display,onCopy:()=>d(n.title,n.value,n.copyToast),onDownload:()=>v(n.title,n.value),panelKey:n.key,t})},n.key))]})]})]})]}):e.jsx(X,{compact:!0,className:"min-h-[240px]",title:t("logs.detail.loadError"),description:t("common.noData")})})]})})}function Q({label:s,value:l}){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:s}),e.jsx("p",{className:"mt-2 break-all text-sm font-semibold leading-6",children:l})]})}function K({label:s,value:l}){return e.jsxs("div",{className:"min-w-0 space-y-1",children:[e.jsx("dt",{className:"text-xs text-muted-foreground",children:s}),e.jsx("dd",{className:"min-w-0 break-all whitespace-pre-wrap text-sm font-medium leading-6 text-foreground",children:l??"-"})]})}function Vs({display:s,onCopy:l,onDownload:p,panelKey:a,title:o,t}){return e.jsxs("div",{className:"space-y-3 rounded-lg border bg-secondary/40 p-4","data-testid":`log-payload-${a}`,children:[e.jsxs("div",{className:"flex flex-wrap items-center justify-between gap-3",children:[e.jsx("h4",{className:"text-xs font-semibold uppercase tracking-wide text-muted-foreground",children:o}),e.jsxs("div",{className:"flex items-center gap-2",children:[e.jsxs(R,{variant:"outline",size:"sm",onClick:l,children:[e.jsx(Re,{className:"mr-2 h-3.5 w-3.5"}),t("common.actions.copy")]}),e.jsxs(R,{variant:"outline",size:"sm",onClick:p,children:[e.jsx(De,{className:"mr-2 h-3.5 w-3.5"}),t("common.actions.download")]})]})]}),s.isTruncated?e.jsx("p",{className:"rounded-lg border border-warning/30 bg-warning-bg px-3 py-2 text-xs text-warning",children:t("logs.detail.payload.truncated",{shown:s.displayedLength.toLocaleString(),total:s.originalLength.toLocaleString()})}):null,e.jsx("pre",{className:"max-h-72 overflow-auto whitespace-pre rounded-lg border bg-secondary p-3 text-xs",children:s.text})]})}const Z=[20,50,100],J=["endpoint","provider","requestedModel","routedModel","apiKey","tokens","duration","status","error"],oe=["endpoint","provider","requestedModel","routedModel","apiKey","tokens","duration","status","error"];function Us(){return typeof window>"u"?"comfortable":window.localStorage.getItem(q.logs.density)==="compact"?"compact":"comfortable"}function Hs(){if(typeof window>"u")return Z[0];const s=window.localStorage.getItem(q.logs.pageSize),l=Number(s);return Z.includes(l)?l:Z[0]}function _e(s,l=!1){if(!s)return;const p=l?`${s}T23:59:59.999`:`${s}T00:00:00.000`,a=Date.parse(p);return Number.isFinite(a)?a:void 0}function Bs(s,l,p){return s===p&&l===p}function Ws({columnOptions:s,exporting:l,onExport:p,onRefresh:a,onResetColumns:o,onSetDensity:t,onToggleColumn:i,refreshing:y,rowDensity:b,visibleColumns:d,visibleColumnSet:v}){const{t:u}=O(),N=JSON.stringify(d)===JSON.stringify(J);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.jsx(As,{block:!0,className:"w-full overflow-x-auto sm:w-auto",value:b,onChange:t,options:[{value:"comfortable",label:u("logs.table.density.comfortable")},{value:"compact",label:u("logs.table.density.compact")}]}),e.jsxs(Ps,{children:[e.jsx(qs,{asChild:!0,children:e.jsx(R,{variant:"outline",size:"sm",className:"w-full sm:w-auto",children:u("logs.actions.columns")})}),e.jsxs(zs,{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:u("logs.actions.columns")}),e.jsx("p",{className:"text-xs text-muted-foreground",children:u("logs.actions.visibleCount",{count:d.length})})]}),e.jsx(R,{variant:"ghost",size:"sm",onClick:o,disabled:N,children:u("common.actions.reset")})]}),e.jsx("div",{className:"grid gap-1.5",children:s.map(f=>{const w=v.has(f.id);return e.jsxs("label",{className:E("flex cursor-pointer items-center gap-3 rounded-xl px-3 py-2 text-sm transition hover:bg-accent",w&&"bg-primary/10 text-primary"),children:[e.jsx("input",{type:"checkbox",checked:w,onChange:()=>i(f.id),className:"h-4 w-4 rounded border-border"}),e.jsx("span",{children:f.label})]},f.id)})})]})]}),e.jsxs(R,{onClick:p,disabled:l,className:"w-full sm:w-auto",children:[e.jsx(De,{className:"mr-2 h-4 w-4"}),u(l?"logs.actions.exporting":"logs.actions.export")]})]}),e.jsx("div",{className:"flex w-full items-center xl:w-auto",children:e.jsxs(R,{variant:"outline",size:"sm",onClick:a,disabled:y,className:"shrink-0",children:[e.jsx(us,{className:E("mr-2 h-4 w-4",y&&"animate-spin")}),u(y?"common.actions.refreshing":"logs.actions.manualRefresh")]})})]})}function Gs({record:s,providerLabelMap:l,onSelect:p}){const{t:a}=O(),o=fe(s,a),t=l.get(s.provider)??s.provider,i=Me(s.session_id),y=i==null?void 0:i.accentStyle;return e.jsxs("button",{type:"button","data-session-id":i==null?void 0:i.sessionId,"data-session-color":i==null?void 0:i.colorKey,style:y,onClick:()=>p(s.id),className:"w-full space-y-2 border-b border-border/50 px-4 py-3 text-left transition-colors hover:bg-muted/50",children:[e.jsxs("div",{className:"flex items-center justify-between gap-2",children:[e.jsx("span",{className:"text-xs text-muted-foreground",children:he(s.timestamp)}),e.jsx(V,{variant:o.variant,className:"text-xs",children:o.label})]}),e.jsxs("div",{className:"flex items-center justify-between gap-3 text-xs",children:[e.jsx("span",{className:"min-w-0 truncate font-medium",title:t,children:t}),e.jsx("span",{className:"min-w-0 truncate text-muted-foreground",title:s.model,children:s.model})]}),e.jsxs("div",{className:"flex flex-wrap items-center gap-x-3 gap-y-1 text-xs tabular-nums text-muted-foreground",children:[e.jsx("span",{children:A(s.latency_ms,a("common.units.ms"))}),s.ttft_ms!=null?e.jsxs("span",{children:[a("logs.table.columns.latencyTtft")," ",M(s.ttft_ms)]}):null]})]})}const Ee={accent:"bg-primary",ok:"bg-success",warn:"bg-warning",error:"bg-destructive"};function Js({logId:s,providerLabelMap:l,apiKeyMap:p}){const{t:a}=O(),{record:o,isPending:t,isError:i,errorMessage:y,statusMeta:b,providerLabel:d,handleCopy:v,refetch:u}=ze({apiKeyMap:p,logId:s,open:!0,providerLabelMap:l}),N=x.useMemo(()=>{var C,D,F,_;if(!o)return[];const n=[{key:"client-request",title:a("logs.detail.payload.clientRequest"),value:((C=o.payload)==null?void 0:C.client_request)??null,emptyLabel:a("logs.detail.payload.emptyRequest"),copyToast:"logs.detail.copy.requestSuccess"}];return(D=o.payload)!=null&&D.upstream_request&&n.push({key:"upstream-request",title:a("logs.detail.payload.upstreamRequest"),value:o.payload.upstream_request,emptyLabel:a("logs.detail.payload.emptyRequest"),copyToast:"logs.detail.copy.requestSuccess"}),(F=o.payload)!=null&&F.upstream_response&&n.push({key:"upstream-response",title:a("logs.detail.payload.upstreamResponse"),value:o.payload.upstream_response,emptyLabel:a("logs.detail.payload.emptyResponse"),copyToast:"logs.detail.copy.responseSuccess"}),n.push({key:"client-response",title:a("logs.detail.payload.clientResponse"),value:((_=o.payload)==null?void 0:_.client_response)??null,emptyLabel:a("logs.detail.payload.emptyResponse"),copyToast:"logs.detail.copy.responseSuccess"}),n.map(c=>({...c,display:Ke(c.value,c.emptyLabel)}))},[o,a]),[f,w]=x.useState("client-request"),r=N.find(n=>n.key===f)??N[0];if(t)return e.jsx("div",{className:"py-3",children:e.jsx(Pe,{className:"h-28 w-full"})});if(i)return e.jsx(X,{compact:!0,tone:"danger",title:a("logs.detail.loadError"),description:y??a("common.unknownError"),action:e.jsx(R,{variant:"outline",size:"sm",onClick:()=>void u(),children:a("common.actions.refresh")})});if(!o)return e.jsx(X,{compact:!0,title:a("logs.detail.loadError"),description:a("common.noData")});const h=Ks(o,d,a),L=a("common.units.ms"),g=[{label:a("logs.detail.info.status"),value:(b==null?void 0:b.label)??"-"},{label:a("logs.detail.info.latency"),value:A(o.latency_ms,L)},{label:a("logs.detail.info.ttft"),value:A(o.ttft_ms,L)},{label:a("logs.detail.info.inputTokens"),value:M(o.input_tokens)},{label:a("logs.detail.info.outputTokens"),value:M(o.output_tokens)},{label:a("logs.detail.info.cacheReadTokens"),value:M(o.cache_read_tokens)}],j=o.ttft_ms!=null,k=o.session_id;return e.jsxs("div",{"data-testid":"log-row-expanded",className:"grid gap-5 py-1 xl:grid-cols-[minmax(0,1.15fr)_minmax(0,1fr)]",children:[e.jsxs("div",{className:"min-w-0",children:[e.jsx("p",{className:"mb-3 text-[10.5px] font-semibold uppercase tracking-[0.06em] text-muted-foreground",children:a("logs.detail.trace.title")}),e.jsx("ol",{"data-testid":"log-trace-timeline",className:"flex flex-col",children:h.map((n,C)=>e.jsxs("li",{className:"grid grid-cols-[14px_1fr] gap-3",children:[e.jsxs("div",{className:"flex flex-col items-center","aria-hidden":"true",children:[e.jsx("span",{className:E("mt-1 h-[9px] w-[9px] rounded-full",Ee[n.tone])}),C<h.length-1?e.jsx("span",{className:"mt-[3px] w-px flex-1 bg-border"}):null]}),e.jsxs("div",{className:"pb-3.5",children:[e.jsxs("div",{className:"flex items-baseline gap-2.5",children:[e.jsx("span",{className:"text-xs font-semibold",children:n.title}),n.atLabel?e.jsx("span",{className:"text-[10.5px] tabular-nums text-muted-foreground",children:n.atLabel}):null,n.durLabel?e.jsx("span",{className:"ml-auto text-[10.5px] tabular-nums text-muted-foreground",children:n.durLabel}):null]}),n.detail?e.jsx("div",{className:"mt-1 text-[11px] leading-[1.55] text-muted-foreground",children:n.detail}):null,e.jsx("div",{className:"mt-1.5 h-1 w-full max-w-[220px] bg-secondary",children:e.jsx("div",{className:E("h-full",Ee[n.tone]),style:{width:`${n.barPct}%`}})})]})]},n.id))}),j?null:e.jsx("p",{className:"mt-1 text-[10.5px] text-muted-foreground/70",children:a("logs.detail.trace.degraded")})]}),e.jsxs("div",{className:"flex min-w-0 flex-col gap-3",children:[e.jsx("div",{className:"grid grid-cols-3 gap-2",children:g.map(n=>e.jsxs("div",{className:"border border-border bg-card px-2.5 py-2",children:[e.jsx("div",{className:"text-[10.5px] text-muted-foreground",children:n.label}),e.jsx("div",{className:"mt-0.5 text-[13px] font-semibold tabular-nums",children:n.value})]},n.label))}),e.jsxs("div",{className:"border border-border bg-card",children:[e.jsx("div",{className:"flex gap-0.5 border-b border-border bg-secondary/50 p-1.5",role:"tablist",children:N.map(n=>{const C=n.key===(r==null?void 0:r.key);return e.jsx("button",{type:"button",role:"tab","aria-selected":C,onClick:()=>w(n.key),className:E("px-2.5 py-1 text-[10.5px] font-medium transition-colors",C?"bg-card text-foreground":"text-muted-foreground hover:text-foreground"),children:n.title},n.key)})}),e.jsx("pre",{"data-testid":`log-payload-${(r==null?void 0:r.key)??"none"}`,className:"m-0 max-h-[172px] overflow-auto whitespace-pre-wrap p-3 font-mono text-[10.5px] leading-[1.65] text-muted-foreground",children:(r==null?void 0:r.display.text)||a("logs.detail.payload.emptyRequest")})]}),e.jsxs("div",{className:"flex flex-wrap gap-2",children:[e.jsxs(R,{variant:"outline",size:"sm",className:"h-[30px] flex-1",onClick:()=>{r&&v(r.title,r.value,r.copyToast)},children:[e.jsx(Re,{className:"mr-1.5 h-3.5 w-3.5","aria-hidden":"true"}),a("logs.detail.inline.copyRequest")]}),k?e.jsx(R,{variant:"outline",size:"sm",className:"h-[30px] flex-1",onClick:()=>v(a("logs.detail.inline.copySession"),k,"logs.detail.inline.sessionCopied"),children:a("logs.detail.inline.copySession")}):null,e.jsx(R,{asChild:!0,variant:"outline",size:"sm",className:"h-[30px] flex-1",children:e.jsxs(qe,{to:"/providers?tab=routing",children:[a("logs.detail.inline.viewRule"),e.jsx(ps,{className:"ml-1.5 h-3.5 w-3.5","aria-hidden":"true"})]})})]})]})]})}function Zs({record:s,providerLabelMap:l,apiKeyMap:p,onSelect:a,isExpanded:o,onToggleExpand:t,isEven:i,density:y,visibleColumnSet:b}){const{t:d}=O(),v=l.get(s.provider)??s.provider,u=s.endpoint||"-",N=fe(s,d),f=s.client_model??d("logs.table.requestedModelFallback"),w=s.api_key_id!=null?p.get(s.api_key_id):void 0,r=s.api_key_id==null?d("logs.table.apiKeyUnknown"):w!=null&&w.isWildcard?d("apiKeys.wildcard"):w!=null&&w.name?w.name:s.api_key_name?s.api_key_name:d("logs.table.apiKeyUnknown"),h=y==="compact"?"px-3 py-1.5":"px-3 py-2",L=i?"bg-muted/30":"bg-background",g=Me(s.session_id),j=g==null?void 0:g.accentStyle,k=b.size+2,n=d(o?"logs.detail.inline.collapse":"logs.detail.inline.expand");return e.jsxs(e.Fragment,{children:[e.jsxs("tr",{"data-log-id":s.id,"data-session-id":g==null?void 0:g.sessionId,"data-session-color":g==null?void 0:g.colorKey,className:E("transition-colors duration-160 ease-surface",i?"bg-muted/30":"",o?"bg-muted/50":"hover:bg-muted/50"),children:[e.jsx("td",{className:E("sticky left-0 z-10 text-xs",h,L),style:j,children:e.jsxs("div",{className:"flex items-center gap-1.5",children:[e.jsx("button",{type:"button","aria-expanded":o,"aria-label":n,onClick:()=>t(s.id),className:"-ml-0.5 inline-flex h-5 w-5 shrink-0 items-center justify-center rounded-sm text-muted-foreground transition-colors hover:bg-secondary hover:text-foreground focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-ring",children:e.jsx(xs,{className:E("h-3.5 w-3.5 transition-transform duration-160 ease-surface",o&&"rotate-90"),"aria-hidden":"true"})}),e.jsx("span",{className:"metric-number",children:he(s.timestamp)})]})}),b.has("endpoint")&&e.jsx("td",{className:E(h,"text-xs"),children:u}),b.has("provider")&&e.jsx("td",{className:E(h,"text-xs"),children:e.jsx("div",{className:"max-w-[100px] truncate",title:v,children:v})}),b.has("requestedModel")&&e.jsx("td",{className:E(h,"text-xs text-muted-foreground"),children:e.jsx("div",{className:"max-w-[120px] truncate",title:f,children:f})}),b.has("routedModel")&&e.jsx("td",{className:E(h,"text-xs"),children:e.jsx("div",{className:"max-w-[120px] truncate",title:s.model,children:s.model})}),b.has("apiKey")&&e.jsx("td",{className:E(h,"text-xs text-muted-foreground"),children:e.jsx("div",{className:"max-w-[90px] truncate",title:r,children:r})}),b.has("tokens")&&e.jsx("td",{className:E(h,"text-right text-xs tabular-nums align-top"),children:e.jsxs("span",{className:"inline-flex flex-col items-end gap-0.5",children:[e.jsxs("span",{className:"whitespace-nowrap",children:[d("logs.table.columns.tokenIn")," ",M(s.input_tokens),e.jsx("span",{className:"mx-1 text-muted-foreground/50",children:"·"}),d("logs.table.columns.tokenOut")," ",M(s.output_tokens)]}),(()=>{const C=(s.cache_read_tokens??0)+(s.cache_creation_tokens??0);return C>0?e.jsxs("span",{className:"whitespace-nowrap text-[11px] text-muted-foreground/70",children:[d("logs.table.columns.tokenCache")," ",M(C)]}):null})()]})}),b.has("duration")&&e.jsx("td",{className:E(h,"text-right text-xs tabular-nums align-top"),children:e.jsxs("span",{className:"inline-flex flex-col items-end gap-0.5",children:[e.jsx("span",{className:"whitespace-nowrap",children:A(s.latency_ms,"ms")}),(s.ttft_ms!=null||s.tpot_ms!=null)&&e.jsxs("span",{className:"whitespace-nowrap text-[11px] text-muted-foreground/70",title:`${d("logs.table.columns.latencyTtft")} ${A(s.ttft_ms,"ms")} · ${d("logs.table.columns.latencyTpot")} ${A(s.tpot_ms,"ms/tk")}`,children:[d("logs.table.columns.latencyTtft")," ",M(s.ttft_ms),e.jsx("span",{className:"mx-1 text-muted-foreground/50",children:"·"}),d("logs.table.columns.latencyTpot")," ",M(s.tpot_ms)]})]})}),b.has("status")&&e.jsx("td",{className:E(h,"text-center"),children:e.jsx(V,{variant:N.variant,className:"text-xs",children:N.label})}),b.has("error")&&e.jsx("td",{className:E(h,"text-xs text-muted-foreground"),children:e.jsx("div",{className:"max-w-[100px] truncate",title:s.error??"",children:s.error?s.error:"-"})}),e.jsx("td",{className:E("sticky right-0 z-10 text-center",h,L),children:e.jsx(R,{variant:"outline",size:"sm",onClick:()=>a(s.id),children:d("logs.actions.detail")})})]}),o?e.jsx("tr",{"data-testid":`log-row-expanded-wrapper-${s.id}`,children:e.jsx("td",{colSpan:k,className:"border-t border-border bg-secondary/30 p-0",children:e.jsx("div",{className:"px-5 pb-5 pt-3",children:e.jsx(Js,{logId:s.id,providerLabelMap:l,apiKeyMap:p})})})}):null]})}function Xs(s){const{t:l}=O(),{tableScrollRef:p,visibleColumnSet:a,visibleColumnCount:o,logsError:t,logsPending:i,items:y,activeFiltersCount:b,total:d,handleResetFilters:v,handleRetry:u,providerLabelMap:N,apiKeyMap:f,handleOpenDetail:w,expandedLogId:r,onToggleExpand:h,rowDensity:L,showScrollHint:g,pageSize:j,setPageSize:k,page:n,totalPages:C,setPage:D}=s,F=e.jsx(X,{compact:!0,tone:"danger",icon:e.jsx(gs,{className:"h-5 w-5","aria-hidden":"true"}),title:l("logs.toast.listError.title"),description:t,action:e.jsxs("div",{className:"flex flex-wrap items-center justify-center gap-2",children:[e.jsx(R,{variant:"outline",size:"sm",onClick:u,children:l("common.actions.refresh")}),b>0?e.jsx(R,{variant:"ghost",size:"sm",onClick:v,children:l("common.actions.reset")}):null]})}),_=e.jsx(X,{compact:!0,tone:"primary",icon:e.jsx(fs,{className:"h-5 w-5","aria-hidden":"true"}),title:b>0?l("logs.empty.filteredTitle"):l("logs.empty.title"),description:b>0?l("logs.empty.filteredSubtitle"):l("logs.empty.subtitle"),action:e.jsxs("div",{className:"flex flex-wrap items-center justify-center gap-2",children:[b>0?e.jsx(R,{variant:"outline",size:"sm",onClick:v,children:l("logs.empty.actions.reset")}):null,e.jsx(R,{asChild:!0,variant:"ghost",size:"sm",children:e.jsx(qe,{to:"/api-keys",children:l("logs.empty.actions.apiKeys")})})]})});return e.jsx(Fe,{className:"overflow-hidden bg-card shadow-[var(--surface-shadow)]",children:e.jsxs(Te,{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:l("logs.title")}),e.jsxs("p",{className:"text-xs text-muted-foreground",children:[e.jsx("span",{className:"metric-number",children:l("logs.summary.total",{value:d.toLocaleString()})}),e.jsx("span",{className:"mx-1.5 text-muted-foreground/50",children:"·"}),l("logs.actions.visibleCount",{count:o-2})]})]}),e.jsxs("div",{className:"hidden md:flex flex-wrap items-center gap-2",children:[e.jsx(V,{variant:"secondary",children:"Wide Table"}),e.jsx(V,{variant:"outline",className:"bg-background",children:l(L==="compact"?"logs.table.density.compact":"logs.table.density.comfortable")}),g?e.jsx(V,{variant:"warning",children:"Scroll for more"}):null]})]}),e.jsxs("div",{className:"relative hidden md:block",children:[e.jsx("div",{ref:p,className:"overflow-x-auto",children:e.jsxs("table",{className:"w-full min-w-[1180px] 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:l("logs.table.columns.time")}),a.has("endpoint")&&e.jsx("th",{className:"px-3 py-2.5 text-left text-xs font-semibold uppercase tracking-wider text-muted-foreground",children:l("logs.table.columns.endpoint")}),a.has("provider")&&e.jsx("th",{className:"px-3 py-2.5 text-left text-xs font-semibold uppercase tracking-wider text-muted-foreground",children:l("logs.table.columns.provider")}),a.has("requestedModel")&&e.jsx("th",{className:"px-3 py-2.5 text-left text-xs font-semibold uppercase tracking-wider text-muted-foreground",children:l("logs.table.columns.requestedModel")}),a.has("routedModel")&&e.jsx("th",{className:"px-3 py-2.5 text-left text-xs font-semibold uppercase tracking-wider text-muted-foreground",children:l("logs.table.columns.routedModel")}),a.has("apiKey")&&e.jsx("th",{className:"px-3 py-2.5 text-left text-xs font-semibold uppercase tracking-wider text-muted-foreground",children:l("logs.table.columns.apiKey")}),a.has("tokens")&&e.jsx("th",{className:"px-3 py-2.5 text-right text-xs font-semibold uppercase tracking-wider text-muted-foreground",children:l("logs.table.columns.tokens")}),a.has("duration")&&e.jsx("th",{className:"px-3 py-2.5 text-right text-xs font-semibold uppercase tracking-wider text-muted-foreground",children:l("logs.table.columns.duration")}),a.has("status")&&e.jsx("th",{className:"px-3 py-2.5 text-center text-xs font-semibold uppercase tracking-wider text-muted-foreground",children:l("logs.table.columns.status")}),a.has("error")&&e.jsx("th",{className:"px-3 py-2.5 text-left text-xs font-semibold uppercase tracking-wider text-muted-foreground",children:l("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:l("logs.table.columns.actions")})]})}),e.jsx("tbody",{className:"divide-y divide-border/50",children:i?Array.from({length:8}).map((c,z)=>e.jsx(Ms,{columns:o},z)):t&&y.length===0?e.jsx("tr",{children:e.jsx("td",{colSpan:o,className:"px-3 py-6",children:F})}):y.length===0?e.jsx("tr",{children:e.jsx("td",{colSpan:o,className:"px-3 py-8 text-center text-sm text-muted-foreground",children:_})}):y.map((c,z)=>e.jsx(Zs,{record:c,providerLabelMap:N,apiKeyMap:f,onSelect:w,isExpanded:c.id===r,onToggleExpand:h,isEven:z%2===0,density:L,visibleColumnSet:a},c.id))})]})}),g&&e.jsx("div",{className:"table-scroll-hint"})]}),e.jsx("div",{className:"md:hidden",children:i?e.jsx("div",{className:"space-y-3 p-4",children:Array.from({length:5}).map((c,z)=>e.jsx(Pe,{className:"h-20 w-full"},z))}):t&&y.length===0?e.jsx("div",{className:"px-3 py-6",children:F}):y.length===0?e.jsx("div",{className:"px-3 py-8",children:_}):y.map(c=>e.jsx(Gs,{record:c,providerLabelMap:N,onSelect:w},c.id))}),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:l("logs.table.pagination.perPage")}),e.jsxs(te,{value:j.toString(),onValueChange:c=>k(Number(c)),children:[e.jsx(le,{className:"h-8 w-[80px] bg-background",children:e.jsx(ae,{})}),e.jsx(re,{children:Z.map(c=>e.jsx(I,{value:c.toString(),children:c},c))})]})]}),e.jsxs("div",{className:"flex items-center gap-2 rounded-full bg-secondary px-2 py-2",children:[e.jsx(R,{variant:"outline",size:"sm",onClick:()=>D(c=>Math.max(c-1,1)),disabled:n<=1,children:l("logs.table.pagination.previous")}),e.jsx("span",{className:"metric-number px-1 text-sm text-muted-foreground",children:l("logs.table.pagination.pageLabel",{page:C===0?0:n,total:C})}),e.jsx(R,{variant:"outline",size:"sm",onClick:()=>D(c=>C===0?c:Math.min(c+1,C)),disabled:C===0||n>=C,children:l("logs.table.pagination.next")})]})]})]})})}function Ys({exportTimeoutMs:s,queryParams:l,total:p}){const{t:a}=O(),{pushToast:o}=ge(),[t,i]=x.useState(!1),y=x.useCallback(async()=>{if(!t){i(!0);try{const b=p>0?Math.min(p,5e3):1e3,d={...l,limit:b,offset:0},v=await ye.exportArchive(d,s),u=new Date().toISOString().replace(/[:.]/g,"-"),N=URL.createObjectURL(v),f=document.createElement("a");f.href=N,f.download=`cc-gw-logs-${u}.zip`,document.body.appendChild(f),f.click(),f.remove(),URL.revokeObjectURL(N),o({title:a("logs.toast.exportSuccess.title"),description:a("logs.toast.exportSuccess.desc"),variant:"success"})}catch(b){const d=bs(b);o({title:a("logs.toast.exportError.title"),description:a("logs.toast.exportError.desc",{message:d.message}),variant:"error"})}finally{i(!1)}}},[s,t,o,l,a,p]);return{exporting:t,handleExport:y}}function et(){const s=x.useRef(null),[l,p]=x.useState(!1),a=x.useCallback(()=>{const o=s.current;if(!o)return;const t=o.scrollWidth-o.scrollLeft-o.clientWidth>1;p(t)},[]);return x.useEffect(()=>{const o=s.current;if(!o)return;a(),o.addEventListener("scroll",a,{passive:!0});const t=new ResizeObserver(a);return t.observe(o),()=>{o.removeEventListener("scroll",a),t.disconnect()}},[a]),{scrollRef:s,showScrollHint:l,updateScrollHint:a}}function st(){const[s,l]=$(q.logs.density,Us,{serialize:v=>v,deserialize:v=>v==="compact"?"compact":"comfortable"}),[p,a]=$(q.logs.visibleColumns,J,{serialize:JSON.stringify,deserialize:v=>{try{const u=JSON.parse(v);if(!Array.isArray(u))return J;const N=u.filter(f=>oe.includes(f));return N.length>0?N:J}catch{return J}}}),{scrollRef:o,showScrollHint:t}=et(),i=x.useMemo(()=>new Set(p),[p]),y=p.length+2,b=x.useCallback(v=>{a(u=>{if(u.includes(v))return u.length===1?u:u.filter(f=>f!==v);const N=[...u,v];return N.sort((f,w)=>oe.indexOf(f)-oe.indexOf(w)),N})},[]);return{resetVisibleColumns:x.useCallback(()=>{a(J)},[]),rowDensity:s,setRowDensity:l,showScrollHint:t,tableScrollRef:o,toggleColumn:b,visibleColumnCount:y,visibleColumns:p,visibleColumnSet:i}}function tt(){var Ne,we,ke,Se,Ce;const{t:s}=O(),{pushToast:l}=ge(),p=Os(),[a,o]=$(q.logs.providerFilter,"all"),[t,i]=$(q.logs.endpointFilter,"all"),[y,b]=$(q.logs.modelFilter,""),[d,v]=$(q.logs.statusFilter,"all"),[u,N]=$(q.logs.fromDate,""),[f,w]=$(q.logs.toDate,""),[r,h]=x.useState(1),[L,g]=$(q.logs.pageSize,Hs,{serialize:m=>String(m),deserialize:m=>{const S=Number(m);return Z.includes(S)?S:Z[0]}}),[j,k]=x.useState(null),[n,C]=x.useState(!1),[D,F]=x.useState(null),[_,c]=$(q.logs.selectedApiKeys,[],{serialize:JSON.stringify,deserialize:m=>{try{const S=JSON.parse(m);return Array.isArray(S)?S.map(P=>Number(P)).filter(P=>Number.isInteger(P)&&P>0):[]}catch{return[]}}}),[z,Ae]=x.useState(!0),{resetVisibleColumns:Oe,rowDensity:Ie,setRowDensity:$e,showScrollHint:Qe,tableScrollRef:Ve,toggleColumn:Ue,visibleColumnCount:He,visibleColumns:Be,visibleColumnSet:We}=st(),Ge=x.useDeferredValue(y),T=y===""?"":Ge;x.useEffect(()=>{h(1),F(null)},[a,t,T,d,u,f,L,_]);const ne=x.useMemo(()=>{const m={limit:L,offset:(r-1)*L};a!=="all"&&(m.provider=a),t!=="all"&&(m.endpoint=t),T.trim().length>0&&(m.model=T.trim()),d!=="all"&&(m.status=d);const S=_e(u),P=_e(f,!0);return S!==void 0&&(m.from=S),P!==void 0&&(m.to=P),_.length>0&&(m.apiKeys=_.join(",")),m},[T,t,u,r,L,a,_,d,f]),U=G(H.logs.list(ne),ye.listRequest(ne),{gcTime:6e4}),W=G(H.providers.all(),Le.providersRequest()),be=G(H.apiKeys.all(),{url:"/api/keys",method:"GET"}),ie=G(H.customEndpoints.all(),{url:"/api/custom-endpoints",method:"GET"}),je=G(H.config.exportTimeout(),Le.configRequest());x.useEffect(()=>{!U.isError||!U.error||l({title:s("logs.toast.listError.title"),description:s("logs.toast.listError.desc",{message:U.error.message}),variant:"error"})},[U.error,U.isError,l,s]),x.useEffect(()=>{!W.isError||!W.error||l({title:s("logs.toast.providerError.title"),description:s("logs.toast.providerError.desc",{message:W.error.message}),variant:"error"})},[W.error,W.isError,l,s]);const se=((Ne=U.data)==null?void 0:Ne.total)??0,Y=se>0?Math.ceil(se/L):0,Je=((we=U.data)==null?void 0:we.items)??[],Ze=x.useMemo(()=>{var S;const m=(S=je.data)==null?void 0:S.logExportTimeoutSeconds;return typeof m=="number"&&Number.isFinite(m)?Math.min(Math.max(Math.round(m),5),600)*1e3:6e4},[(ke=je.data)==null?void 0:ke.logExportTimeoutSeconds]);x.useEffect(()=>{Y>0&&r>Y&&h(Y)},[r,Y]);const de=W.data??[],ce=x.useMemo(()=>{const m=new Map;for(const S of de)S.id&&m.set(S.id,S.label??S.id);return m},[de]),ve=x.useMemo(()=>{var S;const m=new Map;m.set("anthropic",s("logs.filters.endpointAnthropic")),m.set("openai",s("logs.filters.endpointOpenAI"));for(const P of((S=ie.data)==null?void 0:S.endpoints)??[])m.set(P.id,P.label||P.id);return m},[(Se=ie.data)==null?void 0:Se.endpoints,s]),Xe=x.useMemo(()=>{const m=[];if(a!=="all"){const S=ce.get(a)??a;m.push({key:"provider",label:`${s("logs.filters.provider")}: ${S}`,onRemove:()=>o("all")})}if(t!=="all"){const S=ve.get(t)??t;m.push({key:"endpoint",label:`${s("logs.filters.endpoint")}: ${S}`,onRemove:()=>i("all")})}if(T.trim()&&m.push({key:"model",label:`${s("logs.filters.modelId")}: ${T.trim()}`,onRemove:()=>b("")}),d!=="all"){const S=s(d==="success"?"logs.filters.statusSuccess":"logs.filters.statusError");m.push({key:"status",label:`${s("logs.filters.status")}: ${S}`,onRemove:()=>v("all")})}return u&&m.push({key:"from",label:`${s("logs.filters.startDate")}: ${u}`,onRemove:()=>N("")}),f&&m.push({key:"to",label:`${s("logs.filters.endDate")}: ${f}`,onRemove:()=>w("")}),_.length>0&&m.push({key:"apiKeys",label:s("logs.filters.apiKeySelected",{count:_.length}),onRemove:()=>c([])}),m},[T,t,ve,u,a,ce,_.length,d,s,f]),me=be.data??[],Ye=x.useMemo(()=>{const m=new Map;for(const S of me)m.set(S.id,S);return m},[me]),es=x.useMemo(()=>oe.map(m=>({id:m,label:s(`logs.table.columns.${m}`)})),[s]),ee=x.useMemo(()=>{const m=new Date;return`${m.getFullYear()}-${String(m.getMonth()+1).padStart(2,"0")}-${String(m.getDate()).padStart(2,"0")}`},[]),ss=x.useMemo(()=>a==="all"&&t==="all"&&T.trim()===""&&d==="all"&&u===""&&f===""&&_.length===0?"all":d==="error"&&t==="all"&&a==="all"&&T.trim()===""&&u===""&&f===""&&_.length===0?"errors":Bs(u,f,ee)&&t==="all"&&a==="all"&&T.trim()===""&&d==="all"&&_.length===0?"today":t==="anthropic"&&a==="all"&&T.trim()===""&&d==="all"&&u===""&&f===""&&_.length===0?"anthropic":t==="openai"&&a==="all"&&T.trim()===""&&d==="all"&&u===""&&f===""&&_.length===0?"openai":null,[T,t,u,a,_.length,d,f,ee]),ue=x.useCallback(()=>{o("all"),b(""),i("all"),v("all"),N(""),w(""),c([])},[]),ts=x.useCallback(m=>{if(h(1),ue(),m!=="all"){if(m==="errors"){v("error");return}if(m==="today"){N(ee),w(ee);return}if(m==="anthropic"){i("anthropic");return}m==="openai"&&i("openai")}},[ue,ee]),{exporting:ls,handleExport:as}=Ys({exportTimeoutMs:Ze,queryParams:ne,total:se}),rs=x.useCallback(m=>{p.removeQueries({queryKey:["logs","detail"],type:"inactive"}),k(m),C(!0)},[p]),os=x.useCallback(()=>{C(!1)},[]),ns=x.useCallback(m=>{F(S=>S===m?null:m)},[]);return x.useEffect(()=>{n||j===null||(p.removeQueries({queryKey:H.logs.detail(j),exact:!0}),k(null))},[n,p,j]),{activeFilters:Xe,activeQuickView:ss,apiKeyMap:Ye,apiKeys:me,apiKeysQuery:be,applyQuickView:ts,columnOptions:es,customEndpoints:(Ce=ie.data)==null?void 0:Ce.endpoints,endpointFilter:t,exporting:ls,expandedLogId:D,filtersExpanded:z,fromDate:u,handleCloseDetail:os,handleExport:as,handleOpenDetail:rs,handleResetFilters:ue,handleToggleExpand:ns,isDetailOpen:n,items:Je,logsQuery:U,modelFilter:y,page:r,pageSize:L,providerFilter:a,providerLabelMap:ce,providerOptions:de,rowDensity:Ie,resetVisibleColumns:Oe,selectedApiKeys:_,selectedLogId:j,setEndpointFilter:i,setFiltersExpanded:Ae,setFromDate:N,setModelFilter:b,setPage:h,setPageSize:g,setProviderFilter:o,setRowDensity:$e,setSelectedApiKeys:c,setStatusFilter:v,setToDate:w,showScrollHint:Qe,statusFilter:d,tableScrollRef:Ve,toDate:f,toggleColumn:Ue,total:se,totalPages:Y,visibleColumnCount:He,visibleColumns:Be,visibleColumnSet:We}}function wt(){var l;const s=tt();return e.jsxs("div",{className:"flex flex-col gap-4",children:[e.jsx(hs,{actions:e.jsx(Ws,{columnOptions:s.columnOptions,exporting:s.exporting,onExport:()=>void s.handleExport(),onRefresh:()=>void s.logsQuery.refetch(),onResetColumns:s.resetVisibleColumns,onSetDensity:s.setRowDensity,onToggleColumn:s.toggleColumn,refreshing:s.logsQuery.isFetching,rowDensity:s.rowDensity,visibleColumns:s.visibleColumns,visibleColumnSet:s.visibleColumnSet})}),e.jsx($s,{activeFilters:s.activeFilters,filtersExpanded:s.filtersExpanded,setFiltersExpanded:s.setFiltersExpanded,handleResetFilters:s.handleResetFilters,activeQuickView:s.activeQuickView,applyQuickView:s.applyQuickView,providerFilter:s.providerFilter,setProviderFilter:s.setProviderFilter,endpointFilter:s.endpointFilter,setEndpointFilter:s.setEndpointFilter,selectedApiKeys:s.selectedApiKeys,setSelectedApiKeys:s.setSelectedApiKeys,modelFilter:s.modelFilter,setModelFilter:s.setModelFilter,statusFilter:s.statusFilter,setStatusFilter:s.setStatusFilter,fromDate:s.fromDate,setFromDate:s.setFromDate,toDate:s.toDate,setToDate:s.setToDate,providerOptions:s.providerOptions,apiKeys:s.apiKeys,apiKeysLoading:s.apiKeysQuery.isLoading,customEndpoints:s.customEndpoints}),e.jsx(Xs,{tableScrollRef:s.tableScrollRef,visibleColumnSet:s.visibleColumnSet,visibleColumnCount:s.visibleColumnCount,logsError:s.logsQuery.isError?((l=s.logsQuery.error)==null?void 0:l.message)??null:null,logsPending:s.logsQuery.isPending,items:s.items,activeFiltersCount:s.activeFilters.length,total:s.total,handleResetFilters:s.handleResetFilters,handleRetry:()=>void s.logsQuery.refetch(),providerLabelMap:s.providerLabelMap,apiKeyMap:s.apiKeyMap,handleOpenDetail:s.handleOpenDetail,expandedLogId:s.expandedLogId,onToggleExpand:s.handleToggleExpand,rowDensity:s.rowDensity,showScrollHint:s.showScrollHint,pageSize:s.pageSize,setPageSize:s.setPageSize,page:s.page,totalPages:s.totalPages,setPage:s.setPage}),e.jsx(Qs,{open:s.isDetailOpen,logId:s.selectedLogId,onClose:s.handleCloseDetail,providerLabelMap:s.providerLabelMap,apiKeyMap:s.apiKeyMap})]})}export{wt as default};
|