@kaitranntt/ccs 7.69.1-dev.1 → 7.69.1-dev.3

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 (53) hide show
  1. package/dist/ui/assets/accounts-DN0lP-yj.js +1 -0
  2. package/dist/ui/assets/{alert-dialog-QyEXocpn.js → alert-dialog-BA39vaYL.js} +1 -1
  3. package/dist/ui/assets/api-D2cjf1H4.js +4 -0
  4. package/dist/ui/assets/{auth-section-BszF77uT.js → auth-section-BNX8_9MJ.js} +1 -1
  5. package/dist/ui/assets/{backups-section-D6RgaOx1.js → backups-section-Bt0FA5zl.js} +1 -1
  6. package/dist/ui/assets/channels-FaDUjf3Y.js +1 -0
  7. package/dist/ui/assets/{checkbox-Dzwkj_Pg.js → checkbox-DHF-UBrH.js} +1 -1
  8. package/dist/ui/assets/claude-extension-D-skBToQ.js +1 -0
  9. package/dist/ui/assets/cliproxy-CD7z-_q8.js +3 -0
  10. package/dist/ui/assets/cliproxy-ai-providers-QSOOqh8F.js +15 -0
  11. package/dist/ui/assets/cliproxy-control-panel-D9dLU28p.js +1 -0
  12. package/dist/ui/assets/codex-CHO5_hku.js +27 -0
  13. package/dist/ui/assets/confirm-dialog-BICDz_zm.js +1 -0
  14. package/dist/ui/assets/copilot-BnQrRCuJ.js +3 -0
  15. package/dist/ui/assets/{cursor-BrcDgu6X.js → cursor-CXopLKfC.js} +1 -1
  16. package/dist/ui/assets/droid-CLFg9ELE.js +2 -0
  17. package/dist/ui/assets/{globalenv-section-DoX37DqB.js → globalenv-section-NPjCcYBN.js} +1 -1
  18. package/dist/ui/assets/{health-D_gdcxnc.js → health-B_3JpCrY.js} +1 -1
  19. package/dist/ui/assets/index-B5Egq7qY.js +1 -0
  20. package/dist/ui/assets/index-BY2j-o67.js +1 -0
  21. package/dist/ui/assets/{index-CTGpqIx6.js → index-BcUkpsGj.js} +1 -1
  22. package/dist/ui/assets/{index-DoVPk3vW.js → index-BgGHTjTd.js} +1 -1
  23. package/dist/ui/assets/index-DNmWbKbN.js +72 -0
  24. package/dist/ui/assets/index-DZddoGfE.js +1 -0
  25. package/dist/ui/assets/logs-Bb1OVYeK.js +1 -0
  26. package/dist/ui/assets/{masked-input-C2H-Ax0Z.js → masked-input-b4-lEKNq.js} +1 -1
  27. package/dist/ui/assets/proxy-status-widget-s89zaj3X.js +1 -0
  28. package/dist/ui/assets/{raw-json-settings-editor-panel-WxTn7-hS.js → raw-json-settings-editor-panel-Dr_BNQwQ.js} +1 -1
  29. package/dist/ui/assets/{searchable-select-1zOULoec.js → searchable-select-FJPe_YWv.js} +1 -1
  30. package/dist/ui/assets/{separator-BCfZ54mZ.js → separator-DJ0ku_ak.js} +1 -1
  31. package/dist/ui/assets/{shared-DlTbnc9n.js → shared-DyQlJnbj.js} +1 -1
  32. package/dist/ui/assets/{table-Bx2cnkWN.js → table-6Yg65ZZH.js} +1 -1
  33. package/dist/ui/assets/{updates-SiZKOnUD.js → updates-DSCXb6Au.js} +1 -1
  34. package/dist/ui/index.html +1 -1
  35. package/lib/mcp/ccs-browser-server.cjs +119 -27
  36. package/package.json +1 -1
  37. package/dist/ui/assets/accounts-D9eEaNx9.js +0 -1
  38. package/dist/ui/assets/api-7vQe0xOg.js +0 -4
  39. package/dist/ui/assets/channels-B1vgnNJX.js +0 -1
  40. package/dist/ui/assets/claude-extension-CKO4bJ22.js +0 -1
  41. package/dist/ui/assets/cliproxy-ai-providers-CmbFYVoR.js +0 -15
  42. package/dist/ui/assets/cliproxy-control-panel-M8ZfUq3C.js +0 -1
  43. package/dist/ui/assets/cliproxy-kHd-oC5W.js +0 -3
  44. package/dist/ui/assets/codex-BJ0RdMuh.js +0 -27
  45. package/dist/ui/assets/confirm-dialog-BlSaX2gK.js +0 -1
  46. package/dist/ui/assets/copilot-NJKZQXQ_.js +0 -3
  47. package/dist/ui/assets/droid-B9u9ZB-a.js +0 -2
  48. package/dist/ui/assets/index-BNU4Hhe_.js +0 -1
  49. package/dist/ui/assets/index-DFEMq3KP.js +0 -1
  50. package/dist/ui/assets/index-DOn6k1jF.js +0 -72
  51. package/dist/ui/assets/index-h08p9xL5.js +0 -1
  52. package/dist/ui/assets/logs-DtH4YMt4.js +0 -1
  53. package/dist/ui/assets/proxy-status-widget-BOrsn86w.js +0 -1
@@ -1,15 +0,0 @@
1
- import{j as e}from"./radix-ui-Zb8sVEtn.js";import{r as c,u as Be,h as Fe}from"./react-vendor-CNOkPC89.js";import{c as D,aD as ue,b4 as pe,B as h,b5 as Me,ag as Ge,ah as Ve,ai as ze,aj as Je,ak as _e,L as M,I as P,M as Qe,N as We,O as Xe,aC as Ye,d as f,b6 as xe,b7 as Ue,Y as ne,S as ye,n as se,Q as be,R as je,U as X,V as Y,b8 as Ne,b9 as Ze,ba as es}from"./index-DOn6k1jF.js";import{P as ss}from"./proxy-status-widget-BOrsn86w.js";import{C as ts}from"./confirm-dialog-BlSaX2gK.js";import{l as rs,w as Ie,m as Le,n as he,aB as te,s as as,R as oe,Z as ns,a9 as Re,p as Te,O as is,Q as ls,as as os,at as ds,_ as we,aL as Ee,aM as qe,ah as Oe,aw as cs,aN as ms}from"./icons-KVCk4_U8.js";import{u as us,a as ge,b as fe}from"./tanstack-CrmUhA7Z.js";import{t as G}from"./notifications-B2HqRBj7.js";import"./utils-CzKF5WmX.js";import"./form-utils-Bcoyqxpq.js";import"./code-highlight-BRUf_pqB.js";import"./alert-dialog-QyEXocpn.js";function ps(s){switch(s){case"ready":return{icon:Le,text:"Ready",className:"text-green-600"};case"partial":return{icon:Ie,text:"Needs attention",className:"text-amber-600"};default:return{icon:rs,text:"Not configured",className:"text-muted-foreground"}}}function xs({families:s,selectedFamily:t,onSelect:r}){return e.jsx("div",{className:"space-y-1",children:s.map(a=>{const i=a.id===t,o=ps(a.status),l=o.icon;return e.jsx("button",{type:"button",onClick:()=>r(a.id),className:D("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(ue,{provider:pe(a.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:a.displayName}),a.entries.length>0&&e.jsx(h,{variant:"secondary",className:"h-4 px-1 text-[10px]",children:a.entries.length})]}),e.jsxs("div",{className:D("mt-0.5 flex items-center gap-1.5 text-xs",o.className),children:[e.jsx(l,{className:"h-3 w-3"}),e.jsx("span",{children:o.text})]})]}),e.jsx(h,{variant:"outline",className:"h-5 px-1.5 text-[9px] uppercase tracking-wide",children:a.authMode})]})},a.id)})})}function hs(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 Ce(s){return s.split(`
2
- `).map(t=>t.trim()).filter(t=>t.length>0)}function gs(s){return s.split(`
3
- `).map(t=>t.trim()).filter(t=>t.length>0).map(t=>{const r=t.includes(":")?":":"=",[a,...i]=t.split(r);return{key:a.trim(),value:i.join(r).trim()}}).filter(t=>t.key.length>0)}function fs(s){return Ue(s)}function Z({value:s,onChange:t,placeholder:r,rows:a=4}){return e.jsx("textarea",{rows:a,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 vs(s){return(s?.headers||[]).map(t=>`${t.key}: ${t.value}`).join(`
4
- `)}function ys(s){return(s?.excludedModels||[]).join(`
5
- `)}function bs(s){return xe(s?.models)}function ke({title:s,items:t,icon:r}){return e.jsxs("div",{className:"rounded-xl border bg-background/80 p-4",children:[e.jsxs("div",{className:"flex items-center gap-2 text-sm font-medium",children:[r,s]}),e.jsx("div",{className:"mt-3 space-y-3",children:t.map((a,i)=>e.jsxs("div",{className:"flex items-start gap-3",children:[e.jsx("div",{className:"mt-0.5 flex h-5 w-5 shrink-0 items-center justify-center rounded-full border bg-muted/40 text-[11px] font-semibold text-muted-foreground",children:i+1}),e.jsx("div",{className:"text-sm leading-6 text-muted-foreground",children:a})]},`${s}:${a}`))})]})}function js({family:s,entry:t,open:r,onOpenChange:a,onSubmit:i,isSaving:o}){const l=c.useMemo(()=>hs(s),[s]),n=!!t,u=s==="openai-compatibility",y=s==="claude-api-key",[U,K]=c.useState(()=>t?.name||""),[j,q]=c.useState(()=>t?.baseUrl||""),[N,H]=c.useState(()=>t?.proxyUrl||""),[I,J]=c.useState(()=>t?.prefix||""),[w,L]=c.useState(""),[b,p]=c.useState(""),[R,C]=c.useState(()=>vs(t)),[T,B]=c.useState(()=>ys(t)),[O,v]=c.useState(()=>bs(t)),A=c.useMemo(()=>Me(O),[O]),[S,$]=c.useState(()=>!!(t?.headers.length||t?.excludedModels.length||t?.proxyUrl||t?.prefix)),F=c.useMemo(()=>!n||!t?.secretConfigured?null:u?"Leave API keys blank to keep the stored connector secrets.":"Leave the API key blank to keep the stored secret.",[t?.secretConfigured,n,u]),d=async()=>{if(A.length>0)return;const g=w.trim(),_=Ce(b),k=n&&t?.secretConfigured&&!g.length&&_.length===0,le={name:u?U:void 0,baseUrl:j,proxyUrl:y?N:void 0,prefix:y?I:void 0,headers:gs(R),excludedModels:y?Ce(T):void 0,models:fs(O),preserveSecrets:k,...u?_.length>0?{apiKeys:_}:{}:g.length>0?{apiKey:g}:{}};await i(le)};return e.jsx(Ge,{open:r,onOpenChange:a,children:e.jsx(Ve,{className:"overflow-hidden p-0 sm:max-w-3xl",children:e.jsxs("div",{className:"max-h-[85vh] overflow-y-auto",children:[e.jsx("div",{className:"border-b bg-muted/20 px-6 py-5",children:e.jsxs(ze,{className:"gap-4 text-left",children:[e.jsxs("div",{className:"flex items-start gap-4",children:[e.jsx("div",{className:"flex h-12 w-12 items-center justify-center rounded-xl border bg-background",children:e.jsx(ue,{provider:pe(s),size:"md"})}),e.jsxs("div",{className:"min-w-0",children:[e.jsxs("div",{className:"flex flex-wrap items-center gap-2",children:[e.jsx(Je,{children:n?`Edit ${l.familyName}`:`Set up ${l.familyName}`}),e.jsx(h,{variant:"outline",className:"uppercase text-[11px]",children:u?"connector":"api-key"})]}),e.jsx(_e,{className:"mt-1 max-w-2xl leading-6",children:l.description})]})]}),e.jsxs("div",{className:"grid gap-3 md:grid-cols-2",children:[e.jsx(ke,{title:"Required now",items:l.requiredNow,icon:e.jsx(he,{className:"h-4 w-4 text-primary"})}),e.jsx(ke,{title:"Optional later",items:l.optionalLater,icon:e.jsx(te,{className:"h-4 w-4 text-primary"})})]}),F?e.jsx("div",{className:"rounded-lg border border-amber-200 bg-amber-50 px-3 py-2 text-xs leading-5 text-amber-800",children:F}):null]})}),e.jsxs("div",{className:"space-y-6 px-6 py-6",children:[e.jsxs("section",{className:"space-y-4",children:[e.jsxs("div",{children:[e.jsx("div",{className:"text-sm font-semibold",children:"Required setup"}),e.jsx("div",{className:"mt-1 text-sm text-muted-foreground",children:"Save the smallest working configuration first."})]}),u?e.jsxs("div",{className:"grid gap-4",children:[e.jsxs("div",{className:"space-y-1.5",children:[e.jsx(M,{htmlFor:"connector-name",children:"Connector Name"}),e.jsx(P,{id:"connector-name",value:U,onChange:g=>K(g.target.value),placeholder:l.connectorPlaceholder}),e.jsx("p",{className:"text-xs text-muted-foreground",children:l.connectorHelper})]}),e.jsxs("div",{className:"space-y-1.5",children:[e.jsx(M,{htmlFor:"base-url",children:"Base URL"}),e.jsx(P,{id:"base-url",value:j,onChange:g=>q(g.target.value),placeholder:l.baseUrlPlaceholder}),e.jsx("p",{className:"text-xs text-muted-foreground",children:l.baseUrlHelper})]}),e.jsxs("div",{className:"space-y-1.5",children:[e.jsx(M,{children:"API Keys"}),e.jsx(Z,{value:b,onChange:p,rows:4,placeholder:`${l.keyPlaceholder}
6
- ${l.keyPlaceholder}`}),e.jsx("p",{className:"text-xs text-muted-foreground",children:l.keyHelper})]})]}):e.jsxs("div",{className:"space-y-1.5",children:[e.jsx(M,{htmlFor:"api-key",children:l.keyLabel}),e.jsx(P,{id:"api-key",type:"password",value:w,onChange:g=>L(g.target.value),placeholder:l.keyPlaceholder}),e.jsx("p",{className:"text-xs text-muted-foreground",children:l.keyHelper})]})]}),e.jsxs("section",{className:"space-y-4",children:[e.jsxs("div",{children:[e.jsx("div",{className:"text-sm font-semibold",children:"Optional routing"}),e.jsx("div",{className:"mt-1 text-sm text-muted-foreground",children:"Only fill these when the route needs more than the default behavior."})]}),u?null:e.jsxs("div",{className:"space-y-1.5",children:[e.jsx(M,{htmlFor:"base-url",children:"Base URL"}),e.jsx(P,{id:"base-url",value:j,onChange:g=>q(g.target.value),placeholder:l.baseUrlPlaceholder}),e.jsx("p",{className:"text-xs text-muted-foreground",children:l.baseUrlHelper})]}),e.jsxs("div",{className:"space-y-1.5",children:[e.jsx(M,{children:"Model Mappings"}),e.jsx(Z,{value:O,onChange:v,rows:4,placeholder:l.aliasesPlaceholder}),e.jsx("p",{className:"text-xs text-muted-foreground",children:l.aliasesHelper}),A.length>0?e.jsx("p",{className:"text-xs text-destructive",children:A[0]}):null]})]}),e.jsx(Qe,{open:S,onOpenChange:$,children:e.jsxs("div",{className:"rounded-xl border",children:[e.jsx(We,{asChild:!0,children:e.jsxs("button",{type:"button",className:"flex w-full items-center justify-between gap-4 px-4 py-4 text-left",children:[e.jsxs("div",{children:[e.jsxs("div",{className:"flex items-center gap-2 text-sm font-medium",children:[e.jsx(te,{className:"h-4 w-4 text-primary"}),"Advanced routing"]}),e.jsxs("div",{className:"mt-1 text-sm text-muted-foreground",children:["Headers",y?", proxy, prefix, and exclusions.":" and provider-specific overrides."]})]}),e.jsx(as,{className:D("h-4 w-4 text-muted-foreground transition-transform",S&&"rotate-180")})]})}),e.jsx(Xe,{className:"border-t px-4 py-4",children:e.jsxs("div",{className:"space-y-4",children:[e.jsxs("div",{className:"space-y-1.5",children:[e.jsx(M,{children:"Headers"}),e.jsx(Z,{value:R,onChange:C,rows:3,placeholder:l.headersPlaceholder}),e.jsx("p",{className:"text-xs text-muted-foreground",children:"Use headers only when the provider requires extra routing or auth context."})]}),y?e.jsxs(e.Fragment,{children:[e.jsxs("div",{className:"grid gap-4 md:grid-cols-2",children:[e.jsxs("div",{className:"space-y-1.5",children:[e.jsx(M,{htmlFor:"prefix",children:"Prefix"}),e.jsx(P,{id:"prefix",value:I,onChange:g=>J(g.target.value),placeholder:"glm-"}),e.jsx("p",{className:"text-xs text-muted-foreground",children:"Optional. Prepends model names before routing."})]}),e.jsxs("div",{className:"space-y-1.5",children:[e.jsx(M,{htmlFor:"proxy-url",children:"Proxy URL"}),e.jsx(P,{id:"proxy-url",value:N,onChange:g=>H(g.target.value),placeholder:"http://127.0.0.1:8080"}),e.jsx("p",{className:"text-xs text-muted-foreground",children:"Optional. Sends requests through an intermediate proxy."})]})]}),e.jsxs("div",{className:"space-y-1.5",children:[e.jsx(M,{children:"Excluded Models"}),e.jsx(Z,{value:T,onChange:B,rows:3,placeholder:"claude-opus-4-1\\nclaude-sonnet-4-5"}),e.jsx("p",{className:"text-xs text-muted-foreground",children:"Optional. One model ID per line when this route should reject specific upstream models."})]})]}):null]})})]})})]}),e.jsxs(Ye,{className:"border-t bg-muted/10 px-6 py-4",children:[e.jsx(f,{type:"button",variant:"outline",onClick:()=>a(!1),children:"Cancel"}),e.jsx(f,{type:"button",onClick:()=>void d(),disabled:o||A.length>0,children:o?"Saving...":u?n?"Save Connector":"Create Connector":"Save Entry"})]})]})})})}const ie=["cliproxy-ai-providers"];function Ns(){return us({queryKey:ie,queryFn:()=>ne.cliproxy.aiProviders.list()})}function ws(){const s=ge();return fe({mutationFn:({family:t,data:r})=>ne.cliproxy.aiProviders.create(t,r),onSuccess:()=>{s.invalidateQueries({queryKey:ie}),G.success("Provider entry created")},onError:t=>{G.error(t.message)}})}function Cs(){const s=ge();return fe({mutationFn:({family:t,entryId:r,data:a})=>ne.cliproxy.aiProviders.update(t,r,a),onSuccess:()=>{s.invalidateQueries({queryKey:ie}),G.success("Provider entry updated")},onError:t=>{G.error(t.message)}})}function ks(){const s=ge();return fe({mutationFn:({family:t,entryId:r})=>ne.cliproxy.aiProviders.delete(t,r),onSuccess:()=>{s.invalidateQueries({queryKey:ie}),G.success("Provider entry removed")},onError:t=>{G.error(t.message)}})}function Q({label:s,value:t,hint:r}){return e.jsxs("div",{className:"rounded-lg border bg-background p-3",children:[e.jsx("div",{className:"text-[11px] uppercase tracking-wide text-muted-foreground",children:s}),e.jsx("div",{className:"mt-1 break-all text-sm font-medium leading-5",children:t}),r?e.jsx("div",{className:"mt-1 text-xs text-muted-foreground",children:r}):null]})}function Ps(s){switch(s){case"ready":return{label:"Ready",className:"bg-emerald-50 text-emerald-700 hover:bg-emerald-50"};case"partial":return{label:"Needs attention",className:"bg-amber-50 text-amber-700 hover:bg-amber-50"};default:return{label:"Empty",className:"bg-muted text-muted-foreground hover:bg-muted"}}}function ce(s){return s.proxyUrl?"Proxy override":s.prefix?"Prefixed route":s.baseUrl?"Direct upstream":"Default runtime"}function Ke(s){return s.filter(t=>t.alias.trim().length>0).length}function He(s){return s.filter(t=>t.name.trim().length>0&&t.alias.trim().length===0).length}function re(s){const t=Ke(s),r=He(s),a=[];return t>0&&a.push(`${t} mapped`),r>0&&a.push(`${r} direct`),a.length>0?a.join(" + "):"No model rules"}function me({configured:s}){return e.jsx(h,{variant:"secondary",className:D("border-transparent text-[10px]",s?"bg-emerald-50 text-emerald-700 hover:bg-emerald-50":"bg-muted text-muted-foreground hover:bg-muted"),children:s?"Configured":"Missing secret"})}const V="<stored in CLIProxy>";function $e(s){switch(s.id){case"gemini-api-key":return{requiredNow:["Save the Gemini API key.","Leave Base URL blank unless you use a custom Gemini gateway.","Add model mappings only when Gemini model names differ from the requested ones."],optionalLater:["Headers for provider-specific project routing.","Base URL override for a proxy or regional endpoint.","Mappings such as claude-sonnet-4-5 -> gemini-2.5-pro."],emptyStateSummary:[`Requests to ${s.routePath} use CLIProxy-managed Gemini credentials.`,"The default upstream is enough for most Gemini setups.","Model mappings and headers are optional, not step one."],profileBoundary:"Use API Profiles when you want a CCS-native Anthropic-compatible profile instead of this CLIProxy-managed Gemini route.",editPrompts:[{label:"Base URL",hint:"Change it only for a custom Gemini gateway or regional endpoint."},{label:"Model mappings",hint:"Add them only when requested names and Gemini names differ."},{label:"Headers",hint:"Keep them empty unless the provider requires project or org routing."}]};case"codex-api-key":return{requiredNow:["Save the Codex or OpenAI API key.","Leave Base URL blank unless this route should hit a different OpenAI-style host.","Add mappings only when the upstream model name differs from what CCS requests."],optionalLater:["Base URL override for a gateway, proxy, or self-hosted endpoint.","Headers for org or project routing.","Mappings such as claude-sonnet-4-5 -> gpt-5."],emptyStateSummary:[`Requests to ${s.routePath} use CLIProxy-managed Codex credentials.`,"Most setups can keep the default upstream and skip extra routing.","Mappings are only needed when the upstream model naming does not match the requested one."],profileBoundary:"Use API Profiles when you want a CCS-native Anthropic-compatible profile rather than this CLIProxy-managed Codex route.",editPrompts:[{label:"Base URL",hint:"Change it only when Codex should resolve through another OpenAI-style endpoint."},{label:"Model mappings",hint:"Map requested model names to the exact upstream model ID only when needed."},{label:"Headers",hint:"Use headers sparingly for project routing or extra auth."}]};case"claude-api-key":return{requiredNow:["Save the Anthropic or compatible API key.","Leave Base URL blank unless this route should point at a custom Claude-compatible endpoint.","Add mappings only when the upstream model ID differs from the requested Claude model name."],optionalLater:["Prefix or proxy overrides for advanced route rewriting.","Excluded models when a route should block specific model IDs.","Headers for project-scoped routing."],emptyStateSummary:[`Requests to ${s.routePath} use a CLIProxy-managed Claude-compatible key.`,"Base URL, proxy, and prefix rewrites are advanced options, not the minimum setup.","Most users can start with a key only, then add mappings or filters if routing needs it."],profileBoundary:"Use API Profiles when you want a CCS-native Anthropic-compatible profile or preset instead of this CLIProxy-managed Claude route.",editPrompts:[{label:"Base URL",hint:"Change it only when Claude traffic should target another compatible endpoint."},{label:"Mappings",hint:"Add them only when the requested Claude model name should route to a different upstream ID."},{label:"Advanced routing",hint:"Proxy, prefix, headers, and exclusions are for edge cases. Leave them blank when unsure."}]};case"vertex-api-key":return{requiredNow:["Save the Vertex API key.","Leave Base URL blank unless a regional or gateway endpoint is required.","Add mappings only when the upstream model name differs from the requested name."],optionalLater:["Base URL override for a regional gateway.","Headers for provider-specific routing.","Mappings for translating requested names to Vertex model IDs."],emptyStateSummary:[`Requests to ${s.routePath} use CLIProxy-managed Vertex credentials.`,"Most setups start with the key only and keep the default endpoint.","Mappings and headers are optional follow-up steps."],profileBoundary:"Use API Profiles when you need a CCS-native Anthropic-compatible profile rather than this CLIProxy-managed Vertex route.",editPrompts:[{label:"Base URL",hint:"Use it only for a regional gateway or managed Vertex endpoint."},{label:"Model mappings",hint:"Add them only when the requested names need translating upstream."},{label:"Headers",hint:"Keep them empty unless the provider requires extra routing context."}]};case"openai-compatibility":return{requiredNow:["Name the connector, for example openrouter or together.","Set the connector Base URL.","Add at least one API key before saving."],optionalLater:["Headers for provider-specific auth or project routing.","Model mappings such as claude-sonnet-4-5 -> gpt-4.1.","Additional API keys for the same connector."],emptyStateSummary:[`Requests to ${s.routePath} resolve through a named OpenAI-compatible connector.`,"This flow needs a connector name, a Base URL, and one or more API keys.","Headers and mappings come after the connector is already working."],profileBoundary:"Use API Profiles when you want a CCS-native Anthropic-compatible profile, preset, or provider outside the CLIProxy connector flow.",editPrompts:[{label:"Connector identity",hint:"Keep the connector name and Base URL stable once clients depend on it."},{label:"Model mappings",hint:"Only add them when the connector expects a different upstream model ID."},{label:"Headers",hint:"Use them for provider-specific auth or project routing, not as a default."}]}}}function z(s){return s.split(`
7
- `).map(t=>t.trim()).filter(t=>t.length>0)}function ae(s){return s.split(`
8
- `).map(t=>t.trim()).filter(t=>t.length>0).map(t=>{const r=t.includes(":")?":":"=",[a,...i]=t.split(r);return{key:a.trim(),value:i.join(r).trim()}}).filter(t=>t.key.length>0)}function W(s){return Ue(s)}function As(s){return(s?.headers||[]).map(t=>`${t.key}: ${t.value}`).join(`
9
- `)}function Ss(s){return(s?.excludedModels||[]).join(`
10
- `)}function Ms(s){return xe(s?.models)}function de(s){return{name:s.name||"",baseUrl:s.baseUrl||"",proxyUrl:s.proxyUrl||"",prefix:s.prefix||"",headersText:As(s),excludedModelsText:Ss(s),modelAliasesText:Ms(s),apiKey:"",apiKeysText:""}}function Us(s){const t=ae(s);if(t.length!==0)return Object.fromEntries(t.map(r=>[r.key,r.value]))}function Is(s){const t=W(s).map(r=>r.alias.trim()?{name:r.name,alias:r.alias}:{name:r.name});return t.length>0?t:void 0}function Pe(s){return Array.isArray(s)?xe(s):""}function Ls(s){const t=z(s);return t.length>0?t:void 0}function Ae(s,t,r){const a=Us(r.headersText),i=Is(r.modelAliasesText),o=Ls(r.excludedModelsText),l=r.apiKey.trim()||(t.secretConfigured?V:"");if(s.id==="openai-compatibility"){const n=z(r.apiKeysText),u=t.apiKeysMasked?.length||1;return{name:r.name.trim()||t.name||"connector","base-url":r.baseUrl.trim(),...a?{headers:a}:{},"api-key-entries":n.length>0?n.map(y=>({"api-key":y})):t.secretConfigured?Array.from({length:u},()=>({"api-key":V})):[],...i?{models:i}:{}}}return{"api-key":l,...r.baseUrl.trim()?{"base-url":r.baseUrl.trim()}:{},...r.proxyUrl.trim()?{"proxy-url":r.proxyUrl.trim()}:{},...r.prefix.trim()?{prefix:r.prefix.trim()}:{},...a?{headers:a}:{},...o?{"excluded-models":o}:{},...i?{models:i}:{}}}function Rs(s,t,r){const a=JSON.parse(r);if(!a||typeof a!="object"||Array.isArray(a))throw new Error("Raw config must be a JSON object.");if(s.id==="openai-compatibility"){const o=a,n=(Array.isArray(o["api-key-entries"])?o["api-key-entries"]:[]).map(u=>typeof u=="string"?u:u&&typeof u=="object"&&typeof u["api-key"]=="string"?u["api-key"]:"").filter(u=>u&&u!==V);return{name:typeof o.name=="string"?o.name:t.name||"",baseUrl:typeof o["base-url"]=="string"?o["base-url"]:"",proxyUrl:"",prefix:"",headersText:o.headers&&typeof o.headers=="object"&&!Array.isArray(o.headers)?Object.entries(o.headers).map(([u,y])=>`${u}: ${y}`).join(`
11
- `):"",excludedModelsText:"",modelAliasesText:Pe(o.models),apiKey:"",apiKeysText:n.join(`
12
- `)}}const i=a;return{name:"",baseUrl:typeof i["base-url"]=="string"?i["base-url"]:"",proxyUrl:typeof i["proxy-url"]=="string"?i["proxy-url"]:"",prefix:typeof i.prefix=="string"?i.prefix:"",headersText:i.headers&&typeof i.headers=="object"&&!Array.isArray(i.headers)?Object.entries(i.headers).map(([o,l])=>`${o}: ${l}`).join(`
13
- `):"",excludedModelsText:Array.isArray(i["excluded-models"])?i["excluded-models"].join(`
14
- `):"",modelAliasesText:Pe(i.models),apiKey:typeof i["api-key"]=="string"&&i["api-key"]!==V?i["api-key"]:"",apiKeysText:""}}function Ts(s,t,r){if(s.id==="openai-compatibility"){const o=z(r.apiKeysText),l=t.secretConfigured&&o.length===0;return{name:r.name.trim(),baseUrl:r.baseUrl.trim(),headers:ae(r.headersText),models:W(r.modelAliasesText),preserveSecrets:l,...o.length>0?{apiKeys:o}:{}}}const a=r.apiKey.trim(),i=t.secretConfigured&&a.length===0;return{baseUrl:r.baseUrl.trim(),proxyUrl:r.proxyUrl.trim(),prefix:r.prefix.trim(),headers:ae(r.headersText),excludedModels:z(r.excludedModelsText),models:W(r.modelAliasesText),preserveSecrets:i,...a.length>0?{apiKey:a}:{}}}function Es(s,t,r){const a={ANTHROPIC_BASE_URL:`${r.target}${s.routePath}`,ANTHROPIC_AUTH_TOKEN:"ccs-internal-managed"},i=W(t.modelAliasesText).find(o=>o.name.trim());return i?.name&&(a.ANTHROPIC_MODEL=es(i)),{env:a}}function Se({badge:s,title:t,items:r}){return e.jsxs("div",{className:"rounded-xl border bg-background p-4",children:[e.jsxs("div",{className:"flex flex-wrap items-center gap-2",children:[e.jsx(h,{variant:"secondary",className:"text-[11px]",children:s}),e.jsx("div",{className:"text-sm font-medium",children:t})]}),e.jsx("div",{className:"mt-4 space-y-3",children:r.map((a,i)=>e.jsxs("div",{className:"flex items-start gap-3 rounded-lg border bg-muted/10 px-3 py-3",children:[e.jsx("div",{className:"mt-0.5 flex h-5 w-5 shrink-0 items-center justify-center rounded-full border bg-background text-[11px] font-semibold text-muted-foreground",children:i+1}),e.jsx("div",{className:"text-sm leading-6 text-muted-foreground",children:a})]},`${t}:${a}`))})]})}function E({label:s,helper:t,children:r}){return e.jsxs("div",{className:"space-y-2",children:[e.jsx("div",{className:"text-[11px] font-medium uppercase tracking-wide text-muted-foreground",children:s}),r,t?e.jsx("div",{className:"text-xs leading-5 text-muted-foreground",children:t}):null]})}function ee({value:s,onChange:t,placeholder:r,rows:a=4}){return e.jsx("textarea",{rows:a,value:s,onChange:i=>t(i.target.value),placeholder:r,className:"flex min-h-24 w-full rounded-md border border-input bg-background 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 qs({family:s,entry:t,source:r,isSaving:a,onSave:i,onDelete:o}){const l=$e(s),[n,u]=c.useState(()=>de(t)),[y,U]=c.useState(null),[K,j]=c.useState(!0),[q,N]=c.useState(null),[H,I]=c.useState("config"),[J,w]=c.useState("raw"),L=c.useMemo(()=>JSON.stringify(Ae(s,t,de(t)),null,2),[t,s]),b=c.useMemo(()=>JSON.stringify(Ae(s,t,n),null,2),[n,t,s]),p=y??b,R=c.useMemo(()=>Es(s,n,r),[n,s,r]),C=c.useMemo(()=>W(n.modelAliasesText),[n.modelAliasesText]),T=c.useMemo(()=>Me(n.modelAliasesText),[n.modelAliasesText]),B=c.useMemo(()=>ae(n.headersText),[n.headersText]),O=c.useMemo(()=>z(n.excludedModelsText),[n.excludedModelsText]),v=c.useMemo(()=>JSON.stringify(R,null,2),[R]),A=Ke(C),S=He(C),$=B.length+O.length+(n.proxyUrl.trim()?1:0)+(n.prefix.trim()?1:0),F=s.id==="openai-compatibility"?n.headersText.trim().length>0:!!(n.proxyUrl.trim()||n.prefix.trim()||n.headersText.trim()||n.excludedModelsText.trim()),d=y!==null?y!==L:b!==L,g=c.useMemo(()=>{if(s.id==="openai-compatibility"){const m=[];return n.name.trim()||m.push("name"),n.baseUrl.trim()||m.push("base-url"),!t.secretConfigured&&z(n.apiKeysText).length===0&&m.push("api-key-entries"),m}return!t.secretConfigured&&!n.apiKey.trim()?["api-key"]:[]},[n.apiKey,n.apiKeysText,n.baseUrl,n.name,t.secretConfigured,s.id]),_=K&&g.length===0&&T.length===0&&d,k=m=>{u(x=>m(x)),U(null),j(!0),N(null)},le=m=>{U(m);try{const x=Rs(s,t,m);u(x),j(!0),N(null)}catch(x){j(!1),N(x instanceof Error?x.message:"Invalid JSON")}},De=()=>{u(de(t)),U(null),j(!0),N(null)},ve=m=>{k(x=>m==="minimal"?s.id==="openai-compatibility"?{...x,headersText:"",modelAliasesText:""}:{...x,baseUrl:"",proxyUrl:"",prefix:"",headersText:"",excludedModelsText:"",modelAliasesText:""}:{...x,proxyUrl:"",prefix:"",headersText:"",excludedModelsText:s.id==="openai-compatibility"?x.excludedModelsText:""})};return e.jsxs("div",{className:"grid min-h-0 flex-1 grid-cols-[minmax(360px,0.44fr)_minmax(0,0.56fr)] divide-x overflow-hidden rounded-b-xl border-x border-b bg-card",children:[e.jsx("div",{className:"min-h-0 overflow-hidden bg-muted/5",children:e.jsxs(be,{value:H,onValueChange:I,className:"flex h-full flex-col",children:[e.jsxs("div",{className:"border-b bg-background px-4 pt-4",children:[e.jsxs("div",{className:"mb-3 flex flex-wrap items-start justify-between gap-3",children:[e.jsxs("div",{className:"space-y-2",children:[e.jsxs("div",{className:"flex flex-wrap items-center gap-2",children:[e.jsx("h3",{className:"truncate text-lg font-semibold",children:t.label}),e.jsx(me,{configured:t.secretConfigured}),e.jsx(h,{variant:"outline",className:"uppercase",children:s.authMode})]}),e.jsxs("div",{className:"flex flex-wrap gap-2",children:[e.jsx(h,{variant:"outline",className:"font-mono text-[11px]",children:s.routePath}),e.jsx(h,{variant:"outline",className:"text-[11px]",children:ce(t)}),e.jsx(h,{variant:"outline",className:"text-[11px]",children:r.label})]})]}),e.jsxs("div",{className:"flex flex-wrap items-center gap-2",children:[e.jsxs(f,{type:"button",size:"sm",variant:"outline",onClick:De,disabled:!d,children:[e.jsx(ls,{className:"mr-1 h-3.5 w-3.5"}),"Reset"]}),e.jsxs(f,{type:"button",size:"sm",variant:"outline",onClick:o,children:[e.jsx(os,{className:"mr-1 h-3.5 w-3.5"}),"Remove"]}),e.jsxs(f,{type:"button",size:"sm",onClick:()=>void i(Ts(s,t,n)),disabled:!_||a,children:[e.jsx(ds,{className:"mr-1 h-3.5 w-3.5"}),a?"Saving...":"Save"]})]})]}),e.jsxs(je,{className:"grid w-full grid-cols-2",children:[e.jsxs(X,{value:"config",className:"gap-2 text-xs",children:[e.jsx(te,{className:"h-3.5 w-3.5"}),"Config"]}),e.jsxs(X,{value:"usage",className:"gap-2 text-xs",children:[e.jsx(we,{className:"h-3.5 w-3.5"}),"Info & Usage"]})]})]}),e.jsx(Y,{value:"config",className:"mt-0 min-h-0 flex-1 overflow-hidden data-[state=inactive]:hidden",children:e.jsx(se,{className:"h-full",children:e.jsxs("div",{className:"space-y-6 p-5",children:[e.jsxs("div",{className:"rounded-xl border bg-background p-4",children:[e.jsxs("div",{className:"flex flex-wrap items-start justify-between gap-4",children:[e.jsxs("div",{className:"space-y-1",children:[e.jsx("div",{className:"text-sm font-medium",children:"Workspace presets"}),e.jsx("div",{className:"text-sm text-muted-foreground",children:"Keep the route lean by default, then layer routing only when this entry actually needs it."})]}),e.jsxs("div",{className:"flex flex-wrap gap-2",children:[e.jsx(f,{type:"button",size:"sm",variant:"outline",onClick:()=>ve("minimal"),children:"Minimal setup"}),e.jsx(f,{type:"button",size:"sm",variant:"outline",onClick:()=>ve("clean-routing"),children:"Clear routing noise"})]})]}),e.jsxs("div",{className:"mt-4 grid gap-3 2xl:grid-cols-3",children:[e.jsx(Q,{label:"Secret",value:t.secretConfigured?"Stored in CLIProxy":"Missing",hint:t.secretConfigured?"Rotate only when needed":"Required to save"}),e.jsx(Q,{label:"Model Rules",value:C.length>0?re(C):"No model rules",hint:"Requested model names stay direct unless remapped"}),e.jsx(Q,{label:"Advanced",value:$>0?`${$} active`:"Optional",hint:"Proxy, prefix, headers, and exclusions"})]})]}),g.length>0?e.jsxs("div",{className:"rounded-xl border border-amber-200 bg-amber-50/80 p-4 text-sm text-amber-900",children:["Missing required fields:"," ",e.jsx("span",{className:"font-mono",children:g.join(", ")})]}):null,e.jsxs("div",{className:"rounded-xl border bg-background p-4",children:[e.jsxs("div",{className:"mb-4 flex items-center gap-2 text-sm font-medium",children:[e.jsx(he,{className:"h-4 w-4 text-primary"}),"Connection"]}),e.jsxs("div",{className:"grid gap-4 2xl:grid-cols-2",children:[s.id==="openai-compatibility"?e.jsx(E,{label:"Connector Name",helper:"This is the saved connector label shown in the entry switcher.",children:e.jsx(P,{value:n.name,onChange:m=>k(x=>({...x,name:m.target.value})),placeholder:"openrouter"})}):e.jsx(E,{label:`${s.displayName} API Key`,helper:t.secretConfigured?"Leave blank to keep the stored secret. Enter a new value only to rotate it.":"Required before this route can authenticate.",children:e.jsx(P,{type:"password",value:n.apiKey,onChange:m=>k(x=>({...x,apiKey:m.target.value})),placeholder:t.secretConfigured?t.apiKeyMasked||V:"Paste provider API key"})}),s.id==="openai-compatibility"?e.jsx(E,{label:"API Keys",helper:t.secretConfigured?"One key per line. Leave empty to preserve the stored connector keys.":"Add one key per line. A connector needs at least one key.",children:e.jsx(ee,{value:n.apiKeysText,onChange:m=>k(x=>({...x,apiKeysText:m})),placeholder:"sk-...",rows:4})}):null,e.jsx(E,{label:"Base URL",helper:s.id==="openai-compatibility"?"Required for connectors. This is the upstream OpenAI-style endpoint.":"Leave blank unless this route should target another upstream host.",children:e.jsx(P,{value:n.baseUrl,onChange:m=>k(x=>({...x,baseUrl:m.target.value})),placeholder:s.id==="codex-api-key"?"https://api.openai.com/v1":s.id==="claude-api-key"?"https://api.anthropic.com":s.id==="openai-compatibility"?"https://openrouter.ai/api/v1":"https://provider.example.com"})}),s.id!=="openai-compatibility"?e.jsx(E,{label:"Proxy URL",helper:"Optional intermediary endpoint. Leave blank for direct routing.",children:e.jsx(P,{value:n.proxyUrl,onChange:m=>k(x=>({...x,proxyUrl:m.target.value})),placeholder:"https://proxy.example.com/v1"})}):null,s.id!=="openai-compatibility"?e.jsx(E,{label:"Prefix",helper:"Optional model prefix rewrite for advanced routing only.",children:e.jsx(P,{value:n.prefix,onChange:m=>k(x=>({...x,prefix:m.target.value})),placeholder:"provider/"})}):null]})]}),e.jsxs("div",{className:"rounded-xl border bg-background p-4",children:[e.jsxs("div",{className:"mb-4 flex items-center justify-between gap-3",children:[e.jsxs("div",{className:"flex items-center gap-2 text-sm font-medium",children:[e.jsx(Ee,{className:"h-4 w-4 text-primary"}),"Model rules"]}),e.jsxs("div",{className:"flex flex-wrap gap-2",children:[A>0?e.jsxs(h,{variant:"outline",children:[A," mapped"]}):null,S>0?e.jsxs(h,{variant:"outline",children:[S," direct"]}):null,C.length===0?e.jsx(h,{variant:"outline",children:"Optional"}):null]})]}),e.jsx(E,{label:"Requested [= Upstream]",helper:"Use requested=upstream for remaps. Use a plain model name when you want the route to expose that model directly.",children:e.jsx(ee,{value:n.modelAliasesText,onChange:m=>k(x=>({...x,modelAliasesText:m})),placeholder:`claude-sonnet-4-5=gpt-5
15
- glm-5`,rows:6})}),T.length>0?e.jsx("div",{className:"mt-3 rounded-md border border-destructive/30 bg-destructive/10 px-3 py-2 text-sm text-destructive",children:T[0]}):null]}),e.jsxs("div",{className:"rounded-xl border bg-background p-4",children:[e.jsxs("div",{className:"mb-4 flex items-center justify-between gap-3",children:[e.jsxs("div",{className:"flex items-center gap-2 text-sm font-medium",children:[e.jsx(te,{className:"h-4 w-4 text-primary"}),"Advanced routing"]}),e.jsx(h,{variant:"outline",children:F?`${$} active`:"Optional"})]}),e.jsxs("div",{className:"grid gap-4 2xl:grid-cols-2",children:[e.jsx(E,{label:"Headers",helper:"One header per line. Use only when the upstream expects org, project, or secondary auth headers.",children:e.jsx(ee,{value:n.headersText,onChange:m=>k(x=>({...x,headersText:m})),placeholder:"OpenAI-Organization: org_...",rows:5})}),s.id!=="openai-compatibility"?e.jsx(E,{label:"Excluded Models",helper:"One model ID per line. These models will be blocked for this entry.",children:e.jsx(ee,{value:n.excludedModelsText,onChange:m=>k(x=>({...x,excludedModelsText:m})),placeholder:"claude-opus-4-1",rows:5})}):e.jsx("div",{className:"rounded-xl border border-dashed bg-muted/10 p-4 text-sm text-muted-foreground",children:"OpenAI-compatible connectors keep advanced routing lean. Add headers or model mappings first before introducing extra route layers elsewhere."})]})]})]})})}),e.jsx(Y,{value:"usage",className:"mt-0 min-h-0 flex-1 overflow-hidden data-[state=inactive]:hidden",children:e.jsx(se,{className:"h-full",children:e.jsxs("div",{className:"space-y-4 p-5",children:[e.jsxs("div",{className:"rounded-xl border bg-background p-4",children:[e.jsxs("div",{className:"flex items-center gap-2 text-sm font-medium",children:[e.jsx(qe,{className:"h-4 w-4 text-primary"}),"How this route behaves"]}),e.jsxs("div",{className:"mt-3 space-y-3 text-sm leading-6 text-muted-foreground",children:[e.jsxs("div",{className:"rounded-lg border bg-muted/10 p-4",children:["Calls to ",e.jsx("span",{className:"font-mono",children:s.routePath})," use this saved entry inside CLIProxy."]}),e.jsx("div",{className:"rounded-lg border bg-muted/10 p-4",children:n.baseUrl.trim()?`Traffic resolves to ${n.baseUrl.trim()} unless you layer another proxy in front.`:"Traffic keeps the family default upstream unless you add a custom base URL."}),e.jsx("div",{className:"rounded-lg border bg-muted/10 p-4",children:C.length>0?`${re(C)} rule${C.length===1?"":"s"} active for this entry.`:"Requested model names pass through unchanged until you add explicit model rules."})]})]}),e.jsxs("div",{className:"rounded-xl border bg-background p-4",children:[e.jsxs("div",{className:"flex items-center gap-2 text-sm font-medium",children:[e.jsx(we,{className:"h-4 w-4 text-primary"}),"When API Profiles fits better"]}),e.jsx("div",{className:"mt-3 text-sm leading-6 text-muted-foreground",children:l.profileBoundary})]}),e.jsxs("div",{className:"rounded-xl border bg-background p-4",children:[e.jsxs("div",{className:"flex items-center gap-2 text-sm font-medium",children:[e.jsx(Oe,{className:"h-4 w-4 text-primary"}),"Editing rule of thumb"]}),e.jsx("div",{className:"mt-3 space-y-3",children:l.editPrompts.map(m=>e.jsxs("div",{className:"rounded-lg border bg-muted/10 p-4",children:[e.jsx("div",{className:"text-sm font-medium",children:m.label}),e.jsx("div",{className:"mt-1 text-sm leading-6 text-muted-foreground",children:m.hint})]},m.label))})]})]})})})]})}),e.jsx("div",{className:"min-h-0 overflow-hidden",children:e.jsxs(be,{value:J,onValueChange:w,className:"flex h-full flex-col",children:[e.jsxs("div",{className:"border-b bg-background px-4 pt-4",children:[e.jsxs("div",{className:"mb-3 flex items-center justify-between gap-3",children:[e.jsx("div",{className:"text-sm font-medium",children:"Raw configuration"}),e.jsxs("div",{className:"text-xs text-muted-foreground",children:["Target ",e.jsx("span",{className:"font-mono",children:r.target})]})]}),e.jsxs(je,{className:"grid w-full grid-cols-2",children:[e.jsxs(X,{value:"raw",className:"gap-2 text-xs",children:[e.jsx(cs,{className:"h-3.5 w-3.5"}),"Raw Entry Config"]}),e.jsxs(X,{value:"preview",className:"gap-2 text-xs",children:[e.jsx(ms,{className:"h-3.5 w-3.5"}),"settings.json Preview"]})]})]}),e.jsx(Y,{value:"raw",className:"mt-0 min-h-0 flex-1 overflow-hidden data-[state=inactive]:hidden",children:e.jsxs("div",{className:"flex h-full flex-col",children:[e.jsx("div",{className:"border-b bg-muted/10 px-6 py-3 text-sm text-muted-foreground",children:t.secretConfigured?`Stored secrets are shown as ${V}. Replace the placeholder only when you want to rotate the secret.`:"Add secrets directly in the JSON or use the form on the left."}),q?e.jsx("div",{className:"mx-6 mt-4 rounded-md border border-destructive/30 bg-destructive/10 px-3 py-2 text-sm text-destructive",children:q}):null,e.jsx("div",{className:"min-h-0 flex-1 px-6 pb-4 pt-4",children:e.jsx("div",{className:"h-full overflow-hidden rounded-md border bg-background",children:e.jsx(Ne,{value:p,onChange:le,language:"json",minHeight:"100%",heightMode:"fill-parent"})})})]})}),e.jsx(Y,{value:"preview",className:"mt-0 min-h-0 flex-1 overflow-hidden data-[state=inactive]:hidden",children:e.jsxs("div",{className:"flex h-full flex-col",children:[e.jsx("div",{className:"border-b bg-muted/10 px-6 py-3 text-sm text-muted-foreground",children:"Derived preview for a CCS profile that points to this CLIProxy route. The route stays local; the upstream key remains managed here."}),e.jsx("div",{className:"min-h-0 flex-1 px-6 pb-4 pt-4",children:e.jsx("div",{className:"h-full overflow-hidden rounded-md border bg-background",children:e.jsx(Ne,{value:v,onChange:()=>{},language:"json",readonly:!0,minHeight:"100%",heightMode:"fill-parent"})})}),e.jsx("div",{className:"mx-6 mb-4 overflow-hidden rounded-md border",children:e.jsx(Ze,{profileEnv:R.env})})]})})]})})]})}function Os({family:s,onAddEntry:t,onOpenControlPanel:r,onOpenProfiles:a}){const i=$e(s),o=s.supportsNamedEntries?"Create connector":`Add ${s.displayName} entry`;return e.jsx("div",{className:"space-y-5",children:e.jsxs("div",{className:"grid gap-5 2xl:grid-cols-[minmax(0,1fr)_320px]",children:[e.jsxs("div",{className:"rounded-xl border bg-card",children:[e.jsxs("div",{className:"flex flex-wrap items-start justify-between gap-4 border-b px-5 py-4",children:[e.jsxs("div",{className:"flex items-start gap-3",children:[e.jsx("div",{className:"flex h-10 w-10 items-center justify-center rounded-lg bg-muted",children:e.jsx(he,{className:"h-5 w-5 text-muted-foreground"})}),e.jsxs("div",{children:[e.jsxs("h3",{className:"text-lg font-semibold",children:["Set up ",s.displayName]}),e.jsx("p",{className:"mt-1 text-sm text-muted-foreground",children:"Start with the smallest working setup. Add routing rules only after the route is already working."})]})]}),e.jsxs(f,{type:"button",onClick:t,children:[e.jsx(Re,{className:"mr-1 h-4 w-4"}),o]})]}),e.jsxs("div",{className:"space-y-4 p-5",children:[e.jsxs("div",{className:"rounded-xl border bg-muted/10 p-4",children:[e.jsx("div",{className:"text-sm font-medium",children:"Recommended setup flow"}),e.jsx("div",{className:"mt-1 text-sm text-muted-foreground",children:"Finish the left section first. Treat the right section as optional follow-up."}),e.jsxs("div",{className:"mt-4 space-y-4",children:[e.jsx(Se,{badge:"Do this first",title:"Minimum working setup",items:i.requiredNow}),e.jsx(Se,{badge:"Only if needed",title:"Optional later",items:i.optionalLater})]})]}),e.jsxs("div",{className:"rounded-xl border bg-muted/15 p-4",children:[e.jsxs("div",{className:"flex items-center gap-2 text-sm font-medium",children:[e.jsx(Oe,{className:"h-4 w-4 text-emerald-600"}),"Need the other pages?"]}),e.jsx("div",{className:"mt-2 text-sm leading-6 text-muted-foreground",children:"Use Overview or Control Panel for OAuth sign-ins. Use API Profiles only for CCS-native Anthropic-compatible profiles and presets."}),e.jsxs("div",{className:"mt-4 flex flex-wrap gap-2",children:[e.jsx(f,{type:"button",size:"sm",variant:"outline",onClick:r,children:"Control Panel"}),e.jsxs(f,{type:"button",size:"sm",variant:"outline",onClick:a,children:["API Profiles",e.jsx(Te,{className:"ml-1 h-3.5 w-3.5"})]})]})]})]})]}),e.jsxs("div",{className:"space-y-4",children:[e.jsxs("div",{className:"rounded-xl border bg-card p-5",children:[e.jsxs("div",{className:"flex items-center gap-2 text-sm font-medium",children:[e.jsx(qe,{className:"h-4 w-4 text-primary"}),"What this route does"]}),e.jsxs("div",{className:"mt-3 flex flex-wrap gap-2",children:[e.jsx(h,{variant:"outline",className:"font-mono text-[11px]",children:s.routePath}),e.jsx(h,{variant:"outline",className:"uppercase text-[11px]",children:s.authMode})]}),e.jsx("div",{className:"mt-4 space-y-3",children:i.emptyStateSummary.map(l=>e.jsx("div",{className:"rounded-lg border bg-muted/10 p-4 text-sm leading-6 text-muted-foreground",children:l},l))})]}),e.jsxs("div",{className:"rounded-xl border bg-card p-5",children:[e.jsxs("div",{className:"flex items-center gap-2 text-sm font-medium",children:[e.jsx(Ee,{className:"h-4 w-4 text-primary"}),"When API Profiles is the better fit"]}),e.jsx("div",{className:"mt-3 text-sm leading-6 text-muted-foreground",children:i.profileBoundary})]})]})]})})}function Ws(){const s=Be(),t=Fe(),{data:r,error:a,isLoading:i,isFetching:o,refetch:l}=Ns(),n=ws(),u=Cs(),y=ks(),[U,K]=c.useState(!1),[j,q]=c.useState(null),[N,H]=c.useState(null),[I,J]=c.useState(null),w=c.useMemo(()=>r?.families??[],[r?.families]),L=c.useMemo(()=>new URLSearchParams(s.search).get("family")||null,[s.search]),b=c.useMemo(()=>L&&w.some(d=>d.id===L)?L:w[0]?.id??"gemini-api-key",[w,L]),p=c.useMemo(()=>w.find(d=>d.id===b)||null,[w,b]),R=c.useMemo(()=>{const d=p?.entries??[];return d.length===0?null:I&&d.some(g=>g.id===I)?I:d[0]?.id??null},[I,p?.entries]),C=d=>{t({pathname:s.pathname,search:`?family=${d}`},{replace:!0})},T=()=>{q(null),K(!0)};if(i)return e.jsxs("div",{className:"flex h-full min-h-0 overflow-hidden",children:[e.jsx(ye,{className:"h-full w-80 rounded-none"}),e.jsx(ye,{className:"h-full flex-1 rounded-none"})]});if(a||!r||!p){const d=a instanceof Error?a.message:"Failed to load CLIProxy AI providers. Check the local server and try again.";return e.jsx("div",{className:"flex h-full min-h-0 items-center justify-center bg-muted/10 p-6",children:e.jsx("div",{className:"w-full max-w-2xl rounded-xl border bg-card p-6 shadow-sm",children:e.jsxs("div",{className:"flex items-start gap-4",children:[e.jsx("div",{className:"flex h-11 w-11 items-center justify-center rounded-lg bg-destructive/10",children:e.jsx(Ie,{className:"h-5 w-5 text-destructive"})}),e.jsxs("div",{className:"min-w-0 flex-1",children:[e.jsx("div",{className:"text-lg font-semibold",children:"Unable to load AI Providers"}),e.jsx("div",{className:"mt-2 text-sm text-muted-foreground",children:d}),e.jsxs("div",{className:"mt-4 flex flex-wrap gap-2",children:[e.jsxs(f,{type:"button",onClick:()=>void l(),children:[e.jsx(oe,{className:"mr-2 h-4 w-4"}),"Retry"]}),e.jsx(f,{type:"button",variant:"outline",onClick:()=>t("/cliproxy/control-panel"),children:"Control Panel"}),e.jsx(f,{type:"button",variant:"outline",onClick:()=>t("/providers"),children:"API Profiles"})]})]})]})})})}const B=p.entries.filter(d=>d.secretConfigured),O=w.filter(d=>d.status==="ready").length,v=p.entries.find(d=>d.id===R)??null,A=p.entries.length>1,S=Ps(p.status),$=p.entries.length>0,F=e.jsxs("div",{className:"rounded-xl border bg-background p-4",children:[e.jsxs("div",{className:"flex items-start justify-between gap-3",children:[e.jsxs("div",{children:[e.jsx("div",{className:"text-[11px] uppercase tracking-wide text-muted-foreground",children:"Setup status"}),e.jsx("div",{className:"mt-1 text-sm font-medium",children:p.routePath})]}),e.jsx(h,{variant:"secondary",className:S.className,children:S.label})]}),e.jsxs("div",{className:"mt-3 grid gap-2 sm:grid-cols-2",children:[e.jsx(Q,{label:"Entries",value:`${p.entries.length}`,hint:"configured rows"}),e.jsx(Q,{label:"Secrets",value:`${B.length}/${p.entries.length||0}`,hint:"stored in CLIProxy"})]}),e.jsx("div",{className:"mt-3 rounded-lg border bg-muted/15 p-3 text-xs leading-5 text-muted-foreground",children:"Overview handles OAuth sign-ins. This page stores CLIProxy-managed keys and connectors. API Profiles remains for CCS-native Anthropic-compatible profiles."})]});return e.jsxs("div",{className:"flex h-full min-h-0 overflow-hidden",children:[e.jsxs("div",{className:"flex w-80 flex-col border-r bg-muted/30",children:[e.jsxs("div",{className:"border-b bg-background p-4",children:[e.jsxs("div",{className:"mb-1 flex items-center justify-between",children:[e.jsxs("div",{className:"flex items-center gap-2",children:[e.jsx(ns,{className:"h-5 w-5 text-primary"}),e.jsx("h1",{className:"font-semibold",children:"CLIProxy Plus"})]}),e.jsx(f,{variant:"ghost",size:"icon",className:"h-8 w-8",type:"button",onClick:()=>void l(),disabled:o,children:e.jsx(oe,{className:D("h-4 w-4",o&&"animate-spin")})})]}),e.jsx("p",{className:"mb-3 text-xs text-muted-foreground",children:"AI Providers"}),e.jsxs(f,{variant:"default",size:"sm",className:"w-full gap-2",type:"button",onClick:T,children:[e.jsx(Re,{className:"h-4 w-4"}),p.supportsNamedEntries?"Create Connector":`Add ${p.displayName} Entry`]})]}),e.jsx(se,{className:"flex-1",children:e.jsxs("div",{className:"p-2",children:[e.jsx("div",{className:"px-3 py-2 text-xs font-medium uppercase tracking-wide text-muted-foreground",children:"Provider Families"}),e.jsx(xs,{families:w,selectedFamily:b,onSelect:C})]})}),e.jsx("div",{className:"border-t p-3",children:e.jsx(ss,{})}),e.jsx("div",{className:"border-t bg-background p-3 text-xs text-muted-foreground",children:e.jsxs("div",{className:"flex items-center justify-between",children:[e.jsxs("span",{children:[w.length," families"]}),e.jsxs("span",{className:"flex items-center gap-1",children:[e.jsx(Le,{className:"h-3 w-3 text-emerald-600"}),O," ready"]})]})})]}),e.jsxs("div",{className:"flex min-w-0 flex-1 flex-col bg-background",children:[e.jsx("div",{className:"shrink-0 border-b bg-background px-6 py-4",children:e.jsxs("div",{className:"flex flex-wrap items-start justify-between gap-4",children:[e.jsxs("div",{className:"flex items-center gap-3",children:[e.jsx(ue,{provider:pe(p.id),size:"lg"}),e.jsxs("div",{children:[e.jsxs("div",{className:"flex flex-wrap items-center gap-2",children:[e.jsx("h2",{className:"text-lg font-semibold",children:p.displayName}),e.jsx(h,{variant:"secondary",className:S.className,children:S.label}),e.jsx(h,{variant:"outline",className:"uppercase",children:p.authMode}),e.jsx(h,{variant:"outline",className:"font-mono text-[11px]",children:p.routePath})]}),e.jsx("p",{className:"mt-0.5 text-xs text-muted-foreground",children:p.description})]})]}),e.jsxs("div",{className:"flex flex-wrap items-center gap-2",children:[e.jsx(f,{type:"button",variant:"ghost",size:"sm",onClick:()=>void l(),disabled:o,children:e.jsx(oe,{className:D("h-4 w-4",o&&"animate-spin")})}),e.jsx(f,{type:"button",variant:"outline",onClick:()=>t("/cliproxy/control-panel"),children:"Control Panel"}),e.jsxs(f,{type:"button",variant:"outline",onClick:()=>t("/providers"),children:["API Profiles",e.jsx(Te,{className:"ml-1 h-3.5 w-3.5"})]})]})]})}),$?e.jsxs("div",{className:"flex min-h-0 flex-1 flex-col overflow-hidden",children:[e.jsxs("div",{className:"shrink-0 border-b bg-muted/5 px-6 py-4",children:[e.jsxs("div",{className:"mb-3 flex flex-wrap items-center justify-between gap-3",children:[e.jsxs("div",{className:"flex items-center gap-2 text-xs font-medium uppercase tracking-wide text-muted-foreground",children:[e.jsx(is,{className:"h-3 w-3"}),A?"Saved entries":"Saved entry"]}),e.jsxs("div",{className:"flex flex-wrap items-center gap-2",children:[e.jsxs(h,{variant:"outline",className:"text-[11px]",children:[p.entries.length," entries"]}),e.jsxs(h,{variant:"outline",className:"text-[11px]",children:[B.length,"/",p.entries.length," secrets stored"]})]})]}),A?e.jsx("div",{className:"flex flex-wrap gap-3",children:p.entries.map(d=>e.jsxs("button",{type:"button",onClick:()=>J(d.id),className:D("min-w-[220px] max-w-[280px] flex-1 rounded-xl border bg-background px-4 py-3 text-left transition-colors",d.id===R?"border-primary/30 bg-primary/5 shadow-sm":"border-border/60 hover:bg-muted/50"),children:[e.jsxs("div",{className:"flex flex-wrap items-center gap-2",children:[e.jsx("div",{className:"truncate text-sm font-medium",children:d.label}),e.jsx(me,{configured:d.secretConfigured})]}),e.jsx("div",{className:"mt-2 truncate text-xs text-muted-foreground",children:d.baseUrl||p.routePath}),e.jsxs("div",{className:"mt-3 flex flex-wrap gap-1.5",children:[e.jsx(h,{variant:"outline",className:"text-[10px]",children:ce(d)}),d.models.length>0?e.jsx(h,{variant:"outline",className:"text-[10px]",children:re(d.models)}):null,e.jsxs(h,{variant:"outline",className:"text-[10px]",children:[d.headers.length," hdr"]})]})]},d.id))}):v?e.jsx("div",{className:"rounded-xl border bg-background px-4 py-3",children:e.jsxs("div",{className:"flex flex-wrap items-center justify-between gap-3",children:[e.jsxs("div",{className:"min-w-0",children:[e.jsxs("div",{className:"flex flex-wrap items-center gap-2",children:[e.jsx("div",{className:"truncate text-sm font-medium",children:v.label}),e.jsx(me,{configured:v.secretConfigured})]}),e.jsx("div",{className:"mt-1 truncate text-xs text-muted-foreground",children:v.baseUrl||p.routePath})]}),e.jsxs("div",{className:"flex flex-wrap gap-1.5",children:[e.jsx(h,{variant:"outline",className:"text-[10px]",children:ce(v)}),v.models.length>0?e.jsx(h,{variant:"outline",className:"text-[10px]",children:re(v.models)}):null,e.jsxs(h,{variant:"outline",className:"text-[10px]",children:[v.headers.length," hdr"]})]})]})}):null]}),v?e.jsx(qs,{family:p,entry:v,source:r.source,isSaving:u.isPending,onSave:async d=>{await u.mutateAsync({family:b,entryId:v.id,data:d}),l()},onDelete:()=>H(v)},v.id):null]}):e.jsx(se,{className:"flex-1",children:e.jsxs("div",{className:"space-y-6 p-6",children:[F,e.jsx(Os,{family:p,onAddEntry:T,onOpenControlPanel:()=>t("/cliproxy/control-panel"),onOpenProfiles:()=>t("/providers")})]})})]}),e.jsx(js,{family:b,entry:j,open:U,onOpenChange:K,onSubmit:async d=>{j?await u.mutateAsync({family:b,entryId:j.id,data:d}):await n.mutateAsync({family:b,data:d}),K(!1),q(null),l()},isSaving:n.isPending||u.isPending},`${b}:${j?.id??"new"}:${U?"open":"closed"}`),e.jsx(ts,{open:N!==null,title:"Remove provider entry?",description:N?`This removes ${N.label} from ${p.displayName}.`:"",confirmText:"Remove",variant:"destructive",onConfirm:async()=>{N&&(await y.mutateAsync({family:b,entryId:N.id}),H(null))},onCancel:()=>H(null)})]})}export{Ws as CliproxyAiProvidersPage};
@@ -1 +0,0 @@
1
- import{j as e}from"./radix-ui-Zb8sVEtn.js";import{r as s}from"./react-vendor-CNOkPC89.js";import{u as R}from"./tanstack-CrmUhA7Z.js";import{bb as g,Y as I}from"./index-DOn6k1jF.js";import{C as S}from"./default-ports-1QQSffYX.js";import{G as z,R as _,w as D}from"./icons-KVCk4_U8.js";import"./notifications-B2HqRBj7.js";import"./utils-CzKF5WmX.js";import"./form-utils-Bcoyqxpq.js";import"./code-highlight-BRUf_pqB.js";const k="cli-proxy-auth",T="isLoggedIn",O="apiBase",U="apiUrl",K="managementKey";function $(a){return a.startsWith("/")?new URL(a.replace(/\/$/,""),window.location.origin).href:a.replace(/\/$/,"")}function Q(a,c){window.localStorage.removeItem(k),window.localStorage.setItem(O,a),window.localStorage.setItem(U,a),window.localStorage.setItem(K,c),window.localStorage.setItem(T,"true")}function A(){window.localStorage.removeItem(k),window.localStorage.removeItem(O),window.localStorage.removeItem(U),window.localStorage.removeItem(K),window.localStorage.removeItem(T)}function X({port:a=S}){const c=s.useRef(null),[F,C]=s.useState(null),[M,B]=s.useState(0),[L,N]=s.useState(null),[Y,v]=s.useState(!1),{data:l,error:p}=R({queryKey:["cliproxy-server-config"],queryFn:()=>I.cliproxyServer.get(),staleTime:3e4});s.useEffect(()=>{p&&console.warn("[ControlPanelEmbed] Config fetch failed, using local mode:",p)},[p]);const E=!!(l?.remote?.enabled&&l?.remote?.host),{data:w,error:f}=R({queryKey:["auth-tokens-raw",E?"remote":"local"],enabled:l!==void 0&&!E,queryFn:async()=>{try{const t=await fetch(g("/settings/auth/tokens/raw"));if(!t.ok)throw new Error("Failed to fetch auth tokens");const n=await t.json(),o=n.managementSecret.value.trim();if(!o)throw new Error("Management secret missing");return Q($(g("/cliproxy-local/")),o),n}catch(t){throw A(),t}},staleTime:3e4}),{managementUrl:P,checkUrl:x,authToken:y,isRemote:i,displayHost:m}=s.useMemo(()=>{const t=l?.remote,n=l?.local?.port??a;if(t?.enabled&&t?.host){const o=t.protocol||"http",d=t.port||(o==="https"?443:S),h=o==="https"&&d===443||o==="http"&&d===80?"":`:${d}`,r=`${o}://${t.host}${h}`;return{managementUrl:`${r}/management.html`,checkUrl:`${r}/`,authToken:t.auth_token||void 0,isRemote:!0,displayHost:`${t.host}${h}`}}return{managementUrl:g("/cliproxy-local/management.html"),checkUrl:g("/cliproxy-local/"),authToken:w?.managementSecret?.value||void 0,isRemote:!1,displayHost:`localhost:${n}`}},[l,w,a]),b=`${P}:${i?"remote":"local"}:${x}:${y??"missing"}:${M}`,j=l!==void 0&&(i||!!w||!!f);s.useEffect(()=>{f&&console.warn("[ControlPanelEmbed] Failed to preload local control panel session, falling back to manual login:",f)},[f]),s.useEffect(()=>{if(!i)return()=>{A()}},[i]);const G=!j||!(F===b),q=()=>{if(!(!i||!c.current?.contentWindow||!y))try{const t=$(x),n=new URL(`${t}/`).origin;if(new URL(c.current.src,window.location.origin).origin!==n){console.warn("[ControlPanelEmbed] Remote iframe origin mismatch, skipping postMessage");return}c.current.contentWindow.postMessage({type:"ccs-auto-login",apiBase:t,managementKey:y},n)}catch(t){console.debug("[ControlPanelEmbed] Remote postMessage bootstrap failed:",t)}};s.useEffect(()=>{const t=new AbortController;let n=!1;const o=(r,u)=>{n||(v(r),N(u))},d=async()=>{try{if(i){const r=l?.remote,u=await I.cliproxyServer.test({host:r?.host??"",port:r?.port,protocol:r?.protocol??"http",authToken:r?.auth_token});u?.reachable?o(!0,null):o(!1,u?.error?`Remote CLIProxy at ${m}: ${u.error}`:`Remote CLIProxy at ${m} returned an error`)}else(await fetch(x,{signal:t.signal})).ok?o(!0,null):o(!1,"CLIProxy returned an error")}catch(r){if(r instanceof Error&&r.name==="AbortError")return;o(!1,i?`Remote CLIProxy at ${m} is not reachable`:"CLIProxy is not running")}},h=setTimeout(()=>t.abort(),2e3);return d().finally(()=>clearTimeout(h)),()=>{n=!0,t.abort()}},[x,i,m,l]);const H=()=>{C(b),q()},W=()=>{C(null),B(t=>t+1),N(null),v(!1)};return!Y&&L?e.jsxs("div",{className:"flex-1 flex flex-col",children:[e.jsxs("div",{className:"flex items-center justify-between p-4 border-b",children:[e.jsxs("div",{className:"flex items-center gap-2",children:[e.jsx(z,{className:"w-5 h-5 text-primary"}),e.jsx("h2",{className:"font-semibold",children:"CLIProxy Control Panel"})]}),e.jsxs("button",{className:"inline-flex items-center gap-2 px-3 py-1.5 text-sm border rounded-md hover:bg-muted",onClick:W,children:[e.jsx(_,{className:"w-4 h-4"}),"Retry"]})]}),e.jsx("div",{className:"flex-1 flex items-center justify-center bg-muted/20",children:e.jsxs("div",{className:"text-center max-w-md px-8",children:[e.jsx("div",{className:"w-16 h-16 rounded-full bg-destructive/10 flex items-center justify-center mx-auto mb-6",children:e.jsx(D,{className:"w-8 h-8 text-destructive"})}),e.jsx("h3",{className:"text-lg font-semibold mb-2",children:"CLIProxy Not Available"}),e.jsx("p",{className:"text-muted-foreground mb-4",children:L}),e.jsxs("p",{className:"text-sm text-muted-foreground",children:["Start a CLIProxy session with"," ",e.jsx("code",{className:"bg-muted px-1 rounded",children:"ccs gemini"})," or run"," ",e.jsx("code",{className:"bg-muted px-1 rounded",children:"ccs config"})," which auto-starts it."]})]})})]}):e.jsx("div",{className:"flex-1 flex flex-col",children:e.jsxs("div",{className:"flex-1 flex flex-col relative",children:[G&&e.jsx("div",{className:"absolute inset-0 flex items-center justify-center bg-background/80 z-10",children:e.jsxs("div",{className:"text-center",children:[e.jsx(_,{className:"w-8 h-8 animate-spin text-primary mx-auto mb-2"}),e.jsx("p",{className:"text-sm text-muted-foreground",children:i?`Loading Control Panel from ${m}...`:"Loading Control Panel..."})]})}),j?e.jsx("iframe",{ref:c,src:P,className:"flex-1 w-full border-0",title:"CLIProxy Management Panel",onLoad:H},b):null]})})}function ie(){return e.jsx("div",{className:"flex h-full min-h-0 flex-col overflow-hidden",children:e.jsx(X,{})})}export{ie as CliproxyControlPanelPage};
@@ -1,3 +0,0 @@
1
- import{j as e}from"./radix-ui-Zb8sVEtn.js";import{r as d}from"./react-vendor-CNOkPC89.js";import{a as dt,u as Kt,b as us}from"./tanstack-CrmUhA7Z.js";import{a8 as ms,d as U,C as qt,b as Ht,a9 as Gt,c as Q,P as ut,B as H,a as ce,aa as le,L as Y,I as me,r as Ye,s as Ze,t as et,v as tt,w as Ae,ab as Vt,ac as Bt,ad as ps,ae as xs,af as hs,u as zt,ag as mt,ah as pt,ai as xt,aj as ht,ak as $t,al as kt,am as fs,an as gs,W as Qt,ao as st,ap as Jt,Y as Fe,aq as vs,ar as At,as as St,at as js,au as bs,av as Ns,aw as ys,ax as ws,ay as Cs,az as ks,aA as As,aB as Pt,aC as Ss,x as Wt,n as ft,aD as gt,aE as Mt,aF as Xt,aG as Ps,m as Ms,aH as Ds,aI as Is,aJ as at,T as nt,p as it,q as rt,aK as Ts,aL as Ls,aM as Rs,aN as Dt,aO as Es,aP as Os,aQ as _s,aR as Fs,aS as Us,aT as Ks,Q as qs,R as Hs,U as It,V as Tt,aU as Gs,aV as Vs,aW as Bs,aX as zs,aY as $s,aZ as Qs,a_ as Js,a$ as Ws,b0 as Xs,b1 as Ys,b2 as Zs,b3 as ea,S as ta}from"./index-DOn6k1jF.js";import{C as ot}from"./default-ports-1QQSffYX.js";import{t as G}from"./notifications-B2HqRBj7.js";import{C as Yt,L as ne,p as ve,$ as sa,m as je,o as Zt,aF as vt,R as jt,q as Se,aa as Pe,T as qe,a7 as Lt,aG as es,aE as aa,z as bt,Z as Me,_ as ts,i as na,u as ss,aH as ia,at as ra,X as Nt,a9 as as,J as ns,D as is,aI as oa,as as rs,aJ as la,aw as ca,aK as os}from"./icons-KVCk4_U8.js";import{R as Ue,A as Rt,D as Qe,i as da,a as ua}from"./antigravity-responsibility-constants-Bvh4Ybz0.js";import{C as Ke}from"./checkbox-Dzwkj_Pg.js";import{C as ma}from"./confirm-dialog-BlSaX2gK.js";import{S as yt}from"./separator-BCfZ54mZ.js";import{S as pa}from"./searchable-select-1zOULoec.js";import{P as xa}from"./proxy-status-widget-BOrsn86w.js";import"./utils-CzKF5WmX.js";import"./form-utils-Bcoyqxpq.js";import"./code-highlight-BRUf_pqB.js";import"./alert-dialog-QyEXocpn.js";const X="gemini-3.1-pro-high",ye="gemini-3.1-pro-low",ha=Object.freeze({"gemini-3-pro-high":X,"gemini-3.1-pro-high":X,"gemini-3-pro-low":ye,"gemini-3.1-pro-low":ye,"gemini-3-pro-preview":X,"gemini-3-pro-preview-customtools":X,"gemini-3.1-pro-preview":X,"gemini-3.1-pro-preview-customtools":X,"gemini-3-1-pro-preview":X,"gemini-3-1-pro-preview-customtools":X}),ls=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,ga=["agy/","gcli/"];function z(t){return ms(t).toLowerCase()}function va(t){const s=t.trim(),a=s.toLowerCase();for(const n of ga)if(a.startsWith(n))return s.slice(n.length);return s}function ja(t){return t.replace(/-customtools$/i,"")}function ba(t){return ha[z(t)]}function He(t){const s=z(t),a=s.match(fa);if(!a)return null;const[,n,i,c]=a;return{normalizedId:s,version:n.split(/[.-]/).map(o=>Number(o)),family:i,customtools:!!c,dottedVersion:n.includes(".")}}function cs(t,s){const a=Math.max(t.length,s.length);for(let n=0;n<a;n+=1){const i=t[n]??0,c=s[n]??0;if(i!==c)return i>c?1:-1}return 0}function Na(t,s,a){if(t.customtools!==s.customtools)return t.customtools?1:-1;const n=cs(t.version,s.version);if(n!==0)return n>0?-1:1;const i=+(t.dottedVersion===a.dottedVersion),c=+(s.dottedVersion===a.dottedVersion);return i!==c?c-i:t.normalizedId.localeCompare(s.normalizedId)}function Et(t,s){const a=z(s);return t.find(n=>z(n.id)===a)?.id}function ya(t,s){const a=He(t);return!a||s.length===0?void 0:s.map(i=>{const c=He(i.id);return!c||c.family!==a.family?null:{id:i.id,info:c}}).filter(i=>!!i).sort((i,c)=>Na(i.info,c.info,a))[0]?.id}const pe={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:X,name:"Gemini Pro High",description:"Current Antigravity Gemini Pro route with higher reasoning budget",extendedContext:!0,presetMapping:{default:X,opus:X,sonnet:X,haiku:"gemini-3-1-flash-preview"}},{id:ye,name:"Gemini Pro Low",description:"Current Antigravity Gemini Pro route with the lighter quota tier",extendedContext:!0,presetMapping:{default:ye,opus:ye,sonnet:ye,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:X,sonnet:X,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-codex",models:[{id:"gpt-5-codex",name:"GPT-5 Codex",description:"Cross-plan safe Codex default",presetMapping:{default:"gpt-5-codex",opus:"gpt-5-codex",sonnet:"gpt-5-codex",haiku:"gpt-5-codex-mini"}},{id:"gpt-5-codex-mini",name:"GPT-5 Codex Mini",description:"Faster and cheaper Codex option",presetMapping:{default:"gpt-5-codex-mini",opus:"gpt-5-codex",sonnet:"gpt-5-codex",haiku:"gpt-5-codex-mini"}},{id:"gpt-5-mini",name:"GPT-5 Mini",description:"Legacy mini model ID kept for backwards compatibility",presetMapping:{default:"gpt-5-mini",opus:"gpt-5-codex",sonnet:"gpt-5-mini",haiku:"gpt-5-mini"}},{id:"gpt-5.1-codex-mini",name:"GPT-5.1 Codex Mini",description:"Legacy fast Codex mini model",presetMapping:{default:"gpt-5.1-codex-mini",opus:"gpt-5.1-codex-max",sonnet:"gpt-5.1-codex-max",haiku:"gpt-5.1-codex-mini"}},{id:"gpt-5.1-codex-max",name:"GPT-5.1 Codex Max",description:"Higher-effort Codex model with xhigh support",presetMapping:{default:"gpt-5.1-codex-max",opus:"gpt-5.1-codex-max",sonnet:"gpt-5.1-codex-max",haiku:"gpt-5.1-codex-mini"}},{id:"gpt-5.2-codex",name:"GPT-5.2 Codex",description:"Cross-plan Codex model with xhigh support",presetMapping:{default:"gpt-5.2-codex",opus:"gpt-5.2-codex",sonnet:"gpt-5.2-codex",haiku:"gpt-5-codex-mini"}},{id:"gpt-5.3-codex",name:"GPT-5.3 Codex",tier:"paid",description:"Paid Codex plans only",presetMapping:{default:"gpt-5.3-codex",opus:"gpt-5.3-codex",sonnet:"gpt-5.3-codex",haiku:"gpt-5-codex-mini"}},{id:"gpt-5.3-codex-spark",name:"GPT-5.3 Codex Spark",tier:"paid",description:"Paid Codex plans only, ultra-fast coding model",presetMapping:{default:"gpt-5.3-codex-spark",opus:"gpt-5.3-codex",sonnet:"gpt-5.3-codex",haiku:"gpt-5-codex-mini"}},{id:"gpt-5.4",name:"GPT-5.4",tier:"paid",description:"Paid Codex plans only, latest GPT-5 family model",presetMapping:{default:"gpt-5.4",opus:"gpt-5.4",sonnet:"gpt-5.4",haiku:"gpt-5-codex-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-6",name:"Claude Opus 4.6",description:"Latest flagship model",extendedContext:!0,presetMapping:{default:"claude-opus-4-6",opus:"claude-opus-4-6",sonnet:"claude-sonnet-4-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 Ce(t,s){if(!t)return;const a=z(s);if(t.provider==="agy"){const o=ba(a);if(o){const u=t.models.find(r=>r.id===o);if(u)return u}}const n=ls[a.toLowerCase()],i=t.models.find(o=>o.id===a||o.id===n);if(i)return i;const c=He(a);if(c)return t.models.map(o=>({model:o,info:He(o.id)})).filter(o=>!!(o.info&&o.info.family===c.family)).sort((o,u)=>cs(u.info.version,o.info.version))[0]?.model}function wa(t){if(t==="free")return"free";if(typeof t=="string"&&t.trim().length>0)return"paid"}function Ca(t,s){const a=pe[t.toLowerCase()];if(!s||s.models.length===0)return a;const n=s.models.map(u=>({id:u.id,owned_by:s.provider})),i=s.models.map(u=>{const r=Ce(a,u.id);return{...u,name:u.name||r?.name||u.id,tier:r?.tier??wa(u.tier),description:u.description??r?.description,broken:r?.broken,issueUrl:r?.issueUrl,deprecated:r?.deprecated,deprecationReason:r?.deprecationReason,extendedContext:u.extendedContext??r?.extendedContext,presetMapping:r?.presetMapping}}),c=a?.defaultModel?we(a.defaultModel,n):void 0,o=typeof c=="string"&&n.some(u=>z(u.id)===z(c));return{provider:s.provider,displayName:s.displayName||a?.displayName||t,defaultModel:o?c:s.defaultModel,models:i}}function wt(t){const s={},a=new Set([...Object.keys(pe),...Object.keys(t??{})]);for(const n of a){const i=Ca(n,t?.[n]);i&&(s[n]=i)}return s}function ds(t,s,a){const n=Ce(a,s);return n||Ce(pe[t.toLowerCase()],s)}function we(t,s=[]){const a=z(t),n=ya(a,s);if(n)return n;const i=Et(s,a);if(i)return i;const c=ls[a];return(c?Et(s,c):void 0)??a}function ka(t,s=[]){return{default:we(t.default,s),opus:we(t.opus,s),sonnet:we(t.sonnet,s),haiku:we(t.haiku,s)}}function Ct(t,s=[]){if(!t)return[];const a=pe[t.provider.toLowerCase()]??t,n=new Set;return a.models.map(i=>{const c=we(i.id,s),o=i.presetMapping?ka(i.presetMapping,s):void 0,u=t.models.find(r=>z(r.id)===z(c));return{...i,id:c,name:u?.name||i.name,description:u?.description??i.description,presetMapping:o}}).filter(i=>n.has(i.id)?!1:(n.add(i.id),!0))}function Aa(t,s,a=[]){const n=t.trim().toLowerCase();if(!s||!n)return[];const i=pe[n]??s,c=Ct(s,a),o=new Set(c.map(x=>z(x.id))),u=new Set(c.map(x=>Ce(i,x.id)?.id).filter(x=>!!x).map(x=>z(x))),r=new Set,p=new Set(a.map(x=>z(x.id)));return a.filter(x=>{const v=z(x.id),j=va(x.id),m=ja(j),R=Ce(i,j)??Ce(i,m);if(o.has(z(j))||v!==z(j)&&p.has(z(j)))return!1;const k=z(m);if(k!==z(j)&&p.has(k))return!1;const b=R?z(R.id):k;return R&&u.has(b)||r.has(b)||!R&&n==="agy"?!1:(r.add(b),!0)})}function Sa(t,s,a){return ds(t,s,a)?.extendedContext===!0}const Je="ccs-internal-managed";async function Pa(){try{const t=await fetch("/api/settings/auth/tokens/raw");return t.ok?(await t.json())?.apiKey?.value??Je:Je}catch{return Je}}async function Ma(t,s){if(s)return s;try{const a=await fetch("/api/cliproxy/catalog");if(!a.ok)return pe[t];const n=await a.json();return wt(n.catalogs)[t]??pe[t]}catch{return pe[t]}}async function lt(t,s,a){const n=await Ma(t,a);if(!n)return{success:!1};const i=n.models.find(p=>p.id===n.defaultModel)||n.models[0],c=i?.presetMapping||{default:n.defaultModel,opus:n.defaultModel,sonnet:n.defaultModel,haiku:n.defaultModel},o=await Pa(),r={env:{ANTHROPIC_BASE_URL:`http://127.0.0.1:${ot}/api/provider/${t}`,ANTHROPIC_AUTH_TOKEN:o,ANTHROPIC_MODEL:c.default,ANTHROPIC_DEFAULT_OPUS_MODEL:c.opus,ANTHROPIC_DEFAULT_SONNET_MODEL:c.sonnet,ANTHROPIC_DEFAULT_HAIKU_MODEL:c.haiku}};try{return{success:(await fetch(`/api/settings/${t}`,{method:"PUT",headers:{"Content-Type":"application/json"},body:JSON.stringify({settings:r})})).ok,presetName:i?.name||n.defaultModel}}catch{return{success:!1}}}function Da({currentProgress:t,allSteps:s}){return e.jsx("div",{className:"flex justify-center gap-1 pt-2",children:s.map((a,n)=>e.jsx("div",{className:`w-2 h-2 rounded-full transition-colors ${t>=n?"bg-primary":"bg-muted"}`},a))})}function Ia({providers:t,onSelect:s}){return e.jsx("div",{className:"grid gap-2",children:t.map(a=>e.jsxs("button",{onClick:()=>s(a.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:a.name}),e.jsx("div",{className:"text-xs text-muted-foreground",children:a.description})]}),e.jsx(Yt,{className:"w-4 h-4 text-muted-foreground"})]},a.id))})}function Ta({selectedProvider:t,providers:s,authCommand:a,isRefreshing:n,isPending:i,onBack:c,onStartAuth:o,onRefresh:u}){const[r,p]=d.useState(!1),x=async v=>{await navigator.clipboard.writeText(v),p(!0),setTimeout(()=>p(!1),2e3)};return e.jsxs("div",{className:"space-y-4",children:[e.jsxs("div",{className:"text-center space-y-3",children:[e.jsxs("p",{className:"text-sm text-muted-foreground",children:["Authenticate with ",s.find(v=>v.id===t)?.name," to add an account"]}),e.jsx(U,{onClick:o,disabled:i,className:"w-full gap-2",size:"lg",children:i?e.jsxs(e.Fragment,{children:[e.jsx(ne,{className:"w-4 h-4 animate-spin"}),"Authenticating..."]}):e.jsxs(e.Fragment,{children:[e.jsx(ve,{className:"w-4 h-4"}),"Authenticate in Browser"]})}),i&&e.jsx("p",{className:"text-xs text-muted-foreground",children:"Complete the OAuth flow in your browser..."})]}),e.jsxs("div",{className:"relative",children:[e.jsx("div",{className:"absolute inset-0 flex items-center",children:e.jsx("span",{className:"w-full border-t"})}),e.jsx("div",{className:"relative flex justify-center text-xs uppercase",children:e.jsx("span",{className:"bg-background px-2 text-muted-foreground",children:"Or use terminal"})})]}),e.jsx(qt,{children:e.jsxs(Ht,{className:"p-4 space-y-3",children:[e.jsxs("div",{className:"flex items-center gap-2 text-sm text-muted-foreground",children:[e.jsx(sa,{className:"w-4 h-4"}),"Run this command in your terminal:"]}),e.jsxs("div",{className:"flex items-center gap-2",children:[e.jsx("code",{className:"flex-1 px-3 py-2 bg-muted rounded-md font-mono text-sm",children:a}),e.jsx(U,{variant:"outline",size:"icon",onClick:()=>x(a),children:r?e.jsx(je,{className:"w-4 h-4 text-green-500"}):e.jsx(Zt,{className:"w-4 h-4"})})]})]})}),e.jsxs("div",{className:"flex items-center justify-between",children:[e.jsxs(U,{variant:"ghost",onClick:c,disabled:i,children:[e.jsx(vt,{className:"w-4 h-4 mr-2"}),"Back"]}),e.jsxs(U,{variant:"outline",onClick:u,disabled:n||i,children:[e.jsx(jt,{className:`w-4 h-4 mr-2 ${n?"animate-spin":""}`}),n?"Checking...":"Refresh Status"]})]})]})}function La({accounts:t,privacyMode:s,onSelect:a,onAddNew:n,onBack:i}){return e.jsxs("div",{className:"space-y-4",children:[e.jsxs("div",{className:"text-xs font-medium text-muted-foreground uppercase tracking-wide",children:["Select an account (",t.length,")"]}),e.jsx("div",{className:"grid gap-2 max-h-[320px] overflow-y-auto pr-1",children:t.map(c=>{const o=Gt(c.id,c.email,c.tokenFile);return e.jsxs("button",{type:"button",onClick:()=>a(c),className:"flex items-center justify-between p-3 border rounded-lg hover:bg-muted/50 transition-colors text-left",children:[e.jsxs("div",{className:"flex items-center gap-3",children:[e.jsx("div",{className:"w-8 h-8 rounded-full bg-muted flex items-center justify-center",children:e.jsx(Se,{className:"w-4 h-4 text-muted-foreground"})}),e.jsxs("div",{className:"space-y-1",children:[e.jsx("div",{className:Q("font-medium",s&&ut),children:o.email}),e.jsxs("div",{className:"flex items-center gap-1.5 flex-wrap",children:[o.audienceLabel&&e.jsx(H,{variant:"outline",className:Q("text-[10px] h-4 px-1.5 border-transparent",o.audience==="business"?"bg-sky-500/12 text-sky-700 dark:text-sky-300":"bg-emerald-500/12 text-emerald-700 dark:text-emerald-300"),children:o.audienceLabel}),o.detailLabel&&e.jsx(H,{variant:"outline",className:"text-[10px] h-4 px-1.5",children:o.detailLabel}),c.isDefault&&e.jsx("span",{className:"text-xs text-muted-foreground",children:"Default account"})]})]})]}),e.jsx(Yt,{className:"w-4 h-4 text-muted-foreground"})]},c.id)})}),e.jsxs("div",{className:"relative",children:[e.jsx("div",{className:"absolute inset-0 flex items-center",children:e.jsx("span",{className:"w-full border-t"})}),e.jsx("div",{className:"relative flex justify-center text-xs uppercase",children:e.jsx("span",{className:"bg-background px-2 text-muted-foreground",children:"Or"})})]}),e.jsxs("button",{type:"button",className:"w-full flex items-center gap-3 p-3 border-2 border-dashed border-primary/50 rounded-lg hover:border-primary hover:bg-primary/5 transition-colors text-left",onClick:n,children:[e.jsx("div",{className:"w-8 h-8 rounded-full bg-primary/10 flex items-center justify-center shrink-0",children:e.jsx(ve,{className:"w-4 h-4 text-primary"})}),e.jsxs("div",{children:[e.jsx("div",{className:"font-medium text-primary",children:"Add new account"}),e.jsx("div",{className:"text-xs text-muted-foreground",children:"Authenticate with a different account"})]})]}),e.jsx("div",{className:"flex items-center justify-between pt-2",children:e.jsxs(U,{variant:"ghost",onClick:i,children:[e.jsx(vt,{className:"w-4 h-4 mr-2"}),"Back"]})})]})}const Ot="__custom__";function Ra({selectedProvider:t,catalog:s,selectedAccount:a,variantName:n,modelName:i,isPending:c,privacyMode:o,onVariantNameChange:u,onModelChange:r,onBack:p,onSkip:x,onCreate:v}){const{t:j}=ce(),m=s||pe[t],R=m?.models||[],k=i&&!R.some(l=>l.id===i),[b,D]=d.useState(k),S=t==="agy"&&i.trim().length>0?le(i):!1,f=a?Gt(a.id,a.email,a.tokenFile):null,C=l=>{l===Ot?(D(!0),r("")):(D(!1),r(l))};return e.jsxs("div",{className:"space-y-4",children:[a&&e.jsxs("div",{className:"flex items-start gap-2 p-2 bg-muted/50 rounded-md text-sm",children:[e.jsx(Se,{className:"w-4 h-4"}),e.jsxs("div",{className:"space-y-1",children:[e.jsxs("span",{children:[j("setupVariant.using")," ",e.jsx("span",{className:Q(o&&ut),children:f?.email})]}),(f?.audienceLabel||f?.detailLabel)&&e.jsxs("div",{className:"flex items-center gap-1.5 flex-wrap",children:[f?.audienceLabel&&e.jsx(H,{variant:"outline",className:Q("text-[10px] h-4 px-1.5 border-transparent",f.audience==="business"?"bg-sky-500/12 text-sky-700 dark:text-sky-300":"bg-emerald-500/12 text-emerald-700 dark:text-emerald-300"),children:f.audienceLabel}),f?.detailLabel&&e.jsx(H,{variant:"outline",className:"text-[10px] h-4 px-1.5",children:f.detailLabel})]})]})]}),e.jsxs("div",{className:"space-y-2",children:[e.jsx(Y,{htmlFor:"variant-name",children:j("setupVariant.variantNameRequired")}),e.jsx(me,{id:"variant-name",value:n,onChange:l=>u(l.target.value),placeholder:j("setupVariant.variantNamePlaceholder")}),e.jsxs("div",{className:"text-xs text-muted-foreground",children:[j("setupVariant.invokeHintPrefix")," ccs ",n||"<name>",' "prompt"']})]}),e.jsxs("div",{className:"space-y-2",children:[e.jsx(Y,{children:j("setupVariant.model")}),b?e.jsxs("div",{className:"space-y-2",children:[e.jsx(me,{value:i,onChange:l=>r(l.target.value),placeholder:j("setupVariant.modelPlaceholder")}),S&&e.jsx("p",{className:"text-xs text-destructive",children:"Antigravity denylist: Claude Opus 4.5 and Claude Sonnet 4.5 are deprecated."}),e.jsx("button",{type:"button",className:"text-xs text-primary hover:underline",onClick:()=>{D(!1),t==="agy"&&le(i)&&r("")},children:j("setupVariant.choosePresetInstead")})]}):e.jsxs(Ye,{value:R.some(l=>l.id===i)?i:"",onValueChange:C,children:[e.jsx(Ze,{children:e.jsx(et,{placeholder:j("setupVariant.selectModel")})}),e.jsxs(tt,{children:[R.map(l=>e.jsx(Ae,{value:l.id,children:e.jsxs("div",{className:"flex items-center gap-2",children:[e.jsx("span",{children:l.name}),l.description&&e.jsxs("span",{className:"text-xs text-muted-foreground",children:["- ",l.description]})]})},l.id)),e.jsx(Ae,{value:Ot,children:e.jsx("span",{className:"text-primary",children:j("setupVariant.customModelName")})})]})]}),e.jsx("div",{className:"text-xs text-muted-foreground",children:b?j("setupVariant.enterAnyModel"):j("setupVariant.defaultModel",{model:m?.defaultModel||j("setupVariant.providerDefault")})})]}),e.jsxs("div",{className:"flex items-center justify-between pt-2",children:[e.jsxs(U,{variant:"ghost",onClick:p,children:[e.jsx(vt,{className:"w-4 h-4 mr-2"}),j("setupVariant.back")]}),e.jsxs("div",{className:"flex items-center gap-2",children:[e.jsx(U,{variant:"ghost",onClick:x,children:j("setupVariant.skip")}),e.jsx(U,{onClick:v,disabled:!n||c||S,children:j(c?"setupVariant.creating":"setupVariant.createVariant")})]})]}),e.jsx("p",{className:"text-xs text-center text-muted-foreground",children:j("setupVariant.skipHint")})]})}function Ea({variantName:t,onClose:s}){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(je,{className:"w-8 h-8 text-green-600 dark:text-green-400"})})}),e.jsxs("div",{children:[e.jsx("div",{className:"font-semibold text-lg",children:"Variant Created!"}),e.jsx("div",{className:"text-sm text-muted-foreground",children:"Your custom variant is ready to use"})]}),e.jsx(qt,{children:e.jsxs(Ht,{className:"p-4 space-y-2",children:[e.jsx("div",{className:"text-sm text-muted-foreground",children:"Usage:"}),e.jsxs("code",{className:"block px-3 py-2 bg-muted rounded-md font-mono text-sm",children:["ccs ",t,' "your prompt here"']})]})}),e.jsx(U,{onClick:s,className:"w-full",children:"Done"})]})}function Oa({open:t,onClose:s}){const[a,n]=d.useState("provider"),[i,c]=d.useState(""),[o,u]=d.useState(null),[r,p]=d.useState(""),[x,v]=d.useState(""),[j,m]=d.useState(!1),[R,k]=d.useState(!1),{data:b,refetch:D}=Vt(),{data:S}=Bt(),f=ps(),C=xs(),l=hs(),{privacyMode:P}=zt(),g=b?.authStatus.find(L=>L.provider===i),N=d.useMemo(()=>g?.accounts||[],[g?.accounts]),w=d.useMemo(()=>wt(S?.catalogs),[S?.catalogs]),q=!!S;d.useEffect(()=>{if(!t){const L=setTimeout(()=>{n("provider"),c(""),u(null),p(""),v(""),k(!1)},0);return()=>clearTimeout(L)}},[t]),d.useEffect(()=>{if(a==="auth"&&N.length>0&&!R){const L=setTimeout(()=>{n("account")},0);return()=>clearTimeout(L)}},[a,N,R]);const V=async()=>{m(!0),await D(),m(!1)},M=()=>{const L=(g?.accounts?.length||0)===0;C.mutate({provider:i},{onSuccess:async B=>{if(L){const $=await lt(i,void 0,q?w[i]:void 0);$.success&&$.presetName?G.success(`Applied "${$.presetName}" preset`):$.success||G.warning(Qt.t("commonToast.accountAddedPresetFailed"))}B.account&&(u(B.account),n("variant")),D()}})},E=L=>{c(L),(b?.authStatus.find(Z=>Z.provider===L)?.accounts||[]).length===0?n("auth"):n("account")},y=L=>{u(L),n("variant")},K=async()=>{if(!(!r||!i))try{await f.mutateAsync({name:r,provider:i,model:x||void 0,account:o?.id}),n("success")}catch(L){console.error("Failed to create variant:",L)}},O=`ccs ${i} --auth --add`,A=gs(a),I=L=>{if(!L&&(C.isPending&&i&&l.mutate(i),a==="success"||a==="provider")){s();return}};return e.jsx(mt,{open:t,onOpenChange:I,children:e.jsxs(pt,{className:"sm:max-w-lg",onPointerDownOutside:L=>{a!=="success"&&a!=="provider"&&L.preventDefault()},onEscapeKeyDown:L=>{(C.isPending||f.isPending)&&L.preventDefault()},children:[e.jsxs(xt,{children:[e.jsxs(ht,{className:"flex items-center gap-2",children:[e.jsx(Pe,{className:"w-5 h-5 text-primary"}),"Quick Setup Wizard"]}),e.jsxs($t,{children:[a==="provider"&&"Select a provider to get started",a==="auth"&&"Authenticate with your provider",a==="account"&&"Select which account to use",a==="variant"&&"Create your custom variant",a==="success"&&"Setup complete!"]})]}),e.jsxs("div",{className:"space-y-4 py-4",children:[a==="provider"&&e.jsx(Ia,{providers:kt,onSelect:E}),a==="auth"&&e.jsx(Ta,{selectedProvider:i,providers:kt,authCommand:O,isRefreshing:j,isPending:C.isPending,onBack:()=>n("provider"),onStartAuth:M,onRefresh:V}),a==="account"&&e.jsx(La,{accounts:N,privacyMode:P,onSelect:y,onAddNew:()=>{k(!0),n("auth")},onBack:()=>n("provider")}),a==="variant"&&e.jsx(Ra,{selectedProvider:i,catalog:w[i],selectedAccount:o,variantName:r,modelName:x,isPending:f.isPending,privacyMode:P,onVariantNameChange:p,onModelChange:v,onBack:()=>N.length>0?n("account"):n("provider"),onSkip:s,onCreate:K}),a==="success"&&e.jsx(Ea,{variantName:r,onClose:s})]}),e.jsx(Da,{currentProgress:A,allSteps:fs})]})})}const _a=3e3,Fa=300*1e3,Ua=3;function We(t){t.invalidateQueries({queryKey:["cliproxy-catalog"]}),t.invalidateQueries({queryKey:["cliproxy-models"]})}async function Xe(t){const s=await t.text();if(!s)return{};try{return JSON.parse(s)}catch{const a=t.status>=400?`Request failed with status ${t.status}`:void 0;return a?{error:a}:{}}}const xe={provider:null,isAuthenticating:!1,error:null,authUrl:null,oauthState:null,isSubmittingCallback:!1,isDeviceCodeFlow:!1};function Ka(){const[t,s]=d.useState(xe),a=d.useRef(xe),n=d.useRef(0),i=d.useRef(null),c=d.useRef(null),o=d.useRef(0),u=d.useRef(0),r=d.useRef(!1),p=dt(),x=d.useCallback(b=>b===n.current,[]),v=d.useCallback(()=>{c.current&&(clearInterval(c.current),c.current=null),u.current=0},[]);d.useEffect(()=>()=>{i.current?.abort(),v(),r.current=!1},[v]),d.useEffect(()=>{a.current=t},[t]);const j=d.useCallback(async(b,D,S)=>{if(x(S)){if(Date.now()-o.current>Fa){v(),x(S)&&s(f=>({...f,isAuthenticating:!1,error:"Authentication timed out. Please try again."}));return}try{const f=await fetch(`/api/cliproxy/auth/${b}/status?state=${encodeURIComponent(D)}`);if(!x(S))return;const C=await f.json();if(u.current=0,C.status==="ok"){if(!(typeof C.account=="object"&&C.account!==null)){v();const P="Authenticated account could not be registered";G.error(P),s(g=>({...g,isAuthenticating:!1,error:P}));return}v(),p.invalidateQueries({queryKey:["cliproxy-auth"]}),p.invalidateQueries({queryKey:["cliproxy-accounts"]}),p.invalidateQueries({queryKey:["account-quota"]}),We(p),G.success(`${b} authentication successful`),r.current=!1,s(xe)}else if(C.status==="auth_url"){const l=C.url||C.auth_url;l&&(s(P=>({...P,authUrl:l})),r.current||(r.current=!0,window.open(l,"_blank")))}else if(C.status==="device_code"){v();const l=C.user_code&&C.verification_url?`Open ${C.verification_url} and enter code: ${C.user_code}`:"Switch to Device Code method and try again.";G.error("Provider returned Device Code flow in callback mode"),s(P=>({...P,isAuthenticating:!1,error:l}))}else if(C.status==="error"){v();const l=C.error||"Authentication failed";G.error(l),s(P=>({...P,isAuthenticating:!1,error:l}))}}catch(f){if(!x(S)||(u.current+=1,u.current<Ua))return;v();const C=f instanceof Error&&f.message.trim().length>0?f.message:"Lost contact with the auth status endpoint";G.error(C),s(l=>({...l,isAuthenticating:!1,error:C}))}}},[x,p,v]),m=d.useCallback(async(b,D)=>{if(!st(b)){s({...xe,error:`Unknown provider: ${b}`});return}i.current?.abort(),v(),r.current=!1,u.current=0;const S=new AbortController,f=n.current+1;n.current=f,i.current=S;const l=(D?.flowType||(Jt(b)?"device_code":"authorization_code"))==="device_code",P=D?.startEndpoint||(l?"start":"start-url"),g={nickname:D?.nickname,kiroMethod:D?.kiroMethod,kiroIDCStartUrl:D?.kiroIDCStartUrl,kiroIDCRegion:D?.kiroIDCRegion,kiroIDCFlow:D?.kiroIDCFlow,riskAcknowledgement:D?.riskAcknowledgement};s({provider:b,isAuthenticating:!0,error:null,authUrl:null,oauthState:null,isSubmittingCallback:!1,isDeviceCodeFlow:l});try{if(P==="start")fetch(`/api/cliproxy/auth/${b}/start`,{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify(g),signal:S.signal}).then(async N=>{if(!x(f))return;const w=await Xe(N);if(!x(f))return;const q=w.success===!0,V=typeof w.account=="object"&&w.account!==null;if(N.ok&&q&&V)p.invalidateQueries({queryKey:["cliproxy-auth"]}),p.invalidateQueries({queryKey:["cliproxy-accounts"]}),p.invalidateQueries({queryKey:["account-quota"]}),We(p),r.current=!1,s(xe);else{const M=typeof w.error=="string"?w.error:q?"Authenticated account could not be registered":"Authentication failed";G.error(M),s(E=>({...E,isAuthenticating:!1,error:M}))}}).catch(N=>{if(!x(f)||N instanceof Error&&N.name==="AbortError")return;const w=N instanceof Error?N.message:"Authentication failed";G.error(w),s(q=>({...q,isAuthenticating:!1,error:w}))});else{const N=await fetch(`/api/cliproxy/auth/${b}/start-url`,{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify(g),signal:S.signal});if(!x(f))return;const w=await Xe(N);if(!x(f))return;const q=w.success===!0;if(!N.ok||!q){const E=typeof w.error=="string"?w.error:"Failed to start OAuth";throw new Error(E)}const V=typeof w.authUrl=="string"?w.authUrl:null,M=typeof w.state=="string"?w.state:null;if(s(E=>({...E,authUrl:V,oauthState:M})),V&&(r.current=!0,window.open(V,"_blank")),M){if(o.current=Date.now(),!V){if(await j(b,M,f),!x(f))return;const E=a.current;if(!E.isAuthenticating||E.provider!==b)return}c.current=setInterval(()=>{j(b,M,f)},_a)}}}catch(N){if(!x(f))return;if(N instanceof Error&&N.name==="AbortError"){r.current=!1,s(xe);return}const w=N instanceof Error?N.message:"Authentication failed";G.error(w),s(q=>({...q,isAuthenticating:!1,error:w}))}},[x,j,v,p]),R=d.useCallback(()=>{const b=t.provider;n.current+=1,i.current?.abort(),v(),r.current=!1,s(xe),b&&Fe.cliproxy.auth.cancel(b).catch(()=>{})},[t.provider,v]),k=d.useCallback(async b=>{if(!t.provider)return;const D=n.current,S=t.provider;s(f=>({...f,isSubmittingCallback:!0,error:null}));try{const f=await fetch(`/api/cliproxy/auth/${S}/submit-callback`,{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify({redirectUrl:b})});if(!x(D))return;const C=await Xe(f);if(!x(D))return;const l=C.success===!0,P=C.status==="wait",g=typeof C.account=="object"&&C.account!==null;if(f.ok&&P)s(N=>({...N,isSubmittingCallback:!1,error:null}));else if(f.ok&&l&&g)v(),p.invalidateQueries({queryKey:["cliproxy-auth"]}),p.invalidateQueries({queryKey:["cliproxy-accounts"]}),p.invalidateQueries({queryKey:["account-quota"]}),We(p),G.success(`${S} authentication successful`),s(xe);else{const N=typeof C.error=="string"?C.error:l?"Authenticated account could not be registered":"Callback submission failed";throw new Error(N)}}catch(f){if(!x(D))return;const C=f instanceof Error?f.message:"Failed to submit callback";G.error(C),s(l=>({...l,isSubmittingCallback:!1,error:C}))}},[x,t.provider,p,v]);return d.useMemo(()=>({...t,startAuth:m,cancelAuth:R,submitCallback:k}),[t,m,R,k])}function ct({className:t,compact:s=!1,showAcknowledgement:a=!1,acknowledgementPhrase:n=Ue,acknowledgementText:i="",onAcknowledgementTextChange:c,disabled:o=!1,showProxySettingsLink:u=!1}){const{t:r}=ce(),p=r("accountSafetyWarning.title"),x=r("accountSafetyWarning.subtitle"),v=r("accountSafetyWarning.firstLine"),j=r("accountSafetyWarning.secondLine"),m="https://github.com/kaitranntt/ccs/issues/509",R=r("accountSafetyWarning.issueLabel"),k=r("accountSafetyWarning.proxySettingsLabel");return s?e.jsx("section",{role:"alert",className:Q("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(qe,{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:x})]}),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:j})]})]}),e.jsxs("div",{className:"flex flex-wrap items-center gap-2 lg:justify-end",children:[e.jsxs("a",{href:m,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:[R,e.jsx(ve,{className:"h-3 w-3"})]}),u?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(Lt,{className:"h-3 w-3"}),k]}):null,e.jsx(H,{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:Q("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(qe,{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:x})]})]}),e.jsx(H,{variant:"outline",className:"border-amber-500/40 text-amber-700 dark:text-amber-300",children:"High Risk"})]}),e.jsxs("div",{className:"space-y-2 text-sm leading-relaxed",children:[e.jsx("p",{children:v}),e.jsx("p",{className:"font-medium text-amber-900 dark:text-amber-200",children:j}),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:m,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:[R,e.jsx(ve,{className:"h-3.5 w-3.5"})]}),u&&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(Lt,{className:"h-3.5 w-3.5"}),k]}),e.jsx("span",{className:"rounded-md border border-border/70 bg-muted/60 px-2.5 py-1 text-xs text-muted-foreground",children:"Applies to CLI and dashboard auth"})]}),a&&c&&e.jsxs("div",{className:"rounded-lg border border-amber-500/25 bg-amber-500/5 p-2.5",children:[e.jsxs(Y,{htmlFor:"account-risk-ack-text",className:"text-xs leading-5",children:["Type exact phrase to continue:"," ",e.jsx("code",{className:"rounded bg-muted px-1 py-0.5 font-mono",children:n})]}),e.jsx(me,{id:"account-risk-ack-text",value:i,onChange:b=>c(b.target.value),placeholder:n,disabled:o,className:"mt-2 font-mono text-xs"})]})]})]})}function qa({className:t,value:s,onChange:a,disabled:n=!1}){const{t:i}=ce(),c=[s.reviewedIssue509,s.understandsBanRisk,s.acceptsFullResponsibility,s.typedPhrase.trim().replace(/\s+/g," ").toUpperCase()===Rt].filter(Boolean).length,o=c/4*100,u=r=>{a({...s,...r})};return e.jsxs("section",{role:"alert",className:Q("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(qe,{className:"h-4 w-4"})}),e.jsxs("div",{className:"space-y-1",children:[e.jsx("p",{className:"text-sm font-semibold leading-5",children:i("antigravityChecklist.title")}),e.jsx("p",{className:"text-xs text-muted-foreground",children:i("antigravityChecklist.subtitle")})]})]}),e.jsx(H,{variant:"outline",className:"border-rose-500/40 text-rose-700 dark:text-rose-300",children:i("antigravityChecklist.mandatory")})]}),e.jsxs("div",{className:"space-y-1.5",children:[e.jsxs("div",{className:"flex items-center justify-between text-xs text-muted-foreground",children:[e.jsx("span",{children:i("antigravityChecklist.completion")}),e.jsx("span",{children:i("antigravityChecklist.stepsCount",{current:c})})]}),e.jsx(vs,{value:o,className:"h-2"})]}),e.jsxs("div",{className:"space-y-3 rounded-lg border border-rose-500/20 bg-rose-500/5 p-3",children:[e.jsxs("div",{className:"flex items-start gap-2",children:[e.jsx(Ke,{id:"agy-step-reviewed-issue",checked:s.reviewedIssue509,onCheckedChange:r=>u({reviewedIssue509:!!r}),disabled:n}),e.jsx(Y,{htmlFor:"agy-step-reviewed-issue",className:"text-xs leading-5",children:"Step 1: I reviewed issue #509 and understand AGY OAuth can trigger account bans/suspensions."})]}),e.jsxs("div",{className:"flex items-start gap-2",children:[e.jsx(Ke,{id:"agy-step-understands-risk",checked:s.understandsBanRisk,onCheckedChange:r=>u({understandsBanRisk:!!r}),disabled:n}),e.jsx(Y,{htmlFor:"agy-step-understands-risk",className:"text-xs leading-5",children:"Step 2: I understand this OAuth action is my own decision and I accept the upstream risk."})]}),e.jsxs("div",{className:"flex items-start gap-2",children:[e.jsx(Ke,{id:"agy-step-accept-responsibility",checked:s.acceptsFullResponsibility,onCheckedChange:r=>u({acceptsFullResponsibility:!!r}),disabled:n}),e.jsx(Y,{htmlFor:"agy-step-accept-responsibility",className:"text-xs leading-5",children:"Step 3: I accept full responsibility. CCS is not liable for suspension, bans, or access loss."})]})]}),e.jsxs("div",{className:"space-y-2 rounded-lg border border-amber-500/25 bg-amber-500/5 p-3",children:[e.jsxs("div",{className:"flex items-center gap-1.5 text-xs font-medium text-amber-800 dark:text-amber-200",children:[e.jsx(es,{className:"h-3.5 w-3.5"}),"Step 4: Type exact phrase to continue"]}),e.jsx(me,{value:s.typedPhrase,onChange:r=>u({typedPhrase:r.target.value}),placeholder:Rt,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(ve,{className:"h-3.5 w-3.5"})]})})]})]})}function Ha(t){return t.trim().replace(/\s+/g," ").toUpperCase()}function Ga({open:t,onClose:s,provider:a,displayName:n,catalog:i,isFirstAccount:c=!1}){const[o,u]=d.useState(""),[r,p]=d.useState(""),[x,v]=d.useState(!1),[j,m]=d.useState(null),[R,k]=d.useState(""),[b,D]=d.useState(Qe),[S,f]=d.useState(!1),[C,l]=d.useState(!1),[P,g]=d.useState(At),[N,w]=d.useState(""),[q,V]=d.useState(""),[M,E]=d.useState(St),{t:y}=ce(),K=d.useRef(!1),O=d.useRef(0),A=d.useRef(!1),I=Ka(),L=js(),B=a==="kiro",$=a==="agy"||a==="gemini",Z=a==="gemini"&&!S,ee=a==="agy"&&!S,se=$&&C,de=da(b),te=Ha(R)===Ue,ae=Jt(a),h=bs(P),F=B&&P==="idc",ie=B&&ys(P),De=B?Ns(P,M):void 0,Ge=B?Cs(P):void 0,Ve=B?De==="device_code":ae,re=I.isAuthenticating||L.isPending,Ie=o.trim(),Te=N.trim(),ke=q.trim(),Le=j||I.error,Re=d.useCallback(async()=>{const T=await fetch("/api/settings/auth/antigravity-risk");if(!T.ok)throw new Error("Failed to load power user mode setting");return(await T.json()).antigravityAckBypass===!0},[]),be=d.useCallback(async({pendingMessage:T=null,disabledMessage:ue=null}={})=>{const $e=++O.current;l(!0),T!==null&&m(T);try{const Oe=await Re();return O.current!==$e||(f(Oe),ue?m(Oe?null:ue):T!==null&&m(null)),Oe}catch{return O.current!==$e||(f(!1),m(ue??y("addAccountDialog.powerUserLoadFailed")),A.current||(A.current=!0,G.error(y("addAccountDialog.powerUserLoadFailed")))),!1}finally{O.current===$e&&l(!1)}},[Re,y]),Ne=()=>{u(""),p(""),v(!1),m(null),k(""),D(Qe),f(!1),l(!1),g(At),w(""),V(""),E(St),O.current+=1,A.current=!1,K.current=!1,s()};d.useEffect(()=>{t&&(k(""),D(Qe),m(null))},[a,t]),d.useEffect(()=>()=>{O.current+=1},[]),d.useEffect(()=>{if(!t||!$){O.current+=1,f(!1),l(!1);return}be()},[t,a,$,be]),d.useEffect(()=>{if(!t||a!=="agy"||!I.error||!S)return;const T=I.error.toLowerCase();(T.includes("agy_risk_ack_required")||T.includes("responsibility acknowledgement")||T.includes("responsibility checklist"))&&be({pendingMessage:y("addAccountDialog.powerUserLoading"),disabledMessage:y("addAccountDialog.powerUserUnavailableRetry")})},[I.error,t,S,a,be,y]),d.useEffect(()=>{!I.isAuthenticating&&!I.error&&I.provider===null&&t&&K.current&&(K.current=!1,(async()=>{try{const ue=await lt(a,void 0,i);ue.success&&ue.presetName&&c&&G.success(`Applied "${ue.presetName}" preset`)}catch{}Ne()})())},[I.isAuthenticating,I.error,I.provider]);const Ee=()=>{I.cancelAuth(),Ne()},Be=async()=>{I.authUrl&&(await navigator.clipboard.writeText(I.authUrl),v(!0),setTimeout(()=>v(!1),2e3))},ze=()=>{r.trim()&&I.submitCallback(r.trim())},_=()=>{if(se){m(y("addAccountDialog.powerUserLoading"));return}if(ee&&!de){m("Complete all Antigravity responsibility steps before authenticating this provider.");return}if(Z&&!te){m(`Type "${Ue}" to acknowledge the account safety warning before authenticating this provider.`);return}if(m(null),F&&!Te){m("IDC Start URL is required for Kiro IAM Identity Center login.");return}K.current=!0,I.startAuth(a,{nickname:Ie||void 0,kiroMethod:B?P:void 0,kiroIDCStartUrl:F?Te:void 0,kiroIDCRegion:F&&ke?ke:void 0,kiroIDCFlow:F?M:void 0,flowType:B?De:void 0,startEndpoint:B?Ge:void 0,riskAcknowledgement:ee?{version:ua,reviewedIssue509:b.reviewedIssue509,understandsBanRisk:b.understandsBanRisk,acceptsFullResponsibility:b.acceptsFullResponsibility,typedPhrase:b.typedPhrase}:void 0})},J=()=>{K.current=!0,L.mutate(void 0,{onSuccess:async()=>{const T=await lt("kiro",void 0,i);T.success&&T.presetName&&c&&G.success(`Applied "${T.presetName}" preset`),Ne()}})},oe=T=>{T||Ee()},W=I.isAuthenticating;return e.jsx(mt,{open:t,onOpenChange:oe,children:e.jsxs(pt,{className:"sm:max-w-md",onInteractOutside:T=>{W&&T.preventDefault()},children:[e.jsxs(xt,{children:[e.jsx(ht,{children:y("addAccountDialog.title",{displayName:n})}),e.jsx($t,{children:y(B?"addAccountDialog.descKiro":Ve?"addAccountDialog.descDeviceCode":"addAccountDialog.descOauth")})]}),e.jsxs("div",{className:"space-y-4 py-4",children:[ee&&!W&&e.jsx(qa,{value:b,onChange:T=>{D(T),m(null)},disabled:re}),$&&S&&!W&&e.jsxs("div",{className:"rounded-lg border border-amber-400/35 bg-amber-50/70 p-3 text-xs text-amber-900 dark:border-amber-800/60 dark:bg-amber-950/25 dark:text-amber-100",children:[e.jsxs("div",{className:"mb-1.5 flex items-center gap-1.5 font-semibold",children:[e.jsx(es,{className:"h-3.5 w-3.5"}),y("addAccountDialog.powerUserEnabled")]}),y("addAccountDialog.powerUserSkipped")]}),Z&&!W&&e.jsx(ct,{showAcknowledgement:!0,acknowledgementPhrase:Ue,acknowledgementText:R,onAcknowledgementTextChange:T=>{k(T),m(null)},disabled:re}),B&&!W&&e.jsxs("div",{className:"space-y-2",children:[e.jsx(Y,{htmlFor:"kiro-auth-method",children:y("addAccountDialog.authMethod")}),e.jsxs(Ye,{value:P,onValueChange:T=>{g(T),m(null)},children:[e.jsx(Ze,{id:"kiro-auth-method",children:e.jsx(et,{placeholder:y("addAccountDialog.selectKiroAuthMethod")})}),e.jsx(tt,{children:ws.map(T=>e.jsx(Ae,{value:T.id,children:T.label},T.id))})]}),e.jsx("p",{className:"text-xs text-muted-foreground",children:h.description}),ie&&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."]})]}),F&&!W&&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(Y,{htmlFor:"kiro-idc-start-url",children:"IDC Start URL"}),e.jsx(me,{id:"kiro-idc-start-url",value:N,onChange:T=>{w(T.target.value),m(null)},placeholder:"https://d-xxx.awsapps.com/start",disabled:re}),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(Y,{htmlFor:"kiro-idc-region",children:"IDC Region"}),e.jsx(me,{id:"kiro-idc-region",value:q,onChange:T=>{V(T.target.value),m(null)},placeholder:"us-east-1",disabled:re}),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(Y,{htmlFor:"kiro-idc-flow",children:"IDC Flow"}),e.jsxs(Ye,{value:M,onValueChange:T=>{E(T),m(null)},children:[e.jsx(Ze,{id:"kiro-idc-flow",children:e.jsx(et,{placeholder:"Select IDC flow"})}),e.jsxs(tt,{children:[e.jsx(Ae,{value:"authcode",children:"Authorization Code"}),e.jsx(Ae,{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."})]})]}),!W&&e.jsxs("div",{className:"space-y-2",children:[e.jsx(Y,{htmlFor:"nickname",children:y("addAccountDialog.nicknameOptional")}),e.jsxs("div",{className:"flex items-center gap-2",children:[e.jsx(Se,{className:"w-4 h-4 text-muted-foreground"}),e.jsx(me,{id:"nickname",value:o,onChange:T=>{u(T.target.value),m(null)},placeholder:y("addAccountDialog.nicknamePlaceholder"),disabled:re,className:"flex-1"})]}),e.jsx("p",{className:"text-xs text-muted-foreground",children:y("addAccountDialog.nicknameOptionalHint")})]}),W&&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(ne,{className:"w-4 h-4 inline mr-2 animate-spin"}),y("addAccountDialog.waitingForAuth")]}),e.jsx("p",{className:"text-xs text-muted-foreground mt-1",children:I.isDeviceCodeFlow?y("addAccountDialog.deviceCodeHint"):ie?"Complete sign-in in your browser. If it does not return automatically, paste the final kiro:// callback URL below.":y("addAccountDialog.browserHint")})]}),I.authUrl&&!I.isDeviceCodeFlow&&e.jsxs("div",{className:"space-y-3",children:[e.jsxs("div",{className:"space-y-2",children:[e.jsx(Y,{className:"text-xs",children:y("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:I.authUrl}),e.jsxs("div",{className:"flex gap-2 mt-2",children:[e.jsx(U,{variant:"outline",size:"sm",onClick:Be,children:x?e.jsxs(e.Fragment,{children:[e.jsx(je,{className:"w-3 h-3 mr-1"}),y("addAccountDialog.copied")]}):e.jsxs(e.Fragment,{children:[e.jsx(Zt,{className:"w-3 h-3 mr-1"}),y("addAccountDialog.copy")]})}),e.jsxs(U,{variant:"outline",size:"sm",onClick:()=>{if(!I.authUrl)return;const T=window.open(I.authUrl,"_blank");(!T||T.closed||typeof T.closed>"u")&&G.warning(y("addAccountDialog.popupBlocked"),{duration:5e3})},children:[e.jsx(ve,{className:"w-3 h-3 mr-1"}),y("addAccountDialog.open")]})]})]})]}),e.jsxs("div",{className:"space-y-2",children:[e.jsx(Y,{htmlFor:"callback-url",className:"text-xs",children:ie?"Browser did not return? Paste the final kiro:// callback URL:":y("addAccountDialog.redirectPasteLabel")}),e.jsx(me,{id:"callback-url",value:r,onChange:T=>p(T.target.value),placeholder:ie?"kiro://kiro.kiroAgent/authenticate-success?code=...&state=...":y("addAccountDialog.callbackPlaceholder"),className:"font-mono text-xs"}),e.jsx(U,{variant:"secondary",size:"sm",onClick:ze,disabled:!r.trim()||I.isSubmittingCallback,children:I.isSubmittingCallback?e.jsxs(e.Fragment,{children:[e.jsx(ne,{className:"w-3 h-3 mr-1 animate-spin"}),y("addAccountDialog.submitting")]}):y("addAccountDialog.submitCallback")})]})]}),!I.authUrl&&!I.isDeviceCodeFlow&&e.jsx("p",{className:"text-xs text-center text-muted-foreground",children:ie?"Preparing the Kiro sign-in URL. If it does not open automatically, it will appear here shortly.":y("addAccountDialog.preparingUrl")})]}),Le&&e.jsx("p",{className:"text-xs text-center text-destructive",children:Le}),L.isPending&&e.jsxs("p",{className:"text-sm text-center text-muted-foreground",children:[e.jsx(ne,{className:"w-4 h-4 inline mr-2 animate-spin"}),y("addAccountDialog.importingToken")]}),e.jsxs("div",{className:"flex items-center justify-end gap-2 pt-2",children:[e.jsx(U,{variant:"ghost",onClick:Ee,children:y("addAccountDialog.cancel")}),B&&!W&&e.jsx(U,{variant:"outline",onClick:J,disabled:re,children:L.isPending?e.jsxs(e.Fragment,{children:[e.jsx(ne,{className:"w-4 h-4 mr-2 animate-spin"}),y("addAccountDialog.importing")]}):e.jsxs(e.Fragment,{children:[e.jsx(aa,{className:"w-4 h-4 mr-2"}),y("addAccountDialog.importFromIde")]})}),!W&&e.jsxs(U,{onClick:_,disabled:re||se||ee&&!de||Z&&!te,children:[e.jsx(ve,{className:"w-4 h-4 mr-2"}),y("addAccountDialog.authenticate")]})]})]})]})})}const Va=["ANTHROPIC_BASE_URL","ANTHROPIC_AUTH_TOKEN"];function Ba(t){const s=t?.env||{};return Va.filter(a=>!s[a]?.trim())}function za(t,s){const[a,n]=d.useState(null),[i,c]=d.useState(!1),o=dt(),{data:u,isLoading:r,refetch:p}=Kt({queryKey:["settings",t],queryFn:async()=>{const M=await fetch(`/api/settings/${t}/raw`);return M.ok?M.json():{profile:t,settings:{env:{}},mtime:Date.now(),path:`~/.ccs/profiles/${t}/settings.json`}}}),x=u?.settings,v=d.useMemo(()=>a!==null?a:x?JSON.stringify(x,null,2):`{
2
- "env": {}
3
- }`,[a,x]),j=d.useCallback(M=>{n(M)},[]),m=d.useMemo(()=>{try{return JSON.parse(v)}catch{return x||{env:{}}}},[v,x]),R=m?.env?.ANTHROPIC_MODEL,k=m?.env?.ANTHROPIC_DEFAULT_OPUS_MODEL,b=m?.env?.ANTHROPIC_DEFAULT_SONNET_MODEL,D=m?.env?.ANTHROPIC_DEFAULT_HAIKU_MODEL,S=d.useMemo(()=>ks(m?.env||{}),[m]),f=d.useCallback((M,E)=>As(M,E,{supportsExtendedContext:y=>Sa(t,y,s)}),[s,t]),C=d.useCallback((M,E)=>{const y={...m?.env||{},[M]:E},K=Pt(M)?f(y,S):y;delete K.CCS_EXTENDED_CONTEXT;const O={...m,env:K};n(JSON.stringify(O,null,2))},[f,m,S]),l=d.useCallback(M=>{const E=m?.env||{},y=f(E,M);delete y.CCS_EXTENDED_CONTEXT;const K={...m,env:y};n(JSON.stringify(K,null,2))},[f,m]),P=d.useCallback(M=>{const E={...m?.env||{},...M},K=Object.keys(M).some(Pt)?f(E,S):E;delete K.CCS_EXTENDED_CONTEXT;const O={...m,env:K};n(JSON.stringify(O,null,2))},[f,m,S]),g=d.useMemo(()=>{try{return JSON.parse(v),!0}catch{return!1}},[v]),N=d.useMemo(()=>a===null?!1:a!==JSON.stringify(x,null,2),[a,x]),w=d.useMemo(()=>Ba(m),[m]),q=us({mutationFn:async()=>{const M=JSON.parse(v),E=await fetch(`/api/settings/${t}`,{method:"PUT",headers:{"Content-Type":"application/json"},body:JSON.stringify({settings:M,expectedMtime:u?.mtime})});if(E.status===409)throw new Error("CONFLICT");if(!E.ok)throw new Error("Failed to save");return E.json()},onSuccess:M=>{o.invalidateQueries({queryKey:["settings",t]}),n(null),M?.warning?G.success("Settings saved",{description:M.warning}):G.success("Settings saved")},onError:M=>{M.message==="CONFLICT"?c(!0):G.error(M.message)}}),V=async M=>{c(!1),M?(await p(),q.mutate()):n(null)};return{data:u,isLoading:r,refetch:p,rawJsonContent:v,rawJsonEdits:a,isRawJsonValid:g,hasChanges:N,currentSettings:m,currentModel:R,opusModel:k,sonnetModel:b,haikuModel:D,extendedContextEnabled:S,toggleExtendedContext:l,handleRawJsonChange:j,updateEnvValue:C,updateEnvValues:P,saveMutation:{mutate:()=>q.mutate(),isPending:q.isPending},conflictDialog:i,setConflictDialog:c,handleConflictResolve:V,missingRequiredFields:w}}const $a=/-(medium|high|xhigh)$/i;function Qa(t){if(!t)return;const s=t.trim().match($a);if(s?.[1])return s[1].toLowerCase()}function Ja(t){if(!t)return null;const s=Qa(t);return s?{label:`Pinned ${s}`,explicit:!0}:{label:"Auto effort",explicit:!1}}function Wa({label:t}){return e.jsx(H,{variant:"outline",className:"text-[9px] h-4 px-1",children:t})}function _e({modelId:t}){const s=Ja(t);return s?e.jsx(H,{variant:s.explicit?"secondary":"outline",className:"text-[9px] h-4 px-1 uppercase",children:s.label}):null}function _t(t,s){if(!t)return"";if(!s?.prefix)return t;const a=`${s.prefix}/`;return t.startsWith(a)?t.slice(a.length):t}function he(t,s){return s?.recommendedModelId??t}function ge({label:t,description:s,value:a,onChange:n,catalog:i,allModels:c,routing:o,disabled:u}){const{t:r}=ce(),p=i?.provider==="codex",x=d.useMemo(()=>Ct(i,c),[c,i]),v=d.useMemo(()=>Aa(i?.provider??"",i,c),[c,i]),j=new Set(x.map(l=>l.id)),m=d.useMemo(()=>new Map((o?.models??[]).map(l=>[l.modelId.toLowerCase(),l])),[o]),R=d.useMemo(()=>new Set(x.map(l=>he(l.id,m.get(l.id.toLowerCase())))),[x,m]),k=d.useMemo(()=>m.get(_t(a,o).toLowerCase()),[o,m,a]),b=x.map(l=>({value:he(l.id,m.get(l.id.toLowerCase())),groupKey:"recommended",searchText:`${l.id} ${l.name} ${m.get(l.id.toLowerCase())?.recommendedModelId??""}`,keywords:[l.tier??"",i?.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:he(l.id,m.get(l.id.toLowerCase()))}),m.get(l.id.toLowerCase())?.pinnedAvailable?e.jsx(H,{variant:"secondary",className:"text-[9px] h-4 px-1 uppercase",children:m.get(l.id.toLowerCase())?.prefix}):null,p&&e.jsx(_e,{modelId:l.id})]}),itemContent:e.jsxs("div",{className:"flex min-w-0 items-center gap-2",children:[e.jsx("span",{className:"truncate font-mono text-xs",children:he(l.id,m.get(l.id.toLowerCase()))}),l.tier==="paid"&&e.jsx(Wa,{label:r("providerModelSelector.paid")}),m.get(l.id.toLowerCase())?.unprefixedStatus==="shadowed"?e.jsx(H,{variant:"outline",className:"text-[9px] h-4 px-1",children:"Shadowed"}):null,m.get(l.id.toLowerCase())?.unprefixedStatus==="prefix-only"?e.jsx(H,{variant:"outline",className:"text-[9px] h-4 px-1",children:"Prefix only"}):null,p&&e.jsx(_e,{modelId:l.id})]})})),D=v.filter(l=>!j.has(l.id)).filter(l=>!R.has(he(l.id,m.get(l.id.toLowerCase())))).map(l=>({value:he(l.id,m.get(l.id.toLowerCase())),groupKey:"all",searchText:`${l.id} ${m.get(l.id.toLowerCase())?.recommendedModelId??""}`,keywords:[l.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:he(l.id,m.get(l.id.toLowerCase()))}),m.get(l.id.toLowerCase())?.pinnedAvailable?e.jsx(H,{variant:"secondary",className:"text-[9px] h-4 px-1 uppercase",children:m.get(l.id.toLowerCase())?.prefix}):null,p&&e.jsx(_e,{modelId:l.id})]}),itemContent:e.jsxs("div",{className:"flex min-w-0 items-center gap-2",children:[e.jsx("span",{className:"truncate font-mono text-xs",children:he(l.id,m.get(l.id.toLowerCase()))}),m.get(l.id.toLowerCase())?.unprefixedStatus==="shadowed"?e.jsx(H,{variant:"outline",className:"text-[9px] h-4 px-1",children:"Shadowed"}):null,m.get(l.id.toLowerCase())?.unprefixedStatus==="prefix-only"?e.jsx(H,{variant:"outline",className:"text-[9px] h-4 px-1",children:"Prefix only"}):null,p&&e.jsx(_e,{modelId:l.id})]})})),S=!!a&&!b.some(l=>l.value===a)&&!D.some(l=>l.value===a),f=a?{value:a,groupKey:"current",searchText:a,triggerContent:e.jsxs("div",{className:"flex min-w-0 items-center gap-2",children:[e.jsx("span",{className:"truncate font-mono text-xs",children:a}),e.jsx(H,{variant:"outline",className:"text-[9px] h-4 px-1",children:"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:a}),e.jsx(H,{variant:"outline",className:"text-[9px] h-4 px-1",children:"Current"})]})}:null,C=b.length+D.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}),s&&e.jsx("p",{className:"text-[10px] text-muted-foreground",children:s})]}),e.jsx(pa,{value:a||void 0,onChange:n,disabled:u,placeholder:r("providerModelSelector.selectModel"),searchPlaceholder:r("searchableSelect.searchModels"),emptyText:r(C?"searchableSelect.noResults":"providerModelSelector.noModelsAvailable"),triggerClassName:"h-9",groups:[...S&&f?[{key:"current",label:e.jsx("span",{className:"text-xs text-muted-foreground",children:"Current value"})}]:[],{key:"recommended",label:e.jsx("span",{className:"text-xs text-primary",children:r("providerModelSelector.recommended")})},...D.length>0?[{key:"all",label:e.jsx("span",{className:"text-xs text-muted-foreground",children:r("providerModelSelector.allModelsCount",{count:D.length})})}]:[]],options:[...S&&f?[f]:[],...b,...D]}),k?e.jsxs("div",{className:Q("rounded-md border px-2.5 py-2 text-[11px]",k.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:[k.pinnedAvailable?"Preferred pinned model:":"Pinned route status:"," ",e.jsx("code",{children:k.pinnedAvailable?k.recommendedModelId:k.pinnedModelId})]}),e.jsx("p",{className:"mt-1 leading-5",children:k.summary})]}):null,a&&!k&&_t(a,o)!==a?e.jsxs("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:["Pinned model is not currently advertised by the proxy: ",e.jsx("code",{children:a})]}):null]})}function Ft(t,s){const a=n=>s?.models.find(c=>c.modelId.toLowerCase()===n.toLowerCase())?.recommendedModelId??n;return{default:a(t.default),opus:a(t.opus),sonnet:a(t.sonnet),haiku:a(t.haiku)}}function Xa({open:t,onClose:s,currentValues:a,onApply:n,onSave:i,isSaving:c,catalog:o,allModels:u,routing:r}){const{t:p}=ce(),[x,v]=d.useState(Ft(a,r)),[j,m]=d.useState(""),R=k=>{k?(v(Ft(a,r)),m("")):s()};return e.jsx(mt,{open:t,onOpenChange:R,children:e.jsxs(pt,{className:"sm:max-w-md",children:[e.jsx(xt,{children:e.jsxs(ht,{className:"flex items-center gap-2",children:[e.jsx(Pe,{className:"w-4 h-4"}),p("customPresetDialog.title")]})}),e.jsxs("div",{className:"space-y-4 py-4",children:[e.jsxs("div",{className:"space-y-2",children:[e.jsx(Y,{htmlFor:"preset-name",children:p("customPresetDialog.presetNameOptional")}),e.jsx(me,{id:"preset-name",value:j,onChange:k=>m(k.target.value),placeholder:p("customPresetDialog.presetNamePlaceholder"),className:"text-sm"})]}),e.jsx(yt,{}),o?.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(ge,{label:p("customPresetDialog.defaultModel"),description:p("customPresetDialog.defaultModelDesc"),value:x.default,onChange:k=>v({...x,default:k}),catalog:o,allModels:u,routing:r}),e.jsx(ge,{label:p("customPresetDialog.opusModel"),description:p("customPresetDialog.opusModelDesc"),value:x.opus,onChange:k=>v({...x,opus:k}),catalog:o,allModels:u,routing:r}),e.jsx(ge,{label:p("customPresetDialog.sonnetModel"),description:p("customPresetDialog.sonnetModelDesc"),value:x.sonnet,onChange:k=>v({...x,sonnet:k}),catalog:o,allModels:u,routing:r}),e.jsx(ge,{label:p("customPresetDialog.haikuModel"),description:p("customPresetDialog.haikuModelDesc"),value:x.haiku,onChange:k=>v({...x,haiku:k}),catalog:o,allModels:u,routing:r})]}),e.jsxs(Ss,{className:"gap-2 sm:gap-0",children:[e.jsx(U,{variant:"outline",onClick:s,children:p("customPresetDialog.cancel")}),i&&e.jsxs(U,{variant:"secondary",onClick:()=>i(x,j||void 0),disabled:c||!j.trim(),children:[c?e.jsx(ne,{className:"w-4 h-4 mr-1 animate-spin"}):e.jsx(bt,{className:"w-4 h-4 mr-1"}),p("customPresetDialog.savePreset")]}),e.jsxs(U,{onClick:()=>n(x,j||void 0),children:[e.jsx(Me,{className:"w-4 h-4 mr-1"}),p("customPresetDialog.applyPreset")]})]})]})})}function fe({label:t,command:s}){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:s}),e.jsx(Wt,{value:s,size:"icon",className:"h-6 w-6"})]})]})}function Ya({provider:t,displayName:s,defaultTarget:a,data:n,authStatus:i,supportsModelConfig:c=!1}){const o=a||"claude",u=o==="droid",r=t==="codex",p=o==="claude"?`ccs ${t}`:`ccs ${t} --target claude`,x=`${p} --config`,v=`${p} --auth --add`,j=`${p} --accounts`;return e.jsx(ft,{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(ts,{className:"w-4 h-4"}),"Provider Information"]}),e.jsxs("div",{className:"space-y-3 bg-card rounded-lg border p-4 shadow-sm",children:[e.jsxs("div",{className:"grid grid-cols-[100px_1fr] gap-2 text-sm items-center",children:[e.jsx("span",{className:"font-medium text-muted-foreground",children:"Provider"}),e.jsx("span",{className:"font-mono",children:s})]}),n&&e.jsxs(e.Fragment,{children:[e.jsxs("div",{className:"grid grid-cols-[100px_1fr] gap-2 text-sm items-center",children:[e.jsx("span",{className:"font-medium text-muted-foreground",children:"File Path"}),e.jsxs("div",{className:"flex items-center gap-2 min-w-0",children:[e.jsx("code",{className:"bg-muted px-1.5 py-0.5 rounded text-xs break-all",children:n.path}),e.jsx(Wt,{value:n.path,size:"icon",className:"h-5 w-5"})]})]}),e.jsxs("div",{className:"grid grid-cols-[100px_1fr] gap-2 text-sm items-center",children:[e.jsx("span",{className:"font-medium text-muted-foreground",children:"Last Modified"}),e.jsx("span",{className:"text-xs",children:new Date(n.mtime).toLocaleString()})]})]}),e.jsxs("div",{className:"grid grid-cols-[100px_1fr] gap-2 text-sm items-center",children:[e.jsx("span",{className:"font-medium text-muted-foreground",children:"Status"}),i.authenticated?e.jsxs(H,{variant:"outline",className:"w-fit text-green-600 border-green-200 bg-green-50",children:[e.jsx(na,{className:"w-3 h-3 mr-1"}),"Authenticated"]}):e.jsx(H,{variant:"outline",className:"w-fit text-muted-foreground",children:"Not connected"})]}),e.jsxs("div",{className:"grid grid-cols-[100px_1fr] gap-2 text-sm items-center",children:[e.jsx("span",{className:"font-medium text-muted-foreground",children:"Default Target"}),e.jsx("span",{className:"font-mono",children:o})]})]})]}),e.jsxs("div",{children:[e.jsx("h3",{className:"text-sm font-medium mb-3",children:"Quick Usage"}),e.jsxs("div",{className:"space-y-3 bg-card rounded-lg border p-4 shadow-sm",children:[e.jsx(fe,{label:"Run with prompt",command:`ccs ${t} "your prompt"`}),r&&e.jsxs(e.Fragment,{children:[e.jsx(fe,{label:"Run on native Codex (shortcut)",command:'ccsxp "your prompt"'}),e.jsx(fe,{label:"Run on native Codex (--target)",command:`ccs ${t} --target codex "your prompt"`})]}),e.jsx(fe,{label:u?"Droid alias (explicit)":"Run on Droid",command:`ccs-droid ${t} "your prompt"`}),e.jsx(fe,{label:u?"Override to Claude":"Run on Droid (--target)",command:`ccs ${t} --target ${u?"claude":"droid"} "your prompt"`}),c&&e.jsx(fe,{label:o==="claude"?"Change model":"Change model (Claude target)",command:x}),e.jsx(fe,{label:o==="claude"?"Add account":"Add account (Claude target)",command:v}),e.jsx(fe,{label:o==="claude"?"List accounts":"List accounts (Claude target)",command:j}),o!=="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 Za({displayName:t,logoProvider:s,provider:a,data:n,isLoading:i,hasChanges:c,isRawJsonValid:o,isSaving:u,isRemoteMode:r,port:p,onRefetch:x,onSave:v}){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(gt,{provider:s||a,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}),r&&e.jsxs(H,{variant:"secondary",className:"text-xs gap-1 bg-blue-100 text-blue-700 dark:bg-blue-900/30 dark:text-blue-400",children:[e.jsx(ss,{className:"w-3 h-3"}),"Remote"]}),p&&e.jsxs(H,{variant:"outline",className:"text-xs gap-1 font-mono",children:[e.jsx(ia,{className:"w-3 h-3"}),":",p]}),!r&&n?.path&&e.jsx(H,{variant:"outline",className:"text-xs",children:n.path.replace(/^.*[\\/]/,"")})]}),r?e.jsx("p",{className:"text-xs text-blue-600 dark:text-blue-400 mt-0.5",children:"Traffic auto-routed to remote server"}):n&&e.jsxs("p",{className:"text-xs text-muted-foreground mt-0.5",children:["Last modified: ",new Date(n.mtime).toLocaleString()]})]})]}),e.jsxs("div",{className:"flex items-center gap-2",children:[e.jsx(U,{variant:"ghost",size:"sm",onClick:x,disabled:i,children:e.jsx(jt,{className:`w-4 h-4 ${i?"animate-spin":""}`})}),e.jsx(U,{size:"sm",onClick:v,disabled:u||!c||!o,children:u?e.jsxs(e.Fragment,{children:[e.jsx(ne,{className:"w-4 h-4 mr-1 animate-spin"}),"Saving..."]}):e.jsxs(e.Fragment,{children:[e.jsx(ra,{className:"w-4 h-4 mr-1"}),"Save"]})})]})]})}function en({models:t,provider:s,enabled:a,onToggle:n,disabled:i,className:c}){if(t.length===0)return null;const o=t.some(p=>Mt(p.id)),u=t.some(p=>!Mt(p.id));let r="Compatible mappings stay on standard context unless you turn this on.";return o&&u?r="Gemini-compatible mappings can use 1M automatically. Claude mappings stay plain unless you turn this on.":o&&(r="Gemini-compatible mappings can use 1M by default. Turn this off to keep standard context."),e.jsxs("div",{className:Q("rounded-lg border p-3 space-y-2",a?"border-primary/50 bg-primary/5":"border-border bg-muted/30",c),children:[e.jsxs("div",{className:"flex items-center justify-between",children:[e.jsxs("div",{className:"flex items-center gap-2",children:[e.jsx(Me,{className:Q("w-4 h-4",a?"text-primary":"text-muted-foreground")}),e.jsx("span",{className:"text-sm font-medium",children:"Extended Context"}),e.jsx(H,{variant:a?"default":"secondary",className:"text-[10px] h-5 px-1.5",children:"1M tokens"})]}),e.jsx(Xt,{checked:a,onCheckedChange:n,disabled:i})]}),e.jsxs("div",{className:"flex items-start gap-2 text-xs text-muted-foreground",children:[e.jsx(ts,{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:r}),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 tn(t,s){const a=t.presetMapping||{default:t.id,opus:t.id,sonnet:t.id,haiku:t.id};return{ANTHROPIC_MODEL:s(a.default),ANTHROPIC_DEFAULT_OPUS_MODEL:s(a.opus),ANTHROPIC_DEFAULT_SONNET_MODEL:s(a.sonnet),ANTHROPIC_DEFAULT_HAIKU_MODEL:s(a.haiku)}}function sn({catalog:t,savedPresets:s,currentModel:a,opusModel:n,sonnetModel:i,haikuModel:c,providerModels:o,routing:u,provider:r,extendedContextEnabled:p,onExtendedContextToggle:x,onApplyPreset:v,onUpdateEnvValue:j,onOpenCustomPreset:m,onDeletePreset:R,isDeletePending:k}){const b=(u?.models??[]).some(g=>g.pinnedAvailable),D=d.useMemo(()=>new Map((u?.models??[]).map(g=>[g.modelId.toLowerCase(),g])),[u]),S=g=>D.get(g.toLowerCase())?.recommendedModelId??g,f=d.useMemo(()=>{if(!t)return[];const g=[a,n,i,c].filter(w=>!!w).map(w=>Ps(w));return[...new Set(g)].map(w=>ds(t.provider,w,t)).filter(w=>!!w?.extendedContext)},[t,a,n,i,c]),C=d.useMemo(()=>Ct(t,o),[t,o]),l=d.useMemo(()=>{const g=C.filter(w=>w.presetMapping);return g.length===0?[]:g.some(w=>w.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:g.filter(w=>w.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:g.filter(w=>w.tier==="paid")}].filter(w=>w.models.length>0):[{key:"default",models:g.slice(0,4)}]},[C]),P=l.length>0||s.length>0;return e.jsxs(e.Fragment,{children:[P&&e.jsxs("div",{children:[e.jsxs("h3",{className:"text-sm font-medium mb-2 flex items-center gap-2",children:[e.jsx(Pe,{className:"w-4 h-4"}),"Presets"]}),e.jsx("p",{className:"text-xs text-muted-foreground mb-3",children:"Apply pre-configured model mappings"}),e.jsxs("div",{className:"space-y-4",children:[l.map(g=>e.jsxs("div",{children:["label"in g&&g.label&&e.jsxs("div",{className:"flex items-center gap-2 mb-2",children:[e.jsx(H,{variant:"outline",className:g.badgeClassName,children:g.label}),e.jsx("span",{className:"text-[10px] text-muted-foreground",children:g.description})]}),e.jsx("div",{className:"flex flex-wrap gap-2",children:g.models.map(N=>e.jsxs(U,{variant:"outline",size:"sm",className:"text-xs h-7 gap-1",onClick:()=>v(tn(N,S)),children:[e.jsx(Me,{className:`w-3 h-3 ${"iconClassName"in g?g.iconClassName:""}`}),N.name]},N.id))})]},g.key)),e.jsxs("div",{className:"flex flex-wrap gap-2",children:[s.map(g=>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:S(g.default),ANTHROPIC_DEFAULT_OPUS_MODEL:S(g.opus),ANTHROPIC_DEFAULT_SONNET_MODEL:S(g.sonnet),ANTHROPIC_DEFAULT_HAIKU_MODEL:S(g.haiku)})},children:[e.jsx(bt,{className:"w-3 h-3 fill-current"}),g.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:N=>{N.stopPropagation(),R(g.name)},disabled:k,children:e.jsx(Nt,{className:"w-3 h-3"})})]},g.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:m,children:[e.jsx(as,{className:"w-3 h-3"}),"Custom"]})]})]})]}),e.jsx(yt,{}),e.jsxs("div",{children:[e.jsx("h3",{className:"text-sm font-medium mb-2",children:"Model Mapping"}),e.jsx("p",{className:"text-xs text-muted-foreground mb-4",children:"Configure which models to use for each tier"}),u?e.jsx("p",{className:"text-[11px] text-muted-foreground mb-3 rounded-md border bg-muted/30 px-2.5 py-2",children:b?e.jsxs(e.Fragment,{children:["Preferred pinned model names use the ",e.jsxs("code",{children:[u.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:[u.prefix,"/"]})," is not currently advertised by the proxy. Unprefixed names may still be ambiguous until prefix repair completes."]})}):null,r==="codex"&&e.jsxs("p",{className:"text-[11px] text-muted-foreground mb-3 rounded-md border bg-muted/30 px-2.5 py-2",children:["Codex tip: suffixes ",e.jsx("code",{children:"-medium"}),", ",e.jsx("code",{children:"-high"}),", and ",e.jsx("code",{children:"-xhigh"})," ","pin reasoning effort. Unsuffixed models use Thinking settings."]}),e.jsxs("div",{className:"space-y-4",children:[e.jsx(ge,{label:"Default Model",description:"Used when no specific tier is requested",value:a,onChange:g=>j("ANTHROPIC_MODEL",g),catalog:t,allModels:o,routing:u}),f.length>0&&x&&e.jsx(en,{models:f,provider:r,enabled:p??!1,onToggle:x}),e.jsx(ge,{label:"Opus (Most capable)",description:"For complex reasoning tasks",value:n,onChange:g=>j("ANTHROPIC_DEFAULT_OPUS_MODEL",g),catalog:t,allModels:o,routing:u}),e.jsx(ge,{label:"Sonnet (Balanced)",description:"Balance of speed and capability",value:i,onChange:g=>j("ANTHROPIC_DEFAULT_SONNET_MODEL",g),catalog:t,allModels:o,routing:u}),e.jsx(ge,{label:"Haiku (Fast)",description:"Quick responses for simple tasks",value:c,onChange:g=>j("ANTHROPIC_DEFAULT_HAIKU_MODEL",g),catalog:t,allModels:o,routing:u})]})]})]})}function an(t,s){return t?e.jsx(at,{children:e.jsxs(nt,{children:[e.jsx(it,{asChild:!0,children:e.jsxs("div",{className:"flex items-center gap-1.5 text-xs text-muted-foreground",children:[e.jsx(la,{className:"w-3 h-3","aria-hidden":"true"}),e.jsx("span",{className:Q("font-mono max-w-[180px] truncate",s&&ut),title:t,children:t})]})}),e.jsx(rt,{side:"bottom",children:e.jsx("p",{className:"text-xs",children:"GCP Project ID (read-only)"})})]})}):e.jsx(at,{children:e.jsxs(nt,{children:[e.jsx(it,{asChild:!0,children:e.jsxs("div",{className:"flex items-center gap-1 text-xs text-amber-600 dark:text-amber-500",children:[e.jsx(qe,{className:"w-3 h-3","aria-label":"Warning"}),e.jsx("span",{children:"Project ID: N/A"})]})}),e.jsx(rt,{side:"bottom",className:"max-w-[250px]",children:e.jsxs("div",{className:"text-xs space-y-1",children:[e.jsx("p",{className:"font-medium text-amber-600",children:"Missing Project ID"}),e.jsx("p",{children:"This may cause errors. Remove the account and re-add it to fetch the project ID."})]})})]})})}function nn({account:t,onSetDefault:s,onRemove:a,onPauseToggle:n,isRemoving:i,isPausingAccount:c,privacyMode:o,showQuota:u,selectable:r,selected:p,onSelectChange:x}){const v=t.provider.toLowerCase(),{data:j}=Ms(u),{data:m,isLoading:R}=Ds(v,t.id,u),k=Is(j,t)?.lastUsedAt,b=r||n?e.jsxs("div",{className:"flex items-center gap-2 shrink-0",children:[r&&e.jsx("button",{type:"button",onClick:()=>x?.(!p),className:Q("flex items-center justify-center w-5 h-5 rounded border-2 transition-colors shrink-0",p?"bg-primary border-primary text-primary-foreground":"border-muted-foreground/30 hover:border-primary/50"),"aria-label":p?"Deselect account":"Select account",children:p&&e.jsx(je,{className:"w-3 h-3"})}),n&&e.jsx(at,{children:e.jsxs(nt,{children:[e.jsx(it,{asChild:!0,children:e.jsx(U,{variant:"ghost",size:"icon",className:"h-7 w-7 shrink-0",onClick:()=>n(!t.paused),disabled:c,children:c?e.jsx(ne,{className:"w-4 h-4 animate-spin"}):t.paused?e.jsx(ns,{className:"w-4 h-4 text-emerald-500"}):e.jsx(is,{className:"w-4 h-4 text-muted-foreground hover:text-foreground"})})}),e.jsx(rt,{side:"top",children:t.paused?"Resume account":"Pause account"})]})})]}):void 0,D=e.jsxs(Ts,{children:[e.jsx(Ls,{asChild:!0,children:e.jsx(U,{variant:"ghost",size:"icon",className:"h-7 w-7 shrink-0",children:e.jsx(oa,{className:"w-4 h-4"})})}),e.jsxs(Rs,{align:"end",children:[!t.isDefault&&e.jsxs(Dt,{onClick:s,children:[e.jsx(bt,{className:"w-4 h-4 mr-2"}),"Set as default"]}),e.jsxs(Dt,{className:"text-destructive focus:text-destructive",onClick:a,disabled:i,children:[e.jsx(rs,{className:"w-4 h-4 mr-2"}),i?"Removing...":"Remove account"]})]})]});return e.jsx("div",{className:Q("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",p&&"ring-2 ring-primary/50 bg-primary/5"),children:e.jsx(Es,{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:o,showQuota:u,quota:m,quotaLoading:R,runtimeLastUsed:k,beforeIdentity:b,headerEnd:D,bodySlot:t.provider==="agy"?an(t.projectId,o):null,quotaInsetClassName:"pl-11"})})}function rn({selectedCount:t,onPauseSelected:s,onResumeSelected:a,onClearSelection:n,isPausing:i,isResuming:c}){if(t<1)return null;const o=i||c;return e.jsxs("div",{className:"flex items-center gap-3 p-2 bg-muted/50 rounded-lg border mt-2",children:[e.jsxs("span",{className:"text-sm text-muted-foreground",children:[t," selected"]}),e.jsx(U,{variant:"ghost",size:"sm",className:"text-xs h-6 px-2",onClick:n,disabled:o,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:s,disabled:o,children:[i?e.jsx(ne,{className:"w-3 h-3 animate-spin"}):e.jsx(is,{className:"w-3 h-3"}),"Pause Selected"]}),e.jsxs(U,{size:"sm",variant:"outline",className:"h-7 text-xs gap-1",onClick:a,disabled:o,children:[c?e.jsx(ne,{className:"w-3 h-3 animate-spin"}):e.jsx(ns,{className:"w-3 h-3"}),"Resume Selected"]})]})]})}function on({accounts:t,onAddAccount:s,onSetDefault:a,onRemoveAccount:n,onPauseToggle:i,onSoloMode:c,onBulkPause:o,onBulkResume:u,isRemovingAccount:r,isPausingAccount:p,isSoloingAccount:x,isBulkPausing:v,isBulkResuming:j,privacyMode:m,showQuota:R,isKiro:k,kiroNoIncognito:b,onKiroNoIncognitoChange:D,kiroSettingsLoading:S}){const[f,C]=d.useState(new Set),l=d.useMemo(()=>new Set(t.map(A=>A.id)),[t]),P=d.useMemo(()=>new Set([...f].filter(A=>l.has(A))),[f,l]),g=!!(o&&u),N=P.size,w=t.length>0&&P.size===t.length,q=P.size>0&&P.size<t.length,V=d.useCallback(A=>{C(I=>{const L=new Set(I);return L.has(A)?L.delete(A):L.add(A),L})},[]),M=d.useCallback(()=>{C(new Set(t.map(A=>A.id)))},[t]),E=d.useCallback(()=>{C(new Set)},[]),y=d.useCallback(()=>{w?E():M()},[w,M,E]),K=d.useCallback(()=>{o&&P.size>0&&(o(Array.from(P)),C(new Set))},[o,P]),O=d.useCallback(()=>{u&&P.size>0&&(u(Array.from(P)),C(new Set))},[u,P]);return e.jsxs("div",{children:[e.jsxs("div",{className:"flex items-center justify-between mb-3",children:[e.jsxs("h3",{className:"text-sm font-medium flex items-center gap-2",children:[g&&t.length>0&&e.jsx(Ke,{checked:w,onCheckedChange:y,"aria-label":"Select all accounts",className:q?"data-[state=checked]:bg-primary/50":"",...q?{"data-state":"indeterminate"}:{}}),e.jsx(Se,{className:"w-4 h-4"}),"Accounts",t.length>0&&e.jsx(H,{variant:"secondary",className:"text-xs",children:t.length})]}),e.jsxs(U,{variant:"default",size:"sm",className:"h-7 text-xs gap-1",onClick:s,children:[e.jsx(as,{className:"w-3 h-3"}),"Add"]})]}),g&&N>0&&e.jsx(rn,{selectedCount:N,onPauseSelected:K,onResumeSelected:O,onClearSelection:E,isPausing:!!v,isResuming:!!j}),t.length>0?e.jsx("div",{className:"space-y-2",children:t.map(A=>e.jsx(nn,{account:A,onSetDefault:()=>a(A.id),onRemove:()=>n(A.id),onPauseToggle:i?I=>i(A.id,I):void 0,onSoloMode:c?()=>c(A.id):void 0,isRemoving:r,isPausingAccount:p,isSoloingAccount:x,privacyMode:m,showQuota:R,selectable:g,selected:P.has(A.id),onSelectChange:()=>V(A.id)},A.id))}):e.jsxs("div",{className:"py-6 text-center text-muted-foreground bg-muted/30 rounded-lg border border-dashed",children:[e.jsx(Se,{className:"w-8 h-8 mx-auto mb-2 opacity-50"}),e.jsx("p",{className:"text-sm",children:"No accounts connected"}),e.jsx("p",{className:"text-xs opacity-70",children:"Add an account to get started"})]}),k&&D&&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(ss,{className:"w-3.5 h-3.5"}),e.jsx("span",{children:"Use incognito"})]}),e.jsx(Xt,{checked:!b,onCheckedChange:A=>D(!A),disabled:S,className:"scale-90"})]})})]})}function ln({provider:t,catalog:s,savedPresets:a,currentModel:n,opusModel:i,sonnetModel:c,haikuModel:o,providerModels:u,routing:r,extendedContextEnabled:p,onExtendedContextToggle:x,onApplyPreset:v,onUpdateEnvValue:j,onOpenCustomPreset:m,onDeletePreset:R,isDeletePending:k,accounts:b,onAddAccount:D,onSetDefault:S,onRemoveAccount:f,onPauseToggle:C,onSoloMode:l,onBulkPause:P,onBulkResume:g,isRemovingAccount:N,isPausingAccount:w,isSoloingAccount:q,isBulkPausing:V,isBulkResuming:M,privacyMode:E,isRemoteMode:y}){const K=t.toLowerCase(),O=(Os.includes(K)||["anthropic","antigravity","gemini-cli","copilot","github-copilot"].includes(K))&&!y,A=t==="kiro",[I,L]=d.useState(!0),[B,$]=d.useState(!0),[Z,ee]=d.useState(!1),se=d.useCallback(async()=>{if(A)try{$(!0);const ae=(await Fe.config.get()).cliproxy;L(ae?.kiro_no_incognito??!0)}catch{L(!0)}finally{$(!1)}},[A]),de=d.useCallback(async te=>{L(te),ee(!0);try{const ae=await Fe.config.get(),h=ae.cliproxy??{};await Fe.config.update({...ae,cliproxy:{...h,kiro_no_incognito:te}})}catch{L(!te)}finally{ee(!1)}},[]);return d.useEffect(()=>{se()},[se]),e.jsx(ft,{className:"flex-1",children:e.jsxs("div",{className:"p-4 space-y-6",children:[e.jsx(sn,{catalog:s,savedPresets:a,currentModel:n,opusModel:i,sonnetModel:c,haikuModel:o,providerModels:u,routing:r,provider:t,extendedContextEnabled:p,onExtendedContextToggle:x,onApplyPreset:v,onUpdateEnvValue:j,onOpenCustomPreset:m,onDeletePreset:R,isDeletePending:k}),e.jsx(yt,{}),e.jsx(on,{accounts:b,onAddAccount:D,onSetDefault:S,onRemoveAccount:f,onPauseToggle:C,onSoloMode:l,onBulkPause:P,onBulkResume:g,isRemovingAccount:N,isPausingAccount:w,isSoloingAccount:q,isBulkPausing:V,isBulkResuming:M,privacyMode:E,showQuota:O,isKiro:A,kiroNoIncognito:I,onKiroNoIncognitoChange:de,kiroSettingsLoading:B||Z})]})})}function Ut({provider:t,displayName:s,authStatus:a,catalog:n,routing:i,logoProvider:c,baseProvider:o,isRemoteMode:u,port:r,defaultTarget:p,topNotice:x,onAddAccount:v,onSetDefault:j,onRemoveAccount:m,onPauseToggle:R,onSoloMode:k,onBulkPause:b,onBulkResume:D,isRemovingAccount:S,isPausingAccount:f,isSoloingAccount:C,isBulkPausing:l,isBulkResuming:P}){const[g,N]=d.useState(!1),{privacyMode:w}=zt(),{data:q}=_s(),{data:V}=Fs(t),M=Us(),E=Ks(),y=o||t,K=y.toLowerCase()==="agy",O=d.useMemo(()=>{const _=V?.presets||[];return K?_.filter(J=>!le(J.default)&&!le(J.opus)&&!le(J.sonnet)&&!le(J.haiku)):_},[K,V?.presets]),A=d.useMemo(()=>{if(!q?.models)return[];const J={gemini:["google"],agy:["antigravity"],codex:["openai"],qwen:["alibaba","qwen"],iflow:["iflow"],kiro:["kiro","aws"],ghcp:["github","copilot"],kimi:["kimi","moonshot"]}[y.toLowerCase()]||[y.toLowerCase()];return q.models.filter(oe=>J.some(W=>oe.owned_by.toLowerCase().includes(W))?K?!le(oe.id):!0:!1)},[K,q,y]),I=(o||t).toLowerCase(),{data:L,isLoading:B,refetch:$,rawJsonContent:Z,rawJsonEdits:ee,isRawJsonValid:se,hasChanges:de,currentModel:te,opusModel:ae,sonnetModel:h,haikuModel:F,extendedContextEnabled:ie,toggleExtendedContext:De,handleRawJsonChange:Ge,updateEnvValue:Ve,updateEnvValues:re,saveMutation:Ie,conflictDialog:Te,handleConflictResolve:ke,missingRequiredFields:Le}=za(t,n),Re=d.useMemo(()=>(a.accounts||[]).map(_=>({..._,provider:_.provider||o||t})),[a.accounts,o,t]),{data:be}=Kt({queryKey:["auth-tokens-raw"],queryFn:async()=>{const _=await fetch("/api/settings/auth/tokens/raw");return _.ok?_.json():{apiKey:{value:"ccs-internal-managed"}}},staleTime:6e4}),Ne=be?.apiKey?.value??"ccs-internal-managed",Ee=_=>{if(K&&[_.ANTHROPIC_MODEL,_.ANTHROPIC_DEFAULT_OPUS_MODEL,_.ANTHROPIC_DEFAULT_SONNET_MODEL,_.ANTHROPIC_DEFAULT_HAIKU_MODEL].some(oe=>typeof oe=="string"&&le(oe))){G.error("Antigravity denylist: Claude Opus 4.5 and Claude Sonnet 4.5 are deprecated.");return}re({ANTHROPIC_BASE_URL:`http://127.0.0.1:${r??ot}/api/provider/${I}`,ANTHROPIC_AUTH_TOKEN:Ne,..._}),G.success(`Applied "${_.ANTHROPIC_MODEL?.split("/").pop()||"preset"}" preset`)},Be=(_,J)=>{if(K&&[_.default,_.opus,_.sonnet,_.haiku].some(W=>le(W))){G.error("Antigravity denylist: Claude Opus 4.5 and Claude Sonnet 4.5 are deprecated.");return}re({ANTHROPIC_BASE_URL:`http://127.0.0.1:${r??ot}/api/provider/${I}`,ANTHROPIC_AUTH_TOKEN:Ne,ANTHROPIC_MODEL:_.default,ANTHROPIC_DEFAULT_OPUS_MODEL:_.opus,ANTHROPIC_DEFAULT_SONNET_MODEL:_.sonnet,ANTHROPIC_DEFAULT_HAIKU_MODEL:_.haiku}),G.success(`Applied ${J?`"${J}"`:"custom"} preset`),N(!1)},ze=(_,J)=>{if(!J){G.error(Qt.t("commonToast.enterPresetName"));return}if(K&&[_.default,_.opus,_.sonnet,_.haiku].some(oe=>le(oe))){G.error("Antigravity denylist: Claude Opus 4.5 and Claude Sonnet 4.5 are deprecated.");return}M.mutate({profile:t,data:{name:J,..._}}),N(!1)};return e.jsxs("div",{className:"flex-1 flex flex-col overflow-hidden",children:[e.jsx(Za,{provider:t,displayName:s,logoProvider:c,data:L,isLoading:B,hasChanges:de,isRawJsonValid:se,isSaving:Ie.isPending,isRemoteMode:u,port:r,onRefetch:$,onSave:()=>Ie.mutate()}),x?e.jsx("div",{className:"border-b bg-muted/10 px-4 py-3",children:x}):null,B?e.jsxs("div",{className:"flex-1 flex items-center justify-center",children:[e.jsx(ne,{className:"w-8 h-8 animate-spin text-muted-foreground"}),e.jsx("span",{className:"ml-3 text-muted-foreground",children:"Loading settings..."})]}):e.jsxs("div",{className:"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(qs,{defaultValue:"config",className:"h-full flex flex-col",children:[e.jsx("div",{className:"px-4 pt-4 shrink-0",children:e.jsxs(Hs,{className:"w-full",children:[e.jsx(It,{value:"config",className:"flex-1",children:"Model Config"}),e.jsx(It,{value:"info",className:"flex-1",children:"Info & Usage"})]})}),e.jsxs("div",{className:"flex-1 overflow-hidden flex flex-col",children:[e.jsx(Tt,{value:"config",className:"flex-1 mt-0 border-0 p-0 data-[state=inactive]:hidden flex flex-col overflow-hidden",children:e.jsx(ln,{provider:t,catalog:n,savedPresets:O,currentModel:te,opusModel:ae,sonnetModel:h,haikuModel:F,providerModels:A,routing:i,extendedContextEnabled:ie,onExtendedContextToggle:De,onApplyPreset:Ee,onUpdateEnvValue:Ve,onOpenCustomPreset:()=>N(!0),onDeletePreset:_=>E.mutate({profile:t,name:_}),isDeletePending:E.isPending,accounts:Re,onAddAccount:v,onSetDefault:j,onRemoveAccount:m,onPauseToggle:R,onSoloMode:k,onBulkPause:b,onBulkResume:D,isRemovingAccount:S,isPausingAccount:f,isSoloingAccount:C,isBulkPausing:l,isBulkResuming:P,privacyMode:w,isRemoteMode:u})}),e.jsx(Tt,{value:"info",className:"h-full mt-0 border-0 p-0 data-[state=inactive]:hidden",children:e.jsx(Ya,{provider:t,displayName:s,defaultTarget:p,data:L,authStatus:a,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(ca,{className:"w-4 h-4 text-muted-foreground"}),e.jsx("span",{className:"text-sm font-medium text-muted-foreground",children:"Raw Configuration (JSON)"})]}),e.jsx(Gs,{rawJsonContent:Z,isRawJsonValid:se,rawJsonEdits:ee,onRawJsonChange:Ge,profileEnv:L?.settings?.env,missingRequiredFields:Le})]})]}),e.jsx(ma,{open:Te,title:"File Modified Externally",description:"This settings file was modified by another process. Overwrite with your changes or discard?",confirmText:"Overwrite",variant:"destructive",onConfirm:()=>ke(!0),onCancel:()=>ke(!1)}),e.jsx(Xa,{open:g,onClose:()=>N(!1),currentValues:{default:te||"",opus:ae||"",sonnet:h||"",haiku:F||""},onApply:Be,onSave:ze,isSaving:M.isPending,catalog:n,allModels:A,routing:i})]})}function cn({status:t,isSelected:s,onSelect:a}){const{t:n}=ce(),i=t.accounts?.length||0;return e.jsxs("button",{className:Q("w-full flex items-center gap-3 px-3 py-2.5 rounded-lg transition-colors cursor-pointer text-left",s?"bg-primary/10 border border-primary/20":"hover:bg-muted border border-transparent"),onClick:a,children:[e.jsx(gt,{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}),i>0&&e.jsx(H,{variant:"secondary",className:"text-[10px] h-4 px-1",children:i})]}),e.jsx("div",{className:"flex items-center gap-1.5 mt-0.5",children:t.authenticated?e.jsxs(e.Fragment,{children:[e.jsx(je,{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(Nt,{className:"w-3 h-3 text-muted-foreground"}),e.jsx("span",{className:"text-xs text-muted-foreground",children:n("cliproxyPage.notConnected")})]})})]})]})}function dn({variant:t,parentAuth:s,isSelected:a,onSelect:n,onDelete:i,isDeleting:c}){const{t:o}=ce(),u=()=>{n()};return e.jsxs("div",{role:"button",tabIndex:0,className:Q("group w-full flex items-center gap-3 px-3 py-2 rounded-lg transition-colors cursor-pointer text-left pl-6",a?"bg-primary/10 border border-primary/20":"hover:bg-muted border border-transparent"),onClick:u,onKeyDown:r=>{(r.key==="Enter"||r.key===" ")&&(r.preventDefault(),u())},children:[e.jsxs("div",{className:"relative",children:[e.jsx(gt,{provider:t.provider,size:"sm"}),e.jsx(os,{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(H,{variant:"outline",className:"text-[9px] h-4 px-1",children:o("cliproxyPage.variant")}),e.jsx(H,{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:s?.authenticated?e.jsxs(e.Fragment,{children:[e.jsx(je,{className:"w-3 h-3 text-green-600"}),e.jsx("span",{className:"text-xs text-muted-foreground truncate",children:o("cliproxyPage.viaProvider",{provider:t.provider})})]}):e.jsxs(e.Fragment,{children:[e.jsx(Nt,{className:"w-3 h-3 text-muted-foreground"}),e.jsx("span",{className:"text-xs text-muted-foreground",children:o("cliproxyPage.parentNotConnected")})]})})]}),e.jsx(U,{variant:"ghost",size:"icon",className:"h-6 w-6 opacity-0 group-hover:opacity-100 hover:text-destructive",onClick:r=>{r.stopPropagation(),i()},disabled:c,children:e.jsx(rs,{className:"w-3 h-3"})})]})}function un({onSetup:t}){const{t:s}=ce();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(Me,{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(U,{onClick:t,className:"gap-2",children:[e.jsx(Pe,{className:"w-4 h-4"}),s("cliproxyPage.quickSetup")]})]})})}function Mn(){const{t}=ce(),s=dt(),{data:a,isLoading:n}=Vt(),{data:i,isFetching:c}=Vs(),{data:o}=Bt(),{data:u}=Bs(),r=zs(),p=$s(),x=Qs(),v=Js(),j=Ws(),m=Xs(),R=Ys(),k=Zs(),[b,D]=d.useState(()=>{if(typeof window<"u"){const F=new URLSearchParams(window.location.search).get("provider")?.trim().toLowerCase();return F&&st(F)?F:localStorage.getItem("cliproxy-selected-provider")}return null}),[S,f]=d.useState(null),[C,l]=d.useState(!1),[P,g]=d.useState(()=>{if(typeof window>"u")return null;const h=new URLSearchParams(window.location.search),F=h.get("provider")?.trim().toLowerCase();return h.get("action")!=="auth"||!F||!st(F)?null:{provider:F,displayName:ea(F),isFirstAccount:!1}}),N=d.useMemo(()=>a?.authStatus||[],[a?.authStatus]),w=a?.source==="remote",q=d.useMemo(()=>i?.variants||[],[i?.variants]),V=d.useMemo(()=>wt(o?.catalogs),[o?.catalogs]),M=o?.routing??{},E=!!o,y=h=>{D(h),h&&localStorage.setItem("cliproxy-selected-provider",h)},K=d.useMemo(()=>S?null:b&&N.some(h=>h.provider===b)?b:N.length>0&&(N.find(F=>(F.accounts?.length||0)>0)?.provider||N[0]?.provider)||null,[b,S,N]),O=N.find(h=>h.provider===K),A=q.find(h=>h.name===S),I=A?N.find(h=>h.provider===A.provider):void 0,L=(A?.provider||O?.provider||"").toLowerCase().trim(),B=L==="gemini"||L==="agy",$=()=>{s.invalidateQueries({queryKey:["cliproxy"]}),s.invalidateQueries({queryKey:["cliproxy-auth"]}),s.invalidateQueries({queryKey:["cliproxy-catalog"]}),s.invalidateQueries({queryKey:["cliproxy-models"]})},Z=(h,F,ie)=>{x.isPending||v.isPending||(ie?x.mutate({provider:h,accountId:F}):v.mutate({provider:h,accountId:F}))},ee=(h,F)=>{j.isPending||j.mutate({provider:h,accountId:F})},se=(h,F)=>{m.isPending||m.mutate({provider:h,accountIds:F})},de=(h,F)=>{R.isPending||R.mutate({provider:h,accountIds:F})},te=h=>{y(h),f(null)},ae=h=>{f(h),y(null)};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(Me,{className:"w-5 h-5 text-primary"}),e.jsx("h1",{className:"font-semibold",children:u?.backendLabel??"CLIProxy"})]}),e.jsx(U,{variant:"ghost",size:"icon",className:"h-8 w-8",onClick:$,disabled:c,children:e.jsx(jt,{className:Q("w-4 h-4",c&&"animate-spin")})})]}),e.jsx("p",{className:"text-xs text-muted-foreground mb-3",children:t("cliproxyPage.accountManagement")}),e.jsxs(U,{variant:"default",size:"sm",className:"w-full gap-2",onClick:()=>l(!0),children:[e.jsx(Pe,{className:"w-4 h-4"}),t("cliproxyPage.quickSetup")]})]}),e.jsx(ft,{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(h=>e.jsx(ta,{className:"h-14 w-full rounded-lg"},h))}):e.jsx("div",{className:"space-y-1",children:N.map(h=>e.jsx(cn,{status:h,isSelected:K===h.provider,onSelect:()=>te(h.provider)},h.provider))}),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(os,{className:"w-3 h-3"}),t("cliproxyPage.variants")]}),e.jsx("div",{className:"space-y-1",children:q.map(h=>e.jsx(dn,{variant:h,parentAuth:N.find(F=>F.provider===h.provider),isSelected:S===h.name,onSelect:()=>ae(h.name),onDelete:()=>k.mutate(h.name),isDeleting:k.isPending},h.name))})]})]})}),e.jsx("div",{className:"p-3 border-t",children:e.jsx(xa,{})}),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:N.length})}),e.jsxs("span",{className:"flex items-center gap-1",children:[e.jsx(je,{className:"w-3 h-3 text-green-600"}),t("cliproxyPage.connectedCount",{count:N.filter(h=>h.authenticated).length})]})]})})]}),e.jsx("div",{className:"flex-1 flex min-w-0 flex-col overflow-hidden bg-background",children:A&&I?e.jsx(e.Fragment,{children:e.jsx(Ut,{provider:A.name,displayName:t("cliproxyPage.variantDisplay",{name:A.name,provider:A.provider}),authStatus:I,catalog:V[A.provider],routing:M[A.provider],logoProvider:A.provider,baseProvider:A.provider,defaultTarget:A.target,isRemoteMode:w,port:A.port,topNotice:B?e.jsx(ct,{compact:!0,showProxySettingsLink:!0}):void 0,onAddAccount:()=>g({provider:A.provider,displayName:I.displayName,isFirstAccount:(I.accounts?.length||0)===0}),onSetDefault:h=>r.mutate({provider:A.provider,accountId:h}),onRemoveAccount:h=>p.mutate({provider:A.provider,accountId:h}),onPauseToggle:(h,F)=>Z(A.provider,h,F),onSoloMode:h=>ee(A.provider,h),onBulkPause:h=>se(A.provider,h),onBulkResume:h=>de(A.provider,h),isRemovingAccount:p.isPending,isPausingAccount:x.isPending||v.isPending,isSoloingAccount:j.isPending,isBulkPausing:m.isPending,isBulkResuming:R.isPending})}):O?e.jsx(e.Fragment,{children:e.jsx(Ut,{provider:O.provider,displayName:O.displayName,authStatus:O,catalog:V[O.provider],routing:M[O.provider],isRemoteMode:w,topNotice:B?e.jsx(ct,{compact:!0,showProxySettingsLink:!0}):void 0,onAddAccount:()=>g({provider:O.provider,displayName:O.displayName,isFirstAccount:(O.accounts?.length||0)===0}),onSetDefault:h=>r.mutate({provider:O.provider,accountId:h}),onRemoveAccount:h=>p.mutate({provider:O.provider,accountId:h}),onPauseToggle:(h,F)=>Z(O.provider,h,F),onSoloMode:h=>ee(O.provider,h),onBulkPause:h=>se(O.provider,h),onBulkResume:h=>de(O.provider,h),isRemovingAccount:p.isPending,isPausingAccount:x.isPending||v.isPending,isSoloingAccount:j.isPending,isBulkPausing:m.isPending,isBulkResuming:R.isPending})}):e.jsx(un,{onSetup:()=>l(!0)})}),e.jsx(Oa,{open:C,onClose:()=>l(!1)}),e.jsx(Ga,{open:P!==null,onClose:()=>g(null),provider:P?.provider||"",displayName:P?.displayName||"",catalog:E&&P?.provider?V[P.provider]:void 0,isFirstAccount:P?.isFirstAccount||!1})]})}export{Mn as CliproxyPage};