@kaitranntt/ccs 7.69.1-dev.4 → 7.69.1-dev.6

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (49) hide show
  1. package/dist/commands/tokens-command.d.ts.map +1 -1
  2. package/dist/commands/tokens-command.js +26 -37
  3. package/dist/commands/tokens-command.js.map +1 -1
  4. package/dist/ui/assets/accounts-DamxGxu1.js +1 -0
  5. package/dist/ui/assets/{alert-dialog-CuN8HTEx.js → alert-dialog-sars2LJq.js} +1 -1
  6. package/dist/ui/assets/{api-CI8RoZ-m.js → api-DHF10LeP.js} +1 -1
  7. package/dist/ui/assets/{auth-section-C49fRTna.js → auth-section-BNmbrWhd.js} +1 -1
  8. package/dist/ui/assets/{backups-section-DeJGo6Co.js → backups-section-DGURGm2o.js} +1 -1
  9. package/dist/ui/assets/channels-B0j9pbpo.js +1 -0
  10. package/dist/ui/assets/{checkbox-DVHcE1RO.js → checkbox-DQIFU7Wu.js} +1 -1
  11. package/dist/ui/assets/claude-extension-qxiVTjYL.js +1 -0
  12. package/dist/ui/assets/{cliproxy-BQuYNZ_b.js → cliproxy-CdvU0y2i.js} +1 -1
  13. package/dist/ui/assets/{cliproxy-ai-providers-Bjx7XtY6.js → cliproxy-ai-providers-zgUBcUcJ.js} +1 -1
  14. package/dist/ui/assets/{cliproxy-control-panel-DoLho1iE.js → cliproxy-control-panel-S6FdJjgh.js} +1 -1
  15. package/dist/ui/assets/codex-B79sHpGl.js +27 -0
  16. package/dist/ui/assets/{confirm-dialog-D_5v8muu.js → confirm-dialog-DwrX5gr_.js} +1 -1
  17. package/dist/ui/assets/{copilot-B4waN1q6.js → copilot-CgE4vyvS.js} +1 -1
  18. package/dist/ui/assets/{cursor-DHHZs05u.js → cursor-rYsOav5G.js} +1 -1
  19. package/dist/ui/assets/{droid-CZePX0Pf.js → droid-CQlRU59Q.js} +1 -1
  20. package/dist/ui/assets/{globalenv-section-nQDFHMda.js → globalenv-section-DSQ3m4Ei.js} +1 -1
  21. package/dist/ui/assets/{health-BfS7V7RZ.js → health-DE-wdzdl.js} +1 -1
  22. package/dist/ui/assets/{index-EboJtDBz.js → index-BcJqrfhu.js} +1 -1
  23. package/dist/ui/assets/{index-C5CFzca_.js → index-BwtPYSbP.js} +1 -1
  24. package/dist/ui/assets/{index-CRiWOwLR.js → index-C5VFMOG4.js} +1 -1
  25. package/dist/ui/assets/index-CqJW-L_1.js +1 -0
  26. package/dist/ui/assets/{index-B9VMppQ3.js → index-D1jFmelj.js} +1 -1
  27. package/dist/ui/assets/index-g2g1k0QS.js +72 -0
  28. package/dist/ui/assets/{logs-GW0Oy6XF.js → logs-CDpci_AI.js} +1 -1
  29. package/dist/ui/assets/{masked-input-D1Ilmeh7.js → masked-input-DXzbXJrE.js} +1 -1
  30. package/dist/ui/assets/{proxy-status-widget-Bdh67BxQ.js → proxy-status-widget-DCQBVSBP.js} +1 -1
  31. package/dist/ui/assets/{raw-json-settings-editor-panel-DwzGE_kH.js → raw-json-settings-editor-panel-Db_WTo0f.js} +1 -1
  32. package/dist/ui/assets/{searchable-select-DbhlbNK0.js → searchable-select-CHzzY0Km.js} +1 -1
  33. package/dist/ui/assets/{separator-DziIoy6O.js → separator-Bd4OFZm5.js} +1 -1
  34. package/dist/ui/assets/{shared-XJ2EhJPB.js → shared-B8K097LC.js} +1 -1
  35. package/dist/ui/assets/{table-D5bWyv-8.js → table-7IypCMku.js} +1 -1
  36. package/dist/ui/assets/updates-4X5hHhUg.js +1 -0
  37. package/dist/ui/index.html +1 -1
  38. package/package.json +1 -1
  39. package/dist/ui/assets/accounts-D7sfwYrK.js +0 -1
  40. package/dist/ui/assets/channels-CEHW5H6N.js +0 -1
  41. package/dist/ui/assets/claude-extension-CLmICnx_.js +0 -1
  42. package/dist/ui/assets/codex-BDfvFO8E.js +0 -27
  43. package/dist/ui/assets/index-BDfXfBTa.js +0 -72
  44. package/dist/ui/assets/index-yt8jgaSK.js +0 -1
  45. package/dist/ui/assets/updates-ClhhaqwU.js +0 -1
  46. package/scripts/github/build-ai-review-packet.mjs +0 -242
  47. package/scripts/github/normalize-ai-review-output.mjs +0 -934
  48. package/scripts/github/prepare-ai-review-scope.mjs +0 -324
  49. package/scripts/github/run-ai-review-direct.mjs +0 -349
@@ -1 +1 @@
1
- import{j as e}from"./radix-ui-Zb8sVEtn.js";import{r as f,c as pe}from"./react-vendor-CNOkPC89.js";import{u as A,a as L,C as g,b as j,S as h,c as d,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 S,l as ye,m as Ne,n as we,o as ve}from"./index-BDfXfBTa.js";import{a3 as be,al as re,am as Y,an as ne,a1 as le,aa as ke,G as Ce,ao as Se,R as De,$ as V,U as $e,Z as ie,v as Le,ad as H,ap as Fe,Y as Re,C as Te,aq as Me,ar as Pe}from"./icons-KVCk4_U8.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}=L();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(h,{className:"h-4 w-[100px]"}),e.jsx(h,{className:"h-8 w-[80px]"})]}),e.jsx(h,{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:be,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 x=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:d("text-xl font-bold truncate",a&&w),children:n.format(n.value)}),n.subtitle&&e.jsx("p",{className:d("text-[10px] text-muted-foreground truncate",a&&w),children:n.subtitle})]}),e.jsx("div",{className:d("p-2 rounded-lg shrink-0",n.bgColor),children:e.jsx(x,{className:d("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}=L(),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:d("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:d("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:d("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 v(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",v(s.startDate)),s?.endDate&&t.append("until",v(s.endDate)),s?.profile&&t.append("profile",s.profile),$(`/usage/summary?${t}`)},trends:s=>{const t=new URLSearchParams;return s?.startDate&&t.append("since",v(s.startDate)),s?.endDate&&t.append("until",v(s.endDate)),s?.profile&&t.append("profile",s.profile),$(`/usage/daily?${t}`)},hourly:s=>{const t=new URLSearchParams;return s?.startDate&&t.append("since",v(s.startDate)),s?.endDate&&t.append("until",v(s.endDate)),$(`/usage/hourly?${t}`)},models:s=>{const t=new URLSearchParams;return s?.startDate&&t.append("since",v(s.startDate)),s?.endDate&&t.append("until",v(s.endDate)),s?.profile&&t.append("profile",s.profile),$(`/usage/models?${t}`)},sessions:s=>{const t=new URLSearchParams;return s?.startDate&&t.append("since",v(s.startDate)),s?.endDate&&t.append("until",v(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()),$(`/usage/sessions?${t}`)},monthly:(s,t)=>{const a=new URLSearchParams;return s&&a.append("months",s.toString()),t&&a.append("profile",t),$(`/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:()=>$("/usage/status"),insights:s=>{const t=new URLSearchParams;return s?.startDate&&t.append("since",v(s.startDate)),s?.endDate&&t.append("until",v(s.endDate)),s?.profile&&t.append("profile",s.profile),$(`/usage/insights?${t}`)}};async function $(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 f.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]=f.useState({from:T(new Date,30),to:new Date}),[a,r]=f.useState(!1),[c,o]=f.useState(null),[i,n]=f.useState(null),[l,x]=f.useState("daily"),m=Je(),u=f.useCallback(async()=>{r(!0);try{await m()}finally{r(!1)}},[m]),p=f.useMemo(()=>({startDate:s?.from,endDate:s?.to}),[s?.from,s?.to]),{data:F,isLoading:y}=Qe(p),{data:b,isLoading:k}=Ve(p),{data:D,isLoading:q}=Ze(p),{data:R,isLoading:O}=Xe(p),{data:z,isLoading:K}=ss({...p,limit:3}),{data:E}=es(),de=f.useCallback(()=>{const P=new Date;t({from:T(P,1),to:P}),x("hourly")},[]),xe=f.useCallback(P=>{t(P),x("daily")},[]),ue=f.useMemo(()=>E?.lastFetch?Q(new Date(E.lastFetch),{addSuffix:!0}):null,[E?.lastFetch]),me=f.useCallback((P,fe)=>{const G=fe.currentTarget.getBoundingClientRect();n({x:G.left+G.width/2,y:G.top+G.height/2}),o(P)},[]),he=f.useCallback(()=>{o(null),n(null)},[]);return{dateRange:s,isRefreshing:a,viewMode:l,selectedModel:c,popoverPosition:i,summary:F,trends:b,hourlyData:D,models:R,sessions:z,status:E,isSummaryLoading:y,isTrendsLoading:k,isHourlyLoading:q,isModelsLoading:O,isSessionsLoading:K,isLoading:y||k||O||K,handleRefresh:u,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}=L(),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:d("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:d("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}=L();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(),o=f.useMemo(()=>!s||s.length===0?[]:(a==="hourly"?s:[...s].reverse()).map(l=>{const x="hour"in l?l.hour:l.date;return{...l,dateFormatted:ls(x,a),costRounded:Number(l.cost.toFixed(4))}}),[s,a]);if(t)return e.jsx(h,{className:d("h-full w-full",r)});if(!s||s.length===0)return e.jsx("div",{className:d("h-full flex items-center justify-center",r),children:e.jsx("p",{className:"text-muted-foreground",children:a==="hourly"?"No usage data for today":"No usage data available"})});const i=({x:n,y:l,payload:x,isRight:m})=>{const u=m?`$${x.value}`:J(Number(x.value));return e.jsx("text",{x:n,y:l,dy:4,textAnchor:m?"start":"end",fontSize:12,fill:"currentColor",className:d("fill-muted-foreground",c&&"blur-[4px]"),children:u})};return e.jsx("div",{className:d("w-full h-full",r),children:e.jsx(oe,{width:"100%",height:"100%",children:e.jsxs(Ue,{data:o,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:n=>e.jsx(i,{...n,isRight:!1}),tickLine:!1,axisLine:{className:"stroke-muted"}}),e.jsx(Z,{yAxisId:"right",orientation:"right",tick:n=>e.jsx(i,{...n,isRight:!0}),tickLine:!1,axisLine:{className:"stroke-muted"}}),e.jsx(ce,{content:({active:n,payload:l,label:x})=>{if(!n||!l||!l.length)return null;const m=l[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:x}),l.map((u,p)=>e.jsxs("p",{className:d("text-sm",c&&w),style:{color:u.color},children:[u.name,":"," ",u.name==="Tokens"?J(Number(u.value)||0):`$${u.value}`]},p)),"requests"in m&&e.jsxs("p",{className:d("text-sm text-muted-foreground mt-1",c&&w),children:["Requests: ",m.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}=L(),o=f.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(h,{className:d("h-full min-h-[100px] w-full",a)});if(!s||s.length===0)return e.jsx("div",{className:d("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:x})=>{if(!l||!x)return null;const m=x;if(!m.length)return null;const u=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:u.name}),e.jsxs("p",{className:d("text-muted-foreground",r&&w),children:[os(u.value)," (",u.percentage.toFixed(1),"%)"]}),e.jsxs("p",{className:d("text-muted-foreground",r&&w),children:["$",u.cost.toFixed(4)]})]})},n=l=>l.percentage>5?`${l.percentage.toFixed(1)}%`:"";return e.jsx("div",{className:d("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,x)=>e.jsx(Ee,{fill:l.fill,strokeWidth:1},`cell-${x}`))}),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}=L(),o=f.useMemo(()=>{if(!s?.sessions||s.sessions.length===0)return null;const i=s.sessions,n=s.total,l=i.reduce((y,b)=>y+(b.inputTokens+b.outputTokens),0),x=Math.round(l/i.length),u=i.reduce((y,b)=>y+b.cost,0)/i.length,p=i[0],F=p?Q(new Date(p.lastActivity),{addSuffix:!0}):"N/A";return{totalSessions:n,avgTokens:x,avgCost:u,lastActive:F,recentSessions:i.slice(0,3)}},[s]);return t?e.jsxs(g,{className:d("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(h,{className:"h-5 w-32"})}),e.jsx(j,{className:"px-3 pb-3 pt-0 flex-1",children:e.jsx(h,{className:"h-full w-full"})})]}):o?e.jsxs(g,{className:d("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(S,{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:d("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:d("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:d("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(S,{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}=L();if(t||r||a?.running&&o)return e.jsxs(g,{className:d("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(S,{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(h,{className:"h-4 w-[100px]"}),e.jsx(h,{className:"h-16 w-full"})]})})]});if(!a?.running)return e.jsxs(g,{className:d("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(S,{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:d("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(S,{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 x=c?.totalRequests??0,m=c?.quotaExceededCount??0,u=x-m,p=x>0?Math.round(u/x*100):100,F=c?.tokens?.total??0,y=Object.entries(c?.requestsByModel??{}).sort((k,D)=>D[1]-k[1]).slice(0,4),b=y.length>0?y[0][1]:1;return e.jsxs(g,{className:d("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(S,{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:`${p*.88} 88`,strokeLinecap:"round",className:p>=90?"text-green-500":"text-amber-500"})]}),e.jsxs("span",{className:"absolute inset-0 flex items-center justify-center text-[8px] font-bold",children:[p,"%"]})]}),e.jsxs("div",{className:"min-w-0",children:[e.jsx("div",{className:"text-lg font-bold leading-none",children:ee(x)}),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(F)}),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,D])=>{const q=Math.round(D/b*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:D})]}),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}=L();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(S,{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(h,{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:d("text-[10px] text-muted-foreground w-14 text-right shrink-0",r&&w),children:hs(o.tokens)}),e.jsxs("span",{className:d("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:d("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:x,onModelClick:m}){const{privacyMode:u}=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(S,{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:u}),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(S,{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:x,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(h,{className:"h-4 w-32"})}),e.jsx(j,{className:"p-4 pt-0 flex-1",children:e.jsx(h,{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(h,{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(h,{className:"w-2.5 h-2.5 rounded-full"}),e.jsx(h,{className:"h-3 w-24"})]}),e.jsx(h,{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(h,{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(h,{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(h,{className:"w-2 h-2 rounded-full"}),e.jsx(h,{className:"h-3 w-20"})]},s))})]})})]})]})]})}function Fs(){const s=f.useRef(null),{dateRange:t,handleDateRangeChange:a,handleTodayClick:r,handleRefresh:c,isRefreshing:o,lastUpdatedText:i,viewMode:n,summary:l,isSummaryLoading:x,trends:m,hourlyData:u,models:p,sessions:F,isTrendsLoading:y,isHourlyLoading:b,isModelsLoading:k,isSessionsLoading:D,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:x}),e.jsx(js,{viewMode:n,trends:m,hourlyData:u,models:p,sessions:F,isTrendsLoading:y,isHourlyLoading:b,isModelsLoading:k,isSessionsLoading:D,isSummaryLoading:x,onModelClick:q}),e.jsxs(se,{open:!!R,onOpenChange:K=>!K&&z(),children:[e.jsx(ve,{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 f,c as pe}from"./react-vendor-CNOkPC89.js";import{u as A,a as L,C as g,b as j,S as h,c as d,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 S,l as ye,m as Ne,n as we,o as ve}from"./index-g2g1k0QS.js";import{a3 as be,al as re,am as Y,an as ne,a1 as le,aa as ke,G as Ce,ao as Se,R as De,$ as V,U as $e,Z as ie,v as Le,ad as H,ap as Fe,Y as Re,C as Te,aq as Me,ar as Pe}from"./icons-KVCk4_U8.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}=L();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(h,{className:"h-4 w-[100px]"}),e.jsx(h,{className:"h-8 w-[80px]"})]}),e.jsx(h,{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:be,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 x=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:d("text-xl font-bold truncate",a&&w),children:n.format(n.value)}),n.subtitle&&e.jsx("p",{className:d("text-[10px] text-muted-foreground truncate",a&&w),children:n.subtitle})]}),e.jsx("div",{className:d("p-2 rounded-lg shrink-0",n.bgColor),children:e.jsx(x,{className:d("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}=L(),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:d("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:d("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:d("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 v(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",v(s.startDate)),s?.endDate&&t.append("until",v(s.endDate)),s?.profile&&t.append("profile",s.profile),$(`/usage/summary?${t}`)},trends:s=>{const t=new URLSearchParams;return s?.startDate&&t.append("since",v(s.startDate)),s?.endDate&&t.append("until",v(s.endDate)),s?.profile&&t.append("profile",s.profile),$(`/usage/daily?${t}`)},hourly:s=>{const t=new URLSearchParams;return s?.startDate&&t.append("since",v(s.startDate)),s?.endDate&&t.append("until",v(s.endDate)),$(`/usage/hourly?${t}`)},models:s=>{const t=new URLSearchParams;return s?.startDate&&t.append("since",v(s.startDate)),s?.endDate&&t.append("until",v(s.endDate)),s?.profile&&t.append("profile",s.profile),$(`/usage/models?${t}`)},sessions:s=>{const t=new URLSearchParams;return s?.startDate&&t.append("since",v(s.startDate)),s?.endDate&&t.append("until",v(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()),$(`/usage/sessions?${t}`)},monthly:(s,t)=>{const a=new URLSearchParams;return s&&a.append("months",s.toString()),t&&a.append("profile",t),$(`/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:()=>$("/usage/status"),insights:s=>{const t=new URLSearchParams;return s?.startDate&&t.append("since",v(s.startDate)),s?.endDate&&t.append("until",v(s.endDate)),s?.profile&&t.append("profile",s.profile),$(`/usage/insights?${t}`)}};async function $(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 f.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]=f.useState({from:T(new Date,30),to:new Date}),[a,r]=f.useState(!1),[c,o]=f.useState(null),[i,n]=f.useState(null),[l,x]=f.useState("daily"),m=Je(),u=f.useCallback(async()=>{r(!0);try{await m()}finally{r(!1)}},[m]),p=f.useMemo(()=>({startDate:s?.from,endDate:s?.to}),[s?.from,s?.to]),{data:F,isLoading:y}=Qe(p),{data:b,isLoading:k}=Ve(p),{data:D,isLoading:q}=Ze(p),{data:R,isLoading:O}=Xe(p),{data:z,isLoading:K}=ss({...p,limit:3}),{data:E}=es(),de=f.useCallback(()=>{const P=new Date;t({from:T(P,1),to:P}),x("hourly")},[]),xe=f.useCallback(P=>{t(P),x("daily")},[]),ue=f.useMemo(()=>E?.lastFetch?Q(new Date(E.lastFetch),{addSuffix:!0}):null,[E?.lastFetch]),me=f.useCallback((P,fe)=>{const G=fe.currentTarget.getBoundingClientRect();n({x:G.left+G.width/2,y:G.top+G.height/2}),o(P)},[]),he=f.useCallback(()=>{o(null),n(null)},[]);return{dateRange:s,isRefreshing:a,viewMode:l,selectedModel:c,popoverPosition:i,summary:F,trends:b,hourlyData:D,models:R,sessions:z,status:E,isSummaryLoading:y,isTrendsLoading:k,isHourlyLoading:q,isModelsLoading:O,isSessionsLoading:K,isLoading:y||k||O||K,handleRefresh:u,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}=L(),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:d("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:d("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}=L();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(),o=f.useMemo(()=>!s||s.length===0?[]:(a==="hourly"?s:[...s].reverse()).map(l=>{const x="hour"in l?l.hour:l.date;return{...l,dateFormatted:ls(x,a),costRounded:Number(l.cost.toFixed(4))}}),[s,a]);if(t)return e.jsx(h,{className:d("h-full w-full",r)});if(!s||s.length===0)return e.jsx("div",{className:d("h-full flex items-center justify-center",r),children:e.jsx("p",{className:"text-muted-foreground",children:a==="hourly"?"No usage data for today":"No usage data available"})});const i=({x:n,y:l,payload:x,isRight:m})=>{const u=m?`$${x.value}`:J(Number(x.value));return e.jsx("text",{x:n,y:l,dy:4,textAnchor:m?"start":"end",fontSize:12,fill:"currentColor",className:d("fill-muted-foreground",c&&"blur-[4px]"),children:u})};return e.jsx("div",{className:d("w-full h-full",r),children:e.jsx(oe,{width:"100%",height:"100%",children:e.jsxs(Ue,{data:o,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:n=>e.jsx(i,{...n,isRight:!1}),tickLine:!1,axisLine:{className:"stroke-muted"}}),e.jsx(Z,{yAxisId:"right",orientation:"right",tick:n=>e.jsx(i,{...n,isRight:!0}),tickLine:!1,axisLine:{className:"stroke-muted"}}),e.jsx(ce,{content:({active:n,payload:l,label:x})=>{if(!n||!l||!l.length)return null;const m=l[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:x}),l.map((u,p)=>e.jsxs("p",{className:d("text-sm",c&&w),style:{color:u.color},children:[u.name,":"," ",u.name==="Tokens"?J(Number(u.value)||0):`$${u.value}`]},p)),"requests"in m&&e.jsxs("p",{className:d("text-sm text-muted-foreground mt-1",c&&w),children:["Requests: ",m.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}=L(),o=f.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(h,{className:d("h-full min-h-[100px] w-full",a)});if(!s||s.length===0)return e.jsx("div",{className:d("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:x})=>{if(!l||!x)return null;const m=x;if(!m.length)return null;const u=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:u.name}),e.jsxs("p",{className:d("text-muted-foreground",r&&w),children:[os(u.value)," (",u.percentage.toFixed(1),"%)"]}),e.jsxs("p",{className:d("text-muted-foreground",r&&w),children:["$",u.cost.toFixed(4)]})]})},n=l=>l.percentage>5?`${l.percentage.toFixed(1)}%`:"";return e.jsx("div",{className:d("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,x)=>e.jsx(Ee,{fill:l.fill,strokeWidth:1},`cell-${x}`))}),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}=L(),o=f.useMemo(()=>{if(!s?.sessions||s.sessions.length===0)return null;const i=s.sessions,n=s.total,l=i.reduce((y,b)=>y+(b.inputTokens+b.outputTokens),0),x=Math.round(l/i.length),u=i.reduce((y,b)=>y+b.cost,0)/i.length,p=i[0],F=p?Q(new Date(p.lastActivity),{addSuffix:!0}):"N/A";return{totalSessions:n,avgTokens:x,avgCost:u,lastActive:F,recentSessions:i.slice(0,3)}},[s]);return t?e.jsxs(g,{className:d("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(h,{className:"h-5 w-32"})}),e.jsx(j,{className:"px-3 pb-3 pt-0 flex-1",children:e.jsx(h,{className:"h-full w-full"})})]}):o?e.jsxs(g,{className:d("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(S,{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:d("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:d("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:d("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(S,{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}=L();if(t||r||a?.running&&o)return e.jsxs(g,{className:d("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(S,{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(h,{className:"h-4 w-[100px]"}),e.jsx(h,{className:"h-16 w-full"})]})})]});if(!a?.running)return e.jsxs(g,{className:d("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(S,{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:d("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(S,{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 x=c?.totalRequests??0,m=c?.quotaExceededCount??0,u=x-m,p=x>0?Math.round(u/x*100):100,F=c?.tokens?.total??0,y=Object.entries(c?.requestsByModel??{}).sort((k,D)=>D[1]-k[1]).slice(0,4),b=y.length>0?y[0][1]:1;return e.jsxs(g,{className:d("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(S,{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:`${p*.88} 88`,strokeLinecap:"round",className:p>=90?"text-green-500":"text-amber-500"})]}),e.jsxs("span",{className:"absolute inset-0 flex items-center justify-center text-[8px] font-bold",children:[p,"%"]})]}),e.jsxs("div",{className:"min-w-0",children:[e.jsx("div",{className:"text-lg font-bold leading-none",children:ee(x)}),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(F)}),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,D])=>{const q=Math.round(D/b*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:D})]}),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}=L();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(S,{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(h,{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:d("text-[10px] text-muted-foreground w-14 text-right shrink-0",r&&w),children:hs(o.tokens)}),e.jsxs("span",{className:d("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:d("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:x,onModelClick:m}){const{privacyMode:u}=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(S,{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:u}),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(S,{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:x,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(h,{className:"h-4 w-32"})}),e.jsx(j,{className:"p-4 pt-0 flex-1",children:e.jsx(h,{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(h,{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(h,{className:"w-2.5 h-2.5 rounded-full"}),e.jsx(h,{className:"h-3 w-24"})]}),e.jsx(h,{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(h,{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(h,{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(h,{className:"w-2 h-2 rounded-full"}),e.jsx(h,{className:"h-3 w-20"})]},s))})]})})]})]})]})}function Fs(){const s=f.useRef(null),{dateRange:t,handleDateRangeChange:a,handleTodayClick:r,handleRefresh:c,isRefreshing:o,lastUpdatedText:i,viewMode:n,summary:l,isSummaryLoading:x,trends:m,hourlyData:u,models:p,sessions:F,isTrendsLoading:y,isHourlyLoading:b,isModelsLoading:k,isSessionsLoading:D,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:x}),e.jsx(js,{viewMode:n,trends:m,hourlyData:u,models:p,sessions:F,isTrendsLoading:y,isHourlyLoading:b,isModelsLoading:k,isSessionsLoading:D,isSummaryLoading:x,onModelClick:q}),e.jsxs(se,{open:!!R,onOpenChange:K=>!K&&z(),children:[e.jsx(ve,{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};
@@ -0,0 +1 @@
1
+ import{j as e}from"./radix-ui-Zb8sVEtn.js";import{r as o}from"./react-vendor-CNOkPC89.js";import{a as Ne,br as ke,Y as re,be as se,bg as ne,d as C,n as we,B as m,c as g,aF as Se,I as q,r as ie,s as le,t as de,v as oe,w as z,W as l}from"./index-g2g1k0QS.js";import{R as G,w as ce,x as Ae,a8 as me,aB as Ce,A as Me,aa as Pe,as as Be,t as Re,s as _e,a9 as Ve,aK as Te}from"./icons-KVCk4_U8.js";import"./tanstack-CrmUhA7Z.js";import"./notifications-B2HqRBj7.js";import"./utils-CzKF5WmX.js";import"./form-utils-Bcoyqxpq.js";import"./code-highlight-BRUf_pqB.js";const M="__no_backend__";function ue(t){return!!t&&typeof t=="object"&&!Array.isArray(t)&&Object.values(t).every(r=>typeof r=="string")}function De(t){if(!t||typeof t!="object"||Array.isArray(t))return!1;const r=t;return!!r.config&&typeof r.config.enabled=="boolean"&&typeof r.config.timeout=="number"&&ue(r.config.providerModels)&&(r.config.fallbackBackend===null||typeof r.config.fallbackBackend=="string")&&ue(r.config.profileBackends)&&!!r.summary&&typeof r.summary.state=="string"&&typeof r.summary.title=="string"&&typeof r.summary.detail=="string"&&Array.isArray(r.backends)&&Array.isArray(r.profiles)&&!!r.catalog&&Array.isArray(r.catalog.knownBackends)&&Array.isArray(r.catalog.profileNames)&&typeof r.summary.nativeProfileCount=="number"}function Ie(t){return Object.entries(t).sort(([r],[s])=>r.localeCompare(s)).map(([r,s],x)=>({id:`${r}-${s}-${x}`,profileName:r,backendId:s}))}function Ee(t){switch(t){case"ready":return"border-emerald-500/25 bg-emerald-500/10 text-emerald-900 dark:text-emerald-200";case"partial":return"border-amber-500/25 bg-amber-500/10 text-amber-900 dark:text-amber-200";case"needs_setup":return"border-rose-500/25 bg-rose-500/10 text-rose-900 dark:text-rose-200";case"disabled":return"border-border/80 bg-background/85 text-muted-foreground"}}function $e(t){switch(t){case"ready":return"border-emerald-500/25 bg-emerald-500/10 text-emerald-800 dark:text-emerald-200";case"starts_on_launch":return"border-sky-500/25 bg-sky-500/10 text-sky-800 dark:text-sky-200";case"needs_auth":return"border-rose-500/25 bg-rose-500/10 text-rose-800 dark:text-rose-200";case"needs_proxy":return"border-amber-500/25 bg-amber-500/10 text-amber-800 dark:text-amber-200";case"review":return"border-border/80 bg-background/85 text-muted-foreground"}}function ge(t){switch(t){case"active":return l.t("imageAnalysisStatus.badgeReady");case"bypassed":return l.t("imageAnalysisStatus.badgeBypassed");case"fallback":return l.t("imageAnalysisStatus.nativeFallback");case"setup":return l.t("imageAnalysisStatus.badgeSetup");case"disabled":return l.t("imageAnalysisStatus.badgeDisabled");case"native":return l.t("imageAnalysisStatus.badgeNative");case"unresolved":return l.t("imageAnalysisStatus.nativeImageReading")}}function xe(t){switch(t){case"active":return"border-emerald-500/25 bg-emerald-500/10 text-emerald-800 dark:text-emerald-200";case"bypassed":return"border-sky-500/25 bg-sky-500/10 text-sky-800 dark:text-sky-200";case"fallback":case"setup":return"border-amber-500/25 bg-amber-500/10 text-amber-800 dark:text-amber-200";case"native":return"border-emerald-500/25 bg-emerald-500/10 text-emerald-800 dark:text-emerald-200";case"disabled":case"unresolved":return"border-border/80 bg-background/85 text-muted-foreground"}}function Fe(t){switch(t){case"starts_on_launch":return l.t("imageAnalysisSection.backendStartsOnLaunch",{defaultValue:"Starts on launch"});case"needs_auth":return l.t("imageAnalysisStatus.needsAuth");case"needs_proxy":return l.t("imageAnalysisStatus.needsProxy");case"review":return l.t("imageAnalysisSection.review",{defaultValue:"Review"});case"ready":return l.t("imageAnalysisStatus.badgeReady")}}function Oe(t){if(!t)return l.t("imageAnalysisSection.noModelConfigured",{defaultValue:"No model configured."});switch(t.state){case"needs_auth":return t.authReason||l.t("imageAnalysisSection.authenticateToRoute",{defaultValue:"Authenticate to route here."});case"needs_proxy":return t.proxyReason||l.t("imageAnalysisSection.proxyUnavailable",{defaultValue:"Proxy unavailable."});case"starts_on_launch":return l.t("imageAnalysisSection.authReadyLaunchesLocally",{defaultValue:"Auth ready. Launches locally on demand."});case"review":return l.t("imageAnalysisSection.needsManualReview",{defaultValue:"Needs manual review."});case"ready":return null}}function ze(t){switch(t){case"profile-backend":return l.t("imageAnalysisSection.explicitMapping",{defaultValue:"Explicit mapping"});case"fallback-backend":return l.t("imageAnalysisSection.fallbackBackend",{defaultValue:"Fallback backend"});case"cliproxy-provider":return l.t("imageAnalysisSection.providerMatch",{defaultValue:"Provider match"});case"cliproxy-bridge":return l.t("imageAnalysisSection.bridgeMatch",{defaultValue:"Bridge match"});case"native-compatible":return l.t("imageAnalysisSection.nativePath",{defaultValue:"Native path"});case"copilot-alias":return l.t("imageAnalysisSection.copilotAlias",{defaultValue:"Copilot alias"});default:return t.replace(/-/g," ")}}function k(t){return"border-border/50 bg-background/40"}function Le(t){switch(t){case"ready":return"bg-[linear-gradient(90deg,rgba(16,185,129,0.08),transparent_18%),linear-gradient(180deg,rgba(255,255,255,0.72),rgba(255,255,255,0.46))] dark:bg-[linear-gradient(90deg,rgba(16,185,129,0.12),transparent_18%),linear-gradient(180deg,rgba(15,23,42,0.82),rgba(15,23,42,0.56))]";case"starts_on_launch":return"bg-[linear-gradient(90deg,rgba(14,165,233,0.08),transparent_18%),linear-gradient(180deg,rgba(255,255,255,0.72),rgba(255,255,255,0.46))] dark:bg-[linear-gradient(90deg,rgba(14,165,233,0.12),transparent_18%),linear-gradient(180deg,rgba(15,23,42,0.82),rgba(15,23,42,0.56))]";case"needs_auth":return"bg-[linear-gradient(90deg,rgba(244,63,94,0.08),transparent_18%),linear-gradient(180deg,rgba(255,255,255,0.72),rgba(255,255,255,0.46))] dark:bg-[linear-gradient(90deg,rgba(244,63,94,0.12),transparent_18%),linear-gradient(180deg,rgba(15,23,42,0.82),rgba(15,23,42,0.56))]";case"needs_proxy":return"bg-[linear-gradient(90deg,rgba(245,158,11,0.08),transparent_18%),linear-gradient(180deg,rgba(255,255,255,0.72),rgba(255,255,255,0.46))] dark:bg-[linear-gradient(90deg,rgba(245,158,11,0.12),transparent_18%),linear-gradient(180deg,rgba(15,23,42,0.82),rgba(15,23,42,0.56))]";case"review":default:return"bg-[linear-gradient(180deg,rgba(255,255,255,0.74),rgba(255,255,255,0.5))] dark:bg-[linear-gradient(180deg,rgba(15,23,42,0.8),rgba(15,23,42,0.58))]"}}function Ke(t){switch(t){case"ready":return"from-emerald-500 to-emerald-400/30";case"starts_on_launch":return"from-sky-500 to-sky-400/30";case"needs_auth":return"from-rose-500 to-rose-400/30";case"needs_proxy":return"from-amber-500 to-amber-400/30";case"review":default:return"from-slate-400 to-slate-300/20"}}function Ue(t,r){return r.nativeReadPreference?t%2===0?"bg-emerald-500/[0.06]":"bg-emerald-500/[0.08]":t%2===0?"bg-background/75":"bg-muted/18"}function He(t){const r=[`${t.activeProfileCount} routed`,`${t.nativeProfileCount} native`];return t.mappedProfileCount>0&&r.push(`${t.mappedProfileCount} override${t.mappedProfileCount===1?"":"s"}`),r.join(" · ")}function Je(t){return Object.entries(t).reduce((r,[s,x])=>{const h=x.trim();return r[s]=h||null,r},{})}function W(t){return Object.entries(t).filter(([,r])=>r.trim().length>0).map(([r])=>r)}function qe(t){return t.reduce((r,s)=>{const x=s.profileName.trim();return!x||!s.backendId||(r[x]=s.backendId),r},{})}function pe(t,r){const s=Number.parseInt(t.trim(),10);return Number.isInteger(s)?String(Math.min(600,Math.max(10,s))):r}function T({title:t,description:r,icon:s,meta:x,action:h,children:D,className:c}){return e.jsxs("div",{className:g("relative overflow-hidden rounded-2xl border bg-gradient-to-br from-background via-background to-muted/25 p-4 shadow-sm",c),children:[e.jsx("div",{className:"absolute inset-x-0 top-0 h-px bg-gradient-to-r from-primary/40 via-primary/10 to-transparent"}),e.jsxs("div",{className:"relative space-y-4",children:[e.jsxs("div",{className:"flex flex-col gap-3 md:flex-row md:items-start md:justify-between",children:[e.jsxs("div",{className:"flex items-start gap-3",children:[e.jsx("div",{className:"inline-flex h-9 w-9 shrink-0 items-center justify-center rounded-xl border border-primary/20 bg-primary/10 text-primary",children:s}),e.jsxs("div",{children:[e.jsxs("div",{className:"flex flex-wrap items-center gap-2",children:[e.jsx("h3",{className:"text-base font-semibold tracking-tight",children:t}),x]}),e.jsx("p",{className:"mt-0.5 text-sm leading-5 text-muted-foreground",children:r})]})]}),h&&e.jsx("div",{className:"shrink-0",children:h})]}),e.jsx("div",{className:"space-y-3",children:D})]})]})}function ra(){const{t}=Ne(),{fetchRawConfig:r}=ke(),[s,x]=o.useState(null),[h,D]=o.useState(!0),[c,Y]=o.useState(!1),[I,N]=o.useState(null),[P,L]=o.useState(null),[E,Q]=o.useState(!1),[B,X]=o.useState(!0),[K,U]=o.useState("60"),[v,R]=o.useState(""),[w,$]=o.useState({}),[p,F]=o.useState([]),S=o.useCallback(a=>{X(a.config.enabled),U(String(a.config.timeout)),R(a.config.fallbackBackend??""),$(a.catalog.knownBackends.reduce((n,i)=>(n[i]=a.config.providerModels[i]??"",n),{})),F(Ie(a.config.profileBackends))},[]),H=o.useCallback(async()=>{try{D(!0),N(null);const a=await re.imageAnalysis.get();if(!De(a))throw new Error("Image settings returned an unexpected response. Restart the dashboard server so the new API route is available.");x(a),S(a)}catch(a){N(a instanceof Error?a.message:"Failed to load image settings.")}finally{D(!1)}},[S]);o.useEffect(()=>{H(),r()},[H,r]),o.useEffect(()=>{if(!P)return;const a=window.setTimeout(()=>L(null),2500);return()=>window.clearTimeout(a)},[P]),o.useEffect(()=>{s&&Object.keys(s.config.profileBackends).length>0&&Q(!0)},[s]);const u=o.useMemo(()=>W(w),[w]),Z=o.useMemo(()=>{if(!s)return[];const a=s.catalog.knownBackends.filter(i=>u.includes(i)),n=s.catalog.knownBackends.filter(i=>!u.includes(i));return[...a,...n]},[u,s]),O=o.useMemo(()=>s?.profiles.filter(a=>a.nativeReadPreference)??[],[s]);o.useEffect(()=>{if(u.length===0){R("");return}u.includes(v)||R(u[0])},[u,v]);const _=o.useCallback(async a=>{if(!s)return!1;const n=a?.enabled??B,i=a?.providerModels??w,d=W(i),b=pe(a?.timeout??K,String(s.config.timeout)),y=a?.fallbackBackend??v,A=d.length===0?"":d.includes(y)?y:d[0],f=a?.mappingDrafts??p,V={enabled:n,timeout:b,fallbackBackend:A,providerModels:Je(i),profileBackends:qe(f)},je={enabled:s.config.enabled,timeout:String(s.config.timeout),fallbackBackend:s.config.fallbackBackend??"",providerModels:s.catalog.knownBackends.reduce((j,te)=>(j[te]=s.config.providerModels[te]??null,j),{}),profileBackends:s.config.profileBackends};if(JSON.stringify(V)===JSON.stringify(je))return!0;if(n&&d.length===0)return N("Keep at least one provider model configured, or disable Image globally."),S(s),!1;try{Y(!0),N(null);const j=await re.imageAnalysis.update({enabled:n,timeout:Number.parseInt(b,10),fallbackBackend:A||null,providerModels:V.providerModels,profileBackends:V.profileBackends});return x(j),S(j),L(t("commonToast.settingsSaved")),await r(),!0}catch(j){return N(j instanceof Error?j.message:"Failed to save image settings."),S(s),!1}finally{Y(!1)}},[s,B,v,r,S,p,w,t,K]),ee=async()=>{h||c||(L(null),await Promise.all([H(),r()]))},be=async a=>{if(!c){if(a&&u.length===0){N("Keep at least one provider model configured, or disable Image globally.");return}X(a),await _({enabled:a})}},fe=async a=>{if(!s||c)return;const n=pe(a,String(s.config.timeout));U(n),await _({timeout:n})},he=async a=>{c||(R(a),await _({fallbackBackend:a}))},ae=async(a,n)=>{if(!s||c)return;const i=n.trim(),d={...w,[a]:i},b=W(d);if(B&&b.length===0){N("Disable Image first or keep one backend configured."),$(A=>({...A,[a]:s.config.providerModels[a]??""}));return}const y=b.length===0?"":b.includes(v)?v:b[0];$(d),R(y),await _({providerModels:d,fallbackBackend:y})},ve=(a,n)=>{F(i=>i.map(d=>d.id===a?{...d,...n}:d))},J=async a=>{c||(F(a),await _({mappingDrafts:a}))},ye=p.filter(a=>a.profileName.trim()&&a.backendId).length;return h?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(G,{className:"w-5 h-5 animate-spin"}),e.jsx("span",{children:t("settingsPage.imageAnalysisSection.loading")})]})}):s?e.jsxs("div",{className:"relative flex min-h-0 flex-1 flex-col",children:[e.jsxs("div",{className:`absolute left-5 right-5 top-20 z-10 transition-all duration-200 ease-out ${I||P?"translate-y-0 opacity-100":"pointer-events-none -translate-y-2 opacity-0"}`,children:[I&&e.jsxs(se,{variant:"destructive",className:"py-2 shadow-lg",children:[e.jsx(ce,{className:"h-4 w-4"}),e.jsx(ne,{children:I})]}),P&&e.jsxs("div",{className:"flex items-center gap-2 rounded-md border border-green-200 bg-green-50 px-3 py-2 text-green-700 shadow-lg dark:border-green-900/50 dark:bg-green-900/90 dark:text-green-300",children:[e.jsx(Ae,{className:"h-4 w-4 shrink-0"}),e.jsx("span",{className:"text-sm font-medium",children:P})]})]}),e.jsx(we,{className:"min-h-0 flex-1",children:e.jsxs("div",{className:"space-y-6 p-5",children:[e.jsxs("div",{className:"relative overflow-hidden rounded-2xl border bg-gradient-to-br from-background via-background to-muted/30 p-4 shadow-sm",children:[e.jsx("div",{className:"absolute inset-x-0 top-0 h-px bg-gradient-to-r from-primary/70 via-primary/20 to-transparent"}),e.jsx("div",{className:"pointer-events-none absolute inset-0 opacity-[0.035]",style:{backgroundImage:"repeating-linear-gradient(0deg, transparent, transparent 2px, currentColor 2px, currentColor 3px)"}}),e.jsxs("div",{className:"relative",children:[e.jsxs("div",{className:"mb-3 flex items-center justify-between gap-4",children:[e.jsxs("div",{className:"space-y-1",children:[e.jsxs("div",{className:"flex items-center gap-2",children:[e.jsx("div",{className:"inline-flex h-8 w-8 items-center justify-center rounded-xl border border-primary/20 bg-primary/8 text-primary",children:e.jsx(me,{className:"h-4 w-4"})}),e.jsx("p",{className:"text-sm font-semibold tracking-tight",children:t("settingsPage.imageAnalysisSection.title")})]}),e.jsxs("div",{className:"mt-1 flex flex-wrap items-center gap-2 text-sm text-muted-foreground",children:[e.jsx(m,{className:g("border",Ee(s.summary.state)),children:s.summary.title}),e.jsx("span",{children:He(s.summary)})]})]}),e.jsx(C,{variant:"ghost",size:"sm",onClick:ee,disabled:h||c,"aria-label":"Refresh",title:"Refresh",children:e.jsx(G,{className:`h-4 w-4 ${h?"animate-spin":""}`})})]}),e.jsxs("div",{className:"mt-3 grid gap-2 sm:grid-cols-2",children:[e.jsxs("div",{className:"rounded-[18px] border bg-background/72 px-3 py-2.5 backdrop-blur-sm",children:[e.jsx("div",{className:"text-[10px] font-medium uppercase tracking-[0.14em] text-muted-foreground",children:"Active routes"}),e.jsx("div",{className:"mt-1.5 text-xl font-semibold text-foreground",children:s.summary.activeProfileCount}),e.jsx("p",{className:"mt-0.5 text-[11px] text-muted-foreground",children:"Current target path"})]}),e.jsxs("div",{className:"rounded-[18px] border bg-background/72 px-3 py-2.5 backdrop-blur-sm",children:[e.jsx("div",{className:"text-[10px] font-medium uppercase tracking-[0.14em] text-muted-foreground",children:"Native path"}),e.jsx("div",{className:"mt-1.5 text-xl font-semibold text-foreground",children:s.summary.nativeProfileCount}),e.jsx("p",{className:"mt-0.5 text-[11px] text-muted-foreground",children:"Skip transformer"})]})]})]})]}),e.jsxs(T,{tone:"amber",eyebrow:"Control deck",title:"Core setup",description:t("settingsPage.imageAnalysisSection.description"),icon:e.jsx(Ce,{className:"h-4 w-4"}),meta:e.jsxs(m,{variant:"outline",className:"border-amber-500/25 bg-amber-500/10 text-[10px]",children:[u.length," configured"]}),children:[e.jsxs("div",{className:"grid gap-2 lg:grid-cols-3",children:[e.jsxs("div",{className:g("rounded-[18px] border px-3.5 py-3 shadow-sm",k()),children:[e.jsx("div",{className:"text-[10px] font-semibold uppercase tracking-[0.14em] text-amber-700/75 dark:text-amber-300/75",children:"Enabled"}),e.jsxs("div",{className:"mt-2.5 flex items-center justify-between gap-3",children:[e.jsxs("div",{className:"space-y-0.5",children:[e.jsx("div",{className:"text-sm font-semibold text-foreground",children:B?"Transformer on":"Transformer off"}),e.jsx("p",{className:"text-[11px] leading-4 text-muted-foreground",children:"Profile flags stay untouched."})]}),e.jsx(Se,{checked:B,onCheckedChange:a=>{be(a)},disabled:c})]})]}),e.jsxs("div",{className:g("rounded-[18px] border px-3.5 py-3 shadow-sm",k()),children:[e.jsx("div",{className:"text-[10px] font-semibold uppercase tracking-[0.14em] text-amber-700/75 dark:text-amber-300/75",children:"Timeout"}),e.jsxs("div",{className:"mt-2.5 flex items-center gap-2",children:[e.jsx(q,{value:K,onChange:a=>U(a.target.value),inputMode:"numeric",className:"h-10 border-amber-500/15 bg-background/90 text-base",disabled:c,onBlur:a=>{fe(a.currentTarget.value)},onKeyDown:a=>{a.key==="Enter"&&a.currentTarget.blur()}}),e.jsx("span",{className:"text-xs font-medium text-muted-foreground",children:"sec"})]}),e.jsx("p",{className:"mt-1.5 text-[11px] leading-4 text-muted-foreground",children:"Keeps large reads from hanging."})]}),e.jsxs("div",{className:g("rounded-[18px] border px-3.5 py-3 shadow-sm",k()),children:[e.jsx("div",{className:"text-[10px] font-semibold uppercase tracking-[0.14em] text-amber-700/75 dark:text-amber-300/75",children:"Fallback backend"}),e.jsx("div",{className:"mt-2.5",children:e.jsxs(ie,{value:v||M,onValueChange:a=>{he(a===M?"":a)},disabled:c,children:[e.jsx(le,{className:"h-10 border-amber-500/15 bg-background/90",children:e.jsx(de,{placeholder:t("settingsPage.thinkingSection.configureModelFirst")})}),e.jsx(oe,{children:u.length===0?e.jsx(z,{value:M,children:t("settingsPage.thinkingSection.configureModelFirst")}):u.map(a=>e.jsx(z,{value:a,children:a},a))})]})}),e.jsx("p",{className:"mt-1.5 text-[11px] leading-4 text-muted-foreground",children:"Used when no direct route exists."})]})]}),e.jsxs("div",{className:"mt-3 flex flex-wrap gap-1.5",children:[e.jsxs("div",{className:"rounded-full border border-amber-500/15 bg-background/80 px-2.5 py-1 text-[11px] text-muted-foreground",children:[ye," overrides"]}),e.jsxs("div",{className:"rounded-full border border-amber-500/15 bg-background/80 px-2.5 py-1 text-[11px] text-muted-foreground",children:[O.length," native"]}),e.jsxs("div",{className:"rounded-full border border-amber-500/15 bg-background/80 px-2.5 py-1 text-[11px] text-muted-foreground",children:[v||"No fallback"," fallback"]})]})]}),e.jsx(T,{tone:"cyan",eyebrow:"Route inventory",title:"Backend routes",description:"Model entry plus route health.",icon:e.jsx(Me,{className:"h-4 w-4"}),meta:e.jsxs(m,{variant:"outline",className:"border-cyan-500/25 bg-cyan-500/10 text-[10px]",children:[Z.length," backends"]}),children:e.jsx("div",{className:"overflow-hidden rounded-[20px] border border-cyan-500/12 bg-background/65 shadow-sm backdrop-blur-sm",children:Z.map((a,n)=>{const i=s.backends.find(f=>f.backendId===a),d=i?.displayName||a,b=w[a]??"",y=Oe(i),A=b?[`${i?.profilesUsing??0} active`,i?.authReadiness==="missing"?"auth missing":i?.proxyReadiness==="stopped"?"starts on launch":null].filter(Boolean).join(" · "):"No model configured.";return e.jsxs("div",{className:g("relative px-3 py-3 md:px-4",n>0&&"border-t border-cyan-500/10",Le(i?.state)),children:[e.jsx("div",{className:g("absolute bottom-3 left-0 top-3 w-1 rounded-r-full bg-gradient-to-b",Ke(i?.state))}),e.jsxs("div",{className:"pl-2.5",children:[e.jsxs("div",{className:"flex items-start justify-between gap-3",children:[e.jsxs("div",{className:"min-w-0",children:[e.jsxs("div",{className:"flex flex-wrap items-center gap-2",children:[e.jsx("h4",{className:"text-sm font-semibold text-foreground",children:d}),e.jsx(m,{variant:"outline",className:"font-mono text-[10px]",children:a}),i?.profilesUsing?e.jsxs(m,{variant:"outline",className:"border-cyan-500/20 bg-cyan-500/10 text-[10px]",children:[i.profilesUsing," active"]}):null]}),e.jsx("p",{className:"mt-0.5 text-[11px] leading-4 text-muted-foreground",children:A})]}),e.jsx(m,{className:g("border",i?$e(i.state):"border-border/80 bg-background/85 text-muted-foreground"),children:i?Fe(i.state):"Inactive"})]}),e.jsxs("div",{className:"mt-2 flex flex-col gap-2 sm:flex-row",children:[e.jsx(q,{className:"h-10 flex-1 border-cyan-500/15 bg-background/88 text-base",placeholder:t("imageAnalysisSection.setModel",{defaultValue:"Set model"}),value:b,disabled:c,onChange:f=>$(V=>({...V,[a]:f.target.value})),onBlur:f=>{ae(a,f.currentTarget.value)},onKeyDown:f=>{f.key==="Enter"&&f.currentTarget.blur()}}),b.trim().length>0&&e.jsx(C,{type:"button",variant:"outline",size:"sm",className:"h-10 sm:self-stretch",disabled:c,onClick:()=>{ae(a,"")},children:t("common.clear",{defaultValue:"Clear"})})]}),y&&e.jsx("p",{className:"mt-1.5 text-[11px] leading-4 text-muted-foreground",children:y})]})]},a)})})}),e.jsx(T,{tone:"emerald",eyebrow:"Native path",title:"Native reading",description:"Profiles that skip the transformer.",icon:e.jsx(Pe,{className:"h-4 w-4"}),meta:e.jsxs(m,{variant:"outline",children:[O.length," profiles"]}),children:O.length===0?e.jsx("div",{className:g("rounded-[18px] border border-dashed px-3.5 py-3.5 text-sm text-muted-foreground",k()),children:t("imageAnalysisSection.noProfilesPreferNative",{defaultValue:"No profiles prefer native reading yet."})}):e.jsx("div",{className:"grid gap-2 md:grid-cols-2",children:O.map(a=>e.jsx("div",{className:g("rounded-[18px] border px-3.5 py-3 shadow-sm",k()),children:e.jsxs("div",{className:"flex items-start justify-between gap-3",children:[e.jsxs("div",{className:"min-w-0",children:[e.jsxs("div",{className:"flex flex-wrap items-center gap-2",children:[e.jsx("div",{className:"truncate text-sm font-semibold text-foreground",children:a.name}),e.jsx(m,{variant:"outline",className:"text-[10px]",children:a.kind==="variant"?t("cliproxyPage.variant"):t("apiProfiles.title")}),e.jsx(m,{variant:"outline",className:"text-[10px]",children:a.nativeImageCapable?t("imageAnalysisStatus.capabilityVerified"):t("imageAnalysisSection.review",{defaultValue:"Review"})})]}),e.jsxs("div",{className:"mt-1 text-[11px] leading-4 text-muted-foreground",children:[a.profileModel||t("imageAnalysisSection.modelNotDetected",{defaultValue:"Model not detected"})," ","·"," ",a.nativeImageReason||t("imageAnalysisSection.nativeReadPreferred",{defaultValue:"Native read preferred."})]})]}),e.jsx(m,{className:g("border",xe(a.currentTargetMode)),children:ge(a.currentTargetMode)})]})},`native-${a.kind}-${a.name}`))})}),e.jsxs(T,{tone:"slate",eyebrow:"Override lab",title:"Profile routing",description:"Only for explicit route overrides.",icon:e.jsx(Te,{className:"h-4 w-4"}),meta:e.jsx(m,{variant:"outline",className:"border-amber-500/25 bg-amber-500/10 text-[10px] text-amber-800 dark:text-amber-200",children:"Advanced"}),action:e.jsxs("div",{className:"flex items-center gap-2",children:[e.jsxs(C,{type:"button",variant:"outline",size:"sm",onClick:()=>Q(a=>!a),children:[E?e.jsx(Re,{className:"mr-1 h-4 w-4"}):e.jsx(_e,{className:"mr-1 h-4 w-4"}),E?t("common.hide",{defaultValue:"Hide"}):t("common.show",{defaultValue:"Show"})]}),E&&e.jsxs(C,{type:"button",variant:"outline",size:"sm",onClick:()=>F(a=>[...a,{id:`mapping-${Date.now()}`,profileName:"",backendId:u[0]??""}]),disabled:u.length===0||c,children:[e.jsx(Ve,{className:"mr-1 h-4 w-4"}),t("imageAnalysisSection.addMapping",{defaultValue:"Add mapping"})]})]}),className:"border-dashed",children:[e.jsx("datalist",{id:"image-profile-suggestions",children:s.catalog.profileNames.map(a=>e.jsx("option",{value:a},a))}),E?e.jsx("div",{className:"space-y-2",children:p.length===0?e.jsx("div",{className:g("rounded-[18px] border border-dashed px-3.5 py-3.5 text-sm text-muted-foreground",k()),children:"No explicit overrides saved."}):e.jsx("div",{className:"space-y-2",children:p.map(a=>e.jsxs("div",{className:"rounded-[18px] border border-slate-400/20 bg-[linear-gradient(180deg,rgba(255,255,255,0.72),rgba(248,250,252,0.52))] p-3 shadow-sm dark:bg-[linear-gradient(180deg,rgba(15,23,42,0.84),rgba(15,23,42,0.56))]",children:[e.jsxs("div",{className:"flex items-center justify-between gap-3",children:[e.jsxs("div",{className:"flex items-center gap-2 text-[11px] leading-4 text-muted-foreground",children:[e.jsx("span",{children:t("imageAnalysisSection.directOverride",{defaultValue:"Direct override"})}),!(a.profileName.trim()&&a.backendId)&&e.jsx(m,{variant:"outline",className:"text-[10px]",children:"Draft"})]}),e.jsxs(C,{type:"button",variant:"ghost",size:"sm",disabled:c,onClick:()=>{const n=p.filter(i=>i.id!==a.id);J(n)},children:[e.jsx(Be,{className:"mr-1 h-4 w-4"}),t("common.remove",{defaultValue:"Remove"})]})]}),e.jsxs("div",{className:"mt-2 grid gap-2 sm:grid-cols-2",children:[e.jsx(q,{value:a.profileName,list:"image-profile-suggestions",disabled:c,placeholder:t("imageAnalysisSection.profileOrVariantName",{defaultValue:"Profile or variant name"}),className:"h-10 border-slate-400/15 bg-background/88 text-base",onChange:n=>{ve(a.id,{profileName:n.target.value})},onBlur:n=>{const i=p.map(d=>d.id===a.id?{...d,profileName:n.currentTarget.value.trim()}:d);J(i)},onKeyDown:n=>{n.key==="Enter"&&n.currentTarget.blur()}}),e.jsxs(ie,{value:a.backendId||M,disabled:c,onValueChange:n=>{const i=p.map(d=>d.id===a.id?{...d,backendId:n===M?"":n}:d);J(i)},children:[e.jsx(le,{className:"h-10 border-slate-400/15 bg-background/88",children:e.jsx(de,{placeholder:t("settingsPage.thinkingSection.configureModelFirst")})}),e.jsx(oe,{children:u.length===0?e.jsx(z,{value:M,children:t("settingsPage.thinkingSection.configureModelFirst")}):u.map(n=>e.jsx(z,{value:n,children:n},n))})]})]})]},a.id))})}):e.jsxs("div",{className:g("rounded-[18px] border border-dashed px-3.5 py-3 text-sm text-muted-foreground",k()),children:["Hidden by default.",p.length>0?` ${p.length} override${p.length===1?"":"s"} saved.`:" No overrides saved."]})]}),e.jsx(T,{tone:"slate",eyebrow:"Audit view",title:"Coverage",description:"Read-only routing ledger for the current path.",icon:e.jsx(me,{className:"h-4 w-4"}),meta:e.jsxs(m,{variant:"outline",children:[s.profiles.length," profiles"]}),children:e.jsx("div",{className:"overflow-hidden rounded-[20px] border border-slate-400/15 bg-background/75 shadow-sm backdrop-blur-sm",children:s.profiles.map((a,n)=>e.jsxs("div",{className:g("grid gap-2 px-3.5 py-2.5 md:grid-cols-[minmax(0,1fr)_auto] md:items-center",n>0&&"border-t border-slate-400/12",Ue(n,a)),children:[e.jsxs("div",{className:"min-w-0",children:[e.jsxs("div",{className:"flex flex-wrap items-center gap-2",children:[e.jsx("div",{className:"truncate text-sm font-semibold text-foreground",children:a.name}),e.jsx(m,{variant:"outline",className:"text-[10px]",children:a.kind==="variant"?t("cliproxyPage.variant"):t("apiProfiles.title")}),e.jsx(m,{variant:"outline",className:"font-mono text-[10px] uppercase",children:a.target}),a.nativeReadPreference&&e.jsx(m,{variant:"outline",className:"border-emerald-500/20 bg-emerald-500/10 text-[10px]",children:"Native"})]}),e.jsxs("div",{className:"mt-0.5 text-[11px] leading-4 text-muted-foreground",children:[a.backendDisplayName||a.profileModel||"Native file access"," ·"," ",ze(a.resolutionSource)]})]}),e.jsxs("div",{className:"flex items-center gap-2 md:justify-end",children:[a.profileModel&&e.jsx(m,{variant:"outline",className:"font-mono text-[10px]",children:a.profileModel}),e.jsx(m,{className:g("border",xe(a.currentTargetMode)),children:ge(a.currentTargetMode)})]})]},`${a.kind}-${a.name}`))})})]})})]}):e.jsxs("div",{className:"p-5",children:[e.jsxs(se,{variant:"destructive",children:[e.jsx(ce,{className:"h-4 w-4"}),e.jsx(ne,{children:I??t("settingsPage.imageAnalysisSection.description")})]}),e.jsx("div",{className:"mt-4",children:e.jsxs(C,{variant:"outline",size:"sm",onClick:ee,children:[e.jsx(G,{className:"mr-1 h-4 w-4"}),t("sharedPage.retry")]})})]})}export{ra as default};
@@ -1 +1 @@
1
- import{j as e}from"./radix-ui-Zb8sVEtn.js";import{r as o}from"./react-vendor-CNOkPC89.js";import{a as q,be as J,bg as X,d as I,n as Y,L as A,r as R,s as M,t as K,v as B,w as E,I as F,aF as Q}from"./index-BDfXfBTa.js";import{R as $,w as Z,x as ee,ac as se,_ as te,s as re}from"./icons-KVCk4_U8.js";import"./tanstack-CrmUhA7Z.js";import"./notifications-B2HqRBj7.js";import"./utils-CzKF5WmX.js";import"./form-utils-Bcoyqxpq.js";import"./code-highlight-BRUf_pqB.js";const z={mode:"auto",tier_defaults:{opus:"high",sonnet:"medium",haiku:"low"},show_warnings:!0},U=1e4;function ie(){const[t,i]=o.useState(null),[b,d]=o.useState(!0),[_,N]=o.useState(!1),[p,g]=o.useState(null),[P,y]=o.useState(!1),f=o.useRef(void 0),w=o.useRef(!1),k=o.useCallback(async()=>{const r=new AbortController,c=setTimeout(()=>r.abort(),U);try{d(!0),g(null);const n=await fetch("/api/thinking",{signal:r.signal});if(clearTimeout(c),!n.ok)throw n.headers.get("content-type")?.includes("text/html")?new Error(`Server error (${n.status})`):new Error("Failed to load Thinking config");const m=await n.json();i(m.config||z),f.current=m.lastModified,w.current=!0}catch(n){clearTimeout(c),n.name==="AbortError"?g("Request timeout - please try again"):g(n.message)}finally{d(!1)}return()=>r.abort()},[]),l=o.useCallback(async r=>{if(!w.current||t===null){g("Cannot save settings before they load. Click Refresh and try again.");return}const c=t,n={...c,...r.mode!==void 0?{mode:r.mode}:{},...r.tier_defaults!==void 0?{tier_defaults:r.tier_defaults}:{},...r.show_warnings!==void 0?{show_warnings:r.show_warnings}:{}};r.clear_override||r.override===null?delete n.override:r.override!==void 0&&(n.override=r.override),r.clear_provider_overrides||r.provider_overrides===null?delete n.provider_overrides:r.provider_overrides!==void 0&&(n.provider_overrides=r.provider_overrides),i(n);const m=new AbortController,h=setTimeout(()=>m.abort(),U);try{N(!0),g(null);const x={...n,lastModified:f.current},u=await fetch("/api/thinking",{method:"PUT",headers:{"Content-Type":"application/json"},body:JSON.stringify(x),signal:m.signal});if(clearTimeout(h),!u.ok){if(u.headers.get("content-type")?.includes("text/html"))throw new Error(`Server error (${u.status})`);const s=await u.json();throw u.status===409?new Error("Config changed by another session. Refreshing..."):new Error(s.error||"Failed to save")}const v=await u.json();i(v.config),f.current=v.lastModified,y(!0),setTimeout(()=>y(!1),1500)}catch(x){clearTimeout(h),i(c),x.name==="AbortError"?g("Request timeout - please try again"):(g(x.message),x.message.includes("another session")&&setTimeout(()=>k(),1e3))}finally{N(!1)}},[t,k]),T=o.useCallback(r=>{l({mode:r})},[l]),C=o.useCallback((r,c)=>{const n=t?.tier_defaults||z.tier_defaults;l({tier_defaults:{...n,[r]:c}})},[t,l]),O=o.useCallback(r=>{l({show_warnings:r})},[l]),D=o.useCallback(r=>{if(r===void 0){l({override:null,clear_override:!0});return}l({override:r,clear_override:!1})},[l]),L=o.useCallback((r,c,n)=>{const m=t?.provider_overrides||{},h=m[r]||{};if(n===void 0){const{[c]:x,...u}=h,v=Object.keys(u).length>0?u:void 0,{[r]:S,...s}=m,a=v?{...s,[r]:v}:s;l({provider_overrides:Object.keys(a).length>0?a:null,clear_provider_overrides:Object.keys(a).length===0})}else l({provider_overrides:{...m,[r]:{...h,[c]:n}},clear_provider_overrides:!1})},[t,l]);return{config:t||z,loading:b,saving:_,error:p,success:P,fetchConfig:k,saveConfig:l,setMode:T,setTierDefault:C,setShowWarnings:O,setOverride:D,setProviderOverride:L}}const H=[{value:"minimal",label:"Minimal (512 tokens)"},{value:"low",label:"Low (1K tokens)"},{value:"medium",label:"Medium (8K tokens)"},{value:"high",label:"High (24K tokens)"},{value:"xhigh",label:"Extra High (32K tokens)"},{value:"auto",label:"Auto (dynamic)"}],ne=[{value:"__none__",label:"None (use CLI flags only)"},...H,{value:"__custom__",label:"Custom budget (number)"},{value:"off",label:"Off (disable thinking)"}],ae=["agy","gemini","codex"],G=0,V=1e5;function fe(){const{t}=q(),{config:i,loading:b,saving:d,error:_,success:N,fetchConfig:p,setMode:g,setTierDefault:P,setShowWarnings:y,setOverride:f,setProviderOverride:w}=ie(),[k,l]=o.useState(null),[T,C]=o.useState(""),[O,D]=o.useState([]),[L,r]=o.useState(null),c=o.useMemo(()=>Array.from(new Set([...ae,...Object.keys(i.provider_overrides??{}),...O])),[O,i.provider_overrides]),n=i.override===void 0?"__none__":typeof i.override=="number"||/^\d+$/.test(String(i.override))?"__custom__":String(i.override),m=typeof i.override=="number"||/^\d+$/.test(String(i.override??""))?String(i.override):"",h=L??m,x=Object.keys(i.provider_overrides??{}).length>0,u=k??x;o.useEffect(()=>{p()},[p]);const v=()=>{const s=T.trim().toLowerCase();s&&(c.includes(s)||D(a=>[...a,s]),C(""),l(!0))},S=()=>{const s=h.trim();if(!s){f(void 0);return}const a=Number.parseInt(s,10);Number.isNaN(a)||a<G||a>V||!/^\d+$/.test(s)||f(a)};return b?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($,{className:"w-5 h-5 animate-spin"}),e.jsx("span",{children:t("settings.loading")})]})}):e.jsxs(e.Fragment,{children:[e.jsxs("div",{className:`absolute left-5 right-5 top-20 z-10 transition-all duration-200 ease-out ${_||N?"opacity-100 translate-y-0":"opacity-0 -translate-y-2 pointer-events-none"}`,children:[_&&e.jsx(J,{variant:"destructive",className:"py-2 shadow-lg",children:e.jsxs("div",{className:"flex items-center justify-between w-full",children:[e.jsxs("div",{className:"flex items-center gap-2",children:[e.jsx(Z,{className:"h-4 w-4"}),e.jsx(X,{children:_})]}),e.jsxs(I,{variant:"outline",size:"sm",onClick:p,className:"h-7 px-2 text-xs border-destructive/50 hover:bg-destructive/10",children:[e.jsx($,{className:"w-3 h-3 mr-1"}),t("sharedPage.retry")]})]})}),N&&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(ee,{className:"h-4 w-4 shrink-0"}),e.jsx("span",{className:"text-sm font-medium",children:t("settings.saved")})]})]}),e.jsx(Y,{className:"flex-1",children:e.jsxs("div",{className:"p-5 space-y-6",children:[e.jsxs("div",{className:"flex items-center gap-3",children:[e.jsx(se,{className:"w-5 h-5 text-primary"}),e.jsx("p",{className:"text-sm text-muted-foreground",children:t("settingsThinking.description")})]}),e.jsxs("div",{className:"flex items-start gap-2 p-3 rounded-lg bg-blue-50 dark:bg-blue-900/20 border border-blue-200 dark:border-blue-800",children:[e.jsx(te,{className:"w-4 h-4 text-blue-600 dark:text-blue-400 shrink-0 mt-0.5"}),e.jsxs("div",{className:"text-sm text-blue-700 dark:text-blue-300",children:[e.jsx("p",{className:"font-medium",children:t("settingsThinking.supportedProviders")}),e.jsxs("ul",{className:"mt-1 space-y-0.5 text-blue-600 dark:text-blue-400",children:[e.jsxs("li",{children:[t("settingsThinking.supportLine1Prefix")," ",e.jsx("strong",{children:"agy"}),","," ",e.jsx("strong",{children:"gemini"})," ",t("settingsThinking.supportLine1Suffix")]}),e.jsxs("li",{children:[t("settingsThinking.supportLine2Prefix")," ",e.jsx("strong",{children:"codex"})," ",t("settingsThinking.supportLine2SuffixPrefix"),e.jsx("code",{children:"--effort"}),t("settingsThinking.supportLine2SuffixPostfix")]}),e.jsxs("li",{children:[t("settingsThinking.supportLine3Prefix")," ",e.jsx("code",{children:"-high"}),t("settingsThinking.supportLine3Suffix")]})]})]})]}),e.jsxs("div",{className:"space-y-3",children:[e.jsx("h3",{className:"text-base font-medium",children:t("settingsThinking.modeTitle")}),e.jsx("div",{className:"space-y-2",children:["auto","off","manual"].map(s=>e.jsxs("div",{className:`flex items-center justify-between p-4 rounded-lg cursor-pointer transition-colors ${i.mode===s?"bg-primary/10 border border-primary/30":"bg-muted/50 hover:bg-muted/80"} ${d?"opacity-70 pointer-events-none":""}`,onClick:()=>{d||g(s)},children:[e.jsxs("div",{children:[e.jsx("p",{className:"font-medium capitalize",children:s}),e.jsxs("p",{className:"text-sm text-muted-foreground",children:[s==="auto"&&t("settingsThinking.modeAutoDesc"),s==="off"&&t("settingsThinking.modeOffDesc"),s==="manual"&&t("settingsThinking.modeManualDesc")]})]}),e.jsx("div",{className:`w-4 h-4 rounded-full border-2 ${i.mode===s?"bg-primary border-primary":"border-muted-foreground/50"}`})]},s))})]}),i.mode==="auto"&&e.jsxs("div",{className:"space-y-3",children:[e.jsx("h3",{className:"text-base font-medium",children:t("settingsThinking.tierDefaults")}),e.jsx("p",{className:"text-sm text-muted-foreground",children:t("settingsThinking.tierDefaultsDesc")}),e.jsx("div",{className:"space-y-3",children:["opus","sonnet","haiku"].map(s=>e.jsxs("div",{className:"flex items-center gap-4 p-3 rounded-lg bg-muted/30",children:[e.jsx(A,{className:"w-20 capitalize font-medium",children:s}),e.jsxs(R,{value:i.tier_defaults[s],onValueChange:a=>P(s,a),disabled:d,children:[e.jsx(M,{className:"flex-1",children:e.jsx(K,{})}),e.jsx(B,{children:H.map(a=>e.jsx(E,{value:a.value,children:a.label},a.value))})]})]},s))})]}),i.mode==="manual"&&e.jsxs("div",{className:"space-y-3",children:[e.jsx("h3",{className:"text-base font-medium",children:t("settingsThinking.persistentOverride")}),e.jsx("p",{className:"text-sm text-muted-foreground",children:t("settingsThinking.persistentOverrideDesc")}),e.jsxs(R,{value:n,onValueChange:s=>{if(s==="__none__"){f(void 0);return}if(s==="__custom__"){h||r("8192");return}r(null),f(s)},disabled:d,children:[e.jsx(M,{children:e.jsx(K,{})}),e.jsx(B,{children:ne.map(s=>e.jsx(E,{value:s.value,children:s.label},s.value))})]}),n==="__custom__"&&e.jsxs("div",{className:"space-y-2",children:[e.jsxs("div",{className:"flex items-center gap-2",children:[e.jsx(F,{type:"number",min:G,max:V,value:h,onChange:s=>r(s.target.value),onBlur:S,disabled:d,placeholder:t("settingsThinking.enterCustomBudget")}),e.jsx(I,{type:"button",size:"sm",variant:"outline",onClick:S,disabled:d,children:t("settingsThinking.apply")})]}),e.jsxs("p",{className:"text-xs text-muted-foreground",children:["Range: ",G," to ",V]})]})]}),e.jsxs("div",{className:"space-y-3",children:[e.jsxs("button",{type:"button",className:"flex items-center gap-2 text-base font-medium w-full text-left",onClick:()=>l(s=>!(s??x)),disabled:d,children:[e.jsx(re,{className:`w-4 h-4 transition-transform ${u?"rotate-0":"-rotate-90"}`}),t("settingsThinking.providerOverrides",{count:Object.keys(i.provider_overrides??{}).length})]}),u&&e.jsxs("div",{className:"space-y-3",children:[e.jsx("p",{className:"text-sm text-muted-foreground",children:t("settingsThinking.providerOverridesDesc")}),e.jsxs("div",{className:"flex items-center gap-2",children:[e.jsx(F,{value:T,onChange:s=>C(s.target.value),disabled:d,placeholder:t("settingsThinking.addProviderPlaceholder")}),e.jsx(I,{type:"button",size:"sm",variant:"outline",onClick:v,disabled:d,children:t("settingsGlobalEnv.add")})]}),c.map(s=>e.jsxs("div",{className:"space-y-2 p-3 rounded-lg bg-muted/30",children:[e.jsx(A,{className:"capitalize font-medium text-sm",children:s}),e.jsx("div",{className:"grid grid-cols-3 gap-2",children:["opus","sonnet","haiku"].map(a=>{const W=i.provider_overrides?.[s]?.[a]||"__default__";return e.jsxs("div",{className:"space-y-1",children:[e.jsx(A,{className:"text-xs text-muted-foreground capitalize",children:a}),e.jsxs(R,{value:W,onValueChange:j=>w(s,a,j==="__default__"?void 0:j),disabled:d,children:[e.jsx(M,{className:"h-8 text-xs",children:e.jsx(K,{})}),e.jsxs(B,{children:[e.jsx(E,{value:"__default__",children:t("cursorPage.default")}),H.map(j=>e.jsx(E,{value:j.value,children:j.label},j.value))]})]})]},a)})})]},s))]})]}),e.jsxs("div",{className:"flex items-center justify-between p-4 rounded-lg bg-muted/50",children:[e.jsxs("div",{children:[e.jsx("p",{className:"font-medium",children:t("settingsThinking.showWarnings")}),e.jsx("p",{className:"text-sm text-muted-foreground",children:t("settingsThinking.showWarningsDesc")})]}),e.jsx(Q,{checked:i.show_warnings??!0,onCheckedChange:y,disabled:d})]}),e.jsxs("div",{className:"p-4 rounded-lg border bg-muted/30",children:[e.jsx("h4",{className:"text-sm font-medium mb-2",children:t("settingsThinking.cliEnvOverride")}),e.jsxs("p",{className:"text-sm text-muted-foreground mb-2",children:["Override per session with flags or"," ",e.jsx("code",{className:"px-1.5 py-0.5 rounded bg-muted",children:"CCS_THINKING"})," env var. Priority: flag > env > config."]}),e.jsxs("div",{className:"space-y-1 text-sm font-mono text-muted-foreground",children:[e.jsx("p",{children:"ccs gemini --thinking high"}),e.jsx("p",{children:"ccs codex --effort xhigh"}),e.jsx("p",{children:'CCS_THINKING=high ccs codex "debug this"'}),e.jsx("p",{children:"ccs config thinking --mode auto"})]})]})]})}),e.jsx("div",{className:"p-4 border-t bg-background",children:e.jsxs(I,{variant:"outline",size:"sm",onClick:p,disabled:b||d,className:"w-full",children:[e.jsx($,{className:`w-4 h-4 mr-2 ${b?"animate-spin":""}`}),t("settings.refresh")]})})]})}export{fe as default};
1
+ import{j as e}from"./radix-ui-Zb8sVEtn.js";import{r as o}from"./react-vendor-CNOkPC89.js";import{a as q,be as J,bg as X,d as I,n as Y,L as A,r as R,s as M,t as K,v as B,w as E,I as F,aF as Q}from"./index-g2g1k0QS.js";import{R as $,w as Z,x as ee,ac as se,_ as te,s as re}from"./icons-KVCk4_U8.js";import"./tanstack-CrmUhA7Z.js";import"./notifications-B2HqRBj7.js";import"./utils-CzKF5WmX.js";import"./form-utils-Bcoyqxpq.js";import"./code-highlight-BRUf_pqB.js";const z={mode:"auto",tier_defaults:{opus:"high",sonnet:"medium",haiku:"low"},show_warnings:!0},U=1e4;function ie(){const[t,i]=o.useState(null),[b,d]=o.useState(!0),[_,N]=o.useState(!1),[p,g]=o.useState(null),[P,y]=o.useState(!1),f=o.useRef(void 0),w=o.useRef(!1),k=o.useCallback(async()=>{const r=new AbortController,c=setTimeout(()=>r.abort(),U);try{d(!0),g(null);const n=await fetch("/api/thinking",{signal:r.signal});if(clearTimeout(c),!n.ok)throw n.headers.get("content-type")?.includes("text/html")?new Error(`Server error (${n.status})`):new Error("Failed to load Thinking config");const m=await n.json();i(m.config||z),f.current=m.lastModified,w.current=!0}catch(n){clearTimeout(c),n.name==="AbortError"?g("Request timeout - please try again"):g(n.message)}finally{d(!1)}return()=>r.abort()},[]),l=o.useCallback(async r=>{if(!w.current||t===null){g("Cannot save settings before they load. Click Refresh and try again.");return}const c=t,n={...c,...r.mode!==void 0?{mode:r.mode}:{},...r.tier_defaults!==void 0?{tier_defaults:r.tier_defaults}:{},...r.show_warnings!==void 0?{show_warnings:r.show_warnings}:{}};r.clear_override||r.override===null?delete n.override:r.override!==void 0&&(n.override=r.override),r.clear_provider_overrides||r.provider_overrides===null?delete n.provider_overrides:r.provider_overrides!==void 0&&(n.provider_overrides=r.provider_overrides),i(n);const m=new AbortController,h=setTimeout(()=>m.abort(),U);try{N(!0),g(null);const x={...n,lastModified:f.current},u=await fetch("/api/thinking",{method:"PUT",headers:{"Content-Type":"application/json"},body:JSON.stringify(x),signal:m.signal});if(clearTimeout(h),!u.ok){if(u.headers.get("content-type")?.includes("text/html"))throw new Error(`Server error (${u.status})`);const s=await u.json();throw u.status===409?new Error("Config changed by another session. Refreshing..."):new Error(s.error||"Failed to save")}const v=await u.json();i(v.config),f.current=v.lastModified,y(!0),setTimeout(()=>y(!1),1500)}catch(x){clearTimeout(h),i(c),x.name==="AbortError"?g("Request timeout - please try again"):(g(x.message),x.message.includes("another session")&&setTimeout(()=>k(),1e3))}finally{N(!1)}},[t,k]),T=o.useCallback(r=>{l({mode:r})},[l]),C=o.useCallback((r,c)=>{const n=t?.tier_defaults||z.tier_defaults;l({tier_defaults:{...n,[r]:c}})},[t,l]),O=o.useCallback(r=>{l({show_warnings:r})},[l]),D=o.useCallback(r=>{if(r===void 0){l({override:null,clear_override:!0});return}l({override:r,clear_override:!1})},[l]),L=o.useCallback((r,c,n)=>{const m=t?.provider_overrides||{},h=m[r]||{};if(n===void 0){const{[c]:x,...u}=h,v=Object.keys(u).length>0?u:void 0,{[r]:S,...s}=m,a=v?{...s,[r]:v}:s;l({provider_overrides:Object.keys(a).length>0?a:null,clear_provider_overrides:Object.keys(a).length===0})}else l({provider_overrides:{...m,[r]:{...h,[c]:n}},clear_provider_overrides:!1})},[t,l]);return{config:t||z,loading:b,saving:_,error:p,success:P,fetchConfig:k,saveConfig:l,setMode:T,setTierDefault:C,setShowWarnings:O,setOverride:D,setProviderOverride:L}}const H=[{value:"minimal",label:"Minimal (512 tokens)"},{value:"low",label:"Low (1K tokens)"},{value:"medium",label:"Medium (8K tokens)"},{value:"high",label:"High (24K tokens)"},{value:"xhigh",label:"Extra High (32K tokens)"},{value:"auto",label:"Auto (dynamic)"}],ne=[{value:"__none__",label:"None (use CLI flags only)"},...H,{value:"__custom__",label:"Custom budget (number)"},{value:"off",label:"Off (disable thinking)"}],ae=["agy","gemini","codex"],G=0,V=1e5;function fe(){const{t}=q(),{config:i,loading:b,saving:d,error:_,success:N,fetchConfig:p,setMode:g,setTierDefault:P,setShowWarnings:y,setOverride:f,setProviderOverride:w}=ie(),[k,l]=o.useState(null),[T,C]=o.useState(""),[O,D]=o.useState([]),[L,r]=o.useState(null),c=o.useMemo(()=>Array.from(new Set([...ae,...Object.keys(i.provider_overrides??{}),...O])),[O,i.provider_overrides]),n=i.override===void 0?"__none__":typeof i.override=="number"||/^\d+$/.test(String(i.override))?"__custom__":String(i.override),m=typeof i.override=="number"||/^\d+$/.test(String(i.override??""))?String(i.override):"",h=L??m,x=Object.keys(i.provider_overrides??{}).length>0,u=k??x;o.useEffect(()=>{p()},[p]);const v=()=>{const s=T.trim().toLowerCase();s&&(c.includes(s)||D(a=>[...a,s]),C(""),l(!0))},S=()=>{const s=h.trim();if(!s){f(void 0);return}const a=Number.parseInt(s,10);Number.isNaN(a)||a<G||a>V||!/^\d+$/.test(s)||f(a)};return b?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($,{className:"w-5 h-5 animate-spin"}),e.jsx("span",{children:t("settings.loading")})]})}):e.jsxs(e.Fragment,{children:[e.jsxs("div",{className:`absolute left-5 right-5 top-20 z-10 transition-all duration-200 ease-out ${_||N?"opacity-100 translate-y-0":"opacity-0 -translate-y-2 pointer-events-none"}`,children:[_&&e.jsx(J,{variant:"destructive",className:"py-2 shadow-lg",children:e.jsxs("div",{className:"flex items-center justify-between w-full",children:[e.jsxs("div",{className:"flex items-center gap-2",children:[e.jsx(Z,{className:"h-4 w-4"}),e.jsx(X,{children:_})]}),e.jsxs(I,{variant:"outline",size:"sm",onClick:p,className:"h-7 px-2 text-xs border-destructive/50 hover:bg-destructive/10",children:[e.jsx($,{className:"w-3 h-3 mr-1"}),t("sharedPage.retry")]})]})}),N&&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(ee,{className:"h-4 w-4 shrink-0"}),e.jsx("span",{className:"text-sm font-medium",children:t("settings.saved")})]})]}),e.jsx(Y,{className:"flex-1",children:e.jsxs("div",{className:"p-5 space-y-6",children:[e.jsxs("div",{className:"flex items-center gap-3",children:[e.jsx(se,{className:"w-5 h-5 text-primary"}),e.jsx("p",{className:"text-sm text-muted-foreground",children:t("settingsThinking.description")})]}),e.jsxs("div",{className:"flex items-start gap-2 p-3 rounded-lg bg-blue-50 dark:bg-blue-900/20 border border-blue-200 dark:border-blue-800",children:[e.jsx(te,{className:"w-4 h-4 text-blue-600 dark:text-blue-400 shrink-0 mt-0.5"}),e.jsxs("div",{className:"text-sm text-blue-700 dark:text-blue-300",children:[e.jsx("p",{className:"font-medium",children:t("settingsThinking.supportedProviders")}),e.jsxs("ul",{className:"mt-1 space-y-0.5 text-blue-600 dark:text-blue-400",children:[e.jsxs("li",{children:[t("settingsThinking.supportLine1Prefix")," ",e.jsx("strong",{children:"agy"}),","," ",e.jsx("strong",{children:"gemini"})," ",t("settingsThinking.supportLine1Suffix")]}),e.jsxs("li",{children:[t("settingsThinking.supportLine2Prefix")," ",e.jsx("strong",{children:"codex"})," ",t("settingsThinking.supportLine2SuffixPrefix"),e.jsx("code",{children:"--effort"}),t("settingsThinking.supportLine2SuffixPostfix")]}),e.jsxs("li",{children:[t("settingsThinking.supportLine3Prefix")," ",e.jsx("code",{children:"-high"}),t("settingsThinking.supportLine3Suffix")]})]})]})]}),e.jsxs("div",{className:"space-y-3",children:[e.jsx("h3",{className:"text-base font-medium",children:t("settingsThinking.modeTitle")}),e.jsx("div",{className:"space-y-2",children:["auto","off","manual"].map(s=>e.jsxs("div",{className:`flex items-center justify-between p-4 rounded-lg cursor-pointer transition-colors ${i.mode===s?"bg-primary/10 border border-primary/30":"bg-muted/50 hover:bg-muted/80"} ${d?"opacity-70 pointer-events-none":""}`,onClick:()=>{d||g(s)},children:[e.jsxs("div",{children:[e.jsx("p",{className:"font-medium capitalize",children:s}),e.jsxs("p",{className:"text-sm text-muted-foreground",children:[s==="auto"&&t("settingsThinking.modeAutoDesc"),s==="off"&&t("settingsThinking.modeOffDesc"),s==="manual"&&t("settingsThinking.modeManualDesc")]})]}),e.jsx("div",{className:`w-4 h-4 rounded-full border-2 ${i.mode===s?"bg-primary border-primary":"border-muted-foreground/50"}`})]},s))})]}),i.mode==="auto"&&e.jsxs("div",{className:"space-y-3",children:[e.jsx("h3",{className:"text-base font-medium",children:t("settingsThinking.tierDefaults")}),e.jsx("p",{className:"text-sm text-muted-foreground",children:t("settingsThinking.tierDefaultsDesc")}),e.jsx("div",{className:"space-y-3",children:["opus","sonnet","haiku"].map(s=>e.jsxs("div",{className:"flex items-center gap-4 p-3 rounded-lg bg-muted/30",children:[e.jsx(A,{className:"w-20 capitalize font-medium",children:s}),e.jsxs(R,{value:i.tier_defaults[s],onValueChange:a=>P(s,a),disabled:d,children:[e.jsx(M,{className:"flex-1",children:e.jsx(K,{})}),e.jsx(B,{children:H.map(a=>e.jsx(E,{value:a.value,children:a.label},a.value))})]})]},s))})]}),i.mode==="manual"&&e.jsxs("div",{className:"space-y-3",children:[e.jsx("h3",{className:"text-base font-medium",children:t("settingsThinking.persistentOverride")}),e.jsx("p",{className:"text-sm text-muted-foreground",children:t("settingsThinking.persistentOverrideDesc")}),e.jsxs(R,{value:n,onValueChange:s=>{if(s==="__none__"){f(void 0);return}if(s==="__custom__"){h||r("8192");return}r(null),f(s)},disabled:d,children:[e.jsx(M,{children:e.jsx(K,{})}),e.jsx(B,{children:ne.map(s=>e.jsx(E,{value:s.value,children:s.label},s.value))})]}),n==="__custom__"&&e.jsxs("div",{className:"space-y-2",children:[e.jsxs("div",{className:"flex items-center gap-2",children:[e.jsx(F,{type:"number",min:G,max:V,value:h,onChange:s=>r(s.target.value),onBlur:S,disabled:d,placeholder:t("settingsThinking.enterCustomBudget")}),e.jsx(I,{type:"button",size:"sm",variant:"outline",onClick:S,disabled:d,children:t("settingsThinking.apply")})]}),e.jsxs("p",{className:"text-xs text-muted-foreground",children:["Range: ",G," to ",V]})]})]}),e.jsxs("div",{className:"space-y-3",children:[e.jsxs("button",{type:"button",className:"flex items-center gap-2 text-base font-medium w-full text-left",onClick:()=>l(s=>!(s??x)),disabled:d,children:[e.jsx(re,{className:`w-4 h-4 transition-transform ${u?"rotate-0":"-rotate-90"}`}),t("settingsThinking.providerOverrides",{count:Object.keys(i.provider_overrides??{}).length})]}),u&&e.jsxs("div",{className:"space-y-3",children:[e.jsx("p",{className:"text-sm text-muted-foreground",children:t("settingsThinking.providerOverridesDesc")}),e.jsxs("div",{className:"flex items-center gap-2",children:[e.jsx(F,{value:T,onChange:s=>C(s.target.value),disabled:d,placeholder:t("settingsThinking.addProviderPlaceholder")}),e.jsx(I,{type:"button",size:"sm",variant:"outline",onClick:v,disabled:d,children:t("settingsGlobalEnv.add")})]}),c.map(s=>e.jsxs("div",{className:"space-y-2 p-3 rounded-lg bg-muted/30",children:[e.jsx(A,{className:"capitalize font-medium text-sm",children:s}),e.jsx("div",{className:"grid grid-cols-3 gap-2",children:["opus","sonnet","haiku"].map(a=>{const W=i.provider_overrides?.[s]?.[a]||"__default__";return e.jsxs("div",{className:"space-y-1",children:[e.jsx(A,{className:"text-xs text-muted-foreground capitalize",children:a}),e.jsxs(R,{value:W,onValueChange:j=>w(s,a,j==="__default__"?void 0:j),disabled:d,children:[e.jsx(M,{className:"h-8 text-xs",children:e.jsx(K,{})}),e.jsxs(B,{children:[e.jsx(E,{value:"__default__",children:t("cursorPage.default")}),H.map(j=>e.jsx(E,{value:j.value,children:j.label},j.value))]})]})]},a)})})]},s))]})]}),e.jsxs("div",{className:"flex items-center justify-between p-4 rounded-lg bg-muted/50",children:[e.jsxs("div",{children:[e.jsx("p",{className:"font-medium",children:t("settingsThinking.showWarnings")}),e.jsx("p",{className:"text-sm text-muted-foreground",children:t("settingsThinking.showWarningsDesc")})]}),e.jsx(Q,{checked:i.show_warnings??!0,onCheckedChange:y,disabled:d})]}),e.jsxs("div",{className:"p-4 rounded-lg border bg-muted/30",children:[e.jsx("h4",{className:"text-sm font-medium mb-2",children:t("settingsThinking.cliEnvOverride")}),e.jsxs("p",{className:"text-sm text-muted-foreground mb-2",children:["Override per session with flags or"," ",e.jsx("code",{className:"px-1.5 py-0.5 rounded bg-muted",children:"CCS_THINKING"})," env var. Priority: flag > env > config."]}),e.jsxs("div",{className:"space-y-1 text-sm font-mono text-muted-foreground",children:[e.jsx("p",{children:"ccs gemini --thinking high"}),e.jsx("p",{children:"ccs codex --effort xhigh"}),e.jsx("p",{children:'CCS_THINKING=high ccs codex "debug this"'}),e.jsx("p",{children:"ccs config thinking --mode auto"})]})]})]})}),e.jsx("div",{className:"p-4 border-t bg-background",children:e.jsxs(I,{variant:"outline",size:"sm",onClick:p,disabled:b||d,className:"w-full",children:[e.jsx($,{className:`w-4 h-4 mr-2 ${b?"animate-spin":""}`}),t("settings.refresh")]})})]})}export{fe as default};