@kaitranntt/ccs 7.0.0-dev.2 → 7.0.0-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.
@@ -1 +1 @@
1
- import{j as e}from"./radix-ui-CV3R9pD6.js";import{k as us,r}from"./react-vendor-FspHSO0w.js";import{am as me,an as hs,ao as _e,D as ps,E as bs,F as xe,ap as fs,B as C,aq as fe,ar as ge,i as je,I as L,O as gs,Q as js,U as vs,V as Ns,W as Fe}from"./index-DDxKFig1.js";import{S as B}from"./switch-CasTIVeB.js";import{CodeEditor as ys}from"./code-editor-Bm8H1Oot.js";import{a2 as S,ao as ws,z as ks,$ as Cs,m as Ss,ap as ze,j as Es,q as Ps,ab as ve,k as le,T as ue,x as he,y as pe,D as be,a5 as Ts,J as Is,aq as Ls,ar as Me,e as As,W as Rs}from"./icons-DvvDkxaF.js";import"./tanstack-Df9bCj5R.js";import"./notifications-B2Pz7lik.js";import"./utils-CzKF5WmX.js";import"./form-utils-DP6ILe7Z.js";import"./code-highlight-BoHWVYut.js";function Ys(){const[t]=us(),m=t.get("tab"),o=m==="globalenv"?"globalenv":m==="proxy"?"proxy":"websearch",[u,j]=r.useState(o),[l,h]=r.useState(null),[i,E]=r.useState(!0),[A,v]=r.useState(!1),[N,p]=r.useState(null),[T,c]=r.useState(!1),[y,O]=r.useState(null),[V,R]=r.useState(!0),[P,w]=r.useState(null),[G,_]=r.useState(!1),[q,D]=r.useState(!1),[F,z]=r.useState(""),[g,H]=r.useState(""),[Y,Q]=r.useState(!1),[k,I]=r.useState(!1),[X,Z]=r.useState(!1),[b,W]=r.useState(null),[ne,ee]=r.useState(!0),[n,M]=r.useState(!1),[se,te]=r.useState(null),[$e,Ne]=r.useState(!1),[oe,ye]=r.useState(""),[we,ke]=r.useState(""),[U,ae]=r.useState(null),[Be,Ce]=r.useState(!0),[Oe,Se]=r.useState(!1),[Ve,$]=r.useState(null),[De,Ee]=r.useState(!1),[He,ce]=r.useState(null),[We,Pe]=r.useState(!1),[Ue,qe]=r.useState(null),[Ye,Je]=r.useState(null),[Ke,Qe]=r.useState(null),[Xe,Ze]=r.useState(null);r.useEffect(()=>{Te(),Ie(),J(),Le(),Ae()},[]),r.useEffect(()=>{l&&(z(l.providers?.gemini?.model??"gemini-2.5-flash"),H(l.providers?.opencode?.model??"opencode/grok-code"))},[l]);const Te=async()=>{try{E(!0),p(null);const s=await fetch("/api/websearch");if(!s.ok)throw new Error("Failed to load WebSearch config");const a=await s.json();h(a)}catch(s){p(s.message)}finally{E(!1)}},Ie=async()=>{try{R(!0);const s=await fetch("/api/websearch/status");if(!s.ok)throw new Error("Failed to load status");const a=await s.json();O(a)}catch(s){console.error("Failed to fetch WebSearch status:",s)}finally{R(!1)}},J=async()=>{try{_(!0);const s=await fetch("/api/config/raw");if(!s.ok){w(null);return}const a=await s.text();w(a)}catch(s){console.error("Failed to fetch raw config:",s),w(null)}finally{_(!1)}},Le=async()=>{try{ee(!0),te(null);const s=await fetch("/api/global-env");if(!s.ok)throw new Error("Failed to load Global Env config");const a=await s.json();W(a)}catch(s){te(s.message)}finally{ee(!1)}},Ae=async()=>{try{Ce(!0),$(null);const s=await me.cliproxyServer.get();ae(s)}catch(s){$(s.message)}finally{Ce(!1)}},es=async()=>{if(P)try{await navigator.clipboard.writeText(P),D(!0),setTimeout(()=>D(!1),2e3)}catch(s){console.error("Failed to copy:",s)}},ss=()=>{const s=l?.providers||{},a=s.gemini?.enabled??!1,d=s.grok?.enabled??!1,f=s.opencode?.enabled??!1;K({enabled:!a||d||f,providers:{...s,gemini:{...s.gemini,enabled:!a}}})},K=async s=>{if(!l)return;const a={...l,...s};h(a);try{v(!0),p(null);const d=await fetch("/api/websearch",{method:"PUT",headers:{"Content-Type":"application/json"},body:JSON.stringify(a)});if(!d.ok){const x=await d.json();throw new Error(x.error||"Failed to save")}const f=await d.json();h(f.websearch),c(!0),setTimeout(()=>c(!1),1500),fetch("/api/config/raw").then(x=>x.ok?x.text():null).then(x=>x&&w(x)).catch(()=>{})}catch(d){h(l),p(d.message)}finally{v(!1)}},de=l?.providers?.gemini?.enabled??!1,Re=l?.providers?.grok?.enabled??!1,Ge=l?.providers?.opencode?.enabled??!1,ts=()=>{const s=l?.providers||{},a=s.grok?.enabled??!1;K({enabled:de||!a||Ge,providers:{...s,grok:{...s.grok,enabled:!a}}})},as=()=>{const s=l?.providers||{},a=s.opencode?.enabled??!1;K({enabled:de||Re||!a,providers:{...s,opencode:{...s.opencode,enabled:!a}}})},rs=()=>{const s=l?.providers?.gemini?.model??"gemini-2.5-flash";if(F!==s){const a=l?.providers||{};K({providers:{...a,gemini:{...a.gemini,model:F}}})}},ls=()=>{const s=l?.providers?.opencode?.model??"opencode/grok-code";if(g!==s){const a=l?.providers||{};K({providers:{...a,opencode:{...a.opencode,model:g}}})}},re=async s=>{if(!b)return;const a={...b,...s};W(a);try{M(!0),te(null);const d=await fetch("/api/global-env",{method:"PUT",headers:{"Content-Type":"application/json"},body:JSON.stringify(a)});if(!d.ok){const x=await d.json();throw new Error(x.error||"Failed to save")}const f=await d.json();W(f.config),Ne(!0),setTimeout(()=>Ne(!1),1500),fetch("/api/config/raw").then(x=>x.ok?x.text():null).then(x=>x&&w(x)).catch(()=>{})}catch(d){W(b),te(d.message)}finally{M(!1)}},ns=()=>{re({enabled:!b?.enabled})},os=()=>{if(!oe.trim()||!b)return;const s={...b.env,[oe.trim()]:we};re({env:s}),ye(""),ke("")},cs=s=>{if(!b)return;const a={...b.env};delete a[s],re({env:a})},ds=(s,a)=>{if(!b)return;const d={...b.env,[s]:a};re({env:d})},is=async s=>{if(!U)return;const a={remote:{...U.remote,...s.remote},fallback:{...U.fallback,...s.fallback},local:{...U.local,...s.local}};ae(a),ce(null);try{Se(!0),$(null);const d=await me.cliproxyServer.update(s);ae(d),Ee(!0),setTimeout(()=>Ee(!1),1500),fetch("/api/config/raw").then(f=>f.ok?f.text():null).then(f=>f&&w(f)).catch(()=>{})}catch(d){ae(U),$(d.message)}finally{Se(!1)}},ms=async s=>{const{host:a,port:d,protocol:f,authToken:x}=s;if(!a){$("Host is required");return}try{Pe(!0),$(null),ce(null);const ie=d?parseInt(d,10):void 0,xs=await me.cliproxyServer.test({host:a,port:ie||void 0,protocol:f,authToken:x||void 0});ce(xs)}catch(ie){$(ie.message)}finally{Pe(!1)}};return i?e.jsx("div",{className:"h-[calc(100vh-100px)] flex items-center justify-center",children:e.jsxs("div",{className:"flex items-center gap-3 text-muted-foreground",children:[e.jsx(S,{className:"w-5 h-5 animate-spin"}),e.jsx("span",{className:"text-lg",children:"Loading configuration..."})]})}):e.jsx("div",{className:"h-[calc(100vh-100px)]",children:e.jsxs(hs,{direction:"horizontal",className:"h-full",children:[e.jsx(_e,{defaultSize:40,minSize:30,maxSize:55,children:e.jsxs("div",{className:"h-full border-r flex flex-col bg-muted/30 relative",children:[e.jsx("div",{className:"p-5 border-b bg-background",children:e.jsx(ps,{value:u,onValueChange:s=>j(s),children:e.jsxs(bs,{className:"w-full",children:[e.jsxs(xe,{value:"websearch",className:"flex-1 gap-2",children:[e.jsx(ws,{className:"w-4 h-4"}),"WebSearch"]}),e.jsxs(xe,{value:"globalenv",className:"flex-1 gap-2",children:[e.jsx(ks,{className:"w-4 h-4"}),"Global Env"]}),e.jsxs(xe,{value:"proxy",className:"flex-1 gap-2",children:[e.jsx(Cs,{className:"w-4 h-4"}),"Proxy"]})]})})}),u==="websearch"?e.jsx(Gs,{config:l,status:y,statusLoading:V,saving:A,error:N,success:T,isGeminiEnabled:de,isGrokEnabled:Re,isOpenCodeEnabled:Ge,geminiModelInput:F,opencodeModelInput:g,showGeminiHint:Y,showOpencodeHint:k,showGrokHint:X,setGeminiModelInput:z,setOpencodeModelInput:H,setShowGeminiHint:Q,setShowOpencodeHint:I,setShowGrokHint:Z,toggleGemini:ss,toggleGrok:ts,toggleOpenCode:as,saveGeminiModel:rs,saveOpencodeModel:ls,fetchStatus:Ie,fetchConfig:Te,fetchRawConfig:J,loading:i}):u==="globalenv"?e.jsx(_s,{config:b,loading:ne,saving:n,error:se,success:$e,newEnvKey:oe,newEnvValue:we,setNewEnvKey:ye,setNewEnvValue:ke,toggleGlobalEnv:ns,addEnvVar:os,removeEnvVar:cs,updateEnvValue:ds,fetchGlobalEnvConfig:Le,fetchRawConfig:J}):e.jsx(Fs,{config:U,loading:Be,saving:Oe,error:Ve,success:De,testResult:He,testing:We,saveCliproxyServerConfig:is,handleTestConnection:ms,fetchCliproxyServerConfig:Ae,fetchRawConfig:J,editedHost:Ue,setEditedHost:qe,editedPort:Ye,setEditedPort:Je,editedAuthToken:Ke,setEditedAuthToken:Qe,editedLocalPort:Xe,setEditedLocalPort:Ze})]})}),e.jsx(fs,{className:"w-2 bg-border hover:bg-primary/20 transition-colors cursor-col-resize flex items-center justify-center group",children:e.jsx(Ss,{className:"w-3 h-3 text-muted-foreground group-hover:text-primary"})}),e.jsx(_e,{defaultSize:60,minSize:35,children:e.jsxs("div",{className:"h-full flex flex-col",children:[e.jsxs("div",{className:"p-4 border-b bg-background flex items-center justify-between",children:[e.jsxs("div",{className:"flex items-center gap-3",children:[e.jsx(ze,{className:"w-5 h-5 text-primary"}),e.jsxs("div",{children:[e.jsx("h2",{className:"font-semibold",children:"config.yaml"}),e.jsx("p",{className:"text-sm text-muted-foreground",children:"~/.ccs/config.yaml"})]})]}),e.jsxs("div",{className:"flex gap-2",children:[e.jsx(C,{variant:"outline",size:"sm",onClick:es,disabled:!P,children:q?e.jsxs(e.Fragment,{children:[e.jsx(Es,{className:"w-4 h-4 mr-1"}),"Copied"]}):e.jsxs(e.Fragment,{children:[e.jsx(Ps,{className:"w-4 h-4 mr-1"}),"Copy"]})}),e.jsx(C,{variant:"outline",size:"sm",onClick:J,disabled:G,children:e.jsx(S,{className:`w-4 h-4 ${G?"animate-spin":""}`})})]})]}),e.jsx("div",{className:"flex-1 overflow-auto",children:G?e.jsxs("div",{className:"flex items-center justify-center h-full text-muted-foreground",children:[e.jsx(S,{className:"w-5 h-5 animate-spin mr-2"}),"Loading..."]}):P?e.jsx(ys,{value:P,onChange:()=>{},language:"yaml",readonly:!0,minHeight:"auto",className:"min-h-full"}):e.jsx("div",{className:"flex items-center justify-center h-full text-muted-foreground",children:e.jsxs("div",{className:"text-center",children:[e.jsx(ze,{className:"w-12 h-12 mx-auto mb-3 opacity-30"}),e.jsx("p",{children:"Config file not found"}),e.jsx("code",{className:"text-sm bg-muted px-2 py-1 rounded mt-2 inline-block",children:"ccs migrate"})]})})})]})})]})})}function Gs({status:t,statusLoading:m,saving:o,error:u,success:j,isGeminiEnabled:l,isGrokEnabled:h,isOpenCodeEnabled:i,geminiModelInput:E,opencodeModelInput:A,showGeminiHint:v,showOpencodeHint:N,showGrokHint:p,setGeminiModelInput:T,setOpencodeModelInput:c,setShowGeminiHint:y,setShowOpencodeHint:O,setShowGrokHint:V,toggleGemini:R,toggleGrok:P,toggleOpenCode:w,saveGeminiModel:G,saveOpencodeModel:_,fetchStatus:q,fetchConfig:D,fetchRawConfig:F,loading:z}){return e.jsxs(e.Fragment,{children:[e.jsxs("div",{className:`absolute left-5 right-5 top-20 z-10 transition-all duration-200 ease-out ${u||j?"opacity-100 translate-y-0":"opacity-0 -translate-y-2 pointer-events-none"}`,children:[u&&e.jsxs(fe,{variant:"destructive",className:"py-2 shadow-lg",children:[e.jsx(ve,{className:"h-4 w-4"}),e.jsx(ge,{children:u})]}),j&&e.jsxs("div",{className:"flex items-center gap-2 px-3 py-2 rounded-md border border-green-200 bg-green-50 text-green-700 shadow-lg dark:border-green-900/50 dark:bg-green-900/90 dark:text-green-300",children:[e.jsx(le,{className:"h-4 w-4 shrink-0"}),e.jsx("span",{className:"text-sm font-medium",children:"Saved"})]})]}),e.jsx(je,{className:"flex-1",children:e.jsxs("div",{className:"p-5 space-y-6",children:[e.jsx("p",{className:"text-sm text-muted-foreground",children:"CLI-based web search for third-party profiles (gemini, codex, agy, etc.)"}),e.jsxs("div",{className:"flex items-center justify-between p-4 rounded-lg bg-muted/50",children:[e.jsxs("div",{children:[e.jsx("p",{className:"font-medium",children:l?"WebSearch enabled":"WebSearch disabled"}),m?e.jsx("p",{className:"text-sm text-muted-foreground",children:"Checking status..."}):t?.readiness?e.jsx("p",{className:"text-sm text-muted-foreground",children:t.readiness.message}):null]}),e.jsx(C,{variant:"ghost",size:"sm",onClick:q,disabled:m,children:e.jsx(S,{className:`w-4 h-4 ${m?"animate-spin":""}`})})]}),e.jsxs("div",{className:"space-y-3",children:[e.jsx("h3",{className:"text-base font-medium",children:"Providers"}),e.jsxs("div",{className:`rounded-lg border transition-colors ${l?"border-primary border-l-4":"border-border"}`,children:[e.jsxs("div",{className:"flex items-center justify-between p-4",children:[e.jsxs("div",{className:"flex items-center gap-3",children:[e.jsx(ue,{className:`w-5 h-5 ${l?"text-primary":"text-muted-foreground"}`}),e.jsxs("div",{children:[e.jsxs("div",{className:"flex items-center gap-2",children:[e.jsx("p",{className:"font-mono font-medium",children:"gemini"}),e.jsx("span",{className:"text-xs px-1.5 py-0.5 rounded bg-green-500/10 text-green-600 font-medium",children:"FREE"}),t?.geminiCli?.installed?e.jsx("span",{className:"text-xs px-1.5 py-0.5 rounded bg-green-500/10 text-green-600 font-medium",children:"installed"}):e.jsx("span",{className:"text-xs px-1.5 py-0.5 rounded bg-amber-500/10 text-amber-600 font-medium",children:"not installed"})]}),e.jsx("p",{className:"text-sm text-muted-foreground",children:"Google Gemini CLI (1000 req/day free)"})]})]}),e.jsx(B,{checked:l,onCheckedChange:R,disabled:o||!t?.geminiCli?.installed})]}),l&&e.jsx("div",{className:"px-4 pb-4 pt-0",children:e.jsxs("div",{className:"flex items-center gap-2",children:[e.jsx("label",{className:"text-sm text-muted-foreground whitespace-nowrap",children:"Model:"}),e.jsx(L,{value:E,onChange:g=>T(g.target.value),onBlur:G,placeholder:"gemini-2.5-flash",className:"h-8 text-sm font-mono",disabled:o})]})}),!t?.geminiCli?.installed&&!m&&e.jsxs("div",{className:"px-4 pb-4 pt-0 border-t border-border/50",children:[e.jsxs("button",{onClick:()=>y(!v),className:"flex items-center gap-2 text-sm text-amber-600 dark:text-amber-400 hover:underline w-full py-2",children:[v?e.jsx(he,{className:"w-4 h-4"}):e.jsx(pe,{className:"w-4 h-4"}),"How to install Gemini CLI"]}),v&&e.jsxs("div",{className:"mt-2 p-3 rounded-md bg-amber-50 dark:bg-amber-900/20 text-sm",children:[e.jsx("p",{className:"text-amber-700 dark:text-amber-300 mb-2",children:"Install globally (FREE tier available):"}),e.jsx("code",{className:"text-sm bg-amber-100 dark:bg-amber-900/40 px-2 py-1 rounded font-mono block mb-2",children:"npm install -g @google/gemini-cli"}),e.jsxs("a",{href:"https://github.com/google-gemini/gemini-cli",target:"_blank",rel:"noopener noreferrer",className:"text-amber-700 dark:text-amber-300 hover:underline inline-flex items-center gap-1",children:[e.jsx(be,{className:"w-3 h-3"}),"View documentation"]})]})]})]}),e.jsxs("div",{className:`rounded-lg border transition-colors ${i?"border-primary border-l-4":"border-border"}`,children:[e.jsxs("div",{className:"flex items-center justify-between p-4",children:[e.jsxs("div",{className:"flex items-center gap-3",children:[e.jsx(ue,{className:`w-5 h-5 ${i?"text-primary":"text-muted-foreground"}`}),e.jsxs("div",{children:[e.jsxs("div",{className:"flex items-center gap-2",children:[e.jsx("p",{className:"font-mono font-medium",children:"opencode"}),e.jsx("span",{className:"text-xs px-1.5 py-0.5 rounded bg-green-500/10 text-green-600 font-medium",children:"FREE"}),t?.opencodeCli?.installed?e.jsx("span",{className:"text-xs px-1.5 py-0.5 rounded bg-green-500/10 text-green-600 font-medium",children:"installed"}):e.jsx("span",{className:"text-xs px-1.5 py-0.5 rounded bg-amber-500/10 text-amber-600 font-medium",children:"not installed"})]}),e.jsx("p",{className:"text-sm text-muted-foreground",children:"OpenCode (web search via Zen)"})]})]}),e.jsx(B,{checked:i,onCheckedChange:w,disabled:o||!t?.opencodeCli?.installed})]}),i&&e.jsx("div",{className:"px-4 pb-4 pt-0",children:e.jsxs("div",{className:"flex items-center gap-2",children:[e.jsx("label",{className:"text-sm text-muted-foreground whitespace-nowrap",children:"Model:"}),e.jsx(L,{value:A,onChange:g=>c(g.target.value),onBlur:_,placeholder:"opencode/grok-code",className:"h-8 text-sm font-mono",disabled:o})]})}),!t?.opencodeCli?.installed&&!m&&e.jsxs("div",{className:"px-4 pb-4 pt-0 border-t border-border/50",children:[e.jsxs("button",{onClick:()=>O(!N),className:"flex items-center gap-2 text-sm text-purple-600 dark:text-purple-400 hover:underline w-full py-2",children:[N?e.jsx(he,{className:"w-4 h-4"}):e.jsx(pe,{className:"w-4 h-4"}),"How to install OpenCode"]}),N&&e.jsxs("div",{className:"mt-2 p-3 rounded-md bg-purple-50 dark:bg-purple-900/20 text-sm",children:[e.jsx("p",{className:"text-purple-700 dark:text-purple-300 mb-2",children:"Install globally (FREE tier available):"}),e.jsx("code",{className:"text-sm bg-purple-100 dark:bg-purple-900/40 px-2 py-1 rounded font-mono block mb-2",children:"curl -fsSL https://opencode.ai/install | bash"}),e.jsxs("a",{href:"https://github.com/sst/opencode",target:"_blank",rel:"noopener noreferrer",className:"text-purple-700 dark:text-purple-300 hover:underline inline-flex items-center gap-1",children:[e.jsx(be,{className:"w-3 h-3"}),"View documentation"]})]})]})]}),e.jsxs("div",{className:`rounded-lg border transition-colors ${h?"border-primary border-l-4":"border-border"}`,children:[e.jsxs("div",{className:"flex items-center justify-between p-4",children:[e.jsxs("div",{className:"flex items-center gap-3",children:[e.jsx(ue,{className:`w-5 h-5 ${h?"text-primary":"text-muted-foreground"}`}),e.jsxs("div",{children:[e.jsxs("div",{className:"flex items-center gap-2",children:[e.jsx("p",{className:"font-mono font-medium",children:"grok"}),e.jsx("span",{className:"text-xs px-1.5 py-0.5 rounded bg-blue-500/10 text-blue-600 font-medium",children:"GROK_API_KEY"}),t?.grokCli?.installed?e.jsx("span",{className:"text-xs px-1.5 py-0.5 rounded bg-green-500/10 text-green-600 font-medium",children:"installed"}):e.jsx("span",{className:"text-xs px-1.5 py-0.5 rounded bg-amber-500/10 text-amber-600 font-medium",children:"not installed"})]}),e.jsx("p",{className:"text-sm text-muted-foreground",children:"xAI Grok CLI (web + X search)"})]})]}),e.jsx(B,{checked:h,onCheckedChange:P,disabled:o||!t?.grokCli?.installed})]}),!t?.grokCli?.installed&&!m&&e.jsxs("div",{className:"px-4 pb-4 pt-0 border-t border-border/50",children:[e.jsxs("button",{onClick:()=>V(!p),className:"flex items-center gap-2 text-sm text-blue-600 dark:text-blue-400 hover:underline w-full py-2",children:[p?e.jsx(he,{className:"w-4 h-4"}):e.jsx(pe,{className:"w-4 h-4"}),"How to install Grok CLI"]}),p&&e.jsxs("div",{className:"mt-2 p-3 rounded-md bg-blue-50 dark:bg-blue-900/20 text-sm",children:[e.jsx("p",{className:"text-blue-700 dark:text-blue-300 mb-2",children:"Install globally (requires xAI API key):"}),e.jsx("code",{className:"text-sm bg-blue-100 dark:bg-blue-900/40 px-2 py-1 rounded font-mono block mb-2",children:"npm install -g @vibe-kit/grok-cli"}),e.jsxs("a",{href:"https://github.com/superagent-ai/grok-cli",target:"_blank",rel:"noopener noreferrer",className:"text-blue-700 dark:text-blue-300 hover:underline inline-flex items-center gap-1",children:[e.jsx(be,{className:"w-3 h-3"}),"View documentation"]})]})]})]})]})]})}),e.jsx("div",{className:"p-4 border-t bg-background",children:e.jsxs(C,{variant:"outline",size:"sm",onClick:()=>{D(),F()},disabled:z||o,className:"w-full",children:[e.jsx(S,{className:`w-4 h-4 mr-2 ${z?"animate-spin":""}`}),"Refresh"]})})]})}function _s({config:t,loading:m,saving:o,error:u,success:j,newEnvKey:l,newEnvValue:h,setNewEnvKey:i,setNewEnvValue:E,toggleGlobalEnv:A,addEnvVar:v,removeEnvVar:N,fetchGlobalEnvConfig:p,fetchRawConfig:T}){return m?e.jsx("div",{className:"flex-1 flex items-center justify-center",children:e.jsxs("div",{className:"flex items-center gap-3 text-muted-foreground",children:[e.jsx(S,{className:"w-5 h-5 animate-spin"}),e.jsx("span",{children:"Loading..."})]})}):e.jsxs(e.Fragment,{children:[e.jsxs("div",{className:`absolute left-5 right-5 top-20 z-10 transition-all duration-200 ease-out ${u||j?"opacity-100 translate-y-0":"opacity-0 -translate-y-2 pointer-events-none"}`,children:[u&&e.jsxs(fe,{variant:"destructive",className:"py-2 shadow-lg",children:[e.jsx(ve,{className:"h-4 w-4"}),e.jsx(ge,{children:u})]}),j&&e.jsxs("div",{className:"flex items-center gap-2 px-3 py-2 rounded-md border border-green-200 bg-green-50 text-green-700 shadow-lg dark:border-green-900/50 dark:bg-green-900/90 dark:text-green-300",children:[e.jsx(le,{className:"h-4 w-4 shrink-0"}),e.jsx("span",{className:"text-sm font-medium",children:"Saved"})]})]}),e.jsx(je,{className:"flex-1",children:e.jsxs("div",{className:"p-5 space-y-6",children:[e.jsx("p",{className:"text-sm text-muted-foreground",children:"Environment variables injected into all non-Claude subscription profiles (gemini, codex, agy, copilot, etc.)"}),e.jsxs("div",{className:"flex items-center justify-between p-4 rounded-lg bg-muted/50",children:[e.jsxs("div",{children:[e.jsx("p",{className:"font-medium",children:t?.enabled?"Global Env enabled":"Global Env disabled"}),e.jsx("p",{className:"text-sm text-muted-foreground",children:t?.enabled?"Env vars will be injected into third-party profiles":"Env vars will not be injected"})]}),e.jsx(B,{checked:t?.enabled??!0,onCheckedChange:A})]}),e.jsxs("div",{className:"space-y-3",children:[e.jsx("h3",{className:"text-base font-medium",children:"Environment Variables"}),t?.env&&Object.keys(t.env).length>0?e.jsx("div",{className:"space-y-2",children:Object.entries(t.env).map(([c,y])=>e.jsxs("div",{className:"flex items-center gap-2 p-3 rounded-lg border bg-background",children:[e.jsx("code",{className:"flex-1 font-mono text-sm truncate",children:c}),e.jsx("span",{className:"text-muted-foreground",children:"="}),e.jsx("code",{className:"font-mono text-sm px-2 py-1 bg-muted rounded",children:y}),e.jsx(C,{variant:"ghost",size:"sm",onClick:()=>N(c),disabled:o,className:"h-8 w-8 p-0 text-destructive hover:text-destructive hover:bg-destructive/10",children:e.jsx(Ts,{className:"w-4 h-4"})})]},c))}):e.jsx("div",{className:"p-4 rounded-lg border border-dashed text-center text-muted-foreground",children:e.jsx("p",{children:"No environment variables configured"})}),e.jsxs("div",{className:"p-4 rounded-lg border bg-muted/30",children:[e.jsx("h4",{className:"text-sm font-medium mb-3",children:"Add New Variable"}),e.jsxs("div",{className:"flex gap-2",children:[e.jsx(L,{value:l,onChange:c=>i(c.target.value.toUpperCase()),placeholder:"KEY_NAME",className:"flex-1 font-mono text-sm h-9",disabled:o}),e.jsx("span",{className:"flex items-center text-muted-foreground",children:"="}),e.jsx(L,{value:h,onChange:c=>E(c.target.value),placeholder:"value",className:"flex-1 font-mono text-sm h-9",disabled:o}),e.jsxs(C,{size:"sm",onClick:v,disabled:o||!l.trim(),className:"h-9",children:[e.jsx(Is,{className:"w-4 h-4 mr-1"}),"Add"]})]})]}),e.jsxs("div",{className:"p-4 rounded-lg border bg-muted/30",children:[e.jsx("h4",{className:"text-sm font-medium mb-3",children:"Quick Add Common Variables"}),e.jsxs("div",{className:"flex flex-wrap gap-2",children:[[{key:"DISABLE_BUG_COMMAND",value:"1"},{key:"DISABLE_ERROR_REPORTING",value:"1"},{key:"DISABLE_TELEMETRY",value:"1"}].map(({key:c,value:y})=>!t?.env?.[c]&&e.jsxs(C,{variant:"outline",size:"sm",onClick:()=>{i(c),E(y)},className:"text-xs font-mono",children:["+ ",c]},c)),t?.env&&["DISABLE_BUG_COMMAND","DISABLE_ERROR_REPORTING","DISABLE_TELEMETRY"].every(c=>t.env[c])&&e.jsx("span",{className:"text-sm text-muted-foreground",children:"All common variables are configured"})]})]})]})]})}),e.jsx("div",{className:"p-4 border-t bg-background",children:e.jsxs(C,{variant:"outline",size:"sm",onClick:()=>{p(),T()},disabled:m||o,className:"w-full",children:[e.jsx(S,{className:`w-4 h-4 mr-2 ${m?"animate-spin":""}`}),"Refresh"]})})]})}function Fs({config:t,loading:m,saving:o,error:u,success:j,testResult:l,testing:h,saveCliproxyServerConfig:i,handleTestConnection:E,fetchCliproxyServerConfig:A,fetchRawConfig:v,editedHost:N,setEditedHost:p,editedPort:T,setEditedPort:c,editedAuthToken:y,setEditedAuthToken:O,editedLocalPort:V,setEditedLocalPort:R}){const P={enabled:!1,host:"",port:void 0,protocol:"http",auth_token:""},w={enabled:!0,auto_start:!0},G={port:8317,auto_start:!0},_=n=>n==="https"?443:8317,q=t?.remote.host??"",D=t?.remote.port!==void 0?t.remote.port.toString():"",F=t?.remote.auth_token??"",z=(t?.local.port??8317).toString(),g=N??q,H=T??D,Y=y??F,Q=V??z;if(m)return e.jsx("div",{className:"flex-1 flex items-center justify-center",children:e.jsxs("div",{className:"flex items-center gap-3 text-muted-foreground",children:[e.jsx(S,{className:"w-5 h-5 animate-spin"}),e.jsx("span",{children:"Loading..."})]})});const k=t?.remote.enabled??!1,I=t?.remote??P,X=t?.fallback??w,Z=t?.local??G,b=()=>{const n=N??g;n!==t?.remote.host&&i({remote:{...I,host:n}}),p(null)},W=()=>{const n=T??H,M=n===""?void 0:parseInt(n,10),se=M&&!isNaN(M)&&M>0?M:void 0;se!==t?.remote.port&&i({remote:{...I,port:se}}),c(null)},ne=()=>{const n=y??Y;n!==t?.remote.auth_token&&i({remote:{...I,auth_token:n}}),O(null)},ee=()=>{const n=parseInt(V??Q,10);!isNaN(n)&&n!==t?.local.port&&i({local:{...Z,port:n}}),R(null)};return e.jsxs(e.Fragment,{children:[e.jsxs("div",{className:`absolute left-5 right-5 top-20 z-10 transition-all duration-200 ease-out ${u||j?"opacity-100 translate-y-0":"opacity-0 -translate-y-2 pointer-events-none"}`,children:[u&&e.jsxs(fe,{variant:"destructive",className:"py-2 shadow-lg",children:[e.jsx(ve,{className:"h-4 w-4"}),e.jsx(ge,{children:u})]}),j&&e.jsxs("div",{className:"flex items-center gap-2 px-3 py-2 rounded-md border border-green-200 bg-green-50 text-green-700 shadow-lg dark:border-green-900/50 dark:bg-green-900/90 dark:text-green-300",children:[e.jsx(le,{className:"h-4 w-4 shrink-0"}),e.jsx("span",{className:"text-sm font-medium",children:"Saved"})]})]}),e.jsx(je,{className:"flex-1",children:e.jsxs("div",{className:"p-5 space-y-6",children:[e.jsx("p",{className:"text-sm text-muted-foreground",children:"Configure local or remote CLIProxyAPI connection for proxy-based profiles"}),e.jsxs("div",{className:"space-y-3",children:[e.jsx("h3",{className:"text-base font-medium",children:"Connection Mode"}),e.jsxs("div",{className:"grid grid-cols-2 gap-3",children:[e.jsxs("button",{onClick:()=>i({remote:{...I,enabled:!1}}),disabled:o,className:`p-4 rounded-lg border-2 text-left transition-all ${k?"border-border hover:border-muted-foreground/50":"border-primary bg-primary/5"}`,children:[e.jsxs("div",{className:"flex items-center gap-3 mb-2",children:[e.jsx(Ls,{className:`w-5 h-5 ${k?"text-muted-foreground":"text-primary"}`}),e.jsx("span",{className:"font-medium",children:"Local"})]}),e.jsx("p",{className:"text-xs text-muted-foreground",children:"Run CLIProxyAPI binary on this machine"})]}),e.jsxs("button",{onClick:()=>i({remote:{...I,enabled:!0}}),disabled:o,className:`p-4 rounded-lg border-2 text-left transition-all ${k?"border-primary bg-primary/5":"border-border hover:border-muted-foreground/50"}`,children:[e.jsxs("div",{className:"flex items-center gap-3 mb-2",children:[e.jsx(Me,{className:`w-5 h-5 ${k?"text-primary":"text-muted-foreground"}`}),e.jsx("span",{className:"font-medium",children:"Remote"})]}),e.jsx("p",{className:"text-xs text-muted-foreground",children:"Connect to a remote CLIProxyAPI server"})]})]})]}),k&&e.jsxs("div",{className:"space-y-4 p-4 rounded-lg border bg-muted/30",children:[e.jsxs("h4",{className:"text-sm font-medium flex items-center gap-2",children:[e.jsx(Me,{className:"w-4 h-4"}),"Remote Server Configuration"]}),e.jsxs("div",{className:"space-y-1",children:[e.jsx("label",{className:"text-sm text-muted-foreground",children:"Host"}),e.jsx(L,{value:g,onChange:n=>p(n.target.value),onBlur:b,placeholder:"192.168.1.100 or proxy.example.com",className:"font-mono",disabled:o})]}),e.jsxs("div",{className:"grid grid-cols-2 gap-3",children:[e.jsxs("div",{className:"space-y-1",children:[e.jsxs("label",{className:"text-sm text-muted-foreground",children:["Port"," ",e.jsxs("span",{className:"text-xs opacity-70",children:["(default: ",_(t?.remote.protocol||"http"),")"]})]}),e.jsx(L,{type:"text",inputMode:"numeric",value:H,onChange:n=>c(n.target.value.replace(/\D/g,"")),onBlur:W,placeholder:`Leave empty for ${_(t?.remote.protocol||"http")}`,className:"font-mono",disabled:o})]}),e.jsxs("div",{className:"space-y-1",children:[e.jsx("label",{className:"text-sm text-muted-foreground",children:"Protocol"}),e.jsxs(gs,{value:t?.remote.protocol||"http",onValueChange:n=>i({remote:{...I,protocol:n}}),disabled:o,children:[e.jsx(js,{children:e.jsx(vs,{})}),e.jsxs(Ns,{children:[e.jsx(Fe,{value:"http",children:"HTTP"}),e.jsx(Fe,{value:"https",children:"HTTPS"})]})]})]})]}),e.jsxs("div",{className:"space-y-1",children:[e.jsx("label",{className:"text-sm text-muted-foreground",children:"Auth Token (optional)"}),e.jsx(L,{type:"password",value:Y,onChange:n=>O(n.target.value),onBlur:ne,placeholder:"Bearer token for authentication",className:"font-mono",disabled:o})]}),e.jsxs("div",{className:"space-y-3 pt-2",children:[e.jsx(C,{onClick:()=>E({host:g,port:H,protocol:t?.remote.protocol||"http",authToken:Y}),disabled:h||!g,variant:"outline",className:"w-full",children:h?e.jsxs(e.Fragment,{children:[e.jsx(S,{className:"w-4 h-4 mr-2 animate-spin"}),"Testing..."]}):e.jsxs(e.Fragment,{children:[e.jsx(As,{className:"w-4 h-4 mr-2"}),"Test Connection"]})}),l&&e.jsx("div",{className:`p-3 rounded-md ${l.reachable?"bg-green-50 border border-green-200 dark:bg-green-900/20 dark:border-green-900/50":"bg-red-50 border border-red-200 dark:bg-red-900/20 dark:border-red-900/50"}`,children:e.jsx("div",{className:"flex items-center gap-2",children:l.reachable?e.jsxs(e.Fragment,{children:[e.jsx(le,{className:"w-4 h-4 text-green-600 dark:text-green-400"}),e.jsxs("span",{className:"text-sm font-medium text-green-700 dark:text-green-300",children:["Connected (",l.latencyMs,"ms)"]})]}):e.jsxs(e.Fragment,{children:[e.jsx(Rs,{className:"w-4 h-4 text-red-600 dark:text-red-400"}),e.jsx("span",{className:"text-sm font-medium text-red-700 dark:text-red-300",children:l.error||"Connection failed"})]})})})]})]}),e.jsxs("div",{className:"space-y-3",children:[e.jsx("h3",{className:"text-base font-medium",children:"Fallback Settings"}),e.jsxs("div",{className:"space-y-3 p-4 rounded-lg border bg-muted/30",children:[e.jsxs("div",{className:"flex items-center justify-between",children:[e.jsxs("div",{children:[e.jsx("p",{className:"font-medium text-sm",children:"Enable fallback to local"}),e.jsx("p",{className:"text-xs text-muted-foreground",children:"Use local proxy if remote is unreachable"})]}),e.jsx(B,{checked:t?.fallback.enabled??!0,onCheckedChange:n=>i({fallback:{...X,enabled:n}}),disabled:o||!k})]}),e.jsxs("div",{className:"flex items-center justify-between",children:[e.jsxs("div",{children:[e.jsx("p",{className:"font-medium text-sm",children:"Auto-start local proxy"}),e.jsx("p",{className:"text-xs text-muted-foreground",children:"Automatically start local proxy on fallback"})]}),e.jsx(B,{checked:t?.fallback.auto_start??!1,onCheckedChange:n=>i({fallback:{...X,auto_start:n}}),disabled:o||!k||!t?.fallback.enabled})]})]})]}),!k&&e.jsxs("div",{className:"space-y-3",children:[e.jsx("h3",{className:"text-base font-medium",children:"Local Proxy"}),e.jsxs("div",{className:"space-y-3 p-4 rounded-lg border bg-muted/30",children:[e.jsxs("div",{className:"space-y-1",children:[e.jsx("label",{className:"text-sm text-muted-foreground",children:"Port"}),e.jsx(L,{type:"number",value:Q,onChange:n=>R(n.target.value),onBlur:ee,placeholder:"8317",className:"font-mono max-w-32",disabled:o})]}),e.jsxs("div",{className:"flex items-center justify-between",children:[e.jsxs("div",{children:[e.jsx("p",{className:"font-medium text-sm",children:"Auto-start"}),e.jsx("p",{className:"text-xs text-muted-foreground",children:"Start local proxy automatically when needed"})]}),e.jsx(B,{checked:t?.local.auto_start??!0,onCheckedChange:n=>i({local:{...Z,auto_start:n}}),disabled:o})]})]})]})]})}),e.jsx("div",{className:"p-4 border-t bg-background",children:e.jsxs(C,{variant:"outline",size:"sm",onClick:()=>{A(),v()},disabled:m||o,className:"w-full",children:[e.jsx(S,{className:`w-4 h-4 mr-2 ${m?"animate-spin":""}`}),"Refresh"]})})]})}export{Ys as SettingsPage};
1
+ import{j as e}from"./radix-ui-CV3R9pD6.js";import{k as us,r}from"./react-vendor-FspHSO0w.js";import{am as me,an as hs,ao as _e,D as ps,E as bs,F as xe,ap as fs,B as C,aq as fe,ar as ge,i as je,I as L,O as gs,Q as js,U as vs,V as Ns,W as Fe}from"./index-Hai6xZvK.js";import{S as B}from"./switch-BzjyydVV.js";import{CodeEditor as ys}from"./code-editor-DHCb2-64.js";import{a2 as S,ao as ws,z as ks,$ as Cs,m as Ss,ap as ze,j as Es,q as Ps,ab as ve,k as le,T as ue,x as he,y as pe,D as be,a5 as Ts,J as Is,aq as Ls,ar as Me,e as As,W as Rs}from"./icons-DvvDkxaF.js";import"./tanstack-Df9bCj5R.js";import"./notifications-B2Pz7lik.js";import"./utils-CzKF5WmX.js";import"./form-utils-DP6ILe7Z.js";import"./code-highlight-BoHWVYut.js";function Ys(){const[t]=us(),m=t.get("tab"),o=m==="globalenv"?"globalenv":m==="proxy"?"proxy":"websearch",[u,j]=r.useState(o),[l,h]=r.useState(null),[i,E]=r.useState(!0),[A,v]=r.useState(!1),[N,p]=r.useState(null),[T,c]=r.useState(!1),[y,O]=r.useState(null),[V,R]=r.useState(!0),[P,w]=r.useState(null),[G,_]=r.useState(!1),[q,D]=r.useState(!1),[F,z]=r.useState(""),[g,H]=r.useState(""),[Y,Q]=r.useState(!1),[k,I]=r.useState(!1),[X,Z]=r.useState(!1),[b,W]=r.useState(null),[ne,ee]=r.useState(!0),[n,M]=r.useState(!1),[se,te]=r.useState(null),[$e,Ne]=r.useState(!1),[oe,ye]=r.useState(""),[we,ke]=r.useState(""),[U,ae]=r.useState(null),[Be,Ce]=r.useState(!0),[Oe,Se]=r.useState(!1),[Ve,$]=r.useState(null),[De,Ee]=r.useState(!1),[He,ce]=r.useState(null),[We,Pe]=r.useState(!1),[Ue,qe]=r.useState(null),[Ye,Je]=r.useState(null),[Ke,Qe]=r.useState(null),[Xe,Ze]=r.useState(null);r.useEffect(()=>{Te(),Ie(),J(),Le(),Ae()},[]),r.useEffect(()=>{l&&(z(l.providers?.gemini?.model??"gemini-2.5-flash"),H(l.providers?.opencode?.model??"opencode/grok-code"))},[l]);const Te=async()=>{try{E(!0),p(null);const s=await fetch("/api/websearch");if(!s.ok)throw new Error("Failed to load WebSearch config");const a=await s.json();h(a)}catch(s){p(s.message)}finally{E(!1)}},Ie=async()=>{try{R(!0);const s=await fetch("/api/websearch/status");if(!s.ok)throw new Error("Failed to load status");const a=await s.json();O(a)}catch(s){console.error("Failed to fetch WebSearch status:",s)}finally{R(!1)}},J=async()=>{try{_(!0);const s=await fetch("/api/config/raw");if(!s.ok){w(null);return}const a=await s.text();w(a)}catch(s){console.error("Failed to fetch raw config:",s),w(null)}finally{_(!1)}},Le=async()=>{try{ee(!0),te(null);const s=await fetch("/api/global-env");if(!s.ok)throw new Error("Failed to load Global Env config");const a=await s.json();W(a)}catch(s){te(s.message)}finally{ee(!1)}},Ae=async()=>{try{Ce(!0),$(null);const s=await me.cliproxyServer.get();ae(s)}catch(s){$(s.message)}finally{Ce(!1)}},es=async()=>{if(P)try{await navigator.clipboard.writeText(P),D(!0),setTimeout(()=>D(!1),2e3)}catch(s){console.error("Failed to copy:",s)}},ss=()=>{const s=l?.providers||{},a=s.gemini?.enabled??!1,d=s.grok?.enabled??!1,f=s.opencode?.enabled??!1;K({enabled:!a||d||f,providers:{...s,gemini:{...s.gemini,enabled:!a}}})},K=async s=>{if(!l)return;const a={...l,...s};h(a);try{v(!0),p(null);const d=await fetch("/api/websearch",{method:"PUT",headers:{"Content-Type":"application/json"},body:JSON.stringify(a)});if(!d.ok){const x=await d.json();throw new Error(x.error||"Failed to save")}const f=await d.json();h(f.websearch),c(!0),setTimeout(()=>c(!1),1500),fetch("/api/config/raw").then(x=>x.ok?x.text():null).then(x=>x&&w(x)).catch(()=>{})}catch(d){h(l),p(d.message)}finally{v(!1)}},de=l?.providers?.gemini?.enabled??!1,Re=l?.providers?.grok?.enabled??!1,Ge=l?.providers?.opencode?.enabled??!1,ts=()=>{const s=l?.providers||{},a=s.grok?.enabled??!1;K({enabled:de||!a||Ge,providers:{...s,grok:{...s.grok,enabled:!a}}})},as=()=>{const s=l?.providers||{},a=s.opencode?.enabled??!1;K({enabled:de||Re||!a,providers:{...s,opencode:{...s.opencode,enabled:!a}}})},rs=()=>{const s=l?.providers?.gemini?.model??"gemini-2.5-flash";if(F!==s){const a=l?.providers||{};K({providers:{...a,gemini:{...a.gemini,model:F}}})}},ls=()=>{const s=l?.providers?.opencode?.model??"opencode/grok-code";if(g!==s){const a=l?.providers||{};K({providers:{...a,opencode:{...a.opencode,model:g}}})}},re=async s=>{if(!b)return;const a={...b,...s};W(a);try{M(!0),te(null);const d=await fetch("/api/global-env",{method:"PUT",headers:{"Content-Type":"application/json"},body:JSON.stringify(a)});if(!d.ok){const x=await d.json();throw new Error(x.error||"Failed to save")}const f=await d.json();W(f.config),Ne(!0),setTimeout(()=>Ne(!1),1500),fetch("/api/config/raw").then(x=>x.ok?x.text():null).then(x=>x&&w(x)).catch(()=>{})}catch(d){W(b),te(d.message)}finally{M(!1)}},ns=()=>{re({enabled:!b?.enabled})},os=()=>{if(!oe.trim()||!b)return;const s={...b.env,[oe.trim()]:we};re({env:s}),ye(""),ke("")},cs=s=>{if(!b)return;const a={...b.env};delete a[s],re({env:a})},ds=(s,a)=>{if(!b)return;const d={...b.env,[s]:a};re({env:d})},is=async s=>{if(!U)return;const a={remote:{...U.remote,...s.remote},fallback:{...U.fallback,...s.fallback},local:{...U.local,...s.local}};ae(a),ce(null);try{Se(!0),$(null);const d=await me.cliproxyServer.update(s);ae(d),Ee(!0),setTimeout(()=>Ee(!1),1500),fetch("/api/config/raw").then(f=>f.ok?f.text():null).then(f=>f&&w(f)).catch(()=>{})}catch(d){ae(U),$(d.message)}finally{Se(!1)}},ms=async s=>{const{host:a,port:d,protocol:f,authToken:x}=s;if(!a){$("Host is required");return}try{Pe(!0),$(null),ce(null);const ie=d?parseInt(d,10):void 0,xs=await me.cliproxyServer.test({host:a,port:ie||void 0,protocol:f,authToken:x||void 0});ce(xs)}catch(ie){$(ie.message)}finally{Pe(!1)}};return i?e.jsx("div",{className:"h-[calc(100vh-100px)] flex items-center justify-center",children:e.jsxs("div",{className:"flex items-center gap-3 text-muted-foreground",children:[e.jsx(S,{className:"w-5 h-5 animate-spin"}),e.jsx("span",{className:"text-lg",children:"Loading configuration..."})]})}):e.jsx("div",{className:"h-[calc(100vh-100px)]",children:e.jsxs(hs,{direction:"horizontal",className:"h-full",children:[e.jsx(_e,{defaultSize:40,minSize:30,maxSize:55,children:e.jsxs("div",{className:"h-full border-r flex flex-col bg-muted/30 relative",children:[e.jsx("div",{className:"p-5 border-b bg-background",children:e.jsx(ps,{value:u,onValueChange:s=>j(s),children:e.jsxs(bs,{className:"w-full",children:[e.jsxs(xe,{value:"websearch",className:"flex-1 gap-2",children:[e.jsx(ws,{className:"w-4 h-4"}),"WebSearch"]}),e.jsxs(xe,{value:"globalenv",className:"flex-1 gap-2",children:[e.jsx(ks,{className:"w-4 h-4"}),"Global Env"]}),e.jsxs(xe,{value:"proxy",className:"flex-1 gap-2",children:[e.jsx(Cs,{className:"w-4 h-4"}),"Proxy"]})]})})}),u==="websearch"?e.jsx(Gs,{config:l,status:y,statusLoading:V,saving:A,error:N,success:T,isGeminiEnabled:de,isGrokEnabled:Re,isOpenCodeEnabled:Ge,geminiModelInput:F,opencodeModelInput:g,showGeminiHint:Y,showOpencodeHint:k,showGrokHint:X,setGeminiModelInput:z,setOpencodeModelInput:H,setShowGeminiHint:Q,setShowOpencodeHint:I,setShowGrokHint:Z,toggleGemini:ss,toggleGrok:ts,toggleOpenCode:as,saveGeminiModel:rs,saveOpencodeModel:ls,fetchStatus:Ie,fetchConfig:Te,fetchRawConfig:J,loading:i}):u==="globalenv"?e.jsx(_s,{config:b,loading:ne,saving:n,error:se,success:$e,newEnvKey:oe,newEnvValue:we,setNewEnvKey:ye,setNewEnvValue:ke,toggleGlobalEnv:ns,addEnvVar:os,removeEnvVar:cs,updateEnvValue:ds,fetchGlobalEnvConfig:Le,fetchRawConfig:J}):e.jsx(Fs,{config:U,loading:Be,saving:Oe,error:Ve,success:De,testResult:He,testing:We,saveCliproxyServerConfig:is,handleTestConnection:ms,fetchCliproxyServerConfig:Ae,fetchRawConfig:J,editedHost:Ue,setEditedHost:qe,editedPort:Ye,setEditedPort:Je,editedAuthToken:Ke,setEditedAuthToken:Qe,editedLocalPort:Xe,setEditedLocalPort:Ze})]})}),e.jsx(fs,{className:"w-2 bg-border hover:bg-primary/20 transition-colors cursor-col-resize flex items-center justify-center group",children:e.jsx(Ss,{className:"w-3 h-3 text-muted-foreground group-hover:text-primary"})}),e.jsx(_e,{defaultSize:60,minSize:35,children:e.jsxs("div",{className:"h-full flex flex-col",children:[e.jsxs("div",{className:"p-4 border-b bg-background flex items-center justify-between",children:[e.jsxs("div",{className:"flex items-center gap-3",children:[e.jsx(ze,{className:"w-5 h-5 text-primary"}),e.jsxs("div",{children:[e.jsx("h2",{className:"font-semibold",children:"config.yaml"}),e.jsx("p",{className:"text-sm text-muted-foreground",children:"~/.ccs/config.yaml"})]})]}),e.jsxs("div",{className:"flex gap-2",children:[e.jsx(C,{variant:"outline",size:"sm",onClick:es,disabled:!P,children:q?e.jsxs(e.Fragment,{children:[e.jsx(Es,{className:"w-4 h-4 mr-1"}),"Copied"]}):e.jsxs(e.Fragment,{children:[e.jsx(Ps,{className:"w-4 h-4 mr-1"}),"Copy"]})}),e.jsx(C,{variant:"outline",size:"sm",onClick:J,disabled:G,children:e.jsx(S,{className:`w-4 h-4 ${G?"animate-spin":""}`})})]})]}),e.jsx("div",{className:"flex-1 overflow-auto",children:G?e.jsxs("div",{className:"flex items-center justify-center h-full text-muted-foreground",children:[e.jsx(S,{className:"w-5 h-5 animate-spin mr-2"}),"Loading..."]}):P?e.jsx(ys,{value:P,onChange:()=>{},language:"yaml",readonly:!0,minHeight:"auto",className:"min-h-full"}):e.jsx("div",{className:"flex items-center justify-center h-full text-muted-foreground",children:e.jsxs("div",{className:"text-center",children:[e.jsx(ze,{className:"w-12 h-12 mx-auto mb-3 opacity-30"}),e.jsx("p",{children:"Config file not found"}),e.jsx("code",{className:"text-sm bg-muted px-2 py-1 rounded mt-2 inline-block",children:"ccs migrate"})]})})})]})})]})})}function Gs({status:t,statusLoading:m,saving:o,error:u,success:j,isGeminiEnabled:l,isGrokEnabled:h,isOpenCodeEnabled:i,geminiModelInput:E,opencodeModelInput:A,showGeminiHint:v,showOpencodeHint:N,showGrokHint:p,setGeminiModelInput:T,setOpencodeModelInput:c,setShowGeminiHint:y,setShowOpencodeHint:O,setShowGrokHint:V,toggleGemini:R,toggleGrok:P,toggleOpenCode:w,saveGeminiModel:G,saveOpencodeModel:_,fetchStatus:q,fetchConfig:D,fetchRawConfig:F,loading:z}){return e.jsxs(e.Fragment,{children:[e.jsxs("div",{className:`absolute left-5 right-5 top-20 z-10 transition-all duration-200 ease-out ${u||j?"opacity-100 translate-y-0":"opacity-0 -translate-y-2 pointer-events-none"}`,children:[u&&e.jsxs(fe,{variant:"destructive",className:"py-2 shadow-lg",children:[e.jsx(ve,{className:"h-4 w-4"}),e.jsx(ge,{children:u})]}),j&&e.jsxs("div",{className:"flex items-center gap-2 px-3 py-2 rounded-md border border-green-200 bg-green-50 text-green-700 shadow-lg dark:border-green-900/50 dark:bg-green-900/90 dark:text-green-300",children:[e.jsx(le,{className:"h-4 w-4 shrink-0"}),e.jsx("span",{className:"text-sm font-medium",children:"Saved"})]})]}),e.jsx(je,{className:"flex-1",children:e.jsxs("div",{className:"p-5 space-y-6",children:[e.jsx("p",{className:"text-sm text-muted-foreground",children:"CLI-based web search for third-party profiles (gemini, codex, agy, etc.)"}),e.jsxs("div",{className:"flex items-center justify-between p-4 rounded-lg bg-muted/50",children:[e.jsxs("div",{children:[e.jsx("p",{className:"font-medium",children:l?"WebSearch enabled":"WebSearch disabled"}),m?e.jsx("p",{className:"text-sm text-muted-foreground",children:"Checking status..."}):t?.readiness?e.jsx("p",{className:"text-sm text-muted-foreground",children:t.readiness.message}):null]}),e.jsx(C,{variant:"ghost",size:"sm",onClick:q,disabled:m,children:e.jsx(S,{className:`w-4 h-4 ${m?"animate-spin":""}`})})]}),e.jsxs("div",{className:"space-y-3",children:[e.jsx("h3",{className:"text-base font-medium",children:"Providers"}),e.jsxs("div",{className:`rounded-lg border transition-colors ${l?"border-primary border-l-4":"border-border"}`,children:[e.jsxs("div",{className:"flex items-center justify-between p-4",children:[e.jsxs("div",{className:"flex items-center gap-3",children:[e.jsx(ue,{className:`w-5 h-5 ${l?"text-primary":"text-muted-foreground"}`}),e.jsxs("div",{children:[e.jsxs("div",{className:"flex items-center gap-2",children:[e.jsx("p",{className:"font-mono font-medium",children:"gemini"}),e.jsx("span",{className:"text-xs px-1.5 py-0.5 rounded bg-green-500/10 text-green-600 font-medium",children:"FREE"}),t?.geminiCli?.installed?e.jsx("span",{className:"text-xs px-1.5 py-0.5 rounded bg-green-500/10 text-green-600 font-medium",children:"installed"}):e.jsx("span",{className:"text-xs px-1.5 py-0.5 rounded bg-amber-500/10 text-amber-600 font-medium",children:"not installed"})]}),e.jsx("p",{className:"text-sm text-muted-foreground",children:"Google Gemini CLI (1000 req/day free)"})]})]}),e.jsx(B,{checked:l,onCheckedChange:R,disabled:o||!t?.geminiCli?.installed})]}),l&&e.jsx("div",{className:"px-4 pb-4 pt-0",children:e.jsxs("div",{className:"flex items-center gap-2",children:[e.jsx("label",{className:"text-sm text-muted-foreground whitespace-nowrap",children:"Model:"}),e.jsx(L,{value:E,onChange:g=>T(g.target.value),onBlur:G,placeholder:"gemini-2.5-flash",className:"h-8 text-sm font-mono",disabled:o})]})}),!t?.geminiCli?.installed&&!m&&e.jsxs("div",{className:"px-4 pb-4 pt-0 border-t border-border/50",children:[e.jsxs("button",{onClick:()=>y(!v),className:"flex items-center gap-2 text-sm text-amber-600 dark:text-amber-400 hover:underline w-full py-2",children:[v?e.jsx(he,{className:"w-4 h-4"}):e.jsx(pe,{className:"w-4 h-4"}),"How to install Gemini CLI"]}),v&&e.jsxs("div",{className:"mt-2 p-3 rounded-md bg-amber-50 dark:bg-amber-900/20 text-sm",children:[e.jsx("p",{className:"text-amber-700 dark:text-amber-300 mb-2",children:"Install globally (FREE tier available):"}),e.jsx("code",{className:"text-sm bg-amber-100 dark:bg-amber-900/40 px-2 py-1 rounded font-mono block mb-2",children:"npm install -g @google/gemini-cli"}),e.jsxs("a",{href:"https://github.com/google-gemini/gemini-cli",target:"_blank",rel:"noopener noreferrer",className:"text-amber-700 dark:text-amber-300 hover:underline inline-flex items-center gap-1",children:[e.jsx(be,{className:"w-3 h-3"}),"View documentation"]})]})]})]}),e.jsxs("div",{className:`rounded-lg border transition-colors ${i?"border-primary border-l-4":"border-border"}`,children:[e.jsxs("div",{className:"flex items-center justify-between p-4",children:[e.jsxs("div",{className:"flex items-center gap-3",children:[e.jsx(ue,{className:`w-5 h-5 ${i?"text-primary":"text-muted-foreground"}`}),e.jsxs("div",{children:[e.jsxs("div",{className:"flex items-center gap-2",children:[e.jsx("p",{className:"font-mono font-medium",children:"opencode"}),e.jsx("span",{className:"text-xs px-1.5 py-0.5 rounded bg-green-500/10 text-green-600 font-medium",children:"FREE"}),t?.opencodeCli?.installed?e.jsx("span",{className:"text-xs px-1.5 py-0.5 rounded bg-green-500/10 text-green-600 font-medium",children:"installed"}):e.jsx("span",{className:"text-xs px-1.5 py-0.5 rounded bg-amber-500/10 text-amber-600 font-medium",children:"not installed"})]}),e.jsx("p",{className:"text-sm text-muted-foreground",children:"OpenCode (web search via Zen)"})]})]}),e.jsx(B,{checked:i,onCheckedChange:w,disabled:o||!t?.opencodeCli?.installed})]}),i&&e.jsx("div",{className:"px-4 pb-4 pt-0",children:e.jsxs("div",{className:"flex items-center gap-2",children:[e.jsx("label",{className:"text-sm text-muted-foreground whitespace-nowrap",children:"Model:"}),e.jsx(L,{value:A,onChange:g=>c(g.target.value),onBlur:_,placeholder:"opencode/grok-code",className:"h-8 text-sm font-mono",disabled:o})]})}),!t?.opencodeCli?.installed&&!m&&e.jsxs("div",{className:"px-4 pb-4 pt-0 border-t border-border/50",children:[e.jsxs("button",{onClick:()=>O(!N),className:"flex items-center gap-2 text-sm text-purple-600 dark:text-purple-400 hover:underline w-full py-2",children:[N?e.jsx(he,{className:"w-4 h-4"}):e.jsx(pe,{className:"w-4 h-4"}),"How to install OpenCode"]}),N&&e.jsxs("div",{className:"mt-2 p-3 rounded-md bg-purple-50 dark:bg-purple-900/20 text-sm",children:[e.jsx("p",{className:"text-purple-700 dark:text-purple-300 mb-2",children:"Install globally (FREE tier available):"}),e.jsx("code",{className:"text-sm bg-purple-100 dark:bg-purple-900/40 px-2 py-1 rounded font-mono block mb-2",children:"curl -fsSL https://opencode.ai/install | bash"}),e.jsxs("a",{href:"https://github.com/sst/opencode",target:"_blank",rel:"noopener noreferrer",className:"text-purple-700 dark:text-purple-300 hover:underline inline-flex items-center gap-1",children:[e.jsx(be,{className:"w-3 h-3"}),"View documentation"]})]})]})]}),e.jsxs("div",{className:`rounded-lg border transition-colors ${h?"border-primary border-l-4":"border-border"}`,children:[e.jsxs("div",{className:"flex items-center justify-between p-4",children:[e.jsxs("div",{className:"flex items-center gap-3",children:[e.jsx(ue,{className:`w-5 h-5 ${h?"text-primary":"text-muted-foreground"}`}),e.jsxs("div",{children:[e.jsxs("div",{className:"flex items-center gap-2",children:[e.jsx("p",{className:"font-mono font-medium",children:"grok"}),e.jsx("span",{className:"text-xs px-1.5 py-0.5 rounded bg-blue-500/10 text-blue-600 font-medium",children:"GROK_API_KEY"}),t?.grokCli?.installed?e.jsx("span",{className:"text-xs px-1.5 py-0.5 rounded bg-green-500/10 text-green-600 font-medium",children:"installed"}):e.jsx("span",{className:"text-xs px-1.5 py-0.5 rounded bg-amber-500/10 text-amber-600 font-medium",children:"not installed"})]}),e.jsx("p",{className:"text-sm text-muted-foreground",children:"xAI Grok CLI (web + X search)"})]})]}),e.jsx(B,{checked:h,onCheckedChange:P,disabled:o||!t?.grokCli?.installed})]}),!t?.grokCli?.installed&&!m&&e.jsxs("div",{className:"px-4 pb-4 pt-0 border-t border-border/50",children:[e.jsxs("button",{onClick:()=>V(!p),className:"flex items-center gap-2 text-sm text-blue-600 dark:text-blue-400 hover:underline w-full py-2",children:[p?e.jsx(he,{className:"w-4 h-4"}):e.jsx(pe,{className:"w-4 h-4"}),"How to install Grok CLI"]}),p&&e.jsxs("div",{className:"mt-2 p-3 rounded-md bg-blue-50 dark:bg-blue-900/20 text-sm",children:[e.jsx("p",{className:"text-blue-700 dark:text-blue-300 mb-2",children:"Install globally (requires xAI API key):"}),e.jsx("code",{className:"text-sm bg-blue-100 dark:bg-blue-900/40 px-2 py-1 rounded font-mono block mb-2",children:"npm install -g @vibe-kit/grok-cli"}),e.jsxs("a",{href:"https://github.com/superagent-ai/grok-cli",target:"_blank",rel:"noopener noreferrer",className:"text-blue-700 dark:text-blue-300 hover:underline inline-flex items-center gap-1",children:[e.jsx(be,{className:"w-3 h-3"}),"View documentation"]})]})]})]})]})]})}),e.jsx("div",{className:"p-4 border-t bg-background",children:e.jsxs(C,{variant:"outline",size:"sm",onClick:()=>{D(),F()},disabled:z||o,className:"w-full",children:[e.jsx(S,{className:`w-4 h-4 mr-2 ${z?"animate-spin":""}`}),"Refresh"]})})]})}function _s({config:t,loading:m,saving:o,error:u,success:j,newEnvKey:l,newEnvValue:h,setNewEnvKey:i,setNewEnvValue:E,toggleGlobalEnv:A,addEnvVar:v,removeEnvVar:N,fetchGlobalEnvConfig:p,fetchRawConfig:T}){return m?e.jsx("div",{className:"flex-1 flex items-center justify-center",children:e.jsxs("div",{className:"flex items-center gap-3 text-muted-foreground",children:[e.jsx(S,{className:"w-5 h-5 animate-spin"}),e.jsx("span",{children:"Loading..."})]})}):e.jsxs(e.Fragment,{children:[e.jsxs("div",{className:`absolute left-5 right-5 top-20 z-10 transition-all duration-200 ease-out ${u||j?"opacity-100 translate-y-0":"opacity-0 -translate-y-2 pointer-events-none"}`,children:[u&&e.jsxs(fe,{variant:"destructive",className:"py-2 shadow-lg",children:[e.jsx(ve,{className:"h-4 w-4"}),e.jsx(ge,{children:u})]}),j&&e.jsxs("div",{className:"flex items-center gap-2 px-3 py-2 rounded-md border border-green-200 bg-green-50 text-green-700 shadow-lg dark:border-green-900/50 dark:bg-green-900/90 dark:text-green-300",children:[e.jsx(le,{className:"h-4 w-4 shrink-0"}),e.jsx("span",{className:"text-sm font-medium",children:"Saved"})]})]}),e.jsx(je,{className:"flex-1",children:e.jsxs("div",{className:"p-5 space-y-6",children:[e.jsx("p",{className:"text-sm text-muted-foreground",children:"Environment variables injected into all non-Claude subscription profiles (gemini, codex, agy, copilot, etc.)"}),e.jsxs("div",{className:"flex items-center justify-between p-4 rounded-lg bg-muted/50",children:[e.jsxs("div",{children:[e.jsx("p",{className:"font-medium",children:t?.enabled?"Global Env enabled":"Global Env disabled"}),e.jsx("p",{className:"text-sm text-muted-foreground",children:t?.enabled?"Env vars will be injected into third-party profiles":"Env vars will not be injected"})]}),e.jsx(B,{checked:t?.enabled??!0,onCheckedChange:A})]}),e.jsxs("div",{className:"space-y-3",children:[e.jsx("h3",{className:"text-base font-medium",children:"Environment Variables"}),t?.env&&Object.keys(t.env).length>0?e.jsx("div",{className:"space-y-2",children:Object.entries(t.env).map(([c,y])=>e.jsxs("div",{className:"flex items-center gap-2 p-3 rounded-lg border bg-background",children:[e.jsx("code",{className:"flex-1 font-mono text-sm truncate",children:c}),e.jsx("span",{className:"text-muted-foreground",children:"="}),e.jsx("code",{className:"font-mono text-sm px-2 py-1 bg-muted rounded",children:y}),e.jsx(C,{variant:"ghost",size:"sm",onClick:()=>N(c),disabled:o,className:"h-8 w-8 p-0 text-destructive hover:text-destructive hover:bg-destructive/10",children:e.jsx(Ts,{className:"w-4 h-4"})})]},c))}):e.jsx("div",{className:"p-4 rounded-lg border border-dashed text-center text-muted-foreground",children:e.jsx("p",{children:"No environment variables configured"})}),e.jsxs("div",{className:"p-4 rounded-lg border bg-muted/30",children:[e.jsx("h4",{className:"text-sm font-medium mb-3",children:"Add New Variable"}),e.jsxs("div",{className:"flex gap-2",children:[e.jsx(L,{value:l,onChange:c=>i(c.target.value.toUpperCase()),placeholder:"KEY_NAME",className:"flex-1 font-mono text-sm h-9",disabled:o}),e.jsx("span",{className:"flex items-center text-muted-foreground",children:"="}),e.jsx(L,{value:h,onChange:c=>E(c.target.value),placeholder:"value",className:"flex-1 font-mono text-sm h-9",disabled:o}),e.jsxs(C,{size:"sm",onClick:v,disabled:o||!l.trim(),className:"h-9",children:[e.jsx(Is,{className:"w-4 h-4 mr-1"}),"Add"]})]})]}),e.jsxs("div",{className:"p-4 rounded-lg border bg-muted/30",children:[e.jsx("h4",{className:"text-sm font-medium mb-3",children:"Quick Add Common Variables"}),e.jsxs("div",{className:"flex flex-wrap gap-2",children:[[{key:"DISABLE_BUG_COMMAND",value:"1"},{key:"DISABLE_ERROR_REPORTING",value:"1"},{key:"DISABLE_TELEMETRY",value:"1"}].map(({key:c,value:y})=>!t?.env?.[c]&&e.jsxs(C,{variant:"outline",size:"sm",onClick:()=>{i(c),E(y)},className:"text-xs font-mono",children:["+ ",c]},c)),t?.env&&["DISABLE_BUG_COMMAND","DISABLE_ERROR_REPORTING","DISABLE_TELEMETRY"].every(c=>t.env[c])&&e.jsx("span",{className:"text-sm text-muted-foreground",children:"All common variables are configured"})]})]})]})]})}),e.jsx("div",{className:"p-4 border-t bg-background",children:e.jsxs(C,{variant:"outline",size:"sm",onClick:()=>{p(),T()},disabled:m||o,className:"w-full",children:[e.jsx(S,{className:`w-4 h-4 mr-2 ${m?"animate-spin":""}`}),"Refresh"]})})]})}function Fs({config:t,loading:m,saving:o,error:u,success:j,testResult:l,testing:h,saveCliproxyServerConfig:i,handleTestConnection:E,fetchCliproxyServerConfig:A,fetchRawConfig:v,editedHost:N,setEditedHost:p,editedPort:T,setEditedPort:c,editedAuthToken:y,setEditedAuthToken:O,editedLocalPort:V,setEditedLocalPort:R}){const P={enabled:!1,host:"",port:void 0,protocol:"http",auth_token:""},w={enabled:!0,auto_start:!0},G={port:8317,auto_start:!0},_=n=>n==="https"?443:8317,q=t?.remote.host??"",D=t?.remote.port!==void 0?t.remote.port.toString():"",F=t?.remote.auth_token??"",z=(t?.local.port??8317).toString(),g=N??q,H=T??D,Y=y??F,Q=V??z;if(m)return e.jsx("div",{className:"flex-1 flex items-center justify-center",children:e.jsxs("div",{className:"flex items-center gap-3 text-muted-foreground",children:[e.jsx(S,{className:"w-5 h-5 animate-spin"}),e.jsx("span",{children:"Loading..."})]})});const k=t?.remote.enabled??!1,I=t?.remote??P,X=t?.fallback??w,Z=t?.local??G,b=()=>{const n=N??g;n!==t?.remote.host&&i({remote:{...I,host:n}}),p(null)},W=()=>{const n=T??H,M=n===""?void 0:parseInt(n,10),se=M&&!isNaN(M)&&M>0?M:void 0;se!==t?.remote.port&&i({remote:{...I,port:se}}),c(null)},ne=()=>{const n=y??Y;n!==t?.remote.auth_token&&i({remote:{...I,auth_token:n}}),O(null)},ee=()=>{const n=parseInt(V??Q,10);!isNaN(n)&&n!==t?.local.port&&i({local:{...Z,port:n}}),R(null)};return e.jsxs(e.Fragment,{children:[e.jsxs("div",{className:`absolute left-5 right-5 top-20 z-10 transition-all duration-200 ease-out ${u||j?"opacity-100 translate-y-0":"opacity-0 -translate-y-2 pointer-events-none"}`,children:[u&&e.jsxs(fe,{variant:"destructive",className:"py-2 shadow-lg",children:[e.jsx(ve,{className:"h-4 w-4"}),e.jsx(ge,{children:u})]}),j&&e.jsxs("div",{className:"flex items-center gap-2 px-3 py-2 rounded-md border border-green-200 bg-green-50 text-green-700 shadow-lg dark:border-green-900/50 dark:bg-green-900/90 dark:text-green-300",children:[e.jsx(le,{className:"h-4 w-4 shrink-0"}),e.jsx("span",{className:"text-sm font-medium",children:"Saved"})]})]}),e.jsx(je,{className:"flex-1",children:e.jsxs("div",{className:"p-5 space-y-6",children:[e.jsx("p",{className:"text-sm text-muted-foreground",children:"Configure local or remote CLIProxyAPI connection for proxy-based profiles"}),e.jsxs("div",{className:"space-y-3",children:[e.jsx("h3",{className:"text-base font-medium",children:"Connection Mode"}),e.jsxs("div",{className:"grid grid-cols-2 gap-3",children:[e.jsxs("button",{onClick:()=>i({remote:{...I,enabled:!1}}),disabled:o,className:`p-4 rounded-lg border-2 text-left transition-all ${k?"border-border hover:border-muted-foreground/50":"border-primary bg-primary/5"}`,children:[e.jsxs("div",{className:"flex items-center gap-3 mb-2",children:[e.jsx(Ls,{className:`w-5 h-5 ${k?"text-muted-foreground":"text-primary"}`}),e.jsx("span",{className:"font-medium",children:"Local"})]}),e.jsx("p",{className:"text-xs text-muted-foreground",children:"Run CLIProxyAPI binary on this machine"})]}),e.jsxs("button",{onClick:()=>i({remote:{...I,enabled:!0}}),disabled:o,className:`p-4 rounded-lg border-2 text-left transition-all ${k?"border-primary bg-primary/5":"border-border hover:border-muted-foreground/50"}`,children:[e.jsxs("div",{className:"flex items-center gap-3 mb-2",children:[e.jsx(Me,{className:`w-5 h-5 ${k?"text-primary":"text-muted-foreground"}`}),e.jsx("span",{className:"font-medium",children:"Remote"})]}),e.jsx("p",{className:"text-xs text-muted-foreground",children:"Connect to a remote CLIProxyAPI server"})]})]})]}),k&&e.jsxs("div",{className:"space-y-4 p-4 rounded-lg border bg-muted/30",children:[e.jsxs("h4",{className:"text-sm font-medium flex items-center gap-2",children:[e.jsx(Me,{className:"w-4 h-4"}),"Remote Server Configuration"]}),e.jsxs("div",{className:"space-y-1",children:[e.jsx("label",{className:"text-sm text-muted-foreground",children:"Host"}),e.jsx(L,{value:g,onChange:n=>p(n.target.value),onBlur:b,placeholder:"192.168.1.100 or proxy.example.com",className:"font-mono",disabled:o})]}),e.jsxs("div",{className:"grid grid-cols-2 gap-3",children:[e.jsxs("div",{className:"space-y-1",children:[e.jsxs("label",{className:"text-sm text-muted-foreground",children:["Port"," ",e.jsxs("span",{className:"text-xs opacity-70",children:["(default: ",_(t?.remote.protocol||"http"),")"]})]}),e.jsx(L,{type:"text",inputMode:"numeric",value:H,onChange:n=>c(n.target.value.replace(/\D/g,"")),onBlur:W,placeholder:`Leave empty for ${_(t?.remote.protocol||"http")}`,className:"font-mono",disabled:o})]}),e.jsxs("div",{className:"space-y-1",children:[e.jsx("label",{className:"text-sm text-muted-foreground",children:"Protocol"}),e.jsxs(gs,{value:t?.remote.protocol||"http",onValueChange:n=>i({remote:{...I,protocol:n}}),disabled:o,children:[e.jsx(js,{children:e.jsx(vs,{})}),e.jsxs(Ns,{children:[e.jsx(Fe,{value:"http",children:"HTTP"}),e.jsx(Fe,{value:"https",children:"HTTPS"})]})]})]})]}),e.jsxs("div",{className:"space-y-1",children:[e.jsx("label",{className:"text-sm text-muted-foreground",children:"Auth Token (optional)"}),e.jsx(L,{type:"password",value:Y,onChange:n=>O(n.target.value),onBlur:ne,placeholder:"Bearer token for authentication",className:"font-mono",disabled:o})]}),e.jsxs("div",{className:"space-y-3 pt-2",children:[e.jsx(C,{onClick:()=>E({host:g,port:H,protocol:t?.remote.protocol||"http",authToken:Y}),disabled:h||!g,variant:"outline",className:"w-full",children:h?e.jsxs(e.Fragment,{children:[e.jsx(S,{className:"w-4 h-4 mr-2 animate-spin"}),"Testing..."]}):e.jsxs(e.Fragment,{children:[e.jsx(As,{className:"w-4 h-4 mr-2"}),"Test Connection"]})}),l&&e.jsx("div",{className:`p-3 rounded-md ${l.reachable?"bg-green-50 border border-green-200 dark:bg-green-900/20 dark:border-green-900/50":"bg-red-50 border border-red-200 dark:bg-red-900/20 dark:border-red-900/50"}`,children:e.jsx("div",{className:"flex items-center gap-2",children:l.reachable?e.jsxs(e.Fragment,{children:[e.jsx(le,{className:"w-4 h-4 text-green-600 dark:text-green-400"}),e.jsxs("span",{className:"text-sm font-medium text-green-700 dark:text-green-300",children:["Connected (",l.latencyMs,"ms)"]})]}):e.jsxs(e.Fragment,{children:[e.jsx(Rs,{className:"w-4 h-4 text-red-600 dark:text-red-400"}),e.jsx("span",{className:"text-sm font-medium text-red-700 dark:text-red-300",children:l.error||"Connection failed"})]})})})]})]}),e.jsxs("div",{className:"space-y-3",children:[e.jsx("h3",{className:"text-base font-medium",children:"Fallback Settings"}),e.jsxs("div",{className:"space-y-3 p-4 rounded-lg border bg-muted/30",children:[e.jsxs("div",{className:"flex items-center justify-between",children:[e.jsxs("div",{children:[e.jsx("p",{className:"font-medium text-sm",children:"Enable fallback to local"}),e.jsx("p",{className:"text-xs text-muted-foreground",children:"Use local proxy if remote is unreachable"})]}),e.jsx(B,{checked:t?.fallback.enabled??!0,onCheckedChange:n=>i({fallback:{...X,enabled:n}}),disabled:o||!k})]}),e.jsxs("div",{className:"flex items-center justify-between",children:[e.jsxs("div",{children:[e.jsx("p",{className:"font-medium text-sm",children:"Auto-start local proxy"}),e.jsx("p",{className:"text-xs text-muted-foreground",children:"Automatically start local proxy on fallback"})]}),e.jsx(B,{checked:t?.fallback.auto_start??!1,onCheckedChange:n=>i({fallback:{...X,auto_start:n}}),disabled:o||!k||!t?.fallback.enabled})]})]})]}),!k&&e.jsxs("div",{className:"space-y-3",children:[e.jsx("h3",{className:"text-base font-medium",children:"Local Proxy"}),e.jsxs("div",{className:"space-y-3 p-4 rounded-lg border bg-muted/30",children:[e.jsxs("div",{className:"space-y-1",children:[e.jsx("label",{className:"text-sm text-muted-foreground",children:"Port"}),e.jsx(L,{type:"number",value:Q,onChange:n=>R(n.target.value),onBlur:ee,placeholder:"8317",className:"font-mono max-w-32",disabled:o})]}),e.jsxs("div",{className:"flex items-center justify-between",children:[e.jsxs("div",{children:[e.jsx("p",{className:"font-medium text-sm",children:"Auto-start"}),e.jsx("p",{className:"text-xs text-muted-foreground",children:"Start local proxy automatically when needed"})]}),e.jsx(B,{checked:t?.local.auto_start??!0,onCheckedChange:n=>i({local:{...Z,auto_start:n}}),disabled:o})]})]})]})]})}),e.jsx("div",{className:"p-4 border-t bg-background",children:e.jsxs(C,{variant:"outline",size:"sm",onClick:()=>{A(),v()},disabled:m||o,className:"w-full",children:[e.jsx(S,{className:`w-4 h-4 mr-2 ${m?"animate-spin":""}`}),"Refresh"]})})]})}export{Ys as SettingsPage};
@@ -1 +1 @@
1
- import{j as s}from"./radix-ui-CV3R9pD6.js";import{r as d}from"./react-vendor-FspHSO0w.js";import{C as l,a as m}from"./card-ByK9DlE_.js";import{as as c,at as x,aq as u,au as h,ar as p,B as g}from"./index-DDxKFig1.js";import{p as j,N as f,au as N,u as b}from"./icons-DvvDkxaF.js";import"./tanstack-Df9bCj5R.js";import"./notifications-B2Pz7lik.js";import"./utils-CzKF5WmX.js";import"./form-utils-DP6ILe7Z.js";import"./code-highlight-BoHWVYut.js";function q(){const[t,r]=d.useState("commands"),{data:e}=c(),{data:n,isLoading:i}=x(t),o=[{id:"commands",label:"Commands",icon:j,count:e?.commands??0},{id:"skills",label:"Skills",icon:f,count:e?.skills??0},{id:"agents",label:"Agents",icon:N,count:e?.agents??0}];return s.jsxs("div",{className:"p-6 max-w-6xl mx-auto space-y-8",children:[s.jsxs("div",{children:[s.jsx("h1",{className:"text-2xl font-bold",children:"Shared Data"}),s.jsx("p",{className:"text-muted-foreground",children:"Commands, skills, and agents shared across Claude instances"})]}),e&&!e.symlinkStatus.valid&&s.jsxs(u,{variant:"warning",children:[s.jsx(b,{className:"h-4 w-4"}),s.jsx(h,{children:"Configuration Required"}),s.jsxs(p,{children:[e.symlinkStatus.message,". Run `ccs sync` to configure."]})]}),s.jsx("div",{className:"flex gap-2 border-b pb-2",children:o.map(a=>s.jsxs(g,{variant:t===a.id?"default":"ghost",size:"sm",onClick:()=>r(a.id),className:"flex items-center gap-2",children:[s.jsx(a.icon,{className:"w-4 h-4"}),a.label," (",a.count,")"]},a.id))}),s.jsx("div",{className:"mt-4",children:i?s.jsx("div",{className:"text-muted-foreground",children:"Loading..."}):n?.items.length===0?s.jsxs("div",{className:"text-muted-foreground",children:["No ",t," found"]}):s.jsx("div",{className:"grid gap-3",children:n?.items.map(a=>s.jsx(l,{children:s.jsxs(m,{children:[s.jsx("div",{className:"font-medium",children:a.name}),s.jsx("p",{className:"text-sm text-muted-foreground mt-1",children:a.description}),s.jsx("p",{className:"text-xs text-muted-foreground mt-2 font-mono truncate",children:a.path})]})},a.name))})})]})}export{q as SharedPage};
1
+ import{j as s}from"./radix-ui-CV3R9pD6.js";import{r as d}from"./react-vendor-FspHSO0w.js";import{C as l,a as m}from"./card-BE-HBKyn.js";import{as as c,at as x,aq as u,au as h,ar as p,B as g}from"./index-Hai6xZvK.js";import{p as j,N as f,au as N,u as b}from"./icons-DvvDkxaF.js";import"./tanstack-Df9bCj5R.js";import"./notifications-B2Pz7lik.js";import"./utils-CzKF5WmX.js";import"./form-utils-DP6ILe7Z.js";import"./code-highlight-BoHWVYut.js";function q(){const[t,r]=d.useState("commands"),{data:e}=c(),{data:n,isLoading:i}=x(t),o=[{id:"commands",label:"Commands",icon:j,count:e?.commands??0},{id:"skills",label:"Skills",icon:f,count:e?.skills??0},{id:"agents",label:"Agents",icon:N,count:e?.agents??0}];return s.jsxs("div",{className:"p-6 max-w-6xl mx-auto space-y-8",children:[s.jsxs("div",{children:[s.jsx("h1",{className:"text-2xl font-bold",children:"Shared Data"}),s.jsx("p",{className:"text-muted-foreground",children:"Commands, skills, and agents shared across Claude instances"})]}),e&&!e.symlinkStatus.valid&&s.jsxs(u,{variant:"warning",children:[s.jsx(b,{className:"h-4 w-4"}),s.jsx(h,{children:"Configuration Required"}),s.jsxs(p,{children:[e.symlinkStatus.message,". Run `ccs sync` to configure."]})]}),s.jsx("div",{className:"flex gap-2 border-b pb-2",children:o.map(a=>s.jsxs(g,{variant:t===a.id?"default":"ghost",size:"sm",onClick:()=>r(a.id),className:"flex items-center gap-2",children:[s.jsx(a.icon,{className:"w-4 h-4"}),a.label," (",a.count,")"]},a.id))}),s.jsx("div",{className:"mt-4",children:i?s.jsx("div",{className:"text-muted-foreground",children:"Loading..."}):n?.items.length===0?s.jsxs("div",{className:"text-muted-foreground",children:["No ",t," found"]}):s.jsx("div",{className:"grid gap-3",children:n?.items.map(a=>s.jsx(l,{children:s.jsxs(m,{children:[s.jsx("div",{className:"font-medium",children:a.name}),s.jsx("p",{className:"text-sm text-muted-foreground mt-1",children:a.description}),s.jsx("p",{className:"text-xs text-muted-foreground mt-2 font-mono truncate",children:a.path})]})},a.name))})})]})}export{q as SharedPage};
@@ -1 +1 @@
1
- import{j as a,a8 as s,a9 as n}from"./radix-ui-CV3R9pD6.js";import"./react-vendor-FspHSO0w.js";import{c as e}from"./index-DDxKFig1.js";function c({className:t,...r}){return a.jsx(s,{"data-slot":"switch",className:e("peer data-[state=checked]:bg-primary data-[state=unchecked]:bg-input focus-visible:border-ring focus-visible:ring-ring/50 dark:data-[state=unchecked]:bg-input/80 inline-flex h-[1.15rem] w-8 shrink-0 items-center rounded-full border border-transparent shadow-xs transition-all outline-none focus-visible:ring-[3px] disabled:cursor-not-allowed disabled:opacity-50",t),...r,children:a.jsx(n,{"data-slot":"switch-thumb",className:e("bg-background dark:data-[state=unchecked]:bg-foreground dark:data-[state=checked]:bg-primary-foreground pointer-events-none block size-4 rounded-full ring-0 transition-transform data-[state=checked]:translate-x-[calc(100%-2px)] data-[state=unchecked]:translate-x-0")})})}export{c as S};
1
+ import{j as a,a8 as s,a9 as n}from"./radix-ui-CV3R9pD6.js";import"./react-vendor-FspHSO0w.js";import{c as e}from"./index-Hai6xZvK.js";function c({className:t,...r}){return a.jsx(s,{"data-slot":"switch",className:e("peer data-[state=checked]:bg-primary data-[state=unchecked]:bg-input focus-visible:border-ring focus-visible:ring-ring/50 dark:data-[state=unchecked]:bg-input/80 inline-flex h-[1.15rem] w-8 shrink-0 items-center rounded-full border border-transparent shadow-xs transition-all outline-none focus-visible:ring-[3px] disabled:cursor-not-allowed disabled:opacity-50",t),...r,children:a.jsx(n,{"data-slot":"switch-thumb",className:e("bg-background dark:data-[state=unchecked]:bg-foreground dark:data-[state=checked]:bg-primary-foreground pointer-events-none block size-4 rounded-full ring-0 transition-transform data-[state=checked]:translate-x-[calc(100%-2px)] data-[state=unchecked]:translate-x-0")})})}export{c as S};
@@ -24,7 +24,7 @@
24
24
  href="https://fonts.googleapis.com/css2?family=IBM+Plex+Sans:wght@300;400;500;600;700&family=JetBrains+Mono:wght@400;500;600;700&display=swap"
25
25
  rel="stylesheet"
26
26
  />
27
- <script type="module" crossorigin src="/assets/index-DDxKFig1.js"></script>
27
+ <script type="module" crossorigin src="/assets/index-Hai6xZvK.js"></script>
28
28
  <link rel="modulepreload" crossorigin href="/assets/react-vendor-FspHSO0w.js">
29
29
  <link rel="modulepreload" crossorigin href="/assets/radix-ui-CV3R9pD6.js">
30
30
  <link rel="modulepreload" crossorigin href="/assets/tanstack-Df9bCj5R.js">
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@kaitranntt/ccs",
3
- "version": "7.0.0-dev.2",
3
+ "version": "7.0.0-dev.3",
4
4
  "description": "Claude Code Switch - Instant profile switching between Claude Sonnet 4.5 and GLM 4.6",
5
5
  "keywords": [
6
6
  "cli",
@@ -1 +0,0 @@
1
- import{j as e}from"./radix-ui-CV3R9pD6.js";import{r as o}from"./react-vendor-FspHSO0w.js";import{e as _,c as k,T as ge,k as je,l as Ne,B as g,I as y,i as M,L as T,m as R,n as ee,o as ve,s as be,p as we,q as Ce,S as q,r as P,t as H,v as se,w as ye,x as Oe,y as te,z as ae,A as ne,D as Ae,E as Ee,F as G,G as V,R as ke,H as K,J as Te,K as _e,M as Se,N as Pe}from"./index-DDxKFig1.js";import{u as Re,a as Le,b as Me}from"./tanstack-Df9bCj5R.js";import{C as re,S as Y}from"./confirm-dialog-DQeTgOVm.js";import{t as z}from"./notifications-B2Pz7lik.js";import{a2 as D,a5 as le,L as J,a6 as De,E as Ie,d as Ue,J as L,I as Fe,a7 as ie,N as $,b as ce,a8 as He,z as ze,a9 as Ke,D as oe,X as Je,Z as de,aa as $e,$ as Be,ab as xe,ac as Qe,k as me}from"./icons-DvvDkxaF.js";import{C as qe,b as Ge,c as Ve,d as Ye,a as We}from"./card-ByK9DlE_.js";import"./utils-CzKF5WmX.js";import"./form-utils-DP6ILe7Z.js";import"./code-highlight-BoHWVYut.js";function Xe({className:s,showTooltip:a=!0}){const n=e.jsxs(_,{variant:"outline",className:k("bg-accent/10 border-accent/30 text-accent","dark:bg-accent/20 dark:border-accent/40 dark:text-accent-foreground",s),children:[e.jsx("img",{src:"/icons/openrouter.svg",alt:"OpenRouter",className:"mr-1 h-3 w-3"}),"OpenRouter"]});return a?e.jsxs(ge,{children:[e.jsx(je,{asChild:!0,children:n}),e.jsx(Ne,{children:e.jsx("p",{children:"Access 349+ models via OpenRouter"})})]}):n}function W(s){return[/^ANTHROPIC_AUTH_TOKEN$/,/_API_KEY$/,/_AUTH_TOKEN$/,/^API_KEY$/,/^AUTH_TOKEN$/,/_SECRET$/,/^SECRET$/].some(n=>n.test(s))}function ue(s){return s?.env?(s.env.ANTHROPIC_BASE_URL||"").toLowerCase().includes("openrouter.ai"):!1}function Ze(s){return{opus:s.ANTHROPIC_DEFAULT_OPUS_MODEL||void 0,sonnet:s.ANTHROPIC_DEFAULT_SONNET_MODEL||void 0,haiku:s.ANTHROPIC_DEFAULT_HAIKU_MODEL||void 0}}function es(s,a){const n={...s};return a.opus?n.ANTHROPIC_DEFAULT_OPUS_MODEL=a.opus:delete n.ANTHROPIC_DEFAULT_OPUS_MODEL,a.sonnet?n.ANTHROPIC_DEFAULT_SONNET_MODEL=a.sonnet:delete n.ANTHROPIC_DEFAULT_SONNET_MODEL,a.haiku?n.ANTHROPIC_DEFAULT_HAIKU_MODEL=a.haiku:delete n.ANTHROPIC_DEFAULT_HAIKU_MODEL,n}function ss({profileName:s,data:a,settings:n,isLoading:i,isSaving:m,hasChanges:h,isRawJsonValid:c,onRefresh:r,onDelete:d,onSave:x}){return e.jsxs("div",{className:"px-6 py-4 border-b bg-background flex items-center justify-between shrink-0",children:[e.jsxs("div",{children:[e.jsxs("div",{className:"flex items-center gap-2",children:[e.jsx("h2",{className:"text-lg font-semibold",children:s}),a?.path&&e.jsx(_,{variant:"outline",className:"text-xs",children:a.path.replace(/^.*\//,"")}),ue(n)&&e.jsx(Xe,{className:"ml-1"})]}),a&&e.jsxs("p",{className:"text-xs text-muted-foreground mt-0.5",children:["Last modified: ",new Date(a.mtime).toLocaleString()]})]}),e.jsxs("div",{className:"flex items-center gap-2",children:[e.jsx(g,{variant:"ghost",size:"sm",onClick:r,disabled:i,children:e.jsx(D,{className:`w-4 h-4 ${i?"animate-spin":""}`})}),d&&e.jsx(g,{variant:"ghost",size:"sm",onClick:d,children:e.jsx(le,{className:"w-4 h-4 text-destructive"})}),e.jsx(g,{size:"sm",onClick:x,disabled:m||!h||!c,children:m?e.jsxs(e.Fragment,{children:[e.jsx(J,{className:"w-4 h-4 mr-1 animate-spin"}),"Saving..."]}):e.jsxs(e.Fragment,{children:[e.jsx(De,{className:"w-4 h-4 mr-1"}),"Save"]})})]})]})}function he({label:s,...a}){const[n,i]=o.useState(!1);return e.jsxs("div",{className:"space-y-1",children:[s&&e.jsx("label",{className:"text-sm font-medium",children:s}),e.jsxs("div",{className:"relative",children:[e.jsx(y,{type:n?"text":"password",className:"pr-10 font-mono",...a}),e.jsx(g,{type:"button",variant:"ghost",size:"sm",className:"absolute right-0 top-0 h-full px-3",onClick:()=>i(!n),tabIndex:-1,children:n?e.jsx(Ie,{className:"w-4 h-4"}):e.jsx(Ue,{className:"w-4 h-4"})})]})]})}function ts({currentSettings:s,newEnvKey:a,newEnvValue:n,onNewEnvKeyChange:i,onNewEnvValueChange:m,onEnvValueChange:h,onAddEnvVar:c}){return e.jsxs(e.Fragment,{children:[e.jsx(M,{className:"flex-1",children:e.jsx("div",{className:"p-4 space-y-4",children:s?.env&&Object.keys(s.env).length>0?e.jsx(e.Fragment,{children:Object.entries(s.env).map(([r,d])=>e.jsxs("div",{className:"space-y-1.5",children:[e.jsxs(T,{className:"text-xs font-medium flex items-center gap-2 text-muted-foreground",children:[r,W(r)&&e.jsx(_,{variant:"secondary",className:"text-[10px] px-1 py-0 h-4",children:"sensitive"})]}),W(r)?e.jsx(he,{value:d,onChange:x=>h(r,x.target.value),className:"font-mono text-sm h-8"}):e.jsx(y,{value:d,onChange:x=>h(r,x.target.value),className:"font-mono text-sm h-8"})]},r))}):e.jsxs("div",{className:"py-8 text-center text-muted-foreground bg-muted/30 rounded-lg border border-dashed text-sm",children:[e.jsx("p",{children:"No environment variables configured."}),e.jsx("p",{className:"text-xs mt-1 opacity-70",children:"Add variables using the input below or edit the JSON directly."})]})})}),e.jsxs("div",{className:"p-4 border-t bg-background shrink-0",children:[e.jsx(T,{className:"text-xs font-medium text-muted-foreground",children:"Add Environment Variable"}),e.jsxs("div",{className:"flex gap-2 mt-2",children:[e.jsx(y,{placeholder:"VARIABLE_NAME",value:a,onChange:r=>i(r.target.value.toUpperCase()),className:"font-mono text-sm h-8 w-2/5",onKeyDown:r=>r.key==="Enter"&&a.trim()&&c()}),e.jsx(y,{placeholder:"value",value:n,onChange:r=>m(r.target.value),className:"font-mono text-sm h-8 flex-1",onKeyDown:r=>r.key==="Enter"&&a.trim()&&c()}),e.jsx(g,{variant:"outline",size:"sm",className:"h-8",onClick:c,disabled:!a.trim(),children:e.jsx(L,{className:"w-4 h-4"})})]})]})]})}function as({profileName:s,data:a}){return e.jsx(M,{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(Fe,{className:"w-4 h-4"}),"Profile Information"]}),e.jsx("div",{className:"space-y-3 bg-card rounded-lg border p-4 shadow-sm",children:a&&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:"Profile Name"}),e.jsx("span",{className:"font-mono",children:a.profile})]}),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:a.path}),e.jsx(R,{value:a.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(a.mtime).toLocaleString()})]})]})})]}),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.jsxs("div",{children:[e.jsx(T,{className:"text-xs text-muted-foreground",children:"Run with profile"}),e.jsxs("div",{className:"mt-1 flex gap-2",children:[e.jsxs("code",{className:"flex-1 px-2 py-1.5 bg-muted rounded text-xs font-mono truncate",children:["ccs ",s,' "prompt"']}),e.jsx(R,{value:`ccs ${s} "prompt"`,size:"icon",className:"h-6 w-6"})]})]}),e.jsxs("div",{children:[e.jsx(T,{className:"text-xs text-muted-foreground",children:"Set as default"}),e.jsxs("div",{className:"mt-1 flex gap-2",children:[e.jsxs("code",{className:"flex-1 px-2 py-1.5 bg-muted rounded text-xs font-mono truncate",children:["ccs default ",s]}),e.jsx(R,{value:`ccs default ${s}`,size:"icon",className:"h-6 w-6"})]})]})]})]})]})})}function ns({value:s,onChange:a,placeholder:n="Search models...",className:i}){const[m,h]=o.useState(""),[c,r]=o.useState(null),{models:d,isLoading:x,isError:j,isFetching:O}=ee(),A=ve(),f=o.useMemo(()=>be(d,m,{category:c??void 0}),[d,m,c]),b=o.useMemo(()=>we(d,2),[d]),v=!m.trim()&&!c,w=o.useMemo(()=>{const l={anthropic:[],openai:[],google:[],meta:[],mistral:[],opensource:[],other:[]};f.forEach(t=>{l[t.category].push(t)});for(const t of Object.keys(l))l[t]=Ce(l[t]);return l},[f]),p=o.useCallback(()=>{A()},[A]),N=d.find(l=>l.id===s);return x&&d.length===0?e.jsxs("div",{className:k("space-y-2",i),children:[e.jsx(q,{className:"h-10 w-full"}),e.jsx(q,{className:"h-32 w-full"})]}):e.jsxs("div",{className:k("space-y-2 w-full min-w-0 overflow-hidden",i),children:[e.jsxs("div",{className:"flex gap-2",children:[e.jsxs("div",{className:"relative flex-1",children:[e.jsx(ie,{className:"text-muted-foreground absolute left-3 top-1/2 h-4 w-4 -translate-y-1/2"}),e.jsx(y,{value:m,onChange:l=>h(l.target.value),placeholder:n,className:"pl-9"})]}),e.jsx(g,{variant:"outline",size:"icon",onClick:p,disabled:O,title:"Refresh models",children:O?e.jsx(J,{className:"h-4 w-4 animate-spin"}):e.jsx(D,{className:"h-4 w-4"})})]}),e.jsxs("div",{className:"flex flex-wrap gap-1",children:[e.jsxs(_,{variant:c===null?"default":"outline",className:"cursor-pointer",onClick:()=>r(null),children:["All (",d.length,")"]}),Object.keys(P).map(l=>{const t=w[l].length;return t===0?null:e.jsxs(_,{variant:c===l?"default":"outline",className:"cursor-pointer",onClick:()=>r(l),children:[P[l]," (",t,")"]},l)})]}),N&&e.jsxs("div",{className:"bg-muted rounded-md p-2 text-sm",children:[e.jsx("span",{className:"font-medium",children:N.name}),e.jsxs("span",{className:"text-muted-foreground ml-2",children:[H(N.pricing)," |"," ",se(N.context_length)]})]}),e.jsx(M,{className:"h-72 w-full rounded-md border",children:j?e.jsxs("div",{className:"text-destructive p-4 text-center",children:["Failed to load models."," ",e.jsx(g,{variant:"link",onClick:p,children:"Retry"})]}):f.length===0?e.jsxs("div",{className:"text-muted-foreground p-4 text-center",children:['No models found matching "',m,'"']}):e.jsxs("div",{className:"space-y-6 p-3",children:[v&&b.length>0&&e.jsxs("div",{children:[e.jsxs("div",{className:"text-muted-foreground bg-background sticky top-0 mb-2 flex items-center gap-1.5 py-1.5 text-xs font-semibold border-b pb-2",children:[e.jsx($,{className:"h-3 w-3 text-accent"}),e.jsx("span",{children:"Newest Models"})]}),e.jsx("div",{className:"space-y-1",children:b.map(l=>e.jsx(X,{model:l,isSelected:l.id===s,onClick:()=>a(l.id),showAge:!0},l.id))})]}),Object.keys(P).map(l=>{const t=w[l];return t.length===0?null:e.jsxs("div",{children:[e.jsx("div",{className:"text-muted-foreground bg-background sticky top-0 mb-2 py-1.5 text-xs font-semibold border-b pb-2",children:P[l]}),e.jsx("div",{className:"space-y-1",children:t.map(C=>e.jsx(X,{model:C,isSelected:C.id===s,onClick:()=>a(C.id)},C.id))})]},l)})]})})]})}function X({model:s,isSelected:a,onClick:n,showAge:i=!1}){return e.jsxs("button",{type:"button",onClick:n,className:k("group flex w-full items-center gap-2 rounded-md px-3 py-2 text-left text-sm transition-colors","hover:bg-accent hover:text-accent-foreground",a&&"bg-accent text-accent-foreground"),children:[e.jsx("span",{className:"flex-1 min-w-0 truncate font-medium",children:s.name}),e.jsxs("span",{className:k("flex shrink-0 items-center gap-1 text-xs whitespace-nowrap",a?"text-accent-foreground/80":"text-muted-foreground group-hover:text-accent-foreground/80"),children:[i&&s.created&&e.jsx(_,{variant:"outline",className:k("text-[10px] px-1",a?"border-accent-foreground/30 text-accent-foreground/80":"text-accent border-accent/30 group-hover:text-accent-foreground/80 group-hover:border-accent-foreground/30"),children:ye(s.created)}),s.isFree?e.jsx(_,{variant:"secondary",className:k("text-[10px] px-1",a?"bg-accent-foreground/20 text-accent-foreground":"group-hover:bg-accent-foreground/20 group-hover:text-accent-foreground"),children:"Free"}):s.isExacto?e.jsxs(e.Fragment,{children:[e.jsx(_,{variant:"outline",className:k("text-[10px] px-1 border-emerald-500/50 text-emerald-600",a?"border-accent-foreground/30 text-accent-foreground/80":"group-hover:border-accent-foreground/30 group-hover:text-accent-foreground/80"),children:"Exacto"}),e.jsx("span",{className:"tabular-nums",children:H(s.pricing)})]}):e.jsx("span",{className:"tabular-nums",children:H(s.pricing)}),e.jsx("span",{className:"tabular-nums",children:se(s.context_length)})]})]})}function rs({selectedModel:s,value:a,onChange:n,className:i}){const{models:m}=ee(),h=o.useMemo(()=>s?Oe(s,m):{},[s,m]),c=()=>{n(h)},r=(x,j)=>{n({...a,[x]:j||void 0})},d=s&&Object.keys(h).length>0;return e.jsxs(te,{className:k("group",i),children:[e.jsxs(ae,{className:"flex items-center gap-2 text-sm font-medium hover:underline",children:[e.jsx(ce,{className:"h-4 w-4 transition-transform group-data-[state=open]:rotate-90"}),"Model Tier Mapping",e.jsx("span",{className:"text-muted-foreground font-normal",children:"(Advanced)"})]}),e.jsxs(ne,{className:"space-y-3 pt-3",children:[e.jsx("p",{className:"text-muted-foreground text-sm",children:"Configure different models for Claude Code's opus/sonnet/haiku tiers."}),d&&e.jsxs(g,{type:"button",variant:"outline",size:"sm",onClick:c,children:[e.jsx(He,{className:"mr-1 h-4 w-4"}),"Auto-suggest based on ",s?.split("/")[0]]}),e.jsxs("div",{className:"grid gap-3",children:[e.jsxs("div",{className:"grid grid-cols-[80px_1fr] items-center gap-2",children:[e.jsx(T,{htmlFor:"tier-opus",className:"text-right",children:"Opus"}),e.jsx(y,{id:"tier-opus",value:a.opus??"",onChange:x=>r("opus",x.target.value),placeholder:"e.g., anthropic/claude-opus-4"})]}),e.jsxs("div",{className:"grid grid-cols-[80px_1fr] items-center gap-2",children:[e.jsx(T,{htmlFor:"tier-sonnet",className:"text-right",children:"Sonnet"}),e.jsx(y,{id:"tier-sonnet",value:a.sonnet??"",onChange:x=>r("sonnet",x.target.value),placeholder:"e.g., anthropic/claude-sonnet-4"})]}),e.jsxs("div",{className:"grid grid-cols-[80px_1fr] items-center gap-2",children:[e.jsx(T,{htmlFor:"tier-haiku",className:"text-right",children:"Haiku"}),e.jsx(y,{id:"tier-haiku",value:a.haiku??"",onChange:x=>r("haiku",x.target.value),placeholder:"e.g., anthropic/claude-3.5-haiku"})]})]}),e.jsx("p",{className:"text-muted-foreground text-xs",children:"These set ANTHROPIC_DEFAULT_OPUS_MODEL, ANTHROPIC_DEFAULT_SONNET_MODEL, ANTHROPIC_DEFAULT_HAIKU_MODEL."})]})]})}function ls({profileName:s,data:a,currentSettings:n,newEnvKey:i,newEnvValue:m,onNewEnvKeyChange:h,onNewEnvValueChange:c,onEnvValueChange:r,onAddEnvVar:d,onEnvBulkChange:x}){const j=ue(n),O=n?.env,A=o.useMemo(()=>Ze(O??{}),[O]),f=O??{},b=t=>{if(x){const C={...f,ANTHROPIC_MODEL:t,ANTHROPIC_DEFAULT_OPUS_MODEL:t,ANTHROPIC_DEFAULT_SONNET_MODEL:t,ANTHROPIC_DEFAULT_HAIKU_MODEL:t};x(C)}else r("ANTHROPIC_MODEL",t),r("ANTHROPIC_DEFAULT_OPUS_MODEL",t),r("ANTHROPIC_DEFAULT_SONNET_MODEL",t),r("ANTHROPIC_DEFAULT_HAIKU_MODEL",t);z.success("Applied model to all tiers",{duration:2e3})},v=t=>{if(x){const C=es(f,t);x(C)}else t.opus!==void 0&&r("ANTHROPIC_DEFAULT_OPUS_MODEL",t.opus||""),t.sonnet!==void 0&&r("ANTHROPIC_DEFAULT_SONNET_MODEL",t.sonnet||""),t.haiku!==void 0&&r("ANTHROPIC_DEFAULT_HAIKU_MODEL",t.haiku||"")},[w,p]=o.useState(!1),N=new Set(["ANTHROPIC_AUTH_TOKEN"]),l=Object.entries(f).filter(([t])=>!N.has(t));return e.jsx("div",{className:"h-full w-full min-w-0 flex flex-col",children:e.jsxs(Ae,{defaultValue:"env",className:"h-full w-full min-w-0 flex flex-col",children:[e.jsx("div",{className:"px-4 pt-4 shrink-0",children:e.jsxs(Ee,{className:"w-full",children:[e.jsx(G,{value:"env",className:"flex-1",children:j?"Configuration":"Environment Variables"}),e.jsx(G,{value:"info",className:"flex-1",children:"Info & Usage"})]})}),e.jsxs("div",{className:"flex-1 overflow-hidden flex flex-col min-w-0",children:[e.jsx(V,{value:"env",className:"flex-1 mt-0 border-0 p-0 data-[state=inactive]:hidden flex flex-col overflow-hidden min-w-0",children:j?e.jsxs(e.Fragment,{children:[e.jsx("div",{className:"flex-1 overflow-hidden",children:e.jsxs("div",{className:"h-full overflow-y-auto overflow-x-hidden p-4 space-y-6",children:[e.jsxs("div",{className:"space-y-3",children:[e.jsx(T,{className:"text-sm font-medium",children:"Model Selection"}),e.jsx(ns,{value:f.ANTHROPIC_MODEL,onChange:b,placeholder:"Search OpenRouter models..."})]}),e.jsx(rs,{selectedModel:f.ANTHROPIC_MODEL,value:A,onChange:v}),e.jsxs("div",{className:"space-y-2",children:[e.jsx(T,{className:"text-sm font-medium",children:"API Key"}),e.jsx(he,{value:f.ANTHROPIC_AUTH_TOKEN||"",onChange:t=>r("ANTHROPIC_AUTH_TOKEN",t.target.value),placeholder:"sk-or-v1-...",className:"font-mono text-sm"}),e.jsxs("p",{className:"text-xs text-muted-foreground",children:["Get your API key from"," ",e.jsx("a",{href:"https://openrouter.ai/keys",target:"_blank",rel:"noopener noreferrer",className:"text-primary hover:underline",children:"openrouter.ai/keys"})]})]}),l.length>0&&e.jsxs(te,{open:w,onOpenChange:p,children:[e.jsxs(ae,{className:"flex items-center gap-2 text-sm font-medium text-muted-foreground hover:text-foreground transition-colors group",children:[e.jsx(ce,{className:k("h-4 w-4 transition-transform",w&&"rotate-90")}),e.jsx(ze,{className:"h-4 w-4"}),e.jsx("span",{children:"Additional Variables"}),e.jsxs("span",{className:"text-xs font-normal opacity-70",children:["(",l.length,")"]})]}),e.jsx(ne,{className:"pt-4",children:e.jsx("div",{className:"space-y-3 border rounded-lg p-3 bg-muted/30",children:l.map(([t,C])=>e.jsxs("div",{className:"space-y-1",children:[e.jsx(T,{className:"text-xs text-muted-foreground",children:t}),e.jsx(y,{value:C,onChange:I=>r(t,I.target.value),className:"font-mono text-xs h-8"})]},t))})})]})]})}),e.jsxs("div",{className:"p-4 border-t bg-background shrink-0",children:[e.jsx(T,{className:"text-xs font-medium text-muted-foreground",children:"Add Environment Variable"}),e.jsxs("div",{className:"flex gap-2 mt-2",children:[e.jsx(y,{placeholder:"VARIABLE_NAME",value:i,onChange:t=>h(t.target.value.toUpperCase()),className:"font-mono text-sm h-8 w-2/5",onKeyDown:t=>t.key==="Enter"&&i.trim()&&d()}),e.jsx(y,{placeholder:"value",value:m,onChange:t=>c(t.target.value),className:"font-mono text-sm h-8 flex-1",onKeyDown:t=>t.key==="Enter"&&i.trim()&&d()}),e.jsx(g,{variant:"outline",size:"sm",className:"h-8",onClick:d,disabled:!i.trim(),children:e.jsx(L,{className:"w-4 h-4"})})]})]})]}):e.jsx(ts,{currentSettings:n,newEnvKey:i,newEnvValue:m,onNewEnvKeyChange:h,onNewEnvValueChange:c,onEnvValueChange:r,onAddEnvVar:d})}),e.jsx(V,{value:"info",className:"h-full mt-0 border-0 p-0 data-[state=inactive]:hidden",children:e.jsx(as,{profileName:s,data:a})})]})]})})}function is({profileName:s,onDelete:a}){const[n,i]=o.useState({}),[m,h]=o.useState(!1),[c,r]=o.useState(null),[d,x]=o.useState(""),[j,O]=o.useState(""),A=Re(),{data:f,isLoading:b,isError:v,refetch:w}=Le({queryKey:["settings",s],queryFn:async()=>{const u=await fetch(`/api/settings/${s}/raw`);if(!u.ok)throw new Error(`Failed to load settings: ${u.status}`);return u.json()}}),p=f?.settings,N=o.useMemo(()=>{if(c!==null)try{return JSON.parse(c)}catch{}if(p)return{...p,env:{...p.env,...n}}},[p,n,c]),l=o.useMemo(()=>c!==null?c:p?JSON.stringify(p,null,2):"",[c,p]),t=o.useCallback(u=>{r(u)},[]),C=(u,E)=>{const S={...N?.env||{},[u]:E};i(F=>({...F,[u]:E})),r(JSON.stringify({...N,env:S},null,2))},I=u=>{const E={...N?.env||{},...u};i(S=>({...S,...u})),r(JSON.stringify({...N,env:E},null,2))},fe=()=>{if(!d.trim())return;const u=d.trim(),E=j,S={...N?.env||{},[u]:E};i(F=>({...F,[u]:E})),r(JSON.stringify({...N,env:S},null,2)),x(""),O("")},B=o.useMemo(()=>{try{return JSON.parse(l),!0}catch{return!1}},[l]),pe=o.useMemo(()=>c!==null?c!==JSON.stringify(p,null,2):Object.keys(n).length>0,[c,n,p]),U=Me({mutationFn:async()=>{let u;try{u=JSON.parse(l)}catch{u={...f?.settings,env:{...f?.settings?.env,...n}}}const E=await fetch(`/api/settings/${s}`,{method:"PUT",headers:{"Content-Type":"application/json"},body:JSON.stringify({settings:u,expectedMtime:f?.mtime})});if(E.status===409)throw new Error("CONFLICT");if(!E.ok)throw new Error("Failed to save");return E.json()},onSuccess:()=>{A.invalidateQueries({queryKey:["settings",s]}),A.invalidateQueries({queryKey:["profiles"]}),i({}),r(null),z.success("Settings saved")},onError:u=>{u.message==="CONFLICT"?h(!0):z.error(u.message)}}),Q=async u=>{h(!1),u?(await w(),U.mutate()):(i({}),r(null))};return e.jsxs("div",{className:"flex-1 flex flex-col overflow-hidden",children:[e.jsx(ss,{profileName:s,data:f,settings:N,isLoading:b,isSaving:U.isPending,hasChanges:pe,isRawJsonValid:B,onRefresh:()=>w(),onDelete:a,onSave:()=>U.mutate()}),b?e.jsxs("div",{className:"flex-1 flex items-center justify-center",children:[e.jsx(J,{className:"w-8 h-8 animate-spin text-muted-foreground"}),e.jsx("span",{className:"ml-3 text-muted-foreground",children:"Loading settings..."})]}):v?e.jsx("div",{className:"flex-1 flex items-center justify-center",children:e.jsxs("div",{className:"text-center space-y-3",children:[e.jsx("p",{className:"text-sm text-muted-foreground",children:"Failed to load settings."}),e.jsxs(g,{variant:"outline",size:"sm",onClick:()=>w(),children:[e.jsx(D,{className:"w-4 h-4 mr-1"}),"Retry"]})]})}):e.jsxs("div",{className:"flex-1 grid grid-cols-[40%_60%] divide-x overflow-hidden",children:[e.jsx("div",{className:"flex flex-col overflow-hidden bg-muted/5 min-w-0",children:e.jsx(ls,{profileName:s,data:f,currentSettings:N,newEnvKey:d,newEnvValue:j,onNewEnvKeyChange:x,onNewEnvValueChange:O,onEnvValueChange:C,onEnvBulkChange:I,onAddEnvVar:fe})}),e.jsxs("div",{className:"flex flex-col overflow-hidden",children:[e.jsxs("div",{className:"px-6 py-2 bg-muted/30 border-b flex items-center gap-2 shrink-0 h-[45px]",children:[e.jsx(Ke,{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(ke,{rawJsonContent:l,isRawJsonValid:B,rawJsonEdits:c,settings:p,onChange:t})]})]}),e.jsx(re,{open:m,title:"File Modified Externally",description:"Overwrite with your changes or discard?",confirmText:"Overwrite",variant:"destructive",onConfirm:()=>Q(!0),onCancel:()=>Q(!1)})]},s)}const Z="ccs:openrouter-banner-dismissed";function cs({onCreateClick:s}){const[a,n]=o.useState(!0),{modelCount:i,isLoading:m}=K();o.useEffect(()=>{const c=localStorage.getItem(Z)==="true";n(c)},[]);const h=()=>{localStorage.setItem(Z,"true"),n(!0)};return a?null:e.jsx("div",{className:"bg-gradient-to-r from-accent to-accent/90 text-white px-4 py-3 relative shrink-0",children:e.jsxs("div",{className:"flex items-center justify-between gap-4 max-w-screen-xl mx-auto",children:[e.jsxs("div",{className:"flex items-center gap-3 flex-1 min-w-0",children:[e.jsx("div",{className:"p-1.5 bg-white/20 rounded-md shrink-0",children:e.jsx($,{className:"w-4 h-4"})}),e.jsxs("div",{className:"flex-1 min-w-0",children:[e.jsx("p",{className:"font-medium text-sm",children:"NEW: OpenRouter Integration"}),e.jsxs("p",{className:"text-xs text-white/80 truncate",children:["Browse ",m?"300+":`${i}+`," models from OpenAI, Anthropic, Google, Meta and more."]})]})]}),e.jsxs("div",{className:"flex items-center gap-2 shrink-0",children:[s&&e.jsx(g,{size:"sm",variant:"secondary",onClick:s,className:"bg-white text-accent hover:bg-white/90 h-8",children:"Try it now"}),e.jsxs("a",{href:"https://openrouter.ai",target:"_blank",rel:"noopener noreferrer",className:"text-xs text-white/80 hover:text-white hidden sm:flex items-center gap-1",children:["Learn more",e.jsx(oe,{className:"w-3 h-3"})]}),e.jsxs(g,{size:"icon",variant:"ghost",onClick:h,className:"h-7 w-7 text-white/70 hover:text-white hover:bg-white/20",children:[e.jsx(Je,{className:"w-4 h-4"}),e.jsx("span",{className:"sr-only",children:"Dismiss"})]})]})]})})}function os({onOpenRouterClick:s,onCustomClick:a}){const{modelCount:n,isLoading:i}=K();return e.jsx("div",{className:"flex-1 flex items-center justify-center bg-muted/20 p-8",children:e.jsxs("div",{className:"max-w-lg w-full space-y-6",children:[e.jsxs(qe,{className:"border-accent/30 dark:border-accent/40 bg-gradient-to-br from-accent/5 to-background dark:from-accent/10",children:[e.jsxs(Ge,{className:"pb-3",children:[e.jsxs("div",{className:"flex items-center gap-3 mb-2",children:[e.jsx("div",{className:"p-2 rounded-lg bg-accent/10 dark:bg-accent/20",children:e.jsx("img",{src:"/icons/openrouter.svg",alt:"OpenRouter",className:"w-6 h-6"})}),e.jsx(_,{variant:"secondary",className:"bg-accent/10 text-accent dark:bg-accent/20 dark:text-accent-foreground",children:"Recommended"})]}),e.jsx(Ve,{className:"text-xl",children:"Start with OpenRouter"}),e.jsxs(Ye,{className:"text-base",children:["Access ",i?"300+":`${n}+`," models from OpenAI, Anthropic, Google, Meta and more - all through one API."]})]}),e.jsxs(We,{className:"space-y-4",children:[e.jsxs("div",{className:"grid grid-cols-2 gap-3 text-sm",children:[e.jsxs("div",{className:"flex items-center gap-2 text-muted-foreground",children:[e.jsx(de,{className:"w-4 h-4 text-accent"}),e.jsx("span",{children:"One API, all providers"})]}),e.jsxs("div",{className:"flex items-center gap-2 text-muted-foreground",children:[e.jsx($,{className:"w-4 h-4 text-accent"}),e.jsx("span",{children:"Model tier mapping"})]})]}),e.jsxs(g,{onClick:s,className:"w-full bg-accent hover:bg-accent/90 text-white",size:"lg",children:["Create OpenRouter Profile",e.jsx($e,{className:"w-4 h-4 ml-2"})]}),e.jsxs("p",{className:"text-xs text-center text-muted-foreground",children:["Get your API key at"," ",e.jsxs("a",{href:"https://openrouter.ai/keys",target:"_blank",rel:"noopener noreferrer",className:"text-accent hover:underline inline-flex items-center gap-1",children:["openrouter.ai/keys",e.jsx(oe,{className:"w-3 h-3"})]})]})]})]}),e.jsxs("div",{className:"flex items-center gap-4",children:[e.jsx(Y,{className:"flex-1"}),e.jsx("span",{className:"text-xs text-muted-foreground",children:"or"}),e.jsx(Y,{className:"flex-1"})]}),e.jsx(g,{variant:"outline",onClick:a,className:"w-full",children:"Create Custom API Profile"})]})})}function ds({onCreateClick:s}){const{modelCount:a,isLoading:n}=K();return e.jsx("div",{className:"p-3 border-t bg-gradient-to-r from-accent/5 to-accent/10 dark:from-accent/10 dark:to-accent/15",children:e.jsxs("div",{className:"flex items-center gap-2",children:[e.jsx("div",{className:"p-1.5 bg-accent/10 dark:bg-accent/20 rounded shrink-0",children:e.jsx("img",{src:"/icons/openrouter.svg",alt:"",className:"w-4 h-4"})}),e.jsxs("div",{className:"flex-1 min-w-0",children:[e.jsx("p",{className:"text-xs font-medium text-accent dark:text-accent-foreground",children:"OpenRouter"}),e.jsxs("p",{className:"text-[10px] text-muted-foreground truncate",children:[n?"300+":`${a}+`," models available"]})]}),e.jsxs(g,{size:"sm",variant:"ghost",onClick:s,className:"h-7 px-2 text-accent hover:text-accent hover:bg-accent/10 dark:hover:bg-accent/20",children:[e.jsx(de,{className:"w-3 h-3 mr-1"}),e.jsx("span",{className:"text-xs",children:"Add"})]})]})})}function Cs(){const{data:s,isLoading:a,isError:n,refetch:i}=Te(),m=_e(),[h,c]=o.useState(null),[r,d]=o.useState(""),[x,j]=o.useState(!1),[O,A]=o.useState("normal"),[f,b]=o.useState(null);Se();const v=o.useMemo(()=>s?.profiles||[],[s?.profiles]),w=o.useMemo(()=>v.filter(t=>t.name.toLowerCase().includes(r.toLowerCase())),[v,r]),p=h?v.find(t=>t.name===h):null,N=t=>{m.mutate(t,{onSuccess:()=>{h===t&&c(null),b(null)}})},l=t=>{j(!1),c(t)};return e.jsxs("div",{className:"h-[calc(100vh-100px)] flex flex-col",children:[e.jsx(cs,{onCreateClick:()=>j(!0)}),e.jsxs("div",{className:"flex-1 flex min-h-0",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-3",children:[e.jsxs("div",{className:"flex items-center gap-2",children:[e.jsx(Be,{className:"w-5 h-5 text-primary"}),e.jsx("h1",{className:"font-semibold",children:"API Profiles"})]}),e.jsxs(g,{size:"sm",onClick:()=>{j(!0)},children:[e.jsx(L,{className:"w-4 h-4 mr-1"}),"New"]})]}),e.jsxs("div",{className:"relative",children:[e.jsx(ie,{className:"absolute left-2.5 top-2.5 h-4 w-4 text-muted-foreground"}),e.jsx(y,{placeholder:"Search profiles...",className:"pl-8 h-9",value:r,onChange:t=>d(t.target.value)})]})]}),e.jsx(M,{className:"flex-1",children:a?e.jsx("div",{className:"p-4 text-sm text-muted-foreground",children:"Loading profiles..."}):n?e.jsx("div",{className:"p-4 text-center",children:e.jsxs("div",{className:"space-y-3 py-8",children:[e.jsx(xe,{className:"w-12 h-12 mx-auto text-destructive/50"}),e.jsxs("div",{children:[e.jsx("p",{className:"text-sm font-medium",children:"Failed to load profiles"}),e.jsx("p",{className:"text-xs text-muted-foreground mt-1",children:"Unable to fetch API profiles. Please try again."})]}),e.jsxs(g,{size:"sm",variant:"outline",onClick:()=>i(),children:[e.jsx(D,{className:"w-4 h-4 mr-1"}),"Retry"]})]})}):w.length===0?e.jsx("div",{className:"p-4 text-center",children:v.length===0?e.jsxs("div",{className:"space-y-3 py-8",children:[e.jsx(Qe,{className:"w-12 h-12 mx-auto text-muted-foreground/50"}),e.jsxs("div",{children:[e.jsx("p",{className:"text-sm font-medium",children:"No API profiles yet"}),e.jsx("p",{className:"text-xs text-muted-foreground mt-1",children:"Create your first profile to connect to custom API endpoints"})]}),e.jsxs(g,{size:"sm",variant:"outline",onClick:()=>{j(!0)},children:[e.jsx(L,{className:"w-4 h-4 mr-1"}),"Create Profile"]})]}):e.jsxs("p",{className:"text-sm text-muted-foreground py-4",children:['No profiles match "',r,'"']})}):e.jsx("div",{className:"p-2 space-y-1",children:w.map(t=>e.jsx(xs,{profile:t,isSelected:h===t.name,onSelect:()=>{c(t.name)},onDelete:()=>b(t.name)},t.name))})}),v.length>0&&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.jsxs("span",{children:[v.length," profile",v.length!==1?"s":""]}),e.jsxs("span",{className:"flex items-center gap-1",children:[e.jsx(me,{className:"w-3 h-3 text-green-600"}),v.filter(t=>t.configured).length," configured"]})]})}),e.jsx(ds,{onCreateClick:()=>{A("openrouter"),j(!0)}})]}),e.jsx("div",{className:"flex-1 flex flex-col min-w-0",children:p?e.jsx(is,{profileName:p.name,onDelete:()=>b(p.name)}):e.jsx(os,{onOpenRouterClick:()=>{A("openrouter"),j(!0)},onCustomClick:()=>{A("normal"),j(!0)}})})]}),e.jsx(Pe,{open:x,onOpenChange:j,onSuccess:l,initialMode:O}),e.jsx(re,{open:!!f,title:"Delete Profile",description:`Are you sure you want to delete "${f}"? This will remove the settings file and cannot be undone.`,confirmText:"Delete",variant:"destructive",onConfirm:()=>f&&N(f),onCancel:()=>b(null)})]})}function xs({profile:s,isSelected:a,onSelect:n,onDelete:i}){return e.jsxs("div",{className:k("group flex items-center gap-2 px-3 py-2.5 rounded-md cursor-pointer transition-colors",a?"bg-primary/10 border border-primary/20":"hover:bg-muted border border-transparent"),onClick:n,children:[s.configured?e.jsx(me,{className:"w-4 h-4 text-green-600 shrink-0"}):e.jsx(xe,{className:"w-4 h-4 text-yellow-600 shrink-0"}),e.jsxs("div",{className:"flex-1 min-w-0",children:[e.jsx("div",{className:"font-medium text-sm truncate",children:s.name}),e.jsxs("div",{className:"flex items-center gap-1.5 min-w-0",children:[e.jsx("div",{className:"text-xs text-muted-foreground truncate flex-1",children:s.settingsPath}),e.jsx(R,{value:s.settingsPath,size:"icon",className:"h-5 w-5 opacity-0 group-hover:opacity-100 transition-opacity"})]})]}),e.jsx(g,{variant:"ghost",size:"icon",className:"h-7 w-7 opacity-0 group-hover:opacity-100 transition-opacity",onClick:m=>{m.stopPropagation(),i()},children:e.jsx(le,{className:"w-3.5 h-3.5 text-destructive"})})]})}export{Cs as ApiPage};