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

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (55) hide show
  1. package/README.md +1 -0
  2. package/dist/cursor/cursor-anthropic-response.d.ts +6 -0
  3. package/dist/cursor/cursor-anthropic-response.d.ts.map +1 -0
  4. package/dist/cursor/cursor-anthropic-response.js +190 -0
  5. package/dist/cursor/cursor-anthropic-response.js.map +1 -0
  6. package/dist/cursor/cursor-anthropic-translator.d.ts +11 -0
  7. package/dist/cursor/cursor-anthropic-translator.d.ts.map +1 -0
  8. package/dist/cursor/cursor-anthropic-translator.js +167 -0
  9. package/dist/cursor/cursor-anthropic-translator.js.map +1 -0
  10. package/dist/cursor/cursor-anthropic-types.d.ts +46 -0
  11. package/dist/cursor/cursor-anthropic-types.d.ts.map +1 -0
  12. package/dist/cursor/cursor-anthropic-types.js +3 -0
  13. package/dist/cursor/cursor-anthropic-types.js.map +1 -0
  14. package/dist/cursor/cursor-daemon-entry.d.ts.map +1 -1
  15. package/dist/cursor/cursor-daemon-entry.js +53 -24
  16. package/dist/cursor/cursor-daemon-entry.js.map +1 -1
  17. package/dist/cursor/cursor-models.d.ts.map +1 -1
  18. package/dist/cursor/cursor-models.js +36 -2
  19. package/dist/cursor/cursor-models.js.map +1 -1
  20. package/dist/glmt/sse-parser.d.ts +2 -0
  21. package/dist/glmt/sse-parser.d.ts.map +1 -1
  22. package/dist/glmt/sse-parser.js +4 -0
  23. package/dist/glmt/sse-parser.js.map +1 -1
  24. package/dist/shared/provider-preset-catalog.d.ts +1 -1
  25. package/dist/shared/provider-preset-catalog.d.ts.map +1 -1
  26. package/dist/shared/provider-preset-catalog.js +15 -0
  27. package/dist/shared/provider-preset-catalog.js.map +1 -1
  28. package/dist/ui/assets/{accounts-CZEg1_PX.js → accounts-CrNRfOOP.js} +1 -1
  29. package/dist/ui/assets/{alert-dialog-DhwS38kc.js → alert-dialog-0GYXcDLu.js} +1 -1
  30. package/dist/ui/assets/{api-sWNND4wP.js → api-Du9rjWhx.js} +1 -1
  31. package/dist/ui/assets/{auth-section-nJIpOcnm.js → auth-section-DMcsqZyo.js} +1 -1
  32. package/dist/ui/assets/{backups-section-D3A6hmrU.js → backups-section-Bu4mUdGV.js} +1 -1
  33. package/dist/ui/assets/{checkbox-CZrxD1iS.js → checkbox-DiyJL_k4.js} +1 -1
  34. package/dist/ui/assets/{claude-extension-BjInaILv.js → claude-extension-CUlLIos9.js} +1 -1
  35. package/dist/ui/assets/{cliproxy-BGiSCGkl.js → cliproxy-DS95Joc9.js} +1 -1
  36. package/dist/ui/assets/{cliproxy-control-panel-CKO2Sn9B.js → cliproxy-control-panel-BNUMUGIt.js} +1 -1
  37. package/dist/ui/assets/{confirm-dialog-DTKxwrat.js → confirm-dialog-DTWvVQlx.js} +1 -1
  38. package/dist/ui/assets/{copilot-CuRngdBg.js → copilot-p2K9Y5LR.js} +1 -1
  39. package/dist/ui/assets/{cursor-Dxo0uIiU.js → cursor-5SbcR5sW.js} +1 -1
  40. package/dist/ui/assets/{droid-Cl8QsJJL.js → droid-DxdiLHHD.js} +1 -1
  41. package/dist/ui/assets/{globalenv-section-C3dxxoD9.js → globalenv-section-B9l_4XUg.js} +1 -1
  42. package/dist/ui/assets/{health-BUifaDU7.js → health-DDs2IlMm.js} +1 -1
  43. package/dist/ui/assets/{index-CYo-E5rU.js → index-Cy76XBS9.js} +1 -1
  44. package/dist/ui/assets/{index-xayyyR26.js → index-D3yHEBlf.js} +1 -1
  45. package/dist/ui/assets/{index-Cw9Urr0S.js → index-JgHDFSHt.js} +3 -3
  46. package/dist/ui/assets/{index-CPdceT1C.js → index-X7b7NDPo.js} +1 -1
  47. package/dist/ui/assets/{index-BOsbrhaa.js → index-awSrtRcI.js} +1 -1
  48. package/dist/ui/assets/{proxy-status-widget-D94htBPb.js → proxy-status-widget-DEkHz7X-.js} +1 -1
  49. package/dist/ui/assets/{separator-3fBbTn-V.js → separator-BFr5KvfF.js} +1 -1
  50. package/dist/ui/assets/{shared-q_FNNbjD.js → shared-BwP9MOQi.js} +1 -1
  51. package/dist/ui/assets/{switch-5N8qBdBr.js → switch-w7IoOY5x.js} +1 -1
  52. package/dist/ui/assets/{updates-CubQ54J0.js → updates--SN_PZnJ.js} +1 -1
  53. package/dist/ui/icons/novita.svg +9 -0
  54. package/dist/ui/index.html +1 -1
  55. package/package.json +1 -1
@@ -1,4 +1,4 @@
1
- import{j as e}from"./radix-ui-BR1vy4kf.js";import{r as m}from"./react-vendor-CNOkPC89.js";import{B as D,c as M,T as $e,p as ze,q as Ke,r as Qe,s as Je,t as Be,v as qe,w as me,d as g,I as A,a as V,n as ne,L as T,x as q,y as Pe,z as Ve,A as Ye,D as Ge,E as We,S as xe,F as se,G as ie,H as Oe,J as Xe,K as Ze,M as Ee,N as Te,O as Se,Q as es,R as ss,U as ue,V as he,W as te,X as ts,Y as as,Z as ce,C as pe,j as ge,k as fe,_ as je,b as Ne,$ as rs,a0 as ns,a1 as is,a2 as ls,a3 as os,a4 as cs,a5 as ds,a6 as ms,a7 as xs}from"./index-Cw9Urr0S.js";import{a as us,u as hs,b as ve}from"./tanstack-e99Cjjy2.js";import{C as le}from"./confirm-dialog-DTKxwrat.js";import{t as k}from"./notifications-B2HqRBj7.js";import{L as ae,R as X,ai as Ae,aj as ps,E as gs,f as fs,a3 as re,O as js,ak as _e,a4 as de,C as Re,al as Ns,a2 as vs,am as bs,o as oe,X as ws,Z as Me,an as be,ao as De,m as Cs,a6 as ys,ap as ks,x as Le,aq as Ps,v as Ie,n as Os,ar as Es}from"./icons-DrEfTmfX.js";import{S as we}from"./separator-3fBbTn-V.js";import"./utils-CzKF5WmX.js";import"./form-utils-Bcoyqxpq.js";import"./code-highlight-BRUf_pqB.js";import"./alert-dialog-DhwS38kc.js";function Ts({className:s,showTooltip:t=!0}){const n=e.jsxs(D,{variant:"outline",className:M("bg-accent/10 border-accent/30 text-accent","dark:bg-accent/20 dark:border-accent/40 dark:text-accent-foreground",s),children:[e.jsx("img",{src:"/icons/openrouter.svg",alt:"OpenRouter",className:"mr-1 h-3 w-3"}),"OpenRouter"]});return t?e.jsxs($e,{children:[e.jsx(ze,{asChild:!0,children:n}),e.jsx(Ke,{children:e.jsx("p",{children:"Access 349+ models via OpenRouter"})})]}):n}function Ce(s){return[/^ANTHROPIC_AUTH_TOKEN$/,/_API_KEY$/,/_AUTH_TOKEN$/,/^API_KEY$/,/^AUTH_TOKEN$/,/_SECRET$/,/^SECRET$/].some(n=>n.test(s))}function Ue(s){return s?.env?(s.env.ANTHROPIC_BASE_URL||"").toLowerCase().includes("openrouter.ai"):!1}function Ss(s){return{opus:s.ANTHROPIC_DEFAULT_OPUS_MODEL||void 0,sonnet:s.ANTHROPIC_DEFAULT_SONNET_MODEL||void 0,haiku:s.ANTHROPIC_DEFAULT_HAIKU_MODEL||void 0}}function As(s,t){const n={...s};return t.opus?n.ANTHROPIC_DEFAULT_OPUS_MODEL=t.opus:delete n.ANTHROPIC_DEFAULT_OPUS_MODEL,t.sonnet?n.ANTHROPIC_DEFAULT_SONNET_MODEL=t.sonnet:delete n.ANTHROPIC_DEFAULT_SONNET_MODEL,t.haiku?n.ANTHROPIC_DEFAULT_HAIKU_MODEL=t.haiku:delete n.ANTHROPIC_DEFAULT_HAIKU_MODEL,n}function _s({profileName:s,target:t,data:n,settings:a,isLoading:l,isSaving:p,isTargetSaving:h,hasChanges:j,isRawJsonValid:r,onTargetChange:f,onRefresh:u,onDelete:N,onSave:P}){const w=p||h,v=l||w;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}),n?.path&&e.jsx(D,{variant:"outline",className:"text-xs",children:n.path.replace(/^.*\//,"")}),Ue(a)&&e.jsx(Ts,{className:"ml-1"})]}),n&&e.jsxs("p",{className:"text-xs text-muted-foreground mt-0.5",children:["Last modified: ",new Date(n.mtime).toLocaleString()]}),e.jsxs("div",{className:"mt-2 flex items-center gap-2",children:[e.jsx("span",{className:"text-xs text-muted-foreground",children:"Default target:"}),e.jsxs(Qe,{value:t,onValueChange:O=>{v||f(O)},disabled:v,children:[e.jsx(Je,{className:"h-7 w-[170px] text-xs",disabled:v,children:e.jsx(Be,{})}),e.jsxs(qe,{children:[e.jsx(me,{value:"claude",children:"Claude Code"}),e.jsx(me,{value:"droid",children:"Factory Droid"})]})]}),h&&e.jsx(ae,{className:"w-3.5 h-3.5 animate-spin text-muted-foreground"})]})]}),e.jsxs("div",{className:"flex items-center gap-2",children:[e.jsx(g,{variant:"ghost",size:"sm",onClick:u,disabled:v,children:e.jsx(X,{className:`w-4 h-4 ${l?"animate-spin":""}`})}),N&&e.jsx(g,{variant:"ghost",size:"sm",onClick:N,disabled:w,children:e.jsx(Ae,{className:"w-4 h-4 text-destructive"})}),e.jsx(g,{size:"sm",onClick:P,disabled:w||!j||!r,children:p?e.jsxs(e.Fragment,{children:[e.jsx(ae,{className:"w-4 h-4 mr-1 animate-spin"}),"Saving..."]}):e.jsxs(e.Fragment,{children:[e.jsx(ps,{className:"w-4 h-4 mr-1"}),"Save"]})})]})]})}function Fe({label:s,...t}){const[n,a]=m.useState(!1);return e.jsxs("div",{className:"space-y-1",children:[s&&e.jsx("label",{className:"text-sm font-medium",children:s}),e.jsxs("div",{className:"relative",children:[e.jsx(A,{type:n?"text":"password",className:"pr-10 font-mono",...t}),e.jsx(g,{type:"button",variant:"ghost",size:"sm",className:"absolute right-0 top-0 h-full px-3",onClick:()=>a(!n),tabIndex:-1,children:n?e.jsx(gs,{className:"w-4 h-4"}):e.jsx(fs,{className:"w-4 h-4"})})]})]})}function Rs({currentSettings:s,newEnvKey:t,newEnvValue:n,onNewEnvKeyChange:a,onNewEnvValueChange:l,onEnvValueChange:p,onAddEnvVar:h}){const{t:j}=V();return e.jsxs(e.Fragment,{children:[e.jsx(ne,{className:"flex-1",children:e.jsx("div",{className:"p-4 space-y-4",children:s?.env&&Object.keys(s.env).length>0?e.jsx(e.Fragment,{children:Object.entries(s.env).map(([r,f])=>e.jsxs("div",{className:"space-y-1.5",children:[e.jsxs(T,{className:"text-xs font-medium flex items-center gap-2 text-muted-foreground",children:[r,Ce(r)&&e.jsx(D,{variant:"secondary",className:"text-[10px] px-1 py-0 h-4",children:j("envEditor.sensitive")})]}),Ce(r)?e.jsx(Fe,{value:f,onChange:u=>p(r,u.target.value),className:"font-mono text-sm h-8"}):e.jsx(A,{value:f,onChange:u=>p(r,u.target.value),className:"font-mono text-sm h-8"})]},r))}):e.jsxs("div",{className:"py-8 text-center text-muted-foreground bg-muted/30 rounded-lg border border-dashed text-sm",children:[e.jsx("p",{children:j("envEditor.none")}),e.jsx("p",{className:"text-xs mt-1 opacity-70",children:j("envEditor.noneHint")})]})})}),e.jsxs("div",{className:"p-4 border-t bg-background shrink-0",children:[e.jsx(T,{className:"text-xs font-medium text-muted-foreground",children:j("envEditor.addVariable")}),e.jsxs("div",{className:"flex gap-2 mt-2",children:[e.jsx(A,{placeholder:j("envEditor.keyPlaceholder"),value:t,onChange:r=>a(r.target.value.toUpperCase()),className:"font-mono text-sm h-8 w-2/5",onKeyDown:r=>r.key==="Enter"&&t.trim()&&h()}),e.jsx(A,{placeholder:j("envEditor.valuePlaceholder"),value:n,onChange:r=>l(r.target.value),className:"font-mono text-sm h-8 flex-1",onKeyDown:r=>r.key==="Enter"&&t.trim()&&h()}),e.jsx(g,{variant:"outline",size:"sm",className:"h-8",onClick:h,disabled:!t.trim(),children:e.jsx(re,{className:"w-4 h-4"})})]})]})]})}function Ms({profileName:s,target:t,data:n}){const{t:a}=V(),l=t==="droid";return e.jsx(ne,{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(js,{className:"w-4 h-4"}),a("profileEditor.profileInfo")]}),e.jsx("div",{className:"space-y-3 bg-card rounded-lg border p-4 shadow-sm",children:n&&e.jsxs(e.Fragment,{children:[e.jsxs("div",{className:"grid grid-cols-[100px_1fr] gap-2 text-sm items-center",children:[e.jsx("span",{className:"font-medium text-muted-foreground",children:a("profileEditor.profileName")}),e.jsx("span",{className:"font-mono",children:n.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:a("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:n.path}),e.jsx(q,{value:n.path,size:"icon",className:"h-5 w-5"})]})]}),e.jsxs("div",{className:"grid grid-cols-[100px_1fr] gap-2 text-sm items-center",children:[e.jsx("span",{className:"font-medium text-muted-foreground",children:a("profileEditor.lastModified")}),e.jsx("span",{className:"text-xs",children:new Date(n.mtime).toLocaleString()})]}),e.jsxs("div",{className:"grid grid-cols-[100px_1fr] gap-2 text-sm items-center",children:[e.jsx("span",{className:"font-medium text-muted-foreground",children:a("profileEditor.defaultTarget")}),e.jsx("span",{className:"font-mono",children:t})]})]})})]}),e.jsxs("div",{children:[e.jsx("h3",{className:"text-sm font-medium mb-3",children:a("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(T,{className:"text-xs text-muted-foreground",children:a("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(q,{value:`ccs ${s} "prompt"`,size:"icon",className:"h-6 w-6"})]})]}),e.jsxs("div",{children:[e.jsx(T,{className:"text-xs text-muted-foreground",children:a(l?"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:l?`ccsd ${s} "prompt"`:`ccs ${s} --target droid "prompt"`}),e.jsx(q,{value:l?`ccsd ${s} "prompt"`:`ccs ${s} --target droid "prompt"`,size:"icon",className:"h-6 w-6"})]})]}),e.jsxs("div",{children:[e.jsx(T,{className:"text-xs text-muted-foreground",children:a(l?"profileEditor.overrideToClaude":"profileEditor.overrideToClaudeExplicit")}),e.jsxs("div",{className:"mt-1 flex gap-2",children:[e.jsxs("code",{className:"flex-1 px-2 py-1.5 bg-muted rounded text-xs font-mono truncate",children:["ccs ",s,' --target claude "prompt"']}),e.jsx(q,{value:`ccs ${s} --target claude "prompt"`,size:"icon",className:"h-6 w-6"})]})]}),e.jsxs("div",{children:[e.jsx(T,{className:"text-xs text-muted-foreground",children:a("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(q,{value:`ccs default ${s}`,size:"icon",className:"h-6 w-6"})]})]})]})]})]})})}function Ds({value:s,onChange:t,placeholder:n="Search models...",className:a}){const[l,p]=m.useState(""),[h,j]=m.useState(null),{models:r,isLoading:f,isError:u,isFetching:N}=Pe(),P=Ve(),w=m.useMemo(()=>Ye(r,l,{category:h??void 0}),[r,l,h]),v=m.useMemo(()=>Ge(r,2),[r]),O=!l.trim()&&!h,b=m.useMemo(()=>{const c={anthropic:[],openai:[],google:[],meta:[],mistral:[],opensource:[],other:[]};w.forEach(x=>{c[x.category].push(x)});for(const x of Object.keys(c))c[x]=We(c[x]);return c},[w]),F=m.useCallback(()=>{P()},[P]),y=r.find(c=>c.id===s);return f&&r.length===0?e.jsxs("div",{className:M("space-y-2",a),children:[e.jsx(xe,{className:"h-10 w-full"}),e.jsx(xe,{className:"h-32 w-full"})]}):e.jsxs("div",{className:M("space-y-2 w-full min-w-0 overflow-hidden",a),children:[e.jsxs("div",{className:"flex gap-2",children:[e.jsxs("div",{className:"relative flex-1",children:[e.jsx(_e,{className:"text-muted-foreground absolute left-3 top-1/2 h-4 w-4 -translate-y-1/2"}),e.jsx(A,{value:l,onChange:c=>p(c.target.value),placeholder:n,className:"pl-9"})]}),e.jsx(g,{variant:"outline",size:"icon",onClick:F,disabled:N,title:"Refresh models",children:N?e.jsx(ae,{className:"h-4 w-4 animate-spin"}):e.jsx(X,{className:"h-4 w-4"})})]}),e.jsxs("div",{className:"flex flex-wrap gap-1",children:[e.jsxs(D,{variant:h===null?"default":"outline",className:"cursor-pointer",onClick:()=>j(null),children:["All (",r.length,")"]}),Object.keys(se).map(c=>{const x=b[c].length;return x===0?null:e.jsxs(D,{variant:h===c?"default":"outline",className:"cursor-pointer",onClick:()=>j(c),children:[se[c]," (",x,")"]},c)})]}),y&&e.jsxs("div",{className:"bg-muted rounded-md p-2 text-sm",children:[e.jsx("span",{className:"font-medium",children:y.name}),e.jsxs("span",{className:"text-muted-foreground ml-2",children:[ie(y.pricing)," |"," ",Oe(y.context_length)]})]}),e.jsx(ne,{className:"h-72 w-full rounded-md border",children:u?e.jsxs("div",{className:"text-destructive p-4 text-center",children:["Failed to load models."," ",e.jsx(g,{variant:"link",onClick:F,children:"Retry"})]}):w.length===0?e.jsxs("div",{className:"text-muted-foreground p-4 text-center",children:['No models found matching "',l,'"']}):e.jsxs("div",{className:"space-y-6 p-3",children:[O&&v.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(de,{className:"h-3 w-3 text-accent"}),e.jsx("span",{children:"Newest Models"})]}),e.jsx("div",{className:"space-y-1",children:v.map(c=>e.jsx(ye,{model:c,isSelected:c.id===s,onClick:()=>t(c.id),showAge:!0},c.id))})]}),Object.keys(se).map(c=>{const x=b[c];return x.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:se[c]}),e.jsx("div",{className:"space-y-1",children:x.map(o=>e.jsx(ye,{model:o,isSelected:o.id===s,onClick:()=>t(o.id)},o.id))})]},c)})]})})]})}function ye({model:s,isSelected:t,onClick:n,showAge:a=!1}){return e.jsxs("button",{type:"button",onClick:n,className:M("group flex w-full items-center gap-2 rounded-md px-3 py-2 text-left text-sm transition-colors","hover:bg-accent hover:text-accent-foreground",t&&"bg-accent text-accent-foreground"),children:[e.jsx("span",{className:"flex-1 min-w-0 truncate font-medium",children:s.name}),e.jsxs("span",{className:M("flex shrink-0 items-center gap-1 text-xs whitespace-nowrap",t?"text-accent-foreground/80":"text-muted-foreground group-hover:text-accent-foreground/80"),children:[a&&s.created&&e.jsx(D,{variant:"outline",className:M("text-[10px] px-1",t?"border-accent-foreground/30 text-accent-foreground/80":"text-accent border-accent/30 group-hover:text-accent-foreground/80 group-hover:border-accent-foreground/30"),children:Xe(s.created)}),s.isFree?e.jsx(D,{variant:"secondary",className:M("text-[10px] px-1",t?"bg-accent-foreground/20 text-accent-foreground":"group-hover:bg-accent-foreground/20 group-hover:text-accent-foreground"),children:"Free"}):s.isExacto?e.jsxs(e.Fragment,{children:[e.jsx(D,{variant:"outline",className:M("text-[10px] px-1 border-emerald-500/50 text-emerald-600",t?"border-accent-foreground/30 text-accent-foreground/80":"group-hover:border-accent-foreground/30 group-hover:text-accent-foreground/80"),children:"Exacto"}),e.jsx("span",{className:"tabular-nums",children:ie(s.pricing)})]}):e.jsx("span",{className:"tabular-nums",children:ie(s.pricing)}),e.jsx("span",{className:"tabular-nums",children:Oe(s.context_length)})]})]})}function Ls({selectedModel:s,value:t,onChange:n,className:a}){const{t:l}=V(),{models:p}=Pe(),h=m.useMemo(()=>s?Ze(s,p):{},[s,p]),j=()=>{n(h)},r=(u,N)=>{n({...t,[u]:N||void 0})},f=s&&Object.keys(h).length>0;return e.jsxs(Ee,{className:M("group",a),children:[e.jsxs(Te,{className:"flex items-center gap-2 text-sm font-medium hover:underline",children:[e.jsx(Re,{className:"h-4 w-4 transition-transform group-data-[state=open]:rotate-90"}),l("modelTierMapping.title"),e.jsxs("span",{className:"text-muted-foreground font-normal",children:["(",l("modelTierMapping.advanced"),")"]})]}),e.jsxs(Se,{className:"space-y-3 pt-3",children:[e.jsx("p",{className:"text-muted-foreground text-sm",children:l("modelTierMapping.description")}),f&&e.jsxs(g,{type:"button",variant:"outline",size:"sm",onClick:j,children:[e.jsx(Ns,{className:"mr-1 h-4 w-4"}),l("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(T,{htmlFor:"tier-opus",className:"text-right",children:"Opus"}),e.jsx(A,{id:"tier-opus",value:t.opus??"",onChange:u=>r("opus",u.target.value),placeholder:l("modelTierMapping.opusPlaceholder")})]}),e.jsxs("div",{className:"grid grid-cols-[80px_1fr] items-center gap-2",children:[e.jsx(T,{htmlFor:"tier-sonnet",className:"text-right",children:"Sonnet"}),e.jsx(A,{id:"tier-sonnet",value:t.sonnet??"",onChange:u=>r("sonnet",u.target.value),placeholder:l("modelTierMapping.sonnetPlaceholder")})]}),e.jsxs("div",{className:"grid grid-cols-[80px_1fr] items-center gap-2",children:[e.jsx(T,{htmlFor:"tier-haiku",className:"text-right",children:"Haiku"}),e.jsx(A,{id:"tier-haiku",value:t.haiku??"",onChange:u=>r("haiku",u.target.value),placeholder:l("modelTierMapping.haikuPlaceholder")})]})]}),e.jsx("p",{className:"text-muted-foreground text-xs",children:l("modelTierMapping.footer")})]})]})}function Is({profileName:s,target:t,data:n,currentSettings:a,newEnvKey:l,newEnvValue:p,onNewEnvKeyChange:h,onNewEnvValueChange:j,onEnvValueChange:r,onAddEnvVar:f,onEnvBulkChange:u}){const N=Ue(a),P=a?.env,w=m.useMemo(()=>Ss(P??{}),[P]),v=P??{},O=o=>{if(u){const _={...v,ANTHROPIC_MODEL:o,ANTHROPIC_DEFAULT_OPUS_MODEL:o,ANTHROPIC_DEFAULT_SONNET_MODEL:o,ANTHROPIC_DEFAULT_HAIKU_MODEL:o};u(_)}else r("ANTHROPIC_MODEL",o),r("ANTHROPIC_DEFAULT_OPUS_MODEL",o),r("ANTHROPIC_DEFAULT_SONNET_MODEL",o),r("ANTHROPIC_DEFAULT_HAIKU_MODEL",o);k.success(te.t("commonToast.appliedModelAllTiers"),{duration:2e3})},b=o=>{if(u){const _=As(v,o);u(_)}else o.opus!==void 0&&r("ANTHROPIC_DEFAULT_OPUS_MODEL",o.opus||""),o.sonnet!==void 0&&r("ANTHROPIC_DEFAULT_SONNET_MODEL",o.sonnet||""),o.haiku!==void 0&&r("ANTHROPIC_DEFAULT_HAIKU_MODEL",o.haiku||"")},[F,y]=m.useState(!1),c=new Set(["ANTHROPIC_AUTH_TOKEN"]),x=Object.entries(v).filter(([o])=>!c.has(o));return e.jsx("div",{className:"h-full w-full min-w-0 flex flex-col",children:e.jsxs(es,{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(ss,{className:"w-full",children:[e.jsx(ue,{value:"env",className:"flex-1",children:N?"Configuration":"Environment Variables"}),e.jsx(ue,{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(he,{value:"env",className:"flex-1 mt-0 border-0 p-0 data-[state=inactive]:hidden flex flex-col overflow-hidden min-w-0",children:N?e.jsxs(e.Fragment,{children:[e.jsx("div",{className:"flex-1 overflow-hidden",children:e.jsxs("div",{className:"h-full overflow-y-auto overflow-x-hidden p-4 space-y-6",children:[e.jsxs("div",{className:"space-y-3",children:[e.jsx(T,{className:"text-sm font-medium",children:"Model Selection"}),e.jsx(Ds,{value:v.ANTHROPIC_MODEL,onChange:O,placeholder:"Search OpenRouter models..."})]}),e.jsx(Ls,{selectedModel:v.ANTHROPIC_MODEL,value:w,onChange:b}),e.jsxs("div",{className:"space-y-2",children:[e.jsx(T,{className:"text-sm font-medium",children:"API Key"}),e.jsx(Fe,{value:v.ANTHROPIC_AUTH_TOKEN||"",onChange:o=>r("ANTHROPIC_AUTH_TOKEN",o.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"})]})]}),x.length>0&&e.jsxs(Ee,{open:F,onOpenChange:y,children:[e.jsxs(Te,{className:"flex items-center gap-2 text-sm font-medium text-muted-foreground hover:text-foreground transition-colors group",children:[e.jsx(Re,{className:M("h-4 w-4 transition-transform",F&&"rotate-90")}),e.jsx(vs,{className:"h-4 w-4"}),e.jsx("span",{children:"Additional Variables"}),e.jsxs("span",{className:"text-xs font-normal opacity-70",children:["(",x.length,")"]})]}),e.jsx(Se,{className:"pt-4",children:e.jsx("div",{className:"space-y-3 border rounded-lg p-3 bg-muted/30",children:x.map(([o,_])=>e.jsxs("div",{className:"space-y-1",children:[e.jsx(T,{className:"text-xs text-muted-foreground",children:o}),e.jsx(A,{value:_,onChange:$=>r(o,$.target.value),className:"font-mono text-xs h-8"})]},o))})})]})]})}),e.jsxs("div",{className:"p-4 border-t bg-background shrink-0",children:[e.jsx(T,{className:"text-xs font-medium text-muted-foreground",children:"Add Environment Variable"}),e.jsxs("div",{className:"flex gap-2 mt-2",children:[e.jsx(A,{placeholder:"VARIABLE_NAME",value:l,onChange:o=>h(o.target.value.toUpperCase()),className:"font-mono text-sm h-8 w-2/5",onKeyDown:o=>o.key==="Enter"&&l.trim()&&f()}),e.jsx(A,{placeholder:"value",value:p,onChange:o=>j(o.target.value),className:"font-mono text-sm h-8 flex-1",onKeyDown:o=>o.key==="Enter"&&l.trim()&&f()}),e.jsx(g,{variant:"outline",size:"sm",className:"h-8",onClick:f,disabled:!l.trim(),children:e.jsx(re,{className:"w-4 h-4"})})]})]})]}):e.jsx(Rs,{currentSettings:a,newEnvKey:l,newEnvValue:p,onNewEnvKeyChange:h,onNewEnvValueChange:j,onEnvValueChange:r,onAddEnvVar:f})}),e.jsx(he,{value:"info",className:"h-full mt-0 border-0 p-0 data-[state=inactive]:hidden",children:e.jsx(Ms,{profileName:s,target:t,data:n})})]})]})})}function Us({profileName:s,profileTarget:t,onDelete:n,onHasChangesUpdate:a}){const[l,p]=m.useState({}),[h,j]=m.useState(!1),[r,f]=m.useState(null),[u,N]=m.useState(""),[P,w]=m.useState(""),v=us(),{data:O,isLoading:b,isError:F,refetch:y}=hs({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()}}),c=O?.settings,x=m.useMemo(()=>{if(r!==null)try{return JSON.parse(r)}catch{}if(c)return{...c,env:{...c.env,...l}}},[c,l,r]),o=m.useMemo(()=>r!==null?r:c?JSON.stringify(c,null,2):"",[r,c]),_=m.useCallback(d=>{f(d)},[]),$=(d,C)=>{const R={...x?.env||{},[d]:C};p(z=>({...z,[d]:C})),f(JSON.stringify({...x,env:R},null,2))},J=d=>{const C={...x?.env||{},...d};p(R=>({...R,...d})),f(JSON.stringify({...x,env:C},null,2))},Z=()=>{if(!u.trim())return;const d=u.trim(),C=P,R={...x?.env||{},[d]:C};p(z=>({...z,[d]:C})),f(JSON.stringify({...x,env:R},null,2)),N(""),w("")},L=m.useMemo(()=>{try{return JSON.parse(o),!0}catch{return!1}},[o]),B=m.useMemo(()=>r!==null?r!==JSON.stringify(c,null,2):Object.keys(l).length>0,[r,l,c]),E=m.useMemo(()=>{const d=["ANTHROPIC_BASE_URL","ANTHROPIC_AUTH_TOKEN"],C=x?.env||{};return d.filter(R=>!C[R]?.trim())},[x]);m.useEffect(()=>{a?.(B)},[B,a]);const H=ve({mutationFn:async()=>{let d;try{d=JSON.parse(o)}catch{d={...O?.settings,env:{...O?.settings?.env,...l}}}const C=await fetch(`/api/settings/${s}`,{method:"PUT",headers:{"Content-Type":"application/json"},body:JSON.stringify({settings:d,expectedMtime:O?.mtime})});if(C.status===409)throw new Error("CONFLICT");if(!C.ok)throw new Error("Failed to save");return C.json()},onSuccess:()=>{v.invalidateQueries({queryKey:["settings",s]}),v.invalidateQueries({queryKey:["profiles"]}),p({}),f(null),k.success(te.t("commonToast.settingsSaved"))},onError:d=>{d.message==="CONFLICT"?j(!0):k.error(d.message)}}),Y=ve({mutationFn:async d=>(await as.profiles.update(s,{target:d}),d),onSuccess:()=>{v.invalidateQueries({queryKey:["profiles"]}),k.success(te.t("commonToast.defaultTargetUpdated"))},onError:(d,C)=>{const R=C==="droid"?"Factory Droid":"Claude Code",z=d.message.trim()?`: ${d.message}`:"";k.error(te.t("commonToast.failedUpdateDefaultTarget",{target:R,suffix:z}))}}),G=t||"claude",W=H.isPending||Y.isPending,ee=async d=>{j(!1),d?(await y(),H.mutate()):(p({}),f(null))};return e.jsxs("div",{className:"flex-1 flex flex-col overflow-hidden",children:[e.jsx(_s,{profileName:s,target:G,data:O,settings:x,isLoading:b,isSaving:H.isPending,isTargetSaving:Y.isPending,hasChanges:B,isRawJsonValid:L,onTargetChange:d=>{W||d!==G&&Y.mutate(d)},onRefresh:()=>{W||y()},onDelete:n,onSave:()=>{W||H.mutate()}}),b?e.jsxs("div",{className:"flex-1 flex items-center justify-center",children:[e.jsx(ae,{className:"w-8 h-8 animate-spin text-muted-foreground"}),e.jsx("span",{className:"ml-3 text-muted-foreground",children:"Loading settings..."})]}):F?e.jsx("div",{className:"flex-1 flex items-center justify-center",children:e.jsxs("div",{className:"text-center space-y-3",children:[e.jsx("p",{className:"text-sm text-muted-foreground",children:"Failed to load settings."}),e.jsxs(g,{variant:"outline",size:"sm",onClick:()=>y(),children:[e.jsx(X,{className:"w-4 h-4 mr-1"}),"Retry"]})]})}):e.jsxs("div",{className:"flex-1 grid grid-cols-[40%_60%] divide-x overflow-hidden",children:[e.jsx("div",{className:"flex flex-col overflow-hidden bg-muted/5 min-w-0",children:e.jsx(Is,{profileName:s,target:G,data:O,currentSettings:x,newEnvKey:u,newEnvValue:P,onNewEnvKeyChange:N,onNewEnvValueChange:w,onEnvValueChange:$,onEnvBulkChange:J,onAddEnvVar:Z})}),e.jsxs("div",{className:"flex flex-col overflow-hidden",children:[e.jsxs("div",{className:"px-6 py-2 bg-muted/30 border-b flex items-center gap-2 shrink-0 h-[45px]",children:[e.jsx(bs,{className:"w-4 h-4 text-muted-foreground"}),e.jsx("span",{className:"text-sm font-medium text-muted-foreground",children:"Raw Configuration (JSON)"})]}),e.jsx(ts,{rawJsonContent:o,isRawJsonValid:L,rawJsonEdits:r,settings:c,onChange:_,missingRequiredFields:E})]})]}),e.jsx(le,{open:h,title:"File Modified Externally",description:"Overwrite with your changes or discard?",confirmText:"Overwrite",variant:"destructive",onConfirm:()=>ee(!0),onCancel:()=>ee(!1)})]},s)}const ke="ccs:openrouter-banner-dismissed";function Fs({onCreateClick:s}){const[t,n]=m.useState(!0),{modelCount:a,isLoading:l}=ce();m.useEffect(()=>{const h=localStorage.getItem(ke)==="true";n(h)},[]);const p=()=>{localStorage.setItem(ke,"true"),n(!0)};return t?null:e.jsx("div",{className:"bg-gradient-to-r from-accent to-accent/90 text-white px-4 py-3 relative shrink-0",children:e.jsxs("div",{className:"flex items-center justify-between gap-4 max-w-screen-xl mx-auto",children:[e.jsxs("div",{className:"flex items-center gap-3 flex-1 min-w-0",children:[e.jsx("div",{className:"p-1.5 bg-white/20 rounded-md shrink-0",children:e.jsx(de,{className:"w-4 h-4"})}),e.jsxs("div",{className:"flex-1 min-w-0",children:[e.jsx("p",{className:"font-medium text-sm",children:"NEW: OpenRouter Integration"}),e.jsxs("p",{className:"text-xs text-white/80 truncate",children:["Browse ",l?"300+":`${a}+`," models from OpenAI, Anthropic, Google, Meta and more."]})]})]}),e.jsxs("div",{className:"flex items-center gap-2 shrink-0",children:[s&&e.jsx(g,{size:"sm",variant:"secondary",onClick:s,className:"bg-white text-accent hover:bg-white/90 h-8",children:"Try it now"}),e.jsxs("a",{href:"https://openrouter.ai",target:"_blank",rel:"noopener noreferrer",className:"text-xs text-white/80 hover:text-white hidden sm:flex items-center gap-1",children:["Learn more",e.jsx(oe,{className:"w-3 h-3"})]}),e.jsxs(g,{size:"icon",variant:"ghost",onClick:p,className:"h-7 w-7 text-white/70 hover:text-white hover:bg-white/20",children:[e.jsx(ws,{className:"w-4 h-4"}),e.jsx("span",{className:"sr-only",children:"Dismiss"})]})]})]})})}function Hs({onOpenRouterClick:s,onAlibabaCodingPlanClick:t,onCustomClick:n}){const{t:a}=V(),{modelCount:l,isLoading:p}=ce();return e.jsx("div",{className:"flex-1 flex items-center justify-center bg-muted/20 p-8",children:e.jsxs("div",{className:"max-w-lg w-full space-y-6",children:[e.jsxs(pe,{className:"border-accent/30 dark:border-accent/40 bg-gradient-to-br from-accent/5 to-background dark:from-accent/10",children:[e.jsxs(ge,{className:"pb-3",children:[e.jsxs("div",{className:"flex items-center gap-3 mb-2",children:[e.jsx("div",{className:"p-2 rounded-lg bg-accent/10 dark:bg-accent/20",children:e.jsx("img",{src:"/icons/openrouter.svg",alt:"OpenRouter",className:"w-6 h-6"})}),e.jsx(D,{variant:"secondary",className:"bg-accent/10 text-accent dark:bg-accent/20 dark:text-accent-foreground",children:a("openrouterQuickStart.recommended")})]}),e.jsx(fe,{className:"text-xl",children:a("openrouterQuickStart.title")}),e.jsx(je,{className:"text-base",children:a("openrouterQuickStart.description",{modelCountLabel:p?"300+":`${l}+`})})]}),e.jsxs(Ne,{className:"space-y-4",children:[e.jsxs("div",{className:"grid grid-cols-2 gap-3 text-sm",children:[e.jsxs("div",{className:"flex items-center gap-2 text-muted-foreground",children:[e.jsx(Me,{className:"w-4 h-4 text-accent"}),e.jsx("span",{children:a("openrouterQuickStart.featureOneApi")})]}),e.jsxs("div",{className:"flex items-center gap-2 text-muted-foreground",children:[e.jsx(de,{className:"w-4 h-4 text-accent"}),e.jsx("span",{children:a("openrouterQuickStart.featureTierMapping")})]})]}),e.jsxs(g,{onClick:s,className:"w-full bg-accent hover:bg-accent/90 text-white",size:"lg",children:[a("openrouterQuickStart.createOpenRouterProfile"),e.jsx(be,{className:"w-4 h-4 ml-2"})]}),e.jsxs("p",{className:"text-xs text-center text-muted-foreground",children:[a("openrouterQuickStart.getApiKeyAt")," ",e.jsxs("a",{href:"https://openrouter.ai/keys",target:"_blank",rel:"noopener noreferrer",className:"text-accent hover:underline inline-flex items-center gap-1",children:["openrouter.ai/keys",e.jsx(oe,{className:"w-3 h-3"})]})]})]})]}),e.jsxs(pe,{className:"border-orange-500/30 dark:border-orange-500/40 bg-gradient-to-br from-orange-500/5 to-background dark:from-orange-500/10",children:[e.jsxs(ge,{className:"pb-3",children:[e.jsxs("div",{className:"flex items-center gap-3 mb-2",children:[e.jsx("div",{className:"p-2 rounded-lg bg-orange-500/10 dark:bg-orange-500/20",children:e.jsx("img",{src:"/assets/providers/alibabacloud-color.svg",alt:"Alibaba Coding Plan",className:"w-6 h-6"})}),e.jsx(D,{variant:"secondary",className:"bg-orange-500/10 text-orange-700 dark:bg-orange-500/20 dark:text-orange-200",children:a("alibabaCodingPlanQuickStart.recommended")})]}),e.jsx(fe,{className:"text-xl",children:a("alibabaCodingPlanQuickStart.title")}),e.jsx(je,{className:"text-base",children:a("alibabaCodingPlanQuickStart.description")})]}),e.jsxs(Ne,{className:"space-y-4",children:[e.jsxs("div",{className:"grid grid-cols-2 gap-3 text-sm",children:[e.jsxs("div",{className:"flex items-center gap-2 text-muted-foreground",children:[e.jsx(De,{className:"w-4 h-4 text-orange-600"}),e.jsx("span",{children:a("alibabaCodingPlanQuickStart.featureEndpoint")})]}),e.jsxs("div",{className:"flex items-center gap-2 text-muted-foreground",children:[e.jsx(Cs,{className:"w-4 h-4 text-orange-600"}),e.jsx("span",{children:a("alibabaCodingPlanQuickStart.featureKeyFormat")})]})]}),e.jsxs(g,{onClick:t,className:"w-full bg-orange-600 hover:bg-orange-600/90 text-white",size:"lg",children:[a("alibabaCodingPlanQuickStart.createAlibabaProfile"),e.jsx(be,{className:"w-4 h-4 ml-2"})]}),e.jsxs("p",{className:"text-xs text-center text-muted-foreground",children:[a("alibabaCodingPlanQuickStart.readGuideAt")," ",e.jsxs("a",{href:"https://www.alibabacloud.com/help/en/model-studio/coding-plan",target:"_blank",rel:"noopener noreferrer",className:"text-orange-700 dark:text-orange-400 hover:underline inline-flex items-center gap-1",children:["Alibaba Cloud Model Studio",e.jsx(oe,{className:"w-3 h-3"})]})]})]})]}),e.jsxs("div",{className:"flex items-center gap-4",children:[e.jsx(we,{className:"flex-1"}),e.jsx("span",{className:"text-xs text-muted-foreground",children:a("openrouterQuickStart.or")}),e.jsx(we,{className:"flex-1"})]}),e.jsx(g,{variant:"outline",onClick:n,className:"w-full",children:a("openrouterQuickStart.createCustomProfile")})]})})}function $s({onCreateClick:s}){const{modelCount:t,isLoading:n}=ce();return e.jsx("div",{className:"p-3 border-t bg-gradient-to-r from-accent/5 to-accent/10 dark:from-accent/10 dark:to-accent/15",children:e.jsxs("div",{className:"flex items-center gap-2",children:[e.jsx("div",{className:"p-1.5 bg-accent/10 dark:bg-accent/20 rounded shrink-0",children:e.jsx("img",{src:"/icons/openrouter.svg",alt:"",className:"w-4 h-4"})}),e.jsxs("div",{className:"flex-1 min-w-0",children:[e.jsx("p",{className:"text-xs font-medium text-accent dark:text-accent-foreground",children:"OpenRouter"}),e.jsxs("p",{className:"text-[10px] text-muted-foreground truncate",children:[n?"300+":`${t}+`," models available"]})]}),e.jsxs(g,{size:"sm",variant:"ghost",onClick:s,className:"h-7 px-2 text-accent hover:text-accent hover:bg-accent/10 dark:hover:bg-accent/20",children:[e.jsx(Me,{className:"w-3 h-3 mr-1"}),e.jsx("span",{className:"text-xs",children:"Add"})]})]})})}function zs({onCreateClick:s}){const{t}=V();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:t("alibabaCodingPlanPromo.title")}),e.jsx("p",{className:"text-[10px] text-muted-foreground truncate",children:t("alibabaCodingPlanPromo.subtitle")})]}),e.jsxs(g,{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(De,{className:"w-3 h-3 mr-1"}),e.jsx("span",{className:"text-xs",children:t("alibabaCodingPlanPromo.add")})]})]})})}function tt(){const{t:s}=V(),{data:t,isLoading:n,isError:a,refetch:l}=rs(),p=ns(),h=is(),j=ls(),r=os(),f=cs(),u=ds(),[N,P]=m.useState(null),[w,v]=m.useState(""),[O,b]=m.useState(!1),[F,y]=m.useState("normal"),[c,x]=m.useState(null),[o,_]=m.useState(!1),[$,J]=m.useState(null),Z=m.useRef(null);ms();const L=m.useMemo(()=>t?.profiles||[],[t?.profiles]),B=m.useMemo(()=>L.filter(i=>i.name.toLowerCase().includes(w.toLowerCase())),[L,w]),E=N?L.find(i=>i.name===N):null,H=i=>{o&&N!==i?J(i):P(i)},Y=i=>{p.mutate(i,{onSuccess:()=>{N===i&&(P(null),_(!1),J(null)),x(null)}})},G=i=>{b(!1),H(i)},W=i=>{H(i)},ee=(i,I)=>{const S=JSON.stringify(I,null,2)+`
1
+ import{j as e}from"./radix-ui-BR1vy4kf.js";import{r as m}from"./react-vendor-CNOkPC89.js";import{B as D,c as M,T as $e,p as ze,q as Ke,r as Qe,s as Je,t as Be,v as qe,w as me,d as g,I as A,a as V,n as ne,L as T,x as q,y as Pe,z as Ve,A as Ye,D as Ge,E as We,S as xe,F as se,G as ie,H as Oe,J as Xe,K as Ze,M as Ee,N as Te,O as Se,Q as es,R as ss,U as ue,V as he,W as te,X as ts,Y as as,Z as ce,C as pe,j as ge,k as fe,_ as je,b as Ne,$ as rs,a0 as ns,a1 as is,a2 as ls,a3 as os,a4 as cs,a5 as ds,a6 as ms,a7 as xs}from"./index-JgHDFSHt.js";import{a as us,u as hs,b as ve}from"./tanstack-e99Cjjy2.js";import{C as le}from"./confirm-dialog-DTWvVQlx.js";import{t as k}from"./notifications-B2HqRBj7.js";import{L as ae,R as X,ai as Ae,aj as ps,E as gs,f as fs,a3 as re,O as js,ak as _e,a4 as de,C as Re,al as Ns,a2 as vs,am as bs,o as oe,X as ws,Z as Me,an as be,ao as De,m as Cs,a6 as ys,ap as ks,x as Le,aq as Ps,v as Ie,n as Os,ar as Es}from"./icons-DrEfTmfX.js";import{S as we}from"./separator-BFr5KvfF.js";import"./utils-CzKF5WmX.js";import"./form-utils-Bcoyqxpq.js";import"./code-highlight-BRUf_pqB.js";import"./alert-dialog-0GYXcDLu.js";function Ts({className:s,showTooltip:t=!0}){const n=e.jsxs(D,{variant:"outline",className:M("bg-accent/10 border-accent/30 text-accent","dark:bg-accent/20 dark:border-accent/40 dark:text-accent-foreground",s),children:[e.jsx("img",{src:"/icons/openrouter.svg",alt:"OpenRouter",className:"mr-1 h-3 w-3"}),"OpenRouter"]});return t?e.jsxs($e,{children:[e.jsx(ze,{asChild:!0,children:n}),e.jsx(Ke,{children:e.jsx("p",{children:"Access 349+ models via OpenRouter"})})]}):n}function Ce(s){return[/^ANTHROPIC_AUTH_TOKEN$/,/_API_KEY$/,/_AUTH_TOKEN$/,/^API_KEY$/,/^AUTH_TOKEN$/,/_SECRET$/,/^SECRET$/].some(n=>n.test(s))}function Ue(s){return s?.env?(s.env.ANTHROPIC_BASE_URL||"").toLowerCase().includes("openrouter.ai"):!1}function Ss(s){return{opus:s.ANTHROPIC_DEFAULT_OPUS_MODEL||void 0,sonnet:s.ANTHROPIC_DEFAULT_SONNET_MODEL||void 0,haiku:s.ANTHROPIC_DEFAULT_HAIKU_MODEL||void 0}}function As(s,t){const n={...s};return t.opus?n.ANTHROPIC_DEFAULT_OPUS_MODEL=t.opus:delete n.ANTHROPIC_DEFAULT_OPUS_MODEL,t.sonnet?n.ANTHROPIC_DEFAULT_SONNET_MODEL=t.sonnet:delete n.ANTHROPIC_DEFAULT_SONNET_MODEL,t.haiku?n.ANTHROPIC_DEFAULT_HAIKU_MODEL=t.haiku:delete n.ANTHROPIC_DEFAULT_HAIKU_MODEL,n}function _s({profileName:s,target:t,data:n,settings:a,isLoading:l,isSaving:p,isTargetSaving:h,hasChanges:j,isRawJsonValid:r,onTargetChange:f,onRefresh:u,onDelete:N,onSave:P}){const w=p||h,v=l||w;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}),n?.path&&e.jsx(D,{variant:"outline",className:"text-xs",children:n.path.replace(/^.*\//,"")}),Ue(a)&&e.jsx(Ts,{className:"ml-1"})]}),n&&e.jsxs("p",{className:"text-xs text-muted-foreground mt-0.5",children:["Last modified: ",new Date(n.mtime).toLocaleString()]}),e.jsxs("div",{className:"mt-2 flex items-center gap-2",children:[e.jsx("span",{className:"text-xs text-muted-foreground",children:"Default target:"}),e.jsxs(Qe,{value:t,onValueChange:O=>{v||f(O)},disabled:v,children:[e.jsx(Je,{className:"h-7 w-[170px] text-xs",disabled:v,children:e.jsx(Be,{})}),e.jsxs(qe,{children:[e.jsx(me,{value:"claude",children:"Claude Code"}),e.jsx(me,{value:"droid",children:"Factory Droid"})]})]}),h&&e.jsx(ae,{className:"w-3.5 h-3.5 animate-spin text-muted-foreground"})]})]}),e.jsxs("div",{className:"flex items-center gap-2",children:[e.jsx(g,{variant:"ghost",size:"sm",onClick:u,disabled:v,children:e.jsx(X,{className:`w-4 h-4 ${l?"animate-spin":""}`})}),N&&e.jsx(g,{variant:"ghost",size:"sm",onClick:N,disabled:w,children:e.jsx(Ae,{className:"w-4 h-4 text-destructive"})}),e.jsx(g,{size:"sm",onClick:P,disabled:w||!j||!r,children:p?e.jsxs(e.Fragment,{children:[e.jsx(ae,{className:"w-4 h-4 mr-1 animate-spin"}),"Saving..."]}):e.jsxs(e.Fragment,{children:[e.jsx(ps,{className:"w-4 h-4 mr-1"}),"Save"]})})]})]})}function Fe({label:s,...t}){const[n,a]=m.useState(!1);return e.jsxs("div",{className:"space-y-1",children:[s&&e.jsx("label",{className:"text-sm font-medium",children:s}),e.jsxs("div",{className:"relative",children:[e.jsx(A,{type:n?"text":"password",className:"pr-10 font-mono",...t}),e.jsx(g,{type:"button",variant:"ghost",size:"sm",className:"absolute right-0 top-0 h-full px-3",onClick:()=>a(!n),tabIndex:-1,children:n?e.jsx(gs,{className:"w-4 h-4"}):e.jsx(fs,{className:"w-4 h-4"})})]})]})}function Rs({currentSettings:s,newEnvKey:t,newEnvValue:n,onNewEnvKeyChange:a,onNewEnvValueChange:l,onEnvValueChange:p,onAddEnvVar:h}){const{t:j}=V();return e.jsxs(e.Fragment,{children:[e.jsx(ne,{className:"flex-1",children:e.jsx("div",{className:"p-4 space-y-4",children:s?.env&&Object.keys(s.env).length>0?e.jsx(e.Fragment,{children:Object.entries(s.env).map(([r,f])=>e.jsxs("div",{className:"space-y-1.5",children:[e.jsxs(T,{className:"text-xs font-medium flex items-center gap-2 text-muted-foreground",children:[r,Ce(r)&&e.jsx(D,{variant:"secondary",className:"text-[10px] px-1 py-0 h-4",children:j("envEditor.sensitive")})]}),Ce(r)?e.jsx(Fe,{value:f,onChange:u=>p(r,u.target.value),className:"font-mono text-sm h-8"}):e.jsx(A,{value:f,onChange:u=>p(r,u.target.value),className:"font-mono text-sm h-8"})]},r))}):e.jsxs("div",{className:"py-8 text-center text-muted-foreground bg-muted/30 rounded-lg border border-dashed text-sm",children:[e.jsx("p",{children:j("envEditor.none")}),e.jsx("p",{className:"text-xs mt-1 opacity-70",children:j("envEditor.noneHint")})]})})}),e.jsxs("div",{className:"p-4 border-t bg-background shrink-0",children:[e.jsx(T,{className:"text-xs font-medium text-muted-foreground",children:j("envEditor.addVariable")}),e.jsxs("div",{className:"flex gap-2 mt-2",children:[e.jsx(A,{placeholder:j("envEditor.keyPlaceholder"),value:t,onChange:r=>a(r.target.value.toUpperCase()),className:"font-mono text-sm h-8 w-2/5",onKeyDown:r=>r.key==="Enter"&&t.trim()&&h()}),e.jsx(A,{placeholder:j("envEditor.valuePlaceholder"),value:n,onChange:r=>l(r.target.value),className:"font-mono text-sm h-8 flex-1",onKeyDown:r=>r.key==="Enter"&&t.trim()&&h()}),e.jsx(g,{variant:"outline",size:"sm",className:"h-8",onClick:h,disabled:!t.trim(),children:e.jsx(re,{className:"w-4 h-4"})})]})]})]})}function Ms({profileName:s,target:t,data:n}){const{t:a}=V(),l=t==="droid";return e.jsx(ne,{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(js,{className:"w-4 h-4"}),a("profileEditor.profileInfo")]}),e.jsx("div",{className:"space-y-3 bg-card rounded-lg border p-4 shadow-sm",children:n&&e.jsxs(e.Fragment,{children:[e.jsxs("div",{className:"grid grid-cols-[100px_1fr] gap-2 text-sm items-center",children:[e.jsx("span",{className:"font-medium text-muted-foreground",children:a("profileEditor.profileName")}),e.jsx("span",{className:"font-mono",children:n.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:a("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:n.path}),e.jsx(q,{value:n.path,size:"icon",className:"h-5 w-5"})]})]}),e.jsxs("div",{className:"grid grid-cols-[100px_1fr] gap-2 text-sm items-center",children:[e.jsx("span",{className:"font-medium text-muted-foreground",children:a("profileEditor.lastModified")}),e.jsx("span",{className:"text-xs",children:new Date(n.mtime).toLocaleString()})]}),e.jsxs("div",{className:"grid grid-cols-[100px_1fr] gap-2 text-sm items-center",children:[e.jsx("span",{className:"font-medium text-muted-foreground",children:a("profileEditor.defaultTarget")}),e.jsx("span",{className:"font-mono",children:t})]})]})})]}),e.jsxs("div",{children:[e.jsx("h3",{className:"text-sm font-medium mb-3",children:a("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(T,{className:"text-xs text-muted-foreground",children:a("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(q,{value:`ccs ${s} "prompt"`,size:"icon",className:"h-6 w-6"})]})]}),e.jsxs("div",{children:[e.jsx(T,{className:"text-xs text-muted-foreground",children:a(l?"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:l?`ccsd ${s} "prompt"`:`ccs ${s} --target droid "prompt"`}),e.jsx(q,{value:l?`ccsd ${s} "prompt"`:`ccs ${s} --target droid "prompt"`,size:"icon",className:"h-6 w-6"})]})]}),e.jsxs("div",{children:[e.jsx(T,{className:"text-xs text-muted-foreground",children:a(l?"profileEditor.overrideToClaude":"profileEditor.overrideToClaudeExplicit")}),e.jsxs("div",{className:"mt-1 flex gap-2",children:[e.jsxs("code",{className:"flex-1 px-2 py-1.5 bg-muted rounded text-xs font-mono truncate",children:["ccs ",s,' --target claude "prompt"']}),e.jsx(q,{value:`ccs ${s} --target claude "prompt"`,size:"icon",className:"h-6 w-6"})]})]}),e.jsxs("div",{children:[e.jsx(T,{className:"text-xs text-muted-foreground",children:a("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(q,{value:`ccs default ${s}`,size:"icon",className:"h-6 w-6"})]})]})]})]})]})})}function Ds({value:s,onChange:t,placeholder:n="Search models...",className:a}){const[l,p]=m.useState(""),[h,j]=m.useState(null),{models:r,isLoading:f,isError:u,isFetching:N}=Pe(),P=Ve(),w=m.useMemo(()=>Ye(r,l,{category:h??void 0}),[r,l,h]),v=m.useMemo(()=>Ge(r,2),[r]),O=!l.trim()&&!h,b=m.useMemo(()=>{const c={anthropic:[],openai:[],google:[],meta:[],mistral:[],opensource:[],other:[]};w.forEach(x=>{c[x.category].push(x)});for(const x of Object.keys(c))c[x]=We(c[x]);return c},[w]),F=m.useCallback(()=>{P()},[P]),y=r.find(c=>c.id===s);return f&&r.length===0?e.jsxs("div",{className:M("space-y-2",a),children:[e.jsx(xe,{className:"h-10 w-full"}),e.jsx(xe,{className:"h-32 w-full"})]}):e.jsxs("div",{className:M("space-y-2 w-full min-w-0 overflow-hidden",a),children:[e.jsxs("div",{className:"flex gap-2",children:[e.jsxs("div",{className:"relative flex-1",children:[e.jsx(_e,{className:"text-muted-foreground absolute left-3 top-1/2 h-4 w-4 -translate-y-1/2"}),e.jsx(A,{value:l,onChange:c=>p(c.target.value),placeholder:n,className:"pl-9"})]}),e.jsx(g,{variant:"outline",size:"icon",onClick:F,disabled:N,title:"Refresh models",children:N?e.jsx(ae,{className:"h-4 w-4 animate-spin"}):e.jsx(X,{className:"h-4 w-4"})})]}),e.jsxs("div",{className:"flex flex-wrap gap-1",children:[e.jsxs(D,{variant:h===null?"default":"outline",className:"cursor-pointer",onClick:()=>j(null),children:["All (",r.length,")"]}),Object.keys(se).map(c=>{const x=b[c].length;return x===0?null:e.jsxs(D,{variant:h===c?"default":"outline",className:"cursor-pointer",onClick:()=>j(c),children:[se[c]," (",x,")"]},c)})]}),y&&e.jsxs("div",{className:"bg-muted rounded-md p-2 text-sm",children:[e.jsx("span",{className:"font-medium",children:y.name}),e.jsxs("span",{className:"text-muted-foreground ml-2",children:[ie(y.pricing)," |"," ",Oe(y.context_length)]})]}),e.jsx(ne,{className:"h-72 w-full rounded-md border",children:u?e.jsxs("div",{className:"text-destructive p-4 text-center",children:["Failed to load models."," ",e.jsx(g,{variant:"link",onClick:F,children:"Retry"})]}):w.length===0?e.jsxs("div",{className:"text-muted-foreground p-4 text-center",children:['No models found matching "',l,'"']}):e.jsxs("div",{className:"space-y-6 p-3",children:[O&&v.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(de,{className:"h-3 w-3 text-accent"}),e.jsx("span",{children:"Newest Models"})]}),e.jsx("div",{className:"space-y-1",children:v.map(c=>e.jsx(ye,{model:c,isSelected:c.id===s,onClick:()=>t(c.id),showAge:!0},c.id))})]}),Object.keys(se).map(c=>{const x=b[c];return x.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:se[c]}),e.jsx("div",{className:"space-y-1",children:x.map(o=>e.jsx(ye,{model:o,isSelected:o.id===s,onClick:()=>t(o.id)},o.id))})]},c)})]})})]})}function ye({model:s,isSelected:t,onClick:n,showAge:a=!1}){return e.jsxs("button",{type:"button",onClick:n,className:M("group flex w-full items-center gap-2 rounded-md px-3 py-2 text-left text-sm transition-colors","hover:bg-accent hover:text-accent-foreground",t&&"bg-accent text-accent-foreground"),children:[e.jsx("span",{className:"flex-1 min-w-0 truncate font-medium",children:s.name}),e.jsxs("span",{className:M("flex shrink-0 items-center gap-1 text-xs whitespace-nowrap",t?"text-accent-foreground/80":"text-muted-foreground group-hover:text-accent-foreground/80"),children:[a&&s.created&&e.jsx(D,{variant:"outline",className:M("text-[10px] px-1",t?"border-accent-foreground/30 text-accent-foreground/80":"text-accent border-accent/30 group-hover:text-accent-foreground/80 group-hover:border-accent-foreground/30"),children:Xe(s.created)}),s.isFree?e.jsx(D,{variant:"secondary",className:M("text-[10px] px-1",t?"bg-accent-foreground/20 text-accent-foreground":"group-hover:bg-accent-foreground/20 group-hover:text-accent-foreground"),children:"Free"}):s.isExacto?e.jsxs(e.Fragment,{children:[e.jsx(D,{variant:"outline",className:M("text-[10px] px-1 border-emerald-500/50 text-emerald-600",t?"border-accent-foreground/30 text-accent-foreground/80":"group-hover:border-accent-foreground/30 group-hover:text-accent-foreground/80"),children:"Exacto"}),e.jsx("span",{className:"tabular-nums",children:ie(s.pricing)})]}):e.jsx("span",{className:"tabular-nums",children:ie(s.pricing)}),e.jsx("span",{className:"tabular-nums",children:Oe(s.context_length)})]})]})}function Ls({selectedModel:s,value:t,onChange:n,className:a}){const{t:l}=V(),{models:p}=Pe(),h=m.useMemo(()=>s?Ze(s,p):{},[s,p]),j=()=>{n(h)},r=(u,N)=>{n({...t,[u]:N||void 0})},f=s&&Object.keys(h).length>0;return e.jsxs(Ee,{className:M("group",a),children:[e.jsxs(Te,{className:"flex items-center gap-2 text-sm font-medium hover:underline",children:[e.jsx(Re,{className:"h-4 w-4 transition-transform group-data-[state=open]:rotate-90"}),l("modelTierMapping.title"),e.jsxs("span",{className:"text-muted-foreground font-normal",children:["(",l("modelTierMapping.advanced"),")"]})]}),e.jsxs(Se,{className:"space-y-3 pt-3",children:[e.jsx("p",{className:"text-muted-foreground text-sm",children:l("modelTierMapping.description")}),f&&e.jsxs(g,{type:"button",variant:"outline",size:"sm",onClick:j,children:[e.jsx(Ns,{className:"mr-1 h-4 w-4"}),l("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(T,{htmlFor:"tier-opus",className:"text-right",children:"Opus"}),e.jsx(A,{id:"tier-opus",value:t.opus??"",onChange:u=>r("opus",u.target.value),placeholder:l("modelTierMapping.opusPlaceholder")})]}),e.jsxs("div",{className:"grid grid-cols-[80px_1fr] items-center gap-2",children:[e.jsx(T,{htmlFor:"tier-sonnet",className:"text-right",children:"Sonnet"}),e.jsx(A,{id:"tier-sonnet",value:t.sonnet??"",onChange:u=>r("sonnet",u.target.value),placeholder:l("modelTierMapping.sonnetPlaceholder")})]}),e.jsxs("div",{className:"grid grid-cols-[80px_1fr] items-center gap-2",children:[e.jsx(T,{htmlFor:"tier-haiku",className:"text-right",children:"Haiku"}),e.jsx(A,{id:"tier-haiku",value:t.haiku??"",onChange:u=>r("haiku",u.target.value),placeholder:l("modelTierMapping.haikuPlaceholder")})]})]}),e.jsx("p",{className:"text-muted-foreground text-xs",children:l("modelTierMapping.footer")})]})]})}function Is({profileName:s,target:t,data:n,currentSettings:a,newEnvKey:l,newEnvValue:p,onNewEnvKeyChange:h,onNewEnvValueChange:j,onEnvValueChange:r,onAddEnvVar:f,onEnvBulkChange:u}){const N=Ue(a),P=a?.env,w=m.useMemo(()=>Ss(P??{}),[P]),v=P??{},O=o=>{if(u){const _={...v,ANTHROPIC_MODEL:o,ANTHROPIC_DEFAULT_OPUS_MODEL:o,ANTHROPIC_DEFAULT_SONNET_MODEL:o,ANTHROPIC_DEFAULT_HAIKU_MODEL:o};u(_)}else r("ANTHROPIC_MODEL",o),r("ANTHROPIC_DEFAULT_OPUS_MODEL",o),r("ANTHROPIC_DEFAULT_SONNET_MODEL",o),r("ANTHROPIC_DEFAULT_HAIKU_MODEL",o);k.success(te.t("commonToast.appliedModelAllTiers"),{duration:2e3})},b=o=>{if(u){const _=As(v,o);u(_)}else o.opus!==void 0&&r("ANTHROPIC_DEFAULT_OPUS_MODEL",o.opus||""),o.sonnet!==void 0&&r("ANTHROPIC_DEFAULT_SONNET_MODEL",o.sonnet||""),o.haiku!==void 0&&r("ANTHROPIC_DEFAULT_HAIKU_MODEL",o.haiku||"")},[F,y]=m.useState(!1),c=new Set(["ANTHROPIC_AUTH_TOKEN"]),x=Object.entries(v).filter(([o])=>!c.has(o));return e.jsx("div",{className:"h-full w-full min-w-0 flex flex-col",children:e.jsxs(es,{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(ss,{className:"w-full",children:[e.jsx(ue,{value:"env",className:"flex-1",children:N?"Configuration":"Environment Variables"}),e.jsx(ue,{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(he,{value:"env",className:"flex-1 mt-0 border-0 p-0 data-[state=inactive]:hidden flex flex-col overflow-hidden min-w-0",children:N?e.jsxs(e.Fragment,{children:[e.jsx("div",{className:"flex-1 overflow-hidden",children:e.jsxs("div",{className:"h-full overflow-y-auto overflow-x-hidden p-4 space-y-6",children:[e.jsxs("div",{className:"space-y-3",children:[e.jsx(T,{className:"text-sm font-medium",children:"Model Selection"}),e.jsx(Ds,{value:v.ANTHROPIC_MODEL,onChange:O,placeholder:"Search OpenRouter models..."})]}),e.jsx(Ls,{selectedModel:v.ANTHROPIC_MODEL,value:w,onChange:b}),e.jsxs("div",{className:"space-y-2",children:[e.jsx(T,{className:"text-sm font-medium",children:"API Key"}),e.jsx(Fe,{value:v.ANTHROPIC_AUTH_TOKEN||"",onChange:o=>r("ANTHROPIC_AUTH_TOKEN",o.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"})]})]}),x.length>0&&e.jsxs(Ee,{open:F,onOpenChange:y,children:[e.jsxs(Te,{className:"flex items-center gap-2 text-sm font-medium text-muted-foreground hover:text-foreground transition-colors group",children:[e.jsx(Re,{className:M("h-4 w-4 transition-transform",F&&"rotate-90")}),e.jsx(vs,{className:"h-4 w-4"}),e.jsx("span",{children:"Additional Variables"}),e.jsxs("span",{className:"text-xs font-normal opacity-70",children:["(",x.length,")"]})]}),e.jsx(Se,{className:"pt-4",children:e.jsx("div",{className:"space-y-3 border rounded-lg p-3 bg-muted/30",children:x.map(([o,_])=>e.jsxs("div",{className:"space-y-1",children:[e.jsx(T,{className:"text-xs text-muted-foreground",children:o}),e.jsx(A,{value:_,onChange:$=>r(o,$.target.value),className:"font-mono text-xs h-8"})]},o))})})]})]})}),e.jsxs("div",{className:"p-4 border-t bg-background shrink-0",children:[e.jsx(T,{className:"text-xs font-medium text-muted-foreground",children:"Add Environment Variable"}),e.jsxs("div",{className:"flex gap-2 mt-2",children:[e.jsx(A,{placeholder:"VARIABLE_NAME",value:l,onChange:o=>h(o.target.value.toUpperCase()),className:"font-mono text-sm h-8 w-2/5",onKeyDown:o=>o.key==="Enter"&&l.trim()&&f()}),e.jsx(A,{placeholder:"value",value:p,onChange:o=>j(o.target.value),className:"font-mono text-sm h-8 flex-1",onKeyDown:o=>o.key==="Enter"&&l.trim()&&f()}),e.jsx(g,{variant:"outline",size:"sm",className:"h-8",onClick:f,disabled:!l.trim(),children:e.jsx(re,{className:"w-4 h-4"})})]})]})]}):e.jsx(Rs,{currentSettings:a,newEnvKey:l,newEnvValue:p,onNewEnvKeyChange:h,onNewEnvValueChange:j,onEnvValueChange:r,onAddEnvVar:f})}),e.jsx(he,{value:"info",className:"h-full mt-0 border-0 p-0 data-[state=inactive]:hidden",children:e.jsx(Ms,{profileName:s,target:t,data:n})})]})]})})}function Us({profileName:s,profileTarget:t,onDelete:n,onHasChangesUpdate:a}){const[l,p]=m.useState({}),[h,j]=m.useState(!1),[r,f]=m.useState(null),[u,N]=m.useState(""),[P,w]=m.useState(""),v=us(),{data:O,isLoading:b,isError:F,refetch:y}=hs({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()}}),c=O?.settings,x=m.useMemo(()=>{if(r!==null)try{return JSON.parse(r)}catch{}if(c)return{...c,env:{...c.env,...l}}},[c,l,r]),o=m.useMemo(()=>r!==null?r:c?JSON.stringify(c,null,2):"",[r,c]),_=m.useCallback(d=>{f(d)},[]),$=(d,C)=>{const R={...x?.env||{},[d]:C};p(z=>({...z,[d]:C})),f(JSON.stringify({...x,env:R},null,2))},J=d=>{const C={...x?.env||{},...d};p(R=>({...R,...d})),f(JSON.stringify({...x,env:C},null,2))},Z=()=>{if(!u.trim())return;const d=u.trim(),C=P,R={...x?.env||{},[d]:C};p(z=>({...z,[d]:C})),f(JSON.stringify({...x,env:R},null,2)),N(""),w("")},L=m.useMemo(()=>{try{return JSON.parse(o),!0}catch{return!1}},[o]),B=m.useMemo(()=>r!==null?r!==JSON.stringify(c,null,2):Object.keys(l).length>0,[r,l,c]),E=m.useMemo(()=>{const d=["ANTHROPIC_BASE_URL","ANTHROPIC_AUTH_TOKEN"],C=x?.env||{};return d.filter(R=>!C[R]?.trim())},[x]);m.useEffect(()=>{a?.(B)},[B,a]);const H=ve({mutationFn:async()=>{let d;try{d=JSON.parse(o)}catch{d={...O?.settings,env:{...O?.settings?.env,...l}}}const C=await fetch(`/api/settings/${s}`,{method:"PUT",headers:{"Content-Type":"application/json"},body:JSON.stringify({settings:d,expectedMtime:O?.mtime})});if(C.status===409)throw new Error("CONFLICT");if(!C.ok)throw new Error("Failed to save");return C.json()},onSuccess:()=>{v.invalidateQueries({queryKey:["settings",s]}),v.invalidateQueries({queryKey:["profiles"]}),p({}),f(null),k.success(te.t("commonToast.settingsSaved"))},onError:d=>{d.message==="CONFLICT"?j(!0):k.error(d.message)}}),Y=ve({mutationFn:async d=>(await as.profiles.update(s,{target:d}),d),onSuccess:()=>{v.invalidateQueries({queryKey:["profiles"]}),k.success(te.t("commonToast.defaultTargetUpdated"))},onError:(d,C)=>{const R=C==="droid"?"Factory Droid":"Claude Code",z=d.message.trim()?`: ${d.message}`:"";k.error(te.t("commonToast.failedUpdateDefaultTarget",{target:R,suffix:z}))}}),G=t||"claude",W=H.isPending||Y.isPending,ee=async d=>{j(!1),d?(await y(),H.mutate()):(p({}),f(null))};return e.jsxs("div",{className:"flex-1 flex flex-col overflow-hidden",children:[e.jsx(_s,{profileName:s,target:G,data:O,settings:x,isLoading:b,isSaving:H.isPending,isTargetSaving:Y.isPending,hasChanges:B,isRawJsonValid:L,onTargetChange:d=>{W||d!==G&&Y.mutate(d)},onRefresh:()=>{W||y()},onDelete:n,onSave:()=>{W||H.mutate()}}),b?e.jsxs("div",{className:"flex-1 flex items-center justify-center",children:[e.jsx(ae,{className:"w-8 h-8 animate-spin text-muted-foreground"}),e.jsx("span",{className:"ml-3 text-muted-foreground",children:"Loading settings..."})]}):F?e.jsx("div",{className:"flex-1 flex items-center justify-center",children:e.jsxs("div",{className:"text-center space-y-3",children:[e.jsx("p",{className:"text-sm text-muted-foreground",children:"Failed to load settings."}),e.jsxs(g,{variant:"outline",size:"sm",onClick:()=>y(),children:[e.jsx(X,{className:"w-4 h-4 mr-1"}),"Retry"]})]})}):e.jsxs("div",{className:"flex-1 grid grid-cols-[40%_60%] divide-x overflow-hidden",children:[e.jsx("div",{className:"flex flex-col overflow-hidden bg-muted/5 min-w-0",children:e.jsx(Is,{profileName:s,target:G,data:O,currentSettings:x,newEnvKey:u,newEnvValue:P,onNewEnvKeyChange:N,onNewEnvValueChange:w,onEnvValueChange:$,onEnvBulkChange:J,onAddEnvVar:Z})}),e.jsxs("div",{className:"flex flex-col overflow-hidden",children:[e.jsxs("div",{className:"px-6 py-2 bg-muted/30 border-b flex items-center gap-2 shrink-0 h-[45px]",children:[e.jsx(bs,{className:"w-4 h-4 text-muted-foreground"}),e.jsx("span",{className:"text-sm font-medium text-muted-foreground",children:"Raw Configuration (JSON)"})]}),e.jsx(ts,{rawJsonContent:o,isRawJsonValid:L,rawJsonEdits:r,settings:c,onChange:_,missingRequiredFields:E})]})]}),e.jsx(le,{open:h,title:"File Modified Externally",description:"Overwrite with your changes or discard?",confirmText:"Overwrite",variant:"destructive",onConfirm:()=>ee(!0),onCancel:()=>ee(!1)})]},s)}const ke="ccs:openrouter-banner-dismissed";function Fs({onCreateClick:s}){const[t,n]=m.useState(!0),{modelCount:a,isLoading:l}=ce();m.useEffect(()=>{const h=localStorage.getItem(ke)==="true";n(h)},[]);const p=()=>{localStorage.setItem(ke,"true"),n(!0)};return t?null:e.jsx("div",{className:"bg-gradient-to-r from-accent to-accent/90 text-white px-4 py-3 relative shrink-0",children:e.jsxs("div",{className:"flex items-center justify-between gap-4 max-w-screen-xl mx-auto",children:[e.jsxs("div",{className:"flex items-center gap-3 flex-1 min-w-0",children:[e.jsx("div",{className:"p-1.5 bg-white/20 rounded-md shrink-0",children:e.jsx(de,{className:"w-4 h-4"})}),e.jsxs("div",{className:"flex-1 min-w-0",children:[e.jsx("p",{className:"font-medium text-sm",children:"NEW: OpenRouter Integration"}),e.jsxs("p",{className:"text-xs text-white/80 truncate",children:["Browse ",l?"300+":`${a}+`," models from OpenAI, Anthropic, Google, Meta and more."]})]})]}),e.jsxs("div",{className:"flex items-center gap-2 shrink-0",children:[s&&e.jsx(g,{size:"sm",variant:"secondary",onClick:s,className:"bg-white text-accent hover:bg-white/90 h-8",children:"Try it now"}),e.jsxs("a",{href:"https://openrouter.ai",target:"_blank",rel:"noopener noreferrer",className:"text-xs text-white/80 hover:text-white hidden sm:flex items-center gap-1",children:["Learn more",e.jsx(oe,{className:"w-3 h-3"})]}),e.jsxs(g,{size:"icon",variant:"ghost",onClick:p,className:"h-7 w-7 text-white/70 hover:text-white hover:bg-white/20",children:[e.jsx(ws,{className:"w-4 h-4"}),e.jsx("span",{className:"sr-only",children:"Dismiss"})]})]})]})})}function Hs({onOpenRouterClick:s,onAlibabaCodingPlanClick:t,onCustomClick:n}){const{t:a}=V(),{modelCount:l,isLoading:p}=ce();return e.jsx("div",{className:"flex-1 flex items-center justify-center bg-muted/20 p-8",children:e.jsxs("div",{className:"max-w-lg w-full space-y-6",children:[e.jsxs(pe,{className:"border-accent/30 dark:border-accent/40 bg-gradient-to-br from-accent/5 to-background dark:from-accent/10",children:[e.jsxs(ge,{className:"pb-3",children:[e.jsxs("div",{className:"flex items-center gap-3 mb-2",children:[e.jsx("div",{className:"p-2 rounded-lg bg-accent/10 dark:bg-accent/20",children:e.jsx("img",{src:"/icons/openrouter.svg",alt:"OpenRouter",className:"w-6 h-6"})}),e.jsx(D,{variant:"secondary",className:"bg-accent/10 text-accent dark:bg-accent/20 dark:text-accent-foreground",children:a("openrouterQuickStart.recommended")})]}),e.jsx(fe,{className:"text-xl",children:a("openrouterQuickStart.title")}),e.jsx(je,{className:"text-base",children:a("openrouterQuickStart.description",{modelCountLabel:p?"300+":`${l}+`})})]}),e.jsxs(Ne,{className:"space-y-4",children:[e.jsxs("div",{className:"grid grid-cols-2 gap-3 text-sm",children:[e.jsxs("div",{className:"flex items-center gap-2 text-muted-foreground",children:[e.jsx(Me,{className:"w-4 h-4 text-accent"}),e.jsx("span",{children:a("openrouterQuickStart.featureOneApi")})]}),e.jsxs("div",{className:"flex items-center gap-2 text-muted-foreground",children:[e.jsx(de,{className:"w-4 h-4 text-accent"}),e.jsx("span",{children:a("openrouterQuickStart.featureTierMapping")})]})]}),e.jsxs(g,{onClick:s,className:"w-full bg-accent hover:bg-accent/90 text-white",size:"lg",children:[a("openrouterQuickStart.createOpenRouterProfile"),e.jsx(be,{className:"w-4 h-4 ml-2"})]}),e.jsxs("p",{className:"text-xs text-center text-muted-foreground",children:[a("openrouterQuickStart.getApiKeyAt")," ",e.jsxs("a",{href:"https://openrouter.ai/keys",target:"_blank",rel:"noopener noreferrer",className:"text-accent hover:underline inline-flex items-center gap-1",children:["openrouter.ai/keys",e.jsx(oe,{className:"w-3 h-3"})]})]})]})]}),e.jsxs(pe,{className:"border-orange-500/30 dark:border-orange-500/40 bg-gradient-to-br from-orange-500/5 to-background dark:from-orange-500/10",children:[e.jsxs(ge,{className:"pb-3",children:[e.jsxs("div",{className:"flex items-center gap-3 mb-2",children:[e.jsx("div",{className:"p-2 rounded-lg bg-orange-500/10 dark:bg-orange-500/20",children:e.jsx("img",{src:"/assets/providers/alibabacloud-color.svg",alt:"Alibaba Coding Plan",className:"w-6 h-6"})}),e.jsx(D,{variant:"secondary",className:"bg-orange-500/10 text-orange-700 dark:bg-orange-500/20 dark:text-orange-200",children:a("alibabaCodingPlanQuickStart.recommended")})]}),e.jsx(fe,{className:"text-xl",children:a("alibabaCodingPlanQuickStart.title")}),e.jsx(je,{className:"text-base",children:a("alibabaCodingPlanQuickStart.description")})]}),e.jsxs(Ne,{className:"space-y-4",children:[e.jsxs("div",{className:"grid grid-cols-2 gap-3 text-sm",children:[e.jsxs("div",{className:"flex items-center gap-2 text-muted-foreground",children:[e.jsx(De,{className:"w-4 h-4 text-orange-600"}),e.jsx("span",{children:a("alibabaCodingPlanQuickStart.featureEndpoint")})]}),e.jsxs("div",{className:"flex items-center gap-2 text-muted-foreground",children:[e.jsx(Cs,{className:"w-4 h-4 text-orange-600"}),e.jsx("span",{children:a("alibabaCodingPlanQuickStart.featureKeyFormat")})]})]}),e.jsxs(g,{onClick:t,className:"w-full bg-orange-600 hover:bg-orange-600/90 text-white",size:"lg",children:[a("alibabaCodingPlanQuickStart.createAlibabaProfile"),e.jsx(be,{className:"w-4 h-4 ml-2"})]}),e.jsxs("p",{className:"text-xs text-center text-muted-foreground",children:[a("alibabaCodingPlanQuickStart.readGuideAt")," ",e.jsxs("a",{href:"https://www.alibabacloud.com/help/en/model-studio/coding-plan",target:"_blank",rel:"noopener noreferrer",className:"text-orange-700 dark:text-orange-400 hover:underline inline-flex items-center gap-1",children:["Alibaba Cloud Model Studio",e.jsx(oe,{className:"w-3 h-3"})]})]})]})]}),e.jsxs("div",{className:"flex items-center gap-4",children:[e.jsx(we,{className:"flex-1"}),e.jsx("span",{className:"text-xs text-muted-foreground",children:a("openrouterQuickStart.or")}),e.jsx(we,{className:"flex-1"})]}),e.jsx(g,{variant:"outline",onClick:n,className:"w-full",children:a("openrouterQuickStart.createCustomProfile")})]})})}function $s({onCreateClick:s}){const{modelCount:t,isLoading:n}=ce();return e.jsx("div",{className:"p-3 border-t bg-gradient-to-r from-accent/5 to-accent/10 dark:from-accent/10 dark:to-accent/15",children:e.jsxs("div",{className:"flex items-center gap-2",children:[e.jsx("div",{className:"p-1.5 bg-accent/10 dark:bg-accent/20 rounded shrink-0",children:e.jsx("img",{src:"/icons/openrouter.svg",alt:"",className:"w-4 h-4"})}),e.jsxs("div",{className:"flex-1 min-w-0",children:[e.jsx("p",{className:"text-xs font-medium text-accent dark:text-accent-foreground",children:"OpenRouter"}),e.jsxs("p",{className:"text-[10px] text-muted-foreground truncate",children:[n?"300+":`${t}+`," models available"]})]}),e.jsxs(g,{size:"sm",variant:"ghost",onClick:s,className:"h-7 px-2 text-accent hover:text-accent hover:bg-accent/10 dark:hover:bg-accent/20",children:[e.jsx(Me,{className:"w-3 h-3 mr-1"}),e.jsx("span",{className:"text-xs",children:"Add"})]})]})})}function zs({onCreateClick:s}){const{t}=V();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:t("alibabaCodingPlanPromo.title")}),e.jsx("p",{className:"text-[10px] text-muted-foreground truncate",children:t("alibabaCodingPlanPromo.subtitle")})]}),e.jsxs(g,{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(De,{className:"w-3 h-3 mr-1"}),e.jsx("span",{className:"text-xs",children:t("alibabaCodingPlanPromo.add")})]})]})})}function tt(){const{t:s}=V(),{data:t,isLoading:n,isError:a,refetch:l}=rs(),p=ns(),h=is(),j=ls(),r=os(),f=cs(),u=ds(),[N,P]=m.useState(null),[w,v]=m.useState(""),[O,b]=m.useState(!1),[F,y]=m.useState("normal"),[c,x]=m.useState(null),[o,_]=m.useState(!1),[$,J]=m.useState(null),Z=m.useRef(null);ms();const L=m.useMemo(()=>t?.profiles||[],[t?.profiles]),B=m.useMemo(()=>L.filter(i=>i.name.toLowerCase().includes(w.toLowerCase())),[L,w]),E=N?L.find(i=>i.name===N):null,H=i=>{o&&N!==i?J(i):P(i)},Y=i=>{p.mutate(i,{onSuccess:()=>{N===i&&(P(null),_(!1),J(null)),x(null)}})},G=i=>{b(!1),H(i)},W=i=>{H(i)},ee=(i,I)=>{const S=JSON.stringify(I,null,2)+`
2
2
  `,K=new Blob([S],{type:"application/json"}),U=URL.createObjectURL(K),Q=document.createElement("a");Q.href=U,Q.download=i,document.body.appendChild(Q),Q.click(),Q.remove(),URL.revokeObjectURL(U)},d=async()=>{try{const i=await h.mutateAsync();if(i.orphans.length===0){k.success("No orphan profile settings found");return}const I=i.orphans.filter(Q=>Q.validation.valid).length;if(!window.confirm(`Found ${i.orphans.length} orphan settings file(s). Register ${I} valid profile(s) now?`))return;const K=await j.mutateAsync({}),U=K.skipped.length>0?`, skipped ${K.skipped.length}`:"";k.success(`Registered ${K.registered.length} profile(s)${U}`)}catch(i){k.error(i.message)}},C=async()=>{if(!E)return;const i=window.prompt(`Copy profile "${E.name}" to new profile name:`,`${E.name}-copy`);if(!i)return;const I=i.trim();if(!I){k.error("Destination profile name cannot be empty");return}try{const S=await r.mutateAsync({name:E.name,data:{destination:I}});H(I),S.warnings&&S.warnings.length>0&&k.info(S.warnings.join(`
3
3
  `))}catch(S){k.error(S.message)}},R=async()=>{if(E)try{const i=await f.mutateAsync({name:E.name});ee(`${E.name}.ccs-profile.json`,i.bundle),i.redacted?k.info("Export created with redacted token. Use include-secrets flow in CLI if needed."):k.success("Profile export downloaded")}catch(i){k.error(i.message)}},z=()=>{Z.current?.click()},He=async i=>{const I=i.target.files?.[0];if(i.target.value="",!!I)try{const S=await I.text(),K=JSON.parse(S),U=await u.mutateAsync({bundle:K});U.name&&H(U.name),U.warnings&&U.warnings.length>0&&k.info(U.warnings.join(`
4
4
  `))}catch(S){k.error(S.message||"Failed to import profile bundle")}};return e.jsxs("div",{className:"h-[calc(100vh-100px)] flex flex-col",children:[e.jsx(Fs,{onCreateClick:()=>b(!0)}),e.jsxs("div",{className:"flex-1 flex min-h-0",children:[e.jsxs("div",{className:"w-80 border-r flex flex-col bg-muted/30",children:[e.jsxs("div",{className:"p-4 border-b bg-background",children:[e.jsxs("div",{className:"flex items-center justify-between mb-3",children:[e.jsxs("div",{className:"flex items-center gap-2",children:[e.jsx(ys,{className:"w-5 h-5 text-primary"}),e.jsx("h1",{className:"font-semibold",children:s("apiProfiles.title")})]}),e.jsxs("div",{className:"flex items-center gap-1",children:[e.jsx(g,{size:"sm",variant:"outline",onClick:()=>void d(),disabled:h.isPending||j.isPending,"aria-label":"Discover orphan profiles",title:"Discover orphan profiles",children:e.jsx(X,{className:`w-4 h-4 ${h.isPending?"animate-spin":""}`})}),e.jsx(g,{size:"sm",variant:"outline",onClick:z,disabled:u.isPending,"aria-label":"Import profile bundle",title:"Import profile bundle",children:e.jsx(ks,{className:"w-4 h-4"})}),e.jsxs(g,{size:"sm",onClick:()=>{b(!0)},children:[e.jsx(re,{className:"w-4 h-4 mr-1"}),s("apiProfiles.new")]})]})]}),e.jsxs("div",{className:"relative",children:[e.jsx(_e,{className:"absolute left-2.5 top-2.5 h-4 w-4 text-muted-foreground"}),e.jsx(A,{placeholder:s("apiProfiles.searchPlaceholder"),className:"pl-8 h-9",value:w,onChange:i=>v(i.target.value)})]})]}),e.jsx(ne,{className:"flex-1",children:n?e.jsx("div",{className:"p-4 text-sm text-muted-foreground",children:s("apiProfiles.loadingProfiles")}):a?e.jsx("div",{className:"p-4 text-center",children:e.jsxs("div",{className:"space-y-3 py-8",children:[e.jsx(Le,{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(g,{size:"sm",variant:"outline",onClick:()=>l(),children:[e.jsx(X,{className:"w-4 h-4 mr-1"}),s("apiProfiles.retry")]})]})}):B.length===0?e.jsx("div",{className:"p-4 text-center",children:L.length===0?e.jsxs("div",{className:"space-y-3 py-8",children:[e.jsx(Ps,{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(g,{size:"sm",variant:"outline",onClick:()=>{b(!0)},children:[e.jsx(re,{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:w})})}):e.jsx("div",{className:"p-2 space-y-1",children:B.map(i=>e.jsx(Ks,{profile:i,isSelected:N===i.name,onSelect:()=>W(i.name),onDelete:()=>x(i.name)},i.name))})}),L.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:L.length})}),e.jsxs("span",{className:"flex items-center gap-1",children:[e.jsx(Ie,{className:"w-3 h-3 text-green-600"}),s("apiProfiles.configuredCount",{count:L.filter(i=>i.configured).length})]})]})}),e.jsx($s,{onCreateClick:()=>{y("openrouter"),b(!0)}}),e.jsx(zs,{onCreateClick:()=>{y("alibaba-coding-plan"),b(!0)}})]}),e.jsx("div",{className:"flex-1 flex flex-col min-w-0",children:E?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(g,{size:"sm",variant:"outline",onClick:()=>void C(),disabled:r.isPending,children:[e.jsx(Os,{className:"w-4 h-4 mr-1"}),"Copy"]}),e.jsxs(g,{size:"sm",variant:"outline",onClick:()=>void R(),disabled:f.isPending,children:[e.jsx(Es,{className:"w-4 h-4 mr-1"}),"Export"]})]}),e.jsx(Us,{profileName:E.name,profileTarget:E.target,onDelete:()=>x(E.name),onHasChangesUpdate:_},E.name)]}):e.jsx(Hs,{onOpenRouterClick:()=>{y("openrouter"),b(!0)},onAlibabaCodingPlanClick:()=>{y("alibaba-coding-plan"),b(!0)},onCustomClick:()=>{y("normal"),b(!0)}})})]}),e.jsx("input",{ref:Z,type:"file",accept:".json,application/json",className:"hidden",onChange:i=>void He(i)}),e.jsx(xs,{open:O,onOpenChange:b,onSuccess:G,initialMode:F}),e.jsx(le,{open:!!c,title:s("apiProfiles.deleteProfileTitle"),description:s("apiProfiles.deleteProfileDesc",{name:c??""}),confirmText:s("apiProfiles.delete"),variant:"destructive",onConfirm:()=>c&&Y(c),onCancel:()=>x(null)}),e.jsx(le,{open:!!$,title:s("apiProfiles.unsavedChangesTitle"),description:s("apiProfiles.unsavedChangesDesc",{current:N??"",next:$??""}),confirmText:s("apiProfiles.discardSwitch"),variant:"destructive",onConfirm:()=>{_(!1),P($),J(null)},onCancel:()=>J(null)})]})}function Ks({profile:s,isSelected:t,onSelect:n,onDelete:a}){return e.jsxs("div",{className:M("group flex items-center gap-2 px-3 py-2.5 rounded-md cursor-pointer transition-colors",t?"bg-primary/10 border border-primary/20":"hover:bg-muted border border-transparent"),onClick:n,children:[s.configured?e.jsx(Ie,{className:"w-4 h-4 text-green-600 shrink-0"}):e.jsx(Le,{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(D,{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(q,{value:s.settingsPath,size:"icon",className:"h-5 w-5 opacity-0 group-hover:opacity-100 transition-opacity"})]})]}),e.jsx(g,{variant:"ghost",size:"icon",className:"h-7 w-7 opacity-0 group-hover:opacity-100 transition-opacity",onClick:l=>{l.stopPropagation(),a()},children:e.jsx(Ae,{className:"w-3.5 h-3.5 text-destructive"})})]})}export{tt as ApiPage};
@@ -1 +1 @@
1
- import{j as e}from"./radix-ui-BR1vy4kf.js";import{r as n}from"./react-vendor-CNOkPC89.js";import{a as V,bm as W,b5 as X,b7 as Y,n as Z,I as C,d as c}from"./index-Cw9Urr0S.js";import{R as E,x as _,v as ee,m as se,E as K,f as T,l as R,n as z,aC as te,a4 as ae,I as ne,aj as re}from"./icons-DrEfTmfX.js";import"./tanstack-e99Cjjy2.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),[I,b]=n.useState(!1),[$,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 F=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 Q=await A.json();throw new Error(Q.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 G=d??a.apiKey.value,H=u??a.managementSecret.value,M=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:G,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:I?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:H,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:$?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:F,disabled:!M||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-BR1vy4kf.js";import{r as n}from"./react-vendor-CNOkPC89.js";import{a as V,bm as W,b5 as X,b7 as Y,n as Z,I as C,d as c}from"./index-JgHDFSHt.js";import{R as E,x as _,v as ee,m as se,E as K,f as T,l as R,n as z,aC as te,a4 as ae,I as ne,aj as re}from"./icons-DrEfTmfX.js";import"./tanstack-e99Cjjy2.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),[I,b]=n.useState(!1),[$,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 F=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 Q=await A.json();throw new Error(Q.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 G=d??a.apiKey.value,H=u??a.managementSecret.value,M=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:G,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:I?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:H,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:$?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:F,disabled:!M||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-BR1vy4kf.js";import{r}from"./react-vendor-CNOkPC89.js";import{a as S,bm as E,n as k,S as n,C as g,b5 as R,b7 as D,B as T,d as C}from"./index-Cw9Urr0S.js";import{A as O,a as _,b as I,c as F,d as P,e as z,f as L,g as U}from"./alert-dialog-DhwS38kc.js";import{x as $,v as H,a7 as v,u as M,I as Y,R as J}from"./icons-DrEfTmfX.js";import"./tanstack-e99Cjjy2.js";import"./notifications-B2HqRBj7.js";import"./utils-CzKF5WmX.js";import"./form-utils-Bcoyqxpq.js";import"./code-highlight-BRUf_pqB.js";const q=3e3,G=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),G);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(I,{children:[e.jsx(F,{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-BR1vy4kf.js";import{r}from"./react-vendor-CNOkPC89.js";import{a as S,bm as E,n as k,S as n,C as g,b5 as R,b7 as D,B as T,d as C}from"./index-JgHDFSHt.js";import{A as O,a as _,b as I,c as F,d as P,e as z,f as L,g as U}from"./alert-dialog-0GYXcDLu.js";import{x as $,v as H,a7 as v,u as M,I as Y,R as J}from"./icons-DrEfTmfX.js";import"./tanstack-e99Cjjy2.js";import"./notifications-B2HqRBj7.js";import"./utils-CzKF5WmX.js";import"./form-utils-Bcoyqxpq.js";import"./code-highlight-BRUf_pqB.js";const q=3e3,G=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),G);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(I,{children:[e.jsx(F,{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 r,a0 as i,a1 as t}from"./radix-ui-BR1vy4kf.js";import"./react-vendor-CNOkPC89.js";import{c as s}from"./index-Cw9Urr0S.js";import{l as o}from"./icons-DrEfTmfX.js";function b({className:e,...a}){return r.jsx(i,{"data-slot":"checkbox",className:s("peer border-input dark:bg-input/30 data-[state=checked]:bg-primary data-[state=checked]:text-primary-foreground dark:data-[state=checked]:bg-primary data-[state=checked]:border-primary focus-visible:border-ring focus-visible:ring-ring/50 aria-invalid:ring-destructive/20 dark:aria-invalid:ring-destructive/40 aria-invalid:border-destructive size-4 shrink-0 rounded-[4px] border shadow-xs transition-shadow outline-none focus-visible:ring-[3px] disabled:cursor-not-allowed disabled:opacity-50",e),...a,children:r.jsx(t,{"data-slot":"checkbox-indicator",className:"grid place-content-center text-current transition-none",children:r.jsx(o,{className:"size-3.5"})})})}export{b as C};
1
+ import{j as r,a0 as i,a1 as t}from"./radix-ui-BR1vy4kf.js";import"./react-vendor-CNOkPC89.js";import{c as s}from"./index-JgHDFSHt.js";import{l as o}from"./icons-DrEfTmfX.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-BR1vy4kf.js";import{r as W}from"./react-vendor-CNOkPC89.js";import{b2 as Ce,B as p,d as y,n as se,C as u,j as f,k as j,_ as v,b as x,I as H,r as te,s as ae,t as ne,v as ie,w as re,x as F,Q as we,R as Ee,U as le,V as de,c as he}from"./index-Cw9Urr0S.js";import{u as K,a as J,b as V}from"./tanstack-e99Cjjy2.js";import{t as E}from"./notifications-B2HqRBj7.js";import{a4 as Pe,a3 as ke,L as U,aj as De,ai as Be,R as Ie,T as ce,aC as Te,a2 as Re}from"./icons-DrEfTmfX.js";import"./utils-CzKF5WmX.js";import"./form-utils-Bcoyqxpq.js";import"./code-highlight-BRUf_pqB.js";const L=["claude-extension-bindings"];async function P(s,a){const n=await fetch(Ce(s),{headers:{"Content-Type":"application/json"},...a});if(!n.ok){const l=await n.json().catch(()=>null);throw new Error(l?.error||`Request failed (${n.status})`)}return n.status===204?void 0:await n.json()}function qe(){return K({queryKey:["claude-extension-options"],queryFn:()=>P("/claude-extension/profiles")})}function Ae(s,a="vscode"){return K({queryKey:["claude-extension-setup",s,a],enabled:!!s,queryFn:()=>P(`/claude-extension/setup?profile=${encodeURIComponent(s||"")}&host=${encodeURIComponent(a)}`)})}function $e(){return K({queryKey:L,queryFn:()=>P("/claude-extension/bindings")})}function Le(s){return K({queryKey:["claude-extension-binding-status",s],enabled:!!s,queryFn:()=>P(`/claude-extension/bindings/${encodeURIComponent(s||"")}/verify`)})}function Oe(){const s=J();return V({mutationFn:a=>P("/claude-extension/bindings",{method:"POST",body:JSON.stringify(a)}),onSuccess:()=>{s.invalidateQueries({queryKey:L}),E.success("Binding created")},onError:a=>E.error(a.message)})}function Qe(){const s=J();return V({mutationFn:({id:a,binding:n})=>P(`/claude-extension/bindings/${encodeURIComponent(a)}`,{method:"PUT",body:JSON.stringify(n)}),onSuccess:(a,n)=>{s.invalidateQueries({queryKey:L}),s.invalidateQueries({queryKey:["claude-extension-binding-status",n.id]}),E.success("Binding saved")},onError:a=>E.error(a.message)})}function Ue(){const s=J();return V({mutationFn:a=>P(`/claude-extension/bindings/${encodeURIComponent(a)}`,{method:"DELETE"}),onSuccess:()=>{s.invalidateQueries({queryKey:L}),E.success("Binding deleted")},onError:a=>E.error(a.message)})}function ge(s,a){const n=J();return V({mutationFn:({id:l,target:S})=>P(`/claude-extension/bindings/${encodeURIComponent(l)}/${s}`,{method:"POST",body:JSON.stringify({target:S})}),onSuccess:l=>{n.invalidateQueries({queryKey:L}),n.setQueryData(["claude-extension-binding-status",l.bindingId],l),E.success(a)},onError:l=>E.error(l.message)})}function Fe(){return ge("apply","Binding applied")}function Ke(){return ge("reset","Managed values removed")}const Je=[];function oe(s){return{name:"",profile:s,host:"vscode",ideSettingsPath:"",notes:""}}function q(s){return{name:s.name,profile:s.profile,host:s.host,ideSettingsPath:s.ideSettingsPath||"",notes:s.notes||""}}function Ve(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 me(s){return s?.state==="applied"}function Me({state:s}){const a=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:a,children:s})}function _e(s){return s.replace(/[\\/]/g,"$&​")}function c({label:s,value:a,mono:n=!1,copyValue:l}){const S=typeof l=="string"&&l.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}),S?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:_e(a)})}),e.jsx(F,{value:l,label:`Copy ${s.toLowerCase()}`,className:"shrink-0"})]}):e.jsx("span",{className:he("text-left sm:text-right",n&&"font-mono text-xs leading-5 [overflow-wrap:anywhere]"),children:a})]})}function ue({title:s,description:a,value:n}){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(v,{className:"mt-1",children:a})]}),e.jsx(F,{value:n,label:`Copy ${s}`})]})}),e.jsx(x,{children:e.jsx("pre",{className:"max-h-[360px] overflow-auto rounded-lg border bg-muted/30 p-4 text-xs leading-6",children:n})})]})}function xe({title:s,description:a,status:n,applyLabel:l,resetLabel:S,onApply:h,onReset:C,disabled:D,busy:B}){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(v,{className:"mt-1",children:a})]}),n?e.jsx(Me,{state:n.state}):null]})}),e.jsxs(x,{className:"space-y-4",children:[e.jsxs("div",{className:"space-y-2",children:[e.jsx(c,{label:"Path",value:n?.path||"Save a binding first",mono:!0,copyValue:n?.path}),e.jsx(c,{label:"File",value:n?n.exists?"Present":"Not created yet":"Unavailable"})]}),e.jsx("div",{className:"rounded-lg border bg-muted/25 p-3 text-sm text-muted-foreground",children:n?.message||"Verify the binding after saving to inspect the current file state."}),e.jsxs("div",{className:"flex gap-2",children:[e.jsxs(y,{size:"sm",className:"flex-1",onClick:h,disabled:D||B,children:[B?e.jsx(U,{className:"mr-1.5 h-3.5 w-3.5 animate-spin"}):null,l]}),e.jsx(y,{size:"sm",variant:"outline",className:"flex-1",onClick:C,disabled:D||B,children:S})]})]})]})}function ze({binding:s,isSelected:a,onSelect:n}){return e.jsx("button",{onClick:n,className:he("w-full rounded-lg border px-3 py-3 text-left transition-colors",a?"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 as(){const s=qe(),a=$e(),n=Oe(),l=Qe(),S=Ue(),h=Fe(),C=Ke(),D=s.data?.profiles??[],B=s.data?.hosts??[],w=a.data?.bindings??Je,pe=D[0]?.name??"default",[fe,I]=W.useState(!1),[O,T]=W.useState(null),[G,k]=W.useState(()=>oe("default")),o=fe||w.length===0,b=!o&&w.length>0?w.find(t=>t.id===O)??(O?null:w[0]):null,g=b?.id??null,r=o||!b||O?G:q(b),Y=Ae(r.profile,r.host),A=Le(o?void 0:g||void 0),d=B.find(t=>t.id===r.host),M=D.find(t=>t.name===r.profile),_=s.error||a.error||Y.error||A.error,je=`${w.length} saved`,X=n.isPending||l.isPending,ve=h.isPending&&h.variables?.target==="shared"||C.isPending&&C.variables?.target==="shared",be=h.isPending&&h.variables?.target==="ide"||C.isPending&&C.variables?.target==="ide",Z=r.name.trim().length>0&&r.profile.trim().length>0,i=Y.data,m=A.data,ee=Math.max((i?.env.length??0)-6,0),Ne=i?.env.slice(0,6)??[];function z(){I(!0),T(null),k(oe(pe))}async function ye(){if(!Z)return;const t=Ve(r);if(!o&&g){const Q=await l.mutateAsync({id:g,binding:t});I(!1),T(Q.binding.id),k(q(Q.binding));return}const N=await n.mutateAsync(t);I(!1),T(N.binding.id),k(q(N.binding))}async function Se(){if(!g||!b||!window.confirm(`Delete binding "${b.name}"?`))return;await S.mutateAsync(g);const t=w.filter(N=>N.id!==g);t.length>0?(T(t[0].id),I(!1),k(q(t[0]))):z()}function $(t,N){if(!o&&b&&!O){T(b.id),k({...q(b),[t]:N}),I(!1);return}k(Q=>({...Q,[t]:N}))}function R(t,N){if(g){if(N==="apply"){h.mutate({id:g,target:t});return}C.mutate({id:g,target:t})}}return e.jsxs("div",{className:"flex h-[calc(100vh-100px)] min-h-0",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(Pe,{className:"h-5 w-5 text-primary"})}),e.jsxs("div",{children:[e.jsx("h1",{className:"font-semibold",children:"Claude Extension"}),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:je}),d?e.jsx(p,{variant:"outline",children:d.label}):null]})]}),e.jsxs(y,{size:"sm",onClick:z,className:"gap-1.5",children:[e.jsx(ke,{className:"h-3.5 w-3.5"}),"New"]})]})}),e.jsx(se,{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:o?"Create binding":"Binding editor"}),e.jsx(v,{children:"Save a profile + IDE path once, then apply or reset it from the dashboard."})]}),e.jsxs(x,{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(H,{value:r.name,onChange:t=>$("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(te,{value:r.profile,onValueChange:t=>$("profile",t),children:[e.jsx(ae,{children:e.jsx(ne,{placeholder:"Select a profile"})}),e.jsx(ie,{children:D.map(t=>e.jsxs(re,{value:t.name,children:[t.label," (",t.profileType,")"]},t.name))})]}),e.jsx("p",{className:"text-xs text-muted-foreground",children:M?.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:"IDE host"}),e.jsxs(te,{value:r.host,onValueChange:t=>$("host",t),children:[e.jsx(ae,{children:e.jsx(ne,{placeholder:"Select a host"})}),e.jsx(ie,{children:B.map(t=>e.jsx(re,{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:"IDE settings path"}),e.jsx(H,{value:r.ideSettingsPath,onChange:t=>$("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(H,{value:r.notes,onChange:t=>$("notes",t.target.value),placeholder:"Optional reminder for this machine or workspace"})]}),e.jsxs("div",{className:"flex gap-2",children:[e.jsxs(y,{className:"flex-1 gap-1.5",onClick:()=>void ye(),disabled:!Z||X,children:[X?e.jsx(U,{className:"h-3.5 w-3.5 animate-spin"}):e.jsx(De,{className:"h-3.5 w-3.5"}),o?"Create":"Save"]}),e.jsx(y,{variant:"outline",onClick:z,children:"Reset form"})]}),o?null:e.jsxs(y,{variant:"outline",className:"w-full gap-1.5 text-destructive hover:text-destructive",onClick:()=>void Se(),disabled:S.isPending,children:[e.jsx(Be,{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(ze,{binding:t,isSelected:t.id===g&&!o,onSelect:()=>{I(!1),T(t.id),k(q(t))}},t.id)):e.jsx(u,{className:"border-dashed border-border/60 bg-card/60",children:e.jsx(x,{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(se,{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:[M?e.jsx(p,{variant:"outline",children:M.label}):null,d?e.jsx(p,{variant:"outline",children:d.label}):null,o?e.jsx(p,{variant:"secondary",children:"Draft"}):null,m?.sharedSettings&&me(m.sharedSettings)&&me(m.ideSettings)?e.jsx(p,{className:"bg-emerald-600 hover:bg-emerald-600",children:"In sync"}):null]}),e.jsxs("div",{className:"max-w-5xl",children:[e.jsx("h2",{className:"text-2xl font-semibold tracking-tight",children:b?.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(y,{variant:"outline",onClick:()=>void A.refetch(),disabled:o||A.isFetching,children:[A.isFetching?e.jsx(U,{className:"mr-1.5 h-3.5 w-3.5 animate-spin"}):e.jsx(Ie,{className:"mr-1.5 h-3.5 w-3.5"}),"Verify"]}),i?e.jsx(F,{value:i.sharedSettings.command,label:"Copy persist command"}):null]})]}),_?e.jsx(u,{className:"border-destructive/40 bg-destructive/5",children:e.jsxs(x,{className:"flex items-start gap-3 pt-6 text-sm text-destructive",children:[e.jsx(ce,{className:"mt-0.5 h-4 w-4 shrink-0"}),e.jsx("div",{children:_.message})]})}):null,_?null:e.jsxs(we,{defaultValue:"overview",className:"flex flex-col gap-6",children:[e.jsxs(Ee,{className:"w-full justify-start",children:[e.jsx(le,{value:"overview",children:"Overview"}),e.jsx(le,{value:"advanced",children:"Advanced"})]}),e.jsxs(de,{value:"overview",className:"mt-0 space-y-6",children:[e.jsxs("div",{className:"grid gap-6 xl:grid-cols-2",children:[e.jsx(xe,{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:()=>R("shared","apply"),onReset:()=>R("shared","reset"),disabled:o,busy:ve}),e.jsx(xe,{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:()=>R("ide","apply"),onReset:()=>R("ide","reset"),disabled:o,busy:be})]}),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:"Resolved binding"}),e.jsx(v,{children:"The binding uses the same profile resolution as `ccs persist` and `ccs env`."})]}),e.jsxs(x,{className:"space-y-3",children:[e.jsx(c,{label:"Profile",value:i?.profile.label||r.profile||"Not selected"}),e.jsx(c,{label:"Profile type",value:i?.profile.profileType||"Unknown"}),e.jsx(c,{label:"IDE host",value:d?.label||"Not selected"}),e.jsx(c,{label:"IDE path mode",value:r.ideSettingsPath.trim()?"Custom path":"Default user path"}),e.jsx(c,{label:"Effective IDE path",value:m?.ideSettings.path||r.ideSettingsPath.trim()||d?.defaultSettingsPath||"Unavailable",mono:!0,copyValue:m?.ideSettings.path||r.ideSettingsPath.trim()||d?.defaultSettingsPath}),e.jsx(c,{label:"Persist command",value:i?.sharedSettings.command||"Save a valid binding first",mono:!0}),r.notes.trim()?e.jsx(c,{label:"Notes",value:r.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:"Managed payload"}),e.jsx(v,{children:"Keep the main view short. The full JSON stays in the Advanced tab."})]}),e.jsxs(x,{className:"space-y-4",children:[e.jsxs("div",{className:"flex flex-wrap gap-2",children:[Ne.map(t=>e.jsx(p,{variant:"secondary",className:"font-mono text-[10px]",children:t.name},t.name)),ee>0?e.jsxs(p,{variant:"outline",children:["+",ee," 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."})}),o?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(y,{className:"flex-1",onClick:()=>R("all","apply"),disabled:h.isPending,children:[h.isPending&&h.variables?.target==="all"?e.jsx(U,{className:"mr-1.5 h-3.5 w-3.5 animate-spin"}):null,"Apply both targets"]}),e.jsx(y,{variant:"outline",className:"flex-1",onClick:()=>R("all","reset"),disabled:C.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:"Warnings"}),e.jsx(v,{children:"Operational details that can break the binding even when JSON is correct."})]}),e.jsx(x,{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(ce,{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:"Notes"}),e.jsx(v,{children:"Short context from CCS about account continuity and host-specific behavior."})]}),e.jsx(x,{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(Te,{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(de,{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(ue,{title:"Shared Claude settings JSON",description:"Managed env block for ~/.claude/settings.json.",value:i.sharedSettings.json}),e.jsx(ue,{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(v,{children:"Exact environment values that the extension receives after CCS expands this profile."})]}),e.jsx(F,{value:JSON.stringify(i.env,null,2),label:"Copy environment payload"})]})}),e.jsx(x,{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(v,{children:"Useful when debugging drift or comparing with manual edits."})]}),e.jsxs(x,{className:"space-y-3",children:[e.jsx(c,{label:"Target path",value:m?.sharedSettings.path||i.sharedSettings.path,mono:!0,copyValue:m?.sharedSettings.path||i.sharedSettings.path}),e.jsx(c,{label:"Command",value:i.sharedSettings.command,mono:!0}),e.jsx(c,{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(v,{children:"Current file path plus the extension setting key used for this host."})]}),e.jsxs(x,{className:"space-y-3",children:[e.jsx(c,{label:"Target path",value:m?.ideSettings.path||r.ideSettingsPath.trim()||d?.defaultSettingsPath||i.ideSettings.path,mono:!0,copyValue:m?.ideSettings.path||r.ideSettingsPath.trim()||d?.defaultSettingsPath||i.ideSettings.path}),e.jsx(c,{label:"Settings key",value:d?.settingsKey||"Unknown",mono:!0}),e.jsx(c,{label:"Current state",value:m?.ideSettings.state||"Not verified"})]})]})]})]}):e.jsx(u,{className:"border-border/60 bg-card/80",children:e.jsxs(x,{className:"flex min-h-[240px] items-center justify-center gap-3 text-sm text-muted-foreground",children:[e.jsx(Re,{className:"h-5 w-5"}),"Choose a profile and IDE host to preview the generated payload."]})})})]})]})})})]})}export{as as ClaudeExtensionPage};
1
+ import{j as e}from"./radix-ui-BR1vy4kf.js";import{r as W}from"./react-vendor-CNOkPC89.js";import{b2 as Ce,B as p,d as y,n as se,C as u,j as f,k as j,_ as v,b as x,I as H,r as te,s as ae,t as ne,v as ie,w as re,x as F,Q as we,R as Ee,U as le,V as de,c as he}from"./index-JgHDFSHt.js";import{u as K,a as J,b as V}from"./tanstack-e99Cjjy2.js";import{t as E}from"./notifications-B2HqRBj7.js";import{a4 as Pe,a3 as ke,L as U,aj as De,ai as Be,R as Ie,T as ce,aC as Te,a2 as Re}from"./icons-DrEfTmfX.js";import"./utils-CzKF5WmX.js";import"./form-utils-Bcoyqxpq.js";import"./code-highlight-BRUf_pqB.js";const L=["claude-extension-bindings"];async function P(s,a){const n=await fetch(Ce(s),{headers:{"Content-Type":"application/json"},...a});if(!n.ok){const l=await n.json().catch(()=>null);throw new Error(l?.error||`Request failed (${n.status})`)}return n.status===204?void 0:await n.json()}function qe(){return K({queryKey:["claude-extension-options"],queryFn:()=>P("/claude-extension/profiles")})}function Ae(s,a="vscode"){return K({queryKey:["claude-extension-setup",s,a],enabled:!!s,queryFn:()=>P(`/claude-extension/setup?profile=${encodeURIComponent(s||"")}&host=${encodeURIComponent(a)}`)})}function $e(){return K({queryKey:L,queryFn:()=>P("/claude-extension/bindings")})}function Le(s){return K({queryKey:["claude-extension-binding-status",s],enabled:!!s,queryFn:()=>P(`/claude-extension/bindings/${encodeURIComponent(s||"")}/verify`)})}function Oe(){const s=J();return V({mutationFn:a=>P("/claude-extension/bindings",{method:"POST",body:JSON.stringify(a)}),onSuccess:()=>{s.invalidateQueries({queryKey:L}),E.success("Binding created")},onError:a=>E.error(a.message)})}function Qe(){const s=J();return V({mutationFn:({id:a,binding:n})=>P(`/claude-extension/bindings/${encodeURIComponent(a)}`,{method:"PUT",body:JSON.stringify(n)}),onSuccess:(a,n)=>{s.invalidateQueries({queryKey:L}),s.invalidateQueries({queryKey:["claude-extension-binding-status",n.id]}),E.success("Binding saved")},onError:a=>E.error(a.message)})}function Ue(){const s=J();return V({mutationFn:a=>P(`/claude-extension/bindings/${encodeURIComponent(a)}`,{method:"DELETE"}),onSuccess:()=>{s.invalidateQueries({queryKey:L}),E.success("Binding deleted")},onError:a=>E.error(a.message)})}function ge(s,a){const n=J();return V({mutationFn:({id:l,target:S})=>P(`/claude-extension/bindings/${encodeURIComponent(l)}/${s}`,{method:"POST",body:JSON.stringify({target:S})}),onSuccess:l=>{n.invalidateQueries({queryKey:L}),n.setQueryData(["claude-extension-binding-status",l.bindingId],l),E.success(a)},onError:l=>E.error(l.message)})}function Fe(){return ge("apply","Binding applied")}function Ke(){return ge("reset","Managed values removed")}const Je=[];function oe(s){return{name:"",profile:s,host:"vscode",ideSettingsPath:"",notes:""}}function q(s){return{name:s.name,profile:s.profile,host:s.host,ideSettingsPath:s.ideSettingsPath||"",notes:s.notes||""}}function Ve(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 me(s){return s?.state==="applied"}function Me({state:s}){const a=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:a,children:s})}function _e(s){return s.replace(/[\\/]/g,"$&​")}function c({label:s,value:a,mono:n=!1,copyValue:l}){const S=typeof l=="string"&&l.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}),S?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:_e(a)})}),e.jsx(F,{value:l,label:`Copy ${s.toLowerCase()}`,className:"shrink-0"})]}):e.jsx("span",{className:he("text-left sm:text-right",n&&"font-mono text-xs leading-5 [overflow-wrap:anywhere]"),children:a})]})}function ue({title:s,description:a,value:n}){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(v,{className:"mt-1",children:a})]}),e.jsx(F,{value:n,label:`Copy ${s}`})]})}),e.jsx(x,{children:e.jsx("pre",{className:"max-h-[360px] overflow-auto rounded-lg border bg-muted/30 p-4 text-xs leading-6",children:n})})]})}function xe({title:s,description:a,status:n,applyLabel:l,resetLabel:S,onApply:h,onReset:C,disabled:D,busy:B}){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(v,{className:"mt-1",children:a})]}),n?e.jsx(Me,{state:n.state}):null]})}),e.jsxs(x,{className:"space-y-4",children:[e.jsxs("div",{className:"space-y-2",children:[e.jsx(c,{label:"Path",value:n?.path||"Save a binding first",mono:!0,copyValue:n?.path}),e.jsx(c,{label:"File",value:n?n.exists?"Present":"Not created yet":"Unavailable"})]}),e.jsx("div",{className:"rounded-lg border bg-muted/25 p-3 text-sm text-muted-foreground",children:n?.message||"Verify the binding after saving to inspect the current file state."}),e.jsxs("div",{className:"flex gap-2",children:[e.jsxs(y,{size:"sm",className:"flex-1",onClick:h,disabled:D||B,children:[B?e.jsx(U,{className:"mr-1.5 h-3.5 w-3.5 animate-spin"}):null,l]}),e.jsx(y,{size:"sm",variant:"outline",className:"flex-1",onClick:C,disabled:D||B,children:S})]})]})]})}function ze({binding:s,isSelected:a,onSelect:n}){return e.jsx("button",{onClick:n,className:he("w-full rounded-lg border px-3 py-3 text-left transition-colors",a?"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 as(){const s=qe(),a=$e(),n=Oe(),l=Qe(),S=Ue(),h=Fe(),C=Ke(),D=s.data?.profiles??[],B=s.data?.hosts??[],w=a.data?.bindings??Je,pe=D[0]?.name??"default",[fe,I]=W.useState(!1),[O,T]=W.useState(null),[G,k]=W.useState(()=>oe("default")),o=fe||w.length===0,b=!o&&w.length>0?w.find(t=>t.id===O)??(O?null:w[0]):null,g=b?.id??null,r=o||!b||O?G:q(b),Y=Ae(r.profile,r.host),A=Le(o?void 0:g||void 0),d=B.find(t=>t.id===r.host),M=D.find(t=>t.name===r.profile),_=s.error||a.error||Y.error||A.error,je=`${w.length} saved`,X=n.isPending||l.isPending,ve=h.isPending&&h.variables?.target==="shared"||C.isPending&&C.variables?.target==="shared",be=h.isPending&&h.variables?.target==="ide"||C.isPending&&C.variables?.target==="ide",Z=r.name.trim().length>0&&r.profile.trim().length>0,i=Y.data,m=A.data,ee=Math.max((i?.env.length??0)-6,0),Ne=i?.env.slice(0,6)??[];function z(){I(!0),T(null),k(oe(pe))}async function ye(){if(!Z)return;const t=Ve(r);if(!o&&g){const Q=await l.mutateAsync({id:g,binding:t});I(!1),T(Q.binding.id),k(q(Q.binding));return}const N=await n.mutateAsync(t);I(!1),T(N.binding.id),k(q(N.binding))}async function Se(){if(!g||!b||!window.confirm(`Delete binding "${b.name}"?`))return;await S.mutateAsync(g);const t=w.filter(N=>N.id!==g);t.length>0?(T(t[0].id),I(!1),k(q(t[0]))):z()}function $(t,N){if(!o&&b&&!O){T(b.id),k({...q(b),[t]:N}),I(!1);return}k(Q=>({...Q,[t]:N}))}function R(t,N){if(g){if(N==="apply"){h.mutate({id:g,target:t});return}C.mutate({id:g,target:t})}}return e.jsxs("div",{className:"flex h-[calc(100vh-100px)] min-h-0",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(Pe,{className:"h-5 w-5 text-primary"})}),e.jsxs("div",{children:[e.jsx("h1",{className:"font-semibold",children:"Claude Extension"}),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:je}),d?e.jsx(p,{variant:"outline",children:d.label}):null]})]}),e.jsxs(y,{size:"sm",onClick:z,className:"gap-1.5",children:[e.jsx(ke,{className:"h-3.5 w-3.5"}),"New"]})]})}),e.jsx(se,{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:o?"Create binding":"Binding editor"}),e.jsx(v,{children:"Save a profile + IDE path once, then apply or reset it from the dashboard."})]}),e.jsxs(x,{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(H,{value:r.name,onChange:t=>$("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(te,{value:r.profile,onValueChange:t=>$("profile",t),children:[e.jsx(ae,{children:e.jsx(ne,{placeholder:"Select a profile"})}),e.jsx(ie,{children:D.map(t=>e.jsxs(re,{value:t.name,children:[t.label," (",t.profileType,")"]},t.name))})]}),e.jsx("p",{className:"text-xs text-muted-foreground",children:M?.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:"IDE host"}),e.jsxs(te,{value:r.host,onValueChange:t=>$("host",t),children:[e.jsx(ae,{children:e.jsx(ne,{placeholder:"Select a host"})}),e.jsx(ie,{children:B.map(t=>e.jsx(re,{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:"IDE settings path"}),e.jsx(H,{value:r.ideSettingsPath,onChange:t=>$("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(H,{value:r.notes,onChange:t=>$("notes",t.target.value),placeholder:"Optional reminder for this machine or workspace"})]}),e.jsxs("div",{className:"flex gap-2",children:[e.jsxs(y,{className:"flex-1 gap-1.5",onClick:()=>void ye(),disabled:!Z||X,children:[X?e.jsx(U,{className:"h-3.5 w-3.5 animate-spin"}):e.jsx(De,{className:"h-3.5 w-3.5"}),o?"Create":"Save"]}),e.jsx(y,{variant:"outline",onClick:z,children:"Reset form"})]}),o?null:e.jsxs(y,{variant:"outline",className:"w-full gap-1.5 text-destructive hover:text-destructive",onClick:()=>void Se(),disabled:S.isPending,children:[e.jsx(Be,{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(ze,{binding:t,isSelected:t.id===g&&!o,onSelect:()=>{I(!1),T(t.id),k(q(t))}},t.id)):e.jsx(u,{className:"border-dashed border-border/60 bg-card/60",children:e.jsx(x,{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(se,{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:[M?e.jsx(p,{variant:"outline",children:M.label}):null,d?e.jsx(p,{variant:"outline",children:d.label}):null,o?e.jsx(p,{variant:"secondary",children:"Draft"}):null,m?.sharedSettings&&me(m.sharedSettings)&&me(m.ideSettings)?e.jsx(p,{className:"bg-emerald-600 hover:bg-emerald-600",children:"In sync"}):null]}),e.jsxs("div",{className:"max-w-5xl",children:[e.jsx("h2",{className:"text-2xl font-semibold tracking-tight",children:b?.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(y,{variant:"outline",onClick:()=>void A.refetch(),disabled:o||A.isFetching,children:[A.isFetching?e.jsx(U,{className:"mr-1.5 h-3.5 w-3.5 animate-spin"}):e.jsx(Ie,{className:"mr-1.5 h-3.5 w-3.5"}),"Verify"]}),i?e.jsx(F,{value:i.sharedSettings.command,label:"Copy persist command"}):null]})]}),_?e.jsx(u,{className:"border-destructive/40 bg-destructive/5",children:e.jsxs(x,{className:"flex items-start gap-3 pt-6 text-sm text-destructive",children:[e.jsx(ce,{className:"mt-0.5 h-4 w-4 shrink-0"}),e.jsx("div",{children:_.message})]})}):null,_?null:e.jsxs(we,{defaultValue:"overview",className:"flex flex-col gap-6",children:[e.jsxs(Ee,{className:"w-full justify-start",children:[e.jsx(le,{value:"overview",children:"Overview"}),e.jsx(le,{value:"advanced",children:"Advanced"})]}),e.jsxs(de,{value:"overview",className:"mt-0 space-y-6",children:[e.jsxs("div",{className:"grid gap-6 xl:grid-cols-2",children:[e.jsx(xe,{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:()=>R("shared","apply"),onReset:()=>R("shared","reset"),disabled:o,busy:ve}),e.jsx(xe,{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:()=>R("ide","apply"),onReset:()=>R("ide","reset"),disabled:o,busy:be})]}),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:"Resolved binding"}),e.jsx(v,{children:"The binding uses the same profile resolution as `ccs persist` and `ccs env`."})]}),e.jsxs(x,{className:"space-y-3",children:[e.jsx(c,{label:"Profile",value:i?.profile.label||r.profile||"Not selected"}),e.jsx(c,{label:"Profile type",value:i?.profile.profileType||"Unknown"}),e.jsx(c,{label:"IDE host",value:d?.label||"Not selected"}),e.jsx(c,{label:"IDE path mode",value:r.ideSettingsPath.trim()?"Custom path":"Default user path"}),e.jsx(c,{label:"Effective IDE path",value:m?.ideSettings.path||r.ideSettingsPath.trim()||d?.defaultSettingsPath||"Unavailable",mono:!0,copyValue:m?.ideSettings.path||r.ideSettingsPath.trim()||d?.defaultSettingsPath}),e.jsx(c,{label:"Persist command",value:i?.sharedSettings.command||"Save a valid binding first",mono:!0}),r.notes.trim()?e.jsx(c,{label:"Notes",value:r.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:"Managed payload"}),e.jsx(v,{children:"Keep the main view short. The full JSON stays in the Advanced tab."})]}),e.jsxs(x,{className:"space-y-4",children:[e.jsxs("div",{className:"flex flex-wrap gap-2",children:[Ne.map(t=>e.jsx(p,{variant:"secondary",className:"font-mono text-[10px]",children:t.name},t.name)),ee>0?e.jsxs(p,{variant:"outline",children:["+",ee," 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."})}),o?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(y,{className:"flex-1",onClick:()=>R("all","apply"),disabled:h.isPending,children:[h.isPending&&h.variables?.target==="all"?e.jsx(U,{className:"mr-1.5 h-3.5 w-3.5 animate-spin"}):null,"Apply both targets"]}),e.jsx(y,{variant:"outline",className:"flex-1",onClick:()=>R("all","reset"),disabled:C.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:"Warnings"}),e.jsx(v,{children:"Operational details that can break the binding even when JSON is correct."})]}),e.jsx(x,{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(ce,{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:"Notes"}),e.jsx(v,{children:"Short context from CCS about account continuity and host-specific behavior."})]}),e.jsx(x,{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(Te,{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(de,{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(ue,{title:"Shared Claude settings JSON",description:"Managed env block for ~/.claude/settings.json.",value:i.sharedSettings.json}),e.jsx(ue,{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(v,{children:"Exact environment values that the extension receives after CCS expands this profile."})]}),e.jsx(F,{value:JSON.stringify(i.env,null,2),label:"Copy environment payload"})]})}),e.jsx(x,{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(v,{children:"Useful when debugging drift or comparing with manual edits."})]}),e.jsxs(x,{className:"space-y-3",children:[e.jsx(c,{label:"Target path",value:m?.sharedSettings.path||i.sharedSettings.path,mono:!0,copyValue:m?.sharedSettings.path||i.sharedSettings.path}),e.jsx(c,{label:"Command",value:i.sharedSettings.command,mono:!0}),e.jsx(c,{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(v,{children:"Current file path plus the extension setting key used for this host."})]}),e.jsxs(x,{className:"space-y-3",children:[e.jsx(c,{label:"Target path",value:m?.ideSettings.path||r.ideSettingsPath.trim()||d?.defaultSettingsPath||i.ideSettings.path,mono:!0,copyValue:m?.ideSettings.path||r.ideSettingsPath.trim()||d?.defaultSettingsPath||i.ideSettings.path}),e.jsx(c,{label:"Settings key",value:d?.settingsKey||"Unknown",mono:!0}),e.jsx(c,{label:"Current state",value:m?.ideSettings.state||"Not verified"})]})]})]})]}):e.jsx(u,{className:"border-border/60 bg-card/80",children:e.jsxs(x,{className:"flex min-h-[240px] items-center justify-center gap-3 text-sm text-muted-foreground",children:[e.jsx(Re,{className:"h-5 w-5"}),"Choose a profile and IDE host to preview the generated payload."]})})})]})]})})})]})}export{as as ClaudeExtensionPage};