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

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 (47) hide show
  1. package/dist/cliproxy/binary/version-cache.d.ts +10 -0
  2. package/dist/cliproxy/binary/version-cache.d.ts.map +1 -1
  3. package/dist/cliproxy/binary/version-cache.js +29 -7
  4. package/dist/cliproxy/binary/version-cache.js.map +1 -1
  5. package/dist/cliproxy/binary/version-checker.d.ts +14 -3
  6. package/dist/cliproxy/binary/version-checker.d.ts.map +1 -1
  7. package/dist/cliproxy/binary/version-checker.js +65 -36
  8. package/dist/cliproxy/binary/version-checker.js.map +1 -1
  9. package/dist/ui/assets/{accounts-DN0lP-yj.js → accounts-D7sfwYrK.js} +1 -1
  10. package/dist/ui/assets/{alert-dialog-BA39vaYL.js → alert-dialog-CuN8HTEx.js} +1 -1
  11. package/dist/ui/assets/{api-D2cjf1H4.js → api-CI8RoZ-m.js} +1 -1
  12. package/dist/ui/assets/{auth-section-BNX8_9MJ.js → auth-section-C49fRTna.js} +1 -1
  13. package/dist/ui/assets/{backups-section-Bt0FA5zl.js → backups-section-DeJGo6Co.js} +1 -1
  14. package/dist/ui/assets/{channels-FaDUjf3Y.js → channels-CEHW5H6N.js} +1 -1
  15. package/dist/ui/assets/{checkbox-DHF-UBrH.js → checkbox-DVHcE1RO.js} +1 -1
  16. package/dist/ui/assets/{claude-extension-D-skBToQ.js → claude-extension-CLmICnx_.js} +1 -1
  17. package/dist/ui/assets/{cliproxy-CD7z-_q8.js → cliproxy-BQuYNZ_b.js} +1 -1
  18. package/dist/ui/assets/{cliproxy-ai-providers-QSOOqh8F.js → cliproxy-ai-providers-Bjx7XtY6.js} +1 -1
  19. package/dist/ui/assets/{cliproxy-control-panel-D9dLU28p.js → cliproxy-control-panel-DoLho1iE.js} +1 -1
  20. package/dist/ui/assets/{codex-CHO5_hku.js → codex-BDfvFO8E.js} +1 -1
  21. package/dist/ui/assets/{confirm-dialog-BICDz_zm.js → confirm-dialog-D_5v8muu.js} +1 -1
  22. package/dist/ui/assets/{copilot-BnQrRCuJ.js → copilot-B4waN1q6.js} +1 -1
  23. package/dist/ui/assets/{cursor-CXopLKfC.js → cursor-DHHZs05u.js} +1 -1
  24. package/dist/ui/assets/{droid-CLFg9ELE.js → droid-CZePX0Pf.js} +1 -1
  25. package/dist/ui/assets/{globalenv-section-NPjCcYBN.js → globalenv-section-nQDFHMda.js} +1 -1
  26. package/dist/ui/assets/{health-B_3JpCrY.js → health-BfS7V7RZ.js} +1 -1
  27. package/dist/ui/assets/{index-BcUkpsGj.js → index-B9VMppQ3.js} +1 -1
  28. package/dist/ui/assets/{index-DNmWbKbN.js → index-BDfXfBTa.js} +3 -3
  29. package/dist/ui/assets/{index-BgGHTjTd.js → index-C5CFzca_.js} +1 -1
  30. package/dist/ui/assets/{index-BY2j-o67.js → index-CRiWOwLR.js} +1 -1
  31. package/dist/ui/assets/{index-B5Egq7qY.js → index-EboJtDBz.js} +1 -1
  32. package/dist/ui/assets/{index-DZddoGfE.js → index-yt8jgaSK.js} +1 -1
  33. package/dist/ui/assets/{logs-Bb1OVYeK.js → logs-GW0Oy6XF.js} +1 -1
  34. package/dist/ui/assets/{masked-input-b4-lEKNq.js → masked-input-D1Ilmeh7.js} +1 -1
  35. package/dist/ui/assets/{proxy-status-widget-s89zaj3X.js → proxy-status-widget-Bdh67BxQ.js} +1 -1
  36. package/dist/ui/assets/{raw-json-settings-editor-panel-Dr_BNQwQ.js → raw-json-settings-editor-panel-DwzGE_kH.js} +1 -1
  37. package/dist/ui/assets/{searchable-select-FJPe_YWv.js → searchable-select-DbhlbNK0.js} +1 -1
  38. package/dist/ui/assets/{separator-DJ0ku_ak.js → separator-DziIoy6O.js} +1 -1
  39. package/dist/ui/assets/{shared-DyQlJnbj.js → shared-XJ2EhJPB.js} +1 -1
  40. package/dist/ui/assets/{table-6Yg65ZZH.js → table-D5bWyv-8.js} +1 -1
  41. package/dist/ui/assets/{updates-DSCXb6Au.js → updates-ClhhaqwU.js} +1 -1
  42. package/dist/ui/index.html +1 -1
  43. package/dist/web-server/routes/cliproxy-stats-routes.d.ts +37 -0
  44. package/dist/web-server/routes/cliproxy-stats-routes.d.ts.map +1 -1
  45. package/dist/web-server/routes/cliproxy-stats-routes.js +56 -10
  46. package/dist/web-server/routes/cliproxy-stats-routes.js.map +1 -1
  47. package/package.json +1 -1
@@ -1,4 +1,4 @@
1
- import{j as e}from"./radix-ui-Zb8sVEtn.js";import{r as x,h as We}from"./react-vendor-CNOkPC89.js";import{a as Q,B as L,c as H,T as Ye,p as Ve,q as Ge,r as Xe,s as Ze,t as es,v as ss,w as he,d as C,n as oe,L as M,I as z,x as W,y as Re,z as ts,A as as,D as rs,E as ns,S as be,F as te,G as ge,H as Ae,J as is,K as os,M as De,N as _e,O as Me,Q as ls,R as cs,U as we,V as Ce,W as ae,X as ds,Y as Le,Z as ve,C as Qe,b as Fe,j as ms,k as us,_ as xs,$ as hs,a0 as ps,a1 as gs,a2 as fs,a3 as js,a4 as Ns,a5 as vs,a6 as bs,a7 as ws}from"./index-DNmWbKbN.js";import{a as Cs,u as fe,b as ye}from"./tanstack-CrmUhA7Z.js";import{C as je}from"./confirm-dialog-BICDz_zm.js";import{t as E}from"./notifications-B2HqRBj7.js";import{L as re,R as Z,as as He,at as ys,a9 as ne,_ as ks,au as Ie,aa as ie,C as Ue,av as Ss,a7 as Ps,aw as Os,p as Ne,X as Ts,ax as Es,Z as ze,ay as Be,n as ke,az as Se,aA as Rs,aB as pe,a6 as As,ad as Ds,aC as _s,w as Ke,aD as Ms,x as $e,o as Ls,aE as Qs}from"./icons-KVCk4_U8.js";import{M as Je}from"./masked-input-b4-lEKNq.js";import"./utils-CzKF5WmX.js";import"./form-utils-Bcoyqxpq.js";import"./code-highlight-BRUf_pqB.js";import"./alert-dialog-BA39vaYL.js";function Fs({className:s,showTooltip:a=!0}){const{t:r}=Q(),c=e.jsxs(L,{variant:"outline",className:H("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(Ye,{children:[e.jsx(Ve,{asChild:!0,children:c}),e.jsx(Ge,{children:e.jsx("p",{children:r("openrouterBadge.integration")})})]}):c}function Pe(s){return[/^ANTHROPIC_AUTH_TOKEN$/,/_API_KEY$/,/_AUTH_TOKEN$/,/^API_KEY$/,/^AUTH_TOKEN$/,/_SECRET$/,/^SECRET$/].some(r=>r.test(s))}function qe(s){return s?.env?(s.env.ANTHROPIC_BASE_URL||"").toLowerCase().includes("openrouter.ai"):!1}function Hs(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 Is(s,a){const r={...s};return a.opus?r.ANTHROPIC_DEFAULT_OPUS_MODEL=a.opus:delete r.ANTHROPIC_DEFAULT_OPUS_MODEL,a.sonnet?r.ANTHROPIC_DEFAULT_SONNET_MODEL=a.sonnet:delete r.ANTHROPIC_DEFAULT_SONNET_MODEL,a.haiku?r.ANTHROPIC_DEFAULT_HAIKU_MODEL=a.haiku:delete r.ANTHROPIC_DEFAULT_HAIKU_MODEL,r}function Us({profileName:s,target:a,data:r,settings:c,isLoading:o,isSaving:p,isTargetSaving:f,hasChanges:g,isRawJsonValid:t,onTargetChange:m,onRefresh:u,onDelete:j,onSave:P}){const{t:b}=Q(),O=p||f,y=o||O;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}),r?.path&&e.jsx(L,{variant:"outline",className:"text-xs",children:r.path.replace(/^.*\//,"")}),qe(c)&&e.jsx(Fs,{className:"ml-1"})]}),r&&e.jsxs("p",{className:"text-xs text-muted-foreground mt-0.5",children:[b("profileEditor.lastModified"),": ",new Date(r.mtime).toLocaleString()]}),e.jsxs("div",{className:"mt-2 flex items-center gap-2",children:[e.jsxs("span",{className:"text-xs text-muted-foreground",children:[b("profileEditor.defaultTarget"),":"]}),e.jsxs(Xe,{value:a,onValueChange:k=>{y||m(k)},disabled:y,children:[e.jsx(Ze,{className:"h-7 w-[170px] text-xs",disabled:y,children:e.jsx(es,{})}),e.jsxs(ss,{children:[e.jsx(he,{value:"claude",children:b("profileEditor.targetClaude")}),e.jsx(he,{value:"droid",children:b("profileEditor.targetDroid")}),e.jsx(he,{value:"codex",children:b("profileEditor.targetCodex")})]})]}),f&&e.jsx(re,{className:"w-3.5 h-3.5 animate-spin text-muted-foreground"})]})]}),e.jsxs("div",{className:"flex items-center gap-2",children:[e.jsx(C,{variant:"ghost",size:"sm",onClick:u,disabled:y,children:e.jsx(Z,{className:`w-4 h-4 ${o?"animate-spin":""}`})}),j&&e.jsx(C,{variant:"ghost",size:"sm",onClick:j,disabled:O,children:e.jsx(He,{className:"w-4 h-4 text-destructive"})}),e.jsx(C,{size:"sm",onClick:P,disabled:O||!g||!t,children:p?e.jsxs(e.Fragment,{children:[e.jsx(re,{className:"w-4 h-4 mr-1 animate-spin"}),b("profileEditor.saving")]}):e.jsxs(e.Fragment,{children:[e.jsx(ys,{className:"w-4 h-4 mr-1"}),b("settingsAuth.save")]})})]})]})}function zs({currentSettings:s,newEnvKey:a,newEnvValue:r,onNewEnvKeyChange:c,onNewEnvValueChange:o,onEnvValueChange:p,onAddEnvVar:f}){const{t:g}=Q();return e.jsxs(e.Fragment,{children:[e.jsx(oe,{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(([t,m])=>e.jsxs("div",{className:"space-y-1.5",children:[e.jsxs(M,{className:"text-xs font-medium flex items-center gap-2 text-muted-foreground",children:[t,Pe(t)&&e.jsx(L,{variant:"secondary",className:"text-[10px] px-1 py-0 h-4",children:g("envEditor.sensitive")})]}),Pe(t)?e.jsx(Je,{value:m,onChange:u=>p(t,u.target.value),className:"font-mono text-sm h-8"}):e.jsx(z,{value:m,onChange:u=>p(t,u.target.value),className:"font-mono text-sm h-8"})]},t))}):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:g("envEditor.none")}),e.jsx("p",{className:"text-xs mt-1 opacity-70",children:g("envEditor.noneHint")})]})})}),e.jsxs("div",{className:"p-4 border-t bg-background shrink-0",children:[e.jsx(M,{className:"text-xs font-medium text-muted-foreground",children:g("envEditor.addVariable")}),e.jsxs("div",{className:"flex gap-2 mt-2",children:[e.jsx(z,{placeholder:g("envEditor.keyPlaceholder"),value:a,onChange:t=>c(t.target.value.toUpperCase()),className:"font-mono text-sm h-8 w-2/5",onKeyDown:t=>t.key==="Enter"&&a.trim()&&f()}),e.jsx(z,{placeholder:g("envEditor.valuePlaceholder"),value:r,onChange:t=>o(t.target.value),className:"font-mono text-sm h-8 flex-1",onKeyDown:t=>t.key==="Enter"&&a.trim()&&f()}),e.jsx(C,{variant:"outline",size:"sm",className:"h-8",onClick:f,disabled:!a.trim(),children:e.jsx(ne,{className:"w-4 h-4"})})]})]})]})}function Bs({profileName:s,target:a,data:r}){const{t:c}=Q(),o=a==="droid";return e.jsx(oe,{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(ks,{className:"w-4 h-4"}),c("profileEditor.profileInfo")]}),e.jsx("div",{className:"space-y-3 bg-card rounded-lg border p-4 shadow-sm",children:r&&e.jsxs(e.Fragment,{children:[e.jsxs("div",{className:"grid grid-cols-[100px_1fr] gap-2 text-sm items-center",children:[e.jsx("span",{className:"font-medium text-muted-foreground",children:c("profileEditor.profileName")}),e.jsx("span",{className:"font-mono",children:r.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:c("profileEditor.filePath")}),e.jsxs("div",{className:"flex items-center gap-2 min-w-0",children:[e.jsx("code",{className:"bg-muted px-1.5 py-0.5 rounded text-xs break-all",children:r.path}),e.jsx(W,{value:r.path,size:"icon",className:"h-5 w-5"})]})]}),e.jsxs("div",{className:"grid grid-cols-[100px_1fr] gap-2 text-sm items-center",children:[e.jsx("span",{className:"font-medium text-muted-foreground",children:c("profileEditor.lastModified")}),e.jsx("span",{className:"text-xs",children:new Date(r.mtime).toLocaleString()})]}),e.jsxs("div",{className:"grid grid-cols-[100px_1fr] gap-2 text-sm items-center",children:[e.jsx("span",{className:"font-medium text-muted-foreground",children:c("profileEditor.defaultTarget")}),e.jsx("span",{className:"font-mono",children:a})]})]})})]}),e.jsxs("div",{children:[e.jsx("h3",{className:"text-sm font-medium mb-3",children:c("profileEditor.quickUsage")}),e.jsxs("div",{className:"space-y-3 bg-card rounded-lg border p-4 shadow-sm",children:[e.jsxs("div",{children:[e.jsx(M,{className:"text-xs text-muted-foreground",children:c("profileEditor.runWithProfile")}),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(W,{value:`ccs ${s} "prompt"`,size:"icon",className:"h-6 w-6"})]})]}),e.jsxs("div",{children:[e.jsx(M,{className:"text-xs text-muted-foreground",children:c(o?"profileEditor.droidAliasExplicit":"profileEditor.runOnDroid")}),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:`ccs-droid ${s} "prompt"`}),e.jsx(W,{value:`ccs-droid ${s} "prompt"`,size:"icon",className:"h-6 w-6"})]})]}),e.jsxs("div",{children:[e.jsx(M,{className:"text-xs text-muted-foreground",children:c(o?"profileEditor.overrideToClaude":"profileEditor.runOnDroidWithFlag")}),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 ",o?"claude":"droid",' "prompt"']}),e.jsx(W,{value:`ccs ${s} --target ${o?"claude":"droid"} "prompt"`,size:"icon",className:"h-6 w-6"})]})]}),e.jsxs("div",{children:[e.jsx(M,{className:"text-xs text-muted-foreground",children:c("profileEditor.setAsDefault")}),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(W,{value:`ccs default ${s}`,size:"icon",className:"h-6 w-6"})]})]})]})]})]})})}function Ks({value:s,onChange:a,placeholder:r,className:c}){const{t:o}=Q(),[p,f]=x.useState(""),[g,t]=x.useState(null),{models:m,isLoading:u,isError:j,isFetching:P}=Re(),b=ts(),O=x.useMemo(()=>as(m,p,{category:g??void 0}),[m,p,g]),y=x.useMemo(()=>rs(m,2),[m]),k=!p.trim()&&!g,N=x.useMemo(()=>{const i={anthropic:[],openai:[],google:[],meta:[],mistral:[],opensource:[],other:[]};O.forEach(h=>{i[h.category].push(h)});for(const h of Object.keys(i))i[h]=ns(i[h]);return i},[O]),R=x.useCallback(()=>{b()},[b]),v=m.find(i=>i.id===s);return u&&m.length===0?e.jsxs("div",{className:H("space-y-2",c),children:[e.jsx(be,{className:"h-10 w-full"}),e.jsx(be,{className:"h-32 w-full"})]}):e.jsxs("div",{className:H("space-y-2 w-full min-w-0 overflow-hidden",c),children:[e.jsxs("div",{className:"flex gap-2",children:[e.jsxs("div",{className:"relative flex-1",children:[e.jsx(Ie,{className:"text-muted-foreground absolute left-3 top-1/2 h-4 w-4 -translate-y-1/2"}),e.jsx(z,{value:p,onChange:i=>f(i.target.value),placeholder:r??o("openrouterModelPicker.searchModels"),className:"pl-9"})]}),e.jsx(C,{variant:"outline",size:"icon",onClick:R,disabled:P,title:"Refresh models",children:P?e.jsx(re,{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(L,{variant:g===null?"default":"outline",className:"cursor-pointer",onClick:()=>t(null),children:["All (",m.length,")"]}),Object.keys(te).map(i=>{const h=N[i].length;return h===0?null:e.jsxs(L,{variant:g===i?"default":"outline",className:"cursor-pointer",onClick:()=>t(i),children:[te[i]," (",h,")"]},i)})]}),v&&e.jsxs("div",{className:"bg-muted rounded-md p-2 text-sm",children:[e.jsx("span",{className:"font-medium",children:v.name}),e.jsxs("span",{className:"text-muted-foreground ml-2",children:[ge(v.pricing)," |"," ",Ae(v.context_length)]})]}),e.jsx(oe,{className:"h-72 w-full rounded-md border",children:j?e.jsxs("div",{className:"text-destructive p-4 text-center",children:["Failed to load models."," ",e.jsx(C,{variant:"link",onClick:R,children:"Retry"})]}):O.length===0?e.jsxs("div",{className:"text-muted-foreground p-4 text-center",children:['No models found matching "',p,'"']}):e.jsxs("div",{className:"space-y-6 p-3",children:[k&&y.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(ie,{className:"h-3 w-3 text-accent"}),e.jsx("span",{children:o("openrouterModelPicker.newestModels")})]}),e.jsx("div",{className:"space-y-1",children:y.map(i=>e.jsx(Oe,{model:i,isSelected:i.id===s,onClick:()=>a(i.id),showAge:!0},i.id))})]}),Object.keys(te).map(i=>{const h=N[i];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:te[i]}),e.jsx("div",{className:"space-y-1",children:h.map(l=>e.jsx(Oe,{model:l,isSelected:l.id===s,onClick:()=>a(l.id)},l.id))})]},i)})]})})]})}function Oe({model:s,isSelected:a,onClick:r,showAge:c=!1}){return e.jsxs("button",{type:"button",onClick:r,className:H("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:H("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:[c&&s.created&&e.jsx(L,{variant:"outline",className:H("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:is(s.created)}),s.isFree?e.jsx(L,{variant:"secondary",className:H("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(L,{variant:"outline",className:H("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:ge(s.pricing)})]}):e.jsx("span",{className:"tabular-nums",children:ge(s.pricing)}),e.jsx("span",{className:"tabular-nums",children:Ae(s.context_length)})]})]})}function $s({selectedModel:s,value:a,onChange:r,className:c}){const{t:o}=Q(),{models:p}=Re(),f=x.useMemo(()=>s?os(s,p):{},[s,p]),g=()=>{r(f)},t=(u,j)=>{r({...a,[u]:j||void 0})},m=s&&Object.keys(f).length>0;return e.jsxs(De,{className:H("group",c),children:[e.jsxs(_e,{className:"flex items-center gap-2 text-sm font-medium hover:underline",children:[e.jsx(Ue,{className:"h-4 w-4 transition-transform group-data-[state=open]:rotate-90"}),o("modelTierMapping.title"),e.jsxs("span",{className:"text-muted-foreground font-normal",children:["(",o("modelTierMapping.advanced"),")"]})]}),e.jsxs(Me,{className:"space-y-3 pt-3",children:[e.jsx("p",{className:"text-muted-foreground text-sm",children:o("modelTierMapping.description")}),m&&e.jsxs(C,{type:"button",variant:"outline",size:"sm",onClick:g,children:[e.jsx(Ss,{className:"mr-1 h-4 w-4"}),o("modelTierMapping.autoSuggest",{provider: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(M,{htmlFor:"tier-opus",className:"text-right",children:"Opus"}),e.jsx(z,{id:"tier-opus",value:a.opus??"",onChange:u=>t("opus",u.target.value),placeholder:o("modelTierMapping.opusPlaceholder")})]}),e.jsxs("div",{className:"grid grid-cols-[80px_1fr] items-center gap-2",children:[e.jsx(M,{htmlFor:"tier-sonnet",className:"text-right",children:"Sonnet"}),e.jsx(z,{id:"tier-sonnet",value:a.sonnet??"",onChange:u=>t("sonnet",u.target.value),placeholder:o("modelTierMapping.sonnetPlaceholder")})]}),e.jsxs("div",{className:"grid grid-cols-[80px_1fr] items-center gap-2",children:[e.jsx(M,{htmlFor:"tier-haiku",className:"text-right",children:"Haiku"}),e.jsx(z,{id:"tier-haiku",value:a.haiku??"",onChange:u=>t("haiku",u.target.value),placeholder:o("modelTierMapping.haikuPlaceholder")})]})]}),e.jsx("p",{className:"text-muted-foreground text-xs",children:o("modelTierMapping.footer")})]})]})}function Js({profileName:s,target:a,data:r,currentSettings:c,newEnvKey:o,newEnvValue:p,onNewEnvKeyChange:f,onNewEnvValueChange:g,onEnvValueChange:t,onAddEnvVar:m,onEnvBulkChange:u}){const{t:j}=Q(),P=qe(c),b=c?.env,O=x.useMemo(()=>Hs(b??{}),[b]),y=b??{},k=l=>{if(u){const I={...y,ANTHROPIC_MODEL:l,ANTHROPIC_DEFAULT_OPUS_MODEL:l,ANTHROPIC_DEFAULT_SONNET_MODEL:l,ANTHROPIC_DEFAULT_HAIKU_MODEL:l};u(I)}else t("ANTHROPIC_MODEL",l),t("ANTHROPIC_DEFAULT_OPUS_MODEL",l),t("ANTHROPIC_DEFAULT_SONNET_MODEL",l),t("ANTHROPIC_DEFAULT_HAIKU_MODEL",l);E.success(ae.t("commonToast.appliedModelAllTiers"),{duration:2e3})},N=l=>{if(u){const I=Is(y,l);u(I)}else l.opus!==void 0&&t("ANTHROPIC_DEFAULT_OPUS_MODEL",l.opus||""),l.sonnet!==void 0&&t("ANTHROPIC_DEFAULT_SONNET_MODEL",l.sonnet||""),l.haiku!==void 0&&t("ANTHROPIC_DEFAULT_HAIKU_MODEL",l.haiku||"")},[R,v]=x.useState(!1),i=new Set(["ANTHROPIC_AUTH_TOKEN"]),h=Object.entries(y).filter(([l])=>!i.has(l));return e.jsx("div",{className:"h-full w-full min-w-0 flex flex-col",children:e.jsxs(ls,{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(cs,{className:"w-full",children:[e.jsx(we,{value:"env",className:"flex-1",children:P?"Configuration":j("settingsDialog.envTab")}),e.jsx(we,{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(Ce,{value:"env",className:"flex-1 mt-0 border-0 p-0 data-[state=inactive]:hidden flex flex-col overflow-hidden min-w-0",children:P?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(M,{className:"text-sm font-medium",children:"Model Selection"}),e.jsx(Ks,{value:y.ANTHROPIC_MODEL,onChange:k,placeholder:"Search OpenRouter models..."})]}),e.jsx($s,{selectedModel:y.ANTHROPIC_MODEL,value:O,onChange:N}),e.jsxs("div",{className:"space-y-2",children:[e.jsx(M,{className:"text-sm font-medium",children:j("profileDialog.apiKey")}),e.jsx(Je,{value:y.ANTHROPIC_AUTH_TOKEN||"",onChange:l=>t("ANTHROPIC_AUTH_TOKEN",l.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(De,{open:R,onOpenChange:v,children:[e.jsxs(_e,{className:"flex items-center gap-2 text-sm font-medium text-muted-foreground hover:text-foreground transition-colors group",children:[e.jsx(Ue,{className:H("h-4 w-4 transition-transform",R&&"rotate-90")}),e.jsx(Ps,{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(Me,{className:"pt-4",children:e.jsx("div",{className:"space-y-3 border rounded-lg p-3 bg-muted/30",children:h.map(([l,I])=>e.jsxs("div",{className:"space-y-1",children:[e.jsx(M,{className:"text-xs text-muted-foreground",children:l}),e.jsx(z,{value:I,onChange:J=>t(l,J.target.value),className:"font-mono text-xs h-8"})]},l))})})]})]})}),e.jsxs("div",{className:"p-4 border-t bg-background shrink-0",children:[e.jsx(M,{className:"text-xs font-medium text-muted-foreground",children:j("envEditor.addVariable")}),e.jsxs("div",{className:"flex gap-2 mt-2",children:[e.jsx(z,{placeholder:j("envEditor.keyPlaceholder"),value:o,onChange:l=>f(l.target.value.toUpperCase()),className:"font-mono text-sm h-8 w-2/5",onKeyDown:l=>l.key==="Enter"&&o.trim()&&m()}),e.jsx(z,{placeholder:j("envEditor.valuePlaceholder"),value:p,onChange:l=>g(l.target.value),className:"font-mono text-sm h-8 flex-1",onKeyDown:l=>l.key==="Enter"&&o.trim()&&m()}),e.jsx(C,{variant:"outline",size:"sm",className:"h-8",onClick:m,disabled:!o.trim(),children:e.jsx(ne,{className:"w-4 h-4"})})]})]})]}):e.jsx(zs,{currentSettings:c,newEnvKey:o,newEnvValue:p,onNewEnvKeyChange:f,onNewEnvValueChange:g,onEnvValueChange:t,onAddEnvVar:m})}),e.jsx(Ce,{value:"info",className:"h-full mt-0 border-0 p-0 data-[state=inactive]:hidden",children:e.jsx(Bs,{profileName:s,target:a,data:r})})]})]})})}function qs({profileName:s,profileTarget:a,onDelete:r,onHasChangesUpdate:c}){const{t:o}=Q(),[p,f]=x.useState({}),[g,t]=x.useState(!1),[m,u]=x.useState(null),[j,P]=x.useState(""),[b,O]=x.useState(""),y=Cs(),{data:k,isLoading:N,isError:R,refetch:v}=fe({queryKey:["settings",s],queryFn:async()=>{const d=await fetch(`/api/settings/${s}/raw`);if(!d.ok)throw new Error(`Failed to load settings: ${d.status}`);return d.json()}}),i=k?.settings,h=x.useMemo(()=>{if(m!==null)try{return JSON.parse(m)}catch{}if(i)return{...i,env:{...i.env,...p}}},[i,p,m]),l=x.useMemo(()=>m!==null?m:i?JSON.stringify(i,null,2):"",[m,i]),I=x.useCallback(d=>{u(d)},[]),J=x.useCallback(d=>{const w={...h??{}},_=w.ccs_image&&typeof w.ccs_image=="object"?{...w.ccs_image}:{};d?_.native_read=!0:delete _.native_read,Object.keys(_).length>0?w.ccs_image=_:delete w.ccs_image,u(JSON.stringify(w,null,2))},[h]),q=(d,w)=>{const _={...h?.env||{},[d]:w};f(G=>({...G,[d]:w})),u(JSON.stringify({...h,env:_},null,2))},ee=d=>{const w={...h?.env||{},...d};f(_=>({..._,...d})),u(JSON.stringify({...h,env:w},null,2))},U=()=>{if(!j.trim())return;const d=j.trim(),w=b,_={...h?.env||{},[d]:w};f(G=>({...G,[d]:w})),u(JSON.stringify({...h,env:_},null,2)),P(""),O("")},B=x.useMemo(()=>{try{return JSON.parse(l),!0}catch{return!1}},[l]),S=x.useMemo(()=>m!==null?m!==JSON.stringify(i,null,2):Object.keys(p).length>0,[m,p,i]),$=x.useDeferredValue(l),se=x.useMemo(()=>{if(!S||!B)return null;try{return JSON.parse($)}catch{return null}},[S,B,$]),{data:Y,isFetching:le,isError:V,isPlaceholderData:ce}=fe({queryKey:["settings",s,"image-analysis-status-preview",$],enabled:se!==null,placeholderData:d=>d,queryFn:async()=>{const d=await fetch(`/api/settings/${s}/image-analysis-status`,{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify({settings:se})});if(!d.ok)throw new Error(`Failed to preview image-analysis status: ${d.status}`);return d.json()}}),de=S&&B&&!V?Y?.imageAnalysisStatus??k?.imageAnalysisStatus:k?.imageAnalysisStatus,me=S&&B&&!V&&Y?.imageAnalysisStatus?"editor":"saved",ue=S?B?V?"saved":le&&(!Y?.imageAnalysisStatus||ce)?"refreshing":"preview":"invalid":"saved",xe=h?.ccs_image?.native_read===!0,n=x.useMemo(()=>{const d=["ANTHROPIC_BASE_URL","ANTHROPIC_AUTH_TOKEN"],w=h?.env||{};return d.filter(_=>!w[_]?.trim())},[h]);x.useEffect(()=>{c?.(S)},[S,c]);const A=ye({mutationFn:async()=>{let d;try{d=JSON.parse(l)}catch{d={...k?.settings,env:{...k?.settings?.env,...p}}}const w=await fetch(`/api/settings/${s}`,{method:"PUT",headers:{"Content-Type":"application/json"},body:JSON.stringify({settings:d,expectedMtime:k?.mtime})});if(w.status===409)throw new Error("CONFLICT");if(!w.ok)throw new Error("Failed to save");return w.json()},onSuccess:()=>{y.invalidateQueries({queryKey:["settings",s]}),y.invalidateQueries({queryKey:["profiles"]}),f({}),u(null),E.success(ae.t("commonToast.settingsSaved"))},onError:d=>{d.message==="CONFLICT"?t(!0):E.error(d.message)}}),T=ye({mutationFn:async d=>(await Le.profiles.update(s,{target:d}),d),onSuccess:()=>{y.invalidateQueries({queryKey:["profiles"]}),E.success(ae.t("commonToast.defaultTargetUpdated"))},onError:(d,w)=>{const _=w==="droid"?"Factory Droid":w==="codex"?"Codex CLI":"Claude Code",G=d.message.trim()?`: ${d.message}`:"";E.error(ae.t("commonToast.failedUpdateDefaultTarget",{target:_,suffix:G}))}}),F=a||"claude",D=A.isPending||T.isPending,K=async d=>{t(!1),d?(await v(),A.mutate()):(f({}),u(null))};return e.jsxs("div",{className:"flex-1 flex flex-col overflow-hidden",children:[e.jsx(Us,{profileName:s,target:F,data:k,settings:h,isLoading:N,isSaving:A.isPending,isTargetSaving:T.isPending,hasChanges:S,isRawJsonValid:B,onTargetChange:d=>{D||d!==F&&T.mutate(d)},onRefresh:()=>{D||v()},onDelete:r,onSave:()=>{D||A.mutate()}}),N?e.jsxs("div",{className:"flex-1 flex items-center justify-center",children:[e.jsx(re,{className:"w-8 h-8 animate-spin text-muted-foreground"}),e.jsx("span",{className:"ml-3 text-muted-foreground",children:o("settingsDialog.loadingSettings")})]}):R?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:o("settingsPage.failedLoad")}),e.jsxs(C,{variant:"outline",size:"sm",onClick:()=>v(),children:[e.jsx(Z,{className:"w-4 h-4 mr-1"}),o("apiProfiles.retry")]})]})}):e.jsxs("div",{className:"min-h-0 flex-1 grid grid-cols-[40%_60%] divide-x overflow-hidden",children:[e.jsx("div",{className:"flex min-h-0 min-w-0 flex-col overflow-hidden bg-muted/5",children:e.jsx(Js,{profileName:s,target:F,data:k,currentSettings:h,newEnvKey:j,newEnvValue:b,onNewEnvKeyChange:P,onNewEnvValueChange:O,onEnvValueChange:q,onEnvBulkChange:ee,onAddEnvVar:U})}),e.jsxs("div",{className:"flex min-h-0 min-w-0 flex-col overflow-hidden",children:[e.jsxs("div",{className:"px-6 py-2 bg-muted/30 border-b flex items-center gap-2 shrink-0 h-[45px]",children:[e.jsx(Os,{className:"w-4 h-4 text-muted-foreground"}),e.jsx("span",{className:"text-sm font-medium text-muted-foreground",children:o("rawEditorSection.rawConfig")})]}),e.jsx(ds,{rawJsonContent:l,isRawJsonValid:B,rawJsonEdits:m,settings:i,profileTarget:F,imageAnalysisStatus:de,imageAnalysisStatusSource:me,imageAnalysisStatusPreviewState:ue,nativeReadPreferenceOverride:xe,onToggleNativeRead:J,onChange:I,missingRequiredFields:n})]})]}),e.jsx(je,{open:g,title:o("settingsDialog.conflictTitle"),description:o("settingsDialog.conflictDesc"),confirmText:o("settingsDialog.overwrite"),variant:"destructive",onConfirm:()=>K(!0),onCancel:()=>K(!1)})]},s)}const Te="ccs:openrouter-banner-dismissed";function Ws({onCreateClick:s}){const{t:a}=Q(),[r,c]=x.useState(!0),{modelCount:o,isLoading:p}=ve();x.useEffect(()=>{const g=localStorage.getItem(Te)==="true";c(g)},[]);const f=()=>{localStorage.setItem(Te,"true"),c(!0)};return r?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(ie,{className:"w-4 h-4"})}),e.jsxs("div",{className:"flex-1 min-w-0",children:[e.jsxs("p",{className:"font-medium text-sm",children:[a("openrouterBadge.new"),": ",a("openrouterBadge.integration")]}),e.jsx("p",{className:"text-xs text-white/80 truncate",children:a("openrouterBanner.accessModels",{count:p?300:o})})]})]}),e.jsxs("div",{className:"flex items-center gap-2 shrink-0",children:[s&&e.jsx(C,{size:"sm",variant:"secondary",onClick:s,className:"bg-white text-accent hover:bg-white/90 h-8",children:a("openrouterBanner.add")}),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(Ne,{className:"w-3 h-3"})]}),e.jsxs(C,{size:"icon",variant:"ghost",onClick:f,className:"h-7 w-7 text-white/70 hover:text-white hover:bg-white/20",children:[e.jsx(Ts,{className:"w-4 h-4"}),e.jsx("span",{className:"sr-only",children:"Dismiss"})]})]})]})})}function Ys(){return fe({queryKey:["profiles","local-runtime-readiness"],queryFn:()=>Le.profiles.getLocalRuntimeReadiness(),staleTime:15e3,refetchOnWindowFocus:!1})}function X({badge:s,badgeClassName:a,className:r,title:c,description:o,visual:p,highlights:f,actionLabel:g,actionClassName:t,onAction:m,footer:u}){return e.jsxs(Qe,{className:H("flex h-full flex-col border shadow-sm",r),children:[e.jsxs(ms,{className:"space-y-3 pb-3",children:[e.jsxs("div",{className:"flex items-center gap-3",children:[p,e.jsx(L,{variant:"secondary",className:a,children:s})]}),e.jsxs("div",{className:"space-y-1.5",children:[e.jsx(us,{className:"text-base",children:c}),e.jsx(xs,{className:"text-sm leading-6",children:o})]})]}),e.jsxs(Fe,{className:"mt-auto flex flex-1 flex-col gap-4 pt-0",children:[e.jsx("div",{className:"space-y-2 text-xs text-muted-foreground",children:f.map(j=>e.jsxs("div",{className:"flex items-center gap-2",children:[j.icon,e.jsx("span",{children:j.label})]},j.label))}),e.jsxs(C,{onClick:m,className:t,children:[g,e.jsx(As,{className:"ml-2 h-4 w-4"})]}),u?e.jsx("div",{className:"text-xs text-muted-foreground",children:u}):null]})]})}function Ee(s,a,r){return s?s.status==="ready"?{badge:r("openrouterQuickStart.localRuntimeReadyBadge"),badgeClassName:"bg-emerald-500/10 text-emerald-700 dark:bg-emerald-500/20 dark:text-emerald-200",actionLabel:r("openrouterQuickStart.localRuntimeUseAction",{label:a}),description:r("openrouterQuickStart.localRuntimeReadyDescription"),footer:r("openrouterQuickStart.localRuntimeReadyFooter",{endpoint:s.endpoint})}:s.status==="missing-model"?{badge:r("openrouterQuickStart.localRuntimeNeedsModelBadge"),badgeClassName:"bg-amber-500/10 text-amber-700 dark:bg-amber-500/20 dark:text-amber-200",actionLabel:r("openrouterQuickStart.localRuntimeFinishAction",{label:a}),description:r("openrouterQuickStart.localRuntimeNeedsModelDescription"),footer:r("openrouterQuickStart.localRuntimeMissingModelFooter",{command:s.commandHint})}:{badge:r("openrouterQuickStart.localRuntimeOfflineBadge"),badgeClassName:"bg-muted text-muted-foreground",actionLabel:r("openrouterQuickStart.localRuntimeSetupAction",{label:a}),description:r("openrouterQuickStart.localRuntimeOfflineDescription"),footer:r("openrouterQuickStart.localRuntimeOfflineFooter",{command:s.commandHint})}:{badge:r("openrouterQuickStart.localRuntimeCheckingBadge"),badgeClassName:"bg-muted text-muted-foreground",actionLabel:r("openrouterQuickStart.localRuntimeSetupAction",{label:a}),description:r("openrouterQuickStart.localRuntimeCheckingDescription"),footer:r("openrouterQuickStart.localRuntimeCheckingFooter")}}function Vs({hasProfiles:s,profileCount:a,onOpenRouterClick:r,onAlibabaCodingPlanClick:c,onCliproxyClick:o,onCustomClick:p,onOllamaClick:f,onLlamacppClick:g}){const{t}=Q(),{modelCount:m,isLoading:u}=ve(),{data:j}=Ys(),P=u?"300+":`${m}+`,b=s?t("openrouterQuickStart.profileSummaryCount",{count:a}):t("openrouterQuickStart.profileSummaryEmpty"),O=t(s?"openrouterQuickStart.summaryExistingTitle":"openrouterQuickStart.summaryEmptyTitle"),y=s?t("openrouterQuickStart.summaryExistingDescription",{count:a}):t("openrouterQuickStart.summaryEmptyDescription"),k=j?.runtimes.find(i=>i.id==="ollama"),N=j?.runtimes.find(i=>i.id==="llamacpp"),R=Ee(k,t("openrouterQuickStart.localOllamaLabel"),t),v=Ee(N,t("openrouterQuickStart.localLlamacppLabel"),t);return e.jsx("div",{className:"flex h-full min-h-0 flex-col overflow-auto bg-muted/20 p-4 sm:p-6",children:e.jsxs("div",{className:"mx-auto flex w-full max-w-7xl flex-col gap-5",children:[e.jsx(Qe,{className:"border-dashed bg-background/90 shadow-sm",children:e.jsxs(Fe,{className:"flex flex-col gap-4 p-5 lg:flex-row lg:items-center lg:justify-between",children:[e.jsxs("div",{className:"space-y-2",children:[e.jsxs("div",{className:"flex flex-wrap items-center gap-2",children:[e.jsx(L,{variant:"secondary",children:b}),e.jsx(L,{variant:"outline",children:t("openrouterQuickStart.summaryBadgeDefaultQuality")}),e.jsx(L,{variant:"outline",children:t("openrouterQuickStart.summaryBadgeLocalLane")})]}),e.jsxs("div",{className:"space-y-1",children:[e.jsx("h2",{className:"text-xl font-semibold",children:O}),e.jsx("p",{className:"max-w-3xl text-sm leading-6 text-muted-foreground",children:y})]})]}),e.jsx(C,{variant:"outline",onClick:p,className:"shrink-0",children:t("openrouterQuickStart.createCustomProfile")})]})}),e.jsxs("div",{className:"space-y-2",children:[e.jsxs("div",{className:"flex items-center gap-2",children:[e.jsx(Es,{className:"h-4 w-4 text-accent"}),e.jsx("h3",{className:"text-sm font-semibold uppercase tracking-[0.12em] text-foreground/70",children:t("openrouterQuickStart.qualityLanesTitle")})]}),e.jsxs("div",{className:"grid gap-4 lg:grid-cols-2",children:[e.jsx(X,{badge:t("openrouterQuickStart.recommended"),title:t("openrouterQuickStart.title"),description:t("openrouterQuickStart.description",{modelCountLabel:P}),visual:e.jsx("div",{className:"rounded-lg bg-accent/10 p-2",children:e.jsx("img",{src:"/icons/openrouter.svg",alt:"OpenRouter",className:"h-5 w-5"})}),highlights:[{icon:e.jsx(ze,{className:"h-3.5 w-3.5 text-accent"}),label:t("openrouterQuickStart.featureOneApi")},{icon:e.jsx(ie,{className:"h-3.5 w-3.5 text-accent"}),label:t("openrouterQuickStart.qualityLaneHighlightDefaultQuality")}],actionLabel:t("openrouterQuickStart.createOpenRouterProfile"),actionClassName:"w-full bg-accent text-white hover:bg-accent/90",onAction:r,footer:e.jsxs(e.Fragment,{children:[t("openrouterQuickStart.getApiKeyAt")," ",e.jsxs("a",{href:"https://openrouter.ai/keys",target:"_blank",rel:"noopener noreferrer",className:"inline-flex items-center gap-1 text-accent hover:underline",children:["openrouter.ai/keys",e.jsx(Ne,{className:"h-3 w-3"})]})]})}),e.jsx(X,{badge:t("alibabaCodingPlanQuickStart.recommended"),badgeClassName:"bg-orange-500/10 text-orange-700 dark:bg-orange-500/20 dark:text-orange-200",title:t("alibabaCodingPlanQuickStart.title"),description:t("openrouterQuickStart.alibabaLaneDescription"),visual:e.jsx("div",{className:"rounded-lg bg-orange-500/10 p-2",children:e.jsx("img",{src:"/assets/providers/alibabacloud-color.svg",alt:"Alibaba Coding Plan",className:"h-5 w-5"})}),highlights:[{icon:e.jsx(Be,{className:"h-3.5 w-3.5 text-orange-600"}),label:t("alibabaCodingPlanQuickStart.featureEndpoint")},{icon:e.jsx(ke,{className:"h-3.5 w-3.5 text-orange-600"}),label:t("openrouterQuickStart.alibabaLaneHighlightQuality")}],actionLabel:t("alibabaCodingPlanQuickStart.createAlibabaProfile"),actionClassName:"w-full bg-orange-600 text-white hover:bg-orange-600/90",onAction:c,footer:e.jsxs(e.Fragment,{children:[t("alibabaCodingPlanQuickStart.readGuideAt")," ",e.jsxs("a",{href:"https://www.alibabacloud.com/help/en/model-studio/coding-plan",target:"_blank",rel:"noopener noreferrer",className:"inline-flex items-center gap-1 text-orange-700 hover:underline dark:text-orange-400",children:["Alibaba Cloud Model Studio",e.jsx(Ne,{className:"h-3 w-3"})]})]})})]})]}),e.jsxs("div",{className:"space-y-2",children:[e.jsxs("div",{className:"flex items-center gap-2",children:[e.jsx(Se,{className:"h-4 w-4 text-emerald-600"}),e.jsx("h3",{className:"text-sm font-semibold uppercase tracking-[0.12em] text-foreground/70",children:t("openrouterQuickStart.localRuntimesTitle")})]}),e.jsxs("div",{className:"grid gap-4 lg:grid-cols-2",children:[e.jsx(X,{badge:R.badge,badgeClassName:R.badgeClassName,title:t("openrouterQuickStart.localOllamaTitle"),description:R.description,visual:e.jsx("div",{className:"rounded-lg bg-emerald-500/10 p-2",children:e.jsx("img",{src:"/icons/ollama.svg",alt:"Ollama",className:"h-5 w-5"})}),highlights:[{icon:e.jsx(Rs,{className:"h-3.5 w-3.5 text-emerald-600"}),label:t("openrouterQuickStart.localOllamaHighlight")},{icon:e.jsx(ie,{className:"h-3.5 w-3.5 text-emerald-600"}),label:k?.detectedModelCount&&k.detectedModelCount>0?t("openrouterQuickStart.localDetectedModels",{count:k.detectedModelCount}):t("openrouterQuickStart.localNoModelsDetected")}],actionLabel:R.actionLabel,actionClassName:"w-full bg-emerald-600 text-white hover:bg-emerald-600/90",onAction:f,footer:e.jsx("span",{children:R.footer})}),e.jsx(X,{badge:v.badge,badgeClassName:v.badgeClassName,title:t("openrouterQuickStart.localLlamacppTitle"),description:v.description,visual:e.jsx("div",{className:"rounded-lg bg-sky-500/10 p-2",children:e.jsx("img",{src:"/assets/providers/llama-cpp.svg",alt:"llama.cpp",className:"h-5 w-5"})}),highlights:[{icon:e.jsx(pe,{className:"h-3.5 w-3.5 text-sky-600"}),label:t("openrouterQuickStart.localLlamacppHighlight")},{icon:e.jsx(Se,{className:"h-3.5 w-3.5 text-sky-600"}),label:N?.detectedModelCount&&N.detectedModelCount>0?t("openrouterQuickStart.localDetectedModels",{count:N.detectedModelCount}):t("openrouterQuickStart.localWaitingServer")}],actionLabel:v.actionLabel,actionClassName:"w-full bg-sky-600 text-white hover:bg-sky-600/90",onAction:g,footer:e.jsx("span",{children:v.footer})})]})]}),e.jsx("div",{className:"grid gap-4 lg:grid-cols-2",children:e.jsx(X,{badge:t("openrouterQuickStart.runtimeProviderBadge"),badgeClassName:"bg-emerald-500/10 text-emerald-700 dark:bg-emerald-500/20 dark:text-emerald-200",title:t("openrouterQuickStart.runtimeProviderTitle"),description:t("openrouterQuickStart.runtimeProviderManagedDescription"),visual:e.jsx("div",{className:"rounded-lg bg-emerald-500/10 p-2",children:e.jsx(pe,{className:"h-5 w-5 text-emerald-700 dark:text-emerald-300"})}),highlights:[{icon:e.jsx(pe,{className:"h-3.5 w-3.5 text-emerald-600"}),label:t("openrouterQuickStart.runtimeProviderFeatureConnectors")},{icon:e.jsx(ke,{className:"h-3.5 w-3.5 text-emerald-600"}),label:t("openrouterQuickStart.runtimeProviderFeatureSecrets")}],actionLabel:t("openrouterQuickStart.runtimeProviderTitle"),actionClassName:"w-full bg-emerald-600 text-white hover:bg-emerald-600/90",onAction:o,footer:e.jsx("span",{children:t("openrouterQuickStart.runtimeProviderFooter")})})})]})})}function Gs({onCreateClick:s}){const{t:a}=Q();return ve(),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:a("openrouterPromoCard.title")}),e.jsx("p",{className:"text-[10px] text-muted-foreground truncate",children:a("openrouterPromoCard.description")})]}),e.jsxs(C,{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(ze,{className:"w-3 h-3 mr-1"}),e.jsx("span",{className:"text-xs",children:a("openrouterBanner.add")})]})]})})}function Xs({onCreateClick:s}){const{t:a}=Q();return e.jsx("div",{className:"p-3 border-t bg-gradient-to-r from-orange-500/5 to-orange-500/10 dark:from-orange-500/10 dark:to-orange-500/15",children:e.jsxs("div",{className:"flex items-center gap-2",children:[e.jsx("div",{className:"p-1.5 bg-orange-500/10 dark:bg-orange-500/20 rounded shrink-0",children:e.jsx("img",{src:"/assets/providers/alibabacloud-color.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-orange-700 dark:text-orange-300",children:a("alibabaCodingPlanPromo.title")}),e.jsx("p",{className:"text-[10px] text-muted-foreground truncate",children:a("alibabaCodingPlanPromo.subtitle")})]}),e.jsxs(C,{size:"sm",variant:"ghost",onClick:s,className:"h-7 px-2 text-orange-700 dark:text-orange-300 hover:text-orange-700 hover:bg-orange-500/10 dark:hover:bg-orange-500/20",children:[e.jsx(Be,{className:"w-3 h-3 mr-1"}),e.jsx("span",{className:"text-xs",children:a("alibabaCodingPlanPromo.add")})]})]})})}function ut(){const{t:s}=Q(),a=We(),{data:r,isLoading:c,isError:o,refetch:p}=hs(),f=ps(),g=gs(),t=fs(),m=js(),u=Ns(),j=vs(),[P,b]=x.useState(null),[O,y]=x.useState(""),[k,N]=x.useState(!1),[R,v]=x.useState("normal"),[i,h]=x.useState(null),[l,I]=x.useState(!1),[J,q]=x.useState(null),ee=x.useRef(null);bs();const U=x.useMemo(()=>r?.profiles||[],[r?.profiles]),B=x.useMemo(()=>U.filter(n=>n.name.toLowerCase().includes(O.toLowerCase())),[U,O]),S=P?U.find(n=>n.name===P):null,$=n=>{l&&P!==n?q(n):b(n)},se=n=>{f.mutate(n,{onSuccess:()=>{P===n&&(b(null),I(!1),q(null)),h(null)}})},Y=n=>{N(!1),$(n)},le=n=>{$(n)},V=(n,A)=>{const T=JSON.stringify(A,null,2)+`
1
+ import{j as e}from"./radix-ui-Zb8sVEtn.js";import{r as x,h as We}from"./react-vendor-CNOkPC89.js";import{a as Q,B as L,c as H,T as Ye,p as Ve,q as Ge,r as Xe,s as Ze,t as es,v as ss,w as he,d as C,n as oe,L as M,I as z,x as W,y as Re,z as ts,A as as,D as rs,E as ns,S as be,F as te,G as ge,H as Ae,J as is,K as os,M as De,N as _e,O as Me,Q as ls,R as cs,U as we,V as Ce,W as ae,X as ds,Y as Le,Z as ve,C as Qe,b as Fe,j as ms,k as us,_ as xs,$ as hs,a0 as ps,a1 as gs,a2 as fs,a3 as js,a4 as Ns,a5 as vs,a6 as bs,a7 as ws}from"./index-BDfXfBTa.js";import{a as Cs,u as fe,b as ye}from"./tanstack-CrmUhA7Z.js";import{C as je}from"./confirm-dialog-D_5v8muu.js";import{t as E}from"./notifications-B2HqRBj7.js";import{L as re,R as Z,as as He,at as ys,a9 as ne,_ as ks,au as Ie,aa as ie,C as Ue,av as Ss,a7 as Ps,aw as Os,p as Ne,X as Ts,ax as Es,Z as ze,ay as Be,n as ke,az as Se,aA as Rs,aB as pe,a6 as As,ad as Ds,aC as _s,w as Ke,aD as Ms,x as $e,o as Ls,aE as Qs}from"./icons-KVCk4_U8.js";import{M as Je}from"./masked-input-D1Ilmeh7.js";import"./utils-CzKF5WmX.js";import"./form-utils-Bcoyqxpq.js";import"./code-highlight-BRUf_pqB.js";import"./alert-dialog-CuN8HTEx.js";function Fs({className:s,showTooltip:a=!0}){const{t:r}=Q(),c=e.jsxs(L,{variant:"outline",className:H("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(Ye,{children:[e.jsx(Ve,{asChild:!0,children:c}),e.jsx(Ge,{children:e.jsx("p",{children:r("openrouterBadge.integration")})})]}):c}function Pe(s){return[/^ANTHROPIC_AUTH_TOKEN$/,/_API_KEY$/,/_AUTH_TOKEN$/,/^API_KEY$/,/^AUTH_TOKEN$/,/_SECRET$/,/^SECRET$/].some(r=>r.test(s))}function qe(s){return s?.env?(s.env.ANTHROPIC_BASE_URL||"").toLowerCase().includes("openrouter.ai"):!1}function Hs(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 Is(s,a){const r={...s};return a.opus?r.ANTHROPIC_DEFAULT_OPUS_MODEL=a.opus:delete r.ANTHROPIC_DEFAULT_OPUS_MODEL,a.sonnet?r.ANTHROPIC_DEFAULT_SONNET_MODEL=a.sonnet:delete r.ANTHROPIC_DEFAULT_SONNET_MODEL,a.haiku?r.ANTHROPIC_DEFAULT_HAIKU_MODEL=a.haiku:delete r.ANTHROPIC_DEFAULT_HAIKU_MODEL,r}function Us({profileName:s,target:a,data:r,settings:c,isLoading:o,isSaving:p,isTargetSaving:f,hasChanges:g,isRawJsonValid:t,onTargetChange:m,onRefresh:u,onDelete:j,onSave:P}){const{t:b}=Q(),O=p||f,y=o||O;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}),r?.path&&e.jsx(L,{variant:"outline",className:"text-xs",children:r.path.replace(/^.*\//,"")}),qe(c)&&e.jsx(Fs,{className:"ml-1"})]}),r&&e.jsxs("p",{className:"text-xs text-muted-foreground mt-0.5",children:[b("profileEditor.lastModified"),": ",new Date(r.mtime).toLocaleString()]}),e.jsxs("div",{className:"mt-2 flex items-center gap-2",children:[e.jsxs("span",{className:"text-xs text-muted-foreground",children:[b("profileEditor.defaultTarget"),":"]}),e.jsxs(Xe,{value:a,onValueChange:k=>{y||m(k)},disabled:y,children:[e.jsx(Ze,{className:"h-7 w-[170px] text-xs",disabled:y,children:e.jsx(es,{})}),e.jsxs(ss,{children:[e.jsx(he,{value:"claude",children:b("profileEditor.targetClaude")}),e.jsx(he,{value:"droid",children:b("profileEditor.targetDroid")}),e.jsx(he,{value:"codex",children:b("profileEditor.targetCodex")})]})]}),f&&e.jsx(re,{className:"w-3.5 h-3.5 animate-spin text-muted-foreground"})]})]}),e.jsxs("div",{className:"flex items-center gap-2",children:[e.jsx(C,{variant:"ghost",size:"sm",onClick:u,disabled:y,children:e.jsx(Z,{className:`w-4 h-4 ${o?"animate-spin":""}`})}),j&&e.jsx(C,{variant:"ghost",size:"sm",onClick:j,disabled:O,children:e.jsx(He,{className:"w-4 h-4 text-destructive"})}),e.jsx(C,{size:"sm",onClick:P,disabled:O||!g||!t,children:p?e.jsxs(e.Fragment,{children:[e.jsx(re,{className:"w-4 h-4 mr-1 animate-spin"}),b("profileEditor.saving")]}):e.jsxs(e.Fragment,{children:[e.jsx(ys,{className:"w-4 h-4 mr-1"}),b("settingsAuth.save")]})})]})]})}function zs({currentSettings:s,newEnvKey:a,newEnvValue:r,onNewEnvKeyChange:c,onNewEnvValueChange:o,onEnvValueChange:p,onAddEnvVar:f}){const{t:g}=Q();return e.jsxs(e.Fragment,{children:[e.jsx(oe,{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(([t,m])=>e.jsxs("div",{className:"space-y-1.5",children:[e.jsxs(M,{className:"text-xs font-medium flex items-center gap-2 text-muted-foreground",children:[t,Pe(t)&&e.jsx(L,{variant:"secondary",className:"text-[10px] px-1 py-0 h-4",children:g("envEditor.sensitive")})]}),Pe(t)?e.jsx(Je,{value:m,onChange:u=>p(t,u.target.value),className:"font-mono text-sm h-8"}):e.jsx(z,{value:m,onChange:u=>p(t,u.target.value),className:"font-mono text-sm h-8"})]},t))}):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:g("envEditor.none")}),e.jsx("p",{className:"text-xs mt-1 opacity-70",children:g("envEditor.noneHint")})]})})}),e.jsxs("div",{className:"p-4 border-t bg-background shrink-0",children:[e.jsx(M,{className:"text-xs font-medium text-muted-foreground",children:g("envEditor.addVariable")}),e.jsxs("div",{className:"flex gap-2 mt-2",children:[e.jsx(z,{placeholder:g("envEditor.keyPlaceholder"),value:a,onChange:t=>c(t.target.value.toUpperCase()),className:"font-mono text-sm h-8 w-2/5",onKeyDown:t=>t.key==="Enter"&&a.trim()&&f()}),e.jsx(z,{placeholder:g("envEditor.valuePlaceholder"),value:r,onChange:t=>o(t.target.value),className:"font-mono text-sm h-8 flex-1",onKeyDown:t=>t.key==="Enter"&&a.trim()&&f()}),e.jsx(C,{variant:"outline",size:"sm",className:"h-8",onClick:f,disabled:!a.trim(),children:e.jsx(ne,{className:"w-4 h-4"})})]})]})]})}function Bs({profileName:s,target:a,data:r}){const{t:c}=Q(),o=a==="droid";return e.jsx(oe,{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(ks,{className:"w-4 h-4"}),c("profileEditor.profileInfo")]}),e.jsx("div",{className:"space-y-3 bg-card rounded-lg border p-4 shadow-sm",children:r&&e.jsxs(e.Fragment,{children:[e.jsxs("div",{className:"grid grid-cols-[100px_1fr] gap-2 text-sm items-center",children:[e.jsx("span",{className:"font-medium text-muted-foreground",children:c("profileEditor.profileName")}),e.jsx("span",{className:"font-mono",children:r.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:c("profileEditor.filePath")}),e.jsxs("div",{className:"flex items-center gap-2 min-w-0",children:[e.jsx("code",{className:"bg-muted px-1.5 py-0.5 rounded text-xs break-all",children:r.path}),e.jsx(W,{value:r.path,size:"icon",className:"h-5 w-5"})]})]}),e.jsxs("div",{className:"grid grid-cols-[100px_1fr] gap-2 text-sm items-center",children:[e.jsx("span",{className:"font-medium text-muted-foreground",children:c("profileEditor.lastModified")}),e.jsx("span",{className:"text-xs",children:new Date(r.mtime).toLocaleString()})]}),e.jsxs("div",{className:"grid grid-cols-[100px_1fr] gap-2 text-sm items-center",children:[e.jsx("span",{className:"font-medium text-muted-foreground",children:c("profileEditor.defaultTarget")}),e.jsx("span",{className:"font-mono",children:a})]})]})})]}),e.jsxs("div",{children:[e.jsx("h3",{className:"text-sm font-medium mb-3",children:c("profileEditor.quickUsage")}),e.jsxs("div",{className:"space-y-3 bg-card rounded-lg border p-4 shadow-sm",children:[e.jsxs("div",{children:[e.jsx(M,{className:"text-xs text-muted-foreground",children:c("profileEditor.runWithProfile")}),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(W,{value:`ccs ${s} "prompt"`,size:"icon",className:"h-6 w-6"})]})]}),e.jsxs("div",{children:[e.jsx(M,{className:"text-xs text-muted-foreground",children:c(o?"profileEditor.droidAliasExplicit":"profileEditor.runOnDroid")}),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:`ccs-droid ${s} "prompt"`}),e.jsx(W,{value:`ccs-droid ${s} "prompt"`,size:"icon",className:"h-6 w-6"})]})]}),e.jsxs("div",{children:[e.jsx(M,{className:"text-xs text-muted-foreground",children:c(o?"profileEditor.overrideToClaude":"profileEditor.runOnDroidWithFlag")}),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 ",o?"claude":"droid",' "prompt"']}),e.jsx(W,{value:`ccs ${s} --target ${o?"claude":"droid"} "prompt"`,size:"icon",className:"h-6 w-6"})]})]}),e.jsxs("div",{children:[e.jsx(M,{className:"text-xs text-muted-foreground",children:c("profileEditor.setAsDefault")}),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(W,{value:`ccs default ${s}`,size:"icon",className:"h-6 w-6"})]})]})]})]})]})})}function Ks({value:s,onChange:a,placeholder:r,className:c}){const{t:o}=Q(),[p,f]=x.useState(""),[g,t]=x.useState(null),{models:m,isLoading:u,isError:j,isFetching:P}=Re(),b=ts(),O=x.useMemo(()=>as(m,p,{category:g??void 0}),[m,p,g]),y=x.useMemo(()=>rs(m,2),[m]),k=!p.trim()&&!g,N=x.useMemo(()=>{const i={anthropic:[],openai:[],google:[],meta:[],mistral:[],opensource:[],other:[]};O.forEach(h=>{i[h.category].push(h)});for(const h of Object.keys(i))i[h]=ns(i[h]);return i},[O]),R=x.useCallback(()=>{b()},[b]),v=m.find(i=>i.id===s);return u&&m.length===0?e.jsxs("div",{className:H("space-y-2",c),children:[e.jsx(be,{className:"h-10 w-full"}),e.jsx(be,{className:"h-32 w-full"})]}):e.jsxs("div",{className:H("space-y-2 w-full min-w-0 overflow-hidden",c),children:[e.jsxs("div",{className:"flex gap-2",children:[e.jsxs("div",{className:"relative flex-1",children:[e.jsx(Ie,{className:"text-muted-foreground absolute left-3 top-1/2 h-4 w-4 -translate-y-1/2"}),e.jsx(z,{value:p,onChange:i=>f(i.target.value),placeholder:r??o("openrouterModelPicker.searchModels"),className:"pl-9"})]}),e.jsx(C,{variant:"outline",size:"icon",onClick:R,disabled:P,title:"Refresh models",children:P?e.jsx(re,{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(L,{variant:g===null?"default":"outline",className:"cursor-pointer",onClick:()=>t(null),children:["All (",m.length,")"]}),Object.keys(te).map(i=>{const h=N[i].length;return h===0?null:e.jsxs(L,{variant:g===i?"default":"outline",className:"cursor-pointer",onClick:()=>t(i),children:[te[i]," (",h,")"]},i)})]}),v&&e.jsxs("div",{className:"bg-muted rounded-md p-2 text-sm",children:[e.jsx("span",{className:"font-medium",children:v.name}),e.jsxs("span",{className:"text-muted-foreground ml-2",children:[ge(v.pricing)," |"," ",Ae(v.context_length)]})]}),e.jsx(oe,{className:"h-72 w-full rounded-md border",children:j?e.jsxs("div",{className:"text-destructive p-4 text-center",children:["Failed to load models."," ",e.jsx(C,{variant:"link",onClick:R,children:"Retry"})]}):O.length===0?e.jsxs("div",{className:"text-muted-foreground p-4 text-center",children:['No models found matching "',p,'"']}):e.jsxs("div",{className:"space-y-6 p-3",children:[k&&y.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(ie,{className:"h-3 w-3 text-accent"}),e.jsx("span",{children:o("openrouterModelPicker.newestModels")})]}),e.jsx("div",{className:"space-y-1",children:y.map(i=>e.jsx(Oe,{model:i,isSelected:i.id===s,onClick:()=>a(i.id),showAge:!0},i.id))})]}),Object.keys(te).map(i=>{const h=N[i];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:te[i]}),e.jsx("div",{className:"space-y-1",children:h.map(l=>e.jsx(Oe,{model:l,isSelected:l.id===s,onClick:()=>a(l.id)},l.id))})]},i)})]})})]})}function Oe({model:s,isSelected:a,onClick:r,showAge:c=!1}){return e.jsxs("button",{type:"button",onClick:r,className:H("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:H("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:[c&&s.created&&e.jsx(L,{variant:"outline",className:H("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:is(s.created)}),s.isFree?e.jsx(L,{variant:"secondary",className:H("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(L,{variant:"outline",className:H("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:ge(s.pricing)})]}):e.jsx("span",{className:"tabular-nums",children:ge(s.pricing)}),e.jsx("span",{className:"tabular-nums",children:Ae(s.context_length)})]})]})}function $s({selectedModel:s,value:a,onChange:r,className:c}){const{t:o}=Q(),{models:p}=Re(),f=x.useMemo(()=>s?os(s,p):{},[s,p]),g=()=>{r(f)},t=(u,j)=>{r({...a,[u]:j||void 0})},m=s&&Object.keys(f).length>0;return e.jsxs(De,{className:H("group",c),children:[e.jsxs(_e,{className:"flex items-center gap-2 text-sm font-medium hover:underline",children:[e.jsx(Ue,{className:"h-4 w-4 transition-transform group-data-[state=open]:rotate-90"}),o("modelTierMapping.title"),e.jsxs("span",{className:"text-muted-foreground font-normal",children:["(",o("modelTierMapping.advanced"),")"]})]}),e.jsxs(Me,{className:"space-y-3 pt-3",children:[e.jsx("p",{className:"text-muted-foreground text-sm",children:o("modelTierMapping.description")}),m&&e.jsxs(C,{type:"button",variant:"outline",size:"sm",onClick:g,children:[e.jsx(Ss,{className:"mr-1 h-4 w-4"}),o("modelTierMapping.autoSuggest",{provider: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(M,{htmlFor:"tier-opus",className:"text-right",children:"Opus"}),e.jsx(z,{id:"tier-opus",value:a.opus??"",onChange:u=>t("opus",u.target.value),placeholder:o("modelTierMapping.opusPlaceholder")})]}),e.jsxs("div",{className:"grid grid-cols-[80px_1fr] items-center gap-2",children:[e.jsx(M,{htmlFor:"tier-sonnet",className:"text-right",children:"Sonnet"}),e.jsx(z,{id:"tier-sonnet",value:a.sonnet??"",onChange:u=>t("sonnet",u.target.value),placeholder:o("modelTierMapping.sonnetPlaceholder")})]}),e.jsxs("div",{className:"grid grid-cols-[80px_1fr] items-center gap-2",children:[e.jsx(M,{htmlFor:"tier-haiku",className:"text-right",children:"Haiku"}),e.jsx(z,{id:"tier-haiku",value:a.haiku??"",onChange:u=>t("haiku",u.target.value),placeholder:o("modelTierMapping.haikuPlaceholder")})]})]}),e.jsx("p",{className:"text-muted-foreground text-xs",children:o("modelTierMapping.footer")})]})]})}function Js({profileName:s,target:a,data:r,currentSettings:c,newEnvKey:o,newEnvValue:p,onNewEnvKeyChange:f,onNewEnvValueChange:g,onEnvValueChange:t,onAddEnvVar:m,onEnvBulkChange:u}){const{t:j}=Q(),P=qe(c),b=c?.env,O=x.useMemo(()=>Hs(b??{}),[b]),y=b??{},k=l=>{if(u){const I={...y,ANTHROPIC_MODEL:l,ANTHROPIC_DEFAULT_OPUS_MODEL:l,ANTHROPIC_DEFAULT_SONNET_MODEL:l,ANTHROPIC_DEFAULT_HAIKU_MODEL:l};u(I)}else t("ANTHROPIC_MODEL",l),t("ANTHROPIC_DEFAULT_OPUS_MODEL",l),t("ANTHROPIC_DEFAULT_SONNET_MODEL",l),t("ANTHROPIC_DEFAULT_HAIKU_MODEL",l);E.success(ae.t("commonToast.appliedModelAllTiers"),{duration:2e3})},N=l=>{if(u){const I=Is(y,l);u(I)}else l.opus!==void 0&&t("ANTHROPIC_DEFAULT_OPUS_MODEL",l.opus||""),l.sonnet!==void 0&&t("ANTHROPIC_DEFAULT_SONNET_MODEL",l.sonnet||""),l.haiku!==void 0&&t("ANTHROPIC_DEFAULT_HAIKU_MODEL",l.haiku||"")},[R,v]=x.useState(!1),i=new Set(["ANTHROPIC_AUTH_TOKEN"]),h=Object.entries(y).filter(([l])=>!i.has(l));return e.jsx("div",{className:"h-full w-full min-w-0 flex flex-col",children:e.jsxs(ls,{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(cs,{className:"w-full",children:[e.jsx(we,{value:"env",className:"flex-1",children:P?"Configuration":j("settingsDialog.envTab")}),e.jsx(we,{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(Ce,{value:"env",className:"flex-1 mt-0 border-0 p-0 data-[state=inactive]:hidden flex flex-col overflow-hidden min-w-0",children:P?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(M,{className:"text-sm font-medium",children:"Model Selection"}),e.jsx(Ks,{value:y.ANTHROPIC_MODEL,onChange:k,placeholder:"Search OpenRouter models..."})]}),e.jsx($s,{selectedModel:y.ANTHROPIC_MODEL,value:O,onChange:N}),e.jsxs("div",{className:"space-y-2",children:[e.jsx(M,{className:"text-sm font-medium",children:j("profileDialog.apiKey")}),e.jsx(Je,{value:y.ANTHROPIC_AUTH_TOKEN||"",onChange:l=>t("ANTHROPIC_AUTH_TOKEN",l.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(De,{open:R,onOpenChange:v,children:[e.jsxs(_e,{className:"flex items-center gap-2 text-sm font-medium text-muted-foreground hover:text-foreground transition-colors group",children:[e.jsx(Ue,{className:H("h-4 w-4 transition-transform",R&&"rotate-90")}),e.jsx(Ps,{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(Me,{className:"pt-4",children:e.jsx("div",{className:"space-y-3 border rounded-lg p-3 bg-muted/30",children:h.map(([l,I])=>e.jsxs("div",{className:"space-y-1",children:[e.jsx(M,{className:"text-xs text-muted-foreground",children:l}),e.jsx(z,{value:I,onChange:J=>t(l,J.target.value),className:"font-mono text-xs h-8"})]},l))})})]})]})}),e.jsxs("div",{className:"p-4 border-t bg-background shrink-0",children:[e.jsx(M,{className:"text-xs font-medium text-muted-foreground",children:j("envEditor.addVariable")}),e.jsxs("div",{className:"flex gap-2 mt-2",children:[e.jsx(z,{placeholder:j("envEditor.keyPlaceholder"),value:o,onChange:l=>f(l.target.value.toUpperCase()),className:"font-mono text-sm h-8 w-2/5",onKeyDown:l=>l.key==="Enter"&&o.trim()&&m()}),e.jsx(z,{placeholder:j("envEditor.valuePlaceholder"),value:p,onChange:l=>g(l.target.value),className:"font-mono text-sm h-8 flex-1",onKeyDown:l=>l.key==="Enter"&&o.trim()&&m()}),e.jsx(C,{variant:"outline",size:"sm",className:"h-8",onClick:m,disabled:!o.trim(),children:e.jsx(ne,{className:"w-4 h-4"})})]})]})]}):e.jsx(zs,{currentSettings:c,newEnvKey:o,newEnvValue:p,onNewEnvKeyChange:f,onNewEnvValueChange:g,onEnvValueChange:t,onAddEnvVar:m})}),e.jsx(Ce,{value:"info",className:"h-full mt-0 border-0 p-0 data-[state=inactive]:hidden",children:e.jsx(Bs,{profileName:s,target:a,data:r})})]})]})})}function qs({profileName:s,profileTarget:a,onDelete:r,onHasChangesUpdate:c}){const{t:o}=Q(),[p,f]=x.useState({}),[g,t]=x.useState(!1),[m,u]=x.useState(null),[j,P]=x.useState(""),[b,O]=x.useState(""),y=Cs(),{data:k,isLoading:N,isError:R,refetch:v}=fe({queryKey:["settings",s],queryFn:async()=>{const d=await fetch(`/api/settings/${s}/raw`);if(!d.ok)throw new Error(`Failed to load settings: ${d.status}`);return d.json()}}),i=k?.settings,h=x.useMemo(()=>{if(m!==null)try{return JSON.parse(m)}catch{}if(i)return{...i,env:{...i.env,...p}}},[i,p,m]),l=x.useMemo(()=>m!==null?m:i?JSON.stringify(i,null,2):"",[m,i]),I=x.useCallback(d=>{u(d)},[]),J=x.useCallback(d=>{const w={...h??{}},_=w.ccs_image&&typeof w.ccs_image=="object"?{...w.ccs_image}:{};d?_.native_read=!0:delete _.native_read,Object.keys(_).length>0?w.ccs_image=_:delete w.ccs_image,u(JSON.stringify(w,null,2))},[h]),q=(d,w)=>{const _={...h?.env||{},[d]:w};f(G=>({...G,[d]:w})),u(JSON.stringify({...h,env:_},null,2))},ee=d=>{const w={...h?.env||{},...d};f(_=>({..._,...d})),u(JSON.stringify({...h,env:w},null,2))},U=()=>{if(!j.trim())return;const d=j.trim(),w=b,_={...h?.env||{},[d]:w};f(G=>({...G,[d]:w})),u(JSON.stringify({...h,env:_},null,2)),P(""),O("")},B=x.useMemo(()=>{try{return JSON.parse(l),!0}catch{return!1}},[l]),S=x.useMemo(()=>m!==null?m!==JSON.stringify(i,null,2):Object.keys(p).length>0,[m,p,i]),$=x.useDeferredValue(l),se=x.useMemo(()=>{if(!S||!B)return null;try{return JSON.parse($)}catch{return null}},[S,B,$]),{data:Y,isFetching:le,isError:V,isPlaceholderData:ce}=fe({queryKey:["settings",s,"image-analysis-status-preview",$],enabled:se!==null,placeholderData:d=>d,queryFn:async()=>{const d=await fetch(`/api/settings/${s}/image-analysis-status`,{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify({settings:se})});if(!d.ok)throw new Error(`Failed to preview image-analysis status: ${d.status}`);return d.json()}}),de=S&&B&&!V?Y?.imageAnalysisStatus??k?.imageAnalysisStatus:k?.imageAnalysisStatus,me=S&&B&&!V&&Y?.imageAnalysisStatus?"editor":"saved",ue=S?B?V?"saved":le&&(!Y?.imageAnalysisStatus||ce)?"refreshing":"preview":"invalid":"saved",xe=h?.ccs_image?.native_read===!0,n=x.useMemo(()=>{const d=["ANTHROPIC_BASE_URL","ANTHROPIC_AUTH_TOKEN"],w=h?.env||{};return d.filter(_=>!w[_]?.trim())},[h]);x.useEffect(()=>{c?.(S)},[S,c]);const A=ye({mutationFn:async()=>{let d;try{d=JSON.parse(l)}catch{d={...k?.settings,env:{...k?.settings?.env,...p}}}const w=await fetch(`/api/settings/${s}`,{method:"PUT",headers:{"Content-Type":"application/json"},body:JSON.stringify({settings:d,expectedMtime:k?.mtime})});if(w.status===409)throw new Error("CONFLICT");if(!w.ok)throw new Error("Failed to save");return w.json()},onSuccess:()=>{y.invalidateQueries({queryKey:["settings",s]}),y.invalidateQueries({queryKey:["profiles"]}),f({}),u(null),E.success(ae.t("commonToast.settingsSaved"))},onError:d=>{d.message==="CONFLICT"?t(!0):E.error(d.message)}}),T=ye({mutationFn:async d=>(await Le.profiles.update(s,{target:d}),d),onSuccess:()=>{y.invalidateQueries({queryKey:["profiles"]}),E.success(ae.t("commonToast.defaultTargetUpdated"))},onError:(d,w)=>{const _=w==="droid"?"Factory Droid":w==="codex"?"Codex CLI":"Claude Code",G=d.message.trim()?`: ${d.message}`:"";E.error(ae.t("commonToast.failedUpdateDefaultTarget",{target:_,suffix:G}))}}),F=a||"claude",D=A.isPending||T.isPending,K=async d=>{t(!1),d?(await v(),A.mutate()):(f({}),u(null))};return e.jsxs("div",{className:"flex-1 flex flex-col overflow-hidden",children:[e.jsx(Us,{profileName:s,target:F,data:k,settings:h,isLoading:N,isSaving:A.isPending,isTargetSaving:T.isPending,hasChanges:S,isRawJsonValid:B,onTargetChange:d=>{D||d!==F&&T.mutate(d)},onRefresh:()=>{D||v()},onDelete:r,onSave:()=>{D||A.mutate()}}),N?e.jsxs("div",{className:"flex-1 flex items-center justify-center",children:[e.jsx(re,{className:"w-8 h-8 animate-spin text-muted-foreground"}),e.jsx("span",{className:"ml-3 text-muted-foreground",children:o("settingsDialog.loadingSettings")})]}):R?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:o("settingsPage.failedLoad")}),e.jsxs(C,{variant:"outline",size:"sm",onClick:()=>v(),children:[e.jsx(Z,{className:"w-4 h-4 mr-1"}),o("apiProfiles.retry")]})]})}):e.jsxs("div",{className:"min-h-0 flex-1 grid grid-cols-[40%_60%] divide-x overflow-hidden",children:[e.jsx("div",{className:"flex min-h-0 min-w-0 flex-col overflow-hidden bg-muted/5",children:e.jsx(Js,{profileName:s,target:F,data:k,currentSettings:h,newEnvKey:j,newEnvValue:b,onNewEnvKeyChange:P,onNewEnvValueChange:O,onEnvValueChange:q,onEnvBulkChange:ee,onAddEnvVar:U})}),e.jsxs("div",{className:"flex min-h-0 min-w-0 flex-col overflow-hidden",children:[e.jsxs("div",{className:"px-6 py-2 bg-muted/30 border-b flex items-center gap-2 shrink-0 h-[45px]",children:[e.jsx(Os,{className:"w-4 h-4 text-muted-foreground"}),e.jsx("span",{className:"text-sm font-medium text-muted-foreground",children:o("rawEditorSection.rawConfig")})]}),e.jsx(ds,{rawJsonContent:l,isRawJsonValid:B,rawJsonEdits:m,settings:i,profileTarget:F,imageAnalysisStatus:de,imageAnalysisStatusSource:me,imageAnalysisStatusPreviewState:ue,nativeReadPreferenceOverride:xe,onToggleNativeRead:J,onChange:I,missingRequiredFields:n})]})]}),e.jsx(je,{open:g,title:o("settingsDialog.conflictTitle"),description:o("settingsDialog.conflictDesc"),confirmText:o("settingsDialog.overwrite"),variant:"destructive",onConfirm:()=>K(!0),onCancel:()=>K(!1)})]},s)}const Te="ccs:openrouter-banner-dismissed";function Ws({onCreateClick:s}){const{t:a}=Q(),[r,c]=x.useState(!0),{modelCount:o,isLoading:p}=ve();x.useEffect(()=>{const g=localStorage.getItem(Te)==="true";c(g)},[]);const f=()=>{localStorage.setItem(Te,"true"),c(!0)};return r?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(ie,{className:"w-4 h-4"})}),e.jsxs("div",{className:"flex-1 min-w-0",children:[e.jsxs("p",{className:"font-medium text-sm",children:[a("openrouterBadge.new"),": ",a("openrouterBadge.integration")]}),e.jsx("p",{className:"text-xs text-white/80 truncate",children:a("openrouterBanner.accessModels",{count:p?300:o})})]})]}),e.jsxs("div",{className:"flex items-center gap-2 shrink-0",children:[s&&e.jsx(C,{size:"sm",variant:"secondary",onClick:s,className:"bg-white text-accent hover:bg-white/90 h-8",children:a("openrouterBanner.add")}),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(Ne,{className:"w-3 h-3"})]}),e.jsxs(C,{size:"icon",variant:"ghost",onClick:f,className:"h-7 w-7 text-white/70 hover:text-white hover:bg-white/20",children:[e.jsx(Ts,{className:"w-4 h-4"}),e.jsx("span",{className:"sr-only",children:"Dismiss"})]})]})]})})}function Ys(){return fe({queryKey:["profiles","local-runtime-readiness"],queryFn:()=>Le.profiles.getLocalRuntimeReadiness(),staleTime:15e3,refetchOnWindowFocus:!1})}function X({badge:s,badgeClassName:a,className:r,title:c,description:o,visual:p,highlights:f,actionLabel:g,actionClassName:t,onAction:m,footer:u}){return e.jsxs(Qe,{className:H("flex h-full flex-col border shadow-sm",r),children:[e.jsxs(ms,{className:"space-y-3 pb-3",children:[e.jsxs("div",{className:"flex items-center gap-3",children:[p,e.jsx(L,{variant:"secondary",className:a,children:s})]}),e.jsxs("div",{className:"space-y-1.5",children:[e.jsx(us,{className:"text-base",children:c}),e.jsx(xs,{className:"text-sm leading-6",children:o})]})]}),e.jsxs(Fe,{className:"mt-auto flex flex-1 flex-col gap-4 pt-0",children:[e.jsx("div",{className:"space-y-2 text-xs text-muted-foreground",children:f.map(j=>e.jsxs("div",{className:"flex items-center gap-2",children:[j.icon,e.jsx("span",{children:j.label})]},j.label))}),e.jsxs(C,{onClick:m,className:t,children:[g,e.jsx(As,{className:"ml-2 h-4 w-4"})]}),u?e.jsx("div",{className:"text-xs text-muted-foreground",children:u}):null]})]})}function Ee(s,a,r){return s?s.status==="ready"?{badge:r("openrouterQuickStart.localRuntimeReadyBadge"),badgeClassName:"bg-emerald-500/10 text-emerald-700 dark:bg-emerald-500/20 dark:text-emerald-200",actionLabel:r("openrouterQuickStart.localRuntimeUseAction",{label:a}),description:r("openrouterQuickStart.localRuntimeReadyDescription"),footer:r("openrouterQuickStart.localRuntimeReadyFooter",{endpoint:s.endpoint})}:s.status==="missing-model"?{badge:r("openrouterQuickStart.localRuntimeNeedsModelBadge"),badgeClassName:"bg-amber-500/10 text-amber-700 dark:bg-amber-500/20 dark:text-amber-200",actionLabel:r("openrouterQuickStart.localRuntimeFinishAction",{label:a}),description:r("openrouterQuickStart.localRuntimeNeedsModelDescription"),footer:r("openrouterQuickStart.localRuntimeMissingModelFooter",{command:s.commandHint})}:{badge:r("openrouterQuickStart.localRuntimeOfflineBadge"),badgeClassName:"bg-muted text-muted-foreground",actionLabel:r("openrouterQuickStart.localRuntimeSetupAction",{label:a}),description:r("openrouterQuickStart.localRuntimeOfflineDescription"),footer:r("openrouterQuickStart.localRuntimeOfflineFooter",{command:s.commandHint})}:{badge:r("openrouterQuickStart.localRuntimeCheckingBadge"),badgeClassName:"bg-muted text-muted-foreground",actionLabel:r("openrouterQuickStart.localRuntimeSetupAction",{label:a}),description:r("openrouterQuickStart.localRuntimeCheckingDescription"),footer:r("openrouterQuickStart.localRuntimeCheckingFooter")}}function Vs({hasProfiles:s,profileCount:a,onOpenRouterClick:r,onAlibabaCodingPlanClick:c,onCliproxyClick:o,onCustomClick:p,onOllamaClick:f,onLlamacppClick:g}){const{t}=Q(),{modelCount:m,isLoading:u}=ve(),{data:j}=Ys(),P=u?"300+":`${m}+`,b=s?t("openrouterQuickStart.profileSummaryCount",{count:a}):t("openrouterQuickStart.profileSummaryEmpty"),O=t(s?"openrouterQuickStart.summaryExistingTitle":"openrouterQuickStart.summaryEmptyTitle"),y=s?t("openrouterQuickStart.summaryExistingDescription",{count:a}):t("openrouterQuickStart.summaryEmptyDescription"),k=j?.runtimes.find(i=>i.id==="ollama"),N=j?.runtimes.find(i=>i.id==="llamacpp"),R=Ee(k,t("openrouterQuickStart.localOllamaLabel"),t),v=Ee(N,t("openrouterQuickStart.localLlamacppLabel"),t);return e.jsx("div",{className:"flex h-full min-h-0 flex-col overflow-auto bg-muted/20 p-4 sm:p-6",children:e.jsxs("div",{className:"mx-auto flex w-full max-w-7xl flex-col gap-5",children:[e.jsx(Qe,{className:"border-dashed bg-background/90 shadow-sm",children:e.jsxs(Fe,{className:"flex flex-col gap-4 p-5 lg:flex-row lg:items-center lg:justify-between",children:[e.jsxs("div",{className:"space-y-2",children:[e.jsxs("div",{className:"flex flex-wrap items-center gap-2",children:[e.jsx(L,{variant:"secondary",children:b}),e.jsx(L,{variant:"outline",children:t("openrouterQuickStart.summaryBadgeDefaultQuality")}),e.jsx(L,{variant:"outline",children:t("openrouterQuickStart.summaryBadgeLocalLane")})]}),e.jsxs("div",{className:"space-y-1",children:[e.jsx("h2",{className:"text-xl font-semibold",children:O}),e.jsx("p",{className:"max-w-3xl text-sm leading-6 text-muted-foreground",children:y})]})]}),e.jsx(C,{variant:"outline",onClick:p,className:"shrink-0",children:t("openrouterQuickStart.createCustomProfile")})]})}),e.jsxs("div",{className:"space-y-2",children:[e.jsxs("div",{className:"flex items-center gap-2",children:[e.jsx(Es,{className:"h-4 w-4 text-accent"}),e.jsx("h3",{className:"text-sm font-semibold uppercase tracking-[0.12em] text-foreground/70",children:t("openrouterQuickStart.qualityLanesTitle")})]}),e.jsxs("div",{className:"grid gap-4 lg:grid-cols-2",children:[e.jsx(X,{badge:t("openrouterQuickStart.recommended"),title:t("openrouterQuickStart.title"),description:t("openrouterQuickStart.description",{modelCountLabel:P}),visual:e.jsx("div",{className:"rounded-lg bg-accent/10 p-2",children:e.jsx("img",{src:"/icons/openrouter.svg",alt:"OpenRouter",className:"h-5 w-5"})}),highlights:[{icon:e.jsx(ze,{className:"h-3.5 w-3.5 text-accent"}),label:t("openrouterQuickStart.featureOneApi")},{icon:e.jsx(ie,{className:"h-3.5 w-3.5 text-accent"}),label:t("openrouterQuickStart.qualityLaneHighlightDefaultQuality")}],actionLabel:t("openrouterQuickStart.createOpenRouterProfile"),actionClassName:"w-full bg-accent text-white hover:bg-accent/90",onAction:r,footer:e.jsxs(e.Fragment,{children:[t("openrouterQuickStart.getApiKeyAt")," ",e.jsxs("a",{href:"https://openrouter.ai/keys",target:"_blank",rel:"noopener noreferrer",className:"inline-flex items-center gap-1 text-accent hover:underline",children:["openrouter.ai/keys",e.jsx(Ne,{className:"h-3 w-3"})]})]})}),e.jsx(X,{badge:t("alibabaCodingPlanQuickStart.recommended"),badgeClassName:"bg-orange-500/10 text-orange-700 dark:bg-orange-500/20 dark:text-orange-200",title:t("alibabaCodingPlanQuickStart.title"),description:t("openrouterQuickStart.alibabaLaneDescription"),visual:e.jsx("div",{className:"rounded-lg bg-orange-500/10 p-2",children:e.jsx("img",{src:"/assets/providers/alibabacloud-color.svg",alt:"Alibaba Coding Plan",className:"h-5 w-5"})}),highlights:[{icon:e.jsx(Be,{className:"h-3.5 w-3.5 text-orange-600"}),label:t("alibabaCodingPlanQuickStart.featureEndpoint")},{icon:e.jsx(ke,{className:"h-3.5 w-3.5 text-orange-600"}),label:t("openrouterQuickStart.alibabaLaneHighlightQuality")}],actionLabel:t("alibabaCodingPlanQuickStart.createAlibabaProfile"),actionClassName:"w-full bg-orange-600 text-white hover:bg-orange-600/90",onAction:c,footer:e.jsxs(e.Fragment,{children:[t("alibabaCodingPlanQuickStart.readGuideAt")," ",e.jsxs("a",{href:"https://www.alibabacloud.com/help/en/model-studio/coding-plan",target:"_blank",rel:"noopener noreferrer",className:"inline-flex items-center gap-1 text-orange-700 hover:underline dark:text-orange-400",children:["Alibaba Cloud Model Studio",e.jsx(Ne,{className:"h-3 w-3"})]})]})})]})]}),e.jsxs("div",{className:"space-y-2",children:[e.jsxs("div",{className:"flex items-center gap-2",children:[e.jsx(Se,{className:"h-4 w-4 text-emerald-600"}),e.jsx("h3",{className:"text-sm font-semibold uppercase tracking-[0.12em] text-foreground/70",children:t("openrouterQuickStart.localRuntimesTitle")})]}),e.jsxs("div",{className:"grid gap-4 lg:grid-cols-2",children:[e.jsx(X,{badge:R.badge,badgeClassName:R.badgeClassName,title:t("openrouterQuickStart.localOllamaTitle"),description:R.description,visual:e.jsx("div",{className:"rounded-lg bg-emerald-500/10 p-2",children:e.jsx("img",{src:"/icons/ollama.svg",alt:"Ollama",className:"h-5 w-5"})}),highlights:[{icon:e.jsx(Rs,{className:"h-3.5 w-3.5 text-emerald-600"}),label:t("openrouterQuickStart.localOllamaHighlight")},{icon:e.jsx(ie,{className:"h-3.5 w-3.5 text-emerald-600"}),label:k?.detectedModelCount&&k.detectedModelCount>0?t("openrouterQuickStart.localDetectedModels",{count:k.detectedModelCount}):t("openrouterQuickStart.localNoModelsDetected")}],actionLabel:R.actionLabel,actionClassName:"w-full bg-emerald-600 text-white hover:bg-emerald-600/90",onAction:f,footer:e.jsx("span",{children:R.footer})}),e.jsx(X,{badge:v.badge,badgeClassName:v.badgeClassName,title:t("openrouterQuickStart.localLlamacppTitle"),description:v.description,visual:e.jsx("div",{className:"rounded-lg bg-sky-500/10 p-2",children:e.jsx("img",{src:"/assets/providers/llama-cpp.svg",alt:"llama.cpp",className:"h-5 w-5"})}),highlights:[{icon:e.jsx(pe,{className:"h-3.5 w-3.5 text-sky-600"}),label:t("openrouterQuickStart.localLlamacppHighlight")},{icon:e.jsx(Se,{className:"h-3.5 w-3.5 text-sky-600"}),label:N?.detectedModelCount&&N.detectedModelCount>0?t("openrouterQuickStart.localDetectedModels",{count:N.detectedModelCount}):t("openrouterQuickStart.localWaitingServer")}],actionLabel:v.actionLabel,actionClassName:"w-full bg-sky-600 text-white hover:bg-sky-600/90",onAction:g,footer:e.jsx("span",{children:v.footer})})]})]}),e.jsx("div",{className:"grid gap-4 lg:grid-cols-2",children:e.jsx(X,{badge:t("openrouterQuickStart.runtimeProviderBadge"),badgeClassName:"bg-emerald-500/10 text-emerald-700 dark:bg-emerald-500/20 dark:text-emerald-200",title:t("openrouterQuickStart.runtimeProviderTitle"),description:t("openrouterQuickStart.runtimeProviderManagedDescription"),visual:e.jsx("div",{className:"rounded-lg bg-emerald-500/10 p-2",children:e.jsx(pe,{className:"h-5 w-5 text-emerald-700 dark:text-emerald-300"})}),highlights:[{icon:e.jsx(pe,{className:"h-3.5 w-3.5 text-emerald-600"}),label:t("openrouterQuickStart.runtimeProviderFeatureConnectors")},{icon:e.jsx(ke,{className:"h-3.5 w-3.5 text-emerald-600"}),label:t("openrouterQuickStart.runtimeProviderFeatureSecrets")}],actionLabel:t("openrouterQuickStart.runtimeProviderTitle"),actionClassName:"w-full bg-emerald-600 text-white hover:bg-emerald-600/90",onAction:o,footer:e.jsx("span",{children:t("openrouterQuickStart.runtimeProviderFooter")})})})]})})}function Gs({onCreateClick:s}){const{t:a}=Q();return ve(),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:a("openrouterPromoCard.title")}),e.jsx("p",{className:"text-[10px] text-muted-foreground truncate",children:a("openrouterPromoCard.description")})]}),e.jsxs(C,{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(ze,{className:"w-3 h-3 mr-1"}),e.jsx("span",{className:"text-xs",children:a("openrouterBanner.add")})]})]})})}function Xs({onCreateClick:s}){const{t:a}=Q();return e.jsx("div",{className:"p-3 border-t bg-gradient-to-r from-orange-500/5 to-orange-500/10 dark:from-orange-500/10 dark:to-orange-500/15",children:e.jsxs("div",{className:"flex items-center gap-2",children:[e.jsx("div",{className:"p-1.5 bg-orange-500/10 dark:bg-orange-500/20 rounded shrink-0",children:e.jsx("img",{src:"/assets/providers/alibabacloud-color.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-orange-700 dark:text-orange-300",children:a("alibabaCodingPlanPromo.title")}),e.jsx("p",{className:"text-[10px] text-muted-foreground truncate",children:a("alibabaCodingPlanPromo.subtitle")})]}),e.jsxs(C,{size:"sm",variant:"ghost",onClick:s,className:"h-7 px-2 text-orange-700 dark:text-orange-300 hover:text-orange-700 hover:bg-orange-500/10 dark:hover:bg-orange-500/20",children:[e.jsx(Be,{className:"w-3 h-3 mr-1"}),e.jsx("span",{className:"text-xs",children:a("alibabaCodingPlanPromo.add")})]})]})})}function ut(){const{t:s}=Q(),a=We(),{data:r,isLoading:c,isError:o,refetch:p}=hs(),f=ps(),g=gs(),t=fs(),m=js(),u=Ns(),j=vs(),[P,b]=x.useState(null),[O,y]=x.useState(""),[k,N]=x.useState(!1),[R,v]=x.useState("normal"),[i,h]=x.useState(null),[l,I]=x.useState(!1),[J,q]=x.useState(null),ee=x.useRef(null);bs();const U=x.useMemo(()=>r?.profiles||[],[r?.profiles]),B=x.useMemo(()=>U.filter(n=>n.name.toLowerCase().includes(O.toLowerCase())),[U,O]),S=P?U.find(n=>n.name===P):null,$=n=>{l&&P!==n?q(n):b(n)},se=n=>{f.mutate(n,{onSuccess:()=>{P===n&&(b(null),I(!1),q(null)),h(null)}})},Y=n=>{N(!1),$(n)},le=n=>{$(n)},V=(n,A)=>{const T=JSON.stringify(A,null,2)+`
2
2
  `,F=new Blob([T],{type:"application/json"}),D=URL.createObjectURL(F),K=document.createElement("a");K.href=D,K.download=n,document.body.appendChild(K),K.click(),K.remove(),URL.revokeObjectURL(D)},ce=async()=>{try{const n=await g.mutateAsync();if(n.orphans.length===0){E.success(s("apiProfiles.noOrphansFound"));return}const A=n.orphans.filter(K=>K.validation.valid).length;if(!window.confirm(s("apiProfiles.confirmRegisterOrphans",{total:n.orphans.length,valid:A})))return;const F=await t.mutateAsync({}),D=F.skipped.length>0?s("apiProfiles.registeredWithSkipped",{count:F.skipped.length}):"";E.success(s("apiProfiles.registeredProfiles",{count:F.registered.length})+D)}catch(n){E.error(n.message)}},de=async()=>{if(!S)return;const n=window.prompt(s("apiProfiles.copyPrompt",{name:S.name}),`${S.name}-copy`);if(!n)return;const A=n.trim();if(!A){E.error(s("apiProfiles.destinationEmpty"));return}try{const T=await m.mutateAsync({name:S.name,data:{destination:A}});$(A),T.warnings&&T.warnings.length>0&&E.info(T.warnings.join(`
3
3
  `))}catch(T){E.error(T.message)}},me=async()=>{if(S)try{const n=await u.mutateAsync({name:S.name});V(`${S.name}.ccs-profile.json`,n.bundle),n.redacted?E.info(s("apiProfiles.exportRedacted")):E.success(s("apiProfiles.exportDownloaded"))}catch(n){E.error(n.message)}},ue=()=>{ee.current?.click()},xe=async n=>{const A=n.target.files?.[0];if(n.target.value="",!!A)try{const T=await A.text(),F=JSON.parse(T),D=await j.mutateAsync({bundle:F});D.name&&$(D.name),D.warnings&&D.warnings.length>0&&E.info(D.warnings.join(`
4
4
  `))}catch(T){E.error(T.message||s("apiProfiles.importFailed"))}};return e.jsxs("div",{className:"flex h-full min-h-0 flex-col overflow-hidden",children:[e.jsx(Ws,{onCreateClick:()=>N(!0)}),e.jsxs("div",{className:"flex-1 flex min-h-0 overflow-hidden",children:[e.jsxs("div",{className:"w-80 border-r flex flex-col bg-muted/30",children:[e.jsxs("div",{className:"p-4 border-b bg-background",children:[e.jsxs("div",{className:"mb-3 flex items-start justify-between gap-3",children:[e.jsxs("div",{className:"flex items-center gap-2",children:[e.jsx(Ds,{className:"w-5 h-5 text-primary"}),e.jsx("div",{className:"min-w-0",children:e.jsx("h1",{className:"font-semibold",children:s("apiProfiles.sidebarTitle")})})]}),e.jsxs("div",{className:"flex shrink-0 items-center gap-1",children:[e.jsx(C,{size:"sm",variant:"outline",onClick:()=>void ce(),disabled:g.isPending||t.isPending,"aria-label":s("apiProfiles.discoverOrphans"),title:s("apiProfiles.discoverOrphans"),children:e.jsx(Z,{className:`w-4 h-4 ${g.isPending?"animate-spin":""}`})}),e.jsx(C,{size:"sm",variant:"outline",onClick:ue,disabled:j.isPending,"aria-label":s("apiProfiles.importProfileBundle"),title:s("apiProfiles.importProfileBundle"),children:e.jsx(_s,{className:"w-4 h-4"})}),e.jsxs(C,{size:"sm",onClick:()=>{N(!0)},children:[e.jsx(ne,{className:"w-4 h-4 mr-1"}),s("apiProfiles.new")]})]})]}),e.jsx("p",{className:"mb-3 text-xs leading-4 text-muted-foreground",children:s("apiProfiles.sidebarSubtitle")}),e.jsxs("div",{className:"relative",children:[e.jsx(Ie,{className:"absolute left-2.5 top-2.5 h-4 w-4 text-muted-foreground"}),e.jsx(z,{placeholder:s("apiProfiles.searchPlaceholder"),className:"pl-8 h-9",value:O,onChange:n=>y(n.target.value)})]})]}),e.jsx(oe,{className:"flex-1 min-h-0",children:c?e.jsx("div",{className:"p-4 text-sm text-muted-foreground",children:s("apiProfiles.loadingProfiles")}):o?e.jsx("div",{className:"p-4 text-center",children:e.jsxs("div",{className:"space-y-3 py-8",children:[e.jsx(Ke,{className:"w-12 h-12 mx-auto text-destructive/50"}),e.jsxs("div",{children:[e.jsx("p",{className:"text-sm font-medium",children:s("apiProfiles.failedLoadTitle")}),e.jsx("p",{className:"text-xs text-muted-foreground mt-1",children:s("apiProfiles.failedLoadDesc")})]}),e.jsxs(C,{size:"sm",variant:"outline",onClick:()=>p(),children:[e.jsx(Z,{className:"w-4 h-4 mr-1"}),s("apiProfiles.retry")]})]})}):B.length===0?e.jsx("div",{className:"p-4 text-center",children:U.length===0?e.jsxs("div",{className:"space-y-3 py-8",children:[e.jsx(Ms,{className:"w-12 h-12 mx-auto text-muted-foreground/50"}),e.jsxs("div",{children:[e.jsx("p",{className:"text-sm font-medium",children:s("apiProfiles.noProfilesYet")}),e.jsx("p",{className:"text-xs text-muted-foreground mt-1",children:s("apiProfiles.noProfilesDesc")})]}),e.jsxs(C,{size:"sm",variant:"outline",onClick:()=>{N(!0)},children:[e.jsx(ne,{className:"w-4 h-4 mr-1"}),s("apiProfiles.createProfile")]})]}):e.jsx("p",{className:"text-sm text-muted-foreground py-4",children:s("apiProfiles.noProfileMatch",{query:O})})}):e.jsx("div",{className:"p-2 space-y-1",children:B.map(n=>e.jsx(Zs,{profile:n,isSelected:P===n.name,onSelect:()=>le(n.name),onDelete:()=>h(n.name)},n.name))})}),U.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.jsx("span",{children:s("apiProfiles.profileCount",{count:U.length})}),e.jsxs("span",{className:"flex items-center gap-1",children:[e.jsx($e,{className:"w-3 h-3 text-green-600"}),s("apiProfiles.configuredCount",{count:U.filter(n=>n.configured).length})]})]})}),e.jsx(Gs,{onCreateClick:()=>{v("openrouter"),N(!0)}}),e.jsx(Xs,{onCreateClick:()=>{v("alibaba-coding-plan"),N(!0)}})]}),e.jsx("div",{className:"flex min-h-0 flex-1 flex-col min-w-0 overflow-hidden",children:S?e.jsxs(e.Fragment,{children:[e.jsxs("div",{className:"px-4 py-2 border-b bg-background flex items-center justify-end gap-2",children:[e.jsxs(C,{size:"sm",variant:"outline",onClick:()=>void de(),disabled:m.isPending,children:[e.jsx(Ls,{className:"w-4 h-4 mr-1"}),"Copy"]}),e.jsxs(C,{size:"sm",variant:"outline",onClick:()=>void me(),disabled:u.isPending,children:[e.jsx(Qs,{className:"w-4 h-4 mr-1"}),"Export"]})]}),e.jsx(qs,{profileName:S.name,profileTarget:S.target,onDelete:()=>h(S.name),onHasChangesUpdate:I},S.name)]}):e.jsx(Vs,{hasProfiles:U.length>0,profileCount:U.length,onCliproxyClick:()=>{a("/cliproxy/ai-providers")},onOpenRouterClick:()=>{v("openrouter"),N(!0)},onAlibabaCodingPlanClick:()=>{v("alibaba-coding-plan"),N(!0)},onOllamaClick:()=>{v("ollama"),N(!0)},onLlamacppClick:()=>{v("llamacpp"),N(!0)},onCustomClick:()=>{v("normal"),N(!0)}})})]}),e.jsx("input",{ref:ee,type:"file",accept:".json,application/json",className:"hidden",onChange:n=>void xe(n)}),e.jsx(ws,{open:k,onOpenChange:N,onSuccess:Y,initialMode:R}),e.jsx(je,{open:!!i,title:s("apiProfiles.deleteProfileTitle"),description:s("apiProfiles.deleteProfileDesc",{name:i??""}),confirmText:s("apiProfiles.delete"),variant:"destructive",onConfirm:()=>i&&se(i),onCancel:()=>h(null)}),e.jsx(je,{open:!!J,title:s("apiProfiles.unsavedChangesTitle"),description:s("apiProfiles.unsavedChangesDesc",{current:P??"",next:J??""}),confirmText:s("apiProfiles.discardSwitch"),variant:"destructive",onConfirm:()=>{I(!1),b(J),q(null)},onCancel:()=>q(null)})]})}function Zs({profile:s,isSelected:a,onSelect:r,onDelete:c}){return e.jsxs("div",{className:H("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:r,children:[s.configured?e.jsx($e,{className:"w-4 h-4 text-green-600 shrink-0"}):e.jsx(Ke,{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(L,{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(W,{value:s.settingsPath,size:"icon",className:"h-5 w-5 opacity-0 group-hover:opacity-100 transition-opacity"})]})]}),e.jsx(C,{variant:"ghost",size:"icon",className:"h-7 w-7 opacity-0 group-hover:opacity-100 transition-opacity",onClick:o=>{o.stopPropagation(),c()},children:e.jsx(He,{className:"w-3.5 h-3.5 text-destructive"})})]})}export{ut as ApiPage};
@@ -1 +1 @@
1
- import{j as e}from"./radix-ui-Zb8sVEtn.js";import{r as n}from"./react-vendor-CNOkPC89.js";import{a as V,bv as W,be as X,bg as Y,n as Z,I as C,d as c}from"./index-DNmWbKbN.js";import{R as E,w as _,x as ee,n as se,E as K,g as T,m as R,o as z,ah as te,aa as ae,Q as ne,at as re}from"./icons-KVCk4_U8.js";import"./tanstack-CrmUhA7Z.js";import"./notifications-B2HqRBj7.js";import"./utils-CzKF5WmX.js";import"./form-utils-Bcoyqxpq.js";import"./code-highlight-BRUf_pqB.js";function pe(){const{t:s}=V(),{fetchRawConfig:o}=W(),[a,D]=n.useState(null),[j,S]=n.useState(!0),[i,m]=n.useState(!1),[p,r]=n.useState(null),[g,f]=n.useState(null),[w,P]=n.useState(!1),[y,O]=n.useState(!1),[d,N]=n.useState(null),[u,v]=n.useState(null),[$,b]=n.useState(!1),[F,k]=n.useState(!1),h=n.useCallback(async()=>{try{S(!0),r(null);const t=await fetch("/api/settings/auth/tokens/raw");if(!t.ok)throw new Error(s("settingsAuth.failedFetchTokens"));const l=await t.json();D(l)}catch(t){r(t instanceof Error?t.message:s("settings.unknownError"))}finally{S(!1)}},[s]);n.useEffect(()=>{h(),o()},[h,o]),n.useEffect(()=>{if(g){const t=setTimeout(()=>f(null),3e3);return()=>clearTimeout(t)}},[g]),n.useEffect(()=>{if(p){const t=setTimeout(()=>r(null),5e3);return()=>clearTimeout(t)}},[p]);const I=async()=>{const t=d!==null&&d!==a?.apiKey.value,l=u!==null&&u!==a?.managementSecret.value;if(!(!t&&!l))try{m(!0),r(null);const x={};t&&(x.apiKey=d),l&&(x.managementSecret=u);const A=await fetch("/api/settings/auth/tokens",{method:"PUT",headers:{"Content-Type":"application/json"},body:JSON.stringify(x)});if(!A.ok){const M=await A.json();throw new Error(M.error||s("settingsAuth.failedSaveTokens"))}f(s("settingsAuth.tokensUpdated")),N(null),v(null),await h(),await o()}catch(x){r(x instanceof Error?x.message:s("settings.unknownError"))}finally{m(!1)}},U=async()=>{try{m(!0),r(null);const t=await fetch("/api/settings/auth/tokens/regenerate-secret",{method:"POST"});if(!t.ok){const l=await t.json();throw new Error(l.error||s("settingsAuth.failedRegenerate"))}f(s("settingsAuth.secretRegenerated")),await h(),await o()}catch(t){r(t instanceof Error?t.message:s("settings.unknownError"))}finally{m(!1)}},B=async()=>{try{m(!0),r(null);const t=await fetch("/api/settings/auth/tokens/reset",{method:"POST"});if(!t.ok){const l=await t.json();throw new Error(l.error||s("settingsAuth.failedReset"))}f(s("settingsAuth.tokensReset")),N(null),v(null),await h(),await o()}catch(t){r(t instanceof Error?t.message:s("settings.unknownError"))}finally{m(!1)}},J=async()=>{a&&(await navigator.clipboard.writeText(a.apiKey.value),b(!0),setTimeout(()=>b(!1),2e3))},L=async()=>{a&&(await navigator.clipboard.writeText(a.managementSecret.value),k(!0),setTimeout(()=>k(!1),2e3))},Q=async()=>{j||i||(r(null),f(null),await Promise.all([h(),o()]))};if(j||!a)return e.jsx("div",{className:"flex-1 flex items-center justify-center",children:e.jsxs("div",{className:"flex items-center gap-3 text-muted-foreground",children:[e.jsx(E,{className:"w-5 h-5 animate-spin"}),e.jsx("span",{children:s("settings.loading")})]})});const q=d??a.apiKey.value,G=u??a.managementSecret.value,H=d!==null&&d!==a.apiKey.value||u!==null&&u!==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 ${p||g?"opacity-100 translate-y-0":"opacity-0 -translate-y-2 pointer-events-none"}`,children:[p&&e.jsxs(X,{variant:"destructive",className:"py-2 shadow-lg",children:[e.jsx(_,{className:"h-4 w-4"}),e.jsx(Y,{children:p})]}),g&&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(ee,{className:"h-4 w-4 shrink-0"}),e.jsx("span",{className:"text-sm font-medium",children:g})]})]}),e.jsx(Z,{className:"flex-1",children:e.jsxs("div",{className:"p-5 space-y-6",children:[e.jsx("p",{className:"text-sm text-muted-foreground",children:s("settingsAuth.description")}),e.jsxs("div",{className:"space-y-3",children:[e.jsxs("div",{className:"flex items-center gap-2",children:[e.jsx(se,{className:"w-4 h-4 text-primary"}),e.jsx("h3",{className:"text-base font-medium",children:s("settingsAuth.apiKey")}),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:s("settingsAuth.custom")})]}),e.jsx("p",{className:"text-xs text-muted-foreground",children:s("settingsAuth.apiKeyDesc")}),e.jsx("div",{className:"flex gap-2",children:e.jsxs("div",{className:"relative flex-1",children:[e.jsx(C,{type:w?"text":"password",value:q,onChange:t=>N(t.target.value),placeholder:s("settingsAuth.apiKeyPlaceholder"),disabled:i,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(c,{variant:"ghost",size:"sm",className:"h-7 w-7 p-0",onClick:()=>P(!w),children:w?e.jsx(K,{className:"w-4 h-4"}):e.jsx(T,{className:"w-4 h-4"})}),e.jsx(c,{variant:"ghost",size:"sm",className:"h-7 w-7 p-0",onClick:J,disabled:!a.apiKey.value,children:$?e.jsx(R,{className:"w-4 h-4 text-green-600"}):e.jsx(z,{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(te,{className:"w-4 h-4 text-primary"}),e.jsx("h3",{className:"text-base font-medium",children:s("settingsAuth.managementSecret")}),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:s("settingsAuth.custom")})]}),e.jsx("p",{className:"text-xs text-muted-foreground",children:s("settingsAuth.managementSecretDesc")}),e.jsxs("div",{className:"flex gap-2",children:[e.jsxs("div",{className:"relative flex-1",children:[e.jsx(C,{type:y?"text":"password",value:G,onChange:t=>v(t.target.value),placeholder:s("settingsAuth.managementSecretPlaceholder"),disabled:i,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(c,{variant:"ghost",size:"sm",className:"h-7 w-7 p-0",onClick:()=>O(!y),children:y?e.jsx(K,{className:"w-4 h-4"}):e.jsx(T,{className:"w-4 h-4"})}),e.jsx(c,{variant:"ghost",size:"sm",className:"h-7 w-7 p-0",onClick:L,disabled:!a.managementSecret.value,children:F?e.jsx(R,{className:"w-4 h-4 text-green-600"}):e.jsx(z,{className:"w-4 h-4"})})]})]}),e.jsx(c,{variant:"outline",size:"sm",onClick:U,disabled:i,title:s("settingsAuth.generateSecret"),children:e.jsx(ae,{className:"w-4 h-4"})})]})]}),e.jsxs("div",{className:"pt-4 border-t",children:[e.jsxs(c,{variant:"outline",size:"sm",onClick:B,disabled:i||!a.apiKey.isCustom&&!a.managementSecret.isCustom,className:"gap-2",children:[e.jsx(ne,{className:"w-4 h-4"}),s("settingsAuth.resetDefaults")]}),e.jsx("p",{className:"text-xs text-muted-foreground mt-2",children:s("settingsAuth.resetDesc")})]})]})}),e.jsxs("div",{className:"p-4 border-t bg-background flex gap-2",children:[e.jsxs(c,{variant:"outline",size:"sm",onClick:Q,disabled:j||i,className:"flex-1",children:[e.jsx(E,{className:`w-4 h-4 mr-2 ${j?"animate-spin":""}`}),s("settings.refresh")]}),e.jsxs(c,{variant:"default",size:"sm",onClick:I,disabled:!H||i,className:"flex-1",children:[e.jsx(re,{className:`w-4 h-4 mr-2 ${i?"animate-pulse":""}`}),s(i?"settingsAuth.saving":"settingsAuth.save")]})]})]})}export{pe as default};
1
+ import{j as e}from"./radix-ui-Zb8sVEtn.js";import{r as n}from"./react-vendor-CNOkPC89.js";import{a as V,bv as W,be as X,bg as Y,n as Z,I as C,d as c}from"./index-BDfXfBTa.js";import{R as E,w as _,x as ee,n as se,E as K,g as T,m as R,o as z,ah as te,aa as ae,Q as ne,at as re}from"./icons-KVCk4_U8.js";import"./tanstack-CrmUhA7Z.js";import"./notifications-B2HqRBj7.js";import"./utils-CzKF5WmX.js";import"./form-utils-Bcoyqxpq.js";import"./code-highlight-BRUf_pqB.js";function pe(){const{t:s}=V(),{fetchRawConfig:o}=W(),[a,D]=n.useState(null),[j,S]=n.useState(!0),[i,m]=n.useState(!1),[p,r]=n.useState(null),[g,f]=n.useState(null),[w,P]=n.useState(!1),[y,O]=n.useState(!1),[d,N]=n.useState(null),[u,v]=n.useState(null),[$,b]=n.useState(!1),[F,k]=n.useState(!1),h=n.useCallback(async()=>{try{S(!0),r(null);const t=await fetch("/api/settings/auth/tokens/raw");if(!t.ok)throw new Error(s("settingsAuth.failedFetchTokens"));const l=await t.json();D(l)}catch(t){r(t instanceof Error?t.message:s("settings.unknownError"))}finally{S(!1)}},[s]);n.useEffect(()=>{h(),o()},[h,o]),n.useEffect(()=>{if(g){const t=setTimeout(()=>f(null),3e3);return()=>clearTimeout(t)}},[g]),n.useEffect(()=>{if(p){const t=setTimeout(()=>r(null),5e3);return()=>clearTimeout(t)}},[p]);const I=async()=>{const t=d!==null&&d!==a?.apiKey.value,l=u!==null&&u!==a?.managementSecret.value;if(!(!t&&!l))try{m(!0),r(null);const x={};t&&(x.apiKey=d),l&&(x.managementSecret=u);const A=await fetch("/api/settings/auth/tokens",{method:"PUT",headers:{"Content-Type":"application/json"},body:JSON.stringify(x)});if(!A.ok){const M=await A.json();throw new Error(M.error||s("settingsAuth.failedSaveTokens"))}f(s("settingsAuth.tokensUpdated")),N(null),v(null),await h(),await o()}catch(x){r(x instanceof Error?x.message:s("settings.unknownError"))}finally{m(!1)}},U=async()=>{try{m(!0),r(null);const t=await fetch("/api/settings/auth/tokens/regenerate-secret",{method:"POST"});if(!t.ok){const l=await t.json();throw new Error(l.error||s("settingsAuth.failedRegenerate"))}f(s("settingsAuth.secretRegenerated")),await h(),await o()}catch(t){r(t instanceof Error?t.message:s("settings.unknownError"))}finally{m(!1)}},B=async()=>{try{m(!0),r(null);const t=await fetch("/api/settings/auth/tokens/reset",{method:"POST"});if(!t.ok){const l=await t.json();throw new Error(l.error||s("settingsAuth.failedReset"))}f(s("settingsAuth.tokensReset")),N(null),v(null),await h(),await o()}catch(t){r(t instanceof Error?t.message:s("settings.unknownError"))}finally{m(!1)}},J=async()=>{a&&(await navigator.clipboard.writeText(a.apiKey.value),b(!0),setTimeout(()=>b(!1),2e3))},L=async()=>{a&&(await navigator.clipboard.writeText(a.managementSecret.value),k(!0),setTimeout(()=>k(!1),2e3))},Q=async()=>{j||i||(r(null),f(null),await Promise.all([h(),o()]))};if(j||!a)return e.jsx("div",{className:"flex-1 flex items-center justify-center",children:e.jsxs("div",{className:"flex items-center gap-3 text-muted-foreground",children:[e.jsx(E,{className:"w-5 h-5 animate-spin"}),e.jsx("span",{children:s("settings.loading")})]})});const q=d??a.apiKey.value,G=u??a.managementSecret.value,H=d!==null&&d!==a.apiKey.value||u!==null&&u!==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 ${p||g?"opacity-100 translate-y-0":"opacity-0 -translate-y-2 pointer-events-none"}`,children:[p&&e.jsxs(X,{variant:"destructive",className:"py-2 shadow-lg",children:[e.jsx(_,{className:"h-4 w-4"}),e.jsx(Y,{children:p})]}),g&&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(ee,{className:"h-4 w-4 shrink-0"}),e.jsx("span",{className:"text-sm font-medium",children:g})]})]}),e.jsx(Z,{className:"flex-1",children:e.jsxs("div",{className:"p-5 space-y-6",children:[e.jsx("p",{className:"text-sm text-muted-foreground",children:s("settingsAuth.description")}),e.jsxs("div",{className:"space-y-3",children:[e.jsxs("div",{className:"flex items-center gap-2",children:[e.jsx(se,{className:"w-4 h-4 text-primary"}),e.jsx("h3",{className:"text-base font-medium",children:s("settingsAuth.apiKey")}),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:s("settingsAuth.custom")})]}),e.jsx("p",{className:"text-xs text-muted-foreground",children:s("settingsAuth.apiKeyDesc")}),e.jsx("div",{className:"flex gap-2",children:e.jsxs("div",{className:"relative flex-1",children:[e.jsx(C,{type:w?"text":"password",value:q,onChange:t=>N(t.target.value),placeholder:s("settingsAuth.apiKeyPlaceholder"),disabled:i,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(c,{variant:"ghost",size:"sm",className:"h-7 w-7 p-0",onClick:()=>P(!w),children:w?e.jsx(K,{className:"w-4 h-4"}):e.jsx(T,{className:"w-4 h-4"})}),e.jsx(c,{variant:"ghost",size:"sm",className:"h-7 w-7 p-0",onClick:J,disabled:!a.apiKey.value,children:$?e.jsx(R,{className:"w-4 h-4 text-green-600"}):e.jsx(z,{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(te,{className:"w-4 h-4 text-primary"}),e.jsx("h3",{className:"text-base font-medium",children:s("settingsAuth.managementSecret")}),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:s("settingsAuth.custom")})]}),e.jsx("p",{className:"text-xs text-muted-foreground",children:s("settingsAuth.managementSecretDesc")}),e.jsxs("div",{className:"flex gap-2",children:[e.jsxs("div",{className:"relative flex-1",children:[e.jsx(C,{type:y?"text":"password",value:G,onChange:t=>v(t.target.value),placeholder:s("settingsAuth.managementSecretPlaceholder"),disabled:i,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(c,{variant:"ghost",size:"sm",className:"h-7 w-7 p-0",onClick:()=>O(!y),children:y?e.jsx(K,{className:"w-4 h-4"}):e.jsx(T,{className:"w-4 h-4"})}),e.jsx(c,{variant:"ghost",size:"sm",className:"h-7 w-7 p-0",onClick:L,disabled:!a.managementSecret.value,children:F?e.jsx(R,{className:"w-4 h-4 text-green-600"}):e.jsx(z,{className:"w-4 h-4"})})]})]}),e.jsx(c,{variant:"outline",size:"sm",onClick:U,disabled:i,title:s("settingsAuth.generateSecret"),children:e.jsx(ae,{className:"w-4 h-4"})})]})]}),e.jsxs("div",{className:"pt-4 border-t",children:[e.jsxs(c,{variant:"outline",size:"sm",onClick:B,disabled:i||!a.apiKey.isCustom&&!a.managementSecret.isCustom,className:"gap-2",children:[e.jsx(ne,{className:"w-4 h-4"}),s("settingsAuth.resetDefaults")]}),e.jsx("p",{className:"text-xs text-muted-foreground mt-2",children:s("settingsAuth.resetDesc")})]})]})}),e.jsxs("div",{className:"p-4 border-t bg-background flex gap-2",children:[e.jsxs(c,{variant:"outline",size:"sm",onClick:Q,disabled:j||i,className:"flex-1",children:[e.jsx(E,{className:`w-4 h-4 mr-2 ${j?"animate-spin":""}`}),s("settings.refresh")]}),e.jsxs(c,{variant:"default",size:"sm",onClick:I,disabled:!H||i,className:"flex-1",children:[e.jsx(re,{className:`w-4 h-4 mr-2 ${i?"animate-pulse":""}`}),s(i?"settingsAuth.saving":"settingsAuth.save")]})]})]})}export{pe as default};
@@ -1 +1 @@
1
- import{j as e}from"./radix-ui-Zb8sVEtn.js";import{r}from"./react-vendor-CNOkPC89.js";import{a as S,bv as E,n as k,S as n,C as g,be as R,bg as D,B as T,d as C}from"./index-DNmWbKbN.js";import{A as O,a as _,b as F,c as I,d as P,e as z,f as L,g as U}from"./alert-dialog-BA39vaYL.js";import{w as $,x as H,ae as v,v as M,Q as Y,R as J}from"./icons-KVCk4_U8.js";import"./tanstack-CrmUhA7Z.js";import"./notifications-B2HqRBj7.js";import"./utils-CzKF5WmX.js";import"./form-utils-Bcoyqxpq.js";import"./code-highlight-BRUf_pqB.js";const Q=3e3,q=5e3;function ae(){const{t}=S(),{fetchRawConfig:p}=E(),m=r.useRef(null),d=r.useRef(null),[j,y]=r.useState([]),[f,N]=r.useState(!0),[u,w]=r.useState(null),[i,l]=r.useState(null),[c,b]=r.useState(null),[x,h]=r.useState(null),o=r.useCallback(async()=>{m.current?.abort(),m.current=new AbortController;try{N(!0),l(null);const s=await fetch("/api/persist/backups",{signal:m.current.signal});if(!s.ok)throw new Error(t("settingsBackups.failedFetch"));const a=await s.json();y(a.backups||[])}catch(s){if(s instanceof Error&&s.name==="AbortError")return;l(s instanceof Error?s.message:t("settings.unknownError"))}finally{N(!1)}},[t]),A=r.useCallback(async s=>{d.current?.abort(),d.current=new AbortController;try{w(s),l(null);const a=await fetch("/api/persist/restore",{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify({timestamp:s}),signal:d.current.signal});if(!a.ok){const B=await a.json();throw new Error(B.error||t("settingsBackups.failedRestore"))}b(t("settingsBackups.restoreSuccess")),await o(),await p()}catch(a){if(a instanceof Error&&a.name==="AbortError")return;l(a instanceof Error?a.message:t("settings.unknownError"))}finally{w(null)}},[o,p,t]);return r.useEffect(()=>{o()},[o]),r.useEffect(()=>()=>{m.current?.abort(),d.current?.abort()},[]),r.useEffect(()=>{if(c){const s=setTimeout(()=>b(null),Q);return()=>clearTimeout(s)}},[c]),r.useEffect(()=>{if(i){const s=setTimeout(()=>l(null),q);return()=>clearTimeout(s)}},[i]),f?e.jsxs(e.Fragment,{children:[e.jsx(k,{className:"flex-1",children:e.jsxs("div",{className:"p-5 space-y-4",children:[e.jsxs("div",{className:"space-y-2",children:[e.jsx(n,{className:"h-6 w-40"}),e.jsx(n,{className:"h-4 w-full"})]}),[1,2,3].map(s=>e.jsx(g,{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(n,{className:"h-4 w-32"}),e.jsx(n,{className:"h-3 w-48"})]}),e.jsx(n,{className:"h-8 w-20"})]})},s))]})}),e.jsx("div",{className:"p-4 border-t bg-background",children:e.jsx(n,{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 ${i||c?"opacity-100 translate-y-0":"opacity-0 -translate-y-2 pointer-events-none"}`,children:[i&&e.jsxs(R,{variant:"destructive",className:"py-2 shadow-lg",children:[e.jsx($,{className:"h-4 w-4"}),e.jsx(D,{children:i})]}),c&&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(H,{className:"h-4 w-4 shrink-0"}),e.jsx("span",{className:"text-sm font-medium",children:c})]})]}),e.jsx(k,{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(v,{className:"w-5 h-5 text-primary"}),e.jsx("h2",{className:"text-lg font-semibold",children:t("settingsBackups.title")})]}),e.jsx("p",{className:"text-sm text-muted-foreground",children:t("settingsBackups.description")})]}),j.length===0?e.jsx(g,{className:"p-8",children:e.jsxs("div",{className:"text-center",children:[e.jsx(v,{className:"w-12 h-12 mx-auto mb-3 opacity-30 text-muted-foreground"}),e.jsx("p",{className:"text-sm text-muted-foreground",children:t("settingsBackups.none")}),e.jsx("p",{className:"text-xs text-muted-foreground mt-1",children:t("settingsBackups.noneHint")})]})}):e.jsx("div",{className:"space-y-2",children:j.map((s,a)=>e.jsx(g,{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(M,{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}),a===0&&e.jsx(T,{variant:"secondary",className:"text-xs",children:t("settingsBackups.latest")})]}),e.jsx("p",{className:"text-xs text-muted-foreground",children:s.date})]})]}),e.jsxs(C,{variant:"outline",size:"sm",onClick:()=>h(s.timestamp),disabled:u!==null,className:"gap-2 shrink-0",children:[e.jsx(Y,{className:`w-4 h-4 ${u===s.timestamp?"animate-spin":""}`}),u===s.timestamp?t("settingsBackups.restoring"):t("settingsBackups.restore")]})]})},s.timestamp))})]})}),e.jsx("div",{className:"p-4 border-t bg-background",children:e.jsxs(C,{variant:"outline",size:"sm",onClick:()=>{o(),p()},disabled:f||u!==null,className:"w-full",children:[e.jsx(J,{className:`w-4 h-4 mr-2 ${f?"animate-spin":""}`}),t("settings.refresh")]})}),e.jsx(O,{open:!!x,onOpenChange:()=>h(null),children:e.jsxs(_,{children:[e.jsxs(F,{children:[e.jsx(I,{children:t("settingsBackups.restoreConfirmTitle")}),e.jsxs(P,{children:[t("settingsBackups.restoreConfirmPrefix")," ",e.jsx("code",{className:"font-mono bg-muted px-1.5 py-0.5 rounded text-foreground",children:x}),". ",t("settingsBackups.restoreConfirmSuffix")]})]}),e.jsxs(z,{children:[e.jsx(L,{children:t("settingsBackups.cancel")}),e.jsx(U,{onClick:()=>{x&&A(x),h(null)},children:t("settingsBackups.restore")})]})]})})]})}export{ae as default};
1
+ import{j as e}from"./radix-ui-Zb8sVEtn.js";import{r}from"./react-vendor-CNOkPC89.js";import{a as S,bv as E,n as k,S as n,C as g,be as R,bg as D,B as T,d as C}from"./index-BDfXfBTa.js";import{A as O,a as _,b as F,c as I,d as P,e as z,f as L,g as U}from"./alert-dialog-CuN8HTEx.js";import{w as $,x as H,ae as v,v as M,Q as Y,R as J}from"./icons-KVCk4_U8.js";import"./tanstack-CrmUhA7Z.js";import"./notifications-B2HqRBj7.js";import"./utils-CzKF5WmX.js";import"./form-utils-Bcoyqxpq.js";import"./code-highlight-BRUf_pqB.js";const Q=3e3,q=5e3;function ae(){const{t}=S(),{fetchRawConfig:p}=E(),m=r.useRef(null),d=r.useRef(null),[j,y]=r.useState([]),[f,N]=r.useState(!0),[u,w]=r.useState(null),[i,l]=r.useState(null),[c,b]=r.useState(null),[x,h]=r.useState(null),o=r.useCallback(async()=>{m.current?.abort(),m.current=new AbortController;try{N(!0),l(null);const s=await fetch("/api/persist/backups",{signal:m.current.signal});if(!s.ok)throw new Error(t("settingsBackups.failedFetch"));const a=await s.json();y(a.backups||[])}catch(s){if(s instanceof Error&&s.name==="AbortError")return;l(s instanceof Error?s.message:t("settings.unknownError"))}finally{N(!1)}},[t]),A=r.useCallback(async s=>{d.current?.abort(),d.current=new AbortController;try{w(s),l(null);const a=await fetch("/api/persist/restore",{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify({timestamp:s}),signal:d.current.signal});if(!a.ok){const B=await a.json();throw new Error(B.error||t("settingsBackups.failedRestore"))}b(t("settingsBackups.restoreSuccess")),await o(),await p()}catch(a){if(a instanceof Error&&a.name==="AbortError")return;l(a instanceof Error?a.message:t("settings.unknownError"))}finally{w(null)}},[o,p,t]);return r.useEffect(()=>{o()},[o]),r.useEffect(()=>()=>{m.current?.abort(),d.current?.abort()},[]),r.useEffect(()=>{if(c){const s=setTimeout(()=>b(null),Q);return()=>clearTimeout(s)}},[c]),r.useEffect(()=>{if(i){const s=setTimeout(()=>l(null),q);return()=>clearTimeout(s)}},[i]),f?e.jsxs(e.Fragment,{children:[e.jsx(k,{className:"flex-1",children:e.jsxs("div",{className:"p-5 space-y-4",children:[e.jsxs("div",{className:"space-y-2",children:[e.jsx(n,{className:"h-6 w-40"}),e.jsx(n,{className:"h-4 w-full"})]}),[1,2,3].map(s=>e.jsx(g,{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(n,{className:"h-4 w-32"}),e.jsx(n,{className:"h-3 w-48"})]}),e.jsx(n,{className:"h-8 w-20"})]})},s))]})}),e.jsx("div",{className:"p-4 border-t bg-background",children:e.jsx(n,{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 ${i||c?"opacity-100 translate-y-0":"opacity-0 -translate-y-2 pointer-events-none"}`,children:[i&&e.jsxs(R,{variant:"destructive",className:"py-2 shadow-lg",children:[e.jsx($,{className:"h-4 w-4"}),e.jsx(D,{children:i})]}),c&&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(H,{className:"h-4 w-4 shrink-0"}),e.jsx("span",{className:"text-sm font-medium",children:c})]})]}),e.jsx(k,{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(v,{className:"w-5 h-5 text-primary"}),e.jsx("h2",{className:"text-lg font-semibold",children:t("settingsBackups.title")})]}),e.jsx("p",{className:"text-sm text-muted-foreground",children:t("settingsBackups.description")})]}),j.length===0?e.jsx(g,{className:"p-8",children:e.jsxs("div",{className:"text-center",children:[e.jsx(v,{className:"w-12 h-12 mx-auto mb-3 opacity-30 text-muted-foreground"}),e.jsx("p",{className:"text-sm text-muted-foreground",children:t("settingsBackups.none")}),e.jsx("p",{className:"text-xs text-muted-foreground mt-1",children:t("settingsBackups.noneHint")})]})}):e.jsx("div",{className:"space-y-2",children:j.map((s,a)=>e.jsx(g,{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(M,{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}),a===0&&e.jsx(T,{variant:"secondary",className:"text-xs",children:t("settingsBackups.latest")})]}),e.jsx("p",{className:"text-xs text-muted-foreground",children:s.date})]})]}),e.jsxs(C,{variant:"outline",size:"sm",onClick:()=>h(s.timestamp),disabled:u!==null,className:"gap-2 shrink-0",children:[e.jsx(Y,{className:`w-4 h-4 ${u===s.timestamp?"animate-spin":""}`}),u===s.timestamp?t("settingsBackups.restoring"):t("settingsBackups.restore")]})]})},s.timestamp))})]})}),e.jsx("div",{className:"p-4 border-t bg-background",children:e.jsxs(C,{variant:"outline",size:"sm",onClick:()=>{o(),p()},disabled:f||u!==null,className:"w-full",children:[e.jsx(J,{className:`w-4 h-4 mr-2 ${f?"animate-spin":""}`}),t("settings.refresh")]})}),e.jsx(O,{open:!!x,onOpenChange:()=>h(null),children:e.jsxs(_,{children:[e.jsxs(F,{children:[e.jsx(I,{children:t("settingsBackups.restoreConfirmTitle")}),e.jsxs(P,{children:[t("settingsBackups.restoreConfirmPrefix")," ",e.jsx("code",{className:"font-mono bg-muted px-1.5 py-0.5 rounded text-foreground",children:x}),". ",t("settingsBackups.restoreConfirmSuffix")]})]}),e.jsxs(z,{children:[e.jsx(L,{children:t("settingsBackups.cancel")}),e.jsx(U,{onClick:()=>{x&&A(x),h(null)},children:t("settingsBackups.restore")})]})]})})]})}export{ae as default};
@@ -1 +1 @@
1
- import{j as e}from"./radix-ui-Zb8sVEtn.js";import{r as l}from"./react-vendor-CNOkPC89.js";import{a as L,bv as B,be as y,bg as w,n as O,B as $,L as A,aF as U,I as V,d as M}from"./index-DNmWbKbN.js";import{R as D,w as k,x as K,ab as _,at as q,as as G,aG as J}from"./icons-KVCk4_U8.js";import"./tanstack-CrmUhA7Z.js";import"./notifications-B2HqRBj7.js";import"./utils-CzKF5WmX.js";import"./form-utils-Bcoyqxpq.js";import"./code-highlight-BRUf_pqB.js";const F={selected:[],unattended:!1};async function C(t,d){try{const a=await t.json();return typeof a.error=="string"&&a.error.trim().length>0?a.error:d}catch{return d}}function Y(){const[t,d]=l.useState(F),[a,v]=l.useState(null),[h,j]=l.useState(!0),[b,c]=l.useState(!1),[N,u]=l.useState(null),[S,m]=l.useState(null),f=l.useCallback(r=>{m(r),window.setTimeout(()=>m(null),1500)},[]),p=l.useCallback(async()=>{try{j(!0),u(null);const r=await fetch("/api/channels");if(!r.ok)throw new Error(await C(r,"Failed to load Official Channels settings"));const i=await r.json();return d(i.config??F),v(i.status??null),!0}catch(r){return u(r instanceof Error?r.message:"Unknown error"),!1}finally{j(!1)}},[]),T=l.useCallback(async(r,i="Settings saved")=>{try{c(!0),u(null);const n=await fetch("/api/channels",{method:"PUT",headers:{"Content-Type":"application/json"},body:JSON.stringify(r)});if(!n.ok)throw new Error(await C(n,"Failed to save Official Channels settings"));const s=await n.json();return d(o=>s.config??{...o,...r}),f(i),!0}catch(n){return u(n instanceof Error?n.message:"Unknown error"),!1}finally{c(!1)}},[f]),E=l.useCallback(async(r,i)=>{try{c(!0),u(null);const n=await fetch(`/api/channels/${r}/token`,{method:"PUT",headers:{"Content-Type":"application/json"},body:JSON.stringify({token:i})});if(!n.ok)throw new Error(await C(n,`Failed to save ${r} token`));return await p()?(f(`${r} token saved`),!0):!1}catch(n){return u(n instanceof Error?n.message:"Unknown error"),!1}finally{c(!1)}},[p,f]),P=l.useCallback(async r=>{try{c(!0),u(null);const i=await fetch(`/api/channels/${r}/token`,{method:"DELETE"});if(!i.ok)throw new Error(await C(i,`Failed to clear ${r} token`));return await p()?(f(`${r} token cleared`),!0):!1}catch(i){return u(i instanceof Error?i.message:"Unknown error"),!1}finally{c(!1)}},[p,f]);return{config:t,status:a,loading:h,saving:b,error:N,success:S,fetchConfig:p,updateConfig:T,saveToken:E,clearToken:P}}const z={telegram:"",discord:"",imessage:""};function H(t){return t==="ready"?"border-green-200 bg-green-50 text-green-900 dark:border-green-900/60 dark:bg-green-950/40 dark:text-green-100":t==="limited"?"border-amber-200 bg-amber-50 text-amber-900 dark:border-amber-900/60 dark:bg-amber-950/40 dark:text-amber-100":"border-blue-200 bg-blue-50 text-blue-900 dark:border-blue-900/60 dark:bg-blue-950/40 dark:text-blue-100"}function Q(t){return t==="ready"?"default":t==="not_selected"?"secondary":t==="unavailable"?"destructive":"outline"}function W(t){return t==="ready"?"default":t==="partial"?"outline":t==="blocked"?"destructive":"secondary"}function X(t,d){return t.length===0?"None selected":t.map(a=>d?.find(v=>v.id===a)?.displayName??a).join(", ")}function de(){const{t}=L(),{config:d,status:a,loading:v,saving:h,error:j,success:b,fetchConfig:c,updateConfig:N,saveToken:u,clearToken:S}=Y(),{fetchRawConfig:m}=B(),[f,p]=l.useState(z),T=X(d.selected,a?.channels);l.useEffect(()=>{c(),m()},[c,m]);const E=async()=>{await Promise.all([c(),m()])},P=async(s,o)=>{const x=o?[...new Set([...d.selected,s])]:d.selected.filter(R=>R!==s);await N({selected:x},o?`${s} selected for auto-enable`:`${s} removed from auto-enable`)&&await Promise.all([c(),m()])},r=(s,o)=>{p(x=>({...x,[s]:o}))},i=async s=>{await u(s,f[s])&&(p(x=>({...x,[s]:""})),await m())},n=async s=>{await S(s)&&(p(x=>({...x,[s]:""})),await m())};return v?e.jsx("div",{className:"flex flex-1 items-center justify-center",children:e.jsxs("div",{className:"flex items-center gap-3 text-muted-foreground",children:[e.jsx(D,{className:"h-5 w-5 animate-spin"}),e.jsx("span",{children:t("settings.loading")})]})}):e.jsxs(e.Fragment,{children:[e.jsxs("div",{className:`absolute left-5 right-5 top-20 z-10 transition-all duration-200 ease-out ${j||b?"translate-y-0 opacity-100":"pointer-events-none -translate-y-2 opacity-0"}`,children:[j&&e.jsxs(y,{variant:"destructive",className:"py-2 shadow-lg",children:[e.jsx(k,{className:"h-4 w-4"}),e.jsx(w,{children:j})]}),b&&e.jsxs("div",{className:"flex items-center gap-2 rounded-md border border-green-200 bg-green-50 px-3 py-2 text-green-700 shadow-lg dark:border-green-900/50 dark:bg-green-900/90 dark:text-green-300",children:[e.jsx(K,{className:"h-4 w-4 shrink-0"}),e.jsx("span",{className:"text-sm font-medium",children:b})]})]}),e.jsx(O,{className:"flex-1",children:e.jsxs("div",{className:"space-y-6 p-5",children:[e.jsxs("div",{className:"flex items-start gap-3",children:[e.jsx(_,{className:"h-5 w-5 text-primary"}),e.jsxs("div",{className:"space-y-1",children:[e.jsx("p",{className:"font-medium",children:t("settingsPage.channelsSection.title")}),e.jsxs("p",{className:"text-sm text-muted-foreground",children:["Configure official Claude channels here, then run ",e.jsx("code",{children:"ccs"})," normally on a supported native Claude session."]}),e.jsxs("p",{className:"text-sm text-muted-foreground",children:["CCS stores only channel selection in ",e.jsx("code",{children:"config.yaml"}),". Claude keeps the machine-level channel state under ",e.jsx("code",{children:"~/.claude/channels/"}),"."]})]})]}),a&&e.jsxs("div",{className:`rounded-xl border p-4 ${H(a.summary.state)}`,children:[e.jsxs("div",{className:"flex flex-wrap items-start justify-between gap-3",children:[e.jsxs("div",{className:"space-y-2",children:[e.jsxs("div",{className:"flex items-center gap-2",children:[e.jsx($,{variant:a.summary.state==="ready"?"default":"outline",children:a.summary.title}),e.jsx("span",{className:"text-sm font-medium",children:T})]}),e.jsx("p",{className:"text-sm",children:a.summary.message}),e.jsx("p",{className:"text-sm opacity-90",children:a.summary.nextStep})]}),e.jsxs("div",{className:"min-w-[220px] rounded-lg border border-current/10 bg-background/60 p-3 text-sm text-foreground",children:[e.jsx("p",{className:"font-medium",children:"Machine checks"}),e.jsxs("div",{className:"mt-2 space-y-1 text-muted-foreground",children:[e.jsxs("div",{className:"flex items-center justify-between gap-4",children:[e.jsx("span",{children:"Bun"}),e.jsx("span",{children:a.bunInstalled?"Installed":"Missing"})]}),e.jsxs("div",{className:"flex items-center justify-between gap-4",children:[e.jsx("span",{children:"Claude Code"}),e.jsx("span",{children:a.claudeVersion.current?`v${a.claudeVersion.current}`:"Unknown"})]}),e.jsxs("div",{className:"flex items-center justify-between gap-4",children:[e.jsx("span",{children:"Claude auth"}),e.jsx("span",{children:a.auth.authMethod??"Unknown"})]})]})]})]}),a.summary.blockers.length>0&&e.jsx("div",{className:"mt-3 space-y-1 text-sm",children:a.summary.blockers.map(s=>e.jsx("p",{children:s},s))})]}),a&&e.jsxs("div",{className:"rounded-lg border bg-muted/20 p-4",children:[e.jsx("p",{className:"font-medium",children:"Fastest path"}),e.jsxs("div",{className:"mt-3 space-y-2 text-sm text-muted-foreground",children:[e.jsx("p",{children:"1. Turn on the channels you want below."}),e.jsx("p",{children:"2. Save Telegram or Discord bot tokens here if that channel needs one."}),e.jsxs("p",{children:["3. Run ",e.jsx("code",{children:"ccs"})," or a native Claude account profile. CCS adds"," ",e.jsx("code",{children:"--channels"})," for you on supported runs."]}),e.jsx("p",{children:a.supportMessage})]}),e.jsxs("details",{className:"mt-3 rounded-lg border bg-background p-4",children:[e.jsx("summary",{className:"cursor-pointer text-sm font-medium",children:"Advanced notes and scope"}),e.jsxs("div",{className:"mt-3 space-y-2 text-sm text-muted-foreground",children:[e.jsx("p",{children:a.accountStatusCaveat}),e.jsx("p",{children:a.stateScopeMessage})]})]})]}),a&&e.jsxs("div",{className:"rounded-lg border bg-background p-4",children:[e.jsxs("div",{className:"flex flex-wrap items-start justify-between gap-3",children:[e.jsxs("div",{className:"space-y-1",children:[e.jsxs("p",{className:"font-medium",children:["If you run ",e.jsx("code",{children:"ccs"})," now"]}),e.jsx("p",{className:"text-sm text-muted-foreground",children:a.launchPreview.detail})]}),e.jsx($,{variant:W(a.launchPreview.state),children:a.launchPreview.title})]}),e.jsxs("div",{className:"mt-3 space-y-2",children:[e.jsxs("div",{className:"rounded-md bg-muted px-3 py-2 font-mono text-sm",children:[e.jsx("span",{className:"text-muted-foreground",children:"You type:"})," ",a.launchPreview.command]}),e.jsxs("div",{className:"rounded-md bg-muted px-3 py-2 font-mono text-sm break-all",children:[e.jsx("span",{className:"text-muted-foreground",children:"CCS adds:"})," ",a.launchPreview.appendedArgs.length>0?a.launchPreview.appendedArgs.join(" "):"(nothing yet)"]})]}),a.launchPreview.skippedMessages.length>0&&e.jsx("div",{className:"mt-3 space-y-1 text-sm text-muted-foreground",children:a.launchPreview.skippedMessages.map(s=>e.jsx("p",{children:s},s))})]}),a?.claudeVersion.message&&a.claudeVersion.state!=="supported"&&e.jsxs(y,{children:[e.jsx(k,{className:"h-4 w-4"}),e.jsx(w,{children:a.claudeVersion.message})]}),a?.auth.message&&a.auth.state!=="eligible"&&e.jsxs(y,{children:[e.jsx(k,{className:"h-4 w-4"}),e.jsx(w,{children:a.auth.message})]}),a?.auth.orgRequirementMessage&&e.jsxs(y,{children:[e.jsx(k,{className:"h-4 w-4"}),e.jsx(w,{children:a.auth.orgRequirementMessage})]}),e.jsx("div",{className:"space-y-4",children:a?.channels.map(s=>{const o=d.selected.includes(s.id),x=f[s.id];return e.jsxs("div",{className:"rounded-lg border p-4 space-y-4",children:[e.jsxs("div",{className:"flex items-start justify-between gap-4",children:[e.jsxs("div",{children:[e.jsx(A,{className:"text-base font-medium",children:s.displayName}),e.jsx("p",{className:"mt-1 text-sm text-muted-foreground",children:s.summary}),e.jsx("p",{className:"mt-2 font-mono text-xs text-muted-foreground",children:s.pluginSpec})]}),e.jsxs("div",{className:"flex items-center gap-3",children:[e.jsx($,{variant:Q(s.setup.state),children:s.setup.label}),e.jsx(U,{checked:o,disabled:h||!!s.unavailableReason&&!o,onCheckedChange:g=>void P(s.id,g)})]})]}),e.jsxs("div",{className:"rounded-lg bg-muted/30 p-4 text-sm text-muted-foreground space-y-2",children:[e.jsx("p",{children:s.setup.detail}),e.jsx("p",{children:s.setup.nextStep})]}),s.requiresToken&&e.jsxs("div",{className:"space-y-3 rounded-lg bg-muted/30 p-4",children:[e.jsx("p",{className:"text-sm text-muted-foreground",children:!s.tokenConfigured&&s.tokenSource==="process_env"?`The current CCS process already has ${s.envKey}. Save it here only if you want persistent Claude channel state.`:s.tokenConfigured&&s.processEnvAvailable?`${s.envKey} is saved in Claude channel state, and the current CCS process env also provides it.`:`Save ${s.envKey} in Claude's official channel env file. The dashboard never reads the token value back after save.`}),s.tokenConfigured&&e.jsxs("p",{className:"text-sm text-muted-foreground",children:["Saving here writes the same ",e.jsx("code",{children:".env"})," file as"," ",e.jsxs("code",{children:["/",s.id,":configure"]}),", so you do not need to run the configure command again after a successful save."]}),e.jsx(V,{type:"password",value:x,onChange:g=>r(s.id,g.target.value),placeholder:s.tokenConfigured?`Configured. Enter a new ${s.envKey} to replace it.`:!s.tokenConfigured&&s.tokenSource==="process_env"?`Using current CCS process env. Enter a new ${s.envKey} to save it for Claude.`:`Paste ${s.envKey}`,disabled:h}),s.tokenPath&&s.tokenSource!=="process_env"&&e.jsx("div",{className:"text-xs text-muted-foreground break-all",children:s.tokenPath}),e.jsxs("div",{className:"flex flex-wrap gap-2",children:[e.jsxs(M,{onClick:()=>void i(s.id),disabled:h||!x.trim(),children:[e.jsx(q,{className:"mr-2 h-4 w-4"}),"Save Token"]}),e.jsxs(M,{variant:"outline",onClick:()=>void n(s.id),disabled:h||!s.tokenConfigured,children:[e.jsx(G,{className:"mr-2 h-4 w-4"}),"Clear Saved Token"]})]})]}),e.jsxs("details",{className:"rounded-lg border bg-background p-4",children:[e.jsx("summary",{className:"cursor-pointer text-sm font-medium",children:"Claude-side setup commands"}),e.jsx("div",{className:"mt-3 space-y-2",children:(s.manualSetupCommands??[]).map(g=>e.jsx("div",{className:"rounded-md bg-muted px-3 py-2 font-mono text-sm break-all",children:g},g))})]})]},s.id)})}),e.jsx(y,{children:e.jsxs(w,{children:["CCS injects ",e.jsx("code",{children:"--channels"})," only for the current Claude session. Telegram, Discord, and iMessage stop receiving messages when that Claude session exits."]})}),e.jsx("div",{className:"rounded-lg border p-4",children:e.jsxs("div",{className:"flex items-start justify-between gap-4 rounded-lg bg-muted/30 p-4",children:[e.jsxs("div",{className:"flex gap-3",children:[e.jsx(J,{className:"mt-0.5 h-4 w-4 shrink-0 text-amber-600"}),e.jsxs("div",{children:[e.jsx(A,{className:"text-sm font-medium",children:t("profileEditorSections.skipPermissionPrompts")}),e.jsxs("p",{className:"mt-1 text-sm text-muted-foreground",children:["Optional advanced behavior. CCS adds ",e.jsx("code",{children:"--dangerously-skip-permissions"})," ","only when at least one selected channel is being auto-enabled and you did not already pass a permission flag yourself."]})]})]}),e.jsx(U,{checked:d.unattended,disabled:h,onCheckedChange:s=>void(async()=>{await N({unattended:s},s?"Unattended mode enabled":"Unattended mode disabled")&&await m()})()})]})}),e.jsx("div",{className:"flex justify-end",children:e.jsxs(M,{variant:"outline",onClick:()=>void E(),disabled:h,children:[e.jsx(D,{className:`mr-2 h-4 w-4 ${h?"animate-spin":""}`}),t("settings.refresh")]})})]})})]})}export{de as default};
1
+ import{j as e}from"./radix-ui-Zb8sVEtn.js";import{r as l}from"./react-vendor-CNOkPC89.js";import{a as L,bv as B,be as y,bg as w,n as O,B as $,L as A,aF as U,I as V,d as M}from"./index-BDfXfBTa.js";import{R as D,w as k,x as K,ab as _,at as q,as as G,aG as J}from"./icons-KVCk4_U8.js";import"./tanstack-CrmUhA7Z.js";import"./notifications-B2HqRBj7.js";import"./utils-CzKF5WmX.js";import"./form-utils-Bcoyqxpq.js";import"./code-highlight-BRUf_pqB.js";const F={selected:[],unattended:!1};async function C(t,d){try{const a=await t.json();return typeof a.error=="string"&&a.error.trim().length>0?a.error:d}catch{return d}}function Y(){const[t,d]=l.useState(F),[a,v]=l.useState(null),[h,j]=l.useState(!0),[b,c]=l.useState(!1),[N,u]=l.useState(null),[S,m]=l.useState(null),f=l.useCallback(r=>{m(r),window.setTimeout(()=>m(null),1500)},[]),p=l.useCallback(async()=>{try{j(!0),u(null);const r=await fetch("/api/channels");if(!r.ok)throw new Error(await C(r,"Failed to load Official Channels settings"));const i=await r.json();return d(i.config??F),v(i.status??null),!0}catch(r){return u(r instanceof Error?r.message:"Unknown error"),!1}finally{j(!1)}},[]),T=l.useCallback(async(r,i="Settings saved")=>{try{c(!0),u(null);const n=await fetch("/api/channels",{method:"PUT",headers:{"Content-Type":"application/json"},body:JSON.stringify(r)});if(!n.ok)throw new Error(await C(n,"Failed to save Official Channels settings"));const s=await n.json();return d(o=>s.config??{...o,...r}),f(i),!0}catch(n){return u(n instanceof Error?n.message:"Unknown error"),!1}finally{c(!1)}},[f]),E=l.useCallback(async(r,i)=>{try{c(!0),u(null);const n=await fetch(`/api/channels/${r}/token`,{method:"PUT",headers:{"Content-Type":"application/json"},body:JSON.stringify({token:i})});if(!n.ok)throw new Error(await C(n,`Failed to save ${r} token`));return await p()?(f(`${r} token saved`),!0):!1}catch(n){return u(n instanceof Error?n.message:"Unknown error"),!1}finally{c(!1)}},[p,f]),P=l.useCallback(async r=>{try{c(!0),u(null);const i=await fetch(`/api/channels/${r}/token`,{method:"DELETE"});if(!i.ok)throw new Error(await C(i,`Failed to clear ${r} token`));return await p()?(f(`${r} token cleared`),!0):!1}catch(i){return u(i instanceof Error?i.message:"Unknown error"),!1}finally{c(!1)}},[p,f]);return{config:t,status:a,loading:h,saving:b,error:N,success:S,fetchConfig:p,updateConfig:T,saveToken:E,clearToken:P}}const z={telegram:"",discord:"",imessage:""};function H(t){return t==="ready"?"border-green-200 bg-green-50 text-green-900 dark:border-green-900/60 dark:bg-green-950/40 dark:text-green-100":t==="limited"?"border-amber-200 bg-amber-50 text-amber-900 dark:border-amber-900/60 dark:bg-amber-950/40 dark:text-amber-100":"border-blue-200 bg-blue-50 text-blue-900 dark:border-blue-900/60 dark:bg-blue-950/40 dark:text-blue-100"}function Q(t){return t==="ready"?"default":t==="not_selected"?"secondary":t==="unavailable"?"destructive":"outline"}function W(t){return t==="ready"?"default":t==="partial"?"outline":t==="blocked"?"destructive":"secondary"}function X(t,d){return t.length===0?"None selected":t.map(a=>d?.find(v=>v.id===a)?.displayName??a).join(", ")}function de(){const{t}=L(),{config:d,status:a,loading:v,saving:h,error:j,success:b,fetchConfig:c,updateConfig:N,saveToken:u,clearToken:S}=Y(),{fetchRawConfig:m}=B(),[f,p]=l.useState(z),T=X(d.selected,a?.channels);l.useEffect(()=>{c(),m()},[c,m]);const E=async()=>{await Promise.all([c(),m()])},P=async(s,o)=>{const x=o?[...new Set([...d.selected,s])]:d.selected.filter(R=>R!==s);await N({selected:x},o?`${s} selected for auto-enable`:`${s} removed from auto-enable`)&&await Promise.all([c(),m()])},r=(s,o)=>{p(x=>({...x,[s]:o}))},i=async s=>{await u(s,f[s])&&(p(x=>({...x,[s]:""})),await m())},n=async s=>{await S(s)&&(p(x=>({...x,[s]:""})),await m())};return v?e.jsx("div",{className:"flex flex-1 items-center justify-center",children:e.jsxs("div",{className:"flex items-center gap-3 text-muted-foreground",children:[e.jsx(D,{className:"h-5 w-5 animate-spin"}),e.jsx("span",{children:t("settings.loading")})]})}):e.jsxs(e.Fragment,{children:[e.jsxs("div",{className:`absolute left-5 right-5 top-20 z-10 transition-all duration-200 ease-out ${j||b?"translate-y-0 opacity-100":"pointer-events-none -translate-y-2 opacity-0"}`,children:[j&&e.jsxs(y,{variant:"destructive",className:"py-2 shadow-lg",children:[e.jsx(k,{className:"h-4 w-4"}),e.jsx(w,{children:j})]}),b&&e.jsxs("div",{className:"flex items-center gap-2 rounded-md border border-green-200 bg-green-50 px-3 py-2 text-green-700 shadow-lg dark:border-green-900/50 dark:bg-green-900/90 dark:text-green-300",children:[e.jsx(K,{className:"h-4 w-4 shrink-0"}),e.jsx("span",{className:"text-sm font-medium",children:b})]})]}),e.jsx(O,{className:"flex-1",children:e.jsxs("div",{className:"space-y-6 p-5",children:[e.jsxs("div",{className:"flex items-start gap-3",children:[e.jsx(_,{className:"h-5 w-5 text-primary"}),e.jsxs("div",{className:"space-y-1",children:[e.jsx("p",{className:"font-medium",children:t("settingsPage.channelsSection.title")}),e.jsxs("p",{className:"text-sm text-muted-foreground",children:["Configure official Claude channels here, then run ",e.jsx("code",{children:"ccs"})," normally on a supported native Claude session."]}),e.jsxs("p",{className:"text-sm text-muted-foreground",children:["CCS stores only channel selection in ",e.jsx("code",{children:"config.yaml"}),". Claude keeps the machine-level channel state under ",e.jsx("code",{children:"~/.claude/channels/"}),"."]})]})]}),a&&e.jsxs("div",{className:`rounded-xl border p-4 ${H(a.summary.state)}`,children:[e.jsxs("div",{className:"flex flex-wrap items-start justify-between gap-3",children:[e.jsxs("div",{className:"space-y-2",children:[e.jsxs("div",{className:"flex items-center gap-2",children:[e.jsx($,{variant:a.summary.state==="ready"?"default":"outline",children:a.summary.title}),e.jsx("span",{className:"text-sm font-medium",children:T})]}),e.jsx("p",{className:"text-sm",children:a.summary.message}),e.jsx("p",{className:"text-sm opacity-90",children:a.summary.nextStep})]}),e.jsxs("div",{className:"min-w-[220px] rounded-lg border border-current/10 bg-background/60 p-3 text-sm text-foreground",children:[e.jsx("p",{className:"font-medium",children:"Machine checks"}),e.jsxs("div",{className:"mt-2 space-y-1 text-muted-foreground",children:[e.jsxs("div",{className:"flex items-center justify-between gap-4",children:[e.jsx("span",{children:"Bun"}),e.jsx("span",{children:a.bunInstalled?"Installed":"Missing"})]}),e.jsxs("div",{className:"flex items-center justify-between gap-4",children:[e.jsx("span",{children:"Claude Code"}),e.jsx("span",{children:a.claudeVersion.current?`v${a.claudeVersion.current}`:"Unknown"})]}),e.jsxs("div",{className:"flex items-center justify-between gap-4",children:[e.jsx("span",{children:"Claude auth"}),e.jsx("span",{children:a.auth.authMethod??"Unknown"})]})]})]})]}),a.summary.blockers.length>0&&e.jsx("div",{className:"mt-3 space-y-1 text-sm",children:a.summary.blockers.map(s=>e.jsx("p",{children:s},s))})]}),a&&e.jsxs("div",{className:"rounded-lg border bg-muted/20 p-4",children:[e.jsx("p",{className:"font-medium",children:"Fastest path"}),e.jsxs("div",{className:"mt-3 space-y-2 text-sm text-muted-foreground",children:[e.jsx("p",{children:"1. Turn on the channels you want below."}),e.jsx("p",{children:"2. Save Telegram or Discord bot tokens here if that channel needs one."}),e.jsxs("p",{children:["3. Run ",e.jsx("code",{children:"ccs"})," or a native Claude account profile. CCS adds"," ",e.jsx("code",{children:"--channels"})," for you on supported runs."]}),e.jsx("p",{children:a.supportMessage})]}),e.jsxs("details",{className:"mt-3 rounded-lg border bg-background p-4",children:[e.jsx("summary",{className:"cursor-pointer text-sm font-medium",children:"Advanced notes and scope"}),e.jsxs("div",{className:"mt-3 space-y-2 text-sm text-muted-foreground",children:[e.jsx("p",{children:a.accountStatusCaveat}),e.jsx("p",{children:a.stateScopeMessage})]})]})]}),a&&e.jsxs("div",{className:"rounded-lg border bg-background p-4",children:[e.jsxs("div",{className:"flex flex-wrap items-start justify-between gap-3",children:[e.jsxs("div",{className:"space-y-1",children:[e.jsxs("p",{className:"font-medium",children:["If you run ",e.jsx("code",{children:"ccs"})," now"]}),e.jsx("p",{className:"text-sm text-muted-foreground",children:a.launchPreview.detail})]}),e.jsx($,{variant:W(a.launchPreview.state),children:a.launchPreview.title})]}),e.jsxs("div",{className:"mt-3 space-y-2",children:[e.jsxs("div",{className:"rounded-md bg-muted px-3 py-2 font-mono text-sm",children:[e.jsx("span",{className:"text-muted-foreground",children:"You type:"})," ",a.launchPreview.command]}),e.jsxs("div",{className:"rounded-md bg-muted px-3 py-2 font-mono text-sm break-all",children:[e.jsx("span",{className:"text-muted-foreground",children:"CCS adds:"})," ",a.launchPreview.appendedArgs.length>0?a.launchPreview.appendedArgs.join(" "):"(nothing yet)"]})]}),a.launchPreview.skippedMessages.length>0&&e.jsx("div",{className:"mt-3 space-y-1 text-sm text-muted-foreground",children:a.launchPreview.skippedMessages.map(s=>e.jsx("p",{children:s},s))})]}),a?.claudeVersion.message&&a.claudeVersion.state!=="supported"&&e.jsxs(y,{children:[e.jsx(k,{className:"h-4 w-4"}),e.jsx(w,{children:a.claudeVersion.message})]}),a?.auth.message&&a.auth.state!=="eligible"&&e.jsxs(y,{children:[e.jsx(k,{className:"h-4 w-4"}),e.jsx(w,{children:a.auth.message})]}),a?.auth.orgRequirementMessage&&e.jsxs(y,{children:[e.jsx(k,{className:"h-4 w-4"}),e.jsx(w,{children:a.auth.orgRequirementMessage})]}),e.jsx("div",{className:"space-y-4",children:a?.channels.map(s=>{const o=d.selected.includes(s.id),x=f[s.id];return e.jsxs("div",{className:"rounded-lg border p-4 space-y-4",children:[e.jsxs("div",{className:"flex items-start justify-between gap-4",children:[e.jsxs("div",{children:[e.jsx(A,{className:"text-base font-medium",children:s.displayName}),e.jsx("p",{className:"mt-1 text-sm text-muted-foreground",children:s.summary}),e.jsx("p",{className:"mt-2 font-mono text-xs text-muted-foreground",children:s.pluginSpec})]}),e.jsxs("div",{className:"flex items-center gap-3",children:[e.jsx($,{variant:Q(s.setup.state),children:s.setup.label}),e.jsx(U,{checked:o,disabled:h||!!s.unavailableReason&&!o,onCheckedChange:g=>void P(s.id,g)})]})]}),e.jsxs("div",{className:"rounded-lg bg-muted/30 p-4 text-sm text-muted-foreground space-y-2",children:[e.jsx("p",{children:s.setup.detail}),e.jsx("p",{children:s.setup.nextStep})]}),s.requiresToken&&e.jsxs("div",{className:"space-y-3 rounded-lg bg-muted/30 p-4",children:[e.jsx("p",{className:"text-sm text-muted-foreground",children:!s.tokenConfigured&&s.tokenSource==="process_env"?`The current CCS process already has ${s.envKey}. Save it here only if you want persistent Claude channel state.`:s.tokenConfigured&&s.processEnvAvailable?`${s.envKey} is saved in Claude channel state, and the current CCS process env also provides it.`:`Save ${s.envKey} in Claude's official channel env file. The dashboard never reads the token value back after save.`}),s.tokenConfigured&&e.jsxs("p",{className:"text-sm text-muted-foreground",children:["Saving here writes the same ",e.jsx("code",{children:".env"})," file as"," ",e.jsxs("code",{children:["/",s.id,":configure"]}),", so you do not need to run the configure command again after a successful save."]}),e.jsx(V,{type:"password",value:x,onChange:g=>r(s.id,g.target.value),placeholder:s.tokenConfigured?`Configured. Enter a new ${s.envKey} to replace it.`:!s.tokenConfigured&&s.tokenSource==="process_env"?`Using current CCS process env. Enter a new ${s.envKey} to save it for Claude.`:`Paste ${s.envKey}`,disabled:h}),s.tokenPath&&s.tokenSource!=="process_env"&&e.jsx("div",{className:"text-xs text-muted-foreground break-all",children:s.tokenPath}),e.jsxs("div",{className:"flex flex-wrap gap-2",children:[e.jsxs(M,{onClick:()=>void i(s.id),disabled:h||!x.trim(),children:[e.jsx(q,{className:"mr-2 h-4 w-4"}),"Save Token"]}),e.jsxs(M,{variant:"outline",onClick:()=>void n(s.id),disabled:h||!s.tokenConfigured,children:[e.jsx(G,{className:"mr-2 h-4 w-4"}),"Clear Saved Token"]})]})]}),e.jsxs("details",{className:"rounded-lg border bg-background p-4",children:[e.jsx("summary",{className:"cursor-pointer text-sm font-medium",children:"Claude-side setup commands"}),e.jsx("div",{className:"mt-3 space-y-2",children:(s.manualSetupCommands??[]).map(g=>e.jsx("div",{className:"rounded-md bg-muted px-3 py-2 font-mono text-sm break-all",children:g},g))})]})]},s.id)})}),e.jsx(y,{children:e.jsxs(w,{children:["CCS injects ",e.jsx("code",{children:"--channels"})," only for the current Claude session. Telegram, Discord, and iMessage stop receiving messages when that Claude session exits."]})}),e.jsx("div",{className:"rounded-lg border p-4",children:e.jsxs("div",{className:"flex items-start justify-between gap-4 rounded-lg bg-muted/30 p-4",children:[e.jsxs("div",{className:"flex gap-3",children:[e.jsx(J,{className:"mt-0.5 h-4 w-4 shrink-0 text-amber-600"}),e.jsxs("div",{children:[e.jsx(A,{className:"text-sm font-medium",children:t("profileEditorSections.skipPermissionPrompts")}),e.jsxs("p",{className:"mt-1 text-sm text-muted-foreground",children:["Optional advanced behavior. CCS adds ",e.jsx("code",{children:"--dangerously-skip-permissions"})," ","only when at least one selected channel is being auto-enabled and you did not already pass a permission flag yourself."]})]})]}),e.jsx(U,{checked:d.unattended,disabled:h,onCheckedChange:s=>void(async()=>{await N({unattended:s},s?"Unattended mode enabled":"Unattended mode disabled")&&await m()})()})]})}),e.jsx("div",{className:"flex justify-end",children:e.jsxs(M,{variant:"outline",onClick:()=>void E(),disabled:h,children:[e.jsx(D,{className:`mr-2 h-4 w-4 ${h?"animate-spin":""}`}),t("settings.refresh")]})})]})})]})}export{de as default};
@@ -1 +1 @@
1
- import{j as r,a1 as i,a2 as t}from"./radix-ui-Zb8sVEtn.js";import"./react-vendor-CNOkPC89.js";import{c as s}from"./index-DNmWbKbN.js";import{m as o}from"./icons-KVCk4_U8.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,a1 as i,a2 as t}from"./radix-ui-Zb8sVEtn.js";import"./react-vendor-CNOkPC89.js";import{c as s}from"./index-BDfXfBTa.js";import{m as o}from"./icons-KVCk4_U8.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 +1 @@
1
- import{j as e}from"./radix-ui-Zb8sVEtn.js";import{r as W}from"./react-vendor-CNOkPC89.js";import{a as $,bb as Pe,B as p,d as S,n as ae,C as u,j as f,k as j,_ as b,b as h,I as G,r as ne,s as ie,t as re,v as le,w as de,x as K,Q as ke,R as Ee,U as oe,V as ce,c as pe}from"./index-DNmWbKbN.js";import{u as V,a as J,b as M}from"./tanstack-CrmUhA7Z.js";import{t as P}from"./notifications-B2HqRBj7.js";import{aa as De,a9 as Be,L as F,at as Ie,as as Te,R as Re,T as me,ah as qe,a7 as Ae}from"./icons-KVCk4_U8.js";import"./utils-CzKF5WmX.js";import"./form-utils-Bcoyqxpq.js";import"./code-highlight-BRUf_pqB.js";const L=["claude-extension-bindings"];async function k(s,n){const a=await fetch(Pe(s),{headers:{"Content-Type":"application/json"},...n});if(!a.ok){const r=await a.json().catch(()=>null);throw new Error(r?.error||`Request failed (${a.status})`)}return a.status===204?void 0:await a.json()}function $e(){return V({queryKey:["claude-extension-options"],queryFn:()=>k("/claude-extension/profiles")})}function Le(s,n="vscode"){return V({queryKey:["claude-extension-setup",s,n],enabled:!!s,queryFn:()=>k(`/claude-extension/setup?profile=${encodeURIComponent(s||"")}&host=${encodeURIComponent(n)}`)})}function Oe(){return V({queryKey:L,queryFn:()=>k("/claude-extension/bindings")})}function Qe(s){return V({queryKey:["claude-extension-binding-status",s],enabled:!!s,queryFn:()=>k(`/claude-extension/bindings/${encodeURIComponent(s||"")}/verify`)})}function Ue(){const s=J();return M({mutationFn:n=>k("/claude-extension/bindings",{method:"POST",body:JSON.stringify(n)}),onSuccess:()=>{s.invalidateQueries({queryKey:L}),P.success("Binding created")},onError:n=>P.error(n.message)})}function Fe(){const s=J(),{t:n}=$();return M({mutationFn:({id:a,binding:r})=>k(`/claude-extension/bindings/${encodeURIComponent(a)}`,{method:"PUT",body:JSON.stringify(r)}),onSuccess:(a,r)=>{s.invalidateQueries({queryKey:L}),s.invalidateQueries({queryKey:["claude-extension-binding-status",r.id]}),P.success(n("claudeExtensionPage.bindingSaved"))},onError:a=>P.error(a.message)})}function Ke(){const s=J(),{t:n}=$();return M({mutationFn:a=>k(`/claude-extension/bindings/${encodeURIComponent(a)}`,{method:"DELETE"}),onSuccess:()=>{s.invalidateQueries({queryKey:L}),P.success(n("claudeExtensionPage.bindingDeleted"))},onError:a=>P.error(a.message)})}function fe(s,n){const a=J();return M({mutationFn:({id:r,target:C})=>k(`/claude-extension/bindings/${encodeURIComponent(r)}/${s}`,{method:"POST",body:JSON.stringify({target:C})}),onSuccess:r=>{a.invalidateQueries({queryKey:L}),a.setQueryData(["claude-extension-binding-status",r.bindingId],r),P.success(n)},onError:r=>P.error(r.message)})}function Ve(){const{t:s}=$();return fe("apply",s("claudeExtensionPage.bindingApplied"))}function Je(){const{t:s}=$();return fe("reset",s("claudeExtensionPage.managedValuesRemoved"))}const Me=[];function ue(s){return{name:"",profile:s,host:"vscode",ideSettingsPath:"",notes:""}}function R(s){return{name:s.name,profile:s.profile,host:s.host,ideSettingsPath:s.ideSettingsPath||"",notes:s.notes||""}}function _e(s){return{name:s.name.trim(),profile:s.profile.trim(),host:s.host,ideSettingsPath:s.ideSettingsPath.trim()||void 0,notes:s.notes.trim()||void 0}}function he(s){return s?.state==="applied"}function ze({state:s}){const n=s==="applied"?"border-emerald-500/30 bg-emerald-500/10 text-emerald-700 dark:text-emerald-300":s==="drifted"?"border-amber-500/30 bg-amber-500/10 text-amber-700 dark:text-amber-300":s==="missing"?"border-destructive/30 bg-destructive/10 text-destructive":"border-border bg-muted text-muted-foreground";return e.jsx(p,{variant:"outline",className:n,children:s})}function He(s){return s.replace(/[\\/]/g,"$&​")}function o({label:s,value:n,mono:a=!1,copyValue:r}){const C=typeof r=="string"&&r.trim().length>0;return e.jsxs("div",{className:"grid gap-2 text-sm sm:grid-cols-[112px_minmax(0,1fr)] sm:items-start",children:[e.jsx("span",{className:"text-muted-foreground",children:s}),C?e.jsxs("div",{className:"flex min-w-0 items-start gap-2",children:[e.jsx("div",{className:"min-w-0 flex-1 rounded-md border bg-muted/25 px-3 py-2",children:e.jsx("span",{className:"block text-left font-mono text-xs leading-5 [overflow-wrap:anywhere]",children:He(n)})}),e.jsx(K,{value:r,label:`Copy ${s.toLowerCase()}`,className:"shrink-0"})]}):e.jsx("span",{className:pe("text-left sm:text-right",a&&"font-mono text-xs leading-5 [overflow-wrap:anywhere]"),children:n})]})}function xe({title:s,description:n,value:a}){return e.jsxs(u,{className:"border-border/60 bg-card/80",children:[e.jsx(f,{className:"pb-3",children:e.jsxs("div",{className:"flex items-start justify-between gap-3",children:[e.jsxs("div",{children:[e.jsx(j,{className:"text-base",children:s}),e.jsx(b,{className:"mt-1",children:n})]}),e.jsx(K,{value:a,label:`Copy ${s}`})]})}),e.jsx(h,{children:e.jsx("pre",{className:"max-h-[360px] overflow-auto rounded-lg border bg-muted/30 p-4 text-xs leading-6",children:a})})]})}function ge({title:s,description:n,status:a,applyLabel:r,resetLabel:C,onApply:O,onReset:x,disabled:v,busy:E}){return e.jsxs(u,{className:"border-border/60 bg-card/80",children:[e.jsx(f,{className:"pb-3",children:e.jsxs("div",{className:"flex items-start justify-between gap-3",children:[e.jsxs("div",{children:[e.jsx(j,{className:"text-base",children:s}),e.jsx(b,{className:"mt-1",children:n})]}),a?e.jsx(ze,{state:a.state}):null]})}),e.jsxs(h,{className:"space-y-4",children:[e.jsxs("div",{className:"space-y-2",children:[e.jsx(o,{label:"Path",value:a?.path||"Save a binding first",mono:!0,copyValue:a?.path}),e.jsx(o,{label:"File",value:a?a.exists?"Present":"Not created yet":"Unavailable"})]}),e.jsx("div",{className:"rounded-lg border bg-muted/25 p-3 text-sm text-muted-foreground",children:a?.message||"Verify the binding after saving to inspect the current file state."}),e.jsxs("div",{className:"flex gap-2",children:[e.jsxs(S,{size:"sm",className:"flex-1",onClick:O,disabled:v||E,children:[E?e.jsx(F,{className:"mr-1.5 h-3.5 w-3.5 animate-spin"}):null,r]}),e.jsx(S,{size:"sm",variant:"outline",className:"flex-1",onClick:x,disabled:v||E,children:C})]})]})]})}function We({binding:s,isSelected:n,onSelect:a}){return e.jsx("button",{onClick:a,className:pe("w-full rounded-lg border px-3 py-3 text-left transition-colors",n?"border-primary/40 bg-primary/10":"border-border/60 bg-card hover:bg-muted/40"),children:e.jsxs("div",{className:"flex items-start justify-between gap-2",children:[e.jsxs("div",{className:"min-w-0",children:[e.jsx("div",{className:"truncate text-sm font-medium",children:s.name}),e.jsxs("div",{className:"mt-1 text-xs text-muted-foreground",children:[s.profile," · ",s.host]})]}),e.jsx(p,{variant:"outline",className:"shrink-0",children:s.usesDefaultIdeSettingsPath?"Default path":"Custom path"})]})})}function is(){const{t:s}=$(),n=$e(),a=Oe(),r=Ue(),C=Fe(),O=Ke(),x=Ve(),v=Je(),E=n.data?.profiles??[],Y=n.data?.hosts??[],w=a.data?.bindings??Me,je=E[0]?.name??"default",[be,B]=W.useState(!1),[Q,I]=W.useState(null),[X,D]=W.useState(()=>ue("default")),c=be||w.length===0,N=!c&&w.length>0?w.find(t=>t.id===Q)??(Q?null:w[0]):null,g=N?.id??null,l=c||!N||Q?X:R(N),Z=Le(l.profile,l.host),q=Qe(c?void 0:g||void 0),d=Y.find(t=>t.id===l.host),_=E.find(t=>t.name===l.profile),z=n.error||a.error||Z.error||q.error,ve=`${w.length} saved`,ee=r.isPending||C.isPending,Ne=x.isPending&&x.variables?.target==="shared"||v.isPending&&v.variables?.target==="shared",ye=x.isPending&&x.variables?.target==="ide"||v.isPending&&v.variables?.target==="ide",se=l.name.trim().length>0&&l.profile.trim().length>0,i=Z.data,m=q.data,te=Math.max((i?.env.length??0)-6,0),Se=i?.env.slice(0,6)??[];function H(){B(!0),I(null),D(ue(je))}async function Ce(){if(!se)return;const t=_e(l);if(!c&&g){const U=await C.mutateAsync({id:g,binding:t});B(!1),I(U.binding.id),D(R(U.binding));return}const y=await r.mutateAsync(t);B(!1),I(y.binding.id),D(R(y.binding))}async function we(){if(!g||!N||!window.confirm(`Delete binding "${N.name}"?`))return;await O.mutateAsync(g);const t=w.filter(y=>y.id!==g);t.length>0?(I(t[0].id),B(!1),D(R(t[0]))):H()}function A(t,y){if(!c&&N&&!Q){I(N.id),D({...R(N),[t]:y}),B(!1);return}D(U=>({...U,[t]:y}))}function T(t,y){if(g){if(y==="apply"){x.mutate({id:g,target:t});return}v.mutate({id:g,target:t})}}return e.jsxs("div",{className:"flex h-full min-h-0 overflow-hidden",children:[e.jsxs("div",{className:"flex w-[348px] shrink-0 flex-col border-r bg-muted/30 xl:w-[372px]",children:[e.jsx("div",{className:"border-b bg-background p-4",children:e.jsxs("div",{className:"flex items-start justify-between gap-3",children:[e.jsxs("div",{className:"space-y-2",children:[e.jsxs("div",{className:"flex items-center gap-2",children:[e.jsx("div",{className:"rounded-lg border bg-muted/40 p-2",children:e.jsx(De,{className:"h-5 w-5 text-primary"})}),e.jsxs("div",{children:[e.jsx("h1",{className:"font-semibold",children:s("claudeExtensionPage.title")}),e.jsx("p",{className:"text-xs text-muted-foreground",children:"Saved IDE bindings for CCS profiles"})]})]}),e.jsxs("div",{className:"flex items-center gap-2",children:[e.jsx(p,{variant:"secondary",children:ve}),d?e.jsx(p,{variant:"outline",children:d.label}):null]})]}),e.jsxs(S,{size:"sm",onClick:H,className:"gap-1.5",children:[e.jsx(Be,{className:"h-3.5 w-3.5"}),"New"]})]})}),e.jsx(ae,{className:"flex-1",children:e.jsxs("div",{className:"space-y-4 p-5",children:[e.jsxs(u,{className:"border-border/60 bg-card/80",children:[e.jsxs(f,{children:[e.jsx(j,{className:"text-base",children:c?"Create binding":"Binding editor"}),e.jsx(b,{children:"Save a profile + IDE path once, then apply or reset it from the dashboard."})]}),e.jsxs(h,{className:"space-y-4",children:[e.jsxs("div",{className:"space-y-2",children:[e.jsx("div",{className:"text-sm font-medium",children:"Binding name"}),e.jsx(G,{value:l.name,onChange:t=>A("name",t.target.value),placeholder:"VS Code · work profile"})]}),e.jsxs("div",{className:"space-y-2",children:[e.jsx("div",{className:"text-sm font-medium",children:"CCS profile"}),e.jsxs(ne,{value:l.profile,onValueChange:t=>A("profile",t),children:[e.jsx(ie,{children:e.jsx(re,{placeholder:"Select a profile"})}),e.jsx(le,{children:E.map(t=>e.jsxs(de,{value:t.name,children:[t.label," (",t.profileType,")"]},t.name))})]}),e.jsx("p",{className:"text-xs text-muted-foreground",children:_?.description||"Choose which CCS profile the IDE should inherit."})]}),e.jsxs("div",{className:"space-y-2",children:[e.jsx("div",{className:"text-sm font-medium",children:s("settingsPage.thinkingSection.ideHost")}),e.jsxs(ne,{value:l.host,onValueChange:t=>A("host",t),children:[e.jsx(ie,{children:e.jsx(re,{placeholder:"Select a host"})}),e.jsx(le,{children:Y.map(t=>e.jsx(de,{value:t.id,children:t.label},t.id))})]})]}),e.jsxs("div",{className:"space-y-2",children:[e.jsx("div",{className:"text-sm font-medium",children:s("settingsPage.thinkingSection.ideSettingsPath")}),e.jsx(G,{value:l.ideSettingsPath,onChange:t=>A("ideSettingsPath",t.target.value),placeholder:d?.defaultSettingsPath||"Leave blank for the default user settings path"}),e.jsxs("p",{className:"text-xs text-muted-foreground",children:["Leave blank to use the default user settings path for"," ",d?.label||"this IDE","."]})]}),e.jsxs("div",{className:"space-y-2",children:[e.jsx("div",{className:"text-sm font-medium",children:"Notes"}),e.jsx(G,{value:l.notes,onChange:t=>A("notes",t.target.value),placeholder:"Optional reminder for this machine or workspace"})]}),e.jsxs("div",{className:"flex gap-2",children:[e.jsxs(S,{className:"flex-1 gap-1.5",onClick:()=>void Ce(),disabled:!se||ee,children:[ee?e.jsx(F,{className:"h-3.5 w-3.5 animate-spin"}):e.jsx(Ie,{className:"h-3.5 w-3.5"}),c?"Create":"Save"]}),e.jsx(S,{variant:"outline",onClick:H,children:"Reset form"})]}),c?null:e.jsxs(S,{variant:"outline",className:"w-full gap-1.5 text-destructive hover:text-destructive",onClick:()=>void we(),disabled:O.isPending,children:[e.jsx(Te,{className:"h-3.5 w-3.5"}),"Delete binding"]})]})]}),e.jsxs("div",{className:"space-y-2",children:[e.jsx("div",{className:"px-1 text-xs font-medium uppercase tracking-wide text-muted-foreground",children:"Saved bindings"}),e.jsx("div",{className:"space-y-2",children:w.length>0?w.map(t=>e.jsx(We,{binding:t,isSelected:t.id===g&&!c,onSelect:()=>{B(!1),I(t.id),D(R(t))}},t.id)):e.jsx(u,{className:"border-dashed border-border/60 bg-card/60",children:e.jsx(h,{className:"pt-6 text-sm text-muted-foreground",children:"No saved bindings yet. Create one to manage apply, reset, and drift checks from the dashboard."})})})]})]})})]}),e.jsx("div",{className:"min-w-0 flex-1",children:e.jsx(ae,{className:"h-full",children:e.jsxs("div",{className:"w-full space-y-6 p-6 xl:p-7 2xl:p-8",children:[e.jsxs("div",{className:"flex flex-col gap-3 lg:flex-row lg:items-end lg:justify-between",children:[e.jsxs("div",{className:"space-y-2",children:[e.jsxs("div",{className:"flex flex-wrap items-center gap-2",children:[_?e.jsx(p,{variant:"outline",children:_.label}):null,d?e.jsx(p,{variant:"outline",children:d.label}):null,c?e.jsx(p,{variant:"secondary",children:s("settingsPage.thinkingSection.draft")}):null,m?.sharedSettings&&he(m.sharedSettings)&&he(m.ideSettings)?e.jsx(p,{className:"bg-emerald-600 hover:bg-emerald-600",children:s("settingsPage.thinkingSection.inSync")}):null]}),e.jsxs("div",{className:"max-w-5xl",children:[e.jsx("h2",{className:"text-2xl font-semibold tracking-tight",children:N?.name||"Claude extension binding"}),e.jsx("p",{className:"mt-1 text-sm text-muted-foreground",children:"Manage the shared Claude settings file and the IDE-local settings file as two scoped targets."})]})]}),e.jsxs("div",{className:"flex gap-2",children:[e.jsxs(S,{variant:"outline",onClick:()=>void q.refetch(),disabled:c||q.isFetching,children:[q.isFetching?e.jsx(F,{className:"mr-1.5 h-3.5 w-3.5 animate-spin"}):e.jsx(Re,{className:"mr-1.5 h-3.5 w-3.5"}),"Verify"]}),i?e.jsx(K,{value:i.sharedSettings.command,label:"Copy persist command"}):null]})]}),z?e.jsx(u,{className:"border-destructive/40 bg-destructive/5",children:e.jsxs(h,{className:"flex items-start gap-3 pt-6 text-sm text-destructive",children:[e.jsx(me,{className:"mt-0.5 h-4 w-4 shrink-0"}),e.jsx("div",{children:z.message})]})}):null,z?null:e.jsxs(ke,{defaultValue:"overview",className:"flex flex-col gap-6",children:[e.jsxs(Ee,{className:"w-full justify-start",children:[e.jsx(oe,{value:"overview",children:"Overview"})," ",e.jsx(oe,{value:"advanced",children:s("settingsPage.thinkingSection.advanced")})]}),e.jsxs(ce,{value:"overview",className:"mt-0 space-y-6",children:[e.jsxs("div",{className:"grid gap-6 xl:grid-cols-2",children:[e.jsx(ge,{title:"Shared Claude settings",description:"Writes the managed env block inside ~/.claude/settings.json so CLI and IDE behavior stay aligned.",status:m?.sharedSettings,applyLabel:"Apply shared",resetLabel:"Reset shared",onApply:()=>T("shared","apply"),onReset:()=>T("shared","reset"),disabled:c,busy:Ne}),e.jsx(ge,{title:`${d?.label||"IDE"} settings.json`,description:"Writes only the Anthropic extension keys so unrelated editor preferences stay untouched.",status:m?.ideSettings,applyLabel:"Apply IDE",resetLabel:"Reset IDE",onApply:()=>T("ide","apply"),onReset:()=>T("ide","reset"),disabled:c,busy:ye})]}),e.jsxs("div",{className:"grid gap-6 xl:grid-cols-[minmax(0,1.15fr)_minmax(320px,0.85fr)]",children:[e.jsxs(u,{className:"border-border/60 bg-card/80",children:[e.jsxs(f,{children:[e.jsx(j,{className:"text-base",children:s("settingsPage.thinkingSection.resolvedBinding")}),e.jsx(b,{children:"The binding uses the same profile resolution as `ccs persist` and `ccs env`."})]}),e.jsxs(h,{className:"space-y-3",children:[e.jsx(o,{label:"Profile",value:i?.profile.label||l.profile||"Not selected"}),e.jsx(o,{label:"Profile type",value:i?.profile.profileType||"Unknown"}),e.jsx(o,{label:"IDE host",value:d?.label||"Not selected"}),e.jsx(o,{label:"IDE path mode",value:l.ideSettingsPath.trim()?"Custom path":"Default user path"}),e.jsx(o,{label:"Effective IDE path",value:m?.ideSettings.path||l.ideSettingsPath.trim()||d?.defaultSettingsPath||"Unavailable",mono:!0,copyValue:m?.ideSettings.path||l.ideSettingsPath.trim()||d?.defaultSettingsPath}),e.jsx(o,{label:"Persist command",value:i?.sharedSettings.command||"Save a valid binding first",mono:!0}),l.notes.trim()?e.jsx(o,{label:"Notes",value:l.notes.trim()}):null]})]}),e.jsxs(u,{className:"border-border/60 bg-card/80",children:[e.jsxs(f,{children:[e.jsx(j,{className:"text-base",children:s("settingsPage.thinkingSection.managedPayload")}),e.jsx(b,{children:"Keep the main view short. The full JSON stays in the Advanced tab."})]}),e.jsxs(h,{className:"space-y-4",children:[e.jsxs("div",{className:"flex flex-wrap gap-2",children:[Se.map(t=>e.jsx(p,{variant:"secondary",className:"font-mono text-[10px]",children:t.name},t.name)),te>0?e.jsxs(p,{variant:"outline",children:["+",te," more"]}):null]}),e.jsx("div",{className:"rounded-lg border bg-muted/25 p-4 text-sm",children:i?.env.length?e.jsxs("div",{className:"space-y-2",children:[e.jsxs("div",{className:"font-medium",children:["CCS will inject ",i.env.length," environment values."]}),e.jsx("div",{className:"text-muted-foreground",children:"The IDE-local target receives the extension schema. The shared target receives the same env block through Claude settings."})]}):e.jsx("div",{className:"text-muted-foreground",children:"This profile resolves to native Claude defaults, so apply/reset mainly clears existing CCS-managed overrides."})}),c?e.jsx("div",{className:"rounded-lg border border-dashed bg-muted/15 p-4 text-sm text-muted-foreground",children:"Save this draft to unlock apply, reset, and verify actions."}):e.jsxs("div",{className:"flex gap-2",children:[e.jsxs(S,{className:"flex-1",onClick:()=>T("all","apply"),disabled:x.isPending,children:[x.isPending&&x.variables?.target==="all"?e.jsx(F,{className:"mr-1.5 h-3.5 w-3.5 animate-spin"}):null,"Apply both targets"]}),e.jsx(S,{variant:"outline",className:"flex-1",onClick:()=>T("all","reset"),disabled:v.isPending,children:"Reset both targets"})]})]})]})]}),i&&(i.warnings.length>0||i.notes.length>0)?e.jsxs("div",{className:"grid gap-6 xl:grid-cols-2",children:[e.jsxs(u,{className:"border-border/60 bg-card/80",children:[e.jsxs(f,{children:[e.jsx(j,{className:"text-base",children:s("settingsPage.thinkingSection.warnings")}),e.jsx(b,{children:"Operational details that can break the binding even when JSON is correct."})]}),e.jsx(h,{className:"space-y-3",children:i.warnings.length>0?i.warnings.map(t=>e.jsxs("div",{className:"flex items-start gap-3 rounded-lg border border-amber-400/40 bg-amber-50/60 p-3 text-sm dark:bg-amber-950/10",children:[e.jsx(me,{className:"mt-0.5 h-4 w-4 shrink-0 text-amber-600"}),e.jsx("span",{children:t})]},t)):e.jsx("div",{className:"rounded-lg border bg-muted/20 p-3 text-sm text-muted-foreground",children:"No runtime warnings for this binding."})})]}),e.jsxs(u,{className:"border-border/60 bg-card/80",children:[e.jsxs(f,{children:[e.jsx(j,{className:"text-base",children:s("settingsPage.thinkingSection.notes")}),e.jsx(b,{children:"Short context from CCS about account continuity and host-specific behavior."})]}),e.jsx(h,{className:"space-y-3",children:i.notes.length>0?i.notes.map(t=>e.jsxs("div",{className:"flex items-start gap-3 rounded-lg border bg-muted/30 p-3 text-sm",children:[e.jsx(qe,{className:"mt-0.5 h-4 w-4 shrink-0 text-muted-foreground"}),e.jsx("span",{children:t})]},t)):e.jsx("div",{className:"rounded-lg border bg-muted/20 p-3 text-sm text-muted-foreground",children:"No extra notes for this binding."})})]})]}):null]}),e.jsx(ce,{value:"advanced",className:"mt-0 space-y-6",children:i?e.jsxs(e.Fragment,{children:[e.jsxs("div",{className:"grid gap-6 xl:grid-cols-2",children:[e.jsx(xe,{title:"Shared Claude settings JSON",description:"Managed env block for ~/.claude/settings.json.",value:i.sharedSettings.json}),e.jsx(xe,{title:`${d?.label||"IDE"} settings JSON`,description:`Anthropic extension snippet for ${d?.settingsTargetLabel||"settings.json"}.`,value:i.ideSettings.json})]}),e.jsxs(u,{className:"border-border/60 bg-card/80",children:[e.jsx(f,{children:e.jsxs("div",{className:"flex items-start justify-between gap-3",children:[e.jsxs("div",{children:[e.jsx(j,{className:"text-base",children:"Resolved environment payload"}),e.jsx(b,{children:"Exact environment values that the extension receives after CCS expands this profile."})]}),e.jsx(K,{value:JSON.stringify(i.env,null,2),label:"Copy environment payload"})]})}),e.jsx(h,{children:i.env.length>0?e.jsx("pre",{className:"max-h-[420px] overflow-auto rounded-lg border bg-muted/30 p-4 text-xs leading-6",children:JSON.stringify(i.env,null,2)}):e.jsx("div",{className:"rounded-lg border bg-muted/20 p-4 text-sm text-muted-foreground",children:"No env payload. This binding resolves to native Claude defaults."})})]}),e.jsxs("div",{className:"grid gap-6 xl:grid-cols-2",children:[e.jsxs(u,{className:"border-border/60 bg-card/80",children:[e.jsxs(f,{children:[e.jsx(j,{className:"text-base",children:"Shared target metadata"}),e.jsx(b,{children:"Useful when debugging drift or comparing with manual edits."})]}),e.jsxs(h,{className:"space-y-3",children:[e.jsx(o,{label:"Target path",value:m?.sharedSettings.path||i.sharedSettings.path,mono:!0,copyValue:m?.sharedSettings.path||i.sharedSettings.path}),e.jsx(o,{label:"Command",value:i.sharedSettings.command,mono:!0}),e.jsx(o,{label:"Current state",value:m?.sharedSettings.state||"Not verified"})]})]}),e.jsxs(u,{className:"border-border/60 bg-card/80",children:[e.jsxs(f,{children:[e.jsx(j,{className:"text-base",children:"IDE target metadata"}),e.jsx(b,{children:"Current file path plus the extension setting key used for this host."})]}),e.jsxs(h,{className:"space-y-3",children:[e.jsx(o,{label:"Target path",value:m?.ideSettings.path||l.ideSettingsPath.trim()||d?.defaultSettingsPath||i.ideSettings.path,mono:!0,copyValue:m?.ideSettings.path||l.ideSettingsPath.trim()||d?.defaultSettingsPath||i.ideSettings.path}),e.jsx(o,{label:"Settings key",value:d?.settingsKey||"Unknown",mono:!0}),e.jsx(o,{label:"Current state",value:m?.ideSettings.state||"Not verified"})]})]})]})]}):e.jsx(u,{className:"border-border/60 bg-card/80",children:e.jsxs(h,{className:"flex min-h-[240px] items-center justify-center gap-3 text-sm text-muted-foreground",children:[e.jsx(Ae,{className:"h-5 w-5"}),"Choose a profile and IDE host to preview the generated payload."]})})})]})]})})})]})}export{is as ClaudeExtensionPage};
1
+ import{j as e}from"./radix-ui-Zb8sVEtn.js";import{r as W}from"./react-vendor-CNOkPC89.js";import{a as $,bb as Pe,B as p,d as S,n as ae,C as u,j as f,k as j,_ as b,b as h,I as G,r as ne,s as ie,t as re,v as le,w as de,x as K,Q as ke,R as Ee,U as oe,V as ce,c as pe}from"./index-BDfXfBTa.js";import{u as V,a as J,b as M}from"./tanstack-CrmUhA7Z.js";import{t as P}from"./notifications-B2HqRBj7.js";import{aa as De,a9 as Be,L as F,at as Ie,as as Te,R as Re,T as me,ah as qe,a7 as Ae}from"./icons-KVCk4_U8.js";import"./utils-CzKF5WmX.js";import"./form-utils-Bcoyqxpq.js";import"./code-highlight-BRUf_pqB.js";const L=["claude-extension-bindings"];async function k(s,n){const a=await fetch(Pe(s),{headers:{"Content-Type":"application/json"},...n});if(!a.ok){const r=await a.json().catch(()=>null);throw new Error(r?.error||`Request failed (${a.status})`)}return a.status===204?void 0:await a.json()}function $e(){return V({queryKey:["claude-extension-options"],queryFn:()=>k("/claude-extension/profiles")})}function Le(s,n="vscode"){return V({queryKey:["claude-extension-setup",s,n],enabled:!!s,queryFn:()=>k(`/claude-extension/setup?profile=${encodeURIComponent(s||"")}&host=${encodeURIComponent(n)}`)})}function Oe(){return V({queryKey:L,queryFn:()=>k("/claude-extension/bindings")})}function Qe(s){return V({queryKey:["claude-extension-binding-status",s],enabled:!!s,queryFn:()=>k(`/claude-extension/bindings/${encodeURIComponent(s||"")}/verify`)})}function Ue(){const s=J();return M({mutationFn:n=>k("/claude-extension/bindings",{method:"POST",body:JSON.stringify(n)}),onSuccess:()=>{s.invalidateQueries({queryKey:L}),P.success("Binding created")},onError:n=>P.error(n.message)})}function Fe(){const s=J(),{t:n}=$();return M({mutationFn:({id:a,binding:r})=>k(`/claude-extension/bindings/${encodeURIComponent(a)}`,{method:"PUT",body:JSON.stringify(r)}),onSuccess:(a,r)=>{s.invalidateQueries({queryKey:L}),s.invalidateQueries({queryKey:["claude-extension-binding-status",r.id]}),P.success(n("claudeExtensionPage.bindingSaved"))},onError:a=>P.error(a.message)})}function Ke(){const s=J(),{t:n}=$();return M({mutationFn:a=>k(`/claude-extension/bindings/${encodeURIComponent(a)}`,{method:"DELETE"}),onSuccess:()=>{s.invalidateQueries({queryKey:L}),P.success(n("claudeExtensionPage.bindingDeleted"))},onError:a=>P.error(a.message)})}function fe(s,n){const a=J();return M({mutationFn:({id:r,target:C})=>k(`/claude-extension/bindings/${encodeURIComponent(r)}/${s}`,{method:"POST",body:JSON.stringify({target:C})}),onSuccess:r=>{a.invalidateQueries({queryKey:L}),a.setQueryData(["claude-extension-binding-status",r.bindingId],r),P.success(n)},onError:r=>P.error(r.message)})}function Ve(){const{t:s}=$();return fe("apply",s("claudeExtensionPage.bindingApplied"))}function Je(){const{t:s}=$();return fe("reset",s("claudeExtensionPage.managedValuesRemoved"))}const Me=[];function ue(s){return{name:"",profile:s,host:"vscode",ideSettingsPath:"",notes:""}}function R(s){return{name:s.name,profile:s.profile,host:s.host,ideSettingsPath:s.ideSettingsPath||"",notes:s.notes||""}}function _e(s){return{name:s.name.trim(),profile:s.profile.trim(),host:s.host,ideSettingsPath:s.ideSettingsPath.trim()||void 0,notes:s.notes.trim()||void 0}}function he(s){return s?.state==="applied"}function ze({state:s}){const n=s==="applied"?"border-emerald-500/30 bg-emerald-500/10 text-emerald-700 dark:text-emerald-300":s==="drifted"?"border-amber-500/30 bg-amber-500/10 text-amber-700 dark:text-amber-300":s==="missing"?"border-destructive/30 bg-destructive/10 text-destructive":"border-border bg-muted text-muted-foreground";return e.jsx(p,{variant:"outline",className:n,children:s})}function He(s){return s.replace(/[\\/]/g,"$&​")}function o({label:s,value:n,mono:a=!1,copyValue:r}){const C=typeof r=="string"&&r.trim().length>0;return e.jsxs("div",{className:"grid gap-2 text-sm sm:grid-cols-[112px_minmax(0,1fr)] sm:items-start",children:[e.jsx("span",{className:"text-muted-foreground",children:s}),C?e.jsxs("div",{className:"flex min-w-0 items-start gap-2",children:[e.jsx("div",{className:"min-w-0 flex-1 rounded-md border bg-muted/25 px-3 py-2",children:e.jsx("span",{className:"block text-left font-mono text-xs leading-5 [overflow-wrap:anywhere]",children:He(n)})}),e.jsx(K,{value:r,label:`Copy ${s.toLowerCase()}`,className:"shrink-0"})]}):e.jsx("span",{className:pe("text-left sm:text-right",a&&"font-mono text-xs leading-5 [overflow-wrap:anywhere]"),children:n})]})}function xe({title:s,description:n,value:a}){return e.jsxs(u,{className:"border-border/60 bg-card/80",children:[e.jsx(f,{className:"pb-3",children:e.jsxs("div",{className:"flex items-start justify-between gap-3",children:[e.jsxs("div",{children:[e.jsx(j,{className:"text-base",children:s}),e.jsx(b,{className:"mt-1",children:n})]}),e.jsx(K,{value:a,label:`Copy ${s}`})]})}),e.jsx(h,{children:e.jsx("pre",{className:"max-h-[360px] overflow-auto rounded-lg border bg-muted/30 p-4 text-xs leading-6",children:a})})]})}function ge({title:s,description:n,status:a,applyLabel:r,resetLabel:C,onApply:O,onReset:x,disabled:v,busy:E}){return e.jsxs(u,{className:"border-border/60 bg-card/80",children:[e.jsx(f,{className:"pb-3",children:e.jsxs("div",{className:"flex items-start justify-between gap-3",children:[e.jsxs("div",{children:[e.jsx(j,{className:"text-base",children:s}),e.jsx(b,{className:"mt-1",children:n})]}),a?e.jsx(ze,{state:a.state}):null]})}),e.jsxs(h,{className:"space-y-4",children:[e.jsxs("div",{className:"space-y-2",children:[e.jsx(o,{label:"Path",value:a?.path||"Save a binding first",mono:!0,copyValue:a?.path}),e.jsx(o,{label:"File",value:a?a.exists?"Present":"Not created yet":"Unavailable"})]}),e.jsx("div",{className:"rounded-lg border bg-muted/25 p-3 text-sm text-muted-foreground",children:a?.message||"Verify the binding after saving to inspect the current file state."}),e.jsxs("div",{className:"flex gap-2",children:[e.jsxs(S,{size:"sm",className:"flex-1",onClick:O,disabled:v||E,children:[E?e.jsx(F,{className:"mr-1.5 h-3.5 w-3.5 animate-spin"}):null,r]}),e.jsx(S,{size:"sm",variant:"outline",className:"flex-1",onClick:x,disabled:v||E,children:C})]})]})]})}function We({binding:s,isSelected:n,onSelect:a}){return e.jsx("button",{onClick:a,className:pe("w-full rounded-lg border px-3 py-3 text-left transition-colors",n?"border-primary/40 bg-primary/10":"border-border/60 bg-card hover:bg-muted/40"),children:e.jsxs("div",{className:"flex items-start justify-between gap-2",children:[e.jsxs("div",{className:"min-w-0",children:[e.jsx("div",{className:"truncate text-sm font-medium",children:s.name}),e.jsxs("div",{className:"mt-1 text-xs text-muted-foreground",children:[s.profile," · ",s.host]})]}),e.jsx(p,{variant:"outline",className:"shrink-0",children:s.usesDefaultIdeSettingsPath?"Default path":"Custom path"})]})})}function is(){const{t:s}=$(),n=$e(),a=Oe(),r=Ue(),C=Fe(),O=Ke(),x=Ve(),v=Je(),E=n.data?.profiles??[],Y=n.data?.hosts??[],w=a.data?.bindings??Me,je=E[0]?.name??"default",[be,B]=W.useState(!1),[Q,I]=W.useState(null),[X,D]=W.useState(()=>ue("default")),c=be||w.length===0,N=!c&&w.length>0?w.find(t=>t.id===Q)??(Q?null:w[0]):null,g=N?.id??null,l=c||!N||Q?X:R(N),Z=Le(l.profile,l.host),q=Qe(c?void 0:g||void 0),d=Y.find(t=>t.id===l.host),_=E.find(t=>t.name===l.profile),z=n.error||a.error||Z.error||q.error,ve=`${w.length} saved`,ee=r.isPending||C.isPending,Ne=x.isPending&&x.variables?.target==="shared"||v.isPending&&v.variables?.target==="shared",ye=x.isPending&&x.variables?.target==="ide"||v.isPending&&v.variables?.target==="ide",se=l.name.trim().length>0&&l.profile.trim().length>0,i=Z.data,m=q.data,te=Math.max((i?.env.length??0)-6,0),Se=i?.env.slice(0,6)??[];function H(){B(!0),I(null),D(ue(je))}async function Ce(){if(!se)return;const t=_e(l);if(!c&&g){const U=await C.mutateAsync({id:g,binding:t});B(!1),I(U.binding.id),D(R(U.binding));return}const y=await r.mutateAsync(t);B(!1),I(y.binding.id),D(R(y.binding))}async function we(){if(!g||!N||!window.confirm(`Delete binding "${N.name}"?`))return;await O.mutateAsync(g);const t=w.filter(y=>y.id!==g);t.length>0?(I(t[0].id),B(!1),D(R(t[0]))):H()}function A(t,y){if(!c&&N&&!Q){I(N.id),D({...R(N),[t]:y}),B(!1);return}D(U=>({...U,[t]:y}))}function T(t,y){if(g){if(y==="apply"){x.mutate({id:g,target:t});return}v.mutate({id:g,target:t})}}return e.jsxs("div",{className:"flex h-full min-h-0 overflow-hidden",children:[e.jsxs("div",{className:"flex w-[348px] shrink-0 flex-col border-r bg-muted/30 xl:w-[372px]",children:[e.jsx("div",{className:"border-b bg-background p-4",children:e.jsxs("div",{className:"flex items-start justify-between gap-3",children:[e.jsxs("div",{className:"space-y-2",children:[e.jsxs("div",{className:"flex items-center gap-2",children:[e.jsx("div",{className:"rounded-lg border bg-muted/40 p-2",children:e.jsx(De,{className:"h-5 w-5 text-primary"})}),e.jsxs("div",{children:[e.jsx("h1",{className:"font-semibold",children:s("claudeExtensionPage.title")}),e.jsx("p",{className:"text-xs text-muted-foreground",children:"Saved IDE bindings for CCS profiles"})]})]}),e.jsxs("div",{className:"flex items-center gap-2",children:[e.jsx(p,{variant:"secondary",children:ve}),d?e.jsx(p,{variant:"outline",children:d.label}):null]})]}),e.jsxs(S,{size:"sm",onClick:H,className:"gap-1.5",children:[e.jsx(Be,{className:"h-3.5 w-3.5"}),"New"]})]})}),e.jsx(ae,{className:"flex-1",children:e.jsxs("div",{className:"space-y-4 p-5",children:[e.jsxs(u,{className:"border-border/60 bg-card/80",children:[e.jsxs(f,{children:[e.jsx(j,{className:"text-base",children:c?"Create binding":"Binding editor"}),e.jsx(b,{children:"Save a profile + IDE path once, then apply or reset it from the dashboard."})]}),e.jsxs(h,{className:"space-y-4",children:[e.jsxs("div",{className:"space-y-2",children:[e.jsx("div",{className:"text-sm font-medium",children:"Binding name"}),e.jsx(G,{value:l.name,onChange:t=>A("name",t.target.value),placeholder:"VS Code · work profile"})]}),e.jsxs("div",{className:"space-y-2",children:[e.jsx("div",{className:"text-sm font-medium",children:"CCS profile"}),e.jsxs(ne,{value:l.profile,onValueChange:t=>A("profile",t),children:[e.jsx(ie,{children:e.jsx(re,{placeholder:"Select a profile"})}),e.jsx(le,{children:E.map(t=>e.jsxs(de,{value:t.name,children:[t.label," (",t.profileType,")"]},t.name))})]}),e.jsx("p",{className:"text-xs text-muted-foreground",children:_?.description||"Choose which CCS profile the IDE should inherit."})]}),e.jsxs("div",{className:"space-y-2",children:[e.jsx("div",{className:"text-sm font-medium",children:s("settingsPage.thinkingSection.ideHost")}),e.jsxs(ne,{value:l.host,onValueChange:t=>A("host",t),children:[e.jsx(ie,{children:e.jsx(re,{placeholder:"Select a host"})}),e.jsx(le,{children:Y.map(t=>e.jsx(de,{value:t.id,children:t.label},t.id))})]})]}),e.jsxs("div",{className:"space-y-2",children:[e.jsx("div",{className:"text-sm font-medium",children:s("settingsPage.thinkingSection.ideSettingsPath")}),e.jsx(G,{value:l.ideSettingsPath,onChange:t=>A("ideSettingsPath",t.target.value),placeholder:d?.defaultSettingsPath||"Leave blank for the default user settings path"}),e.jsxs("p",{className:"text-xs text-muted-foreground",children:["Leave blank to use the default user settings path for"," ",d?.label||"this IDE","."]})]}),e.jsxs("div",{className:"space-y-2",children:[e.jsx("div",{className:"text-sm font-medium",children:"Notes"}),e.jsx(G,{value:l.notes,onChange:t=>A("notes",t.target.value),placeholder:"Optional reminder for this machine or workspace"})]}),e.jsxs("div",{className:"flex gap-2",children:[e.jsxs(S,{className:"flex-1 gap-1.5",onClick:()=>void Ce(),disabled:!se||ee,children:[ee?e.jsx(F,{className:"h-3.5 w-3.5 animate-spin"}):e.jsx(Ie,{className:"h-3.5 w-3.5"}),c?"Create":"Save"]}),e.jsx(S,{variant:"outline",onClick:H,children:"Reset form"})]}),c?null:e.jsxs(S,{variant:"outline",className:"w-full gap-1.5 text-destructive hover:text-destructive",onClick:()=>void we(),disabled:O.isPending,children:[e.jsx(Te,{className:"h-3.5 w-3.5"}),"Delete binding"]})]})]}),e.jsxs("div",{className:"space-y-2",children:[e.jsx("div",{className:"px-1 text-xs font-medium uppercase tracking-wide text-muted-foreground",children:"Saved bindings"}),e.jsx("div",{className:"space-y-2",children:w.length>0?w.map(t=>e.jsx(We,{binding:t,isSelected:t.id===g&&!c,onSelect:()=>{B(!1),I(t.id),D(R(t))}},t.id)):e.jsx(u,{className:"border-dashed border-border/60 bg-card/60",children:e.jsx(h,{className:"pt-6 text-sm text-muted-foreground",children:"No saved bindings yet. Create one to manage apply, reset, and drift checks from the dashboard."})})})]})]})})]}),e.jsx("div",{className:"min-w-0 flex-1",children:e.jsx(ae,{className:"h-full",children:e.jsxs("div",{className:"w-full space-y-6 p-6 xl:p-7 2xl:p-8",children:[e.jsxs("div",{className:"flex flex-col gap-3 lg:flex-row lg:items-end lg:justify-between",children:[e.jsxs("div",{className:"space-y-2",children:[e.jsxs("div",{className:"flex flex-wrap items-center gap-2",children:[_?e.jsx(p,{variant:"outline",children:_.label}):null,d?e.jsx(p,{variant:"outline",children:d.label}):null,c?e.jsx(p,{variant:"secondary",children:s("settingsPage.thinkingSection.draft")}):null,m?.sharedSettings&&he(m.sharedSettings)&&he(m.ideSettings)?e.jsx(p,{className:"bg-emerald-600 hover:bg-emerald-600",children:s("settingsPage.thinkingSection.inSync")}):null]}),e.jsxs("div",{className:"max-w-5xl",children:[e.jsx("h2",{className:"text-2xl font-semibold tracking-tight",children:N?.name||"Claude extension binding"}),e.jsx("p",{className:"mt-1 text-sm text-muted-foreground",children:"Manage the shared Claude settings file and the IDE-local settings file as two scoped targets."})]})]}),e.jsxs("div",{className:"flex gap-2",children:[e.jsxs(S,{variant:"outline",onClick:()=>void q.refetch(),disabled:c||q.isFetching,children:[q.isFetching?e.jsx(F,{className:"mr-1.5 h-3.5 w-3.5 animate-spin"}):e.jsx(Re,{className:"mr-1.5 h-3.5 w-3.5"}),"Verify"]}),i?e.jsx(K,{value:i.sharedSettings.command,label:"Copy persist command"}):null]})]}),z?e.jsx(u,{className:"border-destructive/40 bg-destructive/5",children:e.jsxs(h,{className:"flex items-start gap-3 pt-6 text-sm text-destructive",children:[e.jsx(me,{className:"mt-0.5 h-4 w-4 shrink-0"}),e.jsx("div",{children:z.message})]})}):null,z?null:e.jsxs(ke,{defaultValue:"overview",className:"flex flex-col gap-6",children:[e.jsxs(Ee,{className:"w-full justify-start",children:[e.jsx(oe,{value:"overview",children:"Overview"})," ",e.jsx(oe,{value:"advanced",children:s("settingsPage.thinkingSection.advanced")})]}),e.jsxs(ce,{value:"overview",className:"mt-0 space-y-6",children:[e.jsxs("div",{className:"grid gap-6 xl:grid-cols-2",children:[e.jsx(ge,{title:"Shared Claude settings",description:"Writes the managed env block inside ~/.claude/settings.json so CLI and IDE behavior stay aligned.",status:m?.sharedSettings,applyLabel:"Apply shared",resetLabel:"Reset shared",onApply:()=>T("shared","apply"),onReset:()=>T("shared","reset"),disabled:c,busy:Ne}),e.jsx(ge,{title:`${d?.label||"IDE"} settings.json`,description:"Writes only the Anthropic extension keys so unrelated editor preferences stay untouched.",status:m?.ideSettings,applyLabel:"Apply IDE",resetLabel:"Reset IDE",onApply:()=>T("ide","apply"),onReset:()=>T("ide","reset"),disabled:c,busy:ye})]}),e.jsxs("div",{className:"grid gap-6 xl:grid-cols-[minmax(0,1.15fr)_minmax(320px,0.85fr)]",children:[e.jsxs(u,{className:"border-border/60 bg-card/80",children:[e.jsxs(f,{children:[e.jsx(j,{className:"text-base",children:s("settingsPage.thinkingSection.resolvedBinding")}),e.jsx(b,{children:"The binding uses the same profile resolution as `ccs persist` and `ccs env`."})]}),e.jsxs(h,{className:"space-y-3",children:[e.jsx(o,{label:"Profile",value:i?.profile.label||l.profile||"Not selected"}),e.jsx(o,{label:"Profile type",value:i?.profile.profileType||"Unknown"}),e.jsx(o,{label:"IDE host",value:d?.label||"Not selected"}),e.jsx(o,{label:"IDE path mode",value:l.ideSettingsPath.trim()?"Custom path":"Default user path"}),e.jsx(o,{label:"Effective IDE path",value:m?.ideSettings.path||l.ideSettingsPath.trim()||d?.defaultSettingsPath||"Unavailable",mono:!0,copyValue:m?.ideSettings.path||l.ideSettingsPath.trim()||d?.defaultSettingsPath}),e.jsx(o,{label:"Persist command",value:i?.sharedSettings.command||"Save a valid binding first",mono:!0}),l.notes.trim()?e.jsx(o,{label:"Notes",value:l.notes.trim()}):null]})]}),e.jsxs(u,{className:"border-border/60 bg-card/80",children:[e.jsxs(f,{children:[e.jsx(j,{className:"text-base",children:s("settingsPage.thinkingSection.managedPayload")}),e.jsx(b,{children:"Keep the main view short. The full JSON stays in the Advanced tab."})]}),e.jsxs(h,{className:"space-y-4",children:[e.jsxs("div",{className:"flex flex-wrap gap-2",children:[Se.map(t=>e.jsx(p,{variant:"secondary",className:"font-mono text-[10px]",children:t.name},t.name)),te>0?e.jsxs(p,{variant:"outline",children:["+",te," more"]}):null]}),e.jsx("div",{className:"rounded-lg border bg-muted/25 p-4 text-sm",children:i?.env.length?e.jsxs("div",{className:"space-y-2",children:[e.jsxs("div",{className:"font-medium",children:["CCS will inject ",i.env.length," environment values."]}),e.jsx("div",{className:"text-muted-foreground",children:"The IDE-local target receives the extension schema. The shared target receives the same env block through Claude settings."})]}):e.jsx("div",{className:"text-muted-foreground",children:"This profile resolves to native Claude defaults, so apply/reset mainly clears existing CCS-managed overrides."})}),c?e.jsx("div",{className:"rounded-lg border border-dashed bg-muted/15 p-4 text-sm text-muted-foreground",children:"Save this draft to unlock apply, reset, and verify actions."}):e.jsxs("div",{className:"flex gap-2",children:[e.jsxs(S,{className:"flex-1",onClick:()=>T("all","apply"),disabled:x.isPending,children:[x.isPending&&x.variables?.target==="all"?e.jsx(F,{className:"mr-1.5 h-3.5 w-3.5 animate-spin"}):null,"Apply both targets"]}),e.jsx(S,{variant:"outline",className:"flex-1",onClick:()=>T("all","reset"),disabled:v.isPending,children:"Reset both targets"})]})]})]})]}),i&&(i.warnings.length>0||i.notes.length>0)?e.jsxs("div",{className:"grid gap-6 xl:grid-cols-2",children:[e.jsxs(u,{className:"border-border/60 bg-card/80",children:[e.jsxs(f,{children:[e.jsx(j,{className:"text-base",children:s("settingsPage.thinkingSection.warnings")}),e.jsx(b,{children:"Operational details that can break the binding even when JSON is correct."})]}),e.jsx(h,{className:"space-y-3",children:i.warnings.length>0?i.warnings.map(t=>e.jsxs("div",{className:"flex items-start gap-3 rounded-lg border border-amber-400/40 bg-amber-50/60 p-3 text-sm dark:bg-amber-950/10",children:[e.jsx(me,{className:"mt-0.5 h-4 w-4 shrink-0 text-amber-600"}),e.jsx("span",{children:t})]},t)):e.jsx("div",{className:"rounded-lg border bg-muted/20 p-3 text-sm text-muted-foreground",children:"No runtime warnings for this binding."})})]}),e.jsxs(u,{className:"border-border/60 bg-card/80",children:[e.jsxs(f,{children:[e.jsx(j,{className:"text-base",children:s("settingsPage.thinkingSection.notes")}),e.jsx(b,{children:"Short context from CCS about account continuity and host-specific behavior."})]}),e.jsx(h,{className:"space-y-3",children:i.notes.length>0?i.notes.map(t=>e.jsxs("div",{className:"flex items-start gap-3 rounded-lg border bg-muted/30 p-3 text-sm",children:[e.jsx(qe,{className:"mt-0.5 h-4 w-4 shrink-0 text-muted-foreground"}),e.jsx("span",{children:t})]},t)):e.jsx("div",{className:"rounded-lg border bg-muted/20 p-3 text-sm text-muted-foreground",children:"No extra notes for this binding."})})]})]}):null]}),e.jsx(ce,{value:"advanced",className:"mt-0 space-y-6",children:i?e.jsxs(e.Fragment,{children:[e.jsxs("div",{className:"grid gap-6 xl:grid-cols-2",children:[e.jsx(xe,{title:"Shared Claude settings JSON",description:"Managed env block for ~/.claude/settings.json.",value:i.sharedSettings.json}),e.jsx(xe,{title:`${d?.label||"IDE"} settings JSON`,description:`Anthropic extension snippet for ${d?.settingsTargetLabel||"settings.json"}.`,value:i.ideSettings.json})]}),e.jsxs(u,{className:"border-border/60 bg-card/80",children:[e.jsx(f,{children:e.jsxs("div",{className:"flex items-start justify-between gap-3",children:[e.jsxs("div",{children:[e.jsx(j,{className:"text-base",children:"Resolved environment payload"}),e.jsx(b,{children:"Exact environment values that the extension receives after CCS expands this profile."})]}),e.jsx(K,{value:JSON.stringify(i.env,null,2),label:"Copy environment payload"})]})}),e.jsx(h,{children:i.env.length>0?e.jsx("pre",{className:"max-h-[420px] overflow-auto rounded-lg border bg-muted/30 p-4 text-xs leading-6",children:JSON.stringify(i.env,null,2)}):e.jsx("div",{className:"rounded-lg border bg-muted/20 p-4 text-sm text-muted-foreground",children:"No env payload. This binding resolves to native Claude defaults."})})]}),e.jsxs("div",{className:"grid gap-6 xl:grid-cols-2",children:[e.jsxs(u,{className:"border-border/60 bg-card/80",children:[e.jsxs(f,{children:[e.jsx(j,{className:"text-base",children:"Shared target metadata"}),e.jsx(b,{children:"Useful when debugging drift or comparing with manual edits."})]}),e.jsxs(h,{className:"space-y-3",children:[e.jsx(o,{label:"Target path",value:m?.sharedSettings.path||i.sharedSettings.path,mono:!0,copyValue:m?.sharedSettings.path||i.sharedSettings.path}),e.jsx(o,{label:"Command",value:i.sharedSettings.command,mono:!0}),e.jsx(o,{label:"Current state",value:m?.sharedSettings.state||"Not verified"})]})]}),e.jsxs(u,{className:"border-border/60 bg-card/80",children:[e.jsxs(f,{children:[e.jsx(j,{className:"text-base",children:"IDE target metadata"}),e.jsx(b,{children:"Current file path plus the extension setting key used for this host."})]}),e.jsxs(h,{className:"space-y-3",children:[e.jsx(o,{label:"Target path",value:m?.ideSettings.path||l.ideSettingsPath.trim()||d?.defaultSettingsPath||i.ideSettings.path,mono:!0,copyValue:m?.ideSettings.path||l.ideSettingsPath.trim()||d?.defaultSettingsPath||i.ideSettings.path}),e.jsx(o,{label:"Settings key",value:d?.settingsKey||"Unknown",mono:!0}),e.jsx(o,{label:"Current state",value:m?.ideSettings.state||"Not verified"})]})]})]})]}):e.jsx(u,{className:"border-border/60 bg-card/80",children:e.jsxs(h,{className:"flex min-h-[240px] items-center justify-center gap-3 text-sm text-muted-foreground",children:[e.jsx(Ae,{className:"h-5 w-5"}),"Choose a profile and IDE host to preview the generated payload."]})})})]})]})})})]})}export{is as ClaudeExtensionPage};