@georgedong32/ccs 7.67.2 → 7.67.4

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 (40) hide show
  1. package/dist/ui/assets/{accounts-DhtktAIG.js → accounts-CzCowrUs.js} +1 -1
  2. package/dist/ui/assets/{alert-dialog-DQK2Jxfk.js → alert-dialog-LsND-cGZ.js} +1 -1
  3. package/dist/ui/assets/{api-Den1YY2d.js → api-i-0agVih.js} +1 -1
  4. package/dist/ui/assets/{auth-section-BQitOLMK.js → auth-section-DQJp0aGP.js} +1 -1
  5. package/dist/ui/assets/{backups-section-BLGK5re-.js → backups-section-B5D0dMOE.js} +1 -1
  6. package/dist/ui/assets/{channels-Dop1axTi.js → channels-NiDkumAl.js} +1 -1
  7. package/dist/ui/assets/{checkbox-DDrDuGxi.js → checkbox-CwzSTCer.js} +1 -1
  8. package/dist/ui/assets/{claude-extension-6WjTc0o8.js → claude-extension-CmqJSUtA.js} +1 -1
  9. package/dist/ui/assets/{cliproxy-ai-providers-DjybBlb5.js → cliproxy-ai-providers-CG63eFGu.js} +1 -1
  10. package/dist/ui/assets/{cliproxy-control-panel-DDif_QAT.js → cliproxy-control-panel-BGWGq0gP.js} +1 -1
  11. package/dist/ui/assets/{cliproxy-Ch7RdSMG.js → cliproxy-jogm6kYf.js} +1 -1
  12. package/dist/ui/assets/{codex-DFAV50Ee.js → codex-CsZ0WXX_.js} +1 -1
  13. package/dist/ui/assets/{confirm-dialog-CP26_Zko.js → confirm-dialog-CMyaanxh.js} +1 -1
  14. package/dist/ui/assets/{copilot-uZuyhqwv.js → copilot-B0PLfdH4.js} +1 -1
  15. package/dist/ui/assets/{cursor-CuaM2FmN.js → cursor-CghFYyk2.js} +1 -1
  16. package/dist/ui/assets/{droid-DdjXJ2lF.js → droid-s1kw4V0q.js} +1 -1
  17. package/dist/ui/assets/{globalenv-section-D5_-EIlf.js → globalenv-section-d3YSlxbQ.js} +1 -1
  18. package/dist/ui/assets/{health-BHhVKLNR.js → health-wJQbPwb8.js} +1 -1
  19. package/dist/ui/assets/index-BHhqByt1.js +1 -0
  20. package/dist/ui/assets/{index-Bm09kGOw.js → index-BSyPYJWF.js} +1 -1
  21. package/dist/ui/assets/{index-B8bAYHAs.js → index-BdR3qGbH.js} +1 -1
  22. package/dist/ui/assets/{index-TSYtCr3K.js → index-BoI6MBbS.js} +3 -3
  23. package/dist/ui/assets/{index-Ba-43jCS.js → index-DDFPAQu4.js} +1 -1
  24. package/dist/ui/assets/index-DivpQpz_.css +1 -0
  25. package/dist/ui/assets/{index-DHY37v8a.js → index-DqMcDqos.js} +1 -1
  26. package/dist/ui/assets/{masked-input-CTkIqCMg.js → masked-input-Byd1i6Bm.js} +1 -1
  27. package/dist/ui/assets/{proxy-status-widget-DPhKjJFl.js → proxy-status-widget-pKxprGDY.js} +1 -1
  28. package/dist/ui/assets/{raw-json-settings-editor-panel-DQr_y0E4.js → raw-json-settings-editor-panel-C8xf13f9.js} +1 -1
  29. package/dist/ui/assets/{searchable-select-C2sP7JW5.js → searchable-select-BX5NA24d.js} +1 -1
  30. package/dist/ui/assets/{separator-2lt47Sla.js → separator-B53uJMjm.js} +1 -1
  31. package/dist/ui/assets/{shared-DPKtsiFQ.js → shared-BTZYXpfu.js} +1 -1
  32. package/dist/ui/assets/{table-DbsFACgT.js → table-DbjCioCJ.js} +1 -1
  33. package/dist/ui/assets/{updates-C5iL4KNn.js → updates-X6HdTfsW.js} +1 -1
  34. package/dist/ui/index.html +2 -2
  35. package/dist/web-server/model-pricing.d.ts.map +1 -1
  36. package/dist/web-server/model-pricing.js +85 -25
  37. package/dist/web-server/model-pricing.js.map +1 -1
  38. package/package.json +1 -1
  39. package/dist/ui/assets/index-Bb2CPQik.css +0 -1
  40. package/dist/ui/assets/index-DLCFe4s3.js +0 -1
@@ -0,0 +1 @@
1
+ import{j as e}from"./radix-ui-BlliRfHq.js";import{r as f,c as we}from"./react-vendor-CNOkPC89.js";import{u as P,a as F,C,b as D,S as j,c as u,P as b,B as V,d as B,e as le,f as ve,g as oe,h as be,D as ke,i as Ce,j as De,k as Se,l as Me,m as Te,n as ie,o as T,p as U,q as Z,I as Fe,r as Le}from"./index-BoI6MBbS.js";import{a0 as ce,ae as G,af as E,ag as de,_ as ue,a6 as $e,G as Re,ah as J,L as Pe,ai as Be,v as qe,u as Ae,aj as Ke,R as Ue,V as te,U as Ie,Z as Ee,t as He,ak as Oe,al as _e,am as xe,C as Qe,an as We}from"./icons-CQ3MLSan.js";import{a as z,u as M,b as se}from"./tanstack-BjiH4QZq.js";import{K as q,L as ee,f as L,H as Ge}from"./utils-CzKF5WmX.js";import{R as me,A as ze,C as Ye,X as Ve,Y as ae,T as he,a as ne,P as Ze,b as Xe,c as Je}from"./charts-BBPXh0Ar.js";import"./notifications-B2HqRBj7.js";import"./form-utils-Bcoyqxpq.js";import"./code-highlight-BRUf_pqB.js";function es({data:s,isLoading:t}){const{privacyMode:a}=P(),{t:n}=F();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(r=>e.jsx(C,{children:e.jsx(D,{className:"p-6",children:e.jsxs("div",{className:"flex items-center justify-between",children:[e.jsxs("div",{className:"space-y-2",children:[e.jsx(j,{className:"h-4 w-[100px]"}),e.jsx(j,{className:"h-8 w-[80px]"})]}),e.jsx(j,{className:"h-8 w-8 rounded-lg"})]})})},r))});const l=(s?.tokenBreakdown?.cacheCreation?.cost??0)+(s?.tokenBreakdown?.cacheRead?.cost??0),o=s?.totalCost?Math.round(l/s.totalCost*100):0,c=[{title:n("analyticsSummary.totalTokens"),value:s?.totalTokens??0,icon:ce,format:r=>K(r),color:"text-blue-600",bgColor:"bg-blue-100 dark:bg-blue-900/20",subtitle:n("analyticsSummary.totalTokensSubtitle",{input:K(s?.totalInputTokens??0),output:K(s?.totalOutputTokens??0)})},{title:n("analyticsSummary.totalCost"),value:s?.totalCost??0,icon:G,format:r=>`$${r.toFixed(2)}`,color:"text-green-600",bgColor:"bg-green-100 dark:bg-green-900/20",subtitle:n("analyticsSummary.totalCostSubtitle",{value:s?.averageCostPerDay?.toFixed(2)??"0.00"})},{title:n("analyticsSummary.cacheTokens"),value:s?.totalCacheTokens??0,icon:E,format:r=>K(r),color:"text-cyan-600",bgColor:"bg-cyan-100 dark:bg-cyan-900/20",subtitle:n("analyticsSummary.cacheTokensSubtitle",{cost:l.toFixed(2),percent:o})},{title:n("analyticsSummary.inputCost"),value:s?.tokenBreakdown?.input?.cost??0,icon:de,format:r=>`$${r.toFixed(2)}`,color:"text-purple-600",bgColor:"bg-purple-100 dark:bg-purple-900/20",subtitle:n("analyticsSummary.tokensSubtitle",{value:K(s?.tokenBreakdown?.input?.tokens??0)})},{title:n("analyticsSummary.outputCost"),value:s?.tokenBreakdown?.output?.cost??0,icon:ue,format:r=>`$${r.toFixed(2)}`,color:"text-orange-600",bgColor:"bg-orange-100 dark:bg-orange-900/20",subtitle:n("analyticsSummary.tokensSubtitle",{value:K(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:c.map((r,i)=>{const x=r.icon;return e.jsx(C,{className:"hover:shadow-md transition-shadow",children:e.jsx(D,{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:r.title}),e.jsx("p",{className:u("text-xl font-bold truncate",a&&b),children:r.format(r.value)}),r.subtitle&&e.jsx("p",{className:u("text-[10px] text-muted-foreground truncate",a&&b),children:r.subtitle})]}),e.jsx("div",{className:u("p-2 rounded-lg shrink-0",r.bgColor),children:e.jsx(x,{className:u("h-4 w-4",r.color)})})]})})},i)})})}function K(s){return s>=1e6?`${(s/1e6).toFixed(1)}M`:s>=1e3?`${(s/1e3).toFixed(1)}K`:s.toLocaleString()}function ss({model:s}){const{privacyMode:t}=P(),{t:a}=F(),n=ts(s.ioRatio,a),l=s.cacheReadTokens||0,o=l>0?l/(s.inputTokens+l)*100:0,c=o>=85?"#6ed192":o>=50?"#f54900":"#c20000";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($e,{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.jsx(V,{variant:"secondary",className:"text-[10px] h-5 px-1.5",children:a("analyticsModelDetail.percentUsage",{percent:s.percentage.toFixed(1)})}),e.jsx(V,{variant:n.variant,className:"text-[10px] h-5 px-1.5",children:a("analyticsModelDetail.ioRatio",{ratio:s.ioRatio.toFixed(0)})}),l>0&&e.jsx(V,{className:"text-[10px] h-5 px-1.5 text-white",style:{backgroundColor:c},children:a("analyticsModelDetail.cacheHitRate",{rate:o.toFixed(0)})})]})]}),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:u("text-lg font-bold",t&&b),children:["$",s.cost.toFixed(2)]}),e.jsx("p",{className:"text-[10px] text-muted-foreground uppercase tracking-wider",children:a("analyticsModelDetail.totalCost")})]}),e.jsxs("div",{className:"p-2 rounded-md bg-muted/50 border text-center",children:[e.jsx("p",{className:u("text-lg font-bold",t&&b),children:ns(s.tokens)}),e.jsx("p",{className:"text-[10px] text-muted-foreground uppercase tracking-wider",children:a("analyticsModelDetail.totalTokens")})]})]}),e.jsxs("div",{className:"space-y-2",children:[e.jsx("h5",{className:"text-[11px] font-medium text-muted-foreground uppercase tracking-wider",children:a("analyticsModelDetail.tokenBreakdown")}),e.jsxs("div",{className:u("space-y-1",t&&b),children:[e.jsx(Q,{label:a("analyticsToken.input"),tokens:s.inputTokens,cost:s.costBreakdown.input.cost,color:"#335c67",icon:de}),e.jsx(Q,{label:a("analyticsToken.output"),tokens:s.outputTokens,cost:s.costBreakdown.output.cost,color:"#fff3b0",icon:ue}),e.jsx(Q,{label:a("analyticsToken.cacheWrite"),tokens:s.cacheCreationTokens,cost:s.costBreakdown.cacheCreation.cost,color:"#e09f3e",icon:E}),e.jsx(Q,{label:a("analyticsToken.cacheRead"),tokens:s.cacheReadTokens,cost:s.costBreakdown.cacheRead.cost,color:"#9e2a2b",icon:E})]})]}),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(Re,{className:"h-3.5 w-3.5 text-muted-foreground"}),e.jsx("span",{className:"text-xs font-medium",children:a("analyticsModelDetail.ioRatioTitle")})]}),e.jsx("p",{className:"text-[11px] text-muted-foreground leading-snug",children:n.description})]})]})}function Q({label:s,tokens:t,cost:a,color:n,icon:l}){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:n}}),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(l,{className:"h-3 w-3 shrink-0"}),e.jsx("span",{children:as(t)})]})]})]})}function ts(s,t){return s>=200?{variant:"destructive",description:t("analyticsModelDetail.ioDescHigh")}:s>=50?{variant:"secondary",description:t("analyticsModelDetail.ioDescMedHigh")}:s>=5?{variant:"outline",description:t("analyticsModelDetail.ioDescBalanced")}:{variant:"default",description:t("analyticsModelDetail.ioDescHighOutput")}}function as(s){return s.toLocaleString()}function ns(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 rs="/api";function S(s){const t=s.getFullYear(),a=String(s.getMonth()+1).padStart(2,"0"),n=String(s.getDate()).padStart(2,"0");return`${t}${a}${n}`}const $={summary:s=>{const t=new URLSearchParams;return s?.startDate&&t.append("since",S(s.startDate)),s?.endDate&&t.append("until",S(s.endDate)),s?.profile&&t.append("profile",s.profile),R(`/usage/summary?${t}`)},trends:s=>{const t=new URLSearchParams;return s?.startDate&&t.append("since",S(s.startDate)),s?.endDate&&t.append("until",S(s.endDate)),s?.profile&&t.append("profile",s.profile),R(`/usage/daily?${t}`)},hourly:s=>{const t=new URLSearchParams;return s?.startDate&&t.append("since",S(s.startDate)),s?.endDate&&t.append("until",S(s.endDate)),R(`/usage/hourly?${t}`)},models:s=>{const t=new URLSearchParams;return s?.startDate&&t.append("since",S(s.startDate)),s?.endDate&&t.append("until",S(s.endDate)),s?.profile&&t.append("profile",s.profile),R(`/usage/models?${t}`)},sessions:s=>{const t=new URLSearchParams;return s?.startDate&&t.append("since",S(s.startDate)),s?.endDate&&t.append("until",S(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()),R(`/usage/sessions?${t}`)},monthly:(s,t)=>{const a=new URLSearchParams;return s&&a.append("months",s.toString()),t&&a.append("profile",t),R(`/usage/monthly?${a}`)},refresh:async()=>{if(!(await fetch(`${rs}/usage/refresh`,{method:"POST",headers:{"Content-Type":"application/json"}})).ok)throw new Error("Failed to refresh usage cache")},status:()=>R("/usage/status"),insights:s=>{const t=new URLSearchParams;return s?.startDate&&t.append("since",S(s.startDate)),s?.endDate&&t.append("until",S(s.endDate)),s?.profile&&t.append("profile",s.profile),R(`/usage/insights?${t}`)},cursorImport:async s=>{const t=new FormData;t.append("file",s);const a=await fetch("/api/usage/cursor/import",{method:"POST",body:t});if(!a.ok){const l=await a.json().catch(()=>({error:"Upload failed"}));throw new Error(l.error||"Failed to import Cursor usage data")}return(await a.json()).data},cursorStatus:async()=>{const s=await fetch("/api/usage/cursor/status");if(!s.ok)throw new Error("Failed to fetch Cursor status");return(await s.json()).data},cursorDataClear:async()=>{const s=await fetch("/api/usage/cursor/data",{method:"DELETE"});if(!s.ok)throw new Error("Failed to clear Cursor data");return(await s.json()).data}};async function R(s){const a=await fetch(`/api${s}`,{headers:{"Content-Type":"application/json"}});if(!a.ok){const l=await a.json().catch(()=>({error:"Unknown error"}));throw new Error(l.error||a.statusText)}const n=await a.json();return n.data||n}function ls(s){return M({queryKey:["usage","summary",s],queryFn:()=>$.summary(s),staleTime:60*1e3})}function os(s){return M({queryKey:["usage","trends",s],queryFn:()=>$.trends(s),staleTime:60*1e3})}function is(s){return M({queryKey:["usage","hourly",s],queryFn:()=>$.hourly(s),staleTime:60*1e3})}function cs(s){return M({queryKey:["usage","models",s],queryFn:()=>$.models(s),staleTime:60*1e3})}function ds(){const s=z();return f.useCallback(async()=>{await $.refresh(),await s.invalidateQueries({queryKey:["usage"]})},[s])}function us(){return M({queryKey:["usage","status"],queryFn:()=>$.status(),staleTime:10*1e3,refetchInterval:30*1e3})}function xs(s){return M({queryKey:["usage","sessions",s],queryFn:()=>$.sessions(s),staleTime:60*1e3})}function ms(){const[s,t]=f.useState({from:q(new Date,30),to:new Date}),[a,n]=f.useState(!1),[l,o]=f.useState(null),[c,r]=f.useState(null),[i,x]=f.useState("daily"),m=ds(),p=f.useCallback(async()=>{n(!0);try{await m()}finally{n(!1)}},[m]),g=f.useMemo(()=>({startDate:s?.from,endDate:s?.to}),[s?.from,s?.to]),{data:k,isLoading:w}=ls(g),{data:d,isLoading:h}=os(g),{data:N,isLoading:v}=is(g),{data:y,isLoading:I}=cs(g),{data:Y,isLoading:H}=xs({...g,limit:3}),{data:O}=us(),fe=f.useCallback(()=>{const A=new Date;t({from:q(A,1),to:A}),x("hourly")},[]),pe=f.useCallback(A=>{t(A),x("daily")},[]),ge=f.useMemo(()=>O?.lastFetch?ee(new Date(O.lastFetch),{addSuffix:!0}):null,[O?.lastFetch]),ye=f.useCallback((A,Ne)=>{const _=Ne.currentTarget.getBoundingClientRect();r({x:_.left+_.width/2,y:_.top+_.height/2}),o(A)},[]),je=f.useCallback(()=>{o(null),r(null)},[]);return{dateRange:s,isRefreshing:a,viewMode:i,selectedModel:l,popoverPosition:c,summary:k,trends:d,hourlyData:N,models:y,sessions:Y,status:O,isSummaryLoading:w,isTrendsLoading:h,isHourlyLoading:v,isModelsLoading:I,isSessionsLoading:H,isLoading:w||h||I||H,handleRefresh:p,handleTodayClick:fe,handleDateRangeChange:pe,handleModelClick:ye,handlePopoverClose:je,lastUpdatedText:ge}}function hs({value:s,onChange:t,presets:a=[{label:"Last 7 days",range:{from:q(new Date,7),to:new Date}},{label:"Last 30 days",range:{from:q(new Date,30),to:new Date}},{label:"Last 90 days",range:{from:q(new Date,90),to:new Date}}],className:n}){const[l,o]=we.useState(!1),c=r=>!s||!s.from||!s.to||!r.from||!r.to?!1:L(s.from,"yyyy-MM-dd")===L(r.from,"yyyy-MM-dd")&&L(s.to,"yyyy-MM-dd")===L(r.to,"yyyy-MM-dd");return e.jsxs("div",{className:u("flex flex-wrap items-center gap-2",n),children:[a.map(r=>e.jsx(B,{variant:c(r.range)?"default":"outline",size:"sm",onClick:()=>t(r.range),children:r.label},r.label)),e.jsxs(le,{open:l,onOpenChange:o,children:[e.jsx(ve,{asChild:!0,children:e.jsxs(B,{id:"date",variant:"outline",className:u("w-auto min-w-[200px] sm:min-w-[240px] justify-start text-left font-normal",!s&&"text-muted-foreground"),children:[e.jsx(J,{className:"mr-2 h-4 w-4"}),s?.from?s.to?e.jsxs(e.Fragment,{children:[L(s.from,"LLL dd, y")," - ",L(s.to,"LLL dd, y")]}):L(s.from,"LLL dd, y"):e.jsx("span",{children:"Pick a date"})]})}),e.jsx(oe,{className:"w-auto p-0",align:"end",children:e.jsx(be,{initialFocus:!0,mode:"range",defaultMonth:s?.from,selected:s,onSelect:t,numberOfMonths:2})})]})]})}function fs(){const s=z();return se({mutationFn:t=>$.cursorImport(t),onSuccess:()=>{s.invalidateQueries({queryKey:["usage"]}),s.invalidateQueries({queryKey:["cursor-status"]})}})}function ps(){return M({queryKey:["cursor-status"],queryFn:()=>$.cursorStatus(),staleTime:30*1e3})}function gs(){const s=z();return se({mutationFn:()=>$.cursorDataClear(),onSuccess:()=>{s.invalidateQueries({queryKey:["usage"]}),s.invalidateQueries({queryKey:["cursor-status"]})}})}function ys(){const{t:s}=F(),{privacyMode:t}=P(),a=f.useRef(null),[n,l]=f.useState(!1),[o,c]=f.useState(null),r=fs(),{data:i,isLoading:x}=ps(),m=gs(),p=async d=>{const h=d.target.files?.[0];if(h){c(null);try{await r.mutateAsync(h)}catch(N){c(N instanceof Error?N.message:s("analyticsCursor.errorMessage"))}a.current&&(a.current.value="")}},g=async()=>{if(window.confirm(s("analyticsCursor.clearConfirm")))try{await m.mutateAsync()}catch{c(s("analyticsCursor.errorMessage"))}},k=d=>d>=1e6?`${(d/1e6).toFixed(1)}M`:d.toLocaleString(),w=d=>!d||d.length<8?d:`${d.slice(0,4)}-${d.slice(4,6)}-${d.slice(6,8)}`;return e.jsxs(ke,{open:n,onOpenChange:l,children:[e.jsx(Ce,{asChild:!0,children:e.jsxs(B,{variant:"outline",size:"sm",className:"gap-2 h-8",children:[e.jsx(E,{className:"w-3.5 h-3.5"}),e.jsx("span",{className:"hidden sm:inline",children:s("analytics.importData")})]})}),e.jsxs(De,{className:"sm:max-w-md",children:[e.jsxs(Se,{children:[e.jsxs(Me,{className:"flex items-center gap-2",children:[e.jsx(E,{className:"w-4 h-4"}),s("analytics.importData")]}),e.jsx(Te,{children:s("analyticsCursor.fileHint")})]}),e.jsx("div",{className:"space-y-4",children:e.jsxs("div",{className:"space-y-3",children:[e.jsxs("div",{className:"flex items-center gap-2 text-sm font-medium",children:[e.jsx(ce,{className:"w-4 h-4"}),"Cursor IDE"]}),e.jsx("input",{ref:a,type:"file",accept:".csv",className:"hidden",onChange:p}),e.jsx(B,{variant:"outline",size:"sm",className:"w-full",disabled:r.isPending,onClick:()=>a.current?.click(),children:r.isPending?e.jsxs(e.Fragment,{children:[e.jsx(Pe,{className:"w-3.5 h-3.5 mr-2 animate-spin"}),s("analyticsCursor.importing")]}):e.jsxs(e.Fragment,{children:[e.jsx(Be,{className:"w-3.5 h-3.5 mr-2"}),s("analyticsCursor.importButton")]})}),r.isSuccess&&e.jsxs("div",{className:"flex items-center gap-1.5 text-xs text-green-600",children:[e.jsx(qe,{className:"w-3.5 h-3.5 shrink-0"}),e.jsx("span",{children:s("analyticsCursor.successMessage")})]}),o&&e.jsxs("div",{className:"flex items-center gap-1.5 text-xs text-destructive",children:[e.jsx(Ae,{className:"w-3.5 h-3.5 shrink-0"}),e.jsx("span",{className:"truncate",children:o})]}),x?null:i?.hasData?e.jsxs("div",{className:"rounded-md border bg-muted/30 p-3 text-xs space-y-1.5",children:[i.dateRange&&e.jsxs("div",{className:"text-muted-foreground",children:[w(i.dateRange.from)," ~ ",w(i.dateRange.to)]}),e.jsxs("div",{className:u(t&&b),children:[k(i.totalTokens)," tokens · ",i.totalEvents," events"]}),i.models.length>0&&e.jsx("div",{className:"text-muted-foreground truncate",children:i.models.join(", ")})]}):e.jsx("p",{className:"text-xs text-muted-foreground",children:s("analyticsCursor.fileHint")}),i?.hasData&&e.jsxs(B,{variant:"ghost",size:"sm",className:"w-full text-xs text-muted-foreground hover:text-destructive",disabled:m.isPending,onClick:g,children:[e.jsx(Ke,{className:"w-3 h-3 mr-1"}),s("analyticsCursor.clearButton")]})]})})]})]})}function js({dateRange:s,onDateRangeChange:t,onTodayClick:a,onRefresh:n,isRefreshing:l,lastUpdatedText:o,viewMode:c}){const{t:r}=F();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:r("analytics.title")}),e.jsx("p",{className:"text-sm text-muted-foreground",children:r("analytics.subtitle")})]}),e.jsxs("div",{className:"flex flex-wrap items-center gap-2 xl:justify-end",children:[e.jsx(B,{variant:c==="hourly"?"default":"outline",size:"sm",className:"h-8",onClick:a,children:"24H"}),e.jsx(hs,{className:"flex-wrap",value:s,onChange:t,presets:[{label:"7D",range:{from:q(new Date,7),to:new Date}},{label:"30D",range:{from:q(new Date,30),to:new Date}},{label:r("analytics.month"),range:{from:Ge(new Date),to:new Date}},{label:r("analytics.allTime"),range:{from:void 0,to:new Date}}]}),o&&e.jsx("span",{className:"text-xs text-muted-foreground whitespace-nowrap",children:r("analytics.updated",{value:o})}),e.jsx(B,{variant:"outline",size:"sm",className:"gap-2 h-8",onClick:n,disabled:l,children:e.jsx(Ue,{className:`w-3.5 h-3.5 ${l?"animate-spin":""}`})}),e.jsx(ys,{})]})]})}function Ns({data:s,isLoading:t,granularity:a="daily",className:n}){const{privacyMode:l}=P(),o=f.useMemo(()=>!s||s.length===0?[]:s.map(i=>{const x="hour"in i?i.hour:i.date;return{...i,dateFormatted:ws(x,a),costRounded:Number(i.cost.toFixed(4))}}),[s,a]);if(t)return e.jsx(j,{className:u("h-full w-full",n)});if(!s||s.length===0)return e.jsx("div",{className:u("h-full flex items-center justify-center",n),children:e.jsx("p",{className:"text-muted-foreground",children:a==="hourly"?"No usage data for today":"No usage data available"})});const c=({x:r,y:i,payload:x,isRight:m})=>{const p=m?`$${x.value}`:re(Number(x.value));return e.jsx("text",{x:r,y:i,dy:4,textAnchor:m?"start":"end",fontSize:12,fill:"currentColor",className:u("fill-muted-foreground",l&&"blur-[4px]"),children:p})};return e.jsx("div",{className:u("w-full h-full",n),children:e.jsx(me,{width:"100%",height:"100%",children:e.jsxs(ze,{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(Ye,{strokeDasharray:"3 3",className:"stroke-muted"}),e.jsx(Ve,{dataKey:"dateFormatted",tick:{fontSize:12},tickLine:!1,axisLine:{className:"stroke-muted"}}),e.jsx(ae,{yAxisId:"left",orientation:"left",tick:r=>e.jsx(c,{...r,isRight:!1}),tickLine:!1,axisLine:{className:"stroke-muted"}}),e.jsx(ae,{yAxisId:"right",orientation:"right",tick:r=>e.jsx(c,{...r,isRight:!0}),tickLine:!1,axisLine:{className:"stroke-muted"}}),e.jsx(he,{content:({active:r,payload:i,label:x})=>{if(!r||!i||!i.length)return null;const m=i[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}),i.map((p,g)=>e.jsxs("p",{className:u("text-sm",l&&b),style:{color:p.color},children:[p.name,":"," ",p.name==="Tokens"?re(Number(p.value)||0):`$${p.value}`]},g)),"requests"in m&&e.jsxs("p",{className:u("text-sm text-muted-foreground mt-1",l&&b),children:["Requests: ",m.requests]})]})}}),e.jsx(ne,{yAxisId:"left",type:"monotone",dataKey:"tokens",stroke:"#0080FF",strokeWidth:2,fillOpacity:1,fill:"url(#tokenGradient)",name:"Tokens"}),e.jsx(ne,{yAxisId:"right",type:"monotone",dataKey:"costRounded",stroke:"#00C49F",strokeWidth:2,fillOpacity:1,fill:"url(#costGradient)",name:"Cost"})]})})})}function ws(s,t){if(t==="hourly"){const[n,l]=s.split(" ");if(n&&l){const o=new Date(`${n}T${l}:00Z`);return L(o,"HH:mm")}return s}const a=new Date(s);return t==="monthly"?L(a,"MMM yyyy"):L(a,"MMM dd")}function re(s){return s>=1e6?`${(s/1e6).toFixed(1)}M`:s>=1e3?`${(s/1e3).toFixed(1)}K`:s.toLocaleString()}function vs({data:s,isLoading:t,className:a}){const{privacyMode:n}=P(),{t:l}=F(),o=f.useMemo(()=>!s||s.length===0?[]:s.map(i=>({name:i.model,value:i.tokens,cost:i.cost,percentage:i.percentage,fill:ie(i.model)})),[s]);if(t)return e.jsx(j,{className:u("h-full min-h-[100px] w-full",a)});if(!s||s.length===0)return e.jsx("div",{className:u("h-full min-h-[100px] flex items-center justify-center",a),children:e.jsx("p",{className:"text-muted-foreground",children:l("analyticsModel.emptyState")})});const c=({active:i,payload:x})=>{if(!i||!x)return null;const m=x;if(!m.length)return null;const p=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:p.name}),e.jsxs("p",{className:u("text-muted-foreground",n&&b),children:[bs(p.value)," (",p.percentage.toFixed(1),"%)"]}),e.jsxs("p",{className:u("text-muted-foreground",n&&b),children:["$",p.cost.toFixed(4)]})]})},r=i=>i.percentage>5?`${i.percentage.toFixed(1)}%`:"";return e.jsx("div",{className:u("w-full h-full min-h-[100px]",a),children:e.jsx(me,{width:"100%",height:"100%",children:e.jsxs(Ze,{children:[e.jsx(Xe,{data:o,cx:"50%",cy:"50%",labelLine:!1,label:r,innerRadius:50,outerRadius:70,paddingAngle:2,dataKey:"value",children:o.map((i,x)=>e.jsx(Je,{fill:i.fill,strokeWidth:1},`cell-${x}`))}),e.jsx(he,{content:c})]})})})}function bs(s){return s>=1e6?`${(s/1e6).toFixed(1)}M`:s>=1e3?`${(s/1e3).toFixed(1)}K`:s.toLocaleString()}function ks(s){if(!s)return"";const a=s.replace(/^\/|\/$/g,"").split("/").filter(n=>n.length>0);return a[a.length-1]||""}function Cs({data:s,isLoading:t,className:a}){const{privacyMode:n}=P(),{t:l}=F(),o=f.useMemo(()=>{if(!s?.sessions||s.sessions.length===0)return null;const c=s.sessions,r=s.total,i=c.reduce((w,d)=>w+(d.inputTokens+d.outputTokens),0),x=Math.round(i/c.length),p=c.reduce((w,d)=>w+d.cost,0)/c.length,g=c[0],k=g?ee(new Date(g.lastActivity),{addSuffix:!0}):"N/A";return{totalSessions:r,avgTokens:x,avgCost:p,lastActive:k,recentSessions:c.slice(0,3)}},[s]);return t?e.jsxs(C,{className:u("flex flex-col h-full min-h-0 overflow-hidden gap-0 py-0",a),children:[e.jsx(T,{className:"px-3 py-2",children:e.jsx(j,{className:"h-5 w-32"})}),e.jsx(D,{className:"px-3 pb-3 pt-0 flex-1",children:e.jsx(j,{className:"h-full w-full"})})]}):o?e.jsxs(C,{className:u("flex flex-col h-full min-h-0 overflow-hidden gap-0 py-0 shadow-sm",a),children:[e.jsx(T,{className:"px-3 py-2",children:e.jsxs(U,{className:"text-base font-semibold flex items-center gap-2",children:[e.jsx(te,{className:"w-4 h-4"}),l("analyticsSession.title")]})}),e.jsxs(D,{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(Ie,{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:l("analyticsSession.totalSessions")})]}),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(Ee,{className:"w-4 h-4"}),e.jsxs("span",{className:u("text-xl font-bold",n&&b),children:["$",o.avgCost.toFixed(2)]})]}),e.jsx("p",{className:"text-[10px] text-muted-foreground uppercase tracking-wider mt-0.5",children:l("analyticsSession.avgCostPerSession")})]})]}),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(He,{className:"w-3 h-3"}),l("analyticsSession.recentActivity")]}),e.jsx("div",{className:"space-y-1.5 max-h-full overflow-y-auto pr-1",children:o.recentSessions.map(c=>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:c.projectPath,children:ks(c.projectPath)}),(c.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:c.target})]}),e.jsx("span",{className:"text-[10px] text-muted-foreground",children:ee(new Date(c.lastActivity),{addSuffix:!0})})]}),e.jsxs("div",{className:u("text-right shrink-0 ml-2",n&&b),children:[e.jsxs("div",{className:"font-mono",children:["$",c.cost.toFixed(2)]}),e.jsxs("div",{className:"text-[10px] text-muted-foreground",children:[Ds(c.inputTokens+c.outputTokens)," toks"]})]})]},c.sessionId))})]})]})]}):e.jsxs(C,{className:u("flex flex-col h-full min-h-0 overflow-hidden gap-0 py-0",a),children:[e.jsx(T,{className:"px-3 py-2",children:e.jsxs(U,{className:"text-base font-semibold flex items-center gap-2",children:[e.jsx(te,{className:"w-4 h-4"}),l("analyticsSession.title")]})}),e.jsx(D,{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:l("analyticsSession.emptyState")})})]})}function Ds(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()}async function X(s,t){try{const a=new URLSearchParams,n=r=>{const i=r.getFullYear(),x=String(r.getMonth()+1).padStart(2,"0"),m=String(r.getDate()).padStart(2,"0");return`${i}${x}${m}`};a.append("since",n(s)),a.append("until",n(t));const l=await fetch(`/api/usage/summary?${a}`,{headers:{"Content-Type":"application/json"}});if(!l.ok)return 0;const o=await l.json();return(o.data||o).totalCost||0}catch{return 0}}function Ss(){const s=new Date;return new Date(s.getFullYear(),s.getMonth()+1,0).getDate()}function Ms(){return new Date().getDate()}function Ts(s,t){return t<=0?"N/A":`${(s/t).toFixed(2)}x`}function Fs(s,t){return t<=0?null:s/t}function Ls(){const s=z(),t=M({queryKey:["cost-leverage-config"],queryFn:async()=>{const N=(await Z.config.get()).preferences?.baseline_cost_30d;return typeof N=="number"?N:void 0},staleTime:30*1e3}),a=t.data,n=f.useMemo(()=>new Date,[]),l=f.useMemo(()=>{const d=new Date(n),h=new Date(n);return h.setDate(h.getDate()-6),{start:h,end:d}},[n]),o=f.useMemo(()=>{const d=new Date(n),h=new Date(n);return h.setDate(h.getDate()-29),{start:h,end:d}},[n]),c=f.useMemo(()=>{const d=new Date(n.getFullYear(),n.getMonth(),1),h=new Date(n);return{start:d,end:h}},[n]),r=M({queryKey:["cost-leverage","7d"],queryFn:()=>X(l.start,l.end),staleTime:60*1e3}),i=M({queryKey:["cost-leverage","30d"],queryFn:()=>X(o.start,o.end),staleTime:60*1e3}),x=M({queryKey:["cost-leverage","month"],queryFn:()=>X(c.start,c.end),staleTime:60*1e3}),m=se({mutationFn:async d=>{const h=await Z.config.get(),v={...h.preferences||{}};d==null?delete v.baseline_cost_30d:v.baseline_cost_30d=d;const y=typeof h.version=="number"?h.version:12;return Z.config.update({version:y,preferences:v})},onSuccess:()=>{s.invalidateQueries({queryKey:["cost-leverage-config"]})}}),p=f.useMemo(()=>{const d=Ms(),h=Ss();return[{label:"7d",cost:r.data??0,windowDays:7,scaleDays:7},{label:"30d",cost:i.data??0,windowDays:30,scaleDays:30},{label:"Month",cost:x.data??0,windowDays:d,scaleDays:h}].map(v=>{const y=a?a*v.scaleDays/30:0;return{label:v.label,estimatedCost:v.cost,scaledBaseline:y,ratio:Fs(v.cost,y),ratioDisplay:Ts(v.cost,y),windowDays:v.windowDays}})},[a,r.data,i.data,x.data]),g=f.useCallback(d=>{const h=d.trim();if(h==="")return m.mutate(void 0),{valid:!0};const N=Number(h);return isNaN(N)||N<=0?{valid:!1,error:"invalid"}:(m.mutate(N),{valid:!0})},[m]),k=t.isLoading||r.isLoading&&i.isLoading&&x.isLoading,w=t.error?.message||m.error?.message||null;return{baselineCost:a,windows:p,isLoading:k,isSaving:m.isPending,error:w,saveBaseline:g,cost7d:r.data,cost30d:i.data,costMonth:x.data}}function $s({className:s,isLoading:t}){const{privacyMode:a}=P(),{t:n}=F(),{baselineCost:l,windows:o,isLoading:c,isSaving:r,error:i,saveBaseline:x}=Ls(),[m,p]=f.useState(l!==void 0?String(l):""),[g,k]=f.useState(null),[w,d]=f.useState(!1);l!==void 0&&!w&&(p(String(l)),d(!0)),l===void 0&&w&&d(!1);const h=f.useCallback(()=>{x(m).valid?(k(null),m.trim()===""&&(p(""),d(!1))):k(n("analyticsCostLeverage.invalidInput"))},[m,x,n]),N=f.useCallback(y=>{y.key==="Enter"&&(y.preventDefault(),h())},[h]),v=l!==void 0&&l>0;return c||t?e.jsxs(C,{className:u("flex flex-col h-full",s),children:[e.jsx(T,{className:"px-3 py-2",children:e.jsx(j,{className:"h-5 w-36"})}),e.jsx(D,{className:"px-3 pb-3 pt-0 flex-1",children:e.jsx(j,{className:"h-full w-full"})})]}):e.jsxs(C,{className:u("flex flex-col h-full min-h-0 overflow-hidden gap-0 py-0 shadow-sm",s),children:[e.jsx(T,{className:"px-3 py-2 shrink-0",children:e.jsxs(U,{className:"text-base font-semibold flex items-center gap-2",children:[e.jsx(Oe,{className:"w-4 h-4"}),n("analyticsCostLeverage.title")]})}),e.jsxs(D,{className:"px-3 pb-3 pt-0 flex-1 min-h-0 flex flex-col gap-2",children:[v?e.jsx("div",{className:"flex-1 flex flex-col gap-2 justify-center min-h-0",children:o.map(y=>e.jsx(Rs,{window:y,privacyMode:a,t:n},y.label))}):e.jsxs("div",{className:"flex-1 flex flex-col items-center justify-center gap-2",children:[e.jsx("div",{className:"w-10 h-10 rounded-full bg-muted/50 flex items-center justify-center",children:e.jsx(G,{className:"w-5 h-5 text-muted-foreground"})}),e.jsx("p",{className:"text-xs text-muted-foreground text-center leading-relaxed max-w-[180px]",children:n("analyticsCostLeverage.noBaseline")})]}),e.jsxs("div",{className:"shrink-0 pt-2 mt-auto border-t",children:[e.jsxs("div",{className:"flex items-center gap-2",children:[e.jsx(G,{className:"w-3.5 h-3.5 text-muted-foreground shrink-0"}),e.jsx(Fe,{type:"text",inputMode:"decimal",value:m,onChange:y=>{p(y.target.value),k(null)},onBlur:h,onKeyDown:N,placeholder:n("analyticsCostLeverage.baselinePlaceholder"),disabled:r,className:u("h-7 text-xs",g&&"border-destructive focus-visible:ring-destructive")}),r&&e.jsx("span",{className:"text-[10px] text-muted-foreground animate-pulse",children:n("analyticsCostLeverage.saving")})]}),g&&e.jsx("p",{className:"text-[10px] text-destructive mt-1",children:g}),i&&e.jsxs("p",{className:"text-[10px] text-destructive mt-1",children:[n("analyticsCostLeverage.saveError"),": ",i]})]})]})]})}function Rs({window:s,privacyMode:t,t:a}){const n=s.label==="7d"?"analyticsCostLeverage.window7d":s.label==="30d"?"analyticsCostLeverage.window30d":"analyticsCostLeverage.windowMonth",l=s.label==="7d"?J:s.label==="30d"?_e:J,o=s.ratio===null?"text-muted-foreground":s.ratio<2.5?"text-red-600 dark:text-red-400":s.ratio<10?"text-amber-600 dark:text-amber-400":"text-emerald-600 dark:text-emerald-400",c=s.ratio===null?"bg-muted/30":s.ratio<2.5?"bg-red-100/30 dark:bg-red-950/30":s.ratio<10?"bg-amber-100/30 dark:bg-amber-950/30":"bg-emerald-100/30 dark:bg-emerald-950/30";return e.jsxs("div",{className:u("flex items-center gap-2 px-2.5 py-2 rounded-lg border transition-colors",c),children:[e.jsxs("div",{className:"flex items-center gap-1.5 shrink-0",children:[e.jsx(l,{className:"w-3.5 h-3.5 text-muted-foreground"}),e.jsx("span",{className:"text-xs text-muted-foreground font-medium",children:a(n)})]}),e.jsxs("span",{className:u("text-xs text-muted-foreground font-mono",t&&b),children:["$",s.estimatedCost.toFixed(2)]}),e.jsx("div",{className:"flex-1 border-t border-dashed border-muted-foreground/30"}),e.jsxs("div",{className:"flex items-center gap-1 shrink-0",children:[s.ratio!==null&&s.ratio>=10&&e.jsx(xe,{className:"w-3.5 h-3.5 text-emerald-500"}),e.jsx("span",{className:u("text-lg font-bold tabular-nums min-w-[56px] text-right",o,t&&b),children:s.ratioDisplay})]})]})}function W(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 Ps({models:s,isLoading:t,onModelClick:a,privacyMode:n}){const{t:l}=F();return e.jsxs(C,{className:"flex flex-col h-full min-h-0 overflow-hidden gap-0 py-0 shadow-sm lg:col-span-4",children:[e.jsx(T,{className:"px-3 py-2",children:e.jsxs(U,{className:"text-base font-semibold flex items-center gap-2",children:[e.jsx(G,{className:"w-4 h-4"}),l("analyticsCostModel.title")]})}),e.jsx(D,{className:"px-2 pb-2 pt-0 flex-1 min-h-0 overflow-y-auto",children:t?e.jsx(j,{className:"h-full w-full"}):e.jsxs("div",{className:"space-y-0.5",children:[[...s||[]].sort((o,c)=>c.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:c=>a(o,c),title:l("analyticsCostModel.clickForDetails"),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:ie(o.model)}}),e.jsx("span",{className:"font-medium truncate group-hover:underline underline-offset-2",children:o.model})]}),e.jsx(Bs,{model:o}),e.jsxs("span",{className:u("text-[10px] text-muted-foreground w-[72px] text-right shrink-0 font-mono",n&&b),title:`${W(o.tokens)} / ${W(o.tokens+o.cacheTokens)}`,children:[W(o.tokens),e.jsx("span",{className:"text-muted-foreground/50",children:"/"}),W(o.tokens+o.cacheTokens)]}),e.jsxs("span",{className:u("font-mono font-medium w-16 text-right shrink-0",n&&b),children:["$",o.cost.toFixed(2)]}),e.jsx(Qe,{className:"w-3 h-3 opacity-0 group-hover:opacity-50 transition-opacity shrink-0"})]},o.model)),e.jsx(qs,{})]})})]})}function Bs({model:s}){const{t}=F(),a={input:"#335c67",output:"#fff3b0",cacheWrite:"#e09f3e",cacheRead:"#9e2a2b"},n=l=>s.cost>0?l/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:a.input,width:`${n(s.costBreakdown.input.cost)}%`},title:`${t("analyticsToken.input")}: $${s.costBreakdown.input.cost.toFixed(2)}`}),e.jsx("div",{className:"h-full",style:{backgroundColor:a.output,width:`${n(s.costBreakdown.output.cost)}%`},title:`${t("analyticsToken.output")}: $${s.costBreakdown.output.cost.toFixed(2)}`}),e.jsx("div",{className:"h-full",style:{backgroundColor:a.cacheWrite,width:`${n(s.costBreakdown.cacheCreation.cost)}%`},title:`${t("analyticsToken.cacheWrite")}: $${s.costBreakdown.cacheCreation.cost.toFixed(2)}`}),e.jsx("div",{className:"h-full",style:{backgroundColor:a.cacheRead,width:`${n(s.costBreakdown.cacheRead.cost)}%`},title:`${t("analyticsToken.cacheRead")}: $${s.costBreakdown.cacheRead.cost.toFixed(2)}`})]})})}function qs(){const{t:s}=F(),t=[{color:"#335c67",label:s("analyticsToken.input")},{color:"#fff3b0",label:s("analyticsToken.output"),hasBorder:!0},{color:"#e09f3e",label:s("analyticsToken.cacheWrite")},{color:"#9e2a2b",label:s("analyticsToken.cacheRead")}];return e.jsx("div",{className:"flex items-center gap-3 pt-2 px-2 text-[10px] text-muted-foreground border-t mt-2",children:t.map(({color:a,label:n,hasBorder:l})=>e.jsxs("span",{className:"flex items-center gap-1",children:[e.jsx("div",{className:u("w-2 h-2 rounded-full",l&&"border border-muted-foreground/30"),style:{backgroundColor:a}}),n]},n))})}function As({viewMode:s,trends:t,hourlyData:a,models:n,sessions:l,isTrendsLoading:o,isHourlyLoading:c,isModelsLoading:r,isSessionsLoading:i,isSummaryLoading:x,onModelClick:m}){const{privacyMode:p}=P(),{t:g}=F();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(C,{className:"flex flex-col h-full min-h-[220px] lg:min-h-[240px] overflow-hidden gap-0 py-0 shadow-sm",children:[e.jsx(T,{className:"px-3 py-2 shrink-0",children:e.jsxs(U,{className:"text-base font-semibold flex items-center gap-2",children:[e.jsx(xe,{className:"w-4 h-4"}),g(s==="hourly"?"analytics.last24Hours":"analytics.usageTrends")]})}),e.jsx(D,{className:"px-3 pb-3 pt-0 flex-1 min-h-0",children:e.jsx(Ns,{data:s==="hourly"?a||[]:t||[],isLoading:s==="hourly"?c: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(Ps,{models:n,isLoading:r,onModelClick:m,privacyMode:p}),e.jsxs(C,{className:"flex flex-col h-full min-h-0 overflow-hidden gap-0 py-0 shadow-sm lg:col-span-2",children:[e.jsx(T,{className:"px-3 py-2",children:e.jsxs(U,{className:"text-base font-semibold flex items-center gap-2",children:[e.jsx(We,{className:"w-4 h-4"}),g("analytics.modelUsage")]})}),e.jsx(D,{className:"px-2 pb-2 pt-0 flex-1 min-h-0 flex items-center justify-center",children:e.jsx(vs,{data:n||[],isLoading:r,className:"h-full w-full"})})]}),e.jsx(Cs,{data:l,isLoading:i,className:"lg:col-span-2"}),e.jsx($s,{className:"lg:col-span-2"})]})]})}function zs(){return e.jsxs("div",{className:"space-y-4 h-full overflow-hidden",children:[e.jsxs(C,{className:"flex flex-col min-h-[300px]",children:[e.jsx(T,{className:"p-4 pb-2",children:e.jsx(j,{className:"h-4 w-32"})}),e.jsx(D,{className:"p-4 pt-0 flex-1",children:e.jsx(j,{className:"h-full w-full"})})]}),e.jsxs("div",{className:"grid grid-cols-1 lg:grid-cols-2 gap-4",children:[e.jsxs(C,{className:"flex flex-col min-h-[250px]",children:[e.jsx(T,{className:"p-4 pb-2",children:e.jsx(j,{className:"h-4 w-28"})}),e.jsx(D,{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(j,{className:"w-2.5 h-2.5 rounded-full"}),e.jsx(j,{className:"h-3 w-24"})]}),e.jsx(j,{className:"h-3 w-16"})]},s))})})]}),e.jsxs(C,{className:"flex flex-col min-h-[250px]",children:[e.jsx(T,{className:"p-4 pb-2",children:e.jsx(j,{className:"h-4 w-28"})}),e.jsx(D,{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(j,{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(j,{className:"w-2 h-2 rounded-full"}),e.jsx(j,{className:"h-3 w-20"})]},s))})]})})]})]})]})}function Ys(){const s=f.useRef(null),{dateRange:t,handleDateRangeChange:a,handleTodayClick:n,handleRefresh:l,isRefreshing:o,lastUpdatedText:c,viewMode:r,summary:i,isSummaryLoading:x,trends:m,hourlyData:p,models:g,sessions:k,isTrendsLoading:w,isHourlyLoading:d,isModelsLoading:h,isSessionsLoading:N,handleModelClick:v,selectedModel:y,popoverPosition:I,handlePopoverClose:Y}=ms();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(js,{dateRange:t,onDateRangeChange:a,onTodayClick:n,onRefresh:l,isRefreshing:o,lastUpdatedText:c,viewMode:r}),e.jsx(es,{data:i,isLoading:x}),e.jsx(As,{viewMode:r,trends:m,hourlyData:p,models:g,sessions:k,isTrendsLoading:w,isHourlyLoading:d,isModelsLoading:h,isSessionsLoading:N,isSummaryLoading:x,onModelClick:v}),e.jsxs(le,{open:!!y,onOpenChange:H=>!H&&Y(),children:[e.jsx(Le,{asChild:!0,children:e.jsx("div",{ref:s,className:"fixed pointer-events-none",style:{left:I?.x??0,top:I?.y??0,width:1,height:1}})}),e.jsx(oe,{className:"w-80 p-3",side:"top",align:"center",children:y&&e.jsx(ss,{model:y})})]})]})}export{Ys as AnalyticsPage,zs as AnalyticsSkeleton};
@@ -1 +1 @@
1
- import{j as e}from"./radix-ui-BlliRfHq.js";import{r as n}from"./react-vendor-CNOkPC89.js";import{bj as Oe,bk as He,q as L,a as ae,I as B,az as D,v as Ve,w as ze,x as Ue,y as We,z as ue,d as V,bl as Ge,bm as Ye,bn as qe,b5 as se,b7 as te,A as Je}from"./index-TSYtCr3K.js";import{C as z}from"./default-ports-1QQSffYX.js";import{b1 as he,R as re,g as Xe,v as fe,W as Qe,u as Ze,b2 as es,b3 as ss,T as ye,ay as ts,n as rs,b4 as as}from"./icons-CQ3MLSan.js";import{P as os}from"./proxy-status-widget-DPhKjJFl.js";import{R as H}from"./antigravity-responsibility-constants-Bvh4Ybz0.js";import{t as T}from"./notifications-B2HqRBj7.js";import"./tanstack-BjiH4QZq.js";import"./utils-CzKF5WmX.js";import"./form-utils-Bcoyqxpq.js";import"./code-highlight-BRUf_pqB.js";import"./alert-dialog-DQK2Jxfk.js";function ns(){const{state:s}=Oe(),t=He(),[g,o]=n.useState(null),[u,b]=n.useState(null),[y,j]=n.useState(null),[p,C]=n.useState(null),[S,P]=n.useState(null),w=n.useCallback(async()=>{try{t.setProxyLoading(!0),t.setProxyError(null);const d=await L.cliproxyServer.get();t.setProxyConfig(d)}catch(d){t.setProxyError(d.message)}finally{t.setProxyLoading(!1)}},[t]),A=n.useCallback(async d=>{const x=s.proxyConfig;if(!x)return;const h={remote:{...x.remote,...d.remote},fallback:{...x.fallback,...d.fallback},local:{...x.local,...d.local}};t.setProxyConfig(h),t.setProxyTestResult(null);try{t.setProxySaving(!0),t.setProxyError(null);const a=await L.cliproxyServer.update(d);t.setProxyConfig(a),t.setProxySuccess(!0),setTimeout(()=>t.setProxySuccess(!1),1500)}catch(a){t.setProxyConfig(x),t.setProxyError(a.message)}finally{t.setProxySaving(!1)}},[s.proxyConfig,t]),E=n.useCallback(async d=>{const{host:x,port:h,protocol:a,authToken:c}=d;if(!x){t.setProxyError("Host is required");return}try{t.setProxyTesting(!0),t.setProxyError(null),t.setProxyTestResult(null);const k=h?parseInt(h,10):void 0,l=await L.cliproxyServer.test({host:x,port:k||void 0,protocol:a,authToken:c||void 0});t.setProxyTestResult(l)}catch(k){t.setProxyError(k.message)}finally{t.setProxyTesting(!1)}},[t]);return{config:s.proxyConfig,loading:s.proxyLoading,saving:s.proxySaving,error:s.proxyError,success:s.proxySuccess,testResult:s.proxyTestResult,testing:s.proxyTesting,editedHost:g,setEditedHost:o,editedPort:u,setEditedPort:b,editedAuthToken:y,setEditedAuthToken:j,editedManagementKey:p,setEditedManagementKey:C,editedLocalPort:S,setEditedLocalPort:P,fetchConfig:w,saveConfig:A,testConnection:E}}function is({config:s,saving:t,displayLocalPort:g,setEditedLocalPort:o,onSaveLocalPort:u,onSaveConfig:b}){const{t:y}=ae(),j=s.local;return e.jsxs("div",{className:"space-y-3",children:[e.jsx("h3",{className:"text-base font-medium",children:y("settingsProxy.localProxy")}),e.jsxs("div",{className:"space-y-3 p-4 rounded-lg border bg-muted/30",children:[e.jsxs("div",{className:"flex items-center gap-2",children:[e.jsx("label",{className:"text-sm text-muted-foreground",children:y("settingsProxy.port")}),e.jsx(B,{type:"text",inputMode:"numeric",value:g,onChange:p=>o(p.target.value.replace(/\D/g,"")),onBlur:u,placeholder:`${z}`,className:"font-mono max-w-32",disabled:t})]}),e.jsxs("div",{className:"flex items-center justify-between",children:[e.jsxs("div",{children:[e.jsx("p",{className:"font-medium text-sm",children:y("settingsProxy.autoStart")}),e.jsx("p",{className:"text-xs text-muted-foreground",children:y("settingsProxy.localAutoStartDesc")})]}),e.jsx(D,{checked:j.auto_start??!0,onCheckedChange:p=>b({local:{...j,auto_start:p}}),disabled:t})]})]})]})}function ls({config:s,saving:t,testing:g,testResult:o,displayHost:u,displayPort:b,displayAuthToken:y,displayManagementKey:j,setEditedHost:p,setEditedPort:C,setEditedAuthToken:S,setEditedManagementKey:P,onSaveHost:w,onSavePort:A,onSaveAuthToken:E,onSaveManagementKey:d,onSaveConfig:x,onTestConnection:h}){const{t:a}=ae(),c=s.remote,k=l=>l==="https"?443:z;return e.jsxs("div",{className:"space-y-4 p-4 rounded-lg border bg-muted/30",children:[e.jsxs("h4",{className:"text-sm font-medium flex items-center gap-2",children:[e.jsx(he,{className:"w-4 h-4"}),a("settingsProxy.remoteConfigTitle")]}),e.jsxs("div",{className:"space-y-1",children:[e.jsx("label",{className:"text-sm text-muted-foreground",children:a("settingsProxy.host")}),e.jsx(B,{value:u,onChange:l=>p(l.target.value),onBlur:w,placeholder:a("settingsProxy.hostPlaceholder"),className:"font-mono",disabled:t})]}),e.jsxs("div",{className:"grid grid-cols-2 gap-3",children:[e.jsxs("div",{className:"space-y-1",children:[e.jsxs("label",{className:"text-sm text-muted-foreground",children:[a("settingsProxy.port")," ",e.jsxs("span",{className:"text-xs opacity-70",children:["(",a("settingsProxy.defaultPort",{value:k(s.remote.protocol||"http")}),")"]})]}),e.jsx(B,{type:"text",inputMode:"numeric",value:b,onChange:l=>C(l.target.value.replace(/\D/g,"")),onBlur:A,placeholder:a("settingsProxy.portPlaceholder",{value:k(s.remote.protocol||"http")}),className:"font-mono",disabled:t})]}),e.jsxs("div",{className:"space-y-1",children:[e.jsx("label",{className:"text-sm text-muted-foreground",children:a("settingsProxy.protocol")}),e.jsxs(Ve,{value:s.remote.protocol||"http",onValueChange:l=>x({remote:{...c,protocol:l}}),disabled:t,children:[e.jsx(ze,{children:e.jsx(Ue,{})}),e.jsxs(We,{children:[e.jsx(ue,{value:"http",children:a("settingsProxy.http")}),e.jsx(ue,{value:"https",children:a("settingsProxy.https")})]})]})]})]}),e.jsxs("div",{className:"space-y-1",children:[e.jsx("label",{className:"text-sm text-muted-foreground",children:a("settingsProxy.apiKeyOptional")}),e.jsx(B,{type:"password",value:y,onChange:l=>S(l.target.value),onBlur:E,placeholder:a("settingsProxy.apiKeyPlaceholder"),className:"font-mono",disabled:t}),e.jsx("p",{className:"text-xs text-muted-foreground",children:a("settingsProxy.apiKeyDesc")})]}),e.jsxs("div",{className:"space-y-1",children:[e.jsx("label",{className:"text-sm text-muted-foreground",children:a("settingsProxy.managementKeyOptional")}),e.jsx(B,{type:"password",value:j,onChange:l=>P(l.target.value),onBlur:d,placeholder:a("settingsProxy.managementKeyPlaceholder"),className:"font-mono",disabled:t}),e.jsx("p",{className:"text-xs text-muted-foreground",children:a("settingsProxy.managementKeyDesc")})]}),e.jsxs("div",{className:"space-y-3 pt-2",children:[e.jsx(V,{onClick:h,disabled:g||!u,variant:"outline",className:"w-full",children:g?e.jsxs(e.Fragment,{children:[e.jsx(re,{className:"w-4 h-4 mr-2 animate-spin"}),a("settingsProxy.testing")]}):e.jsxs(e.Fragment,{children:[e.jsx(Xe,{className:"w-4 h-4 mr-2"}),a("settingsProxy.testConnection")]})}),o&&e.jsx("div",{className:`p-3 rounded-md ${o.reachable?"bg-green-50 border border-green-200 dark:bg-green-900/20 dark:border-green-900/50":"bg-red-50 border border-red-200 dark:bg-red-900/20 dark:border-red-900/50"}`,children:e.jsx("div",{className:"flex items-center gap-2",children:o.reachable?e.jsxs(e.Fragment,{children:[e.jsx(fe,{className:"w-4 h-4 text-green-600 dark:text-green-400"}),e.jsx("span",{className:"text-sm font-medium text-green-700 dark:text-green-300",children:a("settingsProxy.connectedLatency",{value:o.latencyMs})})]}):e.jsxs(e.Fragment,{children:[e.jsx(Qe,{className:"w-4 h-4 text-red-600 dark:text-red-400"}),e.jsx("span",{className:"text-sm font-medium text-red-700 dark:text-red-300",children:o.error||a("settingsProxy.connectionFailed")})]})})})]})]})}const pe="ccs_debug_mode",cs=["kiro","ghcp"];function ds(s){return s.trim().replace(/\s+/g," ").toUpperCase()}function Cs(){const{t:s}=ae(),{config:t,loading:g,saving:o,error:u,success:b,testResult:y,testing:j,editedHost:p,setEditedHost:C,editedPort:S,setEditedPort:P,editedAuthToken:w,setEditedAuthToken:A,editedManagementKey:E,setEditedManagementKey:d,editedLocalPort:x,setEditedLocalPort:h,fetchConfig:a,saveConfig:c,testConnection:k}=ns(),{fetchRawConfig:l}=Ge(),[_,be]=n.useState(()=>{try{return localStorage.getItem(pe)==="true"}catch{return!1}}),[je,U]=n.useState(!1),[Pe,oe]=n.useState(!0),[f,ne]=n.useState(!1),[ke,R]=n.useState(!1),[ie,I]=n.useState(""),K=n.useRef(!1),W=ds(ie)===H,ve=r=>{be(r);try{localStorage.setItem(pe,String(r))}catch{}},G=n.useCallback(async()=>{try{oe(!0);const r=await fetch("/api/settings/auth/antigravity-risk");if(!r.ok)throw new Error(s("settingsProxy.failedLoadAgyMode"));const i=await r.json();U(i.antigravityAckBypass===!0)}catch(r){T.error(r instanceof Error?r.message:s("settingsProxy.failedLoadAgyMode")),U(!1)}finally{oe(!1)}},[s]),$=n.useCallback(async r=>{if(!(K.current||f||o))try{K.current=!0,ne(!0);const i=await fetch("/api/settings/auth/antigravity-risk",{method:"PUT",headers:{"Content-Type":"application/json"},body:JSON.stringify({antigravityAckBypass:r})}),O=await i.json();if(!i.ok)throw new Error(O.error||s("settingsProxy.failedUpdateAgyMode"));const Fe=O.antigravityAckBypass===!0,me=await fetch("/api/settings/auth/antigravity-risk",{cache:"no-store"});if(!me.ok)throw new Error(s("settingsProxy.failedVerifyAgyMode"));const ge=(await me.json()).antigravityAckBypass===!0;if(ge!==r)throw new Error(s("settingsProxy.notPersistedAgyMode"));U(ge&&Fe),R(!1),I(""),T.success(s(r?"settingsProxy.agyModeEnabled":"settingsProxy.agyModeDisabled")),await l()}catch(i){T.error(i instanceof Error?i.message:s("settingsProxy.failedUpdateAgyMode"))}finally{K.current=!1,ne(!1)}},[f,l,o,s]),Ne=n.useCallback(r=>{if(!(K.current||f||o)){if(r){R(!0);return}R(!1),I(""),$(!1)}},[f,$,o]),Ce=n.useCallback(()=>{if(!W){T.error(s("settingsProxy.typePhraseToContinue",{value:H}));return}$(!0)},[W,$,s]),[v,Y]=n.useState("plus"),[Se,we]=n.useState(!1),q=Ye(),{data:Ae}=qe(),le=Ae?.running??!1,J=n.useCallback(async()=>{try{const r=await L.cliproxyServer.getBackend();Y(r.backend)}catch(r){console.error("[Proxy] Failed to fetch backend:",r)}},[]),X=n.useCallback(async()=>{try{const i=(await L.cliproxy.list()).variants.some(O=>cs.includes(O.provider));we(i)}catch(r){console.error("[Proxy] Failed to check variants:",r)}},[]),ce=r=>{const i=v;Y(r),q.mutate({backend:r},{onError:()=>{Y(i)}})};if(n.useEffect(()=>{if(_&&t){const r={...t,remote:{...t.remote,auth_token:t.remote.auth_token?"[REDACTED]":void 0,management_key:t.remote.management_key?"[REDACTED]":void 0}};console.log("[CCS Debug] Debug mode enabled - proxy config:",r)}},[_,t]),n.useEffect(()=>{a(),G(),l(),J(),X()},[a,G,l,J,X]),g||!t)return e.jsx("div",{className:"flex-1 flex items-center justify-center",children:e.jsxs("div",{className:"flex items-center gap-3 text-muted-foreground",children:[e.jsx(re,{className:"w-5 h-5 animate-spin"}),e.jsx("span",{children:s("settings.loading")})]})});const m=t.remote.enabled??!1,F=!m&&le,N=t.remote,M=t.fallback,Ee=t.remote.host??"",Te=t.remote.port!==void 0?t.remote.port.toString():"",Be=t.remote.auth_token??"",Me=t.remote.management_key??"",De=(t.local.port??z).toString(),Q=p??Ee,Z=S??Te,ee=w??Be,de=E??Me,xe=x??De,Le=()=>{const r=p??Q;r!==t.remote.host&&c({remote:{...N,host:r}}),C(null)},_e=()=>{const r=(S??Z).trim();if(r===""){t.remote.port!==void 0&&c({remote:{...N,port:void 0}}),P(null);return}const i=Number(r);if(!Number.isInteger(i)||i<1||i>65535){T.error(s("settingsProxy.invalidPortOrEmpty")),P(null);return}i!==t.remote.port&&c({remote:{...N,port:i}}),P(null)},Re=()=>{const r=w??ee;r!==t.remote.auth_token&&c({remote:{...N,auth_token:r}}),A(null)},Ie=()=>{const r=E??de;r!==t.remote.management_key&&c({remote:{...N,management_key:r||void 0}}),d(null)},Ke=()=>{const r=(x??xe).trim(),i=r===""?z:Number(r);if(!Number.isInteger(i)||i<1||i>65535){T.error(s("settingsProxy.invalidLocalPort")),h(null);return}i!==t.local.port&&c({local:{...t.local,port:i}}),h(null)},$e=()=>{k({host:Q,port:Z,protocol:t.remote.protocol||"http",authToken:ee})};return e.jsxs(e.Fragment,{children:[e.jsxs("div",{className:`absolute left-5 right-5 top-20 z-10 transition-all duration-200 ease-out ${u||b?"opacity-100 translate-y-0":"opacity-0 -translate-y-2 pointer-events-none"}`,children:[u&&e.jsxs(se,{variant:"destructive",className:"py-2 shadow-lg",children:[e.jsx(Ze,{className:"h-4 w-4"}),e.jsx(te,{children:u})]}),b&&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(fe,{className:"h-4 w-4 shrink-0"}),e.jsx("span",{className:"text-sm font-medium",children:s("settings.saved")})]})]}),e.jsx(Je,{className:"flex-1",children:e.jsxs("div",{className:"p-5 space-y-6",children:[e.jsx("p",{className:"text-sm text-muted-foreground",children:s("settingsProxy.description",{backend:s(v==="plus"?"settingsProxy.backendPlus":"settingsProxy.backend")})}),!m&&e.jsxs("div",{className:"space-y-3",children:[e.jsx("h3",{className:"text-base font-medium",children:s("settingsProxy.instanceStatus")}),e.jsx(os,{})]}),e.jsxs("div",{className:"space-y-3",children:[e.jsx("h3",{className:"text-base font-medium",children:s("settingsProxy.connectionMode")}),e.jsxs("div",{className:"grid grid-cols-2 gap-3",children:[e.jsxs("button",{onClick:()=>c({remote:{...N,enabled:!1}}),disabled:o,className:`p-4 rounded-lg border-2 text-left transition-all ${m?"border-border hover:border-muted-foreground/50":"border-primary bg-primary/5"}`,children:[e.jsxs("div",{className:"flex items-center gap-3 mb-2",children:[e.jsx(es,{className:`w-5 h-5 ${m?"text-muted-foreground":"text-primary"}`}),e.jsx("span",{className:"font-medium",children:s("settingsProxy.local")})]}),e.jsx("p",{className:"text-xs text-muted-foreground",children:s("settingsProxy.localDesc",{backend:s(v==="plus"?"settingsProxy.backendPlus":"settingsProxy.backend")})})]}),e.jsxs("button",{onClick:()=>c({remote:{...N,enabled:!0}}),disabled:o,className:`p-4 rounded-lg border-2 text-left transition-all ${m?"border-primary bg-primary/5":"border-border hover:border-muted-foreground/50"}`,children:[e.jsxs("div",{className:"flex items-center gap-3 mb-2",children:[e.jsx(he,{className:`w-5 h-5 ${m?"text-primary":"text-muted-foreground"}`}),e.jsx("span",{className:"font-medium",children:s("settingsProxy.remote")})]}),e.jsx("p",{className:"text-xs text-muted-foreground",children:s("settingsProxy.remoteDesc",{backend:s(v==="plus"?"settingsProxy.backendPlus":"settingsProxy.backend")})})]})]})]}),e.jsxs("div",{className:"space-y-3",children:[e.jsxs("h3",{className:"text-base font-medium flex items-center gap-2",children:[e.jsx(ss,{className:"w-4 h-4"}),s("settingsProxy.backendBinary")]}),!m&&le&&e.jsxs(se,{className:"py-2 border-amber-200 bg-amber-50 dark:border-amber-900/50 dark:bg-amber-900/20 [&>svg]:top-2.5",children:[e.jsx(ye,{className:"h-4 w-4 text-amber-600"}),e.jsx(te,{className:"text-amber-700 dark:text-amber-400",children:s("settingsProxy.stopProxyToSwitch")})]}),e.jsxs("div",{className:"grid grid-cols-2 gap-3",children:[e.jsxs("button",{onClick:()=>ce("plus"),disabled:q.isPending||F,className:`p-4 rounded-lg border-2 text-left transition-all ${v==="plus"?"border-primary bg-primary/5":"border-border hover:border-muted-foreground/50"} ${F?"opacity-60 cursor-not-allowed":""}`,children:[e.jsxs("div",{className:"flex items-center gap-3 mb-2",children:[e.jsx("span",{className:"font-medium",children:s("settingsProxy.backendPlusApi")}),e.jsx("span",{className:"text-xs px-1.5 py-0.5 rounded bg-green-100 text-green-700 dark:bg-green-900/50 dark:text-green-400",children:s("settingsProxy.default")})]}),e.jsx("p",{className:"text-xs text-muted-foreground",children:s("settingsProxy.plusDesc")})]}),e.jsxs("button",{onClick:()=>ce("original"),disabled:q.isPending||F,className:`p-4 rounded-lg border-2 text-left transition-all ${v==="original"?"border-primary bg-primary/5":"border-border hover:border-muted-foreground/50"} ${F?"opacity-60 cursor-not-allowed":""}`,children:[e.jsx("div",{className:"flex items-center gap-3 mb-2",children:e.jsx("span",{className:"font-medium",children:s("settingsProxy.backendApi")})}),e.jsx("p",{className:"text-xs text-muted-foreground",children:s("settingsProxy.originalDesc")})]})]}),v==="original"&&Se&&e.jsxs(se,{variant:"destructive",className:"py-2",children:[e.jsx(ye,{className:"h-4 w-4"}),e.jsx(te,{children:s("settingsProxy.variantsIncompatible")})]})]}),e.jsxs("div",{className:"space-y-3",children:[e.jsxs("h3",{className:"text-base font-medium flex items-center gap-2",children:[e.jsx(ts,{className:"w-4 h-4 text-amber-700 dark:text-amber-300"}),s("settingsProxy.safety")]}),e.jsxs("div",{className:"space-y-3 rounded-lg border border-amber-400/35 bg-amber-50/70 p-4 dark:border-amber-800/60 dark:bg-amber-950/25",children:[e.jsxs("div",{className:"flex items-start justify-between gap-4",children:[e.jsxs("div",{className:"space-y-1",children:[e.jsx("p",{className:"font-medium text-sm",children:s("settingsProxy.agyModeTitle")}),e.jsx("p",{className:"text-xs text-muted-foreground",children:s("settingsProxy.agyModeDesc")})]}),e.jsx(D,{"aria-labelledby":"agy-power-user-mode-label","aria-describedby":"agy-power-user-mode-description",checked:je,disabled:Pe||f||o,onCheckedChange:Ne})]}),e.jsx("p",{id:"agy-power-user-mode-description",className:"text-xs text-amber-800/90 dark:text-amber-200/90",children:s("settingsProxy.agyWarning")}),ke&&e.jsxs("div",{className:"space-y-3 rounded-lg border border-rose-500/40 bg-rose-500/[0.08] p-3.5",children:[e.jsxs("div",{className:"space-y-1.5",children:[e.jsx("p",{className:"text-xs font-semibold tracking-wide text-rose-900 dark:text-rose-200",children:s("settingsProxy.finalConfirm")}),e.jsx("p",{className:"text-xs leading-relaxed text-rose-800/95 dark:text-rose-200/90",children:s("settingsProxy.finalConfirmDesc")})]}),e.jsxs("div",{className:"grid gap-2 md:grid-cols-2",children:[e.jsxs("div",{className:"rounded-md border border-rose-400/30 bg-rose-500/10 p-2.5",children:[e.jsx("p",{className:"text-[11px] font-semibold uppercase tracking-wide text-rose-900 dark:text-rose-200",children:s("settingsProxy.step1")}),e.jsxs("a",{href:"https://github.com/kaitranntt/ccs/issues/509",target:"_blank",rel:"noreferrer",className:"mt-1 inline-flex items-center gap-1.5 text-xs font-medium text-rose-800 underline decoration-rose-500/60 underline-offset-2 transition-colors hover:text-rose-700 dark:text-rose-200",children:[s("settingsProxy.readIssue"),e.jsx(rs,{className:"h-3.5 w-3.5"})]})]}),e.jsxs("div",{className:"rounded-md border border-rose-400/30 bg-rose-500/10 p-2.5",children:[e.jsx("p",{className:"text-[11px] font-semibold uppercase tracking-wide text-rose-900 dark:text-rose-200",children:s("settingsProxy.step2")}),e.jsxs("p",{className:"mt-1 text-xs text-rose-800/95 dark:text-rose-200/90",children:[s("settingsProxy.typePrefix")," ",e.jsx("code",{className:"rounded bg-background/80 px-1 py-0.5 font-mono",children:H})," ",s("settingsProxy.typeSuffix")]})]})]}),e.jsxs("div",{className:"space-y-2",children:[e.jsx(B,{value:ie,onChange:r=>I(r.target.value),placeholder:H,disabled:f||o,className:"font-mono text-xs","aria-label":s("settingsProxy.typePhraseAria")}),e.jsx("p",{className:"text-[11px] text-rose-800/90 dark:text-rose-200/80",children:s("settingsProxy.exactPhrase")})]}),e.jsxs("div",{className:"flex items-center justify-end gap-2",children:[e.jsx(V,{variant:"outline",size:"sm",onClick:()=>{R(!1),I("")},disabled:f||o,children:s("settingsBackups.cancel")}),e.jsx(V,{size:"sm",variant:"destructive",onClick:Ce,disabled:!W||f||o,children:s("settingsProxy.enableAgyMode")})]})]}),e.jsx("span",{id:"agy-power-user-mode-label",className:"sr-only",children:s("settingsProxy.toggleAgyMode")})]})]}),m&&e.jsx(ls,{config:t,saving:o,testing:j,testResult:y,displayHost:Q,displayPort:Z,displayAuthToken:ee,displayManagementKey:de,setEditedHost:C,setEditedPort:P,setEditedAuthToken:A,setEditedManagementKey:d,onSaveHost:Le,onSavePort:_e,onSaveAuthToken:Re,onSaveManagementKey:Ie,onSaveConfig:c,onTestConnection:$e}),e.jsxs("div",{className:"space-y-3",children:[e.jsx("h3",{className:"text-base font-medium",children:s("settingsProxy.fallbackSettings")}),e.jsxs("div",{className:"space-y-3 p-4 rounded-lg border bg-muted/30",children:[e.jsxs("div",{className:"flex items-center justify-between",children:[e.jsxs("div",{children:[e.jsx("p",{className:"font-medium text-sm",children:s("settingsProxy.enableFallback")}),e.jsx("p",{className:"text-xs text-muted-foreground",children:s("settingsProxy.enableFallbackDesc")})]}),e.jsx(D,{checked:M.enabled??!0,onCheckedChange:r=>c({fallback:{...M,enabled:r}}),disabled:o||!m})]}),e.jsxs("div",{className:"flex items-center justify-between",children:[e.jsxs("div",{children:[e.jsx("p",{className:"font-medium text-sm",children:s("settingsProxy.autoStartLocal")}),e.jsx("p",{className:"text-xs text-muted-foreground",children:s("settingsProxy.autoStartLocalDesc")})]}),e.jsx(D,{checked:M.auto_start??!1,onCheckedChange:r=>c({fallback:{...M,auto_start:r}}),disabled:o||!m||!M.enabled})]})]})]}),e.jsxs("div",{className:"space-y-3",children:[e.jsxs("h3",{className:"text-base font-medium flex items-center gap-2",children:[e.jsx(as,{className:"w-4 h-4"}),s("settingsProxy.advanced")]}),e.jsxs("div",{className:"space-y-3 p-4 rounded-lg border bg-muted/30",children:[e.jsxs("div",{className:"flex items-center justify-between",children:[e.jsxs("div",{children:[e.jsx("p",{className:"font-medium text-sm",children:s("settingsProxy.debugMode")}),e.jsx("p",{className:"text-xs text-muted-foreground",children:s("settingsProxy.debugModeDesc")})]}),e.jsx(D,{checked:_,onCheckedChange:ve,disabled:o})]}),_&&e.jsx("p",{className:"text-xs text-amber-600 dark:text-amber-400 pl-0.5",children:s("settingsProxy.debugModeEnabled")})]})]}),!m&&e.jsx(is,{config:t,saving:o,displayLocalPort:xe,setEditedLocalPort:h,onSaveLocalPort:Ke,onSaveConfig:c})]})}),e.jsx("div",{className:"p-4 border-t bg-background",children:e.jsxs(V,{variant:"outline",size:"sm",onClick:()=>{a(),G(),l(),J(),X()},disabled:g||o||f,className:"w-full",children:[e.jsx(re,{className:`w-4 h-4 mr-2 ${g?"animate-spin":""}`}),s("settings.refresh")]})})]})}export{Cs as default};
1
+ import{j as e}from"./radix-ui-BlliRfHq.js";import{r as n}from"./react-vendor-CNOkPC89.js";import{bj as Oe,bk as He,q as L,a as ae,I as B,az as D,v as Ve,w as ze,x as Ue,y as We,z as ue,d as V,bl as Ge,bm as Ye,bn as qe,b5 as se,b7 as te,A as Je}from"./index-BoI6MBbS.js";import{C as z}from"./default-ports-1QQSffYX.js";import{b1 as he,R as re,g as Xe,v as fe,W as Qe,u as Ze,b2 as es,b3 as ss,T as ye,ay as ts,n as rs,b4 as as}from"./icons-CQ3MLSan.js";import{P as os}from"./proxy-status-widget-pKxprGDY.js";import{R as H}from"./antigravity-responsibility-constants-Bvh4Ybz0.js";import{t as T}from"./notifications-B2HqRBj7.js";import"./tanstack-BjiH4QZq.js";import"./utils-CzKF5WmX.js";import"./form-utils-Bcoyqxpq.js";import"./code-highlight-BRUf_pqB.js";import"./alert-dialog-LsND-cGZ.js";function ns(){const{state:s}=Oe(),t=He(),[g,o]=n.useState(null),[u,b]=n.useState(null),[y,j]=n.useState(null),[p,C]=n.useState(null),[S,P]=n.useState(null),w=n.useCallback(async()=>{try{t.setProxyLoading(!0),t.setProxyError(null);const d=await L.cliproxyServer.get();t.setProxyConfig(d)}catch(d){t.setProxyError(d.message)}finally{t.setProxyLoading(!1)}},[t]),A=n.useCallback(async d=>{const x=s.proxyConfig;if(!x)return;const h={remote:{...x.remote,...d.remote},fallback:{...x.fallback,...d.fallback},local:{...x.local,...d.local}};t.setProxyConfig(h),t.setProxyTestResult(null);try{t.setProxySaving(!0),t.setProxyError(null);const a=await L.cliproxyServer.update(d);t.setProxyConfig(a),t.setProxySuccess(!0),setTimeout(()=>t.setProxySuccess(!1),1500)}catch(a){t.setProxyConfig(x),t.setProxyError(a.message)}finally{t.setProxySaving(!1)}},[s.proxyConfig,t]),E=n.useCallback(async d=>{const{host:x,port:h,protocol:a,authToken:c}=d;if(!x){t.setProxyError("Host is required");return}try{t.setProxyTesting(!0),t.setProxyError(null),t.setProxyTestResult(null);const k=h?parseInt(h,10):void 0,l=await L.cliproxyServer.test({host:x,port:k||void 0,protocol:a,authToken:c||void 0});t.setProxyTestResult(l)}catch(k){t.setProxyError(k.message)}finally{t.setProxyTesting(!1)}},[t]);return{config:s.proxyConfig,loading:s.proxyLoading,saving:s.proxySaving,error:s.proxyError,success:s.proxySuccess,testResult:s.proxyTestResult,testing:s.proxyTesting,editedHost:g,setEditedHost:o,editedPort:u,setEditedPort:b,editedAuthToken:y,setEditedAuthToken:j,editedManagementKey:p,setEditedManagementKey:C,editedLocalPort:S,setEditedLocalPort:P,fetchConfig:w,saveConfig:A,testConnection:E}}function is({config:s,saving:t,displayLocalPort:g,setEditedLocalPort:o,onSaveLocalPort:u,onSaveConfig:b}){const{t:y}=ae(),j=s.local;return e.jsxs("div",{className:"space-y-3",children:[e.jsx("h3",{className:"text-base font-medium",children:y("settingsProxy.localProxy")}),e.jsxs("div",{className:"space-y-3 p-4 rounded-lg border bg-muted/30",children:[e.jsxs("div",{className:"flex items-center gap-2",children:[e.jsx("label",{className:"text-sm text-muted-foreground",children:y("settingsProxy.port")}),e.jsx(B,{type:"text",inputMode:"numeric",value:g,onChange:p=>o(p.target.value.replace(/\D/g,"")),onBlur:u,placeholder:`${z}`,className:"font-mono max-w-32",disabled:t})]}),e.jsxs("div",{className:"flex items-center justify-between",children:[e.jsxs("div",{children:[e.jsx("p",{className:"font-medium text-sm",children:y("settingsProxy.autoStart")}),e.jsx("p",{className:"text-xs text-muted-foreground",children:y("settingsProxy.localAutoStartDesc")})]}),e.jsx(D,{checked:j.auto_start??!0,onCheckedChange:p=>b({local:{...j,auto_start:p}}),disabled:t})]})]})]})}function ls({config:s,saving:t,testing:g,testResult:o,displayHost:u,displayPort:b,displayAuthToken:y,displayManagementKey:j,setEditedHost:p,setEditedPort:C,setEditedAuthToken:S,setEditedManagementKey:P,onSaveHost:w,onSavePort:A,onSaveAuthToken:E,onSaveManagementKey:d,onSaveConfig:x,onTestConnection:h}){const{t:a}=ae(),c=s.remote,k=l=>l==="https"?443:z;return e.jsxs("div",{className:"space-y-4 p-4 rounded-lg border bg-muted/30",children:[e.jsxs("h4",{className:"text-sm font-medium flex items-center gap-2",children:[e.jsx(he,{className:"w-4 h-4"}),a("settingsProxy.remoteConfigTitle")]}),e.jsxs("div",{className:"space-y-1",children:[e.jsx("label",{className:"text-sm text-muted-foreground",children:a("settingsProxy.host")}),e.jsx(B,{value:u,onChange:l=>p(l.target.value),onBlur:w,placeholder:a("settingsProxy.hostPlaceholder"),className:"font-mono",disabled:t})]}),e.jsxs("div",{className:"grid grid-cols-2 gap-3",children:[e.jsxs("div",{className:"space-y-1",children:[e.jsxs("label",{className:"text-sm text-muted-foreground",children:[a("settingsProxy.port")," ",e.jsxs("span",{className:"text-xs opacity-70",children:["(",a("settingsProxy.defaultPort",{value:k(s.remote.protocol||"http")}),")"]})]}),e.jsx(B,{type:"text",inputMode:"numeric",value:b,onChange:l=>C(l.target.value.replace(/\D/g,"")),onBlur:A,placeholder:a("settingsProxy.portPlaceholder",{value:k(s.remote.protocol||"http")}),className:"font-mono",disabled:t})]}),e.jsxs("div",{className:"space-y-1",children:[e.jsx("label",{className:"text-sm text-muted-foreground",children:a("settingsProxy.protocol")}),e.jsxs(Ve,{value:s.remote.protocol||"http",onValueChange:l=>x({remote:{...c,protocol:l}}),disabled:t,children:[e.jsx(ze,{children:e.jsx(Ue,{})}),e.jsxs(We,{children:[e.jsx(ue,{value:"http",children:a("settingsProxy.http")}),e.jsx(ue,{value:"https",children:a("settingsProxy.https")})]})]})]})]}),e.jsxs("div",{className:"space-y-1",children:[e.jsx("label",{className:"text-sm text-muted-foreground",children:a("settingsProxy.apiKeyOptional")}),e.jsx(B,{type:"password",value:y,onChange:l=>S(l.target.value),onBlur:E,placeholder:a("settingsProxy.apiKeyPlaceholder"),className:"font-mono",disabled:t}),e.jsx("p",{className:"text-xs text-muted-foreground",children:a("settingsProxy.apiKeyDesc")})]}),e.jsxs("div",{className:"space-y-1",children:[e.jsx("label",{className:"text-sm text-muted-foreground",children:a("settingsProxy.managementKeyOptional")}),e.jsx(B,{type:"password",value:j,onChange:l=>P(l.target.value),onBlur:d,placeholder:a("settingsProxy.managementKeyPlaceholder"),className:"font-mono",disabled:t}),e.jsx("p",{className:"text-xs text-muted-foreground",children:a("settingsProxy.managementKeyDesc")})]}),e.jsxs("div",{className:"space-y-3 pt-2",children:[e.jsx(V,{onClick:h,disabled:g||!u,variant:"outline",className:"w-full",children:g?e.jsxs(e.Fragment,{children:[e.jsx(re,{className:"w-4 h-4 mr-2 animate-spin"}),a("settingsProxy.testing")]}):e.jsxs(e.Fragment,{children:[e.jsx(Xe,{className:"w-4 h-4 mr-2"}),a("settingsProxy.testConnection")]})}),o&&e.jsx("div",{className:`p-3 rounded-md ${o.reachable?"bg-green-50 border border-green-200 dark:bg-green-900/20 dark:border-green-900/50":"bg-red-50 border border-red-200 dark:bg-red-900/20 dark:border-red-900/50"}`,children:e.jsx("div",{className:"flex items-center gap-2",children:o.reachable?e.jsxs(e.Fragment,{children:[e.jsx(fe,{className:"w-4 h-4 text-green-600 dark:text-green-400"}),e.jsx("span",{className:"text-sm font-medium text-green-700 dark:text-green-300",children:a("settingsProxy.connectedLatency",{value:o.latencyMs})})]}):e.jsxs(e.Fragment,{children:[e.jsx(Qe,{className:"w-4 h-4 text-red-600 dark:text-red-400"}),e.jsx("span",{className:"text-sm font-medium text-red-700 dark:text-red-300",children:o.error||a("settingsProxy.connectionFailed")})]})})})]})]})}const pe="ccs_debug_mode",cs=["kiro","ghcp"];function ds(s){return s.trim().replace(/\s+/g," ").toUpperCase()}function Cs(){const{t:s}=ae(),{config:t,loading:g,saving:o,error:u,success:b,testResult:y,testing:j,editedHost:p,setEditedHost:C,editedPort:S,setEditedPort:P,editedAuthToken:w,setEditedAuthToken:A,editedManagementKey:E,setEditedManagementKey:d,editedLocalPort:x,setEditedLocalPort:h,fetchConfig:a,saveConfig:c,testConnection:k}=ns(),{fetchRawConfig:l}=Ge(),[_,be]=n.useState(()=>{try{return localStorage.getItem(pe)==="true"}catch{return!1}}),[je,U]=n.useState(!1),[Pe,oe]=n.useState(!0),[f,ne]=n.useState(!1),[ke,R]=n.useState(!1),[ie,I]=n.useState(""),K=n.useRef(!1),W=ds(ie)===H,ve=r=>{be(r);try{localStorage.setItem(pe,String(r))}catch{}},G=n.useCallback(async()=>{try{oe(!0);const r=await fetch("/api/settings/auth/antigravity-risk");if(!r.ok)throw new Error(s("settingsProxy.failedLoadAgyMode"));const i=await r.json();U(i.antigravityAckBypass===!0)}catch(r){T.error(r instanceof Error?r.message:s("settingsProxy.failedLoadAgyMode")),U(!1)}finally{oe(!1)}},[s]),$=n.useCallback(async r=>{if(!(K.current||f||o))try{K.current=!0,ne(!0);const i=await fetch("/api/settings/auth/antigravity-risk",{method:"PUT",headers:{"Content-Type":"application/json"},body:JSON.stringify({antigravityAckBypass:r})}),O=await i.json();if(!i.ok)throw new Error(O.error||s("settingsProxy.failedUpdateAgyMode"));const Fe=O.antigravityAckBypass===!0,me=await fetch("/api/settings/auth/antigravity-risk",{cache:"no-store"});if(!me.ok)throw new Error(s("settingsProxy.failedVerifyAgyMode"));const ge=(await me.json()).antigravityAckBypass===!0;if(ge!==r)throw new Error(s("settingsProxy.notPersistedAgyMode"));U(ge&&Fe),R(!1),I(""),T.success(s(r?"settingsProxy.agyModeEnabled":"settingsProxy.agyModeDisabled")),await l()}catch(i){T.error(i instanceof Error?i.message:s("settingsProxy.failedUpdateAgyMode"))}finally{K.current=!1,ne(!1)}},[f,l,o,s]),Ne=n.useCallback(r=>{if(!(K.current||f||o)){if(r){R(!0);return}R(!1),I(""),$(!1)}},[f,$,o]),Ce=n.useCallback(()=>{if(!W){T.error(s("settingsProxy.typePhraseToContinue",{value:H}));return}$(!0)},[W,$,s]),[v,Y]=n.useState("plus"),[Se,we]=n.useState(!1),q=Ye(),{data:Ae}=qe(),le=Ae?.running??!1,J=n.useCallback(async()=>{try{const r=await L.cliproxyServer.getBackend();Y(r.backend)}catch(r){console.error("[Proxy] Failed to fetch backend:",r)}},[]),X=n.useCallback(async()=>{try{const i=(await L.cliproxy.list()).variants.some(O=>cs.includes(O.provider));we(i)}catch(r){console.error("[Proxy] Failed to check variants:",r)}},[]),ce=r=>{const i=v;Y(r),q.mutate({backend:r},{onError:()=>{Y(i)}})};if(n.useEffect(()=>{if(_&&t){const r={...t,remote:{...t.remote,auth_token:t.remote.auth_token?"[REDACTED]":void 0,management_key:t.remote.management_key?"[REDACTED]":void 0}};console.log("[CCS Debug] Debug mode enabled - proxy config:",r)}},[_,t]),n.useEffect(()=>{a(),G(),l(),J(),X()},[a,G,l,J,X]),g||!t)return e.jsx("div",{className:"flex-1 flex items-center justify-center",children:e.jsxs("div",{className:"flex items-center gap-3 text-muted-foreground",children:[e.jsx(re,{className:"w-5 h-5 animate-spin"}),e.jsx("span",{children:s("settings.loading")})]})});const m=t.remote.enabled??!1,F=!m&&le,N=t.remote,M=t.fallback,Ee=t.remote.host??"",Te=t.remote.port!==void 0?t.remote.port.toString():"",Be=t.remote.auth_token??"",Me=t.remote.management_key??"",De=(t.local.port??z).toString(),Q=p??Ee,Z=S??Te,ee=w??Be,de=E??Me,xe=x??De,Le=()=>{const r=p??Q;r!==t.remote.host&&c({remote:{...N,host:r}}),C(null)},_e=()=>{const r=(S??Z).trim();if(r===""){t.remote.port!==void 0&&c({remote:{...N,port:void 0}}),P(null);return}const i=Number(r);if(!Number.isInteger(i)||i<1||i>65535){T.error(s("settingsProxy.invalidPortOrEmpty")),P(null);return}i!==t.remote.port&&c({remote:{...N,port:i}}),P(null)},Re=()=>{const r=w??ee;r!==t.remote.auth_token&&c({remote:{...N,auth_token:r}}),A(null)},Ie=()=>{const r=E??de;r!==t.remote.management_key&&c({remote:{...N,management_key:r||void 0}}),d(null)},Ke=()=>{const r=(x??xe).trim(),i=r===""?z:Number(r);if(!Number.isInteger(i)||i<1||i>65535){T.error(s("settingsProxy.invalidLocalPort")),h(null);return}i!==t.local.port&&c({local:{...t.local,port:i}}),h(null)},$e=()=>{k({host:Q,port:Z,protocol:t.remote.protocol||"http",authToken:ee})};return e.jsxs(e.Fragment,{children:[e.jsxs("div",{className:`absolute left-5 right-5 top-20 z-10 transition-all duration-200 ease-out ${u||b?"opacity-100 translate-y-0":"opacity-0 -translate-y-2 pointer-events-none"}`,children:[u&&e.jsxs(se,{variant:"destructive",className:"py-2 shadow-lg",children:[e.jsx(Ze,{className:"h-4 w-4"}),e.jsx(te,{children:u})]}),b&&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(fe,{className:"h-4 w-4 shrink-0"}),e.jsx("span",{className:"text-sm font-medium",children:s("settings.saved")})]})]}),e.jsx(Je,{className:"flex-1",children:e.jsxs("div",{className:"p-5 space-y-6",children:[e.jsx("p",{className:"text-sm text-muted-foreground",children:s("settingsProxy.description",{backend:s(v==="plus"?"settingsProxy.backendPlus":"settingsProxy.backend")})}),!m&&e.jsxs("div",{className:"space-y-3",children:[e.jsx("h3",{className:"text-base font-medium",children:s("settingsProxy.instanceStatus")}),e.jsx(os,{})]}),e.jsxs("div",{className:"space-y-3",children:[e.jsx("h3",{className:"text-base font-medium",children:s("settingsProxy.connectionMode")}),e.jsxs("div",{className:"grid grid-cols-2 gap-3",children:[e.jsxs("button",{onClick:()=>c({remote:{...N,enabled:!1}}),disabled:o,className:`p-4 rounded-lg border-2 text-left transition-all ${m?"border-border hover:border-muted-foreground/50":"border-primary bg-primary/5"}`,children:[e.jsxs("div",{className:"flex items-center gap-3 mb-2",children:[e.jsx(es,{className:`w-5 h-5 ${m?"text-muted-foreground":"text-primary"}`}),e.jsx("span",{className:"font-medium",children:s("settingsProxy.local")})]}),e.jsx("p",{className:"text-xs text-muted-foreground",children:s("settingsProxy.localDesc",{backend:s(v==="plus"?"settingsProxy.backendPlus":"settingsProxy.backend")})})]}),e.jsxs("button",{onClick:()=>c({remote:{...N,enabled:!0}}),disabled:o,className:`p-4 rounded-lg border-2 text-left transition-all ${m?"border-primary bg-primary/5":"border-border hover:border-muted-foreground/50"}`,children:[e.jsxs("div",{className:"flex items-center gap-3 mb-2",children:[e.jsx(he,{className:`w-5 h-5 ${m?"text-primary":"text-muted-foreground"}`}),e.jsx("span",{className:"font-medium",children:s("settingsProxy.remote")})]}),e.jsx("p",{className:"text-xs text-muted-foreground",children:s("settingsProxy.remoteDesc",{backend:s(v==="plus"?"settingsProxy.backendPlus":"settingsProxy.backend")})})]})]})]}),e.jsxs("div",{className:"space-y-3",children:[e.jsxs("h3",{className:"text-base font-medium flex items-center gap-2",children:[e.jsx(ss,{className:"w-4 h-4"}),s("settingsProxy.backendBinary")]}),!m&&le&&e.jsxs(se,{className:"py-2 border-amber-200 bg-amber-50 dark:border-amber-900/50 dark:bg-amber-900/20 [&>svg]:top-2.5",children:[e.jsx(ye,{className:"h-4 w-4 text-amber-600"}),e.jsx(te,{className:"text-amber-700 dark:text-amber-400",children:s("settingsProxy.stopProxyToSwitch")})]}),e.jsxs("div",{className:"grid grid-cols-2 gap-3",children:[e.jsxs("button",{onClick:()=>ce("plus"),disabled:q.isPending||F,className:`p-4 rounded-lg border-2 text-left transition-all ${v==="plus"?"border-primary bg-primary/5":"border-border hover:border-muted-foreground/50"} ${F?"opacity-60 cursor-not-allowed":""}`,children:[e.jsxs("div",{className:"flex items-center gap-3 mb-2",children:[e.jsx("span",{className:"font-medium",children:s("settingsProxy.backendPlusApi")}),e.jsx("span",{className:"text-xs px-1.5 py-0.5 rounded bg-green-100 text-green-700 dark:bg-green-900/50 dark:text-green-400",children:s("settingsProxy.default")})]}),e.jsx("p",{className:"text-xs text-muted-foreground",children:s("settingsProxy.plusDesc")})]}),e.jsxs("button",{onClick:()=>ce("original"),disabled:q.isPending||F,className:`p-4 rounded-lg border-2 text-left transition-all ${v==="original"?"border-primary bg-primary/5":"border-border hover:border-muted-foreground/50"} ${F?"opacity-60 cursor-not-allowed":""}`,children:[e.jsx("div",{className:"flex items-center gap-3 mb-2",children:e.jsx("span",{className:"font-medium",children:s("settingsProxy.backendApi")})}),e.jsx("p",{className:"text-xs text-muted-foreground",children:s("settingsProxy.originalDesc")})]})]}),v==="original"&&Se&&e.jsxs(se,{variant:"destructive",className:"py-2",children:[e.jsx(ye,{className:"h-4 w-4"}),e.jsx(te,{children:s("settingsProxy.variantsIncompatible")})]})]}),e.jsxs("div",{className:"space-y-3",children:[e.jsxs("h3",{className:"text-base font-medium flex items-center gap-2",children:[e.jsx(ts,{className:"w-4 h-4 text-amber-700 dark:text-amber-300"}),s("settingsProxy.safety")]}),e.jsxs("div",{className:"space-y-3 rounded-lg border border-amber-400/35 bg-amber-50/70 p-4 dark:border-amber-800/60 dark:bg-amber-950/25",children:[e.jsxs("div",{className:"flex items-start justify-between gap-4",children:[e.jsxs("div",{className:"space-y-1",children:[e.jsx("p",{className:"font-medium text-sm",children:s("settingsProxy.agyModeTitle")}),e.jsx("p",{className:"text-xs text-muted-foreground",children:s("settingsProxy.agyModeDesc")})]}),e.jsx(D,{"aria-labelledby":"agy-power-user-mode-label","aria-describedby":"agy-power-user-mode-description",checked:je,disabled:Pe||f||o,onCheckedChange:Ne})]}),e.jsx("p",{id:"agy-power-user-mode-description",className:"text-xs text-amber-800/90 dark:text-amber-200/90",children:s("settingsProxy.agyWarning")}),ke&&e.jsxs("div",{className:"space-y-3 rounded-lg border border-rose-500/40 bg-rose-500/[0.08] p-3.5",children:[e.jsxs("div",{className:"space-y-1.5",children:[e.jsx("p",{className:"text-xs font-semibold tracking-wide text-rose-900 dark:text-rose-200",children:s("settingsProxy.finalConfirm")}),e.jsx("p",{className:"text-xs leading-relaxed text-rose-800/95 dark:text-rose-200/90",children:s("settingsProxy.finalConfirmDesc")})]}),e.jsxs("div",{className:"grid gap-2 md:grid-cols-2",children:[e.jsxs("div",{className:"rounded-md border border-rose-400/30 bg-rose-500/10 p-2.5",children:[e.jsx("p",{className:"text-[11px] font-semibold uppercase tracking-wide text-rose-900 dark:text-rose-200",children:s("settingsProxy.step1")}),e.jsxs("a",{href:"https://github.com/kaitranntt/ccs/issues/509",target:"_blank",rel:"noreferrer",className:"mt-1 inline-flex items-center gap-1.5 text-xs font-medium text-rose-800 underline decoration-rose-500/60 underline-offset-2 transition-colors hover:text-rose-700 dark:text-rose-200",children:[s("settingsProxy.readIssue"),e.jsx(rs,{className:"h-3.5 w-3.5"})]})]}),e.jsxs("div",{className:"rounded-md border border-rose-400/30 bg-rose-500/10 p-2.5",children:[e.jsx("p",{className:"text-[11px] font-semibold uppercase tracking-wide text-rose-900 dark:text-rose-200",children:s("settingsProxy.step2")}),e.jsxs("p",{className:"mt-1 text-xs text-rose-800/95 dark:text-rose-200/90",children:[s("settingsProxy.typePrefix")," ",e.jsx("code",{className:"rounded bg-background/80 px-1 py-0.5 font-mono",children:H})," ",s("settingsProxy.typeSuffix")]})]})]}),e.jsxs("div",{className:"space-y-2",children:[e.jsx(B,{value:ie,onChange:r=>I(r.target.value),placeholder:H,disabled:f||o,className:"font-mono text-xs","aria-label":s("settingsProxy.typePhraseAria")}),e.jsx("p",{className:"text-[11px] text-rose-800/90 dark:text-rose-200/80",children:s("settingsProxy.exactPhrase")})]}),e.jsxs("div",{className:"flex items-center justify-end gap-2",children:[e.jsx(V,{variant:"outline",size:"sm",onClick:()=>{R(!1),I("")},disabled:f||o,children:s("settingsBackups.cancel")}),e.jsx(V,{size:"sm",variant:"destructive",onClick:Ce,disabled:!W||f||o,children:s("settingsProxy.enableAgyMode")})]})]}),e.jsx("span",{id:"agy-power-user-mode-label",className:"sr-only",children:s("settingsProxy.toggleAgyMode")})]})]}),m&&e.jsx(ls,{config:t,saving:o,testing:j,testResult:y,displayHost:Q,displayPort:Z,displayAuthToken:ee,displayManagementKey:de,setEditedHost:C,setEditedPort:P,setEditedAuthToken:A,setEditedManagementKey:d,onSaveHost:Le,onSavePort:_e,onSaveAuthToken:Re,onSaveManagementKey:Ie,onSaveConfig:c,onTestConnection:$e}),e.jsxs("div",{className:"space-y-3",children:[e.jsx("h3",{className:"text-base font-medium",children:s("settingsProxy.fallbackSettings")}),e.jsxs("div",{className:"space-y-3 p-4 rounded-lg border bg-muted/30",children:[e.jsxs("div",{className:"flex items-center justify-between",children:[e.jsxs("div",{children:[e.jsx("p",{className:"font-medium text-sm",children:s("settingsProxy.enableFallback")}),e.jsx("p",{className:"text-xs text-muted-foreground",children:s("settingsProxy.enableFallbackDesc")})]}),e.jsx(D,{checked:M.enabled??!0,onCheckedChange:r=>c({fallback:{...M,enabled:r}}),disabled:o||!m})]}),e.jsxs("div",{className:"flex items-center justify-between",children:[e.jsxs("div",{children:[e.jsx("p",{className:"font-medium text-sm",children:s("settingsProxy.autoStartLocal")}),e.jsx("p",{className:"text-xs text-muted-foreground",children:s("settingsProxy.autoStartLocalDesc")})]}),e.jsx(D,{checked:M.auto_start??!1,onCheckedChange:r=>c({fallback:{...M,auto_start:r}}),disabled:o||!m||!M.enabled})]})]})]}),e.jsxs("div",{className:"space-y-3",children:[e.jsxs("h3",{className:"text-base font-medium flex items-center gap-2",children:[e.jsx(as,{className:"w-4 h-4"}),s("settingsProxy.advanced")]}),e.jsxs("div",{className:"space-y-3 p-4 rounded-lg border bg-muted/30",children:[e.jsxs("div",{className:"flex items-center justify-between",children:[e.jsxs("div",{children:[e.jsx("p",{className:"font-medium text-sm",children:s("settingsProxy.debugMode")}),e.jsx("p",{className:"text-xs text-muted-foreground",children:s("settingsProxy.debugModeDesc")})]}),e.jsx(D,{checked:_,onCheckedChange:ve,disabled:o})]}),_&&e.jsx("p",{className:"text-xs text-amber-600 dark:text-amber-400 pl-0.5",children:s("settingsProxy.debugModeEnabled")})]})]}),!m&&e.jsx(is,{config:t,saving:o,displayLocalPort:xe,setEditedLocalPort:h,onSaveLocalPort:Ke,onSaveConfig:c})]})}),e.jsx("div",{className:"p-4 border-t bg-background",children:e.jsxs(V,{variant:"outline",size:"sm",onClick:()=>{a(),G(),l(),J(),X()},disabled:g||o||f,className:"w-full",children:[e.jsx(re,{className:`w-4 h-4 mr-2 ${g?"animate-spin":""}`}),s("settings.refresh")]})})]})}export{Cs as default};
@@ -1 +1 @@
1
- import{j as e}from"./radix-ui-BlliRfHq.js";import{r as o}from"./react-vendor-CNOkPC89.js";import{a as q,b5 as J,b7 as Q,d as I,A as X,L as A,v as R,w as M,x as z,y as K,z as E,I as F,az as Y}from"./index-TSYtCr3K.js";import{R as B,u as Z,v as ee,a8 as se,Q as te,q as re}from"./icons-CQ3MLSan.js";import"./tanstack-BjiH4QZq.js";import"./notifications-B2HqRBj7.js";import"./utils-CzKF5WmX.js";import"./form-utils-Bcoyqxpq.js";import"./code-highlight-BRUf_pqB.js";const $={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||$),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||$.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||$,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(B,{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(Q,{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(B,{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(X,{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(z,{})}),e.jsx(K,{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(z,{})}),e.jsx(K,{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(z,{})}),e.jsxs(K,{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(Y,{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(B,{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-BlliRfHq.js";import{r as o}from"./react-vendor-CNOkPC89.js";import{a as q,b5 as J,b7 as Q,d as I,A as X,L as A,v as R,w as M,x as z,y as K,z as E,I as F,az as Y}from"./index-BoI6MBbS.js";import{R as B,u as Z,v as ee,a8 as se,Q as te,q as re}from"./icons-CQ3MLSan.js";import"./tanstack-BjiH4QZq.js";import"./notifications-B2HqRBj7.js";import"./utils-CzKF5WmX.js";import"./form-utils-Bcoyqxpq.js";import"./code-highlight-BRUf_pqB.js";const $={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||$),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||$.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||$,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(B,{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(Q,{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(B,{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(X,{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(z,{})}),e.jsx(K,{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(z,{})}),e.jsx(K,{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(z,{})}),e.jsxs(K,{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(Y,{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(B,{className:`w-4 h-4 mr-2 ${b?"animate-spin":""}`}),t("settings.refresh")]})})]})}export{fe as default};