@aiworker/web 1.23.0 → 1.23.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (152) hide show
  1. package/dist/assets/{CodeMirrorCommentWidgets-B1Gizi3a.js → CodeMirrorCommentWidgets-teB3HmBT.js} +1 -1
  2. package/dist/assets/DiffView-DC9RX3MF.js +4 -0
  3. package/dist/assets/{DirtyBranchSwitchDialog-aig6zJjg.js → DirtyBranchSwitchDialog-DwPkzXsS.js} +1 -1
  4. package/dist/assets/FilesView-BFZkuu4O.js +13 -0
  5. package/dist/assets/{GitView-BXsS3jG6.js → GitView-B_x52MHY.js} +4 -4
  6. package/dist/assets/{JsonTreeView-D_hpXBnF.js → JsonTreeView-cmAzUTiw.js} +1 -1
  7. package/dist/assets/{LinearIssuesView-BoUiLQG1.js → LinearIssuesView-Dehh5afm.js} +1 -1
  8. package/dist/assets/{MarkdownImageGallery-B_B_a9KS.js → MarkdownImageGallery-DgNOqqhE.js} +1 -1
  9. package/dist/assets/{MarkdownRendererImpl-xgyyLiBM.js → MarkdownRendererImpl-DusmMZ_p.js} +2 -2
  10. package/dist/assets/{OnboardingScreen-DIp84OWt.js → OnboardingScreen-B8fm1H4m.js} +1 -1
  11. package/dist/assets/{PatchDiff-8p6nLJaU.js → PatchDiff-BVr7gJU0.js} +1 -1
  12. package/dist/assets/{PierreDiffViewer-DjC8nTk9.js → PierreDiffViewer-DzLt-nel.js} +1 -1
  13. package/dist/assets/PlanView-BmQUYT_z.js +5 -0
  14. package/dist/assets/SettingsView-ChWmAcZT.js +28 -0
  15. package/dist/assets/{SettingsWindow-Cpb4hM6q.js → SettingsWindow-Dy3M6ZB9.js} +1 -1
  16. package/dist/assets/{ToolOutputDialog-DfaKZXNU.js → ToolOutputDialog-cTl_eLIH.js} +6 -6
  17. package/dist/assets/{ToolPartDiffPreview-DtZLzrSK.js → ToolPartDiffPreview-C_3iYNJQ.js} +2 -2
  18. package/dist/assets/{VirtualizedFileDiff-C8i9HpTB.js → VirtualizedFileDiff-CAWthkoy.js} +4 -4
  19. package/dist/assets/WalkthroughView-C7AHOpCA.js +4 -0
  20. package/dist/assets/{computeVirtualFileMetrics-BBI7ZwrC.js → computeVirtualFileMetrics-BkiDSlTW.js} +2 -2
  21. package/dist/assets/de-DJsQr-p7.js +10 -0
  22. package/dist/assets/es-BuYMlA9g.js +16 -0
  23. package/dist/assets/fr-ePDay33C.js +14 -0
  24. package/dist/assets/index-BD8ILbxF.js +40 -0
  25. package/dist/assets/{index-jXSK5RrB.js → index-n6O3hklM.js} +1 -1
  26. package/dist/assets/index-zhgg-SDz.css +1 -0
  27. package/dist/assets/{isDiffPlainText-B_x_rVon.js → isDiffPlainText-GMdPz-71.js} +1 -1
  28. package/dist/assets/{isFilePlainText-DW_xMer1.js → isFilePlainText-BVuH1zH9.js} +1 -1
  29. package/dist/assets/ja-BzR9xOY_.js +16 -0
  30. package/dist/assets/{ko-idhXGF8j.js → ko-BEjHAm14.js} +3 -3
  31. package/dist/assets/main-BydQ1tr_.js +930 -0
  32. package/dist/assets/{main-CzdPuL0s.js → main-D3ZDQglc.js} +2 -2
  33. package/dist/assets/{markdownCore-Cn4Tyejo.js → markdownCore-Cb2MdZnV.js} +3 -3
  34. package/dist/assets/{miniChat-CCkqKOLp.js → miniChat-d01k801U.js} +2 -2
  35. package/dist/assets/{mobile-mvxTo055.js → mobile-D7VV-Ufz.js} +2 -2
  36. package/dist/assets/patchFileDiff-CdztVMz0.js +13 -0
  37. package/dist/assets/{pl-CGZWUqZJ.js → pl-rQmpxNIF.js} +3 -3
  38. package/dist/assets/pt-BR-CorbsSW-.js +16 -0
  39. package/dist/assets/renderElectronMiniChatApp-BGG9UIlh.js +2 -0
  40. package/dist/assets/renderMobileApp-BRP3J1iv.js +25 -0
  41. package/dist/assets/runtimeEndpointReset-BhT_-c52.js +41 -0
  42. package/dist/assets/scheduledTasksApi-BEuUF_cj.js +1 -0
  43. package/dist/assets/{shikiHighlight-CRl0SUC9.js → shikiHighlight-BzXUjlby.js} +1 -1
  44. package/dist/assets/surface-COKb77Ua.js +1 -0
  45. package/dist/assets/tr-CoAMXPtI.js +7 -0
  46. package/dist/assets/uk-YlAX0rRU.js +16 -0
  47. package/dist/assets/{useAppFontEffects-CPKeOpUo.js → useAppFontEffects-Cwyhjfl5.js} +153 -155
  48. package/dist/assets/useGitComparison-BCZVefdE.js +1 -0
  49. package/dist/assets/{useInlineCommentController-BiWz4AVb.js → useInlineCommentController-DDkpBEU8.js} +2 -2
  50. package/dist/assets/{useRootScrollLock-BS4-kr7P.js → useRootScrollLock-CwjoWuC4.js} +1 -1
  51. package/dist/assets/{vendor-base-ui-DdV8vhHn.js → vendor-base-ui-BY_5qla_.js} +1 -1
  52. package/dist/assets/{vendor-codemirror-language-data-Bg4AEeCr.js → vendor-codemirror-language-data-Cb1YnICj.js} +2 -2
  53. package/dist/assets/vendor-legendapp-list-BuBPBC3R.js +1 -0
  54. package/dist/assets/{vendor-zod-BPAANqvH.js → vendor-zod-B6551dwG.js} +2 -2
  55. package/dist/assets/{web-components-z7hfnS8n.js → web-components-LV3vjTxy.js} +1 -1
  56. package/dist/assets/zh-CN-DDYg0Jl7.js +16 -0
  57. package/dist/assets/zh-TW-CQKaCayr.js +16 -0
  58. package/dist/index.html +4 -4
  59. package/dist/mini-chat.html +4 -4
  60. package/dist/mobile.html +4 -4
  61. package/package.json +1 -1
  62. package/server/index.js +3 -13
  63. package/server/lib/agent-memory/runtime.js +7 -2
  64. package/server/lib/agent-memory/runtime.test.js +22 -0
  65. package/server/lib/event-stream/DOCUMENTATION.md +3 -0
  66. package/server/lib/event-stream/global-hub.js +29 -4
  67. package/server/lib/event-stream/global-hub.test.js +22 -0
  68. package/server/lib/event-stream/global-ws-bridge.js +15 -18
  69. package/server/lib/event-stream/protocol.js +21 -7
  70. package/server/lib/event-stream/runtime.js +9 -6
  71. package/server/lib/event-stream/runtime.test.js +60 -0
  72. package/server/lib/git/DOCUMENTATION.md +10 -1
  73. package/server/lib/git/routes.js +21 -8
  74. package/server/lib/git/routes.test.js +78 -0
  75. package/server/lib/git/service.js +159 -4
  76. package/server/lib/git/service.test.js +74 -0
  77. package/server/lib/github/DOCUMENTATION.md +5 -0
  78. package/server/lib/github/routes.js +2 -2
  79. package/server/lib/message-queue/DOCUMENTATION.md +7 -0
  80. package/server/lib/message-queue/runtime.js +13 -0
  81. package/server/lib/message-queue/runtime.test.js +31 -1
  82. package/server/lib/notifications/DOCUMENTATION.md +1 -1
  83. package/server/lib/notifications/emitter-runtime.js +4 -3
  84. package/server/lib/opencode/DOCUMENTATION.md +18 -4
  85. package/server/lib/opencode/env-runtime.js +5 -1
  86. package/server/lib/opencode/env-runtime.test.js +72 -0
  87. package/server/lib/opencode/feature-routes-runtime.js +15 -1
  88. package/server/lib/opencode/lifecycle.js +4 -3
  89. package/server/lib/opencode/lifecycle.test.js +29 -0
  90. package/server/lib/opencode/managed-plugin-config.js +1 -1
  91. package/server/lib/opencode/proxy.js +33 -0
  92. package/server/lib/opencode/settings-helpers.js +3 -0
  93. package/server/lib/opencode/settings-helpers.test.js +11 -1
  94. package/server/lib/opencode/settings-registry.json +3 -0
  95. package/server/lib/opencode/settings-runtime.js +36 -9
  96. package/server/lib/opencode/settings-runtime.test.js +158 -2
  97. package/server/lib/project-context/DOCUMENTATION.md +13 -3
  98. package/server/lib/project-context/runtime.js +8 -2
  99. package/server/lib/project-context/runtime.test.js +54 -0
  100. package/server/lib/projects/DOCUMENTATION.md +2 -1
  101. package/server/lib/projects/project-config.js +38 -9
  102. package/server/lib/projects/project-config.test.js +97 -0
  103. package/server/lib/projects/project-id.js +26 -0
  104. package/server/lib/relay/DOCUMENTATION.md +20 -0
  105. package/server/lib/relay/host-client.js +7 -0
  106. package/server/lib/relay/host-client.test.js +14 -0
  107. package/server/lib/scheduled-tasks/DOCUMENTATION.md +9 -1
  108. package/server/lib/scheduled-tasks/issue-2710-double-execution.test.js +28 -0
  109. package/server/lib/scheduled-tasks/runtime.js +12 -2
  110. package/server/lib/scheduled-tasks/runtime.test.js +53 -0
  111. package/server/lib/session-assist/DOCUMENTATION.md +131 -66
  112. package/server/lib/session-assist/context.js +127 -0
  113. package/server/lib/session-assist/context.test.js +132 -0
  114. package/server/lib/session-assist/prompt.js +54 -0
  115. package/server/lib/session-assist/runtime.js +111 -257
  116. package/server/lib/session-assist/runtime.test.js +203 -0
  117. package/server/lib/walkthrough/DOCUMENTATION.md +15 -5
  118. package/server/lib/walkthrough/pr-source.test.js +21 -0
  119. package/server/lib/walkthrough/pull-request.js +7 -4
  120. package/server/lib/walkthrough/pull-request.test.js +16 -0
  121. package/server/lib/walkthrough/routes.js +19 -0
  122. package/server/lib/walkthrough/routes.test.js +26 -0
  123. package/server/lib/walkthrough/sources.js +13 -2
  124. package/server/opencode-worktree-readiness.test.js +130 -0
  125. package/dist/assets/DiffView-DXjVsEOw.js +0 -4
  126. package/dist/assets/FilesView-CJdG0-wk.js +0 -17
  127. package/dist/assets/PlanView-CJTmOF6I.js +0 -5
  128. package/dist/assets/SettingsView-DD-JqIJx.js +0 -28
  129. package/dist/assets/WalkthroughView-DeKMvZlL.js +0 -4
  130. package/dist/assets/de-DCrsQ5zS.js +0 -10
  131. package/dist/assets/es-Dwv4YfH6.js +0 -16
  132. package/dist/assets/fr-BCWg4Cnx.js +0 -14
  133. package/dist/assets/index-B68h5S5B.css +0 -1
  134. package/dist/assets/index-DVwMarHI.js +0 -39
  135. package/dist/assets/ja-Bruw3RYC.js +0 -16
  136. package/dist/assets/main-BkyaQhJX.js +0 -930
  137. package/dist/assets/patchFileDiff-Csk4iNUi.js +0 -13
  138. package/dist/assets/pt-BR-B8V7u7tA.js +0 -16
  139. package/dist/assets/renderElectronMiniChatApp-BxoyujA5.js +0 -2
  140. package/dist/assets/renderMobileApp-B48CsP4r.js +0 -25
  141. package/dist/assets/runtimeEndpointReset-Bg5gx18H.js +0 -17
  142. package/dist/assets/scheduledTasksApi-BW0Etzwz.js +0 -1
  143. package/dist/assets/surface-oMvhsog3.js +0 -1
  144. package/dist/assets/tr-BK_KiO2V.js +0 -7
  145. package/dist/assets/uk-CG74xV8N.js +0 -16
  146. package/dist/assets/useGitComparison-DH220WmO.js +0 -1
  147. package/dist/assets/vendor-legendapp-list-gg7YLRW7.js +0 -1
  148. package/dist/assets/zh-CN-T4AXofZI.js +0 -16
  149. package/dist/assets/zh-TW-Dte40sxp.js +0 -16
  150. package/server/lib/mcp-reconnect/DOCUMENTATION.md +0 -55
  151. package/server/lib/mcp-reconnect/runtime.js +0 -122
  152. package/server/lib/mcp-reconnect/runtime.test.js +0 -140
@@ -1,28 +0,0 @@
1
- import{R as o,j as s,f as ut,r as $e}from"./vendor-react-BUCujlKS.js";import{f as tt,B,I as F,o as Pn,bb as wa,t as E,O as mc,fS as gc,ey as ze,fT as Tt,b as Ws,h as fe,at as hc,ap as on,ar as ln,as as fc,ao as cn,eo as Hn,fU as fl,fV as xc,fW as ma,fX as un,bR as vs,bL as Kt,bM as zt,bN as _t,bO as $t,bP as Vt,bQ as ts,T as He,fY as _a,b9 as dn,eb as lr,fZ as vc,f_ as zn,eD as Jt,f$ as Ys,l as Ye,eR as Rt,b_ as St,b$ as Ct,eO as Ft,c0 as Mt,c1 as It,c2 as at,g0 as qt,c3 as Ts,dz as Fa,eQ as In,eT as xa,eS as rn,g1 as Cs,dE as xs,g2 as Ps,g3 as yc,cu as dt,g4 as xl,g5 as bc,g6 as $n,g7 as vl,g8 as wc,g9 as va,fr as Hs,ga as ha,gb as yl,gc as wr,dA as bl,gd as Vn,a6 as ya,a5 as Ks,ge as wl,gf as Kr,ab as jc,e9 as jl,g as Ka,gg as kc,gh as Zs,e8 as Nc,gi as Sc,gj as Cc,gk as jr,a7 as kr,a8 as Nr,a9 as kl,gl as hn,a1 as ki,bm as Sr,N as Cr,gm as zr,au as Ic,c4 as Pc,cK as Ac,R as Tc,Q as Ec,S as Dc,W as Nl,gn as Mc,go as Rc,bX as Lc,c5 as cr,gp as Sl,aa as xi,gq as Cl,P as Un,gr as Qs,ex as zs,eh as Il,a0 as Oc,n as Zt,e3 as Ni,x as Pl,w as Fc,i as Kc,j as zc,e4 as Uc,p as _c,gs as $c,gt as Vc,gu as Ur,dF as Al,gv as Bc,gw as Hi,gx as _r,gy as Hc,gz as Wc,gA as Gc,gB as qc,dL as Si,gC as fs,gD as Ss,gE as Js,gF as Bs,aB as Cn,aC as oa,gG as Sn,eN as bn,gH as ba,gI as $r,gJ as la,gK as ca,bI as Wn,gL as Jc,gM as Qc,gN as Yc,gO as Zc,gP as Wi,gQ as Vr,gR as Xc,gS as ed,gT as td,gU as sd,gV as Br,y as nd,m as Hr,cY as ad,gW as id,gX as Gi,gY as Wr,e6 as rd,gZ as Ii,g_ as od,g$ as ld,h0 as cd,h1 as dd,h2 as ud,h3 as qi,cv as pd,bJ as Tl,h4 as El,h5 as md,ax as wn,ay as gd}from"./useAppFontEffects-CPKeOpUo.js";import{h as yt,u as ie,K as cs,d8 as hd,d9 as Gr,A as fn,aB as pn,q as pt,a2 as fd,D as as,Q as qr,cq as Jr,cx as Qr,V as Ia,p as xd,da as vd,k as yd,cp as ua,db as bd,ak as wd,cu as jd,dc as kd,dd as Nd,s as Sd,e as $a,cv as Cd,E as Va,de as Dl,$ as Id,df as Pd,v as fa,aA as ga,c_ as Ad,_ as Td,aJ as Yr,aZ as ai,aK as Ed,dg as Dd,aa as Bn,dh as Md,z as Ml,di as Zr,d7 as Xr,dj as eo,aH as to,dk as Rd,dl as Ld,dm as Od,dn as Fd,dp as so,b as Kd,aE as Rl,dq as Ll,dr as zd,ds as Ud,dt as _d,du as $d,dv as Vd,dw as Bd,av as Hd,i as Ol}from"./index-DVwMarHI.js";import{u as Wd,U as no,J as Gn,L as qn,M as Jn,Q as Qn,e as Ir,F as An,H as Tn,G as En,a5 as _n,W as Gd,l as As,a3 as qd,a6 as pa,a7 as Fl,R as Jd,V as Qd}from"./runtimeEndpointReset-Bg5gx18H.js";import{u as Us,c as Kl,d as Yd,p as Zd}from"./vendor-zustand-BAGL70zf.js";import{o as Xd,s as ao,b as eu}from"./vendor-zod-BPAANqvH.js";import{s as tu,p as su}from"./vendor-yaml-3778uTud.js";import{c as io,s as nu,C as ro,P as au}from"./shikiHighlight-CRl0SUC9.js";import{getResolvedShikiTheme as iu}from"./appThemeRegistry-BK0dHKa6.js";import{E as oo}from"./vendor-codemirror-view-CiLROUVV.js";import{Q as zl}from"./vendor-qrcode-DTJ12-WC.js";const lo=()=>{const{t}=tt(),[e,a]=o.useState(null);o.useEffect(()=>{let r=!1;const i=typeof AbortController<"u"?new AbortController:void 0;return(async()=>{try{const g=await yt("/api/system/info",{signal:i?.signal,headers:{Accept:"application/json"}});if(!g.ok)return;const c=await g.json().catch(()=>null);if(!c||r)return;const y=typeof c.port=="number"&&Number.isFinite(c.port)&&c.port>0?c.port:null,p=typeof c.tunnelUrl=="string"&&c.tunnelUrl.trim().length>0?c.tunnelUrl.trim():null;a({port:y,tunnelUrl:p})}catch{}})(),()=>{r=!0,i?.abort()}},[]);const n=[];return e?.port!==null&&e?.port!==void 0&&n.push({key:"application",label:t("settings.aiworker.about.field.applicationUrl"),url:`http://localhost:${e.port}/`}),e?.tunnelUrl&&n.push({key:"tunnel",label:t("settings.aiworker.about.field.tunnelUrl"),url:e.tunnelUrl}),n.length===0?null:s.jsx("div",{className:"flex flex-wrap items-center gap-2",children:n.map(r=>s.jsxs(B,{type:"button",variant:"outline",size:"sm",title:r.label,className:"max-w-full gap-1.5 px-2.5",onClick:()=>{Pn(r.url)},children:[s.jsx(F,{name:"external-link",className:"size-3.5 shrink-0"}),s.jsx("span",{className:"max-w-64 truncate font-mono typography-micro",children:r.url})]},r.key))})},co="https://roweb.cn/roweb/openchamber",ru="https://discord.gg/ZYRSdnwwKA",uo="https://x.com/openchamber_dev",ou=800,Ul=({initialUpdateDialogOpen:t=!1})=>{const{t:e}=tt(),[a,n]=o.useState(t),[r,i]=o.useState(!1),[l,g]=o.useState(null),[c,y]=o.useState(null),p=Wd(Us(P=>({info:P.info,checking:P.checking,available:P.available,error:P.error,downloading:P.downloading,downloaded:P.downloaded,progress:P.progress,runtimeType:P.runtimeType,checkForUpdates:P.checkForUpdates,downloadUpdate:P.downloadUpdate,restartToUpdate:P.restartToUpdate}))),{isMobile:b}=wa(),d=l||p.info?.currentVersion||"unknown";o.useEffect(()=>{let P=!1;return(async()=>{try{const N=await yt("/api/system/info",{method:"GET",headers:{Accept:"application/json"}});if(!N.ok)return;const m=await N.json().catch(()=>null),A=typeof m?.aiworkerVersion=="string"&&m.aiworkerVersion.trim().length>0?m.aiworkerVersion.trim():null;P||g(A)}catch{P||g(null)}})(),()=>{P=!0}},[]),o.useEffect(()=>{let P=!1;return(async()=>{try{const N=await yt("/api/opencode/upgrade-status",{method:"GET",headers:{Accept:"application/json"}});if(!N.ok)return;const m=await N.json().catch(()=>null),A=typeof m?.currentVersion=="string"&&m.currentVersion.trim().length>0?m.currentVersion.trim():null;P||y(A)}catch{P||y(null)}})(),()=>{P=!0}},[]);const C=o.useRef(!1);o.useEffect(()=>{if(p.checking)i(!0),C.current=!0;else if(r){const P=setTimeout(()=>{i(!1),C.current&&!p.available&&!p.error&&(E.success(e("settings.aiworker.about.toast.latestVersion")),C.current=!1)},ou);return()=>clearTimeout(P)}},[e,p.checking,r,p.available,p.error]);const f=p.checking||r;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(mc,{width:72,height:72}),s.jsx("h2",{className:`mt-4 ${gc}`,children:"AiWorker"}),s.jsxs("div",{className:"mt-2 space-y-1 typography-ui text-muted-foreground",children:[s.jsx("p",{children:e("aboutDialog.openChamberVersionLabel",{version:d})}),s.jsx("p",{children:e("aboutDialog.openCodeVersionLabel",{version:c||e("settings.aiworker.about.state.unknown")})})]}),s.jsx(lo,{})]}),s.jsxs("div",{className:"flex justify-center",children:[!p.available&&!p.error&&s.jsxs(B,{type:"button",variant:"outline",size:"sm",onClick:()=>p.checkForUpdates(),disabled:f,className:"h-10 w-auto justify-center gap-2 rounded-xl px-4",children:[f?s.jsx(F,{name:"loader",className:"size-4 animate-spin"}):s.jsx(F,{name:"refresh",className:"size-4"}),e(f?"settings.aiworker.about.state.checking":"settings.aiworker.about.actions.checkForUpdates")]}),!f&&p.available&&s.jsxs(B,{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(F,{name:"download",className:"size-4"}),e("settings.aiworker.about.actions.updateToVersion",{version:p.info?.version||""})]})]}),p.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:p.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:co,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(F,{name:"github-fill",className:"size-5"}),s.jsx("span",{children:"GitHub"})]}),s.jsxs("a",{href:ru,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(F,{name:"discord-fill",className:"size-5"}),s.jsx("span",{children:"Discord"})]})]}),s.jsxs("a",{href:uo,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(F,{name:"twitter-xfill",className:"size-5"}),s.jsx("span",{children:"@aiworker_dev"})]})]}),s.jsx("p",{className:"text-center typography-ui text-muted-foreground/60",children:e("aboutDialog.footerNote")}),s.jsx(no,{open:a,onOpenChange:n,info:p.info,downloading:p.downloading,downloaded:p.downloaded,progress:p.progress,error:p.error,onDownload:p.downloadUpdate,onRestart:p.restartToUpdate,runtimeType:p.runtimeType})]}):s.jsxs(ze,{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:Tt,children:e("settings.aiworker.about.field.version")}),s.jsx("span",{className:"typography-meta text-muted-foreground font-mono",children:d})]}),s.jsxs("div",{className:"flex min-w-0 flex-col",children:[s.jsx("span",{className:Tt,children:e("settings.aiworker.about.field.openCodeVersion")}),s.jsx("span",{className:"typography-meta text-muted-foreground font-mono",children:c||e("settings.aiworker.about.state.unknown")})]}),s.jsxs("div",{className:"flex items-center gap-3",children:[p.checking&&s.jsxs("div",{className:"flex items-center gap-2 text-muted-foreground",children:[s.jsx(F,{name:"loader",className:"h-4 w-4 animate-spin"}),s.jsx("span",{className:"typography-meta",children:e("settings.aiworker.about.state.checking")})]}),!p.checking&&p.available&&s.jsxs(B,{size:"sm",variant:"default",onClick:()=>n(!0),children:[s.jsx(F,{name:"download",className:"h-4 w-4 mr-1"}),e("settings.aiworker.about.actions.updateToVersion",{version:p.info?.version||""})]}),!p.checking&&!p.available&&!p.error&&s.jsx("span",{className:"typography-meta text-muted-foreground",children:e("settings.aiworker.about.state.upToDate")}),s.jsx(B,{size:"sm",variant:"outline",onClick:()=>p.checkForUpdates(),disabled:p.checking,children:e("settings.aiworker.about.actions.checkForUpdates")})]})]}),p.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:p.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:Tt,children:e("settings.aiworker.about.field.instanceUrls")}),s.jsx(lo,{})]}),s.jsxs("div",{className:"flex items-center gap-4 px-4 py-4",children:[s.jsxs("a",{href:co,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(F,{name:"github-fill",className:"h-4 w-4"}),s.jsx("span",{children:"GitHub"})]}),s.jsxs("a",{href:uo,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(F,{name:"twitter-xfill",className:"h-4 w-4"}),s.jsx("span",{children:"@aiworker_dev"})]})]})]}),s.jsx(no,{open:a,onOpenChange:n,info:p.info,downloading:p.downloading,downloaded:p.downloaded,progress:p.progress,error:p.error,onDownload:p.downloadUpdate,onRestart:p.restartToUpdate,runtimeType:p.runtimeType})]})},lu=(t,e,a)=>t&&e.some(r=>r.path===t)?t:(e.find(r=>r.id===a)??e[0])?.path??null,_s=()=>{const t=ut.c(4),e=ie(cu),a=Ws(du),n=Ws(uu);let r;return t[0]!==n||t[1]!==a||t[2]!==e?(r=lu(e,a,n),t[0]=n,t[1]=a,t[2]=e,t[3]=r):r=t[3],r};function cu(t){return t.settingsProjectPath}function du(t){return t.projects}function uu(t){return t.activeProjectId}const _l=t=>t.trim(),Ba=t=>{const e=ut.c(40),{className:a}=t,{t:n}=tt(),r=Ws(pu),i=_s(),l=ie(mu),g=cs();let c;e[0]!==r?(c=[...r].sort(gu),e[0]=r,e[1]=c):c=e[1];const y=c;let p;e:{if(y.length===0){p=null;break e}let $;e[2]!==i||e[3]!==y?($=y.find(k=>k.path===i)??y[0],e[2]=i,e[3]=y,e[4]=$):$=e[4],p=$}const b=p;if(g||y.length===0)return null;let d;e[5]!==b||e[6]!==n?(d=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]=d):d=e[7];const C=d;let f;e[8]!==C?(f=_l(C),e[8]=C,e[9]=f):f=e[9];const P=f;let x;e[10]!==a?(x=fe(a),e[10]=a,e[11]=x):x=e[11];let N;e[12]!==n?(N=n("settings.shared.projectSelector.switchProjectAria"),e[12]=n,e[13]=N):N=e[13];let m;e[14]!==n?(m=n("settings.shared.projectSelector.switchProjectTitle"),e[14]=n,e[15]=m):m=e[15];let A,R;e[16]===Symbol.for("react.memo_cache_sentinel")?(A=fe("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"),R=s.jsx(F,{name:"folder",className:"h-4 w-4 opacity-70"}),e[16]=A,e[17]=R):(A=e[16],R=e[17]);let I;e[18]!==P?(I=s.jsx("span",{className:"min-w-0 flex-1 truncate typography-ui-label font-medium",children:P}),e[18]=P,e[19]=I):I=e[19];let j;e[20]===Symbol.for("react.memo_cache_sentinel")?(j=s.jsx(F,{name:"arrow-down-s",className:"size-4 opacity-50"}),e[20]=j):j=e[20];let h;e[21]!==I||e[22]!==N||e[23]!==m?(h=s.jsx(on,{asChild:!0,children:s.jsxs("button",{type:"button","aria-label":N,title:m,className:A,children:[R,I,j]})}),e[21]=I,e[22]=N,e[23]=m,e[24]=h):h=e[24];const w=b?.id??"";let O;e[25]!==l||e[26]!==y?(O=$=>{if(!$)return;const k=y.find(W=>W.id===$);k&&l(k.path)},e[25]=l,e[26]=y,e[27]=O):O=e[27];let T;e[28]!==y?(T=y.map(hu),e[28]=y,e[29]=T):T=e[29];let S;e[30]!==w||e[31]!==O||e[32]!==T?(S=s.jsx(ln,{align:"start",className:"w-auto",children:s.jsx(fc,{value:w,onValueChange:O,children:T})}),e[30]=w,e[31]=O,e[32]=T,e[33]=S):S=e[33];let M;e[34]!==h||e[35]!==S?(M=s.jsxs(cn,{children:[h,S]}),e[34]=h,e[35]=S,e[36]=M):M=e[36];let V;return e[37]!==M||e[38]!==x?(V=s.jsx("div",{className:x,children:M}),e[37]=M,e[38]=x,e[39]=V):V=e[39],V};function pu(t){return t.projects}function mu(t){return t.setSettingsProjectPath}function gu(t,e){return(t.label||t.path).localeCompare(e.label||e.path)}function hu(t){const e=t.label?.trim()?t.label.trim():t.path.split("/").filter(Boolean).pop()||t.path,a=_l(e);return s.jsx(hc,{value:t.id,children:s.jsx("span",{className:"min-w-0 truncate typography-ui",children:a})},t.id)}function fu(t,e){return`opencode:sidebar-group:${t}:${e}`}const dr=t=>{const e=ut.c(33),{label:a,count:n,storageKey:r,defaultExpanded:i,children:l}=t,g=i===void 0?!0:i;let c;e[0]!==a||e[1]!==r?(c=fu(r,a),e[0]=a,e[1]=r,e[2]=c):c=e[2];const y=c,p=o.useId();let b;e[3]!==g||e[4]!==y?(b=()=>{try{const S=localStorage.getItem(y);if(S!==null)return S==="true"}catch{}return g},e[3]=g,e[4]=y,e[5]=b):b=e[5];const[d,C]=$e.useState(b);let f,P;e[6]!==d||e[7]!==y?(f=()=>{try{localStorage.setItem(y,String(d))}catch{}},P=[y,d],e[6]=d,e[7]=y,e[8]=f,e[9]=P):(f=e[8],P=e[9]),$e.useEffect(f,P);let x;e[10]===Symbol.for("react.memo_cache_sentinel")?(x=()=>C(xu),e[10]=x):x=e[10];let N;e[11]===Symbol.for("react.memo_cache_sentinel")?(N=fe("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]=N):N=e[11];const m=!d&&"-rotate-90";let A;e[12]!==m?(A=fe("h-3.5 w-3.5 flex-shrink-0 transition-transform duration-200",m),e[12]=m,e[13]=A):A=e[13];let R;e[14]!==A?(R=s.jsx(F,{name:"arrow-down-s",className:A}),e[14]=A,e[15]=R):R=e[15];let I;e[16]!==a?(I=s.jsx("span",{className:"flex-1 truncate",children:a}),e[16]=a,e[17]=I):I=e[17];let j;e[18]!==n?(j=s.jsx("span",{className:"ml-1 tabular-nums opacity-60",children:n}),e[18]=n,e[19]=j):j=e[19];let h;e[20]!==p||e[21]!==d||e[22]!==R||e[23]!==I||e[24]!==j?(h=s.jsxs("button",{type:"button",onClick:x,"aria-expanded":d,"aria-controls":p,className:N,children:[R,I,j]}),e[20]=p,e[21]=d,e[22]=R,e[23]=I,e[24]=j,e[25]=h):h=e[25];const w=!d;let O;e[26]!==l||e[27]!==p||e[28]!==w?(O=s.jsx("div",{id:p,hidden:w,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]=p,e[28]=w,e[29]=O):O=e[29];let T;return e[30]!==h||e[31]!==O?(T=s.jsxs("div",{children:[h,O]}),e[30]=h,e[31]=O,e[32]=T):T=e[32],T};function xu(t){return!t}const vu=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},yu=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())},po=t=>{const e=yu(vu(t));if(e.length===0)return;const a={};for(const r of e)r.permission&&((a[r.permission]||={})[r.pattern]=r.action);const n={};for(const[r,i]of Object.entries(a)){const l=Object.keys(i);if(l.length===1&&l[0]==="*"){n[r]=i["*"];continue}n[r]=i}return Object.keys(n).length>0?n:void 0},bu=({onItemSelect:t})=>{const{t:e}=tt(),[a,n]=o.useState(null),[r,i]=o.useState(""),[l,g]=o.useState(null),[c,y]=o.useState(null),[p,b]=o.useState(!1),[d,C]=o.useState(null),{selectedAgentName:f,setSelectedAgent:P,setAgentDraft:x,createAgent:N,deleteAgent:m,loadAgents:A}=Hn(Us(U=>({selectedAgentName:U.selectedAgentName,setSelectedAgent:U.setSelectedAgent,setAgentDraft:U.setAgentDraft,createAgent:U.createAgent,deleteAgent:U.deleteAgent,loadAgents:U.loadAgents}))),R=_s(),I=Hn(U=>fl(U,R));o.useEffect(()=>{A(R)},[A,R]);const j="bg-background",h=()=>{const U="new-agent";let re=U,_=1;for(;I.some(H=>H.name===re);)re=`${U}-${_}`,_++;x({name:re,scope:"user"}),P(re),t?.()},w=async U=>{if(ma(U)){E.error(e("settings.agents.sidebar.toast.builtInCannotDelete"));return}g(U),y("delete")},O=async U=>{ma(U)&&(g(U),y("reset"))},T=()=>{g(null),y(null)},S=async()=>{if(!(!l||!c)){b(!0);try{const U=await m(l.name,l.scope,R);U.ok?(U.requiresManualRestart?E.warning(e("settings.agents.page.toast.savedManualRestart")):U.restartDeferred?E.success(e("settings.view.pendingRestart.saved")):c==="delete"?E.success(e("settings.agents.sidebar.toast.agentDeleted",{name:l.name})):E.success(e("settings.agents.sidebar.toast.agentReset",{name:l.name})),T()):c==="delete"?E.error(e("settings.agents.sidebar.toast.deleteFailed")):E.error(e("settings.agents.sidebar.toast.resetFailed"))}catch(U){const re=U instanceof Error?U.message:"",_=/built-in|not deletable|not found/i.test(re);c==="delete"?E.error(e(_?"settings.agents.sidebar.toast.definitionNotFound":"settings.agents.sidebar.toast.deleteFailed")):E.error(e("settings.agents.sidebar.toast.resetFailed"))}b(!1)}},M=U=>{const re=U.name;let _=1,H=`${re}-copy`;for(;I.some(Y=>Y.name===H);)_++,H=`${re}-copy-${_}`;const z=U,K=U.model?.providerID&&U.model?.modelID?`${U.model.providerID}/${U.model.modelID}`:null,te=U;x({name:H,scope:z.scope||"user",description:U.description,model:K,variant:U.variant,temperature:U.temperature,top_p:U.topP,prompt:U.prompt,mode:U.mode,permission:po(U.permission),disable:te.disable}),P(H),t?.()},V=U=>{i(U.name),n(U)},$=async()=>{if(!a)return;const U=r.trim().replace(/\s+/g,"-");if(!U){E.error(e("settings.agents.sidebar.toast.agentNameRequired"));return}if(U===a.name){n(null);return}if(I.some(z=>z.name===U)){E.error(e("settings.agents.sidebar.toast.agentExists"));return}const re=a.model?.providerID&&a.model?.modelID?`${a.model.providerID}/${a.model.modelID}`:null,_=a,H=await N({name:U,description:a.description,model:re,variant:a.variant,temperature:a.temperature,top_p:a.topP,prompt:a.prompt,mode:a.mode,permission:po(a.permission),disable:_.disable,scope:_.scope},R);if(H.ok){const z=await m(a.name,_.scope,R);z.ok?(H.requiresManualRestart||z.requiresManualRestart?E.warning(e("settings.agents.page.toast.savedManualRestart")):E.success(e("settings.agents.sidebar.toast.agentRenamed",{name:U})),P(U)):E.error(e("settings.agents.sidebar.toast.removeOldAfterRenameFailed"))}else E.error(e("settings.agents.sidebar.toast.renameFailed"));n(null)},k=U=>{switch(U){case"primary":return s.jsx(F,{name:"ai-agent",className:"h-3 w-3 text-primary"});case"all":return s.jsx(F,{name:"ai-agent-fill",className:"h-3 w-3 text-primary"});case"subagent":return s.jsx(F,{name:"robot",className:"h-3 w-3 text-primary"});default:return null}},W=I.filter(U=>!xc(U)),D=W.filter(ma),L=W.filter(U=>!ma(U)),{groupedCustomAgents:J,ungroupedCustomAgents:ee}=$e.useMemo(()=>{const U={},re=[];for(const H of L){const z=H;z.group?(U[z.group]||(U[z.group]=[]),U[z.group].push(H)):re.push(H)}return{groupedCustomAgents:Object.keys(U).sort((H,z)=>H.localeCompare(z)).map(H=>({name:H,agents:U[H]})),ungroupedCustomAgents:re}},[L]);return s.jsxs("div",{className:fe("flex h-full flex-col",j),children:[s.jsxs("div",{className:"border-b px-3 pt-4 pb-3",children:[s.jsx("h2",{className:`${un} mb-3`,children:e("settings.agents.sidebar.title")}),s.jsx(Ba,{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(B,{size:"sm","data-settings-item":"agents.create",variant:"ghost",className:"h-7 w-7 px-0 -my-1 text-muted-foreground",onClick:h,children:s.jsx(F,{name:"add",className:"h-3.5 w-3.5"})})]})]}),s.jsx(vs,{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(F,{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:[D.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")}),D.map(U=>s.jsx(Ji,{agent:U,isSelected:f===U.name,onSelect:()=>{P(U.name),t?.()},onReset:()=>O(U),onDuplicate:()=>M(U),getAgentModeIcon:k,isMenuOpen:d===U.name,onMenuOpenChange:re=>C(re?U.name:null)},U.name))]}),L.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")}),J.map(({name:U,agents:re})=>s.jsx(dr,{label:U,count:re.length,storageKey:"agents",children:re.map(_=>s.jsx(Ji,{agent:_,isSelected:f===_.name,onSelect:()=>{P(_.name),t?.()},onRename:()=>V(_),onDelete:()=>w(_),onDuplicate:()=>M(_),getAgentModeIcon:k,isMenuOpen:d===_.name,onMenuOpenChange:H=>C(H?_.name:null)},_.name))},U)),ee.map(U=>s.jsx(Ji,{agent:U,isSelected:f===U.name,onSelect:()=>{P(U.name),t?.()},onRename:()=>V(U),onDelete:()=>w(U),onDuplicate:()=>M(U),getAgentModeIcon:k,isMenuOpen:d===U.name,onMenuOpenChange:re=>C(re?U.name:null)},U.name))]})]})}),s.jsx(Kt,{open:l!==null&&c!==null,onOpenChange:U=>{!U&&!p&&T()},children:s.jsxs(zt,{className:"max-w-md",children:[s.jsxs(_t,{children:[s.jsx($t,{children:e(c==="delete"?"settings.agents.sidebar.dialog.deleteTitle":"settings.agents.sidebar.dialog.resetTitle")}),s.jsx(Vt,{children:c==="delete"?e("settings.agents.sidebar.dialog.deleteDescription",{name:l?.name??""}):e("settings.agents.sidebar.dialog.resetDescription",{name:l?.name??""})})]}),s.jsxs(ts,{children:[s.jsx(B,{size:"sm",variant:"ghost",onClick:T,disabled:p,children:e("settings.common.actions.cancel")}),s.jsx(B,{size:"sm",onClick:S,disabled:p,children:e(c==="delete"?"settings.common.actions.delete":"settings.common.actions.reset")})]})]})}),s.jsx(Kt,{open:a!==null,onOpenChange:U=>!U&&n(null),children:s.jsxs(zt,{children:[s.jsxs(_t,{children:[s.jsx($t,{children:e("settings.agents.sidebar.renameDialog.title")}),s.jsx(Vt,{children:e("settings.agents.sidebar.renameDialog.description",{name:a?.name??""})})]}),s.jsx(He,{value:r,onChange:U=>i(U.target.value),placeholder:e("settings.agents.sidebar.renameDialog.placeholder"),className:"text-foreground placeholder:text-muted-foreground",onKeyDown:U=>{U.key==="Enter"&&$()}}),s.jsxs(ts,{children:[s.jsx(B,{size:"sm",variant:"ghost",onClick:()=>n(null),children:e("settings.common.actions.cancel")}),s.jsx(B,{size:"sm",onClick:$,children:e("settings.common.actions.rename")})]})]})})]})},Ji=t=>{const e=ut.c(52),{agent:a,isSelected:n,onSelect:r,onDelete:i,onReset:l,onRename:g,onDuplicate:c,getAgentModeIcon:y,isMenuOpen:p,onMenuOpenChange:b}=t,{t:d}=tt(),C=a;let f;e[0]===Symbol.for("react.memo_cache_sentinel")?(f=_a(),e[0]=f):f=e[0];const P=f,[x,N]=o.useState(!1);let m;e[1]!==i||e[2]!==c||e[3]!==g||e[4]!==l||e[5]!==d?(m=re=>s.jsxs(s.Fragment,{children:[g&&s.jsxs(re,{onClick:_=>{_.stopPropagation(),g()},children:[s.jsx(F,{name:"edit",className:"h-4 w-4 mr-px"}),d("settings.common.actions.rename")]}),s.jsxs(re,{onClick:_=>{_.stopPropagation(),c()},children:[s.jsx(F,{name:"file-copy",className:"h-4 w-4 mr-px"}),d("settings.common.actions.duplicate")]}),l&&s.jsxs(re,{onClick:_=>{_.stopPropagation(),l()},children:[s.jsx(F,{name:"restart",className:"h-4 w-4 mr-px"}),d("settings.common.actions.reset")]}),i&&s.jsxs(re,{onClick:_=>{_.stopPropagation(),i()},className:"text-destructive focus:text-destructive",children:[s.jsx(F,{name:"delete-bin",className:"h-4 w-4 mr-px"}),d("settings.common.actions.delete")]})]}),e[1]=i,e[2]=c,e[3]=g,e[4]=l,e[5]=d,e[6]=m):m=e[6];const A=m,R=n?"bg-interactive-selection":"hover:bg-interactive-hover";let I;e[7]!==R?(I=fe("group relative flex items-center rounded-md px-1.5 py-1 transition-all duration-200 select-none",R),e[7]=R,e[8]=I):I=e[8];let j;e[9]===Symbol.for("react.memo_cache_sentinel")?(j=P?void 0:re=>{re.preventDefault(),N(!0)},e[9]=j):j=e[9];let h;e[10]!==I?(h=s.jsx("div",{className:I,onContextMenu:j}),e[10]=I,e[11]=h):h=e[11];let w;e[12]!==a.name?(w=s.jsx("span",{className:"typography-ui-label font-normal truncate text-foreground",children:a.name}),e[12]=a.name,e[13]=w):w=e[13];let O;e[14]!==a.mode||e[15]!==y?(O=y(a.mode),e[14]=a.mode,e[15]=y,e[16]=O):O=e[16];let T;e[17]!==a||e[18]!==C.scope||e[19]!==d?(T=(C.scope||ma(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:ma(a)?d("settings.agents.sidebar.badge.system"):C.scope}),e[17]=a,e[18]=C.scope,e[19]=d,e[20]=T):T=e[20];let S;e[21]!==w||e[22]!==O||e[23]!==T?(S=s.jsxs("div",{className:"flex items-center gap-1.5",children:[w,O,T]}),e[21]=w,e[22]=O,e[23]=T,e[24]=S):S=e[24];let M;e[25]!==a.description?(M=a.description&&s.jsx("div",{className:"typography-micro text-muted-foreground/60 truncate leading-tight",children:a.description}),e[25]=a.description,e[26]=M):M=e[26];let V;e[27]!==r||e[28]!==S||e[29]!==M?(V=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:[S,M]}),e[27]=r,e[28]=S,e[29]=M,e[30]=V):V=e[30];let $;e[31]!==b?($=re=>{re&&N(!1),b(re)},e[31]=b,e[32]=$):$=e[32];let k;e[33]===Symbol.for("react.memo_cache_sentinel")?(k=s.jsx(on,{asChild:!0,children:s.jsx(B,{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(F,{name:"more-2",className:"h-3.5 w-3.5"})})}),e[33]=k):k=e[33];let W;e[34]!==A?(W=s.jsx(ln,{align:"end",className:"w-fit min-w-20",children:A(dn)}),e[34]=A,e[35]=W):W=e[35];let D;e[36]!==p||e[37]!==$||e[38]!==W?(D=s.jsxs(cn,{open:p,onOpenChange:$,children:[k,W]}),e[36]=p,e[37]=$,e[38]=W,e[39]=D):D=e[39];let L;e[40]!==V||e[41]!==D?(L=s.jsxs("div",{className:"flex min-w-0 flex-1 items-center",children:[V,D]}),e[40]=V,e[41]=D,e[42]=L):L=e[42];let J;e[43]!==L||e[44]!==h?(J=s.jsx(Jn,{render:h,children:L}),e[43]=L,e[44]=h,e[45]=J):J=e[45];let ee;e[46]!==A?(ee=s.jsx(Gn,{className:"w-fit min-w-20",children:A(qn)}),e[46]=A,e[47]=ee):ee=e[47];let U;return e[48]!==x||e[49]!==J||e[50]!==ee?(U=s.jsxs(Qn,{open:x,onOpenChange:N,children:[J,ee]}),e[48]=x,e[49]=J,e[50]=ee,e[51]=U):U=e[51],U},es=t=>{const e=ut.c(21),{children:a,className:n,outerClassName:r,title:i,titleLeading:l,titleAccessory:g,description:c,headerEnd:y,showSaveStatus:p}=t,b=p===void 0?!1:p,d=i!=null||c!=null||y!=null||b,C=typeof i=="string"||typeof i=="number",f=l!=null||g!=null;let P;e[0]!==r?(P=fe("h-full",r),e[0]=r,e[1]=P):P=e[1];let x;e[2]!==n?(x=fe("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]=x):x=e[3];let N;e[4]!==c||e[5]!==d||e[6]!==f||e[7]!==y||e[8]!==C||e[9]!==b||e[10]!==i||e[11]!==g||e[12]!==l?(N=d&&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:[i!=null?C?f?s.jsxs("div",{className:"flex min-w-0 items-center gap-2",children:[l,s.jsx("h1",{"data-settings-page-heading":!0,tabIndex:-1,className:fe(lr,"min-w-0 truncate"),children:i}),s.jsx("span",{className:"shrink-0",children:g})]}):s.jsx("h1",{"data-settings-page-heading":!0,tabIndex:-1,className:lr,children:i}):i:null,c!=null?typeof c=="string"||typeof c=="number"?s.jsx("p",{className:vc,children:c}):c:null]}),s.jsxs("div",{className:"flex shrink-0 flex-wrap items-center justify-end gap-3",children:[y,b&&s.jsx(ju,{})]})]}),e[4]=c,e[5]=d,e[6]=f,e[7]=y,e[8]=C,e[9]=b,e[10]=i,e[11]=g,e[12]=l,e[13]=N):N=e[13];let m;e[14]!==a||e[15]!==x||e[16]!==N?(m=s.jsxs("div",{className:x,children:[N,a]}),e[14]=a,e[15]=x,e[16]=N,e[17]=m):m=e[17];let A;return e[18]!==P||e[19]!==m?(A=s.jsx(vs,{outerClassName:P,className:"w-full @container",children:m}),e[18]=P,e[19]=m,e[20]=A):A=e[20],A},wu=500,ju=()=>{const t=ut.c(13),{t:e}=tt(),a=o.useSyncExternalStore(hd,Gr,Gr),[n,r]=o.useState(!1);let i,l;if(t[0]!==a?(i=()=>{if(a!=="saving"){r(!1);return}const p=setTimeout(()=>r(!0),wu);return()=>clearTimeout(p)},l=[a],t[0]=a,t[1]=i,t[2]=l):(i=t[1],l=t[2]),o.useEffect(i,l),a==="error"){let p;t[3]===Symbol.for("react.memo_cache_sentinel")?(p=s.jsx(F,{name:"error-warning",className:"size-3.5"}),t[3]=p):p=t[3];let b;t[4]!==e?(b=e("settings.common.status.saveFailed"),t[4]=e,t[5]=b):b=t[5];let d;return t[6]!==b?(d=s.jsxs("div",{"aria-live":"assertive",className:"flex shrink-0 items-center gap-1.5 typography-meta text-[var(--status-error)]",children:[p,s.jsx("span",{children:b})]}),t[6]=b,t[7]=d):d=t[7],d}if(a!=="saving"||!n)return null;let g;t[8]===Symbol.for("react.memo_cache_sentinel")?(g=s.jsx(F,{name:"loader-4",className:"size-3.5 animate-spin"}),t[8]=g):g=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:[g,s.jsx("span",{children:c})]}),t[11]=c,t[12]=y):y=t[12],y},ku=["allow","ask","deny"],Oa=t=>t==="allow"||t==="ask"||t==="deny",ur=()=>({global:null,keys:{}}),Nu=t=>{const e=ur();if(t==null)return e;if(typeof t=="string")return Oa(t)&&(e.global=t),e;if(typeof t!="object"||Array.isArray(t))return e;for(const[a,n]of Object.entries(t)){if(a==="*"){Oa(n)&&(e.global=n);continue}const r={action:null,patterns:[]};if(Oa(n))r.action=n;else if(n&&typeof n=="object"&&!Array.isArray(n))for(const[i,l]of Object.entries(n))Oa(l)&&(i==="*"?r.action=l:r.patterns.push({pattern:i,action:l}));else continue;e.keys[a]=r}return e},pr=t=>{const e={};t.global!==null&&(e["*"]=t.global);for(const[a,n]of Object.entries(t.keys)){const r=n.patterns.filter(i=>i.pattern.trim().length>0);if(n.action!==null&&r.length===0)e[a]=n.action;else if(r.length>0){const i={};n.action!==null&&(i["*"]=n.action);for(const l of r)i[l.pattern]=l.action;e[a]=i}}return Object.keys(e).length>0?e:null},Su=(t,e)=>JSON.stringify(pr(t))===JSON.stringify(pr(e)),jn=t=>JSON.parse(JSON.stringify(t)),Cu=["edit","external_directory","doom_loop","plan_enter","plan_exit"],Iu=new Set(["read","edit","glob","grep","list","bash","task","external_directory","lsp","skill"]),mo=new Set(["write","patch","apply_patch","multiedit","invalid"]),Pu=t=>t.split(/[_-]/).filter(Boolean).map(e=>e.charAt(0).toUpperCase()+e.slice(1)).join(" "),Au=({agent:t})=>{const{t:e}=tt(),a=Hn(z=>z.updateAgent),[n,r]=o.useState(ur),[i,l]=o.useState(ur),[g,c]=o.useState(!0),[y,p]=o.useState(!1),[b,d]=o.useState(!1),[C,f]=o.useState({}),[P,x]=o.useState([]),[N,m]=o.useState(""),[A,R]=o.useState(0),I=t.name,j=_s();o.useEffect(()=>{let z=!1;return c(!0),p(!1),(async()=>{try{const K=j,te=K?`?directory=${encodeURIComponent(K)}`:"",Y=await yt(`/api/config/agents/${encodeURIComponent(I)}/config${te}`,{headers:{"Cache-Control":"no-cache",...K?{"x-opencode-directory":K}:{}}});if(!Y.ok)throw new Error(String(Y.status));const ne=await Y.json().catch(()=>null);if(z)return;const me=Nu(ne?.config?.permission);r(jn(me)),l(me)}catch{z||p(!0)}finally{z||c(!1)}})(),()=>{z=!0}},[I,A,j]),o.useEffect(()=>{let z=!1;return(async()=>{try{const K=await fn.listToolIds({directory:j});!z&&Array.isArray(K)&&x(K.filter(te=>typeof te=="string"&&!mo.has(te)))}catch{}})(),()=>{z=!0}},[I,j]);const h=o.useMemo(()=>{const z=t.permission;if(!Array.isArray(z))return[];const K=[];for(const te of z){if(!te||typeof te!="object")continue;const{permission:Y,pattern:ne,action:me}=te;typeof Y=="string"&&typeof ne=="string"&&Oa(me)&&K.push({permission:Y,pattern:ne,action:me})}return K},[t]),w=o.useCallback(z=>{const K=h.find(Y=>Y.permission===z&&Y.pattern==="*");if(K)return K.action;const te=h.find(Y=>Y.permission==="*"&&Y.pattern==="*");return te?te.action:null},[h]),O=o.useCallback(z=>{const K=i.keys[z]?.patterns??[],te=new Set(K.map(Y=>Y.pattern));return h.filter(Y=>Y.permission===z&&Y.pattern!=="*"&&!te.has(Y.pattern))},[h,i.keys]),T=o.useMemo(()=>{const z=new Set;for(const K of P)z.add(K);for(const K of Cu)z.add(K);for(const K of Object.keys(i.keys))z.add(K);for(const K of mo)z.delete(K);return Array.from(z).sort((K,te)=>K.localeCompare(te))},[P,i.keys]),S=o.useMemo(()=>!Su(i,n),[i,n]),M=z=>{l(K=>({...K,global:z}))},V=(z,K)=>{l(te=>{const Y=jn(te),ne=Y.keys[z]??{action:null,patterns:[]};return ne.action=K,ne.action===null&&ne.patterns.length===0?delete Y.keys[z]:Y.keys[z]=ne,Y})},$=(z,K,te,Y)=>{l(ne=>{const me=jn(ne),de=me.keys[z]??{action:null,patterns:[]};return de.patterns[K]={pattern:te,action:Y},me.keys[z]=de,me})},k=z=>{l(K=>{const te=jn(K),Y=te.keys[z]??{action:null,patterns:[]};return Y.patterns.push({pattern:"",action:"allow"}),te.keys[z]=Y,te}),f(K=>({...K,[z]:!0}))},W=(z,K)=>{l(te=>{const Y=jn(te),ne=Y.keys[z];return ne?(ne.patterns.splice(K,1),ne.action===null&&ne.patterns.length===0&&delete Y.keys[z],Y):te})},D=()=>{const z=N.trim();!z||z==="*"||(l(K=>{if(K.keys[z])return K;const te=jn(K);return te.keys[z]={action:"ask",patterns:[]},te}),f(K=>({...K,[z]:!0})),m(""))},L=async()=>{d(!0);try{const z=pr(i),K=await a(I,{permission:z});K.ok?(r(jn(i)),E.success(K.requiresManualRestart?e("settings.agents.page.permissionsEditor.toast.savedRestartRequired"):e("settings.agents.page.permissionsEditor.toast.saved"))):E.error(e("settings.agents.page.permissionsEditor.toast.saveFailed"))}finally{d(!1)}},J=()=>{l(jn(n))},ee=z=>e(z==="allow"?"settings.agents.page.permissionsEditor.action.allow":z==="ask"?"settings.agents.page.permissionsEditor.action.ask":"settings.agents.page.permissionsEditor.action.deny"),U=e("settings.agents.page.permissionsEditor.action.inherit"),re=e("settings.agents.page.permissionsEditor.action.default"),_=z=>[...z?[{value:"inherit",label:z}]:[],...ku.map(K=>({value:K,label:ee(K)}))],H=(z,K,te,Y=U)=>s.jsx(Ys,{value:z??"inherit",options:_(Y),onChange:ne=>K(ne==="inherit"?null:ne),"aria-label":te});return g?s.jsx(ze,{title:e("settings.agents.page.section.toolPermissions"),children:s.jsx("p",{className:zn,children:e("common.loading")})}):y?s.jsx(ze,{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(B,{variant:"outline",size:"xs",onClick:()=>R(z=>z+1),children:e("settings.agents.page.permissionsEditor.actions.retry")})]})}):s.jsxs(ze,{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(B,{variant:"ghost",size:"xs",className:"!font-normal",onClick:J,disabled:b,children:e("settings.agents.page.permissionsEditor.actions.discard")}),s.jsx(B,{size:"xs",className:"!font-normal",onClick:()=>{L()},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:Tt,children:e("settings.agents.page.permissionsEditor.defaultLabel")}),s.jsx(Jt,{children:e("settings.agents.page.permissionsEditor.defaultInfo")}),i.global===null&&s.jsx("span",{className:"typography-micro text-muted-foreground",children:e("settings.agents.page.permissionsEditor.effectiveHint",{action:ee(w("*")??"allow")})})]}),H(i.global,M,e("settings.agents.page.permissionsEditor.defaultAria"),re)]}),s.jsx("div",{children:T.map(z=>{const K=i.keys[z]??{action:null,patterns:[]},te=O(z),Y=Iu.has(z)||K.patterns.length>0,ne=Y||te.length>0,me=C[z]===!0,de=w(z);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:ne?()=>f(xe=>({...xe,[z]:!me})):void 0,className:fe("flex min-w-0 items-center gap-1.5 text-left",!ne&&"cursor-default"),"aria-expanded":ne?me:void 0,children:[s.jsx(F,{name:me&&ne?"arrow-down-s":"arrow-right-s",className:fe("h-3.5 w-3.5 shrink-0 text-muted-foreground",!ne&&"opacity-0")}),s.jsx("span",{className:Tt,children:Pu(z)}),s.jsx("span",{className:"typography-micro font-mono text-muted-foreground/70",children:z}),K.action===null&&de!==null&&s.jsx("span",{className:"typography-micro text-muted-foreground",children:e("settings.agents.page.permissionsEditor.effectiveHint",{action:ee(de)})}),K.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(K.patterns.length)})})]}),H(K.action,xe=>V(z,xe),e("settings.agents.page.permissionsEditor.keyAria",{key:z}))]}),me&&ne&&s.jsxs("div",{className:"mt-2 space-y-2 pl-5",children:[K.patterns.map((xe,ae)=>s.jsxs("div",{className:"flex flex-wrap items-center gap-2",children:[s.jsx(He,{value:xe.pattern,onChange:le=>$(z,ae,le.target.value,xe.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(Ys,{value:xe.action,options:_(),onChange:le=>$(z,ae,xe.pattern,le),"aria-label":e("settings.agents.page.permissionsEditor.patternActionAria",{key:z})}),s.jsx(B,{variant:"ghost",size:"icon",className:"h-7 w-7 shrink-0 text-muted-foreground hover:bg-destructive/10 hover:text-destructive",onClick:()=>W(z,ae),"aria-label":e("settings.agents.page.permissionsEditor.actions.removeRuleAria"),children:s.jsx(F,{name:"close",className:"h-3.5 w-3.5"})})]},ae)),Y&&s.jsxs(B,{variant:"outline",size:"xs",className:"!font-normal",onClick:()=>k(z),children:[s.jsx(F,{name:"add",className:"mr-1 h-3.5 w-3.5"}),e("settings.agents.page.permissionsEditor.actions.addRule")]}),te.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(Jt,{children:e("settings.agents.page.permissionsEditor.sessionRulesInfo")})]}),te.map(xe=>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:xe.pattern}),s.jsx("span",{className:"typography-micro text-muted-foreground",children:ee(xe.action)})]},`${xe.pattern}-${xe.action}`))]})]})]},z)})}),s.jsxs("div",{className:"flex flex-wrap items-center gap-2 border-t border-border/40 pt-3",children:[s.jsx(He,{value:N,onChange:z=>m(z.target.value),onKeyDown:z=>{z.key==="Enter"&&(z.preventDefault(),D())},placeholder:e("settings.agents.page.permissionsEditor.customKeyPlaceholder"),className:"h-8 w-full max-w-[16rem] font-mono text-xs"}),s.jsxs(B,{variant:"outline",size:"xs",className:"!font-normal",onClick:D,disabled:!N.trim(),children:[s.jsx(F,{name:"add",className:"mr-1 h-3.5 w-3.5"}),e("settings.agents.page.permissionsEditor.actions.addKey")]})]})]})},Tu=(t,e)=>{const a=xa(e);if(!a)return[];const r=t.find(i=>i.id===a.providerId)?.models?.find(i=>i.id===a.modelId);return r?.variants?Object.keys(r.variants):[]},Eu=()=>{const{t}=tt(),e=Ye(H=>H.providers),{selectedAgentName:a,getAgentByName:n,createAgent:r,updateAgent:i,agentDraft:l,setAgentDraft:g}=Hn(Us(H=>({selectedAgentName:H.selectedAgentName,getAgentByName:H.getAgentByName,createAgent:H.createAgent,updateAgent:H.updateAgent,agentDraft:H.agentDraft,setAgentDraft:H.setAgentDraft}))),c=_s(),y=Hn(H=>fl(H,c)),p=a?n(a,c):null,b=!!(l&&l.name===a&&!p),[d,C]=o.useState(""),[f,P]=o.useState("user"),[x,N]=o.useState(""),[m,A]=o.useState("subagent"),[R,I]=o.useState(""),[j,h]=o.useState(""),[w,O]=o.useState(void 0),[T,S]=o.useState(void 0),[M,V]=o.useState(""),[$,k]=o.useState(!1),W=o.useRef(null),D=o.useMemo(()=>Tu(e,R),[R,e]),L=D.length>0,J=j||"__default",ee=L,U=o.useMemo(()=>j&&!D.includes(j)?[j,...D]:D,[j,D]);o.useEffect(()=>{if(b&&l){const H=l.name||"",z=l.scope||"user",K=l.description||"",te=l.mode||"subagent",Y=l.model||"",ne=l.variant||"",me=l.temperature??void 0,de=l.top_p??void 0,xe=l.prompt||"";C(H),P(z),N(K),A(te),I(Y),h(ne),O(me),S(de),V(xe),W.current={draftName:H,draftScope:z,description:K,mode:te,model:Y,variant:ne,temperature:me,topP:de,prompt:xe};return}if(p&&a===p.name){const H=p.description||"",z=p.mode||"subagent",K=p.model?.providerID&&p.model?.modelID?`${p.model.providerID}/${p.model.modelID}`:"",te=p.variant||"",Y=p.temperature??void 0,ne=p.topP??void 0,me=p.prompt||"";N(H),A(z),I(K),h(te),O(Y),S(ne),V(me),W.current={draftName:"",draftScope:"user",description:H,mode:z,model:K,variant:te,temperature:Y,topP:ne,prompt:me}}},[l,b,p,a]);const re=o.useMemo(()=>{const H=W.current;return H?!!(b&&(d!==H.draftName||f!==H.draftScope)||x!==H.description||m!==H.mode||R!==H.model||j!==H.variant||w!==H.temperature||T!==H.topP||M!==H.prompt):!1},[x,d,f,b,m,R,M,w,T,j]),_=async()=>{const H=b?d.trim().replace(/\s+/g,"-"):a?.trim();if(!H){E.error(t("settings.agents.sidebar.toast.agentNameRequired"));return}if(b&&y.some(z=>z.name===H)){E.error(t("settings.agents.sidebar.toast.agentExists"));return}k(!0);try{const z=R.trim(),K=j.trim(),te=M.trim(),Y={name:H,...x.trim()?{description:x.trim()}:{},mode:m,model:z===""?null:z,variant:K===""?null:K||void 0,temperature:w??null,top_p:T??null,prompt:te||(b?void 0:null),...b&&f?{scope:f}:{}};let ne;b?(ne=await r(Y,c),ne.ok&&g(null)):ne=await i(H,Y,c),ne.ok?ne.requiresManualRestart?E.warning(t("settings.agents.page.toast.savedManualRestart")):ne.restartDeferred?E.success(t("settings.view.pendingRestart.saved")):E.success(t(b?"settings.agents.page.toast.created":"settings.agents.page.toast.updated")):E.error(t(b?"settings.agents.page.toast.createFailed":"settings.agents.page.toast.updateFailed"))}catch(z){console.error("Error saving agent:",z);const K=z instanceof Error&&z.message?z.message:t("settings.agents.page.toast.saveUnexpectedError");E.error(K)}finally{k(!1)}};return a?s.jsxs(es,{title:b?t("settings.agents.page.title.new"):a,description:t(b?"settings.agents.page.subtitle.new":"settings.agents.page.subtitle.edit"),showSaveStatus:!1,children:[s.jsxs(ze,{title:t("settings.agents.page.section.identityRole"),divider:!1,contentClassName:"space-y-0",children:[b&&s.jsxs(Rt,{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:d,onChange:H=>C(H.target.value),placeholder:t("settings.agents.page.field.agentNamePlaceholder"),className:"h-7 w-40 px-2"})]}),s.jsxs(St,{value:f,onValueChange:H=>P(H),children:[s.jsx(Ct,{size:Ft,className:"w-fit min-w-[100px]",children:s.jsx(Mt,{placeholder:t("settings.agents.page.field.scopePlaceholder")})}),s.jsxs(It,{align:"end",children:[s.jsx(at,{value:"user",children:s.jsxs("div",{className:"flex items-center gap-2",children:[s.jsx(F,{name:"user-3",className:"h-3.5 w-3.5"}),s.jsx("span",{children:t("settings.common.scope.global")})]})}),s.jsx(at,{value:"project",children:s.jsxs("div",{className:"flex items-center gap-2",children:[s.jsx(F,{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(Ts,{value:x,onChange:H=>N(H.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(Ys,{"aria-label":t("settings.agents.page.field.mode"),value:m,onChange:A,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(ze,{title:t("settings.agents.page.section.modelParameters"),contentClassName:"space-y-3",children:[s.jsx(Rt,{settingsItem:"agents.model",label:t("settings.agents.page.field.overrideModel"),children:s.jsx(Fa,{providerId:xa(R)?.providerId??"",modelId:xa(R)?.modelId??"",onChange:(H,z)=>{I(H&&z?`${H}/${z}`:""),h("")},className:In})}),s.jsx(Rt,{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:ee?s.jsxs(St,{value:J,onValueChange:H=>h(H==="__default"?"":H),children:[s.jsx(Ct,{size:Ft,className:rn,children:s.jsx(Mt,{placeholder:t("settings.agents.page.field.variantPlaceholder"),children:H=>H==="__default"?t("chat.modelControls.default"):H})}),s.jsxs(It,{children:[s.jsx(at,{value:"__default",children:t("chat.modelControls.default")}),U.map(H=>s.jsx(at,{value:H,children:H},H))]})]}):s.jsxs(s.Fragment,{children:[s.jsx(He,{value:j,onChange:H=>h(H.target.value),placeholder:t("settings.agents.page.field.variantPlaceholder"),disabled:!R&&!j,className:"h-8 w-40 rounded-md px-3"}),j&&s.jsx(B,{size:"sm",type:"button",variant:"ghost",onClick:()=>h(""),className:Cs,"aria-label":t("settings.common.actions.clear"),title:t("settings.common.actions.clear"),children:s.jsx(F,{name:"close",className:"h-3.5 w-3.5"})})]})}),s.jsxs(Rt,{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(xs,{value:w,fallbackValue:.7,onValueChange:O,onClear:()=>O(void 0),min:0,max:2,step:.1,inputMode:"decimal",placeholder:"—",emptyLabel:"—",className:Ps}),w!==void 0&&s.jsx(B,{size:"sm",type:"button",variant:"ghost",onClick:()=>O(void 0),className:Cs,"aria-label":t("settings.agents.page.field.clearTemperatureAria"),title:t("settings.common.actions.clear"),children:s.jsx(F,{name:"close",className:"h-3.5 w-3.5"})})]}),s.jsxs(Rt,{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(xs,{value:T,fallbackValue:.9,onValueChange:S,onClear:()=>S(void 0),min:0,max:1,step:.1,inputMode:"decimal",placeholder:"—",emptyLabel:"—",className:Ps}),T!==void 0&&s.jsx(B,{size:"sm",type:"button",variant:"ghost",onClick:()=>S(void 0),className:Cs,"aria-label":t("settings.agents.page.field.clearTopPAria"),title:t("settings.common.actions.clear"),children:s.jsx(F,{name:"close",className:"h-3.5 w-3.5"})})]})]}),s.jsx(ze,{title:t("settings.agents.page.section.systemPrompt"),settingsItem:"agents.system-prompt",children:s.jsx(Ts,{value:M,onChange:H=>V(H.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"})}),!b&&p&&s.jsx(Au,{agent:p}),s.jsx("div",{className:"pb-8",children:s.jsx(B,{onClick:_,disabled:$||!re,size:"xs",className:"!font-normal",children:t($?"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(F,{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")})]})})},Du=Xd({content:ao(),exists:eu(),path:ao().min(1).optional()}),Mu=async(t,e)=>{const a=await t.json().catch(()=>null);return typeof a?.error=="string"&&a.error.trim()?a.error:e},Ru=t=>t.length>0&&!t.endsWith(`
2
- `)?`${t}
3
- `:t,ii={prompt:"",optimizeSystemPrompt:!1,responseStyleEnabled:!1,responseStylePreset:"concise",responseStyleCustomInstructions:""},Lu=(t,e)=>t==="custom"?e:wc(t),Ou=t=>t==="custom"?"custom":xl(t)?t:"concise",go={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"},Qi=async(t,e)=>{if(!(await pt(t)).ok)throw new Error(e)},Fu=()=>{const{t}=tt(),e=yc(),[a,n]=o.useState(""),[r,i]=o.useState("AGENTS.md"),[l,g]=o.useState(!1),[c,y]=o.useState(ii.responseStyleEnabled),[p,b]=o.useState(ii.responseStylePreset),[d,C]=o.useState(ii.responseStyleCustomInstructions),[f,P]=o.useState(!0),[x,N]=o.useState(!1),[m,A]=o.useState(!1),[R,I]=o.useState(""),[j,h]=o.useState(!1),w=o.useRef(null);o.useEffect(()=>{const $=new AbortController;return(async()=>{try{const[W,D]=await Promise.all([pn(),yt("/api/behavior/agents-md",{method:"GET",headers:{Accept:"application/json"},signal:$.signal})]);let L=ii;if(W&&(L={...L,optimizeSystemPrompt:W.optimizeSystemPrompt===!0,responseStyleEnabled:W.responseStyleEnabled===!0,responseStylePreset:Ou(W.responseStylePreset),responseStyleCustomInstructions:W.responseStyleCustomInstructions??""},W.globalBehaviorPrompt!==void 0&&(L={...L,prompt:W.globalBehaviorPrompt})),D.ok){const J=Du.parse(await D.json());if($.signal.aborted)return;i(J.path??"AGENTS.md"),L.prompt.trim()||(L={...L,prompt:J.content})}n(L.prompt),g(L.optimizeSystemPrompt),h(L.optimizeSystemPrompt),y(L.responseStyleEnabled),b(L.responseStylePreset),C(L.responseStyleCustomInstructions),I(L.prompt),w.current={enabled:L.responseStyleEnabled,preset:L.responseStylePreset,custom:L.responseStyleCustomInstructions}}catch(W){W.name!=="AbortError"&&console.warn("Failed to load behavior settings:",W)}finally{P(!1)}})(),()=>$.abort()},[]),o.useEffect(()=>{if(f)return;const $=w.current;if($&&$.enabled===c&&$.preset===p&&$.custom===d)return;const k={enabled:c,preset:p,custom:d},W=setTimeout(async()=>{try{await Qi({responseStyleEnabled:k.enabled,responseStylePreset:k.preset,responseStyleCustomInstructions:k.custom},t("settings.behavior.page.toast.saveFailed")),w.current=k}catch(D){const L=D instanceof Error?D.message:t("settings.behavior.page.toast.saveFailed");E.error(L)}},400);return()=>clearTimeout(W)},[c,p,d,f,t]);const O=Lu(p,d),T=a!==R,S=l!==j,M=async()=>{N(!0);try{const $=Ru(a),k=await yt("/api/behavior/agents-md",{method:"PUT",headers:{"Content-Type":"application/json",Accept:"application/json"},body:JSON.stringify({content:$})});if(!k.ok)throw new Error(await Mu(k,t("settings.behavior.page.toast.saveFailed")));const W=await k.json().catch(()=>null),D=vl(W,"behavior",{id:"agents-md"});await Qi({globalBehaviorPrompt:$},t("settings.behavior.page.toast.saveFailed")),n($),I($),E.success(t(D?"settings.view.pendingRestart.saved":"settings.behavior.page.toast.saved"))}catch($){console.error("Failed to save behavior:",$);const k=$ instanceof Error?$.message:t("settings.behavior.page.toast.saveFailed");E.error(k)}finally{N(!1)}},V=async()=>{A(!0);try{await Qi({optimizeSystemPrompt:l},t("settings.behavior.page.toast.saveFailed")),h(l),$n("behavior",{id:"optimize-system-prompt"}),E.success(t("settings.view.pendingRestart.saved"))}catch($){const k=$ instanceof Error?$.message:t("settings.behavior.page.toast.saveFailed");E.error(k)}finally{A(!1)}};return s.jsxs(es,{title:t("settings.behavior.page.title"),description:t("settings.page.behavior.description"),showSaveStatus:!0,children:[!e&&s.jsxs(ze,{title:t("settings.behavior.page.section.systemPromptOptimization"),divider:!1,settingsItem:"behavior.system-prompt-optimization",contentClassName:"space-y-3",children:[s.jsx(dt,{checked:l,onChange:g,disabled:f||m,label:t("settings.behavior.page.systemPromptOptimization.enable"),ariaLabel:t("settings.behavior.page.systemPromptOptimization.enableAria"),info:t("settings.behavior.page.systemPromptOptimization.info")}),s.jsx(B,{type:"button",size:"xs",onClick:()=>{V()},disabled:f||m||!S,className:"!font-normal",children:t(m?"settings.common.actions.saving":"settings.common.actions.saveChanges")})]}),s.jsxs(ze,{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:r})})]}),settingsItem:"behavior.system-prompt",contentClassName:"space-y-3",children:[s.jsx(Ts,{value:a,onChange:$=>n($.target.value),placeholder:t("settings.behavior.page.field.systemPromptPlaceholder"),rows:12,disabled:f,outerClassName:"min-h-[160px] max-h-[70vh]",className:"w-full font-mono typography-meta bg-transparent"}),s.jsx(B,{onClick:M,disabled:x||!T||f,size:"xs",className:"!font-normal",children:t(x?"settings.common.actions.saving":"settings.common.actions.saveChanges")})]}),s.jsxs(ze,{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(dt,{checked:c,onChange:y,disabled:f,label:t("settings.behavior.page.responseStyle.enable"),ariaLabel:t("settings.behavior.page.responseStyle.enableAria")}),s.jsx(Rt,{label:t("settings.behavior.page.responseStyle.preset"),alignEnd:!1,children:s.jsxs(St,{value:p,onValueChange:$=>b($),disabled:f||!c,children:[s.jsx(Ct,{size:Ft,className:rn,children:s.jsx(Mt,{children:$=>$==="custom"?t("settings.behavior.page.responseStyle.option.custom"):xl($)?t(go[$]):null})}),s.jsxs(It,{children:[bc.map($=>s.jsx(at,{value:$,children:t(go[$])},$)),s.jsx(at,{value:"custom",children:t("settings.behavior.page.responseStyle.option.custom")})]})]})}),s.jsx(Ts,{value:O,onChange:$=>C($.target.value),placeholder:t("settings.behavior.page.responseStyle.customPlaceholder"),rows:5,disabled:f||!c||p!=="custom",outerClassName:"min-h-[120px]",className:"w-full font-mono typography-meta bg-transparent"})]})]})},Ku=t=>{const e=ut.c(176),{onItemSelect:a}=t,{t:n}=tt(),[r,i]=o.useState(null),[l,g]=o.useState(""),[c,y]=o.useState(null),[p,b]=o.useState(null),[d,C]=o.useState(!1),[f,P]=o.useState(null),{selectedCommandName:x,setSelectedCommand:N,setCommandDraft:m,createCommand:A,deleteCommand:R,loadCommands:I}=va(Us(zu)),j=_s();let h;e[0]!==j?(h=Be=>yl(Be,j),e[0]=j,e[1]=h):h=e[1];const w=va(h);let O;e[2]!==j?(O=Be=>wr(Be,j),e[2]=j,e[3]=O):O=e[3];const T=Hs(O),S=Hs(Uu);let M,V;e[4]!==I||e[5]!==S||e[6]!==j?(M=()=>{I(j),S(j)},V=[I,S,j],e[4]=I,e[5]=S,e[6]=j,e[7]=M,e[8]=V):(M=e[7],V=e[8]),o.useEffect(M,V);let $;e[9]!==T?($=new Set(T.map(_u)),e[9]=T,e[10]=$):$=e[10];const k=$;let W;if(e[11]!==w||e[12]!==k){let Be;e[14]!==k?(Be=Et=>!k.has(Et.name),e[14]=k,e[15]=Be):Be=e[15],W=w.filter(Be),e[11]=w,e[12]=k,e[13]=W}else W=e[13];const D=W;let L,J;e[16]!==x||e[17]!==N||e[18]!==k?(L=()=>{x&&k.has(x)&&N(null)},J=[x,N,k],e[16]=x,e[17]=N,e[18]=k,e[19]=L,e[20]=J):(L=e[19],J=e[20]),o.useEffect(L,J);let ee;e[21]!==w||e[22]!==a||e[23]!==m||e[24]!==N?(ee=()=>{let Be="new-command",Et=1;for(;w.some(Me=>Me.name===Be);)Be=`new-command-${Et}`,Et++;m({name:Be,scope:"user"}),N(Be),a?.()},e[21]=w,e[22]=a,e[23]=m,e[24]=N,e[25]=ee):ee=e[25];const U=ee;let re;e[26]!==n?(re=async Be=>{if(ha(Be)){E.error(n("settings.commands.sidebar.toast.builtInCannotDelete"));return}y(Be),b("delete")},e[26]=n,e[27]=re):re=e[27];const _=re;let H;e[28]===Symbol.for("react.memo_cache_sentinel")?(H=async Be=>{ha(Be)&&(y(Be),b("reset"))},e[28]=H):H=e[28];const z=H;let K;e[29]===Symbol.for("react.memo_cache_sentinel")?(K=()=>{y(null),b(null)},e[29]=K):K=e[29];const te=K;let Y;e[30]!==c||e[31]!==p||e[32]!==R||e[33]!==j||e[34]!==n?(Y=async()=>{if(!c||!p)return;C(!0),await R(c.name,j)?(p==="delete"?E.success(n("settings.commands.sidebar.toast.commandDeleted",{name:c.name})):E.success(n("settings.commands.sidebar.toast.commandReset",{name:c.name})),te()):p==="delete"?E.error(n("settings.commands.sidebar.toast.deleteFailed")):E.error(n("settings.commands.sidebar.toast.resetFailed")),C(!1)},e[30]=c,e[31]=p,e[32]=R,e[33]=j,e[34]=n,e[35]=Y):Y=e[35];const ne=Y;let me;e[36]!==w||e[37]!==m||e[38]!==N?(me=Be=>{const Et=Be.name;let Me=1,wt=`${Et}-copy`;for(;w.some(Q=>Q.name===wt);)Me++,wt=`${Et}-copy-${Me}`;m({name:wt,scope:Be.scope||"user",description:Be.description,template:Be.template,agent:Be.agent,model:Be.model}),N(wt)},e[36]=w,e[37]=m,e[38]=N,e[39]=me):me=e[39];const de=me;let xe;e[40]===Symbol.for("react.memo_cache_sentinel")?(xe=Be=>{g(Be.name),i(Be)},e[40]=xe):xe=e[40];const ae=xe;let le;e[41]!==w||e[42]!==A||e[43]!==R||e[44]!==r||e[45]!==l||e[46]!==N||e[47]!==j||e[48]!==n?(le=async()=>{if(!r)return;const Be=l.trim().replace(/\s+/g,"-");if(!Be){E.error(n("settings.commands.sidebar.toast.commandNameRequired"));return}if(Be===r.name){i(null);return}if(w.some(Me=>Me.name===Be)){E.error(n("settings.commands.sidebar.toast.commandExists"));return}await A({name:Be,description:r.description,template:r.template,agent:r.agent,model:r.model},j)?await R(r.name,j)?(E.success(`Command renamed to "${Be}"`),N(Be)):E.error(n("settings.commands.sidebar.toast.removeOldAfterRenameFailed")):E.error(n("settings.commands.sidebar.toast.renameFailed")),i(null)},e[41]=w,e[42]=A,e[43]=R,e[44]=r,e[45]=l,e[46]=N,e[47]=j,e[48]=n,e[49]=le):le=e[49];const ge=le;let Ae,Se,Ce,he,_e,Ue;if(e[50]!==D||e[51]!==U||e[52]!==_||e[53]!==de||e[54]!==a||e[55]!==f||e[56]!==x||e[57]!==N||e[58]!==n){const Be=D.filter(ha),Et=D.filter($u);e[65]===Symbol.for("react.memo_cache_sentinel")?(_e=fe("flex h-full flex-col","bg-background"),e[65]=_e):_e=e[65];let Me;e[66]!==n?(Me=n("settings.commands.sidebar.title"),e[66]=n,e[67]=Me):Me=e[67];let wt;e[68]!==Me?(wt=s.jsx("h2",{className:`${un} mb-3`,children:Me}),e[68]=Me,e[69]=wt):wt=e[69];let Q;e[70]===Symbol.for("react.memo_cache_sentinel")?(Q=s.jsx(Ba,{className:"mb-3"}),e[70]=Q):Q=e[70];let ue;e[71]!==D.length||e[72]!==n?(ue=n("settings.commands.sidebar.total",{count:D.length}),e[71]=D.length,e[72]=n,e[73]=ue):ue=e[73];let De;e[74]!==ue?(De=s.jsx("span",{className:"typography-meta text-muted-foreground",children:ue}),e[74]=ue,e[75]=De):De=e[75];let Pe;e[76]===Symbol.for("react.memo_cache_sentinel")?(Pe=s.jsx(F,{name:"add",className:"h-3.5 w-3.5"}),e[76]=Pe):Pe=e[76];let it;e[77]!==U?(it=s.jsx(B,{size:"sm","data-settings-item":"commands.create",variant:"ghost",className:"h-7 w-7 px-0 -my-1 text-muted-foreground",onClick:U,children:Pe}),e[77]=U,e[78]=it):it=e[78];let rt;e[79]!==De||e[80]!==it?(rt=s.jsxs("div",{className:"flex items-center justify-between gap-2",children:[De,it]}),e[79]=De,e[80]=it,e[81]=rt):rt=e[81],e[82]!==wt||e[83]!==rt?(Ue=s.jsxs("div",{className:"border-b px-3 pt-4 pb-3",children:[wt,Q,rt]}),e[82]=wt,e[83]=rt,e[84]=Ue):Ue=e[84],Ae=vs,Se="flex-1 min-h-0",Ce="space-y-1 px-3 py-2",he=D.length===0?s.jsxs("div",{className:"py-12 px-4 text-center text-muted-foreground",children:[s.jsx(F,{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:[Be.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")}),[...Be].sort(Vu).map(qe=>s.jsx(ho,{command:qe,isSelected:x===qe.name,onSelect:()=>{N(qe.name),a?.()},onReset:()=>z(qe),onDuplicate:()=>de(qe),isMenuOpen:f===qe.name,onMenuOpenChange:Pt=>P(Pt?qe.name:null)},qe.name))]}),Et.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")}),[...Et].sort(Bu).map(qe=>s.jsx(ho,{command:qe,isSelected:x===qe.name,onSelect:()=>{N(qe.name),a?.()},onRename:()=>ae(qe),onDelete:()=>_(qe),onDuplicate:()=>de(qe),isMenuOpen:f===qe.name,onMenuOpenChange:Pt=>P(Pt?qe.name:null)},qe.name))]})]}),e[50]=D,e[51]=U,e[52]=_,e[53]=de,e[54]=a,e[55]=f,e[56]=x,e[57]=N,e[58]=n,e[59]=Ae,e[60]=Se,e[61]=Ce,e[62]=he,e[63]=_e,e[64]=Ue}else Ae=e[59],Se=e[60],Ce=e[61],he=e[62],_e=e[63],Ue=e[64];let ke;e[85]!==Ae||e[86]!==Se||e[87]!==Ce||e[88]!==he?(ke=s.jsx(Ae,{outerClassName:Se,className:Ce,children:he}),e[85]=Ae,e[86]=Se,e[87]=Ce,e[88]=he,e[89]=ke):ke=e[89];const Oe=c!==null&&p!==null;let Ve;e[90]!==d?(Ve=Be=>{!Be&&!d&&te()},e[90]=d,e[91]=Ve):Ve=e[91];let We;e[92]!==p||e[93]!==n?(We=n(p==="delete"?"settings.commands.sidebar.dialog.deleteTitle":"settings.commands.sidebar.dialog.resetTitle"),e[92]=p,e[93]=n,e[94]=We):We=e[94];let ve;e[95]!==We?(ve=s.jsx($t,{children:We}),e[95]=We,e[96]=ve):ve=e[96];let Z;e[97]!==c?.name||e[98]!==p||e[99]!==n?(Z=p==="delete"?n("settings.commands.sidebar.dialog.deleteDescription",{name:c?.name??""}):n("settings.commands.sidebar.dialog.resetDescription",{name:c?.name??""}),e[97]=c?.name,e[98]=p,e[99]=n,e[100]=Z):Z=e[100];let se;e[101]!==Z?(se=s.jsx(Vt,{children:Z}),e[101]=Z,e[102]=se):se=e[102];let ye;e[103]!==ve||e[104]!==se?(ye=s.jsxs(_t,{children:[ve,se]}),e[103]=ve,e[104]=se,e[105]=ye):ye=e[105];let be;e[106]!==n?(be=n("settings.common.actions.cancel"),e[106]=n,e[107]=be):be=e[107];let Re;e[108]!==d||e[109]!==be?(Re=s.jsx(B,{size:"sm",variant:"ghost",onClick:te,disabled:d,children:be}),e[108]=d,e[109]=be,e[110]=Re):Re=e[110];let Fe;e[111]!==p||e[112]!==n?(Fe=n(p==="delete"?"settings.common.actions.delete":"settings.common.actions.reset"),e[111]=p,e[112]=n,e[113]=Fe):Fe=e[113];let Ke;e[114]!==ne||e[115]!==d||e[116]!==Fe?(Ke=s.jsx(B,{size:"sm",onClick:ne,disabled:d,children:Fe}),e[114]=ne,e[115]=d,e[116]=Fe,e[117]=Ke):Ke=e[117];let Ee;e[118]!==Re||e[119]!==Ke?(Ee=s.jsxs(ts,{children:[Re,Ke]}),e[118]=Re,e[119]=Ke,e[120]=Ee):Ee=e[120];let we;e[121]!==ye||e[122]!==Ee?(we=s.jsxs(zt,{className:"max-w-md",children:[ye,Ee]}),e[121]=ye,e[122]=Ee,e[123]=we):we=e[123];let Ze;e[124]!==Oe||e[125]!==Ve||e[126]!==we?(Ze=s.jsx(Kt,{open:Oe,onOpenChange:Ve,children:we}),e[124]=Oe,e[125]=Ve,e[126]=we,e[127]=Ze):Ze=e[127];const pe=r!==null;let Ne;e[128]===Symbol.for("react.memo_cache_sentinel")?(Ne=Be=>!Be&&i(null),e[128]=Ne):Ne=e[128];let Le;e[129]!==n?(Le=n("settings.commands.sidebar.renameDialog.title"),e[129]=n,e[130]=Le):Le=e[130];let Xe;e[131]!==Le?(Xe=s.jsx($t,{children:Le}),e[131]=Le,e[132]=Xe):Xe=e[132];const q=r?.name??"";let je;e[133]!==n||e[134]!==q?(je=n("settings.commands.sidebar.renameDialog.description",{name:q}),e[133]=n,e[134]=q,e[135]=je):je=e[135];let Ie;e[136]!==je?(Ie=s.jsx(Vt,{children:je}),e[136]=je,e[137]=Ie):Ie=e[137];let Je;e[138]!==Xe||e[139]!==Ie?(Je=s.jsxs(_t,{children:[Xe,Ie]}),e[138]=Xe,e[139]=Ie,e[140]=Je):Je=e[140];let ot;e[141]===Symbol.for("react.memo_cache_sentinel")?(ot=Be=>g(Be.target.value),e[141]=ot):ot=e[141];let st;e[142]!==n?(st=n("settings.commands.sidebar.renameDialog.placeholder"),e[142]=n,e[143]=st):st=e[143];let mt;e[144]!==ge?(mt=Be=>{Be.key==="Enter"&&ge()},e[144]=ge,e[145]=mt):mt=e[145];let vt;e[146]!==l||e[147]!==st||e[148]!==mt?(vt=s.jsx(He,{value:l,onChange:ot,placeholder:st,className:"text-foreground placeholder:text-muted-foreground",onKeyDown:mt}),e[146]=l,e[147]=st,e[148]=mt,e[149]=vt):vt=e[149];let G;e[150]===Symbol.for("react.memo_cache_sentinel")?(G=()=>i(null),e[150]=G):G=e[150];let Ge;e[151]!==n?(Ge=n("settings.common.actions.cancel"),e[151]=n,e[152]=Ge):Ge=e[152];let nt;e[153]!==Ge?(nt=s.jsx(B,{size:"sm",variant:"ghost",onClick:G,children:Ge}),e[153]=Ge,e[154]=nt):nt=e[154];let lt;e[155]!==n?(lt=n("settings.common.actions.rename"),e[155]=n,e[156]=lt):lt=e[156];let ht;e[157]!==ge||e[158]!==lt?(ht=s.jsx(B,{size:"sm",onClick:ge,children:lt}),e[157]=ge,e[158]=lt,e[159]=ht):ht=e[159];let Lt;e[160]!==nt||e[161]!==ht?(Lt=s.jsxs(ts,{children:[nt,ht]}),e[160]=nt,e[161]=ht,e[162]=Lt):Lt=e[162];let et;e[163]!==Je||e[164]!==vt||e[165]!==Lt?(et=s.jsxs(zt,{children:[Je,vt,Lt]}),e[163]=Je,e[164]=vt,e[165]=Lt,e[166]=et):et=e[166];let ft;e[167]!==pe||e[168]!==et?(ft=s.jsx(Kt,{open:pe,onOpenChange:Ne,children:et}),e[167]=pe,e[168]=et,e[169]=ft):ft=e[169];let bt;return e[170]!==_e||e[171]!==Ue||e[172]!==ke||e[173]!==Ze||e[174]!==ft?(bt=s.jsxs("div",{className:_e,children:[Ue,ke,Ze,ft]}),e[170]=_e,e[171]=Ue,e[172]=ke,e[173]=Ze,e[174]=ft,e[175]=bt):bt=e[175],bt},ho=t=>{const e=ut.c(47),{command:a,isSelected:n,onSelect:r,onDelete:i,onReset:l,onRename:g,onDuplicate:c,isMenuOpen:y,onMenuOpenChange:p}=t,{t:b}=tt();let d;e[0]===Symbol.for("react.memo_cache_sentinel")?(d=_a(),e[0]=d):d=e[0];const C=d,[f,P]=o.useState(!1);let x;e[1]!==i||e[2]!==c||e[3]!==g||e[4]!==l||e[5]!==b?(x=J=>s.jsxs(s.Fragment,{children:[g&&s.jsxs(J,{onClick:ee=>{ee.stopPropagation(),g()},children:[s.jsx(F,{name:"edit",className:"h-4 w-4 mr-px"}),b("settings.common.actions.rename")]}),s.jsxs(J,{onClick:ee=>{ee.stopPropagation(),c()},children:[s.jsx(F,{name:"file-copy",className:"h-4 w-4 mr-px"}),b("settings.common.actions.duplicate")]}),l&&s.jsxs(J,{onClick:ee=>{ee.stopPropagation(),l()},children:[s.jsx(F,{name:"restart",className:"h-4 w-4 mr-px"}),b("settings.common.actions.reset")]}),i&&s.jsxs(J,{onClick:ee=>{ee.stopPropagation(),i()},className:"text-destructive focus:text-destructive",children:[s.jsx(F,{name:"delete-bin",className:"h-4 w-4 mr-px"}),b("settings.common.actions.delete")]})]}),e[1]=i,e[2]=c,e[3]=g,e[4]=l,e[5]=b,e[6]=x):x=e[6];const N=x,m=n?"bg-interactive-selection":"hover:bg-interactive-hover";let A;e[7]!==m?(A=fe("group relative flex items-center rounded-md px-1.5 py-1 transition-all duration-200 select-none",m),e[7]=m,e[8]=A):A=e[8];let R;e[9]===Symbol.for("react.memo_cache_sentinel")?(R=C?void 0:J=>{J.preventDefault(),P(!0)},e[9]=R):R=e[9];let I;e[10]!==A?(I=s.jsx("div",{className:A,onContextMenu:R}),e[10]=A,e[11]=I):I=e[11];let j;e[12]!==a.name?(j=s.jsxs("span",{className:"typography-ui-label font-normal truncate text-foreground",children:["/",a.name]}),e[12]=a.name,e[13]=j):j=e[13];let h;e[14]!==a||e[15]!==b?(h=(a.scope||ha(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:ha(a)?b("settings.agents.sidebar.badge.system"):a.scope}),e[14]=a,e[15]=b,e[16]=h):h=e[16];let w;e[17]!==j||e[18]!==h?(w=s.jsxs("div",{className:"flex items-center gap-2",children:[j,h]}),e[17]=j,e[18]=h,e[19]=w):w=e[19];let O;e[20]!==a.description?(O=a.description&&s.jsx("div",{className:"typography-micro text-muted-foreground/60 truncate leading-tight",children:a.description}),e[20]=a.description,e[21]=O):O=e[21];let T;e[22]!==r||e[23]!==O||e[24]!==w?(T=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:[w,O]}),e[22]=r,e[23]=O,e[24]=w,e[25]=T):T=e[25];let S;e[26]!==p?(S=J=>{J&&P(!1),p(J)},e[26]=p,e[27]=S):S=e[27];let M;e[28]===Symbol.for("react.memo_cache_sentinel")?(M=s.jsx(on,{asChild:!0,children:s.jsx(B,{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(F,{name:"more-2",className:"h-3.5 w-3.5"})})}),e[28]=M):M=e[28];let V;e[29]!==N?(V=s.jsx(ln,{align:"end",className:"w-fit min-w-20",children:N(dn)}),e[29]=N,e[30]=V):V=e[30];let $;e[31]!==y||e[32]!==S||e[33]!==V?($=s.jsxs(cn,{open:y,onOpenChange:S,children:[M,V]}),e[31]=y,e[32]=S,e[33]=V,e[34]=$):$=e[34];let k;e[35]!==T||e[36]!==$?(k=s.jsxs("div",{className:"flex min-w-0 flex-1 items-center",children:[T,$]}),e[35]=T,e[36]=$,e[37]=k):k=e[37];let W;e[38]!==k||e[39]!==I?(W=s.jsx(Jn,{render:I,children:k}),e[38]=k,e[39]=I,e[40]=W):W=e[40];let D;e[41]!==N?(D=s.jsx(Gn,{className:"w-fit min-w-20",children:N(qn)}),e[41]=N,e[42]=D):D=e[42];let L;return e[43]!==f||e[44]!==W||e[45]!==D?(L=s.jsxs(Qn,{open:f,onOpenChange:P,children:[W,D]}),e[43]=f,e[44]=W,e[45]=D,e[46]=L):L=e[46],L};function zu(t){return{selectedCommandName:t.selectedCommandName,setSelectedCommand:t.setSelectedCommand,setCommandDraft:t.setCommandDraft,createCommand:t.createCommand,deleteCommand:t.deleteCommand,loadCommands:t.loadCommands}}function Uu(t){return t.loadSkills}function _u(t){return t.name}function $u(t){return!ha(t)}function Vu(t,e){return t.name.localeCompare(e.name)}function Bu(t,e){return t.name.localeCompare(e.name)}const Hu=()=>{const{t}=tt(),{selectedCommandName:e,getCommandByName:a,createCommand:n,updateCommand:r,commandDraft:i,setCommandDraft:l}=va(Us(M=>({selectedCommandName:M.selectedCommandName,getCommandByName:M.getCommandByName,createCommand:M.createCommand,updateCommand:M.updateCommand,commandDraft:M.commandDraft,setCommandDraft:M.setCommandDraft}))),g=_s(),c=va(M=>yl(M,g)),y=e?a(e,g):null,p=!!(i&&i.name===e&&!y),[b,d]=o.useState(""),[C,f]=o.useState("user"),[P,x]=o.useState(""),[N,m]=o.useState(""),[A,R]=o.useState(""),[I,j]=o.useState(""),[h,w]=o.useState(!1),O=o.useRef(null);o.useEffect(()=>{if(p&&i){const M=i.name||"",V=i.scope||"user",$=i.description||"",k=i.agent||"",W=i.model||"",D=i.template||"";d(M),f(V),x($),m(k),R(W),j(D),O.current={draftName:M,draftScope:V,description:$,agent:k,model:W,template:D}}else if(y){const M=y.description||"",V=y.agent||"",$=y.model||"",k=y.template||"";x(M),m(V),R($),j(k),O.current={draftName:"",draftScope:"user",description:M,agent:V,model:$,template:k}}},[y,p,e,c,i]);const T=o.useMemo(()=>{const M=O.current;return M?!!(p&&(b!==M.draftName||C!==M.draftScope)||P!==M.description||N!==M.agent||A!==M.model||I!==M.template):!1},[N,P,b,C,p,A,I]),S=async()=>{const M=p?b.trim().replace(/\s+/g,"-"):e?.trim();if(!M){E.error(t("settings.commands.sidebar.toast.commandNameRequired"));return}if(!I.trim()){E.error(t("settings.commands.page.toast.templateRequired"));return}if(p&&c.some(V=>V.name===M)){E.error(t("settings.commands.sidebar.toast.commandExists"));return}w(!0);try{const V=N.trim(),$=A.trim(),k=I.trim(),W={name:M,description:P.trim()||void 0,agent:V===""?null:V,model:$===""?null:$,template:k,scope:p?C:void 0};let D;if(p?(D=await n(W,g),D&&l(null)):D=await r(M,W,g),D){const L=Vn.getState().changes.some(J=>J.scope==="commands"&&J.id.startsWith(`commands:${M}:`));E.success(t(L?"settings.view.pendingRestart.saved":p?"settings.commands.page.toast.created":"settings.commands.page.toast.updated"))}else E.error(t(p?"settings.commands.page.toast.createFailed":"settings.commands.page.toast.updateFailed"))}catch(V){console.error("Error saving command:",V),E.error(t("settings.commands.page.toast.saveUnexpectedError"))}finally{w(!1)}};return e?s.jsxs(es,{title:p?t("settings.commands.page.title.new"):`/${e}`,description:t(p?"settings.commands.page.subtitle.new":"settings.commands.page.subtitle.edit"),showSaveStatus:!1,children:[s.jsxs(ze,{title:t("settings.commands.page.section.identity"),divider:!1,contentClassName:"space-y-0",children:[p&&s.jsxs(Rt,{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:b,onChange:M=>d(M.target.value),placeholder:t("settings.commands.page.field.commandNamePlaceholder"),className:"h-7 w-40 px-2"})]}),s.jsxs(St,{value:C,onValueChange:M=>f(M),children:[s.jsx(Ct,{size:Ft,className:"w-fit min-w-[100px]",children:s.jsx(Mt,{placeholder:t("settings.agents.page.field.scopePlaceholder")})}),s.jsxs(It,{align:"end",children:[s.jsx(at,{value:"user",children:s.jsxs("div",{className:"flex items-center gap-2",children:[s.jsx(F,{name:"user-3",className:"h-3.5 w-3.5"}),s.jsx("span",{children:t("settings.common.scope.global")})]})}),s.jsx(at,{value:"project",children:s.jsxs("div",{className:"flex items-center gap-2",children:[s.jsx(F,{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(Ts,{value:P,onChange:M=>x(M.target.value),placeholder:t("settings.commands.page.field.descriptionPlaceholder"),rows:2,className:"w-full resize-none min-h-[60px] bg-transparent"})})]})]}),s.jsxs(ze,{title:t("settings.commands.page.section.executionContext"),contentClassName:"space-y-0",children:[s.jsx(Rt,{settingsItem:"commands.agent",label:t("settings.commands.page.field.overrideAgent"),children:s.jsx(bl,{agentName:N,onChange:M=>m(M),className:In})}),s.jsx(Rt,{settingsItem:"commands.model",label:t("settings.agents.page.field.overrideModel"),children:s.jsx(Fa,{providerId:xa(A)?.providerId??"",modelId:xa(A)?.modelId??"",onChange:(M,V)=>{R(M&&V?`${M}/${V}`:"")},className:In})})]}),s.jsxs(ze,{title:t("settings.commands.page.section.template"),settingsItem:"commands.template",children:[s.jsx(Ts,{value:I,onChange:M=>j(M.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(B,{onClick:S,disabled:h||!T,size:"xs",className:"!font-normal",children:t(h?"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(F,{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")})]})})},fo=t=>{switch(t){case"connected":return"success";case"failed":return"error";case"needs_auth":case"needs_client_registration":return"warning";default:return"idle"}},xo=t=>{const e=ut.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 r;e[1]!==a?(r=fe("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]=r):r=e[2];let i;return e[3]!==r?(i=s.jsx("span",{className:r}),e[3]=r,e[4]=i):i=e[4],i},Wu=t=>{const e=ut.c(124),{onItemSelect:a}=t,{t:n}=tt(),{selectedMcpName:r,setSelectedMcp:i,setMcpDraft:l,loadMcpConfigs:g,deleteMcp:c}=ya(Us(Gu)),y=_s();let p;e[0]!==y?(p=q=>wl(q,y),e[0]=y,e[1]=p):p=e[1];const b=ya(p);let d;e[2]!==y?(d=q=>q.getStatusForDirectory(y),e[2]=y,e[3]=d):d=e[3];const C=Ks(d),f=Ks(qu),P=Ks(Ju),[x,N]=o.useState(null),[m,A]=o.useState(!1),[R,I]=o.useState(null),[j,h]=o.useState(null),[w,O]=o.useState(!1);let T;e[4]!==b?(T=b.filter(Qu),e[4]=b,e[5]=T):T=e[5];const S=T;let M;e[6]!==b?(M=b.filter(Yu),e[6]=b,e[7]=M):M=e[7];const V=M;let $,k;e[8]!==g||e[9]!==y?($=()=>{g({directory:y})},k=[g,y],e[8]=g,e[9]=y,e[10]=$,e[11]=k):($=e[10],k=e[11]),o.useEffect($,k);let W;e[12]!==P||e[13]!==w||e[14]!==f||e[15]!==y?(W=()=>{if(w)return;O(!0);const q=new Promise(Zu);Promise.all([f({directory:y,silent:!0}),q]).then(()=>{const je=P(y);je&&E.error(je)}).finally(()=>{O(!1)})},e[12]=P,e[13]=w,e[14]=f,e[15]=y,e[16]=W):W=e[16];const D=W;let L;e[17]!==b||e[18]!==a||e[19]!==l||e[20]!==i?(L=()=>{let q="new-mcp-server",je=1;for(;b.some(Je=>Je.name===q);)q=`new-mcp-server-${je}`,je++;l({name:q,scope:"user",type:"local",command:[],url:"",environment:[],headers:[],oauthEnabled:!0,oauthClientId:"",oauthClientSecret:"",oauthScope:"",oauthRedirectUri:"",timeout:"",enabled:!0}),i(q),a?.()},e[17]=b,e[18]=a,e[19]=l,e[20]=i,e[21]=L):L=e[21];const J=L;let ee;e[22]!==c||e[23]!==x||e[24]!==y||e[25]!==n?(ee=async()=>{if(!x)return;A(!0);const q=await c(x.name,y);q.ok?q.reloadFailed?E.warning(q.message||`MCP server "${x.name}" deleted, but OpenCode reload failed`,{description:q.warning||n("settings.mcp.sidebar.toast.refreshListIfStale")}):E.success(q.message||n("settings.mcp.sidebar.toast.serverDeleted",{name:x.name})):E.error(n("settings.mcp.sidebar.toast.deleteFailed")),N(null),A(!1)},e[22]=c,e[23]=x,e[24]=y,e[25]=n,e[26]=ee):ee=e[26];const U=ee;let re;e[27]!==n?(re=(q,je)=>s.jsxs(je,{onClick:Ie=>{Ie.stopPropagation(),N(q)},className:"text-destructive focus:text-destructive",children:[s.jsx(F,{name:"delete-bin",className:"h-4 w-4 mr-px"}),n("settings.common.actions.delete")]}),e[27]=n,e[28]=re):re=e[28];const _=re;let H;e[29]===Symbol.for("react.memo_cache_sentinel")?(H=fe("flex h-full flex-col","bg-background"),e[29]=H):H=e[29];let z;e[30]!==n?(z=n("settings.mcp.sidebar.title"),e[30]=n,e[31]=z):z=e[31];let K;e[32]!==z?(K=s.jsx("h2",{className:un,children:z}),e[32]=z,e[33]=K):K=e[33];let te;e[34]!==n?(te=n("settings.mcp.sidebar.actions.refreshStatusAria"),e[34]=n,e[35]=te):te=e[35];let Y;e[36]!==n?(Y=n("settings.mcp.sidebar.actions.refreshStatusTitle"),e[36]=n,e[37]=Y):Y=e[37];const ne=w&&"animate-spin";let me;e[38]!==ne?(me=fe("h-4 w-4",ne),e[38]=ne,e[39]=me):me=e[39];let de;e[40]!==me?(de=s.jsx(F,{name:"refresh",className:me}),e[40]=me,e[41]=de):de=e[41];let xe;e[42]!==D||e[43]!==w||e[44]!==te||e[45]!==Y||e[46]!==de?(xe=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:w,onClick:D,"aria-label":te,title:Y,children:de}),e[42]=D,e[43]=w,e[44]=te,e[45]=Y,e[46]=de,e[47]=xe):xe=e[47];let ae;e[48]!==K||e[49]!==xe?(ae=s.jsxs("div",{className:"mb-3 flex items-center justify-between gap-3",children:[K,xe]}),e[48]=K,e[49]=xe,e[50]=ae):ae=e[50];let le;e[51]===Symbol.for("react.memo_cache_sentinel")?(le=s.jsx(Ba,{className:"mb-3"}),e[51]=le):le=e[51];let ge;e[52]!==b.length||e[53]!==n?(ge=n("settings.mcp.sidebar.total",{count:b.length}),e[52]=b.length,e[53]=n,e[54]=ge):ge=e[54];let Ae;e[55]!==ge?(Ae=s.jsx("span",{className:"typography-meta text-muted-foreground",children:ge}),e[55]=ge,e[56]=Ae):Ae=e[56];let Se;e[57]!==n?(Se=n("settings.mcp.sidebar.actions.addServerTitle"),e[57]=n,e[58]=Se):Se=e[58];let Ce;e[59]===Symbol.for("react.memo_cache_sentinel")?(Ce=s.jsx(F,{name:"add",className:"h-3.5 w-3.5"}),e[59]=Ce):Ce=e[59];let he;e[60]!==J||e[61]!==Se?(he=s.jsx(B,{size:"sm","data-settings-item":"mcp.create",variant:"ghost",className:"h-7 w-7 px-0 -my-1 text-muted-foreground",onClick:J,title:Se,children:Ce}),e[60]=J,e[61]=Se,e[62]=he):he=e[62];let _e;e[63]!==Ae||e[64]!==he?(_e=s.jsxs("div",{className:"flex items-center justify-between gap-2",children:[Ae,he]}),e[63]=Ae,e[64]=he,e[65]=_e):_e=e[65];let Ue;e[66]!==ae||e[67]!==_e?(Ue=s.jsxs("div",{className:"border-b px-3 pt-4 pb-3",children:[ae,le,_e]}),e[66]=ae,e[67]=_e,e[68]=Ue):Ue=e[68];let ke;e[69]!==b.length||e[70]!==C||e[71]!==a||e[72]!==R||e[73]!==S||e[74]!==_||e[75]!==j||e[76]!==r||e[77]!==l||e[78]!==i||e[79]!==n||e[80]!==V?(ke=s.jsx(vs,{outerClassName:"flex-1 min-h-0",className:"space-y-1 px-3 py-2 overflow-x-hidden",children:b.length===0?s.jsxs("div",{className:"py-12 px-4 text-center text-muted-foreground",children:[s.jsx(F,{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(q=>{const je=C[q.name],Ie=fo(je?.status),Je=r===q.name,ot=_a();return s.jsxs(Qn,{open:j===q.name,onOpenChange:st=>h(st?q.name:null),children:[s.jsxs(Jn,{render:s.jsx("div",{className:fe("group relative flex items-center rounded-md px-1.5 py-1 transition-all duration-200 select-none",Je?"bg-interactive-selection":"hover:bg-interactive-hover"),onContextMenu:ot?void 0:st=>{st.preventDefault(),h(q.name)}}),children:[s.jsxs("button",{onClick:()=>{i(q.name),l(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(xo,{tone:Ie,enabled:q.enabled}),s.jsx("span",{className:"typography-ui-label font-normal truncate text-foreground",children:q.name}),s.jsx("span",{title:q.type==="local"?n("settings.mcp.sidebar.serverType.localTitle"):n("settings.mcp.sidebar.serverType.remoteTitle"),children:q.type==="local"?s.jsx(F,{name:"server",className:"h-3 w-3 text-muted-foreground/60 flex-shrink-0"}):s.jsx(F,{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:q.type==="local"?q.command?.join(" ")??"":q.url??""})]}),s.jsxs(cn,{open:R===q.name,onOpenChange:st=>{st&&h(null),I(st?q.name:null)},children:[s.jsx(on,{asChild:!0,children:s.jsx(B,{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(F,{name:"more-2",className:"h-3.5 w-3.5"})})}),s.jsx(ln,{align:"end",className:"w-fit min-w-20",children:_(q,dn)})]})]}),s.jsx(Gn,{className:"w-fit min-w-20",children:_(q,qn)})]},q.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(q=>{const je=C[q.name],Ie=fo(je?.status),Je=r===q.name,ot=_a();return s.jsxs(Qn,{open:j===q.name,onOpenChange:st=>h(st?q.name:null),children:[s.jsxs(Jn,{render:s.jsx("div",{className:fe("group relative flex items-center rounded-md px-1.5 py-1 transition-all duration-200 select-none",Je?"bg-interactive-selection":"hover:bg-interactive-hover"),onContextMenu:ot?void 0:st=>{st.preventDefault(),h(q.name)}}),children:[s.jsxs("button",{onClick:()=>{i(q.name),l(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(xo,{tone:Ie,enabled:q.enabled}),s.jsx("span",{className:"typography-ui-label font-normal truncate text-foreground",children:q.name}),s.jsx("span",{title:q.type==="local"?n("settings.mcp.sidebar.serverType.localTitle"):n("settings.mcp.sidebar.serverType.remoteTitle"),children:q.type==="local"?s.jsx(F,{name:"server",className:"h-3 w-3 text-muted-foreground/60 flex-shrink-0"}):s.jsx(F,{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:q.type==="local"?q.command?.join(" ")??"":q.url??""})]}),s.jsxs(cn,{open:R===q.name,onOpenChange:st=>{st&&h(null),I(st?q.name:null)},children:[s.jsx(on,{asChild:!0,children:s.jsx(B,{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(F,{name:"more-2",className:"h-3.5 w-3.5"})})}),s.jsx(ln,{align:"end",className:"w-fit min-w-20",children:_(q,dn)})]})]}),s.jsx(Gn,{className:"w-fit min-w-20",children:_(q,qn)})]},q.name)})]})]})}),e[69]=b.length,e[70]=C,e[71]=a,e[72]=R,e[73]=S,e[74]=_,e[75]=j,e[76]=r,e[77]=l,e[78]=i,e[79]=n,e[80]=V,e[81]=ke):ke=e[81];const Oe=x!==null;let Ve;e[82]!==m?(Ve=q=>{!q&&!m&&N(null)},e[82]=m,e[83]=Ve):Ve=e[83];let We;e[84]!==n?(We=n("settings.mcp.sidebar.deleteDialog.title"),e[84]=n,e[85]=We):We=e[85];let ve;e[86]!==We?(ve=s.jsx($t,{children:We}),e[86]=We,e[87]=ve):ve=e[87];const Z=x?.name||"";let se;e[88]!==n||e[89]!==Z?(se=n("settings.mcp.sidebar.deleteDialog.descriptionPrefix",{name:Z}),e[88]=n,e[89]=Z,e[90]=se):se=e[90];let ye;e[91]===Symbol.for("react.memo_cache_sentinel")?(ye=s.jsx("code",{className:"text-foreground",children:"opencode.json"}),e[91]=ye):ye=e[91];let be;e[92]!==se?(be=s.jsxs(Vt,{children:[se," ",ye,"."]}),e[92]=se,e[93]=be):be=e[93];let Re;e[94]!==ve||e[95]!==be?(Re=s.jsxs(_t,{children:[ve,be]}),e[94]=ve,e[95]=be,e[96]=Re):Re=e[96];let Fe;e[97]===Symbol.for("react.memo_cache_sentinel")?(Fe=()=>N(null),e[97]=Fe):Fe=e[97];let Ke;e[98]!==n?(Ke=n("settings.common.actions.cancel"),e[98]=n,e[99]=Ke):Ke=e[99];let Ee;e[100]!==m||e[101]!==Ke?(Ee=s.jsx(B,{size:"sm",variant:"ghost",onClick:Fe,disabled:m,children:Ke}),e[100]=m,e[101]=Ke,e[102]=Ee):Ee=e[102];let we;e[103]!==m||e[104]!==n?(we=n(m?"settings.mcp.sidebar.actions.deleting":"settings.common.actions.delete"),e[103]=m,e[104]=n,e[105]=we):we=e[105];let Ze;e[106]!==U||e[107]!==m||e[108]!==we?(Ze=s.jsx(B,{size:"sm",onClick:U,disabled:m,children:we}),e[106]=U,e[107]=m,e[108]=we,e[109]=Ze):Ze=e[109];let pe;e[110]!==Ee||e[111]!==Ze?(pe=s.jsxs(ts,{children:[Ee,Ze]}),e[110]=Ee,e[111]=Ze,e[112]=pe):pe=e[112];let Ne;e[113]!==Re||e[114]!==pe?(Ne=s.jsxs(zt,{className:"max-w-md",children:[Re,pe]}),e[113]=Re,e[114]=pe,e[115]=Ne):Ne=e[115];let Le;e[116]!==Oe||e[117]!==Ve||e[118]!==Ne?(Le=s.jsx(Kt,{open:Oe,onOpenChange:Ve,children:Ne}),e[116]=Oe,e[117]=Ve,e[118]=Ne,e[119]=Le):Le=e[119];let Xe;return e[120]!==Ue||e[121]!==ke||e[122]!==Le?(Xe=s.jsxs("div",{className:H,children:[Ue,ke,Le]}),e[120]=Ue,e[121]=ke,e[122]=Le,e[123]=Xe):Xe=e[123],Xe};function Gu(t){return{selectedMcpName:t.selectedMcpName,setSelectedMcp:t.setSelectedMcp,setMcpDraft:t.setMcpDraft,loadMcpConfigs:t.loadMcpConfigs,deleteMcp:t.deleteMcp}}function qu(t){return t.refresh}function Ju(t){return t.getErrorForDirectory}function Qu(t){return t.scope==="project"}function Yu(t){return t.scope!=="project"}function Zu(t){return setTimeout(t,500)}function an(t){return typeof t=="object"&&t!==null&&!Array.isArray(t)}function Pa(t){return Array.isArray(t)&&t.every(e=>typeof e=="string")}function nn(t,e){return e!==void 0?{ok:!1,error:t,parsed:e}:{ok:!1,error:t}}function ri(t,e,a){const n=Xu(a),r=typeof a.url=="string"?a.url.trim():"",i=vo(a,"env","environment"),l=vo(a,"headers"),g=ep(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():"",p=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():"",d=tp(a),C=sp(a);return{ok:!0,name:t,type:e,command:n,url:r,environment:i,headers:l,oauthEnabled:g,oauthClientId:c,oauthClientSecret:y,oauthScope:p,oauthRedirectUri:b,timeout:d,enabled:C}}function Xu(t){const e=t.command,a=t.args;if(Pa(e)&&Pa(a))return[...e,...a];if(Pa(e))return e;if(typeof e=="string"&&e.trim()){const n=e.trim().split(/\s+/);return Pa(a)?[...n,...a]:n}return Pa(a)?a:[]}function vo(t,...e){for(const a of e){const n=t[a];if(!an(n))continue;const r=Object.entries(n).filter(([i,l])=>i&&typeof l=="string");if(r.length>0)return r.map(([i,l])=>({key:i,value:String(l)}))}return[]}function ep(t){if(t.oauth===!1||t.oauth===null||t.oauth===void 0||!an(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 tp(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 sp(t){return"disabled"in t&&t.disabled===!0?!1:"enabled"in t?!!t.enabled:!0}function np(t){const e=t.mcpServers;if(an(e)){const n=Object.keys(e);if(n.length===1){const r=n[0],i=e[r];if(an(i))return{name:r,entry:i}}if(n.length>1)return null}const a=Object.keys(t).filter(n=>{const r=t[n];return n!=="mcpServers"&&an(r)});if(a.length===1){const n=a[0],r=t[n];if($l(r))return{name:n,entry:r}}return null}function $l(t){return t.type==="local"||t.type==="remote"||Array.isArray(t.command)||typeof t.url=="string"||Array.isArray(t.args)}function ap(t,e){let a;try{const g=t.trim();if(!g)return nn("No JSON content provided");a=JSON.parse(g)}catch(g){return nn(g instanceof Error?`Invalid JSON: ${g.message}`:"Invalid JSON")}if(!an(a))return nn("Expected a JSON object, not an array or primitive");const n=a,r=n.mcpServers;if(an(r)){const g=Object.keys(r);if(g.length===0)return nn("mcpServers object is empty",a);if(g.length>1)return nn("Paste one server at a time. Found "+g.length+" servers in mcpServers",a);const c=g[0],y=r[c];return an(y)?ri(c,oi(y),y):nn("Server entry is not a valid object",a)}const i=n.mcp;if(an(i)){const g=Object.keys(i);if(g.length===0)return nn("mcp object is empty",a);if(g.length>1)return nn("Paste one server at a time. Found "+g.length+" servers in mcp",a);const c=g[0],y=i[c];return an(y)?ri(c,oi(y),y):nn("Server entry in mcp is not a valid object",a)}const l=np(n);if(l)return ri(l.name,oi(l.entry),l.entry);if($l(n)){const g=oi(n),c=typeof n.name=="string"&&n.name.trim()?n.name.trim():e?.fallbackName;return ri(c,g,n)}return nn("No recognizable MCP server configuration found in JSON",a)}function oi(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 ip(t,e,a){const n=a?.isNewServer??!1,r=t.name,i=n&&r?r:e.name??"";return{...e,name:i,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 Vl(t){const e=[];let a="",n=!1,r=!1;for(let i=0;i<t.length;i++){const l=t[i];if(l==="'"&&!r){n=!n;continue}if(l==='"'&&!n){r=!r;continue}if((l===" "||l===" ")&&!n&&!r){a&&(e.push(a),a="");continue}a+=l}return a&&e.push(a),e}function rp(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:Nc(a.searchParams),stateKey:jl(a.searchParams)}}catch{}return{code:e,context:null,stateKey:null}}const op=t=>{const e=ut.c(27),{value:a,onChange:n,preview:r,onDetectUrl:i}=t;let l;e[0]!==a?(l=()=>a.join(`
4
- `),e[0]=a,e[1]=l):l=e[1];const[g,c]=o.useState(l),y=o.useRef(a);let p,b;e[2]!==a?(p=()=>{JSON.stringify(y.current)!==JSON.stringify(a)&&(y.current=a,c(a.join(`
5
- `)))},b=[a],e[2]=a,e[3]=p,e[4]=b):(p=e[3],b=e[4]),o.useEffect(p,b);let d;e[5]!==n||e[6]!==i?(d=j=>{const h=j.split(`
6
- `).filter(hp);if(i&&h.length===1&&/^https?:\/\/\S+$/i.test(h[0].trim())){i(h[0].trim());return}n(h)},e[5]=n,e[6]=i,e[7]=d):d=e[7];const C=d;let f;e[8]!==n?(f=j=>{const w=j.clipboardData.getData("text").trim();if(!w||w.includes(`
7
- `)||!/\s/.test(w))return;const O=j.currentTarget;if(O.selectionStart!==0||O.selectionEnd!==O.value.length)return;j.preventDefault();const T=Vl(w);c(T.join(`
8
- `)),n(T)},e[8]=n,e[9]=f):f=e[9];const P=f;let x;e[10]!==C?(x=j=>{c(j.target.value),C(j.target.value)},e[10]=C,e[11]=x):x=e[11];let N;e[12]!==C||e[13]!==g?(N=()=>{const j=g.split(`
9
- `).map(fp).join(`
10
- `);c(j),C(j)},e[12]=C,e[13]=g,e[14]=N):N=e[14];const m=Math.max(4,a.length+1);let A;e[15]!==P||e[16]!==x||e[17]!==N||e[18]!==m||e[19]!==g?(A=s.jsx(Ts,{onPaste:P,value:g,onChange:x,onBlur:N,placeholder:`npx
11
- -y
12
- @modelcontextprotocol/server-postgres
13
- postgresql://user:pass@host/db`,rows:m,className:"font-mono typography-meta min-h-[80px]",spellCheck:!1}),e[15]=P,e[16]=x,e[17]=N,e[18]=m,e[19]=g,e[20]=A):A=e[20];let R;e[21]!==r||e[22]!==a?(R=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:r(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(xp)})})]}),e[21]=r,e[22]=a,e[23]=R):R=e[23];let I;return e[24]!==R||e[25]!==A?(I=s.jsxs("div",{className:"space-y-2","data-bwignore":"true","data-1p-ignore":"true","data-lpignore":"true",children:[A,R]}),e[24]=R,e[25]=A,e[26]=I):I=e[26],I},lp=t=>t.toUpperCase().replace(/[^A-Z0-9_]/g,"_"),yo=({value:t,onChange:e,keyTransform:a=lp,keyPlaceholder:n="API_KEY",keyInputClassName:r="w-36 shrink-0 font-mono typography-meta uppercase",pasteLabel:i="Paste .env",pasteTitle:l="Paste KEY=VALUE lines from clipboard",noPairsFoundError:g,importSuccess:c,clipboardReadFailed:y,keyLabel:p,valueLabel:b,valuePlaceholder:d,hideValueTitle:C,showValueTitle:f,addVariable:P,plainTextWarning:x,removeVariableAria:N})=>{const[m,A]=o.useState(new Set),R=()=>e([...t,{key:"",value:""}]),I=T=>{e(t.filter((S,M)=>M!==T)),A(S=>{const M=new Set(S);return M.delete(T),M})},j=(T,S,M)=>{const V=[...t];V[T]={...V[T],[S]:M},e(V)},h=T=>{A(S=>{const M=new Set(S);return M.has(T)?M.delete(T):M.add(T),M})},w=async()=>{try{const T=await navigator.clipboard.readText(),S=[];for(const V of T.split(`
14
- `)){const $=V.trim();if(!$||$.startsWith("#"))continue;const k=$.indexOf("=");if(k===-1)continue;const W=$.slice(0,k).trim();let D=$.slice(k+1).trim();(D.startsWith('"')&&D.endsWith('"')||D.startsWith("'")&&D.endsWith("'"))&&(D=D.slice(1,-1)),W&&S.push({key:W,value:D})}if(S.length===0){E.error(g);return}const M=[...t];for(const V of S){const $=M.findIndex(k=>k.key===V.key);$!==-1?M[$]=V:M.push(V)}e(M),E.success(c(S.length))}catch{E.error(y)}},O=t.some(T=>T.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:p}),s.jsx("span",{className:"typography-micro text-muted-foreground",children:b})]}),s.jsxs(B,{variant:"ghost",size:"xs",className:"!font-normal gap-1 text-muted-foreground",onClick:w,type:"button",title:l,children:[s.jsx(F,{name:"clipboard",className:"h-3 w-3"}),i]})]}),s.jsx("div",{className:"space-y-1.5",children:t.map((T,S)=>s.jsxs("div",{className:"flex items-center gap-2",children:[s.jsx(He,{value:T.key,onChange:M=>j(S,"key",a(M.target.value)),placeholder:n,className:r,"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:m.has(S)?"text":"password",value:T.value,onChange:M=>j(S,"value",M.target.value),placeholder:d,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:()=>h(S),className:"absolute right-2 text-muted-foreground/60 hover:text-muted-foreground",title:m.has(S)?C:f,children:m.has(S)?s.jsx(F,{name:"eye-off",className:"h-3.5 w-3.5"}):s.jsx(F,{name:"eye",className:"h-3.5 w-3.5"})})]}),s.jsx(B,{size:"sm",variant:"ghost",className:"h-7 w-7 px-0 shrink-0 text-muted-foreground hover:text-[var(--status-error)]",onClick:()=>I(S),"aria-label":N,children:s.jsx(F,{name:"delete-bin",className:"h-3.5 w-3.5"})})]},S))}),s.jsxs(B,{variant:"outline",size:"xs",className:"!font-normal gap-1.5",onClick:R,type:"button",children:[s.jsx(F,{name:"add",className:"h-3.5 w-3.5"}),P]}),O&&s.jsx("p",{className:"typography-micro text-muted-foreground/60",children:x})]})},Yi=t=>{const e=ut.c(14),{status:a,enabled:n,getStatusLabel:r,variant:i}=t,l=i===void 0?"compact":i;if(!n||!a)return null;let g,c;if(e[0]!==r||e[1]!==a||e[2]!==l){c=Symbol.for("react.early_return_sentinel");e:{const d={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 C=fe("typography-micro font-medium rounded-full px-2 py-0.5",d.text,d.bg);let f;e[5]!==r||e[6]!==a?(f=r(a),e[5]=r,e[6]=a,e[7]=f):f=e[7],c=s.jsxs("span",{className:C,children:["● ",f]});break e}g=fe("typography-micro font-medium",d.text)}e[0]=r,e[1]=a,e[2]=l,e[3]=g,e[4]=c}else g=e[3],c=e[4];if(c!==Symbol.for("react.early_return_sentinel"))return c;let y;e[8]!==r||e[9]!==a?(y=r(a),e[8]=r,e[9]=a,e[10]=y):y=e[10];let p;return e[11]!==g||e[12]!==y?(p=s.jsxs("span",{className:g,children:["● ",y]}),e[11]=g,e[12]=y,e[13]=p):p=e[13],p},cp=(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")}},dp=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)]"}},up=(t,e,a,n)=>!!(t==="failed"||t==="needs_auth"||t==="needs_client_registration"||e||a||n),pp=async t=>{const e=await yt(`/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},Aa=async t=>{typeof t!="string"||!t.trim()||await yt(`/api/mcp/auth/pending?state=${encodeURIComponent(t.trim())}`,{method:"DELETE"}).catch(()=>{})},li=(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},mp=(t,e)=>{const a=typeof e=="string"&&e.trim()?e.trim():"__global__";return`${t??"__none__"}::${a}`},gp=()=>{const{t}=tt(),e=o.useCallback((oe,ct)=>t(oe,ct),[t]),{selectedMcpName:a,mcpDraft:n,setMcpDraft:r,setSelectedMcp:i,getMcpByName:l,createMcp:g,updateMcp:c,deleteMcp:y}=ya(Us(oe=>({selectedMcpName:oe.selectedMcpName,mcpDraft:oe.mcpDraft,setMcpDraft:oe.setMcpDraft,setSelectedMcp:oe.setSelectedMcp,getMcpByName:oe.getMcpByName,createMcp:oe.createMcp,updateMcp:oe.updateMcp,deleteMcp:oe.deleteMcp}))),p=_s(),b=o.useMemo(()=>cs(),[]),d=Ks(oe=>oe.getStatusForDirectory(p)),C=Ks(oe=>oe.getDiagnosticForDirectory(p)),f=Ks(oe=>oe.refresh),P=Ks(oe=>oe.connect),x=Ks(oe=>oe.disconnect),N=Ks(oe=>oe.completeAuth),m=Ks(oe=>oe.clearAuth),A=Ks(oe=>oe.testConnection),R=Vn(oe=>oe.changes),I=ya(oe=>wl(oe,p)),j=a?l(a,p):null,h=!!(n&&n.name===a&&!j),[w,O]=o.useState(""),[T,S]=o.useState("user"),[M,V]=o.useState("local"),[$,k]=o.useState([]),[W,D]=o.useState(""),[L,J]=o.useState([]),[ee,U]=o.useState([]),[re,_]=o.useState(!0),[H,z]=o.useState(""),[K,te]=o.useState(""),[Y,ne]=o.useState(""),[me,de]=o.useState(""),[xe,ae]=o.useState(""),[le,ge]=o.useState(!0),[Ae,Se]=o.useState(!1),[Ce,he]=o.useState(!1),[_e,Ue]=o.useState(!1),[ke,Oe]=o.useState(!1),[Ve,We]=o.useState(!1),[ve,Z]=o.useState(!1),[se,ye]=o.useState(!1),[be,Re]=o.useState(!1),[Fe,Ke]=o.useState(null),[Ee,we]=o.useState(null),[Ze,pe]=o.useState(""),[Ne,Le]=o.useState(!1),Xe=o.useRef(0),q=o.useRef(!1),[je,Ie]=o.useState(!1),[Je,ot]=o.useState(!1),[st,mt]=o.useState(""),[vt,G]=o.useState(null),Ge=o.useMemo(()=>mp(a,p),[p,a]),nt=o.useRef(Ge),lt=o.useRef(null),ht=o.useCallback(()=>{Ke(null),we(null),pe(""),Le(!1),Xe.current=0,Re(!1),We(!1),Z(!1),q.current=!1},[]),Lt=o.useCallback(()=>{mt(""),G(null),ot(!0)},[]),et=o.useCallback(async()=>{try{const oe=await navigator.clipboard.readText();mt(oe),G(null)}catch{E.error(t("settings.mcp.page.toast.clipboardReadFailed"))}},[t]),ft=o.useCallback(()=>{const oe=ap(st,{fallbackName:w});if(!oe.ok){G(oe.error);return}const xt=ip(oe,{name:w,scope:T,type:M,command:$,url:W,environment:L,headers:ee,oauthEnabled:re,oauthClientId:H,oauthClientSecret:K,oauthScope:Y,oauthRedirectUri:me,timeout:xe,enabled:le},{isNewServer:h});O(xt.name),V(xt.type),k(xt.command??[]),D(xt.url??""),J(xt.environment??[]),U(xt.headers??[]),_(xt.oauthEnabled??!1),z(xt.oauthClientId??""),te(xt.oauthClientSecret??""),ne(xt.oauthScope??""),de(xt.oauthRedirectUri??""),ae(xt.timeout??""),ge(xt.enabled??!0),ot(!1),mt(""),G(null),E.success(t("settings.mcp.page.toast.configImported"))},[st,w,T,M,$,W,L,ee,re,H,K,Y,me,xe,le,h,t]);o.useEffect(()=>{if(h&&n){O(n.name),S(n.scope||"user"),V(n.type),k(n.command),D(n.url),J(n.environment),U(n.headers),_(n.oauthEnabled),z(n.oauthClientId),te(n.oauthClientSecret),ne(n.oauthScope),de(n.oauthRedirectUri),ae(n.timeout),ge(n.enabled),Ie(!1),lt.current={mcpType:n.type,command:n.command,url:n.url,envEntries:n.environment,headerEntries:n.headers,oauthEnabled:n.oauthEnabled,oauthClientId:n.oauthClientId,oauthClientSecret:n.oauthClientSecret,oauthScope:n.oauthScope,oauthRedirectUri:n.oauthRedirectUri,timeout:n.timeout,enabled:n.enabled};return}if(j){S(j.scope==="project"?"project":"user");const oe=Kr(j.environment),ct=j.type==="remote"?j:null,xt=Kr(ct?.headers),Qt=ct?.oauth,Yt=Qt&&typeof Qt=="object"?Qt:null,Bt=Qt!==!1,rs=j.type,ws=rs==="local"?j.command??[]:[],ss=rs==="remote"?j.url??"":"",jt=typeof ct?.timeout=="number"&&Number.isFinite(ct.timeout)?String(ct.timeout):"";V(rs),k(ws),D(ss),J(oe),U(xt),_(Bt),z(Bt?Yt?.clientId??"":""),te(Bt?Yt?.clientSecret??"":""),ne(Bt?Yt?.scope??"":""),de(Bt?Yt?.redirectUri??"":""),ae(jt),ge(j.enabled),Ie(!1),lt.current={mcpType:rs,command:ws,url:ss,envEntries:oe,headerEntries:xt,oauthEnabled:Bt,oauthClientId:Bt?Yt?.clientId??"":"",oauthClientSecret:Bt?Yt?.clientSecret??"":"",oauthScope:Bt?Yt?.scope??"":"",oauthRedirectUri:Bt?Yt?.redirectUri??"":"",timeout:jt,enabled:j.enabled}}},[j,h,n]);const bt=o.useMemo(()=>{const oe=lt.current;return oe?M!==oe.mcpType||le!==oe.enabled||JSON.stringify($)!==JSON.stringify(oe.command)||W!==oe.url||JSON.stringify(L)!==JSON.stringify(oe.envEntries)||JSON.stringify(ee)!==JSON.stringify(oe.headerEntries)||re!==oe.oauthEnabled||H!==oe.oauthClientId||K!==oe.oauthClientSecret||Y!==oe.oauthScope||me!==oe.oauthRedirectUri||xe!==oe.timeout:!1},[M,$,W,L,ee,re,H,K,Y,me,xe,le]),Be=o.useMemo(()=>[{id:"local",label:t("settings.mcp.page.connection.kindCommand"),icon:s.jsx(F,{name:"terminal",className:"h-3.5 w-3.5"})},{id:"remote",label:t("settings.mcp.page.connection.kindLink"),icon:s.jsx(F,{name:"global",className:"h-3.5 w-3.5"})}],[t]),Et=o.useCallback(oe=>{V("remote"),D(oe),k([])},[]),Me=o.useCallback(oe=>{D(oe);const ct=oe.trim();ct&&!/^[a-z][a-z0-9+.-]*:\/\//i.test(ct)&&/\s/.test(ct)&&(V("local"),k(Vl(ct)),D(""))},[]),wt=async()=>{const oe=h?w.trim():a??"";if(!oe){E.error(t("settings.mcp.page.toast.nameRequired"));return}if(h&&I.some(xt=>xt.name===oe)){E.error(t("settings.mcp.page.toast.serverNameExists"));return}if(M==="local"&&$.filter(Boolean).length===0){E.error(t("settings.mcp.page.toast.localCommandRequired"));return}if(M==="remote"&&!W.trim()){E.error(t("settings.mcp.page.toast.remoteUrlRequired"));return}const ct={name:oe,scope:T,type:M,command:$,url:W,environment:L,headers:ee,oauthEnabled:re,oauthClientId:H,oauthClientSecret:K,oauthScope:Y,oauthRedirectUri:me,timeout:xe,enabled:le};Se(!0);try{const xt=h?await g(ct,p):await c(oe,ct,p);xt.ok?(await Aa(Ee),ht(),h&&(r(null),i(oe)),await f({directory:p,silent:!0}),xt.reloadFailed?E.warning(xt.message||t(h?"settings.mcp.page.toast.serverCreatedReloadFailed":"settings.mcp.page.toast.savedReloadFailed"),{description:xt.warning||t("settings.mcp.page.toast.retryRefreshHint")}):xt.restartDeferred?E.success(t("settings.view.pendingRestart.saved")):E.success(xt.message||t(h?"settings.mcp.page.toast.serverCreatedReloading":"settings.mcp.page.toast.savedReloading"))):E.error(t("settings.mcp.page.toast.saveFailed"))}catch(xt){E.error(xt instanceof Error?xt.message:t("settings.mcp.page.toast.unexpectedError"))}finally{Se(!1)}},Q=async()=>{if(!a)return;Ue(!0);const oe=await y(a,p);oe.ok?(await Aa(Ee),ht(),oe.reloadFailed?E.warning(oe.message||t("settings.mcp.page.toast.serverDeletedReloadFailed",{name:a}),{description:oe.warning||t("settings.mcp.page.toast.refreshListIfStale")}):E.success(oe.message||t("settings.mcp.page.toast.serverDeleted",{name:a})),he(!1)):E.error(t("settings.mcp.page.toast.deleteFailed")),Ue(!1)},ue=async()=>{if(a){Oe(!0);try{if(d[a]?.status==="connected")await x(a,p),E.success(t("settings.mcp.page.toast.disconnected"));else{await P(a,p),await f({directory:p,silent:!0});const ct=Ks.getState().getStatusForDirectory(p)[a];ct?.status==="connected"?E.success(t("settings.mcp.page.toast.connected")):ct?.status==="needs_auth"?E.message(t("settings.mcp.page.toast.connectionNeedsAuthorization")):ct?.status==="needs_client_registration"?E.message(t("settings.mcp.page.toast.connectionNeedsClientRegistration")):ct?.status==="failed"?E.error(ct.error||t("settings.mcp.page.toast.connectionFailed")):E.message(t("settings.mcp.page.toast.connectionAttemptFinished"));return}await f({directory:p,silent:!0})}catch(oe){E.error(oe instanceof Error?oe.message:t("settings.mcp.page.toast.connectionFailed"))}finally{Oe(!1)}}},De=o.useCallback(()=>h?(E.error(t("settings.mcp.page.toast.createServerBeforeLiveActions")),!1):bt?(E.error(t("settings.mcp.page.toast.saveBeforeLiveActions")),!1):!0,[bt,h,t]),Pe=o.useCallback(async(oe=!1)=>{try{await f({directory:p,silent:oe})}catch(ct){oe||E.error(ct instanceof Error?ct.message:t("settings.mcp.page.toast.refreshStatusFailed"))}},[p,f,t]);o.useEffect(()=>{Pe(!0)},[Pe]),o.useEffect(()=>{nt.current=Ge,Oe(!1),ye(!1),ht()},[ht,Ge]);const it=o.useCallback(async()=>{if(!a||M!=="remote"||!De())return;We(!0);const oe=Ge;let ct=null;try{const xt=Ks.getState().getStatusForDirectory(p)[a]?.status;q.current=xt==="needs_auth"||xt==="needs_client_registration";const{authorizationUrl:Qt,opened:Yt,nativeFlow:Bt,completion:rs}=await jc({name:a,directory:p});if(Bt){if(nt.current!==oe)return;Ke(null),we(null),Le(!0),Xe.current=0,E.message(t("settings.mcp.page.toast.completeAuthorizationInBrowser")),rs?.then(()=>{nt.current===oe&&(Le(!1),Xe.current=0,q.current=!1,E.success(t("settings.mcp.page.toast.authorizationCompleted")))}).catch(ss=>{nt.current===oe&&(Le(!1),Xe.current=0,q.current=!1,E.error(li(ss,t("settings.mcp.page.toast.authorizationFailed"),e)))});return}const ws=jl(new URL(Qt).searchParams);if(ct=ws,nt.current!==oe||(Ke(Qt),we(ws??null),Le(!0),Xe.current=0,nt.current!==oe))return;Yt?E.message(t(b?"settings.mcp.page.toast.completeAuthorizationInBrowserWithPaste":"settings.mcp.page.toast.completeAuthorizationInBrowser")):E.error(t("settings.mcp.page.toast.openAuthorizationUrlFailed"))}catch(xt){await Aa(ct),nt.current===oe&&E.error(li(xt,t("settings.mcp.page.toast.authorizationStartFailed"),e))}finally{nt.current===oe&&We(!1)}},[p,b,M,De,Ge,a,t,e]),rt=o.useCallback(async()=>{if(!a||!De())return;Z(!0);const oe=Ge;try{if(await m(a,p),nt.current!==oe)return;Ke(null),we(null),pe(""),Le(!1),Xe.current=0,await Aa(Ee),E.success(t("settings.mcp.page.toast.savedAuthorizationRemoved"))}catch(ct){nt.current===oe&&E.error(li(ct,t("settings.mcp.page.toast.clearAuthorizationFailed"),e))}finally{nt.current===oe&&Z(!1)}},[Ee,m,p,De,Ge,a,t,e]),qe=o.useCallback(async()=>{if(!Fe)return;if((await Ka(Fe)).ok){E.success(t("settings.mcp.page.toast.authorizationUrlCopied"));return}E.error(t("settings.mcp.page.toast.authorizationUrlCopyFailed"))},[Fe,t]),Pt=o.useCallback(async()=>{const oe=rp(Ze);if(!oe.code){E.error(t("settings.mcp.page.toast.pasteCallbackOrCodeFirst"));return}const ct=oe.stateKey?await pp(oe.stateKey):null,xt=oe.context??ct,Qt=xt?.name??a,Yt=xt?.directory??p;if(!Qt){E.error(t("settings.mcp.page.toast.missingServerDetails"));return}if(!xt&&!De())return;Re(!0);const Bt=Ge;try{if(await N(Qt,oe.code,Yt),await Aa(oe.stateKey??Ee),nt.current!==Bt)return;pe(""),Ke(null),we(null),Le(!1),Xe.current=0,E.success(Qt===a?t("settings.mcp.page.toast.authorizationCompleted"):t("settings.mcp.page.toast.authorizationCompletedFor",{name:Qt}))}catch(rs){nt.current===Bt&&E.error(li(rs,t("settings.mcp.page.toast.authorizationCompleteFailed"),e))}finally{nt.current===Bt&&Re(!1)}},[Ze,Ee,N,p,De,Ge,a,t,e]),ys=o.useCallback(async()=>{if(!(!a||!De())){if(!le){E.error(t("settings.mcp.page.toast.enableServerBeforeTest"));return}ye(!0);try{const oe=await A(a,p),ct=oe.status?.status;oe.warning?E.warning(oe.warning):ct==="connected"?E.success(t("settings.mcp.page.toast.connectionTestSucceeded")):ct==="needs_auth"?E.message(t("settings.mcp.page.toast.connectionNeedsAuthorization")):ct==="needs_client_registration"?E.message(t("settings.mcp.page.toast.connectionNeedsClientRegistration")):ct==="failed"?E.error(oe.status?.error||oe.error||t("settings.mcp.page.toast.connectionTestFailed")):oe.error?E.error(oe.error):E.message(t("settings.mcp.page.toast.connectionTestFinished"))}catch(oe){E.error(oe instanceof Error?oe.message:t("settings.mcp.page.toast.connectionTestFailed"))}finally{ye(!1)}}},[p,le,De,a,t,A]);if(o.useEffect(()=>{if(!Ne||!a)return;const oe=window.setInterval(()=>{(async()=>{Xe.current+=1,await f({directory:p,silent:!0});const ct=Ks.getState().getStatusForDirectory(p)[a];if(ct){if(q.current&&ct.status!=="needs_auth"&&ct.status!=="needs_client_registration"){Le(!1),Xe.current=0,q.current=!1,Ke(null),pe(""),ct.status==="connected"&&E.success(t("settings.mcp.page.toast.authorizationCompleted"));return}if(!q.current&&ct.status==="failed"){Le(!1),Xe.current=0,q.current=!1,E.error(ct.error||t("settings.mcp.page.toast.authorizationFailed"));return}Xe.current>=30&&(Le(!1),Xe.current=0,q.current=!1,E.message(t("settings.mcp.page.toast.authorizationStillInProgress")))}})()},2e3);return()=>{window.clearInterval(oe)}},[p,Ne,f,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(F,{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=d[a],Os=a?C[a]:void 0,Gt=Xt??Os,is=!h&&!Gt&&R.some(oe=>oe.scope==="mcp"&&oe.id.startsWith(`mcp:${a}:`)),Ht=Xt?.status==="connected",bs=Xt?.status==="needs_auth"||Xt?.status==="needs_client_registration",gs=b||!a?null:kc(a),hs=async()=>{if(gs)try{await navigator.clipboard.writeText(gs),E.success(t("settings.mcp.page.toast.copiedCallbackUrl"))}catch{E.error(t("settings.mcp.page.toast.clipboardWriteFailed"))}},ds=cp(Gt?.status,e,Gt&&"error"in Gt?Gt.error:void 0),Es=oe=>{switch(oe){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 oe}};return s.jsxs(s.Fragment,{children:[s.jsxs(es,{title:h?t("settings.mcp.page.header.newServer"):a,titleAccessory:h?void 0:s.jsx(Yi,{status:is?"awaiting_restart":Gt?.status,enabled:le,getStatusLabel:Es,variant:"pill"}),description:h?t("settings.mcp.page.header.configureNewServer"):t("settings.mcp.page.header.transport",{type:t(M==="local"?"settings.mcp.page.transport.local":"settings.mcp.page.transport.remote")}),headerEnd:!h&&!is?s.jsxs("div",{className:"flex flex-wrap items-center gap-2",children:[s.jsx(B,{variant:Ht?"outline":"default",size:"xs",className:"!font-normal",onClick:ue,disabled:ke||!le,children:t(ke?"settings.mcp.page.actions.working":Ht?"settings.mcp.page.actions.disconnect":"settings.mcp.page.actions.connect")}),M==="remote"&&s.jsxs(s.Fragment,{children:[s.jsx(B,{variant:bs?"default":"outline",size:"xs",className:"!font-normal",onClick:()=>{it()},disabled:Ve||!le,children:t(Ve?"settings.mcp.page.actions.starting":Ht?"settings.mcp.page.actions.reauthorize":"settings.mcp.page.actions.authorize")}),s.jsx(B,{variant:"ghost",size:"xs",className:"!font-normal gap-1 text-muted-foreground",onClick:()=>{rt()},disabled:ve||!le,children:t(ve?"settings.mcp.page.actions.clearing":"settings.mcp.page.actions.clearAuth")})]}),Ht&&s.jsx(B,{variant:"ghost",size:"xs",className:"!font-normal gap-1 text-muted-foreground",onClick:()=>{ys()},disabled:se||!le,children:t(se?"settings.mcp.page.actions.testing":"settings.mcp.page.actions.test")})]}):void 0,showSaveStatus:!1,children:[is&&s.jsx(ze,{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:Tt,children:t("settings.mcp.page.status.runtimeStatus")}),s.jsx(Yi,{status:"awaiting_restart",enabled:le,getStatusLabel:Es})]}),s.jsx("p",{className:"typography-meta text-muted-foreground",children:t("settings.mcp.page.status.description.awaitingRestart")})]})})}),!h&&!is&&up(Gt?.status,Fe,bs,Ne)&&s.jsx(ze,{divider:!1,children:s.jsxs("div",{className:fe("rounded-lg border p-3",dp(Gt?.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:Tt,children:t("settings.mcp.page.status.runtimeStatus")}),s.jsx(Yi,{status:Gt?.status,enabled:le,getStatusLabel:Es})]}),s.jsx("p",{className:"typography-meta text-muted-foreground",children:ds}),s.jsx("p",{className:"typography-micro text-muted-foreground/80",children:T==="project"?t("settings.mcp.page.status.projectScopedTo",{directory:p??t("settings.mcp.page.status.activeProject")}):t("settings.mcp.page.status.userScoped")})]}),s.jsx("div",{className:"flex flex-wrap items-center gap-2",children:!Ht&&s.jsx(B,{variant:"outline",size:"xs",className:"!font-normal",onClick:()=>{ys()},disabled:se||!le,children:t(se?"settings.mcp.page.actions.testing":"settings.mcp.page.actions.testConnection")})}),Gt?.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(Zs,{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")})]}),gs&&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:gs}),s.jsxs(B,{variant:"outline",size:"xs",className:"!font-normal",onClick:()=>{hs()},children:[s.jsx(F,{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:H,onChange:oe=>{z(oe.target.value),_(!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:K,onChange:oe=>{te(oe.target.value),_(!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")})]}),Fe&&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:Fe}),s.jsxs("div",{className:"flex flex-wrap items-center gap-2",children:[s.jsxs(B,{variant:"outline",size:"xs",className:"!font-normal",onClick:()=>{Pn(Fe)},children:[s.jsx(F,{name:"external-link",className:"h-3.5 w-3.5"}),t("settings.mcp.page.actions.openInBrowser")]}),s.jsxs(B,{variant:"outline",size:"xs",className:"!font-normal",onClick:()=>{qe()},children:[s.jsx(F,{name:"clipboard",className:"h-3.5 w-3.5"}),t("settings.mcp.page.actions.copyLink")]})]})]})}),b&&M==="remote"&&(bs||Ne||Fe)&&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(Zs,{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(Ts,{value:Ze,onChange:oe=>pe(oe.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(B,{variant:"outline",size:"xs",className:"!font-normal",onClick:()=>{Pt()},disabled:be,children:t(be?"settings.mcp.page.actions.completing":"settings.mcp.page.actions.completeAuthorization")})})]})})]}),Ne&&s.jsx("p",{className:"mt-4 typography-micro text-muted-foreground",children:t("settings.mcp.page.auth.waitingForOpenCode")})]})}),s.jsxs(ze,{title:t("settings.mcp.page.server.title"),divider:!1,settingsItem:"mcp.server",contentClassName:"space-y-0",titleAccessory:h?s.jsxs(B,{variant:"ghost",size:"xs",className:"!font-normal gap-1.5 text-muted-foreground",onClick:Lt,type:"button",title:t("settings.mcp.page.server.importJsonTitle"),children:[s.jsx(F,{name:"file-code",className:"h-3.5 w-3.5"}),t("settings.mcp.page.server.importJson")]}):null,children:[h&&s.jsxs(Rt,{label:t("settings.mcp.page.server.name"),controlClassName:"flex-wrap @xl:w-auto @xl:flex-1",children:[s.jsx(He,{value:w,onChange:oe=>O(oe.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(St,{value:T,onValueChange:oe=>S(oe),children:[s.jsxs(Ct,{size:Ft,className:"!h-7 min-w-0 max-w-full gap-1.5 px-2",children:[s.jsx(F,{name:T==="user"?"user-3":"folder",className:"h-3.5 w-3.5 shrink-0"}),s.jsx("span",{className:"truncate",children:t(T==="user"?"settings.mcp.page.scope.everywhere":"settings.mcp.page.scope.thisProject")})]}),s.jsxs(It,{align:"end",children:[s.jsx(at,{value:"user",children:s.jsxs("div",{className:"flex items-center gap-2",children:[s.jsx(F,{name:"user-3",className:"h-3.5 w-3.5"}),s.jsx("span",{children:t("settings.mcp.page.scope.everywhere")})]})}),s.jsx(at,{value:"project",children:s.jsxs("div",{className:"flex items-center gap-2",children:[s.jsx(F,{name:"folder",className:"h-3.5 w-3.5"}),s.jsx("span",{children:t("settings.mcp.page.scope.thisProject")})]})})]})]})]}),s.jsx(dt,{checked:le,onChange:ge,label:t("settings.mcp.page.server.enable"),ariaLabel:t("settings.mcp.page.server.enableAria")})]}),s.jsxs(ze,{title:t("settings.mcp.page.connection.title"),description:t("settings.mcp.page.connection.description"),settingsItem:"mcp.command",contentClassName:"space-y-2",children:[s.jsx(Ir,{items:Be,activeId:M,onSelect:oe=>V(oe),layoutMode:"fit",variant:"active-pill",activePillLowercase:!1,className:"h-10"}),M==="local"?s.jsx(op,{value:$,onChange:k,preview:oe=>t("settings.mcp.page.connection.previewArgs",{count:oe}),onDetectUrl:Et}):s.jsx(He,{value:W,onChange:oe=>Me(oe.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(M==="local"?"settings.mcp.page.connection.hintCommand":"settings.mcp.page.connection.hintLink")})]}),M==="remote"&&s.jsx(ze,{title:t("settings.mcp.page.advanced.title"),settingsItem:"mcp.advanced",children:s.jsxs(An,{open:je,onOpenChange:Ie,children:[s.jsxs(Tn,{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:["(",ee.length," ",t("settings.mcp.page.advanced.headers"),xe?` · ${xe}ms`:"",")"]})]}),je?s.jsx(F,{name:"arrow-down-s",className:"h-4 w-4 text-muted-foreground group-hover:text-foreground transition-colors"}):s.jsx(F,{name:"arrow-right-s",className:"h-4 w-4 text-muted-foreground group-hover:text-foreground transition-colors"})]}),s.jsx(En,{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:Tt,children:t("settings.mcp.page.advanced.timeoutMs")}),s.jsx(Jt,{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:xe,onChange:oe=>ae(oe.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(Zs,{as:"div",className:"mb-2",children:[t("settings.mcp.page.advanced.requestHeaders"),ee.length>0&&s.jsxs("span",{className:"ml-1.5 typography-micro text-muted-foreground font-normal",children:["(",ee.length,")"]})]}),s.jsx(yo,{value:ee,onChange:U,keyTransform:oe=>oe.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:oe=>t("settings.mcp.page.toast.importedVariablesCount",{count:oe}),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(ze,{title:t("settings.mcp.page.env.title"),description:t("settings.mcp.page.env.description"),titleAccessory:L.length>0?s.jsxs("span",{className:"typography-micro text-muted-foreground font-normal",children:["(",L.length,")"]}):null,settingsItem:"mcp.environment",children:L.length===0?s.jsxs(B,{variant:"outline",size:"xs",className:"!font-normal gap-1.5",onClick:()=>J([{key:"",value:""}]),children:[s.jsx(F,{name:"add",className:"h-3.5 w-3.5"}),t("settings.mcp.page.env.addEnvironmentVariable")]}):s.jsx(yo,{value:L,onChange:J,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:oe=>t("settings.mcp.page.toast.importedVariablesCount",{count:oe}),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(B,{onClick:wt,disabled:Ae||!bt&&!h,size:"xs",className:"!font-normal",children:t(Ae?"settings.common.actions.saving":h?"settings.common.actions.create":"settings.common.actions.saveChanges")}),!h&&s.jsx(B,{variant:"destructive",size:"xs",className:"!font-normal",onClick:()=>he(!0),children:t("settings.common.actions.delete")})]})," "]}),s.jsx(Kt,{open:Je,onOpenChange:oe=>{oe||(ot(!1),mt(""),G(null))},children:s.jsxs(zt,{className:"max-w-md",children:[s.jsxs(_t,{children:[s.jsx($t,{children:t("settings.mcp.page.importDialog.title")}),s.jsx(Vt,{children:t("settings.mcp.page.importDialog.description")})]}),s.jsxs("div",{className:"space-y-3",children:[s.jsx(Ts,{value:st,onChange:oe=>{mt(oe.target.value),G(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"}),vt&&s.jsx("p",{className:"typography-micro text-[var(--status-error)]",children:vt}),s.jsx("div",{className:"flex flex-wrap items-center gap-2",children:s.jsxs(B,{variant:"outline",size:"xs",className:"!font-normal gap-1",onClick:et,type:"button",children:[s.jsx(F,{name:"clipboard",className:"h-3.5 w-3.5"}),t("settings.mcp.page.importDialog.pasteFromClipboard")]})})]}),s.jsxs(ts,{children:[s.jsx(B,{variant:"outline",onClick:()=>{ot(!1),mt(""),G(null)},className:"text-foreground",children:t("settings.common.actions.cancel")}),s.jsx(B,{onClick:ft,disabled:!st.trim(),size:"sm",children:t("settings.common.actions.import")})]})]})}),s.jsx(Kt,{open:Ce,onOpenChange:oe=>{!oe&&!_e&&he(!1)},children:s.jsxs(zt,{className:"max-w-md",children:[s.jsxs(_t,{children:[s.jsx($t,{children:t("settings.mcp.page.deleteDialog.title",{name:a??""})}),s.jsxs(Vt,{children:[t("settings.mcp.page.deleteDialog.descriptionPrefix")," ",s.jsx("code",{className:"text-foreground",children:"opencode.json"}),"."," ",t("settings.mcp.page.deleteDialog.descriptionSuffix")]})]}),s.jsxs(ts,{children:[s.jsx(B,{variant:"outline",onClick:()=>he(!1),disabled:_e,className:"text-foreground",children:t("settings.common.actions.cancel")}),s.jsx(B,{variant:"destructive",size:"sm",onClick:Q,disabled:_e,children:t(_e?"settings.mcp.page.actions.deleting":"settings.common.actions.delete")})]})]})})]})};function hp(t){return t.trim().length>0}function fp(t){return t.trimEnd()}function xp(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 vi=()=>{try{const e=Ws.getState().getActiveProject?.();if(e?.path?.trim())return e.path.trim();const a=fn.getDirectory();if(a?.trim())return a.trim()}catch(t){console.warn("[PluginsStore] Error resolving config directory:",t)}return null},vp=800,yp=5e3,bp="__default__",mr=new Map,Zi=new Map,wp=1500,Bl=t=>t?.trim()||bp,jp=t=>{mr.delete(Bl(t))},ms=Kl()(Yd(Zd((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=vi(),r=Bl(n),i=Date.now(),l=mr.get(r)??0,g=e().entries.length>0||e().files.length>0;if(!a?.force&&g&&i-l<yp)return!0;const c=Zi.get(r);if(!a?.force&&c)return c;const y=(async()=>{t({isLoading:!0});try{const p=await yt(kn("/api/config/plugins",n),{headers:Ta(n)});if(!p.ok)throw new Error("Failed to load plugins");const b=await yi(p);return t({entries:b.entries??[],files:b.files??[],isLoading:!1}),mr.set(r,Date.now()),a?.force||e().loadRegistryInfo(),!0}catch(p){return console.error("[PluginsStore] Failed to load plugins:",p),t({isLoading:!1}),!1}})();Zi.set(r,y);try{return await y}finally{Zi.delete(r)}},loadRegistryInfo:async a=>{const n=Np(a?.specs??e().entries.map(r=>r.spec));if(n.length===0)return t({isLoadingRegistry:!1}),!0;t({isLoadingRegistry:!0});try{const r=vi(),i={...e().registryInfo};for(const l of Sp(n)){const g=await yt(kp(l,a?.force===!0,r),{headers:Ta(r)});if(!g.ok)throw new Error("Failed to load plugin registry info");const c=await yi(g);for(const y of c.results??[])i[y.spec]=y}return t({registryInfo:i,isLoadingRegistry:!1}),!0}catch(r){return console.error("[PluginsStore] Failed to load plugin registry info:",r),t({isLoadingRegistry:!1}),!1}},updateToLatest:async a=>{const n=e().entries.find(i=>i.id===a);if(!n)return{ok:!1};const r=e().registryInfo[n.spec];return!r||r.kind!=="npm-ok"||!r.hasUpdate||!r.latestVersion?{ok:!1}:await e().updateEntry(a,{spec:`${r.name}@${r.latestVersion}`})},createEntry:async a=>{const n=await da("Creating plugin entry…",async r=>await yt(kn("/api/config/plugins/entry",r),{method:"POST",headers:ci(r),body:JSON.stringify(bo(a))}),e,{restartId:a.spec});return n.ok&&e().loadRegistryInfo({specs:[a.spec],force:!0}),n},updateEntry:async(a,n)=>{const r=e().entries.find(g=>g.id===a)?.spec,i=n.spec??r,l=await da("Updating plugin entry…",async g=>await yt(kn(`/api/config/plugins/entry/${encodeURIComponent(a)}`,g),{method:"PATCH",headers:ci(g),body:JSON.stringify(bo(n))}),e,{restartId:a});return l.ok&&i&&e().loadRegistryInfo({specs:[i],force:!0}),l},deleteEntry:async a=>{const n=e().entries.find(i=>i.id===a),r=await da("Deleting plugin entry…",async i=>await yt(kn(`/api/config/plugins/entry/${encodeURIComponent(a)}`,i),{method:"DELETE",headers:Ta(i)}),e,{restartId:a});if(r.ok&&e().selectedId===a&&t({selectedId:null}),r.ok&&n){const i={...e().registryInfo};delete i[n.spec],t({registryInfo:i})}return r},readFile:async a=>{try{const n=vi(),r=await yt(kn(`/api/config/plugins/file/${encodeURIComponent(a)}`,n),{headers:Ta(n)});if(!r.ok)throw new Error("Failed to read plugin file");return await yi(r)}catch(n){return console.error("[PluginsStore] Failed to read plugin file:",n),null}},createFile:async a=>da("Creating plugin file…",async n=>await yt(kn("/api/config/plugins/file",n),{method:"POST",headers:ci(n),body:JSON.stringify(a)}),e,{restartId:a.fileName}),updateFile:async(a,n)=>da("Updating plugin file…",async r=>await yt(kn(`/api/config/plugins/file/${encodeURIComponent(a)}`,r),{method:"PUT",headers:ci(r),body:JSON.stringify(n)}),e,{restartId:a}),deleteFile:async a=>{const n=await da("Deleting plugin file…",async r=>await yt(kn(`/api/config/plugins/file/${encodeURIComponent(a)}`,r),{method:"DELETE",headers:Ta(r)}),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:fd(),partialize:t=>({selectedId:t.selectedId})}),{name:"plugins-store"}));function kn(t,e){const a=e?`?directory=${encodeURIComponent(e)}`:"";return`${t}${a}`}function kp(t,e,a){const n=new URLSearchParams;e&&n.set("refresh","true"),a&&n.set("directory",a);const r=n.toString();return`/api/config/plugins/registry?${`specs=${t.map(encodeURIComponent).join(",")}`}${r?`&${r}`:""}`}function Np(t){return Array.from(new Set(t.map(e=>e.trim()).filter(Boolean)))}function Sp(t){const e=[];let a=[],n=0;for(const r of t){const i=encodeURIComponent(r),l=a.length===0?i.length:n+1+i.length;a.length>0&&l>wp?(e.push(a),a=[r],n=i.length):(a.push(r),n=l)}return a.length>0&&e.push(a),e}function Ta(t){return t?{"x-opencode-directory":t}:void 0}function ci(t){return{"Content-Type":"application/json",...t?{"x-opencode-directory":t}:{}}}function bo(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 da(t,e,a,n){try{const r=vi(),i=await e(r),l=await yi(i).catch(()=>null);if(!i.ok)throw new Error(l?.error||"Failed to update plugin configuration");return jp(r),l?.requiresManualRestart?(await a().loadPlugins({force:!0}),{ok:!0,requiresManualRestart:!0,reloadFailed:l?.reloadFailed===!0,message:l?.message,warning:l?.warning}):vl(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&&(Sc(t),await Cc({message:l.message,delayMs:l.reloadDelayMs??vp,scopes:["all"]})),await a().loadPlugins({force:!0}),{ok:!0,reloadFailed:l?.reloadFailed===!0,message:l?.message,warning:l?.warning})}catch(r){return console.error("[PluginsStore] Failed to update plugin configuration:",r),{ok:!1}}}async function yi(t){return await t.json()}const Cp=/^[a-z0-9][a-z0-9-_.]*\.(js|ts|mjs|cjs)$/;function Ip(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 Pp=({open:t,onOpenChange:e,defaultScope:a="user"})=>{const{t:n}=tt(),r=ms(k=>k.createEntry),i=ms(k=>k.createFile),[l,g]=o.useState("npm"),[c,y]=o.useState(""),[p,b]=o.useState(""),[d,C]=o.useState(""),[f,P]=o.useState(""),[x,N]=o.useState(a),[m,A]=o.useState(!1),R=o.useCallback(()=>{y(""),b(""),C(""),P(""),N(a)},[a]);o.useEffect(()=>{t&&(g("npm"),R())},[t,R]);const I=k=>{k!==l&&(g(k),R())},j=o.useMemo(()=>Ip(p),[p]),h=!j.ok,w=l==="file"&&d.trim()!==""&&!Cp.test(d.trim()),O=(l==="npm"||l==="path")&&c.trim()==="",T=l==="file"&&f.trim()==="",S=l==="file"&&d.trim()==="",M=m||h||l==="npm"&&O||l==="path"&&O||l==="file"&&(S||w||T),V=async()=>{if(!M){A(!0);try{let k;l==="file"?k=await i({fileName:d.trim(),content:f,scope:x}):k=await r({spec:c.trim(),options:j.ok?j.value:void 0,scope:x}),k.ok?(k.restartDeferred?E.success(n("settings.view.pendingRestart.saved")):E.success(k.message||n("settings.plugins.toast.created")),k.reloadFailed&&E.warning(n("settings.plugins.toast.reloadFailed")),e(!1)):E.error(k.message||n("settings.plugins.sidebar.toast.deleteFailed"))}finally{A(!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(Kt,{open:t,onOpenChange:k=>{!k&&m||e(k)},children:s.jsxs(zt,{className:"max-w-xl",children:[s.jsxs(_t,{children:[s.jsx($t,{children:n("settings.plugins.dialog.add.title")}),s.jsx(Vt,{children:n("settings.plugins.sidebar.empty.description")})]}),s.jsx(Ir,{items:$,activeId:l,onSelect:k=>I(k),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:k=>y(k.target.value),placeholder:n("settings.plugins.page.field.spec.placeholder"),"aria-invalid":O?!1:void 0,disabled:m}),O&&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(Ts,{id:"plugin-options",value:p,onChange:k=>b(k.target.value),rows:5,className:"font-mono",hasError:h,disabled:m}),h&&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:d,onChange:k=>C(k.target.value),placeholder:"my-plugin.ts","aria-invalid":w||void 0,disabled:m}),w&&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(Ts,{id:"plugin-content",value:f,onChange:k=>P(k.target.value),rows:16,className:"font-mono",disabled:m})]})]}),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(k=>{const W=x===k,D=n(k==="user"?"settings.plugins.scope.user":"settings.plugins.scope.project");return s.jsxs("button",{type:"button",onClick:()=>N(k),disabled:m,className:"flex items-center gap-2 py-1 text-left disabled:opacity-50",children:[s.jsx(jr,{checked:W,onChange:()=>N(k),ariaLabel:D}),s.jsx("span",{className:fe("typography-ui-label font-normal",W?"text-foreground":"text-foreground/60"),children:D})]},k)})})]})]}),s.jsxs(ts,{children:[s.jsx(B,{size:"sm",variant:"ghost",onClick:()=>e(!1),disabled:m,children:n("settings.plugins.dialog.add.action.cancel")}),s.jsxs(B,{size:"sm",onClick:()=>{V()},disabled:M,children:[m?s.jsx(F,{name:"loader-4",className:"h-3.5 w-3.5 animate-spin"}):null,n("settings.plugins.dialog.add.action.submit")]})]})]})})},Ap=t=>{const e=ut.c(33),{spec:a}=t;let n;e[0]!==a?(n=g=>g.registryInfo[a],e[0]=a,e[1]=n):n=e[1];const r=ms(n),{t:i}=tt();if(!r)return null;const l=Tp;switch(r.kind){case"npm-ok":{if(!r.hasUpdate||!r.latestVersion)return null;let g;e[2]===Symbol.for("react.memo_cache_sentinel")?(g=s.jsx(F,{name:"arrow-up-s",className:"h-3 w-3"}),e[2]=g):g=e[2];let c;e[3]!==r.latestVersion?(c=s.jsxs("span",{className:"inline-flex items-center gap-0.5 text-[var(--status-success)]",children:[g,r.latestVersion]}),e[3]=r.latestVersion,e[4]=c):c=e[4];let y;return e[5]!==r.currentVersion||e[6]!==r.latestVersion||e[7]!==i||e[8]!==c?(y=l(c,i("settings.plugins.registry.badge.update.tooltip",{current:r.currentVersion??"",latest:r.latestVersion})),e[5]=r.currentVersion,e[6]=r.latestVersion,e[7]=i,e[8]=c,e[9]=y):y=e[9],y}case"npm-missing-version":{let g;e[10]===Symbol.for("react.memo_cache_sentinel")?(g=s.jsx(F,{name:"error-warning",className:"h-3 w-3 text-[var(--status-warning)]"}),e[10]=g):g=e[10];let c;return e[11]!==r.currentVersion||e[12]!==r.name||e[13]!==i?(c=l(g,i("settings.plugins.registry.badge.missingVersion.tooltip",{version:r.currentVersion,name:r.name})),e[11]=r.currentVersion,e[12]=r.name,e[13]=i,e[14]=c):c=e[14],c}case"npm-missing-package":{let g;e[15]===Symbol.for("react.memo_cache_sentinel")?(g=s.jsx(F,{name:"error-warning",className:"h-3 w-3 text-[var(--status-error)]"}),e[15]=g):g=e[15];let c;return e[16]!==r.name||e[17]!==i?(c=l(g,i("settings.plugins.registry.badge.missingPackage.tooltip",{name:r.name})),e[16]=r.name,e[17]=i,e[18]=c):c=e[18],c}case"npm-malformed":{let g;e[19]===Symbol.for("react.memo_cache_sentinel")?(g=s.jsx(F,{name:"error-warning",className:"h-3 w-3 text-[var(--status-error)]"}),e[19]=g):g=e[19];let c;return e[20]!==i?(c=l(g,i("settings.plugins.registry.badge.malformed.tooltip")),e[20]=i,e[21]=c):c=e[21],c}case"npm-network":{let g;e[22]===Symbol.for("react.memo_cache_sentinel")?(g=s.jsx(F,{name:"cloud-off",className:"h-3 w-3 text-muted-foreground"}),e[22]=g):g=e[22];let c;return e[23]!==i?(c=l(g,i("settings.plugins.registry.badge.network.tooltip")),e[23]=i,e[24]=c):c=e[24],c}case"path-missing":{let g;e[25]===Symbol.for("react.memo_cache_sentinel")?(g=s.jsx(F,{name:"error-warning",className:"h-3 w-3 text-[var(--status-error)]"}),e[25]=g):g=e[25];let c;return e[26]!==r.absolutePath||e[27]!==i?(c=l(g,i("settings.plugins.registry.badge.pathMissing.tooltip",{path:r.absolutePath})),e[26]=r.absolutePath,e[27]=i,e[28]=c):c=e[28],c}case"path-unreadable":{let g;e[29]===Symbol.for("react.memo_cache_sentinel")?(g=s.jsx(F,{name:"error-warning",className:"h-3 w-3 text-[var(--status-warning)]"}),e[29]=g):g=e[29];let c;return e[30]!==r.absolutePath||e[31]!==i?(c=l(g,i("settings.plugins.registry.badge.pathUnreadable.tooltip",{path:r.absolutePath})),e[30]=r.absolutePath,e[31]=i,e[32]=c):c=e[32],c}case"path-ok":return null;default:return null}};function Tp(t,e){return s.jsxs(kr,{children:[s.jsx(Nr,{asChild:!0,children:s.jsx("span",{className:"inline-flex shrink-0 items-center gap-0.5 text-xs",children:t})}),s.jsx(kl,{children:e})]})}const Hl=t=>{const e=ut.c(26),{header:a,footer:n,children:r,className:i,variant:l}=t,g=l===void 0?"sidebar":l,c=cs(),y=o.useRef(null),[p,b]=o.useState(!1),[d,C]=o.useState(!1),f=g==="background"||c?"bg-background":"bg-sidebar",P=f==="bg-background"?"var(--surface-background)":"var(--surface-muted)";let x;e[0]===Symbol.for("react.memo_cache_sentinel")?(x=()=>{const M=y.current;if(!M){b(!1),C(!1);return}if(!(M.scrollHeight>M.clientHeight+1)){b(!1),C(!1);return}b(M.scrollTop>1),C(M.scrollTop+M.clientHeight<M.scrollHeight-1)},e[0]=x):x=e[0];const N=x;let m;e[1]===Symbol.for("react.memo_cache_sentinel")?(m=()=>{N()},e[1]=m):m=e[1];let A;e[2]!==r?(A=[r,N],e[2]=r,e[3]=A):A=e[3],o.useEffect(m,A);let R,I;e[4]===Symbol.for("react.memo_cache_sentinel")?(R=()=>{const M=y.current;if(!M)return;const V=()=>N();return M.addEventListener("scroll",V,{passive:!0}),()=>M.removeEventListener("scroll",V)},I=[N],e[4]=R,e[5]=I):(R=e[4],I=e[5]),o.useEffect(R,I);let j;e[6]!==f||e[7]!==i?(j=fe("flex h-full flex-col",f,i),e[6]=f,e[7]=i,e[8]=j):j=e[8];let h;e[9]!==r?(h=s.jsx(vs,{ref:y,outerClassName:"flex-1 min-h-0",className:"space-y-0.5 px-3 py-2 overflow-x-hidden",children:r}),e[9]=r,e[10]=h):h=e[10];let w;e[11]!==P||e[12]!==p?(w=p&&s.jsx("div",{className:"pointer-events-none absolute inset-x-0 top-0 h-4",style:{background:`linear-gradient(to bottom, ${P} 0%, transparent 100%)`}}),e[11]=P,e[12]=p,e[13]=w):w=e[13];let O;e[14]!==P||e[15]!==d?(O=d&&s.jsx("div",{className:"pointer-events-none absolute inset-x-0 bottom-0 h-6",style:{background:`linear-gradient(to top, ${P} 0%, transparent 100%)`}}),e[14]=P,e[15]=d,e[16]=O):O=e[16];let T;e[17]!==O||e[18]!==h||e[19]!==w?(T=s.jsxs("div",{className:"relative flex flex-1 min-h-0 flex-col",children:[h,w,O]}),e[17]=O,e[18]=h,e[19]=w,e[20]=T):T=e[20];let S;return e[21]!==n||e[22]!==a||e[23]!==T||e[24]!==j?(S=s.jsxs("div",{className:j,children:[a,T,n]}),e[21]=n,e[22]=a,e[23]=T,e[24]=j,e[25]=S):S=e[25],S},gr=t=>{const e=ut.c(23),{title:a,metadata:n,selected:r,onSelect:i,icon:l,actions:g,className:c}=t,y=r===void 0?!1:r,p=g&&g.length>0,b=y?"bg-interactive-selection":"hover:bg-interactive-hover";let d;e[0]!==c||e[1]!==b?(d=fe("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]=d):d=e[2];let C;e[3]!==a?(C=s.jsx("span",{className:"typography-ui-label font-normal truncate text-foreground",children:a}),e[3]=a,e[4]=C):C=e[4];let f;e[5]!==l||e[6]!==C?(f=s.jsxs("div",{className:"flex items-center gap-1.5",children:[l,C]}),e[5]=l,e[6]=C,e[7]=f):f=e[7];let P;e[8]!==n?(P=n&&s.jsx("div",{className:"typography-micro text-muted-foreground/60 truncate leading-tight",children:n}),e[8]=n,e[9]=P):P=e[9];let x;e[10]!==i||e[11]!==f||e[12]!==P?(x=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:[f,P]}),e[10]=i,e[11]=f,e[12]=P,e[13]=x):x=e[13];let N;e[14]!==g||e[15]!==p?(N=p&&s.jsxs(cn,{children:[s.jsx(on,{asChild:!0,children:s.jsx(B,{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(F,{name:"more-2",className:"h-3.5 w-3.5"})})}),s.jsx(ln,{align:"end",className:"w-fit min-w-20",children:g.map(Ep)})]}),e[14]=g,e[15]=p,e[16]=N):N=e[16];let m;e[17]!==x||e[18]!==N?(m=s.jsxs("div",{className:"flex min-w-0 flex-1 items-center",children:[x,N]}),e[17]=x,e[18]=N,e[19]=m):m=e[19];let A;return e[20]!==d||e[21]!==m?(A=s.jsx("div",{className:d,children:m}),e[20]=d,e[21]=m,e[22]=A):A=e[22],A};function Ep(t){const e=t.icon;return s.jsxs(dn,{onClick:a=>{a.stopPropagation(),t.onClick()},className:fe(t.destructive&&"text-destructive focus:text-destructive"),children:[e&&s.jsx(F,{name:e,className:"h-4 w-4 mr-px"}),t.label]},t.label)}const Dp=t=>t.parsedKind==="npm"?"code-box":"folder",Mp=t=>{const e=ut.c(144),{onItemSelect:a,onAddClick:n}=t,{t:r}=tt(),{entries:i,files:l,selectedId:g,setSelected:c,deleteEntry:y,deleteFile:p,loadPlugins:b}=ms(Us(Rp)),d=ms(Lp),C=ms(Op),f=ms(Fp),P=ms(Kp),[x,N]=o.useState(null),[m,A]=o.useState(!1),[R,I]=o.useState(!1);let j,h;e[0]!==b?(j=()=>{b()},h=[b],e[0]=b,e[1]=j,e[2]=h):(j=e[1],h=e[2]),o.useEffect(j,h);let w,O;e[3]===Symbol.for("react.memo_cache_sentinel")?(w=()=>{const et=()=>I(!0);return window.addEventListener("aiworker:settings-open-plugin-add",et),()=>window.removeEventListener("aiworker:settings-open-plugin-add",et)},O=[],e[3]=w,e[4]=O):(w=e[3],O=e[4]),o.useEffect(w,O);let T;if(e[5]!==i||e[6]!==d){T={userEntries:0,projectEntries:0};for(const et of i){const ft=d[et.spec];ft?.kind==="npm-ok"&&ft.hasUpdate&&(et.scope==="user"?T.userEntries=T.userEntries+1:et.scope==="project"&&(T.projectEntries=T.projectEntries+1))}e[5]=i,e[6]=d,e[7]=T}else T=e[7];const S=T;let M;e[8]!==i?(M=i.filter(zp),e[8]=i,e[9]=M):M=e[9];const V=M;let $;e[10]!==i?($=i.filter(Up),e[10]=i,e[11]=$):$=e[11];const k=$;let W;e[12]!==l?(W=l.filter(_p),e[12]=l,e[13]=W):W=e[13];const D=W;let L;e[14]!==l?(L=l.filter($p),e[14]=l,e[15]=L):L=e[15];const J=L,ee=i.length+l.length,U=ee===0;let re;e[16]!==n?(re=()=>{n?n():I(!0)},e[16]=n,e[17]=re):re=e[17];const _=re;let H;e[18]!==a||e[19]!==c?(H=et=>{c(et),a?.()},e[18]=a,e[19]=c,e[20]=H):H=e[20];const z=H;let K;e[21]!==i||e[22]!==d||e[23]!==r||e[24]!==P?(K=async et=>{const ft=i.find(Me=>Me.id===et);if(!ft)return;const bt=d[ft.spec];if(!bt||bt.kind!=="npm-ok"||!bt.hasUpdate||!bt.latestVersion)return;const Be=bt.latestVersion;(await P(et)).ok?E.success(r("settings.plugins.toast.updatedToLatest",{version:Be})):E.error(r("settings.plugins.toast.refreshFailed"))},e[21]=i,e[22]=d,e[23]=r,e[24]=P,e[25]=K):K=e[25];const te=K;let Y;e[26]!==f||e[27]!==r?(Y=async()=>{E.info(r("settings.plugins.toast.refreshing"));try{await f({force:!0})}catch{E.error(r("settings.plugins.toast.refreshFailed"))}},e[26]=f,e[27]=r,e[28]=Y):Y=e[28];const ne=Y;let me;e[29]!==y||e[30]!==p||e[31]!==x||e[32]!==r?(me=async()=>{if(!x)return;A(!0);const et=x.kind==="entry"?await y(x.id):await p(x.id);et.ok?E.success(et.message||r("settings.plugins.sidebar.toast.deleted",{name:x.label})):E.error(r("settings.plugins.sidebar.toast.deleteFailed")),N(null),A(!1)},e[29]=y,e[30]=p,e[31]=x,e[32]=r,e[33]=me):me=e[33];const de=me;let xe;e[34]!==z||e[35]!==te||e[36]!==d||e[37]!==g||e[38]!==r?(xe=et=>{const ft=d[et.spec],bt=ft?.kind==="npm-ok"&&ft.hasUpdate&&!!ft.latestVersion,Be=[];return bt&&Be.push({label:r("settings.plugins.sidebar.actions.updateToLatest"),icon:"arrow-up-s",onClick:()=>{te(et.id)}}),Be.push({label:r("settings.common.actions.delete"),icon:"delete-bin",destructive:!0,onClick:()=>N({kind:"entry",id:et.id,label:et.spec})}),s.jsx(gr,{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:et.spec}),s.jsx(Ap,{spec:et.spec})]}),metadata:et.parsedKind==="npm"?r("settings.plugins.sidebar.kind.npm"):r("settings.plugins.sidebar.kind.path"),selected:g===et.id,onSelect:()=>z(et.id),icon:s.jsx(F,{name:Dp(et),className:"h-4 w-4 flex-shrink-0 text-muted-foreground/70"}),actions:Be},et.id)},e[34]=z,e[35]=te,e[36]=d,e[37]=g,e[38]=r,e[39]=xe):xe=e[39];const ae=xe;let le;e[40]!==z||e[41]!==g||e[42]!==r?(le=et=>s.jsx(gr,{title:et.fileName,metadata:r("settings.plugins.sidebar.kind.file"),selected:g===et.id,onSelect:()=>z(et.id),icon:s.jsx(F,{name:"file-text",className:"h-4 w-4 flex-shrink-0 text-muted-foreground/70"}),actions:[{label:r("settings.common.actions.delete"),icon:"delete-bin",destructive:!0,onClick:()=>N({kind:"file",id:et.id,label:et.fileName})}]},et.id),e[40]=z,e[41]=g,e[42]=r,e[43]=le):le=e[43];const ge=le;let Ae;e[44]!==r?(Ae=(et,ft,bt)=>{const Be=bt===void 0?0:bt;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:[et,Be>0&&s.jsx("span",{className:"ml-2 normal-case font-normal text-[var(--status-success)]",children:r(Be===1?"settings.plugins.sidebar.group.updatesAvailable_one":"settings.plugins.sidebar.group.updatesAvailable_other",{count:Be})})]}),ft]})},e[44]=r,e[45]=Ae):Ae=e[45];const Se=Ae;let Ce;e[46]!==r?(Ce=r("settings.plugins.sidebar.title"),e[46]=r,e[47]=Ce):Ce=e[47];let he;e[48]!==Ce?(he=s.jsx("div",{className:"mb-3 flex items-center justify-between gap-3",children:s.jsx("h2",{className:un,children:Ce})}),e[48]=Ce,e[49]=he):he=e[49];let _e;e[50]!==r||e[51]!==ee?(_e=r("settings.plugins.sidebar.total",{count:ee}),e[50]=r,e[51]=ee,e[52]=_e):_e=e[52];let Ue;e[53]!==_e?(Ue=s.jsx("span",{className:"typography-meta text-muted-foreground",children:_e}),e[53]=_e,e[54]=Ue):Ue=e[54];let ke;e[55]!==ne?(ke=()=>{ne()},e[55]=ne,e[56]=ke):ke=e[56];let Oe;e[57]!==r?(Oe=r("settings.plugins.sidebar.actions.refresh"),e[57]=r,e[58]=Oe):Oe=e[58];let Ve;e[59]!==r?(Ve=r("settings.plugins.sidebar.actions.refresh"),e[59]=r,e[60]=Ve):Ve=e[60];const We=C?"size-4 animate-spin":"size-4";let ve;e[61]!==We?(ve=s.jsx(F,{name:"refresh",className:We}),e[61]=We,e[62]=ve):ve=e[62];let Z;e[63]!==C||e[64]!==ke||e[65]!==Oe||e[66]!==Ve||e[67]!==ve?(Z=s.jsx(B,{type:"button","data-settings-item":"plugins.create",variant:"ghost",size:"icon",className:"h-7 w-7 -my-1 text-muted-foreground",onClick:ke,disabled:C,"aria-label":Oe,title:Ve,children:ve}),e[63]=C,e[64]=ke,e[65]=Oe,e[66]=Ve,e[67]=ve,e[68]=Z):Z=e[68];let se;e[69]!==r?(se=r("settings.plugins.sidebar.actions.addTitle"),e[69]=r,e[70]=se):se=e[70];let ye;e[71]!==r?(ye=r("settings.plugins.sidebar.actions.addTitle"),e[71]=r,e[72]=ye):ye=e[72];let be;e[73]===Symbol.for("react.memo_cache_sentinel")?(be=s.jsx(F,{name:"add",className:"size-4"}),e[73]=be):be=e[73];let Re;e[74]!==_||e[75]!==se||e[76]!==ye?(Re=s.jsx(B,{type:"button",variant:"ghost",size:"icon",className:"h-7 w-7 -my-1 text-muted-foreground",onClick:_,"aria-label":se,title:ye,children:be}),e[74]=_,e[75]=se,e[76]=ye,e[77]=Re):Re=e[77];let Fe;e[78]!==Z||e[79]!==Re?(Fe=s.jsxs("div",{className:"flex items-center gap-1",children:[Z,Re]}),e[78]=Z,e[79]=Re,e[80]=Fe):Fe=e[80];let Ke;e[81]!==Ue||e[82]!==Fe?(Ke=s.jsxs("div",{className:"flex items-center justify-between gap-2",children:[Ue,Fe]}),e[81]=Ue,e[82]=Fe,e[83]=Ke):Ke=e[83];let Ee;e[84]!==he||e[85]!==Ke?(Ee=s.jsxs("div",{className:"border-b px-3 pt-4 pb-3",children:[he,Ke]}),e[84]=he,e[85]=Ke,e[86]=Ee):Ee=e[86];let we;e[87]!==U||e[88]!==k||e[89]!==J||e[90]!==ae||e[91]!==ge||e[92]!==Se||e[93]!==r||e[94]!==S||e[95]!==V||e[96]!==D?(we=U?s.jsxs("div",{className:"py-12 px-4 text-center text-muted-foreground",children:[s.jsx(F,{name:"plug",className:"mx-auto mb-3 h-10 w-10 opacity-50"}),s.jsx("p",{className:"typography-ui-label font-medium",children:r("settings.plugins.sidebar.empty.title")}),s.jsx("p",{className:"typography-meta mt-1 opacity-75",children:r("settings.plugins.sidebar.empty.description")})]}):s.jsxs(s.Fragment,{children:[V.length>0&&Se(r("settings.plugins.sidebar.group.userEntries"),V.map(ae),S.userEntries),D.length>0&&Se(r("settings.plugins.sidebar.group.userFiles"),D.map(ge)),k.length>0&&Se(r("settings.plugins.sidebar.group.projectEntries"),k.map(ae),S.projectEntries),J.length>0&&Se(r("settings.plugins.sidebar.group.projectFiles"),J.map(ge))]}),e[87]=U,e[88]=k,e[89]=J,e[90]=ae,e[91]=ge,e[92]=Se,e[93]=r,e[94]=S,e[95]=V,e[96]=D,e[97]=we):we=e[97];let Ze;e[98]!==Ee||e[99]!==we?(Ze=s.jsx(Hl,{variant:"background",header:Ee,children:we}),e[98]=Ee,e[99]=we,e[100]=Ze):Ze=e[100];let pe;e[101]!==R?(pe=s.jsx(Pp,{open:R,onOpenChange:I}),e[101]=R,e[102]=pe):pe=e[102];const Ne=x!==null;let Le;e[103]!==m?(Le=et=>{!et&&!m&&N(null)},e[103]=m,e[104]=Le):Le=e[104];let Xe;e[105]!==r?(Xe=r("settings.plugins.sidebar.deleteDialog.title"),e[105]=r,e[106]=Xe):Xe=e[106];let q;e[107]!==Xe?(q=s.jsx($t,{children:Xe}),e[107]=Xe,e[108]=q):q=e[108];const je=x?.label??"";let Ie;e[109]!==r||e[110]!==je?(Ie=r("settings.plugins.sidebar.deleteDialog.description",{name:je}),e[109]=r,e[110]=je,e[111]=Ie):Ie=e[111];let Je;e[112]!==Ie?(Je=s.jsx(Vt,{children:Ie}),e[112]=Ie,e[113]=Je):Je=e[113];let ot;e[114]!==q||e[115]!==Je?(ot=s.jsxs(_t,{children:[q,Je]}),e[114]=q,e[115]=Je,e[116]=ot):ot=e[116];let st;e[117]===Symbol.for("react.memo_cache_sentinel")?(st=()=>N(null),e[117]=st):st=e[117];let mt;e[118]!==r?(mt=r("settings.common.actions.cancel"),e[118]=r,e[119]=mt):mt=e[119];let vt;e[120]!==m||e[121]!==mt?(vt=s.jsx(B,{size:"sm",variant:"ghost",onClick:st,disabled:m,children:mt}),e[120]=m,e[121]=mt,e[122]=vt):vt=e[122];let G;e[123]!==m||e[124]!==r?(G=r(m?"settings.plugins.sidebar.actions.deleting":"settings.common.actions.delete"),e[123]=m,e[124]=r,e[125]=G):G=e[125];let Ge;e[126]!==de||e[127]!==m||e[128]!==G?(Ge=s.jsx(B,{size:"sm",variant:"destructive",onClick:de,disabled:m,children:G}),e[126]=de,e[127]=m,e[128]=G,e[129]=Ge):Ge=e[129];let nt;e[130]!==vt||e[131]!==Ge?(nt=s.jsxs(ts,{children:[vt,Ge]}),e[130]=vt,e[131]=Ge,e[132]=nt):nt=e[132];let lt;e[133]!==ot||e[134]!==nt?(lt=s.jsxs(zt,{className:"max-w-md",children:[ot,nt]}),e[133]=ot,e[134]=nt,e[135]=lt):lt=e[135];let ht;e[136]!==Ne||e[137]!==Le||e[138]!==lt?(ht=s.jsx(Kt,{open:Ne,onOpenChange:Le,children:lt}),e[136]=Ne,e[137]=Le,e[138]=lt,e[139]=ht):ht=e[139];let Lt;return e[140]!==Ze||e[141]!==pe||e[142]!==ht?(Lt=s.jsxs(s.Fragment,{children:[Ze,pe,ht]}),e[140]=Ze,e[141]=pe,e[142]=ht,e[143]=Lt):Lt=e[143],Lt};function Rp(t){return{entries:t.entries,files:t.files,selectedId:t.selectedId,setSelected:t.setSelected,deleteEntry:t.deleteEntry,deleteFile:t.deleteFile,loadPlugins:t.loadPlugins}}function Lp(t){return t.registryInfo}function Op(t){return t.isLoadingRegistry}function Fp(t){return t.loadRegistryInfo}function Kp(t){return t.updateToLatest}function zp(t){return t.scope==="user"}function Up(t){return t.scope==="project"}function _p(t){return t.scope==="user"}function $p(t){return t.scope==="project"}const Vp=({entryId:t,spec:e})=>{const{t:a}=tt(),n=ms(b=>b.registryInfo[e]),r=ms(b=>b.updateToLatest),[i,l]=o.useState(!1);if(!n)return null;if(n.kind==="npm-ok"){if(!n.hasUpdate||!n.latestVersion)return null;const b=n.latestVersion,d=n.currentVersion??"",C=async()=>{l(!0);try{(await r(t)).ok?E.success(a("settings.plugins.toast.updatedToLatest",{version:b})):E.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(F,{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:d,latest:b})})]}),s.jsx(B,{variant:"default",size:"sm",onClick:()=>{C()},disabled:i,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(F,{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 g=n.kind==="path-unreadable",c=g?"var(--status-warning)":"var(--status-error)",y=g?"alert":"error-warning",p=(()=>{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(F,{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:p})]})]})};function Bp(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 Wl(t){return!t||Object.keys(t).length===0?"":JSON.stringify(t,null,2)}function wo(t){return{mode:"entry",scope:t.scope,spec:t.spec,optionsJson:Wl(t.options),fileName:"",content:""}}function jo(t,e){return{mode:"file",scope:t.scope,spec:"",optionsJson:"",fileName:t.fileName,content:e}}const ko=t=>{const e=ut.c(4),{scope:a,label:n}=t;let r;e[0]===Symbol.for("react.memo_cache_sentinel")?(r=fe("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]=r):r=e[0];let i;return e[1]!==n||e[2]!==a?(i=s.jsx("span",{className:r,"data-scope":a,children:n}),e[1]=n,e[2]=a,e[3]=i):i=e[3],i},Hp=()=>{const{t}=tt(),e=ms(x=>x.selectedId),a=ms(x=>x.entries),n=ms(x=>x.files),r=ms(x=>x.draft),i=ms(x=>x.setDraft),l=ms(x=>x.updateEntry),g=ms(x=>x.updateFile),c=ms(x=>x.readFile),y=o.useMemo(()=>e?a.find(x=>x.id===e)??null:null,[a,e]),p=o.useMemo(()=>e?n.find(x=>x.id===e)??null:null,[n,e]),[b,d]=o.useState(!1),[C,f]=o.useState(!1),P=o.useRef(new Map);if(o.useEffect(()=>{let x=!1;return y?(i(wo(y)),()=>{x=!0}):p?(f(!0),(async()=>{const N=await c(p.id);if(x)return;f(!1);const m=N?.content??"";P.current.set(p.id,m),i(jo(p,m))})(),()=>{x=!0}):(i(null),()=>{x=!0})},[y,p,c,i]),!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(F,{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&&r&&r.mode==="entry"){const x=Bp(r.optionsJson),N=x.ok,m=r.spec!==y.spec||r.optionsJson!==Wl(y.options),A=()=>{i(wo(y))},R=async()=>{if(!N)return;const I=r.spec.trim();if(!I){E.error(t("settings.plugins.validation.specRequired"));return}d(!0);try{const j=await l(y.id,{spec:I,options:x.value});j.ok?j.reloadFailed?E.warning(j.message||t("settings.plugins.toast.reloadFailed"),{description:j.warning}):j.restartDeferred?E.success(t("settings.view.pendingRestart.saved")):E.success(j.message||t("settings.plugins.toast.updated")):E.error(j.message||t("settings.plugins.toast.reloadFailed"))}finally{d(!1)}};return s.jsxs(es,{title:t("settings.plugins.page.header.entry"),titleAccessory:s.jsx(ko,{scope:y.scope,label:y.scope==="project"?t("settings.plugins.sidebar.group.projectEntries"):t("settings.plugins.sidebar.group.userEntries")}),showSaveStatus:!1,children:[s.jsx(ze,{divider:!1,children:s.jsx(Vp,{entryId:y.id,spec:y.spec})}),s.jsx(ze,{title:t("settings.plugins.page.field.spec"),settingsItem:"plugins.spec",children:s.jsx(He,{value:r.spec,onChange:I=>i({...r,spec:I.target.value}),placeholder:t("settings.plugins.page.field.spec.placeholder"),className:"font-mono typography-meta",spellCheck:!1})}),s.jsxs(ze,{title:t("settings.plugins.page.field.options"),settingsItem:"plugins.options",children:[s.jsx(Ts,{value:r.optionsJson,onChange:I=>i({...r,optionsJson:I.target.value}),rows:10,className:fe("font-mono typography-meta min-h-[200px]",!N&&"border-[var(--status-error-border)]"),spellCheck:!1,placeholder:"{ }"}),!N&&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(B,{variant:"default",size:"sm",onClick:()=>{R()},disabled:!m||!N||b,children:t("settings.plugins.page.action.save")}),s.jsx(B,{variant:"outline",size:"sm",onClick:A,disabled:!m||b,children:t("settings.plugins.page.action.discard")})]})]})]})}if(p&&r&&r.mode==="file"){const x=P.current.get(p.id)??"",N=r.content!==x||r.fileName!==p.fileName,m=()=>{(async()=>{f(!0);const I=(await c(p.id))?.content??"";f(!1),P.current.set(p.id,I),i(jo(p,I))})()},A=async()=>{d(!0);try{const R=await g(p.id,{content:r.content});R.ok?(P.current.set(p.id,r.content),R.reloadFailed?E.warning(R.message||t("settings.plugins.toast.reloadFailed"),{description:R.warning}):R.restartDeferred?E.success(t("settings.view.pendingRestart.saved")):E.success(R.message||t("settings.plugins.toast.updated"))):E.error(R.message||t("settings.plugins.toast.reloadFailed"))}finally{d(!1)}};return s.jsx(es,{title:t("settings.plugins.page.header.file"),titleAccessory:s.jsxs(s.Fragment,{children:[s.jsx(ko,{scope:p.scope,label:p.scope==="project"?t("settings.plugins.sidebar.group.projectFiles"):t("settings.plugins.sidebar.group.userFiles")}),s.jsx("span",{className:fe("typography-micro font-mono rounded-full px-2 py-0.5","bg-[var(--surface-elevated)] text-foreground","border border-[var(--interactive-border)]"),children:p.fileName})]}),showSaveStatus:!1,children:s.jsxs(ze,{title:t("settings.plugins.page.field.content"),divider:!1,settingsItem:"plugins.content",children:[s.jsx(Ts,{value:r.content,onChange:R=>i({...r,content:R.target.value}),rows:16,className:"font-mono typography-meta min-h-[320px]",spellCheck:!1,disabled:C}),s.jsxs("div",{className:"flex items-center gap-2 pt-3",children:[s.jsx(B,{variant:"default",size:"sm",onClick:()=>{A()},disabled:!N||b||C,children:t("settings.plugins.page.action.save")}),s.jsx(B,{variant:"outline",size:"sm",onClick:m,disabled:b||C,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(F,{name:"loader-4",className:"mx-auto mb-3 h-6 w-6 animate-spin opacity-50"})})})},Wp="<built-in>",za=t=>t?.path===Wp,hr=t=>!!t&&!za(t)&&t.renamable===!0,Gp=t=>{const e=ut.c(157),{onItemSelect:a}=t,{t:n}=tt(),[r,i]=o.useState(null),[l,g]=o.useState(""),[c,y]=o.useState(null),[p,b]=o.useState(!1),[d,C]=o.useState(null),{selectedSkillName:f,setSelectedSkill:P,setSkillDraft:x,deleteSkill:N,renameSkill:m,getSkillDetail:A}=Hs(Us(qp)),R=_s();let I;e[0]!==R?(I=Me=>wr(Me,R),e[0]=R,e[1]=I):I=e[1];const j=Hs(I),h=Hs(Jp);let w,O;e[2]!==h||e[3]!==R?(w=()=>{h(R)},O=[h,R],e[2]=h,e[3]=R,e[4]=w,e[5]=O):(w=e[4],O=e[5]),o.useEffect(w,O);let T;e[6]!==a||e[7]!==P||e[8]!==x||e[9]!==j?(T=()=>{let Me="new-skill",wt=1;for(;j.some(Q=>Q.name===Me);)Me=`new-skill-${wt}`,wt++;x({name:Me,scope:"user",source:"opencode",description:""}),P(Me),a?.()},e[6]=a,e[7]=P,e[8]=x,e[9]=j,e[10]=T):T=e[10];const S=T;let M;e[11]===Symbol.for("react.memo_cache_sentinel")?(M=async Me=>{za(Me)||y(Me)},e[11]=M):M=e[11];const V=M;let $;e[12]!==c||e[13]!==N||e[14]!==R||e[15]!==n?($=async()=>{if(!c)return;if(za(c)){y(null);return}b(!0),await N(c.name,R)?(E.success(n("settings.skills.sidebar.toast.skillDeleted",{name:c.name})),y(null)):E.error(n("settings.skills.sidebar.toast.deleteSkillFailed")),b(!1)},e[12]=c,e[13]=N,e[14]=R,e[15]=n,e[16]=$):$=e[16];const k=$;let W;e[17]!==A||e[18]!==P||e[19]!==x||e[20]!==R||e[21]!==j||e[22]!==n?(W=async Me=>{if(za(Me))return;const wt=Me.name;let Q=1,ue=`${wt}-copy`;for(;j.some(Pe=>Pe.name===ue);)Q++,ue=`${wt}-copy-${Q}`;const De=await A(Me.name,R);if(!De){E.error(n("settings.skills.sidebar.toast.duplicateLoadFailed"));return}x({name:ue,scope:Me.scope||"user",source:Me.source||"opencode",description:(De.sources.md.fields.includes("description"),""),instructions:""}),P(ue)},e[17]=A,e[18]=P,e[19]=x,e[20]=R,e[21]=j,e[22]=n,e[23]=W):W=e[23];const D=W;let L;e[24]===Symbol.for("react.memo_cache_sentinel")?(L=Me=>{hr(Me)&&(g(Me.name),i(Me))},e[24]=L):L=e[24];const J=L;let ee;e[25]!==r||e[26]!==l||e[27]!==m||e[28]!==P||e[29]!==R||e[30]!==j||e[31]!==n?(ee=async()=>{if(!r)return;if(!hr(r)){i(null);return}const Me=l.trim().replace(/\s+/g,"-").toLowerCase();if(!Me){E.error(n("settings.skills.page.toast.skillNameRequired"));return}if(Me===r.name){i(null);return}if(j.some(Q=>Q.name===Me)){E.error(n("settings.skills.page.toast.skillExists"));return}await m(r.name,Me,R)?(E.success(n("settings.skills.sidebar.toast.skillRenamed",{name:Me})),P(Me)):E.error(n("settings.skills.sidebar.toast.renameFailed")),i(null)},e[25]=r,e[26]=l,e[27]=m,e[28]=P,e[29]=R,e[30]=j,e[31]=n,e[32]=ee):ee=e[32];const U=ee;let re;e[33]!==j?(re=j.filter(Qp),e[33]=j,e[34]=re):re=e[34];const _=re;let H;e[35]!==j?(H=j.filter(Yp),e[35]=j,e[36]=H):H=e[36];const z=H;let K;e[37]===Symbol.for("react.memo_cache_sentinel")?(K=function(wt){const Q={},ue=[];for(const Pe of wt)Pe.group?(Q[Pe.group]||(Q[Pe.group]=[]),Q[Pe.group].push(Pe)):ue.push(Pe);const De=Object.keys(Q).sort(Zp).map(Pe=>({name:Pe,skills:[...Q[Pe]].sort(Xp)}));return ue.sort(em),{sortedGroups:De,ungrouped:ue}},e[37]=K):K=e[37];const te=K;let Y;e[38]!==_?(Y=te(_),e[38]=_,e[39]=Y):Y=e[39];const ne=Y;let me;e[40]!==z?(me=te(z),e[40]=z,e[41]=me):me=e[41];const de=me;let xe;e[42]===Symbol.for("react.memo_cache_sentinel")?(xe=fe("flex h-full flex-col","bg-background"),e[42]=xe):xe=e[42];let ae;e[43]!==n?(ae=n("settings.skills.sidebar.title"),e[43]=n,e[44]=ae):ae=e[44];let le;e[45]!==ae?(le=s.jsx("h2",{className:`${un} mb-3`,children:ae}),e[45]=ae,e[46]=le):le=e[46];let ge;e[47]===Symbol.for("react.memo_cache_sentinel")?(ge=s.jsx(Ba,{className:"mb-3"}),e[47]=ge):ge=e[47];let Ae;e[48]!==j.length||e[49]!==n?(Ae=n("settings.skills.sidebar.total",{count:j.length}),e[48]=j.length,e[49]=n,e[50]=Ae):Ae=e[50];let Se;e[51]!==Ae?(Se=s.jsx("span",{className:"typography-meta text-muted-foreground",children:Ae}),e[51]=Ae,e[52]=Se):Se=e[52];let Ce;e[53]===Symbol.for("react.memo_cache_sentinel")?(Ce=s.jsx(F,{name:"add",className:"h-3.5 w-3.5"}),e[53]=Ce):Ce=e[53];let he;e[54]!==S?(he=s.jsx(B,{size:"sm","data-settings-item":"skills.create",variant:"ghost",className:"h-7 w-7 px-0 -my-1 text-muted-foreground",onClick:S,children:Ce}),e[54]=S,e[55]=he):he=e[55];let _e;e[56]!==Se||e[57]!==he?(_e=s.jsxs("div",{className:"flex items-center justify-between gap-2",children:[Se,he]}),e[56]=Se,e[57]=he,e[58]=_e):_e=e[58];let Ue;e[59]!==le||e[60]!==_e?(Ue=s.jsxs("div",{className:"border-b px-3 pt-4 pb-3",children:[le,ge,_e]}),e[59]=le,e[60]=_e,e[61]=Ue):Ue=e[61];let ke;e[62]!==ne||e[63]!==de||e[64]!==D||e[65]!==a||e[66]!==d||e[67]!==_||e[68]!==f||e[69]!==P||e[70]!==j.length||e[71]!==n||e[72]!==z?(ke=s.jsx(vs,{outerClassName:"flex-1 min-h-0",className:"space-y-1 px-3 py-2 overflow-x-hidden",children:j.length===0?s.jsxs("div",{className:"py-12 px-4 text-center text-muted-foreground",children:[s.jsx(F,{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:[_.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")}),ne.sortedGroups.map(Me=>{const{name:wt,skills:Q}=Me;return s.jsx(dr,{label:wt,count:Q.length,storageKey:"project-skills",children:Q.map(ue=>s.jsx(di,{skill:ue,isSelected:f===ue.name,onSelect:()=>{P(ue.name),a?.()},onRename:()=>J(ue),onDelete:()=>V(ue),onDuplicate:()=>D(ue),isMenuOpen:d===ue.name,onMenuOpenChange:De=>C(De?ue.name:null)},ue.name))},wt)}),ne.ungrouped.map(Me=>s.jsx(di,{skill:Me,isSelected:f===Me.name,onSelect:()=>{P(Me.name),a?.()},onRename:()=>J(Me),onDelete:()=>V(Me),onDuplicate:()=>D(Me),isMenuOpen:d===Me.name,onMenuOpenChange:wt=>C(wt?Me.name:null)},Me.name))]}),z.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")}),de.sortedGroups.map(Me=>{const{name:wt,skills:Q}=Me;return s.jsx(dr,{label:wt,count:Q.length,storageKey:"user-skills",children:Q.map(ue=>s.jsx(di,{skill:ue,isSelected:f===ue.name,onSelect:()=>{P(ue.name),a?.()},onRename:()=>J(ue),onDelete:()=>V(ue),onDuplicate:()=>D(ue),isMenuOpen:d===ue.name,onMenuOpenChange:De=>C(De?ue.name:null)},ue.name))},wt)}),de.ungrouped.map(Me=>s.jsx(di,{skill:Me,isSelected:f===Me.name,onSelect:()=>{P(Me.name),a?.()},onRename:()=>J(Me),onDelete:()=>V(Me),onDuplicate:()=>D(Me),isMenuOpen:d===Me.name,onMenuOpenChange:wt=>C(wt?Me.name:null)},Me.name))]})]})}),e[62]=ne,e[63]=de,e[64]=D,e[65]=a,e[66]=d,e[67]=_,e[68]=f,e[69]=P,e[70]=j.length,e[71]=n,e[72]=z,e[73]=ke):ke=e[73];const Oe=c!==null;let Ve;e[74]!==p?(Ve=Me=>{!Me&&!p&&y(null)},e[74]=p,e[75]=Ve):Ve=e[75];let We;e[76]!==n?(We=n("settings.skills.sidebar.deleteDialog.title"),e[76]=n,e[77]=We):We=e[77];let ve;e[78]!==We?(ve=s.jsx($t,{children:We}),e[78]=We,e[79]=ve):ve=e[79];const Z=c?.name??"";let se;e[80]!==n||e[81]!==Z?(se=n("settings.skills.sidebar.deleteDialog.description",{name:Z}),e[80]=n,e[81]=Z,e[82]=se):se=e[82];let ye;e[83]!==se?(ye=s.jsx(Vt,{children:se}),e[83]=se,e[84]=ye):ye=e[84];let be;e[85]!==ve||e[86]!==ye?(be=s.jsxs(_t,{children:[ve,ye]}),e[85]=ve,e[86]=ye,e[87]=be):be=e[87];let Re;e[88]===Symbol.for("react.memo_cache_sentinel")?(Re=()=>y(null),e[88]=Re):Re=e[88];let Fe;e[89]!==n?(Fe=n("settings.common.actions.cancel"),e[89]=n,e[90]=Fe):Fe=e[90];let Ke;e[91]!==p||e[92]!==Fe?(Ke=s.jsx(B,{size:"sm",className:"text-foreground hover:bg-interactive-hover hover:text-foreground",variant:"ghost",onClick:Re,disabled:p,children:Fe}),e[91]=p,e[92]=Fe,e[93]=Ke):Ke=e[93];let Ee;e[94]!==n?(Ee=n("settings.common.actions.delete"),e[94]=n,e[95]=Ee):Ee=e[95];let we;e[96]!==k||e[97]!==p||e[98]!==Ee?(we=s.jsx(B,{size:"sm",onClick:k,disabled:p,children:Ee}),e[96]=k,e[97]=p,e[98]=Ee,e[99]=we):we=e[99];let Ze;e[100]!==Ke||e[101]!==we?(Ze=s.jsxs(ts,{children:[Ke,we]}),e[100]=Ke,e[101]=we,e[102]=Ze):Ze=e[102];let pe;e[103]!==be||e[104]!==Ze?(pe=s.jsxs(zt,{className:"max-w-md",children:[be,Ze]}),e[103]=be,e[104]=Ze,e[105]=pe):pe=e[105];let Ne;e[106]!==Oe||e[107]!==Ve||e[108]!==pe?(Ne=s.jsx(Kt,{open:Oe,onOpenChange:Ve,children:pe}),e[106]=Oe,e[107]=Ve,e[108]=pe,e[109]=Ne):Ne=e[109];const Le=r!==null;let Xe;e[110]===Symbol.for("react.memo_cache_sentinel")?(Xe=Me=>!Me&&i(null),e[110]=Xe):Xe=e[110];let q;e[111]!==n?(q=n("settings.skills.sidebar.renameDialog.title"),e[111]=n,e[112]=q):q=e[112];let je;e[113]!==q?(je=s.jsx($t,{children:q}),e[113]=q,e[114]=je):je=e[114];const Ie=r?.name??"";let Je;e[115]!==n||e[116]!==Ie?(Je=n("settings.skills.sidebar.renameDialog.description",{name:Ie}),e[115]=n,e[116]=Ie,e[117]=Je):Je=e[117];let ot;e[118]!==Je?(ot=s.jsx(Vt,{children:Je}),e[118]=Je,e[119]=ot):ot=e[119];let st;e[120]!==je||e[121]!==ot?(st=s.jsxs(_t,{children:[je,ot]}),e[120]=je,e[121]=ot,e[122]=st):st=e[122];let mt;e[123]===Symbol.for("react.memo_cache_sentinel")?(mt=Me=>g(Me.target.value),e[123]=mt):mt=e[123];let vt;e[124]!==n?(vt=n("settings.skills.sidebar.renameDialog.placeholder"),e[124]=n,e[125]=vt):vt=e[125];let G;e[126]!==U?(G=Me=>{Me.key==="Enter"&&U()},e[126]=U,e[127]=G):G=e[127];let Ge;e[128]!==l||e[129]!==vt||e[130]!==G?(Ge=s.jsx(He,{value:l,onChange:mt,placeholder:vt,className:"text-foreground placeholder:text-muted-foreground",onKeyDown:G}),e[128]=l,e[129]=vt,e[130]=G,e[131]=Ge):Ge=e[131];let nt;e[132]===Symbol.for("react.memo_cache_sentinel")?(nt=()=>i(null),e[132]=nt):nt=e[132];let lt;e[133]!==n?(lt=n("settings.common.actions.cancel"),e[133]=n,e[134]=lt):lt=e[134];let ht;e[135]!==lt?(ht=s.jsx(B,{size:"sm",className:"text-foreground hover:bg-interactive-hover hover:text-foreground",variant:"ghost",onClick:nt,children:lt}),e[135]=lt,e[136]=ht):ht=e[136];let Lt;e[137]!==n?(Lt=n("settings.common.actions.rename"),e[137]=n,e[138]=Lt):Lt=e[138];let et;e[139]!==U||e[140]!==Lt?(et=s.jsx(B,{size:"sm",onClick:U,children:Lt}),e[139]=U,e[140]=Lt,e[141]=et):et=e[141];let ft;e[142]!==ht||e[143]!==et?(ft=s.jsxs(ts,{children:[ht,et]}),e[142]=ht,e[143]=et,e[144]=ft):ft=e[144];let bt;e[145]!==st||e[146]!==Ge||e[147]!==ft?(bt=s.jsxs(zt,{children:[st,Ge,ft]}),e[145]=st,e[146]=Ge,e[147]=ft,e[148]=bt):bt=e[148];let Be;e[149]!==Le||e[150]!==bt?(Be=s.jsx(Kt,{open:Le,onOpenChange:Xe,children:bt}),e[149]=Le,e[150]=bt,e[151]=Be):Be=e[151];let Et;return e[152]!==Ue||e[153]!==ke||e[154]!==Ne||e[155]!==Be?(Et=s.jsxs("div",{className:xe,children:[Ue,ke,Ne,Be]}),e[152]=Ue,e[153]=ke,e[154]=Ne,e[155]=Be,e[156]=Et):Et=e[156],Et},di=t=>{const e=ut.c(41),{skill:a,isSelected:n,onSelect:r,onDelete:i,onRename:l,onDuplicate:g,isMenuOpen:c,onMenuOpenChange:y}=t,{t:p}=tt();let b;e[0]===Symbol.for("react.memo_cache_sentinel")?(b=_a(),e[0]=b):b=e[0];const d=b;let C;e[1]!==a?(C=za(a),e[1]=a,e[2]=C):C=e[2];const f=C;let P;e[3]!==a?(P=hr(a),e[3]=a,e[4]=P):P=e[4];const x=P,[N,m]=o.useState(!1);let A;e[5]!==x||e[6]!==i||e[7]!==g||e[8]!==l||e[9]!==p?(A=D=>s.jsxs(s.Fragment,{children:[x?s.jsxs(D,{onClick:L=>{L.stopPropagation(),l()},children:[s.jsx(F,{name:"edit",className:"h-4 w-4 mr-px"}),p("settings.common.actions.rename")]}):null,s.jsxs(D,{onClick:L=>{L.stopPropagation(),g()},children:[s.jsx(F,{name:"file-copy",className:"h-4 w-4 mr-px"}),p("settings.common.actions.duplicate")]}),s.jsxs(D,{onClick:L=>{L.stopPropagation(),i()},className:"text-destructive focus:text-destructive",children:[s.jsx(F,{name:"delete-bin",className:"h-4 w-4 mr-px"}),p("settings.common.actions.delete")]})]}),e[5]=x,e[6]=i,e[7]=g,e[8]=l,e[9]=p,e[10]=A):A=e[10];const R=A,I=!f&&N,j=n?"bg-interactive-selection":"hover:bg-interactive-hover";let h;e[11]!==j?(h=fe("group relative flex items-center rounded-md px-1.5 py-1 transition-all duration-200 select-none",j),e[11]=j,e[12]=h):h=e[12];let w;e[13]!==f?(w=!d&&!f?D=>{D.preventDefault(),m(!0)}:void 0,e[13]=f,e[14]=w):w=e[14];let O;e[15]!==h||e[16]!==w?(O=s.jsx("div",{className:h,onContextMenu:w}),e[15]=h,e[16]=w,e[17]=O):O=e[17];let T;e[18]!==a.name?(T=s.jsx("div",{className:"flex items-center gap-1.5",children:s.jsx("span",{className:"typography-ui-label font-normal truncate text-foreground",children:a.name})}),e[18]=a.name,e[19]=T):T=e[19];let S;e[20]!==r||e[21]!==T?(S=s.jsx("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:T}),e[20]=r,e[21]=T,e[22]=S):S=e[22];let M;e[23]!==f||e[24]!==c||e[25]!==y||e[26]!==R?(M=f?null:s.jsxs(cn,{open:c,onOpenChange:D=>{D&&m(!1),y(D)},children:[s.jsx(on,{asChild:!0,children:s.jsx(B,{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(F,{name:"more-2",className:"h-3.5 w-3.5"})})}),s.jsx(ln,{align:"end",className:"w-fit min-w-20",children:R(dn)})]}),e[23]=f,e[24]=c,e[25]=y,e[26]=R,e[27]=M):M=e[27];let V;e[28]!==S||e[29]!==M?(V=s.jsxs("div",{className:"flex min-w-0 flex-1 items-center",children:[S,M]}),e[28]=S,e[29]=M,e[30]=V):V=e[30];let $;e[31]!==V||e[32]!==O?($=s.jsx(Jn,{render:O,children:V}),e[31]=V,e[32]=O,e[33]=$):$=e[33];let k;e[34]!==f||e[35]!==R?(k=f?null:s.jsx(Gn,{className:"w-fit min-w-20",children:R(qn)}),e[34]=f,e[35]=R,e[36]=k):k=e[36];let W;return e[37]!==$||e[38]!==k||e[39]!==I?(W=s.jsxs(Qn,{open:I,onOpenChange:m,children:[$,k]}),e[37]=$,e[38]=k,e[39]=I,e[40]=W):W=e[40],W};function qp(t){return{selectedSkillName:t.selectedSkillName,setSelectedSkill:t.setSelectedSkill,setSkillDraft:t.setSkillDraft,deleteSkill:t.deleteSkill,renameSkill:t.renameSkill,getSkillDetail:t.getSkillDetail}}function Jp(t){return t.loadSkills}function Qp(t){return t.scope==="project"}function Yp(t){return t.scope==="user"}function Zp(t,e){return t.localeCompare(e)}function Xp(t,e){return t.name.localeCompare(e.name)}function em(t,e){return t.name.localeCompare(e.name)}const tm=()=>`custom:${Date.now()}-${Math.random().toString(16).slice(2)}`,sm=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},nm=({open:t,onOpenChange:e})=>{const{t:a}=tt(),n=hn(k=>k.scanRepo),r=hn(k=>k.loadCatalog),i=hn(k=>k.loadSource),l=hn(k=>k.setSelectedSource),g=hn(k=>k.isScanning),c=_n(k=>k.defaultGitIdentityId),y=_n(k=>k.loadDefaultGitIdentityId),[p,b]=o.useState(""),[d,C]=o.useState(""),[f,P]=o.useState(""),[x,N]=o.useState(null),[m,A]=o.useState(null),[R,I]=o.useState(!1),[j,h]=o.useState([]),[w,O]=o.useState(null),T=o.useRef(0),S=o.useCallback(k=>{T.current+=1,I(!1),A(null),k?.clearIdentity&&(h([]),O(null))},[]);o.useEffect(()=>{t&&(T.current+=1,b(""),C(""),P(""),A(null),I(!1),h([]),O(null),y(),N(null),(async()=>{const k=await pn();N(k?k.skillCatalogs??[]:null)})())},[t,y]);const M=o.useMemo(()=>{const k=d.trim(),W=f.trim();return(x??[]).some(D=>{const L=(D.source||"").trim(),J=(D.subpath||"").trim();return L===k&&J===W})},[x,d,f]),V=async()=>{const k=d.trim();if(!k){E.error(a("settings.skills.catalog.add.toast.repositoryRequired"));return}p.trim()||b(sm(k)),I(!1),A(null);const W=T.current+1;T.current=W;const D=await n({source:k,subpath:f.trim()||void 0,gitIdentityId:w||void 0});if(T.current!==W)return;if(!D.ok){if(D.error?.kind==="authRequired"){if(cs()){E.error(a("settings.skills.catalog.shared.toast.privateRepoNotSupportedVsCode"));return}const J=D.error.identities||[];if(h(J),!w&&J.length>0){const ee=c&&c!=="global"&&J.some(U=>U.id===c)?c:J[0].id;O(ee)}E.error(a("settings.skills.catalog.add.toast.authenticationRequiredScan"));return}E.error(D.error?.message||a("settings.skills.catalog.add.toast.scanFailed"));return}const L=D.items?.length||0;if(A(L),L===0){E.error(a("settings.skills.catalog.add.toast.noSkillsFound")),I(!1);return}h([]),I(!0),E.success(a("settings.skills.catalog.shared.toast.foundSkills",{count:L}))},$=async()=>{const k=p.trim(),W=d.trim(),D=f.trim();if(!k){E.error(a("settings.skills.catalog.add.toast.catalogNameRequired"));return}if(!W){E.error(a("settings.skills.catalog.add.toast.repositoryRequired"));return}if(!R){E.error(a("settings.skills.catalog.add.toast.scanBeforeAdd"));return}if(M){E.error(a("settings.skills.catalog.add.toast.catalogAlreadyExists"));return}const L={id:tm(),label:k,source:W,...D?{subpath:D}:{},...w?{gitIdentityId:w}:{}};if(x===null){E.error(a("settings.skills.catalog.add.toast.saveFailed"));return}const J=[...x,L];try{if(!(await pt({skillCatalogs:J})).ok)throw new Error(a("settings.skills.catalog.add.toast.saveFailed"));N(J),E.success(a("settings.skills.catalog.add.toast.catalogAdded")),await r({refresh:!0}),await i(L.id,{refresh:!0}),l(L.id),e(!1)}catch(ee){E.error(ee instanceof Error?ee.message:a("settings.skills.catalog.add.toast.saveFailed"))}};return s.jsx(Kt,{open:t,onOpenChange:e,children:s.jsxs(zt,{className:"max-w-xl",children:[s.jsxs(_t,{children:[s.jsx($t,{children:a("settings.skills.catalog.add.title")}),s.jsxs(Vt,{children:[a("settings.skills.catalog.add.descriptionPrefix")," ",s.jsx("code",{className:"font-mono",children:"SKILL.md"}),a("settings.skills.catalog.add.descriptionSuffix")]})]}),s.jsxs("div",{className:"space-y-4",children:[s.jsxs("div",{className:"space-y-2",children:[s.jsx("label",{className:"typography-ui-label text-foreground",children:a("settings.skills.catalog.add.field.catalogName")}),s.jsx(He,{value:p,onChange:k=>b(k.target.value),placeholder:a("settings.skills.catalog.add.field.catalogNamePlaceholder")})]}),s.jsxs("div",{className:"space-y-2",children:[s.jsxs("div",{className:"flex items-center gap-1",children:[s.jsx("label",{className:"typography-ui-label text-foreground",children:a("settings.skills.catalog.add.field.repository")}),s.jsx(Jt,{children:a("settings.skills.catalog.add.field.repositoryHint")})]}),s.jsx(He,{value:d,onChange:k=>{C(k.target.value),S({clearIdentity:!0})},placeholder:a("settings.skills.catalog.shared.field.repositoryPlaceholder")})]}),s.jsxs("div",{className:"space-y-2",children:[s.jsx("label",{className:"typography-ui-label text-foreground",children:a("settings.skills.catalog.add.field.optionalSubpath")}),s.jsx(He,{value:f,onChange:k=>{P(k.target.value),S({clearIdentity:!0})},placeholder:a("settings.skills.catalog.shared.field.subpathPlaceholder")})]}),j.length>0&&!cs()?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:a("settings.skills.catalog.shared.auth.title")}),s.jsx("span",{className:"typography-meta text-muted-foreground ml-2",children:a("settings.skills.catalog.shared.auth.description")}),s.jsx(Jt,{className:"ml-1",children:a("settings.skills.catalog.shared.auth.footerHint")})]}),s.jsxs(St,{value:w||"",onValueChange:k=>{O(k),S()},children:[s.jsx(Ct,{className:"w-fit",children:s.jsx("span",{children:j.find(k=>k.id===w)?.name||a("settings.skills.catalog.shared.auth.chooseIdentity")})}),s.jsx(It,{align:"start",children:j.map(k=>s.jsx(at,{value:k.id,children:k.name},k.id))})]})]}):null,m!==null?s.jsx("div",{className:"typography-meta text-muted-foreground",children:a("settings.skills.catalog.add.scanResult",{count:m})}):null,M?s.jsx("div",{className:"typography-meta text-muted-foreground",children:a("settings.skills.catalog.add.duplicateMessage")}):null]}),s.jsxs(ts,{children:[s.jsx(B,{size:"sm",variant:"ghost",onClick:()=>e(!1),children:a("settings.common.actions.cancel")}),s.jsxs(B,{size:"sm",className:"gap-2",variant:"ghost",onClick:()=>{V()},disabled:g||!d.trim(),children:[s.jsx(F,{name:"git-repository",className:"h-4 w-4"}),a(g?"settings.skills.catalog.shared.actions.scanning":"settings.skills.catalog.shared.actions.scan")]}),s.jsx(B,{size:"sm",onClick:()=>{$()},disabled:!R||M||x===null||!p.trim()||!d.trim(),children:a("settings.skills.catalog.add.actions.addCatalog")})]})]})})},am=t=>{const e=ut.c(85),{open:a,onOpenChange:n,conflicts:r,onConfirm:i}=t,{t:l}=tt();let g;e[0]===Symbol.for("react.memo_cache_sentinel")?(g={},e[0]=g):g=e[0];const[c,y]=o.useState(g);let p,b;e[1]!==r||e[2]!==a?(p=()=>{if(!a)return;const Y={};for(const ne of r)Y[ne.skillName]="skip";y(Y)},b=[a,r],e[1]=r,e[2]=a,e[3]=p,e[4]=b):(p=e[3],b=e[4]),o.useEffect(p,b);let d;e[5]!==r?(d=Y=>{const ne={};for(const me of r)ne[me.skillName]=Y;y(ne)},e[5]=r,e[6]=d):d=e[6];const C=d;let f;e[7]!==r||e[8]!==c?(f=r.length>0&&r.every(Y=>c[Y.skillName]),e[7]=r,e[8]=c,e[9]=f):f=e[9];const P=f;let x;e[10]!==l?(x=l("settings.skills.catalog.conflicts.title"),e[10]=l,e[11]=x):x=e[11];let N;e[12]!==x?(N=s.jsx($t,{children:x}),e[12]=x,e[13]=N):N=e[13];let m;e[14]!==l?(m=l("settings.skills.catalog.conflicts.description"),e[14]=l,e[15]=m):m=e[15];let A;e[16]!==m?(A=s.jsx(Vt,{children:m}),e[16]=m,e[17]=A):A=e[17];let R;e[18]!==N||e[19]!==A?(R=s.jsxs(_t,{children:[N,A]}),e[18]=N,e[19]=A,e[20]=R):R=e[20];let I;e[21]!==r.length||e[22]!==l?(I=l("settings.skills.catalog.conflicts.count",{count:r.length}),e[21]=r.length,e[22]=l,e[23]=I):I=e[23];let j;e[24]!==I?(j=s.jsx("span",{className:"typography-meta text-muted-foreground",children:I}),e[24]=I,e[25]=j):j=e[25];let h;e[26]!==C?(h=()=>C("skip"),e[26]=C,e[27]=h):h=e[27];let w;e[28]!==l?(w=l("settings.skills.catalog.conflicts.actions.skipAll"),e[28]=l,e[29]=w):w=e[29];let O;e[30]!==h||e[31]!==w?(O=s.jsx(B,{variant:"outline",size:"xs",className:"!font-normal",onClick:h,children:w}),e[30]=h,e[31]=w,e[32]=O):O=e[32];let T;e[33]!==C?(T=()=>C("overwrite"),e[33]=C,e[34]=T):T=e[34];let S;e[35]!==l?(S=l("settings.skills.catalog.conflicts.actions.overwriteAll"),e[35]=l,e[36]=S):S=e[36];let M;e[37]!==T||e[38]!==S?(M=s.jsx(B,{variant:"outline",size:"xs",className:"!font-normal",onClick:T,children:S}),e[37]=T,e[38]=S,e[39]=M):M=e[39];let V;e[40]!==O||e[41]!==M?(V=s.jsxs("div",{className:"flex items-center gap-2",children:[O,M]}),e[40]=O,e[41]=M,e[42]=V):V=e[42];let $;e[43]!==j||e[44]!==V?($=s.jsxs("div",{className:"flex items-center justify-between gap-2",children:[j,V]}),e[43]=j,e[44]=V,e[45]=$):$=e[45];let k;if(e[46]!==r||e[47]!==c||e[48]!==l){let Y;e[50]!==c||e[51]!==l?(Y=ne=>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:ne.skillName}),s.jsx("div",{className:"typography-micro text-muted-foreground",children:l("settings.skills.catalog.conflicts.installedIn",{scope:ne.scope==="project"?l("settings.skills.catalog.conflicts.scope.project"):l("settings.skills.catalog.conflicts.scope.user"),source:ne.source==="agents"?l("settings.skills.catalog.conflicts.source.agents"):l("settings.skills.catalog.conflicts.source.opencode")})})]}),s.jsxs(St,{value:c[ne.skillName]||"skip",onValueChange:me=>y(de=>({...de,[ne.skillName]:me})),children:[s.jsx(Ct,{className:"w-fit",children:s.jsx("span",{className:"capitalize",children:(c[ne.skillName]||"skip")==="overwrite"?l("settings.skills.catalog.conflicts.decision.overwrite"):l("settings.skills.catalog.conflicts.decision.skip")})}),s.jsxs(It,{align:"end",children:[s.jsx(at,{value:"skip",className:"pr-2 [&>span:first-child]:hidden",children:l("settings.skills.catalog.conflicts.decision.skip")}),s.jsx(at,{value:"overwrite",className:"pr-2 [&>span:first-child]:hidden",children:l("settings.skills.catalog.conflicts.decision.overwrite")})]})]})]},ne.skillName),e[50]=c,e[51]=l,e[52]=Y):Y=e[52],k=r.map(Y),e[46]=r,e[47]=c,e[48]=l,e[49]=k}else k=e[49];let W;e[53]!==k?(W=s.jsx("div",{className:"space-y-2",children:k}),e[53]=k,e[54]=W):W=e[54];let D;e[55]!==$||e[56]!==W?(D=s.jsxs("div",{className:"space-y-3",children:[$,W]}),e[55]=$,e[56]=W,e[57]=D):D=e[57];let L;e[58]!==n?(L=()=>n(!1),e[58]=n,e[59]=L):L=e[59];let J;e[60]!==l?(J=l("settings.common.actions.cancel"),e[60]=l,e[61]=J):J=e[61];let ee;e[62]!==L||e[63]!==J?(ee=s.jsx(B,{size:"sm",variant:"ghost",onClick:L,children:J}),e[62]=L,e[63]=J,e[64]=ee):ee=e[64];let U;e[65]!==c||e[66]!==i?(U=()=>i(c),e[65]=c,e[66]=i,e[67]=U):U=e[67];const re=!P;let _;e[68]!==l?(_=l("settings.skills.catalog.conflicts.actions.continue"),e[68]=l,e[69]=_):_=e[69];let H;e[70]!==U||e[71]!==re||e[72]!==_?(H=s.jsx(B,{size:"sm",onClick:U,disabled:re,children:_}),e[70]=U,e[71]=re,e[72]=_,e[73]=H):H=e[73];let z;e[74]!==ee||e[75]!==H?(z=s.jsxs(ts,{children:[ee,H]}),e[74]=ee,e[75]=H,e[76]=z):z=e[76];let K;e[77]!==R||e[78]!==D||e[79]!==z?(K=s.jsxs(zt,{className:"max-w-2xl",children:[R,D,z]}),e[77]=R,e[78]=D,e[79]=z,e[80]=K):K=e[80];let te;return e[81]!==n||e[82]!==a||e[83]!==K?(te=s.jsx(Kt,{open:a,onOpenChange:n,children:K}),e[81]=n,e[82]=a,e[83]=K,e[84]=te):te=e[84],te},Pr=[{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 Ua(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 Gl(t){if(t==="user-claude")return{scope:"user",source:"claude"};if(t==="project-claude")return{scope:"project",source:"claude"};const e=Pr.find(a=>a.value===t);return e?{scope:e.scope,source:e.source}:{scope:"user",source:"opencode"}}const im=t=>{const e=ut.c(124),{open:a,onOpenChange:n,item:r}=t,{t:i}=tt(),l=hn(rm),g=hn(om),[c,y]=o.useState("user"),[p,b]=o.useState("opencode"),d=Ws(lm),C=Ws(cm),[f,P]=o.useState(null),[x,N]=o.useState(!1);let m;e[0]===Symbol.for("react.memo_cache_sentinel")?(m=[],e[0]=m):m=e[0];const[A,R]=o.useState(m),[I,j]=o.useState(null);let h,w;e[1]!==C||e[2]!==a?(h=()=>{a&&(y("user"),b("opencode"),P(C),N(!1),R([]),j(null))},w=[a,C],e[1]=C,e[2]=a,e[3]=h,e[4]=w):(h=e[3],w=e[4]),o.useEffect(h,w);let O;e[5]!==i?(O=we=>{switch(we){case"project-opencode":return i("settings.skills.location.option.projectOpencode.label");case"user-agents":return i("settings.skills.location.option.userAgents.label");case"project-agents":return i("settings.skills.location.option.projectAgents.label");default:return i("settings.skills.location.option.userOpencode.label")}},e[5]=i,e[6]=O):O=e[6];const T=O;let S;e[7]!==i?(S=we=>{switch(we){case"project-opencode":return i("settings.skills.location.option.projectOpencode.description");case"user-agents":return i("settings.skills.location.option.userAgents.description");case"project-agents":return i("settings.skills.location.option.projectAgents.description");default:return i("settings.skills.location.option.userOpencode.description")}},e[7]=i,e[8]=S):S=e[8];const M=S;let V;e:{if(d.length===0){V=null;break e}if(f&&d.some(we=>we.id===f)){V=f;break e}if(C&&d.some(we=>we.id===C)){V=C;break e}V=d[0]?.id??null}const $=V;let k;e:{if(c!=="project"){k=null;break e}const we=$;if(!we){k=null;break e}let Ze;if(e[9]!==we||e[10]!==d){let Ne;e[12]!==we?(Ne=Le=>Le.id===we,e[12]=we,e[13]=Ne):Ne=e[13],Ze=d.find(Ne),e[9]=we,e[10]=d,e[11]=Ze}else Ze=e[11];k=Ze?.path??null}const W=k;let D;e[14]!==l||e[15]!==r?.gitIdentityId||e[16]!==n||e[17]!==i?(D=async we=>{const Ze=await l({source:we.source,subpath:we.subpath,gitIdentityId:r?.gitIdentityId,scope:we.scope,targetSource:we.targetSource,selections:[{skillDir:we.skillDir}],conflictPolicy:"prompt",conflictDecisions:we.conflictDecisions},{directory:we.directoryOverride??null});if(Ze.ok){E.success(i("settings.skills.catalog.installSkill.toast.installed")),n(!1);return}if(Ze.error?.kind==="conflicts"){j({source:we.source,subpath:we.subpath,scope:we.scope,targetSource:we.targetSource,skillDir:we.skillDir,directoryOverride:we.directoryOverride??null}),R(Ze.error.conflicts),N(!0);return}if(Ze.error?.kind==="authRequired"){E.error(Ze.error.message||i("settings.skills.catalog.installSkill.toast.authRequired"));return}E.error(Ze.error?.message||i("settings.skills.catalog.installSkill.toast.installFailed"))},e[14]=l,e[15]=r?.gitIdentityId,e[16]=n,e[17]=i,e[18]=D):D=e[18];const L=D;if(!r)return null;let J;e[19]!==i?(J=i("settings.skills.catalog.installSkill.title"),e[19]=i,e[20]=J):J=e[20];let ee;e[21]!==J?(ee=s.jsx($t,{children:J}),e[21]=J,e[22]=ee):ee=e[22];let U;e[23]!==i?(U=i("settings.skills.catalog.installSkill.descriptionPrefix"),e[23]=i,e[24]=U):U=e[24];let re;e[25]!==r.skillName?(re=s.jsx("span",{className:"font-semibold text-foreground",children:r.skillName}),e[25]=r.skillName,e[26]=re):re=e[26];let _;e[27]!==i?(_=i("settings.skills.catalog.installSkill.descriptionSuffix"),e[27]=i,e[28]=_):_=e[28];let H;e[29]!==U||e[30]!==re||e[31]!==_?(H=s.jsxs(Vt,{children:[U," ",re," ",_]}),e[29]=U,e[30]=re,e[31]=_,e[32]=H):H=e[32];let z;e[33]!==ee||e[34]!==H?(z=s.jsxs(_t,{children:[ee,H]}),e[33]=ee,e[34]=H,e[35]=z):z=e[35];let K;e[36]!==i?(K=i("settings.skills.catalog.installSkill.field.destination"),e[36]=i,e[37]=K):K=e[37];let te;e[38]!==K?(te=s.jsx("span",{className:"typography-ui-label text-foreground",children:K}),e[38]=K,e[39]=te):te=e[39];let Y;e[40]!==c||e[41]!==p?(Y=Ua(c,p),e[40]=c,e[41]=p,e[42]=Y):Y=e[42];let ne;e[43]===Symbol.for("react.memo_cache_sentinel")?(ne=we=>{const Ze=Gl(we);y(Ze.scope),b(Ze.source==="agents"?"agents":"opencode")},e[43]=ne):ne=e[43];let me;e[44]!==c?(me=c==="user"?s.jsx(F,{name:"user-3",className:"h-3.5 w-3.5"}):s.jsx(F,{name:"folder",className:"h-3.5 w-3.5"}),e[44]=c,e[45]=me):me=e[45];let de;e[46]!==p?(de=p==="agents"?s.jsx(F,{name:"robot-2",className:"h-3.5 w-3.5"}):null,e[46]=p,e[47]=de):de=e[47];let xe;e[48]!==T||e[49]!==c||e[50]!==p?(xe=T(Ua(c,p)),e[48]=T,e[49]=c,e[50]=p,e[51]=xe):xe=e[51];let ae;e[52]!==xe?(ae=s.jsx("span",{children:xe}),e[52]=xe,e[53]=ae):ae=e[53];let le;e[54]!==me||e[55]!==de||e[56]!==ae?(le=s.jsxs(Ct,{className:"w-fit gap-1.5",children:[me,de,ae]}),e[54]=me,e[55]=de,e[56]=ae,e[57]=le):le=e[57];let ge;e[58]!==M||e[59]!==T?(ge=Pr.map(we=>s.jsx(at,{value:we.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:[we.scope==="user"?s.jsx(F,{name:"user-3",className:"h-3.5 w-3.5"}):s.jsx(F,{name:"folder",className:"h-3.5 w-3.5"}),we.source==="agents"?s.jsx(F,{name:"robot-2",className:"h-3.5 w-3.5"}):null,s.jsx("span",{children:T(we.value)})]}),s.jsx("span",{className:"typography-micro text-muted-foreground ml-5",children:M(we.value)})]})},we.value)),e[58]=M,e[59]=T,e[60]=ge):ge=e[60];let Ae;e[61]!==ge?(Ae=s.jsx(It,{align:"start",children:ge}),e[61]=ge,e[62]=Ae):Ae=e[62];let Se;e[63]!==Y||e[64]!==le||e[65]!==Ae?(Se=s.jsxs(St,{value:Y,onValueChange:ne,children:[le,Ae]}),e[63]=Y,e[64]=le,e[65]=Ae,e[66]=Se):Se=e[66];let Ce;e[67]!==te||e[68]!==Se?(Ce=s.jsxs("div",{className:"flex flex-wrap items-center gap-2",children:[te,Se]}),e[67]=te,e[68]=Se,e[69]=Ce):Ce=e[69];let he;e[70]!==d||e[71]!==$||e[72]!==c||e[73]!==i?(he=c==="project"&&s.jsxs("div",{className:"flex flex-wrap items-center gap-2",children:[s.jsx("span",{className:"typography-ui-label text-foreground",children:i("settings.skills.catalog.installSkill.field.project")}),d.length===0?s.jsx("span",{className:"typography-meta text-muted-foreground",children:i("settings.skills.catalog.installSkill.field.noProjects")}):s.jsxs(St,{value:$??"",onValueChange:we=>P(we),disabled:d.length===1,children:[s.jsx(Ct,{className:"w-fit",children:s.jsx(Mt,{placeholder:i("settings.skills.catalog.installSkill.field.chooseProjectPlaceholder")})}),s.jsx(It,{align:"start",children:d.map(dm)})]})]}),e[70]=d,e[71]=$,e[72]=c,e[73]=i,e[74]=he):he=e[74];let _e;e[75]!==r.warnings?(_e=r.warnings?.length?s.jsx("div",{className:"typography-micro text-[var(--status-warning)] bg-[var(--status-warning)]/10 px-2 py-1.5 rounded",children:r.warnings.join(" · ")}):null,e[75]=r.warnings,e[76]=_e):_e=e[76];let Ue;e[77]!==Ce||e[78]!==he||e[79]!==_e?(Ue=s.jsxs("div",{className:"mt-2 space-y-3",children:[Ce,he,_e]}),e[77]=Ce,e[78]=he,e[79]=_e,e[80]=Ue):Ue=e[80];let ke;e[81]!==n?(ke=()=>n(!1),e[81]=n,e[82]=ke):ke=e[82];let Oe;e[83]!==i?(Oe=i("settings.common.actions.cancel"),e[83]=i,e[84]=Oe):Oe=e[84];let Ve;e[85]!==ke||e[86]!==Oe?(Ve=s.jsx(B,{size:"sm",variant:"ghost",onClick:ke,children:Oe}),e[85]=ke,e[86]=Oe,e[87]=Ve):Ve=e[87];const We=g||!r.installable||c==="project"&&!W;let ve;e[88]!==W||e[89]!==L||e[90]!==r.repoSource||e[91]!==r.repoSubpath||e[92]!==r.skillDir||e[93]!==c||e[94]!==p?(ve=()=>{L({source:r.repoSource,subpath:r.repoSubpath,scope:c,targetSource:p,skillDir:r.skillDir,directoryOverride:W})},e[88]=W,e[89]=L,e[90]=r.repoSource,e[91]=r.repoSubpath,e[92]=r.skillDir,e[93]=c,e[94]=p,e[95]=ve):ve=e[95];let Z;e[96]!==g||e[97]!==i?(Z=i(g?"settings.skills.catalog.installSkill.actions.installing":"settings.skills.catalog.installSkill.actions.install"),e[96]=g,e[97]=i,e[98]=Z):Z=e[98];let se;e[99]!==We||e[100]!==ve||e[101]!==Z?(se=s.jsx(B,{size:"sm",disabled:We,onClick:ve,children:Z}),e[99]=We,e[100]=ve,e[101]=Z,e[102]=se):se=e[102];let ye;e[103]!==Ve||e[104]!==se?(ye=s.jsxs(ts,{children:[Ve,se]}),e[103]=Ve,e[104]=se,e[105]=ye):ye=e[105];let be;e[106]!==z||e[107]!==Ue||e[108]!==ye?(be=s.jsxs(zt,{className:"max-w-md",children:[z,Ue,ye]}),e[106]=z,e[107]=Ue,e[108]=ye,e[109]=be):be=e[109];let Re;e[110]!==n||e[111]!==a||e[112]!==be?(Re=s.jsx(Kt,{open:a,onOpenChange:n,children:be}),e[110]=n,e[111]=a,e[112]=be,e[113]=Re):Re=e[113];let Fe;e[114]!==I||e[115]!==L?(Fe=we=>{I&&(L({source:I.source,subpath:I.subpath,scope:I.scope,targetSource:I.targetSource,skillDir:I.skillDir,conflictDecisions:we,directoryOverride:I.directoryOverride??null}),N(!1))},e[114]=I,e[115]=L,e[116]=Fe):Fe=e[116];let Ke;e[117]!==A||e[118]!==x||e[119]!==Fe?(Ke=s.jsx(am,{open:x,onOpenChange:N,conflicts:A,onConfirm:Fe}),e[117]=A,e[118]=x,e[119]=Fe,e[120]=Ke):Ke=e[120];let Ee;return e[121]!==Re||e[122]!==Ke?(Ee=s.jsxs(s.Fragment,{children:[Re,Ke]}),e[121]=Re,e[122]=Ke,e[123]=Ee):Ee=e[123],Ee};function rm(t){return t.installSkills}function om(t){return t.isInstalling}function lm(t){return t.projects}function cm(t){return t.activeProjectId}function dm(t){return s.jsx(at,{value:t.id,children:t.label||t.path},t.id)}const um=/^[A-Za-z0-9_.-]+\/[A-Za-z0-9_.-]+$/,pm=t=>{const e=t.trim();return um.test(e)?`https://github.com/${e}`:null},mm=t=>{const e=pm(t.repoSource);if(!e)return null;const a=[t.repoSubpath,t.skillDir].filter(Boolean).join("/");return a?`${e}/tree/HEAD/${a}`:e};let ui=null;const gm=t=>{const e=Sr();return(!ui||ui.locale!==e)&&(ui={locale:e,formatter:new Intl.NumberFormat(e,{notation:"compact"})}),ui.formatter.format(t)},hm=t=>{const e=Date.parse(t);if(Number.isNaN(e))return null;const a=Date.now()-e;if(a<6e4)return{key:"common.relative.justNow",count:0};const n=Math.floor(a/6e4);if(n<60)return{key:"common.relative.minutesAgoShort",count:n};const r=Math.floor(n/60);if(r<24)return{key:"common.relative.hoursAgoShort",count:r};const i=Math.floor(r/24);if(i<7)return{key:"common.relative.daysAgoShort",count:i};const l=Math.floor(i/7);return l<52?{key:"common.relative.weeksAgoShort",count:l}:{key:"common.relative.yearsAgoShort",count:Math.floor(i/365)}},fm=t=>{const e=ut.c(50),{source:a,isActive:n,isLoading:r,skillsCount:i,onSelect:l,t:g}=t,c=a.stars??null;let y,p,b,d,C,f,P,x,N,m;if(e[0]!==n||e[1]!==r||e[2]!==l||e[3]!==i||e[4]!==a.label||e[5]!==a.repoUpdatedAt||e[6]!==a.source||e[7]!==c||e[8]!==g){const j=a.repoUpdatedAt?hm(a.repoUpdatedAt):null;x="button",N=l,m=n;const h=n?"border-primary":"border-[var(--surface-subtle)] hover:border-[var(--interactive-border-hover)]";e[19]!==h?(p=fe("w-full min-h-24 text-left rounded-lg border bg-[var(--surface-elevated)] p-3.5 flex gap-3 items-start transition-colors","focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-ring",h),e[19]=h,e[20]=p):p=e[20],C="min-w-0 flex-1 block";let w;e[21]!==a.label?(w=s.jsx("span",{className:"typography-ui-label font-medium text-foreground truncate",children:a.label}),e[21]=a.label,e[22]=w):w=e[22];let O;e[23]!==r||e[24]!==i||e[25]!==g?(O=r?s.jsx(F,{name:"refresh",className:"h-3 w-3 animate-spin text-muted-foreground shrink-0"}):i!==null&&s.jsx("span",{className:"typography-micro text-muted-foreground shrink-0",children:g("settings.skills.catalog.page.source.skillsCount",{count:i})}),e[23]=r,e[24]=i,e[25]=g,e[26]=O):O=e[26],e[27]!==w||e[28]!==O?(f=s.jsxs("span",{className:"flex items-center gap-2",children:[w,O]}),e[27]=w,e[28]=O,e[29]=f):f=e[29],e[30]!==a.source?(P=s.jsx("span",{className:"typography-micro font-mono text-muted-foreground block mt-0.5 truncate",children:a.source}),e[30]=a.source,e[31]=P):P=e[31],y="flex items-center gap-3 mt-1",e[32]!==c||e[33]!==g?(b=c!==null&&s.jsxs("span",{className:"typography-micro text-muted-foreground flex items-center gap-1",title:g("settings.skills.catalog.page.source.stars",{count:c}),children:[s.jsx(F,{name:"star",className:"h-3 w-3"}),gm(c)]}),e[32]=c,e[33]=g,e[34]=b):b=e[34],d=j&&s.jsx("span",{className:"typography-micro text-muted-foreground",children:j.key==="common.relative.justNow"?g(j.key):g("settings.skills.catalog.page.source.updated",{time:g(j.key,{count:j.count})})}),e[0]=n,e[1]=r,e[2]=l,e[3]=i,e[4]=a.label,e[5]=a.repoUpdatedAt,e[6]=a.source,e[7]=c,e[8]=g,e[9]=y,e[10]=p,e[11]=b,e[12]=d,e[13]=C,e[14]=f,e[15]=P,e[16]=x,e[17]=N,e[18]=m}else y=e[9],p=e[10],b=e[11],d=e[12],C=e[13],f=e[14],P=e[15],x=e[16],N=e[17],m=e[18];let A;e[35]!==y||e[36]!==b||e[37]!==d?(A=s.jsxs("span",{className:y,children:[b,d]}),e[35]=y,e[36]=b,e[37]=d,e[38]=A):A=e[38];let R;e[39]!==A||e[40]!==C||e[41]!==f||e[42]!==P?(R=s.jsxs("span",{className:C,children:[f,P,A]}),e[39]=A,e[40]=C,e[41]=f,e[42]=P,e[43]=R):R=e[43];let I;return e[44]!==p||e[45]!==R||e[46]!==x||e[47]!==N||e[48]!==m?(I=s.jsx("button",{type:x,onClick:N,"aria-pressed":m,className:p,children:R}),e[44]=p,e[45]=R,e[46]=x,e[47]=N,e[48]=m,e[49]=I):I=e[49],I},xm=({mode:t,onModeChange:e,showModeTabs:a=!0})=>{const{t:n}=tt(),{sources:r,itemsBySource:i,selectedSourceId:l,setSelectedSource:g,loadCatalog:c,loadSource:y,isLoadingCatalog:p,isLoadingSource:b,loadedSourceIds:d,lastCatalogError:C}=hn(Us(L=>({sources:L.sources,itemsBySource:L.itemsBySource,selectedSourceId:L.selectedSourceId,setSelectedSource:L.setSelectedSource,loadCatalog:L.loadCatalog,loadSource:L.loadSource,isLoadingCatalog:L.isLoadingCatalog,isLoadingSource:L.isLoadingSource,loadedSourceIds:L.loadedSourceIds,lastCatalogError:L.lastCatalogError}))),[f,P]=o.useState(""),[x,N]=o.useState(!1),[m,A]=o.useState(!1),[R,I]=o.useState(null),[j,h]=o.useState(!1),[w,O]=o.useState(!1),T=o.useRef(null);o.useEffect(()=>{c()},[c]),o.useEffect(()=>{const L=r.filter(U=>!d[U.id]);if(L.length===0)return;let J=!1;return(async()=>{for(const U of L){if(J)return;await y(U.id)}})(),()=>{J=!0}},[r,d,y]),o.useEffect(()=>{!l||d[l]||y(l)},[l,d,y]),o.useEffect(()=>{const L=J=>{(J.metaKey||J.ctrlKey)&&J.key.toLowerCase()==="k"&&(J.preventDefault(),T.current?.focus())};return window.addEventListener("keydown",L),()=>window.removeEventListener("keydown",L)},[]);const S=f.trim().length>0,M=o.useMemo(()=>S?ki(r.flatMap(L=>i[L.id]||[]),f,L=>[L.skillName,L.frontmatterName,L.description]):l?i[l]||[]:[],[r,i,l,f,S]),V=o.useMemo(()=>r.find(L=>L.id===l)||null,[r,l]),$=!!(l&&l.startsWith("custom:")),k=async()=>{if(!(!l||!$)){h(!0);try{const L=await pn();if(!L)return;const ee=(L.skillCatalogs??[]).filter(U=>U.id!==l);await pt({skillCatalogs:ee}),await c({refresh:!0}),O(!1)}finally{h(!1)}}},W=S?n("settings.skills.catalog.page.list.searchTitle"):V?.label??"",D=!S&&l!==null&&!d[l]&&(b||p);return s.jsxs(s.Fragment,{children:[s.jsxs(es,{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(Ir,{items:[{id:"manual",label:n("settings.skills.catalog.page.mode.manual")},{id:"external",label:n("settings.skills.catalog.page.mode.external")}],activeId:t,onSelect:L=>e(L),layoutMode:"fit",variant:"animated",animateActivePill:!1,className:"h-full"})})}),s.jsx("p",{className:"typography-meta text-muted-foreground mb-4",children:n("settings.skills.catalog.page.subtitle")}),s.jsx("div",{"data-settings-item":"skills.catalog.search",className:"mb-5",children:s.jsxs("div",{className:"relative max-w-md",children:[s.jsx(F,{name:"search",className:"absolute left-2.5 top-1/2 -translate-y-1/2 h-3.5 w-3.5 text-muted-foreground"}),s.jsx(He,{ref:T,value:f,onChange:L=>P(L.target.value),placeholder:n("settings.skills.catalog.page.searchAllPlaceholder"),className:fe("h-8 pl-8 w-full",f&&"pr-8")}),f&&s.jsx("button",{type:"button",onClick:()=>{P(""),T.current?.focus()},className:"absolute right-2 top-1/2 -translate-y-1/2 flex items-center justify-center h-4 w-4 rounded text-muted-foreground hover:text-foreground transition-colors",title:n("settings.skills.catalog.page.search.clear"),children:s.jsx(F,{name:"close",className:"h-3 w-3"})})]})}),s.jsx(ze,{title:n("settings.skills.catalog.page.section.sources"),divider:!1,settingsItem:"skills.catalog.source",contentClassName:"space-y-0",children:s.jsxs("div",{className:"grid grid-cols-1 sm:grid-cols-2 gap-3 py-1.5",children:[r.map(L=>s.jsx(fm,{source:L,isActive:L.id===l,isLoading:b&&!d[L.id],skillsCount:d[L.id]?(i[L.id]||[]).length:null,onSelect:()=>g(L.id),t:n},L.id)),s.jsxs("button",{type:"button","data-settings-item":"skills.catalog.add-catalog",onClick:()=>N(!0),className:"min-h-24 text-left rounded-lg border border-dashed border-[var(--interactive-border)] hover:border-[var(--interactive-border-hover)] hover:bg-[var(--surface-muted)] p-3.5 flex gap-3 items-start transition-colors",children:[s.jsx("span",{className:"flex items-center justify-center rounded-md bg-transparent text-muted-foreground w-8 h-8 shrink-0",children:s.jsx(F,{name:"add",className:"h-4 w-4"})}),s.jsxs("span",{className:"min-w-0",children:[s.jsx("span",{className:"typography-ui-label text-muted-foreground block",children:n("settings.skills.catalog.page.source.addOwnTitle")}),s.jsx("span",{className:"typography-micro text-muted-foreground/70 block mt-0.5",children:n("settings.skills.catalog.page.source.addOwnDescription")})]})]})]})}),C&&s.jsx(ze,{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:C.message})]})}),s.jsxs(ze,{children:[s.jsxs("div",{className:"flex items-center justify-between gap-2 pb-2",children:[s.jsxs("div",{className:"flex items-center gap-2 min-w-0",children:[s.jsx("span",{className:"typography-micro font-medium uppercase tracking-wide text-muted-foreground truncate",children:W}),s.jsx("span",{className:"typography-micro text-muted-foreground/70 shrink-0",children:n("settings.skills.catalog.page.foundCount",{count:M.length})})]}),s.jsxs("div",{className:"flex items-center gap-1 shrink-0",children:[s.jsx(B,{variant:"ghost",size:"xs",className:"!font-normal h-6 w-6 px-0",onClick:()=>{l&&!S?y(l,{refresh:!0}):c({refresh:!0})},disabled:p||b,title:n("settings.skills.catalog.page.actions.refreshTitle"),children:s.jsx(F,{name:"refresh",className:fe("h-3.5 w-3.5",(p||b)&&"animate-spin")})}),$&&!S&&s.jsx(B,{variant:"ghost",size:"xs",className:"!font-normal h-6 w-6 px-0 text-[var(--status-error)] hover:text-[var(--status-error)]",onClick:()=>O(!0),disabled:j,title:n("settings.skills.catalog.page.actions.removeCatalogTitle"),children:s.jsx(F,{name:"delete-bin",className:"h-3.5 w-3.5"})})]})]}),D||b&&M.length===0?s.jsxs("div",{className:"py-8 text-center text-muted-foreground",children:[s.jsx(F,{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")})]}):M.length===0?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")})]}):s.jsx("div",{className:"divide-y divide-[var(--surface-subtle)]",children:M.map(L=>{const J=L.installed?.isInstalled,ee=L.installed?.scope,U=mm(L);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:L.skillName}),J&&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:ee||n("settings.skills.catalog.page.badge.unknown")})}),!L.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")})]}),L.description?s.jsx("div",{className:"typography-meta text-muted-foreground mt-0.5 line-clamp-2",children:L.description}):s.jsx("div",{className:"typography-meta text-muted-foreground/50 mt-0.5 italic",children:n("settings.skills.catalog.shared.noDescription")}),s.jsxs("div",{className:"typography-micro text-muted-foreground/80 mt-1 flex items-center gap-2 min-w-0",children:[U?s.jsxs("a",{href:U,target:"_blank",rel:"noreferrer",className:"font-mono hover:underline truncate inline-flex items-center gap-1",title:n("settings.skills.catalog.page.skill.viewOnGithub"),children:[s.jsx(F,{name:"github",className:"h-3 w-3 shrink-0"}),L.repoSource]}):s.jsx("span",{className:"font-mono truncate",children:L.repoSource}),L.skillDir&&s.jsxs(s.Fragment,{children:[s.jsx("span",{className:"opacity-40",children:"·"}),s.jsx("span",{className:"truncate",children:L.skillDir})]})]}),L.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:L.warnings.join(" · ")}):null]}),s.jsxs("div",{className:"flex items-center gap-1.5 shrink-0",children:[U&&s.jsx(B,{variant:"ghost",size:"xs",className:"!font-normal h-6 w-6 px-0",onClick:()=>window.open(U,"_blank","noreferrer"),title:n("settings.skills.catalog.page.skill.viewOnGithub"),children:s.jsx(F,{name:"external-link",className:"h-3.5 w-3.5"})}),J?s.jsx("span",{className:"text-[var(--status-success)] flex items-center justify-center w-7 h-7",title:n("settings.skills.catalog.page.badge.installed",{scope:ee||""}),children:s.jsx(F,{name:"check",className:"h-4 w-4"})}):s.jsx(B,{variant:"outline",size:"xs",className:"!font-normal",disabled:!L.installable,onClick:()=>{I(L),A(!0)},children:n("settings.skills.catalog.shared.actions.install")})]})]})},`${L.sourceId}:${L.skillDir}`)})})]})]}),s.jsx(nm,{open:x,onOpenChange:N}),s.jsx(im,{open:m,onOpenChange:A,item:R}),s.jsx(Kt,{open:w,onOpenChange:L=>{j||O(L)},children:s.jsxs(zt,{className:"max-w-md",children:[s.jsxs(_t,{children:[s.jsx($t,{children:n("settings.skills.catalog.page.removeDialog.title")}),s.jsx(Vt,{children:n("settings.skills.catalog.page.removeDialog.description")})]}),s.jsxs(ts,{children:[s.jsx(B,{size:"sm",variant:"ghost",onClick:()=>O(!1),disabled:j,children:n("settings.common.actions.cancel")}),s.jsx(B,{size:"sm",variant:"destructive",onClick:()=>{k()},disabled:j,children:n("settings.skills.catalog.page.actions.removeCatalog")})]})]})})]})},vm=()=>{const t=ut.c(1);let e;return t[0]===Symbol.for("react.memo_cache_sentinel")?(e=s.jsx(xm,{mode:"external",onModeChange:Nm,showModeTabs:!1}),t[0]=e):e=t[0],e},ym="SKILL.md",bm="h-[clamp(320px,58dvh,680px)] min-h-[260px] max-h-[calc(100dvh-220px)]",bi=(t,e)=>{const a=tu({description:t}).trimEnd(),n=e.trimStart();return`---
22
- ${a}
23
- ---${n?`
24
-
25
- ${n}`:`
26
- `}`},wm=t=>typeof t=="object"&&t!==null&&!Array.isArray(t),ql=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=su(e[1]);if(wm(n)){const r=n.description;typeof r=="string"&&(a=r)}}catch{a=null}return{description:a,instructions:e[2].replace(/^\r?\n/,"")}},jm=(t,e)=>{const a=ql(t);return bi(e,a.instructions)},km=()=>{const{t}=tt(),{currentTheme:e}=Cr(),{selectedSkillName:a,getSkillByName:n,getSkillDetail:r,createSkill:i,updateSkill:l,skillDraft:g,setSkillDraft:c,setSelectedSkill:y}=Hs(Us(pe=>({selectedSkillName:pe.selectedSkillName,getSkillByName:pe.getSkillByName,getSkillDetail:pe.getSkillDetail,createSkill:pe.createSkill,updateSkill:pe.updateSkill,skillDraft:pe.skillDraft,setSkillDraft:pe.setSkillDraft,setSelectedSkill:pe.setSelectedSkill}))),p=_s(),b=Hs(pe=>wr(pe,p)),d=a?n(a,p):null,C=!!(g&&g.name===a&&!d),f=!!(a&&!d&&!g),P=d?.path==="<built-in>";o.useEffect(()=>{f&&y(null)},[f,y]);const[x,N]=o.useState(""),[m,A]=o.useState("user"),[R,I]=o.useState("opencode"),[j,h]=o.useState(""),[w,O]=o.useState(""),[T,S]=o.useState(()=>bi("","")),[M,V]=o.useState("edit"),[$,k]=o.useState([]),[W,D]=o.useState([]),[L,J]=o.useState(!1),[ee,U]=o.useState(!1),[re,_]=o.useState(""),[H,z]=o.useState(""),[K,te]=o.useState(!1),[Y,ne]=o.useState(""),[me,de]=o.useState(""),[xe,ae]=o.useState(null),[le,ge]=o.useState(!1),[Ae,Se]=o.useState(""),[Ce,he]=o.useState(null),[_e,Ue]=o.useState(!1),ke=C?x.trim()!==""||j.trim()!==""||w.trim()!==""||W.length>0:j!==re||w!==H,Oe=xe?me!==Ae:Y.trim()!=="",Ve=o.useCallback(pe=>{switch(pe){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]),We=o.useCallback(pe=>{switch(pe){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(C&&g){const Ne=g.description||"",Le=g.instructions||"";N(g.name||""),A(g.scope||"user"),I(g.source==="agents"?"agents":"opencode"),h(Ne),O(Le),S(bi(Ne,Le)),_(""),z(""),k([]),D(g.pendingFiles||[])}else if(a&&d){U(!0);try{const Ne=await r(a,p);if(Ne){const Le=Ne.sources.md,Xe=Le.description||"",q=Le.instructions||"";h(Xe),O(q),S(bi(Xe,q)),_(Xe),z(q),k(Le.supportingFiles||[])}}catch(Ne){console.error("Failed to load skill details:",Ne)}finally{U(!1)}}})()},[d,C,a,p,b,g,r]);const ve=ie(pe=>pe.editorFontSize),Z=o.useMemo(()=>{const pe=[io(e,{fontSize:ve})],Ne=zr(ym);return Ne&&pe.push(Ne),pe.push(oo.lineWrapping),pe},[e,ve]),se=o.useMemo(()=>{const pe=Y.trim()||"supporting-file.md",Ne=Ic(pe),Le=!!Ne&&Ne!=="markdown",Xe=[io(e,Le?{syntaxColors:!1,fontSize:ve}:{fontSize:ve})],q=zr(pe);return q&&Xe.push(q),Le&&Ne&&Xe.push(nu({language:Ne,themeName:e.metadata.id,theme:iu(e)})),Xe.push(oo.lineWrapping),Xe},[e,Y,ve]),ye=o.useCallback(pe=>{h(pe),S(Ne=>jm(Ne,pe))},[]),be=o.useCallback(pe=>{S(pe);const Ne=ql(pe);h(Ne.description??""),O(Ne.instructions)},[]),Re=async()=>{const pe=C?x.trim().replace(/\s+/g,"-").toLowerCase():a?.trim();if(!pe){E.error(t("settings.skills.page.toast.skillNameRequired"));return}if(!/^[a-z0-9][a-z0-9-]*[a-z0-9]$|^[a-z0-9]$/.test(pe)||pe.length>64){E.error(t("settings.skills.page.toast.invalidSkillName"));return}if(!j.trim()){E.error(t("settings.skills.page.toast.descriptionRequired"));return}if(C&&b.some(Ne=>Ne.name===pe)){E.error(t("settings.skills.page.toast.skillExists"));return}J(!0);try{const Ne={name:pe,description:j.trim(),instructions:w.trim()||void 0,scope:C?m:void 0,source:C?R:void 0,targetPath:C?void 0:d?.path,supportingFiles:C&&W.length>0?W:void 0};let Le;if(C?(Le=await i(Ne,p),Le&&(c(null),D([]),y(pe))):(Le=await l(pe,Ne,p),Le&&(_(j.trim()),z(w.trim()))),Le){const Xe=Vn.getState().changes.some(q=>q.scope==="skills"&&q.id.startsWith(`skills:${pe}:`));E.success(t(Xe?"settings.view.pendingRestart.saved":C?"settings.skills.page.toast.skillCreated":"settings.skills.page.toast.skillUpdated"))}else E.error(t(C?"settings.skills.page.toast.createSkillFailed":"settings.skills.page.toast.updateSkillFailed"))}catch(Ne){console.error("Error saving skill:",Ne),E.error(t("settings.skills.page.toast.saveUnexpectedError"))}finally{J(!1)}},Fe=()=>{ae(null),ne(""),de(""),Se(""),te(!0)},Ke=async pe=>{if(ae(pe),ne(pe),C){const Le=W.find(Xe=>Xe.path===pe)?.content||"";de(Le),Se(Le),te(!0);return}if(a){ge(!0),te(!0);try{const{readSupportingFile:Ne}=Hs.getState(),Le=await Ne(a,pe,p);de(Le||""),Se(Le||"")}catch{E.error(t("settings.skills.page.toast.loadFileContentFailed")),de(""),Se("")}finally{ge(!1)}}},Ee=async()=>{if(!Y.trim()){E.error(t("settings.skills.page.toast.fileNameRequired"));return}const pe=Y.trim(),Ne=xe!==null;if(C){if(Ne)D(q=>q.map(je=>je.path===xe?{path:pe,content:me}:je)),E.success(t("settings.skills.page.toast.fileUpdated",{path:pe}));else{if(W.some(q=>q.path===pe)){E.error(t("settings.skills.page.toast.fileExists"));return}D(q=>[...q,{path:pe,content:me}]),E.success(t("settings.skills.page.toast.fileAdded",{path:pe}))}te(!1),ae(null);return}if(!a){E.error(t("settings.skills.page.toast.noSkillSelected"));return}const{writeSupportingFile:Le}=Hs.getState();if(await Le(a,pe,me,p)){E.success(Ne?t("settings.skills.page.toast.fileUpdated",{path:pe}):t("settings.skills.page.toast.fileCreated",{path:pe})),te(!1),ae(null);const q=await r(a,p);q&&k(q.sources.md.supportingFiles||[])}else E.error(t(Ne?"settings.skills.page.toast.updateFileFailed":"settings.skills.page.toast.createFileFailed"))},we=pe=>{if(C){D(Ne=>Ne.filter(Le=>Le.path!==pe)),E.success(t("settings.skills.page.toast.fileRemoved",{path:pe}));return}a&&he(pe)},Ze=async()=>{if(!Ce||!a)return;Ue(!0);const{deleteSupportingFile:pe}=Hs.getState();if(await pe(a,Ce,p)){E.success(t("settings.skills.page.toast.fileDeleted",{path:Ce}));const Le=await r(a,p);Le&&k(Le.sources.md.supportingFiles||[]),he(null)}else E.error(t("settings.skills.page.toast.deleteFileFailed"));Ue(!1)};return!a&&!g||f?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(F,{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")})]})}):ee?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(es,{title:C?t("settings.skills.page.title.newSkill"):a,description:d?t("settings.skills.page.subtitle.skillLocation",{location:Ve(Ua(d.scope,d.source))}):t("settings.skills.page.subtitle.newSkill"),showSaveStatus:!1,children:[s.jsxs(ze,{title:t("settings.skills.page.section.basicInformation"),divider:!1,settingsItem:"skills.basic-information",contentClassName:"space-y-0",children:[C&&s.jsxs(Rt,{label:t("settings.skills.page.field.skillNameLocation"),info:t("settings.skills.page.field.skillNameHint"),children:[s.jsx(He,{value:x,onChange:pe=>N(pe.target.value.toLowerCase().replace(/\s+/g,"-")),placeholder:t("settings.skills.page.field.skillNamePlaceholder"),className:"h-7 w-40 px-2"}),s.jsxs(St,{value:Ua(m,R),onValueChange:pe=>{const Ne=Gl(pe);A(Ne.scope),I(Ne.source==="agents"?"agents":"opencode")},children:[s.jsxs(Ct,{size:Ft,className:"w-fit gap-1.5",children:[m==="user"?s.jsx(F,{name:"user-3",className:"h-3.5 w-3.5"}):s.jsx(F,{name:"folder",className:"h-3.5 w-3.5"}),R==="agents"?s.jsx(F,{name:"robot-2",className:"h-3.5 w-3.5"}):null,s.jsx("span",{children:Ve(Ua(m,R))})]}),s.jsx(It,{align:"start",children:Pr.map(pe=>s.jsx(at,{value:pe.value,children:s.jsxs("div",{className:"flex flex-col gap-0.5",children:[s.jsxs("div",{className:"flex items-center gap-2",children:[pe.scope==="user"?s.jsx(F,{name:"user-3",className:"h-3.5 w-3.5"}):s.jsx(F,{name:"folder",className:"h-3.5 w-3.5"}),pe.source==="agents"?s.jsx(F,{name:"robot-2",className:"h-3.5 w-3.5"}):null,s.jsx("span",{children:Ve(pe.value)})]}),s.jsx("span",{className:"typography-micro text-muted-foreground ml-6",children:We(pe.value)})]})},pe.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(Ts,{value:j,onChange:pe=>ye(pe.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:P})})]}),s.jsx(ze,{title:t("settings.skills.page.section.instructions"),headerAction:s.jsx(au,{currentMode:M==="preview"?"preview":"edit",onToggle:()=>V(pe=>pe==="preview"?"edit":"preview")}),settingsItem:"skills.instructions",children:s.jsx("div",{className:fe("overflow-hidden rounded-md border border-[var(--surface-subtle)] bg-background",bm),children:M==="preview"?s.jsx(vs,{outerClassName:"h-full",className:"h-full",children:s.jsx("div",{className:"min-h-full px-4 py-3",children:s.jsx(Pc,{content:T,className:"typography-markdown-body",stripFrontmatter:!0,enableFileReferences:!1})})}):s.jsx(ro,{value:T,onChange:be,readOnly:P,extensions:Z,className:"h-full",enableSearch:!0})})}),s.jsx(ze,{title:t("settings.skills.page.section.supportingFiles"),headerAction:s.jsxs(B,{variant:"outline",size:"xs",className:"!font-normal gap-1",onClick:Fe,disabled:P,children:[s.jsx(F,{name:"add",className:"h-3.5 w-3.5"})," ",t("settings.skills.page.actions.addFile")]}),settingsItem:"skills.supporting-files",children:(()=>{const pe=C?W:$;return pe.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:pe.map(Ne=>s.jsxs("div",{className:"flex items-center gap-2 py-1.5 cursor-pointer group",onClick:()=>Ke(Ne.path),children:[s.jsx(F,{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:Ne.path}),C&&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")}),!P&&s.jsx(B,{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:Le=>{Le.stopPropagation(),we(Ne.path)},children:s.jsx(F,{name:"delete-bin",className:"h-3 w-3"})})]},Ne.path))})})()}),s.jsx(ze,{children:s.jsx(B,{onClick:Re,disabled:P||L||!ke,size:"xs",className:"!font-normal",children:t(L?"settings.common.actions.saving":C?"settings.skills.page.actions.createSkill":"settings.common.actions.saveChanges")})})]}),s.jsx(Kt,{open:Ce!==null,onOpenChange:pe=>{!pe&&!_e&&he(null)},children:s.jsxs(zt,{className:"max-w-md",children:[s.jsxs(_t,{children:[s.jsx($t,{children:t("settings.skills.page.deleteFileDialog.title")}),s.jsx(Vt,{children:t("settings.skills.page.deleteFileDialog.description",{path:Ce??""})})]}),s.jsxs(ts,{children:[s.jsx(B,{size:"sm",variant:"ghost",onClick:()=>he(null),disabled:_e,children:t("settings.common.actions.cancel")}),s.jsx(B,{size:"sm",variant:"destructive",onClick:Ze,disabled:_e,children:t("settings.common.actions.delete")})]})]})}),s.jsx(Kt,{open:K,onOpenChange:pe=>{te(pe),pe||ae(null)},children:s.jsxs(zt,{className:"max-w-3xl max-h-[85vh] flex flex-col",children:[s.jsxs(_t,{className:"flex-shrink-0",children:[s.jsx($t,{children:t(xe?"settings.skills.page.fileDialog.titleEdit":"settings.skills.page.fileDialog.titleAdd")}),s.jsx(Vt,{children:t(xe?"settings.skills.page.fileDialog.descriptionEdit":"settings.skills.page.fileDialog.descriptionAdd")})]}),le?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:Tt,children:t("settings.skills.page.fileDialog.field.filePath")}),!xe&&s.jsx(Jt,{children:t("settings.skills.page.fileDialog.field.filePathHint")})]}),s.jsx(He,{value:Y,onChange:pe=>ne(pe.target.value),placeholder:t("settings.skills.page.fileDialog.field.filePathPlaceholder"),className:"text-foreground placeholder:text-muted-foreground focus-visible:ring-[var(--primary-base)]",disabled:xe!==null})]}),s.jsxs("div",{className:"space-y-2 flex-1 min-h-0 flex flex-col",children:[s.jsx("label",{className:`${Tt} 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(ro,{value:me,onChange:de,extensions:se,className:"h-full",enableSearch:!0})})]})]}),s.jsxs(ts,{className:"mt-4",children:[s.jsx(B,{size:"sm",variant:"ghost",onClick:()=>{te(!1),ae(null)},children:t("settings.common.actions.cancel")}),s.jsx(B,{size:"sm",onClick:Ee,disabled:le||!Oe,children:t(xe?"settings.common.actions.saveChanges":"settings.skills.page.actions.createFile")})]})]})})]})},No=t=>{const e=ut.c(2),{view:a}=t,n=a===void 0?"installed":a;let r;return e[0]!==n?(r=n==="catalog"?s.jsx(vm,{}):s.jsx(km,{}),e[0]=n,e[1]=r):r=e[1],r};function Nm(){}const Sm=t=>{const e=ut.c(38),{onItemSelect:a}=t,{t:n}=tt(),r=Ws(Cm),i=ie(Im),l=ie(Pm),{currentTheme:g}=Cr();let c;e[0]===Symbol.for("react.memo_cache_sentinel")?(c=cs(),e[0]=c):c=e[0];const y=c,p=Am;let b,d;e[1]!==r||e[2]!==i||e[3]!==l?(b=()=>{if(r.length===0){i!==null&&l(null);return}i&&r.some(h=>h.id===i)||l(r[0].id)},d=[r,i,l],e[1]=r,e[2]=i,e[3]=l,e[4]=b,e[5]=d):(b=e[4],d=e[5]),o.useEffect(b,d);let C;e[6]===Symbol.for("react.memo_cache_sentinel")?(C=fe("border-b px-3","pt-4 pb-3"),e[6]=C):C=e[6];let f;e[7]!==n?(f=n("settings.page.projects.title"),e[7]=n,e[8]=f):f=e[8];let P;e[9]!==f?(P=s.jsx("h2",{className:`${un} mb-3`,children:f}),e[9]=f,e[10]=P):P=e[10];let x;e[11]!==r.length||e[12]!==n?(x=n("settings.projects.sidebar.total",{count:r.length}),e[11]=r.length,e[12]=n,e[13]=x):x=e[13];let N;e[14]!==x?(N=s.jsx("span",{className:"typography-meta text-muted-foreground",children:x}),e[14]=x,e[15]=N):N=e[15];let m;e[16]!==n?(m=!y&&s.jsx(B,{type:"button",variant:"ghost",size:"icon",className:"h-7 w-7 -my-1 text-muted-foreground",onClick:p,"aria-label":n("settings.projects.sidebar.actions.addProject"),children:s.jsx(F,{name:"add",className:"size-4"})}),e[16]=n,e[17]=m):m=e[17];let A;e[18]!==N||e[19]!==m?(A=s.jsxs("div",{className:"flex items-center justify-between gap-2",children:[N,m]}),e[18]=N,e[19]=m,e[20]=A):A=e[20];let R;e[21]!==A||e[22]!==P?(R=s.jsxs("div",{className:C,children:[P,A]}),e[21]=A,e[22]=P,e[23]=R):R=e[23];let I;if(e[24]!==g||e[25]!==a||e[26]!==r||e[27]!==i||e[28]!==l){let h;e[30]!==g||e[31]!==a||e[32]!==i||e[33]!==l?(h=w=>{const O=w.id===i,T=w.icon?Tc[w.icon]:null,S=w.color?Ec[w.color]??null:null,M=T?s.jsx(F,{name:T,className:fe("h-4 w-4",O?"text-foreground":"text-muted-foreground/70"),style:S?{color:S}:void 0}):s.jsx(F,{name:"folder",className:fe("h-4 w-4",O?"text-foreground":"text-muted-foreground/70"),style:S?{color:S}:void 0}),V=w.iconImage?s.jsx("span",{className:"inline-flex h-4 w-4 items-center justify-center overflow-hidden rounded-[2px]",style:w.iconBackground?{backgroundColor:w.iconBackground}:void 0,children:s.jsx(Dc,{project:w,options:{themeVariant:g.metadata.variant,iconColor:g.colors.surface.foreground},className:"h-full w-full object-contain",fallback:M})}):M;return s.jsx(gr,{title:w.label||w.path,icon:V,selected:O,onSelect:()=>{l(w.id),a?.()}},w.id)},e[30]=g,e[31]=a,e[32]=i,e[33]=l,e[34]=h):h=e[34],I=r.map(h),e[24]=g,e[25]=a,e[26]=r,e[27]=i,e[28]=l,e[29]=I}else I=e[29];let j;return e[35]!==R||e[36]!==I?(j=s.jsx(Hl,{variant:"background",header:R,children:I}),e[35]=R,e[36]=I,e[37]=j):j=e[37],j};function Cm(t){return t.projects}function Im(t){return t.settingsProjectsSelectedId}function Pm(t){return t.setSettingsProjectsSelectedId}function Am(){Ac.requestDirectoryDialog()}const Tm=()=>{const t=ut.c(30),{t:e}=tt(),a=Ws(Em),n=Ws(Dm),r=ie(Mm),i=ie(Rm);let l;e:{if(!r){l=null;break e}let x;t[0]!==a||t[1]!==r?(x=a.find(N=>N.id===r)??null,t[0]=a,t[1]=r,t[2]=x):x=t[2],l=x}const g=l;let c,y;t[3]!==a||t[4]!==r||t[5]!==i?(c=()=>{if(a.length===0){i(null);return}r&&a.some(x=>x.id===r)||i(a[0].id)},y=[a,r,i],t[3]=a,t[4]=r,t[5]=i,t[6]=c,t[7]=y):(c=t[6],y=t[7]),o.useEffect(c,y);let p;t[8]!==g||t[9]!==n?(p=async x=>{g&&n(g.id,{label:x.label,icon:x.icon,color:x.color,iconBackground:x.iconBackground,defaultModel:x.defaultModel??null,defaultVariant:x.defaultVariant??null})},t[8]=g,t[9]=n,t[10]=p):p=t[10];const b=p;if(!g){let x;t[11]!==e?(x=e("settings.page.projects.title"),t[11]=e,t[12]=x):x=t[12];let N;t[13]!==e?(N=e("settings.projects.page.empty.noProjects"),t[13]=e,t[14]=N):N=t[14];let m;t[15]!==N?(m=s.jsx("p",{className:"typography-meta text-muted-foreground",children:N}),t[15]=N,t[16]=m):m=t[16];let A;return t[17]!==x||t[18]!==m?(A=s.jsx(es,{title:x,showSaveStatus:!0,children:m}),t[17]=x,t[18]=m,t[19]=A):A=t[19],A}let d;t[20]!==g.label||t[21]!==e?(d=g.label??e("settings.projects.page.title.default"),t[20]=g.label,t[21]=e,t[22]=d):d=t[22];const C=d;let f;t[23]!==b||t[24]!==g?(f=s.jsx(Gd,{project:g,onIdentitySave:b}),t[23]=b,t[24]=g,t[25]=f):f=t[25];let P;return t[26]!==C||t[27]!==g.path||t[28]!==f?(P=s.jsx(es,{title:C,description:g.path,showSaveStatus:!0,outerClassName:"bg-background",children:f}),t[26]=C,t[27]=g.path,t[28]=f,t[29]=P):P=t[29],P};function Em(t){return t.projects}function Dm(t){return t.updateProjectMeta}function Mm(t){return t.settingsProjectsSelectedId}function Rm(t){return t.setSettingsProjectsSelectedId}const wi=()=>Math.floor(2e4+Math.random()*3e4),Lm=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")},Om=()=>{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"},So=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}},Co=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.installingAiWorker";case"updating":return"settings.remoteInstances.page.phase.updatingAiWorker";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"}},Fm=new Set(["config_resolved","auth_check","master_connecting","remote_probe","installing","updating","server_detecting","server_starting","forwarding"]),Ar=t=>!!(t&&Fm.has(t)),Io=t=>t==="ready"?"ready":t==="error"?"error":t==="degraded"||Ar(t)?"connecting":"idle",Po=t=>{switch(t){case"ready":return"settings.remoteInstances.page.state.ready";case"connecting":return"settings.remoteInstances.page.state.connecting";case"error":return"settings.remoteInstances.page.state.problem";default:return"settings.remoteInstances.page.state.notConnected"}},Km=t=>{const e=(t||"").toLowerCase();return e?e.includes("ui authentication")||e.includes("ui password")?"uiPassword":e.includes("already in use")||e.includes("eaddrinuse")?"localPort":e.includes("neither bun nor npm")?"noRuntime":e.includes("opencode cli is not installed")?"noOpencode":e.includes("requires a ui password")?"uiPassword":e.includes("preferred remote aiworker port")?"externalPort":null:null},Ao={noRuntime:"settings.remoteInstances.page.error.hint.noRuntime",noOpencode:"settings.remoteInstances.page.error.hint.noOpencode"},zm=t=>t==="noRuntime"?Ao.noRuntime:t==="noOpencode"?Ao.noOpencode:null,To=t=>t==="ready"?"bg-[var(--status-success)] animate-pulse":t==="error"?"bg-[var(--status-error)] animate-pulse":t==="degraded"||Ar(t)?"bg-[var(--status-warning)] animate-pulse":"bg-muted-foreground/40",Um=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}`,_m=()=>({id:`forward-${Date.now()}-${Math.random().toString(16).slice(2)}`,enabled:!0,type:"local",localHost:"127.0.0.1",localPort:wi(),remoteHost:"127.0.0.1",remotePort:80}),$m=t=>t.trim().replace(/\*/g,"host").replace(/\?/g,"x")||"user@host",Vs=t=>{const e=ut.c(7),{label:a,hint:n}=t;let r;e[0]!==a?(r=s.jsx("span",{children:a}),e[0]=a,e[1]=r):r=e[1];let i;e[2]!==n?(i=s.jsx(Jt,{contentClassName:"max-w-xs",children:n}),e[2]=n,e[3]=i):i=e[3];let l;return e[4]!==r||e[5]!==i?(l=s.jsxs("span",{className:`inline-flex items-center gap-1 ${Tt}`,children:[r,i]}),e[4]=r,e[5]=i,e[6]=l):l=e[6],l},Vm=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"}},Eo=(t,e)=>{const a=(t||"").trim();return`${!a||a==="127.0.0.1"||a==="::1"?"localhost":a}:${e||0}`},Bm=t=>{const e=(t||"").trim();return!e||e==="0.0.0.0"||e==="::"?"127.0.0.1":e},Hm=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],r=(e[2]||"INFO").toUpperCase(),i=e[3]||"";return`[${n}] [${r}] ${i}`},fr=(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}),Wm=t=>t.trim().toLowerCase()==="authorization",Xi=t=>{const e={};for(const a of t){const n=a.name.trim(),r=a.value.trim();n&&r&&!Wm(n)&&(e[n]=r)}return Object.keys(e).length>0?e:void 0},Gm=t=>Object.entries(t||{}).map(([e,a])=>fr(e,a)),Jl=()=>{if(typeof window>"u")return null;const e=$a()||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}},Do=t=>{try{const e=new URL(t).hostname.toLowerCase();return e==="localhost"||e==="127.0.0.1"||e==="::1"||e==="[::1]"}catch{return!1}},qm=async()=>{const t=ua($a())||window.location.origin;if(!as()||!Va()||(await pn())?.desktopLanAccessActive!==!0)return t;const a=await Dl(),n=Jl();return!a||!n?t:`http://${a}:${n}`},pi=t=>{const e=t.trim();if(e)try{window.location.assign(e)}catch{window.location.href=e}},Jm=t=>{const e=t.sshCommand.trim(),a=t.nickname?.trim(),n=t.portForwards.map(r=>({...r,localHost:r.localHost?.trim()||"127.0.0.1",localPort:typeof r.localPort=="number"?Math.max(1,Math.min(65535,Math.round(r.localPort))):void 0,remoteHost:r.remoteHost?.trim(),remotePort:typeof r.remotePort=="number"?Math.max(1,Math.min(65535,Math.round(r.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}},Qm=()=>{const{t}=tt(),e=ie(v=>v.timeFormatPreference),{clientAuth:a}=Nl(),n=as(),r=As(v=>v.instances),i=As(v=>v.statusesById),l=As(v=>v.importCandidates),g=As(v=>v.isLoading),c=As(v=>v.isImportsLoading),y=As(v=>v.isSaving),p=As(v=>v.error),b=As(v=>v.load),d=As(v=>v.loadImports),C=As(v=>v.refreshStatuses),f=As(v=>v.upsertInstance),P=As(v=>v.createFromCommand),x=As(v=>v.removeInstance),N=As(v=>v.connect),m=As(v=>v.disconnect),A=As(v=>v.retry),R=ie(v=>v.settingsRemoteInstancesSelectedId),I=ie(v=>v.setSettingsRemoteInstancesSelectedId),j=o.useMemo(()=>R&&r.find(v=>v.id===R)||null,[r,R]),[h,w]=o.useState(null),[O,T]=o.useState(!1),[S,M]=o.useState(!1),[V,$]=o.useState(null),[k,W]=o.useState([]),[D,L]=o.useState(null),[J,ee]=o.useState(""),[U,re]=o.useState(!1),[_,H]=o.useState({}),[z,K]=o.useState(!1),[te,Y]=o.useState(!1),[ne,me]=o.useState(()=>Date.now()),[de,xe]=o.useState([]),[ae,le]=o.useState({}),[ge,Ae]=o.useState("local"),[Se,Ce]=o.useState(!1),[he,_e]=o.useState(!1),[Ue,ke]=o.useState(""),[Oe,Ve]=o.useState(""),[We,ve]=o.useState(""),[Z,se]=o.useState([]),[ye,be]=o.useState(""),[Re,Fe]=o.useState(null),[Ke,Ee]=o.useState(!1),[we,Ze]=o.useState(!1),[pe,Ne]=o.useState(null),[Le,Xe]=o.useState(""),[q,je]=o.useState(""),[Ie,Je]=o.useState(""),[ot,st]=o.useState([]),[mt,vt]=o.useState([]),[G,Ge]=o.useState([]),[nt,lt]=o.useState(!1),[ht,Lt]=o.useState(""),[et,ft]=o.useState(null),[bt,Be]=o.useState(null),[Et,Me]=o.useState(null),[wt,Q]=o.useState(null),[ue,De]=o.useState(!1),[Pe,it]=o.useState(!1),[rt,qe]=o.useState("configure"),[Pt,ys]=o.useState(!1),[Xt,Os]=o.useState("relay"),[Gt,is]=o.useState(!0),[Ht,bs]=o.useState(null),gs=o.useMemo(()=>mt.filter(v=>!!v.revokedAt).length,[mt]),[hs,ds]=o.useState(!1),[Es,oe]=o.useState("saved"),[ct,xt]=o.useState(""),[Qt,Yt]=o.useState(""),[Bt,rs]=o.useState(""),[ws,ss]=o.useState(!1);o.useEffect(()=>{b(),d()},[b,d]);const jt=o.useCallback(async()=>{Ce(!0),Fe(null);try{const v=await qr();xe(v.hosts||[]),Ae(v.defaultHostId||"local")}catch(v){Fe(v instanceof Error?v.message:String(v))}finally{Ce(!1)}},[]);o.useEffect(()=>{jt()},[jt]);const At=o.useCallback(async(v,X=ge)=>{_e(!0),Fe(null);try{await Jr({hosts:v,defaultHostId:X,initialHostChoiceCompleted:!0}),xe(v),Ae(X)}catch(Te){Fe(Te instanceof Error?Te.message:String(Te))}finally{_e(!1)}},[ge]),Ut=o.useCallback(async()=>{const v=Qr(Oe);if(!v){Fe(t("desktopHostSwitcher.error.invalidUrl"));return}const X=v.persistedUrl,Qe={id:typeof crypto<"u"&&typeof crypto.randomUUID=="function"?crypto.randomUUID():`host-${Date.now()}-${Math.random().toString(16).slice(2)}`,label:Ue.trim()||Ia(X),url:X,apiUrl:X,...We.trim()?{clientToken:We.trim()}:{},...Xi(Z)?{requestHeaders:Xi(Z)}:{}};await At([Qe,...de],ge),ke(""),Ve(""),ve(""),se([]),Ee(!1),v.redeemUrl&&pi(v.redeemUrl)},[ge,Z,de,Ue,We,Oe,At,t]),Ot=o.useCallback(async()=>{const v=xd(ye);if(!v){Fe(t("settings.remoteInstances.direct.error.invalidConnectLink"));return}const X=await vd().catch(()=>""),Te=JSON.stringify({pairingId:v.pairingId,secret:v.secret,clientLabel:v.label||"AiWorker Desktop",clientKind:"desktop",deviceName:"AiWorker Desktop",devicePlatform:Om(),...X?{dedupeKey:`desktop:${X}`}:{}}),Qe={method:"POST",headers:{"Content-Type":"application/json",Accept:"application/json"},body:Te},Dt=async Nt=>{if(!Nt.ok)return null;const Ms=await Nt.json().catch(()=>null);return(typeof Ms?.clientToken=="string"?Ms.clientToken.trim():"")||null},ks=[...v.candidates].sort((Nt,Ms)=>(Nt.type==="relay"?1:0)-(Ms.type==="relay"?1:0));let us=null;for(const Nt of ks){if(Nt.type==="relay"){const On=yd({relayUrl:Nt.relayUrl,serverId:Nt.serverId,hostEncPubJwk:Nt.hostEncPubJwk,...Nt.grant?{grant:Nt.grant}:{}});try{const ra=await On.fetch("/api/client-auth/pairing/redeem",Qe),si=await Dt(ra);if(si){us={kind:"relay",relay:{relayUrl:Nt.relayUrl,serverId:Nt.serverId,hostEncPubJwk:Nt.hostEncPubJwk},token:si};break}}catch{}finally{On.close()}continue}const Ms=ua(Nt.url);if(Ms)try{const On=await fetch(`${Ms}/api/client-auth/pairing/redeem`,Qe),ra=await Dt(On);if(ra){us={kind:"direct",url:Ms,token:ra};break}}catch{}}if(!us){Fe(t("desktopHostSwitcher.error.invalidUrl"));return}const $s=()=>typeof crypto<"u"&&typeof crypto.randomUUID=="function"?crypto.randomUUID():`host-${Date.now()}-${Math.random().toString(16).slice(2)}`,Ns=v.candidates.find(Nt=>Nt.type==="relay"),qs=us.kind==="relay"?us.relay:Ns?{relayUrl:Ns.relayUrl,serverId:Ns.serverId,hostEncPubJwk:Ns.hostEncPubJwk}:void 0,Sa=v.candidates.filter(Nt=>Nt.type!=="relay").map(Nt=>ua(Nt.url)).find(Nt=>!!Nt),Ln=us.kind==="direct"?us.url:Sa,{token:Ca}=us,kt=Ln||(qs?bd(qs.serverId):null);if(!kt){Fe(t("desktopHostSwitcher.error.invalidUrl"));return}const Wt={url:kt,apiUrl:Ln||void 0,clientToken:Ca,...qs?{relay:qs}:{}},tn=de.find(Nt=>qs?Nt.relay?.serverId===qs.serverId:!Nt.relay&&ua(Nt.apiUrl||Nt.url)===kt);if(tn){const Nt=de.map(Ms=>Ms.id===tn.id?{...Ms,label:v.label||Ms.label,...Wt}:Ms);await At(Nt,ge)}else await At([{id:$s(),label:v.label||Ia(kt),...Wt},...de],ge);be(""),Fe(null),Ze(!1)},[ye,ge,de,At,t]),ns=o.useCallback(async v=>{const X=de.filter(Qe=>Qe.id!==v);await At(X,ge===v?"local":ge),pe===v&&Ne(null)},[ge,pe,de,At]),Ds=o.useCallback(v=>{Ne(v.id),Xe(v.label),je(v.apiUrl||v.url),Je(v.clientToken||""),st(Gm(v.requestHeaders)),Fe(null)},[]),Ai=o.useCallback(async()=>{if(!pe)return;const v=Qr(q);if(!v){Fe(t("desktopHostSwitcher.error.invalidUrl"));return}const X=v.persistedUrl,Te=de.map(Qe=>Qe.id===pe?{...Qe,label:Le.trim()||Ia(X),url:X,apiUrl:X,clientToken:Ie.trim()||void 0,requestHeaders:Xi(ot)}:Qe);await At(Te,ge),Ne(null),v.redeemUrl&&pi(v.redeemUrl)},[ge,ot,Le,Ie,q,pe,de,At,t]),Ti=o.useCallback(async()=>{const v=Qt.trim();if(!v){E.error(t("settings.remoteInstances.page.toast.sshCommandRequired"));return}const X=`ssh-${Date.now()}-${Math.random().toString(16).slice(2)}`;try{await P(X,v,Bt.trim()||t("settings.remoteInstances.sidebar.newSshInstanceName")),I(X),ds(!1),Yt(""),rs(""),E.success(t("settings.remoteInstances.page.toast.instanceCreated"))}catch(Te){E.error(t("settings.remoteInstances.sidebar.toast.createFailed"),{description:Te instanceof Error?Te.message:String(Te)})}},[P,I,Qt,Bt,t]),Ha=o.useCallback(()=>{xt(""),oe(l.length>0?"saved":"manual"),ds(!0)},[l.length]),Ei=o.useCallback(async v=>{await At(de,v)},[de,At]);o.useEffect(()=>{if(!n||de.length===0)return;let v=!1;return Promise.all(de.map(async X=>{const Te=()=>Cd(X.relay,{clientToken:X.clientToken||null,requestHeaders:X.requestHeaders||null}).catch(()=>({status:"unreachable",latencyMs:0}));if(X.relay&&!X.apiUrl)return[X.id,await Te()];const Qe=ua(wd(X));if(!Qe)return[X.id,X.relay?await Te():{status:"unreachable",latencyMs:0}];const Dt=await jd(Qe,{clientToken:X.clientToken||null,requestHeaders:X.requestHeaders||null}).catch(()=>({status:"unreachable",latencyMs:0}));if(Dt.status==="unreachable"&&X.relay){const ks=await Te();if(ks.status==="ok")return[X.id,ks]}return[X.id,Dt]})).then(X=>{v||le(Object.fromEntries(X))}),()=>{v=!0}},[de,n]);const Fs=o.useCallback(async v=>{if(a){v?.silent||lt(!0),v?.silent||ft(null);try{const[X,Te]=await Promise.all([a.listClients(),a.listPendingPairings().catch(()=>null)]);vt(X),Te&&Ge(Te)}catch(X){v?.silent||ft(X instanceof Error?X.message:String(X))}finally{v?.silent||lt(!1)}}},[a]),ja=o.useRef(!1);o.useEffect(()=>{if(!(!Pe||rt!=="result"||!Et)){if(G.some(v=>v.id===Et)){ja.current=!0;return}ja.current&&(Me(null),it(!1),mt.some(v=>v.pairingId===Et)&&E.success(t("settings.remoteInstances.clientAuth.addDevice.connectedToast")))}},[Pe,rt,Et,G,mt,t]);const Di=o.useCallback(async v=>{if(a)try{await a.cancelPairing(v),Ge(X=>X.filter(Te=>Te.id!==v)),await Fs({silent:!0})}catch(X){ft(X instanceof Error?X.message:String(X))}},[a,Fs]);o.useEffect(()=>{if(!a)return;Fs();const v=window.setInterval(()=>{typeof document<"u"&&document.visibilityState!=="visible"||Fs({silent:!0})},5e3);return()=>window.clearInterval(v)},[a,Fs]);const Wa=o.useCallback(async()=>{if(a?.getPairingTransports)try{const Qe=await a.getPairingTransports();return{localUrl:Qe.local,lanUrl:Qe.lan,relayAvailable:Qe.relayAvailable}}catch{}const v=Jl(),X=v?`http://127.0.0.1:${v}`:Do(window.location.origin)?window.location.origin:null;let Te=null;try{const Qe=ua(await qm());Te=Qe&&!Do(Qe)?Qe:null}catch{}return{localUrl:X,lanUrl:Te,relayAvailable:!0}},[a]),Ga=o.useCallback(async()=>{ft(null),Be(null),Q(null),De(!1),Me(null),qe("configure"),is(!0),it(!0);const v=await Wa();bs(v),Os(v.relayAvailable?"relay":v.lanUrl?"lan":"local")},[Wa]),Mi=o.useCallback(async()=>{if(!(!a?.createPairingSession||!Ht)){ft(null),ys(!0);try{const v=ht.trim()||void 0;let X,Te,Qe=!0;Xt==="local"?(X=Ht.localUrl??void 0,Te=!1):Xt==="lan"?(X=Ht.lanUrl??void 0,Te=Gt):Gt&&Ht.lanUrl?(X=Ht.lanUrl,Te=!0):(Qe=!1,Te=!0);const{pairing:Dt,server:ks}=await a.createPairingSession({label:v,allowedClientKinds:["mobile","desktop"],serverUrl:X,includeRelay:Te,includeDirect:Qe}),us=kd({pairingId:Dt.id,secret:Dt.secret,label:ks.label,fingerprint:Dt.fingerprint??void 0,expiresAt:Dt.expiresAt,candidates:ks.candidates}),$s=Nd(us);Be($s),Q(await zl.toDataURL($s,{width:1024,margin:2,errorCorrectionLevel:"L"})),De(!1),ja.current=!1,Me(Dt.id),qe("result"),await Fs({silent:!0})}catch(v){ft(v instanceof Error?v.message:String(v))}finally{ys(!1)}}},[a,Ht,Xt,Gt,ht,Fs]),Ri=o.useCallback(()=>{bt&&Ka(bt).then(v=>{v.ok&&(De(!0),window.setTimeout(()=>De(!1),2e3))})},[bt]),Li=o.useCallback(async v=>{if(!a)return;const X=v.clientKind==="desktop-local";ft(null);try{if(await a.revokeClient(v.id),X&&as()){const Te=await qr();await Jr({hosts:Te.hosts,defaultHostId:Te.defaultHostId,initialHostChoiceCompleted:Te.initialHostChoiceCompleted,localClientToken:null}),vt(Qe=>Qe.map(Dt=>Dt.id===v.id?{...Dt,revokedAt:new Date().toISOString()}:Dt)),Sd({apiBaseUrl:$a(),clientToken:null,runtimeKey:"local"});return}await Fs()}catch(Te){ft(Te instanceof Error?Te.message:String(Te))}},[a,Fs]),qa=o.useCallback(async()=>{if(a){ft(null);try{await a.purgeRevokedClients(),await Fs()}catch(v){ft(v instanceof Error?v.message:String(v))}}},[a,Fs]);o.useEffect(()=>{w(j)},[j]),o.useEffect(()=>{ss(!1)},[R]),o.useEffect(()=>{if(!R)return;const v=window.setInterval(()=>{typeof document<"u"&&document.visibilityState!=="visible"||C()},2e3);return()=>{window.clearInterval(v)}},[C,R]),o.useEffect(()=>{let v=null,X=Date.now();const Te=()=>{const Dt=Date.now();Dt-X>=1e3&&(me(Dt),X=Dt),v=requestAnimationFrame(Te)};(typeof document>"u"||document.visibilityState==="visible")&&(v=requestAnimationFrame(Te));const Qe=()=>{document.visibilityState==="visible"&&v===null?v=requestAnimationFrame(Te):document.visibilityState!=="visible"&&v!==null&&(cancelAnimationFrame(v),v=null)};return document.addEventListener("visibilitychange",Qe),()=>{document.removeEventListener("visibilitychange",Qe),v!==null&&cancelAnimationFrame(v)}},[]);const js=R?i[R]:null,Gs=js?.phase,Zn=Gs==="ready",mn=Gs==="degraded",xn=Ar(Gs),Xs=Zn||(xn||mn),Oi=js?Math.max(0,ne-js.updatedAtMs):0,Dn=mn&&Oi>12e3,Xn=Io(Gs),Mn=Xn==="error"?Km(js?.detail):null,ka=zm(Mn),Fi=o.useMemo(()=>!h||!j?!1:JSON.stringify(h)!==JSON.stringify(j),[h,j]),os=o.useCallback(v=>{w(X=>X&&v(X))},[]),Ki=o.useCallback(async()=>{if(!h)return;const v=Jm(h);if(!v.sshCommand.trim()){E.error(t("settings.remoteInstances.page.toast.sshCommandRequired"));return}if(v.remoteOpenchamber.mode==="external"&&!v.remoteOpenchamber.preferredPort){E.error(t("settings.remoteInstances.page.validation.externalPortRequired")),ss(!0);return}if(v.remoteOpenchamber.mode==="managed"&&v.remoteOpenchamber.bindHost==="0.0.0.0"&&!v.auth.aiworkerPassword?.value?.trim()){E.error(t("settings.remoteInstances.page.validation.remoteLanNeedsPassword")),ss(!0),window.setTimeout(()=>gn.current?.focus(),0);return}if(!(v.localForward.bindHost==="0.0.0.0"&&!window.confirm(t("settings.remoteInstances.page.confirm.bindAllInterfaces")))){if(v.auth.sshPassword?.enabled&&v.auth.sshPassword.value?.trim()&&v.auth.sshPassword.store!=="settings"){const X=window.confirm(t("settings.remoteInstances.page.confirm.storeSshPasswordPlaintext"));v.auth.sshPassword.store=X?"settings":"never",X||(v.auth.sshPassword.value=void 0)}if(v.auth.aiworkerPassword?.enabled&&v.auth.aiworkerPassword.value?.trim()&&v.auth.aiworkerPassword.store!=="settings"){const X=window.confirm(t("settings.remoteInstances.page.confirm.storeUiPasswordPlaintext"));v.auth.aiworkerPassword.store=X?"settings":"never",X||(v.auth.aiworkerPassword.value=void 0)}try{await f(v),E.success(t("settings.remoteInstances.page.toast.instanceSaved"))}catch(X){E.error(t("settings.remoteInstances.page.toast.saveFailed"),{description:X instanceof Error?X.message:String(X)})}}},[h,t,f]),ea=o.useCallback(async(v,X)=>{const Te=`ssh-${Date.now()}-${Math.random().toString(16).slice(2)}`;try{return await P(Te,`ssh ${X}`,v),I(Te),E.success(t("settings.remoteInstances.page.toast.instanceCreated")),!0}catch(Qe){return E.error(t("settings.remoteInstances.sidebar.toast.createFailed"),{description:Qe instanceof Error?Qe.message:String(Qe)}),!1}},[P,I,t]),ta=o.useCallback(()=>{U||(L(null),ee(""))},[U]),zi=o.useCallback((v,X)=>{if(ds(!1),X){L(v),ee($m(v));return}ea(v,v)},[ea]),Ja=o.useMemo(()=>ki(l,ct,v=>[v.host,v.sshCommand]),[l,ct]),Ui=o.useCallback(v=>{const X=(v||"").trim();if(!X){E.error(t("settings.remoteInstances.page.toast.instanceUrlUnavailable"));return}pi(X)},[t]),Qa=o.useCallback(async()=>{const v=D,X=J.trim();if(v){if(!X){E.error(t("settings.remoteInstances.page.toast.destinationRequired"));return}re(!0);try{await ea(v,X)&&(L(null),ee(""))}finally{re(!1)}}},[ea,J,D,t]),sa=o.useCallback(async()=>{if(j)try{await N(j.id);return}catch(v){if(!Lm(v)||!window.confirm(t("settings.remoteInstances.sidebar.confirm.localPortInUseRetry")))throw v;const Te={...j,localForward:{...j.localForward,preferredLocalPort:wi()}};await f(Te),await N(Te.id),E.success(t("settings.remoteInstances.sidebar.toast.retriedWithRandomPort"))}},[N,j,t,f]),gn=o.useRef(null),Rn=o.useRef(null),Na=o.useCallback(async v=>{if(j){if(v==="localPort"){const X={...j,localForward:{...j.localForward,preferredLocalPort:wi()}};try{await f(X),await N(X.id),E.success(t("settings.remoteInstances.sidebar.toast.retriedWithRandomPort"))}catch(Te){E.error(t("settings.remoteInstances.page.toast.connectFailed"),{description:Te instanceof Error?Te.message:String(Te)})}return}ss(!0),window.setTimeout(()=>{if(v==="uiPassword"){gn.current?.focus();return}Rn.current?.scrollIntoView({block:"center"})},0)}},[N,j,t,f]),vn=o.useCallback(async v=>(await Mc(v,600)).map(Te=>Hm(Te)),[]),na=o.useCallback(async()=>{if(h){T(!0),M(!0),$(null);try{const v=await vn(h.id);W(v)}catch(v){W([]),$(v instanceof Error?v.message:String(v))}finally{M(!1)}}},[h,vn]);o.useEffect(()=>{if(!O||!h)return;let v=!1;const X=async()=>{try{const Qe=await vn(h.id);v||(W(Qe),$(null))}catch(Qe){v||$(Qe instanceof Error?Qe.message:String(Qe))}};X();const Te=window.setInterval(()=>{typeof document<"u"&&document.visibilityState!=="visible"||X()},1e3);return()=>{v=!0,window.clearInterval(Te)}},[h,O,vn]);const ce=o.useMemo(()=>k.join(`
27
- `),[k]),ls=o.useCallback(()=>{if(!ce.trim()){E.error(t("settings.remoteInstances.page.toast.noLogsToCopy"));return}Ka(ce).then(v=>{v.ok&&E.success(t("settings.remoteInstances.page.toast.logsCopied"))})},[ce,t]),aa=o.useCallback(async()=>{if(h)try{await Rc(h.id),W([]),E.success(t("settings.remoteInstances.page.toast.logsCleared"))}catch(v){E.error(t("settings.remoteInstances.page.toast.clearLogsFailed"),{description:v instanceof Error?v.message:String(v)})}},[h,t]),Ya=o.useCallback(async()=>{if(!js?.localUrl){E.error(t("settings.remoteInstances.page.toast.instanceUrlUnavailable"));return}const v=js.localUrl.trim();if(!v){E.error(t("settings.remoteInstances.page.toast.instanceUrlUnavailable"));return}pi(v)},[js?.localUrl,t]),Za=o.useCallback(()=>{if(!h)return;if(!Xs&&h.remoteOpenchamber.mode==="external"&&!h.remoteOpenchamber.preferredPort){E.error(t("settings.remoteInstances.page.validation.externalPortRequired")),ss(!0);return}if(!Xs&&h.remoteOpenchamber.mode==="managed"&&h.remoteOpenchamber.bindHost==="0.0.0.0"&&!h.auth.aiworkerPassword?.value?.trim()){E.error(t("settings.remoteInstances.page.validation.remoteLanNeedsPassword")),ss(!0),window.setTimeout(()=>gn.current?.focus(),0);return}K(!0),(Xs?m(h.id):sa()).catch(X=>{const Te=Xs?Zn?"settings.remoteInstances.page.toast.disconnectFailed":"settings.remoteInstances.page.toast.cancelConnectionFailed":"settings.remoteInstances.page.toast.connectFailed";E.error(t(Te),{description:X instanceof Error?X.message:String(X)})}).finally(()=>{K(!1)})},[Xs,sa,m,h,Zn,t]),Xa=o.useCallback(()=>{if(!h||xn)return;Y(!0),(mn?m(h.id).then(()=>sa()):A(h.id)).catch(X=>{E.error(t("settings.remoteInstances.page.toast.retryFailed"),{description:X instanceof Error?X.message:String(X)})}).finally(()=>{Y(!1)})},[sa,m,h,xn,mn,A,t]),ei=t(xn?"settings.remoteInstances.page.actions.connecting":mn?Dn?"settings.remoteInstances.page.actions.reconnectNow":"settings.remoteInstances.page.actions.reconnecting":"settings.remoteInstances.sidebar.actions.retry"),ti=!z&&!te&&(Gs==="error"||Gs==="idle"||!Gs||mn&&Dn)&&!xn,_i=t(Zn?"settings.remoteInstances.sidebar.actions.disconnect":Xs?"settings.remoteInstances.page.actions.cancel":"settings.remoteInstances.sidebar.actions.connect");if(!h)return s.jsxs(es,{title:t("settings.page.remoteInstances.title"),children:[a?s.jsxs(ze,{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(B,{type:"button",size:"xs",className:"!font-normal",onClick:()=>{Ga()},children:[s.jsx(F,{name:"add",className:"h-3.5 w-3.5"}),t("settings.remoteInstances.clientAuth.actions.addDevice")]})}),s.jsxs("div",{className:"space-y-2.5",children:[gs>0?s.jsx("div",{className:"flex justify-end",children:s.jsx(B,{type:"button",variant:"ghost",size:"xs",className:"!font-normal",onClick:()=>{qa()},children:t("settings.remoteInstances.clientAuth.actions.clearRevoked")})}):null,nt&&mt.length===0&&G.length===0?s.jsx("p",{className:"typography-meta text-muted-foreground",children:t("settings.remoteInstances.clientAuth.state.loading")}):mt.length===0&&G.length===0?s.jsx("p",{className:"typography-meta text-muted-foreground",children:t("settings.remoteInstances.clientAuth.state.empty")}):s.jsxs(s.Fragment,{children:[G.map(v=>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:v.label||t("settings.remoteInstances.clientAuth.field.labelPlaceholder")}),v.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(B,{type:"button",variant:"ghost",size:"xs",className:"!font-normal",onClick:()=>{Di(v.id)},children:t("settings.common.actions.cancel")})]},`pending-${v.id}`)),mt.map(v=>{const X=v.clientKind==="desktop-local",Te=v.lastUsedAt?Date.parse(v.lastUsedAt):Number.NaN,Qe=!v.revokedAt&&(X||Number.isFinite(Te)&&Date.now()-Te<9e4),Dt=v.revokedAt?t("settings.remoteInstances.clientAuth.state.revoked"):Qe?v.lastTransport==="relay"&&!X?t("settings.remoteInstances.clientAuth.state.connectedRelay"):t("settings.remoteInstances.clientAuth.state.connectedDirect"):Number.isFinite(Te)?t("settings.remoteInstances.clientAuth.lastUsed",{date:Lc(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:fe("h-2 w-2 shrink-0 rounded-full",v.revokedAt?"bg-muted-foreground/20":Qe?"bg-[var(--status-success)]":"bg-muted-foreground/30")}),s.jsx("p",{className:"typography-ui-label text-foreground truncate",children:v.label}),So(v.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:So(v.devicePlatform)}):null,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:t("settings.remoteInstances.clientAuth.state.thisDevice")}):null,s.jsx("span",{className:fe("typography-micro truncate",Qe&&!v.revokedAt?"text-[var(--status-success)]":"text-muted-foreground"),children:Dt})]})}),s.jsx(B,{type:"button",variant:"ghost",size:"xs",className:"!font-normal",onClick:()=>{Li(v)},disabled:!!v.revokedAt,children:t("settings.remoteInstances.clientAuth.actions.revoke")})]},v.id)})]})]}),et?s.jsx("p",{className:"typography-meta text-[var(--status-error)]",children:et}):null]}):null,n?s.jsxs(ze,{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(B,{type:"button",size:"xs",className:"!font-normal",onClick:()=>Ze(!0),disabled:he,children:t("settings.remoteInstances.direct.import.action")}),s.jsxs(B,{type:"button",variant:"outline",size:"xs",className:"!font-normal",onClick:()=>Ee(!0),disabled:he,children:[s.jsx(F,{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")}):de.length===0?s.jsx("p",{className:"typography-meta text-muted-foreground",children:t("settings.remoteInstances.direct.state.empty")}):de.map(v=>{const X=ae[v.id],Te=X?X.status==="ok"?"desktopHostSwitcher.status.connected":X.status==="auth"?"desktopHostSwitcher.status.authRequired":X.status==="update-recommended"?"desktopHostSwitcher.status.updateRecommended":X.status==="incompatible"?"desktopHostSwitcher.status.incompatible":X.status==="wrong-service"?"desktopHostSwitcher.status.wrongService":"desktopHostSwitcher.status.unreachable":"desktopHostSwitcher.status.checking",Qe=X?.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:fe("h-2 w-2 shrink-0 rounded-full",X?Qe?"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:Ia(v.label)}),ge===v.id?s.jsx("span",{className:"typography-micro text-muted-foreground shrink-0",children:t("desktopHostSwitcher.header.default")}):null,s.jsxs("span",{className:fe("typography-micro shrink-0",Qe?"text-[var(--status-success)]":"text-muted-foreground"),children:[t(Te),Qe&&typeof X?.latencyMs=="number"?t("desktopHostSwitcher.status.ping",{ms:Math.max(0,Math.round(X.latencyMs))}):""]})]}),s.jsx("p",{className:fe("typography-micro text-muted-foreground truncate",v.apiUrl&&"font-mono"),children:v.relay&&!v.apiUrl?t("mobile.connect.relay.badge"):Ia(v.apiUrl||v.url)})]}),s.jsxs("div",{className:"flex shrink-0 items-center gap-1",children:[s.jsx(B,{type:"button",variant:"ghost",size:"xs",className:"!font-normal",onClick:()=>{Ei(v.id)},disabled:he||ge===v.id,"aria-label":t("desktopHostSwitcher.actions.setAsDefaultAria"),children:ge===v.id?s.jsx(F,{name:"star-fill",className:"h-3.5 w-3.5"}):s.jsx(F,{name:"star",className:"h-3.5 w-3.5"})}),v.relay&&!v.apiUrl?null:s.jsxs(B,{type:"button",variant:"ghost",size:"xs",className:"!font-normal",onClick:()=>Ds(v),disabled:he,children:[s.jsx(F,{name:"pencil",className:"h-3.5 w-3.5"}),t("desktopHostSwitcher.actions.edit")]}),s.jsxs(B,{type:"button",variant:"ghost",size:"xs",className:"!font-normal",onClick:()=>{ns(v.id)},disabled:he,children:[s.jsx(F,{name:"delete-bin",className:"h-3.5 w-3.5"}),t("settings.common.actions.delete")]})]})]})},v.id)})}),Re?s.jsx("p",{className:"typography-meta text-[var(--status-error)]",children:Re}):null]}):null,n?s.jsx(Kt,{open:Ke,onOpenChange:Ee,children:s.jsxs(zt,{className:"sm:max-w-lg",children:[s.jsxs(_t,{children:[s.jsx($t,{children:t("settings.remoteInstances.direct.actions.add")}),s.jsx(Vt,{children:t("settings.remoteInstances.direct.addDialog.description")})]}),s.jsxs("form",{className:"space-y-3",onSubmit:v=>{v.preventDefault(),Ut()},children:[s.jsx(He,{className:"h-8",value:Ue,onChange:v=>ke(v.target.value),placeholder:t("settings.remoteInstances.direct.field.labelPlaceholder"),disabled:he}),s.jsx(He,{className:"h-8",value:Oe,onChange:v=>Ve(v.target.value),placeholder:t("settings.remoteInstances.direct.field.urlPlaceholder"),disabled:he,autoFocus:!0}),s.jsxs("div",{className:"space-y-1",children:[s.jsx(He,{className:"h-8",value:We,onChange:v=>ve(v.target.value),placeholder:t("settings.remoteInstances.direct.field.tokenPlaceholder"),type:"password",disabled:he}),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(Zs,{children:t("settings.remoteInstances.direct.headers.title")}),s.jsx(Jt,{children:t("settings.remoteInstances.direct.headers.description")})]}),Z.map(v=>s.jsxs("div",{className:"flex w-full gap-2",children:[s.jsx(He,{className:"h-8 font-mono text-xs",value:v.name,onChange:X=>se(Te=>Te.map(Qe=>Qe.id===v.id?{...Qe,name:X.target.value}:Qe)),placeholder:t("settings.remoteInstances.direct.headers.field.namePlaceholder"),disabled:he}),s.jsx(He,{className:"h-8 font-mono text-xs",value:v.value,onChange:X=>se(Te=>Te.map(Qe=>Qe.id===v.id?{...Qe,value:X.target.value}:Qe)),placeholder:t("settings.remoteInstances.direct.headers.field.valuePlaceholder"),type:"password",disabled:he}),s.jsx("button",{type:"button",onClick:()=>se(X=>X.filter(Te=>Te.id!==v.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:he,children:s.jsx(F,{name:"close",className:"h-4 w-4"})})]},v.id)),s.jsxs(B,{type:"button",variant:"ghost",size:"xs",className:"!font-normal",onClick:()=>se(v=>[...v,fr()]),disabled:he,children:[s.jsx(F,{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(B,{type:"button",variant:"outline",size:"xs",className:"!font-normal",onClick:()=>Ee(!1),disabled:he,children:t("settings.common.actions.cancel")}),s.jsx(B,{type:"submit",size:"xs",className:"!font-normal",disabled:he||!Oe.trim(),children:t("settings.remoteInstances.direct.actions.add")})]})]})]})}):null,n?s.jsx(Kt,{open:!!pe,onOpenChange:v=>{v||Ne(null)},children:s.jsxs(zt,{className:"sm:max-w-lg",children:[s.jsxs(_t,{children:[s.jsx($t,{children:t("desktopHostSwitcher.actions.edit")}),s.jsx(Vt,{children:t("settings.remoteInstances.direct.description")})]}),s.jsxs("form",{className:"space-y-3",onSubmit:v=>{v.preventDefault(),Ai()},children:[s.jsx(He,{className:"h-8",value:Le,onChange:v=>Xe(v.target.value),placeholder:t("settings.remoteInstances.direct.field.labelPlaceholder"),disabled:he}),s.jsx(He,{className:"h-8",value:q,onChange:v=>je(v.target.value),placeholder:t("settings.remoteInstances.direct.field.urlPlaceholder"),disabled:he,autoFocus:!0}),s.jsx(He,{className:"h-8",value:Ie,onChange:v=>Je(v.target.value),placeholder:t("settings.remoteInstances.direct.field.tokenPlaceholder"),type:"password",disabled:he}),s.jsxs("div",{className:"space-y-2",children:[s.jsxs("div",{className:"flex items-center gap-1.5",children:[s.jsx(Zs,{children:t("settings.remoteInstances.direct.headers.title")}),s.jsx(Jt,{children:t("settings.remoteInstances.direct.headers.description")})]}),ot.map(v=>s.jsxs("div",{className:"flex w-full gap-2",children:[s.jsx(He,{className:"h-8 font-mono text-xs",value:v.name,onChange:X=>st(Te=>Te.map(Qe=>Qe.id===v.id?{...Qe,name:X.target.value}:Qe)),placeholder:t("settings.remoteInstances.direct.headers.field.namePlaceholder"),disabled:he}),s.jsx(He,{className:"h-8 font-mono text-xs",value:v.value,onChange:X=>st(Te=>Te.map(Qe=>Qe.id===v.id?{...Qe,value:X.target.value}:Qe)),placeholder:t("settings.remoteInstances.direct.headers.field.valuePlaceholder"),type:"password",disabled:he}),s.jsx("button",{type:"button",onClick:()=>st(X=>X.filter(Te=>Te.id!==v.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:he,children:s.jsx(F,{name:"close",className:"h-4 w-4"})})]},v.id)),s.jsxs(B,{type:"button",variant:"ghost",size:"xs",className:"!font-normal",onClick:()=>st(v=>[...v,fr()]),disabled:he,children:[s.jsx(F,{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(B,{type:"button",variant:"outline",size:"xs",className:"!font-normal",onClick:()=>Ne(null),disabled:he,children:t("settings.common.actions.cancel")}),s.jsx(B,{type:"submit",size:"xs",className:"!font-normal",disabled:he,children:t("settings.common.actions.saveChanges")})]})]})]})}):null,n?s.jsx(Kt,{open:we,onOpenChange:Ze,children:s.jsxs(zt,{className:"sm:max-w-lg",children:[s.jsxs(_t,{children:[s.jsx($t,{children:t("settings.remoteInstances.direct.import.action")}),s.jsx(Vt,{children:t("settings.remoteInstances.direct.import.description")})]}),s.jsxs("form",{className:"space-y-3",onSubmit:v=>{v.preventDefault(),Ot()},children:[s.jsx(He,{className:"h-8",value:ye,onChange:v=>be(v.target.value),placeholder:t("settings.remoteInstances.direct.import.placeholder"),disabled:he,autoFocus:!0}),s.jsxs("div",{className:"flex justify-end gap-2",children:[s.jsx(B,{type:"button",variant:"outline",size:"xs",className:"!font-normal",onClick:()=>Ze(!1),disabled:he,children:t("settings.common.actions.cancel")}),s.jsx(B,{type:"submit",size:"xs",className:"!font-normal",disabled:he||!ye.trim(),children:t("settings.remoteInstances.direct.import.action")})]})]})]})}):null,s.jsx(Kt,{open:Pe,onOpenChange:it,children:s.jsxs(zt,{className:rt==="result"?"sm:max-w-lg":"sm:max-w-md",children:[s.jsxs(_t,{children:[s.jsx($t,{children:t(rt==="result"?"settings.remoteInstances.clientAuth.qrDialogTitle":"settings.remoteInstances.clientAuth.actions.addDevice")}),s.jsx(Vt,{children:t(rt==="result"?"settings.remoteInstances.clientAuth.qrScanHint":"settings.remoteInstances.clientAuth.addDevice.subtitle")})]}),rt==="configure"?s.jsxs("form",{className:"space-y-4",onSubmit:v=>{v.preventDefault(),Mi()},children:[s.jsx(He,{className:"h-8",value:ht,onChange:v=>Lt(v.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:!!Ht?.relayAvailable},{key:"lan",label:t("settings.remoteInstances.clientAuth.addDevice.transport.lan"),hint:t("settings.remoteInstances.clientAuth.addDevice.transport.lanHint"),available:!!Ht?.lanUrl},{key:"local",label:t("settings.remoteInstances.clientAuth.addDevice.transport.local"),hint:t("settings.remoteInstances.clientAuth.addDevice.transport.localHint"),available:!!Ht?.localUrl}].map(v=>{const X=Xt===v.key;return s.jsxs("div",{className:fe("flex items-start gap-2 py-0.5",v.available?"cursor-pointer":"opacity-45"),onClick:()=>{v.available&&Os(v.key)},role:"presentation",children:[s.jsx(jr,{checked:X,disabled:!v.available,onChange:()=>Os(v.key),ariaLabel:v.label,className:"mt-0.5"}),s.jsxs("div",{className:"min-w-0",children:[s.jsx("p",{className:fe("typography-ui-label font-normal",X?"text-foreground":"text-foreground/70"),children:v.label}),s.jsx("p",{className:"typography-meta text-muted-foreground",children:v.hint})]})]},v.key)})}),Xt==="lan"?s.jsxs("label",{className:"flex w-fit cursor-pointer items-center gap-2 pt-1",children:[s.jsx(cr,{checked:Gt,onChange:is,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"&&Ht?.lanUrl?s.jsxs("label",{className:"flex w-fit cursor-pointer items-center gap-2 pt-1",children:[s.jsx(cr,{checked:Gt,onChange:is,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]}),et?s.jsx("p",{className:"typography-meta text-[var(--status-error)]",children:et}):null,s.jsxs("div",{className:"flex justify-end gap-2",children:[s.jsx(B,{type:"button",variant:"outline",size:"xs",className:"!font-normal",onClick:()=>it(!1),disabled:Pt,children:t("settings.common.actions.cancel")}),s.jsx(B,{type:"submit",size:"xs",className:"!font-normal",disabled:Pt||!Ht,children:t("settings.remoteInstances.clientAuth.addDevice.create")})]})]}):s.jsxs("div",{className:"space-y-3",children:[wt?s.jsx("div",{className:"flex justify-center",children:s.jsx("img",{src:wt,alt:t("settings.remoteInstances.clientAuth.qrAlt"),className:"w-full max-w-[420px] rounded-md bg-white p-4"})}):null,bt?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:bt}),s.jsxs(B,{type:"button",variant:"outline",size:"xs",className:"!font-normal shrink-0",onClick:Ri,children:[s.jsx(F,{name:ue?"check":"file-copy",className:fe("h-3.5 w-3.5",ue&&"text-[var(--status-success)]")}),t(ue?"settings.remoteInstances.clientAuth.actions.copied":"settings.common.actions.copyAll")]})]}):null,s.jsx("div",{className:"flex justify-end",children:s.jsx(B,{type:"button",size:"xs",className:"!font-normal",onClick:()=>it(!1),children:t("settings.remoteInstances.clientAuth.addDevice.done")})})]})]})}),n?s.jsx(ze,{title:t("settings.remoteInstances.sidebar.title"),description:t("settings.remoteInstances.sidebar.total",{count:r.length}),headerAction:s.jsxs(B,{type:"button",size:"xs",className:"!font-normal",onClick:Ha,children:[s.jsx(F,{name:"add",className:"h-3.5 w-3.5"}),t("settings.remoteInstances.sidebar.actions.addSshInstance")]}),contentClassName:"space-y-2.5",children:g?s.jsx("p",{className:"typography-meta text-muted-foreground",children:t("settings.remoteInstances.page.state.loadingInstances")}):r.length===0?s.jsx("p",{className:"typography-meta text-muted-foreground",children:l.length===1?t("settings.remoteInstances.page.empty.noInstancesWithOneImport"):l.length>1?t("settings.remoteInstances.page.empty.noInstancesWithImports",{count:l.length}):t("settings.remoteInstances.page.empty.noInstances")}):r.map(v=>{const X=i[v.id],Te=v.nickname?.trim()||v.sshParsed?.destination||v.id,Qe=X?.phase,Dt=Qe==="ready",ks=Io(Qe),us=ks==="error"?X?.detail:void 0;return s.jsxs("div",{className:"space-y-1.5 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:`h-2 w-2 rounded-full ${To(Qe)}`}),s.jsx("p",{className:"typography-ui-label text-foreground truncate",children:Te})]}),s.jsxs("p",{className:"typography-micro text-muted-foreground truncate",children:[t(Po(ks)),ks==="connecting"?` · ${t(Co(Qe))}`:"",Dt&&X?.localUrl?` · ${X.localUrl}`:""]})]}),s.jsxs("div",{className:"flex shrink-0 items-center gap-1",children:[Dt?s.jsxs(B,{type:"button",variant:"ghost",size:"xs",className:"!font-normal",onClick:()=>Ui(X?.localUrl),children:[s.jsx(F,{name:"external-link",className:"h-3.5 w-3.5"}),t("settings.remoteInstances.page.actions.open")]}):null,s.jsxs(B,{type:"button",variant:"ghost",size:"xs",className:"!font-normal",onClick:()=>{(Dt?m(v.id):N(v.id)).catch(Ns=>E.error(t(Dt?"settings.remoteInstances.sidebar.toast.disconnectFailed":"settings.remoteInstances.sidebar.toast.connectFailed"),{description:Ns instanceof Error?Ns.message:String(Ns)}))},children:[Dt?s.jsx(F,{name:"stop",className:"h-3.5 w-3.5"}):s.jsx(F,{name:"plug-2",className:"h-3.5 w-3.5"}),t(Dt?"settings.remoteInstances.sidebar.actions.disconnect":"settings.remoteInstances.sidebar.actions.connect")]}),s.jsxs(B,{type:"button",variant:"ghost",size:"xs",className:"!font-normal",onClick:()=>I(v.id),children:[s.jsx(F,{name:"pencil",className:"h-3.5 w-3.5"}),t("desktopHostSwitcher.actions.edit")]}),s.jsxs(B,{type:"button",variant:"ghost",size:"xs",className:"!font-normal",onClick:()=>{window.confirm(t("settings.remoteInstances.page.confirm.removeInstance"))&&x(v.id).catch(Ns=>E.error(t("settings.remoteInstances.page.toast.removeInstanceFailed"),{description:Ns instanceof Error?Ns.message:String(Ns)}))},children:[s.jsx(F,{name:"delete-bin",className:"h-3.5 w-3.5"}),t("settings.common.actions.delete")]})]})]}),us?s.jsx("p",{className:"typography-micro text-[var(--status-error)] break-words",children:us}):null]},v.id)})}):null,n?s.jsx(Kt,{open:hs,onOpenChange:ds,children:s.jsxs(zt,{className:"sm:max-w-lg",children:[s.jsxs(_t,{children:[s.jsx($t,{children:t("settings.remoteInstances.sidebar.actions.addSshInstance")}),s.jsx(Vt,{children:t("settings.remoteInstances.page.addDialog.description")})]}),s.jsx(Ys,{value:Es,onChange:oe,"aria-label":t("settings.remoteInstances.page.addDialog.sourceLabel"),options:[{value:"saved",label:t("settings.remoteInstances.page.addDialog.tab.saved")},{value:"manual",label:t("settings.remoteInstances.page.addDialog.tab.manual")}]}),Es==="saved"?s.jsxs("div",{className:"space-y-2",children:[s.jsx(He,{className:"h-8",value:ct,onChange:v=>xt(v.target.value),placeholder:t("settings.remoteInstances.page.addDialog.searchPlaceholder"),autoFocus:!0}),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.addDialog.emptySaved")}):Ja.length===0?s.jsx("p",{className:"typography-meta text-muted-foreground",children:t("settings.remoteInstances.page.addDialog.searchEmpty")}):s.jsx("div",{className:"max-h-[45vh] overflow-auto",children:Ja.map(v=>s.jsxs("div",{className:"flex items-center justify-between gap-3 border-b border-[var(--surface-subtle)] py-2.5 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:[v.host,v.pattern?` ${t("settings.remoteInstances.page.import.patternSuffix")}`:""]}),s.jsx("div",{className:"typography-meta text-muted-foreground truncate",children:v.sshCommand})]}),s.jsx(B,{type:"button",variant:"outline",size:"xs",className:"!font-normal",onClick:()=>{zi(v.host,v.pattern)},children:t("settings.remoteInstances.page.addDialog.use")})]},`${v.source}:${v.host}`))})]}):s.jsxs("form",{className:"space-y-3",onSubmit:v=>{v.preventDefault(),Ti()},children:[s.jsx(He,{className:"h-8",value:Bt,onChange:v=>rs(v.target.value),placeholder:t("settings.remoteInstances.page.field.nicknamePlaceholder"),disabled:y}),s.jsx(He,{className:"h-8",value:Qt,onChange:v=>Yt(v.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(B,{type:"button",variant:"outline",size:"xs",className:"!font-normal",onClick:()=>ds(!1),disabled:y,children:t("settings.common.actions.cancel")}),s.jsx(B,{type:"submit",size:"xs",className:"!font-normal",disabled:y||!Qt.trim(),children:t("settings.common.actions.create")})]})]})]})}):null,s.jsx(Kt,{open:!!D,onOpenChange:v=>{v||ta()},children:s.jsxs(zt,{className:"sm:max-w-md",children:[s.jsxs(_t,{children:[s.jsx($t,{children:t("settings.remoteInstances.page.patternDialog.title")}),s.jsx(Vt,{children:D?t("settings.remoteInstances.page.patternDialog.descriptionWithHost",{host:D}):t("settings.remoteInstances.page.patternDialog.description")})]}),s.jsxs("form",{className:"space-y-3",onSubmit:v=>{v.preventDefault(),Qa()},children:[s.jsx(He,{value:J,onChange:v=>ee(v.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(B,{type:"button",variant:"outline",size:"xs",className:"!font-normal",onClick:ta,disabled:U,children:t("settings.common.actions.cancel")}),s.jsx(B,{type:"submit",size:"xs",className:"!font-normal",disabled:U,children:t("settings.remoteInstances.page.actions.create")})]})]})]})})]});const en=h.remoteOpenchamber.mode==="managed",yn=en&&h.remoteOpenchamber.bindHost==="0.0.0.0",ia=yn&&!h.auth.aiworkerPassword?.value?.trim(),$i=h.nickname?.trim()||h.sshParsed?.destination||h.id;return s.jsx(Kt,{open:!!h,onOpenChange:v=>{v||I(null)},children:s.jsxs(zt,{className:"sm:max-w-4xl max-h-[90vh] overflow-auto",children:[s.jsxs("div",{className:"mb-6 px-1",children:[s.jsx("h1",{className:`${lr} truncate`,children:$i}),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 ${To(Gs)}`}),s.jsx("span",{className:"text-foreground",children:t(Po(Xn))}),Xn==="connecting"?s.jsx("span",{children:t(Co(Gs))}):null,js?.localUrl?s.jsx("span",{className:"font-mono text-foreground/80",children:js.localUrl}):null,Dn?s.jsx("span",{children:t("settings.remoteInstances.page.status.reconnectStale")}):null]})]}),s.jsxs(ze,{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(B,{type:"button",variant:Xs?"outline":"default",size:"xs",className:"!font-normal",onClick:Za,disabled:z||te,children:[Xs?s.jsx(F,{name:"stop",className:"h-3.5 w-3.5"}):s.jsx(F,{name:"plug-2",className:"h-3.5 w-3.5"}),_i]}),s.jsxs(B,{type:"button",variant:"outline",size:"xs",className:"!font-normal",onClick:Xa,disabled:!ti,children:[s.jsx(F,{name:"refresh",className:`h-3.5 w-3.5 ${xn||mn&&!Dn?"animate-spin":""}`}),ei]}),s.jsxs(B,{type:"button",variant:"outline",size:"xs",className:"!font-normal",onClick:()=>{na()},children:[s.jsx(F,{name:"terminal-window",className:"h-3.5 w-3.5"}),t("settings.remoteInstances.page.actions.logs")]}),s.jsxs(B,{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"))&&x(h.id).then(()=>{I(null),E.success(t("settings.remoteInstances.page.toast.instanceRemoved"))}).catch(X=>{E.error(t("settings.remoteInstances.page.toast.removeInstanceFailed"),{description:X instanceof Error?X.message:String(X)})})},children:[s.jsx(F,{name:"delete-bin",className:"h-3.5 w-3.5"}),t("settings.remoteInstances.sidebar.actions.remove")]})]}),Xn==="error"&&js?.detail?s.jsxs("div",{className:"space-y-2 rounded-md border border-[var(--status-error)]/30 bg-[var(--status-error-background)] p-3",children:[s.jsx("p",{className:"typography-meta text-[var(--status-error)] break-words",children:js.detail}),ka?s.jsx("p",{className:"typography-micro text-muted-foreground",children:t(ka)}):null,Mn&&!ka?s.jsx(B,{type:"button",variant:"outline",size:"xs",className:"!font-normal",onClick:()=>{Na(Mn)},children:t(Mn==="uiPassword"?"settings.remoteInstances.page.error.action.setUiPassword":Mn==="localPort"?"settings.remoteInstances.page.error.action.pickRandomPort":"settings.remoteInstances.page.error.action.setRemotePort")}):null]}):null,js?.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:js.localUrl})]}):null]}),s.jsxs(ze,{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:h.sshCommand,onChange:v=>os(X=>({...X,sshCommand:v.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:h.nickname||"",onChange:v=>os(X=>({...X,nickname:v.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("div",{className:"w-56 shrink-0",children:s.jsx(Vs,{label:t("settings.remoteInstances.page.field.mode"),hint:t("settings.remoteInstances.page.field.modeHint")})}),s.jsxs(St,{value:h.remoteOpenchamber.mode,onValueChange:v=>os(X=>({...X,remoteOpenchamber:{...X.remoteOpenchamber,mode:v==="external"?"external":"managed"}})),children:[s.jsx(Ct,{size:Ft,className:"w-fit min-w-[140px]",children:s.jsx(Mt,{placeholder:t("settings.remoteInstances.page.field.modePlaceholder")})}),s.jsxs(It,{children:[s.jsx(at,{value:"managed",children:t("settings.remoteInstances.page.field.modeManaged")}),s.jsx(at,{value:"external",children:t("settings.remoteInstances.page.field.modeExternal")})]})]})]})]}),s.jsxs(An,{open:ws,onOpenChange:ss,children:[s.jsxs(Tn,{className:"mt-6 w-auto justify-start gap-1.5",children:[s.jsx("span",{className:Sl,children:t("settings.remoteInstances.page.section.advanced")}),s.jsx(F,{name:ws?"arrow-up-s":"arrow-down-s",className:"h-4 w-4 text-muted-foreground"})]}),s.jsxs(En,{children:[s.jsx("p",{className:"px-2 pb-2 typography-micro text-muted-foreground",children:t("settings.remoteInstances.page.section.advancedHint")}),s.jsxs("div",{className:"flex flex-col gap-1.5 px-2 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(xs,{containerClassName:"w-fit",min:5,max:240,step:1,className:fe(Ps,"tabular-nums"),value:h.connectionTimeoutSec,onValueChange:v=>{os(X=>({...X,connectionTimeoutSec:Number.isFinite(v)?v:X.connectionTimeoutSec}))}})]}),s.jsxs(ze,{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",ref:Rn,children:s.jsx(Vs,{label:t("settings.remoteInstances.page.field.preferredRemotePort"),hint:t("settings.remoteInstances.page.field.preferredRemotePortHint")})}),s.jsx(xs,{containerClassName:"w-fit",min:1,max:65535,step:1,className:fe(Ps,"tabular-nums"),value:h.remoteOpenchamber.preferredPort,onValueChange:v=>{os(X=>({...X,remoteOpenchamber:{...X.remoteOpenchamber,preferredPort:Number.isFinite(v)&&v>0?v:void 0}}))},onClear:()=>{os(v=>({...v,remoteOpenchamber:{...v.remoteOpenchamber,preferredPort:void 0}}))},emptyLabel:t("settings.remoteInstances.page.field.auto")})]}),en?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(Vs,{label:t("settings.remoteInstances.page.field.installMethod"),hint:t("settings.remoteInstances.page.field.installMethodHint")})}),s.jsxs(St,{value:h.remoteOpenchamber.installMethod,onValueChange:v=>os(X=>({...X,remoteOpenchamber:{...X.remoteOpenchamber,installMethod:v==="npm"||v==="bun"?v:"auto"}})),children:[s.jsx(Ct,{size:Ft,className:"w-fit min-w-[140px]",children:s.jsx(Mt,{placeholder:t("settings.remoteInstances.page.field.selectInstallMethodPlaceholder")})}),s.jsxs(It,{children:[s.jsx(at,{value:"auto",children:t("settings.remoteInstances.page.field.installMethodAuto")}),s.jsx(at,{value:"bun",children:"bun"}),s.jsx(at,{value:"npm",children:"npm"})]})]})]}):null,en?s.jsxs("div",{className:"py-1.5",children:[s.jsxs("div",{className:"flex flex-col gap-1.5 md:flex-row md:items-center md:gap-8",children:[s.jsx("div",{className:"w-56 shrink-0",children:s.jsx(Vs,{label:t("settings.remoteInstances.page.field.remoteLanAccess"),hint:t("settings.remoteInstances.page.field.remoteLanAccessHint")})}),s.jsx(xi,{checked:yn,onCheckedChange:v=>os(X=>({...X,remoteOpenchamber:{...X.remoteOpenchamber,bindHost:v?"0.0.0.0":"127.0.0.1"}})),"aria-label":t("settings.remoteInstances.page.field.remoteLanAccess")})]}),yn?s.jsx("p",{className:"mt-2 typography-micro text-[var(--status-warning)] md:pl-[16rem]",children:t("settings.remoteInstances.page.field.remoteLanAccessWarning")}):null]}):null,en?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(Vs,{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(xi,{checked:h.remoteOpenchamber.keepRunning,onCheckedChange:v=>os(X=>({...X,remoteOpenchamber:{...X.remoteOpenchamber,keepRunning:v}}))})})]}):null]}),s.jsxs(ze,{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(Vs,{label:t("settings.remoteInstances.page.field.bindHost"),hint:t("settings.remoteInstances.page.field.bindHostHint")})}),s.jsxs(St,{value:h.localForward.bindHost,onValueChange:v=>{v==="0.0.0.0"&&!window.confirm(t("settings.remoteInstances.page.confirm.bindAllInterfaces"))||os(X=>({...X,localForward:{...X.localForward,bindHost:v==="localhost"||v==="0.0.0.0"?v:"127.0.0.1"}}))},children:[s.jsx(Ct,{size:Ft,className:"w-fit min-w-[240px]",children:s.jsx(Mt,{placeholder:t("settings.remoteInstances.page.field.selectBindHostPlaceholder")})}),s.jsxs(It,{children:[s.jsx(at,{value:"127.0.0.1",children:t("settings.remoteInstances.page.field.bindHostOption.loopback")}),s.jsx(at,{value:"localhost",children:t("settings.remoteInstances.page.field.bindHostOption.localhost")}),s.jsx(at,{value:"0.0.0.0",children:t("settings.remoteInstances.page.field.bindHostOption.lan")})]})]})]}),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(Vs,{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(xs,{containerClassName:"w-fit",min:1,max:65535,step:1,className:fe(Ps,"tabular-nums"),value:h.localForward.preferredLocalPort,onValueChange:v=>{os(X=>({...X,localForward:{...X.localForward,preferredLocalPort:Number.isFinite(v)&&v>0?v:void 0}}))},onClear:()=>{os(v=>({...v,localForward:{...v.localForward,preferredLocalPort:void 0}}))},emptyLabel:t("settings.remoteInstances.page.field.auto")}),s.jsx(B,{type:"button",variant:"outline",size:"xs",className:"!font-normal h-7 w-7 px-0",title:t("settings.remoteInstances.page.actions.pickRandomPort"),onClick:()=>os(v=>({...v,localForward:{...v.localForward,preferredLocalPort:wi()}})),children:s.jsx(F,{name:"shuffle",className:"h-3.5 w-3.5"})})]})]}),s.jsxs("div",{className:"space-y-1 pt-1",children:[s.jsx("p",{className:"typography-micro text-muted-foreground",children:t("settings.remoteInstances.page.tunnelPreview.caption")}),s.jsx("p",{className:"typography-micro font-mono text-foreground/80 break-all",children:`${h.localForward.bindHost}:${h.localForward.preferredLocalPort||"auto"} → ${h.sshParsed?.destination||h.nickname||"remote"}:${h.remoteOpenchamber.preferredPort||"auto"}`})]})]}),s.jsxs(ze,{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("div",{className:"w-56 shrink-0",children:s.jsx(Vs,{label:t("settings.remoteInstances.page.field.sshPasswordOptional"),hint:t("settings.remoteInstances.page.field.sshPasswordHint")})}),s.jsx(He,{className:"h-7 md:max-w-sm",type:"password",value:h.auth.sshPassword?.value||"",onChange:v=>os(X=>({...X,auth:{...X.auth,sshPassword:{enabled:v.target.value.trim().length>0,value:v.target.value,store:X.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("div",{className:"w-56 shrink-0",children:s.jsx(Vs,{label:t(yn?"settings.remoteInstances.page.field.uiPasswordRequired":"settings.remoteInstances.page.field.uiPasswordOptional"),hint:t(en?"settings.remoteInstances.page.field.uiPasswordHintManaged":"settings.remoteInstances.page.field.uiPasswordHintExternal")})}),s.jsx(He,{className:fe("h-7 md:max-w-sm",ia&&"border-[var(--status-error)]"),type:"password",ref:gn,"aria-invalid":ia,value:h.auth.aiworkerPassword?.value||"",onChange:v=>os(X=>({...X,auth:{...X.auth,aiworkerPassword:{enabled:v.target.value.trim().length>0,value:v.target.value,store:X.auth.aiworkerPassword?.store||"never"}}})),placeholder:t("settings.remoteInstances.page.field.uiPasswordPlaceholder")})]}),ia?s.jsx("p",{className:"typography-micro text-[var(--status-error)] md:pl-[16rem]",children:t("settings.remoteInstances.page.field.uiPasswordMissingForLan")}):null]}),s.jsxs(ze,{title:t("settings.remoteInstances.page.section.portForwards"),info:t("settings.remoteInstances.page.section.portForwardsDescription"),contentClassName:"space-y-2",children:[h.portForwards.length===0?s.jsx("p",{className:"typography-micro text-muted-foreground/80",children:t("settings.remoteInstances.page.empty.noExtraForwards")}):null,h.portForwards.map((v,X)=>{const Te=kt=>{os(Wt=>({...Wt,portForwards:Wt.portForwards.map((tn,Nt)=>Nt===X?kt(tn):tn)}))},Qe=v.type==="remote"?"Local target":"Local listen",Dt=v.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.",ks=v.type==="remote"?"Remote listen":"Remote target",us=v.type==="remote"?"Remote host and port where SSH creates the -R listener.":"Remote host and port that receives traffic from local -L listener.",$s=Eo(v.localHost||"localhost",v.localPort),Ns=Eo(v.remoteHost||"localhost",v.remotePort),qs=v.type==="local"&&typeof v.localPort=="number"&&v.localPort>0,Sa=qs?`http://${Bm(v.localHost)}:${v.localPort}`:"",Ln=!!_[v.id],Ca=v.type==="local"?t("settings.remoteInstances.page.forwardType.local"):v.type==="remote"?t("settings.remoteInstances.page.forwardType.remote"):t("settings.remoteInstances.page.forwardType.dynamic");return s.jsxs(An,{open:Ln,onOpenChange:kt=>{H(Wt=>({...Wt,[v.id]:kt}))},className:`${X>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(Tn,{className:"flex items-center gap-2 group",children:[s.jsx(F,{name:"arrow-down-s",className:`h-4 w-4 text-muted-foreground transition-transform ${Ln?"rotate-180":""}`}),s.jsx("span",{className:"typography-ui-label text-foreground truncate",children:Um(v)}),s.jsx("span",{className:"typography-micro text-muted-foreground/70 shrink-0",children:Ca})]})}),s.jsxs("div",{className:"flex items-center gap-2",children:[s.jsx(xi,{checked:v.enabled,onCheckedChange:kt=>Te(Wt=>({...Wt,enabled:kt})),"aria-label":t("settings.remoteInstances.page.actions.enableForwardAria")}),s.jsx(B,{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:()=>os(kt=>({...kt,portForwards:kt.portForwards.filter(Wt=>Wt.id!==v.id)})),children:s.jsx(F,{name:"delete-bin",className:"h-3.5 w-3.5"})})]})]}),s.jsx(En,{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(Vs,{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(Vm(v.type))})]})})}),s.jsxs(St,{value:v.type,onValueChange:kt=>Te(Wt=>({...Wt,type:kt==="dynamic"||kt==="remote"?kt:"local"})),children:[s.jsx(Ct,{size:Ft,className:"w-fit min-w-[140px]",children:s.jsx(Mt,{placeholder:t("settings.remoteInstances.page.field.typePlaceholder")})}),s.jsxs(It,{children:[s.jsx(at,{value:"local",children:t("settings.remoteInstances.page.forwardType.local")}),s.jsx(at,{value:"remote",children:t("settings.remoteInstances.page.forwardType.remote")}),s.jsx(at,{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(Vs,{label:Qe,hint:Dt})}),s.jsxs("div",{className:"flex items-center gap-1.5",children:[s.jsx(He,{className:"h-7 w-32",value:v.localHost||"127.0.0.1",onChange:kt=>Te(Wt=>({...Wt,localHost:kt.target.value})),placeholder:t("settings.remoteInstances.page.field.localHostPlaceholder")}),s.jsx("span",{className:"text-muted-foreground",children:":"}),s.jsx(xs,{containerClassName:"w-fit",min:1,max:65535,step:1,className:fe(Ps,"tabular-nums"),value:v.localPort,onValueChange:kt=>{Te(Wt=>({...Wt,localPort:Number.isFinite(kt)&&kt>0?kt:void 0}))},onClear:()=>{Te(kt=>({...kt,localPort:void 0}))},emptyLabel:t("settings.remoteInstances.page.field.auto")})]})]}),v.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(Vs,{label:ks,hint:us})}),s.jsxs("div",{className:"flex items-center gap-1.5",children:[s.jsx(He,{className:"h-7 w-32",value:v.remoteHost||"",onChange:kt=>Te(Wt=>({...Wt,remoteHost:kt.target.value})),placeholder:t("settings.remoteInstances.page.field.remoteHostPlaceholder")}),s.jsx("span",{className:"text-muted-foreground",children:":"}),s.jsx(xs,{containerClassName:"w-fit",min:1,max:65535,step:1,className:fe(Ps,"tabular-nums"),value:v.remotePort,onValueChange:kt=>{Te(Wt=>({...Wt,remotePort:Number.isFinite(kt)&&kt>0?kt:void 0}))},onClear:()=>{Te(kt=>({...kt,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:v.type==="dynamic"?s.jsxs(s.Fragment,{children:[s.jsx(F,{name:"computer",className:"h-3.5 w-3.5"}),s.jsx("span",{className:"font-mono text-foreground",children:$s}),s.jsx("span",{children:t("settings.remoteInstances.page.preview.localSocks5")})]}):v.type==="remote"?s.jsxs(s.Fragment,{children:[s.jsx(F,{name:"server",className:"h-3.5 w-3.5"}),s.jsx("span",{className:"font-mono text-foreground",children:Ns}),s.jsx("span",{children:t("settings.remoteInstances.page.preview.remote")}),s.jsx(F,{name:"arrow-right",className:"h-3.5 w-3.5"}),s.jsx(F,{name:"computer",className:"h-3.5 w-3.5"}),s.jsx("span",{className:"font-mono text-foreground",children:$s}),s.jsx("span",{children:t("settings.remoteInstances.page.preview.local")})]}):s.jsxs(s.Fragment,{children:[s.jsx(F,{name:"computer",className:"h-3.5 w-3.5"}),s.jsx("span",{className:"font-mono text-foreground",children:$s}),s.jsx("span",{children:t("settings.remoteInstances.page.preview.local")}),s.jsx(F,{name:"arrow-right",className:"h-3.5 w-3.5"}),s.jsx(F,{name:"server",className:"h-3.5 w-3.5"}),s.jsx("span",{className:"font-mono text-foreground",children:Ns}),s.jsx("span",{children:t("settings.remoteInstances.page.preview.remote")})]})}),qs?s.jsxs(B,{type:"button",variant:"outline",size:"xs",className:"!font-normal",onClick:()=>{Pn(Sa).then(kt=>{kt||E.error(t("settings.remoteInstances.page.toast.openLocalEndpointFailed"))})},children:[s.jsx(F,{name:"external-link",className:"h-3.5 w-3.5"}),t("settings.remoteInstances.page.actions.openLocal")]}):null]})]})})]},v.id)}),s.jsxs(B,{type:"button",variant:"outline",size:"xs",className:"!font-normal mt-1",onClick:()=>{const v=_m();os(X=>({...X,portForwards:[...X.portForwards,v]})),H(X=>({...X,[v.id]:!0}))},children:[s.jsx(F,{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(B,{type:"button",size:"xs",className:"!font-normal",onClick:()=>{Ki()},disabled:!Fi||y,children:t("settings.common.actions.saveChanges")}),js?.localUrl?s.jsxs(s.Fragment,{children:[s.jsxs(B,{type:"button",variant:"outline",size:"xs",className:"!font-normal",onClick:()=>{Ka(js.localUrl||"").then(v=>{v.ok&&E.success(t("settings.remoteInstances.page.toast.localUrlCopied"))})},children:[s.jsx(F,{name:"file-copy",className:"h-3.5 w-3.5"}),t("settings.remoteInstances.page.actions.copyLocalUrl")]}),s.jsxs(B,{type:"button",variant:"outline",size:"xs",className:"!font-normal",onClick:()=>{Ya()},children:[s.jsx(F,{name:"external-link",className:"h-3.5 w-3.5"}),t("settings.remoteInstances.page.actions.open")]})]}):null,p?s.jsx("div",{className:"ml-auto typography-meta text-[var(--status-error)]",children:p}):null]})}),s.jsx(Kt,{open:O,onOpenChange:T,children:s.jsxs(zt,{className:"sm:max-w-2xl",children:[s.jsxs(_t,{children:[s.jsx($t,{children:t("settings.remoteInstances.page.logsDialog.title")}),s.jsx(Vt,{children:h?.nickname?.trim()||h?.sshParsed?.destination||h?.id||t("settings.remoteInstances.page.logsDialog.selectedInstanceFallback")})]}),s.jsxs("div",{className:"flex items-center justify-end gap-2",children:[s.jsxs(B,{type:"button",variant:"outline",size:"xs",className:"!font-normal",onClick:ls,disabled:S||!ce.trim(),children:[s.jsx(F,{name:"file-copy",className:"h-3.5 w-3.5"}),t("settings.common.actions.copyAll")]}),s.jsxs(B,{type:"button",variant:"outline",size:"xs",className:"!font-normal",onClick:()=>{aa()},disabled:S,children:[s.jsx(F,{name:"delete-bin",className:"h-3.5 w-3.5"}),t("settings.common.actions.clear")]})]}),S?s.jsx("div",{className:"typography-meta text-muted-foreground",children:t("settings.remoteInstances.page.logsDialog.loading")}):V?s.jsx("div",{className:"typography-meta text-[var(--status-error)]",children:V}):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:k.length>0?k.join(`
28
- `):t("settings.remoteInstances.page.logsDialog.empty")})]})}),s.jsx(Kt,{open:!!D,onOpenChange:v=>{v||ta()},children:s.jsxs(zt,{className:"sm:max-w-md",children:[s.jsxs(_t,{children:[s.jsx($t,{children:t("settings.remoteInstances.page.patternDialog.title")}),s.jsx(Vt,{children:D?t("settings.remoteInstances.page.patternDialog.descriptionWithHost",{host:D}):t("settings.remoteInstances.page.patternDialog.description")})]}),s.jsxs("form",{className:"space-y-3",onSubmit:v=>{v.preventDefault(),Qa()},children:[s.jsx(He,{value:J,onChange:v=>ee(v.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(B,{type:"button",variant:"outline",size:"xs",className:"!font-normal",onClick:ta,disabled:U,children:t("settings.common.actions.cancel")}),s.jsx(B,{type:"submit",size:"xs",className:"!font-normal",disabled:U,children:t("settings.common.actions.create")})]})]})]})})]})})},Ym="__add_provider__",Zm=()=>{const t=fn.getDirectory();return typeof t=="string"&&t.trim().length>0?t.trim():null},Xm=({onItemSelect:t})=>{const{t:e}=tt(),a=_s(),n=Ye(f=>Cl(f,a)),r=Ye(f=>f.selectedProviderId),i=Ye(f=>f.setSelectedProvider),l=Ws(f=>f.activeProjectId),[g,c]=o.useState({}),y=o.useMemo(()=>a||Zm(),[l,a]),p=Ye(f=>f.loadProviders);o.useEffect(()=>{a&&p({directory:a,source:"settings:providers"})},[p,a]),o.useEffect(()=>{if(n.length===0){c({});return}let f=!1;return(async()=>{const x=n.map(async N=>{try{const m=y?`?directory=${encodeURIComponent(y)}`:"",A=await yt(`/api/provider/${encodeURIComponent(N.id)}/source${m}`,{method:"GET",headers:{Accept:"application/json"}});if(!A.ok)return;const R=await A.json().catch(()=>null),I=R?.sources??R?.data?.sources;if(!I||f)return;c(j=>({...j,[N.id]:I}))}catch{}});await Promise.all(x)})(),()=>{f=!0}},[y,n]);const b="bg-background",d=o.useMemo(()=>n.filter(f=>!!g[f.id]?.project?.exists),[n,g]),C=o.useMemo(()=>n.filter(f=>!g[f.id]?.project?.exists),[n,g]);return s.jsxs("div",{className:fe("flex h-full flex-col",b),children:[s.jsxs("div",{className:"border-b px-3 pt-4 pb-3",children:[s.jsx("h2",{className:`${un} mb-3`,children:e("settings.providers.sidebar.title")}),s.jsx(Ba,{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:n.length})}),s.jsx(B,{size:"sm",variant:"ghost",className:"h-7 w-7 px-0 -my-1 text-muted-foreground",onClick:()=>{i(Ym),t?.()},"aria-label":e("settings.providers.sidebar.actions.connectProviderAria"),title:e("settings.providers.sidebar.actions.connectProviderTitle"),children:s.jsx(F,{name:"add",className:"h-3.5 w-3.5"})})]})]}),s.jsx(vs,{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(F,{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:[C.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")}),C.map(f=>s.jsx(Mo,{provider:f,selectedProviderId:r,onSelect:()=>{i(f.id),t?.()}},f.id))]}),d.length>0&&s.jsxs(s.Fragment,{children:[s.jsx("div",{className:fe("px-2 pb-1.5 text-xs font-semibold uppercase tracking-wide text-muted-foreground",C.length>0?"pt-3":"pt-2"),children:e("settings.providers.sidebar.section.projectProviders")}),d.map(f=>s.jsx(Mo,{provider:f,selectedProviderId:r,onSelect:()=>{i(f.id),t?.()}},f.id))]})]})})]})},Mo=t=>{const e=ut.c(17),{provider:a,selectedProviderId:n,onSelect:r}=t,i=Array.isArray(a.models)?a.models.length:0,l=a.id===n,g=a.id,c=l?"bg-interactive-selection":"hover:bg-interactive-hover";let y;e[0]!==c?(y=fe("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 p;e[2]!==a.id?(p=s.jsx(Un,{providerId:a.id,className:"h-4 w-4 flex-shrink-0"}),e[2]=a.id,e[3]=p):p=e[3];const b=a.name||a.id;let d;e[4]!==b?(d=s.jsx("span",{className:"typography-ui-label font-normal truncate flex-1 min-w-0 text-foreground",children:b}),e[4]=b,e[5]=d):d=e[5];let C;e[6]!==i?(C=s.jsx("span",{className:"typography-micro text-muted-foreground/60 flex-shrink-0",children:i}),e[6]=i,e[7]=C):C=e[7];let f;e[8]!==r||e[9]!==p||e[10]!==d||e[11]!==C?(f=s.jsxs("button",{type:"button",onClick:r,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:[p,d,C]}),e[8]=r,e[9]=p,e[10]=d,e[11]=C,e[12]=f):f=e[12];let P;return e[13]!==a.id||e[14]!==y||e[15]!==f?(P=s.jsx("div",{className:y,children:f},g),e[13]=a.id,e[14]=y,e[15]=f,e[16]=P):P=e[16],P},eg=t=>t,tg=(t,e,a)=>t&&!e&&!a,Ro=t=>typeof t=="object"&&t!==null,Ql=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()},sg=t=>{if(!Ro(t))return{};const e={};for(const[a,n]of Object.entries(t))Array.isArray(n)&&(e[a]=n.filter(r=>Ro(r)));return e},Lo=t=>t.length===0?!0:t.some(e=>Ql(e)==="api"),Oo=t=>t.map((e,a)=>({method:e,methodIndex:a})).filter(({method:e})=>Ql(e)==="oauth"),ng=t=>t!=="claude-code",Fo=t=>typeof t.key=="string"&&t.key.trim().length>0||typeof t.optionsApiKey=="string"&&t.optionsApiKey.trim().length>0||t.envDeclared===!0?!0:t.authSourceExists===!0,ag=t=>t.modelCount>0&&(!t.sourcesLoaded||t.hasCredentials||!!t.isEditableCustomProvider),ig=t=>!t.hasCredentials&&!t.userDismissed&&!t.isEditableCustomProvider,Tr={"openai-chat":"@ai-sdk/openai-compatible","openai-responses":"@ai-sdk/openai","anthropic-messages":"@ai-sdk/anthropic"},Kn="__custom_provider__",rg=/^[a-z0-9][a-z0-9-_]*$/,Yl=/^https?:\/\//,og=/^\{env:([^}]+)\}$/;let lg=0;const Ci=()=>`row-${lg++}`,Er=()=>({row:Ci(),id:"",name:""}),Dr=()=>({row:Ci(),key:"",value:""}),cg=()=>({providerID:"",name:"",protocol:"openai-chat",baseURL:"",apiKey:"",models:[Er()],headers:[Dr()]});function dg(t){switch(t){case"@ai-sdk/openai":return"openai-responses";case"@ai-sdk/anthropic":return"anthropic-messages";default:return"openai-chat"}}function ug(t){const e=t.trim();if(!e)return{};const n=e.match(og)?.[1]?.trim();return n?{env:n}:{key:e}}function pg(t){const e=t.options&&typeof t.options=="object"?t.options:null,a=typeof e?.baseURL=="string"?e.baseURL.trim():"";return a&&Yl.test(a)?!0:(Array.isArray(t.models)?t.models:t.models&&typeof t.models=="object"?Object.values(t.models):[]).some(r=>{if(!r||typeof r!="object")return!1;const i="api"in r&&r.api&&typeof r.api=="object"?r.api:null;return typeof i?.npm=="string"&&new Set(Object.values(Tr)).has(i.npm)})}function Ko(t,e){return e?!!(e.user?.exists||e.project?.exists||e.custom?.exists)&&pg(t):!1}function zo(t){return t?.custom?.exists?"custom":t?.project?.exists?"project":"user"}function mg(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:{},r=Object.entries(n).filter(y=>typeof y[0]=="string"&&typeof y[1]=="string").map(([y,p])=>({row:Ci(),key:y,value:p})),i=Array.isArray(t.models)?t.models:t.models&&typeof t.models=="object"?Object.entries(t.models).map(([y,p])=>({id:y,name:p&&typeof p=="object"&&"name"in p&&typeof p.name=="string"?p.name:y})):[],l=i.length>0?i.map(y=>({row:Ci(),id:typeof y?.id=="string"?y.id:"",name:typeof y?.name=="string"?y.name:typeof y?.id=="string"?y.id:""})):[Er()],g=Array.isArray(t.env)?t.env.find(y=>typeof y=="string"&&y.trim().length>0)?.trim():void 0,c=i.find(y=>"api"in y);return{providerID:t.id,name:typeof t.name=="string"&&t.name.trim()?t.name:t.id,protocol:dg(c?.api?.npm),baseURL:a,apiKey:g?`{env:${g}}`:"",models:l,headers:r.length>0?r:[Dr()]}}function gg(t){const e=t.form.providerID.trim(),a=t.form.name.trim(),n=t.form.baseURL.trim(),{env:r,key:i}=ug(t.form.apiKey),l=t.disabledProviders??[],g=t.editingProviderID?.trim(),c=e?rg.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"),p=n?Yl.test(n)?void 0:t.t("settings.providers.page.custom.error.baseURL.format"):t.t("settings.providers.page.custom.error.baseURL.required"),d=!!(r||i||g&&t.allowExistingAuth&&g===e)?void 0:t.t("settings.providers.page.custom.error.apiKey.required"),C=l.includes(e),P=c||!!(g&&g===e)?void 0:t.existingProviderIDs.has(e)&&!C?t.t("settings.providers.page.custom.error.providerID.exists"):void 0,x=new Set,N=t.form.models.map(T=>{const S=T.id.trim(),M=S?x.has(S)?t.t("settings.providers.page.custom.error.duplicate"):void x.add(S):t.t("settings.providers.page.custom.error.required"),V=T.name.trim()?void 0:t.t("settings.providers.page.custom.error.required");return{id:M,name:V}}),m=N.every(T=>!T.id&&!T.name),A=Object.fromEntries(t.form.models.map(T=>[T.id.trim(),{name:T.name.trim()}])),R=new Set,I=t.form.headers.map(T=>{const S=T.key.trim(),M=T.value.trim();if(!S&&!M)return{};const V=S?R.has(S.toLowerCase())?t.t("settings.providers.page.custom.error.duplicate"):void R.add(S.toLowerCase()):t.t("settings.providers.page.custom.error.required"),$=M?void 0:t.t("settings.providers.page.custom.error.required");return{key:V,value:$}}),j=I.every(T=>!T.key&&!T.value),h=Object.fromEntries(t.form.headers.map(T=>({key:T.key.trim(),value:T.value.trim()})).filter(T=>T.key&&T.value).map(T=>[T.key,T.value])),w={providerID:c??P,name:y,baseURL:p,apiKey:d};return!c&&!P&&!y&&!p&&!d&&m&&j?{err:w,models:N,headers:I,result:{providerID:e,name:a,apiKey:i,config:{npm:Tr[t.form.protocol],name:a,...r?{env:[r]}:{},options:{baseURL:n,...Object.keys(h).length>0?{headers:h}:{}},models:A}}}:{err:w,models:N,headers:I}}function hg(t){return t.apiKey?{providerID:t.providerID,auth:{type:"api",key:t.apiKey}}:null}function fg(t,e){return{providerID:t.providerID,config:t.config,scope:e?.scope??"user"}}const Uo=t=>{const e=ut.c(234),{existingProviderIDs:a,disabledProviders:n,busy:r,mode:i,initialValues:l,allowExistingAuth:g,authFailureHint:c,onSubmit:y,onCancel:p,onDisconnect:b}=t;let d;e[0]!==n?(d=n===void 0?[]:n,e[0]=n,e[1]=d):d=e[1];const C=d,f=r===void 0?!1:r,P=i===void 0?"create":i,x=g===void 0?!1:g,N=c===void 0?null:c,{t:m}=tt(),A=P==="edit";let R;e[2]!==l?(R=()=>l??cg(),e[2]=l,e[3]=R):R=e[3];const[I,j]=o.useState(R);let h;e[4]===Symbol.for("react.memo_cache_sentinel")?(h={},e[4]=h):h=e[4];const[w,O]=o.useState(h);let T;e[5]===Symbol.for("react.memo_cache_sentinel")?(T=[],e[5]=T):T=e[5];const[S,M]=o.useState(T);let V;e[6]===Symbol.for("react.memo_cache_sentinel")?(V=[],e[6]=V):V=e[6];const[$,k]=o.useState(V),W=o.useRef(null);let D,L;e[7]!==l||e[8]!==A?(D=()=>{l&&(A&&W.current===l.providerID||(W.current=A?l.providerID:null,j(l),O({}),M([]),k([])))},L=[l,A],e[7]=l,e[8]=A,e[9]=D,e[10]=L):(D=e[9],L=e[10]),o.useEffect(D,L);let J;e[11]===Symbol.for("react.memo_cache_sentinel")?(J=(jt,At)=>{j(Ut=>({...Ut,[jt]:At})),O(Ut=>({...Ut,[jt]:void 0}))},e[11]=J):J=e[11];const ee=J;let U;e[12]===Symbol.for("react.memo_cache_sentinel")?(U=(jt,At,Ut)=>{j(Ot=>({...Ot,models:Ot.models.map((ns,Ds)=>Ds===jt?{...ns,[At]:Ut}:ns)})),M(Ot=>{const ns=[...Ot];return ns[jt]={...ns[jt]??{},[At]:void 0},ns})},e[12]=U):U=e[12];const re=U;let _;e[13]===Symbol.for("react.memo_cache_sentinel")?(_=(jt,At,Ut)=>{j(Ot=>({...Ot,headers:Ot.headers.map((ns,Ds)=>Ds===jt?{...ns,[At]:Ut}:ns)})),k(Ot=>{const ns=[...Ot];return ns[jt]={...ns[jt]??{},[At]:void 0},ns})},e[13]=_):_=e[13];const H=_;let z;e[14]!==x||e[15]!==f||e[16]!==C||e[17]!==a||e[18]!==I||e[19]!==A||e[20]!==y||e[21]!==m?(z=async jt=>{if(jt.preventDefault(),f)return;const At=gg({form:I,t:((Ut,Ot)=>m(Ut,Ot)),existingProviderIDs:a,disabledProviders:C,editingProviderID:A?I.providerID:void 0,allowExistingAuth:A&&x});O(At.err),M(At.models),k(At.headers),At.result&&await y(At.result)},e[14]=x,e[15]=f,e[16]=C,e[17]=a,e[18]=I,e[19]=A,e[20]=y,e[21]=m,e[22]=z):z=e[22];const K=z;let te;e[23]!==A||e[24]!==m?(te=m(A?"settings.providers.page.custom.editTitle":"settings.providers.page.custom.title"),e[23]=A,e[24]=m,e[25]=te):te=e[25];let Y;e[26]!==m?(Y=m("settings.providers.page.custom.description"),e[26]=m,e[27]=Y):Y=e[27];let ne;e[28]!==Y?(ne=s.jsx("p",{className:zn,children:Y}),e[28]=Y,e[29]=ne):ne=e[29];let me;e[30]!==N?(me=N?s.jsx("p",{className:"typography-meta text-[var(--status-warning)]",role:"status",children:N}):null,e[30]=N,e[31]=me):me=e[31];let de;e[32]!==m?(de=m("settings.providers.page.custom.field.providerID.label"),e[32]=m,e[33]=de):de=e[33];let xe;e[34]!==m?(xe=m("settings.providers.page.custom.field.providerID.info"),e[34]=m,e[35]=xe):xe=e[35];const ae=I.providerID;let le;e[36]===Symbol.for("react.memo_cache_sentinel")?(le=jt=>ee("providerID",jt.target.value),e[36]=le):le=e[36];let ge;e[37]!==m?(ge=m("settings.providers.page.custom.field.providerID.placeholder"),e[37]=m,e[38]=ge):ge=e[38];const Ae=!A,Se=A||f,Ce=!!w.providerID;let he;e[39]!==m?(he=m("settings.providers.page.custom.field.providerID.label"),e[39]=m,e[40]=he):he=e[40];let _e;e[41]!==I.providerID||e[42]!==ge||e[43]!==Ae||e[44]!==Se||e[45]!==Ce||e[46]!==he?(_e=s.jsx(He,{value:ae,onChange:le,placeholder:ge,className:"h-8 rounded-md px-3 font-mono text-xs",autoFocus:Ae,disabled:Se,"aria-invalid":Ce,"aria-label":he}),e[41]=I.providerID,e[42]=ge,e[43]=Ae,e[44]=Se,e[45]=Ce,e[46]=he,e[47]=_e):_e=e[47];let Ue;e[48]!==w.providerID?(Ue=w.providerID?s.jsx("p",{className:"mt-1 typography-meta text-[var(--status-error)]",children:w.providerID}):null,e[48]=w.providerID,e[49]=Ue):Ue=e[49];let ke;e[50]!==de||e[51]!==xe||e[52]!==_e||e[53]!==Ue?(ke=s.jsxs(qt,{label:de,info:xe,children:[_e,Ue]}),e[50]=de,e[51]=xe,e[52]=_e,e[53]=Ue,e[54]=ke):ke=e[54];let Oe;e[55]!==m?(Oe=m("settings.providers.page.custom.field.protocol.label"),e[55]=m,e[56]=Oe):Oe=e[56];let Ve;e[57]!==m?(Ve=m("settings.providers.page.custom.field.protocol.info"),e[57]=m,e[58]=Ve):Ve=e[58];const We=I.protocol;let ve;e[59]===Symbol.for("react.memo_cache_sentinel")?(ve=jt=>{jt in Tr&&j(At=>({...At,protocol:jt}))},e[59]=ve):ve=e[59];let Z;e[60]!==m?(Z=m("settings.providers.page.custom.field.protocol.label"),e[60]=m,e[61]=Z):Z=e[61];let se;e[62]===Symbol.for("react.memo_cache_sentinel")?(se=s.jsx(Mt,{}),e[62]=se):se=e[62];let ye;e[63]!==Z?(ye=s.jsx(Ct,{"aria-label":Z,className:"w-full",children:se}),e[63]=Z,e[64]=ye):ye=e[64];let be;e[65]!==m?(be=m("settings.providers.page.custom.field.protocol.openaiChat"),e[65]=m,e[66]=be):be=e[66];let Re;e[67]!==be?(Re=s.jsx(at,{value:"openai-chat",children:be}),e[67]=be,e[68]=Re):Re=e[68];let Fe;e[69]!==m?(Fe=m("settings.providers.page.custom.field.protocol.openaiResponses"),e[69]=m,e[70]=Fe):Fe=e[70];let Ke;e[71]!==Fe?(Ke=s.jsx(at,{value:"openai-responses",children:Fe}),e[71]=Fe,e[72]=Ke):Ke=e[72];let Ee;e[73]!==m?(Ee=m("settings.providers.page.custom.field.protocol.anthropicMessages"),e[73]=m,e[74]=Ee):Ee=e[74];let we;e[75]!==Ee?(we=s.jsx(at,{value:"anthropic-messages",children:Ee}),e[75]=Ee,e[76]=we):we=e[76];let Ze;e[77]!==Re||e[78]!==Ke||e[79]!==we?(Ze=s.jsxs(It,{children:[Re,Ke,we]}),e[77]=Re,e[78]=Ke,e[79]=we,e[80]=Ze):Ze=e[80];let pe;e[81]!==f||e[82]!==I.protocol||e[83]!==ye||e[84]!==Ze?(pe=s.jsxs(St,{value:We,onValueChange:ve,disabled:f,children:[ye,Ze]}),e[81]=f,e[82]=I.protocol,e[83]=ye,e[84]=Ze,e[85]=pe):pe=e[85];let Ne;e[86]!==Oe||e[87]!==Ve||e[88]!==pe?(Ne=s.jsx(qt,{label:Oe,info:Ve,children:pe}),e[86]=Oe,e[87]=Ve,e[88]=pe,e[89]=Ne):Ne=e[89];let Le;e[90]!==m?(Le=m("settings.providers.page.custom.field.name.label"),e[90]=m,e[91]=Le):Le=e[91];let Xe;e[92]!==m?(Xe=m("settings.providers.page.custom.field.name.info"),e[92]=m,e[93]=Xe):Xe=e[93];const q=I.name;let je;e[94]===Symbol.for("react.memo_cache_sentinel")?(je=jt=>ee("name",jt.target.value),e[94]=je):je=e[94];let Ie;e[95]!==m?(Ie=m("settings.providers.page.custom.field.name.placeholder"),e[95]=m,e[96]=Ie):Ie=e[96];const Je=!!w.name;let ot;e[97]!==m?(ot=m("settings.providers.page.custom.field.name.label"),e[97]=m,e[98]=ot):ot=e[98];let st;e[99]!==I.name||e[100]!==Ie||e[101]!==Je||e[102]!==ot?(st=s.jsx(He,{value:q,onChange:je,placeholder:Ie,className:"h-8 rounded-md px-3","aria-invalid":Je,"aria-label":ot}),e[99]=I.name,e[100]=Ie,e[101]=Je,e[102]=ot,e[103]=st):st=e[103];let mt;e[104]!==w.name?(mt=w.name?s.jsx("p",{className:"mt-1 typography-meta text-[var(--status-error)]",children:w.name}):null,e[104]=w.name,e[105]=mt):mt=e[105];let vt;e[106]!==Le||e[107]!==Xe||e[108]!==st||e[109]!==mt?(vt=s.jsxs(qt,{label:Le,info:Xe,children:[st,mt]}),e[106]=Le,e[107]=Xe,e[108]=st,e[109]=mt,e[110]=vt):vt=e[110];let G;e[111]!==m?(G=m("settings.providers.page.custom.field.baseURL.label"),e[111]=m,e[112]=G):G=e[112];let Ge;e[113]!==m?(Ge=m("settings.providers.page.custom.field.baseURL.info"),e[113]=m,e[114]=Ge):Ge=e[114];const nt=I.baseURL;let lt;e[115]===Symbol.for("react.memo_cache_sentinel")?(lt=jt=>ee("baseURL",jt.target.value),e[115]=lt):lt=e[115];let ht;e[116]!==m?(ht=m("settings.providers.page.custom.field.baseURL.placeholder"),e[116]=m,e[117]=ht):ht=e[117];const Lt=!!w.baseURL;let et;e[118]!==m?(et=m("settings.providers.page.custom.field.baseURL.label"),e[118]=m,e[119]=et):et=e[119];let ft;e[120]!==I.baseURL||e[121]!==ht||e[122]!==Lt||e[123]!==et?(ft=s.jsx(He,{value:nt,onChange:lt,placeholder:ht,className:"h-8 rounded-md px-3 font-mono text-xs","aria-invalid":Lt,"aria-label":et}),e[120]=I.baseURL,e[121]=ht,e[122]=Lt,e[123]=et,e[124]=ft):ft=e[124];let bt;e[125]!==w.baseURL?(bt=w.baseURL?s.jsx("p",{className:"mt-1 typography-meta text-[var(--status-error)]",children:w.baseURL}):null,e[125]=w.baseURL,e[126]=bt):bt=e[126];let Be;e[127]!==G||e[128]!==Ge||e[129]!==ft||e[130]!==bt?(Be=s.jsxs(qt,{label:G,info:Ge,children:[ft,bt]}),e[127]=G,e[128]=Ge,e[129]=ft,e[130]=bt,e[131]=Be):Be=e[131];let Et;e[132]!==m?(Et=m("settings.providers.page.custom.field.apiKey.label"),e[132]=m,e[133]=Et):Et=e[133];let Me;e[134]!==x||e[135]!==A||e[136]!==m?(Me=m(A&&x?"settings.providers.page.custom.field.apiKey.editInfo":"settings.providers.page.custom.field.apiKey.info"),e[134]=x,e[135]=A,e[136]=m,e[137]=Me):Me=e[137];const wt=I.apiKey;let Q;e[138]===Symbol.for("react.memo_cache_sentinel")?(Q=jt=>ee("apiKey",jt.target.value),e[138]=Q):Q=e[138];let ue;e[139]!==x||e[140]!==A||e[141]!==m?(ue=m(A&&x?"settings.providers.page.custom.field.apiKey.editPlaceholder":"settings.providers.page.custom.field.apiKey.placeholder"),e[139]=x,e[140]=A,e[141]=m,e[142]=ue):ue=e[142];const De=!!w.apiKey;let Pe;e[143]!==m?(Pe=m("settings.providers.page.custom.field.apiKey.label"),e[143]=m,e[144]=Pe):Pe=e[144];let it;e[145]!==I.apiKey||e[146]!==ue||e[147]!==De||e[148]!==Pe?(it=s.jsx(He,{type:"password",value:wt,onChange:Q,placeholder:ue,className:"h-8 rounded-md px-3 font-mono text-xs","aria-invalid":De,"aria-label":Pe}),e[145]=I.apiKey,e[146]=ue,e[147]=De,e[148]=Pe,e[149]=it):it=e[149];let rt;e[150]!==w.apiKey?(rt=w.apiKey?s.jsx("p",{className:"mt-1 typography-meta text-[var(--status-error)]",children:w.apiKey}):null,e[150]=w.apiKey,e[151]=rt):rt=e[151];let qe;e[152]!==Et||e[153]!==Me||e[154]!==it||e[155]!==rt?(qe=s.jsxs(qt,{label:Et,info:Me,children:[it,rt]}),e[152]=Et,e[153]=Me,e[154]=it,e[155]=rt,e[156]=qe):qe=e[156];let Pt;e[157]!==te||e[158]!==ne||e[159]!==me||e[160]!==ke||e[161]!==Ne||e[162]!==vt||e[163]!==Be||e[164]!==qe?(Pt=s.jsxs(ze,{title:te,divider:!1,settingsItem:"providers.custom",contentClassName:Qs,children:[ne,me,ke,Ne,vt,Be,qe]}),e[157]=te,e[158]=ne,e[159]=me,e[160]=ke,e[161]=Ne,e[162]=vt,e[163]=Be,e[164]=qe,e[165]=Pt):Pt=e[165];let ys;e[166]!==m?(ys=m("settings.providers.page.custom.models.title"),e[166]=m,e[167]=ys):ys=e[167];let Xt;if(e[168]!==I.models||e[169]!==S||e[170]!==m){let jt;e[172]!==I.models.length||e[173]!==S||e[174]!==m?(jt=(At,Ut)=>s.jsx("div",{className:`${zs} 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:Tt,children:m("settings.providers.page.custom.models.idLabel")}),s.jsx(He,{value:At.id,onChange:Ot=>re(Ut,"id",Ot.target.value),placeholder:m("settings.providers.page.custom.models.idPlaceholder"),className:"mt-1 h-8 rounded-md px-3 font-mono text-xs","aria-label":m("settings.providers.page.custom.models.idLabel")}),S[Ut]?.id?s.jsx("p",{className:"mt-1 typography-meta text-[var(--status-error)]",children:S[Ut]?.id}):null]}),s.jsxs("div",{children:[s.jsx("label",{className:Tt,children:m("settings.providers.page.custom.models.nameLabel")}),s.jsx(He,{value:At.name,onChange:Ot=>re(Ut,"name",Ot.target.value),placeholder:m("settings.providers.page.custom.models.namePlaceholder"),className:"mt-1 h-8 rounded-md px-3","aria-label":m("settings.providers.page.custom.models.nameLabel")}),S[Ut]?.name?s.jsx("p",{className:"mt-1 typography-meta text-[var(--status-error)]",children:S[Ut]?.name}):null]})]}),s.jsx(B,{type:"button",variant:"ghost",size:"icon",className:Cs,disabled:I.models.length<=1,onClick:()=>{I.models.length<=1||(j(Ot=>({...Ot,models:Ot.models.filter((ns,Ds)=>Ds!==Ut)})),M(Ot=>Ot.filter((ns,Ds)=>Ds!==Ut)))},"aria-label":m("settings.providers.page.custom.models.remove"),children:s.jsx(F,{name:"delete-bin",className:"size-4"})})]})},At.row),e[172]=I.models.length,e[173]=S,e[174]=m,e[175]=jt):jt=e[175],Xt=I.models.map(jt),e[168]=I.models,e[169]=S,e[170]=m,e[171]=Xt}else Xt=e[171];let Os;e[176]===Symbol.for("react.memo_cache_sentinel")?(Os=()=>{j(xg),M(vg)},e[176]=Os):Os=e[176];let Gt;e[177]!==m?(Gt=m("settings.providers.page.custom.models.add"),e[177]=m,e[178]=Gt):Gt=e[178];let is;e[179]!==Gt?(is=s.jsx(B,{type:"button",variant:"outline",size:"xs",className:"!font-normal",onClick:Os,children:Gt}),e[179]=Gt,e[180]=is):is=e[180];let Ht;e[181]!==ys||e[182]!==Xt||e[183]!==is?(Ht=s.jsxs(ze,{title:ys,contentClassName:Qs,children:[Xt,is]}),e[181]=ys,e[182]=Xt,e[183]=is,e[184]=Ht):Ht=e[184];let bs;e[185]!==m?(bs=m("settings.providers.page.custom.headers.title"),e[185]=m,e[186]=bs):bs=e[186];let gs;e[187]!==m?(gs=m("settings.providers.page.custom.headers.description"),e[187]=m,e[188]=gs):gs=e[188];let hs;e[189]!==gs?(hs=s.jsx("p",{className:zn,children:gs}),e[189]=gs,e[190]=hs):hs=e[190];let ds;if(e[191]!==I.headers||e[192]!==$||e[193]!==m){let jt;e[195]!==I.headers.length||e[196]!==$||e[197]!==m?(jt=(At,Ut)=>s.jsx("div",{className:`${zs} 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:Tt,children:m("settings.providers.page.custom.headers.keyLabel")}),s.jsx(He,{value:At.key,onChange:Ot=>H(Ut,"key",Ot.target.value),placeholder:m("settings.providers.page.custom.headers.keyPlaceholder"),className:"mt-1 h-8 rounded-md px-3 font-mono text-xs","aria-label":m("settings.providers.page.custom.headers.keyLabel")}),$[Ut]?.key?s.jsx("p",{className:"mt-1 typography-meta text-[var(--status-error)]",children:$[Ut]?.key}):null]}),s.jsxs("div",{children:[s.jsx("label",{className:Tt,children:m("settings.providers.page.custom.headers.valueLabel")}),s.jsx(He,{value:At.value,onChange:Ot=>H(Ut,"value",Ot.target.value),placeholder:m("settings.providers.page.custom.headers.valuePlaceholder"),className:"mt-1 h-8 rounded-md px-3 font-mono text-xs","aria-label":m("settings.providers.page.custom.headers.valueLabel")}),$[Ut]?.value?s.jsx("p",{className:"mt-1 typography-meta text-[var(--status-error)]",children:$[Ut]?.value}):null]})]}),s.jsx(B,{type:"button",variant:"ghost",size:"icon",className:Cs,disabled:I.headers.length<=1,onClick:()=>{I.headers.length<=1||(j(Ot=>({...Ot,headers:Ot.headers.filter((ns,Ds)=>Ds!==Ut)})),k(Ot=>Ot.filter((ns,Ds)=>Ds!==Ut)))},"aria-label":m("settings.providers.page.custom.headers.remove"),children:s.jsx(F,{name:"delete-bin",className:"size-4"})})]})},At.row),e[195]=I.headers.length,e[196]=$,e[197]=m,e[198]=jt):jt=e[198],ds=I.headers.map(jt),e[191]=I.headers,e[192]=$,e[193]=m,e[194]=ds}else ds=e[194];let Es;e[199]===Symbol.for("react.memo_cache_sentinel")?(Es=()=>{j(yg),k(bg)},e[199]=Es):Es=e[199];let oe;e[200]!==m?(oe=m("settings.providers.page.custom.headers.add"),e[200]=m,e[201]=oe):oe=e[201];let ct;e[202]!==oe?(ct=s.jsx(B,{type:"button",variant:"outline",size:"xs",className:"!font-normal",onClick:Es,children:oe}),e[202]=oe,e[203]=ct):ct=e[203];let xt;e[204]!==bs||e[205]!==hs||e[206]!==ds||e[207]!==ct?(xt=s.jsxs(ze,{title:bs,contentClassName:Qs,children:[hs,ds,ct]}),e[204]=bs,e[205]=hs,e[206]=ds,e[207]=ct,e[208]=xt):xt=e[208];let Qt;e[209]!==f||e[210]!==p||e[211]!==m?(Qt=p?s.jsx(B,{type:"button",variant:"outline",size:"xs",className:"!font-normal",onClick:p,disabled:f,children:m("settings.providers.page.custom.actions.back")}):null,e[209]=f,e[210]=p,e[211]=m,e[212]=Qt):Qt=e[212];let Yt;e[213]!==f||e[214]!==b||e[215]!==m?(Yt=b?s.jsx(B,{type:"button",variant:"destructive",size:"xs",className:"!font-normal",onClick:()=>{b()},disabled:f,children:m("settings.providers.page.actions.disconnect")}):null,e[213]=f,e[214]=b,e[215]=m,e[216]=Yt):Yt=e[216];let Bt;e[217]!==f||e[218]!==A||e[219]!==m?(Bt=m(f?"settings.providers.page.actions.saving":A?"settings.providers.page.custom.actions.update":"settings.providers.page.custom.actions.save"),e[217]=f,e[218]=A,e[219]=m,e[220]=Bt):Bt=e[220];let rs;e[221]!==f||e[222]!==Bt?(rs=s.jsx(B,{type:"submit",size:"xs",className:"!font-normal",disabled:f,children:Bt}),e[221]=f,e[222]=Bt,e[223]=rs):rs=e[223];let ws;e[224]!==Qt||e[225]!==Yt||e[226]!==rs?(ws=s.jsxs("div",{className:"flex flex-wrap items-center gap-2 py-4",children:[Qt,Yt,rs]}),e[224]=Qt,e[225]=Yt,e[226]=rs,e[227]=ws):ws=e[227];let ss;return e[228]!==K||e[229]!==Pt||e[230]!==Ht||e[231]!==xt||e[232]!==ws?(ss=s.jsxs("form",{onSubmit:K,className:"space-y-0",children:[Pt,Ht,xt,ws]}),e[228]=K,e[229]=Pt,e[230]=Ht,e[231]=xt,e[232]=ws,e[233]=ss):ss=e[233],ss};function xg(t){return{...t,models:[...t.models,Er()]}}function vg(t){return[...t,{}]}function yg(t){return{...t,headers:[...t.headers,Dr()]}}function bg(t){return[...t,{}]}const wg=(t,e)=>!!e&&t!=="claude-code",jg=/[A-Z0-9]{4}-[A-Z0-9]{4,5}/,Yn=t=>typeof t=="object"&&t!==null&&!Array.isArray(t),Is=t=>typeof t=="string"&&t.length>0?t:void 0,kg=t=>{if(!Array.isArray(t))return[];const e=[];for(const a of t){if(!Yn(a))continue;const n=Is(a.value);n!==void 0&&e.push({value:n,label:Is(a.label)??n,...Is(a.hint)?{hint:Is(a.hint)}:{}})}return e},Ng=t=>{if(!Yn(t))return;const e=Is(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}},Sg=t=>{if(!Array.isArray(t))return[];const e=[];for(const a of t){if(!Yn(a))continue;const n=Is(a.key);if(!n)continue;const r=a.type==="select"?"select":"text",i=r==="select"?kg(a.options):[];if(r==="select"&&i.length===0)continue;const l=Ng(a.when);e.push({type:r,key:n,message:Is(a.message)??n,options:i,...Is(a.placeholder)?{placeholder:Is(a.placeholder)}:{},...l?{when:l}:{}})}return e},Cg=(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},Mr=(t,e)=>t.filter(a=>Cg(a,e)),Ig=t=>{const e={};for(const a of t)e[a.key]=a.type==="select"?a.options[0]?.value??"":"";return e},Pg=(t,e)=>Mr(t,e).find(a=>(e[a.key]??"").trim().length===0)??null,Ag=(t,e)=>{const a={};for(const n of Mr(t,e))a[n.key]=(e[n.key]??"").trim();return a},Tg=t=>{const e=Yn(t)?t:{},a=Yn(e.data)?e.data:e,n=Is(a.url)??Is(a.verification_uri_complete)??Is(a.verification_uri),r=Is(a.instructions)??Is(a.message);if(!n&&!r)return null;const i=Is(a.user_code)??Is(a.userCode)??(r?jg.exec(r)?.[0]:void 0);return{method:a.method==="code"?"code":"auto",...n?{url:n}:{},...r?{instructions:r}:{},...i?{userCode:i}:{}}},_o=(t,e,a)=>{const n=Yn(t)?t:{},r=Yn(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 Is(r.message)??e("settings.providers.page.auth.oauth.error.invalidInput");default:return e(a)}},er={phase:"idle"},$o=({providerId:t,methods:e,onConnected:a,className:n})=>{const{t:r}=tt(),[i,l]=o.useState(er),[g,c]=o.useState({}),[y,p]=o.useState(""),b=o.useRef(null);o.useEffect(()=>()=>b.current?.abort(),[]);const d=i.phase==="idle"?null:i.methodIndex,C=i.phase==="authorizing"||i.phase==="waiting"||i.phase==="awaitingCode"&&i.submitting,f=async(h,w,O)=>{const T=await Ka(h);if(T.ok){E.success(r(w));return}console.error("Failed to copy OAuth value:",T.error),E.error(r(O))},P=async(h,w)=>{const O=new AbortController;b.current?.abort(),b.current=O;try{const T=await fn.getSdkClient().provider.oauth.callback({providerID:t,method:h,...w?{code:w}:{}},{signal:O.signal});if(O.signal.aborted)return;if(T.error)throw T.error;l(er),E.success(r("settings.providers.page.toast.oauthCompleted")),await a()}catch(T){if(O.signal.aborted)return;console.error("Failed to complete OAuth flow:",T),l({phase:"failed",methodIndex:h,message:_o(T,r,"settings.providers.page.toast.oauthCompleteFailed")})}finally{b.current===O&&(b.current=null)}},x=async(h,w)=>{l({phase:"authorizing",methodIndex:h});let O;try{const T=await fn.getSdkClient().provider.oauth.authorize({providerID:t,method:h,...Object.keys(w).length>0?{inputs:w}:{}});if(T.error)throw T.error;const S=Tg(T.data);if(!S){l({phase:"failed",methodIndex:h,message:r("settings.providers.page.toast.oauthDetailsMissing")});return}O=S}catch(T){console.error("Failed to start OAuth flow:",T),l({phase:"failed",methodIndex:h,message:_o(T,r,"settings.providers.page.toast.oauthStartFailed")});return}if(O.url&&wg(t,O.url)&&Pn(O.url),O.method==="code"){p(""),l({phase:"awaitingCode",methodIndex:h,authorization:O,submitting:!1});return}l({phase:"waiting",methodIndex:h,authorization:O}),await P(h)},N=h=>{const w=Sg(h.prompts);if(w.length===0){x(h.index,{});return}c(Ig(w)),l({phase:"prompting",methodIndex:h.index,prompts:w,error:null})},m=()=>{if(i.phase!=="prompting")return;const h=Pg(i.prompts,g);if(h){l({...i,error:r("settings.providers.page.auth.oauth.promptRequired",{field:h.message})});return}x(i.methodIndex,Ag(i.prompts,g))},A=()=>{if(i.phase!=="awaitingCode")return;const h=y.trim();h&&(l({...i,submitting:!0}),P(i.methodIndex,h))},R=()=>{b.current?.abort(),b.current=null,l(er)},I=h=>{const w=g[h.key]??"",O=T=>c(S=>({...S,[h.key]:T}));return s.jsxs("div",{className:"space-y-1.5",children:[s.jsx("label",{className:"typography-ui-label text-foreground",children:h.message}),h.type==="select"?s.jsxs(St,{value:w,onValueChange:O,children:[s.jsx(Ct,{size:Ft,className:rn,children:s.jsx(Mt,{children:T=>h.options.find(S=>S.value===T)?.label??null})}),s.jsx(It,{children:h.options.map(T=>s.jsx(at,{value:T.value,children:T.hint?`${T.label} · ${T.hint}`:T.label},T.value))})]}):s.jsx(He,{value:w,onChange:T=>O(T.target.value),placeholder:h.placeholder,className:"max-w-[24rem] text-xs"})]},h.key)},j=h=>s.jsxs(s.Fragment,{children:[h.instructions&&s.jsx("p",{className:"typography-meta text-[var(--primary-base)] bg-[var(--primary-base)]/10 px-2 py-1.5 rounded",children:h.instructions}),h.userCode&&s.jsxs("div",{className:"flex items-center gap-2",children:[s.jsx(He,{value:h.userCode,readOnly:!0,"aria-label":r("settings.providers.page.auth.oauth.deviceCodeLabel"),className:"font-mono text-center tracking-widest"}),s.jsx(B,{variant:"outline",size:"xs",className:"!font-normal shrink-0",onClick:()=>{f(h.userCode??"","settings.providers.page.toast.deviceCodeCopied","settings.providers.page.toast.deviceCodeCopyFailed")},children:r("settings.providers.page.actions.copyCode")})]}),h.url&&s.jsxs("div",{className:"flex items-center gap-2",children:[s.jsx(He,{value:h.url,readOnly:!0,"aria-label":r("settings.providers.page.auth.oauth.linkLabel"),className:"text-xs text-muted-foreground"}),s.jsxs("div",{className:"flex gap-1 shrink-0",children:[s.jsx(B,{variant:"outline",size:"xs",className:"!font-normal",onClick:()=>{Pn(h.url??"")},children:r("settings.providers.page.actions.open")}),s.jsx(B,{variant:"outline",size:"xs",className:"!font-normal",onClick:()=>{f(h.url??"","settings.providers.page.toast.oauthLinkCopied","settings.providers.page.toast.oauthLinkCopyFailed")},children:r("settings.providers.page.actions.copy")})]})]})]});return s.jsx("div",{className:fe("space-y-4",n),children:e.map(h=>{const w=d===h.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:h.label}),s.jsx(B,{variant:"outline",size:"xs",className:"!font-normal shrink-0",onClick:()=>N(h),disabled:C,children:r("settings.providers.page.actions.connect")})]}),w&&i.phase==="prompting"&&s.jsxs("div",{className:"space-y-3",children:[Mr(i.prompts,g).map(I),i.error&&s.jsx("p",{className:"typography-meta text-[var(--status-error)]",children:i.error}),s.jsxs("div",{className:"flex items-center gap-2",children:[s.jsx(B,{size:"xs",className:"!font-normal",onClick:m,children:r("settings.providers.page.actions.continue")}),s.jsx(B,{variant:"ghost",size:"xs",className:"!font-normal",onClick:R,children:r("settings.providers.page.actions.cancel")})]})]}),w&&i.phase==="authorizing"&&s.jsxs("p",{className:"typography-meta text-muted-foreground flex items-center gap-2",children:[s.jsx(F,{name:"loader",className:"h-3.5 w-3.5 animate-spin"}),r("settings.providers.page.auth.oauth.starting")]}),w&&i.phase==="waiting"&&s.jsxs("div",{className:"space-y-3",children:[j(i.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(F,{name:"loader",className:"h-3.5 w-3.5 animate-spin"}),r("settings.providers.page.auth.oauth.waiting")]}),s.jsx(B,{variant:"ghost",size:"xs",className:"!font-normal shrink-0",onClick:R,children:r("settings.providers.page.actions.cancel")})]}),s.jsx("p",{className:"typography-meta text-muted-foreground",children:r("settings.providers.page.auth.oauth.waitingHint")})]}),w&&i.phase==="awaitingCode"&&s.jsxs("div",{className:"space-y-3",children:[j(i.authorization),s.jsx("p",{className:"typography-meta text-muted-foreground",children:r("settings.providers.page.auth.oauth.codeHint")}),s.jsxs("div",{className:"flex items-center gap-2",children:[s.jsx(He,{value:y,onChange:O=>p(O.target.value),placeholder:r("settings.providers.page.auth.pasteAuthorizationCodePlaceholder"),className:"font-mono text-xs",disabled:i.submitting}),s.jsx(B,{size:"xs",className:"!font-normal shrink-0",onClick:A,disabled:i.submitting||y.trim().length===0,children:i.submitting?r("settings.providers.page.actions.saving"):r("settings.providers.page.actions.complete")}),s.jsx(B,{variant:"ghost",size:"xs",className:"!font-normal shrink-0",onClick:R,disabled:i.submitting,children:r("settings.providers.page.actions.cancel")})]})]}),w&&i.phase==="failed"&&s.jsxs("div",{className:"space-y-2",children:[s.jsx("p",{className:"typography-meta text-[var(--status-error)]",children:i.message}),s.jsx(B,{variant:"outline",size:"xs",className:"!font-normal",onClick:()=>N(h),children:r("settings.providers.page.actions.tryAgain")})]})]},h.index)})})},Vo=t=>Array.isArray(t?.env)&&t.env.some(e=>e.trim().length>0),Eg=t=>new Intl.NumberFormat(Sr(),{notation:"compact",compactDisplay:"short",maximumFractionDigits:1,minimumFractionDigits:0}).format(t),Bo=t=>{if(typeof t!="number"||Number.isNaN(t))return null;if(t===0)return"0";const e=Eg(t);return e.endsWith(".0")?e.slice(0,-2):e},Ea="__add_provider__",Zl=t=>typeof t=="object"&&t!==null,Ho=(t,e)=>t.map(({method:a,methodIndex:n})=>({index:n,label:a.label||a.name||e(n),prompts:a.prompts})),Dg=t=>{if(typeof t=="string")return{id:t};if(!Zl(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}},Mg=t=>{let e=[];Array.isArray(t)?e=t:Zl(t)&&(Array.isArray(t.all)?e=t.all:Array.isArray(t.providers)&&(e=t.providers));const a=e.map(r=>Dg(r)).filter(r=>!!r),n=new Set;return a.filter(r=>n.has(r.id)?!1:(n.add(r.id),!0))},Rg=()=>{const{t}=tt(),e=_s(),a=Ye(q=>Cl(q,e)),n=Ye(q=>q.selectedProviderId),r=Ye(q=>q.setSelectedProvider),i=Ye(q=>q.getModelMetadata),l=ie(q=>q.hiddenModels),g=ie(q=>q.toggleHiddenModel),c=ie(q=>q.hideAllModels),y=ie(q=>q.showAllModels),[p,b]=o.useState({}),[d,C]=o.useState(!1),[f,P]=o.useState({}),[x,N]=o.useState(null),[m,A]=o.useState(""),[R,I]=o.useState([]),[j,h]=o.useState(!1),[w,O]=o.useState(null),[T,S]=o.useState(""),[M,V]=o.useState(""),[$,k]=o.useState(!1),[W,D]=o.useState({}),[L,J]=o.useState(0),[ee,U]=o.useState(!1),[re,_]=o.useState(null),[H,z]=o.useState(null),[K,te]=o.useState(null),[Y,ne]=o.useState(null),[me,de]=o.useState(null),[xe,ae]=o.useState(null),le=n===Ea,ge=le&&T===Kn,Ae=!!(H&&n&&H===n&&!le);o.useEffect(()=>{!n&&a.length>0&&r(a[0].id)},[a,n,r]),o.useEffect(()=>{if(!n)return;let q=!0;return(async()=>{C(!0);try{const Ie=await fn.getSdkClient().provider.auth();if(Ie.error)throw new Error(`provider.auth failed: ${String(Ie.error)}`);if(!q)return;b(sg(Ie.data))}catch(Ie){if(!q)return;console.error("Failed to load provider auth methods:",Ie),E.error(t("settings.providers.page.toast.authMethodsLoadFailed"))}finally{q&&C(!1)}})(),()=>{q=!1}},[n,t]),o.useEffect(()=>{if(!eg(le))return;let q=!0;return(async()=>{h(!0),O(null);try{const Ie=await fn.getSdkClient().provider.list();if(Ie.error)throw new Error(`provider.list failed: ${String(Ie.error)}`);if(!q)return;I(Mg(Ie.data))}catch(Ie){if(!q)return;console.error("Failed to load available providers:",Ie),O(t("settings.providers.page.state.unableToLoadProviderList"))}finally{q&&h(!1)}})(),()=>{q=!1}},[le,t]);const Se=o.useMemo(()=>new Set(a.map(q=>q.id)),[a]),Ce=o.useMemo(()=>R.filter(q=>!Se.has(q.id)).sort((q,je)=>{const Ie=(q.name||q.id).toLowerCase(),Je=(je.name||je.id).toLowerCase();return Ie.localeCompare(Je)}),[R,Se]);o.useEffect(()=>{n===Ea&&T&&T!==Kn&&!Ce.some(q=>q.id===T)&&S("")},[n,T,Ce]),o.useEffect(()=>{if(n===Ea){U(!0),_(null),z(null),te(null),ne(null),de(null);return}U(!1),_(null),H&&H!==n&&(z(null),te(null),ne(null),de(null))},[n,H]),o.useEffect(()=>{if(!n||n===Ea)return;const q=W[n];if(!q)return;const je=a.find(ot=>ot.id===n),Ie=Fo({key:je?.key,authSourceExists:q.auth.exists,optionsApiKey:je?.options?.apiKey??null,envDeclared:Vo(je)}),Je=!!(je&&Ko(je,q));ig({hasCredentials:Ie,userDismissed:re===n,isEditableCustomProvider:Je})&&U(!0)},[n,W,a,re]),o.useEffect(()=>{if(!n||n===Ea)return;let q=!1;return(async()=>{try{const Ie=e?`?directory=${encodeURIComponent(e)}`:"",Je=await yt(`/api/provider/${encodeURIComponent(n)}/source${Ie}`,{method:"GET",headers:{Accept:"application/json"}}),ot=await Je.json().catch(()=>null);if(!Je.ok)throw new Error(ot?.error||t("settings.providers.page.toast.providerSourcesLoadFailed"));const st=ot?.sources??ot?.data?.sources;!q&&st&&D(mt=>({...mt,[n]:st}))}catch(Ie){q||console.error("Failed to load provider sources:",Ie)}})(),()=>{q=!0}},[n,L,e,t]);const he=o.useCallback(()=>{J(q=>q+1)},[]),_e=o.useCallback(q=>{D(je=>{const Ie=je[q];return{...je,[q]:{auth:{exists:!0,path:Ie?.auth.path??null},user:Ie?.user??{exists:!1,path:null},project:Ie?.project??{exists:!1,path:null},...Ie?.custom?{custom:Ie.custom}:{}}}}),_(null),U(!1),r(q),he()},[he,r]),Ue=o.useCallback(async(q,je)=>{try{return await Il({scopes:[q],mode:"active"}),"reloaded"}catch(Ie){if(Ie?.requiresManualRestart===!0)return je&&$n(q,{id:je}),"manual-restart";throw Ie}},[]),ke=a.find(q=>q.id===n),Oe=n?W[n]:void 0,Ve=async q=>{const je=f[q]?.trim()??"";if(!je){E.error(t("settings.providers.page.toast.apiKeyRequired"));return}const Ie=`api:${q}`;N(Ie);try{if((await fn.getSdkClient().auth.set({providerID:q,auth:{type:"api",key:je}})).error)throw new Error(t("settings.providers.page.toast.apiKeySaveFailed"));E.success(t("settings.providers.page.toast.apiKeySaved")),P(ot=>({...ot,[q]:""})),await Ue("providers",q),_e(q)}catch(Je){console.error("Failed to save API key:",Je),E.error(t("settings.providers.page.toast.apiKeySaveFailed"))}finally{N(null)}},We=async q=>{const je=`custom:${q.providerID}`;N(je),ae(q.providerID),de(null);try{const Ie=hg(q);if(Ie&&(await fn.getSdkClient().auth.set(Ie)).error)throw new Error(t("settings.providers.page.toast.apiKeySaveFailed"));const Je=fg(q,{scope:H?Y??zo(W[H]):"user"}),ot=await yt(`/api/provider${e?`?directory=${encodeURIComponent(e)}`:""}`,{method:"PUT",headers:{Accept:"application/json","Content-Type":"application/json"},body:JSON.stringify(Je)}),st=await ot.json().catch(()=>null);if(!ot.ok)throw Ie&&de(t("settings.providers.page.custom.authFailure.configAfterAuth")),new Error(st?.error||t("settings.providers.page.toast.customProviderSaveFailed"));E.success(t("settings.providers.page.toast.customProviderSaved",{provider:q.name})),S(""),z(null),te(null),ne(null),de(null),ae(null),await Ue("providers",q.providerID),_e(q.providerID)}catch(Ie){console.error("Failed to save custom provider:",Ie),E.error(Ie instanceof Error&&Ie.message?Ie.message:t("settings.providers.page.toast.customProviderSaveFailed"))}finally{N(null)}},ve=q=>t("settings.providers.page.auth.oauthMethodFallback",{index:String(q+1)}),Z=q=>{U(!1),ng(q)&&$n("providers",{id:q}),_e(q)},se=async q=>{const je=`disconnect:${q}`;N(je);try{const Ie=await yt(`/api/provider/${encodeURIComponent(q)}/auth?scope=all${e?`&directory=${encodeURIComponent(e)}`:""}`,{method:"DELETE",headers:{Accept:"application/json"}}),Je=await Ie.json().catch(()=>null);if(!Ie.ok)throw new Error(Je?.error||t("settings.providers.page.toast.providerDisconnectFailed"));E.success(t("settings.providers.page.toast.providerDisconnected")),await Ue("providers",q),_(null),he()}catch(Ie){console.error("Failed to disconnect provider:",Ie),E.error(t("settings.providers.page.toast.providerDisconnectFailed"))}finally{N(null)}},ye=async q=>{q&&(await se(q),z(null),te(null),ne(null),de(null),ae(null),S(""))};if(!le&&a.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(F,{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(le)return s.jsxs(es,{title:t("settings.providers.page.connect.title"),showSaveStatus:!1,children:[s.jsx(ze,{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")}),j?s.jsx("p",{className:"typography-meta text-muted-foreground",children:t("settings.providers.page.state.loading")}):w?s.jsx("p",{className:"typography-meta text-muted-foreground",children:w}):s.jsxs(cn,{open:$,onOpenChange:q=>{k(q),q||V("")},children:[s.jsx(on,{asChild:!0,children:s.jsxs("button",{type:"button",className:In,children:[s.jsxs("span",{className:"flex items-center gap-2 min-w-0",children:[T&&T!==Kn?s.jsx(Un,{providerId:T,className:"h-3.5 w-3.5 flex-shrink-0"}):null,s.jsx("span",{className:fe("truncate typography-ui-label font-normal",T?"text-foreground":"text-muted-foreground"),children:T===Kn?t("settings.providers.page.custom.optionLabel"):T?Ce.find(q=>q.id===T)?.name||T:t("settings.providers.page.connect.selectProviderPlaceholder")})]}),s.jsx(F,{name:"arrow-down-s",className:"h-4 w-4 flex-shrink-0 text-muted-foreground/50"})]})}),s.jsxs(ln,{align:"start",className:"w-[280px] p-0",onCloseAutoFocus:q=>q.preventDefault(),children:[s.jsxs("div",{className:"flex items-center gap-2 border-b border-[var(--surface-subtle)] px-3 py-2",onKeyDown:q=>q.stopPropagation(),children:[s.jsx(F,{name:"search",className:"h-4 w-4 text-muted-foreground"}),s.jsx("input",{type:"text",value:M,onChange:q=>V(q.target.value),onKeyDown:q=>q.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(vs,{outerClassName:"max-h-[240px]",className:"p-1",children:(()=>{const q=t("settings.providers.page.custom.optionLabel"),je=Oc([q,"other","custom"],M),Ie=ki(Ce,M,Je=>[Je.name||Je.id,Je.id]);return Ie.length===0&&!je?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:[Ie.map(Je=>s.jsxs(dn,{onSelect:()=>{S(Je.id),k(!1),V("")},className:"flex items-center justify-between",children:[s.jsxs("span",{className:"flex items-center gap-2 min-w-0",children:[s.jsx(Un,{providerId:Je.id,className:"h-4 w-4 flex-shrink-0"}),s.jsx("span",{className:"truncate",children:Je.name||Je.id})]}),T===Je.id&&s.jsx(F,{name:"check",className:"h-4 w-4 text-[var(--primary-base)]"})]},Je.id)),je?s.jsxs(dn,{onSelect:()=>{S(Kn),k(!1),V("")},className:"flex items-center justify-between",children:[s.jsxs("span",{className:"flex items-center gap-2 min-w-0",children:[s.jsx(F,{name:"add",className:"h-4 w-4 flex-shrink-0"}),s.jsx("span",{className:"truncate",children:q})]}),T===Kn&&s.jsx(F,{name:"check",className:"h-4 w-4 text-[var(--primary-base)]"})]},Kn):null]})})()})]})]})]})}),ge?s.jsx(Uo,{mode:"create",existingProviderIDs:Se,busy:x?.startsWith("custom:")??!1,authFailureHint:me,onCancel:()=>{S(""),de(null),ae(null)},onDisconnect:me&&xe?()=>{ye(xe)}:void 0,onSubmit:We}):T?s.jsx(ze,{title:t("settings.providers.page.auth.title"),settingsItem:"providers.auth",contentClassName:"space-y-4",children:d?s.jsx("p",{className:"typography-meta text-muted-foreground",children:t("settings.providers.page.auth.loadingMethods")}):s.jsx(s.Fragment,{children:(()=>{const q=p[T]??[],je=Ho(Oo(q),ve),Ie=Lo(q);return s.jsxs(s.Fragment,{children:[Ie?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(Jt,{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:f[T]??"",onChange:Je=>P(ot=>({...ot,[T]:Je.target.value})),placeholder:t("settings.providers.page.auth.apiKeyPlaceholder"),className:"flex-1 font-mono text-xs"}),s.jsx(B,{size:"xs",className:"!font-normal shrink-0",onClick:()=>Ve(T),disabled:x===`api:${T}`,children:x===`api:${T}`?t("settings.providers.page.actions.saving"):t("settings.providers.page.actions.saveKey")})]})]}):null,je.length>0?s.jsx($o,{providerId:T,methods:je,onConnected:()=>Z(T),className:fe(Ie&&"border-t border-[var(--surface-subtle)] pt-2")},T):null]})})()})}):null]});if(!ke)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(F,{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 be=Array.isArray(ke.models)?ke.models:[],Re=p[ke.id]??[],Fe=Ho(Oo(Re),ve),Ke=Lo(Re),Ee=!!Oe,we=Ee&&Ko(ke,Oe),Ze=Fo({key:ke.key,authSourceExists:Oe?.auth.exists,optionsApiKey:ke.options?.apiKey??null,envDeclared:Vo(ke)}),pe=tg(Ee,Ze,we),Ne=ag({modelCount:be.length,sourcesLoaded:Ee,hasCredentials:Ze,isEditableCustomProvider:we}),Le=!Ke&&Fe.length>0?t("settings.providers.page.auth.useReconnectHint"):t("settings.providers.page.auth.incompleteHint"),Xe=ki(be,m,q=>[typeof q?.name=="string"?q.name:"",typeof q?.id=="string"?q.id:""]);return Ae&&we&&K?s.jsx(es,{title:ke.name||ke.id,titleLeading:s.jsx(Un,{providerId:ke.id,className:"h-5 w-5 shrink-0"}),description:s.jsx("span",{className:"font-mono typography-settings-description text-muted-foreground",children:ke.id}),showSaveStatus:!1,children:s.jsx(Uo,{mode:"edit",existingProviderIDs:Se,initialValues:K,allowExistingAuth:Ze||!Ee,busy:x?.startsWith("custom:")??!1,authFailureHint:me,onCancel:()=>{z(null),te(null),ne(null),de(null),ae(null)},onDisconnect:()=>{ye(ke.id)},onSubmit:We})}):s.jsxs(es,{title:ke.name||ke.id,titleLeading:s.jsx(Un,{providerId:ke.id,className:"h-5 w-5 shrink-0"}),description:s.jsx("span",{className:"font-mono typography-settings-description text-muted-foreground",children:ke.id}),showSaveStatus:!1,children:[s.jsx(ze,{title:t("settings.providers.page.auth.title"),divider:!1,headerAction:s.jsxs("div",{className:"flex items-center gap-1",children:[we?s.jsx(B,{variant:"outline",size:"xs",className:"!font-normal",onClick:()=>{de(null),te(mg(ke)),ne(zo(Oe)),z(ke.id)},children:t("settings.providers.page.actions.edit")}):null,s.jsx(B,{variant:"outline",size:"xs",className:"!font-normal",onClick:()=>{const q=!ee;U(q),_(q?null:ke.id)},children:t(ee?"settings.providers.page.actions.hide":"settings.providers.page.actions.reconnect")})]}),settingsItem:"providers.auth",children:ee?d?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:[Ke?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(Jt,{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:f[ke.id]??"",onChange:q=>P(je=>({...je,[ke.id]:q.target.value})),placeholder:t("settings.providers.page.auth.apiKeyPlaceholder"),className:"flex-1 font-mono text-xs"}),s.jsx(B,{size:"xs",className:"!font-normal shrink-0",onClick:()=>Ve(ke.id),disabled:x===`api:${ke.id}`,children:x===`api:${ke.id}`?t("settings.providers.page.actions.saving"):t("settings.providers.page.actions.saveKey")})]})]}):null,Fe.length>0&&s.jsx($o,{providerId:ke.id,methods:Fe,onConnected:()=>Z(ke.id),className:fe(Ke&&"border-t border-[var(--surface-subtle)] pt-2")},ke.id)]}):pe?s.jsxs("div",{className:"flex items-center gap-1.5 py-1.5",children:[s.jsx(F,{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(Jt,{children:Le})]}):s.jsxs("div",{className:"flex items-center gap-1.5 py-1.5",children:[s.jsx(F,{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(Jt,{children:t("settings.providers.page.auth.useReconnectHint")})]})}),s.jsx(ze,{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:Oe&&(Oe.auth.exists||Oe.user.exists||Oe.project.exists||Oe.custom?.exists)?s.jsxs("span",{className:"typography-meta text-muted-foreground",children:[t("settings.providers.page.connectionDetails.configuredIn")," ",[Oe.auth.exists?t("settings.providers.page.connectionDetails.source.authCredentials"):null,Oe.user.exists?t("settings.providers.page.connectionDetails.source.userConfig"):null,Oe.project.exists?t("settings.providers.page.connectionDetails.source.projectConfig"):null,Oe.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(B,{variant:"ghost",size:"xs",className:"!font-normal text-[var(--status-error)] hover:text-[var(--status-error)]",onClick:()=>se(ke.id),disabled:x===`disconnect:${ke.id}`,children:x===`disconnect:${ke.id}`?t("settings.providers.page.actions.disconnecting"):t("settings.providers.page.actions.disconnect")})]})}),Ne?s.jsxs(ze,{title:t("settings.providers.page.models.title"),titleAccessory:s.jsxs("span",{className:"typography-micro text-muted-foreground font-normal",children:["(",be.length,")"]}),headerAction:s.jsxs("div",{className:"flex items-center gap-1",children:[s.jsx(B,{variant:"outline",size:"xs",className:"!font-normal",onClick:()=>{const q=be.map(je=>typeof je?.id=="string"?je.id:"").filter(je=>je.length>0);c(ke.id,q)},children:t("settings.providers.page.actions.hideAll")}),s.jsx(B,{variant:"outline",size:"xs",className:"!font-normal",onClick:()=>y(ke.id),children:t("settings.providers.page.actions.showAll")})]}),settingsItem:"providers.models",children:[s.jsxs("div",{className:"relative mb-2",children:[s.jsx(F,{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:m,onChange:q=>A(q.target.value),placeholder:t("settings.providers.page.models.filterPlaceholder"),className:"h-7 pl-8 w-full"})]}),Xe.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:Xe.map(q=>{const je=typeof q?.id=="string"?q.id:"",Ie=typeof q?.name=="string"?q.name:je,Je=je?i(ke.id,je):void 0,ot=l.some(G=>G.providerID===ke.id&&G.modelID===je),st=Bo(Je?.limit?.context),mt=Bo(Je?.limit?.output),vt=[];return Je?.tool_call&&vt.push({key:"tools",icon:"tools",label:t("settings.providers.page.models.capability.toolCalling")}),Je?.reasoning&&vt.push({key:"reasoning",icon:"brain-ai-3",label:t("settings.providers.page.models.capability.reasoning")}),Je?.attachment&&vt.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:fe("flex items-center gap-3",ot&&"opacity-50"),children:[s.jsx("span",{className:"typography-meta font-medium text-foreground truncate flex-1 min-w-0",children:Ie}),s.jsxs("div",{className:"flex items-center gap-2 flex-shrink-0",children:[(st||mt)&&s.jsxs("span",{className:"typography-micro text-muted-foreground flex-shrink-0 bg-[var(--surface-muted)] px-1.5 py-0.5 rounded",children:[st?`${st} ${t("settings.providers.page.models.tokenBadge.context")}`:"",st&&mt?" · ":"",mt?`${mt} ${t("settings.providers.page.models.tokenBadge.output")}`:""]}),vt.length>0&&s.jsx("div",{className:"flex items-center gap-1 flex-shrink-0",children:vt.map(({key:G,icon:Ge,label:nt})=>s.jsx("span",{className:"flex h-5 w-5 rounded items-center justify-center text-muted-foreground bg-[var(--surface-muted)]",title:nt,"aria-label":nt,children:s.jsx(F,{name:Ge,className:"h-3 w-3"})},G))}),s.jsx("button",{type:"button",onClick:()=>g(ke.id,je),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(ot?"settings.providers.page.models.actions.showModelInSelectors":"settings.providers.page.models.actions.hideModelFromSelectors"),"aria-label":t(ot?"settings.providers.page.models.actions.showModel":"settings.providers.page.models.actions.hideModel"),children:ot?s.jsx(F,{name:"eye-off",className:"h-3.5 w-3.5"}):s.jsx(F,{name:"eye",className:"h-3.5 w-3.5"})})]})]})},je)})})]}):null]})},Lg=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)},Og=t=>{const e=ut.c(75),{onItemSelect:a}=t,{t:n}=tt(),r=Zt(Fg),i=Zt(Kg),l=Zt(zg),g=Zt(Ug),c=Zt(_g),y=Zt($g),p=Zt(Vg),b=Zt(Bg);let d,C;e[0]!==b?(d=()=>{b()},C=[b],e[0]=b,e[1]=d,e[2]=C):(d=e[1],C=e[2]),o.useEffect(d,C);const f=Hg;let P;e[3]!==p?(P=ne=>{ne!=="usage"&&ne!=="remaining"||(p(ne),f({usageDisplayMode:ne}))},e[3]=p,e[4]=P):P=e[4];const x=P;let N;e[5]===Symbol.for("react.memo_cache_sentinel")?(N=fe("flex h-full flex-col","bg-background"),e[5]=N):N=e[5];let m;e[6]!==n?(m=n("settings.usage.sidebar.title"),e[6]=n,e[7]=m):m=e[7];let A;e[8]!==m?(A=s.jsx("h2",{className:`${un} mb-3`,children:m}),e[8]=m,e[9]=A):A=e[9];let R;e[10]!==n?(R=n("settings.usage.sidebar.total",{count:Ni.length}),e[10]=n,e[11]=R):R=e[11];let I;e[12]!==R?(I=s.jsx("span",{className:"typography-meta text-muted-foreground",children:R}),e[12]=R,e[13]=I):I=e[13];let j;e[14]!==g?(j=()=>g(),e[14]=g,e[15]=j):j=e[15];let h;e[16]!==n?(h=n("settings.usage.sidebar.actions.refreshAria"),e[16]=n,e[17]=h):h=e[17];let w;e[18]!==n?(w=n("settings.usage.sidebar.actions.refreshTitle"),e[18]=n,e[19]=w):w=e[19];const O=c&&"animate-spin";let T;e[20]!==O?(T=fe("h-3.5 w-3.5",O),e[20]=O,e[21]=T):T=e[21];let S;e[22]!==T?(S=s.jsx(F,{name:"refresh",className:T}),e[22]=T,e[23]=S):S=e[23];let M;e[24]!==c||e[25]!==h||e[26]!==w||e[27]!==S||e[28]!==j?(M=s.jsx("div",{className:"flex items-center gap-2",children:s.jsx(B,{size:"sm",variant:"ghost",className:"h-7 w-7 px-0 text-muted-foreground",onClick:j,"aria-label":h,title:w,disabled:c,children:S})}),e[24]=c,e[25]=h,e[26]=w,e[27]=S,e[28]=j,e[29]=M):M=e[29];let V;e[30]!==M||e[31]!==I?(V=s.jsxs("div",{className:"flex items-center justify-between gap-2",children:[I,M]}),e[30]=M,e[31]=I,e[32]=V):V=e[32];let $;e[33]!==n?($=n("settings.usage.sidebar.field.display"),e[33]=n,e[34]=$):$=e[34];let k;e[35]!==$?(k=s.jsx("span",{className:"typography-micro text-muted-foreground",children:$}),e[35]=$,e[36]=k):k=e[36];let W;e[37]!==n?(W=n("settings.usage.sidebar.field.displayModePlaceholder"),e[37]=n,e[38]=W):W=e[38];let D;e[39]!==W?(D=s.jsx(Ct,{className:"w-fit",children:s.jsx(Mt,{placeholder:W})}),e[39]=W,e[40]=D):D=e[40];let L;e[41]!==n?(L=n("settings.usage.sidebar.field.displayModeUsage"),e[41]=n,e[42]=L):L=e[42];let J;e[43]!==L?(J=s.jsx(at,{value:"usage",children:L}),e[43]=L,e[44]=J):J=e[44];let ee;e[45]!==n?(ee=n("settings.usage.sidebar.field.displayModeRemaining"),e[45]=n,e[46]=ee):ee=e[46];let U;e[47]!==ee?(U=s.jsx(at,{value:"remaining",children:ee}),e[47]=ee,e[48]=U):U=e[48];let re;e[49]!==J||e[50]!==U?(re=s.jsxs(It,{children:[J,U]}),e[49]=J,e[50]=U,e[51]=re):re=e[51];let _;e[52]!==x||e[53]!==D||e[54]!==re||e[55]!==y?(_=s.jsxs(St,{value:y,onValueChange:x,children:[D,re]}),e[52]=x,e[53]=D,e[54]=re,e[55]=y,e[56]=_):_=e[56];let H;e[57]!==k||e[58]!==_?(H=s.jsxs("div",{className:"mt-2 flex items-center justify-between gap-2",children:[k,_]}),e[57]=k,e[58]=_,e[59]=H):H=e[59];let z;e[60]!==V||e[61]!==H||e[62]!==A?(z=s.jsxs("div",{className:"border-b px-3 pt-4 pb-3",children:[A,V,H]}),e[60]=V,e[61]=H,e[62]=A,e[63]=z):z=e[63];let K;e[64]!==a||e[65]!==r||e[66]!==i||e[67]!==l||e[68]!==n?(K=Ni.map(ne=>{const me=r.find(Ae=>Ae.providerId===ne.id),de=Lg(me?.usage),xe=Pl(de),ae=ne.id===i,le=me?.configured,ge=le?xe==="critical"?{backgroundColor:"var(--status-error)"}:xe==="warn"?{backgroundColor:"var(--status-warning)"}:{backgroundColor:"var(--status-success)"}:{backgroundColor:"var(--surface-muted-foreground)",opacity:.4};return s.jsx("div",{className:fe("group relative flex items-center rounded-md px-1.5 py-1 transition-all duration-200",ae?"bg-interactive-selection":"hover:bg-interactive-hover"),children:s.jsxs("button",{type:"button",onClick:()=>{l(ne.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(Un,{providerId:ne.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:ne.name}),le===!1&&s.jsx("span",{className:"typography-micro text-muted-foreground/60 flex-shrink-0",children:n("settings.usage.sidebar.status.notSet")})]})},ne.id)}),e[64]=a,e[65]=r,e[66]=i,e[67]=l,e[68]=n,e[69]=K):K=e[69];let te;e[70]!==K?(te=s.jsx(vs,{outerClassName:"flex-1 min-h-0",className:"space-y-1 px-3 py-2 overflow-x-hidden",children:K}),e[70]=K,e[71]=te):te=e[71];let Y;return e[72]!==z||e[73]!==te?(Y=s.jsxs("div",{className:N,children:[z,te]}),e[72]=z,e[73]=te,e[74]=Y):Y=e[74],Y};function Fg(t){return t.results}function Kg(t){return t.selectedProviderId}function zg(t){return t.setSelectedProvider}function Ug(t){return t.fetchAllQuotas}function _g(t){return t.isLoading}function $g(t){return t.displayMode}function Vg(t){return t.setDisplayMode}function Bg(t){return t.loadSettings}async function Hg(t){try{await pt(t)}catch(e){console.warn("Failed to save usage settings:",e)}}const Wg=t=>{const e=ut.c(17),{percent:a,tonePercent:n,className:r}=t;let i;e[0]!==a?(i=Fc(a)??0,e[0]=a,e[1]=i):i=e[1];const l=i,g=n??a;let c;e[2]!==g?(c=Pl(g),e[2]=g,e[3]=c):c=e[3];const y=c;let p;e[4]!==y?(p=y==="critical"?{backgroundColor:"var(--status-error)"}:y==="warn"?{backgroundColor:"var(--status-warning)"}:{backgroundColor:"var(--status-success)"},e[4]=y,e[5]=p):p=e[5];const b=p;let d;e[6]!==r?(d=fe("relative h-2.5 rounded-full bg-[var(--interactive-border)] overflow-hidden",r),e[6]=r,e[7]=d):d=e[7];const C=`${l}%`;let f;e[8]!==b||e[9]!==C?(f={...b,width:C},e[8]=b,e[9]=C,e[10]=f):f=e[10];let P;e[11]!==l||e[12]!==f?(P=s.jsx("div",{className:"h-full transition-all duration-300",style:f,role:"progressbar","aria-valuenow":l,"aria-valuemin":0,"aria-valuemax":100}),e[11]=l,e[12]=f,e[13]=P):P=e[13];let x;return e[14]!==d||e[15]!==P?(x=s.jsx("div",{className:d,children:P}),e[14]=d,e[15]=P,e[16]=x):x=e[16],x},tr=t=>{const e=ut.c(44),{title:a,window:n,subtitle:r,showToggle:i,toggleEnabled:l,onToggle:g}=t,c=i===void 0?!1:i,y=l===void 0?!1:l,p=Zt(Gg),b=ie(qg),d=p==="remaining"?n.remainingPercent:n.usedPercent,C=p==="remaining"?"remaining":"used";let f;e[0]!==d||e[1]!==n.valueLabel?(f=Kc(n.valueLabel,d),e[0]=d,e[1]=n.valueLabel,e[2]=f):f=e[2];const P=f,x=n.resetAfterFormatted??n.resetAtFormatted;let N;e[3]!==x||e[4]!==b||e[5]!==n.resetAt?(N=zc(n.resetAt,x,b),e[3]=x,e[4]=b,e[5]=n.resetAt,e[6]=N):N=e[6];const m=N;let A;e[7]!==a?(A=Uc(a),e[7]=a,e[8]=A):A=e[8];const R=A;let I;e[9]!==g||e[10]!==c||e[11]!==y?(I=c&&s.jsx(cr,{checked:y,onChange:ee=>g?.(ee),ariaLabel:"Show in dropdown"}),e[9]=g,e[10]=c,e[11]=y,e[12]=I):I=e[12];let j;e[13]!==R?(j=s.jsx("span",{className:"typography-ui-label text-foreground truncate",children:R}),e[13]=R,e[14]=j):j=e[14];let h;e[15]!==r?(h=r&&s.jsx("span",{className:"typography-meta text-muted-foreground truncate",children:r}),e[15]=r,e[16]=h):h=e[16];let w;e[17]!==j||e[18]!==h?(w=s.jsxs("div",{className:"min-w-0 flex flex-col",children:[j,h]}),e[17]=j,e[18]=h,e[19]=w):w=e[19];let O;e[20]!==w||e[21]!==I?(O=s.jsxs("div",{className:"min-w-0 flex-1 flex items-center gap-2",children:[I,w]}),e[20]=w,e[21]=I,e[22]=O):O=e[22];const T=P==="-"?"":P;let S;e[23]!==T?(S=s.jsx("div",{className:"typography-ui-label text-foreground tabular-nums flex items-center justify-end",children:T}),e[23]=T,e[24]=S):S=e[24];let M;e[25]!==O||e[26]!==S?(M=s.jsxs("div",{className:"flex items-center justify-between gap-3",children:[O,S]}),e[25]=O,e[26]=S,e[27]=M):M=e[27];let V;e[28]!==d||e[29]!==n.usedPercent?(V=s.jsx(Wg,{percent:d,tonePercent:n.usedPercent,className:"h-1.5"}),e[28]=d,e[29]=n.usedPercent,e[30]=V):V=e[30];const $=m?`Resets ${m}`:"";let k;e[31]!==$?(k=s.jsx("span",{className:"typography-micro text-muted-foreground",children:$}),e[31]=$,e[32]=k):k=e[32];let W;e[33]!==C?(W=s.jsx("span",{className:"typography-micro text-muted-foreground",children:C}),e[33]=C,e[34]=W):W=e[34];let D;e[35]!==k||e[36]!==W?(D=s.jsxs("div",{className:"mt-1 flex items-center justify-between",children:[k,W]}),e[35]=k,e[36]=W,e[37]=D):D=e[37];let L;e[38]!==V||e[39]!==D?(L=s.jsxs("div",{className:"mt-2.5",children:[V,D]}),e[38]=V,e[39]=D,e[40]=L):L=e[40];let J;return e[41]!==M||e[42]!==L?(J=s.jsxs("div",{className:"py-3",children:[M,L]}),e[41]=M,e[42]=L,e[43]=J):J=e[43],J};function Gg(t){return t.displayMode}function qg(t){return t.timeFormatPreference}const Jg=`ssh exe.dev "ssh-key generate-api-key --label=aiworker --exp=30d --cmds='billing credits usage'"`,Qg=({providerId:t,providerName:e})=>{const{t:a}=tt(),[n,r]=o.useState(null),[i,l]=o.useState({}),[g,c]=o.useState(!1),y=`/api/quota/credentials/${t}`;o.useEffect(()=>{yt(y).then(async d=>{if(!d.ok)throw new Error;const C=await d.json();r(C),l({})}).catch(()=>r({configured:!1}))},[y]);const p=async(d,C,f)=>{c(!0);try{const P=await yt(d,{method:C,headers:f?{"Content-Type":"application/json"}:void 0,body:f?JSON.stringify(f):void 0}),x=await P.json().catch(()=>null);if(!P.ok)throw new Error(x?.error);x?.configured!==void 0&&r(x),l({}),E.success(a("settings.providers.page.quotaCredentials.saved",{provider:e}))}catch(P){E.error(P instanceof Error&&P.message?P.message:a("settings.providers.page.openCodeGo.saveFailed"))}finally{c(!1)}},b=(d,C,f)=>s.jsxs("label",{className:"block typography-ui-label text-foreground",children:[C,s.jsx(He,{className:"mt-1 h-7 font-mono text-xs",type:"password",autoComplete:"off",value:i[d]??"",onChange:P=>l(x=>({...x,[d]:P.target.value})),placeholder:n?.secretMasked??f})]});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==="exe-dev"&&s.jsxs("div",{className:"space-y-1.5",children:[s.jsx("p",{className:"typography-meta text-muted-foreground",children:a("settings.providers.page.quotaCredentials.exeDevTokenInstructions")}),s.jsx("code",{className:"typography-code block whitespace-pre-wrap break-all rounded bg-muted/50 px-2 py-1.5 text-xs text-foreground",children:Jg})]}),t==="ollama-cloud"&&b("cookie",a("settings.providers.page.openCodeGo.authCookie"),"aid=...; __Secure-session=..."),t==="exe-dev"&&b("usageToken",a("settings.providers.page.quotaCredentials.usageToken"),a("settings.providers.page.quotaCredentials.tokenPlaceholder")),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(B,{size:"xs",disabled:g,onClick:()=>p(y,"PUT",i),children:n?.configured?a("settings.providers.page.openCodeGo.replace"):a("settings.providers.page.openCodeGo.save")}),n?.configured&&s.jsx(B,{variant:"outline",size:"xs",disabled:g,onClick:()=>p(`${y}/validate`,"POST"),children:a("settings.providers.page.openCodeGo.validate")}),t==="cursor"&&s.jsx(B,{variant:"outline",size:"xs",disabled:g,onClick:()=>p(`${y}/import`,"POST"),children:a("settings.providers.page.actions.connect")}),n?.configured&&s.jsx(B,{variant:"destructive",size:"xs",disabled:g,onClick:()=>p(y,"DELETE"),children:a("settings.providers.page.openCodeGo.delete")})]})]})]})},Wo=(t,e)=>{if(!t)return"-";try{return Al(t,e,{fallback:"-"})}catch{return"-"}},Yg=()=>{const{t}=tt(),e=ie(D=>D.timeFormatPreference),a=Zt(D=>D.results),n=Zt(D=>D.selectedProviderId),r=Zt(D=>D.setSelectedProvider),i=Zt(D=>D.loadSettings),l=Zt(D=>D.fetchAllQuotas),g=Zt(D=>D.isLoading),c=Zt(D=>D.lastUpdated),y=Zt(D=>D.error),p=Zt(D=>D.refreshErrors),b=Zt(D=>D.dropdownProviderIds),d=Zt(D=>D.setDropdownProviderIds),C=Zt(D=>D.selectedModels),f=Zt(D=>D.toggleModelSelected),P=Zt(D=>D.applyDefaultSelections);_c(),o.useEffect(()=>{i(),l()},[i,l]),o.useEffect(()=>{if(n||a.length===0)return;const D=a.find(L=>L.configured)?.providerId;r(D??Ni[0]?.id??null)},[a,n,r]);const x=a.find(D=>D.providerId===n)??null,m=Ni.find(D=>D.id===n)?.name??n??t("settings.usage.sidebar.title"),A=x?.usage,R=n?p[n]:void 0,I=R?A?t("header.services.usageRefreshFailedStale",{error:R}):R:x?.configured&&!x.ok?x.error:null,j=n?b.includes(n):!1,h=n==="exe-dev"||n==="ollama-cloud"||n==="cursor",w=o.useCallback(D=>{if(!n)return;const L=D?Array.from(new Set([...b,n])):b.filter(J=>J!==n);d(L),pt({usageDropdownProviders:L})},[b,n,d]),O=o.useMemo(()=>A?.models?Object.entries(A.models).map(([D,L])=>({name:D,windows:L})).filter(D=>Object.keys(D.windows.windows).length>0):[],[A?.models]);o.useEffect(()=>{n&&O.length>0&&P(n,O.map(D=>D.name))},[n,O,P]);const T=o.useMemo(()=>!n||O.length===0?new Map:$c(O,D=>D.name,n),[O,n]),S=o.useMemo(()=>{if(!n)return[];const D=Bc(n);return Vc(D)},[n]),[M,V]=o.useState(()=>({})),$=o.useCallback(D=>{V(L=>({...L,[D]:!L[D]}))},[]),k=o.useCallback(D=>{if(!n)return;f(n,D);const L=C[n]??[],ee=L.includes(D)?L.filter(re=>re!==D):[...L,D],U={...C,[n]:ee};pt({usageSelectedModels:U})},[n,C,f]),W=n?C[n]??[]:[];return n?s.jsxs(es,{title:t("settings.usage.page.header.providerUsage",{provider:m}),titleLeading:s.jsx(Un,{providerId:n,className:"h-5 w-5 shrink-0"}),description:g?s.jsx("span",{className:"animate-pulse typography-settings-description text-muted-foreground",children:t("settings.usage.page.header.refreshing")}):x?.planLabel?t("settings.usage.page.header.lastUpdatedWithPlan",{plan:x.planLabel,time:Wo(c,e)}):t("settings.usage.page.header.lastUpdated",{time:Wo(c,e)}),showSaveStatus:!0,children:[s.jsx(ze,{divider:!1,settingsItem:"usage.work-status-panel",children:s.jsx(dt,{checked:j,onChange:w,label:t("settings.usage.page.options.showInWorkStatus"),ariaLabel:t("settings.usage.page.options.showInWorkStatusAria"),info:t("settings.usage.page.options.showInWorkStatusTooltip")})}),!x&&s.jsx("p",{className:"typography-ui-label text-foreground pb-8",children:t("settings.usage.page.state.noData")}),(y||I)&&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:I??y})]}),x&&!x.configured&&!h&&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==="exe-dev"||n==="ollama-cloud"||n==="cursor")&&s.jsx(Qg,{providerId:n,providerName:m}),A?.windows&&Object.keys(A.windows).length>0&&s.jsx(ze,{settingsItem:"usage.model-quotas",children:s.jsx("div",{className:"divide-y divide-[var(--surface-subtle)]",children:Object.entries(A.windows).map(([D,L])=>s.jsx(tr,{title:D,window:L},D))})}),O.length>0&&s.jsxs(ze,{title:t("settings.usage.page.section.modelQuotas"),contentClassName:"space-y-3",children:[S.map(D=>{const L=T.get(D.id)??[];if(L.length===0)return null;const J=M[D.id]??!1;return s.jsx("section",{className:"p-2",children:s.jsxs(An,{open:!J,onOpenChange:()=>$(D.id),children:[s.jsxs(Tn,{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:D.label}),s.jsxs("span",{className:"typography-micro text-muted-foreground",children:["(",L.length,")"]})]}),J?s.jsx(F,{name:"arrow-right-s",className:"h-4 w-4 text-muted-foreground group-hover:text-foreground transition-colors"}):s.jsx(F,{name:"arrow-down-s",className:"h-4 w-4 text-muted-foreground group-hover:text-foreground transition-colors"})]}),s.jsx(En,{children:s.jsx("div",{className:"divide-y divide-[var(--surface-subtle)] mt-1",children:L.map(ee=>{const U=Object.entries(ee.windows.windows);if(U.length===0)return null;const[re,_]=U[0],H=W.includes(ee.name);return s.jsx(tr,{title:re,subtitle:Ur(ee.name),window:_,showToggle:!0,toggleEnabled:H,onToggle:()=>k(ee.name)},ee.name)})})})]})},D.id)}),(()=>{const D=T.get(null)??[];if(D.length===0)return null;const L=M.other??!1;return s.jsx("section",{className:"p-2",children:s.jsxs(An,{open:!L,onOpenChange:()=>$("other"),children:[s.jsxs(Tn,{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:["(",D.length,")"]})]}),L?s.jsx(F,{name:"arrow-right-s",className:"h-4 w-4 text-muted-foreground group-hover:text-foreground transition-colors"}):s.jsx(F,{name:"arrow-down-s",className:"h-4 w-4 text-muted-foreground group-hover:text-foreground transition-colors"})]}),s.jsx(En,{children:s.jsx("div",{className:"divide-y divide-[var(--surface-subtle)] mt-1",children:D.map(J=>{const ee=Object.entries(J.windows.windows);if(ee.length===0)return null;const[U,re]=ee[0],_=W.includes(J.name);return s.jsx(tr,{title:U,subtitle:Ur(J.name),window:re,showToggle:!0,toggleEnabled:_,onToggle:()=>k(J.name)},J.name)})})})]})})})()]}),x?.configured&&A&&Object.keys(A.windows??{}).length===0&&O.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")})})},Zg="git.commit.generate",xr=Kl(t=>({selectedPromptId:Zg,setSelectedPromptId:e=>{t(a=>a.selectedPromptId===e?a:{selectedPromptId:e})}})),Xg=t=>{const e=ut.c(24),{onItemSelect:a}=t,{t:n}=tt(),r=xr(eh),i=xr(th);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 g;e[1]===Symbol.for("react.memo_cache_sentinel")?(g={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]=g):g=e[1];let c;e[2]===Symbol.for("react.memo_cache_sentinel")?(c={groupKey:"settings.magicPrompts.sidebar.group.linear",items:[{id:"linear.issue.review",titleKey:"settings.magicPrompts.sidebar.item.linearIssueReview"}]},e[2]=c):c=e[2];let y;e[3]===Symbol.for("react.memo_cache_sentinel")?(y={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[3]=y):y=e[3];let p;e[4]===Symbol.for("react.memo_cache_sentinel")?(p=[l,g,c,y,{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[4]=p):p=e[4];const b=p;let d;e[5]!==n?(d=n("settings.magicPrompts.sidebar.title"),e[5]=n,e[6]=d):d=e[6];let C;e[7]!==d?(C=s.jsx("h2",{className:un,children:d}),e[7]=d,e[8]=C):C=e[8];let f;e[9]!==n?(f=n("settings.magicPrompts.sidebar.description"),e[9]=n,e[10]=f):f=e[10];let P;e[11]!==f?(P=s.jsx("p",{className:"typography-meta mt-1 text-muted-foreground",children:f}),e[11]=f,e[12]=P):P=e[12];let x;e[13]!==C||e[14]!==P?(x=s.jsxs("div",{className:"border-b px-3 pt-4 pb-3",children:[C,P]}),e[13]=C,e[14]=P,e[15]=x):x=e[15];let N;e[16]!==a||e[17]!==r||e[18]!==i||e[19]!==n?(N=s.jsx(vs,{outerClassName:"flex-1 min-h-0",className:"space-y-3 px-3 py-2 overflow-x-hidden",children:b.map(A=>s.jsxs("div",{className:"space-y-1",children:[s.jsx("div",{className:"typography-micro px-1 text-muted-foreground",children:n(A.groupKey)}),A.items.map(R=>{const I=r===R.id;return s.jsx("button",{type:"button",onClick:()=>{i(R.id),a?.()},className:fe("flex w-full items-center rounded-md px-2 py-1.5 text-left transition-colors",I?"bg-interactive-selection text-foreground":"text-foreground hover:bg-interactive-hover"),children:s.jsx("span",{className:"typography-ui-label truncate font-normal",children:n(R.titleKey)})},R.id)})]},A.groupKey))}),e[16]=a,e[17]=r,e[18]=i,e[19]=n,e[20]=N):N=e[20];let m;return e[21]!==x||e[22]!==N?(m=s.jsxs("div",{className:"flex h-full flex-col bg-background",children:[x,N]}),e[21]=x,e[22]=N,e[23]=m):m=e[23],m};function eh(t){return t.selectedPromptId}function th(t){return t.setSelectedPromptId}const Go={"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"}]},"linear.issue.review":{titleKey:"settings.magicPrompts.page.group.linearIssueReview.title",descriptionKey:"settings.magicPrompts.page.group.linearIssueReview.description",blocks:[{id:"linear.issue.review.visible",titleKey:"settings.magicPrompts.page.block.visiblePrompt"},{id:"linear.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"}]}},qo=(t,e)=>Object.prototype.hasOwnProperty.call(t,e),sr=t=>t.endsWith(".visible"),sh=()=>{const{t}=tt(),e=o.useCallback(j=>t(j),[t]),a=xr(j=>j.selectedPromptId),[n,r]=o.useState(!0),[i,l]=o.useState({}),[g,c]=o.useState({}),[y,p]=o.useState({}),[b,d]=o.useState({}),[C,f]=o.useState(!1);o.useEffect(()=>{let j=!0;return(async()=>{r(!0);try{const w=await qc();if(!j)return;l(w)}catch(w){console.warn("Failed to load magic prompts:",w),E.error(t("settings.magicPrompts.page.toast.loadFailed"))}finally{j&&r(!1)}})(),()=>{j=!1}},[t]);const P=Go[a]??Go["git.commit.generate"],x=o.useCallback(j=>qo(i,j)?i[j]:Hi(j),[i]),N=o.useCallback(j=>g[j]??x(j),[g,x]),m=o.useCallback((j,h)=>{c(w=>w[j]===h?w:{...w,[j]:h})},[]),A=o.useCallback(async j=>{const h=N(j);if(sr(j)&&h.trim().length===0){E.error(t("settings.magicPrompts.page.toast.visiblePromptRequired"));return}p(w=>({...w,[j]:!0}));try{const w=h===Hi(j)?await _r(j):await Hc(j,h);l(w.overrides),E.success(t("settings.magicPrompts.page.toast.saved"))}catch(w){const O=w instanceof Error?w.message:String(w);E.error(t("settings.magicPrompts.page.toast.saveFailed"),{description:O})}finally{p(w=>({...w,[j]:!1}))}},[N,t]),R=o.useCallback(async j=>{d(h=>({...h,[j]:!0}));try{const h=await _r(j);l(h.overrides),c(w=>({...w,[j]:Hi(j)})),E.success(t("settings.magicPrompts.page.toast.resetSuccess"))}catch(h){const w=h instanceof Error?h.message:String(h);E.error(t("settings.magicPrompts.page.toast.resetFailed"),{description:w})}finally{d(h=>({...h,[j]:!1}))}},[t]),I=o.useCallback(async()=>{f(!0);try{const j=await Wc();l(j.overrides),c({}),E.success(t("settings.magicPrompts.page.toast.resetAllSuccess"))}catch(j){const h=j instanceof Error?j.message:String(j);E.error(t("settings.magicPrompts.page.toast.resetAllFailed"),{description:h})}finally{f(!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(es,{title:e(P.titleKey),titleAccessory:s.jsx(Jt,{contentClassName:"max-w-xs",children:e(P.descriptionKey)}),headerEnd:s.jsx(B,{"data-settings-item":"magic-prompts.reset-overrides",variant:"outline",size:"sm",onClick:()=>{I()},disabled:C||Object.keys(i).length===0,children:t(C?"settings.magicPrompts.page.actions.resetting":"settings.magicPrompts.page.actions.resetAllOverrides")}),showSaveStatus:!1,children:P.blocks.map((j,h)=>{const w=Gc(j.id),O=x(j.id),T=N(j.id),S=qo(i,j.id),M=T!==O,V=sr(j.id)&&T.trim().length===0,$=y[j.id]===!0,k=b[j.id]===!0;return s.jsxs(ze,{title:e(j.titleKey),info:w.description,description:w.placeholders&&w.placeholders.length>0?`${t("settings.magicPrompts.page.placeholdersLabel")} ${w.placeholders.map(W=>`{{${W.key}}}`).join(", ")}`:void 0,divider:h>0,settingsItem:sr(j.id)?"magic-prompts.visible-prompt":"magic-prompts.instructions",contentClassName:"space-y-3",children:[s.jsx(Ts,{value:T,onChange:W=>m(j.id,W.target.value),className:"min-h-[220px] font-mono text-sm"}),V&&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(M?"settings.magicPrompts.page.status.unsavedChanges":S?"settings.magicPrompts.page.status.usingSavedOverride":"settings.magicPrompts.page.status.usingBuiltinDefault")}),s.jsxs("div",{className:"flex items-center gap-2",children:[s.jsx(B,{variant:"outline",size:"sm",onClick:()=>{R(j.id)},disabled:!S||$||k,children:t(k?"settings.magicPrompts.page.actions.resetting":"settings.magicPrompts.page.actions.resetToDefault")}),s.jsx(B,{size:"sm",onClick:()=>{A(j.id)},disabled:!M||$||k||V,children:t($?"settings.common.actions.saving":"settings.magicPrompts.page.actions.save")})]})]})]},j.id)})})},nh=t=>{const e=ut.c(89),{onItemSelect:a}=t,{t:n}=tt(),[r,i]=o.useState(null),[l,g]=o.useState(null),[c,y]=o.useState(null),{selectedSnippetName:p,snippets:b,setSelectedSnippet:d,setSnippetDraft:C,deleteSnippet:f,loadSnippets:P}=Si(Us(ah));let x,N;e[0]!==P?(x=()=>{P()},N=[P],e[0]=P,e[1]=x,e[2]=N):(x=e[1],N=e[2]),o.useEffect(x,N);let m;e[3]!==a||e[4]!==d||e[5]!==C||e[6]!==b?(m=async()=>{const Se=new Set(b.map(ih));let Ce="new-snippet",he=1;for(;Se.has(Ce);)Ce=`new-snippet-${he++}`;C({name:Ce,scope:"global"}),d(Ce),a?.()},e[3]=a,e[4]=d,e[5]=C,e[6]=b,e[7]=m):m=e[7];const A=m;let R;e[8]!==r||e[9]!==f||e[10]!==n?(R=async()=>{if(!r)return;await f(r.name)?(E.success(n("settings.snippets.sidebar.toast.deleted")),i(null)):E.error(n("settings.snippets.sidebar.toast.deleteFailed"))},e[8]=r,e[9]=f,e[10]=n,e[11]=R):R=e[11];const I=R;let j;e[12]!==b?(j=[...b].sort(rh),e[12]=b,e[13]=j):j=e[13];const h=j;let w;e[14]===Symbol.for("react.memo_cache_sentinel")?(w=fe("flex h-full flex-col","bg-background"),e[14]=w):w=e[14];let O;e[15]!==n?(O=n("settings.snippets.sidebar.title"),e[15]=n,e[16]=O):O=e[16];let T;e[17]!==O?(T=s.jsx("h2",{className:`${un} mb-3`,children:O}),e[17]=O,e[18]=T):T=e[18];let S;e[19]!==b.length||e[20]!==n?(S=n("settings.snippets.sidebar.total",{count:b.length}),e[19]=b.length,e[20]=n,e[21]=S):S=e[21];let M;e[22]!==S?(M=s.jsx("span",{className:"typography-meta text-muted-foreground",children:S}),e[22]=S,e[23]=M):M=e[23];let V;e[24]!==n?(V=n("settings.snippets.sidebar.actions.create"),e[24]=n,e[25]=V):V=e[25];let $;e[26]===Symbol.for("react.memo_cache_sentinel")?($=s.jsx(F,{name:"add",className:"h-3.5 w-3.5"}),e[26]=$):$=e[26];let k;e[27]!==A||e[28]!==V?(k=s.jsx(B,{size:"sm","data-settings-item":"snippets.create",variant:"ghost",className:"h-7 w-7 px-0 -my-1 text-muted-foreground",onClick:A,"aria-label":V,children:$}),e[27]=A,e[28]=V,e[29]=k):k=e[29];let W;e[30]!==M||e[31]!==k?(W=s.jsxs("div",{className:"flex items-center justify-between gap-2",children:[M,k]}),e[30]=M,e[31]=k,e[32]=W):W=e[32];let D;e[33]!==W||e[34]!==T?(D=s.jsxs("div",{className:"border-b px-3 pt-4 pb-3",children:[T,W]}),e[33]=W,e[34]=T,e[35]=D):D=e[35];let L;if(e[36]!==a||e[37]!==l||e[38]!==c||e[39]!==p||e[40]!==d||e[41]!==h||e[42]!==n){let Se;e[44]!==a||e[45]!==l||e[46]!==c||e[47]!==p||e[48]!==d||e[49]!==n?(Se=Ce=>s.jsxs(Qn,{open:c===Ce.name,onOpenChange:he=>y(he?Ce.name:null),children:[s.jsxs(Jn,{render:s.jsx("div",{className:fe("group relative flex items-center rounded-md px-1.5 py-1 transition-all duration-200 select-none",p===Ce.name?"bg-interactive-selection":"hover:bg-interactive-hover"),onContextMenu:he=>{he.preventDefault(),y(Ce.name)}}),children:[s.jsxs("button",{onClick:()=>{d(Ce.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:["#",Ce.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.${Ce.source}`)})]}),s.jsx("div",{className:"typography-micro text-muted-foreground/60 truncate leading-tight",children:Ce.description||Ce.content.replace(/\s+/g," ").substring(0,80)})]}),s.jsxs(cn,{open:l===Ce.name,onOpenChange:he=>{he&&y(null),g(he?Ce.name:null)},children:[s.jsx(on,{asChild:!0,children:s.jsx(B,{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:Ce.name}),children:s.jsx(F,{name:"more-2",className:"h-3.5 w-3.5"})})}),s.jsx(ln,{align:"end",className:"w-fit min-w-20",children:s.jsxs(dn,{onClick:he=>{he.stopPropagation(),i(Ce)},className:"text-destructive focus:text-destructive",children:[s.jsx(F,{name:"delete-bin",className:"h-4 w-4 mr-px"}),n("settings.common.actions.delete")]})})]})]}),s.jsx(Gn,{className:"w-fit min-w-20",children:s.jsxs(qn,{onClick:he=>{he.stopPropagation(),i(Ce)},className:"text-destructive focus:text-destructive",children:[s.jsx(F,{name:"delete-bin",className:"h-4 w-4 mr-px"}),n("settings.common.actions.delete")]})})]},`${Ce.source}:${Ce.filePath}`),e[44]=a,e[45]=l,e[46]=c,e[47]=p,e[48]=d,e[49]=n,e[50]=Se):Se=e[50],L=h.map(Se),e[36]=a,e[37]=l,e[38]=c,e[39]=p,e[40]=d,e[41]=h,e[42]=n,e[43]=L}else L=e[43];let J;e[51]!==L?(J=s.jsx(vs,{outerClassName:"flex-1 min-h-0",className:"space-y-1 px-3 py-2",children:L}),e[51]=L,e[52]=J):J=e[52];const ee=r!==null;let U;e[53]===Symbol.for("react.memo_cache_sentinel")?(U=Se=>{Se||i(null)},e[53]=U):U=e[53];let re;e[54]!==n?(re=n("settings.snippets.sidebar.dialog.deleteTitle"),e[54]=n,e[55]=re):re=e[55];let _;e[56]!==re?(_=s.jsx($t,{children:re}),e[56]=re,e[57]=_):_=e[57];const H=r?.name??"";let z;e[58]!==n||e[59]!==H?(z=n("settings.snippets.sidebar.dialog.deleteDescription",{name:H}),e[58]=n,e[59]=H,e[60]=z):z=e[60];let K;e[61]!==z?(K=s.jsx(Vt,{children:z}),e[61]=z,e[62]=K):K=e[62];let te;e[63]!==_||e[64]!==K?(te=s.jsxs(_t,{children:[_,K]}),e[63]=_,e[64]=K,e[65]=te):te=e[65];let Y;e[66]===Symbol.for("react.memo_cache_sentinel")?(Y=()=>i(null),e[66]=Y):Y=e[66];let ne;e[67]!==n?(ne=n("settings.common.actions.cancel"),e[67]=n,e[68]=ne):ne=e[68];let me;e[69]!==ne?(me=s.jsx(B,{size:"sm",variant:"ghost",onClick:Y,children:ne}),e[69]=ne,e[70]=me):me=e[70];let de;e[71]!==n?(de=n("settings.common.actions.delete"),e[71]=n,e[72]=de):de=e[72];let xe;e[73]!==I||e[74]!==de?(xe=s.jsx(B,{size:"sm",onClick:I,children:de}),e[73]=I,e[74]=de,e[75]=xe):xe=e[75];let ae;e[76]!==me||e[77]!==xe?(ae=s.jsxs(ts,{children:[me,xe]}),e[76]=me,e[77]=xe,e[78]=ae):ae=e[78];let le;e[79]!==te||e[80]!==ae?(le=s.jsxs(zt,{className:"max-w-md",children:[te,ae]}),e[79]=te,e[80]=ae,e[81]=le):le=e[81];let ge;e[82]!==ee||e[83]!==le?(ge=s.jsx(Kt,{open:ee,onOpenChange:U,children:le}),e[82]=ee,e[83]=le,e[84]=ge):ge=e[84];let Ae;return e[85]!==D||e[86]!==J||e[87]!==ge?(Ae=s.jsxs("div",{className:w,children:[D,J,ge]}),e[85]=D,e[86]=J,e[87]=ge,e[88]=Ae):Ae=e[88],Ae};function ah(t){return{selectedSnippetName:t.selectedSnippetName,snippets:t.snippets,setSelectedSnippet:t.setSelectedSnippet,setSnippetDraft:t.setSnippetDraft,deleteSnippet:t.deleteSnippet,loadSnippets:t.loadSnippets}}function ih(t){return t.name}function rh(t,e){return t.name.localeCompare(e.name)}const oh=()=>{const{t}=tt(),{selectedSnippetName:e,snippets:a,snippetDraft:n,setSnippetDraft:r,updateSnippet:i,createSnippet:l}=Si(Us(w=>({selectedSnippetName:w.selectedSnippetName,snippets:w.snippets,snippetDraft:w.snippetDraft,setSnippetDraft:w.setSnippetDraft,updateSnippet:w.updateSnippet,createSnippet:w.createSnippet}))),g=o.useMemo(()=>e?a.find(w=>w.name===e||w.aliases.includes(e))??null:null,[e,a]),c=!!(n&&n.name===e&&!g),[y,p]=o.useState(""),[b,d]=o.useState("global"),[C,f]=o.useState(""),[P,x]=o.useState(""),[N,m]=o.useState(""),[A,R]=o.useState(!1),I=o.useRef(null);o.useEffect(()=>{if(c&&n){const w={draftName:n.name||"",draftScope:n.scope||"global",description:n.description||"",aliases:(n.aliases||[]).join(", "),content:n.content||""};p(w.draftName),d(w.draftScope),f(w.description),x(w.aliases),m(w.content),I.current=w}else if(g){const w={draftName:"",draftScope:"global",description:g.description??"",aliases:g.aliases.join(", "),content:g.content};f(w.description),x(w.aliases),m(w.content),I.current=w}},[g,c,e,n]);const j=o.useMemo(()=>{const w=I.current;return w?c&&y!==w.draftName||c&&b!==w.draftScope?!0:C!==w.description||P!==w.aliases||N!==w.content:!1},[P,N,C,y,b,c]),h=async()=>{const w=c?y.trim().replace(/\s+/g,"-"):e?.trim();if(!w){E.error(t("settings.snippets.page.toast.nameRequired"));return}if(!N.trim()){E.error(t("settings.snippets.page.toast.contentRequired"));return}const O=P.split(",").map(T=>T.trim()).filter(Boolean);R(!0);try{if(!(c?await l(w,N,{aliases:O,description:C,scope:b}):await i(w,{content:N,aliases:O,description:C}))){E.error(t("settings.snippets.page.toast.saveFailed"));return}E.success(t("settings.snippets.page.toast.saved")),c&&r(null)}finally{R(!1)}};return e?s.jsxs(es,{title:c?t("settings.snippets.page.title.new"):`#${e}`,description:g?g.filePath:void 0,showSaveStatus:!1,children:[s.jsxs(ze,{divider:!1,contentClassName:"space-y-0",children:[c?s.jsxs(Rt,{label:"#",children:[s.jsx(He,{value:y,onChange:w=>p(w.target.value),placeholder:t("settings.snippets.page.field.namePlaceholder"),className:"h-7 w-44 px-2"}),s.jsxs(St,{value:b,onValueChange:w=>d(w),children:[s.jsx(Ct,{size:Ft,className:"w-fit min-w-[100px]",children:s.jsx(Mt,{})}),s.jsxs(It,{align:"end",children:[s.jsx(at,{value:"global",children:t("settings.common.scope.global")}),s.jsx(at,{value:"project",children:t("settings.common.scope.project")})]})]})]}):null,s.jsx(qt,{label:t("settings.common.field.description"),children:s.jsx(He,{value:C,onChange:w=>f(w.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:P,onChange:w=>x(w.target.value),placeholder:t("settings.snippets.page.field.aliasesPlaceholder"),className:"h-7 w-full max-w-sm px-2"})})]}),s.jsxs(ze,{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(Jt,{children:t("settings.snippets.page.hint")})]}),s.jsx(Ts,{value:N,onChange:w=>m(w.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(B,{onClick:h,disabled:A||!j,size:"xs",className:"!font-normal",children:t(A?"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(F,{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")})]})})},Xl=()=>{const{t}=tt(),e=Ye(b=>b.settingsGitmojiEnabled),a=Ye(b=>b.setSettingsGitmojiEnabled),n=Id(),r=ie(b=>b.gitChangesViewMode),i=ie(b=>b.setGitChangesViewMode),[l,g]=o.useState(!0),c=o.useMemo(()=>[{id:"flat",label:t("settings.aiworker.git.option.flatList")},{id:"tree",label:t("settings.aiworker.git.option.treeView")}],[t]);o.useEffect(()=>{(async()=>{try{const d=await pn();d&&(d.gitmojiEnabled!==void 0&&a(d.gitmojiEnabled),d.gitChangesViewMode!==void 0&&i(d.gitChangesViewMode))}catch(d){console.warn("Failed to load git settings:",d)}finally{g(!1)}})()},[i,a]);const y=o.useCallback(async b=>{a(b);try{await pt({gitmojiEnabled:b})}catch(d){console.warn("Failed to save gitmoji setting:",d)}},[a]),p=o.useCallback(b=>{b!==r&&(i(b),pt({gitChangesViewMode:b}))},[r,i]);return l?null:s.jsx(ze,{title:t("settings.aiworker.git.title"),children:s.jsxs("div",{className:fs,children:[s.jsx(Ss,{settingsItem:"git.changes-view",title:t("settings.aiworker.git.changesViewTitle"),children:s.jsx(Js,{"aria-label":t("settings.aiworker.git.changesViewAria"),children:c.map(b=>s.jsx(Bs,{selected:r===b.id,onSelect:()=>{p(b.id)},label:b.label,ariaLabel:t("settings.aiworker.git.optionAria",{option:b.label})},b.id))})}),s.jsx(dt,{settingsItem:"git.gitmoji",checked:e,onChange:b=>{y(b)},label:t("settings.aiworker.git.enableGitmoji"),ariaLabel:t("settings.aiworker.git.enableGitmojiAria")}),s.jsx(dt,{settingsItem:"git.gitignored-files",checked:n,onChange:Pd,label:t("settings.aiworker.git.showGitignored"),ariaLabel:t("settings.aiworker.git.showGitignoredAria")})]})})},Jo=[{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)"}],lh=[{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"}],ch=({open:t,onOpenChange:e,profileId:a,importData:n})=>{const{t:r}=tt(),i=_n(K=>K.getProfileById),l=_n(K=>K.createProfile),g=_n(K=>K.updateProfile),c=_n(K=>K.deleteProfile),y=o.useMemo(()=>a&&a!=="new"&&!n?i(a):null,[a,i,n]),p=a==="new"||n!=null,b=a==="global",[d,C]=o.useState(""),[f,P]=o.useState(""),[x,N]=o.useState(""),[m,A]=o.useState("ssh"),[R,I]=o.useState(""),[j,h]=o.useState(!1),[w,O]=o.useState(""),[T,S]=o.useState(""),[M,V]=o.useState("keyword"),[$,k]=o.useState("branch"),[W,D]=o.useState(!1),[L,J]=o.useState(!1),[ee,U]=o.useState(!1);o.useEffect(()=>{if(t){if(n){const K=n.host.split("/"),te=K.length>=3?K[K.length-1]:n.host;C(te),P(n.username),N(""),A("token"),I(""),h(!1),O(""),S(n.host),V("string"),k("code")}else if(p)C(""),P(""),N(""),A("ssh"),I(""),h(!1),O(""),S(""),V("keyword"),k("branch");else if(y)C(y.name),P(y.userName),N(y.userEmail),A(y.authType||"ssh"),I(y.sshKey||""),h(y.signCommits===!0),O(y.signingKey||""),S(y.host||""),V(y.color||"keyword"),k(y.icon||"branch");else if(b){const K=i("global");K&&(C(K.name),P(K.userName),N(K.userEmail),A(K.authType||"ssh"),I(K.sshKey||""),h(!1),O(""),S(K.host||""),V(K.color||"keyword"),k(K.icon||"branch"))}}},[t,a,y,p,n,b,i]);const re=async()=>{if(!f.trim()||!x.trim()){E.error(r("settings.gitIdentities.editor.toast.userNameEmailRequired"));return}if(m==="token"&&!T.trim()){E.error(r("settings.gitIdentities.editor.toast.hostRequiredForToken"));return}if(j&&!w.trim()){E.error(r("settings.gitIdentities.editor.toast.signingKeyRequired"));return}D(!0);try{const K={name:d.trim()||f.trim(),userName:f.trim(),userEmail:x.trim(),authType:m,sshKey:m==="ssh"&&R.trim()||null,signCommits:j,signingKey:w.trim()||null,host:m==="token"&&T.trim()||null,color:M,icon:$};let te;if(p)te=await l(K);else if(a)te=await g(a,K);else return;te?(E.success(r(p?"settings.gitIdentities.editor.toast.profileCreated":"settings.gitIdentities.editor.toast.profileUpdated")),e(!1)):E.error(r(p?"settings.gitIdentities.editor.toast.createProfileFailed":"settings.gitIdentities.editor.toast.updateProfileFailed"))}catch(K){console.error("Error saving profile:",K),E.error(r("settings.gitIdentities.editor.toast.saveUnexpectedError"))}finally{D(!1)}},_=async()=>{if(!(!a||p)){U(!0);try{await c(a)?(E.success(r("settings.gitIdentities.editor.toast.profileDeleted")),J(!1),e(!1)):E.error(r("settings.gitIdentities.editor.toast.deleteProfileFailed"))}catch(K){console.error("Error deleting profile:",K),E.error(r("settings.gitIdentities.editor.toast.deleteUnexpectedError"))}finally{U(!1)}}},H=o.useMemo(()=>Jo.find(te=>te.key===M)?.cssVar||"var(--syntax-keyword)",[M]),z=n?r("settings.gitIdentities.editor.title.importCredential"):p?r("settings.gitIdentities.editor.title.newIdentity"):b?r("settings.gitIdentities.editor.title.globalIdentity"):y?.name||r("settings.gitIdentities.editor.title.editIdentity");return s.jsxs(s.Fragment,{children:[s.jsx(Kt,{open:t,onOpenChange:e,children:s.jsxs(zt,{className:"max-w-lg max-h-[85vh] overflow-y-auto",children:[s.jsxs(_t,{children:[s.jsx($t,{children:z}),s.jsx(Vt,{children:r(b?"settings.gitIdentities.editor.description.globalReadOnly":p?"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:`${Tt} block mb-1.5`,children:r("settings.gitIdentities.editor.field.profileName")}),s.jsx(He,{value:d,onChange:K=>C(K.target.value),placeholder:r("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:r("settings.gitIdentities.editor.field.color")}),s.jsx("div",{className:"flex gap-1.5",children:Jo.map(K=>s.jsx("button",{type:"button",onClick:()=>V(K.key),className:fe("w-6 h-6 rounded-md border-2 transition-all cursor-pointer",M===K.key?"border-foreground scale-110":"border-transparent hover:border-border"),style:{backgroundColor:K.cssVar},title:K.label},K.key))})]}),s.jsxs("div",{className:"flex items-center justify-between gap-4",children:[s.jsx("span",{className:"typography-ui-label text-foreground",children:r("settings.gitIdentities.editor.field.icon")}),s.jsx("div",{className:"flex gap-1.5",children:lh.map(K=>{const te=K.Icon;return s.jsx("button",{type:"button",onClick:()=>k(K.key),className:fe("w-7 h-7 rounded-md border-2 transition-all flex items-center justify-center cursor-pointer",$===K.key?"border-[var(--interactive-border)] bg-[var(--surface-muted)]":"border-transparent hover:border-[var(--interactive-border)] hover:bg-[var(--surface-muted)]/50"),title:K.label,children:s.jsx(F,{name:te,className:"w-3.5 h-3.5",style:{color:$===K.key?H:"var(--surface-muted-foreground)"}})},K.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:Tt,children:r("settings.gitIdentities.editor.field.userName")}),!b&&s.jsx("span",{className:"text-[var(--status-error)] text-xs",children:"*"}),s.jsx(Jt,{contentClassName:"max-w-xs",children:r("settings.gitIdentities.editor.field.userNameTooltip")})]}),s.jsx(He,{value:f,onChange:K=>P(K.target.value),placeholder:r("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:Tt,children:r("settings.gitIdentities.editor.field.emailAddress")}),!b&&s.jsx("span",{className:"text-[var(--status-error)] text-xs",children:"*"}),s.jsx(Jt,{contentClassName:"max-w-xs",children:r("settings.gitIdentities.editor.field.emailAddressTooltip")})]}),s.jsx(He,{type:"email",value:x,onChange:K=>N(K.target.value),placeholder:r("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:r("settings.gitIdentities.editor.field.authMethod")}),s.jsxs("div",{className:"flex items-center gap-1",children:[s.jsxs(B,{size:"sm",type:"button",variant:"chip","aria-pressed":m==="ssh",onClick:()=>A("ssh"),children:[s.jsx(F,{name:"lock-2",className:"w-3.5 h-3.5 mr-1"})," SSH"]}),s.jsxs(B,{size:"sm",type:"button",variant:"chip","aria-pressed":m==="token",onClick:()=>A("token"),children:[s.jsx(F,{name:"key",className:"w-3.5 h-3.5 mr-1"})," ",r("settings.gitIdentities.editor.field.authToken")]})]})]}),m==="ssh"&&s.jsxs("div",{children:[s.jsxs("div",{className:"flex items-center gap-1.5 mb-1.5",children:[s.jsx("label",{className:Tt,children:r("settings.gitIdentities.editor.field.sshKeyPath")}),s.jsx(Jt,{contentClassName:"max-w-xs",children:r("settings.gitIdentities.editor.field.sshKeyPathTooltip")})]}),s.jsx(He,{value:R,onChange:K=>I(K.target.value),placeholder:r("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(dt,{checked:j,onChange:h,label:r("settings.gitIdentities.editor.field.signCommits"),info:r("settings.gitIdentities.editor.section.commitSigning"),ariaLabel:r("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:Tt,children:r("settings.gitIdentities.editor.field.signingKey")})}),s.jsx(He,{value:w,onChange:K=>O(K.target.value),placeholder:r("settings.gitIdentities.editor.field.signingKeyPlaceholder"),disabled:!j,className:"h-8 font-mono text-xs"})]})]}),m==="token"&&s.jsxs("div",{children:[s.jsxs("div",{className:"flex items-center gap-1.5 mb-1.5",children:[s.jsx("label",{className:Tt,children:r("settings.gitIdentities.editor.field.host")}),s.jsx("span",{className:"text-[var(--status-error)] text-xs",children:"*"}),s.jsx(Jt,{contentClassName:"max-w-xs",children:r("settings.gitIdentities.editor.field.hostTooltip")})]}),s.jsx(He,{value:T,onChange:K=>S(K.target.value),placeholder:r("settings.gitIdentities.editor.field.hostPlaceholder"),required:!0,className:"h-8 font-mono text-xs"})]})]})]})]}),s.jsxs(ts,{className:"gap-2",children:[!b&&!p&&s.jsxs(B,{variant:"outline",size:"sm",onClick:()=>J(!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(F,{name:"delete-bin",className:"w-3.5 h-3.5 mr-1"})," ",r("settings.common.actions.delete")]}),s.jsx(B,{variant:"ghost",size:"sm",onClick:()=>e(!1),className:"text-foreground hover:bg-interactive-hover hover:text-foreground",children:r(b?"settings.gitIdentities.editor.actions.close":"settings.common.actions.cancel")}),!b&&s.jsx(B,{size:"sm",onClick:re,disabled:W,children:r(W?"settings.common.actions.saving":p?"settings.gitIdentities.editor.actions.create":"settings.gitIdentities.editor.actions.save")})]})]})}),s.jsx(Kt,{open:L,onOpenChange:K=>{ee||J(K)},children:s.jsxs(zt,{className:"max-w-md",children:[s.jsxs(_t,{children:[s.jsx($t,{children:r("settings.gitIdentities.page.deleteDialog.title")}),s.jsx(Vt,{children:r("settings.gitIdentities.page.deleteDialog.description",{name:y?.name||d})})]}),s.jsxs(ts,{children:[s.jsx(B,{variant:"ghost",onClick:()=>J(!1),disabled:ee,children:r("settings.common.actions.cancel")}),s.jsx(B,{size:"sm",variant:"destructive",onClick:()=>{_()},disabled:ee,children:r("settings.common.actions.delete")})]})]})})]})},dh={branch:"git-branch",briefcase:"briefcase",house:"home",graduation:"graduation-cap",code:"code",heart:"heart"},uh={keyword:"var(--syntax-keyword)",error:"var(--status-error)",string:"var(--syntax-string)",function:"var(--syntax-function)",type:"var(--syntax-type)"},ph=()=>{const t=ut.c(112),{t:e}=tt(),{profiles:a,globalIdentity:n,defaultGitIdentityId:r,deleteProfile:i,loadProfiles:l,loadGlobalIdentity:g,loadDiscoveredCredentials:c,loadDefaultGitIdentityId:y,setDefaultGitIdentityId:p,getUnimportedCredentials:b}=_n(Us(gh)),[d,C]=o.useState(!1),[f,P]=o.useState(null),[x,N]=o.useState(null),[m,A]=o.useState(null),[R,I]=o.useState(!1);let j,h;t[0]!==y||t[1]!==c||t[2]!==g||t[3]!==l?(j=()=>{l(),g(),c(),y()},h=[l,g,c,y],t[0]=y,t[1]=c,t[2]=g,t[3]=l,t[4]=j,t[5]=h):(j=t[4],h=t[5]),o.useEffect(j,h);let w,O,T,S,M,V,$,k,W,D,L,J,ee,U;if(t[6]!==r||t[7]!==m||t[8]!==i||t[9]!==b||t[10]!==n||t[11]!==a||t[12]!==p||t[13]!==e){const We=b();let ve;t[28]===Symbol.for("react.memo_cache_sentinel")?(ve=(Ee,we)=>{P(Ee),N(we??null),C(!0)},t[28]=ve):ve=t[28];const Z=ve;let se;t[29]!==r||t[30]!==p||t[31]!==e?(se=async Ee=>{const we=r===Ee?null:Ee;if(!await p(we)){E.error(e("settings.gitIdentities.page.toast.updateDefaultFailed"));return}E.success(e(we?"settings.gitIdentities.page.toast.defaultUpdated":"settings.gitIdentities.page.toast.defaultUnset"))},t[29]=r,t[30]=p,t[31]=e,t[32]=se):se=t[32];const ye=se;let be;t[33]!==m||t[34]!==i||t[35]!==e?(be=async()=>{if(!m)return;I(!0),await i(m.id)?(E.success(e("settings.gitIdentities.page.toast.profileDeleted",{name:m.name})),A(null)):E.error(e("settings.gitIdentities.page.toast.deleteProfileFailed")),I(!1)},t[33]=m,t[34]=i,t[35]=e,t[36]=be):be=t[36],T=be,O=es,t[37]!==e?(M=e("settings.page.git.title"),t[37]=e,t[38]=M):M=t[38],V=!0,w=ze,t[39]!==e?(J=e("settings.gitIdentities.page.section.title"),t[39]=e,t[40]=J):J=t[40],ee=!1;let Re,Fe;t[41]===Symbol.for("react.memo_cache_sentinel")?(Re=()=>Z("new"),Fe=s.jsx(F,{name:"add",className:"w-3.5 h-3.5 mr-1"}),t[41]=Re,t[42]=Fe):(Re=t[41],Fe=t[42]);let Ke;t[43]!==e?(Ke=e("settings.common.badge.new"),t[43]=e,t[44]=Ke):Ke=t[44],t[45]!==Ke?(U=s.jsxs(B,{size:"sm",variant:"outline",onClick:Re,children:[Fe," ",Ke]}),t[45]=Ke,t[46]=U):U=t[46],S="git.identities",$="rounded-lg bg-[var(--surface-elevated)]/70 overflow-hidden flex flex-col",k=n&&s.jsx(Qo,{profile:n,isDefault:r==="global",onEdit:()=>Z("global"),onToggleDefault:()=>ye("global"),isReadOnly:!0,hasBorder:a.length>0||We.length>0}),W=a.map((Ee,we)=>s.jsx(Qo,{profile:Ee,isDefault:r===Ee.id,onEdit:()=>Z(Ee.id),onToggleDefault:()=>ye(Ee.id),onDelete:()=>A(Ee),hasBorder:we<a.length-1||We.length>0},Ee.id)),D=!n&&a.length===0&&We.length===0&&s.jsxs("div",{className:"py-8 px-4 text-center text-muted-foreground",children:[s.jsx(F,{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")})]}),L=We.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")})}),We.map((Ee,we)=>s.jsx(mh,{credential:Ee,onImport:()=>Z("new",{host:Ee.host,username:Ee.username}),hasBorder:we<We.length-1},`${Ee.host}-${Ee.username}`))]}),t[6]=r,t[7]=m,t[8]=i,t[9]=b,t[10]=n,t[11]=a,t[12]=p,t[13]=e,t[14]=w,t[15]=O,t[16]=T,t[17]=S,t[18]=M,t[19]=V,t[20]=$,t[21]=k,t[22]=W,t[23]=D,t[24]=L,t[25]=J,t[26]=ee,t[27]=U}else w=t[14],O=t[15],T=t[16],S=t[17],M=t[18],V=t[19],$=t[20],k=t[21],W=t[22],D=t[23],L=t[24],J=t[25],ee=t[26],U=t[27];let re;t[47]!==$||t[48]!==k||t[49]!==W||t[50]!==D||t[51]!==L?(re=s.jsxs("div",{className:$,children:[k,W,D,L]}),t[47]=$,t[48]=k,t[49]=W,t[50]=D,t[51]=L,t[52]=re):re=t[52];let _;t[53]!==w||t[54]!==S||t[55]!==re||t[56]!==J||t[57]!==ee||t[58]!==U?(_=s.jsx(w,{title:J,divider:ee,headerAction:U,settingsItem:S,children:re}),t[53]=w,t[54]=S,t[55]=re,t[56]=J,t[57]=ee,t[58]=U,t[59]=_):_=t[59];let H;t[60]===Symbol.for("react.memo_cache_sentinel")?(H=s.jsx(Xl,{}),t[60]=H):H=t[60];let z;t[61]!==O||t[62]!==M||t[63]!==V||t[64]!==_?(z=s.jsxs(O,{title:M,showSaveStatus:V,children:[_,H]}),t[61]=O,t[62]=M,t[63]=V,t[64]=_,t[65]=z):z=t[65];let K;t[66]!==x||t[67]!==d||t[68]!==f?(K=s.jsx(ch,{open:d,onOpenChange:C,profileId:f,importData:x}),t[66]=x,t[67]=d,t[68]=f,t[69]=K):K=t[69];const te=m!==null;let Y;t[70]!==R?(Y=We=>{R||We||A(null)},t[70]=R,t[71]=Y):Y=t[71];let ne;t[72]!==e?(ne=e("settings.gitIdentities.page.deleteDialog.title"),t[72]=e,t[73]=ne):ne=t[73];let me;t[74]!==ne?(me=s.jsx($t,{children:ne}),t[74]=ne,t[75]=me):me=t[75];const de=m?.name??"";let xe;t[76]!==e||t[77]!==de?(xe=e("settings.gitIdentities.page.deleteDialog.description",{name:de}),t[76]=e,t[77]=de,t[78]=xe):xe=t[78];let ae;t[79]!==xe?(ae=s.jsx(Vt,{children:xe}),t[79]=xe,t[80]=ae):ae=t[80];let le;t[81]!==me||t[82]!==ae?(le=s.jsxs(_t,{children:[me,ae]}),t[81]=me,t[82]=ae,t[83]=le):le=t[83];let ge;t[84]===Symbol.for("react.memo_cache_sentinel")?(ge=()=>A(null),t[84]=ge):ge=t[84];let Ae;t[85]!==e?(Ae=e("settings.common.actions.cancel"),t[85]=e,t[86]=Ae):Ae=t[86];let Se;t[87]!==R||t[88]!==Ae?(Se=s.jsx(B,{variant:"ghost",onClick:ge,disabled:R,children:Ae}),t[87]=R,t[88]=Ae,t[89]=Se):Se=t[89];let Ce;t[90]!==T?(Ce=()=>{T()},t[90]=T,t[91]=Ce):Ce=t[91];let he;t[92]!==e?(he=e("settings.common.actions.delete"),t[92]=e,t[93]=he):he=t[93];let _e;t[94]!==R||t[95]!==Ce||t[96]!==he?(_e=s.jsx(B,{size:"sm",variant:"destructive",onClick:Ce,disabled:R,children:he}),t[94]=R,t[95]=Ce,t[96]=he,t[97]=_e):_e=t[97];let Ue;t[98]!==Se||t[99]!==_e?(Ue=s.jsxs(ts,{children:[Se,_e]}),t[98]=Se,t[99]=_e,t[100]=Ue):Ue=t[100];let ke;t[101]!==le||t[102]!==Ue?(ke=s.jsxs(zt,{className:"max-w-md",children:[le,Ue]}),t[101]=le,t[102]=Ue,t[103]=ke):ke=t[103];let Oe;t[104]!==te||t[105]!==Y||t[106]!==ke?(Oe=s.jsx(Kt,{open:te,onOpenChange:Y,children:ke}),t[104]=te,t[105]=Y,t[106]=ke,t[107]=Oe):Oe=t[107];let Ve;return t[108]!==z||t[109]!==K||t[110]!==Oe?(Ve=s.jsxs(s.Fragment,{children:[z,K,Oe]}),t[108]=z,t[109]=K,t[110]=Oe,t[111]=Ve):Ve=t[111],Ve},Qo=t=>{const e=ut.c(56),{profile:a,isDefault:n,onEdit:r,onToggleDefault:i,onDelete:l,isReadOnly:g,hasBorder:c}=t,{t:y}=tt(),[p,b]=o.useState(!1),d=dh[a.icon||"branch"]||"git-branch",C=uh[a.color||""],f=a.authType||"ssh";let P;e[0]!==r?(P=_=>{_.currentTarget===_.target&&(_.key!=="Enter"&&_.key!==" "||(_.preventDefault(),r()))},e[0]=r,e[1]=P):P=e[1];const x=P;let N;e[2]!==n||e[3]!==g||e[4]!==l||e[5]!==i||e[6]!==y?(N=_=>s.jsxs(s.Fragment,{children:[s.jsx(_,{onClick:H=>{H.stopPropagation(),i()},children:y(n?"settings.gitIdentities.page.actions.unsetDefault":"settings.gitIdentities.page.actions.setAsDefault")}),!g&&l&&s.jsxs(_,{onClick:H=>{H.stopPropagation(),l()},className:"text-destructive focus:text-destructive",children:[s.jsx(F,{name:"delete-bin",className:"h-4 w-4 mr-px"}),y("settings.common.actions.delete")]})]}),e[2]=n,e[3]=g,e[4]=l,e[5]=i,e[6]=y,e[7]=N):N=e[7];const m=N,A=c&&"border-b border-[var(--surface-subtle)]";let R;e[8]!==A?(R=fe("group flex items-center justify-between gap-3 px-4 py-2.5 transition-colors hover:bg-[var(--interactive-hover)]/30 cursor-pointer",A),e[8]=A,e[9]=R):R=e[9];let I;e[10]===Symbol.for("react.memo_cache_sentinel")?(I=_=>{_.preventDefault(),b(!0)},e[10]=I):I=e[10];let j;e[11]!==x||e[12]!==r||e[13]!==R?(j=s.jsx("div",{className:R,onClick:r,role:"button",tabIndex:0,onKeyDown:x,onContextMenu:I}),e[11]=x,e[12]=r,e[13]=R,e[14]=j):j=e[14];let h;e[15]!==C?(h={color:C},e[15]=C,e[16]=h):h=e[16];let w;e[17]!==d||e[18]!==h?(w=s.jsx(F,{name:d,className:"w-4 h-4 shrink-0",style:h}),e[17]=d,e[18]=h,e[19]=w):w=e[19];let O;e[20]!==a.name?(O=s.jsx("span",{className:"typography-ui-label text-foreground truncate",children:a.name}),e[20]=a.name,e[21]=O):O=e[21];let T;e[22]!==f?(T=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:f}),e[22]=f,e[23]=T):T=e[23];let S;e[24]!==n||e[25]!==y?(S=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]=S):S=e[26];let M;e[27]!==g||e[28]!==y?(M=g&&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]=g,e[28]=y,e[29]=M):M=e[29];let V;e[30]!==T||e[31]!==S||e[32]!==M||e[33]!==O?(V=s.jsxs("div",{className:"flex items-center gap-1.5",children:[O,T,S,M]}),e[30]=T,e[31]=S,e[32]=M,e[33]=O,e[34]=V):V=e[34];const $=f==="token"&&a.host?a.host:a.userEmail;let k;e[35]!==$?(k=s.jsx("div",{className:"typography-micro text-muted-foreground/60 truncate leading-tight",children:$}),e[35]=$,e[36]=k):k=e[36];let W;e[37]!==V||e[38]!==k?(W=s.jsxs("div",{className:"min-w-0",children:[V,k]}),e[37]=V,e[38]=k,e[39]=W):W=e[39];let D;e[40]!==W||e[41]!==w?(D=s.jsxs("div",{className:"flex items-center gap-3 min-w-0",children:[w,W]}),e[40]=W,e[41]=w,e[42]=D):D=e[42];let L;e[43]===Symbol.for("react.memo_cache_sentinel")?(L=s.jsx(on,{asChild:!0,children:s.jsx(B,{size:"icon",variant:"ghost",className:"h-6 w-6 shrink-0 opacity-100 transition-opacity md:opacity-0 md:group-hover:opacity-100",onClick:hh,children:s.jsx(F,{name:"more-2",className:"h-3.5 w-3.5"})})}),e[43]=L):L=e[43];let J;e[44]!==m?(J=s.jsxs(cn,{children:[L,s.jsx(ln,{align:"end",className:"w-fit min-w-28",children:m(dn)})]}),e[44]=m,e[45]=J):J=e[45];let ee;e[46]!==D||e[47]!==J||e[48]!==j?(ee=s.jsxs(Jn,{render:j,children:[D,J]}),e[46]=D,e[47]=J,e[48]=j,e[49]=ee):ee=e[49];let U;e[50]!==m?(U=s.jsx(Gn,{className:"w-fit min-w-28",children:m(qn)}),e[50]=m,e[51]=U):U=e[51];let re;return e[52]!==p||e[53]!==ee||e[54]!==U?(re=s.jsxs(Qn,{open:p,onOpenChange:b,children:[ee,U]}),e[52]=p,e[53]=ee,e[54]=U,e[55]=re):re=e[55],re},mh=t=>{const e=ut.c(21),{credential:a,onImport:n,hasBorder:r}=t,{t:i}=tt();let l;e[0]!==a.host?(l=a.host.split("/"),e[0]=a.host,e[1]=l):l=e[1];const g=l,c=g.length>=3?g[g.length-1]:a.host,y=a.host.includes("/"),p=r&&"border-b border-[var(--surface-subtle)]";let b;e[2]!==p?(b=fe("flex items-center justify-between gap-3 px-4 py-2.5 transition-colors hover:bg-[var(--interactive-hover)]/30",p),e[2]=p,e[3]=b):b=e[3];let d;e[4]!==c?(d=s.jsx("span",{className:"typography-ui-label text-foreground truncate block",children:c}),e[4]=c,e[5]=d):d=e[5];const C=y?a.host:a.username;let f;e[6]!==C?(f=s.jsx("span",{className:"typography-micro text-muted-foreground/60 truncate block leading-tight",children:C}),e[6]=C,e[7]=f):f=e[7];let P;e[8]!==d||e[9]!==f?(P=s.jsxs("div",{className:"min-w-0",children:[d,f]}),e[8]=d,e[9]=f,e[10]=P):P=e[10];let x;e[11]===Symbol.for("react.memo_cache_sentinel")?(x=s.jsx(F,{name:"download",className:"h-3 w-3"}),e[11]=x):x=e[11];let N;e[12]!==i?(N=i("settings.gitIdentities.page.actions.import"),e[12]=i,e[13]=N):N=e[13];let m;e[14]!==n||e[15]!==N?(m=s.jsxs(B,{size:"sm",variant:"ghost",onClick:n,className:"gap-1 shrink-0",children:[x,N]}),e[14]=n,e[15]=N,e[16]=m):m=e[16];let A;return e[17]!==m||e[18]!==b||e[19]!==P?(A=s.jsxs("div",{className:b,children:[P,m]}),e[17]=m,e[18]=b,e[19]=P,e[20]=A):A=e[20],A};function gh(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 hh(t){return t.stopPropagation()}const fh=({embedded:t=!1})=>{const{t:e}=tt(),{isMobile:a}=wa(),n=fa()?.github,r=Cn(k=>k.status),i=Cn(k=>k.isLoading),l=Cn(k=>k.hasChecked),g=Cn(k=>k.refreshStatus),c=Cn(k=>k.setStatus),y=o.useCallback(async k=>{await Pn(k)},[]),[p,b]=o.useState(!1),[d,C]=o.useState(null),[f,P]=o.useState(null),x=o.useRef(null),N=o.useCallback(()=>{x.current!=null&&(window.clearInterval(x.current),x.current=null),P(null)},[]);o.useEffect(()=>((async()=>{try{l||await g(n)}catch(k){console.warn("Failed to load GitHub auth status:",k)}})(),()=>{N()}),[l,g,n,N]);const m=o.useCallback(async()=>{b(!0);try{const k=n?await n.authStart():await(async()=>{const D=await yt("/api/github/auth/start",{method:"POST",headers:{"Content-Type":"application/json",Accept:"application/json"},body:JSON.stringify({})}),L=await D.json().catch(()=>null);if(!D.ok||!L||!("deviceCode"in L))throw new Error(L?.error||D.statusText);return L})();C(k),P(Math.max(1,k.interval)*1e3);const W=k.verificationUriComplete||k.verificationUri;y(W)}catch(k){console.error("Failed to start GitHub connect:",k),E.error(e("settings.github.page.toast.startConnectFailed"))}finally{b(!1)}},[y,n,e]),A=o.useCallback(async k=>{if(n)return n.authComplete(k);const W=await yt("/api/github/auth/complete",{method:"POST",headers:{"Content-Type":"application/json",Accept:"application/json"},body:JSON.stringify({deviceCode:k})}),D=await W.json().catch(()=>null);if(!W.ok||!D)throw new Error(D?.error||W.statusText);return D},[n]);o.useEffect(()=>{if(!(!d?.deviceCode||!f)&&x.current==null)return x.current=window.setInterval(()=>{(async()=>{try{const k=await A(d.deviceCode);if(k.connected){E.success(e("settings.github.page.toast.connected")),C(null),N(),await g(n,{force:!0});return}k.status==="slow_down"&&P(W=>W?W+5e3:5e3),(k.status==="expired_token"||k.status==="access_denied")&&(E.error(k.error||e("settings.github.page.toast.authorizationFailed")),C(null),N())}catch(k){console.warn("GitHub polling failed:",k)}})()},f),()=>{x.current!=null&&(window.clearInterval(x.current),x.current=null)}},[d,f,A,g,n,N,e]);const R=o.useCallback(async k=>{b(!0);try{if(n)await n.authSetGhCliDisabled(k);else{const W=await yt("/api/github/auth/gh-cli",{method:"POST",headers:{"Content-Type":"application/json",Accept:"application/json"},body:JSON.stringify({disabled:k})}),D=await W.json().catch(()=>null);if(!W.ok)throw new Error(D?.error||W.statusText)}E.success(e(k?"settings.github.page.toast.ghCliDisabled":"settings.github.page.toast.ghCliEnabled")),await g(n,{force:!0})}catch(W){console.error("Failed to update gh CLI setting:",W),E.error(e("settings.github.page.toast.ghCliUpdateFailed"))}finally{b(!1)}},[g,n,e]),I=o.useCallback(async()=>{b(!0);try{if(N(),C(null),n)await n.authDisconnect();else{const k=await yt("/api/github/auth",{method:"DELETE",headers:{Accept:"application/json"}});if(!k.ok)throw new Error(k.statusText)}E.success(e("settings.github.page.toast.disconnected")),await g(n,{force:!0})}catch(k){console.error("Failed to disconnect GitHub:",k),E.error(e("settings.github.page.toast.disconnectFailed"))}finally{b(!1)}},[g,n,N,e]),j=o.useCallback(async k=>{if(k){b(!0);try{const W=n?await n.authActivate(k):await(async()=>{const D=await yt("/api/github/auth/activate",{method:"POST",headers:{"Content-Type":"application/json",Accept:"application/json"},body:JSON.stringify({accountId:k})}),L=await D.json().catch(()=>null);if(!D.ok||!L)throw new Error(L?.error||D.statusText);return L})();c(W),E.success(e("settings.github.page.toast.accountSwitched"))}catch(W){console.error("Failed to switch GitHub account:",W),E.error(e("settings.github.page.toast.accountSwitchFailed"))}finally{b(!1)}}},[n,c,e]);if(i&&!l)return null;const h=!!r?.connected,w=r?.user,T=(r?.accounts??[]).filter(k=>!k.current),S=r?.ghCli??null,M=S?.active?e("settings.github.page.accountSource.cli"):e("settings.github.page.accountSource.oauth"),V=s.jsxs(s.Fragment,{children:[s.jsxs("div",{className:"rounded-lg bg-[var(--surface-elevated)]/70 overflow-hidden flex flex-col",children:[h?s.jsxs("div",{className:fe("px-4 py-3",a?"flex flex-col gap-3":"flex items-center justify-between gap-4"),children:[s.jsxs("div",{className:fe("flex min-w-0 items-center gap-4",a?"w-full":void 0),children:[w?.avatarUrl?s.jsx("img",{src:w.avatarUrl,alt:w.login?e("settings.github.page.avatarAlt.withLogin",{login:w.login}):e("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:w?.name?.trim()||w?.login||"GitHub"}),s.jsxs("div",{className:fe("flex items-center gap-2 typography-meta text-muted-foreground mt-0.5",a?"flex-wrap":"truncate"),children:[s.jsx(F,{name:"github-fill",className:"h-3.5 w-3.5 shrink-0"}),s.jsx("span",{className:"font-mono",children:w?.login||e("settings.github.page.label.unknownUser")}),w?.email&&s.jsx("span",{className:"opacity-50",children:"•"}),w?.email&&s.jsx("span",{children:w.email}),s.jsx("span",{className:"opacity-50",children:"•"}),s.jsx("span",{children:M})]}),r?.scope&&s.jsx("div",{className:"typography-micro text-muted-foreground/70 mt-0.5",children:e("settings.github.page.label.scopes",{value:r.scope})}),S?.active&&s.jsx("div",{className:"typography-micro text-muted-foreground/70 mt-0.5",children:e("settings.github.page.ghCli.activeDescription")})]})]}),S?.active?s.jsx(B,{size:"sm",variant:"outline",onClick:()=>R(!0),disabled:p,className:fe(a?"w-full":void 0),children:e("settings.github.page.ghCli.actions.disable")}):s.jsx(B,{size:"sm",variant:"outline",onClick:I,disabled:p,className:fe("text-[var(--status-error)] hover:text-[var(--status-error)]",a?"w-full":void 0),children:e("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:e("settings.github.page.status.notConnected")})}),s.jsx(B,{size:"sm",variant:"default",onClick:m,disabled:p,children:e("settings.github.page.actions.connect")})]}),T.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:e("settings.github.page.label.otherAccounts")}),s.jsx("div",{className:"space-y-1",children:T.map(k=>{const W=k.user,D=k.source==="gh-cli"?e("settings.github.page.accountSource.cli"):e("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:[W?.avatarUrl?s.jsx("img",{src:W.avatarUrl,alt:W.login?e("settings.github.page.avatarAlt.withLogin",{login:W.login}):e("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(F,{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:W?.name?.trim()||W?.login||"GitHub"}),W?.login&&s.jsxs("span",{className:"typography-micro text-muted-foreground truncate",children:[s.jsx("span",{className:"font-mono",children:W.login}),s.jsx("span",{className:"mx-1 opacity-50",children:"·"}),s.jsx("span",{children:D})]})]})]}),s.jsx(B,{size:"sm",variant:"ghost",onClick:()=>j(k.id),disabled:p,children:e("settings.github.page.actions.switchTo")})]},k.id)})})]})]}),h&&s.jsx("div",{className:"mt-2 px-2 pb-2",children:s.jsx(B,{size:"sm",variant:"outline",onClick:m,disabled:p,className:fe(a?"w-full":void 0),children:e("settings.github.page.actions.addAccount")})}),d&&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(Zs,{children:e("settings.github.page.flow.title")}),s.jsx("p",{className:"typography-meta text-muted-foreground",children:e("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:d.userCode}),s.jsx(B,{size:"sm",asChild:!0,children:s.jsx("a",{href:d.verificationUriComplete||d.verificationUri,target:"_blank",rel:"noopener noreferrer",children:e("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:e("settings.github.page.flow.waiting")}),s.jsx(B,{size:"sm",variant:"ghost",disabled:p,onClick:()=>{N(),C(null)},children:e("settings.common.actions.cancel")})]})]})]}),$=S?.available&&!S?.active&&(!S.user||S.disabled)?s.jsx(s.Fragment,{children:s.jsx("div",{className:"rounded-lg bg-[var(--surface-elevated)]/70 overflow-hidden",children:s.jsxs("div",{className:fe("px-4 py-3",a?"flex flex-col gap-3":"flex items-center justify-between gap-4"),children:[s.jsxs("div",{className:fe("flex min-w-0 items-center gap-4",a?"w-full":void 0),children:[S.user?.avatarUrl?s.jsx("img",{src:S.user.avatarUrl,alt:S.user.login?e("settings.github.page.avatarAlt.withLogin",{login:S.user.login}):e("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(F,{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:fe("flex items-center gap-2 typography-meta text-muted-foreground mt-0.5",a?"flex-wrap":"truncate"),children:[s.jsx(F,{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:fe("typography-meta text-muted-foreground",S.disabled?"opacity-60":void 0),children:S.disabled?e("settings.github.page.ghCli.disabledDescription"):e("settings.github.page.ghCli.fallbackDescription")})]})]}),s.jsx(B,{size:"sm",variant:"outline",onClick:()=>R(!S.disabled),disabled:p,className:fe(a?"w-full":void 0),children:S.disabled?e("settings.github.page.ghCli.actions.enable"):e("settings.github.page.ghCli.actions.disable")})]})})}):null;return t?s.jsxs("div",{className:"space-y-4",children:[V,$?s.jsxs("div",{className:"space-y-2",children:[s.jsx(Zs,{children:e("settings.github.page.ghCli.title")}),$]}):null]}):s.jsxs(s.Fragment,{children:[s.jsx(ze,{title:e("settings.github.page.oauth.title"),divider:!1,settingsItem:"git.github-account",info:e("settings.github.page.tooltip.connectAccount"),children:V}),$?s.jsx(ze,{title:e("settings.github.page.ghCli.title"),children:$}):null]})},xh=()=>{const t=ut.c(37),{t:e}=tt(),a=Cn(vh),n=Cn(yh),r=Cn(bh),[i,l]=o.useState(!1),g=a?.connected===!0;let c;t[0]!==g||t[1]!==r||t[2]!==n||t[3]!==a?.user?.login||t[4]!==e?(c=n&&!r?e("common.loading"):g?a?.user?.login?.trim()||e("settings.github.page.status.active"):e("settings.integrations.github.status.notConnected"),t[0]=g,t[1]=r,t[2]=n,t[3]=a?.user?.login,t[4]=e,t[5]=c):c=t[5];const y=c,p=g?"bg-[var(--status-success)]/15 text-[var(--status-success)]":"bg-[var(--surface-muted)] text-muted-foreground";let b;t[6]===Symbol.for("react.memo_cache_sentinel")?(b=s.jsx("div",{className:"flex size-10 shrink-0 items-center justify-center rounded-[10px] bg-[var(--surface-muted)]",children:s.jsx(F,{name:"github-fill",className:"size-5 text-foreground"})}),t[6]=b):b=t[6];let d;t[7]!==e?(d=e("settings.integrations.github.title"),t[7]=e,t[8]=d):d=t[8];let C;t[9]!==d?(C=s.jsx("div",{className:"truncate text-sm font-semibold text-foreground",children:d}),t[9]=d,t[10]=C):C=t[10];let f;t[11]!==e?(f=e("settings.integrations.github.description"),t[11]=e,t[12]=f):f=t[12];let P;t[13]!==f?(P=s.jsx("p",{className:"mt-0.5 line-clamp-1 text-xs leading-snug text-muted-foreground",children:f}),t[13]=f,t[14]=P):P=t[14];let x;t[15]!==C||t[16]!==P?(x=s.jsxs("div",{className:"min-w-0 flex-1",children:[C,P]}),t[15]=C,t[16]=P,t[17]=x):x=t[17];let N;t[18]!==p?(N=fe("max-w-36 shrink-0 truncate rounded-full px-2 py-0.5 text-[10px] font-medium",p),t[18]=p,t[19]=N):N=t[19];let m;t[20]!==y||t[21]!==N?(m=s.jsx("span",{"aria-live":"polite",className:N,children:y}),t[20]=y,t[21]=N,t[22]=m):m=t[22];const A=i&&"rotate-180";let R;t[23]!==A?(R=fe("size-4 shrink-0 text-muted-foreground transition-transform duration-150 ease-out motion-reduce:transition-none",A),t[23]=A,t[24]=R):R=t[24];let I;t[25]!==R?(I=s.jsx(F,{name:"arrow-down-s",className:R}),t[25]=R,t[26]=I):I=t[26];let j;t[27]!==I||t[28]!==x||t[29]!==m?(j=s.jsxs(Tn,{className:"flex w-full min-w-0 items-center gap-3 px-4 py-3 text-left hover:bg-[var(--interactive-hover)]/50 focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-inset focus-visible:ring-[var(--interactive-focus-ring)]",children:[b,x,m,I]}),t[27]=I,t[28]=x,t[29]=m,t[30]=j):j=t[30];let h;t[31]===Symbol.for("react.memo_cache_sentinel")?(h=s.jsx(En,{className:"border-t border-[var(--interactive-border)] px-4 py-4",children:s.jsx(fh,{embedded:!0})}),t[31]=h):h=t[31];let w;t[32]!==j?(w=s.jsxs("div",{"data-settings-item":"integrations.github",className:"overflow-hidden rounded-xl border border-[var(--interactive-border)] bg-[var(--surface-elevated)]",children:[j,h]}),t[32]=j,t[33]=w):w=t[33];let O;return t[34]!==i||t[35]!==w?(O=s.jsx(An,{open:i,onOpenChange:l,children:w}),t[34]=i,t[35]=w,t[36]=O):O=t[36],O};function vh(t){return t.status}function yh(t){return t.isLoading}function bh(t){return t.hasChecked}const mi="__none__",gi="__inherit__";function wh({linear:t,connected:e,organizationId:a}){const{t:n}=tt(),r=Ws(x=>x.projects),[i,l]=o.useState(null),[g,c]=o.useState(!1),[y,p]=o.useState(!1),b=o.useCallback(async()=>{if(!e){l(null),c(!1);return}try{const x=await t.mappingGet();if(x.connected===!1){l(null),c(!1);return}l(x),c(!1)}catch(x){console.error("Failed to load Linear mapping:",x),c(!0)}},[e,t]);o.useEffect(()=>{b()},[b,a]);const d=o.useCallback(async x=>{const N={};for(const m of x.teams??[])m.projectPath&&(N[m.id]=m.projectPath);p(!0),ga("saving");try{const m=await t.mappingSet({defaultProjectPath:x.defaultProjectPath??null,teamProjectPaths:N});if(m.connected===!1){l(null),ga("error");return}l(m),c(!1),ga("saved")}catch(m){console.error("Failed to save Linear mapping:",m),ga("error")}finally{p(!1)}},[t]);if(!e)return null;if(g&&!i)return s.jsx("p",{className:"text-xs text-muted-foreground",children:n("settings.integrations.linear.mapping.loadFailed")});if(!i)return null;const C=x=>r.find(m=>m.path===x)?.label?.trim()||x,f=x=>!x||x===mi?n("settings.integrations.linear.mapping.defaultProject.placeholder"):C(x),P=x=>!x||x===gi?n("settings.integrations.linear.mapping.teams.useDefault"):C(x);return s.jsxs("div",{className:Qs,children:[r.length===0?s.jsx("p",{className:"text-xs text-muted-foreground",children:n("settings.integrations.linear.mapping.emptyProjects")}):null,s.jsx(Rt,{label:n("settings.integrations.linear.mapping.defaultProject"),info:n("settings.integrations.linear.mapping.defaultProject.info"),settingsItem:"integrations.linear.mapping",children:s.jsxs(St,{value:i.defaultProjectPath||mi,disabled:y||r.length===0,onValueChange:x=>{d({...i,defaultProjectPath:x===mi?null:x})},children:[s.jsx(Ct,{size:Ft,className:rn,"aria-label":n("settings.integrations.linear.mapping.defaultProject.aria"),children:s.jsx(Mt,{placeholder:n("settings.integrations.linear.mapping.defaultProject.placeholder"),children:f})}),s.jsxs(It,{children:[s.jsx(at,{value:mi,children:n("settings.integrations.linear.mapping.defaultProject.placeholder")}),i.defaultProjectPath&&!r.some(x=>x.path===i.defaultProjectPath)?s.jsx(at,{value:i.defaultProjectPath,children:i.defaultProjectPath}):null,r.map(x=>s.jsx(at,{value:x.path,children:C(x.path)},x.id))]})]})}),s.jsx(Ss,{title:n("settings.integrations.linear.mapping.teams"),info:n("settings.integrations.linear.mapping.teams.info"),children:(i.teams??[]).length===0?s.jsx("p",{className:"text-xs text-muted-foreground",children:n("settings.integrations.linear.mapping.emptyTeams")}):s.jsx("div",{className:Qs,children:(i.teams??[]).map(x=>s.jsx(Rt,{label:`${x.key} · ${x.name}`,children:s.jsxs(St,{value:x.projectPath||gi,disabled:y||r.length===0,onValueChange:N=>{d({...i,teams:(i.teams??[]).map(m=>m.id===x.id?{...m,projectPath:N===gi?null:N}:m)})},children:[s.jsx(Ct,{size:Ft,className:rn,"aria-label":n("settings.integrations.linear.mapping.teams.aria",{team:x.key}),children:s.jsx(Mt,{placeholder:n("settings.integrations.linear.mapping.teams.useDefault"),children:P})}),s.jsxs(It,{children:[s.jsx(at,{value:gi,children:n("settings.integrations.linear.mapping.teams.useDefault")}),x.projectPath&&!r.some(N=>N.path===x.projectPath)?s.jsx(at,{value:x.projectPath,children:x.projectPath}):null,r.map(N=>s.jsx(at,{value:N.path,children:C(N.path)},N.id))]})]})},x.id))})})]})}function jh({linear:t,connected:e}){const{t:a}=tt(),[n,r]=o.useState(null),[i,l]=o.useState(!1),[g,c]=o.useState(!1);o.useEffect(()=>{if(!e){r(null),l(!1);return}let p=!1;return t.preferencesGet().then(b=>{p||(r(b.sessionComments),l(!1))}).catch(()=>{p||l(!0)}),()=>{p=!0}},[e,t]);const y=o.useCallback(async p=>{const b=n;r(p),c(!0);try{const d=await t.preferencesSet({sessionComments:p});r(d.sessionComments),ga("saved")}catch{r(b),ga("error")}finally{c(!1)}},[n,t]);return e?i?s.jsx("p",{className:"text-xs text-muted-foreground",children:a("settings.integrations.linear.sessionComments.loadFailed")}):s.jsx("div",{className:Qs,children:s.jsx(Rt,{label:a("settings.integrations.linear.sessionComments.label"),info:a("settings.integrations.linear.sessionComments.info"),settingsItem:"integrations.linear.session-comments",children:s.jsx(xi,{checked:n===!0,disabled:n===null||g,onCheckedChange:p=>{y(p)},"aria-label":a("settings.integrations.linear.sessionComments.aria")})})}):null}const kh=3*6e4,Nh=1500;function Yo(t){const e=t?.workspaces??[],a=e.find(n=>n.current);return{connected:!!t?.connected,ids:e.map(n=>n.id).slice().sort().join(","),currentId:a?.id||t?.organization?.id||"",currentAuthorizedAt:a?.authorizedAt??0}}function Sh(t,e){return e.connected?t.connected?e.ids!==t.ids||e.currentId!==t.currentId||e.currentAuthorizedAt!==t.currentAuthorizedAt:!0:!1}const Ch=()=>{const{t}=tt(),e=fa()?.linear,a=oa(S=>S.status),n=oa(S=>S.isLoading),r=oa(S=>S.hasChecked),i=oa(S=>S.refreshStatus),l=oa(S=>S.setStatus),[g,c]=o.useState(!1),[y,p]=o.useState(!1),[b,d]=o.useState(!1),C=o.useRef(null),f=o.useCallback(()=>{C.current!=null&&(window.clearInterval(C.current),C.current=null),p(!1)},[]);o.useEffect(()=>{if(e)return r||i(e),()=>{f()}},[r,i,e,f]);const P=o.useCallback(async()=>{if(!e)return;f(),c(!0);const S=Yo(oa.getState().status);try{const M=await e.authStart(as()?"desktop":"web");p(!0),d(!0),Pn(M.authorizationUrl);const V=Date.now()+kh;C.current=window.setInterval(()=>{(async()=>{if(Date.now()>V){f(),E.error(t("settings.integrations.linear.toast.authorizationFailed"));return}const $=await i(e,{force:!0});Sh(S,Yo($))&&(f(),E.success(t("settings.integrations.linear.toast.connected")),Ad())})()},Nh)}catch(M){console.error("Failed to start Linear connect:",M),E.error(t("settings.integrations.linear.toast.startConnectFailed")),f()}finally{c(!1)}},[i,e,f,t]),x=o.useCallback(async S=>{if(!(!e||!S)){c(!0);try{const M=await e.authActivate(S);l(M),E.success(t("settings.integrations.linear.toast.workspaceSwitched"))}catch(M){console.error("Failed to switch Linear workspace:",M),E.error(t("settings.integrations.linear.toast.workspaceSwitchFailed"))}finally{c(!1)}}},[e,l,t]),N=o.useCallback(async()=>{if(e){c(!0);try{f(),await e.authDisconnect(),E.success(t("settings.integrations.linear.toast.disconnected")),await i(e,{force:!0})}catch(S){console.error("Failed to disconnect Linear:",S),E.error(t("settings.integrations.linear.toast.disconnectFailed"))}finally{c(!1)}}},[i,e,f,t]);if(!e)return null;const m=!!a?.connected,A=a?.user,R=a?.organization,j=(a?.workspaces??[]).filter(S=>!S.current),h=A?.displayName?.trim()||A?.name?.trim()||t("settings.integrations.linear.label.unknownUser"),w=y?t("settings.integrations.linear.status.waiting"):n&&!r?t("common.loading"):m?R?.name?.trim()||t("settings.integrations.linear.status.connected"):t("settings.integrations.linear.status.notConnected"),O=y?"bg-[var(--status-warning)]/15 text-[var(--status-warning)]":m?"bg-[var(--status-success)]/15 text-[var(--status-success)]":"bg-[var(--surface-muted)] text-muted-foreground",T=y||b;return s.jsx(An,{open:T,onOpenChange:S=>{if(y){d(!0);return}d(S)},children:s.jsxs("div",{"data-settings-item":"integrations.linear",className:"overflow-hidden rounded-xl border border-[var(--interactive-border)] bg-[var(--surface-elevated)]",children:[s.jsxs(Tn,{className:"flex w-full min-w-0 items-center gap-3 px-4 py-3 text-left hover:bg-[var(--interactive-hover)]/50 focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-inset focus-visible:ring-[var(--interactive-focus-ring)]",children:[s.jsx("div",{className:"flex size-10 shrink-0 items-center justify-center rounded-[10px] bg-[var(--surface-muted)]",children:s.jsx(F,{name:"linear",className:"size-5 text-foreground"})}),s.jsxs("div",{className:"min-w-0 flex-1",children:[s.jsx("div",{className:"truncate text-sm font-semibold text-foreground",children:t("settings.integrations.linear.title")}),s.jsx("p",{className:"mt-0.5 line-clamp-1 text-xs leading-snug text-muted-foreground",children:t("settings.integrations.linear.description")})]}),s.jsx("span",{"aria-live":"polite",className:fe("max-w-36 shrink-0 truncate rounded-full px-2 py-0.5 text-[10px] font-medium",O),children:w}),s.jsx(F,{name:"arrow-down-s",className:fe("size-4 shrink-0 text-muted-foreground transition-transform duration-150 ease-out motion-reduce:transition-none",T&&"rotate-180")})]}),s.jsx(En,{className:"border-t border-[var(--interactive-border)] px-4 py-4",children:s.jsxs("div",{className:"space-y-3",children:[m?s.jsxs("div",{className:"flex min-w-0 items-center gap-3",children:[A?.avatarUrl?s.jsx("img",{src:A.avatarUrl,alt:t("settings.integrations.linear.avatarAlt.withName",{name:h}),className:"size-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 size-10 shrink-0 items-center justify-center rounded-full border border-[var(--interactive-border)] bg-[var(--surface-muted)]",children:s.jsx(F,{name:"linear",className:"size-4 text-muted-foreground"})}),s.jsxs("div",{className:"min-w-0 flex-1",children:[s.jsx("div",{className:"truncate text-sm font-medium text-foreground",children:h}),s.jsx("p",{className:"mt-0.5 truncate text-xs text-muted-foreground",children:[R?.name,A?.email].filter(Boolean).join(" · ")})]})]}):y?s.jsx("p",{className:"text-xs text-muted-foreground",children:t("settings.integrations.linear.flow.description")}):null,m?s.jsxs(s.Fragment,{children:[s.jsx(wh,{linear:e,connected:m,organizationId:R?.id??null}),s.jsx(jh,{linear:e,connected:m}),j.length>0?s.jsxs("div",{className:"space-y-2",children:[s.jsx("p",{className:"typography-micro text-muted-foreground",children:t("settings.integrations.linear.label.otherWorkspaces")}),s.jsx("div",{className:"space-y-1",children:j.map(S=>{const M=S.user,V=S.name?.trim()||t("settings.integrations.linear.status.connected");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:"min-w-0",children:[s.jsx("div",{className:"truncate text-sm font-medium text-foreground",children:V}),M?.email?s.jsx("p",{className:"truncate text-xs text-muted-foreground",children:M.email}):null]}),s.jsx(B,{type:"button",size:"sm",variant:"ghost",onClick:()=>{x(S.id)},disabled:g,children:t("settings.integrations.linear.actions.switchTo")})]},S.id)})})]}):null,s.jsxs("div",{className:"flex flex-wrap items-center gap-2",children:[s.jsx(B,{type:"button",size:"sm",variant:"outline",onClick:()=>{P()},disabled:g||y,"data-settings-item":"integrations.linear.add-workspace",children:t("settings.integrations.linear.actions.addWorkspace")}),s.jsx(B,{type:"button",size:"sm",variant:"destructive",onClick:()=>{N()},disabled:g,children:t("settings.integrations.linear.actions.disconnect")})]})]}):y?s.jsxs("div",{className:"flex flex-wrap items-center gap-2",children:[s.jsx("span",{className:"typography-micro text-muted-foreground animate-pulse",children:t("settings.integrations.linear.flow.waiting")}),s.jsx(B,{type:"button",size:"sm",variant:"ghost",disabled:g,onClick:f,children:t("settings.common.actions.cancel")})]}):s.jsxs(B,{type:"button",size:"sm",variant:"default",onClick:()=>{P()},disabled:g||n&&!r,children:[g?s.jsx(F,{name:"loader-4",className:"size-3.5 animate-spin"}):null,t("settings.integrations.linear.actions.connect")]})]})})]})})},Ih=()=>{const t=ut.c(18),{t:e}=tt();let a;t[0]===Symbol.for("react.memo_cache_sentinel")?(a=cs(),t[0]=a):a=t[0];const n=!a,r=!!fa()?.linear;let i;t[1]!==e?(i=e("settings.page.integrations.title"),t[1]=e,t[2]=i):i=t[2];let l;t[3]!==e?(l=e("settings.page.integrations.description"),t[3]=e,t[4]=l):l=t[4];let g;t[5]!==e?(g=e("settings.integrations.firstParty.title"),t[5]=e,t[6]=g):g=t[6];let c;t[7]!==e?(c=e("settings.integrations.firstParty.info"),t[7]=e,t[8]=c):c=t[8];let y,p;t[9]===Symbol.for("react.memo_cache_sentinel")?(y=n?s.jsx(xh,{}):null,p=r?s.jsx(Ch,{}):null,t[9]=y,t[10]=p):(y=t[9],p=t[10]);let b;t[11]!==g||t[12]!==c?(b=s.jsxs(ze,{title:g,info:c,divider:!1,settingsItem:"integrations.first-party",contentClassName:"space-y-3",children:[y,p]}),t[11]=g,t[12]=c,t[13]=b):b=t[13];let d;return t[14]!==i||t[15]!==l||t[16]!==b?(d=s.jsx(es,{title:i,description:l,showSaveStatus:!0,children:b}),t[14]=i,t[15]=l,t[16]=b,t[17]=d):d=t[17],d},Ph=[{value:"system",labelKey:"settings.aiworker.visual.option.themeMode.system",descriptionKey:"settings.aiworker.visual.option.themeMode.system.description"},{value:"light",labelKey:"settings.aiworker.visual.option.themeMode.light",descriptionKey:"settings.aiworker.visual.option.themeMode.light.description"},{value:"dark",labelKey:"settings.aiworker.visual.option.themeMode.dark",descriptionKey:"settings.aiworker.visual.option.themeMode.dark.description"}],Ah=[{id:"dynamic",labelKey:"settings.aiworker.visual.option.diffLayout.dynamic.label",descriptionKey:"settings.aiworker.visual.option.diffLayout.dynamic.description"},{id:"inline",labelKey:"settings.aiworker.visual.option.diffLayout.inline.label",descriptionKey:"settings.aiworker.visual.option.diffLayout.inline.description"},{id:"side-by-side",labelKey:"settings.aiworker.visual.option.diffLayout.sideBySide.label",descriptionKey:"settings.aiworker.visual.option.diffLayout.sideBySide.description"}],Th=[{id:"svg",labelKey:"settings.aiworker.visual.option.mermaidRendering.svg.label",descriptionKey:"settings.aiworker.visual.option.mermaidRendering.svg.description"},{id:"ascii",labelKey:"settings.aiworker.visual.option.mermaidRendering.ascii.label",descriptionKey:"settings.aiworker.visual.option.mermaidRendering.ascii.description"}],Da="AiWorker - AI Coding Assistant",Zo=[{id:"system",labelKey:"settings.aiworker.visual.option.pwaOrientation.system.label",descriptionKey:"settings.aiworker.visual.option.pwaOrientation.system.description"},{id:"portrait",labelKey:"settings.aiworker.visual.option.pwaOrientation.portrait.label",descriptionKey:"settings.aiworker.visual.option.pwaOrientation.portrait.description"},{id:"landscape",labelKey:"settings.aiworker.visual.option.pwaOrientation.landscape.label",descriptionKey:"settings.aiworker.visual.option.pwaOrientation.landscape.description"}],Xo=[{id:"native",labelKey:"settings.aiworker.visual.option.mobileKeyboardMode.native.label",descriptionKey:"settings.aiworker.visual.option.mobileKeyboardMode.native.description"},{id:"resize-content",labelKey:"settings.aiworker.visual.option.mobileKeyboardMode.resizeContent.label",descriptionKey:"settings.aiworker.visual.option.mobileKeyboardMode.resizeContent.description"}],nr=t=>t==="portrait"||t==="landscape"?t:"system",Eh=[{id:"markdown",labelKey:"settings.aiworker.visual.option.userMessageRendering.markdown.label",descriptionKey:"settings.aiworker.visual.option.userMessageRendering.markdown.description"},{id:"plain",labelKey:"settings.aiworker.visual.option.userMessageRendering.plain.label",descriptionKey:"settings.aiworker.visual.option.userMessageRendering.plain.description"}],Dh=[{id:"sorted",labelKey:"settings.aiworker.visual.option.chatRenderMode.sorted.label",descriptionKey:"settings.aiworker.visual.option.chatRenderMode.sorted.description"},{id:"live",labelKey:"settings.aiworker.visual.option.chatRenderMode.live.label",descriptionKey:"settings.aiworker.visual.option.chatRenderMode.live.description"}],el=[{id:"auto",labelKey:"settings.aiworker.visual.option.messageTransport.auto.label",descriptionKey:"settings.aiworker.visual.option.messageTransport.auto.description"},{id:"ws",labelKey:"settings.aiworker.visual.option.messageTransport.ws.label",descriptionKey:"settings.aiworker.visual.option.messageTransport.ws.description"},{id:"sse",labelKey:"settings.aiworker.visual.option.messageTransport.sse.label",descriptionKey:"settings.aiworker.visual.option.messageTransport.sse.description"}],Mh=[{id:"collapsed",labelKey:"settings.aiworker.visual.option.activityRenderMode.collapsed.label",descriptionKey:"settings.aiworker.visual.option.activityRenderMode.collapsed.description"},{id:"summary",labelKey:"settings.aiworker.visual.option.activityRenderMode.summary.label",descriptionKey:"settings.aiworker.visual.option.activityRenderMode.summary.description"}],tl=[{id:"auto",labelKey:"settings.aiworker.visual.option.timeFormat.auto.label",descriptionKey:"settings.aiworker.visual.option.timeFormat.auto.description"},{id:"24h",labelKey:"settings.aiworker.visual.option.timeFormat.24h.label",descriptionKey:"settings.aiworker.visual.option.timeFormat.24h.description"},{id:"12h",labelKey:"settings.aiworker.visual.option.timeFormat.12h.label",descriptionKey:"settings.aiworker.visual.option.timeFormat.12h.description"}],sl=[{id:"auto",labelKey:"settings.aiworker.visual.option.weekStart.auto.label",descriptionKey:"settings.aiworker.visual.option.weekStart.auto.description"},{id:"monday",labelKey:"settings.aiworker.visual.option.weekStart.monday.label"},{id:"sunday",labelKey:"settings.aiworker.visual.option.weekStart.sunday.label"}],Rh=[{id:"steer",labelKey:"settings.aiworker.visual.option.followUpBehavior.steer.label"},{id:"queue",labelKey:"settings.aiworker.visual.option.followUpBehavior.queue.label"}],Lh=[{id:"ask",labelKey:"settings.aiworker.visual.option.largeTextPaste.ask.label"},{id:"attach",labelKey:"settings.aiworker.visual.option.largeTextPaste.attach.label"},{id:"inline",labelKey:"settings.aiworker.visual.option.largeTextPaste.inline.label"}],Oh=[{id:"global",labelKey:"settings.aiworker.visual.option.inputHistoryScope.global.label"},{id:"session",labelKey:"settings.aiworker.visual.option.inputHistoryScope.session.label"}],Fh=t=>t==="markdown"?"markdown":"plain",Kh=[{id:"left",labelKey:"settings.aiworker.desktopNetwork.option.windowControlsLeft"},{id:"right",labelKey:"settings.aiworker.desktopNetwork.option.windowControlsRight"}],zh=[{id:"classic",labelKey:"settings.aiworker.desktopNetwork.option.windowControlsClassic"},{id:"traffic-lights",labelKey:"settings.aiworker.desktopNetwork.option.windowControlsTrafficLights"}],Pi=({visibleSettings:t})=>{const{locale:e,locales:a,setLocale:n,label:r,t:i}=tt(),l=o.useCallback(u=>i(u),[i]),{isMobile:g}=wa(),{terminal:c}=Nl(),{browserTab:y}=qd(),p=Td(),b=ie(u=>u.showReasoningTraces),d=ie(u=>u.sessionRecapEnabled),C=ie(u=>u.sessionSuggestionEnabled),f=ie(u=>u.setSessionRecapEnabled),P=ie(u=>u.setSessionSuggestionEnabled),x=ie(u=>u.sessionGoalEnabled),N=ie(u=>u.setSessionGoalEnabled),m=ie(u=>u.sessionGoalDefaultBudgetEnabled),A=ie(u=>u.setSessionGoalDefaultBudgetEnabled),R=ie(u=>u.sessionGoalDefaultBudget),I=ie(u=>u.setSessionGoalDefaultBudget),j=ie(u=>u.setShowReasoningTraces),h=ie(u=>u.streamingAutoFollowEnabled),w=ie(u=>u.setStreamingAutoFollowEnabled),O=ie(u=>u.collapsibleThinkingBlocks),T=ie(u=>u.setCollapsibleThinkingBlocks),S=ie(u=>u.mermaidRenderingMode),M=ie(u=>u.setMermaidRenderingMode),V=ie(u=>u.userMessageRenderingMode),$=ie(u=>u.setUserMessageRenderingMode),k=ie(u=>u.collapsibleUserMessages),W=ie(u=>u.setCollapsibleUserMessages),D=ie(u=>u.stickyUserHeader),L=ie(u=>u.promptNavigatorEnabled),J=ie(u=>u.setStickyUserHeader),ee=ie(u=>u.setPromptNavigatorEnabled),U=ie(u=>u.autoSaveEnabled),re=ie(u=>u.setAutoSaveEnabled),_=ie(u=>u.wideChatLayoutEnabled),H=ie(u=>u.setWideChatLayoutEnabled),z=ie(u=>u.codeBlockLineWrap),K=ie(u=>u.setCodeBlockLineWrap),te=ie(u=>u.chatRenderMode),Y=ie(u=>u.setChatRenderMode),ne=ie(u=>u.activityRenderMode),me=ie(u=>u.setActivityRenderMode),de=ie(u=>u.fontSize),xe=ie(u=>u.setFontSize),ae=ie(u=>u.terminalFontSize),le=ie(u=>u.setTerminalFontSize),ge=ie(u=>u.terminalShell),Ae=ie(u=>u.setTerminalShell),Se=ie(u=>u.terminalLoginShells),Ce=ie(u=>u.setTerminalLoginShells),he=ie(u=>u.editorFontSize),_e=ie(u=>u.setEditorFontSize),Ue=ie(u=>u.uiFont),ke=ie(u=>u.setUiFont),Oe=ie(u=>u.monoFont),Ve=ie(u=>u.setMonoFont),We=ie(u=>u.padding),ve=ie(u=>u.setPadding),Z=ie(u=>u.inputBarOffset),se=ie(u=>u.setInputBarOffset),ye=ie(u=>u.mobileKeyboardMode),be=ie(u=>u.setMobileKeyboardMode),Re=ie(u=>u.diffLayoutPreference),Fe=ie(u=>u.setDiffLayoutPreference),Ke=ie(u=>u.showTerminalQuickKeysOnDesktop),Ee=ie(u=>u.sessionTabsEnabled),we=ie(u=>u.setSessionTabsEnabled),Ze=ie(u=>u.setShowTerminalQuickKeysOnDesktop),pe=ie(u=>u.fileEditorKeymap),Ne=ie(u=>u.setFileEditorKeymap),Le=Yr(u=>u.followUpBehavior),Xe=Yr(u=>u.setFollowUpBehavior),q=ai(u=>u.scope),je=ai(u=>u.entryLimit),Ie=ai(u=>u.applyScope),Je=ai(u=>u.applyEntryLimit),ot=ie(u=>u.persistChatDraft),st=ie(u=>u.setPersistChatDraft),mt=ie(u=>u.inputSpellcheckEnabled),vt=ie(u=>u.setInputSpellcheckEnabled),G=ie(u=>u.largeTextPasteBehavior),Ge=ie(u=>u.setLargeTextPasteBehavior),nt=ie(u=>u.enterToSend),lt=ie(u=>u.setEnterToSend),ht=ie(u=>u.enterToSendConfigured),Lt=ie(u=>u.setEnterToSendConfigured),et=ht?nt:!g,ft=ie(u=>u.showToolFileIcons),bt=ie(u=>u.setShowToolFileIcons),Be=ie(u=>u.showTurnChangedFiles),Et=ie(u=>u.setShowTurnChangedFiles),Me=ie(u=>u.showExpandedBashTools),wt=ie(u=>u.setShowExpandedBashTools),Q=ie(u=>u.showExpandedEditTools),ue=ie(u=>u.setShowExpandedEditTools),De=ie(u=>u.timeFormatPreference),Pe=ie(u=>u.setTimeFormatPreference),it=ie(u=>u.weekStartPreference),rt=ie(u=>u.setWeekStartPreference),qe=ie(u=>u.showSplitAssistantMessageActions),Pt=ie(u=>u.setShowSplitAssistantMessageActions),ys=ie(u=>u.allowPromptingSubagentSessions),Xt=ie(u=>u.setAllowPromptingSubagentSessions),Os=ie(u=>u.draftStartersVisible),Gt=ie(u=>u.setDraftStartersVisible),is=Ye(u=>u.settingsMessageStreamTransport),Ht=Ye(u=>u.setSettingsMessageStreamTransport),bs=is,gs=Ye(u=>u.settingsDefaultFileViewerPreview),hs=Ye(u=>u.setSettingsDefaultFileViewerPreview),ds=ie(u=>u.isSettingsDialogOpen),{themeMode:Es,setThemeMode:oe,availableThemes:ct,customThemesLoading:xt,reloadCustomThemes:Qt,lightThemeId:Yt,darkThemeId:Bt,setLightThemePreference:rs,setDarkThemePreference:ws}=Cr(),[ss,jt]=o.useState(!1),At=o.useMemo(()=>as()&&typeof window<"u"&&window.__AIWORKER_PLATFORM__==="darwin",[]),Ut=ie(u=>u.dockBadgeEnabled),Ot=ie(u=>u.setDockBadgeEnabled),ns=ie(u=>u.alwaysShowScrollbars===!0),Ds=ie(u=>u.setAlwaysShowScrollbars),Ai=Ed(),Ti=ie(u=>u.desktopWindowControlsPosition),Ha=ie(u=>u.setDesktopWindowControlsPosition),Ei=ie(u=>u.desktopWindowControlsStyle),Fs=ie(u=>u.setDesktopWindowControlsStyle),[ja,Di]=o.useState(0),Wa=ie(u=>u.reportUsage),Ga=ie(u=>u.setReportUsage),Mi=o.useCallback(u=>{Ga(u),pt({reportUsage:u})},[Ga]),Ri=o.useCallback(u=>{Ha(u),pt({desktopWindowControlsPosition:u})},[Ha]),Li=o.useCallback(u=>{Fs(u),pt({desktopWindowControlsStyle:u})},[Fs]),qa=(ds||g||cs())&&(t?t.includes("chatRenderMode"):!0);o.useEffect(()=>{if(!qa)return;let u=null,gt=Date.now();const ps=()=>{const sn=Date.now();sn-gt>=420&&(Di(Fn=>(Fn+1)%24),gt=sn),u=requestAnimationFrame(ps)};(typeof document>"u"||document.visibilityState==="visible")&&(u=requestAnimationFrame(ps));const Rs=()=>{document.visibilityState==="visible"&&u===null?u=requestAnimationFrame(ps):document.visibilityState!=="visible"&&u!==null&&(cancelAnimationFrame(u),u=null)};return document.addEventListener("visibilitychange",Rs),()=>{document.removeEventListener("visibilitychange",Rs),u!==null&&cancelAnimationFrame(u)}},[qa]);const js=o.useCallback(u=>{$(u),pt({userMessageRenderingMode:u})},[$]),Gs=o.useCallback(u=>{J(u),pt({stickyUserHeader:u})},[J]),Zn=o.useCallback(u=>{ee(u),pt({promptNavigatorEnabled:u})},[ee]),mn=o.useCallback(u=>{Gt(u),pt({draftStartersVisible:u})},[Gt]),xn=o.useCallback(u=>{W(u),pt({collapsibleUserMessages:u})},[W]),Or=o.useCallback(u=>{H(u),pt({wideChatLayoutEnabled:u})},[H]),Xs=o.useCallback(u=>{Pt(u),pt({showSplitAssistantMessageActions:u})},[Pt]),Oi=o.useCallback(u=>{vt(u),pt({inputSpellcheckEnabled:u})},[vt]),Dn=o.useCallback(u=>{lt(u),Lt(!0),pt({enterToSend:u,enterToSendConfigured:!0})},[lt,Lt]),Xn=o.useCallback(u=>{Y(u),pt({chatRenderMode:u})},[Y]),Mn=o.useCallback(u=>{Ht(u),pt({messageStreamTransport:u})},[Ht]),ka=o.useCallback(u=>{Ie(u),pt({inputHistoryScope:u})},[Ie]),Fi=o.useCallback(u=>{const gt=Math.round(u);Dd(gt)&&(Je(gt),pt({inputHistoryLimit:gt}))},[Je]),os=o.useCallback(u=>{me(u),pt({activityRenderMode:u})},[me]),Ki=o.useCallback(u=>{M(u),pt({mermaidRenderingMode:u})},[M]),ea=o.useCallback(u=>{bt(u),pt({showToolFileIcons:u})},[bt]),ta=o.useCallback(u=>{Et(u),pt({showTurnChangedFiles:u})},[Et]),zi=o.useCallback(u=>{hs(u),pt({defaultFileViewerPreview:u}),window.dispatchEvent(new CustomEvent("aiworker:file-viewer-preview-mode-changed",{detail:{enabled:u}}))},[hs]),Ja=o.useCallback(u=>{wt(u),pt({showExpandedBashTools:u})},[wt]),Ui=o.useCallback(u=>{ue(u),pt({showExpandedEditTools:u})},[ue]),Qa=o.useCallback(u=>{Pe(u),pt({timeFormatPreference:u})},[Pe]),sa=o.useCallback(u=>{rt(u),pt({weekStartPreference:u})},[rt]),gn=o.useMemo(()=>ct.filter(u=>u.metadata.variant==="light").sort((u,gt)=>u.metadata.name.localeCompare(gt.metadata.name)),[ct]),Rn=o.useMemo(()=>ct.filter(u=>u.metadata.variant==="dark").sort((u,gt)=>u.metadata.name.localeCompare(gt.metadata.name)),[ct]),Na=o.useMemo(()=>gn.find(u=>u.metadata.id===Yt)??gn[0],[gn,Yt]),vn=o.useMemo(()=>Rn.find(u=>u.metadata.id===Bt)??Rn[0],[Rn,Bt]),na=o.useCallback((u,gt)=>{const ps=gt==="dark"?" Dark":" Light";return u.endsWith(ps)?u.slice(0,-ps.length):u},[]),ce=u=>t?t.includes(u):!0,ls=cs(),aa=ce("theme")&&!ls,Ya=ce("windowControlsPosition")&&Ai,Za=ce("theme")||ce("timeFormat")||ce("weekStart"),Xa=ls?Za:ce("theme")||Ya||ce("pwaInstallName")||ce("pwaOrientation")||ce("timeFormat")||ce("weekStart"),ei=ce("fontSize")||ce("terminalFontSize")||ce("editorFontSize")||ce("spacing")||ce("scrollbars")&&!aa||ce("inputBarOffset")&&g,ti=ce("terminalQuickKeys")&&!g||(ce("terminalShell")||ce("terminalLoginShell"))&&!ls||ce("fileEditorKeymap")||ce("autoSaveEnabled")||ce("sessionTabs")&&!ls&&!g,_i=ce("mermaidRendering")||ce("sessionGoal")&&!ls||ce("userMessageRendering")||ce("chatRenderMode")||ce("messageTransport")||ce("activityRenderMode")||ce("collapsibleUserMessages")||ce("stickyUserHeader")||ce("promptNavigatorEnabled")&&!ls||ce("wideChatLayout")||ce("codeBlockLineWrap")||ce("splitAssistantMessageActions")||ce("subagentReadOnlyBanner")||ce("diffLayout")||ce("dotfiles")||ce("fileViewerPreview")||ce("reasoning")||ce("followUpBehavior")||ce("inputHistoryScope")||ce("inputHistoryLimit")||ce("persistDraft")||ce("largeTextPaste")||ce("showToolFileIcons")||ce("expandedTools")||!g&&ce("inputSpellcheck")||ce("enterToSend"),en=ce("chatRenderMode")||ce("activityRenderMode"),yn=ce("messageTransport"),ia=ce("userMessageRendering")||ce("mermaidRendering")||ce("diffLayout")&&!ls||ce("followUpBehavior")||ce("inputHistoryScope")||ce("inputHistoryLimit"),$i=ce("sessionAssist")||ce("sessionGoal")&&!ls||ce("subagentReadOnlyBanner")||ce("collapsibleUserMessages")||ce("stickyUserHeader")||ce("promptNavigatorEnabled")&&!ls||ce("wideChatLayout")||ce("codeBlockLineWrap")||ce("splitAssistantMessageActions")||ce("dotfiles")||ce("fileViewerPreview")||ce("persistDraft")||ce("largeTextPaste")||ce("showToolFileIcons")||ce("showTurnChangedFiles")||!g&&ce("inputSpellcheck")||ce("enterToSend")||ce("reasoning")||ce("expandedTools"),v=Xa||ei||ti,X=ce("pwaInstallName")&&Bn()&&y&&!as()&&!ls,Te=ce("pwaOrientation")&&Bn()&&!as()&&!ls,Qe=ce("mobileKeyboardMode")&&Bn()&&!as()&&!ls&&Md(),Dt=(ce("terminalShell")||ce("terminalLoginShell"))&&!ls,[ks,us]=o.useState([]),[$s,Ns]=o.useState(0);o.useEffect(()=>Ml(()=>{us([]),Ns(u=>u+1)}),[]),o.useEffect(()=>{let u=!1;if(!(!Dt||!c.listShells))return c.listShells().then(gt=>{u||us(gt)}).catch(()=>{u||us([])}),()=>{u=!0}},[Dt,c,$s]);const qs=o.useMemo(()=>{const u=ks.filter(gt=>gt.id!=="auto");return ge==="auto"||u.some(gt=>gt.id===ge)?u:[{id:ge,name:ge,supportsLogin:!1},...u]},[ks,ge]),Sa=ks.find(u=>u.id===ge)?.supportsLogin===!0,Ln=Se.includes(ge),Ca=u=>{Ce(u?[...Se.filter(gt=>gt!==ge),ge]:Se.filter(gt=>gt!==ge))},[kt,Wt]=o.useState(""),[tn,Nt]=o.useState("system"),Ms=o.useMemo(()=>{const u=tl.find(gt=>gt.id===De);return l(u?.labelKey??"settings.aiworker.visual.option.timeFormat.auto.label")},[De,l]),On=o.useMemo(()=>{const u=sl.find(gt=>gt.id===it);return l(u?.labelKey??"settings.aiworker.visual.option.weekStart.auto.label")},[it,l]),ra=o.useMemo(()=>{const u=Zo.find(gt=>gt.id===tn);return u?l(u.labelKey):void 0},[tn,l]),si=o.useMemo(()=>{const u=Xo.find(gt=>gt.id===ye);return u?l(u.labelKey):void 0},[ye,l]),Vi=o.useCallback(async u=>{if(typeof window>"u")return;const gt=window,Rs=u.trim().replace(/\s+/g," ").slice(0,64);if(await pt({pwaAppName:Rs}),typeof gt.__AIWORKER_SET_PWA_INSTALL_NAME__=="function"){const sn=gt.__AIWORKER_SET_PWA_INSTALL_NAME__(Rs);Wt(sn);return}Wt(Rs||Da),gt.__AIWORKER_UPDATE_PWA_MANIFEST__?.()},[]),Fr=o.useCallback(async u=>{if(typeof window>"u")return;const gt=window,ps=nr(u);if(await pt({pwaOrientation:ps}),typeof gt.__AIWORKER_SET_PWA_ORIENTATION__=="function"){const Rs=gt.__AIWORKER_SET_PWA_ORIENTATION__(ps);Nt(Rs);return}Nt(ps),gt.__AIWORKER_UPDATE_PWA_MANIFEST__?.()},[]);o.useEffect(()=>{if(typeof window>"u"||!X&&!Te&&!Qe)return;let u=!1;return(async()=>{try{const ps=await pn();if(!ps){u||Wt(Da);return}const sn=(ps.pwaAppName??"").trim().replace(/\s+/g," ").slice(0,64),Fn=nr(ps.pwaOrientation),ni=so(ps.mobileKeyboardMode);u||(X&&Wt(sn||Da),Te&&Nt(Fn),Qe&&be(ni))}catch{u||(X&&Wt(Da),Te&&Nt("system"),Qe&&be("native"))}})(),()=>{u=!0}},[be,Qe,X,Te]);const Bi=ce("scrollbars")?s.jsx(dt,{checked:ns,onChange:Ds,label:i("settings.aiworker.visual.field.alwaysShowScrollbars"),info:i("settings.aiworker.visual.field.alwaysShowScrollbarsHint"),settingsItem:"appearance.scrollbars"}):null;return s.jsxs("div",{className:"space-y-0",children:[Xa&&s.jsxs("div",{className:"space-y-0",children:[aa&&s.jsxs(ze,{title:i("settings.aiworker.visual.section.colorModeAndTheme"),divider:!1,children:[s.jsxs(Sn,{children:[s.jsx("div",{className:Qs,children:s.jsx(Js,{"aria-label":i("settings.aiworker.visual.section.colorMode"),children:Ph.map(u=>s.jsx(Bs,{selected:Es===u.value,onSelect:()=>oe(u.value),label:l(u.labelKey),ariaLabel:l(u.labelKey)},u.value))})}),s.jsxs("div",{className:Qs,children:[s.jsx(qt,{label:i("settings.aiworker.visual.field.lightTheme"),settingsItem:"appearance.light-theme",children:s.jsxs(St,{value:Na?.metadata.id??"",onValueChange:rs,children:[s.jsx(Ct,{"aria-label":i("settings.aiworker.visual.field.selectLightThemeAria"),size:Ft,className:bn,children:s.jsx(Mt,{placeholder:i("settings.aiworker.visual.field.selectThemePlaceholder"),children:Na?na(Na.metadata.name,"light"):void 0})}),s.jsx(It,{children:gn.map(u=>s.jsx(at,{value:u.metadata.id,children:na(u.metadata.name,"light")},u.metadata.id))})]})}),s.jsx(qt,{label:i("settings.aiworker.visual.field.darkTheme"),settingsItem:"appearance.dark-theme",children:s.jsxs(St,{value:vn?.metadata.id??"",onValueChange:ws,children:[s.jsx(Ct,{"aria-label":i("settings.aiworker.visual.field.selectDarkThemeAria"),size:Ft,className:bn,children:s.jsx(Mt,{placeholder:i("settings.aiworker.visual.field.selectThemePlaceholder"),children:vn?na(vn.metadata.name,"dark"):void 0})}),s.jsx(It,{children:Rn.map(u=>s.jsx(at,{value:u.metadata.id,children:na(u.metadata.name,"dark")},u.metadata.id))})]})}),s.jsxs("div",{className:"flex items-center gap-2 pt-1",children:[s.jsxs("button",{type:"button",disabled:xt||ss,onClick:()=>{const u=Date.now();jt(!0),Qt().finally(()=>{const gt=Date.now()-u;if(gt<500){window.setTimeout(()=>{jt(!1)},500-gt);return}jt(!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(F,{name:"restart",className:fe("h-3.5 w-3.5",ss&&"animate-spin")}),i(ss?"settings.aiworker.visual.actions.reloadingThemes":"settings.aiworker.visual.actions.reloadThemes")]}),s.jsx(Jt,{children:i("settings.aiworker.visual.field.themeImportInfoTooltip")})]})]})]}),At&&s.jsx(ba,{settingsItem:"appearance.dock-badge",children:s.jsx(dt,{checked:Ut,onChange:Ot,label:i("settings.aiworker.visual.field.dockBadge"),info:i("settings.aiworker.visual.field.dockBadgeHint"),ariaLabel:i("settings.aiworker.visual.field.dockBadge")})}),Bi&&s.jsx(ba,{children:Bi})]}),Ya&&s.jsx(ze,{title:i("settings.aiworker.desktopNetwork.field.windowControls"),info:i("settings.aiworker.desktopNetwork.field.windowControlsPositionDescription"),divider:aa,children:s.jsxs(Sn,{children:[s.jsx(qt,{label:i("settings.aiworker.desktopNetwork.field.windowControlsPosition"),settingsItem:"sessions.desktop-window-controls-position",children:s.jsx(Ys,{value:Ti,options:Kh.map(u=>({value:u.id,label:l(u.labelKey)})),onChange:Ri,"aria-label":i("settings.aiworker.desktopNetwork.field.windowControlsPositionAria")})}),s.jsx(qt,{label:i("settings.aiworker.desktopNetwork.field.windowControlsStyle"),settingsItem:"sessions.desktop-window-controls-style",children:s.jsx(Ys,{value:Ei,options:zh.map(u=>({value:u.id,label:l(u.labelKey)})),onChange:Li,"aria-label":i("settings.aiworker.desktopNetwork.field.windowControlsStyleAria")})})]})}),Za&&s.jsx(ze,{title:i("settings.aiworker.visual.section.localization"),children:s.jsxs(Sn,{children:[s.jsx(qt,{label:i("settings.appearance.language.label"),info:i("settings.appearance.language.description"),settingsItem:"appearance.language",children:s.jsxs(St,{value:e,onValueChange:u=>n(u),children:[s.jsx(Ct,{"aria-label":i("settings.appearance.language.select"),size:Ft,className:bn,children:s.jsx(Mt,{children:r(e)})}),s.jsx(It,{children:a.map(u=>s.jsx(at,{value:u,children:r(u)},u))})]})}),(ce("timeFormat")||ce("weekStart"))&&s.jsxs("div",{className:Qs,children:[ce("timeFormat")&&s.jsx(qt,{label:i("settings.aiworker.visual.field.timeFormat"),settingsItem:"appearance.time-format",children:s.jsxs(St,{value:De,onValueChange:u=>Qa(u),children:[s.jsx(Ct,{"aria-label":i("settings.aiworker.visual.field.selectTimeFormatAria"),size:Ft,className:bn,children:s.jsx(Mt,{children:Ms})}),s.jsx(It,{children:tl.map(u=>s.jsx(at,{value:u.id,children:l(u.labelKey)},u.id))})]})}),ce("weekStart")&&s.jsx(qt,{label:i("settings.aiworker.visual.field.weekStartsOn"),settingsItem:"appearance.week-start",children:s.jsxs(St,{value:it,onValueChange:u=>sa(u),children:[s.jsx(Ct,{"aria-label":i("settings.aiworker.visual.field.selectWeekStartAria"),size:Ft,className:bn,children:s.jsx(Mt,{children:On})}),s.jsx(It,{children:sl.map(u=>s.jsx(at,{value:u.id,children:l(u.labelKey)},u.id))})]})})]})]})}),(X||Te||Qe)&&s.jsxs(ze,{title:i("settings.aiworker.visual.section.appInstall"),contentClassName:Qs,children:[X&&s.jsxs(Rt,{label:i("settings.aiworker.visual.field.installAppName"),info:i("settings.aiworker.visual.field.installAppNameHint"),settingsItem:"appearance.pwa-install-name",alignEnd:!1,controlClassName:zs,children:[s.jsx(He,{value:kt,onChange:u=>{Wt(u.target.value)},onBlur:()=>{Vi(kt)},onKeyDown:u=>{u.key==="Enter"&&(u.preventDefault(),Vi(kt))},className:"min-w-0 flex-1",maxLength:64,"aria-label":i("settings.aiworker.visual.field.pwaInstallAppNameAria")}),s.jsx(B,{size:"sm",type:"button",variant:"ghost",onClick:()=>{Wt(Da),Vi("")},className:Cs,"aria-label":i("settings.aiworker.visual.actions.resetInstallAppNameAria"),title:i("settings.common.actions.reset"),children:s.jsx(F,{name:"restart",className:"h-3.5 w-3.5"})})]}),Te&&s.jsxs(Rt,{label:i("settings.aiworker.visual.field.installOrientation"),description:i("settings.aiworker.visual.field.installOrientationHint"),settingsItem:"appearance.pwa-orientation",alignEnd:!1,controlClassName:zs,children:[s.jsxs(St,{value:tn,onValueChange:u=>{const gt=nr(u);Nt(gt),Fr(gt)},children:[s.jsx(Ct,{"aria-label":i("settings.aiworker.visual.field.pwaInstallOrientationAria"),size:Ft,className:$r,children:s.jsx(Mt,{placeholder:i("settings.aiworker.visual.field.selectOrientationPlaceholder"),children:ra})}),s.jsx(It,{children:Zo.map(u=>s.jsx(at,{value:u.id,children:l(u.labelKey)},u.id))})]}),s.jsx(B,{size:"sm",type:"button",variant:"ghost",onClick:()=>{Nt("system"),Fr("system")},disabled:tn==="system",className:Cs,"aria-label":i("settings.aiworker.visual.actions.resetInstallOrientationAria"),title:i("settings.common.actions.reset"),children:s.jsx(F,{name:"restart",className:"h-3.5 w-3.5"})})]}),Qe&&s.jsxs(Rt,{label:i("settings.aiworker.visual.field.mobileKeyboardMode"),info:i("settings.aiworker.visual.field.mobileKeyboardModeHint"),settingsItem:"appearance.mobile-keyboard-mode",alignEnd:!1,controlClassName:zs,children:[s.jsxs(St,{value:ye,onValueChange:u=>{const gt=so(u);be(gt),pt({mobileKeyboardMode:gt})},children:[s.jsx(Ct,{"aria-label":i("settings.aiworker.visual.field.mobileKeyboardModeAria"),size:Ft,className:$r,children:s.jsx(Mt,{placeholder:i("settings.aiworker.visual.field.selectMobileKeyboardModePlaceholder"),children:si})}),s.jsx(It,{children:Xo.map(u=>s.jsx(at,{value:u.id,children:l(u.labelKey)},u.id))})]}),s.jsx(B,{size:"sm",type:"button",variant:"ghost",onClick:()=>{be("native"),pt({mobileKeyboardMode:"native"})},disabled:ye==="native",className:Cs,"aria-label":i("settings.aiworker.visual.actions.resetMobileKeyboardModeAria"),title:i("settings.common.actions.reset"),children:s.jsx(F,{name:"restart",className:"h-3.5 w-3.5"})})]})]})]}),ei&&s.jsxs(ze,{title:i("settings.aiworker.visual.section.densityAndType"),contentClassName:Qs,children:[ce("fontSize")&&!g||ce("terminalFontSize")?s.jsxs(Sn,{children:[ce("fontSize")&&!g&&s.jsxs(qt,{label:i("settings.aiworker.visual.field.interfaceFont"),settingsItem:"appearance.interface-font-size",controlClassName:"w-full",children:[s.jsxs(St,{value:Ue,onValueChange:u=>ke(u),children:[s.jsx(Ct,{"aria-label":i("settings.aiworker.visual.field.selectInterfaceFontAria"),size:Ft,className:bn,children:s.jsx(Mt,{children:Zr.find(u=>u.id===Ue)?.label})}),s.jsx(It,{children:Zr.map(u=>s.jsx(at,{value:u.id,children:s.jsx("span",{style:{fontFamily:u.stack},children:u.label})},u.id))})]}),s.jsx(B,{size:"sm",type:"button",variant:"ghost",onClick:()=>ke(Xr),disabled:Ue===Xr,className:Cs,"aria-label":i("settings.aiworker.visual.actions.resetInterfaceFontAria"),title:i("settings.common.actions.reset"),children:s.jsx(F,{name:"restart",className:"h-3.5 w-3.5"})})]}),ce("terminalFontSize")&&s.jsxs(qt,{label:i("settings.aiworker.visual.field.codeFont"),controlClassName:"w-full",children:[s.jsxs(St,{value:Oe,onValueChange:u=>Ve(u),children:[s.jsx(Ct,{"aria-label":i("settings.aiworker.visual.field.selectCodeFontAria"),size:Ft,className:bn,children:s.jsx(Mt,{children:eo.find(u=>u.id===Oe)?.label})}),s.jsx(It,{children:eo.map(u=>s.jsx(at,{value:u.id,children:s.jsx("span",{style:{fontFamily:u.stack},children:u.label})},u.id))})]}),s.jsx(B,{size:"sm",type:"button",variant:"ghost",onClick:()=>Ve(to),disabled:Oe===to,className:Cs,"aria-label":i("settings.aiworker.visual.actions.resetCodeFontAria"),title:i("settings.common.actions.reset"),children:s.jsx(F,{name:"restart",className:"h-3.5 w-3.5"})})]})]}):null,ce("fontSize")&&!g||ce("terminalFontSize")||ce("editorFontSize")?s.jsxs(Sn,{children:[ce("fontSize")&&!g&&s.jsx(qt,{label:i("settings.aiworker.visual.field.interfaceFontSize"),controlClassName:"w-full",children:s.jsxs("div",{className:la,children:[s.jsx(xs,{value:de,onValueChange:xe,min:50,max:200,step:5,className:Ps,"aria-label":i("settings.aiworker.visual.field.fontSizePercentageAria")}),s.jsx("span",{className:ca,children:"%"}),s.jsx(B,{size:"sm",type:"button",variant:"ghost",onClick:()=>xe(100),disabled:de===100,className:Cs,"aria-label":i("settings.aiworker.visual.actions.resetFontSizeAria"),title:i("settings.common.actions.reset"),children:s.jsx(F,{name:"restart",className:"h-3.5 w-3.5"})})]})}),ce("terminalFontSize")&&s.jsx(qt,{label:i("settings.aiworker.visual.field.terminalFontSize"),settingsItem:"appearance.terminal-font-size",controlClassName:"w-full",children:s.jsxs("div",{className:la,children:[s.jsx(xs,{value:ae,onValueChange:le,min:9,max:52,step:1,className:Ps}),s.jsx("span",{className:ca,children:"px"}),s.jsx(B,{size:"sm",type:"button",variant:"ghost",onClick:()=>le(13),disabled:ae===13,className:Cs,"aria-label":i("settings.aiworker.visual.actions.resetTerminalFontSizeAria"),title:i("settings.common.actions.reset"),children:s.jsx(F,{name:"restart",className:"h-3.5 w-3.5"})})]})}),ce("editorFontSize")&&s.jsx(qt,{label:i("settings.aiworker.visual.field.editorFontSize"),settingsItem:"appearance.editor-font-size",controlClassName:"w-full",children:s.jsxs("div",{className:la,children:[s.jsx(xs,{value:he,onValueChange:_e,min:9,max:32,step:1,className:Ps}),s.jsx("span",{className:ca,children:"px"}),s.jsx(B,{size:"sm",type:"button",variant:"ghost",onClick:()=>_e(13),disabled:he===13,className:Cs,"aria-label":i("settings.aiworker.visual.actions.resetEditorFontSizeAria"),title:i("settings.common.actions.reset"),children:s.jsx(F,{name:"restart",className:"h-3.5 w-3.5"})})]})})]}):null,ce("spacing")||ce("inputBarOffset")&&g?s.jsxs(Sn,{children:[ce("spacing")&&s.jsx(qt,{label:i("settings.aiworker.visual.field.spacingDensity"),settingsItem:"appearance.spacing-density",controlClassName:"w-full",children:s.jsxs("div",{className:la,children:[s.jsx(xs,{value:We,onValueChange:ve,min:50,max:200,step:5,className:Ps}),s.jsx("span",{className:ca,children:"%"}),s.jsx(B,{size:"sm",type:"button",variant:"ghost",onClick:()=>ve(100),disabled:We===100,className:Cs,"aria-label":i("settings.aiworker.visual.actions.resetSpacingAria"),title:i("settings.common.actions.reset"),children:s.jsx(F,{name:"restart",className:"h-3.5 w-3.5"})})]})}),ce("inputBarOffset")&&g&&s.jsx(qt,{label:i("settings.aiworker.visual.field.inputBarOffset"),info:i("settings.aiworker.visual.field.inputBarOffsetTooltip"),settingsItem:"appearance.input-bar-offset",controlClassName:"w-full",children:s.jsxs("div",{className:la,children:[s.jsx(xs,{value:Z,onValueChange:se,min:0,max:100,step:5,className:Ps}),s.jsx("span",{className:ca,children:"px"}),s.jsx(B,{size:"sm",type:"button",variant:"ghost",onClick:()=>se(0),disabled:Z===0,className:Cs,"aria-label":i("settings.aiworker.visual.actions.resetInputBarOffsetAria"),title:i("settings.common.actions.reset"),children:s.jsx(F,{name:"restart",className:"h-3.5 w-3.5"})})]})})]}):null,!aa&&Bi]}),ti&&s.jsxs(ze,{title:i("settings.aiworker.visual.section.navigation"),contentClassName:"space-y-4",children:[ce("fileEditorKeymap")&&s.jsx(Ss,{title:i("settings.aiworker.visual.field.fileEditorKeymap"),settingsItem:"appearance.file-editor-keymap",children:s.jsx(Js,{"aria-label":i("settings.aiworker.visual.field.fileEditorKeymap"),children:["default","vim"].map(u=>s.jsx(Bs,{selected:pe===u,onSelect:()=>Ne(u),label:i(`settings.aiworker.visual.option.fileEditorKeymap.${u}`),ariaLabel:i(`settings.aiworker.visual.option.fileEditorKeymap.${u}`)},u))})}),s.jsxs("div",{className:fs,children:[ce("autoSaveEnabled")&&s.jsx(dt,{checked:U,onChange:re,label:i("settings.aiworker.visual.field.autoSaveEnabled"),ariaLabel:i("settings.aiworker.visual.field.autoSaveEnabledAria"),info:i("settings.aiworker.visual.field.autoSaveEnabledInfo"),settingsItem:"appearance.auto-save-enabled"}),Dt&&s.jsx(qt,{label:i("settings.aiworker.visual.field.terminalShell"),info:i("settings.aiworker.visual.field.terminalShellHint"),settingsItem:"appearance.terminal-shell",className:"pt-2",children:s.jsxs(St,{value:ge,onValueChange:u=>{Rd(u)&&Ae(u)},children:[s.jsx(Ct,{"aria-label":i("settings.aiworker.visual.field.terminalShellAria"),size:Ft,className:bn,children:s.jsx(Mt,{})}),s.jsxs(It,{children:[s.jsx(at,{value:"auto",children:i("settings.aiworker.visual.option.terminalShell.auto")}),qs.map(u=>s.jsx(at,{value:u.id,children:u.name},u.id))]})]})}),Dt&&Sa&&s.jsx(dt,{checked:Ln,onChange:Ca,label:i("settings.aiworker.visual.field.terminalLoginShell"),ariaLabel:i("settings.aiworker.visual.field.terminalLoginShell"),settingsItem:"appearance.terminal-login-shell"}),ce("terminalQuickKeys")&&!g&&s.jsx(dt,{checked:Ke,onChange:Ze,label:i("settings.aiworker.visual.field.terminalQuickKeys"),ariaLabel:i("settings.aiworker.visual.field.terminalQuickKeysAria"),settingsItem:"appearance.terminal-quick-keys",info:i("settings.aiworker.visual.field.terminalQuickKeysTooltip",{control:Wn("ctrl"),alt:Wn("alt")})})]}),ce("sessionTabs")&&!ls&&!g&&s.jsx(Ss,{title:i("settings.aiworker.visual.field.sessionTabsGroup"),settingsItem:"appearance.session-tabs",children:s.jsx(dt,{checked:Ee,onChange:we,label:i("settings.aiworker.visual.field.sessionTabs"),ariaLabel:i("settings.aiworker.visual.field.sessionTabsAria"),info:i("settings.aiworker.visual.field.sessionTabsInfo")})})]}),_i&&s.jsxs(s.Fragment,{children:[en&&s.jsxs(ze,{title:i("settings.aiworker.visual.section.chatDisplay"),divider:v,contentClassName:"space-y-6",children:[ce("chatRenderMode")&&s.jsx(Ss,{title:i("settings.aiworker.visual.section.chatRenderMode"),settingsItem:"chat.render-mode",children:s.jsx("div",{role:"radiogroup","aria-label":i("settings.aiworker.visual.section.chatRenderModeAria"),className:"grid w-full max-w-[26rem] grid-cols-1 gap-3 @xl:grid-cols-2",children:Dh.map(u=>{const gt=te===u.id,ps=ja%12;return s.jsxs("button",{type:"button",onClick:()=>Xn(u.id),"aria-pressed":gt,className:fe("flex flex-col items-start gap-1 rounded-lg border p-3 text-left transition-colors",gt?"border-primary bg-primary/5":"border-border hover:border-border/80 hover:bg-muted/50"),children:[s.jsx("span",{className:fe("typography-ui-label",gt?"text-foreground":"text-muted-foreground"),children:l(u.labelKey)}),s.jsx("div",{className:"mt-2 w-full rounded-md border border-border/60 bg-muted/30 p-2",children:u.id==="live"?s.jsx("div",{className:"space-y-1.5",children:[0,1,2].map(Rs=>{const sn=Rs*3+1,Fn=ps-sn+1,ni=Fn<=0?0:Fn===1?42:Fn===2?68:92,pc=ni>0;return s.jsxs("div",{className:fe("flex items-center gap-1.5 transition-all duration-300 motion-reduce:transition-none",pc?"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:`${ni}%`}})]},Rs)})}):s.jsx("div",{className:"space-y-1.5",children:[0,1,2].map(Rs=>{const sn=ps>=(Rs+1)*3;return s.jsxs("div",{className:fe("flex items-center gap-1.5 transition-all duration-300 motion-reduce:transition-none",sn?"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%"}})]},Rs)})})})]},u.id)})})}),ce("activityRenderMode")&&s.jsx(Ss,{title:i("settings.aiworker.visual.section.activityDefault"),settingsItem:"chat.activity-default",children:s.jsx(Js,{"aria-label":i("settings.aiworker.visual.section.activityDefaultAria"),children:Mh.map(u=>s.jsx(Bs,{selected:ne===u.id,onSelect:()=>os(u.id),label:l(u.labelKey),ariaLabel:i("settings.aiworker.visual.field.activityDefaultModeAria",{option:l(u.labelKey)})},u.id))})})]}),yn&&s.jsxs(ze,{title:i("settings.aiworker.visual.section.messageStreamTransport"),divider:en||v,settingsItem:"chat.message-transport",contentClassName:"space-y-2",children:[s.jsx(Ys,{value:bs,options:el.map(u=>({value:u.id,label:l(u.labelKey)})),onChange:Mn,"aria-label":i("settings.aiworker.visual.section.messageStreamTransport")}),(()=>{const u=el.find(gt=>gt.id===bs);return u?.descriptionKey?s.jsx("span",{className:"typography-meta text-muted-foreground",children:l(u.descriptionKey)}):null})()]}),ia&&s.jsx(ze,{title:i("settings.aiworker.visual.section.chatMessageOptions"),divider:en||yn||v,children:s.jsxs(Sn,{className:"lg:gap-y-6",children:[ce("userMessageRendering")&&s.jsx(Ss,{title:i("settings.aiworker.visual.section.userMessageRendering"),children:s.jsx(Js,{"aria-label":i("settings.aiworker.visual.section.userMessageRenderingAria"),children:Eh.map(u=>s.jsx(Bs,{selected:Fh(V)===u.id,onSelect:()=>js(u.id),label:l(u.labelKey),ariaLabel:i("settings.aiworker.visual.field.userMessageRenderingAria",{option:l(u.labelKey)})},u.id))})}),ce("mermaidRendering")&&s.jsx(Ss,{title:i("settings.aiworker.visual.section.mermaidRendering"),children:s.jsx(Js,{"aria-label":i("settings.aiworker.visual.section.mermaidRenderingAria"),children:Th.map(u=>s.jsx(Bs,{selected:S===u.id,onSelect:()=>Ki(u.id),label:l(u.labelKey),ariaLabel:i("settings.aiworker.visual.field.mermaidRenderingAria",{option:l(u.labelKey)})},u.id))})}),ce("diffLayout")&&!ls&&s.jsx(Ss,{title:i("settings.aiworker.visual.section.diffLayout"),children:s.jsx(Js,{"aria-label":i("settings.aiworker.visual.section.diffLayoutAria"),children:Ah.map(u=>s.jsx(Bs,{selected:Re===u.id,onSelect:()=>Fe(u.id),label:l(u.labelKey),ariaLabel:i("settings.aiworker.visual.field.diffLayoutAria",{option:l(u.labelKey)})},u.id))})}),ce("followUpBehavior")&&s.jsx(Ss,{title:i("settings.aiworker.visual.section.followUpBehavior"),settingsItem:"chat.follow-up-behavior",children:s.jsx(Js,{"aria-label":i("settings.aiworker.visual.section.followUpBehaviorAria"),children:Rh.map(u=>s.jsx(Bs,{selected:Le===u.id,onSelect:()=>Xe(u.id),label:l(u.labelKey),ariaLabel:i("settings.aiworker.visual.field.followUpBehaviorAria",{option:l(u.labelKey)})},u.id))})}),ce("inputHistoryScope")&&s.jsx(Ss,{title:i("settings.aiworker.visual.field.inputHistoryScope"),info:i("settings.aiworker.visual.field.inputHistoryScopeDescription"),settingsItem:"chat.input-history-scope",children:s.jsx(Js,{"aria-label":i("settings.aiworker.visual.section.inputHistoryScopeAria"),children:Oh.map(u=>s.jsx(Bs,{selected:q===u.id,onSelect:()=>ka(u.id),label:l(u.labelKey),ariaLabel:l(u.labelKey)},u.id))})}),ce("inputHistoryLimit")&&s.jsx(Ss,{title:i("settings.aiworker.visual.field.inputHistoryLimit"),description:i("settings.aiworker.visual.field.inputHistoryLimitDescription"),contentClassName:zs,settingsItem:"chat.input-history-limit",children:s.jsxs("div",{className:la,children:[s.jsx(xs,{value:je,onValueChange:Fi,min:Od,max:Ld,step:1,className:Ps,deferExternalValueWhileFocused:!0,"aria-label":i("settings.aiworker.visual.field.inputHistoryLimitAria")}),s.jsx("span",{className:ca,children:i("settings.aiworker.visual.field.inputHistoryLimitUnit")})]})})]})}),$i&&s.jsxs(s.Fragment,{children:[ce("expandedTools")&&s.jsxs(ze,{title:i("settings.aiworker.visual.section.showToolsOpenedByDefault"),divider:en||yn||ia||v,contentClassName:fs,children:[s.jsx(dt,{checked:Me,onChange:Ja,label:i("settings.aiworker.visual.field.bash"),ariaLabel:i("settings.aiworker.visual.field.showExpandedBashToolsAria")}),s.jsx(dt,{checked:Q,onChange:Ui,label:i("settings.aiworker.visual.field.editTools"),ariaLabel:i("settings.aiworker.visual.field.showExpandedEditToolsAria")})]}),s.jsxs(ze,{title:i("settings.aiworker.visual.section.sessionAssistance"),settingsItem:"chat.session-assistance",contentClassName:fs,children:[s.jsx(dt,{checked:Os,onChange:mn,label:i("settings.aiworker.visual.field.draftStartersVisible"),ariaLabel:i("settings.aiworker.visual.field.draftStartersVisibleAria"),settingsItem:"chat.draft-starters-visible"}),ce("sessionAssist")&&s.jsxs(s.Fragment,{children:[s.jsx(dt,{checked:d,onChange:f,label:i("settings.aiworker.visual.field.sessionRecap"),ariaLabel:i("settings.aiworker.visual.field.sessionRecapAria"),settingsItem:"chat.session-recap"}),s.jsx(dt,{checked:C,onChange:P,label:i("settings.aiworker.visual.field.sessionSuggestion"),ariaLabel:i("settings.aiworker.visual.field.sessionSuggestionAria"),settingsItem:"chat.session-suggestion"})]}),ce("subagentReadOnlyBanner")&&s.jsx(dt,{checked:ys,onChange:Xt,label:i("settings.aiworker.visual.field.allowPromptingSubagentSessions"),ariaLabel:i("settings.aiworker.visual.field.allowPromptingSubagentSessionsAria"),settingsItem:"chat.subagent-read-only-banner"})]}),ce("sessionGoal")&&!ls&&s.jsxs(ze,{title:i("settings.aiworker.visual.goal.sectionTitle"),info:i("settings.aiworker.visual.goal.description"),contentClassName:fs,children:[s.jsx(dt,{checked:x,onChange:N,label:i("settings.aiworker.visual.field.sessionGoal"),ariaLabel:i("settings.aiworker.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(dt,{checked:m,onChange:A,disabled:!x,label:i("settings.aiworker.visual.goal.budgetLabel"),ariaLabel:i("settings.aiworker.visual.goal.budgetAria")}),x&&m?s.jsx(xs,{value:R,onValueChange:u=>{typeof u=="number"&&Number.isFinite(u)&&u>0&&I(Math.floor(u))},min:1e3,max:1e8,step:5e4}):null]})]}),ce("reasoning")&&s.jsxs(ze,{title:i("settings.aiworker.visual.section.reasoning"),settingsItem:"chat.reasoning",contentClassName:fs,children:[s.jsx(dt,{checked:b,onChange:j,label:i("settings.aiworker.visual.field.showReasoningTraces"),ariaLabel:i("settings.aiworker.visual.field.showReasoningTracesAria"),settingsItem:"chat.reasoning-traces"}),b&&s.jsx(dt,{checked:O,onChange:T,label:i("settings.aiworker.visual.field.collapsibleThinkingBlocks"),ariaLabel:i("settings.aiworker.visual.field.collapsibleThinkingBlocksAria")})]}),s.jsx(ze,{title:i("settings.aiworker.visual.section.streaming"),settingsItem:"chat.streaming",contentClassName:fs,children:s.jsx(dt,{checked:h,onChange:w,label:i("settings.aiworker.visual.field.streamingAutoFollow"),ariaLabel:i("settings.aiworker.visual.field.streamingAutoFollowAria"),info:i("settings.aiworker.visual.field.streamingAutoFollowInfo"),settingsItem:"chat.streaming-auto-follow"})}),(ce("collapsibleUserMessages")||ce("stickyUserHeader")||ce("promptNavigatorEnabled")&&!ls||ce("wideChatLayout")||ce("splitAssistantMessageActions")||ce("codeBlockLineWrap"))&&s.jsxs(ze,{title:i("settings.aiworker.visual.section.messageAppearance"),settingsItem:"chat.message-appearance",contentClassName:fs,children:[ce("collapsibleUserMessages")&&s.jsx(dt,{checked:k,onChange:xn,label:i("settings.aiworker.visual.field.collapsibleUserMessages"),ariaLabel:i("settings.aiworker.visual.field.collapsibleUserMessagesAria"),settingsItem:"chat.collapsible-user-messages"}),ce("stickyUserHeader")&&s.jsx(dt,{checked:D,onChange:Gs,label:i("settings.aiworker.visual.field.stickyUserHeader"),ariaLabel:i("settings.aiworker.visual.field.stickyUserHeaderAria"),settingsItem:"chat.sticky-user-header"}),ce("promptNavigatorEnabled")&&!ls&&s.jsx(dt,{checked:L,onChange:Zn,label:i("settings.aiworker.visual.field.promptNavigatorEnabled"),ariaLabel:i("settings.aiworker.visual.field.promptNavigatorEnabledAria"),settingsItem:"chat.prompt-navigator"}),ce("wideChatLayout")&&s.jsx(dt,{checked:_,onChange:Or,label:i("settings.aiworker.visual.field.wideChatLayout"),ariaLabel:i("settings.aiworker.visual.field.wideChatLayoutAria"),settingsItem:"chat.wide-layout"}),ce("splitAssistantMessageActions")&&s.jsx(dt,{checked:qe,onChange:Xs,label:i("settings.aiworker.visual.field.showSplitAssistantMessageActions"),ariaLabel:i("settings.aiworker.visual.field.showSplitAssistantMessageActionsAria"),settingsItem:"chat.inline-assistant-actions",info:i("settings.aiworker.visual.field.showSplitAssistantMessageActionsTooltip")}),ce("codeBlockLineWrap")&&s.jsx(dt,{checked:z,onChange:K,label:i("settings.aiworker.visual.field.codeBlockLineWrap"),ariaLabel:i("settings.aiworker.visual.field.codeBlockLineWrapAria"),settingsItem:"chat.code-block-line-wrap"})]}),(ce("showToolFileIcons")||ce("showTurnChangedFiles")||ce("dotfiles")&&!cs()||ce("fileViewerPreview"))&&s.jsxs(ze,{title:i("settings.aiworker.visual.section.toolsAndFiles"),settingsItem:"chat.tools-and-files",contentClassName:fs,children:[ce("showToolFileIcons")&&s.jsx(dt,{checked:ft,onChange:ea,label:i("settings.aiworker.visual.field.showToolFileIcons"),ariaLabel:i("settings.aiworker.visual.field.showToolFileIconsAria"),settingsItem:"chat.tool-file-icons"}),ce("showTurnChangedFiles")&&s.jsx(dt,{checked:Be,onChange:ta,label:i("settings.aiworker.visual.field.showTurnChangedFiles"),ariaLabel:i("settings.aiworker.visual.field.showTurnChangedFilesAria"),settingsItem:"chat.changed-files"}),ce("dotfiles")&&!cs()&&s.jsx(dt,{checked:p,onChange:Fd,label:i("settings.aiworker.visual.field.showDotfiles"),ariaLabel:i("settings.aiworker.visual.field.showDotfilesAria"),settingsItem:"chat.dotfiles"}),ce("fileViewerPreview")&&s.jsx(dt,{checked:gs,onChange:zi,label:i("settings.aiworker.defaults.field.openFilesPreview"),ariaLabel:i("settings.aiworker.defaults.field.openFilesPreviewAria")})]}),(ce("persistDraft")||ce("largeTextPaste")||!g&&ce("inputSpellcheck")||ce("enterToSend"))&&s.jsxs(ze,{title:i("settings.aiworker.visual.section.composer"),settingsItem:"chat.composer",contentClassName:"space-y-6",children:[(ce("persistDraft")||!g&&ce("inputSpellcheck"))&&s.jsxs("div",{className:fs,children:[ce("persistDraft")&&s.jsx(dt,{checked:ot,onChange:st,label:i("settings.aiworker.visual.field.persistDraftMessages"),ariaLabel:i("settings.aiworker.visual.field.persistDraftMessagesAria"),settingsItem:"chat.persist-drafts"}),!g&&ce("inputSpellcheck")&&s.jsx(dt,{checked:mt,onChange:Oi,label:i("settings.aiworker.visual.field.enableSpellcheckInTextInputs"),ariaLabel:i("settings.aiworker.visual.field.enableSpellcheckInTextInputsAria"),settingsItem:"chat.spellcheck"})]}),ce("largeTextPaste")&&s.jsx(Ss,{title:i("settings.aiworker.visual.field.largeTextPaste"),description:i("settings.aiworker.visual.field.largeTextPasteHint"),settingsItem:"chat.large-text-paste",children:s.jsx(Js,{"aria-label":i("settings.aiworker.visual.field.largeTextPasteAria"),children:Lh.map(u=>s.jsx(Bs,{selected:G===u.id,onSelect:()=>Ge(u.id),label:l(u.labelKey),ariaLabel:i("settings.aiworker.visual.field.largeTextPasteOptionAria",{option:l(u.labelKey)})},u.id))})}),ce("enterToSend")&&s.jsx(Ss,{title:i("settings.aiworker.visual.field.enterToSend"),description:i("settings.aiworker.visual.field.enterToSendHint"),settingsItem:"chat.enter-to-send",children:s.jsxs(Js,{"aria-label":i("settings.aiworker.visual.field.enterToSend"),children:[s.jsx(Bs,{selected:et,onSelect:()=>Dn(!0),label:i("settings.aiworker.visual.option.enterToSend.enter.label"),ariaLabel:i("settings.aiworker.visual.option.enterToSend.enter.label")}),s.jsx(Bs,{selected:!et,onSelect:()=>Dn(!1),label:i("settings.aiworker.visual.option.enterToSend.modifier.label"),ariaLabel:i("settings.aiworker.visual.option.enterToSend.modifier.label")})]})})]})]})]}),ce("reportUsage")&&s.jsx(ze,{title:i("settings.aiworker.visual.section.privacy"),children:s.jsx(dt,{checked:Wa,onChange:Mi,label:i("settings.aiworker.visual.field.sendAnonymousUsageReports"),info:i("settings.aiworker.visual.field.sendAnonymousUsageReportsHint"),ariaLabel:i("settings.aiworker.visual.field.sendAnonymousUsageReportsAria"),settingsItem:"appearance.usage-reports"})})]})},Uh=1,_h=365,nl=30,$h=[{value:"archive",labelKey:"settings.aiworker.sessionRetention.action.archive"},{value:"delete",labelKey:"settings.aiworker.sessionRetention.action.delete"}],ec=()=>{const t=ut.c(88),{t:e}=tt(),a=ie(Vh),n=ie(Bh),r=ie(Hh),i=ie(Wh),l=ie(Gh),g=ie(qh);let c;t[0]===Symbol.for("react.memo_cache_sentinel")?(c={autoRun:!1},t[0]=c):c=t[0];const{candidates:y,isRunning:p,runCleanup:b,action:d}=Jc(c),C=y.length;let f;t[1]!==b||t[2]!==e?(f=async()=>{const de=await b({force:!0});if(de.completedIds.length===0&&de.failedIds.length===0){E.message(de.action==="archive"?e("settings.aiworker.sessionRetention.toast.noneEligibleArchive"):e("settings.aiworker.sessionRetention.toast.noneEligibleDelete"));return}de.completedIds.length>0&&E.success(de.action==="archive"?e("settings.aiworker.sessionRetention.toast.archivedCount",{count:de.completedIds.length}):e("settings.aiworker.sessionRetention.toast.deletedCount",{count:de.completedIds.length})),de.failedIds.length>0&&E.error(de.action==="archive"?e("settings.aiworker.sessionRetention.toast.failedArchiveCount",{count:de.failedIds.length}):e("settings.aiworker.sessionRetention.toast.failedDeleteCount",{count:de.failedIds.length}))},t[1]=b,t[2]=e,t[3]=f):f=t[3];const P=f;let x;t[4]!==e?(x=e("settings.aiworker.sessionRetention.title"),t[4]=e,t[5]=x):x=t[5];let N;t[6]!==e?(N=e("settings.aiworker.sessionRetention.tooltip"),t[6]=e,t[7]=N):N=t[7];let m;t[8]!==e?(m=e("settings.aiworker.sessionRetention.field.enableAutoCleanup"),t[8]=e,t[9]=m):m=t[9];let A;t[10]!==e?(A=e("settings.aiworker.sessionRetention.field.enableAutoCleanupAria"),t[10]=e,t[11]=A):A=t[11];let R;t[12]!==a||t[13]!==i||t[14]!==m||t[15]!==A?(R=s.jsx(dt,{settingsItem:"sessions.auto-cleanup",checked:a,onChange:i,label:m,ariaLabel:A}),t[12]=a,t[13]=i,t[14]=m,t[15]=A,t[16]=R):R=t[16];let I;t[17]!==e?(I=e("settings.aiworker.sessionRetention.field.retentionPeriod"),t[17]=e,t[18]=I):I=t[18];let j;t[19]!==e?(j=e("settings.aiworker.sessionRetention.field.retentionPeriodAria"),t[19]=e,t[20]=j):j=t[20];let h;t[21]===Symbol.for("react.memo_cache_sentinel")?(h=fe(Ps,"tabular-nums"),t[21]=h):h=t[21];let w;t[22]!==n||t[23]!==l||t[24]!==j?(w=s.jsx(xs,{value:n,onValueChange:l,min:Uh,max:_h,step:1,"aria-label":j,className:h}),t[22]=n,t[23]=l,t[24]=j,t[25]=w):w=t[25];let O;t[26]!==e?(O=e("settings.aiworker.sessionRetention.field.days"),t[26]=e,t[27]=O):O=t[27];let T;t[28]!==O?(T=s.jsx("span",{className:"typography-ui-label text-muted-foreground",children:O}),t[28]=O,t[29]=T):T=t[29];let S;t[30]!==l?(S=()=>l(nl),t[30]=l,t[31]=S):S=t[31];const M=n===nl;let V;t[32]!==e?(V=e("settings.aiworker.sessionRetention.actions.resetRetentionAria"),t[32]=e,t[33]=V):V=t[33];let $;t[34]!==e?($=e("settings.common.actions.reset"),t[34]=e,t[35]=$):$=t[35];let k;t[36]===Symbol.for("react.memo_cache_sentinel")?(k=s.jsx(F,{name:"restart",className:"h-3.5 w-3.5"}),t[36]=k):k=t[36];let W;t[37]!==S||t[38]!==M||t[39]!==V||t[40]!==$?(W=s.jsx(B,{size:"sm",type:"button",variant:"ghost",onClick:S,disabled:M,className:Cs,"aria-label":V,title:$,children:k}),t[37]=S,t[38]=M,t[39]=V,t[40]=$,t[41]=W):W=t[41];let D;t[42]!==w||t[43]!==T||t[44]!==W||t[45]!==I?(D=s.jsxs(Rt,{settingsItem:"sessions.retention-period",label:I,children:[w,T,W]}),t[42]=w,t[43]=T,t[44]=W,t[45]=I,t[46]=D):D=t[46];let L;t[47]!==e?(L=e("settings.aiworker.sessionRetention.field.whenSessionsExpire"),t[47]=e,t[48]=L):L=t[48];let J;t[49]!==e?(J=$h.map(de=>({value:de.value,label:e(de.labelKey)})),t[49]=e,t[50]=J):J=t[50];let ee;t[51]!==r||t[52]!==g||t[53]!==J?(ee=s.jsx(Ys,{value:r,onChange:g,options:J}),t[51]=r,t[52]=g,t[53]=J,t[54]=ee):ee=t[54];let U;t[55]!==L||t[56]!==ee?(U=s.jsx(Rt,{settingsItem:"sessions.retention-action",label:L,children:ee}),t[55]=L,t[56]=ee,t[57]=U):U=t[57];let re;t[58]!==D||t[59]!==U?(re=s.jsxs(ba,{className:"space-y-0",children:[D,U]}),t[58]=D,t[59]=U,t[60]=re):re=t[60];let _;t[61]!==e?(_=e("settings.aiworker.sessionRetention.manualCleanup.title"),t[61]=e,t[62]=_):_=t[62];let H;t[63]!==p||t[64]!==e?(H=e(p?"settings.aiworker.sessionRetention.actions.cleaningUp":"settings.aiworker.sessionRetention.actions.runCleanupNow"),t[63]=p,t[64]=e,t[65]=H):H=t[65];let z;t[66]!==P||t[67]!==p||t[68]!==H?(z=s.jsx(B,{type:"button",variant:"outline",size:"xs",onClick:P,disabled:p,className:"!font-normal",children:H}),t[66]=P,t[67]=p,t[68]=H,t[69]=z):z=t[69];let K;t[70]!==_||t[71]!==z?(K=s.jsx(Rt,{label:_,children:z}),t[70]=_,t[71]=z,t[72]=K):K=t[72];let te;t[73]!==d||t[74]!==C||t[75]!==e?(te=d==="archive"?e("settings.aiworker.sessionRetention.manualCleanup.eligibleArchiveNow",{count:C}):e("settings.aiworker.sessionRetention.manualCleanup.eligibleDeleteNow",{count:C}),t[73]=d,t[74]=C,t[75]=e,t[76]=te):te=t[76];let Y;t[77]!==te?(Y=s.jsx("p",{className:"typography-meta text-muted-foreground",children:te}),t[77]=te,t[78]=Y):Y=t[78];let ne;t[79]!==K||t[80]!==Y?(ne=s.jsxs("div",{className:"mt-1 py-1.5 space-y-1",children:[K,Y]}),t[79]=K,t[80]=Y,t[81]=ne):ne=t[81];let me;return t[82]!==x||t[83]!==re||t[84]!==N||t[85]!==ne||t[86]!==R?(me=s.jsxs(ze,{title:x,info:N,children:[R,re,ne]}),t[82]=x,t[83]=re,t[84]=N,t[85]=ne,t[86]=R,t[87]=me):me=t[87],me};function Vh(t){return t.autoDeleteEnabled}function Bh(t){return t.autoDeleteAfterDays}function Hh(t){return t.sessionRetentionAction}function Wh(t){return t.setAutoDeleteEnabled}function Gh(t){return t.setAutoDeleteAfterDays}function qh(t){return t.setSessionRetentionAction}const al=(t,e,a)=>!t||!Number.isFinite(t)?e:new Intl.DateTimeFormat(Sr(),{dateStyle:"medium",timeStyle:"short",hour12:a==="auto"?void 0:a==="12h"}).format(t),tc=()=>{const{t}=tt(),e=ie(h=>h.timeFormatPreference),[a,n]=o.useState(!1),[r,i]=o.useState(!0),[l,g]=o.useState(!1),[c,y]=o.useState(null),[p,b]=o.useState(!1),[d,C]=o.useState([]),[f,P]=o.useState(Qc),[x,N]=o.useState(""),m=o.useMemo(()=>Yc(),[]),A=o.useCallback(async()=>{i(!0),N("");try{const h=await Zc();C(h)}catch(h){const w=h instanceof Error?h.message:t("settings.aiworker.passkeys.toast.loadFailed");N(w)}finally{i(!1)}},[t]);o.useEffect(()=>{let h=!1;return(async()=>{try{if(!m.supported){h||(n(!1),i(!1));return}h||n(!0)}catch{h||n(!1)}if(!h){const w=await Wi();if(P(w),!w.enabled){C([]),i(!1);return}await A()}})(),()=>{h=!0,Vr()}},[A,m.supported]);const R=o.useCallback(async()=>{if(!f.enabled){const h=t("settings.aiworker.passkeys.toast.enableUiPasswordFirst");N(h),E.message(h);return}if(!a){N(m.reason),E.message(m.reason);return}if(l){Vr(),g(!1);return}N(""),g(!0);try{await Xc(),P(await Wi()),await A(),E.success(t("settings.aiworker.passkeys.toast.added"))}catch(h){if(ed(h)){E.message(t("settings.aiworker.passkeys.toast.setupCanceled"));return}const w=h instanceof Error?h.message:t("settings.aiworker.passkeys.toast.addFailed");N(w),E.error(w)}finally{g(!1)}},[l,A,f.enabled,m.reason,a,t]),I=o.useCallback(async h=>{y(h),N("");try{await td(h),P(await Wi()),await A(),E.success(t("settings.aiworker.passkeys.toast.removed"))}catch(w){const O=w instanceof Error?w.message:t("settings.aiworker.passkeys.toast.removeFailed");N(O),E.error(O)}finally{y(null)}},[A,t]),j=o.useCallback(async()=>{b(!0),N("");try{await sd(),window.location.reload()}catch(h){const w=h instanceof Error?h.message:t("settings.aiworker.passkeys.toast.clearAuthFailed");N(w),E.error(w),b(!1)}},[t]);return s.jsxs(ze,{title:t("settings.aiworker.passkeys.title"),children:[s.jsxs("div",{className:"space-y-2",children:[s.jsxs(Rt,{label:t("settings.aiworker.passkeys.field.currentDevice"),children:[s.jsx(B,{type:"button",variant:l?"secondary":"outline",size:"xs",onClick:()=>{R()},disabled:r||p,className:"!font-normal",children:t(l?"settings.aiworker.passkeys.actions.cancelSetup":"settings.aiworker.passkeys.actions.add")}),s.jsx(B,{type:"button",variant:"ghost",size:"xs",onClick:()=>{j()},disabled:r||l||p,className:"!font-normal text-muted-foreground hover:text-foreground",children:t(p?"settings.aiworker.passkeys.actions.signingOut":"settings.aiworker.passkeys.actions.signOutEverywhere")})]}),!f.enabled&&s.jsx("p",{className:"typography-meta text-muted-foreground",children:t("settings.aiworker.passkeys.state.uiPasswordRequired")}),f.enabled&&!a&&s.jsx("p",{className:"typography-meta text-muted-foreground",children:m.reason}),r?s.jsx("p",{className:"typography-meta text-muted-foreground",children:t("settings.aiworker.passkeys.state.loading")}):d.length===0?s.jsx("p",{className:"typography-meta text-muted-foreground",children:t("settings.aiworker.passkeys.state.noneSaved")}):s.jsx("div",{className:"space-y-1 pt-1",children:d.map(h=>s.jsxs(Rt,{label:s.jsx("span",{title:h.label,children:h.label}),alignEnd:!1,controlClassName:"justify-between sm:flex-1",children:[s.jsx("span",{className:"typography-meta text-muted-foreground truncate",children:h.lastUsedAt?t("settings.aiworker.passkeys.item.lastUsed",{time:al(h.lastUsedAt,t("settings.aiworker.passkeys.time.neverUsed"),e)}):t("settings.aiworker.passkeys.item.added",{time:al(h.createdAt,t("settings.aiworker.passkeys.time.neverUsed"),e)})}),s.jsx(B,{type:"button",variant:"ghost",size:"xs",onClick:()=>{I(h.id)},disabled:c===h.id,className:"!font-normal text-muted-foreground hover:text-foreground",children:c===h.id?t("settings.aiworker.passkeys.actions.removing"):t("settings.common.actions.delete")})]},h.id))})]}),x&&s.jsx("div",{className:"mt-1 py-1.5",children:s.jsx("p",{className:"typography-meta text-[var(--status-error)]",children:x})})]})},sc=()=>{const t=ut.c(14),{t:e}=tt(),a=Br(Jh),n=Br(Qh);let r;t[0]!==e?(r=e("settings.aiworker.appLinks.title"),t[0]=e,t[1]=r):r=t[1];let i;t[2]!==e?(i=e("settings.aiworker.appLinks.info"),t[2]=e,t[3]=i):i=t[3];let l;t[4]!==n||t[5]!==e||t[6]!==a?(l=a.length===0?s.jsx("p",{className:"typography-meta text-muted-foreground",children:e("settings.aiworker.appLinks.empty")}):a.map(y=>s.jsxs("div",{className:"flex items-center justify-between gap-2 py-0.5",children:[s.jsx("span",{className:"min-w-0 truncate font-mono text-[13px]",children:`${y}://`}),s.jsx(B,{type:"button",variant:"ghost",size:"xs",onClick:()=>n(y),className:"!font-normal text-muted-foreground hover:text-foreground","aria-label":e("settings.aiworker.appLinks.removeAria",{scheme:`${y}://`}),children:e("settings.common.actions.delete")})]},y)),t[4]=n,t[5]=e,t[6]=a,t[7]=l):l=t[7];let g;t[8]!==l?(g=s.jsx("div",{className:"space-y-1","data-settings-item":"general.app-links",children:l}),t[8]=l,t[9]=g):g=t[9];let c;return t[10]!==r||t[11]!==i||t[12]!==g?(c=s.jsx(ze,{title:r,description:i,children:g}),t[10]=r,t[11]=i,t[12]=g,t[13]=c):c=t[13],c};function Jh(t){return t.trustedSchemes}function Qh(t){return t.removeTrustedScheme}const ar=t=>{const e=xa(t);return e||{providerId:"",modelId:""}},nc=()=>{const{t}=tt(),e=Ye(ae=>ae.setProvider),a=Ye(ae=>ae.setModel),n=Ye(ae=>ae.setAgent),r=Ye(ae=>ae.setCurrentVariant),i=Ye(ae=>ae.setCurrentVariantOverride),l=Ye(ae=>ae.setSettingsDefaultModel),g=Ye(ae=>ae.setSettingsDefaultVariant),c=Ye(ae=>ae.setSettingsDefaultAgent),y=Ye(ae=>ae.selectionSource==="manual"),p=nd(ae=>ae.currentSessionId),b=Hr(ae=>ae.getSessionModelSelection),d=Hr(ae=>ae.getSessionAgentSelection),C=!!(y&&p&&b(p)),f=!!(y&&p&&d(p)),P=ie(ae=>ae.showDeletionDialog),x=ie(ae=>ae.setShowDeletionDialog),N=Ye(ae=>ae.providers),m=Ye(ae=>ae.modelsMetadata),[A,R]=o.useState(),[I,j]=o.useState(),[h,w]=o.useState(),[O,T]=o.useState(!0),[S,M]=o.useState(),[V,$]=o.useState([]),[k,W]=o.useState(),[D,L]=o.useState(!0),J=o.useMemo(()=>ar(A),[A]);o.useEffect(()=>{(async()=>{try{const le=await pn();if(le){const ge=le.defaultModel?.trim()||void 0,Ae=le.defaultVariant?.trim()||void 0,Se=le.defaultAgent?.trim()||void 0;ge!==void 0&&R(ge),Ae!==void 0&&j(Ae),Se!==void 0&&w(Se),le.smallModelUseDefault!==void 0&&T(le.smallModelUseDefault);const Ce=le.smallModelOverride?.trim();Ce&&M(Ce);const he=le.walkthroughModelOverride?.trim();he&&W(he)}}catch(le){console.warn("Failed to load defaults settings:",le)}finally{L(!1)}})()},[]);const ee=o.useCallback(async(ae,le)=>{const ge=ae&&le?`${ae}/${le}`:void 0;R(ge),j(void 0),g(void 0),l(ge),C||(r(void 0),ae&&le&&N.find(Se=>Se.id===ae)&&(e(ae),a(le)));try{await pt({defaultModel:ge??"",defaultVariant:""})}catch(Ae){console.warn("Failed to save default model:",Ae)}},[C,N,r,a,e,l,g]),U="__default__",re=o.useCallback(ae=>ae===U?t("settings.aiworker.defaults.option.default"):ae.charAt(0).toUpperCase()+ae.slice(1),[t]),_=o.useCallback(async ae=>{const le=ae===U?void 0:ae||void 0;j(le),g(le),C||i(le??null,le);try{await pt({defaultVariant:le??""})}catch(ge){console.warn("Failed to save default variant:",ge)}},[C,i,g]),H=o.useCallback(async ae=>{const le=ae||void 0;w(le),c(le),ae&&!f&&n(ae);try{await pt({defaultAgent:le??""})}catch(ge){console.warn("Failed to save default agent:",ge)}},[f,n,c]),z=o.useCallback(async ae=>{T(ae);try{await pt({smallModelUseDefault:ae})}catch(le){console.warn("Failed to save small model preference:",le)}},[]),K=o.useCallback(async(ae,le)=>{const ge=ae&&le?`${ae}/${le}`:void 0;M(ge);try{await pt({smallModelOverride:ge??""})}catch(Ae){console.warn("Failed to save small model override:",Ae)}},[]),te=o.useCallback(async(ae,le)=>{const ge=ae&&le?`${ae}/${le}`:void 0;W(ge);try{await pt({walkthroughModelOverride:ge??""})}catch(Ae){console.warn("Failed to save walkthrough model override:",Ae)}},[]),Y=o.useCallback((ae,le)=>m.get(`${ae}/${le}`)?.structured_output!==!1,[m]),ne=o.useMemo(()=>ar(S),[S]),me=o.useMemo(()=>ar(k),[k]);o.useEffect(()=>{let ae=!1;return(async()=>{try{const le=await yt("/api/small-model",{method:"GET",headers:{Accept:"application/json"}});if(!le.ok)return;const ge=await le.json().catch(()=>null);!ae&&Array.isArray(ge?.authenticatedProviders)&&$(ge.authenticatedProviders.filter(Ae=>typeof Ae=="string"))}catch{}})(),()=>{ae=!0}},[]);const de=o.useMemo(()=>{if(!J.providerId||!J.modelId)return[];const ge=N.find(Ae=>Ae.id===J.providerId)?.models.find(Ae=>Ae.id===J.modelId)?.variants;return ge?Object.keys(ge):[]},[J.modelId,J.providerId,N]),xe=de.length>0;return o.useEffect(()=>{!xe&&I&&(j(void 0),g(void 0),C||r(void 0),pt({defaultVariant:""}).catch(()=>{}))},[C,I,r,g,xe]),D?null:s.jsx(s.Fragment,{children:s.jsx(ze,{title:t("settings.aiworker.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.aiworker.defaults.summaryPrefix")," ",J.providerId?s.jsxs("span",{className:"text-foreground",children:[J.providerId,"/",J.modelId,xe?` (${I??t("settings.aiworker.defaults.option.defaultLowercase")})`:""]}):s.jsx("span",{className:"text-foreground",children:t("settings.aiworker.defaults.summaryOpenCodeDefault")}),h&&s.jsxs(s.Fragment,{children:[" / ",s.jsx("span",{className:"text-foreground",children:h})]})]}),s.jsxs("div",{children:[s.jsx(Rt,{settingsItem:"sessions.default-model",label:t("settings.aiworker.defaults.field.defaultModel"),children:s.jsx(Fa,{providerId:J.providerId,modelId:J.modelId,onChange:ee,className:In})}),s.jsx(Rt,{settingsItem:"sessions.default-thinking",label:t("settings.aiworker.defaults.field.defaultThinking"),children:s.jsxs(St,{value:I??U,onValueChange:_,disabled:!xe,children:[s.jsx(Ct,{size:Ft,className:rn,children:s.jsx(Mt,{placeholder:t("settings.aiworker.defaults.field.thinkingPlaceholder"),children:re(I??U)})}),s.jsxs(It,{children:[s.jsx(at,{value:U,children:t("settings.aiworker.defaults.option.default")}),de.map(ae=>s.jsx(at,{value:ae,children:re(ae)},ae))]})]})}),s.jsx(Rt,{settingsItem:"sessions.default-agent",label:t("settings.aiworker.defaults.field.defaultAgent"),children:s.jsx(bl,{agentName:h||"",onChange:H,filter:ae=>ad(ae.mode),className:In})})]}),s.jsx(ba,{className:fs,children:s.jsx(dt,{settingsItem:"sessions.deletion-dialog",checked:P,onChange:x,label:t("settings.aiworker.defaults.field.showDeletionDialog"),ariaLabel:t("settings.aiworker.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(Zs,{children:t("settings.aiworker.defaults.smallModel.title")}),s.jsx(Jt,{children:t("settings.aiworker.defaults.smallModel.description")})]}),s.jsx(dt,{settingsItem:"sessions.small-model",checked:O,onChange:ae=>{z(ae)},label:t("settings.aiworker.defaults.smallModel.useDefault"),ariaLabel:t("settings.aiworker.defaults.smallModel.useDefaultAria")}),O?null:s.jsx(Rt,{label:t("settings.aiworker.defaults.smallModel.overrideModel"),children:s.jsx(Fa,{providerId:ne.providerId,modelId:ne.modelId,onChange:K,allowedProviderIds:V,className:In})}),s.jsxs(ba,{className:fs,children:[s.jsxs("div",{className:"flex items-center gap-1.5",children:[s.jsx(Zs,{children:t("settings.aiworker.defaults.walkthroughModel.title")}),s.jsx(Jt,{children:t("settings.aiworker.defaults.walkthroughModel.description")})]}),s.jsx(Rt,{settingsItem:"sessions.walkthrough-model",label:t("settings.aiworker.defaults.walkthroughModel.overrideModel"),children:s.jsx(Fa,{providerId:me.providerId,modelId:me.modelId,onChange:te,allowedProviderIds:V,isModelAllowed:Y,placeholder:t("settings.aiworker.defaults.walkthroughModel.usesSmallModel"),className:In})})]})]})]})})})},il={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"}},Yh={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"},Zh=()=>{const{t}=tt(),e=o.useMemo(()=>as(),[]),a=o.useMemo(()=>cs(),[]),n=o.useMemo(()=>typeof window>"u"?!1:window.Capacitor?.isNativePlatform?.()===!0||window.location.protocol==="capacitor:",[]),r=!e&&!a&&!n,i=ie(_=>_.nativeNotificationsEnabled),l=ie(_=>_.setNativeNotificationsEnabled),g=ie(_=>_.notificationMode),c=ie(_=>_.setNotificationMode),y=ie(_=>_.notifyOnSubtasks),p=ie(_=>_.setNotifyOnSubtasks),b=ie(_=>_.notifyOnCompletion),d=ie(_=>_.setNotifyOnCompletion),C=ie(_=>_.notifyOnError),f=ie(_=>_.setNotifyOnError),P=ie(_=>_.notifyOnQuestion),x=ie(_=>_.setNotifyOnQuestion),N=ie(_=>_.notificationTemplates),m=ie(_=>_.setNotificationTemplates),[A,R]=o.useState("default"),[I,j]=o.useState(!1),[h,w]=o.useState(!1),[O,T]=o.useState(!1);o.useEffect(()=>{if(!r){j(!1),w(!1);return}typeof Notification<"u"&&R(Notification.permission);const _=typeof window<"u"&&"serviceWorker"in navigator&&"PushManager"in window&&"Notification"in window;j(_),(async()=>{if(!_){w(!1);return}try{const z=await navigator.serviceWorker.getRegistration();if(!z){w(!1);return}const K=await z.pushManager.getSubscription();w(!!K)}catch{w(!1)}})()},[r]);const S=async _=>{if(e){l(_);return}if(!r){l(_);return}if(_&&typeof Notification<"u"&&Notification.permission==="default")try{const H=await Notification.requestPermission();R(H),H==="granted"?l(!0):E.error(t("settings.notifications.page.toast.permissionDenied.title"),{description:t("settings.notifications.page.toast.permissionDenied.description")})}catch(H){console.error("Failed to request notification permission:",H),E.error(t("settings.notifications.page.toast.requestPermissionFailed"))}else l(!!(_&&A==="granted"))},M=e||a||n||r&&typeof Notification<"u"&&Notification.permission==="granted",V=(_,H,z)=>{m(K=>({...K,[_]:{...K[_],[H]:z}}))},$=_=>{const H="=".repeat((4-_.length%4)%4),z=(_+H).replace(/-/g,"+").replace(/_/g,"/"),K=atob(z),te=new Uint8Array(K.length);for(let Y=0;Y<K.length;Y+=1)te[Y]=K.charCodeAt(Y);return te},k=async(_,H,z)=>{let K=null;const te=new Promise((Y,ne)=>{K=setTimeout(()=>{ne(new Error(z))},H)});try{return await Promise.race([_,te])}finally{K&&clearTimeout(K)}},W=async _=>{if(_.active)return;const H=_.installing||_.waiting;H&&H.state!=="activated"&&await k(new Promise(z=>{const K=()=>{H.state==="activated"&&(H.removeEventListener("statechange",K),z())};H.addEventListener("statechange",K),K()}),15e3,"Service worker activation timed out")},D=async()=>{if(typeof navigator.serviceWorker.register!="function")throw new Error("navigator.serviceWorker.register unavailable");const _=[{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 H=null;for(const z of _)try{const K=z.opts?navigator.serviceWorker.register("/sw.js",z.opts):navigator.serviceWorker.register("/sw.js");return await k(K,1e4,`Service worker registration timed out (${z.label})`)}catch(K){H=K}throw H instanceof Error?H:new Error("Service worker registration failed")},L=async()=>{if(!("serviceWorker"in navigator))throw new Error("Service worker not supported");const _=await navigator.serviceWorker.getRegistration();if(_)return _;const H=await D();try{await H.update()}catch{}return await W(H),H},J=_=>{const H=_,z=[`type=${typeof _}`,`toString=${String(_)}`,`name=${String(H?.name??"")}`,`message=${String(H?.message??"")}`];let K="";try{K=JSON.stringify(_)}catch{}return{summary:z.filter(Boolean).join(" | "),json:K,stack:typeof H?.stack=="string"?H.stack:""}},ee=async()=>{const _=fa();if(!_?.notifications){E.error(t("settings.notifications.page.toast.notificationsApiUnavailable"));return}try{await _.notifications.notifyAgentCompletion({title:t("settings.notifications.page.testNotification.title"),body:t("settings.notifications.page.testNotification.body"),tag:"openchamber-test"})?E.success(t("settings.notifications.page.toast.testNotificationSent")):E.error(t("settings.notifications.page.toast.testNotificationFailed"))}catch(H){console.error("Test notification failed:",H),E.error(t("settings.notifications.page.toast.testNotificationFailed"))}},U=async()=>{if(!I){E.error(t("settings.notifications.page.toast.pushUnsupported"));return}const _=fa();if(!_?.push){E.error(t("settings.notifications.page.toast.pushApiUnavailable"));return}T(!0);try{if(typeof Notification<"u"&&Notification.permission==="default"){const de=await Notification.requestPermission();if(R(de),de!=="granted"){E.error(t("settings.notifications.page.toast.permissionDenied.title"),{description:t("settings.notifications.page.toast.permissionDenied.enableInBrowser")});return}}if(typeof Notification<"u"&&Notification.permission!=="granted"){E.error(t("settings.notifications.page.toast.permissionDenied.title"),{description:t("settings.notifications.page.toast.permissionDenied.enableInBrowser")});return}const H=await _.push.getVapidPublicKey();if(!H?.publicKey){E.error(t("settings.notifications.page.toast.pushKeyLoadFailed"));return}const z=await L();await W(z);const K=await z.pushManager.getSubscription();if(!("pushManager"in z)||!z.pushManager)throw new Error("PushManager unavailable (requires installed PWA + iOS 16.4+)");const Y=(K??await k(z.pushManager.subscribe({userVisibleOnly:!0,applicationServerKey:$(H.publicKey)}),15e3,"Push subscription timed out")).toJSON(),ne=Y.keys;if(!Y.endpoint||!ne?.p256dh||!ne.auth)throw new Error("Push subscription missing keys");if(!(await k(_.push.subscribe({endpoint:Y.endpoint,keys:{p256dh:ne.p256dh,auth:ne.auth},origin:typeof window<"u"?window.location.origin:void 0,platform:Kd()}),15e3,"Push subscribe request timed out"))?.ok){E.error(t("settings.notifications.page.toast.enableBackgroundFailed"));return}w(!0),E.success(t("settings.notifications.page.toast.backgroundEnabled"))}catch(H){console.error("[Push] Enable failed:",H);const z=J(H);E.error(t("settings.notifications.page.toast.enableBackgroundFailed"),{description:z.summary})}finally{T(!1)}},re=async()=>{if(!I){w(!1);return}const _=fa();if(!_?.push){E.error(t("settings.notifications.page.toast.pushApiUnavailable"));return}T(!0);try{const z=await(await L()).pushManager.getSubscription();if(!z){w(!1);return}const K=z.endpoint;await z.unsubscribe(),await _.push.unsubscribe({endpoint:K}),w(!1),E.success(t("settings.notifications.page.toast.backgroundDisabled"))}finally{T(!1)}};return s.jsxs(s.Fragment,{children:[s.jsxs(ze,{settingsItem:"notifications.delivery",title:t("settings.notifications.page.delivery.title"),divider:!1,children:[s.jsxs("div",{className:fs,children:[s.jsx(dt,{checked:i&&M,onChange:_=>{S(_)},label:t("settings.notifications.page.delivery.enableLabel"),info:r?t("settings.notifications.page.delivery.browserPermissionHint"):a?t("settings.notifications.page.delivery.vscodeHint"):void 0,ariaLabel:t("settings.notifications.page.delivery.enableAria")}),i&&M&&!n&&s.jsxs(s.Fragment,{children:[s.jsx(dt,{checked:g==="always",onChange:_=>c(_?"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(B,{type:"button",variant:"outline",size:"sm",onClick:()=>{ee()},children:t("settings.notifications.page.delivery.testAction")})})]})]}),r&&s.jsxs("div",{className:"mt-1",children:[A==="denied"&&s.jsx("p",{className:"typography-meta text-[var(--status-error)] mt-1",children:t("settings.notifications.page.delivery.permissionDenied")}),A==="granted"&&!i&&s.jsx("p",{className:"typography-meta text-muted-foreground/70 mt-1",children:t("settings.notifications.page.delivery.permissionGrantedButDisabled")})]})]}),i&&M&&s.jsxs(s.Fragment,{children:[s.jsx(ze,{settingsItem:"notifications.events",title:t("settings.notifications.page.events.title"),children:s.jsxs("div",{className:fs,children:[s.jsx(dt,{checked:b,onChange:d,label:t("settings.notifications.page.events.completionLabel"),ariaLabel:t("settings.notifications.page.events.completionAria")}),s.jsx(dt,{checked:y,onChange:p,label:t("settings.notifications.page.events.subtaskLabel"),ariaLabel:t("settings.notifications.page.events.subtaskAria")}),s.jsx(dt,{checked:C,onChange:f,label:t("settings.notifications.page.events.errorLabel"),ariaLabel:t("settings.notifications.page.events.errorAria")}),s.jsx(dt,{checked:P,onChange:x,label:t("settings.notifications.page.events.questionLabel"),ariaLabel:t("settings.notifications.page.events.questionAria")})]})}),!n&&s.jsx(ze,{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(Sn,{className:"gap-2 md:grid-cols-2 md:gap-3 lg:gap-3",children:["completion","subtask","error","question"].map(_=>s.jsxs("section",{className:"p-2",children:[s.jsx(Zs,{className:"capitalize",children:t(Yh[_])}),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:N[_].title,onChange:H=>V(_,"title",H.target.value),className:"h-7",placeholder:t(il[_].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:N[_].message,onChange:H=>V(_,"message",H.target.value),className:"h-7",placeholder:t(il[_].messageKey)})]})]})]},_))})})]}),r&&s.jsx(ze,{settingsItem:"notifications.push",title:t("settings.notifications.page.push.title"),children:s.jsx(dt,{checked:I?h:!1,disabled:!I||O,onChange:_=>{_?U():re()},label:t("settings.notifications.page.push.enableLabel"),description:I?void 0:t("settings.notifications.page.push.unsupportedHint"),info:I?t("settings.notifications.page.push.supportedHint"):void 0,ariaLabel:t("settings.notifications.page.push.enableAria"),labelAccessory:O?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})})]})},Ls=t=>{if(!t)return;t.pause();const{src:e}=t;e.startsWith("blob:")&&URL.revokeObjectURL(e),t.removeAttribute("src"),t.load()},Xh=[{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"}],rl=t=>{const e=ut.c(8),{value:a,label:n}=t,r=`${n}: ${a}/5`,i=`${a/5*100}%`;let l;e[0]!==i?(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:i}})}),e[0]=i,e[1]=l):l=e[1];let g;e[2]!==n?(g=s.jsx("span",{className:"typography-ui-compact text-muted-foreground",children:n}),e[2]=n,e[3]=g):g=e[3];let c;return e[4]!==r||e[5]!==l||e[6]!==g?(c=s.jsxs("span",{className:"flex items-center gap-1.5",title:r,children:[l,g]}),e[4]=r,e[5]=l,e[6]=g,e[7]=c):c=e[7],c},ef=({selectedModelId:t,onSelect:e})=>{const{t:a}=tt(),n=$e.useCallback(d=>a(d),[a]),[r,i]=$e.useState(new Map),[l,g]=$e.useState(null),c=$e.useCallback(async()=>{try{const d=await yt("/api/dictation/status",{query:{provider:"local"}});if(!d.ok)return;const C=await d.json();Array.isArray(C?.models)&&i(new Map(C.models.map(f=>[f.id,f])))}catch{}},[]);$e.useEffect(()=>{c()},[c]);const y=Array.from(r.values()).some(d=>d.downloading);$e.useEffect(()=>{if(!y)return;const d=setInterval(()=>{c()},2e3);return()=>clearInterval(d)},[y,c]);const p=async d=>{g(d);try{await yt(`/api/dictation/models/${encodeURIComponent(d)}/download`,{method:"POST"}),await c()}catch{}finally{g(null)}},b=async d=>{g(d);try{await yt(`/api/dictation/models/${encodeURIComponent(d)}`,{method:"DELETE"}),await c()}catch{}finally{g(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:Xh.map(d=>{const C=t===d.id,f=r.get(d.id)??null;return s.jsx("div",{className:fe("rounded-lg border border-[var(--interactive-border)] p-3",C&&"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(d.id),onKeyDown:P=>{(P.key===" "||P.key==="Enter")&&(P.preventDefault(),e(d.id))},children:[s.jsx("div",{className:"pt-0.5",children:s.jsx(jr,{checked:C,onChange:()=>e(d.id),ariaLabel:n(d.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:fe("typography-ui-label font-normal",C?"text-foreground":"text-foreground/50"),children:n(d.labelKey)}),d.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(d.badgeKey)}):null]}),s.jsxs("div",{className:"flex flex-col gap-1.5",children:[s.jsx(rl,{value:d.accuracy,label:a("settings.voice.page.stt.meta.accuracy")}),s.jsx(rl,{value:d.speed,label:a("settings.voice.page.stt.meta.speed")}),s.jsx("span",{className:"typography-ui-compact tabular-nums text-muted-foreground",children:d.size})]}),f?.downloadError?s.jsx("p",{className:"typography-meta text-[var(--status-error)]",children:f.downloadError}):null]})]}),s.jsx("div",{className:"flex shrink-0 items-center gap-1",children:f?.installed?s.jsxs(s.Fragment,{children:[s.jsx(B,{variant:"ghost",size:"xs",className:"h-6 w-6 p-0 text-muted-foreground hover:text-[var(--status-error)]",disabled:l===d.id,onClick:()=>{b(d.id)},title:a("settings.voice.page.stt.modelDelete"),"aria-label":a("settings.voice.page.stt.modelDelete"),children:s.jsx(F,{name:"delete-bin",className:"h-4 w-4"})}),s.jsx(F,{name:"checkbox-circle",className:"h-4 w-4 flex-shrink-0 text-[var(--status-success)]","aria-label":a("settings.voice.page.stt.modelInstalled")})]}):f?.downloading?s.jsxs("span",{className:"flex items-center gap-1.5",children:[s.jsx(F,{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 f.downloadProgress=="number"?`${f.downloadProgress}%`:""})]}):s.jsx(B,{variant:"ghost",size:"xs",className:"h-6 w-6 p-0",disabled:l===d.id,onClick:()=>{p(d.id)},title:a("settings.voice.page.stt.modelDownload"),"aria-label":a("settings.voice.page.stt.modelDownload"),children:s.jsx(F,{name:"download",className:"h-4 w-4"})})})]})},d.id)})})},tf=[{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)"}],vr="kokoro-en-v0_19",sf="kokoro-multi-lang-v1_1",nf=[{id:0,label:"Maple (af)"},{id:1,label:"Sol (af)"},{id:2,label:"Vale (bf)"},{id:3,label:"Xiaoxiao (zf)"},{id:58,label:"Yunxi (zm)"}],Ma=(t,e)=>`${t}:${e}`,af=()=>{const[t,e]=$e.useState([]),[a,n]=$e.useState(null),r=$e.useCallback(async()=>{try{const g=await yt("/api/dictation/status",{query:{provider:"local"}});if(!g.ok)return;const c=await g.json();Array.isArray(c?.ttsModels)&&e(c.ttsModels)}catch{}},[]);$e.useEffect(()=>{r()},[r]);const i=t.some(g=>g.downloading);$e.useEffect(()=>{if(!i)return;const g=setInterval(()=>{r()},2e3);return()=>clearInterval(g)},[i,r]);const l=$e.useCallback(async(g,c)=>{n(g);try{const y=c==="POST"?`/api/dictation/models/${g}/download`:`/api/dictation/models/${g}`;await yt(y,{method:c}),await r()}catch{}finally{n(null)}},[r]);return{models:t,requestingId:a,request:l,refresh:r}},rf=t=>{const e=tf.map(a=>({modelId:vr,speakerId:a.id,label:a.label}));for(const a of t)if(!(a.id===vr||!a.installed)){if(a.id===sf){for(const n of nf)e.push({modelId:a.id,speakerId:n.id,label:`${n.label} · Kokoro zh/en`});continue}e.push({modelId:a.id,speakerId:0,label:a.description??a.id})}return e},of=t=>{const e=ut.c(14),{models:a,requestingId:n,request:r}=t,{t:i}=tt();let l,g,c;if(e[0]!==a||e[1]!==r||e[2]!==n||e[3]!==i){c=Symbol.for("react.early_return_sentinel");e:{const p=a.filter(df);if(p.length===0){c=null;break e}l="flex flex-col";let b;e[7]!==r||e[8]!==n||e[9]!==i?(b=d=>s.jsxs("div",{className:"flex items-center gap-2 py-1.5",children:[s.jsx("span",{className:"typography-ui-label text-foreground",children:d.description??d.id}),d.installed?s.jsxs(s.Fragment,{children:[s.jsx(F,{name:"checkbox-circle",className:"h-4 w-4 text-[var(--status-success)]","aria-label":i("settings.voice.page.stt.modelInstalled")}),s.jsx(B,{variant:"ghost",size:"xs",className:"h-6 w-6 p-0 text-muted-foreground hover:text-[var(--status-error)]",disabled:n!==null,onClick:()=>{r(d.id,"DELETE")},title:i("settings.voice.page.stt.modelDelete"),"aria-label":i("settings.voice.page.stt.modelDelete"),children:s.jsx(F,{name:"delete-bin",className:"h-4 w-4"})})]}):d.downloading?s.jsxs("span",{className:"flex items-center gap-1.5",children:[s.jsx(F,{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 d.downloadProgress=="number"?`${d.downloadProgress}%`:""})]}):s.jsx(B,{variant:"ghost",size:"xs",className:"h-6 w-6 p-0",disabled:n!==null,onClick:()=>{r(d.id,"POST")},title:i("settings.voice.page.stt.modelDownload"),"aria-label":i("settings.voice.page.stt.modelDownload"),children:s.jsx(F,{name:"download",className:"h-4 w-4"})}),d.downloadError?s.jsx("span",{className:"typography-meta text-[var(--status-error)]",children:d.downloadError}):null]},d.id),e[7]=r,e[8]=n,e[9]=i,e[10]=b):b=e[10],g=p.map(b)}e[0]=a,e[1]=r,e[2]=n,e[3]=i,e[4]=l,e[5]=g,e[6]=c}else l=e[4],g=e[5],c=e[6];if(c!==Symbol.for("react.early_return_sentinel"))return c;let y;return e[11]!==l||e[12]!==g?(y=s.jsx("div",{className:l,children:g}),e[11]=l,e[12]=g,e[13]=y):y=e[13],y},lf=[{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"}],cf=()=>{const{t}=tt(),{isMobile:e}=wa(),a=Ye(G=>G.voiceProvider),n=Ye(G=>G.setVoiceProvider),r=Ye(G=>G.speechRate),i=Ye(G=>G.setSpeechRate),l=Ye(G=>G.speechPitch),g=Ye(G=>G.setSpeechPitch),c=Ye(G=>G.speechVolume),y=Ye(G=>G.setSpeechVolume),p=Ye(G=>G.sayVoice),b=Ye(G=>G.setSayVoice),d=Ye(G=>G.localTtsVoiceId),C=Ye(G=>G.localTtsModelId),f=Ye(G=>G.setLocalTtsModelId),P=af(),x=$e.useMemo(()=>rf(P.models),[P.models]),N=Ye(G=>G.ttsFollowTextLanguage),m=Ye(G=>G.setTtsFollowTextLanguage),A=Ye(G=>G.setLocalTtsVoiceId),{speak:R,stop:I,isPlaying:j,error:h}=id(),w=$e.useCallback(()=>{if(j){I();return}const G=x.find(Ge=>Ge.modelId===C&&Ge.speakerId===d)?.label??String(d);R(t("settings.voice.page.preview.voiceLine",{voiceName:G}),{model:C,speakerId:d,speed:Ye.getState().speechRate})},[j,C,d,x,R,I,t]),O=Ye(G=>G.browserVoice),T=Ye(G=>G.setBrowserVoice),S=Ye(G=>G.openaiVoice),M=Ye(G=>G.setOpenaiVoice),V=Ye(G=>G.openaiApiKey),$=Ye(G=>G.setOpenaiApiKey),k=Ye(G=>G.openaiCompatibleUrl),W=Ye(G=>G.setOpenaiCompatibleUrl),D=Ye(G=>G.openaiCompatibleApiKey),L=Ye(G=>G.setOpenaiCompatibleApiKey),J=Ye(G=>G.openaiCompatibleVoice),ee=Ye(G=>G.setOpenaiCompatibleVoice),U=Ye(G=>G.openaiCompatibleTtsModel),re=Ye(G=>G.setOpenaiCompatibleTtsModel),_=Ye(G=>G.showMessageTTSButtons),H=Ye(G=>G.ttsInputMode),z=Ye(G=>G.setTtsInputMode),K=Ye(G=>G.sttProvider),te=Ye(G=>G.setSttProvider),Y=Ye(G=>G.sttServerUrl),ne=Ye(G=>G.setSttServerUrl),me=Ye(G=>G.sttApiKey),de=Ye(G=>G.setSttApiKey),xe=Ye(G=>G.sttModel),ae=Ye(G=>G.setSttModel),le=Ye(G=>G.sttLocalModel),ge=Ye(G=>G.setSttLocalModel),Ae=Ye(G=>G.sttLanguage),Se=Ye(G=>G.setSttLanguage),Ce=Ye(G=>G.setShowMessageTTSButtons),he=Ye(G=>G.dictationEnabled),_e=Ye(G=>G.setDictationEnabled),[Ue,ke]=$e.useState(!1),[Oe,Ve]=$e.useState([]),[We,ve]=$e.useState(!1),[Z,se]=$e.useState(null),[ye,be]=$e.useState(!1),[Re,Fe]=$e.useState(!1),[Ke,Ee]=$e.useState(null),[we,Ze]=$e.useState(!1),[pe,Ne]=$e.useState(null),[Le,Xe]=$e.useState([]),[q,je]=$e.useState(!1);$e.useEffect(()=>((async()=>{const Ge=await Gi.waitForVoices();Xe(Ge)})(),"speechSynthesis"in window&&(window.speechSynthesis.onvoiceschanged=()=>{Xe(window.speechSynthesis.getVoices())}),()=>{"speechSynthesis"in window&&(window.speechSynthesis.onvoiceschanged=null)}),[]);const Ie=$e.useMemo(()=>Le.filter(G=>G.lang).sort((G,Ge)=>{const nt=G.lang.startsWith("en"),lt=Ge.lang.startsWith("en");if(nt&&!lt)return-1;if(!nt&&lt)return 1;const ht=G.lang.localeCompare(Ge.lang);return ht!==0?ht:G.name.localeCompare(Ge.name)}),[Le]),Je=$e.useCallback(()=>{if(q){Gi.cancelSpeech(),je(!1);return}const G=Le.find(ht=>ht.name===O),Ge=G?.name??t("settings.voice.page.preview.browserVoiceFallback"),nt=t("settings.voice.page.preview.voiceLine",{voiceName:Ge});je(!0);const lt=new SpeechSynthesisUtterance(nt);lt.rate=r,lt.pitch=l,lt.volume=c,G&&(lt.voice=G,lt.lang=G.lang),lt.onend=()=>je(!1),lt.onerror=()=>je(!1),window.speechSynthesis.cancel(),window.speechSynthesis.speak(lt)},[O,Le,r,l,c,q,t]);$e.useEffect(()=>()=>{q&&Gi.cancelSpeech()},[q]),$e.useEffect(()=>{if(!_||a!=="openai"&&a!=="openai-compatible"){be(V.trim().length>0);return}(async()=>{try{const lt=(await(await yt("/api/tts/status")).json()).available,ht=V.trim().length>0;be(lt||ht)}catch{be(V.trim().length>0)}})()},[V,_,a]),$e.useEffect(()=>{if(!_){ke(!1),Ve([]);return}yt("/api/tts/say/status").then(G=>G.json()).then(G=>{if(ke(G.available),G.voices){const Ge=G.voices.filter((nt,lt,ht)=>ht.findIndex(Lt=>Lt.name===nt.name)===lt).sort((nt,lt)=>nt.name.localeCompare(lt.name));Ve(Ge)}}).catch(()=>{ke(!1)})},[_]);const ot=$e.useCallback(async()=>{if(Z){Ls(Z),se(null),ve(!1);return}ve(!0);let G=null;try{const Ge=await yt("/api/tts/say/speak",{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify({text:t("settings.voice.page.preview.voiceLine",{voiceName:p}),voice:p,rate:Math.round(100+(r-.5)*200)})});if(!Ge.ok)throw new Error("Preview failed");const nt=await Ge.blob(),lt=URL.createObjectURL(nt);G=new Audio(lt),G.onended=()=>{Ls(G),se(null),ve(!1)},G.onerror=()=>{Ls(G),se(null),ve(!1)},se(G),await G.play()}catch{Ls(G),se(null),ve(!1)}},[p,r,Z,t]);$e.useEffect(()=>()=>{Ls(Z)},[Z]);const st=$e.useCallback(async()=>{if(Ke){Ls(Ke),Ee(null),Fe(!1);return}Fe(!0);let G=null;try{const Ge=await yt("/api/tts/speak",{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify({text:t("settings.voice.page.preview.voiceLine",{voiceName:S}),voice:S,speed:r,apiKey:V||void 0})});if(!Ge.ok){const ht=await Ge.json().catch(()=>({error:"Unknown error"}));throw new Error(ht.error||`HTTP ${Ge.status}`)}const nt=await Ge.blob(),lt=URL.createObjectURL(nt);G=new Audio(lt),G.onended=()=>{Ls(G),Ee(null),Fe(!1)},G.onerror=()=>{Ls(G),Ee(null),Fe(!1)},Ee(G),await G.play()}catch{Ls(G),Ee(null),Fe(!1)}},[S,r,Ke,V,t]);$e.useEffect(()=>()=>{Ls(Ke)},[Ke]);const mt=$e.useCallback(async()=>{if(pe){Ls(pe),Ne(null),Ze(!1);return}if(!k.trim())return;Ze(!0);let G=null;try{const Ge=await yt("/api/tts/speak",{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify({text:t("settings.voice.page.preview.customServerLine"),voice:J,model:U||void 0,speed:r,baseURL:k,apiKey:D||void 0})});if(!Ge.ok){const ht=await Ge.json().catch(()=>({error:"Unknown error"}));throw new Error(ht.error||`HTTP ${Ge.status}`)}const nt=await Ge.blob(),lt=URL.createObjectURL(nt);G=new Audio(lt),G.onended=()=>{Ls(G),Ne(null),Ze(!1)},G.onerror=()=>{Ls(G),Ne(null),Ze(!1)},Ne(G),await G.play()}catch{Ls(G),Ne(null),Ze(!1)}},[k,J,U,D,r,pe,t]);$e.useEffect(()=>()=>{Ls(pe)},[pe]);const vt="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(ze,{settingsItem:"voice.playback",title:t("settings.voice.page.section.playbackAndSummary"),divider:!1,contentClassName:"space-y-4",children:[s.jsx(dt,{checked:_,onChange:Ce,label:t("settings.voice.page.field.messageReadAloudButton"),ariaLabel:t("settings.voice.page.field.messageReadAloudButtonAria")}),_&&s.jsxs(s.Fragment,{children:[s.jsx(Ss,{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(Ys,{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")},...Ue?[{value:"say",label:s.jsxs(s.Fragment,{children:[s.jsx(F,{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:fe(Tt,!ye&&"text-[var(--status-error)]"),children:t("settings.voice.page.field.apiKey")}),s.jsx("span",{className:fe(zn,!ye&&"text-[var(--status-error)]/80"),children:t(ye&&!V?"settings.voice.page.field.apiKeyHintUsingConfig":ye?"settings.voice.page.field.apiKeyHintProvide":"settings.voice.page.field.apiKeyHintRequired")}),s.jsxs("div",{className:fe("relative",zs),children:[s.jsx("input",{type:"password",value:V,onChange:G=>$(G.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"}),V&&s.jsx("button",{type:"button",onClick:()=>$(""),className:"absolute right-2 top-1/2 -translate-y-1/2 text-muted-foreground hover:text-foreground",children:s.jsx(F,{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:fe(Tt,!k.trim()&&"text-[var(--status-error)]"),children:t("settings.voice.page.field.serverUrl")}),s.jsx(Jt,{children:t("settings.voice.page.field.serverUrlHint")})]}),s.jsxs("div",{className:fe("relative",zs),children:[s.jsx("input",{type:"text",value:k,onChange:G=>W(G.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"}),k&&s.jsx("button",{type:"button",onClick:()=>W(""),className:"absolute right-2 top-1/2 -translate-y-1/2 text-muted-foreground hover:text-foreground",children:s.jsx(F,{name:"close",className:"w-3.5 h-3.5"})})]})]}),s.jsxs("div",{className:"space-y-1.5",children:[s.jsx("span",{className:Tt,children:"API Key"}),s.jsx("span",{className:zn,children:"Optional"}),s.jsxs("div",{className:fe("relative",zs),children:[s.jsx("input",{type:"password",value:D,onChange:G=>L(G.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"}),D&&s.jsx("button",{type:"button",onClick:()=>L(""),className:"absolute right-2 top-1/2 -translate-y-1/2 text-muted-foreground hover:text-foreground",children:s.jsx(F,{name:"close",className:"w-3.5 h-3.5"})})]})]}),s.jsxs("div",{className:"space-y-1.5",children:[s.jsx("span",{className:Tt,children:t("settings.voice.page.field.model")}),s.jsx("div",{className:fe("relative",zs),children:s.jsx("input",{type:"text",value:U,onChange:G=>re(G.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:Tt,children:t("settings.voice.page.field.voice")}),s.jsx(Jt,{children:t("settings.voice.page.field.voiceIdentifierHint")})]}),s.jsxs("div",{className:fe("flex items-center gap-2",zs),children:[s.jsx("div",{className:"relative min-w-0 flex-1",children:s.jsx("input",{type:"text",value:J,onChange:G=>ee(G.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(B,{size:"xs",variant:"ghost",onClick:mt,title:t("settings.voice.page.actions.preview"),disabled:!k.trim(),children:we?s.jsx(F,{name:"stop",className:"w-3.5 h-3.5"}):s.jsx(F,{name:"play",className:"w-3.5 h-3.5"})})]})]})]}),a==="local"&&s.jsx(of,{...P}),(a==="local"||a==="say")&&s.jsx(dt,{checked:N,onChange:m,label:t("settings.voice.page.field.followTextLanguage"),ariaLabel:t("settings.voice.page.field.followTextLanguageAria"),info:t("settings.voice.page.field.followTextLanguageInfo")}),s.jsxs(Rt,{label:t("settings.voice.page.field.voice"),children:[a==="local"&&s.jsxs(s.Fragment,{children:[s.jsxs(St,{value:Ma(C,d),onValueChange:G=>{const Ge=x.find(nt=>Ma(nt.modelId,nt.speakerId)===G);Ge&&(f(Ge.modelId),A(Ge.speakerId))},children:[s.jsx(Ct,{size:Ft,className:rn,children:s.jsx(Mt,{placeholder:t("settings.voice.page.field.selectVoicePlaceholder"),children:G=>x.find(Ge=>Ma(Ge.modelId,Ge.speakerId)===G)?.label??G})}),s.jsx(It,{children:x.map(G=>s.jsx(at,{value:Ma(G.modelId,G.speakerId),children:G.label},Ma(G.modelId,G.speakerId)))})]}),s.jsx(B,{size:"xs",variant:"ghost",onClick:w,title:t("settings.voice.page.actions.preview"),children:j?s.jsx(F,{name:"stop",className:"w-3.5 h-3.5"}):s.jsx(F,{name:"play",className:"w-3.5 h-3.5"})}),h?s.jsx("span",{className:"typography-meta text-[var(--status-error)]",children:h}):null]}),a==="openai"&&ye&&s.jsxs(s.Fragment,{children:[s.jsxs(St,{value:S,onValueChange:M,children:[s.jsx(Ct,{size:Ft,className:rn,children:s.jsx(Mt,{placeholder:t("settings.voice.page.field.selectVoicePlaceholder")})}),s.jsx(It,{children:lf.map(G=>s.jsx(at,{value:G.value,children:G.label},G.value))})]}),s.jsx(B,{size:"xs",variant:"ghost",onClick:st,title:t("settings.voice.page.actions.preview"),children:Re?s.jsx(F,{name:"stop",className:"w-3.5 h-3.5"}):s.jsx(F,{name:"play",className:"w-3.5 h-3.5"})})]}),a==="openai-compatible"&&s.jsx("span",{className:zn,children:t("settings.voice.page.field.configuredAbove")}),a==="say"&&Ue&&Oe.length>0&&s.jsxs(s.Fragment,{children:[s.jsxs(St,{value:p,onValueChange:b,children:[s.jsx(Ct,{size:Ft,className:rn,children:s.jsx(Mt,{placeholder:t("settings.voice.page.field.selectVoicePlaceholder")})}),s.jsx(It,{children:Oe.map(G=>s.jsx(at,{value:G.name,children:G.name},G.name))})]}),s.jsx(B,{size:"xs",variant:"ghost",onClick:ot,title:t("settings.voice.page.actions.preview"),children:We?s.jsx(F,{name:"stop",className:"w-3.5 h-3.5"}):s.jsx(F,{name:"play",className:"w-3.5 h-3.5"})})]}),a==="browser"&&Ie.length>0&&s.jsxs(s.Fragment,{children:[s.jsxs(St,{value:O||"$auto",onValueChange:G=>T(G==="$auto"?"":G),children:[s.jsx(Ct,{size:Ft,className:rn,children:s.jsx(Mt,{placeholder:t("settings.voice.page.field.auto")})}),s.jsxs(It,{children:[s.jsx(at,{value:"$auto",children:t("settings.voice.page.field.auto")}),Ie.map(G=>s.jsxs(at,{value:G.name,children:[G.name," (",G.lang,")"]},G.name))]})]}),s.jsx(B,{size:"xs",variant:"ghost",onClick:Je,title:t("settings.voice.page.actions.preview"),children:q?s.jsx(F,{name:"stop",className:"w-3.5 h-3.5"}):s.jsx(F,{name:"play",className:"w-3.5 h-3.5"})})]})]}),s.jsxs(Rt,{label:t("settings.voice.page.field.speechRate"),children:[!e&&s.jsx("input",{type:"range",min:.5,max:2,step:.1,value:r,onChange:G=>i(Number(G.target.value)),className:vt}),s.jsx(xs,{value:r,onValueChange:i,min:.5,max:2,step:.1,className:fe(Ps,"tabular-nums")})]}),s.jsxs(Rt,{label:t("settings.voice.page.field.speechPitch"),children:[!e&&s.jsx("input",{type:"range",min:.5,max:2,step:.1,value:l,onChange:G=>g(Number(G.target.value)),className:vt}),s.jsx(xs,{value:l,onValueChange:g,min:.5,max:2,step:.1,className:fe(Ps,"tabular-nums")})]}),s.jsxs(Rt,{label:t("settings.voice.page.field.speechVolume"),children:[!e&&s.jsx("input",{type:"range",min:0,max:1,step:.1,value:c,onChange:G=>y(Number(G.target.value)),className:vt}),e?s.jsx(xs,{value:Math.round(c*100),onValueChange:G=>y(G/100),min:0,max:100,step:10,className:fe(Ps,"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(Ss,{title:t("settings.voice.page.field.ttsInputMode"),children:s.jsx(Ys,{value:H,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(ze,{settingsItem:"voice.speech-recognition",title:t("settings.voice.page.section.speechRecognition"),contentClassName:"space-y-4",children:[s.jsx(dt,{checked:he,onChange:_e,label:t("settings.voice.page.field.enableVoiceInput"),ariaLabel:t("settings.voice.page.field.enableVoiceInputAria")}),he&&s.jsxs(s.Fragment,{children:[s.jsx(Ss,{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(Ys,{value:K,onChange:te,"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")}]})}),K==="local"&&s.jsxs("div",{className:"space-y-1.5",children:[s.jsx("span",{className:Tt,children:t("settings.voice.page.field.model")}),s.jsx(ef,{selectedModelId:le,onSelect:ge})]}),K==="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:fe(Tt,!Y.trim()&&"text-[var(--status-error)]"),children:t("settings.voice.page.field.serverUrl")}),s.jsx(Jt,{children:t("settings.voice.page.field.sttServerUrlHint")})]}),s.jsxs("div",{className:fe("relative",zs),children:[s.jsx("input",{type:"text",value:Y,onChange:G=>ne(G.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"}),Y&&s.jsx("button",{type:"button",onClick:()=>ne(""),className:"absolute right-2 top-1/2 -translate-y-1/2 text-muted-foreground hover:text-foreground",children:s.jsx(F,{name:"close",className:"w-3.5 h-3.5"})})]})]}),s.jsxs("div",{className:"space-y-1.5",children:[s.jsx("span",{className:Tt,children:"API Key"}),s.jsx("span",{className:zn,children:"Optional"}),s.jsxs("div",{className:fe("relative",zs),children:[s.jsx("input",{type:"password",value:me,onChange:G=>de(G.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"}),me&&s.jsx("button",{type:"button",onClick:()=>de(""),className:"absolute right-2 top-1/2 -translate-y-1/2 text-muted-foreground hover:text-foreground",children:s.jsx(F,{name:"close",className:"w-3.5 h-3.5"})})]})]}),s.jsxs("div",{className:"space-y-1.5",children:[s.jsx("span",{className:Tt,children:t("settings.voice.page.field.model")}),s.jsx("div",{className:fe("relative",zs),children:s.jsx("input",{type:"text",value:xe,onChange:G=>ae(G.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:Tt,children:t("settings.voice.page.field.language")}),s.jsx(Jt,{children:t("settings.voice.page.field.sttLanguageHint")})]}),s.jsx("div",{className:"relative max-w-[8rem]",children:s.jsx("input",{type:"text",value:Ae,onChange:G=>Se(G.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"})})]})]})]})]})]})};function df(t){return t.id===vr||t.installed||t.downloading}const hi=[{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}],fi=[{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}],uf="https://developers.cloudflare.com/cloudflare-one/networks/connectors/cloudflare-tunnel/get-started/create-remote-tunnel/",pf="https://developers.cloudflare.com/cloudflare-one/networks/connectors/cloudflare-tunnel/do-more-with-tunnels/local-management/configuration-file/",ir=[{value:"quick",labelKey:"settings.aiworker.tunnel.option.mode.quick.label",tooltipKey:"settings.aiworker.tunnel.option.mode.quick.tooltip"},{value:"managed-remote",labelKey:"settings.aiworker.tunnel.option.mode.managedRemote.label",tooltipKey:"settings.aiworker.tunnel.option.mode.managedRemote.tooltip"},{value:"managed-local",labelKey:"settings.aiworker.tunnel.option.mode.managedLocal.label",tooltipKey:"settings.aiworker.tunnel.option.mode.managedLocal.tooltip"}],mf=[".yml",".yaml",".json"],gf="settings.aiworker.tunnel.error.invalidConfigExtension",Ra=t=>{const e=t.trim().toLowerCase();return mf.some(a=>e.endsWith(a))},hf=t=>t==="ngrok"?"ngrok":"cloudflared",ac=()=>{if(typeof window<"u"&&typeof window.__AIWORKER_PLATFORM__=="string"){const e=window.__AIWORKER_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"},ff=(t,e=ac())=>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/cloudflare-tunnel/downloads/",rr=(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():hf(a),r=typeof e?.platform=="string"&&e.platform.trim().length>0?e.platform.trim():ac(),i=typeof e?.installCommand=="string"&&e.installCommand.trim().length>0?e.installCommand.trim():ff(a,r);return{provider:a,dependency:n,installCommand:i}},ic=t=>t==="cloudflare"?"Cloudflare":t==="ngrok"?"Ngrok":t,ol=t=>{const e=ut.c(11),{provider:a}=t;let n;e[0]!==a?(n=ic(a),e[0]=a,e[1]=n):n=e[1];const r=n,g=a==="cloudflare"||a==="ngrok"?"text-[var(--status-warning)]":"text-muted-foreground";let c;e[2]!==g?(c=fe("size-4 shrink-0",g),e[2]=g,e[3]=c):c=e[3];let y;e[4]!==c?(y=s.jsx(F,{name:"cloud",className:c}),e[4]=c,e[5]=y):y=e[5];let p;e[6]!==r?(p=s.jsx("span",{children:r}),e[6]=r,e[7]=p):p=e[7];let b;return e[8]!==y||e[9]!==p?(b=s.jsxs("span",{className:"flex items-center gap-2",children:[y,p]}),e[8]=y,e[9]=p,e[10]=b):b=e[10],b},Nn=t=>t==="quick"?"quick":t==="managed-remote"?"managed-remote":t==="managed-local"?"managed-local":"quick",yr=(t,e,a)=>t.find(r=>r.ms===e)?.value||a,ll=(t,e,a)=>{const n=yr(t,e,a);return t.find(r=>r.value===n)?.label||n},cl=t=>{const e=Math.max(0,t),a=Math.floor(e/1e3),n=Math.floor(a/3600),r=Math.floor(a%3600/60),i=a%60;return n>0?`${n}h ${r}m`:r>0?`${r}m ${i}s`:`${i}s`},xf=(t,e)=>Al(t,e,{hour:"2-digit",precision:"second"}),ji=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()}},vf=t=>{if(!Array.isArray(t))return[];const e=new Set,a=new Set,n=[];for(const r of t){if(!r||typeof r!="object")continue;const i=r,l=typeof i.id=="string"?i.id.trim():"",g=typeof i.name=="string"?i.name.trim():"",c=ji(typeof i.hostname=="string"?i.hostname:"");!l||!g||!c||e.has(l)||a.has(c)||(e.add(l),a.add(c),n.push({id:l,name:g,hostname:c}))}return n},yf=()=>typeof crypto<"u"&&typeof crypto.randomUUID=="function"?crypto.randomUUID():`${Date.now()}-${Math.random().toString(36).slice(2,10)}`,bf=()=>{const{t}=tt(),e=ie(Q=>Q.timeFormatPreference),a=o.useCallback(Q=>t(Q),[t]),[n,r]=o.useState("checking"),[i,l]=o.useState(null),[g,c]=o.useState(null),[y,p]=o.useState(null),[b,d]=o.useState(null),[C,f]=o.useState(null),[P,x]=o.useState(!1),[N,m]=o.useState(!1),[A,R]=o.useState(!1),[I,j]=o.useState("cloudflare"),[h,w]=o.useState(()=>rr("cloudflare")),[O,T]=o.useState([]),[S,M]=o.useState("quick"),[V,$]=o.useState(null),[k,W]=o.useState([]),[D,L]=o.useState({}),[J,ee]=o.useState(""),[U,re]=o.useState({}),[_,H]=o.useState(new Set),[z,K]=o.useState(!1),[te,Y]=o.useState(""),[ne,me]=o.useState(""),[de,xe]=o.useState(""),[ae,le]=o.useState(1800*1e3),[ge,Ae]=o.useState(480*60*1e3),[Se,Ce]=o.useState(""),[he,_e]=o.useState([]),[Ue,ke]=o.useState(()=>Date.now()),[Oe,Ve]=o.useState(null),We=t(gf),ve=o.useRef(null),Z=o.useMemo(()=>V?!Ra(V):!1,[V]),se=o.useMemo(()=>k.find(Q=>Q.id===J)||k[0]||null,[k,J]),ye=o.useMemo(()=>he.map(Q=>{const ue=Q.expiresAt<=Ue,De=Q.status==="active"&&!ue,Pe=De?cl(Q.expiresAt-Ue):Q.inactiveReason==="expired"||ue?"expired":"inactive",it=Pe==="expired"?t("settings.aiworker.tunnel.state.expired"):Q.inactiveReason==="tunnel-revoked"?t("settings.aiworker.tunnel.state.revoked"):t("settings.aiworker.tunnel.state.inactive"),rt=Nn(Q.mode);return{...Q,isActive:De,mode:rt,remainingTextForSession:Pe,inactiveLabel:it}}),[Ue,he,t]),be=o.useMemo(()=>i?.connectUrl?i.bootstrapExpiresAt===null?!0:i.bootstrapExpiresAt>Ue:!1,[Ue,i?.bootstrapExpiresAt,i?.connectUrl]),Re=o.useMemo(()=>!i||n!=="active"&&n!=="stopping"?!1:g===S,[g,n,i,S]),Fe=o.useMemo(()=>!i||n!=="active"||!g?!1:g!==S,[g,n,i,S]),Ke=o.useMemo(()=>{if(typeof Oe=="number"&&Number.isFinite(Oe)&&Oe>0)return Oe;if(typeof window>"u")return null;const ue=$a()||window.location.href;let De=0;try{De=Number(new URL(ue).port)}catch{De=Number(window.location.port)}return Number.isFinite(De)&&De>0?De:null},[Oe]),Ee=o.useMemo(()=>O.find(Q=>Q.provider===I)??null,[O,I]),we=o.useMemo(()=>{const Q=new Set(Ee?.modes?.map(ue=>ue.key).filter(ue=>ue==="quick"||ue==="managed-remote"||ue==="managed-local"));return Q.size===0?ir:ir.filter(ue=>Q.has(ue.value))},[Ee]),Ze=o.useMemo(()=>we.some(Q=>Q.value==="managed-remote"||Q.value==="managed-local"),[we]),pe=o.useMemo(()=>h.provider===I?h:rr(I),[h,I]),Ne=o.useCallback(async Q=>{await Pn(Q)},[]),Le=o.useCallback((Q,ue)=>(w(rr(ue,Q)),Q.available===!0),[]),Xe=o.useCallback(async(Q,ue)=>{try{const De=await yt("/api/openchamber/tunnel/check",{query:{provider:Q},...ue?{signal:ue}:{}});if(!De.ok)return null;const Pe=await De.json();if(ue?.aborted)return null;const it=Le(Pe,Q);return r(rt=>rt==="checking"||rt==="starting"||rt==="active"||rt==="stopping"?rt:it?"idle":"not-available"),it}catch{return null}},[Le]),q=o.useCallback(async Q=>{try{const[ue,De,Pe,it]=await Promise.all([yt("/api/openchamber/tunnel/check",{signal:Q}),yt("/api/openchamber/tunnel/status",{signal:Q}),pn(),yt("/api/openchamber/tunnel/providers",{signal:Q})]),rt=await ue.json(),qe=await De.json(),Pt=Pe??{},ys=it.ok?await it.json():{},Xt=qe.ttlConfig?.bootstrapTtlMs??(Pt.tunnelBootstrapTtlMs===void 0?1800*1e3:Pt.tunnelBootstrapTtlMs),Os=typeof qe.ttlConfig?.sessionTtlMs=="number"?qe.ttlConfig.sessionTtlMs:Pt.tunnelSessionTtlMs??480*60*1e3,Gt=Nn(qe.mode??Pt.tunnelMode),is=Pt.tunnelProvider??"cloudflare",Ht=Pt.managedLocalTunnelConfigPath??null,bs=Le(rt,is),gs=vf(qe?.managedRemoteTunnelPresets),hs=typeof qe.managedRemoteTunnelHostname=="string"?qe.managedRemoteTunnelHostname:"",ds=gs.length>0?gs:hs?[{id:`legacy-${ji(hs)}`,name:hs,hostname:ji(hs)}]:[],Es=ds[0]?.id||"";if(le(Xt),Ae(Os),j(is),T(Array.isArray(ys?.providers)?ys.providers:[]),M(Gt),$(Ht),W(ds),ee(Es),_e(Array.isArray(qe.activeSessions)?qe.activeSessions:[]),c(qe.activeTunnelMode?Nn(qe.activeTunnelMode):qe.active&&qe.mode?Nn(qe.mode):null),H(new Set(Array.isArray(qe.managedRemoteTunnelTokenPresetIds)?qe.managedRemoteTunnelTokenPresetIds:[])),Ve(typeof qe.localPort=="number"?qe.localPort:null),qe.active&&qe.url){l({url:qe.url,connectUrl:null,bootstrapExpiresAt:typeof qe.bootstrapExpiresAt=="number"?qe.bootstrapExpiresAt:null}),r("active");return}r(bs?"idle":"not-available")}catch{Q.aborted||(r("error"),d(t("settings.aiworker.tunnel.toast.checkAvailabilityFailed")))}},[Le,t]);o.useEffect(()=>{const Q=new AbortController;return q(Q.signal),()=>Q.abort()},[q]),o.useEffect(()=>{if(!i?.connectUrl){p(null);return}let Q=!1;return zl.toDataURL(i.connectUrl,{width:256,margin:2,color:{dark:"#000000",light:"#ffffff"}}).then(ue=>{Q||p(ue)}).catch(()=>{Q||p(null)}),()=>{Q=!0}},[i?.connectUrl]),o.useEffect(()=>{if(!i?.bootstrapExpiresAt){Ce(t("settings.aiworker.tunnel.state.noExpiry"));return}let Q=null,ue=Date.now();const De=()=>{const rt=i.bootstrapExpiresAt?i.bootstrapExpiresAt-Date.now():0;rt<=0?Ce(t("settings.aiworker.tunnel.state.expired")):Ce(cl(rt))},Pe=()=>{const rt=Date.now();rt-ue>=1e3&&(De(),ue=rt),Q=requestAnimationFrame(Pe)};De(),(typeof document>"u"||document.visibilityState==="visible")&&(Q=requestAnimationFrame(Pe));const it=()=>{document.visibilityState==="visible"&&Q===null?Q=requestAnimationFrame(Pe):document.visibilityState!=="visible"&&Q!==null&&(cancelAnimationFrame(Q),Q=null)};return document.addEventListener("visibilitychange",it),()=>{document.removeEventListener("visibilitychange",it),Q!==null&&cancelAnimationFrame(Q)}},[t,i?.bootstrapExpiresAt]),o.useEffect(()=>{let Q=null,ue=Date.now();const De=()=>{const it=Date.now();it-ue>=1e3&&(ke(it),ue=it),Q=requestAnimationFrame(De)};(typeof document>"u"||document.visibilityState==="visible")&&(Q=requestAnimationFrame(De));const Pe=()=>{document.visibilityState==="visible"&&Q===null?Q=requestAnimationFrame(De):document.visibilityState!=="visible"&&Q!==null&&(cancelAnimationFrame(Q),Q=null)};return document.addEventListener("visibilitychange",Pe),()=>{document.removeEventListener("visibilitychange",Pe),Q!==null&&cancelAnimationFrame(Q)}},[]),o.useEffect(()=>{if(n==="starting"||n==="stopping"||n==="checking")return;let Q=!1;const ue=async()=>{try{const Pe=await yt("/api/openchamber/tunnel/status");if(!Pe.ok||Q)return;const it=await Pe.json();if(Q)return;_e(Array.isArray(it.activeSessions)?it.activeSessions:[]),H(new Set(Array.isArray(it.managedRemoteTunnelTokenPresetIds)?it.managedRemoteTunnelTokenPresetIds:[])),Ve(typeof it.localPort=="number"?it.localPort:null)}catch{}},De=window.setInterval(()=>{typeof document<"u"&&document.visibilityState!=="visible"||ue()},5e3);return()=>{Q=!0,window.clearInterval(De)}},[n]);const je=o.useCallback(async Q=>{R(!0);try{await pt(Q),Object.prototype.hasOwnProperty.call(Q,"tunnelMode")&&Q.tunnelMode&&M(Q.tunnelMode),Object.prototype.hasOwnProperty.call(Q,"tunnelProvider")&&typeof Q.tunnelProvider=="string"&&j(Q.tunnelProvider),Object.prototype.hasOwnProperty.call(Q,"managedLocalTunnelConfigPath")&&$(Q.managedLocalTunnelConfigPath??null),Object.prototype.hasOwnProperty.call(Q,"managedRemoteTunnelPresets")&&Q.managedRemoteTunnelPresets&&W(Q.managedRemoteTunnelPresets)}catch{E.error(t("settings.aiworker.tunnel.toast.saveSettingsFailed"))}finally{R(!1)}},[t]),Ie=o.useCallback(async(Q,ue)=>{m(!0);try{await pt({tunnelBootstrapTtlMs:Q,tunnelSessionTtlMs:ue})}catch{E.error(t("settings.aiworker.tunnel.toast.saveTtlFailed"))}finally{m(!1)}},[t]),Je=o.useCallback(async Q=>{const ue=Q.token.trim();if(ue)try{const De={...U,[Q.presetId]:ue};await pt({managedRemoteTunnelPresetTokens:De}),H(Pe=>{const it=new Set(Pe);return it.add(Q.presetId),it})}catch{E.error(t("settings.aiworker.tunnel.toast.saveTokenFailed"))}},[U,t]),ot=o.useCallback(async Q=>{f(null),d(null);const ue=O.find(Pe=>Pe.provider===Q),De=ue?.modes?.some(Pe=>Pe.key===S)?S:Nn(ue?.modes?.[0]?.key);await je({tunnelProvider:Q,tunnelMode:De}),Xe(Q)},[O,Xe,je,S]),st=o.useCallback(async()=>{const Q=await Rl({filters:[{name:"Config",extensions:["yml","yaml","json"]}]});if(Q.success&&typeof Q.path=="string"&&Q.path.trim().length>0){const ue=Q.path.trim();if(!Ra(ue)){E.error(We);return}$(ue),await je({managedLocalTunnelConfigPath:ue});return}ve.current?.click()},[We,je]),mt=o.useCallback(Q=>{const ue=Q.trim();$(ue.length>0?ue:null)},[]),vt=o.useCallback(async()=>{if(V&&!Ra(V)){E.error(We);return}await je({managedLocalTunnelConfigPath:V})},[We,V,je]),G=o.useCallback(async()=>{$(null),await je({managedLocalTunnelConfigPath:null})},[je]),Ge=o.useCallback(async Q=>{const ue=Q.target.files?.[0];if(!ue)return;const De=ue.name.trim();if(De.length!==0){if(!Ra(De)){E.error(We);return}$(De),await je({managedLocalTunnelConfigPath:De}),Q.target.value=""}},[We,je]),nt=o.useCallback(async()=>{if(d(null),f(null),S==="managed-local"&&V&&!Ra(V)){d(We),E.error(We);return}r("starting");try{let Q="",ue="";if(S==="managed-remote"){if(!se){r("idle"),f(t("settings.aiworker.tunnel.toast.selectOrAddManagedRemoteFirst")),E.error(t("settings.aiworker.tunnel.toast.selectOrAddManagedRemoteFirst"));return}Q=se.hostname,ue=(U[se.id]||"").trim(),await je({tunnelMode:"managed-remote",managedRemoteTunnelPresets:k})}const De=await yt("/api/openchamber/tunnel/start",{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify({provider:I,mode:S,...S==="managed-remote"&&se?{managedRemoteTunnelPresetId:se.id,managedRemoteTunnelPresetName:se.name}:{},...S==="managed-remote"&&Q?{managedRemoteTunnelHostname:Q}:{},...S==="managed-remote"&&ue?{managedRemoteTunnelToken:ue}:{},...S==="managed-local"&&V?{configPath:V}:{}})}),Pe=await De.json();if(!De.ok||!Pe.ok){if(S==="managed-remote"&&typeof Pe.error=="string"&&Pe.error.includes("Managed remote tunnel token is required")){r("idle"),f(t("settings.aiworker.tunnel.toast.managedRemoteTokenRequiredBeforeStarting")),E.error(t("settings.aiworker.tunnel.toast.addManagedRemoteTokenBeforeStarting"));return}r("error"),d(Pe.error||t("settings.aiworker.tunnel.toast.startFailed")),E.error(Pe.error||t("settings.aiworker.tunnel.toast.startFailed"));return}const it=typeof Pe.url=="string"?Pe.url:"";if(!it){r("error"),d(t("settings.aiworker.tunnel.toast.startedButNoPublicUrl")),E.error(t("settings.aiworker.tunnel.toast.startedButNoPublicUrl"));return}if(l({url:it,connectUrl:typeof Pe.connectUrl=="string"?Pe.connectUrl:null,bootstrapExpiresAt:typeof Pe.bootstrapExpiresAt=="number"?Pe.bootstrapExpiresAt:null}),c(Pe.activeTunnelMode?Nn(Pe.activeTunnelMode):Pe.mode?Nn(Pe.mode):S),_e(Array.isArray(Pe.activeSessions)?Pe.activeSessions:[]),Array.isArray(Pe.managedRemoteTunnelTokenPresetIds)&&H(new Set(Pe.managedRemoteTunnelTokenPresetIds)),typeof Pe.localPort=="number"&&Ve(Pe.localPort),typeof Pe.mode=="string"&&M(Nn(Pe.mode)),r("active"),Pe.replacedTunnel){const rt=typeof Pe.revokedBootstrapCount=="number"?Pe.revokedBootstrapCount:0,qe=typeof Pe.invalidatedSessionCount=="number"?Pe.invalidatedSessionCount:0;rt===1&&qe===1?E.warning(t("settings.aiworker.tunnel.toast.replacedTunnelSingleSingle")):rt===1?E.warning(t("settings.aiworker.tunnel.toast.replacedTunnelSingleManySessions",{invalidatedSessionCount:qe})):qe===1?E.warning(t("settings.aiworker.tunnel.toast.replacedTunnelManyLinksSingleSession",{revokedBootstrapCount:rt})):E.warning(t("settings.aiworker.tunnel.toast.replacedTunnelManyMany",{revokedBootstrapCount:rt,invalidatedSessionCount:qe}))}else E.success(t("settings.aiworker.tunnel.toast.linkReady"))}catch{r("error"),d(t("settings.aiworker.tunnel.toast.startFailed")),E.error(t("settings.aiworker.tunnel.toast.startFailed"))}},[We,k,je,se,U,t,I,S,V]),lt=o.useCallback(async()=>{r("stopping");try{await yt("/api/openchamber/tunnel/stop",{method:"POST"});const Q=await yt("/api/openchamber/tunnel/status");if(Q.ok){const ue=await Q.json();_e(Array.isArray(ue.activeSessions)?ue.activeSessions:[]),H(new Set(Array.isArray(ue.managedRemoteTunnelTokenPresetIds)?ue.managedRemoteTunnelTokenPresetIds:[])),Ve(typeof ue.localPort=="number"?ue.localPort:null)}l(null),c(null),p(null),r("idle"),E.success(t("settings.aiworker.tunnel.toast.stopped"))}catch{r("error"),d(t("settings.aiworker.tunnel.toast.stopFailed")),E.error(t("settings.aiworker.tunnel.toast.stopFailed"))}},[t]),ht=o.useCallback(async()=>{if(i?.connectUrl)try{await navigator.clipboard.writeText(i.connectUrl),x(!0),E.success(t("settings.aiworker.tunnel.toast.connectLinkCopied")),setTimeout(()=>x(!1),2e3)}catch{E.error(t("settings.aiworker.tunnel.toast.copyUrlFailed"))}},[t,i?.connectUrl]),Lt=o.useCallback(async Q=>{const ue=hi.find(De=>De.value===Q);ue&&(le(ue.ms),await Ie(ue.ms,ge))},[Ie,ge]),et=o.useCallback(async Q=>{const ue=fi.find(De=>De.value===Q);!ue||ue.ms===null||(Ae(ue.ms),await Ie(ae,ue.ms))},[ae,Ie]),ft=o.useCallback(async Q=>{f(null),d(null),n!=="active"&&n!=="stopping"&&n!=="starting"&&r("idle"),await je({tunnelMode:Q,managedRemoteTunnelPresets:k})},[k,je,n]),bt=o.useCallback(async(Q,ue)=>{try{await pt({managedRemoteTunnelPresets:ue})}catch{E.error(t("settings.aiworker.tunnel.toast.saveSelectedManagedRemoteFailed"))}},[t]),Be=o.useCallback(Q=>{const ue=k.find(De=>De.id===Q);ue&&(ee(ue.id),f(null),bt(ue,k))},[k,bt]),Et=o.useCallback(async()=>{const Q=te.trim(),ue=ji(ne),De=de.trim();if(!Q){E.error(t("settings.aiworker.tunnel.toast.tunnelNameRequired"));return}if(!ue){E.error(t("settings.aiworker.tunnel.toast.managedRemoteHostnameRequired"));return}if(!De){E.error(t("settings.aiworker.tunnel.toast.managedRemoteTokenRequired"));return}if(k.some(rt=>rt.hostname===ue)){E.error(t("settings.aiworker.tunnel.toast.hostnameAlreadyExists"));return}const Pe={id:yf(),name:Q,hostname:ue},it=[...k,Pe];W(it),ee(Pe.id),L(rt=>({...rt,[Pe.id]:!0})),re(rt=>({...rt,[Pe.id]:De})),f(null),K(!1),Y(""),me(""),xe(""),await je({tunnelMode:"managed-remote",managedRemoteTunnelPresets:it,managedRemoteTunnelPresetTokens:{...U,[Pe.id]:De}}),await Je({presetId:Pe.id,presetName:Pe.name,hostname:Pe.hostname,token:De}),E.success(t("settings.aiworker.tunnel.toast.managedRemoteSaved"))},[k,ne,te,de,Je,je,U,t]),Me=o.useCallback(async Q=>{const ue=k.find(qe=>qe.id===Q);if(!ue)return;const De=k.filter(qe=>qe.id!==ue.id),Pe=De[0]?.id||"",it=J===ue.id?Pe:J,rt=Object.fromEntries(Object.entries(U).filter(([qe,Pt])=>qe!==ue.id&&Pt.trim().length>0));W(De),ee(it),L(qe=>{const Pt={...qe};return delete Pt[ue.id],Pt}),re(qe=>{const Pt={...qe};return delete Pt[ue.id],Pt}),H(qe=>{const Pt=new Set(qe);return Pt.delete(ue.id),Pt}),f(null),await je({managedRemoteTunnelPresets:De,managedRemoteTunnelPresetTokens:rt}),E.success(t("settings.aiworker.tunnel.toast.managedRemoteRemoved"))},[k,je,J,U,t]),wt="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.aiworker.tunnel.state.loading")})}):s.jsx(ze,{title:t("settings.aiworker.tunnel.title"),info:s.jsxs("div",{className:"space-y-1",children:[s.jsx("p",{children:t("settings.aiworker.tunnel.description")}),s.jsx("p",{children:t("settings.aiworker.tunnel.note.serverSideEnforced")}),s.jsx("p",{children:t("settings.aiworker.tunnel.note.connectLinksOneTime")})]}),divider:!1,children:s.jsxs("div",{className:"space-y-6",children:[ye.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(F,{name:"information",className:"size-4 text-[var(--status-info)]"}),s.jsx("p",{className:Wr,children:t("settings.aiworker.tunnel.section.redeemedAccessLinks")})]}),s.jsx("div",{className:"space-y-1",children:ye.map(Q=>{const ue=Q.mode==="quick",De=Q.mode==="managed-remote",Pe=ue?"border-[var(--status-warning-border)] bg-[var(--status-warning-background)] text-[var(--status-warning)]":De?"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)]",it=Q.isActive?ue?"text-[var(--status-warning)]":De?"text-[var(--status-info)]":"text-[var(--status-success)]":"text-muted-foreground/50",rt=t(ue?"settings.aiworker.tunnel.badge.quick":De?"settings.aiworker.tunnel.badge.remote":"settings.aiworker.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(F,{name:"checkbox-blank-circle-fill",className:fe("size-2.5 shrink-0",it)}),s.jsx("span",{className:fe("typography-micro rounded border px-1.5 py-0.5 uppercase",Pe),children:rt}),s.jsx("span",{className:"typography-meta text-muted-foreground/80",children:t("settings.aiworker.tunnel.session.redeemedAt",{time:xf(Q.createdAt,e)})}),s.jsx("span",{className:"typography-meta text-foreground",children:Q.isActive?t("settings.aiworker.tunnel.session.expiresIn",{remaining:Q.remainingTextForSession}):Q.inactiveLabel===t("settings.aiworker.tunnel.state.inactive")?t("settings.aiworker.tunnel.state.inactive"):t("settings.aiworker.tunnel.session.inactiveWithReason",{reason:Q.inactiveLabel})})]},Q.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(F,{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:Wr,children:t("settings.aiworker.tunnel.notAvailable.dependencyNotFound",{dependency:pe.dependency})}),s.jsx("p",{className:"typography-meta text-muted-foreground/70",children:t("settings.aiworker.tunnel.notAvailable.installHint")}),s.jsx("code",{className:"typography-code block rounded bg-muted/50 px-2 py-1 text-xs text-foreground",children:pe.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:Tt,children:t("settings.aiworker.tunnel.field.provider")}),s.jsxs(St,{value:I,onValueChange:Q=>{ot(Q)},disabled:A||n==="starting"||n==="stopping",children:[s.jsx(Ct,{size:Ft,className:"max-w-[16rem]",children:s.jsx(Mt,{placeholder:t("settings.aiworker.tunnel.field.providerPlaceholder"),children:ic(I)})}),s.jsxs(It,{children:[O.length>0?O.map(Q=>s.jsx(at,{value:Q.provider,children:s.jsx(ol,{provider:Q.provider})},Q.provider)):s.jsx(at,{value:"cloudflare",children:s.jsx(ol,{provider:"cloudflare"})}),s.jsx(at,{value:"__more-soon",disabled:!0,children:t("settings.aiworker.tunnel.option.moreProvidersSoon")})]})]})]}),s.jsxs("div",{"data-settings-item":"tunnel.type",className:"space-y-1.5",children:[s.jsx("p",{className:Tt,children:t("settings.aiworker.tunnel.field.tunnelType")}),s.jsx("div",{className:"flex flex-wrap items-center gap-1",children:we.map(Q=>s.jsxs(kr,{children:[s.jsx(Nr,{asChild:!0,children:s.jsx(B,{variant:"chip",size:"xs","aria-pressed":S===Q.value,className:"!font-normal",onClick:()=>{ft(Q.value)},disabled:A||n==="starting"||n==="stopping",children:a(Q.labelKey)})}),s.jsx(kl,{sideOffset:8,className:"max-w-xs",children:a(Q.tooltipKey)})]},Q.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:fe(Tt,"shrink-0"),children:t("settings.aiworker.tunnel.field.connectLinkTtl")}),s.jsxs(St,{value:yr(hi,ae,"1800000"),onValueChange:Q=>{Lt(Q)},disabled:N||A||n==="starting"||n==="stopping",children:[s.jsx(Ct,{size:Ft,className:"max-w-[11rem] min-w-0",children:s.jsx(Mt,{className:"truncate",children:ll(hi,ae,"1800000")})}),s.jsx(It,{children:hi.map(Q=>s.jsx(at,{value:Q.value,children:Q.label},Q.value))})]})]}),s.jsxs("div",{className:"flex min-w-0 items-center gap-2",children:[s.jsx("span",{className:fe(Tt,"shrink-0"),children:t("settings.aiworker.tunnel.field.tunnelSessionTtl")}),s.jsxs(St,{value:yr(fi,ge,"28800000"),onValueChange:Q=>{et(Q)},disabled:N||A||n==="starting"||n==="stopping",children:[s.jsx(Ct,{size:Ft,className:"max-w-[11rem] min-w-0",children:s.jsx(Mt,{className:"truncate",children:ll(fi,ge,"28800000")})}),s.jsx(It,{children:fi.map(Q=>s.jsx(at,{value:Q.value,children:Q.label},Q.value))})]})]})]}),S==="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(F,{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.aiworker.tunnel.option.mode.quick.tooltip")}),Ze&&s.jsx("p",{className:"typography-meta mt-1 text-[var(--status-warning)]",children:t("settings.aiworker.tunnel.warning.quickModeReliability")})]})]})}),S==="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 Ke=="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.aiworker.tunnel.note.cloudflareConnectorTarget")," ",s.jsxs("code",{children:["http://localhost:",Ke]})]})}),s.jsxs("div",{className:"mb-1 flex items-center justify-between gap-3",children:[s.jsx(Zs,{children:t("settings.aiworker.tunnel.section.savedManagedRemoteTunnels")}),s.jsxs(B,{variant:"ghost",size:"xs",className:"!font-normal",onClick:()=>K(Q=>!Q),disabled:n==="starting"||n==="stopping"||A,children:[s.jsx(F,{name:"add",className:"h-3.5 w-3.5"}),t("settings.common.actions.create")]})]}),k.length>0?s.jsx("div",{className:"overflow-hidden rounded-md border border-[var(--surface-subtle)]",children:k.map((Q,ue)=>{const De=U[Q.id]||"",Pe=_.has(Q.id),it=D[Q.id]??!1;return s.jsx("div",{className:fe(ue<k.length-1&&"border-b border-[var(--surface-subtle)]"),children:s.jsxs(An,{open:it,onOpenChange:rt=>{L(qe=>({...qe,[Q.id]:rt})),rt&&Be(Q.id)},className:"py-1.5",children:[s.jsxs("div",{className:"flex items-start gap-2 px-3",children:[s.jsxs(Tn,{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"||A,children:[it?s.jsx(F,{name:"arrow-down-s",className:"h-4 w-4 text-muted-foreground"}):s.jsx(F,{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:Q.name})]}),s.jsx(B,{variant:"ghost",size:"xs",className:"h-7 w-7 p-0 text-muted-foreground hover:text-[var(--status-error)]","aria-label":t("settings.aiworker.tunnel.actions.removePresetAria",{name:Q.name}),onClick:()=>{Me(Q.id)},disabled:n==="starting"||n==="stopping"||A,children:s.jsx(F,{name:"delete-bin",className:"h-3.5 w-3.5"})})]}),s.jsx(En,{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.aiworker.tunnel.field.hostnameLabel")," ",s.jsx("code",{children:Q.hostname})]}),s.jsx(He,{type:"password",value:De,onChange:rt=>{const qe=rt.target.value;f(null),re(Pt=>({...Pt,[Q.id]:qe}))},onBlur:rt=>{const qe=rt.currentTarget.value.trim();qe&&Je({presetId:Q.id,presetName:Q.name,hostname:Q.hostname,token:qe})},placeholder:t(Pe?"settings.aiworker.tunnel.field.savedTokenAvailablePlaceholder":"settings.aiworker.tunnel.field.pasteTokenPlaceholder"),className:"h-7",disabled:n==="starting"||n==="stopping"}),s.jsx("div",{className:"flex items-center justify-end",children:s.jsx(B,{variant:"ghost",size:"xs",className:"!font-normal",disabled:n==="starting"||n==="stopping"||De.trim().length===0,onClick:()=>{Je({presetId:Q.id,presetName:Q.name,hostname:Q.hostname,token:De})},children:t("settings.aiworker.tunnel.actions.saveToken")})})]})})]})},Q.id)})}):s.jsx("p",{className:"typography-meta text-muted-foreground/70",children:t("settings.aiworker.tunnel.empty.noManagedRemoteTunnels")}),z&&s.jsxs("div",{className:"space-y-2 rounded-md border border-[var(--surface-subtle)] p-2",children:[s.jsx(He,{value:te,onChange:Q=>Y(Q.target.value),placeholder:t("settings.aiworker.tunnel.field.newPresetNamePlaceholder"),className:"h-7",disabled:A||n==="starting"||n==="stopping"}),s.jsx(He,{value:ne,onChange:Q=>me(Q.target.value),placeholder:t("settings.aiworker.tunnel.field.newPresetHostnamePlaceholder"),className:"h-7",disabled:A||n==="starting"||n==="stopping"}),s.jsx(He,{type:"password",value:de,onChange:Q=>xe(Q.target.value),placeholder:t("settings.aiworker.tunnel.field.newPresetTokenPlaceholder"),className:"h-7",disabled:A||n==="starting"||n==="stopping"}),typeof Ke=="number"&&s.jsxs("p",{className:"typography-meta text-muted-foreground/70",children:[t("settings.aiworker.tunnel.note.cloudflareConnectorTargetUse")," ",s.jsxs("code",{children:["http://localhost:",Ke]}),"."]}),s.jsxs("div",{className:"flex items-center gap-2",children:[s.jsx(B,{variant:"ghost",size:"xs",className:"!font-normal",onClick:()=>{Et()},disabled:A||n==="starting"||n==="stopping",children:t("settings.common.actions.saveChanges")}),s.jsx(B,{variant:"ghost",size:"xs",className:"!font-normal",onClick:()=>{K(!1),Y(""),me(""),xe("")},disabled:A||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.aiworker.tunnel.note.tokensSavedPerTunnel")}),s.jsx(Jt,{children:t("settings.aiworker.tunnel.tooltip.tokensSavedPath")})]}),!se&&C&&s.jsx("p",{className:"typography-meta text-[var(--status-error)]",children:C})]}),S==="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:Tt,children:t("settings.aiworker.tunnel.field.configurationFile")}),s.jsx("input",{ref:ve,type:"file",accept:".yml,.yaml,.json",className:"hidden",onChange:Q=>{Ge(Q)}}),s.jsxs("div",{className:"flex items-center gap-2",children:[s.jsx(He,{value:V||"",onChange:Q=>{mt(Q.target.value)},onBlur:()=>{vt()},placeholder:t("settings.aiworker.tunnel.field.configurationFilePlaceholder"),className:"h-7",disabled:n==="starting"||n==="stopping"||A}),s.jsx(B,{variant:"outline",size:"xs",className:"h-7 w-7 p-0","aria-label":t("settings.aiworker.tunnel.actions.browseConfigFileAria"),onClick:()=>{st()},disabled:n==="starting"||n==="stopping"||A,children:s.jsx(F,{name:"folder",className:"size-3.5"})}),V&&s.jsx(B,{variant:"ghost",size:"xs",className:"h-7 w-7 p-0","aria-label":t("settings.aiworker.tunnel.actions.clearConfigFileAria"),onClick:()=>{G()},disabled:n==="starting"||n==="stopping"||A,children:s.jsx(F,{name:"close",className:"size-3.5"})})]}),s.jsx("p",{className:"typography-meta text-muted-foreground/70",children:t(V?"settings.aiworker.tunnel.note.customConfigUsed":"settings.aiworker.tunnel.note.defaultConfigUsed")}),Z&&s.jsx("p",{className:"typography-meta text-[var(--status-error)]",children:We})]})}),!Re&&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(F,{name:"information",className:"mt-0.5 size-4 shrink-0 text-[var(--status-info)]"}),s.jsxs("div",{className:"space-y-1",children:[S==="managed-remote"&&s.jsxs(s.Fragment,{children:[s.jsx("p",{className:"typography-meta text-[var(--status-info)]",children:t("settings.aiworker.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:()=>{Ne(uf)},children:[t("settings.aiworker.tunnel.actions.openManagedRemoteDocs"),s.jsx(F,{name:"external-link",className:"size-3.5"})]})]}),S==="managed-local"&&s.jsxs(s.Fragment,{children:[s.jsx("p",{className:"typography-meta text-[var(--status-info)]",children:t("settings.aiworker.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:()=>{Ne(pf)},children:[t("settings.aiworker.tunnel.actions.openManagedLocalDocs"),s.jsx(F,{name:"external-link",className:"size-3.5"})]})]}),s.jsx("p",{className:"typography-meta text-[var(--status-info)]",children:t("settings.aiworker.tunnel.note.startModeAndGenerateLink",{mode:a(ir.find(Q=>Q.value===S)?.labelKey??"settings.aiworker.tunnel.option.mode.quick.label")})})]})]})}),S==="managed-remote"&&s.jsxs("div",{className:"space-y-1.5",children:[s.jsx("p",{className:Tt,children:t("settings.aiworker.tunnel.field.managedRemoteTunnelToConnect")}),s.jsxs(St,{value:J||(k[0]?.id??""),onValueChange:Q=>{Be(Q)},disabled:A||n==="starting"||n==="stopping"||k.length<=1,children:[s.jsx(Ct,{size:Ft,children:s.jsx(Mt,{placeholder:t("settings.aiworker.tunnel.field.selectSavedTunnelPlaceholder"),children:se?.name})}),s.jsx(It,{fitContent:!0,children:k.map(Q=>s.jsx(at,{value:Q.id,children:Q.name},Q.id))})]})]}),Fe&&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(F,{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.aiworker.tunnel.warning.replacesActiveTunnel")})]})}),s.jsx(B,{size:"sm",variant:"outline",onClick:nt,disabled:n==="starting"||A||S==="managed-remote"&&!se||S==="managed-local"&&Z,className:fe(wt,n==="starting"&&"opacity-70"),children:n==="starting"?s.jsxs(s.Fragment,{children:[s.jsx(F,{name:"loader-4",className:"size-3.5 animate-spin"})," ",t("settings.aiworker.tunnel.actions.startingTunnel")]}):t("settings.aiworker.tunnel.actions.startTunnel")})]})]}),Re&&i&&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.aiworker.tunnel.state.tunnelReady")})]}),s.jsxs("div",{children:[s.jsx("p",{className:"typography-meta mb-1 text-muted-foreground/70",children:t("settings.aiworker.tunnel.field.publicUrlHint")}),s.jsx("code",{className:"typography-code block truncate rounded bg-muted/50 px-2 py-1 text-xs text-foreground",children:i.url})]}),be&&i.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.aiworker.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:i.connectUrl}),s.jsxs(B,{size:"sm",variant:"ghost",onClick:ht,className:"shrink-0 gap-1.5",children:[P?s.jsx(F,{name:"check",className:"size-3.5 text-[var(--status-success)]"}):s.jsx(F,{name:"file-copy",className:"size-3.5"}),t(P?"settings.aiworker.tunnel.actions.copied":"settings.common.actions.copyAll")]})]}),s.jsxs("p",{className:"typography-meta mt-1 text-muted-foreground/70",children:[t("settings.aiworker.tunnel.field.expires"),": ",i.bootstrapExpiresAt?Se:t("settings.aiworker.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.aiworker.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.aiworker.tunnel.note.scanQrToConnect")})]})]})]}),s.jsx("div",{className:"pt-1",children:s.jsxs("div",{className:"flex flex-wrap items-center gap-2",children:[s.jsxs(B,{size:"sm",variant:"outline",onClick:nt,disabled:n==="stopping"||A||S==="managed-local"&&Z,className:wt,children:[s.jsx(F,{name:"restart",className:"size-3.5"}),t("settings.aiworker.tunnel.actions.newConnectLink")]}),s.jsx(B,{size:"sm",variant:"ghost",onClick:lt,disabled:n==="stopping"||A,className:"gap-2 text-[var(--status-error)]",children:n==="stopping"?s.jsxs(s.Fragment,{children:[s.jsx(F,{name:"loader-4",className:"size-3.5 animate-spin"})," ",t("settings.aiworker.tunnel.actions.stopping")]}):t("settings.aiworker.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(B,{size:"sm",variant:"ghost",onClick:nt,children:t("settings.aiworker.tunnel.actions.retry")})]})]})})},rc=()=>{const{t}=tt(),[e,a]=$e.useState(""),[n,r]=$e.useState(!0),[i,l]=$e.useState(!1),g=ie(d=>d.showOpenCodeUpdateNotifications),c=ie(d=>d.setShowOpenCodeUpdateNotifications);$e.useEffect(()=>{let d=!1;return(async()=>{try{const C=await pn();if(d||!C)return;a(C.opencodeBinary??"")}catch{}finally{d||r(!1)}})(),()=>{d=!0}},[]);const y=$e.useCallback(async()=>{if(!(typeof window>"u")&&as())try{const d=await Rl();d.success&&d.path&&d.path.trim().length>0&&a(d.path.trim())}catch{}},[]),p=$e.useCallback(async()=>{l(!0);try{const d=e.trim(),C=d.length>=2&&(d.startsWith('"')&&d.endsWith('"')||d.startsWith("'")&&d.endsWith("'"))?d.slice(1,-1).trim():d;await pt({opencodeBinary:C}),$n("cli",{id:"opencode-binary"}),E.success(t("settings.view.pendingRestart.saved"))}finally{l(!1)}},[t,e]),b=$e.useCallback(d=>{c(d),pt({showOpenCodeUpdateNotifications:d})},[c]);return s.jsx(ze,{title:t("settings.aiworker.opencodeCli.title"),children:s.jsxs("div",{className:"space-y-0.5",children:[s.jsxs(Rt,{settingsItem:"sessions.opencode-binary",label:t("settings.aiworker.opencodeCli.field.binaryPath"),info:s.jsxs(s.Fragment,{children:[t("settings.aiworker.opencodeCli.tipPrefix")," ",s.jsx("span",{className:"font-mono",children:"OPENCODE_BINARY"})," ",t("settings.aiworker.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:d=>a(d.target.value),placeholder:t("settings.aiworker.opencodeCli.field.binaryPathPlaceholder"),disabled:n||i,className:"h-8 min-w-0 flex-1 font-mono text-xs"}),s.jsx(B,{type:"button",variant:"outline",size:"xs",onClick:y,disabled:n||i||!as(),className:Cs,"aria-label":t("settings.aiworker.opencodeCli.actions.browseAria"),title:t("settings.aiworker.opencodeCli.actions.browse"),children:s.jsx(F,{name:"folder",className:"h-4 w-4"})})]}),s.jsxs(ba,{className:fs,children:[!Ll()&&s.jsx(dt,{settingsItem:"sessions.opencode-update-notifications",checked:g,onChange:b,label:t("settings.aiworker.opencodeCli.field.showUpdateNotifications"),ariaLabel:t("settings.aiworker.opencodeCli.field.showUpdateNotificationsAria")}),s.jsx("div",{className:"flex justify-start py-1.5",children:s.jsx(B,{type:"button",size:"xs",onClick:p,disabled:n||i,className:"shrink-0 !font-normal",children:t(i?"settings.common.actions.saving":"settings.common.actions.saveChanges")})})]})]})})},oc=()=>{const t=ut.c(44),{t:e}=tt(),a=ie(wf),n=ie(jf),r=ie(kf),i=ie(Nf),l=ie(Sf),g=ie(Cf),c=ie(If);let y;t[0]!==n?(y=S=>{n(S),pt({agentControlToolEnabled:S}),$n("cli",{id:"agent-control-tool"})},t[0]=n,t[1]=y):y=t[1];const p=y;let b;t[2]!==i?(b=S=>{i(S),pt({agentWebToolEnabled:S}),$n("cli",{id:"agent-web-tool"})},t[2]=i,t[3]=b):b=t[3];const d=b;let C;t[4]!==c?(C=S=>{c(S),pt({agentMemoryToolEnabled:S}).finally(()=>{S&&rd.getState().refresh()}),$n("cli",{id:"agent-memory-tool"})},t[4]=c,t[5]=C):C=t[5];const f=C;let P;t[6]!==e?(P=e("settings.aiworker.tools.title"),t[6]=e,t[7]=P):P=t[7];let x;t[8]!==e?(x=e("settings.aiworker.tools.field.agentControlTool"),t[8]=e,t[9]=x):x=t[9];let N;t[10]!==e?(N=e("settings.aiworker.tools.field.agentControlToolAria"),t[10]=e,t[11]=N):N=t[11];let m;t[12]!==e?(m=e("settings.aiworker.tools.field.agentControlToolInfo"),t[12]=e,t[13]=m):m=t[13];let A;t[14]!==a||t[15]!==p||t[16]!==x||t[17]!==N||t[18]!==m?(A=s.jsx(dt,{settingsItem:"sessions.agent-control-tool",checked:a,onChange:p,label:x,ariaLabel:N,info:m}),t[14]=a,t[15]=p,t[16]=x,t[17]=N,t[18]=m,t[19]=A):A=t[19];let R;t[20]!==e?(R=e("settings.aiworker.tools.field.agentWebTool"),t[20]=e,t[21]=R):R=t[21];let I;t[22]!==e?(I=e("settings.aiworker.tools.field.agentWebToolAria"),t[22]=e,t[23]=I):I=t[23];let j;t[24]!==e?(j=e("settings.aiworker.tools.field.agentWebToolInfo"),t[24]=e,t[25]=j):j=t[25];let h;t[26]!==r||t[27]!==d||t[28]!==j||t[29]!==R||t[30]!==I?(h=s.jsx(dt,{settingsItem:"sessions.agent-web-tool",checked:r,onChange:d,label:R,ariaLabel:I,info:j}),t[26]=r,t[27]=d,t[28]=j,t[29]=R,t[30]=I,t[31]=h):h=t[31];let w;t[32]!==g||t[33]!==l||t[34]!==f||t[35]!==e?(w=g?s.jsx(dt,{settingsItem:"sessions.agent-memory-tool",checked:l,onChange:f,label:e("settings.aiworker.tools.field.agentMemoryTool"),ariaLabel:e("settings.aiworker.tools.field.agentMemoryToolAria"),info:e("settings.aiworker.tools.field.agentMemoryToolInfo")}):null,t[32]=g,t[33]=l,t[34]=f,t[35]=e,t[36]=w):w=t[36];let O;t[37]!==h||t[38]!==w||t[39]!==A?(O=s.jsxs("div",{className:fs,children:[A,h,w]}),t[37]=h,t[38]=w,t[39]=A,t[40]=O):O=t[40];let T;return t[41]!==O||t[42]!==P?(T=s.jsx(ze,{title:P,children:O}),t[41]=O,t[42]=P,t[43]=T):T=t[43],T};function wf(t){return t.agentControlToolEnabled}function jf(t){return t.setAgentControlToolEnabled}function kf(t){return t.agentWebToolEnabled}function Nf(t){return t.setAgentWebToolEnabled}function Sf(t){return t.agentMemoryToolEnabled}function Cf(t){return t.agentMemoryFeatureAvailable}function If(t){return t.setAgentMemoryToolEnabled}const lc=()=>{const{t}=tt(),e=as()&&Va(),a=e&&typeof window<"u"&&window.__AIWORKER_PLATFORM__==="darwin",[n,r]=$e.useState(!1),[i,l]=$e.useState(!1),[g,c]=$e.useState(!1),[y,p]=$e.useState(""),[b,d]=$e.useState(!1),[C,f]=$e.useState(!1),[P,x]=$e.useState(null),[N,m]=$e.useState(!0),[A,R]=$e.useState(!1),[I,j]=$e.useState(!1),[h,w]=$e.useState(!1),[O,T]=$e.useState(!1),[S,M]=$e.useState(!1),[V,$]=$e.useState(!1),[k,W]=$e.useState(!1),[D,L]=$e.useState(!0),[J,ee]=$e.useState(!0),[U,re]=$e.useState(!1),[_,H]=$e.useState(!1),[z,K]=$e.useState(!1),[te,Y]=$e.useState(null),[ne,me]=$e.useState(null);$e.useEffect(()=>{if(!e){m(!1);return}let ve=!1;return(async()=>{try{const Z=await pn();if(!Z)throw new Error(t("settings.aiworker.desktopNetwork.error.loadFailed"));if(ve)return;const se=Z.desktopLanAccessEnabled===!0;r(se),l(se),c(Z.hasDesktopUiPassword===!0),p(""),d(!1),f(Z.desktopLanAccessActive===!0),x(Z.desktopLanAccessBlockedReason??null);const ye=Z.desktopMacMenuBarEnabled!==!1;L(ye),ee(ye),Y(null)}catch(Z){ve||Y(Z instanceof Error?Z.message:t("settings.aiworker.desktopNetwork.error.loadFailed"))}finally{ve||m(!1)}})(),()=>{ve=!0}},[e,t]),$e.useEffect(()=>{if(!e){j(!1);return}let ve=!1;return(async()=>{const Z=await zd();ve||(j(Z?.supported===!0),w(Z?.enabled===!0))})(),()=>{ve=!0}},[e]),$e.useEffect(()=>{if(!e){M(!1);return}let ve=!1;return(async()=>{const Z=await Ud();ve||(M(Z?.supported===!0),$(Z?.enabled===!0))})(),()=>{ve=!0}},[e]),$e.useEffect(()=>{if(!e){re(!1);return}let ve=!1;return(async()=>{const Z=await _d();ve||(re(Z?.supported===!0),H(Z?.enabled===!0))})(),()=>{ve=!0}},[e]),$e.useEffect(()=>{if(!e||!i){me(null);return}let ve=!1;return(async()=>{const Z=await Dl();ve||me(Z)})(),()=>{ve=!0}},[i,e]);const de=y.trim(),xe=de.length>0||b,ae=i!==n||xe||J!==D,le=$e.useMemo(()=>{if(typeof window>"u")return null;const Z=$a()||window.location.href;let se=0;try{se=Number(new URL(Z).port)}catch{se=Number(window.location.port)}return Number.isFinite(se)&&se>0?se:null},[]),ge=i&&C&&ne&&le?`http://${ne}:${le}`:null,Ae=de.length>0||g&&!b,Se=i&&!Ae,Ce=n&&!C&&P==="missing-password",he=N||A||!ae||Se,_e=$e.useCallback(ve=>{p(ve),ve.trim()&&d(!1)},[]),Ue=$e.useCallback(()=>{p(""),d(!0),l(!1)},[]),ke=$e.useCallback(async()=>{if(!I||O)return;const ve=!h;w(ve),T(!0),Y(null);try{const Z=await $d(ve);if(!Z?.supported)throw new Error(t("settings.aiworker.desktopNetwork.error.launchAtLoginUnsupported"));w(Z.enabled)}catch(Z){w(!ve),Y(Z instanceof Error?Z.message:t("settings.aiworker.desktopNetwork.error.launchAtLoginSaveFailed"))}finally{T(!1)}},[O,h,I,t]),Oe=$e.useCallback(async()=>{if(!S||k)return;const ve=!V;$(ve),W(!0),Y(null);try{const Z=await Vd(ve);if(!Z)throw new Error(t("settings.aiworker.desktopNetwork.error.minimizeToTraySaveFailed"));if(!Z.supported)throw new Error(t("settings.aiworker.desktopNetwork.error.minimizeToTrayUnsupported"));$(Z.enabled)}catch(Z){$(!ve),Y(Z instanceof Error?Z.message:t("settings.aiworker.desktopNetwork.error.minimizeToTraySaveFailed"))}finally{W(!1)}},[k,V,S,t]),Ve=$e.useCallback(async()=>{if(!U||z)return;const ve=!_;H(ve),K(!0),Y(null);try{const Z=await Bd(ve);if(!Z?.supported)throw new Error(t("settings.aiworker.desktopNetwork.error.keepAwakeUnsupported"));H(Z.enabled)}catch(Z){H(!ve),Y(Z instanceof Error?Z.message:t("settings.aiworker.desktopNetwork.error.keepAwakeSaveFailed"))}finally{K(!1)}},[z,_,U,t]),We=$e.useCallback(async()=>{if(ae){R(!0),Y(null);try{if(!(await pt({desktopLanAccessEnabled:i,...de?{desktopUiPassword:de}:b?{desktopUiPassword:""}:{},desktopMacMenuBarEnabled:J})).ok)throw new Error(t("settings.aiworker.desktopNetwork.error.saveFailed"));if(r(i),de?c(!0):b&&c(!1),p(""),d(!1),L(J),!await Hd())throw new Error(t("settings.aiworker.desktopNetwork.error.savedRestartFailed"))}catch(ve){Y(ve instanceof Error?ve.message:t("settings.aiworker.desktopNetwork.error.saveFailed")),R(!1)}}},[J,i,ae,de,b,t]);return e?s.jsx(ze,{title:t("settings.aiworker.desktopNetwork.title"),children:s.jsxs("div",{className:"space-y-3",children:[I||a||S||U?s.jsxs("div",{className:fs,children:[I?s.jsx(dt,{settingsItem:"sessions.desktop-launch-at-login",checked:h,onChange:ve=>{ve!==h&&ke()},disabled:O,label:t("settings.aiworker.desktopNetwork.field.launchAtLogin"),info:t("settings.aiworker.desktopNetwork.field.launchAtLoginDescription"),ariaLabel:t("settings.aiworker.desktopNetwork.field.launchAtLoginAria")}):null,a?s.jsx(dt,{settingsItem:"sessions.desktop-mac-menu-bar",checked:J,onChange:ee,disabled:N||A,label:t("settings.aiworker.desktopNetwork.field.macMenuBar"),info:t("settings.aiworker.desktopNetwork.field.macMenuBarDescription"),ariaLabel:t("settings.aiworker.desktopNetwork.field.macMenuBarAria")}):null,S?s.jsx(dt,{settingsItem:"sessions.desktop-minimize-to-tray",checked:V,onChange:ve=>{ve!==V&&Oe()},disabled:k,label:t("settings.aiworker.desktopNetwork.field.minimizeToTray"),info:t("settings.aiworker.desktopNetwork.field.minimizeToTrayDescription"),ariaLabel:t("settings.aiworker.desktopNetwork.field.minimizeToTrayAria")}):null,U?s.jsx(dt,{settingsItem:"sessions.desktop-keep-awake",checked:_,onChange:ve=>{ve!==_&&Ve()},disabled:z,label:t("settings.aiworker.desktopNetwork.field.keepAwake"),info:t("settings.aiworker.desktopNetwork.field.keepAwakeDescription"),ariaLabel:t("settings.aiworker.desktopNetwork.field.keepAwakeAria")}):null]}):null,s.jsxs(qt,{settingsItem:"sessions.desktop-ui-password",label:s.jsx("label",{htmlFor:"desktop-ui-password",children:t("settings.aiworker.desktopPassword.field.password")}),info:t("settings.aiworker.desktopPassword.field.passwordDescription"),children:[s.jsx(He,{id:"desktop-ui-password",type:"password",className:"h-8 min-w-0 flex-1",value:y,onChange:ve=>_e(ve.target.value),placeholder:t(g&&!b?"settings.aiworker.desktopPassword.field.passwordSetPlaceholder":"settings.aiworker.desktopPassword.field.passwordPlaceholder"),disabled:N||A,required:i&&!Ae,"aria-invalid":Se}),g&&!b?s.jsx(B,{type:"button",variant:"ghost",size:"xs",onClick:Ue,disabled:N||A,className:"shrink-0 !font-normal",children:t("settings.aiworker.desktopPassword.actions.removePassword")}):null]}),s.jsx("div",{className:fs,children:s.jsx(dt,{settingsItem:"sessions.desktop-lan-access",checked:i,onChange:l,disabled:N||A,label:t("settings.aiworker.desktopNetwork.field.allowLanAccess"),info:t("settings.aiworker.desktopNetwork.field.allowLanAccessDescription"),description:s.jsxs(s.Fragment,{children:[s.jsx("span",{className:"block text-[var(--status-warning)]/85",children:t("settings.aiworker.desktopNetwork.field.warning")}),Se||Ce?s.jsx("span",{className:"block text-[var(--status-warning)]/85",children:t("settings.aiworker.desktopNetwork.field.passwordRequiredWarning")}):null]}),ariaLabel:t("settings.aiworker.desktopNetwork.field.allowLanAccessAria")})}),te?s.jsx("div",{className:"typography-micro text-[var(--status-error)]",children:te}):null,ge?s.jsxs("div",{className:"typography-micro text-muted-foreground/80",children:[t(ae&&!n?"settings.aiworker.desktopNetwork.hint.openAfterRestart":"settings.aiworker.desktopNetwork.hint.openNow"),s.jsx("span",{className:"font-mono text-foreground",children:ge})]}):null,s.jsx("div",{className:"flex justify-start py-1.5",children:s.jsx(B,{type:"button",size:"xs",onClick:We,disabled:he,className:"shrink-0 !font-normal",children:t(A?"settings.common.actions.saving":"settings.aiworker.desktopNetwork.actions.saveAndRestart")})})]})}):null},cc=new Set(["shift","control","alt","meta"]),Rr=3,Pf=3e3;function Lr(t,e=!1){const a=new Set;return t.altKey&&a.add("alt"),t.ctrlKey&&a.add("control"),t.metaKey&&a.add("meta"),t.shiftKey&&a.add("shift"),e&&a.add(t.key.toLowerCase()),a.size}function Af(t){return t.action.customizable}function dl(t){if(Lr(t)>Rr)return null;const e=[];return(t.metaKey||t.ctrlKey)&&e.push("mod"),t.shiftKey&&e.push("shift"),t.altKey&&e.push("alt"),e.length>0?Ii(e.join("+")):null}function Tf(t){if(cc.has(t.key.toLowerCase())||Lr(t,!0)>Rr)return null;const e=cd(dd(t));if(!e)return null;const a=[];return(t.metaKey||t.ctrlKey)&&a.push("mod"),t.shiftKey&&a.push("shift"),t.altKey&&a.push("alt"),a.push(e),Ii(a.join("+"))}function Ef(t){const e=t.key.toLowerCase();if(!cc.has(e)||Lr(t,!0)>Rr)return null;const a=[];return(t.metaKey||t.ctrlKey||e==="meta"||e==="control")&&a.push("mod"),(t.shiftKey||e==="shift")&&a.push("shift"),(t.altKey||e==="alt")&&a.push("alt"),a.length>0?Ii(a.join("+")):null}function ul(t){return t.chords.length>0?{...t,livePreview:null,settled:!0}:t}function Df(t,e,a){if(e.repeat||e.isComposing)return t;if(a==="keyup")return{...t,livePreview:dl(e)};if(e.key==="Backspace")return{chords:t.chords.slice(0,-1),livePreview:null,settled:!1};const n=Tf(e);if(n){if(t.settled)return{chords:[n],livePreview:null,settled:!1};const r=t.chords.length<2?[...t.chords,n]:t.chords;return{chords:r,livePreview:null,settled:r.length===2}}return{...t,livePreview:dl(e)}}const Mf=t=>{const e=ut.c(117),{action:a,overrides:n,onSave:r,onOpenChange:i}=t,{t:l}=tt();let g;e[0]!==l?(g=le=>l(le.settingsLabelKey),e[0]=l,e[1]=g):g=e[1];const c=g;let y;e[2]!==c?(y=le=>le.action.customizable?c(le.action):Wn(le.action.defaultBinding),e[2]=c,e[3]=y):y=e[3];const p=y;let b;e[4]===Symbol.for("react.memo_cache_sentinel")?(b={chords:[],livePreview:null,settled:!1},e[4]=b):b=e[4];const[d,C]=o.useState(b),f=o.useRef(null);let P,x;e[5]!==a?(P=()=>{a&&(C({chords:[],livePreview:null,settled:!1}),f.current?.focus())},x=[a],e[5]=a,e[6]=P,e[7]=x):(P=e[6],x=e[7]),o.useEffect(P,x);const N=d.chords.length===1&&!d.settled;let m,A;e[8]!==N?(m=()=>{if(!N)return;const le=window.setTimeout(()=>C(ul),Pf);return()=>window.clearTimeout(le)},A=[N],e[8]=N,e[9]=m,e[10]=A):(m=e[9],A=e[10]),o.useEffect(m,A);let R;e[11]!==d.chords?(R=Ii(d.chords.join(" ")),e[11]=d.chords,e[12]=R):R=e[12];const I=R;let j;e[13]!==a||e[14]!==I||e[15]!==n?(j=a&&I?od(a.id,I,n):[],e[13]=a,e[14]=I,e[15]=n,e[16]=j):j=e[16];const h=j;let w;e[17]!==h?(w=h.find(Rf),e[17]=h,e[18]=w):w=e[18];const O=w;let T,S,M,V,$,k,W,D,L,J,ee,U,re,_,H;if(e[19]!==a||e[20]!==c||e[21]!==I||e[22]!==p||e[23]!==h||e[24]!==i||e[25]!==r||e[26]!==O||e[27]!==d||e[28]!==l){const le=h.filter(Af);$=le.find(Lf);const ge=le.find(Of),Ae=h.find(Ff);let Se;e[44]!==i?(Se=()=>i(!1),e[44]=i,e[45]=Se):Se=e[45],M=Se,V=()=>{d.settled||C(ul),!(!a||!I||O||$)&&(r(a.id,I,ge?.action.id),M())};let Ce;e[46]!==a||e[47]!==d?(Ce=(Re,Fe)=>{Re.preventDefault(),Re.stopPropagation();const Ke=!!(a&&"prefixStyle"in a&&a.prefixStyle);if(Fe==="keyup"&&Ke&&d.chords.length===0){const we=Ef(Re);if(we){C({chords:[we],livePreview:null,settled:!0});return}}const Ee=Df(d,{altKey:Re.altKey,code:Re.nativeEvent.code,ctrlKey:Re.ctrlKey,isComposing:Re.nativeEvent.isComposing,key:Re.key,metaKey:Re.metaKey,repeat:Re.repeat,shiftKey:Re.shiftKey},Fe);C(Ke&&Ee.chords.length>1?d:Ee)},e[46]=a,e[47]=d,e[48]=Ce):Ce=e[48];const he=Ce;S=Kt,_=a!==null,H=Kf,T=zt,k="max-w-md",W=f,D=!1;let _e;e[49]!==a||e[50]!==c||e[51]!==l?(_e=a?l("settings.aiworker.keyboardShortcuts.dialog.title",{action:c(a)}):"",e[49]=a,e[50]=c,e[51]=l,e[52]=_e):_e=e[52];let Ue;e[53]!==_e?(Ue=s.jsx($t,{children:_e}),e[53]=_e,e[54]=Ue):Ue=e[54];let ke;e[55]!==l?(ke=l("settings.aiworker.keyboardShortcuts.dialog.instructions"),e[55]=l,e[56]=ke):ke=e[56];let Oe;e[57]!==ke?(Oe=s.jsx(Vt,{children:ke}),e[57]=ke,e[58]=Oe):Oe=e[58],e[59]!==Ue||e[60]!==Oe?(L=s.jsxs(_t,{children:[Ue,Oe]}),e[59]=Ue,e[60]=Oe,e[61]=L):L=e[61];let Ve,We;e[62]!==he?(Ve=Re=>he(Re,"keydown"),We=Re=>he(Re,"keyup"),e[62]=he,e[63]=Ve,e[64]=We):(Ve=e[63],We=e[64]);let ve;e[65]===Symbol.for("react.memo_cache_sentinel")?(ve=()=>C(zf),e[65]=ve):ve=e[65];let Z;e[66]!==d.chords?(Z=d.chords.map(Uf),e[66]=d.chords,e[67]=Z):Z=e[67];let se;e[68]!==d.livePreview?(se=d.livePreview?s.jsx("kbd",{className:"rounded-md border border-dashed border-border bg-muted px-3 py-2 typography-ui-label font-mono text-muted-foreground",children:Wn(d.livePreview)}):null,e[68]=d.livePreview,e[69]=se):se=e[69];let ye;e[70]!==d.chords.length||e[71]!==d.livePreview||e[72]!==l?(ye=d.chords.length===0&&!d.livePreview?s.jsx("span",{className:"typography-ui-label text-muted-foreground",children:l("settings.aiworker.keyboardShortcuts.dialog.recording")}):null,e[70]=d.chords.length,e[71]=d.livePreview,e[72]=l,e[73]=ye):ye=e[73];let be;e[74]!==Z||e[75]!==se||e[76]!==ye?(be=s.jsxs("div",{className:"flex flex-wrap items-center justify-center gap-2",children:[Z,se,ye]}),e[74]=Z,e[75]=se,e[76]=ye,e[77]=be):be=e[77],e[78]!==Ve||e[79]!==We||e[80]!==be?(J=s.jsx("div",{className:"flex min-h-28 items-center justify-center rounded-lg border border-border bg-[var(--surface-elevated)] px-4 py-5 text-center outline-none focus-visible:ring-2 focus-visible:ring-ring",tabIndex:0,ref:f,onKeyDown:Ve,onKeyUp:We,onBlur:ve,children:be}),e[78]=Ve,e[79]=We,e[80]=be,e[81]=J):J=e[81],ee=d.settled&&O?s.jsx("p",{className:"typography-meta text-[var(--status-error)]",children:l("settings.aiworker.keyboardShortcuts.error.internalConflict")}):d.settled&&$?s.jsx("p",{className:"typography-meta text-[var(--status-error)]",children:l("settings.aiworker.keyboardShortcuts.error.prefixConflict",{action:c($.action)})}):null,U=d.settled&&ge&&!O&&!$?s.jsx("p",{className:"typography-meta text-[var(--status-warning)]",children:l("settings.aiworker.keyboardShortcuts.error.exactConflict",{action:c(ge.action)})}):null,re=d.settled&&Ae&&!O&&!$?s.jsx("p",{className:"typography-meta text-[var(--status-warning)]",children:l("settings.aiworker.keyboardShortcuts.warning.contextualPrefix",{action:p(Ae)})}):null,e[19]=a,e[20]=c,e[21]=I,e[22]=p,e[23]=h,e[24]=i,e[25]=r,e[26]=O,e[27]=d,e[28]=l,e[29]=T,e[30]=S,e[31]=M,e[32]=V,e[33]=$,e[34]=k,e[35]=W,e[36]=D,e[37]=L,e[38]=J,e[39]=ee,e[40]=U,e[41]=re,e[42]=_,e[43]=H}else T=e[29],S=e[30],M=e[31],V=e[32],$=e[33],k=e[34],W=e[35],D=e[36],L=e[37],J=e[38],ee=e[39],U=e[40],re=e[41],_=e[42],H=e[43];let z;e[82]!==I||e[83]!==d.settled||e[84]!==l?(z=d.settled&&I&&ld(I)?s.jsx("p",{className:"typography-meta text-[var(--status-warning)]",children:l("settings.aiworker.keyboardShortcuts.warning.riskyBrowserShortcut")}):null,e[82]=I,e[83]=d.settled,e[84]=l,e[85]=z):z=e[85];let K;e[86]!==l?(K=l("settings.common.actions.cancel"),e[86]=l,e[87]=K):K=e[87];let te;e[88]!==M||e[89]!==K?(te=s.jsx(B,{type:"button",variant:"ghost",size:"sm",onClick:M,children:K}),e[88]=M,e[89]=K,e[90]=te):te=e[90];const Y=!I||d.settled&&(!!O||!!$);let ne;e[91]!==l?(ne=l("settings.aiworker.keyboardShortcuts.actions.confirm"),e[91]=l,e[92]=ne):ne=e[92];let me;e[93]!==V||e[94]!==Y||e[95]!==ne?(me=s.jsx(B,{type:"button",size:"sm",disabled:Y,onClick:V,children:ne}),e[93]=V,e[94]=Y,e[95]=ne,e[96]=me):me=e[96];let de;e[97]!==te||e[98]!==me?(de=s.jsxs(ts,{children:[te,me]}),e[97]=te,e[98]=me,e[99]=de):de=e[99];let xe;e[100]!==T||e[101]!==k||e[102]!==W||e[103]!==D||e[104]!==L||e[105]!==J||e[106]!==ee||e[107]!==U||e[108]!==re||e[109]!==z||e[110]!==de?(xe=s.jsxs(T,{className:k,initialFocus:W,showCloseButton:D,children:[L,J,ee,U,re,z,de]}),e[100]=T,e[101]=k,e[102]=W,e[103]=D,e[104]=L,e[105]=J,e[106]=ee,e[107]=U,e[108]=re,e[109]=z,e[110]=de,e[111]=xe):xe=e[111];let ae;return e[112]!==S||e[113]!==_||e[114]!==H||e[115]!==xe?(ae=s.jsx(S,{open:_,onOpenChange:H,children:xe}),e[112]=S,e[113]=_,e[114]=H,e[115]=xe,e[116]=ae):ae=e[116],ae};function Rf(t){return!t.action.customizable&&t.kind!=="contextual-prefix"}function Lf(t){return t.kind==="prefix"}function Of(t){return t.kind==="exact"}function Ff(t){return t.kind==="contextual-prefix"}function Kf(t,e){t||e.cancel()}function zf(t){return{...t,livePreview:null}}function Uf(t,e){return s.jsx("kbd",{className:"rounded-md border border-border bg-muted px-3 py-2 typography-ui-label font-mono text-foreground",children:Wn(t)},`${t}-${e}`)}const _f=["session","models","panels","navigation","application"],$f=()=>{const t=ut.c(24),{t:e}=tt(),a=ie(Vf),n=ie(Bf),r=ie(Hf),i=ie(Wf),[l,g]=o.useState(null);let c;if(t[0]===Symbol.for("react.memo_cache_sentinel")){const I=ud();c=cs()?I.filter(Gf):I,t[0]=c}else c=t[0];const y=c,p=qf;let b;t[1]!==n||t[2]!==a?(b=(I,j,h)=>{const w={...a,[I]:j};h&&(w[h]=qi),n(I,j),h&&n(h,qi),p(w)},t[1]=n,t[2]=a,t[3]=b):b=t[3];const d=b;let C;t[4]!==r||t[5]!==a?(C=I=>{const j={...a};delete j[I],r(I),p(j)},t[4]=r,t[5]=a,t[6]=C):C=t[6];const f=C;let P;t[7]!==a||t[8]!==e?(P=I=>{const j="prefixStyle"in I&&I.prefixStyle,h=j?pd(I.id,a):Tl(I.id,a),w=Wn(h,e("settings.aiworker.keyboardShortcuts.unassigned"));if(!j||!h||h===qi)return w;const O=I.id==="switch_session_tab"?e("settings.aiworker.keyboardShortcuts.action.switch_session_tab.suffix"):e("settings.aiworker.keyboardShortcuts.action.switch_context_surface.suffix");return`${w}${O}`},t[7]=a,t[8]=e,t[9]=P):P=t[9];const x=P;let N;t[10]!==i||t[11]!==f||t[12]!==x||t[13]!==a||t[14]!==e?(N=_f.map((I,j)=>{const h=y.filter(w=>w.category===I);return h.length===0?null:s.jsx(ze,{settingsItem:j===0?"shortcuts.keyboard-shortcuts":void 0,title:e(`settings.aiworker.keyboardShortcuts.category.${I}`),divider:j!==0,info:j===0?e("settings.aiworker.keyboardShortcuts.tooltip"):void 0,headerAction:j===0?s.jsx(B,{type:"button",variant:"outline",size:"xs",className:"!font-normal",onClick:()=>{i(),p({})},children:e("settings.aiworker.keyboardShortcuts.actions.resetAll")}):void 0,children:s.jsx("div",{className:"space-y-2",children:h.map(w=>s.jsxs(Rt,{label:e(w.settingsLabelKey),children:[s.jsx("kbd",{className:"min-w-32 rounded-md border border-border bg-muted px-2 py-1 text-center typography-meta font-mono text-foreground",children:x(w)}),s.jsx(B,{type:"button",variant:"secondary",size:"xs",className:"!font-normal",onClick:()=>g(w),children:e("settings.aiworker.keyboardShortcuts.actions.edit")}),w.id in a?s.jsx(B,{type:"button",variant:"ghost",size:"xs",className:"!font-normal",onClick:()=>f(w.id),children:e("settings.common.actions.reset")}):null]},w.id))})},I)}),t[10]=i,t[11]=f,t[12]=x,t[13]=a,t[14]=e,t[15]=N):N=t[15];let m;t[16]===Symbol.for("react.memo_cache_sentinel")?(m=I=>{I||g(null)},t[16]=m):m=t[16];let A;t[17]!==l||t[18]!==d||t[19]!==a?(A=s.jsx(Mf,{action:l,overrides:a,onSave:d,onOpenChange:m}),t[17]=l,t[18]=d,t[19]=a,t[20]=A):A=t[20];let R;return t[21]!==N||t[22]!==A?(R=s.jsxs(s.Fragment,{children:[N,A]}),t[21]=N,t[22]=A,t[23]=R):R=t[23],R};function Vf(t){return t.shortcutOverrides}function Bf(t){return t.setShortcutOverride}function Hf(t){return t.clearShortcutOverride}function Wf(t){return t.resetAllShortcutOverrides}function Gf(t){return t.id!=="toggle_prompt_navigator"}function qf(t){pt({shortcutOverrides:t})}const dc=()=>{const t=ut.c(2),[e,a]=o.useState(0);let n,r;return t[0]===Symbol.for("react.memo_cache_sentinel")?(n=()=>Ml(()=>a(ix)),r=[],t[0]=n,t[1]=r):(n=t[0],r=t[1]),o.useEffect(n,r),e},Jf=t=>{const e=ut.c(80),{section:a}=t,{t:n}=tt(),{isMobile:r}=wa();dc();let i;e[0]!==r?(i=r&&Bn(),e[0]=r,e[1]=i):i=e[1];const l=i;let g;e[2]===Symbol.for("react.memo_cache_sentinel")?(g=cs(),e[2]=g):g=e[2];const c=g;let y;e[3]===Symbol.for("react.memo_cache_sentinel")?(y=as()&&Va(),e[3]=y):y=e[3];const p=y;if(!a){let U,re,_,H,z,K,te,Y;e[4]===Symbol.for("react.memo_cache_sentinel")?(_=s.jsx(Pi,{}),H=s.jsx(nc,{}),z=p&&s.jsx(lc,{}),K=!c&&s.jsx(rc,{}),te=!c&&s.jsx(oc,{}),Y=s.jsx(ec,{}),U=s.jsx(sc,{}),re=Bn()&&!as()&&!c&&!Ol()&&s.jsx(tc,{}),e[4]=U,e[5]=re,e[6]=_,e[7]=H,e[8]=z,e[9]=K,e[10]=te,e[11]=Y):(U=e[4],re=e[5],_=e[6],H=e[7],z=e[8],K=e[9],te=e[10],Y=e[11]);let ne;e[12]!==l?(ne=l&&s.jsx(Ul,{}),e[12]=l,e[13]=ne):ne=e[13];let me;return e[14]!==ne?(me=s.jsxs(es,{showSaveStatus:!0,className:"openchamber-page-body space-y-3 sm:space-y-6",children:[_,H,z,K,te,Y,U,re,ne]}),e[14]=ne,e[15]=me):me=e[15],me}let b;e[16]!==a?(b=()=>{switch(a){case"general":return s.jsx(Yf,{});case"visual":return s.jsx(Zf,{});case"chat":return s.jsx(Xf,{});case"sessions":return s.jsx(ex,{});case"shortcuts":return s.jsx(Qf,{});case"git":return s.jsx(tx,{});case"notifications":return s.jsx(sx,{});case"voice":return s.jsx(nx,{});case"tunnel":return s.jsx(ax,{});default:return null}},e[16]=a,e[17]=b):b=e[17];const d=b;let C;e[18]!==n?(C=n("settings.page.general.title"),e[18]=n,e[19]=C):C=e[19];let f;e[20]!==n?(f=n("settings.page.appearance.title"),e[20]=n,e[21]=f):f=e[21];let P;e[22]!==n?(P=n("settings.page.chat.title"),e[22]=n,e[23]=P):P=e[23];let x;e[24]!==n?(x=n("settings.page.sessions.title"),e[24]=n,e[25]=x):x=e[25];let N;e[26]!==n?(N=n("settings.page.shortcuts.title"),e[26]=n,e[27]=N):N=e[27];let m;e[28]!==n?(m=n("settings.page.git.title"),e[28]=n,e[29]=m):m=e[29];let A;e[30]!==n?(A=n("settings.page.git.title"),e[30]=n,e[31]=A):A=e[31];let R;e[32]!==n?(R=n("settings.page.notifications.title"),e[32]=n,e[33]=R):R=e[33];let I;e[34]!==n?(I=n("settings.page.voice.title"),e[34]=n,e[35]=I):I=e[35];let j;e[36]!==n?(j=n("settings.page.tunnel.title"),e[36]=n,e[37]=j):j=e[37];let h;e[38]!==m||e[39]!==A||e[40]!==R||e[41]!==I||e[42]!==j||e[43]!==C||e[44]!==f||e[45]!==P||e[46]!==x||e[47]!==N?(h={general:C,visual:f,chat:P,sessions:x,shortcuts:N,git:m,github:A,notifications:R,voice:I,tunnel:j},e[38]=m,e[39]=A,e[40]=R,e[41]=I,e[42]=j,e[43]=C,e[44]=f,e[45]=P,e[46]=x,e[47]=N,e[48]=h):h=e[48];const w=h[a];let O;e[49]!==n?(O=n("settings.page.general.description"),e[49]=n,e[50]=O):O=e[50];let T;e[51]!==n?(T=n("settings.page.appearance.description"),e[51]=n,e[52]=T):T=e[52];let S;e[53]!==n?(S=n("settings.page.chat.description"),e[53]=n,e[54]=S):S=e[54];let M;e[55]!==n?(M=n("settings.page.sessions.description"),e[55]=n,e[56]=M):M=e[56];let V;e[57]!==n?(V=n("settings.page.shortcuts.description"),e[57]=n,e[58]=V):V=e[58];let $;e[59]!==n?($=n("settings.page.notifications.description"),e[59]=n,e[60]=$):$=e[60];let k;e[61]!==n?(k=n("settings.page.voice.description"),e[61]=n,e[62]=k):k=e[62];let W;e[63]!==n?(W=n("settings.page.tunnel.description"),e[63]=n,e[64]=W):W=e[64];let D;e[65]!==O||e[66]!==T||e[67]!==S||e[68]!==M||e[69]!==V||e[70]!==$||e[71]!==k||e[72]!==W?(D={general:O,visual:T,chat:S,sessions:M,shortcuts:V,git:void 0,github:void 0,notifications:$,voice:k,tunnel:W},e[65]=O,e[66]=T,e[67]=S,e[68]=M,e[69]=V,e[70]=$,e[71]=k,e[72]=W,e[73]=D):D=e[73];const L=D[a];let J;e[74]!==d?(J=d(),e[74]=d,e[75]=J):J=e[75];let ee;return e[76]!==L||e[77]!==w||e[78]!==J?(ee=s.jsx(es,{title:w,description:L,showSaveStatus:!0,className:"openchamber-page-body",children:J}),e[76]=L,e[77]=w,e[78]=J,e[79]=ee):ee=e[79],ee},Qf=()=>{const t=ut.c(1);let e;return t[0]===Symbol.for("react.memo_cache_sentinel")?(e=s.jsx($f,{}),t[0]=e):e=t[0],e},Yf=()=>{const t=ut.c(10);let e;t[0]===Symbol.for("react.memo_cache_sentinel")?(e=cs(),t[0]=e):e=t[0];const a=e;dc();let n;t[1]===Symbol.for("react.memo_cache_sentinel")?(n=as()&&Va(),t[1]=n):n=t[1];const r=n;let i;t[2]===Symbol.for("react.memo_cache_sentinel")?(i=Bn()&&!as()&&!a&&!Ol(),t[2]=i):i=t[2];const l=i;let g,c,y,p,b;t[3]===Symbol.for("react.memo_cache_sentinel")?(g=r&&s.jsx(lc,{}),c=l&&s.jsx(tc,{}),y=s.jsx(sc,{}),p=!a&&s.jsx(rc,{}),b=!a&&s.jsx(oc,{}),t[3]=g,t[4]=c,t[5]=y,t[6]=p,t[7]=b):(g=t[3],c=t[4],y=t[5],p=t[6],b=t[7]);let d;t[8]===Symbol.for("react.memo_cache_sentinel")?(d=a?[]:["sessionTabs"],t[8]=d):d=t[8];let C;return t[9]===Symbol.for("react.memo_cache_sentinel")?(C=s.jsxs(s.Fragment,{children:[g,c,y,p,b,s.jsx(Pi,{visibleSettings:["fileEditorKeymap",...d,"autoSaveEnabled",...a?[]:["terminalQuickKeys"],...a?[]:["terminalShell"],...a?[]:["terminalLoginShell"],"messageTransport","reportUsage"]})]}),t[9]=C):C=t[9],C},Zf=()=>{const t=ut.c(2);let e;t[0]===Symbol.for("react.memo_cache_sentinel")?(e=cs(),t[0]=e):e=t[0];const a=e;let n;return t[1]===Symbol.for("react.memo_cache_sentinel")?(n=s.jsx(Pi,{visibleSettings:["theme","windowControlsPosition","pwaInstallName","pwaOrientation","mobileKeyboardMode","timeFormat",...a?[]:["weekStart"],"fontSize","terminalFontSize","editorFontSize","spacing","scrollbars","inputBarOffset"]}),t[1]=n):n=t[1],n},Xf=()=>{const t=ut.c(2);let e;t[0]===Symbol.for("react.memo_cache_sentinel")?(e=cs(),t[0]=e):e=t[0];const a=e;let n;return t[1]===Symbol.for("react.memo_cache_sentinel")?(n=s.jsx(Pi,{visibleSettings:["sessionGoal","sessionAssist","chatRenderMode","activityRenderMode","userMessageRendering","mermaidRendering","reasoning","showToolFileIcons","showTurnChangedFiles","expandedTools","collapsibleUserMessages","stickyUserHeader",...a?[]:["promptNavigatorEnabled"],"wideChatLayout","codeBlockLineWrap","splitAssistantMessageActions","subagentReadOnlyBanner","diffLayout","inputHistoryScope","inputHistoryLimit","dotfiles","fileViewerPreview","followUpBehavior","persistDraft","inputSpellcheck","largeTextPaste","enterToSend"]}),t[1]=n):n=t[1],n},ex=()=>{const t=ut.c(1);let e;return t[0]===Symbol.for("react.memo_cache_sentinel")?(e=s.jsxs(s.Fragment,{children:[s.jsx(nc,{}),s.jsx(ec,{})]}),t[0]=e):e=t[0],e},tx=()=>{const t=ut.c(1);let e;return t[0]===Symbol.for("react.memo_cache_sentinel")?(e=s.jsx(Xl,{}),t[0]=e):e=t[0],e},sx=()=>{const t=ut.c(1);let e;return t[0]===Symbol.for("react.memo_cache_sentinel")?(e=s.jsx(Zh,{}),t[0]=e):e=t[0],e},nx=()=>{const t=ut.c(1);if(cs())return null;let e;return t[0]===Symbol.for("react.memo_cache_sentinel")?(e=s.jsx(cf,{}),t[0]=e):e=t[0],e},ax=()=>{const t=ut.c(1);if(cs())return null;let e;return t[0]===Symbol.for("react.memo_cache_sentinel")?(e=s.jsx(bf,{}),t[0]=e):e=t[0],e};function ix(t){return t+1}const rx=t=>{const e=ut.c(85),{className:a}=t,{t:n}=tt(),r=Vn(El),i=Vn(ox),l=ie(lx),g=ie(cx),[c,y]=$e.useState(!1),[p,b]=$e.useState(!1),d=r>0;let C;e[0]!==n?(C=async()=>{try{const Se=await md({message:n("settings.view.pendingRestart.applying")});if(Se.requiresManualRestart){E.warning(n("settings.view.pendingRestart.manualRestartRequired"));return}Se.ok&&E.success(n("settings.view.pendingRestart.applied"))}catch(Se){const Ce=Se,he=Ce instanceof Error&&Ce.message?Ce.message:n("settings.view.pendingRestart.applyFailed");E.error(he)}},e[0]=n,e[1]=C):C=e[1];const f=C;let P;e[2]!==n?(P=async()=>{try{await Il({message:n("settings.view.pendingRestart.applying"),mode:"projects",scopes:["all"]}),Vn.getState().clear()}catch{}},e[2]=n,e[3]=P):P=e[3];const x=P;let N;e[4]!==p||e[5]!==f||e[6]!==g?(N=()=>{p&&g(!1),y(!1),b(!1),f()},e[4]=p,e[5]=f,e[6]=g,e[7]=N):N=e[7];const m=N;let A;e[8]!==d||e[9]!==f||e[10]!==x||e[11]!==l?(A=()=>{if(!d){x();return}if(l){b(!1),y(!0);return}f()},e[8]=d,e[9]=f,e[10]=x,e[11]=l,e[12]=A):A=e[12];const R=A;let I;e[13]!==d||e[14]!==i||e[15]!==n?(I=n(d?i?"settings.view.pendingRestart.applying":"settings.view.actions.applyAndRestartOpenCode":"settings.view.actions.reloadOpenCode"),e[13]=d,e[14]=i,e[15]=n,e[16]=I):I=e[16];const j=I;let h;e[17]!==d||e[18]!==r||e[19]!==n?(h=d?r===1?n("settings.view.actions.applyAndRestartOpenCodeTooltipSingle"):n("settings.view.actions.applyAndRestartOpenCodeTooltipPlural",{count:r}):n("settings.view.actions.reloadOpenCodeTooltip"),e[17]=d,e[18]=r,e[19]=n,e[20]=h):h=e[20];const w=h,O=d?"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",T=i&&"opacity-80";let S;e[21]!==a||e[22]!==O||e[23]!==T?(S=fe("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",O,T,a),e[21]=a,e[22]=O,e[23]=T,e[24]=S):S=e[24];let M;e[25]!==d||e[26]!==r?(M=d?s.jsx("span",{className:fe("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:r}):s.jsx(F,{name:"restart",className:"h-4 w-4 shrink-0"}),e[25]=d,e[26]=r,e[27]=M):M=e[27];let V;e[28]!==j?(V=s.jsx("span",{className:"truncate",children:j}),e[28]=j,e[29]=V):V=e[29];let $;e[30]!==R||e[31]!==i||e[32]!==M||e[33]!==V||e[34]!==S||e[35]!==w?($=s.jsxs("button",{type:"button",disabled:i,title:w,"aria-label":w,onClick:R,className:S,children:[M,V]}),e[30]=R,e[31]=i,e[32]=M,e[33]=V,e[34]=S,e[35]=w,e[36]=$):$=e[36];let k;e[37]===Symbol.for("react.memo_cache_sentinel")?(k=Se=>{y(Se),Se||b(!1)},e[37]=k):k=e[37];let W;e[38]!==n?(W=n("settings.view.pendingRestart.confirm.title"),e[38]=n,e[39]=W):W=e[39];let D;e[40]!==W?(D=s.jsx($t,{children:W}),e[40]=W,e[41]=D):D=e[41];let L;e[42]!==n?(L=n("settings.view.pendingRestart.confirm.description"),e[42]=n,e[43]=L):L=e[43];let J;e[44]!==L?(J=s.jsx(Vt,{children:L}),e[44]=L,e[45]=J):J=e[45];let ee;e[46]!==D||e[47]!==J?(ee=s.jsxs(_t,{children:[D,J]}),e[46]=D,e[47]=J,e[48]=ee):ee=e[48];let U;e[49]===Symbol.for("react.memo_cache_sentinel")?(U={width:"40%"},e[49]=U):U=e[49];let re;e[50]===Symbol.for("react.memo_cache_sentinel")?(re=()=>y(!1),e[50]=re):re=e[50];let _;e[51]!==n?(_=n("settings.view.pendingRestart.confirm.cancel"),e[51]=n,e[52]=_):_=e[52];let H;e[53]!==_?(H=s.jsx("div",{className:"min-w-0 shrink-0",style:U,children:s.jsx(B,{type:"button",variant:"outline",className:"h-9 w-full normal-case",onClick:re,children:_})}),e[53]=_,e[54]=H):H=e[54];let z;e[55]===Symbol.for("react.memo_cache_sentinel")?(z={width:"40%"},e[55]=z):z=e[55];let K;e[56]!==n?(K=n("settings.view.actions.applyAndRestartOpenCode"),e[56]=n,e[57]=K):K=e[57];let te;e[58]!==m||e[59]!==K?(te=s.jsx("div",{className:"min-w-0 shrink-0",style:z,children:s.jsx(B,{type:"button",variant:"default",className:"h-9 w-full normal-case",onClick:m,children:K})}),e[58]=m,e[59]=K,e[60]=te):te=e[60];let Y;e[61]!==H||e[62]!==te?(Y=s.jsxs("div",{className:"flex w-full items-stretch justify-center gap-3",children:[H,te]}),e[61]=H,e[62]=te,e[63]=Y):Y=e[63];let ne;e[64]===Symbol.for("react.memo_cache_sentinel")?(ne=()=>b(dx),e[64]=ne):ne=e[64];let me;e[65]!==p?(me=p?s.jsx(F,{name:"checkbox",className:"h-4 w-4 text-primary"}):s.jsx(F,{name:"checkbox-blank",className:"h-4 w-4"}),e[65]=p,e[66]=me):me=e[66];let de;e[67]!==n?(de=n("settings.view.pendingRestart.confirm.dontShowAgain"),e[67]=n,e[68]=de):de=e[68];let xe;e[69]!==p||e[70]!==me||e[71]!==de?(xe=s.jsxs("button",{type:"button",onClick:ne,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":p,children:[me,de]}),e[69]=p,e[70]=me,e[71]=de,e[72]=xe):xe=e[72];let ae;e[73]!==Y||e[74]!==xe?(ae=s.jsxs("div",{className:"flex w-full flex-col items-center gap-3",children:[Y,xe]}),e[73]=Y,e[74]=xe,e[75]=ae):ae=e[75];let le;e[76]!==ee||e[77]!==ae?(le=s.jsxs(zt,{showCloseButton:!1,className:"max-w-md gap-5",children:[ee,ae]}),e[76]=ee,e[77]=ae,e[78]=le):le=e[78];let ge;e[79]!==c||e[80]!==le?(ge=s.jsx(Kt,{open:c,onOpenChange:k,children:le}),e[79]=c,e[80]=le,e[81]=ge):ge=e[81];let Ae;return e[82]!==$||e[83]!==ge?(Ae=s.jsxs(s.Fragment,{children:[$,ge]}),e[82]=$,e[83]=ge,e[84]=Ae):Ae=e[84],Ae};function ox(t){return t.isApplying}function lx(t){return t.showOpenCodeRestartConfirm}function cx(t){return t.setShowOpenCodeRestartConfirm}function dx(t){return!t}const ux=[{id:"chat.activity-default",page:"chat",titleKey:"settings.aiworker.visual.section.activityDefault",keywords:["activity","collapsed","expanded","live","tools","history"]},{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.aiworker.visual.field.timeFormat",keywords:["clock","12h","24h"]},{id:"appearance.week-start",page:"appearance",titleKey:"settings.aiworker.visual.field.weekStartsOn",keywords:["calendar","monday","sunday"]},{id:"appearance.light-theme",page:"appearance",titleKey:"settings.aiworker.visual.field.lightTheme",keywords:["theme","color","light mode"],isAvailable:t=>!t.isVSCode},{id:"appearance.dark-theme",page:"appearance",titleKey:"settings.aiworker.visual.field.darkTheme",keywords:["theme","color","dark mode"],isAvailable:t=>!t.isVSCode},{id:"appearance.dock-badge",page:"appearance",titleKey:"settings.aiworker.visual.field.dockBadge",descriptionKey:"settings.aiworker.visual.field.dockBadgeHint",keywords:["dock","badge","unread","unseen","counter","count","notification","macos"],isAvailable:t=>t.isMac},{id:"appearance.scrollbars",page:"appearance",titleKey:"settings.aiworker.visual.field.alwaysShowScrollbars",descriptionKey:"settings.aiworker.visual.field.alwaysShowScrollbarsHint",keywords:["scrollbar","scrollbars","scroll","mouse","wheel","accessibility","always visible"]},{id:"appearance.pwa-install-name",page:"appearance",titleKey:"settings.aiworker.visual.field.installAppName",descriptionKey:"settings.aiworker.visual.field.installAppNameHint",keywords:["pwa","installed app"],isAvailable:t=>t.isWeb&&!t.isDesktop&&!t.isVSCode},{id:"appearance.pwa-orientation",page:"appearance",titleKey:"settings.aiworker.visual.field.installOrientation",descriptionKey:"settings.aiworker.visual.field.installOrientationHint",keywords:["pwa","portrait","landscape"],isAvailable:t=>t.isWeb&&!t.isDesktop&&!t.isVSCode},{id:"appearance.mobile-keyboard-mode",page:"appearance",titleKey:"settings.aiworker.visual.field.mobileKeyboardMode",descriptionKey:"settings.aiworker.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.aiworker.visual.field.interfaceFontSize",keywords:["font","text size","ui scale"],isAvailable:t=>!t.isMobile},{id:"appearance.terminal-font-size",page:"appearance",titleKey:"settings.aiworker.visual.field.terminalFontSize",keywords:["terminal","font","text size"]},{id:"appearance.terminal-shell",page:"general",titleKey:"settings.aiworker.visual.field.terminalShell",descriptionKey:"settings.aiworker.visual.field.terminalShellHint",keywords:["terminal","shell","bash","zsh","fish","pwsh","powershell"],isAvailable:t=>!t.isVSCode},{id:"appearance.editor-font-size",page:"appearance",titleKey:"settings.aiworker.visual.field.editorFontSize",keywords:["editor","font","text size","code"]},{id:"appearance.spacing-density",page:"appearance",titleKey:"settings.aiworker.visual.field.spacingDensity",keywords:["density","compact","comfortable","spacing"]},{id:"appearance.input-bar-offset",page:"appearance",titleKey:"settings.aiworker.visual.field.inputBarOffset",descriptionKey:"settings.aiworker.visual.field.inputBarOffsetTooltip",keywords:["input","home bar","offset"],isAvailable:t=>t.isMobile},{id:"appearance.auto-save-enabled",page:"general",titleKey:"settings.aiworker.visual.field.autoSaveEnabled",descriptionKey:"settings.aiworker.visual.field.autoSaveEnabledInfo",keywords:["editor","autosave","auto-save","files","save"]},{id:"appearance.file-editor-keymap",page:"general",titleKey:"settings.aiworker.visual.field.fileEditorKeymap",keywords:["editor","vim","keymap"]},{id:"appearance.session-tabs",page:"general",titleKey:"settings.aiworker.visual.field.sessionTabsGroup",descriptionKey:"settings.aiworker.visual.field.sessionTabsInfo",keywords:["session","tabs","header","working set"],isAvailable:t=>!t.isMobile&&!t.isVSCode},{id:"appearance.terminal-quick-keys",page:"general",titleKey:"settings.aiworker.visual.field.terminalQuickKeys",descriptionKey:"settings.aiworker.visual.field.terminalQuickKeysTooltip",keywords:["terminal","keyboard","esc","ctrl","arrows"],isAvailable:t=>!t.isMobile&&!t.isVSCode},{id:"appearance.usage-reports",page:"general",titleKey:"settings.aiworker.visual.field.sendAnonymousUsageReports",descriptionKey:"settings.aiworker.visual.field.sendAnonymousUsageReportsHint",keywords:["telemetry","analytics"]},{id:"general.app-links",page:"general",titleKey:"settings.aiworker.appLinks.title",descriptionKey:"settings.aiworker.appLinks.info",keywords:["security","app link","deep link","scheme","protocol","obsidian","notion"]},{id:"chat.render-mode",page:"chat",titleKey:"settings.aiworker.visual.section.chatRenderMode",keywords:["messages","conversation","rendering"]},{id:"chat.message-transport",page:"general",titleKey:"settings.aiworker.visual.section.messageStreamTransport",keywords:["streaming","sse","websocket"]},{id:"chat.session-recap",page:"chat",titleKey:"settings.aiworker.visual.field.sessionRecap",keywords:["recap","assist","small model","summary"]},{id:"chat.session-assistance",page:"chat",titleKey:"settings.aiworker.visual.section.sessionAssistance",keywords:["recap","suggestion","subagent"]},{id:"chat.session-suggestion",page:"chat",titleKey:"settings.aiworker.visual.field.sessionSuggestion",keywords:["suggestion","assist","small model","follow up"]},{id:"chat.session-goal",page:"chat",titleKey:"settings.aiworker.visual.field.sessionGoal",keywords:["goal","objective","auto continue","small model"],isAvailable:t=>!t.isVSCode},{id:"chat.session-goal-budget",page:"chat",titleKey:"settings.aiworker.visual.goal.budgetLabel",keywords:["goal","budget","tokens","limit"],isAvailable:t=>!t.isVSCode},{id:"chat.reasoning-traces",page:"chat",titleKey:"settings.aiworker.visual.field.showReasoningTraces",keywords:["thinking","reasoning"]},{id:"chat.reasoning",page:"chat",titleKey:"settings.aiworker.visual.section.reasoning",keywords:["thinking","traces"]},{id:"chat.streaming",page:"chat",titleKey:"settings.aiworker.visual.section.streaming",keywords:["stream","scroll"]},{id:"chat.streaming-auto-follow",page:"chat",titleKey:"settings.aiworker.visual.field.streamingAutoFollow",descriptionKey:"settings.aiworker.visual.field.streamingAutoFollowInfo",keywords:["autoscroll","auto-scroll","follow","stick to bottom","streaming"]},{id:"chat.sticky-user-header",page:"chat",titleKey:"settings.aiworker.visual.field.stickyUserHeader",keywords:["messages","header"]},{id:"chat.prompt-navigator",page:"chat",titleKey:"settings.aiworker.visual.field.promptNavigatorEnabled",keywords:["prompt","navigator","navigation","timeline","scroll"],isAvailable:t=>!t.isVSCode},{id:"chat.collapsible-user-messages",page:"chat",titleKey:"settings.aiworker.visual.field.collapsibleUserMessages",keywords:["collapse","expand","clamp","long messages","user messages"]},{id:"chat.wide-layout",page:"chat",titleKey:"settings.aiworker.visual.field.wideChatLayout",keywords:["layout","wide","messages"]},{id:"chat.message-appearance",page:"chat",titleKey:"settings.aiworker.visual.section.messageAppearance",keywords:["layout","messages","appearance"]},{id:"chat.code-block-line-wrap",page:"chat",titleKey:"settings.aiworker.visual.field.codeBlockLineWrap",keywords:["code","wrap","line wrap","markdown"]},{id:"chat.inline-assistant-actions",page:"chat",titleKey:"settings.aiworker.visual.field.showSplitAssistantMessageActions",descriptionKey:"settings.aiworker.visual.field.showSplitAssistantMessageActionsTooltip",keywords:["copy","save image","read aloud"]},{id:"chat.draft-starters-visible",page:"chat",titleKey:"settings.aiworker.visual.field.draftStartersVisible",keywords:["starter","starters","new session","welcome","suggestions"]},{id:"chat.subagent-read-only-banner",page:"chat",titleKey:"settings.aiworker.visual.field.allowPromptingSubagentSessions",keywords:["subagent","read only","prompt","banner"]},{id:"chat.tool-file-icons",page:"chat",titleKey:"settings.aiworker.visual.field.showToolFileIcons",keywords:["tools","files","icons"]},{id:"chat.tools-and-files",page:"chat",titleKey:"settings.aiworker.visual.section.toolsAndFiles",keywords:["tools","files","dotfiles"]},{id:"chat.changed-files",page:"chat",titleKey:"settings.aiworker.visual.field.showTurnChangedFiles",keywords:["changed files","turns"]},{id:"chat.dotfiles",page:"chat",titleKey:"settings.aiworker.visual.field.showDotfiles",keywords:["hidden files"],isAvailable:t=>!t.isVSCode},{id:"chat.follow-up-behavior",page:"chat",titleKey:"settings.aiworker.visual.section.followUpBehavior",descriptionKey:"settings.aiworker.visual.field.followUpBehaviorDescription",keywords:["follow up","queue","steer","send immediately"]},{id:"chat.input-history-scope",page:"chat",titleKey:"settings.aiworker.visual.field.inputHistoryScope",descriptionKey:"settings.aiworker.visual.field.inputHistoryScopeDescription",keywords:["input history","composer history","global","session","reuse"]},{id:"chat.input-history-limit",page:"chat",titleKey:"settings.aiworker.visual.field.inputHistoryLimit",descriptionKey:"settings.aiworker.visual.field.inputHistoryLimitDescription",keywords:["history limit","prompt recall","remember prompts","composer history","submitted prompts","trim history"]},{id:"chat.persist-drafts",page:"chat",titleKey:"settings.aiworker.visual.field.persistDraftMessages",keywords:["draft","message"]},{id:"chat.composer",page:"chat",titleKey:"settings.aiworker.visual.section.composer",keywords:["input","draft","spellcheck","paste"]},{id:"chat.spellcheck",page:"chat",titleKey:"settings.aiworker.visual.field.enableSpellcheckInTextInputs",keywords:["spelling","input"],isAvailable:t=>!t.isMobile},{id:"chat.large-text-paste",page:"chat",titleKey:"settings.aiworker.visual.field.largeTextPaste",descriptionKey:"settings.aiworker.visual.field.largeTextPasteHint",keywords:["paste","clipboard","attachment","large","text","file"]},{id:"chat.enter-to-send",page:"chat",titleKey:"settings.aiworker.visual.field.enterToSend",descriptionKey:"settings.aiworker.visual.field.enterToSendHint",keywords:["enter","shift enter","ctrl enter","cmd enter","mod enter","send","newline"]},{id:"sessions.default-model",page:"sessions",titleKey:"settings.aiworker.defaults.field.defaultModel",keywords:["model","provider","new sessions"]},{id:"sessions.default-thinking",page:"sessions",titleKey:"settings.aiworker.defaults.field.defaultThinking",keywords:["thinking","reasoning","variant"]},{id:"sessions.default-agent",page:"sessions",titleKey:"settings.aiworker.defaults.field.defaultAgent",keywords:["agent","new sessions"]},{id:"sessions.deletion-dialog",page:"sessions",titleKey:"settings.aiworker.defaults.field.showDeletionDialog",keywords:["delete","confirmation"]},{id:"sessions.small-model",page:"sessions",titleKey:"settings.aiworker.defaults.smallModel.title",descriptionKey:"settings.aiworker.defaults.smallModel.description",keywords:["small model","utility","summary","recap","cheap","override"]},{id:"sessions.walkthrough-model",page:"sessions",titleKey:"settings.aiworker.defaults.walkthroughModel.title",descriptionKey:"settings.aiworker.defaults.walkthroughModel.description",keywords:["walkthrough","diff","review","changes","structured output","model","override"]},{id:"sessions.auto-cleanup",page:"sessions",titleKey:"settings.aiworker.sessionRetention.field.enableAutoCleanup",descriptionKey:"settings.aiworker.sessionRetention.tooltip",keywords:["retention","archive","delete"]},{id:"sessions.retention-period",page:"sessions",titleKey:"settings.aiworker.sessionRetention.field.retentionPeriod",keywords:["days","cleanup","retention"]},{id:"sessions.retention-action",page:"sessions",titleKey:"settings.aiworker.sessionRetention.field.whenSessionsExpire",keywords:["archive","delete","expire"]},{id:"sessions.desktop-launch-at-login",page:"general",titleKey:"settings.aiworker.desktopNetwork.field.launchAtLogin",descriptionKey:"settings.aiworker.desktopNetwork.field.launchAtLoginDescription",keywords:["desktop","startup","login","launch","background","autostart"],isAvailable:t=>t.isDesktopLocalOrigin},{id:"sessions.desktop-window-controls-position",page:"appearance",titleKey:"settings.aiworker.desktopNetwork.field.windowControlsPosition",descriptionKey:"settings.aiworker.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.aiworker.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.aiworker.desktopNetwork.field.macMenuBar",descriptionKey:"settings.aiworker.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.aiworker.desktopNetwork.field.minimizeToTray",descriptionKey:"settings.aiworker.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.aiworker.desktopNetwork.field.keepAwake",descriptionKey:"settings.aiworker.desktopNetwork.field.keepAwakeDescription",keywords:["desktop","sleep","awake","server","mobile","phone"],isAvailable:t=>t.isDesktopLocalOrigin},{id:"sessions.desktop-ui-password",page:"general",titleKey:"settings.aiworker.desktopPassword.field.password",descriptionKey:"settings.aiworker.desktopPassword.field.passwordDescription",keywords:["desktop","password","auth","login"],isAvailable:t=>t.isDesktopLocalOrigin},{id:"sessions.desktop-lan-access",page:"general",titleKey:"settings.aiworker.desktopNetwork.field.allowLanAccess",descriptionKey:"settings.aiworker.desktopNetwork.field.allowLanAccessDescription",keywords:["desktop","lan","network","phone","tablet"],isAvailable:t=>t.isDesktopLocalOrigin},{id:"sessions.opencode-binary",page:"general",titleKey:"settings.aiworker.opencodeCli.field.binaryPath",keywords:["opencode","cli","binary","path"],isAvailable:t=>!t.isVSCode},{id:"sessions.opencode-update-notifications",page:"general",titleKey:"settings.aiworker.opencodeCli.field.showUpdateNotifications",keywords:["opencode","cli","updates"],isAvailable:t=>!t.isVSCode&&!t.isWindowsArm64},{id:"sessions.agent-control-tool",page:"general",titleKey:"settings.aiworker.tools.field.agentControlTool",descriptionKey:"settings.aiworker.tools.field.agentControlToolInfo",keywords:["agent","tool","orchestration","aiworker","sessions","schedule","control"],isAvailable:t=>!t.isVSCode},{id:"sessions.agent-web-tool",page:"general",titleKey:"settings.aiworker.tools.field.agentWebTool",descriptionKey:"settings.aiworker.tools.field.agentWebToolInfo",keywords:["agent","tool","web","browser","page","preview","aiworker"],isAvailable:t=>!t.isVSCode},{id:"sessions.agent-memory-tool",page:"general",titleKey:"settings.aiworker.tools.field.agentMemoryTool",descriptionKey:"settings.aiworker.tools.field.agentMemoryToolInfo",keywords:["agent","tool","memory","remember","recall","preferences","aiworker"],isAvailable:t=>!t.isVSCode&&ie.getState().agentMemoryFeatureAvailable},{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.aiworker.git.changesViewTitle",keywords:["changes","flat list","tree view"]},{id:"git.gitmoji",page:"git",titleKey:"settings.aiworker.git.enableGitmoji",keywords:["commit","emoji"]},{id:"git.gitignored-files",page:"git",titleKey:"settings.aiworker.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.default-model",page:"projects",titleKey:"settings.projects.page.field.projectModel",keywords:["model","default","new chat","project metadata"]},{id:"projects.default-thinking",page:"projects",titleKey:"settings.projects.page.field.projectThinking",keywords:["thinking","variant","reasoning","effort","model","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.aiworker.worktrees.setup.waitForCommands",keywords:["worktree","setup commands","bootstrap","wait"]},{id:"projects.worktree.setup.replace",page:"projects",titleKey:"settings.projects.shared.replaceMode",keywords:["worktree","setup commands","shared","team","only mine"]},{id:"projects.shared",page:"projects",titleKey:"settings.projects.shared.title",descriptionKey:"settings.projects.shared.description",keywords:["shared","team","repository",".aiworker","project.json","trust"]},{id:"projects.shared.plansDir",page:"projects",titleKey:"settings.projects.shared.plansDir",descriptionKey:"settings.projects.shared.plansDirInfo",keywords:["plans","folder","shared","team","docs"]},{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.aiworker.keyboardShortcuts.title",descriptionKey:"settings.aiworker.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.aiworker.tunnel.field.provider",descriptionKey:"settings.aiworker.tunnel.description",keywords:["remote access","cloudflare","ngrok"],isAvailable:t=>!t.isVSCode},{id:"tunnel.type",page:"tunnel",titleKey:"settings.aiworker.tunnel.field.tunnelType",keywords:["quick","managed remote","managed local"],isAvailable:t=>!t.isVSCode},{id:"tunnel.ttl",page:"tunnel",titleKey:"settings.aiworker.tunnel.field.connectLinkTtl",descriptionKey:"settings.aiworker.tunnel.field.tunnelSessionTtl",keywords:["expiry","expiration","session ttl","connect link ttl"],isAvailable:t=>!t.isVSCode},{id:"tunnel.managed-remote",page:"tunnel",titleKey:"settings.aiworker.tunnel.section.savedManagedRemoteTunnels",keywords:["cloudflare","hostname","token","managed remote"],isAvailable:t=>!t.isVSCode},{id:"tunnel.managed-local-config",page:"tunnel",titleKey:"settings.aiworker.tunnel.field.configurationFile",descriptionKey:"settings.aiworker.tunnel.note.managedLocalUsesConfig",keywords:["cloudflared","config","yaml","json","managed local"],isAvailable:t=>!t.isVSCode},{id:"tunnel.start",page:"tunnel",titleKey:"settings.aiworker.tunnel.actions.startTunnel",descriptionKey:"settings.aiworker.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},{id:"integrations.first-party",page:"integrations",titleKey:"settings.integrations.firstParty.title",descriptionKey:"settings.integrations.firstParty.info",keywords:["built-in","first-party","native","github","linear"],isAvailable:t=>!t.isVSCode},{id:"integrations.github",page:"integrations",titleKey:"settings.integrations.github.title",descriptionKey:"settings.integrations.github.description",keywords:["github","account","oauth","gh","cli","prs","pull request","issues","connect"],isAvailable:t=>!t.isVSCode},{id:"integrations.linear",page:"integrations",titleKey:"settings.integrations.linear.title",descriptionKey:"settings.integrations.linear.description",keywords:["linear","issues","oauth","connect","workspace"],isAvailable:t=>!t.isVSCode},{id:"integrations.linear.add-workspace",page:"integrations",titleKey:"settings.integrations.linear.actions.addWorkspace",descriptionKey:"settings.integrations.linear.description",keywords:["linear","workspace","add","connect","oauth"],isAvailable:t=>!t.isVSCode},{id:"integrations.linear.mapping",page:"integrations",titleKey:"settings.integrations.linear.mapping.defaultProject",descriptionKey:"settings.integrations.linear.mapping.defaultProject.info",keywords:["linear","project","team","map","workspace","directory"],isAvailable:t=>!t.isVSCode}];function pl(t){return t.trim().toLocaleLowerCase()}function px({query:t,runtimeCtx:e,visiblePageSlugs:a,t:n,getPageTitle:r}){const i=pl(t);if(!i)return[];const l=a?new Set(a):null,g=i.split(/\s+/).filter(Boolean);return ux.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 p=n(c.titleKey),b=c.descriptionKey?n(c.descriptionKey):null,d=pl([p,b,r(c.page),...c.keywords??[]].filter(Boolean).join(" "));return g.every(C=>d.includes(C))?[{...c,title:p,description:b,pageTitle:r(c.page)}]:[]})}const ml=256,gl=280,uc="__aiworkerSettingsDetail",mx=["general","appearance","chat","notifications","sessions","shortcuts","voice","integrations","usage","about","projects","remote-instances","tunnel","git","providers","agents","behavior","commands","mcp","plugins","magic-prompts","snippets","skills.installed","skills.catalog"],gx=["general","projects","opencode","content"],hx="__add_provider__";function fx(t,e){const a=cs(),n=!t&&Bn();return{isVSCode:a,isWeb:n,isDesktop:t,isMobile:e}}function hl(t,e){return t.isAvailable?t.isAvailable(e):!0}function br(t){return typeof t=="object"&&t!==null&&!Array.isArray(t)}function La(t,e){const a=new Set(e);let n=t,r=1;for(;a.has(n);)n=`${t}-${r}`,r+=1;return n}function or(t){if(!br(t))return null;const e=t[uc];if(!br(e))return null;const a=e.page,n=e.stage;return typeof a!="string"||n!=="page-content"?null:{page:Fl(a),stage:n}}function xx(){return typeof window>"u"||!br(window.history.state)?{}:window.history.state}const Ax=({onClose:t,forceMobile:e,isWindowed:a,visiblePageSlugs:n,initialMobileStage:r="nav",registerBackHandler:i})=>{const{t:l}=tt(),g=wa(),c=e??g.isMobile,y=Vn(El),p=ie(Z=>Z.settingsPage),b=ie(Z=>Z.isSettingsDialogOpen),d=ie(Z=>Z.setSettingsPage),C=ie(Z=>Z.shortcutOverrides.open_settings),f=Fl(p),[P,x]=o.useState(r),N=o.useRef(r==="nav"?f:null);o.useEffect(()=>{!c&&f==="home"&&d("general")},[c,d,f]);const[m,A]=o.useState(""),[R,I]=o.useState(null),[j,h]=o.useState(0),w=o.useRef(null),O=o.useRef(!1),T=o.useRef([]),S=o.useRef(0),M=o.useRef(!1),V=o.useMemo(()=>as(),[]),$=o.useMemo(()=>as()&&Va(),[]),k=o.useMemo(()=>as()&&typeof window<"u"&&window.__AIWORKER_PLATFORM__==="darwin",[]),W=o.useMemo(()=>as()&&typeof window<"u"&&window.__AIWORKER_PLATFORM__==="win32",[]),D=o.useMemo(()=>as()&&typeof window<"u"&&window.__AIWORKER_PLATFORM__==="linux",[]),L=o.useMemo(()=>Ll(),[]),J=o.useMemo(()=>fx(V,c),[V,c]),ee=o.useMemo(()=>{const Z=n?new Set(n):null;return Jd.filter(se=>se.slug!=="home").filter(se=>!Z||Z.has(se.slug)).filter(se=>hl(se,J)).filter(se=>!(J.isVSCode&&se.slug==="projects")).filter(se=>!(c&&se.slug==="shortcuts"))},[J,c,n]),U=o.useMemo(()=>{const Z=new Map(mx.map((se,ye)=>[se,ye]));return ee.slice().sort((se,ye)=>(Z.get(se.slug)??999)-(Z.get(ye.slug)??999))},[ee]),re=Ws(Z=>Z.activeProjectId),_=_s();o.useEffect(()=>{if(!(!b&&!J.isVSCode&&!a)){if(f==="agents"){Hn.getState().loadAgents(_);return}if(f==="commands"){va.getState().loadCommands(_);return}if(f==="mcp"){ya.getState().loadMcpConfigs({directory:_});return}if(f==="plugins"){ms.getState().loadPlugins();return}(f==="skills.installed"||f==="skills.catalog")&&(Hs.getState().loadSkills(_),hn.getState().loadCatalog()),f==="snippets"&&Si.getState().loadSnippets()}},[re,b,a,J.isVSCode,_,f]);const H=o.useCallback(Z=>{if(d(Z),N.current=Z,!c)return;const se=pa(Z);if(!se||se.slug==="home"){x("nav");return}x(se.kind==="split"?"page-sidebar":"page-content")},[c,d]),z=o.useMemo(()=>pa(f),[f]),K=o.useMemo(()=>({general:"general",appearance:"visual",chat:"chat",shortcuts:"shortcuts",sessions:"sessions",notifications:"notifications",voice:"voice",tunnel:"tunnel"}),[]),te=o.useCallback(Z=>{switch(Z){case"general":return l("settings.page.general.title");case"projects":return l("settings.page.projects.title");case"remote-instances":return l("settings.page.remoteInstances.title");case"providers":return l("settings.page.providers.title");case"usage":return l("settings.page.usage.title");case"agents":return l("settings.page.agents.title");case"behavior":return l("settings.page.behavior.title");case"commands":return l("settings.page.commands.title");case"mcp":return l("settings.page.mcp.title");case"plugins":return l("settings.page.plugins.title");case"skills.installed":return l("settings.page.skills.title");case"skills.catalog":return l("settings.page.skillsCatalog.title");case"git":return l("settings.page.git.title");case"integrations":return l("settings.page.integrations.title");case"appearance":return l("settings.page.appearance.title");case"chat":return l("settings.page.chat.title");case"shortcuts":return l("settings.page.shortcuts.title");case"sessions":return l("settings.page.sessions.title");case"magic-prompts":return l("settings.page.magicPrompts.title");case"snippets":return l("settings.page.snippets.title");case"notifications":return l("settings.page.notifications.title");case"voice":return l("settings.page.voice.title");case"tunnel":return l("settings.page.tunnel.title");case"about":return l("settings.page.about.title");default:return l("settings.view.home.title")}},[l]),Y=o.useMemo(()=>px({query:m,runtimeCtx:{...J,isDesktopLocalOrigin:$,isMac:k,isWindows:W,isLinux:D,isWindowsArm64:L},visiblePageSlugs:n,t:l,getPageTitle:te}),[te,L,$,k,W,D,J,m,l,n]),ne=o.useCallback(Z=>{if(Z.id.startsWith("agents.")){const se=Hn.getState(),ye=La("new-agent",se.agents.map(be=>be.name));return se.setAgentDraft({name:ye,scope:"user"}),se.setSelectedAgent(ye),Z.id==="agents.create"?"agents.name":Z.id}if(Z.id.startsWith("commands.")){const se=va.getState(),ye=La("new-command",se.commands.map(be=>be.name));return se.setCommandDraft({name:ye,scope:"user"}),se.setSelectedCommand(ye),Z.id==="commands.create"?"commands.name":Z.id}if(Z.id.startsWith("mcp.")){const se=ya.getState(),ye=La("new-mcp-server",se.mcpServers.map(be=>be.name));return se.setMcpDraft({name:ye,scope:"user",type:"local",command:[],url:"",environment:[],headers:[],oauthEnabled:!0,oauthClientId:"",oauthClientSecret:"",oauthScope:"",oauthRedirectUri:"",timeout:"",enabled:!0}),se.setSelectedMcp(ye),Z.id==="mcp.create"?"mcp.server":Z.id}if(Z.id.startsWith("snippets.")){const se=Si.getState(),ye=La("new-snippet",se.snippets.map(be=>be.name));return se.setSnippetDraft({name:ye,scope:"global"}),se.setSelectedSnippet(ye),Z.id==="snippets.create"?"snippets.content":Z.id}if(Z.id.startsWith("skills.")){const se=Hs.getState(),ye=La("new-skill",se.skills.map(be=>be.name));return se.setSkillDraft({name:ye,scope:"user",source:"opencode",description:"",instructions:""}),se.setSelectedSkill(ye),Z.id==="skills.create"?"skills.basic-information":Z.id}return Z.id==="providers.connect"&&Ye.getState().setSelectedProvider(hx),Z.id==="plugins.create"?"plugins.spec":Z.id},[]),me=o.useMemo(()=>{const Z=[],se=new Map;for(const ye of Y){let be=se.get(ye.page);be||(be={page:ye.page,pageTitle:ye.pageTitle,results:[]},se.set(ye.page,be),Z.push(be)),be.results.push(ye)}return Z},[Y]);o.useEffect(()=>{h(0),S.current=0,M.current=!1},[m]),o.useEffect(()=>{S.current=j},[j]),o.useEffect(()=>{T.current[j]?.scrollIntoView({block:"nearest"})},[j]),o.useEffect(()=>{j>=Y.length&&h(Math.max(0,Y.length-1)),T.current.length=Y.length},[j,Y.length]);const de=o.useCallback(Z=>{const se=ne(Z);I(se),H(Z.page),c&&x("page-content"),Z.id==="plugins.create"&&typeof window<"u"&&window.setTimeout(()=>{window.dispatchEvent(new CustomEvent("aiworker:settings-open-plugin-add"))},50)},[c,H,ne]),xe=o.useCallback(Z=>{if(m.trim()){if(Z.key==="Escape"){Z.preventDefault(),A("");return}if(Y.length!==0){if(Z.key==="ArrowDown"){Z.preventDefault(),M.current=!0,h(se=>(se+1)%Y.length);return}if(Z.key==="ArrowUp"){Z.preventDefault(),M.current=!0,h(se=>(se-1+Y.length)%Y.length);return}if(Z.key==="Enter"){Z.preventDefault();const se=(S.current%Y.length+Y.length)%Y.length,ye=Y[se]??Y[0];ye&&de(ye)}}}},[de,m,Y]);o.useEffect(()=>{const Z=R;if(!Z)return;let se=!1;const ye=window.requestAnimationFrame(()=>{if(se)return;const be=typeof CSS<"u"&&CSS.escape?CSS.escape(Z):Z.replace(/[^a-zA-Z0-9_-]/g,"\\$&"),Re=w.current?.querySelector(`[data-settings-item="${be}"]`);Re&&(I(null),Re.scrollIntoView({block:"center",behavior:"smooth"}),Re.setAttribute("data-settings-search-highlight","true"),window.setTimeout(()=>{Re.removeAttribute("data-settings-search-highlight")},1600))});return()=>{se=!0,window.cancelAnimationFrame(ye)}},[R,f]);const ae=o.useCallback(()=>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:Sl,children:l("settings.view.unavailable.title")}),s.jsx("p",{className:"typography-ui text-muted-foreground mt-1",children:l("settings.view.unavailable.description")})]})}),[l]),le=o.useCallback((Z,se)=>{switch(Z){case"projects":return s.jsx(Sm,{onItemSelect:se.onItemSelect});case"agents":return s.jsx(bu,{onItemSelect:se.onItemSelect});case"commands":return s.jsx(Ku,{onItemSelect:se.onItemSelect});case"mcp":return s.jsx(Wu,{onItemSelect:se.onItemSelect});case"plugins":return s.jsx(Mp,{onItemSelect:se.onItemSelect});case"skills.installed":return s.jsx(Gp,{onItemSelect:se.onItemSelect});case"providers":return s.jsx(Xm,{onItemSelect:se.onItemSelect});case"usage":return s.jsx(Og,{onItemSelect:se.onItemSelect});case"magic-prompts":return s.jsx(Xg,{onItemSelect:se.onItemSelect});case"snippets":return s.jsx(nh,{onItemSelect:se.onItemSelect});default:return null}},[]),ge=o.useCallback(Z=>{const se=pa(Z);if(se&&!hl(se,J))return ae();switch(Z){case"projects":return s.jsx(Tm,{});case"remote-instances":return s.jsx(Qm,{});case"agents":return s.jsx(Eu,{});case"behavior":return s.jsx(Fu,{});case"commands":return s.jsx(Hu,{});case"mcp":return s.jsx(gp,{});case"plugins":return s.jsx(Hp,{});case"skills.installed":return s.jsx(No,{view:"installed"});case"skills.catalog":return s.jsx(No,{view:"catalog"});case"providers":return s.jsx(Rg,{});case"usage":return s.jsx(Yg,{});case"about":return s.jsx(es,{title:l("settings.page.about.title"),showSaveStatus:!1,children:s.jsx(Ul,{})});case"magic-prompts":return s.jsx(sh,{});case"snippets":return s.jsx(oh,{});case"git":return s.jsx(ph,{});case"integrations":return s.jsx(Ih,{});case"general":case"appearance":case"chat":case"shortcuts":case"sessions":case"notifications":case"voice":case"tunnel":{const ye=K[Z]??"visual";return s.jsx(Jf,{section:ye})}default:return null}},[K,ae,J,l]);o.useEffect(()=>{if(!c||P!=="nav"||f==="home"||N.current===f)return;const Z=pa(f);!Z||Z.slug==="home"||(N.current=f,x(Z.kind==="split"?"page-sidebar":"page-content"))},[c,P,f]);const Ae=c&&P!=="nav",Se=c&&P==="page-content"&&z?.kind==="split",Ce=l(Se?"settings.view.actions.back":Ae?"settings.view.actions.backToSettings":"settings.view.actions.closeSettings"),he=Tl("open_settings",C===void 0?void 0:{open_settings:C}),_e=he?l("settings.view.actions.closeSettingsWithShortcut",{shortcut:Wn(he)}):l("settings.view.actions.closeSettings"),Ue=o.useCallback(Z=>{if(typeof window>"u"||J.isVSCode)return;const se=or(window.history.state);se?.page===Z&&se.stage==="page-content"||window.history.pushState({...xx(),[uc]:{page:Z,stage:"page-content"}},"",window.location.href)},[J.isVSCode]),ke=o.useCallback(()=>{O.current=!0,x("page-content"),Ue(f)},[Ue,f]);o.useEffect(()=>{if(!c||P!=="page-content"||!O.current)return;O.current=!1;const Z=window.requestAnimationFrame(()=>{w.current?.querySelector("[data-settings-page-heading]")?.focus({preventScroll:!0})});return()=>{window.cancelAnimationFrame(Z)}},[c,P,f]);const Oe=o.useCallback(()=>{if(Se){if((typeof window<"u"?or(window.history.state):null)?.page===f&&!J.isVSCode){window.history.back();return}x("page-sidebar");return}x("nav")},[Se,J.isVSCode,f]);o.useEffect(()=>{if(i)return i(()=>!c||P==="nav"?!1:(Oe(),!0)),()=>i(null)},[Oe,c,P,i]),o.useEffect(()=>{if(!c||J.isVSCode)return;const Z=se=>{if(pa(f)?.kind!=="split")return;if(or(se.state)?.page===f){x("page-content");return}x(be=>be==="page-content"?"page-sidebar":be)};return window.addEventListener("popstate",Z),()=>{window.removeEventListener("popstate",Z)}},[c,J.isVSCode,f]);const Ve=()=>{const Z=m.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(F,{name:"search",className:"h-4 w-4 shrink-0"}),s.jsx("input",{value:m,onChange:se=>A(se.target.value),onKeyDown:xe,placeholder:l("settings.view.search.placeholder"),"aria-label":l("settings.view.search.aria"),className:"typography-ui min-w-0 flex-1 bg-transparent text-foreground outline-none placeholder:text-muted-foreground/70"}),Z&&s.jsx("button",{type:"button",onClick:()=>A(""),"aria-label":l("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(F,{name:"close",className:"h-3.5 w-3.5"})})]})}),s.jsx(vs,{outerClassName:"flex-1 min-h-0",disableHorizontal:!0,children:s.jsx("div",{className:"flex flex-col gap-0.5 px-4 pt-4 pb-2",children:Z?Y.length>0?(()=>{let se=0;return me.map(ye=>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:ye.pageTitle}),ye.results.map(be=>{const Re=se;se+=1;const Fe=Re===j,Ke=!!be.description;return s.jsxs("button",{type:"button",ref:Ee=>{T.current[Re]=Ee},onMouseMove:()=>{M.current=!1,h(Re)},onClick:()=>de(be),className:fe("flex w-full flex-col rounded-md px-2 text-left focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-primary/50",Ke?"min-h-11 py-1.5":"py-2",Fe?"bg-interactive-selection":"hover:bg-interactive-hover"),children:[s.jsx("span",{className:"typography-ui-label text-foreground truncate",children:be.title}),Ke&&s.jsx("span",{className:"typography-micro text-muted-foreground/70 line-clamp-2",children:be.description})]},be.id)})]},ye.page))})():s.jsx("div",{className:"px-2 py-6 text-center typography-ui text-muted-foreground",children:l("settings.view.search.noResults")}):(()=>{const se=new Map;for(const be of U){const Re=be.group,Fe=se.get(Re);Fe?Fe.push(be):se.set(Re,[be])}return gx.map(be=>({group:be,pages:se.get(be)??[]})).filter(be=>be.pages.length>0).map(({group:be,pages:Re},Fe)=>s.jsxs("div",{className:"space-y-0.5",children:[s.jsx("div",{className:fe("px-3 pb-1 typography-micro font-semibold uppercase tracking-wide text-muted-foreground sm:px-2 sm:pb-0.5",Fe===0?"pt-1":"pt-4 sm:pt-3"),children:l(`settings.view.nav.group.${be}`)}),Re.map(Ke=>{const Ee=f===Ke.slug&&!(c&&P==="nav"),we=Qd(Ke.slug);return!we&&Ke.slug!=="mcp"?null:s.jsx(kr,{children:s.jsx(Nr,{asChild:!0,children:s.jsxs("button",{type:"button",onClick:()=>H(Ke.slug),"aria-current":Ee?"page":void 0,className:fe("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",Ee?"bg-interactive-selection text-foreground":"text-foreground hover:bg-interactive-hover"),children:[Ke.slug==="mcp"?s.jsx(gd,{className:"h-[18px] w-[18px] shrink-0 sm:h-4 sm:w-4"}):s.jsx(F,{name:we,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:te(Ke.slug)}),Ke.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:l("settings.view.badge.beta")})]})]})})},Ke.slug)})]},be))})()})}),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:(!J.isVSCode||y>0)&&s.jsx(rx,{})})})]})},We=()=>{if(P==="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(wn,{children:Ve()})})});if(!z)return s.jsx("div",{className:"flex-1 bg-background"});if(P==="page-sidebar"){if(z.kind!=="split"){const se=ge(f);return s.jsx(vs,{outerClassName:"flex-1 min-h-0",className:"bg-background",disableHorizontal:!0,children:s.jsx(wn,{children:se})})}return s.jsx(vs,{outerClassName:"flex-1 min-h-0",className:"bg-background",disableHorizontal:!0,children:s.jsx(wn,{children:le(f,{onItemSelect:ke})})})}const Z=ge(f);return s.jsx(vs,{outerClassName:"flex-1 min-h-0",className:"bg-background",disableHorizontal:!0,children:s.jsx(wn,{children:Z})})},ve=()=>!z||f==="home"?null:z.kind==="split"?s.jsxs("div",{className:"flex h-full min-h-0 overflow-hidden",children:[s.jsx("div",{className:fe("border-r",J.isVSCode?"bg-background":"bg-sidebar"),style:{width:gl,minWidth:gl,borderColor:"var(--interactive-border)"},children:s.jsx(wn,{children:le(f,{})})}),s.jsx(vs,{outerClassName:"flex-1 min-h-0",className:"bg-background",disableHorizontal:!0,children:s.jsx(wn,{children:ge(f)})})]}):s.jsx(vs,{outerClassName:"h-full min-h-0",className:"bg-background",disableHorizontal:!0,children:s.jsx(wn,{children:ge(f)})});return s.jsxs("div",{ref:w,"data-settings-view":"true",className:fe("relative flex h-full min-h-0 flex-col overflow-hidden bg-background"),children:[c?s.jsxs("div",{className:fe("flex h-[var(--oc-header-height,56px)] shrink-0 items-center gap-2 px-3",P!=="nav"&&"border-b","bg-background"),style:P!=="nav"?{borderColor:"var(--interactive-border)"}:void 0,children:[Ae?s.jsx("button",{type:"button",onClick:Oe,"aria-label":Ce,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(F,{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:P==="nav"?l("settings.view.home.title"):z?te(z.slug):l("settings.view.home.title")}),t&&s.jsx("button",{type:"button",onClick:t,"aria-label":l("settings.view.actions.closeSettings"),title:_e,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(F,{name:"close",className:"h-5 w-5"})})]}):s.jsxs(s.Fragment,{children:[Ae&&s.jsx("div",{className:fe("absolute left-3 z-50",a?"top-2":"top-3"),children:s.jsx("button",{type:"button",onClick:Oe,"aria-label":l("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(F,{name:"arrow-left-s",className:"h-5 w-5"})})}),t&&s.jsx("div",{className:fe("absolute right-0.5 z-50",a?"top-0.5":"top-1"),children:s.jsx("button",{type:"button",onClick:t,"aria-label":l("settings.view.actions.closeSettings"),title:_e,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(F,{name:"close",className:"h-5 w-5"})})})]}),s.jsx("div",{className:"flex flex-1 min-h-0 overflow-hidden",children:c?We():s.jsxs(s.Fragment,{children:[s.jsx("div",{className:fe("relative flex h-full min-h-0 flex-col overflow-hidden border-r",V?"bg-sidebar":J.isVSCode?"bg-background":"bg-sidebar"),style:{width:`${ml}px`,minWidth:`${ml}px`,borderColor:"var(--interactive-border)"},children:s.jsx(wn,{children:Ve()})}),s.jsx("div",{className:"flex-1 overflow-hidden bg-background",children:ve()})]})})]})};export{Ul as A,Ax as S};