@kaitranntt/ccs 8.1.0-dev.8 → 8.1.0-dev.9

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 (48) hide show
  1. package/dist/cliproxy/auth/auth-types.d.ts +2 -0
  2. package/dist/cliproxy/auth/auth-types.d.ts.map +1 -1
  3. package/dist/cliproxy/auth/oauth-handler.d.ts.map +1 -1
  4. package/dist/cliproxy/auth/oauth-handler.js +6 -5
  5. package/dist/cliproxy/auth/oauth-handler.js.map +1 -1
  6. package/dist/ui/assets/{Trans-CFMFYYpD.js → Trans-BIQ-yfAc.js} +1 -1
  7. package/dist/ui/assets/{accounts-h1gqXM-0.js → accounts-bN7DnjXo.js} +1 -1
  8. package/dist/ui/assets/{alert-dialog-Vh6QicdF.js → alert-dialog-D0yey0YJ.js} +1 -1
  9. package/dist/ui/assets/{api-DrsVgT3M.js → api-CEtMc2bM.js} +1 -1
  10. package/dist/ui/assets/{auth-section-C2K-5-Q_.js → auth-section-BHZUn2Hv.js} +1 -1
  11. package/dist/ui/assets/{backups-section-Cgx3DG70.js → backups-section-BNVlJSV3.js} +1 -1
  12. package/dist/ui/assets/{channels-elFStIOg.js → channels-BOB1P4Kt.js} +1 -1
  13. package/dist/ui/assets/{checkbox-BA2Nv6uj.js → checkbox-Bt-F3GmI.js} +1 -1
  14. package/dist/ui/assets/{claude-extension-Cbzm1xyr.js → claude-extension-AzKgsH0H.js} +1 -1
  15. package/dist/ui/assets/cliproxy-C1liaQi8.js +4 -0
  16. package/dist/ui/assets/{cliproxy-ai-providers-DN2FxLCQ.js → cliproxy-ai-providers-CzyaYfYI.js} +1 -1
  17. package/dist/ui/assets/{cliproxy-control-panel-DKvKuLeu.js → cliproxy-control-panel-DmkEW68l.js} +1 -1
  18. package/dist/ui/assets/{codex-wv1Mj9cV.js → codex-B2FLnjZI.js} +1 -1
  19. package/dist/ui/assets/{confirm-dialog-C5LKFQNa.js → confirm-dialog-CYvBJC0z.js} +1 -1
  20. package/dist/ui/assets/{copilot-DB8jUneY.js → copilot-Csab21fh.js} +1 -1
  21. package/dist/ui/assets/{cursor-runhbgIm.js → cursor-fOpftodW.js} +1 -1
  22. package/dist/ui/assets/{droid-DzsmNBYv.js → droid-FIcjtOf-.js} +1 -1
  23. package/dist/ui/assets/{globalenv-section-DFJnQFOm.js → globalenv-section-CpIAk36Y.js} +1 -1
  24. package/dist/ui/assets/{health-DHi_nP61.js → health-D0HvHNud.js} +1 -1
  25. package/dist/ui/assets/{index-DumIOj9c.js → index-BTPa3KEN.js} +1 -1
  26. package/dist/ui/assets/{index-DdkWxj5k.js → index-Cr4G276q.js} +1 -1
  27. package/dist/ui/assets/{index-DXux-_8_.js → index-D0VoBTF3.js} +1 -1
  28. package/dist/ui/assets/{index-Bwl0kamX.js → index-D5G9mVmP.js} +1 -1
  29. package/dist/ui/assets/{index-BR5qAAbI.js → index-Dm_QojrJ.js} +1 -1
  30. package/dist/ui/assets/{index-iTp4zo4j.js → index-N35Xkk8N.js} +1 -1
  31. package/dist/ui/assets/{index-Dhm3a4O3.js → index-sIfjKy42.js} +18 -18
  32. package/dist/ui/assets/{logs-BKqorypd.js → logs-B33n-VaM.js} +1 -1
  33. package/dist/ui/assets/{masked-input-bEP3NYf-.js → masked-input-BrUE6z_f.js} +1 -1
  34. package/dist/ui/assets/{proxy-status-widget-BlJejNxQ.js → proxy-status-widget-Dm2ziI5D.js} +1 -1
  35. package/dist/ui/assets/{raw-json-settings-editor-panel-BbgPfknN.js → raw-json-settings-editor-panel-DZRtQXbD.js} +1 -1
  36. package/dist/ui/assets/{searchable-select-CvzgoeqS.js → searchable-select-D2smFEI5.js} +1 -1
  37. package/dist/ui/assets/{separator-CjpBR2iP.js → separator-BvoSJCHW.js} +1 -1
  38. package/dist/ui/assets/{shared-Cd_FV84z.js → shared-qKNFwLmT.js} +1 -1
  39. package/dist/ui/assets/{table-Cf4yyqmc.js → table-DYyc1gJc.js} +1 -1
  40. package/dist/ui/assets/{updates-ChHv6_jj.js → updates-XXi3TQNZ.js} +1 -1
  41. package/dist/ui/assets/{use-accounts-DY6S-vHk.js → use-accounts-BR64_yUk.js} +1 -1
  42. package/dist/ui/index.html +1 -1
  43. package/dist/web-server/routes/cliproxy-auth-routes.d.ts +10 -0
  44. package/dist/web-server/routes/cliproxy-auth-routes.d.ts.map +1 -1
  45. package/dist/web-server/routes/cliproxy-auth-routes.js +45 -13
  46. package/dist/web-server/routes/cliproxy-auth-routes.js.map +1 -1
  47. package/package.json +1 -1
  48. package/dist/ui/assets/cliproxy-CbbAcrvW.js +0 -4
@@ -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};
@@ -1,4 +1,4 @@
1
- import{j as e}from"./radix-ui-nu4wz29m.js";import{r as o,u as Fe,e as Ge}from"./react-vendor-Bjx91N7w.js";import{c as B,aH as pe,b8 as xe,B as p,a as Ue,b9 as Ie,ai as Ve,aj as ze,ak as Je,al as _e,am as Qe,L,I as A,O as We,Q as Xe,R as Ye,aE as Ze,e as y,ba as he,bb as Le,_ as ne,S as be,x as se,U as je,V as Ne,W as X,X as Y,bc as we,bd as es,be as ss}from"./index-Dhm3a4O3.js";import{P as ts}from"./proxy-status-widget-BlJejNxQ.js";import{C as rs}from"./confirm-dialog-C5LKFQNa.js";import{l as as,w as Re,m as Te,n as ge,aC as te,s as ns,R as de,Z as is,a9 as Ee,p as qe,O as ls,Q as os,at as ds,au as cs,_ as Ce,aM as Oe,aN as He,ai as Ke,ax as ms,aO as us}from"./icons-DzKUh8vG.js";import{u as ps,a as fe,b as ve}from"./tanstack-bhJxV1h8.js";import{t as G}from"./notifications-B4_o8bcr.js";import"./utils-CzKF5WmX.js";import"./form-utils-CuHzLhJZ.js";import"./charts-eIPy2oG6.js";import"./alert-dialog-Vh6QicdF.js";import"./Trans-CFMFYYpD.js";function xs(s){switch(s){case"ready":return{icon:Te,text:"Ready",className:"text-green-600"};case"partial":return{icon:Re,text:"Needs attention",className:"text-amber-600"};default:return{icon:as,text:"Not configured",className:"text-muted-foreground"}}}function hs({families:s,selectedFamily:t,onSelect:r}){return e.jsx("div",{className:"space-y-1",children:s.map(n=>{const i=n.id===t,d=xs(n.status),h=d.icon;return e.jsx("button",{type:"button",onClick:()=>r(n.id),className:B("w-full cursor-pointer rounded-lg border px-3 py-2.5 text-left transition-colors",i?"border-primary/20 bg-primary/10":"border-transparent hover:bg-muted/70"),children:e.jsxs("div",{className:"flex items-center gap-3",children:[e.jsx(pe,{provider:xe(n.id),size:"md"}),e.jsxs("div",{className:"min-w-0 flex-1",children:[e.jsxs("div",{className:"flex items-center gap-2",children:[e.jsx("span",{className:"truncate text-sm font-medium",children:n.displayName}),n.entries.length>0&&e.jsx(p,{variant:"secondary",className:"h-4 px-1 text-[10px]",children:n.entries.length})]}),e.jsxs("div",{className:B("mt-0.5 flex items-center gap-1.5 text-xs",d.className),children:[e.jsx(h,{className:"h-3 w-3"}),e.jsx("span",{children:d.text})]})]}),e.jsx(p,{variant:"outline",className:"h-5 px-1.5 text-[9px] uppercase tracking-wide",children:n.authMode})]})},n.id)})})}function gs(s){switch(s){case"gemini-api-key":return{familyName:"Gemini",description:"Store the Gemini key here so CLIProxy can route Gemini requests without creating a separate CCS API Profile.",requiredNow:["Paste the Gemini API key.","Leave Base URL empty unless you use a custom Gemini host."],optionalLater:["Model mappings only when requested names and Gemini names differ.","Headers only when your provider setup requires them."],keyLabel:"Gemini API Key",keyPlaceholder:"AIza...",keyHelper:"This is the only field most Gemini setups need.",baseUrlPlaceholder:"https://generativelanguage.googleapis.com",baseUrlHelper:"Optional. Leave blank to keep the default Gemini endpoint.",aliasesPlaceholder:"claude-sonnet-4-5=gemini-2.5-pro",aliasesHelper:"Format: requested=upstream. Leave this blank unless the upstream Gemini model name differs.",headersPlaceholder:"X-Goog-User-Project: your-project"};case"codex-api-key":return{familyName:"Codex",description:"Store the Codex or OpenAI key here so CLIProxy can route Codex requests without duplicating the setup in API Profiles.",requiredNow:["Paste the Codex or OpenAI API key.","Leave Base URL empty unless this route should target another OpenAI-style endpoint."],optionalLater:["Model mappings only when the upstream model ID differs.","Headers only when org or project routing needs them."],keyLabel:"Codex API Key",keyPlaceholder:"sk-...",keyHelper:"This is the only field most Codex setups need.",baseUrlPlaceholder:"https://api.openai.com/v1",baseUrlHelper:"Optional. Leave blank to keep the default Codex endpoint.",aliasesPlaceholder:"claude-sonnet-4-5=gpt-5",aliasesHelper:"Format: requested=upstream. Add a mapping only when the upstream model name differs.",headersPlaceholder:"OpenAI-Organization: org_..."};case"claude-api-key":return{familyName:"Claude",description:"Store the Anthropic or compatible key here for CLIProxy-managed Claude routing. Save the key first, then add rewrites only if this route needs them.",requiredNow:["Paste the Claude or Anthropic-compatible API key.","Leave Base URL empty unless this route should target another compatible endpoint."],optionalLater:["Model mappings only when the requested and upstream Claude model IDs differ.","Proxy, prefix, exclusions, and headers only for advanced routing cases."],keyLabel:"Claude API Key",keyPlaceholder:"sk-ant-...",keyHelper:"Most Claude routes can start with the key only.",baseUrlPlaceholder:"https://api.anthropic.com",baseUrlHelper:"Optional. Leave blank to keep the default Claude-compatible endpoint.",aliasesPlaceholder:"claude-sonnet-4-5=claude-3-7-sonnet-latest",aliasesHelper:"Format: requested=upstream. Add a mapping only when the upstream model ID should differ.",headersPlaceholder:"X-Project: internal-routing"};case"vertex-api-key":return{familyName:"Vertex",description:"Store the Vertex key here so CLIProxy can route Vertex traffic without creating a separate CCS API Profile.",requiredNow:["Paste the Vertex API key.","Leave Base URL empty unless a regional or gateway endpoint is required."],optionalLater:["Model mappings only when the upstream name differs.","Headers only when the provider expects extra routing context."],keyLabel:"Vertex API Key",keyPlaceholder:"AIza...",keyHelper:"Most Vertex routes only need the key.",baseUrlPlaceholder:"https://vertex.googleapis.com",baseUrlHelper:"Optional. Leave blank to keep the default Vertex endpoint.",aliasesPlaceholder:"claude-sonnet-4-5=gemini-2.5-pro",aliasesHelper:"Format: requested=upstream. Leave blank unless the upstream model name differs.",headersPlaceholder:"X-Goog-User-Project: your-project"};case"openai-compatibility":return{familyName:"OpenAI-Compatible Connector",description:"Create a named connector for OpenRouter, Together, or any OpenAI-style endpoint. This page owns the connector setup directly inside CLIProxy.",requiredNow:["Pick a connector name such as openrouter or together.","Set the connector Base URL.","Add at least one API key before saving."],optionalLater:["Model mappings only when requested and upstream model names differ.","Headers only when the connector requires provider-specific auth or routing."],keyLabel:"API Keys",keyPlaceholder:"sk-...",keyHelper:"Add one key per line. Most connectors start with a single key.",connectorPlaceholder:"openrouter",connectorHelper:"This becomes the connector label in the saved entries list.",baseUrlPlaceholder:"https://openrouter.ai/api/v1",baseUrlHelper:"Required for connectors. This is the upstream OpenAI-style endpoint.",aliasesPlaceholder:"claude-sonnet-4-5=gpt-4.1",aliasesHelper:"Format: requested=upstream. Leave blank unless the connector expects a different model ID.",headersPlaceholder:"HTTP-Referer: https://your-app.example"}}}function ke(s){return s.split(`
1
+ import{j as e}from"./radix-ui-nu4wz29m.js";import{r as o,u as Fe,e as Ge}from"./react-vendor-Bjx91N7w.js";import{c as B,aH as pe,b8 as xe,B as p,a as Ue,b9 as Ie,ai as Ve,aj as ze,ak as Je,al as _e,am as Qe,L,I as A,O as We,Q as Xe,R as Ye,aE as Ze,e as y,ba as he,bb as Le,_ as ne,S as be,x as se,U as je,V as Ne,W as X,X as Y,bc as we,bd as es,be as ss}from"./index-sIfjKy42.js";import{P as ts}from"./proxy-status-widget-Dm2ziI5D.js";import{C as rs}from"./confirm-dialog-CYvBJC0z.js";import{l as as,w as Re,m as Te,n as ge,aC as te,s as ns,R as de,Z as is,a9 as Ee,p as qe,O as ls,Q as os,at as ds,au as cs,_ as Ce,aM as Oe,aN as He,ai as Ke,ax as ms,aO as us}from"./icons-DzKUh8vG.js";import{u as ps,a as fe,b as ve}from"./tanstack-bhJxV1h8.js";import{t as G}from"./notifications-B4_o8bcr.js";import"./utils-CzKF5WmX.js";import"./form-utils-CuHzLhJZ.js";import"./charts-eIPy2oG6.js";import"./alert-dialog-D0yey0YJ.js";import"./Trans-BIQ-yfAc.js";function xs(s){switch(s){case"ready":return{icon:Te,text:"Ready",className:"text-green-600"};case"partial":return{icon:Re,text:"Needs attention",className:"text-amber-600"};default:return{icon:as,text:"Not configured",className:"text-muted-foreground"}}}function hs({families:s,selectedFamily:t,onSelect:r}){return e.jsx("div",{className:"space-y-1",children:s.map(n=>{const i=n.id===t,d=xs(n.status),h=d.icon;return e.jsx("button",{type:"button",onClick:()=>r(n.id),className:B("w-full cursor-pointer rounded-lg border px-3 py-2.5 text-left transition-colors",i?"border-primary/20 bg-primary/10":"border-transparent hover:bg-muted/70"),children:e.jsxs("div",{className:"flex items-center gap-3",children:[e.jsx(pe,{provider:xe(n.id),size:"md"}),e.jsxs("div",{className:"min-w-0 flex-1",children:[e.jsxs("div",{className:"flex items-center gap-2",children:[e.jsx("span",{className:"truncate text-sm font-medium",children:n.displayName}),n.entries.length>0&&e.jsx(p,{variant:"secondary",className:"h-4 px-1 text-[10px]",children:n.entries.length})]}),e.jsxs("div",{className:B("mt-0.5 flex items-center gap-1.5 text-xs",d.className),children:[e.jsx(h,{className:"h-3 w-3"}),e.jsx("span",{children:d.text})]})]}),e.jsx(p,{variant:"outline",className:"h-5 px-1.5 text-[9px] uppercase tracking-wide",children:n.authMode})]})},n.id)})})}function gs(s){switch(s){case"gemini-api-key":return{familyName:"Gemini",description:"Store the Gemini key here so CLIProxy can route Gemini requests without creating a separate CCS API Profile.",requiredNow:["Paste the Gemini API key.","Leave Base URL empty unless you use a custom Gemini host."],optionalLater:["Model mappings only when requested names and Gemini names differ.","Headers only when your provider setup requires them."],keyLabel:"Gemini API Key",keyPlaceholder:"AIza...",keyHelper:"This is the only field most Gemini setups need.",baseUrlPlaceholder:"https://generativelanguage.googleapis.com",baseUrlHelper:"Optional. Leave blank to keep the default Gemini endpoint.",aliasesPlaceholder:"claude-sonnet-4-5=gemini-2.5-pro",aliasesHelper:"Format: requested=upstream. Leave this blank unless the upstream Gemini model name differs.",headersPlaceholder:"X-Goog-User-Project: your-project"};case"codex-api-key":return{familyName:"Codex",description:"Store the Codex or OpenAI key here so CLIProxy can route Codex requests without duplicating the setup in API Profiles.",requiredNow:["Paste the Codex or OpenAI API key.","Leave Base URL empty unless this route should target another OpenAI-style endpoint."],optionalLater:["Model mappings only when the upstream model ID differs.","Headers only when org or project routing needs them."],keyLabel:"Codex API Key",keyPlaceholder:"sk-...",keyHelper:"This is the only field most Codex setups need.",baseUrlPlaceholder:"https://api.openai.com/v1",baseUrlHelper:"Optional. Leave blank to keep the default Codex endpoint.",aliasesPlaceholder:"claude-sonnet-4-5=gpt-5",aliasesHelper:"Format: requested=upstream. Add a mapping only when the upstream model name differs.",headersPlaceholder:"OpenAI-Organization: org_..."};case"claude-api-key":return{familyName:"Claude",description:"Store the Anthropic or compatible key here for CLIProxy-managed Claude routing. Save the key first, then add rewrites only if this route needs them.",requiredNow:["Paste the Claude or Anthropic-compatible API key.","Leave Base URL empty unless this route should target another compatible endpoint."],optionalLater:["Model mappings only when the requested and upstream Claude model IDs differ.","Proxy, prefix, exclusions, and headers only for advanced routing cases."],keyLabel:"Claude API Key",keyPlaceholder:"sk-ant-...",keyHelper:"Most Claude routes can start with the key only.",baseUrlPlaceholder:"https://api.anthropic.com",baseUrlHelper:"Optional. Leave blank to keep the default Claude-compatible endpoint.",aliasesPlaceholder:"claude-sonnet-4-5=claude-3-7-sonnet-latest",aliasesHelper:"Format: requested=upstream. Add a mapping only when the upstream model ID should differ.",headersPlaceholder:"X-Project: internal-routing"};case"vertex-api-key":return{familyName:"Vertex",description:"Store the Vertex key here so CLIProxy can route Vertex traffic without creating a separate CCS API Profile.",requiredNow:["Paste the Vertex API key.","Leave Base URL empty unless a regional or gateway endpoint is required."],optionalLater:["Model mappings only when the upstream name differs.","Headers only when the provider expects extra routing context."],keyLabel:"Vertex API Key",keyPlaceholder:"AIza...",keyHelper:"Most Vertex routes only need the key.",baseUrlPlaceholder:"https://vertex.googleapis.com",baseUrlHelper:"Optional. Leave blank to keep the default Vertex endpoint.",aliasesPlaceholder:"claude-sonnet-4-5=gemini-2.5-pro",aliasesHelper:"Format: requested=upstream. Leave blank unless the upstream model name differs.",headersPlaceholder:"X-Goog-User-Project: your-project"};case"openai-compatibility":return{familyName:"OpenAI-Compatible Connector",description:"Create a named connector for OpenRouter, Together, or any OpenAI-style endpoint. This page owns the connector setup directly inside CLIProxy.",requiredNow:["Pick a connector name such as openrouter or together.","Set the connector Base URL.","Add at least one API key before saving."],optionalLater:["Model mappings only when requested and upstream model names differ.","Headers only when the connector requires provider-specific auth or routing."],keyLabel:"API Keys",keyPlaceholder:"sk-...",keyHelper:"Add one key per line. Most connectors start with a single key.",connectorPlaceholder:"openrouter",connectorHelper:"This becomes the connector label in the saved entries list.",baseUrlPlaceholder:"https://openrouter.ai/api/v1",baseUrlHelper:"Required for connectors. This is the upstream OpenAI-style endpoint.",aliasesPlaceholder:"claude-sonnet-4-5=gpt-4.1",aliasesHelper:"Format: requested=upstream. Leave blank unless the connector expects a different model ID.",headersPlaceholder:"HTTP-Referer: https://your-app.example"}}}function ke(s){return s.split(`
2
2
  `).map(t=>t.trim()).filter(t=>t.length>0)}function fs(s){return s.split(`
3
3
  `).map(t=>t.trim()).filter(t=>t.length>0).map(t=>{const r=t.includes(":")?":":"=",[n,...i]=t.split(r);return{key:n.trim(),value:i.join(r).trim()}}).filter(t=>t.key.length>0)}function vs(s){return Le(s)}function Z({value:s,onChange:t,placeholder:r,rows:n=4}){return e.jsx("textarea",{rows:n,value:s,onChange:i=>t(i.target.value),placeholder:r,className:"flex min-h-24 w-full rounded-md border border-input bg-transparent px-3 py-2 text-sm shadow-xs outline-none transition-[color,box-shadow] placeholder:text-muted-foreground focus-visible:border-ring focus-visible:ring-[3px] focus-visible:ring-ring/50"})}function ys(s){return(s?.headers||[]).map(t=>`${t.key}: ${t.value}`).join(`
4
4
  `)}function bs(s){return(s?.excludedModels||[]).join(`
@@ -1 +1 @@
1
- import{j as t}from"./radix-ui-nu4wz29m.js";import{r as a}from"./react-vendor-Bjx91N7w.js";import{u as _}from"./tanstack-bhJxV1h8.js";import{a as D,bf as g,_ as $}from"./index-Dhm3a4O3.js";import{C as A}from"./default-ports-1QQSffYX.js";import{G as Q,R as T,w as X}from"./icons-DzKUh8vG.js";import"./notifications-B4_o8bcr.js";import"./utils-CzKF5WmX.js";import"./form-utils-CuHzLhJZ.js";import"./charts-eIPy2oG6.js";const O="cli-proxy-auth",U="isLoggedIn",K="apiBase",B="apiUrl",C="managementKey";function k(l){return l.startsWith("/")?new URL(l.replace(/\/$/,""),window.location.origin).href:l.replace(/\/$/,"")}function J(l,u){window.localStorage.removeItem(O),window.localStorage.setItem(K,l),window.localStorage.setItem(B,l),window.localStorage.setItem(C,u),window.localStorage.setItem(U,"true")}function w(){window.localStorage.removeItem(O),window.localStorage.removeItem(K),window.localStorage.removeItem(B),window.localStorage.removeItem(C),window.localStorage.removeItem(U)}function V(){window.localStorage.removeItem(C)}function Z({port:l=A}){const{t:u}=D(),f=a.useRef(null),[F,N]=a.useState(null),[M,G]=a.useState(0),[E,P]=a.useState(null),[H,j]=a.useState(!1),{data:i,error:y}=_({queryKey:["cliproxy-server-config"],queryFn:()=>$.cliproxyServer.get(),staleTime:3e4});a.useEffect(()=>{y&&console.warn("[ControlPanelEmbed] Config fetch failed, using local mode:",y)},[y]);const R=!!(i?.remote?.enabled&&i?.remote?.host),{data:b,error:x}=_({queryKey:["auth-tokens-raw",R?"remote":"local"],enabled:i!==void 0&&!R,queryFn:async()=>{try{const e=await fetch(g("/settings/auth/tokens/raw"));if(!e.ok)throw new Error("Failed to fetch auth tokens");const s=await e.json(),o=s.managementSecret.value.trim();if(!o)throw new Error("Management secret missing");return J(k(g("/cliproxy-local/")),o),s}catch(e){throw w(),e}},staleTime:3e4}),{managementUrl:S,checkUrl:h,authToken:L,isRemote:n,displayHost:c}=a.useMemo(()=>{const e=i?.remote,s=i?.local?.port??l;if(e?.enabled&&e?.host){const o=e.protocol||"http",m=e.port||(o==="https"?443:A),p=o==="https"&&m===443||o==="http"&&m===80?"":`:${m}`,r=`${o}://${e.host}${p}`;return{managementUrl:`${r}/management.html`,checkUrl:`${r}/`,authToken:e.auth_token||void 0,isRemote:!0,displayHost:`${e.host}${p}`}}return{managementUrl:g("/cliproxy-local/management.html"),checkUrl:g("/cliproxy-local/"),authToken:b?.managementSecret?.value||void 0,isRemote:!1,displayHost:`localhost:${s}`}},[i,b,l]),v=`${S}:${n?"remote":"local"}:${h}:${L??"missing"}:${M}`,I=i!==void 0&&(n||!!b||!!x);a.useEffect(()=>{x&&console.warn("[ControlPanelEmbed] Failed to preload local control panel session, falling back to manual login:",x)},[x]),a.useEffect(()=>{if(n)return;const e=()=>{w()};return window.addEventListener("beforeunload",e),()=>{window.removeEventListener("beforeunload",e),w()}},[n]);const Y=!I||!(F===v),q=()=>{if(!(!n||!f.current?.contentWindow||!L))try{const e=k(h),s=new URL(`${e}/`).origin;if(new URL(f.current.src,window.location.origin).origin!==s){console.warn("[ControlPanelEmbed] Remote iframe origin mismatch, skipping postMessage");return}f.current.contentWindow.postMessage({type:"ccs-auto-login",apiBase:e,managementKey:L},s)}catch(e){console.debug("[ControlPanelEmbed] Remote postMessage bootstrap failed:",e)}};a.useEffect(()=>{const e=new AbortController;let s=!1;const o=(r,d)=>{s||(j(r),P(d))},m=async()=>{try{if(n){const r=i?.remote,d=await $.cliproxyServer.test({host:r?.host??"",port:r?.port,protocol:r?.protocol??"http",authToken:r?.auth_token});d?.reachable?o(!0,null):o(!1,d?.error?`Remote CLIProxy at ${c}: ${d.error}`:`Remote CLIProxy at ${c} returned an error`)}else(await fetch(h,{signal:e.signal})).ok?o(!0,null):o(!1,"CLIProxy returned an error")}catch(r){if(r instanceof Error&&r.name==="AbortError")return;o(!1,n?`Remote CLIProxy at ${c} is not reachable`:"CLIProxy is not running")}},p=setTimeout(()=>e.abort(),2e3);return m().finally(()=>clearTimeout(p)),()=>{s=!0,e.abort()}},[h,n,c,i]);const W=()=>{N(v),q(),n||V()},z=()=>{n||w(),N(null),G(e=>e+1),P(null),j(!1)};return!H&&E?t.jsxs("div",{className:"flex-1 flex flex-col",children:[t.jsxs("div",{className:"flex items-center justify-between p-4 border-b",children:[t.jsxs("div",{className:"flex items-center gap-2",children:[t.jsx(Q,{className:"w-5 h-5 text-primary"}),t.jsx("h2",{className:"font-semibold",children:u("cliproxyHeader.cliproxyControlPanel")})]}),t.jsxs("button",{className:"inline-flex items-center gap-2 px-3 py-1.5 text-sm border rounded-md hover:bg-muted",onClick:z,children:[t.jsx(T,{className:"w-4 h-4"}),"Retry"]})]}),t.jsx("div",{className:"flex-1 flex items-center justify-center bg-muted/20",children:t.jsxs("div",{className:"text-center max-w-md px-8",children:[t.jsx("div",{className:"w-16 h-16 rounded-full bg-destructive/10 flex items-center justify-center mx-auto mb-6",children:t.jsx(X,{className:"w-8 h-8 text-destructive"})}),t.jsx("h3",{className:"text-lg font-semibold mb-2",children:u("cliproxyHeader.cliproxyNotAvailable")}),t.jsx("p",{className:"text-muted-foreground mb-4",children:E}),t.jsxs("p",{className:"text-sm text-muted-foreground",children:["Start a CLIProxy session with"," ",t.jsx("code",{className:"bg-muted px-1 rounded",children:"ccs gemini"})," or run"," ",t.jsx("code",{className:"bg-muted px-1 rounded",children:"ccs config"})," which auto-starts it."]})]})})]}):t.jsx("div",{className:"flex-1 flex flex-col",children:t.jsxs("div",{className:"flex-1 flex flex-col relative",children:[Y&&t.jsx("div",{className:"absolute inset-0 flex items-center justify-center bg-background/80 z-10",children:t.jsxs("div",{className:"text-center",children:[t.jsx(T,{className:"w-8 h-8 animate-spin text-primary mx-auto mb-2"}),t.jsx("p",{className:"text-sm text-muted-foreground",children:n?`Loading Control Panel from ${c}...`:"Loading Control Panel..."})]})}),I?t.jsx("iframe",{ref:f,src:S,className:"flex-1 w-full border-0",title:"CLIProxy Management Panel",onLoad:W},v):null]})})}function de(){return t.jsx("div",{className:"flex h-full min-h-0 flex-col overflow-hidden",children:t.jsx(Z,{})})}export{de as CliproxyControlPanelPage};
1
+ import{j as t}from"./radix-ui-nu4wz29m.js";import{r as a}from"./react-vendor-Bjx91N7w.js";import{u as _}from"./tanstack-bhJxV1h8.js";import{a as D,bf as g,_ as $}from"./index-sIfjKy42.js";import{C as A}from"./default-ports-1QQSffYX.js";import{G as Q,R as T,w as X}from"./icons-DzKUh8vG.js";import"./notifications-B4_o8bcr.js";import"./utils-CzKF5WmX.js";import"./form-utils-CuHzLhJZ.js";import"./charts-eIPy2oG6.js";const O="cli-proxy-auth",U="isLoggedIn",K="apiBase",B="apiUrl",C="managementKey";function k(l){return l.startsWith("/")?new URL(l.replace(/\/$/,""),window.location.origin).href:l.replace(/\/$/,"")}function J(l,u){window.localStorage.removeItem(O),window.localStorage.setItem(K,l),window.localStorage.setItem(B,l),window.localStorage.setItem(C,u),window.localStorage.setItem(U,"true")}function w(){window.localStorage.removeItem(O),window.localStorage.removeItem(K),window.localStorage.removeItem(B),window.localStorage.removeItem(C),window.localStorage.removeItem(U)}function V(){window.localStorage.removeItem(C)}function Z({port:l=A}){const{t:u}=D(),f=a.useRef(null),[F,N]=a.useState(null),[M,G]=a.useState(0),[E,P]=a.useState(null),[H,j]=a.useState(!1),{data:i,error:y}=_({queryKey:["cliproxy-server-config"],queryFn:()=>$.cliproxyServer.get(),staleTime:3e4});a.useEffect(()=>{y&&console.warn("[ControlPanelEmbed] Config fetch failed, using local mode:",y)},[y]);const R=!!(i?.remote?.enabled&&i?.remote?.host),{data:b,error:x}=_({queryKey:["auth-tokens-raw",R?"remote":"local"],enabled:i!==void 0&&!R,queryFn:async()=>{try{const e=await fetch(g("/settings/auth/tokens/raw"));if(!e.ok)throw new Error("Failed to fetch auth tokens");const s=await e.json(),o=s.managementSecret.value.trim();if(!o)throw new Error("Management secret missing");return J(k(g("/cliproxy-local/")),o),s}catch(e){throw w(),e}},staleTime:3e4}),{managementUrl:S,checkUrl:h,authToken:L,isRemote:n,displayHost:c}=a.useMemo(()=>{const e=i?.remote,s=i?.local?.port??l;if(e?.enabled&&e?.host){const o=e.protocol||"http",m=e.port||(o==="https"?443:A),p=o==="https"&&m===443||o==="http"&&m===80?"":`:${m}`,r=`${o}://${e.host}${p}`;return{managementUrl:`${r}/management.html`,checkUrl:`${r}/`,authToken:e.auth_token||void 0,isRemote:!0,displayHost:`${e.host}${p}`}}return{managementUrl:g("/cliproxy-local/management.html"),checkUrl:g("/cliproxy-local/"),authToken:b?.managementSecret?.value||void 0,isRemote:!1,displayHost:`localhost:${s}`}},[i,b,l]),v=`${S}:${n?"remote":"local"}:${h}:${L??"missing"}:${M}`,I=i!==void 0&&(n||!!b||!!x);a.useEffect(()=>{x&&console.warn("[ControlPanelEmbed] Failed to preload local control panel session, falling back to manual login:",x)},[x]),a.useEffect(()=>{if(n)return;const e=()=>{w()};return window.addEventListener("beforeunload",e),()=>{window.removeEventListener("beforeunload",e),w()}},[n]);const Y=!I||!(F===v),q=()=>{if(!(!n||!f.current?.contentWindow||!L))try{const e=k(h),s=new URL(`${e}/`).origin;if(new URL(f.current.src,window.location.origin).origin!==s){console.warn("[ControlPanelEmbed] Remote iframe origin mismatch, skipping postMessage");return}f.current.contentWindow.postMessage({type:"ccs-auto-login",apiBase:e,managementKey:L},s)}catch(e){console.debug("[ControlPanelEmbed] Remote postMessage bootstrap failed:",e)}};a.useEffect(()=>{const e=new AbortController;let s=!1;const o=(r,d)=>{s||(j(r),P(d))},m=async()=>{try{if(n){const r=i?.remote,d=await $.cliproxyServer.test({host:r?.host??"",port:r?.port,protocol:r?.protocol??"http",authToken:r?.auth_token});d?.reachable?o(!0,null):o(!1,d?.error?`Remote CLIProxy at ${c}: ${d.error}`:`Remote CLIProxy at ${c} returned an error`)}else(await fetch(h,{signal:e.signal})).ok?o(!0,null):o(!1,"CLIProxy returned an error")}catch(r){if(r instanceof Error&&r.name==="AbortError")return;o(!1,n?`Remote CLIProxy at ${c} is not reachable`:"CLIProxy is not running")}},p=setTimeout(()=>e.abort(),2e3);return m().finally(()=>clearTimeout(p)),()=>{s=!0,e.abort()}},[h,n,c,i]);const W=()=>{N(v),q(),n||V()},z=()=>{n||w(),N(null),G(e=>e+1),P(null),j(!1)};return!H&&E?t.jsxs("div",{className:"flex-1 flex flex-col",children:[t.jsxs("div",{className:"flex items-center justify-between p-4 border-b",children:[t.jsxs("div",{className:"flex items-center gap-2",children:[t.jsx(Q,{className:"w-5 h-5 text-primary"}),t.jsx("h2",{className:"font-semibold",children:u("cliproxyHeader.cliproxyControlPanel")})]}),t.jsxs("button",{className:"inline-flex items-center gap-2 px-3 py-1.5 text-sm border rounded-md hover:bg-muted",onClick:z,children:[t.jsx(T,{className:"w-4 h-4"}),"Retry"]})]}),t.jsx("div",{className:"flex-1 flex items-center justify-center bg-muted/20",children:t.jsxs("div",{className:"text-center max-w-md px-8",children:[t.jsx("div",{className:"w-16 h-16 rounded-full bg-destructive/10 flex items-center justify-center mx-auto mb-6",children:t.jsx(X,{className:"w-8 h-8 text-destructive"})}),t.jsx("h3",{className:"text-lg font-semibold mb-2",children:u("cliproxyHeader.cliproxyNotAvailable")}),t.jsx("p",{className:"text-muted-foreground mb-4",children:E}),t.jsxs("p",{className:"text-sm text-muted-foreground",children:["Start a CLIProxy session with"," ",t.jsx("code",{className:"bg-muted px-1 rounded",children:"ccs gemini"})," or run"," ",t.jsx("code",{className:"bg-muted px-1 rounded",children:"ccs config"})," which auto-starts it."]})]})})]}):t.jsx("div",{className:"flex-1 flex flex-col",children:t.jsxs("div",{className:"flex-1 flex flex-col relative",children:[Y&&t.jsx("div",{className:"absolute inset-0 flex items-center justify-center bg-background/80 z-10",children:t.jsxs("div",{className:"text-center",children:[t.jsx(T,{className:"w-8 h-8 animate-spin text-primary mx-auto mb-2"}),t.jsx("p",{className:"text-sm text-muted-foreground",children:n?`Loading Control Panel from ${c}...`:"Loading Control Panel..."})]})}),I?t.jsx("iframe",{ref:f,src:S,className:"flex-1 w-full border-0",title:"CLIProxy Management Panel",onLoad:W},v):null]})})}function de(){return t.jsx("div",{className:"flex h-full min-h-0 flex-col overflow-hidden",children:t.jsx(Z,{})})}export{de as CliproxyControlPanelPage};