@kaitranntt/ccs 7.52.2-dev.4 → 7.52.2-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.
- package/README.md +4 -0
- package/dist/api/services/index.d.ts +3 -1
- package/dist/api/services/index.d.ts.map +1 -1
- package/dist/api/services/index.js +10 -1
- package/dist/api/services/index.js.map +1 -1
- package/dist/api/services/profile-lifecycle-service.d.ts +24 -0
- package/dist/api/services/profile-lifecycle-service.d.ts.map +1 -0
- package/dist/api/services/profile-lifecycle-service.js +364 -0
- package/dist/api/services/profile-lifecycle-service.js.map +1 -0
- package/dist/api/services/profile-lifecycle-validation.d.ts +11 -0
- package/dist/api/services/profile-lifecycle-validation.d.ts.map +1 -0
- package/dist/api/services/profile-lifecycle-validation.js +87 -0
- package/dist/api/services/profile-lifecycle-validation.js.map +1 -0
- package/dist/api/services/profile-types.d.ts +66 -0
- package/dist/api/services/profile-types.d.ts.map +1 -1
- package/dist/cliproxy/auth/gemini-token-refresh.d.ts.map +1 -1
- package/dist/cliproxy/auth/gemini-token-refresh.js +42 -14
- package/dist/cliproxy/auth/gemini-token-refresh.js.map +1 -1
- package/dist/cliproxy/binary-manager.d.ts.map +1 -1
- package/dist/cliproxy/binary-manager.js +13 -14
- package/dist/cliproxy/binary-manager.js.map +1 -1
- package/dist/cliproxy/quota-fetcher-codex.d.ts.map +1 -1
- package/dist/cliproxy/quota-fetcher-codex.js +199 -63
- package/dist/cliproxy/quota-fetcher-codex.js.map +1 -1
- package/dist/cliproxy/quota-fetcher.d.ts +12 -0
- package/dist/cliproxy/quota-fetcher.d.ts.map +1 -1
- package/dist/cliproxy/quota-fetcher.js +328 -260
- package/dist/cliproxy/quota-fetcher.js.map +1 -1
- package/dist/cliproxy/quota-types.d.ts +18 -4
- package/dist/cliproxy/quota-types.d.ts.map +1 -1
- package/dist/commands/api-command.d.ts.map +1 -1
- package/dist/commands/api-command.js +275 -1
- package/dist/commands/api-command.js.map +1 -1
- package/dist/commands/help-command.d.ts.map +1 -1
- package/dist/commands/help-command.js +4 -0
- package/dist/commands/help-command.js.map +1 -1
- package/dist/ui/assets/accounts-C19R3bH_.js +1 -0
- package/dist/ui/assets/{alert-dialog-QYUhRzXK.js → alert-dialog-HJSnKjIs.js} +1 -1
- package/dist/ui/assets/api-DSqH5CNY.js +4 -0
- package/dist/ui/assets/auth-section-CYKSK386.js +1 -0
- package/dist/ui/assets/backups-section-DG3ZbzbF.js +1 -0
- package/dist/ui/assets/{checkbox-DGiQ22i1.js → checkbox-Du_1Cq1z.js} +1 -1
- package/dist/ui/assets/cliproxy-CrhOC0jn.js +3 -0
- package/dist/ui/assets/cliproxy-control-panel-DLzDKBdd.js +1 -0
- package/dist/ui/assets/{confirm-dialog-DDdeYI2H.js → confirm-dialog-D5ln-pf7.js} +1 -1
- package/dist/ui/assets/{copilot-DFaXcekY.js → copilot-Bhp7sQwN.js} +2 -2
- package/dist/ui/assets/{cursor-DepYQY1w.js → cursor-Dfn3jHV4.js} +1 -1
- package/dist/ui/assets/{droid-CTtRivEr.js → droid-Vjl6_n7D.js} +1 -1
- package/dist/ui/assets/globalenv-section-CcmKdM4g.js +1 -0
- package/dist/ui/assets/{health-D6oasd62.js → health-3zy8jvwf.js} +1 -1
- package/dist/ui/assets/{icons-BYZM_9Gm.js → icons-D2eEmpHv.js} +1 -1
- package/dist/ui/assets/index-BusjPRWX.css +1 -0
- package/dist/ui/assets/index-CP_OIR4n.js +1 -0
- package/dist/ui/assets/index-DbxzdeHz.js +1 -0
- package/dist/ui/assets/index-f_yPeQQQ.js +1 -0
- package/dist/ui/assets/{index-Diuv26bz.js → index-iOpyYqld.js} +1 -1
- package/dist/ui/assets/index-uTmtgDew.js +47 -0
- package/dist/ui/assets/proxy-status-widget-1lHBE3f2.js +1 -0
- package/dist/ui/assets/{separator-CSt5QZvu.js → separator-CsVbirkY.js} +1 -1
- package/dist/ui/assets/shared-DGq6uQfx.js +8 -0
- package/dist/ui/assets/{switch-CTrO47Q-.js → switch-BR0F3O9R.js} +1 -1
- package/dist/ui/assets/{updates-BBghSoYr.js → updates-ZSQz4CLF.js} +1 -1
- package/dist/ui/index.html +3 -3
- package/dist/web-server/routes/cliproxy-stats-routes.d.ts +12 -0
- package/dist/web-server/routes/cliproxy-stats-routes.d.ts.map +1 -1
- package/dist/web-server/routes/cliproxy-stats-routes.js +22 -9
- package/dist/web-server/routes/cliproxy-stats-routes.js.map +1 -1
- package/dist/web-server/routes/profile-routes.d.ts.map +1 -1
- package/dist/web-server/routes/profile-routes.js +206 -9
- package/dist/web-server/routes/profile-routes.js.map +1 -1
- package/dist/web-server/services/cliproxy-dashboard-install-service.d.ts +21 -0
- package/dist/web-server/services/cliproxy-dashboard-install-service.d.ts.map +1 -0
- package/dist/web-server/services/cliproxy-dashboard-install-service.js +51 -0
- package/dist/web-server/services/cliproxy-dashboard-install-service.js.map +1 -0
- package/package.json +1 -1
- package/dist/ui/assets/accounts-IsT_BiCd.js +0 -1
- package/dist/ui/assets/api-BYUVLPig.js +0 -1
- package/dist/ui/assets/auth-section-CqMQGbDM.js +0 -1
- package/dist/ui/assets/backups-section-htDdMLh5.js +0 -1
- package/dist/ui/assets/cliproxy-BpQHL05v.js +0 -3
- package/dist/ui/assets/cliproxy-control-panel-CCdMLyj2.js +0 -1
- package/dist/ui/assets/globalenv-section-CljFwX-s.js +0 -1
- package/dist/ui/assets/index-CGPdFYiT.js +0 -1
- package/dist/ui/assets/index-CK9IG4x4.js +0 -1
- package/dist/ui/assets/index-CeXOFv5d.js +0 -1
- package/dist/ui/assets/index-CmZS09IA.js +0 -47
- package/dist/ui/assets/index-WBo504Wu.css +0 -1
- package/dist/ui/assets/proxy-status-widget-exblPwy_.js +0 -1
- package/dist/ui/assets/shared-CbdTTMNS.js +0 -8
|
@@ -1 +0,0 @@
|
|
|
1
|
-
import{j as e}from"./radix-ui-BR1vy4kf.js";import{r as n}from"./react-vendor-CNOkPC89.js";import{a as V,bg as W,b7 as X,b9 as Y,n as Z,I as C,d as c}from"./index-CmZS09IA.js";import{R as E,a3 as _,u as ee,l as se,E as K,e as T,k as R,m as z,aA as te,a2 as ae,z as ne,ai as re}from"./icons-BYZM_9Gm.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";function pe(){const{t:s}=V(),{fetchRawConfig:o}=W(),[a,D]=n.useState(null),[j,S]=n.useState(!0),[i,m]=n.useState(!1),[p,r]=n.useState(null),[g,f]=n.useState(null),[w,P]=n.useState(!1),[y,O]=n.useState(!1),[d,N]=n.useState(null),[u,v]=n.useState(null),[$,k]=n.useState(!1),[F,b]=n.useState(!1),h=n.useCallback(async()=>{try{S(!0),r(null);const t=await fetch("/api/settings/auth/tokens/raw");if(!t.ok)throw new Error(s("settingsAuth.failedFetchTokens"));const l=await t.json();D(l)}catch(t){r(t instanceof Error?t.message:s("settings.unknownError"))}finally{S(!1)}},[s]);n.useEffect(()=>{h(),o()},[h,o]),n.useEffect(()=>{if(g){const t=setTimeout(()=>f(null),3e3);return()=>clearTimeout(t)}},[g]),n.useEffect(()=>{if(p){const t=setTimeout(()=>r(null),5e3);return()=>clearTimeout(t)}},[p]);const I=async()=>{const t=d!==null&&d!==a?.apiKey.value,l=u!==null&&u!==a?.managementSecret.value;if(!(!t&&!l))try{m(!0),r(null);const x={};t&&(x.apiKey=d),l&&(x.managementSecret=u);const A=await fetch("/api/settings/auth/tokens",{method:"PUT",headers:{"Content-Type":"application/json"},body:JSON.stringify(x)});if(!A.ok){const Q=await A.json();throw new Error(Q.error||s("settingsAuth.failedSaveTokens"))}f(s("settingsAuth.tokensUpdated")),N(null),v(null),await h(),await o()}catch(x){r(x instanceof Error?x.message:s("settings.unknownError"))}finally{m(!1)}},U=async()=>{try{m(!0),r(null);const t=await fetch("/api/settings/auth/tokens/regenerate-secret",{method:"POST"});if(!t.ok){const l=await t.json();throw new Error(l.error||s("settingsAuth.failedRegenerate"))}f(s("settingsAuth.secretRegenerated")),await h(),await o()}catch(t){r(t instanceof Error?t.message:s("settings.unknownError"))}finally{m(!1)}},B=async()=>{try{m(!0),r(null);const t=await fetch("/api/settings/auth/tokens/reset",{method:"POST"});if(!t.ok){const l=await t.json();throw new Error(l.error||s("settingsAuth.failedReset"))}f(s("settingsAuth.tokensReset")),N(null),v(null),await h(),await o()}catch(t){r(t instanceof Error?t.message:s("settings.unknownError"))}finally{m(!1)}},J=async()=>{a&&(await navigator.clipboard.writeText(a.apiKey.value),k(!0),setTimeout(()=>k(!1),2e3))},L=async()=>{a&&(await navigator.clipboard.writeText(a.managementSecret.value),b(!0),setTimeout(()=>b(!1),2e3))},q=async()=>{j||i||(r(null),f(null),await Promise.all([h(),o()]))};if(j||!a)return e.jsx("div",{className:"flex-1 flex items-center justify-center",children:e.jsxs("div",{className:"flex items-center gap-3 text-muted-foreground",children:[e.jsx(E,{className:"w-5 h-5 animate-spin"}),e.jsx("span",{children:s("settings.loading")})]})});const G=d??a.apiKey.value,H=u??a.managementSecret.value,M=d!==null&&d!==a.apiKey.value||u!==null&&u!==a.managementSecret.value;return e.jsxs(e.Fragment,{children:[e.jsxs("div",{className:`absolute left-5 right-5 top-20 z-10 transition-all duration-200 ease-out ${p||g?"opacity-100 translate-y-0":"opacity-0 -translate-y-2 pointer-events-none"}`,children:[p&&e.jsxs(X,{variant:"destructive",className:"py-2 shadow-lg",children:[e.jsx(_,{className:"h-4 w-4"}),e.jsx(Y,{children:p})]}),g&&e.jsxs("div",{className:"flex items-center gap-2 px-3 py-2 rounded-md border border-green-200 bg-green-50 text-green-700 shadow-lg dark:border-green-900/50 dark:bg-green-900/90 dark:text-green-300",children:[e.jsx(ee,{className:"h-4 w-4 shrink-0"}),e.jsx("span",{className:"text-sm font-medium",children:g})]})]}),e.jsx(Z,{className:"flex-1",children:e.jsxs("div",{className:"p-5 space-y-6",children:[e.jsx("p",{className:"text-sm text-muted-foreground",children:s("settingsAuth.description")}),e.jsxs("div",{className:"space-y-3",children:[e.jsxs("div",{className:"flex items-center gap-2",children:[e.jsx(se,{className:"w-4 h-4 text-primary"}),e.jsx("h3",{className:"text-base font-medium",children:s("settingsAuth.apiKey")}),a.apiKey.isCustom&&e.jsx("span",{className:"text-xs px-2 py-0.5 rounded bg-amber-100 text-amber-700 dark:bg-amber-900/50 dark:text-amber-300",children:s("settingsAuth.custom")})]}),e.jsx("p",{className:"text-xs text-muted-foreground",children:s("settingsAuth.apiKeyDesc")}),e.jsx("div",{className:"flex gap-2",children:e.jsxs("div",{className:"relative flex-1",children:[e.jsx(C,{type:w?"text":"password",value:G,onChange:t=>N(t.target.value),placeholder:s("settingsAuth.apiKeyPlaceholder"),disabled:i,className:"pr-20 font-mono text-sm"}),e.jsxs("div",{className:"absolute right-2 top-1/2 -translate-y-1/2 flex gap-1",children:[e.jsx(c,{variant:"ghost",size:"sm",className:"h-7 w-7 p-0",onClick:()=>P(!w),children:w?e.jsx(K,{className:"w-4 h-4"}):e.jsx(T,{className:"w-4 h-4"})}),e.jsx(c,{variant:"ghost",size:"sm",className:"h-7 w-7 p-0",onClick:J,disabled:!a.apiKey.value,children:$?e.jsx(R,{className:"w-4 h-4 text-green-600"}):e.jsx(z,{className:"w-4 h-4"})})]})]})})]}),e.jsxs("div",{className:"space-y-3",children:[e.jsxs("div",{className:"flex items-center gap-2",children:[e.jsx(te,{className:"w-4 h-4 text-primary"}),e.jsx("h3",{className:"text-base font-medium",children:s("settingsAuth.managementSecret")}),a.managementSecret.isCustom&&e.jsx("span",{className:"text-xs px-2 py-0.5 rounded bg-amber-100 text-amber-700 dark:bg-amber-900/50 dark:text-amber-300",children:s("settingsAuth.custom")})]}),e.jsx("p",{className:"text-xs text-muted-foreground",children:s("settingsAuth.managementSecretDesc")}),e.jsxs("div",{className:"flex gap-2",children:[e.jsxs("div",{className:"relative flex-1",children:[e.jsx(C,{type:y?"text":"password",value:H,onChange:t=>v(t.target.value),placeholder:s("settingsAuth.managementSecretPlaceholder"),disabled:i,className:"pr-20 font-mono text-sm"}),e.jsxs("div",{className:"absolute right-2 top-1/2 -translate-y-1/2 flex gap-1",children:[e.jsx(c,{variant:"ghost",size:"sm",className:"h-7 w-7 p-0",onClick:()=>O(!y),children:y?e.jsx(K,{className:"w-4 h-4"}):e.jsx(T,{className:"w-4 h-4"})}),e.jsx(c,{variant:"ghost",size:"sm",className:"h-7 w-7 p-0",onClick:L,disabled:!a.managementSecret.value,children:F?e.jsx(R,{className:"w-4 h-4 text-green-600"}):e.jsx(z,{className:"w-4 h-4"})})]})]}),e.jsx(c,{variant:"outline",size:"sm",onClick:U,disabled:i,title:s("settingsAuth.generateSecret"),children:e.jsx(ae,{className:"w-4 h-4"})})]})]}),e.jsxs("div",{className:"pt-4 border-t",children:[e.jsxs(c,{variant:"outline",size:"sm",onClick:B,disabled:i||!a.apiKey.isCustom&&!a.managementSecret.isCustom,className:"gap-2",children:[e.jsx(ne,{className:"w-4 h-4"}),s("settingsAuth.resetDefaults")]}),e.jsx("p",{className:"text-xs text-muted-foreground mt-2",children:s("settingsAuth.resetDesc")})]})]})}),e.jsxs("div",{className:"p-4 border-t bg-background flex gap-2",children:[e.jsxs(c,{variant:"outline",size:"sm",onClick:q,disabled:j||i,className:"flex-1",children:[e.jsx(E,{className:`w-4 h-4 mr-2 ${j?"animate-spin":""}`}),s("settings.refresh")]}),e.jsxs(c,{variant:"default",size:"sm",onClick:I,disabled:!M||i,className:"flex-1",children:[e.jsx(re,{className:`w-4 h-4 mr-2 ${i?"animate-pulse":""}`}),s(i?"settingsAuth.saving":"settingsAuth.save")]})]})]})}export{pe as default};
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
import{j as e}from"./radix-ui-BR1vy4kf.js";import{r}from"./react-vendor-CNOkPC89.js";import{a as S,bg as E,n as k,S as n,C as g,b7 as R,b9 as D,B as T,d as C}from"./index-CmZS09IA.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-QYUhRzXK.js";import{a3 as $,u as H,a6 as y,t as M,z as Y,R as J}from"./icons-BYZM_9Gm.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,3 +0,0 @@
|
|
|
1
|
-
import{j as e}from"./radix-ui-BR1vy4kf.js";import{r as l}from"./react-vendor-CNOkPC89.js";import{a as Ke,u as bs,b as zs}from"./tanstack-e99Cjjy2.js";import{d as R,C as ks,b as Cs,c as B,P as Ae,a as ee,a3 as Z,L as Y,I as ce,r as Ve,s as Be,t as Ge,v as $e,w as je,a4 as As,a5 as Js,a6 as Ws,a7 as Xs,u as Ss,a8 as Qe,a9 as ze,aa as Je,ab as We,ac as Ps,ad as ls,ae as Ys,af as Zs,W as Ds,ag as Ie,ah as Ms,Y as be,B as H,ai as Fe,aj as cs,ak as et,al as st,am as tt,an as at,ao as ds,ap as us,aq as nt,x as Ts,n as Xe,ar as it,as as rt,at as ot,m as lt,au as ct,av as dt,aw as ut,ax as mt,ay as xt,az as pt,aA as ue,T as me,p as xe,q as pe,aB as ht,aC as gt,aD as ft,aE as ms,aF as jt,aG as vt,aH as Nt,aI as yt,aJ as wt,aK as bt,aL as kt,Q as Ct,R as At,U as xs,V as ps,aM as St,aN as Pt,aO as Dt,aP as Mt,aQ as Tt,aR as Ot,aS as Et,aT as _t,aU as Rt,aV as Lt,aW as It,aX as Ft,S as Ut}from"./index-CmZS09IA.js";import{C as Ue}from"./default-ports-1QQSffYX.js";import{t as q}from"./notifications-B2HqRBj7.js";import{C as Os,L as W,n as ge,N as qt,k as ne,m as Es,ap as Ye,R as Ze,o as fe,a2 as Ne,T as es,a0 as Ht,aq as _s,ar as Kt,as as Se,Z as ye,J as Rs,g as Vt,s as Ls,at as Bt,ai as Gt,X as ss,a1 as Is,w as Fs,x as qe,au as $t,t as hs,av as Qt,ah as Us,u as zt,aw as gs,l as Jt,a3 as Wt,al as Xt,ax as qs}from"./icons-BYZM_9Gm.js";import{R as ke,A as fs,D as Ee,i as Yt,a as Zt,P as ea}from"./proxy-status-widget-exblPwy_.js";import{C as Ce}from"./checkbox-DGiQ22i1.js";import{C as sa}from"./confirm-dialog-DDdeYI2H.js";import{S as ts}from"./separator-CSt5QZvu.js";import{S as Hs}from"./switch-CTrO47Q-.js";import"./utils-CzKF5WmX.js";import"./form-utils-Cn_Uld6y.js";import"./code-highlight-BRUf_pqB.js";import"./alert-dialog-QYUhRzXK.js";const ve={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-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:"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",name:"Kimi K2",description:"Kimi model currently available via iFlow"},{id:"deepseek-v3.2",name:"DeepSeek V3.2",description:"Current DeepSeek V3.2 model via iFlow"},{id:"deepseek-r1",name:"DeepSeek R1",description:"Reasoning-focused DeepSeek model"},{id:"glm-4.6",name:"GLM 4.6",description:"Zhipu GLM 4.6 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"}]}},_e="ccs-internal-managed";async function ta(){try{const s=await fetch("/api/settings/auth/tokens/raw");return s.ok?(await s.json())?.apiKey?.value??_e:_e}catch{return _e}}async function He(s,a){const t=ve[s];if(!t)return{success:!1};const n=t.models[0],i=n?.presetMapping||{default:t.defaultModel,opus:t.defaultModel,sonnet:t.defaultModel,haiku:t.defaultModel},c=await ta(),o={env:{ANTHROPIC_BASE_URL:`http://127.0.0.1:${Ue}/api/provider/${s}`,ANTHROPIC_AUTH_TOKEN:c,ANTHROPIC_MODEL:i.default,ANTHROPIC_DEFAULT_OPUS_MODEL:i.opus,ANTHROPIC_DEFAULT_SONNET_MODEL:i.sonnet,ANTHROPIC_DEFAULT_HAIKU_MODEL:i.haiku}};try{return{success:(await fetch(`/api/settings/${s}`,{method:"PUT",headers:{"Content-Type":"application/json"},body:JSON.stringify({settings:o})})).ok,presetName:n?.name||t.defaultModel}}catch{return{success:!1}}}function aa({currentProgress:s,allSteps:a}){return e.jsx("div",{className:"flex justify-center gap-1 pt-2",children:a.map((t,n)=>e.jsx("div",{className:`w-2 h-2 rounded-full transition-colors ${s>=n?"bg-primary":"bg-muted"}`},t))})}function na({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(Os,{className:"w-4 h-4 text-muted-foreground"})]},t.id))})}function ia({selectedProvider:s,providers:a,authCommand:t,isRefreshing:n,isPending:i,onBack:c,onStartAuth:m,onRefresh:o}){const[p,f]=l.useState(!1),N=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(R,{onClick:m,disabled:i,className:"w-full gap-2",size:"lg",children:i?e.jsxs(e.Fragment,{children:[e.jsx(W,{className:"w-4 h-4 animate-spin"}),"Authenticating..."]}):e.jsxs(e.Fragment,{children:[e.jsx(ge,{className:"w-4 h-4"}),"Authenticate in Browser"]})}),i&&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(ks,{children:e.jsxs(Cs,{className:"p-4 space-y-3",children:[e.jsxs("div",{className:"flex items-center gap-2 text-sm text-muted-foreground",children:[e.jsx(qt,{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(R,{variant:"outline",size:"icon",onClick:()=>N(t),children:p?e.jsx(ne,{className:"w-4 h-4 text-green-500"}):e.jsx(Es,{className:"w-4 h-4"})})]})]})}),e.jsxs("div",{className:"flex items-center justify-between",children:[e.jsxs(R,{variant:"ghost",onClick:c,disabled:i,children:[e.jsx(Ye,{className:"w-4 h-4 mr-2"}),"Back"]}),e.jsxs(R,{variant:"outline",onClick:o,disabled:n||i,children:[e.jsx(Ze,{className:`w-4 h-4 mr-2 ${n?"animate-spin":""}`}),n?"Checking...":"Refresh Status"]})]})]})}function ra({accounts:s,privacyMode:a,onSelect:t,onAddNew:n,onBack:i}){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(c=>e.jsxs("button",{type:"button",onClick:()=>t(c),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(fe,{className:"w-4 h-4 text-muted-foreground"})}),e.jsxs("div",{children:[e.jsx("div",{className:B("font-medium",a&&Ae),children:c.email||c.id}),c.isDefault&&e.jsx("div",{className:"text-xs text-muted-foreground",children:"Default account"})]})]}),e.jsx(Os,{className:"w-4 h-4 text-muted-foreground"})]},c.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:n,children:[e.jsx("div",{className:"w-8 h-8 rounded-full bg-primary/10 flex items-center justify-center shrink-0",children:e.jsx(ge,{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(R,{variant:"ghost",onClick:i,children:[e.jsx(Ye,{className:"w-4 h-4 mr-2"}),"Back"]})})]})}const js="__custom__";function oa({selectedProvider:s,selectedAccount:a,variantName:t,modelName:n,isPending:i,privacyMode:c,onVariantNameChange:m,onModelChange:o,onBack:p,onSkip:f,onCreate:N}){const{t:u}=ee(),r=ve[s]?.models||[],b=n&&!r.some(v=>v.id===n),[j,x]=l.useState(b),M=s==="agy"&&n.trim().length>0?Z(n):!1,g=v=>{v===js?(x(!0),o("")):(x(!1),o(v))};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(fe,{className:"w-4 h-4"}),e.jsxs("span",{children:[u("setupVariant.using")," ",e.jsx("span",{className:B(c&&Ae),children:a.email||a.id})]})]}),e.jsxs("div",{className:"space-y-2",children:[e.jsx(Y,{htmlFor:"variant-name",children:u("setupVariant.variantNameRequired")}),e.jsx(ce,{id:"variant-name",value:t,onChange:v=>m(v.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(Y,{children:u("setupVariant.model")}),j?e.jsxs("div",{className:"space-y-2",children:[e.jsx(ce,{value:n,onChange:v=>o(v.target.value),placeholder:u("setupVariant.modelPlaceholder")}),M&&e.jsx("p",{className:"text-xs text-destructive",children:"Antigravity denylist: Claude Opus 4.5 and Claude Sonnet 4.5 are deprecated."}),e.jsx("button",{type:"button",className:"text-xs text-primary hover:underline",onClick:()=>{x(!1),s==="agy"&&Z(n)&&o("")},children:u("setupVariant.choosePresetInstead")})]}):e.jsxs(Ve,{value:r.some(v=>v.id===n)?n:"",onValueChange:g,children:[e.jsx(Be,{children:e.jsx(Ge,{placeholder:u("setupVariant.selectModel")})}),e.jsxs($e,{children:[r.map(v=>e.jsx(je,{value:v.id,children:e.jsxs("div",{className:"flex items-center gap-2",children:[e.jsx("span",{children:v.name}),v.description&&e.jsxs("span",{className:"text-xs text-muted-foreground",children:["- ",v.description]})]})},v.id)),e.jsx(je,{value:js,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:ve[s]?.defaultModel||u("setupVariant.providerDefault")})})]}),e.jsxs("div",{className:"flex items-center justify-between pt-2",children:[e.jsxs(R,{variant:"ghost",onClick:p,children:[e.jsx(Ye,{className:"w-4 h-4 mr-2"}),u("setupVariant.back")]}),e.jsxs("div",{className:"flex items-center gap-2",children:[e.jsx(R,{variant:"ghost",onClick:f,children:u("setupVariant.skip")}),e.jsx(R,{onClick:N,disabled:!t||i||M,children:u(i?"setupVariant.creating":"setupVariant.createVariant")})]})]}),e.jsx("p",{className:"text-xs text-center text-muted-foreground",children:u("setupVariant.skipHint")})]})}function la({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(ne,{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(ks,{children:e.jsxs(Cs,{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(R,{onClick:a,className:"w-full",children:"Done"})]})}function ca({open:s,onClose:a}){const[t,n]=l.useState("provider"),[i,c]=l.useState(""),[m,o]=l.useState(null),[p,f]=l.useState(""),[N,u]=l.useState(""),[r,b]=l.useState(!1),[j,x]=l.useState(!1),{data:M,refetch:g}=As(),v=Js(),E=Ws(),C=Xs(),{privacyMode:I}=Ss(),D=M?.authStatus.find(T=>T.provider===i),h=l.useMemo(()=>D?.accounts||[],[D?.accounts]);l.useEffect(()=>{if(!s){const T=setTimeout(()=>{n("provider"),c(""),o(null),f(""),u(""),x(!1)},0);return()=>clearTimeout(T)}},[s]),l.useEffect(()=>{if(t==="auth"&&h.length>0&&!j){const T=setTimeout(()=>{n("account")},0);return()=>clearTimeout(T)}},[t,h,j]);const F=async()=>{b(!0),await g(),b(!1)},y=()=>{const T=(D?.accounts?.length||0)===0;E.mutate({provider:i},{onSuccess:async _=>{if(T){const U=await He(i);U.success&&U.presetName?q.success(`Applied "${U.presetName}" preset`):U.success||q.warning(Ds.t("commonToast.accountAddedPresetFailed"))}_.account&&(o(_.account),n("variant")),g()}})},A=T=>{c(T),(M?.authStatus.find(V=>V.provider===T)?.accounts||[]).length===0?n("auth"):n("account")},w=T=>{o(T),n("variant")},S=async()=>{if(!(!p||!i))try{await v.mutateAsync({name:p,provider:i,model:N||void 0,account:m?.id}),n("success")}catch(T){console.error("Failed to create variant:",T)}},k=`ccs ${i} --auth --add`,K=Zs(t),G=T=>{if(!T&&(E.isPending&&i&&C.mutate(i),t==="success"||t==="provider")){a();return}};return e.jsx(Qe,{open:s,onOpenChange:G,children:e.jsxs(ze,{className:"sm:max-w-lg",onPointerDownOutside:T=>{t!=="success"&&t!=="provider"&&T.preventDefault()},onEscapeKeyDown:T=>{(E.isPending||v.isPending)&&T.preventDefault()},children:[e.jsxs(Je,{children:[e.jsxs(We,{className:"flex items-center gap-2",children:[e.jsx(Ne,{className:"w-5 h-5 text-primary"}),"Quick Setup Wizard"]}),e.jsxs(Ps,{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(na,{providers:ls,onSelect:A}),t==="auth"&&e.jsx(ia,{selectedProvider:i,providers:ls,authCommand:k,isRefreshing:r,isPending:E.isPending,onBack:()=>n("provider"),onStartAuth:y,onRefresh:F}),t==="account"&&e.jsx(ra,{accounts:h,privacyMode:I,onSelect:w,onAddNew:()=>{x(!0),n("auth")},onBack:()=>n("provider")}),t==="variant"&&e.jsx(oa,{selectedProvider:i,selectedAccount:m,variantName:p,modelName:N,isPending:v.isPending,privacyMode:I,onVariantNameChange:f,onModelChange:u,onBack:()=>h.length>0?n("account"):n("provider"),onSkip:a,onCreate:S}),t==="success"&&e.jsx(la,{variantName:p,onClose:a})]}),e.jsx(aa,{currentProgress:K,allSteps:Ys})]})})}const da=3e3,ua=300*1e3;async function Re(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 le={provider:null,isAuthenticating:!1,error:null,authUrl:null,oauthState:null,isSubmittingCallback:!1,isDeviceCodeFlow:!1};function ma(){const[s,a]=l.useState(le),t=l.useRef(null),n=l.useRef(null),i=l.useRef(0),c=l.useRef(!1),m=Ke(),o=l.useCallback(()=>{n.current&&(clearInterval(n.current),n.current=null)},[]);l.useEffect(()=>()=>{t.current?.abort(),o(),c.current=!1},[o]);const p=l.useCallback(async(r,b)=>{if(Date.now()-i.current>ua){o(),a(j=>({...j,isAuthenticating:!1,error:"Authentication timed out. Please try again."}));return}try{const x=await(await fetch(`/api/cliproxy/auth/${r}/status?state=${encodeURIComponent(b)}`)).json();if(x.status==="ok")o(),m.invalidateQueries({queryKey:["cliproxy-auth"]}),m.invalidateQueries({queryKey:["account-quota"]}),q.success(`${r} authentication successful`),c.current=!1,a(le);else if(x.status==="auth_url"){const M=x.url||x.auth_url;M&&(a(g=>({...g,authUrl:M})),c.current||(c.current=!0,window.open(M,"_blank")))}else if(x.status==="device_code"){o();const M=x.user_code&&x.verification_url?`Open ${x.verification_url} and enter code: ${x.user_code}`:"Switch to Device Code method and try again.";q.error("Provider returned Device Code flow in callback mode"),a(g=>({...g,isAuthenticating:!1,error:M}))}else if(x.status==="error"){o();const M=x.error||"Authentication failed";q.error(M),a(g=>({...g,isAuthenticating:!1,error:M}))}}catch{}},[m,o]),f=l.useCallback(async(r,b)=>{if(!Ie(r)){a({...le,error:`Unknown provider: ${r}`});return}t.current?.abort(),o(),c.current=!1;const j=new AbortController;t.current=j;const M=(b?.flowType||(Ms(r)?"device_code":"authorization_code"))==="device_code",g=b?.startEndpoint||(M?"start":"start-url"),v={nickname:b?.nickname,kiroMethod:b?.kiroMethod,riskAcknowledgement:b?.riskAcknowledgement};a({provider:r,isAuthenticating:!0,error:null,authUrl:null,oauthState:null,isSubmittingCallback:!1,isDeviceCodeFlow:M});try{if(g==="start")fetch(`/api/cliproxy/auth/${r}/start`,{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify(v),signal:j.signal}).then(async E=>{const C=await Re(E),I=C.success===!0;if(E.ok&&I)m.invalidateQueries({queryKey:["cliproxy-auth"]}),m.invalidateQueries({queryKey:["account-quota"]}),c.current=!1,a(le);else{const D=typeof C.error=="string"?C.error:"Authentication failed";q.error(D),a(h=>({...h,isAuthenticating:!1,error:D}))}}).catch(E=>{if(E instanceof Error&&E.name==="AbortError")return;const C=E instanceof Error?E.message:"Authentication failed";q.error(C),a(I=>({...I,isAuthenticating:!1,error:C}))});else{const E=await fetch(`/api/cliproxy/auth/${r}/start-url`,{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify(v),signal:j.signal}),C=await Re(E),I=C.success===!0;if(!E.ok||!I){const F=typeof C.error=="string"?C.error:"Failed to start OAuth";throw new Error(F)}const D=typeof C.authUrl=="string"?C.authUrl:null,h=typeof C.state=="string"?C.state:null;a(F=>({...F,authUrl:D,oauthState:h})),D&&(c.current=!0,window.open(D,"_blank")),h&&(i.current=Date.now(),n.current=setInterval(()=>{p(r,h)},da))}}catch(E){if(E instanceof Error&&E.name==="AbortError"){c.current=!1,a(le);return}const C=E instanceof Error?E.message:"Authentication failed";q.error(C),a(I=>({...I,isAuthenticating:!1,error:C}))}},[p,o,m]),N=l.useCallback(()=>{const r=s.provider;t.current?.abort(),o(),c.current=!1,a(le),r&&be.cliproxy.auth.cancel(r).catch(()=>{})},[s.provider,o]),u=l.useCallback(async r=>{if(s.provider){a(b=>({...b,isSubmittingCallback:!0,error:null}));try{const b=await fetch(`/api/cliproxy/auth/${s.provider}/submit-callback`,{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify({redirectUrl:r})}),j=await Re(b),x=j.success===!0;if(b.ok&&x)o(),m.invalidateQueries({queryKey:["cliproxy-auth"]}),m.invalidateQueries({queryKey:["account-quota"]}),q.success(`${s.provider} authentication successful`),a(le);else{const M=typeof j.error=="string"?j.error:"Callback submission failed";throw new Error(M)}}catch(b){const j=b instanceof Error?b.message:"Failed to submit callback";q.error(j),a(x=>({...x,isSubmittingCallback:!1,error:j}))}}},[s.provider,m,o]);return l.useMemo(()=>({...s,startAuth:f,cancelAuth:N,submitCallback:u}),[s,f,N,u])}function Ks({className:s,showAcknowledgement:a=!1,acknowledgementPhrase:t=ke,acknowledgementText:n="",onAcknowledgementTextChange:i,disabled:c=!1,showProxySettingsLink:m=!1}){const{t:o}=ee(),p=o("accountSafetyWarning.title"),f=o("accountSafetyWarning.subtitle"),N=o("accountSafetyWarning.firstLine"),u=o("accountSafetyWarning.secondLine"),r="https://github.com/kaitranntt/ccs/issues/509",b=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(es,{className:"h-4 w-4"})}),e.jsxs("div",{children:[e.jsx("p",{className:"text-sm font-semibold leading-5",children:p}),e.jsx("p",{className:"text-xs text-muted-foreground",children:f})]})]}),e.jsx(H,{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:N}),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:[b,e.jsx(ge,{className:"h-3.5 w-3.5"})]}),m&&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(Ht,{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&&i&&e.jsxs("div",{className:"rounded-lg border border-amber-500/25 bg-amber-500/5 p-2.5",children:[e.jsxs(Y,{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(ce,{id:"account-risk-ack-text",value:n,onChange:x=>i(x.target.value),placeholder:t,disabled:c,className:"mt-2 font-mono text-xs"})]})]})]})}function xa({className:s,value:a,onChange:t,disabled:n=!1}){const{t:i}=ee(),c=[a.reviewedIssue509,a.understandsBanRisk,a.acceptsFullResponsibility,a.typedPhrase.trim().replace(/\s+/g," ").toUpperCase()===fs].filter(Boolean).length,m=c/4*100,o=p=>{t({...a,...p})};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(es,{className:"h-4 w-4"})}),e.jsxs("div",{className:"space-y-1",children:[e.jsx("p",{className:"text-sm font-semibold leading-5",children:i("antigravityChecklist.title")}),e.jsx("p",{className:"text-xs text-muted-foreground",children:i("antigravityChecklist.subtitle")})]})]}),e.jsx(H,{variant:"outline",className:"border-rose-500/40 text-rose-700 dark:text-rose-300",children:i("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:i("antigravityChecklist.completion")}),e.jsx("span",{children:i("antigravityChecklist.stepsCount",{current:c})})]}),e.jsx(Fe,{value:m,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(Ce,{id:"agy-step-reviewed-issue",checked:a.reviewedIssue509,onCheckedChange:p=>o({reviewedIssue509:!!p}),disabled:n}),e.jsx(Y,{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(Ce,{id:"agy-step-understands-risk",checked:a.understandsBanRisk,onCheckedChange:p=>o({understandsBanRisk:!!p}),disabled:n}),e.jsx(Y,{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(Ce,{id:"agy-step-accept-responsibility",checked:a.acceptsFullResponsibility,onCheckedChange:p=>o({acceptsFullResponsibility:!!p}),disabled:n}),e.jsx(Y,{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(_s,{className:"h-3.5 w-3.5"}),"Step 4: Type exact phrase to continue"]}),e.jsx(ce,{value:a.typedPhrase,onChange:p=>o({typedPhrase:p.target.value}),placeholder:fs,disabled:n,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(ge,{className:"h-3.5 w-3.5"})]})})]})]})}function pa(s){return s.trim().replace(/\s+/g," ").toUpperCase()}function ha({open:s,onClose:a,provider:t,displayName:n,isFirstAccount:i=!1}){const[c,m]=l.useState(""),[o,p]=l.useState(""),[f,N]=l.useState(!1),[u,r]=l.useState(null),[b,j]=l.useState(""),[x,M]=l.useState(Ee),[g,v]=l.useState(!1),[E,C]=l.useState(!1),[I,D]=l.useState(cs),{t:h}=ee(),F=l.useRef(!1),y=ma(),A=et(),w=t==="kiro",S=t==="gemini",k=t==="agy"&&!g,K=t==="agy"&&E,G=Yt(x),T=pa(b)===ke,_=Ms(t),U=st(t),V=tt(I),se=w?V.flowType==="device_code":_,z=y.isAuthenticating||A.isPending,X=c.trim(),te=u||y.error,d=l.useCallback(async()=>{const P=await fetch("/api/settings/auth/antigravity-risk");if(!P.ok)throw new Error("Failed to load Antigravity power user setting");return(await P.json()).antigravityAckBypass===!0},[]),O=()=>{m(""),p(""),N(!1),r(null),j(""),M(Ee),v(!1),C(!1),D(cs),F.current=!1,a()};l.useEffect(()=>{s&&(j(""),M(Ee),r(null))},[t,s]),l.useEffect(()=>{let P=!1;if(!s||t!=="agy"){v(!1),C(!1);return}return(async()=>{try{C(!0);const ae=await d();P||v(ae)}catch{P||v(!1)}finally{P||C(!1)}})(),()=>{P=!0}},[d,s,t]),l.useEffect(()=>{if(!s||t!=="agy"||!y.error||!g)return;const P=y.error.toLowerCase();if(!(P.includes("agy_risk_ack_required")||P.includes("responsibility acknowledgement")||P.includes("responsibility checklist")))return;let ae=!1;return(async()=>{try{C(!0);const we=await d();if(ae)return;v(we),we||r("Power user mode is off. Complete the AGY checklist and retry.")}catch{if(ae)return;v(!1),r("Power user mode is off. Complete the AGY checklist and retry.")}finally{ae||C(!1)}})(),()=>{ae=!0}},[g,y.error,d,s,t]),l.useEffect(()=>{!y.isAuthenticating&&!y.error&&y.provider===null&&s&&F.current&&(F.current=!1,(async()=>{try{const ie=await He(t);ie.success&&ie.presetName&&i&&q.success(`Applied "${ie.presetName}" preset`)}catch{}O()})())},[y.isAuthenticating,y.error,y.provider]);const $=()=>{y.cancelAuth(),O()},de=async()=>{y.authUrl&&(await navigator.clipboard.writeText(y.authUrl),N(!0),setTimeout(()=>N(!1),2e3))},Pe=()=>{o.trim()&&y.submitCallback(o.trim())},De=()=>{if(K){r("Loading Antigravity safety settings. Please wait a moment and retry.");return}if(k&&!G){r("Complete all Antigravity responsibility steps before authenticating this provider.");return}if(S&&!T){r(`Type "${ke}" to acknowledge the account safety warning before authenticating this provider.`);return}if(U&&!X){r(`Nickname is required for ${n} accounts.`);return}r(null),F.current=!0,y.startAuth(t,{nickname:X||void 0,kiroMethod:w?I:void 0,flowType:w?V.flowType:void 0,startEndpoint:w?V.startEndpoint:void 0,riskAcknowledgement:k?{version:Zt,reviewedIssue509:x.reviewedIssue509,understandsBanRisk:x.understandsBanRisk,acceptsFullResponsibility:x.acceptsFullResponsibility,typedPhrase:x.typedPhrase}:void 0})},Me=()=>{F.current=!0,A.mutate(void 0,{onSuccess:async()=>{const P=await He("kiro");P.success&&P.presetName&&i&&q.success(`Applied "${P.presetName}" preset`),O()}})},Te=P=>{P||$()},J=y.isAuthenticating;return e.jsx(Qe,{open:s,onOpenChange:Te,children:e.jsxs(ze,{className:"sm:max-w-md",onInteractOutside:P=>{J&&P.preventDefault()},children:[e.jsxs(Je,{children:[e.jsx(We,{children:h("addAccountDialog.title",{displayName:n})}),e.jsx(Ps,{children:h(w?"addAccountDialog.descKiro":se?"addAccountDialog.descDeviceCode":"addAccountDialog.descOauth")})]}),e.jsxs("div",{className:"space-y-4 py-4",children:[k&&!J&&e.jsx(xa,{value:x,onChange:P=>{M(P),r(null)},disabled:z}),t==="agy"&&g&&!J&&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(_s,{className:"h-3.5 w-3.5"}),h("addAccountDialog.powerUserEnabled")]}),h("addAccountDialog.powerUserSkipped")]}),S&&!J&&e.jsx(Ks,{showAcknowledgement:!0,acknowledgementPhrase:ke,acknowledgementText:b,onAcknowledgementTextChange:P=>{j(P),r(null)},disabled:z}),w&&!J&&e.jsxs("div",{className:"space-y-2",children:[e.jsx(Y,{htmlFor:"kiro-auth-method",children:h("addAccountDialog.authMethod")}),e.jsxs(Ve,{value:I,onValueChange:P=>{D(P),r(null)},children:[e.jsx(Be,{id:"kiro-auth-method",children:e.jsx(Ge,{placeholder:h("addAccountDialog.selectKiroAuthMethod")})}),e.jsx($e,{children:at.map(P=>e.jsx(je,{value:P.id,children:P.label},P.id))})]}),e.jsx("p",{className:"text-xs text-muted-foreground",children:V.description})]}),!J&&e.jsxs("div",{className:"space-y-2",children:[e.jsx(Y,{htmlFor:"nickname",children:h(U?"addAccountDialog.nicknameRequired":"addAccountDialog.nicknameOptional")}),e.jsxs("div",{className:"flex items-center gap-2",children:[e.jsx(fe,{className:"w-4 h-4 text-muted-foreground"}),e.jsx(ce,{id:"nickname",value:c,onChange:P=>{m(P.target.value),r(null)},placeholder:h("addAccountDialog.nicknamePlaceholder"),disabled:z,className:"flex-1"})]}),e.jsx("p",{className:"text-xs text-muted-foreground",children:h(U?"addAccountDialog.nicknameRequiredHint":"addAccountDialog.nicknameOptionalHint")})]}),J&&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(W,{className:"w-4 h-4 inline mr-2 animate-spin"}),h("addAccountDialog.waitingForAuth")]}),e.jsx("p",{className:"text-xs text-muted-foreground mt-1",children:y.isDeviceCodeFlow?h("addAccountDialog.deviceCodeHint"):h("addAccountDialog.browserHint")})]}),y.authUrl&&!y.isDeviceCodeFlow&&e.jsxs("div",{className:"space-y-3",children:[e.jsxs("div",{className:"space-y-2",children:[e.jsx(Y,{className:"text-xs",children:h("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:y.authUrl}),e.jsxs("div",{className:"flex gap-2 mt-2",children:[e.jsx(R,{variant:"outline",size:"sm",onClick:de,children:f?e.jsxs(e.Fragment,{children:[e.jsx(ne,{className:"w-3 h-3 mr-1"}),h("addAccountDialog.copied")]}):e.jsxs(e.Fragment,{children:[e.jsx(Es,{className:"w-3 h-3 mr-1"}),h("addAccountDialog.copy")]})}),e.jsxs(R,{variant:"outline",size:"sm",onClick:()=>{if(!y.authUrl)return;const P=window.open(y.authUrl,"_blank");(!P||P.closed||typeof P.closed>"u")&&q.warning(h("addAccountDialog.popupBlocked"),{duration:5e3})},children:[e.jsx(ge,{className:"w-3 h-3 mr-1"}),h("addAccountDialog.open")]})]})]})]}),e.jsxs("div",{className:"space-y-2",children:[e.jsx(Y,{htmlFor:"callback-url",className:"text-xs",children:h("addAccountDialog.redirectPasteLabel")}),e.jsx(ce,{id:"callback-url",value:o,onChange:P=>p(P.target.value),placeholder:h("addAccountDialog.callbackPlaceholder"),className:"font-mono text-xs"}),e.jsx(R,{variant:"secondary",size:"sm",onClick:Pe,disabled:!o.trim()||y.isSubmittingCallback,children:y.isSubmittingCallback?e.jsxs(e.Fragment,{children:[e.jsx(W,{className:"w-3 h-3 mr-1 animate-spin"}),h("addAccountDialog.submitting")]}):h("addAccountDialog.submitCallback")})]})]}),!y.authUrl&&!y.isDeviceCodeFlow&&e.jsx("p",{className:"text-xs text-center text-muted-foreground",children:h("addAccountDialog.preparingUrl")})]}),te&&e.jsx("p",{className:"text-xs text-center text-destructive",children:te}),A.isPending&&e.jsxs("p",{className:"text-sm text-center text-muted-foreground",children:[e.jsx(W,{className:"w-4 h-4 inline mr-2 animate-spin"}),h("addAccountDialog.importingToken")]}),e.jsxs("div",{className:"flex items-center justify-end gap-2 pt-2",children:[e.jsx(R,{variant:"ghost",onClick:$,children:h("addAccountDialog.cancel")}),w&&!J&&e.jsx(R,{variant:"outline",onClick:Me,disabled:z,children:A.isPending?e.jsxs(e.Fragment,{children:[e.jsx(W,{className:"w-4 h-4 mr-2 animate-spin"}),h("addAccountDialog.importing")]}):e.jsxs(e.Fragment,{children:[e.jsx(Kt,{className:"w-4 h-4 mr-2"}),h("addAccountDialog.importFromIde")]})}),!J&&e.jsxs(R,{onClick:De,disabled:z||K||U&&!X||k&&!G||S&&!T,children:[e.jsx(ge,{className:"w-4 h-4 mr-2"}),h("addAccountDialog.authenticate")]})]})]})]})})}const as="[1m]";function ga(s){return s.toLowerCase().startsWith("gemini-")}function ns(s){return s.toLowerCase().endsWith(as.toLowerCase())}function fa(s){return!s||ns(s)?s:`${s}${as}`}function Vs(s){return s&&(ns(s)?s.slice(0,-as.length):s)}const vs=["ANTHROPIC_MODEL"],ja=["ANTHROPIC_BASE_URL","ANTHROPIC_AUTH_TOKEN"];function va(s){const a=s?.env||{};return ja.filter(t=>!a[t]?.trim())}function Na(s){const[a,t]=l.useState(null),[n,i]=l.useState(!1),c=Ke(),{data:m,isLoading:o,refetch:p}=bs({queryKey:["settings",s],queryFn:async()=>{const A=await fetch(`/api/settings/${s}/raw`);return A.ok?A.json():{profile:s,settings:{env:{}},mtime:Date.now(),path:`~/.ccs/profiles/${s}/settings.json`}}}),f=m?.settings,N=l.useMemo(()=>a!==null?a:f?JSON.stringify(f,null,2):`{
|
|
2
|
-
"env": {}
|
|
3
|
-
}`,[a,f]),u=l.useCallback(A=>{t(A)},[]),r=l.useMemo(()=>{try{return JSON.parse(N)}catch{return f||{env:{}}}},[N,f]),b=r?.env?.ANTHROPIC_MODEL,j=r?.env?.ANTHROPIC_DEFAULT_OPUS_MODEL,x=r?.env?.ANTHROPIC_DEFAULT_SONNET_MODEL,M=r?.env?.ANTHROPIC_DEFAULT_HAIKU_MODEL,g=l.useMemo(()=>{const A=r?.env||{};return vs.some(w=>{const S=A[w];return S&&ns(S)})},[r]),v=l.useCallback((A,w)=>{const S={...r?.env||{},[A]:w},k={...r,env:S};t(JSON.stringify(k,null,2))},[r]),E=l.useCallback(A=>{const w=r?.env||{},S={};for(const G of vs){const T=w[G];T&&(S[G]=A?fa(T):Vs(T))}const k={...w,...S};delete k.CCS_EXTENDED_CONTEXT;const K={...r,env:k};t(JSON.stringify(K,null,2))},[r]),C=l.useCallback(A=>{const w={...r?.env||{},...A},S={...r,env:w};t(JSON.stringify(S,null,2))},[r]),I=l.useMemo(()=>{try{return JSON.parse(N),!0}catch{return!1}},[N]),D=l.useMemo(()=>a===null?!1:a!==JSON.stringify(f,null,2),[a,f]),h=l.useMemo(()=>va(r),[r]),F=zs({mutationFn:async()=>{const A=JSON.parse(N),w=await fetch(`/api/settings/${s}`,{method:"PUT",headers:{"Content-Type":"application/json"},body:JSON.stringify({settings:A,expectedMtime:m?.mtime})});if(w.status===409)throw new Error("CONFLICT");if(!w.ok)throw new Error("Failed to save");return w.json()},onSuccess:A=>{c.invalidateQueries({queryKey:["settings",s]}),t(null),A?.warning?q.success("Settings saved",{description:A.warning}):q.success("Settings saved")},onError:A=>{A.message==="CONFLICT"?i(!0):q.error(A.message)}}),y=async A=>{i(!1),A?(await p(),F.mutate()):t(null)};return{data:m,isLoading:o,refetch:p,rawJsonContent:N,rawJsonEdits:a,isRawJsonValid:I,hasChanges:D,currentSettings:r,currentModel:b,opusModel:j,sonnetModel:x,haikuModel:M,extendedContextEnabled:g,toggleExtendedContext:E,handleRawJsonChange:u,updateEnvValue:v,updateEnvValues:C,saveMutation:{mutate:()=>F.mutate(),isPending:F.isPending},conflictDialog:n,setConflictDialog:i,handleConflictResolve:y,missingRequiredFields:h}}const ya=/-(medium|high|xhigh)$/i;function wa(s){if(!s)return;const a=s.trim().match(ya);if(a?.[1])return a[1].toLowerCase()}function Le(s){if(!s)return null;const a=wa(s);return a?{label:`Pinned ${a}`,explicit:!0}:{label:"Auto effort",explicit:!1}}function oe({label:s,description:a,value:t,onChange:n,catalog:i,allModels:c,disabled:m}){const{t:o}=ee(),p=new Set(i?.models.map(u=>u.id)||[]),f=i?.provider==="codex",N=f?Le(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(Ve,{value:t||"",onValueChange:n,disabled:m,children:[e.jsx(Be,{className:"h-9",children:e.jsx(Ge,{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}),N&&e.jsx(H,{variant:N.explicit?"secondary":"outline",className:"text-[9px] h-4 px-1 uppercase",children:N.label})]})})}),e.jsxs($e,{className:"max-h-[300px]",children:[i&&i.models.length>0&&e.jsxs(ds,{children:[e.jsx(us,{className:"text-xs text-primary",children:o("providerModelSelector.recommended")}),i.models.map(u=>{const r=f?Le(u.id):null;return e.jsx(je,{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(H,{variant:"outline",className:"text-[9px] h-4 px-1",children:o("providerModelSelector.paid")}),r&&e.jsx(H,{variant:r.explicit?"secondary":"outline",className:"text-[9px] h-4 px-1 uppercase",children:r.label}),t===u.id&&e.jsx(ne,{className:"w-3 h-3 text-primary ml-auto"})]})},u.id)})]}),c.length>0&&e.jsxs(ds,{children:[e.jsx(us,{className:"text-xs text-muted-foreground",children:o("providerModelSelector.allModelsCount",{count:c.length})}),c.filter(u=>!p.has(u.id)).map(u=>{const r=f?Le(u.id):null;return e.jsx(je,{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(H,{variant:r.explicit?"secondary":"outline",className:"text-[9px] h-4 px-1 uppercase",children:r.label}),t===u.id&&e.jsx(ne,{className:"w-3 h-3 text-primary ml-auto"})]})},u.id)})]}),(!i||i.models.length===0)&&c.length===0&&e.jsx("div",{className:"py-2 px-3 text-xs text-muted-foreground",children:o("providerModelSelector.noModelsAvailable")})]})]})]})}function ba({open:s,onClose:a,currentValues:t,onApply:n,onSave:i,isSaving:c,catalog:m,allModels:o}){const{t:p}=ee(),[f,N]=l.useState(t),[u,r]=l.useState(""),b=j=>{j?(N(t),r("")):a()};return e.jsx(Qe,{open:s,onOpenChange:b,children:e.jsxs(ze,{className:"sm:max-w-md",children:[e.jsx(Je,{children:e.jsxs(We,{className:"flex items-center gap-2",children:[e.jsx(Ne,{className:"w-4 h-4"}),p("customPresetDialog.title")]})}),e.jsxs("div",{className:"space-y-4 py-4",children:[e.jsxs("div",{className:"space-y-2",children:[e.jsx(Y,{htmlFor:"preset-name",children:p("customPresetDialog.presetNameOptional")}),e.jsx(ce,{id:"preset-name",value:u,onChange:j=>r(j.target.value),placeholder:p("customPresetDialog.presetNamePlaceholder"),className:"text-sm"})]}),e.jsx(ts,{}),m?.provider==="codex"&&e.jsxs("p",{className:"text-[11px] text-muted-foreground rounded-md border bg-muted/30 px-2.5 py-2",children:[p("customPresetDialog.codexTipPrefix")," ",e.jsx("code",{children:"-medium"}),", ",e.jsx("code",{children:"-high"}),", and"," ",e.jsx("code",{children:"-xhigh"})," ",p("customPresetDialog.codexTipSuffix")]}),e.jsx(oe,{label:p("customPresetDialog.defaultModel"),description:p("customPresetDialog.defaultModelDesc"),value:f.default,onChange:j=>N({...f,default:j}),catalog:m,allModels:o}),e.jsx(oe,{label:p("customPresetDialog.opusModel"),description:p("customPresetDialog.opusModelDesc"),value:f.opus,onChange:j=>N({...f,opus:j}),catalog:m,allModels:o}),e.jsx(oe,{label:p("customPresetDialog.sonnetModel"),description:p("customPresetDialog.sonnetModelDesc"),value:f.sonnet,onChange:j=>N({...f,sonnet:j}),catalog:m,allModels:o}),e.jsx(oe,{label:p("customPresetDialog.haikuModel"),description:p("customPresetDialog.haikuModelDesc"),value:f.haiku,onChange:j=>N({...f,haiku:j}),catalog:m,allModels:o})]}),e.jsxs(nt,{className:"gap-2 sm:gap-0",children:[e.jsx(R,{variant:"outline",onClick:a,children:p("customPresetDialog.cancel")}),i&&e.jsxs(R,{variant:"secondary",onClick:()=>i(f,u||void 0),disabled:c||!u.trim(),children:[c?e.jsx(W,{className:"w-4 h-4 mr-1 animate-spin"}):e.jsx(Se,{className:"w-4 h-4 mr-1"}),p("customPresetDialog.savePreset")]}),e.jsxs(R,{onClick:()=>n(f,u||void 0),children:[e.jsx(ye,{className:"w-4 h-4 mr-1"}),p("customPresetDialog.applyPreset")]})]})]})})}function he({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(Ts,{value:a,size:"icon",className:"h-6 w-6"})]})]})}function ka({provider:s,displayName:a,defaultTarget:t,data:n,authStatus:i}){const c=t||"claude",m=c==="droid";return e.jsx(Xe,{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})]}),n&&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:n.path}),e.jsx(Ts,{value:n.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(n.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"}),i.authenticated?e.jsxs(H,{variant:"outline",className:"w-fit text-green-600 border-green-200 bg-green-50",children:[e.jsx(Vt,{className:"w-3 h-3 mr-1"}),"Authenticated"]}):e.jsx(H,{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:c})]})]})]}),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(he,{label:"Run with prompt",command:`ccs ${s} "your prompt"`}),e.jsx(he,{label:m?"Droid alias (explicit)":"Run on Droid",command:m?`ccsd ${s} "your prompt"`:`ccs ${s} --target droid "your prompt"`}),e.jsx(he,{label:m?"Override to Claude":"Override target",command:`ccs ${s} --target claude "your prompt"`}),e.jsx(he,{label:"Change model",command:`ccs ${s} --config`}),e.jsx(he,{label:"Add account",command:`ccs ${s} --add`}),e.jsx(he,{label:"List accounts",command:`ccs ${s} --accounts`})]})]})]})})}const Ca={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 is({provider:s,className:a,size:t="md"}){const n=it(s),i=Ca[t],c=rt(s);return e.jsx("div",{className:B("flex items-center justify-center rounded-md",c&&(ot(s)?"bg-gray-900 p-1":"bg-white p-1"),i.container,a),children:c?e.jsx("img",{src:c,alt:`${s} logo`,className:B(i.icon,"object-contain")}):e.jsx("span",{className:B("font-semibold",n.textClass,i.text),children:n.letter})})}function Aa({displayName:s,logoProvider:a,provider:t,data:n,isLoading:i,hasChanges:c,isRawJsonValid:m,isSaving:o,isRemoteMode:p,port:f,onRefetch:N,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(is,{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}),p&&e.jsxs(H,{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(Ls,{className:"w-3 h-3"}),"Remote"]}),f&&e.jsxs(H,{variant:"outline",className:"text-xs gap-1 font-mono",children:[e.jsx(Bt,{className:"w-3 h-3"}),":",f]}),!p&&n?.path&&e.jsx(H,{variant:"outline",className:"text-xs",children:n.path.replace(/^.*[\\/]/,"")})]}),p?e.jsx("p",{className:"text-xs text-blue-600 dark:text-blue-400 mt-0.5",children:"Traffic auto-routed to remote server"}):n&&e.jsxs("p",{className:"text-xs text-muted-foreground mt-0.5",children:["Last modified: ",new Date(n.mtime).toLocaleString()]})]})]}),e.jsxs("div",{className:"flex items-center gap-2",children:[e.jsx(R,{variant:"ghost",size:"sm",onClick:N,disabled:i,children:e.jsx(Ze,{className:`w-4 h-4 ${i?"animate-spin":""}`})}),e.jsx(R,{size:"sm",onClick:u,disabled:o||!c||!m,children:o?e.jsxs(e.Fragment,{children:[e.jsx(W,{className:"w-4 h-4 mr-1 animate-spin"}),"Saving..."]}):e.jsxs(e.Fragment,{children:[e.jsx(Gt,{className:"w-4 h-4 mr-1"}),"Save"]})})]})]})}function Sa({model:s,provider:a,enabled:t,onToggle:n,disabled:i,className:c}){if(!s?.extendedContext)return null;const m=ga(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",c),children:[e.jsxs("div",{className:"flex items-center justify-between",children:[e.jsxs("div",{className:"flex items-center gap-2",children:[e.jsx(ye,{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(H,{variant:t?"default":"secondary",className:"text-[10px] h-5 px-1.5",children:"1M tokens"})]}),e.jsx(Hs,{checked:t,onCheckedChange:n,disabled:i})]}),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:m?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 Pa({catalog:s,savedPresets:a,currentModel:t,opusModel:n,sonnetModel:i,haikuModel:c,providerModels:m,provider:o,extendedContextEnabled:p,onExtendedContextToggle:f,onApplyPreset:N,onUpdateEnvValue:u,onOpenCustomPreset:r,onDeletePreset:b,isDeletePending:j}){const x=s&&s.models.length>0||a.length>0,M=l.useMemo(()=>{if(!s||!t)return;const g=Vs(t);return s.models.find(v=>v.id===g)},[s,t]);return e.jsxs(e.Fragment,{children:[x&&e.jsxs("div",{children:[e.jsxs("h3",{className:"text-sm font-medium mb-2 flex items-center gap-2",children:[e.jsx(Ne,{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(g=>e.jsxs(R,{variant:"outline",size:"sm",className:"text-xs h-7 gap-1",onClick:()=>{const v=g.presetMapping||{default:g.id,opus:g.id,sonnet:g.id,haiku:g.id};N({ANTHROPIC_MODEL:v.default,ANTHROPIC_DEFAULT_OPUS_MODEL:v.opus,ANTHROPIC_DEFAULT_SONNET_MODEL:v.sonnet,ANTHROPIC_DEFAULT_HAIKU_MODEL:v.haiku})},children:[e.jsx(ye,{className:"w-3 h-3"}),g.name]},g.id)),a.map(g=>e.jsxs("div",{className:"group relative",children:[e.jsxs(R,{variant:"secondary",size:"sm",className:"text-xs h-7 gap-1 pr-6",onClick:()=>{N({ANTHROPIC_MODEL:g.default,ANTHROPIC_DEFAULT_OPUS_MODEL:g.opus,ANTHROPIC_DEFAULT_SONNET_MODEL:g.sonnet,ANTHROPIC_DEFAULT_HAIKU_MODEL:g.haiku})},children:[e.jsx(Se,{className:"w-3 h-3 fill-current"}),g.name]}),e.jsx(R,{variant:"ghost",size:"icon",className:"absolute right-0 top-0 h-7 w-5 opacity-0 group-hover:opacity-100 hover:text-destructive",onClick:v=>{v.stopPropagation(),b(g.name)},disabled:j,children:e.jsx(ss,{className:"w-3 h-3"})})]},g.name)),e.jsxs(R,{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(Is,{className:"w-3 h-3"}),"Custom"]})]})]}),e.jsx(ts,{}),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(oe,{label:"Default Model",description:"Used when no specific tier is requested",value:t,onChange:g=>u("ANTHROPIC_MODEL",g),catalog:s,allModels:m}),M?.extendedContext&&f&&e.jsx(Sa,{model:M,provider:o,enabled:p??!1,onToggle:f}),e.jsx(oe,{label:"Opus (Most capable)",description:"For complex reasoning tasks",value:n,onChange:g=>u("ANTHROPIC_DEFAULT_OPUS_MODEL",g),catalog:s,allModels:m}),e.jsx(oe,{label:"Sonnet (Balanced)",description:"Balance of speed and capability",value:i,onChange:g=>u("ANTHROPIC_DEFAULT_SONNET_MODEL",g),catalog:s,allModels:m}),e.jsx(oe,{label:"Haiku (Fast)",description:"Quick responses for simple tasks",value:c,onChange:g=>u("ANTHROPIC_DEFAULT_HAIKU_MODEL",g),catalog:s,allModels:m})]})]})]})}function Ns(s){const a=Math.max(0,Math.min(100,s));return a<=20?"bg-destructive":a<=50?"bg-yellow-500":"bg-green-500"}function ys(s){if(!s)return"";try{const a=new Date(s),n=new Date().getTime()-a.getTime();if(n<0)return"just now";const i=Math.floor(n/(1e3*60)),c=Math.floor(n/(1e3*60*60)),m=Math.floor(n/(1e3*60*60*24));return m>0?`${m}d ago`:c>0?`${c}h ago`:i>0?`${i}m ago`:"just now"}catch{return""}}function Da(s){if(!s)return!1;try{const a=new Date(s);return new Date().getTime()-a.getTime()<3600*1e3}catch{return!1}}function Ma({account:s,onSetDefault:a,onRemove:t,onPauseToggle:n,isRemoving:i,isPausingAccount:c,privacyMode:m,showQuota:o,selectable:p,selected:f,onSelectChange:N}){const u=s.provider.toLowerCase(),r=u==="codex",b=u==="claude"||u==="anthropic",{data:j}=lt(o),{data:x,isLoading:M}=ct(u,s.id,o),g=j?.accountStats?.[s.email||s.id]?.lastUsedAt,v=Da(g),E=dt(s.provider,x),C=ut(s.provider,x),I=r&&x&&mt(x)?xt(x.windows):null,D=[{label:"5h",value:I?.fiveHourWindow?.remainingPercent??null},{label:"Weekly",value:I?.weeklyWindow?.remainingPercent??null}].filter(w=>w.value!==null),h=b&&x&&pt(x)?[{label:"5h",value:x.coreUsage?.fiveHour?.remainingPercent??x.windows.find(w=>w.rateLimitType==="five_hour")?.remainingPercent??null},{label:"Weekly",value:x.coreUsage?.weekly?.remainingPercent??x.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):[],F=r?D:b?h:[],y=E!==null?jt(E):null,A=y!==null?Number(y):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:[p&&e.jsx("button",{type:"button",onClick:()=>N?.(!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(ne,{className:"w-3 h-3"})}),n&&e.jsx(ue,{children:e.jsxs(me,{children:[e.jsx(xe,{asChild:!0,children:e.jsx(R,{variant:"ghost",size:"icon",className:"h-7 w-7 shrink-0",onClick:()=>n(!s.paused),disabled:c,children:c?e.jsx(W,{className:"w-4 h-4 animate-spin"}):s.paused?e.jsx(Fs,{className:"w-4 h-4 text-emerald-500"}):e.jsx(qe,{className:"w-4 h-4 text-muted-foreground hover:text-foreground"})})}),e.jsx(pe,{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(fe,{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",m&&Ae),children:s.email||s.id}),s.isDefault&&e.jsxs(H,{variant:"secondary",className:"text-[10px] h-4 px-1.5 gap-0.5",children:[e.jsx(Se,{className:"w-2.5 h-2.5 fill-current"}),"Default"]}),s.paused&&e.jsxs(H,{variant:"outline",className:"text-[10px] h-4 px-1.5 border-yellow-500 text-yellow-600",children:[e.jsx(qe,{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(ue,{children:e.jsxs(me,{children:[e.jsx(xe,{asChild:!0,children:e.jsxs("div",{className:"flex items-center gap-1 text-xs text-muted-foreground",children:[e.jsx($t,{className:"w-3 h-3","aria-hidden":"true"}),e.jsx("span",{className:B("font-mono max-w-[180px] truncate",m&&Ae),title:s.projectId,children:s.projectId})]})}),e.jsx(pe,{side:"bottom",children:e.jsx("p",{className:"text-xs",children:"GCP Project ID (read-only)"})})]})}):e.jsx(ue,{children:e.jsxs(me,{children:[e.jsx(xe,{asChild:!0,children:e.jsxs("div",{className:"flex items-center gap-1 text-xs text-amber-600 dark:text-amber-500",children:[e.jsx(es,{className:"w-3 h-3","aria-label":"Warning"}),e.jsx("span",{children:"Project ID: N/A"})]})}),e.jsx(pe,{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(hs,{className:"w-3 h-3"}),"Last used: ",new Date(s.lastUsedAt).toLocaleDateString()]})]})]}),e.jsxs(ht,{children:[e.jsx(gt,{asChild:!0,children:e.jsx(R,{variant:"ghost",size:"icon",className:"h-7 w-7 shrink-0",children:e.jsx(Qt,{className:"w-4 h-4"})})}),e.jsxs(ft,{align:"end",children:[!s.isDefault&&e.jsxs(ms,{onClick:a,children:[e.jsx(Se,{className:"w-4 h-4 mr-2"}),"Set as default"]}),e.jsxs(ms,{className:"text-destructive focus:text-destructive",onClick:t,disabled:i,children:[e.jsx(Us,{className:"w-4 h-4 mr-2"}),i?"Removing...":"Remove account"]})]})]})]}),o&&e.jsx("div",{className:"pl-11",children:M?e.jsxs("div",{className:"flex items-center gap-2 text-xs text-muted-foreground",children:[e.jsx(W,{className:"w-3 h-3 animate-spin"}),e.jsx("span",{children:"Loading quota..."})]}):A!==null?e.jsxs("div",{className:"space-y-1.5",children:[e.jsx("div",{className:"flex items-center gap-1.5 text-xs",children:v?e.jsxs(e.Fragment,{children:[e.jsx(zt,{className:"w-3 h-3 text-emerald-500"}),e.jsxs("span",{className:"text-emerald-600 dark:text-emerald-400",children:["Active · ",ys(g)]})]}):g?e.jsxs(e.Fragment,{children:[e.jsx(hs,{className:"w-3 h-3 text-muted-foreground"}),e.jsxs("span",{className:"text-muted-foreground",children:["Last used ",ys(g)]})]}):e.jsxs(e.Fragment,{children:[e.jsx(gs,{className:"w-3 h-3 text-muted-foreground"}),e.jsx("span",{className:"text-muted-foreground",children:"Not used yet"})]})}),e.jsx(ue,{children:e.jsxs(me,{children:[e.jsx(xe,{asChild:!0,children:F.length>0?e.jsx("div",{className:"space-y-1.5",children:F.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(Fe,{value:Math.max(0,Math.min(100,w.value)),className:"h-2 flex-1",indicatorClassName:Ns(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(Fe,{value:Math.max(0,Math.min(100,A)),className:"h-2 flex-1",indicatorClassName:Ns(A)}),e.jsxs("span",{className:"text-xs font-medium w-10 text-right",children:[y,"%"]})]})}),e.jsx(pe,{side:"bottom",className:"max-w-xs",children:e.jsx(vt,{quota:x,resetTime:C})})]})})]}):x?.success?e.jsx("div",{className:"flex items-center gap-1.5",children:e.jsxs(H,{variant:"outline",className:"text-[10px] h-5 px-2 gap-1 border-muted-foreground/50 text-muted-foreground",children:[e.jsx(gs,{className:"w-3 h-3"}),"No limits"]})}):x?.needsReauth?e.jsx(ue,{children:e.jsxs(me,{children:[e.jsx(xe,{asChild:!0,children:e.jsx("div",{className:"flex items-center gap-1.5",children:e.jsxs(H,{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(Jt,{className:"w-3 h-3"}),"Reauth"]})})}),e.jsx(pe,{side:"bottom",className:"max-w-[220px]",children:e.jsx("p",{className:"text-xs",children:x.error?.includes("No refresh token")?"No refresh token available. Remove and re-add account to fix.":x.error?.includes("refresh")||x.error?.includes("Invalid")?`Auto-refresh failed: ${x.error}`:`Token issue: ${x.error||"Re-authenticate required"}`})})]})}):x?.error||x&&!x.success?e.jsx(ue,{children:e.jsxs(me,{children:[e.jsx(xe,{asChild:!0,children:e.jsx("div",{className:"flex items-center gap-1.5",children:e.jsxs(H,{variant:"outline",className:"text-[10px] h-5 px-2 gap-1 border-muted-foreground/50 text-muted-foreground",children:[e.jsx(Wt,{className:"w-3 h-3"}),"N/A"]})})}),e.jsx(pe,{side:"bottom",children:e.jsx("p",{className:"text-xs",children:x?.error||"Quota information unavailable"})})]})}):null})]})}function Ta({selectedCount:s,onPauseSelected:a,onResumeSelected:t,onClearSelection:n,isPausing:i,isResuming:c}){if(s<1)return null;const m=i||c;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(R,{variant:"ghost",size:"sm",className:"text-xs h-6 px-2",onClick:n,disabled:m,children:"Clear"}),e.jsxs("div",{className:"flex gap-2 ml-auto",children:[e.jsxs(R,{size:"sm",variant:"outline",className:"h-7 text-xs gap-1",onClick:a,disabled:m,children:[i?e.jsx(W,{className:"w-3 h-3 animate-spin"}):e.jsx(qe,{className:"w-3 h-3"}),"Pause Selected"]}),e.jsxs(R,{size:"sm",variant:"outline",className:"h-7 text-xs gap-1",onClick:t,disabled:m,children:[c?e.jsx(W,{className:"w-3 h-3 animate-spin"}):e.jsx(Fs,{className:"w-3 h-3"}),"Resume Selected"]})]})]})}function Oa({accounts:s,onAddAccount:a,onSetDefault:t,onRemoveAccount:n,onPauseToggle:i,onSoloMode:c,onBulkPause:m,onBulkResume:o,isRemovingAccount:p,isPausingAccount:f,isSoloingAccount:N,isBulkPausing:u,isBulkResuming:r,privacyMode:b,showQuota:j,isKiro:x,kiroNoIncognito:M,onKiroNoIncognitoChange:g,kiroSettingsLoading:v}){const[E,C]=l.useState(new Set),I=l.useMemo(()=>new Set(s.map(_=>_.id)),[s]),D=l.useMemo(()=>new Set([...E].filter(_=>I.has(_))),[E,I]),h=!!(m&&o),F=D.size,y=s.length>0&&D.size===s.length,A=D.size>0&&D.size<s.length,w=l.useCallback(_=>{C(U=>{const V=new Set(U);return V.has(_)?V.delete(_):V.add(_),V})},[]),S=l.useCallback(()=>{C(new Set(s.map(_=>_.id)))},[s]),k=l.useCallback(()=>{C(new Set)},[]),K=l.useCallback(()=>{y?k():S()},[y,S,k]),G=l.useCallback(()=>{m&&D.size>0&&(m(Array.from(D)),C(new Set))},[m,D]),T=l.useCallback(()=>{o&&D.size>0&&(o(Array.from(D)),C(new Set))},[o,D]);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:[h&&s.length>0&&e.jsx(Ce,{checked:y,onCheckedChange:K,"aria-label":"Select all accounts",className:A?"data-[state=checked]:bg-primary/50":"",...A?{"data-state":"indeterminate"}:{}}),e.jsx(fe,{className:"w-4 h-4"}),"Accounts",s.length>0&&e.jsx(H,{variant:"secondary",className:"text-xs",children:s.length})]}),e.jsxs(R,{variant:"default",size:"sm",className:"h-7 text-xs gap-1",onClick:a,children:[e.jsx(Is,{className:"w-3 h-3"}),"Add"]})]}),h&&F>0&&e.jsx(Ta,{selectedCount:F,onPauseSelected:G,onResumeSelected:T,onClearSelection:k,isPausing:!!u,isResuming:!!r}),s.length>0?e.jsx("div",{className:"space-y-2",children:s.map(_=>e.jsx(Ma,{account:_,onSetDefault:()=>t(_.id),onRemove:()=>n(_.id),onPauseToggle:i?U=>i(_.id,U):void 0,onSoloMode:c?()=>c(_.id):void 0,isRemoving:p,isPausingAccount:f,isSoloingAccount:N,privacyMode:b,showQuota:j,selectable:h,selected:D.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(fe,{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"})]}),x&&g&&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(Ls,{className:"w-3.5 h-3.5"}),e.jsx("span",{children:"Use incognito"})]}),e.jsx(Hs,{checked:!M,onCheckedChange:_=>g(!_),disabled:v,className:"scale-90"})]})})]})}function Ea({provider:s,catalog:a,savedPresets:t,currentModel:n,opusModel:i,sonnetModel:c,haikuModel:m,providerModels:o,extendedContextEnabled:p,onExtendedContextToggle:f,onApplyPreset:N,onUpdateEnvValue:u,onOpenCustomPreset:r,onDeletePreset:b,isDeletePending:j,accounts:x,onAddAccount:M,onSetDefault:g,onRemoveAccount:v,onPauseToggle:E,onSoloMode:C,onBulkPause:I,onBulkResume:D,isRemovingAccount:h,isPausingAccount:F,isSoloingAccount:y,isBulkPausing:A,isBulkResuming:w,privacyMode:S,isRemoteMode:k}){const K=s.toLowerCase(),G=(Nt.includes(K)||["anthropic","antigravity","gemini-cli","copilot","github-copilot"].includes(K))&&!k,T=s==="kiro",[_,U]=l.useState(!0),[V,se]=l.useState(!0),[z,X]=l.useState(!1),te=l.useCallback(async()=>{if(T)try{se(!0);const $=(await be.config.get()).cliproxy;U($?.kiro_no_incognito??!0)}catch{U(!0)}finally{se(!1)}},[T]),d=l.useCallback(async O=>{U(O),X(!0);try{const $=await be.config.get(),de=$.cliproxy??{};await be.config.update({...$,cliproxy:{...de,kiro_no_incognito:O}})}catch{U(!O)}finally{X(!1)}},[]);return l.useEffect(()=>{te()},[te]),e.jsx(Xe,{className:"flex-1",children:e.jsxs("div",{className:"p-4 space-y-6",children:[e.jsx(Pa,{catalog:a,savedPresets:t,currentModel:n,opusModel:i,sonnetModel:c,haikuModel:m,providerModels:o,provider:s,extendedContextEnabled:p,onExtendedContextToggle:f,onApplyPreset:N,onUpdateEnvValue:u,onOpenCustomPreset:r,onDeletePreset:b,isDeletePending:j}),e.jsx(ts,{}),e.jsx(Oa,{accounts:x,onAddAccount:M,onSetDefault:g,onRemoveAccount:v,onPauseToggle:E,onSoloMode:C,onBulkPause:I,onBulkResume:D,isRemovingAccount:h,isPausingAccount:F,isSoloingAccount:y,isBulkPausing:A,isBulkResuming:w,privacyMode:S,showQuota:G,isKiro:T,kiroNoIncognito:_,onKiroNoIncognitoChange:d,kiroSettingsLoading:V||z})]})})}function ws({provider:s,displayName:a,authStatus:t,catalog:n,logoProvider:i,baseProvider:c,isRemoteMode:m,port:o,defaultTarget:p,onAddAccount:f,onSetDefault:N,onRemoveAccount:u,onPauseToggle:r,onSoloMode:b,onBulkPause:j,onBulkResume:x,isRemovingAccount:M,isPausingAccount:g,isSoloingAccount:v,isBulkPausing:E,isBulkResuming:C}){const[I,D]=l.useState(!1),{privacyMode:h}=Ss(),{data:F}=yt(),{data:y}=wt(s),A=bt(),w=kt(),S=c||s,k=S.toLowerCase()==="agy",K=l.useMemo(()=>{const L=y?.presets||[];return k?L.filter(Q=>!Z(Q.default)&&!Z(Q.opus)&&!Z(Q.sonnet)&&!Z(Q.haiku)):L},[k,y?.presets]),G=l.useMemo(()=>{if(!F?.models)return[];const Q={gemini:["google"],agy:["antigravity"],codex:["openai"],qwen:["alibaba","qwen"],iflow:["iflow"],kiro:["kiro","aws"],ghcp:["github","copilot"],kimi:["kimi","moonshot"]}[S.toLowerCase()]||[S.toLowerCase()];return F.models.filter(re=>Q.some(Oe=>re.owned_by.toLowerCase().includes(Oe))?k?!Z(re.id):!0:!1)},[k,F,S]),T=(c||s).toLowerCase(),{data:_,isLoading:U,refetch:V,rawJsonContent:se,rawJsonEdits:z,isRawJsonValid:X,hasChanges:te,currentModel:d,opusModel:O,sonnetModel:$,haikuModel:de,extendedContextEnabled:Pe,toggleExtendedContext:De,handleRawJsonChange:Me,updateEnvValue:Te,updateEnvValues:J,saveMutation:P,conflictDialog:ie,handleConflictResolve:ae,missingRequiredFields:rs}=Na(s),we=l.useMemo(()=>(t.accounts||[]).map(L=>({...L,provider:L.provider||c||s})),[t.accounts,c,s]),{data:Bs}=bs({queryKey:["auth-tokens-raw"],queryFn:async()=>{const L=await fetch("/api/settings/auth/tokens/raw");return L.ok?L.json():{apiKey:{value:"ccs-internal-managed"}}},staleTime:6e4}),os=Bs?.apiKey?.value??"ccs-internal-managed",Gs=L=>{if(k&&[L.ANTHROPIC_MODEL,L.ANTHROPIC_DEFAULT_OPUS_MODEL,L.ANTHROPIC_DEFAULT_SONNET_MODEL,L.ANTHROPIC_DEFAULT_HAIKU_MODEL].some(re=>typeof re=="string"&&Z(re))){q.error("Antigravity denylist: Claude Opus 4.5 and Claude Sonnet 4.5 are deprecated.");return}J({ANTHROPIC_BASE_URL:`http://127.0.0.1:${o??Ue}/api/provider/${T}`,ANTHROPIC_AUTH_TOKEN:os,...L}),q.success(`Applied "${L.ANTHROPIC_MODEL?.split("/").pop()||"preset"}" preset`)},$s=(L,Q)=>{if(k&&[L.default,L.opus,L.sonnet,L.haiku].some(Oe=>Z(Oe))){q.error("Antigravity denylist: Claude Opus 4.5 and Claude Sonnet 4.5 are deprecated.");return}J({ANTHROPIC_BASE_URL:`http://127.0.0.1:${o??Ue}/api/provider/${T}`,ANTHROPIC_AUTH_TOKEN:os,ANTHROPIC_MODEL:L.default,ANTHROPIC_DEFAULT_OPUS_MODEL:L.opus,ANTHROPIC_DEFAULT_SONNET_MODEL:L.sonnet,ANTHROPIC_DEFAULT_HAIKU_MODEL:L.haiku}),q.success(`Applied ${Q?`"${Q}"`:"custom"} preset`),D(!1)},Qs=(L,Q)=>{if(!Q){q.error(Ds.t("commonToast.enterPresetName"));return}if(k&&[L.default,L.opus,L.sonnet,L.haiku].some(re=>Z(re))){q.error("Antigravity denylist: Claude Opus 4.5 and Claude Sonnet 4.5 are deprecated.");return}A.mutate({profile:s,data:{name:Q,...L}}),D(!1)};return e.jsxs("div",{className:"flex-1 flex flex-col overflow-hidden",children:[e.jsx(Aa,{provider:s,displayName:a,logoProvider:i,data:_,isLoading:U,hasChanges:te,isRawJsonValid:X,isSaving:P.isPending,isRemoteMode:m,port:o,onRefetch:V,onSave:()=>P.mutate()}),U?e.jsxs("div",{className:"flex-1 flex items-center justify-center",children:[e.jsx(W,{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(Ct,{defaultValue:"config",className:"h-full flex flex-col",children:[e.jsx("div",{className:"px-4 pt-4 shrink-0",children:e.jsxs(At,{className:"w-full",children:[e.jsx(xs,{value:"config",className:"flex-1",children:"Model Config"}),e.jsx(xs,{value:"info",className:"flex-1",children:"Info & Usage"})]})}),e.jsxs("div",{className:"flex-1 overflow-hidden flex flex-col",children:[e.jsx(ps,{value:"config",className:"flex-1 mt-0 border-0 p-0 data-[state=inactive]:hidden flex flex-col overflow-hidden",children:e.jsx(Ea,{provider:s,catalog:n,savedPresets:K,currentModel:d,opusModel:O,sonnetModel:$,haikuModel:de,providerModels:G,extendedContextEnabled:Pe,onExtendedContextToggle:De,onApplyPreset:Gs,onUpdateEnvValue:Te,onOpenCustomPreset:()=>D(!0),onDeletePreset:L=>w.mutate({profile:s,name:L}),isDeletePending:w.isPending,accounts:we,onAddAccount:f,onSetDefault:N,onRemoveAccount:u,onPauseToggle:r,onSoloMode:b,onBulkPause:j,onBulkResume:x,isRemovingAccount:M,isPausingAccount:g,isSoloingAccount:v,isBulkPausing:E,isBulkResuming:C,privacyMode:h,isRemoteMode:m})}),e.jsx(ps,{value:"info",className:"h-full mt-0 border-0 p-0 data-[state=inactive]:hidden",children:e.jsx(ka,{provider:s,displayName:a,defaultTarget:p,data:_,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(Xt,{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(St,{rawJsonContent:se,isRawJsonValid:X,rawJsonEdits:z,onRawJsonChange:Me,profileEnv:_?.settings?.env,missingRequiredFields:rs})]})]}),e.jsx(sa,{open:ie,title:"File Modified Externally",description:"This settings file was modified by another process. Overwrite with your changes or discard?",confirmText:"Overwrite",variant:"destructive",onConfirm:()=>ae(!0),onCancel:()=>ae(!1)}),e.jsx(ba,{open:I,onClose:()=>D(!1),currentValues:{default:d||"",opus:O||"",sonnet:$||"",haiku:de||""},onApply:$s,onSave:Qs,isSaving:A.isPending,catalog:n,allModels:G})]})}function _a({status:s,isSelected:a,onSelect:t}){const{t:n}=ee(),i=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(is,{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}),i>0&&e.jsx(H,{variant:"secondary",className:"text-[10px] h-4 px-1",children:i})]}),e.jsx("div",{className:"flex items-center gap-1.5 mt-0.5",children:s.authenticated?e.jsxs(e.Fragment,{children:[e.jsx(ne,{className:"w-3 h-3 text-green-600"}),e.jsx("span",{className:"text-xs text-green-600",children:n("cliproxyPage.connected")})]}):e.jsxs(e.Fragment,{children:[e.jsx(ss,{className:"w-3 h-3 text-muted-foreground"}),e.jsx("span",{className:"text-xs text-muted-foreground",children:n("cliproxyPage.notConnected")})]})})]})]})}function Ra({variant:s,parentAuth:a,isSelected:t,onSelect:n,onDelete:i,isDeleting:c}){const{t:m}=ee();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:n,children:[e.jsxs("div",{className:"relative",children:[e.jsx(is,{provider:s.provider,size:"sm"}),e.jsx(qs,{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(H,{variant:"outline",className:"text-[9px] h-4 px-1",children:m("cliproxyPage.variant")}),e.jsx(H,{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(ne,{className:"w-3 h-3 text-green-600"}),e.jsx("span",{className:"text-xs text-muted-foreground truncate",children:m("cliproxyPage.viaProvider",{provider:s.provider})})]}):e.jsxs(e.Fragment,{children:[e.jsx(ss,{className:"w-3 h-3 text-muted-foreground"}),e.jsx("span",{className:"text-xs text-muted-foreground",children:m("cliproxyPage.parentNotConnected")})]})})]}),e.jsx(R,{variant:"ghost",size:"icon",className:"h-6 w-6 opacity-0 group-hover:opacity-100 hover:text-destructive",onClick:o=>{o.stopPropagation(),i()},disabled:c,children:e.jsx(Us,{className:"w-3 h-3"})})]})}function La({onSetup:s}){const{t:a}=ee();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(ye,{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(R,{onClick:s,className:"gap-2",children:[e.jsx(Ne,{className:"w-4 h-4"}),a("cliproxyPage.quickSetup")]})]})})}function Za(){const{t:s}=ee(),a=Ke(),{data:t,isLoading:n}=As(),{data:i,isFetching:c}=Pt(),{data:m}=Dt(),o=Mt(),p=Tt(),f=Ot(),N=Et(),u=_t(),r=Rt(),b=Lt(),j=It(),[x,M]=l.useState(()=>{if(typeof window<"u"){const O=new URLSearchParams(window.location.search).get("provider")?.trim().toLowerCase();return O&&Ie(O)?O:localStorage.getItem("cliproxy-selected-provider")}return null}),[g,v]=l.useState(null),[E,C]=l.useState(!1),[I,D]=l.useState(()=>{if(typeof window>"u")return null;const d=new URLSearchParams(window.location.search),O=d.get("provider")?.trim().toLowerCase();return d.get("action")!=="auth"||!O||!Ie(O)?null:{provider:O,displayName:Ft(O),isFirstAccount:!1}}),h=l.useMemo(()=>t?.authStatus||[],[t?.authStatus]),F=t?.source==="remote",y=l.useMemo(()=>i?.variants||[],[i?.variants]),A=d=>{M(d),d&&localStorage.setItem("cliproxy-selected-provider",d)},w=l.useMemo(()=>g?null:x&&h.some(d=>d.provider===x)?x:h.length>0&&(h.find(O=>(O.accounts?.length||0)>0)?.provider||h[0]?.provider)||null,[x,g,h]),S=h.find(d=>d.provider===w),k=y.find(d=>d.name===g),K=k?h.find(d=>d.provider===k.provider):void 0,G=(k?.provider||S?.provider||"").toLowerCase().trim(),T=G==="gemini"||G==="agy",_=()=>{a.invalidateQueries({queryKey:["cliproxy"]}),a.invalidateQueries({queryKey:["cliproxy-auth"]})},U=(d,O,$)=>{f.isPending||N.isPending||($?f.mutate({provider:d,accountId:O}):N.mutate({provider:d,accountId:O}))},V=(d,O)=>{u.isPending||u.mutate({provider:d,accountId:O})},se=(d,O)=>{r.isPending||r.mutate({provider:d,accountIds:O})},z=(d,O)=>{b.isPending||b.mutate({provider:d,accountIds:O})},X=d=>{A(d),v(null)},te=d=>{v(d),A(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(ye,{className:"w-5 h-5 text-primary"}),e.jsx("h1",{className:"font-semibold",children:m?.backendLabel??"CLIProxy"})]}),e.jsx(R,{variant:"ghost",size:"icon",className:"h-8 w-8",onClick:_,disabled:c,children:e.jsx(Ze,{className:B("w-4 h-4",c&&"animate-spin")})})]}),e.jsx("p",{className:"text-xs text-muted-foreground mb-3",children:s("cliproxyPage.accountManagement")}),e.jsxs(R,{variant:"default",size:"sm",className:"w-full gap-2",onClick:()=>C(!0),children:[e.jsx(Ne,{className:"w-4 h-4"}),s("cliproxyPage.quickSetup")]})]}),e.jsx(Xe,{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")}),n?e.jsx("div",{className:"space-y-2 px-2",children:[1,2,3,4].map(d=>e.jsx(Ut,{className:"h-14 w-full rounded-lg"},d))}):e.jsx("div",{className:"space-y-1",children:h.map(d=>e.jsx(_a,{status:d,isSelected:w===d.provider,onSelect:()=>X(d.provider)},d.provider))}),y.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(qs,{className:"w-3 h-3"}),s("cliproxyPage.variants")]}),e.jsx("div",{className:"space-y-1",children:y.map(d=>e.jsx(Ra,{variant:d,parentAuth:h.find(O=>O.provider===d.provider),isSelected:g===d.name,onSelect:()=>te(d.name),onDelete:()=>j.mutate(d.name),isDeleting:j.isPending},d.name))})]})]})}),e.jsx("div",{className:"p-3 border-t",children:e.jsx(ea,{})}),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:h.length})}),e.jsxs("span",{className:"flex items-center gap-1",children:[e.jsx(ne,{className:"w-3 h-3 text-green-600"}),s("cliproxyPage.connectedCount",{count:h.filter(d=>d.authenticated).length})]})]})})]}),e.jsxs("div",{className:"flex-1 flex flex-col min-w-0 bg-background",children:[T&&e.jsx(Ks,{showProxySettingsLink:!0,className:"mx-4 mt-4"}),k&&K?e.jsx(ws,{provider:k.name,displayName:s("cliproxyPage.variantDisplay",{name:k.name,provider:k.provider}),authStatus:K,catalog:ve[k.provider],logoProvider:k.provider,baseProvider:k.provider,defaultTarget:k.target,isRemoteMode:F,port:k.port,onAddAccount:()=>D({provider:k.provider,displayName:K.displayName,isFirstAccount:(K.accounts?.length||0)===0}),onSetDefault:d=>o.mutate({provider:k.provider,accountId:d}),onRemoveAccount:d=>p.mutate({provider:k.provider,accountId:d}),onPauseToggle:(d,O)=>U(k.provider,d,O),onSoloMode:d=>V(k.provider,d),onBulkPause:d=>se(k.provider,d),onBulkResume:d=>z(k.provider,d),isRemovingAccount:p.isPending,isPausingAccount:f.isPending||N.isPending,isSoloingAccount:u.isPending,isBulkPausing:r.isPending,isBulkResuming:b.isPending}):S?e.jsx(ws,{provider:S.provider,displayName:S.displayName,authStatus:S,catalog:ve[S.provider],isRemoteMode:F,onAddAccount:()=>D({provider:S.provider,displayName:S.displayName,isFirstAccount:(S.accounts?.length||0)===0}),onSetDefault:d=>o.mutate({provider:S.provider,accountId:d}),onRemoveAccount:d=>p.mutate({provider:S.provider,accountId:d}),onPauseToggle:(d,O)=>U(S.provider,d,O),onSoloMode:d=>V(S.provider,d),onBulkPause:d=>se(S.provider,d),onBulkResume:d=>z(S.provider,d),isRemovingAccount:p.isPending,isPausingAccount:f.isPending||N.isPending,isSoloingAccount:u.isPending,isBulkPausing:r.isPending,isBulkResuming:b.isPending}):e.jsx(La,{onSetup:()=>C(!0)})]}),e.jsx(ca,{open:E,onClose:()=>C(!1)}),e.jsx(ha,{open:I!==null,onClose:()=>D(null),provider:I?.provider||"",displayName:I?.displayName||"",isFirstAccount:I?.isFirstAccount||!1})]})}export{Za as CliproxyPage};
|
|
@@ -1 +0,0 @@
|
|
|
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,aY as M}from"./index-CmZS09IA.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 as Y}from"./icons-BYZM_9Gm.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(Y,{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 +0,0 @@
|
|
|
1
|
-
import{j as e}from"./radix-ui-BR1vy4kf.js";import{r as m}from"./react-vendor-CNOkPC89.js";import{be as C,bf as w,a as G,bg as y,b7 as S,b9 as k,n as R,d as x,I as j}from"./index-CmZS09IA.js";import{S as A}from"./switch-CTrO47Q-.js";import{R as N,a3 as D,u as L,ah as T,a1 as I}from"./icons-BYZM_9Gm.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";function _(){const{state:s}=C(),n=w(),[o,r]=m.useState(""),[c,g]=m.useState(""),u=m.useCallback(async()=>{try{n.setGlobalEnvLoading(!0),n.setGlobalEnvError(null);const a=await fetch("/api/global-env");if(!a.ok)throw new Error("Failed to load Global Env config");const l=await a.json();n.setGlobalEnvConfig(l)}catch(a){n.setGlobalEnvError(a.message)}finally{n.setGlobalEnvLoading(!1)}},[n]),i=m.useCallback(async a=>{const l=s.globalEnvConfig;if(!l)return;const f={...l,...a};n.setGlobalEnvConfig(f);try{n.setGlobalEnvSaving(!0),n.setGlobalEnvError(null);const d=await fetch("/api/global-env",{method:"PUT",headers:{"Content-Type":"application/json"},body:JSON.stringify(f)});if(!d.ok){const E=await d.json();throw new Error(E.error||"Failed to save")}const v=await d.json();n.setGlobalEnvConfig(v.config),n.setGlobalEnvSuccess(!0),setTimeout(()=>n.setGlobalEnvSuccess(!1),1500)}catch(d){n.setGlobalEnvConfig(l),n.setGlobalEnvError(d.message)}finally{n.setGlobalEnvSaving(!1)}},[s.globalEnvConfig,n]),h=m.useCallback(()=>{if(!o.trim()||!s.globalEnvConfig)return;const a={...s.globalEnvConfig.env,[o.trim()]:c};i({env:a}),r(""),g("")},[o,c,s.globalEnvConfig,i]),b=m.useCallback(a=>{if(!s.globalEnvConfig)return;const l={...s.globalEnvConfig.env};delete l[a],i({env:l})},[s.globalEnvConfig,i]);return{config:s.globalEnvConfig,loading:s.globalEnvLoading,saving:s.globalEnvSaving,error:s.globalEnvError,success:s.globalEnvSuccess,newEnvKey:o,setNewEnvKey:r,newEnvValue:c,setNewEnvValue:g,fetchConfig:u,saveConfig:i,addEnvVar:h,removeEnvVar:b}}function $(){const{t:s}=G(),{config:n,loading:o,saving:r,error:c,success:g,newEnvKey:u,setNewEnvKey:i,newEnvValue:h,setNewEnvValue:b,fetchConfig:a,saveConfig:l,addEnvVar:f,removeEnvVar:d}=_(),{fetchRawConfig:v}=y();m.useEffect(()=>{a(),v()},[a,v]);const E=()=>{l({enabled:!n?.enabled})};return o?e.jsx("div",{className:"flex-1 flex items-center justify-center",children:e.jsxs("div",{className:"flex items-center gap-3 text-muted-foreground",children:[e.jsx(N,{className:"w-5 h-5 animate-spin"}),e.jsx("span",{children:s("settings.loading")})]})}):e.jsxs(e.Fragment,{children:[e.jsxs("div",{className:`absolute left-5 right-5 top-20 z-10 transition-all duration-200 ease-out ${c||g?"opacity-100 translate-y-0":"opacity-0 -translate-y-2 pointer-events-none"}`,children:[c&&e.jsxs(S,{variant:"destructive",className:"py-2 shadow-lg",children:[e.jsx(D,{className:"h-4 w-4"}),e.jsx(k,{children:c})]}),g&&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(L,{className:"h-4 w-4 shrink-0"}),e.jsx("span",{className:"text-sm font-medium",children:s("settings.saved")})]})]}),e.jsx(R,{className:"flex-1",children:e.jsxs("div",{className:"p-5 space-y-6",children:[e.jsx("p",{className:"text-sm text-muted-foreground",children:s("settingsGlobalEnv.description")}),e.jsxs("div",{className:"flex items-center justify-between p-4 rounded-lg bg-muted/50",children:[e.jsxs("div",{children:[e.jsx("p",{className:"font-medium",children:n?.enabled?s("settingsGlobalEnv.enabled"):s("settingsGlobalEnv.disabled")}),e.jsx("p",{className:"text-sm text-muted-foreground",children:n?.enabled?s("settingsGlobalEnv.enabledDesc"):s("settingsGlobalEnv.disabledDesc")})]}),e.jsx(A,{checked:n?.enabled??!0,onCheckedChange:E})]}),e.jsxs("div",{className:"space-y-3",children:[e.jsx("h3",{className:"text-base font-medium",children:s("settingsGlobalEnv.envVars")}),n?.env&&Object.keys(n.env).length>0?e.jsx("div",{className:"space-y-2",children:Object.entries(n.env).map(([t,p])=>e.jsxs("div",{className:"flex items-center gap-2 p-3 rounded-lg border bg-background",children:[e.jsx("code",{className:"flex-1 font-mono text-sm truncate",children:t}),e.jsx("span",{className:"text-muted-foreground",children:"="}),e.jsx("code",{className:"font-mono text-sm px-2 py-1 bg-muted rounded",children:p}),e.jsx(x,{variant:"ghost",size:"sm",onClick:()=>d(t),disabled:r,className:"h-8 w-8 p-0 text-destructive hover:text-destructive hover:bg-destructive/10",children:e.jsx(T,{className:"w-4 h-4"})})]},t))}):e.jsx("div",{className:"p-4 rounded-lg border border-dashed text-center text-muted-foreground",children:e.jsx("p",{children:s("settingsGlobalEnv.noneConfigured")})}),e.jsxs("div",{className:"p-4 rounded-lg border bg-muted/30",children:[e.jsx("h4",{className:"text-sm font-medium mb-3",children:s("settingsGlobalEnv.addNew")}),e.jsxs("div",{className:"flex gap-2",children:[e.jsx(j,{value:u,onChange:t=>i(t.target.value.toUpperCase()),placeholder:s("settingsGlobalEnv.keyName"),className:"flex-1 font-mono text-sm h-9",disabled:r}),e.jsx("span",{className:"flex items-center text-muted-foreground",children:"="}),e.jsx(j,{value:h,onChange:t=>b(t.target.value),placeholder:s("settingsGlobalEnv.value"),className:"flex-1 font-mono text-sm h-9",disabled:r}),e.jsxs(x,{size:"sm",onClick:f,disabled:r||!u.trim(),className:"h-9",children:[e.jsx(I,{className:"w-4 h-4 mr-1"}),s("settingsGlobalEnv.add")]})]})]}),e.jsxs("div",{className:"p-4 rounded-lg border bg-muted/30",children:[e.jsx("h4",{className:"text-sm font-medium mb-3",children:s("settingsGlobalEnv.quickAdd")}),e.jsxs("div",{className:"flex flex-wrap gap-2",children:[[{key:"DISABLE_BUG_COMMAND",value:"1"},{key:"DISABLE_ERROR_REPORTING",value:"1"},{key:"DISABLE_TELEMETRY",value:"1"}].map(({key:t,value:p})=>!n?.env?.[t]&&e.jsxs(x,{variant:"outline",size:"sm",onClick:()=>{i(t),b(p)},className:"text-xs font-mono",children:["+ ",t]},t)),n?.env&&["DISABLE_BUG_COMMAND","DISABLE_ERROR_REPORTING","DISABLE_TELEMETRY"].every(t=>n.env[t])&&e.jsx("span",{className:"text-sm text-muted-foreground",children:s("settingsGlobalEnv.allConfigured")})]})]})]})]})}),e.jsx("div",{className:"p-4 border-t bg-background",children:e.jsxs(x,{variant:"outline",size:"sm",onClick:()=>{a(),v()},disabled:o||r,className:"w-full",children:[e.jsx(N,{className:`w-4 h-4 mr-2 ${o?"animate-spin":""}`}),s("settings.refresh")]})})]})}export{$ as default};
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
import{j as e}from"./radix-ui-BR1vy4kf.js";import{r as c}from"./react-vendor-CNOkPC89.js";import{be as F,bf as U,a as R,I as K,bg as _,b7 as z,b9 as B,n as q,d as T}from"./index-CmZS09IA.js";import{S as D}from"./switch-CTrO47Q-.js";import{N as Y,k as J,r as X,q as Z,n as Q,R as y,a3 as V,u as ee,aR as se}from"./icons-BYZM_9Gm.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";function te(){const{state:s}=F(),t=U(),[o,g]=c.useState(""),[r,d]=c.useState(""),[x,p]=c.useState(!1),[j,f]=c.useState(!1),S=c.useCallback(async()=>{try{t.setWebSearchLoading(!0),t.setWebSearchError(null);const a=await fetch("/api/websearch");if(!a.ok)throw new Error("Failed to load WebSearch config");const n=await a.json();t.setWebSearchConfig(n)}catch(a){t.setWebSearchError(a.message)}finally{t.setWebSearchLoading(!1)}},[t]),v=c.useCallback(async()=>{try{t.setWebSearchStatusLoading(!0);const a=await fetch("/api/websearch/status");if(!a.ok)throw new Error("Failed to load status");const n=await a.json();t.setWebSearchStatus(n)}catch{}finally{t.setWebSearchStatusLoading(!1)}},[t]),b=c.useCallback(async a=>{const n=s.webSearchConfig;if(!n)return;const w={...n,...a};t.setWebSearchConfig(w);try{t.setWebSearchSaving(!0),t.setWebSearchError(null);const l=await fetch("/api/websearch",{method:"PUT",headers:{"Content-Type":"application/json"},body:JSON.stringify(w)});if(!l.ok){const k=await l.json();throw new Error(k.error||"Failed to save")}const i=await l.json();t.setWebSearchConfig(i.websearch),t.setWebSearchSuccess(!0),setTimeout(()=>t.setWebSearchSuccess(!1),1500)}catch(l){t.setWebSearchConfig(n),t.setWebSearchError(l.message)}finally{t.setWebSearchSaving(!1)}},[s.webSearchConfig,t]);c.useEffect(()=>{s.webSearchConfig&&(g(s.webSearchConfig.providers?.gemini?.model??"gemini-2.5-flash"),d(s.webSearchConfig.providers?.opencode?.model??"opencode/grok-code"))},[s.webSearchConfig]);const C=c.useCallback(async()=>{const a=s.webSearchConfig?.providers?.gemini?.model??"gemini-2.5-flash";if(o!==a){const n=s.webSearchConfig?.providers||{};await b({providers:{...n,gemini:{...n.gemini,model:o}}}),p(!0),setTimeout(()=>p(!1),2e3)}},[o,s.webSearchConfig,b]),h=c.useCallback(async()=>{const a=s.webSearchConfig?.providers?.opencode?.model??"opencode/grok-code";if(r!==a){const n=s.webSearchConfig?.providers||{};await b({providers:{...n,opencode:{...n.opencode,model:r}}}),f(!0),setTimeout(()=>f(!1),2e3)}},[r,s.webSearchConfig,b]);return{config:s.webSearchConfig,status:s.webSearchStatus,loading:s.webSearchLoading,statusLoading:s.webSearchStatusLoading,saving:s.webSearchSaving,error:s.webSearchError,success:s.webSearchSuccess,geminiModelInput:o,setGeminiModelInput:g,opencodeModelInput:r,setOpencodeModelInput:d,geminiModelSaved:x,opencodeModelSaved:j,fetchConfig:S,fetchStatus:v,saveConfig:b,saveGeminiModel:C,saveOpencodeModel:h}}function H({name:s,label:t,badge:o,badgeColor:g,enabled:r,installed:d,statusLoading:x,saving:p,onToggle:j,modelInput:f,setModelInput:S,onModelBlur:v,modelSaved:b,modelPlaceholder:C,showHint:h,setShowHint:a,installCmd:n,docsUrl:w,hintColor:l}){const{t:i}=R(),k=g==="green"?"bg-green-500/10 text-green-600":g==="blue"?"bg-blue-500/10 text-blue-600":"bg-purple-500/10 text-purple-600",W=l==="amber"?"bg-amber-50 dark:bg-amber-900/20 text-amber-700 dark:text-amber-300":l==="blue"?"bg-blue-50 dark:bg-blue-900/20 text-blue-700 dark:text-blue-300":"bg-purple-50 dark:bg-purple-900/20 text-purple-700 dark:text-purple-300",E=l==="amber"?"bg-amber-100 dark:bg-amber-900/40":l==="blue"?"bg-blue-100 dark:bg-blue-900/40":"bg-purple-100 dark:bg-purple-900/40",M=l==="amber"?"text-amber-600 dark:text-amber-400":l==="blue"?"text-blue-600 dark:text-blue-400":"text-purple-600 dark:text-purple-400",G=s==="opencode"?"OpenCode":s.charAt(0).toUpperCase()+s.slice(1);return e.jsxs("div",{className:`rounded-lg border transition-colors ${r?"border-primary border-l-4":"border-border"}`,children:[e.jsxs("div",{className:"flex items-center justify-between p-4",children:[e.jsxs("div",{className:"flex items-center gap-3",children:[e.jsx(Y,{className:`w-5 h-5 ${r?"text-primary":"text-muted-foreground"}`}),e.jsxs("div",{children:[e.jsxs("div",{className:"flex items-center gap-2",children:[e.jsx("p",{className:"font-mono font-medium",children:s}),e.jsx("span",{className:`text-xs px-1.5 py-0.5 rounded font-medium ${k}`,children:o}),d?e.jsx("span",{className:"text-xs px-1.5 py-0.5 rounded bg-green-500/10 text-green-600 font-medium",children:i("settingsWebsearch.installed")}):e.jsx("span",{className:"text-xs px-1.5 py-0.5 rounded bg-amber-500/10 text-amber-600 font-medium",children:i("settingsWebsearch.notInstalled")})]}),e.jsx("p",{className:"text-sm text-muted-foreground",children:t})]})]}),e.jsx(D,{checked:r,onCheckedChange:j,disabled:p||!d})]}),r&&f!==void 0&&S&&v&&e.jsx("div",{className:"px-4 pb-4 pt-0",children:e.jsxs("div",{className:"flex items-center gap-2",children:[e.jsx("label",{className:"text-sm text-muted-foreground whitespace-nowrap",children:i("settingsWebsearch.model")}),e.jsx(K,{value:f,onChange:I=>S(I.target.value),onBlur:v,placeholder:C,className:"h-8 text-sm font-mono",disabled:p}),b&&e.jsxs("span",{className:"flex items-center gap-1 text-green-600 dark:text-green-400 text-xs animate-in fade-in duration-200",children:[e.jsx(J,{className:"w-3.5 h-3.5"}),i("settings.saved")]})]})}),!d&&!x&&e.jsxs("div",{className:"px-4 pb-4 pt-0 border-t border-border/50",children:[e.jsxs("button",{onClick:()=>a(!h),className:`flex items-center gap-2 text-sm hover:underline w-full py-2 ${M}`,children:[h?e.jsx(X,{className:"w-4 h-4"}):e.jsx(Z,{className:"w-4 h-4"}),i("settingsWebsearch.howInstall",{name:G})]}),h&&e.jsxs("div",{className:`mt-2 p-3 rounded-md text-sm ${W}`,children:[e.jsxs("p",{className:"mb-2",children:[i("settingsWebsearch.installGlobally")," ",i(o==="GROK_API_KEY"?"settingsWebsearch.requiresKey":"settingsWebsearch.freeTier"),":"]}),e.jsx("code",{className:`text-sm px-2 py-1 rounded font-mono block mb-2 ${E}`,children:n}),e.jsxs("a",{href:w,target:"_blank",rel:"noopener noreferrer",className:"hover:underline inline-flex items-center gap-1",children:[e.jsx(Q,{className:"w-3 h-3"}),i("settingsWebsearch.viewDocs")]})]})]})]})}function be(){const{t:s}=R(),{config:t,status:o,loading:g,statusLoading:r,saving:d,error:x,success:p,geminiModelInput:j,setGeminiModelInput:f,opencodeModelInput:S,setOpencodeModelInput:v,geminiModelSaved:b,opencodeModelSaved:C,fetchConfig:h,fetchStatus:a,saveConfig:n,saveGeminiModel:w,saveOpencodeModel:l}=te(),{fetchRawConfig:i}=_(),[k,W]=c.useState(!1),[E,M]=c.useState(!1),[G,I]=c.useState(!1);c.useEffect(()=>{h(),a(),i()},[h,a,i]);const N=t?.providers?.gemini?.enabled??!1,O=t?.providers?.grok?.enabled??!1,L=t?.providers?.opencode?.enabled??!1,A=()=>{const m=t?.providers||{},u=m.gemini?.enabled??!1;n({enabled:!u||O||L,providers:{...m,gemini:{...m.gemini,enabled:!u}}})},$=()=>{const m=t?.providers||{},u=m.grok?.enabled??!1;n({enabled:N||!u||L,providers:{...m,grok:{...m.grok,enabled:!u}}})},P=()=>{const m=t?.providers||{},u=m.opencode?.enabled??!1;n({enabled:N||O||!u,providers:{...m,opencode:{...m.opencode,enabled:!u}}})};return g?e.jsx("div",{className:"flex-1 flex items-center justify-center",children:e.jsxs("div",{className:"flex items-center gap-3 text-muted-foreground",children:[e.jsx(y,{className:"w-5 h-5 animate-spin"}),e.jsx("span",{children:s("settings.loading")})]})}):e.jsxs(e.Fragment,{children:[e.jsxs("div",{className:`absolute left-5 right-5 top-20 z-10 transition-all duration-200 ease-out ${x||p?"opacity-100 translate-y-0":"opacity-0 -translate-y-2 pointer-events-none"}`,children:[x&&e.jsxs(z,{variant:"destructive",className:"py-2 shadow-lg",children:[e.jsx(V,{className:"h-4 w-4"}),e.jsx(B,{children:x})]}),p&&e.jsxs("div",{className:"flex items-center gap-2 px-3 py-2 rounded-md border border-green-200 bg-green-50 text-green-700 shadow-lg dark:border-green-900/50 dark:bg-green-900/90 dark:text-green-300",children:[e.jsx(ee,{className:"h-4 w-4 shrink-0"}),e.jsx("span",{className:"text-sm font-medium",children:s("settings.saved")})]})]}),e.jsx(q,{className:"flex-1",children:e.jsxs("div",{className:"p-5 space-y-6",children:[e.jsx("p",{className:"text-sm text-muted-foreground",children:s("settingsWebsearch.description")}),e.jsxs("div",{className:"flex items-center justify-between p-4 rounded-lg bg-muted/50",children:[e.jsxs("div",{children:[e.jsx("p",{className:"font-medium",children:s(N?"settingsWebsearch.enabled":"settingsWebsearch.disabled")}),r?e.jsx("p",{className:"text-sm text-muted-foreground",children:s("settingsWebsearch.checking")}):o?.readiness?e.jsx("p",{className:"text-sm text-muted-foreground",children:o.readiness.message}):null]}),e.jsx(T,{variant:"ghost",size:"sm",onClick:a,disabled:r,children:e.jsx(y,{className:`w-4 h-4 ${r?"animate-spin":""}`})})]}),e.jsxs("div",{className:"space-y-3",children:[e.jsx("h3",{className:"text-base font-medium",children:s("settingsWebsearch.providers")}),!o?.geminiCli&&!o?.opencodeCli&&!o?.grokCli&&!r&&e.jsxs("div",{className:"flex flex-col items-center justify-center p-8 border-2 border-dashed rounded-lg text-center bg-muted/30",children:[e.jsx(se,{className:"w-12 h-12 text-muted-foreground mb-3 opacity-30"}),e.jsx("p",{className:"font-medium text-foreground mb-1",children:s("settingsWebsearch.noneConfigured")}),e.jsx("p",{className:"text-sm text-muted-foreground mb-4",children:s("settingsWebsearch.noneConfiguredHint")}),e.jsxs(T,{variant:"outline",size:"sm",onClick:a,children:[e.jsx(y,{className:"w-4 h-4 mr-2"}),s("settingsWebsearch.checkProviders")]})]}),e.jsx(H,{name:"gemini",label:"Google Gemini CLI (1000 req/day free)",badge:"FREE",badgeColor:"green",enabled:N,installed:o?.geminiCli?.installed??!1,statusLoading:r,saving:d,onToggle:A,modelInput:j,setModelInput:f,onModelBlur:w,modelSaved:b,modelPlaceholder:"gemini-2.5-flash",showHint:k,setShowHint:W,installCmd:"npm install -g @google/gemini-cli",docsUrl:"https://github.com/google-gemini/gemini-cli",hintColor:"amber"}),e.jsx(H,{name:"opencode",label:"OpenCode (web search via Zen)",badge:"FREE",badgeColor:"green",enabled:L,installed:o?.opencodeCli?.installed??!1,statusLoading:r,saving:d,onToggle:P,modelInput:S,setModelInput:v,onModelBlur:l,modelSaved:C,modelPlaceholder:"opencode/grok-code",showHint:E,setShowHint:M,installCmd:"curl -fsSL https://opencode.ai/install | bash",docsUrl:"https://github.com/sst/opencode",hintColor:"purple"}),e.jsx(H,{name:"grok",label:"xAI Grok CLI (web + X search)",badge:"GROK_API_KEY",badgeColor:"blue",enabled:O,installed:o?.grokCli?.installed??!1,statusLoading:r,saving:d,onToggle:$,showHint:G,setShowHint:I,installCmd:"npm install -g @vibe-kit/grok-cli",docsUrl:"https://github.com/superagent-ai/grok-cli",hintColor:"blue"})]})]})}),e.jsx("div",{className:"p-4 border-t bg-background",children:e.jsxs(T,{variant:"outline",size:"sm",onClick:()=>{h(),i()},disabled:g||d,className:"w-full",children:[e.jsx(y,{className:`w-4 h-4 mr-2 ${g?"animate-spin":""}`}),s("settings.refresh")]})})]})}export{be as default};
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
import{j as e}from"./radix-ui-BR1vy4kf.js";import{r as n}from"./react-vendor-CNOkPC89.js";import{be as Oe,bf as Ve,Y as L,a as ae,I as B,r as He,s as Ue,t as ze,v as We,w as ue,d as H,bg as Ye,bh as Ge,bi as qe,b7 as se,b9 as te,n as Je}from"./index-CmZS09IA.js";import{S as D}from"./switch-CTrO47Q-.js";import{C as U}from"./default-ports-1QQSffYX.js";import{aS as he,R as re,f as Xe,u as fe,W as Qe,a3 as Ze,aT as es,aU as ss,T as ye,aq as ts,n as rs,aV as as}from"./icons-BYZM_9Gm.js";import{R as V,P as os}from"./proxy-status-widget-exblPwy_.js";import{t as T}from"./notifications-B2HqRBj7.js";import"./tanstack-e99Cjjy2.js";import"./utils-CzKF5WmX.js";import"./form-utils-Cn_Uld6y.js";import"./code-highlight-BRUf_pqB.js";import"./alert-dialog-QYUhRzXK.js";function ns(){const{state:s}=Oe(),t=Ve(),[g,o]=n.useState(null),[u,b]=n.useState(null),[y,j]=n.useState(null),[p,C]=n.useState(null),[S,P]=n.useState(null),w=n.useCallback(async()=>{try{t.setProxyLoading(!0),t.setProxyError(null);const d=await L.cliproxyServer.get();t.setProxyConfig(d)}catch(d){t.setProxyError(d.message)}finally{t.setProxyLoading(!1)}},[t]),A=n.useCallback(async d=>{const x=s.proxyConfig;if(!x)return;const h={remote:{...x.remote,...d.remote},fallback:{...x.fallback,...d.fallback},local:{...x.local,...d.local}};t.setProxyConfig(h),t.setProxyTestResult(null);try{t.setProxySaving(!0),t.setProxyError(null);const a=await L.cliproxyServer.update(d);t.setProxyConfig(a),t.setProxySuccess(!0),setTimeout(()=>t.setProxySuccess(!1),1500)}catch(a){t.setProxyConfig(x),t.setProxyError(a.message)}finally{t.setProxySaving(!1)}},[s.proxyConfig,t]),E=n.useCallback(async d=>{const{host:x,port:h,protocol:a,authToken:c}=d;if(!x){t.setProxyError("Host is required");return}try{t.setProxyTesting(!0),t.setProxyError(null),t.setProxyTestResult(null);const k=h?parseInt(h,10):void 0,l=await L.cliproxyServer.test({host:x,port:k||void 0,protocol:a,authToken:c||void 0});t.setProxyTestResult(l)}catch(k){t.setProxyError(k.message)}finally{t.setProxyTesting(!1)}},[t]);return{config:s.proxyConfig,loading:s.proxyLoading,saving:s.proxySaving,error:s.proxyError,success:s.proxySuccess,testResult:s.proxyTestResult,testing:s.proxyTesting,editedHost:g,setEditedHost:o,editedPort:u,setEditedPort:b,editedAuthToken:y,setEditedAuthToken:j,editedManagementKey:p,setEditedManagementKey:C,editedLocalPort:S,setEditedLocalPort:P,fetchConfig:w,saveConfig:A,testConnection:E}}function is({config:s,saving:t,displayLocalPort:g,setEditedLocalPort:o,onSaveLocalPort:u,onSaveConfig:b}){const{t:y}=ae(),j=s.local;return e.jsxs("div",{className:"space-y-3",children:[e.jsx("h3",{className:"text-base font-medium",children:y("settingsProxy.localProxy")}),e.jsxs("div",{className:"space-y-3 p-4 rounded-lg border bg-muted/30",children:[e.jsxs("div",{className:"flex items-center gap-2",children:[e.jsx("label",{className:"text-sm text-muted-foreground",children:y("settingsProxy.port")}),e.jsx(B,{type:"text",inputMode:"numeric",value:g,onChange:p=>o(p.target.value.replace(/\D/g,"")),onBlur:u,placeholder:`${U}`,className:"font-mono max-w-32",disabled:t})]}),e.jsxs("div",{className:"flex items-center justify-between",children:[e.jsxs("div",{children:[e.jsx("p",{className:"font-medium text-sm",children:y("settingsProxy.autoStart")}),e.jsx("p",{className:"text-xs text-muted-foreground",children:y("settingsProxy.localAutoStartDesc")})]}),e.jsx(D,{checked:j.auto_start??!0,onCheckedChange:p=>b({local:{...j,auto_start:p}}),disabled:t})]})]})]})}function ls({config:s,saving:t,testing:g,testResult:o,displayHost:u,displayPort:b,displayAuthToken:y,displayManagementKey:j,setEditedHost:p,setEditedPort:C,setEditedAuthToken:S,setEditedManagementKey:P,onSaveHost:w,onSavePort:A,onSaveAuthToken:E,onSaveManagementKey:d,onSaveConfig:x,onTestConnection:h}){const{t:a}=ae(),c=s.remote,k=l=>l==="https"?443:U;return e.jsxs("div",{className:"space-y-4 p-4 rounded-lg border bg-muted/30",children:[e.jsxs("h4",{className:"text-sm font-medium flex items-center gap-2",children:[e.jsx(he,{className:"w-4 h-4"}),a("settingsProxy.remoteConfigTitle")]}),e.jsxs("div",{className:"space-y-1",children:[e.jsx("label",{className:"text-sm text-muted-foreground",children:a("settingsProxy.host")}),e.jsx(B,{value:u,onChange:l=>p(l.target.value),onBlur:w,placeholder:a("settingsProxy.hostPlaceholder"),className:"font-mono",disabled:t})]}),e.jsxs("div",{className:"grid grid-cols-2 gap-3",children:[e.jsxs("div",{className:"space-y-1",children:[e.jsxs("label",{className:"text-sm text-muted-foreground",children:[a("settingsProxy.port")," ",e.jsxs("span",{className:"text-xs opacity-70",children:["(",a("settingsProxy.defaultPort",{value:k(s.remote.protocol||"http")}),")"]})]}),e.jsx(B,{type:"text",inputMode:"numeric",value:b,onChange:l=>C(l.target.value.replace(/\D/g,"")),onBlur:A,placeholder:a("settingsProxy.portPlaceholder",{value:k(s.remote.protocol||"http")}),className:"font-mono",disabled:t})]}),e.jsxs("div",{className:"space-y-1",children:[e.jsx("label",{className:"text-sm text-muted-foreground",children:a("settingsProxy.protocol")}),e.jsxs(He,{value:s.remote.protocol||"http",onValueChange:l=>x({remote:{...c,protocol:l}}),disabled:t,children:[e.jsx(Ue,{children:e.jsx(ze,{})}),e.jsxs(We,{children:[e.jsx(ue,{value:"http",children:a("settingsProxy.http")}),e.jsx(ue,{value:"https",children:a("settingsProxy.https")})]})]})]})]}),e.jsxs("div",{className:"space-y-1",children:[e.jsx("label",{className:"text-sm text-muted-foreground",children:a("settingsProxy.apiKeyOptional")}),e.jsx(B,{type:"password",value:y,onChange:l=>S(l.target.value),onBlur:E,placeholder:a("settingsProxy.apiKeyPlaceholder"),className:"font-mono",disabled:t}),e.jsx("p",{className:"text-xs text-muted-foreground",children:a("settingsProxy.apiKeyDesc")})]}),e.jsxs("div",{className:"space-y-1",children:[e.jsx("label",{className:"text-sm text-muted-foreground",children:a("settingsProxy.managementKeyOptional")}),e.jsx(B,{type:"password",value:j,onChange:l=>P(l.target.value),onBlur:d,placeholder:a("settingsProxy.managementKeyPlaceholder"),className:"font-mono",disabled:t}),e.jsx("p",{className:"text-xs text-muted-foreground",children:a("settingsProxy.managementKeyDesc")})]}),e.jsxs("div",{className:"space-y-3 pt-2",children:[e.jsx(H,{onClick:h,disabled:g||!u,variant:"outline",className:"w-full",children:g?e.jsxs(e.Fragment,{children:[e.jsx(re,{className:"w-4 h-4 mr-2 animate-spin"}),a("settingsProxy.testing")]}):e.jsxs(e.Fragment,{children:[e.jsx(Xe,{className:"w-4 h-4 mr-2"}),a("settingsProxy.testConnection")]})}),o&&e.jsx("div",{className:`p-3 rounded-md ${o.reachable?"bg-green-50 border border-green-200 dark:bg-green-900/20 dark:border-green-900/50":"bg-red-50 border border-red-200 dark:bg-red-900/20 dark:border-red-900/50"}`,children:e.jsx("div",{className:"flex items-center gap-2",children:o.reachable?e.jsxs(e.Fragment,{children:[e.jsx(fe,{className:"w-4 h-4 text-green-600 dark:text-green-400"}),e.jsx("span",{className:"text-sm font-medium text-green-700 dark:text-green-300",children:a("settingsProxy.connectedLatency",{value:o.latencyMs})})]}):e.jsxs(e.Fragment,{children:[e.jsx(Qe,{className:"w-4 h-4 text-red-600 dark:text-red-400"}),e.jsx("span",{className:"text-sm font-medium text-red-700 dark:text-red-300",children:o.error||a("settingsProxy.connectionFailed")})]})})})]})]})}const pe="ccs_debug_mode",cs=["kiro","ghcp"];function ds(s){return s.trim().replace(/\s+/g," ").toUpperCase()}function Cs(){const{t:s}=ae(),{config:t,loading:g,saving:o,error:u,success:b,testResult:y,testing:j,editedHost:p,setEditedHost:C,editedPort:S,setEditedPort:P,editedAuthToken:w,setEditedAuthToken:A,editedManagementKey:E,setEditedManagementKey:d,editedLocalPort:x,setEditedLocalPort:h,fetchConfig:a,saveConfig:c,testConnection:k}=ns(),{fetchRawConfig:l}=Ye(),[_,be]=n.useState(()=>{try{return localStorage.getItem(pe)==="true"}catch{return!1}}),[je,z]=n.useState(!1),[Pe,oe]=n.useState(!0),[f,ne]=n.useState(!1),[ke,R]=n.useState(!1),[ie,I]=n.useState(""),K=n.useRef(!1),W=ds(ie)===V,ve=r=>{be(r);try{localStorage.setItem(pe,String(r))}catch{}},Y=n.useCallback(async()=>{try{oe(!0);const r=await fetch("/api/settings/auth/antigravity-risk");if(!r.ok)throw new Error(s("settingsProxy.failedLoadAgyMode"));const i=await r.json();z(i.antigravityAckBypass===!0)}catch(r){T.error(r instanceof Error?r.message:s("settingsProxy.failedLoadAgyMode")),z(!1)}finally{oe(!1)}},[s]),$=n.useCallback(async r=>{if(!(K.current||f||o))try{K.current=!0,ne(!0);const i=await fetch("/api/settings/auth/antigravity-risk",{method:"PUT",headers:{"Content-Type":"application/json"},body:JSON.stringify({antigravityAckBypass:r})}),O=await i.json();if(!i.ok)throw new Error(O.error||s("settingsProxy.failedUpdateAgyMode"));const Fe=O.antigravityAckBypass===!0,me=await fetch("/api/settings/auth/antigravity-risk",{cache:"no-store"});if(!me.ok)throw new Error(s("settingsProxy.failedVerifyAgyMode"));const ge=(await me.json()).antigravityAckBypass===!0;if(ge!==r)throw new Error(s("settingsProxy.notPersistedAgyMode"));z(ge&&Fe),R(!1),I(""),T.success(s(r?"settingsProxy.agyModeEnabled":"settingsProxy.agyModeDisabled")),await l()}catch(i){T.error(i instanceof Error?i.message:s("settingsProxy.failedUpdateAgyMode"))}finally{K.current=!1,ne(!1)}},[f,l,o,s]),Ne=n.useCallback(r=>{if(!(K.current||f||o)){if(r){R(!0);return}R(!1),I(""),$(!1)}},[f,$,o]),Ce=n.useCallback(()=>{if(!W){T.error(s("settingsProxy.typePhraseToContinue",{value:V}));return}$(!0)},[W,$,s]),[v,G]=n.useState("plus"),[Se,we]=n.useState(!1),q=Ge(),{data:Ae}=qe(),le=Ae?.running??!1,J=n.useCallback(async()=>{try{const r=await L.cliproxyServer.getBackend();G(r.backend)}catch(r){console.error("[Proxy] Failed to fetch backend:",r)}},[]),X=n.useCallback(async()=>{try{const i=(await L.cliproxy.list()).variants.some(O=>cs.includes(O.provider));we(i)}catch(r){console.error("[Proxy] Failed to check variants:",r)}},[]),ce=r=>{const i=v;G(r),q.mutate({backend:r},{onError:()=>{G(i)}})};if(n.useEffect(()=>{if(_&&t){const r={...t,remote:{...t.remote,auth_token:t.remote.auth_token?"[REDACTED]":void 0,management_key:t.remote.management_key?"[REDACTED]":void 0}};console.log("[CCS Debug] Debug mode enabled - proxy config:",r)}},[_,t]),n.useEffect(()=>{a(),Y(),l(),J(),X()},[a,Y,l,J,X]),g||!t)return e.jsx("div",{className:"flex-1 flex items-center justify-center",children:e.jsxs("div",{className:"flex items-center gap-3 text-muted-foreground",children:[e.jsx(re,{className:"w-5 h-5 animate-spin"}),e.jsx("span",{children:s("settings.loading")})]})});const m=t.remote.enabled??!1,F=!m&&le,N=t.remote,M=t.fallback,Ee=t.remote.host??"",Te=t.remote.port!==void 0?t.remote.port.toString():"",Be=t.remote.auth_token??"",Me=t.remote.management_key??"",De=(t.local.port??U).toString(),Q=p??Ee,Z=S??Te,ee=w??Be,de=E??Me,xe=x??De,Le=()=>{const r=p??Q;r!==t.remote.host&&c({remote:{...N,host:r}}),C(null)},_e=()=>{const r=(S??Z).trim();if(r===""){t.remote.port!==void 0&&c({remote:{...N,port:void 0}}),P(null);return}const i=Number(r);if(!Number.isInteger(i)||i<1||i>65535){T.error(s("settingsProxy.invalidPortOrEmpty")),P(null);return}i!==t.remote.port&&c({remote:{...N,port:i}}),P(null)},Re=()=>{const r=w??ee;r!==t.remote.auth_token&&c({remote:{...N,auth_token:r}}),A(null)},Ie=()=>{const r=E??de;r!==t.remote.management_key&&c({remote:{...N,management_key:r||void 0}}),d(null)},Ke=()=>{const r=(x??xe).trim(),i=r===""?U:Number(r);if(!Number.isInteger(i)||i<1||i>65535){T.error(s("settingsProxy.invalidLocalPort")),h(null);return}i!==t.local.port&&c({local:{...t.local,port:i}}),h(null)},$e=()=>{k({host:Q,port:Z,protocol:t.remote.protocol||"http",authToken:ee})};return e.jsxs(e.Fragment,{children:[e.jsxs("div",{className:`absolute left-5 right-5 top-20 z-10 transition-all duration-200 ease-out ${u||b?"opacity-100 translate-y-0":"opacity-0 -translate-y-2 pointer-events-none"}`,children:[u&&e.jsxs(se,{variant:"destructive",className:"py-2 shadow-lg",children:[e.jsx(Ze,{className:"h-4 w-4"}),e.jsx(te,{children:u})]}),b&&e.jsxs("div",{className:"flex items-center gap-2 px-3 py-2 rounded-md border border-green-200 bg-green-50 text-green-700 shadow-lg dark:border-green-900/50 dark:bg-green-900/90 dark:text-green-300",children:[e.jsx(fe,{className:"h-4 w-4 shrink-0"}),e.jsx("span",{className:"text-sm font-medium",children:s("settings.saved")})]})]}),e.jsx(Je,{className:"flex-1",children:e.jsxs("div",{className:"p-5 space-y-6",children:[e.jsx("p",{className:"text-sm text-muted-foreground",children:s("settingsProxy.description",{backend:s(v==="plus"?"settingsProxy.backendPlus":"settingsProxy.backend")})}),!m&&e.jsxs("div",{className:"space-y-3",children:[e.jsx("h3",{className:"text-base font-medium",children:s("settingsProxy.instanceStatus")}),e.jsx(os,{})]}),e.jsxs("div",{className:"space-y-3",children:[e.jsx("h3",{className:"text-base font-medium",children:s("settingsProxy.connectionMode")}),e.jsxs("div",{className:"grid grid-cols-2 gap-3",children:[e.jsxs("button",{onClick:()=>c({remote:{...N,enabled:!1}}),disabled:o,className:`p-4 rounded-lg border-2 text-left transition-all ${m?"border-border hover:border-muted-foreground/50":"border-primary bg-primary/5"}`,children:[e.jsxs("div",{className:"flex items-center gap-3 mb-2",children:[e.jsx(es,{className:`w-5 h-5 ${m?"text-muted-foreground":"text-primary"}`}),e.jsx("span",{className:"font-medium",children:s("settingsProxy.local")})]}),e.jsx("p",{className:"text-xs text-muted-foreground",children:s("settingsProxy.localDesc",{backend:s(v==="plus"?"settingsProxy.backendPlus":"settingsProxy.backend")})})]}),e.jsxs("button",{onClick:()=>c({remote:{...N,enabled:!0}}),disabled:o,className:`p-4 rounded-lg border-2 text-left transition-all ${m?"border-primary bg-primary/5":"border-border hover:border-muted-foreground/50"}`,children:[e.jsxs("div",{className:"flex items-center gap-3 mb-2",children:[e.jsx(he,{className:`w-5 h-5 ${m?"text-primary":"text-muted-foreground"}`}),e.jsx("span",{className:"font-medium",children:s("settingsProxy.remote")})]}),e.jsx("p",{className:"text-xs text-muted-foreground",children:s("settingsProxy.remoteDesc",{backend:s(v==="plus"?"settingsProxy.backendPlus":"settingsProxy.backend")})})]})]})]}),e.jsxs("div",{className:"space-y-3",children:[e.jsxs("h3",{className:"text-base font-medium flex items-center gap-2",children:[e.jsx(ss,{className:"w-4 h-4"}),s("settingsProxy.backendBinary")]}),!m&&le&&e.jsxs(se,{className:"py-2 border-amber-200 bg-amber-50 dark:border-amber-900/50 dark:bg-amber-900/20 [&>svg]:top-2.5",children:[e.jsx(ye,{className:"h-4 w-4 text-amber-600"}),e.jsx(te,{className:"text-amber-700 dark:text-amber-400",children:s("settingsProxy.stopProxyToSwitch")})]}),e.jsxs("div",{className:"grid grid-cols-2 gap-3",children:[e.jsxs("button",{onClick:()=>ce("plus"),disabled:q.isPending||F,className:`p-4 rounded-lg border-2 text-left transition-all ${v==="plus"?"border-primary bg-primary/5":"border-border hover:border-muted-foreground/50"} ${F?"opacity-60 cursor-not-allowed":""}`,children:[e.jsxs("div",{className:"flex items-center gap-3 mb-2",children:[e.jsx("span",{className:"font-medium",children:s("settingsProxy.backendPlusApi")}),e.jsx("span",{className:"text-xs px-1.5 py-0.5 rounded bg-green-100 text-green-700 dark:bg-green-900/50 dark:text-green-400",children:s("settingsProxy.default")})]}),e.jsx("p",{className:"text-xs text-muted-foreground",children:s("settingsProxy.plusDesc")})]}),e.jsxs("button",{onClick:()=>ce("original"),disabled:q.isPending||F,className:`p-4 rounded-lg border-2 text-left transition-all ${v==="original"?"border-primary bg-primary/5":"border-border hover:border-muted-foreground/50"} ${F?"opacity-60 cursor-not-allowed":""}`,children:[e.jsx("div",{className:"flex items-center gap-3 mb-2",children:e.jsx("span",{className:"font-medium",children:s("settingsProxy.backendApi")})}),e.jsx("p",{className:"text-xs text-muted-foreground",children:s("settingsProxy.originalDesc")})]})]}),v==="original"&&Se&&e.jsxs(se,{variant:"destructive",className:"py-2",children:[e.jsx(ye,{className:"h-4 w-4"}),e.jsx(te,{children:s("settingsProxy.variantsIncompatible")})]})]}),e.jsxs("div",{className:"space-y-3",children:[e.jsxs("h3",{className:"text-base font-medium flex items-center gap-2",children:[e.jsx(ts,{className:"w-4 h-4 text-amber-700 dark:text-amber-300"}),s("settingsProxy.safety")]}),e.jsxs("div",{className:"space-y-3 rounded-lg border border-amber-400/35 bg-amber-50/70 p-4 dark:border-amber-800/60 dark:bg-amber-950/25",children:[e.jsxs("div",{className:"flex items-start justify-between gap-4",children:[e.jsxs("div",{className:"space-y-1",children:[e.jsx("p",{className:"font-medium text-sm",children:s("settingsProxy.agyModeTitle")}),e.jsx("p",{className:"text-xs text-muted-foreground",children:s("settingsProxy.agyModeDesc")})]}),e.jsx(D,{"aria-labelledby":"agy-power-user-mode-label","aria-describedby":"agy-power-user-mode-description",checked:je,disabled:Pe||f||o,onCheckedChange:Ne})]}),e.jsx("p",{id:"agy-power-user-mode-description",className:"text-xs text-amber-800/90 dark:text-amber-200/90",children:s("settingsProxy.agyWarning")}),ke&&e.jsxs("div",{className:"space-y-3 rounded-lg border border-rose-500/40 bg-rose-500/[0.08] p-3.5",children:[e.jsxs("div",{className:"space-y-1.5",children:[e.jsx("p",{className:"text-xs font-semibold tracking-wide text-rose-900 dark:text-rose-200",children:s("settingsProxy.finalConfirm")}),e.jsx("p",{className:"text-xs leading-relaxed text-rose-800/95 dark:text-rose-200/90",children:s("settingsProxy.finalConfirmDesc")})]}),e.jsxs("div",{className:"grid gap-2 md:grid-cols-2",children:[e.jsxs("div",{className:"rounded-md border border-rose-400/30 bg-rose-500/10 p-2.5",children:[e.jsx("p",{className:"text-[11px] font-semibold uppercase tracking-wide text-rose-900 dark:text-rose-200",children:s("settingsProxy.step1")}),e.jsxs("a",{href:"https://github.com/kaitranntt/ccs/issues/509",target:"_blank",rel:"noreferrer",className:"mt-1 inline-flex items-center gap-1.5 text-xs font-medium text-rose-800 underline decoration-rose-500/60 underline-offset-2 transition-colors hover:text-rose-700 dark:text-rose-200",children:[s("settingsProxy.readIssue"),e.jsx(rs,{className:"h-3.5 w-3.5"})]})]}),e.jsxs("div",{className:"rounded-md border border-rose-400/30 bg-rose-500/10 p-2.5",children:[e.jsx("p",{className:"text-[11px] font-semibold uppercase tracking-wide text-rose-900 dark:text-rose-200",children:s("settingsProxy.step2")}),e.jsxs("p",{className:"mt-1 text-xs text-rose-800/95 dark:text-rose-200/90",children:[s("settingsProxy.typePrefix")," ",e.jsx("code",{className:"rounded bg-background/80 px-1 py-0.5 font-mono",children:V})," ",s("settingsProxy.typeSuffix")]})]})]}),e.jsxs("div",{className:"space-y-2",children:[e.jsx(B,{value:ie,onChange:r=>I(r.target.value),placeholder:V,disabled:f||o,className:"font-mono text-xs","aria-label":s("settingsProxy.typePhraseAria")}),e.jsx("p",{className:"text-[11px] text-rose-800/90 dark:text-rose-200/80",children:s("settingsProxy.exactPhrase")})]}),e.jsxs("div",{className:"flex items-center justify-end gap-2",children:[e.jsx(H,{variant:"outline",size:"sm",onClick:()=>{R(!1),I("")},disabled:f||o,children:s("settingsBackups.cancel")}),e.jsx(H,{size:"sm",variant:"destructive",onClick:Ce,disabled:!W||f||o,children:s("settingsProxy.enableAgyMode")})]})]}),e.jsx("span",{id:"agy-power-user-mode-label",className:"sr-only",children:s("settingsProxy.toggleAgyMode")})]})]}),m&&e.jsx(ls,{config:t,saving:o,testing:j,testResult:y,displayHost:Q,displayPort:Z,displayAuthToken:ee,displayManagementKey:de,setEditedHost:C,setEditedPort:P,setEditedAuthToken:A,setEditedManagementKey:d,onSaveHost:Le,onSavePort:_e,onSaveAuthToken:Re,onSaveManagementKey:Ie,onSaveConfig:c,onTestConnection:$e}),e.jsxs("div",{className:"space-y-3",children:[e.jsx("h3",{className:"text-base font-medium",children:s("settingsProxy.fallbackSettings")}),e.jsxs("div",{className:"space-y-3 p-4 rounded-lg border bg-muted/30",children:[e.jsxs("div",{className:"flex items-center justify-between",children:[e.jsxs("div",{children:[e.jsx("p",{className:"font-medium text-sm",children:s("settingsProxy.enableFallback")}),e.jsx("p",{className:"text-xs text-muted-foreground",children:s("settingsProxy.enableFallbackDesc")})]}),e.jsx(D,{checked:M.enabled??!0,onCheckedChange:r=>c({fallback:{...M,enabled:r}}),disabled:o||!m})]}),e.jsxs("div",{className:"flex items-center justify-between",children:[e.jsxs("div",{children:[e.jsx("p",{className:"font-medium text-sm",children:s("settingsProxy.autoStartLocal")}),e.jsx("p",{className:"text-xs text-muted-foreground",children:s("settingsProxy.autoStartLocalDesc")})]}),e.jsx(D,{checked:M.auto_start??!1,onCheckedChange:r=>c({fallback:{...M,auto_start:r}}),disabled:o||!m||!M.enabled})]})]})]}),e.jsxs("div",{className:"space-y-3",children:[e.jsxs("h3",{className:"text-base font-medium flex items-center gap-2",children:[e.jsx(as,{className:"w-4 h-4"}),s("settingsProxy.advanced")]}),e.jsxs("div",{className:"space-y-3 p-4 rounded-lg border bg-muted/30",children:[e.jsxs("div",{className:"flex items-center justify-between",children:[e.jsxs("div",{children:[e.jsx("p",{className:"font-medium text-sm",children:s("settingsProxy.debugMode")}),e.jsx("p",{className:"text-xs text-muted-foreground",children:s("settingsProxy.debugModeDesc")})]}),e.jsx(D,{checked:_,onCheckedChange:ve,disabled:o})]}),_&&e.jsx("p",{className:"text-xs text-amber-600 dark:text-amber-400 pl-0.5",children:s("settingsProxy.debugModeEnabled")})]})]}),!m&&e.jsx(is,{config:t,saving:o,displayLocalPort:xe,setEditedLocalPort:h,onSaveLocalPort:Ke,onSaveConfig:c})]})}),e.jsx("div",{className:"p-4 border-t bg-background",children:e.jsxs(H,{variant:"outline",size:"sm",onClick:()=>{a(),Y(),l(),J(),X()},disabled:g||o||f,className:"w-full",children:[e.jsx(re,{className:`w-4 h-4 mr-2 ${g?"animate-spin":""}`}),s("settings.refresh")]})})]})}export{Cs as default};
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
import{j as e}from"./radix-ui-BR1vy4kf.js";import{r as o}from"./react-vendor-CNOkPC89.js";import{a as q,b7 as J,b9 as X,d as I,n as Y,L as A,r as R,s as M,t as K,v as B,w as E,I as F}from"./index-CmZS09IA.js";import{S as Q}from"./switch-CTrO47Q-.js";import{R as $,a3 as Z,u as ee,a4 as se,J as te,q as re}from"./icons-BYZM_9Gm.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 z={mode:"auto",tier_defaults:{opus:"high",sonnet:"medium",haiku:"low"},show_warnings:!0},U=1e4;function ie(){const[t,i]=o.useState(null),[b,d]=o.useState(!0),[_,N]=o.useState(!1),[p,g]=o.useState(null),[P,y]=o.useState(!1),f=o.useRef(void 0),w=o.useRef(!1),k=o.useCallback(async()=>{const r=new AbortController,c=setTimeout(()=>r.abort(),U);try{d(!0),g(null);const n=await fetch("/api/thinking",{signal:r.signal});if(clearTimeout(c),!n.ok)throw n.headers.get("content-type")?.includes("text/html")?new Error(`Server error (${n.status})`):new Error("Failed to load Thinking config");const m=await n.json();i(m.config||z),f.current=m.lastModified,w.current=!0}catch(n){clearTimeout(c),n.name==="AbortError"?g("Request timeout - please try again"):g(n.message)}finally{d(!1)}return()=>r.abort()},[]),l=o.useCallback(async r=>{if(!w.current||t===null){g("Cannot save settings before they load. Click Refresh and try again.");return}const c=t,n={...c,...r.mode!==void 0?{mode:r.mode}:{},...r.tier_defaults!==void 0?{tier_defaults:r.tier_defaults}:{},...r.show_warnings!==void 0?{show_warnings:r.show_warnings}:{}};r.clear_override||r.override===null?delete n.override:r.override!==void 0&&(n.override=r.override),r.clear_provider_overrides||r.provider_overrides===null?delete n.provider_overrides:r.provider_overrides!==void 0&&(n.provider_overrides=r.provider_overrides),i(n);const m=new AbortController,h=setTimeout(()=>m.abort(),U);try{N(!0),g(null);const x={...n,lastModified:f.current},u=await fetch("/api/thinking",{method:"PUT",headers:{"Content-Type":"application/json"},body:JSON.stringify(x),signal:m.signal});if(clearTimeout(h),!u.ok){if(u.headers.get("content-type")?.includes("text/html"))throw new Error(`Server error (${u.status})`);const s=await u.json();throw u.status===409?new Error("Config changed by another session. Refreshing..."):new Error(s.error||"Failed to save")}const v=await u.json();i(v.config),f.current=v.lastModified,y(!0),setTimeout(()=>y(!1),1500)}catch(x){clearTimeout(h),i(c),x.name==="AbortError"?g("Request timeout - please try again"):(g(x.message),x.message.includes("another session")&&setTimeout(()=>k(),1e3))}finally{N(!1)}},[t,k]),T=o.useCallback(r=>{l({mode:r})},[l]),C=o.useCallback((r,c)=>{const n=t?.tier_defaults||z.tier_defaults;l({tier_defaults:{...n,[r]:c}})},[t,l]),S=o.useCallback(r=>{l({show_warnings:r})},[l]),D=o.useCallback(r=>{if(r===void 0){l({override:null,clear_override:!0});return}l({override:r,clear_override:!1})},[l]),L=o.useCallback((r,c,n)=>{const m=t?.provider_overrides||{},h=m[r]||{};if(n===void 0){const{[c]:x,...u}=h,v=Object.keys(u).length>0?u:void 0,{[r]:O,...s}=m,a=v?{...s,[r]:v}:s;l({provider_overrides:Object.keys(a).length>0?a:null,clear_provider_overrides:Object.keys(a).length===0})}else l({provider_overrides:{...m,[r]:{...h,[c]:n}},clear_provider_overrides:!1})},[t,l]);return{config:t||z,loading:b,saving:_,error:p,success:P,fetchConfig:k,saveConfig:l,setMode:T,setTierDefault:C,setShowWarnings:S,setOverride:D,setProviderOverride:L}}const H=[{value:"minimal",label:"Minimal (512 tokens)"},{value:"low",label:"Low (1K tokens)"},{value:"medium",label:"Medium (8K tokens)"},{value:"high",label:"High (24K tokens)"},{value:"xhigh",label:"Extra High (32K tokens)"},{value:"auto",label:"Auto (dynamic)"}],ne=[{value:"__none__",label:"None (use CLI flags only)"},...H,{value:"__custom__",label:"Custom budget (number)"},{value:"off",label:"Off (disable thinking)"}],ae=["agy","gemini","codex"],G=0,V=1e5;function ve(){const{t}=q(),{config:i,loading:b,saving:d,error:_,success:N,fetchConfig:p,setMode:g,setTierDefault:P,setShowWarnings:y,setOverride:f,setProviderOverride:w}=ie(),[k,l]=o.useState(null),[T,C]=o.useState(""),[S,D]=o.useState([]),[L,r]=o.useState(null),c=o.useMemo(()=>Array.from(new Set([...ae,...Object.keys(i.provider_overrides??{}),...S])),[S,i.provider_overrides]),n=i.override===void 0?"__none__":typeof i.override=="number"||/^\d+$/.test(String(i.override))?"__custom__":String(i.override),m=typeof i.override=="number"||/^\d+$/.test(String(i.override??""))?String(i.override):"",h=L??m,x=Object.keys(i.provider_overrides??{}).length>0,u=k??x;o.useEffect(()=>{p()},[p]);const v=()=>{const s=T.trim().toLowerCase();s&&(c.includes(s)||D(a=>[...a,s]),C(""),l(!0))},O=()=>{const s=h.trim();if(!s){f(void 0);return}const a=Number.parseInt(s,10);Number.isNaN(a)||a<G||a>V||!/^\d+$/.test(s)||f(a)};return b?e.jsx("div",{className:"flex-1 flex items-center justify-center",children:e.jsxs("div",{className:"flex items-center gap-3 text-muted-foreground",children:[e.jsx($,{className:"w-5 h-5 animate-spin"}),e.jsx("span",{children:t("settings.loading")})]})}):e.jsxs(e.Fragment,{children:[e.jsxs("div",{className:`absolute left-5 right-5 top-20 z-10 transition-all duration-200 ease-out ${_||N?"opacity-100 translate-y-0":"opacity-0 -translate-y-2 pointer-events-none"}`,children:[_&&e.jsx(J,{variant:"destructive",className:"py-2 shadow-lg",children:e.jsxs("div",{className:"flex items-center justify-between w-full",children:[e.jsxs("div",{className:"flex items-center gap-2",children:[e.jsx(Z,{className:"h-4 w-4"}),e.jsx(X,{children:_})]}),e.jsxs(I,{variant:"outline",size:"sm",onClick:p,className:"h-7 px-2 text-xs border-destructive/50 hover:bg-destructive/10",children:[e.jsx($,{className:"w-3 h-3 mr-1"}),t("sharedPage.retry")]})]})}),N&&e.jsxs("div",{className:"flex items-center gap-2 px-3 py-2 rounded-md border border-green-200 bg-green-50 text-green-700 shadow-lg dark:border-green-900/50 dark:bg-green-900/90 dark:text-green-300",children:[e.jsx(ee,{className:"h-4 w-4 shrink-0"}),e.jsx("span",{className:"text-sm font-medium",children:t("settings.saved")})]})]}),e.jsx(Y,{className:"flex-1",children:e.jsxs("div",{className:"p-5 space-y-6",children:[e.jsxs("div",{className:"flex items-center gap-3",children:[e.jsx(se,{className:"w-5 h-5 text-primary"}),e.jsx("p",{className:"text-sm text-muted-foreground",children:t("settingsThinking.description")})]}),e.jsxs("div",{className:"flex items-start gap-2 p-3 rounded-lg bg-blue-50 dark:bg-blue-900/20 border border-blue-200 dark:border-blue-800",children:[e.jsx(te,{className:"w-4 h-4 text-blue-600 dark:text-blue-400 shrink-0 mt-0.5"}),e.jsxs("div",{className:"text-sm text-blue-700 dark:text-blue-300",children:[e.jsx("p",{className:"font-medium",children:t("settingsThinking.supportedProviders")}),e.jsxs("ul",{className:"mt-1 space-y-0.5 text-blue-600 dark:text-blue-400",children:[e.jsxs("li",{children:[t("settingsThinking.supportLine1Prefix")," ",e.jsx("strong",{children:"agy"}),","," ",e.jsx("strong",{children:"gemini"})," ",t("settingsThinking.supportLine1Suffix")]}),e.jsxs("li",{children:[t("settingsThinking.supportLine2Prefix")," ",e.jsx("strong",{children:"codex"})," ",t("settingsThinking.supportLine2SuffixPrefix"),e.jsx("code",{children:"--effort"}),t("settingsThinking.supportLine2SuffixPostfix")]}),e.jsxs("li",{children:[t("settingsThinking.supportLine3Prefix")," ",e.jsx("code",{children:"-high"}),t("settingsThinking.supportLine3Suffix")]})]})]})]}),e.jsxs("div",{className:"space-y-3",children:[e.jsx("h3",{className:"text-base font-medium",children:t("settingsThinking.modeTitle")}),e.jsx("div",{className:"space-y-2",children:["auto","off","manual"].map(s=>e.jsxs("div",{className:`flex items-center justify-between p-4 rounded-lg cursor-pointer transition-colors ${i.mode===s?"bg-primary/10 border border-primary/30":"bg-muted/50 hover:bg-muted/80"} ${d?"opacity-70 pointer-events-none":""}`,onClick:()=>{d||g(s)},children:[e.jsxs("div",{children:[e.jsx("p",{className:"font-medium capitalize",children:s}),e.jsxs("p",{className:"text-sm text-muted-foreground",children:[s==="auto"&&t("settingsThinking.modeAutoDesc"),s==="off"&&t("settingsThinking.modeOffDesc"),s==="manual"&&t("settingsThinking.modeManualDesc")]})]}),e.jsx("div",{className:`w-4 h-4 rounded-full border-2 ${i.mode===s?"bg-primary border-primary":"border-muted-foreground/50"}`})]},s))})]}),i.mode==="auto"&&e.jsxs("div",{className:"space-y-3",children:[e.jsx("h3",{className:"text-base font-medium",children:t("settingsThinking.tierDefaults")}),e.jsx("p",{className:"text-sm text-muted-foreground",children:t("settingsThinking.tierDefaultsDesc")}),e.jsx("div",{className:"space-y-3",children:["opus","sonnet","haiku"].map(s=>e.jsxs("div",{className:"flex items-center gap-4 p-3 rounded-lg bg-muted/30",children:[e.jsx(A,{className:"w-20 capitalize font-medium",children:s}),e.jsxs(R,{value:i.tier_defaults[s],onValueChange:a=>P(s,a),disabled:d,children:[e.jsx(M,{className:"flex-1",children:e.jsx(K,{})}),e.jsx(B,{children:H.map(a=>e.jsx(E,{value:a.value,children:a.label},a.value))})]})]},s))})]}),i.mode==="manual"&&e.jsxs("div",{className:"space-y-3",children:[e.jsx("h3",{className:"text-base font-medium",children:t("settingsThinking.persistentOverride")}),e.jsx("p",{className:"text-sm text-muted-foreground",children:t("settingsThinking.persistentOverrideDesc")}),e.jsxs(R,{value:n,onValueChange:s=>{if(s==="__none__"){f(void 0);return}if(s==="__custom__"){h||r("8192");return}r(null),f(s)},disabled:d,children:[e.jsx(M,{children:e.jsx(K,{})}),e.jsx(B,{children:ne.map(s=>e.jsx(E,{value:s.value,children:s.label},s.value))})]}),n==="__custom__"&&e.jsxs("div",{className:"space-y-2",children:[e.jsxs("div",{className:"flex items-center gap-2",children:[e.jsx(F,{type:"number",min:G,max:V,value:h,onChange:s=>r(s.target.value),onBlur:O,disabled:d,placeholder:t("settingsThinking.enterCustomBudget")}),e.jsx(I,{type:"button",size:"sm",variant:"outline",onClick:O,disabled:d,children:t("settingsThinking.apply")})]}),e.jsxs("p",{className:"text-xs text-muted-foreground",children:["Range: ",G," to ",V]})]})]}),e.jsxs("div",{className:"space-y-3",children:[e.jsxs("button",{type:"button",className:"flex items-center gap-2 text-base font-medium w-full text-left",onClick:()=>l(s=>!(s??x)),disabled:d,children:[e.jsx(re,{className:`w-4 h-4 transition-transform ${u?"rotate-0":"-rotate-90"}`}),t("settingsThinking.providerOverrides",{count:Object.keys(i.provider_overrides??{}).length})]}),u&&e.jsxs("div",{className:"space-y-3",children:[e.jsx("p",{className:"text-sm text-muted-foreground",children:t("settingsThinking.providerOverridesDesc")}),e.jsxs("div",{className:"flex items-center gap-2",children:[e.jsx(F,{value:T,onChange:s=>C(s.target.value),disabled:d,placeholder:t("settingsThinking.addProviderPlaceholder")}),e.jsx(I,{type:"button",size:"sm",variant:"outline",onClick:v,disabled:d,children:t("settingsGlobalEnv.add")})]}),c.map(s=>e.jsxs("div",{className:"space-y-2 p-3 rounded-lg bg-muted/30",children:[e.jsx(A,{className:"capitalize font-medium text-sm",children:s}),e.jsx("div",{className:"grid grid-cols-3 gap-2",children:["opus","sonnet","haiku"].map(a=>{const W=i.provider_overrides?.[s]?.[a]||"__default__";return e.jsxs("div",{className:"space-y-1",children:[e.jsx(A,{className:"text-xs text-muted-foreground capitalize",children:a}),e.jsxs(R,{value:W,onValueChange:j=>w(s,a,j==="__default__"?void 0:j),disabled:d,children:[e.jsx(M,{className:"h-8 text-xs",children:e.jsx(K,{})}),e.jsxs(B,{children:[e.jsx(E,{value:"__default__",children:t("cursorPage.default")}),H.map(j=>e.jsx(E,{value:j.value,children:j.label},j.value))]})]})]},a)})})]},s))]})]}),e.jsxs("div",{className:"flex items-center justify-between p-4 rounded-lg bg-muted/50",children:[e.jsxs("div",{children:[e.jsx("p",{className:"font-medium",children:t("settingsThinking.showWarnings")}),e.jsx("p",{className:"text-sm text-muted-foreground",children:t("settingsThinking.showWarningsDesc")})]}),e.jsx(Q,{checked:i.show_warnings??!0,onCheckedChange:y,disabled:d})]}),e.jsxs("div",{className:"p-4 rounded-lg border bg-muted/30",children:[e.jsx("h4",{className:"text-sm font-medium mb-2",children:t("settingsThinking.cliEnvOverride")}),e.jsxs("p",{className:"text-sm text-muted-foreground mb-2",children:["Override per session with flags or"," ",e.jsx("code",{className:"px-1.5 py-0.5 rounded bg-muted",children:"CCS_THINKING"})," env var. Priority: flag > env > config."]}),e.jsxs("div",{className:"space-y-1 text-sm font-mono text-muted-foreground",children:[e.jsx("p",{children:"ccs gemini --thinking high"}),e.jsx("p",{children:"ccs codex --effort xhigh"}),e.jsx("p",{children:'CCS_THINKING=high ccs codex "debug this"'}),e.jsx("p",{children:"ccs config thinking --mode auto"})]})]})]})}),e.jsx("div",{className:"p-4 border-t bg-background",children:e.jsxs(I,{variant:"outline",size:"sm",onClick:p,disabled:b||d,className:"w-full",children:[e.jsx($,{className:`w-4 h-4 mr-2 ${b?"animate-spin":""}`}),t("settings.refresh")]})})]})}export{ve as default};
|