@openchamber/web 1.18.2 → 1.18.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 (136) hide show
  1. package/bin/lib/commands-models.js +1 -1
  2. package/dist/assets/{CodeMirrorCommentWidgets-CxcJ5x9h.js → CodeMirrorCommentWidgets-DbUi6I9s.js} +1 -1
  3. package/dist/assets/{CommitSection-C9sBBYAJ.js → CommitSection-Jc2_hNPE.js} +1 -1
  4. package/dist/assets/{DiagramEditor-C7nUw7p3.js → DiagramEditor-PCrYHBko.js} +1 -1
  5. package/dist/assets/{DiagramView-cYxZP-HS.js → DiagramView-CndEcZNu.js} +1 -1
  6. package/dist/assets/{DiffView-1zd0slLu.js → DiffView-DEGlNjMH.js} +2 -2
  7. package/dist/assets/FilesView-CzUgIvUm.js +14 -0
  8. package/dist/assets/{GitView-OSVIn5V1.js → GitView-C-n17voy.js} +1 -1
  9. package/dist/assets/{JsonTreeView-Kgepz4pR.js → JsonTreeView-BYcgdTOQ.js} +1 -1
  10. package/dist/assets/MarkdownImageGallery-DzHwkVIH.js +1 -0
  11. package/dist/assets/MarkdownRendererImpl-DUcIcWgs.js +12 -0
  12. package/dist/assets/OnboardingScreen-BmN0lhk4.js +1 -0
  13. package/dist/assets/{PatchDiff-Cddz02Ya.js → PatchDiff-Bn7bfgUv.js} +1 -1
  14. package/dist/assets/{PierreDiffViewer-B5k0KvPW.js → PierreDiffViewer-D1fWvrUn.js} +2 -2
  15. package/dist/assets/{PlanView-BYgHBHDt.js → PlanView-CWM0iyFk.js} +3 -3
  16. package/dist/assets/{SessionSwitcherDropdown-ig2OT22Z.js → SessionSwitcherDropdown-Cez-9xRh.js} +1 -1
  17. package/dist/assets/SettingsView-Bl1drwPw.js +28 -0
  18. package/dist/assets/{SettingsWindow-CNHM8ifT.js → SettingsWindow-DL5axjDZ.js} +1 -1
  19. package/dist/assets/{ToolOutputDialog-DrGeYq2p.js → ToolOutputDialog-BtIJkFno.js} +7 -7
  20. package/dist/assets/{ToolPartDiffPreview-BRmPpe94.js → ToolPartDiffPreview-i3PQo6_0.js} +1 -1
  21. package/dist/assets/{VirtualizedFileDiff-Dcu8Q-5P.js → VirtualizedFileDiff-DkcusvMa.js} +1 -1
  22. package/dist/assets/{WalkthroughView-HStEYdD2.js → WalkthroughView-Cc5Hd6P5.js} +2 -2
  23. package/dist/assets/{computeVirtualFileMetrics-DQE7R9IY.js → computeVirtualFileMetrics-xPena3W2.js} +2 -2
  24. package/dist/assets/contextPanelEmbeddedChat-tQekJUAF.js +1 -0
  25. package/dist/assets/de-u7gSnqWs.js +9 -0
  26. package/dist/assets/es-T9O7aAOr.js +15 -0
  27. package/dist/assets/fr-Oor7ewbE.js +13 -0
  28. package/dist/assets/index-CVNuER6G.css +1 -0
  29. package/dist/assets/{index-BgQEgA2a.js → index-Crz1YOFl.js} +1 -1
  30. package/dist/assets/index-iFY_N5aO.js +7 -0
  31. package/dist/assets/{isDiffPlainText-XyBCe4eD.js → isDiffPlainText-Dudf-dWx.js} +1 -1
  32. package/dist/assets/{isFilePlainText-JbqDfa3n.js → isFilePlainText-DS4QV1dd.js} +1 -1
  33. package/dist/assets/ja-DHpqbVmr.js +15 -0
  34. package/dist/assets/ko-CwLkS3nx.js +15 -0
  35. package/dist/assets/{main-LfcbGv7C.js → main-C0DyIwTb.js} +2 -2
  36. package/dist/assets/main-CAxX6DAN.js +915 -0
  37. package/dist/assets/markdownCore-DhfzuGXu.js +2 -0
  38. package/dist/assets/markdownImageAssets-BTNlRyjd.js +1 -0
  39. package/dist/assets/{miniChat-CUp_elRz.js → miniChat-CGfrxKpJ.js} +2 -2
  40. package/dist/assets/{mobile-CBSN7BsH.js → mobile-DEmhwNcV.js} +2 -2
  41. package/dist/assets/{patchFileDiff-DCIXUHRJ.js → patchFileDiff-C5D1OPCa.js} +2 -2
  42. package/dist/assets/{pl-tHTP6XQx.js → pl-CcZILN8q.js} +4 -4
  43. package/dist/assets/pt-BR-DYHhVK6o.js +15 -0
  44. package/dist/assets/{renderElectronMiniChatApp-eZl-5STF.js → renderElectronMiniChatApp-Dpbswpom.js} +2 -2
  45. package/dist/assets/renderMobileApp-B5HA4qbi.js +25 -0
  46. package/dist/assets/runtimeEndpointReset-cbahJ3hD.js +13 -0
  47. package/dist/assets/scheduledTasksApi-BxgGWTL8.js +1 -0
  48. package/dist/assets/{shikiHighlight-eU8abJ3T.js → shikiHighlight-CmanopUB.js} +1 -1
  49. package/dist/assets/uk-BA2kZR38.js +15 -0
  50. package/dist/assets/{useAppFontEffects-Bbpz77To.js → useAppFontEffects-sHmU5b8u.js} +137 -137
  51. package/dist/assets/useInlineCommentController-gt56WkxJ.js +2 -0
  52. package/dist/assets/{vendor-codemirror-language-data-Dzt9rWZZ.js → vendor-codemirror-language-data-Dihw9MtL.js} +2 -2
  53. package/dist/assets/{vendor-marked-i_gIkIP3.js → vendor-marked-CX41MkDF.js} +1 -1
  54. package/dist/assets/{web-components-DGvnI0zx.js → web-components-BL-Ur2Tb.js} +1 -1
  55. package/dist/assets/zh-CN-dlOQK6v9.js +15 -0
  56. package/dist/assets/zh-TW-BnqQ-WL5.js +15 -0
  57. package/dist/index.html +4 -4
  58. package/dist/mini-chat.html +3 -3
  59. package/dist/mobile.html +3 -3
  60. package/package.json +2 -2
  61. package/server/index.js +65 -19
  62. package/server/lib/agent-tool/DOCUMENTATION.md +21 -6
  63. package/server/lib/agent-tool/runtime.js +90 -16
  64. package/server/lib/agent-tool/runtime.test.js +86 -0
  65. package/server/lib/browser-control/DOCUMENTATION.md +50 -0
  66. package/server/lib/browser-control/broker.js +154 -0
  67. package/server/lib/browser-control/broker.test.js +191 -0
  68. package/server/lib/browser-control/routes.js +48 -0
  69. package/server/lib/browser-control/routes.test.js +108 -0
  70. package/server/lib/dev-servers/parse.js +203 -0
  71. package/server/lib/dev-servers/parse.test.js +174 -0
  72. package/server/lib/dev-servers/routes.js +135 -0
  73. package/server/lib/dev-tunnel/DOCUMENTATION.md +57 -0
  74. package/server/lib/dev-tunnel/client.js +174 -0
  75. package/server/lib/dev-tunnel/runtime.js +189 -0
  76. package/server/lib/dev-tunnel/tunnel.test.js +282 -0
  77. package/server/lib/git/credentials.js +0 -33
  78. package/server/lib/github/DOCUMENTATION.md +1 -1
  79. package/server/lib/openchamber-control/DOCUMENTATION.md +9 -0
  80. package/server/lib/openchamber-control/actions.js +33 -1
  81. package/server/lib/openchamber-control/screenshots.js +83 -0
  82. package/server/lib/openchamber-control/screenshots.test.js +84 -0
  83. package/server/lib/openchamber-control/service.js +141 -2
  84. package/server/lib/openchamber-control/service.test.js +55 -0
  85. package/server/lib/opencode/core-routes.js +31 -52
  86. package/server/lib/opencode/core-routes.test.js +37 -9
  87. package/server/lib/opencode/feature-routes-runtime.js +4 -0
  88. package/server/lib/opencode/settings-helpers.js +3 -9
  89. package/server/lib/projects/project-config.js +181 -2
  90. package/server/lib/projects/project-config.test.js +295 -0
  91. package/server/lib/quota/DOCUMENTATION.md +4 -2
  92. package/server/lib/quota/credentials/providers.js +0 -7
  93. package/server/lib/quota/credentials/store.js +11 -1
  94. package/server/lib/quota/credentials/store.test.js +9 -1
  95. package/server/lib/quota/providers/opencode-go.js +35 -35
  96. package/server/lib/quota/providers/opencode-go.test.js +52 -7
  97. package/server/lib/quota/routes.js +0 -2
  98. package/server/lib/relay/DOCUMENTATION.md +2 -0
  99. package/server/lib/relay/tunnel-host.js +157 -33
  100. package/server/lib/relay/tunnel-host.test.js +147 -0
  101. package/server/lib/scheduled-tasks/DOCUMENTATION.md +49 -0
  102. package/server/lib/scheduled-tasks/issue-2710-double-execution.test.js +488 -0
  103. package/server/lib/scheduled-tasks/routes.js +6 -0
  104. package/server/lib/scheduled-tasks/runtime.js +369 -108
  105. package/server/lib/scheduled-tasks/service.js +7 -1
  106. package/server/lib/scheduled-tasks/service.test.js +20 -0
  107. package/server/lib/walkthrough/index.js +0 -2
  108. package/server/sse-routes.test.js +3 -0
  109. package/dist/assets/FilesView-WkxsWHBE.js +0 -14
  110. package/dist/assets/MarkdownRendererImpl-CKAsRfIk.js +0 -12
  111. package/dist/assets/OnboardingScreen-BCgYA7J5.js +0 -1
  112. package/dist/assets/SettingsView-e7Fmxnz8.js +0 -28
  113. package/dist/assets/contextPanelEmbeddedChat-5VGWIT_J.js +0 -1
  114. package/dist/assets/de-B6t6T54h.js +0 -9
  115. package/dist/assets/es-DH9NUKge.js +0 -15
  116. package/dist/assets/fr-Do4t2KmA.js +0 -13
  117. package/dist/assets/index-B45s9aAX.css +0 -1
  118. package/dist/assets/index-CNrN5qDs.js +0 -7
  119. package/dist/assets/ja-DJT9EM80.js +0 -15
  120. package/dist/assets/ko-CfWRq2p4.js +0 -15
  121. package/dist/assets/main-B4oBRI9u.js +0 -193
  122. package/dist/assets/markdownCore-A3_L34oS.js +0 -2
  123. package/dist/assets/pt-BR-BDEzzltP.js +0 -15
  124. package/dist/assets/renderMobileApp-DA7wpIBi.js +0 -23
  125. package/dist/assets/runtimeEndpointReset-D5izT-u5.js +0 -13
  126. package/dist/assets/scheduledTasksApi-CTJdfSWc.js +0 -1
  127. package/dist/assets/uk-B6Q32nyk.js +0 -15
  128. package/dist/assets/useInlineCommentController-D7zs7-BQ.js +0 -2
  129. package/dist/assets/vendor-zumer-snapdom-Btyu_Xi2.js +0 -8
  130. package/dist/assets/zh-CN-7MGcwGaC.js +0 -15
  131. package/dist/assets/zh-TW-CFPfqxlL.js +0 -15
  132. package/server/lib/preview/proxy-runtime.js +0 -1604
  133. package/server/lib/preview/proxy-runtime.test.js +0 -528
  134. package/server/lib/quota/opencode-go-credentials.js +0 -11
  135. package/server/lib/quota/opencode-go-credentials.test.js +0 -32
  136. package/server/lib/quota/routes.test.js +0 -40
@@ -0,0 +1,28 @@
1
+ import{R as o,j as s,f as ht,r as We}from"./vendor-react-BUCujlKS.js";import{f as ot,B as H,I as _,o as En,aV as Jn,t as R,O as Cl,f8 as Il,ee as Oe,f9 as Et,b as Fs,h as je,fa as Pl,aR as $s,aT as Bs,fb as Al,aU as Hs,e5 as ja,fc as Tl,fd as Bn,fe as qs,bU as Ds,bs as Ut,bt as Vt,bu as Ht,bv as Gt,bw as qt,bx as os,S as He,ff as xa,aQ as Gs,dV as Oi,fg as El,fh as ir,fi as In,eg as Yt,fj as Ls,l as nt,fk as $t,bK as Dt,bL as Mt,eq as Kt,bM as _t,bN as Rt,bO as dt,fl as Qt,bP as Ns,dj as ua,fm as bn,er as Gn,fn as vn,fo as gs,dp as ys,fp as Dl,fq as ut,fr as Ao,fs as Ml,ft as qn,fu as qa,fv as Rl,fw as Qa,fx as rn,fy as Hn,dk as To,fz as Tn,ag as Ya,af as Is,fA as rr,eH as Ol,dT as Eo,g as ga,fB as Ll,fC as Vs,dS as Fl,fD as Kl,fE as _l,fF as Wi,aX as Ji,aY as Qi,aZ as Do,fG as an,fH as sn,L as Yi,fI as or,aa as zl,bQ as Ul,cq as Vl,Q as $l,N as Bl,R as Hl,V as Mo,fJ as Gl,fK as ql,bH as Wl,bR as Li,eG as lr,P as Pn,fL as xn,ed as As,a$ as Ro,n as ss,bg as Wa,x as Jl,i as Ql,j as Yl,bA as Zl,p as Xl,fM as ec,bj as tc,bB as cr,bC as Oo,bi as sc,fN as gi,fO as dr,fP as nc,fQ as ac,fR as ic,fS as rc,dv as Za,fT as bs,fU as Os,fV as gn,fW as hn,aj as ea,fX as fn,fY as Wn,fZ as pr,f_ as ta,f$ as sa,g0 as oc,g1 as lc,g2 as cc,g3 as dc,g4 as hi,g5 as mr,g6 as pc,g7 as mc,g8 as uc,g9 as gc,ga as hc,gb as fi,gc as ur,gd as fc,cb as xc,br as gr,ge as nn,gf as xi,bq as hr,gg as Lo,gh as fr,gi as Fo,gj as bc,d_ as vc,gk as yc,ac as dn,ae as jc,gl as wc}from"./useAppFontEffects-sHmU5b8u.js";import{r as ct,C as ds,cr as Nc,cs as xr,t as on,al as bi,l as Ko,U as kc,K as yt,n as jn,u as de,x as is,I as br,bY as vr,b$ as yr,J as na,p as Sc,ct as Cc,j as Ic,bX as $n,cu as Pc,a4 as Ac,b_ as Tc,cv as Ec,cw as Dc,s as Mc,e as wa,bZ as Rc,y as Na,cx as _o,R as Oc,cy as Lc,Q as Fc,aB as jr,at as Kc,Y as yn,cz as _c,q as zo,cA as wr,cq as Nr,cB as kr,ar as Sr,cC as zc,cD as Uc,cE as Cr,b as Vc,ap as Uo,cF as Vo,cG as $c,cH as Bc,cI as Hc,cJ as Gc,cK as qc,cL as Wc,af as Jc,i as $o}from"./index-iFY_N5aO.js";import{u as Qc,U as Ir,w as Dn,y as Mn,z as Rn,A as On,b as Zi,q as ba,s as va,v as ya,J as An,F as Yc,h as ws,p as Zc,H as Xc,K as pa,Q as Bo,B as ed,E as td}from"./runtimeEndpointReset-cbahJ3hD.js";import{u as Ps,c as Ho,d as sd,p as nd}from"./vendor-zustand-BAGL70zf.js";import{s as ad,p as id}from"./vendor-yaml-3778uTud.js";import{c as Pr,s as rd,C as Ar,P as od}from"./shikiHighlight-CmanopUB.js";import{getResolvedShikiTheme as ld}from"./appThemeRegistry-BK0dHKa6.js";import{E as Tr}from"./vendor-codemirror-view-DSzLbZiS.js";import{Q as Go}from"./vendor-qrcode-DTJ12-WC.js";import{f as cd,s as dd}from"./contextPanelEmbeddedChat-tQekJUAF.js";const Er=()=>{const{t}=ot(),[e,a]=o.useState(null);o.useEffect(()=>{let i=!1;const r=typeof AbortController<"u"?new AbortController:void 0;return(async()=>{try{const x=await ct("/api/system/info",{signal:r?.signal,headers:{Accept:"application/json"}});if(!x.ok)return;const c=await x.json().catch(()=>null);if(!c||i)return;const y=typeof c.port=="number"&&Number.isFinite(c.port)&&c.port>0?c.port:null,m=typeof c.tunnelUrl=="string"&&c.tunnelUrl.trim().length>0?c.tunnelUrl.trim():null;a({port:y,tunnelUrl:m})}catch{}})(),()=>{i=!0,r?.abort()}},[]);const n=[];return e?.port!==null&&e?.port!==void 0&&n.push({key:"application",label:t("settings.openchamber.about.field.applicationUrl"),url:`http://localhost:${e.port}/`}),e?.tunnelUrl&&n.push({key:"tunnel",label:t("settings.openchamber.about.field.tunnelUrl"),url:e.tunnelUrl}),n.length===0?null:s.jsx("div",{className:"flex flex-wrap items-center gap-2",children:n.map(i=>s.jsxs(H,{type:"button",variant:"outline",size:"sm",title:i.label,className:"max-w-full gap-1.5 px-2.5",onClick:()=>{En(i.url)},children:[s.jsx(_,{name:"external-link",className:"size-3.5 shrink-0"}),s.jsx("span",{className:"max-w-64 truncate font-mono typography-micro",children:i.url})]},i.key))})},Dr="https://github.com/openchamber/openchamber",pd="https://discord.gg/ZYRSdnwwKA",Mr="https://x.com/openchamber_dev",md=800,qo=({initialUpdateDialogOpen:t=!1})=>{const{t:e}=ot(),[a,n]=o.useState(t),[i,r]=o.useState(!1),[l,x]=o.useState(null),[c,y]=o.useState(null),m=Qc(Ps(N=>({info:N.info,checking:N.checking,available:N.available,error:N.error,downloading:N.downloading,downloaded:N.downloaded,progress:N.progress,runtimeType:N.runtimeType,checkForUpdates:N.checkForUpdates,downloadUpdate:N.downloadUpdate,restartToUpdate:N.restartToUpdate}))),{isMobile:b}=Jn(),p=l||m.info?.currentVersion||"unknown";o.useEffect(()=>{let N=!1;return(async()=>{try{const C=await ct("/api/system/info",{method:"GET",headers:{Accept:"application/json"}});if(!C.ok)return;const u=await C.json().catch(()=>null),E=typeof u?.openchamberVersion=="string"&&u.openchamberVersion.trim().length>0?u.openchamberVersion.trim():null;N||x(E)}catch{N||x(null)}})(),()=>{N=!0}},[]),o.useEffect(()=>{let N=!1;return(async()=>{try{const C=await ct("/api/opencode/upgrade-status",{method:"GET",headers:{Accept:"application/json"}});if(!C.ok)return;const u=await C.json().catch(()=>null),E=typeof u?.currentVersion=="string"&&u.currentVersion.trim().length>0?u.currentVersion.trim():null;N||y(E)}catch{N||y(null)}})(),()=>{N=!0}},[]);const L=o.useRef(!1);o.useEffect(()=>{if(m.checking)r(!0),L.current=!0;else if(i){const N=setTimeout(()=>{r(!1),L.current&&!m.available&&!m.error&&(R.success(e("settings.openchamber.about.toast.latestVersion")),L.current=!1)},md);return()=>clearTimeout(N)}},[e,m.checking,i,m.available,m.error]);const k=m.checking||i;return b?s.jsxs("div",{className:"w-full space-y-6 pb-2",children:[s.jsxs("div",{className:"flex flex-col items-center text-center",children:[s.jsx(Cl,{width:72,height:72}),s.jsx("h2",{className:`mt-4 ${Il}`,children:"OpenChamber"}),s.jsxs("div",{className:"mt-2 space-y-1 typography-ui text-muted-foreground",children:[s.jsx("p",{children:e("aboutDialog.openChamberVersionLabel",{version:p})}),s.jsx("p",{children:e("aboutDialog.openCodeVersionLabel",{version:c||e("settings.openchamber.about.state.unknown")})})]}),s.jsx(Er,{})]}),s.jsxs("div",{className:"flex justify-center",children:[!m.available&&!m.error&&s.jsxs(H,{type:"button",variant:"outline",size:"sm",onClick:()=>m.checkForUpdates(),disabled:k,className:"h-10 w-auto justify-center gap-2 rounded-xl px-4",children:[k?s.jsx(_,{name:"loader",className:"size-4 animate-spin"}):s.jsx(_,{name:"refresh",className:"size-4"}),e(k?"settings.openchamber.about.state.checking":"settings.openchamber.about.actions.checkForUpdates")]}),!k&&m.available&&s.jsxs(H,{type:"button",variant:"default",size:"sm",onClick:()=>n(!0),className:"h-10 w-auto justify-center gap-2 rounded-xl px-4",children:[s.jsx(_,{name:"download",className:"size-4"}),e("settings.openchamber.about.actions.updateToVersion",{version:m.info?.version||""})]})]}),m.error&&s.jsx("p",{className:"rounded-xl border border-[var(--status-error-border)] bg-[var(--status-error-background)] px-3 py-2 typography-meta text-[var(--status-error)]",children:m.error}),s.jsxs("div",{className:"flex flex-col items-center gap-3 text-center",children:[s.jsxs("div",{className:"flex items-center justify-center gap-5",children:[s.jsxs("a",{href:Dr,target:"_blank",rel:"noopener noreferrer",className:"flex items-center gap-1.5 typography-ui-label text-muted-foreground transition-colors hover:text-foreground",children:[s.jsx(_,{name:"github-fill",className:"size-5"}),s.jsx("span",{children:"GitHub"})]}),s.jsxs("a",{href:pd,target:"_blank",rel:"noopener noreferrer",className:"flex items-center gap-1.5 typography-ui-label text-muted-foreground transition-colors hover:text-foreground",children:[s.jsx(_,{name:"discord-fill",className:"size-5"}),s.jsx("span",{children:"Discord"})]})]}),s.jsxs("a",{href:Mr,target:"_blank",rel:"noopener noreferrer",className:"flex items-center gap-1.5 typography-ui-label text-muted-foreground transition-colors hover:text-foreground",children:[s.jsx(_,{name:"twitter-xfill",className:"size-5"}),s.jsx("span",{children:"@openchamber_dev"})]})]}),s.jsx("p",{className:"text-center typography-ui text-muted-foreground/60",children:e("aboutDialog.footerNote")}),s.jsx(Ir,{open:a,onOpenChange:n,info:m.info,downloading:m.downloading,downloaded:m.downloaded,progress:m.progress,error:m.error,onDownload:m.downloadUpdate,onRestart:m.restartToUpdate,runtimeType:m.runtimeType})]}):s.jsxs(Oe,{divider:!1,children:[s.jsxs("div",{className:"rounded-lg bg-[var(--surface-elevated)]/70 overflow-hidden flex flex-col",children:[s.jsxs("div",{className:"flex flex-col @xl:flex-row @xl:items-center justify-between gap-4 px-4 py-3 border-b border-border/40",children:[s.jsxs("div",{className:"flex min-w-0 flex-col",children:[s.jsx("span",{className:Et,children:e("settings.openchamber.about.field.version")}),s.jsx("span",{className:"typography-meta text-muted-foreground font-mono",children:p})]}),s.jsxs("div",{className:"flex min-w-0 flex-col",children:[s.jsx("span",{className:Et,children:e("settings.openchamber.about.field.openCodeVersion")}),s.jsx("span",{className:"typography-meta text-muted-foreground font-mono",children:c||e("settings.openchamber.about.state.unknown")})]}),s.jsxs("div",{className:"flex items-center gap-3",children:[m.checking&&s.jsxs("div",{className:"flex items-center gap-2 text-muted-foreground",children:[s.jsx(_,{name:"loader",className:"h-4 w-4 animate-spin"}),s.jsx("span",{className:"typography-meta",children:e("settings.openchamber.about.state.checking")})]}),!m.checking&&m.available&&s.jsxs(H,{size:"sm",variant:"default",onClick:()=>n(!0),children:[s.jsx(_,{name:"download",className:"h-4 w-4 mr-1"}),e("settings.openchamber.about.actions.updateToVersion",{version:m.info?.version||""})]}),!m.checking&&!m.available&&!m.error&&s.jsx("span",{className:"typography-meta text-muted-foreground",children:e("settings.openchamber.about.state.upToDate")}),s.jsx(H,{size:"sm",variant:"outline",onClick:()=>m.checkForUpdates(),disabled:m.checking,children:e("settings.openchamber.about.actions.checkForUpdates")})]})]}),m.error&&s.jsx("div",{className:"px-3 py-2 border-b border-border/40",children:s.jsx("p",{className:"typography-meta text-[var(--status-error)]",children:m.error})}),s.jsxs("div",{className:"flex flex-col gap-2 border-b border-border/40 px-4 py-3 @xl:flex-row @xl:items-center @xl:justify-between",children:[s.jsx("span",{className:Et,children:e("settings.openchamber.about.field.instanceUrls")}),s.jsx(Er,{})]}),s.jsxs("div",{className:"flex items-center gap-4 px-4 py-4",children:[s.jsxs("a",{href:Dr,target:"_blank",rel:"noopener noreferrer",className:"flex items-center gap-1.5 text-muted-foreground hover:text-foreground typography-meta transition-colors",children:[s.jsx(_,{name:"github-fill",className:"h-4 w-4"}),s.jsx("span",{children:"GitHub"})]}),s.jsxs("a",{href:Mr,target:"_blank",rel:"noopener noreferrer",className:"flex items-center gap-1.5 text-muted-foreground hover:text-foreground typography-meta transition-colors",children:[s.jsx(_,{name:"twitter-xfill",className:"h-4 w-4"}),s.jsx("span",{children:"@openchamber_dev"})]})]})]}),s.jsx(Ir,{open:a,onOpenChange:n,info:m.info,downloading:m.downloading,downloaded:m.downloaded,progress:m.progress,error:m.error,onDownload:m.downloadUpdate,onRestart:m.restartToUpdate,runtimeType:m.runtimeType})]})},Wo=t=>t.replace(/[-_]/g," ").replace(/\b\w/g,e=>e.toUpperCase()),ka=t=>{const e=ht.c(39),{className:a}=t,{t:n}=ot(),i=Fs(ud),r=Fs(gd),l=Fs(hd),x=ds();let c;e[0]!==i?(c=[...i].sort(fd),e[0]=i,e[1]=c):c=e[1];const y=c;let m;e:{if(y.length===0){m=null;break e}let $;e[2]!==r||e[3]!==y?($=y.find(w=>w.id===r)??y[0],e[2]=r,e[3]=y,e[4]=$):$=e[4],m=$}const b=m;if(x||y.length===0)return null;let p;e[5]!==b||e[6]!==n?(p=b?.label&&b.label.trim().length>0?b.label:b?.path.split("/").filter(Boolean).pop()||b?.path||n("settings.shared.projectSelector.fallbackProject"),e[5]=b,e[6]=n,e[7]=p):p=e[7];const L=p;let k;e[8]!==L?(k=Wo(L),e[8]=L,e[9]=k):k=e[9];const N=k;let h;e[10]!==a?(h=je(a),e[10]=a,e[11]=h):h=e[11];let C;e[12]!==n?(C=n("settings.shared.projectSelector.switchProjectAria"),e[12]=n,e[13]=C):C=e[13];let u;e[14]!==n?(u=n("settings.shared.projectSelector.switchProjectTitle"),e[14]=n,e[15]=u):u=e[15];let E,q;e[16]===Symbol.for("react.memo_cache_sentinel")?(E=je("text-foreground border border-border/80 appearance-none flex h-8 w-full min-w-0 rounded-lg bg-transparent px-3 py-1 outline-none","hover:border-input focus-visible:ring-1 focus-visible:ring-primary/50 focus-visible:border-primary/70","flex items-center gap-1.5 text-left"),q=s.jsx(_,{name:"folder",className:"h-4 w-4 opacity-70"}),e[16]=E,e[17]=q):(E=e[16],q=e[17]);let M;e[18]!==N?(M=s.jsx("span",{className:"min-w-0 flex-1 truncate typography-ui-label font-medium",children:N}),e[18]=N,e[19]=M):M=e[19];let I;e[20]===Symbol.for("react.memo_cache_sentinel")?(I=s.jsx(_,{name:"arrow-down-s",className:"size-4 opacity-50"}),e[20]=I):I=e[20];let g;e[21]!==M||e[22]!==C||e[23]!==u?(g=s.jsx($s,{asChild:!0,children:s.jsxs("button",{type:"button","aria-label":C,title:u,className:E,children:[q,M,I]})}),e[21]=M,e[22]=C,e[23]=u,e[24]=g):g=e[24];const j=b?.id??"";let F;e[25]!==l?(F=$=>{$&&l($)},e[25]=l,e[26]=F):F=e[26];let S;e[27]!==y?(S=y.map(xd),e[27]=y,e[28]=S):S=e[28];let T;e[29]!==j||e[30]!==F||e[31]!==S?(T=s.jsx(Bs,{align:"start",className:"w-auto",children:s.jsx(Al,{value:j,onValueChange:F,children:S})}),e[29]=j,e[30]=F,e[31]=S,e[32]=T):T=e[32];let v;e[33]!==g||e[34]!==T?(v=s.jsxs(Hs,{children:[g,T]}),e[33]=g,e[34]=T,e[35]=v):v=e[35];let K;return e[36]!==v||e[37]!==h?(K=s.jsx("div",{className:h,children:v}),e[36]=v,e[37]=h,e[38]=K):K=e[38],K};function ud(t){return t.projects}function gd(t){return t.activeProjectId}function hd(t){return t.setActiveProject}function fd(t,e){return(t.label||t.path).localeCompare(e.label||e.path)}function xd(t){const e=t.label?.trim()?t.label.trim():t.path.split("/").filter(Boolean).pop()||t.path,a=Wo(e);return s.jsx(Pl,{value:t.id,children:s.jsx("span",{className:"min-w-0 truncate typography-ui",children:a})},t.id)}function bd(t,e){return`opencode:sidebar-group:${t}:${e}`}const Fi=t=>{const e=ht.c(33),{label:a,count:n,storageKey:i,defaultExpanded:r,children:l}=t,x=r===void 0?!0:r;let c;e[0]!==a||e[1]!==i?(c=bd(i,a),e[0]=a,e[1]=i,e[2]=c):c=e[2];const y=c,m=o.useId();let b;e[3]!==x||e[4]!==y?(b=()=>{try{const T=localStorage.getItem(y);if(T!==null)return T==="true"}catch{}return x},e[3]=x,e[4]=y,e[5]=b):b=e[5];const[p,L]=We.useState(b);let k,N;e[6]!==p||e[7]!==y?(k=()=>{try{localStorage.setItem(y,String(p))}catch{}},N=[y,p],e[6]=p,e[7]=y,e[8]=k,e[9]=N):(k=e[8],N=e[9]),We.useEffect(k,N);let h;e[10]===Symbol.for("react.memo_cache_sentinel")?(h=()=>L(vd),e[10]=h):h=e[10];let C;e[11]===Symbol.for("react.memo_cache_sentinel")?(C=je("flex w-full items-center gap-1 rounded-md px-2 py-1 text-left","text-xs font-semibold uppercase tracking-wide text-muted-foreground","hover:bg-[var(--interactive-hover)] transition-colors duration-150","focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-primary/50"),e[11]=C):C=e[11];const u=!p&&"-rotate-90";let E;e[12]!==u?(E=je("h-3.5 w-3.5 flex-shrink-0 transition-transform duration-200",u),e[12]=u,e[13]=E):E=e[13];let q;e[14]!==E?(q=s.jsx(_,{name:"arrow-down-s",className:E}),e[14]=E,e[15]=q):q=e[15];let M;e[16]!==a?(M=s.jsx("span",{className:"flex-1 truncate",children:a}),e[16]=a,e[17]=M):M=e[17];let I;e[18]!==n?(I=s.jsx("span",{className:"ml-1 tabular-nums opacity-60",children:n}),e[18]=n,e[19]=I):I=e[19];let g;e[20]!==m||e[21]!==p||e[22]!==q||e[23]!==M||e[24]!==I?(g=s.jsxs("button",{type:"button",onClick:h,"aria-expanded":p,"aria-controls":m,className:C,children:[q,M,I]}),e[20]=m,e[21]=p,e[22]=q,e[23]=M,e[24]=I,e[25]=g):g=e[25];const j=!p;let F;e[26]!==l||e[27]!==m||e[28]!==j?(F=s.jsx("div",{id:m,hidden:j,className:"mt-0.5 space-y-0.5 ml-2 pl-3 border-l-2 border-[var(--interactive-border)]",children:l}),e[26]=l,e[27]=m,e[28]=j,e[29]=F):F=e[29];let S;return e[30]!==g||e[31]!==F?(S=s.jsxs("div",{children:[g,F]}),e[30]=g,e[31]=F,e[32]=S):S=e[32],S};function vd(t){return!t}const yd=t=>{if(!Array.isArray(t))return[];const e=[];for(const a of t){if(!a||typeof a!="object")continue;const n=a;typeof n.permission!="string"||typeof n.pattern!="string"||typeof n.action!="string"||n.action!=="allow"&&n.action!=="ask"&&n.action!=="deny"||e.push({permission:n.permission,pattern:n.pattern,action:n.action})}return e},jd=t=>{const e=new Map;for(const a of t)!a.permission||a.permission==="invalid"||a.pattern&&e.set(`${a.permission}::${a.pattern}`,a);return Array.from(e.values())},Rr=t=>{const e=jd(yd(t));if(e.length===0)return;const a={};for(const i of e)i.permission&&((a[i.permission]||={})[i.pattern]=i.action);const n={};for(const[i,r]of Object.entries(a)){const l=Object.keys(r);if(l.length===1&&l[0]==="*"){n[i]=r["*"];continue}n[i]=r}return Object.keys(n).length>0?n:void 0},wd=({onItemSelect:t})=>{const{t:e}=ot(),[a,n]=o.useState(null),[i,r]=o.useState(""),[l,x]=o.useState(null),[c,y]=o.useState(null),[m,b]=o.useState(!1),[p,L]=o.useState(null),{selectedAgentName:k,agents:N,setSelectedAgent:h,setAgentDraft:C,createAgent:u,deleteAgent:E,loadAgents:q}=ja(Ps(P=>({selectedAgentName:P.selectedAgentName,agents:P.agents,setSelectedAgent:P.setSelectedAgent,setAgentDraft:P.setAgentDraft,createAgent:P.createAgent,deleteAgent:P.deleteAgent,loadAgents:P.loadAgents})));o.useEffect(()=>{q()},[q]);const M="bg-background",I=()=>{const P="new-agent";let ee=P,se=1;for(;N.some(D=>D.name===ee);)ee=`${P}-${se}`,se++;C({name:ee,scope:"user"}),h(ee),t?.()},g=async P=>{if(Bn(P)){R.error(e("settings.agents.sidebar.toast.builtInCannotDelete"));return}x(P),y("delete")},j=async P=>{Bn(P)&&(x(P),y("reset"))},F=()=>{x(null),y(null)},S=async()=>{if(!(!l||!c)){b(!0);try{const P=await E(l.name,l.scope);P.ok?(P.requiresManualRestart?R.warning(e("settings.agents.page.toast.savedManualRestart")):P.restartDeferred?R.success(e("settings.view.pendingRestart.saved")):c==="delete"?R.success(e("settings.agents.sidebar.toast.agentDeleted",{name:l.name})):R.success(e("settings.agents.sidebar.toast.agentReset",{name:l.name})),F()):c==="delete"?R.error(e("settings.agents.sidebar.toast.deleteFailed")):R.error(e("settings.agents.sidebar.toast.resetFailed"))}catch(P){const ee=P instanceof Error?P.message:"",se=/built-in|not deletable|not found/i.test(ee);c==="delete"?R.error(e(se?"settings.agents.sidebar.toast.definitionNotFound":"settings.agents.sidebar.toast.deleteFailed")):R.error(e("settings.agents.sidebar.toast.resetFailed"))}b(!1)}},T=P=>{const ee=P.name;let se=1,D=`${ee}-copy`;for(;N.some(V=>V.name===D);)se++,D=`${ee}-copy-${se}`;const O=P,U=P.model?.providerID&&P.model?.modelID?`${P.model.providerID}/${P.model.modelID}`:null,A=P;C({name:D,scope:O.scope||"user",description:P.description,model:U,variant:P.variant,temperature:P.temperature,top_p:P.topP,prompt:P.prompt,mode:P.mode,permission:Rr(P.permission),disable:A.disable}),h(D)},v=P=>{r(P.name),n(P)},K=async()=>{if(!a)return;const P=i.trim().replace(/\s+/g,"-");if(!P){R.error(e("settings.agents.sidebar.toast.agentNameRequired"));return}if(P===a.name){n(null);return}if(N.some(O=>O.name===P)){R.error(e("settings.agents.sidebar.toast.agentExists"));return}const ee=a.model?.providerID&&a.model?.modelID?`${a.model.providerID}/${a.model.modelID}`:null,se=a,D=await u({name:P,description:a.description,model:ee,variant:a.variant,temperature:a.temperature,top_p:a.topP,prompt:a.prompt,mode:a.mode,permission:Rr(a.permission),disable:se.disable,scope:se.scope});if(D.ok){const O=await E(a.name,se.scope);O.ok?(D.requiresManualRestart||O.requiresManualRestart?R.warning(e("settings.agents.page.toast.savedManualRestart")):R.success(e("settings.agents.sidebar.toast.agentRenamed",{name:P})),h(P)):R.error(e("settings.agents.sidebar.toast.removeOldAfterRenameFailed"))}else R.error(e("settings.agents.sidebar.toast.renameFailed"));n(null)},$=P=>{switch(P){case"primary":return s.jsx(_,{name:"ai-agent",className:"h-3 w-3 text-primary"});case"all":return s.jsx(_,{name:"ai-agent-fill",className:"h-3 w-3 text-primary"});case"subagent":return s.jsx(_,{name:"robot",className:"h-3 w-3 text-primary"});default:return null}},w=N.filter(P=>!Tl(P)),G=w.filter(Bn),Q=w.filter(P=>!Bn(P)),{groupedCustomAgents:X,ungroupedCustomAgents:Z}=We.useMemo(()=>{const P={},ee=[];for(const D of Q){const O=D;O.group?(P[O.group]||(P[O.group]=[]),P[O.group].push(D)):ee.push(D)}return{groupedCustomAgents:Object.keys(P).sort((D,O)=>D.localeCompare(O)).map(D=>({name:D,agents:P[D]})),ungroupedCustomAgents:ee}},[Q]);return s.jsxs("div",{className:je("flex h-full flex-col",M),children:[s.jsxs("div",{className:"border-b px-3 pt-4 pb-3",children:[s.jsx("h2",{className:`${qs} mb-3`,children:e("settings.agents.sidebar.title")}),s.jsx(ka,{className:"mb-3"}),s.jsxs("div",{className:"flex items-center justify-between gap-2",children:[s.jsx("span",{className:"typography-meta text-muted-foreground",children:e("settings.agents.sidebar.total",{count:w.length})}),s.jsx(H,{size:"sm","data-settings-item":"agents.create",variant:"ghost",className:"h-7 w-7 px-0 -my-1 text-muted-foreground",onClick:I,children:s.jsx(_,{name:"add",className:"h-3.5 w-3.5"})})]})]}),s.jsx(Ds,{outerClassName:"flex-1 min-h-0",className:"space-y-1 px-3 py-2 overflow-x-hidden",children:w.length===0?s.jsxs("div",{className:"py-12 px-4 text-center text-muted-foreground",children:[s.jsx(_,{name:"robot-2",className:"mx-auto mb-3 h-10 w-10 opacity-50"}),s.jsx("p",{className:"typography-ui-label font-medium",children:e("settings.agents.sidebar.empty.title")}),s.jsx("p",{className:"typography-meta mt-1 opacity-75",children:e("settings.agents.sidebar.empty.description")})]}):s.jsxs(s.Fragment,{children:[G.length>0&&s.jsxs(s.Fragment,{children:[s.jsx("div",{className:"px-2 pb-1.5 pt-2 text-xs font-semibold uppercase tracking-wide text-muted-foreground",children:e("settings.agents.sidebar.section.builtIn")}),G.map(P=>s.jsx(vi,{agent:P,isSelected:k===P.name,onSelect:()=>{h(P.name),t?.()},onReset:()=>j(P),onDuplicate:()=>T(P),getAgentModeIcon:$,isMenuOpen:p===P.name,onMenuOpenChange:ee=>L(ee?P.name:null)},P.name))]}),Q.length>0&&s.jsxs(s.Fragment,{children:[s.jsx("div",{className:"px-2 pb-1.5 pt-3 text-xs font-semibold uppercase tracking-wide text-muted-foreground",children:e("settings.agents.sidebar.section.custom")}),X.map(({name:P,agents:ee})=>s.jsx(Fi,{label:P,count:ee.length,storageKey:"agents",children:ee.map(se=>s.jsx(vi,{agent:se,isSelected:k===se.name,onSelect:()=>{h(se.name),t?.()},onRename:()=>v(se),onDelete:()=>g(se),onDuplicate:()=>T(se),getAgentModeIcon:$,isMenuOpen:p===se.name,onMenuOpenChange:D=>L(D?se.name:null)},se.name))},P)),Z.map(P=>s.jsx(vi,{agent:P,isSelected:k===P.name,onSelect:()=>{h(P.name),t?.()},onRename:()=>v(P),onDelete:()=>g(P),onDuplicate:()=>T(P),getAgentModeIcon:$,isMenuOpen:p===P.name,onMenuOpenChange:ee=>L(ee?P.name:null)},P.name))]})]})}),s.jsx(Ut,{open:l!==null&&c!==null,onOpenChange:P=>{!P&&!m&&F()},children:s.jsxs(Vt,{className:"max-w-md",children:[s.jsxs(Ht,{children:[s.jsx(Gt,{children:e(c==="delete"?"settings.agents.sidebar.dialog.deleteTitle":"settings.agents.sidebar.dialog.resetTitle")}),s.jsx(qt,{children:c==="delete"?e("settings.agents.sidebar.dialog.deleteDescription",{name:l?.name??""}):e("settings.agents.sidebar.dialog.resetDescription",{name:l?.name??""})})]}),s.jsxs(os,{children:[s.jsx(H,{size:"sm",variant:"ghost",onClick:F,disabled:m,children:e("settings.common.actions.cancel")}),s.jsx(H,{size:"sm",onClick:S,disabled:m,children:e(c==="delete"?"settings.common.actions.delete":"settings.common.actions.reset")})]})]})}),s.jsx(Ut,{open:a!==null,onOpenChange:P=>!P&&n(null),children:s.jsxs(Vt,{children:[s.jsxs(Ht,{children:[s.jsx(Gt,{children:e("settings.agents.sidebar.renameDialog.title")}),s.jsx(qt,{children:e("settings.agents.sidebar.renameDialog.description",{name:a?.name??""})})]}),s.jsx(He,{value:i,onChange:P=>r(P.target.value),placeholder:e("settings.agents.sidebar.renameDialog.placeholder"),className:"text-foreground placeholder:text-muted-foreground",onKeyDown:P=>{P.key==="Enter"&&K()}}),s.jsxs(os,{children:[s.jsx(H,{size:"sm",variant:"ghost",onClick:()=>n(null),children:e("settings.common.actions.cancel")}),s.jsx(H,{size:"sm",onClick:K,children:e("settings.common.actions.rename")})]})]})})]})},vi=t=>{const e=ht.c(52),{agent:a,isSelected:n,onSelect:i,onDelete:r,onReset:l,onRename:x,onDuplicate:c,getAgentModeIcon:y,isMenuOpen:m,onMenuOpenChange:b}=t,{t:p}=ot(),L=a;let k;e[0]===Symbol.for("react.memo_cache_sentinel")?(k=xa(),e[0]=k):k=e[0];const N=k,[h,C]=o.useState(!1);let u;e[1]!==r||e[2]!==c||e[3]!==x||e[4]!==l||e[5]!==p?(u=se=>s.jsxs(s.Fragment,{children:[x&&s.jsxs(se,{onClick:D=>{D.stopPropagation(),x()},children:[s.jsx(_,{name:"edit",className:"h-4 w-4 mr-px"}),p("settings.common.actions.rename")]}),s.jsxs(se,{onClick:D=>{D.stopPropagation(),c()},children:[s.jsx(_,{name:"file-copy",className:"h-4 w-4 mr-px"}),p("settings.common.actions.duplicate")]}),l&&s.jsxs(se,{onClick:D=>{D.stopPropagation(),l()},children:[s.jsx(_,{name:"restart",className:"h-4 w-4 mr-px"}),p("settings.common.actions.reset")]}),r&&s.jsxs(se,{onClick:D=>{D.stopPropagation(),r()},className:"text-destructive focus:text-destructive",children:[s.jsx(_,{name:"delete-bin",className:"h-4 w-4 mr-px"}),p("settings.common.actions.delete")]})]}),e[1]=r,e[2]=c,e[3]=x,e[4]=l,e[5]=p,e[6]=u):u=e[6];const E=u,q=n?"bg-interactive-selection":"hover:bg-interactive-hover";let M;e[7]!==q?(M=je("group relative flex items-center rounded-md px-1.5 py-1 transition-all duration-200 select-none",q),e[7]=q,e[8]=M):M=e[8];let I;e[9]===Symbol.for("react.memo_cache_sentinel")?(I=N?void 0:se=>{se.preventDefault(),C(!0)},e[9]=I):I=e[9];let g;e[10]!==M?(g=s.jsx("div",{className:M,onContextMenu:I}),e[10]=M,e[11]=g):g=e[11];let j;e[12]!==a.name?(j=s.jsx("span",{className:"typography-ui-label font-normal truncate text-foreground",children:a.name}),e[12]=a.name,e[13]=j):j=e[13];let F;e[14]!==a.mode||e[15]!==y?(F=y(a.mode),e[14]=a.mode,e[15]=y,e[16]=F):F=e[16];let S;e[17]!==a||e[18]!==L.scope||e[19]!==p?(S=(L.scope||Bn(a))&&s.jsx("span",{className:"typography-micro text-muted-foreground bg-muted px-1 rounded flex-shrink-0 leading-none pb-px border border-border/50",children:Bn(a)?p("settings.agents.sidebar.badge.system"):L.scope}),e[17]=a,e[18]=L.scope,e[19]=p,e[20]=S):S=e[20];let T;e[21]!==j||e[22]!==F||e[23]!==S?(T=s.jsxs("div",{className:"flex items-center gap-1.5",children:[j,F,S]}),e[21]=j,e[22]=F,e[23]=S,e[24]=T):T=e[24];let v;e[25]!==a.description?(v=a.description&&s.jsx("div",{className:"typography-micro text-muted-foreground/60 truncate leading-tight",children:a.description}),e[25]=a.description,e[26]=v):v=e[26];let K;e[27]!==i||e[28]!==T||e[29]!==v?(K=s.jsxs("button",{onClick:i,className:"flex min-w-0 flex-1 flex-col gap-0 rounded-sm text-left focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-primary/50",tabIndex:0,children:[T,v]}),e[27]=i,e[28]=T,e[29]=v,e[30]=K):K=e[30];let $;e[31]!==b?($=se=>{se&&C(!1),b(se)},e[31]=b,e[32]=$):$=e[32];let w;e[33]===Symbol.for("react.memo_cache_sentinel")?(w=s.jsx($s,{asChild:!0,children:s.jsx(H,{size:"sm",variant:"ghost",className:"h-6 w-6 px-0 flex-shrink-0 -mr-1 opacity-100 transition-opacity md:opacity-0 md:group-hover:opacity-100",children:s.jsx(_,{name:"more-2",className:"h-3.5 w-3.5"})})}),e[33]=w):w=e[33];let G;e[34]!==E?(G=s.jsx(Bs,{align:"end",className:"w-fit min-w-20",children:E(Gs)}),e[34]=E,e[35]=G):G=e[35];let Q;e[36]!==m||e[37]!==$||e[38]!==G?(Q=s.jsxs(Hs,{open:m,onOpenChange:$,children:[w,G]}),e[36]=m,e[37]=$,e[38]=G,e[39]=Q):Q=e[39];let X;e[40]!==K||e[41]!==Q?(X=s.jsxs("div",{className:"flex min-w-0 flex-1 items-center",children:[K,Q]}),e[40]=K,e[41]=Q,e[42]=X):X=e[42];let Z;e[43]!==X||e[44]!==g?(Z=s.jsx(Rn,{render:g,children:X}),e[43]=X,e[44]=g,e[45]=Z):Z=e[45];let P;e[46]!==E?(P=s.jsx(Dn,{className:"w-fit min-w-20",children:E(Mn)}),e[46]=E,e[47]=P):P=e[47];let ee;return e[48]!==h||e[49]!==Z||e[50]!==P?(ee=s.jsxs(On,{open:h,onOpenChange:C,children:[Z,P]}),e[48]=h,e[49]=Z,e[50]=P,e[51]=ee):ee=e[51],ee},rs=t=>{const e=ht.c(21),{children:a,className:n,outerClassName:i,title:r,titleLeading:l,titleAccessory:x,description:c,headerEnd:y,showSaveStatus:m}=t,b=m===void 0?!1:m,p=r!=null||c!=null||y!=null||b,L=typeof r=="string"||typeof r=="number",k=l!=null||x!=null;let N;e[0]!==i?(N=je("h-full",i),e[0]=i,e[1]=N):N=e[1];let h;e[2]!==n?(h=je("mx-auto max-w-[840px] space-y-0 px-6 py-6 @3xl:px-12 @3xl:py-8","[&>section:first-of-type]:border-t-0 [&>section:first-of-type]:pt-0",n),e[2]=n,e[3]=h):h=e[3];let C;e[4]!==c||e[5]!==p||e[6]!==k||e[7]!==y||e[8]!==L||e[9]!==b||e[10]!==r||e[11]!==x||e[12]!==l?(C=p&&s.jsxs("div",{className:"mb-2 flex flex-wrap items-start justify-between gap-x-4 gap-y-3 pb-6",children:[s.jsxs("div",{className:"min-w-0 flex-1 basis-64 space-y-1",children:[r!=null?L?k?s.jsxs("div",{className:"flex min-w-0 items-center gap-2",children:[l,s.jsx("h1",{className:je(Oi,"min-w-0 truncate"),children:r}),s.jsx("span",{className:"shrink-0",children:x})]}):s.jsx("h1",{className:Oi,children:r}):r:null,c!=null?typeof c=="string"||typeof c=="number"?s.jsx("p",{className:El,children:c}):c:null]}),s.jsxs("div",{className:"flex shrink-0 flex-wrap items-center justify-end gap-3",children:[y,b&&s.jsx(kd,{})]})]}),e[4]=c,e[5]=p,e[6]=k,e[7]=y,e[8]=L,e[9]=b,e[10]=r,e[11]=x,e[12]=l,e[13]=C):C=e[13];let u;e[14]!==a||e[15]!==h||e[16]!==C?(u=s.jsxs("div",{className:h,children:[C,a]}),e[14]=a,e[15]=h,e[16]=C,e[17]=u):u=e[17];let E;return e[18]!==N||e[19]!==u?(E=s.jsx(Ds,{outerClassName:N,className:"w-full @container",children:u}),e[18]=N,e[19]=u,e[20]=E):E=e[20],E},Nd=500,kd=()=>{const t=ht.c(13),{t:e}=ot(),a=o.useSyncExternalStore(Nc,xr,xr),[n,i]=o.useState(!1);let r,l;if(t[0]!==a?(r=()=>{if(a!=="saving"){i(!1);return}const m=setTimeout(()=>i(!0),Nd);return()=>clearTimeout(m)},l=[a],t[0]=a,t[1]=r,t[2]=l):(r=t[1],l=t[2]),o.useEffect(r,l),a==="error"){let m;t[3]===Symbol.for("react.memo_cache_sentinel")?(m=s.jsx(_,{name:"error-warning",className:"size-3.5"}),t[3]=m):m=t[3];let b;t[4]!==e?(b=e("settings.common.status.saveFailed"),t[4]=e,t[5]=b):b=t[5];let p;return t[6]!==b?(p=s.jsxs("div",{"aria-live":"assertive",className:"flex shrink-0 items-center gap-1.5 typography-meta text-[var(--status-error)]",children:[m,s.jsx("span",{children:b})]}),t[6]=b,t[7]=p):p=t[7],p}if(a!=="saving"||!n)return null;let x;t[8]===Symbol.for("react.memo_cache_sentinel")?(x=s.jsx(_,{name:"loader-4",className:"size-3.5 animate-spin"}),t[8]=x):x=t[8];let c;t[9]!==e?(c=e("settings.common.actions.saving"),t[9]=e,t[10]=c):c=t[10];let y;return t[11]!==c?(y=s.jsxs("div",{"aria-live":"polite",className:"flex shrink-0 items-center gap-1.5 typography-meta text-muted-foreground",children:[x,s.jsx("span",{children:c})]}),t[11]=c,t[12]=y):y=t[12],y},Sd=["allow","ask","deny"],ma=t=>t==="allow"||t==="ask"||t==="deny",Ki=()=>({global:null,keys:{}}),Cd=t=>{const e=Ki();if(t==null)return e;if(typeof t=="string")return ma(t)&&(e.global=t),e;if(typeof t!="object"||Array.isArray(t))return e;for(const[a,n]of Object.entries(t)){if(a==="*"){ma(n)&&(e.global=n);continue}const i={action:null,patterns:[]};if(ma(n))i.action=n;else if(n&&typeof n=="object"&&!Array.isArray(n))for(const[r,l]of Object.entries(n))ma(l)&&(r==="*"?i.action=l:i.patterns.push({pattern:r,action:l}));else continue;e.keys[a]=i}return e},_i=t=>{const e={};t.global!==null&&(e["*"]=t.global);for(const[a,n]of Object.entries(t.keys)){const i=n.patterns.filter(r=>r.pattern.trim().length>0);if(n.action!==null&&i.length===0)e[a]=n.action;else if(i.length>0){const r={};n.action!==null&&(r["*"]=n.action);for(const l of i)r[l.pattern]=l.action;e[a]=r}}return Object.keys(e).length>0?e:null},Id=(t,e)=>JSON.stringify(_i(t))===JSON.stringify(_i(e)),pn=t=>JSON.parse(JSON.stringify(t)),Pd=["edit","external_directory","doom_loop","plan_enter","plan_exit"],Ad=new Set(["read","edit","glob","grep","list","bash","task","external_directory","lsp","skill"]),Or=new Set(["write","patch","apply_patch","multiedit","invalid"]),Td=t=>t.split(/[_-]/).filter(Boolean).map(e=>e.charAt(0).toUpperCase()+e.slice(1)).join(" "),Ed=({agent:t})=>{const{t:e}=ot(),a=ja(O=>O.updateAgent),[n,i]=o.useState(Ki),[r,l]=o.useState(Ki),[x,c]=o.useState(!0),[y,m]=o.useState(!1),[b,p]=o.useState(!1),[L,k]=o.useState({}),[N,h]=o.useState([]),[C,u]=o.useState(""),[E,q]=o.useState(0),M=t.name;o.useEffect(()=>{let O=!1;return c(!0),m(!1),(async()=>{try{const U=ir(),A=U?`?directory=${encodeURIComponent(U)}`:"",V=await ct(`/api/config/agents/${encodeURIComponent(M)}/config${A}`,{headers:{"Cache-Control":"no-cache",...U?{"x-opencode-directory":U}:{}}});if(!V.ok)throw new Error(String(V.status));const W=await V.json().catch(()=>null);if(O)return;const te=Cd(W?.config?.permission);i(pn(te)),l(te)}catch{O||m(!0)}finally{O||c(!1)}})(),()=>{O=!0}},[M,E]),o.useEffect(()=>{let O=!1;return(async()=>{try{const U=await on.listToolIds({directory:ir()});!O&&Array.isArray(U)&&h(U.filter(A=>typeof A=="string"&&!Or.has(A)))}catch{}})(),()=>{O=!0}},[M]);const I=o.useMemo(()=>{const O=t.permission;if(!Array.isArray(O))return[];const U=[];for(const A of O){if(!A||typeof A!="object")continue;const{permission:V,pattern:W,action:te}=A;typeof V=="string"&&typeof W=="string"&&ma(te)&&U.push({permission:V,pattern:W,action:te})}return U},[t]),g=o.useCallback(O=>{const U=I.find(V=>V.permission===O&&V.pattern==="*");if(U)return U.action;const A=I.find(V=>V.permission==="*"&&V.pattern==="*");return A?A.action:null},[I]),j=o.useCallback(O=>{const U=r.keys[O]?.patterns??[],A=new Set(U.map(V=>V.pattern));return I.filter(V=>V.permission===O&&V.pattern!=="*"&&!A.has(V.pattern))},[I,r.keys]),F=o.useMemo(()=>{const O=new Set;for(const U of N)O.add(U);for(const U of Pd)O.add(U);for(const U of Object.keys(r.keys))O.add(U);for(const U of Or)O.delete(U);return Array.from(O).sort((U,A)=>U.localeCompare(A))},[N,r.keys]),S=o.useMemo(()=>!Id(r,n),[r,n]),T=O=>{l(U=>({...U,global:O}))},v=(O,U)=>{l(A=>{const V=pn(A),W=V.keys[O]??{action:null,patterns:[]};return W.action=U,W.action===null&&W.patterns.length===0?delete V.keys[O]:V.keys[O]=W,V})},K=(O,U,A,V)=>{l(W=>{const te=pn(W),ae=te.keys[O]??{action:null,patterns:[]};return ae.patterns[U]={pattern:A,action:V},te.keys[O]=ae,te})},$=O=>{l(U=>{const A=pn(U),V=A.keys[O]??{action:null,patterns:[]};return V.patterns.push({pattern:"",action:"allow"}),A.keys[O]=V,A}),k(U=>({...U,[O]:!0}))},w=(O,U)=>{l(A=>{const V=pn(A),W=V.keys[O];return W?(W.patterns.splice(U,1),W.action===null&&W.patterns.length===0&&delete V.keys[O],V):A})},G=()=>{const O=C.trim();!O||O==="*"||(l(U=>{if(U.keys[O])return U;const A=pn(U);return A.keys[O]={action:"ask",patterns:[]},A}),k(U=>({...U,[O]:!0})),u(""))},Q=async()=>{p(!0);try{const O=_i(r),U=await a(M,{permission:O});U.ok?(i(pn(r)),R.success(U.requiresManualRestart?e("settings.agents.page.permissionsEditor.toast.savedRestartRequired"):e("settings.agents.page.permissionsEditor.toast.saved"))):R.error(e("settings.agents.page.permissionsEditor.toast.saveFailed"))}finally{p(!1)}},X=()=>{l(pn(n))},Z=O=>e(O==="allow"?"settings.agents.page.permissionsEditor.action.allow":O==="ask"?"settings.agents.page.permissionsEditor.action.ask":"settings.agents.page.permissionsEditor.action.deny"),P=e("settings.agents.page.permissionsEditor.action.inherit"),ee=e("settings.agents.page.permissionsEditor.action.default"),se=O=>[...O?[{value:"inherit",label:O}]:[],...Sd.map(U=>({value:U,label:Z(U)}))],D=(O,U,A,V=P)=>s.jsx(Ls,{value:O??"inherit",options:se(V),onChange:W=>U(W==="inherit"?null:W),"aria-label":A});return x?s.jsx(Oe,{title:e("settings.agents.page.section.toolPermissions"),children:s.jsx("p",{className:In,children:e("common.loading")})}):y?s.jsx(Oe,{title:e("settings.agents.page.section.toolPermissions"),children:s.jsxs("div",{className:"flex items-center gap-3",children:[s.jsx("p",{className:"typography-meta text-[var(--status-error)]",children:e("settings.agents.page.permissionsEditor.state.loadFailed")}),s.jsx(H,{variant:"outline",size:"xs",onClick:()=>q(O=>O+1),children:e("settings.agents.page.permissionsEditor.actions.retry")})]})}):s.jsxs(Oe,{title:e("settings.agents.page.section.toolPermissions"),settingsItem:"agents.permissions",info:e("settings.agents.page.permissionsEditor.sectionInfo"),headerAction:S?s.jsxs("div",{className:"flex items-center gap-2",children:[s.jsx(H,{variant:"ghost",size:"xs",className:"!font-normal",onClick:X,disabled:b,children:e("settings.agents.page.permissionsEditor.actions.discard")}),s.jsx(H,{size:"xs",className:"!font-normal",onClick:()=>{Q()},disabled:b,children:e(b?"settings.common.actions.saving":"settings.agents.page.permissionsEditor.actions.save")})]}):void 0,contentClassName:"space-y-4",children:[s.jsxs("div",{className:"flex flex-col gap-2 pb-2 @xl:flex-row @xl:items-center @xl:justify-between",children:[s.jsxs("div",{className:"flex items-center gap-1.5",children:[s.jsx("span",{className:Et,children:e("settings.agents.page.permissionsEditor.defaultLabel")}),s.jsx(Yt,{children:e("settings.agents.page.permissionsEditor.defaultInfo")}),r.global===null&&s.jsx("span",{className:"typography-micro text-muted-foreground",children:e("settings.agents.page.permissionsEditor.effectiveHint",{action:Z(g("*")??"allow")})})]}),D(r.global,T,e("settings.agents.page.permissionsEditor.defaultAria"),ee)]}),s.jsx("div",{children:F.map(O=>{const U=r.keys[O]??{action:null,patterns:[]},A=j(O),V=Ad.has(O)||U.patterns.length>0,W=V||A.length>0,te=L[O]===!0,ae=g(O);return s.jsxs("div",{className:"border-t border-border/40 py-2",children:[s.jsxs("div",{className:"flex flex-col gap-2 @xl:flex-row @xl:items-center @xl:justify-between",children:[s.jsxs("button",{type:"button",onClick:W?()=>k(le=>({...le,[O]:!te})):void 0,className:je("flex min-w-0 items-center gap-1.5 text-left",!W&&"cursor-default"),"aria-expanded":W?te:void 0,children:[s.jsx(_,{name:te&&W?"arrow-down-s":"arrow-right-s",className:je("h-3.5 w-3.5 shrink-0 text-muted-foreground",!W&&"opacity-0")}),s.jsx("span",{className:Et,children:Td(O)}),s.jsx("span",{className:"typography-micro font-mono text-muted-foreground/70",children:O}),U.action===null&&ae!==null&&s.jsx("span",{className:"typography-micro text-muted-foreground",children:e("settings.agents.page.permissionsEditor.effectiveHint",{action:Z(ae)})}),U.patterns.length>0&&s.jsx("span",{className:"typography-micro rounded bg-muted px-1 text-muted-foreground",children:e("settings.agents.page.permissionsEditor.ruleCount",{count:String(U.patterns.length)})})]}),D(U.action,le=>v(O,le),e("settings.agents.page.permissionsEditor.keyAria",{key:O}))]}),te&&W&&s.jsxs("div",{className:"mt-2 space-y-2 pl-5",children:[U.patterns.map((le,be)=>s.jsxs("div",{className:"flex flex-wrap items-center gap-2",children:[s.jsx(He,{value:le.pattern,onChange:ke=>K(O,be,ke.target.value,le.action),placeholder:e("settings.agents.page.permissionsEditor.patternPlaceholder"),className:"h-8 w-full max-w-[24rem] min-w-0 flex-1 font-mono text-xs"}),s.jsx(Ls,{value:le.action,options:se(),onChange:ke=>K(O,be,le.pattern,ke),"aria-label":e("settings.agents.page.permissionsEditor.patternActionAria",{key:O})}),s.jsx(H,{variant:"ghost",size:"icon",className:"h-7 w-7 shrink-0 text-muted-foreground hover:bg-destructive/10 hover:text-destructive",onClick:()=>w(O,be),"aria-label":e("settings.agents.page.permissionsEditor.actions.removeRuleAria"),children:s.jsx(_,{name:"close",className:"h-3.5 w-3.5"})})]},be)),V&&s.jsxs(H,{variant:"outline",size:"xs",className:"!font-normal",onClick:()=>$(O),children:[s.jsx(_,{name:"add",className:"mr-1 h-3.5 w-3.5"}),e("settings.agents.page.permissionsEditor.actions.addRule")]}),A.length>0&&s.jsxs("div",{className:"space-y-1 pt-1",children:[s.jsxs("div",{className:"flex items-center gap-1.5",children:[s.jsx("span",{className:"typography-micro font-medium text-muted-foreground",children:e("settings.agents.page.permissionsEditor.sessionRulesTitle")}),s.jsx(Yt,{children:e("settings.agents.page.permissionsEditor.sessionRulesInfo")})]}),A.map(le=>s.jsxs("div",{className:"flex items-center gap-2",children:[s.jsx("span",{className:"typography-micro min-w-0 flex-1 truncate font-mono text-muted-foreground/70",children:le.pattern}),s.jsx("span",{className:"typography-micro text-muted-foreground",children:Z(le.action)})]},`${le.pattern}-${le.action}`))]})]})]},O)})}),s.jsxs("div",{className:"flex flex-wrap items-center gap-2 border-t border-border/40 pt-3",children:[s.jsx(He,{value:C,onChange:O=>u(O.target.value),onKeyDown:O=>{O.key==="Enter"&&(O.preventDefault(),G())},placeholder:e("settings.agents.page.permissionsEditor.customKeyPlaceholder"),className:"h-8 w-full max-w-[16rem] font-mono text-xs"}),s.jsxs(H,{variant:"outline",size:"xs",className:"!font-normal",onClick:G,disabled:!C.trim(),children:[s.jsx(_,{name:"add",className:"mr-1 h-3.5 w-3.5"}),e("settings.agents.page.permissionsEditor.actions.addKey")]})]})]})},Dd=(t,e)=>{const a=Gn(e);if(!a)return[];const i=t.find(r=>r.id===a.providerId)?.models?.find(r=>r.id===a.modelId);return i?.variants?Object.keys(i.variants):[]},Md=()=>{const{t}=ot(),e=nt(D=>D.providers),{selectedAgentName:a,getAgentByName:n,createAgent:i,updateAgent:r,agents:l,agentDraft:x,setAgentDraft:c}=ja(Ps(D=>({selectedAgentName:D.selectedAgentName,getAgentByName:D.getAgentByName,createAgent:D.createAgent,updateAgent:D.updateAgent,agents:D.agents,agentDraft:D.agentDraft,setAgentDraft:D.setAgentDraft}))),y=a?n(a):null,m=!!(x&&x.name===a&&!y),[b,p]=o.useState(""),[L,k]=o.useState("user"),[N,h]=o.useState(""),[C,u]=o.useState("subagent"),[E,q]=o.useState(""),[M,I]=o.useState(""),[g,j]=o.useState(void 0),[F,S]=o.useState(void 0),[T,v]=o.useState(""),[K,$]=o.useState(!1),w=o.useRef(null),G=o.useMemo(()=>Dd(e,E),[E,e]),Q=G.length>0,X=M||"__default",Z=Q,P=o.useMemo(()=>M&&!G.includes(M)?[M,...G]:G,[M,G]);o.useEffect(()=>{if(m&&x){const D=x.name||"",O=x.scope||"user",U=x.description||"",A=x.mode||"subagent",V=x.model||"",W=x.variant||"",te=x.temperature??void 0,ae=x.top_p??void 0,le=x.prompt||"";p(D),k(O),h(U),u(A),q(V),I(W),j(te),S(ae),v(le),w.current={draftName:D,draftScope:O,description:U,mode:A,model:V,variant:W,temperature:te,topP:ae,prompt:le};return}if(y&&a===y.name){const D=y.description||"",O=y.mode||"subagent",U=y.model?.providerID&&y.model?.modelID?`${y.model.providerID}/${y.model.modelID}`:"",A=y.variant||"",V=y.temperature??void 0,W=y.topP??void 0,te=y.prompt||"";h(D),u(O),q(U),I(A),j(V),S(W),v(te),w.current={draftName:"",draftScope:"user",description:D,mode:O,model:U,variant:A,temperature:V,topP:W,prompt:te}}},[x,m,y,a]);const ee=o.useMemo(()=>{const D=w.current;return D?!!(m&&(b!==D.draftName||L!==D.draftScope)||N!==D.description||C!==D.mode||E!==D.model||M!==D.variant||g!==D.temperature||F!==D.topP||T!==D.prompt):!1},[N,b,L,m,C,E,T,g,F,M]),se=async()=>{const D=m?b.trim().replace(/\s+/g,"-"):a?.trim();if(!D){R.error(t("settings.agents.sidebar.toast.agentNameRequired"));return}if(m&&l.some(O=>O.name===D)){R.error(t("settings.agents.sidebar.toast.agentExists"));return}$(!0);try{const O=E.trim(),U=M.trim(),A=T.trim(),V={name:D,...N.trim()?{description:N.trim()}:{},mode:C,model:O===""?null:O,variant:U===""?null:U||void 0,temperature:g??null,top_p:F??null,prompt:A||(m?void 0:null),...m&&L?{scope:L}:{}};let W;m?(W=await i(V),W.ok&&c(null)):W=await r(D,V),W.ok?W.requiresManualRestart?R.warning(t("settings.agents.page.toast.savedManualRestart")):W.restartDeferred?R.success(t("settings.view.pendingRestart.saved")):R.success(t(m?"settings.agents.page.toast.created":"settings.agents.page.toast.updated")):R.error(t(m?"settings.agents.page.toast.createFailed":"settings.agents.page.toast.updateFailed"))}catch(O){console.error("Error saving agent:",O);const U=O instanceof Error&&O.message?O.message:t("settings.agents.page.toast.saveUnexpectedError");R.error(U)}finally{$(!1)}};return a?s.jsxs(rs,{title:m?t("settings.agents.page.title.new"):a,description:t(m?"settings.agents.page.subtitle.new":"settings.agents.page.subtitle.edit"),showSaveStatus:!1,children:[s.jsxs(Oe,{title:t("settings.agents.page.section.identityRole"),divider:!1,contentClassName:"space-y-0",children:[m&&s.jsxs($t,{settingsItem:"agents.name",label:t("settings.agents.page.field.agentName"),children:[s.jsxs("div",{className:"flex items-center",children:[s.jsx("span",{className:"typography-ui-label text-muted-foreground mr-1",children:"@"}),s.jsx(He,{value:b,onChange:D=>p(D.target.value),placeholder:t("settings.agents.page.field.agentNamePlaceholder"),className:"h-7 w-40 px-2"})]}),s.jsxs(Dt,{value:L,onValueChange:D=>k(D),children:[s.jsx(Mt,{size:Kt,className:"w-fit min-w-[100px]",children:s.jsx(_t,{placeholder:t("settings.agents.page.field.scopePlaceholder")})}),s.jsxs(Rt,{align:"end",children:[s.jsx(dt,{value:"user",children:s.jsxs("div",{className:"flex items-center gap-2",children:[s.jsx(_,{name:"user-3",className:"h-3.5 w-3.5"}),s.jsx("span",{children:t("settings.common.scope.global")})]})}),s.jsx(dt,{value:"project",children:s.jsxs("div",{className:"flex items-center gap-2",children:[s.jsx(_,{name:"folder",className:"h-3.5 w-3.5"}),s.jsx("span",{children:t("settings.common.scope.project")})]})})]})]})]}),s.jsx(Qt,{label:t("settings.common.field.description"),controlClassName:"w-full max-w-none",children:s.jsx(Ns,{value:N,onChange:D=>h(D.target.value),placeholder:t("settings.agents.page.field.descriptionPlaceholder"),rows:2,className:"w-full resize-none min-h-[60px] bg-transparent"})}),s.jsx(Qt,{settingsItem:"agents.mode",label:t("settings.agents.page.field.mode"),info:t("settings.agents.page.field.modeTooltip"),children:s.jsx(Ls,{"aria-label":t("settings.agents.page.field.mode"),value:C,onChange:u,options:[{value:"primary",label:t("settings.agents.page.mode.primary")},{value:"subagent",label:t("settings.agents.page.mode.subagent")},{value:"all",label:t("settings.agents.page.mode.all")}]})})]}),s.jsxs(Oe,{title:t("settings.agents.page.section.modelParameters"),contentClassName:"space-y-3",children:[s.jsx($t,{settingsItem:"agents.model",label:t("settings.agents.page.field.overrideModel"),children:s.jsx(ua,{providerId:Gn(E)?.providerId??"",modelId:Gn(E)?.modelId??"",onChange:(D,O)=>{q(D&&O?`${D}/${O}`:""),I("")},className:bn})}),s.jsx($t,{settingsItem:"agents.variant",label:t("settings.agents.page.field.variant"),info:s.jsxs("div",{className:"space-y-1",children:[s.jsx("p",{children:t("settings.agents.page.field.variantTooltip")}),s.jsx("p",{children:t("settings.agents.page.field.variantHint")})]}),children:Z?s.jsxs(Dt,{value:X,onValueChange:D=>I(D==="__default"?"":D),children:[s.jsx(Mt,{size:Kt,className:vn,children:s.jsx(_t,{placeholder:t("settings.agents.page.field.variantPlaceholder"),children:D=>D==="__default"?t("chat.modelControls.default"):D})}),s.jsxs(Rt,{children:[s.jsx(dt,{value:"__default",children:t("chat.modelControls.default")}),P.map(D=>s.jsx(dt,{value:D,children:D},D))]})]}):s.jsxs(s.Fragment,{children:[s.jsx(He,{value:M,onChange:D=>I(D.target.value),placeholder:t("settings.agents.page.field.variantPlaceholder"),disabled:!E&&!M,className:"h-8 w-40 rounded-md px-3"}),M&&s.jsx(H,{size:"sm",type:"button",variant:"ghost",onClick:()=>I(""),className:gs,"aria-label":t("settings.common.actions.clear"),title:t("settings.common.actions.clear"),children:s.jsx(_,{name:"close",className:"h-3.5 w-3.5"})})]})}),s.jsxs($t,{settingsItem:"agents.temperature",label:t("settings.agents.page.field.temperature"),info:s.jsxs("div",{className:"space-y-1",children:[s.jsx("p",{children:t("settings.agents.page.field.temperatureTooltip")}),s.jsx("p",{children:t("settings.agents.page.field.temperatureRange")})]}),children:[s.jsx(ys,{value:g,fallbackValue:.7,onValueChange:j,onClear:()=>j(void 0),min:0,max:2,step:.1,inputMode:"decimal",placeholder:"—",emptyLabel:"—",className:"w-16"}),g!==void 0&&s.jsx(H,{size:"sm",type:"button",variant:"ghost",onClick:()=>j(void 0),className:gs,"aria-label":t("settings.agents.page.field.clearTemperatureAria"),title:t("settings.common.actions.clear"),children:s.jsx(_,{name:"close",className:"h-3.5 w-3.5"})})]}),s.jsxs($t,{settingsItem:"agents.top-p",label:t("settings.agents.page.field.topP"),info:s.jsxs("div",{className:"space-y-1",children:[s.jsx("p",{children:t("settings.agents.page.field.topPTooltip")}),s.jsx("p",{children:t("settings.agents.page.field.topPRange")})]}),children:[s.jsx(ys,{value:F,fallbackValue:.9,onValueChange:S,onClear:()=>S(void 0),min:0,max:1,step:.1,inputMode:"decimal",placeholder:"—",emptyLabel:"—",className:"w-16"}),F!==void 0&&s.jsx(H,{size:"sm",type:"button",variant:"ghost",onClick:()=>S(void 0),className:gs,"aria-label":t("settings.agents.page.field.clearTopPAria"),title:t("settings.common.actions.clear"),children:s.jsx(_,{name:"close",className:"h-3.5 w-3.5"})})]})]}),s.jsx(Oe,{title:t("settings.agents.page.section.systemPrompt"),settingsItem:"agents.system-prompt",children:s.jsx(Ns,{value:T,onChange:D=>v(D.target.value),placeholder:t("settings.agents.page.field.systemPromptPlaceholder"),rows:8,className:"w-full font-mono typography-meta min-h-[120px] max-h-[60vh] bg-transparent resize-y"})}),!m&&y&&s.jsx(Ed,{agent:y}),s.jsx("div",{className:"pb-8",children:s.jsx(H,{onClick:se,disabled:K||!ee,size:"xs",className:"!font-normal",children:t(K?"settings.common.actions.saving":"settings.common.actions.saveChanges")})})]}):s.jsx("div",{className:"flex h-full items-center justify-center",children:s.jsxs("div",{className:"text-center text-muted-foreground",children:[s.jsx(_,{name:"robot-2",className:"mx-auto mb-3 h-12 w-12 opacity-50"}),s.jsx("p",{className:"typography-body",children:t("settings.agents.page.empty.title")}),s.jsx("p",{className:"typography-meta mt-1 opacity-75",children:t("settings.agents.page.empty.description")})]})})},Rd="~/.config/opencode/AGENTS.md",Jo=async(t,e)=>{const a=await t.json().catch(()=>null);return typeof a?.error=="string"&&a.error.trim()?a.error:e},Od=t=>t.length>0&&!t.endsWith(`
2
+ `)?`${t}
3
+ `:t,Oa={prompt:"",optimizeSystemPrompt:!1,responseStyleEnabled:!1,responseStylePreset:"concise",responseStyleCustomInstructions:""},Ld=(t,e)=>t==="custom"?e:Rl(t),Fd=t=>t==="custom"?"custom":Ao(t)?t:"concise",Lr={concise:"settings.behavior.page.responseStyle.option.concise",detailed:"settings.behavior.page.responseStyle.option.detailed",mentor:"settings.behavior.page.responseStyle.option.mentor",pushback:"settings.behavior.page.responseStyle.option.pushback",noFiller:"settings.behavior.page.responseStyle.option.noFiller",matchEnergy:"settings.behavior.page.responseStyle.option.matchEnergy",warmPeer:"settings.behavior.page.responseStyle.option.warmPeer"},yi=async(t,e)=>{bi("saving");try{const a=await ct("/api/config/settings",{method:"PUT",headers:{"Content-Type":"application/json",Accept:"application/json"},body:JSON.stringify(t)});if(!a.ok)throw new Error(await Jo(a,e));bi("saved")}catch(a){throw bi("error"),a}},Kd=()=>{const{t}=ot(),e=Dl(),[a,n]=o.useState(""),[i,r]=o.useState(!1),[l,x]=o.useState(Oa.responseStyleEnabled),[c,y]=o.useState(Oa.responseStylePreset),[m,b]=o.useState(Oa.responseStyleCustomInstructions),[p,L]=o.useState(!0),[k,N]=o.useState(!1),[h,C]=o.useState(!1),[u,E]=o.useState(""),[q,M]=o.useState(!1),I=o.useRef(null);o.useEffect(()=>{const v=new AbortController;return(async()=>{try{const[$,w]=await Promise.all([ct("/api/config/settings",{method:"GET",headers:{Accept:"application/json"},signal:v.signal}),ct("/api/behavior/agents-md",{method:"GET",headers:{Accept:"application/json"},signal:v.signal})]);let G=Oa;if($.ok){const Q=await $.json();G={...G,optimizeSystemPrompt:Q.optimizeSystemPrompt===!0,responseStyleEnabled:Q.responseStyleEnabled===!0,responseStylePreset:Fd(Q.responseStylePreset),responseStyleCustomInstructions:typeof Q.responseStyleCustomInstructions=="string"?Q.responseStyleCustomInstructions:""},typeof Q.globalBehaviorPrompt=="string"&&(G={...G,prompt:Q.globalBehaviorPrompt})}if(!G.prompt.trim()&&w.ok){const Q=await w.json();typeof Q.content=="string"&&(G={...G,prompt:Q.content})}n(G.prompt),r(G.optimizeSystemPrompt),M(G.optimizeSystemPrompt),x(G.responseStyleEnabled),y(G.responseStylePreset),b(G.responseStyleCustomInstructions),E(G.prompt),I.current={enabled:G.responseStyleEnabled,preset:G.responseStylePreset,custom:G.responseStyleCustomInstructions}}catch($){$.name!=="AbortError"&&console.warn("Failed to load behavior settings:",$)}finally{L(!1)}})(),()=>v.abort()},[]),o.useEffect(()=>{if(p)return;const v=I.current;if(v&&v.enabled===l&&v.preset===c&&v.custom===m)return;const K={enabled:l,preset:c,custom:m},$=setTimeout(async()=>{try{await yi({responseStyleEnabled:K.enabled,responseStylePreset:K.preset,responseStyleCustomInstructions:K.custom},t("settings.behavior.page.toast.saveFailed")),I.current=K}catch(w){const G=w instanceof Error?w.message:t("settings.behavior.page.toast.saveFailed");R.error(G)}},400);return()=>clearTimeout($)},[l,c,m,p,t]);const g=Ld(c,m),j=a!==u,F=i!==q,S=async()=>{N(!0);try{const v=Od(a),K=await ct("/api/behavior/agents-md",{method:"PUT",headers:{"Content-Type":"application/json",Accept:"application/json"},body:JSON.stringify({content:v})});if(!K.ok)throw new Error(await Jo(K,t("settings.behavior.page.toast.saveFailed")));const $=await K.json().catch(()=>null),w=qa($,"behavior",{id:"agents-md"});await yi({globalBehaviorPrompt:v},t("settings.behavior.page.toast.saveFailed")),n(v),E(v),R.success(t(w?"settings.view.pendingRestart.saved":"settings.behavior.page.toast.saved"))}catch(v){console.error("Failed to save behavior:",v);const K=v instanceof Error?v.message:t("settings.behavior.page.toast.saveFailed");R.error(K)}finally{N(!1)}},T=async()=>{C(!0);try{await yi({optimizeSystemPrompt:i},t("settings.behavior.page.toast.saveFailed")),M(i),qn("behavior",{id:"optimize-system-prompt"}),R.success(t("settings.view.pendingRestart.saved"))}catch(v){const K=v instanceof Error?v.message:t("settings.behavior.page.toast.saveFailed");R.error(K)}finally{C(!1)}};return s.jsxs(rs,{title:t("settings.behavior.page.title"),description:t("settings.page.behavior.description"),showSaveStatus:!0,children:[!e&&s.jsxs(Oe,{title:t("settings.behavior.page.section.systemPromptOptimization"),divider:!1,settingsItem:"behavior.system-prompt-optimization",contentClassName:"space-y-3",children:[s.jsx(ut,{checked:i,onChange:r,disabled:p||h,label:t("settings.behavior.page.systemPromptOptimization.enable"),ariaLabel:t("settings.behavior.page.systemPromptOptimization.enableAria"),info:t("settings.behavior.page.systemPromptOptimization.info")}),s.jsx(H,{type:"button",size:"xs",onClick:()=>{T()},disabled:p||h||!F,className:"!font-normal",children:t(h?"settings.common.actions.saving":"settings.common.actions.saveChanges")})]}),s.jsxs(Oe,{title:t("settings.behavior.page.section.systemPrompt"),info:s.jsxs("div",{className:"space-y-1",children:[s.jsx("p",{className:"font-medium text-foreground",children:t("settings.behavior.page.warning.title")}),s.jsx("p",{children:t("settings.behavior.page.warning.description",{path:Rd})})]}),settingsItem:"behavior.system-prompt",contentClassName:"space-y-3",children:[s.jsx(Ns,{value:a,onChange:v=>n(v.target.value),placeholder:t("settings.behavior.page.field.systemPromptPlaceholder"),rows:12,disabled:p,outerClassName:"min-h-[160px] max-h-[70vh]",className:"w-full font-mono typography-meta bg-transparent"}),s.jsx(H,{onClick:S,disabled:k||!j||p,size:"xs",className:"!font-normal",children:t(k?"settings.common.actions.saving":"settings.common.actions.saveChanges")})]}),s.jsxs(Oe,{title:t("settings.behavior.page.section.responseStyle"),info:t("settings.behavior.page.responseStyle.tooltip"),settingsItem:"behavior.response-style",contentClassName:"space-y-3",children:[s.jsx(ut,{checked:l,onChange:x,disabled:p,label:t("settings.behavior.page.responseStyle.enable"),ariaLabel:t("settings.behavior.page.responseStyle.enableAria")}),s.jsx($t,{label:t("settings.behavior.page.responseStyle.preset"),alignEnd:!1,children:s.jsxs(Dt,{value:c,onValueChange:v=>y(v),disabled:p||!l,children:[s.jsx(Mt,{size:Kt,className:vn,children:s.jsx(_t,{children:v=>v==="custom"?t("settings.behavior.page.responseStyle.option.custom"):Ao(v)?t(Lr[v]):null})}),s.jsxs(Rt,{children:[Ml.map(v=>s.jsx(dt,{value:v,children:t(Lr[v])},v)),s.jsx(dt,{value:"custom",children:t("settings.behavior.page.responseStyle.option.custom")})]})]})}),s.jsx(Ns,{value:g,onChange:v=>b(v.target.value),placeholder:t("settings.behavior.page.responseStyle.customPlaceholder"),rows:5,disabled:p||!l||c!=="custom",outerClassName:"min-h-[120px]",className:"w-full font-mono typography-meta bg-transparent"})]})]})},_d=t=>{const e=ht.c(169),{onItemSelect:a}=t,{t:n}=ot(),[i,r]=o.useState(null),[l,x]=o.useState(""),[c,y]=o.useState(null),[m,b]=o.useState(null),[p,L]=o.useState(!1),[k,N]=o.useState(null),{selectedCommandName:h,commands:C,setSelectedCommand:u,setCommandDraft:E,createCommand:q,deleteCommand:M,loadCommands:I}=Qa(Ps(zd)),g=rn(Ud),j=rn(Vd);let F,S;e[0]!==I||e[1]!==j?(F=()=>{I(),j()},S=[I,j],e[0]=I,e[1]=j,e[2]=F,e[3]=S):(F=e[2],S=e[3]),o.useEffect(F,S);let T;e[4]!==g?(T=new Set(g.map($d)),e[4]=g,e[5]=T):T=e[5];const v=T;let K;if(e[6]!==C||e[7]!==v){let ie;e[9]!==v?(ie=Ae=>!v.has(Ae.name),e[9]=v,e[10]=ie):ie=e[10],K=C.filter(ie),e[6]=C,e[7]=v,e[8]=K}else K=e[8];const $=K;let w,G;e[11]!==h||e[12]!==u||e[13]!==v?(w=()=>{h&&v.has(h)&&u(null)},G=[h,u,v],e[11]=h,e[12]=u,e[13]=v,e[14]=w,e[15]=G):(w=e[14],G=e[15]),o.useEffect(w,G);let Q;e[16]!==C||e[17]!==a||e[18]!==E||e[19]!==u?(Q=()=>{let ie="new-command",Ae=1;for(;C.some(Be=>Be.name===ie);)ie=`new-command-${Ae}`,Ae++;E({name:ie,scope:"user"}),u(ie),a?.()},e[16]=C,e[17]=a,e[18]=E,e[19]=u,e[20]=Q):Q=e[20];const X=Q;let Z;e[21]!==n?(Z=async ie=>{if(Hn(ie)){R.error(n("settings.commands.sidebar.toast.builtInCannotDelete"));return}y(ie),b("delete")},e[21]=n,e[22]=Z):Z=e[22];const P=Z;let ee;e[23]===Symbol.for("react.memo_cache_sentinel")?(ee=async ie=>{Hn(ie)&&(y(ie),b("reset"))},e[23]=ee):ee=e[23];const se=ee;let D;e[24]===Symbol.for("react.memo_cache_sentinel")?(D=()=>{y(null),b(null)},e[24]=D):D=e[24];const O=D;let U;e[25]!==c||e[26]!==m||e[27]!==M||e[28]!==n?(U=async()=>{if(!c||!m)return;L(!0),await M(c.name)?(m==="delete"?R.success(n("settings.commands.sidebar.toast.commandDeleted",{name:c.name})):R.success(n("settings.commands.sidebar.toast.commandReset",{name:c.name})),O()):m==="delete"?R.error(n("settings.commands.sidebar.toast.deleteFailed")):R.error(n("settings.commands.sidebar.toast.resetFailed")),L(!1)},e[25]=c,e[26]=m,e[27]=M,e[28]=n,e[29]=U):U=e[29];const A=U;let V;e[30]!==C||e[31]!==E||e[32]!==u?(V=ie=>{const Ae=ie.name;let Be=1,qe=`${Ae}-copy`;for(;C.some(Nt=>Nt.name===qe);)Be++,qe=`${Ae}-copy-${Be}`;E({name:qe,scope:ie.scope||"user",description:ie.description,template:ie.template,agent:ie.agent,model:ie.model}),u(qe)},e[30]=C,e[31]=E,e[32]=u,e[33]=V):V=e[33];const W=V;let te;e[34]===Symbol.for("react.memo_cache_sentinel")?(te=ie=>{x(ie.name),r(ie)},e[34]=te):te=e[34];const ae=te;let le;e[35]!==C||e[36]!==q||e[37]!==M||e[38]!==i||e[39]!==l||e[40]!==u||e[41]!==n?(le=async()=>{if(!i)return;const ie=l.trim().replace(/\s+/g,"-");if(!ie){R.error(n("settings.commands.sidebar.toast.commandNameRequired"));return}if(ie===i.name){r(null);return}if(C.some(Be=>Be.name===ie)){R.error(n("settings.commands.sidebar.toast.commandExists"));return}await q({name:ie,description:i.description,template:i.template,agent:i.agent,model:i.model})?await M(i.name)?(R.success(`Command renamed to "${ie}"`),u(ie)):R.error(n("settings.commands.sidebar.toast.removeOldAfterRenameFailed")):R.error(n("settings.commands.sidebar.toast.renameFailed")),r(null)},e[35]=C,e[36]=q,e[37]=M,e[38]=i,e[39]=l,e[40]=u,e[41]=n,e[42]=le):le=e[42];const be=le;let ke,ce,ge,Ee,Se,Ne;if(e[43]!==$||e[44]!==X||e[45]!==P||e[46]!==W||e[47]!==a||e[48]!==k||e[49]!==h||e[50]!==u||e[51]!==n){const ie=$.filter(Hn),Ae=$.filter(Bd);e[58]===Symbol.for("react.memo_cache_sentinel")?(Se=je("flex h-full flex-col","bg-background"),e[58]=Se):Se=e[58];let Be;e[59]!==n?(Be=n("settings.commands.sidebar.title"),e[59]=n,e[60]=Be):Be=e[60];let qe;e[61]!==Be?(qe=s.jsx("h2",{className:`${qs} mb-3`,children:Be}),e[61]=Be,e[62]=qe):qe=e[62];let Nt;e[63]===Symbol.for("react.memo_cache_sentinel")?(Nt=s.jsx(ka,{className:"mb-3"}),e[63]=Nt):Nt=e[63];let xt;e[64]!==$.length||e[65]!==n?(xt=n("settings.commands.sidebar.total",{count:$.length}),e[64]=$.length,e[65]=n,e[66]=xt):xt=e[66];let zt;e[67]!==xt?(zt=s.jsx("span",{className:"typography-meta text-muted-foreground",children:xt}),e[67]=xt,e[68]=zt):zt=e[68];let J;e[69]===Symbol.for("react.memo_cache_sentinel")?(J=s.jsx(_,{name:"add",className:"h-3.5 w-3.5"}),e[69]=J):J=e[69];let xe;e[70]!==X?(xe=s.jsx(H,{size:"sm","data-settings-item":"commands.create",variant:"ghost",className:"h-7 w-7 px-0 -my-1 text-muted-foreground",onClick:X,children:J}),e[70]=X,e[71]=xe):xe=e[71];let Re;e[72]!==zt||e[73]!==xe?(Re=s.jsxs("div",{className:"flex items-center justify-between gap-2",children:[zt,xe]}),e[72]=zt,e[73]=xe,e[74]=Re):Re=e[74],e[75]!==qe||e[76]!==Re?(Ne=s.jsxs("div",{className:"border-b px-3 pt-4 pb-3",children:[qe,Nt,Re]}),e[75]=qe,e[76]=Re,e[77]=Ne):Ne=e[77],ke=Ds,ce="flex-1 min-h-0",ge="space-y-1 px-3 py-2",Ee=$.length===0?s.jsxs("div",{className:"py-12 px-4 text-center text-muted-foreground",children:[s.jsx(_,{name:"terminal-box",className:"mx-auto mb-3 h-10 w-10 opacity-50"}),s.jsx("p",{className:"typography-ui-label font-medium",children:n("settings.commands.sidebar.empty.title")}),s.jsx("p",{className:"typography-meta mt-1 opacity-75",children:n("settings.commands.sidebar.empty.description")})]}):s.jsxs(s.Fragment,{children:[ie.length>0&&s.jsxs(s.Fragment,{children:[s.jsx("div",{className:"px-2 pb-1.5 pt-2 text-xs font-semibold uppercase tracking-wide text-muted-foreground",children:n("settings.commands.sidebar.section.builtIn")}),[...ie].sort(Hd).map(we=>s.jsx(Fr,{command:we,isSelected:h===we.name,onSelect:()=>{u(we.name),a?.()},onReset:()=>se(we),onDuplicate:()=>W(we),isMenuOpen:k===we.name,onMenuOpenChange:rt=>N(rt?we.name:null)},we.name))]}),Ae.length>0&&s.jsxs(s.Fragment,{children:[s.jsx("div",{className:"px-2 pb-1.5 pt-3 text-xs font-semibold uppercase tracking-wide text-muted-foreground",children:n("settings.commands.sidebar.section.custom")}),[...Ae].sort(Gd).map(we=>s.jsx(Fr,{command:we,isSelected:h===we.name,onSelect:()=>{u(we.name),a?.()},onRename:()=>ae(we),onDelete:()=>P(we),onDuplicate:()=>W(we),isMenuOpen:k===we.name,onMenuOpenChange:rt=>N(rt?we.name:null)},we.name))]})]}),e[43]=$,e[44]=X,e[45]=P,e[46]=W,e[47]=a,e[48]=k,e[49]=h,e[50]=u,e[51]=n,e[52]=ke,e[53]=ce,e[54]=ge,e[55]=Ee,e[56]=Se,e[57]=Ne}else ke=e[52],ce=e[53],ge=e[54],Ee=e[55],Se=e[56],Ne=e[57];let fe;e[78]!==ke||e[79]!==ce||e[80]!==ge||e[81]!==Ee?(fe=s.jsx(ke,{outerClassName:ce,className:ge,children:Ee}),e[78]=ke,e[79]=ce,e[80]=ge,e[81]=Ee,e[82]=fe):fe=e[82];const Ke=c!==null&&m!==null;let De;e[83]!==p?(De=ie=>{!ie&&!p&&O()},e[83]=p,e[84]=De):De=e[84];let he;e[85]!==m||e[86]!==n?(he=n(m==="delete"?"settings.commands.sidebar.dialog.deleteTitle":"settings.commands.sidebar.dialog.resetTitle"),e[85]=m,e[86]=n,e[87]=he):he=e[87];let pe;e[88]!==he?(pe=s.jsx(Gt,{children:he}),e[88]=he,e[89]=pe):pe=e[89];let Ie;e[90]!==c?.name||e[91]!==m||e[92]!==n?(Ie=m==="delete"?n("settings.commands.sidebar.dialog.deleteDescription",{name:c?.name??""}):n("settings.commands.sidebar.dialog.resetDescription",{name:c?.name??""}),e[90]=c?.name,e[91]=m,e[92]=n,e[93]=Ie):Ie=e[93];let ze;e[94]!==Ie?(ze=s.jsx(qt,{children:Ie}),e[94]=Ie,e[95]=ze):ze=e[95];let Je;e[96]!==pe||e[97]!==ze?(Je=s.jsxs(Ht,{children:[pe,ze]}),e[96]=pe,e[97]=ze,e[98]=Je):Je=e[98];let _e;e[99]!==n?(_e=n("settings.common.actions.cancel"),e[99]=n,e[100]=_e):_e=e[100];let Le;e[101]!==p||e[102]!==_e?(Le=s.jsx(H,{size:"sm",variant:"ghost",onClick:O,disabled:p,children:_e}),e[101]=p,e[102]=_e,e[103]=Le):Le=e[103];let Pe;e[104]!==m||e[105]!==n?(Pe=n(m==="delete"?"settings.common.actions.delete":"settings.common.actions.reset"),e[104]=m,e[105]=n,e[106]=Pe):Pe=e[106];let Ye;e[107]!==A||e[108]!==p||e[109]!==Pe?(Ye=s.jsx(H,{size:"sm",onClick:A,disabled:p,children:Pe}),e[107]=A,e[108]=p,e[109]=Pe,e[110]=Ye):Ye=e[110];let Ge;e[111]!==Le||e[112]!==Ye?(Ge=s.jsxs(os,{children:[Le,Ye]}),e[111]=Le,e[112]=Ye,e[113]=Ge):Ge=e[113];let Me;e[114]!==Je||e[115]!==Ge?(Me=s.jsxs(Vt,{className:"max-w-md",children:[Je,Ge]}),e[114]=Je,e[115]=Ge,e[116]=Me):Me=e[116];let $e;e[117]!==Ke||e[118]!==De||e[119]!==Me?($e=s.jsx(Ut,{open:Ke,onOpenChange:De,children:Me}),e[117]=Ke,e[118]=De,e[119]=Me,e[120]=$e):$e=e[120];const Fe=i!==null;let ye;e[121]===Symbol.for("react.memo_cache_sentinel")?(ye=ie=>!ie&&r(null),e[121]=ye):ye=e[121];let z;e[122]!==n?(z=n("settings.commands.sidebar.renameDialog.title"),e[122]=n,e[123]=z):z=e[123];let oe;e[124]!==z?(oe=s.jsx(Gt,{children:z}),e[124]=z,e[125]=oe):oe=e[125];const me=i?.name??"";let ve;e[126]!==n||e[127]!==me?(ve=n("settings.commands.sidebar.renameDialog.description",{name:me}),e[126]=n,e[127]=me,e[128]=ve):ve=e[128];let re;e[129]!==ve?(re=s.jsx(qt,{children:ve}),e[129]=ve,e[130]=re):re=e[130];let Ve;e[131]!==oe||e[132]!==re?(Ve=s.jsxs(Ht,{children:[oe,re]}),e[131]=oe,e[132]=re,e[133]=Ve):Ve=e[133];let Ze;e[134]===Symbol.for("react.memo_cache_sentinel")?(Ze=ie=>x(ie.target.value),e[134]=Ze):Ze=e[134];let B;e[135]!==n?(B=n("settings.commands.sidebar.renameDialog.placeholder"),e[135]=n,e[136]=B):B=e[136];let Ue;e[137]!==be?(Ue=ie=>{ie.key==="Enter"&&be()},e[137]=be,e[138]=Ue):Ue=e[138];let Qe;e[139]!==l||e[140]!==B||e[141]!==Ue?(Qe=s.jsx(He,{value:l,onChange:Ze,placeholder:B,className:"text-foreground placeholder:text-muted-foreground",onKeyDown:Ue}),e[139]=l,e[140]=B,e[141]=Ue,e[142]=Qe):Qe=e[142];let et;e[143]===Symbol.for("react.memo_cache_sentinel")?(et=()=>r(null),e[143]=et):et=e[143];let tt;e[144]!==n?(tt=n("settings.common.actions.cancel"),e[144]=n,e[145]=tt):tt=e[145];let wt;e[146]!==tt?(wt=s.jsx(H,{size:"sm",variant:"ghost",onClick:et,children:tt}),e[146]=tt,e[147]=wt):wt=e[147];let mt;e[148]!==n?(mt=n("settings.common.actions.rename"),e[148]=n,e[149]=mt):mt=e[149];let pt;e[150]!==be||e[151]!==mt?(pt=s.jsx(H,{size:"sm",onClick:be,children:mt}),e[150]=be,e[151]=mt,e[152]=pt):pt=e[152];let at;e[153]!==wt||e[154]!==pt?(at=s.jsxs(os,{children:[wt,pt]}),e[153]=wt,e[154]=pt,e[155]=at):at=e[155];let ft;e[156]!==Ve||e[157]!==Qe||e[158]!==at?(ft=s.jsxs(Vt,{children:[Ve,Qe,at]}),e[156]=Ve,e[157]=Qe,e[158]=at,e[159]=ft):ft=e[159];let gt;e[160]!==Fe||e[161]!==ft?(gt=s.jsx(Ut,{open:Fe,onOpenChange:ye,children:ft}),e[160]=Fe,e[161]=ft,e[162]=gt):gt=e[162];let Ct;return e[163]!==Se||e[164]!==Ne||e[165]!==fe||e[166]!==$e||e[167]!==gt?(Ct=s.jsxs("div",{className:Se,children:[Ne,fe,$e,gt]}),e[163]=Se,e[164]=Ne,e[165]=fe,e[166]=$e,e[167]=gt,e[168]=Ct):Ct=e[168],Ct},Fr=t=>{const e=ht.c(47),{command:a,isSelected:n,onSelect:i,onDelete:r,onReset:l,onRename:x,onDuplicate:c,isMenuOpen:y,onMenuOpenChange:m}=t,{t:b}=ot();let p;e[0]===Symbol.for("react.memo_cache_sentinel")?(p=xa(),e[0]=p):p=e[0];const L=p,[k,N]=o.useState(!1);let h;e[1]!==r||e[2]!==c||e[3]!==x||e[4]!==l||e[5]!==b?(h=Z=>s.jsxs(s.Fragment,{children:[x&&s.jsxs(Z,{onClick:P=>{P.stopPropagation(),x()},children:[s.jsx(_,{name:"edit",className:"h-4 w-4 mr-px"}),b("settings.common.actions.rename")]}),s.jsxs(Z,{onClick:P=>{P.stopPropagation(),c()},children:[s.jsx(_,{name:"file-copy",className:"h-4 w-4 mr-px"}),b("settings.common.actions.duplicate")]}),l&&s.jsxs(Z,{onClick:P=>{P.stopPropagation(),l()},children:[s.jsx(_,{name:"restart",className:"h-4 w-4 mr-px"}),b("settings.common.actions.reset")]}),r&&s.jsxs(Z,{onClick:P=>{P.stopPropagation(),r()},className:"text-destructive focus:text-destructive",children:[s.jsx(_,{name:"delete-bin",className:"h-4 w-4 mr-px"}),b("settings.common.actions.delete")]})]}),e[1]=r,e[2]=c,e[3]=x,e[4]=l,e[5]=b,e[6]=h):h=e[6];const C=h,u=n?"bg-interactive-selection":"hover:bg-interactive-hover";let E;e[7]!==u?(E=je("group relative flex items-center rounded-md px-1.5 py-1 transition-all duration-200 select-none",u),e[7]=u,e[8]=E):E=e[8];let q;e[9]===Symbol.for("react.memo_cache_sentinel")?(q=L?void 0:Z=>{Z.preventDefault(),N(!0)},e[9]=q):q=e[9];let M;e[10]!==E?(M=s.jsx("div",{className:E,onContextMenu:q}),e[10]=E,e[11]=M):M=e[11];let I;e[12]!==a.name?(I=s.jsxs("span",{className:"typography-ui-label font-normal truncate text-foreground",children:["/",a.name]}),e[12]=a.name,e[13]=I):I=e[13];let g;e[14]!==a||e[15]!==b?(g=(a.scope||Hn(a))&&s.jsx("span",{className:"typography-micro text-muted-foreground bg-muted px-1 rounded flex-shrink-0 leading-none pb-px border border-border/50",children:Hn(a)?b("settings.agents.sidebar.badge.system"):a.scope}),e[14]=a,e[15]=b,e[16]=g):g=e[16];let j;e[17]!==I||e[18]!==g?(j=s.jsxs("div",{className:"flex items-center gap-2",children:[I,g]}),e[17]=I,e[18]=g,e[19]=j):j=e[19];let F;e[20]!==a.description?(F=a.description&&s.jsx("div",{className:"typography-micro text-muted-foreground/60 truncate leading-tight",children:a.description}),e[20]=a.description,e[21]=F):F=e[21];let S;e[22]!==i||e[23]!==F||e[24]!==j?(S=s.jsxs("button",{onClick:i,className:"flex min-w-0 flex-1 flex-col gap-0 rounded-sm text-left focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-primary/50",tabIndex:0,children:[j,F]}),e[22]=i,e[23]=F,e[24]=j,e[25]=S):S=e[25];let T;e[26]!==m?(T=Z=>{Z&&N(!1),m(Z)},e[26]=m,e[27]=T):T=e[27];let v;e[28]===Symbol.for("react.memo_cache_sentinel")?(v=s.jsx($s,{asChild:!0,children:s.jsx(H,{size:"sm",variant:"ghost",className:"h-6 w-6 px-0 flex-shrink-0 -mr-1 opacity-100 transition-opacity md:opacity-0 md:group-hover:opacity-100",children:s.jsx(_,{name:"more-2",className:"h-3.5 w-3.5"})})}),e[28]=v):v=e[28];let K;e[29]!==C?(K=s.jsx(Bs,{align:"end",className:"w-fit min-w-20",children:C(Gs)}),e[29]=C,e[30]=K):K=e[30];let $;e[31]!==y||e[32]!==T||e[33]!==K?($=s.jsxs(Hs,{open:y,onOpenChange:T,children:[v,K]}),e[31]=y,e[32]=T,e[33]=K,e[34]=$):$=e[34];let w;e[35]!==S||e[36]!==$?(w=s.jsxs("div",{className:"flex min-w-0 flex-1 items-center",children:[S,$]}),e[35]=S,e[36]=$,e[37]=w):w=e[37];let G;e[38]!==w||e[39]!==M?(G=s.jsx(Rn,{render:M,children:w}),e[38]=w,e[39]=M,e[40]=G):G=e[40];let Q;e[41]!==C?(Q=s.jsx(Dn,{className:"w-fit min-w-20",children:C(Mn)}),e[41]=C,e[42]=Q):Q=e[42];let X;return e[43]!==k||e[44]!==G||e[45]!==Q?(X=s.jsxs(On,{open:k,onOpenChange:N,children:[G,Q]}),e[43]=k,e[44]=G,e[45]=Q,e[46]=X):X=e[46],X};function zd(t){return{selectedCommandName:t.selectedCommandName,commands:t.commands,setSelectedCommand:t.setSelectedCommand,setCommandDraft:t.setCommandDraft,createCommand:t.createCommand,deleteCommand:t.deleteCommand,loadCommands:t.loadCommands}}function Ud(t){return t.skills}function Vd(t){return t.loadSkills}function $d(t){return t.name}function Bd(t){return!Hn(t)}function Hd(t,e){return t.name.localeCompare(e.name)}function Gd(t,e){return t.name.localeCompare(e.name)}const qd=()=>{const{t}=ot(),{selectedCommandName:e,getCommandByName:a,createCommand:n,updateCommand:i,commands:r,commandDraft:l,setCommandDraft:x}=Qa(Ps(T=>({selectedCommandName:T.selectedCommandName,getCommandByName:T.getCommandByName,createCommand:T.createCommand,updateCommand:T.updateCommand,commands:T.commands,commandDraft:T.commandDraft,setCommandDraft:T.setCommandDraft}))),c=e?a(e):null,y=!!(l&&l.name===e&&!c),[m,b]=o.useState(""),[p,L]=o.useState("user"),[k,N]=o.useState(""),[h,C]=o.useState(""),[u,E]=o.useState(""),[q,M]=o.useState(""),[I,g]=o.useState(!1),j=o.useRef(null);o.useEffect(()=>{if(y&&l){const T=l.name||"",v=l.scope||"user",K=l.description||"",$=l.agent||"",w=l.model||"",G=l.template||"";b(T),L(v),N(K),C($),E(w),M(G),j.current={draftName:T,draftScope:v,description:K,agent:$,model:w,template:G}}else if(c){const T=c.description||"",v=c.agent||"",K=c.model||"",$=c.template||"";N(T),C(v),E(K),M($),j.current={draftName:"",draftScope:"user",description:T,agent:v,model:K,template:$}}},[c,y,e,r,l]);const F=o.useMemo(()=>{const T=j.current;return T?!!(y&&(m!==T.draftName||p!==T.draftScope)||k!==T.description||h!==T.agent||u!==T.model||q!==T.template):!1},[h,k,m,p,y,u,q]),S=async()=>{const T=y?m.trim().replace(/\s+/g,"-"):e?.trim();if(!T){R.error(t("settings.commands.sidebar.toast.commandNameRequired"));return}if(!q.trim()){R.error(t("settings.commands.page.toast.templateRequired"));return}if(y&&r.some(v=>v.name===T)){R.error(t("settings.commands.sidebar.toast.commandExists"));return}g(!0);try{const v=h.trim(),K=u.trim(),$=q.trim(),w={name:T,description:k.trim()||void 0,agent:v===""?null:v,model:K===""?null:K,template:$,scope:y?p:void 0};let G;if(y?(G=await n(w),G&&x(null)):G=await i(T,w),G){const Q=Tn.getState().changes.some(X=>X.scope==="commands"&&X.id.startsWith(`commands:${T}:`));R.success(t(Q?"settings.view.pendingRestart.saved":y?"settings.commands.page.toast.created":"settings.commands.page.toast.updated"))}else R.error(t(y?"settings.commands.page.toast.createFailed":"settings.commands.page.toast.updateFailed"))}catch(v){console.error("Error saving command:",v),R.error(t("settings.commands.page.toast.saveUnexpectedError"))}finally{g(!1)}};return e?s.jsxs(rs,{title:y?t("settings.commands.page.title.new"):`/${e}`,description:t(y?"settings.commands.page.subtitle.new":"settings.commands.page.subtitle.edit"),showSaveStatus:!1,children:[s.jsxs(Oe,{title:t("settings.commands.page.section.identity"),divider:!1,contentClassName:"space-y-0",children:[y&&s.jsxs($t,{settingsItem:"commands.name",label:t("settings.commands.page.field.commandName"),children:[s.jsxs("div",{className:"flex items-center",children:[s.jsx("span",{className:"typography-ui-label text-muted-foreground mr-1",children:"/"}),s.jsx(He,{value:m,onChange:T=>b(T.target.value),placeholder:t("settings.commands.page.field.commandNamePlaceholder"),className:"h-7 w-40 px-2"})]}),s.jsxs(Dt,{value:p,onValueChange:T=>L(T),children:[s.jsx(Mt,{size:Kt,className:"w-fit min-w-[100px]",children:s.jsx(_t,{placeholder:t("settings.agents.page.field.scopePlaceholder")})}),s.jsxs(Rt,{align:"end",children:[s.jsx(dt,{value:"user",children:s.jsxs("div",{className:"flex items-center gap-2",children:[s.jsx(_,{name:"user-3",className:"h-3.5 w-3.5"}),s.jsx("span",{children:t("settings.common.scope.global")})]})}),s.jsx(dt,{value:"project",children:s.jsxs("div",{className:"flex items-center gap-2",children:[s.jsx(_,{name:"folder",className:"h-3.5 w-3.5"}),s.jsx("span",{children:t("settings.common.scope.project")})]})})]})]})]}),s.jsxs("div",{className:"py-1.5",children:[s.jsx("span",{className:"typography-ui-label text-foreground",children:t("settings.common.field.description")}),s.jsx("div",{className:"mt-1.5",children:s.jsx(Ns,{value:k,onChange:T=>N(T.target.value),placeholder:t("settings.commands.page.field.descriptionPlaceholder"),rows:2,className:"w-full resize-none min-h-[60px] bg-transparent"})})]})]}),s.jsxs(Oe,{title:t("settings.commands.page.section.executionContext"),contentClassName:"space-y-0",children:[s.jsx($t,{settingsItem:"commands.agent",label:t("settings.commands.page.field.overrideAgent"),children:s.jsx(To,{agentName:h,onChange:T=>C(T),className:bn})}),s.jsx($t,{settingsItem:"commands.model",label:t("settings.agents.page.field.overrideModel"),children:s.jsx(ua,{providerId:Gn(u)?.providerId??"",modelId:Gn(u)?.modelId??"",onChange:(T,v)=>{E(T&&v?`${T}/${v}`:"")},className:bn})})]}),s.jsxs(Oe,{title:t("settings.commands.page.section.template"),settingsItem:"commands.template",children:[s.jsx(Ns,{value:q,onChange:T=>M(T.target.value),placeholder:t("settings.commands.page.field.templatePlaceholder"),rows:12,className:"w-full font-mono typography-meta min-h-[160px] max-h-[60vh] bg-transparent resize-y"}),s.jsxs("p",{className:"mt-2 typography-meta text-muted-foreground",children:[s.jsx("code",{className:"text-foreground",children:"$ARGUMENTS"})," ",t("settings.commands.page.templateHint.userInput")," ·"," ",s.jsx("code",{className:"text-foreground",children:"!`cmd`"})," ",t("settings.commands.page.templateHint.shellOutput")," ·"," ",s.jsx("code",{className:"text-foreground",children:"@file"})," ",t("settings.commands.page.templateHint.fileContents")]}),s.jsx("div",{className:"pt-3",children:s.jsx(H,{onClick:S,disabled:I||!F,size:"xs",className:"!font-normal",children:t(I?"settings.common.actions.saving":"settings.common.actions.saveChanges")})})]})]}):s.jsx("div",{className:"flex h-full items-center justify-center",children:s.jsxs("div",{className:"text-center text-muted-foreground",children:[s.jsx(_,{name:"terminal-box",className:"mx-auto mb-3 h-12 w-12 opacity-50"}),s.jsx("p",{className:"typography-body",children:t("settings.commands.page.empty.title")}),s.jsx("p",{className:"typography-meta mt-1 opacity-75",children:t("settings.commands.page.empty.description")})]})})},Kr=t=>{switch(t){case"connected":return"success";case"failed":return"error";case"needs_auth":case"needs_client_registration":return"warning";default:return"idle"}},_r=t=>{const e=ht.c(5),{tone:a,enabled:n}=t;if(!n){let l;return e[0]===Symbol.for("react.memo_cache_sentinel")?(l=s.jsx("span",{className:"inline-block h-2 w-2 rounded-full bg-muted-foreground/30 flex-shrink-0"}),e[0]=l):l=e[0],l}let i;e[1]!==a?(i=je("inline-block h-2 w-2 rounded-full flex-shrink-0",{success:"bg-[var(--status-success)]",error:"bg-[var(--status-error)]",warning:"bg-[var(--status-warning)]",idle:"bg-muted-foreground/40"}[a]),e[1]=a,e[2]=i):i=e[2];let r;return e[3]!==i?(r=s.jsx("span",{className:i}),e[3]=i,e[4]=r):r=e[4],r},Wd=t=>{const e=ht.c(120),{onItemSelect:a}=t,{t:n}=ot(),{mcpServers:i,selectedMcpName:r,setSelectedMcp:l,setMcpDraft:x,loadMcpConfigs:c,deleteMcp:y}=Ya(Ps(Jd)),m=Ko(Qd);let b;e[0]!==m?(b=re=>re.getStatusForDirectory(m??null),e[0]=m,e[1]=b):b=e[1];const p=Is(b),L=Is(Yd),k=Is(Zd),[N,h]=o.useState(null),[C,u]=o.useState(!1),[E,q]=o.useState(null),[M,I]=o.useState(null),[g,j]=o.useState(!1);let F;e[2]!==i?(F=i.filter(Xd),e[2]=i,e[3]=F):F=e[3];const S=F;let T;e[4]!==i?(T=i.filter(ep),e[4]=i,e[5]=T):T=e[5];const v=T;let K,$;e[6]!==c?(K=()=>{c()},$=[c],e[6]=c,e[7]=K,e[8]=$):(K=e[7],$=e[8]),o.useEffect(K,$);let w;e[9]!==m||e[10]!==k||e[11]!==g||e[12]!==L?(w=()=>{if(g)return;j(!0);const re=new Promise(tp);Promise.all([L({directory:m,silent:!0}),re]).then(()=>{const Ve=k(m);Ve&&R.error(Ve)}).finally(()=>{j(!1)})},e[9]=m,e[10]=k,e[11]=g,e[12]=L,e[13]=w):w=e[13];const G=w;let Q;e[14]!==i||e[15]!==a||e[16]!==x||e[17]!==l?(Q=()=>{let re="new-mcp-server",Ve=1;for(;i.some(B=>B.name===re);)re=`new-mcp-server-${Ve}`,Ve++;x({name:re,scope:"user",type:"local",command:[],url:"",environment:[],headers:[],oauthEnabled:!0,oauthClientId:"",oauthClientSecret:"",oauthScope:"",oauthRedirectUri:"",timeout:"",enabled:!0}),l(re),a?.()},e[14]=i,e[15]=a,e[16]=x,e[17]=l,e[18]=Q):Q=e[18];const X=Q;let Z;e[19]!==y||e[20]!==N||e[21]!==n?(Z=async()=>{if(!N)return;u(!0);const re=await y(N.name);re.ok?re.reloadFailed?R.warning(re.message||`MCP server "${N.name}" deleted, but OpenCode reload failed`,{description:re.warning||n("settings.mcp.sidebar.toast.refreshListIfStale")}):R.success(re.message||n("settings.mcp.sidebar.toast.serverDeleted",{name:N.name})):R.error(n("settings.mcp.sidebar.toast.deleteFailed")),h(null),u(!1)},e[19]=y,e[20]=N,e[21]=n,e[22]=Z):Z=e[22];const P=Z;let ee;e[23]!==n?(ee=(re,Ve)=>s.jsxs(Ve,{onClick:Ze=>{Ze.stopPropagation(),h(re)},className:"text-destructive focus:text-destructive",children:[s.jsx(_,{name:"delete-bin",className:"h-4 w-4 mr-px"}),n("settings.common.actions.delete")]}),e[23]=n,e[24]=ee):ee=e[24];const se=ee;let D;e[25]===Symbol.for("react.memo_cache_sentinel")?(D=je("flex h-full flex-col","bg-background"),e[25]=D):D=e[25];let O;e[26]!==n?(O=n("settings.mcp.sidebar.title"),e[26]=n,e[27]=O):O=e[27];let U;e[28]!==O?(U=s.jsx("h2",{className:qs,children:O}),e[28]=O,e[29]=U):U=e[29];let A;e[30]!==n?(A=n("settings.mcp.sidebar.actions.refreshStatusAria"),e[30]=n,e[31]=A):A=e[31];let V;e[32]!==n?(V=n("settings.mcp.sidebar.actions.refreshStatusTitle"),e[32]=n,e[33]=V):V=e[33];const W=g&&"animate-spin";let te;e[34]!==W?(te=je("h-4 w-4",W),e[34]=W,e[35]=te):te=e[35];let ae;e[36]!==te?(ae=s.jsx(_,{name:"refresh",className:te}),e[36]=te,e[37]=ae):ae=e[37];let le;e[38]!==G||e[39]!==g||e[40]!==A||e[41]!==V||e[42]!==ae?(le=s.jsx("button",{type:"button",className:"inline-flex h-7 w-7 items-center justify-center rounded-md text-muted-foreground transition-colors hover:text-foreground hover:bg-interactive-hover focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-primary",disabled:g,onClick:G,"aria-label":A,title:V,children:ae}),e[38]=G,e[39]=g,e[40]=A,e[41]=V,e[42]=ae,e[43]=le):le=e[43];let be;e[44]!==U||e[45]!==le?(be=s.jsxs("div",{className:"mb-3 flex items-center justify-between gap-3",children:[U,le]}),e[44]=U,e[45]=le,e[46]=be):be=e[46];let ke;e[47]===Symbol.for("react.memo_cache_sentinel")?(ke=s.jsx(ka,{className:"mb-3"}),e[47]=ke):ke=e[47];let ce;e[48]!==i.length||e[49]!==n?(ce=n("settings.mcp.sidebar.total",{count:i.length}),e[48]=i.length,e[49]=n,e[50]=ce):ce=e[50];let ge;e[51]!==ce?(ge=s.jsx("span",{className:"typography-meta text-muted-foreground",children:ce}),e[51]=ce,e[52]=ge):ge=e[52];let Ee;e[53]!==n?(Ee=n("settings.mcp.sidebar.actions.addServerTitle"),e[53]=n,e[54]=Ee):Ee=e[54];let Se;e[55]===Symbol.for("react.memo_cache_sentinel")?(Se=s.jsx(_,{name:"add",className:"h-3.5 w-3.5"}),e[55]=Se):Se=e[55];let Ne;e[56]!==X||e[57]!==Ee?(Ne=s.jsx(H,{size:"sm","data-settings-item":"mcp.create",variant:"ghost",className:"h-7 w-7 px-0 -my-1 text-muted-foreground",onClick:X,title:Ee,children:Se}),e[56]=X,e[57]=Ee,e[58]=Ne):Ne=e[58];let fe;e[59]!==ge||e[60]!==Ne?(fe=s.jsxs("div",{className:"flex items-center justify-between gap-2",children:[ge,Ne]}),e[59]=ge,e[60]=Ne,e[61]=fe):fe=e[61];let Ke;e[62]!==be||e[63]!==fe?(Ke=s.jsxs("div",{className:"border-b px-3 pt-4 pb-3",children:[be,ke,fe]}),e[62]=be,e[63]=fe,e[64]=Ke):Ke=e[64];let De;e[65]!==i.length||e[66]!==p||e[67]!==a||e[68]!==E||e[69]!==S||e[70]!==se||e[71]!==M||e[72]!==r||e[73]!==x||e[74]!==l||e[75]!==n||e[76]!==v?(De=s.jsx(Ds,{outerClassName:"flex-1 min-h-0",className:"space-y-1 px-3 py-2 overflow-x-hidden",children:i.length===0?s.jsxs("div",{className:"py-12 px-4 text-center text-muted-foreground",children:[s.jsx(_,{name:"plug",className:"mx-auto mb-3 h-10 w-10 opacity-50"}),s.jsx("p",{className:"typography-ui-label font-medium",children:n("settings.mcp.sidebar.empty.title")}),s.jsx("p",{className:"typography-meta mt-1 opacity-75",children:n("settings.mcp.sidebar.empty.description")})]}):s.jsxs(s.Fragment,{children:[S.length>0&&s.jsxs(s.Fragment,{children:[s.jsx("div",{className:"px-2 pb-1.5 pt-2 text-xs font-semibold uppercase tracking-wide text-muted-foreground",children:n("settings.mcp.sidebar.group.projectServers")}),S.map(re=>{const Ve=p[re.name],Ze=Kr(Ve?.status),B=r===re.name,Ue=xa();return s.jsxs(On,{open:M===re.name,onOpenChange:Qe=>I(Qe?re.name:null),children:[s.jsxs(Rn,{render:s.jsx("div",{className:je("group relative flex items-center rounded-md px-1.5 py-1 transition-all duration-200 select-none",B?"bg-interactive-selection":"hover:bg-interactive-hover"),onContextMenu:Ue?void 0:Qe=>{Qe.preventDefault(),I(re.name)}}),children:[s.jsxs("button",{onClick:()=>{l(re.name),x(null),a?.()},className:"flex min-w-0 flex-1 flex-col gap-0 rounded-sm text-left focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-primary/50",children:[s.jsxs("div",{className:"flex items-center gap-2",children:[s.jsx(_r,{tone:Ze,enabled:re.enabled}),s.jsx("span",{className:"typography-ui-label font-normal truncate text-foreground",children:re.name}),s.jsx("span",{title:re.type==="local"?n("settings.mcp.sidebar.serverType.localTitle"):n("settings.mcp.sidebar.serverType.remoteTitle"),children:re.type==="local"?s.jsx(_,{name:"server",className:"h-3 w-3 text-muted-foreground/60 flex-shrink-0"}):s.jsx(_,{name:"global",className:"h-3 w-3 text-muted-foreground/60 flex-shrink-0"})})]}),s.jsx("div",{className:"typography-micro text-muted-foreground/60 truncate leading-tight pl-4",children:re.type==="local"?re.command?.join(" ")??"":re.url??""})]}),s.jsxs(Hs,{open:E===re.name,onOpenChange:Qe=>{Qe&&I(null),q(Qe?re.name:null)},children:[s.jsx($s,{asChild:!0,children:s.jsx(H,{size:"xs",variant:"ghost",className:"flex-shrink-0 -mr-1 opacity-100 transition-opacity md:opacity-0 md:group-hover:opacity-100",children:s.jsx(_,{name:"more-2",className:"h-3.5 w-3.5"})})}),s.jsx(Bs,{align:"end",className:"w-fit min-w-20",children:se(re,Gs)})]})]}),s.jsx(Dn,{className:"w-fit min-w-20",children:se(re,Mn)})]},re.name)})]}),v.length>0&&s.jsxs(s.Fragment,{children:[s.jsx("div",{className:"px-2 pb-1.5 pt-2 text-xs font-semibold uppercase tracking-wide text-muted-foreground",children:n("settings.mcp.sidebar.group.userServers")}),v.map(re=>{const Ve=p[re.name],Ze=Kr(Ve?.status),B=r===re.name,Ue=xa();return s.jsxs(On,{open:M===re.name,onOpenChange:Qe=>I(Qe?re.name:null),children:[s.jsxs(Rn,{render:s.jsx("div",{className:je("group relative flex items-center rounded-md px-1.5 py-1 transition-all duration-200 select-none",B?"bg-interactive-selection":"hover:bg-interactive-hover"),onContextMenu:Ue?void 0:Qe=>{Qe.preventDefault(),I(re.name)}}),children:[s.jsxs("button",{onClick:()=>{l(re.name),x(null),a?.()},className:"flex min-w-0 flex-1 flex-col gap-0 rounded-sm text-left focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-primary/50",children:[s.jsxs("div",{className:"flex items-center gap-2",children:[s.jsx(_r,{tone:Ze,enabled:re.enabled}),s.jsx("span",{className:"typography-ui-label font-normal truncate text-foreground",children:re.name}),s.jsx("span",{title:re.type==="local"?n("settings.mcp.sidebar.serverType.localTitle"):n("settings.mcp.sidebar.serverType.remoteTitle"),children:re.type==="local"?s.jsx(_,{name:"server",className:"h-3 w-3 text-muted-foreground/60 flex-shrink-0"}):s.jsx(_,{name:"global",className:"h-3 w-3 text-muted-foreground/60 flex-shrink-0"})})]}),s.jsx("div",{className:"typography-micro text-muted-foreground/60 truncate leading-tight pl-4",children:re.type==="local"?re.command?.join(" ")??"":re.url??""})]}),s.jsxs(Hs,{open:E===re.name,onOpenChange:Qe=>{Qe&&I(null),q(Qe?re.name:null)},children:[s.jsx($s,{asChild:!0,children:s.jsx(H,{size:"xs",variant:"ghost",className:"flex-shrink-0 -mr-1 opacity-100 transition-opacity md:opacity-0 md:group-hover:opacity-100",children:s.jsx(_,{name:"more-2",className:"h-3.5 w-3.5"})})}),s.jsx(Bs,{align:"end",className:"w-fit min-w-20",children:se(re,Gs)})]})]}),s.jsx(Dn,{className:"w-fit min-w-20",children:se(re,Mn)})]},re.name)})]})]})}),e[65]=i.length,e[66]=p,e[67]=a,e[68]=E,e[69]=S,e[70]=se,e[71]=M,e[72]=r,e[73]=x,e[74]=l,e[75]=n,e[76]=v,e[77]=De):De=e[77];const he=N!==null;let pe;e[78]!==C?(pe=re=>{!re&&!C&&h(null)},e[78]=C,e[79]=pe):pe=e[79];let Ie;e[80]!==n?(Ie=n("settings.mcp.sidebar.deleteDialog.title"),e[80]=n,e[81]=Ie):Ie=e[81];let ze;e[82]!==Ie?(ze=s.jsx(Gt,{children:Ie}),e[82]=Ie,e[83]=ze):ze=e[83];const Je=N?.name||"";let _e;e[84]!==n||e[85]!==Je?(_e=n("settings.mcp.sidebar.deleteDialog.descriptionPrefix",{name:Je}),e[84]=n,e[85]=Je,e[86]=_e):_e=e[86];let Le;e[87]===Symbol.for("react.memo_cache_sentinel")?(Le=s.jsx("code",{className:"text-foreground",children:"opencode.json"}),e[87]=Le):Le=e[87];let Pe;e[88]!==_e?(Pe=s.jsxs(qt,{children:[_e," ",Le,"."]}),e[88]=_e,e[89]=Pe):Pe=e[89];let Ye;e[90]!==ze||e[91]!==Pe?(Ye=s.jsxs(Ht,{children:[ze,Pe]}),e[90]=ze,e[91]=Pe,e[92]=Ye):Ye=e[92];let Ge;e[93]===Symbol.for("react.memo_cache_sentinel")?(Ge=()=>h(null),e[93]=Ge):Ge=e[93];let Me;e[94]!==n?(Me=n("settings.common.actions.cancel"),e[94]=n,e[95]=Me):Me=e[95];let $e;e[96]!==C||e[97]!==Me?($e=s.jsx(H,{size:"sm",variant:"ghost",onClick:Ge,disabled:C,children:Me}),e[96]=C,e[97]=Me,e[98]=$e):$e=e[98];let Fe;e[99]!==C||e[100]!==n?(Fe=n(C?"settings.mcp.sidebar.actions.deleting":"settings.common.actions.delete"),e[99]=C,e[100]=n,e[101]=Fe):Fe=e[101];let ye;e[102]!==P||e[103]!==C||e[104]!==Fe?(ye=s.jsx(H,{size:"sm",onClick:P,disabled:C,children:Fe}),e[102]=P,e[103]=C,e[104]=Fe,e[105]=ye):ye=e[105];let z;e[106]!==$e||e[107]!==ye?(z=s.jsxs(os,{children:[$e,ye]}),e[106]=$e,e[107]=ye,e[108]=z):z=e[108];let oe;e[109]!==Ye||e[110]!==z?(oe=s.jsxs(Vt,{className:"max-w-md",children:[Ye,z]}),e[109]=Ye,e[110]=z,e[111]=oe):oe=e[111];let me;e[112]!==he||e[113]!==pe||e[114]!==oe?(me=s.jsx(Ut,{open:he,onOpenChange:pe,children:oe}),e[112]=he,e[113]=pe,e[114]=oe,e[115]=me):me=e[115];let ve;return e[116]!==Ke||e[117]!==De||e[118]!==me?(ve=s.jsxs("div",{className:D,children:[Ke,De,me]}),e[116]=Ke,e[117]=De,e[118]=me,e[119]=ve):ve=e[119],ve};function Jd(t){return{mcpServers:t.mcpServers,selectedMcpName:t.selectedMcpName,setSelectedMcp:t.setSelectedMcp,setMcpDraft:t.setMcpDraft,loadMcpConfigs:t.loadMcpConfigs,deleteMcp:t.deleteMcp}}function Qd(t){return t.currentDirectory}function Yd(t){return t.refresh}function Zd(t){return t.getErrorForDirectory}function Xd(t){return t.scope==="project"}function ep(t){return t.scope!=="project"}function tp(t){return setTimeout(t,500)}function Us(t){return typeof t=="object"&&t!==null&&!Array.isArray(t)}function aa(t){return Array.isArray(t)&&t.every(e=>typeof e=="string")}function zs(t,e){return e!==void 0?{ok:!1,error:t,parsed:e}:{ok:!1,error:t}}function La(t,e,a){const n=sp(a),i=typeof a.url=="string"?a.url.trim():"",r=zr(a,"env","environment"),l=zr(a,"headers"),x=np(a),c=typeof a.oauth=="object"&&a.oauth!==null?String(a.oauth.clientId??"").trim():"",y=typeof a.oauth=="object"&&a.oauth!==null?String(a.oauth.clientSecret??"").trim():"",m=typeof a.oauth=="object"&&a.oauth!==null?String(a.oauth.scope??"").trim():"",b=typeof a.oauth=="object"&&a.oauth!==null?String(a.oauth.redirectUri??"").trim():"",p=ap(a),L=ip(a);return{ok:!0,name:t,type:e,command:n,url:i,environment:r,headers:l,oauthEnabled:x,oauthClientId:c,oauthClientSecret:y,oauthScope:m,oauthRedirectUri:b,timeout:p,enabled:L}}function sp(t){const e=t.command,a=t.args;if(aa(e)&&aa(a))return[...e,...a];if(aa(e))return e;if(typeof e=="string"&&e.trim()){const n=e.trim().split(/\s+/);return aa(a)?[...n,...a]:n}return aa(a)?a:[]}function zr(t,...e){for(const a of e){const n=t[a];if(!Us(n))continue;const i=Object.entries(n).filter(([r,l])=>r&&typeof l=="string");if(i.length>0)return i.map(([r,l])=>({key:r,value:String(l)}))}return[]}function np(t){if(t.oauth===!1||t.oauth===null||t.oauth===void 0||!Us(t.oauth))return!1;const e=t.oauth;return!!(typeof e.clientId=="string"&&e.clientId.trim()||typeof e.clientSecret=="string"&&e.clientSecret.trim()||typeof e.scope=="string"&&e.scope.trim()||typeof e.redirectUri=="string"&&e.redirectUri.trim())}function ap(t){const e=t.timeout;if(typeof e=="number"&&Number.isFinite(e)&&e>0)return String(Math.floor(e));if(typeof e=="string"&&e.trim()){const a=Number(e);if(Number.isFinite(a)&&a>0)return String(Math.floor(a))}return""}function ip(t){return"disabled"in t&&t.disabled===!0?!1:"enabled"in t?!!t.enabled:!0}function rp(t){const e=t.mcpServers;if(Us(e)){const n=Object.keys(e);if(n.length===1){const i=n[0],r=e[i];if(Us(r))return{name:i,entry:r}}if(n.length>1)return null}const a=Object.keys(t).filter(n=>{const i=t[n];return n!=="mcpServers"&&Us(i)});if(a.length===1){const n=a[0],i=t[n];if(Qo(i))return{name:n,entry:i}}return null}function Qo(t){return t.type==="local"||t.type==="remote"||Array.isArray(t.command)||typeof t.url=="string"||Array.isArray(t.args)}function op(t,e){let a;try{const x=t.trim();if(!x)return zs("No JSON content provided");a=JSON.parse(x)}catch(x){return zs(x instanceof Error?`Invalid JSON: ${x.message}`:"Invalid JSON")}if(!Us(a))return zs("Expected a JSON object, not an array or primitive");const n=a,i=n.mcpServers;if(Us(i)){const x=Object.keys(i);if(x.length===0)return zs("mcpServers object is empty",a);if(x.length>1)return zs("Paste one server at a time. Found "+x.length+" servers in mcpServers",a);const c=x[0],y=i[c];return Us(y)?La(c,Fa(y),y):zs("Server entry is not a valid object",a)}const r=n.mcp;if(Us(r)){const x=Object.keys(r);if(x.length===0)return zs("mcp object is empty",a);if(x.length>1)return zs("Paste one server at a time. Found "+x.length+" servers in mcp",a);const c=x[0],y=r[c];return Us(y)?La(c,Fa(y),y):zs("Server entry in mcp is not a valid object",a)}const l=rp(n);if(l)return La(l.name,Fa(l.entry),l.entry);if(Qo(n)){const x=Fa(n),c=typeof n.name=="string"&&n.name.trim()?n.name.trim():e?.fallbackName;return La(c,x,n)}return zs("No recognizable MCP server configuration found in JSON",a)}function Fa(t){return t.type==="remote"?"remote":t.type==="local"?"local":typeof t.url=="string"&&t.url.trim()?"remote":(Array.isArray(t.command)||typeof t.command=="string"||Array.isArray(t.args),"local")}function lp(t,e,a){const n=a?.isNewServer??!1,i=t.name,r=n&&i?i:e.name??"";return{...e,name:r,type:t.type,command:t.type==="local"?t.command:[],url:t.type==="remote"?t.url:"",environment:t.environment,headers:t.type==="remote"?t.headers:[],oauthEnabled:t.type==="remote"?t.oauthEnabled:!1,oauthClientId:t.type==="remote"?t.oauthClientId:"",oauthClientSecret:t.type==="remote"?t.oauthClientSecret:"",oauthScope:t.type==="remote"?t.oauthScope:"",oauthRedirectUri:t.type==="remote"?t.oauthRedirectUri:"",timeout:t.type==="remote"?t.timeout:"",enabled:t.enabled}}function Yo(t){const e=[];let a="",n=!1,i=!1;for(let r=0;r<t.length;r++){const l=t[r];if(l==="'"&&!i){n=!n;continue}if(l==='"'&&!n){i=!i;continue}if((l===" "||l===" ")&&!n&&!i){a&&(e.push(a),a="");continue}a+=l}return a&&e.push(a),e}function cp(t){const e=t.trim();if(!e)return{code:null,context:null,stateKey:null};try{const a=new URL(e),n=a.searchParams.get("code");if(typeof n=="string"&&n.trim())return{code:n.trim(),context:Fl(a.searchParams),stateKey:Eo(a.searchParams)}}catch{}return{code:e,context:null,stateKey:null}}const dp=t=>{const e=ht.c(27),{value:a,onChange:n,preview:i,onDetectUrl:r}=t;let l;e[0]!==a?(l=()=>a.join(`
4
+ `),e[0]=a,e[1]=l):l=e[1];const[x,c]=o.useState(l),y=o.useRef(a);let m,b;e[2]!==a?(m=()=>{JSON.stringify(y.current)!==JSON.stringify(a)&&(y.current=a,c(a.join(`
5
+ `)))},b=[a],e[2]=a,e[3]=m,e[4]=b):(m=e[3],b=e[4]),o.useEffect(m,b);let p;e[5]!==n||e[6]!==r?(p=I=>{const g=I.split(`
6
+ `).filter(bp);if(r&&g.length===1&&/^https?:\/\/\S+$/i.test(g[0].trim())){r(g[0].trim());return}n(g)},e[5]=n,e[6]=r,e[7]=p):p=e[7];const L=p;let k;e[8]!==n?(k=I=>{const j=I.clipboardData.getData("text").trim();if(!j||j.includes(`
7
+ `)||!/\s/.test(j))return;const F=I.currentTarget;if(F.selectionStart!==0||F.selectionEnd!==F.value.length)return;I.preventDefault();const S=Yo(j);c(S.join(`
8
+ `)),n(S)},e[8]=n,e[9]=k):k=e[9];const N=k;let h;e[10]!==L?(h=I=>{c(I.target.value),L(I.target.value)},e[10]=L,e[11]=h):h=e[11];let C;e[12]!==L||e[13]!==x?(C=()=>{const I=x.split(`
9
+ `).map(vp).join(`
10
+ `);c(I),L(I)},e[12]=L,e[13]=x,e[14]=C):C=e[14];const u=Math.max(4,a.length+1);let E;e[15]!==N||e[16]!==h||e[17]!==C||e[18]!==u||e[19]!==x?(E=s.jsx(Ns,{onPaste:N,value:x,onChange:h,onBlur:C,placeholder:`npx
11
+ -y
12
+ @modelcontextprotocol/server-postgres
13
+ postgresql://user:pass@host/db`,rows:u,className:"font-mono typography-meta min-h-[80px]",spellCheck:!1}),e[15]=N,e[16]=h,e[17]=C,e[18]=u,e[19]=x,e[20]=E):E=e[20];let q;e[21]!==i||e[22]!==a?(q=a.length>0&&s.jsxs("details",{className:"group",children:[s.jsx("summary",{className:"typography-micro text-muted-foreground/60 cursor-pointer select-none hover:text-muted-foreground",children:i(a.length)}),s.jsx("div",{className:"mt-1 rounded-md bg-[var(--surface-elevated)] px-3 py-2 overflow-x-auto",children:s.jsx("code",{className:"typography-micro text-foreground/80 whitespace-pre",children:a.map(yp)})})]}),e[21]=i,e[22]=a,e[23]=q):q=e[23];let M;return e[24]!==q||e[25]!==E?(M=s.jsxs("div",{className:"space-y-2","data-bwignore":"true","data-1p-ignore":"true","data-lpignore":"true",children:[E,q]}),e[24]=q,e[25]=E,e[26]=M):M=e[26],M},pp=t=>t.toUpperCase().replace(/[^A-Z0-9_]/g,"_"),Ur=({value:t,onChange:e,keyTransform:a=pp,keyPlaceholder:n="API_KEY",keyInputClassName:i="w-36 shrink-0 font-mono typography-meta uppercase",pasteLabel:r="Paste .env",pasteTitle:l="Paste KEY=VALUE lines from clipboard",noPairsFoundError:x,importSuccess:c,clipboardReadFailed:y,keyLabel:m,valueLabel:b,valuePlaceholder:p,hideValueTitle:L,showValueTitle:k,addVariable:N,plainTextWarning:h,removeVariableAria:C})=>{const[u,E]=o.useState(new Set),q=()=>e([...t,{key:"",value:""}]),M=S=>{e(t.filter((T,v)=>v!==S)),E(T=>{const v=new Set(T);return v.delete(S),v})},I=(S,T,v)=>{const K=[...t];K[S]={...K[S],[T]:v},e(K)},g=S=>{E(T=>{const v=new Set(T);return v.has(S)?v.delete(S):v.add(S),v})},j=async()=>{try{const S=await navigator.clipboard.readText(),T=[];for(const K of S.split(`
14
+ `)){const $=K.trim();if(!$||$.startsWith("#"))continue;const w=$.indexOf("=");if(w===-1)continue;const G=$.slice(0,w).trim();let Q=$.slice(w+1).trim();(Q.startsWith('"')&&Q.endsWith('"')||Q.startsWith("'")&&Q.endsWith("'"))&&(Q=Q.slice(1,-1)),G&&T.push({key:G,value:Q})}if(T.length===0){R.error(x);return}const v=[...t];for(const K of T){const $=v.findIndex(w=>w.key===K.key);$!==-1?v[$]=K:v.push(K)}e(v),R.success(c(T.length))}catch{R.error(y)}},F=t.some(S=>S.value.length>0);return s.jsxs("div",{className:"space-y-2",children:[s.jsxs("div",{className:"flex items-center justify-between gap-2",children:[s.jsxs("div",{className:"flex items-center gap-3",children:[s.jsx("span",{className:"typography-micro text-muted-foreground w-32 shrink-0",children:m}),s.jsx("span",{className:"typography-micro text-muted-foreground",children:b})]}),s.jsxs(H,{variant:"ghost",size:"xs",className:"!font-normal gap-1 text-muted-foreground",onClick:j,type:"button",title:l,children:[s.jsx(_,{name:"clipboard",className:"h-3 w-3"}),r]})]}),s.jsx("div",{className:"space-y-1.5",children:t.map((S,T)=>s.jsxs("div",{className:"flex items-center gap-2",children:[s.jsx(He,{value:S.key,onChange:v=>I(T,"key",a(v.target.value)),placeholder:n,className:i,"data-bwignore":"true","data-1p-ignore":"true","data-lpignore":"true",spellCheck:!1}),s.jsxs("div",{className:"relative flex-1 flex items-center",children:[s.jsx(He,{type:u.has(T)?"text":"password",value:S.value,onChange:v=>I(T,"value",v.target.value),placeholder:p,className:"font-mono typography-meta pr-8 w-full",autoComplete:"new-password","data-bwignore":"true","data-1p-ignore":"true","data-lpignore":"true",spellCheck:!1}),s.jsx("button",{type:"button",onClick:()=>g(T),className:"absolute right-2 text-muted-foreground/60 hover:text-muted-foreground",title:u.has(T)?L:k,children:u.has(T)?s.jsx(_,{name:"eye-off",className:"h-3.5 w-3.5"}):s.jsx(_,{name:"eye",className:"h-3.5 w-3.5"})})]}),s.jsx(H,{size:"sm",variant:"ghost",className:"h-7 w-7 px-0 shrink-0 text-muted-foreground hover:text-[var(--status-error)]",onClick:()=>M(T),"aria-label":C,children:s.jsx(_,{name:"delete-bin",className:"h-3.5 w-3.5"})})]},T))}),s.jsxs(H,{variant:"outline",size:"xs",className:"!font-normal gap-1.5",onClick:q,type:"button",children:[s.jsx(_,{name:"add",className:"h-3.5 w-3.5"}),N]}),F&&s.jsx("p",{className:"typography-micro text-muted-foreground/60",children:h})]})},ji=t=>{const e=ht.c(14),{status:a,enabled:n,getStatusLabel:i,variant:r}=t,l=r===void 0?"compact":r;if(!n||!a)return null;let x,c;if(e[0]!==i||e[1]!==a||e[2]!==l){c=Symbol.for("react.early_return_sentinel");e:{const p={connected:{text:"text-[var(--status-success)]",bg:"bg-[var(--status-success)]/10"},failed:{text:"text-[var(--status-error)]",bg:"bg-[var(--status-error)]/10"},needs_auth:{text:"text-[var(--status-warning)]",bg:"bg-[var(--status-warning)]/10"},needs_client_registration:{text:"text-[var(--status-warning)]",bg:"bg-[var(--status-warning)]/10"},awaiting_restart:{text:"text-[var(--status-warning)]",bg:"bg-[var(--status-warning)]/10"}}[a]??{text:"text-muted-foreground",bg:""};if(l==="pill"){const L=je("typography-micro font-medium rounded-full px-2 py-0.5",p.text,p.bg);let k;e[5]!==i||e[6]!==a?(k=i(a),e[5]=i,e[6]=a,e[7]=k):k=e[7],c=s.jsxs("span",{className:L,children:["● ",k]});break e}x=je("typography-micro font-medium",p.text)}e[0]=i,e[1]=a,e[2]=l,e[3]=x,e[4]=c}else x=e[3],c=e[4];if(c!==Symbol.for("react.early_return_sentinel"))return c;let y;e[8]!==i||e[9]!==a?(y=i(a),e[8]=i,e[9]=a,e[10]=y):y=e[10];let m;return e[11]!==x||e[12]!==y?(m=s.jsxs("span",{className:x,children:["● ",y]}),e[11]=x,e[12]=y,e[13]=m):m=e[13],m},mp=(t,e,a)=>{switch(t){case"connected":return e("settings.mcp.page.status.description.connected");case"failed":return a?.trim()||e("settings.mcp.page.status.description.failedDefault");case"needs_auth":return e("settings.mcp.page.status.description.needsAuth");case"needs_client_registration":return a?.trim()||e("settings.mcp.page.status.description.needsClientRegistrationDefault");case"disabled":return e("settings.mcp.page.status.description.disabled");default:return e("settings.mcp.page.status.description.default")}},up=t=>{switch(t){case"failed":return"border-[var(--status-error-border)] bg-[var(--status-error-background)]";case"needs_auth":case"needs_client_registration":return"border-[var(--status-warning-border)] bg-[var(--status-warning-background)]";default:return"border-[var(--interactive-border)] bg-[var(--surface-elevated)]"}},gp=(t,e,a,n)=>!!(t==="failed"||t==="needs_auth"||t==="needs_client_registration"||e||a||n),hp=async t=>{const e=await ct(`/api/mcp/auth/pending?state=${encodeURIComponent(t)}`);if(!e.ok)return null;const a=await e.json().catch(()=>null);return a?.name?.trim()?{name:a.name.trim(),directory:typeof a.directory=="string"&&a.directory.trim()?a.directory.trim():null}:null},ia=async t=>{typeof t!="string"||!t.trim()||await ct(`/api/mcp/auth/pending?state=${encodeURIComponent(t.trim())}`,{method:"DELETE"}).catch(()=>{})},Ka=(t,e,a)=>{const n=t instanceof Error?t.message:e;return/oauth state required/i.test(n)?a("settings.mcp.page.toast.authSessionExpired"):n},fp=(t,e)=>{const a=typeof e=="string"&&e.trim()?e.trim():"__global__";return`${t??"__none__"}::${a}`},xp=()=>{const{t}=ot(),e=o.useCallback((Y,Ce)=>t(Y,Ce),[t]),{selectedMcpName:a,mcpServers:n,mcpDraft:i,setMcpDraft:r,setSelectedMcp:l,getMcpByName:x,createMcp:c,updateMcp:y,deleteMcp:m}=Ya(Ps(Y=>({selectedMcpName:Y.selectedMcpName,mcpServers:Y.mcpServers,mcpDraft:Y.mcpDraft,setMcpDraft:Y.setMcpDraft,setSelectedMcp:Y.setSelectedMcp,getMcpByName:Y.getMcpByName,createMcp:Y.createMcp,updateMcp:Y.updateMcp,deleteMcp:Y.deleteMcp}))),b=Ko(Y=>Y.currentDirectory),p=o.useMemo(()=>ds(),[]),L=Is(Y=>Y.getStatusForDirectory(b??null)),k=Is(Y=>Y.getDiagnosticForDirectory(b??null)),N=Is(Y=>Y.refresh),h=Is(Y=>Y.connect),C=Is(Y=>Y.disconnect),u=Is(Y=>Y.completeAuth),E=Is(Y=>Y.clearAuth),q=Is(Y=>Y.testConnection),M=Tn(Y=>Y.changes),I=a?x(a):null,g=!!(i&&i.name===a&&!I),[j,F]=o.useState(""),[S,T]=o.useState("user"),[v,K]=o.useState("local"),[$,w]=o.useState([]),[G,Q]=o.useState(""),[X,Z]=o.useState([]),[P,ee]=o.useState([]),[se,D]=o.useState(!0),[O,U]=o.useState(""),[A,V]=o.useState(""),[W,te]=o.useState(""),[ae,le]=o.useState(""),[be,ke]=o.useState(""),[ce,ge]=o.useState(!0),[Ee,Se]=o.useState(!1),[Ne,fe]=o.useState(!1),[Ke,De]=o.useState(!1),[he,pe]=o.useState(!1),[Ie,ze]=o.useState(!1),[Je,_e]=o.useState(!1),[Le,Pe]=o.useState(!1),[Ye,Ge]=o.useState(!1),[Me,$e]=o.useState(null),[Fe,ye]=o.useState(null),[z,oe]=o.useState(""),[me,ve]=o.useState(!1),re=o.useRef(0),Ve=o.useRef(!1),[Ze,B]=o.useState(!1),[Ue,Qe]=o.useState(!1),[et,tt]=o.useState(""),[wt,mt]=o.useState(null),pt=o.useMemo(()=>fp(a,b),[b,a]),at=o.useRef(pt),ft=o.useRef(null),gt=o.useCallback(()=>{$e(null),ye(null),oe(""),ve(!1),re.current=0,Ge(!1),ze(!1),_e(!1),Ve.current=!1},[]),Ct=o.useCallback(()=>{tt(""),mt(null),Qe(!0)},[]),ie=o.useCallback(async()=>{try{const Y=await navigator.clipboard.readText();tt(Y),mt(null)}catch{R.error(t("settings.mcp.page.toast.clipboardReadFailed"))}},[t]),Ae=o.useCallback(()=>{const Y=op(et,{fallbackName:j});if(!Y.ok){mt(Y.error);return}const st=lp(Y,{name:j,scope:S,type:v,command:$,url:G,environment:X,headers:P,oauthEnabled:se,oauthClientId:O,oauthClientSecret:A,oauthScope:W,oauthRedirectUri:ae,timeout:be,enabled:ce},{isNewServer:g});F(st.name),K(st.type),w(st.command??[]),Q(st.url??""),Z(st.environment??[]),ee(st.headers??[]),D(st.oauthEnabled??!1),U(st.oauthClientId??""),V(st.oauthClientSecret??""),te(st.oauthScope??""),le(st.oauthRedirectUri??""),ke(st.timeout??""),ge(st.enabled??!0),Qe(!1),tt(""),mt(null),R.success(t("settings.mcp.page.toast.configImported"))},[et,j,S,v,$,G,X,P,se,O,A,W,ae,be,ce,g,t]);o.useEffect(()=>{if(g&&i){F(i.name),T(i.scope||"user"),K(i.type),w(i.command),Q(i.url),Z(i.environment),ee(i.headers),D(i.oauthEnabled),U(i.oauthClientId),V(i.oauthClientSecret),te(i.oauthScope),le(i.oauthRedirectUri),ke(i.timeout),ge(i.enabled),B(!1),ft.current={mcpType:i.type,command:i.command,url:i.url,envEntries:i.environment,headerEntries:i.headers,oauthEnabled:i.oauthEnabled,oauthClientId:i.oauthClientId,oauthClientSecret:i.oauthClientSecret,oauthScope:i.oauthScope,oauthRedirectUri:i.oauthRedirectUri,timeout:i.timeout,enabled:i.enabled};return}if(I){T(I.scope==="project"?"project":"user");const Y=rr(I.environment),Ce=I.type==="remote"?I:null,st=rr(Ce?.headers),At=Ce?.oauth,jt=At&&typeof At=="object"?At:null,Jt=At!==!1,fs=I.type,cs=fs==="local"?I.command??[]:[],Ts=fs==="remote"?I.url??"":"",Ws=typeof Ce?.timeout=="number"&&Number.isFinite(Ce.timeout)?String(Ce.timeout):"";K(fs),w(cs),Q(Ts),Z(Y),ee(st),D(Jt),U(Jt?jt?.clientId??"":""),V(Jt?jt?.clientSecret??"":""),te(Jt?jt?.scope??"":""),le(Jt?jt?.redirectUri??"":""),ke(Ws),ge(I.enabled),B(!1),ft.current={mcpType:fs,command:cs,url:Ts,envEntries:Y,headerEntries:st,oauthEnabled:Jt,oauthClientId:Jt?jt?.clientId??"":"",oauthClientSecret:Jt?jt?.clientSecret??"":"",oauthScope:Jt?jt?.scope??"":"",oauthRedirectUri:Jt?jt?.redirectUri??"":"",timeout:Ws,enabled:I.enabled}}},[I,g,i]);const Be=o.useMemo(()=>{const Y=ft.current;return Y?v!==Y.mcpType||ce!==Y.enabled||JSON.stringify($)!==JSON.stringify(Y.command)||G!==Y.url||JSON.stringify(X)!==JSON.stringify(Y.envEntries)||JSON.stringify(P)!==JSON.stringify(Y.headerEntries)||se!==Y.oauthEnabled||O!==Y.oauthClientId||A!==Y.oauthClientSecret||W!==Y.oauthScope||ae!==Y.oauthRedirectUri||be!==Y.timeout:!1},[v,$,G,X,P,se,O,A,W,ae,be,ce]),qe=o.useMemo(()=>[{id:"local",label:t("settings.mcp.page.connection.kindCommand"),icon:s.jsx(_,{name:"terminal",className:"h-3.5 w-3.5"})},{id:"remote",label:t("settings.mcp.page.connection.kindLink"),icon:s.jsx(_,{name:"global",className:"h-3.5 w-3.5"})}],[t]),Nt=o.useCallback(Y=>{K("remote"),Q(Y),w([])},[]),xt=o.useCallback(Y=>{Q(Y);const Ce=Y.trim();Ce&&!/^[a-z][a-z0-9+.-]*:\/\//i.test(Ce)&&/\s/.test(Ce)&&(K("local"),w(Yo(Ce)),Q(""))},[]),zt=async()=>{const Y=g?j.trim():a??"";if(!Y){R.error(t("settings.mcp.page.toast.nameRequired"));return}if(g&&n.some(st=>st.name===Y)){R.error(t("settings.mcp.page.toast.serverNameExists"));return}if(v==="local"&&$.filter(Boolean).length===0){R.error(t("settings.mcp.page.toast.localCommandRequired"));return}if(v==="remote"&&!G.trim()){R.error(t("settings.mcp.page.toast.remoteUrlRequired"));return}const Ce={name:Y,scope:S,type:v,command:$,url:G,environment:X,headers:P,oauthEnabled:se,oauthClientId:O,oauthClientSecret:A,oauthScope:W,oauthRedirectUri:ae,timeout:be,enabled:ce};Se(!0);try{const st=g?await c(Ce):await y(Y,Ce);st.ok?(await ia(Fe),gt(),g&&(r(null),l(Y)),await N({directory:b,silent:!0}),st.reloadFailed?R.warning(st.message||t(g?"settings.mcp.page.toast.serverCreatedReloadFailed":"settings.mcp.page.toast.savedReloadFailed"),{description:st.warning||t("settings.mcp.page.toast.retryRefreshHint")}):st.restartDeferred?R.success(t("settings.view.pendingRestart.saved")):R.success(st.message||t(g?"settings.mcp.page.toast.serverCreatedReloading":"settings.mcp.page.toast.savedReloading"))):R.error(t("settings.mcp.page.toast.saveFailed"))}catch(st){R.error(st instanceof Error?st.message:t("settings.mcp.page.toast.unexpectedError"))}finally{Se(!1)}},J=async()=>{if(!a)return;De(!0);const Y=await m(a);Y.ok?(await ia(Fe),gt(),Y.reloadFailed?R.warning(Y.message||t("settings.mcp.page.toast.serverDeletedReloadFailed",{name:a}),{description:Y.warning||t("settings.mcp.page.toast.refreshListIfStale")}):R.success(Y.message||t("settings.mcp.page.toast.serverDeleted",{name:a})),fe(!1)):R.error(t("settings.mcp.page.toast.deleteFailed")),De(!1)},xe=async()=>{if(a){pe(!0);try{if(L[a]?.status==="connected")await C(a,b),R.success(t("settings.mcp.page.toast.disconnected"));else{await h(a,b),await N({directory:b,silent:!0});const Ce=Is.getState().getStatusForDirectory(b??null)[a];Ce?.status==="connected"?R.success(t("settings.mcp.page.toast.connected")):Ce?.status==="needs_auth"?R.message(t("settings.mcp.page.toast.connectionNeedsAuthorization")):Ce?.status==="needs_client_registration"?R.message(t("settings.mcp.page.toast.connectionNeedsClientRegistration")):Ce?.status==="failed"?R.error(Ce.error||t("settings.mcp.page.toast.connectionFailed")):R.message(t("settings.mcp.page.toast.connectionAttemptFinished"));return}await N({directory:b,silent:!0})}catch(Y){R.error(Y instanceof Error?Y.message:t("settings.mcp.page.toast.connectionFailed"))}finally{pe(!1)}}},Re=o.useCallback(()=>g?(R.error(t("settings.mcp.page.toast.createServerBeforeLiveActions")),!1):Be?(R.error(t("settings.mcp.page.toast.saveBeforeLiveActions")),!1):!0,[Be,g,t]),we=o.useCallback(async(Y=!1)=>{try{await N({directory:b,silent:Y})}catch(Ce){Y||R.error(Ce instanceof Error?Ce.message:t("settings.mcp.page.toast.refreshStatusFailed"))}},[b,N,t]);o.useEffect(()=>{we(!0)},[we]),o.useEffect(()=>{at.current=pt,pe(!1),Pe(!1),gt()},[gt,pt]);const rt=o.useCallback(async()=>{if(!a||v!=="remote"||!Re())return;ze(!0);const Y=pt;let Ce=null;try{const st=Is.getState().getStatusForDirectory(b??null)[a]?.status;Ve.current=st==="needs_auth"||st==="needs_client_registration";const{authorizationUrl:At,opened:jt,nativeFlow:Jt,completion:fs}=await Ol({name:a,directory:b});if(Jt){if(at.current!==Y)return;$e(null),ye(null),ve(!0),re.current=0,R.message(t("settings.mcp.page.toast.completeAuthorizationInBrowser")),fs?.then(()=>{at.current===Y&&(ve(!1),re.current=0,Ve.current=!1,R.success(t("settings.mcp.page.toast.authorizationCompleted")))}).catch(Ts=>{at.current===Y&&(ve(!1),re.current=0,Ve.current=!1,R.error(Ka(Ts,t("settings.mcp.page.toast.authorizationFailed"),e)))});return}const cs=Eo(new URL(At).searchParams);if(Ce=cs,at.current!==Y||($e(At),ye(cs??null),ve(!0),re.current=0,at.current!==Y))return;jt?R.message(t(p?"settings.mcp.page.toast.completeAuthorizationInBrowserWithPaste":"settings.mcp.page.toast.completeAuthorizationInBrowser")):R.error(t("settings.mcp.page.toast.openAuthorizationUrlFailed"))}catch(st){await ia(Ce),at.current===Y&&R.error(Ka(st,t("settings.mcp.page.toast.authorizationStartFailed"),e))}finally{at.current===Y&&ze(!1)}},[b,p,v,Re,pt,a,t,e]),lt=o.useCallback(async()=>{if(!a||!Re())return;_e(!0);const Y=pt;try{if(await E(a,b),at.current!==Y)return;$e(null),ye(null),oe(""),ve(!1),re.current=0,await ia(Fe),R.success(t("settings.mcp.page.toast.savedAuthorizationRemoved"))}catch(Ce){at.current===Y&&R.error(Ka(Ce,t("settings.mcp.page.toast.clearAuthorizationFailed"),e))}finally{at.current===Y&&_e(!1)}},[Fe,E,b,Re,pt,a,t,e]),it=o.useCallback(async()=>{if(!Me)return;if((await ga(Me)).ok){R.success(t("settings.mcp.page.toast.authorizationUrlCopied"));return}R.error(t("settings.mcp.page.toast.authorizationUrlCopyFailed"))},[Me,t]),It=o.useCallback(async()=>{const Y=cp(z);if(!Y.code){R.error(t("settings.mcp.page.toast.pasteCallbackOrCodeFirst"));return}const Ce=Y.stateKey?await hp(Y.stateKey):null,st=Y.context??Ce,At=st?.name??a,jt=st?.directory??b;if(!At){R.error(t("settings.mcp.page.toast.missingServerDetails"));return}if(!st&&!Re())return;Ge(!0);const Jt=pt;try{if(await u(At,Y.code,jt),await ia(Y.stateKey??Fe),at.current!==Jt)return;oe(""),$e(null),ye(null),ve(!1),re.current=0,R.success(At===a?t("settings.mcp.page.toast.authorizationCompleted"):t("settings.mcp.page.toast.authorizationCompletedFor",{name:At}))}catch(fs){at.current===Jt&&R.error(Ka(fs,t("settings.mcp.page.toast.authorizationCompleteFailed"),e))}finally{at.current===Jt&&Ge(!1)}},[z,Fe,u,b,Re,pt,a,t,e]),ls=o.useCallback(async()=>{if(!(!a||!Re())){if(!ce){R.error(t("settings.mcp.page.toast.enableServerBeforeTest"));return}Pe(!0);try{const Y=await q(a,b),Ce=Y.status?.status;Y.warning?R.warning(Y.warning):Ce==="connected"?R.success(t("settings.mcp.page.toast.connectionTestSucceeded")):Ce==="needs_auth"?R.message(t("settings.mcp.page.toast.connectionNeedsAuthorization")):Ce==="needs_client_registration"?R.message(t("settings.mcp.page.toast.connectionNeedsClientRegistration")):Ce==="failed"?R.error(Y.status?.error||Y.error||t("settings.mcp.page.toast.connectionTestFailed")):Y.error?R.error(Y.error):R.message(t("settings.mcp.page.toast.connectionTestFinished"))}catch(Y){R.error(Y instanceof Error?Y.message:t("settings.mcp.page.toast.connectionTestFailed"))}finally{Pe(!1)}}},[b,ce,Re,a,t,q]);if(o.useEffect(()=>{if(!me||!a)return;const Y=window.setInterval(()=>{(async()=>{re.current+=1,await N({directory:b,silent:!0});const Ce=Is.getState().getStatusForDirectory(b??null)[a];if(Ce){if(Ve.current&&Ce.status!=="needs_auth"&&Ce.status!=="needs_client_registration"){ve(!1),re.current=0,Ve.current=!1,$e(null),oe(""),Ce.status==="connected"&&R.success(t("settings.mcp.page.toast.authorizationCompleted"));return}if(!Ve.current&&Ce.status==="failed"){ve(!1),re.current=0,Ve.current=!1,R.error(Ce.error||t("settings.mcp.page.toast.authorizationFailed"));return}re.current>=30&&(ve(!1),re.current=0,Ve.current=!1,R.message(t("settings.mcp.page.toast.authorizationStillInProgress")))}})()},2e3);return()=>{window.clearInterval(Y)}},[b,me,N,a,t]),!a)return s.jsx("div",{className:"flex h-full items-center justify-center",children:s.jsxs("div",{className:"text-center text-muted-foreground",children:[s.jsx(_,{name:"plug",className:"mx-auto mb-3 h-12 w-12 opacity-50"}),s.jsx("p",{className:"typography-body",children:t("settings.mcp.page.empty.selectServer")}),s.jsx("p",{className:"typography-meta mt-1 opacity-75",children:t("settings.mcp.page.empty.addNewOne")})]})});const Xt=L[a],ts=a?k[a]:void 0,Wt=Xt??ts,kt=!g&&!Wt&&M.some(Y=>Y.scope==="mcp"&&Y.id.startsWith(`mcp:${a}:`)),bt=Xt?.status==="connected",Pt=Xt?.status==="needs_auth"||Xt?.status==="needs_client_registration",St=p||!a?null:Ll(a),Ft=async()=>{if(St)try{await navigator.clipboard.writeText(St),R.success(t("settings.mcp.page.toast.copiedCallbackUrl"))}catch{R.error(t("settings.mcp.page.toast.clipboardWriteFailed"))}},Bt=mp(Wt?.status,e,Wt&&"error"in Wt?Wt.error:void 0),hs=Y=>{switch(Y){case"connected":return t("settings.mcp.page.status.label.connected");case"failed":return t("settings.mcp.page.status.label.failed");case"needs_auth":return t("settings.mcp.page.status.label.needsAuth");case"needs_client_registration":return t("settings.mcp.page.status.label.needsRegistration");case"awaiting_restart":return t("settings.mcp.page.status.label.awaitingRestart");default:return Y}};return s.jsxs(s.Fragment,{children:[s.jsxs(rs,{title:g?t("settings.mcp.page.header.newServer"):a,titleAccessory:g?void 0:s.jsx(ji,{status:kt?"awaiting_restart":Wt?.status,enabled:ce,getStatusLabel:hs,variant:"pill"}),description:g?t("settings.mcp.page.header.configureNewServer"):t("settings.mcp.page.header.transport",{type:t(v==="local"?"settings.mcp.page.transport.local":"settings.mcp.page.transport.remote")}),headerEnd:!g&&!kt?s.jsxs("div",{className:"flex flex-wrap items-center gap-2",children:[s.jsx(H,{variant:bt?"outline":"default",size:"xs",className:"!font-normal",onClick:xe,disabled:he||!ce,children:t(he?"settings.mcp.page.actions.working":bt?"settings.mcp.page.actions.disconnect":"settings.mcp.page.actions.connect")}),v==="remote"&&s.jsxs(s.Fragment,{children:[s.jsx(H,{variant:Pt?"default":"outline",size:"xs",className:"!font-normal",onClick:()=>{rt()},disabled:Ie||!ce,children:t(Ie?"settings.mcp.page.actions.starting":bt?"settings.mcp.page.actions.reauthorize":"settings.mcp.page.actions.authorize")}),s.jsx(H,{variant:"ghost",size:"xs",className:"!font-normal gap-1 text-muted-foreground",onClick:()=>{lt()},disabled:Je||!ce,children:t(Je?"settings.mcp.page.actions.clearing":"settings.mcp.page.actions.clearAuth")})]}),bt&&s.jsx(H,{variant:"ghost",size:"xs",className:"!font-normal gap-1 text-muted-foreground",onClick:()=>{ls()},disabled:Le||!ce,children:t(Le?"settings.mcp.page.actions.testing":"settings.mcp.page.actions.test")})]}):void 0,showSaveStatus:!1,children:[kt&&s.jsx(Oe,{divider:!1,children:s.jsx("div",{className:"rounded-lg border p-3 border-[var(--status-warning-border)] bg-[var(--status-warning-background)]",children:s.jsxs("div",{className:"min-w-0 space-y-1",children:[s.jsxs("div",{className:"flex flex-wrap items-center gap-x-2 gap-y-1",children:[s.jsx("span",{className:Et,children:t("settings.mcp.page.status.runtimeStatus")}),s.jsx(ji,{status:"awaiting_restart",enabled:ce,getStatusLabel:hs})]}),s.jsx("p",{className:"typography-meta text-muted-foreground",children:t("settings.mcp.page.status.description.awaitingRestart")})]})})}),!g&&!kt&&gp(Wt?.status,Me,Pt,me)&&s.jsx(Oe,{divider:!1,children:s.jsxs("div",{className:je("rounded-lg border p-3",up(Wt?.status)),children:[s.jsxs("div",{className:"space-y-4",children:[s.jsxs("div",{className:"min-w-0 space-y-1",children:[s.jsxs("div",{className:"flex flex-wrap items-center gap-x-2 gap-y-1",children:[s.jsx("span",{className:Et,children:t("settings.mcp.page.status.runtimeStatus")}),s.jsx(ji,{status:Wt?.status,enabled:ce,getStatusLabel:hs})]}),s.jsx("p",{className:"typography-meta text-muted-foreground",children:Bt}),s.jsx("p",{className:"typography-micro text-muted-foreground/80",children:S==="project"?t("settings.mcp.page.status.projectScopedTo",{directory:b??t("settings.mcp.page.status.activeProject")}):t("settings.mcp.page.status.userScoped")})]}),s.jsx("div",{className:"flex flex-wrap items-center gap-2",children:!bt&&s.jsx(H,{variant:"outline",size:"xs",className:"!font-normal",onClick:()=>{ls()},disabled:Le||!ce,children:t(Le?"settings.mcp.page.actions.testing":"settings.mcp.page.actions.testConnection")})}),Wt?.status==="needs_client_registration"&&s.jsxs("div",{className:"space-y-3 rounded-md border border-[var(--interactive-border)] bg-[var(--surface-background)] px-3 py-3",children:[s.jsxs("div",{children:[s.jsx(Vs,{as:"div",children:t("settings.mcp.page.registration.title")}),s.jsx("p",{className:"mt-1 typography-micro text-muted-foreground",children:t("settings.mcp.page.registration.description")})]}),St&&s.jsxs("div",{children:[s.jsx("div",{className:"typography-micro text-muted-foreground",children:t("settings.mcp.page.registration.callbackLabel")}),s.jsxs("div",{className:"mt-1 flex items-start gap-2",children:[s.jsx("span",{className:"min-w-0 flex-1 break-all font-mono typography-micro text-foreground/80",children:St}),s.jsxs(H,{variant:"outline",size:"xs",className:"!font-normal",onClick:()=>{Ft()},children:[s.jsx(_,{name:"clipboard",className:"h-3.5 w-3.5"}),t("settings.mcp.page.actions.copyLink")]})]})]}),s.jsxs("div",{className:"grid gap-3 @xl:grid-cols-2",children:[s.jsx(Qt,{label:t("settings.mcp.page.registration.clientId"),children:s.jsx(He,{value:O,onChange:Y=>{U(Y.target.value),D(!0)},className:"font-mono typography-meta","data-bwignore":"true","data-1p-ignore":"true"})}),s.jsx(Qt,{label:t("settings.mcp.page.registration.clientSecret"),children:s.jsx(He,{type:"password",value:A,onChange:Y=>{V(Y.target.value),D(!0)},className:"font-mono typography-meta","data-bwignore":"true","data-1p-ignore":"true"})})]}),s.jsx("p",{className:"typography-micro text-muted-foreground",children:t("settings.mcp.page.registration.afterSaving")})]}),Me&&s.jsx("div",{className:"rounded-md border border-[var(--interactive-border)] bg-[var(--surface-background)] px-3 py-2",children:s.jsxs("div",{className:"space-y-2",children:[s.jsx("div",{className:"typography-micro text-muted-foreground",children:t("settings.mcp.page.auth.authorizationUrl")}),s.jsx("div",{className:"break-all typography-micro text-foreground font-mono",children:Me}),s.jsxs("div",{className:"flex flex-wrap items-center gap-2",children:[s.jsxs(H,{variant:"outline",size:"xs",className:"!font-normal",onClick:()=>{En(Me)},children:[s.jsx(_,{name:"external-link",className:"h-3.5 w-3.5"}),t("settings.mcp.page.actions.openInBrowser")]}),s.jsxs(H,{variant:"outline",size:"xs",className:"!font-normal",onClick:()=>{it()},children:[s.jsx(_,{name:"clipboard",className:"h-3.5 w-3.5"}),t("settings.mcp.page.actions.copyLink")]})]})]})}),p&&v==="remote"&&(Pt||me||Me)&&s.jsx("div",{className:"rounded-md border border-[var(--interactive-border)] bg-[var(--surface-background)] px-3 py-3",children:s.jsxs("div",{className:"space-y-2",children:[s.jsxs("div",{children:[s.jsx(Vs,{as:"div",children:t("settings.mcp.page.auth.manualFallbackTitle")}),s.jsx("p",{className:"mt-1 typography-micro text-muted-foreground",children:t("settings.mcp.page.auth.manualFallbackDescription")})]}),s.jsx(Ns,{value:z,onChange:Y=>oe(Y.target.value),placeholder:t("settings.mcp.page.auth.callbackInputPlaceholder"),rows:3,className:"font-mono typography-meta","data-bwignore":"true","data-1p-ignore":"true",spellCheck:!1}),s.jsx("div",{className:"flex flex-wrap items-center gap-2",children:s.jsx(H,{variant:"outline",size:"xs",className:"!font-normal",onClick:()=>{It()},disabled:Ye,children:t(Ye?"settings.mcp.page.actions.completing":"settings.mcp.page.actions.completeAuthorization")})})]})})]}),me&&s.jsx("p",{className:"mt-4 typography-micro text-muted-foreground",children:t("settings.mcp.page.auth.waitingForOpenCode")})]})}),s.jsxs(Oe,{title:t("settings.mcp.page.server.title"),divider:!1,settingsItem:"mcp.server",contentClassName:"space-y-0",titleAccessory:g?s.jsxs(H,{variant:"ghost",size:"xs",className:"!font-normal gap-1.5 text-muted-foreground",onClick:Ct,type:"button",title:t("settings.mcp.page.server.importJsonTitle"),children:[s.jsx(_,{name:"file-code",className:"h-3.5 w-3.5"}),t("settings.mcp.page.server.importJson")]}):null,children:[g&&s.jsxs($t,{label:t("settings.mcp.page.server.name"),controlClassName:"flex-wrap @xl:w-auto @xl:flex-1",children:[s.jsx(He,{value:j,onChange:Y=>F(Y.target.value.toLowerCase().replace(/[^a-z0-9_-]/g,"-")),placeholder:t("settings.mcp.page.server.namePlaceholder"),className:"h-7 w-48 min-w-0 max-w-full shrink font-mono px-2",autoFocus:!0}),s.jsxs(Dt,{value:S,onValueChange:Y=>T(Y),children:[s.jsxs(Mt,{size:Kt,className:"!h-7 min-w-0 max-w-full gap-1.5 px-2",children:[s.jsx(_,{name:S==="user"?"user-3":"folder",className:"h-3.5 w-3.5 shrink-0"}),s.jsx("span",{className:"truncate",children:t(S==="user"?"settings.mcp.page.scope.everywhere":"settings.mcp.page.scope.thisProject")})]}),s.jsxs(Rt,{align:"end",children:[s.jsx(dt,{value:"user",children:s.jsxs("div",{className:"flex items-center gap-2",children:[s.jsx(_,{name:"user-3",className:"h-3.5 w-3.5"}),s.jsx("span",{children:t("settings.mcp.page.scope.everywhere")})]})}),s.jsx(dt,{value:"project",children:s.jsxs("div",{className:"flex items-center gap-2",children:[s.jsx(_,{name:"folder",className:"h-3.5 w-3.5"}),s.jsx("span",{children:t("settings.mcp.page.scope.thisProject")})]})})]})]})]}),s.jsx(ut,{checked:ce,onChange:ge,label:t("settings.mcp.page.server.enable"),ariaLabel:t("settings.mcp.page.server.enableAria")})]}),s.jsxs(Oe,{title:t("settings.mcp.page.connection.title"),description:t("settings.mcp.page.connection.description"),settingsItem:"mcp.command",contentClassName:"space-y-2",children:[s.jsx(Zi,{items:qe,activeId:v,onSelect:Y=>K(Y),layoutMode:"fit",variant:"active-pill",activePillLowercase:!1,className:"h-10"}),v==="local"?s.jsx(dp,{value:$,onChange:w,preview:Y=>t("settings.mcp.page.connection.previewArgs",{count:Y}),onDetectUrl:Nt}):s.jsx(He,{value:G,onChange:Y=>xt(Y.target.value),placeholder:t("settings.mcp.page.connection.serverUrlPlaceholder"),className:"font-mono typography-meta"}),s.jsx("p",{className:"typography-micro text-muted-foreground",children:t(v==="local"?"settings.mcp.page.connection.hintCommand":"settings.mcp.page.connection.hintLink")})]}),v==="remote"&&s.jsx(Oe,{title:t("settings.mcp.page.advanced.title"),settingsItem:"mcp.advanced",children:s.jsxs(ba,{open:Ze,onOpenChange:B,children:[s.jsxs(va,{className:"flex w-full items-center justify-between py-0.5 group",children:[s.jsxs("div",{className:"flex items-center gap-1.5 text-left",children:[s.jsx("span",{className:"typography-ui-label font-normal text-foreground",children:t("settings.mcp.page.advanced.configure")}),s.jsxs("span",{className:"typography-micro text-muted-foreground",children:["(",P.length," ",t("settings.mcp.page.advanced.headers"),be?` · ${be}ms`:"",")"]})]}),Ze?s.jsx(_,{name:"arrow-down-s",className:"h-4 w-4 text-muted-foreground group-hover:text-foreground transition-colors"}):s.jsx(_,{name:"arrow-right-s",className:"h-4 w-4 text-muted-foreground group-hover:text-foreground transition-colors"})]}),s.jsx(ya,{className:"pt-2",children:s.jsxs("div",{className:"space-y-4",children:[s.jsx("div",{className:"space-y-2",children:s.jsxs("div",{className:"flex flex-col gap-2 @xl:flex-row @xl:items-center @xl:gap-8",children:[s.jsxs("div",{className:"flex min-w-0 flex-row items-center gap-1 @xl:w-56 shrink-0",children:[s.jsx("span",{className:Et,children:t("settings.mcp.page.advanced.timeoutMs")}),s.jsx(Yt,{children:t("settings.mcp.page.advanced.timeoutHint")})]}),s.jsx("div",{className:"flex items-center gap-2",children:s.jsx(He,{type:"number",min:"1",step:"1",value:be,onChange:Y=>ke(Y.target.value),placeholder:"5000",className:"h-7 w-32 font-mono px-2","data-bwignore":"true","data-1p-ignore":"true"})})]})}),s.jsxs("div",{children:[s.jsxs(Vs,{as:"div",className:"mb-2",children:[t("settings.mcp.page.advanced.requestHeaders"),P.length>0&&s.jsxs("span",{className:"ml-1.5 typography-micro text-muted-foreground font-normal",children:["(",P.length,")"]})]}),s.jsx(Ur,{value:P,onChange:ee,keyTransform:Y=>Y.trimStart(),keyPlaceholder:t("settings.mcp.page.advanced.headerNamePlaceholder"),keyInputClassName:"w-36 shrink-0 font-mono typography-meta",pasteLabel:t("settings.mcp.page.advanced.pasteHeaders"),pasteTitle:t("settings.mcp.page.advanced.pasteHeadersTitle"),noPairsFoundError:t("settings.mcp.page.toast.noKeyValuePairsFound"),importSuccess:Y=>t("settings.mcp.page.toast.importedVariablesCount",{count:Y}),clipboardReadFailed:t("settings.mcp.page.toast.clipboardReadFailed"),keyLabel:t("settings.mcp.page.env.key"),valueLabel:t("settings.mcp.page.env.value"),valuePlaceholder:t("settings.mcp.page.env.valuePlaceholder"),hideValueTitle:t("settings.mcp.page.env.hide"),showValueTitle:t("settings.mcp.page.env.show"),addVariable:t("settings.mcp.page.env.addVariable"),plainTextWarning:t("settings.mcp.page.env.plainTextWarning"),removeVariableAria:t("settings.mcp.page.env.removeVariableAria")})]})]})})]})}),s.jsx(Oe,{title:t("settings.mcp.page.env.title"),description:t("settings.mcp.page.env.description"),titleAccessory:X.length>0?s.jsxs("span",{className:"typography-micro text-muted-foreground font-normal",children:["(",X.length,")"]}):null,settingsItem:"mcp.environment",children:X.length===0?s.jsxs(H,{variant:"outline",size:"xs",className:"!font-normal gap-1.5",onClick:()=>Z([{key:"",value:""}]),children:[s.jsx(_,{name:"add",className:"h-3.5 w-3.5"}),t("settings.mcp.page.env.addEnvironmentVariable")]}):s.jsx(Ur,{value:X,onChange:Z,keyPlaceholder:t("settings.mcp.page.env.keyPlaceholder"),pasteLabel:t("settings.mcp.page.env.pasteEnv"),pasteTitle:t("settings.mcp.page.env.pasteEnvTitle"),noPairsFoundError:t("settings.mcp.page.toast.noKeyValuePairsFound"),importSuccess:Y=>t("settings.mcp.page.toast.importedVariablesCount",{count:Y}),clipboardReadFailed:t("settings.mcp.page.toast.clipboardReadFailed"),keyLabel:t("settings.mcp.page.env.key"),valueLabel:t("settings.mcp.page.env.value"),valuePlaceholder:t("settings.mcp.page.env.valuePlaceholder"),hideValueTitle:t("settings.mcp.page.env.hide"),showValueTitle:t("settings.mcp.page.env.show"),addVariable:t("settings.mcp.page.env.addVariable"),plainTextWarning:t("settings.mcp.page.env.plainTextWarning"),removeVariableAria:t("settings.mcp.page.env.removeVariableAria")})}),s.jsxs("div",{className:"flex items-center gap-2 pb-8",children:[s.jsx(H,{onClick:zt,disabled:Ee||!Be&&!g,size:"xs",className:"!font-normal",children:t(Ee?"settings.common.actions.saving":g?"settings.common.actions.create":"settings.common.actions.saveChanges")}),!g&&s.jsx(H,{variant:"destructive",size:"xs",className:"!font-normal",onClick:()=>fe(!0),children:t("settings.common.actions.delete")})]})," "]}),s.jsx(Ut,{open:Ue,onOpenChange:Y=>{Y||(Qe(!1),tt(""),mt(null))},children:s.jsxs(Vt,{className:"max-w-md",children:[s.jsxs(Ht,{children:[s.jsx(Gt,{children:t("settings.mcp.page.importDialog.title")}),s.jsx(qt,{children:t("settings.mcp.page.importDialog.description")})]}),s.jsxs("div",{className:"space-y-3",children:[s.jsx(Ns,{value:et,onChange:Y=>{tt(Y.target.value),mt(null)},placeholder:`{
15
+ "mcpServers": {
16
+ "postgres": {
17
+ "command": "npx",
18
+ "args": ["-y", "@modelcontextprotocol/server-postgres"]
19
+ }
20
+ }
21
+ }`,rows:8,className:"font-mono typography-meta",spellCheck:!1,"data-bwignore":"true","data-1p-ignore":"true"}),wt&&s.jsx("p",{className:"typography-micro text-[var(--status-error)]",children:wt}),s.jsx("div",{className:"flex flex-wrap items-center gap-2",children:s.jsxs(H,{variant:"outline",size:"xs",className:"!font-normal gap-1",onClick:ie,type:"button",children:[s.jsx(_,{name:"clipboard",className:"h-3.5 w-3.5"}),t("settings.mcp.page.importDialog.pasteFromClipboard")]})})]}),s.jsxs(os,{children:[s.jsx(H,{variant:"outline",onClick:()=>{Qe(!1),tt(""),mt(null)},className:"text-foreground",children:t("settings.common.actions.cancel")}),s.jsx(H,{onClick:Ae,disabled:!et.trim(),size:"sm",children:t("settings.common.actions.import")})]})]})}),s.jsx(Ut,{open:Ne,onOpenChange:Y=>{!Y&&!Ke&&fe(!1)},children:s.jsxs(Vt,{className:"max-w-md",children:[s.jsxs(Ht,{children:[s.jsx(Gt,{children:t("settings.mcp.page.deleteDialog.title",{name:a??""})}),s.jsxs(qt,{children:[t("settings.mcp.page.deleteDialog.descriptionPrefix")," ",s.jsx("code",{className:"text-foreground",children:"opencode.json"}),"."," ",t("settings.mcp.page.deleteDialog.descriptionSuffix")]})]}),s.jsxs(os,{children:[s.jsx(H,{variant:"outline",onClick:()=>fe(!1),disabled:Ke,className:"text-foreground",children:t("settings.common.actions.cancel")}),s.jsx(H,{variant:"destructive",size:"sm",onClick:J,disabled:Ke,children:t(Ke?"settings.mcp.page.actions.deleting":"settings.common.actions.delete")})]})]})})]})};function bp(t){return t.trim().length>0}function vp(t){return t.trimEnd()}function yp(t,e){return s.jsxs("span",{className:"block",children:[s.jsxs("span",{className:"text-muted-foreground select-none mr-2",children:["[",e,"]"]}),t]},e)}const $a=()=>{try{const e=Fs.getState().getActiveProject?.();if(e?.path?.trim())return e.path.trim();const a=on.getDirectory();if(a?.trim())return a.trim()}catch(t){console.warn("[PluginsStore] Error resolving config directory:",t)}return null},jp=800,wp=5e3,Np="__default__",zi=new Map,wi=new Map,kp=1500,Zo=t=>t?.trim()||Np,Sp=t=>{zi.delete(Zo(t))},us=Ho()(sd(nd((t,e)=>({entries:[],files:[],selectedId:null,isLoading:!1,registryInfo:{},isLoadingRegistry:!1,draft:null,setSelected:a=>t({selectedId:a}),setDraft:a=>t({draft:a}),loadPlugins:async a=>{const n=$a(),i=Zo(n),r=Date.now(),l=zi.get(i)??0,x=e().entries.length>0||e().files.length>0;if(!a?.force&&x&&r-l<wp)return!0;const c=wi.get(i);if(!a?.force&&c)return c;const y=(async()=>{t({isLoading:!0});try{const m=await ct(mn("/api/config/plugins",n),{headers:ra(n)});if(!m.ok)throw new Error("Failed to load plugins");const b=await Ba(m);return t({entries:b.entries??[],files:b.files??[],isLoading:!1}),zi.set(i,Date.now()),a?.force||e().loadRegistryInfo(),!0}catch(m){return console.error("[PluginsStore] Failed to load plugins:",m),t({isLoading:!1}),!1}})();wi.set(i,y);try{return await y}finally{wi.delete(i)}},loadRegistryInfo:async a=>{const n=Ip(a?.specs??e().entries.map(i=>i.spec));if(n.length===0){t({isLoadingRegistry:!1});return}t({isLoadingRegistry:!0});try{const i=$a(),r={...e().registryInfo};for(const l of Pp(n)){const x=await ct(Cp(l,a?.force===!0,i),{headers:ra(i)});if(!x.ok)throw new Error("Failed to load plugin registry info");const c=await Ba(x);for(const y of c.results??[])r[y.spec]=y}t({registryInfo:r,isLoadingRegistry:!1})}catch(i){console.error("[PluginsStore] Failed to load plugin registry info:",i),t({isLoadingRegistry:!1})}},updateToLatest:async a=>{const n=e().entries.find(r=>r.id===a);if(!n)return{ok:!1};const i=e().registryInfo[n.spec];return!i||i.kind!=="npm-ok"||!i.hasUpdate||!i.latestVersion?{ok:!1}:await e().updateEntry(a,{spec:`${i.name}@${i.latestVersion}`})},createEntry:async a=>{const n=await Vn("Creating plugin entry…",async i=>await ct(mn("/api/config/plugins/entry",i),{method:"POST",headers:_a(i),body:JSON.stringify(Vr(a))}),e,{restartId:a.spec});return n.ok&&e().loadRegistryInfo({specs:[a.spec],force:!0}),n},updateEntry:async(a,n)=>{const i=e().entries.find(x=>x.id===a)?.spec,r=n.spec??i,l=await Vn("Updating plugin entry…",async x=>await ct(mn(`/api/config/plugins/entry/${encodeURIComponent(a)}`,x),{method:"PATCH",headers:_a(x),body:JSON.stringify(Vr(n))}),e,{restartId:a});return l.ok&&r&&e().loadRegistryInfo({specs:[r],force:!0}),l},deleteEntry:async a=>{const n=e().entries.find(r=>r.id===a),i=await Vn("Deleting plugin entry…",async r=>await ct(mn(`/api/config/plugins/entry/${encodeURIComponent(a)}`,r),{method:"DELETE",headers:ra(r)}),e,{restartId:a});if(i.ok&&e().selectedId===a&&t({selectedId:null}),i.ok&&n){const r={...e().registryInfo};delete r[n.spec],t({registryInfo:r})}return i},readFile:async a=>{try{const n=$a(),i=await ct(mn(`/api/config/plugins/file/${encodeURIComponent(a)}`,n),{headers:ra(n)});if(!i.ok)throw new Error("Failed to read plugin file");return await Ba(i)}catch(n){return console.error("[PluginsStore] Failed to read plugin file:",n),null}},createFile:async a=>Vn("Creating plugin file…",async n=>await ct(mn("/api/config/plugins/file",n),{method:"POST",headers:_a(n),body:JSON.stringify(a)}),e,{restartId:a.fileName}),updateFile:async(a,n)=>Vn("Updating plugin file…",async i=>await ct(mn(`/api/config/plugins/file/${encodeURIComponent(a)}`,i),{method:"PUT",headers:_a(i),body:JSON.stringify(n)}),e,{restartId:a}),deleteFile:async a=>{const n=await Vn("Deleting plugin file…",async i=>await ct(mn(`/api/config/plugins/file/${encodeURIComponent(a)}`,i),{method:"DELETE",headers:ra(i)}),e,{restartId:a});return n.ok&&e().selectedId===a&&t({selectedId:null}),n},getById:a=>e().entries.find(n=>n.id===a)??e().files.find(n=>n.id===a)}),{name:"plugins-store",storage:kc(),partialize:t=>({selectedId:t.selectedId})}),{name:"plugins-store"}));function mn(t,e){const a=e?`?directory=${encodeURIComponent(e)}`:"";return`${t}${a}`}function Cp(t,e,a){const n=new URLSearchParams;e&&n.set("refresh","true"),a&&n.set("directory",a);const i=n.toString();return`/api/config/plugins/registry?${`specs=${t.map(encodeURIComponent).join(",")}`}${i?`&${i}`:""}`}function Ip(t){return Array.from(new Set(t.map(e=>e.trim()).filter(Boolean)))}function Pp(t){const e=[];let a=[],n=0;for(const i of t){const r=encodeURIComponent(i),l=a.length===0?r.length:n+1+r.length;a.length>0&&l>kp?(e.push(a),a=[i],n=r.length):(a.push(i),n=l)}return a.length>0&&e.push(a),e}function ra(t){return t?{"x-opencode-directory":t}:void 0}function _a(t){return{"Content-Type":"application/json",...t?{"x-opencode-directory":t}:{}}}function Vr(t){const e={};return t.spec!==void 0&&(e.spec=t.spec),t.options!==void 0&&(e.options=t.options),t.scope!==void 0&&(e.scope=t.scope),e}async function Vn(t,e,a,n){try{const i=$a(),r=await e(i),l=await Ba(r).catch(()=>null);if(!r.ok)throw new Error(l?.error||"Failed to update plugin configuration");return Sp(i),l?.requiresManualRestart?(await a().loadPlugins({force:!0}),{ok:!0,requiresManualRestart:!0,reloadFailed:l?.reloadFailed===!0,message:l?.message,warning:l?.warning}):qa(l,"plugins",{id:n?.restartId})?(await a().loadPlugins({force:!0}),{ok:!0,restartDeferred:!0,reloadFailed:l?.reloadFailed===!0,message:l?.message,warning:l?.warning}):(l?.requiresReload&&(Kl(t),await _l({message:l.message,delayMs:l.reloadDelayMs??jp,scopes:["all"]})),await a().loadPlugins({force:!0}),{ok:!0,reloadFailed:l?.reloadFailed===!0,message:l?.message,warning:l?.warning})}catch(i){return console.error("[PluginsStore] Failed to update plugin configuration:",i),{ok:!1}}}async function Ba(t){return await t.json()}const Ap=/^[a-z0-9][a-z0-9-_.]*\.(js|ts|mjs|cjs)$/;function Tp(t){const e=t.trim();if(e==="")return{ok:!0,value:void 0};try{const a=JSON.parse(e);return a===null||typeof a!="object"||Array.isArray(a)?{ok:!1}:{ok:!0,value:a}}catch{return{ok:!1}}}const Ep=({open:t,onOpenChange:e,defaultScope:a="user"})=>{const{t:n}=ot(),i=us(w=>w.createEntry),r=us(w=>w.createFile),[l,x]=o.useState("npm"),[c,y]=o.useState(""),[m,b]=o.useState(""),[p,L]=o.useState(""),[k,N]=o.useState(""),[h,C]=o.useState(a),[u,E]=o.useState(!1),q=o.useCallback(()=>{y(""),b(""),L(""),N(""),C(a)},[a]);o.useEffect(()=>{t&&(x("npm"),q())},[t,q]);const M=w=>{w!==l&&(x(w),q())},I=o.useMemo(()=>Tp(m),[m]),g=!I.ok,j=l==="file"&&p.trim()!==""&&!Ap.test(p.trim()),F=(l==="npm"||l==="path")&&c.trim()==="",S=l==="file"&&k.trim()==="",T=l==="file"&&p.trim()==="",v=u||g||l==="npm"&&F||l==="path"&&F||l==="file"&&(T||j||S),K=async()=>{if(!v){E(!0);try{let w;l==="file"?w=await r({fileName:p.trim(),content:k,scope:h}):w=await i({spec:c.trim(),options:I.ok?I.value:void 0,scope:h}),w.ok?(w.restartDeferred?R.success(n("settings.view.pendingRestart.saved")):R.success(w.message||n("settings.plugins.toast.created")),w.reloadFailed&&R.warning(n("settings.plugins.toast.reloadFailed")),e(!1)):R.error(w.message||n("settings.plugins.sidebar.toast.deleteFailed"))}finally{E(!1)}}},$=o.useMemo(()=>[{id:"npm",label:n("settings.plugins.dialog.add.tab.npm")},{id:"path",label:n("settings.plugins.dialog.add.tab.path")},{id:"file",label:n("settings.plugins.dialog.add.tab.file")}],[n]);return s.jsx(Ut,{open:t,onOpenChange:w=>{!w&&u||e(w)},children:s.jsxs(Vt,{className:"max-w-xl",children:[s.jsxs(Ht,{children:[s.jsx(Gt,{children:n("settings.plugins.dialog.add.title")}),s.jsx(qt,{children:n("settings.plugins.sidebar.empty.description")})]}),s.jsx(Zi,{items:$,activeId:l,onSelect:w=>M(w),layoutMode:"fit",variant:"active-pill",activePillLowercase:!1,className:"h-10"}),s.jsxs("div",{className:"flex flex-col gap-4",children:[(l==="npm"||l==="path")&&s.jsxs(s.Fragment,{children:[s.jsxs("div",{"data-settings-item":"plugins.spec",className:"flex flex-col gap-1.5",children:[s.jsx("label",{htmlFor:"plugin-spec",className:"typography-ui-label text-foreground",children:n("settings.plugins.page.field.spec")}),s.jsx(He,{id:"plugin-spec",value:c,onChange:w=>y(w.target.value),placeholder:n("settings.plugins.page.field.spec.placeholder"),"aria-invalid":F?!1:void 0,disabled:u}),F&&s.jsx("p",{className:"typography-meta text-muted-foreground",children:n("settings.plugins.validation.specRequired")})]}),s.jsxs("div",{"data-settings-item":"plugins.options",className:"flex flex-col gap-1.5",children:[s.jsx("label",{htmlFor:"plugin-options",className:"typography-ui-label text-foreground",children:n("settings.plugins.page.field.options")}),s.jsx(Ns,{id:"plugin-options",value:m,onChange:w=>b(w.target.value),rows:5,className:"font-mono",hasError:g,disabled:u}),g&&s.jsx("p",{className:"typography-meta text-[var(--status-error)]",children:n("settings.plugins.page.field.options.invalidJson")})]})]}),l==="file"&&s.jsxs(s.Fragment,{children:[s.jsxs("div",{"data-settings-item":"plugins.content",className:"flex flex-col gap-1.5",children:[s.jsx("label",{htmlFor:"plugin-filename",className:"typography-ui-label text-foreground",children:n("settings.plugins.page.field.fileName")}),s.jsx(He,{id:"plugin-filename",value:p,onChange:w=>L(w.target.value),placeholder:"my-plugin.ts","aria-invalid":j||void 0,disabled:u}),j&&s.jsx("p",{className:"typography-meta text-[var(--status-error)]",children:n("settings.plugins.validation.fileName")})]}),s.jsxs("div",{className:"flex flex-col gap-1.5",children:[s.jsx("label",{htmlFor:"plugin-content",className:"typography-ui-label text-foreground",children:n("settings.plugins.page.field.content")}),s.jsx(Ns,{id:"plugin-content",value:k,onChange:w=>N(w.target.value),rows:16,className:"font-mono",disabled:u})]})]}),s.jsxs("div",{className:"flex flex-col gap-1.5",children:[s.jsx("span",{className:"typography-ui-label text-foreground",children:n("settings.plugins.page.field.scope")}),s.jsx("div",{className:"flex items-center gap-4",children:["user","project"].map(w=>{const G=h===w,Q=n(w==="user"?"settings.plugins.scope.user":"settings.plugins.scope.project");return s.jsxs("button",{type:"button",onClick:()=>C(w),disabled:u,className:"flex items-center gap-2 py-1 text-left disabled:opacity-50",children:[s.jsx(Wi,{checked:G,onChange:()=>C(w),ariaLabel:Q}),s.jsx("span",{className:je("typography-ui-label font-normal",G?"text-foreground":"text-foreground/60"),children:Q})]},w)})})]})]}),s.jsxs(os,{children:[s.jsx(H,{size:"sm",variant:"ghost",onClick:()=>e(!1),disabled:u,children:n("settings.plugins.dialog.add.action.cancel")}),s.jsxs(H,{size:"sm",onClick:()=>{K()},disabled:v,children:[u?s.jsx(_,{name:"loader-4",className:"h-3.5 w-3.5 animate-spin"}):null,n("settings.plugins.dialog.add.action.submit")]})]})]})})},Dp=t=>{const e=ht.c(33),{spec:a}=t;let n;e[0]!==a?(n=x=>x.registryInfo[a],e[0]=a,e[1]=n):n=e[1];const i=us(n),{t:r}=ot();if(!i)return null;const l=Mp;switch(i.kind){case"npm-ok":{if(!i.hasUpdate||!i.latestVersion)return null;let x;e[2]===Symbol.for("react.memo_cache_sentinel")?(x=s.jsx(_,{name:"arrow-up-s",className:"h-3 w-3"}),e[2]=x):x=e[2];let c;e[3]!==i.latestVersion?(c=s.jsxs("span",{className:"inline-flex items-center gap-0.5 text-[var(--status-success)]",children:[x,i.latestVersion]}),e[3]=i.latestVersion,e[4]=c):c=e[4];let y;return e[5]!==i.currentVersion||e[6]!==i.latestVersion||e[7]!==r||e[8]!==c?(y=l(c,r("settings.plugins.registry.badge.update.tooltip",{current:i.currentVersion??"",latest:i.latestVersion})),e[5]=i.currentVersion,e[6]=i.latestVersion,e[7]=r,e[8]=c,e[9]=y):y=e[9],y}case"npm-missing-version":{let x;e[10]===Symbol.for("react.memo_cache_sentinel")?(x=s.jsx(_,{name:"error-warning",className:"h-3 w-3 text-[var(--status-warning)]"}),e[10]=x):x=e[10];let c;return e[11]!==i.currentVersion||e[12]!==i.name||e[13]!==r?(c=l(x,r("settings.plugins.registry.badge.missingVersion.tooltip",{version:i.currentVersion,name:i.name})),e[11]=i.currentVersion,e[12]=i.name,e[13]=r,e[14]=c):c=e[14],c}case"npm-missing-package":{let x;e[15]===Symbol.for("react.memo_cache_sentinel")?(x=s.jsx(_,{name:"error-warning",className:"h-3 w-3 text-[var(--status-error)]"}),e[15]=x):x=e[15];let c;return e[16]!==i.name||e[17]!==r?(c=l(x,r("settings.plugins.registry.badge.missingPackage.tooltip",{name:i.name})),e[16]=i.name,e[17]=r,e[18]=c):c=e[18],c}case"npm-malformed":{let x;e[19]===Symbol.for("react.memo_cache_sentinel")?(x=s.jsx(_,{name:"error-warning",className:"h-3 w-3 text-[var(--status-error)]"}),e[19]=x):x=e[19];let c;return e[20]!==r?(c=l(x,r("settings.plugins.registry.badge.malformed.tooltip")),e[20]=r,e[21]=c):c=e[21],c}case"npm-network":{let x;e[22]===Symbol.for("react.memo_cache_sentinel")?(x=s.jsx(_,{name:"cloud-off",className:"h-3 w-3 text-muted-foreground"}),e[22]=x):x=e[22];let c;return e[23]!==r?(c=l(x,r("settings.plugins.registry.badge.network.tooltip")),e[23]=r,e[24]=c):c=e[24],c}case"path-missing":{let x;e[25]===Symbol.for("react.memo_cache_sentinel")?(x=s.jsx(_,{name:"error-warning",className:"h-3 w-3 text-[var(--status-error)]"}),e[25]=x):x=e[25];let c;return e[26]!==i.absolutePath||e[27]!==r?(c=l(x,r("settings.plugins.registry.badge.pathMissing.tooltip",{path:i.absolutePath})),e[26]=i.absolutePath,e[27]=r,e[28]=c):c=e[28],c}case"path-unreadable":{let x;e[29]===Symbol.for("react.memo_cache_sentinel")?(x=s.jsx(_,{name:"error-warning",className:"h-3 w-3 text-[var(--status-warning)]"}),e[29]=x):x=e[29];let c;return e[30]!==i.absolutePath||e[31]!==r?(c=l(x,r("settings.plugins.registry.badge.pathUnreadable.tooltip",{path:i.absolutePath})),e[30]=i.absolutePath,e[31]=r,e[32]=c):c=e[32],c}case"path-ok":return null;default:return null}};function Mp(t,e){return s.jsxs(Ji,{children:[s.jsx(Qi,{asChild:!0,children:s.jsx("span",{className:"inline-flex shrink-0 items-center gap-0.5 text-xs",children:t})}),s.jsx(Do,{children:e})]})}const Xo=t=>{const e=ht.c(26),{header:a,footer:n,children:i,className:r,variant:l}=t,x=l===void 0?"sidebar":l,c=ds(),y=o.useRef(null),[m,b]=o.useState(!1),[p,L]=o.useState(!1),k=x==="background"||c?"bg-background":"bg-sidebar",N=k==="bg-background"?"var(--surface-background)":"var(--surface-muted)";let h;e[0]===Symbol.for("react.memo_cache_sentinel")?(h=()=>{const v=y.current;if(!v){b(!1),L(!1);return}if(!(v.scrollHeight>v.clientHeight+1)){b(!1),L(!1);return}b(v.scrollTop>1),L(v.scrollTop+v.clientHeight<v.scrollHeight-1)},e[0]=h):h=e[0];const C=h;let u;e[1]===Symbol.for("react.memo_cache_sentinel")?(u=()=>{C()},e[1]=u):u=e[1];let E;e[2]!==i?(E=[i,C],e[2]=i,e[3]=E):E=e[3],o.useEffect(u,E);let q,M;e[4]===Symbol.for("react.memo_cache_sentinel")?(q=()=>{const v=y.current;if(!v)return;const K=()=>C();return v.addEventListener("scroll",K,{passive:!0}),()=>v.removeEventListener("scroll",K)},M=[C],e[4]=q,e[5]=M):(q=e[4],M=e[5]),o.useEffect(q,M);let I;e[6]!==k||e[7]!==r?(I=je("flex h-full flex-col",k,r),e[6]=k,e[7]=r,e[8]=I):I=e[8];let g;e[9]!==i?(g=s.jsx(Ds,{ref:y,outerClassName:"flex-1 min-h-0",className:"space-y-0.5 px-3 py-2 overflow-x-hidden",children:i}),e[9]=i,e[10]=g):g=e[10];let j;e[11]!==N||e[12]!==m?(j=m&&s.jsx("div",{className:"pointer-events-none absolute inset-x-0 top-0 h-4",style:{background:`linear-gradient(to bottom, ${N} 0%, transparent 100%)`}}),e[11]=N,e[12]=m,e[13]=j):j=e[13];let F;e[14]!==N||e[15]!==p?(F=p&&s.jsx("div",{className:"pointer-events-none absolute inset-x-0 bottom-0 h-6",style:{background:`linear-gradient(to top, ${N} 0%, transparent 100%)`}}),e[14]=N,e[15]=p,e[16]=F):F=e[16];let S;e[17]!==F||e[18]!==g||e[19]!==j?(S=s.jsxs("div",{className:"relative flex flex-1 min-h-0 flex-col",children:[g,j,F]}),e[17]=F,e[18]=g,e[19]=j,e[20]=S):S=e[20];let T;return e[21]!==n||e[22]!==a||e[23]!==S||e[24]!==I?(T=s.jsxs("div",{className:I,children:[a,S,n]}),e[21]=n,e[22]=a,e[23]=S,e[24]=I,e[25]=T):T=e[25],T},Ui=t=>{const e=ht.c(23),{title:a,metadata:n,selected:i,onSelect:r,icon:l,actions:x,className:c}=t,y=i===void 0?!1:i,m=x&&x.length>0,b=y?"bg-interactive-selection":"hover:bg-interactive-hover";let p;e[0]!==c||e[1]!==b?(p=je("group relative flex items-center rounded-md px-1.5 py-0.5 transition-all duration-200",b,c),e[0]=c,e[1]=b,e[2]=p):p=e[2];let L;e[3]!==a?(L=s.jsx("span",{className:"typography-ui-label font-normal truncate text-foreground",children:a}),e[3]=a,e[4]=L):L=e[4];let k;e[5]!==l||e[6]!==L?(k=s.jsxs("div",{className:"flex items-center gap-1.5",children:[l,L]}),e[5]=l,e[6]=L,e[7]=k):k=e[7];let N;e[8]!==n?(N=n&&s.jsx("div",{className:"typography-micro text-muted-foreground/60 truncate leading-tight",children:n}),e[8]=n,e[9]=N):N=e[9];let h;e[10]!==r||e[11]!==k||e[12]!==N?(h=s.jsxs("button",{onClick:r,className:"flex min-w-0 flex-1 flex-col gap-0 rounded-sm text-left focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-primary/50",tabIndex:0,children:[k,N]}),e[10]=r,e[11]=k,e[12]=N,e[13]=h):h=e[13];let C;e[14]!==x||e[15]!==m?(C=m&&s.jsxs(Hs,{children:[s.jsx($s,{asChild:!0,children:s.jsx(H,{size:"icon",variant:"ghost",className:"h-6 w-6 flex-shrink-0 -mr-1 opacity-100 transition-opacity md:opacity-0 md:group-hover:opacity-100",children:s.jsx(_,{name:"more-2",className:"h-3.5 w-3.5"})})}),s.jsx(Bs,{align:"end",className:"w-fit min-w-20",children:x.map(Rp)})]}),e[14]=x,e[15]=m,e[16]=C):C=e[16];let u;e[17]!==h||e[18]!==C?(u=s.jsxs("div",{className:"flex min-w-0 flex-1 items-center",children:[h,C]}),e[17]=h,e[18]=C,e[19]=u):u=e[19];let E;return e[20]!==p||e[21]!==u?(E=s.jsx("div",{className:p,children:u}),e[20]=p,e[21]=u,e[22]=E):E=e[22],E};function Rp(t){const e=t.icon;return s.jsxs(Gs,{onClick:a=>{a.stopPropagation(),t.onClick()},className:je(t.destructive&&"text-destructive focus:text-destructive"),children:[e&&s.jsx(_,{name:e,className:"h-4 w-4 mr-px"}),t.label]},t.label)}const Op=t=>t.parsedKind==="npm"?"code-box":"folder",Lp=t=>{const e=ht.c(144),{onItemSelect:a,onAddClick:n}=t,{t:i}=ot(),{entries:r,files:l,selectedId:x,setSelected:c,deleteEntry:y,deleteFile:m,loadPlugins:b}=us(Ps(Fp)),p=us(Kp),L=us(_p),k=us(zp),N=us(Up),[h,C]=o.useState(null),[u,E]=o.useState(!1),[q,M]=o.useState(!1);let I,g;e[0]!==b?(I=()=>{b()},g=[b],e[0]=b,e[1]=I,e[2]=g):(I=e[1],g=e[2]),o.useEffect(I,g);let j,F;e[3]===Symbol.for("react.memo_cache_sentinel")?(j=()=>{const ie=()=>M(!0);return window.addEventListener("openchamber:settings-open-plugin-add",ie),()=>window.removeEventListener("openchamber:settings-open-plugin-add",ie)},F=[],e[3]=j,e[4]=F):(j=e[3],F=e[4]),o.useEffect(j,F);let S;if(e[5]!==r||e[6]!==p){S={userEntries:0,projectEntries:0};for(const ie of r){const Ae=p[ie.spec];Ae?.kind==="npm-ok"&&Ae.hasUpdate&&(ie.scope==="user"?S.userEntries=S.userEntries+1:ie.scope==="project"&&(S.projectEntries=S.projectEntries+1))}e[5]=r,e[6]=p,e[7]=S}else S=e[7];const T=S;let v;e[8]!==r?(v=r.filter(Vp),e[8]=r,e[9]=v):v=e[9];const K=v;let $;e[10]!==r?($=r.filter($p),e[10]=r,e[11]=$):$=e[11];const w=$;let G;e[12]!==l?(G=l.filter(Bp),e[12]=l,e[13]=G):G=e[13];const Q=G;let X;e[14]!==l?(X=l.filter(Hp),e[14]=l,e[15]=X):X=e[15];const Z=X,P=r.length+l.length,ee=P===0;let se;e[16]!==n?(se=()=>{n?n():M(!0)},e[16]=n,e[17]=se):se=e[17];const D=se;let O;e[18]!==a||e[19]!==c?(O=ie=>{c(ie),a?.()},e[18]=a,e[19]=c,e[20]=O):O=e[20];const U=O;let A;e[21]!==r||e[22]!==p||e[23]!==i||e[24]!==N?(A=async ie=>{const Ae=r.find(xt=>xt.id===ie);if(!Ae)return;const Be=p[Ae.spec];if(!Be||Be.kind!=="npm-ok"||!Be.hasUpdate||!Be.latestVersion)return;const qe=Be.latestVersion;(await N(ie)).ok?R.success(i("settings.plugins.toast.updatedToLatest",{version:qe})):R.error(i("settings.plugins.toast.refreshFailed"))},e[21]=r,e[22]=p,e[23]=i,e[24]=N,e[25]=A):A=e[25];const V=A;let W;e[26]!==k||e[27]!==i?(W=async()=>{R.info(i("settings.plugins.toast.refreshing"));try{await k({force:!0})}catch{R.error(i("settings.plugins.toast.refreshFailed"))}},e[26]=k,e[27]=i,e[28]=W):W=e[28];const te=W;let ae;e[29]!==y||e[30]!==m||e[31]!==h||e[32]!==i?(ae=async()=>{if(!h)return;E(!0);const ie=h.kind==="entry"?await y(h.id):await m(h.id);ie.ok?R.success(ie.message||i("settings.plugins.sidebar.toast.deleted",{name:h.label})):R.error(i("settings.plugins.sidebar.toast.deleteFailed")),C(null),E(!1)},e[29]=y,e[30]=m,e[31]=h,e[32]=i,e[33]=ae):ae=e[33];const le=ae;let be;e[34]!==U||e[35]!==V||e[36]!==p||e[37]!==x||e[38]!==i?(be=ie=>{const Ae=p[ie.spec],Be=Ae?.kind==="npm-ok"&&Ae.hasUpdate&&!!Ae.latestVersion,qe=[];return Be&&qe.push({label:i("settings.plugins.sidebar.actions.updateToLatest"),icon:"arrow-up-s",onClick:()=>{V(ie.id)}}),qe.push({label:i("settings.common.actions.delete"),icon:"delete-bin",destructive:!0,onClick:()=>C({kind:"entry",id:ie.id,label:ie.spec})}),s.jsx(Ui,{title:s.jsxs("span",{className:"flex min-w-0 items-center gap-1.5",children:[s.jsx("span",{className:"min-w-0 flex-1 truncate",children:ie.spec}),s.jsx(Dp,{spec:ie.spec})]}),metadata:ie.parsedKind==="npm"?i("settings.plugins.sidebar.kind.npm"):i("settings.plugins.sidebar.kind.path"),selected:x===ie.id,onSelect:()=>U(ie.id),icon:s.jsx(_,{name:Op(ie),className:"h-4 w-4 flex-shrink-0 text-muted-foreground/70"}),actions:qe},ie.id)},e[34]=U,e[35]=V,e[36]=p,e[37]=x,e[38]=i,e[39]=be):be=e[39];const ke=be;let ce;e[40]!==U||e[41]!==x||e[42]!==i?(ce=ie=>s.jsx(Ui,{title:ie.fileName,metadata:i("settings.plugins.sidebar.kind.file"),selected:x===ie.id,onSelect:()=>U(ie.id),icon:s.jsx(_,{name:"file-text",className:"h-4 w-4 flex-shrink-0 text-muted-foreground/70"}),actions:[{label:i("settings.common.actions.delete"),icon:"delete-bin",destructive:!0,onClick:()=>C({kind:"file",id:ie.id,label:ie.fileName})}]},ie.id),e[40]=U,e[41]=x,e[42]=i,e[43]=ce):ce=e[43];const ge=ce;let Ee;e[44]!==i?(Ee=(ie,Ae,Be)=>{const qe=Be===void 0?0:Be;return s.jsxs(s.Fragment,{children:[s.jsxs("div",{className:"px-2 pb-1.5 pt-2 text-xs font-semibold uppercase tracking-wide text-muted-foreground",children:[ie,qe>0&&s.jsx("span",{className:"ml-2 normal-case font-normal text-[var(--status-success)]",children:i(qe===1?"settings.plugins.sidebar.group.updatesAvailable_one":"settings.plugins.sidebar.group.updatesAvailable_other",{count:qe})})]}),Ae]})},e[44]=i,e[45]=Ee):Ee=e[45];const Se=Ee;let Ne;e[46]!==i?(Ne=i("settings.plugins.sidebar.title"),e[46]=i,e[47]=Ne):Ne=e[47];let fe;e[48]!==Ne?(fe=s.jsx("div",{className:"mb-3 flex items-center justify-between gap-3",children:s.jsx("h2",{className:qs,children:Ne})}),e[48]=Ne,e[49]=fe):fe=e[49];let Ke;e[50]!==i||e[51]!==P?(Ke=i("settings.plugins.sidebar.total",{count:P}),e[50]=i,e[51]=P,e[52]=Ke):Ke=e[52];let De;e[53]!==Ke?(De=s.jsx("span",{className:"typography-meta text-muted-foreground",children:Ke}),e[53]=Ke,e[54]=De):De=e[54];let he;e[55]!==te?(he=()=>{te()},e[55]=te,e[56]=he):he=e[56];let pe;e[57]!==i?(pe=i("settings.plugins.sidebar.actions.refresh"),e[57]=i,e[58]=pe):pe=e[58];let Ie;e[59]!==i?(Ie=i("settings.plugins.sidebar.actions.refresh"),e[59]=i,e[60]=Ie):Ie=e[60];const ze=L?"size-4 animate-spin":"size-4";let Je;e[61]!==ze?(Je=s.jsx(_,{name:"refresh",className:ze}),e[61]=ze,e[62]=Je):Je=e[62];let _e;e[63]!==L||e[64]!==he||e[65]!==pe||e[66]!==Ie||e[67]!==Je?(_e=s.jsx(H,{type:"button","data-settings-item":"plugins.create",variant:"ghost",size:"icon",className:"h-7 w-7 -my-1 text-muted-foreground",onClick:he,disabled:L,"aria-label":pe,title:Ie,children:Je}),e[63]=L,e[64]=he,e[65]=pe,e[66]=Ie,e[67]=Je,e[68]=_e):_e=e[68];let Le;e[69]!==i?(Le=i("settings.plugins.sidebar.actions.addTitle"),e[69]=i,e[70]=Le):Le=e[70];let Pe;e[71]!==i?(Pe=i("settings.plugins.sidebar.actions.addTitle"),e[71]=i,e[72]=Pe):Pe=e[72];let Ye;e[73]===Symbol.for("react.memo_cache_sentinel")?(Ye=s.jsx(_,{name:"add",className:"size-4"}),e[73]=Ye):Ye=e[73];let Ge;e[74]!==D||e[75]!==Le||e[76]!==Pe?(Ge=s.jsx(H,{type:"button",variant:"ghost",size:"icon",className:"h-7 w-7 -my-1 text-muted-foreground",onClick:D,"aria-label":Le,title:Pe,children:Ye}),e[74]=D,e[75]=Le,e[76]=Pe,e[77]=Ge):Ge=e[77];let Me;e[78]!==_e||e[79]!==Ge?(Me=s.jsxs("div",{className:"flex items-center gap-1",children:[_e,Ge]}),e[78]=_e,e[79]=Ge,e[80]=Me):Me=e[80];let $e;e[81]!==De||e[82]!==Me?($e=s.jsxs("div",{className:"flex items-center justify-between gap-2",children:[De,Me]}),e[81]=De,e[82]=Me,e[83]=$e):$e=e[83];let Fe;e[84]!==fe||e[85]!==$e?(Fe=s.jsxs("div",{className:"border-b px-3 pt-4 pb-3",children:[fe,$e]}),e[84]=fe,e[85]=$e,e[86]=Fe):Fe=e[86];let ye;e[87]!==ee||e[88]!==w||e[89]!==Z||e[90]!==ke||e[91]!==ge||e[92]!==Se||e[93]!==i||e[94]!==T||e[95]!==K||e[96]!==Q?(ye=ee?s.jsxs("div",{className:"py-12 px-4 text-center text-muted-foreground",children:[s.jsx(_,{name:"plug",className:"mx-auto mb-3 h-10 w-10 opacity-50"}),s.jsx("p",{className:"typography-ui-label font-medium",children:i("settings.plugins.sidebar.empty.title")}),s.jsx("p",{className:"typography-meta mt-1 opacity-75",children:i("settings.plugins.sidebar.empty.description")})]}):s.jsxs(s.Fragment,{children:[K.length>0&&Se(i("settings.plugins.sidebar.group.userEntries"),K.map(ke),T.userEntries),Q.length>0&&Se(i("settings.plugins.sidebar.group.userFiles"),Q.map(ge)),w.length>0&&Se(i("settings.plugins.sidebar.group.projectEntries"),w.map(ke),T.projectEntries),Z.length>0&&Se(i("settings.plugins.sidebar.group.projectFiles"),Z.map(ge))]}),e[87]=ee,e[88]=w,e[89]=Z,e[90]=ke,e[91]=ge,e[92]=Se,e[93]=i,e[94]=T,e[95]=K,e[96]=Q,e[97]=ye):ye=e[97];let z;e[98]!==Fe||e[99]!==ye?(z=s.jsx(Xo,{variant:"background",header:Fe,children:ye}),e[98]=Fe,e[99]=ye,e[100]=z):z=e[100];let oe;e[101]!==q?(oe=s.jsx(Ep,{open:q,onOpenChange:M}),e[101]=q,e[102]=oe):oe=e[102];const me=h!==null;let ve;e[103]!==u?(ve=ie=>{!ie&&!u&&C(null)},e[103]=u,e[104]=ve):ve=e[104];let re;e[105]!==i?(re=i("settings.plugins.sidebar.deleteDialog.title"),e[105]=i,e[106]=re):re=e[106];let Ve;e[107]!==re?(Ve=s.jsx(Gt,{children:re}),e[107]=re,e[108]=Ve):Ve=e[108];const Ze=h?.label??"";let B;e[109]!==i||e[110]!==Ze?(B=i("settings.plugins.sidebar.deleteDialog.description",{name:Ze}),e[109]=i,e[110]=Ze,e[111]=B):B=e[111];let Ue;e[112]!==B?(Ue=s.jsx(qt,{children:B}),e[112]=B,e[113]=Ue):Ue=e[113];let Qe;e[114]!==Ve||e[115]!==Ue?(Qe=s.jsxs(Ht,{children:[Ve,Ue]}),e[114]=Ve,e[115]=Ue,e[116]=Qe):Qe=e[116];let et;e[117]===Symbol.for("react.memo_cache_sentinel")?(et=()=>C(null),e[117]=et):et=e[117];let tt;e[118]!==i?(tt=i("settings.common.actions.cancel"),e[118]=i,e[119]=tt):tt=e[119];let wt;e[120]!==u||e[121]!==tt?(wt=s.jsx(H,{size:"sm",variant:"ghost",onClick:et,disabled:u,children:tt}),e[120]=u,e[121]=tt,e[122]=wt):wt=e[122];let mt;e[123]!==u||e[124]!==i?(mt=i(u?"settings.plugins.sidebar.actions.deleting":"settings.common.actions.delete"),e[123]=u,e[124]=i,e[125]=mt):mt=e[125];let pt;e[126]!==le||e[127]!==u||e[128]!==mt?(pt=s.jsx(H,{size:"sm",variant:"destructive",onClick:le,disabled:u,children:mt}),e[126]=le,e[127]=u,e[128]=mt,e[129]=pt):pt=e[129];let at;e[130]!==wt||e[131]!==pt?(at=s.jsxs(os,{children:[wt,pt]}),e[130]=wt,e[131]=pt,e[132]=at):at=e[132];let ft;e[133]!==Qe||e[134]!==at?(ft=s.jsxs(Vt,{className:"max-w-md",children:[Qe,at]}),e[133]=Qe,e[134]=at,e[135]=ft):ft=e[135];let gt;e[136]!==me||e[137]!==ve||e[138]!==ft?(gt=s.jsx(Ut,{open:me,onOpenChange:ve,children:ft}),e[136]=me,e[137]=ve,e[138]=ft,e[139]=gt):gt=e[139];let Ct;return e[140]!==z||e[141]!==oe||e[142]!==gt?(Ct=s.jsxs(s.Fragment,{children:[z,oe,gt]}),e[140]=z,e[141]=oe,e[142]=gt,e[143]=Ct):Ct=e[143],Ct};function Fp(t){return{entries:t.entries,files:t.files,selectedId:t.selectedId,setSelected:t.setSelected,deleteEntry:t.deleteEntry,deleteFile:t.deleteFile,loadPlugins:t.loadPlugins}}function Kp(t){return t.registryInfo}function _p(t){return t.isLoadingRegistry}function zp(t){return t.loadRegistryInfo}function Up(t){return t.updateToLatest}function Vp(t){return t.scope==="user"}function $p(t){return t.scope==="project"}function Bp(t){return t.scope==="user"}function Hp(t){return t.scope==="project"}const Gp=({entryId:t,spec:e})=>{const{t:a}=ot(),n=us(b=>b.registryInfo[e]),i=us(b=>b.updateToLatest),[r,l]=o.useState(!1);if(!n)return null;if(n.kind==="npm-ok"){if(!n.hasUpdate||!n.latestVersion)return null;const b=n.latestVersion,p=n.currentVersion??"",L=async()=>{l(!0);try{(await i(t)).ok?R.success(a("settings.plugins.toast.updatedToLatest",{version:b})):R.error(a("settings.plugins.toast.refreshFailed"))}finally{l(!1)}};return s.jsxs("div",{className:"rounded-md border border-border bg-card p-3 flex items-start gap-3",children:[s.jsx(_,{name:"arrow-up",className:"h-5 w-5 text-[var(--status-success)] shrink-0 mt-0.5"}),s.jsxs("div",{className:"flex-1 min-w-0",children:[s.jsx("p",{className:"typography-label text-[var(--status-success)]",children:a("settings.plugins.registry.banner.updateAvailable.title")}),s.jsx("p",{className:"typography-micro text-muted-foreground mt-0.5",children:a("settings.plugins.registry.banner.updateAvailable.description",{current:p,latest:b})})]}),s.jsx(H,{variant:"default",size:"sm",onClick:()=>{L()},disabled:r,children:a("settings.plugins.registry.banner.updateAvailable.action",{latest:b})})]})}if(n.kind==="path-ok")return null;if(n.kind==="npm-network")return s.jsxs("div",{className:"rounded-md border border-border bg-card p-3 flex items-start gap-3",children:[s.jsx(_,{name:"cloud-off",className:"h-5 w-5 text-muted-foreground shrink-0 mt-0.5"}),s.jsx("div",{className:"flex-1 min-w-0",children:s.jsx("p",{className:"typography-micro text-muted-foreground",children:a("settings.plugins.registry.badge.network.tooltip")})})]});const x=n.kind==="path-unreadable",c=x?"var(--status-warning)":"var(--status-error)",y=x?"alert":"error-warning",m=(()=>{switch(n.kind){case"npm-missing-version":return a("settings.plugins.registry.banner.invalid.missingVersion");case"npm-missing-package":return a("settings.plugins.registry.banner.invalid.missingPackage");case"npm-malformed":return a("settings.plugins.registry.banner.invalid.malformed");case"path-missing":return a("settings.plugins.registry.banner.invalid.pathMissing");case"path-unreadable":return a("settings.plugins.registry.banner.invalid.pathUnreadable")}})();return s.jsxs("div",{className:"rounded-md border border-border bg-card p-3 flex items-start gap-3",children:[s.jsx(_,{name:y,className:"h-5 w-5 shrink-0 mt-0.5",style:{color:c}}),s.jsxs("div",{className:"flex-1 min-w-0",children:[s.jsx("p",{className:"typography-label",style:{color:c},children:a("settings.plugins.registry.banner.invalid.title")}),s.jsx("p",{className:"typography-micro text-muted-foreground mt-0.5",children:m})]})]})};function qp(t){const e=t.trim();if(e.length===0)return{ok:!0,value:void 0};try{const a=JSON.parse(e);return a===null||typeof a!="object"||Array.isArray(a)?{ok:!1}:{ok:!0,value:a}}catch{return{ok:!1}}}function el(t){return!t||Object.keys(t).length===0?"":JSON.stringify(t,null,2)}function $r(t){return{mode:"entry",scope:t.scope,spec:t.spec,optionsJson:el(t.options),fileName:"",content:""}}function Br(t,e){return{mode:"file",scope:t.scope,spec:"",optionsJson:"",fileName:t.fileName,content:e}}const Hr=t=>{const e=ht.c(4),{scope:a,label:n}=t;let i;e[0]===Symbol.for("react.memo_cache_sentinel")?(i=je("typography-micro font-medium rounded-full px-2 py-0.5","bg-[var(--surface-elevated)] text-muted-foreground","border border-[var(--interactive-border)]"),e[0]=i):i=e[0];let r;return e[1]!==n||e[2]!==a?(r=s.jsx("span",{className:i,"data-scope":a,children:n}),e[1]=n,e[2]=a,e[3]=r):r=e[3],r},Wp=()=>{const{t}=ot(),e=us(h=>h.selectedId),a=us(h=>h.entries),n=us(h=>h.files),i=us(h=>h.draft),r=us(h=>h.setDraft),l=us(h=>h.updateEntry),x=us(h=>h.updateFile),c=us(h=>h.readFile),y=o.useMemo(()=>e?a.find(h=>h.id===e)??null:null,[a,e]),m=o.useMemo(()=>e?n.find(h=>h.id===e)??null:null,[n,e]),[b,p]=o.useState(!1),[L,k]=o.useState(!1),N=o.useRef(new Map);if(o.useEffect(()=>{let h=!1;return y?(r($r(y)),()=>{h=!0}):m?(k(!0),(async()=>{const C=await c(m.id);if(h)return;k(!1);const u=C?.content??"";N.current.set(m.id,u),r(Br(m,u))})(),()=>{h=!0}):(r(null),()=>{h=!0})},[y,m,c,r]),!e)return s.jsx("div",{className:"flex h-full items-center justify-center",children:s.jsxs("div",{className:"text-center text-muted-foreground",children:[s.jsx(_,{name:"plug",className:"mx-auto mb-3 h-12 w-12 opacity-50"}),s.jsx("p",{className:"typography-body",children:t("settings.plugins.page.empty.select")}),s.jsx("p",{className:"typography-meta mt-1 opacity-75",children:t("settings.plugins.page.empty.add")})]})});if(y&&i&&i.mode==="entry"){const h=qp(i.optionsJson),C=h.ok,u=i.spec!==y.spec||i.optionsJson!==el(y.options),E=()=>{r($r(y))},q=async()=>{if(!C)return;const M=i.spec.trim();if(!M){R.error(t("settings.plugins.validation.specRequired"));return}p(!0);try{const I=await l(y.id,{spec:M,options:h.value});I.ok?I.reloadFailed?R.warning(I.message||t("settings.plugins.toast.reloadFailed"),{description:I.warning}):I.restartDeferred?R.success(t("settings.view.pendingRestart.saved")):R.success(I.message||t("settings.plugins.toast.updated")):R.error(I.message||t("settings.plugins.toast.reloadFailed"))}finally{p(!1)}};return s.jsxs(rs,{title:t("settings.plugins.page.header.entry"),titleAccessory:s.jsx(Hr,{scope:y.scope,label:y.scope==="project"?t("settings.plugins.sidebar.group.projectEntries"):t("settings.plugins.sidebar.group.userEntries")}),showSaveStatus:!1,children:[s.jsx(Oe,{divider:!1,children:s.jsx(Gp,{entryId:y.id,spec:y.spec})}),s.jsx(Oe,{title:t("settings.plugins.page.field.spec"),settingsItem:"plugins.spec",children:s.jsx(He,{value:i.spec,onChange:M=>r({...i,spec:M.target.value}),placeholder:t("settings.plugins.page.field.spec.placeholder"),className:"font-mono typography-meta",spellCheck:!1})}),s.jsxs(Oe,{title:t("settings.plugins.page.field.options"),settingsItem:"plugins.options",children:[s.jsx(Ns,{value:i.optionsJson,onChange:M=>r({...i,optionsJson:M.target.value}),rows:10,className:je("font-mono typography-meta min-h-[200px]",!C&&"border-[var(--status-error-border)]"),spellCheck:!1,placeholder:"{ }"}),!C&&s.jsx("p",{className:"typography-micro text-[var(--status-error)]",children:t("settings.plugins.page.field.options.invalidJson")}),s.jsxs("div",{className:"flex items-center gap-2 pt-3",children:[s.jsx(H,{variant:"default",size:"sm",onClick:()=>{q()},disabled:!u||!C||b,children:t("settings.plugins.page.action.save")}),s.jsx(H,{variant:"outline",size:"sm",onClick:E,disabled:!u||b,children:t("settings.plugins.page.action.discard")})]})]})]})}if(m&&i&&i.mode==="file"){const h=N.current.get(m.id)??"",C=i.content!==h||i.fileName!==m.fileName,u=()=>{(async()=>{k(!0);const M=(await c(m.id))?.content??"";k(!1),N.current.set(m.id,M),r(Br(m,M))})()},E=async()=>{p(!0);try{const q=await x(m.id,{content:i.content});q.ok?(N.current.set(m.id,i.content),q.reloadFailed?R.warning(q.message||t("settings.plugins.toast.reloadFailed"),{description:q.warning}):q.restartDeferred?R.success(t("settings.view.pendingRestart.saved")):R.success(q.message||t("settings.plugins.toast.updated"))):R.error(q.message||t("settings.plugins.toast.reloadFailed"))}finally{p(!1)}};return s.jsx(rs,{title:t("settings.plugins.page.header.file"),titleAccessory:s.jsxs(s.Fragment,{children:[s.jsx(Hr,{scope:m.scope,label:m.scope==="project"?t("settings.plugins.sidebar.group.projectFiles"):t("settings.plugins.sidebar.group.userFiles")}),s.jsx("span",{className:je("typography-micro font-mono rounded-full px-2 py-0.5","bg-[var(--surface-elevated)] text-foreground","border border-[var(--interactive-border)]"),children:m.fileName})]}),showSaveStatus:!1,children:s.jsxs(Oe,{title:t("settings.plugins.page.field.content"),divider:!1,settingsItem:"plugins.content",children:[s.jsx(Ns,{value:i.content,onChange:q=>r({...i,content:q.target.value}),rows:16,className:"font-mono typography-meta min-h-[320px]",spellCheck:!1,disabled:L}),s.jsxs("div",{className:"flex items-center gap-2 pt-3",children:[s.jsx(H,{variant:"default",size:"sm",onClick:()=>{E()},disabled:!C||b||L,children:t("settings.plugins.page.action.save")}),s.jsx(H,{variant:"outline",size:"sm",onClick:u,disabled:b||L,children:t("settings.plugins.page.action.discard")})]})]})})}return s.jsx("div",{className:"flex h-full items-center justify-center",children:s.jsx("div",{className:"text-center text-muted-foreground",children:s.jsx(_,{name:"loader-4",className:"mx-auto mb-3 h-6 w-6 animate-spin opacity-50"})})})},Jp="<built-in>",ha=t=>t?.path===Jp,Vi=t=>!!t&&!ha(t)&&t.renamable===!0,Qp=t=>{const e=ht.c(148),{onItemSelect:a}=t,{t:n}=ot(),[i,r]=o.useState(null),[l,x]=o.useState(""),[c,y]=o.useState(null),[m,b]=o.useState(!1),[p,L]=o.useState(null),{selectedSkillName:k,skills:N,setSelectedSkill:h,setSkillDraft:C,deleteSkill:u,renameSkill:E,getSkillDetail:q}=rn(Ps(Yp));let M;e[0]!==a||e[1]!==h||e[2]!==C||e[3]!==N?(M=()=>{let ie="new-skill",Ae=1;for(;N.some(Be=>Be.name===ie);)ie=`new-skill-${Ae}`,Ae++;C({name:ie,scope:"user",source:"opencode",description:""}),h(ie),a?.()},e[0]=a,e[1]=h,e[2]=C,e[3]=N,e[4]=M):M=e[4];const I=M;let g;e[5]===Symbol.for("react.memo_cache_sentinel")?(g=async ie=>{ha(ie)||y(ie)},e[5]=g):g=e[5];const j=g;let F;e[6]!==c||e[7]!==u||e[8]!==n?(F=async()=>{if(!c)return;if(ha(c)){y(null);return}b(!0),await u(c.name)?(R.success(n("settings.skills.sidebar.toast.skillDeleted",{name:c.name})),y(null)):R.error(n("settings.skills.sidebar.toast.deleteSkillFailed")),b(!1)},e[6]=c,e[7]=u,e[8]=n,e[9]=F):F=e[9];const S=F;let T;e[10]!==q||e[11]!==h||e[12]!==C||e[13]!==N||e[14]!==n?(T=async ie=>{if(ha(ie))return;const Ae=ie.name;let Be=1,qe=`${Ae}-copy`;for(;N.some(xt=>xt.name===qe);)Be++,qe=`${Ae}-copy-${Be}`;const Nt=await q(ie.name);if(!Nt){R.error(n("settings.skills.sidebar.toast.duplicateLoadFailed"));return}C({name:qe,scope:ie.scope||"user",source:ie.source||"opencode",description:(Nt.sources.md.fields.includes("description"),""),instructions:""}),h(qe)},e[10]=q,e[11]=h,e[12]=C,e[13]=N,e[14]=n,e[15]=T):T=e[15];const v=T;let K;e[16]===Symbol.for("react.memo_cache_sentinel")?(K=ie=>{Vi(ie)&&(x(ie.name),r(ie))},e[16]=K):K=e[16];const $=K;let w;e[17]!==i||e[18]!==l||e[19]!==E||e[20]!==h||e[21]!==N||e[22]!==n?(w=async()=>{if(!i)return;if(!Vi(i)){r(null);return}const ie=l.trim().replace(/\s+/g,"-").toLowerCase();if(!ie){R.error(n("settings.skills.page.toast.skillNameRequired"));return}if(ie===i.name){r(null);return}if(N.some(Be=>Be.name===ie)){R.error(n("settings.skills.page.toast.skillExists"));return}await E(i.name,ie)?(R.success(n("settings.skills.sidebar.toast.skillRenamed",{name:ie})),h(ie)):R.error(n("settings.skills.sidebar.toast.renameFailed")),r(null)},e[17]=i,e[18]=l,e[19]=E,e[20]=h,e[21]=N,e[22]=n,e[23]=w):w=e[23];const G=w;let Q;e[24]!==N?(Q=N.filter(Zp),e[24]=N,e[25]=Q):Q=e[25];const X=Q;let Z;e[26]!==N?(Z=N.filter(Xp),e[26]=N,e[27]=Z):Z=e[27];const P=Z;let ee;e[28]===Symbol.for("react.memo_cache_sentinel")?(ee=function(Ae){const Be={},qe=[];for(const xt of Ae)xt.group?(Be[xt.group]||(Be[xt.group]=[]),Be[xt.group].push(xt)):qe.push(xt);const Nt=Object.keys(Be).sort(em).map(xt=>({name:xt,skills:[...Be[xt]].sort(tm)}));return qe.sort(sm),{sortedGroups:Nt,ungrouped:qe}},e[28]=ee):ee=e[28];const se=ee;let D;e[29]!==X?(D=se(X),e[29]=X,e[30]=D):D=e[30];const O=D;let U;e[31]!==P?(U=se(P),e[31]=P,e[32]=U):U=e[32];const A=U;let V;e[33]===Symbol.for("react.memo_cache_sentinel")?(V=je("flex h-full flex-col","bg-background"),e[33]=V):V=e[33];let W;e[34]!==n?(W=n("settings.skills.sidebar.title"),e[34]=n,e[35]=W):W=e[35];let te;e[36]!==W?(te=s.jsx("h2",{className:`${qs} mb-3`,children:W}),e[36]=W,e[37]=te):te=e[37];let ae;e[38]===Symbol.for("react.memo_cache_sentinel")?(ae=s.jsx(ka,{className:"mb-3"}),e[38]=ae):ae=e[38];let le;e[39]!==N.length||e[40]!==n?(le=n("settings.skills.sidebar.total",{count:N.length}),e[39]=N.length,e[40]=n,e[41]=le):le=e[41];let be;e[42]!==le?(be=s.jsx("span",{className:"typography-meta text-muted-foreground",children:le}),e[42]=le,e[43]=be):be=e[43];let ke;e[44]===Symbol.for("react.memo_cache_sentinel")?(ke=s.jsx(_,{name:"add",className:"h-3.5 w-3.5"}),e[44]=ke):ke=e[44];let ce;e[45]!==I?(ce=s.jsx(H,{size:"sm","data-settings-item":"skills.create",variant:"ghost",className:"h-7 w-7 px-0 -my-1 text-muted-foreground",onClick:I,children:ke}),e[45]=I,e[46]=ce):ce=e[46];let ge;e[47]!==be||e[48]!==ce?(ge=s.jsxs("div",{className:"flex items-center justify-between gap-2",children:[be,ce]}),e[47]=be,e[48]=ce,e[49]=ge):ge=e[49];let Ee;e[50]!==te||e[51]!==ge?(Ee=s.jsxs("div",{className:"border-b px-3 pt-4 pb-3",children:[te,ae,ge]}),e[50]=te,e[51]=ge,e[52]=Ee):Ee=e[52];let Se;e[53]!==O||e[54]!==A||e[55]!==v||e[56]!==a||e[57]!==p||e[58]!==X||e[59]!==k||e[60]!==h||e[61]!==N.length||e[62]!==n||e[63]!==P?(Se=s.jsx(Ds,{outerClassName:"flex-1 min-h-0",className:"space-y-1 px-3 py-2 overflow-x-hidden",children:N.length===0?s.jsxs("div",{className:"py-12 px-4 text-center text-muted-foreground",children:[s.jsx(_,{name:"book-open",className:"mx-auto mb-3 h-10 w-10 opacity-50"}),s.jsx("p",{className:"typography-ui-label font-medium",children:n("settings.skills.sidebar.empty.title")}),s.jsx("p",{className:"typography-meta mt-1 opacity-75",children:n("settings.skills.sidebar.empty.description")})]}):s.jsxs(s.Fragment,{children:[X.length>0&&s.jsxs(s.Fragment,{children:[s.jsx("div",{className:"px-2 pb-1.5 pt-2 text-xs font-semibold uppercase tracking-wide text-muted-foreground",children:n("settings.skills.sidebar.section.project")}),O.sortedGroups.map(ie=>{const{name:Ae,skills:Be}=ie;return s.jsx(Fi,{label:Ae,count:Be.length,storageKey:"project-skills",children:Be.map(qe=>s.jsx(za,{skill:qe,isSelected:k===qe.name,onSelect:()=>{h(qe.name),a?.()},onRename:()=>$(qe),onDelete:()=>j(qe),onDuplicate:()=>v(qe),isMenuOpen:p===qe.name,onMenuOpenChange:Nt=>L(Nt?qe.name:null)},qe.name))},Ae)}),O.ungrouped.map(ie=>s.jsx(za,{skill:ie,isSelected:k===ie.name,onSelect:()=>{h(ie.name),a?.()},onRename:()=>$(ie),onDelete:()=>j(ie),onDuplicate:()=>v(ie),isMenuOpen:p===ie.name,onMenuOpenChange:Ae=>L(Ae?ie.name:null)},ie.name))]}),P.length>0&&s.jsxs(s.Fragment,{children:[s.jsx("div",{className:"px-2 pb-1.5 pt-3 text-xs font-semibold uppercase tracking-wide text-muted-foreground",children:n("settings.skills.sidebar.section.user")}),A.sortedGroups.map(ie=>{const{name:Ae,skills:Be}=ie;return s.jsx(Fi,{label:Ae,count:Be.length,storageKey:"user-skills",children:Be.map(qe=>s.jsx(za,{skill:qe,isSelected:k===qe.name,onSelect:()=>{h(qe.name),a?.()},onRename:()=>$(qe),onDelete:()=>j(qe),onDuplicate:()=>v(qe),isMenuOpen:p===qe.name,onMenuOpenChange:Nt=>L(Nt?qe.name:null)},qe.name))},Ae)}),A.ungrouped.map(ie=>s.jsx(za,{skill:ie,isSelected:k===ie.name,onSelect:()=>{h(ie.name),a?.()},onRename:()=>$(ie),onDelete:()=>j(ie),onDuplicate:()=>v(ie),isMenuOpen:p===ie.name,onMenuOpenChange:Ae=>L(Ae?ie.name:null)},ie.name))]})]})}),e[53]=O,e[54]=A,e[55]=v,e[56]=a,e[57]=p,e[58]=X,e[59]=k,e[60]=h,e[61]=N.length,e[62]=n,e[63]=P,e[64]=Se):Se=e[64];const Ne=c!==null;let fe;e[65]!==m?(fe=ie=>{!ie&&!m&&y(null)},e[65]=m,e[66]=fe):fe=e[66];let Ke;e[67]!==n?(Ke=n("settings.skills.sidebar.deleteDialog.title"),e[67]=n,e[68]=Ke):Ke=e[68];let De;e[69]!==Ke?(De=s.jsx(Gt,{children:Ke}),e[69]=Ke,e[70]=De):De=e[70];const he=c?.name??"";let pe;e[71]!==n||e[72]!==he?(pe=n("settings.skills.sidebar.deleteDialog.description",{name:he}),e[71]=n,e[72]=he,e[73]=pe):pe=e[73];let Ie;e[74]!==pe?(Ie=s.jsx(qt,{children:pe}),e[74]=pe,e[75]=Ie):Ie=e[75];let ze;e[76]!==De||e[77]!==Ie?(ze=s.jsxs(Ht,{children:[De,Ie]}),e[76]=De,e[77]=Ie,e[78]=ze):ze=e[78];let Je;e[79]===Symbol.for("react.memo_cache_sentinel")?(Je=()=>y(null),e[79]=Je):Je=e[79];let _e;e[80]!==n?(_e=n("settings.common.actions.cancel"),e[80]=n,e[81]=_e):_e=e[81];let Le;e[82]!==m||e[83]!==_e?(Le=s.jsx(H,{size:"sm",className:"text-foreground hover:bg-interactive-hover hover:text-foreground",variant:"ghost",onClick:Je,disabled:m,children:_e}),e[82]=m,e[83]=_e,e[84]=Le):Le=e[84];let Pe;e[85]!==n?(Pe=n("settings.common.actions.delete"),e[85]=n,e[86]=Pe):Pe=e[86];let Ye;e[87]!==S||e[88]!==m||e[89]!==Pe?(Ye=s.jsx(H,{size:"sm",onClick:S,disabled:m,children:Pe}),e[87]=S,e[88]=m,e[89]=Pe,e[90]=Ye):Ye=e[90];let Ge;e[91]!==Le||e[92]!==Ye?(Ge=s.jsxs(os,{children:[Le,Ye]}),e[91]=Le,e[92]=Ye,e[93]=Ge):Ge=e[93];let Me;e[94]!==ze||e[95]!==Ge?(Me=s.jsxs(Vt,{className:"max-w-md",children:[ze,Ge]}),e[94]=ze,e[95]=Ge,e[96]=Me):Me=e[96];let $e;e[97]!==Ne||e[98]!==fe||e[99]!==Me?($e=s.jsx(Ut,{open:Ne,onOpenChange:fe,children:Me}),e[97]=Ne,e[98]=fe,e[99]=Me,e[100]=$e):$e=e[100];const Fe=i!==null;let ye;e[101]===Symbol.for("react.memo_cache_sentinel")?(ye=ie=>!ie&&r(null),e[101]=ye):ye=e[101];let z;e[102]!==n?(z=n("settings.skills.sidebar.renameDialog.title"),e[102]=n,e[103]=z):z=e[103];let oe;e[104]!==z?(oe=s.jsx(Gt,{children:z}),e[104]=z,e[105]=oe):oe=e[105];const me=i?.name??"";let ve;e[106]!==n||e[107]!==me?(ve=n("settings.skills.sidebar.renameDialog.description",{name:me}),e[106]=n,e[107]=me,e[108]=ve):ve=e[108];let re;e[109]!==ve?(re=s.jsx(qt,{children:ve}),e[109]=ve,e[110]=re):re=e[110];let Ve;e[111]!==oe||e[112]!==re?(Ve=s.jsxs(Ht,{children:[oe,re]}),e[111]=oe,e[112]=re,e[113]=Ve):Ve=e[113];let Ze;e[114]===Symbol.for("react.memo_cache_sentinel")?(Ze=ie=>x(ie.target.value),e[114]=Ze):Ze=e[114];let B;e[115]!==n?(B=n("settings.skills.sidebar.renameDialog.placeholder"),e[115]=n,e[116]=B):B=e[116];let Ue;e[117]!==G?(Ue=ie=>{ie.key==="Enter"&&G()},e[117]=G,e[118]=Ue):Ue=e[118];let Qe;e[119]!==l||e[120]!==B||e[121]!==Ue?(Qe=s.jsx(He,{value:l,onChange:Ze,placeholder:B,className:"text-foreground placeholder:text-muted-foreground",onKeyDown:Ue}),e[119]=l,e[120]=B,e[121]=Ue,e[122]=Qe):Qe=e[122];let et;e[123]===Symbol.for("react.memo_cache_sentinel")?(et=()=>r(null),e[123]=et):et=e[123];let tt;e[124]!==n?(tt=n("settings.common.actions.cancel"),e[124]=n,e[125]=tt):tt=e[125];let wt;e[126]!==tt?(wt=s.jsx(H,{size:"sm",className:"text-foreground hover:bg-interactive-hover hover:text-foreground",variant:"ghost",onClick:et,children:tt}),e[126]=tt,e[127]=wt):wt=e[127];let mt;e[128]!==n?(mt=n("settings.common.actions.rename"),e[128]=n,e[129]=mt):mt=e[129];let pt;e[130]!==G||e[131]!==mt?(pt=s.jsx(H,{size:"sm",onClick:G,children:mt}),e[130]=G,e[131]=mt,e[132]=pt):pt=e[132];let at;e[133]!==wt||e[134]!==pt?(at=s.jsxs(os,{children:[wt,pt]}),e[133]=wt,e[134]=pt,e[135]=at):at=e[135];let ft;e[136]!==Ve||e[137]!==Qe||e[138]!==at?(ft=s.jsxs(Vt,{children:[Ve,Qe,at]}),e[136]=Ve,e[137]=Qe,e[138]=at,e[139]=ft):ft=e[139];let gt;e[140]!==Fe||e[141]!==ft?(gt=s.jsx(Ut,{open:Fe,onOpenChange:ye,children:ft}),e[140]=Fe,e[141]=ft,e[142]=gt):gt=e[142];let Ct;return e[143]!==Ee||e[144]!==Se||e[145]!==$e||e[146]!==gt?(Ct=s.jsxs("div",{className:V,children:[Ee,Se,$e,gt]}),e[143]=Ee,e[144]=Se,e[145]=$e,e[146]=gt,e[147]=Ct):Ct=e[147],Ct},za=t=>{const e=ht.c(52),{skill:a,isSelected:n,onSelect:i,onDelete:r,onRename:l,onDuplicate:x,isMenuOpen:c,onMenuOpenChange:y}=t,{t:m}=ot();let b;e[0]===Symbol.for("react.memo_cache_sentinel")?(b=xa(),e[0]=b):b=e[0];const p=b;let L;e[1]!==a.source||e[2]!==m?(L=a.source==="claude"?m("settings.skills.sidebar.badge.claude"):a.source==="agents"?m("settings.skills.sidebar.badge.agents"):m("settings.skills.sidebar.badge.opencode"),e[1]=a.source,e[2]=m,e[3]=L):L=e[3];const k=L;let N;e[4]!==a?(N=ha(a),e[4]=a,e[5]=N):N=e[5];const h=N;let C;e[6]!==a?(C=Vi(a),e[6]=a,e[7]=C):C=e[7];const u=C,[E,q]=o.useState(!1);let M;e[8]!==u||e[9]!==r||e[10]!==x||e[11]!==l||e[12]!==m?(M=se=>s.jsxs(s.Fragment,{children:[u?s.jsxs(se,{onClick:D=>{D.stopPropagation(),l()},children:[s.jsx(_,{name:"edit",className:"h-4 w-4 mr-px"}),m("settings.common.actions.rename")]}):null,s.jsxs(se,{onClick:D=>{D.stopPropagation(),x()},children:[s.jsx(_,{name:"file-copy",className:"h-4 w-4 mr-px"}),m("settings.common.actions.duplicate")]}),s.jsxs(se,{onClick:D=>{D.stopPropagation(),r()},className:"text-destructive focus:text-destructive",children:[s.jsx(_,{name:"delete-bin",className:"h-4 w-4 mr-px"}),m("settings.common.actions.delete")]})]}),e[8]=u,e[9]=r,e[10]=x,e[11]=l,e[12]=m,e[13]=M):M=e[13];const I=M,g=!h&&E,j=n?"bg-interactive-selection":"hover:bg-interactive-hover";let F;e[14]!==j?(F=je("group relative flex items-center rounded-md px-1.5 py-1 transition-all duration-200 select-none",j),e[14]=j,e[15]=F):F=e[15];let S;e[16]!==h?(S=!p&&!h?se=>{se.preventDefault(),q(!0)}:void 0,e[16]=h,e[17]=S):S=e[17];let T;e[18]!==F||e[19]!==S?(T=s.jsx("div",{className:F,onContextMenu:S}),e[18]=F,e[19]=S,e[20]=T):T=e[20];let v;e[21]!==a.name?(v=s.jsx("span",{className:"typography-ui-label font-normal truncate text-foreground",children:a.name}),e[21]=a.name,e[22]=v):v=e[22];let K;e[23]!==a.scope?(K=s.jsx("span",{className:"typography-micro text-muted-foreground bg-[var(--surface-muted)] px-1 rounded flex-shrink-0 leading-none pb-px border border-[var(--interactive-border)]/50",children:a.scope}),e[23]=a.scope,e[24]=K):K=e[24];let $;e[25]!==k?($=s.jsx("span",{className:"typography-micro text-muted-foreground bg-[var(--surface-muted)] px-1 rounded flex-shrink-0 leading-none pb-px border border-[var(--interactive-border)]/50",children:k}),e[25]=k,e[26]=$):$=e[26];let w;e[27]!==v||e[28]!==K||e[29]!==$?(w=s.jsxs("div",{className:"flex items-center gap-1.5",children:[v,K,$]}),e[27]=v,e[28]=K,e[29]=$,e[30]=w):w=e[30];let G;e[31]!==i||e[32]!==w?(G=s.jsx("button",{onClick:i,className:"flex min-w-0 flex-1 flex-col gap-0 rounded-sm text-left focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-primary/50",tabIndex:0,children:w}),e[31]=i,e[32]=w,e[33]=G):G=e[33];let Q;e[34]!==h||e[35]!==c||e[36]!==y||e[37]!==I?(Q=h?null:s.jsxs(Hs,{open:c,onOpenChange:se=>{se&&q(!1),y(se)},children:[s.jsx($s,{asChild:!0,children:s.jsx(H,{size:"sm",variant:"ghost",className:"h-6 w-6 px-0 flex-shrink-0 -mr-1 opacity-100 transition-opacity md:opacity-0 md:group-hover:opacity-100",children:s.jsx(_,{name:"more-2",className:"h-3.5 w-3.5"})})}),s.jsx(Bs,{align:"end",className:"w-fit min-w-20",children:I(Gs)})]}),e[34]=h,e[35]=c,e[36]=y,e[37]=I,e[38]=Q):Q=e[38];let X;e[39]!==G||e[40]!==Q?(X=s.jsxs("div",{className:"flex min-w-0 flex-1 items-center",children:[G,Q]}),e[39]=G,e[40]=Q,e[41]=X):X=e[41];let Z;e[42]!==T||e[43]!==X?(Z=s.jsx(Rn,{render:T,children:X}),e[42]=T,e[43]=X,e[44]=Z):Z=e[44];let P;e[45]!==h||e[46]!==I?(P=h?null:s.jsx(Dn,{className:"w-fit min-w-20",children:I(Mn)}),e[45]=h,e[46]=I,e[47]=P):P=e[47];let ee;return e[48]!==Z||e[49]!==P||e[50]!==g?(ee=s.jsxs(On,{open:g,onOpenChange:q,children:[Z,P]}),e[48]=Z,e[49]=P,e[50]=g,e[51]=ee):ee=e[51],ee};function Yp(t){return{selectedSkillName:t.selectedSkillName,skills:t.skills,setSelectedSkill:t.setSelectedSkill,setSkillDraft:t.setSkillDraft,deleteSkill:t.deleteSkill,renameSkill:t.renameSkill,getSkillDetail:t.getSkillDetail}}function Zp(t){return t.scope==="project"}function Xp(t){return t.scope==="user"}function em(t,e){return t.localeCompare(e)}function tm(t,e){return t.name.localeCompare(e.name)}function sm(t,e){return t.name.localeCompare(e.name)}const nm=()=>`custom:${Date.now()}-${Math.random().toString(16).slice(2)}`,am=t=>{const e=t.trim(),a=e.startsWith("https://")?"https":e.startsWith("git@")?"ssh":"shorthand";if(a==="ssh")return`${e.split(":")[1].replace(/\.git$/i,"")}`;if(a==="https")return e.split("/").slice(3).filter(Boolean).join("/").replace(/\.git$/i,"");const n=e.match(/^([^/\s]+)\/([^/\s]+)(?:\/.+)?$/);return n?`${n[1]}/${n[2].replace(/\.git$/i,"")}`:e},im=async()=>{try{const t=jn()?.settings;if(t)return(await t.load())?.settings||{};const e=await ct("/api/config/settings",{method:"GET",headers:{Accept:"application/json"}});return e.ok?await e.json().catch(()=>null):null}catch{return null}},rm=t=>{const e=ht.c(162),{open:a,onOpenChange:n}=t,{t:i}=ot(),r=an(om),l=an(lm),x=an(cm),c=an(dm),y=an(pm),m=An(mm),b=An(um),[p,L]=o.useState(""),[k,N]=o.useState(""),[h,C]=o.useState("");let u;e[0]===Symbol.for("react.memo_cache_sentinel")?(u=[],e[0]=u):u=e[0];const[E,q]=o.useState(u),[M,I]=o.useState(null),[g,j]=o.useState(!1);let F;e[1]===Symbol.for("react.memo_cache_sentinel")?(F=[],e[1]=F):F=e[1];const[S,T]=o.useState(F),[v,K]=o.useState(null),$=o.useRef(0);let w;e[2]===Symbol.for("react.memo_cache_sentinel")?(w=Ae=>{$.current=$.current+1,j(!1),I(null),Ae?.clearIdentity&&(T([]),K(null))},e[2]=w):w=e[2];const G=w;let Q,X;e[3]!==b||e[4]!==a?(Q=()=>{a&&($.current=$.current+1,L(""),N(""),C(""),I(null),j(!1),T([]),K(null),b(),(async()=>{const Ae=await im(),Be=Array.isArray(Ae?.skillCatalogs)?Ae?.skillCatalogs:[];q(Be||[])})())},X=[a,b],e[3]=b,e[4]=a,e[5]=Q,e[6]=X):(Q=e[5],X=e[6]),o.useEffect(Q,X);let Z;e[7]!==k?(Z=k.trim(),e[7]=k,e[8]=Z):Z=e[8];const P=Z;let ee;e[9]!==h?(ee=h.trim(),e[9]=h,e[10]=ee):ee=e[10];const se=ee;let D;if(e[11]!==E||e[12]!==P||e[13]!==se){let Ae;e[15]!==P||e[16]!==se?(Ae=Be=>{const qe=(Be.source||"").trim(),Nt=(Be.subpath||"").trim();return qe===P&&Nt===se},e[15]=P,e[16]=se,e[17]=Ae):Ae=e[17],D=E.some(Ae),e[11]=E,e[12]=P,e[13]=se,e[14]=D}else D=e[14];const O=D;let U;e[18]!==m||e[19]!==v||e[20]!==p||e[21]!==r||e[22]!==k||e[23]!==h||e[24]!==i?(U=async()=>{const Ae=k.trim();if(!Ae){R.error(i("settings.skills.catalog.add.toast.repositoryRequired"));return}p.trim()||L(am(Ae)),j(!1),I(null);const Be=$.current+1;$.current=Be;const qe=await r({source:Ae,subpath:h.trim()||void 0,gitIdentityId:v||void 0});if($.current!==Be)return;if(!qe.ok){if(qe.error?.kind==="authRequired"){if(ds()){R.error(i("settings.skills.catalog.shared.toast.privateRepoNotSupportedVsCode"));return}const xt=qe.error.identities||[];if(T(xt),!v&&xt.length>0){const zt=m&&m!=="global"&&xt.some(J=>J.id===m)?m:xt[0].id;K(zt)}R.error(i("settings.skills.catalog.add.toast.authenticationRequiredScan"));return}R.error(qe.error?.message||i("settings.skills.catalog.add.toast.scanFailed"));return}const Nt=qe.items?.length||0;if(I(Nt),Nt===0){R.error(i("settings.skills.catalog.add.toast.noSkillsFound")),j(!1);return}T([]),j(!0),R.success(i("settings.skills.catalog.shared.toast.foundSkills",{count:Nt}))},e[18]=m,e[19]=v,e[20]=p,e[21]=r,e[22]=k,e[23]=h,e[24]=i,e[25]=U):U=e[25];const A=U;let V;e[26]!==E||e[27]!==v||e[28]!==O||e[29]!==p||e[30]!==l||e[31]!==x||e[32]!==n||e[33]!==g||e[34]!==c||e[35]!==k||e[36]!==h||e[37]!==i?(V=async()=>{const Ae=p.trim(),Be=k.trim(),qe=h.trim();if(!Ae){R.error(i("settings.skills.catalog.add.toast.catalogNameRequired"));return}if(!Be){R.error(i("settings.skills.catalog.add.toast.repositoryRequired"));return}if(!g){R.error(i("settings.skills.catalog.add.toast.scanBeforeAdd"));return}if(O){R.error(i("settings.skills.catalog.add.toast.catalogAlreadyExists"));return}const Nt={id:nm(),label:Ae,source:Be,...qe?{subpath:qe}:{},...v?{gitIdentityId:v}:{}},xt=[...E,Nt];try{await yt({skillCatalogs:xt}),q(xt),R.success(i("settings.skills.catalog.add.toast.catalogAdded")),await l({refresh:!0}),await x(Nt.id,{refresh:!0}),c(Nt.id),n(!1)}catch(zt){const J=zt;R.error(J instanceof Error?J.message:i("settings.skills.catalog.add.toast.saveFailed"))}},e[26]=E,e[27]=v,e[28]=O,e[29]=p,e[30]=l,e[31]=x,e[32]=n,e[33]=g,e[34]=c,e[35]=k,e[36]=h,e[37]=i,e[38]=V):V=e[38];const W=V;let te;e[39]!==i?(te=i("settings.skills.catalog.add.title"),e[39]=i,e[40]=te):te=e[40];let ae;e[41]!==te?(ae=s.jsx(Gt,{children:te}),e[41]=te,e[42]=ae):ae=e[42];let le;e[43]!==i?(le=i("settings.skills.catalog.add.descriptionPrefix"),e[43]=i,e[44]=le):le=e[44];let be;e[45]===Symbol.for("react.memo_cache_sentinel")?(be=s.jsx("code",{className:"font-mono",children:"SKILL.md"}),e[45]=be):be=e[45];let ke;e[46]!==i?(ke=i("settings.skills.catalog.add.descriptionSuffix"),e[46]=i,e[47]=ke):ke=e[47];let ce;e[48]!==le||e[49]!==ke?(ce=s.jsxs(qt,{children:[le," ",be,ke]}),e[48]=le,e[49]=ke,e[50]=ce):ce=e[50];let ge;e[51]!==ae||e[52]!==ce?(ge=s.jsxs(Ht,{children:[ae,ce]}),e[51]=ae,e[52]=ce,e[53]=ge):ge=e[53];let Ee;e[54]!==i?(Ee=i("settings.skills.catalog.add.field.catalogName"),e[54]=i,e[55]=Ee):Ee=e[55];let Se;e[56]!==Ee?(Se=s.jsx("label",{className:"typography-ui-label text-foreground",children:Ee}),e[56]=Ee,e[57]=Se):Se=e[57];let Ne;e[58]===Symbol.for("react.memo_cache_sentinel")?(Ne=Ae=>L(Ae.target.value),e[58]=Ne):Ne=e[58];let fe;e[59]!==i?(fe=i("settings.skills.catalog.add.field.catalogNamePlaceholder"),e[59]=i,e[60]=fe):fe=e[60];let Ke;e[61]!==p||e[62]!==fe?(Ke=s.jsx(He,{value:p,onChange:Ne,placeholder:fe}),e[61]=p,e[62]=fe,e[63]=Ke):Ke=e[63];let De;e[64]!==Se||e[65]!==Ke?(De=s.jsxs("div",{className:"space-y-2",children:[Se,Ke]}),e[64]=Se,e[65]=Ke,e[66]=De):De=e[66];let he;e[67]!==i?(he=i("settings.skills.catalog.add.field.repository"),e[67]=i,e[68]=he):he=e[68];let pe;e[69]!==he?(pe=s.jsx("label",{className:"typography-ui-label text-foreground",children:he}),e[69]=he,e[70]=pe):pe=e[70];let Ie;e[71]!==i?(Ie=i("settings.skills.catalog.add.field.repositoryHint"),e[71]=i,e[72]=Ie):Ie=e[72];let ze;e[73]!==Ie?(ze=s.jsx(Yt,{children:Ie}),e[73]=Ie,e[74]=ze):ze=e[74];let Je;e[75]!==pe||e[76]!==ze?(Je=s.jsxs("div",{className:"flex items-center gap-1",children:[pe,ze]}),e[75]=pe,e[76]=ze,e[77]=Je):Je=e[77];let _e;e[78]===Symbol.for("react.memo_cache_sentinel")?(_e=Ae=>{N(Ae.target.value),G({clearIdentity:!0})},e[78]=_e):_e=e[78];let Le;e[79]!==i?(Le=i("settings.skills.catalog.shared.field.repositoryPlaceholder"),e[79]=i,e[80]=Le):Le=e[80];let Pe;e[81]!==k||e[82]!==Le?(Pe=s.jsx(He,{value:k,onChange:_e,placeholder:Le}),e[81]=k,e[82]=Le,e[83]=Pe):Pe=e[83];let Ye;e[84]!==Je||e[85]!==Pe?(Ye=s.jsxs("div",{className:"space-y-2",children:[Je,Pe]}),e[84]=Je,e[85]=Pe,e[86]=Ye):Ye=e[86];let Ge;e[87]!==i?(Ge=i("settings.skills.catalog.add.field.optionalSubpath"),e[87]=i,e[88]=Ge):Ge=e[88];let Me;e[89]!==Ge?(Me=s.jsx("label",{className:"typography-ui-label text-foreground",children:Ge}),e[89]=Ge,e[90]=Me):Me=e[90];let $e;e[91]===Symbol.for("react.memo_cache_sentinel")?($e=Ae=>{C(Ae.target.value),G({clearIdentity:!0})},e[91]=$e):$e=e[91];let Fe;e[92]!==i?(Fe=i("settings.skills.catalog.shared.field.subpathPlaceholder"),e[92]=i,e[93]=Fe):Fe=e[93];let ye;e[94]!==h||e[95]!==Fe?(ye=s.jsx(He,{value:h,onChange:$e,placeholder:Fe}),e[94]=h,e[95]=Fe,e[96]=ye):ye=e[96];let z;e[97]!==Me||e[98]!==ye?(z=s.jsxs("div",{className:"space-y-2",children:[Me,ye]}),e[97]=Me,e[98]=ye,e[99]=z):z=e[99];let oe;e[100]!==v||e[101]!==S||e[102]!==i?(oe=S.length>0&&!ds()?s.jsxs("div",{className:"space-y-2",children:[s.jsxs("div",{className:"flex items-center",children:[s.jsx("span",{className:"typography-ui-label text-[var(--status-warning)]",children:i("settings.skills.catalog.shared.auth.title")}),s.jsx("span",{className:"typography-meta text-muted-foreground ml-2",children:i("settings.skills.catalog.shared.auth.description")}),s.jsx(Yt,{className:"ml-1",children:i("settings.skills.catalog.shared.auth.footerHint")})]}),s.jsxs(Dt,{value:v||"",onValueChange:Ae=>{K(Ae),G()},children:[s.jsx(Mt,{className:"w-fit",children:s.jsx("span",{children:S.find(Ae=>Ae.id===v)?.name||i("settings.skills.catalog.shared.auth.chooseIdentity")})}),s.jsx(Rt,{align:"start",children:S.map(gm)})]})]}):null,e[100]=v,e[101]=S,e[102]=i,e[103]=oe):oe=e[103];let me;e[104]!==M||e[105]!==i?(me=M!==null?s.jsx("div",{className:"typography-meta text-muted-foreground",children:i("settings.skills.catalog.add.scanResult",{count:M})}):null,e[104]=M,e[105]=i,e[106]=me):me=e[106];let ve;e[107]!==O||e[108]!==i?(ve=O?s.jsx("div",{className:"typography-meta text-muted-foreground",children:i("settings.skills.catalog.add.duplicateMessage")}):null,e[107]=O,e[108]=i,e[109]=ve):ve=e[109];let re;e[110]!==De||e[111]!==Ye||e[112]!==z||e[113]!==oe||e[114]!==me||e[115]!==ve?(re=s.jsxs("div",{className:"space-y-4",children:[De,Ye,z,oe,me,ve]}),e[110]=De,e[111]=Ye,e[112]=z,e[113]=oe,e[114]=me,e[115]=ve,e[116]=re):re=e[116];let Ve;e[117]!==n?(Ve=()=>n(!1),e[117]=n,e[118]=Ve):Ve=e[118];let Ze;e[119]!==i?(Ze=i("settings.common.actions.cancel"),e[119]=i,e[120]=Ze):Ze=e[120];let B;e[121]!==Ve||e[122]!==Ze?(B=s.jsx(H,{size:"sm",variant:"ghost",onClick:Ve,children:Ze}),e[121]=Ve,e[122]=Ze,e[123]=B):B=e[123];let Ue;e[124]!==A?(Ue=()=>{A()},e[124]=A,e[125]=Ue):Ue=e[125];let Qe;e[126]!==y||e[127]!==k?(Qe=y||!k.trim(),e[126]=y,e[127]=k,e[128]=Qe):Qe=e[128];let et;e[129]===Symbol.for("react.memo_cache_sentinel")?(et=s.jsx(_,{name:"git-repository",className:"h-4 w-4"}),e[129]=et):et=e[129];let tt;e[130]!==y||e[131]!==i?(tt=i(y?"settings.skills.catalog.shared.actions.scanning":"settings.skills.catalog.shared.actions.scan"),e[130]=y,e[131]=i,e[132]=tt):tt=e[132];let wt;e[133]!==Ue||e[134]!==Qe||e[135]!==tt?(wt=s.jsxs(H,{size:"sm",className:"gap-2",variant:"ghost",onClick:Ue,disabled:Qe,children:[et,tt]}),e[133]=Ue,e[134]=Qe,e[135]=tt,e[136]=wt):wt=e[136];let mt;e[137]!==W?(mt=()=>{W()},e[137]=W,e[138]=mt):mt=e[138];let pt;e[139]!==O||e[140]!==p||e[141]!==g||e[142]!==k?(pt=!g||O||!p.trim()||!k.trim(),e[139]=O,e[140]=p,e[141]=g,e[142]=k,e[143]=pt):pt=e[143];let at;e[144]!==i?(at=i("settings.skills.catalog.add.actions.addCatalog"),e[144]=i,e[145]=at):at=e[145];let ft;e[146]!==mt||e[147]!==pt||e[148]!==at?(ft=s.jsx(H,{size:"sm",onClick:mt,disabled:pt,children:at}),e[146]=mt,e[147]=pt,e[148]=at,e[149]=ft):ft=e[149];let gt;e[150]!==B||e[151]!==wt||e[152]!==ft?(gt=s.jsxs(os,{children:[B,wt,ft]}),e[150]=B,e[151]=wt,e[152]=ft,e[153]=gt):gt=e[153];let Ct;e[154]!==ge||e[155]!==re||e[156]!==gt?(Ct=s.jsxs(Vt,{className:"max-w-xl",children:[ge,re,gt]}),e[154]=ge,e[155]=re,e[156]=gt,e[157]=Ct):Ct=e[157];let ie;return e[158]!==n||e[159]!==a||e[160]!==Ct?(ie=s.jsx(Ut,{open:a,onOpenChange:n,children:Ct}),e[158]=n,e[159]=a,e[160]=Ct,e[161]=ie):ie=e[161],ie};function om(t){return t.scanRepo}function lm(t){return t.loadCatalog}function cm(t){return t.loadSource}function dm(t){return t.setSelectedSource}function pm(t){return t.isScanning}function mm(t){return t.defaultGitIdentityId}function um(t){return t.loadDefaultGitIdentityId}function gm(t){return s.jsx(dt,{value:t.id,children:t.name},t.id)}const hm=t=>{const e=ht.c(85),{open:a,onOpenChange:n,conflicts:i,onConfirm:r}=t,{t:l}=ot();let x;e[0]===Symbol.for("react.memo_cache_sentinel")?(x={},e[0]=x):x=e[0];const[c,y]=o.useState(x);let m,b;e[1]!==i||e[2]!==a?(m=()=>{if(!a)return;const W={};for(const te of i)W[te.skillName]="skip";y(W)},b=[a,i],e[1]=i,e[2]=a,e[3]=m,e[4]=b):(m=e[3],b=e[4]),o.useEffect(m,b);let p;e[5]!==i?(p=W=>{const te={};for(const ae of i)te[ae.skillName]=W;y(te)},e[5]=i,e[6]=p):p=e[6];const L=p;let k;e[7]!==i||e[8]!==c?(k=i.length>0&&i.every(W=>c[W.skillName]),e[7]=i,e[8]=c,e[9]=k):k=e[9];const N=k;let h;e[10]!==l?(h=l("settings.skills.catalog.conflicts.title"),e[10]=l,e[11]=h):h=e[11];let C;e[12]!==h?(C=s.jsx(Gt,{children:h}),e[12]=h,e[13]=C):C=e[13];let u;e[14]!==l?(u=l("settings.skills.catalog.conflicts.description"),e[14]=l,e[15]=u):u=e[15];let E;e[16]!==u?(E=s.jsx(qt,{children:u}),e[16]=u,e[17]=E):E=e[17];let q;e[18]!==C||e[19]!==E?(q=s.jsxs(Ht,{children:[C,E]}),e[18]=C,e[19]=E,e[20]=q):q=e[20];let M;e[21]!==i.length||e[22]!==l?(M=l("settings.skills.catalog.conflicts.count",{count:i.length}),e[21]=i.length,e[22]=l,e[23]=M):M=e[23];let I;e[24]!==M?(I=s.jsx("span",{className:"typography-meta text-muted-foreground",children:M}),e[24]=M,e[25]=I):I=e[25];let g;e[26]!==L?(g=()=>L("skip"),e[26]=L,e[27]=g):g=e[27];let j;e[28]!==l?(j=l("settings.skills.catalog.conflicts.actions.skipAll"),e[28]=l,e[29]=j):j=e[29];let F;e[30]!==g||e[31]!==j?(F=s.jsx(H,{variant:"outline",size:"xs",className:"!font-normal",onClick:g,children:j}),e[30]=g,e[31]=j,e[32]=F):F=e[32];let S;e[33]!==L?(S=()=>L("overwrite"),e[33]=L,e[34]=S):S=e[34];let T;e[35]!==l?(T=l("settings.skills.catalog.conflicts.actions.overwriteAll"),e[35]=l,e[36]=T):T=e[36];let v;e[37]!==S||e[38]!==T?(v=s.jsx(H,{variant:"outline",size:"xs",className:"!font-normal",onClick:S,children:T}),e[37]=S,e[38]=T,e[39]=v):v=e[39];let K;e[40]!==F||e[41]!==v?(K=s.jsxs("div",{className:"flex items-center gap-2",children:[F,v]}),e[40]=F,e[41]=v,e[42]=K):K=e[42];let $;e[43]!==I||e[44]!==K?($=s.jsxs("div",{className:"flex items-center justify-between gap-2",children:[I,K]}),e[43]=I,e[44]=K,e[45]=$):$=e[45];let w;if(e[46]!==i||e[47]!==c||e[48]!==l){let W;e[50]!==c||e[51]!==l?(W=te=>s.jsxs("div",{className:"flex items-center justify-between gap-3 py-1.5",children:[s.jsxs("div",{className:"min-w-0",children:[s.jsx("div",{className:"typography-ui-label truncate",children:te.skillName}),s.jsx("div",{className:"typography-micro text-muted-foreground",children:l("settings.skills.catalog.conflicts.installedIn",{scope:te.scope==="project"?l("settings.skills.catalog.conflicts.scope.project"):l("settings.skills.catalog.conflicts.scope.user"),source:te.source==="agents"?l("settings.skills.catalog.conflicts.source.agents"):l("settings.skills.catalog.conflicts.source.opencode")})})]}),s.jsxs(Dt,{value:c[te.skillName]||"skip",onValueChange:ae=>y(le=>({...le,[te.skillName]:ae})),children:[s.jsx(Mt,{className:"w-fit",children:s.jsx("span",{className:"capitalize",children:(c[te.skillName]||"skip")==="overwrite"?l("settings.skills.catalog.conflicts.decision.overwrite"):l("settings.skills.catalog.conflicts.decision.skip")})}),s.jsxs(Rt,{align:"end",children:[s.jsx(dt,{value:"skip",className:"pr-2 [&>span:first-child]:hidden",children:l("settings.skills.catalog.conflicts.decision.skip")}),s.jsx(dt,{value:"overwrite",className:"pr-2 [&>span:first-child]:hidden",children:l("settings.skills.catalog.conflicts.decision.overwrite")})]})]})]},te.skillName),e[50]=c,e[51]=l,e[52]=W):W=e[52],w=i.map(W),e[46]=i,e[47]=c,e[48]=l,e[49]=w}else w=e[49];let G;e[53]!==w?(G=s.jsx("div",{className:"space-y-2",children:w}),e[53]=w,e[54]=G):G=e[54];let Q;e[55]!==$||e[56]!==G?(Q=s.jsxs("div",{className:"space-y-3",children:[$,G]}),e[55]=$,e[56]=G,e[57]=Q):Q=e[57];let X;e[58]!==n?(X=()=>n(!1),e[58]=n,e[59]=X):X=e[59];let Z;e[60]!==l?(Z=l("settings.common.actions.cancel"),e[60]=l,e[61]=Z):Z=e[61];let P;e[62]!==X||e[63]!==Z?(P=s.jsx(H,{size:"sm",variant:"ghost",onClick:X,children:Z}),e[62]=X,e[63]=Z,e[64]=P):P=e[64];let ee;e[65]!==c||e[66]!==r?(ee=()=>r(c),e[65]=c,e[66]=r,e[67]=ee):ee=e[67];const se=!N;let D;e[68]!==l?(D=l("settings.skills.catalog.conflicts.actions.continue"),e[68]=l,e[69]=D):D=e[69];let O;e[70]!==ee||e[71]!==se||e[72]!==D?(O=s.jsx(H,{size:"sm",onClick:ee,disabled:se,children:D}),e[70]=ee,e[71]=se,e[72]=D,e[73]=O):O=e[73];let U;e[74]!==P||e[75]!==O?(U=s.jsxs(os,{children:[P,O]}),e[74]=P,e[75]=O,e[76]=U):U=e[76];let A;e[77]!==q||e[78]!==Q||e[79]!==U?(A=s.jsxs(Vt,{className:"max-w-2xl",children:[q,Q,U]}),e[77]=q,e[78]=Q,e[79]=U,e[80]=A):A=e[80];let V;return e[81]!==n||e[82]!==a||e[83]!==A?(V=s.jsx(Ut,{open:a,onOpenChange:n,children:A}),e[81]=n,e[82]=a,e[83]=A,e[84]=V):V=e[84],V},Xi=[{value:"user-opencode",scope:"user",source:"opencode",label:"User / OpenCode",description:"Global OpenCode config location"},{value:"project-opencode",scope:"project",source:"opencode",label:"Project / OpenCode",description:"Current project .opencode location"},{value:"user-agents",scope:"user",source:"agents",label:"User / Agents",description:"Global .agents compatibility location"},{value:"project-agents",scope:"project",source:"agents",label:"Project / Agents",description:"Current project .agents compatibility location"}];function fa(t,e){return t==="project"&&e==="claude"?"project-claude":t==="project"&&e==="agents"?"project-agents":e==="claude"?"user-claude":t==="project"?"project-opencode":e==="agents"?"user-agents":"user-opencode"}function tl(t){if(t==="user-claude")return{scope:"user",source:"claude"};if(t==="project-claude")return{scope:"project",source:"claude"};const e=Xi.find(a=>a.value===t);return e?{scope:e.scope,source:e.source}:{scope:"user",source:"opencode"}}const fm=t=>{const e=ht.c(124),{open:a,onOpenChange:n,item:i}=t,{t:r}=ot(),l=an(xm),x=an(bm),[c,y]=o.useState("user"),[m,b]=o.useState("opencode"),p=Fs(vm),L=Fs(ym),[k,N]=o.useState(null),[h,C]=o.useState(!1);let u;e[0]===Symbol.for("react.memo_cache_sentinel")?(u=[],e[0]=u):u=e[0];const[E,q]=o.useState(u),[M,I]=o.useState(null);let g,j;e[1]!==L||e[2]!==a?(g=()=>{a&&(y("user"),b("opencode"),N(L),C(!1),q([]),I(null))},j=[a,L],e[1]=L,e[2]=a,e[3]=g,e[4]=j):(g=e[3],j=e[4]),o.useEffect(g,j);let F;e[5]!==r?(F=ye=>{switch(ye){case"project-opencode":return r("settings.skills.location.option.projectOpencode.label");case"user-agents":return r("settings.skills.location.option.userAgents.label");case"project-agents":return r("settings.skills.location.option.projectAgents.label");default:return r("settings.skills.location.option.userOpencode.label")}},e[5]=r,e[6]=F):F=e[6];const S=F;let T;e[7]!==r?(T=ye=>{switch(ye){case"project-opencode":return r("settings.skills.location.option.projectOpencode.description");case"user-agents":return r("settings.skills.location.option.userAgents.description");case"project-agents":return r("settings.skills.location.option.projectAgents.description");default:return r("settings.skills.location.option.userOpencode.description")}},e[7]=r,e[8]=T):T=e[8];const v=T;let K;e:{if(p.length===0){K=null;break e}if(k&&p.some(ye=>ye.id===k)){K=k;break e}if(L&&p.some(ye=>ye.id===L)){K=L;break e}K=p[0]?.id??null}const $=K;let w;e:{if(c!=="project"){w=null;break e}const ye=$;if(!ye){w=null;break e}let z;if(e[9]!==ye||e[10]!==p){let me;e[12]!==ye?(me=ve=>ve.id===ye,e[12]=ye,e[13]=me):me=e[13],z=p.find(me),e[9]=ye,e[10]=p,e[11]=z}else z=e[11];w=z?.path??null}const G=w;let Q;e[14]!==l||e[15]!==i||e[16]!==n||e[17]!==r?(Q=async ye=>{const z={skillDir:ye.skillDir};i?.clawdhub&&(z.clawdhub={slug:i.clawdhub.slug,version:i.clawdhub.version});const oe=await l({source:ye.source,subpath:ye.subpath,gitIdentityId:i?.gitIdentityId,scope:ye.scope,targetSource:ye.targetSource,selections:[z],conflictPolicy:"prompt",conflictDecisions:ye.conflictDecisions},{directory:ye.directoryOverride??null});if(oe.ok){R.success(r("settings.skills.catalog.installSkill.toast.installed")),n(!1);return}if(oe.error?.kind==="conflicts"){I({source:ye.source,subpath:ye.subpath,scope:ye.scope,targetSource:ye.targetSource,skillDir:ye.skillDir,directoryOverride:ye.directoryOverride??null}),q(oe.error.conflicts),C(!0);return}if(oe.error?.kind==="authRequired"){R.error(oe.error.message||r("settings.skills.catalog.installSkill.toast.authRequired"));return}R.error(oe.error?.message||r("settings.skills.catalog.installSkill.toast.installFailed"))},e[14]=l,e[15]=i,e[16]=n,e[17]=r,e[18]=Q):Q=e[18];const X=Q;if(!i)return null;let Z;e[19]!==r?(Z=r("settings.skills.catalog.installSkill.title"),e[19]=r,e[20]=Z):Z=e[20];let P;e[21]!==Z?(P=s.jsx(Gt,{children:Z}),e[21]=Z,e[22]=P):P=e[22];let ee;e[23]!==r?(ee=r("settings.skills.catalog.installSkill.descriptionPrefix"),e[23]=r,e[24]=ee):ee=e[24];let se;e[25]!==i.skillName?(se=s.jsx("span",{className:"font-semibold text-foreground",children:i.skillName}),e[25]=i.skillName,e[26]=se):se=e[26];let D;e[27]!==r?(D=r("settings.skills.catalog.installSkill.descriptionSuffix"),e[27]=r,e[28]=D):D=e[28];let O;e[29]!==ee||e[30]!==se||e[31]!==D?(O=s.jsxs(qt,{children:[ee," ",se," ",D]}),e[29]=ee,e[30]=se,e[31]=D,e[32]=O):O=e[32];let U;e[33]!==P||e[34]!==O?(U=s.jsxs(Ht,{children:[P,O]}),e[33]=P,e[34]=O,e[35]=U):U=e[35];let A;e[36]!==r?(A=r("settings.skills.catalog.installSkill.field.destination"),e[36]=r,e[37]=A):A=e[37];let V;e[38]!==A?(V=s.jsx("span",{className:"typography-ui-label text-foreground",children:A}),e[38]=A,e[39]=V):V=e[39];let W;e[40]!==c||e[41]!==m?(W=fa(c,m),e[40]=c,e[41]=m,e[42]=W):W=e[42];let te;e[43]===Symbol.for("react.memo_cache_sentinel")?(te=ye=>{const z=tl(ye);y(z.scope),b(z.source==="agents"?"agents":"opencode")},e[43]=te):te=e[43];let ae;e[44]!==c?(ae=c==="user"?s.jsx(_,{name:"user-3",className:"h-3.5 w-3.5"}):s.jsx(_,{name:"folder",className:"h-3.5 w-3.5"}),e[44]=c,e[45]=ae):ae=e[45];let le;e[46]!==m?(le=m==="agents"?s.jsx(_,{name:"robot-2",className:"h-3.5 w-3.5"}):null,e[46]=m,e[47]=le):le=e[47];let be;e[48]!==S||e[49]!==c||e[50]!==m?(be=S(fa(c,m)),e[48]=S,e[49]=c,e[50]=m,e[51]=be):be=e[51];let ke;e[52]!==be?(ke=s.jsx("span",{children:be}),e[52]=be,e[53]=ke):ke=e[53];let ce;e[54]!==ae||e[55]!==le||e[56]!==ke?(ce=s.jsxs(Mt,{className:"w-fit gap-1.5",children:[ae,le,ke]}),e[54]=ae,e[55]=le,e[56]=ke,e[57]=ce):ce=e[57];let ge;e[58]!==v||e[59]!==S?(ge=Xi.map(ye=>s.jsx(dt,{value:ye.value,className:"pr-2 [&>span:first-child]:hidden",children:s.jsxs("div",{className:"flex flex-col gap-0.5",children:[s.jsxs("div",{className:"flex items-center gap-2",children:[ye.scope==="user"?s.jsx(_,{name:"user-3",className:"h-3.5 w-3.5"}):s.jsx(_,{name:"folder",className:"h-3.5 w-3.5"}),ye.source==="agents"?s.jsx(_,{name:"robot-2",className:"h-3.5 w-3.5"}):null,s.jsx("span",{children:S(ye.value)})]}),s.jsx("span",{className:"typography-micro text-muted-foreground ml-5",children:v(ye.value)})]})},ye.value)),e[58]=v,e[59]=S,e[60]=ge):ge=e[60];let Ee;e[61]!==ge?(Ee=s.jsx(Rt,{align:"start",children:ge}),e[61]=ge,e[62]=Ee):Ee=e[62];let Se;e[63]!==W||e[64]!==ce||e[65]!==Ee?(Se=s.jsxs(Dt,{value:W,onValueChange:te,children:[ce,Ee]}),e[63]=W,e[64]=ce,e[65]=Ee,e[66]=Se):Se=e[66];let Ne;e[67]!==V||e[68]!==Se?(Ne=s.jsxs("div",{className:"flex flex-wrap items-center gap-2",children:[V,Se]}),e[67]=V,e[68]=Se,e[69]=Ne):Ne=e[69];let fe;e[70]!==p||e[71]!==$||e[72]!==c||e[73]!==r?(fe=c==="project"&&s.jsxs("div",{className:"flex flex-wrap items-center gap-2",children:[s.jsx("span",{className:"typography-ui-label text-foreground",children:r("settings.skills.catalog.installSkill.field.project")}),p.length===0?s.jsx("span",{className:"typography-meta text-muted-foreground",children:r("settings.skills.catalog.installSkill.field.noProjects")}):s.jsxs(Dt,{value:$??"",onValueChange:ye=>N(ye),disabled:p.length===1,children:[s.jsx(Mt,{className:"w-fit",children:s.jsx(_t,{placeholder:r("settings.skills.catalog.installSkill.field.chooseProjectPlaceholder")})}),s.jsx(Rt,{align:"start",children:p.map(jm)})]})]}),e[70]=p,e[71]=$,e[72]=c,e[73]=r,e[74]=fe):fe=e[74];let Ke;e[75]!==i.warnings?(Ke=i.warnings?.length?s.jsx("div",{className:"typography-micro text-[var(--status-warning)] bg-[var(--status-warning)]/10 px-2 py-1.5 rounded",children:i.warnings.join(" · ")}):null,e[75]=i.warnings,e[76]=Ke):Ke=e[76];let De;e[77]!==Ne||e[78]!==fe||e[79]!==Ke?(De=s.jsxs("div",{className:"mt-2 space-y-3",children:[Ne,fe,Ke]}),e[77]=Ne,e[78]=fe,e[79]=Ke,e[80]=De):De=e[80];let he;e[81]!==n?(he=()=>n(!1),e[81]=n,e[82]=he):he=e[82];let pe;e[83]!==r?(pe=r("settings.common.actions.cancel"),e[83]=r,e[84]=pe):pe=e[84];let Ie;e[85]!==he||e[86]!==pe?(Ie=s.jsx(H,{size:"sm",variant:"ghost",onClick:he,children:pe}),e[85]=he,e[86]=pe,e[87]=Ie):Ie=e[87];const ze=x||!i.installable||c==="project"&&!G;let Je;e[88]!==G||e[89]!==X||e[90]!==i.repoSource||e[91]!==i.repoSubpath||e[92]!==i.skillDir||e[93]!==c||e[94]!==m?(Je=()=>{X({source:i.repoSource,subpath:i.repoSubpath,scope:c,targetSource:m,skillDir:i.skillDir,directoryOverride:G})},e[88]=G,e[89]=X,e[90]=i.repoSource,e[91]=i.repoSubpath,e[92]=i.skillDir,e[93]=c,e[94]=m,e[95]=Je):Je=e[95];let _e;e[96]!==x||e[97]!==r?(_e=r(x?"settings.skills.catalog.installSkill.actions.installing":"settings.skills.catalog.installSkill.actions.install"),e[96]=x,e[97]=r,e[98]=_e):_e=e[98];let Le;e[99]!==ze||e[100]!==Je||e[101]!==_e?(Le=s.jsx(H,{size:"sm",disabled:ze,onClick:Je,children:_e}),e[99]=ze,e[100]=Je,e[101]=_e,e[102]=Le):Le=e[102];let Pe;e[103]!==Ie||e[104]!==Le?(Pe=s.jsxs(os,{children:[Ie,Le]}),e[103]=Ie,e[104]=Le,e[105]=Pe):Pe=e[105];let Ye;e[106]!==U||e[107]!==De||e[108]!==Pe?(Ye=s.jsxs(Vt,{className:"max-w-md",children:[U,De,Pe]}),e[106]=U,e[107]=De,e[108]=Pe,e[109]=Ye):Ye=e[109];let Ge;e[110]!==n||e[111]!==a||e[112]!==Ye?(Ge=s.jsx(Ut,{open:a,onOpenChange:n,children:Ye}),e[110]=n,e[111]=a,e[112]=Ye,e[113]=Ge):Ge=e[113];let Me;e[114]!==M||e[115]!==X?(Me=ye=>{M&&(X({source:M.source,subpath:M.subpath,scope:M.scope,targetSource:M.targetSource,skillDir:M.skillDir,conflictDecisions:ye,directoryOverride:M.directoryOverride??null}),C(!1))},e[114]=M,e[115]=X,e[116]=Me):Me=e[116];let $e;e[117]!==E||e[118]!==h||e[119]!==Me?($e=s.jsx(hm,{open:h,onOpenChange:C,conflicts:E,onConfirm:Me}),e[117]=E,e[118]=h,e[119]=Me,e[120]=$e):$e=e[120];let Fe;return e[121]!==Ge||e[122]!==$e?(Fe=s.jsxs(s.Fragment,{children:[Ge,$e]}),e[121]=Ge,e[122]=$e,e[123]=Fe):Fe=e[123],Fe};function xm(t){return t.installSkills}function bm(t){return t.isInstalling}function vm(t){return t.projects}function ym(t){return t.activeProjectId}function jm(t){return s.jsx(dt,{value:t.id,children:t.label||t.path},t.id)}const wm=async()=>{try{const t=jn()?.settings;if(t)return(await t.load())?.settings||{};const e=await ct("/api/config/settings",{method:"GET",headers:{Accept:"application/json"}});return e.ok?await e.json().catch(()=>null):null}catch{return null}},Nm=({mode:t,onModeChange:e,showModeTabs:a=!0})=>{const{t:n}=ot(),{sources:i,itemsBySource:r,selectedSourceId:l,setSelectedSource:x,loadCatalog:c,loadSource:y,loadMoreClawdHub:m,isLoadingCatalog:b,isLoadingSource:p,isLoadingMore:L,loadedSourceIds:k,clawdhubHasMoreBySource:N,lastCatalogError:h}=an(Ps(P=>({sources:P.sources,itemsBySource:P.itemsBySource,selectedSourceId:P.selectedSourceId,setSelectedSource:P.setSelectedSource,loadCatalog:P.loadCatalog,loadSource:P.loadSource,loadMoreClawdHub:P.loadMoreClawdHub,isLoadingCatalog:P.isLoadingCatalog,isLoadingSource:P.isLoadingSource,isLoadingMore:P.isLoadingMore,loadedSourceIds:P.loadedSourceIds,clawdhubHasMoreBySource:P.clawdhubHasMoreBySource,lastCatalogError:P.lastCatalogError}))),[C,u]=o.useState(""),[E,q]=o.useState(!1),[M,I]=o.useState(!1),[g,j]=o.useState(null),[F,S]=o.useState(!1),[T,v]=o.useState(!1);o.useEffect(()=>{c()},[c]),o.useEffect(()=>{l&&(k[l]||y(l))},[l,k,y]);const K=o.useMemo(()=>l?r[l]||[]:[],[r,l]),$=o.useMemo(()=>{const P=C.trim().toLowerCase();return P?K.filter(ee=>{const se=ee.skillName.toLowerCase(),D=(ee.description||"").toLowerCase(),O=(ee.frontmatterName||"").toLowerCase();return se.includes(P)||D.includes(P)||O.includes(P)}):K},[K,C]),w=o.useMemo(()=>i.find(P=>P.id===l)||null,[i,l]),G=!!(l&&l.startsWith("custom:")),Q=w?.source==="clawdhub:registry"||w?.sourceType==="clawdhub",X=!!(l&&(N[l]??!0)),Z=async()=>{if(!(!l||!G)){S(!0);try{const P=await wm(),se=(Array.isArray(P?.skillCatalogs)?P?.skillCatalogs:[]).filter(D=>D.id!==l);await yt({skillCatalogs:se}),await c({refresh:!0}),v(!1)}finally{S(!1)}}};return s.jsxs(s.Fragment,{children:[s.jsxs(rs,{title:n("settings.skills.catalog.page.title"),showSaveStatus:!1,children:[a&&s.jsx("div",{className:"mb-4",children:s.jsx("div",{className:"h-10",children:s.jsx(Zi,{items:[{id:"manual",label:n("settings.skills.catalog.page.mode.manual")},{id:"external",label:n("settings.skills.catalog.page.mode.external")}],activeId:t,onSelect:P=>e(P),layoutMode:"fit",variant:"animated",animateActivePill:!1,className:"h-full"})})}),s.jsxs(Oe,{title:n("settings.skills.catalog.page.section.sourceRepository"),divider:!1,settingsItem:"skills.catalog.source",contentClassName:"space-y-0",children:[s.jsxs("div",{className:"flex flex-wrap items-center gap-2 py-1.5",children:[s.jsxs(Dt,{value:l||"",onValueChange:P=>x(P),children:[s.jsx(Mt,{size:Kt,className:je(sn,"w-fit"),children:s.jsx(_t,{placeholder:n("settings.skills.catalog.page.field.selectSourcePlaceholder"),children:w?.label})}),s.jsx(Rt,{align:"start",children:i.map(P=>s.jsx(dt,{value:P.id,children:P.label},P.id))})]}),s.jsx(H,{variant:"outline",size:"xs",className:"!font-normal h-6 w-6 px-0",onClick:()=>{l?y(l,{refresh:!0}):c({refresh:!0})},disabled:b||p,title:n("settings.skills.catalog.page.actions.refreshTitle"),children:s.jsx(_,{name:"refresh",className:je("h-3.5 w-3.5",(b||p)&&"animate-spin")})}),G&&s.jsx(H,{variant:"ghost",size:"xs",className:"!font-normal h-6 w-6 px-0 text-[var(--status-error)] hover:text-[var(--status-error)]",onClick:()=>v(!0),disabled:F,title:n("settings.skills.catalog.page.actions.removeCatalogTitle"),children:s.jsx(_,{name:"delete-bin",className:"h-3.5 w-3.5"})}),s.jsxs(H,{"data-settings-item":"skills.catalog.add-catalog",size:"xs",className:"!font-normal gap-1",onClick:()=>q(!0),children:[s.jsx(_,{name:"add",className:"h-3.5 w-3.5"})," ",n("settings.skills.catalog.page.actions.addCatalog")]})]}),s.jsxs("div",{"data-settings-item":"skills.catalog.search",className:"py-1.5",children:[s.jsxs("div",{className:"relative",children:[s.jsx(_,{name:"search",className:"absolute left-2 top-1/2 -translate-y-1/2 h-3.5 w-3.5 text-muted-foreground"}),s.jsx(He,{value:C,onChange:P=>u(P.target.value),placeholder:n("settings.skills.catalog.shared.field.searchSkillsPlaceholder"),className:"h-7 pl-8 w-full sm:w-64"})]}),s.jsx("span",{className:"typography-meta text-muted-foreground mt-1 block",children:b?n("settings.skills.catalog.page.loading.catalog"):n("settings.skills.catalog.page.foundCount",{count:$.length})})]})]}),h&&s.jsx(Oe,{children:s.jsxs("div",{className:"rounded-lg border border-[var(--status-error-border)] bg-[var(--status-error-background)] px-4 py-3",children:[s.jsx("div",{className:"typography-ui-label font-medium text-[var(--status-error)]",children:n("settings.skills.catalog.page.error.catalogTitle")}),s.jsx("div",{className:"typography-meta text-[var(--status-error)]/80 mt-1",children:h.message})]})}),s.jsxs(Oe,{children:[$.length===0&&!p?s.jsxs("div",{className:"py-8 text-center text-muted-foreground",children:[s.jsx("p",{className:"typography-body",children:n("settings.skills.catalog.page.empty.noSkillsTitle")}),s.jsx("p",{className:"typography-meta mt-1 opacity-75",children:n("settings.skills.catalog.page.empty.noSkillsDescription")})]}):p?s.jsxs("div",{className:"py-8 text-center text-muted-foreground",children:[s.jsx(_,{name:"refresh",className:"mx-auto mb-3 h-5 w-5 animate-spin opacity-50"}),s.jsx("p",{className:"typography-meta",children:n("settings.skills.catalog.page.loading.skills")})]}):s.jsx("div",{className:"divide-y divide-[var(--surface-subtle)]",children:$.map(P=>{const ee=P.installed?.isInstalled,se=P.installed?.scope;return s.jsx("div",{className:"py-2",children:s.jsxs("div",{className:"flex items-start justify-between gap-4",children:[s.jsxs("div",{className:"min-w-0 flex-1",children:[s.jsxs("div",{className:"flex items-center gap-2",children:[s.jsx("span",{className:"typography-ui-label font-medium text-foreground truncate",children:P.skillName}),ee&&s.jsx("span",{className:"typography-micro text-[var(--status-success)] bg-[var(--status-success)]/10 px-1.5 py-0.5 rounded flex-shrink-0",children:n("settings.skills.catalog.page.badge.installed",{scope:se||n("settings.skills.catalog.page.badge.unknown")})}),!P.installable&&s.jsx("span",{className:"typography-micro text-[var(--status-warning)] bg-[var(--status-warning)]/10 px-1.5 py-0.5 rounded flex-shrink-0",children:n("settings.skills.catalog.page.badge.notInstallable")})]}),P.description?s.jsx("div",{className:"typography-meta text-muted-foreground mt-0.5 line-clamp-2",children:P.description}):s.jsx("div",{className:"typography-meta text-muted-foreground/50 mt-0.5 italic",children:n("settings.skills.catalog.shared.noDescription")}),P.clawdhub&&s.jsxs("div",{className:"typography-micro text-muted-foreground mt-1.5 flex items-center gap-3",children:[P.clawdhub.owner&&s.jsxs("span",{children:[n("settings.skills.catalog.page.byOwnerPrefix")," ",s.jsx("span",{className:"font-medium text-foreground/80",children:P.clawdhub.owner})]}),s.jsxs("span",{className:"flex items-center gap-1",children:[s.jsx(_,{name:"download",className:"h-3 w-3"}),P.clawdhub.downloads?.toLocaleString()??0]}),(P.clawdhub.stars??0)>0&&s.jsxs("span",{className:"flex items-center gap-1",children:[s.jsx(_,{name:"star",className:"h-3 w-3"}),P.clawdhub.stars]}),s.jsxs("span",{className:"bg-[var(--surface-muted)] px-1.5 py-0.5 rounded",children:["v",P.clawdhub.version]})]}),P.warnings?.length?s.jsx("div",{className:"typography-micro text-[var(--status-warning)] mt-1.5 bg-[var(--status-warning)]/10 px-2 py-1 rounded w-fit",children:P.warnings.join(" · ")}):null]}),s.jsx(H,{variant:"outline",size:"xs",className:"!font-normal shrink-0",disabled:!P.installable,onClick:()=>{j(P),I(!0)},children:n("settings.skills.catalog.shared.actions.install")})]})},`${P.sourceId}:${P.skillDir}`)})}),Q&&X&&!p&&$.length>0&&s.jsx("div",{className:"flex justify-center mt-2",children:s.jsx(H,{variant:"outline",size:"xs",className:"!font-normal",onClick:()=>{m()},disabled:L,children:n(L?"settings.skills.catalog.page.loading.more":"settings.skills.catalog.page.actions.loadMoreSkills")})})]})]}),s.jsx(rm,{open:E,onOpenChange:q}),s.jsx(fm,{open:M,onOpenChange:I,item:g}),s.jsx(Ut,{open:T,onOpenChange:P=>{F||v(P)},children:s.jsxs(Vt,{className:"max-w-md",children:[s.jsxs(Ht,{children:[s.jsx(Gt,{children:n("settings.skills.catalog.page.removeDialog.title")}),s.jsx(qt,{children:n("settings.skills.catalog.page.removeDialog.description")})]}),s.jsxs(os,{children:[s.jsx(H,{size:"sm",variant:"ghost",onClick:()=>v(!1),disabled:F,children:n("settings.common.actions.cancel")}),s.jsx(H,{size:"sm",variant:"destructive",onClick:()=>{Z()},disabled:F,children:n("settings.skills.catalog.page.actions.removeCatalog")})]})]})})]})},km=()=>{const t=ht.c(1);let e;return t[0]===Symbol.for("react.memo_cache_sentinel")?(e=s.jsx(Nm,{mode:"external",onModeChange:Tm,showModeTabs:!1}),t[0]=e):e=t[0],e},Sm="SKILL.md",Cm="h-[clamp(320px,58dvh,680px)] min-h-[260px] max-h-[calc(100dvh-220px)]",Ha=(t,e)=>{const a=ad({description:t}).trimEnd(),n=e.trimStart();return`---
22
+ ${a}
23
+ ---${n?`
24
+
25
+ ${n}`:`
26
+ `}`},Im=t=>typeof t=="object"&&t!==null&&!Array.isArray(t),sl=t=>{const e=t.match(/^---\r?\n([\s\S]*?)\r?\n---(?:\r?\n|$)([\s\S]*)$/);if(!e)return{description:null,instructions:t};let a=null;try{const n=id(e[1]);if(Im(n)){const i=n.description;typeof i=="string"&&(a=i)}}catch{a=null}return{description:a,instructions:e[2].replace(/^\r?\n/,"")}},Pm=(t,e)=>{const a=sl(t);return Ha(e,a.instructions)},Am=()=>{const{t}=ot(),{currentTheme:e}=Yi(),{selectedSkillName:a,getSkillByName:n,getSkillDetail:i,createSkill:r,updateSkill:l,skills:x,skillDraft:c,setSkillDraft:y,setSelectedSkill:m}=rn(Ps(z=>({selectedSkillName:z.selectedSkillName,getSkillByName:z.getSkillByName,getSkillDetail:z.getSkillDetail,createSkill:z.createSkill,updateSkill:z.updateSkill,skills:z.skills,skillDraft:z.skillDraft,setSkillDraft:z.setSkillDraft,setSelectedSkill:z.setSelectedSkill}))),b=a?n(a):null,p=!!(c&&c.name===a&&!b),L=!!(a&&!b&&!c),k=b?.path==="<built-in>";o.useEffect(()=>{L&&m(null)},[L,m]);const[N,h]=o.useState(""),[C,u]=o.useState("user"),[E,q]=o.useState("opencode"),[M,I]=o.useState(""),[g,j]=o.useState(""),[F,S]=o.useState(()=>Ha("","")),[T,v]=o.useState("edit"),[K,$]=o.useState([]),[w,G]=o.useState([]),[Q,X]=o.useState(!1),[Z,P]=o.useState(!1),[ee,se]=o.useState(""),[D,O]=o.useState(""),[U,A]=o.useState(!1),[V,W]=o.useState(""),[te,ae]=o.useState(""),[le,be]=o.useState(null),[ke,ce]=o.useState(!1),[ge,Ee]=o.useState(""),[Se,Ne]=o.useState(null),[fe,Ke]=o.useState(!1),De=p?N.trim()!==""||M.trim()!==""||g.trim()!==""||w.length>0:M!==ee||g!==D,he=le?te!==ge:V.trim()!=="",pe=o.useCallback(z=>{switch(z){case"project-opencode":return t("settings.skills.location.option.projectOpencode.label");case"user-claude":return t("settings.skills.location.option.userClaude.label");case"project-claude":return t("settings.skills.location.option.projectClaude.label");case"user-agents":return t("settings.skills.location.option.userAgents.label");case"project-agents":return t("settings.skills.location.option.projectAgents.label");default:return t("settings.skills.location.option.userOpencode.label")}},[t]),Ie=o.useCallback(z=>{switch(z){case"project-opencode":return t("settings.skills.location.option.projectOpencode.description");case"user-claude":return t("settings.skills.location.option.userClaude.description");case"project-claude":return t("settings.skills.location.option.projectClaude.description");case"user-agents":return t("settings.skills.location.option.userAgents.description");case"project-agents":return t("settings.skills.location.option.projectAgents.description");default:return t("settings.skills.location.option.userOpencode.description")}},[t]);o.useEffect(()=>{(async()=>{if(p&&c){const oe=c.description||"",me=c.instructions||"";h(c.name||""),u(c.scope||"user"),q(c.source==="agents"?"agents":"opencode"),I(oe),j(me),S(Ha(oe,me)),se(""),O(""),$([]),G(c.pendingFiles||[])}else if(a&&b){P(!0);try{const oe=await i(a);if(oe){const me=oe.sources.md,ve=me.description||"",re=me.instructions||"";I(ve),j(re),S(Ha(ve,re)),se(ve),O(re),$(me.supportingFiles||[])}}catch(oe){console.error("Failed to load skill details:",oe)}finally{P(!1)}}})()},[b,p,a,x,c,i]);const ze=de(z=>z.editorFontSize),Je=o.useMemo(()=>{const z=[Pr(e,{fontSize:ze})],oe=or(Sm);return oe&&z.push(oe),z.push(Tr.lineWrapping),z},[e,ze]),_e=o.useMemo(()=>{const z=V.trim()||"supporting-file.md",oe=zl(z),me=!!oe&&oe!=="markdown",ve=[Pr(e,me?{syntaxColors:!1,fontSize:ze}:{fontSize:ze})],re=or(z);return re&&ve.push(re),me&&oe&&ve.push(rd({language:oe,themeName:e.metadata.id,theme:ld(e)})),ve.push(Tr.lineWrapping),ve},[e,V,ze]),Le=o.useCallback(z=>{I(z),S(oe=>Pm(oe,z))},[]),Pe=o.useCallback(z=>{S(z);const oe=sl(z);I(oe.description??""),j(oe.instructions)},[]),Ye=async()=>{const z=p?N.trim().replace(/\s+/g,"-").toLowerCase():a?.trim();if(!z){R.error(t("settings.skills.page.toast.skillNameRequired"));return}if(!/^[a-z0-9][a-z0-9-]*[a-z0-9]$|^[a-z0-9]$/.test(z)||z.length>64){R.error(t("settings.skills.page.toast.invalidSkillName"));return}if(!M.trim()){R.error(t("settings.skills.page.toast.descriptionRequired"));return}if(p&&x.some(oe=>oe.name===z)){R.error(t("settings.skills.page.toast.skillExists"));return}X(!0);try{const oe={name:z,description:M.trim(),instructions:g.trim()||void 0,scope:p?C:void 0,source:p?E:void 0,targetPath:p?void 0:b?.path,supportingFiles:p&&w.length>0?w:void 0};let me;if(p?(me=await r(oe),me&&(y(null),G([]),m(z))):(me=await l(z,oe),me&&(se(M.trim()),O(g.trim()))),me){const ve=Tn.getState().changes.some(re=>re.scope==="skills"&&re.id.startsWith(`skills:${z}:`));R.success(t(ve?"settings.view.pendingRestart.saved":p?"settings.skills.page.toast.skillCreated":"settings.skills.page.toast.skillUpdated"))}else R.error(t(p?"settings.skills.page.toast.createSkillFailed":"settings.skills.page.toast.updateSkillFailed"))}catch(oe){console.error("Error saving skill:",oe),R.error(t("settings.skills.page.toast.saveUnexpectedError"))}finally{X(!1)}},Ge=()=>{be(null),W(""),ae(""),Ee(""),A(!0)},Me=async z=>{if(be(z),W(z),p){const me=w.find(ve=>ve.path===z)?.content||"";ae(me),Ee(me),A(!0);return}if(a){ce(!0),A(!0);try{const{readSupportingFile:oe}=rn.getState(),me=await oe(a,z);ae(me||""),Ee(me||"")}catch{R.error(t("settings.skills.page.toast.loadFileContentFailed")),ae(""),Ee("")}finally{ce(!1)}}},$e=async()=>{if(!V.trim()){R.error(t("settings.skills.page.toast.fileNameRequired"));return}const z=V.trim(),oe=le!==null;if(p){if(oe)G(re=>re.map(Ve=>Ve.path===le?{path:z,content:te}:Ve)),R.success(t("settings.skills.page.toast.fileUpdated",{path:z}));else{if(w.some(re=>re.path===z)){R.error(t("settings.skills.page.toast.fileExists"));return}G(re=>[...re,{path:z,content:te}]),R.success(t("settings.skills.page.toast.fileAdded",{path:z}))}A(!1),be(null);return}if(!a){R.error(t("settings.skills.page.toast.noSkillSelected"));return}const{writeSupportingFile:me}=rn.getState();if(await me(a,z,te)){R.success(oe?t("settings.skills.page.toast.fileUpdated",{path:z}):t("settings.skills.page.toast.fileCreated",{path:z})),A(!1),be(null);const re=await i(a);re&&$(re.sources.md.supportingFiles||[])}else R.error(t(oe?"settings.skills.page.toast.updateFileFailed":"settings.skills.page.toast.createFileFailed"))},Fe=z=>{if(p){G(oe=>oe.filter(me=>me.path!==z)),R.success(t("settings.skills.page.toast.fileRemoved",{path:z}));return}a&&Ne(z)},ye=async()=>{if(!Se||!a)return;Ke(!0);const{deleteSupportingFile:z}=rn.getState();if(await z(a,Se)){R.success(t("settings.skills.page.toast.fileDeleted",{path:Se}));const me=await i(a);me&&$(me.sources.md.supportingFiles||[]),Ne(null)}else R.error(t("settings.skills.page.toast.deleteFileFailed"));Ke(!1)};return!a&&!c||L?s.jsx("div",{className:"flex h-full items-center justify-center px-4",children:s.jsxs("div",{className:"text-center text-muted-foreground",children:[s.jsx(_,{name:"book-open",className:"mx-auto mb-3 h-10 w-10 sm:h-12 sm:w-12 opacity-50"}),s.jsx("p",{className:"typography-body",children:t("settings.skills.page.empty.title")}),s.jsx("p",{className:"typography-meta mt-1 opacity-75",children:t("settings.skills.page.empty.description")})]})}):Z?s.jsx("div",{className:"flex h-full items-center justify-center px-4",children:s.jsx("div",{className:"text-center text-muted-foreground",children:s.jsx("p",{className:"typography-body",children:t("settings.skills.page.loading.details")})})}):s.jsxs(s.Fragment,{children:[s.jsxs(rs,{title:p?t("settings.skills.page.title.newSkill"):a,description:b?t("settings.skills.page.subtitle.skillLocation",{location:pe(fa(b.scope,b.source))}):t("settings.skills.page.subtitle.newSkill"),showSaveStatus:!1,children:[s.jsxs(Oe,{title:t("settings.skills.page.section.basicInformation"),divider:!1,settingsItem:"skills.basic-information",contentClassName:"space-y-0",children:[p&&s.jsxs($t,{label:t("settings.skills.page.field.skillNameLocation"),info:t("settings.skills.page.field.skillNameHint"),children:[s.jsx(He,{value:N,onChange:z=>h(z.target.value.toLowerCase().replace(/\s+/g,"-")),placeholder:t("settings.skills.page.field.skillNamePlaceholder"),className:"h-7 w-40 px-2"}),s.jsxs(Dt,{value:fa(C,E),onValueChange:z=>{const oe=tl(z);u(oe.scope),q(oe.source==="agents"?"agents":"opencode")},children:[s.jsxs(Mt,{size:Kt,className:"w-fit gap-1.5",children:[C==="user"?s.jsx(_,{name:"user-3",className:"h-3.5 w-3.5"}):s.jsx(_,{name:"folder",className:"h-3.5 w-3.5"}),E==="agents"?s.jsx(_,{name:"robot-2",className:"h-3.5 w-3.5"}):null,s.jsx("span",{children:pe(fa(C,E))})]}),s.jsx(Rt,{align:"start",children:Xi.map(z=>s.jsx(dt,{value:z.value,children:s.jsxs("div",{className:"flex flex-col gap-0.5",children:[s.jsxs("div",{className:"flex items-center gap-2",children:[z.scope==="user"?s.jsx(_,{name:"user-3",className:"h-3.5 w-3.5"}):s.jsx(_,{name:"folder",className:"h-3.5 w-3.5"}),z.source==="agents"?s.jsx(_,{name:"robot-2",className:"h-3.5 w-3.5"}):null,s.jsx("span",{children:pe(z.value)})]}),s.jsx("span",{className:"typography-micro text-muted-foreground ml-6",children:Ie(z.value)})]})},z.value))})]})]}),s.jsx(Qt,{label:s.jsxs(s.Fragment,{children:[t("settings.common.field.description")," ",s.jsx("span",{className:"text-[var(--status-error)]",children:"*"})]}),info:t("settings.skills.page.field.descriptionHint"),controlClassName:"w-full max-w-none",children:s.jsx(Ns,{value:M,onChange:z=>Le(z.target.value),placeholder:t("settings.skills.page.field.descriptionPlaceholder"),rows:2,className:"w-full resize-none min-h-[60px] max-h-32 bg-transparent",disabled:k})})]}),s.jsx(Oe,{title:t("settings.skills.page.section.instructions"),headerAction:s.jsx(od,{currentMode:T==="preview"?"preview":"edit",onToggle:()=>v(z=>z==="preview"?"edit":"preview")}),settingsItem:"skills.instructions",children:s.jsx("div",{className:je("overflow-hidden rounded-md border border-[var(--surface-subtle)] bg-background",Cm),children:T==="preview"?s.jsx(Ds,{outerClassName:"h-full",className:"h-full",children:s.jsx("div",{className:"min-h-full px-4 py-3",children:s.jsx(Ul,{content:F,className:"typography-markdown-body",stripFrontmatter:!0,enableFileReferences:!1})})}):s.jsx(Ar,{value:F,onChange:Pe,readOnly:k,extensions:Je,className:"h-full",enableSearch:!0})})}),s.jsx(Oe,{title:t("settings.skills.page.section.supportingFiles"),headerAction:s.jsxs(H,{variant:"outline",size:"xs",className:"!font-normal gap-1",onClick:Ge,disabled:k,children:[s.jsx(_,{name:"add",className:"h-3.5 w-3.5"})," ",t("settings.skills.page.actions.addFile")]}),settingsItem:"skills.supporting-files",children:(()=>{const z=p?w:K;return z.length===0?s.jsx("p",{className:"typography-meta text-muted-foreground py-1.5",children:t("settings.skills.page.supportingFiles.empty")}):s.jsx("div",{className:"divide-y divide-[var(--surface-subtle)]",children:z.map(oe=>s.jsxs("div",{className:"flex items-center gap-2 py-1.5 cursor-pointer group",onClick:()=>Me(oe.path),children:[s.jsx(_,{name:"file",className:"h-3.5 w-3.5 text-muted-foreground flex-shrink-0"}),s.jsx("span",{className:"typography-ui-label text-foreground truncate",children:oe.path}),p&&s.jsx("span",{className:"typography-micro text-[var(--status-warning)] bg-[var(--status-warning)]/10 px-1.5 py-0.5 rounded flex-shrink-0",children:t("settings.skills.page.badge.pending")}),!k&&s.jsx(H,{size:"sm",variant:"ghost",className:"h-5 w-5 px-0 flex-shrink-0 text-muted-foreground hover:text-[var(--status-error)] opacity-0 group-hover:opacity-100 transition-opacity",onClick:me=>{me.stopPropagation(),Fe(oe.path)},children:s.jsx(_,{name:"delete-bin",className:"h-3 w-3"})})]},oe.path))})})()}),s.jsx(Oe,{children:s.jsx(H,{onClick:Ye,disabled:k||Q||!De,size:"xs",className:"!font-normal",children:t(Q?"settings.common.actions.saving":p?"settings.skills.page.actions.createSkill":"settings.common.actions.saveChanges")})})]}),s.jsx(Ut,{open:Se!==null,onOpenChange:z=>{!z&&!fe&&Ne(null)},children:s.jsxs(Vt,{className:"max-w-md",children:[s.jsxs(Ht,{children:[s.jsx(Gt,{children:t("settings.skills.page.deleteFileDialog.title")}),s.jsx(qt,{children:t("settings.skills.page.deleteFileDialog.description",{path:Se??""})})]}),s.jsxs(os,{children:[s.jsx(H,{size:"sm",variant:"ghost",onClick:()=>Ne(null),disabled:fe,children:t("settings.common.actions.cancel")}),s.jsx(H,{size:"sm",variant:"destructive",onClick:ye,disabled:fe,children:t("settings.common.actions.delete")})]})]})}),s.jsx(Ut,{open:U,onOpenChange:z=>{A(z),z||be(null)},children:s.jsxs(Vt,{className:"max-w-3xl max-h-[85vh] flex flex-col",children:[s.jsxs(Ht,{className:"flex-shrink-0",children:[s.jsx(Gt,{children:t(le?"settings.skills.page.fileDialog.titleEdit":"settings.skills.page.fileDialog.titleAdd")}),s.jsx(qt,{children:t(le?"settings.skills.page.fileDialog.descriptionEdit":"settings.skills.page.fileDialog.descriptionAdd")})]}),ke?s.jsx("div",{className:"flex-1 flex items-center justify-center py-8",children:s.jsx("span",{className:"typography-meta text-muted-foreground",children:t("settings.skills.page.loading.fileContent")})}):s.jsxs("div",{className:"space-y-4 flex-1 min-h-0 flex flex-col pt-2",children:[s.jsxs("div",{className:"space-y-2 flex-shrink-0",children:[s.jsxs("div",{className:"flex items-center gap-1",children:[s.jsx("label",{className:Et,children:t("settings.skills.page.fileDialog.field.filePath")}),!le&&s.jsx(Yt,{children:t("settings.skills.page.fileDialog.field.filePathHint")})]}),s.jsx(He,{value:V,onChange:z=>W(z.target.value),placeholder:t("settings.skills.page.fileDialog.field.filePathPlaceholder"),className:"text-foreground placeholder:text-muted-foreground focus-visible:ring-[var(--primary-base)]",disabled:le!==null})]}),s.jsxs("div",{className:"space-y-2 flex-1 min-h-0 flex flex-col",children:[s.jsx("label",{className:`${Et} flex-shrink-0`,children:t("settings.skills.page.fileDialog.field.content")}),s.jsx("div",{className:"h-[45vh] min-h-[250px] max-h-[55vh] overflow-hidden rounded-md border border-[var(--surface-subtle)] bg-background",children:s.jsx(Ar,{value:te,onChange:ae,extensions:_e,className:"h-full",enableSearch:!0})})]})]}),s.jsxs(os,{className:"mt-4",children:[s.jsx(H,{size:"sm",variant:"ghost",onClick:()=>{A(!1),be(null)},children:t("settings.common.actions.cancel")}),s.jsx(H,{size:"sm",onClick:$e,disabled:ke||!he,children:t(le?"settings.common.actions.saveChanges":"settings.skills.page.actions.createFile")})]})]})})]})},Gr=t=>{const e=ht.c(2),{view:a}=t,n=a===void 0?"installed":a;let i;return e[0]!==n?(i=n==="catalog"?s.jsx(km,{}):s.jsx(Am,{}),e[0]=n,e[1]=i):i=e[1],i};function Tm(){}const Em=t=>{const e=ht.c(38),{onItemSelect:a}=t,{t:n}=ot(),i=Fs(Dm),r=de(Mm),l=de(Rm),{currentTheme:x}=Yi();let c;e[0]===Symbol.for("react.memo_cache_sentinel")?(c=ds(),e[0]=c):c=e[0];const y=c,m=Om;let b,p;e[1]!==i||e[2]!==r||e[3]!==l?(b=()=>{if(i.length===0){r!==null&&l(null);return}r&&i.some(g=>g.id===r)||l(i[0].id)},p=[i,r,l],e[1]=i,e[2]=r,e[3]=l,e[4]=b,e[5]=p):(b=e[4],p=e[5]),o.useEffect(b,p);let L;e[6]===Symbol.for("react.memo_cache_sentinel")?(L=je("border-b px-3","pt-4 pb-3"),e[6]=L):L=e[6];let k;e[7]!==n?(k=n("settings.page.projects.title"),e[7]=n,e[8]=k):k=e[8];let N;e[9]!==k?(N=s.jsx("h2",{className:`${qs} mb-3`,children:k}),e[9]=k,e[10]=N):N=e[10];let h;e[11]!==i.length||e[12]!==n?(h=n("settings.projects.sidebar.total",{count:i.length}),e[11]=i.length,e[12]=n,e[13]=h):h=e[13];let C;e[14]!==h?(C=s.jsx("span",{className:"typography-meta text-muted-foreground",children:h}),e[14]=h,e[15]=C):C=e[15];let u;e[16]!==n?(u=!y&&s.jsx(H,{type:"button",variant:"ghost",size:"icon",className:"h-7 w-7 -my-1 text-muted-foreground",onClick:m,"aria-label":n("settings.projects.sidebar.actions.addProject"),children:s.jsx(_,{name:"add",className:"size-4"})}),e[16]=n,e[17]=u):u=e[17];let E;e[18]!==C||e[19]!==u?(E=s.jsxs("div",{className:"flex items-center justify-between gap-2",children:[C,u]}),e[18]=C,e[19]=u,e[20]=E):E=e[20];let q;e[21]!==E||e[22]!==N?(q=s.jsxs("div",{className:L,children:[N,E]}),e[21]=E,e[22]=N,e[23]=q):q=e[23];let M;if(e[24]!==x||e[25]!==a||e[26]!==i||e[27]!==r||e[28]!==l){let g;e[30]!==x||e[31]!==a||e[32]!==r||e[33]!==l?(g=j=>{const F=j.id===r,S=j.icon?$l[j.icon]:null,T=j.color?Bl[j.color]??null:null,v=S?s.jsx(_,{name:S,className:je("h-4 w-4",F?"text-foreground":"text-muted-foreground/70"),style:T?{color:T}:void 0}):s.jsx(_,{name:"folder",className:je("h-4 w-4",F?"text-foreground":"text-muted-foreground/70"),style:T?{color:T}:void 0}),K=j.iconImage?s.jsx("span",{className:"inline-flex h-4 w-4 items-center justify-center overflow-hidden rounded-[2px]",style:j.iconBackground?{backgroundColor:j.iconBackground}:void 0,children:s.jsx(Hl,{project:j,options:{themeVariant:x.metadata.variant,iconColor:x.colors.surface.foreground},className:"h-full w-full object-contain",fallback:v})}):v;return s.jsx(Ui,{title:j.label||j.path,icon:K,selected:F,onSelect:()=>{l(j.id),a?.()}},j.id)},e[30]=x,e[31]=a,e[32]=r,e[33]=l,e[34]=g):g=e[34],M=i.map(g),e[24]=x,e[25]=a,e[26]=i,e[27]=r,e[28]=l,e[29]=M}else M=e[29];let I;return e[35]!==q||e[36]!==M?(I=s.jsx(Xo,{variant:"background",header:q,children:M}),e[35]=q,e[36]=M,e[37]=I):I=e[37],I};function Dm(t){return t.projects}function Mm(t){return t.settingsProjectsSelectedId}function Rm(t){return t.setSettingsProjectsSelectedId}function Om(){Vl.requestDirectoryDialog()}const Lm=()=>{const t=ht.c(30),{t:e}=ot(),a=Fs(Fm),n=Fs(Km),i=de(_m),r=de(zm);let l;e:{if(!i){l=null;break e}let h;t[0]!==a||t[1]!==i?(h=a.find(C=>C.id===i)??null,t[0]=a,t[1]=i,t[2]=h):h=t[2],l=h}const x=l;let c,y;t[3]!==a||t[4]!==i||t[5]!==r?(c=()=>{if(a.length===0){r(null);return}i&&a.some(h=>h.id===i)||r(a[0].id)},y=[a,i,r],t[3]=a,t[4]=i,t[5]=r,t[6]=c,t[7]=y):(c=t[6],y=t[7]),o.useEffect(c,y);let m;t[8]!==x||t[9]!==n?(m=async h=>{x&&n(x.id,{label:h.label,icon:h.icon,color:h.color,iconBackground:h.iconBackground,defaultModel:h.defaultModel??null})},t[8]=x,t[9]=n,t[10]=m):m=t[10];const b=m;if(!x){let h;t[11]!==e?(h=e("settings.page.projects.title"),t[11]=e,t[12]=h):h=t[12];let C;t[13]!==e?(C=e("settings.projects.page.empty.noProjects"),t[13]=e,t[14]=C):C=t[14];let u;t[15]!==C?(u=s.jsx("p",{className:"typography-meta text-muted-foreground",children:C}),t[15]=C,t[16]=u):u=t[16];let E;return t[17]!==h||t[18]!==u?(E=s.jsx(rs,{title:h,showSaveStatus:!0,children:u}),t[17]=h,t[18]=u,t[19]=E):E=t[19],E}let p;t[20]!==x.label||t[21]!==e?(p=x.label??e("settings.projects.page.title.default"),t[20]=x.label,t[21]=e,t[22]=p):p=t[22];const L=p;let k;t[23]!==b||t[24]!==x?(k=s.jsx(Yc,{project:x,onIdentitySave:b}),t[23]=b,t[24]=x,t[25]=k):k=t[25];let N;return t[26]!==L||t[27]!==x.path||t[28]!==k?(N=s.jsx(rs,{title:L,description:x.path,showSaveStatus:!0,outerClassName:"bg-background",children:k}),t[26]=L,t[27]=x.path,t[28]=k,t[29]=N):N=t[29],N};function Fm(t){return t.projects}function Km(t){return t.updateProjectMeta}function _m(t){return t.settingsProjectsSelectedId}function zm(t){return t.setSettingsProjectsSelectedId}const $i=()=>Math.floor(2e4+Math.random()*3e4),Um=t=>{const e=(t instanceof Error?t.message:String(t)).toLowerCase();return e.includes("address already in use")||e.includes("eaddrinuse")||e.includes("port already in use")},Vm=()=>{if(typeof navigator>"u")return;const t=(navigator.userAgent||"").toLowerCase();if(t.includes("mac"))return"macos";if(t.includes("win"))return"windows";if(t.includes("linux"))return"linux"},qr=t=>{switch((t||"").toLowerCase()){case"ios":return"iOS";case"android":return"Android";case"macos":case"darwin":return"macOS";case"windows":case"win32":return"Windows";case"linux":return"Linux";default:return null}},Wr=t=>{switch(t){case"config_resolved":return"settings.remoteInstances.page.phase.resolvingConfiguration";case"auth_check":return"settings.remoteInstances.page.phase.checkingAuth";case"master_connecting":return"settings.remoteInstances.page.phase.establishingSsh";case"remote_probe":return"settings.remoteInstances.page.phase.probingRemote";case"installing":return"settings.remoteInstances.page.phase.installingOpenChamber";case"updating":return"settings.remoteInstances.page.phase.updatingOpenChamber";case"server_detecting":return"settings.remoteInstances.page.phase.detectingServer";case"server_starting":return"settings.remoteInstances.page.phase.startingServer";case"forwarding":return"settings.remoteInstances.page.phase.forwardingPorts";case"ready":return"settings.remoteInstances.sidebar.phase.ready";case"degraded":return"settings.remoteInstances.page.phase.reconnecting";case"error":return"settings.remoteInstances.sidebar.phase.error";default:return"settings.remoteInstances.sidebar.phase.idle"}},$m=new Set(["config_resolved","auth_check","master_connecting","remote_probe","installing","updating","server_detecting","server_starting","forwarding"]),nl=t=>!!(t&&$m.has(t)),Jr=t=>t==="ready"?"bg-[var(--status-success)] animate-pulse":t==="error"?"bg-[var(--status-error)] animate-pulse":t==="degraded"||nl(t)?"bg-[var(--status-warning)] animate-pulse":"bg-muted-foreground/40",Bm=t=>t.type==="dynamic"?`${t.localHost||"127.0.0.1"}:${t.localPort||0}`:t.type==="remote"?`${t.remoteHost||"127.0.0.1"}:${t.remotePort||0} -> ${t.localHost||"127.0.0.1"}:${t.localPort||0}`:`${t.localHost||"127.0.0.1"}:${t.localPort||0} -> ${t.remoteHost||"127.0.0.1"}:${t.remotePort||0}`,Hm=()=>({id:`forward-${Date.now()}-${Math.random().toString(16).slice(2)}`,enabled:!0,type:"local",localHost:"127.0.0.1",localPort:$i(),remoteHost:"127.0.0.1",remotePort:80}),Gm=t=>t.trim().replace(/\*/g,"host").replace(/\?/g,"x")||"user@host",tn=t=>{const e=ht.c(7),{label:a,hint:n}=t;let i;e[0]!==a?(i=s.jsx("span",{children:a}),e[0]=a,e[1]=i):i=e[1];let r;e[2]!==n?(r=s.jsx(Yt,{contentClassName:"max-w-xs",children:n}),e[2]=n,e[3]=r):r=e[3];let l;return e[4]!==i||e[5]!==r?(l=s.jsxs("span",{className:`inline-flex items-center gap-1 ${Et}`,children:[i,r]}),e[4]=i,e[5]=r,e[6]=l):l=e[6],l},qm=t=>{switch(t){case"remote":return"settings.remoteInstances.page.forwardTypeDescription.remote";case"dynamic":return"settings.remoteInstances.page.forwardTypeDescription.dynamic";default:return"settings.remoteInstances.page.forwardTypeDescription.local"}},Qr=(t,e)=>{const a=(t||"").trim();return`${!a||a==="127.0.0.1"||a==="::1"?"localhost":a}:${e||0}`},Wm=t=>{const e=(t||"").trim();return!e||e==="0.0.0.0"||e==="::"?"127.0.0.1":e},Jm=t=>{const e=t.match(/^\[(\d{10,})\]\s*(?:\[([A-Z]+)\]\s*)?(.*)$/);if(!e)return t;const a=Number(e[1]),n=Number.isFinite(a)?new Date(a).toISOString():e[1],i=(e[2]||"INFO").toUpperCase(),r=e[3]||"";return`[${n}] [${i}] ${r}`},Bi=(t="",e="")=>({id:typeof crypto<"u"&&typeof crypto.randomUUID=="function"?crypto.randomUUID():`header-${Date.now()}-${Math.random().toString(16).slice(2)}`,name:t,value:e}),Qm=t=>t.trim().toLowerCase()==="authorization",Ni=t=>{const e={};for(const a of t){const n=a.name.trim(),i=a.value.trim();n&&i&&!Qm(n)&&(e[n]=i)}return Object.keys(e).length>0?e:void 0},Ym=t=>Object.entries(t||{}).map(([e,a])=>Bi(e,a)),al=()=>{if(typeof window>"u")return null;const e=wa()||window.location.href;try{const a=Number(new URL(e).port||window.location.port);return Number.isFinite(a)&&a>0?a:null}catch{const a=Number(window.location.port);return Number.isFinite(a)&&a>0?a:null}},Yr=t=>{try{const e=new URL(t).hostname.toLowerCase();return e==="localhost"||e==="127.0.0.1"||e==="::1"||e==="[::1]"}catch{return!1}},Zm=async()=>{const t=$n(wa())||window.location.origin;if(!is()||!Na())return t;let e;try{e=await ct("/api/config/settings",{method:"GET",headers:{Accept:"application/json"}})}catch{return t}if(!e.ok||(await e.json().catch(()=>null))?.desktopLanAccessActive!==!0)return t;const n=await _o(),i=al();return!n||!i?t:`http://${n}:${i}`},ki=t=>{const e=t.trim();if(e)try{window.location.assign(e)}catch{window.location.href=e}},Xm=t=>{const e=t.sshCommand.trim(),a=t.nickname?.trim(),n=t.portForwards.map(i=>({...i,localHost:i.localHost?.trim()||"127.0.0.1",localPort:typeof i.localPort=="number"?Math.max(1,Math.min(65535,Math.round(i.localPort))):void 0,remoteHost:i.remoteHost?.trim(),remotePort:typeof i.remotePort=="number"?Math.max(1,Math.min(65535,Math.round(i.remotePort))):void 0}));return{...t,sshCommand:e,...a?{nickname:a}:{nickname:void 0},connectionTimeoutSec:Math.max(5,Math.min(240,Math.round(t.connectionTimeoutSec||60))),localForward:{...t.localForward,bindHost:t.localForward.bindHost==="localhost"||t.localForward.bindHost==="0.0.0.0"?t.localForward.bindHost:"127.0.0.1",preferredLocalPort:typeof t.localForward.preferredLocalPort=="number"?Math.max(1,Math.min(65535,Math.round(t.localForward.preferredLocalPort))):void 0},remoteOpenchamber:{...t.remoteOpenchamber,preferredPort:typeof t.remoteOpenchamber.preferredPort=="number"?Math.max(1,Math.min(65535,Math.round(t.remoteOpenchamber.preferredPort))):void 0},portForwards:n}},eu=()=>{const{t}=ot(),e=de(f=>f.timeFormatPreference),{clientAuth:a}=Mo(),n=is(),i=ws(f=>f.instances),r=ws(f=>f.statusesById),l=ws(f=>f.importCandidates),x=ws(f=>f.isLoading),c=ws(f=>f.isImportsLoading),y=ws(f=>f.isSaving),m=ws(f=>f.error),b=ws(f=>f.load),p=ws(f=>f.loadImports),L=ws(f=>f.refreshStatuses),k=ws(f=>f.upsertInstance),N=ws(f=>f.createFromCommand),h=ws(f=>f.removeInstance),C=ws(f=>f.connect),u=ws(f=>f.disconnect),E=ws(f=>f.retry),q=de(f=>f.settingsRemoteInstancesSelectedId),M=de(f=>f.setSettingsRemoteInstancesSelectedId),I=o.useMemo(()=>q&&i.find(f=>f.id===q)||null,[i,q]),[g,j]=o.useState(null),[F,S]=o.useState(!1),[T,v]=o.useState(!1),[K,$]=o.useState(null),[w,G]=o.useState([]),[Q,X]=o.useState(null),[Z,P]=o.useState(""),[ee,se]=o.useState(!1),[D,O]=o.useState({}),[U,A]=o.useState(!1),[V,W]=o.useState(!1),[te,ae]=o.useState(()=>Date.now()),[le,be]=o.useState([]),[ke,ce]=o.useState({}),[ge,Ee]=o.useState("local"),[Se,Ne]=o.useState(!1),[fe,Ke]=o.useState(!1),[De,he]=o.useState(""),[pe,Ie]=o.useState(""),[ze,Je]=o.useState(""),[_e,Le]=o.useState([]),[Pe,Ye]=o.useState(""),[Ge,Me]=o.useState(null),[$e,Fe]=o.useState(!1),[ye,z]=o.useState(!1),[oe,me]=o.useState(null),[ve,re]=o.useState(""),[Ve,Ze]=o.useState(""),[B,Ue]=o.useState(""),[Qe,et]=o.useState([]),[tt,wt]=o.useState([]),[mt,pt]=o.useState([]),[at,ft]=o.useState(!1),[gt,Ct]=o.useState(""),[ie,Ae]=o.useState(null),[Be,qe]=o.useState(null),[Nt,xt]=o.useState(null),[zt,J]=o.useState(null),[xe,Re]=o.useState(!1),[we,rt]=o.useState(!1),[lt,it]=o.useState("configure"),[It,ls]=o.useState(!1),[Xt,ts]=o.useState("relay"),[Wt,kt]=o.useState(!0),[bt,Pt]=o.useState(null),St=o.useMemo(()=>tt.filter(f=>!!f.revokedAt).length,[tt]),[Ft,Bt]=o.useState(!1),[hs,Y]=o.useState("ssh user@example.com"),[Ce,st]=o.useState("");o.useEffect(()=>{b(),p()},[b,p]);const At=o.useCallback(async()=>{Ne(!0),Me(null);try{const f=await br();be(f.hosts||[]),Ee(f.defaultHostId||"local")}catch(f){Me(f instanceof Error?f.message:String(f))}finally{Ne(!1)}},[]);o.useEffect(()=>{At()},[At]);const jt=o.useCallback(async(f,ne=ge)=>{Ke(!0),Me(null);try{await vr({hosts:f,defaultHostId:ne,initialHostChoiceCompleted:!0}),be(f),Ee(ne)}catch(Te){Me(Te instanceof Error?Te.message:String(Te))}finally{Ke(!1)}},[ge]),Jt=o.useCallback(async()=>{const f=yr(pe);if(!f){Me(t("desktopHostSwitcher.error.invalidUrl"));return}const ne=f.persistedUrl,Xe={id:typeof crypto<"u"&&typeof crypto.randomUUID=="function"?crypto.randomUUID():`host-${Date.now()}-${Math.random().toString(16).slice(2)}`,label:De.trim()||na(ne),url:ne,apiUrl:ne,...ze.trim()?{clientToken:ze.trim()}:{},...Ni(_e)?{requestHeaders:Ni(_e)}:{}};await jt([Xe,...le],ge),he(""),Ie(""),Je(""),Le([]),Fe(!1),f.redeemUrl&&ki(f.redeemUrl)},[ge,_e,le,De,ze,pe,jt,t]),fs=o.useCallback(async()=>{const f=Sc(Pe);if(!f){Me(t("settings.remoteInstances.direct.error.invalidConnectLink"));return}const ne=await Cc().catch(()=>""),Te=JSON.stringify({pairingId:f.pairingId,secret:f.secret,clientLabel:f.label||"OpenChamber Desktop",clientKind:"desktop",deviceName:"OpenChamber Desktop",devicePlatform:Vm(),...ne?{dedupeKey:`desktop:${ne}`}:{}}),Xe={method:"POST",headers:{"Content-Type":"application/json",Accept:"application/json"},body:Te},Lt=async Ot=>{if(!Ot.ok)return null;const as=await Ot.json().catch(()=>null);return(typeof as?.clientToken=="string"?as.clientToken.trim():"")||null},js=[...f.candidates].sort((Ot,as)=>(Ot.type==="relay"?1:0)-(as.type==="relay"?1:0));let es=null;for(const Ot of js){if(Ot.type==="relay"){const _s=Ic({relayUrl:Ot.relayUrl,serverId:Ot.serverId,hostEncPubJwk:Ot.hostEncPubJwk,...Ot.grant?{grant:Ot.grant}:{}});try{const Rs=await _s.fetch("/api/client-auth/pairing/redeem",Xe),Ma=await Lt(Rs);if(Ma){es={kind:"relay",relay:{relayUrl:Ot.relayUrl,serverId:Ot.serverId,hostEncPubJwk:Ot.hostEncPubJwk},token:Ma};break}}catch{}finally{_s.close()}continue}const as=$n(Ot.url);if(as)try{const _s=await fetch(`${as}/api/client-auth/pairing/redeem`,Xe),Rs=await Lt(_s);if(Rs){es={kind:"direct",url:as,token:Rs};break}}catch{}}if(!es){Me(t("desktopHostSwitcher.error.invalidUrl"));return}const Es=()=>typeof crypto<"u"&&typeof crypto.randomUUID=="function"?crypto.randomUUID():`host-${Date.now()}-${Math.random().toString(16).slice(2)}`,Xs=f.candidates.find(Ot=>Ot.type==="relay"),Ms=es.kind==="relay"?es.relay:Xs?{relayUrl:Xs.relayUrl,serverId:Xs.serverId,hostEncPubJwk:Xs.hostEncPubJwk}:void 0,Zn=f.candidates.filter(Ot=>Ot.type!=="relay").map(Ot=>$n(Ot.url)).find(Ot=>!!Ot),Nn=es.kind==="direct"?es.url:Zn,{token:Xn}=es,Tt=Nn||(Ms?Pc(Ms.serverId):null);if(!Tt){Me(t("desktopHostSwitcher.error.invalidUrl"));return}const Zt={url:Tt,apiUrl:Nn||void 0,clientToken:Xn,...Ms?{relay:Ms}:{}},kn=le.find(Ot=>Ms?Ot.relay?.serverId===Ms.serverId:!Ot.relay&&$n(Ot.apiUrl||Ot.url)===Tt);if(kn){const Ot=le.map(as=>as.id===kn.id?{...as,label:f.label||as.label,...Zt}:as);await jt(Ot,ge)}else await jt([{id:Es(),label:f.label||na(Tt),...Zt},...le],ge);Ye(""),Me(null),z(!1)},[Pe,ge,le,jt,t]),cs=o.useCallback(async f=>{const ne=le.filter(Xe=>Xe.id!==f);await jt(ne,ge===f?"local":ge),oe===f&&me(null)},[ge,oe,le,jt]),Ts=o.useCallback(f=>{me(f.id),re(f.label),Ze(f.apiUrl||f.url),Ue(f.clientToken||""),et(Ym(f.requestHeaders)),Me(null)},[]),Ws=o.useCallback(async()=>{if(!oe)return;const f=yr(Ve);if(!f){Me(t("desktopHostSwitcher.error.invalidUrl"));return}const ne=f.persistedUrl,Te=le.map(Xe=>Xe.id===oe?{...Xe,label:ve.trim()||na(ne),url:ne,apiUrl:ne,clientToken:B.trim()||void 0,requestHeaders:Ni(Qe)}:Xe);await jt(Te,ge),me(null),f.redeemUrl&&ki(f.redeemUrl)},[ge,Qe,ve,B,Ve,oe,le,jt,t]),ei=o.useCallback(async()=>{const f=hs.trim();if(!f){R.error(t("settings.remoteInstances.page.toast.sshCommandRequired"));return}const ne=`ssh-${Date.now()}-${Math.random().toString(16).slice(2)}`;try{await N(ne,f,Ce.trim()||t("settings.remoteInstances.sidebar.newSshInstanceName")),M(ne),Bt(!1),Y("ssh user@example.com"),st(""),R.success(t("settings.remoteInstances.page.toast.instanceCreated"))}catch(Te){R.error(t("settings.remoteInstances.sidebar.toast.createFailed"),{description:Te instanceof Error?Te.message:String(Te)})}},[N,M,hs,Ce,t]),ti=o.useCallback(async f=>{await jt(le,f)},[le,jt]);o.useEffect(()=>{if(!n||le.length===0)return;let f=!1;return Promise.all(le.map(async ne=>{const Te=()=>Rc(ne.relay,{clientToken:ne.clientToken||null,requestHeaders:ne.requestHeaders||null}).catch(()=>({status:"unreachable",latencyMs:0}));if(ne.relay&&!ne.apiUrl)return[ne.id,await Te()];const Xe=$n(Ac(ne));if(!Xe)return[ne.id,ne.relay?await Te():{status:"unreachable",latencyMs:0}];const Lt=await Tc(Xe,{clientToken:ne.clientToken||null,requestHeaders:ne.requestHeaders||null}).catch(()=>({status:"unreachable",latencyMs:0}));if(Lt.status==="unreachable"&&ne.relay){const js=await Te();if(js.status==="ok")return[ne.id,js]}return[ne.id,Lt]})).then(ne=>{f||ce(Object.fromEntries(ne))}),()=>{f=!0}},[le,n]);const Ss=o.useCallback(async f=>{if(a){f?.silent||ft(!0),f?.silent||Ae(null);try{const[ne,Te]=await Promise.all([a.listClients(),a.listPendingPairings().catch(()=>null)]);wt(ne),Te&&pt(Te)}catch(ne){f?.silent||Ae(ne instanceof Error?ne.message:String(ne))}finally{f?.silent||ft(!1)}}},[a]),Qn=o.useRef(!1);o.useEffect(()=>{if(!(!we||lt!=="result"||!Nt)){if(mt.some(f=>f.id===Nt)){Qn.current=!0;return}Qn.current&&(xt(null),rt(!1),tt.some(f=>f.pairingId===Nt)&&R.success(t("settings.remoteInstances.clientAuth.addDevice.connectedToast")))}},[we,lt,Nt,mt,tt,t]);const si=o.useCallback(async f=>{if(a)try{await a.cancelPairing(f),pt(ne=>ne.filter(Te=>Te.id!==f)),await Ss({silent:!0})}catch(ne){Ae(ne instanceof Error?ne.message:String(ne))}},[a,Ss]);o.useEffect(()=>{if(!a)return;Ss();const f=window.setInterval(()=>{typeof document<"u"&&document.visibilityState!=="visible"||Ss({silent:!0})},5e3);return()=>window.clearInterval(f)},[a,Ss]);const Sa=o.useCallback(async()=>{if(a?.getPairingTransports)try{const Xe=await a.getPairingTransports();return{localUrl:Xe.local,lanUrl:Xe.lan,relayAvailable:Xe.relayAvailable}}catch{}const f=al(),ne=f?`http://127.0.0.1:${f}`:Yr(window.location.origin)?window.location.origin:null;let Te=null;try{const Xe=$n(await Zm());Te=Xe&&!Yr(Xe)?Xe:null}catch{}return{localUrl:ne,lanUrl:Te,relayAvailable:!0}},[a]),ni=o.useCallback(async()=>{Ae(null),qe(null),J(null),Re(!1),xt(null),it("configure"),kt(!0),rt(!0);const f=await Sa();Pt(f),ts(f.relayAvailable?"relay":f.lanUrl?"lan":"local")},[Sa]),ai=o.useCallback(async()=>{if(!(!a?.createPairingSession||!bt)){Ae(null),ls(!0);try{const f=gt.trim()||void 0;let ne,Te,Xe=!0;Xt==="local"?(ne=bt.localUrl??void 0,Te=!1):Xt==="lan"?(ne=bt.lanUrl??void 0,Te=Wt):Wt&&bt.lanUrl?(ne=bt.lanUrl,Te=!0):(Xe=!1,Te=!0);const{pairing:Lt,server:js}=await a.createPairingSession({label:f,allowedClientKinds:["mobile","desktop"],serverUrl:ne,includeRelay:Te,includeDirect:Xe}),es=Ec({pairingId:Lt.id,secret:Lt.secret,label:js.label,fingerprint:Lt.fingerprint??void 0,expiresAt:Lt.expiresAt,candidates:js.candidates}),Es=Dc(es);qe(Es),J(await Go.toDataURL(Es,{width:1024,margin:2,errorCorrectionLevel:"L"})),Re(!1),Qn.current=!1,xt(Lt.id),it("result"),await Ss({silent:!0})}catch(f){Ae(f instanceof Error?f.message:String(f))}finally{ls(!1)}}},[a,bt,Xt,Wt,gt,Ss]),ii=o.useCallback(()=>{Be&&ga(Be).then(f=>{f.ok&&(Re(!0),window.setTimeout(()=>Re(!1),2e3))})},[Be]),ri=o.useCallback(async f=>{if(!a)return;const ne=f.clientKind==="desktop-local";Ae(null);try{if(await a.revokeClient(f.id),ne&&is()){const Te=await br();await vr({hosts:Te.hosts,defaultHostId:Te.defaultHostId,initialHostChoiceCompleted:Te.initialHostChoiceCompleted,localClientToken:null}),wt(Xe=>Xe.map(Lt=>Lt.id===f.id?{...Lt,revokedAt:new Date().toISOString()}:Lt)),Mc({apiBaseUrl:wa(),clientToken:null,runtimeKey:"local"});return}await Ss()}catch(Te){Ae(Te instanceof Error?Te.message:String(Te))}},[a,Ss]),oi=o.useCallback(async()=>{if(a){Ae(null);try{await a.purgeRevokedClients(),await Ss()}catch(f){Ae(f instanceof Error?f.message:String(f))}}},[a,Ss]);o.useEffect(()=>{j(I)},[I]),o.useEffect(()=>{if(!q)return;const f=window.setInterval(()=>{typeof document<"u"&&document.visibilityState!=="visible"||L()},2e3);return()=>{window.clearInterval(f)}},[L,q]),o.useEffect(()=>{let f=null,ne=Date.now();const Te=()=>{const Lt=Date.now();Lt-ne>=1e3&&(ae(Lt),ne=Lt),f=requestAnimationFrame(Te)};(typeof document>"u"||document.visibilityState==="visible")&&(f=requestAnimationFrame(Te));const Xe=()=>{document.visibilityState==="visible"&&f===null?f=requestAnimationFrame(Te):document.visibilityState!=="visible"&&f!==null&&(cancelAnimationFrame(f),f=null)};return document.addEventListener("visibilitychange",Xe),()=>{document.removeEventListener("visibilitychange",Xe),f!==null&&cancelAnimationFrame(f)}},[]);const Cs=q?r[q]:null,Ks=Cs?.phase,Fn=Ks==="ready",Js=Ks==="degraded",ln=nl(Ks),cn=Fn||(ln||Js),li=Cs?Math.max(0,te-Cs.updatedAtMs):0,Kn=Js&&li>12e3,ci=o.useMemo(()=>!g||!I?!1:JSON.stringify(g)!==JSON.stringify(I),[g,I]),ps=o.useCallback(f=>{j(ne=>ne&&f(ne))},[]),di=o.useCallback(async()=>{if(!g)return;const f=Xm(g);if(!f.sshCommand.trim()){R.error(t("settings.remoteInstances.page.toast.sshCommandRequired"));return}if(!(f.localForward.bindHost==="0.0.0.0"&&!window.confirm(t("settings.remoteInstances.page.confirm.bindAllInterfaces")))){if(f.auth.sshPassword?.enabled&&f.auth.sshPassword.value?.trim()&&f.auth.sshPassword.store!=="settings"){const ne=window.confirm(t("settings.remoteInstances.page.confirm.storeSshPasswordPlaintext"));f.auth.sshPassword.store=ne?"settings":"never",ne||(f.auth.sshPassword.value=void 0)}if(f.auth.openchamberPassword?.enabled&&f.auth.openchamberPassword.value?.trim()&&f.auth.openchamberPassword.store!=="settings"){const ne=window.confirm(t("settings.remoteInstances.page.confirm.storeUiPasswordPlaintext"));f.auth.openchamberPassword.store=ne?"settings":"never",ne||(f.auth.openchamberPassword.value=void 0)}try{await k(f),R.success(t("settings.remoteInstances.page.toast.instanceSaved"))}catch(ne){R.error(t("settings.remoteInstances.page.toast.saveFailed"),{description:ne instanceof Error?ne.message:String(ne)})}}},[g,t,k]),Qs=o.useCallback(async(f,ne)=>{const Te=`ssh-${Date.now()}-${Math.random().toString(16).slice(2)}`;try{return await N(Te,`ssh ${ne}`,f),M(Te),R.success(t("settings.remoteInstances.page.toast.instanceCreated")),!0}catch(Xe){return R.error(t("settings.remoteInstances.sidebar.toast.createFailed"),{description:Xe instanceof Error?Xe.message:String(Xe)}),!1}},[N,M,t]),Ys=o.useCallback(()=>{ee||(X(null),P(""))},[ee]),Yn=o.useCallback((f,ne)=>{if(ne){X(f),P(Gm(f));return}Qs(f,f)},[Qs]),_n=o.useCallback(async()=>{const f=Q,ne=Z.trim();if(f){if(!ne){R.error(t("settings.remoteInstances.page.toast.destinationRequired"));return}se(!0);try{await Qs(f,ne)&&(X(null),P(""))}finally{se(!1)}}},[Qs,Z,Q,t]),Zs=o.useCallback(async()=>{if(I)try{await C(I.id);return}catch(f){if(!Um(f)||!window.confirm(t("settings.remoteInstances.sidebar.confirm.localPortInUseRetry")))throw f;const Te={...I,localForward:{...I.localForward,preferredLocalPort:$i()}};await k(Te),await C(Te.id),R.success(t("settings.remoteInstances.sidebar.toast.retriedWithRandomPort"))}},[C,I,t,k]),ue=o.useCallback(async f=>(await Gl(f,600)).map(Te=>Jm(Te)),[]),ns=o.useCallback(async()=>{if(g){S(!0),v(!0),$(null);try{const f=await ue(g.id);G(f)}catch(f){G([]),$(f instanceof Error?f.message:String(f))}finally{v(!1)}}},[g,ue]);o.useEffect(()=>{if(!F||!g)return;let f=!1;const ne=async()=>{try{const Xe=await ue(g.id);f||(G(Xe),$(null))}catch(Xe){f||$(Xe instanceof Error?Xe.message:String(Xe))}};ne();const Te=window.setInterval(()=>{typeof document<"u"&&document.visibilityState!=="visible"||ne()},1e3);return()=>{f=!0,window.clearInterval(Te)}},[g,F,ue]);const wn=o.useMemo(()=>w.join(`
27
+ `),[w]),Ca=o.useCallback(()=>{if(!wn.trim()){R.error(t("settings.remoteInstances.page.toast.noLogsToCopy"));return}ga(wn).then(f=>{f.ok&&R.success(t("settings.remoteInstances.page.toast.logsCopied"))})},[wn,t]),Ia=o.useCallback(async()=>{if(g)try{await ql(g.id),G([]),R.success(t("settings.remoteInstances.page.toast.logsCleared"))}catch(f){R.error(t("settings.remoteInstances.page.toast.clearLogsFailed"),{description:f instanceof Error?f.message:String(f)})}},[g,t]),Pa=o.useCallback(async()=>{if(!Cs?.localUrl){R.error(t("settings.remoteInstances.page.toast.instanceUrlUnavailable"));return}const f=Cs.localUrl.trim();if(!f){R.error(t("settings.remoteInstances.page.toast.instanceUrlUnavailable"));return}ki(f)},[Cs?.localUrl,t]),Aa=o.useCallback(()=>{if(!g)return;A(!0),(cn?u(g.id):Zs()).catch(ne=>{const Te=cn?Fn?"settings.remoteInstances.page.toast.disconnectFailed":"settings.remoteInstances.page.toast.cancelConnectionFailed":"settings.remoteInstances.page.toast.connectFailed";R.error(t(Te),{description:ne instanceof Error?ne.message:String(ne)})}).finally(()=>{A(!1)})},[cn,Zs,u,g,Fn,t]),Ta=o.useCallback(()=>{if(!g||ln)return;W(!0),(Js?u(g.id).then(()=>Zs()):E(g.id)).catch(ne=>{R.error(t("settings.remoteInstances.page.toast.retryFailed"),{description:ne instanceof Error?ne.message:String(ne)})}).finally(()=>{W(!1)})},[Zs,u,g,ln,Js,E,t]),Ea=t(ln?"settings.remoteInstances.page.actions.connecting":Js?Kn?"settings.remoteInstances.page.actions.reconnectNow":"settings.remoteInstances.page.actions.reconnecting":"settings.remoteInstances.sidebar.actions.retry"),pi=!U&&!V&&(Ks==="error"||Ks==="idle"||!Ks||Js&&Kn)&&!ln,zn=t(Fn?"settings.remoteInstances.sidebar.actions.disconnect":cn?"settings.remoteInstances.page.actions.cancel":"settings.remoteInstances.sidebar.actions.connect");if(!g)return s.jsxs(rs,{title:t("settings.page.remoteInstances.title"),children:[a?s.jsxs(Oe,{title:t("settings.remoteInstances.clientAuth.title"),info:t("settings.remoteInstances.clientAuth.description"),divider:!1,settingsItem:"remote-instances.client-auth",contentClassName:"space-y-3",children:[s.jsx("div",{children:s.jsxs(H,{type:"button",size:"xs",className:"!font-normal",onClick:()=>{ni()},children:[s.jsx(_,{name:"add",className:"h-3.5 w-3.5"}),t("settings.remoteInstances.clientAuth.actions.addDevice")]})}),s.jsxs("div",{className:"space-y-2.5",children:[St>0?s.jsx("div",{className:"flex justify-end",children:s.jsx(H,{type:"button",variant:"ghost",size:"xs",className:"!font-normal",onClick:()=>{oi()},children:t("settings.remoteInstances.clientAuth.actions.clearRevoked")})}):null,at&&tt.length===0&&mt.length===0?s.jsx("p",{className:"typography-meta text-muted-foreground",children:t("settings.remoteInstances.clientAuth.state.loading")}):tt.length===0&&mt.length===0?s.jsx("p",{className:"typography-meta text-muted-foreground",children:t("settings.remoteInstances.clientAuth.state.empty")}):s.jsxs(s.Fragment,{children:[mt.map(f=>s.jsxs("div",{className:"flex items-center justify-between gap-3 py-1.5",children:[s.jsxs("div",{className:"min-w-0 space-y-0.5",children:[s.jsxs("div",{className:"flex min-w-0 items-center gap-2",children:[s.jsx("span",{className:"h-2 w-2 shrink-0 rounded-full bg-[var(--status-warning)] animate-pulse"}),s.jsx("p",{className:"typography-ui-label text-foreground truncate",children:f.label||t("settings.remoteInstances.clientAuth.field.labelPlaceholder")}),f.usesRelay?s.jsx("span",{className:"typography-micro text-muted-foreground bg-muted px-1 rounded shrink-0 leading-none pb-px border border-border/50",children:t("settings.remoteInstances.clientAuth.state.viaRelay")}):null]}),s.jsx("p",{className:"typography-micro text-muted-foreground truncate",children:t("settings.remoteInstances.clientAuth.state.pending")})]}),s.jsx(H,{type:"button",variant:"ghost",size:"xs",className:"!font-normal",onClick:()=>{si(f.id)},children:t("settings.common.actions.cancel")})]},`pending-${f.id}`)),tt.map(f=>{const ne=f.clientKind==="desktop-local",Te=f.lastUsedAt?Date.parse(f.lastUsedAt):Number.NaN,Xe=!f.revokedAt&&(ne||Number.isFinite(Te)&&Date.now()-Te<9e4),Lt=f.revokedAt?t("settings.remoteInstances.clientAuth.state.revoked"):Xe?f.lastTransport==="relay"&&!ne?t("settings.remoteInstances.clientAuth.state.connectedRelay"):t("settings.remoteInstances.clientAuth.state.connectedDirect"):Number.isFinite(Te)?t("settings.remoteInstances.clientAuth.lastUsed",{date:Wl(Te,e,{month:"short",day:"numeric",hour:"numeric",minute:"2-digit"})}):t("settings.remoteInstances.clientAuth.neverUsed");return s.jsxs("div",{className:"flex items-center justify-between gap-3 py-1.5",children:[s.jsx("div",{className:"min-w-0",children:s.jsxs("div",{className:"flex min-w-0 flex-wrap items-center gap-x-2 gap-y-0.5",children:[s.jsx("span",{className:je("h-2 w-2 shrink-0 rounded-full",f.revokedAt?"bg-muted-foreground/20":Xe?"bg-[var(--status-success)]":"bg-muted-foreground/30")}),s.jsx("p",{className:"typography-ui-label text-foreground truncate",children:f.label}),qr(f.devicePlatform)?s.jsx("span",{className:"typography-micro text-muted-foreground bg-muted px-1 rounded shrink-0 leading-none pb-px border border-border/50",children:qr(f.devicePlatform)}):null,ne?s.jsx("span",{className:"typography-micro text-muted-foreground bg-muted px-1 rounded flex-shrink-0 leading-none pb-px border border-border/50",children:t("settings.remoteInstances.clientAuth.state.thisDevice")}):null,s.jsx("span",{className:je("typography-micro truncate",Xe&&!f.revokedAt?"text-[var(--status-success)]":"text-muted-foreground"),children:Lt})]})}),s.jsx(H,{type:"button",variant:"ghost",size:"xs",className:"!font-normal",onClick:()=>{ri(f)},disabled:!!f.revokedAt,children:t("settings.remoteInstances.clientAuth.actions.revoke")})]},f.id)})]})]}),ie?s.jsx("p",{className:"typography-meta text-[var(--status-error)]",children:ie}):null]}):null,n?s.jsxs(Oe,{title:t("settings.remoteInstances.direct.title"),info:t("settings.remoteInstances.direct.description"),settingsItem:"remote-instances.direct-hosts",contentClassName:"space-y-4",headerAction:s.jsxs("div",{className:"flex shrink-0 items-center gap-2",children:[s.jsx(H,{type:"button",size:"xs",className:"!font-normal",onClick:()=>z(!0),disabled:fe,children:t("settings.remoteInstances.direct.import.action")}),s.jsxs(H,{type:"button",variant:"outline",size:"xs",className:"!font-normal",onClick:()=>Fe(!0),disabled:fe,children:[s.jsx(_,{name:"add",className:"h-3.5 w-3.5"}),t("settings.remoteInstances.direct.actions.add")]})]}),children:[s.jsx("div",{className:"space-y-2.5",children:Se?s.jsx("p",{className:"typography-meta text-muted-foreground",children:t("settings.remoteInstances.direct.state.loading")}):le.length===0?s.jsx("p",{className:"typography-meta text-muted-foreground",children:t("settings.remoteInstances.direct.state.empty")}):le.map(f=>{const ne=ke[f.id],Te=ne?ne.status==="ok"?"desktopHostSwitcher.status.connected":ne.status==="auth"?"desktopHostSwitcher.status.authRequired":ne.status==="update-recommended"?"desktopHostSwitcher.status.updateRecommended":ne.status==="incompatible"?"desktopHostSwitcher.status.incompatible":ne.status==="wrong-service"?"desktopHostSwitcher.status.wrongService":"desktopHostSwitcher.status.unreachable":"desktopHostSwitcher.status.checking",Xe=ne?.status==="ok";return s.jsx("div",{className:"py-1.5",children:s.jsxs("div",{className:"flex items-center justify-between gap-3",children:[s.jsxs("div",{className:"min-w-0 space-y-0.5",children:[s.jsxs("div",{className:"flex min-w-0 items-center gap-2",children:[s.jsx("span",{className:je("h-2 w-2 shrink-0 rounded-full",ne?Xe?"bg-[var(--status-success)]":"bg-[var(--status-error)]":"bg-muted-foreground/30 animate-pulse")}),s.jsx("p",{className:"typography-ui-label text-foreground truncate",children:na(f.label)}),ge===f.id?s.jsx("span",{className:"typography-micro text-muted-foreground shrink-0",children:t("desktopHostSwitcher.header.default")}):null,s.jsxs("span",{className:je("typography-micro shrink-0",Xe?"text-[var(--status-success)]":"text-muted-foreground"),children:[t(Te),Xe&&typeof ne?.latencyMs=="number"?t("desktopHostSwitcher.status.ping",{ms:Math.max(0,Math.round(ne.latencyMs))}):""]})]}),s.jsx("p",{className:je("typography-micro text-muted-foreground truncate",f.apiUrl&&"font-mono"),children:f.relay&&!f.apiUrl?t("mobile.connect.relay.badge"):na(f.apiUrl||f.url)})]}),s.jsxs("div",{className:"flex shrink-0 items-center gap-1",children:[s.jsx(H,{type:"button",variant:"ghost",size:"xs",className:"!font-normal",onClick:()=>{ti(f.id)},disabled:fe||ge===f.id,"aria-label":t("desktopHostSwitcher.actions.setAsDefaultAria"),children:ge===f.id?s.jsx(_,{name:"star-fill",className:"h-3.5 w-3.5"}):s.jsx(_,{name:"star",className:"h-3.5 w-3.5"})}),f.relay&&!f.apiUrl?null:s.jsxs(H,{type:"button",variant:"ghost",size:"xs",className:"!font-normal",onClick:()=>Ts(f),disabled:fe,children:[s.jsx(_,{name:"pencil",className:"h-3.5 w-3.5"}),t("desktopHostSwitcher.actions.edit")]}),s.jsxs(H,{type:"button",variant:"ghost",size:"xs",className:"!font-normal",onClick:()=>{cs(f.id)},disabled:fe,children:[s.jsx(_,{name:"delete-bin",className:"h-3.5 w-3.5"}),t("settings.common.actions.delete")]})]})]})},f.id)})}),Ge?s.jsx("p",{className:"typography-meta text-[var(--status-error)]",children:Ge}):null]}):null,n?s.jsx(Ut,{open:$e,onOpenChange:Fe,children:s.jsxs(Vt,{className:"sm:max-w-lg",children:[s.jsxs(Ht,{children:[s.jsx(Gt,{children:t("settings.remoteInstances.direct.actions.add")}),s.jsx(qt,{children:t("settings.remoteInstances.direct.addDialog.description")})]}),s.jsxs("form",{className:"space-y-3",onSubmit:f=>{f.preventDefault(),Jt()},children:[s.jsx(He,{className:"h-8",value:De,onChange:f=>he(f.target.value),placeholder:t("settings.remoteInstances.direct.field.labelPlaceholder"),disabled:fe}),s.jsx(He,{className:"h-8",value:pe,onChange:f=>Ie(f.target.value),placeholder:t("settings.remoteInstances.direct.field.urlPlaceholder"),disabled:fe,autoFocus:!0}),s.jsxs("div",{className:"space-y-1",children:[s.jsx(He,{className:"h-8",value:ze,onChange:f=>Je(f.target.value),placeholder:t("settings.remoteInstances.direct.field.tokenPlaceholder"),type:"password",disabled:fe}),s.jsx("p",{className:"px-1 typography-micro text-muted-foreground",children:t("settings.remoteInstances.direct.note")})]}),s.jsxs("div",{className:"space-y-2",children:[s.jsxs("div",{className:"flex items-center gap-1.5",children:[s.jsx(Vs,{children:t("settings.remoteInstances.direct.headers.title")}),s.jsx(Yt,{children:t("settings.remoteInstances.direct.headers.description")})]}),_e.map(f=>s.jsxs("div",{className:"flex w-full gap-2",children:[s.jsx(He,{className:"h-8 font-mono text-xs",value:f.name,onChange:ne=>Le(Te=>Te.map(Xe=>Xe.id===f.id?{...Xe,name:ne.target.value}:Xe)),placeholder:t("settings.remoteInstances.direct.headers.field.namePlaceholder"),disabled:fe}),s.jsx(He,{className:"h-8 font-mono text-xs",value:f.value,onChange:ne=>Le(Te=>Te.map(Xe=>Xe.id===f.id?{...Xe,value:ne.target.value}:Xe)),placeholder:t("settings.remoteInstances.direct.headers.field.valuePlaceholder"),type:"password",disabled:fe}),s.jsx("button",{type:"button",onClick:()=>Le(ne=>ne.filter(Te=>Te.id!==f.id)),className:"flex h-8 w-8 flex-shrink-0 items-center justify-center rounded-md text-muted-foreground hover:bg-[var(--status-error-background)] hover:text-[var(--status-error)] focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-[var(--interactive-focus-ring)]","aria-label":t("settings.remoteInstances.direct.headers.removeAria"),disabled:fe,children:s.jsx(_,{name:"close",className:"h-4 w-4"})})]},f.id)),s.jsxs(H,{type:"button",variant:"ghost",size:"xs",className:"!font-normal",onClick:()=>Le(f=>[...f,Bi()]),disabled:fe,children:[s.jsx(_,{name:"add",className:"h-3.5 w-3.5"}),t("settings.remoteInstances.direct.headers.actions.add")]})]}),s.jsxs("div",{className:"flex justify-end gap-2",children:[s.jsx(H,{type:"button",variant:"outline",size:"xs",className:"!font-normal",onClick:()=>Fe(!1),disabled:fe,children:t("settings.common.actions.cancel")}),s.jsx(H,{type:"submit",size:"xs",className:"!font-normal",disabled:fe||!pe.trim(),children:t("settings.remoteInstances.direct.actions.add")})]})]})]})}):null,n?s.jsx(Ut,{open:!!oe,onOpenChange:f=>{f||me(null)},children:s.jsxs(Vt,{className:"sm:max-w-lg",children:[s.jsxs(Ht,{children:[s.jsx(Gt,{children:t("desktopHostSwitcher.actions.edit")}),s.jsx(qt,{children:t("settings.remoteInstances.direct.description")})]}),s.jsxs("form",{className:"space-y-3",onSubmit:f=>{f.preventDefault(),Ws()},children:[s.jsx(He,{className:"h-8",value:ve,onChange:f=>re(f.target.value),placeholder:t("settings.remoteInstances.direct.field.labelPlaceholder"),disabled:fe}),s.jsx(He,{className:"h-8",value:Ve,onChange:f=>Ze(f.target.value),placeholder:t("settings.remoteInstances.direct.field.urlPlaceholder"),disabled:fe,autoFocus:!0}),s.jsx(He,{className:"h-8",value:B,onChange:f=>Ue(f.target.value),placeholder:t("settings.remoteInstances.direct.field.tokenPlaceholder"),type:"password",disabled:fe}),s.jsxs("div",{className:"space-y-2",children:[s.jsxs("div",{className:"flex items-center gap-1.5",children:[s.jsx(Vs,{children:t("settings.remoteInstances.direct.headers.title")}),s.jsx(Yt,{children:t("settings.remoteInstances.direct.headers.description")})]}),Qe.map(f=>s.jsxs("div",{className:"flex w-full gap-2",children:[s.jsx(He,{className:"h-8 font-mono text-xs",value:f.name,onChange:ne=>et(Te=>Te.map(Xe=>Xe.id===f.id?{...Xe,name:ne.target.value}:Xe)),placeholder:t("settings.remoteInstances.direct.headers.field.namePlaceholder"),disabled:fe}),s.jsx(He,{className:"h-8 font-mono text-xs",value:f.value,onChange:ne=>et(Te=>Te.map(Xe=>Xe.id===f.id?{...Xe,value:ne.target.value}:Xe)),placeholder:t("settings.remoteInstances.direct.headers.field.valuePlaceholder"),type:"password",disabled:fe}),s.jsx("button",{type:"button",onClick:()=>et(ne=>ne.filter(Te=>Te.id!==f.id)),className:"flex h-8 w-8 flex-shrink-0 items-center justify-center rounded-md text-muted-foreground hover:bg-[var(--status-error-background)] hover:text-[var(--status-error)] focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-[var(--interactive-focus-ring)]","aria-label":t("settings.remoteInstances.direct.headers.removeAria"),disabled:fe,children:s.jsx(_,{name:"close",className:"h-4 w-4"})})]},f.id)),s.jsxs(H,{type:"button",variant:"ghost",size:"xs",className:"!font-normal",onClick:()=>et(f=>[...f,Bi()]),disabled:fe,children:[s.jsx(_,{name:"add",className:"h-3.5 w-3.5"}),t("settings.remoteInstances.direct.headers.actions.add")]})]}),s.jsxs("div",{className:"flex justify-end gap-2",children:[s.jsx(H,{type:"button",variant:"outline",size:"xs",className:"!font-normal",onClick:()=>me(null),disabled:fe,children:t("settings.common.actions.cancel")}),s.jsx(H,{type:"submit",size:"xs",className:"!font-normal",disabled:fe,children:t("settings.common.actions.saveChanges")})]})]})]})}):null,n?s.jsx(Ut,{open:ye,onOpenChange:z,children:s.jsxs(Vt,{className:"sm:max-w-lg",children:[s.jsxs(Ht,{children:[s.jsx(Gt,{children:t("settings.remoteInstances.direct.import.action")}),s.jsx(qt,{children:t("settings.remoteInstances.direct.import.description")})]}),s.jsxs("form",{className:"space-y-3",onSubmit:f=>{f.preventDefault(),fs()},children:[s.jsx(He,{className:"h-8",value:Pe,onChange:f=>Ye(f.target.value),placeholder:t("settings.remoteInstances.direct.import.placeholder"),disabled:fe,autoFocus:!0}),s.jsxs("div",{className:"flex justify-end gap-2",children:[s.jsx(H,{type:"button",variant:"outline",size:"xs",className:"!font-normal",onClick:()=>z(!1),disabled:fe,children:t("settings.common.actions.cancel")}),s.jsx(H,{type:"submit",size:"xs",className:"!font-normal",disabled:fe||!Pe.trim(),children:t("settings.remoteInstances.direct.import.action")})]})]})]})}):null,s.jsx(Ut,{open:we,onOpenChange:rt,children:s.jsxs(Vt,{className:lt==="result"?"sm:max-w-lg":"sm:max-w-md",children:[s.jsxs(Ht,{children:[s.jsx(Gt,{children:t(lt==="result"?"settings.remoteInstances.clientAuth.qrDialogTitle":"settings.remoteInstances.clientAuth.actions.addDevice")}),s.jsx(qt,{children:t(lt==="result"?"settings.remoteInstances.clientAuth.qrScanHint":"settings.remoteInstances.clientAuth.addDevice.subtitle")})]}),lt==="configure"?s.jsxs("form",{className:"space-y-4",onSubmit:f=>{f.preventDefault(),ai()},children:[s.jsx(He,{className:"h-8",value:gt,onChange:f=>Ct(f.target.value),placeholder:t("settings.remoteInstances.clientAuth.field.labelPlaceholder"),autoFocus:!0}),s.jsxs("div",{className:"space-y-1.5",children:[s.jsx("p",{className:"typography-ui-label text-foreground",children:t("settings.remoteInstances.clientAuth.addDevice.transportLabel")}),s.jsx("div",{role:"radiogroup","aria-label":t("settings.remoteInstances.clientAuth.addDevice.transportLabel"),className:"space-y-1.5",children:[{key:"relay",label:t("settings.remoteInstances.clientAuth.addDevice.transport.relay"),hint:t("settings.remoteInstances.clientAuth.addDevice.transport.relayHint"),available:!!bt?.relayAvailable},{key:"lan",label:t("settings.remoteInstances.clientAuth.addDevice.transport.lan"),hint:t("settings.remoteInstances.clientAuth.addDevice.transport.lanHint"),available:!!bt?.lanUrl},{key:"local",label:t("settings.remoteInstances.clientAuth.addDevice.transport.local"),hint:t("settings.remoteInstances.clientAuth.addDevice.transport.localHint"),available:!!bt?.localUrl}].map(f=>{const ne=Xt===f.key;return s.jsxs("div",{className:je("flex items-start gap-2 py-0.5",f.available?"cursor-pointer":"opacity-45"),onClick:()=>{f.available&&ts(f.key)},role:"presentation",children:[s.jsx(Wi,{checked:ne,disabled:!f.available,onChange:()=>ts(f.key),ariaLabel:f.label,className:"mt-0.5"}),s.jsxs("div",{className:"min-w-0",children:[s.jsx("p",{className:je("typography-ui-label font-normal",ne?"text-foreground":"text-foreground/70"),children:f.label}),s.jsx("p",{className:"typography-meta text-muted-foreground",children:f.hint})]})]},f.key)})}),Xt==="lan"?s.jsxs("label",{className:"flex w-fit cursor-pointer items-center gap-2 pt-1",children:[s.jsx(Li,{checked:Wt,onChange:kt,ariaLabel:t("settings.remoteInstances.clientAuth.addDevice.fallback.relay")}),s.jsx("span",{className:"typography-meta text-muted-foreground",children:t("settings.remoteInstances.clientAuth.addDevice.fallback.relay")})]}):null,Xt==="relay"&&bt?.lanUrl?s.jsxs("label",{className:"flex w-fit cursor-pointer items-center gap-2 pt-1",children:[s.jsx(Li,{checked:Wt,onChange:kt,ariaLabel:t("settings.remoteInstances.clientAuth.addDevice.fallback.preferLocal")}),s.jsx("span",{className:"typography-meta text-muted-foreground",children:t("settings.remoteInstances.clientAuth.addDevice.fallback.preferLocal")})]}):null]}),ie?s.jsx("p",{className:"typography-meta text-[var(--status-error)]",children:ie}):null,s.jsxs("div",{className:"flex justify-end gap-2",children:[s.jsx(H,{type:"button",variant:"outline",size:"xs",className:"!font-normal",onClick:()=>rt(!1),disabled:It,children:t("settings.common.actions.cancel")}),s.jsx(H,{type:"submit",size:"xs",className:"!font-normal",disabled:It||!bt,children:t("settings.remoteInstances.clientAuth.addDevice.create")})]})]}):s.jsxs("div",{className:"space-y-3",children:[zt?s.jsx("div",{className:"flex justify-center",children:s.jsx("img",{src:zt,alt:t("settings.remoteInstances.clientAuth.qrAlt"),className:"w-full max-w-[420px] rounded-md bg-white p-4"})}):null,Be?s.jsxs("div",{className:"flex items-center gap-2 rounded-md border border-[var(--interactive-border)] p-2",children:[s.jsx("code",{className:"min-w-0 flex-1 truncate typography-code text-muted-foreground",children:Be}),s.jsxs(H,{type:"button",variant:"outline",size:"xs",className:"!font-normal shrink-0",onClick:ii,children:[s.jsx(_,{name:xe?"check":"file-copy",className:je("h-3.5 w-3.5",xe&&"text-[var(--status-success)]")}),t(xe?"settings.remoteInstances.clientAuth.actions.copied":"settings.common.actions.copyAll")]})]}):null,s.jsx("div",{className:"flex justify-end",children:s.jsx(H,{type:"button",size:"xs",className:"!font-normal",onClick:()=>rt(!1),children:t("settings.remoteInstances.clientAuth.addDevice.done")})})]})]})}),n?s.jsx(Oe,{title:t("settings.remoteInstances.sidebar.title"),description:t("settings.remoteInstances.sidebar.total",{count:i.length}),headerAction:s.jsxs(H,{type:"button",size:"xs",className:"!font-normal",onClick:()=>Bt(!0),children:[s.jsx(_,{name:"add",className:"h-3.5 w-3.5"}),t("settings.remoteInstances.sidebar.actions.addSshInstance")]}),contentClassName:"space-y-2.5",children:x?s.jsx("p",{className:"typography-meta text-muted-foreground",children:t("settings.remoteInstances.page.import.loading")}):i.length===0?s.jsx("p",{className:"typography-meta text-muted-foreground",children:t("settings.remoteInstances.page.import.noneFound")}):i.map(f=>{const ne=r[f.id],Te=f.nickname?.trim()||f.sshParsed?.destination||f.id,Xe=ne?.phase,Lt=Xe==="ready";return s.jsxs("div",{className:"flex items-center justify-between gap-3 py-1.5",children:[s.jsxs("div",{className:"min-w-0 space-y-0.5",children:[s.jsxs("div",{className:"flex min-w-0 items-center gap-2",children:[s.jsx("span",{className:`h-2 w-2 rounded-full ${Jr(Xe)}`}),s.jsx("p",{className:"typography-ui-label text-foreground truncate",children:Te})]}),s.jsxs("p",{className:"typography-micro text-muted-foreground truncate",children:[t(Wr(Xe)),ne?.localUrl?` · ${ne.localUrl}`:""]})]}),s.jsxs("div",{className:"flex shrink-0 items-center gap-1",children:[s.jsxs(H,{type:"button",variant:"ghost",size:"xs",className:"!font-normal",onClick:()=>{(Lt?u(f.id):C(f.id)).catch(es=>R.error(t(Lt?"settings.remoteInstances.sidebar.toast.disconnectFailed":"settings.remoteInstances.sidebar.toast.connectFailed"),{description:es instanceof Error?es.message:String(es)}))},children:[Lt?s.jsx(_,{name:"stop",className:"h-3.5 w-3.5"}):s.jsx(_,{name:"plug-2",className:"h-3.5 w-3.5"}),t(Lt?"settings.remoteInstances.sidebar.actions.disconnect":"settings.remoteInstances.sidebar.actions.connect")]}),s.jsxs(H,{type:"button",variant:"ghost",size:"xs",className:"!font-normal",onClick:()=>M(f.id),children:[s.jsx(_,{name:"pencil",className:"h-3.5 w-3.5"}),t("desktopHostSwitcher.actions.edit")]}),s.jsxs(H,{type:"button",variant:"ghost",size:"xs",className:"!font-normal",onClick:()=>{window.confirm(t("settings.remoteInstances.page.confirm.removeInstance"))&&h(f.id).catch(es=>R.error(t("settings.remoteInstances.page.toast.removeInstanceFailed"),{description:es instanceof Error?es.message:String(es)}))},children:[s.jsx(_,{name:"delete-bin",className:"h-3.5 w-3.5"}),t("settings.common.actions.delete")]})]})]},f.id)})}):null,n?s.jsx(Ut,{open:Ft,onOpenChange:Bt,children:s.jsxs(Vt,{className:"sm:max-w-lg",children:[s.jsxs(Ht,{children:[s.jsx(Gt,{children:t("settings.remoteInstances.sidebar.actions.addSshInstance")}),s.jsx(qt,{children:t("settings.remoteInstances.page.section.instanceDescription")})]}),s.jsxs("form",{className:"space-y-3",onSubmit:f=>{f.preventDefault(),ei()},children:[s.jsx(He,{className:"h-8",value:Ce,onChange:f=>st(f.target.value),placeholder:t("settings.remoteInstances.page.field.nicknamePlaceholder"),disabled:y}),s.jsx(He,{className:"h-8",value:hs,onChange:f=>Y(f.target.value),placeholder:t("settings.remoteInstances.page.field.sshCommandPlaceholder"),disabled:y,autoFocus:!0}),s.jsxs("div",{className:"flex justify-end gap-2",children:[s.jsx(H,{type:"button",variant:"outline",size:"xs",className:"!font-normal",onClick:()=>Bt(!1),disabled:y,children:t("settings.common.actions.cancel")}),s.jsx(H,{type:"submit",size:"xs",className:"!font-normal",disabled:y||!hs.trim(),children:t("settings.common.actions.create")})]})]})]})}):null,n?s.jsx(Oe,{title:t("settings.remoteInstances.page.import.sectionTitle"),children:c?s.jsx("p",{className:"typography-meta text-muted-foreground",children:t("settings.remoteInstances.page.import.loading")}):l.length===0?s.jsx("p",{className:"typography-meta text-muted-foreground",children:t("settings.remoteInstances.page.import.noneFound")}):s.jsx("div",{children:l.map(f=>s.jsxs("div",{className:"flex items-center justify-between gap-3 border-b border-[var(--surface-subtle)] py-3 last:border-b-0",children:[s.jsxs("div",{className:"min-w-0",children:[s.jsxs("div",{className:"typography-ui-label font-medium text-foreground truncate",children:[f.host,f.pattern?` ${t("settings.remoteInstances.page.import.patternSuffix")}`:""]}),s.jsx("div",{className:"typography-meta text-muted-foreground truncate",children:f.sshCommand})]}),s.jsx(H,{type:"button",variant:"outline",size:"xs",className:"!font-normal",onClick:()=>{Yn(f.host,f.pattern)},children:t("settings.common.actions.import")})]},`${f.source}:${f.host}`))})}):null,s.jsx(Ut,{open:!!Q,onOpenChange:f=>{f||Ys()},children:s.jsxs(Vt,{className:"sm:max-w-md",children:[s.jsxs(Ht,{children:[s.jsx(Gt,{children:t("settings.remoteInstances.page.patternDialog.title")}),s.jsx(qt,{children:Q?t("settings.remoteInstances.page.patternDialog.descriptionWithHost",{host:Q}):t("settings.remoteInstances.page.patternDialog.description")})]}),s.jsxs("form",{className:"space-y-3",onSubmit:f=>{f.preventDefault(),_n()},children:[s.jsx(He,{value:Z,onChange:f=>P(f.target.value),placeholder:t("settings.remoteInstances.page.patternDialog.destinationPlaceholder"),autoFocus:!0}),s.jsxs("div",{className:"flex items-center justify-end gap-2",children:[s.jsx(H,{type:"button",variant:"outline",size:"xs",className:"!font-normal",onClick:Ys,disabled:ee,children:t("settings.common.actions.cancel")}),s.jsx(H,{type:"submit",size:"xs",className:"!font-normal",disabled:ee,children:t("settings.remoteInstances.page.actions.create")})]})]})]})})]});const Un=g.remoteOpenchamber.mode==="managed",Da=g.nickname?.trim()||g.sshParsed?.destination||g.id;return s.jsx(Ut,{open:!!g,onOpenChange:f=>{f||M(null)},children:s.jsxs(Vt,{className:"sm:max-w-4xl max-h-[90vh] overflow-auto",children:[s.jsxs("div",{className:"mb-6 px-1",children:[s.jsx("h1",{className:`${Oi} truncate`,children:Da}),s.jsxs("div",{className:"mt-1 flex flex-wrap items-center gap-2 typography-meta text-muted-foreground",children:[s.jsx("span",{className:`h-2.5 w-2.5 rounded-full ${Jr(Ks)}`}),s.jsx("span",{children:t(Wr(Ks))}),Cs?.localUrl?s.jsx("span",{className:"font-mono text-foreground/80",children:Cs.localUrl}):null,Kn?s.jsx("span",{children:t("settings.remoteInstances.page.status.reconnectStale")}):null]})]}),s.jsxs(Oe,{title:t("settings.remoteInstances.page.section.actions"),info:t("settings.remoteInstances.page.section.actionsDescription"),divider:!1,contentClassName:"space-y-3",children:[s.jsxs("div",{className:"flex flex-wrap items-center gap-2",children:[s.jsxs(H,{type:"button",variant:cn?"outline":"default",size:"xs",className:"!font-normal",onClick:Aa,disabled:U||V,children:[cn?s.jsx(_,{name:"stop",className:"h-3.5 w-3.5"}):s.jsx(_,{name:"plug-2",className:"h-3.5 w-3.5"}),zn]}),s.jsxs(H,{type:"button",variant:"outline",size:"xs",className:"!font-normal",onClick:Ta,disabled:!pi,children:[s.jsx(_,{name:"refresh",className:`h-3.5 w-3.5 ${ln||Js&&!Kn?"animate-spin":""}`}),Ea]}),s.jsxs(H,{type:"button",variant:"outline",size:"xs",className:"!font-normal",onClick:()=>{ns()},children:[s.jsx(_,{name:"terminal-window",className:"h-3.5 w-3.5"}),t("settings.remoteInstances.page.actions.logs")]}),s.jsxs(H,{type:"button",variant:"outline",size:"xs",className:"!font-normal text-[var(--status-error)] border-[var(--status-error)]/30 hover:text-[var(--status-error)]",onClick:()=>{window.confirm(t("settings.remoteInstances.page.confirm.removeInstance"))&&h(g.id).then(()=>{M(null),R.success(t("settings.remoteInstances.page.toast.instanceRemoved"))}).catch(ne=>{R.error(t("settings.remoteInstances.page.toast.removeInstanceFailed"),{description:ne instanceof Error?ne.message:String(ne)})})},children:[s.jsx(_,{name:"delete-bin",className:"h-3.5 w-3.5"}),t("settings.remoteInstances.sidebar.actions.remove")]})]}),Cs?.localUrl?s.jsxs("div",{className:"flex flex-wrap items-center gap-2 typography-meta text-muted-foreground",children:[s.jsx("span",{children:t("settings.remoteInstances.page.status.currentLocalUrl")}),s.jsx("span",{className:"font-mono text-foreground/90",children:Cs.localUrl})]}):null]}),s.jsxs(Oe,{title:t("settings.remoteInstances.page.section.instance"),info:t("settings.remoteInstances.page.section.instanceDescription"),contentClassName:"space-y-3",children:[s.jsxs("div",{className:"flex flex-col gap-1.5 py-1.5 md:flex-row md:items-center md:gap-8",children:[s.jsx("span",{className:"typography-ui-label text-foreground w-56 shrink-0",children:t("settings.remoteInstances.page.field.sshCommand")}),s.jsx(He,{className:"h-7 md:max-w-xl",value:g.sshCommand,onChange:f=>ps(ne=>({...ne,sshCommand:f.target.value})),placeholder:t("settings.remoteInstances.page.field.sshCommandPlaceholder")})]}),s.jsxs("div",{className:"flex flex-col gap-1.5 py-1.5 md:flex-row md:items-center md:gap-8",children:[s.jsx("span",{className:"typography-ui-label text-foreground w-56 shrink-0",children:t("settings.remoteInstances.page.field.nickname")}),s.jsx(He,{className:"h-7 md:max-w-sm",value:g.nickname||"",onChange:f=>ps(ne=>({...ne,nickname:f.target.value})),placeholder:t("settings.remoteInstances.page.field.nicknamePlaceholder")})]}),s.jsxs("div",{className:"flex flex-col gap-1.5 py-1.5 md:flex-row md:items-center md:gap-8",children:[s.jsx("span",{className:"typography-ui-label text-foreground w-56 shrink-0",children:t("settings.remoteInstances.page.field.connectionTimeoutSeconds")}),s.jsx(ys,{containerClassName:"w-fit",min:5,max:240,step:1,className:"w-16 tabular-nums",value:g.connectionTimeoutSec,onValueChange:f=>{ps(ne=>({...ne,connectionTimeoutSec:Number.isFinite(f)?f:ne.connectionTimeoutSec}))}})]})]}),s.jsxs(Oe,{title:t("settings.remoteInstances.page.section.remoteServer"),info:t("settings.remoteInstances.page.section.remoteServerDescription"),contentClassName:"space-y-3",children:[s.jsxs("div",{className:"flex flex-col gap-1.5 py-1.5 md:flex-row md:items-center md:gap-8",children:[s.jsx("div",{className:"w-56 shrink-0",children:s.jsx(tn,{label:t("settings.remoteInstances.page.field.mode"),hint:t("settings.remoteInstances.page.field.modeHint")})}),s.jsxs(Dt,{value:g.remoteOpenchamber.mode,onValueChange:f=>ps(ne=>({...ne,remoteOpenchamber:{...ne.remoteOpenchamber,mode:f==="external"?"external":"managed"}})),children:[s.jsx(Mt,{size:Kt,className:"w-fit min-w-[140px]",children:s.jsx(_t,{placeholder:t("settings.remoteInstances.page.field.modePlaceholder")})}),s.jsxs(Rt,{children:[s.jsx(dt,{value:"managed",children:t("settings.remoteInstances.page.field.modeManaged")}),s.jsx(dt,{value:"external",children:t("settings.remoteInstances.page.field.modeExternal")})]})]})]}),s.jsxs("div",{className:"flex flex-col gap-1.5 py-1.5 md:flex-row md:items-center md:gap-8",children:[s.jsx("div",{className:"w-56 shrink-0",children:s.jsx(tn,{label:t("settings.remoteInstances.page.field.preferredRemotePort"),hint:t("settings.remoteInstances.page.field.preferredRemotePortHint")})}),s.jsx(ys,{containerClassName:"w-fit",min:1,max:65535,step:1,className:"w-20 tabular-nums",value:g.remoteOpenchamber.preferredPort,onValueChange:f=>{ps(ne=>({...ne,remoteOpenchamber:{...ne.remoteOpenchamber,preferredPort:Number.isFinite(f)&&f>0?f:void 0}}))},onClear:()=>{ps(f=>({...f,remoteOpenchamber:{...f.remoteOpenchamber,preferredPort:void 0}}))},emptyLabel:t("settings.remoteInstances.page.field.auto")})]}),Un?s.jsxs("div",{className:"flex flex-col gap-1.5 py-1.5 md:flex-row md:items-center md:gap-8",children:[s.jsx("div",{className:"w-56 shrink-0",children:s.jsx(tn,{label:t("settings.remoteInstances.page.field.installMethod"),hint:t("settings.remoteInstances.page.field.installMethodHint")})}),s.jsxs(Dt,{value:g.remoteOpenchamber.installMethod,onValueChange:f=>ps(ne=>({...ne,remoteOpenchamber:{...ne.remoteOpenchamber,installMethod:f==="npm"||f==="download_release"||f==="upload_bundle"?f:"bun"}})),children:[s.jsx(Mt,{size:Kt,className:"w-fit min-w-[140px]",children:s.jsx(_t,{placeholder:t("settings.remoteInstances.page.field.selectInstallMethodPlaceholder")})}),s.jsxs(Rt,{children:[s.jsx(dt,{value:"bun",children:"bun"}),s.jsx(dt,{value:"npm",children:"npm"}),s.jsx(dt,{value:"download_release",children:t("settings.remoteInstances.page.field.installMethodDownloadRelease")}),s.jsx(dt,{value:"upload_bundle",children:t("settings.remoteInstances.page.field.installMethodUploadBundle")})]})]})]}):null,Un?s.jsxs("div",{className:"flex flex-col gap-1.5 py-1.5 md:flex-row md:items-center md:gap-8",children:[s.jsx("div",{className:"w-56 shrink-0",children:s.jsx(tn,{label:t("settings.remoteInstances.page.field.keepServerRunning"),hint:t("settings.remoteInstances.page.field.keepServerRunningHint")})}),s.jsx("div",{className:"flex w-full items-center gap-2 md:max-w-xs",children:s.jsx(lr,{checked:g.remoteOpenchamber.keepRunning,onCheckedChange:f=>ps(ne=>({...ne,remoteOpenchamber:{...ne.remoteOpenchamber,keepRunning:f}}))})})]}):null]}),s.jsxs(Oe,{title:t("settings.remoteInstances.page.section.mainTunnel"),info:t("settings.remoteInstances.page.section.mainTunnelDescription"),contentClassName:"space-y-3",children:[s.jsxs("div",{className:"flex flex-col gap-1.5 py-1.5 md:flex-row md:items-center md:gap-8",children:[s.jsx("div",{className:"w-56 shrink-0",children:s.jsx(tn,{label:t("settings.remoteInstances.page.field.bindHost"),hint:t("settings.remoteInstances.page.field.bindHostHint")})}),s.jsxs(Dt,{value:g.localForward.bindHost,onValueChange:f=>{f==="0.0.0.0"&&!window.confirm(t("settings.remoteInstances.page.confirm.bindAllInterfaces"))||ps(ne=>({...ne,localForward:{...ne.localForward,bindHost:f==="localhost"||f==="0.0.0.0"?f:"127.0.0.1"}}))},children:[s.jsx(Mt,{size:Kt,className:"w-fit min-w-[140px]",children:s.jsx(_t,{placeholder:t("settings.remoteInstances.page.field.selectBindHostPlaceholder")})}),s.jsxs(Rt,{children:[s.jsx(dt,{value:"127.0.0.1",children:"127.0.0.1"}),s.jsx(dt,{value:"localhost",children:"localhost"}),s.jsx(dt,{value:"0.0.0.0",children:"0.0.0.0"})]})]})]}),s.jsxs("div",{className:"flex flex-col gap-1.5 py-1.5 md:flex-row md:items-center md:gap-8",children:[s.jsx("div",{className:"w-56 shrink-0",children:s.jsx(tn,{label:t("settings.remoteInstances.page.field.preferredLocalPort"),hint:t("settings.remoteInstances.page.field.preferredLocalPortHint")})}),s.jsxs("div",{className:"flex w-full items-center gap-2 md:max-w-sm",children:[s.jsx(ys,{containerClassName:"w-fit",min:1,max:65535,step:1,className:"w-20 tabular-nums",value:g.localForward.preferredLocalPort,onValueChange:f=>{ps(ne=>({...ne,localForward:{...ne.localForward,preferredLocalPort:Number.isFinite(f)&&f>0?f:void 0}}))},onClear:()=>{ps(f=>({...f,localForward:{...f.localForward,preferredLocalPort:void 0}}))},emptyLabel:t("settings.remoteInstances.page.field.auto")}),s.jsx(H,{type:"button",variant:"outline",size:"xs",className:"!font-normal h-7 w-7 px-0",title:t("settings.remoteInstances.page.actions.pickRandomPort"),onClick:()=>ps(f=>({...f,localForward:{...f.localForward,preferredLocalPort:$i()}})),children:s.jsx(_,{name:"shuffle",className:"h-3.5 w-3.5"})})]})]})]}),s.jsxs(Oe,{title:t("settings.remoteInstances.page.section.authentication"),info:t("settings.remoteInstances.page.section.authenticationDescription"),contentClassName:"space-y-3",children:[s.jsxs("div",{className:"flex flex-col gap-1.5 py-1.5 md:flex-row md:items-center md:gap-8",children:[s.jsx("span",{className:"typography-ui-label text-foreground w-56 shrink-0",children:t("settings.remoteInstances.page.field.sshPasswordOptional")}),s.jsx(He,{className:"h-7 md:max-w-sm",type:"password",value:g.auth.sshPassword?.value||"",onChange:f=>ps(ne=>({...ne,auth:{...ne.auth,sshPassword:{enabled:f.target.value.trim().length>0,value:f.target.value,store:ne.auth.sshPassword?.store||"never"}}})),placeholder:t("settings.remoteInstances.page.field.sshPasswordPlaceholder")})]}),s.jsxs("div",{className:"flex flex-col gap-1.5 py-1.5 md:flex-row md:items-center md:gap-8",children:[s.jsx("span",{className:"typography-ui-label text-foreground w-56 shrink-0",children:t("settings.remoteInstances.page.field.uiPasswordOptional")}),s.jsx(He,{className:"h-7 md:max-w-sm",type:"password",value:g.auth.openchamberPassword?.value||"",onChange:f=>ps(ne=>({...ne,auth:{...ne.auth,openchamberPassword:{enabled:f.target.value.trim().length>0,value:f.target.value,store:ne.auth.openchamberPassword?.store||"never"}}})),placeholder:t("settings.remoteInstances.page.field.uiPasswordPlaceholder")})]})]}),s.jsxs(Oe,{title:t("settings.remoteInstances.page.section.portForwards"),info:t("settings.remoteInstances.page.section.portForwardsDescription"),contentClassName:"space-y-2",children:[g.portForwards.length===0?s.jsx("p",{className:"typography-micro text-muted-foreground/80",children:t("settings.remoteInstances.page.empty.noExtraForwards")}):null,g.portForwards.map((f,ne)=>{const Te=Tt=>{ps(Zt=>({...Zt,portForwards:Zt.portForwards.map((kn,Ot)=>Ot===ne?Tt(kn):kn)}))},Xe=f.type==="remote"?"Local target":"Local listen",Lt=f.type==="remote"?"Local host and port on your machine that receives traffic from remote -R listener.":"Local host and port where this forward listens on your machine.",js=f.type==="remote"?"Remote listen":"Remote target",es=f.type==="remote"?"Remote host and port where SSH creates the -R listener.":"Remote host and port that receives traffic from local -L listener.",Es=Qr(f.localHost||"localhost",f.localPort),Xs=Qr(f.remoteHost||"localhost",f.remotePort),Ms=f.type==="local"&&typeof f.localPort=="number"&&f.localPort>0,Zn=Ms?`http://${Wm(f.localHost)}:${f.localPort}`:"",Nn=!!D[f.id],Xn=f.type==="local"?t("settings.remoteInstances.page.forwardType.local"):f.type==="remote"?t("settings.remoteInstances.page.forwardType.remote"):t("settings.remoteInstances.page.forwardType.dynamic");return s.jsxs(ba,{open:Nn,onOpenChange:Tt=>{O(Zt=>({...Zt,[f.id]:Tt}))},className:`${ne>0?"border-t border-[var(--surface-subtle)]":""} py-2`,children:[s.jsxs("div",{className:"flex items-center justify-between gap-2",children:[s.jsx("div",{className:"min-w-0 flex items-center gap-2",children:s.jsxs(va,{className:"flex items-center gap-2 group",children:[s.jsx(_,{name:"arrow-down-s",className:`h-4 w-4 text-muted-foreground transition-transform ${Nn?"rotate-180":""}`}),s.jsx("span",{className:"typography-ui-label text-foreground truncate",children:Bm(f)}),s.jsx("span",{className:"typography-micro text-muted-foreground/70 shrink-0",children:Xn})]})}),s.jsxs("div",{className:"flex items-center gap-2",children:[s.jsx(lr,{checked:f.enabled,onCheckedChange:Tt=>Te(Zt=>({...Zt,enabled:Tt})),"aria-label":t("settings.remoteInstances.page.actions.enableForwardAria")}),s.jsx(H,{type:"button",variant:"ghost",size:"xs",className:"!font-normal h-6 w-6 px-0 text-[var(--status-error)] hover:text-[var(--status-error)]",onClick:()=>ps(Tt=>({...Tt,portForwards:Tt.portForwards.filter(Zt=>Zt.id!==f.id)})),children:s.jsx(_,{name:"delete-bin",className:"h-3.5 w-3.5"})})]})]}),s.jsx(ya,{className:"pt-2",children:s.jsxs("div",{className:"space-y-0 pb-2",children:[s.jsxs("div",{className:"flex flex-col gap-1.5 py-1.5 md:flex-row md:items-center md:gap-8",children:[s.jsx("div",{className:"w-56 shrink-0",children:s.jsx(tn,{label:t("settings.remoteInstances.page.field.forwardType"),hint:s.jsxs("div",{className:"space-y-1",children:[s.jsx("p",{children:t("settings.remoteInstances.page.field.forwardTypeHint")}),s.jsx("p",{children:t(qm(f.type))})]})})}),s.jsxs(Dt,{value:f.type,onValueChange:Tt=>Te(Zt=>({...Zt,type:Tt==="dynamic"||Tt==="remote"?Tt:"local"})),children:[s.jsx(Mt,{size:Kt,className:"w-fit min-w-[140px]",children:s.jsx(_t,{placeholder:t("settings.remoteInstances.page.field.typePlaceholder")})}),s.jsxs(Rt,{children:[s.jsx(dt,{value:"local",children:t("settings.remoteInstances.page.forwardType.local")}),s.jsx(dt,{value:"remote",children:t("settings.remoteInstances.page.forwardType.remote")}),s.jsx(dt,{value:"dynamic",children:t("settings.remoteInstances.page.forwardType.dynamic")})]})]})]}),s.jsxs("div",{className:"flex flex-col gap-1.5 py-1.5 md:flex-row md:items-center md:gap-8",children:[s.jsx("div",{className:"w-56 shrink-0",children:s.jsx(tn,{label:Xe,hint:Lt})}),s.jsxs("div",{className:"flex items-center gap-1.5",children:[s.jsx(He,{className:"h-7 w-32",value:f.localHost||"127.0.0.1",onChange:Tt=>Te(Zt=>({...Zt,localHost:Tt.target.value})),placeholder:t("settings.remoteInstances.page.field.localHostPlaceholder")}),s.jsx("span",{className:"text-muted-foreground",children:":"}),s.jsx(ys,{containerClassName:"w-fit",min:1,max:65535,step:1,className:"w-16 tabular-nums",value:f.localPort,onValueChange:Tt=>{Te(Zt=>({...Zt,localPort:Number.isFinite(Tt)&&Tt>0?Tt:void 0}))},onClear:()=>{Te(Tt=>({...Tt,localPort:void 0}))},emptyLabel:t("settings.remoteInstances.page.field.auto")})]})]}),f.type!=="dynamic"?s.jsxs("div",{className:"flex flex-col gap-1.5 py-1.5 md:flex-row md:items-center md:gap-8",children:[s.jsx("div",{className:"w-56 shrink-0",children:s.jsx(tn,{label:js,hint:es})}),s.jsxs("div",{className:"flex items-center gap-1.5",children:[s.jsx(He,{className:"h-7 w-32",value:f.remoteHost||"",onChange:Tt=>Te(Zt=>({...Zt,remoteHost:Tt.target.value})),placeholder:t("settings.remoteInstances.page.field.remoteHostPlaceholder")}),s.jsx("span",{className:"text-muted-foreground",children:":"}),s.jsx(ys,{containerClassName:"w-fit",min:1,max:65535,step:1,className:"w-16 tabular-nums",value:f.remotePort,onValueChange:Tt=>{Te(Zt=>({...Zt,remotePort:Number.isFinite(Tt)&&Tt>0?Tt:void 0}))},onClear:()=>{Te(Tt=>({...Tt,remotePort:void 0}))},emptyLabel:t("settings.remoteInstances.page.field.auto")})]})]}):null,s.jsxs("div",{className:"mt-2 flex flex-wrap items-center justify-between gap-2 rounded-md bg-[var(--surface-subtle)] p-2",children:[s.jsx("div",{className:"flex flex-wrap items-center gap-1 typography-micro text-muted-foreground/80",children:f.type==="dynamic"?s.jsxs(s.Fragment,{children:[s.jsx(_,{name:"computer",className:"h-3.5 w-3.5"}),s.jsx("span",{className:"font-mono text-foreground",children:Es}),s.jsx("span",{children:t("settings.remoteInstances.page.preview.localSocks5")})]}):f.type==="remote"?s.jsxs(s.Fragment,{children:[s.jsx(_,{name:"server",className:"h-3.5 w-3.5"}),s.jsx("span",{className:"font-mono text-foreground",children:Xs}),s.jsx("span",{children:t("settings.remoteInstances.page.preview.remote")}),s.jsx(_,{name:"arrow-right",className:"h-3.5 w-3.5"}),s.jsx(_,{name:"computer",className:"h-3.5 w-3.5"}),s.jsx("span",{className:"font-mono text-foreground",children:Es}),s.jsx("span",{children:t("settings.remoteInstances.page.preview.local")})]}):s.jsxs(s.Fragment,{children:[s.jsx(_,{name:"computer",className:"h-3.5 w-3.5"}),s.jsx("span",{className:"font-mono text-foreground",children:Es}),s.jsx("span",{children:t("settings.remoteInstances.page.preview.local")}),s.jsx(_,{name:"arrow-right",className:"h-3.5 w-3.5"}),s.jsx(_,{name:"server",className:"h-3.5 w-3.5"}),s.jsx("span",{className:"font-mono text-foreground",children:Xs}),s.jsx("span",{children:t("settings.remoteInstances.page.preview.remote")})]})}),Ms?s.jsxs(H,{type:"button",variant:"outline",size:"xs",className:"!font-normal",onClick:()=>{En(Zn).then(Tt=>{Tt||R.error(t("settings.remoteInstances.page.toast.openLocalEndpointFailed"))})},children:[s.jsx(_,{name:"external-link",className:"h-3.5 w-3.5"}),t("settings.remoteInstances.page.actions.openLocal")]}):null]})]})})]},f.id)}),s.jsxs(H,{type:"button",variant:"outline",size:"xs",className:"!font-normal mt-1",onClick:()=>{const f=Hm();ps(ne=>({...ne,portForwards:[...ne.portForwards,f]})),O(ne=>({...ne,[f.id]:!0}))},children:[s.jsx(_,{name:"add",className:"h-3.5 w-3.5"}),t("settings.remoteInstances.page.actions.addForward")]})]}),s.jsx("div",{className:"mt-8 border-t border-[var(--interactive-border)] pt-3",children:s.jsxs("div",{className:"flex items-center gap-2",children:[s.jsx(H,{type:"button",size:"xs",className:"!font-normal",onClick:()=>{di()},disabled:!ci||y,children:t("settings.common.actions.saveChanges")}),Cs?.localUrl?s.jsxs(s.Fragment,{children:[s.jsxs(H,{type:"button",variant:"outline",size:"xs",className:"!font-normal",onClick:()=>{ga(Cs.localUrl||"").then(f=>{f.ok&&R.success(t("settings.remoteInstances.page.toast.localUrlCopied"))})},children:[s.jsx(_,{name:"file-copy",className:"h-3.5 w-3.5"}),t("settings.remoteInstances.page.actions.copyLocalUrl")]}),s.jsxs(H,{type:"button",variant:"outline",size:"xs",className:"!font-normal",onClick:()=>{Pa()},children:[s.jsx(_,{name:"external-link",className:"h-3.5 w-3.5"}),t("settings.remoteInstances.page.actions.open")]})]}):null,m?s.jsx("div",{className:"ml-auto typography-meta text-[var(--status-error)]",children:m}):null]})}),s.jsx(Ut,{open:F,onOpenChange:S,children:s.jsxs(Vt,{className:"sm:max-w-2xl",children:[s.jsxs(Ht,{children:[s.jsx(Gt,{children:t("settings.remoteInstances.page.logsDialog.title")}),s.jsx(qt,{children:g?.nickname?.trim()||g?.sshParsed?.destination||g?.id||t("settings.remoteInstances.page.logsDialog.selectedInstanceFallback")})]}),s.jsxs("div",{className:"flex items-center justify-end gap-2",children:[s.jsxs(H,{type:"button",variant:"outline",size:"xs",className:"!font-normal",onClick:Ca,disabled:T||!wn.trim(),children:[s.jsx(_,{name:"file-copy",className:"h-3.5 w-3.5"}),t("settings.common.actions.copyAll")]}),s.jsxs(H,{type:"button",variant:"outline",size:"xs",className:"!font-normal",onClick:()=>{Ia()},disabled:T,children:[s.jsx(_,{name:"delete-bin",className:"h-3.5 w-3.5"}),t("settings.common.actions.clear")]})]}),T?s.jsx("div",{className:"typography-meta text-muted-foreground",children:t("settings.remoteInstances.page.logsDialog.loading")}):K?s.jsx("div",{className:"typography-meta text-[var(--status-error)]",children:K}):s.jsx("pre",{className:"max-h-[55vh] overflow-auto rounded-md border border-[var(--interactive-border)] bg-[var(--surface-elevated)] p-3 typography-micro text-foreground whitespace-pre-wrap break-words",children:w.length>0?w.join(`
28
+ `):t("settings.remoteInstances.page.logsDialog.empty")})]})}),s.jsx(Ut,{open:!!Q,onOpenChange:f=>{f||Ys()},children:s.jsxs(Vt,{className:"sm:max-w-md",children:[s.jsxs(Ht,{children:[s.jsx(Gt,{children:t("settings.remoteInstances.page.patternDialog.title")}),s.jsx(qt,{children:Q?t("settings.remoteInstances.page.patternDialog.descriptionWithHost",{host:Q}):t("settings.remoteInstances.page.patternDialog.description")})]}),s.jsxs("form",{className:"space-y-3",onSubmit:f=>{f.preventDefault(),_n()},children:[s.jsx(He,{value:Z,onChange:f=>P(f.target.value),placeholder:t("settings.remoteInstances.page.patternDialog.destinationPlaceholder"),autoFocus:!0}),s.jsxs("div",{className:"flex items-center justify-end gap-2",children:[s.jsx(H,{type:"button",variant:"outline",size:"xs",className:"!font-normal",onClick:Ys,disabled:ee,children:t("settings.common.actions.cancel")}),s.jsx(H,{type:"submit",size:"xs",className:"!font-normal",disabled:ee,children:t("settings.common.actions.create")})]})]})]})})]})})},tu="__add_provider__",su=()=>{const t=on.getDirectory();return typeof t=="string"&&t.trim().length>0?t.trim():null},nu=({onItemSelect:t})=>{const{t:e}=ot(),a=nt(p=>p.providers),n=nt(p=>p.selectedProviderId),i=nt(p=>p.setSelectedProvider),r=Fs(p=>p.activeProjectId),[l,x]=o.useState({}),c=o.useMemo(()=>su(),[r]);o.useEffect(()=>{if(a.length===0){x({});return}let p=!1;return(async()=>{const k=a.map(async N=>{try{const h=c?`?directory=${encodeURIComponent(c)}`:"",C=await ct(`/api/provider/${encodeURIComponent(N.id)}/source${h}`,{method:"GET",headers:{Accept:"application/json"}});if(!C.ok)return;const u=await C.json().catch(()=>null),E=u?.sources??u?.data?.sources;if(!E||p)return;x(q=>({...q,[N.id]:E}))}catch{}});await Promise.all(k)})(),()=>{p=!0}},[c,a]);const y="bg-background",m=o.useMemo(()=>a.filter(p=>!!l[p.id]?.project?.exists),[a,l]),b=o.useMemo(()=>a.filter(p=>!l[p.id]?.project?.exists),[a,l]);return s.jsxs("div",{className:je("flex h-full flex-col",y),children:[s.jsxs("div",{className:"border-b px-3 pt-4 pb-3",children:[s.jsx("h2",{className:`${qs} mb-3`,children:e("settings.providers.sidebar.title")}),s.jsx(ka,{className:"mb-3"}),s.jsxs("div",{className:"flex items-center justify-between gap-2",children:[s.jsx("span",{className:"typography-meta text-muted-foreground",children:e("settings.providers.sidebar.total",{count:a.length})}),s.jsx(H,{size:"sm",variant:"ghost",className:"h-7 w-7 px-0 -my-1 text-muted-foreground",onClick:()=>{i(tu),t?.()},"aria-label":e("settings.providers.sidebar.actions.connectProviderAria"),title:e("settings.providers.sidebar.actions.connectProviderTitle"),children:s.jsx(_,{name:"add",className:"h-3.5 w-3.5"})})]})]}),s.jsx(Ds,{outerClassName:"flex-1 min-h-0",className:"space-y-1 px-3 py-2 overflow-x-hidden",children:a.length===0?s.jsxs("div",{className:"py-12 px-4 text-center text-muted-foreground",children:[s.jsx(_,{name:"stack",className:"mx-auto mb-3 h-10 w-10 opacity-50"}),s.jsx("p",{className:"typography-ui-label font-medium",children:e("settings.providers.sidebar.empty.title")}),s.jsx("p",{className:"typography-meta mt-1 opacity-75",children:e("settings.providers.sidebar.empty.description")})]}):s.jsxs(s.Fragment,{children:[b.length>0&&s.jsxs(s.Fragment,{children:[s.jsx("div",{className:"px-2 pb-1.5 pt-2 text-xs font-semibold uppercase tracking-wide text-muted-foreground",children:e("settings.providers.sidebar.section.userProviders")}),b.map(p=>s.jsx(Zr,{provider:p,selectedProviderId:n,onSelect:()=>{i(p.id),t?.()}},p.id))]}),m.length>0&&s.jsxs(s.Fragment,{children:[s.jsx("div",{className:je("px-2 pb-1.5 text-xs font-semibold uppercase tracking-wide text-muted-foreground",b.length>0?"pt-3":"pt-2"),children:e("settings.providers.sidebar.section.projectProviders")}),m.map(p=>s.jsx(Zr,{provider:p,selectedProviderId:n,onSelect:()=>{i(p.id),t?.()}},p.id))]})]})})]})},Zr=t=>{const e=ht.c(17),{provider:a,selectedProviderId:n,onSelect:i}=t,r=Array.isArray(a.models)?a.models.length:0,l=a.id===n,x=a.id,c=l?"bg-interactive-selection":"hover:bg-interactive-hover";let y;e[0]!==c?(y=je("group relative flex items-center rounded-md px-1.5 py-1 transition-all duration-200",c),e[0]=c,e[1]=y):y=e[1];let m;e[2]!==a.id?(m=s.jsx(Pn,{providerId:a.id,className:"h-4 w-4 flex-shrink-0"}),e[2]=a.id,e[3]=m):m=e[3];const b=a.name||a.id;let p;e[4]!==b?(p=s.jsx("span",{className:"typography-ui-label font-normal truncate flex-1 min-w-0 text-foreground",children:b}),e[4]=b,e[5]=p):p=e[5];let L;e[6]!==r?(L=s.jsx("span",{className:"typography-micro text-muted-foreground/60 flex-shrink-0",children:r}),e[6]=r,e[7]=L):L=e[7];let k;e[8]!==i||e[9]!==m||e[10]!==p||e[11]!==L?(k=s.jsxs("button",{type:"button",onClick:i,className:"flex min-w-0 flex-1 items-center gap-2 rounded-sm text-left focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-primary/50",tabIndex:0,children:[m,p,L]}),e[8]=i,e[9]=m,e[10]=p,e[11]=L,e[12]=k):k=e[12];let N;return e[13]!==a.id||e[14]!==y||e[15]!==k?(N=s.jsx("div",{className:y,children:k},x),e[13]=a.id,e[14]=y,e[15]=k,e[16]=N):N=e[16],N},au=t=>t,Xr=t=>typeof t=="object"&&t!==null,il=t=>{const e=typeof t.type=="string"?t.type:"",a=`${t.name??""} ${t.label??""}`.toLowerCase(),n=`${e} ${a}`.toLowerCase();return n.includes("oauth")?"oauth":n.includes("api")?"api":e.toLowerCase()},iu=t=>{if(!Xr(t))return{};const e={};for(const[a,n]of Object.entries(t))Array.isArray(n)&&(e[a]=n.filter(i=>Xr(i)));return e},eo=t=>t.length===0?!0:t.some(e=>il(e)==="api"),to=t=>t.map((e,a)=>({method:e,methodIndex:a})).filter(({method:e})=>il(e)==="oauth"),rl="@ai-sdk/openai-compatible",Cn="__custom_provider__",ru=/^[a-z0-9][a-z0-9-_]*$/,ol=/^https?:\/\//,ou=/^\{env:([^}]+)\}$/;let lu=0;const Ja=()=>`row-${lu++}`,er=()=>({row:Ja(),id:"",name:""}),tr=()=>({row:Ja(),key:"",value:""}),cu=()=>({providerID:"",name:"",baseURL:"",apiKey:"",models:[er()],headers:[tr()]});function du(t){const e=t.trim();if(!e)return{};const n=e.match(ou)?.[1]?.trim();return n?{env:n}:{key:e}}function pu(t){const e=t.options&&typeof t.options=="object"?t.options:null,a=typeof e?.baseURL=="string"?e.baseURL.trim():"";return a&&ol.test(a)?!0:(Array.isArray(t.models)?t.models:t.models&&typeof t.models=="object"?Object.values(t.models):[]).some(i=>{if(!i||typeof i!="object")return!1;const r="api"in i&&i.api&&typeof i.api=="object"?i.api:null;return typeof r?.npm=="string"&&r.npm===rl})}function mu(t,e){return e?!!(e.user?.exists||e.project?.exists||e.custom?.exists)&&pu(t):!1}function so(t){return t?.custom?.exists?"custom":t?.project?.exists?"project":"user"}function uu(t){const e=t.options&&typeof t.options=="object"?t.options:{},a=typeof e.baseURL=="string"?e.baseURL:"",n=e.headers&&typeof e.headers=="object"&&!Array.isArray(e.headers)?e.headers:{},i=Object.entries(n).filter(c=>typeof c[0]=="string"&&typeof c[1]=="string").map(([c,y])=>({row:Ja(),key:c,value:y})),r=Array.isArray(t.models)?t.models:t.models&&typeof t.models=="object"?Object.entries(t.models).map(([c,y])=>({id:c,name:y&&typeof y=="object"&&"name"in y&&typeof y.name=="string"?y.name:c})):[],l=r.length>0?r.map(c=>({row:Ja(),id:typeof c?.id=="string"?c.id:"",name:typeof c?.name=="string"?c.name:typeof c?.id=="string"?c.id:""})):[er()],x=Array.isArray(t.env)?t.env.find(c=>typeof c=="string"&&c.trim().length>0)?.trim():void 0;return{providerID:t.id,name:typeof t.name=="string"&&t.name.trim()?t.name:t.id,baseURL:a,apiKey:x?`{env:${x}}`:"",models:l,headers:i.length>0?i:[tr()]}}function gu(t){const e=t.form.providerID.trim(),a=t.form.name.trim(),n=t.form.baseURL.trim(),{env:i,key:r}=du(t.form.apiKey),l=t.disabledProviders??[],x=t.editingProviderID?.trim(),c=e?ru.test(e)?void 0:t.t("settings.providers.page.custom.error.providerID.format"):t.t("settings.providers.page.custom.error.providerID.required"),y=a?void 0:t.t("settings.providers.page.custom.error.name.required"),m=n?ol.test(n)?void 0:t.t("settings.providers.page.custom.error.baseURL.format"):t.t("settings.providers.page.custom.error.baseURL.required"),p=!!(i||r||x&&t.allowExistingAuth&&x===e)?void 0:t.t("settings.providers.page.custom.error.apiKey.required"),L=l.includes(e),N=c||!!(x&&x===e)?void 0:t.existingProviderIDs.has(e)&&!L?t.t("settings.providers.page.custom.error.providerID.exists"):void 0,h=new Set,C=t.form.models.map(S=>{const T=S.id.trim(),v=T?h.has(T)?t.t("settings.providers.page.custom.error.duplicate"):void h.add(T):t.t("settings.providers.page.custom.error.required"),K=S.name.trim()?void 0:t.t("settings.providers.page.custom.error.required");return{id:v,name:K}}),u=C.every(S=>!S.id&&!S.name),E=Object.fromEntries(t.form.models.map(S=>[S.id.trim(),{name:S.name.trim()}])),q=new Set,M=t.form.headers.map(S=>{const T=S.key.trim(),v=S.value.trim();if(!T&&!v)return{};const K=T?q.has(T.toLowerCase())?t.t("settings.providers.page.custom.error.duplicate"):void q.add(T.toLowerCase()):t.t("settings.providers.page.custom.error.required"),$=v?void 0:t.t("settings.providers.page.custom.error.required");return{key:K,value:$}}),I=M.every(S=>!S.key&&!S.value),g=Object.fromEntries(t.form.headers.map(S=>({key:S.key.trim(),value:S.value.trim()})).filter(S=>S.key&&S.value).map(S=>[S.key,S.value])),j={providerID:c??N,name:y,baseURL:m,apiKey:p};return!c&&!N&&!y&&!m&&!p&&u&&I?{err:j,models:C,headers:M,result:{providerID:e,name:a,apiKey:r,config:{npm:rl,name:a,...i?{env:[i]}:{},options:{baseURL:n,...Object.keys(g).length>0?{headers:g}:{}},models:E}}}:{err:j,models:C,headers:M}}function hu(t){return t.apiKey?{providerID:t.providerID,auth:{type:"api",key:t.apiKey}}:null}function fu(t,e){return{providerID:t.providerID,config:t.config,scope:e?.scope??"user"}}const no=t=>{const e=ht.c(198),{existingProviderIDs:a,disabledProviders:n,busy:i,mode:r,initialValues:l,allowExistingAuth:x,authFailureHint:c,onSubmit:y,onCancel:m,onDisconnect:b}=t;let p;e[0]!==n?(p=n===void 0?[]:n,e[0]=n,e[1]=p):p=e[1];const L=p,k=i===void 0?!1:i,N=r===void 0?"create":r,h=x===void 0?!1:x,C=c===void 0?null:c,{t:u}=ot(),E=N==="edit";let q;e[2]!==l?(q=()=>l??cu(),e[2]=l,e[3]=q):q=e[3];const[M,I]=o.useState(q);let g;e[4]===Symbol.for("react.memo_cache_sentinel")?(g={},e[4]=g):g=e[4];const[j,F]=o.useState(g);let S;e[5]===Symbol.for("react.memo_cache_sentinel")?(S=[],e[5]=S):S=e[5];const[T,v]=o.useState(S);let K;e[6]===Symbol.for("react.memo_cache_sentinel")?(K=[],e[6]=K):K=e[6];const[$,w]=o.useState(K),G=o.useRef(null);let Q,X;e[7]!==l||e[8]!==E?(Q=()=>{l&&(E&&G.current===l.providerID||(G.current=E?l.providerID:null,I(l),F({}),v([]),w([])))},X=[l,E],e[7]=l,e[8]=E,e[9]=Q,e[10]=X):(Q=e[9],X=e[10]),o.useEffect(Q,X);let Z;e[11]===Symbol.for("react.memo_cache_sentinel")?(Z=(kt,bt)=>{I(Pt=>({...Pt,[kt]:bt})),F(Pt=>({...Pt,[kt]:void 0}))},e[11]=Z):Z=e[11];const P=Z;let ee;e[12]===Symbol.for("react.memo_cache_sentinel")?(ee=(kt,bt,Pt)=>{I(St=>({...St,models:St.models.map((Ft,Bt)=>Bt===kt?{...Ft,[bt]:Pt}:Ft)})),v(St=>{const Ft=[...St];return Ft[kt]={...Ft[kt]??{},[bt]:void 0},Ft})},e[12]=ee):ee=e[12];const se=ee;let D;e[13]===Symbol.for("react.memo_cache_sentinel")?(D=(kt,bt,Pt)=>{I(St=>({...St,headers:St.headers.map((Ft,Bt)=>Bt===kt?{...Ft,[bt]:Pt}:Ft)})),w(St=>{const Ft=[...St];return Ft[kt]={...Ft[kt]??{},[bt]:void 0},Ft})},e[13]=D):D=e[13];const O=D;let U;e[14]!==h||e[15]!==k||e[16]!==L||e[17]!==a||e[18]!==M||e[19]!==E||e[20]!==y||e[21]!==u?(U=async kt=>{if(kt.preventDefault(),k)return;const bt=gu({form:M,t:((Pt,St)=>u(Pt,St)),existingProviderIDs:a,disabledProviders:L,editingProviderID:E?M.providerID:void 0,allowExistingAuth:E&&h});F(bt.err),v(bt.models),w(bt.headers),bt.result&&await y(bt.result)},e[14]=h,e[15]=k,e[16]=L,e[17]=a,e[18]=M,e[19]=E,e[20]=y,e[21]=u,e[22]=U):U=e[22];const A=U;let V;e[23]!==E||e[24]!==u?(V=u(E?"settings.providers.page.custom.editTitle":"settings.providers.page.custom.title"),e[23]=E,e[24]=u,e[25]=V):V=e[25];let W;e[26]!==u?(W=u("settings.providers.page.custom.description"),e[26]=u,e[27]=W):W=e[27];let te;e[28]!==W?(te=s.jsx("p",{className:In,children:W}),e[28]=W,e[29]=te):te=e[29];let ae;e[30]!==C?(ae=C?s.jsx("p",{className:"typography-meta text-[var(--status-warning)]",role:"status",children:C}):null,e[30]=C,e[31]=ae):ae=e[31];let le;e[32]!==u?(le=u("settings.providers.page.custom.field.providerID.label"),e[32]=u,e[33]=le):le=e[33];let be;e[34]!==u?(be=u("settings.providers.page.custom.field.providerID.info"),e[34]=u,e[35]=be):be=e[35];const ke=M.providerID;let ce;e[36]===Symbol.for("react.memo_cache_sentinel")?(ce=kt=>P("providerID",kt.target.value),e[36]=ce):ce=e[36];let ge;e[37]!==u?(ge=u("settings.providers.page.custom.field.providerID.placeholder"),e[37]=u,e[38]=ge):ge=e[38];const Ee=!E,Se=E||k,Ne=!!j.providerID;let fe;e[39]!==u?(fe=u("settings.providers.page.custom.field.providerID.label"),e[39]=u,e[40]=fe):fe=e[40];let Ke;e[41]!==M.providerID||e[42]!==ge||e[43]!==Ee||e[44]!==Se||e[45]!==Ne||e[46]!==fe?(Ke=s.jsx(He,{value:ke,onChange:ce,placeholder:ge,className:"h-8 rounded-md px-3 font-mono text-xs",autoFocus:Ee,disabled:Se,"aria-invalid":Ne,"aria-label":fe}),e[41]=M.providerID,e[42]=ge,e[43]=Ee,e[44]=Se,e[45]=Ne,e[46]=fe,e[47]=Ke):Ke=e[47];let De;e[48]!==j.providerID?(De=j.providerID?s.jsx("p",{className:"mt-1 typography-meta text-[var(--status-error)]",children:j.providerID}):null,e[48]=j.providerID,e[49]=De):De=e[49];let he;e[50]!==le||e[51]!==be||e[52]!==Ke||e[53]!==De?(he=s.jsxs(Qt,{label:le,info:be,children:[Ke,De]}),e[50]=le,e[51]=be,e[52]=Ke,e[53]=De,e[54]=he):he=e[54];let pe;e[55]!==u?(pe=u("settings.providers.page.custom.field.name.label"),e[55]=u,e[56]=pe):pe=e[56];let Ie;e[57]!==u?(Ie=u("settings.providers.page.custom.field.name.info"),e[57]=u,e[58]=Ie):Ie=e[58];const ze=M.name;let Je;e[59]===Symbol.for("react.memo_cache_sentinel")?(Je=kt=>P("name",kt.target.value),e[59]=Je):Je=e[59];let _e;e[60]!==u?(_e=u("settings.providers.page.custom.field.name.placeholder"),e[60]=u,e[61]=_e):_e=e[61];const Le=!!j.name;let Pe;e[62]!==u?(Pe=u("settings.providers.page.custom.field.name.label"),e[62]=u,e[63]=Pe):Pe=e[63];let Ye;e[64]!==M.name||e[65]!==_e||e[66]!==Le||e[67]!==Pe?(Ye=s.jsx(He,{value:ze,onChange:Je,placeholder:_e,className:"h-8 rounded-md px-3","aria-invalid":Le,"aria-label":Pe}),e[64]=M.name,e[65]=_e,e[66]=Le,e[67]=Pe,e[68]=Ye):Ye=e[68];let Ge;e[69]!==j.name?(Ge=j.name?s.jsx("p",{className:"mt-1 typography-meta text-[var(--status-error)]",children:j.name}):null,e[69]=j.name,e[70]=Ge):Ge=e[70];let Me;e[71]!==pe||e[72]!==Ie||e[73]!==Ye||e[74]!==Ge?(Me=s.jsxs(Qt,{label:pe,info:Ie,children:[Ye,Ge]}),e[71]=pe,e[72]=Ie,e[73]=Ye,e[74]=Ge,e[75]=Me):Me=e[75];let $e;e[76]!==u?($e=u("settings.providers.page.custom.field.baseURL.label"),e[76]=u,e[77]=$e):$e=e[77];let Fe;e[78]!==u?(Fe=u("settings.providers.page.custom.field.baseURL.info"),e[78]=u,e[79]=Fe):Fe=e[79];const ye=M.baseURL;let z;e[80]===Symbol.for("react.memo_cache_sentinel")?(z=kt=>P("baseURL",kt.target.value),e[80]=z):z=e[80];let oe;e[81]!==u?(oe=u("settings.providers.page.custom.field.baseURL.placeholder"),e[81]=u,e[82]=oe):oe=e[82];const me=!!j.baseURL;let ve;e[83]!==u?(ve=u("settings.providers.page.custom.field.baseURL.label"),e[83]=u,e[84]=ve):ve=e[84];let re;e[85]!==M.baseURL||e[86]!==oe||e[87]!==me||e[88]!==ve?(re=s.jsx(He,{value:ye,onChange:z,placeholder:oe,className:"h-8 rounded-md px-3 font-mono text-xs","aria-invalid":me,"aria-label":ve}),e[85]=M.baseURL,e[86]=oe,e[87]=me,e[88]=ve,e[89]=re):re=e[89];let Ve;e[90]!==j.baseURL?(Ve=j.baseURL?s.jsx("p",{className:"mt-1 typography-meta text-[var(--status-error)]",children:j.baseURL}):null,e[90]=j.baseURL,e[91]=Ve):Ve=e[91];let Ze;e[92]!==$e||e[93]!==Fe||e[94]!==re||e[95]!==Ve?(Ze=s.jsxs(Qt,{label:$e,info:Fe,children:[re,Ve]}),e[92]=$e,e[93]=Fe,e[94]=re,e[95]=Ve,e[96]=Ze):Ze=e[96];let B;e[97]!==u?(B=u("settings.providers.page.custom.field.apiKey.label"),e[97]=u,e[98]=B):B=e[98];let Ue;e[99]!==h||e[100]!==E||e[101]!==u?(Ue=u(E&&h?"settings.providers.page.custom.field.apiKey.editInfo":"settings.providers.page.custom.field.apiKey.info"),e[99]=h,e[100]=E,e[101]=u,e[102]=Ue):Ue=e[102];const Qe=M.apiKey;let et;e[103]===Symbol.for("react.memo_cache_sentinel")?(et=kt=>P("apiKey",kt.target.value),e[103]=et):et=e[103];let tt;e[104]!==h||e[105]!==E||e[106]!==u?(tt=u(E&&h?"settings.providers.page.custom.field.apiKey.editPlaceholder":"settings.providers.page.custom.field.apiKey.placeholder"),e[104]=h,e[105]=E,e[106]=u,e[107]=tt):tt=e[107];const wt=!!j.apiKey;let mt;e[108]!==u?(mt=u("settings.providers.page.custom.field.apiKey.label"),e[108]=u,e[109]=mt):mt=e[109];let pt;e[110]!==M.apiKey||e[111]!==tt||e[112]!==wt||e[113]!==mt?(pt=s.jsx(He,{type:"password",value:Qe,onChange:et,placeholder:tt,className:"h-8 rounded-md px-3 font-mono text-xs","aria-invalid":wt,"aria-label":mt}),e[110]=M.apiKey,e[111]=tt,e[112]=wt,e[113]=mt,e[114]=pt):pt=e[114];let at;e[115]!==j.apiKey?(at=j.apiKey?s.jsx("p",{className:"mt-1 typography-meta text-[var(--status-error)]",children:j.apiKey}):null,e[115]=j.apiKey,e[116]=at):at=e[116];let ft;e[117]!==B||e[118]!==Ue||e[119]!==pt||e[120]!==at?(ft=s.jsxs(Qt,{label:B,info:Ue,children:[pt,at]}),e[117]=B,e[118]=Ue,e[119]=pt,e[120]=at,e[121]=ft):ft=e[121];let gt;e[122]!==V||e[123]!==te||e[124]!==ae||e[125]!==he||e[126]!==Me||e[127]!==Ze||e[128]!==ft?(gt=s.jsxs(Oe,{title:V,divider:!1,settingsItem:"providers.custom",contentClassName:xn,children:[te,ae,he,Me,Ze,ft]}),e[122]=V,e[123]=te,e[124]=ae,e[125]=he,e[126]=Me,e[127]=Ze,e[128]=ft,e[129]=gt):gt=e[129];let Ct;e[130]!==u?(Ct=u("settings.providers.page.custom.models.title"),e[130]=u,e[131]=Ct):Ct=e[131];let ie;if(e[132]!==M.models||e[133]!==T||e[134]!==u){let kt;e[136]!==M.models.length||e[137]!==T||e[138]!==u?(kt=(bt,Pt)=>s.jsx("div",{className:`${As} space-y-2`,children:s.jsxs("div",{className:"flex items-start gap-2",children:[s.jsxs("div",{className:"min-w-0 flex-1 space-y-2",children:[s.jsxs("div",{children:[s.jsx("label",{className:Et,children:u("settings.providers.page.custom.models.idLabel")}),s.jsx(He,{value:bt.id,onChange:St=>se(Pt,"id",St.target.value),placeholder:u("settings.providers.page.custom.models.idPlaceholder"),className:"mt-1 h-8 rounded-md px-3 font-mono text-xs","aria-label":u("settings.providers.page.custom.models.idLabel")}),T[Pt]?.id?s.jsx("p",{className:"mt-1 typography-meta text-[var(--status-error)]",children:T[Pt]?.id}):null]}),s.jsxs("div",{children:[s.jsx("label",{className:Et,children:u("settings.providers.page.custom.models.nameLabel")}),s.jsx(He,{value:bt.name,onChange:St=>se(Pt,"name",St.target.value),placeholder:u("settings.providers.page.custom.models.namePlaceholder"),className:"mt-1 h-8 rounded-md px-3","aria-label":u("settings.providers.page.custom.models.nameLabel")}),T[Pt]?.name?s.jsx("p",{className:"mt-1 typography-meta text-[var(--status-error)]",children:T[Pt]?.name}):null]})]}),s.jsx(H,{type:"button",variant:"ghost",size:"icon",className:gs,disabled:M.models.length<=1,onClick:()=>{M.models.length<=1||(I(St=>({...St,models:St.models.filter((Ft,Bt)=>Bt!==Pt)})),v(St=>St.filter((Ft,Bt)=>Bt!==Pt)))},"aria-label":u("settings.providers.page.custom.models.remove"),children:s.jsx(_,{name:"delete-bin",className:"size-4"})})]})},bt.row),e[136]=M.models.length,e[137]=T,e[138]=u,e[139]=kt):kt=e[139],ie=M.models.map(kt),e[132]=M.models,e[133]=T,e[134]=u,e[135]=ie}else ie=e[135];let Ae;e[140]===Symbol.for("react.memo_cache_sentinel")?(Ae=()=>{I(xu),v(bu)},e[140]=Ae):Ae=e[140];let Be;e[141]!==u?(Be=u("settings.providers.page.custom.models.add"),e[141]=u,e[142]=Be):Be=e[142];let qe;e[143]!==Be?(qe=s.jsx(H,{type:"button",variant:"outline",size:"xs",className:"!font-normal",onClick:Ae,children:Be}),e[143]=Be,e[144]=qe):qe=e[144];let Nt;e[145]!==Ct||e[146]!==ie||e[147]!==qe?(Nt=s.jsxs(Oe,{title:Ct,contentClassName:xn,children:[ie,qe]}),e[145]=Ct,e[146]=ie,e[147]=qe,e[148]=Nt):Nt=e[148];let xt;e[149]!==u?(xt=u("settings.providers.page.custom.headers.title"),e[149]=u,e[150]=xt):xt=e[150];let zt;e[151]!==u?(zt=u("settings.providers.page.custom.headers.description"),e[151]=u,e[152]=zt):zt=e[152];let J;e[153]!==zt?(J=s.jsx("p",{className:In,children:zt}),e[153]=zt,e[154]=J):J=e[154];let xe;if(e[155]!==M.headers||e[156]!==$||e[157]!==u){let kt;e[159]!==M.headers.length||e[160]!==$||e[161]!==u?(kt=(bt,Pt)=>s.jsx("div",{className:`${As} space-y-2`,children:s.jsxs("div",{className:"flex items-start gap-2",children:[s.jsxs("div",{className:"min-w-0 flex-1 space-y-2",children:[s.jsxs("div",{children:[s.jsx("label",{className:Et,children:u("settings.providers.page.custom.headers.keyLabel")}),s.jsx(He,{value:bt.key,onChange:St=>O(Pt,"key",St.target.value),placeholder:u("settings.providers.page.custom.headers.keyPlaceholder"),className:"mt-1 h-8 rounded-md px-3 font-mono text-xs","aria-label":u("settings.providers.page.custom.headers.keyLabel")}),$[Pt]?.key?s.jsx("p",{className:"mt-1 typography-meta text-[var(--status-error)]",children:$[Pt]?.key}):null]}),s.jsxs("div",{children:[s.jsx("label",{className:Et,children:u("settings.providers.page.custom.headers.valueLabel")}),s.jsx(He,{value:bt.value,onChange:St=>O(Pt,"value",St.target.value),placeholder:u("settings.providers.page.custom.headers.valuePlaceholder"),className:"mt-1 h-8 rounded-md px-3 font-mono text-xs","aria-label":u("settings.providers.page.custom.headers.valueLabel")}),$[Pt]?.value?s.jsx("p",{className:"mt-1 typography-meta text-[var(--status-error)]",children:$[Pt]?.value}):null]})]}),s.jsx(H,{type:"button",variant:"ghost",size:"icon",className:gs,disabled:M.headers.length<=1,onClick:()=>{M.headers.length<=1||(I(St=>({...St,headers:St.headers.filter((Ft,Bt)=>Bt!==Pt)})),w(St=>St.filter((Ft,Bt)=>Bt!==Pt)))},"aria-label":u("settings.providers.page.custom.headers.remove"),children:s.jsx(_,{name:"delete-bin",className:"size-4"})})]})},bt.row),e[159]=M.headers.length,e[160]=$,e[161]=u,e[162]=kt):kt=e[162],xe=M.headers.map(kt),e[155]=M.headers,e[156]=$,e[157]=u,e[158]=xe}else xe=e[158];let Re;e[163]===Symbol.for("react.memo_cache_sentinel")?(Re=()=>{I(vu),w(yu)},e[163]=Re):Re=e[163];let we;e[164]!==u?(we=u("settings.providers.page.custom.headers.add"),e[164]=u,e[165]=we):we=e[165];let rt;e[166]!==we?(rt=s.jsx(H,{type:"button",variant:"outline",size:"xs",className:"!font-normal",onClick:Re,children:we}),e[166]=we,e[167]=rt):rt=e[167];let lt;e[168]!==xt||e[169]!==J||e[170]!==xe||e[171]!==rt?(lt=s.jsxs(Oe,{title:xt,contentClassName:xn,children:[J,xe,rt]}),e[168]=xt,e[169]=J,e[170]=xe,e[171]=rt,e[172]=lt):lt=e[172];let it;e[173]!==k||e[174]!==m||e[175]!==u?(it=m?s.jsx(H,{type:"button",variant:"outline",size:"xs",className:"!font-normal",onClick:m,disabled:k,children:u("settings.providers.page.custom.actions.back")}):null,e[173]=k,e[174]=m,e[175]=u,e[176]=it):it=e[176];let It;e[177]!==k||e[178]!==b||e[179]!==u?(It=b?s.jsx(H,{type:"button",variant:"destructive",size:"xs",className:"!font-normal",onClick:()=>{b()},disabled:k,children:u("settings.providers.page.actions.disconnect")}):null,e[177]=k,e[178]=b,e[179]=u,e[180]=It):It=e[180];let ls;e[181]!==k||e[182]!==E||e[183]!==u?(ls=u(k?"settings.providers.page.actions.saving":E?"settings.providers.page.custom.actions.update":"settings.providers.page.custom.actions.save"),e[181]=k,e[182]=E,e[183]=u,e[184]=ls):ls=e[184];let Xt;e[185]!==k||e[186]!==ls?(Xt=s.jsx(H,{type:"submit",size:"xs",className:"!font-normal",disabled:k,children:ls}),e[185]=k,e[186]=ls,e[187]=Xt):Xt=e[187];let ts;e[188]!==it||e[189]!==It||e[190]!==Xt?(ts=s.jsxs("div",{className:"flex flex-wrap items-center gap-2 py-4",children:[it,It,Xt]}),e[188]=it,e[189]=It,e[190]=Xt,e[191]=ts):ts=e[191];let Wt;return e[192]!==A||e[193]!==gt||e[194]!==Nt||e[195]!==lt||e[196]!==ts?(Wt=s.jsxs("form",{onSubmit:A,className:"space-y-0",children:[gt,Nt,lt,ts]}),e[192]=A,e[193]=gt,e[194]=Nt,e[195]=lt,e[196]=ts,e[197]=Wt):Wt=e[197],Wt};function xu(t){return{...t,models:[...t.models,er()]}}function bu(t){return[...t,{}]}function vu(t){return{...t,headers:[...t.headers,tr()]}}function yu(t){return[...t,{}]}const ju=/[A-Z0-9]{4}-[A-Z0-9]{4,5}/,Ln=t=>typeof t=="object"&&t!==null&&!Array.isArray(t),vs=t=>typeof t=="string"&&t.length>0?t:void 0,wu=t=>{if(!Array.isArray(t))return[];const e=[];for(const a of t){if(!Ln(a))continue;const n=vs(a.value);n!==void 0&&e.push({value:n,label:vs(a.label)??n,...vs(a.hint)?{hint:vs(a.hint)}:{}})}return e},Nu=t=>{if(!Ln(t))return;const e=vs(t.key),a=t.op==="eq"||t.op==="neq"?t.op:void 0;if(!(!e||!a||typeof t.value!="string"))return{key:e,op:a,value:t.value}},ku=t=>{if(!Array.isArray(t))return[];const e=[];for(const a of t){if(!Ln(a))continue;const n=vs(a.key);if(!n)continue;const i=a.type==="select"?"select":"text",r=i==="select"?wu(a.options):[];if(i==="select"&&r.length===0)continue;const l=Nu(a.when);e.push({type:i,key:n,message:vs(a.message)??n,options:r,...vs(a.placeholder)?{placeholder:vs(a.placeholder)}:{},...l?{when:l}:{}})}return e},Su=(t,e)=>{if(!t.when)return!0;const a=e[t.when.key]??"";return t.when.op==="eq"?a===t.when.value:a!==t.when.value},sr=(t,e)=>t.filter(a=>Su(a,e)),Cu=t=>{const e={};for(const a of t)e[a.key]=a.type==="select"?a.options[0]?.value??"":"";return e},Iu=(t,e)=>sr(t,e).find(a=>(e[a.key]??"").trim().length===0)??null,Pu=(t,e)=>{const a={};for(const n of sr(t,e))a[n.key]=(e[n.key]??"").trim();return a},Au=t=>{const e=Ln(t)?t:{},a=Ln(e.data)?e.data:e,n=vs(a.url)??vs(a.verification_uri_complete)??vs(a.verification_uri),i=vs(a.instructions)??vs(a.message);if(!n&&!i)return null;const r=vs(a.user_code)??vs(a.userCode)??(i?ju.exec(i)?.[0]:void 0);return{method:a.method==="code"?"code":"auto",...n?{url:n}:{},...i?{instructions:i}:{},...r?{userCode:r}:{}}},ao=(t,e,a)=>{const n=Ln(t)?t:{},i=Ln(n.data)?n.data:{};switch(n.name){case"ProviderAuthOauthMissing":return e("settings.providers.page.auth.oauth.error.sessionExpired");case"ProviderAuthOauthCodeMissing":return e("settings.providers.page.auth.oauth.error.codeRequired");case"ProviderAuthOauthCallbackFailed":return e("settings.providers.page.auth.oauth.error.declined");case"ProviderAuthValidationFailed":return vs(i.message)??e("settings.providers.page.auth.oauth.error.invalidInput");default:return e(a)}},Si={phase:"idle"},io=({providerId:t,methods:e,onConnected:a,className:n})=>{const{t:i}=ot(),[r,l]=o.useState(Si),[x,c]=o.useState({}),[y,m]=o.useState(""),b=o.useRef(null);o.useEffect(()=>()=>b.current?.abort(),[]);const p=r.phase==="idle"?null:r.methodIndex,L=r.phase==="authorizing"||r.phase==="waiting"||r.phase==="awaitingCode"&&r.submitting,k=async(g,j,F)=>{const S=await ga(g);if(S.ok){R.success(i(j));return}console.error("Failed to copy OAuth value:",S.error),R.error(i(F))},N=async(g,j)=>{const F=new AbortController;b.current?.abort(),b.current=F;try{const S=await on.getSdkClient().provider.oauth.callback({providerID:t,method:g,...j?{code:j}:{}},{signal:F.signal});if(F.signal.aborted)return;if(S.error)throw S.error;l(Si),R.success(i("settings.providers.page.toast.oauthCompleted")),await a()}catch(S){if(F.signal.aborted)return;console.error("Failed to complete OAuth flow:",S),l({phase:"failed",methodIndex:g,message:ao(S,i,"settings.providers.page.toast.oauthCompleteFailed")})}finally{b.current===F&&(b.current=null)}},h=async(g,j)=>{l({phase:"authorizing",methodIndex:g});let F;try{const S=await on.getSdkClient().provider.oauth.authorize({providerID:t,method:g,...Object.keys(j).length>0?{inputs:j}:{}});if(S.error)throw S.error;const T=Au(S.data);if(!T){l({phase:"failed",methodIndex:g,message:i("settings.providers.page.toast.oauthDetailsMissing")});return}F=T}catch(S){console.error("Failed to start OAuth flow:",S),l({phase:"failed",methodIndex:g,message:ao(S,i,"settings.providers.page.toast.oauthStartFailed")});return}if(F.url&&En(F.url),F.method==="code"){m(""),l({phase:"awaitingCode",methodIndex:g,authorization:F,submitting:!1});return}l({phase:"waiting",methodIndex:g,authorization:F}),await N(g)},C=g=>{const j=ku(g.prompts);if(j.length===0){h(g.index,{});return}c(Cu(j)),l({phase:"prompting",methodIndex:g.index,prompts:j,error:null})},u=()=>{if(r.phase!=="prompting")return;const g=Iu(r.prompts,x);if(g){l({...r,error:i("settings.providers.page.auth.oauth.promptRequired",{field:g.message})});return}h(r.methodIndex,Pu(r.prompts,x))},E=()=>{if(r.phase!=="awaitingCode")return;const g=y.trim();g&&(l({...r,submitting:!0}),N(r.methodIndex,g))},q=()=>{b.current?.abort(),b.current=null,l(Si)},M=g=>{const j=x[g.key]??"",F=S=>c(T=>({...T,[g.key]:S}));return s.jsxs("div",{className:"space-y-1.5",children:[s.jsx("label",{className:"typography-ui-label text-foreground",children:g.message}),g.type==="select"?s.jsxs(Dt,{value:j,onValueChange:F,children:[s.jsx(Mt,{size:Kt,className:vn,children:s.jsx(_t,{children:S=>g.options.find(T=>T.value===S)?.label??null})}),s.jsx(Rt,{children:g.options.map(S=>s.jsx(dt,{value:S.value,children:S.hint?`${S.label} · ${S.hint}`:S.label},S.value))})]}):s.jsx(He,{value:j,onChange:S=>F(S.target.value),placeholder:g.placeholder,className:"max-w-[24rem] text-xs"})]},g.key)},I=g=>s.jsxs(s.Fragment,{children:[g.instructions&&s.jsx("p",{className:"typography-meta text-[var(--primary-base)] bg-[var(--primary-base)]/10 px-2 py-1.5 rounded",children:g.instructions}),g.userCode&&s.jsxs("div",{className:"flex items-center gap-2",children:[s.jsx(He,{value:g.userCode,readOnly:!0,"aria-label":i("settings.providers.page.auth.oauth.deviceCodeLabel"),className:"font-mono text-center tracking-widest"}),s.jsx(H,{variant:"outline",size:"xs",className:"!font-normal shrink-0",onClick:()=>{k(g.userCode??"","settings.providers.page.toast.deviceCodeCopied","settings.providers.page.toast.deviceCodeCopyFailed")},children:i("settings.providers.page.actions.copyCode")})]}),g.url&&s.jsxs("div",{className:"flex items-center gap-2",children:[s.jsx(He,{value:g.url,readOnly:!0,"aria-label":i("settings.providers.page.auth.oauth.linkLabel"),className:"text-xs text-muted-foreground"}),s.jsxs("div",{className:"flex gap-1 shrink-0",children:[s.jsx(H,{variant:"outline",size:"xs",className:"!font-normal",onClick:()=>{En(g.url??"")},children:i("settings.providers.page.actions.open")}),s.jsx(H,{variant:"outline",size:"xs",className:"!font-normal",onClick:()=>{k(g.url??"","settings.providers.page.toast.oauthLinkCopied","settings.providers.page.toast.oauthLinkCopyFailed")},children:i("settings.providers.page.actions.copy")})]})]})]});return s.jsx("div",{className:je("space-y-4",n),children:e.map(g=>{const j=p===g.index;return s.jsxs("div",{className:"space-y-3",children:[s.jsxs("div",{className:"flex items-center justify-between gap-2",children:[s.jsx("div",{className:"typography-ui-label text-foreground",children:g.label}),s.jsx(H,{variant:"outline",size:"xs",className:"!font-normal shrink-0",onClick:()=>C(g),disabled:L,children:i("settings.providers.page.actions.connect")})]}),j&&r.phase==="prompting"&&s.jsxs("div",{className:"space-y-3",children:[sr(r.prompts,x).map(M),r.error&&s.jsx("p",{className:"typography-meta text-[var(--status-error)]",children:r.error}),s.jsxs("div",{className:"flex items-center gap-2",children:[s.jsx(H,{size:"xs",className:"!font-normal",onClick:u,children:i("settings.providers.page.actions.continue")}),s.jsx(H,{variant:"ghost",size:"xs",className:"!font-normal",onClick:q,children:i("settings.providers.page.actions.cancel")})]})]}),j&&r.phase==="authorizing"&&s.jsxs("p",{className:"typography-meta text-muted-foreground flex items-center gap-2",children:[s.jsx(_,{name:"loader",className:"h-3.5 w-3.5 animate-spin"}),i("settings.providers.page.auth.oauth.starting")]}),j&&r.phase==="waiting"&&s.jsxs("div",{className:"space-y-3",children:[I(r.authorization),s.jsxs("div",{className:"flex items-center justify-between gap-2",children:[s.jsxs("p",{className:"typography-meta text-muted-foreground flex items-center gap-2",children:[s.jsx(_,{name:"loader",className:"h-3.5 w-3.5 animate-spin"}),i("settings.providers.page.auth.oauth.waiting")]}),s.jsx(H,{variant:"ghost",size:"xs",className:"!font-normal shrink-0",onClick:q,children:i("settings.providers.page.actions.cancel")})]}),s.jsx("p",{className:"typography-meta text-muted-foreground",children:i("settings.providers.page.auth.oauth.waitingHint")})]}),j&&r.phase==="awaitingCode"&&s.jsxs("div",{className:"space-y-3",children:[I(r.authorization),s.jsx("p",{className:"typography-meta text-muted-foreground",children:i("settings.providers.page.auth.oauth.codeHint")}),s.jsxs("div",{className:"flex items-center gap-2",children:[s.jsx(He,{value:y,onChange:F=>m(F.target.value),placeholder:i("settings.providers.page.auth.pasteAuthorizationCodePlaceholder"),className:"font-mono text-xs",disabled:r.submitting}),s.jsx(H,{size:"xs",className:"!font-normal shrink-0",onClick:E,disabled:r.submitting||y.trim().length===0,children:r.submitting?i("settings.providers.page.actions.saving"):i("settings.providers.page.actions.complete")}),s.jsx(H,{variant:"ghost",size:"xs",className:"!font-normal shrink-0",onClick:q,disabled:r.submitting,children:i("settings.providers.page.actions.cancel")})]})]}),j&&r.phase==="failed"&&s.jsxs("div",{className:"space-y-2",children:[s.jsx("p",{className:"typography-meta text-[var(--status-error)]",children:r.message}),s.jsx(H,{variant:"outline",size:"xs",className:"!font-normal",onClick:()=>C(g),children:i("settings.providers.page.actions.tryAgain")})]})]},g.index)})})},Tu=t=>new Intl.NumberFormat(Ro(),{notation:"compact",compactDisplay:"short",maximumFractionDigits:1,minimumFractionDigits:0}).format(t),ro=t=>{if(typeof t!="number"||Number.isNaN(t))return null;if(t===0)return"0";const e=Tu(t);return e.endsWith(".0")?e.slice(0,-2):e},oa="__add_provider__",ll=t=>typeof t=="object"&&t!==null,oo=(t,e)=>t.map(({method:a,methodIndex:n})=>({index:n,label:a.label||a.name||e(n),prompts:a.prompts})),Eu=t=>{if(typeof t=="string")return{id:t};if(!ll(t))return null;const e=typeof t.id=="string"&&t.id||typeof t.providerID=="string"&&t.providerID||typeof t.slug=="string"&&t.slug||typeof t.name=="string"&&t.name;if(!e)return null;const a=typeof t.name=="string"?t.name:void 0;return{id:e,name:a}},Du=t=>{let e=[];Array.isArray(t)?e=t:ll(t)&&(Array.isArray(t.all)?e=t.all:Array.isArray(t.providers)&&(e=t.providers));const a=e.map(i=>Eu(i)).filter(i=>!!i),n=new Set;return a.filter(i=>n.has(i.id)?!1:(n.add(i.id),!0))},Mu=()=>{const{t}=ot(),e=nt(z=>z.providers),a=nt(z=>z.selectedProviderId),n=nt(z=>z.setSelectedProvider),i=nt(z=>z.getModelMetadata),r=de(z=>z.hiddenModels),l=de(z=>z.toggleHiddenModel),x=de(z=>z.hideAllModels),c=de(z=>z.showAllModels),[y,m]=o.useState({}),[b,p]=o.useState(!1),[L,k]=o.useState({}),[N,h]=o.useState(null),[C,u]=o.useState(""),[E,q]=o.useState([]),[M,I]=o.useState(!1),[g,j]=o.useState(null),[F,S]=o.useState(""),[T,v]=o.useState(""),[K,$]=o.useState(!1),[w,G]=o.useState({}),[Q,X]=o.useState(!1),[Z,P]=o.useState(null),[ee,se]=o.useState(null),[D,O]=o.useState(null),[U,A]=o.useState(null),[V,W]=o.useState(null),te=a===oa,ae=te&&F===Cn,le=!!(Z&&a&&Z===a&&!te);o.useEffect(()=>{!a&&e.length>0&&n(e[0].id)},[e,a,n]),o.useEffect(()=>{if(!a)return;let z=!0;return(async()=>{p(!0);try{const me=await on.getSdkClient().provider.auth();if(me.error)throw new Error(`provider.auth failed: ${String(me.error)}`);if(!z)return;m(iu(me.data))}catch(me){if(!z)return;console.error("Failed to load provider auth methods:",me),R.error(t("settings.providers.page.toast.authMethodsLoadFailed"))}finally{z&&p(!1)}})(),()=>{z=!1}},[a,t]),o.useEffect(()=>{if(!au(te))return;let z=!0;return(async()=>{I(!0),j(null);try{const me=await on.getSdkClient().provider.list();if(me.error)throw new Error(`provider.list failed: ${String(me.error)}`);if(!z)return;q(Du(me.data))}catch(me){if(!z)return;console.error("Failed to load available providers:",me),j(t("settings.providers.page.state.unableToLoadProviderList"))}finally{z&&I(!1)}})(),()=>{z=!1}},[te,t]);const be=o.useMemo(()=>new Set(e.map(z=>z.id)),[e]),ke=o.useMemo(()=>E.filter(z=>!be.has(z.id)).sort((z,oe)=>{const me=(z.name||z.id).toLowerCase(),ve=(oe.name||oe.id).toLowerCase();return me.localeCompare(ve)}),[E,be]);o.useEffect(()=>{a===oa&&F&&F!==Cn&&!ke.some(z=>z.id===F)&&S("")},[a,F,ke]),o.useEffect(()=>{if(a===oa){X(!0),P(null),se(null),O(null),A(null);return}X(!1),Z&&Z!==a&&(P(null),se(null),O(null),A(null))},[a,Z]),o.useEffect(()=>{if(!a||a===oa)return;const z=w[a];if(!z)return;const oe=e.find(re=>re.id===a),me=Array.isArray(oe?.env)?oe.env.filter(re=>typeof re=="string"&&re.trim().length>0):[];z.auth.exists||me.length>0||X(!0)},[a,w,e]),o.useEffect(()=>{if(!a||a===oa)return;let z=!1;return(async()=>{try{const me=await ct(`/api/provider/${encodeURIComponent(a)}/source`,{method:"GET",headers:{Accept:"application/json"}}),ve=await me.json().catch(()=>null);if(!me.ok)throw new Error(ve?.error||t("settings.providers.page.toast.providerSourcesLoadFailed"));const re=ve?.sources??ve?.data?.sources;!z&&re&&G(Ve=>({...Ve,[a]:re}))}catch(me){z||console.error("Failed to load provider sources:",me)}})(),()=>{z=!0}},[a,t]);const ce=e.find(z=>z.id===a),ge=a?w[a]:void 0,Ee=async z=>{const oe=L[z]?.trim()??"";if(!oe){R.error(t("settings.providers.page.toast.apiKeyRequired"));return}const me=`api:${z}`;h(me);try{if((await on.getSdkClient().auth.set({providerID:z,auth:{type:"api",key:oe}})).error)throw new Error(t("settings.providers.page.toast.apiKeySaveFailed"));R.success(t("settings.providers.page.toast.apiKeySaved")),k(re=>({...re,[z]:""})),qn("providers",{id:z}),n(z)}catch(ve){console.error("Failed to save API key:",ve),R.error(t("settings.providers.page.toast.apiKeySaveFailed"))}finally{h(null)}},Se=async z=>{const oe=`custom:${z.providerID}`;h(oe),W(z.providerID),A(null);try{const me=hu(z);if(me&&(await on.getSdkClient().auth.set(me)).error)throw new Error(t("settings.providers.page.toast.apiKeySaveFailed"));const ve=fu(z,{scope:Z?D??so(w[Z]):"user"}),re=await ct("/api/provider",{method:"PUT",headers:{Accept:"application/json","Content-Type":"application/json"},body:JSON.stringify(ve)}),Ve=await re.json().catch(()=>null);if(!re.ok)throw me&&A(t("settings.providers.page.custom.authFailure.configAfterAuth")),new Error(Ve?.error||t("settings.providers.page.toast.customProviderSaveFailed"));R.success(t("settings.providers.page.toast.customProviderSaved",{provider:z.name})),S(""),P(null),se(null),O(null),A(null),W(null),qa(Ve,"providers",{id:z.providerID}),n(z.providerID)}catch(me){console.error("Failed to save custom provider:",me),R.error(me instanceof Error&&me.message?me.message:t("settings.providers.page.toast.customProviderSaveFailed"))}finally{h(null)}},Ne=z=>t("settings.providers.page.auth.oauthMethodFallback",{index:String(z+1)}),fe=z=>{X(!1),qn("providers",{id:z}),n(z)},Ke=async z=>{const oe=`disconnect:${z}`;h(oe);try{const me=await ct(`/api/provider/${encodeURIComponent(z)}/auth?scope=all`,{method:"DELETE",headers:{Accept:"application/json"}}),ve=await me.json().catch(()=>null);if(!me.ok)throw new Error(ve?.error||t("settings.providers.page.toast.providerDisconnectFailed"));R.success(t("settings.providers.page.toast.providerDisconnected")),qa(ve,"providers",{id:z})}catch(me){console.error("Failed to disconnect provider:",me),R.error(t("settings.providers.page.toast.providerDisconnectFailed"))}finally{h(null)}},De=async z=>{z&&(await Ke(z),P(null),se(null),O(null),A(null),W(null),S(""))};if(!te&&e.length===0)return s.jsx("div",{className:"flex h-full items-center justify-center",children:s.jsxs("div",{className:"text-center text-muted-foreground",children:[s.jsx(_,{name:"stack",className:"mx-auto mb-3 h-12 w-12 opacity-50"}),s.jsx("p",{className:"typography-body",children:t("settings.providers.page.empty.noProvidersDetected")}),s.jsx("p",{className:"typography-meta mt-1 opacity-75",children:t("settings.providers.page.empty.checkOpenCodeConfiguration")})]})});if(te)return s.jsxs(rs,{title:t("settings.providers.page.connect.title"),showSaveStatus:!1,children:[s.jsx(Oe,{title:t("settings.providers.page.connect.selectProviderTitle"),divider:!1,settingsItem:"providers.connect",children:s.jsxs("div",{className:"flex flex-wrap items-center gap-2 py-1.5",children:[s.jsx("span",{className:"typography-ui-label text-foreground",children:t("settings.providers.page.connect.providerField")}),M?s.jsx("p",{className:"typography-meta text-muted-foreground",children:t("settings.providers.page.state.loading")}):g?s.jsx("p",{className:"typography-meta text-muted-foreground",children:g}):s.jsxs(Hs,{open:K,onOpenChange:z=>{$(z),z||v("")},children:[s.jsx($s,{asChild:!0,children:s.jsxs("button",{type:"button",className:bn,children:[s.jsxs("span",{className:"flex items-center gap-2 min-w-0",children:[F&&F!==Cn?s.jsx(Pn,{providerId:F,className:"h-3.5 w-3.5 flex-shrink-0"}):null,s.jsx("span",{className:je("truncate typography-ui-label font-normal",F?"text-foreground":"text-muted-foreground"),children:F===Cn?t("settings.providers.page.custom.optionLabel"):F?ke.find(z=>z.id===F)?.name||F:t("settings.providers.page.connect.selectProviderPlaceholder")})]}),s.jsx(_,{name:"arrow-down-s",className:"h-4 w-4 flex-shrink-0 text-muted-foreground/50"})]})}),s.jsxs(Bs,{align:"start",className:"w-[280px] p-0",onCloseAutoFocus:z=>z.preventDefault(),children:[s.jsxs("div",{className:"flex items-center gap-2 border-b border-[var(--surface-subtle)] px-3 py-2",onKeyDown:z=>z.stopPropagation(),children:[s.jsx(_,{name:"search",className:"h-4 w-4 text-muted-foreground"}),s.jsx("input",{type:"text",value:T,onChange:z=>v(z.target.value),onKeyDown:z=>z.stopPropagation(),placeholder:t("settings.providers.page.connect.searchProvidersPlaceholder"),className:"flex-1 bg-transparent typography-meta outline-none placeholder:text-muted-foreground",autoFocus:!0})]}),s.jsx(Ds,{outerClassName:"max-h-[240px]",className:"p-1",children:(()=>{const z=T.toLowerCase(),oe=t("settings.providers.page.custom.optionLabel"),me=!z||oe.toLowerCase().includes(z)||"other".includes(z)||"custom".includes(z),ve=ke.filter(re=>(re.name||re.id).toLowerCase().includes(z)||re.id.toLowerCase().includes(z));return ve.length===0&&!me?s.jsx("p",{className:"py-4 text-center typography-meta text-muted-foreground",children:t("settings.providers.page.connect.noProvidersFound")}):s.jsxs(s.Fragment,{children:[ve.map(re=>s.jsxs(Gs,{onSelect:()=>{S(re.id),$(!1),v("")},className:"flex items-center justify-between",children:[s.jsxs("span",{className:"flex items-center gap-2 min-w-0",children:[s.jsx(Pn,{providerId:re.id,className:"h-4 w-4 flex-shrink-0"}),s.jsx("span",{className:"truncate",children:re.name||re.id})]}),F===re.id&&s.jsx(_,{name:"check",className:"h-4 w-4 text-[var(--primary-base)]"})]},re.id)),me?s.jsxs(Gs,{onSelect:()=>{S(Cn),$(!1),v("")},className:"flex items-center justify-between",children:[s.jsxs("span",{className:"flex items-center gap-2 min-w-0",children:[s.jsx(_,{name:"add",className:"h-4 w-4 flex-shrink-0"}),s.jsx("span",{className:"truncate",children:oe})]}),F===Cn&&s.jsx(_,{name:"check",className:"h-4 w-4 text-[var(--primary-base)]"})]},Cn):null]})})()})]})]})]})}),ae?s.jsx(no,{mode:"create",existingProviderIDs:be,busy:N?.startsWith("custom:")??!1,authFailureHint:U,onCancel:()=>{S(""),A(null),W(null)},onDisconnect:U&&V?()=>{De(V)}:void 0,onSubmit:Se}):F?s.jsx(Oe,{title:t("settings.providers.page.auth.title"),settingsItem:"providers.auth",contentClassName:"space-y-4",children:b?s.jsx("p",{className:"typography-meta text-muted-foreground",children:t("settings.providers.page.auth.loadingMethods")}):s.jsx(s.Fragment,{children:(()=>{const z=y[F]??[],oe=oo(to(z),Ne),me=eo(z);return s.jsxs(s.Fragment,{children:[me?s.jsxs("div",{className:"py-1.5",children:[s.jsxs("label",{className:"typography-ui-label text-foreground flex items-center gap-1.5",children:[t("settings.providers.page.auth.apiKeyLabel"),s.jsx(Yt,{children:t("settings.providers.page.auth.apiKeyTooltip")})]}),s.jsxs("div",{className:"flex flex-col @xl:flex-row @xl:items-center gap-2 mt-1.5",children:[s.jsx(He,{type:"password",value:L[F]??"",onChange:ve=>k(re=>({...re,[F]:ve.target.value})),placeholder:t("settings.providers.page.auth.apiKeyPlaceholder"),className:"flex-1 font-mono text-xs"}),s.jsx(H,{size:"xs",className:"!font-normal shrink-0",onClick:()=>Ee(F),disabled:N===`api:${F}`,children:N===`api:${F}`?t("settings.providers.page.actions.saving"):t("settings.providers.page.actions.saveKey")})]})]}):null,oe.length>0?s.jsx(io,{providerId:F,methods:oe,onConnected:()=>fe(F),className:je(me&&"border-t border-[var(--surface-subtle)] pt-2")},F):null]})})()})}):null]});if(!ce)return s.jsx("div",{className:"flex h-full items-center justify-center",children:s.jsxs("div",{className:"text-center text-muted-foreground",children:[s.jsx(_,{name:"stack",className:"mx-auto mb-3 h-12 w-12 opacity-50"}),s.jsx("p",{className:"typography-body",children:t("settings.providers.page.empty.selectProviderFromSidebar")}),s.jsx("p",{className:"typography-meta mt-1 opacity-75",children:t("settings.providers.page.empty.reviewDetailsAndConfigureAuth")})]})});const he=Array.isArray(ce.models)?ce.models:[],pe=y[ce.id]??[],Ie=oo(to(pe),Ne),ze=eo(pe),Je=!!ge,_e=Je&&mu(ce,ge),Le=Array.isArray(ce.env)?ce.env.filter(z=>typeof z=="string"&&z.trim().length>0):[],Pe=!!ge?.auth.exists,Ye=Le.length>0,Ge=Pe||Ye,Me=Je&&!Ge,$e=he.length>0&&(!Je||Ge),Fe=!ze&&Ie.length>0?t("settings.providers.page.auth.useReconnectHint"):t("settings.providers.page.auth.incompleteHint"),ye=he.filter(z=>{const oe=typeof z?.name=="string"?z.name:"",me=typeof z?.id=="string"?z.id:"",ve=C.trim().toLowerCase();return ve?oe.toLowerCase().includes(ve)||me.toLowerCase().includes(ve):!0});return le&&_e&&ee?s.jsx(rs,{title:ce.name||ce.id,titleLeading:s.jsx(Pn,{providerId:ce.id,className:"h-5 w-5 shrink-0"}),description:s.jsx("span",{className:"font-mono typography-settings-description text-muted-foreground",children:ce.id}),showSaveStatus:!1,children:s.jsx(no,{mode:"edit",existingProviderIDs:be,initialValues:ee,allowExistingAuth:Ge||!Je,busy:N?.startsWith("custom:")??!1,authFailureHint:U,onCancel:()=>{P(null),se(null),O(null),A(null),W(null)},onDisconnect:()=>{De(ce.id)},onSubmit:Se})}):s.jsxs(rs,{title:ce.name||ce.id,titleLeading:s.jsx(Pn,{providerId:ce.id,className:"h-5 w-5 shrink-0"}),description:s.jsx("span",{className:"font-mono typography-settings-description text-muted-foreground",children:ce.id}),showSaveStatus:!1,children:[s.jsx(Oe,{title:t("settings.providers.page.auth.title"),divider:!1,headerAction:s.jsxs("div",{className:"flex items-center gap-1",children:[_e?s.jsx(H,{variant:"outline",size:"xs",className:"!font-normal",onClick:()=>{A(null),se(uu(ce)),O(so(ge)),P(ce.id)},children:t("settings.providers.page.actions.edit")}):null,s.jsx(H,{variant:"outline",size:"xs",className:"!font-normal",onClick:()=>X(z=>!z),children:t(Q?"settings.providers.page.actions.hide":"settings.providers.page.actions.reconnect")})]}),settingsItem:"providers.auth",children:Q?b?s.jsx("div",{className:"py-1.5 typography-meta text-muted-foreground",children:t("settings.providers.page.auth.loadingMethods")}):s.jsxs("div",{className:"space-y-4",children:[ze?s.jsxs("div",{className:"py-1.5",children:[s.jsxs("label",{className:"typography-ui-label text-foreground flex items-center gap-1.5",children:[t("settings.providers.page.auth.apiKeyLabel"),s.jsx(Yt,{children:t("settings.providers.page.auth.apiKeyTooltip")})]}),s.jsxs("div",{className:"flex flex-col @xl:flex-row @xl:items-center gap-2 mt-1.5",children:[s.jsx(He,{type:"password",value:L[ce.id]??"",onChange:z=>k(oe=>({...oe,[ce.id]:z.target.value})),placeholder:t("settings.providers.page.auth.apiKeyPlaceholder"),className:"flex-1 font-mono text-xs"}),s.jsx(H,{size:"xs",className:"!font-normal shrink-0",onClick:()=>Ee(ce.id),disabled:N===`api:${ce.id}`,children:N===`api:${ce.id}`?t("settings.providers.page.actions.saving"):t("settings.providers.page.actions.saveKey")})]})]}):null,Ie.length>0&&s.jsx(io,{providerId:ce.id,methods:Ie,onConnected:()=>fe(ce.id),className:je(ze&&"border-t border-[var(--surface-subtle)] pt-2")},ce.id)]}):Me?s.jsxs("div",{className:"flex items-center gap-1.5 py-1.5",children:[s.jsx(_,{name:"alert",className:"w-4 h-4 text-[var(--status-warning)] shrink-0"}),s.jsx("span",{className:"typography-ui-label text-foreground",children:t("settings.providers.page.auth.incomplete")}),s.jsx(Yt,{children:Fe})]}):s.jsxs("div",{className:"flex items-center gap-1.5 py-1.5",children:[s.jsx(_,{name:"check",className:"w-4 h-4 text-[var(--status-success)] shrink-0"}),s.jsx("span",{className:"typography-ui-label text-foreground",children:t("settings.providers.page.auth.connected")}),s.jsx(Yt,{children:t("settings.providers.page.auth.useReconnectHint")})]})}),s.jsx(Oe,{title:t("settings.providers.page.connectionDetails.title"),settingsItem:"providers.connection-details",children:s.jsxs("div",{className:"flex flex-col gap-2 py-1.5 @xl:flex-row @xl:items-center @xl:justify-between @xl:gap-8",children:[s.jsx("div",{className:"flex min-w-0 flex-col",children:ge&&(ge.auth.exists||ge.user.exists||ge.project.exists||ge.custom?.exists)?s.jsxs("span",{className:"typography-meta text-muted-foreground",children:[t("settings.providers.page.connectionDetails.configuredIn")," ",[ge.auth.exists?t("settings.providers.page.connectionDetails.source.authCredentials"):null,ge.user.exists?t("settings.providers.page.connectionDetails.source.userConfig"):null,ge.project.exists?t("settings.providers.page.connectionDetails.source.projectConfig"):null,ge.custom?.exists?t("settings.providers.page.connectionDetails.source.customConfig"):null].filter(Boolean).join(", ")]}):s.jsx("span",{className:"typography-meta text-muted-foreground",children:t("settings.providers.page.connectionDetails.noActiveSource")})}),s.jsx(H,{variant:"ghost",size:"xs",className:"!font-normal text-[var(--status-error)] hover:text-[var(--status-error)]",onClick:()=>Ke(ce.id),disabled:N===`disconnect:${ce.id}`,children:N===`disconnect:${ce.id}`?t("settings.providers.page.actions.disconnecting"):t("settings.providers.page.actions.disconnect")})]})}),$e?s.jsxs(Oe,{title:t("settings.providers.page.models.title"),titleAccessory:s.jsxs("span",{className:"typography-micro text-muted-foreground font-normal",children:["(",he.length,")"]}),headerAction:s.jsxs("div",{className:"flex items-center gap-1",children:[s.jsx(H,{variant:"outline",size:"xs",className:"!font-normal",onClick:()=>{const z=he.map(oe=>typeof oe?.id=="string"?oe.id:"").filter(oe=>oe.length>0);x(ce.id,z)},children:t("settings.providers.page.actions.hideAll")}),s.jsx(H,{variant:"outline",size:"xs",className:"!font-normal",onClick:()=>c(ce.id),children:t("settings.providers.page.actions.showAll")})]}),settingsItem:"providers.models",children:[s.jsxs("div",{className:"relative mb-2",children:[s.jsx(_,{name:"search",className:"absolute left-2 top-1/2 -translate-y-1/2 h-3.5 w-3.5 text-muted-foreground"}),s.jsx(He,{value:C,onChange:z=>u(z.target.value),placeholder:t("settings.providers.page.models.filterPlaceholder"),className:"h-7 pl-8 w-full"})]}),ye.length===0?s.jsx("p",{className:"typography-meta text-muted-foreground py-4 text-center",children:t("settings.providers.page.models.noModelsMatchFilter")}):s.jsx("div",{className:"divide-y divide-[var(--surface-subtle)]",children:ye.map(z=>{const oe=typeof z?.id=="string"?z.id:"",me=typeof z?.name=="string"?z.name:oe,ve=oe?i(ce.id,oe):void 0,re=r.some(Ue=>Ue.providerID===ce.id&&Ue.modelID===oe),Ve=ro(ve?.limit?.context),Ze=ro(ve?.limit?.output),B=[];return ve?.tool_call&&B.push({key:"tools",icon:"tools",label:t("settings.providers.page.models.capability.toolCalling")}),ve?.reasoning&&B.push({key:"reasoning",icon:"brain-ai-3",label:t("settings.providers.page.models.capability.reasoning")}),ve?.attachment&&B.push({key:"image",icon:"file-image",label:t("settings.providers.page.models.capability.imageInput")}),s.jsx("div",{className:"py-1.5",children:s.jsxs("div",{className:je("flex items-center gap-3",re&&"opacity-50"),children:[s.jsx("span",{className:"typography-meta font-medium text-foreground truncate flex-1 min-w-0",children:me}),s.jsxs("div",{className:"flex items-center gap-2 flex-shrink-0",children:[(Ve||Ze)&&s.jsxs("span",{className:"typography-micro text-muted-foreground flex-shrink-0 bg-[var(--surface-muted)] px-1.5 py-0.5 rounded",children:[Ve?`${Ve} ${t("settings.providers.page.models.tokenBadge.context")}`:"",Ve&&Ze?" · ":"",Ze?`${Ze} ${t("settings.providers.page.models.tokenBadge.output")}`:""]}),B.length>0&&s.jsx("div",{className:"flex items-center gap-1 flex-shrink-0",children:B.map(({key:Ue,icon:Qe,label:et})=>s.jsx("span",{className:"flex h-5 w-5 rounded items-center justify-center text-muted-foreground bg-[var(--surface-muted)]",title:et,"aria-label":et,children:s.jsx(_,{name:Qe,className:"h-3 w-3"})},Ue))}),s.jsx("button",{type:"button",onClick:()=>l(ce.id,oe),className:"flex h-6 w-6 items-center justify-center rounded text-muted-foreground hover:text-foreground hover:bg-[var(--interactive-hover)]/50",title:t(re?"settings.providers.page.models.actions.showModelInSelectors":"settings.providers.page.models.actions.hideModelFromSelectors"),"aria-label":t(re?"settings.providers.page.models.actions.showModel":"settings.providers.page.models.actions.hideModel"),children:re?s.jsx(_,{name:"eye-off",className:"h-3.5 w-3.5"}):s.jsx(_,{name:"eye",className:"h-3.5 w-3.5"})})]})]})},oe)})})]}):null]})},Ru=t=>{const e=t?.windows??{},a=Object.values(e).map(n=>n.usedPercent).filter(n=>typeof n=="number");return a.length===0?null:Math.max(...a)},Ou=t=>{const e=ht.c(75),{onItemSelect:a}=t,{t:n}=ot(),i=ss(Lu),r=ss(Fu),l=ss(Ku),x=ss(_u),c=ss(zu),y=ss(Uu),m=ss(Vu),b=ss($u);let p,L;e[0]!==b?(p=()=>{b()},L=[b],e[0]=b,e[1]=p,e[2]=L):(p=e[1],L=e[2]),o.useEffect(p,L);const k=Bu;let N;e[3]!==m?(N=te=>{te!=="usage"&&te!=="remaining"||(m(te),k({usageDisplayMode:te}))},e[3]=m,e[4]=N):N=e[4];const h=N;let C;e[5]===Symbol.for("react.memo_cache_sentinel")?(C=je("flex h-full flex-col","bg-background"),e[5]=C):C=e[5];let u;e[6]!==n?(u=n("settings.usage.sidebar.title"),e[6]=n,e[7]=u):u=e[7];let E;e[8]!==u?(E=s.jsx("h2",{className:`${qs} mb-3`,children:u}),e[8]=u,e[9]=E):E=e[9];let q;e[10]!==n?(q=n("settings.usage.sidebar.total",{count:Wa.length}),e[10]=n,e[11]=q):q=e[11];let M;e[12]!==q?(M=s.jsx("span",{className:"typography-meta text-muted-foreground",children:q}),e[12]=q,e[13]=M):M=e[13];let I;e[14]!==x?(I=()=>x(),e[14]=x,e[15]=I):I=e[15];let g;e[16]!==n?(g=n("settings.usage.sidebar.actions.refreshAria"),e[16]=n,e[17]=g):g=e[17];let j;e[18]!==n?(j=n("settings.usage.sidebar.actions.refreshTitle"),e[18]=n,e[19]=j):j=e[19];const F=c&&"animate-spin";let S;e[20]!==F?(S=je("h-3.5 w-3.5",F),e[20]=F,e[21]=S):S=e[21];let T;e[22]!==S?(T=s.jsx(_,{name:"refresh",className:S}),e[22]=S,e[23]=T):T=e[23];let v;e[24]!==c||e[25]!==g||e[26]!==j||e[27]!==T||e[28]!==I?(v=s.jsx("div",{className:"flex items-center gap-2",children:s.jsx(H,{size:"sm",variant:"ghost",className:"h-7 w-7 px-0 text-muted-foreground",onClick:I,"aria-label":g,title:j,disabled:c,children:T})}),e[24]=c,e[25]=g,e[26]=j,e[27]=T,e[28]=I,e[29]=v):v=e[29];let K;e[30]!==v||e[31]!==M?(K=s.jsxs("div",{className:"flex items-center justify-between gap-2",children:[M,v]}),e[30]=v,e[31]=M,e[32]=K):K=e[32];let $;e[33]!==n?($=n("settings.usage.sidebar.field.display"),e[33]=n,e[34]=$):$=e[34];let w;e[35]!==$?(w=s.jsx("span",{className:"typography-micro text-muted-foreground",children:$}),e[35]=$,e[36]=w):w=e[36];let G;e[37]!==n?(G=n("settings.usage.sidebar.field.displayModePlaceholder"),e[37]=n,e[38]=G):G=e[38];let Q;e[39]!==G?(Q=s.jsx(Mt,{className:"w-fit",children:s.jsx(_t,{placeholder:G})}),e[39]=G,e[40]=Q):Q=e[40];let X;e[41]!==n?(X=n("settings.usage.sidebar.field.displayModeUsage"),e[41]=n,e[42]=X):X=e[42];let Z;e[43]!==X?(Z=s.jsx(dt,{value:"usage",children:X}),e[43]=X,e[44]=Z):Z=e[44];let P;e[45]!==n?(P=n("settings.usage.sidebar.field.displayModeRemaining"),e[45]=n,e[46]=P):P=e[46];let ee;e[47]!==P?(ee=s.jsx(dt,{value:"remaining",children:P}),e[47]=P,e[48]=ee):ee=e[48];let se;e[49]!==Z||e[50]!==ee?(se=s.jsxs(Rt,{children:[Z,ee]}),e[49]=Z,e[50]=ee,e[51]=se):se=e[51];let D;e[52]!==h||e[53]!==Q||e[54]!==se||e[55]!==y?(D=s.jsxs(Dt,{value:y,onValueChange:h,children:[Q,se]}),e[52]=h,e[53]=Q,e[54]=se,e[55]=y,e[56]=D):D=e[56];let O;e[57]!==w||e[58]!==D?(O=s.jsxs("div",{className:"mt-2 flex items-center justify-between gap-2",children:[w,D]}),e[57]=w,e[58]=D,e[59]=O):O=e[59];let U;e[60]!==K||e[61]!==O||e[62]!==E?(U=s.jsxs("div",{className:"border-b px-3 pt-4 pb-3",children:[E,K,O]}),e[60]=K,e[61]=O,e[62]=E,e[63]=U):U=e[63];let A;e[64]!==a||e[65]!==i||e[66]!==r||e[67]!==l||e[68]!==n?(A=Wa.map(te=>{const ae=i.find(Ee=>Ee.providerId===te.id),le=Ru(ae?.usage),be=Jl(le),ke=te.id===r,ce=ae?.configured??!1,ge=ce?be==="critical"?{backgroundColor:"var(--status-error)"}:be==="warn"?{backgroundColor:"var(--status-warning)"}:{backgroundColor:"var(--status-success)"}:{backgroundColor:"var(--surface-muted-foreground)",opacity:.4};return s.jsx("div",{className:je("group relative flex items-center rounded-md px-1.5 py-1 transition-all duration-200",ke?"bg-interactive-selection":"hover:bg-interactive-hover"),children:s.jsxs("button",{type:"button",onClick:()=>{l(te.id),a?.()},className:"flex min-w-0 flex-1 items-center gap-2 rounded-sm text-left focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-primary/50",children:[s.jsx("span",{className:"h-2.5 w-2.5 rounded-full flex-shrink-0",style:ge}),s.jsx(Pn,{providerId:te.id,className:"h-4 w-4 flex-shrink-0"}),s.jsx("span",{className:"typography-ui-label font-normal truncate flex-1 min-w-0 text-foreground",children:te.name}),!ce&&s.jsx("span",{className:"typography-micro text-muted-foreground/60 flex-shrink-0",children:n("settings.usage.sidebar.status.notSet")})]})},te.id)}),e[64]=a,e[65]=i,e[66]=r,e[67]=l,e[68]=n,e[69]=A):A=e[69];let V;e[70]!==A?(V=s.jsx(Ds,{outerClassName:"flex-1 min-h-0",className:"space-y-1 px-3 py-2 overflow-x-hidden",children:A}),e[70]=A,e[71]=V):V=e[71];let W;return e[72]!==U||e[73]!==V?(W=s.jsxs("div",{className:C,children:[U,V]}),e[72]=U,e[73]=V,e[74]=W):W=e[74],W};function Lu(t){return t.results}function Fu(t){return t.selectedProviderId}function Ku(t){return t.setSelectedProvider}function _u(t){return t.fetchAllQuotas}function zu(t){return t.isLoading}function Uu(t){return t.displayMode}function Vu(t){return t.setDisplayMode}function $u(t){return t.loadSettings}async function Bu(t){try{await yt(t)}catch(e){console.warn("Failed to save usage settings:",e)}}const Ci=t=>{const e=ht.c(44),{title:a,window:n,subtitle:i,showToggle:r,toggleEnabled:l,onToggle:x}=t,c=r===void 0?!1:r,y=l===void 0?!1:l,m=ss(Hu),b=de(Gu),p=m==="remaining"?n.remainingPercent:n.usedPercent,L=m==="remaining"?"remaining":"used";let k;e[0]!==p||e[1]!==n.valueLabel?(k=Ql(n.valueLabel,p),e[0]=p,e[1]=n.valueLabel,e[2]=k):k=e[2];const N=k,h=n.resetAfterFormatted??n.resetAtFormatted;let C;e[3]!==h||e[4]!==b||e[5]!==n.resetAt?(C=Yl(n.resetAt,h,b),e[3]=h,e[4]=b,e[5]=n.resetAt,e[6]=C):C=e[6];const u=C;let E;e[7]!==a?(E=Zl(a),e[7]=a,e[8]=E):E=e[8];const q=E;let M;e[9]!==x||e[10]!==c||e[11]!==y?(M=c&&s.jsx(Li,{checked:y,onChange:P=>x?.(P),ariaLabel:"Show in dropdown"}),e[9]=x,e[10]=c,e[11]=y,e[12]=M):M=e[12];let I;e[13]!==q?(I=s.jsx("span",{className:"typography-ui-label text-foreground truncate",children:q}),e[13]=q,e[14]=I):I=e[14];let g;e[15]!==i?(g=i&&s.jsx("span",{className:"typography-meta text-muted-foreground truncate",children:i}),e[15]=i,e[16]=g):g=e[16];let j;e[17]!==I||e[18]!==g?(j=s.jsxs("div",{className:"min-w-0 flex flex-col",children:[I,g]}),e[17]=I,e[18]=g,e[19]=j):j=e[19];let F;e[20]!==j||e[21]!==M?(F=s.jsxs("div",{className:"min-w-0 flex-1 flex items-center gap-2",children:[M,j]}),e[20]=j,e[21]=M,e[22]=F):F=e[22];const S=N==="-"?"":N;let T;e[23]!==S?(T=s.jsx("div",{className:"typography-ui-label text-foreground tabular-nums flex items-center justify-end",children:S}),e[23]=S,e[24]=T):T=e[24];let v;e[25]!==F||e[26]!==T?(v=s.jsxs("div",{className:"flex items-center justify-between gap-3",children:[F,T]}),e[25]=F,e[26]=T,e[27]=v):v=e[27];let K;e[28]!==p||e[29]!==n.usedPercent?(K=s.jsx(Zc,{percent:p,tonePercent:n.usedPercent,className:"h-1.5"}),e[28]=p,e[29]=n.usedPercent,e[30]=K):K=e[30];const $=u?`Resets ${u}`:"";let w;e[31]!==$?(w=s.jsx("span",{className:"typography-micro text-muted-foreground",children:$}),e[31]=$,e[32]=w):w=e[32];let G;e[33]!==L?(G=s.jsx("span",{className:"typography-micro text-muted-foreground",children:L}),e[33]=L,e[34]=G):G=e[34];let Q;e[35]!==w||e[36]!==G?(Q=s.jsxs("div",{className:"mt-1 flex items-center justify-between",children:[w,G]}),e[35]=w,e[36]=G,e[37]=Q):Q=e[37];let X;e[38]!==K||e[39]!==Q?(X=s.jsxs("div",{className:"mt-2.5",children:[K,Q]}),e[38]=K,e[39]=Q,e[40]=X):X=e[40];let Z;return e[41]!==v||e[42]!==X?(Z=s.jsxs("div",{className:"py-3",children:[v,X]}),e[41]=v,e[42]=X,e[43]=Z):Z=e[43],Z};function Hu(t){return t.displayMode}function Gu(t){return t.timeFormatPreference}const qu=({providerId:t,providerName:e})=>{const{t:a}=ot(),[n,i]=o.useState(null),[r,l]=o.useState({}),[x,c]=o.useState(!1),y=`/api/quota/credentials/${t}`;o.useEffect(()=>{ct(y).then(async p=>{if(!p.ok)throw new Error;const L=await p.json();i(L),l({})}).catch(()=>i({configured:!1}))},[y]);const m=async(p,L,k)=>{c(!0);try{const N=await ct(p,{method:L,headers:k?{"Content-Type":"application/json"}:void 0,body:k?JSON.stringify(k):void 0}),h=await N.json().catch(()=>null);if(!N.ok)throw new Error(h?.error);h?.configured!==void 0&&i(h),l({}),R.success(a("settings.providers.page.quotaCredentials.saved",{provider:e}))}catch(N){R.error(N instanceof Error&&N.message?N.message:a("settings.providers.page.openCodeGo.saveFailed"))}finally{c(!1)}},b=(p,L,k)=>s.jsxs("label",{className:"block typography-ui-label text-foreground",children:[L,s.jsx(He,{className:"mt-1 h-7 font-mono text-xs",type:"password",autoComplete:"off",value:r[p]??"",onChange:N=>l(h=>({...h,[p]:N.target.value})),placeholder:n?.secretMasked??k})]});return s.jsxs("div",{"data-settings-item":`usage.${t}-credentials`,className:"mb-8",children:[s.jsx("div",{className:"mb-1 px-1",children:s.jsx("h3",{className:"typography-ui-header font-medium text-foreground",children:e})}),s.jsxs("section",{className:"space-y-3 px-2 pb-2 pt-0",children:[t==="ollama-cloud"&&b("cookie",a("settings.providers.page.openCodeGo.authCookie"),"session=..."),t==="cursor"&&b("accessToken",a("settings.providers.page.quotaCredentials.accessToken"),a("settings.providers.page.quotaCredentials.tokenPlaceholder")),t==="cursor"&&b("refreshToken",a("settings.providers.page.quotaCredentials.refreshToken"),a("settings.providers.page.quotaCredentials.tokenPlaceholder")),s.jsxs("div",{className:"flex flex-wrap gap-2",children:[s.jsx(H,{size:"xs",disabled:x,onClick:()=>m(y,"PUT",r),children:n?.configured?a("settings.providers.page.openCodeGo.replace"):a("settings.providers.page.openCodeGo.save")}),n?.configured&&s.jsx(H,{variant:"outline",size:"xs",disabled:x,onClick:()=>m(`${y}/validate`,"POST"),children:a("settings.providers.page.openCodeGo.validate")}),t==="cursor"&&s.jsx(H,{variant:"outline",size:"xs",disabled:x,onClick:()=>m(`${y}/import`,"POST"),children:a("settings.providers.page.actions.connect")}),n?.configured&&s.jsx(H,{variant:"destructive",size:"xs",disabled:x,onClick:()=>m(y,"DELETE"),children:a("settings.providers.page.openCodeGo.delete")})]})]})]})},Wu=(t,e)=>{if(!t)return"-";try{return Oo(t,e,{fallback:"-"})}catch{return"-"}},Ju=()=>{const{t}=ot(),e=de(w=>w.timeFormatPreference),a=ss(w=>w.results),n=ss(w=>w.selectedProviderId),i=ss(w=>w.setSelectedProvider),r=ss(w=>w.loadSettings),l=ss(w=>w.fetchAllQuotas),x=ss(w=>w.isLoading),c=ss(w=>w.lastUpdated),y=ss(w=>w.error),m=ss(w=>w.dropdownProviderIds),b=ss(w=>w.setDropdownProviderIds),p=ss(w=>w.selectedModels),L=ss(w=>w.toggleModelSelected),k=ss(w=>w.applyDefaultSelections);Xl(),o.useEffect(()=>{r(),l()},[r,l]),o.useEffect(()=>{if(n||a.length===0)return;const w=a.find(G=>G.configured)?.providerId;i(w??Wa[0]?.id??null)},[a,n,i]);const N=a.find(w=>w.providerId===n)??null,C=Wa.find(w=>w.id===n)?.name??n??t("settings.usage.sidebar.title"),u=N?.usage,E=N?.configured&&!N.ok?N.error:null,q=n?m.includes(n):!1,M=n==="ollama-cloud"||n==="cursor",I=o.useCallback(w=>{if(!n)return;const G=w?Array.from(new Set([...m,n])):m.filter(Q=>Q!==n);b(G),yt({usageDropdownProviders:G})},[m,n,b]),g=o.useMemo(()=>u?.models?Object.entries(u.models).map(([w,G])=>({name:w,windows:G})).filter(w=>Object.keys(w.windows.windows).length>0):[],[u?.models]);o.useEffect(()=>{n&&g.length>0&&k(n,g.map(w=>w.name))},[n,g,k]);const j=o.useMemo(()=>!n||g.length===0?new Map:ec(g,w=>w.name,n),[g,n]),F=o.useMemo(()=>{if(!n)return[];const w=sc(n);return tc(w)},[n]),[S,T]=o.useState(()=>({})),v=o.useCallback(w=>{T(G=>({...G,[w]:!G[w]}))},[]),K=o.useCallback(w=>{if(!n)return;L(n,w);const G=p[n]??[],X=G.includes(w)?G.filter(P=>P!==w):[...G,w],Z={...p,[n]:X};yt({usageSelectedModels:Z})},[n,p,L]),$=n?p[n]??[]:[];return n?s.jsxs(rs,{title:t("settings.usage.page.header.providerUsage",{provider:C}),titleLeading:s.jsx(Pn,{providerId:n,className:"h-5 w-5 shrink-0"}),description:x?s.jsx("span",{className:"animate-pulse typography-settings-description text-muted-foreground",children:t("settings.usage.page.header.refreshing")}):t("settings.usage.page.header.lastUpdated",{time:Wu(c,e)}),showSaveStatus:!0,children:[s.jsx(Oe,{divider:!1,settingsItem:"usage.work-status-panel",children:s.jsx(ut,{checked:q,onChange:I,label:t("settings.usage.page.options.showInWorkStatus"),ariaLabel:t("settings.usage.page.options.showInWorkStatusAria"),info:t("settings.usage.page.options.showInWorkStatusTooltip")})}),!N&&s.jsx("p",{className:"typography-ui-label text-foreground pb-8",children:t("settings.usage.page.state.noData")}),(y||E)&&s.jsxs("div",{className:"mb-8 rounded-lg border border-[var(--status-error-border)] bg-[var(--status-error-background)] px-4 py-3",children:[s.jsx("p",{className:"typography-ui-label font-medium text-[var(--status-error)]",children:t("settings.usage.page.state.refreshFailedTitle")}),s.jsx("p",{className:"typography-meta text-[var(--status-error)]/80 mt-1",children:y??E})]}),N&&!N.configured&&!M&&s.jsxs("div",{className:"mb-8 rounded-lg border border-[var(--status-warning-border)] bg-[var(--status-warning-background)] px-4 py-3",children:[s.jsx("p",{className:"typography-ui-label font-medium text-[var(--status-warning)]",children:t("settings.usage.page.state.providerNotConfiguredTitle")}),s.jsx("p",{className:"typography-meta text-[var(--status-warning)]/80 mt-1",children:t("settings.usage.page.state.providerNotConfiguredDescription")})]}),(n==="ollama-cloud"||n==="cursor")&&s.jsx(qu,{providerId:n,providerName:C}),u?.windows&&Object.keys(u.windows).length>0&&s.jsx(Oe,{settingsItem:"usage.model-quotas",children:s.jsx("div",{className:"divide-y divide-[var(--surface-subtle)]",children:Object.entries(u.windows).map(([w,G])=>s.jsx(Ci,{title:w,window:G},w))})}),g.length>0&&s.jsxs(Oe,{title:t("settings.usage.page.section.modelQuotas"),contentClassName:"space-y-3",children:[F.map(w=>{const G=j.get(w.id)??[];if(G.length===0)return null;const Q=S[w.id]??!1;return s.jsx("section",{className:"p-2",children:s.jsxs(ba,{open:!Q,onOpenChange:()=>v(w.id),children:[s.jsxs(va,{className:"flex w-full items-center justify-between py-0.5 group",children:[s.jsxs("div",{className:"flex items-center gap-1.5 text-left",children:[s.jsx("span",{className:"typography-ui-label font-normal text-foreground",children:w.label}),s.jsxs("span",{className:"typography-micro text-muted-foreground",children:["(",G.length,")"]})]}),Q?s.jsx(_,{name:"arrow-right-s",className:"h-4 w-4 text-muted-foreground group-hover:text-foreground transition-colors"}):s.jsx(_,{name:"arrow-down-s",className:"h-4 w-4 text-muted-foreground group-hover:text-foreground transition-colors"})]}),s.jsx(ya,{children:s.jsx("div",{className:"divide-y divide-[var(--surface-subtle)] mt-1",children:G.map(X=>{const Z=Object.entries(X.windows.windows);if(Z.length===0)return null;const[P,ee]=Z[0],se=$.includes(X.name);return s.jsx(Ci,{title:P,subtitle:cr(X.name),window:ee,showToggle:!0,toggleEnabled:se,onToggle:()=>K(X.name)},X.name)})})})]})},w.id)}),(()=>{const w=j.get(null)??[];if(w.length===0)return null;const G=S.other??!1;return s.jsx("section",{className:"p-2",children:s.jsxs(ba,{open:!G,onOpenChange:()=>v("other"),children:[s.jsxs(va,{className:"flex w-full items-center justify-between py-0.5 group",children:[s.jsxs("div",{className:"flex items-center gap-1.5 text-left",children:[s.jsx("span",{className:"typography-ui-label font-normal text-foreground",children:t("settings.usage.page.section.otherModels")}),s.jsxs("span",{className:"typography-micro text-muted-foreground",children:["(",w.length,")"]})]}),G?s.jsx(_,{name:"arrow-right-s",className:"h-4 w-4 text-muted-foreground group-hover:text-foreground transition-colors"}):s.jsx(_,{name:"arrow-down-s",className:"h-4 w-4 text-muted-foreground group-hover:text-foreground transition-colors"})]}),s.jsx(ya,{children:s.jsx("div",{className:"divide-y divide-[var(--surface-subtle)] mt-1",children:w.map(Q=>{const X=Object.entries(Q.windows.windows);if(X.length===0)return null;const[Z,P]=X[0],ee=$.includes(Q.name);return s.jsx(Ci,{title:Z,subtitle:cr(Q.name),window:P,showToggle:!0,toggleEnabled:ee,onToggle:()=>K(Q.name)},Q.name)})})})]})})})()]}),N?.configured&&u&&Object.keys(u.windows??{}).length===0&&g.length===0&&s.jsxs("div",{className:"pb-8",children:[s.jsx("p",{className:"typography-ui-label text-foreground",children:t("settings.usage.page.state.noQuotaWindowsTitle")}),s.jsx("p",{className:"typography-meta text-muted-foreground mt-1",children:t("settings.usage.page.state.noQuotaWindowsDescription")})]})]}):s.jsx("div",{className:"flex h-full items-center justify-center text-muted-foreground",children:s.jsx("p",{className:"typography-body",children:t("settings.usage.page.empty.selectProvider")})})},Qu="git.commit.generate",Hi=Ho(t=>({selectedPromptId:Qu,setSelectedPromptId:e=>{t(a=>a.selectedPromptId===e?a:{selectedPromptId:e})}})),Yu=t=>{const e=ht.c(23),{onItemSelect:a}=t,{t:n}=ot(),i=Hi(Zu),r=Hi(Xu);let l;e[0]===Symbol.for("react.memo_cache_sentinel")?(l={groupKey:"settings.magicPrompts.sidebar.group.git",items:[{id:"git.commit.generate",titleKey:"settings.magicPrompts.sidebar.item.gitCommitGenerate"},{id:"git.pr.generate",titleKey:"settings.magicPrompts.sidebar.item.gitPrGenerate"},{id:"git.conflict.resolve",titleKey:"settings.magicPrompts.sidebar.item.gitConflictResolve"},{id:"git.integrate.cherrypick.resolve",titleKey:"settings.magicPrompts.sidebar.item.gitCherrypickConflictResolve"}]},e[0]=l):l=e[0];let x;e[1]===Symbol.for("react.memo_cache_sentinel")?(x={groupKey:"settings.magicPrompts.sidebar.group.github",items:[{id:"github.pr.review",titleKey:"settings.magicPrompts.sidebar.item.githubPrReview"},{id:"github.issue.review",titleKey:"settings.magicPrompts.sidebar.item.githubIssueReview"},{id:"github.pr.checks.review",titleKey:"settings.magicPrompts.sidebar.item.githubPrFailedChecksReview"},{id:"github.pr.comments.review",titleKey:"settings.magicPrompts.sidebar.item.githubPrCommentsReview"},{id:"github.pr.comment.single",titleKey:"settings.magicPrompts.sidebar.item.githubSinglePrCommentReview"}]},e[1]=x):x=e[1];let c;e[2]===Symbol.for("react.memo_cache_sentinel")?(c={groupKey:"settings.magicPrompts.sidebar.group.planning",items:[{id:"plan.todo",titleKey:"settings.magicPrompts.sidebar.item.planTodo"},{id:"plan.improve",titleKey:"settings.magicPrompts.sidebar.item.planImprove"},{id:"plan.implement",titleKey:"settings.magicPrompts.sidebar.item.planImplement"}]},e[2]=c):c=e[2];let y;e[3]===Symbol.for("react.memo_cache_sentinel")?(y=[l,x,c,{groupKey:"settings.magicPrompts.sidebar.group.session",items:[{id:"session.explore",titleKey:"settings.magicPrompts.sidebar.item.sessionExplore"},{id:"session.summary",titleKey:"settings.magicPrompts.sidebar.item.sessionSummary"},{id:"session.review",titleKey:"settings.magicPrompts.sidebar.item.sessionWorkspaceReview"},{id:"session.plan",titleKey:"settings.magicPrompts.sidebar.item.sessionFeaturePlan"},{id:"session.craftGoal",titleKey:"settings.magicPrompts.sidebar.item.sessionCraftGoal"},{id:"session.catchup",titleKey:"settings.magicPrompts.sidebar.item.sessionCatchUp"},{id:"session.debug",titleKey:"settings.magicPrompts.sidebar.item.sessionDebug"},{id:"session.weigh",titleKey:"settings.magicPrompts.sidebar.item.sessionWeigh"},{id:"session.fusion",titleKey:"settings.magicPrompts.sidebar.item.sessionFusion"}]}],e[3]=y):y=e[3];const m=y;let b;e[4]!==n?(b=n("settings.magicPrompts.sidebar.title"),e[4]=n,e[5]=b):b=e[5];let p;e[6]!==b?(p=s.jsx("h2",{className:qs,children:b}),e[6]=b,e[7]=p):p=e[7];let L;e[8]!==n?(L=n("settings.magicPrompts.sidebar.description"),e[8]=n,e[9]=L):L=e[9];let k;e[10]!==L?(k=s.jsx("p",{className:"typography-meta mt-1 text-muted-foreground",children:L}),e[10]=L,e[11]=k):k=e[11];let N;e[12]!==p||e[13]!==k?(N=s.jsxs("div",{className:"border-b px-3 pt-4 pb-3",children:[p,k]}),e[12]=p,e[13]=k,e[14]=N):N=e[14];let h;e[15]!==a||e[16]!==i||e[17]!==r||e[18]!==n?(h=s.jsx(Ds,{outerClassName:"flex-1 min-h-0",className:"space-y-3 px-3 py-2 overflow-x-hidden",children:m.map(u=>s.jsxs("div",{className:"space-y-1",children:[s.jsx("div",{className:"typography-micro px-1 text-muted-foreground",children:n(u.groupKey)}),u.items.map(E=>{const q=i===E.id;return s.jsx("button",{type:"button",onClick:()=>{r(E.id),a?.()},className:je("flex w-full items-center rounded-md px-2 py-1.5 text-left transition-colors",q?"bg-interactive-selection text-foreground":"text-foreground hover:bg-interactive-hover"),children:s.jsx("span",{className:"typography-ui-label truncate font-normal",children:n(E.titleKey)})},E.id)})]},u.groupKey))}),e[15]=a,e[16]=i,e[17]=r,e[18]=n,e[19]=h):h=e[19];let C;return e[20]!==h||e[21]!==N?(C=s.jsxs("div",{className:"flex h-full flex-col bg-background",children:[N,h]}),e[20]=h,e[21]=N,e[22]=C):C=e[22],C};function Zu(t){return t.selectedPromptId}function Xu(t){return t.setSelectedPromptId}const lo={"git.commit.generate":{titleKey:"settings.magicPrompts.page.group.gitCommitGenerate.title",descriptionKey:"settings.magicPrompts.page.group.gitCommitGenerate.description",blocks:[{id:"git.commit.generate.visible",titleKey:"settings.magicPrompts.page.block.visiblePrompt"},{id:"git.commit.generate.instructions",titleKey:"settings.magicPrompts.page.block.instructions"}]},"git.pr.generate":{titleKey:"settings.magicPrompts.page.group.gitPrGenerate.title",descriptionKey:"settings.magicPrompts.page.group.gitPrGenerate.description",blocks:[{id:"git.pr.generate.visible",titleKey:"settings.magicPrompts.page.block.visiblePrompt"},{id:"git.pr.generate.instructions",titleKey:"settings.magicPrompts.page.block.instructions"}]},"github.pr.review":{titleKey:"settings.magicPrompts.page.group.githubPrReview.title",descriptionKey:"settings.magicPrompts.page.group.githubPrReview.description",blocks:[{id:"github.pr.review.visible",titleKey:"settings.magicPrompts.page.block.visiblePrompt"},{id:"github.pr.review.instructions",titleKey:"settings.magicPrompts.page.block.instructions"}]},"github.issue.review":{titleKey:"settings.magicPrompts.page.group.githubIssueReview.title",descriptionKey:"settings.magicPrompts.page.group.githubIssueReview.description",blocks:[{id:"github.issue.review.visible",titleKey:"settings.magicPrompts.page.block.visiblePrompt"},{id:"github.issue.review.instructions",titleKey:"settings.magicPrompts.page.block.instructions"}]},"github.pr.checks.review":{titleKey:"settings.magicPrompts.page.group.githubPrFailedChecksReview.title",descriptionKey:"settings.magicPrompts.page.group.githubPrFailedChecksReview.description",blocks:[{id:"github.pr.checks.review.visible",titleKey:"settings.magicPrompts.page.block.visiblePrompt"},{id:"github.pr.checks.review.instructions",titleKey:"settings.magicPrompts.page.block.instructions"}]},"github.pr.comments.review":{titleKey:"settings.magicPrompts.page.group.githubPrCommentsReview.title",descriptionKey:"settings.magicPrompts.page.group.githubPrCommentsReview.description",blocks:[{id:"github.pr.comments.review.visible",titleKey:"settings.magicPrompts.page.block.visiblePrompt"},{id:"github.pr.comments.review.instructions",titleKey:"settings.magicPrompts.page.block.instructions"}]},"github.pr.comment.single":{titleKey:"settings.magicPrompts.page.group.githubSinglePrCommentReview.title",descriptionKey:"settings.magicPrompts.page.group.githubSinglePrCommentReview.description",blocks:[{id:"github.pr.comment.single.visible",titleKey:"settings.magicPrompts.page.block.visiblePrompt"},{id:"github.pr.comment.single.instructions",titleKey:"settings.magicPrompts.page.block.instructions"}]},"git.conflict.resolve":{titleKey:"settings.magicPrompts.page.group.gitConflictResolve.title",descriptionKey:"settings.magicPrompts.page.group.gitConflictResolve.description",blocks:[{id:"git.conflict.resolve.visible",titleKey:"settings.magicPrompts.page.block.visiblePrompt"},{id:"git.conflict.resolve.instructions",titleKey:"settings.magicPrompts.page.block.instructions"}]},"git.integrate.cherrypick.resolve":{titleKey:"settings.magicPrompts.page.group.gitCherrypickConflictResolve.title",descriptionKey:"settings.magicPrompts.page.group.gitCherrypickConflictResolve.description",blocks:[{id:"git.integrate.cherrypick.resolve.visible",titleKey:"settings.magicPrompts.page.block.visiblePrompt"},{id:"git.integrate.cherrypick.resolve.instructions",titleKey:"settings.magicPrompts.page.block.instructions"}]},"plan.improve":{titleKey:"settings.magicPrompts.page.group.planImprove.title",descriptionKey:"settings.magicPrompts.page.group.planImprove.description",blocks:[{id:"plan.improve.visible",titleKey:"settings.magicPrompts.page.block.visiblePrompt"},{id:"plan.improve.instructions",titleKey:"settings.magicPrompts.page.block.instructions"}]},"plan.todo":{titleKey:"settings.magicPrompts.page.group.planTodo.title",descriptionKey:"settings.magicPrompts.page.group.planTodo.description",blocks:[{id:"plan.todo.visible",titleKey:"settings.magicPrompts.page.block.visiblePrompt"},{id:"plan.todo.instructions",titleKey:"settings.magicPrompts.page.block.instructions"}]},"plan.implement":{titleKey:"settings.magicPrompts.page.group.planImplement.title",descriptionKey:"settings.magicPrompts.page.group.planImplement.description",blocks:[{id:"plan.implement.visible",titleKey:"settings.magicPrompts.page.block.visiblePrompt"},{id:"plan.implement.instructions",titleKey:"settings.magicPrompts.page.block.instructions"}]},"session.summary":{titleKey:"settings.magicPrompts.page.group.sessionSummary.title",descriptionKey:"settings.magicPrompts.page.group.sessionSummary.description",blocks:[{id:"session.summary.visible",titleKey:"settings.magicPrompts.page.block.visiblePrompt"},{id:"session.summary.instructions",titleKey:"settings.magicPrompts.page.block.instructions"}]},"session.review":{titleKey:"settings.magicPrompts.page.group.sessionWorkspaceReview.title",descriptionKey:"settings.magicPrompts.page.group.sessionWorkspaceReview.description",blocks:[{id:"session.review.visible",titleKey:"settings.magicPrompts.page.block.visiblePrompt"},{id:"session.review.instructions",titleKey:"settings.magicPrompts.page.block.instructions"}]},"session.plan":{titleKey:"settings.magicPrompts.page.group.sessionFeaturePlan.title",descriptionKey:"settings.magicPrompts.page.group.sessionFeaturePlan.description",blocks:[{id:"session.plan.visible",titleKey:"settings.magicPrompts.page.block.visiblePrompt"},{id:"session.plan.instructions",titleKey:"settings.magicPrompts.page.block.instructions"}]},"session.craftGoal":{titleKey:"settings.magicPrompts.page.group.sessionCraftGoal.title",descriptionKey:"settings.magicPrompts.page.group.sessionCraftGoal.description",blocks:[{id:"session.craftGoal.visible",titleKey:"settings.magicPrompts.page.block.visiblePrompt"},{id:"session.craftGoal.instructions",titleKey:"settings.magicPrompts.page.block.instructions"}]},"session.catchup":{titleKey:"settings.magicPrompts.page.group.sessionCatchUp.title",descriptionKey:"settings.magicPrompts.page.group.sessionCatchUp.description",blocks:[{id:"session.catchup.visible",titleKey:"settings.magicPrompts.page.block.visiblePrompt"},{id:"session.catchup.instructions",titleKey:"settings.magicPrompts.page.block.instructions"}]},"session.debug":{titleKey:"settings.magicPrompts.page.group.sessionDebug.title",descriptionKey:"settings.magicPrompts.page.group.sessionDebug.description",blocks:[{id:"session.debug.visible",titleKey:"settings.magicPrompts.page.block.visiblePrompt"},{id:"session.debug.instructions",titleKey:"settings.magicPrompts.page.block.instructions"}]},"session.weigh":{titleKey:"settings.magicPrompts.page.group.sessionWeigh.title",descriptionKey:"settings.magicPrompts.page.group.sessionWeigh.description",blocks:[{id:"session.weigh.visible",titleKey:"settings.magicPrompts.page.block.visiblePrompt"},{id:"session.weigh.instructions",titleKey:"settings.magicPrompts.page.block.instructions"}]},"session.explore":{titleKey:"settings.magicPrompts.page.group.sessionExplore.title",descriptionKey:"settings.magicPrompts.page.group.sessionExplore.description",blocks:[{id:"session.explore.visible",titleKey:"settings.magicPrompts.page.block.visiblePrompt"},{id:"session.explore.instructions",titleKey:"settings.magicPrompts.page.block.instructions"}]},"session.fusion":{titleKey:"settings.magicPrompts.page.group.sessionFusion.title",descriptionKey:"settings.magicPrompts.page.group.sessionFusion.description",blocks:[{id:"session.fusion.visible",titleKey:"settings.magicPrompts.page.block.visiblePrompt"},{id:"session.fusion.instructions",titleKey:"settings.magicPrompts.page.block.instructions"}]}},co=(t,e)=>Object.prototype.hasOwnProperty.call(t,e),Ii=t=>t.endsWith(".visible"),eg=()=>{const{t}=ot(),e=o.useCallback(I=>t(I),[t]),a=Hi(I=>I.selectedPromptId),[n,i]=o.useState(!0),[r,l]=o.useState({}),[x,c]=o.useState({}),[y,m]=o.useState({}),[b,p]=o.useState({}),[L,k]=o.useState(!1);o.useEffect(()=>{let I=!0;return(async()=>{i(!0);try{const j=await rc();if(!I)return;l(j)}catch(j){console.warn("Failed to load magic prompts:",j),R.error(t("settings.magicPrompts.page.toast.loadFailed"))}finally{I&&i(!1)}})(),()=>{I=!1}},[t]);const N=lo[a]??lo["git.commit.generate"],h=o.useCallback(I=>co(r,I)?r[I]:gi(I),[r]),C=o.useCallback(I=>x[I]??h(I),[x,h]),u=o.useCallback((I,g)=>{c(j=>j[I]===g?j:{...j,[I]:g})},[]),E=o.useCallback(async I=>{const g=C(I);if(Ii(I)&&g.trim().length===0){R.error(t("settings.magicPrompts.page.toast.visiblePromptRequired"));return}m(j=>({...j,[I]:!0}));try{const j=g===gi(I)?await dr(I):await nc(I,g);l(j.overrides),R.success(t("settings.magicPrompts.page.toast.saved"))}catch(j){const F=j instanceof Error?j.message:String(j);R.error(t("settings.magicPrompts.page.toast.saveFailed"),{description:F})}finally{m(j=>({...j,[I]:!1}))}},[C,t]),q=o.useCallback(async I=>{p(g=>({...g,[I]:!0}));try{const g=await dr(I);l(g.overrides),c(j=>({...j,[I]:gi(I)})),R.success(t("settings.magicPrompts.page.toast.resetSuccess"))}catch(g){const j=g instanceof Error?g.message:String(g);R.error(t("settings.magicPrompts.page.toast.resetFailed"),{description:j})}finally{p(g=>({...g,[I]:!1}))}},[t]),M=o.useCallback(async()=>{k(!0);try{const I=await ac();l(I.overrides),c({}),R.success(t("settings.magicPrompts.page.toast.resetAllSuccess"))}catch(I){const g=I instanceof Error?I.message:String(I);R.error(t("settings.magicPrompts.page.toast.resetAllFailed"),{description:g})}finally{k(!1)}},[t]);return n?s.jsxs("div",{className:"py-6 px-6 flex items-center gap-2 text-muted-foreground",children:[s.jsx("span",{className:"inline-block h-1.5 w-1.5 rounded-full bg-current animate-busy-pulse","aria-label":t("settings.magicPrompts.page.loading.aria")}),s.jsx("span",{className:"typography-ui",children:t("settings.magicPrompts.page.loading.text")})]}):s.jsx(rs,{title:e(N.titleKey),titleAccessory:s.jsx(Yt,{contentClassName:"max-w-xs",children:e(N.descriptionKey)}),headerEnd:s.jsx(H,{"data-settings-item":"magic-prompts.reset-overrides",variant:"outline",size:"sm",onClick:()=>{M()},disabled:L||Object.keys(r).length===0,children:t(L?"settings.magicPrompts.page.actions.resetting":"settings.magicPrompts.page.actions.resetAllOverrides")}),showSaveStatus:!1,children:N.blocks.map((I,g)=>{const j=ic(I.id),F=h(I.id),S=C(I.id),T=co(r,I.id),v=S!==F,K=Ii(I.id)&&S.trim().length===0,$=y[I.id]===!0,w=b[I.id]===!0;return s.jsxs(Oe,{title:e(I.titleKey),info:j.description,description:j.placeholders&&j.placeholders.length>0?`${t("settings.magicPrompts.page.placeholdersLabel")} ${j.placeholders.map(G=>`{{${G.key}}}`).join(", ")}`:void 0,divider:g>0,settingsItem:Ii(I.id)?"magic-prompts.visible-prompt":"magic-prompts.instructions",contentClassName:"space-y-3",children:[s.jsx(Ns,{value:S,onChange:G=>u(I.id,G.target.value),className:"min-h-[220px] font-mono text-sm"}),K&&s.jsx("div",{className:"typography-micro text-[var(--status-error)]",children:t("settings.magicPrompts.page.validation.visiblePromptRequired")}),s.jsxs("div",{className:"flex items-center justify-between gap-2",children:[s.jsx("span",{className:"typography-micro text-muted-foreground",children:t(v?"settings.magicPrompts.page.status.unsavedChanges":T?"settings.magicPrompts.page.status.usingSavedOverride":"settings.magicPrompts.page.status.usingBuiltinDefault")}),s.jsxs("div",{className:"flex items-center gap-2",children:[s.jsx(H,{variant:"outline",size:"sm",onClick:()=>{q(I.id)},disabled:!T||$||w,children:t(w?"settings.magicPrompts.page.actions.resetting":"settings.magicPrompts.page.actions.resetToDefault")}),s.jsx(H,{size:"sm",onClick:()=>{E(I.id)},disabled:!v||$||w||K,children:t($?"settings.common.actions.saving":"settings.magicPrompts.page.actions.save")})]})]})]},I.id)})})},tg=t=>{const e=ht.c(89),{onItemSelect:a}=t,{t:n}=ot(),[i,r]=o.useState(null),[l,x]=o.useState(null),[c,y]=o.useState(null),{selectedSnippetName:m,snippets:b,setSelectedSnippet:p,setSnippetDraft:L,deleteSnippet:k,loadSnippets:N}=Za(Ps(sg));let h,C;e[0]!==N?(h=()=>{N()},C=[N],e[0]=N,e[1]=h,e[2]=C):(h=e[1],C=e[2]),o.useEffect(h,C);let u;e[3]!==a||e[4]!==p||e[5]!==L||e[6]!==b?(u=async()=>{const Se=new Set(b.map(ng));let Ne="new-snippet",fe=1;for(;Se.has(Ne);)Ne=`new-snippet-${fe++}`;L({name:Ne,scope:"global"}),p(Ne),a?.()},e[3]=a,e[4]=p,e[5]=L,e[6]=b,e[7]=u):u=e[7];const E=u;let q;e[8]!==i||e[9]!==k||e[10]!==n?(q=async()=>{if(!i)return;await k(i.name)?(R.success(n("settings.snippets.sidebar.toast.deleted")),r(null)):R.error(n("settings.snippets.sidebar.toast.deleteFailed"))},e[8]=i,e[9]=k,e[10]=n,e[11]=q):q=e[11];const M=q;let I;e[12]!==b?(I=[...b].sort(ag),e[12]=b,e[13]=I):I=e[13];const g=I;let j;e[14]===Symbol.for("react.memo_cache_sentinel")?(j=je("flex h-full flex-col","bg-background"),e[14]=j):j=e[14];let F;e[15]!==n?(F=n("settings.snippets.sidebar.title"),e[15]=n,e[16]=F):F=e[16];let S;e[17]!==F?(S=s.jsx("h2",{className:`${qs} mb-3`,children:F}),e[17]=F,e[18]=S):S=e[18];let T;e[19]!==b.length||e[20]!==n?(T=n("settings.snippets.sidebar.total",{count:b.length}),e[19]=b.length,e[20]=n,e[21]=T):T=e[21];let v;e[22]!==T?(v=s.jsx("span",{className:"typography-meta text-muted-foreground",children:T}),e[22]=T,e[23]=v):v=e[23];let K;e[24]!==n?(K=n("settings.snippets.sidebar.actions.create"),e[24]=n,e[25]=K):K=e[25];let $;e[26]===Symbol.for("react.memo_cache_sentinel")?($=s.jsx(_,{name:"add",className:"h-3.5 w-3.5"}),e[26]=$):$=e[26];let w;e[27]!==E||e[28]!==K?(w=s.jsx(H,{size:"sm","data-settings-item":"snippets.create",variant:"ghost",className:"h-7 w-7 px-0 -my-1 text-muted-foreground",onClick:E,"aria-label":K,children:$}),e[27]=E,e[28]=K,e[29]=w):w=e[29];let G;e[30]!==v||e[31]!==w?(G=s.jsxs("div",{className:"flex items-center justify-between gap-2",children:[v,w]}),e[30]=v,e[31]=w,e[32]=G):G=e[32];let Q;e[33]!==G||e[34]!==S?(Q=s.jsxs("div",{className:"border-b px-3 pt-4 pb-3",children:[S,G]}),e[33]=G,e[34]=S,e[35]=Q):Q=e[35];let X;if(e[36]!==a||e[37]!==l||e[38]!==c||e[39]!==m||e[40]!==p||e[41]!==g||e[42]!==n){let Se;e[44]!==a||e[45]!==l||e[46]!==c||e[47]!==m||e[48]!==p||e[49]!==n?(Se=Ne=>s.jsxs(On,{open:c===Ne.name,onOpenChange:fe=>y(fe?Ne.name:null),children:[s.jsxs(Rn,{render:s.jsx("div",{className:je("group relative flex items-center rounded-md px-1.5 py-1 transition-all duration-200 select-none",m===Ne.name?"bg-interactive-selection":"hover:bg-interactive-hover"),onContextMenu:fe=>{fe.preventDefault(),y(Ne.name)}}),children:[s.jsxs("button",{onClick:()=>{p(Ne.name),a?.()},className:"flex min-w-0 flex-1 flex-col gap-0 rounded-sm text-left focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-primary/50",children:[s.jsxs("div",{className:"flex items-center gap-2",children:[s.jsxs("span",{className:"typography-ui-label font-normal truncate text-foreground",children:["#",Ne.name]}),s.jsx("span",{className:"typography-micro text-muted-foreground bg-muted px-1 rounded flex-shrink-0 leading-none pb-px border border-border/50",children:n(`snippets.source.${Ne.source}`)})]}),s.jsx("div",{className:"typography-micro text-muted-foreground/60 truncate leading-tight",children:Ne.description||Ne.content.replace(/\s+/g," ").substring(0,80)})]}),s.jsxs(Hs,{open:l===Ne.name,onOpenChange:fe=>{fe&&y(null),x(fe?Ne.name:null)},children:[s.jsx($s,{asChild:!0,children:s.jsx(H,{size:"sm",variant:"ghost",className:"h-6 w-6 px-0 flex-shrink-0 -mr-1 opacity-100 transition-opacity md:opacity-0 md:group-hover:opacity-100","aria-label":n("settings.snippets.sidebar.actions.more",{name:Ne.name}),children:s.jsx(_,{name:"more-2",className:"h-3.5 w-3.5"})})}),s.jsx(Bs,{align:"end",className:"w-fit min-w-20",children:s.jsxs(Gs,{onClick:fe=>{fe.stopPropagation(),r(Ne)},className:"text-destructive focus:text-destructive",children:[s.jsx(_,{name:"delete-bin",className:"h-4 w-4 mr-px"}),n("settings.common.actions.delete")]})})]})]}),s.jsx(Dn,{className:"w-fit min-w-20",children:s.jsxs(Mn,{onClick:fe=>{fe.stopPropagation(),r(Ne)},className:"text-destructive focus:text-destructive",children:[s.jsx(_,{name:"delete-bin",className:"h-4 w-4 mr-px"}),n("settings.common.actions.delete")]})})]},`${Ne.source}:${Ne.filePath}`),e[44]=a,e[45]=l,e[46]=c,e[47]=m,e[48]=p,e[49]=n,e[50]=Se):Se=e[50],X=g.map(Se),e[36]=a,e[37]=l,e[38]=c,e[39]=m,e[40]=p,e[41]=g,e[42]=n,e[43]=X}else X=e[43];let Z;e[51]!==X?(Z=s.jsx(Ds,{outerClassName:"flex-1 min-h-0",className:"space-y-1 px-3 py-2",children:X}),e[51]=X,e[52]=Z):Z=e[52];const P=i!==null;let ee;e[53]===Symbol.for("react.memo_cache_sentinel")?(ee=Se=>{Se||r(null)},e[53]=ee):ee=e[53];let se;e[54]!==n?(se=n("settings.snippets.sidebar.dialog.deleteTitle"),e[54]=n,e[55]=se):se=e[55];let D;e[56]!==se?(D=s.jsx(Gt,{children:se}),e[56]=se,e[57]=D):D=e[57];const O=i?.name??"";let U;e[58]!==n||e[59]!==O?(U=n("settings.snippets.sidebar.dialog.deleteDescription",{name:O}),e[58]=n,e[59]=O,e[60]=U):U=e[60];let A;e[61]!==U?(A=s.jsx(qt,{children:U}),e[61]=U,e[62]=A):A=e[62];let V;e[63]!==D||e[64]!==A?(V=s.jsxs(Ht,{children:[D,A]}),e[63]=D,e[64]=A,e[65]=V):V=e[65];let W;e[66]===Symbol.for("react.memo_cache_sentinel")?(W=()=>r(null),e[66]=W):W=e[66];let te;e[67]!==n?(te=n("settings.common.actions.cancel"),e[67]=n,e[68]=te):te=e[68];let ae;e[69]!==te?(ae=s.jsx(H,{size:"sm",variant:"ghost",onClick:W,children:te}),e[69]=te,e[70]=ae):ae=e[70];let le;e[71]!==n?(le=n("settings.common.actions.delete"),e[71]=n,e[72]=le):le=e[72];let be;e[73]!==M||e[74]!==le?(be=s.jsx(H,{size:"sm",onClick:M,children:le}),e[73]=M,e[74]=le,e[75]=be):be=e[75];let ke;e[76]!==ae||e[77]!==be?(ke=s.jsxs(os,{children:[ae,be]}),e[76]=ae,e[77]=be,e[78]=ke):ke=e[78];let ce;e[79]!==V||e[80]!==ke?(ce=s.jsxs(Vt,{className:"max-w-md",children:[V,ke]}),e[79]=V,e[80]=ke,e[81]=ce):ce=e[81];let ge;e[82]!==P||e[83]!==ce?(ge=s.jsx(Ut,{open:P,onOpenChange:ee,children:ce}),e[82]=P,e[83]=ce,e[84]=ge):ge=e[84];let Ee;return e[85]!==Q||e[86]!==Z||e[87]!==ge?(Ee=s.jsxs("div",{className:j,children:[Q,Z,ge]}),e[85]=Q,e[86]=Z,e[87]=ge,e[88]=Ee):Ee=e[88],Ee};function sg(t){return{selectedSnippetName:t.selectedSnippetName,snippets:t.snippets,setSelectedSnippet:t.setSelectedSnippet,setSnippetDraft:t.setSnippetDraft,deleteSnippet:t.deleteSnippet,loadSnippets:t.loadSnippets}}function ng(t){return t.name}function ag(t,e){return t.name.localeCompare(e.name)}const ig=()=>{const{t}=ot(),{selectedSnippetName:e,snippets:a,snippetDraft:n,setSnippetDraft:i,updateSnippet:r,createSnippet:l}=Za(Ps(j=>({selectedSnippetName:j.selectedSnippetName,snippets:j.snippets,snippetDraft:j.snippetDraft,setSnippetDraft:j.setSnippetDraft,updateSnippet:j.updateSnippet,createSnippet:j.createSnippet}))),x=o.useMemo(()=>e?a.find(j=>j.name===e||j.aliases.includes(e))??null:null,[e,a]),c=!!(n&&n.name===e&&!x),[y,m]=o.useState(""),[b,p]=o.useState("global"),[L,k]=o.useState(""),[N,h]=o.useState(""),[C,u]=o.useState(""),[E,q]=o.useState(!1),M=o.useRef(null);o.useEffect(()=>{if(c&&n){const j={draftName:n.name||"",draftScope:n.scope||"global",description:n.description||"",aliases:(n.aliases||[]).join(", "),content:n.content||""};m(j.draftName),p(j.draftScope),k(j.description),h(j.aliases),u(j.content),M.current=j}else if(x){const j={draftName:"",draftScope:"global",description:x.description??"",aliases:x.aliases.join(", "),content:x.content};k(j.description),h(j.aliases),u(j.content),M.current=j}},[x,c,e,n]);const I=o.useMemo(()=>{const j=M.current;return j?c&&y!==j.draftName||c&&b!==j.draftScope?!0:L!==j.description||N!==j.aliases||C!==j.content:!1},[N,C,L,y,b,c]),g=async()=>{const j=c?y.trim().replace(/\s+/g,"-"):e?.trim();if(!j){R.error(t("settings.snippets.page.toast.nameRequired"));return}if(!C.trim()){R.error(t("settings.snippets.page.toast.contentRequired"));return}const F=N.split(",").map(S=>S.trim()).filter(Boolean);q(!0);try{if(!(c?await l(j,C,{aliases:F,description:L,scope:b}):await r(j,{content:C,aliases:F,description:L}))){R.error(t("settings.snippets.page.toast.saveFailed"));return}R.success(t("settings.snippets.page.toast.saved")),c&&i(null)}finally{q(!1)}};return e?s.jsxs(rs,{title:c?t("settings.snippets.page.title.new"):`#${e}`,description:x?x.filePath:void 0,showSaveStatus:!1,children:[s.jsxs(Oe,{divider:!1,contentClassName:"space-y-0",children:[c?s.jsxs($t,{label:"#",children:[s.jsx(He,{value:y,onChange:j=>m(j.target.value),placeholder:t("settings.snippets.page.field.namePlaceholder"),className:"h-7 w-44 px-2"}),s.jsxs(Dt,{value:b,onValueChange:j=>p(j),children:[s.jsx(Mt,{size:Kt,className:"w-fit min-w-[100px]",children:s.jsx(_t,{})}),s.jsxs(Rt,{align:"end",children:[s.jsx(dt,{value:"global",children:t("settings.common.scope.global")}),s.jsx(dt,{value:"project",children:t("settings.common.scope.project")})]})]})]}):null,s.jsx(Qt,{label:t("settings.common.field.description"),children:s.jsx(He,{value:L,onChange:j=>k(j.target.value),placeholder:t("settings.snippets.page.field.descriptionPlaceholder"),className:"h-7 w-full max-w-sm px-2"})}),s.jsx(Qt,{label:t("settings.snippets.page.field.aliases"),children:s.jsx(He,{value:N,onChange:j=>h(j.target.value),placeholder:t("settings.snippets.page.field.aliasesPlaceholder"),className:"h-7 w-full max-w-sm px-2"})})]}),s.jsxs(Oe,{settingsItem:"snippets.content",children:[s.jsxs("div",{className:"flex items-center gap-1",children:[s.jsx("span",{className:"typography-ui-label text-foreground",children:t("settings.snippets.page.field.content")}),s.jsx(Yt,{children:t("settings.snippets.page.hint")})]}),s.jsx(Ns,{value:C,onChange:j=>u(j.target.value),placeholder:t("settings.snippets.page.field.contentPlaceholder"),rows:12,className:"mt-1.5 w-full font-mono typography-meta min-h-[160px] max-h-[60vh] bg-transparent"}),s.jsx("div",{className:"pt-3",children:s.jsx(H,{onClick:g,disabled:E||!I,size:"xs",className:"!font-normal",children:t(E?"settings.common.actions.saving":"settings.common.actions.saveChanges")})})]})]}):s.jsx("div",{className:"flex h-full items-center justify-center",children:s.jsxs("div",{className:"text-center text-muted-foreground",children:[s.jsx(_,{name:"file-text",className:"mx-auto mb-3 h-12 w-12 opacity-50"}),s.jsx("p",{className:"typography-body",children:t("settings.snippets.page.empty.title")}),s.jsx("p",{className:"typography-meta mt-1 opacity-75",children:t("settings.snippets.page.empty.description")})]})})},cl=()=>{const{t}=ot(),e=nt(b=>b.settingsGitmojiEnabled),a=nt(b=>b.setSettingsGitmojiEnabled),n=Oc(),i=de(b=>b.gitChangesViewMode),r=de(b=>b.setGitChangesViewMode),[l,x]=o.useState(!0),c=o.useMemo(()=>[{id:"flat",label:t("settings.openchamber.git.option.flatList")},{id:"tree",label:t("settings.openchamber.git.option.treeView")}],[t]);o.useEffect(()=>{(async()=>{try{let p=null;if(!p){const L=jn()?.settings;if(L)try{const N=(await L.load())?.settings;N&&(p={gitmojiEnabled:typeof N.gitmojiEnabled=="boolean"?N.gitmojiEnabled:void 0,gitChangesViewMode:N.gitChangesViewMode==="flat"||N.gitChangesViewMode==="tree"?N.gitChangesViewMode:void 0})}catch{}}if(!p){const L=await ct("/api/config/settings",{method:"GET",headers:{Accept:"application/json"}});L.ok&&(p=await L.json())}p&&(typeof p.gitmojiEnabled=="boolean"&&a(p.gitmojiEnabled),(p.gitChangesViewMode==="flat"||p.gitChangesViewMode==="tree")&&r(p.gitChangesViewMode))}catch(p){console.warn("Failed to load git settings:",p)}finally{x(!1)}})()},[r,a]);const y=o.useCallback(async b=>{a(b);try{await yt({gitmojiEnabled:b})}catch(p){console.warn("Failed to save gitmoji setting:",p)}},[a]),m=o.useCallback(b=>{b!==i&&(r(b),yt({gitChangesViewMode:b}))},[i,r]);return l?null:s.jsx(Oe,{title:t("settings.openchamber.git.title"),children:s.jsxs("div",{className:bs,children:[s.jsx(Os,{settingsItem:"git.changes-view",title:t("settings.openchamber.git.changesViewTitle"),children:s.jsx(gn,{"aria-label":t("settings.openchamber.git.changesViewAria"),children:c.map(b=>s.jsx(hn,{selected:i===b.id,onSelect:()=>{m(b.id)},label:b.label,ariaLabel:t("settings.openchamber.git.optionAria",{option:b.label})},b.id))})}),s.jsx(ut,{settingsItem:"git.gitmoji",checked:e,onChange:b=>{y(b)},label:t("settings.openchamber.git.enableGitmoji"),ariaLabel:t("settings.openchamber.git.enableGitmojiAria")}),s.jsx(ut,{settingsItem:"git.gitignored-files",checked:n,onChange:Lc,label:t("settings.openchamber.git.showGitignored"),ariaLabel:t("settings.openchamber.git.showGitignoredAria")})]})})},dl=()=>{const{t}=ot(),{isMobile:e}=Jn(),a=jn()?.github,n=ea(v=>v.status),i=ea(v=>v.isLoading),r=ea(v=>v.hasChecked),l=ea(v=>v.refreshStatus),x=ea(v=>v.setStatus),c=o.useCallback(async v=>{await En(v)},[]),[y,m]=o.useState(!1),[b,p]=o.useState(null),[L,k]=o.useState(null),N=o.useRef(null),h=o.useCallback(()=>{N.current!=null&&(window.clearInterval(N.current),N.current=null),k(null)},[]);o.useEffect(()=>((async()=>{try{r||await l(a)}catch(v){console.warn("Failed to load GitHub auth status:",v)}})(),()=>{h()}),[r,l,a,h]);const C=o.useCallback(async()=>{m(!0);try{const v=a?await a.authStart():await(async()=>{const $=await ct("/api/github/auth/start",{method:"POST",headers:{"Content-Type":"application/json",Accept:"application/json"},body:JSON.stringify({})}),w=await $.json().catch(()=>null);if(!$.ok||!w||!("deviceCode"in w))throw new Error(w?.error||$.statusText);return w})();p(v),k(Math.max(1,v.interval)*1e3);const K=v.verificationUriComplete||v.verificationUri;c(K)}catch(v){console.error("Failed to start GitHub connect:",v),R.error(t("settings.github.page.toast.startConnectFailed"))}finally{m(!1)}},[c,a,t]),u=o.useCallback(async v=>{if(a)return a.authComplete(v);const K=await ct("/api/github/auth/complete",{method:"POST",headers:{"Content-Type":"application/json",Accept:"application/json"},body:JSON.stringify({deviceCode:v})}),$=await K.json().catch(()=>null);if(!K.ok||!$)throw new Error($?.error||K.statusText);return $},[a]);o.useEffect(()=>{if(!(!b?.deviceCode||!L)&&N.current==null)return N.current=window.setInterval(()=>{(async()=>{try{const v=await u(b.deviceCode);if(v.connected){R.success(t("settings.github.page.toast.connected")),p(null),h(),await l(a,{force:!0});return}v.status==="slow_down"&&k(K=>K?K+5e3:5e3),(v.status==="expired_token"||v.status==="access_denied")&&(R.error(v.error||t("settings.github.page.toast.authorizationFailed")),p(null),h())}catch(v){console.warn("GitHub polling failed:",v)}})()},L),()=>{N.current!=null&&(window.clearInterval(N.current),N.current=null)}},[b,L,u,l,a,h,t]);const E=o.useCallback(async v=>{m(!0);try{if(a)await a.authSetGhCliDisabled(v);else{const K=await ct("/api/github/auth/gh-cli",{method:"POST",headers:{"Content-Type":"application/json",Accept:"application/json"},body:JSON.stringify({disabled:v})}),$=await K.json().catch(()=>null);if(!K.ok)throw new Error($?.error||K.statusText)}R.success(t(v?"settings.github.page.toast.ghCliDisabled":"settings.github.page.toast.ghCliEnabled")),await l(a,{force:!0})}catch(K){console.error("Failed to update gh CLI setting:",K),R.error(t("settings.github.page.toast.ghCliUpdateFailed"))}finally{m(!1)}},[l,a,t]),q=o.useCallback(async()=>{m(!0);try{if(h(),p(null),a)await a.authDisconnect();else{const v=await ct("/api/github/auth",{method:"DELETE",headers:{Accept:"application/json"}});if(!v.ok)throw new Error(v.statusText)}R.success(t("settings.github.page.toast.disconnected")),await l(a,{force:!0})}catch(v){console.error("Failed to disconnect GitHub:",v),R.error(t("settings.github.page.toast.disconnectFailed"))}finally{m(!1)}},[l,a,h,t]),M=o.useCallback(async v=>{if(v){m(!0);try{const K=a?await a.authActivate(v):await(async()=>{const $=await ct("/api/github/auth/activate",{method:"POST",headers:{"Content-Type":"application/json",Accept:"application/json"},body:JSON.stringify({accountId:v})}),w=await $.json().catch(()=>null);if(!$.ok||!w)throw new Error(w?.error||$.statusText);return w})();x(K),R.success(t("settings.github.page.toast.accountSwitched"))}catch(K){console.error("Failed to switch GitHub account:",K),R.error(t("settings.github.page.toast.accountSwitchFailed"))}finally{m(!1)}}},[a,x,t]);if(i)return null;const I=!!n?.connected,g=n?.user,F=(n?.accounts??[]).filter(v=>!v.current),S=n?.ghCli??null,T=S?.active?t("settings.github.page.accountSource.cli"):t("settings.github.page.accountSource.oauth");return s.jsxs(s.Fragment,{children:[s.jsxs(Oe,{title:t("settings.github.page.oauth.title"),divider:!1,settingsItem:"git.github-account",info:t("settings.github.page.tooltip.connectAccount"),children:[s.jsxs("div",{className:"rounded-lg bg-[var(--surface-elevated)]/70 overflow-hidden flex flex-col",children:[I?s.jsxs("div",{className:je("px-4 py-3",e?"flex flex-col gap-3":"flex items-center justify-between gap-4"),children:[s.jsxs("div",{className:je("flex min-w-0 items-center gap-4",e?"w-full":void 0),children:[g?.avatarUrl?s.jsx("img",{src:g.avatarUrl,alt:g.login?t("settings.github.page.avatarAlt.withLogin",{login:g.login}):t("settings.github.page.avatarAlt.fallback"),className:"h-10 w-10 shrink-0 rounded-full border border-[var(--interactive-border)] bg-[var(--surface-muted)] object-cover",loading:"lazy",referrerPolicy:"no-referrer"}):s.jsx("div",{className:"h-10 w-10 shrink-0 rounded-full border border-[var(--interactive-border)] bg-[var(--surface-muted)]"}),s.jsxs("div",{className:"min-w-0 flex-1",children:[s.jsx("div",{className:"typography-ui-label text-foreground",children:g?.name?.trim()||g?.login||"GitHub"}),s.jsxs("div",{className:je("flex items-center gap-2 typography-meta text-muted-foreground mt-0.5",e?"flex-wrap":"truncate"),children:[s.jsx(_,{name:"github-fill",className:"h-3.5 w-3.5 shrink-0"}),s.jsx("span",{className:"font-mono",children:g?.login||t("settings.github.page.label.unknownUser")}),g?.email&&s.jsx("span",{className:"opacity-50",children:"•"}),g?.email&&s.jsx("span",{children:g.email}),s.jsx("span",{className:"opacity-50",children:"•"}),s.jsx("span",{children:T})]}),n?.scope&&s.jsx("div",{className:"typography-micro text-muted-foreground/70 mt-0.5",children:t("settings.github.page.label.scopes",{value:n.scope})}),S?.active&&s.jsx("div",{className:"typography-micro text-muted-foreground/70 mt-0.5",children:t("settings.github.page.ghCli.activeDescription")})]})]}),S?.active?s.jsx(H,{size:"sm",variant:"outline",onClick:()=>E(!0),disabled:y,className:je(e?"w-full":void 0),children:t("settings.github.page.ghCli.actions.disable")}):s.jsx(H,{size:"sm",variant:"outline",onClick:q,disabled:y,className:je("text-[var(--status-error)] hover:text-[var(--status-error)]",e?"w-full":void 0),children:t("settings.github.page.actions.disconnect")})]}):s.jsxs("div",{className:"flex items-center justify-between gap-4 px-4 py-4",children:[s.jsx("div",{className:"flex min-w-0 flex-col",children:s.jsx("span",{className:"typography-ui-label text-foreground",children:t("settings.github.page.status.notConnected")})}),s.jsx(H,{size:"sm",variant:"default",onClick:C,disabled:y,children:t("settings.github.page.actions.connect")})]}),F.length>0&&s.jsxs("div",{className:"mt-2 border-t border-[var(--surface-subtle)] pt-2 px-2 pb-1",children:[s.jsx("div",{className:"typography-micro text-muted-foreground mb-2 px-1",children:t("settings.github.page.label.otherAccounts")}),s.jsx("div",{className:"space-y-1",children:F.map(v=>{const K=v.user,$=v.source==="gh-cli"?t("settings.github.page.accountSource.cli"):t("settings.github.page.accountSource.oauth");return s.jsxs("div",{className:"flex items-center justify-between gap-3 rounded-md border border-[var(--surface-subtle)] bg-[var(--surface-muted)] px-3 py-2",children:[s.jsxs("div",{className:"flex min-w-0 items-center gap-3",children:[K?.avatarUrl?s.jsx("img",{src:K.avatarUrl,alt:K.login?t("settings.github.page.avatarAlt.withLogin",{login:K.login}):t("settings.github.page.avatarAlt.fallback"),className:"h-6 w-6 shrink-0 rounded-full border border-[var(--interactive-border)] bg-[var(--surface-muted)] object-cover",loading:"lazy",referrerPolicy:"no-referrer"}):s.jsx("div",{className:"flex h-6 w-6 shrink-0 items-center justify-center rounded-full border border-[var(--interactive-border)] bg-[var(--surface-muted)]",children:s.jsx(_,{name:"github-fill",className:"h-3 w-3 text-muted-foreground"})}),s.jsxs("div",{className:"min-w-0 flex flex-col",children:[s.jsx("span",{className:"typography-ui-label text-foreground truncate",children:K?.name?.trim()||K?.login||"GitHub"}),K?.login&&s.jsxs("span",{className:"typography-micro text-muted-foreground truncate",children:[s.jsx("span",{className:"font-mono",children:K.login}),s.jsx("span",{className:"mx-1 opacity-50",children:"·"}),s.jsx("span",{children:$})]})]})]}),s.jsx(H,{size:"sm",variant:"ghost",onClick:()=>M(v.id),disabled:y,children:t("settings.github.page.actions.switchTo")})]},v.id)})})]})]}),I&&s.jsx("div",{className:"mt-2 px-2 pb-2",children:s.jsx(H,{size:"sm",variant:"outline",onClick:C,disabled:y,className:je(e?"w-full":void 0),children:t("settings.github.page.actions.addAccount")})}),b&&s.jsxs("div",{className:"mt-4 rounded-lg bg-[var(--surface-elevated)]/70 p-4 border border-[var(--interactive-border)]",children:[s.jsxs("div",{className:"space-y-1",children:[s.jsx(Vs,{children:t("settings.github.page.flow.title")}),s.jsx("p",{className:"typography-meta text-muted-foreground",children:t("settings.github.page.flow.description")})]}),s.jsxs("div",{className:"flex items-center justify-between gap-3 mt-4",children:[s.jsx("div",{className:"font-mono text-xl tracking-widest text-foreground bg-[var(--surface-muted)] px-3 py-1.5 rounded-md border border-[var(--interactive-border)]",children:b.userCode}),s.jsx(H,{size:"sm",asChild:!0,children:s.jsx("a",{href:b.verificationUriComplete||b.verificationUri,target:"_blank",rel:"noopener noreferrer",children:t("settings.github.page.actions.openGithub")})})]}),s.jsxs("div",{className:"mt-4 flex items-center justify-between",children:[s.jsx("span",{className:"typography-micro text-muted-foreground animate-pulse",children:t("settings.github.page.flow.waiting")}),s.jsx(H,{size:"sm",variant:"ghost",disabled:y,onClick:()=>{h(),p(null)},children:t("settings.common.actions.cancel")})]})]})]}),S?.available&&!S?.active&&(!S.user||S.disabled)&&s.jsx(Oe,{title:t("settings.github.page.ghCli.title"),children:s.jsx("div",{className:"rounded-lg bg-[var(--surface-elevated)]/70 overflow-hidden",children:s.jsxs("div",{className:je("px-4 py-3",e?"flex flex-col gap-3":"flex items-center justify-between gap-4"),children:[s.jsxs("div",{className:je("flex min-w-0 items-center gap-4",e?"w-full":void 0),children:[S.user?.avatarUrl?s.jsx("img",{src:S.user.avatarUrl,alt:S.user.login?t("settings.github.page.avatarAlt.withLogin",{login:S.user.login}):t("settings.github.page.avatarAlt.fallback"),className:"h-10 w-10 shrink-0 rounded-full border border-[var(--interactive-border)] bg-[var(--surface-muted)] object-cover",loading:"lazy",referrerPolicy:"no-referrer"}):s.jsx("div",{className:"flex h-10 w-10 shrink-0 items-center justify-center rounded-full border border-[var(--interactive-border)] bg-[var(--surface-muted)]",children:s.jsx(_,{name:"github-fill",className:"h-4 w-4 text-muted-foreground"})}),s.jsxs("div",{className:"min-w-0 flex-1",children:[!S.disabled&&S.user&&s.jsx("div",{className:"typography-ui-label text-foreground truncate",children:S.user.name?.trim()||S.user.login||"GitHub"}),!S.disabled&&S.user?.login&&s.jsxs("div",{className:je("flex items-center gap-2 typography-meta text-muted-foreground mt-0.5",e?"flex-wrap":"truncate"),children:[s.jsx(_,{name:"github-fill",className:"h-3.5 w-3.5 shrink-0"}),s.jsx("span",{className:"font-mono",children:S.user.login}),S.user.email&&s.jsx("span",{className:"opacity-50",children:"•"}),S.user.email&&s.jsx("span",{children:S.user.email})]}),s.jsx("div",{className:je("typography-meta text-muted-foreground",S.disabled?"opacity-60":void 0),children:S.disabled?t("settings.github.page.ghCli.disabledDescription"):t("settings.github.page.ghCli.fallbackDescription")})]})]}),s.jsx(H,{size:"sm",variant:"outline",onClick:()=>E(!S.disabled),disabled:y,className:je(e?"w-full":void 0),children:S.disabled?t("settings.github.page.ghCli.actions.enable"):t("settings.github.page.ghCli.actions.disable")})]})})})]})},po=[{key:"keyword",label:"Green",cssVar:"var(--syntax-keyword)"},{key:"error",label:"Red",cssVar:"var(--status-error)"},{key:"string",label:"Cyan",cssVar:"var(--syntax-string)"},{key:"function",label:"Orange",cssVar:"var(--syntax-function)"},{key:"type",label:"Yellow",cssVar:"var(--syntax-type)"}],rg=[{key:"branch",Icon:"git-branch",label:"Branch"},{key:"briefcase",Icon:"briefcase",label:"Work"},{key:"house",Icon:"home",label:"Personal"},{key:"graduation",Icon:"graduation-cap",label:"School"},{key:"code",Icon:"code",label:"Code"}],og=({open:t,onOpenChange:e,profileId:a,importData:n})=>{const{t:i}=ot(),r=An(A=>A.getProfileById),l=An(A=>A.createProfile),x=An(A=>A.updateProfile),c=An(A=>A.deleteProfile),y=o.useMemo(()=>a&&a!=="new"&&!n?r(a):null,[a,r,n]),m=a==="new"||n!=null,b=a==="global",[p,L]=o.useState(""),[k,N]=o.useState(""),[h,C]=o.useState(""),[u,E]=o.useState("ssh"),[q,M]=o.useState(""),[I,g]=o.useState(!1),[j,F]=o.useState(""),[S,T]=o.useState(""),[v,K]=o.useState("keyword"),[$,w]=o.useState("branch"),[G,Q]=o.useState(!1),[X,Z]=o.useState(!1),[P,ee]=o.useState(!1);o.useEffect(()=>{if(t){if(n){const A=n.host.split("/"),V=A.length>=3?A[A.length-1]:n.host;L(V),N(n.username),C(""),E("token"),M(""),g(!1),F(""),T(n.host),K("string"),w("code")}else if(m)L(""),N(""),C(""),E("ssh"),M(""),g(!1),F(""),T(""),K("keyword"),w("branch");else if(y)L(y.name),N(y.userName),C(y.userEmail),E(y.authType||"ssh"),M(y.sshKey||""),g(y.signCommits===!0),F(y.signingKey||""),T(y.host||""),K(y.color||"keyword"),w(y.icon||"branch");else if(b){const A=r("global");A&&(L(A.name),N(A.userName),C(A.userEmail),E(A.authType||"ssh"),M(A.sshKey||""),g(!1),F(""),T(A.host||""),K(A.color||"keyword"),w(A.icon||"branch"))}}},[t,a,y,m,n,b,r]);const se=async()=>{if(!k.trim()||!h.trim()){R.error(i("settings.gitIdentities.editor.toast.userNameEmailRequired"));return}if(u==="token"&&!S.trim()){R.error(i("settings.gitIdentities.editor.toast.hostRequiredForToken"));return}if(I&&!j.trim()){R.error(i("settings.gitIdentities.editor.toast.signingKeyRequired"));return}Q(!0);try{const A={name:p.trim()||k.trim(),userName:k.trim(),userEmail:h.trim(),authType:u,sshKey:u==="ssh"&&q.trim()||null,signCommits:I,signingKey:j.trim()||null,host:u==="token"&&S.trim()||null,color:v,icon:$};let V;if(m)V=await l(A);else if(a)V=await x(a,A);else return;V?(R.success(i(m?"settings.gitIdentities.editor.toast.profileCreated":"settings.gitIdentities.editor.toast.profileUpdated")),e(!1)):R.error(i(m?"settings.gitIdentities.editor.toast.createProfileFailed":"settings.gitIdentities.editor.toast.updateProfileFailed"))}catch(A){console.error("Error saving profile:",A),R.error(i("settings.gitIdentities.editor.toast.saveUnexpectedError"))}finally{Q(!1)}},D=async()=>{if(!(!a||m)){ee(!0);try{await c(a)?(R.success(i("settings.gitIdentities.editor.toast.profileDeleted")),Z(!1),e(!1)):R.error(i("settings.gitIdentities.editor.toast.deleteProfileFailed"))}catch(A){console.error("Error deleting profile:",A),R.error(i("settings.gitIdentities.editor.toast.deleteUnexpectedError"))}finally{ee(!1)}}},O=o.useMemo(()=>po.find(V=>V.key===v)?.cssVar||"var(--syntax-keyword)",[v]),U=n?i("settings.gitIdentities.editor.title.importCredential"):m?i("settings.gitIdentities.editor.title.newIdentity"):b?i("settings.gitIdentities.editor.title.globalIdentity"):y?.name||i("settings.gitIdentities.editor.title.editIdentity");return s.jsxs(s.Fragment,{children:[s.jsx(Ut,{open:t,onOpenChange:e,children:s.jsxs(Vt,{className:"max-w-lg max-h-[85vh] overflow-y-auto",children:[s.jsxs(Ht,{children:[s.jsx(Gt,{children:U}),s.jsx(qt,{children:i(b?"settings.gitIdentities.editor.description.globalReadOnly":m?"settings.gitIdentities.editor.description.newProfile":"settings.gitIdentities.editor.description.editProfile")})]}),s.jsxs("div",{className:"space-y-5 py-2",children:[!b&&s.jsxs("div",{className:"space-y-3",children:[s.jsxs("div",{children:[s.jsx("label",{className:`${Et} block mb-1.5`,children:i("settings.gitIdentities.editor.field.profileName")}),s.jsx(He,{value:p,onChange:A=>L(A.target.value),placeholder:i("settings.gitIdentities.editor.field.profileNamePlaceholder"),className:"h-8"})]}),s.jsxs("div",{className:"flex items-center justify-between gap-4",children:[s.jsx("span",{className:"typography-ui-label text-foreground",children:i("settings.gitIdentities.editor.field.color")}),s.jsx("div",{className:"flex gap-1.5",children:po.map(A=>s.jsx("button",{type:"button",onClick:()=>K(A.key),className:je("w-6 h-6 rounded-md border-2 transition-all cursor-pointer",v===A.key?"border-foreground scale-110":"border-transparent hover:border-border"),style:{backgroundColor:A.cssVar},title:A.label},A.key))})]}),s.jsxs("div",{className:"flex items-center justify-between gap-4",children:[s.jsx("span",{className:"typography-ui-label text-foreground",children:i("settings.gitIdentities.editor.field.icon")}),s.jsx("div",{className:"flex gap-1.5",children:rg.map(A=>{const V=A.Icon;return s.jsx("button",{type:"button",onClick:()=>w(A.key),className:je("w-7 h-7 rounded-md border-2 transition-all flex items-center justify-center cursor-pointer",$===A.key?"border-[var(--interactive-border)] bg-[var(--surface-muted)]":"border-transparent hover:border-[var(--interactive-border)] hover:bg-[var(--surface-muted)]/50"),title:A.label,children:s.jsx(_,{name:V,className:"w-3.5 h-3.5",style:{color:$===A.key?O:"var(--surface-muted-foreground)"}})},A.key)})})]})]}),!b&&s.jsx("div",{className:"border-t border-border/40"}),s.jsxs("div",{className:"space-y-3",children:[s.jsxs("div",{children:[s.jsxs("div",{className:"flex items-center gap-1.5 mb-1.5",children:[s.jsx("label",{className:Et,children:i("settings.gitIdentities.editor.field.userName")}),!b&&s.jsx("span",{className:"text-[var(--status-error)] text-xs",children:"*"}),s.jsx(Yt,{contentClassName:"max-w-xs",children:i("settings.gitIdentities.editor.field.userNameTooltip")})]}),s.jsx(He,{value:k,onChange:A=>N(A.target.value),placeholder:i("settings.gitIdentities.editor.field.userNamePlaceholder"),required:!b,readOnly:b,disabled:b,className:"h-8"})]}),s.jsxs("div",{children:[s.jsxs("div",{className:"flex items-center gap-1.5 mb-1.5",children:[s.jsx("label",{className:Et,children:i("settings.gitIdentities.editor.field.emailAddress")}),!b&&s.jsx("span",{className:"text-[var(--status-error)] text-xs",children:"*"}),s.jsx(Yt,{contentClassName:"max-w-xs",children:i("settings.gitIdentities.editor.field.emailAddressTooltip")})]}),s.jsx(He,{type:"email",value:h,onChange:A=>C(A.target.value),placeholder:i("settings.gitIdentities.editor.field.emailAddressPlaceholder"),required:!b,readOnly:b,disabled:b,className:"h-8"})]})]}),!b&&s.jsxs(s.Fragment,{children:[s.jsx("div",{className:"border-t border-border/40"}),s.jsxs("div",{className:"space-y-3",children:[s.jsxs("div",{className:"flex items-center justify-between gap-4",children:[s.jsx("span",{className:"typography-ui-label text-foreground",children:i("settings.gitIdentities.editor.field.authMethod")}),s.jsxs("div",{className:"flex items-center gap-1",children:[s.jsxs(H,{size:"sm",type:"button",variant:"chip","aria-pressed":u==="ssh",onClick:()=>E("ssh"),children:[s.jsx(_,{name:"lock-2",className:"w-3.5 h-3.5 mr-1"})," SSH"]}),s.jsxs(H,{size:"sm",type:"button",variant:"chip","aria-pressed":u==="token",onClick:()=>E("token"),children:[s.jsx(_,{name:"key",className:"w-3.5 h-3.5 mr-1"})," ",i("settings.gitIdentities.editor.field.authToken")]})]})]}),u==="ssh"&&s.jsxs("div",{children:[s.jsxs("div",{className:"flex items-center gap-1.5 mb-1.5",children:[s.jsx("label",{className:Et,children:i("settings.gitIdentities.editor.field.sshKeyPath")}),s.jsx(Yt,{contentClassName:"max-w-xs",children:i("settings.gitIdentities.editor.field.sshKeyPathTooltip")})]}),s.jsx(He,{value:q,onChange:A=>M(A.target.value),placeholder:i("settings.gitIdentities.editor.field.sshKeyPathPlaceholder"),className:"h-8 font-mono text-xs"})]}),s.jsxs("div",{className:"border-t border-border/40 pt-3 space-y-3",children:[s.jsx(ut,{checked:I,onChange:g,label:i("settings.gitIdentities.editor.field.signCommits"),info:i("settings.gitIdentities.editor.section.commitSigning"),ariaLabel:i("settings.gitIdentities.editor.field.signCommits")}),s.jsxs("div",{children:[s.jsx("div",{className:"flex items-center gap-1.5 mb-1.5",children:s.jsx("label",{className:Et,children:i("settings.gitIdentities.editor.field.signingKey")})}),s.jsx(He,{value:j,onChange:A=>F(A.target.value),placeholder:i("settings.gitIdentities.editor.field.signingKeyPlaceholder"),disabled:!I,className:"h-8 font-mono text-xs"})]})]}),u==="token"&&s.jsxs("div",{children:[s.jsxs("div",{className:"flex items-center gap-1.5 mb-1.5",children:[s.jsx("label",{className:Et,children:i("settings.gitIdentities.editor.field.host")}),s.jsx("span",{className:"text-[var(--status-error)] text-xs",children:"*"}),s.jsx(Yt,{contentClassName:"max-w-xs",children:i("settings.gitIdentities.editor.field.hostTooltip")})]}),s.jsx(He,{value:S,onChange:A=>T(A.target.value),placeholder:i("settings.gitIdentities.editor.field.hostPlaceholder"),required:!0,className:"h-8 font-mono text-xs"})]})]})]})]}),s.jsxs(os,{className:"gap-2",children:[!b&&!m&&s.jsxs(H,{variant:"outline",size:"sm",onClick:()=>Z(!0),className:"text-[var(--status-error)] hover:text-[var(--status-error)] border-[var(--status-error)]/30 hover:bg-[var(--status-error)]/10 mr-auto",children:[s.jsx(_,{name:"delete-bin",className:"w-3.5 h-3.5 mr-1"})," ",i("settings.common.actions.delete")]}),s.jsx(H,{variant:"ghost",size:"sm",onClick:()=>e(!1),className:"text-foreground hover:bg-interactive-hover hover:text-foreground",children:i(b?"settings.gitIdentities.editor.actions.close":"settings.common.actions.cancel")}),!b&&s.jsx(H,{size:"sm",onClick:se,disabled:G,children:i(G?"settings.common.actions.saving":m?"settings.gitIdentities.editor.actions.create":"settings.gitIdentities.editor.actions.save")})]})]})}),s.jsx(Ut,{open:X,onOpenChange:A=>{P||Z(A)},children:s.jsxs(Vt,{className:"max-w-md",children:[s.jsxs(Ht,{children:[s.jsx(Gt,{children:i("settings.gitIdentities.page.deleteDialog.title")}),s.jsx(qt,{children:i("settings.gitIdentities.page.deleteDialog.description",{name:y?.name||p})})]}),s.jsxs(os,{children:[s.jsx(H,{variant:"ghost",onClick:()=>Z(!1),disabled:P,children:i("settings.common.actions.cancel")}),s.jsx(H,{size:"sm",variant:"destructive",onClick:()=>{D()},disabled:P,children:i("settings.common.actions.delete")})]})]})})]})},lg={branch:"git-branch",briefcase:"briefcase",house:"home",graduation:"graduation-cap",code:"code",heart:"heart"},cg={keyword:"var(--syntax-keyword)",error:"var(--status-error)",string:"var(--syntax-string)",function:"var(--syntax-function)",type:"var(--syntax-type)"},dg=()=>{const t=ht.c(113),{t:e}=ot(),{profiles:a,globalIdentity:n,defaultGitIdentityId:i,deleteProfile:r,loadProfiles:l,loadGlobalIdentity:x,loadDiscoveredCredentials:c,loadDefaultGitIdentityId:y,setDefaultGitIdentityId:m,getUnimportedCredentials:b}=An(Ps(mg)),[p,L]=o.useState(!1),[k,N]=o.useState(null),[h,C]=o.useState(null),[u,E]=o.useState(null),[q,M]=o.useState(!1);let I,g;t[0]!==y||t[1]!==c||t[2]!==x||t[3]!==l?(I=()=>{l(),x(),c(),y()},g=[l,x,c,y],t[0]=y,t[1]=c,t[2]=x,t[3]=l,t[4]=I,t[5]=g):(I=t[4],g=t[5]),o.useEffect(I,g);let j,F,S,T,v,K,$,w,G,Q,X,Z,P,ee;if(t[6]!==i||t[7]!==u||t[8]!==r||t[9]!==b||t[10]!==n||t[11]!==a||t[12]!==m||t[13]!==e){const ze=b();let Je;t[28]===Symbol.for("react.memo_cache_sentinel")?(Je=(Fe,ye)=>{N(Fe),C(ye??null),L(!0)},t[28]=Je):Je=t[28];const _e=Je;let Le;t[29]!==i||t[30]!==m||t[31]!==e?(Le=async Fe=>{const ye=i===Fe?null:Fe;if(!await m(ye)){R.error(e("settings.gitIdentities.page.toast.updateDefaultFailed"));return}R.success(e(ye?"settings.gitIdentities.page.toast.defaultUpdated":"settings.gitIdentities.page.toast.defaultUnset"))},t[29]=i,t[30]=m,t[31]=e,t[32]=Le):Le=t[32];const Pe=Le;let Ye;t[33]!==u||t[34]!==r||t[35]!==e?(Ye=async()=>{if(!u)return;M(!0),await r(u.id)?(R.success(e("settings.gitIdentities.page.toast.profileDeleted",{name:u.name})),E(null)):R.error(e("settings.gitIdentities.page.toast.deleteProfileFailed")),M(!1)},t[33]=u,t[34]=r,t[35]=e,t[36]=Ye):Ye=t[36],S=Ye,F=rs,t[37]!==e?(T=e("settings.page.git.title"),t[37]=e,t[38]=T):T=t[38],v=!0,t[39]===Symbol.for("react.memo_cache_sentinel")?(K=s.jsx(dl,{}),t[39]=K):K=t[39],j=Oe,t[40]!==e?(Z=e("settings.gitIdentities.page.section.title"),t[40]=e,t[41]=Z):Z=t[41];let Ge,Me;t[42]===Symbol.for("react.memo_cache_sentinel")?(Ge=()=>_e("new"),Me=s.jsx(_,{name:"add",className:"w-3.5 h-3.5 mr-1"}),t[42]=Ge,t[43]=Me):(Ge=t[42],Me=t[43]);let $e;t[44]!==e?($e=e("settings.common.badge.new"),t[44]=e,t[45]=$e):$e=t[45],t[46]!==$e?(P=s.jsxs(H,{size:"sm",variant:"outline",onClick:Ge,children:[Me," ",$e]}),t[46]=$e,t[47]=P):P=t[47],ee="git.identities",$="rounded-lg bg-[var(--surface-elevated)]/70 overflow-hidden flex flex-col",w=n&&s.jsx(mo,{profile:n,isDefault:i==="global",onEdit:()=>_e("global"),onToggleDefault:()=>Pe("global"),isReadOnly:!0,hasBorder:a.length>0||ze.length>0}),G=a.map((Fe,ye)=>s.jsx(mo,{profile:Fe,isDefault:i===Fe.id,onEdit:()=>_e(Fe.id),onToggleDefault:()=>Pe(Fe.id),onDelete:()=>E(Fe),hasBorder:ye<a.length-1||ze.length>0},Fe.id)),Q=!n&&a.length===0&&ze.length===0&&s.jsxs("div",{className:"py-8 px-4 text-center text-muted-foreground",children:[s.jsx(_,{name:"shield-keyhole",className:"mx-auto mb-2 h-8 w-8 opacity-40"}),s.jsx("p",{className:"typography-ui-label",children:e("settings.gitIdentities.page.empty.title")}),s.jsx("p",{className:"typography-meta mt-1 opacity-75",children:e("settings.gitIdentities.page.empty.description")})]}),X=ze.length>0&&s.jsxs(s.Fragment,{children:[s.jsx("div",{className:"px-4 py-2 border-t border-[var(--surface-subtle)]",children:s.jsx("span",{className:"typography-micro text-muted-foreground",children:e("settings.gitIdentities.page.discoveredCredentials.title")})}),ze.map((Fe,ye)=>s.jsx(pg,{credential:Fe,onImport:()=>_e("new",{host:Fe.host,username:Fe.username}),hasBorder:ye<ze.length-1},`${Fe.host}-${Fe.username}`))]}),t[6]=i,t[7]=u,t[8]=r,t[9]=b,t[10]=n,t[11]=a,t[12]=m,t[13]=e,t[14]=j,t[15]=F,t[16]=S,t[17]=T,t[18]=v,t[19]=K,t[20]=$,t[21]=w,t[22]=G,t[23]=Q,t[24]=X,t[25]=Z,t[26]=P,t[27]=ee}else j=t[14],F=t[15],S=t[16],T=t[17],v=t[18],K=t[19],$=t[20],w=t[21],G=t[22],Q=t[23],X=t[24],Z=t[25],P=t[26],ee=t[27];let se;t[48]!==$||t[49]!==w||t[50]!==G||t[51]!==Q||t[52]!==X?(se=s.jsxs("div",{className:$,children:[w,G,Q,X]}),t[48]=$,t[49]=w,t[50]=G,t[51]=Q,t[52]=X,t[53]=se):se=t[53];let D;t[54]!==j||t[55]!==se||t[56]!==Z||t[57]!==P||t[58]!==ee?(D=s.jsx(j,{title:Z,headerAction:P,settingsItem:ee,children:se}),t[54]=j,t[55]=se,t[56]=Z,t[57]=P,t[58]=ee,t[59]=D):D=t[59];let O;t[60]===Symbol.for("react.memo_cache_sentinel")?(O=s.jsx(cl,{}),t[60]=O):O=t[60];let U;t[61]!==F||t[62]!==T||t[63]!==v||t[64]!==K||t[65]!==D?(U=s.jsxs(F,{title:T,showSaveStatus:v,children:[K,D,O]}),t[61]=F,t[62]=T,t[63]=v,t[64]=K,t[65]=D,t[66]=U):U=t[66];let A;t[67]!==h||t[68]!==p||t[69]!==k?(A=s.jsx(og,{open:p,onOpenChange:L,profileId:k,importData:h}),t[67]=h,t[68]=p,t[69]=k,t[70]=A):A=t[70];const V=u!==null;let W;t[71]!==q?(W=ze=>{q||ze||E(null)},t[71]=q,t[72]=W):W=t[72];let te;t[73]!==e?(te=e("settings.gitIdentities.page.deleteDialog.title"),t[73]=e,t[74]=te):te=t[74];let ae;t[75]!==te?(ae=s.jsx(Gt,{children:te}),t[75]=te,t[76]=ae):ae=t[76];const le=u?.name??"";let be;t[77]!==e||t[78]!==le?(be=e("settings.gitIdentities.page.deleteDialog.description",{name:le}),t[77]=e,t[78]=le,t[79]=be):be=t[79];let ke;t[80]!==be?(ke=s.jsx(qt,{children:be}),t[80]=be,t[81]=ke):ke=t[81];let ce;t[82]!==ae||t[83]!==ke?(ce=s.jsxs(Ht,{children:[ae,ke]}),t[82]=ae,t[83]=ke,t[84]=ce):ce=t[84];let ge;t[85]===Symbol.for("react.memo_cache_sentinel")?(ge=()=>E(null),t[85]=ge):ge=t[85];let Ee;t[86]!==e?(Ee=e("settings.common.actions.cancel"),t[86]=e,t[87]=Ee):Ee=t[87];let Se;t[88]!==q||t[89]!==Ee?(Se=s.jsx(H,{variant:"ghost",onClick:ge,disabled:q,children:Ee}),t[88]=q,t[89]=Ee,t[90]=Se):Se=t[90];let Ne;t[91]!==S?(Ne=()=>{S()},t[91]=S,t[92]=Ne):Ne=t[92];let fe;t[93]!==e?(fe=e("settings.common.actions.delete"),t[93]=e,t[94]=fe):fe=t[94];let Ke;t[95]!==q||t[96]!==Ne||t[97]!==fe?(Ke=s.jsx(H,{size:"sm",variant:"destructive",onClick:Ne,disabled:q,children:fe}),t[95]=q,t[96]=Ne,t[97]=fe,t[98]=Ke):Ke=t[98];let De;t[99]!==Se||t[100]!==Ke?(De=s.jsxs(os,{children:[Se,Ke]}),t[99]=Se,t[100]=Ke,t[101]=De):De=t[101];let he;t[102]!==ce||t[103]!==De?(he=s.jsxs(Vt,{className:"max-w-md",children:[ce,De]}),t[102]=ce,t[103]=De,t[104]=he):he=t[104];let pe;t[105]!==V||t[106]!==W||t[107]!==he?(pe=s.jsx(Ut,{open:V,onOpenChange:W,children:he}),t[105]=V,t[106]=W,t[107]=he,t[108]=pe):pe=t[108];let Ie;return t[109]!==U||t[110]!==A||t[111]!==pe?(Ie=s.jsxs(s.Fragment,{children:[U,A,pe]}),t[109]=U,t[110]=A,t[111]=pe,t[112]=Ie):Ie=t[112],Ie},mo=t=>{const e=ht.c(56),{profile:a,isDefault:n,onEdit:i,onToggleDefault:r,onDelete:l,isReadOnly:x,hasBorder:c}=t,{t:y}=ot(),[m,b]=o.useState(!1),p=lg[a.icon||"branch"]||"git-branch",L=cg[a.color||""],k=a.authType||"ssh";let N;e[0]!==i?(N=D=>{D.currentTarget===D.target&&(D.key!=="Enter"&&D.key!==" "||(D.preventDefault(),i()))},e[0]=i,e[1]=N):N=e[1];const h=N;let C;e[2]!==n||e[3]!==x||e[4]!==l||e[5]!==r||e[6]!==y?(C=D=>s.jsxs(s.Fragment,{children:[s.jsx(D,{onClick:O=>{O.stopPropagation(),r()},children:y(n?"settings.gitIdentities.page.actions.unsetDefault":"settings.gitIdentities.page.actions.setAsDefault")}),!x&&l&&s.jsxs(D,{onClick:O=>{O.stopPropagation(),l()},className:"text-destructive focus:text-destructive",children:[s.jsx(_,{name:"delete-bin",className:"h-4 w-4 mr-px"}),y("settings.common.actions.delete")]})]}),e[2]=n,e[3]=x,e[4]=l,e[5]=r,e[6]=y,e[7]=C):C=e[7];const u=C,E=c&&"border-b border-[var(--surface-subtle)]";let q;e[8]!==E?(q=je("group flex items-center justify-between gap-3 px-4 py-2.5 transition-colors hover:bg-[var(--interactive-hover)]/30 cursor-pointer",E),e[8]=E,e[9]=q):q=e[9];let M;e[10]===Symbol.for("react.memo_cache_sentinel")?(M=D=>{D.preventDefault(),b(!0)},e[10]=M):M=e[10];let I;e[11]!==h||e[12]!==i||e[13]!==q?(I=s.jsx("div",{className:q,onClick:i,role:"button",tabIndex:0,onKeyDown:h,onContextMenu:M}),e[11]=h,e[12]=i,e[13]=q,e[14]=I):I=e[14];let g;e[15]!==L?(g={color:L},e[15]=L,e[16]=g):g=e[16];let j;e[17]!==p||e[18]!==g?(j=s.jsx(_,{name:p,className:"w-4 h-4 shrink-0",style:g}),e[17]=p,e[18]=g,e[19]=j):j=e[19];let F;e[20]!==a.name?(F=s.jsx("span",{className:"typography-ui-label text-foreground truncate",children:a.name}),e[20]=a.name,e[21]=F):F=e[21];let S;e[22]!==k?(S=s.jsx("span",{className:"typography-micro text-muted-foreground bg-muted px-1 rounded flex-shrink-0 leading-none pb-px border border-border/50",children:k}),e[22]=k,e[23]=S):S=e[23];let T;e[24]!==n||e[25]!==y?(T=n&&s.jsx("span",{className:"typography-micro text-primary bg-primary/12 px-1 rounded flex-shrink-0 leading-none pb-px border border-primary/25",children:y("settings.gitIdentities.page.badge.default")}),e[24]=n,e[25]=y,e[26]=T):T=e[26];let v;e[27]!==x||e[28]!==y?(v=x&&s.jsx("span",{className:"typography-micro text-muted-foreground bg-muted px-1 rounded flex-shrink-0 leading-none pb-px border border-border/50",children:y("settings.agents.sidebar.badge.system")}),e[27]=x,e[28]=y,e[29]=v):v=e[29];let K;e[30]!==S||e[31]!==T||e[32]!==v||e[33]!==F?(K=s.jsxs("div",{className:"flex items-center gap-1.5",children:[F,S,T,v]}),e[30]=S,e[31]=T,e[32]=v,e[33]=F,e[34]=K):K=e[34];const $=k==="token"&&a.host?a.host:a.userEmail;let w;e[35]!==$?(w=s.jsx("div",{className:"typography-micro text-muted-foreground/60 truncate leading-tight",children:$}),e[35]=$,e[36]=w):w=e[36];let G;e[37]!==K||e[38]!==w?(G=s.jsxs("div",{className:"min-w-0",children:[K,w]}),e[37]=K,e[38]=w,e[39]=G):G=e[39];let Q;e[40]!==G||e[41]!==j?(Q=s.jsxs("div",{className:"flex items-center gap-3 min-w-0",children:[j,G]}),e[40]=G,e[41]=j,e[42]=Q):Q=e[42];let X;e[43]===Symbol.for("react.memo_cache_sentinel")?(X=s.jsx($s,{asChild:!0,children:s.jsx(H,{size:"icon",variant:"ghost",className:"h-6 w-6 shrink-0 opacity-100 transition-opacity md:opacity-0 md:group-hover:opacity-100",onClick:ug,children:s.jsx(_,{name:"more-2",className:"h-3.5 w-3.5"})})}),e[43]=X):X=e[43];let Z;e[44]!==u?(Z=s.jsxs(Hs,{children:[X,s.jsx(Bs,{align:"end",className:"w-fit min-w-28",children:u(Gs)})]}),e[44]=u,e[45]=Z):Z=e[45];let P;e[46]!==Q||e[47]!==Z||e[48]!==I?(P=s.jsxs(Rn,{render:I,children:[Q,Z]}),e[46]=Q,e[47]=Z,e[48]=I,e[49]=P):P=e[49];let ee;e[50]!==u?(ee=s.jsx(Dn,{className:"w-fit min-w-28",children:u(Mn)}),e[50]=u,e[51]=ee):ee=e[51];let se;return e[52]!==m||e[53]!==P||e[54]!==ee?(se=s.jsxs(On,{open:m,onOpenChange:b,children:[P,ee]}),e[52]=m,e[53]=P,e[54]=ee,e[55]=se):se=e[55],se},pg=t=>{const e=ht.c(21),{credential:a,onImport:n,hasBorder:i}=t,{t:r}=ot();let l;e[0]!==a.host?(l=a.host.split("/"),e[0]=a.host,e[1]=l):l=e[1];const x=l,c=x.length>=3?x[x.length-1]:a.host,y=a.host.includes("/"),m=i&&"border-b border-[var(--surface-subtle)]";let b;e[2]!==m?(b=je("flex items-center justify-between gap-3 px-4 py-2.5 transition-colors hover:bg-[var(--interactive-hover)]/30",m),e[2]=m,e[3]=b):b=e[3];let p;e[4]!==c?(p=s.jsx("span",{className:"typography-ui-label text-foreground truncate block",children:c}),e[4]=c,e[5]=p):p=e[5];const L=y?a.host:a.username;let k;e[6]!==L?(k=s.jsx("span",{className:"typography-micro text-muted-foreground/60 truncate block leading-tight",children:L}),e[6]=L,e[7]=k):k=e[7];let N;e[8]!==p||e[9]!==k?(N=s.jsxs("div",{className:"min-w-0",children:[p,k]}),e[8]=p,e[9]=k,e[10]=N):N=e[10];let h;e[11]===Symbol.for("react.memo_cache_sentinel")?(h=s.jsx(_,{name:"download",className:"h-3 w-3"}),e[11]=h):h=e[11];let C;e[12]!==r?(C=r("settings.gitIdentities.page.actions.import"),e[12]=r,e[13]=C):C=e[13];let u;e[14]!==n||e[15]!==C?(u=s.jsxs(H,{size:"sm",variant:"ghost",onClick:n,className:"gap-1 shrink-0",children:[h,C]}),e[14]=n,e[15]=C,e[16]=u):u=e[16];let E;return e[17]!==u||e[18]!==b||e[19]!==N?(E=s.jsxs("div",{className:b,children:[N,u]}),e[17]=u,e[18]=b,e[19]=N,e[20]=E):E=e[20],E};function mg(t){return{profiles:t.profiles,globalIdentity:t.globalIdentity,defaultGitIdentityId:t.defaultGitIdentityId,deleteProfile:t.deleteProfile,loadProfiles:t.loadProfiles,loadGlobalIdentity:t.loadGlobalIdentity,loadDiscoveredCredentials:t.loadDiscoveredCredentials,loadDefaultGitIdentityId:t.loadDefaultGitIdentityId,setDefaultGitIdentityId:t.setDefaultGitIdentityId,getUnimportedCredentials:t.getUnimportedCredentials}}function ug(t){return t.stopPropagation()}const gg=[{value:"system",labelKey:"settings.openchamber.visual.option.themeMode.system",descriptionKey:"settings.openchamber.visual.option.themeMode.system.description"},{value:"light",labelKey:"settings.openchamber.visual.option.themeMode.light",descriptionKey:"settings.openchamber.visual.option.themeMode.light.description"},{value:"dark",labelKey:"settings.openchamber.visual.option.themeMode.dark",descriptionKey:"settings.openchamber.visual.option.themeMode.dark.description"}],hg=[{id:"dynamic",labelKey:"settings.openchamber.visual.option.diffLayout.dynamic.label",descriptionKey:"settings.openchamber.visual.option.diffLayout.dynamic.description"},{id:"inline",labelKey:"settings.openchamber.visual.option.diffLayout.inline.label",descriptionKey:"settings.openchamber.visual.option.diffLayout.inline.description"},{id:"side-by-side",labelKey:"settings.openchamber.visual.option.diffLayout.sideBySide.label",descriptionKey:"settings.openchamber.visual.option.diffLayout.sideBySide.description"}],fg=[{id:"svg",labelKey:"settings.openchamber.visual.option.mermaidRendering.svg.label",descriptionKey:"settings.openchamber.visual.option.mermaidRendering.svg.description"},{id:"ascii",labelKey:"settings.openchamber.visual.option.mermaidRendering.ascii.label",descriptionKey:"settings.openchamber.visual.option.mermaidRendering.ascii.description"}],la="OpenChamber - AI Coding Assistant",uo=[{id:"system",labelKey:"settings.openchamber.visual.option.pwaOrientation.system.label",descriptionKey:"settings.openchamber.visual.option.pwaOrientation.system.description"},{id:"portrait",labelKey:"settings.openchamber.visual.option.pwaOrientation.portrait.label",descriptionKey:"settings.openchamber.visual.option.pwaOrientation.portrait.description"},{id:"landscape",labelKey:"settings.openchamber.visual.option.pwaOrientation.landscape.label",descriptionKey:"settings.openchamber.visual.option.pwaOrientation.landscape.description"}],go=[{id:"native",labelKey:"settings.openchamber.visual.option.mobileKeyboardMode.native.label",descriptionKey:"settings.openchamber.visual.option.mobileKeyboardMode.native.description"},{id:"resize-content",labelKey:"settings.openchamber.visual.option.mobileKeyboardMode.resizeContent.label",descriptionKey:"settings.openchamber.visual.option.mobileKeyboardMode.resizeContent.description"}],xg=[{value:"default",labelKey:"settings.openchamber.visual.option.mobileLayout.default"},{value:"new",labelKey:"settings.openchamber.visual.option.mobileLayout.new"}],Pi=t=>t==="portrait"||t==="landscape"?t:"system",bg=[{id:"markdown",labelKey:"settings.openchamber.visual.option.userMessageRendering.markdown.label",descriptionKey:"settings.openchamber.visual.option.userMessageRendering.markdown.description"},{id:"plain",labelKey:"settings.openchamber.visual.option.userMessageRendering.plain.label",descriptionKey:"settings.openchamber.visual.option.userMessageRendering.plain.description"}],vg=[{id:"sorted",labelKey:"settings.openchamber.visual.option.chatRenderMode.sorted.label",descriptionKey:"settings.openchamber.visual.option.chatRenderMode.sorted.description"},{id:"live",labelKey:"settings.openchamber.visual.option.chatRenderMode.live.label",descriptionKey:"settings.openchamber.visual.option.chatRenderMode.live.description"}],ho=[{id:"auto",labelKey:"settings.openchamber.visual.option.messageTransport.auto.label",descriptionKey:"settings.openchamber.visual.option.messageTransport.auto.description"},{id:"ws",labelKey:"settings.openchamber.visual.option.messageTransport.ws.label",descriptionKey:"settings.openchamber.visual.option.messageTransport.ws.description"},{id:"sse",labelKey:"settings.openchamber.visual.option.messageTransport.sse.label",descriptionKey:"settings.openchamber.visual.option.messageTransport.sse.description"}],yg=[{id:"collapsed",labelKey:"settings.openchamber.visual.option.activityRenderMode.collapsed.label",descriptionKey:"settings.openchamber.visual.option.activityRenderMode.collapsed.description"},{id:"summary",labelKey:"settings.openchamber.visual.option.activityRenderMode.summary.label",descriptionKey:"settings.openchamber.visual.option.activityRenderMode.summary.description"}],fo=[{id:"auto",labelKey:"settings.openchamber.visual.option.timeFormat.auto.label",descriptionKey:"settings.openchamber.visual.option.timeFormat.auto.description"},{id:"24h",labelKey:"settings.openchamber.visual.option.timeFormat.24h.label",descriptionKey:"settings.openchamber.visual.option.timeFormat.24h.description"},{id:"12h",labelKey:"settings.openchamber.visual.option.timeFormat.12h.label",descriptionKey:"settings.openchamber.visual.option.timeFormat.12h.description"}],xo=[{id:"auto",labelKey:"settings.openchamber.visual.option.weekStart.auto.label",descriptionKey:"settings.openchamber.visual.option.weekStart.auto.description"},{id:"monday",labelKey:"settings.openchamber.visual.option.weekStart.monday.label"},{id:"sunday",labelKey:"settings.openchamber.visual.option.weekStart.sunday.label"}],jg=[{id:"steer",labelKey:"settings.openchamber.visual.option.followUpBehavior.steer.label"},{id:"queue",labelKey:"settings.openchamber.visual.option.followUpBehavior.queue.label"}],wg=t=>t==="markdown"?"markdown":"plain",Ng=[{id:"left",labelKey:"settings.openchamber.desktopNetwork.option.windowControlsLeft"},{id:"right",labelKey:"settings.openchamber.desktopNetwork.option.windowControlsRight"}],kg=[{id:"classic",labelKey:"settings.openchamber.desktopNetwork.option.windowControlsClassic"},{id:"traffic-lights",labelKey:"settings.openchamber.desktopNetwork.option.windowControlsTrafficLights"}],Xa=({visibleSettings:t})=>{const{locale:e,locales:a,setLocale:n,label:i,t:r}=ot(),l=o.useCallback(d=>r(d),[r]),{isMobile:x}=Jn(),{terminal:c}=Mo(),{browserTab:y}=Xc(),m=Fc(),b=de(d=>d.showReasoningTraces),p=de(d=>d.sessionRecapEnabled),L=de(d=>d.sessionSuggestionEnabled),k=de(d=>d.setSessionRecapEnabled),N=de(d=>d.setSessionSuggestionEnabled),h=de(d=>d.sessionGoalEnabled),C=de(d=>d.setSessionGoalEnabled),u=de(d=>d.sessionGoalDefaultBudgetEnabled),E=de(d=>d.setSessionGoalDefaultBudgetEnabled),q=de(d=>d.sessionGoalDefaultBudget),M=de(d=>d.setSessionGoalDefaultBudget),I=de(d=>d.setShowReasoningTraces),g=de(d=>d.collapsibleThinkingBlocks),j=de(d=>d.setCollapsibleThinkingBlocks),F=de(d=>d.mermaidRenderingMode),S=de(d=>d.setMermaidRenderingMode),T=de(d=>d.userMessageRenderingMode),v=de(d=>d.setUserMessageRenderingMode),K=de(d=>d.collapsibleUserMessages),$=de(d=>d.setCollapsibleUserMessages),w=de(d=>d.stickyUserHeader),G=de(d=>d.promptNavigatorEnabled),Q=de(d=>d.setStickyUserHeader),X=de(d=>d.setPromptNavigatorEnabled),Z=de(d=>d.expandedEditorToolbar),P=de(d=>d.setExpandedEditorToolbar),ee=de(d=>d.autoSaveEnabled),se=de(d=>d.setAutoSaveEnabled),D=de(d=>d.wideChatLayoutEnabled),O=de(d=>d.setWideChatLayoutEnabled),U=de(d=>d.codeBlockLineWrap),A=de(d=>d.setCodeBlockLineWrap),V=de(d=>d.chatRenderMode),W=de(d=>d.setChatRenderMode),te=de(d=>d.activityRenderMode),ae=de(d=>d.setActivityRenderMode),le=de(d=>d.fontSize),be=de(d=>d.setFontSize),ke=de(d=>d.terminalFontSize),ce=de(d=>d.setTerminalFontSize),ge=de(d=>d.terminalShell),Ee=de(d=>d.setTerminalShell),Se=de(d=>d.terminalLoginShells),Ne=de(d=>d.setTerminalLoginShells),fe=de(d=>d.editorFontSize),Ke=de(d=>d.setEditorFontSize),De=de(d=>d.uiFont),he=de(d=>d.setUiFont),pe=de(d=>d.monoFont),Ie=de(d=>d.setMonoFont),ze=de(d=>d.padding),Je=de(d=>d.setPadding),_e=de(d=>d.inputBarOffset),Le=de(d=>d.setInputBarOffset),Pe=de(d=>d.mobileKeyboardMode),Ye=de(d=>d.setMobileKeyboardMode),Ge=de(d=>d.diffLayoutPreference),Me=de(d=>d.setDiffLayoutPreference),$e=de(d=>d.showTerminalQuickKeysOnDesktop),Fe=de(d=>d.setShowTerminalQuickKeysOnDesktop),ye=de(d=>d.fileEditorKeymap),z=de(d=>d.setFileEditorKeymap),oe=jr(d=>d.followUpBehavior),me=jr(d=>d.setFollowUpBehavior),ve=de(d=>d.persistChatDraft),re=de(d=>d.setPersistChatDraft),Ve=de(d=>d.inputSpellcheckEnabled),Ze=de(d=>d.setInputSpellcheckEnabled),B=de(d=>d.showToolFileIcons),Ue=de(d=>d.setShowToolFileIcons),Qe=de(d=>d.showTurnChangedFiles),et=de(d=>d.setShowTurnChangedFiles),tt=de(d=>d.showExpandedBashTools),wt=de(d=>d.setShowExpandedBashTools),mt=de(d=>d.showExpandedEditTools),pt=de(d=>d.setShowExpandedEditTools),at=de(d=>d.timeFormatPreference),ft=de(d=>d.setTimeFormatPreference),gt=de(d=>d.weekStartPreference),Ct=de(d=>d.setWeekStartPreference),ie=de(d=>d.showSplitAssistantMessageActions),Ae=de(d=>d.setShowSplitAssistantMessageActions),Be=de(d=>d.allowPromptingSubagentSessions),qe=de(d=>d.setAllowPromptingSubagentSessions),Nt=de(d=>d.draftStartersVisible),xt=de(d=>d.setDraftStartersVisible),zt=nt(d=>d.settingsMessageStreamTransport),J=nt(d=>d.setSettingsMessageStreamTransport),xe=zt,Re=nt(d=>d.settingsDefaultFileViewerPreview),we=nt(d=>d.setSettingsDefaultFileViewerPreview),rt=de(d=>d.isSettingsDialogOpen),{themeMode:lt,setThemeMode:it,availableThemes:It,customThemesLoading:ls,reloadCustomThemes:Xt,lightThemeId:ts,darkThemeId:Wt,setLightThemePreference:kt,setDarkThemePreference:bt}=Yi(),[Pt,St]=o.useState(!1),Ft=o.useMemo(()=>is()&&typeof window<"u"&&window.__OPENCHAMBER_PLATFORM__==="darwin",[]),Bt=de(d=>d.dockBadgeEnabled),hs=de(d=>d.setDockBadgeEnabled),Y=Kc(),Ce=de(d=>d.desktopWindowControlsPosition),st=de(d=>d.setDesktopWindowControlsPosition),At=de(d=>d.desktopWindowControlsStyle),jt=de(d=>d.setDesktopWindowControlsStyle),[Jt,fs]=o.useState(0),cs=de(d=>d.reportUsage),Ts=de(d=>d.setReportUsage),Ws=o.useCallback(d=>{Ts(d),yt({reportUsage:d})},[Ts]),ei=o.useCallback(d=>{st(d),yt({desktopWindowControlsPosition:d})},[st]),ti=o.useCallback(d=>{jt(d),yt({desktopWindowControlsStyle:d})},[jt]),Ss=(rt||x||ds())&&(t?t.includes("chatRenderMode"):!0);o.useEffect(()=>{if(!Ss)return;let d=null,vt=Date.now();const xs=()=>{const en=Date.now();en-vt>=420&&(fs(Sn=>(Sn+1)%24),vt=en),d=requestAnimationFrame(xs)};(typeof document>"u"||document.visibilityState==="visible")&&(d=requestAnimationFrame(xs));const ms=()=>{document.visibilityState==="visible"&&d===null?d=requestAnimationFrame(xs):document.visibilityState!=="visible"&&d!==null&&(cancelAnimationFrame(d),d=null)};return document.addEventListener("visibilitychange",ms),()=>{document.removeEventListener("visibilitychange",ms),d!==null&&cancelAnimationFrame(d)}},[Ss]);const Qn=o.useCallback(d=>{v(d),yt({userMessageRenderingMode:d})},[v]),si=o.useCallback(d=>{Q(d),yt({stickyUserHeader:d})},[Q]),Sa=o.useCallback(d=>{X(d),yt({promptNavigatorEnabled:d})},[X]),ni=o.useCallback(d=>{xt(d),yt({draftStartersVisible:d})},[xt]),ai=o.useCallback(d=>{P(d),yt({expandedEditorToolbar:d})},[P]),ii=o.useCallback(d=>{$(d),yt({collapsibleUserMessages:d})},[$]),ri=o.useCallback(d=>{O(d),yt({wideChatLayoutEnabled:d})},[O]),oi=o.useCallback(d=>{Ae(d),yt({showSplitAssistantMessageActions:d})},[Ae]),Cs=o.useCallback(d=>{Ze(d),yt({inputSpellcheckEnabled:d})},[Ze]),Ks=o.useCallback(d=>{W(d),yt({chatRenderMode:d})},[W]),Fn=o.useCallback(d=>{J(d),yt({messageStreamTransport:d})},[J]),Js=o.useCallback(d=>{ae(d),yt({activityRenderMode:d})},[ae]),ln=o.useCallback(d=>{S(d),yt({mermaidRenderingMode:d})},[S]),nr=o.useCallback(d=>{Ue(d),yt({showToolFileIcons:d})},[Ue]),cn=o.useCallback(d=>{et(d),yt({showTurnChangedFiles:d})},[et]),li=o.useCallback(d=>{we(d),yt({defaultFileViewerPreview:d}),window.dispatchEvent(new CustomEvent("openchamber:file-viewer-preview-mode-changed",{detail:{enabled:d}}))},[we]),Kn=o.useCallback(d=>{wt(d),yt({showExpandedBashTools:d})},[wt]),ci=o.useCallback(d=>{pt(d),yt({showExpandedEditTools:d})},[pt]),ps=o.useCallback(d=>{ft(d),yt({timeFormatPreference:d})},[ft]),di=o.useCallback(d=>{Ct(d),yt({weekStartPreference:d})},[Ct]),Qs=o.useMemo(()=>It.filter(d=>d.metadata.variant==="light").sort((d,vt)=>d.metadata.name.localeCompare(vt.metadata.name)),[It]),Ys=o.useMemo(()=>It.filter(d=>d.metadata.variant==="dark").sort((d,vt)=>d.metadata.name.localeCompare(vt.metadata.name)),[It]),Yn=o.useMemo(()=>Qs.find(d=>d.metadata.id===ts)??Qs[0],[Qs,ts]),_n=o.useMemo(()=>Ys.find(d=>d.metadata.id===Wt)??Ys[0],[Ys,Wt]),Zs=o.useCallback((d,vt)=>{const xs=vt==="dark"?" Dark":" Light";return d.endsWith(xs)?d.slice(0,-xs.length):d},[]),ue=d=>t?t.includes(d):!0,ns=ds(),wn=ue("theme")&&!ns,Ca=ue("windowControlsPosition")&&Y,Ia=ue("theme")||ue("timeFormat")||ue("weekStart"),Pa=x&&yn()&&!is()&&!ns,Aa=ns?Ia:ue("theme")||Ca||Pa||ue("pwaInstallName")||ue("pwaOrientation")||ue("timeFormat")||ue("weekStart"),Ta=ue("fontSize")||ue("terminalFontSize")||ue("editorFontSize")||ue("spacing")||ue("inputBarOffset")&&x,Ea=ue("terminalQuickKeys")&&!x||(ue("terminalShell")||ue("terminalLoginShell"))&&!ns||ue("fileEditorKeymap")||ue("autoSaveEnabled")||ue("expandedEditorToolbar")&&!ns,pi=ue("mermaidRendering")||ue("sessionGoal")&&!ns||ue("userMessageRendering")||ue("chatRenderMode")||ue("messageTransport")||ue("activityRenderMode")&&V==="sorted"||ue("collapsibleUserMessages")||ue("stickyUserHeader")||ue("promptNavigatorEnabled")&&!ns||ue("wideChatLayout")||ue("codeBlockLineWrap")||ue("splitAssistantMessageActions")||ue("subagentReadOnlyBanner")||ue("diffLayout")||ue("dotfiles")||ue("fileViewerPreview")||ue("reasoning")||ue("followUpBehavior")||ue("persistDraft")||ue("showToolFileIcons")||ue("expandedTools")||!x&&ue("inputSpellcheck"),zn=ue("chatRenderMode")||ue("activityRenderMode")&&V==="sorted",Un=ue("messageTransport"),Da=ue("userMessageRendering")||ue("mermaidRendering")||ue("diffLayout")&&!ns||ue("followUpBehavior"),f=ue("sessionAssist")||ue("sessionGoal")&&!ns||ue("subagentReadOnlyBanner")||ue("collapsibleUserMessages")||ue("stickyUserHeader")||ue("promptNavigatorEnabled")&&!ns||ue("wideChatLayout")||ue("codeBlockLineWrap")||ue("splitAssistantMessageActions")||ue("dotfiles")||ue("fileViewerPreview")||ue("persistDraft")||ue("showToolFileIcons")||ue("showTurnChangedFiles")||!x&&ue("inputSpellcheck")||ue("reasoning")||ue("expandedTools"),ne=Aa||Ta||Ea,Te=ue("pwaInstallName")&&yn()&&y&&!is()&&!ns,Xe=ue("pwaOrientation")&&yn()&&!is()&&!ns,Lt=ue("mobileKeyboardMode")&&yn()&&!is()&&!ns&&_c(),js=(ue("terminalShell")||ue("terminalLoginShell"))&&!ns,[es,Es]=o.useState([]),[Xs,Ms]=o.useState(0);o.useEffect(()=>zo(()=>{Es([]),Ms(d=>d+1)}),[]),o.useEffect(()=>{let d=!1;if(!(!js||!c.listShells))return c.listShells().then(vt=>{d||Es(vt)}).catch(()=>{d||Es([])}),()=>{d=!0}},[js,c,Xs]);const Zn=o.useMemo(()=>{const d=es.filter(vt=>vt.id!=="auto");return ge==="auto"||d.some(vt=>vt.id===ge)?d:[{id:ge,name:ge,supportsLogin:!1},...d]},[es,ge]),Nn=es.find(d=>d.id===ge)?.supportsLogin===!0,Xn=Se.includes(ge),Tt=d=>{Ne(d?[...Se.filter(vt=>vt!==ge),ge]:Se.filter(vt=>vt!==ge))},[Zt,kn]=o.useState(()=>cd()),[Ot,as]=o.useState(""),[_s,Rs]=o.useState("system"),Ma=o.useMemo(()=>{const d=fo.find(vt=>vt.id===at);return l(d?.labelKey??"settings.openchamber.visual.option.timeFormat.auto.label")},[at,l]),wl=o.useMemo(()=>{const d=xo.find(vt=>vt.id===gt);return l(d?.labelKey??"settings.openchamber.visual.option.weekStart.auto.label")},[gt,l]),Nl=o.useMemo(()=>{const d=uo.find(vt=>vt.id===_s);return d?l(d.labelKey):void 0},[_s,l]),kl=o.useMemo(()=>{const d=go.find(vt=>vt.id===Pe);return d?l(d.labelKey):void 0},[Pe,l]),Sl=o.useCallback(d=>{d!==Zt&&(kn(d),dd(d),window.location.reload())},[Zt]),mi=o.useCallback(async d=>{if(typeof window>"u")return;const vt=window,ms=d.trim().replace(/\s+/g," ").slice(0,64);if(await yt({pwaAppName:ms}),typeof vt.__OPENCHAMBER_SET_PWA_INSTALL_NAME__=="function"){const en=vt.__OPENCHAMBER_SET_PWA_INSTALL_NAME__(ms);as(en);return}as(ms||la),vt.__OPENCHAMBER_UPDATE_PWA_MANIFEST__?.()},[]),ar=o.useCallback(async d=>{if(typeof window>"u")return;const vt=window,xs=Pi(d);if(await yt({pwaOrientation:xs}),typeof vt.__OPENCHAMBER_SET_PWA_ORIENTATION__=="function"){const ms=vt.__OPENCHAMBER_SET_PWA_ORIENTATION__(xs);Rs(ms);return}Rs(xs),vt.__OPENCHAMBER_UPDATE_PWA_MANIFEST__?.()},[]);return o.useEffect(()=>{if(typeof window>"u"||!Te&&!Xe&&!Lt)return;let d=!1;return(async()=>{try{const xs=await ct("/api/config/settings",{method:"GET",headers:{Accept:"application/json"},cache:"no-store"});if(!xs.ok){d||as(la);return}const ms=await xs.json().catch(()=>({})),Sn=(typeof ms?.pwaAppName=="string"?ms.pwaAppName:"").trim().replace(/\s+/g," ").slice(0,64),Ra=Pi(ms?.pwaOrientation),ui=Cr(ms?.mobileKeyboardMode);d||(Te&&as(Sn||la),Xe&&Rs(Ra),Lt&&Ye(ui))}catch{d||(Te&&as(la),Xe&&Rs("system"),Lt&&Ye("native"))}})(),()=>{d=!0}},[Ye,Lt,Te,Xe]),s.jsxs("div",{className:"space-y-0",children:[Aa&&s.jsxs("div",{className:"space-y-0",children:[wn&&s.jsxs(Oe,{title:r("settings.openchamber.visual.section.colorModeAndTheme"),divider:!1,children:[s.jsxs(fn,{children:[s.jsxs("div",{className:xn,children:[s.jsx(gn,{"aria-label":r("settings.openchamber.visual.section.colorMode"),children:gg.map(d=>s.jsx(hn,{selected:lt===d.value,onSelect:()=>it(d.value),label:l(d.labelKey),ariaLabel:l(d.labelKey)},d.value))}),Pa&&s.jsx(Wn,{children:s.jsx(Qt,{label:r("settings.openchamber.visual.section.mobileLayout"),children:s.jsx(Ls,{value:Zt,options:xg.map(d=>({value:d.value,label:l(d.labelKey)})),onChange:Sl,"aria-label":r("settings.openchamber.visual.section.mobileLayout")})})})]}),s.jsxs("div",{className:xn,children:[s.jsx(Qt,{label:r("settings.openchamber.visual.field.lightTheme"),settingsItem:"appearance.light-theme",children:s.jsxs(Dt,{value:Yn?.metadata.id??"",onValueChange:kt,children:[s.jsx(Mt,{"aria-label":r("settings.openchamber.visual.field.selectLightThemeAria"),size:Kt,className:sn,children:s.jsx(_t,{placeholder:r("settings.openchamber.visual.field.selectThemePlaceholder"),children:Yn?Zs(Yn.metadata.name,"light"):void 0})}),s.jsx(Rt,{children:Qs.map(d=>s.jsx(dt,{value:d.metadata.id,children:Zs(d.metadata.name,"light")},d.metadata.id))})]})}),s.jsx(Qt,{label:r("settings.openchamber.visual.field.darkTheme"),settingsItem:"appearance.dark-theme",children:s.jsxs(Dt,{value:_n?.metadata.id??"",onValueChange:bt,children:[s.jsx(Mt,{"aria-label":r("settings.openchamber.visual.field.selectDarkThemeAria"),size:Kt,className:sn,children:s.jsx(_t,{placeholder:r("settings.openchamber.visual.field.selectThemePlaceholder"),children:_n?Zs(_n.metadata.name,"dark"):void 0})}),s.jsx(Rt,{children:Ys.map(d=>s.jsx(dt,{value:d.metadata.id,children:Zs(d.metadata.name,"dark")},d.metadata.id))})]})}),s.jsxs("div",{className:"flex items-center gap-2 pt-1",children:[s.jsxs("button",{type:"button",disabled:ls||Pt,onClick:()=>{const d=Date.now();St(!0),Xt().finally(()=>{const vt=Date.now()-d;if(vt<500){window.setTimeout(()=>{St(!1)},500-vt);return}St(!1)})},className:"typography-settings-link inline-flex items-center gap-1.5 disabled:cursor-not-allowed disabled:opacity-50 disabled:no-underline",children:[s.jsx(_,{name:"restart",className:je("h-3.5 w-3.5",Pt&&"animate-spin")}),r(Pt?"settings.openchamber.visual.actions.reloadingThemes":"settings.openchamber.visual.actions.reloadThemes")]}),s.jsx(Yt,{children:r("settings.openchamber.visual.field.themeImportInfoTooltip")})]})]})]}),Ft&&s.jsx(Wn,{settingsItem:"appearance.dock-badge",children:s.jsx(ut,{checked:Bt,onChange:hs,label:r("settings.openchamber.visual.field.dockBadge"),info:r("settings.openchamber.visual.field.dockBadgeHint"),ariaLabel:r("settings.openchamber.visual.field.dockBadge")})})]}),Ca&&s.jsx(Oe,{title:r("settings.openchamber.desktopNetwork.field.windowControls"),info:r("settings.openchamber.desktopNetwork.field.windowControlsPositionDescription"),divider:wn,children:s.jsxs(fn,{children:[s.jsx(Qt,{label:r("settings.openchamber.desktopNetwork.field.windowControlsPosition"),settingsItem:"sessions.desktop-window-controls-position",children:s.jsx(Ls,{value:Ce,options:Ng.map(d=>({value:d.id,label:l(d.labelKey)})),onChange:ei,"aria-label":r("settings.openchamber.desktopNetwork.field.windowControlsPositionAria")})}),s.jsx(Qt,{label:r("settings.openchamber.desktopNetwork.field.windowControlsStyle"),settingsItem:"sessions.desktop-window-controls-style",children:s.jsx(Ls,{value:At,options:kg.map(d=>({value:d.id,label:l(d.labelKey)})),onChange:ti,"aria-label":r("settings.openchamber.desktopNetwork.field.windowControlsStyleAria")})})]})}),Ia&&s.jsx(Oe,{title:r("settings.openchamber.visual.section.localization"),children:s.jsxs(fn,{children:[s.jsx(Qt,{label:r("settings.appearance.language.label"),info:r("settings.appearance.language.description"),settingsItem:"appearance.language",children:s.jsxs(Dt,{value:e,onValueChange:d=>n(d),children:[s.jsx(Mt,{"aria-label":r("settings.appearance.language.select"),size:Kt,className:sn,children:s.jsx(_t,{children:i(e)})}),s.jsx(Rt,{children:a.map(d=>s.jsx(dt,{value:d,children:i(d)},d))})]})}),(ue("timeFormat")||ue("weekStart"))&&s.jsxs("div",{className:xn,children:[ue("timeFormat")&&s.jsx(Qt,{label:r("settings.openchamber.visual.field.timeFormat"),settingsItem:"appearance.time-format",children:s.jsxs(Dt,{value:at,onValueChange:d=>ps(d),children:[s.jsx(Mt,{"aria-label":r("settings.openchamber.visual.field.selectTimeFormatAria"),size:Kt,className:sn,children:s.jsx(_t,{children:Ma})}),s.jsx(Rt,{children:fo.map(d=>s.jsx(dt,{value:d.id,children:l(d.labelKey)},d.id))})]})}),ue("weekStart")&&s.jsx(Qt,{label:r("settings.openchamber.visual.field.weekStartsOn"),settingsItem:"appearance.week-start",children:s.jsxs(Dt,{value:gt,onValueChange:d=>di(d),children:[s.jsx(Mt,{"aria-label":r("settings.openchamber.visual.field.selectWeekStartAria"),size:Kt,className:sn,children:s.jsx(_t,{children:wl})}),s.jsx(Rt,{children:xo.map(d=>s.jsx(dt,{value:d.id,children:l(d.labelKey)},d.id))})]})})]})]})}),(Te||Xe||Lt)&&s.jsxs(Oe,{title:r("settings.openchamber.visual.section.appInstall"),contentClassName:xn,children:[Te&&s.jsxs($t,{label:r("settings.openchamber.visual.field.installAppName"),info:r("settings.openchamber.visual.field.installAppNameHint"),settingsItem:"appearance.pwa-install-name",alignEnd:!1,controlClassName:As,children:[s.jsx(He,{value:Ot,onChange:d=>{as(d.target.value)},onBlur:()=>{mi(Ot)},onKeyDown:d=>{d.key==="Enter"&&(d.preventDefault(),mi(Ot))},className:"min-w-0 flex-1",maxLength:64,"aria-label":r("settings.openchamber.visual.field.pwaInstallAppNameAria")}),s.jsx(H,{size:"sm",type:"button",variant:"ghost",onClick:()=>{as(la),mi("")},className:gs,"aria-label":r("settings.openchamber.visual.actions.resetInstallAppNameAria"),title:r("settings.common.actions.reset"),children:s.jsx(_,{name:"restart",className:"h-3.5 w-3.5"})})]}),Xe&&s.jsxs($t,{label:r("settings.openchamber.visual.field.installOrientation"),description:r("settings.openchamber.visual.field.installOrientationHint"),settingsItem:"appearance.pwa-orientation",alignEnd:!1,controlClassName:As,children:[s.jsxs(Dt,{value:_s,onValueChange:d=>{const vt=Pi(d);Rs(vt),ar(vt)},children:[s.jsx(Mt,{"aria-label":r("settings.openchamber.visual.field.pwaInstallOrientationAria"),size:Kt,className:pr,children:s.jsx(_t,{placeholder:r("settings.openchamber.visual.field.selectOrientationPlaceholder"),children:Nl})}),s.jsx(Rt,{children:uo.map(d=>s.jsx(dt,{value:d.id,children:l(d.labelKey)},d.id))})]}),s.jsx(H,{size:"sm",type:"button",variant:"ghost",onClick:()=>{Rs("system"),ar("system")},disabled:_s==="system",className:gs,"aria-label":r("settings.openchamber.visual.actions.resetInstallOrientationAria"),title:r("settings.common.actions.reset"),children:s.jsx(_,{name:"restart",className:"h-3.5 w-3.5"})})]}),Lt&&s.jsxs($t,{label:r("settings.openchamber.visual.field.mobileKeyboardMode"),info:r("settings.openchamber.visual.field.mobileKeyboardModeHint"),settingsItem:"appearance.mobile-keyboard-mode",alignEnd:!1,controlClassName:As,children:[s.jsxs(Dt,{value:Pe,onValueChange:d=>{const vt=Cr(d);Ye(vt),yt({mobileKeyboardMode:vt})},children:[s.jsx(Mt,{"aria-label":r("settings.openchamber.visual.field.mobileKeyboardModeAria"),size:Kt,className:pr,children:s.jsx(_t,{placeholder:r("settings.openchamber.visual.field.selectMobileKeyboardModePlaceholder"),children:kl})}),s.jsx(Rt,{children:go.map(d=>s.jsx(dt,{value:d.id,children:l(d.labelKey)},d.id))})]}),s.jsx(H,{size:"sm",type:"button",variant:"ghost",onClick:()=>{Ye("native"),yt({mobileKeyboardMode:"native"})},disabled:Pe==="native",className:gs,"aria-label":r("settings.openchamber.visual.actions.resetMobileKeyboardModeAria"),title:r("settings.common.actions.reset"),children:s.jsx(_,{name:"restart",className:"h-3.5 w-3.5"})})]})]})]}),Ta&&s.jsxs(Oe,{title:r("settings.openchamber.visual.section.densityAndType"),contentClassName:xn,children:[ue("fontSize")&&!x||ue("terminalFontSize")?s.jsxs(fn,{children:[ue("fontSize")&&!x&&s.jsxs(Qt,{label:r("settings.openchamber.visual.field.interfaceFont"),settingsItem:"appearance.interface-font-size",controlClassName:"w-full",children:[s.jsxs(Dt,{value:De,onValueChange:d=>he(d),children:[s.jsx(Mt,{"aria-label":r("settings.openchamber.visual.field.selectInterfaceFontAria"),size:Kt,className:sn,children:s.jsx(_t,{children:wr.find(d=>d.id===De)?.label})}),s.jsx(Rt,{children:wr.map(d=>s.jsx(dt,{value:d.id,children:s.jsx("span",{style:{fontFamily:d.stack},children:d.label})},d.id))})]}),s.jsx(H,{size:"sm",type:"button",variant:"ghost",onClick:()=>he(Nr),disabled:De===Nr,className:gs,"aria-label":r("settings.openchamber.visual.actions.resetInterfaceFontAria"),title:r("settings.common.actions.reset"),children:s.jsx(_,{name:"restart",className:"h-3.5 w-3.5"})})]}),ue("terminalFontSize")&&s.jsxs(Qt,{label:r("settings.openchamber.visual.field.codeFont"),controlClassName:"w-full",children:[s.jsxs(Dt,{value:pe,onValueChange:d=>Ie(d),children:[s.jsx(Mt,{"aria-label":r("settings.openchamber.visual.field.selectCodeFontAria"),size:Kt,className:sn,children:s.jsx(_t,{children:kr.find(d=>d.id===pe)?.label})}),s.jsx(Rt,{children:kr.map(d=>s.jsx(dt,{value:d.id,children:s.jsx("span",{style:{fontFamily:d.stack},children:d.label})},d.id))})]}),s.jsx(H,{size:"sm",type:"button",variant:"ghost",onClick:()=>Ie(Sr),disabled:pe===Sr,className:gs,"aria-label":r("settings.openchamber.visual.actions.resetCodeFontAria"),title:r("settings.common.actions.reset"),children:s.jsx(_,{name:"restart",className:"h-3.5 w-3.5"})})]})]}):null,ue("fontSize")&&!x||ue("terminalFontSize")||ue("editorFontSize")?s.jsxs(fn,{children:[ue("fontSize")&&!x&&s.jsx(Qt,{label:r("settings.openchamber.visual.field.interfaceFontSize"),controlClassName:"w-full",children:s.jsxs("div",{className:ta,children:[s.jsx(ys,{value:le,onValueChange:be,min:50,max:200,step:5,"aria-label":r("settings.openchamber.visual.field.fontSizePercentageAria")}),s.jsx("span",{className:sa,children:"%"}),s.jsx(H,{size:"sm",type:"button",variant:"ghost",onClick:()=>be(100),disabled:le===100,className:gs,"aria-label":r("settings.openchamber.visual.actions.resetFontSizeAria"),title:r("settings.common.actions.reset"),children:s.jsx(_,{name:"restart",className:"h-3.5 w-3.5"})})]})}),ue("terminalFontSize")&&s.jsx(Qt,{label:r("settings.openchamber.visual.field.terminalFontSize"),settingsItem:"appearance.terminal-font-size",controlClassName:"w-full",children:s.jsxs("div",{className:ta,children:[s.jsx(ys,{value:ke,onValueChange:ce,min:9,max:52,step:1}),s.jsx("span",{className:sa,children:"px"}),s.jsx(H,{size:"sm",type:"button",variant:"ghost",onClick:()=>ce(13),disabled:ke===13,className:gs,"aria-label":r("settings.openchamber.visual.actions.resetTerminalFontSizeAria"),title:r("settings.common.actions.reset"),children:s.jsx(_,{name:"restart",className:"h-3.5 w-3.5"})})]})}),ue("editorFontSize")&&s.jsx(Qt,{label:r("settings.openchamber.visual.field.editorFontSize"),settingsItem:"appearance.editor-font-size",controlClassName:"w-full",children:s.jsxs("div",{className:ta,children:[s.jsx(ys,{value:fe,onValueChange:Ke,min:9,max:32,step:1}),s.jsx("span",{className:sa,children:"px"}),s.jsx(H,{size:"sm",type:"button",variant:"ghost",onClick:()=>Ke(13),disabled:fe===13,className:gs,"aria-label":r("settings.openchamber.visual.actions.resetEditorFontSizeAria"),title:r("settings.common.actions.reset"),children:s.jsx(_,{name:"restart",className:"h-3.5 w-3.5"})})]})})]}):null,ue("spacing")||ue("inputBarOffset")&&x?s.jsxs(fn,{children:[ue("spacing")&&s.jsx(Qt,{label:r("settings.openchamber.visual.field.spacingDensity"),settingsItem:"appearance.spacing-density",controlClassName:"w-full",children:s.jsxs("div",{className:ta,children:[s.jsx(ys,{value:ze,onValueChange:Je,min:50,max:200,step:5}),s.jsx("span",{className:sa,children:"%"}),s.jsx(H,{size:"sm",type:"button",variant:"ghost",onClick:()=>Je(100),disabled:ze===100,className:gs,"aria-label":r("settings.openchamber.visual.actions.resetSpacingAria"),title:r("settings.common.actions.reset"),children:s.jsx(_,{name:"restart",className:"h-3.5 w-3.5"})})]})}),ue("inputBarOffset")&&x&&s.jsx(Qt,{label:r("settings.openchamber.visual.field.inputBarOffset"),info:r("settings.openchamber.visual.field.inputBarOffsetTooltip"),settingsItem:"appearance.input-bar-offset",controlClassName:"w-full",children:s.jsxs("div",{className:ta,children:[s.jsx(ys,{value:_e,onValueChange:Le,min:0,max:100,step:5}),s.jsx("span",{className:sa,children:"px"}),s.jsx(H,{size:"sm",type:"button",variant:"ghost",onClick:()=>Le(0),disabled:_e===0,className:gs,"aria-label":r("settings.openchamber.visual.actions.resetInputBarOffsetAria"),title:r("settings.common.actions.reset"),children:s.jsx(_,{name:"restart",className:"h-3.5 w-3.5"})})]})})]}):null]}),Ea&&s.jsxs(Oe,{title:r("settings.openchamber.visual.section.navigation"),contentClassName:"space-y-4",children:[ue("fileEditorKeymap")&&s.jsx(Os,{title:r("settings.openchamber.visual.field.fileEditorKeymap"),settingsItem:"appearance.file-editor-keymap",children:s.jsx(gn,{"aria-label":r("settings.openchamber.visual.field.fileEditorKeymap"),children:["default","vim"].map(d=>s.jsx(hn,{selected:ye===d,onSelect:()=>z(d),label:r(`settings.openchamber.visual.option.fileEditorKeymap.${d}`),ariaLabel:r(`settings.openchamber.visual.option.fileEditorKeymap.${d}`)},d))})}),s.jsxs("div",{className:bs,children:[ue("autoSaveEnabled")&&s.jsx(ut,{checked:ee,onChange:se,label:r("settings.openchamber.visual.field.autoSaveEnabled"),ariaLabel:r("settings.openchamber.visual.field.autoSaveEnabledAria"),info:r("settings.openchamber.visual.field.autoSaveEnabledInfo"),settingsItem:"appearance.auto-save-enabled"}),ue("expandedEditorToolbar")&&!ns&&s.jsx(ut,{checked:Z,onChange:ai,label:r("settings.openchamber.visual.field.expandedEditorToolbar"),ariaLabel:r("settings.openchamber.visual.field.expandedEditorToolbarAria"),settingsItem:"appearance.expanded-editor-toolbar"}),ue("terminalQuickKeys")&&!x&&s.jsx(ut,{checked:$e,onChange:Fe,label:r("settings.openchamber.visual.field.terminalQuickKeys"),ariaLabel:r("settings.openchamber.visual.field.terminalQuickKeysAria"),settingsItem:"appearance.terminal-quick-keys",info:r("settings.openchamber.visual.field.terminalQuickKeysTooltip")}),js&&s.jsx(Qt,{label:r("settings.openchamber.visual.field.terminalShell"),info:r("settings.openchamber.visual.field.terminalShellHint"),settingsItem:"appearance.terminal-shell",className:"pt-2",children:s.jsxs(Dt,{value:ge,onValueChange:d=>{zc(d)&&Ee(d)},children:[s.jsx(Mt,{"aria-label":r("settings.openchamber.visual.field.terminalShellAria"),size:Kt,className:sn,children:s.jsx(_t,{})}),s.jsxs(Rt,{children:[s.jsx(dt,{value:"auto",children:r("settings.openchamber.visual.option.terminalShell.auto")}),Zn.map(d=>s.jsx(dt,{value:d.id,children:d.name},d.id))]})]})}),js&&Nn&&s.jsx(ut,{checked:Xn,onChange:Tt,label:r("settings.openchamber.visual.field.terminalLoginShell"),ariaLabel:r("settings.openchamber.visual.field.terminalLoginShell"),settingsItem:"appearance.terminal-login-shell"})]})]}),pi&&s.jsxs(s.Fragment,{children:[zn&&s.jsxs(Oe,{title:r("settings.openchamber.visual.section.chatDisplay"),divider:ne,contentClassName:"space-y-6",children:[ue("chatRenderMode")&&s.jsx(Os,{title:r("settings.openchamber.visual.section.chatRenderMode"),settingsItem:"chat.render-mode",children:s.jsx("div",{role:"radiogroup","aria-label":r("settings.openchamber.visual.section.chatRenderModeAria"),className:"grid w-full max-w-[26rem] grid-cols-1 gap-3 @xl:grid-cols-2",children:vg.map(d=>{const vt=V===d.id,xs=Jt%12;return s.jsxs("button",{type:"button",onClick:()=>Ks(d.id),"aria-pressed":vt,className:je("flex flex-col items-start gap-1 rounded-lg border p-3 text-left transition-colors",vt?"border-primary bg-primary/5":"border-border hover:border-border/80 hover:bg-muted/50"),children:[s.jsx("span",{className:je("typography-ui-label",vt?"text-foreground":"text-muted-foreground"),children:l(d.labelKey)}),s.jsx("div",{className:"mt-2 w-full rounded-md border border-border/60 bg-muted/30 p-2",children:d.id==="live"?s.jsx("div",{className:"space-y-1.5",children:[0,1,2].map(ms=>{const en=ms*3+1,Sn=xs-en+1,Ra=Sn<=0?0:Sn===1?42:Sn===2?68:92,ui=Ra>0;return s.jsxs("div",{className:je("flex items-center gap-1.5 transition-all duration-300 motion-reduce:transition-none",ui?"translate-y-0 opacity-100":"translate-y-1 opacity-0"),children:[s.jsx("span",{className:"h-2 w-2 shrink-0 rounded-full bg-muted-foreground/55"}),s.jsx("span",{className:"h-1.5 rounded bg-muted-foreground/30 transition-all duration-300 motion-reduce:transition-none",style:{width:`${Ra}%`}})]},ms)})}):s.jsx("div",{className:"space-y-1.5",children:[0,1,2].map(ms=>{const en=xs>=(ms+1)*3;return s.jsxs("div",{className:je("flex items-center gap-1.5 transition-all duration-300 motion-reduce:transition-none",en?"translate-y-0 opacity-100":"translate-y-1 opacity-0"),children:[s.jsx("span",{className:"h-2 w-2 shrink-0 rounded-full bg-muted-foreground/55"}),s.jsx("span",{className:"h-1.5 rounded bg-muted-foreground/30",style:{width:"92%"}})]},ms)})})})]},d.id)})})}),ue("activityRenderMode")&&V==="sorted"&&s.jsx(Os,{title:r("settings.openchamber.visual.section.activityDefault"),children:s.jsx(gn,{"aria-label":r("settings.openchamber.visual.section.activityDefaultAria"),children:yg.map(d=>s.jsx(hn,{selected:te===d.id,onSelect:()=>Js(d.id),label:l(d.labelKey),ariaLabel:r("settings.openchamber.visual.field.activityDefaultModeAria",{option:l(d.labelKey)})},d.id))})})]}),Un&&s.jsxs(Oe,{title:r("settings.openchamber.visual.section.messageStreamTransport"),divider:zn||ne,settingsItem:"chat.message-transport",contentClassName:"space-y-2",children:[s.jsx(Ls,{value:xe,options:ho.map(d=>({value:d.id,label:l(d.labelKey)})),onChange:Fn,"aria-label":r("settings.openchamber.visual.section.messageStreamTransport")}),(()=>{const d=ho.find(vt=>vt.id===xe);return d?.descriptionKey?s.jsx("span",{className:"typography-meta text-muted-foreground",children:l(d.descriptionKey)}):null})()]}),Da&&s.jsx(Oe,{title:r("settings.openchamber.visual.section.chatMessageOptions"),divider:zn||Un||ne,children:s.jsxs(fn,{className:"lg:gap-y-6",children:[ue("userMessageRendering")&&s.jsx(Os,{title:r("settings.openchamber.visual.section.userMessageRendering"),children:s.jsx(gn,{"aria-label":r("settings.openchamber.visual.section.userMessageRenderingAria"),children:bg.map(d=>s.jsx(hn,{selected:wg(T)===d.id,onSelect:()=>Qn(d.id),label:l(d.labelKey),ariaLabel:r("settings.openchamber.visual.field.userMessageRenderingAria",{option:l(d.labelKey)})},d.id))})}),ue("mermaidRendering")&&s.jsx(Os,{title:r("settings.openchamber.visual.section.mermaidRendering"),children:s.jsx(gn,{"aria-label":r("settings.openchamber.visual.section.mermaidRenderingAria"),children:fg.map(d=>s.jsx(hn,{selected:F===d.id,onSelect:()=>ln(d.id),label:l(d.labelKey),ariaLabel:r("settings.openchamber.visual.field.mermaidRenderingAria",{option:l(d.labelKey)})},d.id))})}),ue("diffLayout")&&!ns&&s.jsx(Os,{title:r("settings.openchamber.visual.section.diffLayout"),children:s.jsx(gn,{"aria-label":r("settings.openchamber.visual.section.diffLayoutAria"),children:hg.map(d=>s.jsx(hn,{selected:Ge===d.id,onSelect:()=>Me(d.id),label:l(d.labelKey),ariaLabel:r("settings.openchamber.visual.field.diffLayoutAria",{option:l(d.labelKey)})},d.id))})}),ue("followUpBehavior")&&s.jsx(Os,{title:r("settings.openchamber.visual.section.followUpBehavior"),settingsItem:"chat.follow-up-behavior",children:s.jsx(gn,{"aria-label":r("settings.openchamber.visual.section.followUpBehaviorAria"),children:jg.map(d=>s.jsx(hn,{selected:oe===d.id,onSelect:()=>me(d.id),label:l(d.labelKey),ariaLabel:r("settings.openchamber.visual.field.followUpBehaviorAria",{option:l(d.labelKey)})},d.id))})})]})}),f&&s.jsxs(s.Fragment,{children:[ue("expandedTools")&&s.jsxs(Oe,{title:r("settings.openchamber.visual.section.showToolsOpenedByDefault"),divider:zn||Un||Da||ne,contentClassName:bs,children:[s.jsx(ut,{checked:tt,onChange:Kn,label:r("settings.openchamber.visual.field.bash"),ariaLabel:r("settings.openchamber.visual.field.showExpandedBashToolsAria")}),s.jsx(ut,{checked:mt,onChange:ci,label:r("settings.openchamber.visual.field.editTools"),ariaLabel:r("settings.openchamber.visual.field.showExpandedEditToolsAria")})]}),s.jsxs(Oe,{title:r("settings.openchamber.visual.section.sessionAssistance"),settingsItem:"chat.session-assistance",contentClassName:bs,children:[s.jsx(ut,{checked:Nt,onChange:ni,label:r("settings.openchamber.visual.field.draftStartersVisible"),ariaLabel:r("settings.openchamber.visual.field.draftStartersVisibleAria"),settingsItem:"chat.draft-starters-visible"}),ue("sessionAssist")&&s.jsxs(s.Fragment,{children:[s.jsx(ut,{checked:p,onChange:k,label:r("settings.openchamber.visual.field.sessionRecap"),ariaLabel:r("settings.openchamber.visual.field.sessionRecapAria"),settingsItem:"chat.session-recap"}),s.jsx(ut,{checked:L,onChange:N,label:r("settings.openchamber.visual.field.sessionSuggestion"),ariaLabel:r("settings.openchamber.visual.field.sessionSuggestionAria"),settingsItem:"chat.session-suggestion"})]}),ue("subagentReadOnlyBanner")&&s.jsx(ut,{checked:Be,onChange:qe,label:r("settings.openchamber.visual.field.allowPromptingSubagentSessions"),ariaLabel:r("settings.openchamber.visual.field.allowPromptingSubagentSessionsAria"),settingsItem:"chat.subagent-read-only-banner"})]}),ue("sessionGoal")&&!ns&&s.jsxs(Oe,{title:r("settings.openchamber.visual.goal.sectionTitle"),info:r("settings.openchamber.visual.goal.description"),contentClassName:bs,children:[s.jsx(ut,{checked:h,onChange:C,label:r("settings.openchamber.visual.field.sessionGoal"),ariaLabel:r("settings.openchamber.visual.field.sessionGoalAria"),settingsItem:"chat.session-goal"}),s.jsxs("div",{"data-settings-item":"chat.session-goal-budget",className:"flex items-center gap-2",children:[s.jsx(ut,{checked:u,onChange:E,disabled:!h,label:r("settings.openchamber.visual.goal.budgetLabel"),ariaLabel:r("settings.openchamber.visual.goal.budgetAria")}),h&&u?s.jsx(ys,{value:q,onValueChange:d=>{typeof d=="number"&&Number.isFinite(d)&&d>0&&M(Math.floor(d))},min:1e3,max:1e8,step:5e4}):null]})]}),ue("reasoning")&&s.jsxs(Oe,{title:r("settings.openchamber.visual.section.reasoning"),settingsItem:"chat.reasoning",contentClassName:bs,children:[s.jsx(ut,{checked:b,onChange:I,label:r("settings.openchamber.visual.field.showReasoningTraces"),ariaLabel:r("settings.openchamber.visual.field.showReasoningTracesAria"),settingsItem:"chat.reasoning-traces"}),b&&s.jsx(ut,{checked:g,onChange:j,label:r("settings.openchamber.visual.field.collapsibleThinkingBlocks"),ariaLabel:r("settings.openchamber.visual.field.collapsibleThinkingBlocksAria")})]}),(ue("collapsibleUserMessages")||ue("stickyUserHeader")||ue("promptNavigatorEnabled")&&!ns||ue("wideChatLayout")||ue("splitAssistantMessageActions")||ue("codeBlockLineWrap"))&&s.jsxs(Oe,{title:r("settings.openchamber.visual.section.messageAppearance"),settingsItem:"chat.message-appearance",contentClassName:bs,children:[ue("collapsibleUserMessages")&&s.jsx(ut,{checked:K,onChange:ii,label:r("settings.openchamber.visual.field.collapsibleUserMessages"),ariaLabel:r("settings.openchamber.visual.field.collapsibleUserMessagesAria"),settingsItem:"chat.collapsible-user-messages"}),ue("stickyUserHeader")&&s.jsx(ut,{checked:w,onChange:si,label:r("settings.openchamber.visual.field.stickyUserHeader"),ariaLabel:r("settings.openchamber.visual.field.stickyUserHeaderAria"),settingsItem:"chat.sticky-user-header"}),ue("promptNavigatorEnabled")&&!ns&&s.jsx(ut,{checked:G,onChange:Sa,label:r("settings.openchamber.visual.field.promptNavigatorEnabled"),ariaLabel:r("settings.openchamber.visual.field.promptNavigatorEnabledAria"),settingsItem:"chat.prompt-navigator"}),ue("wideChatLayout")&&s.jsx(ut,{checked:D,onChange:ri,label:r("settings.openchamber.visual.field.wideChatLayout"),ariaLabel:r("settings.openchamber.visual.field.wideChatLayoutAria"),settingsItem:"chat.wide-layout"}),ue("splitAssistantMessageActions")&&s.jsx(ut,{checked:ie,onChange:oi,label:r("settings.openchamber.visual.field.showSplitAssistantMessageActions"),ariaLabel:r("settings.openchamber.visual.field.showSplitAssistantMessageActionsAria"),settingsItem:"chat.inline-assistant-actions",info:r("settings.openchamber.visual.field.showSplitAssistantMessageActionsTooltip")}),ue("codeBlockLineWrap")&&s.jsx(ut,{checked:U,onChange:A,label:r("settings.openchamber.visual.field.codeBlockLineWrap"),ariaLabel:r("settings.openchamber.visual.field.codeBlockLineWrapAria"),settingsItem:"chat.code-block-line-wrap"})]}),(ue("showToolFileIcons")||ue("showTurnChangedFiles")||ue("dotfiles")&&!ds()||ue("fileViewerPreview"))&&s.jsxs(Oe,{title:r("settings.openchamber.visual.section.toolsAndFiles"),settingsItem:"chat.tools-and-files",contentClassName:bs,children:[ue("showToolFileIcons")&&s.jsx(ut,{checked:B,onChange:nr,label:r("settings.openchamber.visual.field.showToolFileIcons"),ariaLabel:r("settings.openchamber.visual.field.showToolFileIconsAria"),settingsItem:"chat.tool-file-icons"}),ue("showTurnChangedFiles")&&s.jsx(ut,{checked:Qe,onChange:cn,label:r("settings.openchamber.visual.field.showTurnChangedFiles"),ariaLabel:r("settings.openchamber.visual.field.showTurnChangedFilesAria"),settingsItem:"chat.changed-files"}),ue("dotfiles")&&!ds()&&s.jsx(ut,{checked:m,onChange:Uc,label:r("settings.openchamber.visual.field.showDotfiles"),ariaLabel:r("settings.openchamber.visual.field.showDotfilesAria"),settingsItem:"chat.dotfiles"}),ue("fileViewerPreview")&&s.jsx(ut,{checked:Re,onChange:li,label:r("settings.openchamber.defaults.field.openFilesPreview"),ariaLabel:r("settings.openchamber.defaults.field.openFilesPreviewAria")})]}),(ue("persistDraft")||!x&&ue("inputSpellcheck"))&&s.jsxs(Oe,{title:r("settings.openchamber.visual.section.composer"),settingsItem:"chat.composer",contentClassName:bs,children:[ue("persistDraft")&&s.jsx(ut,{checked:ve,onChange:re,label:r("settings.openchamber.visual.field.persistDraftMessages"),ariaLabel:r("settings.openchamber.visual.field.persistDraftMessagesAria"),settingsItem:"chat.persist-drafts"}),!x&&ue("inputSpellcheck")&&s.jsx(ut,{checked:Ve,onChange:Cs,label:r("settings.openchamber.visual.field.enableSpellcheckInTextInputs"),ariaLabel:r("settings.openchamber.visual.field.enableSpellcheckInTextInputsAria"),settingsItem:"chat.spellcheck"})]})]})]}),ue("reportUsage")&&s.jsx(Oe,{title:r("settings.openchamber.visual.section.privacy"),children:s.jsx(ut,{checked:cs,onChange:Ws,label:r("settings.openchamber.visual.field.sendAnonymousUsageReports"),info:r("settings.openchamber.visual.field.sendAnonymousUsageReportsHint"),ariaLabel:r("settings.openchamber.visual.field.sendAnonymousUsageReportsAria"),settingsItem:"appearance.usage-reports"})})]})},Sg=1,Cg=365,bo=30,Ig=[{value:"archive",labelKey:"settings.openchamber.sessionRetention.action.archive"},{value:"delete",labelKey:"settings.openchamber.sessionRetention.action.delete"}],pl=()=>{const t=ht.c(87),{t:e}=ot(),a=de(Pg),n=de(Ag),i=de(Tg),r=de(Eg),l=de(Dg),x=de(Mg);let c;t[0]===Symbol.for("react.memo_cache_sentinel")?(c={autoRun:!1},t[0]=c):c=t[0];const{candidates:y,isRunning:m,runCleanup:b,action:p}=oc(c),L=y.length;let k;t[1]!==b||t[2]!==e?(k=async()=>{const ae=await b({force:!0});if(ae.completedIds.length===0&&ae.failedIds.length===0){R.message(ae.action==="archive"?e("settings.openchamber.sessionRetention.toast.noneEligibleArchive"):e("settings.openchamber.sessionRetention.toast.noneEligibleDelete"));return}ae.completedIds.length>0&&R.success(ae.action==="archive"?e("settings.openchamber.sessionRetention.toast.archivedCount",{count:ae.completedIds.length}):e("settings.openchamber.sessionRetention.toast.deletedCount",{count:ae.completedIds.length})),ae.failedIds.length>0&&R.error(ae.action==="archive"?e("settings.openchamber.sessionRetention.toast.failedArchiveCount",{count:ae.failedIds.length}):e("settings.openchamber.sessionRetention.toast.failedDeleteCount",{count:ae.failedIds.length}))},t[1]=b,t[2]=e,t[3]=k):k=t[3];const N=k;let h;t[4]!==e?(h=e("settings.openchamber.sessionRetention.title"),t[4]=e,t[5]=h):h=t[5];let C;t[6]!==e?(C=e("settings.openchamber.sessionRetention.tooltip"),t[6]=e,t[7]=C):C=t[7];let u;t[8]!==e?(u=e("settings.openchamber.sessionRetention.field.enableAutoCleanup"),t[8]=e,t[9]=u):u=t[9];let E;t[10]!==e?(E=e("settings.openchamber.sessionRetention.field.enableAutoCleanupAria"),t[10]=e,t[11]=E):E=t[11];let q;t[12]!==a||t[13]!==r||t[14]!==u||t[15]!==E?(q=s.jsx(ut,{settingsItem:"sessions.auto-cleanup",checked:a,onChange:r,label:u,ariaLabel:E}),t[12]=a,t[13]=r,t[14]=u,t[15]=E,t[16]=q):q=t[16];let M;t[17]!==e?(M=e("settings.openchamber.sessionRetention.field.retentionPeriod"),t[17]=e,t[18]=M):M=t[18];let I;t[19]!==e?(I=e("settings.openchamber.sessionRetention.field.retentionPeriodAria"),t[19]=e,t[20]=I):I=t[20];let g;t[21]!==n||t[22]!==l||t[23]!==I?(g=s.jsx(ys,{value:n,onValueChange:l,min:Sg,max:Cg,step:1,"aria-label":I,className:"w-20 tabular-nums"}),t[21]=n,t[22]=l,t[23]=I,t[24]=g):g=t[24];let j;t[25]!==e?(j=e("settings.openchamber.sessionRetention.field.days"),t[25]=e,t[26]=j):j=t[26];let F;t[27]!==j?(F=s.jsx("span",{className:"typography-ui-label text-muted-foreground",children:j}),t[27]=j,t[28]=F):F=t[28];let S;t[29]!==l?(S=()=>l(bo),t[29]=l,t[30]=S):S=t[30];const T=n===bo;let v;t[31]!==e?(v=e("settings.openchamber.sessionRetention.actions.resetRetentionAria"),t[31]=e,t[32]=v):v=t[32];let K;t[33]!==e?(K=e("settings.common.actions.reset"),t[33]=e,t[34]=K):K=t[34];let $;t[35]===Symbol.for("react.memo_cache_sentinel")?($=s.jsx(_,{name:"restart",className:"h-3.5 w-3.5"}),t[35]=$):$=t[35];let w;t[36]!==S||t[37]!==T||t[38]!==v||t[39]!==K?(w=s.jsx(H,{size:"sm",type:"button",variant:"ghost",onClick:S,disabled:T,className:gs,"aria-label":v,title:K,children:$}),t[36]=S,t[37]=T,t[38]=v,t[39]=K,t[40]=w):w=t[40];let G;t[41]!==F||t[42]!==w||t[43]!==M||t[44]!==g?(G=s.jsxs($t,{settingsItem:"sessions.retention-period",label:M,children:[g,F,w]}),t[41]=F,t[42]=w,t[43]=M,t[44]=g,t[45]=G):G=t[45];let Q;t[46]!==e?(Q=e("settings.openchamber.sessionRetention.field.whenSessionsExpire"),t[46]=e,t[47]=Q):Q=t[47];let X;t[48]!==e?(X=Ig.map(ae=>({value:ae.value,label:e(ae.labelKey)})),t[48]=e,t[49]=X):X=t[49];let Z;t[50]!==i||t[51]!==x||t[52]!==X?(Z=s.jsx(Ls,{value:i,onChange:x,options:X}),t[50]=i,t[51]=x,t[52]=X,t[53]=Z):Z=t[53];let P;t[54]!==Q||t[55]!==Z?(P=s.jsx($t,{settingsItem:"sessions.retention-action",label:Q,children:Z}),t[54]=Q,t[55]=Z,t[56]=P):P=t[56];let ee;t[57]!==G||t[58]!==P?(ee=s.jsxs(Wn,{className:"space-y-0",children:[G,P]}),t[57]=G,t[58]=P,t[59]=ee):ee=t[59];let se;t[60]!==e?(se=e("settings.openchamber.sessionRetention.manualCleanup.title"),t[60]=e,t[61]=se):se=t[61];let D;t[62]!==m||t[63]!==e?(D=e(m?"settings.openchamber.sessionRetention.actions.cleaningUp":"settings.openchamber.sessionRetention.actions.runCleanupNow"),t[62]=m,t[63]=e,t[64]=D):D=t[64];let O;t[65]!==N||t[66]!==m||t[67]!==D?(O=s.jsx(H,{type:"button",variant:"outline",size:"xs",onClick:N,disabled:m,className:"!font-normal",children:D}),t[65]=N,t[66]=m,t[67]=D,t[68]=O):O=t[68];let U;t[69]!==se||t[70]!==O?(U=s.jsx($t,{label:se,children:O}),t[69]=se,t[70]=O,t[71]=U):U=t[71];let A;t[72]!==p||t[73]!==L||t[74]!==e?(A=p==="archive"?e("settings.openchamber.sessionRetention.manualCleanup.eligibleArchiveNow",{count:L}):e("settings.openchamber.sessionRetention.manualCleanup.eligibleDeleteNow",{count:L}),t[72]=p,t[73]=L,t[74]=e,t[75]=A):A=t[75];let V;t[76]!==A?(V=s.jsx("p",{className:"typography-meta text-muted-foreground",children:A}),t[76]=A,t[77]=V):V=t[77];let W;t[78]!==U||t[79]!==V?(W=s.jsxs("div",{className:"mt-1 py-1.5 space-y-1",children:[U,V]}),t[78]=U,t[79]=V,t[80]=W):W=t[80];let te;return t[81]!==h||t[82]!==ee||t[83]!==C||t[84]!==W||t[85]!==q?(te=s.jsxs(Oe,{title:h,info:C,children:[q,ee,W]}),t[81]=h,t[82]=ee,t[83]=C,t[84]=W,t[85]=q,t[86]=te):te=t[86],te};function Pg(t){return t.autoDeleteEnabled}function Ag(t){return t.autoDeleteAfterDays}function Tg(t){return t.sessionRetentionAction}function Eg(t){return t.setAutoDeleteEnabled}function Dg(t){return t.setAutoDeleteAfterDays}function Mg(t){return t.setSessionRetentionAction}const vo=(t,e,a)=>!t||!Number.isFinite(t)?e:new Intl.DateTimeFormat(Ro(),{dateStyle:"medium",timeStyle:"short",hour12:a==="auto"?void 0:a==="12h"}).format(t),ml=()=>{const{t}=ot(),e=de(g=>g.timeFormatPreference),[a,n]=o.useState(!1),[i,r]=o.useState(!0),[l,x]=o.useState(!1),[c,y]=o.useState(null),[m,b]=o.useState(!1),[p,L]=o.useState([]),[k,N]=o.useState(lc),[h,C]=o.useState(""),u=o.useMemo(()=>cc(),[]),E=o.useCallback(async()=>{r(!0),C("");try{const g=await dc();L(g)}catch(g){const j=g instanceof Error?g.message:t("settings.openchamber.passkeys.toast.loadFailed");C(j)}finally{r(!1)}},[t]);o.useEffect(()=>{let g=!1;return(async()=>{try{if(!u.supported){g||(n(!1),r(!1));return}g||n(!0)}catch{g||n(!1)}if(!g){const j=await hi();if(N(j),!j.enabled){L([]),r(!1);return}await E()}})(),()=>{g=!0,mr()}},[E,u.supported]);const q=o.useCallback(async()=>{if(!k.enabled){const g=t("settings.openchamber.passkeys.toast.enableUiPasswordFirst");C(g),R.message(g);return}if(!a){C(u.reason),R.message(u.reason);return}if(l){mr(),x(!1);return}C(""),x(!0);try{await pc(),N(await hi()),await E(),R.success(t("settings.openchamber.passkeys.toast.added"))}catch(g){if(mc(g)){R.message(t("settings.openchamber.passkeys.toast.setupCanceled"));return}const j=g instanceof Error?g.message:t("settings.openchamber.passkeys.toast.addFailed");C(j),R.error(j)}finally{x(!1)}},[l,E,k.enabled,u.reason,a,t]),M=o.useCallback(async g=>{y(g),C("");try{await uc(g),N(await hi()),await E(),R.success(t("settings.openchamber.passkeys.toast.removed"))}catch(j){const F=j instanceof Error?j.message:t("settings.openchamber.passkeys.toast.removeFailed");C(F),R.error(F)}finally{y(null)}},[E,t]),I=o.useCallback(async()=>{b(!0),C("");try{await gc(),window.location.reload()}catch(g){const j=g instanceof Error?g.message:t("settings.openchamber.passkeys.toast.clearAuthFailed");C(j),R.error(j),b(!1)}},[t]);return s.jsxs(Oe,{title:t("settings.openchamber.passkeys.title"),children:[s.jsxs("div",{className:"space-y-2",children:[s.jsxs($t,{label:t("settings.openchamber.passkeys.field.currentDevice"),children:[s.jsx(H,{type:"button",variant:l?"secondary":"outline",size:"xs",onClick:()=>{q()},disabled:i||m,className:"!font-normal",children:t(l?"settings.openchamber.passkeys.actions.cancelSetup":"settings.openchamber.passkeys.actions.add")}),s.jsx(H,{type:"button",variant:"ghost",size:"xs",onClick:()=>{I()},disabled:i||l||m,className:"!font-normal text-muted-foreground hover:text-foreground",children:t(m?"settings.openchamber.passkeys.actions.signingOut":"settings.openchamber.passkeys.actions.signOutEverywhere")})]}),!k.enabled&&s.jsx("p",{className:"typography-meta text-muted-foreground",children:t("settings.openchamber.passkeys.state.uiPasswordRequired")}),k.enabled&&!a&&s.jsx("p",{className:"typography-meta text-muted-foreground",children:u.reason}),i?s.jsx("p",{className:"typography-meta text-muted-foreground",children:t("settings.openchamber.passkeys.state.loading")}):p.length===0?s.jsx("p",{className:"typography-meta text-muted-foreground",children:t("settings.openchamber.passkeys.state.noneSaved")}):s.jsx("div",{className:"space-y-1 pt-1",children:p.map(g=>s.jsxs($t,{label:s.jsx("span",{className:"truncate",children:g.label}),alignEnd:!1,controlClassName:"justify-between sm:flex-1",children:[s.jsx("span",{className:"typography-meta text-muted-foreground truncate",children:g.lastUsedAt?t("settings.openchamber.passkeys.item.lastUsed",{time:vo(g.lastUsedAt,t("settings.openchamber.passkeys.time.neverUsed"),e)}):t("settings.openchamber.passkeys.item.added",{time:vo(g.createdAt,t("settings.openchamber.passkeys.time.neverUsed"),e)})}),s.jsx(H,{type:"button",variant:"ghost",size:"xs",onClick:()=>{M(g.id)},disabled:c===g.id,className:"!font-normal text-muted-foreground hover:text-foreground",children:c===g.id?t("settings.openchamber.passkeys.actions.removing"):t("settings.common.actions.delete")})]},g.id))})]}),h&&s.jsx("div",{className:"mt-1 py-1.5",children:s.jsx("p",{className:"typography-meta text-[var(--status-error)]",children:h})})]})},Ai=t=>{const e=Gn(t);return e||{providerId:"",modelId:""}},ul=()=>{const{t}=ot(),e=nt(A=>A.setProvider),a=nt(A=>A.setModel),n=nt(A=>A.setAgent),i=nt(A=>A.setCurrentVariant),r=nt(A=>A.setSettingsDefaultModel),l=nt(A=>A.setSettingsDefaultVariant),x=nt(A=>A.setSettingsDefaultAgent),c=de(A=>A.showDeletionDialog),y=de(A=>A.setShowDeletionDialog),m=nt(A=>A.providers),b=nt(A=>A.modelsMetadata),[p,L]=o.useState(),[k,N]=o.useState(),[h,C]=o.useState(),[u,E]=o.useState(!0),[q,M]=o.useState(),[I,g]=o.useState(),[j,F]=o.useState(),[S,T]=o.useState(!0),v=o.useMemo(()=>Ai(p),[p]);o.useEffect(()=>{(async()=>{try{let V=null;if(!V){const W=jn()?.settings;if(W)try{const ae=(await W.load())?.settings;if(ae){const le=ae;V={defaultModel:typeof ae.defaultModel=="string"?ae.defaultModel:void 0,defaultVariant:typeof le.defaultVariant=="string"?le.defaultVariant:void 0,defaultAgent:typeof ae.defaultAgent=="string"?ae.defaultAgent:void 0,smallModelUseDefault:typeof le.smallModelUseDefault=="boolean"?le.smallModelUseDefault:void 0,smallModelOverride:typeof le.smallModelOverride=="string"?le.smallModelOverride:void 0,walkthroughModelOverride:typeof le.walkthroughModelOverride=="string"?le.walkthroughModelOverride:void 0}}}catch{}}if(!V){const W=await ct("/api/config/settings",{method:"GET",headers:{Accept:"application/json"}});W.ok&&(V=await W.json())}if(V){const W=typeof V.defaultModel=="string"&&V.defaultModel.trim().length>0?V.defaultModel.trim():void 0,te=typeof V.defaultVariant=="string"&&V.defaultVariant.trim().length>0?V.defaultVariant.trim():void 0,ae=typeof V.defaultAgent=="string"&&V.defaultAgent.trim().length>0?V.defaultAgent.trim():void 0;W!==void 0&&L(W),te!==void 0&&N(te),ae!==void 0&&C(ae),typeof V.smallModelUseDefault=="boolean"&&E(V.smallModelUseDefault),typeof V.smallModelOverride=="string"&&V.smallModelOverride.trim()&&M(V.smallModelOverride.trim()),typeof V.walkthroughModelOverride=="string"&&V.walkthroughModelOverride.trim()&&F(V.walkthroughModelOverride.trim())}}catch(V){console.warn("Failed to load defaults settings:",V)}finally{T(!1)}})()},[]);const K=o.useCallback(async(A,V)=>{const W=A&&V?`${A}/${V}`:void 0;L(W),N(void 0),l(void 0),i(void 0),r(W),A&&V&&m.find(ae=>ae.id===A)&&(e(A),a(V));try{await yt({defaultModel:W??"",defaultVariant:""});const te=await ct("/api/config/settings",{method:"PUT",headers:{"Content-Type":"application/json"},body:JSON.stringify({defaultModel:W})});te.ok||console.warn("Failed to save default model to server:",te.status,te.statusText)}catch(te){console.warn("Failed to save default model:",te)}},[m,i,a,e,r,l]),$="__default__",w=o.useCallback(A=>A===$?t("settings.openchamber.defaults.option.default"):A.charAt(0).toUpperCase()+A.slice(1),[t]),G=o.useCallback(async A=>{const V=A===$?void 0:A||void 0;N(V),l(V),i(V);try{await yt({defaultVariant:V??""})}catch(W){console.warn("Failed to save default variant:",W)}},[i,l]),Q=o.useCallback(async A=>{const V=A||void 0;C(V),x(V),A&&n(A);try{await yt({defaultAgent:V??""})}catch(W){console.warn("Failed to save default agent:",W)}},[n,x]),X=o.useCallback(async A=>{E(A);try{await yt({smallModelUseDefault:A})}catch(V){console.warn("Failed to save small model preference:",V)}},[]),Z=o.useCallback(async(A,V)=>{const W=A&&V?`${A}/${V}`:void 0;M(W);try{await yt({smallModelOverride:W??""})}catch(te){console.warn("Failed to save small model override:",te)}},[]),P=o.useCallback(async(A,V)=>{const W=A&&V?`${A}/${V}`:void 0;F(W);try{await yt({walkthroughModelOverride:W??""})}catch(te){console.warn("Failed to save walkthrough model override:",te)}},[]),ee=o.useCallback((A,V)=>b.get(`${A}/${V}`)?.structured_output!==!1,[b]),se=o.useMemo(()=>Ai(q),[q]),D=o.useMemo(()=>Ai(j),[j]);o.useEffect(()=>{if(I!==void 0)return;let A=!1;return(async()=>{try{const V=await ct("/api/small-model",{method:"GET",headers:{Accept:"application/json"}});if(!V.ok)return;const W=await V.json().catch(()=>null);!A&&Array.isArray(W?.authenticatedProviders)&&g(W.authenticatedProviders.filter(te=>typeof te=="string"))}catch{}})(),()=>{A=!0}},[I]);const O=o.useMemo(()=>{if(!v.providerId||!v.modelId)return[];const W=m.find(te=>te.id===v.providerId)?.models.find(te=>te.id===v.modelId)?.variants;return W?Object.keys(W):[]},[v.modelId,v.providerId,m]),U=O.length>0;return o.useEffect(()=>{!U&&k&&(N(void 0),l(void 0),i(void 0),yt({defaultVariant:""}).catch(()=>{}))},[k,i,l,U]),S?null:s.jsx(s.Fragment,{children:s.jsx(Oe,{title:t("settings.openchamber.defaults.title"),divider:!1,children:s.jsxs("div",{className:"space-y-0",children:[s.jsxs("div",{className:"mt-0 mb-1 typography-meta text-muted-foreground",children:[t("settings.openchamber.defaults.summaryPrefix")," ",v.providerId?s.jsxs("span",{className:"text-foreground",children:[v.providerId,"/",v.modelId,U?` (${k??t("settings.openchamber.defaults.option.defaultLowercase")})`:""]}):s.jsx("span",{className:"text-foreground",children:t("settings.openchamber.defaults.summaryOpenCodeDefault")}),h&&s.jsxs(s.Fragment,{children:[" / ",s.jsx("span",{className:"text-foreground",children:h})]})]}),s.jsxs("div",{children:[s.jsx($t,{settingsItem:"sessions.default-model",label:t("settings.openchamber.defaults.field.defaultModel"),children:s.jsx(ua,{providerId:v.providerId,modelId:v.modelId,onChange:K,className:bn})}),s.jsx($t,{settingsItem:"sessions.default-thinking",label:t("settings.openchamber.defaults.field.defaultThinking"),children:s.jsxs(Dt,{value:k??$,onValueChange:G,disabled:!U,children:[s.jsx(Mt,{size:Kt,className:vn,children:s.jsx(_t,{placeholder:t("settings.openchamber.defaults.field.thinkingPlaceholder"),children:w(k??$)})}),s.jsxs(Rt,{children:[s.jsx(dt,{value:$,children:t("settings.openchamber.defaults.option.default")}),O.map(A=>s.jsx(dt,{value:A,children:w(A)},A))]})]})}),s.jsx($t,{settingsItem:"sessions.default-agent",label:t("settings.openchamber.defaults.field.defaultAgent"),children:s.jsx(To,{agentName:h||"",onChange:Q,className:bn})})]}),s.jsx(Wn,{className:bs,children:s.jsx(ut,{settingsItem:"sessions.deletion-dialog",checked:c,onChange:y,label:t("settings.openchamber.defaults.field.showDeletionDialog"),ariaLabel:t("settings.openchamber.defaults.field.showDeletionDialogAria")})}),s.jsxs("div",{className:"space-y-3 pt-6",children:[s.jsxs("div",{className:"flex items-center gap-1.5",children:[s.jsx(Vs,{children:t("settings.openchamber.defaults.smallModel.title")}),s.jsx(Yt,{children:t("settings.openchamber.defaults.smallModel.description")})]}),s.jsx(ut,{settingsItem:"sessions.small-model",checked:u,onChange:A=>{X(A)},label:t("settings.openchamber.defaults.smallModel.useDefault"),ariaLabel:t("settings.openchamber.defaults.smallModel.useDefaultAria")}),u?null:s.jsx($t,{label:t("settings.openchamber.defaults.smallModel.overrideModel"),children:s.jsx(ua,{providerId:se.providerId,modelId:se.modelId,onChange:Z,allowedProviderIds:I,className:bn})}),s.jsxs(Wn,{className:bs,children:[s.jsxs("div",{className:"flex items-center gap-1.5",children:[s.jsx(Vs,{children:t("settings.openchamber.defaults.walkthroughModel.title")}),s.jsx(Yt,{children:t("settings.openchamber.defaults.walkthroughModel.description")})]}),s.jsx($t,{settingsItem:"sessions.walkthrough-model",label:t("settings.openchamber.defaults.walkthroughModel.overrideModel"),children:s.jsx(ua,{providerId:D.providerId,modelId:D.modelId,onChange:P,allowedProviderIds:I,isModelAllowed:ee,placeholder:t("settings.openchamber.defaults.walkthroughModel.usesSmallModel"),className:bn})})]})]})]})})})},yo={completion:{titleKey:"settings.notifications.page.template.defaults.completion.title",messageKey:"settings.notifications.page.template.defaults.completion.message"},error:{titleKey:"settings.notifications.page.template.defaults.error.title",messageKey:"settings.notifications.page.template.defaults.error.message"},question:{titleKey:"settings.notifications.page.template.defaults.question.title",messageKey:"settings.notifications.page.template.defaults.question.message"},subtask:{titleKey:"settings.notifications.page.template.defaults.subtask.title",messageKey:"settings.notifications.page.template.defaults.subtask.message"}},Rg={completion:"settings.notifications.page.template.event.completion",subtask:"settings.notifications.page.template.event.subtask",error:"settings.notifications.page.template.event.error",question:"settings.notifications.page.template.event.question"},Og=()=>{const{t}=ot(),e=o.useMemo(()=>is(),[]),a=o.useMemo(()=>ds(),[]),n=o.useMemo(()=>typeof window>"u"?!1:window.Capacitor?.isNativePlatform?.()===!0||window.location.protocol==="capacitor:",[]),i=!e&&!a&&!n,r=de(D=>D.nativeNotificationsEnabled),l=de(D=>D.setNativeNotificationsEnabled),x=de(D=>D.notificationMode),c=de(D=>D.setNotificationMode),y=de(D=>D.notifyOnSubtasks),m=de(D=>D.setNotifyOnSubtasks),b=de(D=>D.notifyOnCompletion),p=de(D=>D.setNotifyOnCompletion),L=de(D=>D.notifyOnError),k=de(D=>D.setNotifyOnError),N=de(D=>D.notifyOnQuestion),h=de(D=>D.setNotifyOnQuestion),C=de(D=>D.notificationTemplates),u=de(D=>D.setNotificationTemplates),[E,q]=o.useState("default"),[M,I]=o.useState(!1),[g,j]=o.useState(!1),[F,S]=o.useState(!1);o.useEffect(()=>{if(!i){I(!1),j(!1);return}typeof Notification<"u"&&q(Notification.permission);const D=typeof window<"u"&&"serviceWorker"in navigator&&"PushManager"in window&&"Notification"in window;I(D),(async()=>{if(!D){j(!1);return}try{const U=await navigator.serviceWorker.getRegistration();if(!U){j(!1);return}const A=await U.pushManager.getSubscription();j(!!A)}catch{j(!1)}})()},[i]);const T=async D=>{if(e){l(D);return}if(!i){l(D);return}if(D&&typeof Notification<"u"&&Notification.permission==="default")try{const O=await Notification.requestPermission();q(O),O==="granted"?l(!0):R.error(t("settings.notifications.page.toast.permissionDenied.title"),{description:t("settings.notifications.page.toast.permissionDenied.description")})}catch(O){console.error("Failed to request notification permission:",O),R.error(t("settings.notifications.page.toast.requestPermissionFailed"))}else l(!!(D&&E==="granted"))},v=e||a||n||i&&typeof Notification<"u"&&Notification.permission==="granted",K=(D,O,U)=>{u(A=>({...A,[D]:{...A[D],[O]:U}}))},$=D=>{const O="=".repeat((4-D.length%4)%4),U=(D+O).replace(/-/g,"+").replace(/_/g,"/"),A=atob(U),V=new Uint8Array(A.length);for(let W=0;W<A.length;W+=1)V[W]=A.charCodeAt(W);return V},w=async(D,O,U)=>{let A=null;const V=new Promise((W,te)=>{A=setTimeout(()=>{te(new Error(U))},O)});try{return await Promise.race([D,V])}finally{A&&clearTimeout(A)}},G=async D=>{if(D.active)return;const O=D.installing||D.waiting;O&&O.state!=="activated"&&await w(new Promise(U=>{const A=()=>{O.state==="activated"&&(O.removeEventListener("statechange",A),U())};O.addEventListener("statechange",A),A()}),15e3,"Service worker activation timed out")},Q=async()=>{if(typeof navigator.serviceWorker.register!="function")throw new Error("navigator.serviceWorker.register unavailable");const D=[{label:"no-options",opts:null},{label:"scope-root",opts:{scope:"/"}},{label:"type-classic",opts:{type:"classic"}},{label:"type-classic-scope",opts:{type:"classic",scope:"/"}},{label:"updateViaCache-none",opts:{type:"classic",updateViaCache:"none",scope:"/"}}];let O=null;for(const U of D)try{const A=U.opts?navigator.serviceWorker.register("/sw.js",U.opts):navigator.serviceWorker.register("/sw.js");return await w(A,1e4,`Service worker registration timed out (${U.label})`)}catch(A){O=A}throw O instanceof Error?O:new Error("Service worker registration failed")},X=async()=>{if(!("serviceWorker"in navigator))throw new Error("Service worker not supported");const D=await navigator.serviceWorker.getRegistration();if(D)return D;const O=await Q();try{await O.update()}catch{}return await G(O),O},Z=D=>{const O=D,U=[`type=${typeof D}`,`toString=${String(D)}`,`name=${String(O?.name??"")}`,`message=${String(O?.message??"")}`];let A="";try{A=JSON.stringify(D)}catch{}return{summary:U.filter(Boolean).join(" | "),json:A,stack:typeof O?.stack=="string"?O.stack:""}},P=async()=>{const D=jn();if(!D?.notifications){R.error(t("settings.notifications.page.toast.notificationsApiUnavailable"));return}try{await D.notifications.notifyAgentCompletion({title:t("settings.notifications.page.testNotification.title"),body:t("settings.notifications.page.testNotification.body"),tag:"openchamber-test"})?R.success(t("settings.notifications.page.toast.testNotificationSent")):R.error(t("settings.notifications.page.toast.testNotificationFailed"))}catch(O){console.error("Test notification failed:",O),R.error(t("settings.notifications.page.toast.testNotificationFailed"))}},ee=async()=>{if(!M){R.error(t("settings.notifications.page.toast.pushUnsupported"));return}const D=jn();if(!D?.push){R.error(t("settings.notifications.page.toast.pushApiUnavailable"));return}S(!0);try{if(typeof Notification<"u"&&Notification.permission==="default"){const le=await Notification.requestPermission();if(q(le),le!=="granted"){R.error(t("settings.notifications.page.toast.permissionDenied.title"),{description:t("settings.notifications.page.toast.permissionDenied.enableInBrowser")});return}}if(typeof Notification<"u"&&Notification.permission!=="granted"){R.error(t("settings.notifications.page.toast.permissionDenied.title"),{description:t("settings.notifications.page.toast.permissionDenied.enableInBrowser")});return}const O=await D.push.getVapidPublicKey();if(!O?.publicKey){R.error(t("settings.notifications.page.toast.pushKeyLoadFailed"));return}const U=await X();await G(U);const A=await U.pushManager.getSubscription();if(!("pushManager"in U)||!U.pushManager)throw new Error("PushManager unavailable (requires installed PWA + iOS 16.4+)");const W=(A??await w(U.pushManager.subscribe({userVisibleOnly:!0,applicationServerKey:$(O.publicKey)}),15e3,"Push subscription timed out")).toJSON(),te=W.keys;if(!W.endpoint||!te?.p256dh||!te.auth)throw new Error("Push subscription missing keys");if(!(await w(D.push.subscribe({endpoint:W.endpoint,keys:{p256dh:te.p256dh,auth:te.auth},origin:typeof window<"u"?window.location.origin:void 0,platform:Vc()}),15e3,"Push subscribe request timed out"))?.ok){R.error(t("settings.notifications.page.toast.enableBackgroundFailed"));return}j(!0),R.success(t("settings.notifications.page.toast.backgroundEnabled"))}catch(O){console.error("[Push] Enable failed:",O);const U=Z(O);R.error(t("settings.notifications.page.toast.enableBackgroundFailed"),{description:U.summary})}finally{S(!1)}},se=async()=>{if(!M){j(!1);return}const D=jn();if(!D?.push){R.error(t("settings.notifications.page.toast.pushApiUnavailable"));return}S(!0);try{const U=await(await X()).pushManager.getSubscription();if(!U){j(!1);return}const A=U.endpoint;await U.unsubscribe(),await D.push.unsubscribe({endpoint:A}),j(!1),R.success(t("settings.notifications.page.toast.backgroundDisabled"))}finally{S(!1)}};return s.jsxs(s.Fragment,{children:[s.jsxs(Oe,{settingsItem:"notifications.delivery",title:t("settings.notifications.page.delivery.title"),divider:!1,children:[s.jsxs("div",{className:bs,children:[s.jsx(ut,{checked:r&&v,onChange:D=>{T(D)},label:t("settings.notifications.page.delivery.enableLabel"),info:i?t("settings.notifications.page.delivery.browserPermissionHint"):a?t("settings.notifications.page.delivery.vscodeHint"):void 0,ariaLabel:t("settings.notifications.page.delivery.enableAria")}),r&&v&&!n&&s.jsxs(s.Fragment,{children:[s.jsx(ut,{checked:x==="always",onChange:D=>c(D?"always":"hidden-only"),label:t("settings.notifications.page.delivery.focusedLabel"),ariaLabel:t("settings.notifications.page.delivery.focusedAria")}),s.jsx("div",{className:"py-2",children:s.jsx(H,{type:"button",variant:"outline",size:"sm",onClick:()=>{P()},children:t("settings.notifications.page.delivery.testAction")})})]})]}),i&&s.jsxs("div",{className:"mt-1",children:[E==="denied"&&s.jsx("p",{className:"typography-meta text-[var(--status-error)] mt-1",children:t("settings.notifications.page.delivery.permissionDenied")}),E==="granted"&&!r&&s.jsx("p",{className:"typography-meta text-muted-foreground/70 mt-1",children:t("settings.notifications.page.delivery.permissionGrantedButDisabled")})]})]}),r&&v&&s.jsxs(s.Fragment,{children:[s.jsx(Oe,{settingsItem:"notifications.events",title:t("settings.notifications.page.events.title"),children:s.jsxs("div",{className:bs,children:[s.jsx(ut,{checked:b,onChange:p,label:t("settings.notifications.page.events.completionLabel"),ariaLabel:t("settings.notifications.page.events.completionAria")}),s.jsx(ut,{checked:y,onChange:m,label:t("settings.notifications.page.events.subtaskLabel"),ariaLabel:t("settings.notifications.page.events.subtaskAria")}),s.jsx(ut,{checked:L,onChange:k,label:t("settings.notifications.page.events.errorLabel"),ariaLabel:t("settings.notifications.page.events.errorAria")}),s.jsx(ut,{checked:N,onChange:h,label:t("settings.notifications.page.events.questionLabel"),ariaLabel:t("settings.notifications.page.events.questionAria")})]})}),!n&&s.jsx(Oe,{title:t("settings.notifications.page.template.title"),description:s.jsxs(s.Fragment,{children:[t("settings.notifications.page.template.variablesLabel")," ",s.jsx("code",{className:"text-[var(--primary-base)]",children:"{project_name}"})," ",s.jsx("code",{className:"text-[var(--primary-base)]",children:"{worktree}"})," ",s.jsx("code",{className:"text-[var(--primary-base)]",children:"{branch}"})," ",s.jsx("code",{className:"text-[var(--primary-base)]",children:"{session_name}"})," ",s.jsx("code",{className:"text-[var(--primary-base)]",children:"{agent_name}"})," ",s.jsx("code",{className:"text-[var(--primary-base)]",children:"{model_name}"})," ",s.jsx("code",{className:"text-[var(--primary-base)]",children:"{last_message}"})]}),children:s.jsx(fn,{className:"gap-2 md:grid-cols-2 md:gap-3 lg:gap-3",children:["completion","subtask","error","question"].map(D=>s.jsxs("section",{className:"p-2",children:[s.jsx(Vs,{className:"capitalize",children:t(Rg[D])}),s.jsxs("div",{className:"mt-1.5 space-y-2",children:[s.jsxs("div",{children:[s.jsx("label",{className:"typography-micro text-muted-foreground block mb-1",children:t("settings.notifications.page.template.field.title")}),s.jsx(He,{value:C[D].title,onChange:O=>K(D,"title",O.target.value),className:"h-7",placeholder:t(yo[D].titleKey)})]}),s.jsxs("div",{children:[s.jsx("label",{className:"typography-micro text-muted-foreground block mb-1",children:t("settings.notifications.page.template.field.message")}),s.jsx(He,{value:C[D].message,onChange:O=>K(D,"message",O.target.value),className:"h-7",placeholder:t(yo[D].messageKey)})]})]})]},D))})})]}),i&&s.jsx(Oe,{settingsItem:"notifications.push",title:t("settings.notifications.page.push.title"),children:s.jsx(ut,{checked:M?g:!1,disabled:!M||F,onChange:D=>{D?ee():se()},label:t("settings.notifications.page.push.enableLabel"),description:M?void 0:t("settings.notifications.page.push.unsupportedHint"),info:M?t("settings.notifications.page.push.supportedHint"):void 0,ariaLabel:t("settings.notifications.page.push.enableAria"),labelAccessory:F?s.jsx("span",{className:"inline-block h-1.5 w-1.5 rounded-full bg-current text-muted-foreground animate-busy-pulse","aria-label":t("settings.notifications.page.push.loadingAria")}):null})})]})},ks=t=>{if(!t)return;t.pause();const{src:e}=t;e.startsWith("blob:")&&URL.revokeObjectURL(e),t.removeAttribute("src"),t.load()},Lg=[{id:"parakeet-tdt-0.6b-v2-int8",labelKey:"settings.voice.page.stt.model.parakeetV2",badgeKey:"settings.voice.page.stt.badge.bestForEnglish",accuracy:5,speed:5,size:"460 MB"},{id:"parakeet-tdt-0.6b-v3-int8",labelKey:"settings.voice.page.stt.model.parakeetV3",badgeKey:"settings.voice.page.stt.badge.bestForMultilingual",accuracy:5,speed:4,size:"465 MB"},{id:"whisper-base-int8",labelKey:"settings.voice.page.stt.model.whisperBase",badgeKey:null,accuracy:3,speed:3,size:"200 MB"},{id:"whisper-tiny-int8",labelKey:"settings.voice.page.stt.model.whisperTiny",badgeKey:null,accuracy:2,speed:4,size:"115 MB"}],jo=t=>{const e=ht.c(8),{value:a,label:n}=t,i=`${n}: ${a}/5`,r=`${a/5*100}%`;let l;e[0]!==r?(l=s.jsx("span",{className:"h-1.5 w-12 flex-shrink-0 overflow-hidden rounded-full bg-[var(--interactive-border)]","aria-hidden":"true",children:s.jsx("span",{className:"block h-full rounded-full bg-[var(--primary-base)]",style:{width:r}})}),e[0]=r,e[1]=l):l=e[1];let x;e[2]!==n?(x=s.jsx("span",{className:"typography-ui-compact text-muted-foreground",children:n}),e[2]=n,e[3]=x):x=e[3];let c;return e[4]!==i||e[5]!==l||e[6]!==x?(c=s.jsxs("span",{className:"flex items-center gap-1.5",title:i,children:[l,x]}),e[4]=i,e[5]=l,e[6]=x,e[7]=c):c=e[7],c},Fg=({selectedModelId:t,onSelect:e})=>{const{t:a}=ot(),n=We.useCallback(p=>a(p),[a]),[i,r]=We.useState(new Map),[l,x]=We.useState(null),c=We.useCallback(async()=>{try{const p=await ct("/api/dictation/status",{query:{provider:"local"}});if(!p.ok)return;const L=await p.json();Array.isArray(L?.models)&&r(new Map(L.models.map(k=>[k.id,k])))}catch{}},[]);We.useEffect(()=>{c()},[c]);const y=Array.from(i.values()).some(p=>p.downloading);We.useEffect(()=>{if(!y)return;const p=setInterval(()=>{c()},2e3);return()=>clearInterval(p)},[y,c]);const m=async p=>{x(p);try{await ct(`/api/dictation/models/${encodeURIComponent(p)}/download`,{method:"POST"}),await c()}catch{}finally{x(null)}},b=async p=>{x(p);try{await ct(`/api/dictation/models/${encodeURIComponent(p)}`,{method:"DELETE"}),await c()}catch{}finally{x(null)}};return s.jsx("div",{role:"radiogroup","aria-label":a("settings.voice.page.field.model"),className:"mt-1.5 grid w-full grid-cols-1 gap-3 @xl:grid-cols-2",children:Lg.map(p=>{const L=t===p.id,k=i.get(p.id)??null;return s.jsx("div",{className:je("rounded-lg border border-[var(--interactive-border)] p-3",L&&"border-[var(--primary-base)] bg-[var(--primary-base)]/5"),children:s.jsxs("div",{className:"flex items-start justify-between gap-2",children:[s.jsxs("div",{className:"flex min-w-0 flex-1 cursor-pointer items-start gap-2",role:"button",tabIndex:0,onClick:()=>e(p.id),onKeyDown:N=>{(N.key===" "||N.key==="Enter")&&(N.preventDefault(),e(p.id))},children:[s.jsx("div",{className:"pt-0.5",children:s.jsx(Wi,{checked:L,onChange:()=>e(p.id),ariaLabel:n(p.labelKey)})}),s.jsxs("div",{className:"min-w-0 flex-1 space-y-2",children:[s.jsxs("div",{className:"flex flex-wrap items-center gap-2",children:[s.jsx("span",{className:je("typography-ui-label font-normal",L?"text-foreground":"text-foreground/50"),children:n(p.labelKey)}),p.badgeKey?s.jsx("span",{className:"rounded border border-[var(--status-success-border)] bg-[var(--status-success-background)] px-1 text-[9px] font-medium uppercase leading-[14px] tracking-wide text-[var(--status-success)]",children:n(p.badgeKey)}):null]}),s.jsxs("div",{className:"flex flex-col gap-1.5",children:[s.jsx(jo,{value:p.accuracy,label:a("settings.voice.page.stt.meta.accuracy")}),s.jsx(jo,{value:p.speed,label:a("settings.voice.page.stt.meta.speed")}),s.jsx("span",{className:"typography-ui-compact tabular-nums text-muted-foreground",children:p.size})]}),k?.downloadError?s.jsx("p",{className:"typography-meta text-[var(--status-error)]",children:k.downloadError}):null]})]}),s.jsx("div",{className:"flex shrink-0 items-center gap-1",children:k?.installed?s.jsxs(s.Fragment,{children:[s.jsx(H,{variant:"ghost",size:"xs",className:"h-6 w-6 p-0 text-muted-foreground hover:text-[var(--status-error)]",disabled:l===p.id,onClick:()=>{b(p.id)},title:a("settings.voice.page.stt.modelDelete"),"aria-label":a("settings.voice.page.stt.modelDelete"),children:s.jsx(_,{name:"delete-bin",className:"h-4 w-4"})}),s.jsx(_,{name:"checkbox-circle",className:"h-4 w-4 flex-shrink-0 text-[var(--status-success)]","aria-label":a("settings.voice.page.stt.modelInstalled")})]}):k?.downloading?s.jsxs("span",{className:"flex items-center gap-1.5",children:[s.jsx(_,{name:"loader-4",className:"h-3.5 w-3.5 animate-spin text-muted-foreground"}),s.jsx("span",{className:"typography-ui-compact tabular-nums text-muted-foreground",children:typeof k.downloadProgress=="number"?`${k.downloadProgress}%`:""})]}):s.jsx(H,{variant:"ghost",size:"xs",className:"h-6 w-6 p-0",disabled:l===p.id,onClick:()=>{m(p.id)},title:a("settings.voice.page.stt.modelDownload"),"aria-label":a("settings.voice.page.stt.modelDownload"),children:s.jsx(_,{name:"download",className:"h-4 w-4"})})})]})},p.id)})})},Ti=[{id:0,label:"Alloy (af)"},{id:1,label:"Bella (af)"},{id:2,label:"Nicole (af)"},{id:3,label:"Sarah (af)"},{id:4,label:"Sky (af)"},{id:5,label:"Adam (am)"},{id:6,label:"Michael (am)"},{id:7,label:"Emma (bf)"},{id:8,label:"Isabella (bf)"},{id:9,label:"George (bm)"},{id:10,label:"Lewis (bm)"}],Ei="kokoro-en-v0_19",Kg=()=>{const{t}=ot(),[e,a]=We.useState(null),[n,i]=We.useState(!1),r=We.useCallback(async()=>{try{const x=await ct("/api/dictation/status",{query:{provider:"local"}});if(!x.ok)return;const c=await x.json(),y=Array.isArray(c?.ttsModels)?c.ttsModels.find(m=>m.id===Ei):null;y&&a(y)}catch{}},[]);We.useEffect(()=>{r()},[r]),We.useEffect(()=>{if(!e?.downloading)return;const x=setInterval(()=>{r()},2e3);return()=>clearInterval(x)},[e?.downloading,r]);const l=async x=>{i(!0);try{const c=x==="POST"?`/api/dictation/models/${Ei}/download`:`/api/dictation/models/${Ei}`;await ct(c,{method:x}),await r()}catch{}finally{i(!1)}};return e?s.jsxs("div",{className:"flex items-center gap-2 py-1.5",children:[s.jsx("span",{className:"typography-ui-label text-foreground",children:"Kokoro"}),s.jsx("span",{className:"typography-ui-compact tabular-nums text-muted-foreground",children:"305 MB"}),e.installed?s.jsxs(s.Fragment,{children:[s.jsx(_,{name:"checkbox-circle",className:"h-4 w-4 text-[var(--status-success)]","aria-label":t("settings.voice.page.stt.modelInstalled")}),s.jsx(H,{variant:"ghost",size:"xs",className:"h-6 w-6 p-0 text-muted-foreground hover:text-[var(--status-error)]",disabled:n,onClick:()=>{l("DELETE")},title:t("settings.voice.page.stt.modelDelete"),"aria-label":t("settings.voice.page.stt.modelDelete"),children:s.jsx(_,{name:"delete-bin",className:"h-4 w-4"})})]}):e.downloading?s.jsxs("span",{className:"flex items-center gap-1.5",children:[s.jsx(_,{name:"loader-4",className:"h-3.5 w-3.5 animate-spin text-muted-foreground"}),s.jsx("span",{className:"typography-ui-compact tabular-nums text-muted-foreground",children:typeof e.downloadProgress=="number"?`${e.downloadProgress}%`:""})]}):s.jsx(H,{variant:"ghost",size:"xs",className:"h-6 w-6 p-0",disabled:n,onClick:()=>{l("POST")},title:t("settings.voice.page.stt.modelDownload"),"aria-label":t("settings.voice.page.stt.modelDownload"),children:s.jsx(_,{name:"download",className:"h-4 w-4"})}),e.downloadError?s.jsx("span",{className:"typography-meta text-[var(--status-error)]",children:e.downloadError}):null]}):null},_g=[{value:"alloy",label:"Alloy"},{value:"ash",label:"Ash"},{value:"ballad",label:"Ballad"},{value:"coral",label:"Coral"},{value:"echo",label:"Echo"},{value:"fable",label:"Fable"},{value:"nova",label:"Nova"},{value:"onyx",label:"Onyx"},{value:"sage",label:"Sage"},{value:"shimmer",label:"Shimmer"},{value:"verse",label:"Verse"},{value:"marin",label:"Marin"},{value:"cedar",label:"Cedar"}],zg=()=>{const{t}=ot(),{isMobile:e}=Jn(),a=nt(B=>B.voiceProvider),n=nt(B=>B.setVoiceProvider),i=nt(B=>B.speechRate),r=nt(B=>B.setSpeechRate),l=nt(B=>B.speechPitch),x=nt(B=>B.setSpeechPitch),c=nt(B=>B.speechVolume),y=nt(B=>B.setSpeechVolume),m=nt(B=>B.sayVoice),b=nt(B=>B.setSayVoice),p=nt(B=>B.localTtsVoiceId),L=nt(B=>B.setLocalTtsVoiceId),{speak:k,stop:N,isPlaying:h,error:C}=hc(),u=We.useCallback(()=>{if(h){N();return}const B=Ti.find(Ue=>Ue.id===p)?.label??String(p);k(t("settings.voice.page.preview.voiceLine",{voiceName:B}),{speakerId:p,speed:nt.getState().speechRate})},[h,p,k,N,t]),E=nt(B=>B.browserVoice),q=nt(B=>B.setBrowserVoice),M=nt(B=>B.openaiVoice),I=nt(B=>B.setOpenaiVoice),g=nt(B=>B.openaiApiKey),j=nt(B=>B.setOpenaiApiKey),F=nt(B=>B.openaiCompatibleUrl),S=nt(B=>B.setOpenaiCompatibleUrl),T=nt(B=>B.openaiCompatibleApiKey),v=nt(B=>B.setOpenaiCompatibleApiKey),K=nt(B=>B.openaiCompatibleVoice),$=nt(B=>B.setOpenaiCompatibleVoice),w=nt(B=>B.openaiCompatibleTtsModel),G=nt(B=>B.setOpenaiCompatibleTtsModel),Q=nt(B=>B.showMessageTTSButtons),X=nt(B=>B.ttsInputMode),Z=nt(B=>B.setTtsInputMode),P=nt(B=>B.sttProvider),ee=nt(B=>B.setSttProvider),se=nt(B=>B.sttServerUrl),D=nt(B=>B.setSttServerUrl),O=nt(B=>B.sttApiKey),U=nt(B=>B.setSttApiKey),A=nt(B=>B.sttModel),V=nt(B=>B.setSttModel),W=nt(B=>B.sttLocalModel),te=nt(B=>B.setSttLocalModel),ae=nt(B=>B.sttLanguage),le=nt(B=>B.setSttLanguage),be=nt(B=>B.setShowMessageTTSButtons),ke=nt(B=>B.dictationEnabled),ce=nt(B=>B.setDictationEnabled),[ge,Ee]=We.useState(!1),[Se,Ne]=We.useState([]),[fe,Ke]=We.useState(!1),[De,he]=We.useState(null),[pe,Ie]=We.useState(!1),[ze,Je]=We.useState(!1),[_e,Le]=We.useState(null),[Pe,Ye]=We.useState(!1),[Ge,Me]=We.useState(null),[$e,Fe]=We.useState([]),[ye,z]=We.useState(!1);We.useEffect(()=>((async()=>{const Ue=await fi.waitForVoices();Fe(Ue)})(),"speechSynthesis"in window&&(window.speechSynthesis.onvoiceschanged=()=>{Fe(window.speechSynthesis.getVoices())}),()=>{"speechSynthesis"in window&&(window.speechSynthesis.onvoiceschanged=null)}),[]);const oe=We.useMemo(()=>$e.filter(B=>B.lang).sort((B,Ue)=>{const Qe=B.lang.startsWith("en"),et=Ue.lang.startsWith("en");if(Qe&&!et)return-1;if(!Qe&&et)return 1;const tt=B.lang.localeCompare(Ue.lang);return tt!==0?tt:B.name.localeCompare(Ue.name)}),[$e]),me=We.useCallback(()=>{if(ye){fi.cancelSpeech(),z(!1);return}const B=$e.find(tt=>tt.name===E),Ue=B?.name??t("settings.voice.page.preview.browserVoiceFallback"),Qe=t("settings.voice.page.preview.voiceLine",{voiceName:Ue});z(!0);const et=new SpeechSynthesisUtterance(Qe);et.rate=i,et.pitch=l,et.volume=c,B&&(et.voice=B,et.lang=B.lang),et.onend=()=>z(!1),et.onerror=()=>z(!1),window.speechSynthesis.cancel(),window.speechSynthesis.speak(et)},[E,$e,i,l,c,ye,t]);We.useEffect(()=>()=>{ye&&fi.cancelSpeech()},[ye]),We.useEffect(()=>{if(!Q||a!=="openai"&&a!=="openai-compatible"){Ie(g.trim().length>0);return}(async()=>{try{const et=(await(await ct("/api/tts/status")).json()).available,tt=g.trim().length>0;Ie(et||tt)}catch{Ie(g.trim().length>0)}})()},[g,Q,a]),We.useEffect(()=>{if(!Q){Ee(!1),Ne([]);return}ct("/api/tts/say/status").then(B=>B.json()).then(B=>{if(Ee(B.available),B.voices){const Ue=B.voices.filter((Qe,et,tt)=>tt.findIndex(wt=>wt.name===Qe.name)===et).sort((Qe,et)=>Qe.name.localeCompare(et.name));Ne(Ue)}}).catch(()=>{Ee(!1)})},[Q]);const ve=We.useCallback(async()=>{if(De){ks(De),he(null),Ke(!1);return}Ke(!0);let B=null;try{const Ue=await ct("/api/tts/say/speak",{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify({text:t("settings.voice.page.preview.voiceLine",{voiceName:m}),voice:m,rate:Math.round(100+(i-.5)*200)})});if(!Ue.ok)throw new Error("Preview failed");const Qe=await Ue.blob(),et=URL.createObjectURL(Qe);B=new Audio(et),B.onended=()=>{ks(B),he(null),Ke(!1)},B.onerror=()=>{ks(B),he(null),Ke(!1)},he(B),await B.play()}catch{ks(B),he(null),Ke(!1)}},[m,i,De,t]);We.useEffect(()=>()=>{ks(De)},[De]);const re=We.useCallback(async()=>{if(_e){ks(_e),Le(null),Je(!1);return}Je(!0);let B=null;try{const Ue=await ct("/api/tts/speak",{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify({text:t("settings.voice.page.preview.voiceLine",{voiceName:M}),voice:M,speed:i,apiKey:g||void 0})});if(!Ue.ok){const tt=await Ue.json().catch(()=>({error:"Unknown error"}));throw new Error(tt.error||`HTTP ${Ue.status}`)}const Qe=await Ue.blob(),et=URL.createObjectURL(Qe);B=new Audio(et),B.onended=()=>{ks(B),Le(null),Je(!1)},B.onerror=()=>{ks(B),Le(null),Je(!1)},Le(B),await B.play()}catch{ks(B),Le(null),Je(!1)}},[M,i,_e,g,t]);We.useEffect(()=>()=>{ks(_e)},[_e]);const Ve=We.useCallback(async()=>{if(Ge){ks(Ge),Me(null),Ye(!1);return}if(!F.trim())return;Ye(!0);let B=null;try{const Ue=await ct("/api/tts/speak",{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify({text:t("settings.voice.page.preview.customServerLine"),voice:K,model:w||void 0,speed:i,baseURL:F,apiKey:T||void 0})});if(!Ue.ok){const tt=await Ue.json().catch(()=>({error:"Unknown error"}));throw new Error(tt.error||`HTTP ${Ue.status}`)}const Qe=await Ue.blob(),et=URL.createObjectURL(Qe);B=new Audio(et),B.onended=()=>{ks(B),Me(null),Ye(!1)},B.onerror=()=>{ks(B),Me(null),Ye(!1)},Me(B),await B.play()}catch{ks(B),Me(null),Ye(!1)}},[F,K,w,T,i,Ge,t]);We.useEffect(()=>()=>{ks(Ge)},[Ge]);const Ze="flex-1 min-w-0 h-1.5 bg-[var(--interactive-border)] rounded-full appearance-none cursor-pointer [&::-webkit-slider-thumb]:appearance-none [&::-webkit-slider-thumb]:w-4 [&::-webkit-slider-thumb]:h-4 [&::-webkit-slider-thumb]:rounded-full [&::-webkit-slider-thumb]:bg-[var(--primary-base)] [&::-moz-range-thumb]:w-4 [&::-moz-range-thumb]:h-4 [&::-moz-range-thumb]:rounded-full [&::-moz-range-thumb]:bg-[var(--primary-base)] [&::-moz-range-thumb]:border-0 disabled:opacity-50";return s.jsxs(s.Fragment,{children:[s.jsxs(Oe,{settingsItem:"voice.playback",title:t("settings.voice.page.section.playbackAndSummary"),divider:!1,contentClassName:"space-y-4",children:[s.jsx(ut,{checked:Q,onChange:be,label:t("settings.voice.page.field.messageReadAloudButton"),ariaLabel:t("settings.voice.page.field.messageReadAloudButtonAria")}),Q&&s.jsxs(s.Fragment,{children:[s.jsx(Os,{title:t("settings.voice.page.field.provider"),info:s.jsxs("ul",{className:"space-y-1",children:[s.jsxs("li",{children:[s.jsx("strong",{children:t("settings.voice.page.provider.browser")})," ",t("settings.voice.page.tooltip.browser")]}),s.jsxs("li",{children:[s.jsx("strong",{children:t("settings.voice.page.provider.local")})," ",t("settings.voice.page.tooltip.localTts")]}),s.jsxs("li",{children:[s.jsx("strong",{children:t("settings.voice.page.provider.openai")})," ",t("settings.voice.page.tooltip.openai")]}),s.jsxs("li",{children:[s.jsx("strong",{children:t("settings.voice.page.provider.custom")})," ",t("settings.voice.page.tooltip.custom")]}),s.jsxs("li",{children:[s.jsx("strong",{children:t("settings.voice.page.provider.say")})," ",t("settings.voice.page.tooltip.say")]})]}),children:s.jsx(Ls,{value:a,onChange:n,"aria-label":t("settings.voice.page.field.provider"),className:"w-full gap-1.5 sm:gap-2",options:[{value:"browser",label:t("settings.voice.page.provider.browser")},{value:"local",label:t("settings.voice.page.provider.local")},{value:"openai",label:t("settings.voice.page.provider.openai")},{value:"openai-compatible",label:t("settings.voice.page.provider.custom")},...ge?[{value:"say",label:s.jsxs(s.Fragment,{children:[s.jsx(_,{name:"apple",className:"mr-0.5 h-3.5 w-3.5"}),t("settings.voice.page.provider.say")]})}]:[]]})}),a==="openai"&&s.jsxs("div",{className:"space-y-1.5",children:[s.jsx("span",{className:je(Et,!pe&&"text-[var(--status-error)]"),children:t("settings.voice.page.field.apiKey")}),s.jsx("span",{className:je(In,!pe&&"text-[var(--status-error)]/80"),children:t(pe&&!g?"settings.voice.page.field.apiKeyHintUsingConfig":pe?"settings.voice.page.field.apiKeyHintProvide":"settings.voice.page.field.apiKeyHintRequired")}),s.jsxs("div",{className:je("relative",As),children:[s.jsx("input",{type:"password",value:g,onChange:B=>j(B.target.value),placeholder:"sk-...",className:"w-full h-7 rounded-lg border border-input bg-transparent px-2 typography-ui-label text-foreground placeholder:text-muted-foreground focus:outline-none focus:ring-1 focus:ring-primary/50 focus:border-primary/70"}),g&&s.jsx("button",{type:"button",onClick:()=>j(""),className:"absolute right-2 top-1/2 -translate-y-1/2 text-muted-foreground hover:text-foreground",children:s.jsx(_,{name:"close",className:"w-3.5 h-3.5"})})]})]}),a==="openai-compatible"&&s.jsxs("div",{className:"space-y-3",children:[s.jsxs("div",{className:"space-y-1.5",children:[s.jsxs("span",{className:"flex items-center gap-1.5",children:[s.jsx("span",{className:je(Et,!F.trim()&&"text-[var(--status-error)]"),children:t("settings.voice.page.field.serverUrl")}),s.jsx(Yt,{children:t("settings.voice.page.field.serverUrlHint")})]}),s.jsxs("div",{className:je("relative",As),children:[s.jsx("input",{type:"text",value:F,onChange:B=>S(B.target.value),placeholder:"http://localhost:8880/v1",className:"w-full h-7 rounded-lg border border-input bg-transparent px-2 typography-ui-label text-foreground placeholder:text-muted-foreground focus:outline-none focus:ring-1 focus:ring-primary/50 focus:border-primary/70"}),F&&s.jsx("button",{type:"button",onClick:()=>S(""),className:"absolute right-2 top-1/2 -translate-y-1/2 text-muted-foreground hover:text-foreground",children:s.jsx(_,{name:"close",className:"w-3.5 h-3.5"})})]})]}),s.jsxs("div",{className:"space-y-1.5",children:[s.jsx("span",{className:Et,children:"API Key"}),s.jsx("span",{className:In,children:"Optional"}),s.jsxs("div",{className:je("relative",As),children:[s.jsx("input",{type:"password",value:T,onChange:B=>v(B.target.value),placeholder:"sk-...",className:"w-full h-7 rounded-lg border border-input bg-transparent px-2 typography-ui-label text-foreground placeholder:text-muted-foreground focus:outline-none focus:ring-1 focus:ring-primary/50 focus:border-primary/70"}),T&&s.jsx("button",{type:"button",onClick:()=>v(""),className:"absolute right-2 top-1/2 -translate-y-1/2 text-muted-foreground hover:text-foreground",children:s.jsx(_,{name:"close",className:"w-3.5 h-3.5"})})]})]}),s.jsxs("div",{className:"space-y-1.5",children:[s.jsx("span",{className:Et,children:t("settings.voice.page.field.model")}),s.jsx("div",{className:je("relative",As),children:s.jsx("input",{type:"text",value:w,onChange:B=>G(B.target.value),placeholder:"speaches-ai/Kokoro-82M-v1.0-ONNX",className:"w-full h-7 rounded-lg border border-input bg-transparent px-2 typography-ui-label text-foreground placeholder:text-muted-foreground focus:outline-none focus:ring-1 focus:ring-primary/50 focus:border-primary/70"})})]}),s.jsxs("div",{className:"space-y-1.5",children:[s.jsxs("span",{className:"flex items-center gap-1.5",children:[s.jsx("span",{className:Et,children:t("settings.voice.page.field.voice")}),s.jsx(Yt,{children:t("settings.voice.page.field.voiceIdentifierHint")})]}),s.jsxs("div",{className:je("flex items-center gap-2",As),children:[s.jsx("div",{className:"relative min-w-0 flex-1",children:s.jsx("input",{type:"text",value:K,onChange:B=>$(B.target.value),placeholder:"af_sky",className:"w-full h-7 rounded-lg border border-input bg-transparent px-2 typography-ui-label text-foreground placeholder:text-muted-foreground focus:outline-none focus:ring-1 focus:ring-primary/50 focus:border-primary/70"})}),s.jsx(H,{size:"xs",variant:"ghost",onClick:Ve,title:t("settings.voice.page.actions.preview"),disabled:!F.trim(),children:Pe?s.jsx(_,{name:"stop",className:"w-3.5 h-3.5"}):s.jsx(_,{name:"play",className:"w-3.5 h-3.5"})})]})]})]}),a==="local"&&s.jsx(Kg,{}),s.jsxs($t,{label:t("settings.voice.page.field.voice"),children:[a==="local"&&s.jsxs(s.Fragment,{children:[s.jsxs(Dt,{value:String(p),onValueChange:B=>L(Number.parseInt(B,10)||0),children:[s.jsx(Mt,{size:Kt,className:vn,children:s.jsx(_t,{placeholder:t("settings.voice.page.field.selectVoicePlaceholder"),children:B=>Ti.find(Ue=>String(Ue.id)===B)?.label??B})}),s.jsx(Rt,{children:Ti.map(B=>s.jsx(dt,{value:String(B.id),children:B.label},B.id))})]}),s.jsx(H,{size:"xs",variant:"ghost",onClick:u,title:t("settings.voice.page.actions.preview"),children:h?s.jsx(_,{name:"stop",className:"w-3.5 h-3.5"}):s.jsx(_,{name:"play",className:"w-3.5 h-3.5"})}),C?s.jsx("span",{className:"typography-meta text-[var(--status-error)]",children:C}):null]}),a==="openai"&&pe&&s.jsxs(s.Fragment,{children:[s.jsxs(Dt,{value:M,onValueChange:I,children:[s.jsx(Mt,{size:Kt,className:vn,children:s.jsx(_t,{placeholder:t("settings.voice.page.field.selectVoicePlaceholder")})}),s.jsx(Rt,{children:_g.map(B=>s.jsx(dt,{value:B.value,children:B.label},B.value))})]}),s.jsx(H,{size:"xs",variant:"ghost",onClick:re,title:t("settings.voice.page.actions.preview"),children:ze?s.jsx(_,{name:"stop",className:"w-3.5 h-3.5"}):s.jsx(_,{name:"play",className:"w-3.5 h-3.5"})})]}),a==="openai-compatible"&&s.jsx("span",{className:In,children:t("settings.voice.page.field.configuredAbove")}),a==="say"&&ge&&Se.length>0&&s.jsxs(s.Fragment,{children:[s.jsxs(Dt,{value:m,onValueChange:b,children:[s.jsx(Mt,{size:Kt,className:vn,children:s.jsx(_t,{placeholder:t("settings.voice.page.field.selectVoicePlaceholder")})}),s.jsx(Rt,{children:Se.map(B=>s.jsx(dt,{value:B.name,children:B.name},B.name))})]}),s.jsx(H,{size:"xs",variant:"ghost",onClick:ve,title:t("settings.voice.page.actions.preview"),children:fe?s.jsx(_,{name:"stop",className:"w-3.5 h-3.5"}):s.jsx(_,{name:"play",className:"w-3.5 h-3.5"})})]}),a==="browser"&&oe.length>0&&s.jsxs(s.Fragment,{children:[s.jsxs(Dt,{value:E||"$auto",onValueChange:B=>q(B==="$auto"?"":B),children:[s.jsx(Mt,{size:Kt,className:vn,children:s.jsx(_t,{placeholder:t("settings.voice.page.field.auto")})}),s.jsxs(Rt,{children:[s.jsx(dt,{value:"$auto",children:t("settings.voice.page.field.auto")}),oe.map(B=>s.jsxs(dt,{value:B.name,children:[B.name," (",B.lang,")"]},B.name))]})]}),s.jsx(H,{size:"xs",variant:"ghost",onClick:me,title:t("settings.voice.page.actions.preview"),children:ye?s.jsx(_,{name:"stop",className:"w-3.5 h-3.5"}):s.jsx(_,{name:"play",className:"w-3.5 h-3.5"})})]})]}),s.jsxs($t,{label:t("settings.voice.page.field.speechRate"),children:[!e&&s.jsx("input",{type:"range",min:.5,max:2,step:.1,value:i,onChange:B=>r(Number(B.target.value)),className:Ze}),s.jsx(ys,{value:i,onValueChange:r,min:.5,max:2,step:.1,className:"w-16 tabular-nums"})]}),s.jsxs($t,{label:t("settings.voice.page.field.speechPitch"),children:[!e&&s.jsx("input",{type:"range",min:.5,max:2,step:.1,value:l,onChange:B=>x(Number(B.target.value)),className:Ze}),s.jsx(ys,{value:l,onValueChange:x,min:.5,max:2,step:.1,className:"w-16 tabular-nums"})]}),s.jsxs($t,{label:t("settings.voice.page.field.speechVolume"),children:[!e&&s.jsx("input",{type:"range",min:0,max:1,step:.1,value:c,onChange:B=>y(Number(B.target.value)),className:Ze}),e?s.jsx(ys,{value:Math.round(c*100),onValueChange:B=>y(B/100),min:0,max:100,step:10,className:"w-16 tabular-nums"}):s.jsxs("span",{className:"typography-ui-label text-foreground tabular-nums min-w-[3rem] text-right",children:[Math.round(c*100),"%"]})]}),s.jsx(Os,{title:t("settings.voice.page.field.ttsInputMode"),children:s.jsx(Ls,{value:X,onChange:Z,"aria-label":t("settings.voice.page.field.ttsInputMode"),className:"w-full gap-1.5 sm:gap-2",options:[{value:"sanitized",label:t("settings.voice.page.field.ttsInputModeSanitized")},{value:"raw",label:t("settings.voice.page.field.ttsInputModeRaw")},{value:"summarized",label:t("settings.voice.page.field.ttsInputModeSummarized")}]})})]})]}),s.jsxs(Oe,{settingsItem:"voice.speech-recognition",title:t("settings.voice.page.section.speechRecognition"),contentClassName:"space-y-4",children:[s.jsx(ut,{checked:ke,onChange:ce,label:t("settings.voice.page.field.enableVoiceInput"),ariaLabel:t("settings.voice.page.field.enableVoiceInputAria")}),ke&&s.jsxs(s.Fragment,{children:[s.jsx(Os,{title:t("settings.voice.page.field.provider"),info:s.jsxs("ul",{className:"space-y-1",children:[s.jsxs("li",{children:[s.jsx("strong",{children:t("settings.voice.page.provider.local")})," ",t("settings.voice.page.tooltip.sttLocal")]}),s.jsxs("li",{children:[s.jsx("strong",{children:t("settings.voice.page.provider.server")})," ",t("settings.voice.page.tooltip.sttServer")]})]}),children:s.jsx(Ls,{value:P,onChange:ee,"aria-label":t("settings.voice.page.field.provider"),className:"w-full gap-1.5 sm:gap-2",options:[{value:"local",label:t("settings.voice.page.provider.local")},{value:"openai-compatible",label:t("settings.voice.page.provider.server")}]})}),P==="local"&&s.jsxs("div",{className:"space-y-1.5",children:[s.jsx("span",{className:Et,children:t("settings.voice.page.field.model")}),s.jsx(Fg,{selectedModelId:W,onSelect:te})]}),P==="openai-compatible"&&s.jsxs("div",{className:"space-y-3",children:[s.jsxs("div",{className:"space-y-1.5",children:[s.jsxs("span",{className:"flex items-center gap-1.5",children:[s.jsx("span",{className:je(Et,!se.trim()&&"text-[var(--status-error)]"),children:t("settings.voice.page.field.serverUrl")}),s.jsx(Yt,{children:t("settings.voice.page.field.sttServerUrlHint")})]}),s.jsxs("div",{className:je("relative",As),children:[s.jsx("input",{type:"text",value:se,onChange:B=>D(B.target.value),placeholder:"http://localhost:8001/v1",className:"w-full h-7 rounded-lg border border-input bg-transparent px-2 typography-ui-label text-foreground placeholder:text-muted-foreground focus:outline-none focus:ring-1 focus:ring-primary/50 focus:border-primary/70"}),se&&s.jsx("button",{type:"button",onClick:()=>D(""),className:"absolute right-2 top-1/2 -translate-y-1/2 text-muted-foreground hover:text-foreground",children:s.jsx(_,{name:"close",className:"w-3.5 h-3.5"})})]})]}),s.jsxs("div",{className:"space-y-1.5",children:[s.jsx("span",{className:Et,children:"API Key"}),s.jsx("span",{className:In,children:"Optional"}),s.jsxs("div",{className:je("relative",As),children:[s.jsx("input",{type:"password",value:O,onChange:B=>U(B.target.value),placeholder:"sk-...",className:"w-full h-7 rounded-lg border border-input bg-transparent px-2 typography-ui-label text-foreground placeholder:text-muted-foreground focus:outline-none focus:ring-1 focus:ring-primary/50 focus:border-primary/70"}),O&&s.jsx("button",{type:"button",onClick:()=>U(""),className:"absolute right-2 top-1/2 -translate-y-1/2 text-muted-foreground hover:text-foreground",children:s.jsx(_,{name:"close",className:"w-3.5 h-3.5"})})]})]}),s.jsxs("div",{className:"space-y-1.5",children:[s.jsx("span",{className:Et,children:t("settings.voice.page.field.model")}),s.jsx("div",{className:je("relative",As),children:s.jsx("input",{type:"text",value:A,onChange:B=>V(B.target.value),placeholder:"deepdml/faster-whisper-large-v3-turbo-ct2",className:"w-full h-7 rounded-lg border border-input bg-transparent px-2 typography-ui-label text-foreground placeholder:text-muted-foreground focus:outline-none focus:ring-1 focus:ring-primary/50 focus:border-primary/70"})})]}),s.jsxs("div",{className:"space-y-1.5",children:[s.jsxs("span",{className:"flex items-center gap-1.5",children:[s.jsx("span",{className:Et,children:t("settings.voice.page.field.language")}),s.jsx(Yt,{children:t("settings.voice.page.field.sttLanguageHint")})]}),s.jsx("div",{className:"relative max-w-[8rem]",children:s.jsx("input",{type:"text",value:ae,onChange:B=>le(B.target.value),placeholder:"auto",className:"w-full h-7 rounded-lg border border-input bg-transparent px-2 typography-ui-label text-foreground placeholder:text-muted-foreground focus:outline-none focus:ring-1 focus:ring-primary/50 focus:border-primary/70"})})]})]})]})]})]})},Ua=[{value:"1800000",label:"30m",ms:1800*1e3},{value:"180000",label:"3m",ms:180*1e3},{value:"7200000",label:"2h",ms:7200*1e3},{value:"28800000",label:"8h",ms:480*60*1e3},{value:"86400000",label:"24h",ms:1440*60*1e3}],Va=[{value:"3600000",label:"1h",ms:3600*1e3},{value:"28800000",label:"8h",ms:480*60*1e3},{value:"43200000",label:"12h",ms:720*60*1e3},{value:"86400000",label:"24h",ms:1440*60*1e3},{value:"604800000",label:"1w",ms:10080*60*1e3},{value:"2592000000",label:"30d",ms:720*60*60*1e3}],Ug="https://developers.cloudflare.com/cloudflare-one/networks/connectors/cloudflare-tunnel/get-started/create-remote-tunnel/",Vg="https://developers.cloudflare.com/cloudflare-one/networks/connectors/cloudflare-tunnel/do-more-with-tunnels/local-management/configuration-file/",Di=[{value:"quick",labelKey:"settings.openchamber.tunnel.option.mode.quick.label",tooltipKey:"settings.openchamber.tunnel.option.mode.quick.tooltip"},{value:"managed-remote",labelKey:"settings.openchamber.tunnel.option.mode.managedRemote.label",tooltipKey:"settings.openchamber.tunnel.option.mode.managedRemote.tooltip"},{value:"managed-local",labelKey:"settings.openchamber.tunnel.option.mode.managedLocal.label",tooltipKey:"settings.openchamber.tunnel.option.mode.managedLocal.tooltip"}],$g=[".yml",".yaml",".json"],Bg="settings.openchamber.tunnel.error.invalidConfigExtension",ca=t=>{const e=t.trim().toLowerCase();return $g.some(a=>e.endsWith(a))},Hg=t=>t==="ngrok"?"ngrok":"cloudflared",gl=()=>{if(typeof window<"u"&&typeof window.__OPENCHAMBER_PLATFORM__=="string"){const e=window.__OPENCHAMBER_PLATFORM__;if(e==="win32"||e==="darwin"||e==="linux")return e}const t=typeof navigator<"u"?`${navigator.platform||""} ${navigator.userAgent||""}`.toLowerCase():"";return t.includes("win")?"win32":t.includes("mac")?"darwin":"linux"},Gg=(t,e=gl())=>t==="ngrok"?e==="win32"?"winget install ngrok -s msstore":e==="darwin"?"brew install ngrok":"https://ngrok.com/download":e==="win32"?"winget install --id Cloudflare.cloudflared":e==="darwin"?"brew install cloudflared":"https://developers.cloudflare.com/cloudflare-one/networks/connectors/cloudflared/downloads/",Mi=(t,e)=>{const a=typeof e?.provider=="string"&&e.provider.trim().length>0?e.provider.trim().toLowerCase():t,n=typeof e?.dependency=="string"&&e.dependency.trim().length>0?e.dependency.trim():Hg(a),i=typeof e?.platform=="string"&&e.platform.trim().length>0?e.platform.trim():gl(),r=typeof e?.installCommand=="string"&&e.installCommand.trim().length>0?e.installCommand.trim():Gg(a,i);return{provider:a,dependency:n,installCommand:r}},hl=t=>t==="cloudflare"?"Cloudflare":t==="ngrok"?"Ngrok":t,wo=t=>{const e=ht.c(11),{provider:a}=t;let n;e[0]!==a?(n=hl(a),e[0]=a,e[1]=n):n=e[1];const i=n,x=a==="cloudflare"||a==="ngrok"?"text-[var(--status-warning)]":"text-muted-foreground";let c;e[2]!==x?(c=je("size-4 shrink-0",x),e[2]=x,e[3]=c):c=e[3];let y;e[4]!==c?(y=s.jsx(_,{name:"cloud",className:c}),e[4]=c,e[5]=y):y=e[5];let m;e[6]!==i?(m=s.jsx("span",{children:i}),e[6]=i,e[7]=m):m=e[7];let b;return e[8]!==y||e[9]!==m?(b=s.jsxs("span",{className:"flex items-center gap-2",children:[y,m]}),e[8]=y,e[9]=m,e[10]=b):b=e[10],b},un=t=>t==="quick"?"quick":t==="managed-remote"?"managed-remote":t==="managed-local"?"managed-local":"quick",Gi=(t,e,a)=>t.find(i=>i.ms===e)?.value||a,No=(t,e,a)=>{const n=Gi(t,e,a);return t.find(i=>i.value===n)?.label||n},ko=t=>{const e=Math.max(0,t),a=Math.floor(e/1e3),n=Math.floor(a/3600),i=Math.floor(a%3600/60),r=a%60;return n>0?`${n}h ${i}m`:i>0?`${i}m ${r}s`:`${r}s`},qg=(t,e)=>Oo(t,e,{hour:"2-digit",precision:"second"}),Ga=t=>{const e=t.trim();if(!e)return"";try{return(e.includes("://")?new URL(e):new URL(`https://${e}`)).hostname.trim().toLowerCase()}catch{return e.toLowerCase()}},Wg=t=>{if(!Array.isArray(t))return[];const e=new Set,a=new Set,n=[];for(const i of t){if(!i||typeof i!="object")continue;const r=i,l=typeof r.id=="string"?r.id.trim():"",x=typeof r.name=="string"?r.name.trim():"",c=Ga(typeof r.hostname=="string"?r.hostname:"");!l||!x||!c||e.has(l)||a.has(c)||(e.add(l),a.add(c),n.push({id:l,name:x,hostname:c}))}return n},Jg=()=>typeof crypto<"u"&&typeof crypto.randomUUID=="function"?crypto.randomUUID():`${Date.now()}-${Math.random().toString(36).slice(2,10)}`,Qg=()=>{const{t}=ot(),e=de(J=>J.timeFormatPreference),a=o.useCallback(J=>t(J),[t]),[n,i]=o.useState("checking"),[r,l]=o.useState(null),[x,c]=o.useState(null),[y,m]=o.useState(null),[b,p]=o.useState(null),[L,k]=o.useState(null),[N,h]=o.useState(!1),[C,u]=o.useState(!1),[E,q]=o.useState(!1),[M,I]=o.useState("cloudflare"),[g,j]=o.useState(()=>Mi("cloudflare")),[F,S]=o.useState([]),[T,v]=o.useState("quick"),[K,$]=o.useState(null),[w,G]=o.useState([]),[Q,X]=o.useState({}),[Z,P]=o.useState(""),[ee,se]=o.useState({}),[D,O]=o.useState(new Set),[U,A]=o.useState(!1),[V,W]=o.useState(""),[te,ae]=o.useState(""),[le,be]=o.useState(""),[ke,ce]=o.useState(1800*1e3),[ge,Ee]=o.useState(480*60*1e3),[Se,Ne]=o.useState(""),[fe,Ke]=o.useState([]),[De,he]=o.useState(()=>Date.now()),[pe,Ie]=o.useState(null),ze=t(Bg),Je=o.useRef(null),_e=o.useMemo(()=>K?!ca(K):!1,[K]),Le=o.useMemo(()=>w.find(J=>J.id===Z)||w[0]||null,[w,Z]),Pe=o.useMemo(()=>fe.map(J=>{const xe=J.expiresAt<=De,Re=J.status==="active"&&!xe,we=Re?ko(J.expiresAt-De):J.inactiveReason==="expired"||xe?"expired":"inactive",rt=we==="expired"?t("settings.openchamber.tunnel.state.expired"):J.inactiveReason==="tunnel-revoked"?t("settings.openchamber.tunnel.state.revoked"):t("settings.openchamber.tunnel.state.inactive"),lt=un(J.mode);return{...J,isActive:Re,mode:lt,remainingTextForSession:we,inactiveLabel:rt}}),[De,fe,t]),Ye=o.useMemo(()=>r?.connectUrl?r.bootstrapExpiresAt===null?!0:r.bootstrapExpiresAt>De:!1,[De,r?.bootstrapExpiresAt,r?.connectUrl]),Ge=o.useMemo(()=>!r||n!=="active"&&n!=="stopping"?!1:x===T,[x,n,r,T]),Me=o.useMemo(()=>!r||n!=="active"||!x?!1:x!==T,[x,n,r,T]),$e=o.useMemo(()=>{if(typeof pe=="number"&&Number.isFinite(pe)&&pe>0)return pe;if(typeof window>"u")return null;const xe=wa()||window.location.href;let Re=0;try{Re=Number(new URL(xe).port)}catch{Re=Number(window.location.port)}return Number.isFinite(Re)&&Re>0?Re:null},[pe]),Fe=o.useMemo(()=>F.find(J=>J.provider===M)??null,[F,M]),ye=o.useMemo(()=>{const J=new Set(Fe?.modes?.map(xe=>xe.key).filter(xe=>xe==="quick"||xe==="managed-remote"||xe==="managed-local"));return J.size===0?Di:Di.filter(xe=>J.has(xe.value))},[Fe]),z=o.useMemo(()=>ye.some(J=>J.value==="managed-remote"||J.value==="managed-local"),[ye]),oe=o.useMemo(()=>g.provider===M?g:Mi(M),[g,M]),me=o.useCallback(async J=>{await En(J)},[]),ve=o.useCallback((J,xe)=>(j(Mi(xe,J)),J.available===!0),[]),re=o.useCallback(async(J,xe)=>{try{const Re=await ct("/api/openchamber/tunnel/check",{query:{provider:J},...xe?{signal:xe}:{}});if(!Re.ok)return null;const we=await Re.json();if(xe?.aborted)return null;const rt=ve(we,J);return i(lt=>lt==="checking"||lt==="starting"||lt==="active"||lt==="stopping"?lt:rt?"idle":"not-available"),rt}catch{return null}},[ve]),Ve=o.useCallback(async J=>{try{const[xe,Re,we,rt]=await Promise.all([ct("/api/openchamber/tunnel/check",{signal:J}),ct("/api/openchamber/tunnel/status",{signal:J}),ct("/api/config/settings",{signal:J,headers:{Accept:"application/json"}}),ct("/api/openchamber/tunnel/providers",{signal:J})]),lt=await xe.json(),it=await Re.json(),It=we.ok?await we.json():{},ls=rt.ok?await rt.json():{},Xt=it.ttlConfig?.bootstrapTtlMs??(It?.tunnelBootstrapTtlMs===null?null:typeof It?.tunnelBootstrapTtlMs=="number"?It.tunnelBootstrapTtlMs:1800*1e3),ts=typeof it.ttlConfig?.sessionTtlMs=="number"?it.ttlConfig.sessionTtlMs:typeof It?.tunnelSessionTtlMs=="number"?It.tunnelSessionTtlMs:480*60*1e3,Wt=un(it.mode??It?.tunnelMode),kt=typeof It?.tunnelProvider=="string"&&It.tunnelProvider.trim().length>0?It.tunnelProvider.trim().toLowerCase():"cloudflare",bt=typeof It?.managedLocalTunnelConfigPath=="string"&&It.managedLocalTunnelConfigPath.trim()||null,Pt=ve(lt,kt),St=Wg(it?.managedRemoteTunnelPresets),Ft=typeof it.managedRemoteTunnelHostname=="string"?it.managedRemoteTunnelHostname:"",Bt=St.length>0?St:Ft?[{id:`legacy-${Ga(Ft)}`,name:Ft,hostname:Ga(Ft)}]:[],hs=Bt[0]?.id||"";if(ce(Xt),Ee(ts),I(kt),S(Array.isArray(ls?.providers)?ls.providers:[]),v(Wt),$(bt),G(Bt),P(hs),Ke(Array.isArray(it.activeSessions)?it.activeSessions:[]),c(it.activeTunnelMode?un(it.activeTunnelMode):it.active&&it.mode?un(it.mode):null),O(new Set(Array.isArray(it.managedRemoteTunnelTokenPresetIds)?it.managedRemoteTunnelTokenPresetIds:[])),Ie(typeof it.localPort=="number"?it.localPort:null),it.active&&it.url){l({url:it.url,connectUrl:null,bootstrapExpiresAt:typeof it.bootstrapExpiresAt=="number"?it.bootstrapExpiresAt:null}),i("active");return}i(Pt?"idle":"not-available")}catch{J.aborted||(i("error"),p(t("settings.openchamber.tunnel.toast.checkAvailabilityFailed")))}},[ve,t]);o.useEffect(()=>{const J=new AbortController;return Ve(J.signal),()=>J.abort()},[Ve]),o.useEffect(()=>{if(!r?.connectUrl){m(null);return}let J=!1;return Go.toDataURL(r.connectUrl,{width:256,margin:2,color:{dark:"#000000",light:"#ffffff"}}).then(xe=>{J||m(xe)}).catch(()=>{J||m(null)}),()=>{J=!0}},[r?.connectUrl]),o.useEffect(()=>{if(!r?.bootstrapExpiresAt){Ne(t("settings.openchamber.tunnel.state.noExpiry"));return}let J=null,xe=Date.now();const Re=()=>{const lt=r.bootstrapExpiresAt?r.bootstrapExpiresAt-Date.now():0;lt<=0?Ne(t("settings.openchamber.tunnel.state.expired")):Ne(ko(lt))},we=()=>{const lt=Date.now();lt-xe>=1e3&&(Re(),xe=lt),J=requestAnimationFrame(we)};Re(),(typeof document>"u"||document.visibilityState==="visible")&&(J=requestAnimationFrame(we));const rt=()=>{document.visibilityState==="visible"&&J===null?J=requestAnimationFrame(we):document.visibilityState!=="visible"&&J!==null&&(cancelAnimationFrame(J),J=null)};return document.addEventListener("visibilitychange",rt),()=>{document.removeEventListener("visibilitychange",rt),J!==null&&cancelAnimationFrame(J)}},[t,r?.bootstrapExpiresAt]),o.useEffect(()=>{let J=null,xe=Date.now();const Re=()=>{const rt=Date.now();rt-xe>=1e3&&(he(rt),xe=rt),J=requestAnimationFrame(Re)};(typeof document>"u"||document.visibilityState==="visible")&&(J=requestAnimationFrame(Re));const we=()=>{document.visibilityState==="visible"&&J===null?J=requestAnimationFrame(Re):document.visibilityState!=="visible"&&J!==null&&(cancelAnimationFrame(J),J=null)};return document.addEventListener("visibilitychange",we),()=>{document.removeEventListener("visibilitychange",we),J!==null&&cancelAnimationFrame(J)}},[]),o.useEffect(()=>{if(n==="starting"||n==="stopping"||n==="checking")return;let J=!1;const xe=async()=>{try{const we=await ct("/api/openchamber/tunnel/status");if(!we.ok||J)return;const rt=await we.json();if(J)return;Ke(Array.isArray(rt.activeSessions)?rt.activeSessions:[]),O(new Set(Array.isArray(rt.managedRemoteTunnelTokenPresetIds)?rt.managedRemoteTunnelTokenPresetIds:[])),Ie(typeof rt.localPort=="number"?rt.localPort:null)}catch{}},Re=window.setInterval(()=>{typeof document<"u"&&document.visibilityState!=="visible"||xe()},5e3);return()=>{J=!0,window.clearInterval(Re)}},[n]);const Ze=o.useCallback(async J=>{q(!0);try{await yt(J),Object.prototype.hasOwnProperty.call(J,"tunnelMode")&&J.tunnelMode&&v(J.tunnelMode),Object.prototype.hasOwnProperty.call(J,"tunnelProvider")&&typeof J.tunnelProvider=="string"&&I(J.tunnelProvider),Object.prototype.hasOwnProperty.call(J,"managedLocalTunnelConfigPath")&&$(J.managedLocalTunnelConfigPath??null),Object.prototype.hasOwnProperty.call(J,"managedRemoteTunnelPresets")&&J.managedRemoteTunnelPresets&&G(J.managedRemoteTunnelPresets)}catch{R.error(t("settings.openchamber.tunnel.toast.saveSettingsFailed"))}finally{q(!1)}},[t]),B=o.useCallback(async(J,xe)=>{u(!0);try{await yt({tunnelBootstrapTtlMs:J,tunnelSessionTtlMs:xe})}catch{R.error(t("settings.openchamber.tunnel.toast.saveTtlFailed"))}finally{u(!1)}},[t]),Ue=o.useCallback(async J=>{const xe=J.token.trim();if(xe)try{const Re={...ee,[J.presetId]:xe};await yt({managedRemoteTunnelPresetTokens:Re}),O(we=>{const rt=new Set(we);return rt.add(J.presetId),rt})}catch{R.error(t("settings.openchamber.tunnel.toast.saveTokenFailed"))}},[ee,t]),Qe=o.useCallback(async J=>{k(null),p(null);const xe=F.find(we=>we.provider===J),Re=xe?.modes?.some(we=>we.key===T)?T:un(xe?.modes?.[0]?.key);await Ze({tunnelProvider:J,tunnelMode:Re}),re(J)},[F,re,Ze,T]),et=o.useCallback(async()=>{const J=await Uo({filters:[{name:"Config",extensions:["yml","yaml","json"]}]});if(J.success&&typeof J.path=="string"&&J.path.trim().length>0){const xe=J.path.trim();if(!ca(xe)){R.error(ze);return}$(xe),await Ze({managedLocalTunnelConfigPath:xe});return}Je.current?.click()},[ze,Ze]),tt=o.useCallback(J=>{const xe=J.trim();$(xe.length>0?xe:null)},[]),wt=o.useCallback(async()=>{if(K&&!ca(K)){R.error(ze);return}await Ze({managedLocalTunnelConfigPath:K})},[ze,K,Ze]),mt=o.useCallback(async()=>{$(null),await Ze({managedLocalTunnelConfigPath:null})},[Ze]),pt=o.useCallback(async J=>{const xe=J.target.files?.[0];if(!xe)return;const Re=xe.name.trim();if(Re.length!==0){if(!ca(Re)){R.error(ze);return}$(Re),await Ze({managedLocalTunnelConfigPath:Re}),J.target.value=""}},[ze,Ze]),at=o.useCallback(async()=>{if(p(null),k(null),T==="managed-local"&&K&&!ca(K)){p(ze),R.error(ze);return}i("starting");try{let J="",xe="";if(T==="managed-remote"){if(!Le){i("idle"),k(t("settings.openchamber.tunnel.toast.selectOrAddManagedRemoteFirst")),R.error(t("settings.openchamber.tunnel.toast.selectOrAddManagedRemoteFirst"));return}J=Le.hostname,xe=(ee[Le.id]||"").trim(),await Ze({tunnelMode:"managed-remote",managedRemoteTunnelPresets:w})}const Re=await ct("/api/openchamber/tunnel/start",{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify({provider:M,mode:T,...T==="managed-remote"&&Le?{managedRemoteTunnelPresetId:Le.id,managedRemoteTunnelPresetName:Le.name}:{},...T==="managed-remote"&&J?{managedRemoteTunnelHostname:J}:{},...T==="managed-remote"&&xe?{managedRemoteTunnelToken:xe}:{},...T==="managed-local"&&K?{configPath:K}:{}})}),we=await Re.json();if(!Re.ok||!we.ok){if(T==="managed-remote"&&typeof we.error=="string"&&we.error.includes("Managed remote tunnel token is required")){i("idle"),k(t("settings.openchamber.tunnel.toast.managedRemoteTokenRequiredBeforeStarting")),R.error(t("settings.openchamber.tunnel.toast.addManagedRemoteTokenBeforeStarting"));return}i("error"),p(we.error||t("settings.openchamber.tunnel.toast.startFailed")),R.error(we.error||t("settings.openchamber.tunnel.toast.startFailed"));return}const rt=typeof we.url=="string"?we.url:"";if(!rt){i("error"),p(t("settings.openchamber.tunnel.toast.startedButNoPublicUrl")),R.error(t("settings.openchamber.tunnel.toast.startedButNoPublicUrl"));return}if(l({url:rt,connectUrl:typeof we.connectUrl=="string"?we.connectUrl:null,bootstrapExpiresAt:typeof we.bootstrapExpiresAt=="number"?we.bootstrapExpiresAt:null}),c(we.activeTunnelMode?un(we.activeTunnelMode):we.mode?un(we.mode):T),Ke(Array.isArray(we.activeSessions)?we.activeSessions:[]),Array.isArray(we.managedRemoteTunnelTokenPresetIds)&&O(new Set(we.managedRemoteTunnelTokenPresetIds)),typeof we.localPort=="number"&&Ie(we.localPort),typeof we.mode=="string"&&v(un(we.mode)),i("active"),we.replacedTunnel){const lt=typeof we.revokedBootstrapCount=="number"?we.revokedBootstrapCount:0,it=typeof we.invalidatedSessionCount=="number"?we.invalidatedSessionCount:0;lt===1&&it===1?R.warning(t("settings.openchamber.tunnel.toast.replacedTunnelSingleSingle")):lt===1?R.warning(t("settings.openchamber.tunnel.toast.replacedTunnelSingleManySessions",{invalidatedSessionCount:it})):it===1?R.warning(t("settings.openchamber.tunnel.toast.replacedTunnelManyLinksSingleSession",{revokedBootstrapCount:lt})):R.warning(t("settings.openchamber.tunnel.toast.replacedTunnelManyMany",{revokedBootstrapCount:lt,invalidatedSessionCount:it}))}else R.success(t("settings.openchamber.tunnel.toast.linkReady"))}catch{i("error"),p(t("settings.openchamber.tunnel.toast.startFailed")),R.error(t("settings.openchamber.tunnel.toast.startFailed"))}},[ze,w,Ze,Le,ee,t,M,T,K]),ft=o.useCallback(async()=>{i("stopping");try{await ct("/api/openchamber/tunnel/stop",{method:"POST"});const J=await ct("/api/openchamber/tunnel/status");if(J.ok){const xe=await J.json();Ke(Array.isArray(xe.activeSessions)?xe.activeSessions:[]),O(new Set(Array.isArray(xe.managedRemoteTunnelTokenPresetIds)?xe.managedRemoteTunnelTokenPresetIds:[])),Ie(typeof xe.localPort=="number"?xe.localPort:null)}l(null),c(null),m(null),i("idle"),R.success(t("settings.openchamber.tunnel.toast.stopped"))}catch{i("error"),p(t("settings.openchamber.tunnel.toast.stopFailed")),R.error(t("settings.openchamber.tunnel.toast.stopFailed"))}},[t]),gt=o.useCallback(async()=>{if(r?.connectUrl)try{await navigator.clipboard.writeText(r.connectUrl),h(!0),R.success(t("settings.openchamber.tunnel.toast.connectLinkCopied")),setTimeout(()=>h(!1),2e3)}catch{R.error(t("settings.openchamber.tunnel.toast.copyUrlFailed"))}},[t,r?.connectUrl]),Ct=o.useCallback(async J=>{const xe=Ua.find(Re=>Re.value===J);xe&&(ce(xe.ms),await B(xe.ms,ge))},[B,ge]),ie=o.useCallback(async J=>{const xe=Va.find(Re=>Re.value===J);!xe||xe.ms===null||(Ee(xe.ms),await B(ke,xe.ms))},[ke,B]),Ae=o.useCallback(async J=>{k(null),p(null),n!=="active"&&n!=="stopping"&&n!=="starting"&&i("idle"),await Ze({tunnelMode:J,managedRemoteTunnelPresets:w})},[w,Ze,n]),Be=o.useCallback(async(J,xe)=>{try{await yt({managedRemoteTunnelPresets:xe})}catch{R.error(t("settings.openchamber.tunnel.toast.saveSelectedManagedRemoteFailed"))}},[t]),qe=o.useCallback(J=>{const xe=w.find(Re=>Re.id===J);xe&&(P(xe.id),k(null),Be(xe,w))},[w,Be]),Nt=o.useCallback(async()=>{const J=V.trim(),xe=Ga(te),Re=le.trim();if(!J){R.error(t("settings.openchamber.tunnel.toast.tunnelNameRequired"));return}if(!xe){R.error(t("settings.openchamber.tunnel.toast.managedRemoteHostnameRequired"));return}if(!Re){R.error(t("settings.openchamber.tunnel.toast.managedRemoteTokenRequired"));return}if(w.some(lt=>lt.hostname===xe)){R.error(t("settings.openchamber.tunnel.toast.hostnameAlreadyExists"));return}const we={id:Jg(),name:J,hostname:xe},rt=[...w,we];G(rt),P(we.id),X(lt=>({...lt,[we.id]:!0})),se(lt=>({...lt,[we.id]:Re})),k(null),A(!1),W(""),ae(""),be(""),await Ze({tunnelMode:"managed-remote",managedRemoteTunnelPresets:rt,managedRemoteTunnelPresetTokens:{...ee,[we.id]:Re}}),await Ue({presetId:we.id,presetName:we.name,hostname:we.hostname,token:Re}),R.success(t("settings.openchamber.tunnel.toast.managedRemoteSaved"))},[w,te,V,le,Ue,Ze,ee,t]),xt=o.useCallback(async J=>{const xe=w.find(it=>it.id===J);if(!xe)return;const Re=w.filter(it=>it.id!==xe.id),we=Re[0]?.id||"",rt=Z===xe.id?we:Z,lt=Object.fromEntries(Object.entries(ee).filter(([it,It])=>it!==xe.id&&It.trim().length>0));G(Re),P(rt),X(it=>{const It={...it};return delete It[xe.id],It}),se(it=>{const It={...it};return delete It[xe.id],It}),O(it=>{const It=new Set(it);return It.delete(xe.id),It}),k(null),await Ze({managedRemoteTunnelPresets:Re,managedRemoteTunnelPresetTokens:lt}),R.success(t("settings.openchamber.tunnel.toast.managedRemoteRemoved"))},[w,Ze,Z,ee,t]),zt="gap-2 border-[var(--primary-base)] bg-[var(--primary-base)] text-[var(--primary-foreground)] hover:bg-[var(--primary-hover)] hover:text-[var(--primary-foreground)]";return n==="checking"?s.jsx("div",{className:"flex items-center justify-center py-12",children:s.jsx("span",{className:"h-1.5 w-1.5 rounded-full bg-current animate-busy-pulse","aria-label":t("settings.openchamber.tunnel.state.loading")})}):s.jsx(Oe,{title:t("settings.openchamber.tunnel.title"),info:s.jsxs("div",{className:"space-y-1",children:[s.jsx("p",{children:t("settings.openchamber.tunnel.description")}),s.jsx("p",{children:t("settings.openchamber.tunnel.note.serverSideEnforced")}),s.jsx("p",{children:t("settings.openchamber.tunnel.note.connectLinksOneTime")})]}),divider:!1,children:s.jsxs("div",{className:"space-y-6",children:[Pe.length>0&&s.jsx("section",{className:"space-y-2 px-2 pb-2 pt-0",children:s.jsxs("div",{className:"rounded-lg border border-[var(--status-info-border)] bg-[var(--status-info-background)]/30 p-3",children:[s.jsxs("div",{className:"mb-2 flex items-center gap-2",children:[s.jsx(_,{name:"information",className:"size-4 text-[var(--status-info)]"}),s.jsx("p",{className:ur,children:t("settings.openchamber.tunnel.section.redeemedAccessLinks")})]}),s.jsx("div",{className:"space-y-1",children:Pe.map(J=>{const xe=J.mode==="quick",Re=J.mode==="managed-remote",we=xe?"border-[var(--status-warning-border)] bg-[var(--status-warning-background)] text-[var(--status-warning)]":Re?"border-[var(--status-info-border)] bg-[var(--status-info-background)] text-[var(--status-info)]":"border-[var(--status-success-border)] bg-[var(--status-success-background)] text-[var(--status-success)]",rt=J.isActive?xe?"text-[var(--status-warning)]":Re?"text-[var(--status-info)]":"text-[var(--status-success)]":"text-muted-foreground/50",lt=t(xe?"settings.openchamber.tunnel.badge.quick":Re?"settings.openchamber.tunnel.badge.remote":"settings.openchamber.tunnel.badge.local");return s.jsxs("div",{className:"flex flex-wrap items-center gap-x-2 gap-y-1 rounded border border-[var(--surface-subtle)] bg-[var(--surface-elevated)] px-2 py-1.5",children:[s.jsx(_,{name:"checkbox-blank-circle-fill",className:je("size-2.5 shrink-0",rt)}),s.jsx("span",{className:je("typography-micro rounded border px-1.5 py-0.5 uppercase",we),children:lt}),s.jsx("span",{className:"typography-meta text-muted-foreground/80",children:t("settings.openchamber.tunnel.session.redeemedAt",{time:qg(J.createdAt,e)})}),s.jsx("span",{className:"typography-meta text-foreground",children:J.isActive?t("settings.openchamber.tunnel.session.expiresIn",{remaining:J.remainingTextForSession}):J.inactiveLabel===t("settings.openchamber.tunnel.state.inactive")?t("settings.openchamber.tunnel.state.inactive"):t("settings.openchamber.tunnel.session.inactiveWithReason",{reason:J.inactiveLabel})})]},J.sessionId)})})]})}),n==="not-available"&&s.jsx("section",{className:"space-y-2 px-2 pb-2 pt-0",children:s.jsxs("div",{className:"flex items-start gap-2 rounded-lg border border-[var(--status-warning)]/30 bg-[var(--status-warning)]/5 p-3",children:[s.jsx(_,{name:"error-warning",className:"mt-0.5 size-4 shrink-0 text-[var(--status-warning)]"}),s.jsxs("div",{className:"space-y-1",children:[s.jsx("p",{className:ur,children:t("settings.openchamber.tunnel.notAvailable.dependencyNotFound",{dependency:oe.dependency})}),s.jsx("p",{className:"typography-meta text-muted-foreground/70",children:t("settings.openchamber.tunnel.notAvailable.installHint")}),s.jsx("code",{className:"typography-code block rounded bg-muted/50 px-2 py-1 text-xs text-foreground",children:oe.installCommand})]})]})}),s.jsxs("section",{className:"space-y-4 px-2 pb-2 pt-0",children:[s.jsxs("div",{className:"space-y-3",children:[s.jsxs("div",{"data-settings-item":"tunnel.provider",className:"space-y-1.5",children:[s.jsx("p",{className:Et,children:t("settings.openchamber.tunnel.field.provider")}),s.jsxs(Dt,{value:M,onValueChange:J=>{Qe(J)},disabled:E||n==="starting"||n==="stopping",children:[s.jsx(Mt,{size:Kt,className:"max-w-[16rem]",children:s.jsx(_t,{placeholder:t("settings.openchamber.tunnel.field.providerPlaceholder"),children:hl(M)})}),s.jsxs(Rt,{children:[F.length>0?F.map(J=>s.jsx(dt,{value:J.provider,children:s.jsx(wo,{provider:J.provider})},J.provider)):s.jsx(dt,{value:"cloudflare",children:s.jsx(wo,{provider:"cloudflare"})}),s.jsx(dt,{value:"__more-soon",disabled:!0,children:t("settings.openchamber.tunnel.option.moreProvidersSoon")})]})]})]}),s.jsxs("div",{"data-settings-item":"tunnel.type",className:"space-y-1.5",children:[s.jsx("p",{className:Et,children:t("settings.openchamber.tunnel.field.tunnelType")}),s.jsx("div",{className:"flex flex-wrap items-center gap-1",children:ye.map(J=>s.jsxs(Ji,{children:[s.jsx(Qi,{asChild:!0,children:s.jsx(H,{variant:"chip",size:"xs","aria-pressed":T===J.value,className:"!font-normal",onClick:()=>{Ae(J.value)},disabled:E||n==="starting"||n==="stopping",children:a(J.labelKey)})}),s.jsx(Do,{sideOffset:8,className:"max-w-xs",children:a(J.tooltipKey)})]},J.value))})]})]}),s.jsxs("div",{"data-settings-item":"tunnel.ttl",className:"mt-2 grid grid-cols-1 gap-2 py-1.5 md:grid-cols-[14rem_auto] md:gap-x-8 md:gap-y-2",children:[s.jsxs("div",{className:"flex min-w-0 items-center gap-2",children:[s.jsx("span",{className:je(Et,"shrink-0"),children:t("settings.openchamber.tunnel.field.connectLinkTtl")}),s.jsxs(Dt,{value:Gi(Ua,ke,"1800000"),onValueChange:J=>{Ct(J)},disabled:C||E||n==="starting"||n==="stopping",children:[s.jsx(Mt,{size:Kt,className:"max-w-[11rem] min-w-0",children:s.jsx(_t,{className:"truncate",children:No(Ua,ke,"1800000")})}),s.jsx(Rt,{children:Ua.map(J=>s.jsx(dt,{value:J.value,children:J.label},J.value))})]})]}),s.jsxs("div",{className:"flex min-w-0 items-center gap-2",children:[s.jsx("span",{className:je(Et,"shrink-0"),children:t("settings.openchamber.tunnel.field.tunnelSessionTtl")}),s.jsxs(Dt,{value:Gi(Va,ge,"28800000"),onValueChange:J=>{ie(J)},disabled:C||E||n==="starting"||n==="stopping",children:[s.jsx(Mt,{size:Kt,className:"max-w-[11rem] min-w-0",children:s.jsx(_t,{className:"truncate",children:No(Va,ge,"28800000")})}),s.jsx(Rt,{children:Va.map(J=>s.jsx(dt,{value:J.value,children:J.label},J.value))})]})]})]}),T==="quick"&&s.jsx("div",{className:"rounded-lg border border-[var(--status-warning)]/35 bg-[var(--status-warning)]/10 p-3",children:s.jsxs("div",{className:"flex items-start gap-2",children:[s.jsx(_,{name:"error-warning",className:"mt-0.5 size-4 shrink-0 text-[var(--status-warning)]"}),s.jsxs("div",{children:[s.jsx("p",{className:"typography-meta text-[var(--status-warning)]",children:t("settings.openchamber.tunnel.option.mode.quick.tooltip")}),z&&s.jsx("p",{className:"typography-meta mt-1 text-[var(--status-warning)]",children:t("settings.openchamber.tunnel.warning.quickModeReliability")})]})]})}),T==="managed-remote"&&s.jsxs("div",{"data-settings-item":"tunnel.managed-remote",className:"space-y-2 rounded-lg border border-[var(--interactive-border)] bg-[var(--surface-elevated)] p-3",children:[typeof $e=="number"&&s.jsx("div",{className:"rounded-md border border-[var(--status-info-border)] bg-[var(--status-info-background)]/35 px-2 py-1.5",children:s.jsxs("p",{className:"typography-meta text-[var(--status-info)]",children:[t("settings.openchamber.tunnel.note.cloudflareConnectorTarget")," ",s.jsxs("code",{children:["http://localhost:",$e]})]})}),s.jsxs("div",{className:"mb-1 flex items-center justify-between gap-3",children:[s.jsx(Vs,{children:t("settings.openchamber.tunnel.section.savedManagedRemoteTunnels")}),s.jsxs(H,{variant:"ghost",size:"xs",className:"!font-normal",onClick:()=>A(J=>!J),disabled:n==="starting"||n==="stopping"||E,children:[s.jsx(_,{name:"add",className:"h-3.5 w-3.5"}),t("settings.common.actions.create")]})]}),w.length>0?s.jsx("div",{className:"overflow-hidden rounded-md border border-[var(--surface-subtle)]",children:w.map((J,xe)=>{const Re=ee[J.id]||"",we=D.has(J.id),rt=Q[J.id]??!1;return s.jsx("div",{className:je(xe<w.length-1&&"border-b border-[var(--surface-subtle)]"),children:s.jsxs(ba,{open:rt,onOpenChange:lt=>{X(it=>({...it,[J.id]:lt})),lt&&qe(J.id)},className:"py-1.5",children:[s.jsxs("div",{className:"flex items-start gap-2 px-3",children:[s.jsxs(va,{type:"button",className:"group flex-1 justify-start gap-2 rounded-md px-0 py-1 pr-1 text-left hover:bg-[var(--interactive-hover)]",disabled:n==="starting"||n==="stopping"||E,children:[rt?s.jsx(_,{name:"arrow-down-s",className:"h-4 w-4 text-muted-foreground"}):s.jsx(_,{name:"arrow-right-s",className:"h-4 w-4 text-muted-foreground"}),s.jsx("span",{className:"typography-ui-label min-w-0 flex-1 truncate text-foreground",children:J.name})]}),s.jsx(H,{variant:"ghost",size:"xs",className:"h-7 w-7 p-0 text-muted-foreground hover:text-[var(--status-error)]","aria-label":t("settings.openchamber.tunnel.actions.removePresetAria",{name:J.name}),onClick:()=>{xt(J.id)},disabled:n==="starting"||n==="stopping"||E,children:s.jsx(_,{name:"delete-bin",className:"h-3.5 w-3.5"})})]}),s.jsx(ya,{className:"pt-1.5",children:s.jsxs("div",{className:"space-y-1 px-3 pb-2",children:[s.jsxs("p",{className:"typography-meta text-muted-foreground/70",children:[t("settings.openchamber.tunnel.field.hostnameLabel")," ",s.jsx("code",{children:J.hostname})]}),s.jsx(He,{type:"password",value:Re,onChange:lt=>{const it=lt.target.value;k(null),se(It=>({...It,[J.id]:it}))},onBlur:lt=>{const it=lt.currentTarget.value.trim();it&&Ue({presetId:J.id,presetName:J.name,hostname:J.hostname,token:it})},placeholder:t(we?"settings.openchamber.tunnel.field.savedTokenAvailablePlaceholder":"settings.openchamber.tunnel.field.pasteTokenPlaceholder"),className:"h-7",disabled:n==="starting"||n==="stopping"}),s.jsx("div",{className:"flex items-center justify-end",children:s.jsx(H,{variant:"ghost",size:"xs",className:"!font-normal",disabled:n==="starting"||n==="stopping"||Re.trim().length===0,onClick:()=>{Ue({presetId:J.id,presetName:J.name,hostname:J.hostname,token:Re})},children:t("settings.openchamber.tunnel.actions.saveToken")})})]})})]})},J.id)})}):s.jsx("p",{className:"typography-meta text-muted-foreground/70",children:t("settings.openchamber.tunnel.empty.noManagedRemoteTunnels")}),U&&s.jsxs("div",{className:"space-y-2 rounded-md border border-[var(--surface-subtle)] p-2",children:[s.jsx(He,{value:V,onChange:J=>W(J.target.value),placeholder:t("settings.openchamber.tunnel.field.newPresetNamePlaceholder"),className:"h-7",disabled:E||n==="starting"||n==="stopping"}),s.jsx(He,{value:te,onChange:J=>ae(J.target.value),placeholder:t("settings.openchamber.tunnel.field.newPresetHostnamePlaceholder"),className:"h-7",disabled:E||n==="starting"||n==="stopping"}),s.jsx(He,{type:"password",value:le,onChange:J=>be(J.target.value),placeholder:t("settings.openchamber.tunnel.field.newPresetTokenPlaceholder"),className:"h-7",disabled:E||n==="starting"||n==="stopping"}),typeof $e=="number"&&s.jsxs("p",{className:"typography-meta text-muted-foreground/70",children:[t("settings.openchamber.tunnel.note.cloudflareConnectorTargetUse")," ",s.jsxs("code",{children:["http://localhost:",$e]}),"."]}),s.jsxs("div",{className:"flex items-center gap-2",children:[s.jsx(H,{variant:"ghost",size:"xs",className:"!font-normal",onClick:()=>{Nt()},disabled:E||n==="starting"||n==="stopping",children:t("settings.common.actions.saveChanges")}),s.jsx(H,{variant:"ghost",size:"xs",className:"!font-normal",onClick:()=>{A(!1),W(""),ae(""),be("")},disabled:E||n==="starting"||n==="stopping",children:t("settings.common.actions.cancel")})]})]}),s.jsxs("div",{className:"flex items-center gap-1.5",children:[s.jsx("p",{className:"typography-meta text-muted-foreground/80",children:t("settings.openchamber.tunnel.note.tokensSavedPerTunnel")}),s.jsx(Yt,{children:t("settings.openchamber.tunnel.tooltip.tokensSavedPath")})]}),!Le&&L&&s.jsx("p",{className:"typography-meta text-[var(--status-error)]",children:L})]}),T==="managed-local"&&s.jsx("div",{"data-settings-item":"tunnel.managed-local-config",className:"space-y-2 rounded-lg border border-[var(--interactive-border)] bg-[var(--surface-elevated)] p-3",children:s.jsxs("div",{className:"space-y-1.5",children:[s.jsx("p",{className:Et,children:t("settings.openchamber.tunnel.field.configurationFile")}),s.jsx("input",{ref:Je,type:"file",accept:".yml,.yaml,.json",className:"hidden",onChange:J=>{pt(J)}}),s.jsxs("div",{className:"flex items-center gap-2",children:[s.jsx(He,{value:K||"",onChange:J=>{tt(J.target.value)},onBlur:()=>{wt()},placeholder:t("settings.openchamber.tunnel.field.configurationFilePlaceholder"),className:"h-7",disabled:n==="starting"||n==="stopping"||E}),s.jsx(H,{variant:"outline",size:"xs",className:"h-7 w-7 p-0","aria-label":t("settings.openchamber.tunnel.actions.browseConfigFileAria"),onClick:()=>{et()},disabled:n==="starting"||n==="stopping"||E,children:s.jsx(_,{name:"folder",className:"size-3.5"})}),K&&s.jsx(H,{variant:"ghost",size:"xs",className:"h-7 w-7 p-0","aria-label":t("settings.openchamber.tunnel.actions.clearConfigFileAria"),onClick:()=>{mt()},disabled:n==="starting"||n==="stopping"||E,children:s.jsx(_,{name:"close",className:"size-3.5"})})]}),s.jsx("p",{className:"typography-meta text-muted-foreground/70",children:t(K?"settings.openchamber.tunnel.note.customConfigUsed":"settings.openchamber.tunnel.note.defaultConfigUsed")}),_e&&s.jsx("p",{className:"typography-meta text-[var(--status-error)]",children:ze})]})}),!Ge&&s.jsxs("div",{"data-settings-item":"tunnel.start",className:"space-y-6",children:[s.jsx("div",{className:"rounded-lg border border-[var(--status-info-border)] bg-[var(--status-info-background)] p-3",children:s.jsxs("div",{className:"flex items-start gap-2",children:[s.jsx(_,{name:"information",className:"mt-0.5 size-4 shrink-0 text-[var(--status-info)]"}),s.jsxs("div",{className:"space-y-1",children:[T==="managed-remote"&&s.jsxs(s.Fragment,{children:[s.jsx("p",{className:"typography-meta text-[var(--status-info)]",children:t("settings.openchamber.tunnel.note.managedRemoteRequiresDomain")}),s.jsxs("button",{type:"button",className:"typography-meta inline-flex items-center gap-1 text-[var(--status-info)] underline underline-offset-2 hover:opacity-90",onClick:()=>{me(Ug)},children:[t("settings.openchamber.tunnel.actions.openManagedRemoteDocs"),s.jsx(_,{name:"external-link",className:"size-3.5"})]})]}),T==="managed-local"&&s.jsxs(s.Fragment,{children:[s.jsx("p",{className:"typography-meta text-[var(--status-info)]",children:t("settings.openchamber.tunnel.note.managedLocalUsesConfig")}),s.jsxs("button",{type:"button",className:"typography-meta inline-flex items-center gap-1 text-[var(--status-info)] underline underline-offset-2 hover:opacity-90",onClick:()=>{me(Vg)},children:[t("settings.openchamber.tunnel.actions.openManagedLocalDocs"),s.jsx(_,{name:"external-link",className:"size-3.5"})]})]}),s.jsx("p",{className:"typography-meta text-[var(--status-info)]",children:t("settings.openchamber.tunnel.note.startModeAndGenerateLink",{mode:a(Di.find(J=>J.value===T)?.labelKey??"settings.openchamber.tunnel.option.mode.quick.label")})})]})]})}),T==="managed-remote"&&s.jsxs("div",{className:"space-y-1.5",children:[s.jsx("p",{className:Et,children:t("settings.openchamber.tunnel.field.managedRemoteTunnelToConnect")}),s.jsxs(Dt,{value:Z||(w[0]?.id??""),onValueChange:J=>{qe(J)},disabled:E||n==="starting"||n==="stopping"||w.length<=1,children:[s.jsx(Mt,{size:Kt,children:s.jsx(_t,{placeholder:t("settings.openchamber.tunnel.field.selectSavedTunnelPlaceholder"),children:Le?.name})}),s.jsx(Rt,{fitContent:!0,children:w.map(J=>s.jsx(dt,{value:J.id,children:J.name},J.id))})]})]}),Me&&s.jsx("div",{className:"rounded-lg border border-[var(--status-warning-border)] bg-[var(--status-warning-background)] p-3",children:s.jsxs("div",{className:"flex items-start gap-2",children:[s.jsx(_,{name:"error-warning",className:"mt-0.5 size-4 shrink-0 text-[var(--status-warning)]"}),s.jsx("p",{className:"typography-meta text-[var(--status-warning)]",children:t("settings.openchamber.tunnel.warning.replacesActiveTunnel")})]})}),s.jsx(H,{size:"sm",variant:"outline",onClick:at,disabled:n==="starting"||E||T==="managed-remote"&&!Le||T==="managed-local"&&_e,className:je(zt,n==="starting"&&"opacity-70"),children:n==="starting"?s.jsxs(s.Fragment,{children:[s.jsx(_,{name:"loader-4",className:"size-3.5 animate-spin"})," ",t("settings.openchamber.tunnel.actions.startingTunnel")]}):t("settings.openchamber.tunnel.actions.startTunnel")})]})]}),Ge&&r&&s.jsxs("section",{"data-settings-item":"tunnel.start",className:"space-y-4 px-2 pb-2 pt-0",children:[s.jsxs("div",{className:"space-y-3",children:[s.jsxs("div",{className:"flex items-center gap-2",children:[s.jsx("div",{className:"size-2 shrink-0 rounded-full bg-[var(--status-success)]"}),s.jsx("p",{className:"typography-meta font-medium text-foreground",children:t("settings.openchamber.tunnel.state.tunnelReady")})]}),s.jsxs("div",{children:[s.jsx("p",{className:"typography-meta mb-1 text-muted-foreground/70",children:t("settings.openchamber.tunnel.field.publicUrlHint")}),s.jsx("code",{className:"typography-code block truncate rounded bg-muted/50 px-2 py-1 text-xs text-foreground",children:r.url})]}),Ye&&r.connectUrl&&s.jsxs(s.Fragment,{children:[s.jsxs("div",{children:[s.jsx("p",{className:"typography-meta mb-1 text-muted-foreground/70",children:t("settings.openchamber.tunnel.field.connectLink")}),s.jsxs("div",{className:"flex items-center gap-2",children:[s.jsx("code",{className:"typography-code flex-1 truncate rounded bg-muted/50 px-2 py-1 text-xs text-foreground",children:r.connectUrl}),s.jsxs(H,{size:"sm",variant:"ghost",onClick:gt,className:"shrink-0 gap-1.5",children:[N?s.jsx(_,{name:"check",className:"size-3.5 text-[var(--status-success)]"}):s.jsx(_,{name:"file-copy",className:"size-3.5"}),t(N?"settings.openchamber.tunnel.actions.copied":"settings.common.actions.copyAll")]})]}),s.jsxs("p",{className:"typography-meta mt-1 text-muted-foreground/70",children:[t("settings.openchamber.tunnel.field.expires"),": ",r.bootstrapExpiresAt?Se:t("settings.openchamber.tunnel.state.never")]})]}),s.jsxs("div",{className:"flex flex-col items-center gap-2 rounded-lg border border-border/50 bg-[var(--surface-elevated)] p-4",children:[y?s.jsx("img",{src:y,alt:t("settings.openchamber.tunnel.field.connectQrAlt"),className:"size-48"}):s.jsx("div",{className:"size-48 rounded bg-muted/30"}),s.jsx("p",{className:"typography-meta text-muted-foreground",children:t("settings.openchamber.tunnel.note.scanQrToConnect")})]})]})]}),s.jsx("div",{className:"pt-1",children:s.jsxs("div",{className:"flex flex-wrap items-center gap-2",children:[s.jsxs(H,{size:"sm",variant:"outline",onClick:at,disabled:n==="stopping"||E||T==="managed-local"&&_e,className:zt,children:[s.jsx(_,{name:"restart",className:"size-3.5"}),t("settings.openchamber.tunnel.actions.newConnectLink")]}),s.jsx(H,{size:"sm",variant:"ghost",onClick:ft,disabled:n==="stopping"||E,className:"gap-2 text-[var(--status-error)]",children:n==="stopping"?s.jsxs(s.Fragment,{children:[s.jsx(_,{name:"loader-4",className:"size-3.5 animate-spin"})," ",t("settings.openchamber.tunnel.actions.stopping")]}):t("settings.openchamber.tunnel.actions.stopTunnel")})]})})]}),n==="error"&&b&&s.jsxs("section",{className:"space-y-3 px-2 pb-2 pt-0",children:[s.jsx("p",{className:"typography-meta text-[var(--status-error)]",children:b}),s.jsx(H,{size:"sm",variant:"ghost",onClick:at,children:t("settings.openchamber.tunnel.actions.retry")})]})]})})},fl=()=>{const{t}=ot(),[e,a]=We.useState(""),[n,i]=We.useState(!0),[r,l]=We.useState(!1),x=de(p=>p.showOpenCodeUpdateNotifications),c=de(p=>p.setShowOpenCodeUpdateNotifications);We.useEffect(()=>{let p=!1;return(async()=>{try{const L=await ct("/api/config/settings",{method:"GET",headers:{Accept:"application/json"}});if(!L.ok)return;const k=await L.json().catch(()=>null);if(p||!k)return;const N=typeof k.opencodeBinary=="string"?k.opencodeBinary.trim():"";a(N)}catch{}finally{p||i(!1)}})(),()=>{p=!0}},[]);const y=We.useCallback(async()=>{if(!(typeof window>"u")&&is())try{const p=await Uo();p.success&&p.path&&p.path.trim().length>0&&a(p.path.trim())}catch{}},[]),m=We.useCallback(async()=>{l(!0);try{const p=e.trim(),L=p.length>=2&&(p.startsWith('"')&&p.endsWith('"')||p.startsWith("'")&&p.endsWith("'"))?p.slice(1,-1).trim():p;await yt({opencodeBinary:L}),qn("cli",{id:"opencode-binary"}),R.success(t("settings.view.pendingRestart.saved"))}finally{l(!1)}},[t,e]),b=We.useCallback(p=>{c(p),yt({showOpenCodeUpdateNotifications:p})},[c]);return s.jsx(Oe,{title:t("settings.openchamber.opencodeCli.title"),children:s.jsxs("div",{className:"space-y-0.5",children:[s.jsxs($t,{settingsItem:"sessions.opencode-binary",label:t("settings.openchamber.opencodeCli.field.binaryPath"),info:s.jsxs(s.Fragment,{children:[t("settings.openchamber.opencodeCli.tipPrefix")," ",s.jsx("span",{className:"font-mono",children:"OPENCODE_BINARY"})," ",t("settings.openchamber.opencodeCli.tipMiddle")," ",s.jsx("span",{className:"font-mono",children:"~/.config/openchamber/settings.json"}),"."]}),alignEnd:!1,controlClassName:"@xl:w-[20rem]",children:[s.jsx(He,{value:e,onChange:p=>a(p.target.value),placeholder:t("settings.openchamber.opencodeCli.field.binaryPathPlaceholder"),disabled:n||r,className:"h-8 min-w-0 flex-1 font-mono text-xs"}),s.jsx(H,{type:"button",variant:"outline",size:"xs",onClick:y,disabled:n||r||!is(),className:gs,"aria-label":t("settings.openchamber.opencodeCli.actions.browseAria"),title:t("settings.openchamber.opencodeCli.actions.browse"),children:s.jsx(_,{name:"folder",className:"h-4 w-4"})})]}),s.jsxs(Wn,{className:bs,children:[!Vo()&&s.jsx(ut,{settingsItem:"sessions.opencode-update-notifications",checked:x,onChange:b,label:t("settings.openchamber.opencodeCli.field.showUpdateNotifications"),ariaLabel:t("settings.openchamber.opencodeCli.field.showUpdateNotificationsAria")}),s.jsx("div",{className:"flex justify-start py-1.5",children:s.jsx(H,{type:"button",size:"xs",onClick:m,disabled:n||r,className:"shrink-0 !font-normal",children:t(r?"settings.common.actions.saving":"settings.common.actions.saveChanges")})})]})]})})},xl=()=>{const t=ht.c(36),{t:e}=ot(),a=de(Yg),n=de(Zg),i=de(Xg),r=de(eh);let l;t[0]!==n?(l=M=>{n(M),yt({agentControlToolEnabled:M}),qn("cli",{id:"agent-control-tool"})},t[0]=n,t[1]=l):l=t[1];const x=l;let c;t[2]!==r?(c=M=>{r(M),yt({agentWebToolEnabled:M}),qn("cli",{id:"agent-web-tool"})},t[2]=r,t[3]=c):c=t[3];const y=c;let m;t[4]!==e?(m=e("settings.openchamber.tools.title"),t[4]=e,t[5]=m):m=t[5];let b;t[6]!==e?(b=e("settings.openchamber.tools.field.agentControlTool"),t[6]=e,t[7]=b):b=t[7];let p;t[8]!==e?(p=e("settings.openchamber.tools.field.agentControlToolAria"),t[8]=e,t[9]=p):p=t[9];let L;t[10]!==e?(L=e("settings.openchamber.tools.field.agentControlToolInfo"),t[10]=e,t[11]=L):L=t[11];let k;t[12]!==a||t[13]!==x||t[14]!==b||t[15]!==p||t[16]!==L?(k=s.jsx(ut,{settingsItem:"sessions.agent-control-tool",checked:a,onChange:x,label:b,ariaLabel:p,info:L}),t[12]=a,t[13]=x,t[14]=b,t[15]=p,t[16]=L,t[17]=k):k=t[17];let N;t[18]!==e?(N=e("settings.openchamber.tools.field.agentWebTool"),t[18]=e,t[19]=N):N=t[19];let h;t[20]!==e?(h=e("settings.openchamber.tools.field.agentWebToolAria"),t[20]=e,t[21]=h):h=t[21];let C;t[22]!==e?(C=e("settings.openchamber.tools.field.agentWebToolInfo"),t[22]=e,t[23]=C):C=t[23];let u;t[24]!==i||t[25]!==y||t[26]!==N||t[27]!==h||t[28]!==C?(u=s.jsx(ut,{settingsItem:"sessions.agent-web-tool",checked:i,onChange:y,label:N,ariaLabel:h,info:C}),t[24]=i,t[25]=y,t[26]=N,t[27]=h,t[28]=C,t[29]=u):u=t[29];let E;t[30]!==u||t[31]!==k?(E=s.jsxs("div",{className:bs,children:[k,u]}),t[30]=u,t[31]=k,t[32]=E):E=t[32];let q;return t[33]!==E||t[34]!==m?(q=s.jsx(Oe,{title:m,children:E}),t[33]=E,t[34]=m,t[35]=q):q=t[35],q};function Yg(t){return t.agentControlToolEnabled}function Zg(t){return t.setAgentControlToolEnabled}function Xg(t){return t.agentWebToolEnabled}function eh(t){return t.setAgentWebToolEnabled}const bl=()=>{const{t}=ot(),e=is()&&Na(),a=e&&typeof window<"u"&&window.__OPENCHAMBER_PLATFORM__==="darwin",[n,i]=We.useState(!1),[r,l]=We.useState(!1),[x,c]=We.useState(""),[y,m]=We.useState(""),[b,p]=We.useState(!1),[L,k]=We.useState(!1),[N,h]=We.useState(null),[C,u]=We.useState(!0),[E,q]=We.useState(!1),[M,I]=We.useState(!1),[g,j]=We.useState(!1),[F,S]=We.useState(!1),[T,v]=We.useState(!1),[K,$]=We.useState(!1),[w,G]=We.useState(!1),[Q,X]=We.useState(!0),[Z,P]=We.useState(!0),[ee,se]=We.useState(!1),[D,O]=We.useState(!1),[U,A]=We.useState(!1),[V,W]=We.useState(null),[te,ae]=We.useState(null);We.useEffect(()=>{if(!e){u(!1);return}let he=!1;return(async()=>{try{const pe=await ct("/api/config/settings",{method:"GET",headers:{Accept:"application/json"}});if(!pe.ok)throw new Error(t("settings.openchamber.desktopNetwork.error.loadFailed"));const Ie=await pe.json().catch(()=>null);if(he)return;const ze=Ie?.desktopLanAccessEnabled===!0,Je=typeof Ie?.desktopUiPassword=="string"?Ie.desktopUiPassword:"";i(ze),l(ze),c(Je),m(Je),k(Ie?.desktopLanAccessActive===!0),h(typeof Ie?.desktopLanAccessBlockedReason=="string"?Ie.desktopLanAccessBlockedReason:null);const _e=Ie?.desktopMacMenuBarEnabled!==!1;X(_e),P(_e),W(null)}catch(pe){he||W(pe instanceof Error?pe.message:t("settings.openchamber.desktopNetwork.error.loadFailed"))}finally{he||u(!1)}})(),()=>{he=!0}},[e,t]),We.useEffect(()=>{if(!e){I(!1);return}let he=!1;return(async()=>{const pe=await $c();he||(I(pe?.supported===!0),j(pe?.enabled===!0))})(),()=>{he=!0}},[e]),We.useEffect(()=>{if(!e){v(!1);return}let he=!1;return(async()=>{const pe=await Bc();he||(v(pe?.supported===!0),$(pe?.enabled===!0))})(),()=>{he=!0}},[e]),We.useEffect(()=>{if(!e){se(!1);return}let he=!1;return(async()=>{const pe=await Hc();he||(se(pe?.supported===!0),O(pe?.enabled===!0))})(),()=>{he=!0}},[e]),We.useEffect(()=>{if(!e||!r){ae(null);return}let he=!1;return(async()=>{const pe=await _o();he||ae(pe)})(),()=>{he=!0}},[r,e]);const le=r!==n||y!==x||Z!==Q,be=We.useMemo(()=>{if(typeof window>"u")return null;const pe=wa()||window.location.href;let Ie=0;try{Ie=Number(new URL(pe).port)}catch{Ie=Number(window.location.port)}return Number.isFinite(Ie)&&Ie>0?Ie:null},[]),ke=r&&L&&te&&be?`http://${te}:${be}`:null,ce=r&&!y.trim(),ge=n&&!L&&N==="missing-password",Ee=C||E||!le||ce,Se=We.useCallback(he=>{m(he),he.trim()||l(!1)},[]),Ne=We.useCallback(async()=>{if(!M||F)return;const he=!g;j(he),S(!0),W(null);try{const pe=await Gc(he);if(!pe?.supported)throw new Error(t("settings.openchamber.desktopNetwork.error.launchAtLoginUnsupported"));j(pe.enabled)}catch(pe){j(!he),W(pe instanceof Error?pe.message:t("settings.openchamber.desktopNetwork.error.launchAtLoginSaveFailed"))}finally{S(!1)}},[F,g,M,t]),fe=We.useCallback(async()=>{if(!T||w)return;const he=!K;$(he),G(!0),W(null);try{const pe=await qc(he);if(!pe)throw new Error(t("settings.openchamber.desktopNetwork.error.minimizeToTraySaveFailed"));if(!pe.supported)throw new Error(t("settings.openchamber.desktopNetwork.error.minimizeToTrayUnsupported"));$(pe.enabled)}catch(pe){$(!he),W(pe instanceof Error?pe.message:t("settings.openchamber.desktopNetwork.error.minimizeToTraySaveFailed"))}finally{G(!1)}},[w,K,T,t]),Ke=We.useCallback(async()=>{if(!ee||U)return;const he=!D;O(he),A(!0),W(null);try{const pe=await Wc(he);if(!pe?.supported)throw new Error(t("settings.openchamber.desktopNetwork.error.keepAwakeUnsupported"));O(pe.enabled)}catch(pe){O(!he),W(pe instanceof Error?pe.message:t("settings.openchamber.desktopNetwork.error.keepAwakeSaveFailed"))}finally{A(!1)}},[U,D,ee,t]),De=We.useCallback(async()=>{if(le){q(!0),W(null);try{if(!(await ct("/api/config/settings",{method:"PUT",headers:{"Content-Type":"application/json",Accept:"application/json"},body:JSON.stringify({desktopLanAccessEnabled:r,desktopUiPassword:y,desktopMacMenuBarEnabled:Z})})).ok)throw new Error(t("settings.openchamber.desktopNetwork.error.saveFailed"));if(i(r),c(y),X(Z),!await Jc())throw new Error(t("settings.openchamber.desktopNetwork.error.savedRestartFailed"))}catch(he){W(he instanceof Error?he.message:t("settings.openchamber.desktopNetwork.error.saveFailed")),q(!1)}}},[Z,y,r,le,t]);return e?s.jsx(Oe,{title:t("settings.openchamber.desktopNetwork.title"),children:s.jsxs("div",{className:"space-y-3",children:[M||a||T||ee?s.jsxs("div",{className:bs,children:[M?s.jsx(ut,{settingsItem:"sessions.desktop-launch-at-login",checked:g,onChange:he=>{he!==g&&Ne()},disabled:F,label:t("settings.openchamber.desktopNetwork.field.launchAtLogin"),info:t("settings.openchamber.desktopNetwork.field.launchAtLoginDescription"),ariaLabel:t("settings.openchamber.desktopNetwork.field.launchAtLoginAria")}):null,a?s.jsx(ut,{settingsItem:"sessions.desktop-mac-menu-bar",checked:Z,onChange:P,disabled:C||E,label:t("settings.openchamber.desktopNetwork.field.macMenuBar"),info:t("settings.openchamber.desktopNetwork.field.macMenuBarDescription"),ariaLabel:t("settings.openchamber.desktopNetwork.field.macMenuBarAria")}):null,T?s.jsx(ut,{settingsItem:"sessions.desktop-minimize-to-tray",checked:K,onChange:he=>{he!==K&&fe()},disabled:w,label:t("settings.openchamber.desktopNetwork.field.minimizeToTray"),info:t("settings.openchamber.desktopNetwork.field.minimizeToTrayDescription"),ariaLabel:t("settings.openchamber.desktopNetwork.field.minimizeToTrayAria")}):null,ee?s.jsx(ut,{settingsItem:"sessions.desktop-keep-awake",checked:D,onChange:he=>{he!==D&&Ke()},disabled:U,label:t("settings.openchamber.desktopNetwork.field.keepAwake"),info:t("settings.openchamber.desktopNetwork.field.keepAwakeDescription"),ariaLabel:t("settings.openchamber.desktopNetwork.field.keepAwakeAria")}):null]}):null,s.jsxs(Qt,{settingsItem:"sessions.desktop-ui-password",label:s.jsx("label",{htmlFor:"desktop-ui-password",children:t("settings.openchamber.desktopPassword.field.password")}),info:t("settings.openchamber.desktopPassword.field.passwordDescription"),children:[s.jsx(He,{id:"desktop-ui-password",type:b?"text":"password",className:"h-8 min-w-0 flex-1",value:y,onChange:he=>Se(he.target.value),placeholder:t("settings.openchamber.desktopPassword.field.passwordPlaceholder"),disabled:C||E,required:r,"aria-invalid":ce}),s.jsx(H,{type:"button",variant:"ghost",size:"xs",onClick:()=>p(he=>!he),className:gs,"aria-label":t(b?"settings.openchamber.desktopPassword.actions.hidePassword":"settings.openchamber.desktopPassword.actions.showPassword"),"aria-pressed":b,children:s.jsx(_,{name:b?"eye-off":"eye",className:"h-4 w-4"})})]}),s.jsx("div",{className:bs,children:s.jsx(ut,{settingsItem:"sessions.desktop-lan-access",checked:r,onChange:l,disabled:C||E,label:t("settings.openchamber.desktopNetwork.field.allowLanAccess"),info:t("settings.openchamber.desktopNetwork.field.allowLanAccessDescription"),description:s.jsxs(s.Fragment,{children:[s.jsx("span",{className:"block text-[var(--status-warning)]/85",children:t("settings.openchamber.desktopNetwork.field.warning")}),ce||ge?s.jsx("span",{className:"block text-[var(--status-warning)]/85",children:t("settings.openchamber.desktopNetwork.field.passwordRequiredWarning")}):null]}),ariaLabel:t("settings.openchamber.desktopNetwork.field.allowLanAccessAria")})}),V?s.jsx("div",{className:"typography-micro text-[var(--status-error)]",children:V}):null,ke?s.jsxs("div",{className:"typography-micro text-muted-foreground/80",children:[t(le&&!n?"settings.openchamber.desktopNetwork.hint.openAfterRestart":"settings.openchamber.desktopNetwork.hint.openNow"),s.jsx("span",{className:"font-mono text-foreground",children:ke})]}):null,s.jsx("div",{className:"flex justify-start py-1.5",children:s.jsx(H,{type:"button",size:"xs",onClick:De,disabled:Ee,className:"shrink-0 !font-normal",children:t(E?"settings.common.actions.saving":"settings.openchamber.desktopNetwork.actions.saveAndRestart")})})]})}):null},vl=new Set(["shift","control","alt","meta"]),th=t=>{if(vl.has(t.key.toLowerCase()))return null;const e=[];(t.metaKey||t.ctrlKey)&&e.push("mod"),t.shiftKey&&e.push("shift"),t.altKey&&e.push("alt");const a=Lo(t.key);return a?(e.push(a),nn(e.join("+"))):null},sh=t=>{const e=[];if((t.metaKey||t.ctrlKey)&&e.push("mod"),t.shiftKey&&e.push("shift"),t.altKey&&e.push("alt"),vl.has(t.key.toLowerCase()))return e.length>0?nn(e.join("+")):null;const a=Lo(t.key);return a?(e.push(a),e.length>0?nn(e.join("+")):null):null},nh=()=>{const t=ht.c(54),{t:e}=ot();let a;t[0]!==e?(a=U=>e(U),t[0]=e,t[1]=a):a=t[1];const n=a,i=de(ah),r=de(ih),l=de(rh),x=de(oh);let c;if(t[2]===Symbol.for("react.memo_cache_sentinel")){e:{const U=fc();if(!ds()){c=U;break e}c=U.filter(lh)}t[2]=c}else c=t[2];const y=c;let m;t[3]!==n?(m=(U,A)=>{const V=`settings.openchamber.keyboardShortcuts.action.${U}.label`,W=n(V);return W===V?A:W},t[3]=n,t[4]=m):m=t[4];const b=m,[p,L]=o.useState(null);let k;t[5]===Symbol.for("react.memo_cache_sentinel")?(k={},t[5]=k):k=t[5];const[N,h]=o.useState(k),[C,u]=o.useState(""),[E,q]=o.useState(""),[M,I]=o.useState(null),g=ch;let j;t[6]!==i?(j=(U,A)=>{const V=nn(A);for(const W of y){if(W.id===U)continue;const te=gr(W.id,i);if(nn(te)===V)return W.id}return null},t[6]=i,t[7]=j):j=t[7];const F=j;let S;t[8]!==F||t[9]!==r||t[10]!==i||t[11]!==e?(S=(U,A)=>{const V=nn(A),W=F(U,V);if(W){I({actionId:U,combo:V,conflictActionId:W}),u("");return}const te={...i,[U]:V};r(U,V),g(te),I(null),u(""),q(fr(V)?e("settings.openchamber.keyboardShortcuts.warning.riskyBrowserShortcut"):""),h(ae=>{const le={...ae};return delete le[U],le})},t[8]=F,t[9]=r,t[10]=i,t[11]=e,t[12]=S):S=t[12];const T=S;let v;t[13]!==M||t[14]!==r||t[15]!==i||t[16]!==e?(v=()=>{if(!M)return;const U={...i,[M.conflictActionId]:xi,[M.actionId]:M.combo};r(M.conflictActionId,xi),r(M.actionId,M.combo),g(U),I(null),u(""),q(fr(M.combo)?e("settings.openchamber.keyboardShortcuts.warning.riskyBrowserShortcut"):""),h(A=>{const V={...A};return delete V[M.actionId],V})},t[13]=M,t[14]=r,t[15]=i,t[16]=e,t[17]=v):v=t[17];const K=v;let $;t[18]!==l||t[19]!==i?($=U=>{const A={...i};delete A[U],l(U),g(A),h(V=>{const W={...V};return delete W[U],W}),I(null),u(""),q("")},t[18]=l,t[19]=i,t[20]=$):$=t[20];const w=$;let G;t[21]!==e?(G=e("settings.openchamber.keyboardShortcuts.title"),t[21]=e,t[22]=G):G=t[22];let Q;t[23]!==e?(Q=e("settings.openchamber.keyboardShortcuts.tooltip"),t[23]=e,t[24]=Q):Q=t[24];let X;t[25]!==x?(X=()=>{x(),g({}),h({}),I(null),u(""),q("")},t[25]=x,t[26]=X):X=t[26];let Z;t[27]!==e?(Z=e("settings.openchamber.keyboardShortcuts.actions.resetAll"),t[27]=e,t[28]=Z):Z=t[28];let P;t[29]!==X||t[30]!==Z?(P=s.jsx(H,{type:"button",variant:"outline",size:"xs",className:"!font-normal",onClick:X,children:Z}),t[29]=X,t[30]=Z,t[31]=P):P=t[31];let ee;t[32]!==K||t[33]!==C||t[34]!==M||t[35]!==e||t[36]!==E?(ee=(C||E||M)&&s.jsxs("div",{className:"mb-2 space-y-2",children:[M&&s.jsxs("div",{className:"rounded-lg border border-[var(--status-warning-border)] bg-[var(--status-warning-background)] p-3 flex flex-col @xl:flex-row @xl:items-center justify-between gap-3",children:[s.jsx("span",{className:"typography-meta text-foreground",children:e("settings.openchamber.keyboardShortcuts.overwritePrompt")}),s.jsxs("div",{className:"flex gap-2 shrink-0",children:[s.jsx(H,{type:"button",size:"xs",className:"!font-normal",onClick:K,children:e("settings.openchamber.keyboardShortcuts.actions.overwrite")}),s.jsx(H,{type:"button",size:"xs",className:"!font-normal",variant:"ghost",onClick:()=>I(null),children:e("settings.common.actions.cancel")})]})]}),C&&s.jsx("div",{className:"rounded-lg border border-[var(--status-error-border)] bg-[var(--status-error-background)] p-3 typography-meta text-foreground",children:C}),E&&s.jsx("div",{className:"rounded-lg border border-[var(--status-warning-border)] bg-[var(--status-warning-background)] p-3 typography-meta text-foreground",children:E})]}),t[32]=K,t[33]=C,t[34]=M,t[35]=e,t[36]=E,t[37]=ee):ee=t[37];let se;t[38]!==b||t[39]!==p||t[40]!==N||t[41]!==w||t[42]!==T||t[43]!==i||t[44]!==e?(se=y.map((U,A)=>{const V=U.id==="switch_context_surface",W=V?xc(U.id,i):gr(U.id,i),te=N[U.id],ae=te??W,le=typeof te=="string"&&nn(te)!==nn(W),be=ae===""||nn(ae)===xi,ke=p===U.id?e("settings.openchamber.keyboardShortcuts.field.pressKeys"):V&&!be?`${hr(ae)}${e("settings.openchamber.keyboardShortcuts.action.switch_context_surface.suffix")}`:hr(ae);return s.jsx("div",{className:je("py-1.5",A>0&&"border-t border-border/40"),children:s.jsxs($t,{label:b(U.id,U.label),alignEnd:!1,children:[s.jsx(He,{readOnly:!0,value:ke,onFocus:()=>{L(U.id),u("")},onBlur:()=>{p===U.id&&L(null)},onKeyDown:ce=>{if(ce.preventDefault(),ce.stopPropagation(),ce.key==="Escape"){L(null);return}const ge=V?sh(ce):th(ce);ge&&(h(Ee=>({...Ee,[U.id]:ge})),L(null),I(null),u(""))},className:"h-7 w-40 min-w-0 typography-ui-label text-center"}),s.jsx(H,{type:"button",variant:"secondary",size:"xs",className:"!font-normal",onClick:()=>{const ce=N[U.id];if(!ce){u(e("settings.openchamber.keyboardShortcuts.error.captureFirst"));return}T(U.id,ce)},disabled:!le,children:e("settings.common.actions.saveChanges")}),s.jsx(H,{type:"button",size:"xs",className:"!font-normal",variant:"ghost",onClick:()=>w(U.id),children:e("settings.common.actions.reset")})]})},U.id)}),t[38]=b,t[39]=p,t[40]=N,t[41]=w,t[42]=T,t[43]=i,t[44]=e,t[45]=se):se=t[45];let D;t[46]!==se?(D=s.jsx("div",{children:se}),t[46]=se,t[47]=D):D=t[47];let O;return t[48]!==P||t[49]!==ee||t[50]!==D||t[51]!==G||t[52]!==Q?(O=s.jsxs(Oe,{settingsItem:"shortcuts.keyboard-shortcuts",title:G,divider:!1,info:Q,headerAction:P,children:[ee,D]}),t[48]=P,t[49]=ee,t[50]=D,t[51]=G,t[52]=Q,t[53]=O):O=t[53],O};function ah(t){return t.shortcutOverrides}function ih(t){return t.setShortcutOverride}function rh(t){return t.clearShortcutOverride}function oh(t){return t.resetAllShortcutOverrides}function lh(t){return t.id!=="toggle_prompt_navigator"}function ch(t){yt({shortcutOverrides:t})}const yl=()=>{const t=ht.c(2),[e,a]=o.useState(0);let n,i;return t[0]===Symbol.for("react.memo_cache_sentinel")?(n=()=>zo(()=>a(jh)),i=[],t[0]=n,t[1]=i):(n=t[0],i=t[1]),o.useEffect(n,i),e},dh=t=>{const e=ht.c(79),{section:a}=t,{t:n}=ot(),{isMobile:i}=Jn();yl();let r;e[0]!==i?(r=i&&yn(),e[0]=i,e[1]=r):r=e[1];const l=r;let x;e[2]===Symbol.for("react.memo_cache_sentinel")?(x=ds(),e[2]=x):x=e[2];const c=x;let y;e[3]===Symbol.for("react.memo_cache_sentinel")?(y=is()&&Na(),e[3]=y):y=e[3];const m=y;if(!a){let ee,se,D,O,U,A,V;e[4]===Symbol.for("react.memo_cache_sentinel")?(se=s.jsx(Xa,{}),D=s.jsx(ul,{}),O=m&&s.jsx(bl,{}),U=!c&&s.jsx(fl,{}),A=!c&&s.jsx(xl,{}),V=s.jsx(pl,{}),ee=yn()&&!is()&&!c&&!$o()&&s.jsx(ml,{}),e[4]=ee,e[5]=se,e[6]=D,e[7]=O,e[8]=U,e[9]=A,e[10]=V):(ee=e[4],se=e[5],D=e[6],O=e[7],U=e[8],A=e[9],V=e[10]);let W;e[11]!==l?(W=l&&s.jsx(qo,{}),e[11]=l,e[12]=W):W=e[12];let te;return e[13]!==W?(te=s.jsxs(rs,{showSaveStatus:!0,className:"openchamber-page-body space-y-3 sm:space-y-6",children:[se,D,O,U,A,V,ee,W]}),e[13]=W,e[14]=te):te=e[14],te}let b;e[15]!==a?(b=()=>{switch(a){case"general":return s.jsx(mh,{});case"visual":return s.jsx(uh,{});case"chat":return s.jsx(gh,{});case"sessions":return s.jsx(hh,{});case"shortcuts":return s.jsx(ph,{});case"git":return s.jsx(fh,{});case"github":return s.jsx(xh,{});case"notifications":return s.jsx(bh,{});case"voice":return s.jsx(vh,{});case"tunnel":return s.jsx(yh,{});default:return null}},e[15]=a,e[16]=b):b=e[16];const p=b;let L;e[17]!==n?(L=n("settings.page.general.title"),e[17]=n,e[18]=L):L=e[18];let k;e[19]!==n?(k=n("settings.page.appearance.title"),e[19]=n,e[20]=k):k=e[20];let N;e[21]!==n?(N=n("settings.page.chat.title"),e[21]=n,e[22]=N):N=e[22];let h;e[23]!==n?(h=n("settings.page.sessions.title"),e[23]=n,e[24]=h):h=e[24];let C;e[25]!==n?(C=n("settings.page.shortcuts.title"),e[25]=n,e[26]=C):C=e[26];let u;e[27]!==n?(u=n("settings.page.git.title"),e[27]=n,e[28]=u):u=e[28];let E;e[29]!==n?(E=n("settings.page.git.title"),e[29]=n,e[30]=E):E=e[30];let q;e[31]!==n?(q=n("settings.page.notifications.title"),e[31]=n,e[32]=q):q=e[32];let M;e[33]!==n?(M=n("settings.page.voice.title"),e[33]=n,e[34]=M):M=e[34];let I;e[35]!==n?(I=n("settings.page.tunnel.title"),e[35]=n,e[36]=I):I=e[36];let g;e[37]!==u||e[38]!==E||e[39]!==q||e[40]!==M||e[41]!==I||e[42]!==L||e[43]!==k||e[44]!==N||e[45]!==h||e[46]!==C?(g={general:L,visual:k,chat:N,sessions:h,shortcuts:C,git:u,github:E,notifications:q,voice:M,tunnel:I},e[37]=u,e[38]=E,e[39]=q,e[40]=M,e[41]=I,e[42]=L,e[43]=k,e[44]=N,e[45]=h,e[46]=C,e[47]=g):g=e[47];const j=g[a];let F;e[48]!==n?(F=n("settings.page.general.description"),e[48]=n,e[49]=F):F=e[49];let S;e[50]!==n?(S=n("settings.page.appearance.description"),e[50]=n,e[51]=S):S=e[51];let T;e[52]!==n?(T=n("settings.page.chat.description"),e[52]=n,e[53]=T):T=e[53];let v;e[54]!==n?(v=n("settings.page.sessions.description"),e[54]=n,e[55]=v):v=e[55];let K;e[56]!==n?(K=n("settings.page.shortcuts.description"),e[56]=n,e[57]=K):K=e[57];let $;e[58]!==n?($=n("settings.page.notifications.description"),e[58]=n,e[59]=$):$=e[59];let w;e[60]!==n?(w=n("settings.page.voice.description"),e[60]=n,e[61]=w):w=e[61];let G;e[62]!==n?(G=n("settings.page.tunnel.description"),e[62]=n,e[63]=G):G=e[63];let Q;e[64]!==F||e[65]!==S||e[66]!==T||e[67]!==v||e[68]!==K||e[69]!==$||e[70]!==w||e[71]!==G?(Q={general:F,visual:S,chat:T,sessions:v,shortcuts:K,git:void 0,github:void 0,notifications:$,voice:w,tunnel:G},e[64]=F,e[65]=S,e[66]=T,e[67]=v,e[68]=K,e[69]=$,e[70]=w,e[71]=G,e[72]=Q):Q=e[72];const X=Q[a];let Z;e[73]!==p?(Z=p(),e[73]=p,e[74]=Z):Z=e[74];let P;return e[75]!==X||e[76]!==j||e[77]!==Z?(P=s.jsx(rs,{title:j,description:X,showSaveStatus:!0,className:"openchamber-page-body",children:Z}),e[75]=X,e[76]=j,e[77]=Z,e[78]=P):P=e[78],P},ph=()=>{const t=ht.c(1);let e;return t[0]===Symbol.for("react.memo_cache_sentinel")?(e=s.jsx(nh,{}),t[0]=e):e=t[0],e},mh=()=>{const t=ht.c(8);let e;t[0]===Symbol.for("react.memo_cache_sentinel")?(e=ds(),t[0]=e):e=t[0];const a=e;yl();let n;t[1]===Symbol.for("react.memo_cache_sentinel")?(n=is()&&Na(),t[1]=n):n=t[1];const i=n;let r;t[2]===Symbol.for("react.memo_cache_sentinel")?(r=yn()&&!is()&&!a&&!$o(),t[2]=r):r=t[2];const l=r;let x,c,y,m;t[3]===Symbol.for("react.memo_cache_sentinel")?(x=i&&s.jsx(bl,{}),c=l&&s.jsx(ml,{}),y=!a&&s.jsx(fl,{}),m=!a&&s.jsx(xl,{}),t[3]=x,t[4]=c,t[5]=y,t[6]=m):(x=t[3],c=t[4],y=t[5],m=t[6]);let b;return t[7]===Symbol.for("react.memo_cache_sentinel")?(b=s.jsxs(s.Fragment,{children:[x,c,y,m,s.jsx(Xa,{visibleSettings:["fileEditorKeymap","autoSaveEnabled","expandedEditorToolbar",...a?[]:["terminalQuickKeys"],...a?[]:["terminalShell"],...a?[]:["terminalLoginShell"],"messageTransport","reportUsage"]})]}),t[7]=b):b=t[7],b},uh=()=>{const t=ht.c(2);let e;t[0]===Symbol.for("react.memo_cache_sentinel")?(e=ds(),t[0]=e):e=t[0];const a=e;let n;return t[1]===Symbol.for("react.memo_cache_sentinel")?(n=s.jsx(Xa,{visibleSettings:["theme","windowControlsPosition","pwaInstallName","pwaOrientation","mobileKeyboardMode","timeFormat",...a?[]:["weekStart"],"fontSize","terminalFontSize","editorFontSize","spacing","inputBarOffset"]}),t[1]=n):n=t[1],n},gh=()=>{const t=ht.c(2);let e;t[0]===Symbol.for("react.memo_cache_sentinel")?(e=ds(),t[0]=e):e=t[0];const a=e;let n;return t[1]===Symbol.for("react.memo_cache_sentinel")?(n=s.jsx(Xa,{visibleSettings:["sessionGoal","sessionAssist","chatRenderMode","activityRenderMode","userMessageRendering","mermaidRendering","reasoning","showToolFileIcons","showTurnChangedFiles","expandedTools","collapsibleUserMessages","stickyUserHeader",...a?[]:["promptNavigatorEnabled"],"wideChatLayout","codeBlockLineWrap","splitAssistantMessageActions","subagentReadOnlyBanner","diffLayout","dotfiles","fileViewerPreview","followUpBehavior","persistDraft","inputSpellcheck"]}),t[1]=n):n=t[1],n},hh=()=>{const t=ht.c(1);let e;return t[0]===Symbol.for("react.memo_cache_sentinel")?(e=s.jsxs(s.Fragment,{children:[s.jsx(ul,{}),s.jsx(pl,{})]}),t[0]=e):e=t[0],e},fh=()=>{const t=ht.c(1);let e;return t[0]===Symbol.for("react.memo_cache_sentinel")?(e=s.jsx(cl,{}),t[0]=e):e=t[0],e},xh=()=>{const t=ht.c(1);if(ds())return null;let e;return t[0]===Symbol.for("react.memo_cache_sentinel")?(e=s.jsx(dl,{}),t[0]=e):e=t[0],e},bh=()=>{const t=ht.c(1);let e;return t[0]===Symbol.for("react.memo_cache_sentinel")?(e=s.jsx(Og,{}),t[0]=e):e=t[0],e},vh=()=>{const t=ht.c(1);if(ds())return null;let e;return t[0]===Symbol.for("react.memo_cache_sentinel")?(e=s.jsx(zg,{}),t[0]=e):e=t[0],e},yh=()=>{const t=ht.c(1);if(ds())return null;let e;return t[0]===Symbol.for("react.memo_cache_sentinel")?(e=s.jsx(Qg,{}),t[0]=e):e=t[0],e};function jh(t){return t+1}const wh=t=>{const e=ht.c(85),{className:a}=t,{t:n}=ot(),i=Tn(Fo),r=Tn(Nh),l=de(kh),x=de(Sh),[c,y]=We.useState(!1),[m,b]=We.useState(!1),p=i>0;let L;e[0]!==n?(L=async()=>{try{const Se=await bc({message:n("settings.view.pendingRestart.applying")});if(Se.requiresManualRestart){R.warning(n("settings.view.pendingRestart.manualRestartRequired"));return}Se.ok&&R.success(n("settings.view.pendingRestart.applied"))}catch(Se){const Ne=Se,fe=Ne instanceof Error&&Ne.message?Ne.message:n("settings.view.pendingRestart.applyFailed");R.error(fe)}},e[0]=n,e[1]=L):L=e[1];const k=L;let N;e[2]!==n?(N=async()=>{try{await vc({message:n("settings.view.pendingRestart.applying"),mode:"projects",scopes:["all"]}),Tn.getState().clear()}catch{}},e[2]=n,e[3]=N):N=e[3];const h=N;let C;e[4]!==m||e[5]!==k||e[6]!==x?(C=()=>{m&&x(!1),y(!1),b(!1),k()},e[4]=m,e[5]=k,e[6]=x,e[7]=C):C=e[7];const u=C;let E;e[8]!==p||e[9]!==k||e[10]!==h||e[11]!==l?(E=()=>{if(!p){h();return}if(l){b(!1),y(!0);return}k()},e[8]=p,e[9]=k,e[10]=h,e[11]=l,e[12]=E):E=e[12];const q=E;let M;e[13]!==p||e[14]!==r||e[15]!==n?(M=n(p?r?"settings.view.pendingRestart.applying":"settings.view.actions.applyAndRestartOpenCode":"settings.view.actions.reloadOpenCode"),e[13]=p,e[14]=r,e[15]=n,e[16]=M):M=e[16];const I=M;let g;e[17]!==p||e[18]!==i||e[19]!==n?(g=p?i===1?n("settings.view.actions.applyAndRestartOpenCodeTooltipSingle"):n("settings.view.actions.applyAndRestartOpenCodeTooltipPlural",{count:i}):n("settings.view.actions.reloadOpenCodeTooltip"),e[17]=p,e[18]=i,e[19]=n,e[20]=g):g=e[20];const j=g,F=p?"bg-primary text-primary-foreground typography-ui-label font-semibold hover:bg-primary/90":"text-sm font-semibold text-sidebar-foreground/90 hover:text-sidebar-foreground hover:bg-interactive-hover",S=r&&"opacity-80";let T;e[21]!==a||e[22]!==F||e[23]!==S?(T=je("flex w-full items-center gap-2 rounded-md overflow-hidden whitespace-nowrap","h-11 px-3 sm:h-8 sm:px-2","focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-primary/50",F,S,a),e[21]=a,e[22]=F,e[23]=S,e[24]=T):T=e[24];let v;e[25]!==p||e[26]!==i?(v=p?s.jsx("span",{className:je("inline-flex h-5 min-w-5 shrink-0 items-center justify-center rounded-full px-1.5","bg-background text-foreground typography-micro font-semibold tabular-nums"),"aria-hidden":"true",children:i}):s.jsx(_,{name:"restart",className:"h-4 w-4 shrink-0"}),e[25]=p,e[26]=i,e[27]=v):v=e[27];let K;e[28]!==I?(K=s.jsx("span",{className:"truncate",children:I}),e[28]=I,e[29]=K):K=e[29];let $;e[30]!==q||e[31]!==r||e[32]!==v||e[33]!==K||e[34]!==T||e[35]!==j?($=s.jsxs("button",{type:"button",disabled:r,title:j,"aria-label":j,onClick:q,className:T,children:[v,K]}),e[30]=q,e[31]=r,e[32]=v,e[33]=K,e[34]=T,e[35]=j,e[36]=$):$=e[36];let w;e[37]===Symbol.for("react.memo_cache_sentinel")?(w=Se=>{y(Se),Se||b(!1)},e[37]=w):w=e[37];let G;e[38]!==n?(G=n("settings.view.pendingRestart.confirm.title"),e[38]=n,e[39]=G):G=e[39];let Q;e[40]!==G?(Q=s.jsx(Gt,{children:G}),e[40]=G,e[41]=Q):Q=e[41];let X;e[42]!==n?(X=n("settings.view.pendingRestart.confirm.description"),e[42]=n,e[43]=X):X=e[43];let Z;e[44]!==X?(Z=s.jsx(qt,{children:X}),e[44]=X,e[45]=Z):Z=e[45];let P;e[46]!==Q||e[47]!==Z?(P=s.jsxs(Ht,{children:[Q,Z]}),e[46]=Q,e[47]=Z,e[48]=P):P=e[48];let ee;e[49]===Symbol.for("react.memo_cache_sentinel")?(ee={width:"40%"},e[49]=ee):ee=e[49];let se;e[50]===Symbol.for("react.memo_cache_sentinel")?(se=()=>y(!1),e[50]=se):se=e[50];let D;e[51]!==n?(D=n("settings.view.pendingRestart.confirm.cancel"),e[51]=n,e[52]=D):D=e[52];let O;e[53]!==D?(O=s.jsx("div",{className:"min-w-0 shrink-0",style:ee,children:s.jsx(H,{type:"button",variant:"outline",className:"h-9 w-full normal-case",onClick:se,children:D})}),e[53]=D,e[54]=O):O=e[54];let U;e[55]===Symbol.for("react.memo_cache_sentinel")?(U={width:"40%"},e[55]=U):U=e[55];let A;e[56]!==n?(A=n("settings.view.actions.applyAndRestartOpenCode"),e[56]=n,e[57]=A):A=e[57];let V;e[58]!==u||e[59]!==A?(V=s.jsx("div",{className:"min-w-0 shrink-0",style:U,children:s.jsx(H,{type:"button",variant:"default",className:"h-9 w-full normal-case",onClick:u,children:A})}),e[58]=u,e[59]=A,e[60]=V):V=e[60];let W;e[61]!==O||e[62]!==V?(W=s.jsxs("div",{className:"flex w-full items-stretch justify-center gap-3",children:[O,V]}),e[61]=O,e[62]=V,e[63]=W):W=e[63];let te;e[64]===Symbol.for("react.memo_cache_sentinel")?(te=()=>b(Ch),e[64]=te):te=e[64];let ae;e[65]!==m?(ae=m?s.jsx(_,{name:"checkbox",className:"h-4 w-4 text-primary"}):s.jsx(_,{name:"checkbox-blank",className:"h-4 w-4"}),e[65]=m,e[66]=ae):ae=e[66];let le;e[67]!==n?(le=n("settings.view.pendingRestart.confirm.dontShowAgain"),e[67]=n,e[68]=le):le=e[68];let be;e[69]!==m||e[70]!==ae||e[71]!==le?(be=s.jsxs("button",{type:"button",onClick:te,className:"inline-flex items-center justify-center gap-1.5 typography-ui-label text-muted-foreground transition-colors hover:text-foreground focus-visible:outline-none focus-visible:ring-1 focus-visible:ring-primary/50","aria-pressed":m,children:[ae,le]}),e[69]=m,e[70]=ae,e[71]=le,e[72]=be):be=e[72];let ke;e[73]!==W||e[74]!==be?(ke=s.jsxs("div",{className:"flex w-full flex-col items-center gap-3",children:[W,be]}),e[73]=W,e[74]=be,e[75]=ke):ke=e[75];let ce;e[76]!==P||e[77]!==ke?(ce=s.jsxs(Vt,{showCloseButton:!1,className:"max-w-md gap-5",children:[P,ke]}),e[76]=P,e[77]=ke,e[78]=ce):ce=e[78];let ge;e[79]!==c||e[80]!==ce?(ge=s.jsx(Ut,{open:c,onOpenChange:w,children:ce}),e[79]=c,e[80]=ce,e[81]=ge):ge=e[81];let Ee;return e[82]!==$||e[83]!==ge?(Ee=s.jsxs(s.Fragment,{children:[$,ge]}),e[82]=$,e[83]=ge,e[84]=Ee):Ee=e[84],Ee};function Nh(t){return t.isApplying}function kh(t){return t.showOpenCodeRestartConfirm}function Sh(t){return t.setShowOpenCodeRestartConfirm}function Ch(t){return!t}const Ih=[{id:"appearance.language",page:"appearance",titleKey:"settings.appearance.language.label",descriptionKey:"settings.appearance.language.description",keywords:["locale","translation","ui language"]},{id:"appearance.time-format",page:"appearance",titleKey:"settings.openchamber.visual.field.timeFormat",keywords:["clock","12h","24h"]},{id:"appearance.week-start",page:"appearance",titleKey:"settings.openchamber.visual.field.weekStartsOn",keywords:["calendar","monday","sunday"],isAvailable:t=>!t.isVSCode},{id:"appearance.light-theme",page:"appearance",titleKey:"settings.openchamber.visual.field.lightTheme",keywords:["theme","color","light mode"],isAvailable:t=>!t.isVSCode},{id:"appearance.dark-theme",page:"appearance",titleKey:"settings.openchamber.visual.field.darkTheme",keywords:["theme","color","dark mode"],isAvailable:t=>!t.isVSCode},{id:"appearance.dock-badge",page:"appearance",titleKey:"settings.openchamber.visual.field.dockBadge",descriptionKey:"settings.openchamber.visual.field.dockBadgeHint",keywords:["dock","badge","unread","unseen","counter","count","notification","macos"],isAvailable:t=>t.isMac},{id:"appearance.pwa-install-name",page:"appearance",titleKey:"settings.openchamber.visual.field.installAppName",descriptionKey:"settings.openchamber.visual.field.installAppNameHint",keywords:["pwa","installed app"],isAvailable:t=>t.isWeb&&!t.isDesktop&&!t.isVSCode},{id:"appearance.pwa-orientation",page:"appearance",titleKey:"settings.openchamber.visual.field.installOrientation",descriptionKey:"settings.openchamber.visual.field.installOrientationHint",keywords:["pwa","portrait","landscape"],isAvailable:t=>t.isWeb&&!t.isDesktop&&!t.isVSCode},{id:"appearance.mobile-keyboard-mode",page:"appearance",titleKey:"settings.openchamber.visual.field.mobileKeyboardMode",descriptionKey:"settings.openchamber.visual.field.mobileKeyboardModeHint",keywords:["mobile","keyboard","resize"],isAvailable:t=>t.isMobile&&t.isWeb&&!t.isDesktop&&!t.isVSCode},{id:"appearance.interface-font-size",page:"appearance",titleKey:"settings.openchamber.visual.field.interfaceFontSize",keywords:["font","text size","ui scale"],isAvailable:t=>!t.isMobile},{id:"appearance.terminal-font-size",page:"appearance",titleKey:"settings.openchamber.visual.field.terminalFontSize",keywords:["terminal","font","text size"]},{id:"appearance.terminal-shell",page:"general",titleKey:"settings.openchamber.visual.field.terminalShell",descriptionKey:"settings.openchamber.visual.field.terminalShellHint",keywords:["terminal","shell","bash","zsh","fish","pwsh","powershell"],isAvailable:t=>!t.isVSCode},{id:"appearance.editor-font-size",page:"appearance",titleKey:"settings.openchamber.visual.field.editorFontSize",keywords:["editor","font","text size","code"]},{id:"appearance.spacing-density",page:"appearance",titleKey:"settings.openchamber.visual.field.spacingDensity",keywords:["density","compact","comfortable","spacing"]},{id:"appearance.input-bar-offset",page:"appearance",titleKey:"settings.openchamber.visual.field.inputBarOffset",descriptionKey:"settings.openchamber.visual.field.inputBarOffsetTooltip",keywords:["input","home bar","offset"],isAvailable:t=>t.isMobile},{id:"appearance.auto-save-enabled",page:"general",titleKey:"settings.openchamber.visual.field.autoSaveEnabled",descriptionKey:"settings.openchamber.visual.field.autoSaveEnabledInfo",keywords:["editor","autosave","auto-save","files","save"]},{id:"appearance.expanded-editor-toolbar",page:"general",titleKey:"settings.openchamber.visual.field.expandedEditorToolbar",keywords:["editor","toolbar","tabs","docked","files"],isAvailable:t=>!t.isVSCode},{id:"appearance.file-editor-keymap",page:"general",titleKey:"settings.openchamber.visual.field.fileEditorKeymap",keywords:["editor","vim","keymap"]},{id:"appearance.terminal-quick-keys",page:"general",titleKey:"settings.openchamber.visual.field.terminalQuickKeys",descriptionKey:"settings.openchamber.visual.field.terminalQuickKeysTooltip",keywords:["terminal","keyboard","esc","ctrl","arrows"],isAvailable:t=>!t.isMobile&&!t.isVSCode},{id:"appearance.usage-reports",page:"general",titleKey:"settings.openchamber.visual.field.sendAnonymousUsageReports",descriptionKey:"settings.openchamber.visual.field.sendAnonymousUsageReportsHint",keywords:["telemetry","analytics"]},{id:"chat.render-mode",page:"chat",titleKey:"settings.openchamber.visual.section.chatRenderMode",keywords:["messages","conversation","rendering"]},{id:"chat.message-transport",page:"general",titleKey:"settings.openchamber.visual.section.messageStreamTransport",keywords:["streaming","sse","websocket"]},{id:"chat.session-recap",page:"chat",titleKey:"settings.openchamber.visual.field.sessionRecap",keywords:["recap","assist","small model","summary"]},{id:"chat.session-assistance",page:"chat",titleKey:"settings.openchamber.visual.section.sessionAssistance",keywords:["recap","suggestion","subagent"]},{id:"chat.session-suggestion",page:"chat",titleKey:"settings.openchamber.visual.field.sessionSuggestion",keywords:["suggestion","assist","small model","follow up"]},{id:"chat.session-goal",page:"chat",titleKey:"settings.openchamber.visual.field.sessionGoal",keywords:["goal","objective","auto continue","small model"],isAvailable:t=>!t.isVSCode},{id:"chat.session-goal-budget",page:"chat",titleKey:"settings.openchamber.visual.goal.budgetLabel",keywords:["goal","budget","tokens","limit"],isAvailable:t=>!t.isVSCode},{id:"chat.reasoning-traces",page:"chat",titleKey:"settings.openchamber.visual.field.showReasoningTraces",keywords:["thinking","reasoning"]},{id:"chat.reasoning",page:"chat",titleKey:"settings.openchamber.visual.section.reasoning",keywords:["thinking","traces"]},{id:"chat.sticky-user-header",page:"chat",titleKey:"settings.openchamber.visual.field.stickyUserHeader",keywords:["messages","header"]},{id:"chat.prompt-navigator",page:"chat",titleKey:"settings.openchamber.visual.field.promptNavigatorEnabled",keywords:["prompt","navigator","navigation","timeline","scroll"],isAvailable:t=>!t.isVSCode},{id:"chat.collapsible-user-messages",page:"chat",titleKey:"settings.openchamber.visual.field.collapsibleUserMessages",keywords:["collapse","expand","clamp","long messages","user messages"]},{id:"chat.wide-layout",page:"chat",titleKey:"settings.openchamber.visual.field.wideChatLayout",keywords:["layout","wide","messages"]},{id:"chat.message-appearance",page:"chat",titleKey:"settings.openchamber.visual.section.messageAppearance",keywords:["layout","messages","appearance"]},{id:"chat.code-block-line-wrap",page:"chat",titleKey:"settings.openchamber.visual.field.codeBlockLineWrap",keywords:["code","wrap","line wrap","markdown"]},{id:"chat.inline-assistant-actions",page:"chat",titleKey:"settings.openchamber.visual.field.showSplitAssistantMessageActions",descriptionKey:"settings.openchamber.visual.field.showSplitAssistantMessageActionsTooltip",keywords:["copy","save image","read aloud"]},{id:"chat.draft-starters-visible",page:"chat",titleKey:"settings.openchamber.visual.field.draftStartersVisible",keywords:["starter","starters","new session","welcome","suggestions"]},{id:"chat.subagent-read-only-banner",page:"chat",titleKey:"settings.openchamber.visual.field.allowPromptingSubagentSessions",keywords:["subagent","read only","prompt","banner"]},{id:"chat.tool-file-icons",page:"chat",titleKey:"settings.openchamber.visual.field.showToolFileIcons",keywords:["tools","files","icons"]},{id:"chat.tools-and-files",page:"chat",titleKey:"settings.openchamber.visual.section.toolsAndFiles",keywords:["tools","files","dotfiles"]},{id:"chat.changed-files",page:"chat",titleKey:"settings.openchamber.visual.field.showTurnChangedFiles",keywords:["changed files","turns"]},{id:"chat.dotfiles",page:"chat",titleKey:"settings.openchamber.visual.field.showDotfiles",keywords:["hidden files"],isAvailable:t=>!t.isVSCode},{id:"chat.follow-up-behavior",page:"chat",titleKey:"settings.openchamber.visual.section.followUpBehavior",descriptionKey:"settings.openchamber.visual.field.followUpBehaviorDescription",keywords:["follow up","queue","steer","send immediately"]},{id:"chat.persist-drafts",page:"chat",titleKey:"settings.openchamber.visual.field.persistDraftMessages",keywords:["draft","message"]},{id:"chat.composer",page:"chat",titleKey:"settings.openchamber.visual.section.composer",keywords:["input","draft","spellcheck"]},{id:"chat.spellcheck",page:"chat",titleKey:"settings.openchamber.visual.field.enableSpellcheckInTextInputs",keywords:["spelling","input"],isAvailable:t=>!t.isMobile},{id:"sessions.default-model",page:"sessions",titleKey:"settings.openchamber.defaults.field.defaultModel",keywords:["model","provider","new sessions"]},{id:"sessions.default-thinking",page:"sessions",titleKey:"settings.openchamber.defaults.field.defaultThinking",keywords:["thinking","reasoning","variant"]},{id:"sessions.default-agent",page:"sessions",titleKey:"settings.openchamber.defaults.field.defaultAgent",keywords:["agent","new sessions"]},{id:"sessions.deletion-dialog",page:"sessions",titleKey:"settings.openchamber.defaults.field.showDeletionDialog",keywords:["delete","confirmation"]},{id:"sessions.small-model",page:"sessions",titleKey:"settings.openchamber.defaults.smallModel.title",descriptionKey:"settings.openchamber.defaults.smallModel.description",keywords:["small model","utility","summary","recap","cheap","override"]},{id:"sessions.walkthrough-model",page:"sessions",titleKey:"settings.openchamber.defaults.walkthroughModel.title",descriptionKey:"settings.openchamber.defaults.walkthroughModel.description",keywords:["walkthrough","diff","review","changes","structured output","model","override"]},{id:"sessions.auto-cleanup",page:"sessions",titleKey:"settings.openchamber.sessionRetention.field.enableAutoCleanup",descriptionKey:"settings.openchamber.sessionRetention.tooltip",keywords:["retention","archive","delete"]},{id:"sessions.retention-period",page:"sessions",titleKey:"settings.openchamber.sessionRetention.field.retentionPeriod",keywords:["days","cleanup","retention"]},{id:"sessions.retention-action",page:"sessions",titleKey:"settings.openchamber.sessionRetention.field.whenSessionsExpire",keywords:["archive","delete","expire"]},{id:"sessions.desktop-launch-at-login",page:"general",titleKey:"settings.openchamber.desktopNetwork.field.launchAtLogin",descriptionKey:"settings.openchamber.desktopNetwork.field.launchAtLoginDescription",keywords:["desktop","startup","login","launch","background","autostart"],isAvailable:t=>t.isDesktopLocalOrigin},{id:"sessions.desktop-window-controls-position",page:"appearance",titleKey:"settings.openchamber.desktopNetwork.field.windowControlsPosition",descriptionKey:"settings.openchamber.desktopNetwork.field.windowControlsPositionDescription",keywords:["desktop","window","controls","minimize","maximize","close","titlebar","linux","windows"],isAvailable:t=>t.isDesktop&&(t.isWindows||!t.isMac)},{id:"sessions.desktop-window-controls-style",page:"appearance",titleKey:"settings.openchamber.desktopNetwork.field.windowControlsStyle",keywords:["desktop","window","controls","style","traffic","lights","classic","macos","titlebar"],isAvailable:t=>t.isDesktop&&(t.isWindows||!t.isMac)},{id:"sessions.desktop-mac-menu-bar",page:"general",titleKey:"settings.openchamber.desktopNetwork.field.macMenuBar",descriptionKey:"settings.openchamber.desktopNetwork.field.macMenuBarDescription",keywords:["desktop","menu bar","tray","status item","macos","background"],isAvailable:t=>t.isDesktopLocalOrigin&&t.isMac},{id:"sessions.desktop-minimize-to-tray",page:"general",titleKey:"settings.openchamber.desktopNetwork.field.minimizeToTray",descriptionKey:"settings.openchamber.desktopNetwork.field.minimizeToTrayDescription",keywords:["desktop","tray","system tray","minimize","close","background","windows","linux"],isAvailable:t=>t.isDesktopLocalOrigin&&(t.isWindows||t.isLinux)},{id:"sessions.desktop-keep-awake",page:"general",titleKey:"settings.openchamber.desktopNetwork.field.keepAwake",descriptionKey:"settings.openchamber.desktopNetwork.field.keepAwakeDescription",keywords:["desktop","sleep","awake","server","mobile","phone"],isAvailable:t=>t.isDesktopLocalOrigin},{id:"sessions.desktop-ui-password",page:"general",titleKey:"settings.openchamber.desktopPassword.field.password",descriptionKey:"settings.openchamber.desktopPassword.field.passwordDescription",keywords:["desktop","password","auth","login"],isAvailable:t=>t.isDesktopLocalOrigin},{id:"sessions.desktop-lan-access",page:"general",titleKey:"settings.openchamber.desktopNetwork.field.allowLanAccess",descriptionKey:"settings.openchamber.desktopNetwork.field.allowLanAccessDescription",keywords:["desktop","lan","network","phone","tablet"],isAvailable:t=>t.isDesktopLocalOrigin},{id:"sessions.opencode-binary",page:"general",titleKey:"settings.openchamber.opencodeCli.field.binaryPath",keywords:["opencode","cli","binary","path"],isAvailable:t=>!t.isVSCode},{id:"sessions.opencode-update-notifications",page:"general",titleKey:"settings.openchamber.opencodeCli.field.showUpdateNotifications",keywords:["opencode","cli","updates"],isAvailable:t=>!t.isVSCode&&!t.isWindowsArm64},{id:"sessions.agent-control-tool",page:"general",titleKey:"settings.openchamber.tools.field.agentControlTool",descriptionKey:"settings.openchamber.tools.field.agentControlToolInfo",keywords:["agent","tool","orchestration","openchamber","sessions","schedule","control"],isAvailable:t=>!t.isVSCode},{id:"sessions.agent-web-tool",page:"general",titleKey:"settings.openchamber.tools.field.agentWebTool",descriptionKey:"settings.openchamber.tools.field.agentWebToolInfo",keywords:["agent","tool","web","browser","page","preview","openchamber"],isAvailable:t=>!t.isVSCode},{id:"git.github-account",page:"git",titleKey:"settings.github.page.actions.connect",keywords:["github","account","oauth","prs","issues"]},{id:"git.identities",page:"git",titleKey:"settings.gitIdentities.page.section.title",descriptionKey:"settings.gitIdentities.page.empty.description",keywords:["identity","profile","author","email","credentials","signing","commit signing","ssh signing","gpg"]},{id:"git.changes-view",page:"git",titleKey:"settings.openchamber.git.changesViewTitle",keywords:["changes","flat list","tree view"]},{id:"git.gitmoji",page:"git",titleKey:"settings.openchamber.git.enableGitmoji",keywords:["commit","emoji"]},{id:"git.gitignored-files",page:"git",titleKey:"settings.openchamber.git.showGitignored",keywords:["ignored","files","gitignore"]},{id:"usage.work-status-panel",page:"usage",titleKey:"settings.usage.page.options.showInWorkStatus",descriptionKey:"settings.usage.page.options.showInWorkStatusTooltip",keywords:["quota","work","status","panel"]},{id:"usage.model-quotas",page:"usage",titleKey:"settings.usage.page.section.modelQuotas",keywords:["models","quota","limits","tokens"]},{id:"projects.name",page:"projects",titleKey:"settings.projects.page.field.projectName",keywords:["label","display name","project metadata"]},{id:"projects.accent-color",page:"projects",titleKey:"settings.projects.page.field.accentColor",keywords:["color","appearance","project metadata"]},{id:"projects.icon",page:"projects",titleKey:"settings.projects.page.field.projectIcon",keywords:["icon","favicon","upload","project metadata"]},{id:"projects.worktree",page:"projects",titleKey:"settings.projects.page.section.worktree",keywords:["worktree","branch","repository"]},{id:"projects.worktree.setup.wait",page:"projects",titleKey:"settings.openchamber.worktrees.setup.waitForCommands",keywords:["worktree","setup commands","bootstrap","wait"]},{id:"remote-instances.client-auth",page:"remote-instances",titleKey:"settings.remoteInstances.clientAuth.title",descriptionKey:"settings.remoteInstances.clientAuth.description",keywords:["pairing link","client token","connect desktop","remote access","relay","devices","connect from anywhere"],isAvailable:t=>!t.isVSCode},{id:"remote-instances.direct-hosts",page:"remote-instances",titleKey:"settings.remoteInstances.direct.title",descriptionKey:"settings.remoteInstances.direct.description",keywords:["server url","connection token","import link","host switcher","additional headers","request headers","cloudflare access","service token"],isAvailable:t=>t.isDesktop},{id:"behavior.system-prompt-optimization",page:"behavior",titleKey:"settings.behavior.page.section.systemPromptOptimization",descriptionKey:"settings.behavior.page.systemPromptOptimization.info",keywords:["system prompt","tokens","context","optimize","minimal"],isAvailable:t=>!t.isVSCode},{id:"behavior.system-prompt",page:"behavior",titleKey:"settings.behavior.page.section.systemPrompt",descriptionKey:"settings.behavior.page.warning.title",keywords:["agents.md","global instructions","system prompt"]},{id:"behavior.response-style",page:"behavior",titleKey:"settings.behavior.page.section.responseStyle",descriptionKey:"settings.behavior.page.responseStyle.tooltip",keywords:["tone","concise","detailed","custom instructions"]},{id:"agents.create",page:"agents",titleKey:"settings.agents.page.title.new",keywords:["create","add","new agent"]},{id:"agents.name",page:"agents",titleKey:"settings.agents.page.field.agentName",keywords:["agent","name"]},{id:"agents.mode",page:"agents",titleKey:"settings.agents.page.field.mode",descriptionKey:"settings.agents.page.field.modeTooltip",keywords:["primary","subagent","visibility"]},{id:"agents.model",page:"agents",titleKey:"settings.agents.page.field.overrideModel",keywords:["model","provider"]},{id:"agents.variant",page:"agents",titleKey:"settings.agents.page.field.variant",descriptionKey:"settings.agents.page.field.variantTooltip",keywords:["thinking","reasoning","variant","depth"]},{id:"agents.temperature",page:"agents",titleKey:"settings.agents.page.field.temperature",descriptionKey:"settings.agents.page.field.temperatureTooltip",keywords:["randomness","creative"]},{id:"agents.top-p",page:"agents",titleKey:"settings.agents.page.field.topP",descriptionKey:"settings.agents.page.field.topPTooltip",keywords:["sampling","nucleus"]},{id:"agents.system-prompt",page:"agents",titleKey:"settings.agents.page.section.systemPrompt",keywords:["prompt","instructions"]},{id:"agents.permissions",page:"agents",titleKey:"settings.agents.page.section.toolPermissions",keywords:["tools","permissions","allow","ask","deny"]},{id:"commands.create",page:"commands",titleKey:"settings.commands.page.title.new",keywords:["create","add","new command"]},{id:"commands.name",page:"commands",titleKey:"settings.commands.page.field.commandName",keywords:["slash command","name"]},{id:"commands.agent",page:"commands",titleKey:"settings.commands.page.field.overrideAgent",keywords:["agent","execution"]},{id:"commands.model",page:"commands",titleKey:"settings.agents.page.field.overrideModel",keywords:["model","provider"]},{id:"commands.template",page:"commands",titleKey:"settings.commands.page.section.template",keywords:["prompt","template","arguments","shell","file"]},{id:"mcp.create",page:"mcp",titleKey:"settings.mcp.sidebar.actions.addServerTitle",keywords:["create","add","server"]},{id:"mcp.server",page:"mcp",titleKey:"settings.mcp.page.server.title",keywords:["server","name","transport"]},{id:"mcp.command",page:"mcp",titleKey:"settings.mcp.page.connection.command",keywords:["stdio","local","command"]},{id:"mcp.environment",page:"mcp",titleKey:"settings.mcp.page.env.title",keywords:["env","variables","api key"]},{id:"mcp.advanced",page:"mcp",titleKey:"settings.mcp.page.advanced.title",keywords:["oauth","headers","timeout"]},{id:"plugins.create",page:"plugins",titleKey:"settings.plugins.sidebar.actions.addTitle",keywords:["add","plugin","npm","path","file"]},{id:"plugins.spec",page:"plugins",titleKey:"settings.plugins.page.field.spec",keywords:["npm","package","path"]},{id:"plugins.options",page:"plugins",titleKey:"settings.plugins.page.field.options",keywords:["json","configuration"]},{id:"plugins.content",page:"plugins",titleKey:"settings.plugins.page.field.content",keywords:["file","code"]},{id:"snippets.create",page:"snippets",titleKey:"settings.snippets.sidebar.actions.create",keywords:["add","new snippet"]},{id:"snippets.content",page:"snippets",titleKey:"settings.snippets.page.field.content",keywords:["markdown","prompt","template"]},{id:"providers.connect",page:"providers",titleKey:"settings.providers.page.connect.title",keywords:["add provider","connect provider","credentials"]},{id:"providers.custom",page:"providers",titleKey:"settings.providers.page.custom.title",descriptionKey:"settings.providers.page.custom.description",keywords:["other","custom","openai-compatible","base url","api key"]},{id:"providers.auth",page:"providers",titleKey:"settings.providers.page.auth.title",keywords:["api key","oauth","credentials"]},{id:"providers.connection-details",page:"providers",titleKey:"settings.providers.page.connectionDetails.title",keywords:["config","source","disconnect"]},{id:"providers.models",page:"providers",titleKey:"settings.providers.page.models.title",keywords:["models","hide","show"]},{id:"skills.create",page:"skills.installed",titleKey:"settings.skills.page.title.newSkill",keywords:["create","add","new skill"]},{id:"skills.basic-information",page:"skills.installed",titleKey:"settings.skills.page.section.basicInformation",keywords:["name","location","description"]},{id:"skills.instructions",page:"skills.installed",titleKey:"settings.skills.page.section.instructions",keywords:["markdown","skill.md","content"]},{id:"skills.supporting-files",page:"skills.installed",titleKey:"settings.skills.page.section.supportingFiles",keywords:["files","resources"]},{id:"skills.catalog.source",page:"skills.catalog",titleKey:"settings.skills.catalog.page.section.sourceRepository",keywords:["catalog","repository","source","refresh"]},{id:"skills.catalog.search",page:"skills.catalog",titleKey:"settings.skills.catalog.shared.field.searchSkillsPlaceholder",keywords:["find skills","install skills","catalog search"]},{id:"skills.catalog.add-catalog",page:"skills.catalog",titleKey:"settings.skills.catalog.page.actions.addCatalog",keywords:["external repository","add source","catalog"]},{id:"magic-prompts.visible-prompt",page:"magic-prompts",titleKey:"settings.magicPrompts.page.block.visiblePrompt",keywords:["prompt text","user message","template"],isAvailable:t=>!t.isVSCode},{id:"magic-prompts.instructions",page:"magic-prompts",titleKey:"settings.magicPrompts.page.block.instructions",keywords:["hidden prompt","instructions","template"],isAvailable:t=>!t.isVSCode},{id:"magic-prompts.reset-overrides",page:"magic-prompts",titleKey:"settings.magicPrompts.page.actions.resetAllOverrides",keywords:["reset","default prompts","overrides"],isAvailable:t=>!t.isVSCode},{id:"shortcuts.keyboard-shortcuts",page:"shortcuts",titleKey:"settings.openchamber.keyboardShortcuts.title",descriptionKey:"settings.openchamber.keyboardShortcuts.tooltip",keywords:["keyboard","hotkeys","bindings"]},{id:"voice.playback",page:"voice",titleKey:"settings.voice.page.section.playbackAndSummary",keywords:["tts","read aloud","voice","provider","speech rate","speech pitch","speech volume","tts input mode","markdown"]},{id:"voice.speech-recognition",page:"voice",titleKey:"settings.voice.page.section.speechRecognition",keywords:["stt","dictation","voice input","transcribe","whisper","parakeet","microphone"]},{id:"tunnel.provider",page:"tunnel",titleKey:"settings.openchamber.tunnel.field.provider",descriptionKey:"settings.openchamber.tunnel.description",keywords:["remote access","cloudflare","ngrok"],isAvailable:t=>!t.isVSCode},{id:"tunnel.type",page:"tunnel",titleKey:"settings.openchamber.tunnel.field.tunnelType",keywords:["quick","managed remote","managed local"],isAvailable:t=>!t.isVSCode},{id:"tunnel.ttl",page:"tunnel",titleKey:"settings.openchamber.tunnel.field.connectLinkTtl",descriptionKey:"settings.openchamber.tunnel.field.tunnelSessionTtl",keywords:["expiry","expiration","session ttl","connect link ttl"],isAvailable:t=>!t.isVSCode},{id:"tunnel.managed-remote",page:"tunnel",titleKey:"settings.openchamber.tunnel.section.savedManagedRemoteTunnels",keywords:["cloudflare","hostname","token","managed remote"],isAvailable:t=>!t.isVSCode},{id:"tunnel.managed-local-config",page:"tunnel",titleKey:"settings.openchamber.tunnel.field.configurationFile",descriptionKey:"settings.openchamber.tunnel.note.managedLocalUsesConfig",keywords:["cloudflared","config","yaml","json","managed local"],isAvailable:t=>!t.isVSCode},{id:"tunnel.start",page:"tunnel",titleKey:"settings.openchamber.tunnel.actions.startTunnel",descriptionKey:"settings.openchamber.tunnel.note.connectLinksOneTime",keywords:["connect link","qr code","public url","remote access"],isAvailable:t=>!t.isVSCode},{id:"notifications.delivery",page:"notifications",titleKey:"settings.notifications.page.delivery.title",keywords:["desktop notifications","system notifications"]},{id:"notifications.events",page:"notifications",titleKey:"settings.notifications.page.events.title",keywords:["completion","subtasks","errors","questions"]},{id:"notifications.push",page:"notifications",titleKey:"settings.notifications.page.push.title",keywords:["background","push"],isAvailable:t=>t.isWeb&&!t.isDesktop&&!t.isVSCode}];function So(t){return t.trim().toLocaleLowerCase()}function Ph({query:t,runtimeCtx:e,visiblePageSlugs:a,t:n,getPageTitle:i}){const r=So(t);if(!r)return[];const l=a?new Set(a):null,x=r.split(/\s+/).filter(Boolean);return Ih.flatMap(c=>{if(l&&!l.has(c.page))return[];const y=pa(c.page);if(!y||y.isAvailable&&!y.isAvailable(e)||c.isAvailable&&!c.isAvailable(e))return[];const m=n(c.titleKey),b=c.descriptionKey?n(c.descriptionKey):null,p=So([m,b,i(c.page),...c.keywords??[]].filter(Boolean).join(" "));return x.every(L=>p.includes(L))?[{...c,title:m,description:b,pageTitle:i(c.page)}]:[]})}const Co=256,Io=280,jl="__openchamberSettingsDetail",Ah=["general","appearance","chat","notifications","sessions","shortcuts","voice","usage","about","projects","remote-instances","tunnel","git","providers","agents","behavior","commands","mcp","plugins","magic-prompts","snippets","skills.installed","skills.catalog"],Th=["general","projects","opencode","content"],Eh="__add_provider__";function Dh(t,e){const a=ds(),n=!t&&yn();return{isVSCode:a,isWeb:n,isDesktop:t,isMobile:e}}function Po(t,e){return t.isAvailable?t.isAvailable(e):!0}function qi(t){return typeof t=="object"&&t!==null&&!Array.isArray(t)}function da(t,e){const a=new Set(e);let n=t,i=1;for(;a.has(n);)n=`${t}-${i}`,i+=1;return n}function Ri(t){if(!qi(t))return null;const e=t[jl];if(!qi(e))return null;const a=e.page,n=e.stage;return typeof a!="string"||n!=="page-content"?null:{page:Bo(a),stage:n}}function Mh(){return typeof window>"u"||!qi(window.history.state)?{}:window.history.state}const Rh=t=>{const e=ht.c(124),{onClose:a,forceMobile:n,isWindowed:i,visiblePageSlugs:r,initialMobileStage:l}=t,x=l===void 0?"nav":l,{t:c}=ot(),y=Jn(),m=n??y.isMobile,b=Tn(Fo),p=de(Oh),L=de(Lh),k=de(Fh);let N;e[0]!==p?(N=Bo(p),e[0]=p,e[1]=N):N=e[1];const h=N,[C,u]=o.useState(x),E=o.useRef(x==="nav"?h:null);let q,M;e[2]!==m||e[3]!==k||e[4]!==h?(q=()=>{!m&&h==="home"&&k("general")},M=[m,k,h],e[2]=m,e[3]=k,e[4]=h,e[5]=q,e[6]=M):(q=e[5],M=e[6]),o.useEffect(q,M);const[I,g]=o.useState(""),[j,F]=o.useState(null),[S,T]=o.useState(0),v=o.useRef(null);let K;e[7]===Symbol.for("react.memo_cache_sentinel")?(K=[],e[7]=K):K=e[7];const $=o.useRef(K),w=o.useRef(0),G=o.useRef(!1);let Q;e[8]===Symbol.for("react.memo_cache_sentinel")?(Q=is(),e[8]=Q):Q=e[8];const X=Q;let Z;e[9]===Symbol.for("react.memo_cache_sentinel")?(Z=is()&&Na(),e[9]=Z):Z=e[9];const P=Z;let ee;e[10]===Symbol.for("react.memo_cache_sentinel")?(ee=is()&&typeof window<"u"&&window.__OPENCHAMBER_PLATFORM__==="darwin",e[10]=ee):ee=e[10];const se=ee;let D;e[11]===Symbol.for("react.memo_cache_sentinel")?(D=is()&&typeof window<"u"&&window.__OPENCHAMBER_PLATFORM__==="win32",e[11]=D):D=e[11];const O=D;let U;e[12]===Symbol.for("react.memo_cache_sentinel")?(U=is()&&typeof window<"u"&&window.__OPENCHAMBER_PLATFORM__==="linux",e[12]=U):U=e[12];const A=U;let V;e[13]===Symbol.for("react.memo_cache_sentinel")?(V=Vo(),e[13]=V):V=e[13];const W=V;let te;e[14]!==m?(te=Dh(X,m),e[14]=m,e[15]=te):te=e[15];const ae=te;let le;if(e[16]!==m||e[17]!==ae||e[18]!==r){const Y=r?new Set(r):null;let Ce;e[20]!==ae?(Ce=jt=>Po(jt,ae),e[20]=ae,e[21]=Ce):Ce=e[21];let st;e[22]!==ae.isVSCode?(st=jt=>!(ae.isVSCode&&jt.slug==="projects"),e[22]=ae.isVSCode,e[23]=st):st=e[23];let At;e[24]!==m?(At=jt=>!(m&&jt.slug==="shortcuts"),e[24]=m,e[25]=At):At=e[25],le=ed.filter(Kh).filter(jt=>!Y||Y.has(jt.slug)).filter(Ce).filter(st).filter(At),e[16]=m,e[17]=ae,e[18]=r,e[19]=le}else le=e[19];const be=le;let ke;e[26]===Symbol.for("react.memo_cache_sentinel")?(ke=new Map(Ah.map(_h)),e[26]=ke):ke=e[26];const ce=ke;let ge;if(e[27]!==be){let Y;e[29]===Symbol.for("react.memo_cache_sentinel")?(Y=(Ce,st)=>(ce.get(Ce.slug)??999)-(ce.get(st.slug)??999),e[29]=Y):Y=e[29],ge=be.slice().sort(Y),e[27]=be,e[28]=ge}else ge=e[28];const Ee=ge,Se=Fs(zh);let Ne;e[30]!==L||e[31]!==i||e[32]!==ae.isVSCode||e[33]!==h?(Ne=()=>{if(!(!L&&!ae.isVSCode&&!i)){if(h==="agents"){ja.getState().loadAgents();return}if(h==="commands"){Qa.getState().loadCommands();return}if(h==="mcp"){Ya.getState().loadMcpConfigs();return}if(h==="plugins"){us.getState().loadPlugins();return}(h==="skills.installed"||h==="skills.catalog")&&(rn.getState().loadSkills(),an.getState().loadCatalog()),h==="snippets"&&Za.getState().loadSnippets()}},e[30]=L,e[31]=i,e[32]=ae.isVSCode,e[33]=h,e[34]=Ne):Ne=e[34];let fe;e[35]!==Se||e[36]!==L||e[37]!==i||e[38]!==ae.isVSCode||e[39]!==h?(fe=[Se,L,i,ae.isVSCode,h],e[35]=Se,e[36]=L,e[37]=i,e[38]=ae.isVSCode,e[39]=h,e[40]=fe):fe=e[40],o.useEffect(Ne,fe);let Ke;e[41]!==m||e[42]!==k?(Ke=Y=>{if(k(Y),E.current=Y,!m)return;const Ce=pa(Y);if(!Ce||Ce.slug==="home"){u("nav");return}u(Ce.kind==="split"?"page-sidebar":"page-content")},e[41]=m,e[42]=k,e[43]=Ke):Ke=e[43];const De=Ke;let he;e[44]!==h?(he=pa(h),e[44]=h,e[45]=he):he=e[45];const pe=he;let Ie;e[46]===Symbol.for("react.memo_cache_sentinel")?(Ie={general:"general",appearance:"visual",chat:"chat",shortcuts:"shortcuts",sessions:"sessions",notifications:"notifications",voice:"voice",tunnel:"tunnel"},e[46]=Ie):Ie=e[46];const ze=Ie;let Je;e[47]!==c?(Je=Y=>{switch(Y){case"general":return c("settings.page.general.title");case"projects":return c("settings.page.projects.title");case"remote-instances":return c("settings.page.remoteInstances.title");case"providers":return c("settings.page.providers.title");case"usage":return c("settings.page.usage.title");case"agents":return c("settings.page.agents.title");case"behavior":return c("settings.page.behavior.title");case"commands":return c("settings.page.commands.title");case"mcp":return c("settings.page.mcp.title");case"plugins":return c("settings.page.plugins.title");case"skills.installed":return c("settings.page.skills.title");case"skills.catalog":return c("settings.page.skillsCatalog.title");case"git":return c("settings.page.git.title");case"appearance":return c("settings.page.appearance.title");case"chat":return c("settings.page.chat.title");case"shortcuts":return c("settings.page.shortcuts.title");case"sessions":return c("settings.page.sessions.title");case"magic-prompts":return c("settings.page.magicPrompts.title");case"snippets":return c("settings.page.snippets.title");case"notifications":return c("settings.page.notifications.title");case"voice":return c("settings.page.voice.title");case"tunnel":return c("settings.page.tunnel.title");case"about":return c("settings.page.about.title");default:return c("settings.view.home.title")}},e[47]=c,e[48]=Je):Je=e[48];const _e=Je;let Le;e[49]!==_e||e[50]!==ae||e[51]!==I||e[52]!==c||e[53]!==r?(Le=Ph({query:I,runtimeCtx:{...ae,isDesktopLocalOrigin:P,isMac:se,isWindows:O,isLinux:A,isWindowsArm64:W},visiblePageSlugs:r,t:c,getPageTitle:_e}),e[49]=_e,e[50]=ae,e[51]=I,e[52]=c,e[53]=r,e[54]=Le):Le=e[54];const Pe=Le,Ye=Gh;let Ge;if(e[55]!==Pe){Ge=[];const Y=new Map;for(const Ce of Pe){let st=Y.get(Ce.page);st||(st={page:Ce.page,pageTitle:Ce.pageTitle,results:[]},Y.set(Ce.page,st),Ge.push(st)),st.results.push(Ce)}e[55]=Pe,e[56]=Ge}else Ge=e[56];const Me=Ge;let $e;e[57]===Symbol.for("react.memo_cache_sentinel")?($e=()=>{T(0),w.current=0,G.current=!1},e[57]=$e):$e=e[57];let Fe;e[58]!==I?(Fe=[I],e[58]=I,e[59]=Fe):Fe=e[59],o.useEffect($e,Fe);let ye,z;e[60]!==S?(ye=()=>{w.current=S},z=[S],e[60]=S,e[61]=ye,e[62]=z):(ye=e[61],z=e[62]),o.useEffect(ye,z);let oe,me;e[63]!==S?(oe=()=>{$.current[S]?.scrollIntoView({block:"nearest"})},me=[S],e[63]=S,e[64]=oe,e[65]=me):(oe=e[64],me=e[65]),o.useEffect(oe,me);let ve,re;e[66]!==S||e[67]!==Pe.length?(ve=()=>{S>=Pe.length&&T(Math.max(0,Pe.length-1)),$.current.length=Pe.length},re=[S,Pe.length],e[66]=S,e[67]=Pe.length,e[68]=ve,e[69]=re):(ve=e[68],re=e[69]),o.useEffect(ve,re);let Ve;e[70]!==m||e[71]!==De?(Ve=Y=>{const Ce=Ye(Y);F(Ce),De(Y.page),m&&u("page-content"),Y.id==="plugins.create"&&typeof window<"u"&&window.setTimeout(qh,50)},e[70]=m,e[71]=De,e[72]=Ve):Ve=e[72];const Ze=Ve;let B;e[73]!==Ze||e[74]!==I||e[75]!==Pe?(B=Y=>{if(I.trim()){if(Y.key==="Escape"){Y.preventDefault(),g("");return}if(Pe.length!==0){if(Y.key==="ArrowDown"){Y.preventDefault(),G.current=!0,T(Ce=>(Ce+1)%Pe.length);return}if(Y.key==="ArrowUp"){Y.preventDefault(),G.current=!0,T(Ce=>(Ce-1+Pe.length)%Pe.length);return}if(Y.key==="Enter"){Y.preventDefault();const Ce=(w.current%Pe.length+Pe.length)%Pe.length,st=Pe[Ce]??Pe[0];st&&Ze(st)}}}},e[73]=Ze,e[74]=I,e[75]=Pe,e[76]=B):B=e[76];const Ue=B;let Qe;e[77]!==j?(Qe=()=>{const Y=j;if(!Y)return;let Ce=!1;const st=window.requestAnimationFrame(()=>{if(Ce)return;const At=typeof CSS<"u"&&CSS.escape?CSS.escape(Y):Y.replace(/[^a-zA-Z0-9_-]/g,"\\$&"),jt=v.current?.querySelector(`[data-settings-item="${At}"]`);jt&&(F(null),jt.scrollIntoView({block:"center",behavior:"smooth"}),jt.setAttribute("data-settings-search-highlight","true"),window.setTimeout(()=>{jt.removeAttribute("data-settings-search-highlight")},1600))});return()=>{Ce=!0,window.cancelAnimationFrame(st)}},e[77]=j,e[78]=Qe):Qe=e[78];let et;e[79]!==j||e[80]!==h?(et=[j,h],e[79]=j,e[80]=h,e[81]=et):et=e[81],o.useEffect(Qe,et);let tt;e[82]!==c?(tt=()=>s.jsx("div",{className:"flex h-full items-center justify-center px-6",children:s.jsxs("div",{className:"max-w-md text-center",children:[s.jsx("div",{className:wc,children:c("settings.view.unavailable.title")}),s.jsx("p",{className:"typography-ui text-muted-foreground mt-1",children:c("settings.view.unavailable.description")})]})}),e[82]=c,e[83]=tt):tt=e[83];const wt=tt,mt=Wh;let pt;e[84]!==wt||e[85]!==ae||e[86]!==c?(pt=Y=>{const Ce=pa(Y);if(Ce&&!Po(Ce,ae))return wt();switch(Y){case"projects":return s.jsx(Lm,{});case"remote-instances":return s.jsx(eu,{});case"agents":return s.jsx(Md,{});case"behavior":return s.jsx(Kd,{});case"commands":return s.jsx(qd,{});case"mcp":return s.jsx(xp,{});case"plugins":return s.jsx(Wp,{});case"skills.installed":return s.jsx(Gr,{view:"installed"});case"skills.catalog":return s.jsx(Gr,{view:"catalog"});case"providers":return s.jsx(Mu,{});case"usage":return s.jsx(Ju,{});case"about":return s.jsx(rs,{title:c("settings.page.about.title"),showSaveStatus:!1,children:s.jsx(qo,{})});case"magic-prompts":return s.jsx(eg,{});case"snippets":return s.jsx(ig,{});case"git":return s.jsx(dg,{});case"general":case"appearance":case"chat":case"shortcuts":case"sessions":case"notifications":case"voice":case"tunnel":{const st=ze[Y]??"visual";return s.jsx(dh,{section:st})}default:return null}},e[84]=wt,e[85]=ae,e[86]=c,e[87]=pt):pt=e[87];const at=pt;let ft,gt;e[88]!==m||e[89]!==C||e[90]!==h?(ft=()=>{if(!m||C!=="nav"||h==="home"||E.current===h)return;const Y=pa(h);!Y||Y.slug==="home"||(E.current=h,u(Y.kind==="split"?"page-sidebar":"page-content"))},gt=[m,C,h],e[88]=m,e[89]=C,e[90]=h,e[91]=ft,e[92]=gt):(ft=e[91],gt=e[92]),o.useEffect(ft,gt);const Ct=m&&C!=="nav",ie=m&&C==="page-content"&&h==="skills.installed",Ae=C==="page-content"&&pe?.kind==="split"&&!ie;let Be;e[93]!==ie||e[94]!==Ct||e[95]!==c?(Be=c(ie?"settings.view.actions.back":Ct?"settings.view.actions.backToSettings":"settings.view.actions.closeSettings"),e[93]=ie,e[94]=Ct,e[95]=c,e[96]=Be):Be=e[96];const qe=Be,Nt=yc();let xt;e[97]!==ae.isVSCode?(xt=Y=>{if(typeof window>"u"||ae.isVSCode)return;const Ce=Ri(window.history.state);Ce?.page===Y&&Ce.stage==="page-content"||window.history.pushState({...Mh(),[jl]:{page:Y,stage:"page-content"}},"",window.location.href)},e[97]=ae.isVSCode,e[98]=xt):xt=e[98];const zt=xt;let J;e[99]!==zt||e[100]!==h?(J=()=>{u("page-content"),h==="skills.installed"&&zt(h)},e[99]=zt,e[100]=h,e[101]=J):J=e[101];const xe=J;let Re;e[102]!==ie||e[103]!==ae.isVSCode||e[104]!==h?(Re=()=>{if(ie){if((typeof window<"u"?Ri(window.history.state):null)?.page===h&&!ae.isVSCode){window.history.back();return}u("page-sidebar");return}u("nav")},e[102]=ie,e[103]=ae.isVSCode,e[104]=h,e[105]=Re):Re=e[105];const we=Re;let rt,lt;e[106]!==m||e[107]!==ae.isVSCode||e[108]!==h?(rt=()=>{if(!m||ae.isVSCode)return;const Y=Ce=>{if(h!=="skills.installed")return;if(Ri(Ce.state)?.page==="skills.installed"){u("page-content");return}u(Jh)};return window.addEventListener("popstate",Y),()=>{window.removeEventListener("popstate",Y)}},lt=[m,ae.isVSCode,h],e[106]=m,e[107]=ae.isVSCode,e[108]=h,e[109]=rt,e[110]=lt):(rt=e[109],lt=e[110]),o.useEffect(rt,lt);let it;e[111]===Symbol.for("react.memo_cache_sentinel")?(it=()=>{u("page-sidebar")},e[111]=it):it=e[111];const It=it,ls=()=>{const Y=I.trim().length>0;return s.jsxs("div",{className:"flex h-full flex-col overflow-hidden",children:[s.jsx("div",{className:"px-4 pt-3",children:s.jsxs("div",{className:"flex h-10 items-center gap-1.5 rounded-md border border-border bg-background/70 px-2 text-muted-foreground focus-within:ring-2 focus-within:ring-primary/40 sm:h-8",children:[s.jsx(_,{name:"search",className:"h-4 w-4 shrink-0"}),s.jsx("input",{value:I,onChange:Ce=>g(Ce.target.value),onKeyDown:Ue,placeholder:c("settings.view.search.placeholder"),"aria-label":c("settings.view.search.aria"),className:"typography-ui min-w-0 flex-1 bg-transparent text-foreground outline-none placeholder:text-muted-foreground/70"}),Y&&s.jsx("button",{type:"button",onClick:()=>g(""),"aria-label":c("settings.view.search.clear"),className:"inline-flex h-7 w-7 shrink-0 items-center justify-center rounded text-muted-foreground hover:bg-interactive-hover hover:text-foreground sm:h-5 sm:w-5",children:s.jsx(_,{name:"close",className:"h-3.5 w-3.5"})})]})}),s.jsx("div",{className:"flex-1 min-h-0 overflow-y-auto overflow-x-hidden",children:s.jsx("div",{className:"flex flex-col gap-0.5 px-4 pt-4 pb-2",children:Y?Pe.length>0?(()=>{let Ce=0;return Me.map(st=>s.jsxs("div",{className:"space-y-0.5",children:[s.jsx("div",{className:"px-2 pb-0.5 pt-2 typography-micro font-medium text-muted-foreground/70",children:st.pageTitle}),st.results.map(At=>{const jt=Ce;Ce=Ce+1;const Jt=jt===S,fs=!!At.description;return s.jsxs("button",{type:"button",ref:cs=>{$.current[jt]=cs},onMouseMove:()=>{G.current=!1,T(jt)},onClick:()=>Ze(At),className:je("flex w-full flex-col rounded-md px-2 text-left focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-primary/50",fs?"min-h-11 py-1.5":"py-2",Jt?"bg-interactive-selection":"hover:bg-interactive-hover"),children:[s.jsx("span",{className:"typography-ui-label text-foreground truncate",children:At.title}),fs&&s.jsx("span",{className:"typography-micro text-muted-foreground/70 line-clamp-2",children:At.description})]},At.id)})]},st.page))})():s.jsx("div",{className:"px-2 py-6 text-center typography-ui text-muted-foreground",children:c("settings.view.search.noResults")}):(()=>{const Ce=new Map;for(const At of Ee){const jt=At.group,Jt=Ce.get(jt);Jt?Jt.push(At):Ce.set(jt,[At])}return Th.map(At=>({group:At,pages:Ce.get(At)??[]})).filter(Qh).map((At,jt)=>{const{group:Jt,pages:fs}=At;return s.jsxs("div",{className:"space-y-0.5",children:[s.jsx("div",{className:je("px-3 pb-1 typography-micro font-semibold uppercase tracking-wide text-muted-foreground sm:px-2 sm:pb-0.5",jt===0?"pt-1":"pt-4 sm:pt-3"),children:c(`settings.view.nav.group.${Jt}`)}),fs.map(cs=>{const Ts=h===cs.slug&&!(m&&C==="nav"),Ws=td(cs.slug);return!Ws&&cs.slug!=="mcp"?null:s.jsx(Ji,{children:s.jsx(Qi,{asChild:!0,children:s.jsxs("button",{type:"button",onClick:()=>De(cs.slug),"aria-current":Ts?"page":void 0,className:je("flex h-11 w-full items-center gap-2.5 rounded-md px-3 overflow-hidden sm:h-8 sm:gap-2 sm:px-2",Ts?"bg-interactive-selection text-foreground":"text-foreground hover:bg-interactive-hover"),children:[cs.slug==="mcp"?s.jsx(jc,{className:"h-[18px] w-[18px] shrink-0 sm:h-4 sm:w-4"}):s.jsx(_,{name:Ws,className:"h-[18px] w-[18px] shrink-0 sm:h-4 sm:w-4"}),s.jsxs("span",{className:"flex items-center gap-1.5 whitespace-nowrap overflow-hidden transition-opacity duration-150 opacity-100",children:[s.jsx("span",{className:"typography-ui-label font-normal truncate",children:_e(cs.slug)}),cs.slug==="tunnel"&&s.jsx("span",{className:"shrink-0 typography-micro px-1 rounded leading-none pb-px text-[var(--status-warning)] bg-[var(--status-warning)]/10",children:c("settings.view.badge.beta")})]})]})})},cs.slug)})]},Jt)})})()})}),s.jsx("div",{className:"overflow-hidden transition-opacity duration-150 opacity-100",children:s.jsx("div",{className:"border-t border-border bg-background px-4 py-1.5 space-y-0.5 sm:bg-sidebar",children:(!ae.isVSCode||b>0)&&s.jsx(wh,{})})})]})},Xt=()=>{if(C==="nav")return s.jsx("div",{className:"flex-1 min-h-0 overflow-hidden bg-background",children:s.jsx("div",{className:"flex h-full min-h-0 flex-col",children:s.jsx(dn,{children:ls()})})});if(!pe)return s.jsx("div",{className:"flex-1 bg-background"});if(C==="page-sidebar"){if(pe.kind!=="split"){const Ce=at(h);return s.jsx("div",{className:"flex-1 min-h-0 overflow-y-scroll overflow-x-hidden bg-background",children:s.jsx(dn,{children:Ce})})}return s.jsx("div",{className:"flex-1 min-h-0 overflow-y-scroll overflow-x-hidden bg-background",children:s.jsx(dn,{children:mt(h,{onItemSelect:xe})})})}const Y=at(h);return s.jsx("div",{className:"flex-1 min-h-0 overflow-y-scroll overflow-x-hidden bg-background",children:s.jsx(dn,{children:Y})})};let ts;e[112]!==pe||e[113]!==at||e[114]!==ae.isVSCode||e[115]!==h?(ts=()=>!pe||h==="home"?null:pe.kind==="split"?s.jsxs("div",{className:"flex h-full min-h-0 overflow-hidden",children:[s.jsx("div",{className:je("border-r",ae.isVSCode?"bg-background":"bg-sidebar"),style:{width:Io,minWidth:Io,borderColor:"var(--interactive-border)"},children:s.jsx(dn,{children:mt(h,{})})}),s.jsx("div",{className:"flex-1 min-h-0 overflow-y-scroll overflow-x-hidden bg-background",children:s.jsx(dn,{children:at(h)})})]}):s.jsx("div",{className:"h-full min-h-0 overflow-y-scroll overflow-x-hidden bg-background",children:s.jsx(dn,{children:at(h)})}),e[112]=pe,e[113]=at,e[114]=ae.isVSCode,e[115]=h,e[116]=ts):ts=e[116];const Wt=ts,kt="true";let bt;e[117]===Symbol.for("react.memo_cache_sentinel")?(bt=je("relative flex h-full min-h-0 flex-col overflow-hidden bg-background"),e[117]=bt):bt=e[117];const Pt=m?s.jsxs("div",{className:je("flex h-[var(--oc-header-height,56px)] shrink-0 items-center gap-2 px-3",C!=="nav"&&"border-b","bg-background"),style:C!=="nav"?{borderColor:"var(--interactive-border)"}:void 0,children:[Ct?s.jsx("button",{type:"button",onClick:we,"aria-label":qe,className:"inline-flex h-9 w-9 flex-shrink-0 items-center justify-center rounded-lg p-2 text-muted-foreground hover:text-foreground hover:bg-interactive-hover/50 focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-primary",children:s.jsx(_,{name:"arrow-left-s",className:"h-5 w-5"})}):null,s.jsx("div",{className:"min-w-0 flex-1 px-2 typography-ui-label font-medium text-foreground truncate",children:C==="nav"?c("settings.view.home.title"):pe?_e(pe.slug):c("settings.view.home.title")}),Ae&&s.jsx("button",{type:"button",onClick:It,"aria-label":c("settings.view.actions.openSectionList"),className:"inline-flex h-9 w-9 flex-shrink-0 items-center justify-center rounded-lg p-2 text-muted-foreground hover:text-foreground hover:bg-interactive-hover/50 focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-primary",children:s.jsx(_,{name:"list-unordered",className:"h-5 w-5"})}),a&&s.jsx("button",{type:"button",onClick:a,"aria-label":c("settings.view.actions.closeSettings"),title:c("settings.view.actions.closeSettingsWithShortcut",{shortcut:Nt}),className:"inline-flex h-9 w-9 flex-shrink-0 items-center justify-center rounded-lg p-2 text-muted-foreground hover:text-foreground hover:bg-interactive-hover/50 focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-primary",children:s.jsx(_,{name:"close",className:"h-5 w-5"})})]}):s.jsxs(s.Fragment,{children:[Ct&&s.jsx("div",{className:je("absolute left-3 z-50",i?"top-2":"top-3"),children:s.jsx("button",{type:"button",onClick:we,"aria-label":c("settings.view.actions.back"),className:"inline-flex h-9 w-9 items-center justify-center rounded-lg p-2 text-muted-foreground hover:text-foreground hover:bg-interactive-hover/50 focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-primary",children:s.jsx(_,{name:"arrow-left-s",className:"h-5 w-5"})})}),a&&s.jsx("div",{className:je("absolute right-0.5 z-50",i?"top-0.5":"top-1"),children:s.jsx("button",{type:"button",onClick:a,"aria-label":c("settings.view.actions.closeSettings"),title:c("settings.view.actions.closeSettingsWithShortcut",{shortcut:Nt}),className:"inline-flex h-7 w-7 items-center justify-center rounded-md p-0.5 text-muted-foreground hover:text-foreground hover:bg-interactive-hover/50 focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-primary",children:s.jsx(_,{name:"close",className:"h-5 w-5"})})})]}),St="flex flex-1 min-h-0 overflow-hidden",Ft=m?Xt():s.jsxs(s.Fragment,{children:[s.jsx("div",{className:je("relative flex h-full min-h-0 flex-col overflow-hidden border-r",X?"bg-sidebar":ae.isVSCode?"bg-background":"bg-sidebar"),style:{width:`${Co}px`,minWidth:`${Co}px`,borderColor:"var(--interactive-border)"},children:s.jsx(dn,{children:ls()})}),s.jsx("div",{className:"flex-1 overflow-hidden bg-background",children:Wt()})]});let Bt;e[118]!==Ft?(Bt=s.jsx("div",{className:St,children:Ft}),e[118]=Ft,e[119]=Bt):Bt=e[119];let hs;return e[120]!==bt||e[121]!==Pt||e[122]!==Bt?(hs=s.jsxs("div",{ref:v,"data-settings-view":kt,className:bt,children:[Pt,Bt]}),e[120]=bt,e[121]=Pt,e[122]=Bt,e[123]=hs):hs=e[123],hs};function Oh(t){return t.settingsPage}function Lh(t){return t.isSettingsDialogOpen}function Fh(t){return t.setSettingsPage}function Kh(t){return t.slug!=="home"}function _h(t,e){return[t,e]}function zh(t){return t.activeProjectId}function Uh(t){return t.name}function Vh(t){return t.name}function $h(t){return t.name}function Bh(t){return t.name}function Hh(t){return t.name}function Gh(t){if(t.id.startsWith("agents.")){const e=ja.getState(),a=da("new-agent",e.agents.map(Uh));return e.setAgentDraft({name:a,scope:"user"}),e.setSelectedAgent(a),t.id==="agents.create"?"agents.name":t.id}if(t.id.startsWith("commands.")){const e=Qa.getState(),a=da("new-command",e.commands.map(Vh));return e.setCommandDraft({name:a,scope:"user"}),e.setSelectedCommand(a),t.id==="commands.create"?"commands.name":t.id}if(t.id.startsWith("mcp.")){const e=Ya.getState(),a=da("new-mcp-server",e.mcpServers.map($h));return e.setMcpDraft({name:a,scope:"user",type:"local",command:[],url:"",environment:[],headers:[],oauthEnabled:!0,oauthClientId:"",oauthClientSecret:"",oauthScope:"",oauthRedirectUri:"",timeout:"",enabled:!0}),e.setSelectedMcp(a),t.id==="mcp.create"?"mcp.server":t.id}if(t.id.startsWith("snippets.")){const e=Za.getState(),a=da("new-snippet",e.snippets.map(Bh));return e.setSnippetDraft({name:a,scope:"global"}),e.setSelectedSnippet(a),t.id==="snippets.create"?"snippets.content":t.id}if(t.id.startsWith("skills.")){const e=rn.getState(),a=da("new-skill",e.skills.map(Hh));return e.setSkillDraft({name:a,scope:"user",source:"opencode",description:"",instructions:""}),e.setSelectedSkill(a),t.id==="skills.create"?"skills.basic-information":t.id}return t.id==="providers.connect"&&nt.getState().setSelectedProvider(Eh),t.id==="plugins.create"?"plugins.spec":t.id}function qh(){window.dispatchEvent(new CustomEvent("openchamber:settings-open-plugin-add"))}function Wh(t,e){switch(t){case"projects":return s.jsx(Em,{onItemSelect:e.onItemSelect});case"agents":return s.jsx(wd,{onItemSelect:e.onItemSelect});case"commands":return s.jsx(_d,{onItemSelect:e.onItemSelect});case"mcp":return s.jsx(Wd,{onItemSelect:e.onItemSelect});case"plugins":return s.jsx(Lp,{onItemSelect:e.onItemSelect});case"skills.installed":return s.jsx(Qp,{onItemSelect:e.onItemSelect});case"providers":return s.jsx(nu,{onItemSelect:e.onItemSelect});case"usage":return s.jsx(Ou,{onItemSelect:e.onItemSelect});case"magic-prompts":return s.jsx(Yu,{onItemSelect:e.onItemSelect});case"snippets":return s.jsx(tg,{onItemSelect:e.onItemSelect});default:return null}}function Jh(t){return t==="page-content"?"page-sidebar":t}function Qh(t){return t.pages.length>0}const cf=Object.freeze(Object.defineProperty({__proto__:null,SettingsView:Rh},Symbol.toStringTag,{value:"Module"}));export{qo as A,Rh as S,cf as a};