@kaitranntt/ccs 8.1.3 → 8.1.4-dev.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (158) hide show
  1. package/dist/channels/official-channels-runtime.js +1 -1
  2. package/dist/channels/official-channels-runtime.js.map +1 -1
  3. package/dist/cliproxy/ai-providers/codex-reasoning-proxy.d.ts.map +1 -1
  4. package/dist/cliproxy/ai-providers/codex-reasoning-proxy.js +88 -11
  5. package/dist/cliproxy/ai-providers/codex-reasoning-proxy.js.map +1 -1
  6. package/dist/cliproxy/auth/auth-types.d.ts +2 -0
  7. package/dist/cliproxy/auth/auth-types.d.ts.map +1 -1
  8. package/dist/cliproxy/auth/oauth-handler.d.ts.map +1 -1
  9. package/dist/cliproxy/auth/oauth-handler.js +12 -6
  10. package/dist/cliproxy/auth/oauth-handler.js.map +1 -1
  11. package/dist/cliproxy/auth/oauth-trace/redactor.d.ts.map +1 -1
  12. package/dist/cliproxy/auth/oauth-trace/redactor.js +1 -0
  13. package/dist/cliproxy/auth/oauth-trace/redactor.js.map +1 -1
  14. package/dist/cliproxy/proxy/proxy-config-resolver.d.ts.map +1 -1
  15. package/dist/cliproxy/proxy/proxy-config-resolver.js +11 -1
  16. package/dist/cliproxy/proxy/proxy-config-resolver.js.map +1 -1
  17. package/dist/cliproxy/proxy/tool-sanitization-proxy.d.ts.map +1 -1
  18. package/dist/cliproxy/proxy/tool-sanitization-proxy.js +160 -8
  19. package/dist/cliproxy/proxy/tool-sanitization-proxy.js.map +1 -1
  20. package/dist/cliproxy/proxy/upstream-response-timeout.d.ts +14 -0
  21. package/dist/cliproxy/proxy/upstream-response-timeout.d.ts.map +1 -0
  22. package/dist/cliproxy/proxy/upstream-response-timeout.js +72 -0
  23. package/dist/cliproxy/proxy/upstream-response-timeout.js.map +1 -0
  24. package/dist/codex-auth/codex-config-symlink.js +21 -4
  25. package/dist/codex-auth/codex-config-symlink.js.map +1 -1
  26. package/dist/commands/config-channels-command.d.ts +1 -4
  27. package/dist/commands/config-channels-command.d.ts.map +1 -1
  28. package/dist/commands/config-channels-command.js +20 -24
  29. package/dist/commands/config-channels-command.js.map +1 -1
  30. package/dist/cursor/cursor-daemon-auth.d.ts +2 -0
  31. package/dist/cursor/cursor-daemon-auth.d.ts.map +1 -0
  32. package/dist/cursor/cursor-daemon-auth.js +49 -0
  33. package/dist/cursor/cursor-daemon-auth.js.map +1 -0
  34. package/dist/cursor/cursor-daemon-entry.d.ts.map +1 -1
  35. package/dist/cursor/cursor-daemon-entry.js +44 -0
  36. package/dist/cursor/cursor-daemon-entry.js.map +1 -1
  37. package/dist/cursor/cursor-daemon.d.ts +2 -1
  38. package/dist/cursor/cursor-daemon.d.ts.map +1 -1
  39. package/dist/cursor/cursor-daemon.js +21 -5
  40. package/dist/cursor/cursor-daemon.js.map +1 -1
  41. package/dist/cursor/cursor-models.d.ts.map +1 -1
  42. package/dist/cursor/cursor-models.js +2 -1
  43. package/dist/cursor/cursor-models.js.map +1 -1
  44. package/dist/cursor/cursor-profile-executor.d.ts +1 -1
  45. package/dist/cursor/cursor-profile-executor.d.ts.map +1 -1
  46. package/dist/cursor/cursor-profile-executor.js +7 -4
  47. package/dist/cursor/cursor-profile-executor.js.map +1 -1
  48. package/dist/cursor/cursor-runtime-probe.d.ts.map +1 -1
  49. package/dist/cursor/cursor-runtime-probe.js +4 -2
  50. package/dist/cursor/cursor-runtime-probe.js.map +1 -1
  51. package/dist/cursor/types.d.ts +1 -0
  52. package/dist/cursor/types.d.ts.map +1 -1
  53. package/dist/dispatcher/profile-resolver.d.ts +16 -0
  54. package/dist/dispatcher/profile-resolver.d.ts.map +1 -1
  55. package/dist/dispatcher/profile-resolver.js +49 -3
  56. package/dist/dispatcher/profile-resolver.js.map +1 -1
  57. package/dist/docker/docker-key-rotation.d.ts +2 -0
  58. package/dist/docker/docker-key-rotation.d.ts.map +1 -1
  59. package/dist/docker/docker-key-rotation.js +9 -1
  60. package/dist/docker/docker-key-rotation.js.map +1 -1
  61. package/dist/glmt/sse-parser.d.ts +1 -0
  62. package/dist/glmt/sse-parser.d.ts.map +1 -1
  63. package/dist/glmt/sse-parser.js +13 -1
  64. package/dist/glmt/sse-parser.js.map +1 -1
  65. package/dist/proxy/server/messages-route.d.ts.map +1 -1
  66. package/dist/proxy/server/messages-route.js +69 -3
  67. package/dist/proxy/server/messages-route.js.map +1 -1
  68. package/dist/proxy/transformers/request-transformer.d.ts.map +1 -1
  69. package/dist/proxy/transformers/request-transformer.js +9 -2
  70. package/dist/proxy/transformers/request-transformer.js.map +1 -1
  71. package/dist/shared/claude-extension-setup.d.ts.map +1 -1
  72. package/dist/shared/claude-extension-setup.js +2 -1
  73. package/dist/shared/claude-extension-setup.js.map +1 -1
  74. package/dist/targets/codex-adapter.js +1 -1
  75. package/dist/targets/codex-adapter.js.map +1 -1
  76. package/dist/ui/assets/{Trans-DyZQZ3e2.js → Trans-BIQ-yfAc.js} +1 -1
  77. package/dist/ui/assets/accounts-bN7DnjXo.js +1 -0
  78. package/dist/ui/assets/{alert-dialog-DWHL-dqd.js → alert-dialog-D0yey0YJ.js} +1 -1
  79. package/dist/ui/assets/api-CEtMc2bM.js +4 -0
  80. package/dist/ui/assets/{auth-section-B4o90dwz.js → auth-section-BHZUn2Hv.js} +1 -1
  81. package/dist/ui/assets/{backups-section-1AsdSIJO.js → backups-section-BNVlJSV3.js} +1 -1
  82. package/dist/ui/assets/{channels-CU4Zdsc_.js → channels-BOB1P4Kt.js} +1 -1
  83. package/dist/ui/assets/{checkbox-CbCKGH8I.js → checkbox-Bt-F3GmI.js} +1 -1
  84. package/dist/ui/assets/claude-extension-AzKgsH0H.js +1 -0
  85. package/dist/ui/assets/cliproxy-C1liaQi8.js +4 -0
  86. package/dist/ui/assets/{cliproxy-ai-providers-Dr4L5NRY.js → cliproxy-ai-providers-CzyaYfYI.js} +6 -6
  87. package/dist/ui/assets/cliproxy-control-panel-DmkEW68l.js +1 -0
  88. package/dist/ui/assets/codex-B2FLnjZI.js +30 -0
  89. package/dist/ui/assets/{confirm-dialog-b5Dahgnk.js → confirm-dialog-CYvBJC0z.js} +1 -1
  90. package/dist/ui/assets/{copilot-B1Ojakbt.js → copilot-Csab21fh.js} +2 -2
  91. package/dist/ui/assets/{cursor-PUtNVPx1.js → cursor-fOpftodW.js} +1 -1
  92. package/dist/ui/assets/{droid-S2gclncb.js → droid-FIcjtOf-.js} +1 -1
  93. package/dist/ui/assets/{globalenv-section-7wKSmNSG.js → globalenv-section-CpIAk36Y.js} +1 -1
  94. package/dist/ui/assets/{health-hMLN_gyw.js → health-D0HvHNud.js} +1 -1
  95. package/dist/ui/assets/{index-Cx0dmbiQ.js → index-BTPa3KEN.js} +1 -1
  96. package/dist/ui/assets/{index-Coc3_ABK.js → index-Cr4G276q.js} +1 -1
  97. package/dist/ui/assets/{index-BWboJia4.js → index-D0VoBTF3.js} +1 -1
  98. package/dist/ui/assets/{index-CxvNNHgE.js → index-D5G9mVmP.js} +1 -1
  99. package/dist/ui/assets/{index-DkR2KVhF.js → index-Dm_QojrJ.js} +1 -1
  100. package/dist/ui/assets/index-G3mgTfgR.css +1 -0
  101. package/dist/ui/assets/index-N35Xkk8N.js +1 -0
  102. package/dist/ui/assets/{index-CcGVqYOy.js → index-sIfjKy42.js} +18 -18
  103. package/dist/ui/assets/{logs-BRFVfyLc.js → logs-B33n-VaM.js} +1 -1
  104. package/dist/ui/assets/{masked-input-4L9CIZGb.js → masked-input-BrUE6z_f.js} +1 -1
  105. package/dist/ui/assets/proxy-status-widget-Dm2ziI5D.js +1 -0
  106. package/dist/ui/assets/{raw-json-settings-editor-panel-DXh8c8rA.js → raw-json-settings-editor-panel-DZRtQXbD.js} +1 -1
  107. package/dist/ui/assets/{searchable-select-CtvEQrMo.js → searchable-select-D2smFEI5.js} +1 -1
  108. package/dist/ui/assets/{separator-E0ISp1SN.js → separator-BvoSJCHW.js} +1 -1
  109. package/dist/ui/assets/{shared-BeYwHeNS.js → shared-qKNFwLmT.js} +2 -2
  110. package/dist/ui/assets/{table-BBslZvNP.js → table-DYyc1gJc.js} +1 -1
  111. package/dist/ui/assets/updates-XXi3TQNZ.js +1 -0
  112. package/dist/ui/assets/{use-accounts-BdalFsdY.js → use-accounts-BR64_yUk.js} +1 -1
  113. package/dist/ui/index.html +2 -2
  114. package/dist/utils/browser/browser-settings.d.ts.map +1 -1
  115. package/dist/utils/browser/browser-settings.js +13 -3
  116. package/dist/utils/browser/browser-settings.js.map +1 -1
  117. package/dist/utils/glmt-deprecation.d.ts.map +1 -1
  118. package/dist/utils/glmt-deprecation.js +1 -3
  119. package/dist/utils/glmt-deprecation.js.map +1 -1
  120. package/dist/web-server/index.d.ts.map +1 -1
  121. package/dist/web-server/index.js +0 -9
  122. package/dist/web-server/index.js.map +1 -1
  123. package/dist/web-server/middleware/auth-middleware.d.ts.map +1 -1
  124. package/dist/web-server/middleware/auth-middleware.js +26 -4
  125. package/dist/web-server/middleware/auth-middleware.js.map +1 -1
  126. package/dist/web-server/routes/cliproxy-auth-routes.d.ts +10 -0
  127. package/dist/web-server/routes/cliproxy-auth-routes.d.ts.map +1 -1
  128. package/dist/web-server/routes/cliproxy-auth-routes.js +45 -13
  129. package/dist/web-server/routes/cliproxy-auth-routes.js.map +1 -1
  130. package/dist/web-server/routes/cliproxy-local-proxy.d.ts.map +1 -1
  131. package/dist/web-server/routes/cliproxy-local-proxy.js +25 -8
  132. package/dist/web-server/routes/cliproxy-local-proxy.js.map +1 -1
  133. package/dist/web-server/routes/cursor-routes.d.ts.map +1 -1
  134. package/dist/web-server/routes/cursor-routes.js +6 -1
  135. package/dist/web-server/routes/cursor-routes.js.map +1 -1
  136. package/dist/web-server/routes/image-analysis-routes.d.ts.map +1 -1
  137. package/dist/web-server/routes/image-analysis-routes.js +7 -0
  138. package/dist/web-server/routes/image-analysis-routes.js.map +1 -1
  139. package/dist/web-server/routes/settings-routes.d.ts.map +1 -1
  140. package/dist/web-server/routes/settings-routes.js +10 -1
  141. package/dist/web-server/routes/settings-routes.js.map +1 -1
  142. package/dist/web-server/services/claude-extension-settings-service.d.ts.map +1 -1
  143. package/dist/web-server/services/claude-extension-settings-service.js +5 -1
  144. package/dist/web-server/services/claude-extension-settings-service.js.map +1 -1
  145. package/lib/mcp/ccs-browser-server.cjs +24 -13
  146. package/package.json +1 -1
  147. package/scripts/github/stable-release-issue-cleanup-lib.mjs +113 -0
  148. package/scripts/github/stable-release-issue-cleanup.mjs +134 -0
  149. package/dist/ui/assets/accounts-BPJltru3.js +0 -1
  150. package/dist/ui/assets/api-BxPN-zy4.js +0 -4
  151. package/dist/ui/assets/claude-extension-CWpjmIGt.js +0 -1
  152. package/dist/ui/assets/cliproxy-K6eBb5VO.js +0 -4
  153. package/dist/ui/assets/cliproxy-control-panel-Cz5r7kHP.js +0 -1
  154. package/dist/ui/assets/codex-0HdbW8NR.js +0 -30
  155. package/dist/ui/assets/index-BMoGhs28.css +0 -1
  156. package/dist/ui/assets/index-COt1pbk-.js +0 -1
  157. package/dist/ui/assets/proxy-status-widget-s1UWOE23.js +0 -1
  158. package/dist/ui/assets/updates-CDrm903n.js +0 -1
@@ -0,0 +1 @@
1
+ import{j as e}from"./radix-ui-nu4wz29m.js";import{r as W}from"./react-vendor-Bjx91N7w.js";import{a as q,bf as Ce,B as f,e as P,x as te,C as x,s as p,t as v,a0 as j,b as g,I as Y,j as ne,k as ie,l as le,m as de,n as re,z as J,U as we,V as Ve,W as oe,X as ce,c as fe,Y as ke}from"./index-sIfjKy42.js";import{u as Q,a as K,b as M}from"./tanstack-bhJxV1h8.js";import{t as C}from"./notifications-B4_o8bcr.js";import{aa as De,a9 as Be,L as $,au as Ie,at as Te,R as Re,T as ue,ai as Ae,a7 as qe}from"./icons-DzKUh8vG.js";import"./utils-CzKF5WmX.js";import"./form-utils-CuHzLhJZ.js";import"./charts-eIPy2oG6.js";const U=["claude-extension-bindings"];async function w(s,n){const t=await fetch(Ce(s),{headers:{"Content-Type":"application/json"},...n});if(!t.ok){const l=await t.json().catch(()=>null);throw new Error(l?.error||`Request failed (${t.status})`)}return t.status===204?void 0:await t.json()}function Ue(){return Q({queryKey:["claude-extension-options"],queryFn:()=>w("/claude-extension/profiles")})}function Fe(s,n="vscode"){return Q({queryKey:["claude-extension-setup",s,n],enabled:!!s,queryFn:()=>w(`/claude-extension/setup?profile=${encodeURIComponent(s||"")}&host=${encodeURIComponent(n)}`)})}function Le(){return Q({queryKey:U,queryFn:()=>w("/claude-extension/bindings")})}function Oe(s){return Q({queryKey:["claude-extension-binding-status",s],enabled:!!s,queryFn:()=>w(`/claude-extension/bindings/${encodeURIComponent(s||"")}/verify`)})}function $e(){const s=K();return M({mutationFn:n=>w("/claude-extension/bindings",{method:"POST",body:JSON.stringify(n)}),onSuccess:()=>{s.invalidateQueries({queryKey:U}),C.success("Binding created")},onError:n=>C.error(n.message)})}function Je(){const s=K(),{t:n}=q();return M({mutationFn:({id:t,binding:l})=>w(`/claude-extension/bindings/${encodeURIComponent(t)}`,{method:"PUT",body:JSON.stringify(l)}),onSuccess:(t,l)=>{s.invalidateQueries({queryKey:U}),s.invalidateQueries({queryKey:["claude-extension-binding-status",l.id]}),C.success(n("claudeExtensionPage.bindingSaved"))},onError:t=>C.error(t.message)})}function Qe(){const s=K(),{t:n}=q();return M({mutationFn:t=>w(`/claude-extension/bindings/${encodeURIComponent(t)}`,{method:"DELETE"}),onSuccess:()=>{s.invalidateQueries({queryKey:U}),C.success(n("claudeExtensionPage.bindingDeleted"))},onError:t=>C.error(t.message)})}function pe(s,n){const t=K();return M({mutationFn:({id:l,target:S})=>w(`/claude-extension/bindings/${encodeURIComponent(l)}/${s}`,{method:"POST",body:JSON.stringify({target:S})}),onSuccess:l=>{t.invalidateQueries({queryKey:U}),t.setQueryData(["claude-extension-binding-status",l.bindingId],l),C.success(n)},onError:l=>C.error(l.message)})}function Ke(){const{t:s}=q();return pe("apply",s("claudeExtensionPage.bindingApplied"))}function Me(){const{t:s}=q();return pe("reset",s("claudeExtensionPage.managedValuesRemoved"))}const He=[];function xe(s){return{name:"",profile:s,host:"vscode",ideSettingsPath:"",notes:""}}function T(s){return{name:s.name,profile:s.profile,host:s.host,ideSettingsPath:s.ideSettingsPath||"",notes:s.notes||""}}function ze(s){return{name:s.name.trim(),profile:s.profile.trim(),host:s.host,ideSettingsPath:s.ideSettingsPath.trim()||void 0,notes:s.notes.trim()||void 0}}function ge(s){return s?.state==="applied"}function _e({state:s}){const n=s==="applied"?"border-emerald-500/30 bg-emerald-500/10 text-emerald-700 dark:text-emerald-300":s==="drifted"?"border-amber-500/30 bg-amber-500/10 text-amber-700 dark:text-amber-300":s==="missing"?"border-destructive/30 bg-destructive/10 text-destructive":"border-border bg-muted text-muted-foreground";return e.jsx(f,{variant:"outline",className:n,children:s})}function We(s){return s.replace(/[\\/]/g,"$&​")}function o({label:s,value:n,mono:t=!1,copyValue:l}){const S=typeof l=="string"&&l.trim().length>0;return e.jsxs("div",{className:"grid gap-2 text-sm sm:grid-cols-[112px_minmax(0,1fr)] sm:items-start",children:[e.jsx("span",{className:"text-muted-foreground",children:s}),S?e.jsxs("div",{className:"flex min-w-0 items-start gap-2",children:[e.jsx("div",{className:"min-w-0 flex-1 rounded-md border bg-muted/25 px-3 py-2",children:e.jsx("span",{className:"block text-left font-mono text-xs leading-5 [overflow-wrap:anywhere]",children:We(n)})}),e.jsx(J,{value:l,label:`Copy ${s.toLowerCase()}`,className:"shrink-0"})]}):e.jsx("span",{className:fe("text-left sm:text-right",t&&"font-mono text-xs leading-5 [overflow-wrap:anywhere]"),children:n})]})}function me({title:s,description:n,value:t}){return e.jsxs(x,{className:"border-border/60 bg-card/80",children:[e.jsx(p,{className:"pb-3",children:e.jsxs("div",{className:"flex items-start justify-between gap-3",children:[e.jsxs("div",{children:[e.jsx(v,{className:"text-base",children:s}),e.jsx(j,{className:"mt-1",children:n})]}),e.jsx(J,{value:t,label:`Copy ${s}`})]})}),e.jsx(g,{children:e.jsx("pre",{className:"max-h-[360px] overflow-auto rounded-lg border bg-muted/30 p-4 text-xs leading-6",children:t})})]})}function he({title:s,description:n,status:t,applyLabel:l,resetLabel:S,onApply:F,onReset:m,disabled:b,busy:V}){return e.jsxs(x,{className:"border-border/60 bg-card/80",children:[e.jsx(p,{className:"pb-3",children:e.jsxs("div",{className:"flex items-start justify-between gap-3",children:[e.jsxs("div",{children:[e.jsx(v,{className:"text-base",children:s}),e.jsx(j,{className:"mt-1",children:n})]}),t?e.jsx(_e,{state:t.state}):null]})}),e.jsxs(g,{className:"space-y-4",children:[e.jsxs("div",{className:"space-y-2",children:[e.jsx(o,{label:"Path",value:t?.path||"Save a binding first",mono:!0,copyValue:t?.path}),e.jsx(o,{label:"File",value:t?t.exists?"Present":"Not created yet":"Unavailable"})]}),e.jsx("div",{className:"rounded-lg border bg-muted/25 p-3 text-sm text-muted-foreground",children:t?.message||ke.t("claudeExtensionPage.verifyAfterSaving",{defaultValue:"Verify the binding after saving to inspect the current file state."})}),e.jsxs("div",{className:"flex gap-2",children:[e.jsxs(P,{size:"sm",className:"flex-1",onClick:F,disabled:b||V,children:[V?e.jsx($,{className:"mr-1.5 h-3.5 w-3.5 animate-spin"}):null,l]}),e.jsx(P,{size:"sm",variant:"outline",className:"flex-1",onClick:m,disabled:b||V,children:S})]})]})]})}function Ye({binding:s,isSelected:n,onSelect:t}){return e.jsx("button",{onClick:t,className:fe("w-full rounded-lg border px-3 py-3 text-left transition-colors",n?"border-primary/40 bg-primary/10":"border-border/60 bg-card hover:bg-muted/40"),children:e.jsxs("div",{className:"flex items-start justify-between gap-2",children:[e.jsxs("div",{className:"min-w-0",children:[e.jsx("div",{className:"truncate text-sm font-medium",children:s.name}),e.jsxs("div",{className:"mt-1 text-xs text-muted-foreground",children:[s.profile," · ",s.host]})]}),e.jsx(f,{variant:"outline",className:"shrink-0",children:s.usesDefaultIdeSettingsPath?"Default path":"Custom path"})]})})}function ls(){const{t:s}=q(),n=Ue(),t=Le(),l=$e(),S=Je(),F=Qe(),m=Ke(),b=Me(),V=n.data?.profiles??[],G=n.data?.hosts??[],E=t.data?.bindings??He,ve=V[0]?.name??"default",[je,D]=W.useState(!1),[L,B]=W.useState(null),[X,k]=W.useState(()=>xe("default")),c=je||E.length===0,N=!c&&E.length>0?E.find(a=>a.id===L)??(L?null:E[0]):null,h=N?.id??null,d=c||!N||L?X:T(N),Z=Fe(d.profile,d.host),R=Oe(c?void 0:h||void 0),r=G.find(a=>a.id===d.host),H=V.find(a=>a.name===d.profile),z=n.error||t.error||Z.error||R.error,be=`${E.length} saved`,ee=l.isPending||S.isPending,Ne=m.isPending&&m.variables?.target==="shared"||b.isPending&&b.variables?.target==="shared",ye=m.isPending&&m.variables?.target==="ide"||b.isPending&&b.variables?.target==="ide",se=d.name.trim().length>0&&d.profile.trim().length>0,i=Z.data,u=R.data,ae=Math.max((i?.env.length??0)-6,0),Pe=i?.env.slice(0,6)??[];function _(){D(!0),B(null),k(xe(ve))}async function Se(){if(!se)return;const a=ze(d);if(!c&&h){const O=await S.mutateAsync({id:h,binding:a});D(!1),B(O.binding.id),k(T(O.binding));return}const y=await l.mutateAsync(a);D(!1),B(y.binding.id),k(T(y.binding))}async function Ee(){if(!h||!N||!window.confirm(s("claudeExtensionPage.deleteBindingConfirm",{name:N.name,defaultValue:'Delete binding "{{name}}"?'})))return;await F.mutateAsync(h);const a=E.filter(y=>y.id!==h);a.length>0?(B(a[0].id),D(!1),k(T(a[0]))):_()}function A(a,y){if(!c&&N&&!L){B(N.id),k({...T(N),[a]:y}),D(!1);return}k(O=>({...O,[a]:y}))}function I(a,y){if(h){if(y==="apply"){m.mutate({id:h,target:a});return}b.mutate({id:h,target:a})}}return e.jsxs("div",{className:"flex h-full min-h-0 overflow-hidden",children:[e.jsxs("div",{className:"flex w-[348px] shrink-0 flex-col border-r bg-muted/30 xl:w-[372px]",children:[e.jsx("div",{className:"border-b bg-background p-4",children:e.jsxs("div",{className:"flex items-start justify-between gap-3",children:[e.jsxs("div",{className:"space-y-2",children:[e.jsxs("div",{className:"flex items-center gap-2",children:[e.jsx("div",{className:"rounded-lg border bg-muted/40 p-2",children:e.jsx(De,{className:"h-5 w-5 text-primary"})}),e.jsxs("div",{children:[e.jsx("h1",{className:"font-semibold",children:s("claudeExtensionPage.title")}),e.jsx("p",{className:"text-xs text-muted-foreground",children:s("claudeExtensionPage.savedBindingsSubtitle",{defaultValue:"Saved IDE bindings for CCS profiles"})})]})]}),e.jsxs("div",{className:"flex items-center gap-2",children:[e.jsx(f,{variant:"secondary",children:be}),r?e.jsx(f,{variant:"outline",children:r.label}):null]})]}),e.jsxs(P,{size:"sm",onClick:_,className:"gap-1.5",children:[e.jsx(Be,{className:"h-3.5 w-3.5"}),s("claudeExtensionPage.new",{defaultValue:"New"})]})]})}),e.jsx(te,{className:"flex-1",children:e.jsxs("div",{className:"space-y-4 p-5",children:[e.jsxs(x,{className:"border-border/60 bg-card/80",children:[e.jsxs(p,{children:[e.jsx(v,{className:"text-base",children:c?s("claudeExtensionPage.createBinding",{defaultValue:"Create binding"}):s("claudeExtensionPage.bindingEditor",{defaultValue:"Binding editor"})}),e.jsx(j,{children:s("claudeExtensionPage.bindingEditorDescription",{defaultValue:"Save a profile + IDE path once, then apply or reset it from the dashboard."})})]}),e.jsxs(g,{className:"space-y-4",children:[e.jsxs("div",{className:"space-y-2",children:[e.jsx("div",{className:"text-sm font-medium",children:s("settingsPage.thinkingSection.bindingName")}),e.jsx(Y,{value:d.name,onChange:a=>A("name",a.target.value),placeholder:s("claudeExtensionPage.bindingNamePlaceholder",{defaultValue:"VS Code · work profile"})})]}),e.jsxs("div",{className:"space-y-2",children:[e.jsx("div",{className:"text-sm font-medium",children:s("claudeExtensionPage.ccsProfile",{defaultValue:"CCS profile"})}),e.jsxs(ne,{value:d.profile,onValueChange:a=>A("profile",a),children:[e.jsx(ie,{children:e.jsx(le,{placeholder:s("claudeExtensionPage.selectProfile",{defaultValue:"Select a profile"})})}),e.jsx(de,{children:V.map(a=>e.jsxs(re,{value:a.name,children:[a.label," (",a.profileType,")"]},a.name))})]}),e.jsx("p",{className:"text-xs text-muted-foreground",children:H?.description||s("claudeExtensionPage.chooseProfileHint",{defaultValue:"Choose which CCS profile the IDE should inherit."})})]}),e.jsxs("div",{className:"space-y-2",children:[e.jsx("div",{className:"text-sm font-medium",children:s("settingsPage.thinkingSection.ideHost")}),e.jsxs(ne,{value:d.host,onValueChange:a=>A("host",a),children:[e.jsx(ie,{children:e.jsx(le,{placeholder:s("claudeExtensionPage.selectHost",{defaultValue:"Select a host"})})}),e.jsx(de,{children:G.map(a=>e.jsx(re,{value:a.id,children:a.label},a.id))})]})]}),e.jsxs("div",{className:"space-y-2",children:[e.jsx("div",{className:"text-sm font-medium",children:s("settingsPage.thinkingSection.ideSettingsPath")}),e.jsx(Y,{value:d.ideSettingsPath,onChange:a=>A("ideSettingsPath",a.target.value),placeholder:r?.defaultSettingsPath||s("claudeExtensionPage.ideSettingsPathPlaceholder",{defaultValue:"Leave blank for the default user settings path"})}),e.jsxs("p",{className:"text-xs text-muted-foreground",children:[s("claudeExtensionPage.ideSettingsPathHint",{defaultValue:"Leave blank to use the default user settings path for"})," ",r?.label||"this IDE","."]})]}),e.jsxs("div",{className:"space-y-2",children:[e.jsx("div",{className:"text-sm font-medium",children:s("settingsPage.thinkingSection.notes")}),e.jsx(Y,{value:d.notes,onChange:a=>A("notes",a.target.value),placeholder:s("claudeExtensionPage.notesPlaceholder",{defaultValue:"Optional reminder for this machine or workspace"})})]}),e.jsxs("div",{className:"flex gap-2",children:[e.jsxs(P,{className:"flex-1 gap-1.5",onClick:()=>void Se(),disabled:!se||ee,children:[ee?e.jsx($,{className:"h-3.5 w-3.5 animate-spin"}):e.jsx(Ie,{className:"h-3.5 w-3.5"}),c?s("claudeExtensionPage.create",{defaultValue:"Create"}):s("claudeExtensionPage.save",{defaultValue:"Save"})]}),e.jsx(P,{variant:"outline",onClick:_,children:s("claudeExtensionPage.resetForm",{defaultValue:"Reset form"})})]}),c?null:e.jsxs(P,{variant:"outline",className:"w-full gap-1.5 text-destructive hover:text-destructive",onClick:()=>void Ee(),disabled:F.isPending,children:[e.jsx(Te,{className:"h-3.5 w-3.5"}),s("claudeExtensionPage.deleteBinding",{defaultValue:"Delete binding"})]})]})]}),e.jsxs("div",{className:"space-y-2",children:[e.jsx("div",{className:"px-1 text-xs font-medium uppercase tracking-wide text-muted-foreground",children:s("claudeExtensionPage.savedBindings",{defaultValue:"Saved bindings"})}),e.jsx("div",{className:"space-y-2",children:E.length>0?E.map(a=>e.jsx(Ye,{binding:a,isSelected:a.id===h&&!c,onSelect:()=>{D(!1),B(a.id),k(T(a))}},a.id)):e.jsx(x,{className:"border-dashed border-border/60 bg-card/60",children:e.jsx(g,{className:"pt-6 text-sm text-muted-foreground",children:s("claudeExtensionPage.emptyBindings",{defaultValue:"No saved bindings yet. Create one to manage apply, reset, and drift checks from the dashboard."})})})})]})]})})]}),e.jsx("div",{className:"min-w-0 flex-1",children:e.jsx(te,{className:"h-full",children:e.jsxs("div",{className:"w-full space-y-6 p-6 xl:p-7 2xl:p-8",children:[e.jsxs("div",{className:"flex flex-col gap-3 lg:flex-row lg:items-end lg:justify-between",children:[e.jsxs("div",{className:"space-y-2",children:[e.jsxs("div",{className:"flex flex-wrap items-center gap-2",children:[H?e.jsx(f,{variant:"outline",children:H.label}):null,r?e.jsx(f,{variant:"outline",children:r.label}):null,c?e.jsx(f,{variant:"secondary",children:s("settingsPage.thinkingSection.draft")}):null,u?.sharedSettings&&ge(u.sharedSettings)&&ge(u.ideSettings)?e.jsx(f,{className:"bg-emerald-600 hover:bg-emerald-600",children:s("settingsPage.thinkingSection.inSync")}):null]}),e.jsxs("div",{className:"max-w-5xl",children:[e.jsx("h2",{className:"text-2xl font-semibold tracking-tight",children:N?.name||s("claudeExtensionPage.defaultBindingName",{defaultValue:"Claude extension binding"})}),e.jsx("p",{className:"mt-1 text-sm text-muted-foreground",children:s("claudeExtensionPage.bindingDescription",{defaultValue:"Manage the shared Claude settings file and the IDE-local settings file as two scoped targets."})})]})]}),e.jsxs("div",{className:"flex gap-2",children:[e.jsxs(P,{variant:"outline",onClick:()=>void R.refetch(),disabled:c||R.isFetching,children:[R.isFetching?e.jsx($,{className:"mr-1.5 h-3.5 w-3.5 animate-spin"}):e.jsx(Re,{className:"mr-1.5 h-3.5 w-3.5"}),s("claudeExtensionPage.verify",{defaultValue:"Verify"})]}),i?e.jsx(J,{value:i.sharedSettings.command,label:"Copy persist command"}):null]})]}),z?e.jsx(x,{className:"border-destructive/40 bg-destructive/5",children:e.jsxs(g,{className:"flex items-start gap-3 pt-6 text-sm text-destructive",children:[e.jsx(ue,{className:"mt-0.5 h-4 w-4 shrink-0"}),e.jsx("div",{children:z.message})]})}):null,z?null:e.jsxs(we,{defaultValue:"overview",className:"flex flex-col gap-6",children:[e.jsxs(Ve,{className:"w-full justify-start",children:[e.jsx(oe,{value:"overview",children:s("claudeExtensionPage.overview",{defaultValue:"Overview"})})," ",e.jsx(oe,{value:"advanced",children:s("settingsPage.thinkingSection.advanced")})]}),e.jsxs(ce,{value:"overview",className:"mt-0 space-y-6",children:[e.jsxs("div",{className:"grid gap-6 xl:grid-cols-2",children:[e.jsx(he,{title:s("claudeExtensionPage.sharedClaudeSettings",{defaultValue:"Shared Claude settings"}),description:s("claudeExtensionPage.sharedClaudeSettingsDescription",{defaultValue:"Writes the managed env block inside ~/.claude/settings.json so CLI and IDE behavior stay aligned."}),status:u?.sharedSettings,applyLabel:s("claudeExtensionPage.applyShared",{defaultValue:"Apply shared"}),resetLabel:s("claudeExtensionPage.resetShared",{defaultValue:"Reset shared"}),onApply:()=>I("shared","apply"),onReset:()=>I("shared","reset"),disabled:c,busy:Ne}),e.jsx(he,{title:`${r?.label||"IDE"} settings.json`,description:"Writes only the Anthropic extension keys so unrelated editor preferences stay untouched.",status:u?.ideSettings,applyLabel:s("claudeExtensionPage.applyIde",{defaultValue:"Apply IDE"}),resetLabel:s("claudeExtensionPage.resetIde",{defaultValue:"Reset IDE"}),onApply:()=>I("ide","apply"),onReset:()=>I("ide","reset"),disabled:c,busy:ye})]}),e.jsxs("div",{className:"grid gap-6 xl:grid-cols-[minmax(0,1.15fr)_minmax(320px,0.85fr)]",children:[e.jsxs(x,{className:"border-border/60 bg-card/80",children:[e.jsxs(p,{children:[e.jsx(v,{className:"text-base",children:s("settingsPage.thinkingSection.resolvedBinding")}),e.jsx(j,{children:s("claudeExtensionPage.resolvedBindingDescription",{defaultValue:"The binding uses the same profile resolution as `ccs persist` and `ccs env`."})})]}),e.jsxs(g,{className:"space-y-3",children:[e.jsx(o,{label:s("claudeExtensionPage.profile",{defaultValue:"Profile"}),value:i?.profile.label||d.profile||"Not selected"}),e.jsx(o,{label:s("claudeExtensionPage.profileType",{defaultValue:"Profile type"}),value:i?.profile.profileType||"Unknown"}),e.jsx(o,{label:"IDE host",value:r?.label||"Not selected"}),e.jsx(o,{label:s("claudeExtensionPage.idePathMode",{defaultValue:"IDE path mode"}),value:d.ideSettingsPath.trim()?s("claudeExtensionPage.customPath",{defaultValue:"Custom path"}):s("claudeExtensionPage.defaultUserPath",{defaultValue:"Default user path"})}),e.jsx(o,{label:s("claudeExtensionPage.effectiveIdePath",{defaultValue:"Effective IDE path"}),value:u?.ideSettings.path||d.ideSettingsPath.trim()||r?.defaultSettingsPath||"Unavailable",mono:!0,copyValue:u?.ideSettings.path||d.ideSettingsPath.trim()||r?.defaultSettingsPath}),e.jsx(o,{label:s("claudeExtensionPage.persistCommand",{defaultValue:"Persist command"}),value:i?.sharedSettings.command||s("claudeExtensionPage.saveValidBindingFirst",{defaultValue:"Save a valid binding first"}),mono:!0}),d.notes.trim()?e.jsx(o,{label:s("settingsPage.thinkingSection.notes"),value:d.notes.trim()}):null]})]}),e.jsxs(x,{className:"border-border/60 bg-card/80",children:[e.jsxs(p,{children:[e.jsx(v,{className:"text-base",children:s("settingsPage.thinkingSection.managedPayload")}),e.jsx(j,{children:s("claudeExtensionPage.managedPayloadDescription",{defaultValue:"Keep the main view short. The full JSON stays in the Advanced tab."})})]}),e.jsxs(g,{className:"space-y-4",children:[e.jsxs("div",{className:"flex flex-wrap gap-2",children:[Pe.map(a=>e.jsx(f,{variant:"secondary",className:"font-mono text-[10px]",children:a.name},a.name)),ae>0?e.jsxs(f,{variant:"outline",children:["+",ae," more"]}):null]}),e.jsx("div",{className:"rounded-lg border bg-muted/25 p-4 text-sm",children:i?.env.length?e.jsxs("div",{className:"space-y-2",children:[e.jsx("div",{className:"font-medium",children:s("claudeExtensionPage.envInjected",{count:i.env.length,defaultValue:"CCS will inject {{count}} environment values."})}),e.jsx("div",{className:"text-muted-foreground",children:s("claudeExtensionPage.envInjectedDescription",{defaultValue:"The IDE-local target receives the extension schema. The shared target receives the same env block through Claude settings."})})]}):e.jsx("div",{className:"text-muted-foreground",children:s("claudeExtensionPage.nativeDefaultsDescription",{defaultValue:"This profile resolves to native Claude defaults, so apply/reset mainly clears existing CCS-managed overrides."})})}),c?e.jsx("div",{className:"rounded-lg border border-dashed bg-muted/15 p-4 text-sm text-muted-foreground",children:s("claudeExtensionPage.saveDraftToUnlock",{defaultValue:"Save this draft to unlock apply, reset, and verify actions."})}):e.jsxs("div",{className:"flex gap-2",children:[e.jsxs(P,{className:"flex-1",onClick:()=>I("all","apply"),disabled:m.isPending,children:[m.isPending&&m.variables?.target==="all"?e.jsx($,{className:"mr-1.5 h-3.5 w-3.5 animate-spin"}):null,s("claudeExtensionPage.applyBothTargets",{defaultValue:"Apply both targets"})]}),e.jsx(P,{variant:"outline",className:"flex-1",onClick:()=>I("all","reset"),disabled:b.isPending,children:s("claudeExtensionPage.resetBothTargets",{defaultValue:"Reset both targets"})})]})]})]})]}),i&&(i.warnings.length>0||i.notes.length>0)?e.jsxs("div",{className:"grid gap-6 xl:grid-cols-2",children:[e.jsxs(x,{className:"border-border/60 bg-card/80",children:[e.jsxs(p,{children:[e.jsx(v,{className:"text-base",children:s("settingsPage.thinkingSection.warnings")}),e.jsx(j,{children:"Operational details that can break the binding even when JSON is correct."})]}),e.jsx(g,{className:"space-y-3",children:i.warnings.length>0?i.warnings.map(a=>e.jsxs("div",{className:"flex items-start gap-3 rounded-lg border border-amber-400/40 bg-amber-50/60 p-3 text-sm dark:bg-amber-950/10",children:[e.jsx(ue,{className:"mt-0.5 h-4 w-4 shrink-0 text-amber-600"}),e.jsx("span",{children:a})]},a)):e.jsx("div",{className:"rounded-lg border bg-muted/20 p-3 text-sm text-muted-foreground",children:"No runtime warnings for this binding."})})]}),e.jsxs(x,{className:"border-border/60 bg-card/80",children:[e.jsxs(p,{children:[e.jsx(v,{className:"text-base",children:s("settingsPage.thinkingSection.notes")}),e.jsx(j,{children:"Short context from CCS about account continuity and host-specific behavior."})]}),e.jsx(g,{className:"space-y-3",children:i.notes.length>0?i.notes.map(a=>e.jsxs("div",{className:"flex items-start gap-3 rounded-lg border bg-muted/30 p-3 text-sm",children:[e.jsx(Ae,{className:"mt-0.5 h-4 w-4 shrink-0 text-muted-foreground"}),e.jsx("span",{children:a})]},a)):e.jsx("div",{className:"rounded-lg border bg-muted/20 p-3 text-sm text-muted-foreground",children:"No extra notes for this binding."})})]})]}):null]}),e.jsx(ce,{value:"advanced",className:"mt-0 space-y-6",children:i?e.jsxs(e.Fragment,{children:[e.jsxs("div",{className:"grid gap-6 xl:grid-cols-2",children:[e.jsx(me,{title:s("claudeExtensionPage.sharedSettingsJson",{defaultValue:"Shared Claude settings JSON"}),description:s("claudeExtensionPage.sharedSettingsJsonDescription",{defaultValue:"Managed env block for ~/.claude/settings.json."}),value:i.sharedSettings.json}),e.jsx(me,{title:`${r?.label||"IDE"} settings JSON`,description:s("claudeExtensionPage.ideSettingsJsonDescription",{label:r?.settingsTargetLabel||"settings.json",defaultValue:"Anthropic extension snippet for {{label}}."}),value:i.ideSettings.json})]}),e.jsxs(x,{className:"border-border/60 bg-card/80",children:[e.jsx(p,{children:e.jsxs("div",{className:"flex items-start justify-between gap-3",children:[e.jsxs("div",{children:[e.jsx(v,{className:"text-base",children:s("claudeExtensionPage.resolvedEnvironmentPayload",{defaultValue:"Resolved environment payload"})}),e.jsx(j,{children:s("claudeExtensionPage.resolvedEnvironmentPayloadDescription",{defaultValue:"Exact environment values that the extension receives after CCS expands this profile."})})]}),e.jsx(J,{value:JSON.stringify(i.env,null,2),label:s("claudeExtensionPage.copyEnvironmentPayload",{defaultValue:"Copy environment payload"})})]})}),e.jsx(g,{children:i.env.length>0?e.jsx("pre",{className:"max-h-[420px] overflow-auto rounded-lg border bg-muted/30 p-4 text-xs leading-6",children:JSON.stringify(i.env,null,2)}):e.jsx("div",{className:"rounded-lg border bg-muted/20 p-4 text-sm text-muted-foreground",children:"No env payload. This binding resolves to native Claude defaults."})})]}),e.jsxs("div",{className:"grid gap-6 xl:grid-cols-2",children:[e.jsxs(x,{className:"border-border/60 bg-card/80",children:[e.jsxs(p,{children:[e.jsx(v,{className:"text-base",children:"Shared target metadata"}),e.jsx(j,{children:"Useful when debugging drift or comparing with manual edits."})]}),e.jsxs(g,{className:"space-y-3",children:[e.jsx(o,{label:"Target path",value:u?.sharedSettings.path||i.sharedSettings.path,mono:!0,copyValue:u?.sharedSettings.path||i.sharedSettings.path}),e.jsx(o,{label:"Command",value:i.sharedSettings.command,mono:!0}),e.jsx(o,{label:"Current state",value:u?.sharedSettings.state||"Not verified"})]})]}),e.jsxs(x,{className:"border-border/60 bg-card/80",children:[e.jsxs(p,{children:[e.jsx(v,{className:"text-base",children:"IDE target metadata"}),e.jsx(j,{children:"Current file path plus the extension setting key used for this host."})]}),e.jsxs(g,{className:"space-y-3",children:[e.jsx(o,{label:"Target path",value:u?.ideSettings.path||d.ideSettingsPath.trim()||r?.defaultSettingsPath||i.ideSettings.path,mono:!0,copyValue:u?.ideSettings.path||d.ideSettingsPath.trim()||r?.defaultSettingsPath||i.ideSettings.path}),e.jsx(o,{label:"Settings key",value:r?.settingsKey||"Unknown",mono:!0}),e.jsx(o,{label:"Current state",value:u?.ideSettings.state||"Not verified"})]})]})]})]}):e.jsx(x,{className:"border-border/60 bg-card/80",children:e.jsxs(g,{className:"flex min-h-[240px] items-center justify-center gap-3 text-sm text-muted-foreground",children:[e.jsx(qe,{className:"h-5 w-5"}),"Choose a profile and IDE host to preview the generated payload."]})})})]})]})})})]})}export{ls as ClaudeExtensionPage};
@@ -0,0 +1,4 @@
1
+ import{j as e}from"./radix-ui-nu4wz29m.js";import{r as c}from"./react-vendor-Bjx91N7w.js";import{a as wt,u as ss,b as Is}from"./tanstack-bhJxV1h8.js";import{a9 as Ts,a as W,e as U,C as as,b as ns,aa as rs,ab as is,c as X,P as kt,B as z,ac as xe,L as ee,I as ce,j as $e,k as We,l as Qe,m as Je,n as Se,ad as os,ae as ls,af as Es,ag as Rs,ah as Os,u as ds,ai as Ct,aj as At,ak as St,al as Mt,Y as he,am as cs,an as Ht,ao as _s,ap as Ls,aq as Re,ar as us,_ as Xe,as as Fs,at as qt,au as zt,av as Us,aw as Ks,ax as Hs,ay as qs,az as zs,aA as Gs,aB as Bs,aC as Vs,aD as Gt,aE as $s,z as ms,aF as Ws,x as Pt,aG as Qs,aH as Dt,aI as Bt,aJ as ps,aK as Js,w as Xs,aL as Ys,aM as Zs,T as ft,o as gt,p as vt,q as jt,aN as ea,aO as ta,aP as sa,aQ as ct,aR as aa,aS as na,aT as ra,aU as ia,aV as oa,aW as la,U as da,V as ca,W as Vt,X as $t,aX as ua,aY as ma,aZ as pa,a_ as xa,a$ as ha,b0 as fa,b1 as ga,b2 as va,b3 as ja,b4 as ba,b5 as Na,b6 as ze,b7 as ya,S as wa}from"./index-sIfjKy42.js";import{C as bt}from"./default-ports-1QQSffYX.js";import{t as B}from"./notifications-B4_o8bcr.js";import{C as xs,L as ue,p as Me,$ as ka,m as Pe,o as hs,aG as It,R as at,q as Oe,aa as Tt,T as et,a7 as Wt,aH as fs,aF as Ca,z as Et,Z as _e,_ as gs,i as Aa,u as vs,aI as Sa,au as Ma,X as Rt,a9 as nt,J as js,D as bs,aJ as Pa,at as Ns,aK as Da,ax as Ia,aL as tt}from"./icons-DzKUh8vG.js";import{R as Ye,A as Qt,D as ut,i as Ta,a as Ea}from"./antigravity-responsibility-constants-Bvh4Ybz0.js";import{C as Ze}from"./checkbox-Bt-F3GmI.js";import{C as Ra}from"./confirm-dialog-CYvBJC0z.js";import{S as Ot}from"./separator-BvoSJCHW.js";import{S as Oa}from"./searchable-select-D2smFEI5.js";import{P as _a}from"./proxy-status-widget-Dm2ziI5D.js";import"./utils-CzKF5WmX.js";import"./form-utils-CuHzLhJZ.js";import"./charts-eIPy2oG6.js";import"./alert-dialog-D0yey0YJ.js";import"./Trans-BIQ-yfAc.js";const ne="gemini-3.1-pro-high",Ie="gemini-3.1-pro-low",La=Object.freeze({"gemini-3-pro-high":ne,"gemini-3.1-pro-high":ne,"gemini-3-pro-low":Ie,"gemini-3.1-pro-low":Ie,"gemini-3-pro-preview":ne,"gemini-3-pro-preview-customtools":ne,"gemini-3.1-pro-preview":ne,"gemini-3.1-pro-preview-customtools":ne,"gemini-3-1-pro-preview":ne,"gemini-3-1-pro-preview-customtools":ne}),ys=Object.freeze({"gemini-3-pro-preview":"gemini-3.1-pro-preview","gemini-3.1-pro-preview":"gemini-3-pro-preview","gemini-3-flash-preview":"gemini-3.1-flash-preview","gemini-3.1-flash-preview":"gemini-3-flash-preview"}),Fa=/^gemini-(\d+(?:[.-]\d+)*)-(pro|flash)-preview(-customtools)?$/i,Ua=["agy/","gcli/"];function J(t){return Ts(t).toLowerCase()}function Ka(t){const a=t.trim(),s=a.toLowerCase();for(const n of Ua)if(s.startsWith(n))return a.slice(n.length);return a}function Ha(t){return t.replace(/-customtools$/i,"")}function qa(t){return La[J(t)]}function st(t){const a=J(t),s=a.match(Fa);if(!s)return null;const[,n,r,o]=s;return{normalizedId:a,version:n.split(/[.-]/).map(l=>Number(l)),family:r,customtools:!!o,dottedVersion:n.includes(".")}}function ws(t,a){const s=Math.max(t.length,a.length);for(let n=0;n<s;n+=1){const r=t[n]??0,o=a[n]??0;if(r!==o)return r>o?1:-1}return 0}function za(t,a,s){if(t.customtools!==a.customtools)return t.customtools?1:-1;const n=ws(t.version,a.version);if(n!==0)return n>0?-1:1;const r=+(t.dottedVersion===s.dottedVersion),o=+(a.dottedVersion===s.dottedVersion);return r!==o?o-r:t.normalizedId.localeCompare(a.normalizedId)}function Jt(t,a){const s=J(a);return t.find(n=>J(n.id)===s)?.id}function Ga(t,a){const s=st(t);return!s||a.length===0?void 0:a.map(r=>{const o=st(r.id);return!o||o.family!==s.family?null:{id:r.id,info:o}}).filter(r=>!!r).sort((r,o)=>za(r.info,o.info,s))[0]?.id}const je={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:ne,name:"Gemini Pro High",description:"Current Antigravity Gemini Pro route with higher reasoning budget",extendedContext:!0,presetMapping:{default:ne,opus:ne,sonnet:ne,haiku:"gemini-3-1-flash-preview"}},{id:Ie,name:"Gemini Pro Low",description:"Current Antigravity Gemini Pro route with the lighter quota tier",extendedContext:!0,presetMapping:{default:Ie,opus:Ie,sonnet:Ie,haiku:"gemini-3-1-flash-preview"}},{id:"gemini-3-1-flash-preview",name:"Gemini Flash",description:"Resolves to the best advertised Gemini Flash preview via Antigravity",extendedContext:!0,presetMapping:{default:"gemini-3-1-flash-preview",opus:ne,sonnet:ne,haiku:"gemini-3-1-flash-preview"}}]},gemini:{provider:"gemini",displayName:"Gemini",defaultModel:"gemini-2.5-pro",models:[{id:"gemini-3.1-pro-preview",name:"Gemini Pro",tier:"paid",description:"Uses the best advertised Gemini Pro preview when Google exposes one",extendedContext:!0,presetMapping:{default:"gemini-3.1-pro-preview",opus:"gemini-3.1-pro-preview",sonnet:"gemini-3.1-pro-preview",haiku:"gemini-3-flash-preview"}},{id:"gemini-3-flash-preview",name:"Gemini Flash",tier:"paid",description:"Uses the best advertised Gemini Flash preview when Google exposes one",extendedContext:!0,presetMapping:{default:"gemini-3-flash-preview",opus:"gemini-3.1-pro-preview",sonnet:"gemini-3.1-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.4",models:[{id:"gpt-5.5",name:"GPT-5.5",tier:"paid",description:"Newest Codex-released GPT-5 family model; falls back to GPT-5.4 on free plans",codexMaxEffort:"xhigh",codexServiceTiers:["fast"],presetMapping:{default:"gpt-5.5",opus:"gpt-5.5",sonnet:"gpt-5.5",haiku:"gpt-5.4-mini"}},{id:"gpt-5.4",name:"GPT-5.4",description:"Recommended Codex default for most coding and agentic tasks",codexMaxEffort:"xhigh",codexServiceTiers:["fast"],presetMapping:{default:"gpt-5.4",opus:"gpt-5.4",sonnet:"gpt-5.4",haiku:"gpt-5.4-mini"}},{id:"gpt-5.4-mini",name:"GPT-5.4 Mini",description:"Fast, lower-cost Codex option for lighter tasks and haiku-tier routing",codexMaxEffort:"high",presetMapping:{default:"gpt-5.4-mini",opus:"gpt-5.4",sonnet:"gpt-5.4",haiku:"gpt-5.4-mini"}},{id:"gpt-5.3-codex",name:"GPT-5.3 Codex",tier:"paid",description:"Previous flagship coding model whose capabilities now power GPT-5.4",codexMaxEffort:"xhigh",presetMapping:{default:"gpt-5.3-codex",opus:"gpt-5.3-codex",sonnet:"gpt-5.3-codex",haiku:"gpt-5.4-mini"}},{id:"gpt-5.3-codex-spark",name:"GPT-5.3 Codex Spark",tier:"paid",description:"Research preview model for ChatGPT Pro subscribers, optimized for near-instant coding iteration",codexMaxEffort:"xhigh",presetMapping:{default:"gpt-5.3-codex-spark",opus:"gpt-5.3-codex",sonnet:"gpt-5.3-codex",haiku:"gpt-5.4-mini"}},{id:"gpt-5.2",name:"GPT-5.2",description:"Previous general-purpose Codex model",codexMaxEffort:"xhigh",presetMapping:{default:"gpt-5.2",opus:"gpt-5.2",sonnet:"gpt-5.2",haiku:"gpt-5.4-mini"}}]},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-6",models:[{id:"kiro-claude-opus-4-6",name:"Kiro Claude Opus 4.6",description:"Claude Opus 4.6 via Kiro (2.2x credit)",presetMapping:{default:"kiro-claude-opus-4-6",opus:"kiro-claude-opus-4-6",sonnet:"kiro-claude-sonnet-4-6",haiku:"kiro-claude-haiku-4-5"}},{id:"kiro-claude-sonnet-4-6",name:"Kiro Claude Sonnet 4.6",description:"Claude Sonnet 4.6 via Kiro (1.3x credit)",presetMapping:{default:"kiro-claude-sonnet-4-6",opus:"kiro-claude-opus-4-6",sonnet:"kiro-claude-sonnet-4-6",haiku:"kiro-claude-haiku-4-5"}},{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-6",models:[{id:"claude-opus-4-7",name:"Claude Opus 4.7",description:"Latest flagship model",extendedContext:!0,presetMapping:{default:"claude-opus-4-7",opus:"claude-opus-4-7",sonnet:"claude-sonnet-4-6",haiku:"claude-haiku-4-5-20251001"}},{id:"claude-opus-4-6",name:"Claude Opus 4.6",description:"Previous flagship model",extendedContext:!0,presetMapping:{default:"claude-opus-4-6",opus:"claude-opus-4-6",sonnet:"claude-sonnet-4-6",haiku:"claude-haiku-4-5-20251001"}},{id:"claude-sonnet-4-6",name:"Claude Sonnet 4.6",description:"Balanced performance and speed",extendedContext:!0,presetMapping:{default:"claude-sonnet-4-6",opus:"claude-opus-4-6",sonnet:"claude-sonnet-4-6",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"}]}};function Ee(t,a){if(!t)return;const s=J(a);if(t.provider==="agy"){const l=qa(s);if(l){const d=t.models.find(i=>i.id===l);if(d)return d}}const n=ys[s.toLowerCase()],r=t.models.find(l=>l.id===s||l.id===n);if(r)return r;const o=st(s);if(o)return t.models.map(l=>({model:l,info:st(l.id)})).filter(l=>!!(l.info&&l.info.family===o.family)).sort((l,d)=>ws(d.info.version,l.info.version))[0]?.model}function Ba(t){if(t==="free")return"free";if(typeof t=="string"&&t.trim().length>0)return"paid"}function Va(t,a){const s=je[t.toLowerCase()];if(!a||a.models.length===0)return s;const n=a.models.map(d=>({id:d.id,owned_by:a.provider})),r=a.models.map(d=>{const i=Ee(s,d.id);return{...d,name:d.name||i?.name||d.id,tier:i?.tier??Ba(d.tier),description:d.description??i?.description,broken:i?.broken,issueUrl:i?.issueUrl,deprecated:i?.deprecated,deprecationReason:i?.deprecationReason,extendedContext:d.extendedContext??i?.extendedContext,presetMapping:i?.presetMapping}}),o=s?.defaultModel?Te(s.defaultModel,n):void 0,l=typeof o=="string"&&n.some(d=>J(d.id)===J(o));return{provider:a.provider,displayName:a.displayName||s?.displayName||t,defaultModel:l?o:a.defaultModel,models:r}}function _t(t){const a={},s=new Set([...Object.keys(je),...Object.keys(t??{})]);for(const n of s){const r=Va(n,t?.[n]);r&&(a[n]=r)}return a}function ks(t,a,s){const n=Ee(s,a);return n||Ee(je[t.toLowerCase()],a)}function Te(t,a=[]){const s=J(t),n=Ga(s,a);if(n)return n;const r=Jt(a,s);if(r)return r;const o=ys[s];return(o?Jt(a,o):void 0)??s}function $a(t,a=[]){return{default:Te(t.default,a),opus:Te(t.opus,a),sonnet:Te(t.sonnet,a),haiku:Te(t.haiku,a)}}function Lt(t,a=[]){if(!t)return[];const s=je[t.provider.toLowerCase()]??t,n=new Set;return s.models.map(r=>{const o=Te(r.id,a),l=r.presetMapping?$a(r.presetMapping,a):void 0,d=t.models.find(i=>J(i.id)===J(o));return{...r,id:o,name:d?.name||r.name,description:d?.description??r.description,presetMapping:l}}).filter(r=>n.has(r.id)?!1:(n.add(r.id),!0))}function Wa(t,a,s=[]){const n=t.trim().toLowerCase();if(!a||!n)return[];const r=je[n]??a,o=Lt(a,s),l=new Set(o.map(m=>J(m.id))),d=new Set(o.map(m=>Ee(r,m.id)?.id).filter(m=>!!m).map(m=>J(m))),i=new Set,p=new Set(s.map(m=>J(m.id)));return s.filter(m=>{const v=J(m.id),x=Ka(m.id),b=Ha(x),N=Ee(r,x)??Ee(r,b);if(l.has(J(x))||v!==J(x)&&p.has(J(x)))return!1;const C=J(b);if(C!==J(x)&&p.has(C))return!1;const T=N?J(N.id):C;return N&&d.has(T)||i.has(T)||!N&&n==="agy"?!1:(i.add(T),!0)})}function Qa(t,a,s){return ks(t,a,s)?.extendedContext===!0}const mt="ccs-internal-managed";async function Ja(){try{const t=await fetch("/api/settings/auth/tokens/raw");return t.ok?(await t.json())?.apiKey?.value??mt:mt}catch{return mt}}async function Xa(t,a){if(a)return a;try{const s=await fetch("/api/cliproxy/catalog");if(!s.ok)return je[t];const n=await s.json();return _t(n.catalogs)[t]??je[t]}catch{return je[t]}}async function Nt(t,a,s){const n=await Xa(t,s);if(!n)return{success:!1};const r=n.models.find(p=>p.id===n.defaultModel)||n.models[0],o=r?.presetMapping||{default:n.defaultModel,opus:n.defaultModel,sonnet:n.defaultModel,haiku:n.defaultModel},l=await Ja(),i={env:{ANTHROPIC_BASE_URL:`http://127.0.0.1:${bt}/api/provider/${t}`,ANTHROPIC_AUTH_TOKEN:l,ANTHROPIC_MODEL:o.default,ANTHROPIC_DEFAULT_OPUS_MODEL:o.opus,ANTHROPIC_DEFAULT_SONNET_MODEL:o.sonnet,ANTHROPIC_DEFAULT_HAIKU_MODEL:o.haiku}};try{return{success:(await fetch(`/api/settings/${t}`,{method:"PUT",headers:{"Content-Type":"application/json"},body:JSON.stringify({settings:i})})).ok,presetName:r?.name||n.defaultModel}}catch{return{success:!1}}}function Ya({currentProgress:t,allSteps:a}){return e.jsx("div",{className:"flex justify-center gap-1 pt-2",children:a.map((s,n)=>e.jsx("div",{className:`w-2 h-2 rounded-full transition-colors ${t>=n?"bg-primary":"bg-muted"}`},s))})}function Za({providers:t,onSelect:a}){return e.jsx("div",{className:"grid gap-2",children:t.map(s=>e.jsxs("button",{onClick:()=>a(s.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:s.name}),e.jsx("div",{className:"text-xs text-muted-foreground",children:s.description})]}),e.jsx(xs,{className:"w-4 h-4 text-muted-foreground"})]},s.id))})}function en({selectedProvider:t,providers:a,authCommand:s,isRefreshing:n,isPending:r,onBack:o,onStartAuth:l,onRefresh:d}){const{t:i}=W(),[p,m]=c.useState(!1),v=async x=>{await navigator.clipboard.writeText(x),m(!0),setTimeout(()=>m(!1),2e3)};return e.jsxs("div",{className:"space-y-4",children:[e.jsxs("div",{className:"text-center space-y-3",children:[e.jsx("p",{className:"text-sm text-muted-foreground",children:i("setupWizard.authStep.authenticateWith",{provider:a.find(x=>x.id===t)?.name})}),e.jsx(U,{onClick:l,disabled:r,className:"w-full gap-2",size:"lg",children:r?e.jsxs(e.Fragment,{children:[e.jsx(ue,{className:"w-4 h-4 animate-spin"}),i("setupWizard.authStep.authenticating")]}):e.jsxs(e.Fragment,{children:[e.jsx(Me,{className:"w-4 h-4"}),i("setupWizard.authStep.authenticateInBrowser")]})}),r&&e.jsx("p",{className:"text-xs text-muted-foreground",children:i("setupWizard.authStep.completeOAuth")})]}),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:i("setupWizard.authStep.orUseTerminal")})})]}),e.jsx(as,{children:e.jsxs(ns,{className:"p-4 space-y-3",children:[e.jsxs("div",{className:"flex items-center gap-2 text-sm text-muted-foreground",children:[e.jsx(ka,{className:"w-4 h-4"}),i("setupWizard.authStep.runCommandHint")]}),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:s}),e.jsx(U,{variant:"outline",size:"icon",onClick:()=>v(s),children:p?e.jsx(Pe,{className:"w-4 h-4 text-green-500"}):e.jsx(hs,{className:"w-4 h-4"})})]})]})}),e.jsxs("div",{className:"flex items-center justify-between",children:[e.jsxs(U,{variant:"ghost",onClick:o,disabled:r,children:[e.jsx(It,{className:"w-4 h-4 mr-2"}),i("setupWizard.authStep.back")]}),e.jsxs(U,{variant:"outline",onClick:d,disabled:n||r,children:[e.jsx(at,{className:`w-4 h-4 mr-2 ${n?"animate-spin":""}`}),i(n?"setupWizard.authStep.checking":"setupWizard.authStep.refreshStatus")]})]})]})}function tn({accounts:t,privacyMode:a,onSelect:s,onAddNew:n,onBack:r}){const{t:o}=W();return e.jsxs("div",{className:"space-y-4",children:[e.jsx("div",{className:"text-xs font-medium text-muted-foreground uppercase tracking-wide",children:o("setupWizard.accountStep.selectAccount",{count:t.length})}),e.jsx("div",{className:"grid gap-2 max-h-[320px] overflow-y-auto pr-1",children:t.map(l=>{const d=rs(l.id,l.email,l.tokenFile),i=l.provider?.toLowerCase()==="codex"?is(d):null;return e.jsxs("button",{type:"button",onClick:()=>s(l),className:"flex items-center justify-between p-3 border rounded-lg hover:bg-muted/50 transition-colors text-left",children:[e.jsxs("div",{className:"flex items-center gap-3",children:[e.jsx("div",{className:"w-8 h-8 rounded-full bg-muted flex items-center justify-center",children:e.jsx(Oe,{className:"w-4 h-4 text-muted-foreground"})}),e.jsxs("div",{className:"space-y-1",children:[e.jsx("div",{className:X("font-medium",a&&kt),children:d.email}),e.jsxs("div",{className:"flex items-center gap-1.5 flex-wrap",children:[i?.label?e.jsx(z,{variant:"outline",className:X("text-[10px] h-4 px-1.5 border-transparent",i.audience==="business"?"bg-sky-500/12 text-sky-700 dark:text-sky-300":i.audience==="free"?"bg-slate-200/70 text-slate-700 dark:bg-slate-700/40 dark:text-slate-200":"bg-emerald-500/12 text-emerald-700 dark:text-emerald-300"),children:i.label}):d.audienceLabel?e.jsx(z,{variant:"outline",className:X("text-[10px] h-4 px-1.5 border-transparent",d.audience==="business"?"bg-sky-500/12 text-sky-700 dark:text-sky-300":d.audience==="free"?"bg-slate-200/70 text-slate-700 dark:bg-slate-700/40 dark:text-slate-200":"bg-emerald-500/12 text-emerald-700 dark:text-emerald-300"),children:d.audienceLabel}):null,!i?.label&&d.detailLabel&&e.jsx(z,{variant:"outline",className:"text-[10px] h-4 px-1.5",children:d.detailLabel}),l.isDefault&&e.jsx("span",{className:"text-xs text-muted-foreground",children:o("setupWizard.accountStep.defaultAccount")})]})]})]}),e.jsx(xs,{className:"w-4 h-4 text-muted-foreground"})]},l.id)})}),e.jsxs("div",{className:"relative",children:[e.jsx("div",{className:"absolute inset-0 flex items-center",children:e.jsx("span",{className:"w-full border-t"})}),e.jsx("div",{className:"relative flex justify-center text-xs uppercase",children:e.jsx("span",{className:"bg-background px-2 text-muted-foreground",children:o("setupWizard.accountStep.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(Me,{className:"w-4 h-4 text-primary"})}),e.jsxs("div",{children:[e.jsx("div",{className:"font-medium text-primary",children:o("setupWizard.accountStep.addNewAccount")}),e.jsx("div",{className:"text-xs text-muted-foreground",children:o("setupWizard.accountStep.addNewAccountDesc")})]})]}),e.jsx("div",{className:"flex items-center justify-between pt-2",children:e.jsxs(U,{variant:"ghost",onClick:r,children:[e.jsx(It,{className:"w-4 h-4 mr-2"}),o("setupWizard.accountStep.back")]})})]})}const Xt="__custom__";function sn({selectedProvider:t,catalog:a,selectedAccount:s,variantName:n,modelName:r,isPending:o,privacyMode:l,onVariantNameChange:d,onModelChange:i,onBack:p,onSkip:m,onCreate:v}){const{t:x}=W(),b=a||je[t],N=b?.models||[],C=r&&!N.some(g=>g.id===r),[T,M]=c.useState(C),S=t==="agy"&&r.trim().length>0?xe(r):!1,w=s?rs(s.id,s.email,s.tokenFile):null,y=t==="codex"&&w?is(w):null,h=g=>{g===Xt?(M(!0),i("")):(M(!1),i(g))};return e.jsxs("div",{className:"space-y-4",children:[s&&e.jsxs("div",{className:"flex min-w-0 items-start gap-2 rounded-md bg-muted/50 p-2 text-sm",children:[e.jsx(Oe,{className:"w-4 h-4 shrink-0"}),e.jsxs("div",{className:"min-w-0 space-y-1",children:[e.jsxs("span",{children:[x("setupVariant.using")," ",e.jsx("span",{className:X("break-all",l&&kt),children:w?.email})]}),(w?.audienceLabel||w?.detailLabel)&&e.jsxs("div",{className:"flex items-center gap-1.5 flex-wrap",children:[y?.label?e.jsx(z,{variant:"outline",className:X("text-[10px] h-4 px-1.5 border-transparent",y.audience==="business"?"bg-sky-500/12 text-sky-700 dark:text-sky-300":y.audience==="free"?"bg-slate-200/70 text-slate-700 dark:bg-slate-700/40 dark:text-slate-200":"bg-emerald-500/12 text-emerald-700 dark:text-emerald-300"),children:y.label}):w?.audienceLabel?e.jsx(z,{variant:"outline",className:X("text-[10px] h-4 px-1.5 border-transparent",w.audience==="business"?"bg-sky-500/12 text-sky-700 dark:text-sky-300":w.audience==="free"?"bg-slate-200/70 text-slate-700 dark:bg-slate-700/40 dark:text-slate-200":"bg-emerald-500/12 text-emerald-700 dark:text-emerald-300"),children:w.audienceLabel}):null,!y?.label&&w?.detailLabel&&e.jsx(z,{variant:"outline",className:"text-[10px] h-4 px-1.5",children:w.detailLabel})]})]})]}),e.jsxs("div",{className:"space-y-2",children:[e.jsx(ee,{htmlFor:"variant-name",children:x("setupVariant.variantNameRequired")}),e.jsx(ce,{id:"variant-name",value:n,onChange:g=>d(g.target.value),placeholder:x("setupVariant.variantNamePlaceholder")}),e.jsxs("div",{className:"text-xs text-muted-foreground",children:[x("setupVariant.invokeHintPrefix")," ccs ",n||"<name>",' "prompt"']})]}),e.jsxs("div",{className:"space-y-2",children:[e.jsx(ee,{children:x("setupVariant.model")}),T?e.jsxs("div",{className:"space-y-2",children:[e.jsx(ce,{value:r,onChange:g=>i(g.target.value),placeholder:x("setupVariant.modelPlaceholder")}),S&&e.jsx("p",{className:"text-xs text-destructive",children:x("providerEditor.agyDenylist")}),e.jsx("button",{type:"button",className:"text-xs text-primary hover:underline",onClick:()=>{M(!1),t==="agy"&&xe(r)&&i("")},children:x("setupVariant.choosePresetInstead")})]}):e.jsxs($e,{value:N.some(g=>g.id===r)?r:"",onValueChange:h,children:[e.jsx(We,{className:"min-w-0",children:e.jsx(Qe,{placeholder:x("setupVariant.selectModel")})}),e.jsxs(Je,{className:"max-w-[calc(100vw-2rem)]",children:[N.map(g=>e.jsx(Se,{value:g.id,children:e.jsxs("div",{className:"flex min-w-0 items-center gap-2",children:[e.jsx("span",{className:"truncate",children:g.name}),g.description&&e.jsxs("span",{className:"truncate text-xs text-muted-foreground",children:["- ",g.description]})]})},g.id)),e.jsx(Se,{value:Xt,children:e.jsx("span",{className:"text-primary",children:x("setupVariant.customModelName")})})]})]}),e.jsx("div",{className:"text-xs text-muted-foreground",children:T?x("setupVariant.enterAnyModel"):x("setupVariant.defaultModel",{model:b?.defaultModel||x("setupVariant.providerDefault")})})]}),e.jsxs("div",{className:"flex flex-col gap-2 pt-2 sm:flex-row sm:items-center sm:justify-between",children:[e.jsxs(U,{variant:"ghost",onClick:p,className:"justify-start",children:[e.jsx(It,{className:"w-4 h-4 mr-2"}),x("setupVariant.back")]}),e.jsxs("div",{className:"flex flex-col-reverse gap-2 sm:flex-row sm:items-center",children:[e.jsx(U,{variant:"ghost",onClick:m,children:x("setupVariant.skip")}),e.jsx(U,{onClick:v,disabled:!n||o||S,children:x(o?"setupVariant.creating":"setupVariant.createVariant")})]})]}),e.jsx("p",{className:"text-xs text-center text-muted-foreground",children:x("setupVariant.skipHint")})]})}function an({variantName:t,onClose:a}){const{t:s}=W();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(Pe,{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:s("setupWizard.successStep.title")}),e.jsx("div",{className:"text-sm text-muted-foreground",children:s("setupWizard.successStep.subtitle")})]}),e.jsx(as,{children:e.jsxs(ns,{className:"p-4 space-y-2",children:[e.jsx("div",{className:"text-sm text-muted-foreground",children:s("setupWizard.successStep.usage")}),e.jsxs("code",{className:"block px-3 py-2 bg-muted rounded-md font-mono text-sm",children:["ccs ",t,' "your prompt here"']})]})}),e.jsx(U,{onClick:a,className:"w-full",children:s("setupWizard.successStep.done")})]})}function nn({open:t,onClose:a}){const[s,n]=c.useState("provider"),[r,o]=c.useState(""),[l,d]=c.useState(null),[i,p]=c.useState(""),[m,v]=c.useState(""),[x,b]=c.useState(!1),[N,C]=c.useState(!1),{data:T,refetch:M}=os(),{data:S}=ls(),w=Es(),y=Rs(),h=Os(),{privacyMode:g}=ds(),E=T?.authStatus.find(k=>k.provider===r),u=c.useMemo(()=>E?.accounts||[],[E?.accounts]),I=c.useMemo(()=>_t(S?.catalogs),[S?.catalogs]),A=!!S;c.useEffect(()=>{if(!t){const k=setTimeout(()=>{n("provider"),o(""),d(null),p(""),v(""),C(!1)},0);return()=>clearTimeout(k)}},[t]),c.useEffect(()=>{if(s==="auth"&&u.length>0&&!N){const k=setTimeout(()=>{n("account")},0);return()=>clearTimeout(k)}},[s,u,N]);const q=async()=>{b(!0),await M(),b(!1)},P=()=>{const k=(E?.accounts?.length||0)===0;y.mutate({provider:r},{onSuccess:async Q=>{if(k){const j=await Nt(r,void 0,A?I[r]:void 0);j.success&&j.presetName?B.success(`Applied "${j.presetName}" preset`):j.success||B.warning(he.t("commonToast.accountAddedPresetFailed"))}Q.account&&(d(Q.account),n("variant")),M()}})},_=k=>{o(k),(T?.authStatus.find(Y=>Y.provider===k)?.accounts||[]).length===0?n("auth"):n("account")},H=k=>{d(k),n("variant")},G=async()=>{if(!(!i||!r))try{await w.mutateAsync({name:i,provider:r,model:m||void 0,account:l?.id}),n("success")}catch(k){console.error("Failed to create variant:",k)}},V=`ccs ${r} --auth --add`,R=Ls(s),O=k=>{if(!k&&(y.isPending&&r&&h.mutate(r),s==="success"||s==="provider")){a();return}};return e.jsx(Ct,{open:t,onOpenChange:O,children:e.jsxs(At,{className:"grid max-h-[calc(100dvh-2rem)] w-[calc(100vw-2rem)] max-w-lg grid-rows-[auto_minmax(0,1fr)_auto] overflow-hidden p-0 sm:max-w-lg",onPointerDownOutside:k=>{s!=="success"&&s!=="provider"&&k.preventDefault()},onEscapeKeyDown:k=>{(y.isPending||w.isPending)&&k.preventDefault()},children:[e.jsxs(St,{className:"min-w-0 px-6 pt-6 pr-12",children:[e.jsxs(Mt,{className:"flex min-w-0 items-center gap-2",children:[e.jsx(Tt,{className:"w-5 h-5 text-primary"}),he.t("setupWizard.title")]}),e.jsxs(cs,{children:[s==="provider"&&he.t("setupWizard.stepProviderDesc"),s==="auth"&&he.t("setupWizard.stepAuthDesc"),s==="account"&&he.t("setupWizard.stepAccountDesc"),s==="variant"&&he.t("setupWizard.stepVariantDesc"),s==="success"&&he.t("setupWizard.stepSuccessDesc")]})]}),e.jsxs("div",{className:"min-h-0 space-y-4 overflow-y-auto px-6 py-4",children:[s==="provider"&&e.jsx(Za,{providers:Ht,onSelect:_}),s==="auth"&&e.jsx(en,{selectedProvider:r,providers:Ht,authCommand:V,isRefreshing:x,isPending:y.isPending,onBack:()=>n("provider"),onStartAuth:P,onRefresh:q}),s==="account"&&e.jsx(tn,{accounts:u,privacyMode:g,onSelect:H,onAddNew:()=>{C(!0),n("auth")},onBack:()=>n("provider")}),s==="variant"&&e.jsx(sn,{selectedProvider:r,catalog:I[r],selectedAccount:l,variantName:i,modelName:m,isPending:w.isPending,privacyMode:g,onVariantNameChange:p,onModelChange:v,onBack:()=>u.length>0?n("account"):n("provider"),onSkip:a,onCreate:G}),s==="success"&&e.jsx(an,{variantName:i,onClose:a})]}),e.jsx("div",{className:"px-6 pb-6",children:e.jsx(Ya,{currentProgress:R,allSteps:_s})})]})})}const rn=3e3,on=300*1e3,ln=3;function pt(t){t.invalidateQueries({queryKey:["cliproxy-catalog"]}),t.invalidateQueries({queryKey:["cliproxy-models"]})}async function xt(t){const a=await t.text();if(!a)return{};try{return JSON.parse(a)}catch{const s=t.status>=400?`Request failed with status ${t.status}`:void 0;return s?{error:s}:{}}}function dn(t,a){const s=typeof t.message=="string"?t.message:typeof t.error=="string"?t.error:a,n=Array.isArray(t.hints)?t.hints.filter(r=>typeof r=="string"&&r.trim().length>0):[];return n.length>0?[s,...n].join(`
2
+ `):s}const Ne={provider:null,isAuthenticating:!1,error:null,authUrl:null,oauthState:null,isSubmittingCallback:!1,isDeviceCodeFlow:!1};function cn(){const{t}=W(),[a,s]=c.useState(Ne),n=c.useRef(Ne),r=c.useRef(0),o=c.useRef(null),l=c.useRef(null),d=c.useRef(0),i=c.useRef(0),p=c.useRef(!1),m=wt(),v=c.useCallback(M=>M===r.current,[]),x=c.useCallback(()=>{l.current&&(clearInterval(l.current),l.current=null),i.current=0},[]);c.useEffect(()=>()=>{o.current?.abort(),x(),p.current=!1},[x]),c.useEffect(()=>{n.current=a},[a]);const b=c.useCallback(async(M,S,w)=>{if(v(w)){if(Date.now()-d.current>on){x(),v(w)&&s(y=>({...y,isAuthenticating:!1,error:t("toasts.providerAuthTimeout")}));return}try{const y=await fetch(`/api/cliproxy/auth/${M}/status?state=${encodeURIComponent(S)}`);if(!v(w))return;const h=await y.json();if(i.current=0,h.status==="ok"){if(!(typeof h.account=="object"&&h.account!==null)){x();const E=t("toasts.providerAccountRegistrationFailed");B.error(E),s(u=>({...u,isAuthenticating:!1,error:E}));return}x(),m.invalidateQueries({queryKey:["cliproxy-auth"]}),m.invalidateQueries({queryKey:["cliproxy-accounts"]}),m.invalidateQueries({queryKey:["account-quota"]}),pt(m),B.success(t("toasts.providerAuthSuccess",{provider:M})),p.current=!1,s(Ne)}else if(h.status==="auth_url"){const g=h.url||h.auth_url;g&&(s(E=>({...E,authUrl:g})),p.current||(p.current=!0,window.open(g,"_blank")))}else if(h.status==="device_code"){x();const g=h.user_code&&h.verification_url?`Open ${h.verification_url} and enter code: ${h.user_code}`:"Switch to Device Code method and try again.";B.error(t("toasts.providerDeviceCodeInCallback")),s(E=>({...E,isAuthenticating:!1,error:g}))}else if(h.status==="error"){x();const g=h.error||"Authentication failed";B.error(g),s(E=>({...E,isAuthenticating:!1,error:g}))}}catch(y){if(!v(w)||(i.current+=1,i.current<ln))return;x();const h=y instanceof Error&&y.message.trim().length>0?y.message:t("toasts.providerLostStatusEndpoint");B.error(h),s(g=>({...g,isAuthenticating:!1,error:h}))}}},[v,m,x,t]),N=c.useCallback(async(M,S)=>{if(!Re(M)){s({...Ne,error:t("toasts.providerUnknown",{provider:M})});return}o.current?.abort(),x(),p.current=!1,i.current=0;const w=new AbortController,y=r.current+1;r.current=y,o.current=w;const g=(S?.flowType||(us(M)?"device_code":"authorization_code"))==="device_code",E=S?.startEndpoint||(g?"start":"start-url"),u={accountId:S?.accountId,nickname:S?.nickname,kiroMethod:S?.kiroMethod,kiroIDCStartUrl:S?.kiroIDCStartUrl,kiroIDCRegion:S?.kiroIDCRegion,kiroIDCFlow:S?.kiroIDCFlow,gitlabAuthMode:S?.gitlabAuthMode,gitlabBaseUrl:S?.gitlabBaseUrl,gitlabPersonalAccessToken:S?.gitlabPersonalAccessToken,riskAcknowledgement:S?.riskAcknowledgement};s({provider:M,isAuthenticating:!0,error:null,authUrl:null,oauthState:null,isSubmittingCallback:!1,isDeviceCodeFlow:g});try{if(E==="start")fetch(`/api/cliproxy/auth/${M}/start`,{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify(u),signal:w.signal}).then(async I=>{if(!v(y))return;const A=await xt(I);if(!v(y))return;const q=A.success===!0,P=typeof A.account=="object"&&A.account!==null;if(I.ok&&q&&P)m.invalidateQueries({queryKey:["cliproxy-auth"]}),m.invalidateQueries({queryKey:["cliproxy-accounts"]}),m.invalidateQueries({queryKey:["account-quota"]}),pt(m),p.current=!1,s(Ne);else{const _=typeof A.error=="string"?A.error:t(q?"toasts.providerAccountRegistrationFailed":"auth.loginFailed");B.error(_),s(H=>({...H,isAuthenticating:!1,error:_}))}}).catch(I=>{if(!v(y)||I instanceof Error&&I.name==="AbortError")return;const A=I instanceof Error?I.message:"Authentication failed";B.error(A),s(q=>({...q,isAuthenticating:!1,error:A}))});else{const I=await fetch(`/api/cliproxy/auth/${M}/start-url`,{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify(u),signal:w.signal});if(!v(y))return;const A=await xt(I);if(!v(y))return;const q=A.success===!0;if(!I.ok||!q){const H=dn(A,t("toasts.providerStartOAuthFailed"));throw new Error(H)}const P=typeof A.authUrl=="string"?A.authUrl:null,_=typeof A.state=="string"?A.state:null;if(s(H=>({...H,authUrl:P,oauthState:_})),P&&(p.current=!0,window.open(P,"_blank")),_){if(d.current=Date.now(),!P){if(await b(M,_,y),!v(y))return;const H=n.current;if(!H.isAuthenticating||H.provider!==M)return}l.current=setInterval(()=>{b(M,_,y)},rn)}}}catch(I){if(!v(y))return;if(I instanceof Error&&I.name==="AbortError"){p.current=!1,s(Ne);return}const A=I instanceof Error?I.message:t("auth.loginFailed");B.error(A),s(q=>({...q,isAuthenticating:!1,error:A}))}},[v,b,x,m,t]),C=c.useCallback(()=>{const M=a.provider;r.current+=1,o.current?.abort(),x(),p.current=!1,s(Ne),M&&Xe.cliproxy.auth.cancel(M).catch(()=>{})},[a.provider,x]),T=c.useCallback(async M=>{if(!a.provider)return;const S=r.current,w=a.provider;s(y=>({...y,isSubmittingCallback:!0,error:null}));try{const y=await fetch(`/api/cliproxy/auth/${w}/submit-callback`,{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify({redirectUrl:M})});if(!v(S))return;const h=await xt(y);if(!v(S))return;const g=h.success===!0,E=h.status==="wait",u=typeof h.account=="object"&&h.account!==null;if(y.ok&&E)s(I=>({...I,isSubmittingCallback:!1,error:null}));else if(y.ok&&g&&u)x(),m.invalidateQueries({queryKey:["cliproxy-auth"]}),m.invalidateQueries({queryKey:["cliproxy-accounts"]}),m.invalidateQueries({queryKey:["account-quota"]}),pt(m),B.success(t("toasts.providerAuthSuccess",{provider:w})),s(Ne);else{const I=typeof h.error=="string"?h.error:t(g?"toasts.providerAccountRegistrationFailed":"toasts.providerCallbackFailed");throw new Error(I)}}catch(y){if(!v(S))return;const h=y instanceof Error?y.message:t("toasts.providerSubmitCallbackFailed");B.error(h),s(g=>({...g,isSubmittingCallback:!1,error:h}))}},[v,a.provider,m,x,t]);return c.useMemo(()=>({...a,startAuth:N,cancelAuth:C,submitCallback:T}),[a,N,C,T])}function yt({className:t,compact:a=!1,showAcknowledgement:s=!1,acknowledgementPhrase:n=Ye,acknowledgementText:r="",onAcknowledgementTextChange:o,disabled:l=!1,showProxySettingsLink:d=!1}){const{t:i}=W(),p=i("accountSafetyWarning.title"),m=i("accountSafetyWarning.subtitle"),v=i("accountSafetyWarning.firstLine"),x=i("accountSafetyWarning.secondLine"),b="https://github.com/kaitranntt/ccs/issues/509",N=i("accountSafetyWarning.issueLabel"),C=i("accountSafetyWarning.proxySettingsLabel");return a?e.jsx("section",{role:"alert",className:X("border-b border-amber-200/70 bg-amber-50/45 dark:bg-amber-950/5",t),children:e.jsxs("div",{className:"flex flex-col gap-3 px-6 py-3 lg:flex-row lg:items-start lg:justify-between",children:[e.jsxs("div",{className:"min-w-0 flex items-start gap-3",children:[e.jsx("div",{className:"mt-0.5 inline-flex h-6 w-6 items-center justify-center rounded-md bg-amber-500/12 text-amber-700 dark:text-amber-300",children:e.jsx(et,{className:"h-3.5 w-3.5"})}),e.jsxs("div",{className:"min-w-0 space-y-1",children:[e.jsxs("div",{className:"flex flex-wrap items-center gap-2",children:[e.jsx("p",{className:"text-xs font-semibold leading-5",children:p}),e.jsx("p",{className:"text-[11px] text-muted-foreground",children:m})]}),e.jsx("p",{className:"text-xs leading-5 text-muted-foreground",children:v}),e.jsx("p",{className:"text-xs font-medium leading-5 text-amber-900 dark:text-amber-200",children:x})]})]}),e.jsxs("div",{className:"flex flex-wrap items-center gap-2 lg:justify-end",children:[e.jsxs("a",{href:b,target:"_blank",rel:"noreferrer",className:"inline-flex items-center gap-1 rounded-md border border-amber-500/25 bg-background/90 px-2 py-1 text-[11px] font-medium text-amber-800 transition-colors hover:bg-amber-500/10 dark:text-amber-200",children:[N,e.jsx(Me,{className:"h-3 w-3"})]}),d?e.jsxs("a",{href:"/settings?tab=proxy",className:"inline-flex items-center gap-1 rounded-md border border-amber-500/25 bg-background/90 px-2 py-1 text-[11px] font-medium text-amber-800 transition-colors hover:bg-amber-500/10 dark:text-amber-200",children:[e.jsx(Wt,{className:"h-3 w-3"}),C]}):null,e.jsx(z,{variant:"outline",className:"border-amber-500/40 text-[10px] text-amber-700 dark:text-amber-300",children:"High Risk"})]})]})}):e.jsxs("section",{role:"alert",className:X("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",t),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(et,{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:m})]})]}),e.jsx(z,{variant:"outline",className:"border-amber-500/40 text-amber-700 dark:text-amber-300",children:"High Risk"})]}),e.jsxs("div",{className:"space-y-2 text-sm leading-relaxed",children:[e.jsx("p",{children:v}),e.jsx("p",{className:"font-medium text-amber-900 dark:text-amber-200",children:x}),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:b,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:[N,e.jsx(Me,{className:"h-3.5 w-3.5"})]}),d&&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(Wt,{className:"h-3.5 w-3.5"}),C]}),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"})]}),s&&o&&e.jsxs("div",{className:"rounded-lg border border-amber-500/25 bg-amber-500/5 p-2.5",children:[e.jsxs(ee,{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:n})]}),e.jsx(ce,{id:"account-risk-ack-text",value:r,onChange:T=>o(T.target.value),placeholder:n,disabled:l,className:"mt-2 font-mono text-xs"})]})]})]})}function un({className:t,value:a,onChange:s,disabled:n=!1}){const{t:r}=W(),o=[a.reviewedIssue509,a.understandsBanRisk,a.acceptsFullResponsibility,a.typedPhrase.trim().replace(/\s+/g," ").toUpperCase()===Qt].filter(Boolean).length,l=o/4*100,d=i=>{s({...a,...i})};return e.jsxs("section",{role:"alert",className:X("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",t),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(et,{className:"h-4 w-4"})}),e.jsxs("div",{className:"space-y-1",children:[e.jsx("p",{className:"text-sm font-semibold leading-5",children:r("antigravityChecklist.title")}),e.jsx("p",{className:"text-xs text-muted-foreground",children:r("antigravityChecklist.subtitle")})]})]}),e.jsx(z,{variant:"outline",className:"border-rose-500/40 text-rose-700 dark:text-rose-300",children:r("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:r("antigravityChecklist.completion")}),e.jsx("span",{children:r("antigravityChecklist.stepsCount",{current:o})})]}),e.jsx(Fs,{value:l,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(Ze,{id:"agy-step-reviewed-issue",checked:a.reviewedIssue509,onCheckedChange:i=>d({reviewedIssue509:!!i}),disabled:n}),e.jsx(ee,{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(Ze,{id:"agy-step-understands-risk",checked:a.understandsBanRisk,onCheckedChange:i=>d({understandsBanRisk:!!i}),disabled:n}),e.jsx(ee,{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(Ze,{id:"agy-step-accept-responsibility",checked:a.acceptsFullResponsibility,onCheckedChange:i=>d({acceptsFullResponsibility:!!i}),disabled:n}),e.jsx(ee,{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(fs,{className:"h-3.5 w-3.5"}),"Step 4: Type exact phrase to continue"]}),e.jsx(ce,{value:a.typedPhrase,onChange:i=>d({typedPhrase:i.target.value}),placeholder:Qt,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(Me,{className:"h-3.5 w-3.5"})]})})]})]})}function mn(t){return t.trim().replace(/\s+/g," ").toUpperCase()}function pn({open:t,onClose:a,provider:s,displayName:n,catalog:r,account:o,isFirstAccount:l=!1}){const[d,i]=c.useState(""),[p,m]=c.useState(""),[v,x]=c.useState(!1),[b,N]=c.useState(null),[C,T]=c.useState(""),[M,S]=c.useState(ut),[w,y]=c.useState(!1),[h,g]=c.useState(!1),[E,u]=c.useState(qt),[I,A]=c.useState(""),[q,P]=c.useState(""),[_,H]=c.useState(zt),[G,V]=c.useState("oauth"),[R,O]=c.useState(""),[k,Q]=c.useState(""),{t:j}=W(),Y=c.useRef(!1),se=c.useRef(0),le=c.useRef(!1),K=cn(),re=Us(),$=s==="kiro",Z=s==="gitlab",ie=s==="agy"||s==="gemini",be=s==="gemini"&&!w,fe=s==="agy"&&!w,ke=ie&&h,Ce=Ta(M),f=mn(C)===Ye,F=us(s),ge=Ks(E),me=$&&E==="idc",pe=$&&qs(E),Ae=$?Hs(E,_):void 0,it=$?Gs(E):void 0,ot=$?Ae==="device_code":F,de=K.isAuthenticating||re.isPending,Le=d.trim(),Fe=I.trim(),Ue=q.trim(),Ke=R.trim(),L=k.trim(),te=b||K.error,ae=!!o,De=o?.email||o?.nickname||o?.id||n,Ut=c.useCallback(async()=>{const D=await fetch("/api/settings/auth/antigravity-risk");if(!D.ok)throw new Error("Failed to load power user mode setting");return(await D.json()).antigravityAckBypass===!0},[]),He=c.useCallback(async({pendingMessage:D=null,disabledMessage:ve=null}={})=>{const dt=++se.current;g(!0),D!==null&&N(D);try{const qe=await Ut();return se.current!==dt||(y(qe),ve?N(qe?null:ve):D!==null&&N(null)),qe}catch{return se.current!==dt||(y(!1),N(ve??j("addAccountDialog.powerUserLoadFailed")),le.current||(le.current=!0,B.error(j("addAccountDialog.powerUserLoadFailed")))),!1}finally{se.current===dt&&g(!1)}},[Ut,j]),lt=()=>{i(""),m(""),x(!1),N(null),T(""),S(ut),y(!1),g(!1),u(qt),A(""),P(""),H(zt),V("oauth"),O(""),Q(""),se.current+=1,le.current=!1,Y.current=!1,a()};c.useEffect(()=>{t&&(T(""),S(ut),N(null))},[s,t]),c.useEffect(()=>()=>{se.current+=1},[]),c.useEffect(()=>{if(!t||!ie){se.current+=1,y(!1),g(!1);return}He()},[t,s,ie,He]),c.useEffect(()=>{if(!t||s!=="agy"||!K.error||!w)return;const D=K.error.toLowerCase();(D.includes("agy_risk_ack_required")||D.includes("responsibility acknowledgement")||D.includes("responsibility checklist"))&&He({pendingMessage:j("addAccountDialog.powerUserLoading"),disabledMessage:j("addAccountDialog.powerUserUnavailableRetry")})},[K.error,t,w,s,He,j]),c.useEffect(()=>{!K.isAuthenticating&&!K.error&&K.provider===null&&t&&Y.current&&(Y.current=!1,(async()=>{try{const ve=await Nt(s,void 0,r);ve.success&&ve.presetName&&l&&B.success(`Applied "${ve.presetName}" preset`)}catch{}lt()})())},[K.isAuthenticating,K.error,K.provider]);const Kt=()=>{K.cancelAuth(),lt()},As=async()=>{K.authUrl&&(await navigator.clipboard.writeText(K.authUrl),x(!0),setTimeout(()=>x(!1),2e3))},Ss=()=>{p.trim()&&K.submitCallback(p.trim())},Ms=()=>{if(ke){N(j("addAccountDialog.powerUserLoading"));return}if(fe&&!Ce){N("Complete all Antigravity responsibility steps before authenticating this provider.");return}if(be&&!f){N(`Type "${Ye}" to acknowledge the account safety warning before authenticating this provider.`);return}if(N(null),me&&!Fe){N("IDC Start URL is required for Kiro IAM Identity Center login.");return}if(Z&&G==="pat"&&!L){N(j("addAccountDialog.gitlabPatRequired"));return}Y.current=!0,K.startAuth(s,{accountId:o?.id,nickname:o?o.nickname:Le||void 0,kiroMethod:$?E:void 0,kiroIDCStartUrl:me?Fe:void 0,kiroIDCRegion:me&&Ue?Ue:void 0,kiroIDCFlow:me?_:void 0,gitlabAuthMode:Z?G:void 0,gitlabBaseUrl:Z&&Ke?Ke:void 0,gitlabPersonalAccessToken:Z&&G==="pat"&&L?L:void 0,flowType:$?Ae:void 0,startEndpoint:$?it:Z&&G==="pat"?"start":void 0,riskAcknowledgement:fe?{version:Ea,reviewedIssue509:M.reviewedIssue509,understandsBanRisk:M.understandsBanRisk,acceptsFullResponsibility:M.acceptsFullResponsibility,typedPhrase:M.typedPhrase}:void 0})},Ps=()=>{Y.current=!0,re.mutate(void 0,{onSuccess:async()=>{const D=await Nt("kiro",void 0,r);D.success&&D.presetName&&l&&B.success(`Applied "${D.presetName}" preset`),lt()}})},Ds=D=>{D||Kt()},oe=K.isAuthenticating;return e.jsx(Ct,{open:t,onOpenChange:Ds,children:e.jsxs(At,{className:"grid max-h-[calc(100dvh-2rem)] w-[calc(100vw-2rem)] max-w-md grid-rows-[auto_minmax(0,1fr)] overflow-hidden p-0 sm:max-w-md",onInteractOutside:D=>{oe&&D.preventDefault()},children:[e.jsxs(St,{className:"min-w-0 px-6 pt-6 pr-12",children:[e.jsx(Mt,{children:ae?`Reauthenticate ${n}`:j("addAccountDialog.title",{displayName:n})}),e.jsx(cs,{children:ae?`Refresh credentials for ${De}.`:j($?"addAccountDialog.descKiro":ot?"addAccountDialog.descDeviceCode":"addAccountDialog.descOauth")})]}),e.jsxs("div",{className:"min-h-0 space-y-4 overflow-y-auto px-6 py-4",children:[fe&&!oe&&e.jsx(un,{value:M,onChange:D=>{S(D),N(null)},disabled:de}),ie&&w&&!oe&&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(fs,{className:"h-3.5 w-3.5"}),j("addAccountDialog.powerUserEnabled")]}),j("addAccountDialog.powerUserSkipped")]}),be&&!oe&&e.jsx(yt,{showAcknowledgement:!0,acknowledgementPhrase:Ye,acknowledgementText:C,onAcknowledgementTextChange:D=>{T(D),N(null)},disabled:de}),$&&!oe&&e.jsxs("div",{className:"space-y-2",children:[e.jsx(ee,{htmlFor:"kiro-auth-method",children:j("addAccountDialog.authMethod")}),e.jsxs($e,{value:E,onValueChange:D=>{u(D),N(null)},children:[e.jsx(We,{id:"kiro-auth-method",children:e.jsx(Qe,{placeholder:j("addAccountDialog.selectKiroAuthMethod")})}),e.jsx(Je,{children:zs.map(D=>e.jsx(Se,{value:D.id,children:D.label},D.id))})]}),e.jsx("p",{className:"text-xs text-muted-foreground",children:ge.description}),pe&&e.jsxs("p",{className:"text-xs text-muted-foreground",children:["If your browser does not return automatically after login, CCS can accept the final",e.jsx("span",{className:"mx-1 rounded bg-muted px-1.5 py-0.5 font-mono text-[11px]",children:"kiro://..."}),"callback URL in the next step."]})]}),me&&!oe&&e.jsxs("div",{className:"space-y-4 rounded-lg border border-border/60 bg-muted/20 p-4",children:[e.jsxs("div",{className:"space-y-2",children:[e.jsx(ee,{htmlFor:"kiro-idc-start-url",children:"IDC Start URL"}),e.jsx(ce,{id:"kiro-idc-start-url",value:I,onChange:D=>{A(D.target.value),N(null)},placeholder:"https://d-xxx.awsapps.com/start",disabled:de}),e.jsx("p",{className:"text-xs text-muted-foreground",children:"Required for organization IAM Identity Center login."})]}),e.jsxs("div",{className:"space-y-2",children:[e.jsx(ee,{htmlFor:"kiro-idc-region",children:"IDC Region"}),e.jsx(ce,{id:"kiro-idc-region",value:q,onChange:D=>{P(D.target.value),N(null)},placeholder:"us-east-1",disabled:de}),e.jsx("p",{className:"text-xs text-muted-foreground",children:"Optional. Leave blank to use the upstream default region."})]}),e.jsxs("div",{className:"space-y-2",children:[e.jsx(ee,{htmlFor:"kiro-idc-flow",children:"IDC Flow"}),e.jsxs($e,{value:_,onValueChange:D=>{H(D),N(null)},children:[e.jsx(We,{id:"kiro-idc-flow",children:e.jsx(Qe,{placeholder:"{/* TODO i18n: missing key */}Select IDC flow"})}),e.jsxs(Je,{children:[e.jsx(Se,{value:"authcode",children:"Authorization Code"}),e.jsx(Se,{value:"device",children:"Device Code"})]})]}),e.jsx("p",{className:"text-xs text-muted-foreground",children:"Auth Code opens a browser and may need the final callback URL pasted back. Device Code shows a verification code instead."})]})]}),Z&&!oe&&e.jsxs("div",{className:"space-y-4 rounded-lg border border-border/60 bg-muted/20 p-4",children:[e.jsxs("div",{className:"space-y-2",children:[e.jsx(ee,{htmlFor:"gitlab-auth-mode",children:j("addAccountDialog.gitlabAuthMethod")}),e.jsxs($e,{value:G,onValueChange:D=>{V(D),N(null)},children:[e.jsx(We,{id:"gitlab-auth-mode",children:e.jsx(Qe,{placeholder:j("addAccountDialog.selectGitlabAuthMethod")})}),e.jsxs(Je,{children:[e.jsx(Se,{value:"oauth",children:j("addAccountDialog.gitlabAuthOAuth")}),e.jsx(Se,{value:"pat",children:j("addAccountDialog.gitlabAuthPat")})]})]}),e.jsx("p",{className:"text-xs text-muted-foreground",children:j("addAccountDialog.gitlabAuthHint")})]}),e.jsxs("div",{className:"space-y-2",children:[e.jsx(ee,{htmlFor:"gitlab-base-url",children:j("addAccountDialog.gitlabUrl")}),e.jsx(ce,{id:"gitlab-base-url",value:R,onChange:D=>{O(D.target.value),N(null)},placeholder:j("addAccountDialog.gitlabUrlPlaceholder"),disabled:de}),e.jsx("p",{className:"text-xs text-muted-foreground",children:j("addAccountDialog.gitlabUrlHint")})]}),G==="pat"&&e.jsxs("div",{className:"space-y-2",children:[e.jsx(ee,{htmlFor:"gitlab-pat",children:j("addAccountDialog.gitlabPat")}),e.jsx(ce,{id:"gitlab-pat",type:"password",value:k,onChange:D=>{Q(D.target.value),N(null)},placeholder:j("addAccountDialog.gitlabPatPlaceholder"),disabled:de}),e.jsxs("p",{className:"text-xs text-muted-foreground",children:[j("addAccountDialog.gitlabPatHint")," ",e.jsx("span",{className:"font-mono",children:"api"})," and"," ",e.jsx("span",{className:"font-mono",children:"read_user"})," scopes."]})]})]}),!oe&&ae&&e.jsxs("div",{className:"rounded-md border bg-muted/30 px-3 py-2 text-sm",children:[e.jsx("div",{className:"font-medium",children:De}),e.jsx("div",{className:"text-xs text-muted-foreground",children:"This sign-in updates the selected account instead of creating another account."})]}),!oe&&!ae&&e.jsxs("div",{className:"space-y-2",children:[e.jsx(ee,{htmlFor:"nickname",children:j("addAccountDialog.nicknameOptional")}),e.jsxs("div",{className:"flex items-center gap-2",children:[e.jsx(Oe,{className:"w-4 h-4 text-muted-foreground"}),e.jsx(ce,{id:"nickname",value:d,onChange:D=>{i(D.target.value),N(null)},placeholder:j("addAccountDialog.nicknamePlaceholder"),disabled:de,className:"flex-1"})]}),e.jsx("p",{className:"text-xs text-muted-foreground",children:j("addAccountDialog.nicknameOptionalHint")})]}),oe&&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(ue,{className:"w-4 h-4 inline mr-2 animate-spin"}),j("addAccountDialog.waitingForAuth")]}),e.jsx("p",{className:"text-xs text-muted-foreground mt-1",children:K.isDeviceCodeFlow?j("addAccountDialog.deviceCodeHint"):pe?"Complete sign-in in your browser. If it does not return automatically, paste the final kiro:// callback URL below.":j("addAccountDialog.browserHint")})]}),K.authUrl&&!K.isDeviceCodeFlow&&e.jsxs("div",{className:"space-y-3",children:[e.jsxs("div",{className:"space-y-2",children:[e.jsx(ee,{className:"text-xs",children:j("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:K.authUrl}),e.jsxs("div",{className:"flex gap-2 mt-2",children:[e.jsx(U,{variant:"outline",size:"sm",onClick:As,children:v?e.jsxs(e.Fragment,{children:[e.jsx(Pe,{className:"w-3 h-3 mr-1"}),j("addAccountDialog.copied")]}):e.jsxs(e.Fragment,{children:[e.jsx(hs,{className:"w-3 h-3 mr-1"}),j("addAccountDialog.copy")]})}),e.jsxs(U,{variant:"outline",size:"sm",onClick:()=>{if(!K.authUrl)return;const D=window.open(K.authUrl,"_blank");(!D||D.closed||typeof D.closed>"u")&&B.warning(j("addAccountDialog.popupBlocked"),{duration:5e3})},children:[e.jsx(Me,{className:"w-3 h-3 mr-1"}),j("addAccountDialog.open")]})]})]})]}),e.jsxs("div",{className:"space-y-2",children:[e.jsx(ee,{htmlFor:"callback-url",className:"text-xs",children:pe?"Browser did not return? Paste the final kiro:// callback URL:":j("addAccountDialog.redirectPasteLabel")}),e.jsx(ce,{id:"callback-url",value:p,onChange:D=>m(D.target.value),placeholder:pe?"kiro://kiro.kiroAgent/authenticate-success?code=...&state=...":j("addAccountDialog.callbackPlaceholder"),className:"font-mono text-xs"}),e.jsx(U,{variant:"secondary",size:"sm",onClick:Ss,disabled:!p.trim()||K.isSubmittingCallback,children:K.isSubmittingCallback?e.jsxs(e.Fragment,{children:[e.jsx(ue,{className:"w-3 h-3 mr-1 animate-spin"}),j("addAccountDialog.submitting")]}):j("addAccountDialog.submitCallback")})]})]}),!K.authUrl&&!K.isDeviceCodeFlow&&e.jsx("p",{className:"text-xs text-center text-muted-foreground",children:pe?"Preparing the Kiro sign-in URL. If it does not open automatically, it will appear here shortly.":j("addAccountDialog.preparingUrl")})]}),te&&e.jsx("p",{className:"text-xs text-center text-destructive whitespace-pre-line",children:te}),re.isPending&&e.jsxs("p",{className:"text-sm text-center text-muted-foreground",children:[e.jsx(ue,{className:"w-4 h-4 inline mr-2 animate-spin"}),j("addAccountDialog.importingToken")]}),e.jsxs("div",{className:"flex flex-col-reverse gap-2 pt-2 sm:flex-row sm:items-center sm:justify-end",children:[e.jsx(U,{variant:"ghost",onClick:Kt,className:"w-full sm:w-auto",children:j("addAccountDialog.cancel")}),$&&!oe&&e.jsx(U,{variant:"outline",onClick:Ps,disabled:de,className:"w-full sm:w-auto",children:re.isPending?e.jsxs(e.Fragment,{children:[e.jsx(ue,{className:"w-4 h-4 mr-2 animate-spin"}),j("addAccountDialog.importing")]}):e.jsxs(e.Fragment,{children:[e.jsx(Ca,{className:"w-4 h-4 mr-2"}),j("addAccountDialog.importFromIde")]})}),!oe&&e.jsxs(U,{onClick:Ms,className:"w-full sm:w-auto",disabled:de||ke||fe&&!Ce||be&&!f,children:[e.jsx(Me,{className:"w-4 h-4 mr-2"}),ae?"Reauthenticate":j("addAccountDialog.authenticate")]})]})]})]})})}const xn=["ANTHROPIC_BASE_URL","ANTHROPIC_AUTH_TOKEN"];function hn(t){const a=t?.env||{};return xn.filter(s=>!a[s]?.trim())}function fn(t,a){const[s,n]=c.useState(null),[r,o]=c.useState(!1),l=wt(),{data:d,isLoading:i,refetch:p}=ss({queryKey:["settings",t],queryFn:async()=>{const P=await fetch(`/api/settings/${t}/raw`);if(!P.ok){const _=t==="cursor"?`~/.ccs/cliproxy/providers/${t}.settings.json`:Re(t)?`~/.ccs/${t}.settings.json`:`~/.ccs/profiles/${t}/settings.json`;return{profile:t,settings:{env:{}},mtime:Date.now(),path:_}}return P.json()}}),m=d?.settings,v=c.useMemo(()=>s!==null?s:m?JSON.stringify(m,null,2):`{
3
+ "env": {}
4
+ }`,[s,m]),x=c.useCallback(P=>{n(P)},[]),b=c.useMemo(()=>{try{return JSON.parse(v)}catch{return m||{env:{}}}},[v,m]),N=b?.env?.ANTHROPIC_MODEL,C=b?.env?.ANTHROPIC_DEFAULT_OPUS_MODEL,T=b?.env?.ANTHROPIC_DEFAULT_SONNET_MODEL,M=b?.env?.ANTHROPIC_DEFAULT_HAIKU_MODEL,S=c.useMemo(()=>Bs(b?.env||{}),[b]),w=c.useCallback((P,_)=>Vs(P,_,{supportsExtendedContext:H=>Qa(t,H,a)}),[a,t]),y=c.useCallback((P,_)=>{const H={...b?.env||{},[P]:_},G=Gt(P)?w(H,S):H;delete G.CCS_EXTENDED_CONTEXT;const V={...b,env:G};n(JSON.stringify(V,null,2))},[w,b,S]),h=c.useCallback(P=>{const _=b?.env||{},H=w(_,P);delete H.CCS_EXTENDED_CONTEXT;const G={...b,env:H};n(JSON.stringify(G,null,2))},[w,b]),g=c.useCallback(P=>{const _={...b?.env||{},...P},G=Object.keys(P).some(Gt)?w(_,S):_;delete G.CCS_EXTENDED_CONTEXT;const V={...b,env:G};n(JSON.stringify(V,null,2))},[w,b,S]),E=c.useMemo(()=>{try{return JSON.parse(v),!0}catch{return!1}},[v]),u=c.useMemo(()=>s===null?!1:s!==JSON.stringify(m,null,2),[s,m]),I=c.useMemo(()=>hn(b),[b]),A=Is({mutationFn:async()=>{const P=JSON.parse(v),_=await fetch(`/api/settings/${t}`,{method:"PUT",headers:{"Content-Type":"application/json"},body:JSON.stringify({settings:P,expectedMtime:d?.mtime})});if(_.status===409)throw new Error("CONFLICT");if(!_.ok)throw new Error("Failed to save");return _.json()},onSuccess:P=>{l.invalidateQueries({queryKey:["settings",t]}),n(null),P?.warning?B.success(he.t("settings.saved"),{description:P.warning}):B.success(he.t("settings.saved"))},onError:P=>{P.message==="CONFLICT"?o(!0):B.error(P.message)}}),q=async P=>{o(!1),P?(await p(),A.mutate()):n(null)};return{data:d,isLoading:i,refetch:p,rawJsonContent:v,rawJsonEdits:s,isRawJsonValid:E,hasChanges:u,currentSettings:b,currentModel:N,opusModel:C,sonnetModel:T,haikuModel:M,extendedContextEnabled:S,toggleExtendedContext:h,handleRawJsonChange:x,updateEnvValue:y,updateEnvValues:g,saveMutation:{mutate:()=>A.mutate(),isPending:A.isPending},conflictDialog:r,setConflictDialog:o,handleConflictResolve:q,missingRequiredFields:I}}const gn=/-(minimal|low|medium|high|xhigh|fast)$/i,vn=["minimal","low","medium","high","xhigh"];function jn(t){return t?.trim()??""}function rt(t){let a=jn(t),s,n;for(let r=0;r<2;r+=1){const o=a.match(gn);if(!o?.[1])break;const l=o[1].toLowerCase();if(l==="fast"){if(n)break;n="fast"}else{if(s)break;s=l}a=a.slice(0,-o[0].length)}return{baseModel:a,effort:s,serviceTier:n}}function Ft(t){return rt(t).effort}function Cs(t){return rt(t).serviceTier}function bn(t){return rt(t).baseModel}function Yt(t,a){const s=rt(t),n=s.baseModel;return!n||!a?s.serviceTier?`${n}-${s.serviceTier}`:n:[n,a,s.serviceTier].filter(Boolean).join("-")}function Nn(t,a,s=[]){if(!a){const l=Ft(t);return[Yt(t,l)]}const n=bn(t),r=[],o=l=>{const d=l?Yt(n,l):n;r.push(d);for(const i of s)r.push(`${d}-${i}`)};o(void 0);for(const l of vn)if(o(l),l===a)break;return r}function yn(t,a){if(!t)return null;const s=Ft(t);return s?{label:`Pinned ${s}`,explicit:!0}:{label:"Auto effort",explicit:!1}}function wn({label:t}){return e.jsx(z,{variant:"outline",className:"text-[9px] h-4 px-1",children:t})}function Ge({modelId:t}){const a=yn(t);return a?e.jsx(z,{variant:a.explicit?"secondary":"outline",className:"text-[9px] h-4 px-1 uppercase",children:a.label}):null}function Be({modelId:t}){const a=Cs(t);return a?e.jsx(z,{variant:"secondary",className:"text-[9px] h-4 px-1 uppercase",children:a}):null}function Zt(t,a){if(!t)return"";if(!a?.prefix)return t;const s=`${a.prefix}/`;return t.startsWith(s)?t.slice(s.length):t}function Ve(t,a){return a?.recommendedModelId??t}function ht(t,a,s,n){return n?Nn(s,t,a):[s]}function kn(t,a){return a?Cs(t)?"codex-fast":Ft(t)?"codex-reasoning":"recommended":"recommended"}function we({label:t,description:a,value:s,onChange:n,catalog:r,allModels:o,routing:l,disabled:d}){const{t:i}=W(),p=r?.provider==="codex",m=c.useMemo(()=>Lt(r,o),[o,r]),v=c.useMemo(()=>Wa(r?.provider??"",r,o),[o,r]),x=new Set(m.map(h=>h.id)),b=c.useMemo(()=>new Map((l?.models??[]).map(h=>[h.modelId.toLowerCase(),h])),[l]),N=c.useMemo(()=>new Set(m.flatMap(h=>ht(h.codexMaxEffort,h.codexServiceTiers,Ve(h.id,b.get(h.id.toLowerCase())),p))),[p,m,b]),C=c.useMemo(()=>b.get(Zt(s,l).toLowerCase()),[l,b,s]),T=m.flatMap(h=>{const g=b.get(h.id.toLowerCase());return ht(h.codexMaxEffort,h.codexServiceTiers,Ve(h.id,g),p).map(u=>({value:u,groupKey:kn(u,p),searchText:`${u} ${h.id} ${h.name} ${g?.recommendedModelId??""}`,keywords:[h.tier??"",r?.provider??""],triggerContent:e.jsxs("div",{className:"flex min-w-0 items-center gap-2",children:[e.jsx("span",{className:"truncate font-mono text-xs",children:u}),g?.pinnedAvailable?e.jsx(z,{variant:"secondary",className:"text-[9px] h-4 px-1 uppercase",children:g.prefix}):null,p&&e.jsx(Ge,{modelId:u}),p&&e.jsx(Be,{modelId:u})]}),itemContent:e.jsxs("div",{className:"flex min-w-0 items-center gap-2",children:[e.jsx("span",{className:"truncate font-mono text-xs",children:u}),h.tier==="paid"&&e.jsx(wn,{label:i("providerModelSelector.paid")}),g?.unprefixedStatus==="shadowed"?e.jsx(z,{variant:"outline",className:"text-[9px] h-4 px-1",children:i("providerModelSelector.shadowed")}):null,g?.unprefixedStatus==="prefix-only"?e.jsx(z,{variant:"outline",className:"text-[9px] h-4 px-1",children:i("providerModelSelector.prefixOnly")}):null,p&&e.jsx(Ge,{modelId:u}),p&&e.jsx(Be,{modelId:u})]})}))}),M=v.filter(h=>!x.has(h.id)).filter(h=>!N.has(Ve(h.id,b.get(h.id.toLowerCase())))).flatMap(h=>{const g=b.get(h.id.toLowerCase());return ht(void 0,void 0,Ve(h.id,g),p).map(u=>({value:u,groupKey:"all",searchText:`${u} ${h.id} ${g?.recommendedModelId??""}`,keywords:[h.owned_by],triggerContent:e.jsxs("div",{className:"flex min-w-0 items-center gap-2",children:[e.jsx("span",{className:"truncate font-mono text-xs",children:u}),g?.pinnedAvailable?e.jsx(z,{variant:"secondary",className:"text-[9px] h-4 px-1 uppercase",children:g.prefix}):null,p&&e.jsx(Ge,{modelId:u}),p&&e.jsx(Be,{modelId:u})]}),itemContent:e.jsxs("div",{className:"flex min-w-0 items-center gap-2",children:[e.jsx("span",{className:"truncate font-mono text-xs",children:u}),g?.unprefixedStatus==="shadowed"?e.jsx(z,{variant:"outline",className:"text-[9px] h-4 px-1",children:i("providerModelSelector.shadowed")}):null,g?.unprefixedStatus==="prefix-only"?e.jsx(z,{variant:"outline",className:"text-[9px] h-4 px-1",children:i("providerModelSelector.prefixOnly")}):null,p&&e.jsx(Ge,{modelId:u}),p&&e.jsx(Be,{modelId:u})]})}))}),S=!!s&&!T.some(h=>h.value===s)&&!M.some(h=>h.value===s),w=s?{value:s,groupKey:"current",searchText:s,triggerContent:e.jsxs("div",{className:"flex min-w-0 items-center gap-2",children:[e.jsx("span",{className:"truncate font-mono text-xs",children:s}),e.jsx(z,{variant:"outline",className:"text-[9px] h-4 px-1",children:i("providerModelSelector.current")})]}),itemContent:e.jsxs("div",{className:"flex min-w-0 items-center gap-2",children:[e.jsx("span",{className:"truncate font-mono text-xs",children:s}),e.jsx(z,{variant:"outline",className:"text-[9px] h-4 px-1",children:i("providerModelSelector.current")})]})}:null,y=T.length+M.length>0;return e.jsxs("div",{className:"space-y-1.5",children:[e.jsxs("div",{children:[e.jsx("label",{className:"text-xs font-medium",children:t}),a&&e.jsx("p",{className:"text-[10px] text-muted-foreground",children:a})]}),e.jsx(Oa,{value:s||void 0,onChange:n,disabled:d,placeholder:i("providerModelSelector.selectModel"),searchPlaceholder:i("searchableSelect.searchModels"),emptyText:i(y?"searchableSelect.noResults":"providerModelSelector.noModelsAvailable"),triggerClassName:"h-9",groups:[...S&&w?[{key:"current",label:e.jsx("span",{className:"text-xs text-muted-foreground",children:i("providerModelSelector.currentValue")})}]:[],{key:"recommended",label:e.jsx("span",{className:"text-xs text-primary",children:i("providerModelSelector.recommended")})},...p?[{key:"codex-reasoning",label:e.jsx("span",{className:"text-xs text-muted-foreground",children:i("providerModelSelector.codexReasoningVariants")})},{key:"codex-fast",label:e.jsx("span",{className:"text-xs text-amber-600",children:i("providerModelSelector.codexFastVariants")})}]:[],...M.length>0?[{key:"all",label:e.jsx("span",{className:"text-xs text-muted-foreground",children:i("providerModelSelector.allModelsCount",{count:M.length})})}]:[]],options:[...S&&w?[w]:[],...T,...M]}),C?e.jsxs("div",{className:X("rounded-md border px-2.5 py-2 text-[11px]",C.unprefixedStatus==="safe"?"border-border/70 bg-muted/25 text-muted-foreground":"border-amber-300/60 bg-amber-50 text-amber-900 dark:border-amber-500/30 dark:bg-amber-950/25 dark:text-amber-100"),children:[e.jsxs("div",{className:"font-medium",children:[C.pinnedAvailable?i("providerModelSelector.preferredPinnedModel"):i("providerModelSelector.pinnedRouteStatus")," ",e.jsx("code",{children:C.pinnedAvailable?C.recommendedModelId:C.pinnedModelId})]}),e.jsx("p",{className:"mt-1 leading-5",children:C.summary})]}):null,s&&!C&&Zt(s,l)!==s?e.jsx("div",{className:"rounded-md border border-amber-300/60 bg-amber-50 px-2.5 py-2 text-[11px] text-amber-900 dark:border-amber-500/30 dark:bg-amber-950/25 dark:text-amber-100",children:i("providerModelSelector.pinnedModelNotAdvertised",{model:s})}):null]})}function es(t,a){const s=n=>a?.models.find(o=>o.modelId.toLowerCase()===n.toLowerCase())?.recommendedModelId??n;return{default:s(t.default),opus:s(t.opus),sonnet:s(t.sonnet),haiku:s(t.haiku)}}function Cn({open:t,onClose:a,currentValues:s,onApply:n,onSave:r,isSaving:o,catalog:l,allModels:d,routing:i}){const{t:p}=W(),[m,v]=c.useState(es(s,i)),[x,b]=c.useState(""),N=C=>{C?(v(es(s,i)),b("")):a()};return e.jsx(Ct,{open:t,onOpenChange:N,children:e.jsxs(At,{className:"sm:max-w-md",children:[e.jsx(St,{children:e.jsxs(Mt,{className:"flex items-center gap-2",children:[e.jsx(Tt,{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(ee,{htmlFor:"preset-name",children:p("customPresetDialog.presetNameOptional")}),e.jsx(ce,{id:"preset-name",value:x,onChange:C=>b(C.target.value),placeholder:p("customPresetDialog.presetNamePlaceholder"),className:"text-sm"})]}),e.jsx(Ot,{}),l?.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(we,{label:p("customPresetDialog.defaultModel"),description:p("customPresetDialog.defaultModelDesc"),value:m.default,onChange:C=>v({...m,default:C}),catalog:l,allModels:d,routing:i}),e.jsx(we,{label:p("customPresetDialog.opusModel"),description:p("customPresetDialog.opusModelDesc"),value:m.opus,onChange:C=>v({...m,opus:C}),catalog:l,allModels:d,routing:i}),e.jsx(we,{label:p("customPresetDialog.sonnetModel"),description:p("customPresetDialog.sonnetModelDesc"),value:m.sonnet,onChange:C=>v({...m,sonnet:C}),catalog:l,allModels:d,routing:i}),e.jsx(we,{label:p("customPresetDialog.haikuModel"),description:p("customPresetDialog.haikuModelDesc"),value:m.haiku,onChange:C=>v({...m,haiku:C}),catalog:l,allModels:d,routing:i})]}),e.jsxs($s,{className:"gap-2 sm:gap-0",children:[e.jsx(U,{variant:"outline",onClick:a,children:p("customPresetDialog.cancel")}),r&&e.jsxs(U,{variant:"secondary",onClick:()=>r(m,x||void 0),disabled:o||!x.trim(),children:[o?e.jsx(ue,{className:"w-4 h-4 mr-1 animate-spin"}):e.jsx(Et,{className:"w-4 h-4 mr-1"}),p("customPresetDialog.savePreset")]}),e.jsxs(U,{onClick:()=>n(m,x||void 0),children:[e.jsx(_e,{className:"w-4 h-4 mr-1"}),p("customPresetDialog.applyPreset")]})]})]})})}function ye({label:t,command:a}){return e.jsxs("div",{children:[e.jsx("label",{className:"text-xs text-muted-foreground",children:t}),e.jsxs("div",{className:"mt-1 flex gap-2",children:[e.jsx("code",{className:"flex-1 px-2 py-1.5 bg-muted rounded text-xs font-mono truncate",children:a}),e.jsx(ms,{value:a,size:"icon",className:"h-6 w-6"})]})]})}function An({provider:t,displayName:a,baseProvider:s,defaultTarget:n,data:r,authStatus:o,supportsModelConfig:l=!1}){const{t:d}=W(),i=n||"claude",p=i==="droid",m=t==="codex",v=s||o.provider||t,x=Ws(v),b=i==="claude"?`ccs ${t}`:`ccs ${t} --target claude`,N=`${b} --config`,C=`${b} --auth --add`,T=`${b} --accounts`;return e.jsx(Pt,{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(gs,{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:d("providerEditor.provider")}),e.jsx("span",{className:"font-mono",children:a})]}),r&&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:d("providerEditor.filePath")}),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:r.path}),e.jsx(ms,{value:r.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:d("providerEditor.lastModified")}),e.jsx("span",{className:"text-xs",children:new Date(r.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:d("providerEditor.status")}),o.authenticated?e.jsxs(z,{variant:"outline",className:"w-fit text-green-600 border-green-200 bg-green-50",children:[e.jsx(Aa,{className:"w-3 h-3 mr-1"}),"Authenticated"]}):e.jsx(z,{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:d("providerEditor.defaultTarget")}),e.jsx("span",{className:"font-mono",children:i})]}),x&&e.jsxs("div",{className:"grid grid-cols-[100px_1fr] gap-2 text-sm items-start",children:[e.jsx("span",{className:"font-medium text-muted-foreground",children:d("providerConfig.trackLabel")}),e.jsxs("div",{className:"space-y-1",children:[e.jsx("span",{className:"font-mono",children:d(x.labelKey)}),e.jsxs("p",{className:"text-xs text-muted-foreground",children:[d(x.hintKey),Qs(v)?` ${d("providerConfig.plusTrackNote")}`:""]})]})]})]})]}),e.jsxs("div",{children:[e.jsx("h3",{className:"text-sm font-medium mb-3",children:d("providerEditor.quickUsage")}),e.jsxs("div",{className:"space-y-3 bg-card rounded-lg border p-4 shadow-sm",children:[e.jsx(ye,{label:"Run with prompt",command:`ccs ${t} "your prompt"`}),m&&e.jsxs(e.Fragment,{children:[e.jsx(ye,{label:"Run on native Codex (shortcut)",command:'ccsxp "your prompt"'}),e.jsx(ye,{label:"Run on native Codex (--target)",command:`ccs ${t} --target codex "your prompt"`})]}),e.jsx(ye,{label:p?"Droid alias (explicit)":"Run on Droid",command:`ccs-droid ${t} "your prompt"`}),e.jsx(ye,{label:p?"Override to Claude":"Run on Droid (--target)",command:`ccs ${t} --target ${p?"claude":"droid"} "your prompt"`}),l&&e.jsx(ye,{label:i==="claude"?"Change model":"Change model (Claude target)",command:N}),e.jsx(ye,{label:i==="claude"?"Add account":"Add account (Claude target)",command:C}),e.jsx(ye,{label:i==="claude"?"List accounts":"List accounts (Claude target)",command:T}),i!=="claude"&&e.jsx("p",{className:"text-xs text-muted-foreground",children:"Account and model-management flags stay on Claude target. Codex and Droid runtime launches reject those CLIProxy management commands."})]})]})]})})}function Sn(t){const a=t.replace(/\\/g,"/"),n=a.lastIndexOf("/cliproxy/providers/");return n!==-1?a.slice(n+1):a.replace(/^.*\//,"")}function Mn({displayName:t,logoProvider:a,provider:s,data:n,isLoading:r,hasChanges:o,isRawJsonValid:l,isSaving:d,isRemoteMode:i,port:p,onRefetch:m,onSave:v}){const{t:x}=W();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(Dt,{provider:a||s,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:t}),i&&e.jsxs(z,{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(vs,{className:"w-3 h-3"}),"Remote"]}),p&&e.jsxs(z,{variant:"outline",className:"text-xs gap-1 font-mono",children:[e.jsx(Sa,{className:"w-3 h-3"}),":",p]}),!i&&n?.path&&e.jsx(z,{variant:"outline",className:"text-xs",children:Sn(n.path)})]}),i?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:[x("providerEditor.lastModified"),": ",new Date(n.mtime).toLocaleString()]})]})]}),e.jsxs("div",{className:"flex items-center gap-2",children:[e.jsx(U,{variant:"ghost",size:"sm",onClick:m,disabled:r,children:e.jsx(at,{className:`w-4 h-4 ${r?"animate-spin":""}`})}),e.jsx(U,{size:"sm",onClick:v,disabled:d||!o||!l,children:d?e.jsxs(e.Fragment,{children:[e.jsx(ue,{className:"w-4 h-4 mr-1 animate-spin"}),"Saving..."]}):e.jsxs(e.Fragment,{children:[e.jsx(Ma,{className:"w-4 h-4 mr-1"}),"Save"]})})]})]})}function Pn({models:t,provider:a,enabled:s,onToggle:n,disabled:r,className:o}){const{t:l}=W();if(t.length===0)return null;const d=t.some(m=>Bt(m.id)),i=t.some(m=>!Bt(m.id));let p="Compatible mappings stay on standard context unless you turn this on.";return d&&i?p="Gemini-compatible mappings can use 1M automatically. Claude mappings stay plain unless you turn this on.":d&&(p="Gemini-compatible mappings can use 1M by default. Turn this off to keep standard context."),e.jsxs("div",{className:X("rounded-lg border p-3 space-y-2",s?"border-primary/50 bg-primary/5":"border-border bg-muted/30",o),children:[e.jsxs("div",{className:"flex items-center justify-between",children:[e.jsxs("div",{className:"flex items-center gap-2",children:[e.jsx(_e,{className:X("w-4 h-4",s?"text-primary":"text-muted-foreground")}),e.jsx("span",{className:"text-sm font-medium",children:l("extendedContext.extendedContext")}),e.jsx(z,{variant:s?"default":"secondary",className:"text-[10px] h-5 px-1.5",children:"1M tokens"})]}),e.jsx(ps,{checked:s,onCheckedChange:n,disabled:r})]}),e.jsxs("div",{className:"flex items-start gap-2 text-xs text-muted-foreground",children:[e.jsx(gs,{className:"w-3.5 h-3.5 mt-0.5 shrink-0"}),e.jsxs("div",{className:"space-y-1",children:[e.jsxs("p",{children:["Applies the explicit ",e.jsx("code",{children:"[1m]"})," long-context suffix to compatible saved mappings."]}),e.jsx("p",{className:"text-[10px]",children:p}),e.jsxs("p",{className:"text-amber-600 dark:text-amber-500",children:["CCS only saves ",e.jsx("code",{children:"[1m]"}),". Provider pricing and entitlement are separate, and some accounts can still return 429 extra-usage errors for long-context requests."]})]})]})]})}function Dn(t,a){const s=t.presetMapping||{default:t.id,opus:t.id,sonnet:t.id,haiku:t.id};return{ANTHROPIC_MODEL:a(s.default),ANTHROPIC_DEFAULT_OPUS_MODEL:a(s.opus),ANTHROPIC_DEFAULT_SONNET_MODEL:a(s.sonnet),ANTHROPIC_DEFAULT_HAIKU_MODEL:a(s.haiku)}}function In({catalog:t,savedPresets:a,currentModel:s,opusModel:n,sonnetModel:r,haikuModel:o,providerModels:l,routing:d,provider:i,extendedContextEnabled:p,onExtendedContextToggle:m,onApplyPreset:v,onUpdateEnvValue:x,onOpenCustomPreset:b,onDeletePreset:N,isDeletePending:C}){const{t:T}=W(),M=(d?.models??[]).some(u=>u.pinnedAvailable),S=c.useMemo(()=>new Map((d?.models??[]).map(u=>[u.modelId.toLowerCase(),u])),[d]),w=u=>S.get(u.toLowerCase())?.recommendedModelId??u,y=c.useMemo(()=>{if(!t)return[];const u=[s,n,r,o].filter(A=>!!A).map(A=>Js(A));return[...new Set(u)].map(A=>ks(t.provider,A,t)).filter(A=>!!A?.extendedContext)},[t,s,n,r,o]),h=c.useMemo(()=>Lt(t,l),[t,l]),g=c.useMemo(()=>{const u=h.filter(A=>A.presetMapping);return u.length===0?[]:u.some(A=>A.tier==="paid")?[{key:"free",label:"Free Tier",description:"Available on free or paid plans",badgeClassName:"text-[10px] bg-green-100 text-green-700 border-green-200",iconClassName:"text-green-600",models:u.filter(A=>A.tier!=="paid")},{key:"paid",label:"Paid Tier",description:"Requires paid access",badgeClassName:"text-[10px] bg-amber-100 text-amber-700 border-amber-200",iconClassName:"text-amber-700",models:u.filter(A=>A.tier==="paid")}].filter(A=>A.models.length>0):[{key:"default",models:u.slice(0,4)}]},[h]),E=g.length>0||a.length>0;return e.jsxs(e.Fragment,{children:[E&&e.jsxs("div",{children:[e.jsxs("h3",{className:"text-sm font-medium mb-2 flex items-center gap-2",children:[e.jsx(Tt,{className:"w-4 h-4"}),"Presets"]}),e.jsx("p",{className:"text-xs text-muted-foreground mb-3",children:T("providerEditor.presets")}),e.jsxs("div",{className:"space-y-4",children:[g.map(u=>e.jsxs("div",{children:["label"in u&&u.label&&e.jsxs("div",{className:"flex items-center gap-2 mb-2",children:[e.jsx(z,{variant:"outline",className:u.badgeClassName,children:u.label}),e.jsx("span",{className:"text-[10px] text-muted-foreground",children:u.description})]}),e.jsx("div",{className:"flex flex-wrap gap-2",children:u.models.map(I=>e.jsxs(U,{variant:"outline",size:"sm",className:"text-xs h-7 gap-1",onClick:()=>v(Dn(I,w)),children:[e.jsx(_e,{className:`w-3 h-3 ${"iconClassName"in u?u.iconClassName:""}`}),I.name]},I.id))})]},u.key)),e.jsxs("div",{className:"flex flex-wrap gap-2",children:[a.map(u=>e.jsxs("div",{className:"group relative",children:[e.jsxs(U,{variant:"secondary",size:"sm",className:"text-xs h-7 gap-1 pr-6",onClick:()=>{v({ANTHROPIC_MODEL:w(u.default),ANTHROPIC_DEFAULT_OPUS_MODEL:w(u.opus),ANTHROPIC_DEFAULT_SONNET_MODEL:w(u.sonnet),ANTHROPIC_DEFAULT_HAIKU_MODEL:w(u.haiku)})},children:[e.jsx(Et,{className:"w-3 h-3 fill-current"}),u.name]}),e.jsx(U,{variant:"ghost",size:"icon",className:"absolute right-0 top-0 h-7 w-5 opacity-0 group-hover:opacity-100 hover:text-destructive",onClick:I=>{I.stopPropagation(),N(u.name)},disabled:C,children:e.jsx(Rt,{className:"w-3 h-3"})})]},u.name)),e.jsxs(U,{variant:"outline",size:"sm",className:"text-xs h-7 gap-1 border-primary/50 text-primary hover:bg-primary/10 hover:border-primary",onClick:b,children:[e.jsx(nt,{className:"w-3 h-3"}),"Custom"]})]})]})]}),e.jsx(Ot,{}),e.jsxs("div",{children:[e.jsx("h3",{className:"text-sm font-medium mb-2",children:T("providerEditor.modelMapping")}),e.jsx("p",{className:"text-xs text-muted-foreground mb-4",children:"Configure which models to use for each tier"}),d?e.jsx("p",{className:"text-[11px] text-muted-foreground mb-3 rounded-md border bg-muted/30 px-2.5 py-2",children:M?e.jsxs(e.Fragment,{children:["Preferred pinned model names use the ",e.jsxs("code",{children:[d.prefix,"/"]})," prefix. Unprefixed names can still resolve to a different backend when providers overlap."]}):e.jsxs(e.Fragment,{children:["Managed pinning for ",e.jsxs("code",{children:[d.prefix,"/"]})," is not currently advertised by the proxy. Unprefixed names may still be ambiguous until prefix repair completes."]})}):null,i==="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:"-minimal"}),", ",e.jsx("code",{children:"-low"}),", ",e.jsx("code",{children:"-medium"}),","," ",e.jsx("code",{children:"-high"}),", and ",e.jsx("code",{children:"-xhigh"})," pin reasoning effort. ",e.jsx("code",{children:"-fast"})," ","enables the Codex fast service tier on models that support it, including combined forms such as ",e.jsx("code",{children:"gpt-5.4-high-fast"}),"."]}),e.jsxs("div",{className:"space-y-4",children:[e.jsx(we,{label:"Default Model",description:"Used when no specific tier is requested",value:s,onChange:u=>x("ANTHROPIC_MODEL",u),catalog:t,allModels:l,routing:d}),y.length>0&&m&&e.jsx(Pn,{models:y,provider:i,enabled:p??!1,onToggle:m}),e.jsx(we,{label:"Opus (Most capable)",description:"For complex reasoning tasks",value:n,onChange:u=>x("ANTHROPIC_DEFAULT_OPUS_MODEL",u),catalog:t,allModels:l,routing:d}),e.jsx(we,{label:"Sonnet (Balanced)",description:"Balance of speed and capability",value:r,onChange:u=>x("ANTHROPIC_DEFAULT_SONNET_MODEL",u),catalog:t,allModels:l,routing:d}),e.jsx(we,{label:"Haiku (Fast)",description:"Quick responses for simple tasks",value:o,onChange:u=>x("ANTHROPIC_DEFAULT_HAIKU_MODEL",u),catalog:t,allModels:l,routing:d})]})]})]})}function Tn(t,a,s){return t?e.jsx(ft,{children:e.jsxs(gt,{children:[e.jsx(vt,{asChild:!0,children:e.jsxs("div",{className:"flex items-center gap-1.5 text-xs text-muted-foreground",children:[e.jsx(Da,{className:"w-3 h-3","aria-hidden":"true"}),e.jsx("span",{className:X("font-mono max-w-[180px] truncate",a&&kt),title:t,children:t})]})}),e.jsx(jt,{side:"bottom",children:e.jsx("p",{className:"text-xs",children:s("providerEditor.gcpProjectIdReadonly")})})]})}):e.jsx(ft,{children:e.jsxs(gt,{children:[e.jsx(vt,{asChild:!0,children:e.jsxs("div",{className:"flex items-center gap-1 text-xs text-amber-600 dark:text-amber-500",children:[e.jsx(et,{className:"w-3 h-3","aria-label":"Warning"}),e.jsx("span",{children:s("providerEditor.projectIdNA")})]})}),e.jsx(jt,{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:s("providerEditor.missingProjectId")}),e.jsx("p",{children:s("providerEditor.missingProjectIdHint")})]})})]})})}function En({account:t,onSetDefault:a,onRemove:s,onReauth:n,onPauseToggle:r,isRemoving:o,isPausingAccount:l,privacyMode:d,showQuota:i,selectable:p,selected:m,onSelectChange:v}){const{t:x}=W(),b=t.provider.toLowerCase(),{data:N}=Xs(i),{data:C,isLoading:T}=Ys(b,t.id,i),M=Zs(N,t)?.lastUsedAt,S=p||r?e.jsxs("div",{className:"flex items-center gap-2 shrink-0",children:[p&&e.jsx("button",{type:"button",onClick:()=>v?.(!m),className:X("flex items-center justify-center w-5 h-5 rounded border-2 transition-colors shrink-0",m?"bg-primary border-primary text-primary-foreground":"border-muted-foreground/30 hover:border-primary/50"),"aria-label":m?"Deselect account":"Select account",children:m&&e.jsx(Pe,{className:"w-3 h-3"})}),r&&e.jsx(ft,{children:e.jsxs(gt,{children:[e.jsx(vt,{asChild:!0,children:e.jsx(U,{variant:"ghost",size:"icon",className:"h-7 w-7 shrink-0",onClick:()=>r(!t.paused),disabled:l,children:l?e.jsx(ue,{className:"w-4 h-4 animate-spin"}):t.paused?e.jsx(js,{className:"w-4 h-4 text-emerald-500"}):e.jsx(bs,{className:"w-4 h-4 text-muted-foreground hover:text-foreground"})})}),e.jsx(jt,{side:"top",children:t.paused?"Resume account":"Pause account"})]})})]}):void 0,w=e.jsxs(ea,{children:[e.jsx(ta,{asChild:!0,children:e.jsx(U,{variant:"ghost",size:"icon",className:"h-7 w-7 shrink-0",children:e.jsx(Pa,{className:"w-4 h-4"})})}),e.jsxs(sa,{align:"end",children:[!t.isDefault&&e.jsxs(ct,{onClick:a,children:[e.jsx(Et,{className:"w-4 h-4 mr-2"}),"Set as default"]}),n&&e.jsxs(ct,{onClick:n,children:[e.jsx(at,{className:"w-4 h-4 mr-2"}),"Reauthenticate"]}),e.jsxs(ct,{className:"text-destructive focus:text-destructive",onClick:s,disabled:o,children:[e.jsx(Ns,{className:"w-4 h-4 mr-2"}),o?"Removing...":"Remove account"]})]})]});return e.jsx("div",{className:X("rounded-lg border p-3 transition-colors overflow-hidden",t.isDefault?"border-primary/30 bg-primary/5":"border-border hover:bg-muted/30",t.paused&&"opacity-75",m&&"ring-2 ring-primary/50 bg-primary/5"),children:e.jsx(aa,{mode:"detailed",provider:t.provider,accountId:t.id,email:t.email,displayEmail:t.email||t.id,tokenFile:t.tokenFile,tier:t.tier,isDefault:t.isDefault,paused:t.paused,privacyMode:d,showQuota:i,quota:C,quotaLoading:T,runtimeLastUsed:M,beforeIdentity:S,headerEnd:w,bodySlot:t.provider==="agy"?Tn(t.projectId,d,x):null,quotaInsetClassName:"pl-11"})})}function Rn({selectedCount:t,onPauseSelected:a,onResumeSelected:s,onClearSelection:n,isPausing:r,isResuming:o}){if(t<1)return null;const l=r||o;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:[t," selected"]}),e.jsx(U,{variant:"ghost",size:"sm",className:"text-xs h-6 px-2",onClick:n,disabled:l,children:"Clear"}),e.jsxs("div",{className:"flex gap-2 ml-auto",children:[e.jsxs(U,{size:"sm",variant:"outline",className:"h-7 text-xs gap-1",onClick:a,disabled:l,children:[r?e.jsx(ue,{className:"w-3 h-3 animate-spin"}):e.jsx(bs,{className:"w-3 h-3"}),"Pause Selected"]}),e.jsxs(U,{size:"sm",variant:"outline",className:"h-7 text-xs gap-1",onClick:s,disabled:l,children:[o?e.jsx(ue,{className:"w-3 h-3 animate-spin"}):e.jsx(js,{className:"w-3 h-3"}),"Resume Selected"]})]})]})}function On({accounts:t,onAddAccount:a,onReauthAccount:s,onSetDefault:n,onRemoveAccount:r,onPauseToggle:o,onSoloMode:l,onBulkPause:d,onBulkResume:i,isRemovingAccount:p,isPausingAccount:m,isSoloingAccount:v,isBulkPausing:x,isBulkResuming:b,privacyMode:N,showQuota:C,isKiro:T,kiroNoIncognito:M,onKiroNoIncognitoChange:S,kiroSettingsLoading:w}){const{t:y}=W(),[h,g]=c.useState(new Set),E=c.useMemo(()=>new Set(t.map(k=>k.id)),[t]),u=c.useMemo(()=>new Set([...h].filter(k=>E.has(k))),[h,E]),I=!!(d&&i),A=u.size,q=t.length>0&&u.size===t.length,P=u.size>0&&u.size<t.length,_=c.useCallback(k=>{g(Q=>{const j=new Set(Q);return j.has(k)?j.delete(k):j.add(k),j})},[]),H=c.useCallback(()=>{g(new Set(t.map(k=>k.id)))},[t]),G=c.useCallback(()=>{g(new Set)},[]),V=c.useCallback(()=>{q?G():H()},[q,H,G]),R=c.useCallback(()=>{d&&u.size>0&&(d(Array.from(u)),g(new Set))},[d,u]),O=c.useCallback(()=>{i&&u.size>0&&(i(Array.from(u)),g(new Set))},[i,u]);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:[I&&t.length>0&&e.jsx(Ze,{checked:q,onCheckedChange:V,"aria-label":"Select all accounts",className:P?"data-[state=checked]:bg-primary/50":"",...P?{"data-state":"indeterminate"}:{}}),e.jsx(Oe,{className:"w-4 h-4"}),y("providerEditor.accounts"),t.length>0&&e.jsx(z,{variant:"secondary",className:"text-xs",children:t.length})]}),e.jsxs(U,{variant:"default",size:"sm",className:"h-7 text-xs gap-1",onClick:a,children:[e.jsx(nt,{className:"w-3 h-3"}),y("providerEditor.addAccount")]})]}),I&&A>0&&e.jsx(Rn,{selectedCount:A,onPauseSelected:R,onResumeSelected:O,onClearSelection:G,isPausing:!!x,isResuming:!!b}),t.length>0?e.jsx("div",{className:"space-y-2",children:t.map(k=>e.jsx(En,{account:k,onSetDefault:()=>n(k.id),onRemove:()=>r(k.id),onReauth:s?()=>s(k):void 0,onPauseToggle:o?Q=>o(k.id,Q):void 0,onSoloMode:l?()=>l(k.id):void 0,isRemoving:p,isPausingAccount:m,isSoloingAccount:v,privacyMode:N,showQuota:C,selectable:I,selected:u.has(k.id),onSelectChange:()=>_(k.id)},k.id))}):e.jsxs("div",{className:"py-6 text-center text-muted-foreground bg-muted/30 rounded-lg border border-dashed",children:[e.jsx(Oe,{className:"w-8 h-8 mx-auto mb-2 opacity-50"}),e.jsx("p",{className:"text-sm",children:y("providerEditor.noAccountsConnected")}),e.jsx("p",{className:"text-xs opacity-70",children:y("providerEditor.addAccountToStart")})]}),T&&S&&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(vs,{className:"w-3.5 h-3.5"}),e.jsx("span",{children:y("providerEditor.useIncognito")})]}),e.jsx(ps,{checked:!M,onCheckedChange:k=>S(!k),disabled:w,className:"scale-90"})]})})]})}function _n({provider:t,catalog:a,savedPresets:s,currentModel:n,opusModel:r,sonnetModel:o,haikuModel:l,providerModels:d,routing:i,extendedContextEnabled:p,onExtendedContextToggle:m,onApplyPreset:v,onUpdateEnvValue:x,onOpenCustomPreset:b,onDeletePreset:N,isDeletePending:C,accounts:T,onAddAccount:M,onReauthAccount:S,onSetDefault:w,onRemoveAccount:y,onPauseToggle:h,onSoloMode:g,onBulkPause:E,onBulkResume:u,isRemovingAccount:I,isPausingAccount:A,isSoloingAccount:q,isBulkPausing:P,isBulkResuming:_,privacyMode:H,isRemoteMode:G}){const V=t.toLowerCase(),R=(na.includes(V)||["anthropic","antigravity","gemini-cli","copilot","github-copilot"].includes(V))&&!G,O=t==="kiro",[k,Q]=c.useState(!0),[j,Y]=c.useState(!0),[se,le]=c.useState(!1),K=c.useCallback(async()=>{if(O)try{Y(!0);const Z=(await Xe.config.get()).cliproxy;Q(Z?.kiro_no_incognito??!0)}catch{Q(!0)}finally{Y(!1)}},[O]),re=c.useCallback(async $=>{Q($),le(!0);try{const Z=await Xe.config.get(),ie=Z.cliproxy??{};await Xe.config.update({...Z,cliproxy:{...ie,kiro_no_incognito:$}})}catch{Q(!$)}finally{le(!1)}},[]);return c.useEffect(()=>{K()},[K]),e.jsx(Pt,{className:"flex-1",children:e.jsxs("div",{className:"p-4 space-y-6",children:[e.jsx(In,{catalog:a,savedPresets:s,currentModel:n,opusModel:r,sonnetModel:o,haikuModel:l,providerModels:d,routing:i,provider:t,extendedContextEnabled:p,onExtendedContextToggle:m,onApplyPreset:v,onUpdateEnvValue:x,onOpenCustomPreset:b,onDeletePreset:N,isDeletePending:C}),e.jsx(Ot,{}),e.jsx(On,{accounts:T,onAddAccount:M,onReauthAccount:S,onSetDefault:w,onRemoveAccount:y,onPauseToggle:h,onSoloMode:g,onBulkPause:E,onBulkResume:u,isRemovingAccount:I,isPausingAccount:A,isSoloingAccount:q,isBulkPausing:P,isBulkResuming:_,privacyMode:H,showQuota:R,isKiro:O,kiroNoIncognito:k,onKiroNoIncognitoChange:re,kiroSettingsLoading:j||se})]})})}function ts({provider:t,displayName:a,authStatus:s,catalog:n,routing:r,logoProvider:o,baseProvider:l,isRemoteMode:d,port:i,defaultTarget:p,topNotice:m,onAddAccount:v,onReauthAccount:x,onSetDefault:b,onRemoveAccount:N,onPauseToggle:C,onSoloMode:T,onBulkPause:M,onBulkResume:S,isRemovingAccount:w,isPausingAccount:y,isSoloingAccount:h,isBulkPausing:g,isBulkResuming:E}){const[u,I]=c.useState(!1),{privacyMode:A}=ds(),{t:q}=W(),{data:P}=ra(),{data:_}=ia(t),H=oa(),G=la(),V=l||t,R=V.toLowerCase()==="agy",O=c.useMemo(()=>{const L=_?.presets||[];return R?L.filter(te=>!xe(te.default)&&!xe(te.opus)&&!xe(te.sonnet)&&!xe(te.haiku)):L},[R,_?.presets]),k=c.useMemo(()=>{if(!P?.models)return[];const te={gemini:["google"],agy:["antigravity"],codex:["openai"],cursor:["cursor"],gitlab:["gitlab","duo"],codebuddy:["codebuddy"],qwen:["alibaba","qwen"],iflow:["iflow"],kilo:["kilo"],kiro:["kiro","aws"],ghcp:["github","copilot"],kimi:["kimi","moonshot"]}[V.toLowerCase()]||[V.toLowerCase()];return P.models.filter(ae=>te.some(De=>ae.owned_by.toLowerCase().includes(De))?R?!xe(ae.id):!0:!1)},[R,P,V]),Q=(l||t).toLowerCase(),{data:j,isLoading:Y,refetch:se,rawJsonContent:le,rawJsonEdits:K,isRawJsonValid:re,hasChanges:$,currentModel:Z,opusModel:ie,sonnetModel:be,haikuModel:fe,extendedContextEnabled:ke,toggleExtendedContext:Ce,handleRawJsonChange:f,updateEnvValue:F,updateEnvValues:ge,saveMutation:me,conflictDialog:pe,handleConflictResolve:Ae,missingRequiredFields:it}=fn(t,n),ot=c.useMemo(()=>(s.accounts||[]).map(L=>({...L,provider:L.provider||l||t})),[s.accounts,l,t]),{data:de}=ss({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}),Le=de?.apiKey?.value??"ccs-internal-managed",Fe=L=>{if(R&&[L.ANTHROPIC_MODEL,L.ANTHROPIC_DEFAULT_OPUS_MODEL,L.ANTHROPIC_DEFAULT_SONNET_MODEL,L.ANTHROPIC_DEFAULT_HAIKU_MODEL].some(ae=>typeof ae=="string"&&xe(ae))){B.error(q("providerEditor.agyDenylist"));return}ge({ANTHROPIC_BASE_URL:`http://127.0.0.1:${i??bt}/api/provider/${Q}`,ANTHROPIC_AUTH_TOKEN:Le,...L}),B.success(`Applied "${L.ANTHROPIC_MODEL?.split("/").pop()||"preset"}" preset`)},Ue=(L,te)=>{if(R&&[L.default,L.opus,L.sonnet,L.haiku].some(De=>xe(De))){B.error(q("providerEditor.agyDenylist"));return}ge({ANTHROPIC_BASE_URL:`http://127.0.0.1:${i??bt}/api/provider/${Q}`,ANTHROPIC_AUTH_TOKEN:Le,ANTHROPIC_MODEL:L.default,ANTHROPIC_DEFAULT_OPUS_MODEL:L.opus,ANTHROPIC_DEFAULT_SONNET_MODEL:L.sonnet,ANTHROPIC_DEFAULT_HAIKU_MODEL:L.haiku}),B.success(`Applied ${te?`"${te}"`:"custom"} preset`),I(!1)},Ke=(L,te)=>{if(!te){B.error(he.t("commonToast.enterPresetName"));return}if(R&&[L.default,L.opus,L.sonnet,L.haiku].some(ae=>xe(ae))){B.error(q("providerEditor.agyDenylist"));return}H.mutate({profile:t,data:{name:te,...L}}),I(!1)};return e.jsxs("div",{className:"flex-1 flex flex-col overflow-hidden",children:[e.jsx(Mn,{provider:t,displayName:a,logoProvider:o,data:j,isLoading:Y,hasChanges:$,isRawJsonValid:re,isSaving:me.isPending,isRemoteMode:d,port:i,onRefetch:se,onSave:()=>me.mutate()}),m?e.jsx("div",{className:"border-b bg-muted/10 px-4 py-3",children:m}):null,Y?e.jsxs("div",{className:"flex-1 flex items-center justify-center",children:[e.jsx(ue,{className:"w-8 h-8 animate-spin text-muted-foreground"}),e.jsx("span",{className:"ml-3 text-muted-foreground",children:q("providerEditor.loadingSettings")})]}):e.jsxs("div",{className:"min-h-0 flex-1 grid grid-cols-[40%_60%] divide-x overflow-hidden",children:[e.jsx("div",{className:"flex min-h-0 min-w-0 flex-col overflow-hidden bg-muted/5",children:e.jsxs(da,{defaultValue:"config",className:"h-full flex flex-col",children:[e.jsx("div",{className:"px-4 pt-4 shrink-0",children:e.jsxs(ca,{className:"w-full",children:[e.jsx(Vt,{value:"config",className:"flex-1",children:"Model Config"}),e.jsx(Vt,{value:"info",className:"flex-1",children:"Info & Usage"})]})}),e.jsxs("div",{className:"flex-1 overflow-hidden flex flex-col",children:[e.jsx($t,{value:"config",className:"flex-1 mt-0 border-0 p-0 data-[state=inactive]:hidden flex flex-col overflow-hidden",children:e.jsx(_n,{provider:t,catalog:n,savedPresets:O,currentModel:Z,opusModel:ie,sonnetModel:be,haikuModel:fe,providerModels:k,routing:r,extendedContextEnabled:ke,onExtendedContextToggle:Ce,onApplyPreset:Fe,onUpdateEnvValue:F,onOpenCustomPreset:()=>I(!0),onDeletePreset:L=>G.mutate({profile:t,name:L}),isDeletePending:G.isPending,accounts:ot,onAddAccount:v,onReauthAccount:x,onSetDefault:b,onRemoveAccount:N,onPauseToggle:C,onSoloMode:T,onBulkPause:M,onBulkResume:S,isRemovingAccount:w,isPausingAccount:y,isSoloingAccount:h,isBulkPausing:g,isBulkResuming:E,privacyMode:A,isRemoteMode:d})}),e.jsx($t,{value:"info",className:"h-full mt-0 border-0 p-0 data-[state=inactive]:hidden",children:e.jsx(An,{provider:t,displayName:a,baseProvider:l,defaultTarget:p,data:j,authStatus:s,supportsModelConfig:!!n})})]})]})}),e.jsxs("div",{className:"flex min-h-0 min-w-0 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(Ia,{className:"w-4 h-4 text-muted-foreground"}),e.jsxs("span",{className:"text-sm font-medium text-muted-foreground",children:[q("rawEditorSection.rawConfig")," (JSON)"]})]}),e.jsx(ua,{rawJsonContent:le,isRawJsonValid:re,rawJsonEdits:K,onRawJsonChange:f,profileEnv:j?.settings?.env,missingRequiredFields:it})]})]}),e.jsx(Ra,{open:pe,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(Cn,{open:u,onClose:()=>I(!1),currentValues:{default:Z||"",opus:ie||"",sonnet:be||"",haiku:fe||""},onApply:Ue,onSave:Ke,isSaving:H.isPending,catalog:n,allModels:k,routing:r})]})}function Ln({status:t,isSelected:a,onSelect:s}){const{t:n}=W(),r=t.accounts?.length||0;return e.jsxs("button",{className:X("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:s,children:[e.jsx(Dt,{provider:t.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:t.displayName}),r>0&&e.jsx(z,{variant:"secondary",className:"text-[10px] h-4 px-1",children:r})]}),e.jsx("div",{className:"flex items-center gap-1.5 mt-0.5",children:t.authenticated?e.jsxs(e.Fragment,{children:[e.jsx(Pe,{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(Rt,{className:"w-3 h-3 text-muted-foreground"}),e.jsx("span",{className:"text-xs text-muted-foreground",children:n("cliproxyPage.notConnected")})]})})]})]})}function Fn({variant:t,parentAuth:a,isSelected:s,onSelect:n,onDelete:r,isDeleting:o}){const{t:l}=W(),d=()=>{n()};return e.jsxs("div",{role:"button",tabIndex:0,className:X("group w-full flex items-center gap-3 px-3 py-2 rounded-lg transition-colors cursor-pointer text-left pl-6",s?"bg-primary/10 border border-primary/20":"hover:bg-muted border border-transparent"),onClick:d,onKeyDown:i=>{(i.key==="Enter"||i.key===" ")&&(i.preventDefault(),d())},children:[e.jsxs("div",{className:"relative",children:[e.jsx(Dt,{provider:t.provider,size:"sm"}),e.jsx(tt,{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:t.name}),e.jsx(z,{variant:"outline",className:"text-[9px] h-4 px-1",children:l("cliproxyPage.variant")}),e.jsx(z,{variant:"outline",className:"text-[9px] h-4 px-1 uppercase",children:t.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(Pe,{className:"w-3 h-3 text-green-600"}),e.jsx("span",{className:"text-xs text-muted-foreground truncate",children:l("cliproxyPage.viaProvider",{provider:t.provider})})]}):e.jsxs(e.Fragment,{children:[e.jsx(Rt,{className:"w-3 h-3 text-muted-foreground"}),e.jsx("span",{className:"text-xs text-muted-foreground",children:l("cliproxyPage.parentNotConnected")})]})})]}),e.jsx(U,{variant:"ghost",size:"icon",className:"h-6 w-6 opacity-0 group-hover:opacity-100 hover:text-destructive",onClick:i=>{i.stopPropagation(),r()},disabled:o,children:e.jsx(Ns,{className:"w-3 h-3"})})]})}function Un({onAddAccount:t,onCreateVariant:a}){const{t:s}=W();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(_e,{className:"w-8 h-8 text-muted-foreground"})}),e.jsx("h2",{className:"text-xl font-semibold mb-2",children:s("cliproxyPage.emptyTitle")}),e.jsx("p",{className:"text-muted-foreground mb-4",children:s("cliproxyPage.emptyDesc")}),e.jsxs("p",{className:"text-xs text-muted-foreground mb-6",children:[s("cliproxyPage.emptyControlPanelPrefix")," ",e.jsx("a",{href:"/cliproxy/control-panel",className:"text-primary hover:underline",children:s("cliproxyPage.controlPanel")}),"."]}),e.jsxs("div",{className:"flex flex-col justify-center gap-2 sm:flex-row",children:[e.jsxs(U,{onClick:t,className:"gap-2",children:[e.jsx(nt,{className:"w-4 h-4"}),s("cliproxyPage.addAccount")]}),e.jsxs(U,{onClick:a,variant:"outline",className:"gap-2",children:[e.jsx(tt,{className:"w-4 h-4"}),s("cliproxyPage.advancedVariant")]})]})]})})}function nr(){const{t}=W(),a=wt(),{data:s,isLoading:n}=os(),{data:r,isFetching:o}=ma(),{data:l}=ls(),{data:d}=pa(),i=xa(),p=ha(),m=fa(),v=ga(),x=va(),b=ja(),N=ba(),C=Na(),[T,M]=c.useState(()=>{if(typeof window<"u"){const F=new URLSearchParams(window.location.search).get("provider")?.trim().toLowerCase();return F&&Re(F)?F:localStorage.getItem("cliproxy-selected-provider")}return null}),[S,w]=c.useState(null),[y,h]=c.useState(!1),[g,E]=c.useState(()=>{if(typeof window>"u")return null;const f=new URLSearchParams(window.location.search),F=f.get("provider")?.trim().toLowerCase();return f.get("action")!=="auth"||!F||!Re(F)?null:{provider:F,displayName:ze(F),isFirstAccount:!1}}),u=c.useMemo(()=>s?.authStatus||[],[s?.authStatus]),I=c.useMemo(()=>ya(u,f=>f.provider),[u]),A=s?.source==="remote",q=c.useMemo(()=>r?.variants||[],[r?.variants]),P=c.useMemo(()=>_t(l?.catalogs),[l?.catalogs]),_=l?.routing??{},H=!!l,G=f=>{M(f),f&&localStorage.setItem("cliproxy-selected-provider",f)},V=c.useMemo(()=>S?null:T&&u.some(f=>f.provider===T)?T:u.length>0&&(u.find(F=>(F.accounts?.length||0)>0)?.provider||u[0]?.provider)||null,[T,S,u]),R=u.find(f=>f.provider===V),O=q.find(f=>f.name===S),k=O?u.find(f=>f.provider===O.provider):void 0,Q=O&&k?{provider:O.provider,displayName:k.displayName,accountCount:k.accounts?.length||0}:R?{provider:R.provider,displayName:R.displayName,accountCount:R.accounts?.length||0}:null,j=O?{provider:O.provider,displayName:ze(O.provider),accountCount:0}:T&&Re(T)?{provider:T,displayName:ze(T),accountCount:0}:{provider:"gemini",displayName:ze("gemini"),accountCount:0},Y=Q??j,se=(O?.provider||R?.provider||"").toLowerCase().trim(),le=se==="gemini"||se==="agy",K=()=>{a.invalidateQueries({queryKey:["cliproxy"]}),a.invalidateQueries({queryKey:["cliproxy-auth"]}),a.invalidateQueries({queryKey:["cliproxy-catalog"]}),a.invalidateQueries({queryKey:["cliproxy-models"]})},re=(f,F,ge)=>{m.isPending||v.isPending||(ge?m.mutate({provider:f,accountId:F}):v.mutate({provider:f,accountId:F}))},$=(f,F)=>{x.isPending||x.mutate({provider:f,accountId:F})},Z=(f,F)=>{b.isPending||b.mutate({provider:f,accountIds:F})},ie=(f,F)=>{N.isPending||N.mutate({provider:f,accountIds:F})},be=f=>{G(f),w(null)},fe=f=>{w(f),G(null)},ke=()=>{E({provider:Y.provider,displayName:Y.displayName,isFirstAccount:Y.accountCount===0})},Ce=(f,F,ge,me)=>{const pe=ge?.find(Ae=>Ae.id===me);pe&&E({provider:f,displayName:F,isFirstAccount:!1,account:pe})};return e.jsxs("div",{className:"flex h-full min-h-0 overflow-hidden",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(_e,{className:"w-5 h-5 text-primary"}),e.jsx("h1",{className:"font-semibold",children:d?.backendLabel??"CLIProxy"})]}),e.jsx(U,{variant:"ghost",size:"icon",className:"h-8 w-8",onClick:K,disabled:o,children:e.jsx(at,{className:X("w-4 h-4",o&&"animate-spin")})})]}),e.jsx("p",{className:"text-xs text-muted-foreground mb-3",children:t("cliproxyPage.accountManagement")}),e.jsxs("div",{className:"space-y-2",children:[e.jsxs(U,{variant:"default",size:"sm",className:"w-full gap-2",onClick:ke,children:[e.jsx(nt,{className:"w-4 h-4"}),t("cliproxyPage.addAccount")]}),e.jsxs(U,{variant:"outline",size:"sm",className:"w-full gap-2",onClick:()=>h(!0),children:[e.jsx(tt,{className:"w-4 h-4"}),t("cliproxyPage.advancedVariant")]}),e.jsx("p",{className:"text-[11px] leading-relaxed text-muted-foreground",children:t("cliproxyPage.setupActionsHint")})]})]}),e.jsx(Pt,{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:t("cliproxyPage.providers")}),n?e.jsx("div",{className:"space-y-2 px-2",children:[1,2,3,4].map(f=>e.jsx(wa,{className:"h-14 w-full rounded-lg"},f))}):e.jsx("div",{className:"space-y-4",children:I.map(f=>e.jsxs("div",{className:"space-y-1",children:[e.jsxs("div",{className:"px-3",children:[e.jsx("div",{className:"text-[11px] font-medium uppercase tracking-wide text-muted-foreground",children:t(f.labelKey)}),e.jsx("p",{className:"mt-1 text-[11px] leading-relaxed text-muted-foreground",children:t(f.hintKey)})]}),e.jsx("div",{className:"space-y-1",children:f.items.map(F=>e.jsx(Ln,{status:F,isSelected:V===F.provider,onSelect:()=>be(F.provider)},F.provider))})]},f.id))}),q.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(tt,{className:"w-3 h-3"}),t("cliproxyPage.variants")]}),e.jsx("div",{className:"space-y-1",children:q.map(f=>e.jsx(Fn,{variant:f,parentAuth:u.find(F=>F.provider===f.provider),isSelected:S===f.name,onSelect:()=>fe(f.name),onDelete:()=>C.mutate(f.name),isDeleting:C.isPending},f.name))})]})]})}),e.jsx("div",{className:"p-3 border-t",children:e.jsx(_a,{})}),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:t("cliproxyPage.providerCount",{count:u.length})}),e.jsxs("span",{className:"flex items-center gap-1",children:[e.jsx(Pe,{className:"w-3 h-3 text-green-600"}),t("cliproxyPage.connectedCount",{count:u.filter(f=>f.authenticated).length})]})]})})]}),e.jsx("div",{className:"flex-1 flex min-w-0 flex-col overflow-hidden bg-background",children:O&&k?e.jsx(e.Fragment,{children:e.jsx(ts,{provider:O.name,displayName:t("cliproxyPage.variantDisplay",{name:O.name,provider:O.provider}),authStatus:k,catalog:P[O.provider],routing:_[O.provider],logoProvider:O.provider,baseProvider:O.provider,defaultTarget:O.target,isRemoteMode:A,port:O.port,topNotice:le?e.jsx(yt,{compact:!0,showProxySettingsLink:!0}):void 0,onAddAccount:()=>E({provider:O.provider,displayName:k.displayName,isFirstAccount:(k.accounts?.length||0)===0}),onReauthAccount:f=>Ce(O.provider,k.displayName,k.accounts,f.id),onSetDefault:f=>i.mutate({provider:O.provider,accountId:f}),onRemoveAccount:f=>p.mutate({provider:O.provider,accountId:f}),onPauseToggle:(f,F)=>re(O.provider,f,F),onSoloMode:f=>$(O.provider,f),onBulkPause:f=>Z(O.provider,f),onBulkResume:f=>ie(O.provider,f),isRemovingAccount:p.isPending,isPausingAccount:m.isPending||v.isPending,isSoloingAccount:x.isPending,isBulkPausing:b.isPending,isBulkResuming:N.isPending})}):R?e.jsx(e.Fragment,{children:e.jsx(ts,{provider:R.provider,displayName:R.displayName,authStatus:R,catalog:P[R.provider],routing:_[R.provider],isRemoteMode:A,topNotice:le?e.jsx(yt,{compact:!0,showProxySettingsLink:!0}):void 0,onAddAccount:()=>E({provider:R.provider,displayName:R.displayName,isFirstAccount:(R.accounts?.length||0)===0}),onReauthAccount:f=>Ce(R.provider,R.displayName,R.accounts,f.id),onSetDefault:f=>i.mutate({provider:R.provider,accountId:f}),onRemoveAccount:f=>p.mutate({provider:R.provider,accountId:f}),onPauseToggle:(f,F)=>re(R.provider,f,F),onSoloMode:f=>$(R.provider,f),onBulkPause:f=>Z(R.provider,f),onBulkResume:f=>ie(R.provider,f),isRemovingAccount:p.isPending,isPausingAccount:m.isPending||v.isPending,isSoloingAccount:x.isPending,isBulkPausing:b.isPending,isBulkResuming:N.isPending})}):e.jsx(Un,{onAddAccount:ke,onCreateVariant:()=>h(!0)})}),e.jsx(nn,{open:y,onClose:()=>h(!1)}),e.jsx(pn,{open:g!==null,onClose:()=>E(null),provider:g?.provider||"",displayName:g?.displayName||"",catalog:H&&g?.provider?P[g.provider]:void 0,isFirstAccount:g?.isFirstAccount||!1,account:g?.account})]})}export{nr as CliproxyPage};