@kaitranntt/ccs 7.50.0-dev.5 → 7.50.0-dev.6

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (83) hide show
  1. package/README.md +32 -4
  2. package/config/base-iflow.settings.json +4 -4
  3. package/dist/auth/account-context.d.ts +6 -0
  4. package/dist/auth/account-context.d.ts.map +1 -1
  5. package/dist/auth/account-context.js +13 -4
  6. package/dist/auth/account-context.js.map +1 -1
  7. package/dist/auth/auth-commands.d.ts.map +1 -1
  8. package/dist/auth/auth-commands.js +3 -0
  9. package/dist/auth/auth-commands.js.map +1 -1
  10. package/dist/auth/commands/create-command-env.d.ts +3 -0
  11. package/dist/auth/commands/create-command-env.d.ts.map +1 -0
  12. package/dist/auth/commands/create-command-env.js +55 -0
  13. package/dist/auth/commands/create-command-env.js.map +1 -0
  14. package/dist/auth/commands/create-command.d.ts.map +1 -1
  15. package/dist/auth/commands/create-command.js +132 -29
  16. package/dist/auth/commands/create-command.js.map +1 -1
  17. package/dist/auth/commands/list-command.d.ts.map +1 -1
  18. package/dist/auth/commands/list-command.js +2 -0
  19. package/dist/auth/commands/list-command.js.map +1 -1
  20. package/dist/auth/commands/types.d.ts +1 -0
  21. package/dist/auth/commands/types.d.ts.map +1 -1
  22. package/dist/auth/commands/types.js +22 -0
  23. package/dist/auth/commands/types.js.map +1 -1
  24. package/dist/auth/profile-registry.d.ts +1 -0
  25. package/dist/auth/profile-registry.d.ts.map +1 -1
  26. package/dist/auth/profile-registry.js +38 -7
  27. package/dist/auth/profile-registry.js.map +1 -1
  28. package/dist/cliproxy/config/env-builder.d.ts.map +1 -1
  29. package/dist/cliproxy/config/env-builder.js +57 -0
  30. package/dist/cliproxy/config/env-builder.js.map +1 -1
  31. package/dist/config/migration-manager.d.ts.map +1 -1
  32. package/dist/config/migration-manager.js +16 -0
  33. package/dist/config/migration-manager.js.map +1 -1
  34. package/dist/management/instance-manager.d.ts +1 -0
  35. package/dist/management/instance-manager.d.ts.map +1 -1
  36. package/dist/management/instance-manager.js +13 -8
  37. package/dist/management/instance-manager.js.map +1 -1
  38. package/dist/management/profile-context-sync-lock.d.ts +14 -0
  39. package/dist/management/profile-context-sync-lock.d.ts.map +1 -0
  40. package/dist/management/profile-context-sync-lock.js +174 -0
  41. package/dist/management/profile-context-sync-lock.js.map +1 -0
  42. package/dist/management/shared-manager.d.ts +6 -0
  43. package/dist/management/shared-manager.d.ts.map +1 -1
  44. package/dist/management/shared-manager.js +46 -6
  45. package/dist/management/shared-manager.js.map +1 -1
  46. package/dist/ui/assets/accounts-hMd2X1rs.js +1 -0
  47. package/dist/ui/assets/{alert-dialog-Cbz7hjbH.js → alert-dialog-DYqj_ln8.js} +1 -1
  48. package/dist/ui/assets/{api-CtPIBYPJ.js → api-DUB7WunM.js} +1 -1
  49. package/dist/ui/assets/{auth-section-DDB-gXA-.js → auth-section-BPGGH-pS.js} +1 -1
  50. package/dist/ui/assets/{backups-section-f3TrZYc_.js → backups-section-taD9idsR.js} +1 -1
  51. package/dist/ui/assets/{checkbox-DyM_OviW.js → checkbox-C2wWJ45q.js} +1 -1
  52. package/dist/ui/assets/cliproxy-DQBcXCu5.js +3 -0
  53. package/dist/ui/assets/{cliproxy-control-panel-D-0qYG1v.js → cliproxy-control-panel-D_JZc88E.js} +1 -1
  54. package/dist/ui/assets/{confirm-dialog-B1DNTIER.js → confirm-dialog-CQGjNqDg.js} +1 -1
  55. package/dist/ui/assets/{copilot-CsbHY1RT.js → copilot-C55LbvKL.js} +1 -1
  56. package/dist/ui/assets/{cursor-Dae1NLqC.js → cursor-DRxLX6HL.js} +1 -1
  57. package/dist/ui/assets/{droid-BQLHOVuB.js → droid-DlECj4OZ.js} +1 -1
  58. package/dist/ui/assets/{globalenv-section-DryB5ety.js → globalenv-section-BZl3-nsE.js} +1 -1
  59. package/dist/ui/assets/{health-DXE1K5e_.js → health-KcXhO7a4.js} +1 -1
  60. package/dist/ui/assets/{index-BOyrh__4.js → index-BtROiILs.js} +2 -2
  61. package/dist/ui/assets/{index-BDygjMjY.js → index-Cl4dUJFw.js} +1 -1
  62. package/dist/ui/assets/{index-BGM7ArZ-.js → index-D7S6Q5bp.js} +1 -1
  63. package/dist/ui/assets/{index-Dt0OpGYK.js → index-fsXcStKP.js} +1 -1
  64. package/dist/ui/assets/{index-n1iv9ylt.js → index-mxDT1Fbu.js} +1 -1
  65. package/dist/ui/assets/{proxy-status-widget-Bvi7eWkI.js → proxy-status-widget-BxkoV1g7.js} +1 -1
  66. package/dist/ui/assets/{separator-DrB7U5vm.js → separator-lXjk7_Ls.js} +1 -1
  67. package/dist/ui/assets/{shared-ByrShSly.js → shared-NtPxxEp6.js} +1 -1
  68. package/dist/ui/assets/{switch-JJlvFHut.js → switch-lf-m6i0R.js} +1 -1
  69. package/dist/ui/assets/{updates-BUBIr73T.js → updates-Dok03EVa.js} +1 -1
  70. package/dist/ui/index.html +1 -1
  71. package/dist/web-server/routes/account-route-helpers.d.ts +17 -0
  72. package/dist/web-server/routes/account-route-helpers.d.ts.map +1 -0
  73. package/dist/web-server/routes/account-route-helpers.js +34 -0
  74. package/dist/web-server/routes/account-route-helpers.js.map +1 -0
  75. package/dist/web-server/routes/account-routes.d.ts.map +1 -1
  76. package/dist/web-server/routes/account-routes.js +36 -27
  77. package/dist/web-server/routes/account-routes.js.map +1 -1
  78. package/dist/web-server/routes/config-routes.d.ts.map +1 -1
  79. package/dist/web-server/routes/config-routes.js +59 -0
  80. package/dist/web-server/routes/config-routes.js.map +1 -1
  81. package/package.json +1 -1
  82. package/dist/ui/assets/accounts-Cv9gdSl_.js +0 -1
  83. package/dist/ui/assets/cliproxy-nwnHc6Ex.js +0 -3
@@ -1 +1 @@
1
- import{j as e}from"./radix-ui-DIWAxjEp.js";import{r as o}from"./react-vendor-CNOkPC89.js";import{B as k,c as _,T as Oe,o as Te,p as Ae,q as Ee,r as _e,s as Se,t as ke,v as se,b as N,I as A,m as K,L as T,w as D,x as de,y as Pe,z as Re,A as De,D as Me,S as te,E as H,F as Y,G as xe,H as Le,J as Ie,K as me,M as ue,N as he,O as Ue,Q as He,R as ae,U as ne,V as Fe,W as $e,X as W,C as Ke,i as ze,j as Je,Y as Be,a as Qe,Z as qe,_ as Ve,$ as Ye,a0 as Ge}from"./index-BOyrh__4.js";import{a as We,u as Xe,b as re}from"./tanstack-Hn82hibe.js";import{C as G}from"./confirm-dialog-B1DNTIER.js";import{t as I}from"./notifications-B2HqRBj7.js";import{L as F,R as z,ah as fe,ai as Ze,E as es,e as ss,a0 as $,I as ts,aj as pe,a1 as X,c as ge,ak as as,$ as ns,al as rs,n as je,X as is,Z as Ne,am as ls,a5 as cs,a2 as ve,an as os,r as be}from"./icons-D7XDTBCN.js";import{S as ie}from"./separator-DrB7U5vm.js";import"./utils-CzKF5WmX.js";import"./form-utils-Cn_Uld6y.js";import"./code-highlight-BRUf_pqB.js";import"./alert-dialog-Cbz7hjbH.js";function ds({className:s,showTooltip:a=!0}){const t=e.jsxs(k,{variant:"outline",className:_("bg-accent/10 border-accent/30 text-accent","dark:bg-accent/20 dark:border-accent/40 dark:text-accent-foreground",s),children:[e.jsx("img",{src:"/icons/openrouter.svg",alt:"OpenRouter",className:"mr-1 h-3 w-3"}),"OpenRouter"]});return a?e.jsxs(Oe,{children:[e.jsx(Te,{asChild:!0,children:t}),e.jsx(Ae,{children:e.jsx("p",{children:"Access 349+ models via OpenRouter"})})]}):t}function le(s){return[/^ANTHROPIC_AUTH_TOKEN$/,/_API_KEY$/,/_AUTH_TOKEN$/,/^API_KEY$/,/^AUTH_TOKEN$/,/_SECRET$/,/^SECRET$/].some(t=>t.test(s))}function we(s){return s?.env?(s.env.ANTHROPIC_BASE_URL||"").toLowerCase().includes("openrouter.ai"):!1}function xs(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 ms(s,a){const t={...s};return a.opus?t.ANTHROPIC_DEFAULT_OPUS_MODEL=a.opus:delete t.ANTHROPIC_DEFAULT_OPUS_MODEL,a.sonnet?t.ANTHROPIC_DEFAULT_SONNET_MODEL=a.sonnet:delete t.ANTHROPIC_DEFAULT_SONNET_MODEL,a.haiku?t.ANTHROPIC_DEFAULT_HAIKU_MODEL=a.haiku:delete t.ANTHROPIC_DEFAULT_HAIKU_MODEL,t}function us({profileName:s,target:a,data:t,settings:d,isLoading:x,isSaving:m,isTargetSaving:f,hasChanges:l,isRawJsonValid:i,onTargetChange:u,onRefresh:g,onDelete:O,onSave:b}){const v=m||f,j=x||v;return e.jsxs("div",{className:"px-6 py-4 border-b bg-background flex items-center justify-between shrink-0",children:[e.jsxs("div",{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(k,{variant:"outline",className:"text-xs",children:t.path.replace(/^.*\//,"")}),we(d)&&e.jsx(ds,{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:"mt-2 flex items-center gap-2",children:[e.jsx("span",{className:"text-xs text-muted-foreground",children:"Default target:"}),e.jsxs(Ee,{value:a,onValueChange:w=>{j||u(w)},disabled:j,children:[e.jsx(_e,{className:"h-7 w-[170px] text-xs",disabled:j,children:e.jsx(Se,{})}),e.jsxs(ke,{children:[e.jsx(se,{value:"claude",children:"Claude Code"}),e.jsx(se,{value:"droid",children:"Factory Droid"})]})]}),f&&e.jsx(F,{className:"w-3.5 h-3.5 animate-spin text-muted-foreground"})]})]}),e.jsxs("div",{className:"flex items-center gap-2",children:[e.jsx(N,{variant:"ghost",size:"sm",onClick:g,disabled:j,children:e.jsx(z,{className:`w-4 h-4 ${x?"animate-spin":""}`})}),O&&e.jsx(N,{variant:"ghost",size:"sm",onClick:O,disabled:v,children:e.jsx(fe,{className:"w-4 h-4 text-destructive"})}),e.jsx(N,{size:"sm",onClick:b,disabled:v||!l||!i,children:m?e.jsxs(e.Fragment,{children:[e.jsx(F,{className:"w-4 h-4 mr-1 animate-spin"}),"Saving..."]}):e.jsxs(e.Fragment,{children:[e.jsx(Ze,{className:"w-4 h-4 mr-1"}),"Save"]})})]})]})}function Ce({label:s,...a}){const[t,d]=o.useState(!1);return e.jsxs("div",{className:"space-y-1",children:[s&&e.jsx("label",{className:"text-sm font-medium",children:s}),e.jsxs("div",{className:"relative",children:[e.jsx(A,{type:t?"text":"password",className:"pr-10 font-mono",...a}),e.jsx(N,{type:"button",variant:"ghost",size:"sm",className:"absolute right-0 top-0 h-full px-3",onClick:()=>d(!t),tabIndex:-1,children:t?e.jsx(es,{className:"w-4 h-4"}):e.jsx(ss,{className:"w-4 h-4"})})]})]})}function hs({currentSettings:s,newEnvKey:a,newEnvValue:t,onNewEnvKeyChange:d,onNewEnvValueChange:x,onEnvValueChange:m,onAddEnvVar:f}){return e.jsxs(e.Fragment,{children:[e.jsx(K,{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(([l,i])=>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:[l,le(l)&&e.jsx(k,{variant:"secondary",className:"text-[10px] px-1 py-0 h-4",children:"sensitive"})]}),le(l)?e.jsx(Ce,{value:i,onChange:u=>m(l,u.target.value),className:"font-mono text-sm h-8"}):e.jsx(A,{value:i,onChange:u=>m(l,u.target.value),className:"font-mono text-sm h-8"})]},l))}):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(A,{placeholder:"VARIABLE_NAME",value:a,onChange:l=>d(l.target.value.toUpperCase()),className:"font-mono text-sm h-8 w-2/5",onKeyDown:l=>l.key==="Enter"&&a.trim()&&f()}),e.jsx(A,{placeholder:"value",value:t,onChange:l=>x(l.target.value),className:"font-mono text-sm h-8 flex-1",onKeyDown:l=>l.key==="Enter"&&a.trim()&&f()}),e.jsx(N,{variant:"outline",size:"sm",className:"h-8",onClick:f,disabled:!a.trim(),children:e.jsx($,{className:"w-4 h-4"})})]})]})]})}function fs({profileName:s,target:a,data:t}){const d=a==="droid";return e.jsx(K,{className:"h-full",children:e.jsxs("div",{className:"p-4 space-y-6",children:[e.jsxs("div",{children:[e.jsxs("h3",{className:"text-sm font-medium flex items-center gap-2 mb-3",children:[e.jsx(ts,{className:"w-4 h-4"}),"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(D,{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:"Default Target"}),e.jsx("span",{className:"font-mono",children:a})]})]})})]}),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(D,{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:d?"Droid alias (explicit)":"Run on Droid"}),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:d?`ccsd ${s} "prompt"`:`ccs ${s} --target droid "prompt"`}),e.jsx(D,{value:d?`ccsd ${s} "prompt"`:`ccs ${s} --target droid "prompt"`,size:"icon",className:"h-6 w-6"})]})]}),e.jsxs("div",{children:[e.jsx(T,{className:"text-xs text-muted-foreground",children:d?"Override to Claude":"Override to Claude (explicit)"}),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,' --target claude "prompt"']}),e.jsx(D,{value:`ccs ${s} --target claude "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(D,{value:`ccs default ${s}`,size:"icon",className:"h-6 w-6"})]})]})]})]})]})})}function ps({value:s,onChange:a,placeholder:t="Search models...",className:d}){const[x,m]=o.useState(""),[f,l]=o.useState(null),{models:i,isLoading:u,isError:g,isFetching:O}=de(),b=Pe(),v=o.useMemo(()=>Re(i,x,{category:f??void 0}),[i,x,f]),j=o.useMemo(()=>De(i,2),[i]),w=!x.trim()&&!f,S=o.useMemo(()=>{const r={anthropic:[],openai:[],google:[],meta:[],mistral:[],opensource:[],other:[]};v.forEach(h=>{r[h.category].push(h)});for(const h of Object.keys(r))r[h]=Me(r[h]);return r},[v]),E=o.useCallback(()=>{b()},[b]),C=i.find(r=>r.id===s);return u&&i.length===0?e.jsxs("div",{className:_("space-y-2",d),children:[e.jsx(te,{className:"h-10 w-full"}),e.jsx(te,{className:"h-32 w-full"})]}):e.jsxs("div",{className:_("space-y-2 w-full min-w-0 overflow-hidden",d),children:[e.jsxs("div",{className:"flex gap-2",children:[e.jsxs("div",{className:"relative flex-1",children:[e.jsx(pe,{className:"text-muted-foreground absolute left-3 top-1/2 h-4 w-4 -translate-y-1/2"}),e.jsx(A,{value:x,onChange:r=>m(r.target.value),placeholder:t,className:"pl-9"})]}),e.jsx(N,{variant:"outline",size:"icon",onClick:E,disabled:O,title:"Refresh models",children:O?e.jsx(F,{className:"h-4 w-4 animate-spin"}):e.jsx(z,{className:"h-4 w-4"})})]}),e.jsxs("div",{className:"flex flex-wrap gap-1",children:[e.jsxs(k,{variant:f===null?"default":"outline",className:"cursor-pointer",onClick:()=>l(null),children:["All (",i.length,")"]}),Object.keys(H).map(r=>{const h=S[r].length;return h===0?null:e.jsxs(k,{variant:f===r?"default":"outline",className:"cursor-pointer",onClick:()=>l(r),children:[H[r]," (",h,")"]},r)})]}),C&&e.jsxs("div",{className:"bg-muted rounded-md p-2 text-sm",children:[e.jsx("span",{className:"font-medium",children:C.name}),e.jsxs("span",{className:"text-muted-foreground ml-2",children:[Y(C.pricing)," |"," ",xe(C.context_length)]})]}),e.jsx(K,{className:"h-72 w-full rounded-md border",children:g?e.jsxs("div",{className:"text-destructive p-4 text-center",children:["Failed to load models."," ",e.jsx(N,{variant:"link",onClick:E,children:"Retry"})]}):v.length===0?e.jsxs("div",{className:"text-muted-foreground p-4 text-center",children:['No models found matching "',x,'"']}):e.jsxs("div",{className:"space-y-6 p-3",children:[w&&j.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(X,{className:"h-3 w-3 text-accent"}),e.jsx("span",{children:"Newest Models"})]}),e.jsx("div",{className:"space-y-1",children:j.map(r=>e.jsx(ce,{model:r,isSelected:r.id===s,onClick:()=>a(r.id),showAge:!0},r.id))})]}),Object.keys(H).map(r=>{const h=S[r];return h.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:H[r]}),e.jsx("div",{className:"space-y-1",children:h.map(n=>e.jsx(ce,{model:n,isSelected:n.id===s,onClick:()=>a(n.id)},n.id))})]},r)})]})})]})}function ce({model:s,isSelected:a,onClick:t,showAge:d=!1}){return e.jsxs("button",{type:"button",onClick:t,className:_("group flex w-full items-center gap-2 rounded-md px-3 py-2 text-left text-sm transition-colors","hover:bg-accent hover:text-accent-foreground",a&&"bg-accent text-accent-foreground"),children:[e.jsx("span",{className:"flex-1 min-w-0 truncate font-medium",children:s.name}),e.jsxs("span",{className:_("flex shrink-0 items-center gap-1 text-xs whitespace-nowrap",a?"text-accent-foreground/80":"text-muted-foreground group-hover:text-accent-foreground/80"),children:[d&&s.created&&e.jsx(k,{variant:"outline",className:_("text-[10px] px-1",a?"border-accent-foreground/30 text-accent-foreground/80":"text-accent border-accent/30 group-hover:text-accent-foreground/80 group-hover:border-accent-foreground/30"),children:Le(s.created)}),s.isFree?e.jsx(k,{variant:"secondary",className:_("text-[10px] px-1",a?"bg-accent-foreground/20 text-accent-foreground":"group-hover:bg-accent-foreground/20 group-hover:text-accent-foreground"),children:"Free"}):s.isExacto?e.jsxs(e.Fragment,{children:[e.jsx(k,{variant:"outline",className:_("text-[10px] px-1 border-emerald-500/50 text-emerald-600",a?"border-accent-foreground/30 text-accent-foreground/80":"group-hover:border-accent-foreground/30 group-hover:text-accent-foreground/80"),children:"Exacto"}),e.jsx("span",{className:"tabular-nums",children:Y(s.pricing)})]}):e.jsx("span",{className:"tabular-nums",children:Y(s.pricing)}),e.jsx("span",{className:"tabular-nums",children:xe(s.context_length)})]})]})}function gs({selectedModel:s,value:a,onChange:t,className:d}){const{models:x}=de(),m=o.useMemo(()=>s?Ie(s,x):{},[s,x]),f=()=>{t(m)},l=(u,g)=>{t({...a,[u]:g||void 0})},i=s&&Object.keys(m).length>0;return e.jsxs(me,{className:_("group",d),children:[e.jsxs(ue,{className:"flex items-center gap-2 text-sm font-medium hover:underline",children:[e.jsx(ge,{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(he,{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."}),i&&e.jsxs(N,{type:"button",variant:"outline",size:"sm",onClick:f,children:[e.jsx(as,{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(A,{id:"tier-opus",value:a.opus??"",onChange:u=>l("opus",u.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(A,{id:"tier-sonnet",value:a.sonnet??"",onChange:u=>l("sonnet",u.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(A,{id:"tier-haiku",value:a.haiku??"",onChange:u=>l("haiku",u.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 js({profileName:s,target:a,data:t,currentSettings:d,newEnvKey:x,newEnvValue:m,onNewEnvKeyChange:f,onNewEnvValueChange:l,onEnvValueChange:i,onAddEnvVar:u,onEnvBulkChange:g}){const O=we(d),b=d?.env,v=o.useMemo(()=>xs(b??{}),[b]),j=b??{},w=n=>{if(g){const P={...j,ANTHROPIC_MODEL:n,ANTHROPIC_DEFAULT_OPUS_MODEL:n,ANTHROPIC_DEFAULT_SONNET_MODEL:n,ANTHROPIC_DEFAULT_HAIKU_MODEL:n};g(P)}else i("ANTHROPIC_MODEL",n),i("ANTHROPIC_DEFAULT_OPUS_MODEL",n),i("ANTHROPIC_DEFAULT_SONNET_MODEL",n),i("ANTHROPIC_DEFAULT_HAIKU_MODEL",n);I.success("Applied model to all tiers",{duration:2e3})},S=n=>{if(g){const P=ms(j,n);g(P)}else n.opus!==void 0&&i("ANTHROPIC_DEFAULT_OPUS_MODEL",n.opus||""),n.sonnet!==void 0&&i("ANTHROPIC_DEFAULT_SONNET_MODEL",n.sonnet||""),n.haiku!==void 0&&i("ANTHROPIC_DEFAULT_HAIKU_MODEL",n.haiku||"")},[E,C]=o.useState(!1),r=new Set(["ANTHROPIC_AUTH_TOKEN"]),h=Object.entries(j).filter(([n])=>!r.has(n));return e.jsx("div",{className:"h-full w-full min-w-0 flex flex-col",children:e.jsxs(Ue,{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(He,{className:"w-full",children:[e.jsx(ae,{value:"env",className:"flex-1",children:O?"Configuration":"Environment Variables"}),e.jsx(ae,{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(ne,{value:"env",className:"flex-1 mt-0 border-0 p-0 data-[state=inactive]:hidden flex flex-col overflow-hidden min-w-0",children:O?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(ps,{value:j.ANTHROPIC_MODEL,onChange:w,placeholder:"Search OpenRouter models..."})]}),e.jsx(gs,{selectedModel:j.ANTHROPIC_MODEL,value:v,onChange:S}),e.jsxs("div",{className:"space-y-2",children:[e.jsx(T,{className:"text-sm font-medium",children:"API Key"}),e.jsx(Ce,{value:j.ANTHROPIC_AUTH_TOKEN||"",onChange:n=>i("ANTHROPIC_AUTH_TOKEN",n.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"})]})]}),h.length>0&&e.jsxs(me,{open:E,onOpenChange:C,children:[e.jsxs(ue,{className:"flex items-center gap-2 text-sm font-medium text-muted-foreground hover:text-foreground transition-colors group",children:[e.jsx(ge,{className:_("h-4 w-4 transition-transform",E&&"rotate-90")}),e.jsx(ns,{className:"h-4 w-4"}),e.jsx("span",{children:"Additional Variables"}),e.jsxs("span",{className:"text-xs font-normal opacity-70",children:["(",h.length,")"]})]}),e.jsx(he,{className:"pt-4",children:e.jsx("div",{className:"space-y-3 border rounded-lg p-3 bg-muted/30",children:h.map(([n,P])=>e.jsxs("div",{className:"space-y-1",children:[e.jsx(T,{className:"text-xs text-muted-foreground",children:n}),e.jsx(A,{value:P,onChange:M=>i(n,M.target.value),className:"font-mono text-xs h-8"})]},n))})})]})]})}),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(A,{placeholder:"VARIABLE_NAME",value:x,onChange:n=>f(n.target.value.toUpperCase()),className:"font-mono text-sm h-8 w-2/5",onKeyDown:n=>n.key==="Enter"&&x.trim()&&u()}),e.jsx(A,{placeholder:"value",value:m,onChange:n=>l(n.target.value),className:"font-mono text-sm h-8 flex-1",onKeyDown:n=>n.key==="Enter"&&x.trim()&&u()}),e.jsx(N,{variant:"outline",size:"sm",className:"h-8",onClick:u,disabled:!x.trim(),children:e.jsx($,{className:"w-4 h-4"})})]})]})]}):e.jsx(hs,{currentSettings:d,newEnvKey:x,newEnvValue:m,onNewEnvKeyChange:f,onNewEnvValueChange:l,onEnvValueChange:i,onAddEnvVar:u})}),e.jsx(ne,{value:"info",className:"h-full mt-0 border-0 p-0 data-[state=inactive]:hidden",children:e.jsx(fs,{profileName:s,target:a,data:t})})]})]})})}function Ns({profileName:s,profileTarget:a,onDelete:t,onHasChangesUpdate:d}){const[x,m]=o.useState({}),[f,l]=o.useState(!1),[i,u]=o.useState(null),[g,O]=o.useState(""),[b,v]=o.useState(""),j=We(),{data:w,isLoading:S,isError:E,refetch:C}=Xe({queryKey:["settings",s],queryFn:async()=>{const c=await fetch(`/api/settings/${s}/raw`);if(!c.ok)throw new Error(`Failed to load settings: ${c.status}`);return c.json()}}),r=w?.settings,h=o.useMemo(()=>{if(i!==null)try{return JSON.parse(i)}catch{}if(r)return{...r,env:{...r.env,...x}}},[r,x,i]),n=o.useMemo(()=>i!==null?i:r?JSON.stringify(r,null,2):"",[i,r]),P=o.useCallback(c=>{u(c)},[]),M=(c,y)=>{const R={...h?.env||{},[c]:y};m(L=>({...L,[c]:y})),u(JSON.stringify({...h,env:R},null,2))},J=c=>{const y={...h?.env||{},...c};m(R=>({...R,...c})),u(JSON.stringify({...h,env:y},null,2))},p=()=>{if(!g.trim())return;const c=g.trim(),y=b,R={...h?.env||{},[c]:y};m(L=>({...L,[c]:y})),u(JSON.stringify({...h,env:R},null,2)),O(""),v("")},Z=o.useMemo(()=>{try{return JSON.parse(n),!0}catch{return!1}},[n]),B=o.useMemo(()=>i!==null?i!==JSON.stringify(r,null,2):Object.keys(x).length>0,[i,x,r]),ye=o.useMemo(()=>{const c=["ANTHROPIC_BASE_URL","ANTHROPIC_AUTH_TOKEN"],y=h?.env||{};return c.filter(R=>!y[R]?.trim())},[h]);o.useEffect(()=>{d?.(B)},[B,d]);const U=re({mutationFn:async()=>{let c;try{c=JSON.parse(n)}catch{c={...w?.settings,env:{...w?.settings?.env,...x}}}const y=await fetch(`/api/settings/${s}`,{method:"PUT",headers:{"Content-Type":"application/json"},body:JSON.stringify({settings:c,expectedMtime:w?.mtime})});if(y.status===409)throw new Error("CONFLICT");if(!y.ok)throw new Error("Failed to save");return y.json()},onSuccess:()=>{j.invalidateQueries({queryKey:["settings",s]}),j.invalidateQueries({queryKey:["profiles"]}),m({}),u(null),I.success("Settings saved")},onError:c=>{c.message==="CONFLICT"?l(!0):I.error(c.message)}}),Q=re({mutationFn:async c=>(await $e.profiles.update(s,{target:c}),c),onSuccess:()=>{j.invalidateQueries({queryKey:["profiles"]}),I.success("Default target updated")},onError:(c,y)=>{const R=y==="droid"?"Factory Droid":"Claude Code",L=c.message.trim()?`: ${c.message}`:"";I.error(`Failed to update default target to ${R}${L}`)}}),q=a||"claude",V=U.isPending||Q.isPending,ee=async c=>{l(!1),c?(await C(),U.mutate()):(m({}),u(null))};return e.jsxs("div",{className:"flex-1 flex flex-col overflow-hidden",children:[e.jsx(us,{profileName:s,target:q,data:w,settings:h,isLoading:S,isSaving:U.isPending,isTargetSaving:Q.isPending,hasChanges:B,isRawJsonValid:Z,onTargetChange:c=>{V||c!==q&&Q.mutate(c)},onRefresh:()=>{V||C()},onDelete:t,onSave:()=>{V||U.mutate()}}),S?e.jsxs("div",{className:"flex-1 flex items-center justify-center",children:[e.jsx(F,{className:"w-8 h-8 animate-spin text-muted-foreground"}),e.jsx("span",{className:"ml-3 text-muted-foreground",children:"Loading settings..."})]}):E?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(N,{variant:"outline",size:"sm",onClick:()=>C(),children:[e.jsx(z,{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(js,{profileName:s,target:q,data:w,currentSettings:h,newEnvKey:g,newEnvValue:b,onNewEnvKeyChange:O,onNewEnvValueChange:v,onEnvValueChange:M,onEnvBulkChange:J,onAddEnvVar:p})}),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(rs,{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(Fe,{rawJsonContent:n,isRawJsonValid:Z,rawJsonEdits:i,settings:r,onChange:P,missingRequiredFields:ye})]})]}),e.jsx(G,{open:f,title:"File Modified Externally",description:"Overwrite with your changes or discard?",confirmText:"Overwrite",variant:"destructive",onConfirm:()=>ee(!0),onCancel:()=>ee(!1)})]},s)}const oe="ccs:openrouter-banner-dismissed";function vs({onCreateClick:s}){const[a,t]=o.useState(!0),{modelCount:d,isLoading:x}=W();o.useEffect(()=>{const f=localStorage.getItem(oe)==="true";t(f)},[]);const m=()=>{localStorage.setItem(oe,"true"),t(!0)};return a?null:e.jsx("div",{className:"bg-gradient-to-r from-accent to-accent/90 text-white px-4 py-3 relative shrink-0",children:e.jsxs("div",{className:"flex items-center justify-between gap-4 max-w-screen-xl mx-auto",children:[e.jsxs("div",{className:"flex items-center gap-3 flex-1 min-w-0",children:[e.jsx("div",{className:"p-1.5 bg-white/20 rounded-md shrink-0",children:e.jsx(X,{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 ",x?"300+":`${d}+`," models from OpenAI, Anthropic, Google, Meta and more."]})]})]}),e.jsxs("div",{className:"flex items-center gap-2 shrink-0",children:[s&&e.jsx(N,{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(je,{className:"w-3 h-3"})]}),e.jsxs(N,{size:"icon",variant:"ghost",onClick:m,className:"h-7 w-7 text-white/70 hover:text-white hover:bg-white/20",children:[e.jsx(is,{className:"w-4 h-4"}),e.jsx("span",{className:"sr-only",children:"Dismiss"})]})]})]})})}function bs({onOpenRouterClick:s,onCustomClick:a}){const{modelCount:t,isLoading:d}=W();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(Ke,{className:"border-accent/30 dark:border-accent/40 bg-gradient-to-br from-accent/5 to-background dark:from-accent/10",children:[e.jsxs(ze,{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(k,{variant:"secondary",className:"bg-accent/10 text-accent dark:bg-accent/20 dark:text-accent-foreground",children:"Recommended"})]}),e.jsx(Je,{className:"text-xl",children:"Start with OpenRouter"}),e.jsxs(Be,{className:"text-base",children:["Access ",d?"300+":`${t}+`," models from OpenAI, Anthropic, Google, Meta and more - all through one API."]})]}),e.jsxs(Qe,{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(Ne,{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(X,{className:"w-4 h-4 text-accent"}),e.jsx("span",{children:"Model tier mapping"})]})]}),e.jsxs(N,{onClick:s,className:"w-full bg-accent hover:bg-accent/90 text-white",size:"lg",children:["Create OpenRouter Profile",e.jsx(ls,{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(je,{className:"w-3 h-3"})]})]})]})]}),e.jsxs("div",{className:"flex items-center gap-4",children:[e.jsx(ie,{className:"flex-1"}),e.jsx("span",{className:"text-xs text-muted-foreground",children:"or"}),e.jsx(ie,{className:"flex-1"})]}),e.jsx(N,{variant:"outline",onClick:a,className:"w-full",children:"Create Custom API Profile"})]})})}function ws({onCreateClick:s}){const{modelCount:a,isLoading:t}=W();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:[t?"300+":`${a}+`," models available"]})]}),e.jsxs(N,{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(Ne,{className:"w-3 h-3 mr-1"}),e.jsx("span",{className:"text-xs",children:"Add"})]})]})})}function Ls(){const{data:s,isLoading:a,isError:t,refetch:d}=qe(),x=Ve(),[m,f]=o.useState(null),[l,i]=o.useState(""),[u,g]=o.useState(!1),[O,b]=o.useState("normal"),[v,j]=o.useState(null),[w,S]=o.useState(!1),[E,C]=o.useState(null);Ye();const r=o.useMemo(()=>s?.profiles||[],[s?.profiles]),h=o.useMemo(()=>r.filter(p=>p.name.toLowerCase().includes(l.toLowerCase())),[r,l]),n=m?r.find(p=>p.name===m):null,P=p=>{x.mutate(p,{onSuccess:()=>{m===p&&f(null),j(null)}})},M=p=>{g(!1),w&&m!==null?C(p):f(p)},J=p=>{w&&m!==p?C(p):f(p)};return e.jsxs("div",{className:"h-[calc(100vh-100px)] flex flex-col",children:[e.jsx(vs,{onCreateClick:()=>g(!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(cs,{className:"w-5 h-5 text-primary"}),e.jsx("h1",{className:"font-semibold",children:"API Profiles"})]}),e.jsxs(N,{size:"sm",onClick:()=>{g(!0)},children:[e.jsx($,{className:"w-4 h-4 mr-1"}),"New"]})]}),e.jsxs("div",{className:"relative",children:[e.jsx(pe,{className:"absolute left-2.5 top-2.5 h-4 w-4 text-muted-foreground"}),e.jsx(A,{placeholder:"Search profiles...",className:"pl-8 h-9",value:l,onChange:p=>i(p.target.value)})]})]}),e.jsx(K,{className:"flex-1",children:a?e.jsx("div",{className:"p-4 text-sm text-muted-foreground",children:"Loading profiles..."}):t?e.jsx("div",{className:"p-4 text-center",children:e.jsxs("div",{className:"space-y-3 py-8",children:[e.jsx(ve,{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(N,{size:"sm",variant:"outline",onClick:()=>d(),children:[e.jsx(z,{className:"w-4 h-4 mr-1"}),"Retry"]})]})}):h.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(os,{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(N,{size:"sm",variant:"outline",onClick:()=>{g(!0)},children:[e.jsx($,{className:"w-4 h-4 mr-1"}),"Create Profile"]})]}):e.jsxs("p",{className:"text-sm text-muted-foreground py-4",children:['No profiles match "',l,'"']})}):e.jsx("div",{className:"p-2 space-y-1",children:h.map(p=>e.jsx(Cs,{profile:p,isSelected:m===p.name,onSelect:()=>J(p.name),onDelete:()=>j(p.name)},p.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(be,{className:"w-3 h-3 text-green-600"}),r.filter(p=>p.configured).length," configured"]})]})}),e.jsx(ws,{onCreateClick:()=>{b("openrouter"),g(!0)}})]}),e.jsx("div",{className:"flex-1 flex flex-col min-w-0",children:n?e.jsx(Ns,{profileName:n.name,profileTarget:n.target,onDelete:()=>j(n.name),onHasChangesUpdate:S},n.name):e.jsx(bs,{onOpenRouterClick:()=>{b("openrouter"),g(!0)},onCustomClick:()=>{b("normal"),g(!0)}})})]}),e.jsx(Ge,{open:u,onOpenChange:g,onSuccess:M,initialMode:O}),e.jsx(G,{open:!!v,title:"Delete Profile",description:`Are you sure you want to delete "${v}"? This will remove the settings file and cannot be undone.`,confirmText:"Delete",variant:"destructive",onConfirm:()=>v&&P(v),onCancel:()=>j(null)}),e.jsx(G,{open:!!E,title:"Unsaved Changes",description:`You have unsaved changes in "${m}". Discard and switch to "${E}"?`,confirmText:"Discard & Switch",variant:"destructive",onConfirm:()=>{S(!1),f(E),C(null)},onCancel:()=>C(null)})]})}function Cs({profile:s,isSelected:a,onSelect:t,onDelete:d}){return e.jsxs("div",{className:_("group flex items-center gap-2 px-3 py-2.5 rounded-md cursor-pointer transition-colors",a?"bg-primary/10 border border-primary/20":"hover:bg-muted border border-transparent"),onClick:t,children:[s.configured?e.jsx(be,{className:"w-4 h-4 text-green-600 shrink-0"}):e.jsx(ve,{className:"w-4 h-4 text-yellow-600 shrink-0"}),e.jsxs("div",{className:"flex-1 min-w-0",children:[e.jsxs("div",{className:"flex items-center gap-2 min-w-0",children:[e.jsx("div",{className:"font-medium text-sm truncate",children:s.name}),e.jsx(k,{variant:"outline",className:"text-[10px] h-4 px-1.5 uppercase",children:s.target||"claude"})]}),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(D,{value:s.settingsPath,size:"icon",className:"h-5 w-5 opacity-0 group-hover:opacity-100 transition-opacity"})]})]}),e.jsx(N,{variant:"ghost",size:"icon",className:"h-7 w-7 opacity-0 group-hover:opacity-100 transition-opacity",onClick:x=>{x.stopPropagation(),d()},children:e.jsx(fe,{className:"w-3.5 h-3.5 text-destructive"})})]})}export{Ls as ApiPage};
1
+ import{j as e}from"./radix-ui-DIWAxjEp.js";import{r as o}from"./react-vendor-CNOkPC89.js";import{B as k,c as _,T as Oe,o as Te,p as Ae,q as Ee,r as _e,s as Se,t as ke,v as se,b as N,I as A,m as K,L as T,w as D,x as de,y as Pe,z as Re,A as De,D as Me,S as te,E as H,F as Y,G as xe,H as Le,J as Ie,K as me,M as ue,N as he,O as Ue,Q as He,R as ae,U as ne,V as Fe,W as $e,X as W,C as Ke,i as ze,j as Je,Y as Be,a as Qe,Z as qe,_ as Ve,$ as Ye,a0 as Ge}from"./index-BtROiILs.js";import{a as We,u as Xe,b as re}from"./tanstack-Hn82hibe.js";import{C as G}from"./confirm-dialog-CQGjNqDg.js";import{t as I}from"./notifications-B2HqRBj7.js";import{L as F,R as z,ah as fe,ai as Ze,E as es,e as ss,a0 as $,I as ts,aj as pe,a1 as X,c as ge,ak as as,$ as ns,al as rs,n as je,X as is,Z as Ne,am as ls,a5 as cs,a2 as ve,an as os,r as be}from"./icons-D7XDTBCN.js";import{S as ie}from"./separator-lXjk7_Ls.js";import"./utils-CzKF5WmX.js";import"./form-utils-Cn_Uld6y.js";import"./code-highlight-BRUf_pqB.js";import"./alert-dialog-DYqj_ln8.js";function ds({className:s,showTooltip:a=!0}){const t=e.jsxs(k,{variant:"outline",className:_("bg-accent/10 border-accent/30 text-accent","dark:bg-accent/20 dark:border-accent/40 dark:text-accent-foreground",s),children:[e.jsx("img",{src:"/icons/openrouter.svg",alt:"OpenRouter",className:"mr-1 h-3 w-3"}),"OpenRouter"]});return a?e.jsxs(Oe,{children:[e.jsx(Te,{asChild:!0,children:t}),e.jsx(Ae,{children:e.jsx("p",{children:"Access 349+ models via OpenRouter"})})]}):t}function le(s){return[/^ANTHROPIC_AUTH_TOKEN$/,/_API_KEY$/,/_AUTH_TOKEN$/,/^API_KEY$/,/^AUTH_TOKEN$/,/_SECRET$/,/^SECRET$/].some(t=>t.test(s))}function we(s){return s?.env?(s.env.ANTHROPIC_BASE_URL||"").toLowerCase().includes("openrouter.ai"):!1}function xs(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 ms(s,a){const t={...s};return a.opus?t.ANTHROPIC_DEFAULT_OPUS_MODEL=a.opus:delete t.ANTHROPIC_DEFAULT_OPUS_MODEL,a.sonnet?t.ANTHROPIC_DEFAULT_SONNET_MODEL=a.sonnet:delete t.ANTHROPIC_DEFAULT_SONNET_MODEL,a.haiku?t.ANTHROPIC_DEFAULT_HAIKU_MODEL=a.haiku:delete t.ANTHROPIC_DEFAULT_HAIKU_MODEL,t}function us({profileName:s,target:a,data:t,settings:d,isLoading:x,isSaving:m,isTargetSaving:f,hasChanges:l,isRawJsonValid:i,onTargetChange:u,onRefresh:g,onDelete:O,onSave:b}){const v=m||f,j=x||v;return e.jsxs("div",{className:"px-6 py-4 border-b bg-background flex items-center justify-between shrink-0",children:[e.jsxs("div",{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(k,{variant:"outline",className:"text-xs",children:t.path.replace(/^.*\//,"")}),we(d)&&e.jsx(ds,{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:"mt-2 flex items-center gap-2",children:[e.jsx("span",{className:"text-xs text-muted-foreground",children:"Default target:"}),e.jsxs(Ee,{value:a,onValueChange:w=>{j||u(w)},disabled:j,children:[e.jsx(_e,{className:"h-7 w-[170px] text-xs",disabled:j,children:e.jsx(Se,{})}),e.jsxs(ke,{children:[e.jsx(se,{value:"claude",children:"Claude Code"}),e.jsx(se,{value:"droid",children:"Factory Droid"})]})]}),f&&e.jsx(F,{className:"w-3.5 h-3.5 animate-spin text-muted-foreground"})]})]}),e.jsxs("div",{className:"flex items-center gap-2",children:[e.jsx(N,{variant:"ghost",size:"sm",onClick:g,disabled:j,children:e.jsx(z,{className:`w-4 h-4 ${x?"animate-spin":""}`})}),O&&e.jsx(N,{variant:"ghost",size:"sm",onClick:O,disabled:v,children:e.jsx(fe,{className:"w-4 h-4 text-destructive"})}),e.jsx(N,{size:"sm",onClick:b,disabled:v||!l||!i,children:m?e.jsxs(e.Fragment,{children:[e.jsx(F,{className:"w-4 h-4 mr-1 animate-spin"}),"Saving..."]}):e.jsxs(e.Fragment,{children:[e.jsx(Ze,{className:"w-4 h-4 mr-1"}),"Save"]})})]})]})}function Ce({label:s,...a}){const[t,d]=o.useState(!1);return e.jsxs("div",{className:"space-y-1",children:[s&&e.jsx("label",{className:"text-sm font-medium",children:s}),e.jsxs("div",{className:"relative",children:[e.jsx(A,{type:t?"text":"password",className:"pr-10 font-mono",...a}),e.jsx(N,{type:"button",variant:"ghost",size:"sm",className:"absolute right-0 top-0 h-full px-3",onClick:()=>d(!t),tabIndex:-1,children:t?e.jsx(es,{className:"w-4 h-4"}):e.jsx(ss,{className:"w-4 h-4"})})]})]})}function hs({currentSettings:s,newEnvKey:a,newEnvValue:t,onNewEnvKeyChange:d,onNewEnvValueChange:x,onEnvValueChange:m,onAddEnvVar:f}){return e.jsxs(e.Fragment,{children:[e.jsx(K,{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(([l,i])=>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:[l,le(l)&&e.jsx(k,{variant:"secondary",className:"text-[10px] px-1 py-0 h-4",children:"sensitive"})]}),le(l)?e.jsx(Ce,{value:i,onChange:u=>m(l,u.target.value),className:"font-mono text-sm h-8"}):e.jsx(A,{value:i,onChange:u=>m(l,u.target.value),className:"font-mono text-sm h-8"})]},l))}):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(A,{placeholder:"VARIABLE_NAME",value:a,onChange:l=>d(l.target.value.toUpperCase()),className:"font-mono text-sm h-8 w-2/5",onKeyDown:l=>l.key==="Enter"&&a.trim()&&f()}),e.jsx(A,{placeholder:"value",value:t,onChange:l=>x(l.target.value),className:"font-mono text-sm h-8 flex-1",onKeyDown:l=>l.key==="Enter"&&a.trim()&&f()}),e.jsx(N,{variant:"outline",size:"sm",className:"h-8",onClick:f,disabled:!a.trim(),children:e.jsx($,{className:"w-4 h-4"})})]})]})]})}function fs({profileName:s,target:a,data:t}){const d=a==="droid";return e.jsx(K,{className:"h-full",children:e.jsxs("div",{className:"p-4 space-y-6",children:[e.jsxs("div",{children:[e.jsxs("h3",{className:"text-sm font-medium flex items-center gap-2 mb-3",children:[e.jsx(ts,{className:"w-4 h-4"}),"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(D,{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:"Default Target"}),e.jsx("span",{className:"font-mono",children:a})]})]})})]}),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(D,{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:d?"Droid alias (explicit)":"Run on Droid"}),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:d?`ccsd ${s} "prompt"`:`ccs ${s} --target droid "prompt"`}),e.jsx(D,{value:d?`ccsd ${s} "prompt"`:`ccs ${s} --target droid "prompt"`,size:"icon",className:"h-6 w-6"})]})]}),e.jsxs("div",{children:[e.jsx(T,{className:"text-xs text-muted-foreground",children:d?"Override to Claude":"Override to Claude (explicit)"}),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,' --target claude "prompt"']}),e.jsx(D,{value:`ccs ${s} --target claude "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(D,{value:`ccs default ${s}`,size:"icon",className:"h-6 w-6"})]})]})]})]})]})})}function ps({value:s,onChange:a,placeholder:t="Search models...",className:d}){const[x,m]=o.useState(""),[f,l]=o.useState(null),{models:i,isLoading:u,isError:g,isFetching:O}=de(),b=Pe(),v=o.useMemo(()=>Re(i,x,{category:f??void 0}),[i,x,f]),j=o.useMemo(()=>De(i,2),[i]),w=!x.trim()&&!f,S=o.useMemo(()=>{const r={anthropic:[],openai:[],google:[],meta:[],mistral:[],opensource:[],other:[]};v.forEach(h=>{r[h.category].push(h)});for(const h of Object.keys(r))r[h]=Me(r[h]);return r},[v]),E=o.useCallback(()=>{b()},[b]),C=i.find(r=>r.id===s);return u&&i.length===0?e.jsxs("div",{className:_("space-y-2",d),children:[e.jsx(te,{className:"h-10 w-full"}),e.jsx(te,{className:"h-32 w-full"})]}):e.jsxs("div",{className:_("space-y-2 w-full min-w-0 overflow-hidden",d),children:[e.jsxs("div",{className:"flex gap-2",children:[e.jsxs("div",{className:"relative flex-1",children:[e.jsx(pe,{className:"text-muted-foreground absolute left-3 top-1/2 h-4 w-4 -translate-y-1/2"}),e.jsx(A,{value:x,onChange:r=>m(r.target.value),placeholder:t,className:"pl-9"})]}),e.jsx(N,{variant:"outline",size:"icon",onClick:E,disabled:O,title:"Refresh models",children:O?e.jsx(F,{className:"h-4 w-4 animate-spin"}):e.jsx(z,{className:"h-4 w-4"})})]}),e.jsxs("div",{className:"flex flex-wrap gap-1",children:[e.jsxs(k,{variant:f===null?"default":"outline",className:"cursor-pointer",onClick:()=>l(null),children:["All (",i.length,")"]}),Object.keys(H).map(r=>{const h=S[r].length;return h===0?null:e.jsxs(k,{variant:f===r?"default":"outline",className:"cursor-pointer",onClick:()=>l(r),children:[H[r]," (",h,")"]},r)})]}),C&&e.jsxs("div",{className:"bg-muted rounded-md p-2 text-sm",children:[e.jsx("span",{className:"font-medium",children:C.name}),e.jsxs("span",{className:"text-muted-foreground ml-2",children:[Y(C.pricing)," |"," ",xe(C.context_length)]})]}),e.jsx(K,{className:"h-72 w-full rounded-md border",children:g?e.jsxs("div",{className:"text-destructive p-4 text-center",children:["Failed to load models."," ",e.jsx(N,{variant:"link",onClick:E,children:"Retry"})]}):v.length===0?e.jsxs("div",{className:"text-muted-foreground p-4 text-center",children:['No models found matching "',x,'"']}):e.jsxs("div",{className:"space-y-6 p-3",children:[w&&j.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(X,{className:"h-3 w-3 text-accent"}),e.jsx("span",{children:"Newest Models"})]}),e.jsx("div",{className:"space-y-1",children:j.map(r=>e.jsx(ce,{model:r,isSelected:r.id===s,onClick:()=>a(r.id),showAge:!0},r.id))})]}),Object.keys(H).map(r=>{const h=S[r];return h.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:H[r]}),e.jsx("div",{className:"space-y-1",children:h.map(n=>e.jsx(ce,{model:n,isSelected:n.id===s,onClick:()=>a(n.id)},n.id))})]},r)})]})})]})}function ce({model:s,isSelected:a,onClick:t,showAge:d=!1}){return e.jsxs("button",{type:"button",onClick:t,className:_("group flex w-full items-center gap-2 rounded-md px-3 py-2 text-left text-sm transition-colors","hover:bg-accent hover:text-accent-foreground",a&&"bg-accent text-accent-foreground"),children:[e.jsx("span",{className:"flex-1 min-w-0 truncate font-medium",children:s.name}),e.jsxs("span",{className:_("flex shrink-0 items-center gap-1 text-xs whitespace-nowrap",a?"text-accent-foreground/80":"text-muted-foreground group-hover:text-accent-foreground/80"),children:[d&&s.created&&e.jsx(k,{variant:"outline",className:_("text-[10px] px-1",a?"border-accent-foreground/30 text-accent-foreground/80":"text-accent border-accent/30 group-hover:text-accent-foreground/80 group-hover:border-accent-foreground/30"),children:Le(s.created)}),s.isFree?e.jsx(k,{variant:"secondary",className:_("text-[10px] px-1",a?"bg-accent-foreground/20 text-accent-foreground":"group-hover:bg-accent-foreground/20 group-hover:text-accent-foreground"),children:"Free"}):s.isExacto?e.jsxs(e.Fragment,{children:[e.jsx(k,{variant:"outline",className:_("text-[10px] px-1 border-emerald-500/50 text-emerald-600",a?"border-accent-foreground/30 text-accent-foreground/80":"group-hover:border-accent-foreground/30 group-hover:text-accent-foreground/80"),children:"Exacto"}),e.jsx("span",{className:"tabular-nums",children:Y(s.pricing)})]}):e.jsx("span",{className:"tabular-nums",children:Y(s.pricing)}),e.jsx("span",{className:"tabular-nums",children:xe(s.context_length)})]})]})}function gs({selectedModel:s,value:a,onChange:t,className:d}){const{models:x}=de(),m=o.useMemo(()=>s?Ie(s,x):{},[s,x]),f=()=>{t(m)},l=(u,g)=>{t({...a,[u]:g||void 0})},i=s&&Object.keys(m).length>0;return e.jsxs(me,{className:_("group",d),children:[e.jsxs(ue,{className:"flex items-center gap-2 text-sm font-medium hover:underline",children:[e.jsx(ge,{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(he,{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."}),i&&e.jsxs(N,{type:"button",variant:"outline",size:"sm",onClick:f,children:[e.jsx(as,{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(A,{id:"tier-opus",value:a.opus??"",onChange:u=>l("opus",u.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(A,{id:"tier-sonnet",value:a.sonnet??"",onChange:u=>l("sonnet",u.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(A,{id:"tier-haiku",value:a.haiku??"",onChange:u=>l("haiku",u.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 js({profileName:s,target:a,data:t,currentSettings:d,newEnvKey:x,newEnvValue:m,onNewEnvKeyChange:f,onNewEnvValueChange:l,onEnvValueChange:i,onAddEnvVar:u,onEnvBulkChange:g}){const O=we(d),b=d?.env,v=o.useMemo(()=>xs(b??{}),[b]),j=b??{},w=n=>{if(g){const P={...j,ANTHROPIC_MODEL:n,ANTHROPIC_DEFAULT_OPUS_MODEL:n,ANTHROPIC_DEFAULT_SONNET_MODEL:n,ANTHROPIC_DEFAULT_HAIKU_MODEL:n};g(P)}else i("ANTHROPIC_MODEL",n),i("ANTHROPIC_DEFAULT_OPUS_MODEL",n),i("ANTHROPIC_DEFAULT_SONNET_MODEL",n),i("ANTHROPIC_DEFAULT_HAIKU_MODEL",n);I.success("Applied model to all tiers",{duration:2e3})},S=n=>{if(g){const P=ms(j,n);g(P)}else n.opus!==void 0&&i("ANTHROPIC_DEFAULT_OPUS_MODEL",n.opus||""),n.sonnet!==void 0&&i("ANTHROPIC_DEFAULT_SONNET_MODEL",n.sonnet||""),n.haiku!==void 0&&i("ANTHROPIC_DEFAULT_HAIKU_MODEL",n.haiku||"")},[E,C]=o.useState(!1),r=new Set(["ANTHROPIC_AUTH_TOKEN"]),h=Object.entries(j).filter(([n])=>!r.has(n));return e.jsx("div",{className:"h-full w-full min-w-0 flex flex-col",children:e.jsxs(Ue,{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(He,{className:"w-full",children:[e.jsx(ae,{value:"env",className:"flex-1",children:O?"Configuration":"Environment Variables"}),e.jsx(ae,{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(ne,{value:"env",className:"flex-1 mt-0 border-0 p-0 data-[state=inactive]:hidden flex flex-col overflow-hidden min-w-0",children:O?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(ps,{value:j.ANTHROPIC_MODEL,onChange:w,placeholder:"Search OpenRouter models..."})]}),e.jsx(gs,{selectedModel:j.ANTHROPIC_MODEL,value:v,onChange:S}),e.jsxs("div",{className:"space-y-2",children:[e.jsx(T,{className:"text-sm font-medium",children:"API Key"}),e.jsx(Ce,{value:j.ANTHROPIC_AUTH_TOKEN||"",onChange:n=>i("ANTHROPIC_AUTH_TOKEN",n.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"})]})]}),h.length>0&&e.jsxs(me,{open:E,onOpenChange:C,children:[e.jsxs(ue,{className:"flex items-center gap-2 text-sm font-medium text-muted-foreground hover:text-foreground transition-colors group",children:[e.jsx(ge,{className:_("h-4 w-4 transition-transform",E&&"rotate-90")}),e.jsx(ns,{className:"h-4 w-4"}),e.jsx("span",{children:"Additional Variables"}),e.jsxs("span",{className:"text-xs font-normal opacity-70",children:["(",h.length,")"]})]}),e.jsx(he,{className:"pt-4",children:e.jsx("div",{className:"space-y-3 border rounded-lg p-3 bg-muted/30",children:h.map(([n,P])=>e.jsxs("div",{className:"space-y-1",children:[e.jsx(T,{className:"text-xs text-muted-foreground",children:n}),e.jsx(A,{value:P,onChange:M=>i(n,M.target.value),className:"font-mono text-xs h-8"})]},n))})})]})]})}),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(A,{placeholder:"VARIABLE_NAME",value:x,onChange:n=>f(n.target.value.toUpperCase()),className:"font-mono text-sm h-8 w-2/5",onKeyDown:n=>n.key==="Enter"&&x.trim()&&u()}),e.jsx(A,{placeholder:"value",value:m,onChange:n=>l(n.target.value),className:"font-mono text-sm h-8 flex-1",onKeyDown:n=>n.key==="Enter"&&x.trim()&&u()}),e.jsx(N,{variant:"outline",size:"sm",className:"h-8",onClick:u,disabled:!x.trim(),children:e.jsx($,{className:"w-4 h-4"})})]})]})]}):e.jsx(hs,{currentSettings:d,newEnvKey:x,newEnvValue:m,onNewEnvKeyChange:f,onNewEnvValueChange:l,onEnvValueChange:i,onAddEnvVar:u})}),e.jsx(ne,{value:"info",className:"h-full mt-0 border-0 p-0 data-[state=inactive]:hidden",children:e.jsx(fs,{profileName:s,target:a,data:t})})]})]})})}function Ns({profileName:s,profileTarget:a,onDelete:t,onHasChangesUpdate:d}){const[x,m]=o.useState({}),[f,l]=o.useState(!1),[i,u]=o.useState(null),[g,O]=o.useState(""),[b,v]=o.useState(""),j=We(),{data:w,isLoading:S,isError:E,refetch:C}=Xe({queryKey:["settings",s],queryFn:async()=>{const c=await fetch(`/api/settings/${s}/raw`);if(!c.ok)throw new Error(`Failed to load settings: ${c.status}`);return c.json()}}),r=w?.settings,h=o.useMemo(()=>{if(i!==null)try{return JSON.parse(i)}catch{}if(r)return{...r,env:{...r.env,...x}}},[r,x,i]),n=o.useMemo(()=>i!==null?i:r?JSON.stringify(r,null,2):"",[i,r]),P=o.useCallback(c=>{u(c)},[]),M=(c,y)=>{const R={...h?.env||{},[c]:y};m(L=>({...L,[c]:y})),u(JSON.stringify({...h,env:R},null,2))},J=c=>{const y={...h?.env||{},...c};m(R=>({...R,...c})),u(JSON.stringify({...h,env:y},null,2))},p=()=>{if(!g.trim())return;const c=g.trim(),y=b,R={...h?.env||{},[c]:y};m(L=>({...L,[c]:y})),u(JSON.stringify({...h,env:R},null,2)),O(""),v("")},Z=o.useMemo(()=>{try{return JSON.parse(n),!0}catch{return!1}},[n]),B=o.useMemo(()=>i!==null?i!==JSON.stringify(r,null,2):Object.keys(x).length>0,[i,x,r]),ye=o.useMemo(()=>{const c=["ANTHROPIC_BASE_URL","ANTHROPIC_AUTH_TOKEN"],y=h?.env||{};return c.filter(R=>!y[R]?.trim())},[h]);o.useEffect(()=>{d?.(B)},[B,d]);const U=re({mutationFn:async()=>{let c;try{c=JSON.parse(n)}catch{c={...w?.settings,env:{...w?.settings?.env,...x}}}const y=await fetch(`/api/settings/${s}`,{method:"PUT",headers:{"Content-Type":"application/json"},body:JSON.stringify({settings:c,expectedMtime:w?.mtime})});if(y.status===409)throw new Error("CONFLICT");if(!y.ok)throw new Error("Failed to save");return y.json()},onSuccess:()=>{j.invalidateQueries({queryKey:["settings",s]}),j.invalidateQueries({queryKey:["profiles"]}),m({}),u(null),I.success("Settings saved")},onError:c=>{c.message==="CONFLICT"?l(!0):I.error(c.message)}}),Q=re({mutationFn:async c=>(await $e.profiles.update(s,{target:c}),c),onSuccess:()=>{j.invalidateQueries({queryKey:["profiles"]}),I.success("Default target updated")},onError:(c,y)=>{const R=y==="droid"?"Factory Droid":"Claude Code",L=c.message.trim()?`: ${c.message}`:"";I.error(`Failed to update default target to ${R}${L}`)}}),q=a||"claude",V=U.isPending||Q.isPending,ee=async c=>{l(!1),c?(await C(),U.mutate()):(m({}),u(null))};return e.jsxs("div",{className:"flex-1 flex flex-col overflow-hidden",children:[e.jsx(us,{profileName:s,target:q,data:w,settings:h,isLoading:S,isSaving:U.isPending,isTargetSaving:Q.isPending,hasChanges:B,isRawJsonValid:Z,onTargetChange:c=>{V||c!==q&&Q.mutate(c)},onRefresh:()=>{V||C()},onDelete:t,onSave:()=>{V||U.mutate()}}),S?e.jsxs("div",{className:"flex-1 flex items-center justify-center",children:[e.jsx(F,{className:"w-8 h-8 animate-spin text-muted-foreground"}),e.jsx("span",{className:"ml-3 text-muted-foreground",children:"Loading settings..."})]}):E?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(N,{variant:"outline",size:"sm",onClick:()=>C(),children:[e.jsx(z,{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(js,{profileName:s,target:q,data:w,currentSettings:h,newEnvKey:g,newEnvValue:b,onNewEnvKeyChange:O,onNewEnvValueChange:v,onEnvValueChange:M,onEnvBulkChange:J,onAddEnvVar:p})}),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(rs,{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(Fe,{rawJsonContent:n,isRawJsonValid:Z,rawJsonEdits:i,settings:r,onChange:P,missingRequiredFields:ye})]})]}),e.jsx(G,{open:f,title:"File Modified Externally",description:"Overwrite with your changes or discard?",confirmText:"Overwrite",variant:"destructive",onConfirm:()=>ee(!0),onCancel:()=>ee(!1)})]},s)}const oe="ccs:openrouter-banner-dismissed";function vs({onCreateClick:s}){const[a,t]=o.useState(!0),{modelCount:d,isLoading:x}=W();o.useEffect(()=>{const f=localStorage.getItem(oe)==="true";t(f)},[]);const m=()=>{localStorage.setItem(oe,"true"),t(!0)};return a?null:e.jsx("div",{className:"bg-gradient-to-r from-accent to-accent/90 text-white px-4 py-3 relative shrink-0",children:e.jsxs("div",{className:"flex items-center justify-between gap-4 max-w-screen-xl mx-auto",children:[e.jsxs("div",{className:"flex items-center gap-3 flex-1 min-w-0",children:[e.jsx("div",{className:"p-1.5 bg-white/20 rounded-md shrink-0",children:e.jsx(X,{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 ",x?"300+":`${d}+`," models from OpenAI, Anthropic, Google, Meta and more."]})]})]}),e.jsxs("div",{className:"flex items-center gap-2 shrink-0",children:[s&&e.jsx(N,{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(je,{className:"w-3 h-3"})]}),e.jsxs(N,{size:"icon",variant:"ghost",onClick:m,className:"h-7 w-7 text-white/70 hover:text-white hover:bg-white/20",children:[e.jsx(is,{className:"w-4 h-4"}),e.jsx("span",{className:"sr-only",children:"Dismiss"})]})]})]})})}function bs({onOpenRouterClick:s,onCustomClick:a}){const{modelCount:t,isLoading:d}=W();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(Ke,{className:"border-accent/30 dark:border-accent/40 bg-gradient-to-br from-accent/5 to-background dark:from-accent/10",children:[e.jsxs(ze,{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(k,{variant:"secondary",className:"bg-accent/10 text-accent dark:bg-accent/20 dark:text-accent-foreground",children:"Recommended"})]}),e.jsx(Je,{className:"text-xl",children:"Start with OpenRouter"}),e.jsxs(Be,{className:"text-base",children:["Access ",d?"300+":`${t}+`," models from OpenAI, Anthropic, Google, Meta and more - all through one API."]})]}),e.jsxs(Qe,{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(Ne,{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(X,{className:"w-4 h-4 text-accent"}),e.jsx("span",{children:"Model tier mapping"})]})]}),e.jsxs(N,{onClick:s,className:"w-full bg-accent hover:bg-accent/90 text-white",size:"lg",children:["Create OpenRouter Profile",e.jsx(ls,{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(je,{className:"w-3 h-3"})]})]})]})]}),e.jsxs("div",{className:"flex items-center gap-4",children:[e.jsx(ie,{className:"flex-1"}),e.jsx("span",{className:"text-xs text-muted-foreground",children:"or"}),e.jsx(ie,{className:"flex-1"})]}),e.jsx(N,{variant:"outline",onClick:a,className:"w-full",children:"Create Custom API Profile"})]})})}function ws({onCreateClick:s}){const{modelCount:a,isLoading:t}=W();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:[t?"300+":`${a}+`," models available"]})]}),e.jsxs(N,{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(Ne,{className:"w-3 h-3 mr-1"}),e.jsx("span",{className:"text-xs",children:"Add"})]})]})})}function Ls(){const{data:s,isLoading:a,isError:t,refetch:d}=qe(),x=Ve(),[m,f]=o.useState(null),[l,i]=o.useState(""),[u,g]=o.useState(!1),[O,b]=o.useState("normal"),[v,j]=o.useState(null),[w,S]=o.useState(!1),[E,C]=o.useState(null);Ye();const r=o.useMemo(()=>s?.profiles||[],[s?.profiles]),h=o.useMemo(()=>r.filter(p=>p.name.toLowerCase().includes(l.toLowerCase())),[r,l]),n=m?r.find(p=>p.name===m):null,P=p=>{x.mutate(p,{onSuccess:()=>{m===p&&f(null),j(null)}})},M=p=>{g(!1),w&&m!==null?C(p):f(p)},J=p=>{w&&m!==p?C(p):f(p)};return e.jsxs("div",{className:"h-[calc(100vh-100px)] flex flex-col",children:[e.jsx(vs,{onCreateClick:()=>g(!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(cs,{className:"w-5 h-5 text-primary"}),e.jsx("h1",{className:"font-semibold",children:"API Profiles"})]}),e.jsxs(N,{size:"sm",onClick:()=>{g(!0)},children:[e.jsx($,{className:"w-4 h-4 mr-1"}),"New"]})]}),e.jsxs("div",{className:"relative",children:[e.jsx(pe,{className:"absolute left-2.5 top-2.5 h-4 w-4 text-muted-foreground"}),e.jsx(A,{placeholder:"Search profiles...",className:"pl-8 h-9",value:l,onChange:p=>i(p.target.value)})]})]}),e.jsx(K,{className:"flex-1",children:a?e.jsx("div",{className:"p-4 text-sm text-muted-foreground",children:"Loading profiles..."}):t?e.jsx("div",{className:"p-4 text-center",children:e.jsxs("div",{className:"space-y-3 py-8",children:[e.jsx(ve,{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(N,{size:"sm",variant:"outline",onClick:()=>d(),children:[e.jsx(z,{className:"w-4 h-4 mr-1"}),"Retry"]})]})}):h.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(os,{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(N,{size:"sm",variant:"outline",onClick:()=>{g(!0)},children:[e.jsx($,{className:"w-4 h-4 mr-1"}),"Create Profile"]})]}):e.jsxs("p",{className:"text-sm text-muted-foreground py-4",children:['No profiles match "',l,'"']})}):e.jsx("div",{className:"p-2 space-y-1",children:h.map(p=>e.jsx(Cs,{profile:p,isSelected:m===p.name,onSelect:()=>J(p.name),onDelete:()=>j(p.name)},p.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(be,{className:"w-3 h-3 text-green-600"}),r.filter(p=>p.configured).length," configured"]})]})}),e.jsx(ws,{onCreateClick:()=>{b("openrouter"),g(!0)}})]}),e.jsx("div",{className:"flex-1 flex flex-col min-w-0",children:n?e.jsx(Ns,{profileName:n.name,profileTarget:n.target,onDelete:()=>j(n.name),onHasChangesUpdate:S},n.name):e.jsx(bs,{onOpenRouterClick:()=>{b("openrouter"),g(!0)},onCustomClick:()=>{b("normal"),g(!0)}})})]}),e.jsx(Ge,{open:u,onOpenChange:g,onSuccess:M,initialMode:O}),e.jsx(G,{open:!!v,title:"Delete Profile",description:`Are you sure you want to delete "${v}"? This will remove the settings file and cannot be undone.`,confirmText:"Delete",variant:"destructive",onConfirm:()=>v&&P(v),onCancel:()=>j(null)}),e.jsx(G,{open:!!E,title:"Unsaved Changes",description:`You have unsaved changes in "${m}". Discard and switch to "${E}"?`,confirmText:"Discard & Switch",variant:"destructive",onConfirm:()=>{S(!1),f(E),C(null)},onCancel:()=>C(null)})]})}function Cs({profile:s,isSelected:a,onSelect:t,onDelete:d}){return e.jsxs("div",{className:_("group flex items-center gap-2 px-3 py-2.5 rounded-md cursor-pointer transition-colors",a?"bg-primary/10 border border-primary/20":"hover:bg-muted border border-transparent"),onClick:t,children:[s.configured?e.jsx(be,{className:"w-4 h-4 text-green-600 shrink-0"}):e.jsx(ve,{className:"w-4 h-4 text-yellow-600 shrink-0"}),e.jsxs("div",{className:"flex-1 min-w-0",children:[e.jsxs("div",{className:"flex items-center gap-2 min-w-0",children:[e.jsx("div",{className:"font-medium text-sm truncate",children:s.name}),e.jsx(k,{variant:"outline",className:"text-[10px] h-4 px-1.5 uppercase",children:s.target||"claude"})]}),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(D,{value:s.settingsPath,size:"icon",className:"h-5 w-5 opacity-0 group-hover:opacity-100 transition-opacity"})]})]}),e.jsx(N,{variant:"ghost",size:"icon",className:"h-7 w-7 opacity-0 group-hover:opacity-100 transition-opacity",onClick:x=>{x.stopPropagation(),d()},children:e.jsx(fe,{className:"w-3.5 h-3.5 text-destructive"})})]})}export{Ls as ApiPage};
@@ -1 +1 @@
1
- import{j as e}from"./radix-ui-DIWAxjEp.js";import{r as t}from"./react-vendor-CNOkPC89.js";import{bb as Q,b2 as V,b4 as W,m as X,I as S,b as i}from"./index-BOyrh__4.js";import{R as A,a2 as Y,r as Z,l as _,E,e as K,k as T,m as P,az as ee,a1 as se,w as ae,ai as te}from"./icons-D7XDTBCN.js";import"./tanstack-Hn82hibe.js";import"./notifications-B2HqRBj7.js";import"./utils-CzKF5WmX.js";import"./form-utils-Cn_Uld6y.js";import"./code-highlight-BRUf_pqB.js";function he(){const{fetchRawConfig:o}=Q(),[a,I]=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),[w,z]=t.useState(!1),[m,j]=t.useState(null),[d,N]=t.useState(null),[L,b]=t.useState(!1),[U,C]=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();I(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=m!==null&&m!==a?.apiKey.value,l=d!==null&&d!==a?.managementSecret.value;if(!(!s&&!l))try{c(!0),r(null);const h={};s&&(h.apiKey=m),l&&(h.managementSecret=d);const k=await fetch("/api/settings/auth/tokens",{method:"PUT",headers:{"Content-Type":"application/json"},body:JSON.stringify(h)});if(!k.ok){const H=await k.json();throw new Error(H.error||"Failed to save tokens")}f("Tokens updated. Restart CLIProxy to apply."),j(null),N(null),await u(),await o()}catch(h){r(h instanceof Error?h.message:"Unknown error")}finally{c(!1)}},O=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)}},D=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."),j(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),b(!0),setTimeout(()=>b(!1),2e3))},M=async()=>{a&&(await navigator.clipboard.writeText(a.managementSecret.value),C(!0),setTimeout(()=>C(!1),2e3))},q=async()=>{g||n||(r(null),f(null),await Promise.all([u(),o()]))};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(A,{className:"w-5 h-5 animate-spin"}),e.jsx("span",{children:"Loading..."})]})});const B=m??a.apiKey.value,G=d??a.managementSecret.value,J=m!==null&&m!==a.apiKey.value||d!==null&&d!==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(Y,{className:"h-4 w-4"}),e.jsx(W,{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(Z,{className:"h-4 w-4 shrink-0"}),e.jsx("span",{className:"text-sm font-medium",children:p})]})]}),e.jsx(X,{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(_,{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(S,{type:y?"text":"password",value:B,onChange:s=>j(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(E,{className:"w-4 h-4"}):e.jsx(K,{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(P,{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(ee,{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(S,{type:w?"text":"password",value:G,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(!w),children:w?e.jsx(E,{className:"w-4 h-4"}):e.jsx(K,{className:"w-4 h-4"})}),e.jsx(i,{variant:"ghost",size:"sm",className:"h-7 w-7 p-0",onClick:M,disabled:!a.managementSecret.value,children:U?e.jsx(T,{className:"w-4 h-4 text-green-600"}):e.jsx(P,{className:"w-4 h-4"})})]})]}),e.jsx(i,{variant:"outline",size:"sm",onClick:O,disabled:n,title:"Generate new secure secret",children:e.jsx(se,{className:"w-4 h-4"})})]})]}),e.jsxs("div",{className:"pt-4 border-t",children:[e.jsxs(i,{variant:"outline",size:"sm",onClick:D,disabled:n||!a.apiKey.isCustom&&!a.managementSecret.isCustom,className:"gap-2",children:[e.jsx(ae,{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:q,disabled:g||n,className:"flex-1",children:[e.jsx(A,{className:`w-4 h-4 mr-2 ${g?"animate-spin":""}`}),"Refresh"]}),e.jsxs(i,{variant:"default",size:"sm",onClick:F,disabled:!J||n,className:"flex-1",children:[e.jsx(te,{className:`w-4 h-4 mr-2 ${n?"animate-pulse":""}`}),n?"Saving...":"Save"]})]})]})}export{he as default};
1
+ import{j as e}from"./radix-ui-DIWAxjEp.js";import{r as t}from"./react-vendor-CNOkPC89.js";import{bb as Q,b2 as V,b4 as W,m as X,I as S,b as i}from"./index-BtROiILs.js";import{R as A,a2 as Y,r as Z,l as _,E,e as K,k as T,m as P,az as ee,a1 as se,w as ae,ai as te}from"./icons-D7XDTBCN.js";import"./tanstack-Hn82hibe.js";import"./notifications-B2HqRBj7.js";import"./utils-CzKF5WmX.js";import"./form-utils-Cn_Uld6y.js";import"./code-highlight-BRUf_pqB.js";function he(){const{fetchRawConfig:o}=Q(),[a,I]=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),[w,z]=t.useState(!1),[m,j]=t.useState(null),[d,N]=t.useState(null),[L,b]=t.useState(!1),[U,C]=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();I(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=m!==null&&m!==a?.apiKey.value,l=d!==null&&d!==a?.managementSecret.value;if(!(!s&&!l))try{c(!0),r(null);const h={};s&&(h.apiKey=m),l&&(h.managementSecret=d);const k=await fetch("/api/settings/auth/tokens",{method:"PUT",headers:{"Content-Type":"application/json"},body:JSON.stringify(h)});if(!k.ok){const H=await k.json();throw new Error(H.error||"Failed to save tokens")}f("Tokens updated. Restart CLIProxy to apply."),j(null),N(null),await u(),await o()}catch(h){r(h instanceof Error?h.message:"Unknown error")}finally{c(!1)}},O=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)}},D=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."),j(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),b(!0),setTimeout(()=>b(!1),2e3))},M=async()=>{a&&(await navigator.clipboard.writeText(a.managementSecret.value),C(!0),setTimeout(()=>C(!1),2e3))},q=async()=>{g||n||(r(null),f(null),await Promise.all([u(),o()]))};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(A,{className:"w-5 h-5 animate-spin"}),e.jsx("span",{children:"Loading..."})]})});const B=m??a.apiKey.value,G=d??a.managementSecret.value,J=m!==null&&m!==a.apiKey.value||d!==null&&d!==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(Y,{className:"h-4 w-4"}),e.jsx(W,{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(Z,{className:"h-4 w-4 shrink-0"}),e.jsx("span",{className:"text-sm font-medium",children:p})]})]}),e.jsx(X,{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(_,{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(S,{type:y?"text":"password",value:B,onChange:s=>j(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(E,{className:"w-4 h-4"}):e.jsx(K,{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(P,{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(ee,{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(S,{type:w?"text":"password",value:G,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(!w),children:w?e.jsx(E,{className:"w-4 h-4"}):e.jsx(K,{className:"w-4 h-4"})}),e.jsx(i,{variant:"ghost",size:"sm",className:"h-7 w-7 p-0",onClick:M,disabled:!a.managementSecret.value,children:U?e.jsx(T,{className:"w-4 h-4 text-green-600"}):e.jsx(P,{className:"w-4 h-4"})})]})]}),e.jsx(i,{variant:"outline",size:"sm",onClick:O,disabled:n,title:"Generate new secure secret",children:e.jsx(se,{className:"w-4 h-4"})})]})]}),e.jsxs("div",{className:"pt-4 border-t",children:[e.jsxs(i,{variant:"outline",size:"sm",onClick:D,disabled:n||!a.apiKey.isCustom&&!a.managementSecret.isCustom,className:"gap-2",children:[e.jsx(ae,{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:q,disabled:g||n,className:"flex-1",children:[e.jsx(A,{className:`w-4 h-4 mr-2 ${g?"animate-spin":""}`}),"Refresh"]}),e.jsxs(i,{variant:"default",size:"sm",onClick:F,disabled:!J||n,className:"flex-1",children:[e.jsx(te,{className:`w-4 h-4 mr-2 ${n?"animate-pulse":""}`}),n?"Saving...":"Save"]})]})]})}export{he as default};
@@ -1 +1 @@
1
- import{j as e}from"./radix-ui-DIWAxjEp.js";import{r as t}from"./react-vendor-CNOkPC89.js";import{bb as R,m as w,S as a,C as f,b2 as S,b4 as E,B as D,b as y}from"./index-BOyrh__4.js";import{A as B,a as T,b as O,c as _,d as F,e as U,f as I,g as L}from"./alert-dialog-Cbz7hjbH.js";import{a2 as z,r as P,a6 as k,q as $,w as M,R as Y}from"./icons-D7XDTBCN.js";import"./tanstack-Hn82hibe.js";import"./notifications-B2HqRBj7.js";import"./utils-CzKF5WmX.js";import"./form-utils-Cn_Uld6y.js";import"./code-highlight-BRUf_pqB.js";const q=3e3,H=5e3;function te(){const{fetchRawConfig:x}=R(),c=t.useRef(null),m=t.useRef(null),[j,v]=t.useState([]),[h,g]=t.useState(!0),[d,N]=t.useState(null),[n,l]=t.useState(null),[i,b]=t.useState(null),[u,p]=t.useState(null),o=t.useCallback(async()=>{c.current?.abort(),c.current=new AbortController;try{g(!0),l(null);const s=await fetch("/api/persist/backups",{signal:c.current.signal});if(!s.ok)throw new Error("Failed to fetch backups");const r=await s.json();v(r.backups||[])}catch(s){if(s instanceof Error&&s.name==="AbortError")return;l(s instanceof Error?s.message:"Unknown error")}finally{g(!1)}},[]),C=t.useCallback(async s=>{m.current?.abort(),m.current=new AbortController;try{N(s),l(null);const r=await fetch("/api/persist/restore",{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify({timestamp:s}),signal:m.current.signal});if(!r.ok){const A=await r.json();throw new Error(A.error||"Failed to restore backup")}b("Backup restored successfully"),await o(),await x()}catch(r){if(r instanceof Error&&r.name==="AbortError")return;l(r instanceof Error?r.message:"Unknown error")}finally{N(null)}},[o,x]);return t.useEffect(()=>{o()},[o]),t.useEffect(()=>()=>{c.current?.abort(),m.current?.abort()},[]),t.useEffect(()=>{if(i){const s=setTimeout(()=>b(null),q);return()=>clearTimeout(s)}},[i]),t.useEffect(()=>{if(n){const s=setTimeout(()=>l(null),H);return()=>clearTimeout(s)}},[n]),h?e.jsxs(e.Fragment,{children:[e.jsx(w,{className:"flex-1",children:e.jsxs("div",{className:"p-5 space-y-4",children:[e.jsxs("div",{className:"space-y-2",children:[e.jsx(a,{className:"h-6 w-40"}),e.jsx(a,{className:"h-4 w-full"})]}),[1,2,3].map(s=>e.jsx(f,{className:"p-4",children:e.jsxs("div",{className:"flex items-center justify-between",children:[e.jsxs("div",{className:"space-y-2 flex-1",children:[e.jsx(a,{className:"h-4 w-32"}),e.jsx(a,{className:"h-3 w-48"})]}),e.jsx(a,{className:"h-8 w-20"})]})},s))]})}),e.jsx("div",{className:"p-4 border-t bg-background",children:e.jsx(a,{className:"h-9 w-full"})})]}):e.jsxs(e.Fragment,{children:[e.jsxs("div",{className:`absolute left-5 right-5 top-20 z-10 transition-all duration-200 ease-out ${n||i?"opacity-100 translate-y-0":"opacity-0 -translate-y-2 pointer-events-none"}`,children:[n&&e.jsxs(S,{variant:"destructive",className:"py-2 shadow-lg",children:[e.jsx(z,{className:"h-4 w-4"}),e.jsx(E,{children:n})]}),i&&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(P,{className:"h-4 w-4 shrink-0"}),e.jsx("span",{className:"text-sm font-medium",children:i})]})]}),e.jsx(w,{className:"flex-1",children:e.jsxs("div",{className:"p-5 space-y-4",children:[e.jsxs("div",{children:[e.jsxs("div",{className:"flex items-center gap-2 mb-2",children:[e.jsx(k,{className:"w-5 h-5 text-primary"}),e.jsx("h2",{className:"text-lg font-semibold",children:"Settings Backups"})]}),e.jsx("p",{className:"text-sm text-muted-foreground",children:"Restore previous versions of your settings.json file. Backups are created automatically when settings are modified."})]}),j.length===0?e.jsx(f,{className:"p-8",children:e.jsxs("div",{className:"text-center",children:[e.jsx(k,{className:"w-12 h-12 mx-auto mb-3 opacity-30 text-muted-foreground"}),e.jsx("p",{className:"text-sm text-muted-foreground",children:"No backups available"}),e.jsx("p",{className:"text-xs text-muted-foreground mt-1",children:"Backups will appear here when you modify settings"})]})}):e.jsx("div",{className:"space-y-2",children:j.map((s,r)=>e.jsx(f,{className:"p-4 hover:bg-muted/50 transition-colors",children:e.jsxs("div",{className:"flex items-center justify-between gap-4",children:[e.jsxs("div",{className:"flex items-start gap-3 flex-1 min-w-0",children:[e.jsx($,{className:"w-4 h-4 text-muted-foreground mt-0.5 shrink-0"}),e.jsxs("div",{className:"min-w-0 flex-1",children:[e.jsxs("div",{className:"flex items-center gap-2 mb-1",children:[e.jsx("p",{className:"text-sm font-medium font-mono",children:s.timestamp}),r===0&&e.jsx(D,{variant:"secondary",className:"text-xs",children:"Latest"})]}),e.jsx("p",{className:"text-xs text-muted-foreground",children:s.date})]})]}),e.jsxs(y,{variant:"outline",size:"sm",onClick:()=>p(s.timestamp),disabled:d!==null,className:"gap-2 shrink-0",children:[e.jsx(M,{className:`w-4 h-4 ${d===s.timestamp?"animate-spin":""}`}),d===s.timestamp?"Restoring...":"Restore"]})]})},s.timestamp))})]})}),e.jsx("div",{className:"p-4 border-t bg-background",children:e.jsxs(y,{variant:"outline",size:"sm",onClick:()=>{o(),x()},disabled:h||d!==null,className:"w-full",children:[e.jsx(Y,{className:`w-4 h-4 mr-2 ${h?"animate-spin":""}`}),"Refresh"]})}),e.jsx(B,{open:!!u,onOpenChange:()=>p(null),children:e.jsxs(T,{children:[e.jsxs(O,{children:[e.jsx(_,{children:"Restore Backup?"}),e.jsxs(F,{children:["This will replace your current settings with backup from"," ",e.jsx("code",{className:"font-mono bg-muted px-1.5 py-0.5 rounded text-foreground",children:u}),". This action cannot be undone."]})]}),e.jsxs(U,{children:[e.jsx(I,{children:"Cancel"}),e.jsx(L,{onClick:()=>{u&&C(u),p(null)},children:"Restore"})]})]})})]})}export{te as default};
1
+ import{j as e}from"./radix-ui-DIWAxjEp.js";import{r as t}from"./react-vendor-CNOkPC89.js";import{bb as R,m as w,S as a,C as f,b2 as S,b4 as E,B as D,b as y}from"./index-BtROiILs.js";import{A as B,a as T,b as O,c as _,d as F,e as U,f as I,g as L}from"./alert-dialog-DYqj_ln8.js";import{a2 as z,r as P,a6 as k,q as $,w as M,R as Y}from"./icons-D7XDTBCN.js";import"./tanstack-Hn82hibe.js";import"./notifications-B2HqRBj7.js";import"./utils-CzKF5WmX.js";import"./form-utils-Cn_Uld6y.js";import"./code-highlight-BRUf_pqB.js";const q=3e3,H=5e3;function te(){const{fetchRawConfig:x}=R(),c=t.useRef(null),m=t.useRef(null),[j,v]=t.useState([]),[h,g]=t.useState(!0),[d,N]=t.useState(null),[n,l]=t.useState(null),[i,b]=t.useState(null),[u,p]=t.useState(null),o=t.useCallback(async()=>{c.current?.abort(),c.current=new AbortController;try{g(!0),l(null);const s=await fetch("/api/persist/backups",{signal:c.current.signal});if(!s.ok)throw new Error("Failed to fetch backups");const r=await s.json();v(r.backups||[])}catch(s){if(s instanceof Error&&s.name==="AbortError")return;l(s instanceof Error?s.message:"Unknown error")}finally{g(!1)}},[]),C=t.useCallback(async s=>{m.current?.abort(),m.current=new AbortController;try{N(s),l(null);const r=await fetch("/api/persist/restore",{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify({timestamp:s}),signal:m.current.signal});if(!r.ok){const A=await r.json();throw new Error(A.error||"Failed to restore backup")}b("Backup restored successfully"),await o(),await x()}catch(r){if(r instanceof Error&&r.name==="AbortError")return;l(r instanceof Error?r.message:"Unknown error")}finally{N(null)}},[o,x]);return t.useEffect(()=>{o()},[o]),t.useEffect(()=>()=>{c.current?.abort(),m.current?.abort()},[]),t.useEffect(()=>{if(i){const s=setTimeout(()=>b(null),q);return()=>clearTimeout(s)}},[i]),t.useEffect(()=>{if(n){const s=setTimeout(()=>l(null),H);return()=>clearTimeout(s)}},[n]),h?e.jsxs(e.Fragment,{children:[e.jsx(w,{className:"flex-1",children:e.jsxs("div",{className:"p-5 space-y-4",children:[e.jsxs("div",{className:"space-y-2",children:[e.jsx(a,{className:"h-6 w-40"}),e.jsx(a,{className:"h-4 w-full"})]}),[1,2,3].map(s=>e.jsx(f,{className:"p-4",children:e.jsxs("div",{className:"flex items-center justify-between",children:[e.jsxs("div",{className:"space-y-2 flex-1",children:[e.jsx(a,{className:"h-4 w-32"}),e.jsx(a,{className:"h-3 w-48"})]}),e.jsx(a,{className:"h-8 w-20"})]})},s))]})}),e.jsx("div",{className:"p-4 border-t bg-background",children:e.jsx(a,{className:"h-9 w-full"})})]}):e.jsxs(e.Fragment,{children:[e.jsxs("div",{className:`absolute left-5 right-5 top-20 z-10 transition-all duration-200 ease-out ${n||i?"opacity-100 translate-y-0":"opacity-0 -translate-y-2 pointer-events-none"}`,children:[n&&e.jsxs(S,{variant:"destructive",className:"py-2 shadow-lg",children:[e.jsx(z,{className:"h-4 w-4"}),e.jsx(E,{children:n})]}),i&&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(P,{className:"h-4 w-4 shrink-0"}),e.jsx("span",{className:"text-sm font-medium",children:i})]})]}),e.jsx(w,{className:"flex-1",children:e.jsxs("div",{className:"p-5 space-y-4",children:[e.jsxs("div",{children:[e.jsxs("div",{className:"flex items-center gap-2 mb-2",children:[e.jsx(k,{className:"w-5 h-5 text-primary"}),e.jsx("h2",{className:"text-lg font-semibold",children:"Settings Backups"})]}),e.jsx("p",{className:"text-sm text-muted-foreground",children:"Restore previous versions of your settings.json file. Backups are created automatically when settings are modified."})]}),j.length===0?e.jsx(f,{className:"p-8",children:e.jsxs("div",{className:"text-center",children:[e.jsx(k,{className:"w-12 h-12 mx-auto mb-3 opacity-30 text-muted-foreground"}),e.jsx("p",{className:"text-sm text-muted-foreground",children:"No backups available"}),e.jsx("p",{className:"text-xs text-muted-foreground mt-1",children:"Backups will appear here when you modify settings"})]})}):e.jsx("div",{className:"space-y-2",children:j.map((s,r)=>e.jsx(f,{className:"p-4 hover:bg-muted/50 transition-colors",children:e.jsxs("div",{className:"flex items-center justify-between gap-4",children:[e.jsxs("div",{className:"flex items-start gap-3 flex-1 min-w-0",children:[e.jsx($,{className:"w-4 h-4 text-muted-foreground mt-0.5 shrink-0"}),e.jsxs("div",{className:"min-w-0 flex-1",children:[e.jsxs("div",{className:"flex items-center gap-2 mb-1",children:[e.jsx("p",{className:"text-sm font-medium font-mono",children:s.timestamp}),r===0&&e.jsx(D,{variant:"secondary",className:"text-xs",children:"Latest"})]}),e.jsx("p",{className:"text-xs text-muted-foreground",children:s.date})]})]}),e.jsxs(y,{variant:"outline",size:"sm",onClick:()=>p(s.timestamp),disabled:d!==null,className:"gap-2 shrink-0",children:[e.jsx(M,{className:`w-4 h-4 ${d===s.timestamp?"animate-spin":""}`}),d===s.timestamp?"Restoring...":"Restore"]})]})},s.timestamp))})]})}),e.jsx("div",{className:"p-4 border-t bg-background",children:e.jsxs(y,{variant:"outline",size:"sm",onClick:()=>{o(),x()},disabled:h||d!==null,className:"w-full",children:[e.jsx(Y,{className:`w-4 h-4 mr-2 ${h?"animate-spin":""}`}),"Refresh"]})}),e.jsx(B,{open:!!u,onOpenChange:()=>p(null),children:e.jsxs(T,{children:[e.jsxs(O,{children:[e.jsx(_,{children:"Restore Backup?"}),e.jsxs(F,{children:["This will replace your current settings with backup from"," ",e.jsx("code",{className:"font-mono bg-muted px-1.5 py-0.5 rounded text-foreground",children:u}),". This action cannot be undone."]})]}),e.jsxs(U,{children:[e.jsx(I,{children:"Cancel"}),e.jsx(L,{onClick:()=>{u&&C(u),p(null)},children:"Restore"})]})]})})]})}export{te as default};
@@ -1 +1 @@
1
- import{j as r,a0 as i,a1 as t}from"./radix-ui-DIWAxjEp.js";import"./react-vendor-CNOkPC89.js";import{c as s}from"./index-BOyrh__4.js";import{k as o}from"./icons-D7XDTBCN.js";function b({className:e,...a}){return r.jsx(i,{"data-slot":"checkbox",className:s("peer border-input dark:bg-input/30 data-[state=checked]:bg-primary data-[state=checked]:text-primary-foreground dark:data-[state=checked]:bg-primary data-[state=checked]:border-primary focus-visible:border-ring focus-visible:ring-ring/50 aria-invalid:ring-destructive/20 dark:aria-invalid:ring-destructive/40 aria-invalid:border-destructive size-4 shrink-0 rounded-[4px] border shadow-xs transition-shadow outline-none focus-visible:ring-[3px] disabled:cursor-not-allowed disabled:opacity-50",e),...a,children:r.jsx(t,{"data-slot":"checkbox-indicator",className:"grid place-content-center text-current transition-none",children:r.jsx(o,{className:"size-3.5"})})})}export{b as C};
1
+ import{j as r,a0 as i,a1 as t}from"./radix-ui-DIWAxjEp.js";import"./react-vendor-CNOkPC89.js";import{c as s}from"./index-BtROiILs.js";import{k as o}from"./icons-D7XDTBCN.js";function b({className:e,...a}){return r.jsx(i,{"data-slot":"checkbox",className:s("peer border-input dark:bg-input/30 data-[state=checked]:bg-primary data-[state=checked]:text-primary-foreground dark:data-[state=checked]:bg-primary data-[state=checked]:border-primary focus-visible:border-ring focus-visible:ring-ring/50 aria-invalid:ring-destructive/20 dark:aria-invalid:ring-destructive/40 aria-invalid:border-destructive size-4 shrink-0 rounded-[4px] border shadow-xs transition-shadow outline-none focus-visible:ring-[3px] disabled:cursor-not-allowed disabled:opacity-50",e),...a,children:r.jsx(t,{"data-slot":"checkbox-indicator",className:"grid place-content-center text-current transition-none",children:r.jsx(o,{className:"size-3.5"})})})}export{b as C};
@@ -0,0 +1,3 @@
1
+ import{j as e}from"./radix-ui-DIWAxjEp.js";import{r}from"./react-vendor-CNOkPC89.js";import{a as Le,u as js,b as Bs}from"./tanstack-Hn82hibe.js";import{b as R,C as vs,a as Ns,c as H,P as ye,L as W,I as re,q as Ie,r as Fe,s as Ue,t as Ke,v as he,a1 as bs,a2 as Gs,a3 as $s,a4 as Qs,u as ws,a5 as qe,a6 as He,a7 as Be,a8 as Ge,a9 as ys,aa as as,ab as Vs,ac as zs,ad as Js,ae as ks,W as Ne,B as U,af as Re,ag as ns,ah as Ws,ai as Ys,aj as Xs,ak as Zs,al as is,am as rs,an as et,w as Cs,m as $e,ao as st,ap as tt,aq as at,l as nt,ar as it,as as rt,at as ot,au as lt,av as ct,aw as dt,ax as oe,T as le,o as ce,p as de,ay as ut,az as mt,aA as xt,aB as os,aC as pt,aD as ht,aE as gt,aF as ft,aG as jt,aH as vt,aI as Nt,O as bt,Q as wt,R as ls,U as cs,aJ as yt,aK as kt,aL as Ct,aM as At,aN as St,aO as Pt,aP as Mt,aQ as Tt,aR as Ot,aS as Rt,aT as Et,S as _t}from"./index-BtROiILs.js";import{C as Ee}from"./default-ports-1QQSffYX.js";import{t as K}from"./notifications-B2HqRBj7.js";import{c as As,L as J,n as me,z as Dt,k as se,m as Ss,ao as Qe,R as Ve,o as xe,a1 as fe,T as ze,$ as Lt,ap as Ps,aq as It,ar as ke,Z as je,I as Ms,g as Ft,a3 as Ts,as as Ut,ai as Kt,X as Je,a0 as Os,t as Rs,u as _e,at as qt,q as ds,au as Ht,ah as Es,r as Bt,av as us,l as Gt,a2 as $t,al as Qt,aw as _s}from"./icons-D7XDTBCN.js";import{R as be,A as ms,D as Pe,i as Vt,a as zt,P as Jt}from"./proxy-status-widget-BxkoV1g7.js";import{C as we}from"./checkbox-C2wWJ45q.js";import{C as Wt}from"./confirm-dialog-CQGjNqDg.js";import{S as We}from"./separator-lXjk7_Ls.js";import{S as Ds}from"./switch-lf-m6i0R.js";import"./utils-CzKF5WmX.js";import"./form-utils-Cn_Uld6y.js";import"./code-highlight-BRUf_pqB.js";import"./alert-dialog-DYqj_ln8.js";const ge={agy:{provider:"agy",displayName:"Antigravity",defaultModel:"claude-opus-4-6-thinking",models:[{id:"claude-opus-4-6-thinking",name:"Claude Opus 4.6 Thinking",description:"Latest flagship, extended thinking",extendedContext:!1,presetMapping:{default:"claude-opus-4-6-thinking",opus:"claude-opus-4-6-thinking",sonnet:"claude-sonnet-4-6-thinking",haiku:"claude-sonnet-4-6"}},{id:"claude-opus-4-5-thinking",name:"Claude Opus 4.5 Thinking",description:"Previous flagship, extended thinking",presetMapping:{default:"claude-opus-4-5-thinking",opus:"claude-opus-4-5-thinking",sonnet:"claude-sonnet-4-6-thinking",haiku:"claude-sonnet-4-6"}},{id:"claude-sonnet-4-6-thinking",name:"Claude Sonnet 4.6 Thinking",description:"Latest Sonnet with extended thinking",presetMapping:{default:"claude-sonnet-4-6-thinking",opus:"claude-opus-4-6-thinking",sonnet:"claude-sonnet-4-6-thinking",haiku:"claude-sonnet-4-6"}},{id:"claude-sonnet-4-6",name:"Claude Sonnet 4.6",description:"Latest Sonnet baseline",presetMapping:{default:"claude-sonnet-4-6",opus:"claude-opus-4-6-thinking",sonnet:"claude-sonnet-4-6",haiku:"claude-sonnet-4-6"}},{id:"claude-sonnet-4-5-thinking",name:"Claude Sonnet 4.5 Thinking",description:"Balanced with extended thinking",presetMapping:{default:"claude-sonnet-4-5-thinking",opus:"claude-opus-4-6-thinking",sonnet:"claude-sonnet-4-5-thinking",haiku:"claude-sonnet-4-5"}},{id:"claude-sonnet-4-5",name:"Claude Sonnet 4.5",description:"Fast and capable",presetMapping:{default:"claude-sonnet-4-5",opus:"claude-opus-4-6-thinking",sonnet:"claude-sonnet-4-5",haiku:"claude-sonnet-4-5"}},{id:"gemini-3-pro-preview",name:"Gemini 3 Pro",description:"Google latest model via Antigravity",extendedContext:!0,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",extendedContext:!0,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",extendedContext:!0,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",extendedContext:!0,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",extendedContext:!0,presetMapping:{default:"gemini-2.5-pro",opus:"gemini-2.5-pro",sonnet:"gemini-2.5-pro",haiku:"gemini-2.5-flash"}}]},codex:{provider:"codex",displayName:"Codex",defaultModel:"gpt-5.3-codex",models:[{id:"gpt-5.3-codex",name:"GPT-5.3 Codex",description:"Supports up to xhigh effort",presetMapping:{default:"gpt-5.3-codex",opus:"gpt-5.3-codex",sonnet:"gpt-5.3-codex",haiku:"gpt-5-mini"}},{id:"gpt-5.2-codex",name:"GPT-5.2 Codex",description:"Previous stable Codex model",presetMapping:{default:"gpt-5.2-codex",opus:"gpt-5.2-codex",sonnet:"gpt-5.2-codex",haiku:"gpt-5-mini"}},{id:"gpt-5-mini",name:"GPT-5 Mini",description:"Fast, capped at high effort (no xhigh)",presetMapping:{default:"gpt-5-mini",opus:"gpt-5.3-codex",sonnet:"gpt-5-mini",haiku:"gpt-5-mini"}},{id:"gpt-5.1-codex-max",name:"Codex Max (5.1)",description:"Legacy most capable Codex model",presetMapping:{default:"gpt-5.1-codex-max",opus:"gpt-5.1-codex-max",sonnet:"gpt-5.1-codex-max",haiku:"gpt-5.1-codex-mini"}},{id:"gpt-5.2",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:"qwen3-coder-plus",models:[{id:"qwen3-coder-plus",name:"Qwen3 Coder Plus",description:"Code-focused model (1M context)",presetMapping:{default:"qwen3-coder-plus",opus:"qwen3-max",sonnet:"qwen3-coder-plus",haiku:"qwen3-coder-flash"}},{id:"qwen3-max",name:"Qwen3 Max",description:"Flagship model (256K context)",presetMapping:{default:"qwen3-max",opus:"qwen3-max",sonnet:"qwen3-coder-plus",haiku:"qwen3-coder-flash"}},{id:"qwen3-max-preview",name:"Qwen3 Max Preview",description:"Preview with thinking support (256K)",presetMapping:{default:"qwen3-max-preview",opus:"qwen3-max-preview",sonnet:"qwen3-max",haiku:"qwen3-coder-flash"}},{id:"qwen3-235b",name:"Qwen3 235B",description:"Large 235B A22B model",presetMapping:{default:"qwen3-235b",opus:"qwen3-max",sonnet:"qwen3-235b",haiku:"qwen3-coder-flash"}},{id:"qwen3-vl-plus",name:"Qwen3 VL Plus",description:"Vision-language multimodal"},{id:"qwen3-coder-flash",name:"Qwen3 Coder Flash",description:"Fast code generation"},{id:"qwen3-32b",name:"Qwen3 32B",description:"Qwen3 32B model"}]},iflow:{provider:"iflow",displayName:"iFlow",defaultModel:"qwen3-coder-plus",models:[{id:"qwen3-coder-plus",name:"Qwen3 Coder Plus",description:"Recommended default for iFlow accounts",presetMapping:{default:"qwen3-coder-plus",opus:"qwen3-coder-plus",sonnet:"qwen3-coder-plus",haiku:"qwen3-coder-plus"}},{id:"qwen3-max",name:"Qwen3 Max",description:"Flagship Qwen model via iFlow"},{id:"kimi-k2.5",name:"Kimi K2.5",description:"Latest Kimi model via iFlow"},{id:"kimi-k2",name:"Kimi K2",description:"Kimi general model"},{id:"deepseek-v3.2-chat",name:"DeepSeek V3.2 Chat",description:"Stable DeepSeek chat model"},{id:"deepseek-r1",name:"DeepSeek R1",description:"Reasoning-focused DeepSeek model"},{id:"glm-4.7",name:"GLM 4.7",description:"Zhipu GLM 4.7 via iFlow"},{id:"minimax-m2.5",name:"MiniMax M2.5",description:"MiniMax M2.5 via iFlow"},{id:"qwen3-vl-plus",name:"Qwen3 VL Plus",description:"Vision-language model"}]},kimi:{provider:"kimi",displayName:"Kimi (Moonshot)",defaultModel:"kimi-k2.5",models:[{id:"kimi-k2.5",name:"Kimi K2.5",description:"Latest multimodal model (262K context)",presetMapping:{default:"kimi-k2.5",opus:"kimi-k2.5",sonnet:"kimi-k2-thinking",haiku:"kimi-k2"}},{id:"kimi-k2-thinking",name:"Kimi K2 Thinking",description:"Extended reasoning model",presetMapping:{default:"kimi-k2-thinking",opus:"kimi-k2.5",sonnet:"kimi-k2-thinking",haiku:"kimi-k2"}},{id:"kimi-k2",name:"Kimi K2",description:"Flagship coding model"}]},kiro:{provider:"kiro",displayName:"Kiro (AWS)",defaultModel:"kiro-claude-sonnet-4-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"}]},claude:{provider:"claude",displayName:"Claude (Anthropic)",defaultModel:"claude-sonnet-4-5-20250929",models:[{id:"claude-opus-4-6",name:"Claude Opus 4.6",description:"Latest flagship model",extendedContext:!0,presetMapping:{default:"claude-opus-4-6",opus:"claude-opus-4-6",sonnet:"claude-sonnet-4-5-20250929",haiku:"claude-haiku-4-5-20251001"}},{id:"claude-opus-4-5-20251101",name:"Claude Opus 4.5",description:"Most capable Claude model",extendedContext:!0,presetMapping:{default:"claude-opus-4-5-20251101",opus:"claude-opus-4-5-20251101",sonnet:"claude-sonnet-4-5-20250929",haiku:"claude-haiku-4-5-20251001"}},{id:"claude-sonnet-4-5-20250929",name:"Claude Sonnet 4.5",description:"Balanced performance and speed",extendedContext:!0,presetMapping:{default:"claude-sonnet-4-5-20250929",opus:"claude-opus-4-5-20251101",sonnet:"claude-sonnet-4-5-20250929",haiku:"claude-haiku-4-5-20251001"}},{id:"claude-sonnet-4-20250514",name:"Claude Sonnet 4",description:"Previous generation Sonnet",extendedContext:!0,presetMapping:{default:"claude-sonnet-4-20250514",opus:"claude-opus-4-5-20251101",sonnet:"claude-sonnet-4-20250514",haiku:"claude-haiku-4-5-20251001"}},{id:"claude-haiku-4-5-20251001",name:"Claude Haiku 4.5",description:"Fast and efficient"}]}},Me="ccs-internal-managed";async function Yt(){try{const s=await fetch("/api/settings/auth/tokens/raw");return s.ok?(await s.json())?.apiKey?.value??Me:Me}catch{return Me}}async function De(s,a){const t=ge[s];if(!t)return{success:!1};const n=t.models[0],i=n?.presetMapping||{default:t.defaultModel,opus:t.defaultModel,sonnet:t.defaultModel,haiku:t.defaultModel},o=await Yt(),c={env:{ANTHROPIC_BASE_URL:`http://127.0.0.1:${Ee}/api/provider/${s}`,ANTHROPIC_AUTH_TOKEN:o,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:c})})).ok,presetName:n?.name||t.defaultModel}}catch{return{success:!1}}}function Xt({currentProgress:s,allSteps:a}){return e.jsx("div",{className:"flex justify-center gap-1 pt-2",children:a.map((t,n)=>e.jsx("div",{className:`w-2 h-2 rounded-full transition-colors ${s>=n?"bg-primary":"bg-muted"}`},t))})}function Zt({providers:s,onSelect:a}){return e.jsx("div",{className:"grid gap-2",children:s.map(t=>e.jsxs("button",{onClick:()=>a(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(As,{className:"w-4 h-4 text-muted-foreground"})]},t.id))})}function ea({selectedProvider:s,providers:a,authCommand:t,isRefreshing:n,isPending:i,onBack:o,onStartAuth:l,onRefresh:c}){const[j,h]=r.useState(!1),x=async b=>{await navigator.clipboard.writeText(b),h(!0),setTimeout(()=>h(!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 ",a.find(b=>b.id===s)?.name," to add an account"]}),e.jsx(R,{onClick:l,disabled:i,className:"w-full gap-2",size:"lg",children:i?e.jsxs(e.Fragment,{children:[e.jsx(J,{className:"w-4 h-4 animate-spin"}),"Authenticating..."]}):e.jsxs(e.Fragment,{children:[e.jsx(me,{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(vs,{children:e.jsxs(Ns,{className:"p-4 space-y-3",children:[e.jsxs("div",{className:"flex items-center gap-2 text-sm text-muted-foreground",children:[e.jsx(Dt,{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(R,{variant:"outline",size:"icon",onClick:()=>x(t),children:j?e.jsx(se,{className:"w-4 h-4 text-green-500"}):e.jsx(Ss,{className:"w-4 h-4"})})]})]})}),e.jsxs("div",{className:"flex items-center justify-between",children:[e.jsxs(R,{variant:"ghost",onClick:o,disabled:i,children:[e.jsx(Qe,{className:"w-4 h-4 mr-2"}),"Back"]}),e.jsxs(R,{variant:"outline",onClick:c,disabled:n||i,children:[e.jsx(Ve,{className:`w-4 h-4 mr-2 ${n?"animate-spin":""}`}),n?"Checking...":"Refresh Status"]})]})]})}function sa({accounts:s,privacyMode:a,onSelect:t,onAddNew:n,onBack:i}){return e.jsxs("div",{className:"space-y-4",children:[e.jsxs("div",{className:"text-xs font-medium text-muted-foreground uppercase tracking-wide",children:["Select an account (",s.length,")"]}),e.jsx("div",{className:"grid gap-2 max-h-[320px] overflow-y-auto pr-1",children:s.map(o=>e.jsxs("button",{type:"button",onClick:()=>t(o),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(xe,{className:"w-4 h-4 text-muted-foreground"})}),e.jsxs("div",{children:[e.jsx("div",{className:H("font-medium",a&&ye),children:o.email||o.id}),o.isDefault&&e.jsx("div",{className:"text-xs text-muted-foreground",children:"Default account"})]})]}),e.jsx(As,{className:"w-4 h-4 text-muted-foreground"})]},o.id))}),e.jsxs("div",{className:"relative",children:[e.jsx("div",{className:"absolute inset-0 flex items-center",children:e.jsx("span",{className:"w-full border-t"})}),e.jsx("div",{className:"relative flex justify-center text-xs uppercase",children:e.jsx("span",{className:"bg-background px-2 text-muted-foreground",children:"Or"})})]}),e.jsxs("button",{type:"button",className:"w-full flex items-center gap-3 p-3 border-2 border-dashed border-primary/50 rounded-lg hover:border-primary hover:bg-primary/5 transition-colors text-left",onClick:n,children:[e.jsx("div",{className:"w-8 h-8 rounded-full bg-primary/10 flex items-center justify-center shrink-0",children:e.jsx(me,{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(R,{variant:"ghost",onClick:i,children:[e.jsx(Qe,{className:"w-4 h-4 mr-2"}),"Back"]})})]})}const xs="__custom__";function ta({selectedProvider:s,selectedAccount:a,variantName:t,modelName:n,isPending:i,privacyMode:o,onVariantNameChange:l,onModelChange:c,onBack:j,onSkip:h,onCreate:x}){const b=ge[s]?.models||[],u=n&&!b.some(g=>g.id===n),[v,C]=r.useState(u),m=g=>{g===xs?(C(!0),c("")):(C(!1),c(g))};return e.jsxs("div",{className:"space-y-4",children:[a&&e.jsxs("div",{className:"flex items-center gap-2 p-2 bg-muted/50 rounded-md text-sm",children:[e.jsx(xe,{className:"w-4 h-4"}),e.jsxs("span",{children:["Using:"," ",e.jsx("span",{className:H(o&&ye),children:a.email||a.id})]})]}),e.jsxs("div",{className:"space-y-2",children:[e.jsx(W,{htmlFor:"variant-name",children:"Variant Name *"}),e.jsx(re,{id:"variant-name",value:t,onChange:g=>l(g.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(W,{children:"Model"}),v?e.jsxs("div",{className:"space-y-2",children:[e.jsx(re,{value:n,onChange:g=>c(g.target.value),placeholder:"e.g., gemini-2.5-pro, claude-opus-4-5"}),e.jsx("button",{type:"button",className:"text-xs text-primary hover:underline",onClick:()=>C(!1),children:"Choose from presets instead"})]}):e.jsxs(Ie,{value:b.some(g=>g.id===n)?n:"",onValueChange:m,children:[e.jsx(Fe,{children:e.jsx(Ue,{placeholder:"Select a model"})}),e.jsxs(Ke,{children:[b.map(g=>e.jsx(he,{value:g.id,children:e.jsxs("div",{className:"flex items-center gap-2",children:[e.jsx("span",{children:g.name}),g.description&&e.jsxs("span",{className:"text-xs text-muted-foreground",children:["- ",g.description]})]})},g.id)),e.jsx(he,{value:xs,children:e.jsx("span",{className:"text-primary",children:"Custom model name..."})})]})]}),e.jsx("div",{className:"text-xs text-muted-foreground",children:v?"Enter any model name supported by CLIProxy":`Default: ${ge[s]?.defaultModel||"provider default"}`})]}),e.jsxs("div",{className:"flex items-center justify-between pt-2",children:[e.jsxs(R,{variant:"ghost",onClick:j,children:[e.jsx(Qe,{className:"w-4 h-4 mr-2"}),"Back"]}),e.jsxs("div",{className:"flex items-center gap-2",children:[e.jsx(R,{variant:"ghost",onClick:h,children:"Skip"}),e.jsx(R,{onClick:x,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 aa({variantName:s,onClose:a}){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(se,{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(vs,{children:e.jsxs(Ns,{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(R,{onClick:a,className:"w-full",children:"Done"})]})}function na({open:s,onClose:a}){const[t,n]=r.useState("provider"),[i,o]=r.useState(""),[l,c]=r.useState(null),[j,h]=r.useState(""),[x,b]=r.useState(""),[u,v]=r.useState(!1),[C,m]=r.useState(!1),{data:g,refetch:p}=bs(),O=Gs(),P=$s(),k=Qs(),{privacyMode:_}=ws(),w=g?.authStatus.find(M=>M.provider===i),E=r.useMemo(()=>w?.accounts||[],[w?.accounts]);r.useEffect(()=>{if(!s){const M=setTimeout(()=>{n("provider"),o(""),c(null),h(""),b(""),m(!1)},0);return()=>clearTimeout(M)}},[s]),r.useEffect(()=>{if(t==="auth"&&E.length>0&&!C){const M=setTimeout(()=>{n("account")},0);return()=>clearTimeout(M)}},[t,E,C]);const N=async()=>{v(!0),await p(),v(!1)},F=()=>{const M=(w?.accounts?.length||0)===0;P.mutate({provider:i},{onSuccess:async T=>{if(M){const I=await De(i);I.success&&I.presetName?K.success(`Applied "${I.presetName}" preset`):I.success||K.warning("Account added, but failed to apply default preset")}T.account&&(c(T.account),n("variant")),p()}})},y=M=>{o(M),(g?.authStatus.find($=>$.provider===M)?.accounts||[]).length===0?n("auth"):n("account")},f=M=>{c(M),n("variant")},A=async()=>{if(!(!j||!i))try{await O.mutateAsync({name:j,provider:i,model:x||void 0,account:l?.id}),n("success")}catch(M){console.error("Failed to create variant:",M)}},L=`ccs ${i} --auth --add`,B=zs(t),G=M=>{if(!M&&(P.isPending&&i&&k.mutate(i),t==="success"||t==="provider")){a();return}};return e.jsx(qe,{open:s,onOpenChange:G,children:e.jsxs(He,{className:"sm:max-w-lg",onPointerDownOutside:M=>{t!=="success"&&t!=="provider"&&M.preventDefault()},onEscapeKeyDown:M=>{(P.isPending||O.isPending)&&M.preventDefault()},children:[e.jsxs(Be,{children:[e.jsxs(Ge,{className:"flex items-center gap-2",children:[e.jsx(fe,{className:"w-5 h-5 text-primary"}),"Quick Setup Wizard"]}),e.jsxs(ys,{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(Zt,{providers:as,onSelect:y}),t==="auth"&&e.jsx(ea,{selectedProvider:i,providers:as,authCommand:L,isRefreshing:u,isPending:P.isPending,onBack:()=>n("provider"),onStartAuth:F,onRefresh:N}),t==="account"&&e.jsx(sa,{accounts:E,privacyMode:_,onSelect:f,onAddNew:()=>{m(!0),n("auth")},onBack:()=>n("provider")}),t==="variant"&&e.jsx(ta,{selectedProvider:i,selectedAccount:l,variantName:j,modelName:x,isPending:O.isPending,privacyMode:_,onVariantNameChange:h,onModelChange:b,onBack:()=>E.length>0?n("account"):n("provider"),onSkip:a,onCreate:A}),t==="success"&&e.jsx(aa,{variantName:j,onClose:a})]}),e.jsx(Xt,{currentProgress:B,allSteps:Vs})]})})}const ia=3e3,ra=300*1e3;async function Te(s){const a=await s.text();if(!a)return{};try{return JSON.parse(a)}catch{const t=s.status>=400?`Request failed with status ${s.status}`:void 0;return t?{error:t}:{}}}const ie={provider:null,isAuthenticating:!1,error:null,authUrl:null,oauthState:null,isSubmittingCallback:!1,isDeviceCodeFlow:!1};function oa(){const[s,a]=r.useState(ie),t=r.useRef(null),n=r.useRef(null),i=r.useRef(0),o=r.useRef(!1),l=Le(),c=r.useCallback(()=>{n.current&&(clearInterval(n.current),n.current=null)},[]);r.useEffect(()=>()=>{t.current?.abort(),c(),o.current=!1},[c]);const j=r.useCallback(async(u,v)=>{if(Date.now()-i.current>ra){c(),a(C=>({...C,isAuthenticating:!1,error:"Authentication timed out. Please try again."}));return}try{const m=await(await fetch(`/api/cliproxy/auth/${u}/status?state=${encodeURIComponent(v)}`)).json();if(m.status==="ok")c(),l.invalidateQueries({queryKey:["cliproxy-auth"]}),l.invalidateQueries({queryKey:["account-quota"]}),K.success(`${u} authentication successful`),o.current=!1,a(ie);else if(m.status==="auth_url"){const g=m.url||m.auth_url;g&&(a(p=>({...p,authUrl:g})),o.current||(o.current=!0,window.open(g,"_blank")))}else if(m.status==="device_code"){c();const g=m.user_code&&m.verification_url?`Open ${m.verification_url} and enter code: ${m.user_code}`:"Switch to Device Code method and try again.";K.error("Provider returned Device Code flow in callback mode"),a(p=>({...p,isAuthenticating:!1,error:g}))}else if(m.status==="error"){c();const g=m.error||"Authentication failed";K.error(g),a(p=>({...p,isAuthenticating:!1,error:g}))}}catch{}},[l,c]),h=r.useCallback(async(u,v)=>{if(!Js(u)){a({...ie,error:`Unknown provider: ${u}`});return}t.current?.abort(),c(),o.current=!1;const C=new AbortController;t.current=C;const g=(v?.flowType||(ks(u)?"device_code":"authorization_code"))==="device_code",p=v?.startEndpoint||(g?"start":"start-url"),O={nickname:v?.nickname,kiroMethod:v?.kiroMethod,riskAcknowledgement:v?.riskAcknowledgement};a({provider:u,isAuthenticating:!0,error:null,authUrl:null,oauthState:null,isSubmittingCallback:!1,isDeviceCodeFlow:g});try{if(p==="start")fetch(`/api/cliproxy/auth/${u}/start`,{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify(O),signal:C.signal}).then(async P=>{const k=await Te(P),_=k.success===!0;if(P.ok&&_)l.invalidateQueries({queryKey:["cliproxy-auth"]}),l.invalidateQueries({queryKey:["account-quota"]}),o.current=!1,a(ie);else{const w=typeof k.error=="string"?k.error:"Authentication failed";K.error(w),a(E=>({...E,isAuthenticating:!1,error:w}))}}).catch(P=>{if(P instanceof Error&&P.name==="AbortError")return;const k=P instanceof Error?P.message:"Authentication failed";K.error(k),a(_=>({..._,isAuthenticating:!1,error:k}))});else{const P=await fetch(`/api/cliproxy/auth/${u}/start-url`,{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify(O),signal:C.signal}),k=await Te(P),_=k.success===!0;if(!P.ok||!_){const N=typeof k.error=="string"?k.error:"Failed to start OAuth";throw new Error(N)}const w=typeof k.authUrl=="string"?k.authUrl:null,E=typeof k.state=="string"?k.state:null;a(N=>({...N,authUrl:w,oauthState:E})),w&&(o.current=!0,window.open(w,"_blank")),E&&(i.current=Date.now(),n.current=setInterval(()=>{j(u,E)},ia))}}catch(P){if(P instanceof Error&&P.name==="AbortError"){o.current=!1,a(ie);return}const k=P instanceof Error?P.message:"Authentication failed";K.error(k),a(_=>({..._,isAuthenticating:!1,error:k}))}},[j,c,l]),x=r.useCallback(()=>{const u=s.provider;t.current?.abort(),c(),o.current=!1,a(ie),u&&Ne.cliproxy.auth.cancel(u).catch(()=>{})},[s.provider,c]),b=r.useCallback(async u=>{if(s.provider){a(v=>({...v,isSubmittingCallback:!0,error:null}));try{const v=await fetch(`/api/cliproxy/auth/${s.provider}/submit-callback`,{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify({redirectUrl:u})}),C=await Te(v),m=C.success===!0;if(v.ok&&m)c(),l.invalidateQueries({queryKey:["cliproxy-auth"]}),l.invalidateQueries({queryKey:["account-quota"]}),K.success(`${s.provider} authentication successful`),a(ie);else{const g=typeof C.error=="string"?C.error:"Callback submission failed";throw new Error(g)}}catch(v){const C=v instanceof Error?v.message:"Failed to submit callback";K.error(C),a(m=>({...m,isSubmittingCallback:!1,error:C}))}}},[s.provider,l,c]);return r.useMemo(()=>({...s,startAuth:h,cancelAuth:x,submitCallback:b}),[s,h,x,b])}function Ls({className:s,showAcknowledgement:a=!1,acknowledgementPhrase:t=be,acknowledgementText:n="",onAcknowledgementTextChange:i,disabled:o=!1,showProxySettingsLink:l=!1}){const c="OAuth Account Safety Warning",j="Issue #509 · Gemini + AGY OAuth risk",h=e.jsxs(e.Fragment,{children:["Issue #509 documents suspension/ban reports tied to ",e.jsx("code",{className:"font-mono",children:"ccs agy"})," ","and shared-account usage between ",e.jsx("code",{className:"font-mono",children:"ccs gemini"})," and"," ",e.jsx("code",{className:"font-mono",children:"ccs agy"}),"."]}),x=e.jsx(e.Fragment,{children:"Continue only if you accept full responsibility for OAuth and account-access risk."});return e.jsxs("section",{role:"alert",className:H("relative overflow-hidden rounded-xl border border-amber-500/30 bg-gradient-to-br from-amber-50 via-background to-rose-50/70 shadow-sm dark:from-amber-950/20 dark:to-rose-950/20",s),children:[e.jsx("div",{className:"absolute inset-x-0 top-0 h-0.5 bg-gradient-to-r from-amber-500 via-orange-500 to-rose-500"}),e.jsxs("div",{className:"space-y-3 p-4",children:[e.jsxs("div",{className:"flex items-start justify-between gap-3",children:[e.jsxs("div",{className:"flex items-start gap-2.5",children:[e.jsx("div",{className:"mt-0.5 inline-flex h-7 w-7 items-center justify-center rounded-md bg-amber-500/15 text-amber-700 dark:text-amber-400",children:e.jsx(ze,{className:"h-4 w-4"})}),e.jsxs("div",{children:[e.jsx("p",{className:"text-sm font-semibold leading-5",children:c}),e.jsx("p",{className:"text-xs text-muted-foreground",children:j})]})]}),e.jsx(U,{variant:"outline",className:"border-amber-500/40 text-amber-700 dark:text-amber-300",children:"High Risk"})]}),e.jsxs("div",{className:"space-y-2 text-sm leading-relaxed",children:[e.jsx("p",{children:h}),e.jsx("p",{className:"font-medium text-amber-900 dark:text-amber-200",children:x}),e.jsx("p",{className:"text-xs text-muted-foreground",children:"CCS is provided as-is and does not take responsibility for suspension, bans, or access loss from upstream providers."})]}),e.jsxs("div",{className:"flex flex-wrap items-center gap-2",children:[e.jsxs("a",{href:"https://github.com/kaitranntt/ccs/issues/509",target:"_blank",rel:"noreferrer",className:"inline-flex items-center gap-1.5 rounded-md border border-amber-500/30 bg-amber-500/10 px-2.5 py-1 text-xs font-medium text-amber-800 transition-colors hover:bg-amber-500/15 dark:text-amber-200",children:["Read issue #509",e.jsx(me,{className:"h-3.5 w-3.5"})]}),l&&e.jsxs("a",{href:"/settings?tab=proxy",className:"inline-flex items-center gap-1.5 rounded-md border border-amber-500/30 bg-amber-500/10 px-2.5 py-1 text-xs font-medium text-amber-800 transition-colors hover:bg-amber-500/15 dark:text-amber-200",children:[e.jsx(Lt,{className:"h-3.5 w-3.5"}),"Gemini + AGY controls: Settings > Proxy"]}),e.jsx("span",{className:"rounded-md border border-border/70 bg-muted/60 px-2.5 py-1 text-xs text-muted-foreground",children:"Applies to CLI and dashboard auth"})]}),a&&i&&e.jsxs("div",{className:"rounded-lg border border-amber-500/25 bg-amber-500/5 p-2.5",children:[e.jsxs(W,{htmlFor:"account-risk-ack-text",className:"text-xs leading-5",children:["Type exact phrase to continue:"," ",e.jsx("code",{className:"rounded bg-muted px-1 py-0.5 font-mono",children:t})]}),e.jsx(re,{id:"account-risk-ack-text",value:n,onChange:C=>i(C.target.value),placeholder:t,disabled:o,className:"mt-2 font-mono text-xs"})]})]})]})}function la({className:s,value:a,onChange:t,disabled:n=!1}){const i=[a.reviewedIssue509,a.understandsBanRisk,a.acceptsFullResponsibility,a.typedPhrase.trim().replace(/\s+/g," ").toUpperCase()===ms].filter(Boolean).length,o=i/4*100,l=c=>{t({...a,...c})};return e.jsxs("section",{role:"alert",className:H("relative overflow-hidden rounded-xl border border-rose-500/35 bg-gradient-to-br from-rose-50 via-background to-amber-50/70 p-4 shadow-sm dark:from-rose-950/20 dark:to-amber-950/20",s),children:[e.jsx("div",{className:"absolute inset-x-0 top-0 h-0.5 bg-gradient-to-r from-rose-500 via-orange-500 to-amber-500"}),e.jsxs("div",{className:"space-y-4",children:[e.jsxs("div",{className:"flex items-start justify-between gap-3",children:[e.jsxs("div",{className:"flex items-start gap-2.5",children:[e.jsx("div",{className:"mt-0.5 inline-flex h-7 w-7 items-center justify-center rounded-md bg-rose-500/15 text-rose-700 dark:text-rose-300",children:e.jsx(ze,{className:"h-4 w-4"})}),e.jsxs("div",{className:"space-y-1",children:[e.jsx("p",{className:"text-sm font-semibold leading-5",children:"Antigravity OAuth Responsibility"}),e.jsx("p",{className:"text-xs text-muted-foreground",children:"Complete all 4 steps before you can authenticate."})]})]}),e.jsx(U,{variant:"outline",className:"border-rose-500/40 text-rose-700 dark:text-rose-300",children:"Mandatory"})]}),e.jsxs("div",{className:"space-y-1.5",children:[e.jsxs("div",{className:"flex items-center justify-between text-xs text-muted-foreground",children:[e.jsx("span",{children:"Completion"}),e.jsxs("span",{children:[i,"/4 steps"]})]}),e.jsx(Re,{value:o,className:"h-2"})]}),e.jsxs("div",{className:"space-y-3 rounded-lg border border-rose-500/20 bg-rose-500/5 p-3",children:[e.jsxs("div",{className:"flex items-start gap-2",children:[e.jsx(we,{id:"agy-step-reviewed-issue",checked:a.reviewedIssue509,onCheckedChange:c=>l({reviewedIssue509:!!c}),disabled:n}),e.jsx(W,{htmlFor:"agy-step-reviewed-issue",className:"text-xs leading-5",children:"Step 1: I reviewed issue #509 and understand AGY OAuth can trigger account bans/suspensions."})]}),e.jsxs("div",{className:"flex items-start gap-2",children:[e.jsx(we,{id:"agy-step-understands-risk",checked:a.understandsBanRisk,onCheckedChange:c=>l({understandsBanRisk:!!c}),disabled:n}),e.jsx(W,{htmlFor:"agy-step-understands-risk",className:"text-xs leading-5",children:"Step 2: I understand this OAuth action is my own decision and I accept the upstream risk."})]}),e.jsxs("div",{className:"flex items-start gap-2",children:[e.jsx(we,{id:"agy-step-accept-responsibility",checked:a.acceptsFullResponsibility,onCheckedChange:c=>l({acceptsFullResponsibility:!!c}),disabled:n}),e.jsx(W,{htmlFor:"agy-step-accept-responsibility",className:"text-xs leading-5",children:"Step 3: I accept full responsibility. CCS is not liable for suspension, bans, or access loss."})]})]}),e.jsxs("div",{className:"space-y-2 rounded-lg border border-amber-500/25 bg-amber-500/5 p-3",children:[e.jsxs("div",{className:"flex items-center gap-1.5 text-xs font-medium text-amber-800 dark:text-amber-200",children:[e.jsx(Ps,{className:"h-3.5 w-3.5"}),"Step 4: Type exact phrase to continue"]}),e.jsx(re,{value:a.typedPhrase,onChange:c=>l({typedPhrase:c.target.value}),placeholder:ms,disabled:n,className:"font-mono text-xs"})]}),e.jsx("div",{className:"flex flex-wrap items-center gap-2 text-xs",children:e.jsxs("a",{href:"https://github.com/kaitranntt/ccs/issues/509",target:"_blank",rel:"noreferrer",className:"inline-flex items-center gap-1.5 rounded-md border border-rose-500/30 bg-rose-500/10 px-2.5 py-1 font-medium text-rose-800 transition-colors hover:bg-rose-500/15 dark:text-rose-200",children:["Read issue #509",e.jsx(me,{className:"h-3.5 w-3.5"})]})})]})]})}function ca(s){return s.trim().replace(/\s+/g," ").toUpperCase()}function da({open:s,onClose:a,provider:t,displayName:n,isFirstAccount:i=!1}){const[o,l]=r.useState(""),[c,j]=r.useState(""),[h,x]=r.useState(!1),[b,u]=r.useState(null),[v,C]=r.useState(""),[m,g]=r.useState(Pe),[p,O]=r.useState(!1),[P,k]=r.useState(!1),[_,w]=r.useState(ns),E=r.useRef(!1),N=oa(),F=Ws(),y=t==="kiro",f=t==="gemini",A=t==="agy"&&!p,L=t==="agy"&&P,B=Vt(m),G=ca(v)===be,M=ks(t),T=Ys(t),I=Xs(_),$=y?I.flowType==="device_code":M,Q=N.isAuthenticating||F.isPending,Y=o.trim(),X=b||N.error,d=r.useCallback(async()=>{const S=await fetch("/api/settings/auth/antigravity-risk");if(!S.ok)throw new Error("Failed to load Antigravity power user setting");return(await S.json()).antigravityAckBypass===!0},[]),D=()=>{l(""),j(""),x(!1),u(null),C(""),g(Pe),O(!1),k(!1),w(ns),E.current=!1,a()};r.useEffect(()=>{s&&(C(""),g(Pe),u(null))},[t,s]),r.useEffect(()=>{let S=!1;if(!s||t!=="agy"){O(!1),k(!1);return}return(async()=>{try{k(!0);const ee=await d();S||O(ee)}catch{S||O(!1)}finally{S||k(!1)}})(),()=>{S=!0}},[d,s,t]),r.useEffect(()=>{if(!s||t!=="agy"||!N.error||!p)return;const S=N.error.toLowerCase();if(!(S.includes("agy_risk_ack_required")||S.includes("responsibility acknowledgement")||S.includes("responsibility checklist")))return;let ee=!1;return(async()=>{try{k(!0);const ve=await d();if(ee)return;O(ve),ve||u("Power user mode is off. Complete the AGY checklist and retry.")}catch{if(ee)return;O(!1),u("Power user mode is off. Complete the AGY checklist and retry.")}finally{ee||k(!1)}})(),()=>{ee=!0}},[p,N.error,d,s,t]),r.useEffect(()=>{!N.isAuthenticating&&!N.error&&N.provider===null&&s&&E.current&&(E.current=!1,(async()=>{try{const te=await De(t);te.success&&te.presetName&&i&&K.success(`Applied "${te.presetName}" preset`)}catch{}D()})())},[N.isAuthenticating,N.error,N.provider]);const V=()=>{N.cancelAuth(),D()},Z=async()=>{N.authUrl&&(await navigator.clipboard.writeText(N.authUrl),x(!0),setTimeout(()=>x(!1),2e3))},pe=()=>{c.trim()&&N.submitCallback(c.trim())},Ce=()=>{if(L){u("Loading Antigravity safety settings. Please wait a moment and retry.");return}if(A&&!B){u("Complete all Antigravity responsibility steps before authenticating this provider.");return}if(f&&!G){u(`Type "${be}" to acknowledge the account safety warning before authenticating this provider.`);return}if(T&&!Y){u(`Nickname is required for ${n} accounts.`);return}u(null),E.current=!0,N.startAuth(t,{nickname:Y||void 0,kiroMethod:y?_:void 0,flowType:y?I.flowType:void 0,startEndpoint:y?I.startEndpoint:void 0,riskAcknowledgement:A?{version:zt,reviewedIssue509:m.reviewedIssue509,understandsBanRisk:m.understandsBanRisk,acceptsFullResponsibility:m.acceptsFullResponsibility,typedPhrase:m.typedPhrase}:void 0})},Ae=()=>{E.current=!0,F.mutate(void 0,{onSuccess:async()=>{const S=await De("kiro");S.success&&S.presetName&&i&&K.success(`Applied "${S.presetName}" preset`),D()}})},Se=S=>{S||V()},z=N.isAuthenticating;return e.jsx(qe,{open:s,onOpenChange:Se,children:e.jsxs(He,{className:"sm:max-w-md",onInteractOutside:S=>{z&&S.preventDefault()},children:[e.jsxs(Be,{children:[e.jsxs(Ge,{children:["Add ",n," Account"]}),e.jsx(ys,{children:y?"Choose a Kiro auth method, then authenticate via browser or import from Kiro IDE.":$?"Click Authenticate. A verification code will appear for you to enter on the provider website.":"Click Authenticate to get an OAuth URL. Open it in any browser to sign in."})]}),e.jsxs("div",{className:"space-y-4 py-4",children:[A&&!z&&e.jsx(la,{value:m,onChange:S=>{g(S),u(null)},disabled:Q}),t==="agy"&&p&&!z&&e.jsxs("div",{className:"rounded-lg border border-amber-400/35 bg-amber-50/70 p-3 text-xs text-amber-900 dark:border-amber-800/60 dark:bg-amber-950/25 dark:text-amber-100",children:[e.jsxs("div",{className:"mb-1.5 flex items-center gap-1.5 font-semibold",children:[e.jsx(Ps,{className:"h-3.5 w-3.5"}),"Power user mode enabled"]}),"AGY responsibility checklist is skipped from Settings ",">"," Proxy. You accept full responsibility for OAuth/account risk."]}),f&&!z&&e.jsx(Ls,{showAcknowledgement:!0,acknowledgementPhrase:be,acknowledgementText:v,onAcknowledgementTextChange:S=>{C(S),u(null)},disabled:Q}),y&&!z&&e.jsxs("div",{className:"space-y-2",children:[e.jsx(W,{htmlFor:"kiro-auth-method",children:"Auth Method"}),e.jsxs(Ie,{value:_,onValueChange:S=>{w(S),u(null)},children:[e.jsx(Fe,{id:"kiro-auth-method",children:e.jsx(Ue,{placeholder:"Select Kiro auth method"})}),e.jsx(Ke,{children:Zs.map(S=>e.jsx(he,{value:S.id,children:S.label},S.id))})]}),e.jsx("p",{className:"text-xs text-muted-foreground",children:I.description})]}),!z&&e.jsxs("div",{className:"space-y-2",children:[e.jsx(W,{htmlFor:"nickname",children:T?"Nickname (required)":"Nickname (optional)"}),e.jsxs("div",{className:"flex items-center gap-2",children:[e.jsx(xe,{className:"w-4 h-4 text-muted-foreground"}),e.jsx(re,{id:"nickname",value:o,onChange:S=>{l(S.target.value),u(null)},placeholder:"e.g., work, personal",disabled:Q,className:"flex-1"})]}),e.jsx("p",{className:"text-xs text-muted-foreground",children:T?"Required for this provider. Use a unique friendly name (e.g., work, personal).":"A friendly name to identify this account. Auto-generated from email if left empty."})]}),z&&e.jsxs("div",{className:"space-y-4",children:[e.jsxs("div",{className:"text-center",children:[e.jsxs("p",{className:"text-sm text-muted-foreground",children:[e.jsx(J,{className:"w-4 h-4 inline mr-2 animate-spin"}),"Waiting for authentication..."]}),e.jsx("p",{className:"text-xs text-muted-foreground mt-1",children:N.isDeviceCodeFlow?"A verification code dialog will appear shortly. Enter the code on the provider website.":"Complete the authentication in your browser. This dialog closes automatically."})]}),N.authUrl&&!N.isDeviceCodeFlow&&e.jsxs("div",{className:"space-y-3",children:[e.jsxs("div",{className:"space-y-2",children:[e.jsx(W,{className:"text-xs",children:"Open this URL in any browser to sign in:"}),e.jsxs("div",{className:"p-3 bg-muted rounded-md",children:[e.jsx("p",{className:"text-xs text-muted-foreground break-all font-mono line-clamp-3",children:N.authUrl}),e.jsxs("div",{className:"flex gap-2 mt-2",children:[e.jsx(R,{variant:"outline",size:"sm",onClick:Z,children:h?e.jsxs(e.Fragment,{children:[e.jsx(se,{className:"w-3 h-3 mr-1"}),"Copied"]}):e.jsxs(e.Fragment,{children:[e.jsx(Ss,{className:"w-3 h-3 mr-1"}),"Copy"]})}),e.jsxs(R,{variant:"outline",size:"sm",onClick:()=>{if(!N.authUrl)return;const S=window.open(N.authUrl,"_blank");(!S||S.closed||typeof S.closed>"u")&&K.warning("Popup blocked. Copy the URL above and open it manually in your browser.",{duration:5e3})},children:[e.jsx(me,{className:"w-3 h-3 mr-1"}),"Open"]})]})]})]}),e.jsxs("div",{className:"space-y-2",children:[e.jsx(W,{htmlFor:"callback-url",className:"text-xs",children:"Redirect didn't work? Paste the callback URL:"}),e.jsx(re,{id:"callback-url",value:c,onChange:S=>j(S.target.value),placeholder:"Paste the redirect URL here...",className:"font-mono text-xs"}),e.jsx(R,{variant:"secondary",size:"sm",onClick:pe,disabled:!c.trim()||N.isSubmittingCallback,children:N.isSubmittingCallback?e.jsxs(e.Fragment,{children:[e.jsx(J,{className:"w-3 h-3 mr-1 animate-spin"}),"Submitting..."]}):"Submit Callback"})]})]}),!N.authUrl&&!N.isDeviceCodeFlow&&e.jsx("p",{className:"text-xs text-center text-muted-foreground",children:"Preparing sign-in URL..."})]}),X&&e.jsx("p",{className:"text-xs text-center text-destructive",children:X}),F.isPending&&e.jsxs("p",{className:"text-sm text-center text-muted-foreground",children:[e.jsx(J,{className:"w-4 h-4 inline mr-2 animate-spin"}),"Importing token from Kiro IDE..."]}),e.jsxs("div",{className:"flex items-center justify-end gap-2 pt-2",children:[e.jsx(R,{variant:"ghost",onClick:V,children:"Cancel"}),y&&!z&&e.jsx(R,{variant:"outline",onClick:Ae,disabled:Q,children:F.isPending?e.jsxs(e.Fragment,{children:[e.jsx(J,{className:"w-4 h-4 mr-2 animate-spin"}),"Importing..."]}):e.jsxs(e.Fragment,{children:[e.jsx(It,{className:"w-4 h-4 mr-2"}),"Import from IDE"]})}),!z&&e.jsxs(R,{onClick:Ce,disabled:Q||L||T&&!Y||A&&!B||f&&!G,children:[e.jsx(me,{className:"w-4 h-4 mr-2"}),"Authenticate"]})]})]})]})})}const Ye="[1m]";function ua(s){return s.toLowerCase().startsWith("gemini-")}function Xe(s){return s.toLowerCase().endsWith(Ye.toLowerCase())}function ma(s){return!s||Xe(s)?s:`${s}${Ye}`}function Is(s){return s&&(Xe(s)?s.slice(0,-Ye.length):s)}const ps=["ANTHROPIC_MODEL"],xa=["ANTHROPIC_BASE_URL","ANTHROPIC_AUTH_TOKEN"];function pa(s){const a=s?.env||{};return xa.filter(t=>!a[t]?.trim())}function ha(s){const[a,t]=r.useState(null),[n,i]=r.useState(!1),o=Le(),{data:l,isLoading:c,refetch:j}=js({queryKey:["settings",s],queryFn:async()=>{const y=await fetch(`/api/settings/${s}/raw`);return y.ok?y.json():{profile:s,settings:{env:{}},mtime:Date.now(),path:`~/.ccs/profiles/${s}/settings.json`}}}),h=l?.settings,x=r.useMemo(()=>a!==null?a:h?JSON.stringify(h,null,2):`{
2
+ "env": {}
3
+ }`,[a,h]),b=r.useCallback(y=>{t(y)},[]),u=r.useMemo(()=>{try{return JSON.parse(x)}catch{return h||{env:{}}}},[x,h]),v=u?.env?.ANTHROPIC_MODEL,C=u?.env?.ANTHROPIC_DEFAULT_OPUS_MODEL,m=u?.env?.ANTHROPIC_DEFAULT_SONNET_MODEL,g=u?.env?.ANTHROPIC_DEFAULT_HAIKU_MODEL,p=r.useMemo(()=>{const y=u?.env||{};return ps.some(f=>{const A=y[f];return A&&Xe(A)})},[u]),O=r.useCallback((y,f)=>{const A={...u?.env||{},[y]:f},L={...u,env:A};t(JSON.stringify(L,null,2))},[u]),P=r.useCallback(y=>{const f=u?.env||{},A={};for(const G of ps){const M=f[G];M&&(A[G]=y?ma(M):Is(M))}const L={...f,...A};delete L.CCS_EXTENDED_CONTEXT;const B={...u,env:L};t(JSON.stringify(B,null,2))},[u]),k=r.useCallback(y=>{const f={...u?.env||{},...y},A={...u,env:f};t(JSON.stringify(A,null,2))},[u]),_=r.useMemo(()=>{try{return JSON.parse(x),!0}catch{return!1}},[x]),w=r.useMemo(()=>a===null?!1:a!==JSON.stringify(h,null,2),[a,h]),E=r.useMemo(()=>pa(u),[u]),N=Bs({mutationFn:async()=>{const y=JSON.parse(x),f=await fetch(`/api/settings/${s}`,{method:"PUT",headers:{"Content-Type":"application/json"},body:JSON.stringify({settings:y,expectedMtime:l?.mtime})});if(f.status===409)throw new Error("CONFLICT");if(!f.ok)throw new Error("Failed to save");return f.json()},onSuccess:y=>{o.invalidateQueries({queryKey:["settings",s]}),t(null),y?.warning?K.success("Settings saved",{description:y.warning}):K.success("Settings saved")},onError:y=>{y.message==="CONFLICT"?i(!0):K.error(y.message)}}),F=async y=>{i(!1),y?(await j(),N.mutate()):t(null)};return{data:l,isLoading:c,refetch:j,rawJsonContent:x,rawJsonEdits:a,isRawJsonValid:_,hasChanges:w,currentSettings:u,currentModel:v,opusModel:C,sonnetModel:m,haikuModel:g,extendedContextEnabled:p,toggleExtendedContext:P,handleRawJsonChange:b,updateEnvValue:O,updateEnvValues:k,saveMutation:{mutate:()=>N.mutate(),isPending:N.isPending},conflictDialog:n,setConflictDialog:i,handleConflictResolve:F,missingRequiredFields:E}}const ga=/-(medium|high|xhigh)$/i;function fa(s){if(!s)return;const a=s.trim().match(ga);if(a?.[1])return a[1].toLowerCase()}function Oe(s){if(!s)return null;const a=fa(s);return a?{label:`Pinned ${a}`,explicit:!0}:{label:"Auto effort",explicit:!1}}function ne({label:s,description:a,value:t,onChange:n,catalog:i,allModels:o,disabled:l}){const c=new Set(i?.models.map(x=>x.id)||[]),j=i?.provider==="codex",h=j?Oe(t):null;return e.jsxs("div",{className:"space-y-1.5",children:[e.jsxs("div",{children:[e.jsx("label",{className:"text-xs font-medium",children:s}),a&&e.jsx("p",{className:"text-[10px] text-muted-foreground",children:a})]}),e.jsxs(Ie,{value:t||"",onValueChange:n,disabled:l,children:[e.jsx(Fe,{className:"h-9",children:e.jsx(Ue,{placeholder:"Select model",children:t&&e.jsxs("div",{className:"flex items-center gap-2",children:[e.jsx("span",{className:"truncate font-mono text-xs",children:t}),h&&e.jsx(U,{variant:h.explicit?"secondary":"outline",className:"text-[9px] h-4 px-1 uppercase",children:h.label})]})})}),e.jsxs(Ke,{className:"max-h-[300px]",children:[i&&i.models.length>0&&e.jsxs(is,{children:[e.jsx(rs,{className:"text-xs text-primary",children:"Recommended"}),i.models.map(x=>{const b=j?Oe(x.id):null;return e.jsx(he,{value:x.id,children:e.jsxs("div",{className:"flex items-center gap-2",children:[e.jsx("span",{className:"truncate font-mono text-xs",children:x.id}),x.tier==="paid"&&e.jsx(U,{variant:"outline",className:"text-[9px] h-4 px-1",children:"PAID"}),b&&e.jsx(U,{variant:b.explicit?"secondary":"outline",className:"text-[9px] h-4 px-1 uppercase",children:b.label}),t===x.id&&e.jsx(se,{className:"w-3 h-3 text-primary ml-auto"})]})},x.id)})]}),o.length>0&&e.jsxs(is,{children:[e.jsxs(rs,{className:"text-xs text-muted-foreground",children:["All Models (",o.length,")"]}),o.filter(x=>!c.has(x.id)).map(x=>{const b=j?Oe(x.id):null;return e.jsx(he,{value:x.id,children:e.jsxs("div",{className:"flex items-center gap-2",children:[e.jsx("span",{className:"truncate font-mono text-xs",children:x.id}),b&&e.jsx(U,{variant:b.explicit?"secondary":"outline",className:"text-[9px] h-4 px-1 uppercase",children:b.label}),t===x.id&&e.jsx(se,{className:"w-3 h-3 text-primary ml-auto"})]})},x.id)})]}),(!i||i.models.length===0)&&o.length===0&&e.jsx("div",{className:"py-2 px-3 text-xs text-muted-foreground",children:"No models available"})]})]})]})}function ja({open:s,onClose:a,currentValues:t,onApply:n,onSave:i,isSaving:o,catalog:l,allModels:c}){const[j,h]=r.useState(t),[x,b]=r.useState(""),u=v=>{v?(h(t),b("")):a()};return e.jsx(qe,{open:s,onOpenChange:u,children:e.jsxs(He,{className:"sm:max-w-md",children:[e.jsx(Be,{children:e.jsxs(Ge,{className:"flex items-center gap-2",children:[e.jsx(fe,{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(W,{htmlFor:"preset-name",children:"Preset Name (optional)"}),e.jsx(re,{id:"preset-name",value:x,onChange:v=>b(v.target.value),placeholder:"e.g., My Custom Config",className:"text-sm"})]}),e.jsx(We,{}),l?.provider==="codex"&&e.jsxs("p",{className:"text-[11px] text-muted-foreground rounded-md border bg-muted/30 px-2.5 py-2",children:["Codex tip: suffixes ",e.jsx("code",{children:"-medium"}),", ",e.jsx("code",{children:"-high"}),", and ",e.jsx("code",{children:"-xhigh"})," ","pin effort. Unsuffixed models use Thinking settings."]}),e.jsx(ne,{label:"Default Model",description:"Used when no specific tier is requested",value:j.default,onChange:v=>h({...j,default:v}),catalog:l,allModels:c}),e.jsx(ne,{label:"Opus (Most capable)",description:"For complex reasoning tasks",value:j.opus,onChange:v=>h({...j,opus:v}),catalog:l,allModels:c}),e.jsx(ne,{label:"Sonnet (Balanced)",description:"Balance of speed and capability",value:j.sonnet,onChange:v=>h({...j,sonnet:v}),catalog:l,allModels:c}),e.jsx(ne,{label:"Haiku (Fast)",description:"Quick responses for simple tasks",value:j.haiku,onChange:v=>h({...j,haiku:v}),catalog:l,allModels:c})]}),e.jsxs(et,{className:"gap-2 sm:gap-0",children:[e.jsx(R,{variant:"outline",onClick:a,children:"Cancel"}),i&&e.jsxs(R,{variant:"secondary",onClick:()=>i(j,x||void 0),disabled:o||!x.trim(),children:[o?e.jsx(J,{className:"w-4 h-4 mr-1 animate-spin"}):e.jsx(ke,{className:"w-4 h-4 mr-1"}),"Save Preset"]}),e.jsxs(R,{onClick:()=>n(j,x||void 0),children:[e.jsx(je,{className:"w-4 h-4 mr-1"}),"Apply Preset"]})]})]})})}function ue({label:s,command:a}){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:a}),e.jsx(Cs,{value:a,size:"icon",className:"h-6 w-6"})]})]})}function va({provider:s,displayName:a,defaultTarget:t,data:n,authStatus:i}){const o=t||"claude",l=o==="droid";return e.jsx($e,{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(Ms,{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:a})]}),n&&e.jsxs(e.Fragment,{children:[e.jsxs("div",{className:"grid grid-cols-[100px_1fr] gap-2 text-sm items-center",children:[e.jsx("span",{className:"font-medium text-muted-foreground",children:"File Path"}),e.jsxs("div",{className:"flex items-center gap-2 min-w-0",children:[e.jsx("code",{className:"bg-muted px-1.5 py-0.5 rounded text-xs break-all",children:n.path}),e.jsx(Cs,{value:n.path,size:"icon",className:"h-5 w-5"})]})]}),e.jsxs("div",{className:"grid grid-cols-[100px_1fr] gap-2 text-sm items-center",children:[e.jsx("span",{className:"font-medium text-muted-foreground",children:"Last Modified"}),e.jsx("span",{className:"text-xs",children:new Date(n.mtime).toLocaleString()})]})]}),e.jsxs("div",{className:"grid grid-cols-[100px_1fr] gap-2 text-sm items-center",children:[e.jsx("span",{className:"font-medium text-muted-foreground",children:"Status"}),i.authenticated?e.jsxs(U,{variant:"outline",className:"w-fit text-green-600 border-green-200 bg-green-50",children:[e.jsx(Ft,{className:"w-3 h-3 mr-1"}),"Authenticated"]}):e.jsx(U,{variant:"outline",className:"w-fit text-muted-foreground",children:"Not connected"})]}),e.jsxs("div",{className:"grid grid-cols-[100px_1fr] gap-2 text-sm items-center",children:[e.jsx("span",{className:"font-medium text-muted-foreground",children:"Default Target"}),e.jsx("span",{className:"font-mono",children:o})]})]})]}),e.jsxs("div",{children:[e.jsx("h3",{className:"text-sm font-medium mb-3",children:"Quick Usage"}),e.jsxs("div",{className:"space-y-3 bg-card rounded-lg border p-4 shadow-sm",children:[e.jsx(ue,{label:"Run with prompt",command:`ccs ${s} "your prompt"`}),e.jsx(ue,{label:l?"Droid alias (explicit)":"Run on Droid",command:l?`ccsd ${s} "your prompt"`:`ccs ${s} --target droid "your prompt"`}),e.jsx(ue,{label:l?"Override to Claude":"Override target",command:`ccs ${s} --target claude "your prompt"`}),e.jsx(ue,{label:"Change model",command:`ccs ${s} --config`}),e.jsx(ue,{label:"Add account",command:`ccs ${s} --add`}),e.jsx(ue,{label:"List accounts",command:`ccs ${s} --accounts`})]})]})]})})}const Na={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 Ze({provider:s,className:a,size:t="md"}){const n=st(s),i=Na[t],o=tt(s);return e.jsx("div",{className:H("flex items-center justify-center rounded-md",o&&(at(s)?"bg-gray-900 p-1":"bg-white p-1"),i.container,a),children:o?e.jsx("img",{src:o,alt:`${s} logo`,className:H(i.icon,"object-contain")}):e.jsx("span",{className:H("font-semibold",n.textClass,i.text),children:n.letter})})}function ba({displayName:s,logoProvider:a,provider:t,data:n,isLoading:i,hasChanges:o,isRawJsonValid:l,isSaving:c,isRemoteMode:j,port:h,onRefetch:x,onSave:b}){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(Ze,{provider:a||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}),j&&e.jsxs(U,{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(Ts,{className:"w-3 h-3"}),"Remote"]}),h&&e.jsxs(U,{variant:"outline",className:"text-xs gap-1 font-mono",children:[e.jsx(Ut,{className:"w-3 h-3"}),":",h]}),!j&&n?.path&&e.jsx(U,{variant:"outline",className:"text-xs",children:n.path.replace(/^.*[\\/]/,"")})]}),j?e.jsx("p",{className:"text-xs text-blue-600 dark:text-blue-400 mt-0.5",children:"Traffic auto-routed to remote server"}):n&&e.jsxs("p",{className:"text-xs text-muted-foreground mt-0.5",children:["Last modified: ",new Date(n.mtime).toLocaleString()]})]})]}),e.jsxs("div",{className:"flex items-center gap-2",children:[e.jsx(R,{variant:"ghost",size:"sm",onClick:x,disabled:i,children:e.jsx(Ve,{className:`w-4 h-4 ${i?"animate-spin":""}`})}),e.jsx(R,{size:"sm",onClick:b,disabled:c||!o||!l,children:c?e.jsxs(e.Fragment,{children:[e.jsx(J,{className:"w-4 h-4 mr-1 animate-spin"}),"Saving..."]}):e.jsxs(e.Fragment,{children:[e.jsx(Kt,{className:"w-4 h-4 mr-1"}),"Save"]})})]})]})}function wa({model:s,provider:a,enabled:t,onToggle:n,disabled:i,className:o}){if(!s?.extendedContext)return null;const l=ua(s.id);return e.jsxs("div",{className:H("rounded-lg border p-3 space-y-2",t?"border-primary/50 bg-primary/5":"border-border bg-muted/30",o),children:[e.jsxs("div",{className:"flex items-center justify-between",children:[e.jsxs("div",{className:"flex items-center gap-2",children:[e.jsx(je,{className:H("w-4 h-4",t?"text-primary":"text-muted-foreground")}),e.jsx("span",{className:"text-sm font-medium",children:"Extended Context"}),e.jsx(U,{variant:t?"default":"secondary",className:"text-[10px] h-5 px-1.5",children:"1M tokens"})]}),e.jsx(Ds,{checked:t,onCheckedChange:n,disabled:i})]}),e.jsxs("div",{className:"flex items-start gap-2 text-xs text-muted-foreground",children:[e.jsx(Ms,{className:"w-3.5 h-3.5 mt-0.5 shrink-0"}),e.jsxs("div",{className:"space-y-1",children:[e.jsx("p",{children:"Enables 1M token context window instead of default 200K."}),e.jsx("p",{className:"text-[10px]",children:l?e.jsxs("span",{className:"text-primary",children:["Auto-enabled for ",a," Gemini models"]}):e.jsxs("span",{children:["Opt-in for ",a," Claude models via --1m flag"]})}),t&&e.jsx("p",{className:"text-amber-600 dark:text-amber-500",children:"Note: 2x input pricing applies for tokens beyond 200K"})]})]})]})}function ya({catalog:s,savedPresets:a,currentModel:t,opusModel:n,sonnetModel:i,haikuModel:o,providerModels:l,provider:c,extendedContextEnabled:j,onExtendedContextToggle:h,onApplyPreset:x,onUpdateEnvValue:b,onOpenCustomPreset:u,onDeletePreset:v,isDeletePending:C}){const m=s&&s.models.length>0||a.length>0,g=r.useMemo(()=>{if(!s||!t)return;const p=Is(t);return s.models.find(O=>O.id===p)},[s,t]);return e.jsxs(e.Fragment,{children:[m&&e.jsxs("div",{children:[e.jsxs("h3",{className:"text-sm font-medium mb-2 flex items-center gap-2",children:[e.jsx(fe,{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(p=>e.jsxs(R,{variant:"outline",size:"sm",className:"text-xs h-7 gap-1",onClick:()=>{const O=p.presetMapping||{default:p.id,opus:p.id,sonnet:p.id,haiku:p.id};x({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(je,{className:"w-3 h-3"}),p.name]},p.id)),a.map(p=>e.jsxs("div",{className:"group relative",children:[e.jsxs(R,{variant:"secondary",size:"sm",className:"text-xs h-7 gap-1 pr-6",onClick:()=>{x({ANTHROPIC_MODEL:p.default,ANTHROPIC_DEFAULT_OPUS_MODEL:p.opus,ANTHROPIC_DEFAULT_SONNET_MODEL:p.sonnet,ANTHROPIC_DEFAULT_HAIKU_MODEL:p.haiku})},children:[e.jsx(ke,{className:"w-3 h-3 fill-current"}),p.name]}),e.jsx(R,{variant:"ghost",size:"icon",className:"absolute right-0 top-0 h-7 w-5 opacity-0 group-hover:opacity-100 hover:text-destructive",onClick:O=>{O.stopPropagation(),v(p.name)},disabled:C,children:e.jsx(Je,{className:"w-3 h-3"})})]},p.name)),e.jsxs(R,{variant:"outline",size:"sm",className:"text-xs h-7 gap-1 border-primary/50 text-primary hover:bg-primary/10 hover:border-primary",onClick:u,children:[e.jsx(Os,{className:"w-3 h-3"}),"Custom"]})]})]}),e.jsx(We,{}),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"}),c==="codex"&&e.jsxs("p",{className:"text-[11px] text-muted-foreground mb-3 rounded-md border bg-muted/30 px-2.5 py-2",children:["Codex tip: suffixes ",e.jsx("code",{children:"-medium"}),", ",e.jsx("code",{children:"-high"}),", and ",e.jsx("code",{children:"-xhigh"})," ","pin reasoning effort. Unsuffixed models use Thinking settings."]}),e.jsxs("div",{className:"space-y-4",children:[e.jsx(ne,{label:"Default Model",description:"Used when no specific tier is requested",value:t,onChange:p=>b("ANTHROPIC_MODEL",p),catalog:s,allModels:l}),g?.extendedContext&&h&&e.jsx(wa,{model:g,provider:c,enabled:j??!1,onToggle:h}),e.jsx(ne,{label:"Opus (Most capable)",description:"For complex reasoning tasks",value:n,onChange:p=>b("ANTHROPIC_DEFAULT_OPUS_MODEL",p),catalog:s,allModels:l}),e.jsx(ne,{label:"Sonnet (Balanced)",description:"Balance of speed and capability",value:i,onChange:p=>b("ANTHROPIC_DEFAULT_SONNET_MODEL",p),catalog:s,allModels:l}),e.jsx(ne,{label:"Haiku (Fast)",description:"Quick responses for simple tasks",value:o,onChange:p=>b("ANTHROPIC_DEFAULT_HAIKU_MODEL",p),catalog:s,allModels:l})]})]})]})}function hs(s){const a=Math.max(0,Math.min(100,s));return a<=20?"bg-destructive":a<=50?"bg-yellow-500":"bg-green-500"}function gs(s){if(!s)return"";try{const a=new Date(s),n=new Date().getTime()-a.getTime();if(n<0)return"just now";const i=Math.floor(n/(1e3*60)),o=Math.floor(n/(1e3*60*60)),l=Math.floor(n/(1e3*60*60*24));return l>0?`${l}d ago`:o>0?`${o}h ago`:i>0?`${i}m ago`:"just now"}catch{return""}}function ka(s){if(!s)return!1;try{const a=new Date(s);return new Date().getTime()-a.getTime()<3600*1e3}catch{return!1}}function Ca({account:s,onSetDefault:a,onRemove:t,onPauseToggle:n,isRemoving:i,isPausingAccount:o,privacyMode:l,showQuota:c,selectable:j,selected:h,onSelectChange:x}){const b=s.provider.toLowerCase(),u=b==="codex",v=b==="claude"||b==="anthropic",{data:C}=nt(c),{data:m,isLoading:g}=it(b,s.id,c),p=C?.accountStats?.[s.email||s.id]?.lastUsedAt,O=ka(p),P=rt(s.provider,m),k=ot(s.provider,m),_=u&&m&&lt(m)?ct(m.windows):null,w=[{label:"5h",value:_?.fiveHourWindow?.remainingPercent??null},{label:"Weekly",value:_?.weeklyWindow?.remainingPercent??null}].filter(f=>f.value!==null),E=v&&m&&dt(m)?[{label:"5h",value:m.coreUsage?.fiveHour?.remainingPercent??m.windows.find(f=>f.rateLimitType==="five_hour")?.remainingPercent??null},{label:"Weekly",value:m.coreUsage?.weekly?.remainingPercent??m.windows.find(f=>["seven_day","seven_day_opus","seven_day_sonnet","seven_day_oauth_apps","seven_day_cowork"].includes(f.rateLimitType))?.remainingPercent??null}].filter(f=>f.value!==null):[],N=u?w:v?E:[],F=P!==null?pt(P):null,y=F!==null?Number(F):null;return e.jsxs("div",{className:H("flex flex-col gap-2 p-3 rounded-lg border transition-colors overflow-hidden",s.isDefault?"border-primary/30 bg-primary/5":"border-border hover:bg-muted/30",s.paused&&"opacity-75",h&&"ring-2 ring-primary/50 bg-primary/5"),children:[e.jsxs("div",{className:"flex items-center justify-between gap-2",children:[e.jsxs("div",{className:"flex items-center gap-3 min-w-0 flex-1",children:[j&&e.jsx("button",{type:"button",onClick:()=>x?.(!h),className:H("flex items-center justify-center w-5 h-5 rounded border-2 transition-colors shrink-0",h?"bg-primary border-primary text-primary-foreground":"border-muted-foreground/30 hover:border-primary/50"),"aria-label":h?"Deselect account":"Select account",children:h&&e.jsx(se,{className:"w-3 h-3"})}),n&&e.jsx(oe,{children:e.jsxs(le,{children:[e.jsx(ce,{asChild:!0,children:e.jsx(R,{variant:"ghost",size:"icon",className:"h-7 w-7 shrink-0",onClick:()=>n(!s.paused),disabled:o,children:o?e.jsx(J,{className:"w-4 h-4 animate-spin"}):s.paused?e.jsx(Rs,{className:"w-4 h-4 text-emerald-500"}):e.jsx(_e,{className:"w-4 h-4 text-muted-foreground hover:text-foreground"})})}),e.jsx(de,{side:"top",children:s.paused?"Resume account":"Pause account"})]})}),e.jsxs("div",{className:"relative shrink-0",children:[e.jsx("div",{className:H("flex items-center justify-center w-8 h-8 rounded-full",s.isDefault?"bg-primary/10":"bg-muted"),children:e.jsx(xe,{className:"w-4 h-4"})}),s.tier&&s.tier!=="unknown"&&s.tier!=="free"&&e.jsx("span",{className:H("absolute -bottom-0.5 -right-0.5 text-[7px] font-bold uppercase px-1 py-px rounded","ring-1 ring-background",s.tier==="ultra"?"bg-violet-500/20 text-violet-600 dark:bg-violet-500/30 dark:text-violet-300":"bg-yellow-500/20 text-yellow-700 dark:bg-yellow-500/25 dark:text-yellow-400"),children:s.tier==="ultra"?"U":"P"})]}),e.jsxs("div",{className:"min-w-0 flex-1",children:[e.jsxs("div",{className:"flex items-center gap-2",children:[e.jsx("span",{className:H("font-medium text-sm truncate",l&&ye),children:s.email||s.id}),s.isDefault&&e.jsxs(U,{variant:"secondary",className:"text-[10px] h-4 px-1.5 gap-0.5",children:[e.jsx(ke,{className:"w-2.5 h-2.5 fill-current"}),"Default"]}),s.paused&&e.jsxs(U,{variant:"outline",className:"text-[10px] h-4 px-1.5 border-yellow-500 text-yellow-600",children:[e.jsx(_e,{className:"w-2 h-2 mr-0.5"}),"Paused"]})]}),s.provider==="agy"&&e.jsx("div",{className:"flex items-center gap-1.5 mt-1",children:s.projectId?e.jsx(oe,{children:e.jsxs(le,{children:[e.jsx(ce,{asChild:!0,children:e.jsxs("div",{className:"flex items-center gap-1 text-xs text-muted-foreground",children:[e.jsx(qt,{className:"w-3 h-3","aria-hidden":"true"}),e.jsx("span",{className:H("font-mono max-w-[180px] truncate",l&&ye),title:s.projectId,children:s.projectId})]})}),e.jsx(de,{side:"bottom",children:e.jsx("p",{className:"text-xs",children:"GCP Project ID (read-only)"})})]})}):e.jsx(oe,{children:e.jsxs(le,{children:[e.jsx(ce,{asChild:!0,children:e.jsxs("div",{className:"flex items-center gap-1 text-xs text-amber-600 dark:text-amber-500",children:[e.jsx(ze,{className:"w-3 h-3","aria-label":"Warning"}),e.jsx("span",{children:"Project ID: N/A"})]})}),e.jsx(de,{side:"bottom",className:"max-w-[250px]",children:e.jsxs("div",{className:"text-xs space-y-1",children:[e.jsx("p",{className:"font-medium text-amber-600",children:"Missing Project ID"}),e.jsx("p",{children:"This may cause errors. Remove the account and re-add it to fetch the project ID."})]})})]})})}),s.lastUsedAt&&e.jsxs("div",{className:"flex items-center gap-1 text-xs text-muted-foreground mt-0.5",children:[e.jsx(ds,{className:"w-3 h-3"}),"Last used: ",new Date(s.lastUsedAt).toLocaleDateString()]})]})]}),e.jsxs(ut,{children:[e.jsx(mt,{asChild:!0,children:e.jsx(R,{variant:"ghost",size:"icon",className:"h-7 w-7 shrink-0",children:e.jsx(Ht,{className:"w-4 h-4"})})}),e.jsxs(xt,{align:"end",children:[!s.isDefault&&e.jsxs(os,{onClick:a,children:[e.jsx(ke,{className:"w-4 h-4 mr-2"}),"Set as default"]}),e.jsxs(os,{className:"text-destructive focus:text-destructive",onClick:t,disabled:i,children:[e.jsx(Es,{className:"w-4 h-4 mr-2"}),i?"Removing...":"Remove account"]})]})]})]}),c&&e.jsx("div",{className:"pl-11",children:g?e.jsxs("div",{className:"flex items-center gap-2 text-xs text-muted-foreground",children:[e.jsx(J,{className:"w-3 h-3 animate-spin"}),e.jsx("span",{children:"Loading quota..."})]}):y!==null?e.jsxs("div",{className:"space-y-1.5",children:[e.jsx("div",{className:"flex items-center gap-1.5 text-xs",children:O?e.jsxs(e.Fragment,{children:[e.jsx(Bt,{className:"w-3 h-3 text-emerald-500"}),e.jsxs("span",{className:"text-emerald-600 dark:text-emerald-400",children:["Active · ",gs(p)]})]}):p?e.jsxs(e.Fragment,{children:[e.jsx(ds,{className:"w-3 h-3 text-muted-foreground"}),e.jsxs("span",{className:"text-muted-foreground",children:["Last used ",gs(p)]})]}):e.jsxs(e.Fragment,{children:[e.jsx(us,{className:"w-3 h-3 text-muted-foreground"}),e.jsx("span",{className:"text-muted-foreground",children:"Not used yet"})]})}),e.jsx(oe,{children:e.jsxs(le,{children:[e.jsx(ce,{asChild:!0,children:N.length>0?e.jsx("div",{className:"space-y-1.5",children:N.map(f=>e.jsxs("div",{className:"flex items-center gap-2",children:[e.jsx("span",{className:"w-10 text-[10px] text-muted-foreground",children:f.label}),e.jsx(Re,{value:Math.max(0,Math.min(100,f.value)),className:"h-2 flex-1",indicatorClassName:hs(f.value)}),e.jsxs("span",{className:"text-xs font-medium w-10 text-right",children:[f.value,"%"]})]},f.label))}):e.jsxs("div",{className:"flex items-center gap-2",children:[e.jsx(Re,{value:Math.max(0,Math.min(100,y)),className:"h-2 flex-1",indicatorClassName:hs(y)}),e.jsxs("span",{className:"text-xs font-medium w-10 text-right",children:[F,"%"]})]})}),e.jsx(de,{side:"bottom",className:"max-w-xs",children:e.jsx(ht,{quota:m,resetTime:k})})]})})]}):m?.success?e.jsx("div",{className:"flex items-center gap-1.5",children:e.jsxs(U,{variant:"outline",className:"text-[10px] h-5 px-2 gap-1 border-muted-foreground/50 text-muted-foreground",children:[e.jsx(us,{className:"w-3 h-3"}),"No limits"]})}):m?.needsReauth?e.jsx(oe,{children:e.jsxs(le,{children:[e.jsx(ce,{asChild:!0,children:e.jsx("div",{className:"flex items-center gap-1.5",children:e.jsxs(U,{variant:"outline",className:"text-[10px] h-5 px-2 gap-1 border-amber-500/50 text-amber-600 dark:text-amber-400",children:[e.jsx(Gt,{className:"w-3 h-3"}),"Reauth"]})})}),e.jsx(de,{side:"bottom",className:"max-w-[220px]",children:e.jsx("p",{className:"text-xs",children:m.error?.includes("No refresh token")?"No refresh token available. Remove and re-add account to fix.":m.error?.includes("refresh")||m.error?.includes("Invalid")?`Auto-refresh failed: ${m.error}`:`Token issue: ${m.error||"Re-authenticate required"}`})})]})}):m?.error||m&&!m.success?e.jsx(oe,{children:e.jsxs(le,{children:[e.jsx(ce,{asChild:!0,children:e.jsx("div",{className:"flex items-center gap-1.5",children:e.jsxs(U,{variant:"outline",className:"text-[10px] h-5 px-2 gap-1 border-muted-foreground/50 text-muted-foreground",children:[e.jsx($t,{className:"w-3 h-3"}),"N/A"]})})}),e.jsx(de,{side:"bottom",children:e.jsx("p",{className:"text-xs",children:m?.error||"Quota information unavailable"})})]})}):null})]})}function Aa({selectedCount:s,onPauseSelected:a,onResumeSelected:t,onClearSelection:n,isPausing:i,isResuming:o}){if(s<1)return null;const l=i||o;return e.jsxs("div",{className:"flex items-center gap-3 p-2 bg-muted/50 rounded-lg border mt-2",children:[e.jsxs("span",{className:"text-sm text-muted-foreground",children:[s," selected"]}),e.jsx(R,{variant:"ghost",size:"sm",className:"text-xs h-6 px-2",onClick:n,disabled:l,children:"Clear"}),e.jsxs("div",{className:"flex gap-2 ml-auto",children:[e.jsxs(R,{size:"sm",variant:"outline",className:"h-7 text-xs gap-1",onClick:a,disabled:l,children:[i?e.jsx(J,{className:"w-3 h-3 animate-spin"}):e.jsx(_e,{className:"w-3 h-3"}),"Pause Selected"]}),e.jsxs(R,{size:"sm",variant:"outline",className:"h-7 text-xs gap-1",onClick:t,disabled:l,children:[o?e.jsx(J,{className:"w-3 h-3 animate-spin"}):e.jsx(Rs,{className:"w-3 h-3"}),"Resume Selected"]})]})]})}function Sa({accounts:s,onAddAccount:a,onSetDefault:t,onRemoveAccount:n,onPauseToggle:i,onSoloMode:o,onBulkPause:l,onBulkResume:c,isRemovingAccount:j,isPausingAccount:h,isSoloingAccount:x,isBulkPausing:b,isBulkResuming:u,privacyMode:v,showQuota:C,isKiro:m,kiroNoIncognito:g,onKiroNoIncognitoChange:p,kiroSettingsLoading:O}){const[P,k]=r.useState(new Set),_=r.useMemo(()=>new Set(s.map(T=>T.id)),[s]),w=r.useMemo(()=>new Set([...P].filter(T=>_.has(T))),[P,_]),E=!!(l&&c),N=w.size,F=s.length>0&&w.size===s.length,y=w.size>0&&w.size<s.length,f=r.useCallback(T=>{k(I=>{const $=new Set(I);return $.has(T)?$.delete(T):$.add(T),$})},[]),A=r.useCallback(()=>{k(new Set(s.map(T=>T.id)))},[s]),L=r.useCallback(()=>{k(new Set)},[]),B=r.useCallback(()=>{F?L():A()},[F,A,L]),G=r.useCallback(()=>{l&&w.size>0&&(l(Array.from(w)),k(new Set))},[l,w]),M=r.useCallback(()=>{c&&w.size>0&&(c(Array.from(w)),k(new Set))},[c,w]);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&&s.length>0&&e.jsx(we,{checked:F,onCheckedChange:B,"aria-label":"Select all accounts",className:y?"data-[state=checked]:bg-primary/50":"",...y?{"data-state":"indeterminate"}:{}}),e.jsx(xe,{className:"w-4 h-4"}),"Accounts",s.length>0&&e.jsx(U,{variant:"secondary",className:"text-xs",children:s.length})]}),e.jsxs(R,{variant:"default",size:"sm",className:"h-7 text-xs gap-1",onClick:a,children:[e.jsx(Os,{className:"w-3 h-3"}),"Add"]})]}),E&&N>0&&e.jsx(Aa,{selectedCount:N,onPauseSelected:G,onResumeSelected:M,onClearSelection:L,isPausing:!!b,isResuming:!!u}),s.length>0?e.jsx("div",{className:"space-y-2",children:s.map(T=>e.jsx(Ca,{account:T,onSetDefault:()=>t(T.id),onRemove:()=>n(T.id),onPauseToggle:i?I=>i(T.id,I):void 0,onSoloMode:o?()=>o(T.id):void 0,isRemoving:j,isPausingAccount:h,isSoloingAccount:x,privacyMode:v,showQuota:C,selectable:E,selected:w.has(T.id),onSelectChange:()=>f(T.id)},T.id))}):e.jsxs("div",{className:"py-6 text-center text-muted-foreground bg-muted/30 rounded-lg border border-dashed",children:[e.jsx(xe,{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"})]}),m&&p&&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(Ts,{className:"w-3.5 h-3.5"}),e.jsx("span",{children:"Use incognito"})]}),e.jsx(Ds,{checked:!g,onCheckedChange:T=>p(!T),disabled:O,className:"scale-90"})]})})]})}function Pa({provider:s,catalog:a,savedPresets:t,currentModel:n,opusModel:i,sonnetModel:o,haikuModel:l,providerModels:c,extendedContextEnabled:j,onExtendedContextToggle:h,onApplyPreset:x,onUpdateEnvValue:b,onOpenCustomPreset:u,onDeletePreset:v,isDeletePending:C,accounts:m,onAddAccount:g,onSetDefault:p,onRemoveAccount:O,onPauseToggle:P,onSoloMode:k,onBulkPause:_,onBulkResume:w,isRemovingAccount:E,isPausingAccount:N,isSoloingAccount:F,isBulkPausing:y,isBulkResuming:f,privacyMode:A,isRemoteMode:L}){const B=s.toLowerCase(),G=(gt.includes(B)||["anthropic","antigravity","gemini-cli","copilot","github-copilot"].includes(B))&&!L,M=s==="kiro",[T,I]=r.useState(!0),[$,Q]=r.useState(!0),[Y,X]=r.useState(!1),d=r.useCallback(async()=>{if(M)try{Q(!0);const Z=(await Ne.config.get()).cliproxy;I(Z?.kiro_no_incognito??!0)}catch{I(!0)}finally{Q(!1)}},[M]),D=r.useCallback(async V=>{I(V),X(!0);try{const Z=await Ne.config.get(),pe=Z.cliproxy??{};await Ne.config.update({...Z,cliproxy:{...pe,kiro_no_incognito:V}})}catch{I(!V)}finally{X(!1)}},[]);return r.useEffect(()=>{d()},[d]),e.jsx($e,{className:"flex-1",children:e.jsxs("div",{className:"p-4 space-y-6",children:[e.jsx(ya,{catalog:a,savedPresets:t,currentModel:n,opusModel:i,sonnetModel:o,haikuModel:l,providerModels:c,provider:s,extendedContextEnabled:j,onExtendedContextToggle:h,onApplyPreset:x,onUpdateEnvValue:b,onOpenCustomPreset:u,onDeletePreset:v,isDeletePending:C}),e.jsx(We,{}),e.jsx(Sa,{accounts:m,onAddAccount:g,onSetDefault:p,onRemoveAccount:O,onPauseToggle:P,onSoloMode:k,onBulkPause:_,onBulkResume:w,isRemovingAccount:E,isPausingAccount:N,isSoloingAccount:F,isBulkPausing:y,isBulkResuming:f,privacyMode:A,showQuota:G,isKiro:M,kiroNoIncognito:T,onKiroNoIncognitoChange:D,kiroSettingsLoading:$||Y})]})})}function fs({provider:s,displayName:a,authStatus:t,catalog:n,logoProvider:i,baseProvider:o,isRemoteMode:l,port:c,defaultTarget:j,onAddAccount:h,onSetDefault:x,onRemoveAccount:b,onPauseToggle:u,onSoloMode:v,onBulkPause:C,onBulkResume:m,isRemovingAccount:g,isPausingAccount:p,isSoloingAccount:O,isBulkPausing:P,isBulkResuming:k}){const[_,w]=r.useState(!1),{privacyMode:E}=ws(),{data:N}=ft(),{data:F}=jt(s),y=vt(),f=Nt(),A=F?.presets||[],L=o||s,B=r.useMemo(()=>{if(!N?.models)return[];const ae={gemini:["google"],agy:["antigravity"],codex:["openai"],qwen:["alibaba","qwen"],iflow:["iflow"],kiro:["kiro","aws"],ghcp:["github","copilot"],kimi:["kimi","moonshot"]}[L.toLowerCase()]||[L.toLowerCase()];return N.models.filter(ts=>ae.some(Hs=>ts.owned_by.toLowerCase().includes(Hs)))},[N,L]),G=(o||s).toLowerCase(),{data:M,isLoading:T,refetch:I,rawJsonContent:$,rawJsonEdits:Q,isRawJsonValid:Y,hasChanges:X,currentModel:d,opusModel:D,sonnetModel:V,haikuModel:Z,extendedContextEnabled:pe,toggleExtendedContext:Ce,handleRawJsonChange:Ae,updateEnvValue:Se,updateEnvValues:z,saveMutation:S,conflictDialog:te,handleConflictResolve:ee,missingRequiredFields:es}=ha(s),ve=r.useMemo(()=>(t.accounts||[]).map(q=>({...q,provider:q.provider||o||s})),[t.accounts,o,s]),{data:Fs}=js({queryKey:["auth-tokens-raw"],queryFn:async()=>{const q=await fetch("/api/settings/auth/tokens/raw");return q.ok?q.json():{apiKey:{value:"ccs-internal-managed"}}},staleTime:6e4}),ss=Fs?.apiKey?.value??"ccs-internal-managed",Us=q=>{z({ANTHROPIC_BASE_URL:`http://127.0.0.1:${c??Ee}/api/provider/${G}`,ANTHROPIC_AUTH_TOKEN:ss,...q}),K.success(`Applied "${q.ANTHROPIC_MODEL?.split("/").pop()||"preset"}" preset`)},Ks=(q,ae)=>{z({ANTHROPIC_BASE_URL:`http://127.0.0.1:${c??Ee}/api/provider/${G}`,ANTHROPIC_AUTH_TOKEN:ss,ANTHROPIC_MODEL:q.default,ANTHROPIC_DEFAULT_OPUS_MODEL:q.opus,ANTHROPIC_DEFAULT_SONNET_MODEL:q.sonnet,ANTHROPIC_DEFAULT_HAIKU_MODEL:q.haiku}),K.success(`Applied ${ae?`"${ae}"`:"custom"} preset`),w(!1)},qs=(q,ae)=>{if(!ae){K.error("Please enter a preset name to save");return}y.mutate({profile:s,data:{name:ae,...q}}),w(!1)};return e.jsxs("div",{className:"flex-1 flex flex-col overflow-hidden",children:[e.jsx(ba,{provider:s,displayName:a,logoProvider:i,data:M,isLoading:T,hasChanges:X,isRawJsonValid:Y,isSaving:S.isPending,isRemoteMode:l,port:c,onRefetch:I,onSave:()=>S.mutate()}),T?e.jsxs("div",{className:"flex-1 flex items-center justify-center",children:[e.jsx(J,{className:"w-8 h-8 animate-spin text-muted-foreground"}),e.jsx("span",{className:"ml-3 text-muted-foreground",children:"Loading settings..."})]}):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(bt,{defaultValue:"config",className:"h-full flex flex-col",children:[e.jsx("div",{className:"px-4 pt-4 shrink-0",children:e.jsxs(wt,{className:"w-full",children:[e.jsx(ls,{value:"config",className:"flex-1",children:"Model Config"}),e.jsx(ls,{value:"info",className:"flex-1",children:"Info & Usage"})]})}),e.jsxs("div",{className:"flex-1 overflow-hidden flex flex-col",children:[e.jsx(cs,{value:"config",className:"flex-1 mt-0 border-0 p-0 data-[state=inactive]:hidden flex flex-col overflow-hidden",children:e.jsx(Pa,{provider:s,catalog:n,savedPresets:A,currentModel:d,opusModel:D,sonnetModel:V,haikuModel:Z,providerModels:B,extendedContextEnabled:pe,onExtendedContextToggle:Ce,onApplyPreset:Us,onUpdateEnvValue:Se,onOpenCustomPreset:()=>w(!0),onDeletePreset:q=>f.mutate({profile:s,name:q}),isDeletePending:f.isPending,accounts:ve,onAddAccount:h,onSetDefault:x,onRemoveAccount:b,onPauseToggle:u,onSoloMode:v,onBulkPause:C,onBulkResume:m,isRemovingAccount:g,isPausingAccount:p,isSoloingAccount:O,isBulkPausing:P,isBulkResuming:k,privacyMode:E,isRemoteMode:l})}),e.jsx(cs,{value:"info",className:"h-full mt-0 border-0 p-0 data-[state=inactive]:hidden",children:e.jsx(va,{provider:s,displayName:a,defaultTarget:j,data:M,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(Qt,{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(yt,{rawJsonContent:$,isRawJsonValid:Y,rawJsonEdits:Q,onRawJsonChange:Ae,profileEnv:M?.settings?.env,missingRequiredFields:es})]})]}),e.jsx(Wt,{open:te,title:"File Modified Externally",description:"This settings file was modified by another process. Overwrite with your changes or discard?",confirmText:"Overwrite",variant:"destructive",onConfirm:()=>ee(!0),onCancel:()=>ee(!1)}),e.jsx(ja,{open:_,onClose:()=>w(!1),currentValues:{default:d||"",opus:D||"",sonnet:V||"",haiku:Z||""},onApply:Ks,onSave:qs,isSaving:y.isPending,catalog:n,allModels:B})]})}function Ma({status:s,isSelected:a,onSelect:t}){const n=s.accounts?.length||0;return e.jsxs("button",{className:H("w-full flex items-center gap-3 px-3 py-2.5 rounded-lg transition-colors cursor-pointer text-left",a?"bg-primary/10 border border-primary/20":"hover:bg-muted border border-transparent"),onClick:t,children:[e.jsx(Ze,{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}),n>0&&e.jsx(U,{variant:"secondary",className:"text-[10px] h-4 px-1",children:n})]}),e.jsx("div",{className:"flex items-center gap-1.5 mt-0.5",children:s.authenticated?e.jsxs(e.Fragment,{children:[e.jsx(se,{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(Je,{className:"w-3 h-3 text-muted-foreground"}),e.jsx("span",{className:"text-xs text-muted-foreground",children:"Not connected"})]})})]})]})}function Ta({variant:s,parentAuth:a,isSelected:t,onSelect:n,onDelete:i,isDeleting:o}){return e.jsxs("button",{className:H("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:n,children:[e.jsxs("div",{className:"relative",children:[e.jsx(Ze,{provider:s.provider,size:"sm"}),e.jsx(_s,{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(U,{variant:"outline",className:"text-[9px] h-4 px-1",children:"variant"}),e.jsx(U,{variant:"outline",className:"text-[9px] h-4 px-1 uppercase",children:s.target||"claude"})]}),e.jsx("div",{className:"flex items-center gap-1.5 mt-0.5",children:a?.authenticated?e.jsxs(e.Fragment,{children:[e.jsx(se,{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(Je,{className:"w-3 h-3 text-muted-foreground"}),e.jsx("span",{className:"text-xs text-muted-foreground",children:"Parent not connected"})]})})]}),e.jsx(R,{variant:"ghost",size:"icon",className:"h-6 w-6 opacity-0 group-hover:opacity-100 hover:text-destructive",onClick:l=>{l.stopPropagation(),i()},disabled:o,children:e.jsx(Es,{className:"w-3 h-3"})})]})}function Oa({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(je,{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(R,{onClick:s,className:"gap-2",children:[e.jsx(fe,{className:"w-4 h-4"}),"Quick Setup"]})]})})}function za(){const s=Le(),{data:a,isLoading:t}=bs(),{data:n,isFetching:i}=kt(),{data:o}=Ct(),l=At(),c=St(),j=Pt(),h=Mt(),x=Tt(),b=Ot(),u=Rt(),v=Et(),[C,m]=r.useState(()=>typeof window<"u"?localStorage.getItem("cliproxy-selected-provider"):null),[g,p]=r.useState(null),[O,P]=r.useState(!1),[k,_]=r.useState(null),w=r.useMemo(()=>a?.authStatus||[],[a?.authStatus]),E=a?.source==="remote",N=r.useMemo(()=>n?.variants||[],[n?.variants]),F=d=>{m(d),d&&localStorage.setItem("cliproxy-selected-provider",d)},y=r.useMemo(()=>g?null:C&&w.some(d=>d.provider===C)?C:w.length>0&&(w.find(D=>(D.accounts?.length||0)>0)?.provider||w[0]?.provider)||null,[C,g,w]),f=w.find(d=>d.provider===y),A=N.find(d=>d.name===g),L=A?w.find(d=>d.provider===A.provider):void 0,B=(A?.provider||f?.provider||"").toLowerCase().trim(),G=B==="gemini"||B==="agy",M=()=>{s.invalidateQueries({queryKey:["cliproxy"]}),s.invalidateQueries({queryKey:["cliproxy-auth"]})},T=(d,D,V)=>{j.isPending||h.isPending||(V?j.mutate({provider:d,accountId:D}):h.mutate({provider:d,accountId:D}))},I=(d,D)=>{x.isPending||x.mutate({provider:d,accountId:D})},$=(d,D)=>{b.isPending||b.mutate({provider:d,accountIds:D})},Q=(d,D)=>{u.isPending||u.mutate({provider:d,accountIds:D})},Y=d=>{F(d),p(null)},X=d=>{p(d),F(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(je,{className:"w-5 h-5 text-primary"}),e.jsx("h1",{className:"font-semibold",children:o?.backendLabel??"CLIProxy"})]}),e.jsx(R,{variant:"ghost",size:"icon",className:"h-8 w-8",onClick:M,disabled:i,children:e.jsx(Ve,{className:H("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(R,{variant:"default",size:"sm",className:"w-full gap-2",onClick:()=>P(!0),children:[e.jsx(fe,{className:"w-4 h-4"}),"Quick Setup"]})]}),e.jsx($e,{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(d=>e.jsx(_t,{className:"h-14 w-full rounded-lg"},d))}):e.jsx("div",{className:"space-y-1",children:w.map(d=>e.jsx(Ma,{status:d,isSelected:y===d.provider,onSelect:()=>Y(d.provider)},d.provider))}),N.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(_s,{className:"w-3 h-3"}),"Variants"]}),e.jsx("div",{className:"space-y-1",children:N.map(d=>e.jsx(Ta,{variant:d,parentAuth:w.find(D=>D.provider===d.provider),isSelected:g===d.name,onSelect:()=>X(d.name),onDelete:()=>v.mutate(d.name),isDeleting:v.isPending},d.name))})]})]})}),e.jsx("div",{className:"p-3 border-t",children:e.jsx(Jt,{})}),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:[w.length," provider",w.length!==1?"s":""]}),e.jsxs("span",{className:"flex items-center gap-1",children:[e.jsx(se,{className:"w-3 h-3 text-green-600"}),w.filter(d=>d.authenticated).length," connected"]})]})})]}),e.jsxs("div",{className:"flex-1 flex flex-col min-w-0 bg-background",children:[G&&e.jsx(Ls,{showProxySettingsLink:!0,className:"mx-4 mt-4"}),A&&L?e.jsx(fs,{provider:A.name,displayName:`${A.name} (${A.provider} variant)`,authStatus:L,catalog:ge[A.provider],logoProvider:A.provider,baseProvider:A.provider,defaultTarget:A.target,isRemoteMode:E,port:A.port,onAddAccount:()=>_({provider:A.provider,displayName:L.displayName,isFirstAccount:(L.accounts?.length||0)===0}),onSetDefault:d=>l.mutate({provider:A.provider,accountId:d}),onRemoveAccount:d=>c.mutate({provider:A.provider,accountId:d}),onPauseToggle:(d,D)=>T(A.provider,d,D),onSoloMode:d=>I(A.provider,d),onBulkPause:d=>$(A.provider,d),onBulkResume:d=>Q(A.provider,d),isRemovingAccount:c.isPending,isPausingAccount:j.isPending||h.isPending,isSoloingAccount:x.isPending,isBulkPausing:b.isPending,isBulkResuming:u.isPending}):f?e.jsx(fs,{provider:f.provider,displayName:f.displayName,authStatus:f,catalog:ge[f.provider],isRemoteMode:E,onAddAccount:()=>_({provider:f.provider,displayName:f.displayName,isFirstAccount:(f.accounts?.length||0)===0}),onSetDefault:d=>l.mutate({provider:f.provider,accountId:d}),onRemoveAccount:d=>c.mutate({provider:f.provider,accountId:d}),onPauseToggle:(d,D)=>T(f.provider,d,D),onSoloMode:d=>I(f.provider,d),onBulkPause:d=>$(f.provider,d),onBulkResume:d=>Q(f.provider,d),isRemovingAccount:c.isPending,isPausingAccount:j.isPending||h.isPending,isSoloingAccount:x.isPending,isBulkPausing:b.isPending,isBulkResuming:u.isPending}):e.jsx(Oa,{onSetup:()=>P(!0)})]}),e.jsx(na,{open:O,onClose:()=>P(!1)}),e.jsx(da,{open:k!==null,onClose:()=>_(null),provider:k?.provider||"",displayName:k?.displayName||"",isFirstAccount:k?.isFirstAccount||!1})]})}export{za as CliproxyPage};
@@ -1 +1 @@
1
- import{j as e}from"./radix-ui-DIWAxjEp.js";import{r as s}from"./react-vendor-CNOkPC89.js";import{u as k}from"./tanstack-Hn82hibe.js";import{W as K,aU as M}from"./index-BOyrh__4.js";import{C as P}from"./default-ports-1QQSffYX.js";import{G as F,R as L,a2 as H,a3 as q,K as W,b as G,X as _}from"./icons-D7XDTBCN.js";import"./notifications-B2HqRBj7.js";import"./utils-CzKF5WmX.js";import"./form-utils-Cn_Uld6y.js";import"./code-highlight-BRUf_pqB.js";function z({port:c=P}){const i=s.useRef(null),[$,b]=s.useState(null),[R,E]=s.useState(0),[g,m]=s.useState(null),[I,d]=s.useState(!1),[S,U]=s.useState(!0),{data:j,error:f}=k({queryKey:["cliproxy-server-config"],queryFn:()=>K.cliproxyServer.get(),staleTime:3e4}),{data:y}=k({queryKey:["auth-tokens-raw"],queryFn:async()=>{const t=await fetch(M("/settings/auth/tokens/raw"));if(!t.ok)throw new Error("Failed to fetch auth tokens");return t.json()},staleTime:3e4});s.useEffect(()=>{f&&console.warn("[ControlPanelEmbed] Config fetch failed, using local mode:",f)},[f]);const{managementUrl:n,checkUrl:u,authToken:r,isRemote:l,displayHost:x}=s.useMemo(()=>{const t=j?.remote;if(t?.enabled&&t?.host){const o=t.protocol||"http",a=t.port||(o==="https"?443:P),v=o==="https"&&a===443||o==="http"&&a===80?"":`:${a}`,w=`${o}://${t.host}${v}`;return{managementUrl:`${w}/management.html`,checkUrl:`${w}/`,authToken:t.auth_token||void 0,isRemote:!0,displayHost:`${t.host}${v}`}}const h=y?.managementSecret?.value||"ccs";return{managementUrl:`http://localhost:${c}/management.html`,checkUrl:`http://localhost:${c}/`,authToken:h,isRemote:!1,displayHost:`localhost:${c}`}},[j,y,c]),p=$===n,N=!p;s.useEffect(()=>{const t=new AbortController,h=async()=>{try{(await fetch(u,{signal:t.signal})).ok?(d(!0),m(null)):(d(!1),m(l?`Remote CLIProxy at ${x} returned an error`:"CLIProxy returned an error"))}catch(a){if(a instanceof Error&&a.name==="AbortError")return;d(!1),m(l?`Remote CLIProxy at ${x} is not reachable`:"CLIProxy is not running")}},o=setTimeout(()=>t.abort(),2e3);return h().finally(()=>clearTimeout(o)),()=>t.abort()},[u,l,x]);const C=s.useCallback(()=>{if(!(!p||!i.current?.contentWindow||!r))try{const t=u.replace(/\/$/,"");if(!i.current.src.startsWith(t)){console.warn("[ControlPanelEmbed] Iframe origin mismatch, skipping postMessage");return}i.current.contentWindow.postMessage({type:"ccs-auto-login",apiBase:t,managementKey:r},t)}catch(t){console.debug("[ControlPanelEmbed] postMessage failed - cross-origin:",t)}},[r,u,p]);s.useEffect(()=>{C()},[C]);const T=s.useCallback(()=>{b(n)},[n]),A=()=>{b(null),E(t=>t+1),m(null),d(!1)};return!I&&g?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(F,{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:A,children:[e.jsx(L,{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(H,{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:g}),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:[S&&!N&&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(q,{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(W,{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(G,{className:"h-3.5 w-3.5"})}),e.jsx("button",{className:"text-blue-600 hover:text-blue-800 dark:hover:text-blue-400",onClick:()=>U(!1),children:e.jsx(_,{className:"h-3.5 w-3.5"})})]})}),N&&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(L,{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 ${x}...`:"Loading Control Panel..."})]})}),e.jsx("iframe",{ref:i,src:n,className:"flex-1 w-full border-0",title:"CLIProxy Management Panel",onLoad:T},`${n}:${R}`)]})}function te(){return e.jsx("div",{className:"h-[calc(100vh-100px)] flex flex-col",children:e.jsx(z,{})})}export{te as CliproxyControlPanelPage};
1
+ import{j as e}from"./radix-ui-DIWAxjEp.js";import{r as s}from"./react-vendor-CNOkPC89.js";import{u as k}from"./tanstack-Hn82hibe.js";import{W as K,aU as M}from"./index-BtROiILs.js";import{C as P}from"./default-ports-1QQSffYX.js";import{G as F,R as L,a2 as H,a3 as q,K as W,b as G,X as _}from"./icons-D7XDTBCN.js";import"./notifications-B2HqRBj7.js";import"./utils-CzKF5WmX.js";import"./form-utils-Cn_Uld6y.js";import"./code-highlight-BRUf_pqB.js";function z({port:c=P}){const i=s.useRef(null),[$,b]=s.useState(null),[R,E]=s.useState(0),[g,m]=s.useState(null),[I,d]=s.useState(!1),[S,U]=s.useState(!0),{data:j,error:f}=k({queryKey:["cliproxy-server-config"],queryFn:()=>K.cliproxyServer.get(),staleTime:3e4}),{data:y}=k({queryKey:["auth-tokens-raw"],queryFn:async()=>{const t=await fetch(M("/settings/auth/tokens/raw"));if(!t.ok)throw new Error("Failed to fetch auth tokens");return t.json()},staleTime:3e4});s.useEffect(()=>{f&&console.warn("[ControlPanelEmbed] Config fetch failed, using local mode:",f)},[f]);const{managementUrl:n,checkUrl:u,authToken:r,isRemote:l,displayHost:x}=s.useMemo(()=>{const t=j?.remote;if(t?.enabled&&t?.host){const o=t.protocol||"http",a=t.port||(o==="https"?443:P),v=o==="https"&&a===443||o==="http"&&a===80?"":`:${a}`,w=`${o}://${t.host}${v}`;return{managementUrl:`${w}/management.html`,checkUrl:`${w}/`,authToken:t.auth_token||void 0,isRemote:!0,displayHost:`${t.host}${v}`}}const h=y?.managementSecret?.value||"ccs";return{managementUrl:`http://localhost:${c}/management.html`,checkUrl:`http://localhost:${c}/`,authToken:h,isRemote:!1,displayHost:`localhost:${c}`}},[j,y,c]),p=$===n,N=!p;s.useEffect(()=>{const t=new AbortController,h=async()=>{try{(await fetch(u,{signal:t.signal})).ok?(d(!0),m(null)):(d(!1),m(l?`Remote CLIProxy at ${x} returned an error`:"CLIProxy returned an error"))}catch(a){if(a instanceof Error&&a.name==="AbortError")return;d(!1),m(l?`Remote CLIProxy at ${x} is not reachable`:"CLIProxy is not running")}},o=setTimeout(()=>t.abort(),2e3);return h().finally(()=>clearTimeout(o)),()=>t.abort()},[u,l,x]);const C=s.useCallback(()=>{if(!(!p||!i.current?.contentWindow||!r))try{const t=u.replace(/\/$/,"");if(!i.current.src.startsWith(t)){console.warn("[ControlPanelEmbed] Iframe origin mismatch, skipping postMessage");return}i.current.contentWindow.postMessage({type:"ccs-auto-login",apiBase:t,managementKey:r},t)}catch(t){console.debug("[ControlPanelEmbed] postMessage failed - cross-origin:",t)}},[r,u,p]);s.useEffect(()=>{C()},[C]);const T=s.useCallback(()=>{b(n)},[n]),A=()=>{b(null),E(t=>t+1),m(null),d(!1)};return!I&&g?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(F,{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:A,children:[e.jsx(L,{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(H,{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:g}),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:[S&&!N&&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(q,{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(W,{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(G,{className:"h-3.5 w-3.5"})}),e.jsx("button",{className:"text-blue-600 hover:text-blue-800 dark:hover:text-blue-400",onClick:()=>U(!1),children:e.jsx(_,{className:"h-3.5 w-3.5"})})]})}),N&&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(L,{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 ${x}...`:"Loading Control Panel..."})]})}),e.jsx("iframe",{ref:i,src:n,className:"flex-1 w-full border-0",title:"CLIProxy Management Panel",onLoad:T},`${n}:${R}`)]})}function te(){return e.jsx("div",{className:"h-[calc(100vh-100px)] flex flex-col",children:e.jsx(z,{})})}export{te as CliproxyControlPanelPage};
@@ -1 +1 @@
1
- import{j as e}from"./radix-ui-DIWAxjEp.js";import{A as c,a as d,b as g,c as x,d as h,e as j,f as A,g as D}from"./alert-dialog-Cbz7hjbH.js";function f({open:i,onConfirm:l,onCancel:r,title:s,description:t,confirmText:a="Confirm",variant:o="default"}){return e.jsx(c,{open:i,onOpenChange:n=>!n&&r(),children:e.jsxs(d,{children:[e.jsxs(g,{children:[e.jsx(x,{children:s}),e.jsx(h,{children:t})]}),e.jsxs(j,{children:[e.jsx(A,{onClick:r,children:"Cancel"}),e.jsx(D,{onClick:l,className:o==="destructive"?"bg-red-600 hover:bg-red-700 text-white":"",children:a})]})]})})}export{f as C};
1
+ import{j as e}from"./radix-ui-DIWAxjEp.js";import{A as c,a as d,b as g,c as x,d as h,e as j,f as A,g as D}from"./alert-dialog-DYqj_ln8.js";function f({open:i,onConfirm:l,onCancel:r,title:s,description:t,confirmText:a="Confirm",variant:o="default"}){return e.jsx(c,{open:i,onOpenChange:n=>!n&&r(),children:e.jsxs(d,{children:[e.jsxs(g,{children:[e.jsx(x,{children:s}),e.jsx(h,{children:t})]}),e.jsxs(j,{children:[e.jsx(A,{onClick:r,children:"Cancel"}),e.jsx(D,{onClick:l,className:o==="destructive"?"bg-red-600 hover:bg-red-700 text-white":"",children:a})]})]})})}export{f as C};