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

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (44) hide show
  1. package/README.md +1 -1
  2. package/dist/cliproxy/stats-fetcher.d.ts +41 -0
  3. package/dist/cliproxy/stats-fetcher.d.ts.map +1 -1
  4. package/dist/cliproxy/stats-fetcher.js +32 -1
  5. package/dist/cliproxy/stats-fetcher.js.map +1 -1
  6. package/dist/ui/assets/{accounts-Cs_Uohn7.js → accounts-CbGqm04Q.js} +1 -1
  7. package/dist/ui/assets/{alert-dialog-cRwDSggu.js → alert-dialog-zpinTbtF.js} +1 -1
  8. package/dist/ui/assets/{api-C73W2Hb1.js → api-CalCxo_A.js} +1 -1
  9. package/dist/ui/assets/{auth-section-DgF431PH.js → auth-section-BjuUeaLO.js} +1 -1
  10. package/dist/ui/assets/{backups-section-9V2yDu_e.js → backups-section-DNkq5ZUy.js} +1 -1
  11. package/dist/ui/assets/{checkbox-BeoeEcEZ.js → checkbox-Df7G7a1w.js} +1 -1
  12. package/dist/ui/assets/{cliproxy-DAlyh7zw.js → cliproxy-DLwo08Aq.js} +1 -1
  13. package/dist/ui/assets/{cliproxy-control-panel-CE4y4VDk.js → cliproxy-control-panel--SMhq8Fs.js} +1 -1
  14. package/dist/ui/assets/{confirm-dialog-COTT5ztZ.js → confirm-dialog-Dl3qe-0j.js} +1 -1
  15. package/dist/ui/assets/{copilot-Cm5PT0v6.js → copilot-CdJG-Shj.js} +1 -1
  16. package/dist/ui/assets/{cursor-DYhCaKbC.js → cursor-DMH09Hqq.js} +1 -1
  17. package/dist/ui/assets/{droid-eTM2_tVh.js → droid-ufxKKFsV.js} +1 -1
  18. package/dist/ui/assets/{globalenv-section-Dzt_ECFK.js → globalenv-section-CZMJi0Tl.js} +1 -1
  19. package/dist/ui/assets/{health-Bk8Cj2vi.js → health-CU3rjKc6.js} +1 -1
  20. package/dist/ui/assets/{index-BXDW5hxG.js → index-CFOuEr7f.js} +1 -1
  21. package/dist/ui/assets/{index-CKnNRLzv.js → index-CxzNRZhe.js} +1 -1
  22. package/dist/ui/assets/{index-jqDLGaO4.js → index-KBHcxzj5.js} +1 -1
  23. package/dist/ui/assets/index-UzqXH0bn.js +47 -0
  24. package/dist/ui/assets/{index-D1Gx_G_A.js → index-v5UgttWm.js} +1 -1
  25. package/dist/ui/assets/{proxy-status-widget-D-PfDCn1.js → proxy-status-widget-FJrBfPdV.js} +1 -1
  26. package/dist/ui/assets/{separator-CjXUYlSy.js → separator-B8bpSt_-.js} +1 -1
  27. package/dist/ui/assets/{shared-C9EvhZ8u.js → shared-BK-E4ojq.js} +1 -1
  28. package/dist/ui/assets/{switch-DFLN6xA0.js → switch-kyFX8Qe1.js} +1 -1
  29. package/dist/ui/assets/{updates-FcpGeTFg.js → updates-DBinmc39.js} +1 -1
  30. package/dist/ui/index.html +1 -1
  31. package/dist/web-server/usage/aggregator.d.ts +4 -0
  32. package/dist/web-server/usage/aggregator.d.ts.map +1 -1
  33. package/dist/web-server/usage/aggregator.js +24 -1
  34. package/dist/web-server/usage/aggregator.js.map +1 -1
  35. package/dist/web-server/usage/cliproxy-usage-syncer.d.ts +34 -0
  36. package/dist/web-server/usage/cliproxy-usage-syncer.d.ts.map +1 -0
  37. package/dist/web-server/usage/cliproxy-usage-syncer.js +152 -0
  38. package/dist/web-server/usage/cliproxy-usage-syncer.js.map +1 -0
  39. package/dist/web-server/usage/cliproxy-usage-transformer.d.ts +26 -0
  40. package/dist/web-server/usage/cliproxy-usage-transformer.d.ts.map +1 -0
  41. package/dist/web-server/usage/cliproxy-usage-transformer.js +141 -0
  42. package/dist/web-server/usage/cliproxy-usage-transformer.js.map +1 -0
  43. package/package.json +1 -1
  44. package/dist/ui/assets/index-hlYFfpDN.js +0 -47
@@ -1 +1 @@
1
- import{j as e}from"./radix-ui-BR1vy4kf.js";import{r}from"./react-vendor-CNOkPC89.js";import{a as S,bf as E,n as k,S as n,C as g,b6 as R,b8 as D,B as T,d as C}from"./index-hlYFfpDN.js";import{A as O,a as _,b as z,c as F,d as I,e as P,f as L,g as U}from"./alert-dialog-cRwDSggu.js";import{a3 as $,u as H,a6 as y,t as M,z as Y,R as J}from"./icons-kPbuhVdj.js";import"./tanstack-e99Cjjy2.js";import"./notifications-B2HqRBj7.js";import"./utils-CzKF5WmX.js";import"./form-utils-Cn_Uld6y.js";import"./code-highlight-BRUf_pqB.js";const q=3e3,G=5e3;function ae(){const{t}=S(),{fetchRawConfig:p}=E(),m=r.useRef(null),d=r.useRef(null),[j,v]=r.useState([]),[f,N]=r.useState(!0),[u,w]=r.useState(null),[i,l]=r.useState(null),[c,b]=r.useState(null),[x,h]=r.useState(null),o=r.useCallback(async()=>{m.current?.abort(),m.current=new AbortController;try{N(!0),l(null);const s=await fetch("/api/persist/backups",{signal:m.current.signal});if(!s.ok)throw new Error(t("settingsBackups.failedFetch"));const a=await s.json();v(a.backups||[])}catch(s){if(s instanceof Error&&s.name==="AbortError")return;l(s instanceof Error?s.message:t("settings.unknownError"))}finally{N(!1)}},[t]),A=r.useCallback(async s=>{d.current?.abort(),d.current=new AbortController;try{w(s),l(null);const a=await fetch("/api/persist/restore",{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify({timestamp:s}),signal:d.current.signal});if(!a.ok){const B=await a.json();throw new Error(B.error||t("settingsBackups.failedRestore"))}b(t("settingsBackups.restoreSuccess")),await o(),await p()}catch(a){if(a instanceof Error&&a.name==="AbortError")return;l(a instanceof Error?a.message:t("settings.unknownError"))}finally{w(null)}},[o,p,t]);return r.useEffect(()=>{o()},[o]),r.useEffect(()=>()=>{m.current?.abort(),d.current?.abort()},[]),r.useEffect(()=>{if(c){const s=setTimeout(()=>b(null),q);return()=>clearTimeout(s)}},[c]),r.useEffect(()=>{if(i){const s=setTimeout(()=>l(null),G);return()=>clearTimeout(s)}},[i]),f?e.jsxs(e.Fragment,{children:[e.jsx(k,{className:"flex-1",children:e.jsxs("div",{className:"p-5 space-y-4",children:[e.jsxs("div",{className:"space-y-2",children:[e.jsx(n,{className:"h-6 w-40"}),e.jsx(n,{className:"h-4 w-full"})]}),[1,2,3].map(s=>e.jsx(g,{className:"p-4",children:e.jsxs("div",{className:"flex items-center justify-between",children:[e.jsxs("div",{className:"space-y-2 flex-1",children:[e.jsx(n,{className:"h-4 w-32"}),e.jsx(n,{className:"h-3 w-48"})]}),e.jsx(n,{className:"h-8 w-20"})]})},s))]})}),e.jsx("div",{className:"p-4 border-t bg-background",children:e.jsx(n,{className:"h-9 w-full"})})]}):e.jsxs(e.Fragment,{children:[e.jsxs("div",{className:`absolute left-5 right-5 top-20 z-10 transition-all duration-200 ease-out ${i||c?"opacity-100 translate-y-0":"opacity-0 -translate-y-2 pointer-events-none"}`,children:[i&&e.jsxs(R,{variant:"destructive",className:"py-2 shadow-lg",children:[e.jsx($,{className:"h-4 w-4"}),e.jsx(D,{children:i})]}),c&&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(H,{className:"h-4 w-4 shrink-0"}),e.jsx("span",{className:"text-sm font-medium",children:c})]})]}),e.jsx(k,{className:"flex-1",children:e.jsxs("div",{className:"p-5 space-y-4",children:[e.jsxs("div",{children:[e.jsxs("div",{className:"flex items-center gap-2 mb-2",children:[e.jsx(y,{className:"w-5 h-5 text-primary"}),e.jsx("h2",{className:"text-lg font-semibold",children:t("settingsBackups.title")})]}),e.jsx("p",{className:"text-sm text-muted-foreground",children:t("settingsBackups.description")})]}),j.length===0?e.jsx(g,{className:"p-8",children:e.jsxs("div",{className:"text-center",children:[e.jsx(y,{className:"w-12 h-12 mx-auto mb-3 opacity-30 text-muted-foreground"}),e.jsx("p",{className:"text-sm text-muted-foreground",children:t("settingsBackups.none")}),e.jsx("p",{className:"text-xs text-muted-foreground mt-1",children:t("settingsBackups.noneHint")})]})}):e.jsx("div",{className:"space-y-2",children:j.map((s,a)=>e.jsx(g,{className:"p-4 hover:bg-muted/50 transition-colors",children:e.jsxs("div",{className:"flex items-center justify-between gap-4",children:[e.jsxs("div",{className:"flex items-start gap-3 flex-1 min-w-0",children:[e.jsx(M,{className:"w-4 h-4 text-muted-foreground mt-0.5 shrink-0"}),e.jsxs("div",{className:"min-w-0 flex-1",children:[e.jsxs("div",{className:"flex items-center gap-2 mb-1",children:[e.jsx("p",{className:"text-sm font-medium font-mono",children:s.timestamp}),a===0&&e.jsx(T,{variant:"secondary",className:"text-xs",children:t("settingsBackups.latest")})]}),e.jsx("p",{className:"text-xs text-muted-foreground",children:s.date})]})]}),e.jsxs(C,{variant:"outline",size:"sm",onClick:()=>h(s.timestamp),disabled:u!==null,className:"gap-2 shrink-0",children:[e.jsx(Y,{className:`w-4 h-4 ${u===s.timestamp?"animate-spin":""}`}),u===s.timestamp?t("settingsBackups.restoring"):t("settingsBackups.restore")]})]})},s.timestamp))})]})}),e.jsx("div",{className:"p-4 border-t bg-background",children:e.jsxs(C,{variant:"outline",size:"sm",onClick:()=>{o(),p()},disabled:f||u!==null,className:"w-full",children:[e.jsx(J,{className:`w-4 h-4 mr-2 ${f?"animate-spin":""}`}),t("settings.refresh")]})}),e.jsx(O,{open:!!x,onOpenChange:()=>h(null),children:e.jsxs(_,{children:[e.jsxs(z,{children:[e.jsx(F,{children:t("settingsBackups.restoreConfirmTitle")}),e.jsxs(I,{children:[t("settingsBackups.restoreConfirmPrefix")," ",e.jsx("code",{className:"font-mono bg-muted px-1.5 py-0.5 rounded text-foreground",children:x}),". ",t("settingsBackups.restoreConfirmSuffix")]})]}),e.jsxs(P,{children:[e.jsx(L,{children:t("settingsBackups.cancel")}),e.jsx(U,{onClick:()=>{x&&A(x),h(null)},children:t("settingsBackups.restore")})]})]})})]})}export{ae as default};
1
+ import{j as e}from"./radix-ui-BR1vy4kf.js";import{r}from"./react-vendor-CNOkPC89.js";import{a as S,bf as E,n as k,S as n,C as g,b6 as R,b8 as D,B as T,d as C}from"./index-UzqXH0bn.js";import{A as O,a as _,b as z,c as F,d as I,e as P,f as L,g as U}from"./alert-dialog-zpinTbtF.js";import{a3 as $,u as H,a6 as y,t as M,z as Y,R as J}from"./icons-kPbuhVdj.js";import"./tanstack-e99Cjjy2.js";import"./notifications-B2HqRBj7.js";import"./utils-CzKF5WmX.js";import"./form-utils-Cn_Uld6y.js";import"./code-highlight-BRUf_pqB.js";const q=3e3,G=5e3;function ae(){const{t}=S(),{fetchRawConfig:p}=E(),m=r.useRef(null),d=r.useRef(null),[j,v]=r.useState([]),[f,N]=r.useState(!0),[u,w]=r.useState(null),[i,l]=r.useState(null),[c,b]=r.useState(null),[x,h]=r.useState(null),o=r.useCallback(async()=>{m.current?.abort(),m.current=new AbortController;try{N(!0),l(null);const s=await fetch("/api/persist/backups",{signal:m.current.signal});if(!s.ok)throw new Error(t("settingsBackups.failedFetch"));const a=await s.json();v(a.backups||[])}catch(s){if(s instanceof Error&&s.name==="AbortError")return;l(s instanceof Error?s.message:t("settings.unknownError"))}finally{N(!1)}},[t]),A=r.useCallback(async s=>{d.current?.abort(),d.current=new AbortController;try{w(s),l(null);const a=await fetch("/api/persist/restore",{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify({timestamp:s}),signal:d.current.signal});if(!a.ok){const B=await a.json();throw new Error(B.error||t("settingsBackups.failedRestore"))}b(t("settingsBackups.restoreSuccess")),await o(),await p()}catch(a){if(a instanceof Error&&a.name==="AbortError")return;l(a instanceof Error?a.message:t("settings.unknownError"))}finally{w(null)}},[o,p,t]);return r.useEffect(()=>{o()},[o]),r.useEffect(()=>()=>{m.current?.abort(),d.current?.abort()},[]),r.useEffect(()=>{if(c){const s=setTimeout(()=>b(null),q);return()=>clearTimeout(s)}},[c]),r.useEffect(()=>{if(i){const s=setTimeout(()=>l(null),G);return()=>clearTimeout(s)}},[i]),f?e.jsxs(e.Fragment,{children:[e.jsx(k,{className:"flex-1",children:e.jsxs("div",{className:"p-5 space-y-4",children:[e.jsxs("div",{className:"space-y-2",children:[e.jsx(n,{className:"h-6 w-40"}),e.jsx(n,{className:"h-4 w-full"})]}),[1,2,3].map(s=>e.jsx(g,{className:"p-4",children:e.jsxs("div",{className:"flex items-center justify-between",children:[e.jsxs("div",{className:"space-y-2 flex-1",children:[e.jsx(n,{className:"h-4 w-32"}),e.jsx(n,{className:"h-3 w-48"})]}),e.jsx(n,{className:"h-8 w-20"})]})},s))]})}),e.jsx("div",{className:"p-4 border-t bg-background",children:e.jsx(n,{className:"h-9 w-full"})})]}):e.jsxs(e.Fragment,{children:[e.jsxs("div",{className:`absolute left-5 right-5 top-20 z-10 transition-all duration-200 ease-out ${i||c?"opacity-100 translate-y-0":"opacity-0 -translate-y-2 pointer-events-none"}`,children:[i&&e.jsxs(R,{variant:"destructive",className:"py-2 shadow-lg",children:[e.jsx($,{className:"h-4 w-4"}),e.jsx(D,{children:i})]}),c&&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(H,{className:"h-4 w-4 shrink-0"}),e.jsx("span",{className:"text-sm font-medium",children:c})]})]}),e.jsx(k,{className:"flex-1",children:e.jsxs("div",{className:"p-5 space-y-4",children:[e.jsxs("div",{children:[e.jsxs("div",{className:"flex items-center gap-2 mb-2",children:[e.jsx(y,{className:"w-5 h-5 text-primary"}),e.jsx("h2",{className:"text-lg font-semibold",children:t("settingsBackups.title")})]}),e.jsx("p",{className:"text-sm text-muted-foreground",children:t("settingsBackups.description")})]}),j.length===0?e.jsx(g,{className:"p-8",children:e.jsxs("div",{className:"text-center",children:[e.jsx(y,{className:"w-12 h-12 mx-auto mb-3 opacity-30 text-muted-foreground"}),e.jsx("p",{className:"text-sm text-muted-foreground",children:t("settingsBackups.none")}),e.jsx("p",{className:"text-xs text-muted-foreground mt-1",children:t("settingsBackups.noneHint")})]})}):e.jsx("div",{className:"space-y-2",children:j.map((s,a)=>e.jsx(g,{className:"p-4 hover:bg-muted/50 transition-colors",children:e.jsxs("div",{className:"flex items-center justify-between gap-4",children:[e.jsxs("div",{className:"flex items-start gap-3 flex-1 min-w-0",children:[e.jsx(M,{className:"w-4 h-4 text-muted-foreground mt-0.5 shrink-0"}),e.jsxs("div",{className:"min-w-0 flex-1",children:[e.jsxs("div",{className:"flex items-center gap-2 mb-1",children:[e.jsx("p",{className:"text-sm font-medium font-mono",children:s.timestamp}),a===0&&e.jsx(T,{variant:"secondary",className:"text-xs",children:t("settingsBackups.latest")})]}),e.jsx("p",{className:"text-xs text-muted-foreground",children:s.date})]})]}),e.jsxs(C,{variant:"outline",size:"sm",onClick:()=>h(s.timestamp),disabled:u!==null,className:"gap-2 shrink-0",children:[e.jsx(Y,{className:`w-4 h-4 ${u===s.timestamp?"animate-spin":""}`}),u===s.timestamp?t("settingsBackups.restoring"):t("settingsBackups.restore")]})]})},s.timestamp))})]})}),e.jsx("div",{className:"p-4 border-t bg-background",children:e.jsxs(C,{variant:"outline",size:"sm",onClick:()=>{o(),p()},disabled:f||u!==null,className:"w-full",children:[e.jsx(J,{className:`w-4 h-4 mr-2 ${f?"animate-spin":""}`}),t("settings.refresh")]})}),e.jsx(O,{open:!!x,onOpenChange:()=>h(null),children:e.jsxs(_,{children:[e.jsxs(z,{children:[e.jsx(F,{children:t("settingsBackups.restoreConfirmTitle")}),e.jsxs(I,{children:[t("settingsBackups.restoreConfirmPrefix")," ",e.jsx("code",{className:"font-mono bg-muted px-1.5 py-0.5 rounded text-foreground",children:x}),". ",t("settingsBackups.restoreConfirmSuffix")]})]}),e.jsxs(P,{children:[e.jsx(L,{children:t("settingsBackups.cancel")}),e.jsx(U,{onClick:()=>{x&&A(x),h(null)},children:t("settingsBackups.restore")})]})]})})]})}export{ae as default};
@@ -1 +1 @@
1
- import{j as r,a0 as i,a1 as t}from"./radix-ui-BR1vy4kf.js";import"./react-vendor-CNOkPC89.js";import{c as s}from"./index-hlYFfpDN.js";import{k as o}from"./icons-kPbuhVdj.js";function b({className:e,...a}){return r.jsx(i,{"data-slot":"checkbox",className:s("peer border-input dark:bg-input/30 data-[state=checked]:bg-primary data-[state=checked]:text-primary-foreground dark:data-[state=checked]:bg-primary data-[state=checked]:border-primary focus-visible:border-ring focus-visible:ring-ring/50 aria-invalid:ring-destructive/20 dark:aria-invalid:ring-destructive/40 aria-invalid:border-destructive size-4 shrink-0 rounded-[4px] border shadow-xs transition-shadow outline-none focus-visible:ring-[3px] disabled:cursor-not-allowed disabled:opacity-50",e),...a,children:r.jsx(t,{"data-slot":"checkbox-indicator",className:"grid place-content-center text-current transition-none",children:r.jsx(o,{className:"size-3.5"})})})}export{b as C};
1
+ import{j as r,a0 as i,a1 as t}from"./radix-ui-BR1vy4kf.js";import"./react-vendor-CNOkPC89.js";import{c as s}from"./index-UzqXH0bn.js";import{k as o}from"./icons-kPbuhVdj.js";function b({className:e,...a}){return r.jsx(i,{"data-slot":"checkbox",className:s("peer border-input dark:bg-input/30 data-[state=checked]:bg-primary data-[state=checked]:text-primary-foreground dark:data-[state=checked]:bg-primary data-[state=checked]:border-primary focus-visible:border-ring focus-visible:ring-ring/50 aria-invalid:ring-destructive/20 dark:aria-invalid:ring-destructive/40 aria-invalid:border-destructive size-4 shrink-0 rounded-[4px] border shadow-xs transition-shadow outline-none focus-visible:ring-[3px] disabled:cursor-not-allowed disabled:opacity-50",e),...a,children:r.jsx(t,{"data-slot":"checkbox-indicator",className:"grid place-content-center text-current transition-none",children:r.jsx(o,{className:"size-3.5"})})})}export{b as C};
@@ -1,3 +1,3 @@
1
- import{j as e}from"./radix-ui-BR1vy4kf.js";import{r as d}from"./react-vendor-CNOkPC89.js";import{a as Ue,u as ws,b as $s}from"./tanstack-e99Cjjy2.js";import{d as O,C as ys,b as bs,c as B,P as Ce,a as Z,L as W,I as oe,r as qe,s as Ke,t as He,v as Ve,w as ge,a3 as ks,a4 as Qs,a5 as zs,a6 as Js,u as Cs,a7 as Be,a8 as Ge,a9 as $e,aa as Qe,ab as As,ac as rs,ad as Ws,ae as Ys,W as Ss,af as Oe,ag as Ps,Y as ye,B as U,ah as _e,ai as os,aj as Xs,ak as Zs,al as et,am as st,an as ls,ao as cs,ap as tt,x as Ms,n as ze,aq as at,ar as nt,as as it,m as rt,at as ot,au as lt,av as ct,aw as dt,ax as ut,ay as mt,az as le,T as ce,p as de,q as ue,aA as xt,aB as pt,aC as ht,aD as ds,aE as gt,aF as ft,aG as jt,aH as vt,aI as Nt,aJ as wt,aK as yt,Q as bt,R as kt,U as us,V as ms,aL as Ct,aM as At,aN as St,aO as Pt,aP as Mt,aQ as Dt,aR as Tt,aS as Et,aT as Rt,aU as Ot,aV as _t,aW as Lt,S as It}from"./index-hlYFfpDN.js";import{C as Le}from"./default-ports-1QQSffYX.js";import{t as K}from"./notifications-B2HqRBj7.js";import{C as Ds,L as J,n as xe,N as Ft,k as te,m as Ts,ao as Je,R as We,o as pe,a2 as je,T as Ye,a0 as Ut,ap as Es,aq as qt,ar as Ae,Z as ve,J as Rs,g as Kt,s as Os,as as Ht,ai as Vt,X as Xe,a1 as _s,w as Ls,x as Ie,at as Bt,t as xs,au as Gt,ah as Is,u as $t,av as ps,l as Qt,a3 as zt,al as Jt,aw as Fs}from"./icons-kPbuhVdj.js";import{R as be,A as hs,D as De,i as Wt,a as Yt,P as Xt}from"./proxy-status-widget-D-PfDCn1.js";import{C as ke}from"./checkbox-BeoeEcEZ.js";import{C as Zt}from"./confirm-dialog-COTT5ztZ.js";import{S as Ze}from"./separator-CjXUYlSy.js";import{S as Us}from"./switch-DFLN6xA0.js";import"./utils-CzKF5WmX.js";import"./form-utils-Cn_Uld6y.js";import"./code-highlight-BRUf_pqB.js";import"./alert-dialog-cRwDSggu.js";const fe={agy:{provider:"agy",displayName:"Antigravity",defaultModel:"claude-opus-4-6-thinking",models:[{id:"claude-opus-4-6-thinking",name:"Claude Opus 4.6 Thinking",description:"Latest flagship, extended thinking",extendedContext:!1,presetMapping:{default:"claude-opus-4-6-thinking",opus:"claude-opus-4-6-thinking",sonnet:"claude-sonnet-4-6",haiku:"claude-sonnet-4-6"}},{id:"claude-opus-4-5-thinking",name:"Claude Opus 4.5 Thinking",description:"Previous flagship, extended thinking",presetMapping:{default:"claude-opus-4-5-thinking",opus:"claude-opus-4-5-thinking",sonnet:"claude-sonnet-4-6",haiku:"claude-sonnet-4-6"}},{id:"claude-sonnet-4-6",name:"Claude Sonnet 4.6",description:"Latest Sonnet with thinking budget support",presetMapping:{default:"claude-sonnet-4-6",opus:"claude-opus-4-6-thinking",sonnet:"claude-sonnet-4-6",haiku:"claude-sonnet-4-6"}},{id:"claude-sonnet-4-5-thinking",name:"Claude Sonnet 4.5 Thinking",description:"Balanced with extended thinking",presetMapping:{default:"claude-sonnet-4-5-thinking",opus:"claude-opus-4-6-thinking",sonnet:"claude-sonnet-4-5-thinking",haiku:"claude-sonnet-4-5"}},{id:"claude-sonnet-4-5",name:"Claude Sonnet 4.5",description:"Fast and capable",presetMapping:{default:"claude-sonnet-4-5",opus:"claude-opus-4-6-thinking",sonnet:"claude-sonnet-4-5",haiku:"claude-sonnet-4-5"}},{id:"gemini-3-pro-preview",name:"Gemini 3 Pro",description:"Google latest model via Antigravity",extendedContext:!0,presetMapping:{default:"gemini-3-pro-preview",opus:"gemini-3-pro-preview",sonnet:"gemini-3-pro-preview",haiku:"gemini-3-flash-preview"}},{id:"gemini-3-flash-preview",name:"Gemini 3 Flash",description:"Fast Gemini model via Antigravity",extendedContext:!0,presetMapping:{default:"gemini-3-flash-preview",opus:"gemini-3-pro-preview",sonnet:"gemini-3-pro-preview",haiku:"gemini-3-flash-preview"}}]},gemini:{provider:"gemini",displayName:"Gemini",defaultModel:"gemini-2.5-pro",models:[{id:"gemini-3-pro-preview",name:"Gemini 3 Pro",tier:"paid",description:"Latest model, requires paid Google account",extendedContext:!0,presetMapping:{default:"gemini-3-pro-preview",opus:"gemini-3-pro-preview",sonnet:"gemini-3-pro-preview",haiku:"gemini-3-flash-preview"}},{id:"gemini-3-flash-preview",name:"Gemini 3 Flash",tier:"paid",description:"Fast Gemini 3 model, requires paid Google account",extendedContext:!0,presetMapping:{default:"gemini-3-flash-preview",opus:"gemini-3-pro-preview",sonnet:"gemini-3-pro-preview",haiku:"gemini-3-flash-preview"}},{id:"gemini-2.5-pro",name:"Gemini 2.5 Pro",description:"Stable, works with free Google account",extendedContext:!0,presetMapping:{default:"gemini-2.5-pro",opus:"gemini-2.5-pro",sonnet:"gemini-2.5-pro",haiku:"gemini-2.5-flash"}}]},codex:{provider:"codex",displayName:"Codex",defaultModel:"gpt-5.3-codex",models:[{id:"gpt-5.3-codex",name:"GPT-5.3 Codex",description:"Supports up to xhigh effort",presetMapping:{default:"gpt-5.3-codex",opus:"gpt-5.3-codex",sonnet:"gpt-5.3-codex",haiku:"gpt-5-mini"}},{id:"gpt-5.2-codex",name:"GPT-5.2 Codex",description:"Previous stable Codex model",presetMapping:{default:"gpt-5.2-codex",opus:"gpt-5.2-codex",sonnet:"gpt-5.2-codex",haiku:"gpt-5-mini"}},{id:"gpt-5-mini",name:"GPT-5 Mini",description:"Fast, capped at high effort (no xhigh)",presetMapping:{default:"gpt-5-mini",opus:"gpt-5.3-codex",sonnet:"gpt-5-mini",haiku:"gpt-5-mini"}},{id:"gpt-5.1-codex-max",name:"Codex Max (5.1)",description:"Legacy most capable Codex model",presetMapping:{default:"gpt-5.1-codex-max",opus:"gpt-5.1-codex-max",sonnet:"gpt-5.1-codex-max",haiku:"gpt-5.1-codex-mini"}},{id:"gpt-5.2",name:"GPT 5.2",description:"Latest GPT model",presetMapping:{default:"gpt-5.2",opus:"gpt-5.2",sonnet:"gpt-5.2",haiku:"gpt-5.2"}},{id:"gpt-5.1-codex-mini",name:"Codex Mini",description:"Fast and efficient Codex model"}]},qwen:{provider:"qwen",displayName:"Qwen",defaultModel:"qwen3-coder-plus",models:[{id:"qwen3-coder-plus",name:"Qwen3 Coder Plus",description:"Code-focused model (1M context)",presetMapping:{default:"qwen3-coder-plus",opus:"qwen3-max",sonnet:"qwen3-coder-plus",haiku:"qwen3-coder-flash"}},{id:"qwen3-max",name:"Qwen3 Max",description:"Flagship model (256K context)",presetMapping:{default:"qwen3-max",opus:"qwen3-max",sonnet:"qwen3-coder-plus",haiku:"qwen3-coder-flash"}},{id:"qwen3-max-preview",name:"Qwen3 Max Preview",description:"Preview with thinking support (256K)",presetMapping:{default:"qwen3-max-preview",opus:"qwen3-max-preview",sonnet:"qwen3-max",haiku:"qwen3-coder-flash"}},{id:"qwen3-235b",name:"Qwen3 235B",description:"Large 235B A22B model",presetMapping:{default:"qwen3-235b",opus:"qwen3-max",sonnet:"qwen3-235b",haiku:"qwen3-coder-flash"}},{id:"qwen3-vl-plus",name:"Qwen3 VL Plus",description:"Vision-language multimodal"},{id:"qwen3-coder-flash",name:"Qwen3 Coder Flash",description:"Fast code generation"},{id:"qwen3-32b",name:"Qwen3 32B",description:"Qwen3 32B model"}]},iflow:{provider:"iflow",displayName:"iFlow",defaultModel:"qwen3-coder-plus",models:[{id:"qwen3-coder-plus",name:"Qwen3 Coder Plus",description:"Recommended default for iFlow accounts",presetMapping:{default:"qwen3-coder-plus",opus:"qwen3-coder-plus",sonnet:"qwen3-coder-plus",haiku:"qwen3-coder-plus"}},{id:"qwen3-max",name:"Qwen3 Max",description:"Flagship Qwen model via iFlow"},{id:"kimi-k2.5",name:"Kimi K2.5",description:"Latest Kimi model via iFlow"},{id:"kimi-k2",name:"Kimi K2",description:"Kimi general model"},{id:"deepseek-v3.2-chat",name:"DeepSeek V3.2 Chat",description:"Stable DeepSeek chat model"},{id:"deepseek-r1",name:"DeepSeek R1",description:"Reasoning-focused DeepSeek model"},{id:"glm-4.7",name:"GLM 4.7",description:"Zhipu GLM 4.7 via iFlow"},{id:"minimax-m2.5",name:"MiniMax M2.5",description:"MiniMax M2.5 via iFlow"},{id:"qwen3-vl-plus",name:"Qwen3 VL Plus",description:"Vision-language model"}]},kimi:{provider:"kimi",displayName:"Kimi (Moonshot)",defaultModel:"kimi-k2.5",models:[{id:"kimi-k2.5",name:"Kimi K2.5",description:"Latest multimodal model (262K context)",presetMapping:{default:"kimi-k2.5",opus:"kimi-k2.5",sonnet:"kimi-k2-thinking",haiku:"kimi-k2"}},{id:"kimi-k2-thinking",name:"Kimi K2 Thinking",description:"Extended reasoning model",presetMapping:{default:"kimi-k2-thinking",opus:"kimi-k2.5",sonnet:"kimi-k2-thinking",haiku:"kimi-k2"}},{id:"kimi-k2",name:"Kimi K2",description:"Flagship coding model"}]},kiro:{provider:"kiro",displayName:"Kiro (AWS)",defaultModel:"kiro-claude-sonnet-4-5",models:[{id:"kiro-claude-opus-4-5",name:"Kiro Claude Opus 4.5",description:"Claude Opus 4.5 via Kiro (2.2x credit)",presetMapping:{default:"kiro-claude-opus-4-5",opus:"kiro-claude-opus-4-5",sonnet:"kiro-claude-sonnet-4-5",haiku:"kiro-claude-haiku-4-5"}},{id:"kiro-claude-sonnet-4-5",name:"Kiro Claude Sonnet 4.5",description:"Claude Sonnet 4.5 via Kiro (1.3x credit)",presetMapping:{default:"kiro-claude-sonnet-4-5",opus:"kiro-claude-opus-4-5",sonnet:"kiro-claude-sonnet-4-5",haiku:"kiro-claude-haiku-4-5"}},{id:"kiro-claude-sonnet-4",name:"Kiro Claude Sonnet 4",description:"Claude Sonnet 4 via Kiro (1.3x credit)",presetMapping:{default:"kiro-claude-sonnet-4",opus:"kiro-claude-opus-4-5",sonnet:"kiro-claude-sonnet-4",haiku:"kiro-claude-haiku-4-5"}},{id:"kiro-claude-haiku-4-5",name:"Kiro Claude Haiku 4.5",description:"Claude Haiku 4.5 via Kiro (0.4x credit)"}]},ghcp:{provider:"ghcp",displayName:"GitHub Copilot (OAuth)",defaultModel:"claude-sonnet-4.5",models:[{id:"claude-opus-4.5",name:"Claude Opus 4.5",description:"Anthropic Claude Opus 4.5 via GitHub Copilot",presetMapping:{default:"claude-opus-4.5",opus:"claude-opus-4.5",sonnet:"claude-sonnet-4.5",haiku:"claude-haiku-4.5"}},{id:"claude-sonnet-4.5",name:"Claude Sonnet 4.5",description:"Anthropic Claude Sonnet 4.5 via GitHub Copilot",presetMapping:{default:"claude-sonnet-4.5",opus:"claude-opus-4.5",sonnet:"claude-sonnet-4.5",haiku:"claude-haiku-4.5"}},{id:"claude-sonnet-4",name:"Claude Sonnet 4",description:"Anthropic Claude Sonnet 4 via GitHub Copilot"},{id:"claude-haiku-4.5",name:"Claude Haiku 4.5",description:"Anthropic Claude Haiku 4.5 via GitHub Copilot"},{id:"gpt-5.2",name:"GPT-5.2",description:"OpenAI GPT-5.2 via GitHub Copilot",presetMapping:{default:"gpt-5.2",opus:"gpt-5.2",sonnet:"gpt-5.1",haiku:"gpt-5-mini"}},{id:"gpt-5.1",name:"GPT-5.1",description:"OpenAI GPT-5.1 via GitHub Copilot"},{id:"gpt-5",name:"GPT-5",description:"OpenAI GPT-5 via GitHub Copilot"},{id:"gpt-5-mini",name:"GPT-5 Mini",description:"OpenAI GPT-5 Mini via GitHub Copilot"},{id:"gemini-3-pro",name:"Gemini 3 Pro",description:"Google Gemini 3 Pro via GitHub Copilot"}]},claude:{provider:"claude",displayName:"Claude (Anthropic)",defaultModel:"claude-sonnet-4-5-20250929",models:[{id:"claude-opus-4-6",name:"Claude Opus 4.6",description:"Latest flagship model",extendedContext:!0,presetMapping:{default:"claude-opus-4-6",opus:"claude-opus-4-6",sonnet:"claude-sonnet-4-5-20250929",haiku:"claude-haiku-4-5-20251001"}},{id:"claude-opus-4-5-20251101",name:"Claude Opus 4.5",description:"Most capable Claude model",extendedContext:!0,presetMapping:{default:"claude-opus-4-5-20251101",opus:"claude-opus-4-5-20251101",sonnet:"claude-sonnet-4-5-20250929",haiku:"claude-haiku-4-5-20251001"}},{id:"claude-sonnet-4-5-20250929",name:"Claude Sonnet 4.5",description:"Balanced performance and speed",extendedContext:!0,presetMapping:{default:"claude-sonnet-4-5-20250929",opus:"claude-opus-4-5-20251101",sonnet:"claude-sonnet-4-5-20250929",haiku:"claude-haiku-4-5-20251001"}},{id:"claude-sonnet-4-20250514",name:"Claude Sonnet 4",description:"Previous generation Sonnet",extendedContext:!0,presetMapping:{default:"claude-sonnet-4-20250514",opus:"claude-opus-4-5-20251101",sonnet:"claude-sonnet-4-20250514",haiku:"claude-haiku-4-5-20251001"}},{id:"claude-haiku-4-5-20251001",name:"Claude Haiku 4.5",description:"Fast and efficient"}]}},Te="ccs-internal-managed";async function ea(){try{const s=await fetch("/api/settings/auth/tokens/raw");return s.ok?(await s.json())?.apiKey?.value??Te:Te}catch{return Te}}async function Fe(s,a){const t=fe[s];if(!t)return{success:!1};const i=t.models[0],n=i?.presetMapping||{default:t.defaultModel,opus:t.defaultModel,sonnet:t.defaultModel,haiku:t.defaultModel},l=await ea(),o={env:{ANTHROPIC_BASE_URL:`http://127.0.0.1:${Le}/api/provider/${s}`,ANTHROPIC_AUTH_TOKEN:l,ANTHROPIC_MODEL:n.default,ANTHROPIC_DEFAULT_OPUS_MODEL:n.opus,ANTHROPIC_DEFAULT_SONNET_MODEL:n.sonnet,ANTHROPIC_DEFAULT_HAIKU_MODEL:n.haiku}};try{return{success:(await fetch(`/api/settings/${s}`,{method:"PUT",headers:{"Content-Type":"application/json"},body:JSON.stringify({settings:o})})).ok,presetName:i?.name||t.defaultModel}}catch{return{success:!1}}}function sa({currentProgress:s,allSteps:a}){return e.jsx("div",{className:"flex justify-center gap-1 pt-2",children:a.map((t,i)=>e.jsx("div",{className:`w-2 h-2 rounded-full transition-colors ${s>=i?"bg-primary":"bg-muted"}`},t))})}function ta({providers:s,onSelect:a}){return e.jsx("div",{className:"grid gap-2",children:s.map(t=>e.jsxs("button",{onClick:()=>a(t.id),className:"flex items-center justify-between p-3 border rounded-lg hover:bg-muted/50 transition-colors text-left",children:[e.jsxs("div",{children:[e.jsx("div",{className:"font-medium",children:t.name}),e.jsx("div",{className:"text-xs text-muted-foreground",children:t.description})]}),e.jsx(Ds,{className:"w-4 h-4 text-muted-foreground"})]},t.id))})}function aa({selectedProvider:s,providers:a,authCommand:t,isRefreshing:i,isPending:n,onBack:l,onStartAuth:x,onRefresh:o}){const[h,f]=d.useState(!1),v=async u=>{await navigator.clipboard.writeText(u),f(!0),setTimeout(()=>f(!1),2e3)};return e.jsxs("div",{className:"space-y-4",children:[e.jsxs("div",{className:"text-center space-y-3",children:[e.jsxs("p",{className:"text-sm text-muted-foreground",children:["Authenticate with ",a.find(u=>u.id===s)?.name," to add an account"]}),e.jsx(O,{onClick:x,disabled:n,className:"w-full gap-2",size:"lg",children:n?e.jsxs(e.Fragment,{children:[e.jsx(J,{className:"w-4 h-4 animate-spin"}),"Authenticating..."]}):e.jsxs(e.Fragment,{children:[e.jsx(xe,{className:"w-4 h-4"}),"Authenticate in Browser"]})}),n&&e.jsx("p",{className:"text-xs text-muted-foreground",children:"Complete the OAuth flow in your browser..."})]}),e.jsxs("div",{className:"relative",children:[e.jsx("div",{className:"absolute inset-0 flex items-center",children:e.jsx("span",{className:"w-full border-t"})}),e.jsx("div",{className:"relative flex justify-center text-xs uppercase",children:e.jsx("span",{className:"bg-background px-2 text-muted-foreground",children:"Or use terminal"})})]}),e.jsx(ys,{children:e.jsxs(bs,{className:"p-4 space-y-3",children:[e.jsxs("div",{className:"flex items-center gap-2 text-sm text-muted-foreground",children:[e.jsx(Ft,{className:"w-4 h-4"}),"Run this command in your terminal:"]}),e.jsxs("div",{className:"flex items-center gap-2",children:[e.jsx("code",{className:"flex-1 px-3 py-2 bg-muted rounded-md font-mono text-sm",children:t}),e.jsx(O,{variant:"outline",size:"icon",onClick:()=>v(t),children:h?e.jsx(te,{className:"w-4 h-4 text-green-500"}):e.jsx(Ts,{className:"w-4 h-4"})})]})]})}),e.jsxs("div",{className:"flex items-center justify-between",children:[e.jsxs(O,{variant:"ghost",onClick:l,disabled:n,children:[e.jsx(Je,{className:"w-4 h-4 mr-2"}),"Back"]}),e.jsxs(O,{variant:"outline",onClick:o,disabled:i||n,children:[e.jsx(We,{className:`w-4 h-4 mr-2 ${i?"animate-spin":""}`}),i?"Checking...":"Refresh Status"]})]})]})}function na({accounts:s,privacyMode:a,onSelect:t,onAddNew:i,onBack:n}){return e.jsxs("div",{className:"space-y-4",children:[e.jsxs("div",{className:"text-xs font-medium text-muted-foreground uppercase tracking-wide",children:["Select an account (",s.length,")"]}),e.jsx("div",{className:"grid gap-2 max-h-[320px] overflow-y-auto pr-1",children:s.map(l=>e.jsxs("button",{type:"button",onClick:()=>t(l),className:"flex items-center justify-between p-3 border rounded-lg hover:bg-muted/50 transition-colors text-left",children:[e.jsxs("div",{className:"flex items-center gap-3",children:[e.jsx("div",{className:"w-8 h-8 rounded-full bg-muted flex items-center justify-center",children:e.jsx(pe,{className:"w-4 h-4 text-muted-foreground"})}),e.jsxs("div",{children:[e.jsx("div",{className:B("font-medium",a&&Ce),children:l.email||l.id}),l.isDefault&&e.jsx("div",{className:"text-xs text-muted-foreground",children:"Default account"})]})]}),e.jsx(Ds,{className:"w-4 h-4 text-muted-foreground"})]},l.id))}),e.jsxs("div",{className:"relative",children:[e.jsx("div",{className:"absolute inset-0 flex items-center",children:e.jsx("span",{className:"w-full border-t"})}),e.jsx("div",{className:"relative flex justify-center text-xs uppercase",children:e.jsx("span",{className:"bg-background px-2 text-muted-foreground",children:"Or"})})]}),e.jsxs("button",{type:"button",className:"w-full flex items-center gap-3 p-3 border-2 border-dashed border-primary/50 rounded-lg hover:border-primary hover:bg-primary/5 transition-colors text-left",onClick:i,children:[e.jsx("div",{className:"w-8 h-8 rounded-full bg-primary/10 flex items-center justify-center shrink-0",children:e.jsx(xe,{className:"w-4 h-4 text-primary"})}),e.jsxs("div",{children:[e.jsx("div",{className:"font-medium text-primary",children:"Add new account"}),e.jsx("div",{className:"text-xs text-muted-foreground",children:"Authenticate with a different account"})]})]}),e.jsx("div",{className:"flex items-center justify-between pt-2",children:e.jsxs(O,{variant:"ghost",onClick:n,children:[e.jsx(Je,{className:"w-4 h-4 mr-2"}),"Back"]})})]})}const gs="__custom__";function ia({selectedProvider:s,selectedAccount:a,variantName:t,modelName:i,isPending:n,privacyMode:l,onVariantNameChange:x,onModelChange:o,onBack:h,onSkip:f,onCreate:v}){const{t:u}=Z(),r=fe[s]?.models||[],y=i&&!r.some(m=>m.id===i),[j,p]=d.useState(y),D=m=>{m===gs?(p(!0),o("")):(p(!1),o(m))};return e.jsxs("div",{className:"space-y-4",children:[a&&e.jsxs("div",{className:"flex items-center gap-2 p-2 bg-muted/50 rounded-md text-sm",children:[e.jsx(pe,{className:"w-4 h-4"}),e.jsxs("span",{children:[u("setupVariant.using")," ",e.jsx("span",{className:B(l&&Ce),children:a.email||a.id})]})]}),e.jsxs("div",{className:"space-y-2",children:[e.jsx(W,{htmlFor:"variant-name",children:u("setupVariant.variantNameRequired")}),e.jsx(oe,{id:"variant-name",value:t,onChange:m=>x(m.target.value),placeholder:u("setupVariant.variantNamePlaceholder")}),e.jsxs("div",{className:"text-xs text-muted-foreground",children:[u("setupVariant.invokeHintPrefix")," ccs ",t||"<name>",' "prompt"']})]}),e.jsxs("div",{className:"space-y-2",children:[e.jsx(W,{children:u("setupVariant.model")}),j?e.jsxs("div",{className:"space-y-2",children:[e.jsx(oe,{value:i,onChange:m=>o(m.target.value),placeholder:u("setupVariant.modelPlaceholder")}),e.jsx("button",{type:"button",className:"text-xs text-primary hover:underline",onClick:()=>p(!1),children:u("setupVariant.choosePresetInstead")})]}):e.jsxs(qe,{value:r.some(m=>m.id===i)?i:"",onValueChange:D,children:[e.jsx(Ke,{children:e.jsx(He,{placeholder:u("setupVariant.selectModel")})}),e.jsxs(Ve,{children:[r.map(m=>e.jsx(ge,{value:m.id,children:e.jsxs("div",{className:"flex items-center gap-2",children:[e.jsx("span",{children:m.name}),m.description&&e.jsxs("span",{className:"text-xs text-muted-foreground",children:["- ",m.description]})]})},m.id)),e.jsx(ge,{value:gs,children:e.jsx("span",{className:"text-primary",children:u("setupVariant.customModelName")})})]})]}),e.jsx("div",{className:"text-xs text-muted-foreground",children:j?u("setupVariant.enterAnyModel"):u("setupVariant.defaultModel",{model:fe[s]?.defaultModel||u("setupVariant.providerDefault")})})]}),e.jsxs("div",{className:"flex items-center justify-between pt-2",children:[e.jsxs(O,{variant:"ghost",onClick:h,children:[e.jsx(Je,{className:"w-4 h-4 mr-2"}),u("setupVariant.back")]}),e.jsxs("div",{className:"flex items-center gap-2",children:[e.jsx(O,{variant:"ghost",onClick:f,children:u("setupVariant.skip")}),e.jsx(O,{onClick:v,disabled:!t||n,children:u(n?"setupVariant.creating":"setupVariant.createVariant")})]})]}),e.jsx("p",{className:"text-xs text-center text-muted-foreground",children:u("setupVariant.skipHint")})]})}function ra({variantName:s,onClose:a}){return e.jsxs("div",{className:"space-y-4 text-center",children:[e.jsx("div",{className:"flex justify-center",children:e.jsx("div",{className:"w-16 h-16 bg-green-100 dark:bg-green-900/30 rounded-full flex items-center justify-center",children:e.jsx(te,{className:"w-8 h-8 text-green-600 dark:text-green-400"})})}),e.jsxs("div",{children:[e.jsx("div",{className:"font-semibold text-lg",children:"Variant Created!"}),e.jsx("div",{className:"text-sm text-muted-foreground",children:"Your custom variant is ready to use"})]}),e.jsx(ys,{children:e.jsxs(bs,{className:"p-4 space-y-2",children:[e.jsx("div",{className:"text-sm text-muted-foreground",children:"Usage:"}),e.jsxs("code",{className:"block px-3 py-2 bg-muted rounded-md font-mono text-sm",children:["ccs ",s,' "your prompt here"']})]})}),e.jsx(O,{onClick:a,className:"w-full",children:"Done"})]})}function oa({open:s,onClose:a}){const[t,i]=d.useState("provider"),[n,l]=d.useState(""),[x,o]=d.useState(null),[h,f]=d.useState(""),[v,u]=d.useState(""),[r,y]=d.useState(!1),[j,p]=d.useState(!1),{data:D,refetch:m}=ks(),R=Qs(),E=zs(),b=Js(),{privacyMode:L}=Cs(),A=D?.authStatus.find(P=>P.provider===n),g=d.useMemo(()=>A?.accounts||[],[A?.accounts]);d.useEffect(()=>{if(!s){const P=setTimeout(()=>{i("provider"),l(""),o(null),f(""),u(""),p(!1)},0);return()=>clearTimeout(P)}},[s]),d.useEffect(()=>{if(t==="auth"&&g.length>0&&!j){const P=setTimeout(()=>{i("account")},0);return()=>clearTimeout(P)}},[t,g,j]);const I=async()=>{y(!0),await m(),y(!1)},N=()=>{const P=(A?.accounts?.length||0)===0;E.mutate({provider:n},{onSuccess:async _=>{if(P){const F=await Fe(n);F.success&&F.presetName?K.success(`Applied "${F.presetName}" preset`):F.success||K.warning(Ss.t("commonToast.accountAddedPresetFailed"))}_.account&&(o(_.account),i("variant")),m()}})},k=P=>{l(P),(D?.authStatus.find(H=>H.provider===P)?.accounts||[]).length===0?i("auth"):i("account")},w=P=>{o(P),i("variant")},M=async()=>{if(!(!h||!n))try{await R.mutateAsync({name:h,provider:n,model:v||void 0,account:x?.id}),i("success")}catch(P){console.error("Failed to create variant:",P)}},C=`ccs ${n} --auth --add`,q=Ys(t),G=P=>{if(!P&&(E.isPending&&n&&b.mutate(n),t==="success"||t==="provider")){a();return}};return e.jsx(Be,{open:s,onOpenChange:G,children:e.jsxs(Ge,{className:"sm:max-w-lg",onPointerDownOutside:P=>{t!=="success"&&t!=="provider"&&P.preventDefault()},onEscapeKeyDown:P=>{(E.isPending||R.isPending)&&P.preventDefault()},children:[e.jsxs($e,{children:[e.jsxs(Qe,{className:"flex items-center gap-2",children:[e.jsx(je,{className:"w-5 h-5 text-primary"}),"Quick Setup Wizard"]}),e.jsxs(As,{children:[t==="provider"&&"Select a provider to get started",t==="auth"&&"Authenticate with your provider",t==="account"&&"Select which account to use",t==="variant"&&"Create your custom variant",t==="success"&&"Setup complete!"]})]}),e.jsxs("div",{className:"space-y-4 py-4",children:[t==="provider"&&e.jsx(ta,{providers:rs,onSelect:k}),t==="auth"&&e.jsx(aa,{selectedProvider:n,providers:rs,authCommand:C,isRefreshing:r,isPending:E.isPending,onBack:()=>i("provider"),onStartAuth:N,onRefresh:I}),t==="account"&&e.jsx(na,{accounts:g,privacyMode:L,onSelect:w,onAddNew:()=>{p(!0),i("auth")},onBack:()=>i("provider")}),t==="variant"&&e.jsx(ia,{selectedProvider:n,selectedAccount:x,variantName:h,modelName:v,isPending:R.isPending,privacyMode:L,onVariantNameChange:f,onModelChange:u,onBack:()=>g.length>0?i("account"):i("provider"),onSkip:a,onCreate:M}),t==="success"&&e.jsx(ra,{variantName:h,onClose:a})]}),e.jsx(sa,{currentProgress:q,allSteps:Ws})]})})}const la=3e3,ca=300*1e3;async function Ee(s){const a=await s.text();if(!a)return{};try{return JSON.parse(a)}catch{const t=s.status>=400?`Request failed with status ${s.status}`:void 0;return t?{error:t}:{}}}const re={provider:null,isAuthenticating:!1,error:null,authUrl:null,oauthState:null,isSubmittingCallback:!1,isDeviceCodeFlow:!1};function da(){const[s,a]=d.useState(re),t=d.useRef(null),i=d.useRef(null),n=d.useRef(0),l=d.useRef(!1),x=Ue(),o=d.useCallback(()=>{i.current&&(clearInterval(i.current),i.current=null)},[]);d.useEffect(()=>()=>{t.current?.abort(),o(),l.current=!1},[o]);const h=d.useCallback(async(r,y)=>{if(Date.now()-n.current>ca){o(),a(j=>({...j,isAuthenticating:!1,error:"Authentication timed out. Please try again."}));return}try{const p=await(await fetch(`/api/cliproxy/auth/${r}/status?state=${encodeURIComponent(y)}`)).json();if(p.status==="ok")o(),x.invalidateQueries({queryKey:["cliproxy-auth"]}),x.invalidateQueries({queryKey:["account-quota"]}),K.success(`${r} authentication successful`),l.current=!1,a(re);else if(p.status==="auth_url"){const D=p.url||p.auth_url;D&&(a(m=>({...m,authUrl:D})),l.current||(l.current=!0,window.open(D,"_blank")))}else if(p.status==="device_code"){o();const D=p.user_code&&p.verification_url?`Open ${p.verification_url} and enter code: ${p.user_code}`:"Switch to Device Code method and try again.";K.error("Provider returned Device Code flow in callback mode"),a(m=>({...m,isAuthenticating:!1,error:D}))}else if(p.status==="error"){o();const D=p.error||"Authentication failed";K.error(D),a(m=>({...m,isAuthenticating:!1,error:D}))}}catch{}},[x,o]),f=d.useCallback(async(r,y)=>{if(!Oe(r)){a({...re,error:`Unknown provider: ${r}`});return}t.current?.abort(),o(),l.current=!1;const j=new AbortController;t.current=j;const D=(y?.flowType||(Ps(r)?"device_code":"authorization_code"))==="device_code",m=y?.startEndpoint||(D?"start":"start-url"),R={nickname:y?.nickname,kiroMethod:y?.kiroMethod,riskAcknowledgement:y?.riskAcknowledgement};a({provider:r,isAuthenticating:!0,error:null,authUrl:null,oauthState:null,isSubmittingCallback:!1,isDeviceCodeFlow:D});try{if(m==="start")fetch(`/api/cliproxy/auth/${r}/start`,{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify(R),signal:j.signal}).then(async E=>{const b=await Ee(E),L=b.success===!0;if(E.ok&&L)x.invalidateQueries({queryKey:["cliproxy-auth"]}),x.invalidateQueries({queryKey:["account-quota"]}),l.current=!1,a(re);else{const A=typeof b.error=="string"?b.error:"Authentication failed";K.error(A),a(g=>({...g,isAuthenticating:!1,error:A}))}}).catch(E=>{if(E instanceof Error&&E.name==="AbortError")return;const b=E instanceof Error?E.message:"Authentication failed";K.error(b),a(L=>({...L,isAuthenticating:!1,error:b}))});else{const E=await fetch(`/api/cliproxy/auth/${r}/start-url`,{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify(R),signal:j.signal}),b=await Ee(E),L=b.success===!0;if(!E.ok||!L){const I=typeof b.error=="string"?b.error:"Failed to start OAuth";throw new Error(I)}const A=typeof b.authUrl=="string"?b.authUrl:null,g=typeof b.state=="string"?b.state:null;a(I=>({...I,authUrl:A,oauthState:g})),A&&(l.current=!0,window.open(A,"_blank")),g&&(n.current=Date.now(),i.current=setInterval(()=>{h(r,g)},la))}}catch(E){if(E instanceof Error&&E.name==="AbortError"){l.current=!1,a(re);return}const b=E instanceof Error?E.message:"Authentication failed";K.error(b),a(L=>({...L,isAuthenticating:!1,error:b}))}},[h,o,x]),v=d.useCallback(()=>{const r=s.provider;t.current?.abort(),o(),l.current=!1,a(re),r&&ye.cliproxy.auth.cancel(r).catch(()=>{})},[s.provider,o]),u=d.useCallback(async r=>{if(s.provider){a(y=>({...y,isSubmittingCallback:!0,error:null}));try{const y=await fetch(`/api/cliproxy/auth/${s.provider}/submit-callback`,{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify({redirectUrl:r})}),j=await Ee(y),p=j.success===!0;if(y.ok&&p)o(),x.invalidateQueries({queryKey:["cliproxy-auth"]}),x.invalidateQueries({queryKey:["account-quota"]}),K.success(`${s.provider} authentication successful`),a(re);else{const D=typeof j.error=="string"?j.error:"Callback submission failed";throw new Error(D)}}catch(y){const j=y instanceof Error?y.message:"Failed to submit callback";K.error(j),a(p=>({...p,isSubmittingCallback:!1,error:j}))}}},[s.provider,x,o]);return d.useMemo(()=>({...s,startAuth:f,cancelAuth:v,submitCallback:u}),[s,f,v,u])}function qs({className:s,showAcknowledgement:a=!1,acknowledgementPhrase:t=be,acknowledgementText:i="",onAcknowledgementTextChange:n,disabled:l=!1,showProxySettingsLink:x=!1}){const{t:o}=Z(),h=o("accountSafetyWarning.title"),f=o("accountSafetyWarning.subtitle"),v=o("accountSafetyWarning.firstLine"),u=o("accountSafetyWarning.secondLine"),r="https://github.com/kaitranntt/ccs/issues/509",y=o("accountSafetyWarning.issueLabel"),j=o("accountSafetyWarning.proxySettingsLabel");return e.jsxs("section",{role:"alert",className:B("relative overflow-hidden rounded-xl border border-amber-500/30 bg-gradient-to-br from-amber-50 via-background to-rose-50/70 shadow-sm dark:from-amber-950/20 dark:to-rose-950/20",s),children:[e.jsx("div",{className:"absolute inset-x-0 top-0 h-0.5 bg-gradient-to-r from-amber-500 via-orange-500 to-rose-500"}),e.jsxs("div",{className:"space-y-3 p-4",children:[e.jsxs("div",{className:"flex items-start justify-between gap-3",children:[e.jsxs("div",{className:"flex items-start gap-2.5",children:[e.jsx("div",{className:"mt-0.5 inline-flex h-7 w-7 items-center justify-center rounded-md bg-amber-500/15 text-amber-700 dark:text-amber-400",children:e.jsx(Ye,{className:"h-4 w-4"})}),e.jsxs("div",{children:[e.jsx("p",{className:"text-sm font-semibold leading-5",children:h}),e.jsx("p",{className:"text-xs text-muted-foreground",children:f})]})]}),e.jsx(U,{variant:"outline",className:"border-amber-500/40 text-amber-700 dark:text-amber-300",children:"High Risk"})]}),e.jsxs("div",{className:"space-y-2 text-sm leading-relaxed",children:[e.jsx("p",{children:v}),e.jsx("p",{className:"font-medium text-amber-900 dark:text-amber-200",children:u}),e.jsx("p",{className:"text-xs text-muted-foreground",children:"CCS is provided as-is and does not take responsibility for suspension, bans, or access loss from upstream providers."})]}),e.jsxs("div",{className:"flex flex-wrap items-center gap-2",children:[e.jsxs("a",{href:r,target:"_blank",rel:"noreferrer",className:"inline-flex items-center gap-1.5 rounded-md border border-amber-500/30 bg-amber-500/10 px-2.5 py-1 text-xs font-medium text-amber-800 transition-colors hover:bg-amber-500/15 dark:text-amber-200",children:[y,e.jsx(xe,{className:"h-3.5 w-3.5"})]}),x&&e.jsxs("a",{href:"/settings?tab=proxy",className:"inline-flex items-center gap-1.5 rounded-md border border-amber-500/30 bg-amber-500/10 px-2.5 py-1 text-xs font-medium text-amber-800 transition-colors hover:bg-amber-500/15 dark:text-amber-200",children:[e.jsx(Ut,{className:"h-3.5 w-3.5"}),j]}),e.jsx("span",{className:"rounded-md border border-border/70 bg-muted/60 px-2.5 py-1 text-xs text-muted-foreground",children:"Applies to CLI and dashboard auth"})]}),a&&n&&e.jsxs("div",{className:"rounded-lg border border-amber-500/25 bg-amber-500/5 p-2.5",children:[e.jsxs(W,{htmlFor:"account-risk-ack-text",className:"text-xs leading-5",children:["Type exact phrase to continue:"," ",e.jsx("code",{className:"rounded bg-muted px-1 py-0.5 font-mono",children:t})]}),e.jsx(oe,{id:"account-risk-ack-text",value:i,onChange:p=>n(p.target.value),placeholder:t,disabled:l,className:"mt-2 font-mono text-xs"})]})]})]})}function ua({className:s,value:a,onChange:t,disabled:i=!1}){const{t:n}=Z(),l=[a.reviewedIssue509,a.understandsBanRisk,a.acceptsFullResponsibility,a.typedPhrase.trim().replace(/\s+/g," ").toUpperCase()===hs].filter(Boolean).length,x=l/4*100,o=h=>{t({...a,...h})};return e.jsxs("section",{role:"alert",className:B("relative overflow-hidden rounded-xl border border-rose-500/35 bg-gradient-to-br from-rose-50 via-background to-amber-50/70 p-4 shadow-sm dark:from-rose-950/20 dark:to-amber-950/20",s),children:[e.jsx("div",{className:"absolute inset-x-0 top-0 h-0.5 bg-gradient-to-r from-rose-500 via-orange-500 to-amber-500"}),e.jsxs("div",{className:"space-y-4",children:[e.jsxs("div",{className:"flex items-start justify-between gap-3",children:[e.jsxs("div",{className:"flex items-start gap-2.5",children:[e.jsx("div",{className:"mt-0.5 inline-flex h-7 w-7 items-center justify-center rounded-md bg-rose-500/15 text-rose-700 dark:text-rose-300",children:e.jsx(Ye,{className:"h-4 w-4"})}),e.jsxs("div",{className:"space-y-1",children:[e.jsx("p",{className:"text-sm font-semibold leading-5",children:n("antigravityChecklist.title")}),e.jsx("p",{className:"text-xs text-muted-foreground",children:n("antigravityChecklist.subtitle")})]})]}),e.jsx(U,{variant:"outline",className:"border-rose-500/40 text-rose-700 dark:text-rose-300",children:n("antigravityChecklist.mandatory")})]}),e.jsxs("div",{className:"space-y-1.5",children:[e.jsxs("div",{className:"flex items-center justify-between text-xs text-muted-foreground",children:[e.jsx("span",{children:n("antigravityChecklist.completion")}),e.jsx("span",{children:n("antigravityChecklist.stepsCount",{current:l})})]}),e.jsx(_e,{value:x,className:"h-2"})]}),e.jsxs("div",{className:"space-y-3 rounded-lg border border-rose-500/20 bg-rose-500/5 p-3",children:[e.jsxs("div",{className:"flex items-start gap-2",children:[e.jsx(ke,{id:"agy-step-reviewed-issue",checked:a.reviewedIssue509,onCheckedChange:h=>o({reviewedIssue509:!!h}),disabled:i}),e.jsx(W,{htmlFor:"agy-step-reviewed-issue",className:"text-xs leading-5",children:"Step 1: I reviewed issue #509 and understand AGY OAuth can trigger account bans/suspensions."})]}),e.jsxs("div",{className:"flex items-start gap-2",children:[e.jsx(ke,{id:"agy-step-understands-risk",checked:a.understandsBanRisk,onCheckedChange:h=>o({understandsBanRisk:!!h}),disabled:i}),e.jsx(W,{htmlFor:"agy-step-understands-risk",className:"text-xs leading-5",children:"Step 2: I understand this OAuth action is my own decision and I accept the upstream risk."})]}),e.jsxs("div",{className:"flex items-start gap-2",children:[e.jsx(ke,{id:"agy-step-accept-responsibility",checked:a.acceptsFullResponsibility,onCheckedChange:h=>o({acceptsFullResponsibility:!!h}),disabled:i}),e.jsx(W,{htmlFor:"agy-step-accept-responsibility",className:"text-xs leading-5",children:"Step 3: I accept full responsibility. CCS is not liable for suspension, bans, or access loss."})]})]}),e.jsxs("div",{className:"space-y-2 rounded-lg border border-amber-500/25 bg-amber-500/5 p-3",children:[e.jsxs("div",{className:"flex items-center gap-1.5 text-xs font-medium text-amber-800 dark:text-amber-200",children:[e.jsx(Es,{className:"h-3.5 w-3.5"}),"Step 4: Type exact phrase to continue"]}),e.jsx(oe,{value:a.typedPhrase,onChange:h=>o({typedPhrase:h.target.value}),placeholder:hs,disabled:i,className:"font-mono text-xs"})]}),e.jsx("div",{className:"flex flex-wrap items-center gap-2 text-xs",children:e.jsxs("a",{href:"https://github.com/kaitranntt/ccs/issues/509",target:"_blank",rel:"noreferrer",className:"inline-flex items-center gap-1.5 rounded-md border border-rose-500/30 bg-rose-500/10 px-2.5 py-1 font-medium text-rose-800 transition-colors hover:bg-rose-500/15 dark:text-rose-200",children:["Read issue #509",e.jsx(xe,{className:"h-3.5 w-3.5"})]})})]})]})}function ma(s){return s.trim().replace(/\s+/g," ").toUpperCase()}function xa({open:s,onClose:a,provider:t,displayName:i,isFirstAccount:n=!1}){const[l,x]=d.useState(""),[o,h]=d.useState(""),[f,v]=d.useState(!1),[u,r]=d.useState(null),[y,j]=d.useState(""),[p,D]=d.useState(De),[m,R]=d.useState(!1),[E,b]=d.useState(!1),[L,A]=d.useState(os),{t:g}=Z(),I=d.useRef(!1),N=da(),k=Xs(),w=t==="kiro",M=t==="gemini",C=t==="agy"&&!m,q=t==="agy"&&E,G=Wt(p),P=ma(y)===be,_=Ps(t),F=Zs(t),H=et(L),ee=w?H.flowType==="device_code":_,$=N.isAuthenticating||k.isPending,Y=l.trim(),X=u||N.error,c=d.useCallback(async()=>{const S=await fetch("/api/settings/auth/antigravity-risk");if(!S.ok)throw new Error("Failed to load Antigravity power user setting");return(await S.json()).antigravityAckBypass===!0},[]),T=()=>{x(""),h(""),v(!1),r(null),j(""),D(De),R(!1),b(!1),A(os),I.current=!1,a()};d.useEffect(()=>{s&&(j(""),D(De),r(null))},[t,s]),d.useEffect(()=>{let S=!1;if(!s||t!=="agy"){R(!1),b(!1);return}return(async()=>{try{b(!0);const ae=await c();S||R(ae)}catch{S||R(!1)}finally{S||b(!1)}})(),()=>{S=!0}},[c,s,t]),d.useEffect(()=>{if(!s||t!=="agy"||!N.error||!m)return;const S=N.error.toLowerCase();if(!(S.includes("agy_risk_ack_required")||S.includes("responsibility acknowledgement")||S.includes("responsibility checklist")))return;let ae=!1;return(async()=>{try{b(!0);const we=await c();if(ae)return;R(we),we||r("Power user mode is off. Complete the AGY checklist and retry.")}catch{if(ae)return;R(!1),r("Power user mode is off. Complete the AGY checklist and retry.")}finally{ae||b(!1)}})(),()=>{ae=!0}},[m,N.error,c,s,t]),d.useEffect(()=>{!N.isAuthenticating&&!N.error&&N.provider===null&&s&&I.current&&(I.current=!1,(async()=>{try{const se=await Fe(t);se.success&&se.presetName&&n&&K.success(`Applied "${se.presetName}" preset`)}catch{}T()})())},[N.isAuthenticating,N.error,N.provider]);const Q=()=>{N.cancelAuth(),T()},he=async()=>{N.authUrl&&(await navigator.clipboard.writeText(N.authUrl),v(!0),setTimeout(()=>v(!1),2e3))},Se=()=>{o.trim()&&N.submitCallback(o.trim())},Pe=()=>{if(q){r("Loading Antigravity safety settings. Please wait a moment and retry.");return}if(C&&!G){r("Complete all Antigravity responsibility steps before authenticating this provider.");return}if(M&&!P){r(`Type "${be}" to acknowledge the account safety warning before authenticating this provider.`);return}if(F&&!Y){r(`Nickname is required for ${i} accounts.`);return}r(null),I.current=!0,N.startAuth(t,{nickname:Y||void 0,kiroMethod:w?L:void 0,flowType:w?H.flowType:void 0,startEndpoint:w?H.startEndpoint:void 0,riskAcknowledgement:C?{version:Yt,reviewedIssue509:p.reviewedIssue509,understandsBanRisk:p.understandsBanRisk,acceptsFullResponsibility:p.acceptsFullResponsibility,typedPhrase:p.typedPhrase}:void 0})},Me=()=>{I.current=!0,k.mutate(void 0,{onSuccess:async()=>{const S=await Fe("kiro");S.success&&S.presetName&&n&&K.success(`Applied "${S.presetName}" preset`),T()}})},Ne=S=>{S||Q()},z=N.isAuthenticating;return e.jsx(Be,{open:s,onOpenChange:Ne,children:e.jsxs(Ge,{className:"sm:max-w-md",onInteractOutside:S=>{z&&S.preventDefault()},children:[e.jsxs($e,{children:[e.jsx(Qe,{children:g("addAccountDialog.title",{displayName:i})}),e.jsx(As,{children:g(w?"addAccountDialog.descKiro":ee?"addAccountDialog.descDeviceCode":"addAccountDialog.descOauth")})]}),e.jsxs("div",{className:"space-y-4 py-4",children:[C&&!z&&e.jsx(ua,{value:p,onChange:S=>{D(S),r(null)},disabled:$}),t==="agy"&&m&&!z&&e.jsxs("div",{className:"rounded-lg border border-amber-400/35 bg-amber-50/70 p-3 text-xs text-amber-900 dark:border-amber-800/60 dark:bg-amber-950/25 dark:text-amber-100",children:[e.jsxs("div",{className:"mb-1.5 flex items-center gap-1.5 font-semibold",children:[e.jsx(Es,{className:"h-3.5 w-3.5"}),g("addAccountDialog.powerUserEnabled")]}),g("addAccountDialog.powerUserSkipped")]}),M&&!z&&e.jsx(qs,{showAcknowledgement:!0,acknowledgementPhrase:be,acknowledgementText:y,onAcknowledgementTextChange:S=>{j(S),r(null)},disabled:$}),w&&!z&&e.jsxs("div",{className:"space-y-2",children:[e.jsx(W,{htmlFor:"kiro-auth-method",children:g("addAccountDialog.authMethod")}),e.jsxs(qe,{value:L,onValueChange:S=>{A(S),r(null)},children:[e.jsx(Ke,{id:"kiro-auth-method",children:e.jsx(He,{placeholder:g("addAccountDialog.selectKiroAuthMethod")})}),e.jsx(Ve,{children:st.map(S=>e.jsx(ge,{value:S.id,children:S.label},S.id))})]}),e.jsx("p",{className:"text-xs text-muted-foreground",children:H.description})]}),!z&&e.jsxs("div",{className:"space-y-2",children:[e.jsx(W,{htmlFor:"nickname",children:g(F?"addAccountDialog.nicknameRequired":"addAccountDialog.nicknameOptional")}),e.jsxs("div",{className:"flex items-center gap-2",children:[e.jsx(pe,{className:"w-4 h-4 text-muted-foreground"}),e.jsx(oe,{id:"nickname",value:l,onChange:S=>{x(S.target.value),r(null)},placeholder:g("addAccountDialog.nicknamePlaceholder"),disabled:$,className:"flex-1"})]}),e.jsx("p",{className:"text-xs text-muted-foreground",children:g(F?"addAccountDialog.nicknameRequiredHint":"addAccountDialog.nicknameOptionalHint")})]}),z&&e.jsxs("div",{className:"space-y-4",children:[e.jsxs("div",{className:"text-center",children:[e.jsxs("p",{className:"text-sm text-muted-foreground",children:[e.jsx(J,{className:"w-4 h-4 inline mr-2 animate-spin"}),g("addAccountDialog.waitingForAuth")]}),e.jsx("p",{className:"text-xs text-muted-foreground mt-1",children:N.isDeviceCodeFlow?g("addAccountDialog.deviceCodeHint"):g("addAccountDialog.browserHint")})]}),N.authUrl&&!N.isDeviceCodeFlow&&e.jsxs("div",{className:"space-y-3",children:[e.jsxs("div",{className:"space-y-2",children:[e.jsx(W,{className:"text-xs",children:g("addAccountDialog.openUrlLabel")}),e.jsxs("div",{className:"p-3 bg-muted rounded-md",children:[e.jsx("p",{className:"text-xs text-muted-foreground break-all font-mono line-clamp-3",children:N.authUrl}),e.jsxs("div",{className:"flex gap-2 mt-2",children:[e.jsx(O,{variant:"outline",size:"sm",onClick:he,children:f?e.jsxs(e.Fragment,{children:[e.jsx(te,{className:"w-3 h-3 mr-1"}),g("addAccountDialog.copied")]}):e.jsxs(e.Fragment,{children:[e.jsx(Ts,{className:"w-3 h-3 mr-1"}),g("addAccountDialog.copy")]})}),e.jsxs(O,{variant:"outline",size:"sm",onClick:()=>{if(!N.authUrl)return;const S=window.open(N.authUrl,"_blank");(!S||S.closed||typeof S.closed>"u")&&K.warning(g("addAccountDialog.popupBlocked"),{duration:5e3})},children:[e.jsx(xe,{className:"w-3 h-3 mr-1"}),g("addAccountDialog.open")]})]})]})]}),e.jsxs("div",{className:"space-y-2",children:[e.jsx(W,{htmlFor:"callback-url",className:"text-xs",children:g("addAccountDialog.redirectPasteLabel")}),e.jsx(oe,{id:"callback-url",value:o,onChange:S=>h(S.target.value),placeholder:g("addAccountDialog.callbackPlaceholder"),className:"font-mono text-xs"}),e.jsx(O,{variant:"secondary",size:"sm",onClick:Se,disabled:!o.trim()||N.isSubmittingCallback,children:N.isSubmittingCallback?e.jsxs(e.Fragment,{children:[e.jsx(J,{className:"w-3 h-3 mr-1 animate-spin"}),g("addAccountDialog.submitting")]}):g("addAccountDialog.submitCallback")})]})]}),!N.authUrl&&!N.isDeviceCodeFlow&&e.jsx("p",{className:"text-xs text-center text-muted-foreground",children:g("addAccountDialog.preparingUrl")})]}),X&&e.jsx("p",{className:"text-xs text-center text-destructive",children:X}),k.isPending&&e.jsxs("p",{className:"text-sm text-center text-muted-foreground",children:[e.jsx(J,{className:"w-4 h-4 inline mr-2 animate-spin"}),g("addAccountDialog.importingToken")]}),e.jsxs("div",{className:"flex items-center justify-end gap-2 pt-2",children:[e.jsx(O,{variant:"ghost",onClick:Q,children:g("addAccountDialog.cancel")}),w&&!z&&e.jsx(O,{variant:"outline",onClick:Me,disabled:$,children:k.isPending?e.jsxs(e.Fragment,{children:[e.jsx(J,{className:"w-4 h-4 mr-2 animate-spin"}),g("addAccountDialog.importing")]}):e.jsxs(e.Fragment,{children:[e.jsx(qt,{className:"w-4 h-4 mr-2"}),g("addAccountDialog.importFromIde")]})}),!z&&e.jsxs(O,{onClick:Pe,disabled:$||q||F&&!Y||C&&!G||M&&!P,children:[e.jsx(xe,{className:"w-4 h-4 mr-2"}),g("addAccountDialog.authenticate")]})]})]})]})})}const es="[1m]";function pa(s){return s.toLowerCase().startsWith("gemini-")}function ss(s){return s.toLowerCase().endsWith(es.toLowerCase())}function ha(s){return!s||ss(s)?s:`${s}${es}`}function Ks(s){return s&&(ss(s)?s.slice(0,-es.length):s)}const fs=["ANTHROPIC_MODEL"],ga=["ANTHROPIC_BASE_URL","ANTHROPIC_AUTH_TOKEN"];function fa(s){const a=s?.env||{};return ga.filter(t=>!a[t]?.trim())}function ja(s){const[a,t]=d.useState(null),[i,n]=d.useState(!1),l=Ue(),{data:x,isLoading:o,refetch:h}=ws({queryKey:["settings",s],queryFn:async()=>{const k=await fetch(`/api/settings/${s}/raw`);return k.ok?k.json():{profile:s,settings:{env:{}},mtime:Date.now(),path:`~/.ccs/profiles/${s}/settings.json`}}}),f=x?.settings,v=d.useMemo(()=>a!==null?a:f?JSON.stringify(f,null,2):`{
1
+ import{j as e}from"./radix-ui-BR1vy4kf.js";import{r as d}from"./react-vendor-CNOkPC89.js";import{a as Ue,u as ws,b as $s}from"./tanstack-e99Cjjy2.js";import{d as O,C as ys,b as bs,c as B,P as Ce,a as Z,L as W,I as oe,r as qe,s as Ke,t as He,v as Ve,w as ge,a3 as ks,a4 as Qs,a5 as zs,a6 as Js,u as Cs,a7 as Be,a8 as Ge,a9 as $e,aa as Qe,ab as As,ac as rs,ad as Ws,ae as Ys,W as Ss,af as Oe,ag as Ps,Y as ye,B as U,ah as _e,ai as os,aj as Xs,ak as Zs,al as et,am as st,an as ls,ao as cs,ap as tt,x as Ms,n as ze,aq as at,ar as nt,as as it,m as rt,at as ot,au as lt,av as ct,aw as dt,ax as ut,ay as mt,az as le,T as ce,p as de,q as ue,aA as xt,aB as pt,aC as ht,aD as ds,aE as gt,aF as ft,aG as jt,aH as vt,aI as Nt,aJ as wt,aK as yt,Q as bt,R as kt,U as us,V as ms,aL as Ct,aM as At,aN as St,aO as Pt,aP as Mt,aQ as Dt,aR as Tt,aS as Et,aT as Rt,aU as Ot,aV as _t,aW as Lt,S as It}from"./index-UzqXH0bn.js";import{C as Le}from"./default-ports-1QQSffYX.js";import{t as K}from"./notifications-B2HqRBj7.js";import{C as Ds,L as J,n as xe,N as Ft,k as te,m as Ts,ao as Je,R as We,o as pe,a2 as je,T as Ye,a0 as Ut,ap as Es,aq as qt,ar as Ae,Z as ve,J as Rs,g as Kt,s as Os,as as Ht,ai as Vt,X as Xe,a1 as _s,w as Ls,x as Ie,at as Bt,t as xs,au as Gt,ah as Is,u as $t,av as ps,l as Qt,a3 as zt,al as Jt,aw as Fs}from"./icons-kPbuhVdj.js";import{R as be,A as hs,D as De,i as Wt,a as Yt,P as Xt}from"./proxy-status-widget-FJrBfPdV.js";import{C as ke}from"./checkbox-Df7G7a1w.js";import{C as Zt}from"./confirm-dialog-Dl3qe-0j.js";import{S as Ze}from"./separator-B8bpSt_-.js";import{S as Us}from"./switch-kyFX8Qe1.js";import"./utils-CzKF5WmX.js";import"./form-utils-Cn_Uld6y.js";import"./code-highlight-BRUf_pqB.js";import"./alert-dialog-zpinTbtF.js";const fe={agy:{provider:"agy",displayName:"Antigravity",defaultModel:"claude-opus-4-6-thinking",models:[{id:"claude-opus-4-6-thinking",name:"Claude Opus 4.6 Thinking",description:"Latest flagship, extended thinking",extendedContext:!1,presetMapping:{default:"claude-opus-4-6-thinking",opus:"claude-opus-4-6-thinking",sonnet:"claude-sonnet-4-6",haiku:"claude-sonnet-4-6"}},{id:"claude-opus-4-5-thinking",name:"Claude Opus 4.5 Thinking",description:"Previous flagship, extended thinking",presetMapping:{default:"claude-opus-4-5-thinking",opus:"claude-opus-4-5-thinking",sonnet:"claude-sonnet-4-6",haiku:"claude-sonnet-4-6"}},{id:"claude-sonnet-4-6",name:"Claude Sonnet 4.6",description:"Latest Sonnet with thinking budget support",presetMapping:{default:"claude-sonnet-4-6",opus:"claude-opus-4-6-thinking",sonnet:"claude-sonnet-4-6",haiku:"claude-sonnet-4-6"}},{id:"claude-sonnet-4-5-thinking",name:"Claude Sonnet 4.5 Thinking",description:"Balanced with extended thinking",presetMapping:{default:"claude-sonnet-4-5-thinking",opus:"claude-opus-4-6-thinking",sonnet:"claude-sonnet-4-5-thinking",haiku:"claude-sonnet-4-5"}},{id:"claude-sonnet-4-5",name:"Claude Sonnet 4.5",description:"Fast and capable",presetMapping:{default:"claude-sonnet-4-5",opus:"claude-opus-4-6-thinking",sonnet:"claude-sonnet-4-5",haiku:"claude-sonnet-4-5"}},{id:"gemini-3-pro-preview",name:"Gemini 3 Pro",description:"Google latest model via Antigravity",extendedContext:!0,presetMapping:{default:"gemini-3-pro-preview",opus:"gemini-3-pro-preview",sonnet:"gemini-3-pro-preview",haiku:"gemini-3-flash-preview"}},{id:"gemini-3-flash-preview",name:"Gemini 3 Flash",description:"Fast Gemini model via Antigravity",extendedContext:!0,presetMapping:{default:"gemini-3-flash-preview",opus:"gemini-3-pro-preview",sonnet:"gemini-3-pro-preview",haiku:"gemini-3-flash-preview"}}]},gemini:{provider:"gemini",displayName:"Gemini",defaultModel:"gemini-2.5-pro",models:[{id:"gemini-3-pro-preview",name:"Gemini 3 Pro",tier:"paid",description:"Latest model, requires paid Google account",extendedContext:!0,presetMapping:{default:"gemini-3-pro-preview",opus:"gemini-3-pro-preview",sonnet:"gemini-3-pro-preview",haiku:"gemini-3-flash-preview"}},{id:"gemini-3-flash-preview",name:"Gemini 3 Flash",tier:"paid",description:"Fast Gemini 3 model, requires paid Google account",extendedContext:!0,presetMapping:{default:"gemini-3-flash-preview",opus:"gemini-3-pro-preview",sonnet:"gemini-3-pro-preview",haiku:"gemini-3-flash-preview"}},{id:"gemini-2.5-pro",name:"Gemini 2.5 Pro",description:"Stable, works with free Google account",extendedContext:!0,presetMapping:{default:"gemini-2.5-pro",opus:"gemini-2.5-pro",sonnet:"gemini-2.5-pro",haiku:"gemini-2.5-flash"}}]},codex:{provider:"codex",displayName:"Codex",defaultModel:"gpt-5.3-codex",models:[{id:"gpt-5.3-codex",name:"GPT-5.3 Codex",description:"Supports up to xhigh effort",presetMapping:{default:"gpt-5.3-codex",opus:"gpt-5.3-codex",sonnet:"gpt-5.3-codex",haiku:"gpt-5-mini"}},{id:"gpt-5.2-codex",name:"GPT-5.2 Codex",description:"Previous stable Codex model",presetMapping:{default:"gpt-5.2-codex",opus:"gpt-5.2-codex",sonnet:"gpt-5.2-codex",haiku:"gpt-5-mini"}},{id:"gpt-5-mini",name:"GPT-5 Mini",description:"Fast, capped at high effort (no xhigh)",presetMapping:{default:"gpt-5-mini",opus:"gpt-5.3-codex",sonnet:"gpt-5-mini",haiku:"gpt-5-mini"}},{id:"gpt-5.1-codex-max",name:"Codex Max (5.1)",description:"Legacy most capable Codex model",presetMapping:{default:"gpt-5.1-codex-max",opus:"gpt-5.1-codex-max",sonnet:"gpt-5.1-codex-max",haiku:"gpt-5.1-codex-mini"}},{id:"gpt-5.2",name:"GPT 5.2",description:"Latest GPT model",presetMapping:{default:"gpt-5.2",opus:"gpt-5.2",sonnet:"gpt-5.2",haiku:"gpt-5.2"}},{id:"gpt-5.1-codex-mini",name:"Codex Mini",description:"Fast and efficient Codex model"}]},qwen:{provider:"qwen",displayName:"Qwen",defaultModel:"qwen3-coder-plus",models:[{id:"qwen3-coder-plus",name:"Qwen3 Coder Plus",description:"Code-focused model (1M context)",presetMapping:{default:"qwen3-coder-plus",opus:"qwen3-max",sonnet:"qwen3-coder-plus",haiku:"qwen3-coder-flash"}},{id:"qwen3-max",name:"Qwen3 Max",description:"Flagship model (256K context)",presetMapping:{default:"qwen3-max",opus:"qwen3-max",sonnet:"qwen3-coder-plus",haiku:"qwen3-coder-flash"}},{id:"qwen3-max-preview",name:"Qwen3 Max Preview",description:"Preview with thinking support (256K)",presetMapping:{default:"qwen3-max-preview",opus:"qwen3-max-preview",sonnet:"qwen3-max",haiku:"qwen3-coder-flash"}},{id:"qwen3-235b",name:"Qwen3 235B",description:"Large 235B A22B model",presetMapping:{default:"qwen3-235b",opus:"qwen3-max",sonnet:"qwen3-235b",haiku:"qwen3-coder-flash"}},{id:"qwen3-vl-plus",name:"Qwen3 VL Plus",description:"Vision-language multimodal"},{id:"qwen3-coder-flash",name:"Qwen3 Coder Flash",description:"Fast code generation"},{id:"qwen3-32b",name:"Qwen3 32B",description:"Qwen3 32B model"}]},iflow:{provider:"iflow",displayName:"iFlow",defaultModel:"qwen3-coder-plus",models:[{id:"qwen3-coder-plus",name:"Qwen3 Coder Plus",description:"Recommended default for iFlow accounts",presetMapping:{default:"qwen3-coder-plus",opus:"qwen3-coder-plus",sonnet:"qwen3-coder-plus",haiku:"qwen3-coder-plus"}},{id:"qwen3-max",name:"Qwen3 Max",description:"Flagship Qwen model via iFlow"},{id:"kimi-k2.5",name:"Kimi K2.5",description:"Latest Kimi model via iFlow"},{id:"kimi-k2",name:"Kimi K2",description:"Kimi general model"},{id:"deepseek-v3.2-chat",name:"DeepSeek V3.2 Chat",description:"Stable DeepSeek chat model"},{id:"deepseek-r1",name:"DeepSeek R1",description:"Reasoning-focused DeepSeek model"},{id:"glm-4.7",name:"GLM 4.7",description:"Zhipu GLM 4.7 via iFlow"},{id:"minimax-m2.5",name:"MiniMax M2.5",description:"MiniMax M2.5 via iFlow"},{id:"qwen3-vl-plus",name:"Qwen3 VL Plus",description:"Vision-language model"}]},kimi:{provider:"kimi",displayName:"Kimi (Moonshot)",defaultModel:"kimi-k2.5",models:[{id:"kimi-k2.5",name:"Kimi K2.5",description:"Latest multimodal model (262K context)",presetMapping:{default:"kimi-k2.5",opus:"kimi-k2.5",sonnet:"kimi-k2-thinking",haiku:"kimi-k2"}},{id:"kimi-k2-thinking",name:"Kimi K2 Thinking",description:"Extended reasoning model",presetMapping:{default:"kimi-k2-thinking",opus:"kimi-k2.5",sonnet:"kimi-k2-thinking",haiku:"kimi-k2"}},{id:"kimi-k2",name:"Kimi K2",description:"Flagship coding model"}]},kiro:{provider:"kiro",displayName:"Kiro (AWS)",defaultModel:"kiro-claude-sonnet-4-5",models:[{id:"kiro-claude-opus-4-5",name:"Kiro Claude Opus 4.5",description:"Claude Opus 4.5 via Kiro (2.2x credit)",presetMapping:{default:"kiro-claude-opus-4-5",opus:"kiro-claude-opus-4-5",sonnet:"kiro-claude-sonnet-4-5",haiku:"kiro-claude-haiku-4-5"}},{id:"kiro-claude-sonnet-4-5",name:"Kiro Claude Sonnet 4.5",description:"Claude Sonnet 4.5 via Kiro (1.3x credit)",presetMapping:{default:"kiro-claude-sonnet-4-5",opus:"kiro-claude-opus-4-5",sonnet:"kiro-claude-sonnet-4-5",haiku:"kiro-claude-haiku-4-5"}},{id:"kiro-claude-sonnet-4",name:"Kiro Claude Sonnet 4",description:"Claude Sonnet 4 via Kiro (1.3x credit)",presetMapping:{default:"kiro-claude-sonnet-4",opus:"kiro-claude-opus-4-5",sonnet:"kiro-claude-sonnet-4",haiku:"kiro-claude-haiku-4-5"}},{id:"kiro-claude-haiku-4-5",name:"Kiro Claude Haiku 4.5",description:"Claude Haiku 4.5 via Kiro (0.4x credit)"}]},ghcp:{provider:"ghcp",displayName:"GitHub Copilot (OAuth)",defaultModel:"claude-sonnet-4.5",models:[{id:"claude-opus-4.5",name:"Claude Opus 4.5",description:"Anthropic Claude Opus 4.5 via GitHub Copilot",presetMapping:{default:"claude-opus-4.5",opus:"claude-opus-4.5",sonnet:"claude-sonnet-4.5",haiku:"claude-haiku-4.5"}},{id:"claude-sonnet-4.5",name:"Claude Sonnet 4.5",description:"Anthropic Claude Sonnet 4.5 via GitHub Copilot",presetMapping:{default:"claude-sonnet-4.5",opus:"claude-opus-4.5",sonnet:"claude-sonnet-4.5",haiku:"claude-haiku-4.5"}},{id:"claude-sonnet-4",name:"Claude Sonnet 4",description:"Anthropic Claude Sonnet 4 via GitHub Copilot"},{id:"claude-haiku-4.5",name:"Claude Haiku 4.5",description:"Anthropic Claude Haiku 4.5 via GitHub Copilot"},{id:"gpt-5.2",name:"GPT-5.2",description:"OpenAI GPT-5.2 via GitHub Copilot",presetMapping:{default:"gpt-5.2",opus:"gpt-5.2",sonnet:"gpt-5.1",haiku:"gpt-5-mini"}},{id:"gpt-5.1",name:"GPT-5.1",description:"OpenAI GPT-5.1 via GitHub Copilot"},{id:"gpt-5",name:"GPT-5",description:"OpenAI GPT-5 via GitHub Copilot"},{id:"gpt-5-mini",name:"GPT-5 Mini",description:"OpenAI GPT-5 Mini via GitHub Copilot"},{id:"gemini-3-pro",name:"Gemini 3 Pro",description:"Google Gemini 3 Pro via GitHub Copilot"}]},claude:{provider:"claude",displayName:"Claude (Anthropic)",defaultModel:"claude-sonnet-4-5-20250929",models:[{id:"claude-opus-4-6",name:"Claude Opus 4.6",description:"Latest flagship model",extendedContext:!0,presetMapping:{default:"claude-opus-4-6",opus:"claude-opus-4-6",sonnet:"claude-sonnet-4-5-20250929",haiku:"claude-haiku-4-5-20251001"}},{id:"claude-opus-4-5-20251101",name:"Claude Opus 4.5",description:"Most capable Claude model",extendedContext:!0,presetMapping:{default:"claude-opus-4-5-20251101",opus:"claude-opus-4-5-20251101",sonnet:"claude-sonnet-4-5-20250929",haiku:"claude-haiku-4-5-20251001"}},{id:"claude-sonnet-4-5-20250929",name:"Claude Sonnet 4.5",description:"Balanced performance and speed",extendedContext:!0,presetMapping:{default:"claude-sonnet-4-5-20250929",opus:"claude-opus-4-5-20251101",sonnet:"claude-sonnet-4-5-20250929",haiku:"claude-haiku-4-5-20251001"}},{id:"claude-sonnet-4-20250514",name:"Claude Sonnet 4",description:"Previous generation Sonnet",extendedContext:!0,presetMapping:{default:"claude-sonnet-4-20250514",opus:"claude-opus-4-5-20251101",sonnet:"claude-sonnet-4-20250514",haiku:"claude-haiku-4-5-20251001"}},{id:"claude-haiku-4-5-20251001",name:"Claude Haiku 4.5",description:"Fast and efficient"}]}},Te="ccs-internal-managed";async function ea(){try{const s=await fetch("/api/settings/auth/tokens/raw");return s.ok?(await s.json())?.apiKey?.value??Te:Te}catch{return Te}}async function Fe(s,a){const t=fe[s];if(!t)return{success:!1};const i=t.models[0],n=i?.presetMapping||{default:t.defaultModel,opus:t.defaultModel,sonnet:t.defaultModel,haiku:t.defaultModel},l=await ea(),o={env:{ANTHROPIC_BASE_URL:`http://127.0.0.1:${Le}/api/provider/${s}`,ANTHROPIC_AUTH_TOKEN:l,ANTHROPIC_MODEL:n.default,ANTHROPIC_DEFAULT_OPUS_MODEL:n.opus,ANTHROPIC_DEFAULT_SONNET_MODEL:n.sonnet,ANTHROPIC_DEFAULT_HAIKU_MODEL:n.haiku}};try{return{success:(await fetch(`/api/settings/${s}`,{method:"PUT",headers:{"Content-Type":"application/json"},body:JSON.stringify({settings:o})})).ok,presetName:i?.name||t.defaultModel}}catch{return{success:!1}}}function sa({currentProgress:s,allSteps:a}){return e.jsx("div",{className:"flex justify-center gap-1 pt-2",children:a.map((t,i)=>e.jsx("div",{className:`w-2 h-2 rounded-full transition-colors ${s>=i?"bg-primary":"bg-muted"}`},t))})}function ta({providers:s,onSelect:a}){return e.jsx("div",{className:"grid gap-2",children:s.map(t=>e.jsxs("button",{onClick:()=>a(t.id),className:"flex items-center justify-between p-3 border rounded-lg hover:bg-muted/50 transition-colors text-left",children:[e.jsxs("div",{children:[e.jsx("div",{className:"font-medium",children:t.name}),e.jsx("div",{className:"text-xs text-muted-foreground",children:t.description})]}),e.jsx(Ds,{className:"w-4 h-4 text-muted-foreground"})]},t.id))})}function aa({selectedProvider:s,providers:a,authCommand:t,isRefreshing:i,isPending:n,onBack:l,onStartAuth:x,onRefresh:o}){const[h,f]=d.useState(!1),v=async u=>{await navigator.clipboard.writeText(u),f(!0),setTimeout(()=>f(!1),2e3)};return e.jsxs("div",{className:"space-y-4",children:[e.jsxs("div",{className:"text-center space-y-3",children:[e.jsxs("p",{className:"text-sm text-muted-foreground",children:["Authenticate with ",a.find(u=>u.id===s)?.name," to add an account"]}),e.jsx(O,{onClick:x,disabled:n,className:"w-full gap-2",size:"lg",children:n?e.jsxs(e.Fragment,{children:[e.jsx(J,{className:"w-4 h-4 animate-spin"}),"Authenticating..."]}):e.jsxs(e.Fragment,{children:[e.jsx(xe,{className:"w-4 h-4"}),"Authenticate in Browser"]})}),n&&e.jsx("p",{className:"text-xs text-muted-foreground",children:"Complete the OAuth flow in your browser..."})]}),e.jsxs("div",{className:"relative",children:[e.jsx("div",{className:"absolute inset-0 flex items-center",children:e.jsx("span",{className:"w-full border-t"})}),e.jsx("div",{className:"relative flex justify-center text-xs uppercase",children:e.jsx("span",{className:"bg-background px-2 text-muted-foreground",children:"Or use terminal"})})]}),e.jsx(ys,{children:e.jsxs(bs,{className:"p-4 space-y-3",children:[e.jsxs("div",{className:"flex items-center gap-2 text-sm text-muted-foreground",children:[e.jsx(Ft,{className:"w-4 h-4"}),"Run this command in your terminal:"]}),e.jsxs("div",{className:"flex items-center gap-2",children:[e.jsx("code",{className:"flex-1 px-3 py-2 bg-muted rounded-md font-mono text-sm",children:t}),e.jsx(O,{variant:"outline",size:"icon",onClick:()=>v(t),children:h?e.jsx(te,{className:"w-4 h-4 text-green-500"}):e.jsx(Ts,{className:"w-4 h-4"})})]})]})}),e.jsxs("div",{className:"flex items-center justify-between",children:[e.jsxs(O,{variant:"ghost",onClick:l,disabled:n,children:[e.jsx(Je,{className:"w-4 h-4 mr-2"}),"Back"]}),e.jsxs(O,{variant:"outline",onClick:o,disabled:i||n,children:[e.jsx(We,{className:`w-4 h-4 mr-2 ${i?"animate-spin":""}`}),i?"Checking...":"Refresh Status"]})]})]})}function na({accounts:s,privacyMode:a,onSelect:t,onAddNew:i,onBack:n}){return e.jsxs("div",{className:"space-y-4",children:[e.jsxs("div",{className:"text-xs font-medium text-muted-foreground uppercase tracking-wide",children:["Select an account (",s.length,")"]}),e.jsx("div",{className:"grid gap-2 max-h-[320px] overflow-y-auto pr-1",children:s.map(l=>e.jsxs("button",{type:"button",onClick:()=>t(l),className:"flex items-center justify-between p-3 border rounded-lg hover:bg-muted/50 transition-colors text-left",children:[e.jsxs("div",{className:"flex items-center gap-3",children:[e.jsx("div",{className:"w-8 h-8 rounded-full bg-muted flex items-center justify-center",children:e.jsx(pe,{className:"w-4 h-4 text-muted-foreground"})}),e.jsxs("div",{children:[e.jsx("div",{className:B("font-medium",a&&Ce),children:l.email||l.id}),l.isDefault&&e.jsx("div",{className:"text-xs text-muted-foreground",children:"Default account"})]})]}),e.jsx(Ds,{className:"w-4 h-4 text-muted-foreground"})]},l.id))}),e.jsxs("div",{className:"relative",children:[e.jsx("div",{className:"absolute inset-0 flex items-center",children:e.jsx("span",{className:"w-full border-t"})}),e.jsx("div",{className:"relative flex justify-center text-xs uppercase",children:e.jsx("span",{className:"bg-background px-2 text-muted-foreground",children:"Or"})})]}),e.jsxs("button",{type:"button",className:"w-full flex items-center gap-3 p-3 border-2 border-dashed border-primary/50 rounded-lg hover:border-primary hover:bg-primary/5 transition-colors text-left",onClick:i,children:[e.jsx("div",{className:"w-8 h-8 rounded-full bg-primary/10 flex items-center justify-center shrink-0",children:e.jsx(xe,{className:"w-4 h-4 text-primary"})}),e.jsxs("div",{children:[e.jsx("div",{className:"font-medium text-primary",children:"Add new account"}),e.jsx("div",{className:"text-xs text-muted-foreground",children:"Authenticate with a different account"})]})]}),e.jsx("div",{className:"flex items-center justify-between pt-2",children:e.jsxs(O,{variant:"ghost",onClick:n,children:[e.jsx(Je,{className:"w-4 h-4 mr-2"}),"Back"]})})]})}const gs="__custom__";function ia({selectedProvider:s,selectedAccount:a,variantName:t,modelName:i,isPending:n,privacyMode:l,onVariantNameChange:x,onModelChange:o,onBack:h,onSkip:f,onCreate:v}){const{t:u}=Z(),r=fe[s]?.models||[],y=i&&!r.some(m=>m.id===i),[j,p]=d.useState(y),D=m=>{m===gs?(p(!0),o("")):(p(!1),o(m))};return e.jsxs("div",{className:"space-y-4",children:[a&&e.jsxs("div",{className:"flex items-center gap-2 p-2 bg-muted/50 rounded-md text-sm",children:[e.jsx(pe,{className:"w-4 h-4"}),e.jsxs("span",{children:[u("setupVariant.using")," ",e.jsx("span",{className:B(l&&Ce),children:a.email||a.id})]})]}),e.jsxs("div",{className:"space-y-2",children:[e.jsx(W,{htmlFor:"variant-name",children:u("setupVariant.variantNameRequired")}),e.jsx(oe,{id:"variant-name",value:t,onChange:m=>x(m.target.value),placeholder:u("setupVariant.variantNamePlaceholder")}),e.jsxs("div",{className:"text-xs text-muted-foreground",children:[u("setupVariant.invokeHintPrefix")," ccs ",t||"<name>",' "prompt"']})]}),e.jsxs("div",{className:"space-y-2",children:[e.jsx(W,{children:u("setupVariant.model")}),j?e.jsxs("div",{className:"space-y-2",children:[e.jsx(oe,{value:i,onChange:m=>o(m.target.value),placeholder:u("setupVariant.modelPlaceholder")}),e.jsx("button",{type:"button",className:"text-xs text-primary hover:underline",onClick:()=>p(!1),children:u("setupVariant.choosePresetInstead")})]}):e.jsxs(qe,{value:r.some(m=>m.id===i)?i:"",onValueChange:D,children:[e.jsx(Ke,{children:e.jsx(He,{placeholder:u("setupVariant.selectModel")})}),e.jsxs(Ve,{children:[r.map(m=>e.jsx(ge,{value:m.id,children:e.jsxs("div",{className:"flex items-center gap-2",children:[e.jsx("span",{children:m.name}),m.description&&e.jsxs("span",{className:"text-xs text-muted-foreground",children:["- ",m.description]})]})},m.id)),e.jsx(ge,{value:gs,children:e.jsx("span",{className:"text-primary",children:u("setupVariant.customModelName")})})]})]}),e.jsx("div",{className:"text-xs text-muted-foreground",children:j?u("setupVariant.enterAnyModel"):u("setupVariant.defaultModel",{model:fe[s]?.defaultModel||u("setupVariant.providerDefault")})})]}),e.jsxs("div",{className:"flex items-center justify-between pt-2",children:[e.jsxs(O,{variant:"ghost",onClick:h,children:[e.jsx(Je,{className:"w-4 h-4 mr-2"}),u("setupVariant.back")]}),e.jsxs("div",{className:"flex items-center gap-2",children:[e.jsx(O,{variant:"ghost",onClick:f,children:u("setupVariant.skip")}),e.jsx(O,{onClick:v,disabled:!t||n,children:u(n?"setupVariant.creating":"setupVariant.createVariant")})]})]}),e.jsx("p",{className:"text-xs text-center text-muted-foreground",children:u("setupVariant.skipHint")})]})}function ra({variantName:s,onClose:a}){return e.jsxs("div",{className:"space-y-4 text-center",children:[e.jsx("div",{className:"flex justify-center",children:e.jsx("div",{className:"w-16 h-16 bg-green-100 dark:bg-green-900/30 rounded-full flex items-center justify-center",children:e.jsx(te,{className:"w-8 h-8 text-green-600 dark:text-green-400"})})}),e.jsxs("div",{children:[e.jsx("div",{className:"font-semibold text-lg",children:"Variant Created!"}),e.jsx("div",{className:"text-sm text-muted-foreground",children:"Your custom variant is ready to use"})]}),e.jsx(ys,{children:e.jsxs(bs,{className:"p-4 space-y-2",children:[e.jsx("div",{className:"text-sm text-muted-foreground",children:"Usage:"}),e.jsxs("code",{className:"block px-3 py-2 bg-muted rounded-md font-mono text-sm",children:["ccs ",s,' "your prompt here"']})]})}),e.jsx(O,{onClick:a,className:"w-full",children:"Done"})]})}function oa({open:s,onClose:a}){const[t,i]=d.useState("provider"),[n,l]=d.useState(""),[x,o]=d.useState(null),[h,f]=d.useState(""),[v,u]=d.useState(""),[r,y]=d.useState(!1),[j,p]=d.useState(!1),{data:D,refetch:m}=ks(),R=Qs(),E=zs(),b=Js(),{privacyMode:L}=Cs(),A=D?.authStatus.find(P=>P.provider===n),g=d.useMemo(()=>A?.accounts||[],[A?.accounts]);d.useEffect(()=>{if(!s){const P=setTimeout(()=>{i("provider"),l(""),o(null),f(""),u(""),p(!1)},0);return()=>clearTimeout(P)}},[s]),d.useEffect(()=>{if(t==="auth"&&g.length>0&&!j){const P=setTimeout(()=>{i("account")},0);return()=>clearTimeout(P)}},[t,g,j]);const I=async()=>{y(!0),await m(),y(!1)},N=()=>{const P=(A?.accounts?.length||0)===0;E.mutate({provider:n},{onSuccess:async _=>{if(P){const F=await Fe(n);F.success&&F.presetName?K.success(`Applied "${F.presetName}" preset`):F.success||K.warning(Ss.t("commonToast.accountAddedPresetFailed"))}_.account&&(o(_.account),i("variant")),m()}})},k=P=>{l(P),(D?.authStatus.find(H=>H.provider===P)?.accounts||[]).length===0?i("auth"):i("account")},w=P=>{o(P),i("variant")},M=async()=>{if(!(!h||!n))try{await R.mutateAsync({name:h,provider:n,model:v||void 0,account:x?.id}),i("success")}catch(P){console.error("Failed to create variant:",P)}},C=`ccs ${n} --auth --add`,q=Ys(t),G=P=>{if(!P&&(E.isPending&&n&&b.mutate(n),t==="success"||t==="provider")){a();return}};return e.jsx(Be,{open:s,onOpenChange:G,children:e.jsxs(Ge,{className:"sm:max-w-lg",onPointerDownOutside:P=>{t!=="success"&&t!=="provider"&&P.preventDefault()},onEscapeKeyDown:P=>{(E.isPending||R.isPending)&&P.preventDefault()},children:[e.jsxs($e,{children:[e.jsxs(Qe,{className:"flex items-center gap-2",children:[e.jsx(je,{className:"w-5 h-5 text-primary"}),"Quick Setup Wizard"]}),e.jsxs(As,{children:[t==="provider"&&"Select a provider to get started",t==="auth"&&"Authenticate with your provider",t==="account"&&"Select which account to use",t==="variant"&&"Create your custom variant",t==="success"&&"Setup complete!"]})]}),e.jsxs("div",{className:"space-y-4 py-4",children:[t==="provider"&&e.jsx(ta,{providers:rs,onSelect:k}),t==="auth"&&e.jsx(aa,{selectedProvider:n,providers:rs,authCommand:C,isRefreshing:r,isPending:E.isPending,onBack:()=>i("provider"),onStartAuth:N,onRefresh:I}),t==="account"&&e.jsx(na,{accounts:g,privacyMode:L,onSelect:w,onAddNew:()=>{p(!0),i("auth")},onBack:()=>i("provider")}),t==="variant"&&e.jsx(ia,{selectedProvider:n,selectedAccount:x,variantName:h,modelName:v,isPending:R.isPending,privacyMode:L,onVariantNameChange:f,onModelChange:u,onBack:()=>g.length>0?i("account"):i("provider"),onSkip:a,onCreate:M}),t==="success"&&e.jsx(ra,{variantName:h,onClose:a})]}),e.jsx(sa,{currentProgress:q,allSteps:Ws})]})})}const la=3e3,ca=300*1e3;async function Ee(s){const a=await s.text();if(!a)return{};try{return JSON.parse(a)}catch{const t=s.status>=400?`Request failed with status ${s.status}`:void 0;return t?{error:t}:{}}}const re={provider:null,isAuthenticating:!1,error:null,authUrl:null,oauthState:null,isSubmittingCallback:!1,isDeviceCodeFlow:!1};function da(){const[s,a]=d.useState(re),t=d.useRef(null),i=d.useRef(null),n=d.useRef(0),l=d.useRef(!1),x=Ue(),o=d.useCallback(()=>{i.current&&(clearInterval(i.current),i.current=null)},[]);d.useEffect(()=>()=>{t.current?.abort(),o(),l.current=!1},[o]);const h=d.useCallback(async(r,y)=>{if(Date.now()-n.current>ca){o(),a(j=>({...j,isAuthenticating:!1,error:"Authentication timed out. Please try again."}));return}try{const p=await(await fetch(`/api/cliproxy/auth/${r}/status?state=${encodeURIComponent(y)}`)).json();if(p.status==="ok")o(),x.invalidateQueries({queryKey:["cliproxy-auth"]}),x.invalidateQueries({queryKey:["account-quota"]}),K.success(`${r} authentication successful`),l.current=!1,a(re);else if(p.status==="auth_url"){const D=p.url||p.auth_url;D&&(a(m=>({...m,authUrl:D})),l.current||(l.current=!0,window.open(D,"_blank")))}else if(p.status==="device_code"){o();const D=p.user_code&&p.verification_url?`Open ${p.verification_url} and enter code: ${p.user_code}`:"Switch to Device Code method and try again.";K.error("Provider returned Device Code flow in callback mode"),a(m=>({...m,isAuthenticating:!1,error:D}))}else if(p.status==="error"){o();const D=p.error||"Authentication failed";K.error(D),a(m=>({...m,isAuthenticating:!1,error:D}))}}catch{}},[x,o]),f=d.useCallback(async(r,y)=>{if(!Oe(r)){a({...re,error:`Unknown provider: ${r}`});return}t.current?.abort(),o(),l.current=!1;const j=new AbortController;t.current=j;const D=(y?.flowType||(Ps(r)?"device_code":"authorization_code"))==="device_code",m=y?.startEndpoint||(D?"start":"start-url"),R={nickname:y?.nickname,kiroMethod:y?.kiroMethod,riskAcknowledgement:y?.riskAcknowledgement};a({provider:r,isAuthenticating:!0,error:null,authUrl:null,oauthState:null,isSubmittingCallback:!1,isDeviceCodeFlow:D});try{if(m==="start")fetch(`/api/cliproxy/auth/${r}/start`,{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify(R),signal:j.signal}).then(async E=>{const b=await Ee(E),L=b.success===!0;if(E.ok&&L)x.invalidateQueries({queryKey:["cliproxy-auth"]}),x.invalidateQueries({queryKey:["account-quota"]}),l.current=!1,a(re);else{const A=typeof b.error=="string"?b.error:"Authentication failed";K.error(A),a(g=>({...g,isAuthenticating:!1,error:A}))}}).catch(E=>{if(E instanceof Error&&E.name==="AbortError")return;const b=E instanceof Error?E.message:"Authentication failed";K.error(b),a(L=>({...L,isAuthenticating:!1,error:b}))});else{const E=await fetch(`/api/cliproxy/auth/${r}/start-url`,{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify(R),signal:j.signal}),b=await Ee(E),L=b.success===!0;if(!E.ok||!L){const I=typeof b.error=="string"?b.error:"Failed to start OAuth";throw new Error(I)}const A=typeof b.authUrl=="string"?b.authUrl:null,g=typeof b.state=="string"?b.state:null;a(I=>({...I,authUrl:A,oauthState:g})),A&&(l.current=!0,window.open(A,"_blank")),g&&(n.current=Date.now(),i.current=setInterval(()=>{h(r,g)},la))}}catch(E){if(E instanceof Error&&E.name==="AbortError"){l.current=!1,a(re);return}const b=E instanceof Error?E.message:"Authentication failed";K.error(b),a(L=>({...L,isAuthenticating:!1,error:b}))}},[h,o,x]),v=d.useCallback(()=>{const r=s.provider;t.current?.abort(),o(),l.current=!1,a(re),r&&ye.cliproxy.auth.cancel(r).catch(()=>{})},[s.provider,o]),u=d.useCallback(async r=>{if(s.provider){a(y=>({...y,isSubmittingCallback:!0,error:null}));try{const y=await fetch(`/api/cliproxy/auth/${s.provider}/submit-callback`,{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify({redirectUrl:r})}),j=await Ee(y),p=j.success===!0;if(y.ok&&p)o(),x.invalidateQueries({queryKey:["cliproxy-auth"]}),x.invalidateQueries({queryKey:["account-quota"]}),K.success(`${s.provider} authentication successful`),a(re);else{const D=typeof j.error=="string"?j.error:"Callback submission failed";throw new Error(D)}}catch(y){const j=y instanceof Error?y.message:"Failed to submit callback";K.error(j),a(p=>({...p,isSubmittingCallback:!1,error:j}))}}},[s.provider,x,o]);return d.useMemo(()=>({...s,startAuth:f,cancelAuth:v,submitCallback:u}),[s,f,v,u])}function qs({className:s,showAcknowledgement:a=!1,acknowledgementPhrase:t=be,acknowledgementText:i="",onAcknowledgementTextChange:n,disabled:l=!1,showProxySettingsLink:x=!1}){const{t:o}=Z(),h=o("accountSafetyWarning.title"),f=o("accountSafetyWarning.subtitle"),v=o("accountSafetyWarning.firstLine"),u=o("accountSafetyWarning.secondLine"),r="https://github.com/kaitranntt/ccs/issues/509",y=o("accountSafetyWarning.issueLabel"),j=o("accountSafetyWarning.proxySettingsLabel");return e.jsxs("section",{role:"alert",className:B("relative overflow-hidden rounded-xl border border-amber-500/30 bg-gradient-to-br from-amber-50 via-background to-rose-50/70 shadow-sm dark:from-amber-950/20 dark:to-rose-950/20",s),children:[e.jsx("div",{className:"absolute inset-x-0 top-0 h-0.5 bg-gradient-to-r from-amber-500 via-orange-500 to-rose-500"}),e.jsxs("div",{className:"space-y-3 p-4",children:[e.jsxs("div",{className:"flex items-start justify-between gap-3",children:[e.jsxs("div",{className:"flex items-start gap-2.5",children:[e.jsx("div",{className:"mt-0.5 inline-flex h-7 w-7 items-center justify-center rounded-md bg-amber-500/15 text-amber-700 dark:text-amber-400",children:e.jsx(Ye,{className:"h-4 w-4"})}),e.jsxs("div",{children:[e.jsx("p",{className:"text-sm font-semibold leading-5",children:h}),e.jsx("p",{className:"text-xs text-muted-foreground",children:f})]})]}),e.jsx(U,{variant:"outline",className:"border-amber-500/40 text-amber-700 dark:text-amber-300",children:"High Risk"})]}),e.jsxs("div",{className:"space-y-2 text-sm leading-relaxed",children:[e.jsx("p",{children:v}),e.jsx("p",{className:"font-medium text-amber-900 dark:text-amber-200",children:u}),e.jsx("p",{className:"text-xs text-muted-foreground",children:"CCS is provided as-is and does not take responsibility for suspension, bans, or access loss from upstream providers."})]}),e.jsxs("div",{className:"flex flex-wrap items-center gap-2",children:[e.jsxs("a",{href:r,target:"_blank",rel:"noreferrer",className:"inline-flex items-center gap-1.5 rounded-md border border-amber-500/30 bg-amber-500/10 px-2.5 py-1 text-xs font-medium text-amber-800 transition-colors hover:bg-amber-500/15 dark:text-amber-200",children:[y,e.jsx(xe,{className:"h-3.5 w-3.5"})]}),x&&e.jsxs("a",{href:"/settings?tab=proxy",className:"inline-flex items-center gap-1.5 rounded-md border border-amber-500/30 bg-amber-500/10 px-2.5 py-1 text-xs font-medium text-amber-800 transition-colors hover:bg-amber-500/15 dark:text-amber-200",children:[e.jsx(Ut,{className:"h-3.5 w-3.5"}),j]}),e.jsx("span",{className:"rounded-md border border-border/70 bg-muted/60 px-2.5 py-1 text-xs text-muted-foreground",children:"Applies to CLI and dashboard auth"})]}),a&&n&&e.jsxs("div",{className:"rounded-lg border border-amber-500/25 bg-amber-500/5 p-2.5",children:[e.jsxs(W,{htmlFor:"account-risk-ack-text",className:"text-xs leading-5",children:["Type exact phrase to continue:"," ",e.jsx("code",{className:"rounded bg-muted px-1 py-0.5 font-mono",children:t})]}),e.jsx(oe,{id:"account-risk-ack-text",value:i,onChange:p=>n(p.target.value),placeholder:t,disabled:l,className:"mt-2 font-mono text-xs"})]})]})]})}function ua({className:s,value:a,onChange:t,disabled:i=!1}){const{t:n}=Z(),l=[a.reviewedIssue509,a.understandsBanRisk,a.acceptsFullResponsibility,a.typedPhrase.trim().replace(/\s+/g," ").toUpperCase()===hs].filter(Boolean).length,x=l/4*100,o=h=>{t({...a,...h})};return e.jsxs("section",{role:"alert",className:B("relative overflow-hidden rounded-xl border border-rose-500/35 bg-gradient-to-br from-rose-50 via-background to-amber-50/70 p-4 shadow-sm dark:from-rose-950/20 dark:to-amber-950/20",s),children:[e.jsx("div",{className:"absolute inset-x-0 top-0 h-0.5 bg-gradient-to-r from-rose-500 via-orange-500 to-amber-500"}),e.jsxs("div",{className:"space-y-4",children:[e.jsxs("div",{className:"flex items-start justify-between gap-3",children:[e.jsxs("div",{className:"flex items-start gap-2.5",children:[e.jsx("div",{className:"mt-0.5 inline-flex h-7 w-7 items-center justify-center rounded-md bg-rose-500/15 text-rose-700 dark:text-rose-300",children:e.jsx(Ye,{className:"h-4 w-4"})}),e.jsxs("div",{className:"space-y-1",children:[e.jsx("p",{className:"text-sm font-semibold leading-5",children:n("antigravityChecklist.title")}),e.jsx("p",{className:"text-xs text-muted-foreground",children:n("antigravityChecklist.subtitle")})]})]}),e.jsx(U,{variant:"outline",className:"border-rose-500/40 text-rose-700 dark:text-rose-300",children:n("antigravityChecklist.mandatory")})]}),e.jsxs("div",{className:"space-y-1.5",children:[e.jsxs("div",{className:"flex items-center justify-between text-xs text-muted-foreground",children:[e.jsx("span",{children:n("antigravityChecklist.completion")}),e.jsx("span",{children:n("antigravityChecklist.stepsCount",{current:l})})]}),e.jsx(_e,{value:x,className:"h-2"})]}),e.jsxs("div",{className:"space-y-3 rounded-lg border border-rose-500/20 bg-rose-500/5 p-3",children:[e.jsxs("div",{className:"flex items-start gap-2",children:[e.jsx(ke,{id:"agy-step-reviewed-issue",checked:a.reviewedIssue509,onCheckedChange:h=>o({reviewedIssue509:!!h}),disabled:i}),e.jsx(W,{htmlFor:"agy-step-reviewed-issue",className:"text-xs leading-5",children:"Step 1: I reviewed issue #509 and understand AGY OAuth can trigger account bans/suspensions."})]}),e.jsxs("div",{className:"flex items-start gap-2",children:[e.jsx(ke,{id:"agy-step-understands-risk",checked:a.understandsBanRisk,onCheckedChange:h=>o({understandsBanRisk:!!h}),disabled:i}),e.jsx(W,{htmlFor:"agy-step-understands-risk",className:"text-xs leading-5",children:"Step 2: I understand this OAuth action is my own decision and I accept the upstream risk."})]}),e.jsxs("div",{className:"flex items-start gap-2",children:[e.jsx(ke,{id:"agy-step-accept-responsibility",checked:a.acceptsFullResponsibility,onCheckedChange:h=>o({acceptsFullResponsibility:!!h}),disabled:i}),e.jsx(W,{htmlFor:"agy-step-accept-responsibility",className:"text-xs leading-5",children:"Step 3: I accept full responsibility. CCS is not liable for suspension, bans, or access loss."})]})]}),e.jsxs("div",{className:"space-y-2 rounded-lg border border-amber-500/25 bg-amber-500/5 p-3",children:[e.jsxs("div",{className:"flex items-center gap-1.5 text-xs font-medium text-amber-800 dark:text-amber-200",children:[e.jsx(Es,{className:"h-3.5 w-3.5"}),"Step 4: Type exact phrase to continue"]}),e.jsx(oe,{value:a.typedPhrase,onChange:h=>o({typedPhrase:h.target.value}),placeholder:hs,disabled:i,className:"font-mono text-xs"})]}),e.jsx("div",{className:"flex flex-wrap items-center gap-2 text-xs",children:e.jsxs("a",{href:"https://github.com/kaitranntt/ccs/issues/509",target:"_blank",rel:"noreferrer",className:"inline-flex items-center gap-1.5 rounded-md border border-rose-500/30 bg-rose-500/10 px-2.5 py-1 font-medium text-rose-800 transition-colors hover:bg-rose-500/15 dark:text-rose-200",children:["Read issue #509",e.jsx(xe,{className:"h-3.5 w-3.5"})]})})]})]})}function ma(s){return s.trim().replace(/\s+/g," ").toUpperCase()}function xa({open:s,onClose:a,provider:t,displayName:i,isFirstAccount:n=!1}){const[l,x]=d.useState(""),[o,h]=d.useState(""),[f,v]=d.useState(!1),[u,r]=d.useState(null),[y,j]=d.useState(""),[p,D]=d.useState(De),[m,R]=d.useState(!1),[E,b]=d.useState(!1),[L,A]=d.useState(os),{t:g}=Z(),I=d.useRef(!1),N=da(),k=Xs(),w=t==="kiro",M=t==="gemini",C=t==="agy"&&!m,q=t==="agy"&&E,G=Wt(p),P=ma(y)===be,_=Ps(t),F=Zs(t),H=et(L),ee=w?H.flowType==="device_code":_,$=N.isAuthenticating||k.isPending,Y=l.trim(),X=u||N.error,c=d.useCallback(async()=>{const S=await fetch("/api/settings/auth/antigravity-risk");if(!S.ok)throw new Error("Failed to load Antigravity power user setting");return(await S.json()).antigravityAckBypass===!0},[]),T=()=>{x(""),h(""),v(!1),r(null),j(""),D(De),R(!1),b(!1),A(os),I.current=!1,a()};d.useEffect(()=>{s&&(j(""),D(De),r(null))},[t,s]),d.useEffect(()=>{let S=!1;if(!s||t!=="agy"){R(!1),b(!1);return}return(async()=>{try{b(!0);const ae=await c();S||R(ae)}catch{S||R(!1)}finally{S||b(!1)}})(),()=>{S=!0}},[c,s,t]),d.useEffect(()=>{if(!s||t!=="agy"||!N.error||!m)return;const S=N.error.toLowerCase();if(!(S.includes("agy_risk_ack_required")||S.includes("responsibility acknowledgement")||S.includes("responsibility checklist")))return;let ae=!1;return(async()=>{try{b(!0);const we=await c();if(ae)return;R(we),we||r("Power user mode is off. Complete the AGY checklist and retry.")}catch{if(ae)return;R(!1),r("Power user mode is off. Complete the AGY checklist and retry.")}finally{ae||b(!1)}})(),()=>{ae=!0}},[m,N.error,c,s,t]),d.useEffect(()=>{!N.isAuthenticating&&!N.error&&N.provider===null&&s&&I.current&&(I.current=!1,(async()=>{try{const se=await Fe(t);se.success&&se.presetName&&n&&K.success(`Applied "${se.presetName}" preset`)}catch{}T()})())},[N.isAuthenticating,N.error,N.provider]);const Q=()=>{N.cancelAuth(),T()},he=async()=>{N.authUrl&&(await navigator.clipboard.writeText(N.authUrl),v(!0),setTimeout(()=>v(!1),2e3))},Se=()=>{o.trim()&&N.submitCallback(o.trim())},Pe=()=>{if(q){r("Loading Antigravity safety settings. Please wait a moment and retry.");return}if(C&&!G){r("Complete all Antigravity responsibility steps before authenticating this provider.");return}if(M&&!P){r(`Type "${be}" to acknowledge the account safety warning before authenticating this provider.`);return}if(F&&!Y){r(`Nickname is required for ${i} accounts.`);return}r(null),I.current=!0,N.startAuth(t,{nickname:Y||void 0,kiroMethod:w?L:void 0,flowType:w?H.flowType:void 0,startEndpoint:w?H.startEndpoint:void 0,riskAcknowledgement:C?{version:Yt,reviewedIssue509:p.reviewedIssue509,understandsBanRisk:p.understandsBanRisk,acceptsFullResponsibility:p.acceptsFullResponsibility,typedPhrase:p.typedPhrase}:void 0})},Me=()=>{I.current=!0,k.mutate(void 0,{onSuccess:async()=>{const S=await Fe("kiro");S.success&&S.presetName&&n&&K.success(`Applied "${S.presetName}" preset`),T()}})},Ne=S=>{S||Q()},z=N.isAuthenticating;return e.jsx(Be,{open:s,onOpenChange:Ne,children:e.jsxs(Ge,{className:"sm:max-w-md",onInteractOutside:S=>{z&&S.preventDefault()},children:[e.jsxs($e,{children:[e.jsx(Qe,{children:g("addAccountDialog.title",{displayName:i})}),e.jsx(As,{children:g(w?"addAccountDialog.descKiro":ee?"addAccountDialog.descDeviceCode":"addAccountDialog.descOauth")})]}),e.jsxs("div",{className:"space-y-4 py-4",children:[C&&!z&&e.jsx(ua,{value:p,onChange:S=>{D(S),r(null)},disabled:$}),t==="agy"&&m&&!z&&e.jsxs("div",{className:"rounded-lg border border-amber-400/35 bg-amber-50/70 p-3 text-xs text-amber-900 dark:border-amber-800/60 dark:bg-amber-950/25 dark:text-amber-100",children:[e.jsxs("div",{className:"mb-1.5 flex items-center gap-1.5 font-semibold",children:[e.jsx(Es,{className:"h-3.5 w-3.5"}),g("addAccountDialog.powerUserEnabled")]}),g("addAccountDialog.powerUserSkipped")]}),M&&!z&&e.jsx(qs,{showAcknowledgement:!0,acknowledgementPhrase:be,acknowledgementText:y,onAcknowledgementTextChange:S=>{j(S),r(null)},disabled:$}),w&&!z&&e.jsxs("div",{className:"space-y-2",children:[e.jsx(W,{htmlFor:"kiro-auth-method",children:g("addAccountDialog.authMethod")}),e.jsxs(qe,{value:L,onValueChange:S=>{A(S),r(null)},children:[e.jsx(Ke,{id:"kiro-auth-method",children:e.jsx(He,{placeholder:g("addAccountDialog.selectKiroAuthMethod")})}),e.jsx(Ve,{children:st.map(S=>e.jsx(ge,{value:S.id,children:S.label},S.id))})]}),e.jsx("p",{className:"text-xs text-muted-foreground",children:H.description})]}),!z&&e.jsxs("div",{className:"space-y-2",children:[e.jsx(W,{htmlFor:"nickname",children:g(F?"addAccountDialog.nicknameRequired":"addAccountDialog.nicknameOptional")}),e.jsxs("div",{className:"flex items-center gap-2",children:[e.jsx(pe,{className:"w-4 h-4 text-muted-foreground"}),e.jsx(oe,{id:"nickname",value:l,onChange:S=>{x(S.target.value),r(null)},placeholder:g("addAccountDialog.nicknamePlaceholder"),disabled:$,className:"flex-1"})]}),e.jsx("p",{className:"text-xs text-muted-foreground",children:g(F?"addAccountDialog.nicknameRequiredHint":"addAccountDialog.nicknameOptionalHint")})]}),z&&e.jsxs("div",{className:"space-y-4",children:[e.jsxs("div",{className:"text-center",children:[e.jsxs("p",{className:"text-sm text-muted-foreground",children:[e.jsx(J,{className:"w-4 h-4 inline mr-2 animate-spin"}),g("addAccountDialog.waitingForAuth")]}),e.jsx("p",{className:"text-xs text-muted-foreground mt-1",children:N.isDeviceCodeFlow?g("addAccountDialog.deviceCodeHint"):g("addAccountDialog.browserHint")})]}),N.authUrl&&!N.isDeviceCodeFlow&&e.jsxs("div",{className:"space-y-3",children:[e.jsxs("div",{className:"space-y-2",children:[e.jsx(W,{className:"text-xs",children:g("addAccountDialog.openUrlLabel")}),e.jsxs("div",{className:"p-3 bg-muted rounded-md",children:[e.jsx("p",{className:"text-xs text-muted-foreground break-all font-mono line-clamp-3",children:N.authUrl}),e.jsxs("div",{className:"flex gap-2 mt-2",children:[e.jsx(O,{variant:"outline",size:"sm",onClick:he,children:f?e.jsxs(e.Fragment,{children:[e.jsx(te,{className:"w-3 h-3 mr-1"}),g("addAccountDialog.copied")]}):e.jsxs(e.Fragment,{children:[e.jsx(Ts,{className:"w-3 h-3 mr-1"}),g("addAccountDialog.copy")]})}),e.jsxs(O,{variant:"outline",size:"sm",onClick:()=>{if(!N.authUrl)return;const S=window.open(N.authUrl,"_blank");(!S||S.closed||typeof S.closed>"u")&&K.warning(g("addAccountDialog.popupBlocked"),{duration:5e3})},children:[e.jsx(xe,{className:"w-3 h-3 mr-1"}),g("addAccountDialog.open")]})]})]})]}),e.jsxs("div",{className:"space-y-2",children:[e.jsx(W,{htmlFor:"callback-url",className:"text-xs",children:g("addAccountDialog.redirectPasteLabel")}),e.jsx(oe,{id:"callback-url",value:o,onChange:S=>h(S.target.value),placeholder:g("addAccountDialog.callbackPlaceholder"),className:"font-mono text-xs"}),e.jsx(O,{variant:"secondary",size:"sm",onClick:Se,disabled:!o.trim()||N.isSubmittingCallback,children:N.isSubmittingCallback?e.jsxs(e.Fragment,{children:[e.jsx(J,{className:"w-3 h-3 mr-1 animate-spin"}),g("addAccountDialog.submitting")]}):g("addAccountDialog.submitCallback")})]})]}),!N.authUrl&&!N.isDeviceCodeFlow&&e.jsx("p",{className:"text-xs text-center text-muted-foreground",children:g("addAccountDialog.preparingUrl")})]}),X&&e.jsx("p",{className:"text-xs text-center text-destructive",children:X}),k.isPending&&e.jsxs("p",{className:"text-sm text-center text-muted-foreground",children:[e.jsx(J,{className:"w-4 h-4 inline mr-2 animate-spin"}),g("addAccountDialog.importingToken")]}),e.jsxs("div",{className:"flex items-center justify-end gap-2 pt-2",children:[e.jsx(O,{variant:"ghost",onClick:Q,children:g("addAccountDialog.cancel")}),w&&!z&&e.jsx(O,{variant:"outline",onClick:Me,disabled:$,children:k.isPending?e.jsxs(e.Fragment,{children:[e.jsx(J,{className:"w-4 h-4 mr-2 animate-spin"}),g("addAccountDialog.importing")]}):e.jsxs(e.Fragment,{children:[e.jsx(qt,{className:"w-4 h-4 mr-2"}),g("addAccountDialog.importFromIde")]})}),!z&&e.jsxs(O,{onClick:Pe,disabled:$||q||F&&!Y||C&&!G||M&&!P,children:[e.jsx(xe,{className:"w-4 h-4 mr-2"}),g("addAccountDialog.authenticate")]})]})]})]})})}const es="[1m]";function pa(s){return s.toLowerCase().startsWith("gemini-")}function ss(s){return s.toLowerCase().endsWith(es.toLowerCase())}function ha(s){return!s||ss(s)?s:`${s}${es}`}function Ks(s){return s&&(ss(s)?s.slice(0,-es.length):s)}const fs=["ANTHROPIC_MODEL"],ga=["ANTHROPIC_BASE_URL","ANTHROPIC_AUTH_TOKEN"];function fa(s){const a=s?.env||{};return ga.filter(t=>!a[t]?.trim())}function ja(s){const[a,t]=d.useState(null),[i,n]=d.useState(!1),l=Ue(),{data:x,isLoading:o,refetch:h}=ws({queryKey:["settings",s],queryFn:async()=>{const k=await fetch(`/api/settings/${s}/raw`);return k.ok?k.json():{profile:s,settings:{env:{}},mtime:Date.now(),path:`~/.ccs/profiles/${s}/settings.json`}}}),f=x?.settings,v=d.useMemo(()=>a!==null?a:f?JSON.stringify(f,null,2):`{
2
2
  "env": {}
3
3
  }`,[a,f]),u=d.useCallback(k=>{t(k)},[]),r=d.useMemo(()=>{try{return JSON.parse(v)}catch{return f||{env:{}}}},[v,f]),y=r?.env?.ANTHROPIC_MODEL,j=r?.env?.ANTHROPIC_DEFAULT_OPUS_MODEL,p=r?.env?.ANTHROPIC_DEFAULT_SONNET_MODEL,D=r?.env?.ANTHROPIC_DEFAULT_HAIKU_MODEL,m=d.useMemo(()=>{const k=r?.env||{};return fs.some(w=>{const M=k[w];return M&&ss(M)})},[r]),R=d.useCallback((k,w)=>{const M={...r?.env||{},[k]:w},C={...r,env:M};t(JSON.stringify(C,null,2))},[r]),E=d.useCallback(k=>{const w=r?.env||{},M={};for(const G of fs){const P=w[G];P&&(M[G]=k?ha(P):Ks(P))}const C={...w,...M};delete C.CCS_EXTENDED_CONTEXT;const q={...r,env:C};t(JSON.stringify(q,null,2))},[r]),b=d.useCallback(k=>{const w={...r?.env||{},...k},M={...r,env:w};t(JSON.stringify(M,null,2))},[r]),L=d.useMemo(()=>{try{return JSON.parse(v),!0}catch{return!1}},[v]),A=d.useMemo(()=>a===null?!1:a!==JSON.stringify(f,null,2),[a,f]),g=d.useMemo(()=>fa(r),[r]),I=$s({mutationFn:async()=>{const k=JSON.parse(v),w=await fetch(`/api/settings/${s}`,{method:"PUT",headers:{"Content-Type":"application/json"},body:JSON.stringify({settings:k,expectedMtime:x?.mtime})});if(w.status===409)throw new Error("CONFLICT");if(!w.ok)throw new Error("Failed to save");return w.json()},onSuccess:k=>{l.invalidateQueries({queryKey:["settings",s]}),t(null),k?.warning?K.success("Settings saved",{description:k.warning}):K.success("Settings saved")},onError:k=>{k.message==="CONFLICT"?n(!0):K.error(k.message)}}),N=async k=>{n(!1),k?(await h(),I.mutate()):t(null)};return{data:x,isLoading:o,refetch:h,rawJsonContent:v,rawJsonEdits:a,isRawJsonValid:L,hasChanges:A,currentSettings:r,currentModel:y,opusModel:j,sonnetModel:p,haikuModel:D,extendedContextEnabled:m,toggleExtendedContext:E,handleRawJsonChange:u,updateEnvValue:R,updateEnvValues:b,saveMutation:{mutate:()=>I.mutate(),isPending:I.isPending},conflictDialog:i,setConflictDialog:n,handleConflictResolve:N,missingRequiredFields:g}}const va=/-(medium|high|xhigh)$/i;function Na(s){if(!s)return;const a=s.trim().match(va);if(a?.[1])return a[1].toLowerCase()}function Re(s){if(!s)return null;const a=Na(s);return a?{label:`Pinned ${a}`,explicit:!0}:{label:"Auto effort",explicit:!1}}function ie({label:s,description:a,value:t,onChange:i,catalog:n,allModels:l,disabled:x}){const{t:o}=Z(),h=new Set(n?.models.map(u=>u.id)||[]),f=n?.provider==="codex",v=f?Re(t):null;return e.jsxs("div",{className:"space-y-1.5",children:[e.jsxs("div",{children:[e.jsx("label",{className:"text-xs font-medium",children:s}),a&&e.jsx("p",{className:"text-[10px] text-muted-foreground",children:a})]}),e.jsxs(qe,{value:t||"",onValueChange:i,disabled:x,children:[e.jsx(Ke,{className:"h-9",children:e.jsx(He,{placeholder:o("providerModelSelector.selectModel"),children:t&&e.jsxs("div",{className:"flex items-center gap-2",children:[e.jsx("span",{className:"truncate font-mono text-xs",children:t}),v&&e.jsx(U,{variant:v.explicit?"secondary":"outline",className:"text-[9px] h-4 px-1 uppercase",children:v.label})]})})}),e.jsxs(Ve,{className:"max-h-[300px]",children:[n&&n.models.length>0&&e.jsxs(ls,{children:[e.jsx(cs,{className:"text-xs text-primary",children:o("providerModelSelector.recommended")}),n.models.map(u=>{const r=f?Re(u.id):null;return e.jsx(ge,{value:u.id,children:e.jsxs("div",{className:"flex items-center gap-2",children:[e.jsx("span",{className:"truncate font-mono text-xs",children:u.id}),u.tier==="paid"&&e.jsx(U,{variant:"outline",className:"text-[9px] h-4 px-1",children:o("providerModelSelector.paid")}),r&&e.jsx(U,{variant:r.explicit?"secondary":"outline",className:"text-[9px] h-4 px-1 uppercase",children:r.label}),t===u.id&&e.jsx(te,{className:"w-3 h-3 text-primary ml-auto"})]})},u.id)})]}),l.length>0&&e.jsxs(ls,{children:[e.jsx(cs,{className:"text-xs text-muted-foreground",children:o("providerModelSelector.allModelsCount",{count:l.length})}),l.filter(u=>!h.has(u.id)).map(u=>{const r=f?Re(u.id):null;return e.jsx(ge,{value:u.id,children:e.jsxs("div",{className:"flex items-center gap-2",children:[e.jsx("span",{className:"truncate font-mono text-xs",children:u.id}),r&&e.jsx(U,{variant:r.explicit?"secondary":"outline",className:"text-[9px] h-4 px-1 uppercase",children:r.label}),t===u.id&&e.jsx(te,{className:"w-3 h-3 text-primary ml-auto"})]})},u.id)})]}),(!n||n.models.length===0)&&l.length===0&&e.jsx("div",{className:"py-2 px-3 text-xs text-muted-foreground",children:o("providerModelSelector.noModelsAvailable")})]})]})]})}function wa({open:s,onClose:a,currentValues:t,onApply:i,onSave:n,isSaving:l,catalog:x,allModels:o}){const{t:h}=Z(),[f,v]=d.useState(t),[u,r]=d.useState(""),y=j=>{j?(v(t),r("")):a()};return e.jsx(Be,{open:s,onOpenChange:y,children:e.jsxs(Ge,{className:"sm:max-w-md",children:[e.jsx($e,{children:e.jsxs(Qe,{className:"flex items-center gap-2",children:[e.jsx(je,{className:"w-4 h-4"}),h("customPresetDialog.title")]})}),e.jsxs("div",{className:"space-y-4 py-4",children:[e.jsxs("div",{className:"space-y-2",children:[e.jsx(W,{htmlFor:"preset-name",children:h("customPresetDialog.presetNameOptional")}),e.jsx(oe,{id:"preset-name",value:u,onChange:j=>r(j.target.value),placeholder:h("customPresetDialog.presetNamePlaceholder"),className:"text-sm"})]}),e.jsx(Ze,{}),x?.provider==="codex"&&e.jsxs("p",{className:"text-[11px] text-muted-foreground rounded-md border bg-muted/30 px-2.5 py-2",children:[h("customPresetDialog.codexTipPrefix")," ",e.jsx("code",{children:"-medium"}),", ",e.jsx("code",{children:"-high"}),", and"," ",e.jsx("code",{children:"-xhigh"})," ",h("customPresetDialog.codexTipSuffix")]}),e.jsx(ie,{label:h("customPresetDialog.defaultModel"),description:h("customPresetDialog.defaultModelDesc"),value:f.default,onChange:j=>v({...f,default:j}),catalog:x,allModels:o}),e.jsx(ie,{label:h("customPresetDialog.opusModel"),description:h("customPresetDialog.opusModelDesc"),value:f.opus,onChange:j=>v({...f,opus:j}),catalog:x,allModels:o}),e.jsx(ie,{label:h("customPresetDialog.sonnetModel"),description:h("customPresetDialog.sonnetModelDesc"),value:f.sonnet,onChange:j=>v({...f,sonnet:j}),catalog:x,allModels:o}),e.jsx(ie,{label:h("customPresetDialog.haikuModel"),description:h("customPresetDialog.haikuModelDesc"),value:f.haiku,onChange:j=>v({...f,haiku:j}),catalog:x,allModels:o})]}),e.jsxs(tt,{className:"gap-2 sm:gap-0",children:[e.jsx(O,{variant:"outline",onClick:a,children:h("customPresetDialog.cancel")}),n&&e.jsxs(O,{variant:"secondary",onClick:()=>n(f,u||void 0),disabled:l||!u.trim(),children:[l?e.jsx(J,{className:"w-4 h-4 mr-1 animate-spin"}):e.jsx(Ae,{className:"w-4 h-4 mr-1"}),h("customPresetDialog.savePreset")]}),e.jsxs(O,{onClick:()=>i(f,u||void 0),children:[e.jsx(ve,{className:"w-4 h-4 mr-1"}),h("customPresetDialog.applyPreset")]})]})]})})}function me({label:s,command:a}){return e.jsxs("div",{children:[e.jsx("label",{className:"text-xs text-muted-foreground",children:s}),e.jsxs("div",{className:"mt-1 flex gap-2",children:[e.jsx("code",{className:"flex-1 px-2 py-1.5 bg-muted rounded text-xs font-mono truncate",children:a}),e.jsx(Ms,{value:a,size:"icon",className:"h-6 w-6"})]})]})}function ya({provider:s,displayName:a,defaultTarget:t,data:i,authStatus:n}){const l=t||"claude",x=l==="droid";return e.jsx(ze,{className:"h-full",children:e.jsxs("div",{className:"p-4 space-y-6",children:[e.jsxs("div",{children:[e.jsxs("h3",{className:"text-sm font-medium flex items-center gap-2 mb-3",children:[e.jsx(Rs,{className:"w-4 h-4"}),"Provider Information"]}),e.jsxs("div",{className:"space-y-3 bg-card rounded-lg border p-4 shadow-sm",children:[e.jsxs("div",{className:"grid grid-cols-[100px_1fr] gap-2 text-sm items-center",children:[e.jsx("span",{className:"font-medium text-muted-foreground",children:"Provider"}),e.jsx("span",{className:"font-mono",children:a})]}),i&&e.jsxs(e.Fragment,{children:[e.jsxs("div",{className:"grid grid-cols-[100px_1fr] gap-2 text-sm items-center",children:[e.jsx("span",{className:"font-medium text-muted-foreground",children:"File Path"}),e.jsxs("div",{className:"flex items-center gap-2 min-w-0",children:[e.jsx("code",{className:"bg-muted px-1.5 py-0.5 rounded text-xs break-all",children:i.path}),e.jsx(Ms,{value:i.path,size:"icon",className:"h-5 w-5"})]})]}),e.jsxs("div",{className:"grid grid-cols-[100px_1fr] gap-2 text-sm items-center",children:[e.jsx("span",{className:"font-medium text-muted-foreground",children:"Last Modified"}),e.jsx("span",{className:"text-xs",children:new Date(i.mtime).toLocaleString()})]})]}),e.jsxs("div",{className:"grid grid-cols-[100px_1fr] gap-2 text-sm items-center",children:[e.jsx("span",{className:"font-medium text-muted-foreground",children:"Status"}),n.authenticated?e.jsxs(U,{variant:"outline",className:"w-fit text-green-600 border-green-200 bg-green-50",children:[e.jsx(Kt,{className:"w-3 h-3 mr-1"}),"Authenticated"]}):e.jsx(U,{variant:"outline",className:"w-fit text-muted-foreground",children:"Not connected"})]}),e.jsxs("div",{className:"grid grid-cols-[100px_1fr] gap-2 text-sm items-center",children:[e.jsx("span",{className:"font-medium text-muted-foreground",children:"Default Target"}),e.jsx("span",{className:"font-mono",children:l})]})]})]}),e.jsxs("div",{children:[e.jsx("h3",{className:"text-sm font-medium mb-3",children:"Quick Usage"}),e.jsxs("div",{className:"space-y-3 bg-card rounded-lg border p-4 shadow-sm",children:[e.jsx(me,{label:"Run with prompt",command:`ccs ${s} "your prompt"`}),e.jsx(me,{label:x?"Droid alias (explicit)":"Run on Droid",command:x?`ccsd ${s} "your prompt"`:`ccs ${s} --target droid "your prompt"`}),e.jsx(me,{label:x?"Override to Claude":"Override target",command:`ccs ${s} --target claude "your prompt"`}),e.jsx(me,{label:"Change model",command:`ccs ${s} --config`}),e.jsx(me,{label:"Add account",command:`ccs ${s} --add`}),e.jsx(me,{label:"List accounts",command:`ccs ${s} --accounts`})]})]})]})})}const ba={sm:{container:"w-6 h-6",icon:"w-4 h-4",text:"text-xs"},md:{container:"w-8 h-8",icon:"w-5 h-5",text:"text-sm"},lg:{container:"w-12 h-12",icon:"w-8 h-8",text:"text-lg"}};function ts({provider:s,className:a,size:t="md"}){const i=at(s),n=ba[t],l=nt(s);return e.jsx("div",{className:B("flex items-center justify-center rounded-md",l&&(it(s)?"bg-gray-900 p-1":"bg-white p-1"),n.container,a),children:l?e.jsx("img",{src:l,alt:`${s} logo`,className:B(n.icon,"object-contain")}):e.jsx("span",{className:B("font-semibold",i.textClass,n.text),children:i.letter})})}function ka({displayName:s,logoProvider:a,provider:t,data:i,isLoading:n,hasChanges:l,isRawJsonValid:x,isSaving:o,isRemoteMode:h,port:f,onRefetch:v,onSave:u}){return e.jsxs("div",{className:"px-6 py-4 border-b bg-background flex items-center justify-between shrink-0",children:[e.jsxs("div",{className:"flex items-center gap-3",children:[e.jsx(ts,{provider:a||t,size:"lg"}),e.jsxs("div",{children:[e.jsxs("div",{className:"flex items-center gap-2",children:[e.jsx("h2",{className:"text-lg font-semibold",children:s}),h&&e.jsxs(U,{variant:"secondary",className:"text-xs gap-1 bg-blue-100 text-blue-700 dark:bg-blue-900/30 dark:text-blue-400",children:[e.jsx(Os,{className:"w-3 h-3"}),"Remote"]}),f&&e.jsxs(U,{variant:"outline",className:"text-xs gap-1 font-mono",children:[e.jsx(Ht,{className:"w-3 h-3"}),":",f]}),!h&&i?.path&&e.jsx(U,{variant:"outline",className:"text-xs",children:i.path.replace(/^.*[\\/]/,"")})]}),h?e.jsx("p",{className:"text-xs text-blue-600 dark:text-blue-400 mt-0.5",children:"Traffic auto-routed to remote server"}):i&&e.jsxs("p",{className:"text-xs text-muted-foreground mt-0.5",children:["Last modified: ",new Date(i.mtime).toLocaleString()]})]})]}),e.jsxs("div",{className:"flex items-center gap-2",children:[e.jsx(O,{variant:"ghost",size:"sm",onClick:v,disabled:n,children:e.jsx(We,{className:`w-4 h-4 ${n?"animate-spin":""}`})}),e.jsx(O,{size:"sm",onClick:u,disabled:o||!l||!x,children:o?e.jsxs(e.Fragment,{children:[e.jsx(J,{className:"w-4 h-4 mr-1 animate-spin"}),"Saving..."]}):e.jsxs(e.Fragment,{children:[e.jsx(Vt,{className:"w-4 h-4 mr-1"}),"Save"]})})]})]})}function Ca({model:s,provider:a,enabled:t,onToggle:i,disabled:n,className:l}){if(!s?.extendedContext)return null;const x=pa(s.id);return e.jsxs("div",{className:B("rounded-lg border p-3 space-y-2",t?"border-primary/50 bg-primary/5":"border-border bg-muted/30",l),children:[e.jsxs("div",{className:"flex items-center justify-between",children:[e.jsxs("div",{className:"flex items-center gap-2",children:[e.jsx(ve,{className:B("w-4 h-4",t?"text-primary":"text-muted-foreground")}),e.jsx("span",{className:"text-sm font-medium",children:"Extended Context"}),e.jsx(U,{variant:t?"default":"secondary",className:"text-[10px] h-5 px-1.5",children:"1M tokens"})]}),e.jsx(Us,{checked:t,onCheckedChange:i,disabled:n})]}),e.jsxs("div",{className:"flex items-start gap-2 text-xs text-muted-foreground",children:[e.jsx(Rs,{className:"w-3.5 h-3.5 mt-0.5 shrink-0"}),e.jsxs("div",{className:"space-y-1",children:[e.jsx("p",{children:"Enables 1M token context window instead of default 200K."}),e.jsx("p",{className:"text-[10px]",children:x?e.jsxs("span",{className:"text-primary",children:["Auto-enabled for ",a," Gemini models"]}):e.jsxs("span",{children:["Opt-in for ",a," Claude models via --1m flag"]})}),t&&e.jsx("p",{className:"text-amber-600 dark:text-amber-500",children:"Note: 2x input pricing applies for tokens beyond 200K"})]})]})]})}function Aa({catalog:s,savedPresets:a,currentModel:t,opusModel:i,sonnetModel:n,haikuModel:l,providerModels:x,provider:o,extendedContextEnabled:h,onExtendedContextToggle:f,onApplyPreset:v,onUpdateEnvValue:u,onOpenCustomPreset:r,onDeletePreset:y,isDeletePending:j}){const p=s&&s.models.length>0||a.length>0,D=d.useMemo(()=>{if(!s||!t)return;const m=Ks(t);return s.models.find(R=>R.id===m)},[s,t]);return e.jsxs(e.Fragment,{children:[p&&e.jsxs("div",{children:[e.jsxs("h3",{className:"text-sm font-medium mb-2 flex items-center gap-2",children:[e.jsx(je,{className:"w-4 h-4"}),"Presets"]}),e.jsx("p",{className:"text-xs text-muted-foreground mb-3",children:"Apply pre-configured model mappings"}),e.jsxs("div",{className:"flex flex-wrap gap-2",children:[s?.models.slice(0,4).map(m=>e.jsxs(O,{variant:"outline",size:"sm",className:"text-xs h-7 gap-1",onClick:()=>{const R=m.presetMapping||{default:m.id,opus:m.id,sonnet:m.id,haiku:m.id};v({ANTHROPIC_MODEL:R.default,ANTHROPIC_DEFAULT_OPUS_MODEL:R.opus,ANTHROPIC_DEFAULT_SONNET_MODEL:R.sonnet,ANTHROPIC_DEFAULT_HAIKU_MODEL:R.haiku})},children:[e.jsx(ve,{className:"w-3 h-3"}),m.name]},m.id)),a.map(m=>e.jsxs("div",{className:"group relative",children:[e.jsxs(O,{variant:"secondary",size:"sm",className:"text-xs h-7 gap-1 pr-6",onClick:()=>{v({ANTHROPIC_MODEL:m.default,ANTHROPIC_DEFAULT_OPUS_MODEL:m.opus,ANTHROPIC_DEFAULT_SONNET_MODEL:m.sonnet,ANTHROPIC_DEFAULT_HAIKU_MODEL:m.haiku})},children:[e.jsx(Ae,{className:"w-3 h-3 fill-current"}),m.name]}),e.jsx(O,{variant:"ghost",size:"icon",className:"absolute right-0 top-0 h-7 w-5 opacity-0 group-hover:opacity-100 hover:text-destructive",onClick:R=>{R.stopPropagation(),y(m.name)},disabled:j,children:e.jsx(Xe,{className:"w-3 h-3"})})]},m.name)),e.jsxs(O,{variant:"outline",size:"sm",className:"text-xs h-7 gap-1 border-primary/50 text-primary hover:bg-primary/10 hover:border-primary",onClick:r,children:[e.jsx(_s,{className:"w-3 h-3"}),"Custom"]})]})]}),e.jsx(Ze,{}),e.jsxs("div",{children:[e.jsx("h3",{className:"text-sm font-medium mb-2",children:"Model Mapping"}),e.jsx("p",{className:"text-xs text-muted-foreground mb-4",children:"Configure which models to use for each tier"}),o==="codex"&&e.jsxs("p",{className:"text-[11px] text-muted-foreground mb-3 rounded-md border bg-muted/30 px-2.5 py-2",children:["Codex tip: suffixes ",e.jsx("code",{children:"-medium"}),", ",e.jsx("code",{children:"-high"}),", and ",e.jsx("code",{children:"-xhigh"})," ","pin reasoning effort. Unsuffixed models use Thinking settings."]}),e.jsxs("div",{className:"space-y-4",children:[e.jsx(ie,{label:"Default Model",description:"Used when no specific tier is requested",value:t,onChange:m=>u("ANTHROPIC_MODEL",m),catalog:s,allModels:x}),D?.extendedContext&&f&&e.jsx(Ca,{model:D,provider:o,enabled:h??!1,onToggle:f}),e.jsx(ie,{label:"Opus (Most capable)",description:"For complex reasoning tasks",value:i,onChange:m=>u("ANTHROPIC_DEFAULT_OPUS_MODEL",m),catalog:s,allModels:x}),e.jsx(ie,{label:"Sonnet (Balanced)",description:"Balance of speed and capability",value:n,onChange:m=>u("ANTHROPIC_DEFAULT_SONNET_MODEL",m),catalog:s,allModels:x}),e.jsx(ie,{label:"Haiku (Fast)",description:"Quick responses for simple tasks",value:l,onChange:m=>u("ANTHROPIC_DEFAULT_HAIKU_MODEL",m),catalog:s,allModels:x})]})]})]})}function js(s){const a=Math.max(0,Math.min(100,s));return a<=20?"bg-destructive":a<=50?"bg-yellow-500":"bg-green-500"}function vs(s){if(!s)return"";try{const a=new Date(s),i=new Date().getTime()-a.getTime();if(i<0)return"just now";const n=Math.floor(i/(1e3*60)),l=Math.floor(i/(1e3*60*60)),x=Math.floor(i/(1e3*60*60*24));return x>0?`${x}d ago`:l>0?`${l}h ago`:n>0?`${n}m ago`:"just now"}catch{return""}}function Sa(s){if(!s)return!1;try{const a=new Date(s);return new Date().getTime()-a.getTime()<3600*1e3}catch{return!1}}function Pa({account:s,onSetDefault:a,onRemove:t,onPauseToggle:i,isRemoving:n,isPausingAccount:l,privacyMode:x,showQuota:o,selectable:h,selected:f,onSelectChange:v}){const u=s.provider.toLowerCase(),r=u==="codex",y=u==="claude"||u==="anthropic",{data:j}=rt(o),{data:p,isLoading:D}=ot(u,s.id,o),m=j?.accountStats?.[s.email||s.id]?.lastUsedAt,R=Sa(m),E=lt(s.provider,p),b=ct(s.provider,p),L=r&&p&&dt(p)?ut(p.windows):null,A=[{label:"5h",value:L?.fiveHourWindow?.remainingPercent??null},{label:"Weekly",value:L?.weeklyWindow?.remainingPercent??null}].filter(w=>w.value!==null),g=y&&p&&mt(p)?[{label:"5h",value:p.coreUsage?.fiveHour?.remainingPercent??p.windows.find(w=>w.rateLimitType==="five_hour")?.remainingPercent??null},{label:"Weekly",value:p.coreUsage?.weekly?.remainingPercent??p.windows.find(w=>["seven_day","seven_day_opus","seven_day_sonnet","seven_day_oauth_apps","seven_day_cowork"].includes(w.rateLimitType))?.remainingPercent??null}].filter(w=>w.value!==null):[],I=r?A:y?g:[],N=E!==null?gt(E):null,k=N!==null?Number(N):null;return e.jsxs("div",{className:B("flex flex-col gap-2 p-3 rounded-lg border transition-colors overflow-hidden",s.isDefault?"border-primary/30 bg-primary/5":"border-border hover:bg-muted/30",s.paused&&"opacity-75",f&&"ring-2 ring-primary/50 bg-primary/5"),children:[e.jsxs("div",{className:"flex items-center justify-between gap-2",children:[e.jsxs("div",{className:"flex items-center gap-3 min-w-0 flex-1",children:[h&&e.jsx("button",{type:"button",onClick:()=>v?.(!f),className:B("flex items-center justify-center w-5 h-5 rounded border-2 transition-colors shrink-0",f?"bg-primary border-primary text-primary-foreground":"border-muted-foreground/30 hover:border-primary/50"),"aria-label":f?"Deselect account":"Select account",children:f&&e.jsx(te,{className:"w-3 h-3"})}),i&&e.jsx(le,{children:e.jsxs(ce,{children:[e.jsx(de,{asChild:!0,children:e.jsx(O,{variant:"ghost",size:"icon",className:"h-7 w-7 shrink-0",onClick:()=>i(!s.paused),disabled:l,children:l?e.jsx(J,{className:"w-4 h-4 animate-spin"}):s.paused?e.jsx(Ls,{className:"w-4 h-4 text-emerald-500"}):e.jsx(Ie,{className:"w-4 h-4 text-muted-foreground hover:text-foreground"})})}),e.jsx(ue,{side:"top",children:s.paused?"Resume account":"Pause account"})]})}),e.jsxs("div",{className:"relative shrink-0",children:[e.jsx("div",{className:B("flex items-center justify-center w-8 h-8 rounded-full",s.isDefault?"bg-primary/10":"bg-muted"),children:e.jsx(pe,{className:"w-4 h-4"})}),s.tier&&s.tier!=="unknown"&&s.tier!=="free"&&e.jsx("span",{className:B("absolute -bottom-0.5 -right-0.5 text-[7px] font-bold uppercase px-1 py-px rounded","ring-1 ring-background",s.tier==="ultra"?"bg-violet-500/20 text-violet-600 dark:bg-violet-500/30 dark:text-violet-300":"bg-yellow-500/20 text-yellow-700 dark:bg-yellow-500/25 dark:text-yellow-400"),children:s.tier==="ultra"?"U":"P"})]}),e.jsxs("div",{className:"min-w-0 flex-1",children:[e.jsxs("div",{className:"flex items-center gap-2",children:[e.jsx("span",{className:B("font-medium text-sm truncate",x&&Ce),children:s.email||s.id}),s.isDefault&&e.jsxs(U,{variant:"secondary",className:"text-[10px] h-4 px-1.5 gap-0.5",children:[e.jsx(Ae,{className:"w-2.5 h-2.5 fill-current"}),"Default"]}),s.paused&&e.jsxs(U,{variant:"outline",className:"text-[10px] h-4 px-1.5 border-yellow-500 text-yellow-600",children:[e.jsx(Ie,{className:"w-2 h-2 mr-0.5"}),"Paused"]})]}),s.provider==="agy"&&e.jsx("div",{className:"flex items-center gap-1.5 mt-1",children:s.projectId?e.jsx(le,{children:e.jsxs(ce,{children:[e.jsx(de,{asChild:!0,children:e.jsxs("div",{className:"flex items-center gap-1 text-xs text-muted-foreground",children:[e.jsx(Bt,{className:"w-3 h-3","aria-hidden":"true"}),e.jsx("span",{className:B("font-mono max-w-[180px] truncate",x&&Ce),title:s.projectId,children:s.projectId})]})}),e.jsx(ue,{side:"bottom",children:e.jsx("p",{className:"text-xs",children:"GCP Project ID (read-only)"})})]})}):e.jsx(le,{children:e.jsxs(ce,{children:[e.jsx(de,{asChild:!0,children:e.jsxs("div",{className:"flex items-center gap-1 text-xs text-amber-600 dark:text-amber-500",children:[e.jsx(Ye,{className:"w-3 h-3","aria-label":"Warning"}),e.jsx("span",{children:"Project ID: N/A"})]})}),e.jsx(ue,{side:"bottom",className:"max-w-[250px]",children:e.jsxs("div",{className:"text-xs space-y-1",children:[e.jsx("p",{className:"font-medium text-amber-600",children:"Missing Project ID"}),e.jsx("p",{children:"This may cause errors. Remove the account and re-add it to fetch the project ID."})]})})]})})}),s.lastUsedAt&&e.jsxs("div",{className:"flex items-center gap-1 text-xs text-muted-foreground mt-0.5",children:[e.jsx(xs,{className:"w-3 h-3"}),"Last used: ",new Date(s.lastUsedAt).toLocaleDateString()]})]})]}),e.jsxs(xt,{children:[e.jsx(pt,{asChild:!0,children:e.jsx(O,{variant:"ghost",size:"icon",className:"h-7 w-7 shrink-0",children:e.jsx(Gt,{className:"w-4 h-4"})})}),e.jsxs(ht,{align:"end",children:[!s.isDefault&&e.jsxs(ds,{onClick:a,children:[e.jsx(Ae,{className:"w-4 h-4 mr-2"}),"Set as default"]}),e.jsxs(ds,{className:"text-destructive focus:text-destructive",onClick:t,disabled:n,children:[e.jsx(Is,{className:"w-4 h-4 mr-2"}),n?"Removing...":"Remove account"]})]})]})]}),o&&e.jsx("div",{className:"pl-11",children:D?e.jsxs("div",{className:"flex items-center gap-2 text-xs text-muted-foreground",children:[e.jsx(J,{className:"w-3 h-3 animate-spin"}),e.jsx("span",{children:"Loading quota..."})]}):k!==null?e.jsxs("div",{className:"space-y-1.5",children:[e.jsx("div",{className:"flex items-center gap-1.5 text-xs",children:R?e.jsxs(e.Fragment,{children:[e.jsx($t,{className:"w-3 h-3 text-emerald-500"}),e.jsxs("span",{className:"text-emerald-600 dark:text-emerald-400",children:["Active · ",vs(m)]})]}):m?e.jsxs(e.Fragment,{children:[e.jsx(xs,{className:"w-3 h-3 text-muted-foreground"}),e.jsxs("span",{className:"text-muted-foreground",children:["Last used ",vs(m)]})]}):e.jsxs(e.Fragment,{children:[e.jsx(ps,{className:"w-3 h-3 text-muted-foreground"}),e.jsx("span",{className:"text-muted-foreground",children:"Not used yet"})]})}),e.jsx(le,{children:e.jsxs(ce,{children:[e.jsx(de,{asChild:!0,children:I.length>0?e.jsx("div",{className:"space-y-1.5",children:I.map(w=>e.jsxs("div",{className:"flex items-center gap-2",children:[e.jsx("span",{className:"w-10 text-[10px] text-muted-foreground",children:w.label}),e.jsx(_e,{value:Math.max(0,Math.min(100,w.value)),className:"h-2 flex-1",indicatorClassName:js(w.value)}),e.jsxs("span",{className:"text-xs font-medium w-10 text-right",children:[w.value,"%"]})]},w.label))}):e.jsxs("div",{className:"flex items-center gap-2",children:[e.jsx(_e,{value:Math.max(0,Math.min(100,k)),className:"h-2 flex-1",indicatorClassName:js(k)}),e.jsxs("span",{className:"text-xs font-medium w-10 text-right",children:[N,"%"]})]})}),e.jsx(ue,{side:"bottom",className:"max-w-xs",children:e.jsx(ft,{quota:p,resetTime:b})})]})})]}):p?.success?e.jsx("div",{className:"flex items-center gap-1.5",children:e.jsxs(U,{variant:"outline",className:"text-[10px] h-5 px-2 gap-1 border-muted-foreground/50 text-muted-foreground",children:[e.jsx(ps,{className:"w-3 h-3"}),"No limits"]})}):p?.needsReauth?e.jsx(le,{children:e.jsxs(ce,{children:[e.jsx(de,{asChild:!0,children:e.jsx("div",{className:"flex items-center gap-1.5",children:e.jsxs(U,{variant:"outline",className:"text-[10px] h-5 px-2 gap-1 border-amber-500/50 text-amber-600 dark:text-amber-400",children:[e.jsx(Qt,{className:"w-3 h-3"}),"Reauth"]})})}),e.jsx(ue,{side:"bottom",className:"max-w-[220px]",children:e.jsx("p",{className:"text-xs",children:p.error?.includes("No refresh token")?"No refresh token available. Remove and re-add account to fix.":p.error?.includes("refresh")||p.error?.includes("Invalid")?`Auto-refresh failed: ${p.error}`:`Token issue: ${p.error||"Re-authenticate required"}`})})]})}):p?.error||p&&!p.success?e.jsx(le,{children:e.jsxs(ce,{children:[e.jsx(de,{asChild:!0,children:e.jsx("div",{className:"flex items-center gap-1.5",children:e.jsxs(U,{variant:"outline",className:"text-[10px] h-5 px-2 gap-1 border-muted-foreground/50 text-muted-foreground",children:[e.jsx(zt,{className:"w-3 h-3"}),"N/A"]})})}),e.jsx(ue,{side:"bottom",children:e.jsx("p",{className:"text-xs",children:p?.error||"Quota information unavailable"})})]})}):null})]})}function Ma({selectedCount:s,onPauseSelected:a,onResumeSelected:t,onClearSelection:i,isPausing:n,isResuming:l}){if(s<1)return null;const x=n||l;return e.jsxs("div",{className:"flex items-center gap-3 p-2 bg-muted/50 rounded-lg border mt-2",children:[e.jsxs("span",{className:"text-sm text-muted-foreground",children:[s," selected"]}),e.jsx(O,{variant:"ghost",size:"sm",className:"text-xs h-6 px-2",onClick:i,disabled:x,children:"Clear"}),e.jsxs("div",{className:"flex gap-2 ml-auto",children:[e.jsxs(O,{size:"sm",variant:"outline",className:"h-7 text-xs gap-1",onClick:a,disabled:x,children:[n?e.jsx(J,{className:"w-3 h-3 animate-spin"}):e.jsx(Ie,{className:"w-3 h-3"}),"Pause Selected"]}),e.jsxs(O,{size:"sm",variant:"outline",className:"h-7 text-xs gap-1",onClick:t,disabled:x,children:[l?e.jsx(J,{className:"w-3 h-3 animate-spin"}):e.jsx(Ls,{className:"w-3 h-3"}),"Resume Selected"]})]})]})}function Da({accounts:s,onAddAccount:a,onSetDefault:t,onRemoveAccount:i,onPauseToggle:n,onSoloMode:l,onBulkPause:x,onBulkResume:o,isRemovingAccount:h,isPausingAccount:f,isSoloingAccount:v,isBulkPausing:u,isBulkResuming:r,privacyMode:y,showQuota:j,isKiro:p,kiroNoIncognito:D,onKiroNoIncognitoChange:m,kiroSettingsLoading:R}){const[E,b]=d.useState(new Set),L=d.useMemo(()=>new Set(s.map(_=>_.id)),[s]),A=d.useMemo(()=>new Set([...E].filter(_=>L.has(_))),[E,L]),g=!!(x&&o),I=A.size,N=s.length>0&&A.size===s.length,k=A.size>0&&A.size<s.length,w=d.useCallback(_=>{b(F=>{const H=new Set(F);return H.has(_)?H.delete(_):H.add(_),H})},[]),M=d.useCallback(()=>{b(new Set(s.map(_=>_.id)))},[s]),C=d.useCallback(()=>{b(new Set)},[]),q=d.useCallback(()=>{N?C():M()},[N,M,C]),G=d.useCallback(()=>{x&&A.size>0&&(x(Array.from(A)),b(new Set))},[x,A]),P=d.useCallback(()=>{o&&A.size>0&&(o(Array.from(A)),b(new Set))},[o,A]);return e.jsxs("div",{children:[e.jsxs("div",{className:"flex items-center justify-between mb-3",children:[e.jsxs("h3",{className:"text-sm font-medium flex items-center gap-2",children:[g&&s.length>0&&e.jsx(ke,{checked:N,onCheckedChange:q,"aria-label":"Select all accounts",className:k?"data-[state=checked]:bg-primary/50":"",...k?{"data-state":"indeterminate"}:{}}),e.jsx(pe,{className:"w-4 h-4"}),"Accounts",s.length>0&&e.jsx(U,{variant:"secondary",className:"text-xs",children:s.length})]}),e.jsxs(O,{variant:"default",size:"sm",className:"h-7 text-xs gap-1",onClick:a,children:[e.jsx(_s,{className:"w-3 h-3"}),"Add"]})]}),g&&I>0&&e.jsx(Ma,{selectedCount:I,onPauseSelected:G,onResumeSelected:P,onClearSelection:C,isPausing:!!u,isResuming:!!r}),s.length>0?e.jsx("div",{className:"space-y-2",children:s.map(_=>e.jsx(Pa,{account:_,onSetDefault:()=>t(_.id),onRemove:()=>i(_.id),onPauseToggle:n?F=>n(_.id,F):void 0,onSoloMode:l?()=>l(_.id):void 0,isRemoving:h,isPausingAccount:f,isSoloingAccount:v,privacyMode:y,showQuota:j,selectable:g,selected:A.has(_.id),onSelectChange:()=>w(_.id)},_.id))}):e.jsxs("div",{className:"py-6 text-center text-muted-foreground bg-muted/30 rounded-lg border border-dashed",children:[e.jsx(pe,{className:"w-8 h-8 mx-auto mb-2 opacity-50"}),e.jsx("p",{className:"text-sm",children:"No accounts connected"}),e.jsx("p",{className:"text-xs opacity-70",children:"Add an account to get started"})]}),p&&m&&e.jsx("div",{className:"mt-3 pt-3 border-t border-dashed",children:e.jsxs("div",{className:"flex items-center justify-between gap-3",children:[e.jsxs("div",{className:"flex items-center gap-2 text-sm text-muted-foreground",children:[e.jsx(Os,{className:"w-3.5 h-3.5"}),e.jsx("span",{children:"Use incognito"})]}),e.jsx(Us,{checked:!D,onCheckedChange:_=>m(!_),disabled:R,className:"scale-90"})]})})]})}function Ta({provider:s,catalog:a,savedPresets:t,currentModel:i,opusModel:n,sonnetModel:l,haikuModel:x,providerModels:o,extendedContextEnabled:h,onExtendedContextToggle:f,onApplyPreset:v,onUpdateEnvValue:u,onOpenCustomPreset:r,onDeletePreset:y,isDeletePending:j,accounts:p,onAddAccount:D,onSetDefault:m,onRemoveAccount:R,onPauseToggle:E,onSoloMode:b,onBulkPause:L,onBulkResume:A,isRemovingAccount:g,isPausingAccount:I,isSoloingAccount:N,isBulkPausing:k,isBulkResuming:w,privacyMode:M,isRemoteMode:C}){const q=s.toLowerCase(),G=(jt.includes(q)||["anthropic","antigravity","gemini-cli","copilot","github-copilot"].includes(q))&&!C,P=s==="kiro",[_,F]=d.useState(!0),[H,ee]=d.useState(!0),[$,Y]=d.useState(!1),X=d.useCallback(async()=>{if(P)try{ee(!0);const Q=(await ye.config.get()).cliproxy;F(Q?.kiro_no_incognito??!0)}catch{F(!0)}finally{ee(!1)}},[P]),c=d.useCallback(async T=>{F(T),Y(!0);try{const Q=await ye.config.get(),he=Q.cliproxy??{};await ye.config.update({...Q,cliproxy:{...he,kiro_no_incognito:T}})}catch{F(!T)}finally{Y(!1)}},[]);return d.useEffect(()=>{X()},[X]),e.jsx(ze,{className:"flex-1",children:e.jsxs("div",{className:"p-4 space-y-6",children:[e.jsx(Aa,{catalog:a,savedPresets:t,currentModel:i,opusModel:n,sonnetModel:l,haikuModel:x,providerModels:o,provider:s,extendedContextEnabled:h,onExtendedContextToggle:f,onApplyPreset:v,onUpdateEnvValue:u,onOpenCustomPreset:r,onDeletePreset:y,isDeletePending:j}),e.jsx(Ze,{}),e.jsx(Da,{accounts:p,onAddAccount:D,onSetDefault:m,onRemoveAccount:R,onPauseToggle:E,onSoloMode:b,onBulkPause:L,onBulkResume:A,isRemovingAccount:g,isPausingAccount:I,isSoloingAccount:N,isBulkPausing:k,isBulkResuming:w,privacyMode:M,showQuota:G,isKiro:P,kiroNoIncognito:_,onKiroNoIncognitoChange:c,kiroSettingsLoading:H||$})]})})}function Ns({provider:s,displayName:a,authStatus:t,catalog:i,logoProvider:n,baseProvider:l,isRemoteMode:x,port:o,defaultTarget:h,onAddAccount:f,onSetDefault:v,onRemoveAccount:u,onPauseToggle:r,onSoloMode:y,onBulkPause:j,onBulkResume:p,isRemovingAccount:D,isPausingAccount:m,isSoloingAccount:R,isBulkPausing:E,isBulkResuming:b}){const[L,A]=d.useState(!1),{privacyMode:g}=Cs(),{data:I}=vt(),{data:N}=Nt(s),k=wt(),w=yt(),M=N?.presets||[],C=l||s,q=d.useMemo(()=>{if(!I?.models)return[];const ne={gemini:["google"],agy:["antigravity"],codex:["openai"],qwen:["alibaba","qwen"],iflow:["iflow"],kiro:["kiro","aws"],ghcp:["github","copilot"],kimi:["kimi","moonshot"]}[C.toLowerCase()]||[C.toLowerCase()];return I.models.filter(is=>ne.some(Gs=>is.owned_by.toLowerCase().includes(Gs)))},[I,C]),G=(l||s).toLowerCase(),{data:P,isLoading:_,refetch:F,rawJsonContent:H,rawJsonEdits:ee,isRawJsonValid:$,hasChanges:Y,currentModel:X,opusModel:c,sonnetModel:T,haikuModel:Q,extendedContextEnabled:he,toggleExtendedContext:Se,handleRawJsonChange:Pe,updateEnvValue:Me,updateEnvValues:Ne,saveMutation:z,conflictDialog:S,handleConflictResolve:se,missingRequiredFields:ae}=ja(s),as=d.useMemo(()=>(t.accounts||[]).map(V=>({...V,provider:V.provider||l||s})),[t.accounts,l,s]),{data:we}=ws({queryKey:["auth-tokens-raw"],queryFn:async()=>{const V=await fetch("/api/settings/auth/tokens/raw");return V.ok?V.json():{apiKey:{value:"ccs-internal-managed"}}},staleTime:6e4}),ns=we?.apiKey?.value??"ccs-internal-managed",Hs=V=>{Ne({ANTHROPIC_BASE_URL:`http://127.0.0.1:${o??Le}/api/provider/${G}`,ANTHROPIC_AUTH_TOKEN:ns,...V}),K.success(`Applied "${V.ANTHROPIC_MODEL?.split("/").pop()||"preset"}" preset`)},Vs=(V,ne)=>{Ne({ANTHROPIC_BASE_URL:`http://127.0.0.1:${o??Le}/api/provider/${G}`,ANTHROPIC_AUTH_TOKEN:ns,ANTHROPIC_MODEL:V.default,ANTHROPIC_DEFAULT_OPUS_MODEL:V.opus,ANTHROPIC_DEFAULT_SONNET_MODEL:V.sonnet,ANTHROPIC_DEFAULT_HAIKU_MODEL:V.haiku}),K.success(`Applied ${ne?`"${ne}"`:"custom"} preset`),A(!1)},Bs=(V,ne)=>{if(!ne){K.error(Ss.t("commonToast.enterPresetName"));return}k.mutate({profile:s,data:{name:ne,...V}}),A(!1)};return e.jsxs("div",{className:"flex-1 flex flex-col overflow-hidden",children:[e.jsx(ka,{provider:s,displayName:a,logoProvider:n,data:P,isLoading:_,hasChanges:Y,isRawJsonValid:$,isSaving:z.isPending,isRemoteMode:x,port:o,onRefetch:F,onSave:()=>z.mutate()}),_?e.jsxs("div",{className:"flex-1 flex items-center justify-center",children:[e.jsx(J,{className:"w-8 h-8 animate-spin text-muted-foreground"}),e.jsx("span",{className:"ml-3 text-muted-foreground",children:"Loading settings..."})]}):e.jsxs("div",{className:"flex-1 grid grid-cols-[40%_60%] divide-x overflow-hidden",children:[e.jsx("div",{className:"flex flex-col overflow-hidden bg-muted/5",children:e.jsxs(bt,{defaultValue:"config",className:"h-full flex flex-col",children:[e.jsx("div",{className:"px-4 pt-4 shrink-0",children:e.jsxs(kt,{className:"w-full",children:[e.jsx(us,{value:"config",className:"flex-1",children:"Model Config"}),e.jsx(us,{value:"info",className:"flex-1",children:"Info & Usage"})]})}),e.jsxs("div",{className:"flex-1 overflow-hidden flex flex-col",children:[e.jsx(ms,{value:"config",className:"flex-1 mt-0 border-0 p-0 data-[state=inactive]:hidden flex flex-col overflow-hidden",children:e.jsx(Ta,{provider:s,catalog:i,savedPresets:M,currentModel:X,opusModel:c,sonnetModel:T,haikuModel:Q,providerModels:q,extendedContextEnabled:he,onExtendedContextToggle:Se,onApplyPreset:Hs,onUpdateEnvValue:Me,onOpenCustomPreset:()=>A(!0),onDeletePreset:V=>w.mutate({profile:s,name:V}),isDeletePending:w.isPending,accounts:as,onAddAccount:f,onSetDefault:v,onRemoveAccount:u,onPauseToggle:r,onSoloMode:y,onBulkPause:j,onBulkResume:p,isRemovingAccount:D,isPausingAccount:m,isSoloingAccount:R,isBulkPausing:E,isBulkResuming:b,privacyMode:g,isRemoteMode:x})}),e.jsx(ms,{value:"info",className:"h-full mt-0 border-0 p-0 data-[state=inactive]:hidden",children:e.jsx(ya,{provider:s,displayName:a,defaultTarget:h,data:P,authStatus:t})})]})]})}),e.jsxs("div",{className:"flex flex-col overflow-hidden",children:[e.jsxs("div",{className:"px-6 py-2 bg-muted/30 border-b flex items-center gap-2 shrink-0 h-[45px]",children:[e.jsx(Jt,{className:"w-4 h-4 text-muted-foreground"}),e.jsx("span",{className:"text-sm font-medium text-muted-foreground",children:"Raw Configuration (JSON)"})]}),e.jsx(Ct,{rawJsonContent:H,isRawJsonValid:$,rawJsonEdits:ee,onRawJsonChange:Pe,profileEnv:P?.settings?.env,missingRequiredFields:ae})]})]}),e.jsx(Zt,{open:S,title:"File Modified Externally",description:"This settings file was modified by another process. Overwrite with your changes or discard?",confirmText:"Overwrite",variant:"destructive",onConfirm:()=>se(!0),onCancel:()=>se(!1)}),e.jsx(wa,{open:L,onClose:()=>A(!1),currentValues:{default:X||"",opus:c||"",sonnet:T||"",haiku:Q||""},onApply:Vs,onSave:Bs,isSaving:k.isPending,catalog:i,allModels:q})]})}function Ea({status:s,isSelected:a,onSelect:t}){const{t:i}=Z(),n=s.accounts?.length||0;return e.jsxs("button",{className:B("w-full flex items-center gap-3 px-3 py-2.5 rounded-lg transition-colors cursor-pointer text-left",a?"bg-primary/10 border border-primary/20":"hover:bg-muted border border-transparent"),onClick:t,children:[e.jsx(ts,{provider:s.provider,size:"md"}),e.jsxs("div",{className:"flex-1 min-w-0",children:[e.jsxs("div",{className:"flex items-center gap-2",children:[e.jsx("span",{className:"font-medium text-sm truncate",children:s.displayName}),n>0&&e.jsx(U,{variant:"secondary",className:"text-[10px] h-4 px-1",children:n})]}),e.jsx("div",{className:"flex items-center gap-1.5 mt-0.5",children:s.authenticated?e.jsxs(e.Fragment,{children:[e.jsx(te,{className:"w-3 h-3 text-green-600"}),e.jsx("span",{className:"text-xs text-green-600",children:i("cliproxyPage.connected")})]}):e.jsxs(e.Fragment,{children:[e.jsx(Xe,{className:"w-3 h-3 text-muted-foreground"}),e.jsx("span",{className:"text-xs text-muted-foreground",children:i("cliproxyPage.notConnected")})]})})]})]})}function Ra({variant:s,parentAuth:a,isSelected:t,onSelect:i,onDelete:n,isDeleting:l}){const{t:x}=Z();return e.jsxs("button",{className:B("group w-full flex items-center gap-3 px-3 py-2 rounded-lg transition-colors cursor-pointer text-left pl-6",t?"bg-primary/10 border border-primary/20":"hover:bg-muted border border-transparent"),onClick:i,children:[e.jsxs("div",{className:"relative",children:[e.jsx(ts,{provider:s.provider,size:"sm"}),e.jsx(Fs,{className:"w-2.5 h-2.5 absolute -bottom-0.5 -right-0.5 text-muted-foreground"})]}),e.jsxs("div",{className:"flex-1 min-w-0",children:[e.jsxs("div",{className:"flex items-center gap-2",children:[e.jsx("span",{className:"font-medium text-sm truncate",children:s.name}),e.jsx(U,{variant:"outline",className:"text-[9px] h-4 px-1",children:x("cliproxyPage.variant")}),e.jsx(U,{variant:"outline",className:"text-[9px] h-4 px-1 uppercase",children:s.target||"claude"})]}),e.jsx("div",{className:"flex items-center gap-1.5 mt-0.5",children:a?.authenticated?e.jsxs(e.Fragment,{children:[e.jsx(te,{className:"w-3 h-3 text-green-600"}),e.jsx("span",{className:"text-xs text-muted-foreground truncate",children:x("cliproxyPage.viaProvider",{provider:s.provider})})]}):e.jsxs(e.Fragment,{children:[e.jsx(Xe,{className:"w-3 h-3 text-muted-foreground"}),e.jsx("span",{className:"text-xs text-muted-foreground",children:x("cliproxyPage.parentNotConnected")})]})})]}),e.jsx(O,{variant:"ghost",size:"icon",className:"h-6 w-6 opacity-0 group-hover:opacity-100 hover:text-destructive",onClick:o=>{o.stopPropagation(),n()},disabled:l,children:e.jsx(Is,{className:"w-3 h-3"})})]})}function Oa({onSetup:s}){const{t:a}=Z();return e.jsx("div",{className:"flex-1 flex items-center justify-center bg-muted/20",children:e.jsxs("div",{className:"text-center max-w-md px-8",children:[e.jsx("div",{className:"w-16 h-16 rounded-full bg-muted flex items-center justify-center mx-auto mb-6",children:e.jsx(ve,{className:"w-8 h-8 text-muted-foreground"})}),e.jsx("h2",{className:"text-xl font-semibold mb-2",children:a("cliproxyPage.emptyTitle")}),e.jsx("p",{className:"text-muted-foreground mb-4",children:a("cliproxyPage.emptyDesc")}),e.jsxs("p",{className:"text-xs text-muted-foreground mb-6",children:[a("cliproxyPage.emptyControlPanelPrefix")," ",e.jsx("a",{href:"/cliproxy/control-panel",className:"text-primary hover:underline",children:a("cliproxyPage.controlPanel")}),"."]}),e.jsxs(O,{onClick:s,className:"gap-2",children:[e.jsx(je,{className:"w-4 h-4"}),a("cliproxyPage.quickSetup")]})]})})}function Ya(){const{t:s}=Z(),a=Ue(),{data:t,isLoading:i}=ks(),{data:n,isFetching:l}=At(),{data:x}=St(),o=Pt(),h=Mt(),f=Dt(),v=Tt(),u=Et(),r=Rt(),y=Ot(),j=_t(),[p,D]=d.useState(()=>{if(typeof window<"u"){const T=new URLSearchParams(window.location.search).get("provider")?.trim().toLowerCase();return T&&Oe(T)?T:localStorage.getItem("cliproxy-selected-provider")}return null}),[m,R]=d.useState(null),[E,b]=d.useState(!1),[L,A]=d.useState(()=>{if(typeof window>"u")return null;const c=new URLSearchParams(window.location.search),T=c.get("provider")?.trim().toLowerCase();return c.get("action")!=="auth"||!T||!Oe(T)?null:{provider:T,displayName:Lt(T),isFirstAccount:!1}}),g=d.useMemo(()=>t?.authStatus||[],[t?.authStatus]),I=t?.source==="remote",N=d.useMemo(()=>n?.variants||[],[n?.variants]),k=c=>{D(c),c&&localStorage.setItem("cliproxy-selected-provider",c)},w=d.useMemo(()=>m?null:p&&g.some(c=>c.provider===p)?p:g.length>0&&(g.find(T=>(T.accounts?.length||0)>0)?.provider||g[0]?.provider)||null,[p,m,g]),M=g.find(c=>c.provider===w),C=N.find(c=>c.name===m),q=C?g.find(c=>c.provider===C.provider):void 0,G=(C?.provider||M?.provider||"").toLowerCase().trim(),P=G==="gemini"||G==="agy",_=()=>{a.invalidateQueries({queryKey:["cliproxy"]}),a.invalidateQueries({queryKey:["cliproxy-auth"]})},F=(c,T,Q)=>{f.isPending||v.isPending||(Q?f.mutate({provider:c,accountId:T}):v.mutate({provider:c,accountId:T}))},H=(c,T)=>{u.isPending||u.mutate({provider:c,accountId:T})},ee=(c,T)=>{r.isPending||r.mutate({provider:c,accountIds:T})},$=(c,T)=>{y.isPending||y.mutate({provider:c,accountIds:T})},Y=c=>{k(c),R(null)},X=c=>{R(c),k(null)};return e.jsxs("div",{className:"h-[calc(100vh-100px)] flex",children:[e.jsxs("div",{className:"w-80 border-r flex flex-col bg-muted/30",children:[e.jsxs("div",{className:"p-4 border-b bg-background",children:[e.jsxs("div",{className:"flex items-center justify-between mb-1",children:[e.jsxs("div",{className:"flex items-center gap-2",children:[e.jsx(ve,{className:"w-5 h-5 text-primary"}),e.jsx("h1",{className:"font-semibold",children:x?.backendLabel??"CLIProxy"})]}),e.jsx(O,{variant:"ghost",size:"icon",className:"h-8 w-8",onClick:_,disabled:l,children:e.jsx(We,{className:B("w-4 h-4",l&&"animate-spin")})})]}),e.jsx("p",{className:"text-xs text-muted-foreground mb-3",children:s("cliproxyPage.accountManagement")}),e.jsxs(O,{variant:"default",size:"sm",className:"w-full gap-2",onClick:()=>b(!0),children:[e.jsx(je,{className:"w-4 h-4"}),s("cliproxyPage.quickSetup")]})]}),e.jsx(ze,{className:"flex-1",children:e.jsxs("div",{className:"p-2",children:[e.jsx("div",{className:"text-xs font-medium text-muted-foreground uppercase tracking-wide px-3 py-2",children:s("cliproxyPage.providers")}),i?e.jsx("div",{className:"space-y-2 px-2",children:[1,2,3,4].map(c=>e.jsx(It,{className:"h-14 w-full rounded-lg"},c))}):e.jsx("div",{className:"space-y-1",children:g.map(c=>e.jsx(Ea,{status:c,isSelected:w===c.provider,onSelect:()=>Y(c.provider)},c.provider))}),N.length>0&&e.jsxs(e.Fragment,{children:[e.jsxs("div",{className:"text-xs font-medium text-muted-foreground uppercase tracking-wide px-3 py-2 mt-4 flex items-center gap-1.5",children:[e.jsx(Fs,{className:"w-3 h-3"}),s("cliproxyPage.variants")]}),e.jsx("div",{className:"space-y-1",children:N.map(c=>e.jsx(Ra,{variant:c,parentAuth:g.find(T=>T.provider===c.provider),isSelected:m===c.name,onSelect:()=>X(c.name),onDelete:()=>j.mutate(c.name),isDeleting:j.isPending},c.name))})]})]})}),e.jsx("div",{className:"p-3 border-t",children:e.jsx(Xt,{})}),e.jsx("div",{className:"p-3 border-t bg-background text-xs text-muted-foreground",children:e.jsxs("div",{className:"flex items-center justify-between",children:[e.jsx("span",{children:s("cliproxyPage.providerCount",{count:g.length})}),e.jsxs("span",{className:"flex items-center gap-1",children:[e.jsx(te,{className:"w-3 h-3 text-green-600"}),s("cliproxyPage.connectedCount",{count:g.filter(c=>c.authenticated).length})]})]})})]}),e.jsxs("div",{className:"flex-1 flex flex-col min-w-0 bg-background",children:[P&&e.jsx(qs,{showProxySettingsLink:!0,className:"mx-4 mt-4"}),C&&q?e.jsx(Ns,{provider:C.name,displayName:s("cliproxyPage.variantDisplay",{name:C.name,provider:C.provider}),authStatus:q,catalog:fe[C.provider],logoProvider:C.provider,baseProvider:C.provider,defaultTarget:C.target,isRemoteMode:I,port:C.port,onAddAccount:()=>A({provider:C.provider,displayName:q.displayName,isFirstAccount:(q.accounts?.length||0)===0}),onSetDefault:c=>o.mutate({provider:C.provider,accountId:c}),onRemoveAccount:c=>h.mutate({provider:C.provider,accountId:c}),onPauseToggle:(c,T)=>F(C.provider,c,T),onSoloMode:c=>H(C.provider,c),onBulkPause:c=>ee(C.provider,c),onBulkResume:c=>$(C.provider,c),isRemovingAccount:h.isPending,isPausingAccount:f.isPending||v.isPending,isSoloingAccount:u.isPending,isBulkPausing:r.isPending,isBulkResuming:y.isPending}):M?e.jsx(Ns,{provider:M.provider,displayName:M.displayName,authStatus:M,catalog:fe[M.provider],isRemoteMode:I,onAddAccount:()=>A({provider:M.provider,displayName:M.displayName,isFirstAccount:(M.accounts?.length||0)===0}),onSetDefault:c=>o.mutate({provider:M.provider,accountId:c}),onRemoveAccount:c=>h.mutate({provider:M.provider,accountId:c}),onPauseToggle:(c,T)=>F(M.provider,c,T),onSoloMode:c=>H(M.provider,c),onBulkPause:c=>ee(M.provider,c),onBulkResume:c=>$(M.provider,c),isRemovingAccount:h.isPending,isPausingAccount:f.isPending||v.isPending,isSoloingAccount:u.isPending,isBulkPausing:r.isPending,isBulkResuming:y.isPending}):e.jsx(Oa,{onSetup:()=>b(!0)})]}),e.jsx(oa,{open:E,onClose:()=>b(!1)}),e.jsx(xa,{open:L!==null,onClose:()=>A(null),provider:L?.provider||"",displayName:L?.displayName||"",isFirstAccount:L?.isFirstAccount||!1})]})}export{Ya as CliproxyPage};
@@ -1 +1 @@
1
- import{j as e}from"./radix-ui-BR1vy4kf.js";import{r as s}from"./react-vendor-CNOkPC89.js";import{u as k}from"./tanstack-e99Cjjy2.js";import{Y as K,aX as M}from"./index-hlYFfpDN.js";import{C as P}from"./default-ports-1QQSffYX.js";import{G as F,R as L,a3 as H,s as q,K as G,c as W,X}from"./icons-kPbuhVdj.js";import"./notifications-B2HqRBj7.js";import"./utils-CzKF5WmX.js";import"./form-utils-Cn_Uld6y.js";import"./code-highlight-BRUf_pqB.js";function _({port:c=P}){const i=s.useRef(null),[$,b]=s.useState(null),[R,E]=s.useState(0),[g,m]=s.useState(null),[I,d]=s.useState(!1),[S,T]=s.useState(!0),{data:j,error:f}=k({queryKey:["cliproxy-server-config"],queryFn:()=>K.cliproxyServer.get(),staleTime:3e4}),{data:y}=k({queryKey:["auth-tokens-raw"],queryFn:async()=>{const t=await fetch(M("/settings/auth/tokens/raw"));if(!t.ok)throw new Error("Failed to fetch auth tokens");return t.json()},staleTime:3e4});s.useEffect(()=>{f&&console.warn("[ControlPanelEmbed] Config fetch failed, using local mode:",f)},[f]);const{managementUrl:n,checkUrl:u,authToken:r,isRemote:l,displayHost:x}=s.useMemo(()=>{const t=j?.remote;if(t?.enabled&&t?.host){const o=t.protocol||"http",a=t.port||(o==="https"?443:P),v=o==="https"&&a===443||o==="http"&&a===80?"":`:${a}`,w=`${o}://${t.host}${v}`;return{managementUrl:`${w}/management.html`,checkUrl:`${w}/`,authToken:t.auth_token||void 0,isRemote:!0,displayHost:`${t.host}${v}`}}const h=y?.managementSecret?.value||"ccs";return{managementUrl:`http://localhost:${c}/management.html`,checkUrl:`http://localhost:${c}/`,authToken:h,isRemote:!1,displayHost:`localhost:${c}`}},[j,y,c]),p=$===n,N=!p;s.useEffect(()=>{const t=new AbortController,h=async()=>{try{(await fetch(u,{signal:t.signal})).ok?(d(!0),m(null)):(d(!1),m(l?`Remote CLIProxy at ${x} returned an error`:"CLIProxy returned an error"))}catch(a){if(a instanceof Error&&a.name==="AbortError")return;d(!1),m(l?`Remote CLIProxy at ${x} is not reachable`:"CLIProxy is not running")}},o=setTimeout(()=>t.abort(),2e3);return h().finally(()=>clearTimeout(o)),()=>t.abort()},[u,l,x]);const C=s.useCallback(()=>{if(!(!p||!i.current?.contentWindow||!r))try{const t=u.replace(/\/$/,"");if(!i.current.src.startsWith(t)){console.warn("[ControlPanelEmbed] Iframe origin mismatch, skipping postMessage");return}i.current.contentWindow.postMessage({type:"ccs-auto-login",apiBase:t,managementKey:r},t)}catch(t){console.debug("[ControlPanelEmbed] postMessage failed - cross-origin:",t)}},[r,u,p]);s.useEffect(()=>{C()},[C]);const U=s.useCallback(()=>{b(n)},[n]),A=()=>{b(null),E(t=>t+1),m(null),d(!1)};return!I&&g?e.jsxs("div",{className:"flex-1 flex flex-col",children:[e.jsxs("div",{className:"flex items-center justify-between p-4 border-b",children:[e.jsxs("div",{className:"flex items-center gap-2",children:[e.jsx(F,{className:"w-5 h-5 text-primary"}),e.jsx("h2",{className:"font-semibold",children:"CLIProxy Control Panel"})]}),e.jsxs("button",{className:"inline-flex items-center gap-2 px-3 py-1.5 text-sm border rounded-md hover:bg-muted",onClick:A,children:[e.jsx(L,{className:"w-4 h-4"}),"Retry"]})]}),e.jsx("div",{className:"flex-1 flex items-center justify-center bg-muted/20",children:e.jsxs("div",{className:"text-center max-w-md px-8",children:[e.jsx("div",{className:"w-16 h-16 rounded-full bg-destructive/10 flex items-center justify-center mx-auto mb-6",children:e.jsx(H,{className:"w-8 h-8 text-destructive"})}),e.jsx("h3",{className:"text-lg font-semibold mb-2",children:"CLIProxy Not Available"}),e.jsx("p",{className:"text-muted-foreground mb-4",children:g}),e.jsxs("p",{className:"text-sm text-muted-foreground",children:["Start a CLIProxy session with"," ",e.jsx("code",{className:"bg-muted px-1 rounded",children:"ccs gemini"})," or run"," ",e.jsx("code",{className:"bg-muted px-1 rounded",children:"ccs config"})," which auto-starts it."]})]})})]}):e.jsxs("div",{className:"flex-1 flex flex-col relative",children:[S&&!N&&e.jsx("div",{className:"absolute top-2 left-1/2 -translate-x-1/2 z-20",children:e.jsxs("div",{className:"flex items-center gap-2 px-3 py-1.5 bg-blue-50 dark:bg-blue-950 border border-blue-200 dark:border-blue-800 rounded-md text-sm",children:[l&&e.jsxs(e.Fragment,{children:[e.jsx(q,{className:"h-3.5 w-3.5 text-green-600"}),e.jsx("span",{className:"text-green-600 font-medium",children:"Remote"}),e.jsx("span",{className:"text-blue-300 dark:text-blue-700",children:"|"})]}),e.jsx(G,{className:"h-3.5 w-3.5 text-blue-600"}),e.jsxs("span",{children:["Key:"," ",e.jsx("code",{className:"bg-blue-100 dark:bg-blue-900 px-1 rounded font-mono font-semibold",children:r&&r.length>4?`***${r.slice(-4)}`:r||"ccs"})]}),e.jsx("a",{href:"/settings?tab=auth",className:"text-blue-600 hover:text-blue-800 dark:hover:text-blue-400",title:"Manage auth tokens",children:e.jsx(W,{className:"h-3.5 w-3.5"})}),e.jsx("button",{className:"text-blue-600 hover:text-blue-800 dark:hover:text-blue-400",onClick:()=>T(!1),children:e.jsx(X,{className:"h-3.5 w-3.5"})})]})}),N&&e.jsx("div",{className:"absolute inset-0 flex items-center justify-center bg-background/80 z-10",children:e.jsxs("div",{className:"text-center",children:[e.jsx(L,{className:"w-8 h-8 animate-spin text-primary mx-auto mb-2"}),e.jsx("p",{className:"text-sm text-muted-foreground",children:l?`Loading Control Panel from ${x}...`:"Loading Control Panel..."})]})}),e.jsx("iframe",{ref:i,src:n,className:"flex-1 w-full border-0",title:"CLIProxy Management Panel",onLoad:U},`${n}:${R}`)]})}function te(){return e.jsx("div",{className:"h-[calc(100vh-100px)] flex flex-col",children:e.jsx(_,{})})}export{te as CliproxyControlPanelPage};
1
+ import{j as e}from"./radix-ui-BR1vy4kf.js";import{r as s}from"./react-vendor-CNOkPC89.js";import{u as k}from"./tanstack-e99Cjjy2.js";import{Y as K,aX as M}from"./index-UzqXH0bn.js";import{C as P}from"./default-ports-1QQSffYX.js";import{G as F,R as L,a3 as H,s as q,K as G,c as W,X}from"./icons-kPbuhVdj.js";import"./notifications-B2HqRBj7.js";import"./utils-CzKF5WmX.js";import"./form-utils-Cn_Uld6y.js";import"./code-highlight-BRUf_pqB.js";function _({port:c=P}){const i=s.useRef(null),[$,b]=s.useState(null),[R,E]=s.useState(0),[g,m]=s.useState(null),[I,d]=s.useState(!1),[S,T]=s.useState(!0),{data:j,error:f}=k({queryKey:["cliproxy-server-config"],queryFn:()=>K.cliproxyServer.get(),staleTime:3e4}),{data:y}=k({queryKey:["auth-tokens-raw"],queryFn:async()=>{const t=await fetch(M("/settings/auth/tokens/raw"));if(!t.ok)throw new Error("Failed to fetch auth tokens");return t.json()},staleTime:3e4});s.useEffect(()=>{f&&console.warn("[ControlPanelEmbed] Config fetch failed, using local mode:",f)},[f]);const{managementUrl:n,checkUrl:u,authToken:r,isRemote:l,displayHost:x}=s.useMemo(()=>{const t=j?.remote;if(t?.enabled&&t?.host){const o=t.protocol||"http",a=t.port||(o==="https"?443:P),v=o==="https"&&a===443||o==="http"&&a===80?"":`:${a}`,w=`${o}://${t.host}${v}`;return{managementUrl:`${w}/management.html`,checkUrl:`${w}/`,authToken:t.auth_token||void 0,isRemote:!0,displayHost:`${t.host}${v}`}}const h=y?.managementSecret?.value||"ccs";return{managementUrl:`http://localhost:${c}/management.html`,checkUrl:`http://localhost:${c}/`,authToken:h,isRemote:!1,displayHost:`localhost:${c}`}},[j,y,c]),p=$===n,N=!p;s.useEffect(()=>{const t=new AbortController,h=async()=>{try{(await fetch(u,{signal:t.signal})).ok?(d(!0),m(null)):(d(!1),m(l?`Remote CLIProxy at ${x} returned an error`:"CLIProxy returned an error"))}catch(a){if(a instanceof Error&&a.name==="AbortError")return;d(!1),m(l?`Remote CLIProxy at ${x} is not reachable`:"CLIProxy is not running")}},o=setTimeout(()=>t.abort(),2e3);return h().finally(()=>clearTimeout(o)),()=>t.abort()},[u,l,x]);const C=s.useCallback(()=>{if(!(!p||!i.current?.contentWindow||!r))try{const t=u.replace(/\/$/,"");if(!i.current.src.startsWith(t)){console.warn("[ControlPanelEmbed] Iframe origin mismatch, skipping postMessage");return}i.current.contentWindow.postMessage({type:"ccs-auto-login",apiBase:t,managementKey:r},t)}catch(t){console.debug("[ControlPanelEmbed] postMessage failed - cross-origin:",t)}},[r,u,p]);s.useEffect(()=>{C()},[C]);const U=s.useCallback(()=>{b(n)},[n]),A=()=>{b(null),E(t=>t+1),m(null),d(!1)};return!I&&g?e.jsxs("div",{className:"flex-1 flex flex-col",children:[e.jsxs("div",{className:"flex items-center justify-between p-4 border-b",children:[e.jsxs("div",{className:"flex items-center gap-2",children:[e.jsx(F,{className:"w-5 h-5 text-primary"}),e.jsx("h2",{className:"font-semibold",children:"CLIProxy Control Panel"})]}),e.jsxs("button",{className:"inline-flex items-center gap-2 px-3 py-1.5 text-sm border rounded-md hover:bg-muted",onClick:A,children:[e.jsx(L,{className:"w-4 h-4"}),"Retry"]})]}),e.jsx("div",{className:"flex-1 flex items-center justify-center bg-muted/20",children:e.jsxs("div",{className:"text-center max-w-md px-8",children:[e.jsx("div",{className:"w-16 h-16 rounded-full bg-destructive/10 flex items-center justify-center mx-auto mb-6",children:e.jsx(H,{className:"w-8 h-8 text-destructive"})}),e.jsx("h3",{className:"text-lg font-semibold mb-2",children:"CLIProxy Not Available"}),e.jsx("p",{className:"text-muted-foreground mb-4",children:g}),e.jsxs("p",{className:"text-sm text-muted-foreground",children:["Start a CLIProxy session with"," ",e.jsx("code",{className:"bg-muted px-1 rounded",children:"ccs gemini"})," or run"," ",e.jsx("code",{className:"bg-muted px-1 rounded",children:"ccs config"})," which auto-starts it."]})]})})]}):e.jsxs("div",{className:"flex-1 flex flex-col relative",children:[S&&!N&&e.jsx("div",{className:"absolute top-2 left-1/2 -translate-x-1/2 z-20",children:e.jsxs("div",{className:"flex items-center gap-2 px-3 py-1.5 bg-blue-50 dark:bg-blue-950 border border-blue-200 dark:border-blue-800 rounded-md text-sm",children:[l&&e.jsxs(e.Fragment,{children:[e.jsx(q,{className:"h-3.5 w-3.5 text-green-600"}),e.jsx("span",{className:"text-green-600 font-medium",children:"Remote"}),e.jsx("span",{className:"text-blue-300 dark:text-blue-700",children:"|"})]}),e.jsx(G,{className:"h-3.5 w-3.5 text-blue-600"}),e.jsxs("span",{children:["Key:"," ",e.jsx("code",{className:"bg-blue-100 dark:bg-blue-900 px-1 rounded font-mono font-semibold",children:r&&r.length>4?`***${r.slice(-4)}`:r||"ccs"})]}),e.jsx("a",{href:"/settings?tab=auth",className:"text-blue-600 hover:text-blue-800 dark:hover:text-blue-400",title:"Manage auth tokens",children:e.jsx(W,{className:"h-3.5 w-3.5"})}),e.jsx("button",{className:"text-blue-600 hover:text-blue-800 dark:hover:text-blue-400",onClick:()=>T(!1),children:e.jsx(X,{className:"h-3.5 w-3.5"})})]})}),N&&e.jsx("div",{className:"absolute inset-0 flex items-center justify-center bg-background/80 z-10",children:e.jsxs("div",{className:"text-center",children:[e.jsx(L,{className:"w-8 h-8 animate-spin text-primary mx-auto mb-2"}),e.jsx("p",{className:"text-sm text-muted-foreground",children:l?`Loading Control Panel from ${x}...`:"Loading Control Panel..."})]})}),e.jsx("iframe",{ref:i,src:n,className:"flex-1 w-full border-0",title:"CLIProxy Management Panel",onLoad:U},`${n}:${R}`)]})}function te(){return e.jsx("div",{className:"h-[calc(100vh-100px)] flex flex-col",children:e.jsx(_,{})})}export{te as CliproxyControlPanelPage};
@@ -1 +1 @@
1
- import{j as e}from"./radix-ui-BR1vy4kf.js";import{A as c,a as d,b as g,c as x,d as h,e as j,f as A,g as D}from"./alert-dialog-cRwDSggu.js";function f({open:i,onConfirm:l,onCancel:r,title:s,description:t,confirmText:a="Confirm",variant:o="default"}){return e.jsx(c,{open:i,onOpenChange:n=>!n&&r(),children:e.jsxs(d,{children:[e.jsxs(g,{children:[e.jsx(x,{children:s}),e.jsx(h,{children:t})]}),e.jsxs(j,{children:[e.jsx(A,{onClick:r,children:"Cancel"}),e.jsx(D,{onClick:l,className:o==="destructive"?"bg-red-600 hover:bg-red-700 text-white":"",children:a})]})]})})}export{f as C};
1
+ import{j as e}from"./radix-ui-BR1vy4kf.js";import{A as c,a as d,b as g,c as x,d as h,e as j,f as A,g as D}from"./alert-dialog-zpinTbtF.js";function f({open:i,onConfirm:l,onCancel:r,title:s,description:t,confirmText:a="Confirm",variant:o="default"}){return e.jsx(c,{open:i,onOpenChange:n=>!n&&r(),children:e.jsxs(d,{children:[e.jsxs(g,{children:[e.jsx(x,{children:s}),e.jsx(h,{children:t})]}),e.jsxs(j,{children:[e.jsx(A,{onClick:r,children:"Cancel"}),e.jsx(D,{onClick:l,className:o==="destructive"?"bg-red-600 hover:bg-red-700 text-white":"",children:a})]})]})})}export{f as C};