@kaitranntt/ccs 7.74.0-dev.1 → 7.74.0-dev.2
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/dist/cliproxy/codex-plan-compatibility.d.ts.map +1 -1
- package/dist/cliproxy/codex-plan-compatibility.js +1 -0
- package/dist/cliproxy/codex-plan-compatibility.js.map +1 -1
- package/dist/cliproxy/model-catalog.d.ts.map +1 -1
- package/dist/cliproxy/model-catalog.js +12 -0
- package/dist/cliproxy/model-catalog.js.map +1 -1
- package/dist/ui/assets/{accounts-D0Z5AVKW.js → accounts-BGE0yjYy.js} +1 -1
- package/dist/ui/assets/{alert-dialog-CzJucE0e.js → alert-dialog-DuiOADsV.js} +1 -1
- package/dist/ui/assets/{api-DXAf4i-v.js → api-Guj515aS.js} +1 -1
- package/dist/ui/assets/{auth-section-BrnnHBi-.js → auth-section-SAQbhr1I.js} +1 -1
- package/dist/ui/assets/{backups-section-DCBcfZ-C.js → backups-section-DDvlWpiu.js} +1 -1
- package/dist/ui/assets/{channels-BSapONLx.js → channels-BplAqAOq.js} +1 -1
- package/dist/ui/assets/{checkbox-Bd7X5Xud.js → checkbox-BOkFW5T7.js} +1 -1
- package/dist/ui/assets/{claude-extension-BYJxm4B5.js → claude-extension-n_MuC68N.js} +1 -1
- package/dist/ui/assets/{cliproxy-G5JuFm2j.js → cliproxy-WWj2GyJE.js} +1 -1
- package/dist/ui/assets/{cliproxy-ai-providers-D7r2Us_Y.js → cliproxy-ai-providers-B70CiXmm.js} +1 -1
- package/dist/ui/assets/{cliproxy-control-panel-Cmo3ArVL.js → cliproxy-control-panel-B7FrWnuW.js} +1 -1
- package/dist/ui/assets/{codex-4VNBJ4Nb.js → codex-BoljmCX9.js} +8 -8
- package/dist/ui/assets/{confirm-dialog--zJgz4y0.js → confirm-dialog-D73zMOJ7.js} +1 -1
- package/dist/ui/assets/{copilot-2ARJ9YVb.js → copilot-CmS0DhuS.js} +1 -1
- package/dist/ui/assets/{cursor-CQNCrVt0.js → cursor-btzq1F22.js} +1 -1
- package/dist/ui/assets/{droid-Dl5wRjDv.js → droid-Dt-4f5BE.js} +1 -1
- package/dist/ui/assets/{globalenv-section-T1imQsSA.js → globalenv-section-DWWZ9ERp.js} +1 -1
- package/dist/ui/assets/{health-CNous3WN.js → health-CuzprvVL.js} +1 -1
- package/dist/ui/assets/{index-fV5BBuAO.js → index-CA5Km3DW.js} +1 -1
- package/dist/ui/assets/{index-BcLnqcxD.js → index-CHCBgQxw.js} +1 -1
- package/dist/ui/assets/{index-DH916Tyi.js → index-ClrCKbzh.js} +1 -1
- package/dist/ui/assets/{index-Be3dhMW3.js → index-DEqhujvv.js} +1 -1
- package/dist/ui/assets/{index-DFgCoUVv.js → index-DPiX3K4c.js} +1 -1
- package/dist/ui/assets/{index-CqJFugM4.js → index-DQXr3j8J.js} +1 -1
- package/dist/ui/assets/{index-2X8-14xr.js → index-DhAjOd4r.js} +2 -2
- package/dist/ui/assets/{logs-CZsWbq7X.js → logs-CabVgAOr.js} +1 -1
- package/dist/ui/assets/{masked-input-_EkW1Pzo.js → masked-input-4lwOg03z.js} +1 -1
- package/dist/ui/assets/{proxy-status-widget-D82T2X4F.js → proxy-status-widget-C6Ctzus0.js} +1 -1
- package/dist/ui/assets/{raw-json-settings-editor-panel-DNmb_vR-.js → raw-json-settings-editor-panel-upVhpuik.js} +1 -1
- package/dist/ui/assets/{searchable-select--iFe00dY.js → searchable-select-DkL__exx.js} +1 -1
- package/dist/ui/assets/{separator-CaGbNw8E.js → separator-fWUi3UIY.js} +1 -1
- package/dist/ui/assets/{shared-Cgk48Wu3.js → shared-I-FRJqTw.js} +1 -1
- package/dist/ui/assets/{table-CKuoPAz4.js → table-D3mrbj8H.js} +1 -1
- package/dist/ui/assets/{updates-Dr8Yq-Pm.js → updates-2HIhdejN.js} +1 -1
- package/dist/ui/index.html +1 -1
- package/package.json +1 -1
|
@@ -1 +1 @@
|
|
|
1
|
-
import{j as e}from"./radix-ui-Zb8sVEtn.js";import{r as p,c as pe}from"./react-vendor-CNOkPC89.js";import{u as A,a as $,C as g,b as j,S as f,c as x,P as w,B as I,d as _,e as se,f as ge,g as te,h as je,i as ae,j as N,k as D,l as ye,m as Ne,n as we,o as be}from"./index-2X8-14xr.js";import{a3 as ve,am as re,an as Y,ao as ne,a1 as le,aa as ke,G as Ce,ap as Se,R as De,$ as V,U as $e,Z as ie,v as Le,ae as H,aq as Fe,Y as Re,C as Te,ar as Me,as as Pe}from"./icons-DyorC3Xk.js";import{a as Be,u as U}from"./tanstack-CrmUhA7Z.js";import{K as T,L as Q,f as C,H as Ae}from"./utils-CzKF5WmX.js";import{R as oe,A as Ue,C as qe,X as Oe,Y as Z,T as ce,a as X,P as Ie,b as Ke,c as Ee}from"./charts-BBPXh0Ar.js";import"./notifications-B2HqRBj7.js";import"./form-utils-Bcoyqxpq.js";import"./code-highlight-BRUf_pqB.js";function Ge({data:s,isLoading:t}){const{privacyMode:a}=A(),{t:r}=$();if(t)return e.jsx("div",{className:"grid grid-cols-2 md:grid-cols-3 lg:grid-cols-5 gap-4",children:[1,2,3,4,5].map(n=>e.jsx(g,{children:e.jsx(j,{className:"p-6",children:e.jsxs("div",{className:"flex items-center justify-between",children:[e.jsxs("div",{className:"space-y-2",children:[e.jsx(f,{className:"h-4 w-[100px]"}),e.jsx(f,{className:"h-8 w-[80px]"})]}),e.jsx(f,{className:"h-8 w-8 rounded-lg"})]})})},n))});const c=(s?.tokenBreakdown?.cacheCreation?.cost??0)+(s?.tokenBreakdown?.cacheRead?.cost??0),o=s?.totalCost?Math.round(c/s.totalCost*100):0,i=[{title:r("analyticsSummary.totalTokens"),value:s?.totalTokens??0,icon:ve,format:n=>B(n),color:"text-blue-600",bgColor:"bg-blue-100 dark:bg-blue-900/20",subtitle:r("analyticsSummary.totalTokensSubtitle",{input:B(s?.totalInputTokens??0),output:B(s?.totalOutputTokens??0)})},{title:r("analyticsSummary.totalCost"),value:s?.totalCost??0,icon:re,format:n=>`$${n.toFixed(2)}`,color:"text-green-600",bgColor:"bg-green-100 dark:bg-green-900/20",subtitle:r("analyticsSummary.totalCostSubtitle",{value:s?.averageCostPerDay?.toFixed(2)??"0.00"})},{title:r("analyticsSummary.cacheTokens"),value:s?.totalCacheTokens??0,icon:Y,format:n=>B(n),color:"text-cyan-600",bgColor:"bg-cyan-100 dark:bg-cyan-900/20",subtitle:r("analyticsSummary.cacheTokensSubtitle",{cost:c.toFixed(2),percent:o})},{title:r("analyticsSummary.inputCost"),value:s?.tokenBreakdown?.input?.cost??0,icon:ne,format:n=>`$${n.toFixed(2)}`,color:"text-purple-600",bgColor:"bg-purple-100 dark:bg-purple-900/20",subtitle:r("analyticsSummary.tokensSubtitle",{value:B(s?.tokenBreakdown?.input?.tokens??0)})},{title:r("analyticsSummary.outputCost"),value:s?.tokenBreakdown?.output?.cost??0,icon:le,format:n=>`$${n.toFixed(2)}`,color:"text-orange-600",bgColor:"bg-orange-100 dark:bg-orange-900/20",subtitle:r("analyticsSummary.tokensSubtitle",{value:B(s?.tokenBreakdown?.output?.tokens??0)})}];return e.jsx("div",{className:"grid grid-cols-2 md:grid-cols-3 lg:grid-cols-5 gap-4",children:i.map((n,l)=>{const d=n.icon;return e.jsx(g,{className:"hover:shadow-md transition-shadow",children:e.jsx(j,{className:"p-4",children:e.jsxs("div",{className:"flex items-center justify-between space-x-2",children:[e.jsxs("div",{className:"space-y-1 min-w-0",children:[e.jsx("p",{className:"text-xs font-medium text-muted-foreground truncate",children:n.title}),e.jsx("p",{className:x("text-xl font-bold truncate",a&&w),children:n.format(n.value)}),n.subtitle&&e.jsx("p",{className:x("text-[10px] text-muted-foreground truncate",a&&w),children:n.subtitle})]}),e.jsx("div",{className:x("p-2 rounded-lg shrink-0",n.bgColor),children:e.jsx(d,{className:x("h-4 w-4",n.color)})})]})})},l)})})}function B(s){return s>=1e6?`${(s/1e6).toFixed(1)}M`:s>=1e3?`${(s/1e3).toFixed(1)}K`:s.toLocaleString()}function He({model:s}){const{privacyMode:t}=A(),{t:a}=$(),r=We(s.ioRatio);return e.jsxs("div",{className:"space-y-4",children:[e.jsxs("div",{className:"space-y-2",children:[e.jsxs("div",{className:"flex items-center gap-2",children:[e.jsx(ke,{className:"h-4 w-4 text-primary shrink-0"}),e.jsx("h4",{className:"font-semibold leading-none truncate",title:s.model,children:s.model})]}),e.jsxs("div",{className:"flex flex-wrap gap-2",children:[e.jsxs(I,{variant:"secondary",className:"text-[10px] h-5 px-1.5",children:[s.percentage.toFixed(1),"% usage"]}),e.jsxs(I,{variant:r.variant,className:"text-[10px] h-5 px-1.5",children:[s.ioRatio.toFixed(0),":1 I/O"]})]})]}),e.jsxs("div",{className:"grid grid-cols-2 gap-2",children:[e.jsxs("div",{className:"p-2 rounded-md bg-muted/50 border text-center",children:[e.jsxs("p",{className:x("text-lg font-bold",t&&w),children:["$",s.cost.toFixed(2)]}),e.jsx("p",{className:"text-[10px] text-muted-foreground uppercase tracking-wider",children:a("analyticsCards.totalCost")})]}),e.jsxs("div",{className:"p-2 rounded-md bg-muted/50 border text-center",children:[e.jsx("p",{className:x("text-lg font-bold",t&&w),children:ze(s.tokens)}),e.jsx("p",{className:"text-[10px] text-muted-foreground uppercase tracking-wider",children:a("analyticsCards.totalTokens")})]})]}),e.jsxs("div",{className:"space-y-2",children:[e.jsx("h5",{className:"text-[11px] font-medium text-muted-foreground uppercase tracking-wider",children:"Token Breakdown"}),e.jsxs("div",{className:x("space-y-1",t&&w),children:[e.jsx(W,{label:"Input",tokens:s.inputTokens,cost:s.costBreakdown.input.cost,color:"#335c67",icon:ne}),e.jsx(W,{label:"Output",tokens:s.outputTokens,cost:s.costBreakdown.output.cost,color:"#fff3b0",icon:le}),e.jsx(W,{label:"Cache Write",tokens:s.cacheCreationTokens,cost:s.costBreakdown.cacheCreation.cost,color:"#e09f3e",icon:Y}),e.jsx(W,{label:"Cache Read",tokens:s.cacheReadTokens,cost:s.costBreakdown.cacheRead.cost,color:"#9e2a2b",icon:Y})]})]}),e.jsxs("div",{className:"p-2.5 rounded-md border bg-muted/20 space-y-1.5",children:[e.jsxs("div",{className:"flex items-center gap-2",children:[e.jsx(Ce,{className:"h-3.5 w-3.5 text-muted-foreground"}),e.jsx("span",{className:"text-xs font-medium",children:a("analyticsCards.inputOutputRatio")})]}),e.jsx("p",{className:"text-[11px] text-muted-foreground leading-snug",children:r.description})]})]})}function W({label:s,tokens:t,cost:a,color:r,icon:c}){return t===0?null:e.jsxs("div",{className:"flex items-center gap-2 text-xs",children:[e.jsx("div",{className:"w-1 h-6 rounded-full shrink-0",style:{backgroundColor:r}}),e.jsxs("div",{className:"flex-1 min-w-0",children:[e.jsxs("div",{className:"flex items-center justify-between",children:[e.jsx("span",{className:"font-medium truncate",children:s}),e.jsxs("span",{className:"font-mono text-muted-foreground",children:["$",a.toFixed(3)]})]}),e.jsxs("div",{className:"flex items-center gap-1.5 text-muted-foreground",children:[e.jsx(c,{className:"h-3 w-3 shrink-0"}),e.jsx("span",{children:_e(t)})]})]})]})}function We(s){return s>=200?{variant:"destructive",description:"Extended thinking or large context loading. Expected for reasoning models."}:s>=50?{variant:"secondary",description:"More input than output. Typical for analysis tasks."}:s>=5?{variant:"outline",description:"Balanced input/output ratio for typical coding tasks."}:{variant:"default",description:"More output than input. Generation-heavy workload."}}function _e(s){return s.toLocaleString()}function ze(s){return s>=1e9?`${(s/1e9).toFixed(1)}B`:s>=1e6?`${(s/1e6).toFixed(1)}M`:s>=1e3?`${(s/1e3).toFixed(1)}K`:s.toString()}const Ye="/api";function b(s){const t=s.getFullYear(),a=String(s.getMonth()+1).padStart(2,"0"),r=String(s.getDate()).padStart(2,"0");return`${t}${a}${r}`}const M={summary:s=>{const t=new URLSearchParams;return s?.startDate&&t.append("since",b(s.startDate)),s?.endDate&&t.append("until",b(s.endDate)),s?.profile&&t.append("profile",s.profile),F(`/usage/summary?${t}`)},trends:s=>{const t=new URLSearchParams;return s?.startDate&&t.append("since",b(s.startDate)),s?.endDate&&t.append("until",b(s.endDate)),s?.profile&&t.append("profile",s.profile),F(`/usage/daily?${t}`)},hourly:s=>{const t=new URLSearchParams;return s?.startDate&&t.append("since",b(s.startDate)),s?.endDate&&t.append("until",b(s.endDate)),F(`/usage/hourly?${t}`)},models:s=>{const t=new URLSearchParams;return s?.startDate&&t.append("since",b(s.startDate)),s?.endDate&&t.append("until",b(s.endDate)),s?.profile&&t.append("profile",s.profile),F(`/usage/models?${t}`)},sessions:s=>{const t=new URLSearchParams;return s?.startDate&&t.append("since",b(s.startDate)),s?.endDate&&t.append("until",b(s.endDate)),s?.profile&&t.append("profile",s.profile),s?.limit&&t.append("limit",s.limit.toString()),s?.offset&&t.append("offset",s.offset.toString()),F(`/usage/sessions?${t}`)},monthly:(s,t)=>{const a=new URLSearchParams;return s&&a.append("months",s.toString()),t&&a.append("profile",t),F(`/usage/monthly?${a}`)},refresh:async()=>{if(!(await fetch(`${Ye}/usage/refresh`,{method:"POST",headers:{"Content-Type":"application/json"}})).ok)throw new Error("Failed to refresh usage cache")},status:()=>F("/usage/status"),insights:s=>{const t=new URLSearchParams;return s?.startDate&&t.append("since",b(s.startDate)),s?.endDate&&t.append("until",b(s.endDate)),s?.profile&&t.append("profile",s.profile),F(`/usage/insights?${t}`)}};async function F(s){const a=await fetch(`/api${s}`,{headers:{"Content-Type":"application/json"}});if(!a.ok){const c=await a.json().catch(()=>({error:"Unknown error"}));throw new Error(c.error||a.statusText)}const r=await a.json();return r.data||r}function Qe(s){return U({queryKey:["usage","summary",s],queryFn:()=>M.summary(s),staleTime:60*1e3})}function Ve(s){return U({queryKey:["usage","trends",s],queryFn:()=>M.trends(s),staleTime:60*1e3})}function Ze(s){return U({queryKey:["usage","hourly",s],queryFn:()=>M.hourly(s),staleTime:60*1e3})}function Xe(s){return U({queryKey:["usage","models",s],queryFn:()=>M.models(s),staleTime:60*1e3})}function Je(){const s=Be();return p.useCallback(async()=>{await M.refresh(),await s.invalidateQueries({queryKey:["usage"]})},[s])}function es(){return U({queryKey:["usage","status"],queryFn:()=>M.status(),staleTime:10*1e3,refetchInterval:30*1e3})}function ss(s){return U({queryKey:["usage","sessions",s],queryFn:()=>M.sessions(s),staleTime:60*1e3})}function ts(){const[s,t]=p.useState({from:T(new Date,30),to:new Date}),[a,r]=p.useState(!1),[c,o]=p.useState(null),[i,n]=p.useState(null),[l,d]=p.useState("daily"),m=Je(),h=p.useCallback(async()=>{r(!0);try{await m()}finally{r(!1)}},[m]),u=p.useMemo(()=>({startDate:s?.from,endDate:s?.to}),[s?.from,s?.to]),{data:S,isLoading:y}=Qe(u),{data:v,isLoading:k}=Ve(u),{data:L,isLoading:q}=Ze(u),{data:R,isLoading:O}=Xe(u),{data:z,isLoading:K}=ss({...u,limit:3}),{data:E}=es(),de=p.useCallback(()=>{const P=new Date;t({from:T(P,1),to:P}),d("hourly")},[]),xe=p.useCallback(P=>{t(P),d("daily")},[]),ue=p.useMemo(()=>E?.lastFetch?Q(new Date(E.lastFetch),{addSuffix:!0}):null,[E?.lastFetch]),me=p.useCallback((P,fe)=>{const G=fe.currentTarget.getBoundingClientRect();n({x:G.left+G.width/2,y:G.top+G.height/2}),o(P)},[]),he=p.useCallback(()=>{o(null),n(null)},[]);return{dateRange:s,isRefreshing:a,viewMode:l,selectedModel:c,popoverPosition:i,summary:S,trends:v,hourlyData:L,models:R,sessions:z,status:E,isSummaryLoading:y,isTrendsLoading:k,isHourlyLoading:q,isModelsLoading:O,isSessionsLoading:K,isLoading:y||k||O||K,handleRefresh:h,handleTodayClick:de,handleDateRangeChange:xe,handleModelClick:me,handlePopoverClose:he,lastUpdatedText:ue}}function as({value:s,onChange:t,presets:a=[{label:"Last 7 days",range:{from:T(new Date,7),to:new Date}},{label:"Last 30 days",range:{from:T(new Date,30),to:new Date}},{label:"Last 90 days",range:{from:T(new Date,90),to:new Date}}],className:r}){const[c,o]=pe.useState(!1),{t:i}=$(),n=l=>!s||!s.from||!s.to||!l.from||!l.to?!1:C(s.from,"yyyy-MM-dd")===C(l.from,"yyyy-MM-dd")&&C(s.to,"yyyy-MM-dd")===C(l.to,"yyyy-MM-dd");return e.jsxs("div",{className:x("flex flex-wrap items-center gap-2",r),children:[a.map(l=>e.jsx(_,{variant:n(l.range)?"default":"outline",size:"sm",onClick:()=>t(l.range),children:l.label},l.label)),e.jsxs(se,{open:c,onOpenChange:o,children:[e.jsx(ge,{asChild:!0,children:e.jsxs(_,{id:"date",variant:"outline",className:x("w-auto min-w-[200px] sm:min-w-[240px] justify-start text-left font-normal",!s&&"text-muted-foreground"),children:[e.jsx(Se,{className:"mr-2 h-4 w-4"}),s?.from?s.to?e.jsxs(e.Fragment,{children:[C(s.from,"LLL dd, y")," - ",C(s.to,"LLL dd, y")]}):C(s.from,"LLL dd, y"):e.jsx("span",{children:i("dateRangeFilter.pickADate")})]})}),e.jsx(te,{className:"w-auto p-0",align:"end",children:e.jsx(je,{initialFocus:!0,mode:"range",defaultMonth:s?.from,selected:s,onSelect:t,numberOfMonths:2})})]})]})}function rs({dateRange:s,onDateRangeChange:t,onTodayClick:a,onRefresh:r,isRefreshing:c,lastUpdatedText:o,viewMode:i}){const{t:n}=$();return e.jsxs("div",{className:"flex flex-col gap-3 shrink-0 xl:flex-row xl:items-center xl:justify-between",children:[e.jsxs("div",{children:[e.jsx("h1",{className:"text-xl font-semibold",children:n("analytics.title")}),e.jsx("p",{className:"text-sm text-muted-foreground",children:n("analytics.subtitle")})]}),e.jsxs("div",{className:"flex flex-wrap items-center gap-2 xl:justify-end",children:[e.jsx(_,{variant:i==="hourly"?"default":"outline",size:"sm",className:"h-8",onClick:a,children:"24H"}),e.jsx(as,{className:"flex-wrap",value:s,onChange:t,presets:[{label:"7D",range:{from:T(new Date,7),to:new Date}},{label:"30D",range:{from:T(new Date,30),to:new Date}},{label:n("analytics.month"),range:{from:Ae(new Date),to:new Date}},{label:n("analytics.allTime"),range:{from:void 0,to:new Date}}]}),o&&e.jsx("span",{className:"text-xs text-muted-foreground whitespace-nowrap",children:n("analytics.updated",{value:o})}),e.jsx(_,{variant:"outline",size:"sm",className:"gap-2 h-8",onClick:r,disabled:c,children:e.jsx(De,{className:`w-3.5 h-3.5 ${c?"animate-spin":""}`})})]})]})}function ns({data:s,isLoading:t,granularity:a="daily",className:r}){const{privacyMode:c}=A(),{t:o}=$(),i=p.useMemo(()=>!s||s.length===0?[]:s.map(d=>{const m="hour"in d?d.hour:d.date;return{...d,dateFormatted:ls(m,a),costRounded:Number(d.cost.toFixed(4))}}),[s,a]);if(t)return e.jsx(f,{className:x("h-full w-full",r)});if(!s||s.length===0)return e.jsx("div",{className:x("h-full flex items-center justify-center",r),children:e.jsx("p",{className:"text-muted-foreground",children:o(a==="hourly"?"analytics.noDailyUsage":"analytics.noUsageData")})});const n=({x:l,y:d,payload:m,isRight:h})=>{const u=h?`$${m.value}`:J(Number(m.value));return e.jsx("text",{x:l,y:d,dy:4,textAnchor:h?"start":"end",fontSize:12,fill:"currentColor",className:x("fill-muted-foreground",c&&"blur-[4px]"),children:u})};return e.jsx("div",{className:x("w-full h-full",r),children:e.jsx(oe,{width:"100%",height:"100%",children:e.jsxs(Ue,{data:i,margin:{top:5,right:30,left:20,bottom:5},children:[e.jsxs("defs",{children:[e.jsxs("linearGradient",{id:"tokenGradient",x1:"0",y1:"0",x2:"0",y2:"1",children:[e.jsx("stop",{offset:"5%",stopColor:"#0080FF",stopOpacity:.8}),e.jsx("stop",{offset:"95%",stopColor:"#0080FF",stopOpacity:.1})]}),e.jsxs("linearGradient",{id:"costGradient",x1:"0",y1:"0",x2:"0",y2:"1",children:[e.jsx("stop",{offset:"5%",stopColor:"#00C49F",stopOpacity:.8}),e.jsx("stop",{offset:"95%",stopColor:"#00C49F",stopOpacity:.1})]})]}),e.jsx(qe,{strokeDasharray:"3 3",className:"stroke-muted"}),e.jsx(Oe,{dataKey:"dateFormatted",tick:{fontSize:12},tickLine:!1,axisLine:{className:"stroke-muted"}}),e.jsx(Z,{yAxisId:"left",orientation:"left",tick:l=>e.jsx(n,{...l,isRight:!1}),tickLine:!1,axisLine:{className:"stroke-muted"}}),e.jsx(Z,{yAxisId:"right",orientation:"right",tick:l=>e.jsx(n,{...l,isRight:!0}),tickLine:!1,axisLine:{className:"stroke-muted"}}),e.jsx(ce,{content:({active:l,payload:d,label:m})=>{if(!l||!d||!d.length)return null;const h=d[0].payload;return e.jsxs("div",{className:"rounded-lg border bg-background p-3 shadow-lg",children:[e.jsx("p",{className:"font-medium mb-2",children:m}),d.map((u,S)=>e.jsxs("p",{className:x("text-sm",c&&w),style:{color:u.color},children:[u.name,":"," ",u.name==="Tokens"?J(Number(u.value)||0):`$${u.value}`]},S)),"requests"in h&&e.jsxs("p",{className:x("text-sm text-muted-foreground mt-1",c&&w),children:["Requests: ",h.requests]})]})}}),e.jsx(X,{yAxisId:"left",type:"monotone",dataKey:"tokens",stroke:"#0080FF",strokeWidth:2,fillOpacity:1,fill:"url(#tokenGradient)",name:"Tokens"}),e.jsx(X,{yAxisId:"right",type:"monotone",dataKey:"costRounded",stroke:"#00C49F",strokeWidth:2,fillOpacity:1,fill:"url(#costGradient)",name:"Cost"})]})})})}function ls(s,t){if(t==="hourly"){const[r,c]=s.split(" ");if(r&&c){const o=new Date(`${r}T${c}:00Z`);return C(o,"HH:mm")}return s}const a=new Date(s);return t==="monthly"?C(a,"MMM yyyy"):C(a,"MMM dd")}function J(s){return s>=1e6?`${(s/1e6).toFixed(1)}M`:s>=1e3?`${(s/1e3).toFixed(1)}K`:s.toLocaleString()}function is({data:s,isLoading:t,className:a}){const{privacyMode:r}=A(),{t:c}=$(),o=p.useMemo(()=>!s||s.length===0?[]:s.map(l=>({name:l.model,value:l.tokens,cost:l.cost,percentage:l.percentage,fill:ae(l.model)})),[s]);if(t)return e.jsx(f,{className:x("h-full min-h-[100px] w-full",a)});if(!s||s.length===0)return e.jsx("div",{className:x("h-full min-h-[100px] flex items-center justify-center",a),children:e.jsx("p",{className:"text-muted-foreground",children:c("analyticsCards.noModelData")})});const i=({active:l,payload:d})=>{if(!l||!d)return null;const m=d;if(!m.length)return null;const h=m[0].payload;return e.jsxs("div",{className:"rounded-lg border bg-background p-2 shadow-lg text-xs",children:[e.jsx("p",{className:"font-medium mb-1",children:h.name}),e.jsxs("p",{className:x("text-muted-foreground",r&&w),children:[os(h.value)," (",h.percentage.toFixed(1),"%)"]}),e.jsxs("p",{className:x("text-muted-foreground",r&&w),children:["$",h.cost.toFixed(4)]})]})},n=l=>l.percentage>5?`${l.percentage.toFixed(1)}%`:"";return e.jsx("div",{className:x("w-full h-full min-h-[100px]",a),children:e.jsx(oe,{width:"100%",height:"100%",children:e.jsxs(Ie,{children:[e.jsx(Ke,{data:o,cx:"50%",cy:"50%",labelLine:!1,label:n,innerRadius:50,outerRadius:70,paddingAngle:2,dataKey:"value",children:o.map((l,d)=>e.jsx(Ee,{fill:l.fill,strokeWidth:1},`cell-${d}`))}),e.jsx(ce,{content:i})]})})})}function os(s){return s>=1e6?`${(s/1e6).toFixed(1)}M`:s>=1e3?`${(s/1e3).toFixed(1)}K`:s.toLocaleString()}function cs(s){if(!s)return"";const a=s.replace(/^\/|\/$/g,"").split("/").filter(r=>r.length>0);return a[a.length-1]||""}function ds({data:s,isLoading:t,className:a}){const{privacyMode:r}=A(),{t:c}=$(),o=p.useMemo(()=>{if(!s?.sessions||s.sessions.length===0)return null;const i=s.sessions,n=s.total,l=i.reduce((y,v)=>y+(v.inputTokens+v.outputTokens),0),d=Math.round(l/i.length),h=i.reduce((y,v)=>y+v.cost,0)/i.length,u=i[0],S=u?Q(new Date(u.lastActivity),{addSuffix:!0}):"N/A";return{totalSessions:n,avgTokens:d,avgCost:h,lastActive:S,recentSessions:i.slice(0,3)}},[s]);return t?e.jsxs(g,{className:x("flex flex-col h-full min-h-0 overflow-hidden gap-0 py-0",a),children:[e.jsx(N,{className:"px-3 py-2",children:e.jsx(f,{className:"h-5 w-32"})}),e.jsx(j,{className:"px-3 pb-3 pt-0 flex-1",children:e.jsx(f,{className:"h-full w-full"})})]}):o?e.jsxs(g,{className:x("flex flex-col h-full min-h-0 overflow-hidden gap-0 py-0 shadow-sm",a),children:[e.jsx(N,{className:"px-3 py-2",children:e.jsxs(D,{className:"text-base font-semibold flex items-center gap-2",children:[e.jsx(V,{className:"w-4 h-4"}),"Session Stats"]})}),e.jsxs(j,{className:"px-3 pb-3 pt-0 flex-1 min-h-0 flex flex-col gap-3",children:[e.jsxs("div",{className:"grid grid-cols-2 gap-2",children:[e.jsxs("div",{className:"p-2 rounded-md bg-muted/50 border text-center",children:[e.jsxs("div",{className:"flex items-center justify-center gap-1.5 text-blue-600 dark:text-blue-400",children:[e.jsx($e,{className:"w-4 h-4"}),e.jsx("span",{className:"text-xl font-bold",children:o.totalSessions})]}),e.jsx("p",{className:"text-[10px] text-muted-foreground uppercase tracking-wider mt-0.5",children:"Total Sessions"})]}),e.jsxs("div",{className:"p-2 rounded-md bg-muted/50 border text-center",children:[e.jsxs("div",{className:"flex items-center justify-center gap-1.5 text-green-600 dark:text-green-400",children:[e.jsx(ie,{className:"w-4 h-4"}),e.jsxs("span",{className:x("text-xl font-bold",r&&w),children:["$",o.avgCost.toFixed(2)]})]}),e.jsx("p",{className:"text-[10px] text-muted-foreground uppercase tracking-wider mt-0.5",children:"Avg Cost/Session"})]})]}),e.jsxs("div",{className:"flex-1 min-h-0 space-y-2",children:[e.jsxs("div",{className:"flex items-center gap-1 text-xs text-muted-foreground font-medium mb-1",children:[e.jsx(Le,{className:"w-3 h-3"}),"Recent Activity"]}),e.jsx("div",{className:"space-y-1.5 max-h-full overflow-y-auto pr-1",children:o.recentSessions.map(i=>e.jsxs("div",{className:"flex items-center justify-between text-xs p-1.5 rounded bg-muted/30 hover:bg-muted/50 transition-colors",children:[e.jsxs("div",{className:"flex flex-col min-w-0 flex-1",children:[e.jsxs("div",{className:"flex items-center gap-1",children:[e.jsx("span",{className:"font-medium truncate",title:i.projectPath,children:cs(i.projectPath)}),(i.target??"claude")!=="claude"&&e.jsx("span",{className:"shrink-0 px-1 py-0 text-[9px] font-medium rounded bg-purple-100 text-purple-700 dark:bg-purple-900/30 dark:text-purple-300 uppercase",children:i.target})]}),e.jsx("span",{className:"text-[10px] text-muted-foreground",children:Q(new Date(i.lastActivity),{addSuffix:!0})})]}),e.jsxs("div",{className:x("text-right shrink-0 ml-2",r&&w),children:[e.jsxs("div",{className:"font-mono",children:["$",i.cost.toFixed(2)]}),e.jsxs("div",{className:"text-[10px] text-muted-foreground",children:[xs(i.inputTokens+i.outputTokens)," toks"]})]})]},i.sessionId))})]})]})]}):e.jsxs(g,{className:x("flex flex-col h-full min-h-0 overflow-hidden gap-0 py-0",a),children:[e.jsx(N,{className:"px-3 py-2",children:e.jsxs(D,{className:"text-base font-semibold flex items-center gap-2",children:[e.jsx(V,{className:"w-4 h-4"}),"Session Stats"]})}),e.jsx(j,{className:"px-3 pb-3 pt-0 flex-1 flex items-center justify-center",children:e.jsx("p",{className:"text-sm text-muted-foreground text-center",children:c("analyticsCards.noSessionData")})})]})}function xs(s){return s>=1e9?`${(s/1e9).toFixed(1)}B`:s>=1e6?`${(s/1e6).toFixed(1)}M`:s>=1e3?`${(s/1e3).toFixed(1)}K`:s.toString()}function us({className:s,isLoading:t}){const{data:a,isLoading:r}=ye(),{data:c,isLoading:o,error:i}=Ne(a?.running),{t:n}=$();if(t||r||a?.running&&o)return e.jsxs(g,{className:x("flex flex-col h-full min-h-0 overflow-hidden gap-0 py-0",s),children:[e.jsx(N,{className:"px-3 py-2",children:e.jsxs(D,{className:"text-base font-semibold flex items-center gap-2",children:[e.jsx(H,{className:"h-4 w-4"}),"CLIProxy Stats"]})}),e.jsx(j,{className:"px-3 pb-3 pt-0 flex-1",children:e.jsxs("div",{className:"space-y-3",children:[e.jsx(f,{className:"h-4 w-[100px]"}),e.jsx(f,{className:"h-16 w-full"})]})})]});if(!a?.running)return e.jsxs(g,{className:x("flex flex-col h-full min-h-0 overflow-hidden gap-0 py-0 border-dashed",s),children:[e.jsx(N,{className:"px-3 py-2",children:e.jsxs("div",{className:"flex items-center justify-between",children:[e.jsxs(D,{className:"text-base font-semibold flex items-center gap-2",children:[e.jsx(H,{className:"h-4 w-4 text-muted-foreground"}),"CLIProxy Stats"]}),e.jsx(I,{variant:"secondary",className:"text-[10px] h-5",children:n("cliproxyStatsOverview.offline")})]})}),e.jsx(j,{className:"px-3 pb-3 pt-0 flex-1 flex items-center justify-center",children:e.jsx("p",{className:"text-xs text-muted-foreground text-center",children:n("cliproxyStatsOverview.noActiveSessionHint")})})]});if(i)return e.jsxs(g,{className:x("flex flex-col h-full min-h-0 overflow-hidden gap-0 py-0 border-destructive/50",s),children:[e.jsx(N,{className:"px-3 py-2",children:e.jsxs("div",{className:"flex items-center justify-between",children:[e.jsxs(D,{className:"text-base font-semibold flex items-center gap-2",children:[e.jsx(H,{className:"h-4 w-4"}),"CLIProxy Stats"]}),e.jsx(I,{variant:"destructive",className:"text-[10px] h-5",children:"Error"})]})}),e.jsx(j,{className:"px-3 pb-3 pt-0 flex-1",children:e.jsx("p",{className:"text-xs text-destructive",children:i.message})})]});const d=c?.totalRequests??0,m=c?.quotaExceededCount??0,h=d-m,u=d>0?Math.round(h/d*100):100,S=c?.tokens?.total??0,y=Object.entries(c?.requestsByModel??{}).sort((k,L)=>L[1]-k[1]).slice(0,4),v=y.length>0?y[0][1]:1;return e.jsxs(g,{className:x("flex flex-col h-full min-h-0 overflow-hidden gap-0 py-0",s),children:[e.jsx(N,{className:"px-3 py-2 border-b bg-muted/5",children:e.jsxs("div",{className:"flex items-center justify-between",children:[e.jsxs(D,{className:"text-base font-semibold flex items-center gap-2",children:[e.jsx(H,{className:"h-4 w-4"}),"CLIProxy Stats"]}),e.jsxs(I,{variant:"outline",className:"text-[10px] h-5 text-green-600 border-green-200 bg-green-50 dark:bg-green-900/10 dark:border-green-800",children:[e.jsx(ie,{className:"h-3 w-3 mr-0.5"}),n("cliproxyStatsOverview.running")]})]})}),e.jsx(j,{className:"p-0 flex-1 min-h-0",children:e.jsx(we,{className:"h-full",children:e.jsxs("div",{className:"p-3 space-y-3",children:[e.jsxs("div",{className:"grid grid-cols-2 gap-2",children:[e.jsxs("div",{className:"flex items-center gap-2 p-2 rounded-lg bg-muted/30",children:[e.jsxs("div",{className:"relative",children:[e.jsxs("svg",{className:"w-10 h-10 -rotate-90",viewBox:"0 0 36 36",children:[e.jsx("circle",{cx:"18",cy:"18",r:"14",fill:"none",stroke:"currentColor",strokeWidth:"3",className:"text-muted/30"}),e.jsx("circle",{cx:"18",cy:"18",r:"14",fill:"none",stroke:"currentColor",strokeWidth:"3",strokeDasharray:`${u*.88} 88`,strokeLinecap:"round",className:u>=90?"text-green-500":"text-amber-500"})]}),e.jsxs("span",{className:"absolute inset-0 flex items-center justify-center text-[8px] font-bold",children:[u,"%"]})]}),e.jsxs("div",{className:"min-w-0",children:[e.jsx("div",{className:"text-lg font-bold leading-none",children:ee(d)}),e.jsx("div",{className:"text-[9px] text-muted-foreground mt-0.5",children:m>0?`${m} failed`:"All success"})]})]}),e.jsxs("div",{className:"flex items-center gap-2 p-2 rounded-lg bg-muted/30",children:[e.jsx("div",{className:"p-1.5 rounded-md bg-purple-100 dark:bg-purple-900/20",children:e.jsx(Fe,{className:"h-4 w-4 text-purple-600"})}),e.jsxs("div",{className:"min-w-0",children:[e.jsx("div",{className:"text-lg font-bold leading-none",children:ee(S)}),e.jsx("div",{className:"text-[9px] text-muted-foreground mt-0.5",children:n("cliproxyStatsOverview.totalTokens")})]})]})]}),y.length>0&&e.jsxs("div",{className:"space-y-1.5",children:[e.jsxs("div",{className:"flex items-center gap-1.5 text-[10px] font-medium text-muted-foreground",children:[e.jsx(Re,{className:"h-3 w-3"}),n("cliproxyStatsOverview.modelsUsed")]}),e.jsx("div",{className:"space-y-1",children:y.map(([k,L])=>{const q=Math.round(L/v*100),R=ms(k);return e.jsxs("div",{className:"group",children:[e.jsxs("div",{className:"flex items-center justify-between text-[10px] mb-0.5",children:[e.jsx("span",{className:"truncate font-medium",title:k,children:R}),e.jsx("span",{className:"text-muted-foreground shrink-0 ml-2",children:L})]}),e.jsx("div",{className:"h-1 bg-muted/50 rounded-full overflow-hidden",children:e.jsx("div",{className:"h-full bg-accent/70 rounded-full transition-all",style:{width:`${q}%`}})})]},k)})})]})]})})})]})}function ee(s){return s>=1e6?`${(s/1e6).toFixed(1)}M`:s>=1e3?`${(s/1e3).toFixed(1)}K`:s.toLocaleString()}function ms(s){let t=s.replace(/^gemini-claude-/,"").replace(/^gemini-/,"").replace(/^claude-/,"").replace(/^anthropic\./,"").replace(/-thinking$/," Thinking");return t=t.split(/[-_]/).map(a=>a.charAt(0).toUpperCase()+a.slice(1)).join(" "),t.length>20&&(t=t.slice(0,18)+"..."),t}function hs(s){return s>=1e9?`${(s/1e9).toFixed(1)}B`:s>=1e6?`${(s/1e6).toFixed(1)}M`:s>=1e3?`${(s/1e3).toFixed(0)}K`:s.toString()}function fs({models:s,isLoading:t,onModelClick:a,privacyMode:r}){const{t:c}=$();return e.jsxs(g,{className:"flex flex-col h-full min-h-0 overflow-hidden gap-0 py-0 shadow-sm lg:col-span-4",children:[e.jsx(N,{className:"px-3 py-2",children:e.jsxs(D,{className:"text-base font-semibold flex items-center gap-2",children:[e.jsx(re,{className:"w-4 h-4"}),c("analyticsPages.costByModel")]})}),e.jsx(j,{className:"px-2 pb-2 pt-0 flex-1 min-h-0 overflow-y-auto",children:t?e.jsx(f,{className:"h-full w-full"}):e.jsxs("div",{className:"space-y-0.5",children:[[...s||[]].sort((o,i)=>i.cost-o.cost).map(o=>e.jsxs("button",{className:"group flex items-center text-xs w-full hover:bg-muted/50 rounded px-2 py-1.5 transition-colors cursor-pointer gap-3",onClick:i=>a(o,i),title:"Click for details",children:[e.jsxs("div",{className:"flex items-center gap-2 min-w-0 w-[180px] shrink-0",children:[e.jsx("div",{className:"w-2 h-2 rounded-full shrink-0",style:{backgroundColor:ae(o.model)}}),e.jsx("span",{className:"font-medium truncate group-hover:underline underline-offset-2",children:o.model})]}),e.jsx(ps,{model:o}),e.jsx("span",{className:x("text-[10px] text-muted-foreground w-14 text-right shrink-0",r&&w),children:hs(o.tokens)}),e.jsxs("span",{className:x("font-mono font-medium w-16 text-right shrink-0",r&&w),children:["$",o.cost.toFixed(2)]}),e.jsx(Te,{className:"w-3 h-3 opacity-0 group-hover:opacity-50 transition-opacity shrink-0"})]},o.model)),e.jsx(gs,{})]})})]})}function ps({model:s}){const t={input:"#335c67",output:"#fff3b0",cacheWrite:"#e09f3e",cacheRead:"#9e2a2b"},a=r=>s.cost>0?r/s.cost*100:0;return e.jsx("div",{className:"flex-1 flex items-center gap-1 min-w-0",children:e.jsxs("div",{className:"flex-1 h-2 bg-muted rounded-full overflow-hidden flex",children:[e.jsx("div",{className:"h-full",style:{backgroundColor:t.input,width:`${a(s.costBreakdown.input.cost)}%`},title:`Input: $${s.costBreakdown.input.cost.toFixed(2)}`}),e.jsx("div",{className:"h-full",style:{backgroundColor:t.output,width:`${a(s.costBreakdown.output.cost)}%`},title:`Output: $${s.costBreakdown.output.cost.toFixed(2)}`}),e.jsx("div",{className:"h-full",style:{backgroundColor:t.cacheWrite,width:`${a(s.costBreakdown.cacheCreation.cost)}%`},title:`Cache Write: $${s.costBreakdown.cacheCreation.cost.toFixed(2)}`}),e.jsx("div",{className:"h-full",style:{backgroundColor:t.cacheRead,width:`${a(s.costBreakdown.cacheRead.cost)}%`},title:`Cache Read: $${s.costBreakdown.cacheRead.cost.toFixed(2)}`})]})})}function gs(){const s=[{color:"#335c67",label:"Input"},{color:"#fff3b0",label:"Output",hasBorder:!0},{color:"#e09f3e",label:"Cache Write"},{color:"#9e2a2b",label:"Cache Read"}];return e.jsx("div",{className:"flex items-center gap-3 pt-2 px-2 text-[10px] text-muted-foreground border-t mt-2",children:s.map(({color:t,label:a,hasBorder:r})=>e.jsxs("span",{className:"flex items-center gap-1",children:[e.jsx("div",{className:x("w-2 h-2 rounded-full",r&&"border border-muted-foreground/30"),style:{backgroundColor:t}}),a]},a))})}function js({viewMode:s,trends:t,hourlyData:a,models:r,sessions:c,isTrendsLoading:o,isHourlyLoading:i,isModelsLoading:n,isSessionsLoading:l,isSummaryLoading:d,onModelClick:m}){const{privacyMode:h}=A();return e.jsxs("div",{className:"min-h-0 grid gap-4 lg:grid-rows-[minmax(260px,1.2fr)_minmax(220px,0.9fr)]",children:[e.jsxs(g,{className:"flex flex-col h-full min-h-[220px] lg:min-h-[240px] overflow-hidden gap-0 py-0 shadow-sm",children:[e.jsx(N,{className:"px-3 py-2 shrink-0",children:e.jsxs(D,{className:"text-base font-semibold flex items-center gap-2",children:[e.jsx(Me,{className:"w-4 h-4"}),s==="hourly"?"Last 24 Hours":"Usage Trends"]})}),e.jsx(j,{className:"px-3 pb-3 pt-0 flex-1 min-h-0",children:e.jsx(ns,{data:s==="hourly"?a||[]:t||[],isLoading:s==="hourly"?i:o,granularity:s==="hourly"?"hourly":"daily"})})]}),e.jsxs("div",{className:"grid grid-cols-1 lg:grid-cols-10 gap-4 h-auto min-h-[220px] lg:h-full lg:min-h-[220px] lg:grid-rows-[minmax(0,1fr)] lg:[&>*]:min-h-0",children:[e.jsx(fs,{models:r,isLoading:n,onModelClick:m,privacyMode:h}),e.jsxs(g,{className:"flex flex-col h-full min-h-0 overflow-hidden gap-0 py-0 shadow-sm lg:col-span-2",children:[e.jsx(N,{className:"px-3 py-2",children:e.jsxs(D,{className:"text-base font-semibold flex items-center gap-2",children:[e.jsx(Pe,{className:"w-4 h-4"}),"Model Usage"]})}),e.jsx(j,{className:"px-2 pb-2 pt-0 flex-1 min-h-0 flex items-center justify-center",children:e.jsx(is,{data:r||[],isLoading:n,className:"h-full w-full"})})]}),e.jsx(ds,{data:c,isLoading:l,className:"lg:col-span-2"}),e.jsx(us,{isLoading:d,className:"lg:col-span-2"})]})]})}function Ls(){return e.jsxs("div",{className:"space-y-4 h-full overflow-hidden",children:[e.jsxs(g,{className:"flex flex-col min-h-[300px]",children:[e.jsx(N,{className:"p-4 pb-2",children:e.jsx(f,{className:"h-4 w-32"})}),e.jsx(j,{className:"p-4 pt-0 flex-1",children:e.jsx(f,{className:"h-full w-full"})})]}),e.jsxs("div",{className:"grid grid-cols-1 lg:grid-cols-2 gap-4",children:[e.jsxs(g,{className:"flex flex-col min-h-[250px]",children:[e.jsx(N,{className:"p-4 pb-2",children:e.jsx(f,{className:"h-4 w-28"})}),e.jsx(j,{className:"p-4 pt-2",children:e.jsx("div",{className:"space-y-3",children:[1,2,3,4,5].map(s=>e.jsxs("div",{className:"flex justify-between items-center",children:[e.jsxs("div",{className:"flex items-center gap-2",children:[e.jsx(f,{className:"w-2.5 h-2.5 rounded-full"}),e.jsx(f,{className:"h-3 w-24"})]}),e.jsx(f,{className:"h-3 w-16"})]},s))})})]}),e.jsxs(g,{className:"flex flex-col min-h-[250px]",children:[e.jsx(N,{className:"p-4 pb-2",children:e.jsx(f,{className:"h-4 w-28"})}),e.jsx(j,{className:"p-4 pt-0 flex-1",children:e.jsxs("div",{className:"flex w-full h-full items-center",children:[e.jsx("div",{className:"flex-1 flex justify-center",children:e.jsx(f,{className:"h-[180px] w-[180px] rounded-full"})}),e.jsx("div",{className:"w-[140px] shrink-0 pl-2 space-y-2",children:[1,2,3,4].map(s=>e.jsxs("div",{className:"flex items-center gap-2",children:[e.jsx(f,{className:"w-2 h-2 rounded-full"}),e.jsx(f,{className:"h-3 w-20"})]},s))})]})})]})]})]})}function Fs(){const s=p.useRef(null),{dateRange:t,handleDateRangeChange:a,handleTodayClick:r,handleRefresh:c,isRefreshing:o,lastUpdatedText:i,viewMode:n,summary:l,isSummaryLoading:d,trends:m,hourlyData:h,models:u,sessions:S,isTrendsLoading:y,isHourlyLoading:v,isModelsLoading:k,isSessionsLoading:L,handleModelClick:q,selectedModel:R,popoverPosition:O,handlePopoverClose:z}=ts();return e.jsxs("div",{className:"grid h-full min-h-0 grid-rows-[auto_auto_minmax(0,1fr)] gap-4 overflow-y-auto px-4 py-4",children:[e.jsx(rs,{dateRange:t,onDateRangeChange:a,onTodayClick:r,onRefresh:c,isRefreshing:o,lastUpdatedText:i,viewMode:n}),e.jsx(Ge,{data:l,isLoading:d}),e.jsx(js,{viewMode:n,trends:m,hourlyData:h,models:u,sessions:S,isTrendsLoading:y,isHourlyLoading:v,isModelsLoading:k,isSessionsLoading:L,isSummaryLoading:d,onModelClick:q}),e.jsxs(se,{open:!!R,onOpenChange:K=>!K&&z(),children:[e.jsx(be,{asChild:!0,children:e.jsx("div",{ref:s,className:"fixed pointer-events-none",style:{left:O?.x??0,top:O?.y??0,width:1,height:1}})}),e.jsx(te,{className:"w-80 p-3",side:"top",align:"center",children:R&&e.jsx(He,{model:R})})]})]})}export{Fs as AnalyticsPage,Ls as AnalyticsSkeleton};
|
|
1
|
+
import{j as e}from"./radix-ui-Zb8sVEtn.js";import{r as p,c as pe}from"./react-vendor-CNOkPC89.js";import{u as A,a as $,C as g,b as j,S as f,c as x,P as w,B as I,d as _,e as se,f as ge,g as te,h as je,i as ae,j as N,k as D,l as ye,m as Ne,n as we,o as be}from"./index-DhAjOd4r.js";import{a3 as ve,am as re,an as Y,ao as ne,a1 as le,aa as ke,G as Ce,ap as Se,R as De,$ as V,U as $e,Z as ie,v as Le,ae as H,aq as Fe,Y as Re,C as Te,ar as Me,as as Pe}from"./icons-DyorC3Xk.js";import{a as Be,u as U}from"./tanstack-CrmUhA7Z.js";import{K as T,L as Q,f as C,H as Ae}from"./utils-CzKF5WmX.js";import{R as oe,A as Ue,C as qe,X as Oe,Y as Z,T as ce,a as X,P as Ie,b as Ke,c as Ee}from"./charts-BBPXh0Ar.js";import"./notifications-B2HqRBj7.js";import"./form-utils-Bcoyqxpq.js";import"./code-highlight-BRUf_pqB.js";function Ge({data:s,isLoading:t}){const{privacyMode:a}=A(),{t:r}=$();if(t)return e.jsx("div",{className:"grid grid-cols-2 md:grid-cols-3 lg:grid-cols-5 gap-4",children:[1,2,3,4,5].map(n=>e.jsx(g,{children:e.jsx(j,{className:"p-6",children:e.jsxs("div",{className:"flex items-center justify-between",children:[e.jsxs("div",{className:"space-y-2",children:[e.jsx(f,{className:"h-4 w-[100px]"}),e.jsx(f,{className:"h-8 w-[80px]"})]}),e.jsx(f,{className:"h-8 w-8 rounded-lg"})]})})},n))});const c=(s?.tokenBreakdown?.cacheCreation?.cost??0)+(s?.tokenBreakdown?.cacheRead?.cost??0),o=s?.totalCost?Math.round(c/s.totalCost*100):0,i=[{title:r("analyticsSummary.totalTokens"),value:s?.totalTokens??0,icon:ve,format:n=>B(n),color:"text-blue-600",bgColor:"bg-blue-100 dark:bg-blue-900/20",subtitle:r("analyticsSummary.totalTokensSubtitle",{input:B(s?.totalInputTokens??0),output:B(s?.totalOutputTokens??0)})},{title:r("analyticsSummary.totalCost"),value:s?.totalCost??0,icon:re,format:n=>`$${n.toFixed(2)}`,color:"text-green-600",bgColor:"bg-green-100 dark:bg-green-900/20",subtitle:r("analyticsSummary.totalCostSubtitle",{value:s?.averageCostPerDay?.toFixed(2)??"0.00"})},{title:r("analyticsSummary.cacheTokens"),value:s?.totalCacheTokens??0,icon:Y,format:n=>B(n),color:"text-cyan-600",bgColor:"bg-cyan-100 dark:bg-cyan-900/20",subtitle:r("analyticsSummary.cacheTokensSubtitle",{cost:c.toFixed(2),percent:o})},{title:r("analyticsSummary.inputCost"),value:s?.tokenBreakdown?.input?.cost??0,icon:ne,format:n=>`$${n.toFixed(2)}`,color:"text-purple-600",bgColor:"bg-purple-100 dark:bg-purple-900/20",subtitle:r("analyticsSummary.tokensSubtitle",{value:B(s?.tokenBreakdown?.input?.tokens??0)})},{title:r("analyticsSummary.outputCost"),value:s?.tokenBreakdown?.output?.cost??0,icon:le,format:n=>`$${n.toFixed(2)}`,color:"text-orange-600",bgColor:"bg-orange-100 dark:bg-orange-900/20",subtitle:r("analyticsSummary.tokensSubtitle",{value:B(s?.tokenBreakdown?.output?.tokens??0)})}];return e.jsx("div",{className:"grid grid-cols-2 md:grid-cols-3 lg:grid-cols-5 gap-4",children:i.map((n,l)=>{const d=n.icon;return e.jsx(g,{className:"hover:shadow-md transition-shadow",children:e.jsx(j,{className:"p-4",children:e.jsxs("div",{className:"flex items-center justify-between space-x-2",children:[e.jsxs("div",{className:"space-y-1 min-w-0",children:[e.jsx("p",{className:"text-xs font-medium text-muted-foreground truncate",children:n.title}),e.jsx("p",{className:x("text-xl font-bold truncate",a&&w),children:n.format(n.value)}),n.subtitle&&e.jsx("p",{className:x("text-[10px] text-muted-foreground truncate",a&&w),children:n.subtitle})]}),e.jsx("div",{className:x("p-2 rounded-lg shrink-0",n.bgColor),children:e.jsx(d,{className:x("h-4 w-4",n.color)})})]})})},l)})})}function B(s){return s>=1e6?`${(s/1e6).toFixed(1)}M`:s>=1e3?`${(s/1e3).toFixed(1)}K`:s.toLocaleString()}function He({model:s}){const{privacyMode:t}=A(),{t:a}=$(),r=We(s.ioRatio);return e.jsxs("div",{className:"space-y-4",children:[e.jsxs("div",{className:"space-y-2",children:[e.jsxs("div",{className:"flex items-center gap-2",children:[e.jsx(ke,{className:"h-4 w-4 text-primary shrink-0"}),e.jsx("h4",{className:"font-semibold leading-none truncate",title:s.model,children:s.model})]}),e.jsxs("div",{className:"flex flex-wrap gap-2",children:[e.jsxs(I,{variant:"secondary",className:"text-[10px] h-5 px-1.5",children:[s.percentage.toFixed(1),"% usage"]}),e.jsxs(I,{variant:r.variant,className:"text-[10px] h-5 px-1.5",children:[s.ioRatio.toFixed(0),":1 I/O"]})]})]}),e.jsxs("div",{className:"grid grid-cols-2 gap-2",children:[e.jsxs("div",{className:"p-2 rounded-md bg-muted/50 border text-center",children:[e.jsxs("p",{className:x("text-lg font-bold",t&&w),children:["$",s.cost.toFixed(2)]}),e.jsx("p",{className:"text-[10px] text-muted-foreground uppercase tracking-wider",children:a("analyticsCards.totalCost")})]}),e.jsxs("div",{className:"p-2 rounded-md bg-muted/50 border text-center",children:[e.jsx("p",{className:x("text-lg font-bold",t&&w),children:ze(s.tokens)}),e.jsx("p",{className:"text-[10px] text-muted-foreground uppercase tracking-wider",children:a("analyticsCards.totalTokens")})]})]}),e.jsxs("div",{className:"space-y-2",children:[e.jsx("h5",{className:"text-[11px] font-medium text-muted-foreground uppercase tracking-wider",children:"Token Breakdown"}),e.jsxs("div",{className:x("space-y-1",t&&w),children:[e.jsx(W,{label:"Input",tokens:s.inputTokens,cost:s.costBreakdown.input.cost,color:"#335c67",icon:ne}),e.jsx(W,{label:"Output",tokens:s.outputTokens,cost:s.costBreakdown.output.cost,color:"#fff3b0",icon:le}),e.jsx(W,{label:"Cache Write",tokens:s.cacheCreationTokens,cost:s.costBreakdown.cacheCreation.cost,color:"#e09f3e",icon:Y}),e.jsx(W,{label:"Cache Read",tokens:s.cacheReadTokens,cost:s.costBreakdown.cacheRead.cost,color:"#9e2a2b",icon:Y})]})]}),e.jsxs("div",{className:"p-2.5 rounded-md border bg-muted/20 space-y-1.5",children:[e.jsxs("div",{className:"flex items-center gap-2",children:[e.jsx(Ce,{className:"h-3.5 w-3.5 text-muted-foreground"}),e.jsx("span",{className:"text-xs font-medium",children:a("analyticsCards.inputOutputRatio")})]}),e.jsx("p",{className:"text-[11px] text-muted-foreground leading-snug",children:r.description})]})]})}function W({label:s,tokens:t,cost:a,color:r,icon:c}){return t===0?null:e.jsxs("div",{className:"flex items-center gap-2 text-xs",children:[e.jsx("div",{className:"w-1 h-6 rounded-full shrink-0",style:{backgroundColor:r}}),e.jsxs("div",{className:"flex-1 min-w-0",children:[e.jsxs("div",{className:"flex items-center justify-between",children:[e.jsx("span",{className:"font-medium truncate",children:s}),e.jsxs("span",{className:"font-mono text-muted-foreground",children:["$",a.toFixed(3)]})]}),e.jsxs("div",{className:"flex items-center gap-1.5 text-muted-foreground",children:[e.jsx(c,{className:"h-3 w-3 shrink-0"}),e.jsx("span",{children:_e(t)})]})]})]})}function We(s){return s>=200?{variant:"destructive",description:"Extended thinking or large context loading. Expected for reasoning models."}:s>=50?{variant:"secondary",description:"More input than output. Typical for analysis tasks."}:s>=5?{variant:"outline",description:"Balanced input/output ratio for typical coding tasks."}:{variant:"default",description:"More output than input. Generation-heavy workload."}}function _e(s){return s.toLocaleString()}function ze(s){return s>=1e9?`${(s/1e9).toFixed(1)}B`:s>=1e6?`${(s/1e6).toFixed(1)}M`:s>=1e3?`${(s/1e3).toFixed(1)}K`:s.toString()}const Ye="/api";function b(s){const t=s.getFullYear(),a=String(s.getMonth()+1).padStart(2,"0"),r=String(s.getDate()).padStart(2,"0");return`${t}${a}${r}`}const M={summary:s=>{const t=new URLSearchParams;return s?.startDate&&t.append("since",b(s.startDate)),s?.endDate&&t.append("until",b(s.endDate)),s?.profile&&t.append("profile",s.profile),F(`/usage/summary?${t}`)},trends:s=>{const t=new URLSearchParams;return s?.startDate&&t.append("since",b(s.startDate)),s?.endDate&&t.append("until",b(s.endDate)),s?.profile&&t.append("profile",s.profile),F(`/usage/daily?${t}`)},hourly:s=>{const t=new URLSearchParams;return s?.startDate&&t.append("since",b(s.startDate)),s?.endDate&&t.append("until",b(s.endDate)),F(`/usage/hourly?${t}`)},models:s=>{const t=new URLSearchParams;return s?.startDate&&t.append("since",b(s.startDate)),s?.endDate&&t.append("until",b(s.endDate)),s?.profile&&t.append("profile",s.profile),F(`/usage/models?${t}`)},sessions:s=>{const t=new URLSearchParams;return s?.startDate&&t.append("since",b(s.startDate)),s?.endDate&&t.append("until",b(s.endDate)),s?.profile&&t.append("profile",s.profile),s?.limit&&t.append("limit",s.limit.toString()),s?.offset&&t.append("offset",s.offset.toString()),F(`/usage/sessions?${t}`)},monthly:(s,t)=>{const a=new URLSearchParams;return s&&a.append("months",s.toString()),t&&a.append("profile",t),F(`/usage/monthly?${a}`)},refresh:async()=>{if(!(await fetch(`${Ye}/usage/refresh`,{method:"POST",headers:{"Content-Type":"application/json"}})).ok)throw new Error("Failed to refresh usage cache")},status:()=>F("/usage/status"),insights:s=>{const t=new URLSearchParams;return s?.startDate&&t.append("since",b(s.startDate)),s?.endDate&&t.append("until",b(s.endDate)),s?.profile&&t.append("profile",s.profile),F(`/usage/insights?${t}`)}};async function F(s){const a=await fetch(`/api${s}`,{headers:{"Content-Type":"application/json"}});if(!a.ok){const c=await a.json().catch(()=>({error:"Unknown error"}));throw new Error(c.error||a.statusText)}const r=await a.json();return r.data||r}function Qe(s){return U({queryKey:["usage","summary",s],queryFn:()=>M.summary(s),staleTime:60*1e3})}function Ve(s){return U({queryKey:["usage","trends",s],queryFn:()=>M.trends(s),staleTime:60*1e3})}function Ze(s){return U({queryKey:["usage","hourly",s],queryFn:()=>M.hourly(s),staleTime:60*1e3})}function Xe(s){return U({queryKey:["usage","models",s],queryFn:()=>M.models(s),staleTime:60*1e3})}function Je(){const s=Be();return p.useCallback(async()=>{await M.refresh(),await s.invalidateQueries({queryKey:["usage"]})},[s])}function es(){return U({queryKey:["usage","status"],queryFn:()=>M.status(),staleTime:10*1e3,refetchInterval:30*1e3})}function ss(s){return U({queryKey:["usage","sessions",s],queryFn:()=>M.sessions(s),staleTime:60*1e3})}function ts(){const[s,t]=p.useState({from:T(new Date,30),to:new Date}),[a,r]=p.useState(!1),[c,o]=p.useState(null),[i,n]=p.useState(null),[l,d]=p.useState("daily"),m=Je(),h=p.useCallback(async()=>{r(!0);try{await m()}finally{r(!1)}},[m]),u=p.useMemo(()=>({startDate:s?.from,endDate:s?.to}),[s?.from,s?.to]),{data:S,isLoading:y}=Qe(u),{data:v,isLoading:k}=Ve(u),{data:L,isLoading:q}=Ze(u),{data:R,isLoading:O}=Xe(u),{data:z,isLoading:K}=ss({...u,limit:3}),{data:E}=es(),de=p.useCallback(()=>{const P=new Date;t({from:T(P,1),to:P}),d("hourly")},[]),xe=p.useCallback(P=>{t(P),d("daily")},[]),ue=p.useMemo(()=>E?.lastFetch?Q(new Date(E.lastFetch),{addSuffix:!0}):null,[E?.lastFetch]),me=p.useCallback((P,fe)=>{const G=fe.currentTarget.getBoundingClientRect();n({x:G.left+G.width/2,y:G.top+G.height/2}),o(P)},[]),he=p.useCallback(()=>{o(null),n(null)},[]);return{dateRange:s,isRefreshing:a,viewMode:l,selectedModel:c,popoverPosition:i,summary:S,trends:v,hourlyData:L,models:R,sessions:z,status:E,isSummaryLoading:y,isTrendsLoading:k,isHourlyLoading:q,isModelsLoading:O,isSessionsLoading:K,isLoading:y||k||O||K,handleRefresh:h,handleTodayClick:de,handleDateRangeChange:xe,handleModelClick:me,handlePopoverClose:he,lastUpdatedText:ue}}function as({value:s,onChange:t,presets:a=[{label:"Last 7 days",range:{from:T(new Date,7),to:new Date}},{label:"Last 30 days",range:{from:T(new Date,30),to:new Date}},{label:"Last 90 days",range:{from:T(new Date,90),to:new Date}}],className:r}){const[c,o]=pe.useState(!1),{t:i}=$(),n=l=>!s||!s.from||!s.to||!l.from||!l.to?!1:C(s.from,"yyyy-MM-dd")===C(l.from,"yyyy-MM-dd")&&C(s.to,"yyyy-MM-dd")===C(l.to,"yyyy-MM-dd");return e.jsxs("div",{className:x("flex flex-wrap items-center gap-2",r),children:[a.map(l=>e.jsx(_,{variant:n(l.range)?"default":"outline",size:"sm",onClick:()=>t(l.range),children:l.label},l.label)),e.jsxs(se,{open:c,onOpenChange:o,children:[e.jsx(ge,{asChild:!0,children:e.jsxs(_,{id:"date",variant:"outline",className:x("w-auto min-w-[200px] sm:min-w-[240px] justify-start text-left font-normal",!s&&"text-muted-foreground"),children:[e.jsx(Se,{className:"mr-2 h-4 w-4"}),s?.from?s.to?e.jsxs(e.Fragment,{children:[C(s.from,"LLL dd, y")," - ",C(s.to,"LLL dd, y")]}):C(s.from,"LLL dd, y"):e.jsx("span",{children:i("dateRangeFilter.pickADate")})]})}),e.jsx(te,{className:"w-auto p-0",align:"end",children:e.jsx(je,{initialFocus:!0,mode:"range",defaultMonth:s?.from,selected:s,onSelect:t,numberOfMonths:2})})]})]})}function rs({dateRange:s,onDateRangeChange:t,onTodayClick:a,onRefresh:r,isRefreshing:c,lastUpdatedText:o,viewMode:i}){const{t:n}=$();return e.jsxs("div",{className:"flex flex-col gap-3 shrink-0 xl:flex-row xl:items-center xl:justify-between",children:[e.jsxs("div",{children:[e.jsx("h1",{className:"text-xl font-semibold",children:n("analytics.title")}),e.jsx("p",{className:"text-sm text-muted-foreground",children:n("analytics.subtitle")})]}),e.jsxs("div",{className:"flex flex-wrap items-center gap-2 xl:justify-end",children:[e.jsx(_,{variant:i==="hourly"?"default":"outline",size:"sm",className:"h-8",onClick:a,children:"24H"}),e.jsx(as,{className:"flex-wrap",value:s,onChange:t,presets:[{label:"7D",range:{from:T(new Date,7),to:new Date}},{label:"30D",range:{from:T(new Date,30),to:new Date}},{label:n("analytics.month"),range:{from:Ae(new Date),to:new Date}},{label:n("analytics.allTime"),range:{from:void 0,to:new Date}}]}),o&&e.jsx("span",{className:"text-xs text-muted-foreground whitespace-nowrap",children:n("analytics.updated",{value:o})}),e.jsx(_,{variant:"outline",size:"sm",className:"gap-2 h-8",onClick:r,disabled:c,children:e.jsx(De,{className:`w-3.5 h-3.5 ${c?"animate-spin":""}`})})]})]})}function ns({data:s,isLoading:t,granularity:a="daily",className:r}){const{privacyMode:c}=A(),{t:o}=$(),i=p.useMemo(()=>!s||s.length===0?[]:s.map(d=>{const m="hour"in d?d.hour:d.date;return{...d,dateFormatted:ls(m,a),costRounded:Number(d.cost.toFixed(4))}}),[s,a]);if(t)return e.jsx(f,{className:x("h-full w-full",r)});if(!s||s.length===0)return e.jsx("div",{className:x("h-full flex items-center justify-center",r),children:e.jsx("p",{className:"text-muted-foreground",children:o(a==="hourly"?"analytics.noDailyUsage":"analytics.noUsageData")})});const n=({x:l,y:d,payload:m,isRight:h})=>{const u=h?`$${m.value}`:J(Number(m.value));return e.jsx("text",{x:l,y:d,dy:4,textAnchor:h?"start":"end",fontSize:12,fill:"currentColor",className:x("fill-muted-foreground",c&&"blur-[4px]"),children:u})};return e.jsx("div",{className:x("w-full h-full",r),children:e.jsx(oe,{width:"100%",height:"100%",children:e.jsxs(Ue,{data:i,margin:{top:5,right:30,left:20,bottom:5},children:[e.jsxs("defs",{children:[e.jsxs("linearGradient",{id:"tokenGradient",x1:"0",y1:"0",x2:"0",y2:"1",children:[e.jsx("stop",{offset:"5%",stopColor:"#0080FF",stopOpacity:.8}),e.jsx("stop",{offset:"95%",stopColor:"#0080FF",stopOpacity:.1})]}),e.jsxs("linearGradient",{id:"costGradient",x1:"0",y1:"0",x2:"0",y2:"1",children:[e.jsx("stop",{offset:"5%",stopColor:"#00C49F",stopOpacity:.8}),e.jsx("stop",{offset:"95%",stopColor:"#00C49F",stopOpacity:.1})]})]}),e.jsx(qe,{strokeDasharray:"3 3",className:"stroke-muted"}),e.jsx(Oe,{dataKey:"dateFormatted",tick:{fontSize:12},tickLine:!1,axisLine:{className:"stroke-muted"}}),e.jsx(Z,{yAxisId:"left",orientation:"left",tick:l=>e.jsx(n,{...l,isRight:!1}),tickLine:!1,axisLine:{className:"stroke-muted"}}),e.jsx(Z,{yAxisId:"right",orientation:"right",tick:l=>e.jsx(n,{...l,isRight:!0}),tickLine:!1,axisLine:{className:"stroke-muted"}}),e.jsx(ce,{content:({active:l,payload:d,label:m})=>{if(!l||!d||!d.length)return null;const h=d[0].payload;return e.jsxs("div",{className:"rounded-lg border bg-background p-3 shadow-lg",children:[e.jsx("p",{className:"font-medium mb-2",children:m}),d.map((u,S)=>e.jsxs("p",{className:x("text-sm",c&&w),style:{color:u.color},children:[u.name,":"," ",u.name==="Tokens"?J(Number(u.value)||0):`$${u.value}`]},S)),"requests"in h&&e.jsxs("p",{className:x("text-sm text-muted-foreground mt-1",c&&w),children:["Requests: ",h.requests]})]})}}),e.jsx(X,{yAxisId:"left",type:"monotone",dataKey:"tokens",stroke:"#0080FF",strokeWidth:2,fillOpacity:1,fill:"url(#tokenGradient)",name:"Tokens"}),e.jsx(X,{yAxisId:"right",type:"monotone",dataKey:"costRounded",stroke:"#00C49F",strokeWidth:2,fillOpacity:1,fill:"url(#costGradient)",name:"Cost"})]})})})}function ls(s,t){if(t==="hourly"){const[r,c]=s.split(" ");if(r&&c){const o=new Date(`${r}T${c}:00Z`);return C(o,"HH:mm")}return s}const a=new Date(s);return t==="monthly"?C(a,"MMM yyyy"):C(a,"MMM dd")}function J(s){return s>=1e6?`${(s/1e6).toFixed(1)}M`:s>=1e3?`${(s/1e3).toFixed(1)}K`:s.toLocaleString()}function is({data:s,isLoading:t,className:a}){const{privacyMode:r}=A(),{t:c}=$(),o=p.useMemo(()=>!s||s.length===0?[]:s.map(l=>({name:l.model,value:l.tokens,cost:l.cost,percentage:l.percentage,fill:ae(l.model)})),[s]);if(t)return e.jsx(f,{className:x("h-full min-h-[100px] w-full",a)});if(!s||s.length===0)return e.jsx("div",{className:x("h-full min-h-[100px] flex items-center justify-center",a),children:e.jsx("p",{className:"text-muted-foreground",children:c("analyticsCards.noModelData")})});const i=({active:l,payload:d})=>{if(!l||!d)return null;const m=d;if(!m.length)return null;const h=m[0].payload;return e.jsxs("div",{className:"rounded-lg border bg-background p-2 shadow-lg text-xs",children:[e.jsx("p",{className:"font-medium mb-1",children:h.name}),e.jsxs("p",{className:x("text-muted-foreground",r&&w),children:[os(h.value)," (",h.percentage.toFixed(1),"%)"]}),e.jsxs("p",{className:x("text-muted-foreground",r&&w),children:["$",h.cost.toFixed(4)]})]})},n=l=>l.percentage>5?`${l.percentage.toFixed(1)}%`:"";return e.jsx("div",{className:x("w-full h-full min-h-[100px]",a),children:e.jsx(oe,{width:"100%",height:"100%",children:e.jsxs(Ie,{children:[e.jsx(Ke,{data:o,cx:"50%",cy:"50%",labelLine:!1,label:n,innerRadius:50,outerRadius:70,paddingAngle:2,dataKey:"value",children:o.map((l,d)=>e.jsx(Ee,{fill:l.fill,strokeWidth:1},`cell-${d}`))}),e.jsx(ce,{content:i})]})})})}function os(s){return s>=1e6?`${(s/1e6).toFixed(1)}M`:s>=1e3?`${(s/1e3).toFixed(1)}K`:s.toLocaleString()}function cs(s){if(!s)return"";const a=s.replace(/^\/|\/$/g,"").split("/").filter(r=>r.length>0);return a[a.length-1]||""}function ds({data:s,isLoading:t,className:a}){const{privacyMode:r}=A(),{t:c}=$(),o=p.useMemo(()=>{if(!s?.sessions||s.sessions.length===0)return null;const i=s.sessions,n=s.total,l=i.reduce((y,v)=>y+(v.inputTokens+v.outputTokens),0),d=Math.round(l/i.length),h=i.reduce((y,v)=>y+v.cost,0)/i.length,u=i[0],S=u?Q(new Date(u.lastActivity),{addSuffix:!0}):"N/A";return{totalSessions:n,avgTokens:d,avgCost:h,lastActive:S,recentSessions:i.slice(0,3)}},[s]);return t?e.jsxs(g,{className:x("flex flex-col h-full min-h-0 overflow-hidden gap-0 py-0",a),children:[e.jsx(N,{className:"px-3 py-2",children:e.jsx(f,{className:"h-5 w-32"})}),e.jsx(j,{className:"px-3 pb-3 pt-0 flex-1",children:e.jsx(f,{className:"h-full w-full"})})]}):o?e.jsxs(g,{className:x("flex flex-col h-full min-h-0 overflow-hidden gap-0 py-0 shadow-sm",a),children:[e.jsx(N,{className:"px-3 py-2",children:e.jsxs(D,{className:"text-base font-semibold flex items-center gap-2",children:[e.jsx(V,{className:"w-4 h-4"}),"Session Stats"]})}),e.jsxs(j,{className:"px-3 pb-3 pt-0 flex-1 min-h-0 flex flex-col gap-3",children:[e.jsxs("div",{className:"grid grid-cols-2 gap-2",children:[e.jsxs("div",{className:"p-2 rounded-md bg-muted/50 border text-center",children:[e.jsxs("div",{className:"flex items-center justify-center gap-1.5 text-blue-600 dark:text-blue-400",children:[e.jsx($e,{className:"w-4 h-4"}),e.jsx("span",{className:"text-xl font-bold",children:o.totalSessions})]}),e.jsx("p",{className:"text-[10px] text-muted-foreground uppercase tracking-wider mt-0.5",children:"Total Sessions"})]}),e.jsxs("div",{className:"p-2 rounded-md bg-muted/50 border text-center",children:[e.jsxs("div",{className:"flex items-center justify-center gap-1.5 text-green-600 dark:text-green-400",children:[e.jsx(ie,{className:"w-4 h-4"}),e.jsxs("span",{className:x("text-xl font-bold",r&&w),children:["$",o.avgCost.toFixed(2)]})]}),e.jsx("p",{className:"text-[10px] text-muted-foreground uppercase tracking-wider mt-0.5",children:"Avg Cost/Session"})]})]}),e.jsxs("div",{className:"flex-1 min-h-0 space-y-2",children:[e.jsxs("div",{className:"flex items-center gap-1 text-xs text-muted-foreground font-medium mb-1",children:[e.jsx(Le,{className:"w-3 h-3"}),"Recent Activity"]}),e.jsx("div",{className:"space-y-1.5 max-h-full overflow-y-auto pr-1",children:o.recentSessions.map(i=>e.jsxs("div",{className:"flex items-center justify-between text-xs p-1.5 rounded bg-muted/30 hover:bg-muted/50 transition-colors",children:[e.jsxs("div",{className:"flex flex-col min-w-0 flex-1",children:[e.jsxs("div",{className:"flex items-center gap-1",children:[e.jsx("span",{className:"font-medium truncate",title:i.projectPath,children:cs(i.projectPath)}),(i.target??"claude")!=="claude"&&e.jsx("span",{className:"shrink-0 px-1 py-0 text-[9px] font-medium rounded bg-purple-100 text-purple-700 dark:bg-purple-900/30 dark:text-purple-300 uppercase",children:i.target})]}),e.jsx("span",{className:"text-[10px] text-muted-foreground",children:Q(new Date(i.lastActivity),{addSuffix:!0})})]}),e.jsxs("div",{className:x("text-right shrink-0 ml-2",r&&w),children:[e.jsxs("div",{className:"font-mono",children:["$",i.cost.toFixed(2)]}),e.jsxs("div",{className:"text-[10px] text-muted-foreground",children:[xs(i.inputTokens+i.outputTokens)," toks"]})]})]},i.sessionId))})]})]})]}):e.jsxs(g,{className:x("flex flex-col h-full min-h-0 overflow-hidden gap-0 py-0",a),children:[e.jsx(N,{className:"px-3 py-2",children:e.jsxs(D,{className:"text-base font-semibold flex items-center gap-2",children:[e.jsx(V,{className:"w-4 h-4"}),"Session Stats"]})}),e.jsx(j,{className:"px-3 pb-3 pt-0 flex-1 flex items-center justify-center",children:e.jsx("p",{className:"text-sm text-muted-foreground text-center",children:c("analyticsCards.noSessionData")})})]})}function xs(s){return s>=1e9?`${(s/1e9).toFixed(1)}B`:s>=1e6?`${(s/1e6).toFixed(1)}M`:s>=1e3?`${(s/1e3).toFixed(1)}K`:s.toString()}function us({className:s,isLoading:t}){const{data:a,isLoading:r}=ye(),{data:c,isLoading:o,error:i}=Ne(a?.running),{t:n}=$();if(t||r||a?.running&&o)return e.jsxs(g,{className:x("flex flex-col h-full min-h-0 overflow-hidden gap-0 py-0",s),children:[e.jsx(N,{className:"px-3 py-2",children:e.jsxs(D,{className:"text-base font-semibold flex items-center gap-2",children:[e.jsx(H,{className:"h-4 w-4"}),"CLIProxy Stats"]})}),e.jsx(j,{className:"px-3 pb-3 pt-0 flex-1",children:e.jsxs("div",{className:"space-y-3",children:[e.jsx(f,{className:"h-4 w-[100px]"}),e.jsx(f,{className:"h-16 w-full"})]})})]});if(!a?.running)return e.jsxs(g,{className:x("flex flex-col h-full min-h-0 overflow-hidden gap-0 py-0 border-dashed",s),children:[e.jsx(N,{className:"px-3 py-2",children:e.jsxs("div",{className:"flex items-center justify-between",children:[e.jsxs(D,{className:"text-base font-semibold flex items-center gap-2",children:[e.jsx(H,{className:"h-4 w-4 text-muted-foreground"}),"CLIProxy Stats"]}),e.jsx(I,{variant:"secondary",className:"text-[10px] h-5",children:n("cliproxyStatsOverview.offline")})]})}),e.jsx(j,{className:"px-3 pb-3 pt-0 flex-1 flex items-center justify-center",children:e.jsx("p",{className:"text-xs text-muted-foreground text-center",children:n("cliproxyStatsOverview.noActiveSessionHint")})})]});if(i)return e.jsxs(g,{className:x("flex flex-col h-full min-h-0 overflow-hidden gap-0 py-0 border-destructive/50",s),children:[e.jsx(N,{className:"px-3 py-2",children:e.jsxs("div",{className:"flex items-center justify-between",children:[e.jsxs(D,{className:"text-base font-semibold flex items-center gap-2",children:[e.jsx(H,{className:"h-4 w-4"}),"CLIProxy Stats"]}),e.jsx(I,{variant:"destructive",className:"text-[10px] h-5",children:"Error"})]})}),e.jsx(j,{className:"px-3 pb-3 pt-0 flex-1",children:e.jsx("p",{className:"text-xs text-destructive",children:i.message})})]});const d=c?.totalRequests??0,m=c?.quotaExceededCount??0,h=d-m,u=d>0?Math.round(h/d*100):100,S=c?.tokens?.total??0,y=Object.entries(c?.requestsByModel??{}).sort((k,L)=>L[1]-k[1]).slice(0,4),v=y.length>0?y[0][1]:1;return e.jsxs(g,{className:x("flex flex-col h-full min-h-0 overflow-hidden gap-0 py-0",s),children:[e.jsx(N,{className:"px-3 py-2 border-b bg-muted/5",children:e.jsxs("div",{className:"flex items-center justify-between",children:[e.jsxs(D,{className:"text-base font-semibold flex items-center gap-2",children:[e.jsx(H,{className:"h-4 w-4"}),"CLIProxy Stats"]}),e.jsxs(I,{variant:"outline",className:"text-[10px] h-5 text-green-600 border-green-200 bg-green-50 dark:bg-green-900/10 dark:border-green-800",children:[e.jsx(ie,{className:"h-3 w-3 mr-0.5"}),n("cliproxyStatsOverview.running")]})]})}),e.jsx(j,{className:"p-0 flex-1 min-h-0",children:e.jsx(we,{className:"h-full",children:e.jsxs("div",{className:"p-3 space-y-3",children:[e.jsxs("div",{className:"grid grid-cols-2 gap-2",children:[e.jsxs("div",{className:"flex items-center gap-2 p-2 rounded-lg bg-muted/30",children:[e.jsxs("div",{className:"relative",children:[e.jsxs("svg",{className:"w-10 h-10 -rotate-90",viewBox:"0 0 36 36",children:[e.jsx("circle",{cx:"18",cy:"18",r:"14",fill:"none",stroke:"currentColor",strokeWidth:"3",className:"text-muted/30"}),e.jsx("circle",{cx:"18",cy:"18",r:"14",fill:"none",stroke:"currentColor",strokeWidth:"3",strokeDasharray:`${u*.88} 88`,strokeLinecap:"round",className:u>=90?"text-green-500":"text-amber-500"})]}),e.jsxs("span",{className:"absolute inset-0 flex items-center justify-center text-[8px] font-bold",children:[u,"%"]})]}),e.jsxs("div",{className:"min-w-0",children:[e.jsx("div",{className:"text-lg font-bold leading-none",children:ee(d)}),e.jsx("div",{className:"text-[9px] text-muted-foreground mt-0.5",children:m>0?`${m} failed`:"All success"})]})]}),e.jsxs("div",{className:"flex items-center gap-2 p-2 rounded-lg bg-muted/30",children:[e.jsx("div",{className:"p-1.5 rounded-md bg-purple-100 dark:bg-purple-900/20",children:e.jsx(Fe,{className:"h-4 w-4 text-purple-600"})}),e.jsxs("div",{className:"min-w-0",children:[e.jsx("div",{className:"text-lg font-bold leading-none",children:ee(S)}),e.jsx("div",{className:"text-[9px] text-muted-foreground mt-0.5",children:n("cliproxyStatsOverview.totalTokens")})]})]})]}),y.length>0&&e.jsxs("div",{className:"space-y-1.5",children:[e.jsxs("div",{className:"flex items-center gap-1.5 text-[10px] font-medium text-muted-foreground",children:[e.jsx(Re,{className:"h-3 w-3"}),n("cliproxyStatsOverview.modelsUsed")]}),e.jsx("div",{className:"space-y-1",children:y.map(([k,L])=>{const q=Math.round(L/v*100),R=ms(k);return e.jsxs("div",{className:"group",children:[e.jsxs("div",{className:"flex items-center justify-between text-[10px] mb-0.5",children:[e.jsx("span",{className:"truncate font-medium",title:k,children:R}),e.jsx("span",{className:"text-muted-foreground shrink-0 ml-2",children:L})]}),e.jsx("div",{className:"h-1 bg-muted/50 rounded-full overflow-hidden",children:e.jsx("div",{className:"h-full bg-accent/70 rounded-full transition-all",style:{width:`${q}%`}})})]},k)})})]})]})})})]})}function ee(s){return s>=1e6?`${(s/1e6).toFixed(1)}M`:s>=1e3?`${(s/1e3).toFixed(1)}K`:s.toLocaleString()}function ms(s){let t=s.replace(/^gemini-claude-/,"").replace(/^gemini-/,"").replace(/^claude-/,"").replace(/^anthropic\./,"").replace(/-thinking$/," Thinking");return t=t.split(/[-_]/).map(a=>a.charAt(0).toUpperCase()+a.slice(1)).join(" "),t.length>20&&(t=t.slice(0,18)+"..."),t}function hs(s){return s>=1e9?`${(s/1e9).toFixed(1)}B`:s>=1e6?`${(s/1e6).toFixed(1)}M`:s>=1e3?`${(s/1e3).toFixed(0)}K`:s.toString()}function fs({models:s,isLoading:t,onModelClick:a,privacyMode:r}){const{t:c}=$();return e.jsxs(g,{className:"flex flex-col h-full min-h-0 overflow-hidden gap-0 py-0 shadow-sm lg:col-span-4",children:[e.jsx(N,{className:"px-3 py-2",children:e.jsxs(D,{className:"text-base font-semibold flex items-center gap-2",children:[e.jsx(re,{className:"w-4 h-4"}),c("analyticsPages.costByModel")]})}),e.jsx(j,{className:"px-2 pb-2 pt-0 flex-1 min-h-0 overflow-y-auto",children:t?e.jsx(f,{className:"h-full w-full"}):e.jsxs("div",{className:"space-y-0.5",children:[[...s||[]].sort((o,i)=>i.cost-o.cost).map(o=>e.jsxs("button",{className:"group flex items-center text-xs w-full hover:bg-muted/50 rounded px-2 py-1.5 transition-colors cursor-pointer gap-3",onClick:i=>a(o,i),title:"Click for details",children:[e.jsxs("div",{className:"flex items-center gap-2 min-w-0 w-[180px] shrink-0",children:[e.jsx("div",{className:"w-2 h-2 rounded-full shrink-0",style:{backgroundColor:ae(o.model)}}),e.jsx("span",{className:"font-medium truncate group-hover:underline underline-offset-2",children:o.model})]}),e.jsx(ps,{model:o}),e.jsx("span",{className:x("text-[10px] text-muted-foreground w-14 text-right shrink-0",r&&w),children:hs(o.tokens)}),e.jsxs("span",{className:x("font-mono font-medium w-16 text-right shrink-0",r&&w),children:["$",o.cost.toFixed(2)]}),e.jsx(Te,{className:"w-3 h-3 opacity-0 group-hover:opacity-50 transition-opacity shrink-0"})]},o.model)),e.jsx(gs,{})]})})]})}function ps({model:s}){const t={input:"#335c67",output:"#fff3b0",cacheWrite:"#e09f3e",cacheRead:"#9e2a2b"},a=r=>s.cost>0?r/s.cost*100:0;return e.jsx("div",{className:"flex-1 flex items-center gap-1 min-w-0",children:e.jsxs("div",{className:"flex-1 h-2 bg-muted rounded-full overflow-hidden flex",children:[e.jsx("div",{className:"h-full",style:{backgroundColor:t.input,width:`${a(s.costBreakdown.input.cost)}%`},title:`Input: $${s.costBreakdown.input.cost.toFixed(2)}`}),e.jsx("div",{className:"h-full",style:{backgroundColor:t.output,width:`${a(s.costBreakdown.output.cost)}%`},title:`Output: $${s.costBreakdown.output.cost.toFixed(2)}`}),e.jsx("div",{className:"h-full",style:{backgroundColor:t.cacheWrite,width:`${a(s.costBreakdown.cacheCreation.cost)}%`},title:`Cache Write: $${s.costBreakdown.cacheCreation.cost.toFixed(2)}`}),e.jsx("div",{className:"h-full",style:{backgroundColor:t.cacheRead,width:`${a(s.costBreakdown.cacheRead.cost)}%`},title:`Cache Read: $${s.costBreakdown.cacheRead.cost.toFixed(2)}`})]})})}function gs(){const s=[{color:"#335c67",label:"Input"},{color:"#fff3b0",label:"Output",hasBorder:!0},{color:"#e09f3e",label:"Cache Write"},{color:"#9e2a2b",label:"Cache Read"}];return e.jsx("div",{className:"flex items-center gap-3 pt-2 px-2 text-[10px] text-muted-foreground border-t mt-2",children:s.map(({color:t,label:a,hasBorder:r})=>e.jsxs("span",{className:"flex items-center gap-1",children:[e.jsx("div",{className:x("w-2 h-2 rounded-full",r&&"border border-muted-foreground/30"),style:{backgroundColor:t}}),a]},a))})}function js({viewMode:s,trends:t,hourlyData:a,models:r,sessions:c,isTrendsLoading:o,isHourlyLoading:i,isModelsLoading:n,isSessionsLoading:l,isSummaryLoading:d,onModelClick:m}){const{privacyMode:h}=A();return e.jsxs("div",{className:"min-h-0 grid gap-4 lg:grid-rows-[minmax(260px,1.2fr)_minmax(220px,0.9fr)]",children:[e.jsxs(g,{className:"flex flex-col h-full min-h-[220px] lg:min-h-[240px] overflow-hidden gap-0 py-0 shadow-sm",children:[e.jsx(N,{className:"px-3 py-2 shrink-0",children:e.jsxs(D,{className:"text-base font-semibold flex items-center gap-2",children:[e.jsx(Me,{className:"w-4 h-4"}),s==="hourly"?"Last 24 Hours":"Usage Trends"]})}),e.jsx(j,{className:"px-3 pb-3 pt-0 flex-1 min-h-0",children:e.jsx(ns,{data:s==="hourly"?a||[]:t||[],isLoading:s==="hourly"?i:o,granularity:s==="hourly"?"hourly":"daily"})})]}),e.jsxs("div",{className:"grid grid-cols-1 lg:grid-cols-10 gap-4 h-auto min-h-[220px] lg:h-full lg:min-h-[220px] lg:grid-rows-[minmax(0,1fr)] lg:[&>*]:min-h-0",children:[e.jsx(fs,{models:r,isLoading:n,onModelClick:m,privacyMode:h}),e.jsxs(g,{className:"flex flex-col h-full min-h-0 overflow-hidden gap-0 py-0 shadow-sm lg:col-span-2",children:[e.jsx(N,{className:"px-3 py-2",children:e.jsxs(D,{className:"text-base font-semibold flex items-center gap-2",children:[e.jsx(Pe,{className:"w-4 h-4"}),"Model Usage"]})}),e.jsx(j,{className:"px-2 pb-2 pt-0 flex-1 min-h-0 flex items-center justify-center",children:e.jsx(is,{data:r||[],isLoading:n,className:"h-full w-full"})})]}),e.jsx(ds,{data:c,isLoading:l,className:"lg:col-span-2"}),e.jsx(us,{isLoading:d,className:"lg:col-span-2"})]})]})}function Ls(){return e.jsxs("div",{className:"space-y-4 h-full overflow-hidden",children:[e.jsxs(g,{className:"flex flex-col min-h-[300px]",children:[e.jsx(N,{className:"p-4 pb-2",children:e.jsx(f,{className:"h-4 w-32"})}),e.jsx(j,{className:"p-4 pt-0 flex-1",children:e.jsx(f,{className:"h-full w-full"})})]}),e.jsxs("div",{className:"grid grid-cols-1 lg:grid-cols-2 gap-4",children:[e.jsxs(g,{className:"flex flex-col min-h-[250px]",children:[e.jsx(N,{className:"p-4 pb-2",children:e.jsx(f,{className:"h-4 w-28"})}),e.jsx(j,{className:"p-4 pt-2",children:e.jsx("div",{className:"space-y-3",children:[1,2,3,4,5].map(s=>e.jsxs("div",{className:"flex justify-between items-center",children:[e.jsxs("div",{className:"flex items-center gap-2",children:[e.jsx(f,{className:"w-2.5 h-2.5 rounded-full"}),e.jsx(f,{className:"h-3 w-24"})]}),e.jsx(f,{className:"h-3 w-16"})]},s))})})]}),e.jsxs(g,{className:"flex flex-col min-h-[250px]",children:[e.jsx(N,{className:"p-4 pb-2",children:e.jsx(f,{className:"h-4 w-28"})}),e.jsx(j,{className:"p-4 pt-0 flex-1",children:e.jsxs("div",{className:"flex w-full h-full items-center",children:[e.jsx("div",{className:"flex-1 flex justify-center",children:e.jsx(f,{className:"h-[180px] w-[180px] rounded-full"})}),e.jsx("div",{className:"w-[140px] shrink-0 pl-2 space-y-2",children:[1,2,3,4].map(s=>e.jsxs("div",{className:"flex items-center gap-2",children:[e.jsx(f,{className:"w-2 h-2 rounded-full"}),e.jsx(f,{className:"h-3 w-20"})]},s))})]})})]})]})]})}function Fs(){const s=p.useRef(null),{dateRange:t,handleDateRangeChange:a,handleTodayClick:r,handleRefresh:c,isRefreshing:o,lastUpdatedText:i,viewMode:n,summary:l,isSummaryLoading:d,trends:m,hourlyData:h,models:u,sessions:S,isTrendsLoading:y,isHourlyLoading:v,isModelsLoading:k,isSessionsLoading:L,handleModelClick:q,selectedModel:R,popoverPosition:O,handlePopoverClose:z}=ts();return e.jsxs("div",{className:"grid h-full min-h-0 grid-rows-[auto_auto_minmax(0,1fr)] gap-4 overflow-y-auto px-4 py-4",children:[e.jsx(rs,{dateRange:t,onDateRangeChange:a,onTodayClick:r,onRefresh:c,isRefreshing:o,lastUpdatedText:i,viewMode:n}),e.jsx(Ge,{data:l,isLoading:d}),e.jsx(js,{viewMode:n,trends:m,hourlyData:h,models:u,sessions:S,isTrendsLoading:y,isHourlyLoading:v,isModelsLoading:k,isSessionsLoading:L,isSummaryLoading:d,onModelClick:q}),e.jsxs(se,{open:!!R,onOpenChange:K=>!K&&z(),children:[e.jsx(be,{asChild:!0,children:e.jsx("div",{ref:s,className:"fixed pointer-events-none",style:{left:O?.x??0,top:O?.y??0,width:1,height:1}})}),e.jsx(te,{className:"w-80 p-3",side:"top",align:"center",children:R&&e.jsx(He,{model:R})})]})]})}export{Fs as AnalyticsPage,Ls as AnalyticsSkeleton};
|
|
@@ -1 +1 @@
|
|
|
1
|
-
import{j as e}from"./radix-ui-Zb8sVEtn.js";import{r as n}from"./react-vendor-CNOkPC89.js";import{bt as Ue,bu as ze,Y as R,a as oe,I as B,aI as M,r as We,s as Ye,t as Xe,v as Ge,w as ye,d as z,bv as qe,bw as Je,bx as Qe,by as Ze,b6 as he,bz as es,bA as ss,bi as H,bk as V,n as ts}from"./index-2X8-14xr.js";import{C as W}from"./default-ports-1QQSffYX.js";import{bb as fe,R as ae,h as rs,x as je,W as as,w as os,aA as ns,bc as is,T as re,aH as ls,p as cs,bd as ds}from"./icons-DyorC3Xk.js";import{P as xs}from"./proxy-status-widget-D82T2X4F.js";import{R as U}from"./antigravity-responsibility-constants-Bvh4Ybz0.js";import{t as T}from"./notifications-B2HqRBj7.js";import"./tanstack-CrmUhA7Z.js";import"./utils-CzKF5WmX.js";import"./form-utils-Bcoyqxpq.js";import"./code-highlight-BRUf_pqB.js";import"./alert-dialog-CzJucE0e.js";function ms(){const{state:s}=Ue(),t=ze(),[g,o]=n.useState(null),[u,f]=n.useState(null),[p,j]=n.useState(null),[y,C]=n.useState(null),[S,P]=n.useState(null),w=n.useCallback(async()=>{try{t.setProxyLoading(!0),t.setProxyError(null);const d=await R.cliproxyServer.get();t.setProxyConfig(d)}catch(d){t.setProxyError(d.message)}finally{t.setProxyLoading(!1)}},[t]),A=n.useCallback(async d=>{const x=s.proxyConfig;if(!x)return;const h={remote:{...x.remote,...d.remote},fallback:{...x.fallback,...d.fallback},local:{...x.local,...d.local}};t.setProxyConfig(h),t.setProxyTestResult(null);try{t.setProxySaving(!0),t.setProxyError(null);const a=await R.cliproxyServer.update(d);t.setProxyConfig(a),t.setProxySuccess(!0),setTimeout(()=>t.setProxySuccess(!1),1500)}catch(a){t.setProxyConfig(x),t.setProxyError(a.message)}finally{t.setProxySaving(!1)}},[s.proxyConfig,t]),E=n.useCallback(async d=>{const{host:x,port:h,protocol:a,authToken:c}=d;if(!x){t.setProxyError("Host is required");return}try{t.setProxyTesting(!0),t.setProxyError(null),t.setProxyTestResult(null);const v=h?parseInt(h,10):void 0,l=await R.cliproxyServer.test({host:x,port:v||void 0,protocol:a,authToken:c||void 0});t.setProxyTestResult(l)}catch(v){t.setProxyError(v.message)}finally{t.setProxyTesting(!1)}},[t]);return{config:s.proxyConfig,loading:s.proxyLoading,saving:s.proxySaving,error:s.proxyError,success:s.proxySuccess,testResult:s.proxyTestResult,testing:s.proxyTesting,editedHost:g,setEditedHost:o,editedPort:u,setEditedPort:f,editedAuthToken:p,setEditedAuthToken:j,editedManagementKey:y,setEditedManagementKey:C,editedLocalPort:S,setEditedLocalPort:P,fetchConfig:w,saveConfig:A,testConnection:E}}function gs({config:s,saving:t,displayLocalPort:g,setEditedLocalPort:o,onSaveLocalPort:u,onSaveConfig:f}){const{t:p}=oe(),j=s.local;return e.jsxs("div",{className:"space-y-3",children:[e.jsx("h3",{className:"text-base font-medium",children:p("settingsProxy.localProxy")}),e.jsxs("div",{className:"space-y-3 p-4 rounded-lg border bg-muted/30",children:[e.jsxs("div",{className:"flex items-center gap-2",children:[e.jsx("label",{className:"text-sm text-muted-foreground",children:p("settingsProxy.port")}),e.jsx(B,{type:"text",inputMode:"numeric",value:g,onChange:y=>o(y.target.value.replace(/\D/g,"")),onBlur:u,placeholder:`${W}`,className:"font-mono max-w-32",disabled:t})]}),e.jsxs("div",{className:"flex items-center justify-between",children:[e.jsxs("div",{children:[e.jsx("p",{className:"font-medium text-sm",children:p("settingsProxy.autoStart")}),e.jsx("p",{className:"text-xs text-muted-foreground",children:p("settingsProxy.localAutoStartDesc")})]}),e.jsx(M,{checked:j.auto_start??!0,onCheckedChange:y=>f({local:{...j,auto_start:y}}),disabled:t})]})]})]})}function us({config:s,saving:t,testing:g,testResult:o,displayHost:u,displayPort:f,displayAuthToken:p,displayManagementKey:j,setEditedHost:y,setEditedPort:C,setEditedAuthToken:S,setEditedManagementKey:P,onSaveHost:w,onSavePort:A,onSaveAuthToken:E,onSaveManagementKey:d,onSaveConfig:x,onTestConnection:h}){const{t:a}=oe(),c=s.remote,v=l=>l==="https"?443:W;return e.jsxs("div",{className:"space-y-4 p-4 rounded-lg border bg-muted/30",children:[e.jsxs("h4",{className:"text-sm font-medium flex items-center gap-2",children:[e.jsx(fe,{className:"w-4 h-4"}),a("settingsProxy.remoteConfigTitle")]}),e.jsxs("div",{className:"space-y-1",children:[e.jsx("label",{className:"text-sm text-muted-foreground",children:a("settingsProxy.host")}),e.jsx(B,{value:u,onChange:l=>y(l.target.value),onBlur:w,placeholder:a("settingsProxy.hostPlaceholder"),className:"font-mono",disabled:t})]}),e.jsxs("div",{className:"grid grid-cols-2 gap-3",children:[e.jsxs("div",{className:"space-y-1",children:[e.jsxs("label",{className:"text-sm text-muted-foreground",children:[a("settingsProxy.port")," ",e.jsxs("span",{className:"text-xs opacity-70",children:["(",a("settingsProxy.defaultPort",{value:v(s.remote.protocol||"http")}),")"]})]}),e.jsx(B,{type:"text",inputMode:"numeric",value:f,onChange:l=>C(l.target.value.replace(/\D/g,"")),onBlur:A,placeholder:a("settingsProxy.portPlaceholder",{value:v(s.remote.protocol||"http")}),className:"font-mono",disabled:t})]}),e.jsxs("div",{className:"space-y-1",children:[e.jsx("label",{className:"text-sm text-muted-foreground",children:a("settingsProxy.protocol")}),e.jsxs(We,{value:s.remote.protocol||"http",onValueChange:l=>x({remote:{...c,protocol:l}}),disabled:t,children:[e.jsx(Ye,{children:e.jsx(Xe,{})}),e.jsxs(Ge,{children:[e.jsx(ye,{value:"http",children:a("settingsProxy.http")}),e.jsx(ye,{value:"https",children:a("settingsProxy.https")})]})]})]})]}),e.jsxs("div",{className:"space-y-1",children:[e.jsx("label",{className:"text-sm text-muted-foreground",children:a("settingsProxy.apiKeyOptional")}),e.jsx(B,{type:"password",value:p,onChange:l=>S(l.target.value),onBlur:E,placeholder:a("settingsProxy.apiKeyPlaceholder"),className:"font-mono",disabled:t}),e.jsx("p",{className:"text-xs text-muted-foreground",children:a("settingsProxy.apiKeyDesc")})]}),e.jsxs("div",{className:"space-y-1",children:[e.jsx("label",{className:"text-sm text-muted-foreground",children:a("settingsProxy.managementKeyOptional")}),e.jsx(B,{type:"password",value:j,onChange:l=>P(l.target.value),onBlur:d,placeholder:a("settingsProxy.managementKeyPlaceholder"),className:"font-mono",disabled:t}),e.jsx("p",{className:"text-xs text-muted-foreground",children:a("settingsProxy.managementKeyDesc")})]}),e.jsxs("div",{className:"space-y-3 pt-2",children:[e.jsx(z,{onClick:h,disabled:g||!u,variant:"outline",className:"w-full",children:g?e.jsxs(e.Fragment,{children:[e.jsx(ae,{className:"w-4 h-4 mr-2 animate-spin"}),a("settingsProxy.testing")]}):e.jsxs(e.Fragment,{children:[e.jsx(rs,{className:"w-4 h-4 mr-2"}),a("settingsProxy.testConnection")]})}),o&&e.jsx("div",{className:`p-3 rounded-md ${o.reachable?"bg-green-50 border border-green-200 dark:bg-green-900/20 dark:border-green-900/50":"bg-red-50 border border-red-200 dark:bg-red-900/20 dark:border-red-900/50"}`,children:e.jsx("div",{className:"flex items-center gap-2",children:o.reachable?e.jsxs(e.Fragment,{children:[e.jsx(je,{className:"w-4 h-4 text-green-600 dark:text-green-400"}),e.jsx("span",{className:"text-sm font-medium text-green-700 dark:text-green-300",children:a("settingsProxy.connectedLatency",{value:o.latencyMs})})]}):e.jsxs(e.Fragment,{children:[e.jsx(as,{className:"w-4 h-4 text-red-600 dark:text-red-400"}),e.jsx("span",{className:"text-sm font-medium text-red-700 dark:text-red-300",children:o.error||a("settingsProxy.connectionFailed")})]})})})]})]})}const be="ccs_debug_mode";function ps(s){return s.trim().replace(/\s+/g," ").toUpperCase()}function Ts(){const{t:s}=oe(),{config:t,loading:g,saving:o,error:u,success:f,testResult:p,testing:j,editedHost:y,setEditedHost:C,editedPort:S,setEditedPort:P,editedAuthToken:w,setEditedAuthToken:A,editedManagementKey:E,setEditedManagementKey:d,editedLocalPort:x,setEditedLocalPort:h,fetchConfig:a,saveConfig:c,testConnection:v}=ms(),{fetchRawConfig:l}=qe(),[_,Pe]=n.useState(()=>{try{return localStorage.getItem(be)==="true"}catch{return!1}}),[ve,Y]=n.useState(!1),[ke,ne]=n.useState(!0),[b,ie]=n.useState(!1),[Ne,L]=n.useState(!1),[le,I]=n.useState(""),K=n.useRef(!1),X=ps(le)===U,Ce=r=>{Pe(r);try{localStorage.setItem(be,String(r))}catch{}},G=n.useCallback(async()=>{try{ne(!0);const r=await fetch("/api/settings/auth/antigravity-risk");if(!r.ok)throw new Error(s("settingsProxy.failedLoadAgyMode"));const i=await r.json();Y(i.antigravityAckBypass===!0)}catch(r){T.error(r instanceof Error?r.message:s("settingsProxy.failedLoadAgyMode")),Y(!1)}finally{ne(!1)}},[s]),O=n.useCallback(async r=>{if(!(K.current||b||o))try{K.current=!0,ie(!0);const i=await fetch("/api/settings/auth/antigravity-risk",{method:"PUT",headers:{"Content-Type":"application/json"},body:JSON.stringify({antigravityAckBypass:r})}),$=await i.json();if(!i.ok)throw new Error($.error||s("settingsProxy.failedUpdateAgyMode"));const Ve=$.antigravityAckBypass===!0,ue=await fetch("/api/settings/auth/antigravity-risk",{cache:"no-store"});if(!ue.ok)throw new Error(s("settingsProxy.failedVerifyAgyMode"));const pe=(await ue.json()).antigravityAckBypass===!0;if(pe!==r)throw new Error(s("settingsProxy.notPersistedAgyMode"));Y(pe&&Ve),L(!1),I(""),T.success(s(r?"settingsProxy.agyModeEnabled":"settingsProxy.agyModeDisabled")),await l()}catch(i){T.error(i instanceof Error?i.message:s("settingsProxy.failedUpdateAgyMode"))}finally{K.current=!1,ie(!1)}},[b,l,o,s]),Se=n.useCallback(r=>{if(!(K.current||b||o)){if(r){L(!0);return}L(!1),I(""),O(!1)}},[b,O,o]),we=n.useCallback(()=>{if(!X){T.error(s("settingsProxy.typePhraseToContinue",{value:U}));return}O(!0)},[X,O,s]),[k,q]=n.useState("original"),[Ae,Ee]=n.useState(!1),J=Je(),{data:Te}=Qe(),ce=Te?.running??!1,Be=Ze.map(he).join(", "),de=es.map(he).join(", "),Q=n.useCallback(async()=>{try{const r=await R.cliproxyServer.getBackend();q(r.backend)}catch(r){console.error("[Proxy] Failed to fetch backend:",r)}},[]),Z=n.useCallback(async()=>{try{const i=(await R.cliproxy.list()).variants.some($=>ss($));Ee(i)}catch(r){console.error("[Proxy] Failed to check variants:",r)}},[]),xe=r=>{const i=k;q(r),J.mutate({backend:r},{onError:()=>{q(i)}})};if(n.useEffect(()=>{if(_&&t){const r={...t,remote:{...t.remote,auth_token:t.remote.auth_token?"[REDACTED]":void 0,management_key:t.remote.management_key?"[REDACTED]":void 0}};console.log("[CCS Debug] Debug mode enabled - proxy config:",r)}},[_,t]),n.useEffect(()=>{a(),G(),l(),Q(),Z()},[a,G,l,Q,Z]),g||!t)return e.jsx("div",{className:"flex-1 flex items-center justify-center",children:e.jsxs("div",{className:"flex items-center gap-3 text-muted-foreground",children:[e.jsx(ae,{className:"w-5 h-5 animate-spin"}),e.jsx("span",{children:s("settings.loading")})]})});const m=t.remote.enabled??!1,F=!m&&ce,N=t.remote,D=t.fallback,De=t.remote.host??"",Me=t.remote.port!==void 0?t.remote.port.toString():"",Re=t.remote.auth_token??"",_e=t.remote.management_key??"",Le=(t.local.port??W).toString(),ee=y??De,se=S??Me,te=w??Re,me=E??_e,ge=x??Le,Ie=()=>{const r=y??ee;r!==t.remote.host&&c({remote:{...N,host:r}}),C(null)},Ke=()=>{const r=(S??se).trim();if(r===""){t.remote.port!==void 0&&c({remote:{...N,port:void 0}}),P(null);return}const i=Number(r);if(!Number.isInteger(i)||i<1||i>65535){T.error(s("settingsProxy.invalidPortOrEmpty")),P(null);return}i!==t.remote.port&&c({remote:{...N,port:i}}),P(null)},Oe=()=>{const r=w??te;r!==t.remote.auth_token&&c({remote:{...N,auth_token:r}}),A(null)},Fe=()=>{const r=E??me;r!==t.remote.management_key&&c({remote:{...N,management_key:r||void 0}}),d(null)},$e=()=>{const r=(x??ge).trim(),i=r===""?W:Number(r);if(!Number.isInteger(i)||i<1||i>65535){T.error(s("settingsProxy.invalidLocalPort")),h(null);return}i!==t.local.port&&c({local:{...t.local,port:i}}),h(null)},He=()=>{v({host:ee,port:se,protocol:t.remote.protocol||"http",authToken:te})};return e.jsxs(e.Fragment,{children:[e.jsxs("div",{className:`absolute left-5 right-5 top-20 z-10 transition-all duration-200 ease-out ${u||f?"opacity-100 translate-y-0":"opacity-0 -translate-y-2 pointer-events-none"}`,children:[u&&e.jsxs(H,{variant:"destructive",className:"py-2 shadow-lg",children:[e.jsx(os,{className:"h-4 w-4"}),e.jsx(V,{children:u})]}),f&&e.jsxs("div",{className:"flex items-center gap-2 px-3 py-2 rounded-md border border-green-200 bg-green-50 text-green-700 shadow-lg dark:border-green-900/50 dark:bg-green-900/90 dark:text-green-300",children:[e.jsx(je,{className:"h-4 w-4 shrink-0"}),e.jsx("span",{className:"text-sm font-medium",children:s("settings.saved")})]})]}),e.jsx(ts,{className:"flex-1",children:e.jsxs("div",{className:"p-5 space-y-6",children:[e.jsx("p",{className:"text-sm text-muted-foreground",children:s("settingsProxy.description",{backend:s(k==="plus"?"settingsProxy.backendPlus":"settingsProxy.backend")})}),!m&&e.jsxs("div",{className:"space-y-3",children:[e.jsx("h3",{className:"text-base font-medium",children:s("settingsProxy.instanceStatus")}),e.jsx(xs,{})]}),e.jsxs("div",{className:"space-y-3",children:[e.jsx("h3",{className:"text-base font-medium",children:s("settingsProxy.connectionMode")}),e.jsxs("div",{className:"grid grid-cols-2 gap-3",children:[e.jsxs("button",{onClick:()=>c({remote:{...N,enabled:!1}}),disabled:o,className:`p-4 rounded-lg border-2 text-left transition-all ${m?"border-border hover:border-muted-foreground/50":"border-primary bg-primary/5"}`,children:[e.jsxs("div",{className:"flex items-center gap-3 mb-2",children:[e.jsx(ns,{className:`w-5 h-5 ${m?"text-muted-foreground":"text-primary"}`}),e.jsx("span",{className:"font-medium",children:s("settingsProxy.local")})]}),e.jsx("p",{className:"text-xs text-muted-foreground",children:s("settingsProxy.localDesc",{backend:s(k==="plus"?"settingsProxy.backendPlus":"settingsProxy.backend")})})]}),e.jsxs("button",{onClick:()=>c({remote:{...N,enabled:!0}}),disabled:o,className:`p-4 rounded-lg border-2 text-left transition-all ${m?"border-primary bg-primary/5":"border-border hover:border-muted-foreground/50"}`,children:[e.jsxs("div",{className:"flex items-center gap-3 mb-2",children:[e.jsx(fe,{className:`w-5 h-5 ${m?"text-primary":"text-muted-foreground"}`}),e.jsx("span",{className:"font-medium",children:s("settingsProxy.remote")})]}),e.jsx("p",{className:"text-xs text-muted-foreground",children:s("settingsProxy.remoteDesc",{backend:s(k==="plus"?"settingsProxy.backendPlus":"settingsProxy.backend")})})]})]})]}),e.jsxs("div",{className:"space-y-3",children:[e.jsxs("h3",{className:"text-base font-medium flex items-center gap-2",children:[e.jsx(is,{className:"w-4 h-4"}),s("settingsProxy.backendBinary")]}),!m&&ce&&e.jsxs(H,{className:"py-2 border-amber-200 bg-amber-50 dark:border-amber-900/50 dark:bg-amber-900/20 [&>svg]:top-2.5",children:[e.jsx(re,{className:"h-4 w-4 text-amber-600"}),e.jsx(V,{className:"text-amber-700 dark:text-amber-400",children:s("settingsProxy.stopProxyToSwitch")})]}),e.jsxs("div",{className:"grid grid-cols-2 gap-3",children:[e.jsxs("button",{onClick:()=>xe("plus"),disabled:J.isPending||F,className:`p-4 rounded-lg border-2 text-left transition-all ${k==="plus"?"border-primary bg-primary/5":"border-border hover:border-muted-foreground/50"} ${F?"opacity-60 cursor-not-allowed":""}`,children:[e.jsx("div",{className:"flex items-center gap-3 mb-2",children:e.jsx("span",{className:"font-medium",children:s("settingsProxy.backendPlusApi")})}),e.jsx("p",{className:"text-xs text-muted-foreground",children:s("settingsProxy.plusDesc")}),e.jsx("p",{className:"mt-2 text-[11px] leading-relaxed text-muted-foreground",children:de})]}),e.jsxs("button",{onClick:()=>xe("original"),disabled:J.isPending||F,className:`p-4 rounded-lg border-2 text-left transition-all ${k==="original"?"border-primary bg-primary/5":"border-border hover:border-muted-foreground/50"} ${F?"opacity-60 cursor-not-allowed":""}`,children:[e.jsxs("div",{className:"flex items-center gap-3 mb-2",children:[e.jsx("span",{className:"font-medium",children:s("settingsProxy.backendApi")}),e.jsx("span",{className:"text-xs px-1.5 py-0.5 rounded bg-green-100 text-green-700 dark:bg-green-900/50 dark:text-green-400",children:s("settingsProxy.default")})]}),e.jsx("p",{className:"text-xs text-muted-foreground",children:s("settingsProxy.originalDesc")}),e.jsx("p",{className:"mt-2 text-[11px] leading-relaxed text-muted-foreground",children:Be})]})]}),k==="plus"&&e.jsxs(H,{className:"py-2 border-amber-200 bg-amber-50 dark:border-amber-900/50 dark:bg-amber-900/20 [&>svg]:top-2.5",children:[e.jsx(re,{className:"h-4 w-4 text-amber-600"}),e.jsx(V,{className:"text-amber-700 dark:text-amber-400",children:s("settingsProxy.plusFallbackNotice")})]}),k==="original"&&Ae&&e.jsxs(H,{variant:"destructive",className:"py-2",children:[e.jsx(re,{className:"h-4 w-4"}),e.jsx(V,{children:s("settingsProxy.variantsIncompatible",{providers:de})})]})]}),e.jsxs("div",{className:"space-y-3",children:[e.jsxs("h3",{className:"text-base font-medium flex items-center gap-2",children:[e.jsx(ls,{className:"w-4 h-4 text-amber-700 dark:text-amber-300"}),s("settingsProxy.safety")]}),e.jsxs("div",{className:"space-y-3 rounded-lg border border-amber-400/35 bg-amber-50/70 p-4 dark:border-amber-800/60 dark:bg-amber-950/25",children:[e.jsxs("div",{className:"flex items-start justify-between gap-4",children:[e.jsxs("div",{className:"space-y-1",children:[e.jsx("p",{className:"font-medium text-sm",children:s("settingsProxy.agyModeTitle")}),e.jsx("p",{className:"text-xs text-muted-foreground",children:s("settingsProxy.agyModeDesc")})]}),e.jsx(M,{"aria-labelledby":"agy-power-user-mode-label","aria-describedby":"agy-power-user-mode-description",checked:ve,disabled:ke||b||o,onCheckedChange:Se})]}),e.jsx("p",{id:"agy-power-user-mode-description",className:"text-xs text-amber-800/90 dark:text-amber-200/90",children:s("settingsProxy.agyWarning")}),Ne&&e.jsxs("div",{className:"space-y-3 rounded-lg border border-rose-500/40 bg-rose-500/[0.08] p-3.5",children:[e.jsxs("div",{className:"space-y-1.5",children:[e.jsx("p",{className:"text-xs font-semibold tracking-wide text-rose-900 dark:text-rose-200",children:s("settingsProxy.finalConfirm")}),e.jsx("p",{className:"text-xs leading-relaxed text-rose-800/95 dark:text-rose-200/90",children:s("settingsProxy.finalConfirmDesc")})]}),e.jsxs("div",{className:"grid gap-2 md:grid-cols-2",children:[e.jsxs("div",{className:"rounded-md border border-rose-400/30 bg-rose-500/10 p-2.5",children:[e.jsx("p",{className:"text-[11px] font-semibold uppercase tracking-wide text-rose-900 dark:text-rose-200",children:s("settingsProxy.step1")}),e.jsxs("a",{href:"https://github.com/kaitranntt/ccs/issues/509",target:"_blank",rel:"noreferrer",className:"mt-1 inline-flex items-center gap-1.5 text-xs font-medium text-rose-800 underline decoration-rose-500/60 underline-offset-2 transition-colors hover:text-rose-700 dark:text-rose-200",children:[s("settingsProxy.readIssue"),e.jsx(cs,{className:"h-3.5 w-3.5"})]})]}),e.jsxs("div",{className:"rounded-md border border-rose-400/30 bg-rose-500/10 p-2.5",children:[e.jsx("p",{className:"text-[11px] font-semibold uppercase tracking-wide text-rose-900 dark:text-rose-200",children:s("settingsProxy.step2")}),e.jsxs("p",{className:"mt-1 text-xs text-rose-800/95 dark:text-rose-200/90",children:[s("settingsProxy.typePrefix")," ",e.jsx("code",{className:"rounded bg-background/80 px-1 py-0.5 font-mono",children:U})," ",s("settingsProxy.typeSuffix")]})]})]}),e.jsxs("div",{className:"space-y-2",children:[e.jsx(B,{value:le,onChange:r=>I(r.target.value),placeholder:U,disabled:b||o,className:"font-mono text-xs","aria-label":s("settingsProxy.typePhraseAria")}),e.jsx("p",{className:"text-[11px] text-rose-800/90 dark:text-rose-200/80",children:s("settingsProxy.exactPhrase")})]}),e.jsxs("div",{className:"flex items-center justify-end gap-2",children:[e.jsx(z,{variant:"outline",size:"sm",onClick:()=>{L(!1),I("")},disabled:b||o,children:s("settingsBackups.cancel")}),e.jsx(z,{size:"sm",variant:"destructive",onClick:we,disabled:!X||b||o,children:s("settingsProxy.enableAgyMode")})]})]}),e.jsx("span",{id:"agy-power-user-mode-label",className:"sr-only",children:s("settingsProxy.toggleAgyMode")})]})]}),m&&e.jsx(us,{config:t,saving:o,testing:j,testResult:p,displayHost:ee,displayPort:se,displayAuthToken:te,displayManagementKey:me,setEditedHost:C,setEditedPort:P,setEditedAuthToken:A,setEditedManagementKey:d,onSaveHost:Ie,onSavePort:Ke,onSaveAuthToken:Oe,onSaveManagementKey:Fe,onSaveConfig:c,onTestConnection:He}),e.jsxs("div",{className:"space-y-3",children:[e.jsx("h3",{className:"text-base font-medium",children:s("settingsProxy.fallbackSettings")}),e.jsxs("div",{className:"space-y-3 p-4 rounded-lg border bg-muted/30",children:[e.jsxs("div",{className:"flex items-center justify-between",children:[e.jsxs("div",{children:[e.jsx("p",{className:"font-medium text-sm",children:s("settingsProxy.enableFallback")}),e.jsx("p",{className:"text-xs text-muted-foreground",children:s("settingsProxy.enableFallbackDesc")})]}),e.jsx(M,{checked:D.enabled??!0,onCheckedChange:r=>c({fallback:{...D,enabled:r}}),disabled:o||!m})]}),e.jsxs("div",{className:"flex items-center justify-between",children:[e.jsxs("div",{children:[e.jsx("p",{className:"font-medium text-sm",children:s("settingsProxy.autoStartLocal")}),e.jsx("p",{className:"text-xs text-muted-foreground",children:s("settingsProxy.autoStartLocalDesc")})]}),e.jsx(M,{checked:D.auto_start??!1,onCheckedChange:r=>c({fallback:{...D,auto_start:r}}),disabled:o||!m||!D.enabled})]})]})]}),e.jsxs("div",{className:"space-y-3",children:[e.jsxs("h3",{className:"text-base font-medium flex items-center gap-2",children:[e.jsx(ds,{className:"w-4 h-4"}),s("settingsProxy.advanced")]}),e.jsxs("div",{className:"space-y-3 p-4 rounded-lg border bg-muted/30",children:[e.jsxs("div",{className:"flex items-center justify-between",children:[e.jsxs("div",{children:[e.jsx("p",{className:"font-medium text-sm",children:s("settingsProxy.debugMode")}),e.jsx("p",{className:"text-xs text-muted-foreground",children:s("settingsProxy.debugModeDesc")})]}),e.jsx(M,{checked:_,onCheckedChange:Ce,disabled:o})]}),_&&e.jsx("p",{className:"text-xs text-amber-600 dark:text-amber-400 pl-0.5",children:s("settingsProxy.debugModeEnabled")})]})]}),!m&&e.jsx(gs,{config:t,saving:o,displayLocalPort:ge,setEditedLocalPort:h,onSaveLocalPort:$e,onSaveConfig:c})]})}),e.jsx("div",{className:"p-4 border-t bg-background",children:e.jsxs(z,{variant:"outline",size:"sm",onClick:()=>{a(),G(),l(),Q(),Z()},disabled:g||o||b,className:"w-full",children:[e.jsx(ae,{className:`w-4 h-4 mr-2 ${g?"animate-spin":""}`}),s("settings.refresh")]})})]})}export{Ts as default};
|
|
1
|
+
import{j as e}from"./radix-ui-Zb8sVEtn.js";import{r as n}from"./react-vendor-CNOkPC89.js";import{bt as Ue,bu as ze,Y as R,a as oe,I as B,aI as M,r as We,s as Ye,t as Xe,v as Ge,w as ye,d as z,bv as qe,bw as Je,bx as Qe,by as Ze,b6 as he,bz as es,bA as ss,bi as H,bk as V,n as ts}from"./index-DhAjOd4r.js";import{C as W}from"./default-ports-1QQSffYX.js";import{bb as fe,R as ae,h as rs,x as je,W as as,w as os,aA as ns,bc as is,T as re,aH as ls,p as cs,bd as ds}from"./icons-DyorC3Xk.js";import{P as xs}from"./proxy-status-widget-C6Ctzus0.js";import{R as U}from"./antigravity-responsibility-constants-Bvh4Ybz0.js";import{t as T}from"./notifications-B2HqRBj7.js";import"./tanstack-CrmUhA7Z.js";import"./utils-CzKF5WmX.js";import"./form-utils-Bcoyqxpq.js";import"./code-highlight-BRUf_pqB.js";import"./alert-dialog-DuiOADsV.js";function ms(){const{state:s}=Ue(),t=ze(),[g,o]=n.useState(null),[u,f]=n.useState(null),[p,j]=n.useState(null),[y,C]=n.useState(null),[S,P]=n.useState(null),w=n.useCallback(async()=>{try{t.setProxyLoading(!0),t.setProxyError(null);const d=await R.cliproxyServer.get();t.setProxyConfig(d)}catch(d){t.setProxyError(d.message)}finally{t.setProxyLoading(!1)}},[t]),A=n.useCallback(async d=>{const x=s.proxyConfig;if(!x)return;const h={remote:{...x.remote,...d.remote},fallback:{...x.fallback,...d.fallback},local:{...x.local,...d.local}};t.setProxyConfig(h),t.setProxyTestResult(null);try{t.setProxySaving(!0),t.setProxyError(null);const a=await R.cliproxyServer.update(d);t.setProxyConfig(a),t.setProxySuccess(!0),setTimeout(()=>t.setProxySuccess(!1),1500)}catch(a){t.setProxyConfig(x),t.setProxyError(a.message)}finally{t.setProxySaving(!1)}},[s.proxyConfig,t]),E=n.useCallback(async d=>{const{host:x,port:h,protocol:a,authToken:c}=d;if(!x){t.setProxyError("Host is required");return}try{t.setProxyTesting(!0),t.setProxyError(null),t.setProxyTestResult(null);const v=h?parseInt(h,10):void 0,l=await R.cliproxyServer.test({host:x,port:v||void 0,protocol:a,authToken:c||void 0});t.setProxyTestResult(l)}catch(v){t.setProxyError(v.message)}finally{t.setProxyTesting(!1)}},[t]);return{config:s.proxyConfig,loading:s.proxyLoading,saving:s.proxySaving,error:s.proxyError,success:s.proxySuccess,testResult:s.proxyTestResult,testing:s.proxyTesting,editedHost:g,setEditedHost:o,editedPort:u,setEditedPort:f,editedAuthToken:p,setEditedAuthToken:j,editedManagementKey:y,setEditedManagementKey:C,editedLocalPort:S,setEditedLocalPort:P,fetchConfig:w,saveConfig:A,testConnection:E}}function gs({config:s,saving:t,displayLocalPort:g,setEditedLocalPort:o,onSaveLocalPort:u,onSaveConfig:f}){const{t:p}=oe(),j=s.local;return e.jsxs("div",{className:"space-y-3",children:[e.jsx("h3",{className:"text-base font-medium",children:p("settingsProxy.localProxy")}),e.jsxs("div",{className:"space-y-3 p-4 rounded-lg border bg-muted/30",children:[e.jsxs("div",{className:"flex items-center gap-2",children:[e.jsx("label",{className:"text-sm text-muted-foreground",children:p("settingsProxy.port")}),e.jsx(B,{type:"text",inputMode:"numeric",value:g,onChange:y=>o(y.target.value.replace(/\D/g,"")),onBlur:u,placeholder:`${W}`,className:"font-mono max-w-32",disabled:t})]}),e.jsxs("div",{className:"flex items-center justify-between",children:[e.jsxs("div",{children:[e.jsx("p",{className:"font-medium text-sm",children:p("settingsProxy.autoStart")}),e.jsx("p",{className:"text-xs text-muted-foreground",children:p("settingsProxy.localAutoStartDesc")})]}),e.jsx(M,{checked:j.auto_start??!0,onCheckedChange:y=>f({local:{...j,auto_start:y}}),disabled:t})]})]})]})}function us({config:s,saving:t,testing:g,testResult:o,displayHost:u,displayPort:f,displayAuthToken:p,displayManagementKey:j,setEditedHost:y,setEditedPort:C,setEditedAuthToken:S,setEditedManagementKey:P,onSaveHost:w,onSavePort:A,onSaveAuthToken:E,onSaveManagementKey:d,onSaveConfig:x,onTestConnection:h}){const{t:a}=oe(),c=s.remote,v=l=>l==="https"?443:W;return e.jsxs("div",{className:"space-y-4 p-4 rounded-lg border bg-muted/30",children:[e.jsxs("h4",{className:"text-sm font-medium flex items-center gap-2",children:[e.jsx(fe,{className:"w-4 h-4"}),a("settingsProxy.remoteConfigTitle")]}),e.jsxs("div",{className:"space-y-1",children:[e.jsx("label",{className:"text-sm text-muted-foreground",children:a("settingsProxy.host")}),e.jsx(B,{value:u,onChange:l=>y(l.target.value),onBlur:w,placeholder:a("settingsProxy.hostPlaceholder"),className:"font-mono",disabled:t})]}),e.jsxs("div",{className:"grid grid-cols-2 gap-3",children:[e.jsxs("div",{className:"space-y-1",children:[e.jsxs("label",{className:"text-sm text-muted-foreground",children:[a("settingsProxy.port")," ",e.jsxs("span",{className:"text-xs opacity-70",children:["(",a("settingsProxy.defaultPort",{value:v(s.remote.protocol||"http")}),")"]})]}),e.jsx(B,{type:"text",inputMode:"numeric",value:f,onChange:l=>C(l.target.value.replace(/\D/g,"")),onBlur:A,placeholder:a("settingsProxy.portPlaceholder",{value:v(s.remote.protocol||"http")}),className:"font-mono",disabled:t})]}),e.jsxs("div",{className:"space-y-1",children:[e.jsx("label",{className:"text-sm text-muted-foreground",children:a("settingsProxy.protocol")}),e.jsxs(We,{value:s.remote.protocol||"http",onValueChange:l=>x({remote:{...c,protocol:l}}),disabled:t,children:[e.jsx(Ye,{children:e.jsx(Xe,{})}),e.jsxs(Ge,{children:[e.jsx(ye,{value:"http",children:a("settingsProxy.http")}),e.jsx(ye,{value:"https",children:a("settingsProxy.https")})]})]})]})]}),e.jsxs("div",{className:"space-y-1",children:[e.jsx("label",{className:"text-sm text-muted-foreground",children:a("settingsProxy.apiKeyOptional")}),e.jsx(B,{type:"password",value:p,onChange:l=>S(l.target.value),onBlur:E,placeholder:a("settingsProxy.apiKeyPlaceholder"),className:"font-mono",disabled:t}),e.jsx("p",{className:"text-xs text-muted-foreground",children:a("settingsProxy.apiKeyDesc")})]}),e.jsxs("div",{className:"space-y-1",children:[e.jsx("label",{className:"text-sm text-muted-foreground",children:a("settingsProxy.managementKeyOptional")}),e.jsx(B,{type:"password",value:j,onChange:l=>P(l.target.value),onBlur:d,placeholder:a("settingsProxy.managementKeyPlaceholder"),className:"font-mono",disabled:t}),e.jsx("p",{className:"text-xs text-muted-foreground",children:a("settingsProxy.managementKeyDesc")})]}),e.jsxs("div",{className:"space-y-3 pt-2",children:[e.jsx(z,{onClick:h,disabled:g||!u,variant:"outline",className:"w-full",children:g?e.jsxs(e.Fragment,{children:[e.jsx(ae,{className:"w-4 h-4 mr-2 animate-spin"}),a("settingsProxy.testing")]}):e.jsxs(e.Fragment,{children:[e.jsx(rs,{className:"w-4 h-4 mr-2"}),a("settingsProxy.testConnection")]})}),o&&e.jsx("div",{className:`p-3 rounded-md ${o.reachable?"bg-green-50 border border-green-200 dark:bg-green-900/20 dark:border-green-900/50":"bg-red-50 border border-red-200 dark:bg-red-900/20 dark:border-red-900/50"}`,children:e.jsx("div",{className:"flex items-center gap-2",children:o.reachable?e.jsxs(e.Fragment,{children:[e.jsx(je,{className:"w-4 h-4 text-green-600 dark:text-green-400"}),e.jsx("span",{className:"text-sm font-medium text-green-700 dark:text-green-300",children:a("settingsProxy.connectedLatency",{value:o.latencyMs})})]}):e.jsxs(e.Fragment,{children:[e.jsx(as,{className:"w-4 h-4 text-red-600 dark:text-red-400"}),e.jsx("span",{className:"text-sm font-medium text-red-700 dark:text-red-300",children:o.error||a("settingsProxy.connectionFailed")})]})})})]})]})}const be="ccs_debug_mode";function ps(s){return s.trim().replace(/\s+/g," ").toUpperCase()}function Ts(){const{t:s}=oe(),{config:t,loading:g,saving:o,error:u,success:f,testResult:p,testing:j,editedHost:y,setEditedHost:C,editedPort:S,setEditedPort:P,editedAuthToken:w,setEditedAuthToken:A,editedManagementKey:E,setEditedManagementKey:d,editedLocalPort:x,setEditedLocalPort:h,fetchConfig:a,saveConfig:c,testConnection:v}=ms(),{fetchRawConfig:l}=qe(),[_,Pe]=n.useState(()=>{try{return localStorage.getItem(be)==="true"}catch{return!1}}),[ve,Y]=n.useState(!1),[ke,ne]=n.useState(!0),[b,ie]=n.useState(!1),[Ne,L]=n.useState(!1),[le,I]=n.useState(""),K=n.useRef(!1),X=ps(le)===U,Ce=r=>{Pe(r);try{localStorage.setItem(be,String(r))}catch{}},G=n.useCallback(async()=>{try{ne(!0);const r=await fetch("/api/settings/auth/antigravity-risk");if(!r.ok)throw new Error(s("settingsProxy.failedLoadAgyMode"));const i=await r.json();Y(i.antigravityAckBypass===!0)}catch(r){T.error(r instanceof Error?r.message:s("settingsProxy.failedLoadAgyMode")),Y(!1)}finally{ne(!1)}},[s]),O=n.useCallback(async r=>{if(!(K.current||b||o))try{K.current=!0,ie(!0);const i=await fetch("/api/settings/auth/antigravity-risk",{method:"PUT",headers:{"Content-Type":"application/json"},body:JSON.stringify({antigravityAckBypass:r})}),$=await i.json();if(!i.ok)throw new Error($.error||s("settingsProxy.failedUpdateAgyMode"));const Ve=$.antigravityAckBypass===!0,ue=await fetch("/api/settings/auth/antigravity-risk",{cache:"no-store"});if(!ue.ok)throw new Error(s("settingsProxy.failedVerifyAgyMode"));const pe=(await ue.json()).antigravityAckBypass===!0;if(pe!==r)throw new Error(s("settingsProxy.notPersistedAgyMode"));Y(pe&&Ve),L(!1),I(""),T.success(s(r?"settingsProxy.agyModeEnabled":"settingsProxy.agyModeDisabled")),await l()}catch(i){T.error(i instanceof Error?i.message:s("settingsProxy.failedUpdateAgyMode"))}finally{K.current=!1,ie(!1)}},[b,l,o,s]),Se=n.useCallback(r=>{if(!(K.current||b||o)){if(r){L(!0);return}L(!1),I(""),O(!1)}},[b,O,o]),we=n.useCallback(()=>{if(!X){T.error(s("settingsProxy.typePhraseToContinue",{value:U}));return}O(!0)},[X,O,s]),[k,q]=n.useState("original"),[Ae,Ee]=n.useState(!1),J=Je(),{data:Te}=Qe(),ce=Te?.running??!1,Be=Ze.map(he).join(", "),de=es.map(he).join(", "),Q=n.useCallback(async()=>{try{const r=await R.cliproxyServer.getBackend();q(r.backend)}catch(r){console.error("[Proxy] Failed to fetch backend:",r)}},[]),Z=n.useCallback(async()=>{try{const i=(await R.cliproxy.list()).variants.some($=>ss($));Ee(i)}catch(r){console.error("[Proxy] Failed to check variants:",r)}},[]),xe=r=>{const i=k;q(r),J.mutate({backend:r},{onError:()=>{q(i)}})};if(n.useEffect(()=>{if(_&&t){const r={...t,remote:{...t.remote,auth_token:t.remote.auth_token?"[REDACTED]":void 0,management_key:t.remote.management_key?"[REDACTED]":void 0}};console.log("[CCS Debug] Debug mode enabled - proxy config:",r)}},[_,t]),n.useEffect(()=>{a(),G(),l(),Q(),Z()},[a,G,l,Q,Z]),g||!t)return e.jsx("div",{className:"flex-1 flex items-center justify-center",children:e.jsxs("div",{className:"flex items-center gap-3 text-muted-foreground",children:[e.jsx(ae,{className:"w-5 h-5 animate-spin"}),e.jsx("span",{children:s("settings.loading")})]})});const m=t.remote.enabled??!1,F=!m&&ce,N=t.remote,D=t.fallback,De=t.remote.host??"",Me=t.remote.port!==void 0?t.remote.port.toString():"",Re=t.remote.auth_token??"",_e=t.remote.management_key??"",Le=(t.local.port??W).toString(),ee=y??De,se=S??Me,te=w??Re,me=E??_e,ge=x??Le,Ie=()=>{const r=y??ee;r!==t.remote.host&&c({remote:{...N,host:r}}),C(null)},Ke=()=>{const r=(S??se).trim();if(r===""){t.remote.port!==void 0&&c({remote:{...N,port:void 0}}),P(null);return}const i=Number(r);if(!Number.isInteger(i)||i<1||i>65535){T.error(s("settingsProxy.invalidPortOrEmpty")),P(null);return}i!==t.remote.port&&c({remote:{...N,port:i}}),P(null)},Oe=()=>{const r=w??te;r!==t.remote.auth_token&&c({remote:{...N,auth_token:r}}),A(null)},Fe=()=>{const r=E??me;r!==t.remote.management_key&&c({remote:{...N,management_key:r||void 0}}),d(null)},$e=()=>{const r=(x??ge).trim(),i=r===""?W:Number(r);if(!Number.isInteger(i)||i<1||i>65535){T.error(s("settingsProxy.invalidLocalPort")),h(null);return}i!==t.local.port&&c({local:{...t.local,port:i}}),h(null)},He=()=>{v({host:ee,port:se,protocol:t.remote.protocol||"http",authToken:te})};return e.jsxs(e.Fragment,{children:[e.jsxs("div",{className:`absolute left-5 right-5 top-20 z-10 transition-all duration-200 ease-out ${u||f?"opacity-100 translate-y-0":"opacity-0 -translate-y-2 pointer-events-none"}`,children:[u&&e.jsxs(H,{variant:"destructive",className:"py-2 shadow-lg",children:[e.jsx(os,{className:"h-4 w-4"}),e.jsx(V,{children:u})]}),f&&e.jsxs("div",{className:"flex items-center gap-2 px-3 py-2 rounded-md border border-green-200 bg-green-50 text-green-700 shadow-lg dark:border-green-900/50 dark:bg-green-900/90 dark:text-green-300",children:[e.jsx(je,{className:"h-4 w-4 shrink-0"}),e.jsx("span",{className:"text-sm font-medium",children:s("settings.saved")})]})]}),e.jsx(ts,{className:"flex-1",children:e.jsxs("div",{className:"p-5 space-y-6",children:[e.jsx("p",{className:"text-sm text-muted-foreground",children:s("settingsProxy.description",{backend:s(k==="plus"?"settingsProxy.backendPlus":"settingsProxy.backend")})}),!m&&e.jsxs("div",{className:"space-y-3",children:[e.jsx("h3",{className:"text-base font-medium",children:s("settingsProxy.instanceStatus")}),e.jsx(xs,{})]}),e.jsxs("div",{className:"space-y-3",children:[e.jsx("h3",{className:"text-base font-medium",children:s("settingsProxy.connectionMode")}),e.jsxs("div",{className:"grid grid-cols-2 gap-3",children:[e.jsxs("button",{onClick:()=>c({remote:{...N,enabled:!1}}),disabled:o,className:`p-4 rounded-lg border-2 text-left transition-all ${m?"border-border hover:border-muted-foreground/50":"border-primary bg-primary/5"}`,children:[e.jsxs("div",{className:"flex items-center gap-3 mb-2",children:[e.jsx(ns,{className:`w-5 h-5 ${m?"text-muted-foreground":"text-primary"}`}),e.jsx("span",{className:"font-medium",children:s("settingsProxy.local")})]}),e.jsx("p",{className:"text-xs text-muted-foreground",children:s("settingsProxy.localDesc",{backend:s(k==="plus"?"settingsProxy.backendPlus":"settingsProxy.backend")})})]}),e.jsxs("button",{onClick:()=>c({remote:{...N,enabled:!0}}),disabled:o,className:`p-4 rounded-lg border-2 text-left transition-all ${m?"border-primary bg-primary/5":"border-border hover:border-muted-foreground/50"}`,children:[e.jsxs("div",{className:"flex items-center gap-3 mb-2",children:[e.jsx(fe,{className:`w-5 h-5 ${m?"text-primary":"text-muted-foreground"}`}),e.jsx("span",{className:"font-medium",children:s("settingsProxy.remote")})]}),e.jsx("p",{className:"text-xs text-muted-foreground",children:s("settingsProxy.remoteDesc",{backend:s(k==="plus"?"settingsProxy.backendPlus":"settingsProxy.backend")})})]})]})]}),e.jsxs("div",{className:"space-y-3",children:[e.jsxs("h3",{className:"text-base font-medium flex items-center gap-2",children:[e.jsx(is,{className:"w-4 h-4"}),s("settingsProxy.backendBinary")]}),!m&&ce&&e.jsxs(H,{className:"py-2 border-amber-200 bg-amber-50 dark:border-amber-900/50 dark:bg-amber-900/20 [&>svg]:top-2.5",children:[e.jsx(re,{className:"h-4 w-4 text-amber-600"}),e.jsx(V,{className:"text-amber-700 dark:text-amber-400",children:s("settingsProxy.stopProxyToSwitch")})]}),e.jsxs("div",{className:"grid grid-cols-2 gap-3",children:[e.jsxs("button",{onClick:()=>xe("plus"),disabled:J.isPending||F,className:`p-4 rounded-lg border-2 text-left transition-all ${k==="plus"?"border-primary bg-primary/5":"border-border hover:border-muted-foreground/50"} ${F?"opacity-60 cursor-not-allowed":""}`,children:[e.jsx("div",{className:"flex items-center gap-3 mb-2",children:e.jsx("span",{className:"font-medium",children:s("settingsProxy.backendPlusApi")})}),e.jsx("p",{className:"text-xs text-muted-foreground",children:s("settingsProxy.plusDesc")}),e.jsx("p",{className:"mt-2 text-[11px] leading-relaxed text-muted-foreground",children:de})]}),e.jsxs("button",{onClick:()=>xe("original"),disabled:J.isPending||F,className:`p-4 rounded-lg border-2 text-left transition-all ${k==="original"?"border-primary bg-primary/5":"border-border hover:border-muted-foreground/50"} ${F?"opacity-60 cursor-not-allowed":""}`,children:[e.jsxs("div",{className:"flex items-center gap-3 mb-2",children:[e.jsx("span",{className:"font-medium",children:s("settingsProxy.backendApi")}),e.jsx("span",{className:"text-xs px-1.5 py-0.5 rounded bg-green-100 text-green-700 dark:bg-green-900/50 dark:text-green-400",children:s("settingsProxy.default")})]}),e.jsx("p",{className:"text-xs text-muted-foreground",children:s("settingsProxy.originalDesc")}),e.jsx("p",{className:"mt-2 text-[11px] leading-relaxed text-muted-foreground",children:Be})]})]}),k==="plus"&&e.jsxs(H,{className:"py-2 border-amber-200 bg-amber-50 dark:border-amber-900/50 dark:bg-amber-900/20 [&>svg]:top-2.5",children:[e.jsx(re,{className:"h-4 w-4 text-amber-600"}),e.jsx(V,{className:"text-amber-700 dark:text-amber-400",children:s("settingsProxy.plusFallbackNotice")})]}),k==="original"&&Ae&&e.jsxs(H,{variant:"destructive",className:"py-2",children:[e.jsx(re,{className:"h-4 w-4"}),e.jsx(V,{children:s("settingsProxy.variantsIncompatible",{providers:de})})]})]}),e.jsxs("div",{className:"space-y-3",children:[e.jsxs("h3",{className:"text-base font-medium flex items-center gap-2",children:[e.jsx(ls,{className:"w-4 h-4 text-amber-700 dark:text-amber-300"}),s("settingsProxy.safety")]}),e.jsxs("div",{className:"space-y-3 rounded-lg border border-amber-400/35 bg-amber-50/70 p-4 dark:border-amber-800/60 dark:bg-amber-950/25",children:[e.jsxs("div",{className:"flex items-start justify-between gap-4",children:[e.jsxs("div",{className:"space-y-1",children:[e.jsx("p",{className:"font-medium text-sm",children:s("settingsProxy.agyModeTitle")}),e.jsx("p",{className:"text-xs text-muted-foreground",children:s("settingsProxy.agyModeDesc")})]}),e.jsx(M,{"aria-labelledby":"agy-power-user-mode-label","aria-describedby":"agy-power-user-mode-description",checked:ve,disabled:ke||b||o,onCheckedChange:Se})]}),e.jsx("p",{id:"agy-power-user-mode-description",className:"text-xs text-amber-800/90 dark:text-amber-200/90",children:s("settingsProxy.agyWarning")}),Ne&&e.jsxs("div",{className:"space-y-3 rounded-lg border border-rose-500/40 bg-rose-500/[0.08] p-3.5",children:[e.jsxs("div",{className:"space-y-1.5",children:[e.jsx("p",{className:"text-xs font-semibold tracking-wide text-rose-900 dark:text-rose-200",children:s("settingsProxy.finalConfirm")}),e.jsx("p",{className:"text-xs leading-relaxed text-rose-800/95 dark:text-rose-200/90",children:s("settingsProxy.finalConfirmDesc")})]}),e.jsxs("div",{className:"grid gap-2 md:grid-cols-2",children:[e.jsxs("div",{className:"rounded-md border border-rose-400/30 bg-rose-500/10 p-2.5",children:[e.jsx("p",{className:"text-[11px] font-semibold uppercase tracking-wide text-rose-900 dark:text-rose-200",children:s("settingsProxy.step1")}),e.jsxs("a",{href:"https://github.com/kaitranntt/ccs/issues/509",target:"_blank",rel:"noreferrer",className:"mt-1 inline-flex items-center gap-1.5 text-xs font-medium text-rose-800 underline decoration-rose-500/60 underline-offset-2 transition-colors hover:text-rose-700 dark:text-rose-200",children:[s("settingsProxy.readIssue"),e.jsx(cs,{className:"h-3.5 w-3.5"})]})]}),e.jsxs("div",{className:"rounded-md border border-rose-400/30 bg-rose-500/10 p-2.5",children:[e.jsx("p",{className:"text-[11px] font-semibold uppercase tracking-wide text-rose-900 dark:text-rose-200",children:s("settingsProxy.step2")}),e.jsxs("p",{className:"mt-1 text-xs text-rose-800/95 dark:text-rose-200/90",children:[s("settingsProxy.typePrefix")," ",e.jsx("code",{className:"rounded bg-background/80 px-1 py-0.5 font-mono",children:U})," ",s("settingsProxy.typeSuffix")]})]})]}),e.jsxs("div",{className:"space-y-2",children:[e.jsx(B,{value:le,onChange:r=>I(r.target.value),placeholder:U,disabled:b||o,className:"font-mono text-xs","aria-label":s("settingsProxy.typePhraseAria")}),e.jsx("p",{className:"text-[11px] text-rose-800/90 dark:text-rose-200/80",children:s("settingsProxy.exactPhrase")})]}),e.jsxs("div",{className:"flex items-center justify-end gap-2",children:[e.jsx(z,{variant:"outline",size:"sm",onClick:()=>{L(!1),I("")},disabled:b||o,children:s("settingsBackups.cancel")}),e.jsx(z,{size:"sm",variant:"destructive",onClick:we,disabled:!X||b||o,children:s("settingsProxy.enableAgyMode")})]})]}),e.jsx("span",{id:"agy-power-user-mode-label",className:"sr-only",children:s("settingsProxy.toggleAgyMode")})]})]}),m&&e.jsx(us,{config:t,saving:o,testing:j,testResult:p,displayHost:ee,displayPort:se,displayAuthToken:te,displayManagementKey:me,setEditedHost:C,setEditedPort:P,setEditedAuthToken:A,setEditedManagementKey:d,onSaveHost:Ie,onSavePort:Ke,onSaveAuthToken:Oe,onSaveManagementKey:Fe,onSaveConfig:c,onTestConnection:He}),e.jsxs("div",{className:"space-y-3",children:[e.jsx("h3",{className:"text-base font-medium",children:s("settingsProxy.fallbackSettings")}),e.jsxs("div",{className:"space-y-3 p-4 rounded-lg border bg-muted/30",children:[e.jsxs("div",{className:"flex items-center justify-between",children:[e.jsxs("div",{children:[e.jsx("p",{className:"font-medium text-sm",children:s("settingsProxy.enableFallback")}),e.jsx("p",{className:"text-xs text-muted-foreground",children:s("settingsProxy.enableFallbackDesc")})]}),e.jsx(M,{checked:D.enabled??!0,onCheckedChange:r=>c({fallback:{...D,enabled:r}}),disabled:o||!m})]}),e.jsxs("div",{className:"flex items-center justify-between",children:[e.jsxs("div",{children:[e.jsx("p",{className:"font-medium text-sm",children:s("settingsProxy.autoStartLocal")}),e.jsx("p",{className:"text-xs text-muted-foreground",children:s("settingsProxy.autoStartLocalDesc")})]}),e.jsx(M,{checked:D.auto_start??!1,onCheckedChange:r=>c({fallback:{...D,auto_start:r}}),disabled:o||!m||!D.enabled})]})]})]}),e.jsxs("div",{className:"space-y-3",children:[e.jsxs("h3",{className:"text-base font-medium flex items-center gap-2",children:[e.jsx(ds,{className:"w-4 h-4"}),s("settingsProxy.advanced")]}),e.jsxs("div",{className:"space-y-3 p-4 rounded-lg border bg-muted/30",children:[e.jsxs("div",{className:"flex items-center justify-between",children:[e.jsxs("div",{children:[e.jsx("p",{className:"font-medium text-sm",children:s("settingsProxy.debugMode")}),e.jsx("p",{className:"text-xs text-muted-foreground",children:s("settingsProxy.debugModeDesc")})]}),e.jsx(M,{checked:_,onCheckedChange:Ce,disabled:o})]}),_&&e.jsx("p",{className:"text-xs text-amber-600 dark:text-amber-400 pl-0.5",children:s("settingsProxy.debugModeEnabled")})]})]}),!m&&e.jsx(gs,{config:t,saving:o,displayLocalPort:ge,setEditedLocalPort:h,onSaveLocalPort:$e,onSaveConfig:c})]})}),e.jsx("div",{className:"p-4 border-t bg-background",children:e.jsxs(z,{variant:"outline",size:"sm",onClick:()=>{a(),G(),l(),Q(),Z()},disabled:g||o||b,className:"w-full",children:[e.jsx(ae,{className:`w-4 h-4 mr-2 ${g?"animate-spin":""}`}),s("settings.refresh")]})})]})}export{Ts as default};
|