@kaitranntt/ccs 7.14.0 → 7.15.0-dev.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/cliproxy/account-manager.d.ts +46 -1
- package/dist/cliproxy/account-manager.d.ts.map +1 -1
- package/dist/cliproxy/account-manager.js +175 -10
- package/dist/cliproxy/account-manager.js.map +1 -1
- package/dist/cliproxy/auth/oauth-handler.d.ts.map +1 -1
- package/dist/cliproxy/auth/oauth-handler.js +65 -3
- package/dist/cliproxy/auth/oauth-handler.js.map +1 -1
- package/dist/cliproxy/cliproxy-executor.d.ts.map +1 -1
- package/dist/cliproxy/cliproxy-executor.js +18 -23
- package/dist/cliproxy/cliproxy-executor.js.map +1 -1
- package/dist/cliproxy/quota-fetcher.d.ts +3 -1
- package/dist/cliproxy/quota-fetcher.d.ts.map +1 -1
- package/dist/cliproxy/quota-fetcher.js +98 -24
- package/dist/cliproxy/quota-fetcher.js.map +1 -1
- package/dist/cliproxy/quota-manager.d.ts +88 -0
- package/dist/cliproxy/quota-manager.d.ts.map +1 -0
- package/dist/cliproxy/quota-manager.js +278 -0
- package/dist/cliproxy/quota-manager.js.map +1 -0
- package/dist/commands/cliproxy-command.d.ts.map +1 -1
- package/dist/commands/cliproxy-command.js +191 -0
- package/dist/commands/cliproxy-command.js.map +1 -1
- package/dist/commands/help-command.d.ts.map +1 -1
- package/dist/commands/help-command.js +4 -0
- package/dist/commands/help-command.js.map +1 -1
- package/dist/config/unified-config-loader.d.ts.map +1 -1
- package/dist/config/unified-config-loader.js +22 -0
- package/dist/config/unified-config-loader.js.map +1 -1
- package/dist/config/unified-config-types.d.ts +62 -2
- package/dist/config/unified-config-types.d.ts.map +1 -1
- package/dist/config/unified-config-types.js +29 -2
- package/dist/config/unified-config-types.js.map +1 -1
- package/dist/ui/assets/{accounts-wkvC_Z1E.js → accounts-D31DF_DO.js} +1 -1
- package/dist/ui/assets/{alert-dialog--nlDi-Dj.js → alert-dialog-LCg4HaeZ.js} +1 -1
- package/dist/ui/assets/{api-DeyefOLW.js → api-Bmxcet5w.js} +1 -1
- package/dist/ui/assets/{auth-section-BQXfw1cb.js → auth-section-CRTokeZ8.js} +1 -1
- package/dist/ui/assets/{card-P5vPGo2D.js → card-BmnReIPp.js} +1 -1
- package/dist/ui/assets/cliproxy-BrJaxqVj.js +3 -0
- package/dist/ui/assets/{cliproxy-control-panel-Dbs8NAQa.js → cliproxy-control-panel-D7FGe5HL.js} +1 -1
- package/dist/ui/assets/{confirm-dialog-BM75Bkww.js → confirm-dialog-CzpGAyFB.js} +1 -1
- package/dist/ui/assets/{copilot-BwylIlO5.js → copilot-C2v-0P0m.js} +3 -3
- package/dist/ui/assets/{globalenv-section-Cgpz_NQ0.js → globalenv-section-Cx0L1Zte.js} +1 -1
- package/dist/ui/assets/{health-DWUjYWDI.js → health-BvZrzSJ3.js} +1 -1
- package/dist/ui/assets/icons-CZDQWWm2.js +1 -0
- package/dist/ui/assets/index-BX0IVNt5.css +1 -0
- package/dist/ui/assets/{index-CIWe-99u.js → index-CJrvk2Qf.js} +1 -1
- package/dist/ui/assets/{index-D8MFq-UJ.js → index-D8K1YCe7.js} +14 -14
- package/dist/ui/assets/{index-4Wd5fx72.js → index-fED9JOL0.js} +1 -1
- package/dist/ui/assets/{index-f_AuSs01.js → index-qAWtHsB9.js} +1 -1
- package/dist/ui/assets/{shared-I-pAdvVQ.js → shared-Do9VzQ5g.js} +1 -1
- package/dist/ui/assets/{switch-DHwS-NMF.js → switch-CmGBdPfU.js} +1 -1
- package/dist/ui/index.html +3 -3
- package/dist/web-server/index.d.ts.map +1 -1
- package/dist/web-server/index.js +8 -1
- package/dist/web-server/index.js.map +1 -1
- package/dist/web-server/routes/cliproxy-auth-routes.d.ts.map +1 -1
- package/dist/web-server/routes/cliproxy-auth-routes.js +92 -1
- package/dist/web-server/routes/cliproxy-auth-routes.js.map +1 -1
- package/package.json +1 -1
- package/scripts/code-reviewer.ts +308 -0
- package/dist/ui/assets/cliproxy-CcMLaKpF.js +0 -3
- package/dist/ui/assets/icons-U9n5DGj9.js +0 -1
- package/dist/ui/assets/index-1g-Hy9VA.css +0 -1
|
@@ -1 +1 @@
|
|
|
1
|
-
import{j as e}from"./radix-ui-CBgg0XeO.js";import{r as c}from"./react-vendor-B_CU-WTZ.js";import{B as S,c as E,T as Ne,k as ve,l as be,a as g,I as y,i as I,L as T,m as M,n as ne,o as we,s as Ce,p as ye,q as Oe,S as W,r as L,t as $,v as re,w as Ae,x as Ee,y as ie,z as le,A as ce,D as Te,E as _e,F as X,G as Z,R as ke,H as q,J as Se,K as Pe,M as Re,N as Le}from"./index-D8MFq-UJ.js";import{u as Me,a as De,b as Ie}from"./tanstack-CxYN0q6L.js";import{C as B,S as ee}from"./confirm-dialog-BM75Bkww.js";import{t as Q}from"./notifications-dJQY2-U6.js";import{a0 as U,a9 as oe,L as G,aa as Ue,E as He,d as Fe,O as D,I as Ke,ab as de,Q as V,b as xe,ac as ze,N as Je,ad as $e,m as me,X as Be,Z as ue,ae as Qe,_ as qe,V as he,af as Ge,n as fe}from"./icons-U9n5DGj9.js";import{C as Ve,b as Ye,c as We,d as Xe,a as Ze}from"./card-P5vPGo2D.js";import"./utils-CzKF5WmX.js";import"./form-utils-kUVlZZAO.js";import"./code-highlight-DKN39ySy.js";import"./alert-dialog--nlDi-Dj.js";function es({className:s,showTooltip:t=!0}){const i=e.jsxs(S,{variant:"outline",className:E("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 t?e.jsxs(Ne,{children:[e.jsx(ve,{asChild:!0,children:i}),e.jsx(be,{children:e.jsx("p",{children:"Access 349+ models via OpenRouter"})})]}):i}function se(s){return[/^ANTHROPIC_AUTH_TOKEN$/,/_API_KEY$/,/_AUTH_TOKEN$/,/^API_KEY$/,/^AUTH_TOKEN$/,/_SECRET$/,/^SECRET$/].some(i=>i.test(s))}function pe(s){return s?.env?(s.env.ANTHROPIC_BASE_URL||"").toLowerCase().includes("openrouter.ai"):!1}function ss(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 ts(s,t){const i={...s};return t.opus?i.ANTHROPIC_DEFAULT_OPUS_MODEL=t.opus:delete i.ANTHROPIC_DEFAULT_OPUS_MODEL,t.sonnet?i.ANTHROPIC_DEFAULT_SONNET_MODEL=t.sonnet:delete i.ANTHROPIC_DEFAULT_SONNET_MODEL,t.haiku?i.ANTHROPIC_DEFAULT_HAIKU_MODEL=t.haiku:delete i.ANTHROPIC_DEFAULT_HAIKU_MODEL,i}function as({profileName:s,data:t,settings:i,isLoading:l,isSaving:d,hasChanges:f,isRawJsonValid:x,onRefresh:n,onDelete:o,onSave:m}){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}),t?.path&&e.jsx(S,{variant:"outline",className:"text-xs",children:t.path.replace(/^.*\//,"")}),pe(i)&&e.jsx(es,{className:"ml-1"})]}),t&&e.jsxs("p",{className:"text-xs text-muted-foreground mt-0.5",children:["Last modified: ",new Date(t.mtime).toLocaleString()]})]}),e.jsxs("div",{className:"flex items-center gap-2",children:[e.jsx(g,{variant:"ghost",size:"sm",onClick:n,disabled:l,children:e.jsx(U,{className:`w-4 h-4 ${l?"animate-spin":""}`})}),o&&e.jsx(g,{variant:"ghost",size:"sm",onClick:o,children:e.jsx(oe,{className:"w-4 h-4 text-destructive"})}),e.jsx(g,{size:"sm",onClick:m,disabled:d||!f||!x,children:d?e.jsxs(e.Fragment,{children:[e.jsx(G,{className:"w-4 h-4 mr-1 animate-spin"}),"Saving..."]}):e.jsxs(e.Fragment,{children:[e.jsx(Ue,{className:"w-4 h-4 mr-1"}),"Save"]})})]})]})}function ge({label:s,...t}){const[i,l]=c.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:i?"text":"password",className:"pr-10 font-mono",...t}),e.jsx(g,{type:"button",variant:"ghost",size:"sm",className:"absolute right-0 top-0 h-full px-3",onClick:()=>l(!i),tabIndex:-1,children:i?e.jsx(He,{className:"w-4 h-4"}):e.jsx(Fe,{className:"w-4 h-4"})})]})]})}function ns({currentSettings:s,newEnvKey:t,newEnvValue:i,onNewEnvKeyChange:l,onNewEnvValueChange:d,onEnvValueChange:f,onAddEnvVar:x}){return e.jsxs(e.Fragment,{children:[e.jsx(I,{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(([n,o])=>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:[n,se(n)&&e.jsx(S,{variant:"secondary",className:"text-[10px] px-1 py-0 h-4",children:"sensitive"})]}),se(n)?e.jsx(ge,{value:o,onChange:m=>f(n,m.target.value),className:"font-mono text-sm h-8"}):e.jsx(y,{value:o,onChange:m=>f(n,m.target.value),className:"font-mono text-sm h-8"})]},n))}):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:t,onChange:n=>l(n.target.value.toUpperCase()),className:"font-mono text-sm h-8 w-2/5",onKeyDown:n=>n.key==="Enter"&&t.trim()&&x()}),e.jsx(y,{placeholder:"value",value:i,onChange:n=>d(n.target.value),className:"font-mono text-sm h-8 flex-1",onKeyDown:n=>n.key==="Enter"&&t.trim()&&x()}),e.jsx(g,{variant:"outline",size:"sm",className:"h-8",onClick:x,disabled:!t.trim(),children:e.jsx(D,{className:"w-4 h-4"})})]})]})]})}function rs({profileName:s,data:t}){return e.jsx(I,{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(Ke,{className:"w-4 h-4"}),"Profile Information"]}),e.jsx("div",{className:"space-y-3 bg-card rounded-lg border p-4 shadow-sm",children:t&&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:t.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:t.path}),e.jsx(M,{value:t.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(t.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(M,{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(M,{value:`ccs default ${s}`,size:"icon",className:"h-6 w-6"})]})]})]})]})]})})}function is({value:s,onChange:t,placeholder:i="Search models...",className:l}){const[d,f]=c.useState(""),[x,n]=c.useState(null),{models:o,isLoading:m,isError:j,isFetching:O}=ne(),A=we(),N=c.useMemo(()=>Ce(o,d,{category:x??void 0}),[o,d,x]),b=c.useMemo(()=>ye(o,2),[o]),k=!d.trim()&&!x,_=c.useMemo(()=>{const r={anthropic:[],openai:[],google:[],meta:[],mistral:[],opensource:[],other:[]};N.forEach(a=>{r[a.category].push(a)});for(const a of Object.keys(r))r[a]=Oe(r[a]);return r},[N]),C=c.useCallback(()=>{A()},[A]),p=o.find(r=>r.id===s);return m&&o.length===0?e.jsxs("div",{className:E("space-y-2",l),children:[e.jsx(W,{className:"h-10 w-full"}),e.jsx(W,{className:"h-32 w-full"})]}):e.jsxs("div",{className:E("space-y-2 w-full min-w-0 overflow-hidden",l),children:[e.jsxs("div",{className:"flex gap-2",children:[e.jsxs("div",{className:"relative flex-1",children:[e.jsx(de,{className:"text-muted-foreground absolute left-3 top-1/2 h-4 w-4 -translate-y-1/2"}),e.jsx(y,{value:d,onChange:r=>f(r.target.value),placeholder:i,className:"pl-9"})]}),e.jsx(g,{variant:"outline",size:"icon",onClick:C,disabled:O,title:"Refresh models",children:O?e.jsx(G,{className:"h-4 w-4 animate-spin"}):e.jsx(U,{className:"h-4 w-4"})})]}),e.jsxs("div",{className:"flex flex-wrap gap-1",children:[e.jsxs(S,{variant:x===null?"default":"outline",className:"cursor-pointer",onClick:()=>n(null),children:["All (",o.length,")"]}),Object.keys(L).map(r=>{const a=_[r].length;return a===0?null:e.jsxs(S,{variant:x===r?"default":"outline",className:"cursor-pointer",onClick:()=>n(r),children:[L[r]," (",a,")"]},r)})]}),p&&e.jsxs("div",{className:"bg-muted rounded-md p-2 text-sm",children:[e.jsx("span",{className:"font-medium",children:p.name}),e.jsxs("span",{className:"text-muted-foreground ml-2",children:[$(p.pricing)," |"," ",re(p.context_length)]})]}),e.jsx(I,{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:C,children:"Retry"})]}):N.length===0?e.jsxs("div",{className:"text-muted-foreground p-4 text-center",children:['No models found matching "',d,'"']}):e.jsxs("div",{className:"space-y-6 p-3",children:[k&&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(V,{className:"h-3 w-3 text-accent"}),e.jsx("span",{children:"Newest Models"})]}),e.jsx("div",{className:"space-y-1",children:b.map(r=>e.jsx(te,{model:r,isSelected:r.id===s,onClick:()=>t(r.id),showAge:!0},r.id))})]}),Object.keys(L).map(r=>{const a=_[r];return a.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:L[r]}),e.jsx("div",{className:"space-y-1",children:a.map(v=>e.jsx(te,{model:v,isSelected:v.id===s,onClick:()=>t(v.id)},v.id))})]},r)})]})})]})}function te({model:s,isSelected:t,onClick:i,showAge:l=!1}){return e.jsxs("button",{type:"button",onClick:i,className:E("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",t&&"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:E("flex shrink-0 items-center gap-1 text-xs whitespace-nowrap",t?"text-accent-foreground/80":"text-muted-foreground group-hover:text-accent-foreground/80"),children:[l&&s.created&&e.jsx(S,{variant:"outline",className:E("text-[10px] px-1",t?"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:Ae(s.created)}),s.isFree?e.jsx(S,{variant:"secondary",className:E("text-[10px] px-1",t?"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(S,{variant:"outline",className:E("text-[10px] px-1 border-emerald-500/50 text-emerald-600",t?"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:$(s.pricing)})]}):e.jsx("span",{className:"tabular-nums",children:$(s.pricing)}),e.jsx("span",{className:"tabular-nums",children:re(s.context_length)})]})]})}function ls({selectedModel:s,value:t,onChange:i,className:l}){const{models:d}=ne(),f=c.useMemo(()=>s?Ee(s,d):{},[s,d]),x=()=>{i(f)},n=(m,j)=>{i({...t,[m]:j||void 0})},o=s&&Object.keys(f).length>0;return e.jsxs(ie,{className:E("group",l),children:[e.jsxs(le,{className:"flex items-center gap-2 text-sm font-medium hover:underline",children:[e.jsx(xe,{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(ce,{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."}),o&&e.jsxs(g,{type:"button",variant:"outline",size:"sm",onClick:x,children:[e.jsx(ze,{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:t.opus??"",onChange:m=>n("opus",m.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:t.sonnet??"",onChange:m=>n("sonnet",m.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:t.haiku??"",onChange:m=>n("haiku",m.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 cs({profileName:s,data:t,currentSettings:i,newEnvKey:l,newEnvValue:d,onNewEnvKeyChange:f,onNewEnvValueChange:x,onEnvValueChange:n,onAddEnvVar:o,onEnvBulkChange:m}){const j=pe(i),O=i?.env,A=c.useMemo(()=>ss(O??{}),[O]),N=O??{},b=a=>{if(m){const v={...N,ANTHROPIC_MODEL:a,ANTHROPIC_DEFAULT_OPUS_MODEL:a,ANTHROPIC_DEFAULT_SONNET_MODEL:a,ANTHROPIC_DEFAULT_HAIKU_MODEL:a};m(v)}else n("ANTHROPIC_MODEL",a),n("ANTHROPIC_DEFAULT_OPUS_MODEL",a),n("ANTHROPIC_DEFAULT_SONNET_MODEL",a),n("ANTHROPIC_DEFAULT_HAIKU_MODEL",a);Q.success("Applied model to all tiers",{duration:2e3})},k=a=>{if(m){const v=ts(N,a);m(v)}else a.opus!==void 0&&n("ANTHROPIC_DEFAULT_OPUS_MODEL",a.opus||""),a.sonnet!==void 0&&n("ANTHROPIC_DEFAULT_SONNET_MODEL",a.sonnet||""),a.haiku!==void 0&&n("ANTHROPIC_DEFAULT_HAIKU_MODEL",a.haiku||"")},[_,C]=c.useState(!1),p=new Set(["ANTHROPIC_AUTH_TOKEN"]),r=Object.entries(N).filter(([a])=>!p.has(a));return e.jsx("div",{className:"h-full w-full min-w-0 flex flex-col",children:e.jsxs(Te,{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(_e,{className:"w-full",children:[e.jsx(X,{value:"env",className:"flex-1",children:j?"Configuration":"Environment Variables"}),e.jsx(X,{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(Z,{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(is,{value:N.ANTHROPIC_MODEL,onChange:b,placeholder:"Search OpenRouter models..."})]}),e.jsx(ls,{selectedModel:N.ANTHROPIC_MODEL,value:A,onChange:k}),e.jsxs("div",{className:"space-y-2",children:[e.jsx(T,{className:"text-sm font-medium",children:"API Key"}),e.jsx(ge,{value:N.ANTHROPIC_AUTH_TOKEN||"",onChange:a=>n("ANTHROPIC_AUTH_TOKEN",a.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"})]})]}),r.length>0&&e.jsxs(ie,{open:_,onOpenChange:C,children:[e.jsxs(le,{className:"flex items-center gap-2 text-sm font-medium text-muted-foreground hover:text-foreground transition-colors group",children:[e.jsx(xe,{className:E("h-4 w-4 transition-transform",_&&"rotate-90")}),e.jsx(Je,{className:"h-4 w-4"}),e.jsx("span",{children:"Additional Variables"}),e.jsxs("span",{className:"text-xs font-normal opacity-70",children:["(",r.length,")"]})]}),e.jsx(ce,{className:"pt-4",children:e.jsx("div",{className:"space-y-3 border rounded-lg p-3 bg-muted/30",children:r.map(([a,v])=>e.jsxs("div",{className:"space-y-1",children:[e.jsx(T,{className:"text-xs text-muted-foreground",children:a}),e.jsx(y,{value:v,onChange:R=>n(a,R.target.value),className:"font-mono text-xs h-8"})]},a))})})]})]})}),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:l,onChange:a=>f(a.target.value.toUpperCase()),className:"font-mono text-sm h-8 w-2/5",onKeyDown:a=>a.key==="Enter"&&l.trim()&&o()}),e.jsx(y,{placeholder:"value",value:d,onChange:a=>x(a.target.value),className:"font-mono text-sm h-8 flex-1",onKeyDown:a=>a.key==="Enter"&&l.trim()&&o()}),e.jsx(g,{variant:"outline",size:"sm",className:"h-8",onClick:o,disabled:!l.trim(),children:e.jsx(D,{className:"w-4 h-4"})})]})]})]}):e.jsx(ns,{currentSettings:i,newEnvKey:l,newEnvValue:d,onNewEnvKeyChange:f,onNewEnvValueChange:x,onEnvValueChange:n,onAddEnvVar:o})}),e.jsx(Z,{value:"info",className:"h-full mt-0 border-0 p-0 data-[state=inactive]:hidden",children:e.jsx(rs,{profileName:s,data:t})})]})]})})}function os({profileName:s,onDelete:t,onHasChangesUpdate:i}){const[l,d]=c.useState({}),[f,x]=c.useState(!1),[n,o]=c.useState(null),[m,j]=c.useState(""),[O,A]=c.useState(""),N=Me(),{data:b,isLoading:k,isError:_,refetch:C}=De({queryKey:["settings",s],queryFn:async()=>{const h=await fetch(`/api/settings/${s}/raw`);if(!h.ok)throw new Error(`Failed to load settings: ${h.status}`);return h.json()}}),p=b?.settings,r=c.useMemo(()=>{if(n!==null)try{return JSON.parse(n)}catch{}if(p)return{...p,env:{...p.env,...l}}},[p,l,n]),a=c.useMemo(()=>n!==null?n:p?JSON.stringify(p,null,2):"",[n,p]),v=c.useCallback(h=>{o(h)},[]),R=(h,w)=>{const P={...r?.env||{},[h]:w};d(J=>({...J,[h]:w})),o(JSON.stringify({...r,env:P},null,2))},H=h=>{const w={...r?.env||{},...h};d(P=>({...P,...h})),o(JSON.stringify({...r,env:w},null,2))},F=()=>{if(!m.trim())return;const h=m.trim(),w=O,P={...r?.env||{},[h]:w};d(J=>({...J,[h]:w})),o(JSON.stringify({...r,env:P},null,2)),j(""),A("")},u=c.useMemo(()=>{try{return JSON.parse(a),!0}catch{return!1}},[a]),K=c.useMemo(()=>n!==null?n!==JSON.stringify(p,null,2):Object.keys(l).length>0,[n,l,p]),je=c.useMemo(()=>{const h=["ANTHROPIC_BASE_URL","ANTHROPIC_AUTH_TOKEN"],w=r?.env||{};return h.filter(P=>!w[P]?.trim())},[r]);c.useEffect(()=>{i?.(K)},[K,i]);const z=Ie({mutationFn:async()=>{let h;try{h=JSON.parse(a)}catch{h={...b?.settings,env:{...b?.settings?.env,...l}}}const w=await fetch(`/api/settings/${s}`,{method:"PUT",headers:{"Content-Type":"application/json"},body:JSON.stringify({settings:h,expectedMtime:b?.mtime})});if(w.status===409)throw new Error("CONFLICT");if(!w.ok)throw new Error("Failed to save");return w.json()},onSuccess:()=>{N.invalidateQueries({queryKey:["settings",s]}),N.invalidateQueries({queryKey:["profiles"]}),d({}),o(null),Q.success("Settings saved")},onError:h=>{h.message==="CONFLICT"?x(!0):Q.error(h.message)}}),Y=async h=>{x(!1),h?(await C(),z.mutate()):(d({}),o(null))};return e.jsxs("div",{className:"flex-1 flex flex-col overflow-hidden",children:[e.jsx(as,{profileName:s,data:b,settings:r,isLoading:k,isSaving:z.isPending,hasChanges:K,isRawJsonValid:u,onRefresh:()=>C(),onDelete:t,onSave:()=>z.mutate()}),k?e.jsxs("div",{className:"flex-1 flex items-center justify-center",children:[e.jsx(G,{className:"w-8 h-8 animate-spin text-muted-foreground"}),e.jsx("span",{className:"ml-3 text-muted-foreground",children:"Loading settings..."})]}):_?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:()=>C(),children:[e.jsx(U,{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(cs,{profileName:s,data:b,currentSettings:r,newEnvKey:m,newEnvValue:O,onNewEnvKeyChange:j,onNewEnvValueChange:A,onEnvValueChange:R,onEnvBulkChange:H,onAddEnvVar:F})}),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($e,{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:a,isRawJsonValid:u,rawJsonEdits:n,settings:p,onChange:v,missingRequiredFields:je})]})]}),e.jsx(B,{open:f,title:"File Modified Externally",description:"Overwrite with your changes or discard?",confirmText:"Overwrite",variant:"destructive",onConfirm:()=>Y(!0),onCancel:()=>Y(!1)})]},s)}const ae="ccs:openrouter-banner-dismissed";function ds({onCreateClick:s}){const[t,i]=c.useState(!0),{modelCount:l,isLoading:d}=q();c.useEffect(()=>{const x=localStorage.getItem(ae)==="true";i(x)},[]);const f=()=>{localStorage.setItem(ae,"true"),i(!0)};return t?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(V,{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 ",d?"300+":`${l}+`," 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(me,{className:"w-3 h-3"})]}),e.jsxs(g,{size:"icon",variant:"ghost",onClick:f,className:"h-7 w-7 text-white/70 hover:text-white hover:bg-white/20",children:[e.jsx(Be,{className:"w-4 h-4"}),e.jsx("span",{className:"sr-only",children:"Dismiss"})]})]})]})})}function xs({onOpenRouterClick:s,onCustomClick:t}){const{modelCount:i,isLoading:l}=q();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(Ve,{className:"border-accent/30 dark:border-accent/40 bg-gradient-to-br from-accent/5 to-background dark:from-accent/10",children:[e.jsxs(Ye,{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(S,{variant:"secondary",className:"bg-accent/10 text-accent dark:bg-accent/20 dark:text-accent-foreground",children:"Recommended"})]}),e.jsx(We,{className:"text-xl",children:"Start with OpenRouter"}),e.jsxs(Xe,{className:"text-base",children:["Access ",l?"300+":`${i}+`," models from OpenAI, Anthropic, Google, Meta and more - all through one API."]})]}),e.jsxs(Ze,{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(ue,{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(V,{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(Qe,{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(me,{className:"w-3 h-3"})]})]})]})]}),e.jsxs("div",{className:"flex items-center gap-4",children:[e.jsx(ee,{className:"flex-1"}),e.jsx("span",{className:"text-xs text-muted-foreground",children:"or"}),e.jsx(ee,{className:"flex-1"})]}),e.jsx(g,{variant:"outline",onClick:t,className:"w-full",children:"Create Custom API Profile"})]})})}function ms({onCreateClick:s}){const{modelCount:t,isLoading:i}=q();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:[i?"300+":`${t}+`," 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(ue,{className:"w-3 h-3 mr-1"}),e.jsx("span",{className:"text-xs",children:"Add"})]})]})})}function As(){const{data:s,isLoading:t,isError:i,refetch:l}=Se(),d=Pe(),[f,x]=c.useState(null),[n,o]=c.useState(""),[m,j]=c.useState(!1),[O,A]=c.useState("normal"),[N,b]=c.useState(null),[k,_]=c.useState(!1),[C,p]=c.useState(null);Re();const r=c.useMemo(()=>s?.profiles||[],[s?.profiles]),a=c.useMemo(()=>r.filter(u=>u.name.toLowerCase().includes(n.toLowerCase())),[r,n]),v=f?r.find(u=>u.name===f):null,R=u=>{d.mutate(u,{onSuccess:()=>{f===u&&x(null),b(null)}})},H=u=>{j(!1),k&&f!==null?p(u):x(u)},F=u=>{k&&f!==u?p(u):x(u)};return e.jsxs("div",{className:"h-[calc(100vh-100px)] flex flex-col",children:[e.jsx(ds,{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(qe,{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(D,{className:"w-4 h-4 mr-1"}),"New"]})]}),e.jsxs("div",{className:"relative",children:[e.jsx(de,{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:n,onChange:u=>o(u.target.value)})]})]}),e.jsx(I,{className:"flex-1",children:t?e.jsx("div",{className:"p-4 text-sm text-muted-foreground",children:"Loading profiles..."}):i?e.jsx("div",{className:"p-4 text-center",children:e.jsxs("div",{className:"space-y-3 py-8",children:[e.jsx(he,{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:()=>l(),children:[e.jsx(U,{className:"w-4 h-4 mr-1"}),"Retry"]})]})}):a.length===0?e.jsx("div",{className:"p-4 text-center",children:r.length===0?e.jsxs("div",{className:"space-y-3 py-8",children:[e.jsx(Ge,{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(D,{className:"w-4 h-4 mr-1"}),"Create Profile"]})]}):e.jsxs("p",{className:"text-sm text-muted-foreground py-4",children:['No profiles match "',n,'"']})}):e.jsx("div",{className:"p-2 space-y-1",children:a.map(u=>e.jsx(us,{profile:u,isSelected:f===u.name,onSelect:()=>F(u.name),onDelete:()=>b(u.name)},u.name))})}),r.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:[r.length," profile",r.length!==1?"s":""]}),e.jsxs("span",{className:"flex items-center gap-1",children:[e.jsx(fe,{className:"w-3 h-3 text-green-600"}),r.filter(u=>u.configured).length," configured"]})]})}),e.jsx(ms,{onCreateClick:()=>{A("openrouter"),j(!0)}})]}),e.jsx("div",{className:"flex-1 flex flex-col min-w-0",children:v?e.jsx(os,{profileName:v.name,onDelete:()=>b(v.name),onHasChangesUpdate:_},v.name):e.jsx(xs,{onOpenRouterClick:()=>{A("openrouter"),j(!0)},onCustomClick:()=>{A("normal"),j(!0)}})})]}),e.jsx(Le,{open:m,onOpenChange:j,onSuccess:H,initialMode:O}),e.jsx(B,{open:!!N,title:"Delete Profile",description:`Are you sure you want to delete "${N}"? This will remove the settings file and cannot be undone.`,confirmText:"Delete",variant:"destructive",onConfirm:()=>N&&R(N),onCancel:()=>b(null)}),e.jsx(B,{open:!!C,title:"Unsaved Changes",description:`You have unsaved changes in "${f}". Discard and switch to "${C}"?`,confirmText:"Discard & Switch",variant:"destructive",onConfirm:()=>{_(!1),x(C),p(null)},onCancel:()=>p(null)})]})}function us({profile:s,isSelected:t,onSelect:i,onDelete:l}){return e.jsxs("div",{className:E("group flex items-center gap-2 px-3 py-2.5 rounded-md cursor-pointer transition-colors",t?"bg-primary/10 border border-primary/20":"hover:bg-muted border border-transparent"),onClick:i,children:[s.configured?e.jsx(fe,{className:"w-4 h-4 text-green-600 shrink-0"}):e.jsx(he,{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(M,{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:d=>{d.stopPropagation(),l()},children:e.jsx(oe,{className:"w-3.5 h-3.5 text-destructive"})})]})}export{As as ApiPage};
|
|
1
|
+
import{j as e}from"./radix-ui-CBgg0XeO.js";import{r as c}from"./react-vendor-B_CU-WTZ.js";import{B as S,c as E,T as Ne,k as ve,l as be,a as g,I as y,i as I,L as T,m as M,n as ne,o as we,s as Ce,p as ye,q as Oe,S as W,r as L,t as $,v as re,w as Ae,x as Ee,y as ie,z as le,A as ce,D as Te,E as _e,F as X,G as Z,R as ke,H as q,J as Se,K as Pe,M as Re,N as Le}from"./index-D8K1YCe7.js";import{u as Me,a as De,b as Ie}from"./tanstack-CxYN0q6L.js";import{C as B,S as ee}from"./confirm-dialog-CzpGAyFB.js";import{t as Q}from"./notifications-dJQY2-U6.js";import{a0 as U,a9 as oe,L as G,aa as Ue,E as He,d as Fe,O as D,I as Ke,ab as de,Q as V,b as xe,ac as ze,N as Je,ad as $e,m as me,X as Be,Z as ue,ae as Qe,_ as qe,V as he,af as Ge,n as fe}from"./icons-CZDQWWm2.js";import{C as Ve,b as Ye,c as We,d as Xe,a as Ze}from"./card-BmnReIPp.js";import"./utils-CzKF5WmX.js";import"./form-utils-kUVlZZAO.js";import"./code-highlight-DKN39ySy.js";import"./alert-dialog-LCg4HaeZ.js";function es({className:s,showTooltip:t=!0}){const i=e.jsxs(S,{variant:"outline",className:E("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 t?e.jsxs(Ne,{children:[e.jsx(ve,{asChild:!0,children:i}),e.jsx(be,{children:e.jsx("p",{children:"Access 349+ models via OpenRouter"})})]}):i}function se(s){return[/^ANTHROPIC_AUTH_TOKEN$/,/_API_KEY$/,/_AUTH_TOKEN$/,/^API_KEY$/,/^AUTH_TOKEN$/,/_SECRET$/,/^SECRET$/].some(i=>i.test(s))}function pe(s){return s?.env?(s.env.ANTHROPIC_BASE_URL||"").toLowerCase().includes("openrouter.ai"):!1}function ss(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 ts(s,t){const i={...s};return t.opus?i.ANTHROPIC_DEFAULT_OPUS_MODEL=t.opus:delete i.ANTHROPIC_DEFAULT_OPUS_MODEL,t.sonnet?i.ANTHROPIC_DEFAULT_SONNET_MODEL=t.sonnet:delete i.ANTHROPIC_DEFAULT_SONNET_MODEL,t.haiku?i.ANTHROPIC_DEFAULT_HAIKU_MODEL=t.haiku:delete i.ANTHROPIC_DEFAULT_HAIKU_MODEL,i}function as({profileName:s,data:t,settings:i,isLoading:l,isSaving:d,hasChanges:f,isRawJsonValid:x,onRefresh:n,onDelete:o,onSave:m}){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}),t?.path&&e.jsx(S,{variant:"outline",className:"text-xs",children:t.path.replace(/^.*\//,"")}),pe(i)&&e.jsx(es,{className:"ml-1"})]}),t&&e.jsxs("p",{className:"text-xs text-muted-foreground mt-0.5",children:["Last modified: ",new Date(t.mtime).toLocaleString()]})]}),e.jsxs("div",{className:"flex items-center gap-2",children:[e.jsx(g,{variant:"ghost",size:"sm",onClick:n,disabled:l,children:e.jsx(U,{className:`w-4 h-4 ${l?"animate-spin":""}`})}),o&&e.jsx(g,{variant:"ghost",size:"sm",onClick:o,children:e.jsx(oe,{className:"w-4 h-4 text-destructive"})}),e.jsx(g,{size:"sm",onClick:m,disabled:d||!f||!x,children:d?e.jsxs(e.Fragment,{children:[e.jsx(G,{className:"w-4 h-4 mr-1 animate-spin"}),"Saving..."]}):e.jsxs(e.Fragment,{children:[e.jsx(Ue,{className:"w-4 h-4 mr-1"}),"Save"]})})]})]})}function ge({label:s,...t}){const[i,l]=c.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:i?"text":"password",className:"pr-10 font-mono",...t}),e.jsx(g,{type:"button",variant:"ghost",size:"sm",className:"absolute right-0 top-0 h-full px-3",onClick:()=>l(!i),tabIndex:-1,children:i?e.jsx(He,{className:"w-4 h-4"}):e.jsx(Fe,{className:"w-4 h-4"})})]})]})}function ns({currentSettings:s,newEnvKey:t,newEnvValue:i,onNewEnvKeyChange:l,onNewEnvValueChange:d,onEnvValueChange:f,onAddEnvVar:x}){return e.jsxs(e.Fragment,{children:[e.jsx(I,{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(([n,o])=>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:[n,se(n)&&e.jsx(S,{variant:"secondary",className:"text-[10px] px-1 py-0 h-4",children:"sensitive"})]}),se(n)?e.jsx(ge,{value:o,onChange:m=>f(n,m.target.value),className:"font-mono text-sm h-8"}):e.jsx(y,{value:o,onChange:m=>f(n,m.target.value),className:"font-mono text-sm h-8"})]},n))}):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:t,onChange:n=>l(n.target.value.toUpperCase()),className:"font-mono text-sm h-8 w-2/5",onKeyDown:n=>n.key==="Enter"&&t.trim()&&x()}),e.jsx(y,{placeholder:"value",value:i,onChange:n=>d(n.target.value),className:"font-mono text-sm h-8 flex-1",onKeyDown:n=>n.key==="Enter"&&t.trim()&&x()}),e.jsx(g,{variant:"outline",size:"sm",className:"h-8",onClick:x,disabled:!t.trim(),children:e.jsx(D,{className:"w-4 h-4"})})]})]})]})}function rs({profileName:s,data:t}){return e.jsx(I,{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(Ke,{className:"w-4 h-4"}),"Profile Information"]}),e.jsx("div",{className:"space-y-3 bg-card rounded-lg border p-4 shadow-sm",children:t&&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:t.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:t.path}),e.jsx(M,{value:t.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(t.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(M,{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(M,{value:`ccs default ${s}`,size:"icon",className:"h-6 w-6"})]})]})]})]})]})})}function is({value:s,onChange:t,placeholder:i="Search models...",className:l}){const[d,f]=c.useState(""),[x,n]=c.useState(null),{models:o,isLoading:m,isError:j,isFetching:O}=ne(),A=we(),N=c.useMemo(()=>Ce(o,d,{category:x??void 0}),[o,d,x]),b=c.useMemo(()=>ye(o,2),[o]),k=!d.trim()&&!x,_=c.useMemo(()=>{const r={anthropic:[],openai:[],google:[],meta:[],mistral:[],opensource:[],other:[]};N.forEach(a=>{r[a.category].push(a)});for(const a of Object.keys(r))r[a]=Oe(r[a]);return r},[N]),C=c.useCallback(()=>{A()},[A]),p=o.find(r=>r.id===s);return m&&o.length===0?e.jsxs("div",{className:E("space-y-2",l),children:[e.jsx(W,{className:"h-10 w-full"}),e.jsx(W,{className:"h-32 w-full"})]}):e.jsxs("div",{className:E("space-y-2 w-full min-w-0 overflow-hidden",l),children:[e.jsxs("div",{className:"flex gap-2",children:[e.jsxs("div",{className:"relative flex-1",children:[e.jsx(de,{className:"text-muted-foreground absolute left-3 top-1/2 h-4 w-4 -translate-y-1/2"}),e.jsx(y,{value:d,onChange:r=>f(r.target.value),placeholder:i,className:"pl-9"})]}),e.jsx(g,{variant:"outline",size:"icon",onClick:C,disabled:O,title:"Refresh models",children:O?e.jsx(G,{className:"h-4 w-4 animate-spin"}):e.jsx(U,{className:"h-4 w-4"})})]}),e.jsxs("div",{className:"flex flex-wrap gap-1",children:[e.jsxs(S,{variant:x===null?"default":"outline",className:"cursor-pointer",onClick:()=>n(null),children:["All (",o.length,")"]}),Object.keys(L).map(r=>{const a=_[r].length;return a===0?null:e.jsxs(S,{variant:x===r?"default":"outline",className:"cursor-pointer",onClick:()=>n(r),children:[L[r]," (",a,")"]},r)})]}),p&&e.jsxs("div",{className:"bg-muted rounded-md p-2 text-sm",children:[e.jsx("span",{className:"font-medium",children:p.name}),e.jsxs("span",{className:"text-muted-foreground ml-2",children:[$(p.pricing)," |"," ",re(p.context_length)]})]}),e.jsx(I,{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:C,children:"Retry"})]}):N.length===0?e.jsxs("div",{className:"text-muted-foreground p-4 text-center",children:['No models found matching "',d,'"']}):e.jsxs("div",{className:"space-y-6 p-3",children:[k&&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(V,{className:"h-3 w-3 text-accent"}),e.jsx("span",{children:"Newest Models"})]}),e.jsx("div",{className:"space-y-1",children:b.map(r=>e.jsx(te,{model:r,isSelected:r.id===s,onClick:()=>t(r.id),showAge:!0},r.id))})]}),Object.keys(L).map(r=>{const a=_[r];return a.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:L[r]}),e.jsx("div",{className:"space-y-1",children:a.map(v=>e.jsx(te,{model:v,isSelected:v.id===s,onClick:()=>t(v.id)},v.id))})]},r)})]})})]})}function te({model:s,isSelected:t,onClick:i,showAge:l=!1}){return e.jsxs("button",{type:"button",onClick:i,className:E("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",t&&"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:E("flex shrink-0 items-center gap-1 text-xs whitespace-nowrap",t?"text-accent-foreground/80":"text-muted-foreground group-hover:text-accent-foreground/80"),children:[l&&s.created&&e.jsx(S,{variant:"outline",className:E("text-[10px] px-1",t?"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:Ae(s.created)}),s.isFree?e.jsx(S,{variant:"secondary",className:E("text-[10px] px-1",t?"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(S,{variant:"outline",className:E("text-[10px] px-1 border-emerald-500/50 text-emerald-600",t?"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:$(s.pricing)})]}):e.jsx("span",{className:"tabular-nums",children:$(s.pricing)}),e.jsx("span",{className:"tabular-nums",children:re(s.context_length)})]})]})}function ls({selectedModel:s,value:t,onChange:i,className:l}){const{models:d}=ne(),f=c.useMemo(()=>s?Ee(s,d):{},[s,d]),x=()=>{i(f)},n=(m,j)=>{i({...t,[m]:j||void 0})},o=s&&Object.keys(f).length>0;return e.jsxs(ie,{className:E("group",l),children:[e.jsxs(le,{className:"flex items-center gap-2 text-sm font-medium hover:underline",children:[e.jsx(xe,{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(ce,{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."}),o&&e.jsxs(g,{type:"button",variant:"outline",size:"sm",onClick:x,children:[e.jsx(ze,{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:t.opus??"",onChange:m=>n("opus",m.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:t.sonnet??"",onChange:m=>n("sonnet",m.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:t.haiku??"",onChange:m=>n("haiku",m.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 cs({profileName:s,data:t,currentSettings:i,newEnvKey:l,newEnvValue:d,onNewEnvKeyChange:f,onNewEnvValueChange:x,onEnvValueChange:n,onAddEnvVar:o,onEnvBulkChange:m}){const j=pe(i),O=i?.env,A=c.useMemo(()=>ss(O??{}),[O]),N=O??{},b=a=>{if(m){const v={...N,ANTHROPIC_MODEL:a,ANTHROPIC_DEFAULT_OPUS_MODEL:a,ANTHROPIC_DEFAULT_SONNET_MODEL:a,ANTHROPIC_DEFAULT_HAIKU_MODEL:a};m(v)}else n("ANTHROPIC_MODEL",a),n("ANTHROPIC_DEFAULT_OPUS_MODEL",a),n("ANTHROPIC_DEFAULT_SONNET_MODEL",a),n("ANTHROPIC_DEFAULT_HAIKU_MODEL",a);Q.success("Applied model to all tiers",{duration:2e3})},k=a=>{if(m){const v=ts(N,a);m(v)}else a.opus!==void 0&&n("ANTHROPIC_DEFAULT_OPUS_MODEL",a.opus||""),a.sonnet!==void 0&&n("ANTHROPIC_DEFAULT_SONNET_MODEL",a.sonnet||""),a.haiku!==void 0&&n("ANTHROPIC_DEFAULT_HAIKU_MODEL",a.haiku||"")},[_,C]=c.useState(!1),p=new Set(["ANTHROPIC_AUTH_TOKEN"]),r=Object.entries(N).filter(([a])=>!p.has(a));return e.jsx("div",{className:"h-full w-full min-w-0 flex flex-col",children:e.jsxs(Te,{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(_e,{className:"w-full",children:[e.jsx(X,{value:"env",className:"flex-1",children:j?"Configuration":"Environment Variables"}),e.jsx(X,{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(Z,{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(is,{value:N.ANTHROPIC_MODEL,onChange:b,placeholder:"Search OpenRouter models..."})]}),e.jsx(ls,{selectedModel:N.ANTHROPIC_MODEL,value:A,onChange:k}),e.jsxs("div",{className:"space-y-2",children:[e.jsx(T,{className:"text-sm font-medium",children:"API Key"}),e.jsx(ge,{value:N.ANTHROPIC_AUTH_TOKEN||"",onChange:a=>n("ANTHROPIC_AUTH_TOKEN",a.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"})]})]}),r.length>0&&e.jsxs(ie,{open:_,onOpenChange:C,children:[e.jsxs(le,{className:"flex items-center gap-2 text-sm font-medium text-muted-foreground hover:text-foreground transition-colors group",children:[e.jsx(xe,{className:E("h-4 w-4 transition-transform",_&&"rotate-90")}),e.jsx(Je,{className:"h-4 w-4"}),e.jsx("span",{children:"Additional Variables"}),e.jsxs("span",{className:"text-xs font-normal opacity-70",children:["(",r.length,")"]})]}),e.jsx(ce,{className:"pt-4",children:e.jsx("div",{className:"space-y-3 border rounded-lg p-3 bg-muted/30",children:r.map(([a,v])=>e.jsxs("div",{className:"space-y-1",children:[e.jsx(T,{className:"text-xs text-muted-foreground",children:a}),e.jsx(y,{value:v,onChange:R=>n(a,R.target.value),className:"font-mono text-xs h-8"})]},a))})})]})]})}),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:l,onChange:a=>f(a.target.value.toUpperCase()),className:"font-mono text-sm h-8 w-2/5",onKeyDown:a=>a.key==="Enter"&&l.trim()&&o()}),e.jsx(y,{placeholder:"value",value:d,onChange:a=>x(a.target.value),className:"font-mono text-sm h-8 flex-1",onKeyDown:a=>a.key==="Enter"&&l.trim()&&o()}),e.jsx(g,{variant:"outline",size:"sm",className:"h-8",onClick:o,disabled:!l.trim(),children:e.jsx(D,{className:"w-4 h-4"})})]})]})]}):e.jsx(ns,{currentSettings:i,newEnvKey:l,newEnvValue:d,onNewEnvKeyChange:f,onNewEnvValueChange:x,onEnvValueChange:n,onAddEnvVar:o})}),e.jsx(Z,{value:"info",className:"h-full mt-0 border-0 p-0 data-[state=inactive]:hidden",children:e.jsx(rs,{profileName:s,data:t})})]})]})})}function os({profileName:s,onDelete:t,onHasChangesUpdate:i}){const[l,d]=c.useState({}),[f,x]=c.useState(!1),[n,o]=c.useState(null),[m,j]=c.useState(""),[O,A]=c.useState(""),N=Me(),{data:b,isLoading:k,isError:_,refetch:C}=De({queryKey:["settings",s],queryFn:async()=>{const h=await fetch(`/api/settings/${s}/raw`);if(!h.ok)throw new Error(`Failed to load settings: ${h.status}`);return h.json()}}),p=b?.settings,r=c.useMemo(()=>{if(n!==null)try{return JSON.parse(n)}catch{}if(p)return{...p,env:{...p.env,...l}}},[p,l,n]),a=c.useMemo(()=>n!==null?n:p?JSON.stringify(p,null,2):"",[n,p]),v=c.useCallback(h=>{o(h)},[]),R=(h,w)=>{const P={...r?.env||{},[h]:w};d(J=>({...J,[h]:w})),o(JSON.stringify({...r,env:P},null,2))},H=h=>{const w={...r?.env||{},...h};d(P=>({...P,...h})),o(JSON.stringify({...r,env:w},null,2))},F=()=>{if(!m.trim())return;const h=m.trim(),w=O,P={...r?.env||{},[h]:w};d(J=>({...J,[h]:w})),o(JSON.stringify({...r,env:P},null,2)),j(""),A("")},u=c.useMemo(()=>{try{return JSON.parse(a),!0}catch{return!1}},[a]),K=c.useMemo(()=>n!==null?n!==JSON.stringify(p,null,2):Object.keys(l).length>0,[n,l,p]),je=c.useMemo(()=>{const h=["ANTHROPIC_BASE_URL","ANTHROPIC_AUTH_TOKEN"],w=r?.env||{};return h.filter(P=>!w[P]?.trim())},[r]);c.useEffect(()=>{i?.(K)},[K,i]);const z=Ie({mutationFn:async()=>{let h;try{h=JSON.parse(a)}catch{h={...b?.settings,env:{...b?.settings?.env,...l}}}const w=await fetch(`/api/settings/${s}`,{method:"PUT",headers:{"Content-Type":"application/json"},body:JSON.stringify({settings:h,expectedMtime:b?.mtime})});if(w.status===409)throw new Error("CONFLICT");if(!w.ok)throw new Error("Failed to save");return w.json()},onSuccess:()=>{N.invalidateQueries({queryKey:["settings",s]}),N.invalidateQueries({queryKey:["profiles"]}),d({}),o(null),Q.success("Settings saved")},onError:h=>{h.message==="CONFLICT"?x(!0):Q.error(h.message)}}),Y=async h=>{x(!1),h?(await C(),z.mutate()):(d({}),o(null))};return e.jsxs("div",{className:"flex-1 flex flex-col overflow-hidden",children:[e.jsx(as,{profileName:s,data:b,settings:r,isLoading:k,isSaving:z.isPending,hasChanges:K,isRawJsonValid:u,onRefresh:()=>C(),onDelete:t,onSave:()=>z.mutate()}),k?e.jsxs("div",{className:"flex-1 flex items-center justify-center",children:[e.jsx(G,{className:"w-8 h-8 animate-spin text-muted-foreground"}),e.jsx("span",{className:"ml-3 text-muted-foreground",children:"Loading settings..."})]}):_?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:()=>C(),children:[e.jsx(U,{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(cs,{profileName:s,data:b,currentSettings:r,newEnvKey:m,newEnvValue:O,onNewEnvKeyChange:j,onNewEnvValueChange:A,onEnvValueChange:R,onEnvBulkChange:H,onAddEnvVar:F})}),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($e,{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:a,isRawJsonValid:u,rawJsonEdits:n,settings:p,onChange:v,missingRequiredFields:je})]})]}),e.jsx(B,{open:f,title:"File Modified Externally",description:"Overwrite with your changes or discard?",confirmText:"Overwrite",variant:"destructive",onConfirm:()=>Y(!0),onCancel:()=>Y(!1)})]},s)}const ae="ccs:openrouter-banner-dismissed";function ds({onCreateClick:s}){const[t,i]=c.useState(!0),{modelCount:l,isLoading:d}=q();c.useEffect(()=>{const x=localStorage.getItem(ae)==="true";i(x)},[]);const f=()=>{localStorage.setItem(ae,"true"),i(!0)};return t?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(V,{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 ",d?"300+":`${l}+`," 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(me,{className:"w-3 h-3"})]}),e.jsxs(g,{size:"icon",variant:"ghost",onClick:f,className:"h-7 w-7 text-white/70 hover:text-white hover:bg-white/20",children:[e.jsx(Be,{className:"w-4 h-4"}),e.jsx("span",{className:"sr-only",children:"Dismiss"})]})]})]})})}function xs({onOpenRouterClick:s,onCustomClick:t}){const{modelCount:i,isLoading:l}=q();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(Ve,{className:"border-accent/30 dark:border-accent/40 bg-gradient-to-br from-accent/5 to-background dark:from-accent/10",children:[e.jsxs(Ye,{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(S,{variant:"secondary",className:"bg-accent/10 text-accent dark:bg-accent/20 dark:text-accent-foreground",children:"Recommended"})]}),e.jsx(We,{className:"text-xl",children:"Start with OpenRouter"}),e.jsxs(Xe,{className:"text-base",children:["Access ",l?"300+":`${i}+`," models from OpenAI, Anthropic, Google, Meta and more - all through one API."]})]}),e.jsxs(Ze,{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(ue,{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(V,{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(Qe,{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(me,{className:"w-3 h-3"})]})]})]})]}),e.jsxs("div",{className:"flex items-center gap-4",children:[e.jsx(ee,{className:"flex-1"}),e.jsx("span",{className:"text-xs text-muted-foreground",children:"or"}),e.jsx(ee,{className:"flex-1"})]}),e.jsx(g,{variant:"outline",onClick:t,className:"w-full",children:"Create Custom API Profile"})]})})}function ms({onCreateClick:s}){const{modelCount:t,isLoading:i}=q();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:[i?"300+":`${t}+`," 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(ue,{className:"w-3 h-3 mr-1"}),e.jsx("span",{className:"text-xs",children:"Add"})]})]})})}function As(){const{data:s,isLoading:t,isError:i,refetch:l}=Se(),d=Pe(),[f,x]=c.useState(null),[n,o]=c.useState(""),[m,j]=c.useState(!1),[O,A]=c.useState("normal"),[N,b]=c.useState(null),[k,_]=c.useState(!1),[C,p]=c.useState(null);Re();const r=c.useMemo(()=>s?.profiles||[],[s?.profiles]),a=c.useMemo(()=>r.filter(u=>u.name.toLowerCase().includes(n.toLowerCase())),[r,n]),v=f?r.find(u=>u.name===f):null,R=u=>{d.mutate(u,{onSuccess:()=>{f===u&&x(null),b(null)}})},H=u=>{j(!1),k&&f!==null?p(u):x(u)},F=u=>{k&&f!==u?p(u):x(u)};return e.jsxs("div",{className:"h-[calc(100vh-100px)] flex flex-col",children:[e.jsx(ds,{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(qe,{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(D,{className:"w-4 h-4 mr-1"}),"New"]})]}),e.jsxs("div",{className:"relative",children:[e.jsx(de,{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:n,onChange:u=>o(u.target.value)})]})]}),e.jsx(I,{className:"flex-1",children:t?e.jsx("div",{className:"p-4 text-sm text-muted-foreground",children:"Loading profiles..."}):i?e.jsx("div",{className:"p-4 text-center",children:e.jsxs("div",{className:"space-y-3 py-8",children:[e.jsx(he,{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:()=>l(),children:[e.jsx(U,{className:"w-4 h-4 mr-1"}),"Retry"]})]})}):a.length===0?e.jsx("div",{className:"p-4 text-center",children:r.length===0?e.jsxs("div",{className:"space-y-3 py-8",children:[e.jsx(Ge,{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(D,{className:"w-4 h-4 mr-1"}),"Create Profile"]})]}):e.jsxs("p",{className:"text-sm text-muted-foreground py-4",children:['No profiles match "',n,'"']})}):e.jsx("div",{className:"p-2 space-y-1",children:a.map(u=>e.jsx(us,{profile:u,isSelected:f===u.name,onSelect:()=>F(u.name),onDelete:()=>b(u.name)},u.name))})}),r.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:[r.length," profile",r.length!==1?"s":""]}),e.jsxs("span",{className:"flex items-center gap-1",children:[e.jsx(fe,{className:"w-3 h-3 text-green-600"}),r.filter(u=>u.configured).length," configured"]})]})}),e.jsx(ms,{onCreateClick:()=>{A("openrouter"),j(!0)}})]}),e.jsx("div",{className:"flex-1 flex flex-col min-w-0",children:v?e.jsx(os,{profileName:v.name,onDelete:()=>b(v.name),onHasChangesUpdate:_},v.name):e.jsx(xs,{onOpenRouterClick:()=>{A("openrouter"),j(!0)},onCustomClick:()=>{A("normal"),j(!0)}})})]}),e.jsx(Le,{open:m,onOpenChange:j,onSuccess:H,initialMode:O}),e.jsx(B,{open:!!N,title:"Delete Profile",description:`Are you sure you want to delete "${N}"? This will remove the settings file and cannot be undone.`,confirmText:"Delete",variant:"destructive",onConfirm:()=>N&&R(N),onCancel:()=>b(null)}),e.jsx(B,{open:!!C,title:"Unsaved Changes",description:`You have unsaved changes in "${f}". Discard and switch to "${C}"?`,confirmText:"Discard & Switch",variant:"destructive",onConfirm:()=>{_(!1),x(C),p(null)},onCancel:()=>p(null)})]})}function us({profile:s,isSelected:t,onSelect:i,onDelete:l}){return e.jsxs("div",{className:E("group flex items-center gap-2 px-3 py-2.5 rounded-md cursor-pointer transition-colors",t?"bg-primary/10 border border-primary/20":"hover:bg-muted border border-transparent"),onClick:i,children:[s.configured?e.jsx(fe,{className:"w-4 h-4 text-green-600 shrink-0"}):e.jsx(he,{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(M,{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:d=>{d.stopPropagation(),l()},children:e.jsx(oe,{className:"w-3.5 h-3.5 text-destructive"})})]})}export{As as ApiPage};
|
|
@@ -1 +1 @@
|
|
|
1
|
-
import{j as e}from"./radix-ui-CBgg0XeO.js";import{r as t}from"./react-vendor-B_CU-WTZ.js";import{
|
|
1
|
+
import{j as e}from"./radix-ui-CBgg0XeO.js";import{r as t}from"./react-vendor-B_CU-WTZ.js";import{aI as Q,aD as V,aF as H,i as W,I as b,a as i}from"./index-D8K1YCe7.js";import{a0 as E,V as X,n as Y,k as Z,E as K,d as A,j as T,l as I,aB as _,Q as ee,R as se,aa as ae}from"./icons-CZDQWWm2.js";import"./tanstack-CxYN0q6L.js";import"./notifications-dJQY2-U6.js";import"./utils-CzKF5WmX.js";import"./form-utils-kUVlZZAO.js";import"./code-highlight-DKN39ySy.js";function ue(){const{fetchRawConfig:o}=Q(),[a,P]=t.useState(null),[g,v]=t.useState(!0),[n,c]=t.useState(!1),[x,r]=t.useState(null),[p,f]=t.useState(null),[y,R]=t.useState(!1),[j,z]=t.useState(!1),[d,w]=t.useState(null),[m,N]=t.useState(null),[L,C]=t.useState(!1),[U,k]=t.useState(!1),u=t.useCallback(async()=>{try{v(!0),r(null);const s=await fetch("/api/settings/auth/tokens/raw");if(!s.ok)throw new Error("Failed to fetch auth tokens");const l=await s.json();P(l)}catch(s){r(s instanceof Error?s.message:"Unknown error")}finally{v(!1)}},[]);t.useEffect(()=>{u(),o()},[u,o]),t.useEffect(()=>{if(p){const s=setTimeout(()=>f(null),3e3);return()=>clearTimeout(s)}},[p]),t.useEffect(()=>{if(x){const s=setTimeout(()=>r(null),5e3);return()=>clearTimeout(s)}},[x]);const F=async()=>{const s=d!==null&&d!==a?.apiKey.value,l=m!==null&&m!==a?.managementSecret.value;if(!(!s&&!l))try{c(!0),r(null);const h={};s&&(h.apiKey=d),l&&(h.managementSecret=m);const S=await fetch("/api/settings/auth/tokens",{method:"PUT",headers:{"Content-Type":"application/json"},body:JSON.stringify(h)});if(!S.ok){const J=await S.json();throw new Error(J.error||"Failed to save tokens")}f("Tokens updated. Restart CLIProxy to apply."),w(null),N(null),await u(),await o()}catch(h){r(h instanceof Error?h.message:"Unknown error")}finally{c(!1)}},D=async()=>{try{c(!0),r(null);const s=await fetch("/api/settings/auth/tokens/regenerate-secret",{method:"POST"});if(!s.ok){const l=await s.json();throw new Error(l.error||"Failed to regenerate secret")}f("New management secret generated. Restart CLIProxy to apply."),await u(),await o()}catch(s){r(s instanceof Error?s.message:"Unknown error")}finally{c(!1)}},O=async()=>{try{c(!0),r(null);const s=await fetch("/api/settings/auth/tokens/reset",{method:"POST"});if(!s.ok){const l=await s.json();throw new Error(l.error||"Failed to reset tokens")}f("Tokens reset to defaults. Restart CLIProxy to apply."),w(null),N(null),await u(),await o()}catch(s){r(s instanceof Error?s.message:"Unknown error")}finally{c(!1)}},$=async()=>{a&&(await navigator.clipboard.writeText(a.apiKey.value),C(!0),setTimeout(()=>C(!1),2e3))},B=async()=>{a&&(await navigator.clipboard.writeText(a.managementSecret.value),k(!0),setTimeout(()=>k(!1),2e3))};if(g||!a)return e.jsx("div",{className:"flex-1 flex items-center justify-center",children:e.jsxs("div",{className:"flex items-center gap-3 text-muted-foreground",children:[e.jsx(E,{className:"w-5 h-5 animate-spin"}),e.jsx("span",{children:"Loading..."})]})});const M=d??a.apiKey.value,q=m??a.managementSecret.value,G=d!==null&&d!==a.apiKey.value||m!==null&&m!==a.managementSecret.value;return e.jsxs(e.Fragment,{children:[e.jsxs("div",{className:`absolute left-5 right-5 top-20 z-10 transition-all duration-200 ease-out ${x||p?"opacity-100 translate-y-0":"opacity-0 -translate-y-2 pointer-events-none"}`,children:[x&&e.jsxs(V,{variant:"destructive",className:"py-2 shadow-lg",children:[e.jsx(X,{className:"h-4 w-4"}),e.jsx(H,{children:x})]}),p&&e.jsxs("div",{className:"flex items-center gap-2 px-3 py-2 rounded-md border border-green-200 bg-green-50 text-green-700 shadow-lg dark:border-green-900/50 dark:bg-green-900/90 dark:text-green-300",children:[e.jsx(Y,{className:"h-4 w-4 shrink-0"}),e.jsx("span",{className:"text-sm font-medium",children:p})]})]}),e.jsx(W,{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 CLIProxy authentication tokens. Changes require CLIProxy restart."}),e.jsxs("div",{className:"space-y-3",children:[e.jsxs("div",{className:"flex items-center gap-2",children:[e.jsx(Z,{className:"w-4 h-4 text-primary"}),e.jsx("h3",{className:"text-base font-medium",children:"API Key"}),a.apiKey.isCustom&&e.jsx("span",{className:"text-xs px-2 py-0.5 rounded bg-amber-100 text-amber-700 dark:bg-amber-900/50 dark:text-amber-300",children:"Custom"})]}),e.jsx("p",{className:"text-xs text-muted-foreground",children:"Used by Claude Code to authenticate with CLIProxy"}),e.jsx("div",{className:"flex gap-2",children:e.jsxs("div",{className:"relative flex-1",children:[e.jsx(b,{type:y?"text":"password",value:M,onChange:s=>w(s.target.value),placeholder:"API key",disabled:n,className:"pr-20 font-mono text-sm"}),e.jsxs("div",{className:"absolute right-2 top-1/2 -translate-y-1/2 flex gap-1",children:[e.jsx(i,{variant:"ghost",size:"sm",className:"h-7 w-7 p-0",onClick:()=>R(!y),children:y?e.jsx(K,{className:"w-4 h-4"}):e.jsx(A,{className:"w-4 h-4"})}),e.jsx(i,{variant:"ghost",size:"sm",className:"h-7 w-7 p-0",onClick:$,disabled:!a.apiKey.value,children:L?e.jsx(T,{className:"w-4 h-4 text-green-600"}):e.jsx(I,{className:"w-4 h-4"})})]})]})})]}),e.jsxs("div",{className:"space-y-3",children:[e.jsxs("div",{className:"flex items-center gap-2",children:[e.jsx(_,{className:"w-4 h-4 text-primary"}),e.jsx("h3",{className:"text-base font-medium",children:"Management Secret"}),a.managementSecret.isCustom&&e.jsx("span",{className:"text-xs px-2 py-0.5 rounded bg-amber-100 text-amber-700 dark:bg-amber-900/50 dark:text-amber-300",children:"Custom"})]}),e.jsx("p",{className:"text-xs text-muted-foreground",children:"Used by CCS dashboard to access CLIProxy management APIs"}),e.jsxs("div",{className:"flex gap-2",children:[e.jsxs("div",{className:"relative flex-1",children:[e.jsx(b,{type:j?"text":"password",value:q,onChange:s=>N(s.target.value),placeholder:"Management secret",disabled:n,className:"pr-20 font-mono text-sm"}),e.jsxs("div",{className:"absolute right-2 top-1/2 -translate-y-1/2 flex gap-1",children:[e.jsx(i,{variant:"ghost",size:"sm",className:"h-7 w-7 p-0",onClick:()=>z(!j),children:j?e.jsx(K,{className:"w-4 h-4"}):e.jsx(A,{className:"w-4 h-4"})}),e.jsx(i,{variant:"ghost",size:"sm",className:"h-7 w-7 p-0",onClick:B,disabled:!a.managementSecret.value,children:U?e.jsx(T,{className:"w-4 h-4 text-green-600"}):e.jsx(I,{className:"w-4 h-4"})})]})]}),e.jsx(i,{variant:"outline",size:"sm",onClick:D,disabled:n,title:"Generate new secure secret",children:e.jsx(ee,{className:"w-4 h-4"})})]})]}),e.jsxs("div",{className:"pt-4 border-t",children:[e.jsxs(i,{variant:"outline",size:"sm",onClick:O,disabled:n||!a.apiKey.isCustom&&!a.managementSecret.isCustom,className:"gap-2",children:[e.jsx(se,{className:"w-4 h-4"}),"Reset to Defaults"]}),e.jsx("p",{className:"text-xs text-muted-foreground mt-2",children:"Resets both API key and management secret to their default values."})]})]})}),e.jsxs("div",{className:"p-4 border-t bg-background flex gap-2",children:[e.jsxs(i,{variant:"outline",size:"sm",onClick:()=>{u(),o()},disabled:g||n,className:"flex-1",children:[e.jsx(E,{className:`w-4 h-4 mr-2 ${g?"animate-spin":""}`}),"Refresh"]}),e.jsxs(i,{variant:"default",size:"sm",onClick:F,disabled:!G||n,className:"flex-1",children:[e.jsx(ae,{className:`w-4 h-4 mr-2 ${n?"animate-pulse":""}`}),n?"Saving...":"Save"]})]})]})}export{ue as default};
|
|
@@ -1 +1 @@
|
|
|
1
|
-
import{j as r}from"./radix-ui-CBgg0XeO.js";import"./react-vendor-B_CU-WTZ.js";import{c as d}from"./index-
|
|
1
|
+
import{j as r}from"./radix-ui-CBgg0XeO.js";import"./react-vendor-B_CU-WTZ.js";import{c as d}from"./index-D8K1YCe7.js";function n({className:a,...t}){return r.jsx("div",{"data-slot":"card",className:d("bg-card text-card-foreground flex flex-col gap-6 rounded-xl border py-6 shadow-sm",a),...t})}function c({className:a,...t}){return r.jsx("div",{"data-slot":"card-header",className:d("@container/card-header grid auto-rows-min grid-rows-[auto_auto] items-start gap-2 px-6 has-data-[slot=card-action]:grid-cols-[1fr_auto] [.border-b]:pb-6",a),...t})}function i({className:a,...t}){return r.jsx("div",{"data-slot":"card-title",className:d("leading-none font-semibold",a),...t})}function l({className:a,...t}){return r.jsx("div",{"data-slot":"card-description",className:d("text-muted-foreground text-sm",a),...t})}function u({className:a,...t}){return r.jsx("div",{"data-slot":"card-content",className:d("px-6",a),...t})}export{n as C,u as a,c as b,i as c,l as d};
|
|
@@ -0,0 +1,3 @@
|
|
|
1
|
+
import{j as e,W as fs,X as js,Y as vs,Z as Ns,_ as ws}from"./radix-ui-CBgg0XeO.js";import{r as p}from"./react-vendor-B_CU-WTZ.js";import{u as Ke,a as me,b as bs}from"./tanstack-CxYN0q6L.js";import{a as w,c as P,P as ue,L as Z,I as xe,O as pe,Q as he,U as ge,V as fe,W as ee,X as $e,Y as ys,Z as qe,_ as ze,u as Qe,$ as je,a0 as ve,a1 as Ne,a2 as we,a3 as Be,a4 as Cs,a5 as _e,a6 as Ee,B as L,a7 as ks,m as Je,i as be,h as As,a8 as Ss,a9 as Ps,aa as Ms,ab as We,T as Ye,k as Xe,ac as Ts,l as Ze,ad as Os,ae as Ds,af as Y,ag as _s,ah as Es,ai as Is,aj as Ls,D as Rs,E as Fs,F as Ie,G as Le,ak as Us,al as Hs,am as Vs,an as Gs,ao as Ks,ap as $s,aq as qs,ar as zs,y as Qs,A as Bs,as as Js,at as Ws,au as Ys,av as Xs,aw as Zs,ax as et,S as st}from"./index-D8K1YCe7.js";import{t as F}from"./notifications-dJQY2-U6.js";import{b as es,L as q,m as ye,t as tt,j as z,l as at,ag as Ce,a0 as $,ah as Q,Q as J,ai as ss,aj as se,Z as te,I as nt,f as it,Y as ke,ak as rt,aa as ot,X as ae,O as ts,al as Re,q as X,am as lt,an as ct,a9 as as,n as dt,ao as mt,ad as ut,A as xt,ap as pt,aq as ht,S as gt,ar as Fe,as as ft,at as jt,U as vt,T as Ue,au as ns}from"./icons-CZDQWWm2.js";import{C as is,a as rs}from"./card-BmnReIPp.js";import{S as Ae,C as Nt}from"./confirm-dialog-CzpGAyFB.js";import{S as wt}from"./switch-CmGBdPfU.js";import{A as bt,a as yt,b as Ct,c as kt,d as At,e as St,f as Pt,g as Mt}from"./alert-dialog-LCg4HaeZ.js";import"./utils-CzKF5WmX.js";import"./form-utils-kUVlZZAO.js";import"./code-highlight-DKN39ySy.js";const B={agy:{provider:"agy",displayName:"Antigravity",defaultModel:"gemini-claude-opus-4-5-thinking",models:[{id:"gemini-claude-opus-4-5-thinking",name:"Claude Opus 4.5 Thinking",description:"Most capable, extended thinking",presetMapping:{default:"gemini-claude-opus-4-5-thinking",opus:"gemini-claude-opus-4-5-thinking",sonnet:"gemini-claude-sonnet-4-5-thinking",haiku:"gemini-claude-sonnet-4-5"}},{id:"gemini-claude-sonnet-4-5-thinking",name:"Claude Sonnet 4.5 Thinking",description:"Balanced with extended thinking",presetMapping:{default:"gemini-claude-sonnet-4-5-thinking",opus:"gemini-claude-opus-4-5-thinking",sonnet:"gemini-claude-sonnet-4-5-thinking",haiku:"gemini-claude-sonnet-4-5"}},{id:"gemini-claude-sonnet-4-5",name:"Claude Sonnet 4.5",description:"Fast and capable",presetMapping:{default:"gemini-claude-sonnet-4-5",opus:"gemini-claude-opus-4-5-thinking",sonnet:"gemini-claude-sonnet-4-5",haiku:"gemini-claude-sonnet-4-5"}},{id:"gemini-3-pro-preview",name:"Gemini 3 Pro",description:"Google latest model via Antigravity",presetMapping:{default:"gemini-3-pro-preview",opus:"gemini-3-pro-preview",sonnet:"gemini-3-pro-preview",haiku:"gemini-3-flash-preview"}},{id:"gemini-3-flash-preview",name:"Gemini 3 Flash",description:"Fast Gemini model via Antigravity",presetMapping:{default:"gemini-3-flash-preview",opus:"gemini-3-pro-preview",sonnet:"gemini-3-pro-preview",haiku:"gemini-3-flash-preview"}}]},gemini:{provider:"gemini",displayName:"Gemini",defaultModel:"gemini-2.5-pro",models:[{id:"gemini-3-pro-preview",name:"Gemini 3 Pro",tier:"paid",description:"Latest model, requires paid Google account",presetMapping:{default:"gemini-3-pro-preview",opus:"gemini-3-pro-preview",sonnet:"gemini-3-pro-preview",haiku:"gemini-3-flash-preview"}},{id:"gemini-3-flash-preview",name:"Gemini 3 Flash",tier:"paid",description:"Fast Gemini 3 model, requires paid Google account",presetMapping:{default:"gemini-3-flash-preview",opus:"gemini-3-pro-preview",sonnet:"gemini-3-pro-preview",haiku:"gemini-3-flash-preview"}},{id:"gemini-2.5-pro",name:"Gemini 2.5 Pro",description:"Stable, works with free Google account",presetMapping:{default:"gemini-2.5-pro",opus:"gemini-2.5-pro",sonnet:"gemini-2.5-pro",haiku:"gemini-2.5-flash"}}]},codex:{provider:"codex",displayName:"Codex",defaultModel:"gpt-5.1-codex-max",models:[{id:"gpt-5.1-codex-max",name:"Codex Max (5.1)",description:"Most capable Codex model",presetMapping:{default:"gpt-5.1-codex-max",opus:"gpt-5.1-codex-max-high",sonnet:"gpt-5.1-codex-max",haiku:"gpt-5.1-codex-mini-high"}},{id:"gpt-5.2",name:"GPT 5.2",description:"Latest GPT model",presetMapping:{default:"gpt-5.2",opus:"gpt-5.2",sonnet:"gpt-5.2",haiku:"gpt-5.2"}},{id:"gpt-5.1-codex-mini",name:"Codex Mini",description:"Fast and efficient Codex model"}]},qwen:{provider:"qwen",displayName:"Qwen",defaultModel:"qwen-coder-plus",models:[{id:"qwen-coder-plus",name:"Qwen Coder Plus",description:"Alibaba code-focused model"},{id:"qwen-max",name:"Qwen Max",description:"Most capable Qwen model"}]},iflow:{provider:"iflow",displayName:"iFlow",defaultModel:"iflow-default",models:[{id:"iflow-default",name:"iFlow Default",description:"Default iFlow model"}]},kiro:{provider:"kiro",displayName:"Kiro (AWS)",defaultModel:"kiro-claude-sonnet-4-5",models:[{id:"kiro-claude-opus-4-5",name:"Kiro Claude Opus 4.5",description:"Claude Opus 4.5 via Kiro (2.2x credit)",presetMapping:{default:"kiro-claude-opus-4-5",opus:"kiro-claude-opus-4-5",sonnet:"kiro-claude-sonnet-4-5",haiku:"kiro-claude-haiku-4-5"}},{id:"kiro-claude-sonnet-4-5",name:"Kiro Claude Sonnet 4.5",description:"Claude Sonnet 4.5 via Kiro (1.3x credit)",presetMapping:{default:"kiro-claude-sonnet-4-5",opus:"kiro-claude-opus-4-5",sonnet:"kiro-claude-sonnet-4-5",haiku:"kiro-claude-haiku-4-5"}},{id:"kiro-claude-sonnet-4",name:"Kiro Claude Sonnet 4",description:"Claude Sonnet 4 via Kiro (1.3x credit)",presetMapping:{default:"kiro-claude-sonnet-4",opus:"kiro-claude-opus-4-5",sonnet:"kiro-claude-sonnet-4",haiku:"kiro-claude-haiku-4-5"}},{id:"kiro-claude-haiku-4-5",name:"Kiro Claude Haiku 4.5",description:"Claude Haiku 4.5 via Kiro (0.4x credit)"}]},ghcp:{provider:"ghcp",displayName:"GitHub Copilot (OAuth)",defaultModel:"claude-sonnet-4.5",models:[{id:"claude-opus-4.5",name:"Claude Opus 4.5",description:"Anthropic Claude Opus 4.5 via GitHub Copilot",presetMapping:{default:"claude-opus-4.5",opus:"claude-opus-4.5",sonnet:"claude-sonnet-4.5",haiku:"claude-haiku-4.5"}},{id:"claude-sonnet-4.5",name:"Claude Sonnet 4.5",description:"Anthropic Claude Sonnet 4.5 via GitHub Copilot",presetMapping:{default:"claude-sonnet-4.5",opus:"claude-opus-4.5",sonnet:"claude-sonnet-4.5",haiku:"claude-haiku-4.5"}},{id:"claude-sonnet-4",name:"Claude Sonnet 4",description:"Anthropic Claude Sonnet 4 via GitHub Copilot"},{id:"claude-haiku-4.5",name:"Claude Haiku 4.5",description:"Anthropic Claude Haiku 4.5 via GitHub Copilot"},{id:"gpt-5.2",name:"GPT-5.2",description:"OpenAI GPT-5.2 via GitHub Copilot",presetMapping:{default:"gpt-5.2",opus:"gpt-5.2",sonnet:"gpt-5.1",haiku:"gpt-5-mini"}},{id:"gpt-5.1",name:"GPT-5.1",description:"OpenAI GPT-5.1 via GitHub Copilot"},{id:"gpt-5",name:"GPT-5",description:"OpenAI GPT-5 via GitHub Copilot"},{id:"gpt-5-mini",name:"GPT-5 Mini",description:"OpenAI GPT-5 Mini via GitHub Copilot"},{id:"gemini-3-pro",name:"Gemini 3 Pro",description:"Google Gemini 3 Pro via GitHub Copilot"}]}},ce=8317,ie="ccs-internal-managed";async function Tt(){try{const s=await fetch("/api/settings/auth/tokens/raw");return s.ok?(await s.json())?.apiKey?.value??ie:ie}catch{return ie}}async function de(s,n){const t=B[s];if(!t)return{success:!1};const a=t.models[0],i=a?.presetMapping||{default:t.defaultModel,opus:t.defaultModel,sonnet:t.defaultModel,haiku:t.defaultModel},l=await Tt(),u={env:{ANTHROPIC_BASE_URL:`http://127.0.0.1:${ce}/api/provider/${s}`,ANTHROPIC_AUTH_TOKEN:l,ANTHROPIC_MODEL:i.default,ANTHROPIC_DEFAULT_OPUS_MODEL:i.opus,ANTHROPIC_DEFAULT_SONNET_MODEL:i.sonnet,ANTHROPIC_DEFAULT_HAIKU_MODEL:i.haiku}};try{return{success:(await fetch(`/api/settings/${s}`,{method:"PUT",headers:{"Content-Type":"application/json"},body:JSON.stringify({settings:u})})).ok,presetName:a?.name||t.defaultModel}}catch{return{success:!1}}}const He=[{id:"gemini",name:"Google Gemini",description:"Gemini Pro/Flash models"},{id:"codex",name:"OpenAI Codex",description:"GPT-4 and codex models"},{id:"agy",name:"Antigravity",description:"Antigravity AI models"},{id:"qwen",name:"Alibaba Qwen",description:"Qwen Code models"},{id:"iflow",name:"iFlow",description:"iFlow AI models"},{id:"kiro",name:"Kiro (AWS)",description:"AWS CodeWhisperer models"},{id:"ghcp",name:"GitHub Copilot (OAuth)",description:"GitHub Copilot via OAuth"}],os=["provider","auth","variant","success"];function Ot(s){return s==="account"?1:os.indexOf(s)}function Dt({currentProgress:s,allSteps:n}){return e.jsx("div",{className:"flex justify-center gap-1 pt-2",children:n.map((t,a)=>e.jsx("div",{className:`w-2 h-2 rounded-full transition-colors ${s>=a?"bg-primary":"bg-muted"}`},t))})}function _t({providers:s,onSelect:n}){return e.jsx("div",{className:"grid gap-2",children:s.map(t=>e.jsxs("button",{onClick:()=>n(t.id),className:"flex items-center justify-between p-3 border rounded-lg hover:bg-muted/50 transition-colors text-left",children:[e.jsxs("div",{children:[e.jsx("div",{className:"font-medium",children:t.name}),e.jsx("div",{className:"text-xs text-muted-foreground",children:t.description})]}),e.jsx(es,{className:"w-4 h-4 text-muted-foreground"})]},t.id))})}function Et({selectedProvider:s,providers:n,authCommand:t,isRefreshing:a,isPending:i,onBack:l,onStartAuth:c,onRefresh:u}){const[r,d]=p.useState(!1),h=async x=>{await navigator.clipboard.writeText(x),d(!0),setTimeout(()=>d(!1),2e3)};return e.jsxs("div",{className:"space-y-4",children:[e.jsxs("div",{className:"text-center space-y-3",children:[e.jsxs("p",{className:"text-sm text-muted-foreground",children:["Authenticate with ",n.find(x=>x.id===s)?.name," to add an account"]}),e.jsx(w,{onClick:c,disabled:i,className:"w-full gap-2",size:"lg",children:i?e.jsxs(e.Fragment,{children:[e.jsx(q,{className:"w-4 h-4 animate-spin"}),"Authenticating..."]}):e.jsxs(e.Fragment,{children:[e.jsx(ye,{className:"w-4 h-4"}),"Authenticate in Browser"]})}),i&&e.jsx("p",{className:"text-xs text-muted-foreground",children:"Complete the OAuth flow in your browser..."})]}),e.jsxs("div",{className:"relative",children:[e.jsx("div",{className:"absolute inset-0 flex items-center",children:e.jsx("span",{className:"w-full border-t"})}),e.jsx("div",{className:"relative flex justify-center text-xs uppercase",children:e.jsx("span",{className:"bg-background px-2 text-muted-foreground",children:"Or use terminal"})})]}),e.jsx(is,{children:e.jsxs(rs,{className:"p-4 space-y-3",children:[e.jsxs("div",{className:"flex items-center gap-2 text-sm text-muted-foreground",children:[e.jsx(tt,{className:"w-4 h-4"}),"Run this command in your terminal:"]}),e.jsxs("div",{className:"flex items-center gap-2",children:[e.jsx("code",{className:"flex-1 px-3 py-2 bg-muted rounded-md font-mono text-sm",children:t}),e.jsx(w,{variant:"outline",size:"icon",onClick:()=>h(t),children:r?e.jsx(z,{className:"w-4 h-4 text-green-500"}):e.jsx(at,{className:"w-4 h-4"})})]})]})}),e.jsxs("div",{className:"flex items-center justify-between",children:[e.jsxs(w,{variant:"ghost",onClick:l,disabled:i,children:[e.jsx(Ce,{className:"w-4 h-4 mr-2"}),"Back"]}),e.jsxs(w,{variant:"outline",onClick:u,disabled:a||i,children:[e.jsx($,{className:`w-4 h-4 mr-2 ${a?"animate-spin":""}`}),a?"Checking...":"Refresh Status"]})]})]})}function It({accounts:s,privacyMode:n,onSelect:t,onAddNew:a,onBack:i}){return e.jsxs("div",{className:"space-y-4",children:[e.jsxs("div",{className:"text-xs font-medium text-muted-foreground uppercase tracking-wide",children:["Select an account (",s.length,")"]}),e.jsx("div",{className:"grid gap-2",children:s.map(l=>e.jsxs("button",{type:"button",onClick:()=>t(l),className:"flex items-center justify-between p-3 border rounded-lg hover:bg-muted/50 transition-colors text-left",children:[e.jsxs("div",{className:"flex items-center gap-3",children:[e.jsx("div",{className:"w-8 h-8 rounded-full bg-muted flex items-center justify-center",children:e.jsx(Q,{className:"w-4 h-4 text-muted-foreground"})}),e.jsxs("div",{children:[e.jsx("div",{className:P("font-medium",n&&ue),children:l.email||l.id}),l.isDefault&&e.jsx("div",{className:"text-xs text-muted-foreground",children:"Default account"})]})]}),e.jsx(es,{className:"w-4 h-4 text-muted-foreground"})]},l.id))}),e.jsxs("div",{className:"relative",children:[e.jsx("div",{className:"absolute inset-0 flex items-center",children:e.jsx("span",{className:"w-full border-t"})}),e.jsx("div",{className:"relative flex justify-center text-xs uppercase",children:e.jsx("span",{className:"bg-background px-2 text-muted-foreground",children:"Or"})})]}),e.jsxs("button",{type:"button",className:"w-full flex items-center gap-3 p-3 border-2 border-dashed border-primary/50 rounded-lg hover:border-primary hover:bg-primary/5 transition-colors text-left",onClick:a,children:[e.jsx("div",{className:"w-8 h-8 rounded-full bg-primary/10 flex items-center justify-center shrink-0",children:e.jsx(ye,{className:"w-4 h-4 text-primary"})}),e.jsxs("div",{children:[e.jsx("div",{className:"font-medium text-primary",children:"Add new account"}),e.jsx("div",{className:"text-xs text-muted-foreground",children:"Authenticate with a different account"})]})]}),e.jsx("div",{className:"flex items-center justify-between pt-2",children:e.jsxs(w,{variant:"ghost",onClick:i,children:[e.jsx(Ce,{className:"w-4 h-4 mr-2"}),"Back"]})})]})}function Lt({selectedProvider:s,selectedAccount:n,variantName:t,modelName:a,isPending:i,privacyMode:l,onVariantNameChange:c,onModelChange:u,onBack:r,onSkip:d,onCreate:h}){return e.jsxs("div",{className:"space-y-4",children:[n&&e.jsxs("div",{className:"flex items-center gap-2 p-2 bg-muted/50 rounded-md text-sm",children:[e.jsx(Q,{className:"w-4 h-4"}),e.jsxs("span",{children:["Using:"," ",e.jsx("span",{className:P(l&&ue),children:n.email||n.id})]})]}),e.jsxs("div",{className:"space-y-2",children:[e.jsx(Z,{htmlFor:"variant-name",children:"Variant Name *"}),e.jsx(xe,{id:"variant-name",value:t,onChange:x=>c(x.target.value),placeholder:"e.g., my-gemini, g3, flash"}),e.jsxs("div",{className:"text-xs text-muted-foreground",children:["Use this name to invoke: ccs ",t||"<name>",' "prompt"']})]}),e.jsxs("div",{className:"space-y-2",children:[e.jsx(Z,{children:"Model"}),e.jsxs(pe,{value:a,onValueChange:u,children:[e.jsx(he,{children:e.jsx(ge,{placeholder:"Select a model"})}),e.jsx(fe,{children:B[s]?.models.map(x=>e.jsx(ee,{value:x.id,children:e.jsxs("div",{className:"flex items-center gap-2",children:[e.jsx("span",{children:x.name}),x.description&&e.jsxs("span",{className:"text-xs text-muted-foreground",children:["- ",x.description]})]})},x.id))})]}),e.jsxs("div",{className:"text-xs text-muted-foreground",children:["Default: ",B[s]?.defaultModel||"provider default"]})]}),e.jsxs("div",{className:"flex items-center justify-between pt-2",children:[e.jsxs(w,{variant:"ghost",onClick:r,children:[e.jsx(Ce,{className:"w-4 h-4 mr-2"}),"Back"]}),e.jsxs("div",{className:"flex items-center gap-2",children:[e.jsx(w,{variant:"ghost",onClick:d,children:"Skip"}),e.jsx(w,{onClick:h,disabled:!t||i,children:i?"Creating...":"Create Variant"})]})]}),e.jsx("p",{className:"text-xs text-center text-muted-foreground",children:"Skip if you just wanted to add an account without creating a variant"})]})}function Rt({variantName:s,onClose:n}){return e.jsxs("div",{className:"space-y-4 text-center",children:[e.jsx("div",{className:"flex justify-center",children:e.jsx("div",{className:"w-16 h-16 bg-green-100 dark:bg-green-900/30 rounded-full flex items-center justify-center",children:e.jsx(z,{className:"w-8 h-8 text-green-600 dark:text-green-400"})})}),e.jsxs("div",{children:[e.jsx("div",{className:"font-semibold text-lg",children:"Variant Created!"}),e.jsx("div",{className:"text-sm text-muted-foreground",children:"Your custom variant is ready to use"})]}),e.jsx(is,{children:e.jsxs(rs,{className:"p-4 space-y-2",children:[e.jsx("div",{className:"text-sm text-muted-foreground",children:"Usage:"}),e.jsxs("code",{className:"block px-3 py-2 bg-muted rounded-md font-mono text-sm",children:["ccs ",s,' "your prompt here"']})]})}),e.jsx(w,{onClick:n,className:"w-full",children:"Done"})]})}function Ft({open:s,onClose:n}){const[t,a]=p.useState("provider"),[i,l]=p.useState(""),[c,u]=p.useState(null),[r,d]=p.useState(""),[h,x]=p.useState(""),[g,o]=p.useState(!1),[b,A]=p.useState(!1),{data:v,refetch:D}=$e(),k=ys(),O=qe(),M=ze(),{privacyMode:I}=Qe(),y=v?.authStatus.find(N=>N.provider===i),j=p.useMemo(()=>y?.accounts||[],[y?.accounts]);p.useEffect(()=>{if(!s){const N=setTimeout(()=>{a("provider"),l(""),u(null),d(""),x(""),A(!1)},0);return()=>clearTimeout(N)}},[s]),p.useEffect(()=>{if(t==="auth"&&j.length>0&&!b){const N=setTimeout(()=>{a("account")},0);return()=>clearTimeout(N)}},[t,j,b]);const f=async()=>{o(!0),await D(),o(!1)},S=()=>{const N=(y?.accounts?.length||0)===0;O.mutate({provider:i},{onSuccess:async H=>{if(N){const V=await de(i);V.success&&V.presetName?F.success(`Applied "${V.presetName}" preset`):V.success||F.warning("Account added, but failed to apply default preset")}H.account&&(u(H.account),a("variant")),D()}})},_=N=>{l(N),(v?.authStatus.find(ne=>ne.provider===N)?.accounts||[]).length===0?a("auth"):a("account")},R=N=>{u(N),a("variant")},U=async()=>{if(!(!r||!i))try{await k.mutateAsync({name:r,provider:i,model:h||void 0,account:c?.id}),a("success")}catch(N){console.error("Failed to create variant:",N)}},m=`ccs ${i} --auth --add`,C=Ot(t),T=N=>{if(!N&&(O.isPending&&i&&M.mutate(i),t==="success"||t==="provider")){n();return}};return e.jsx(je,{open:s,onOpenChange:T,children:e.jsxs(ve,{className:"sm:max-w-lg",onPointerDownOutside:N=>{t!=="success"&&t!=="provider"&&N.preventDefault()},onEscapeKeyDown:N=>{(O.isPending||k.isPending)&&N.preventDefault()},children:[e.jsxs(Ne,{children:[e.jsxs(we,{className:"flex items-center gap-2",children:[e.jsx(J,{className:"w-5 h-5 text-primary"}),"Quick Setup Wizard"]}),e.jsxs(Be,{children:[t==="provider"&&"Select a provider to get started",t==="auth"&&"Authenticate with your provider",t==="account"&&"Select which account to use",t==="variant"&&"Create your custom variant",t==="success"&&"Setup complete!"]})]}),e.jsxs("div",{className:"space-y-4 py-4",children:[t==="provider"&&e.jsx(_t,{providers:He,onSelect:_}),t==="auth"&&e.jsx(Et,{selectedProvider:i,providers:He,authCommand:m,isRefreshing:g,isPending:O.isPending,onBack:()=>a("provider"),onStartAuth:S,onRefresh:f}),t==="account"&&e.jsx(It,{accounts:j,privacyMode:I,onSelect:R,onAddNew:()=>{A(!0),a("auth")},onBack:()=>a("provider")}),t==="variant"&&e.jsx(Lt,{selectedProvider:i,selectedAccount:c,variantName:r,modelName:h,isPending:k.isPending,privacyMode:I,onVariantNameChange:d,onModelChange:x,onBack:()=>j.length>0?a("account"):a("provider"),onSkip:n,onCreate:U}),t==="success"&&e.jsx(Rt,{variantName:r,onClose:n})]}),e.jsx(Dt,{currentProgress:C,allSteps:os})]})})}function Ut({open:s,onClose:n,provider:t,displayName:a,isFirstAccount:i=!1}){const[l,c]=p.useState(""),u=qe(),r=Cs(),d=ze(),h=t==="kiro",x=u.isPending||r.isPending,g=()=>{x&&d.mutate(t),c(""),n()},o=()=>{u.mutate({provider:t,nickname:l.trim()||void 0},{onSuccess:async()=>{const v=await de(t);v.success&&v.presetName?i&&F.success(`Applied "${v.presetName}" preset`):v.success||F.warning("Account added, but failed to apply default preset. You may need to configure settings manually."),c(""),n()}})},b=()=>{r.mutate(void 0,{onSuccess:async()=>{const v=await de("kiro");v.success&&v.presetName&&i&&F.success(`Applied "${v.presetName}" preset`),c(""),n()}})},A=v=>{v||g()};return e.jsx(je,{open:s,onOpenChange:A,children:e.jsxs(ve,{className:"sm:max-w-md",children:[e.jsxs(Ne,{children:[e.jsxs(we,{children:["Add ",a," Account"]}),e.jsx(Be,{children:h?"Authenticate via browser or import an existing token from Kiro IDE.":"Click the button below to authenticate a new account. A browser window will open for OAuth."})]}),e.jsxs("div",{className:"space-y-4 py-4",children:[e.jsxs("div",{className:"space-y-2",children:[e.jsx(Z,{htmlFor:"nickname",children:"Nickname (optional)"}),e.jsxs("div",{className:"flex items-center gap-2",children:[e.jsx(Q,{className:"w-4 h-4 text-muted-foreground"}),e.jsx(xe,{id:"nickname",value:l,onChange:v=>c(v.target.value),placeholder:"e.g., work, personal",disabled:x,className:"flex-1"})]}),e.jsx("p",{className:"text-xs text-muted-foreground",children:"A friendly name to identify this account. Auto-generated from email if left empty."})]}),e.jsxs("div",{className:"flex items-center justify-end gap-2 pt-2",children:[e.jsx(w,{variant:"ghost",onClick:g,children:"Cancel"}),h&&e.jsx(w,{variant:"outline",onClick:b,disabled:x,children:r.isPending?e.jsxs(e.Fragment,{children:[e.jsx(q,{className:"w-4 h-4 mr-2 animate-spin"}),"Importing..."]}):e.jsxs(e.Fragment,{children:[e.jsx(ss,{className:"w-4 h-4 mr-2"}),"Import from IDE"]})}),e.jsx(w,{onClick:o,disabled:x,children:u.isPending?e.jsxs(e.Fragment,{children:[e.jsx(q,{className:"w-4 h-4 mr-2 animate-spin"}),"Authenticating..."]}):e.jsxs(e.Fragment,{children:[e.jsx(ye,{className:"w-4 h-4 mr-2"}),"Authenticate"]})})]}),u.isPending&&e.jsx("p",{className:"text-sm text-center text-muted-foreground",children:"Complete the OAuth flow in your browser..."}),r.isPending&&e.jsx("p",{className:"text-sm text-center text-muted-foreground",children:"Importing token from Kiro IDE..."})]})]})})}const Ht=["ANTHROPIC_BASE_URL","ANTHROPIC_AUTH_TOKEN"];function Vt(s){const n=s?.env||{};return Ht.filter(t=>!n[t]?.trim())}function Gt(s){const[n,t]=p.useState(null),[a,i]=p.useState(!1),l=Ke(),{data:c,isLoading:u,refetch:r}=me({queryKey:["settings",s],queryFn:async()=>{const f=await fetch(`/api/settings/${s}/raw`);return f.ok?f.json():{profile:s,settings:{env:{}},mtime:Date.now(),path:`~/.ccs/profiles/${s}/settings.json`}}}),d=c?.settings,h=p.useMemo(()=>n!==null?n:d?JSON.stringify(d,null,2):`{
|
|
2
|
+
"env": {}
|
|
3
|
+
}`,[n,d]),x=p.useCallback(f=>{t(f)},[]),g=p.useMemo(()=>{try{return JSON.parse(h)}catch{return d||{env:{}}}},[h,d]),o=g?.env?.ANTHROPIC_MODEL,b=g?.env?.ANTHROPIC_DEFAULT_OPUS_MODEL,A=g?.env?.ANTHROPIC_DEFAULT_SONNET_MODEL,v=g?.env?.ANTHROPIC_DEFAULT_HAIKU_MODEL,D=p.useCallback((f,S)=>{const _={...g?.env||{},[f]:S},R={...g,env:_};t(JSON.stringify(R,null,2))},[g]),k=p.useCallback(f=>{const S={...g?.env||{},...f},_={...g,env:S};t(JSON.stringify(_,null,2))},[g]),O=p.useMemo(()=>{try{return JSON.parse(h),!0}catch{return!1}},[h]),M=p.useMemo(()=>n===null?!1:n!==JSON.stringify(d,null,2),[n,d]),I=p.useMemo(()=>Vt(g),[g]),y=bs({mutationFn:async()=>{const f=JSON.parse(h),S=await fetch(`/api/settings/${s}`,{method:"PUT",headers:{"Content-Type":"application/json"},body:JSON.stringify({settings:f,expectedMtime:c?.mtime})});if(S.status===409)throw new Error("CONFLICT");if(!S.ok)throw new Error("Failed to save");return S.json()},onSuccess:f=>{l.invalidateQueries({queryKey:["settings",s]}),t(null),f?.warning?F.success("Settings saved",{description:f.warning}):F.success("Settings saved")},onError:f=>{f.message==="CONFLICT"?i(!0):F.error(f.message)}}),j=async f=>{i(!1),f?(await r(),y.mutate()):t(null)};return{data:c,isLoading:u,refetch:r,rawJsonContent:h,rawJsonEdits:n,isRawJsonValid:O,hasChanges:M,currentSettings:g,currentModel:o,opusModel:b,sonnetModel:A,haikuModel:v,handleRawJsonChange:x,updateEnvValue:D,updateEnvValues:k,saveMutation:{mutate:()=>y.mutate(),isPending:y.isPending},conflictDialog:a,setConflictDialog:i,handleConflictResolve:j,missingRequiredFields:I}}function K({label:s,description:n,value:t,onChange:a,catalog:i,allModels:l,disabled:c}){const u=new Set(i?.models.map(r=>r.id)||[]);return e.jsxs("div",{className:"space-y-1.5",children:[e.jsxs("div",{children:[e.jsx("label",{className:"text-xs font-medium",children:s}),n&&e.jsx("p",{className:"text-[10px] text-muted-foreground",children:n})]}),e.jsxs(pe,{value:t||"",onValueChange:a,disabled:c,children:[e.jsx(he,{className:"h-9",children:e.jsx(ge,{placeholder:"Select model",children:t&&e.jsx("span",{className:"truncate font-mono text-xs",children:t})})}),e.jsxs(fe,{className:"max-h-[300px]",children:[i&&i.models.length>0&&e.jsxs(_e,{children:[e.jsx(Ee,{className:"text-xs text-primary",children:"Recommended"}),i.models.map(r=>e.jsx(ee,{value:r.id,children:e.jsxs("div",{className:"flex items-center gap-2",children:[e.jsx("span",{className:"truncate font-mono text-xs",children:r.id}),r.tier==="paid"&&e.jsx(L,{variant:"outline",className:"text-[9px] h-4 px-1",children:"PAID"}),t===r.id&&e.jsx(z,{className:"w-3 h-3 text-primary ml-auto"})]})},r.id))]}),l.length>0&&e.jsxs(_e,{children:[e.jsxs(Ee,{className:"text-xs text-muted-foreground",children:["All Models (",l.length,")"]}),l.filter(r=>!u.has(r.id)).map(r=>e.jsx(ee,{value:r.id,children:e.jsxs("div",{className:"flex items-center gap-2",children:[e.jsx("span",{className:"truncate font-mono text-xs",children:r.id}),t===r.id&&e.jsx(z,{className:"w-3 h-3 text-primary ml-auto"})]})},r.id))]}),(!i||i.models.length===0)&&l.length===0&&e.jsx("div",{className:"py-2 px-3 text-xs text-muted-foreground",children:"No models available"})]})]})]})}function Kt({open:s,onClose:n,currentValues:t,onApply:a,onSave:i,isSaving:l,catalog:c,allModels:u}){const[r,d]=p.useState(t),[h,x]=p.useState(""),g=o=>{o?(d(t),x("")):n()};return e.jsx(je,{open:s,onOpenChange:g,children:e.jsxs(ve,{className:"sm:max-w-md",children:[e.jsx(Ne,{children:e.jsxs(we,{className:"flex items-center gap-2",children:[e.jsx(J,{className:"w-4 h-4"}),"Custom Preset"]})}),e.jsxs("div",{className:"space-y-4 py-4",children:[e.jsxs("div",{className:"space-y-2",children:[e.jsx(Z,{htmlFor:"preset-name",children:"Preset Name (optional)"}),e.jsx(xe,{id:"preset-name",value:h,onChange:o=>x(o.target.value),placeholder:"e.g., My Custom Config",className:"text-sm"})]}),e.jsx(Ae,{}),e.jsx(K,{label:"Default Model",description:"Used when no specific tier is requested",value:r.default,onChange:o=>d({...r,default:o}),catalog:c,allModels:u}),e.jsx(K,{label:"Opus (Most capable)",description:"For complex reasoning tasks",value:r.opus,onChange:o=>d({...r,opus:o}),catalog:c,allModels:u}),e.jsx(K,{label:"Sonnet (Balanced)",description:"Balance of speed and capability",value:r.sonnet,onChange:o=>d({...r,sonnet:o}),catalog:c,allModels:u}),e.jsx(K,{label:"Haiku (Fast)",description:"Quick responses for simple tasks",value:r.haiku,onChange:o=>d({...r,haiku:o}),catalog:c,allModels:u})]}),e.jsxs(ks,{className:"gap-2 sm:gap-0",children:[e.jsx(w,{variant:"outline",onClick:n,children:"Cancel"}),i&&e.jsxs(w,{variant:"secondary",onClick:()=>i(r,h||void 0),disabled:l||!h.trim(),children:[l?e.jsx(q,{className:"w-4 h-4 mr-1 animate-spin"}):e.jsx(se,{className:"w-4 h-4 mr-1"}),"Save Preset"]}),e.jsxs(w,{onClick:()=>a(r,h||void 0),children:[e.jsx(te,{className:"w-4 h-4 mr-1"}),"Apply Preset"]})]})]})})}function W({label:s,command:n}){return e.jsxs("div",{children:[e.jsx("label",{className:"text-xs text-muted-foreground",children:s}),e.jsxs("div",{className:"mt-1 flex gap-2",children:[e.jsx("code",{className:"flex-1 px-2 py-1.5 bg-muted rounded text-xs font-mono truncate",children:n}),e.jsx(Je,{value:n,size:"icon",className:"h-6 w-6"})]})]})}function $t({provider:s,displayName:n,data:t,authStatus:a}){return e.jsx(be,{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(nt,{className:"w-4 h-4"}),"Provider Information"]}),e.jsxs("div",{className:"space-y-3 bg-card rounded-lg border p-4 shadow-sm",children:[e.jsxs("div",{className:"grid grid-cols-[100px_1fr] gap-2 text-sm items-center",children:[e.jsx("span",{className:"font-medium text-muted-foreground",children:"Provider"}),e.jsx("span",{className:"font-mono",children:n})]}),t&&e.jsxs(e.Fragment,{children:[e.jsxs("div",{className:"grid grid-cols-[100px_1fr] gap-2 text-sm items-center",children:[e.jsx("span",{className:"font-medium text-muted-foreground",children:"File Path"}),e.jsxs("div",{className:"flex items-center gap-2 min-w-0",children:[e.jsx("code",{className:"bg-muted px-1.5 py-0.5 rounded text-xs break-all",children:t.path}),e.jsx(Je,{value:t.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(t.mtime).toLocaleString()})]})]}),e.jsxs("div",{className:"grid grid-cols-[100px_1fr] gap-2 text-sm items-center",children:[e.jsx("span",{className:"font-medium text-muted-foreground",children:"Status"}),a.authenticated?e.jsxs(L,{variant:"outline",className:"w-fit text-green-600 border-green-200 bg-green-50",children:[e.jsx(it,{className:"w-3 h-3 mr-1"}),"Authenticated"]}):e.jsx(L,{variant:"outline",className:"w-fit text-muted-foreground",children:"Not connected"})]})]})]}),e.jsxs("div",{children:[e.jsx("h3",{className:"text-sm font-medium mb-3",children:"Quick Usage"}),e.jsxs("div",{className:"space-y-3 bg-card rounded-lg border p-4 shadow-sm",children:[e.jsx(W,{label:"Run with prompt",command:`ccs ${s} "your prompt"`}),e.jsx(W,{label:"Change model",command:`ccs ${s} --config`}),e.jsx(W,{label:"Add account",command:`ccs ${s} --add`}),e.jsx(W,{label:"List accounts",command:`ccs ${s} --accounts`})]})]})]})})}const qt={gemini:"/assets/providers/gemini-color.svg",codex:"/assets/providers/openai.svg",agy:"/assets/providers/agy.png",qwen:"/assets/providers/qwen-color.svg",iflow:"/assets/providers/iflow.png",kiro:"/assets/providers/kiro.png",ghcp:"/assets/providers/copilot.svg"},zt={gemini:{text:"text-blue-600",letter:"G"},claude:{text:"text-orange-600",letter:"C"},codex:{text:"text-emerald-600",letter:"X"},agy:{text:"text-violet-600",letter:"A"},qwen:{text:"text-cyan-600",letter:"Q"},iflow:{text:"text-indigo-600",letter:"i"},kiro:{text:"text-teal-600",letter:"K"},ghcp:{text:"text-green-600",letter:"C"}},Qt={sm:{container:"w-6 h-6",icon:"w-4 h-4",text:"text-xs"},md:{container:"w-8 h-8",icon:"w-5 h-5",text:"text-sm"},lg:{container:"w-12 h-12",icon:"w-8 h-8",text:"text-lg"}};function Se({provider:s,className:n,size:t="md"}){const a=s.toLowerCase(),i=zt[a]||{text:"text-gray-600",letter:s[0]?.toUpperCase()||"?"},l=Qt[t],c=qt[a];return e.jsx("div",{className:P("flex items-center justify-center rounded-md",c&&"bg-white p-1",l.container,n),children:c?e.jsx("img",{src:c,alt:`${s} logo`,className:P(l.icon,"object-contain")}):e.jsx("span",{className:P("font-semibold",i.text,l.text),children:i.letter})})}function Bt({displayName:s,logoProvider:n,provider:t,data:a,isLoading:i,hasChanges:l,isRawJsonValid:c,isSaving:u,isRemoteMode:r,port:d,onRefetch:h,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",{className:"flex items-center gap-3",children:[e.jsx(Se,{provider:n||t,size:"lg"}),e.jsxs("div",{children:[e.jsxs("div",{className:"flex items-center gap-2",children:[e.jsx("h2",{className:"text-lg font-semibold",children:s}),r&&e.jsxs(L,{variant:"secondary",className:"text-xs gap-1 bg-blue-100 text-blue-700 dark:bg-blue-900/30 dark:text-blue-400",children:[e.jsx(ke,{className:"w-3 h-3"}),"Remote"]}),d&&e.jsxs(L,{variant:"outline",className:"text-xs gap-1 font-mono",children:[e.jsx(rt,{className:"w-3 h-3"}),":",d]}),!r&&a?.path&&e.jsx(L,{variant:"outline",className:"text-xs",children:a.path.replace(/^.*[\\/]/,"")})]}),r?e.jsx("p",{className:"text-xs text-blue-600 dark:text-blue-400 mt-0.5",children:"Traffic auto-routed to remote server"}):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(w,{variant:"ghost",size:"sm",onClick:h,disabled:i,children:e.jsx($,{className:`w-4 h-4 ${i?"animate-spin":""}`})}),e.jsx(w,{size:"sm",onClick:x,disabled:u||!l||!c,children:u?e.jsxs(e.Fragment,{children:[e.jsx(q,{className:"w-4 h-4 mr-1 animate-spin"}),"Saving..."]}):e.jsxs(e.Fragment,{children:[e.jsx(ot,{className:"w-4 h-4 mr-1"}),"Save"]})})]})]})}function Jt({catalog:s,savedPresets:n,currentModel:t,opusModel:a,sonnetModel:i,haikuModel:l,providerModels:c,onApplyPreset:u,onUpdateEnvValue:r,onOpenCustomPreset:d,onDeletePreset:h,isDeletePending:x}){const g=s&&s.models.length>0||n.length>0;return e.jsxs(e.Fragment,{children:[g&&e.jsxs("div",{children:[e.jsxs("h3",{className:"text-sm font-medium mb-2 flex items-center gap-2",children:[e.jsx(J,{className:"w-4 h-4"}),"Presets"]}),e.jsx("p",{className:"text-xs text-muted-foreground mb-3",children:"Apply pre-configured model mappings"}),e.jsxs("div",{className:"flex flex-wrap gap-2",children:[s?.models.slice(0,4).map(o=>e.jsxs(w,{variant:"outline",size:"sm",className:"text-xs h-7 gap-1",onClick:()=>{const b=o.presetMapping||{default:o.id,opus:o.id,sonnet:o.id,haiku:o.id};u({ANTHROPIC_MODEL:b.default,ANTHROPIC_DEFAULT_OPUS_MODEL:b.opus,ANTHROPIC_DEFAULT_SONNET_MODEL:b.sonnet,ANTHROPIC_DEFAULT_HAIKU_MODEL:b.haiku})},children:[e.jsx(te,{className:"w-3 h-3"}),o.name]},o.id)),n.map(o=>e.jsxs("div",{className:"group relative",children:[e.jsxs(w,{variant:"secondary",size:"sm",className:"text-xs h-7 gap-1 pr-6",onClick:()=>{u({ANTHROPIC_MODEL:o.default,ANTHROPIC_DEFAULT_OPUS_MODEL:o.opus,ANTHROPIC_DEFAULT_SONNET_MODEL:o.sonnet,ANTHROPIC_DEFAULT_HAIKU_MODEL:o.haiku})},children:[e.jsx(se,{className:"w-3 h-3 fill-current"}),o.name]}),e.jsx(w,{variant:"ghost",size:"icon",className:"absolute right-0 top-0 h-7 w-5 opacity-0 group-hover:opacity-100 hover:text-destructive",onClick:b=>{b.stopPropagation(),h(o.name)},disabled:x,children:e.jsx(ae,{className:"w-3 h-3"})})]},o.name)),e.jsxs(w,{variant:"outline",size:"sm",className:"text-xs h-7 gap-1 border-primary/50 text-primary hover:bg-primary/10 hover:border-primary",onClick:d,children:[e.jsx(ts,{className:"w-3 h-3"}),"Custom"]})]})]}),e.jsx(Ae,{}),e.jsxs("div",{children:[e.jsx("h3",{className:"text-sm font-medium mb-2",children:"Model Mapping"}),e.jsx("p",{className:"text-xs text-muted-foreground mb-4",children:"Configure which models to use for each tier"}),e.jsxs("div",{className:"space-y-4",children:[e.jsx(K,{label:"Default Model",description:"Used when no specific tier is requested",value:t,onChange:o=>r("ANTHROPIC_MODEL",o),catalog:s,allModels:c}),e.jsx(K,{label:"Opus (Most capable)",description:"For complex reasoning tasks",value:a,onChange:o=>r("ANTHROPIC_DEFAULT_OPUS_MODEL",o),catalog:s,allModels:c}),e.jsx(K,{label:"Sonnet (Balanced)",description:"Balance of speed and capability",value:i,onChange:o=>r("ANTHROPIC_DEFAULT_SONNET_MODEL",o),catalog:s,allModels:c}),e.jsx(K,{label:"Haiku (Fast)",description:"Quick responses for simple tasks",value:l,onChange:o=>r("ANTHROPIC_DEFAULT_HAIKU_MODEL",o),catalog:s,allModels:c})]})]})]})}function Wt({...s}){return e.jsx(fs,{"data-slot":"dropdown-menu",...s})}function Yt({...s}){return e.jsx(js,{"data-slot":"dropdown-menu-trigger",...s})}function Xt({className:s,sideOffset:n=4,...t}){return e.jsx(vs,{children:e.jsx(Ns,{"data-slot":"dropdown-menu-content",sideOffset:n,className:P("bg-popover text-popover-foreground data-[state=open]:animate-in data-[state=closed]:animate-out data-[state=closed]:fade-out-0 data-[state=open]:fade-in-0 data-[state=closed]:zoom-out-95 data-[state=open]:zoom-in-95 data-[side=bottom]:slide-in-from-top-2 data-[side=left]:slide-in-from-right-2 data-[side=right]:slide-in-from-left-2 data-[side=top]:slide-in-from-bottom-2 z-50 max-h-(--radix-dropdown-menu-content-available-height) min-w-[8rem] origin-(--radix-dropdown-menu-content-transform-origin) overflow-x-hidden overflow-y-auto rounded-md border p-1 shadow-md bg-white dark:bg-zinc-950",s),...t})})}function re({className:s,inset:n,variant:t="default",...a}){return e.jsx(ws,{"data-slot":"dropdown-menu-item","data-inset":n,"data-variant":t,className:P("focus:bg-accent focus:text-accent-foreground data-[variant=destructive]:text-destructive data-[variant=destructive]:focus:bg-destructive/10 dark:data-[variant=destructive]:focus:bg-destructive/20 data-[variant=destructive]:focus:text-destructive data-[variant=destructive]:*:[svg]:!text-destructive [&_svg:not([class*='text-'])]:text-muted-foreground focus:[&_svg:not([class*='text-'])]:text-current relative flex cursor-default items-center gap-2 rounded-sm px-2 py-1.5 text-sm outline-hidden select-none data-[disabled]:pointer-events-none data-[disabled]:opacity-50 data-[inset]:pl-8 [&_svg]:pointer-events-none [&_svg]:shrink-0 [&_svg:not([class*='size-'])]:size-4",s),...a})}function Zt(s){return s<=20?"bg-destructive":s<=50?"bg-yellow-500":"bg-green-500"}function Ve(s){if(!s)return"";try{const n=new Date(s),a=new Date().getTime()-n.getTime();if(a<0)return"just now";const i=Math.floor(a/(1e3*60)),l=Math.floor(a/(1e3*60*60)),c=Math.floor(a/(1e3*60*60*24));return c>0?`${c}d ago`:l>0?`${l}h ago`:i>0?`${i}m ago`:"just now"}catch{return""}}function ea(s){if(!s)return!1;try{const n=new Date(s);return new Date().getTime()-n.getTime()<3600*1e3}catch{return!1}}function sa({account:s,onSetDefault:n,onRemove:t,onPauseToggle:a,isRemoving:i,isPausingAccount:l,privacyMode:c,showQuota:u}){const{data:r}=As(u&&s.provider==="agy"),{data:d,isLoading:h}=Ss(s.provider,s.id,u&&s.provider==="agy"),x=r?.accountStats?.[s.email||s.id]?.lastUsedAt,g=ea(x),o=d?.success?Ps(d.models):null,b=d?.success&&d.models.length>0?Ms(d.models):null;return e.jsxs("div",{className:P("flex flex-col gap-2 p-3 rounded-lg border transition-colors",s.isDefault?"border-primary/30 bg-primary/5":"border-border hover:bg-muted/30"),children:[e.jsxs("div",{className:"flex items-center justify-between",children:[e.jsxs("div",{className:"flex items-center gap-3",children:[e.jsx("div",{className:P("flex items-center justify-center w-8 h-8 rounded-full",s.isDefault?"bg-primary/10":"bg-muted"),children:e.jsx(Q,{className:"w-4 h-4"})}),e.jsxs("div",{children:[e.jsxs("div",{className:"flex items-center gap-2",children:[e.jsx("span",{className:P("font-medium text-sm",c&&ue),children:s.email||s.id}),s.isDefault&&e.jsxs(L,{variant:"secondary",className:"text-[10px] h-4 px-1.5 gap-0.5",children:[e.jsx(se,{className:"w-2.5 h-2.5 fill-current"}),"Default"]}),s.tier&&s.tier!=="unknown"&&e.jsx(L,{variant:"outline",className:P("text-[10px] h-4 px-1.5 uppercase",s.tier==="paid"&&"border-blue-500 text-blue-600",s.tier==="free"&&"border-gray-400 text-gray-500"),children:s.tier}),s.paused&&e.jsxs(L,{variant:"outline",className:"text-[10px] h-4 px-1.5 border-yellow-500 text-yellow-600",children:[e.jsx(Re,{className:"w-2 h-2 mr-0.5"}),"Paused"]})]}),s.lastUsedAt&&e.jsxs("div",{className:"flex items-center gap-1 text-xs text-muted-foreground mt-0.5",children:[e.jsx(X,{className:"w-3 h-3"}),"Last used: ",new Date(s.lastUsedAt).toLocaleDateString()]})]})]}),e.jsxs(Wt,{children:[e.jsx(Yt,{asChild:!0,children:e.jsx(w,{variant:"ghost",size:"icon",className:"h-7 w-7",children:e.jsx(lt,{className:"w-4 h-4"})})}),e.jsxs(Xt,{align:"end",children:[!s.isDefault&&e.jsxs(re,{onClick:n,children:[e.jsx(se,{className:"w-4 h-4 mr-2"}),"Set as default"]}),a&&e.jsx(re,{onClick:()=>a(!s.paused),disabled:l,children:s.paused?e.jsxs(e.Fragment,{children:[e.jsx(ct,{className:"w-4 h-4 mr-2"}),l?"Resuming...":"Resume account"]}):e.jsxs(e.Fragment,{children:[e.jsx(Re,{className:"w-4 h-4 mr-2"}),l?"Pausing...":"Pause account"]})}),e.jsxs(re,{className:"text-destructive focus:text-destructive",onClick:t,disabled:i,children:[e.jsx(as,{className:"w-4 h-4 mr-2"}),i?"Removing...":"Remove account"]})]})]})]}),u&&s.provider==="agy"&&e.jsx("div",{className:"pl-11",children:h?e.jsxs("div",{className:"flex items-center gap-2 text-xs text-muted-foreground",children:[e.jsx(q,{className:"w-3 h-3 animate-spin"}),e.jsx("span",{children:"Loading quota..."})]}):o!==null?e.jsxs("div",{className:"space-y-1.5",children:[e.jsx("div",{className:"flex items-center gap-1.5 text-xs",children:g?e.jsxs(e.Fragment,{children:[e.jsx(dt,{className:"w-3 h-3 text-emerald-500"}),e.jsxs("span",{className:"text-emerald-600 dark:text-emerald-400",children:["Active · ",Ve(x)]})]}):x?e.jsxs(e.Fragment,{children:[e.jsx(X,{className:"w-3 h-3 text-muted-foreground"}),e.jsxs("span",{className:"text-muted-foreground",children:["Last used ",Ve(x)]})]}):e.jsxs(e.Fragment,{children:[e.jsx(mt,{className:"w-3 h-3 text-muted-foreground"}),e.jsx("span",{className:"text-muted-foreground",children:"Not used yet"})]})}),e.jsx(We,{children:e.jsxs(Ye,{children:[e.jsx(Xe,{asChild:!0,children:e.jsxs("div",{className:"flex items-center gap-2",children:[e.jsx(Ts,{value:o,className:"h-2 flex-1",indicatorClassName:Zt(o)}),e.jsxs("span",{className:"text-xs font-medium w-10 text-right",children:[o,"%"]})]})}),e.jsx(Ze,{side:"bottom",className:"max-w-xs",children:e.jsxs("div",{className:"text-xs space-y-1",children:[e.jsx("p",{className:"font-medium",children:"Model Quotas:"}),Os(d?.models||[]).map(A=>e.jsxs("div",{className:"flex justify-between gap-4",children:[e.jsx("span",{className:"truncate",children:A.displayName||A.name}),e.jsxs("span",{className:"font-mono",children:[A.percentage,"%"]})]},A.name)),b&&e.jsxs("div",{className:"flex items-center gap-1.5 mt-2 pt-2 border-t border-border/50",children:[e.jsx(X,{className:"w-3 h-3 text-blue-400"}),e.jsxs("span",{className:"text-blue-400 font-medium",children:["Resets ",Ds(b)]})]})]})})]})})]}):d?.error?e.jsx("div",{className:"text-xs text-muted-foreground",children:d.error}):null})]})}function ta({accounts:s,onAddAccount:n,onSetDefault:t,onRemoveAccount:a,onPauseToggle:i,isRemovingAccount:l,isPausingAccount:c,privacyMode:u,showQuota:r,isKiro:d,kiroNoIncognito:h,onKiroNoIncognitoChange:x,kiroSettingsLoading:g}){return e.jsxs("div",{children:[e.jsxs("div",{className:"flex items-center justify-between mb-3",children:[e.jsxs("h3",{className:"text-sm font-medium flex items-center gap-2",children:[e.jsx(Q,{className:"w-4 h-4"}),"Accounts",s.length>0&&e.jsx(L,{variant:"secondary",className:"text-xs",children:s.length})]}),e.jsxs(w,{variant:"default",size:"sm",className:"h-7 text-xs gap-1",onClick:n,children:[e.jsx(ts,{className:"w-3 h-3"}),"Add"]})]}),s.length>0?e.jsx("div",{className:"space-y-2",children:s.map(o=>e.jsx(sa,{account:o,onSetDefault:()=>t(o.id),onRemove:()=>a(o.id),onPauseToggle:i?b=>i(o.id,b):void 0,isRemoving:l,isPausingAccount:c,privacyMode:u,showQuota:r},o.id))}):e.jsxs("div",{className:"py-6 text-center text-muted-foreground bg-muted/30 rounded-lg border border-dashed",children:[e.jsx(Q,{className:"w-8 h-8 mx-auto mb-2 opacity-50"}),e.jsx("p",{className:"text-sm",children:"No accounts connected"}),e.jsx("p",{className:"text-xs opacity-70",children:"Add an account to get started"})]}),d&&x&&e.jsx("div",{className:"mt-3 pt-3 border-t border-dashed",children:e.jsxs("div",{className:"flex items-center justify-between gap-3",children:[e.jsxs("div",{className:"flex items-center gap-2 text-sm text-muted-foreground",children:[e.jsx(ke,{className:"w-3.5 h-3.5"}),e.jsx("span",{children:"Use incognito"})]}),e.jsx(wt,{checked:!h,onCheckedChange:o=>x(!o),disabled:g,className:"scale-90"})]})})]})}function aa({provider:s,catalog:n,savedPresets:t,currentModel:a,opusModel:i,sonnetModel:l,haikuModel:c,providerModels:u,onApplyPreset:r,onUpdateEnvValue:d,onOpenCustomPreset:h,onDeletePreset:x,isDeletePending:g,accounts:o,onAddAccount:b,onSetDefault:A,onRemoveAccount:v,onPauseToggle:D,isRemovingAccount:k,isPausingAccount:O,privacyMode:M,isRemoteMode:I}){const y=s==="kiro",[j,f]=p.useState(!0),[S,_]=p.useState(!0),[R,U]=p.useState(!1),m=p.useCallback(async()=>{if(y)try{_(!0);const N=(await Y.config.get()).cliproxy;f(N?.kiro_no_incognito??!0)}catch{f(!0)}finally{_(!1)}},[y]),C=p.useCallback(async T=>{f(T),U(!0);try{const N=await Y.config.get(),H=N.cliproxy??{};await Y.config.update({...N,cliproxy:{...H,kiro_no_incognito:T}})}catch{f(!T)}finally{U(!1)}},[]);return p.useEffect(()=>{m()},[m]),e.jsx(be,{className:"flex-1",children:e.jsxs("div",{className:"p-4 space-y-6",children:[e.jsx(Jt,{catalog:n,savedPresets:t,currentModel:a,opusModel:i,sonnetModel:l,haikuModel:c,providerModels:u,onApplyPreset:r,onUpdateEnvValue:d,onOpenCustomPreset:h,onDeletePreset:x,isDeletePending:g}),e.jsx(Ae,{}),e.jsx(ta,{accounts:o,onAddAccount:b,onSetDefault:A,onRemoveAccount:v,onPauseToggle:D,isRemovingAccount:k,isPausingAccount:O,privacyMode:M,showQuota:s==="agy"&&!I,isKiro:y,kiroNoIncognito:j,onKiroNoIncognitoChange:C,kiroSettingsLoading:S||R})]})})}function Ge({provider:s,displayName:n,authStatus:t,catalog:a,logoProvider:i,baseProvider:l,isRemoteMode:c,port:u,onAddAccount:r,onSetDefault:d,onRemoveAccount:h,onPauseToggle:x,isRemovingAccount:g,isPausingAccount:o}){const[b,A]=p.useState(!1),{privacyMode:v}=Qe(),{data:D}=_s(),{data:k}=Es(s),O=Is(),M=Ls(),I=k?.presets||[],y=l||s,j=p.useMemo(()=>{if(!D?.models)return[];const G={gemini:["google"],agy:["antigravity"],codex:["openai"],qwen:["alibaba","qwen"],iflow:["iflow"],kiro:["kiro","aws"],ghcp:["github","copilot"]}[y.toLowerCase()]||[y.toLowerCase()];return D.models.filter(De=>G.some(gs=>De.owned_by.toLowerCase().includes(gs)))},[D,y]),{data:f,isLoading:S,refetch:_,rawJsonContent:R,rawJsonEdits:U,isRawJsonValid:m,hasChanges:C,currentModel:T,opusModel:N,sonnetModel:H,haikuModel:V,handleRawJsonChange:ne,updateEnvValue:ls,updateEnvValues:Pe,saveMutation:Me,conflictDialog:cs,handleConflictResolve:Te,missingRequiredFields:ds}=Gt(s),ms=t.accounts||[],{data:us}=me({queryKey:["auth-tokens-raw"],queryFn:async()=>{const E=await fetch("/api/settings/auth/tokens/raw");return E.ok?E.json():{apiKey:{value:"ccs-internal-managed"}}},staleTime:6e4}),Oe=us?.apiKey?.value??"ccs-internal-managed",xs=E=>{Pe({ANTHROPIC_BASE_URL:`http://127.0.0.1:${u??ce}/api/provider/${s}`,ANTHROPIC_AUTH_TOKEN:Oe,...E}),F.success(`Applied "${E.ANTHROPIC_MODEL?.split("/").pop()||"preset"}" preset`)},ps=(E,G)=>{Pe({ANTHROPIC_BASE_URL:`http://127.0.0.1:${u??ce}/api/provider/${s}`,ANTHROPIC_AUTH_TOKEN:Oe,ANTHROPIC_MODEL:E.default,ANTHROPIC_DEFAULT_OPUS_MODEL:E.opus,ANTHROPIC_DEFAULT_SONNET_MODEL:E.sonnet,ANTHROPIC_DEFAULT_HAIKU_MODEL:E.haiku}),F.success(`Applied ${G?`"${G}"`:"custom"} preset`),A(!1)},hs=(E,G)=>{if(!G){F.error("Please enter a preset name to save");return}O.mutate({profile:s,data:{name:G,...E}}),A(!1)};return e.jsxs("div",{className:"flex-1 flex flex-col overflow-hidden",children:[e.jsx(Bt,{provider:s,displayName:n,logoProvider:i,data:f,isLoading:S,hasChanges:C,isRawJsonValid:m,isSaving:Me.isPending,isRemoteMode:c,port:u,onRefetch:_,onSave:()=>Me.mutate()}),S?e.jsxs("div",{className:"flex-1 flex items-center justify-center",children:[e.jsx(q,{className:"w-8 h-8 animate-spin text-muted-foreground"}),e.jsx("span",{className:"ml-3 text-muted-foreground",children:"Loading settings..."})]}):e.jsxs("div",{className:"flex-1 grid grid-cols-[40%_60%] divide-x overflow-hidden",children:[e.jsx("div",{className:"flex flex-col overflow-hidden bg-muted/5",children:e.jsxs(Rs,{defaultValue:"config",className:"h-full flex flex-col",children:[e.jsx("div",{className:"px-4 pt-4 shrink-0",children:e.jsxs(Fs,{className:"w-full",children:[e.jsx(Ie,{value:"config",className:"flex-1",children:"Model Config"}),e.jsx(Ie,{value:"info",className:"flex-1",children:"Info & Usage"})]})}),e.jsxs("div",{className:"flex-1 overflow-hidden flex flex-col",children:[e.jsx(Le,{value:"config",className:"flex-1 mt-0 border-0 p-0 data-[state=inactive]:hidden flex flex-col overflow-hidden",children:e.jsx(aa,{provider:s,catalog:a,savedPresets:I,currentModel:T,opusModel:N,sonnetModel:H,haikuModel:V,providerModels:j,onApplyPreset:xs,onUpdateEnvValue:ls,onOpenCustomPreset:()=>A(!0),onDeletePreset:E=>M.mutate({profile:s,name:E}),isDeletePending:M.isPending,accounts:ms,onAddAccount:r,onSetDefault:d,onRemoveAccount:h,onPauseToggle:x,isRemovingAccount:g,isPausingAccount:o,privacyMode:v,isRemoteMode:c})}),e.jsx(Le,{value:"info",className:"h-full mt-0 border-0 p-0 data-[state=inactive]:hidden",children:e.jsx($t,{provider:s,displayName:n,data:f,authStatus:t})})]})]})}),e.jsxs("div",{className:"flex flex-col overflow-hidden",children:[e.jsxs("div",{className:"px-6 py-2 bg-muted/30 border-b flex items-center gap-2 shrink-0 h-[45px]",children:[e.jsx(ut,{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(Us,{rawJsonContent:R,isRawJsonValid:m,rawJsonEdits:U,onRawJsonChange:ne,profileEnv:f?.settings?.env,missingRequiredFields:ds})]})]}),e.jsx(Nt,{open:cs,title:"File Modified Externally",description:"This settings file was modified by another process. Overwrite with your changes or discard?",confirmText:"Overwrite",variant:"destructive",onConfirm:()=>Te(!0),onCancel:()=>Te(!1)}),e.jsx(Kt,{open:b,onClose:()=>A(!1),currentValues:{default:T||"",opus:N||"",sonnet:H||"",haiku:V||""},onApply:ps,onSave:hs,isSaving:O.isPending,catalog:a,allModels:j})]})}function oe(s,n){const t=s.replace(/-\d+$/,"").split(".").map(Number),a=n.replace(/-\d+$/,"").split(".").map(Number);for(let i=0;i<3;i++){if((t[i]||0)>(a[i]||0))return!0;if((t[i]||0)<(a[i]||0))return!1}return!1}function na(s){if(!s)return"";const n=new Date(s).getTime(),a=Date.now()-n,i=Math.floor(a/(1e3*60*60)),l=Math.floor(a%(1e3*60*60)/(1e3*60));return i>0?`${i}h ${l}m`:`${l}m`}function ia(s){if(!s)return"";const n=Date.now()-s,t=Math.floor(n/(1e3*60)),a=Math.floor(n/(1e3*60*60));return t<1?"just now":t<60?`${t}m ago`:`${a}h ago`}function le({icon:s,tooltip:n,onClick:t,disabled:a,isPending:i,className:l,variant:c="ghost"}){return e.jsxs(Ye,{children:[e.jsx(Xe,{asChild:!0,children:e.jsx(w,{variant:c==="destructive-ghost"?"ghost":c,size:"sm",className:P("h-7 w-7 p-0",c==="destructive-ghost"&&"hover:bg-destructive/10 hover:text-destructive hover:border-destructive/30",l),onClick:t,disabled:a,children:i?e.jsx($,{className:"w-3.5 h-3.5 animate-spin"}):e.jsx(s,{className:"w-3.5 h-3.5"})})}),e.jsx(Ze,{side:"bottom",className:"text-xs",children:n})]})}function ra(){const{data:s,isLoading:n}=Hs(),{data:t}=Vs(),{data:a,isLoading:i}=Gs(),l=Ks(),c=$s(),u=qs(),r=zs(),[d,h]=p.useState(!1),[x,g]=p.useState(""),[o,b]=p.useState(!1),[A,v]=p.useState(null),{data:D}=me({queryKey:["cliproxy-server-config"],queryFn:()=>Y.cliproxyServer.get(),staleTime:3e4}),k=D?.remote,O=k?.enabled&&k?.host,M=s?.running??!1,I=l.isPending||c.isPending||u.isPending||r.isPending,y=t?.hasUpdate??!1,j=t?.isStable===!1,f=t?.currentVersion,S=j?t?.maxStableVersion||a?.latestStable:t?.latestVersion,_=C=>{if(!C)return;const T=a?.maxStableVersion||"6.6.80";if(oe(C,T)){v(C),b(!0);return}r.mutate({version:C})},R=()=>{A&&r.mutate({version:A,force:!0}),b(!1),v(null)},U=()=>{b(!1),v(null)},m=O?(()=>{const C=k.protocol||"http",T=k.port||(C==="https"?443:80);return C==="https"&&T===443||C==="http"&&T===80?k.host:`${k.host}:${T}`})():null;return O?e.jsxs("div",{className:P("rounded-lg border p-3 transition-colors","border-blue-500/30 bg-blue-500/5"),children:[e.jsxs("div",{className:"flex items-center justify-between",children:[e.jsxs("div",{className:"flex items-center gap-2",children:[e.jsx(ke,{className:"w-4 h-4 text-blue-500"}),e.jsx("span",{className:"text-sm font-medium",children:"Remote Proxy"}),e.jsx(L,{variant:"secondary",className:"text-[10px] h-4 px-1.5 bg-blue-100 text-blue-700 dark:bg-blue-900/30 dark:text-blue-400",children:"Active"})]}),e.jsx(xt,{className:"w-3 h-3 text-blue-600"})]}),e.jsxs("div",{className:"mt-2 text-xs text-muted-foreground",children:[e.jsx("div",{className:"flex items-center gap-1 mb-1",children:e.jsx("span",{className:"font-mono",children:m})}),e.jsx("p",{className:"text-[10px] text-muted-foreground/70 leading-tight",children:"Traffic auto-routed to remote server"})]})]}):e.jsx(We,{delayDuration:300,children:e.jsxs("div",{className:P("rounded-lg border p-3 transition-colors",M?"border-green-500/30 bg-green-500/5":"border-muted bg-muted/30"),children:[e.jsxs("div",{className:"flex items-center justify-between",children:[e.jsxs("div",{className:"flex items-center gap-2",children:[e.jsx("div",{className:P("w-2 h-2 rounded-full",M?"bg-green-500 animate-pulse":"bg-muted-foreground/30")}),e.jsx("span",{className:"text-sm font-medium",children:"CLIProxy Plus"})]}),e.jsx("div",{className:"flex items-center gap-1",children:n?e.jsx($,{className:"w-3 h-3 animate-spin text-muted-foreground"}):M?e.jsxs(e.Fragment,{children:[e.jsx(le,{icon:pt,tooltip:"Restart",onClick:()=>u.mutate(),disabled:I,isPending:u.isPending}),e.jsx(le,{icon:ht,tooltip:"Stop",onClick:()=>c.mutate(),disabled:I,isPending:c.isPending,variant:"destructive-ghost"}),e.jsx(le,{icon:d?ae:gt,tooltip:d?"Close":"Version settings",onClick:()=>h(!d),className:d?"bg-muted":void 0})]}):e.jsx(Fe,{className:"w-3 h-3 text-muted-foreground"})})]}),f&&e.jsxs("div",{className:"mt-1.5 flex items-center gap-2",children:[e.jsxs("span",{className:P("text-xs font-mono text-muted-foreground",j&&"text-amber-600 dark:text-amber-400"),children:["v",f]}),(y||j)&&S&&e.jsxs(L,{variant:"secondary",className:P("text-[10px] h-4 px-1.5 gap-0.5 cursor-pointer transition-colors",j?"bg-amber-100 text-amber-700 hover:bg-amber-200 dark:bg-amber-900/30 dark:text-amber-400 dark:hover:bg-amber-900/50":"bg-green-100 text-green-700 hover:bg-green-200 dark:bg-green-900/30 dark:text-green-400 dark:hover:bg-green-900/50"),onClick:()=>_(S),title:`Click to ${j?"downgrade":"update"}`,children:[j?e.jsx(ft,{className:"w-2.5 h-2.5"}):e.jsx(jt,{className:"w-2.5 h-2.5"}),S]})]}),M&&s&&e.jsxs("div",{className:"mt-2 flex items-center gap-4 text-xs text-muted-foreground",children:[e.jsxs("span",{className:"flex items-center gap-1",children:["Port ",s.port]}),s.sessionCount!==void 0&&s.sessionCount>0&&e.jsxs("span",{className:"flex items-center gap-1",children:[e.jsx(vt,{className:"w-3 h-3"}),s.sessionCount," session",s.sessionCount!==1?"s":""]}),s.startedAt&&e.jsxs("span",{className:"flex items-center gap-1",children:[e.jsx(X,{className:"w-3 h-3"}),na(s.startedAt)]})]}),M&&e.jsx(Qs,{open:d,onOpenChange:h,children:e.jsxs(Bs,{className:"mt-3 pt-3 border-t border-muted",children:[e.jsx("h4",{className:"text-xs font-medium text-muted-foreground mb-3",children:"Version Management"}),e.jsxs("div",{className:"flex items-center gap-2",children:[e.jsxs(pe,{value:x,onValueChange:g,disabled:i,children:[e.jsx(he,{className:"h-8 text-xs flex-1",children:e.jsx(ge,{placeholder:"Select version to install..."})}),e.jsx(fe,{children:a?.versions.slice(0,20).map(C=>{const T=a?.maxStableVersion&&oe(C,a.maxStableVersion);return e.jsx(ee,{value:C,className:"text-xs",children:e.jsxs("span",{className:"flex items-center gap-2",children:["v",C,C===a.latestStable&&e.jsx("span",{className:"text-green-600 dark:text-green-400",children:"(stable)"}),T&&e.jsx("span",{className:"text-amber-600 dark:text-amber-400",children:"⚠"})]})},C)})})]}),e.jsxs(w,{variant:"outline",size:"sm",className:"h-8 text-xs gap-1.5 px-3",onClick:()=>_(x),disabled:r.isPending||!x,children:[r.isPending?e.jsx($,{className:"w-3.5 h-3.5 animate-spin"}):e.jsx(ss,{className:"w-3.5 h-3.5"}),"Install"]})]}),x&&a?.maxStableVersion&&oe(x,a.maxStableVersion)&&e.jsxs("div",{className:"mt-2 flex items-center gap-1.5 text-[11px] text-amber-600 dark:text-amber-400",children:[e.jsx(Ue,{className:"w-3.5 h-3.5 flex-shrink-0"}),e.jsxs("span",{children:["Versions above ",a.maxStableVersion," have known issues"]})]}),t?.checkedAt&&e.jsxs("div",{className:"mt-2 text-[10px] text-muted-foreground/60",children:["Last checked ",ia(t.checkedAt)]})]})}),!M&&e.jsxs("div",{className:"mt-2 flex items-center justify-between",children:[e.jsx("span",{className:"text-xs text-muted-foreground",children:"Not running"}),e.jsxs(w,{variant:"outline",size:"sm",className:"h-7 text-xs gap-1",onClick:()=>l.mutate(),disabled:l.isPending,children:[l.isPending?e.jsx($,{className:"w-3 h-3 animate-spin"}):e.jsx(Fe,{className:"w-3 h-3"}),"Start"]})]}),e.jsx(bt,{open:o,onOpenChange:b,children:e.jsxs(yt,{children:[e.jsxs(Ct,{children:[e.jsxs(kt,{className:"flex items-center gap-2",children:[e.jsx(Ue,{className:"w-5 h-5 text-amber-500"}),"Install Unstable Version?"]}),e.jsxs(At,{className:"space-y-2",children:[e.jsxs("p",{children:["You are about to install ",e.jsxs("strong",{children:["v",A]}),", which is above the maximum stable version"," ",e.jsxs("strong",{children:["v",a?.maxStableVersion||"6.6.80"]}),"."]}),e.jsx("p",{className:"text-amber-600 dark:text-amber-400",children:"This version has known stability issues and may cause unexpected behavior."}),e.jsx("p",{children:"Are you sure you want to proceed?"})]})]}),e.jsxs(St,{children:[e.jsx(Pt,{onClick:U,children:"Cancel"}),e.jsx(Mt,{onClick:R,className:"bg-amber-500 hover:bg-amber-600 text-white",children:"Install Anyway"})]})]})})]})})}function oa({status:s,isSelected:n,onSelect:t}){const a=s.accounts?.length||0;return e.jsxs("button",{className:P("w-full flex items-center gap-3 px-3 py-2.5 rounded-lg transition-colors cursor-pointer text-left",n?"bg-primary/10 border border-primary/20":"hover:bg-muted border border-transparent"),onClick:t,children:[e.jsx(Se,{provider:s.provider,size:"md"}),e.jsxs("div",{className:"flex-1 min-w-0",children:[e.jsxs("div",{className:"flex items-center gap-2",children:[e.jsx("span",{className:"font-medium text-sm truncate",children:s.displayName}),a>0&&e.jsx(L,{variant:"secondary",className:"text-[10px] h-4 px-1",children:a})]}),e.jsx("div",{className:"flex items-center gap-1.5 mt-0.5",children:s.authenticated?e.jsxs(e.Fragment,{children:[e.jsx(z,{className:"w-3 h-3 text-green-600"}),e.jsx("span",{className:"text-xs text-green-600",children:"Connected"})]}):e.jsxs(e.Fragment,{children:[e.jsx(ae,{className:"w-3 h-3 text-muted-foreground"}),e.jsx("span",{className:"text-xs text-muted-foreground",children:"Not connected"})]})})]})]})}function la({variant:s,parentAuth:n,isSelected:t,onSelect:a,onDelete:i,isDeleting:l}){return e.jsxs("button",{className:P("group w-full flex items-center gap-3 px-3 py-2 rounded-lg transition-colors cursor-pointer text-left pl-6",t?"bg-primary/10 border border-primary/20":"hover:bg-muted border border-transparent"),onClick:a,children:[e.jsxs("div",{className:"relative",children:[e.jsx(Se,{provider:s.provider,size:"sm"}),e.jsx(ns,{className:"w-2.5 h-2.5 absolute -bottom-0.5 -right-0.5 text-muted-foreground"})]}),e.jsxs("div",{className:"flex-1 min-w-0",children:[e.jsxs("div",{className:"flex items-center gap-2",children:[e.jsx("span",{className:"font-medium text-sm truncate",children:s.name}),e.jsx(L,{variant:"outline",className:"text-[9px] h-4 px-1",children:"variant"})]}),e.jsx("div",{className:"flex items-center gap-1.5 mt-0.5",children:n?.authenticated?e.jsxs(e.Fragment,{children:[e.jsx(z,{className:"w-3 h-3 text-green-600"}),e.jsxs("span",{className:"text-xs text-muted-foreground truncate",children:["via ",s.provider]})]}):e.jsxs(e.Fragment,{children:[e.jsx(ae,{className:"w-3 h-3 text-muted-foreground"}),e.jsx("span",{className:"text-xs text-muted-foreground",children:"Parent not connected"})]})})]}),e.jsx(w,{variant:"ghost",size:"icon",className:"h-6 w-6 opacity-0 group-hover:opacity-100 hover:text-destructive",onClick:c=>{c.stopPropagation(),i()},disabled:l,children:e.jsx(as,{className:"w-3 h-3"})})]})}function ca({onSetup:s}){return e.jsx("div",{className:"flex-1 flex items-center justify-center bg-muted/20",children:e.jsxs("div",{className:"text-center max-w-md px-8",children:[e.jsx("div",{className:"w-16 h-16 rounded-full bg-muted flex items-center justify-center mx-auto mb-6",children:e.jsx(te,{className:"w-8 h-8 text-muted-foreground"})}),e.jsx("h2",{className:"text-xl font-semibold mb-2",children:"CCS Profile Manager"}),e.jsx("p",{className:"text-muted-foreground mb-4",children:"Manage OAuth authentication, account preferences, and model selection for CLIProxy providers. Configure how CCS routes requests to different AI backends."}),e.jsxs("p",{className:"text-xs text-muted-foreground mb-6",children:["For live usage stats and real-time monitoring, visit the"," ",e.jsx("a",{href:"/cliproxy/control-panel",className:"text-primary hover:underline",children:"Control Panel"}),"."]}),e.jsxs(w,{onClick:s,className:"gap-2",children:[e.jsx(J,{className:"w-4 h-4"}),"Quick Setup"]})]})})}function ya(){const s=Ke(),{data:n,isLoading:t}=$e(),{data:a,isFetching:i}=Js(),l=Ws(),c=Ys(),u=Xs(),r=Zs(),d=et(),[h,x]=p.useState(null),[g,o]=p.useState(null),[b,A]=p.useState(!1),[v,D]=p.useState(null),k=p.useMemo(()=>n?.authStatus||[],[n?.authStatus]),O=n?.source==="remote",M=p.useMemo(()=>a?.variants||[],[a?.variants]),I=p.useMemo(()=>g?null:h&&k.some(m=>m.provider===h)?h:k.length>0?k[0].provider:null,[h,g,k]),y=k.find(m=>m.provider===I),j=M.find(m=>m.name===g),f=j?k.find(m=>m.provider===j.provider):void 0,S=()=>{s.invalidateQueries({queryKey:["cliproxy"]}),s.invalidateQueries({queryKey:["cliproxy-auth"]})},_=(m,C,T)=>{u.isPending||r.isPending||(T?u.mutate({provider:m,accountId:C}):r.mutate({provider:m,accountId:C}))},R=m=>{x(m),o(null)},U=m=>{o(m),x(null)};return e.jsxs("div",{className:"h-[calc(100vh-100px)] flex",children:[e.jsxs("div",{className:"w-80 border-r flex flex-col bg-muted/30",children:[e.jsxs("div",{className:"p-4 border-b bg-background",children:[e.jsxs("div",{className:"flex items-center justify-between mb-1",children:[e.jsxs("div",{className:"flex items-center gap-2",children:[e.jsx(te,{className:"w-5 h-5 text-primary"}),e.jsx("h1",{className:"font-semibold",children:"CLIProxy Plus"})]}),e.jsx(w,{variant:"ghost",size:"icon",className:"h-8 w-8",onClick:S,disabled:i,children:e.jsx($,{className:P("w-4 h-4",i&&"animate-spin")})})]}),e.jsx("p",{className:"text-xs text-muted-foreground mb-3",children:"CCS-level account management"}),e.jsxs(w,{variant:"default",size:"sm",className:"w-full gap-2",onClick:()=>A(!0),children:[e.jsx(J,{className:"w-4 h-4"}),"Quick Setup"]})]}),e.jsx(be,{className:"flex-1",children:e.jsxs("div",{className:"p-2",children:[e.jsx("div",{className:"text-xs font-medium text-muted-foreground uppercase tracking-wide px-3 py-2",children:"Providers"}),t?e.jsx("div",{className:"space-y-2 px-2",children:[1,2,3,4].map(m=>e.jsx(st,{className:"h-14 w-full rounded-lg"},m))}):e.jsx("div",{className:"space-y-1",children:k.map(m=>e.jsx(oa,{status:m,isSelected:I===m.provider,onSelect:()=>R(m.provider)},m.provider))}),M.length>0&&e.jsxs(e.Fragment,{children:[e.jsxs("div",{className:"text-xs font-medium text-muted-foreground uppercase tracking-wide px-3 py-2 mt-4 flex items-center gap-1.5",children:[e.jsx(ns,{className:"w-3 h-3"}),"Variants"]}),e.jsx("div",{className:"space-y-1",children:M.map(m=>e.jsx(la,{variant:m,parentAuth:k.find(C=>C.provider===m.provider),isSelected:g===m.name,onSelect:()=>U(m.name),onDelete:()=>d.mutate(m.name),isDeleting:d.isPending},m.name))})]})]})}),e.jsx("div",{className:"p-3 border-t",children:e.jsx(ra,{})}),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:[k.length," provider",k.length!==1?"s":""]}),e.jsxs("span",{className:"flex items-center gap-1",children:[e.jsx(z,{className:"w-3 h-3 text-green-600"}),k.filter(m=>m.authenticated).length," connected"]})]})})]}),e.jsx("div",{className:"flex-1 flex flex-col min-w-0 bg-background",children:j&&f?e.jsx(Ge,{provider:j.name,displayName:`${j.name} (${j.provider} variant)`,authStatus:f,catalog:B[j.provider],logoProvider:j.provider,baseProvider:j.provider,isRemoteMode:O,port:j.port,onAddAccount:()=>D({provider:j.provider,displayName:f.displayName,isFirstAccount:(f.accounts?.length||0)===0}),onSetDefault:m=>l.mutate({provider:j.provider,accountId:m}),onRemoveAccount:m=>c.mutate({provider:j.provider,accountId:m}),onPauseToggle:(m,C)=>_(j.provider,m,C),isRemovingAccount:c.isPending,isPausingAccount:u.isPending||r.isPending}):y?e.jsx(Ge,{provider:y.provider,displayName:y.displayName,authStatus:y,catalog:B[y.provider],isRemoteMode:O,onAddAccount:()=>D({provider:y.provider,displayName:y.displayName,isFirstAccount:(y.accounts?.length||0)===0}),onSetDefault:m=>l.mutate({provider:y.provider,accountId:m}),onRemoveAccount:m=>c.mutate({provider:y.provider,accountId:m}),onPauseToggle:(m,C)=>_(y.provider,m,C),isRemovingAccount:c.isPending,isPausingAccount:u.isPending||r.isPending}):e.jsx(ca,{onSetup:()=>A(!0)})}),e.jsx(Ft,{open:b,onClose:()=>A(!1)}),e.jsx(Ut,{open:v!==null,onClose:()=>D(null),provider:v?.provider||"",displayName:v?.displayName||"",isFirstAccount:v?.isFirstAccount||!1})]})}export{ya as CliproxyPage};
|
package/dist/ui/assets/{cliproxy-control-panel-Dbs8NAQa.js → cliproxy-control-panel-D7FGe5HL.js}
RENAMED
|
@@ -1 +1 @@
|
|
|
1
|
-
import{j as e}from"./radix-ui-CBgg0XeO.js";import{r as s}from"./react-vendor-B_CU-WTZ.js";import{a as w}from"./tanstack-CxYN0q6L.js";import{af as I}from"./index-
|
|
1
|
+
import{j as e}from"./radix-ui-CBgg0XeO.js";import{r as s}from"./react-vendor-B_CU-WTZ.js";import{a as w}from"./tanstack-CxYN0q6L.js";import{af as I}from"./index-D8K1YCe7.js";import{G as R,a0 as v,V as S,Y as T,K as U,S as K,X as M}from"./icons-CZDQWWm2.js";import"./notifications-dJQY2-U6.js";import"./utils-CzKF5WmX.js";import"./form-utils-kUVlZZAO.js";import"./code-highlight-DKN39ySy.js";const A=8317;function F({port:c=A}){const n=s.useRef(null),[f,p]=s.useState(!0),[b,i]=s.useState(null),[k,m]=s.useState(!1),[P,L]=s.useState(!0),{data:g,error:h}=w({queryKey:["cliproxy-server-config"],queryFn:()=>I.cliproxyServer.get(),staleTime:3e4}),{data:j}=w({queryKey:["auth-tokens-raw"],queryFn:async()=>{const t=await fetch("/api/settings/auth/tokens/raw");if(!t.ok)throw new Error("Failed to fetch auth tokens");return t.json()},staleTime:3e4});s.useEffect(()=>{h&&console.warn("[ControlPanelEmbed] Config fetch failed, using local mode:",h)},[h]);const{managementUrl:y,checkUrl:d,authToken:r,isRemote:l,displayHost:u}=s.useMemo(()=>{const t=g?.remote;if(t?.enabled&&t?.host){const o=t.protocol||"http",a=t.port||(o==="https"?443:80),N=o==="https"&&a===443||o==="http"&&a===80?"":`:${a}`,C=`${o}://${t.host}${N}`;return{managementUrl:`${C}/management.html`,checkUrl:`${C}/`,authToken:t.auth_token||void 0,isRemote:!0,displayHost:`${t.host}${N}`}}const x=j?.managementSecret?.value||"ccs";return{managementUrl:`http://localhost:${c}/management.html`,checkUrl:`http://localhost:${c}/`,authToken:x,isRemote:!1,displayHost:`localhost:${c}`}},[g,j,c]);s.useEffect(()=>{const t=new AbortController,x=async()=>{try{(await fetch(d,{signal:t.signal})).ok?(m(!0),i(null)):(m(!1),i(l?`Remote CLIProxy at ${u} returned an error`:"CLIProxy returned an error"))}catch(a){if(a instanceof Error&&a.name==="AbortError")return;m(!1),i(l?`Remote CLIProxy at ${u} is not reachable`:"CLIProxy is not running")}},o=setTimeout(()=>t.abort(),2e3);return x().finally(()=>clearTimeout(o)),()=>t.abort()},[d,l,u]);const $=s.useCallback(()=>{if(p(!1),n.current?.contentWindow&&r)try{const t=d.replace(/\/$/,"");if(!n.current.src.startsWith(t)){console.warn("[ControlPanelEmbed] Iframe origin mismatch, skipping postMessage");return}n.current.contentWindow.postMessage({type:"ccs-auto-login",apiBase:t,managementKey:r},t)}catch(t){console.debug("[ControlPanelEmbed] postMessage failed - cross-origin:",t)}},[d,r]),E=()=>{p(!0),i(null),m(!1),n.current&&(n.current.src=y)};return!k&&b?e.jsxs("div",{className:"flex-1 flex flex-col",children:[e.jsxs("div",{className:"flex items-center justify-between p-4 border-b",children:[e.jsxs("div",{className:"flex items-center gap-2",children:[e.jsx(R,{className:"w-5 h-5 text-primary"}),e.jsx("h2",{className:"font-semibold",children:"CLIProxy Control Panel"})]}),e.jsxs("button",{className:"inline-flex items-center gap-2 px-3 py-1.5 text-sm border rounded-md hover:bg-muted",onClick:E,children:[e.jsx(v,{className:"w-4 h-4"}),"Retry"]})]}),e.jsx("div",{className:"flex-1 flex items-center justify-center bg-muted/20",children:e.jsxs("div",{className:"text-center max-w-md px-8",children:[e.jsx("div",{className:"w-16 h-16 rounded-full bg-destructive/10 flex items-center justify-center mx-auto mb-6",children:e.jsx(S,{className:"w-8 h-8 text-destructive"})}),e.jsx("h3",{className:"text-lg font-semibold mb-2",children:"CLIProxy Not Available"}),e.jsx("p",{className:"text-muted-foreground mb-4",children:b}),e.jsxs("p",{className:"text-sm text-muted-foreground",children:["Start a CLIProxy session with"," ",e.jsx("code",{className:"bg-muted px-1 rounded",children:"ccs gemini"})," or run"," ",e.jsx("code",{className:"bg-muted px-1 rounded",children:"ccs config"})," which auto-starts it."]})]})})]}):e.jsxs("div",{className:"flex-1 flex flex-col relative",children:[P&&!f&&e.jsx("div",{className:"absolute top-2 left-1/2 -translate-x-1/2 z-20",children:e.jsxs("div",{className:"flex items-center gap-2 px-3 py-1.5 bg-blue-50 dark:bg-blue-950 border border-blue-200 dark:border-blue-800 rounded-md text-sm",children:[l&&e.jsxs(e.Fragment,{children:[e.jsx(T,{className:"h-3.5 w-3.5 text-green-600"}),e.jsx("span",{className:"text-green-600 font-medium",children:"Remote"}),e.jsx("span",{className:"text-blue-300 dark:text-blue-700",children:"|"})]}),e.jsx(U,{className:"h-3.5 w-3.5 text-blue-600"}),e.jsxs("span",{children:["Key:"," ",e.jsx("code",{className:"bg-blue-100 dark:bg-blue-900 px-1 rounded font-mono font-semibold",children:r&&r.length>4?`***${r.slice(-4)}`:r||"ccs"})]}),e.jsx("a",{href:"/settings?tab=auth",className:"text-blue-600 hover:text-blue-800 dark:hover:text-blue-400",title:"Manage auth tokens",children:e.jsx(K,{className:"h-3.5 w-3.5"})}),e.jsx("button",{className:"text-blue-600 hover:text-blue-800 dark:hover:text-blue-400",onClick:()=>L(!1),children:e.jsx(M,{className:"h-3.5 w-3.5"})})]})}),f&&e.jsx("div",{className:"absolute inset-0 flex items-center justify-center bg-background/80 z-10",children:e.jsxs("div",{className:"text-center",children:[e.jsx(v,{className:"w-8 h-8 animate-spin text-primary mx-auto mb-2"}),e.jsx("p",{className:"text-sm text-muted-foreground",children:l?`Loading Control Panel from ${u}...`:"Loading Control Panel..."})]})}),e.jsx("iframe",{ref:n,src:y,className:"flex-1 w-full border-0",title:"CLIProxy Management Panel",onLoad:$})]})}function B(){return e.jsx("div",{className:"h-[calc(100vh-100px)] flex flex-col",children:e.jsx(F,{})})}export{B as CliproxyControlPanelPage};
|
|
@@ -1 +1 @@
|
|
|
1
|
-
import{j as r,$ as c}from"./radix-ui-CBgg0XeO.js";import"./react-vendor-B_CU-WTZ.js";import{c as d}from"./index-
|
|
1
|
+
import{j as r,$ as c}from"./radix-ui-CBgg0XeO.js";import"./react-vendor-B_CU-WTZ.js";import{c as d}from"./index-D8K1YCe7.js";import{A as h,a as x,b as g,c as m,d as p,e as f,f as j,g as u}from"./alert-dialog-LCg4HaeZ.js";function v({className:t,orientation:e="horizontal",decorative:a=!0,...o}){return r.jsx(c,{"data-slot":"separator",decorative:a,orientation:e,className:d("bg-border shrink-0 data-[orientation=horizontal]:h-px data-[orientation=horizontal]:w-full data-[orientation=vertical]:h-full data-[orientation=vertical]:w-px",t),...o})}function k({open:t,onConfirm:e,onCancel:a,title:o,description:i,confirmText:l="Confirm",variant:n="default"}){return r.jsx(h,{open:t,onOpenChange:s=>!s&&a(),children:r.jsxs(x,{children:[r.jsxs(g,{children:[r.jsx(m,{children:o}),r.jsx(p,{children:i})]}),r.jsxs(f,{children:[r.jsx(j,{onClick:a,children:"Cancel"}),r.jsx(u,{onClick:e,className:n==="destructive"?"bg-red-600 hover:bg-red-700 text-white":"",children:l})]})]})})}export{k as C,v as S};
|