@vantran-se/openchamber-web 1.22.1 → 1.23.0
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.
- package/README.md +2 -3
- package/bin/cli.js +11 -1
- package/bin/cli.test.js +92 -0
- package/bin/lib/cli-startup.js +49 -0
- package/bin/lib/commands-startup.js +41 -6
- package/dist/assets/{CodeMirrorCommentWidgets-C53Q7pbX.js → CodeMirrorCommentWidgets-DFg2wnpo.js} +1 -1
- package/dist/assets/DiffView-3Dn4QHbu.js +4 -0
- package/dist/assets/DirtyBranchSwitchDialog-CwOerqVi.js +1 -0
- package/dist/assets/FilesView-BdTOpew9.js +17 -0
- package/dist/assets/GitView-Dqf9vHJh.js +6 -0
- package/dist/assets/{JsonTreeView-Bl0lp9Rs.js → JsonTreeView-BKdsjg5B.js} +1 -1
- package/dist/assets/LinearIssuesView-CmbeL7I6.js +1 -0
- package/dist/assets/MarkdownImageGallery-_5gEVr0X.js +1 -0
- package/dist/assets/MarkdownRendererImpl-wVZlx4dd.js +12 -0
- package/dist/assets/OnboardingScreen-DdP4_nuc.js +1 -0
- package/dist/assets/{PatchDiff-D6NXAfJk.js → PatchDiff-am3SAss2.js} +1 -1
- package/dist/assets/PierreDiffViewer-DCsydlKs.js +161 -0
- package/dist/assets/PlanView-BoJxdRZe.js +5 -0
- package/dist/assets/SettingsView-CcM8pF5O.js +28 -0
- package/dist/assets/{SettingsWindow-BiWDBRvb.js → SettingsWindow-DVTdDSol.js} +1 -1
- package/dist/assets/SymbolsNerdFontMono-Regular-aK5vsLov.woff2 +0 -0
- package/dist/assets/{ToolOutputDialog-BQexMQIm.js → ToolOutputDialog-BgfTbDZ4.js} +6 -6
- package/dist/assets/ToolPartDiffPreview-C7WLk5i9.js +8 -0
- package/dist/assets/{VirtualizedFileDiff-Dpz2ra8h.js → VirtualizedFileDiff-DcdgkH-x.js} +1 -1
- package/dist/assets/WalkthroughView-BEVUDxuw.js +4 -0
- package/dist/assets/{computeVirtualFileMetrics-DtyozJdt.js → computeVirtualFileMetrics-C8byMnRh.js} +2 -2
- package/dist/assets/contextPanelEmbeddedChat-CirXEPJq.js +1 -0
- package/dist/assets/de-C8jV7J9y.js +10 -0
- package/dist/assets/es-BI6J1M5R.js +16 -0
- package/dist/assets/fr-D6oDFt7E.js +14 -0
- package/dist/assets/ghostty-vt-DdA0Zryv.wasm +0 -0
- package/dist/assets/{index-DmhujXbT.js → index-BB7ryz8y.js} +1 -1
- package/dist/assets/index-BqhiCmYS.js +39 -0
- package/dist/assets/index-FqSOBz0J.css +1 -0
- package/dist/assets/{isDiffPlainText-XyulMHxx.js → isDiffPlainText-45ujMPGb.js} +1 -1
- package/dist/assets/{isFilePlainText-B19Ddps1.js → isFilePlainText-Cc4KFSYi.js} +1 -1
- package/dist/assets/ja-C_4i5EQu.js +16 -0
- package/dist/assets/ko-BFbOTpbq.js +16 -0
- package/dist/assets/{main-B2a_JfKZ.js → main-C9ETLKFc.js} +2 -2
- package/dist/assets/main-CJmb2dF8.js +930 -0
- package/dist/assets/markdownCore-DVuZpnli.js +5 -0
- package/dist/assets/{miniChat-B3CSU_Ps.js → miniChat-B4Ytoq2n.js} +2 -2
- package/dist/assets/{mobile-QNcFIVCW.js → mobile-BUT6-lo1.js} +2 -2
- package/dist/assets/patchFileDiff-8j1apICU.js +13 -0
- package/dist/assets/pl-COFvT56l.js +16 -0
- package/dist/assets/pt-BR-DtVOO2Lj.js +16 -0
- package/dist/assets/renderElectronMiniChatApp-B6vUG-vF.js +2 -0
- package/dist/assets/renderMobileApp-BNgHraq6.js +25 -0
- package/dist/assets/runtimeEndpointReset-B8LYpWvr.js +17 -0
- package/dist/assets/scheduledTasksApi-GC4epIYA.js +1 -0
- package/dist/assets/{shikiHighlight-DE-OwqGw.js → shikiHighlight-BJISeZsQ.js} +1 -1
- package/dist/assets/surface-BvRzS58U.js +1 -0
- package/dist/assets/tr-B8Q0Go2l.js +7 -0
- package/dist/assets/uk-Dk4a-Fn-.js +16 -0
- package/dist/assets/{useAppFontEffects-COAeIX-D.js → useAppFontEffects-DpFNefUA.js} +153 -179
- package/dist/assets/useGitComparison-Dfxaqd0s.js +1 -0
- package/dist/assets/useInlineCommentController-CscsE4t-.js +2 -0
- package/dist/assets/useRootScrollLock-BaCvuRlT.js +1 -0
- package/dist/assets/{vendor-base-ui-BeMD8X_w.js → vendor-base-ui-DdV8vhHn.js} +1 -1
- package/dist/assets/{vendor-codemirror-language-data-BG3v1Ghq.js → vendor-codemirror-language-data-DzlSIu_W.js} +2 -2
- package/dist/assets/vendor-legendapp-list-BuBPBC3R.js +1 -0
- package/dist/assets/vendor-zod-BPAANqvH.js +39 -0
- package/dist/assets/{web-components-BNMwa0qm.js → web-components-CdGfR2XJ.js} +1 -1
- package/dist/assets/zh-CN-B_BXxG1Q.js +16 -0
- package/dist/assets/zh-TW-DLrl1SPZ.js +16 -0
- package/dist/index.html +5 -43
- package/dist/mini-chat.html +4 -4
- package/dist/mobile.html +4 -4
- package/package.json +8 -5
- package/server/index.d.ts +15 -0
- package/server/index.js +82 -13
- package/server/lib/agent-tool/runtime.js +2 -19
- package/server/lib/changelog/update-notes.js +82 -0
- package/server/lib/changelog/update-notes.test.js +59 -0
- package/server/lib/data-dir-migration.js +40 -0
- package/server/lib/data-dir-migration.test.js +59 -0
- package/server/lib/dev-tunnel/DOCUMENTATION.md +13 -4
- package/server/lib/dev-tunnel/runtime.js +4 -4
- package/server/lib/dev-tunnel/tunnel.test.js +20 -0
- package/server/lib/event-stream/runtime.test.js +12 -12
- package/server/lib/fs/DOCUMENTATION.md +5 -0
- package/server/lib/fs/routes.js +63 -21
- package/server/lib/fs/routes.test.js +187 -1
- package/server/lib/git/DOCUMENTATION.md +32 -6
- package/server/lib/git/routes.js +40 -4
- package/server/lib/git/service.js +291 -215
- package/server/lib/git/service.test.js +593 -25
- package/server/lib/inherited-env.js +16 -9
- package/server/lib/inherited-env.test.js +8 -9
- package/server/lib/mcp-reconnect/DOCUMENTATION.md +55 -0
- package/server/lib/mcp-reconnect/runtime.js +122 -0
- package/server/lib/mcp-reconnect/runtime.test.js +140 -0
- package/server/lib/message-queue/DOCUMENTATION.md +161 -0
- package/server/lib/message-queue/runtime.js +870 -0
- package/server/lib/message-queue/runtime.test.js +482 -0
- package/server/lib/network-defaults.js +23 -0
- package/server/lib/network-defaults.test.js +52 -0
- package/server/lib/openchamber-sessions/routes.js +102 -0
- package/server/lib/openchamber-sessions/routes.test.js +88 -0
- package/server/lib/opencode/DOCUMENTATION.md +30 -6
- package/server/lib/opencode/bootstrap-runtime.js +2 -0
- package/server/lib/opencode/config-paths.test.js +116 -0
- package/server/lib/opencode/core-routes.js +1 -0
- package/server/lib/opencode/feature-routes-runtime.js +7 -0
- package/server/lib/opencode/input-history-scope.js +14 -0
- package/server/lib/opencode/managed-plugin-config.js +35 -0
- package/server/lib/opencode/openchamber-routes.js +64 -4
- package/server/lib/opencode/openchamber-routes.test.js +130 -3
- package/server/lib/opencode/plugins.js +2 -2
- package/server/lib/opencode/providers.js +44 -2
- package/server/lib/opencode/providers.test.js +131 -4
- package/server/lib/opencode/routes.js +9 -7
- package/server/lib/opencode/server-startup-runtime.js +1 -1
- package/server/lib/opencode/settings-files.js +214 -0
- package/server/lib/opencode/settings-helpers.js +113 -41
- package/server/lib/opencode/settings-helpers.test.js +342 -0
- package/server/lib/opencode/settings-registry.json +747 -0
- package/server/lib/opencode/settings-runtime.js +141 -20
- package/server/lib/opencode/settings-runtime.test.js +191 -4
- package/server/lib/opencode/shared.js +4 -1
- package/server/lib/opencode/shutdown-runtime.js +2 -0
- package/server/lib/opencode/skill-routes.js +2 -1
- package/server/lib/opencode/snippets.js +1 -2
- package/server/lib/package-manager.js +4 -29
- package/server/lib/package-manager.test.js +2 -2
- package/server/lib/project-context/DOCUMENTATION.md +25 -1
- package/server/lib/project-context/routes.http.test.js +18 -0
- package/server/lib/project-context/routes.js +15 -0
- package/server/lib/project-context/runtime.js +248 -23
- package/server/lib/project-context/runtime.test.js +106 -3
- package/server/lib/projects/DOCUMENTATION.md +76 -0
- package/server/lib/projects/project-config.js +142 -9
- package/server/lib/projects/project-id.js +17 -0
- package/server/lib/projects/project-setup.js +409 -0
- package/server/lib/projects/project-setup.test.js +557 -0
- package/server/lib/projects/routes.js +59 -0
- package/server/lib/quota/DOCUMENTATION.md +40 -2
- package/server/lib/quota/credentials/providers.js +4 -0
- package/server/lib/quota/credentials/store.js +1 -1
- package/server/lib/quota/credentials/store.test.js +4 -4
- package/server/lib/quota/index.js +1 -0
- package/server/lib/quota/providers/cline-pass.js +125 -0
- package/server/lib/quota/providers/cline-pass.test.js +103 -0
- package/server/lib/quota/providers/exe-dev.js +75 -0
- package/server/lib/quota/providers/exe-dev.test.js +47 -0
- package/server/lib/quota/providers/hyper.js +118 -0
- package/server/lib/quota/providers/hyper.test.js +126 -0
- package/server/lib/quota/providers/index.js +22 -0
- package/server/lib/quota/providers/neuralwatt.js +3 -6
- package/server/lib/quota/providers/neuralwatt.test.js +7 -7
- package/server/lib/quota/providers/ollama-cloud.js +31 -0
- package/server/lib/quota/providers/ollama-cloud.test.js +33 -1
- package/server/lib/quota/providers/opencode-go.js +2 -1
- package/server/lib/quota/providers/opencode-go.test.js +31 -2
- package/server/lib/quota/providers/openrouter.js +119 -24
- package/server/lib/quota/providers/openrouter.test.js +330 -0
- package/server/lib/quota/routes.js +2 -0
- package/server/lib/quota/utils/auth.js +1 -1
- package/server/lib/relay/DOCUMENTATION.md +56 -1
- package/server/lib/relay/cross-compat.test.js +26 -0
- package/server/lib/relay/downstream-scheduler.js +154 -0
- package/server/lib/relay/downstream-scheduler.test.js +162 -0
- package/server/lib/relay/e2ee.js +10 -8
- package/server/lib/relay/flow-control.test.js +177 -0
- package/server/lib/relay/host-client.js +37 -8
- package/server/lib/relay/host-client.test.js +9 -1
- package/server/lib/relay/tunnel-codec.js +9 -0
- package/server/lib/relay/tunnel-host.js +69 -18
- package/server/lib/relay/tunnel-host.test.js +9 -1
- package/server/lib/security/request-security.js +21 -6
- package/server/lib/security/request-security.test.js +42 -8
- package/server/lib/session-assist/runtime.js +7 -10
- package/server/lib/session-goal/DOCUMENTATION.md +20 -7
- package/server/lib/session-goal/create.js +3 -1
- package/server/lib/session-goal/runtime.js +81 -20
- package/server/lib/session-goal/runtime.test.js +426 -0
- package/server/lib/skills-catalog/DOCUMENTATION.md +1 -1
- package/server/lib/skills-catalog/install.js +3 -2
- package/server/lib/small-model/DOCUMENTATION.md +7 -2
- package/server/lib/small-model/call.js +17 -6
- package/server/lib/small-model/call.test.js +52 -0
- package/server/lib/small-model/index.js +7 -11
- package/server/lib/small-model/routes.js +2 -1
- package/server/lib/small-model/runtime-providers.js +15 -7
- package/server/lib/small-model/runtime-providers.test.js +7 -1
- package/server/lib/system-prompt/runtime.js +2 -21
- package/server/lib/terminal/DOCUMENTATION.md +14 -10
- package/server/lib/terminal/runtime.js +190 -31
- package/server/lib/terminal/runtime.test.js +571 -37
- package/server/lib/terminal/shells.js +17 -0
- package/server/lib/terminal/shells.test.js +32 -1
- package/server/lib/ui-auth/ui-auth.js +4 -1
- package/server/lib/ui-auth/ui-auth.test.js +16 -0
- package/server/lib/walkthrough/DOCUMENTATION.md +33 -14
- package/server/lib/walkthrough/index.js +1 -0
- package/server/lib/walkthrough/model-settings.js +8 -12
- package/server/lib/walkthrough/prompt.js +3 -1
- package/server/lib/walkthrough/routes.test.js +26 -5
- package/server/lib/walkthrough/sources.js +23 -2
- package/dist/assets/CommitSection-X-f2RgYr.js +0 -1
- package/dist/assets/DiffView-Dh1ey2x9.js +0 -4
- package/dist/assets/FilesView-3ZYP72ki.js +0 -17
- package/dist/assets/GitView-CMuN7z2Z.js +0 -6
- package/dist/assets/LinearIssuesView-CQiUDU8b.js +0 -1
- package/dist/assets/MarkdownImageGallery-bA0PS-tn.js +0 -1
- package/dist/assets/MarkdownRendererImpl-BGQi2PLq.js +0 -12
- package/dist/assets/OnboardingScreen-D3kYJIb6.js +0 -1
- package/dist/assets/PierreDiffViewer-Ct2A13NO.js +0 -157
- package/dist/assets/PlanView-6AUjzNQn.js +0 -5
- package/dist/assets/SettingsView-CHI8fFaK.js +0 -28
- package/dist/assets/ToolPartDiffPreview-DPAATNn6.js +0 -8
- package/dist/assets/WalkthroughView-AX-u2pFg.js +0 -4
- package/dist/assets/contextPanelEmbeddedChat-C9EcRSDF.js +0 -1
- package/dist/assets/de-DqVn5vme.js +0 -9
- package/dist/assets/es-hj43Z53i.js +0 -15
- package/dist/assets/fr-BmkZt2mF.js +0 -13
- package/dist/assets/index-L_ncV-6H.css +0 -1
- package/dist/assets/index-qES19dlJ.js +0 -7
- package/dist/assets/ja-DioMIEGF.js +0 -15
- package/dist/assets/ko-BqPgaQJb.js +0 -15
- package/dist/assets/main-CYgSu6dx.js +0 -928
- package/dist/assets/markdownCore-CWRCqSH2.js +0 -3
- package/dist/assets/patchFileDiff-BpMQZnYu.js +0 -10
- package/dist/assets/pl-slULBF4R.js +0 -15
- package/dist/assets/pt-BR-BqH8fuCH.js +0 -15
- package/dist/assets/renderElectronMiniChatApp-D77bmLqo.js +0 -2
- package/dist/assets/renderMobileApp-BQ3Kdm-d.js +0 -25
- package/dist/assets/runtimeEndpointReset-CRGn1gVj.js +0 -16
- package/dist/assets/scheduledTasksApi-BSRCtP6T.js +0 -1
- package/dist/assets/tr-CjEbw1Aw.js +0 -6
- package/dist/assets/uk-BkkfxbOs.js +0 -15
- package/dist/assets/useInlineCommentController-JsBboQwt.js +0 -2
- package/dist/assets/useRootScrollLock-C0N9mCwz.js +0 -1
- package/dist/assets/vendor-ghostty-web-CrxinGGH.js +0 -13
- package/dist/assets/vendor-legendapp-list-gg7YLRW7.js +0 -1
- package/dist/assets/vendor-zod-BLfBSgBh.js +0 -39
- package/dist/assets/zh-CN-C6FMdVgv.js +0 -15
- package/dist/assets/zh-TW-CdcMjDxv.js +0 -15
|
@@ -0,0 +1,28 @@
|
|
|
1
|
+
import{R as o,j as s,f as pt,r as $e}from"./vendor-react-BUCujlKS.js";import{f as tt,B,I as F,o as Pn,bb as ja,t as E,O as uc,fS as gc,ey as ze,fT as Tt,b as Gs,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 ua,fX as pn,bR as bs,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 bc,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 Wt,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 vc,cu as dt,g4 as xl,g5 as yc,g6 as $n,g7 as bl,g8 as jc,g9 as ba,fr as Hs,ga as ha,gb as vl,gc as jr,dA as yl,gd as Vn,a6 as va,a5 as Ks,ge as jl,gf as Kr,ab as wc,e9 as wl,g as Ka,gg as kc,gh as Zs,e8 as Nc,gi as Sc,gj as Cc,gk as wr,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 Gc,gA as qc,gB as Wc,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 yn,gH as ya,gI as $r,gJ as la,gK as ca,bI as Gn,gL as Jc,gM as Qc,gN as Yc,gO as Zc,gP as Gi,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 qi,gY as Gr,e6 as rd,gZ as Ii,g_ as od,g$ as ld,h0 as cd,h1 as dd,h2 as pd,h3 as Wi,cv as md,bJ as Tl,h4 as El,h5 as ud,ax as jn,ay as gd}from"./useAppFontEffects-DpFNefUA.js";import{h as vt,u as ie,K as cs,d8 as hd,d9 as qr,A as fn,aB as mn,q as mt,a2 as fd,D as as,Q as Wr,cq as Jr,cx as Qr,V as Ia,p as xd,da as bd,k as vd,cp as pa,db as yd,ak as jd,cu as wd,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-BqhiCmYS.js";import{u as Gd,U as no,J as qn,L as Wn,M as Jn,Q as Qn,e as Ir,F as An,H as Tn,G as En,a5 as _n,W as qd,l as As,a3 as Wd,a6 as ma,a7 as Fl,R as Jd,V as Qd}from"./runtimeEndpointReset-B8LYpWvr.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 ep}from"./vendor-zod-BPAANqvH.js";import{s as tp,p as sp}from"./vendor-yaml-3778uTud.js";import{c as io,s as np,C as ro,P as ap}from"./shikiHighlight-BJISeZsQ.js";import{getResolvedShikiTheme as ip}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 vt("/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 v=typeof c.port=="number"&&Number.isFinite(c.port)&&c.port>0?c.port:null,m=typeof c.tunnelUrl=="string"&&c.tunnelUrl.trim().length>0?c.tunnelUrl.trim():null;a({port:v,tunnelUrl:m})}catch{}})(),()=>{r=!0,i?.abort()}},[]);const n=[];return e?.port!==null&&e?.port!==void 0&&n.push({key:"application",label:t("settings.openchamber.about.field.applicationUrl"),url:`http://localhost:${e.port}/`}),e?.tunnelUrl&&n.push({key:"tunnel",label:t("settings.openchamber.about.field.tunnelUrl"),url:e.tunnelUrl}),n.length===0?null:s.jsx("div",{className:"flex flex-wrap items-center gap-2",children:n.map(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://github.com/openchamber/openchamber",rp="https://discord.gg/ZYRSdnwwKA",po="https://x.com/openchamber_dev",op=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,v]=o.useState(null),m=Gd(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:y}=ja(),d=l||m.info?.currentVersion||"unknown";o.useEffect(()=>{let P=!1;return(async()=>{try{const N=await vt("/api/system/info",{method:"GET",headers:{Accept:"application/json"}});if(!N.ok)return;const u=await N.json().catch(()=>null),A=typeof u?.openchamberVersion=="string"&&u.openchamberVersion.trim().length>0?u.openchamberVersion.trim():null;P||g(A)}catch{P||g(null)}})(),()=>{P=!0}},[]),o.useEffect(()=>{let P=!1;return(async()=>{try{const N=await vt("/api/opencode/upgrade-status",{method:"GET",headers:{Accept:"application/json"}});if(!N.ok)return;const u=await N.json().catch(()=>null),A=typeof u?.currentVersion=="string"&&u.currentVersion.trim().length>0?u.currentVersion.trim():null;P||v(A)}catch{P||v(null)}})(),()=>{P=!0}},[]);const C=o.useRef(!1);o.useEffect(()=>{if(m.checking)i(!0),C.current=!0;else if(r){const P=setTimeout(()=>{i(!1),C.current&&!m.available&&!m.error&&(E.success(e("settings.openchamber.about.toast.latestVersion")),C.current=!1)},op);return()=>clearTimeout(P)}},[e,m.checking,r,m.available,m.error]);const f=m.checking||r;return y?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(uc,{width:72,height:72}),s.jsx("h2",{className:`mt-4 ${gc}`,children:"OpenChamber"}),s.jsxs("div",{className:"mt-2 space-y-1 typography-ui text-muted-foreground",children:[s.jsx("p",{children:e("aboutDialog.openChamberVersionLabel",{version:d})}),s.jsx("p",{children:e("aboutDialog.openCodeVersionLabel",{version:c||e("settings.openchamber.about.state.unknown")})})]}),s.jsx(lo,{})]}),s.jsxs("div",{className:"flex justify-center",children:[!m.available&&!m.error&&s.jsxs(B,{type:"button",variant:"outline",size:"sm",onClick:()=>m.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.openchamber.about.state.checking":"settings.openchamber.about.actions.checkForUpdates")]}),!f&&m.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.openchamber.about.actions.updateToVersion",{version:m.info?.version||""})]})]}),m.error&&s.jsx("p",{className:"rounded-xl border border-[var(--status-error-border)] bg-[var(--status-error-background)] px-3 py-2 typography-meta text-[var(--status-error)]",children:m.error}),s.jsxs("div",{className:"flex flex-col items-center gap-3 text-center",children:[s.jsxs("div",{className:"flex items-center justify-center gap-5",children:[s.jsxs("a",{href: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:rp,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:po,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:"@openchamber_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:m.info,downloading:m.downloading,downloaded:m.downloaded,progress:m.progress,error:m.error,onDownload:m.downloadUpdate,onRestart:m.restartToUpdate,runtimeType:m.runtimeType})]}):s.jsxs(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.openchamber.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.openchamber.about.field.openCodeVersion")}),s.jsx("span",{className:"typography-meta text-muted-foreground font-mono",children:c||e("settings.openchamber.about.state.unknown")})]}),s.jsxs("div",{className:"flex items-center gap-3",children:[m.checking&&s.jsxs("div",{className:"flex items-center gap-2 text-muted-foreground",children:[s.jsx(F,{name:"loader",className:"h-4 w-4 animate-spin"}),s.jsx("span",{className:"typography-meta",children:e("settings.openchamber.about.state.checking")})]}),!m.checking&&m.available&&s.jsxs(B,{size:"sm",variant:"default",onClick:()=>n(!0),children:[s.jsx(F,{name:"download",className:"h-4 w-4 mr-1"}),e("settings.openchamber.about.actions.updateToVersion",{version:m.info?.version||""})]}),!m.checking&&!m.available&&!m.error&&s.jsx("span",{className:"typography-meta text-muted-foreground",children:e("settings.openchamber.about.state.upToDate")}),s.jsx(B,{size:"sm",variant:"outline",onClick:()=>m.checkForUpdates(),disabled:m.checking,children:e("settings.openchamber.about.actions.checkForUpdates")})]})]}),m.error&&s.jsx("div",{className:"px-3 py-2 border-b border-border/40",children:s.jsx("p",{className:"typography-meta text-[var(--status-error)]",children:m.error})}),s.jsxs("div",{className:"flex flex-col gap-2 border-b border-border/40 px-4 py-3 @xl:flex-row @xl:items-center @xl:justify-between",children:[s.jsx("span",{className:Tt,children:e("settings.openchamber.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:po,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:"@openchamber_dev"})]})]})]}),s.jsx(no,{open:a,onOpenChange:n,info:m.info,downloading:m.downloading,downloaded:m.downloaded,progress:m.progress,error:m.error,onDownload:m.downloadUpdate,onRestart:m.restartToUpdate,runtimeType:m.runtimeType})]})},lp=(t,e,a)=>t&&e.some(r=>r.path===t)?t:(e.find(r=>r.id===a)??e[0])?.path??null,_s=()=>{const t=pt.c(4),e=ie(cp),a=Gs(dp),n=Gs(pp);let r;return t[0]!==n||t[1]!==a||t[2]!==e?(r=lp(e,a,n),t[0]=n,t[1]=a,t[2]=e,t[3]=r):r=t[3],r};function cp(t){return t.settingsProjectPath}function dp(t){return t.projects}function pp(t){return t.activeProjectId}const _l=t=>t.trim(),Ba=t=>{const e=pt.c(40),{className:a}=t,{t:n}=tt(),r=Gs(mp),i=_s(),l=ie(up),g=cs();let c;e[0]!==r?(c=[...r].sort(gp),e[0]=r,e[1]=c):c=e[1];const v=c;let m;e:{if(v.length===0){m=null;break e}let $;e[2]!==i||e[3]!==v?($=v.find(k=>k.path===i)??v[0],e[2]=i,e[3]=v,e[4]=$):$=e[4],m=$}const y=m;if(g||v.length===0)return null;let d;e[5]!==y||e[6]!==n?(d=y?.label&&y.label.trim().length>0?y.label:y?.path.split("/").filter(Boolean).pop()||y?.path||n("settings.shared.projectSelector.fallbackProject"),e[5]=y,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 u;e[14]!==n?(u=n("settings.shared.projectSelector.switchProjectTitle"),e[14]=n,e[15]=u):u=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 w;e[20]===Symbol.for("react.memo_cache_sentinel")?(w=s.jsx(F,{name:"arrow-down-s",className:"size-4 opacity-50"}),e[20]=w):w=e[20];let h;e[21]!==I||e[22]!==N||e[23]!==u?(h=s.jsx(on,{asChild:!0,children:s.jsxs("button",{type:"button","aria-label":N,title:u,className:A,children:[R,I,w]})}),e[21]=I,e[22]=N,e[23]=u,e[24]=h):h=e[24];const j=y?.id??"";let O;e[25]!==l||e[26]!==v?(O=$=>{if(!$)return;const k=v.find(G=>G.id===$);k&&l(k.path)},e[25]=l,e[26]=v,e[27]=O):O=e[27];let T;e[28]!==v?(T=v.map(hp),e[28]=v,e[29]=T):T=e[29];let S;e[30]!==j||e[31]!==O||e[32]!==T?(S=s.jsx(ln,{align:"start",className:"w-auto",children:s.jsx(fc,{value:j,onValueChange:O,children:T})}),e[30]=j,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 mp(t){return t.projects}function up(t){return t.setSettingsProjectPath}function gp(t,e){return(t.label||t.path).localeCompare(e.label||e.path)}function hp(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 fp(t,e){return`opencode:sidebar-group:${t}:${e}`}const dr=t=>{const e=pt.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=fp(r,a),e[0]=a,e[1]=r,e[2]=c):c=e[2];const v=c,m=o.useId();let y;e[3]!==g||e[4]!==v?(y=()=>{try{const S=localStorage.getItem(v);if(S!==null)return S==="true"}catch{}return g},e[3]=g,e[4]=v,e[5]=y):y=e[5];const[d,C]=$e.useState(y);let f,P;e[6]!==d||e[7]!==v?(f=()=>{try{localStorage.setItem(v,String(d))}catch{}},P=[v,d],e[6]=d,e[7]=v,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(xp),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 u=!d&&"-rotate-90";let A;e[12]!==u?(A=fe("h-3.5 w-3.5 flex-shrink-0 transition-transform duration-200",u),e[12]=u,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 w;e[18]!==n?(w=s.jsx("span",{className:"ml-1 tabular-nums opacity-60",children:n}),e[18]=n,e[19]=w):w=e[19];let h;e[20]!==m||e[21]!==d||e[22]!==R||e[23]!==I||e[24]!==w?(h=s.jsxs("button",{type:"button",onClick:x,"aria-expanded":d,"aria-controls":m,className:N,children:[R,I,w]}),e[20]=m,e[21]=d,e[22]=R,e[23]=I,e[24]=w,e[25]=h):h=e[25];const j=!d;let O;e[26]!==l||e[27]!==m||e[28]!==j?(O=s.jsx("div",{id:m,hidden:j,className:"mt-0.5 space-y-0.5 ml-2 pl-3 border-l-2 border-[var(--interactive-border)]",children:l}),e[26]=l,e[27]=m,e[28]=j,e[29]=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 xp(t){return!t}const bp=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},vp=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())},mo=t=>{const e=vp(bp(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},yp=({onItemSelect:t})=>{const{t:e}=tt(),[a,n]=o.useState(null),[r,i]=o.useState(""),[l,g]=o.useState(null),[c,v]=o.useState(null),[m,y]=o.useState(!1),[d,C]=o.useState(null),{selectedAgentName:f,setSelectedAgent:P,setAgentDraft:x,createAgent:N,deleteAgent:u,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 w="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?.()},j=async U=>{if(ua(U)){E.error(e("settings.agents.sidebar.toast.builtInCannotDelete"));return}g(U),v("delete")},O=async U=>{ua(U)&&(g(U),v("reset"))},T=()=>{g(null),v(null)},S=async()=>{if(!(!l||!c)){y(!0);try{const U=await u(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"))}y(!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:mo(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:mo(a.permission),disable:_.disable,scope:_.scope},R);if(H.ok){const z=await u(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}},G=I.filter(U=>!xc(U)),D=G.filter(ua),L=G.filter(U=>!ua(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",w),children:[s.jsxs("div",{className:"border-b px-3 pt-4 pb-3",children:[s.jsx("h2",{className:`${pn} 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:G.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(bs,{outerClassName:"flex-1 min-h-0",className:"space-y-1 px-3 py-2 overflow-x-hidden",children:G.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:()=>j(_),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:()=>j(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&&!m&&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:m,children:e("settings.common.actions.cancel")}),s.jsx(B,{size:"sm",onClick:S,disabled:m,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=pt.c(52),{agent:a,isSelected:n,onSelect:r,onDelete:i,onReset:l,onRename:g,onDuplicate:c,getAgentModeIcon:v,isMenuOpen:m,onMenuOpenChange:y}=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 u;e[1]!==i||e[2]!==c||e[3]!==g||e[4]!==l||e[5]!==d?(u=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]=u):u=e[6];const A=u,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 w;e[9]===Symbol.for("react.memo_cache_sentinel")?(w=P?void 0:re=>{re.preventDefault(),N(!0)},e[9]=w):w=e[9];let h;e[10]!==I?(h=s.jsx("div",{className:I,onContextMenu:w}),e[10]=I,e[11]=h):h=e[11];let j;e[12]!==a.name?(j=s.jsx("span",{className:"typography-ui-label font-normal truncate text-foreground",children:a.name}),e[12]=a.name,e[13]=j):j=e[13];let O;e[14]!==a.mode||e[15]!==v?(O=v(a.mode),e[14]=a.mode,e[15]=v,e[16]=O):O=e[16];let T;e[17]!==a||e[18]!==C.scope||e[19]!==d?(T=(C.scope||ua(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:ua(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]!==j||e[22]!==O||e[23]!==T?(S=s.jsxs("div",{className:"flex items-center gap-1.5",children:[j,O,T]}),e[21]=j,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]!==y?($=re=>{re&&N(!1),y(re)},e[31]=y,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 G;e[34]!==A?(G=s.jsx(ln,{align:"end",className:"w-fit min-w-20",children:A(dn)}),e[34]=A,e[35]=G):G=e[35];let D;e[36]!==m||e[37]!==$||e[38]!==G?(D=s.jsxs(cn,{open:m,onOpenChange:$,children:[k,G]}),e[36]=m,e[37]=$,e[38]=G,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(qn,{className:"w-fit min-w-20",children:A(Wn)}),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=pt.c(21),{children:a,className:n,outerClassName:r,title:i,titleLeading:l,titleAccessory:g,description:c,headerEnd:v,showSaveStatus:m}=t,y=m===void 0?!1:m,d=i!=null||c!=null||v!=null||y,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]!==v||e[8]!==C||e[9]!==y||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:bc,children:c}):c:null]}),s.jsxs("div",{className:"flex shrink-0 flex-wrap items-center justify-end gap-3",children:[v,y&&s.jsx(wp,{})]})]}),e[4]=c,e[5]=d,e[6]=f,e[7]=v,e[8]=C,e[9]=y,e[10]=i,e[11]=g,e[12]=l,e[13]=N):N=e[13];let u;e[14]!==a||e[15]!==x||e[16]!==N?(u=s.jsxs("div",{className:x,children:[N,a]}),e[14]=a,e[15]=x,e[16]=N,e[17]=u):u=e[17];let A;return e[18]!==P||e[19]!==u?(A=s.jsx(bs,{outerClassName:P,className:"w-full @container",children:u}),e[18]=P,e[19]=u,e[20]=A):A=e[20],A},jp=500,wp=()=>{const t=pt.c(13),{t:e}=tt(),a=o.useSyncExternalStore(hd,qr,qr),[n,r]=o.useState(!1);let i,l;if(t[0]!==a?(i=()=>{if(a!=="saving"){r(!1);return}const m=setTimeout(()=>r(!0),jp);return()=>clearTimeout(m)},l=[a],t[0]=a,t[1]=i,t[2]=l):(i=t[1],l=t[2]),o.useEffect(i,l),a==="error"){let m;t[3]===Symbol.for("react.memo_cache_sentinel")?(m=s.jsx(F,{name:"error-warning",className:"size-3.5"}),t[3]=m):m=t[3];let y;t[4]!==e?(y=e("settings.common.status.saveFailed"),t[4]=e,t[5]=y):y=t[5];let d;return t[6]!==y?(d=s.jsxs("div",{"aria-live":"assertive",className:"flex shrink-0 items-center gap-1.5 typography-meta text-[var(--status-error)]",children:[m,s.jsx("span",{children:y})]}),t[6]=y,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 v;return t[11]!==c?(v=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]=v):v=t[12],v},kp=["allow","ask","deny"],Oa=t=>t==="allow"||t==="ask"||t==="deny",pr=()=>({global:null,keys:{}}),Np=t=>{const e=pr();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},mr=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},Sp=(t,e)=>JSON.stringify(mr(t))===JSON.stringify(mr(e)),wn=t=>JSON.parse(JSON.stringify(t)),Cp=["edit","external_directory","doom_loop","plan_enter","plan_exit"],Ip=new Set(["read","edit","glob","grep","list","bash","task","external_directory","lsp","skill"]),uo=new Set(["write","patch","apply_patch","multiedit","invalid"]),Pp=t=>t.split(/[_-]/).filter(Boolean).map(e=>e.charAt(0).toUpperCase()+e.slice(1)).join(" "),Ap=({agent:t})=>{const{t:e}=tt(),a=Hn(z=>z.updateAgent),[n,r]=o.useState(pr),[i,l]=o.useState(pr),[g,c]=o.useState(!0),[v,m]=o.useState(!1),[y,d]=o.useState(!1),[C,f]=o.useState({}),[P,x]=o.useState([]),[N,u]=o.useState(""),[A,R]=o.useState(0),I=t.name,w=_s();o.useEffect(()=>{let z=!1;return c(!0),m(!1),(async()=>{try{const K=w,te=K?`?directory=${encodeURIComponent(K)}`:"",Y=await vt(`/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 ue=Np(ne?.config?.permission);r(wn(ue)),l(ue)}catch{z||m(!0)}finally{z||c(!1)}})(),()=>{z=!0}},[I,A,w]),o.useEffect(()=>{let z=!1;return(async()=>{try{const K=await fn.listToolIds({directory:w});!z&&Array.isArray(K)&&x(K.filter(te=>typeof te=="string"&&!uo.has(te)))}catch{}})(),()=>{z=!0}},[I,w]);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:ue}=te;typeof Y=="string"&&typeof ne=="string"&&Oa(ue)&&K.push({permission:Y,pattern:ne,action:ue})}return K},[t]),j=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 Cp)z.add(K);for(const K of Object.keys(i.keys))z.add(K);for(const K of uo)z.delete(K);return Array.from(z).sort((K,te)=>K.localeCompare(te))},[P,i.keys]),S=o.useMemo(()=>!Sp(i,n),[i,n]),M=z=>{l(K=>({...K,global:z}))},V=(z,K)=>{l(te=>{const Y=wn(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 ue=wn(ne),de=ue.keys[z]??{action:null,patterns:[]};return de.patterns[K]={pattern:te,action:Y},ue.keys[z]=de,ue})},k=z=>{l(K=>{const te=wn(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}))},G=(z,K)=>{l(te=>{const Y=wn(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=wn(K);return te.keys[z]={action:"ask",patterns:[]},te}),f(K=>({...K,[z]:!0})),u(""))},L=async()=>{d(!0);try{const z=mr(i),K=await a(I,{permission:z});K.ok?(r(wn(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(wn(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}]:[],...kp.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")})}):v?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:y,children:e("settings.agents.page.permissionsEditor.actions.discard")}),s.jsx(B,{size:"xs",className:"!font-normal",onClick:()=>{L()},disabled:y,children:e(y?"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(j("*")??"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=Ip.has(z)||K.patterns.length>0,ne=Y||te.length>0,ue=C[z]===!0,de=j(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]:!ue})):void 0,className:fe("flex min-w-0 items-center gap-1.5 text-left",!ne&&"cursor-default"),"aria-expanded":ne?ue:void 0,children:[s.jsx(F,{name:ue&&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:Pp(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}))]}),ue&&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:()=>G(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=>u(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")]})]})]})},Tp=(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):[]},Ep=()=>{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(),v=Hn(H=>fl(H,c)),m=a?n(a,c):null,y=!!(l&&l.name===a&&!m),[d,C]=o.useState(""),[f,P]=o.useState("user"),[x,N]=o.useState(""),[u,A]=o.useState("subagent"),[R,I]=o.useState(""),[w,h]=o.useState(""),[j,O]=o.useState(void 0),[T,S]=o.useState(void 0),[M,V]=o.useState(""),[$,k]=o.useState(!1),G=o.useRef(null),D=o.useMemo(()=>Tp(e,R),[R,e]),L=D.length>0,J=w||"__default",ee=L,U=o.useMemo(()=>w&&!D.includes(w)?[w,...D]:D,[w,D]);o.useEffect(()=>{if(y&&l){const H=l.name||"",z=l.scope||"user",K=l.description||"",te=l.mode||"subagent",Y=l.model||"",ne=l.variant||"",ue=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(ue),S(de),V(xe),G.current={draftName:H,draftScope:z,description:K,mode:te,model:Y,variant:ne,temperature:ue,topP:de,prompt:xe};return}if(m&&a===m.name){const H=m.description||"",z=m.mode||"subagent",K=m.model?.providerID&&m.model?.modelID?`${m.model.providerID}/${m.model.modelID}`:"",te=m.variant||"",Y=m.temperature??void 0,ne=m.topP??void 0,ue=m.prompt||"";N(H),A(z),I(K),h(te),O(Y),S(ne),V(ue),G.current={draftName:"",draftScope:"user",description:H,mode:z,model:K,variant:te,temperature:Y,topP:ne,prompt:ue}}},[l,y,m,a]);const re=o.useMemo(()=>{const H=G.current;return H?!!(y&&(d!==H.draftName||f!==H.draftScope)||x!==H.description||u!==H.mode||R!==H.model||w!==H.variant||j!==H.temperature||T!==H.topP||M!==H.prompt):!1},[x,d,f,y,u,R,M,j,T,w]),_=async()=>{const H=y?d.trim().replace(/\s+/g,"-"):a?.trim();if(!H){E.error(t("settings.agents.sidebar.toast.agentNameRequired"));return}if(y&&v.some(z=>z.name===H)){E.error(t("settings.agents.sidebar.toast.agentExists"));return}k(!0);try{const z=R.trim(),K=w.trim(),te=M.trim(),Y={name:H,...x.trim()?{description:x.trim()}:{},mode:u,model:z===""?null:z,variant:K===""?null:K||void 0,temperature:j??null,top_p:T??null,prompt:te||(y?void 0:null),...y&&f?{scope:f}:{}};let ne;y?(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(y?"settings.agents.page.toast.created":"settings.agents.page.toast.updated")):E.error(t(y?"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:y?t("settings.agents.page.title.new"):a,description:t(y?"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:[y&&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(Wt,{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(Wt,{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:u,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:w,onChange:H=>h(H.target.value),placeholder:t("settings.agents.page.field.variantPlaceholder"),disabled:!R&&!w,className:"h-8 w-40 rounded-md px-3"}),w&&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:j,fallbackValue:.7,onValueChange:O,onClear:()=>O(void 0),min:0,max:2,step:.1,inputMode:"decimal",placeholder:"—",emptyLabel:"—",className:Ps}),j!==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"})}),!y&&m&&s.jsx(Ap,{agent:m}),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")})]})})},Dp=Xd({content:ao(),exists:ep(),path:ao().min(1).optional()}),Mp=async(t,e)=>{const a=await t.json().catch(()=>null);return typeof a?.error=="string"&&a.error.trim()?a.error:e},Rp=t=>t.length>0&&!t.endsWith(`
|
|
2
|
+
`)?`${t}
|
|
3
|
+
`:t,ii={prompt:"",optimizeSystemPrompt:!1,responseStyleEnabled:!1,responseStylePreset:"concise",responseStyleCustomInstructions:""},Lp=(t,e)=>t==="custom"?e:jc(t),Op=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 mt(t)).ok)throw new Error(e)},Fp=()=>{const{t}=tt(),e=vc(),[a,n]=o.useState(""),[r,i]=o.useState("AGENTS.md"),[l,g]=o.useState(!1),[c,v]=o.useState(ii.responseStyleEnabled),[m,y]=o.useState(ii.responseStylePreset),[d,C]=o.useState(ii.responseStyleCustomInstructions),[f,P]=o.useState(!0),[x,N]=o.useState(!1),[u,A]=o.useState(!1),[R,I]=o.useState(""),[w,h]=o.useState(!1),j=o.useRef(null);o.useEffect(()=>{const $=new AbortController;return(async()=>{try{const[G,D]=await Promise.all([mn(),vt("/api/behavior/agents-md",{method:"GET",headers:{Accept:"application/json"},signal:$.signal})]);let L=ii;if(G&&(L={...L,optimizeSystemPrompt:G.optimizeSystemPrompt===!0,responseStyleEnabled:G.responseStyleEnabled===!0,responseStylePreset:Op(G.responseStylePreset),responseStyleCustomInstructions:G.responseStyleCustomInstructions??""},G.globalBehaviorPrompt!==void 0&&(L={...L,prompt:G.globalBehaviorPrompt})),D.ok){const J=Dp.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),v(L.responseStyleEnabled),y(L.responseStylePreset),C(L.responseStyleCustomInstructions),I(L.prompt),j.current={enabled:L.responseStyleEnabled,preset:L.responseStylePreset,custom:L.responseStyleCustomInstructions}}catch(G){G.name!=="AbortError"&&console.warn("Failed to load behavior settings:",G)}finally{P(!1)}})(),()=>$.abort()},[]),o.useEffect(()=>{if(f)return;const $=j.current;if($&&$.enabled===c&&$.preset===m&&$.custom===d)return;const k={enabled:c,preset:m,custom:d},G=setTimeout(async()=>{try{await Qi({responseStyleEnabled:k.enabled,responseStylePreset:k.preset,responseStyleCustomInstructions:k.custom},t("settings.behavior.page.toast.saveFailed")),j.current=k}catch(D){const L=D instanceof Error?D.message:t("settings.behavior.page.toast.saveFailed");E.error(L)}},400);return()=>clearTimeout(G)},[c,m,d,f,t]);const O=Lp(m,d),T=a!==R,S=l!==w,M=async()=>{N(!0);try{const $=Rp(a),k=await vt("/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 Mp(k,t("settings.behavior.page.toast.saveFailed")));const G=await k.json().catch(()=>null),D=bl(G,"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||u,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||u||!S,className:"!font-normal",children:t(u?"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:v,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:m,onValueChange:$=>y($),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:[yc.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||m!=="custom",outerClassName:"min-h-[120px]",className:"w-full font-mono typography-meta bg-transparent"})]})]})},Kp=t=>{const e=pt.c(176),{onItemSelect:a}=t,{t:n}=tt(),[r,i]=o.useState(null),[l,g]=o.useState(""),[c,v]=o.useState(null),[m,y]=o.useState(null),[d,C]=o.useState(!1),[f,P]=o.useState(null),{selectedCommandName:x,setSelectedCommand:N,setCommandDraft:u,createCommand:A,deleteCommand:R,loadCommands:I}=ba(Us(zp)),w=_s();let h;e[0]!==w?(h=Be=>vl(Be,w),e[0]=w,e[1]=h):h=e[1];const j=ba(h);let O;e[2]!==w?(O=Be=>jr(Be,w),e[2]=w,e[3]=O):O=e[3];const T=Hs(O),S=Hs(Up);let M,V;e[4]!==I||e[5]!==S||e[6]!==w?(M=()=>{I(w),S(w)},V=[I,S,w],e[4]=I,e[5]=S,e[6]=w,e[7]=M,e[8]=V):(M=e[7],V=e[8]),o.useEffect(M,V);let $;e[9]!==T?($=new Set(T.map(_p)),e[9]=T,e[10]=$):$=e[10];const k=$;let G;if(e[11]!==j||e[12]!==k){let Be;e[14]!==k?(Be=Et=>!k.has(Et.name),e[14]=k,e[15]=Be):Be=e[15],G=j.filter(Be),e[11]=j,e[12]=k,e[13]=G}else G=e[13];const D=G;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]!==j||e[22]!==a||e[23]!==u||e[24]!==N?(ee=()=>{let Be="new-command",Et=1;for(;j.some(Me=>Me.name===Be);)Be=`new-command-${Et}`,Et++;u({name:Be,scope:"user"}),N(Be),a?.()},e[21]=j,e[22]=a,e[23]=u,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}v(Be),y("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)&&(v(Be),y("reset"))},e[28]=H):H=e[28];const z=H;let K;e[29]===Symbol.for("react.memo_cache_sentinel")?(K=()=>{v(null),y(null)},e[29]=K):K=e[29];const te=K;let Y;e[30]!==c||e[31]!==m||e[32]!==R||e[33]!==w||e[34]!==n?(Y=async()=>{if(!c||!m)return;C(!0),await R(c.name,w)?(m==="delete"?E.success(n("settings.commands.sidebar.toast.commandDeleted",{name:c.name})):E.success(n("settings.commands.sidebar.toast.commandReset",{name:c.name})),te()):m==="delete"?E.error(n("settings.commands.sidebar.toast.deleteFailed")):E.error(n("settings.commands.sidebar.toast.resetFailed")),C(!1)},e[30]=c,e[31]=m,e[32]=R,e[33]=w,e[34]=n,e[35]=Y):Y=e[35];const ne=Y;let ue;e[36]!==j||e[37]!==u||e[38]!==N?(ue=Be=>{const Et=Be.name;let Me=1,jt=`${Et}-copy`;for(;j.some(Q=>Q.name===jt);)Me++,jt=`${Et}-copy-${Me}`;u({name:jt,scope:Be.scope||"user",description:Be.description,template:Be.template,agent:Be.agent,model:Be.model}),N(jt)},e[36]=j,e[37]=u,e[38]=N,e[39]=ue):ue=e[39];const de=ue;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]!==j||e[42]!==A||e[43]!==R||e[44]!==r||e[45]!==l||e[46]!==N||e[47]!==w||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(j.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},w)?await R(r.name,w)?(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]=j,e[42]=A,e[43]=R,e[44]=r,e[45]=l,e[46]=N,e[47]=w,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($p);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 jt;e[68]!==Me?(jt=s.jsx("h2",{className:`${pn} mb-3`,children:Me}),e[68]=Me,e[69]=jt):jt=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 pe;e[71]!==D.length||e[72]!==n?(pe=n("settings.commands.sidebar.total",{count:D.length}),e[71]=D.length,e[72]=n,e[73]=pe):pe=e[73];let De;e[74]!==pe?(De=s.jsx("span",{className:"typography-meta text-muted-foreground",children:pe}),e[74]=pe,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]!==jt||e[83]!==rt?(Ue=s.jsxs("div",{className:"border-b px-3 pt-4 pb-3",children:[jt,Q,rt]}),e[82]=jt,e[83]=rt,e[84]=Ue):Ue=e[84],Ae=bs,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(Vp).map(We=>s.jsx(ho,{command:We,isSelected:x===We.name,onSelect:()=>{N(We.name),a?.()},onReset:()=>z(We),onDuplicate:()=>de(We),isMenuOpen:f===We.name,onMenuOpenChange:Pt=>P(Pt?We.name:null)},We.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(Bp).map(We=>s.jsx(ho,{command:We,isSelected:x===We.name,onSelect:()=>{N(We.name),a?.()},onRename:()=>ae(We),onDelete:()=>_(We),onDuplicate:()=>de(We),isMenuOpen:f===We.name,onMenuOpenChange:Pt=>P(Pt?We.name:null)},We.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&&m!==null;let Ve;e[90]!==d?(Ve=Be=>{!Be&&!d&&te()},e[90]=d,e[91]=Ve):Ve=e[91];let Ge;e[92]!==m||e[93]!==n?(Ge=n(m==="delete"?"settings.commands.sidebar.dialog.deleteTitle":"settings.commands.sidebar.dialog.resetTitle"),e[92]=m,e[93]=n,e[94]=Ge):Ge=e[94];let be;e[95]!==Ge?(be=s.jsx($t,{children:Ge}),e[95]=Ge,e[96]=be):be=e[96];let Z;e[97]!==c?.name||e[98]!==m||e[99]!==n?(Z=m==="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]=m,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 ve;e[103]!==be||e[104]!==se?(ve=s.jsxs(_t,{children:[be,se]}),e[103]=be,e[104]=se,e[105]=ve):ve=e[105];let ye;e[106]!==n?(ye=n("settings.common.actions.cancel"),e[106]=n,e[107]=ye):ye=e[107];let Re;e[108]!==d||e[109]!==ye?(Re=s.jsx(B,{size:"sm",variant:"ghost",onClick:te,disabled:d,children:ye}),e[108]=d,e[109]=ye,e[110]=Re):Re=e[110];let Fe;e[111]!==m||e[112]!==n?(Fe=n(m==="delete"?"settings.common.actions.delete":"settings.common.actions.reset"),e[111]=m,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 je;e[121]!==ve||e[122]!==Ee?(je=s.jsxs(zt,{className:"max-w-md",children:[ve,Ee]}),e[121]=ve,e[122]=Ee,e[123]=je):je=e[123];let Ze;e[124]!==Oe||e[125]!==Ve||e[126]!==je?(Ze=s.jsx(Kt,{open:Oe,onOpenChange:Ve,children:je}),e[124]=Oe,e[125]=Ve,e[126]=je,e[127]=Ze):Ze=e[127];const me=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 W=r?.name??"";let we;e[133]!==n||e[134]!==W?(we=n("settings.commands.sidebar.renameDialog.description",{name:W}),e[133]=n,e[134]=W,e[135]=we):we=e[135];let Ie;e[136]!==we?(Ie=s.jsx(Vt,{children:we}),e[136]=we,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 ut;e[144]!==ge?(ut=Be=>{Be.key==="Enter"&&ge()},e[144]=ge,e[145]=ut):ut=e[145];let bt;e[146]!==l||e[147]!==st||e[148]!==ut?(bt=s.jsx(He,{value:l,onChange:ot,placeholder:st,className:"text-foreground placeholder:text-muted-foreground",onKeyDown:ut}),e[146]=l,e[147]=st,e[148]=ut,e[149]=bt):bt=e[149];let q;e[150]===Symbol.for("react.memo_cache_sentinel")?(q=()=>i(null),e[150]=q):q=e[150];let qe;e[151]!==n?(qe=n("settings.common.actions.cancel"),e[151]=n,e[152]=qe):qe=e[152];let nt;e[153]!==qe?(nt=s.jsx(B,{size:"sm",variant:"ghost",onClick:q,children:qe}),e[153]=qe,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]!==bt||e[165]!==Lt?(et=s.jsxs(zt,{children:[Je,bt,Lt]}),e[163]=Je,e[164]=bt,e[165]=Lt,e[166]=et):et=e[166];let ft;e[167]!==me||e[168]!==et?(ft=s.jsx(Kt,{open:me,onOpenChange:Ne,children:et}),e[167]=me,e[168]=et,e[169]=ft):ft=e[169];let yt;return e[170]!==_e||e[171]!==Ue||e[172]!==ke||e[173]!==Ze||e[174]!==ft?(yt=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]=yt):yt=e[175],yt},ho=t=>{const e=pt.c(47),{command:a,isSelected:n,onSelect:r,onDelete:i,onReset:l,onRename:g,onDuplicate:c,isMenuOpen:v,onMenuOpenChange:m}=t,{t:y}=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]!==y?(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"}),y("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"}),y("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"}),y("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"}),y("settings.common.actions.delete")]})]}),e[1]=i,e[2]=c,e[3]=g,e[4]=l,e[5]=y,e[6]=x):x=e[6];const N=x,u=n?"bg-interactive-selection":"hover:bg-interactive-hover";let A;e[7]!==u?(A=fe("group relative flex items-center rounded-md px-1.5 py-1 transition-all duration-200 select-none",u),e[7]=u,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 w;e[12]!==a.name?(w=s.jsxs("span",{className:"typography-ui-label font-normal truncate text-foreground",children:["/",a.name]}),e[12]=a.name,e[13]=w):w=e[13];let h;e[14]!==a||e[15]!==y?(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)?y("settings.agents.sidebar.badge.system"):a.scope}),e[14]=a,e[15]=y,e[16]=h):h=e[16];let j;e[17]!==w||e[18]!==h?(j=s.jsxs("div",{className:"flex items-center gap-2",children:[w,h]}),e[17]=w,e[18]=h,e[19]=j):j=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]!==j?(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:[j,O]}),e[22]=r,e[23]=O,e[24]=j,e[25]=T):T=e[25];let S;e[26]!==m?(S=J=>{J&&P(!1),m(J)},e[26]=m,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]!==v||e[32]!==S||e[33]!==V?($=s.jsxs(cn,{open:v,onOpenChange:S,children:[M,V]}),e[31]=v,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 G;e[38]!==k||e[39]!==I?(G=s.jsx(Jn,{render:I,children:k}),e[38]=k,e[39]=I,e[40]=G):G=e[40];let D;e[41]!==N?(D=s.jsx(qn,{className:"w-fit min-w-20",children:N(Wn)}),e[41]=N,e[42]=D):D=e[42];let L;return e[43]!==f||e[44]!==G||e[45]!==D?(L=s.jsxs(Qn,{open:f,onOpenChange:P,children:[G,D]}),e[43]=f,e[44]=G,e[45]=D,e[46]=L):L=e[46],L};function zp(t){return{selectedCommandName:t.selectedCommandName,setSelectedCommand:t.setSelectedCommand,setCommandDraft:t.setCommandDraft,createCommand:t.createCommand,deleteCommand:t.deleteCommand,loadCommands:t.loadCommands}}function Up(t){return t.loadSkills}function _p(t){return t.name}function $p(t){return!ha(t)}function Vp(t,e){return t.name.localeCompare(e.name)}function Bp(t,e){return t.name.localeCompare(e.name)}const Hp=()=>{const{t}=tt(),{selectedCommandName:e,getCommandByName:a,createCommand:n,updateCommand:r,commandDraft:i,setCommandDraft:l}=ba(Us(M=>({selectedCommandName:M.selectedCommandName,getCommandByName:M.getCommandByName,createCommand:M.createCommand,updateCommand:M.updateCommand,commandDraft:M.commandDraft,setCommandDraft:M.setCommandDraft}))),g=_s(),c=ba(M=>vl(M,g)),v=e?a(e,g):null,m=!!(i&&i.name===e&&!v),[y,d]=o.useState(""),[C,f]=o.useState("user"),[P,x]=o.useState(""),[N,u]=o.useState(""),[A,R]=o.useState(""),[I,w]=o.useState(""),[h,j]=o.useState(!1),O=o.useRef(null);o.useEffect(()=>{if(m&&i){const M=i.name||"",V=i.scope||"user",$=i.description||"",k=i.agent||"",G=i.model||"",D=i.template||"";d(M),f(V),x($),u(k),R(G),w(D),O.current={draftName:M,draftScope:V,description:$,agent:k,model:G,template:D}}else if(v){const M=v.description||"",V=v.agent||"",$=v.model||"",k=v.template||"";x(M),u(V),R($),w(k),O.current={draftName:"",draftScope:"user",description:M,agent:V,model:$,template:k}}},[v,m,e,c,i]);const T=o.useMemo(()=>{const M=O.current;return M?!!(m&&(y!==M.draftName||C!==M.draftScope)||P!==M.description||N!==M.agent||A!==M.model||I!==M.template):!1},[N,P,y,C,m,A,I]),S=async()=>{const M=m?y.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(m&&c.some(V=>V.name===M)){E.error(t("settings.commands.sidebar.toast.commandExists"));return}j(!0);try{const V=N.trim(),$=A.trim(),k=I.trim(),G={name:M,description:P.trim()||void 0,agent:V===""?null:V,model:$===""?null:$,template:k,scope:m?C:void 0};let D;if(m?(D=await n(G,g),D&&l(null)):D=await r(M,G,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":m?"settings.commands.page.toast.created":"settings.commands.page.toast.updated"))}else E.error(t(m?"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{j(!1)}};return e?s.jsxs(es,{title:m?t("settings.commands.page.title.new"):`/${e}`,description:t(m?"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:[m&&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:y,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(yl,{agentName:N,onChange:M=>u(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=>w(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=pt.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},Gp=t=>{const e=pt.c(124),{onItemSelect:a}=t,{t:n}=tt(),{selectedMcpName:r,setSelectedMcp:i,setMcpDraft:l,loadMcpConfigs:g,deleteMcp:c}=va(Us(qp)),v=_s();let m;e[0]!==v?(m=W=>jl(W,v),e[0]=v,e[1]=m):m=e[1];const y=va(m);let d;e[2]!==v?(d=W=>W.getStatusForDirectory(v),e[2]=v,e[3]=d):d=e[3];const C=Ks(d),f=Ks(Wp),P=Ks(Jp),[x,N]=o.useState(null),[u,A]=o.useState(!1),[R,I]=o.useState(null),[w,h]=o.useState(null),[j,O]=o.useState(!1);let T;e[4]!==y?(T=y.filter(Qp),e[4]=y,e[5]=T):T=e[5];const S=T;let M;e[6]!==y?(M=y.filter(Yp),e[6]=y,e[7]=M):M=e[7];const V=M;let $,k;e[8]!==g||e[9]!==v?($=()=>{g({directory:v})},k=[g,v],e[8]=g,e[9]=v,e[10]=$,e[11]=k):($=e[10],k=e[11]),o.useEffect($,k);let G;e[12]!==P||e[13]!==j||e[14]!==f||e[15]!==v?(G=()=>{if(j)return;O(!0);const W=new Promise(Zp);Promise.all([f({directory:v,silent:!0}),W]).then(()=>{const we=P(v);we&&E.error(we)}).finally(()=>{O(!1)})},e[12]=P,e[13]=j,e[14]=f,e[15]=v,e[16]=G):G=e[16];const D=G;let L;e[17]!==y||e[18]!==a||e[19]!==l||e[20]!==i?(L=()=>{let W="new-mcp-server",we=1;for(;y.some(Je=>Je.name===W);)W=`new-mcp-server-${we}`,we++;l({name:W,scope:"user",type:"local",command:[],url:"",environment:[],headers:[],oauthEnabled:!0,oauthClientId:"",oauthClientSecret:"",oauthScope:"",oauthRedirectUri:"",timeout:"",enabled:!0}),i(W),a?.()},e[17]=y,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]!==v||e[25]!==n?(ee=async()=>{if(!x)return;A(!0);const W=await c(x.name,v);W.ok?W.reloadFailed?E.warning(W.message||`MCP server "${x.name}" deleted, but OpenCode reload failed`,{description:W.warning||n("settings.mcp.sidebar.toast.refreshListIfStale")}):E.success(W.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]=v,e[25]=n,e[26]=ee):ee=e[26];const U=ee;let re;e[27]!==n?(re=(W,we)=>s.jsxs(we,{onClick:Ie=>{Ie.stopPropagation(),N(W)},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:pn,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=j&&"animate-spin";let ue;e[38]!==ne?(ue=fe("h-4 w-4",ne),e[38]=ne,e[39]=ue):ue=e[39];let de;e[40]!==ue?(de=s.jsx(F,{name:"refresh",className:ue}),e[40]=ue,e[41]=de):de=e[41];let xe;e[42]!==D||e[43]!==j||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:j,onClick:D,"aria-label":te,title:Y,children:de}),e[42]=D,e[43]=j,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]!==y.length||e[53]!==n?(ge=n("settings.mcp.sidebar.total",{count:y.length}),e[52]=y.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]!==y.length||e[70]!==C||e[71]!==a||e[72]!==R||e[73]!==S||e[74]!==_||e[75]!==w||e[76]!==r||e[77]!==l||e[78]!==i||e[79]!==n||e[80]!==V?(ke=s.jsx(bs,{outerClassName:"flex-1 min-h-0",className:"space-y-1 px-3 py-2 overflow-x-hidden",children:y.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(W=>{const we=C[W.name],Ie=fo(we?.status),Je=r===W.name,ot=_a();return s.jsxs(Qn,{open:w===W.name,onOpenChange:st=>h(st?W.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(W.name)}}),children:[s.jsxs("button",{onClick:()=>{i(W.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:W.enabled}),s.jsx("span",{className:"typography-ui-label font-normal truncate text-foreground",children:W.name}),s.jsx("span",{title:W.type==="local"?n("settings.mcp.sidebar.serverType.localTitle"):n("settings.mcp.sidebar.serverType.remoteTitle"),children:W.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:W.type==="local"?W.command?.join(" ")??"":W.url??""})]}),s.jsxs(cn,{open:R===W.name,onOpenChange:st=>{st&&h(null),I(st?W.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:_(W,dn)})]})]}),s.jsx(qn,{className:"w-fit min-w-20",children:_(W,Wn)})]},W.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(W=>{const we=C[W.name],Ie=fo(we?.status),Je=r===W.name,ot=_a();return s.jsxs(Qn,{open:w===W.name,onOpenChange:st=>h(st?W.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(W.name)}}),children:[s.jsxs("button",{onClick:()=>{i(W.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:W.enabled}),s.jsx("span",{className:"typography-ui-label font-normal truncate text-foreground",children:W.name}),s.jsx("span",{title:W.type==="local"?n("settings.mcp.sidebar.serverType.localTitle"):n("settings.mcp.sidebar.serverType.remoteTitle"),children:W.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:W.type==="local"?W.command?.join(" ")??"":W.url??""})]}),s.jsxs(cn,{open:R===W.name,onOpenChange:st=>{st&&h(null),I(st?W.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:_(W,dn)})]})]}),s.jsx(qn,{className:"w-fit min-w-20",children:_(W,Wn)})]},W.name)})]})]})}),e[69]=y.length,e[70]=C,e[71]=a,e[72]=R,e[73]=S,e[74]=_,e[75]=w,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]!==u?(Ve=W=>{!W&&!u&&N(null)},e[82]=u,e[83]=Ve):Ve=e[83];let Ge;e[84]!==n?(Ge=n("settings.mcp.sidebar.deleteDialog.title"),e[84]=n,e[85]=Ge):Ge=e[85];let be;e[86]!==Ge?(be=s.jsx($t,{children:Ge}),e[86]=Ge,e[87]=be):be=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 ve;e[91]===Symbol.for("react.memo_cache_sentinel")?(ve=s.jsx("code",{className:"text-foreground",children:"opencode.json"}),e[91]=ve):ve=e[91];let ye;e[92]!==se?(ye=s.jsxs(Vt,{children:[se," ",ve,"."]}),e[92]=se,e[93]=ye):ye=e[93];let Re;e[94]!==be||e[95]!==ye?(Re=s.jsxs(_t,{children:[be,ye]}),e[94]=be,e[95]=ye,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]!==u||e[101]!==Ke?(Ee=s.jsx(B,{size:"sm",variant:"ghost",onClick:Fe,disabled:u,children:Ke}),e[100]=u,e[101]=Ke,e[102]=Ee):Ee=e[102];let je;e[103]!==u||e[104]!==n?(je=n(u?"settings.mcp.sidebar.actions.deleting":"settings.common.actions.delete"),e[103]=u,e[104]=n,e[105]=je):je=e[105];let Ze;e[106]!==U||e[107]!==u||e[108]!==je?(Ze=s.jsx(B,{size:"sm",onClick:U,disabled:u,children:je}),e[106]=U,e[107]=u,e[108]=je,e[109]=Ze):Ze=e[109];let me;e[110]!==Ee||e[111]!==Ze?(me=s.jsxs(ts,{children:[Ee,Ze]}),e[110]=Ee,e[111]=Ze,e[112]=me):me=e[112];let Ne;e[113]!==Re||e[114]!==me?(Ne=s.jsxs(zt,{className:"max-w-md",children:[Re,me]}),e[113]=Re,e[114]=me,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 qp(t){return{selectedMcpName:t.selectedMcpName,setSelectedMcp:t.setSelectedMcp,setMcpDraft:t.setMcpDraft,loadMcpConfigs:t.loadMcpConfigs,deleteMcp:t.deleteMcp}}function Wp(t){return t.refresh}function Jp(t){return t.getErrorForDirectory}function Qp(t){return t.scope==="project"}function Yp(t){return t.scope!=="project"}function Zp(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=Xp(a),r=typeof a.url=="string"?a.url.trim():"",i=bo(a,"env","environment"),l=bo(a,"headers"),g=em(a),c=typeof a.oauth=="object"&&a.oauth!==null?String(a.oauth.clientId??"").trim():"",v=typeof a.oauth=="object"&&a.oauth!==null?String(a.oauth.clientSecret??"").trim():"",m=typeof a.oauth=="object"&&a.oauth!==null?String(a.oauth.scope??"").trim():"",y=typeof a.oauth=="object"&&a.oauth!==null?String(a.oauth.redirectUri??"").trim():"",d=tm(a),C=sm(a);return{ok:!0,name:t,type:e,command:n,url:r,environment:i,headers:l,oauthEnabled:g,oauthClientId:c,oauthClientSecret:v,oauthScope:m,oauthRedirectUri:y,timeout:d,enabled:C}}function Xp(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 bo(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 em(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 tm(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 sm(t){return"disabled"in t&&t.disabled===!0?!1:"enabled"in t?!!t.enabled:!0}function nm(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 am(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],v=r[c];return an(v)?ri(c,oi(v),v):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],v=i[c];return an(v)?ri(c,oi(v),v):nn("Server entry in mcp is not a valid object",a)}const l=nm(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 im(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 rm(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:wl(a.searchParams)}}catch{}return{code:e,context:null,stateKey:null}}const om=t=>{const e=pt.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),v=o.useRef(a);let m,y;e[2]!==a?(m=()=>{JSON.stringify(v.current)!==JSON.stringify(a)&&(v.current=a,c(a.join(`
|
|
5
|
+
`)))},y=[a],e[2]=a,e[3]=m,e[4]=y):(m=e[3],y=e[4]),o.useEffect(m,y);let d;e[5]!==n||e[6]!==i?(d=w=>{const h=w.split(`
|
|
6
|
+
`).filter(hm);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=w=>{const j=w.clipboardData.getData("text").trim();if(!j||j.includes(`
|
|
7
|
+
`)||!/\s/.test(j))return;const O=w.currentTarget;if(O.selectionStart!==0||O.selectionEnd!==O.value.length)return;w.preventDefault();const T=Vl(j);c(T.join(`
|
|
8
|
+
`)),n(T)},e[8]=n,e[9]=f):f=e[9];const P=f;let x;e[10]!==C?(x=w=>{c(w.target.value),C(w.target.value)},e[10]=C,e[11]=x):x=e[11];let N;e[12]!==C||e[13]!==g?(N=()=>{const w=g.split(`
|
|
9
|
+
`).map(fm).join(`
|
|
10
|
+
`);c(w),C(w)},e[12]=C,e[13]=g,e[14]=N):N=e[14];const u=Math.max(4,a.length+1);let A;e[15]!==P||e[16]!==x||e[17]!==N||e[18]!==u||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:u,className:"font-mono typography-meta min-h-[80px]",spellCheck:!1}),e[15]=P,e[16]=x,e[17]=N,e[18]=u,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(xm)})})]}),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},lm=t=>t.toUpperCase().replace(/[^A-Z0-9_]/g,"_"),vo=({value:t,onChange:e,keyTransform:a=lm,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:v,keyLabel:m,valueLabel:y,valuePlaceholder:d,hideValueTitle:C,showValueTitle:f,addVariable:P,plainTextWarning:x,removeVariableAria:N})=>{const[u,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})},w=(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})},j=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 G=$.slice(0,k).trim();let D=$.slice(k+1).trim();(D.startsWith('"')&&D.endsWith('"')||D.startsWith("'")&&D.endsWith("'"))&&(D=D.slice(1,-1)),G&&S.push({key:G,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(v)}},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:m}),s.jsx("span",{className:"typography-micro text-muted-foreground",children:y})]}),s.jsxs(B,{variant:"ghost",size:"xs",className:"!font-normal gap-1 text-muted-foreground",onClick:j,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=>w(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:u.has(S)?"text":"password",value:T.value,onChange:M=>w(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:u.has(S)?C:f,children:u.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=pt.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 v;e[8]!==r||e[9]!==a?(v=r(a),e[8]=r,e[9]=a,e[10]=v):v=e[10];let m;return e[11]!==g||e[12]!==v?(m=s.jsxs("span",{className:g,children:["● ",v]}),e[11]=g,e[12]=v,e[13]=m):m=e[13],m},cm=(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")}},dm=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)]"}},pm=(t,e,a,n)=>!!(t==="failed"||t==="needs_auth"||t==="needs_client_registration"||e||a||n),mm=async t=>{const e=await vt(`/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 vt(`/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},um=(t,e)=>{const a=typeof e=="string"&&e.trim()?e.trim():"__global__";return`${t??"__none__"}::${a}`},gm=()=>{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:v}=va(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}))),m=_s(),y=o.useMemo(()=>cs(),[]),d=Ks(oe=>oe.getStatusForDirectory(m)),C=Ks(oe=>oe.getDiagnosticForDirectory(m)),f=Ks(oe=>oe.refresh),P=Ks(oe=>oe.connect),x=Ks(oe=>oe.disconnect),N=Ks(oe=>oe.completeAuth),u=Ks(oe=>oe.clearAuth),A=Ks(oe=>oe.testConnection),R=Vn(oe=>oe.changes),I=va(oe=>jl(oe,m)),w=a?l(a,m):null,h=!!(n&&n.name===a&&!w),[j,O]=o.useState(""),[T,S]=o.useState("user"),[M,V]=o.useState("local"),[$,k]=o.useState([]),[G,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(""),[ue,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,Ge]=o.useState(!1),[be,Z]=o.useState(!1),[se,ve]=o.useState(!1),[ye,Re]=o.useState(!1),[Fe,Ke]=o.useState(null),[Ee,je]=o.useState(null),[Ze,me]=o.useState(""),[Ne,Le]=o.useState(!1),Xe=o.useRef(0),W=o.useRef(!1),[we,Ie]=o.useState(!1),[Je,ot]=o.useState(!1),[st,ut]=o.useState(""),[bt,q]=o.useState(null),qe=o.useMemo(()=>um(a,m),[m,a]),nt=o.useRef(qe),lt=o.useRef(null),ht=o.useCallback(()=>{Ke(null),je(null),me(""),Le(!1),Xe.current=0,Re(!1),Ge(!1),Z(!1),W.current=!1},[]),Lt=o.useCallback(()=>{ut(""),q(null),ot(!0)},[]),et=o.useCallback(async()=>{try{const oe=await navigator.clipboard.readText();ut(oe),q(null)}catch{E.error(t("settings.mcp.page.toast.clipboardReadFailed"))}},[t]),ft=o.useCallback(()=>{const oe=am(st,{fallbackName:j});if(!oe.ok){q(oe.error);return}const xt=im(oe,{name:j,scope:T,type:M,command:$,url:G,environment:L,headers:ee,oauthEnabled:re,oauthClientId:H,oauthClientSecret:K,oauthScope:Y,oauthRedirectUri:ue,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),ut(""),q(null),E.success(t("settings.mcp.page.toast.configImported"))},[st,j,T,M,$,G,L,ee,re,H,K,Y,ue,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(w){S(w.scope==="project"?"project":"user");const oe=Kr(w.environment),ct=w.type==="remote"?w:null,xt=Kr(ct?.headers),Qt=ct?.oauth,Yt=Qt&&typeof Qt=="object"?Qt:null,Bt=Qt!==!1,rs=w.type,js=rs==="local"?w.command??[]:[],ss=rs==="remote"?w.url??"":"",wt=typeof ct?.timeout=="number"&&Number.isFinite(ct.timeout)?String(ct.timeout):"";V(rs),k(js),D(ss),J(oe),U(xt),_(Bt),z(Bt?Yt?.clientId??"":""),te(Bt?Yt?.clientSecret??"":""),ne(Bt?Yt?.scope??"":""),de(Bt?Yt?.redirectUri??"":""),ae(wt),ge(w.enabled),Ie(!1),lt.current={mcpType:rs,command:js,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:wt,enabled:w.enabled}}},[w,h,n]);const yt=o.useMemo(()=>{const oe=lt.current;return oe?M!==oe.mcpType||le!==oe.enabled||JSON.stringify($)!==JSON.stringify(oe.command)||G!==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||ue!==oe.oauthRedirectUri||xe!==oe.timeout:!1},[M,$,G,L,ee,re,H,K,Y,ue,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(""))},[]),jt=async()=>{const oe=h?j.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"&&!G.trim()){E.error(t("settings.mcp.page.toast.remoteUrlRequired"));return}const ct={name:oe,scope:T,type:M,command:$,url:G,environment:L,headers:ee,oauthEnabled:re,oauthClientId:H,oauthClientSecret:K,oauthScope:Y,oauthRedirectUri:ue,timeout:xe,enabled:le};Se(!0);try{const xt=h?await g(ct,m):await c(oe,ct,m);xt.ok?(await Aa(Ee),ht(),h&&(r(null),i(oe)),await f({directory:m,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 v(a,m);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)},pe=async()=>{if(a){Oe(!0);try{if(d[a]?.status==="connected")await x(a,m),E.success(t("settings.mcp.page.toast.disconnected"));else{await P(a,m),await f({directory:m,silent:!0});const ct=Ks.getState().getStatusForDirectory(m)[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:m,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):yt?(E.error(t("settings.mcp.page.toast.saveBeforeLiveActions")),!1):!0,[yt,h,t]),Pe=o.useCallback(async(oe=!1)=>{try{await f({directory:m,silent:oe})}catch(ct){oe||E.error(ct instanceof Error?ct.message:t("settings.mcp.page.toast.refreshStatusFailed"))}},[m,f,t]);o.useEffect(()=>{Pe(!0)},[Pe]),o.useEffect(()=>{nt.current=qe,Oe(!1),ve(!1),ht()},[ht,qe]);const it=o.useCallback(async()=>{if(!a||M!=="remote"||!De())return;Ge(!0);const oe=qe;let ct=null;try{const xt=Ks.getState().getStatusForDirectory(m)[a]?.status;W.current=xt==="needs_auth"||xt==="needs_client_registration";const{authorizationUrl:Qt,opened:Yt,nativeFlow:Bt,completion:rs}=await wc({name:a,directory:m});if(Bt){if(nt.current!==oe)return;Ke(null),je(null),Le(!0),Xe.current=0,E.message(t("settings.mcp.page.toast.completeAuthorizationInBrowser")),rs?.then(()=>{nt.current===oe&&(Le(!1),Xe.current=0,W.current=!1,E.success(t("settings.mcp.page.toast.authorizationCompleted")))}).catch(ss=>{nt.current===oe&&(Le(!1),Xe.current=0,W.current=!1,E.error(li(ss,t("settings.mcp.page.toast.authorizationFailed"),e)))});return}const js=wl(new URL(Qt).searchParams);if(ct=js,nt.current!==oe||(Ke(Qt),je(js??null),Le(!0),Xe.current=0,nt.current!==oe))return;Yt?E.message(t(y?"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&&Ge(!1)}},[m,y,M,De,qe,a,t,e]),rt=o.useCallback(async()=>{if(!a||!De())return;Z(!0);const oe=qe;try{if(await u(a,m),nt.current!==oe)return;Ke(null),je(null),me(""),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,u,m,De,qe,a,t,e]),We=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=rm(Ze);if(!oe.code){E.error(t("settings.mcp.page.toast.pasteCallbackOrCodeFirst"));return}const ct=oe.stateKey?await mm(oe.stateKey):null,xt=oe.context??ct,Qt=xt?.name??a,Yt=xt?.directory??m;if(!Qt){E.error(t("settings.mcp.page.toast.missingServerDetails"));return}if(!xt&&!De())return;Re(!0);const Bt=qe;try{if(await N(Qt,oe.code,Yt),await Aa(oe.stateKey??Ee),nt.current!==Bt)return;me(""),Ke(null),je(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,m,De,qe,a,t,e]),vs=o.useCallback(async()=>{if(!(!a||!De())){if(!le){E.error(t("settings.mcp.page.toast.enableServerBeforeTest"));return}ve(!0);try{const oe=await A(a,m),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{ve(!1)}}},[m,le,De,a,t,A]);if(o.useEffect(()=>{if(!Ne||!a)return;const oe=window.setInterval(()=>{(async()=>{Xe.current+=1,await f({directory:m,silent:!0});const ct=Ks.getState().getStatusForDirectory(m)[a];if(ct){if(W.current&&ct.status!=="needs_auth"&&ct.status!=="needs_client_registration"){Le(!1),Xe.current=0,W.current=!1,Ke(null),me(""),ct.status==="connected"&&E.success(t("settings.mcp.page.toast.authorizationCompleted"));return}if(!W.current&&ct.status==="failed"){Le(!1),Xe.current=0,W.current=!1,E.error(ct.error||t("settings.mcp.page.toast.authorizationFailed"));return}Xe.current>=30&&(Le(!1),Xe.current=0,W.current=!1,E.message(t("settings.mcp.page.toast.authorizationStillInProgress")))}})()},2e3);return()=>{window.clearInterval(oe)}},[m,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,qt=Xt??Os,is=!h&&!qt&&R.some(oe=>oe.scope==="mcp"&&oe.id.startsWith(`mcp:${a}:`)),Ht=Xt?.status==="connected",ys=Xt?.status==="needs_auth"||Xt?.status==="needs_client_registration",gs=y||!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=cm(qt?.status,e,qt&&"error"in qt?qt.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":qt?.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:pe,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:ys?"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:be||!le,children:t(be?"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:()=>{vs()},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&&pm(qt?.status,Fe,ys,Ne)&&s.jsx(ze,{divider:!1,children:s.jsxs("div",{className:fe("rounded-lg border p-3",dm(qt?.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:qt?.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:m??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:()=>{vs()},disabled:se||!le,children:t(se?"settings.mcp.page.actions.testing":"settings.mcp.page.actions.testConnection")})}),qt?.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(Wt,{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(Wt,{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:()=>{We()},children:[s.jsx(F,{name:"clipboard",className:"h-3.5 w-3.5"}),t("settings.mcp.page.actions.copyLink")]})]})]})}),y&&M==="remote"&&(ys||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=>me(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:ye,children:t(ye?"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:j,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(om,{value:$,onChange:k,preview:oe=>t("settings.mcp.page.connection.previewArgs",{count:oe}),onDetectUrl:Et}):s.jsx(He,{value:G,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:we,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`:"",")"]})]}),we?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(vo,{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(vo,{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:jt,disabled:Ae||!yt&&!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),ut(""),q(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=>{ut(oe.target.value),q(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"}),bt&&s.jsx("p",{className:"typography-micro text-[var(--status-error)]",children:bt}),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),ut(""),q(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 hm(t){return t.trim().length>0}function fm(t){return t.trimEnd()}function xm(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 bi=()=>{try{const e=Gs.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},bm=800,vm=5e3,ym="__default__",ur=new Map,Zi=new Map,jm=1500,Bl=t=>t?.trim()||ym,wm=t=>{ur.delete(Bl(t))},us=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=bi(),r=Bl(n),i=Date.now(),l=ur.get(r)??0,g=e().entries.length>0||e().files.length>0;if(!a?.force&&g&&i-l<vm)return!0;const c=Zi.get(r);if(!a?.force&&c)return c;const v=(async()=>{t({isLoading:!0});try{const m=await vt(kn("/api/config/plugins",n),{headers:Ta(n)});if(!m.ok)throw new Error("Failed to load plugins");const y=await vi(m);return t({entries:y.entries??[],files:y.files??[],isLoading:!1}),ur.set(r,Date.now()),a?.force||e().loadRegistryInfo(),!0}catch(m){return console.error("[PluginsStore] Failed to load plugins:",m),t({isLoading:!1}),!1}})();Zi.set(r,v);try{return await v}finally{Zi.delete(r)}},loadRegistryInfo:async a=>{const n=Nm(a?.specs??e().entries.map(r=>r.spec));if(n.length===0)return t({isLoadingRegistry:!1}),!0;t({isLoadingRegistry:!0});try{const r=bi(),i={...e().registryInfo};for(const l of Sm(n)){const g=await vt(km(l,a?.force===!0,r),{headers:Ta(r)});if(!g.ok)throw new Error("Failed to load plugin registry info");const c=await vi(g);for(const v of c.results??[])i[v.spec]=v}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 vt(kn("/api/config/plugins/entry",r),{method:"POST",headers:ci(r),body:JSON.stringify(yo(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 vt(kn(`/api/config/plugins/entry/${encodeURIComponent(a)}`,g),{method:"PATCH",headers:ci(g),body:JSON.stringify(yo(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 vt(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=bi(),r=await vt(kn(`/api/config/plugins/file/${encodeURIComponent(a)}`,n),{headers:Ta(n)});if(!r.ok)throw new Error("Failed to read plugin file");return await vi(r)}catch(n){return console.error("[PluginsStore] Failed to read plugin file:",n),null}},createFile:async a=>da("Creating plugin file…",async n=>await vt(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 vt(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 vt(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 km(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 Nm(t){return Array.from(new Set(t.map(e=>e.trim()).filter(Boolean)))}function Sm(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>jm?(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 yo(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=bi(),i=await e(r),l=await vi(i).catch(()=>null);if(!i.ok)throw new Error(l?.error||"Failed to update plugin configuration");return wm(r),l?.requiresManualRestart?(await a().loadPlugins({force:!0}),{ok:!0,requiresManualRestart:!0,reloadFailed:l?.reloadFailed===!0,message:l?.message,warning:l?.warning}):bl(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??bm,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 vi(t){return await t.json()}const Cm=/^[a-z0-9][a-z0-9-_.]*\.(js|ts|mjs|cjs)$/;function Im(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 Pm=({open:t,onOpenChange:e,defaultScope:a="user"})=>{const{t:n}=tt(),r=us(k=>k.createEntry),i=us(k=>k.createFile),[l,g]=o.useState("npm"),[c,v]=o.useState(""),[m,y]=o.useState(""),[d,C]=o.useState(""),[f,P]=o.useState(""),[x,N]=o.useState(a),[u,A]=o.useState(!1),R=o.useCallback(()=>{v(""),y(""),C(""),P(""),N(a)},[a]);o.useEffect(()=>{t&&(g("npm"),R())},[t,R]);const I=k=>{k!==l&&(g(k),R())},w=o.useMemo(()=>Im(m),[m]),h=!w.ok,j=l==="file"&&d.trim()!==""&&!Cm.test(d.trim()),O=(l==="npm"||l==="path")&&c.trim()==="",T=l==="file"&&f.trim()==="",S=l==="file"&&d.trim()==="",M=u||h||l==="npm"&&O||l==="path"&&O||l==="file"&&(S||j||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:w.ok?w.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&&u||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=>v(k.target.value),placeholder:n("settings.plugins.page.field.spec.placeholder"),"aria-invalid":O?!1:void 0,disabled:u}),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:m,onChange:k=>y(k.target.value),rows:5,className:"font-mono",hasError:h,disabled:u}),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":j||void 0,disabled:u}),j&&s.jsx("p",{className:"typography-meta text-[var(--status-error)]",children:n("settings.plugins.validation.fileName")})]}),s.jsxs("div",{className:"flex flex-col gap-1.5",children:[s.jsx("label",{htmlFor:"plugin-content",className:"typography-ui-label text-foreground",children:n("settings.plugins.page.field.content")}),s.jsx(Ts,{id:"plugin-content",value:f,onChange:k=>P(k.target.value),rows:16,className:"font-mono",disabled:u})]})]}),s.jsxs("div",{className:"flex flex-col gap-1.5",children:[s.jsx("span",{className:"typography-ui-label text-foreground",children:n("settings.plugins.page.field.scope")}),s.jsx("div",{className:"flex items-center gap-4",children:["user","project"].map(k=>{const G=x===k,D=n(k==="user"?"settings.plugins.scope.user":"settings.plugins.scope.project");return s.jsxs("button",{type:"button",onClick:()=>N(k),disabled:u,className:"flex items-center gap-2 py-1 text-left disabled:opacity-50",children:[s.jsx(wr,{checked:G,onChange:()=>N(k),ariaLabel:D}),s.jsx("span",{className:fe("typography-ui-label font-normal",G?"text-foreground":"text-foreground/60"),children:D})]},k)})})]})]}),s.jsxs(ts,{children:[s.jsx(B,{size:"sm",variant:"ghost",onClick:()=>e(!1),disabled:u,children:n("settings.plugins.dialog.add.action.cancel")}),s.jsxs(B,{size:"sm",onClick:()=>{V()},disabled:M,children:[u?s.jsx(F,{name:"loader-4",className:"h-3.5 w-3.5 animate-spin"}):null,n("settings.plugins.dialog.add.action.submit")]})]})]})})},Am=t=>{const e=pt.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=us(n),{t:i}=tt();if(!r)return null;const l=Tm;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 v;return e[5]!==r.currentVersion||e[6]!==r.latestVersion||e[7]!==i||e[8]!==c?(v=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]=v):v=e[9],v}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 Tm(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=pt.c(26),{header:a,footer:n,children:r,className:i,variant:l}=t,g=l===void 0?"sidebar":l,c=cs(),v=o.useRef(null),[m,y]=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=v.current;if(!M){y(!1),C(!1);return}if(!(M.scrollHeight>M.clientHeight+1)){y(!1),C(!1);return}y(M.scrollTop>1),C(M.scrollTop+M.clientHeight<M.scrollHeight-1)},e[0]=x):x=e[0];const N=x;let u;e[1]===Symbol.for("react.memo_cache_sentinel")?(u=()=>{N()},e[1]=u):u=e[1];let A;e[2]!==r?(A=[r,N],e[2]=r,e[3]=A):A=e[3],o.useEffect(u,A);let R,I;e[4]===Symbol.for("react.memo_cache_sentinel")?(R=()=>{const M=v.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 w;e[6]!==f||e[7]!==i?(w=fe("flex h-full flex-col",f,i),e[6]=f,e[7]=i,e[8]=w):w=e[8];let h;e[9]!==r?(h=s.jsx(bs,{ref:v,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 j;e[11]!==P||e[12]!==m?(j=m&&s.jsx("div",{className:"pointer-events-none absolute inset-x-0 top-0 h-4",style:{background:`linear-gradient(to bottom, ${P} 0%, transparent 100%)`}}),e[11]=P,e[12]=m,e[13]=j):j=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]!==j?(T=s.jsxs("div",{className:"relative flex flex-1 min-h-0 flex-col",children:[h,j,O]}),e[17]=O,e[18]=h,e[19]=j,e[20]=T):T=e[20];let S;return e[21]!==n||e[22]!==a||e[23]!==T||e[24]!==w?(S=s.jsxs("div",{className:w,children:[a,T,n]}),e[21]=n,e[22]=a,e[23]=T,e[24]=w,e[25]=S):S=e[25],S},gr=t=>{const e=pt.c(23),{title:a,metadata:n,selected:r,onSelect:i,icon:l,actions:g,className:c}=t,v=r===void 0?!1:r,m=g&&g.length>0,y=v?"bg-interactive-selection":"hover:bg-interactive-hover";let d;e[0]!==c||e[1]!==y?(d=fe("group relative flex items-center rounded-md px-1.5 py-0.5 transition-all duration-200",y,c),e[0]=c,e[1]=y,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]!==m?(N=m&&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(Em)})]}),e[14]=g,e[15]=m,e[16]=N):N=e[16];let u;e[17]!==x||e[18]!==N?(u=s.jsxs("div",{className:"flex min-w-0 flex-1 items-center",children:[x,N]}),e[17]=x,e[18]=N,e[19]=u):u=e[19];let A;return e[20]!==d||e[21]!==u?(A=s.jsx("div",{className:d,children:u}),e[20]=d,e[21]=u,e[22]=A):A=e[22],A};function Em(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 Dm=t=>t.parsedKind==="npm"?"code-box":"folder",Mm=t=>{const e=pt.c(144),{onItemSelect:a,onAddClick:n}=t,{t:r}=tt(),{entries:i,files:l,selectedId:g,setSelected:c,deleteEntry:v,deleteFile:m,loadPlugins:y}=us(Us(Rm)),d=us(Lm),C=us(Om),f=us(Fm),P=us(Km),[x,N]=o.useState(null),[u,A]=o.useState(!1),[R,I]=o.useState(!1);let w,h;e[0]!==y?(w=()=>{y()},h=[y],e[0]=y,e[1]=w,e[2]=h):(w=e[1],h=e[2]),o.useEffect(w,h);let j,O;e[3]===Symbol.for("react.memo_cache_sentinel")?(j=()=>{const et=()=>I(!0);return window.addEventListener("openchamber:settings-open-plugin-add",et),()=>window.removeEventListener("openchamber:settings-open-plugin-add",et)},O=[],e[3]=j,e[4]=O):(j=e[3],O=e[4]),o.useEffect(j,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(zm),e[8]=i,e[9]=M):M=e[9];const V=M;let $;e[10]!==i?($=i.filter(Um),e[10]=i,e[11]=$):$=e[11];const k=$;let G;e[12]!==l?(G=l.filter(_m),e[12]=l,e[13]=G):G=e[13];const D=G;let L;e[14]!==l?(L=l.filter($m),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 yt=d[ft.spec];if(!yt||yt.kind!=="npm-ok"||!yt.hasUpdate||!yt.latestVersion)return;const Be=yt.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 ue;e[29]!==v||e[30]!==m||e[31]!==x||e[32]!==r?(ue=async()=>{if(!x)return;A(!0);const et=x.kind==="entry"?await v(x.id):await m(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]=v,e[30]=m,e[31]=x,e[32]=r,e[33]=ue):ue=e[33];const de=ue;let xe;e[34]!==z||e[35]!==te||e[36]!==d||e[37]!==g||e[38]!==r?(xe=et=>{const ft=d[et.spec],yt=ft?.kind==="npm-ok"&&ft.hasUpdate&&!!ft.latestVersion,Be=[];return yt&&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(Am,{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:Dm(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,yt)=>{const Be=yt===void 0?0:yt;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:pn,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 Ge=C?"size-4 animate-spin":"size-4";let be;e[61]!==Ge?(be=s.jsx(F,{name:"refresh",className:Ge}),e[61]=Ge,e[62]=be):be=e[62];let Z;e[63]!==C||e[64]!==ke||e[65]!==Oe||e[66]!==Ve||e[67]!==be?(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:be}),e[63]=C,e[64]=ke,e[65]=Oe,e[66]=Ve,e[67]=be,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 ve;e[71]!==r?(ve=r("settings.plugins.sidebar.actions.addTitle"),e[71]=r,e[72]=ve):ve=e[72];let ye;e[73]===Symbol.for("react.memo_cache_sentinel")?(ye=s.jsx(F,{name:"add",className:"size-4"}),e[73]=ye):ye=e[73];let Re;e[74]!==_||e[75]!==se||e[76]!==ve?(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:ve,children:ye}),e[74]=_,e[75]=se,e[76]=ve,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 je;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?(je=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]=je):je=e[97];let Ze;e[98]!==Ee||e[99]!==je?(Ze=s.jsx(Hl,{variant:"background",header:Ee,children:je}),e[98]=Ee,e[99]=je,e[100]=Ze):Ze=e[100];let me;e[101]!==R?(me=s.jsx(Pm,{open:R,onOpenChange:I}),e[101]=R,e[102]=me):me=e[102];const Ne=x!==null;let Le;e[103]!==u?(Le=et=>{!et&&!u&&N(null)},e[103]=u,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 W;e[107]!==Xe?(W=s.jsx($t,{children:Xe}),e[107]=Xe,e[108]=W):W=e[108];const we=x?.label??"";let Ie;e[109]!==r||e[110]!==we?(Ie=r("settings.plugins.sidebar.deleteDialog.description",{name:we}),e[109]=r,e[110]=we,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]!==W||e[115]!==Je?(ot=s.jsxs(_t,{children:[W,Je]}),e[114]=W,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 ut;e[118]!==r?(ut=r("settings.common.actions.cancel"),e[118]=r,e[119]=ut):ut=e[119];let bt;e[120]!==u||e[121]!==ut?(bt=s.jsx(B,{size:"sm",variant:"ghost",onClick:st,disabled:u,children:ut}),e[120]=u,e[121]=ut,e[122]=bt):bt=e[122];let q;e[123]!==u||e[124]!==r?(q=r(u?"settings.plugins.sidebar.actions.deleting":"settings.common.actions.delete"),e[123]=u,e[124]=r,e[125]=q):q=e[125];let qe;e[126]!==de||e[127]!==u||e[128]!==q?(qe=s.jsx(B,{size:"sm",variant:"destructive",onClick:de,disabled:u,children:q}),e[126]=de,e[127]=u,e[128]=q,e[129]=qe):qe=e[129];let nt;e[130]!==bt||e[131]!==qe?(nt=s.jsxs(ts,{children:[bt,qe]}),e[130]=bt,e[131]=qe,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]!==me||e[142]!==ht?(Lt=s.jsxs(s.Fragment,{children:[Ze,me,ht]}),e[140]=Ze,e[141]=me,e[142]=ht,e[143]=Lt):Lt=e[143],Lt};function Rm(t){return{entries:t.entries,files:t.files,selectedId:t.selectedId,setSelected:t.setSelected,deleteEntry:t.deleteEntry,deleteFile:t.deleteFile,loadPlugins:t.loadPlugins}}function Lm(t){return t.registryInfo}function Om(t){return t.isLoadingRegistry}function Fm(t){return t.loadRegistryInfo}function Km(t){return t.updateToLatest}function zm(t){return t.scope==="user"}function Um(t){return t.scope==="project"}function _m(t){return t.scope==="user"}function $m(t){return t.scope==="project"}const Vm=({entryId:t,spec:e})=>{const{t:a}=tt(),n=us(y=>y.registryInfo[e]),r=us(y=>y.updateToLatest),[i,l]=o.useState(!1);if(!n)return null;if(n.kind==="npm-ok"){if(!n.hasUpdate||!n.latestVersion)return null;const y=n.latestVersion,d=n.currentVersion??"",C=async()=>{l(!0);try{(await r(t)).ok?E.success(a("settings.plugins.toast.updatedToLatest",{version:y})):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:y})})]}),s.jsx(B,{variant:"default",size:"sm",onClick:()=>{C()},disabled:i,children:a("settings.plugins.registry.banner.updateAvailable.action",{latest:y})})]})}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)",v=g?"alert":"error-warning",m=(()=>{switch(n.kind){case"npm-missing-version":return a("settings.plugins.registry.banner.invalid.missingVersion");case"npm-missing-package":return a("settings.plugins.registry.banner.invalid.missingPackage");case"npm-malformed":return a("settings.plugins.registry.banner.invalid.malformed");case"path-missing":return a("settings.plugins.registry.banner.invalid.pathMissing");case"path-unreadable":return a("settings.plugins.registry.banner.invalid.pathUnreadable")}})();return s.jsxs("div",{className:"rounded-md border border-border bg-card p-3 flex items-start gap-3",children:[s.jsx(F,{name:v,className:"h-5 w-5 shrink-0 mt-0.5",style:{color:c}}),s.jsxs("div",{className:"flex-1 min-w-0",children:[s.jsx("p",{className:"typography-label",style:{color:c},children:a("settings.plugins.registry.banner.invalid.title")}),s.jsx("p",{className:"typography-micro text-muted-foreground mt-0.5",children:m})]})]})};function Bm(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 Gl(t){return!t||Object.keys(t).length===0?"":JSON.stringify(t,null,2)}function jo(t){return{mode:"entry",scope:t.scope,spec:t.spec,optionsJson:Gl(t.options),fileName:"",content:""}}function wo(t,e){return{mode:"file",scope:t.scope,spec:"",optionsJson:"",fileName:t.fileName,content:e}}const ko=t=>{const e=pt.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},Hm=()=>{const{t}=tt(),e=us(x=>x.selectedId),a=us(x=>x.entries),n=us(x=>x.files),r=us(x=>x.draft),i=us(x=>x.setDraft),l=us(x=>x.updateEntry),g=us(x=>x.updateFile),c=us(x=>x.readFile),v=o.useMemo(()=>e?a.find(x=>x.id===e)??null:null,[a,e]),m=o.useMemo(()=>e?n.find(x=>x.id===e)??null:null,[n,e]),[y,d]=o.useState(!1),[C,f]=o.useState(!1),P=o.useRef(new Map);if(o.useEffect(()=>{let x=!1;return v?(i(jo(v)),()=>{x=!0}):m?(f(!0),(async()=>{const N=await c(m.id);if(x)return;f(!1);const u=N?.content??"";P.current.set(m.id,u),i(wo(m,u))})(),()=>{x=!0}):(i(null),()=>{x=!0})},[v,m,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(v&&r&&r.mode==="entry"){const x=Bm(r.optionsJson),N=x.ok,u=r.spec!==v.spec||r.optionsJson!==Gl(v.options),A=()=>{i(jo(v))},R=async()=>{if(!N)return;const I=r.spec.trim();if(!I){E.error(t("settings.plugins.validation.specRequired"));return}d(!0);try{const w=await l(v.id,{spec:I,options:x.value});w.ok?w.reloadFailed?E.warning(w.message||t("settings.plugins.toast.reloadFailed"),{description:w.warning}):w.restartDeferred?E.success(t("settings.view.pendingRestart.saved")):E.success(w.message||t("settings.plugins.toast.updated")):E.error(w.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:v.scope,label:v.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(Vm,{entryId:v.id,spec:v.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:!u||!N||y,children:t("settings.plugins.page.action.save")}),s.jsx(B,{variant:"outline",size:"sm",onClick:A,disabled:!u||y,children:t("settings.plugins.page.action.discard")})]})]})]})}if(m&&r&&r.mode==="file"){const x=P.current.get(m.id)??"",N=r.content!==x||r.fileName!==m.fileName,u=()=>{(async()=>{f(!0);const I=(await c(m.id))?.content??"";f(!1),P.current.set(m.id,I),i(wo(m,I))})()},A=async()=>{d(!0);try{const R=await g(m.id,{content:r.content});R.ok?(P.current.set(m.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:m.scope,label:m.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:m.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||y||C,children:t("settings.plugins.page.action.save")}),s.jsx(B,{variant:"outline",size:"sm",onClick:u,disabled:y||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"})})})},Gm="<built-in>",za=t=>t?.path===Gm,hr=t=>!!t&&!za(t)&&t.renamable===!0,qm=t=>{const e=pt.c(157),{onItemSelect:a}=t,{t:n}=tt(),[r,i]=o.useState(null),[l,g]=o.useState(""),[c,v]=o.useState(null),[m,y]=o.useState(!1),[d,C]=o.useState(null),{selectedSkillName:f,setSelectedSkill:P,setSkillDraft:x,deleteSkill:N,renameSkill:u,getSkillDetail:A}=Hs(Us(Wm)),R=_s();let I;e[0]!==R?(I=Me=>jr(Me,R),e[0]=R,e[1]=I):I=e[1];const w=Hs(I),h=Hs(Jm);let j,O;e[2]!==h||e[3]!==R?(j=()=>{h(R)},O=[h,R],e[2]=h,e[3]=R,e[4]=j,e[5]=O):(j=e[4],O=e[5]),o.useEffect(j,O);let T;e[6]!==a||e[7]!==P||e[8]!==x||e[9]!==w?(T=()=>{let Me="new-skill",jt=1;for(;w.some(Q=>Q.name===Me);)Me=`new-skill-${jt}`,jt++;x({name:Me,scope:"user",source:"opencode",description:""}),P(Me),a?.()},e[6]=a,e[7]=P,e[8]=x,e[9]=w,e[10]=T):T=e[10];const S=T;let M;e[11]===Symbol.for("react.memo_cache_sentinel")?(M=async Me=>{za(Me)||v(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)){v(null);return}y(!0),await N(c.name,R)?(E.success(n("settings.skills.sidebar.toast.skillDeleted",{name:c.name})),v(null)):E.error(n("settings.skills.sidebar.toast.deleteSkillFailed")),y(!1)},e[12]=c,e[13]=N,e[14]=R,e[15]=n,e[16]=$):$=e[16];const k=$;let G;e[17]!==A||e[18]!==P||e[19]!==x||e[20]!==R||e[21]!==w||e[22]!==n?(G=async Me=>{if(za(Me))return;const jt=Me.name;let Q=1,pe=`${jt}-copy`;for(;w.some(Pe=>Pe.name===pe);)Q++,pe=`${jt}-copy-${Q}`;const De=await A(Me.name,R);if(!De){E.error(n("settings.skills.sidebar.toast.duplicateLoadFailed"));return}x({name:pe,scope:Me.scope||"user",source:Me.source||"opencode",description:(De.sources.md.fields.includes("description"),""),instructions:""}),P(pe)},e[17]=A,e[18]=P,e[19]=x,e[20]=R,e[21]=w,e[22]=n,e[23]=G):G=e[23];const D=G;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]!==u||e[28]!==P||e[29]!==R||e[30]!==w||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(w.some(Q=>Q.name===Me)){E.error(n("settings.skills.page.toast.skillExists"));return}await u(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]=u,e[28]=P,e[29]=R,e[30]=w,e[31]=n,e[32]=ee):ee=e[32];const U=ee;let re;e[33]!==w?(re=w.filter(Qm),e[33]=w,e[34]=re):re=e[34];const _=re;let H;e[35]!==w?(H=w.filter(Ym),e[35]=w,e[36]=H):H=e[36];const z=H;let K;e[37]===Symbol.for("react.memo_cache_sentinel")?(K=function(jt){const Q={},pe=[];for(const Pe of jt)Pe.group?(Q[Pe.group]||(Q[Pe.group]=[]),Q[Pe.group].push(Pe)):pe.push(Pe);const De=Object.keys(Q).sort(Zm).map(Pe=>({name:Pe,skills:[...Q[Pe]].sort(Xm)}));return pe.sort(eu),{sortedGroups:De,ungrouped:pe}},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 ue;e[40]!==z?(ue=te(z),e[40]=z,e[41]=ue):ue=e[41];const de=ue;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:`${pn} 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]!==w.length||e[49]!==n?(Ae=n("settings.skills.sidebar.total",{count:w.length}),e[48]=w.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]!==w.length||e[71]!==n||e[72]!==z?(ke=s.jsx(bs,{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:"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:jt,skills:Q}=Me;return s.jsx(dr,{label:jt,count:Q.length,storageKey:"project-skills",children:Q.map(pe=>s.jsx(di,{skill:pe,isSelected:f===pe.name,onSelect:()=>{P(pe.name),a?.()},onRename:()=>J(pe),onDelete:()=>V(pe),onDuplicate:()=>D(pe),isMenuOpen:d===pe.name,onMenuOpenChange:De=>C(De?pe.name:null)},pe.name))},jt)}),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:jt=>C(jt?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:jt,skills:Q}=Me;return s.jsx(dr,{label:jt,count:Q.length,storageKey:"user-skills",children:Q.map(pe=>s.jsx(di,{skill:pe,isSelected:f===pe.name,onSelect:()=>{P(pe.name),a?.()},onRename:()=>J(pe),onDelete:()=>V(pe),onDuplicate:()=>D(pe),isMenuOpen:d===pe.name,onMenuOpenChange:De=>C(De?pe.name:null)},pe.name))},jt)}),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:jt=>C(jt?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]=w.length,e[71]=n,e[72]=z,e[73]=ke):ke=e[73];const Oe=c!==null;let Ve;e[74]!==m?(Ve=Me=>{!Me&&!m&&v(null)},e[74]=m,e[75]=Ve):Ve=e[75];let Ge;e[76]!==n?(Ge=n("settings.skills.sidebar.deleteDialog.title"),e[76]=n,e[77]=Ge):Ge=e[77];let be;e[78]!==Ge?(be=s.jsx($t,{children:Ge}),e[78]=Ge,e[79]=be):be=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 ve;e[83]!==se?(ve=s.jsx(Vt,{children:se}),e[83]=se,e[84]=ve):ve=e[84];let ye;e[85]!==be||e[86]!==ve?(ye=s.jsxs(_t,{children:[be,ve]}),e[85]=be,e[86]=ve,e[87]=ye):ye=e[87];let Re;e[88]===Symbol.for("react.memo_cache_sentinel")?(Re=()=>v(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]!==m||e[92]!==Fe?(Ke=s.jsx(B,{size:"sm",className:"text-foreground hover:bg-interactive-hover hover:text-foreground",variant:"ghost",onClick:Re,disabled:m,children:Fe}),e[91]=m,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 je;e[96]!==k||e[97]!==m||e[98]!==Ee?(je=s.jsx(B,{size:"sm",onClick:k,disabled:m,children:Ee}),e[96]=k,e[97]=m,e[98]=Ee,e[99]=je):je=e[99];let Ze;e[100]!==Ke||e[101]!==je?(Ze=s.jsxs(ts,{children:[Ke,je]}),e[100]=Ke,e[101]=je,e[102]=Ze):Ze=e[102];let me;e[103]!==ye||e[104]!==Ze?(me=s.jsxs(zt,{className:"max-w-md",children:[ye,Ze]}),e[103]=ye,e[104]=Ze,e[105]=me):me=e[105];let Ne;e[106]!==Oe||e[107]!==Ve||e[108]!==me?(Ne=s.jsx(Kt,{open:Oe,onOpenChange:Ve,children:me}),e[106]=Oe,e[107]=Ve,e[108]=me,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 W;e[111]!==n?(W=n("settings.skills.sidebar.renameDialog.title"),e[111]=n,e[112]=W):W=e[112];let we;e[113]!==W?(we=s.jsx($t,{children:W}),e[113]=W,e[114]=we):we=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]!==we||e[121]!==ot?(st=s.jsxs(_t,{children:[we,ot]}),e[120]=we,e[121]=ot,e[122]=st):st=e[122];let ut;e[123]===Symbol.for("react.memo_cache_sentinel")?(ut=Me=>g(Me.target.value),e[123]=ut):ut=e[123];let bt;e[124]!==n?(bt=n("settings.skills.sidebar.renameDialog.placeholder"),e[124]=n,e[125]=bt):bt=e[125];let q;e[126]!==U?(q=Me=>{Me.key==="Enter"&&U()},e[126]=U,e[127]=q):q=e[127];let qe;e[128]!==l||e[129]!==bt||e[130]!==q?(qe=s.jsx(He,{value:l,onChange:ut,placeholder:bt,className:"text-foreground placeholder:text-muted-foreground",onKeyDown:q}),e[128]=l,e[129]=bt,e[130]=q,e[131]=qe):qe=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 yt;e[145]!==st||e[146]!==qe||e[147]!==ft?(yt=s.jsxs(zt,{children:[st,qe,ft]}),e[145]=st,e[146]=qe,e[147]=ft,e[148]=yt):yt=e[148];let Be;e[149]!==Le||e[150]!==yt?(Be=s.jsx(Kt,{open:Le,onOpenChange:Xe,children:yt}),e[149]=Le,e[150]=yt,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=pt.c(41),{skill:a,isSelected:n,onSelect:r,onDelete:i,onRename:l,onDuplicate:g,isMenuOpen:c,onMenuOpenChange:v}=t,{t:m}=tt();let y;e[0]===Symbol.for("react.memo_cache_sentinel")?(y=_a(),e[0]=y):y=e[0];const d=y;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,u]=o.useState(!1);let A;e[5]!==x||e[6]!==i||e[7]!==g||e[8]!==l||e[9]!==m?(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"}),m("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"}),m("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"}),m("settings.common.actions.delete")]})]}),e[5]=x,e[6]=i,e[7]=g,e[8]=l,e[9]=m,e[10]=A):A=e[10];const R=A,I=!f&&N,w=n?"bg-interactive-selection":"hover:bg-interactive-hover";let h;e[11]!==w?(h=fe("group relative flex items-center rounded-md px-1.5 py-1 transition-all duration-200 select-none",w),e[11]=w,e[12]=h):h=e[12];let j;e[13]!==f?(j=!d&&!f?D=>{D.preventDefault(),u(!0)}:void 0,e[13]=f,e[14]=j):j=e[14];let O;e[15]!==h||e[16]!==j?(O=s.jsx("div",{className:h,onContextMenu:j}),e[15]=h,e[16]=j,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]!==v||e[26]!==R?(M=f?null:s.jsxs(cn,{open:c,onOpenChange:D=>{D&&u(!1),v(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]=v,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(qn,{className:"w-fit min-w-20",children:R(Wn)}),e[34]=f,e[35]=R,e[36]=k):k=e[36];let G;return e[37]!==$||e[38]!==k||e[39]!==I?(G=s.jsxs(Qn,{open:I,onOpenChange:u,children:[$,k]}),e[37]=$,e[38]=k,e[39]=I,e[40]=G):G=e[40],G};function Wm(t){return{selectedSkillName:t.selectedSkillName,setSelectedSkill:t.setSelectedSkill,setSkillDraft:t.setSkillDraft,deleteSkill:t.deleteSkill,renameSkill:t.renameSkill,getSkillDetail:t.getSkillDetail}}function Jm(t){return t.loadSkills}function Qm(t){return t.scope==="project"}function Ym(t){return t.scope==="user"}function Zm(t,e){return t.localeCompare(e)}function Xm(t,e){return t.name.localeCompare(e.name)}function eu(t,e){return t.name.localeCompare(e.name)}const tu=()=>`custom:${Date.now()}-${Math.random().toString(16).slice(2)}`,su=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},nu=({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),v=_n(k=>k.loadDefaultGitIdentityId),[m,y]=o.useState(""),[d,C]=o.useState(""),[f,P]=o.useState(""),[x,N]=o.useState(null),[u,A]=o.useState(null),[R,I]=o.useState(!1),[w,h]=o.useState([]),[j,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,y(""),C(""),P(""),A(null),I(!1),h([]),O(null),v(),N(null),(async()=>{const k=await mn();N(k?k.skillCatalogs??[]:null)})())},[t,v]);const M=o.useMemo(()=>{const k=d.trim(),G=f.trim();return(x??[]).some(D=>{const L=(D.source||"").trim(),J=(D.subpath||"").trim();return L===k&&J===G})},[x,d,f]),V=async()=>{const k=d.trim();if(!k){E.error(a("settings.skills.catalog.add.toast.repositoryRequired"));return}m.trim()||y(su(k)),I(!1),A(null);const G=T.current+1;T.current=G;const D=await n({source:k,subpath:f.trim()||void 0,gitIdentityId:j||void 0});if(T.current!==G)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),!j&&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=m.trim(),G=d.trim(),D=f.trim();if(!k){E.error(a("settings.skills.catalog.add.toast.catalogNameRequired"));return}if(!G){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:tu(),label:k,source:G,...D?{subpath:D}:{},...j?{gitIdentityId:j}:{}};if(x===null){E.error(a("settings.skills.catalog.add.toast.saveFailed"));return}const J=[...x,L];try{if(!(await mt({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:m,onChange:k=>y(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")})]}),w.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:j||"",onValueChange:k=>{O(k),S()},children:[s.jsx(Ct,{className:"w-fit",children:s.jsx("span",{children:w.find(k=>k.id===j)?.name||a("settings.skills.catalog.shared.auth.chooseIdentity")})}),s.jsx(It,{align:"start",children:w.map(k=>s.jsx(at,{value:k.id,children:k.name},k.id))})]})]}):null,u!==null?s.jsx("div",{className:"typography-meta text-muted-foreground",children:a("settings.skills.catalog.add.scanResult",{count:u})}):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||!m.trim()||!d.trim(),children:a("settings.skills.catalog.add.actions.addCatalog")})]})]})})},au=t=>{const e=pt.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,v]=o.useState(g);let m,y;e[1]!==r||e[2]!==a?(m=()=>{if(!a)return;const Y={};for(const ne of r)Y[ne.skillName]="skip";v(Y)},y=[a,r],e[1]=r,e[2]=a,e[3]=m,e[4]=y):(m=e[3],y=e[4]),o.useEffect(m,y);let d;e[5]!==r?(d=Y=>{const ne={};for(const ue of r)ne[ue.skillName]=Y;v(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 u;e[14]!==l?(u=l("settings.skills.catalog.conflicts.description"),e[14]=l,e[15]=u):u=e[15];let A;e[16]!==u?(A=s.jsx(Vt,{children:u}),e[16]=u,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 w;e[24]!==I?(w=s.jsx("span",{className:"typography-meta text-muted-foreground",children:I}),e[24]=I,e[25]=w):w=e[25];let h;e[26]!==C?(h=()=>C("skip"),e[26]=C,e[27]=h):h=e[27];let j;e[28]!==l?(j=l("settings.skills.catalog.conflicts.actions.skipAll"),e[28]=l,e[29]=j):j=e[29];let O;e[30]!==h||e[31]!==j?(O=s.jsx(B,{variant:"outline",size:"xs",className:"!font-normal",onClick:h,children:j}),e[30]=h,e[31]=j,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]!==w||e[44]!==V?($=s.jsxs("div",{className:"flex items-center justify-between gap-2",children:[w,V]}),e[43]=w,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:ue=>v(de=>({...de,[ne.skillName]:ue})),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 G;e[53]!==k?(G=s.jsx("div",{className:"space-y-2",children:k}),e[53]=k,e[54]=G):G=e[54];let D;e[55]!==$||e[56]!==G?(D=s.jsxs("div",{className:"space-y-3",children:[$,G]}),e[55]=$,e[56]=G,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 ql(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 iu=t=>{const e=pt.c(124),{open:a,onOpenChange:n,item:r}=t,{t:i}=tt(),l=hn(ru),g=hn(ou),[c,v]=o.useState("user"),[m,y]=o.useState("opencode"),d=Gs(lu),C=Gs(cu),[f,P]=o.useState(null),[x,N]=o.useState(!1);let u;e[0]===Symbol.for("react.memo_cache_sentinel")?(u=[],e[0]=u):u=e[0];const[A,R]=o.useState(u),[I,w]=o.useState(null);let h,j;e[1]!==C||e[2]!==a?(h=()=>{a&&(v("user"),y("opencode"),P(C),N(!1),R([]),w(null))},j=[a,C],e[1]=C,e[2]=a,e[3]=h,e[4]=j):(h=e[3],j=e[4]),o.useEffect(h,j);let O;e[5]!==i?(O=je=>{switch(je){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=je=>{switch(je){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(je=>je.id===f)){V=f;break e}if(C&&d.some(je=>je.id===C)){V=C;break e}V=d[0]?.id??null}const $=V;let k;e:{if(c!=="project"){k=null;break e}const je=$;if(!je){k=null;break e}let Ze;if(e[9]!==je||e[10]!==d){let Ne;e[12]!==je?(Ne=Le=>Le.id===je,e[12]=je,e[13]=Ne):Ne=e[13],Ze=d.find(Ne),e[9]=je,e[10]=d,e[11]=Ze}else Ze=e[11];k=Ze?.path??null}const G=k;let D;e[14]!==l||e[15]!==r?.gitIdentityId||e[16]!==n||e[17]!==i?(D=async je=>{const Ze=await l({source:je.source,subpath:je.subpath,gitIdentityId:r?.gitIdentityId,scope:je.scope,targetSource:je.targetSource,selections:[{skillDir:je.skillDir}],conflictPolicy:"prompt",conflictDecisions:je.conflictDecisions},{directory:je.directoryOverride??null});if(Ze.ok){E.success(i("settings.skills.catalog.installSkill.toast.installed")),n(!1);return}if(Ze.error?.kind==="conflicts"){w({source:je.source,subpath:je.subpath,scope:je.scope,targetSource:je.targetSource,skillDir:je.skillDir,directoryOverride:je.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]!==m?(Y=Ua(c,m),e[40]=c,e[41]=m,e[42]=Y):Y=e[42];let ne;e[43]===Symbol.for("react.memo_cache_sentinel")?(ne=je=>{const Ze=ql(je);v(Ze.scope),y(Ze.source==="agents"?"agents":"opencode")},e[43]=ne):ne=e[43];let ue;e[44]!==c?(ue=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]=ue):ue=e[45];let de;e[46]!==m?(de=m==="agents"?s.jsx(F,{name:"robot-2",className:"h-3.5 w-3.5"}):null,e[46]=m,e[47]=de):de=e[47];let xe;e[48]!==T||e[49]!==c||e[50]!==m?(xe=T(Ua(c,m)),e[48]=T,e[49]=c,e[50]=m,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]!==ue||e[55]!==de||e[56]!==ae?(le=s.jsxs(Ct,{className:"w-fit gap-1.5",children:[ue,de,ae]}),e[54]=ue,e[55]=de,e[56]=ae,e[57]=le):le=e[57];let ge;e[58]!==M||e[59]!==T?(ge=Pr.map(je=>s.jsx(at,{value:je.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:[je.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"}),je.source==="agents"?s.jsx(F,{name:"robot-2",className:"h-3.5 w-3.5"}):null,s.jsx("span",{children:T(je.value)})]}),s.jsx("span",{className:"typography-micro text-muted-foreground ml-5",children:M(je.value)})]})},je.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:je=>P(je),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(du)})]})]}),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 Ge=g||!r.installable||c==="project"&&!G;let be;e[88]!==G||e[89]!==L||e[90]!==r.repoSource||e[91]!==r.repoSubpath||e[92]!==r.skillDir||e[93]!==c||e[94]!==m?(be=()=>{L({source:r.repoSource,subpath:r.repoSubpath,scope:c,targetSource:m,skillDir:r.skillDir,directoryOverride:G})},e[88]=G,e[89]=L,e[90]=r.repoSource,e[91]=r.repoSubpath,e[92]=r.skillDir,e[93]=c,e[94]=m,e[95]=be):be=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]!==Ge||e[100]!==be||e[101]!==Z?(se=s.jsx(B,{size:"sm",disabled:Ge,onClick:be,children:Z}),e[99]=Ge,e[100]=be,e[101]=Z,e[102]=se):se=e[102];let ve;e[103]!==Ve||e[104]!==se?(ve=s.jsxs(ts,{children:[Ve,se]}),e[103]=Ve,e[104]=se,e[105]=ve):ve=e[105];let ye;e[106]!==z||e[107]!==Ue||e[108]!==ve?(ye=s.jsxs(zt,{className:"max-w-md",children:[z,Ue,ve]}),e[106]=z,e[107]=Ue,e[108]=ve,e[109]=ye):ye=e[109];let Re;e[110]!==n||e[111]!==a||e[112]!==ye?(Re=s.jsx(Kt,{open:a,onOpenChange:n,children:ye}),e[110]=n,e[111]=a,e[112]=ye,e[113]=Re):Re=e[113];let Fe;e[114]!==I||e[115]!==L?(Fe=je=>{I&&(L({source:I.source,subpath:I.subpath,scope:I.scope,targetSource:I.targetSource,skillDir:I.skillDir,conflictDecisions:je,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(au,{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 ru(t){return t.installSkills}function ou(t){return t.isInstalling}function lu(t){return t.projects}function cu(t){return t.activeProjectId}function du(t){return s.jsx(at,{value:t.id,children:t.label||t.path},t.id)}const pu=/^[A-Za-z0-9_.-]+\/[A-Za-z0-9_.-]+$/,mu=t=>{const e=t.trim();return pu.test(e)?`https://github.com/${e}`:null},uu=t=>{const e=mu(t.repoSource);if(!e)return null;const a=[t.repoSubpath,t.skillDir].filter(Boolean).join("/");return a?`${e}/tree/HEAD/${a}`:e};let pi=null;const gu=t=>{const e=Sr();return(!pi||pi.locale!==e)&&(pi={locale:e,formatter:new Intl.NumberFormat(e,{notation:"compact"})}),pi.formatter.format(t)},hu=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)}},fu=t=>{const e=pt.c(50),{source:a,isActive:n,isLoading:r,skillsCount:i,onSelect:l,t:g}=t,c=a.stars??null;let v,m,y,d,C,f,P,x,N,u;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 w=a.repoUpdatedAt?hu(a.repoUpdatedAt):null;x="button",N=l,u=n;const h=n?"border-primary":"border-[var(--surface-subtle)] hover:border-[var(--interactive-border-hover)]";e[19]!==h?(m=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]=m):m=e[20],C="min-w-0 flex-1 block";let j;e[21]!==a.label?(j=s.jsx("span",{className:"typography-ui-label font-medium text-foreground truncate",children:a.label}),e[21]=a.label,e[22]=j):j=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]!==j||e[28]!==O?(f=s.jsxs("span",{className:"flex items-center gap-2",children:[j,O]}),e[27]=j,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],v="flex items-center gap-3 mt-1",e[32]!==c||e[33]!==g?(y=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"}),gu(c)]}),e[32]=c,e[33]=g,e[34]=y):y=e[34],d=w&&s.jsx("span",{className:"typography-micro text-muted-foreground",children:w.key==="common.relative.justNow"?g(w.key):g("settings.skills.catalog.page.source.updated",{time:g(w.key,{count:w.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]=v,e[10]=m,e[11]=y,e[12]=d,e[13]=C,e[14]=f,e[15]=P,e[16]=x,e[17]=N,e[18]=u}else v=e[9],m=e[10],y=e[11],d=e[12],C=e[13],f=e[14],P=e[15],x=e[16],N=e[17],u=e[18];let A;e[35]!==v||e[36]!==y||e[37]!==d?(A=s.jsxs("span",{className:v,children:[y,d]}),e[35]=v,e[36]=y,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]!==m||e[45]!==R||e[46]!==x||e[47]!==N||e[48]!==u?(I=s.jsx("button",{type:x,onClick:N,"aria-pressed":u,className:m,children:R}),e[44]=m,e[45]=R,e[46]=x,e[47]=N,e[48]=u,e[49]=I):I=e[49],I},xu=({mode:t,onModeChange:e,showModeTabs:a=!0})=>{const{t:n}=tt(),{sources:r,itemsBySource:i,selectedSourceId:l,setSelectedSource:g,loadCatalog:c,loadSource:v,isLoadingCatalog:m,isLoadingSource:y,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),[u,A]=o.useState(!1),[R,I]=o.useState(null),[w,h]=o.useState(!1),[j,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 v(U.id)}})(),()=>{J=!0}},[r,d,v]),o.useEffect(()=>{!l||d[l]||v(l)},[l,d,v]),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 mn();if(!L)return;const ee=(L.skillCatalogs??[]).filter(U=>U.id!==l);await mt({skillCatalogs:ee}),await c({refresh:!0}),O(!1)}finally{h(!1)}}},G=S?n("settings.skills.catalog.page.list.searchTitle"):V?.label??"",D=!S&&l!==null&&!d[l]&&(y||m);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(fu,{source:L,isActive:L.id===l,isLoading:y&&!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:G}),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?v(l,{refresh:!0}):c({refresh:!0})},disabled:m||y,title:n("settings.skills.catalog.page.actions.refreshTitle"),children:s.jsx(F,{name:"refresh",className:fe("h-3.5 w-3.5",(m||y)&&"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:w,title:n("settings.skills.catalog.page.actions.removeCatalogTitle"),children:s.jsx(F,{name:"delete-bin",className:"h-3.5 w-3.5"})})]})]}),D||y&&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=uu(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(nu,{open:x,onOpenChange:N}),s.jsx(iu,{open:u,onOpenChange:A,item:R}),s.jsx(Kt,{open:j,onOpenChange:L=>{w||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:w,children:n("settings.common.actions.cancel")}),s.jsx(B,{size:"sm",variant:"destructive",onClick:()=>{k()},disabled:w,children:n("settings.skills.catalog.page.actions.removeCatalog")})]})]})})]})},bu=()=>{const t=pt.c(1);let e;return t[0]===Symbol.for("react.memo_cache_sentinel")?(e=s.jsx(xu,{mode:"external",onModeChange:Nu,showModeTabs:!1}),t[0]=e):e=t[0],e},vu="SKILL.md",yu="h-[clamp(320px,58dvh,680px)] min-h-[260px] max-h-[calc(100dvh-220px)]",yi=(t,e)=>{const a=tp({description:t}).trimEnd(),n=e.trimStart();return`---
|
|
22
|
+
${a}
|
|
23
|
+
---${n?`
|
|
24
|
+
|
|
25
|
+
${n}`:`
|
|
26
|
+
`}`},ju=t=>typeof t=="object"&&t!==null&&!Array.isArray(t),Wl=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=sp(e[1]);if(ju(n)){const r=n.description;typeof r=="string"&&(a=r)}}catch{a=null}return{description:a,instructions:e[2].replace(/^\r?\n/,"")}},wu=(t,e)=>{const a=Wl(t);return yi(e,a.instructions)},ku=()=>{const{t}=tt(),{currentTheme:e}=Cr(),{selectedSkillName:a,getSkillByName:n,getSkillDetail:r,createSkill:i,updateSkill:l,skillDraft:g,setSkillDraft:c,setSelectedSkill:v}=Hs(Us(me=>({selectedSkillName:me.selectedSkillName,getSkillByName:me.getSkillByName,getSkillDetail:me.getSkillDetail,createSkill:me.createSkill,updateSkill:me.updateSkill,skillDraft:me.skillDraft,setSkillDraft:me.setSkillDraft,setSelectedSkill:me.setSelectedSkill}))),m=_s(),y=Hs(me=>jr(me,m)),d=a?n(a,m):null,C=!!(g&&g.name===a&&!d),f=!!(a&&!d&&!g),P=d?.path==="<built-in>";o.useEffect(()=>{f&&v(null)},[f,v]);const[x,N]=o.useState(""),[u,A]=o.useState("user"),[R,I]=o.useState("opencode"),[w,h]=o.useState(""),[j,O]=o.useState(""),[T,S]=o.useState(()=>yi("","")),[M,V]=o.useState("edit"),[$,k]=o.useState([]),[G,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(""),[ue,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()!==""||w.trim()!==""||j.trim()!==""||G.length>0:w!==re||j!==H,Oe=xe?ue!==Ae:Y.trim()!=="",Ve=o.useCallback(me=>{switch(me){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]),Ge=o.useCallback(me=>{switch(me){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(yi(Ne,Le)),_(""),z(""),k([]),D(g.pendingFiles||[])}else if(a&&d){U(!0);try{const Ne=await r(a,m);if(Ne){const Le=Ne.sources.md,Xe=Le.description||"",W=Le.instructions||"";h(Xe),O(W),S(yi(Xe,W)),_(Xe),z(W),k(Le.supportingFiles||[])}}catch(Ne){console.error("Failed to load skill details:",Ne)}finally{U(!1)}}})()},[d,C,a,m,y,g,r]);const be=ie(me=>me.editorFontSize),Z=o.useMemo(()=>{const me=[io(e,{fontSize:be})],Ne=zr(vu);return Ne&&me.push(Ne),me.push(oo.lineWrapping),me},[e,be]),se=o.useMemo(()=>{const me=Y.trim()||"supporting-file.md",Ne=Ic(me),Le=!!Ne&&Ne!=="markdown",Xe=[io(e,Le?{syntaxColors:!1,fontSize:be}:{fontSize:be})],W=zr(me);return W&&Xe.push(W),Le&&Ne&&Xe.push(np({language:Ne,themeName:e.metadata.id,theme:ip(e)})),Xe.push(oo.lineWrapping),Xe},[e,Y,be]),ve=o.useCallback(me=>{h(me),S(Ne=>wu(Ne,me))},[]),ye=o.useCallback(me=>{S(me);const Ne=Wl(me);h(Ne.description??""),O(Ne.instructions)},[]),Re=async()=>{const me=C?x.trim().replace(/\s+/g,"-").toLowerCase():a?.trim();if(!me){E.error(t("settings.skills.page.toast.skillNameRequired"));return}if(!/^[a-z0-9][a-z0-9-]*[a-z0-9]$|^[a-z0-9]$/.test(me)||me.length>64){E.error(t("settings.skills.page.toast.invalidSkillName"));return}if(!w.trim()){E.error(t("settings.skills.page.toast.descriptionRequired"));return}if(C&&y.some(Ne=>Ne.name===me)){E.error(t("settings.skills.page.toast.skillExists"));return}J(!0);try{const Ne={name:me,description:w.trim(),instructions:j.trim()||void 0,scope:C?u:void 0,source:C?R:void 0,targetPath:C?void 0:d?.path,supportingFiles:C&&G.length>0?G:void 0};let Le;if(C?(Le=await i(Ne,m),Le&&(c(null),D([]),v(me))):(Le=await l(me,Ne,m),Le&&(_(w.trim()),z(j.trim()))),Le){const Xe=Vn.getState().changes.some(W=>W.scope==="skills"&&W.id.startsWith(`skills:${me}:`));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 me=>{if(ae(me),ne(me),C){const Le=G.find(Xe=>Xe.path===me)?.content||"";de(Le),Se(Le),te(!0);return}if(a){ge(!0),te(!0);try{const{readSupportingFile:Ne}=Hs.getState(),Le=await Ne(a,me,m);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 me=Y.trim(),Ne=xe!==null;if(C){if(Ne)D(W=>W.map(we=>we.path===xe?{path:me,content:ue}:we)),E.success(t("settings.skills.page.toast.fileUpdated",{path:me}));else{if(G.some(W=>W.path===me)){E.error(t("settings.skills.page.toast.fileExists"));return}D(W=>[...W,{path:me,content:ue}]),E.success(t("settings.skills.page.toast.fileAdded",{path:me}))}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,me,ue,m)){E.success(Ne?t("settings.skills.page.toast.fileUpdated",{path:me}):t("settings.skills.page.toast.fileCreated",{path:me})),te(!1),ae(null);const W=await r(a,m);W&&k(W.sources.md.supportingFiles||[])}else E.error(t(Ne?"settings.skills.page.toast.updateFileFailed":"settings.skills.page.toast.createFileFailed"))},je=me=>{if(C){D(Ne=>Ne.filter(Le=>Le.path!==me)),E.success(t("settings.skills.page.toast.fileRemoved",{path:me}));return}a&&he(me)},Ze=async()=>{if(!Ce||!a)return;Ue(!0);const{deleteSupportingFile:me}=Hs.getState();if(await me(a,Ce,m)){E.success(t("settings.skills.page.toast.fileDeleted",{path:Ce}));const Le=await r(a,m);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:me=>N(me.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(u,R),onValueChange:me=>{const Ne=ql(me);A(Ne.scope),I(Ne.source==="agents"?"agents":"opencode")},children:[s.jsxs(Ct,{size:Ft,className:"w-fit gap-1.5",children:[u==="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(u,R))})]}),s.jsx(It,{align:"start",children:Pr.map(me=>s.jsx(at,{value:me.value,children:s.jsxs("div",{className:"flex flex-col gap-0.5",children:[s.jsxs("div",{className:"flex items-center gap-2",children:[me.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"}),me.source==="agents"?s.jsx(F,{name:"robot-2",className:"h-3.5 w-3.5"}):null,s.jsx("span",{children:Ve(me.value)})]}),s.jsx("span",{className:"typography-micro text-muted-foreground ml-6",children:Ge(me.value)})]})},me.value))})]})]}),s.jsx(Wt,{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:w,onChange:me=>ve(me.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(ap,{currentMode:M==="preview"?"preview":"edit",onToggle:()=>V(me=>me==="preview"?"edit":"preview")}),settingsItem:"skills.instructions",children:s.jsx("div",{className:fe("overflow-hidden rounded-md border border-[var(--surface-subtle)] bg-background",yu),children:M==="preview"?s.jsx(bs,{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:ye,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 me=C?G:$;return me.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:me.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(),je(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:me=>{!me&&!_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:me=>{te(me),me||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:me=>ne(me.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:ue,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=pt.c(2),{view:a}=t,n=a===void 0?"installed":a;let r;return e[0]!==n?(r=n==="catalog"?s.jsx(bu,{}):s.jsx(ku,{}),e[0]=n,e[1]=r):r=e[1],r};function Nu(){}const Su=t=>{const e=pt.c(38),{onItemSelect:a}=t,{t:n}=tt(),r=Gs(Cu),i=ie(Iu),l=ie(Pu),{currentTheme:g}=Cr();let c;e[0]===Symbol.for("react.memo_cache_sentinel")?(c=cs(),e[0]=c):c=e[0];const v=c,m=Au;let y,d;e[1]!==r||e[2]!==i||e[3]!==l?(y=()=>{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]=y,e[5]=d):(y=e[4],d=e[5]),o.useEffect(y,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:`${pn} 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 u;e[16]!==n?(u=!v&&s.jsx(B,{type:"button",variant:"ghost",size:"icon",className:"h-7 w-7 -my-1 text-muted-foreground",onClick:m,"aria-label":n("settings.projects.sidebar.actions.addProject"),children:s.jsx(F,{name:"add",className:"size-4"})}),e[16]=n,e[17]=u):u=e[17];let A;e[18]!==N||e[19]!==u?(A=s.jsxs("div",{className:"flex items-center justify-between gap-2",children:[N,u]}),e[18]=N,e[19]=u,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=j=>{const O=j.id===i,T=j.icon?Tc[j.icon]:null,S=j.color?Ec[j.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=j.iconImage?s.jsx("span",{className:"inline-flex h-4 w-4 items-center justify-center overflow-hidden rounded-[2px]",style:j.iconBackground?{backgroundColor:j.iconBackground}:void 0,children:s.jsx(Dc,{project:j,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:j.label||j.path,icon:V,selected:O,onSelect:()=>{l(j.id),a?.()}},j.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 w;return e[35]!==R||e[36]!==I?(w=s.jsx(Hl,{variant:"background",header:R,children:I}),e[35]=R,e[36]=I,e[37]=w):w=e[37],w};function Cu(t){return t.projects}function Iu(t){return t.settingsProjectsSelectedId}function Pu(t){return t.setSettingsProjectsSelectedId}function Au(){Ac.requestDirectoryDialog()}const Tu=()=>{const t=pt.c(30),{t:e}=tt(),a=Gs(Eu),n=Gs(Du),r=ie(Mu),i=ie(Ru);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,v;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)},v=[a,r,i],t[3]=a,t[4]=r,t[5]=i,t[6]=c,t[7]=v):(c=t[6],v=t[7]),o.useEffect(c,v);let m;t[8]!==g||t[9]!==n?(m=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]=m):m=t[10];const y=m;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 u;t[15]!==N?(u=s.jsx("p",{className:"typography-meta text-muted-foreground",children:N}),t[15]=N,t[16]=u):u=t[16];let A;return t[17]!==x||t[18]!==u?(A=s.jsx(es,{title:x,showSaveStatus:!0,children:u}),t[17]=x,t[18]=u,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]!==y||t[24]!==g?(f=s.jsx(qd,{project:g,onIdentitySave:y}),t[23]=y,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 Eu(t){return t.projects}function Du(t){return t.updateProjectMeta}function Mu(t){return t.settingsProjectsSelectedId}function Ru(t){return t.setSettingsProjectsSelectedId}const ji=()=>Math.floor(2e4+Math.random()*3e4),Lu=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")},Ou=()=>{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.installingOpenChamber";case"updating":return"settings.remoteInstances.page.phase.updatingOpenChamber";case"server_detecting":return"settings.remoteInstances.page.phase.detectingServer";case"server_starting":return"settings.remoteInstances.page.phase.startingServer";case"forwarding":return"settings.remoteInstances.page.phase.forwardingPorts";case"ready":return"settings.remoteInstances.sidebar.phase.ready";case"degraded":return"settings.remoteInstances.page.phase.reconnecting";case"error":return"settings.remoteInstances.sidebar.phase.error";default:return"settings.remoteInstances.sidebar.phase.idle"}},Fu=new Set(["config_resolved","auth_check","master_connecting","remote_probe","installing","updating","server_detecting","server_starting","forwarding"]),Ar=t=>!!(t&&Fu.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"}},Ku=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 openchamber port")?"externalPort":null:null},Ao={noRuntime:"settings.remoteInstances.page.error.hint.noRuntime",noOpencode:"settings.remoteInstances.page.error.hint.noOpencode"},zu=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",Uu=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}`,_u=()=>({id:`forward-${Date.now()}-${Math.random().toString(16).slice(2)}`,enabled:!0,type:"local",localHost:"127.0.0.1",localPort:ji(),remoteHost:"127.0.0.1",remotePort:80}),$u=t=>t.trim().replace(/\*/g,"host").replace(/\?/g,"x")||"user@host",Vs=t=>{const e=pt.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},Vu=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}`},Bu=t=>{const e=(t||"").trim();return!e||e==="0.0.0.0"||e==="::"?"127.0.0.1":e},Hu=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}),Gu=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&&!Gu(n)&&(e[n]=r)}return Object.keys(e).length>0?e:void 0},qu=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}},Wu=async()=>{const t=pa($a())||window.location.origin;if(!as()||!Va()||(await mn())?.desktopLanAccessActive!==!0)return t;const a=await Dl(),n=Jl();return!a||!n?t:`http://${a}:${n}`},mi=t=>{const e=t.trim();if(e)try{window.location.assign(e)}catch{window.location.href=e}},Ju=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}},Qu=()=>{const{t}=tt(),e=ie(b=>b.timeFormatPreference),{clientAuth:a}=Nl(),n=as(),r=As(b=>b.instances),i=As(b=>b.statusesById),l=As(b=>b.importCandidates),g=As(b=>b.isLoading),c=As(b=>b.isImportsLoading),v=As(b=>b.isSaving),m=As(b=>b.error),y=As(b=>b.load),d=As(b=>b.loadImports),C=As(b=>b.refreshStatuses),f=As(b=>b.upsertInstance),P=As(b=>b.createFromCommand),x=As(b=>b.removeInstance),N=As(b=>b.connect),u=As(b=>b.disconnect),A=As(b=>b.retry),R=ie(b=>b.settingsRemoteInstancesSelectedId),I=ie(b=>b.setSettingsRemoteInstancesSelectedId),w=o.useMemo(()=>R&&r.find(b=>b.id===R)||null,[r,R]),[h,j]=o.useState(null),[O,T]=o.useState(!1),[S,M]=o.useState(!1),[V,$]=o.useState(null),[k,G]=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,ue]=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(""),[Ge,be]=o.useState(""),[Z,se]=o.useState([]),[ve,ye]=o.useState(""),[Re,Fe]=o.useState(null),[Ke,Ee]=o.useState(!1),[je,Ze]=o.useState(!1),[me,Ne]=o.useState(null),[Le,Xe]=o.useState(""),[W,we]=o.useState(""),[Ie,Je]=o.useState(""),[ot,st]=o.useState([]),[ut,bt]=o.useState([]),[q,qe]=o.useState([]),[nt,lt]=o.useState(!1),[ht,Lt]=o.useState(""),[et,ft]=o.useState(null),[yt,Be]=o.useState(null),[Et,Me]=o.useState(null),[jt,Q]=o.useState(null),[pe,De]=o.useState(!1),[Pe,it]=o.useState(!1),[rt,We]=o.useState("configure"),[Pt,vs]=o.useState(!1),[Xt,Os]=o.useState("relay"),[qt,is]=o.useState(!0),[Ht,ys]=o.useState(null),gs=o.useMemo(()=>ut.filter(b=>!!b.revokedAt).length,[ut]),[hs,ds]=o.useState(!1),[Es,oe]=o.useState("saved"),[ct,xt]=o.useState(""),[Qt,Yt]=o.useState(""),[Bt,rs]=o.useState(""),[js,ss]=o.useState(!1);o.useEffect(()=>{y(),d()},[y,d]);const wt=o.useCallback(async()=>{Ce(!0),Fe(null);try{const b=await Wr();xe(b.hosts||[]),Ae(b.defaultHostId||"local")}catch(b){Fe(b instanceof Error?b.message:String(b))}finally{Ce(!1)}},[]);o.useEffect(()=>{wt()},[wt]);const At=o.useCallback(async(b,X=ge)=>{_e(!0),Fe(null);try{await Jr({hosts:b,defaultHostId:X,initialHostChoiceCompleted:!0}),xe(b),Ae(X)}catch(Te){Fe(Te instanceof Error?Te.message:String(Te))}finally{_e(!1)}},[ge]),Ut=o.useCallback(async()=>{const b=Qr(Oe);if(!b){Fe(t("desktopHostSwitcher.error.invalidUrl"));return}const X=b.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,...Ge.trim()?{clientToken:Ge.trim()}:{},...Xi(Z)?{requestHeaders:Xi(Z)}:{}};await At([Qe,...de],ge),ke(""),Ve(""),be(""),se([]),Ee(!1),b.redeemUrl&&mi(b.redeemUrl)},[ge,Z,de,Ue,Ge,Oe,At,t]),Ot=o.useCallback(async()=>{const b=xd(ve);if(!b){Fe(t("settings.remoteInstances.direct.error.invalidConnectLink"));return}const X=await bd().catch(()=>""),Te=JSON.stringify({pairingId:b.pairingId,secret:b.secret,clientLabel:b.label||"OpenChamber Desktop",clientKind:"desktop",deviceName:"OpenChamber Desktop",devicePlatform:Ou(),...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=[...b.candidates].sort((Nt,Ms)=>(Nt.type==="relay"?1:0)-(Ms.type==="relay"?1:0));let ps=null;for(const Nt of ks){if(Nt.type==="relay"){const On=vd({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){ps={kind:"relay",relay:{relayUrl:Nt.relayUrl,serverId:Nt.serverId,hostEncPubJwk:Nt.hostEncPubJwk},token:si};break}}catch{}finally{On.close()}continue}const Ms=pa(Nt.url);if(Ms)try{const On=await fetch(`${Ms}/api/client-auth/pairing/redeem`,Qe),ra=await Dt(On);if(ra){ps={kind:"direct",url:Ms,token:ra};break}}catch{}}if(!ps){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=b.candidates.find(Nt=>Nt.type==="relay"),Ws=ps.kind==="relay"?ps.relay:Ns?{relayUrl:Ns.relayUrl,serverId:Ns.serverId,hostEncPubJwk:Ns.hostEncPubJwk}:void 0,Sa=b.candidates.filter(Nt=>Nt.type!=="relay").map(Nt=>pa(Nt.url)).find(Nt=>!!Nt),Ln=ps.kind==="direct"?ps.url:Sa,{token:Ca}=ps,kt=Ln||(Ws?yd(Ws.serverId):null);if(!kt){Fe(t("desktopHostSwitcher.error.invalidUrl"));return}const Gt={url:kt,apiUrl:Ln||void 0,clientToken:Ca,...Ws?{relay:Ws}:{}},tn=de.find(Nt=>Ws?Nt.relay?.serverId===Ws.serverId:!Nt.relay&&pa(Nt.apiUrl||Nt.url)===kt);if(tn){const Nt=de.map(Ms=>Ms.id===tn.id?{...Ms,label:b.label||Ms.label,...Gt}:Ms);await At(Nt,ge)}else await At([{id:$s(),label:b.label||Ia(kt),...Gt},...de],ge);ye(""),Fe(null),Ze(!1)},[ve,ge,de,At,t]),ns=o.useCallback(async b=>{const X=de.filter(Qe=>Qe.id!==b);await At(X,ge===b?"local":ge),me===b&&Ne(null)},[ge,me,de,At]),Ds=o.useCallback(b=>{Ne(b.id),Xe(b.label),we(b.apiUrl||b.url),Je(b.clientToken||""),st(qu(b.requestHeaders)),Fe(null)},[]),Ai=o.useCallback(async()=>{if(!me)return;const b=Qr(W);if(!b){Fe(t("desktopHostSwitcher.error.invalidUrl"));return}const X=b.persistedUrl,Te=de.map(Qe=>Qe.id===me?{...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),b.redeemUrl&&mi(b.redeemUrl)},[ge,ot,Le,Ie,W,me,de,At,t]),Ti=o.useCallback(async()=>{const b=Qt.trim();if(!b){E.error(t("settings.remoteInstances.page.toast.sshCommandRequired"));return}const X=`ssh-${Date.now()}-${Math.random().toString(16).slice(2)}`;try{await P(X,b,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 b=>{await At(de,b)},[de,At]);o.useEffect(()=>{if(!n||de.length===0)return;let b=!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=pa(jd(X));if(!Qe)return[X.id,X.relay?await Te():{status:"unreachable",latencyMs:0}];const Dt=await wd(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=>{b||le(Object.fromEntries(X))}),()=>{b=!0}},[de,n]);const Fs=o.useCallback(async b=>{if(a){b?.silent||lt(!0),b?.silent||ft(null);try{const[X,Te]=await Promise.all([a.listClients(),a.listPendingPairings().catch(()=>null)]);bt(X),Te&&qe(Te)}catch(X){b?.silent||ft(X instanceof Error?X.message:String(X))}finally{b?.silent||lt(!1)}}},[a]),wa=o.useRef(!1);o.useEffect(()=>{if(!(!Pe||rt!=="result"||!Et)){if(q.some(b=>b.id===Et)){wa.current=!0;return}wa.current&&(Me(null),it(!1),ut.some(b=>b.pairingId===Et)&&E.success(t("settings.remoteInstances.clientAuth.addDevice.connectedToast")))}},[Pe,rt,Et,q,ut,t]);const Di=o.useCallback(async b=>{if(a)try{await a.cancelPairing(b),qe(X=>X.filter(Te=>Te.id!==b)),await Fs({silent:!0})}catch(X){ft(X instanceof Error?X.message:String(X))}},[a,Fs]);o.useEffect(()=>{if(!a)return;Fs();const b=window.setInterval(()=>{typeof document<"u"&&document.visibilityState!=="visible"||Fs({silent:!0})},5e3);return()=>window.clearInterval(b)},[a,Fs]);const Ga=o.useCallback(async()=>{if(a?.getPairingTransports)try{const Qe=await a.getPairingTransports();return{localUrl:Qe.local,lanUrl:Qe.lan,relayAvailable:Qe.relayAvailable}}catch{}const b=Jl(),X=b?`http://127.0.0.1:${b}`:Do(window.location.origin)?window.location.origin:null;let Te=null;try{const Qe=pa(await Wu());Te=Qe&&!Do(Qe)?Qe:null}catch{}return{localUrl:X,lanUrl:Te,relayAvailable:!0}},[a]),qa=o.useCallback(async()=>{ft(null),Be(null),Q(null),De(!1),Me(null),We("configure"),is(!0),it(!0);const b=await Ga();ys(b),Os(b.relayAvailable?"relay":b.lanUrl?"lan":"local")},[Ga]),Mi=o.useCallback(async()=>{if(!(!a?.createPairingSession||!Ht)){ft(null),vs(!0);try{const b=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=qt):qt&&Ht.lanUrl?(X=Ht.lanUrl,Te=!0):(Qe=!1,Te=!0);const{pairing:Dt,server:ks}=await a.createPairingSession({label:b,allowedClientKinds:["mobile","desktop"],serverUrl:X,includeRelay:Te,includeDirect:Qe}),ps=kd({pairingId:Dt.id,secret:Dt.secret,label:ks.label,fingerprint:Dt.fingerprint??void 0,expiresAt:Dt.expiresAt,candidates:ks.candidates}),$s=Nd(ps);Be($s),Q(await zl.toDataURL($s,{width:1024,margin:2,errorCorrectionLevel:"L"})),De(!1),wa.current=!1,Me(Dt.id),We("result"),await Fs({silent:!0})}catch(b){ft(b instanceof Error?b.message:String(b))}finally{vs(!1)}}},[a,Ht,Xt,qt,ht,Fs]),Ri=o.useCallback(()=>{yt&&Ka(yt).then(b=>{b.ok&&(De(!0),window.setTimeout(()=>De(!1),2e3))})},[yt]),Li=o.useCallback(async b=>{if(!a)return;const X=b.clientKind==="desktop-local";ft(null);try{if(await a.revokeClient(b.id),X&&as()){const Te=await Wr();await Jr({hosts:Te.hosts,defaultHostId:Te.defaultHostId,initialHostChoiceCompleted:Te.initialHostChoiceCompleted,localClientToken:null}),bt(Qe=>Qe.map(Dt=>Dt.id===b.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]),Wa=o.useCallback(async()=>{if(a){ft(null);try{await a.purgeRevokedClients(),await Fs()}catch(b){ft(b instanceof Error?b.message:String(b))}}},[a,Fs]);o.useEffect(()=>{j(w)},[w]),o.useEffect(()=>{ss(!1)},[R]),o.useEffect(()=>{if(!R)return;const b=window.setInterval(()=>{typeof document<"u"&&document.visibilityState!=="visible"||C()},2e3);return()=>{window.clearInterval(b)}},[C,R]),o.useEffect(()=>{let b=null,X=Date.now();const Te=()=>{const Dt=Date.now();Dt-X>=1e3&&(ue(Dt),X=Dt),b=requestAnimationFrame(Te)};(typeof document>"u"||document.visibilityState==="visible")&&(b=requestAnimationFrame(Te));const Qe=()=>{document.visibilityState==="visible"&&b===null?b=requestAnimationFrame(Te):document.visibilityState!=="visible"&&b!==null&&(cancelAnimationFrame(b),b=null)};return document.addEventListener("visibilitychange",Qe),()=>{document.removeEventListener("visibilitychange",Qe),b!==null&&cancelAnimationFrame(b)}},[]);const ws=R?i[R]:null,qs=ws?.phase,Zn=qs==="ready",un=qs==="degraded",xn=Ar(qs),Xs=Zn||(xn||un),Oi=ws?Math.max(0,ne-ws.updatedAtMs):0,Dn=un&&Oi>12e3,Xn=Io(qs),Mn=Xn==="error"?Ku(ws?.detail):null,ka=zu(Mn),Fi=o.useMemo(()=>!h||!w?!1:JSON.stringify(h)!==JSON.stringify(w),[h,w]),os=o.useCallback(b=>{j(X=>X&&b(X))},[]),Ki=o.useCallback(async()=>{if(!h)return;const b=Ju(h);if(!b.sshCommand.trim()){E.error(t("settings.remoteInstances.page.toast.sshCommandRequired"));return}if(b.remoteOpenchamber.mode==="external"&&!b.remoteOpenchamber.preferredPort){E.error(t("settings.remoteInstances.page.validation.externalPortRequired")),ss(!0);return}if(b.remoteOpenchamber.mode==="managed"&&b.remoteOpenchamber.bindHost==="0.0.0.0"&&!b.auth.openchamberPassword?.value?.trim()){E.error(t("settings.remoteInstances.page.validation.remoteLanNeedsPassword")),ss(!0),window.setTimeout(()=>gn.current?.focus(),0);return}if(!(b.localForward.bindHost==="0.0.0.0"&&!window.confirm(t("settings.remoteInstances.page.confirm.bindAllInterfaces")))){if(b.auth.sshPassword?.enabled&&b.auth.sshPassword.value?.trim()&&b.auth.sshPassword.store!=="settings"){const X=window.confirm(t("settings.remoteInstances.page.confirm.storeSshPasswordPlaintext"));b.auth.sshPassword.store=X?"settings":"never",X||(b.auth.sshPassword.value=void 0)}if(b.auth.openchamberPassword?.enabled&&b.auth.openchamberPassword.value?.trim()&&b.auth.openchamberPassword.store!=="settings"){const X=window.confirm(t("settings.remoteInstances.page.confirm.storeUiPasswordPlaintext"));b.auth.openchamberPassword.store=X?"settings":"never",X||(b.auth.openchamberPassword.value=void 0)}try{await f(b),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(b,X)=>{const Te=`ssh-${Date.now()}-${Math.random().toString(16).slice(2)}`;try{return await P(Te,`ssh ${X}`,b),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((b,X)=>{if(ds(!1),X){L(b),ee($u(b));return}ea(b,b)},[ea]),Ja=o.useMemo(()=>ki(l,ct,b=>[b.host,b.sshCommand]),[l,ct]),Ui=o.useCallback(b=>{const X=(b||"").trim();if(!X){E.error(t("settings.remoteInstances.page.toast.instanceUrlUnavailable"));return}mi(X)},[t]),Qa=o.useCallback(async()=>{const b=D,X=J.trim();if(b){if(!X){E.error(t("settings.remoteInstances.page.toast.destinationRequired"));return}re(!0);try{await ea(b,X)&&(L(null),ee(""))}finally{re(!1)}}},[ea,J,D,t]),sa=o.useCallback(async()=>{if(w)try{await N(w.id);return}catch(b){if(!Lu(b)||!window.confirm(t("settings.remoteInstances.sidebar.confirm.localPortInUseRetry")))throw b;const Te={...w,localForward:{...w.localForward,preferredLocalPort:ji()}};await f(Te),await N(Te.id),E.success(t("settings.remoteInstances.sidebar.toast.retriedWithRandomPort"))}},[N,w,t,f]),gn=o.useRef(null),Rn=o.useRef(null),Na=o.useCallback(async b=>{if(w){if(b==="localPort"){const X={...w,localForward:{...w.localForward,preferredLocalPort:ji()}};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(b==="uiPassword"){gn.current?.focus();return}Rn.current?.scrollIntoView({block:"center"})},0)}},[N,w,t,f]),bn=o.useCallback(async b=>(await Mc(b,600)).map(Te=>Hu(Te)),[]),na=o.useCallback(async()=>{if(h){T(!0),M(!0),$(null);try{const b=await bn(h.id);G(b)}catch(b){G([]),$(b instanceof Error?b.message:String(b))}finally{M(!1)}}},[h,bn]);o.useEffect(()=>{if(!O||!h)return;let b=!1;const X=async()=>{try{const Qe=await bn(h.id);b||(G(Qe),$(null))}catch(Qe){b||$(Qe instanceof Error?Qe.message:String(Qe))}};X();const Te=window.setInterval(()=>{typeof document<"u"&&document.visibilityState!=="visible"||X()},1e3);return()=>{b=!0,window.clearInterval(Te)}},[h,O,bn]);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(b=>{b.ok&&E.success(t("settings.remoteInstances.page.toast.logsCopied"))})},[ce,t]),aa=o.useCallback(async()=>{if(h)try{await Rc(h.id),G([]),E.success(t("settings.remoteInstances.page.toast.logsCleared"))}catch(b){E.error(t("settings.remoteInstances.page.toast.clearLogsFailed"),{description:b instanceof Error?b.message:String(b)})}},[h,t]),Ya=o.useCallback(async()=>{if(!ws?.localUrl){E.error(t("settings.remoteInstances.page.toast.instanceUrlUnavailable"));return}const b=ws.localUrl.trim();if(!b){E.error(t("settings.remoteInstances.page.toast.instanceUrlUnavailable"));return}mi(b)},[ws?.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.openchamberPassword?.value?.trim()){E.error(t("settings.remoteInstances.page.validation.remoteLanNeedsPassword")),ss(!0),window.setTimeout(()=>gn.current?.focus(),0);return}K(!0),(Xs?u(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,u,h,Zn,t]),Xa=o.useCallback(()=>{if(!h||xn)return;Y(!0),(un?u(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,u,h,xn,un,A,t]),ei=t(xn?"settings.remoteInstances.page.actions.connecting":un?Dn?"settings.remoteInstances.page.actions.reconnectNow":"settings.remoteInstances.page.actions.reconnecting":"settings.remoteInstances.sidebar.actions.retry"),ti=!z&&!te&&(qs==="error"||qs==="idle"||!qs||un&&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:()=>{qa()},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:()=>{Wa()},children:t("settings.remoteInstances.clientAuth.actions.clearRevoked")})}):null,nt&&ut.length===0&&q.length===0?s.jsx("p",{className:"typography-meta text-muted-foreground",children:t("settings.remoteInstances.clientAuth.state.loading")}):ut.length===0&&q.length===0?s.jsx("p",{className:"typography-meta text-muted-foreground",children:t("settings.remoteInstances.clientAuth.state.empty")}):s.jsxs(s.Fragment,{children:[q.map(b=>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:b.label||t("settings.remoteInstances.clientAuth.field.labelPlaceholder")}),b.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(b.id)},children:t("settings.common.actions.cancel")})]},`pending-${b.id}`)),ut.map(b=>{const X=b.clientKind==="desktop-local",Te=b.lastUsedAt?Date.parse(b.lastUsedAt):Number.NaN,Qe=!b.revokedAt&&(X||Number.isFinite(Te)&&Date.now()-Te<9e4),Dt=b.revokedAt?t("settings.remoteInstances.clientAuth.state.revoked"):Qe?b.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",b.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:b.label}),So(b.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(b.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&&!b.revokedAt?"text-[var(--status-success)]":"text-muted-foreground"),children:Dt})]})}),s.jsx(B,{type:"button",variant:"ghost",size:"xs",className:"!font-normal",onClick:()=>{Li(b)},disabled:!!b.revokedAt,children:t("settings.remoteInstances.clientAuth.actions.revoke")})]},b.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(b=>{const X=ae[b.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(b.label)}),ge===b.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",b.apiUrl&&"font-mono"),children:b.relay&&!b.apiUrl?t("mobile.connect.relay.badge"):Ia(b.apiUrl||b.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(b.id)},disabled:he||ge===b.id,"aria-label":t("desktopHostSwitcher.actions.setAsDefaultAria"),children:ge===b.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"})}),b.relay&&!b.apiUrl?null:s.jsxs(B,{type:"button",variant:"ghost",size:"xs",className:"!font-normal",onClick:()=>Ds(b),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(b.id)},disabled:he,children:[s.jsx(F,{name:"delete-bin",className:"h-3.5 w-3.5"}),t("settings.common.actions.delete")]})]})]})},b.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:b=>{b.preventDefault(),Ut()},children:[s.jsx(He,{className:"h-8",value:Ue,onChange:b=>ke(b.target.value),placeholder:t("settings.remoteInstances.direct.field.labelPlaceholder"),disabled:he}),s.jsx(He,{className:"h-8",value:Oe,onChange:b=>Ve(b.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:Ge,onChange:b=>be(b.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(b=>s.jsxs("div",{className:"flex w-full gap-2",children:[s.jsx(He,{className:"h-8 font-mono text-xs",value:b.name,onChange:X=>se(Te=>Te.map(Qe=>Qe.id===b.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:b.value,onChange:X=>se(Te=>Te.map(Qe=>Qe.id===b.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!==b.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"})})]},b.id)),s.jsxs(B,{type:"button",variant:"ghost",size:"xs",className:"!font-normal",onClick:()=>se(b=>[...b,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:!!me,onOpenChange:b=>{b||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:b=>{b.preventDefault(),Ai()},children:[s.jsx(He,{className:"h-8",value:Le,onChange:b=>Xe(b.target.value),placeholder:t("settings.remoteInstances.direct.field.labelPlaceholder"),disabled:he}),s.jsx(He,{className:"h-8",value:W,onChange:b=>we(b.target.value),placeholder:t("settings.remoteInstances.direct.field.urlPlaceholder"),disabled:he,autoFocus:!0}),s.jsx(He,{className:"h-8",value:Ie,onChange:b=>Je(b.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(b=>s.jsxs("div",{className:"flex w-full gap-2",children:[s.jsx(He,{className:"h-8 font-mono text-xs",value:b.name,onChange:X=>st(Te=>Te.map(Qe=>Qe.id===b.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:b.value,onChange:X=>st(Te=>Te.map(Qe=>Qe.id===b.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!==b.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"})})]},b.id)),s.jsxs(B,{type:"button",variant:"ghost",size:"xs",className:"!font-normal",onClick:()=>st(b=>[...b,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:je,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:b=>{b.preventDefault(),Ot()},children:[s.jsx(He,{className:"h-8",value:ve,onChange:b=>ye(b.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||!ve.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:b=>{b.preventDefault(),Mi()},children:[s.jsx(He,{className:"h-8",value:ht,onChange:b=>Lt(b.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(b=>{const X=Xt===b.key;return s.jsxs("div",{className:fe("flex items-start gap-2 py-0.5",b.available?"cursor-pointer":"opacity-45"),onClick:()=>{b.available&&Os(b.key)},role:"presentation",children:[s.jsx(wr,{checked:X,disabled:!b.available,onChange:()=>Os(b.key),ariaLabel:b.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:b.label}),s.jsx("p",{className:"typography-meta text-muted-foreground",children:b.hint})]})]},b.key)})}),Xt==="lan"?s.jsxs("label",{className:"flex w-fit cursor-pointer items-center gap-2 pt-1",children:[s.jsx(cr,{checked:qt,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:qt,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:[jt?s.jsx("div",{className:"flex justify-center",children:s.jsx("img",{src:jt,alt:t("settings.remoteInstances.clientAuth.qrAlt"),className:"w-full max-w-[420px] rounded-md bg-white p-4"})}):null,yt?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:yt}),s.jsxs(B,{type:"button",variant:"outline",size:"xs",className:"!font-normal shrink-0",onClick:Ri,children:[s.jsx(F,{name:pe?"check":"file-copy",className:fe("h-3.5 w-3.5",pe&&"text-[var(--status-success)]")}),t(pe?"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(b=>{const X=i[b.id],Te=b.nickname?.trim()||b.sshParsed?.destination||b.id,Qe=X?.phase,Dt=Qe==="ready",ks=Io(Qe),ps=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?u(b.id):N(b.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(b.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(b.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")]})]})]}),ps?s.jsx("p",{className:"typography-micro text-[var(--status-error)] break-words",children:ps}):null]},b.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:b=>xt(b.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(b=>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:[b.host,b.pattern?` ${t("settings.remoteInstances.page.import.patternSuffix")}`:""]}),s.jsx("div",{className:"typography-meta text-muted-foreground truncate",children:b.sshCommand})]}),s.jsx(B,{type:"button",variant:"outline",size:"xs",className:"!font-normal",onClick:()=>{zi(b.host,b.pattern)},children:t("settings.remoteInstances.page.addDialog.use")})]},`${b.source}:${b.host}`))})]}):s.jsxs("form",{className:"space-y-3",onSubmit:b=>{b.preventDefault(),Ti()},children:[s.jsx(He,{className:"h-8",value:Bt,onChange:b=>rs(b.target.value),placeholder:t("settings.remoteInstances.page.field.nicknamePlaceholder"),disabled:v}),s.jsx(He,{className:"h-8",value:Qt,onChange:b=>Yt(b.target.value),placeholder:t("settings.remoteInstances.page.field.sshCommandPlaceholder"),disabled:v,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:v,children:t("settings.common.actions.cancel")}),s.jsx(B,{type:"submit",size:"xs",className:"!font-normal",disabled:v||!Qt.trim(),children:t("settings.common.actions.create")})]})]})]})}):null,s.jsx(Kt,{open:!!D,onOpenChange:b=>{b||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:b=>{b.preventDefault(),Qa()},children:[s.jsx(He,{value:J,onChange:b=>ee(b.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",vn=en&&h.remoteOpenchamber.bindHost==="0.0.0.0",ia=vn&&!h.auth.openchamberPassword?.value?.trim(),$i=h.nickname?.trim()||h.sshParsed?.destination||h.id;return s.jsx(Kt,{open:!!h,onOpenChange:b=>{b||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(qs)}`}),s.jsx("span",{className:"text-foreground",children:t(Po(Xn))}),Xn==="connecting"?s.jsx("span",{children:t(Co(qs))}):null,ws?.localUrl?s.jsx("span",{className:"font-mono text-foreground/80",children:ws.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||un&&!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"&&ws?.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:ws.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,ws?.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:ws.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:b=>os(X=>({...X,sshCommand:b.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:b=>os(X=>({...X,nickname:b.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:b=>os(X=>({...X,remoteOpenchamber:{...X.remoteOpenchamber,mode:b==="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:js,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:js?"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:b=>{os(X=>({...X,connectionTimeoutSec:Number.isFinite(b)?b: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:b=>{os(X=>({...X,remoteOpenchamber:{...X.remoteOpenchamber,preferredPort:Number.isFinite(b)&&b>0?b:void 0}}))},onClear:()=>{os(b=>({...b,remoteOpenchamber:{...b.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:b=>os(X=>({...X,remoteOpenchamber:{...X.remoteOpenchamber,installMethod:b==="npm"||b==="bun"?b:"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:vn,onCheckedChange:b=>os(X=>({...X,remoteOpenchamber:{...X.remoteOpenchamber,bindHost:b?"0.0.0.0":"127.0.0.1"}})),"aria-label":t("settings.remoteInstances.page.field.remoteLanAccess")})]}),vn?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:b=>os(X=>({...X,remoteOpenchamber:{...X.remoteOpenchamber,keepRunning:b}}))})})]}):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:b=>{b==="0.0.0.0"&&!window.confirm(t("settings.remoteInstances.page.confirm.bindAllInterfaces"))||os(X=>({...X,localForward:{...X.localForward,bindHost:b==="localhost"||b==="0.0.0.0"?b:"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:b=>{os(X=>({...X,localForward:{...X.localForward,preferredLocalPort:Number.isFinite(b)&&b>0?b:void 0}}))},onClear:()=>{os(b=>({...b,localForward:{...b.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(b=>({...b,localForward:{...b.localForward,preferredLocalPort:ji()}})),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:b=>os(X=>({...X,auth:{...X.auth,sshPassword:{enabled:b.target.value.trim().length>0,value:b.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(vn?"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.openchamberPassword?.value||"",onChange:b=>os(X=>({...X,auth:{...X.auth,openchamberPassword:{enabled:b.target.value.trim().length>0,value:b.target.value,store:X.auth.openchamberPassword?.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((b,X)=>{const Te=kt=>{os(Gt=>({...Gt,portForwards:Gt.portForwards.map((tn,Nt)=>Nt===X?kt(tn):tn)}))},Qe=b.type==="remote"?"Local target":"Local listen",Dt=b.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=b.type==="remote"?"Remote listen":"Remote target",ps=b.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(b.localHost||"localhost",b.localPort),Ns=Eo(b.remoteHost||"localhost",b.remotePort),Ws=b.type==="local"&&typeof b.localPort=="number"&&b.localPort>0,Sa=Ws?`http://${Bu(b.localHost)}:${b.localPort}`:"",Ln=!!_[b.id],Ca=b.type==="local"?t("settings.remoteInstances.page.forwardType.local"):b.type==="remote"?t("settings.remoteInstances.page.forwardType.remote"):t("settings.remoteInstances.page.forwardType.dynamic");return s.jsxs(An,{open:Ln,onOpenChange:kt=>{H(Gt=>({...Gt,[b.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:Uu(b)}),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:b.enabled,onCheckedChange:kt=>Te(Gt=>({...Gt,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(Gt=>Gt.id!==b.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(Vu(b.type))})]})})}),s.jsxs(St,{value:b.type,onValueChange:kt=>Te(Gt=>({...Gt,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:b.localHost||"127.0.0.1",onChange:kt=>Te(Gt=>({...Gt,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:b.localPort,onValueChange:kt=>{Te(Gt=>({...Gt,localPort:Number.isFinite(kt)&&kt>0?kt:void 0}))},onClear:()=>{Te(kt=>({...kt,localPort:void 0}))},emptyLabel:t("settings.remoteInstances.page.field.auto")})]})]}),b.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:ps})}),s.jsxs("div",{className:"flex items-center gap-1.5",children:[s.jsx(He,{className:"h-7 w-32",value:b.remoteHost||"",onChange:kt=>Te(Gt=>({...Gt,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:b.remotePort,onValueChange:kt=>{Te(Gt=>({...Gt,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:b.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")})]}):b.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")})]})}),Ws?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]})]})})]},b.id)}),s.jsxs(B,{type:"button",variant:"outline",size:"xs",className:"!font-normal mt-1",onClick:()=>{const b=_u();os(X=>({...X,portForwards:[...X.portForwards,b]})),H(X=>({...X,[b.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||v,children:t("settings.common.actions.saveChanges")}),ws?.localUrl?s.jsxs(s.Fragment,{children:[s.jsxs(B,{type:"button",variant:"outline",size:"xs",className:"!font-normal",onClick:()=>{Ka(ws.localUrl||"").then(b=>{b.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,m?s.jsx("div",{className:"ml-auto typography-meta text-[var(--status-error)]",children:m}):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:b=>{b||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:b=>{b.preventDefault(),Qa()},children:[s.jsx(He,{value:J,onChange:b=>ee(b.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")})]})]})]})})]})})},Yu="__add_provider__",Zu=()=>{const t=fn.getDirectory();return typeof t=="string"&&t.trim().length>0?t.trim():null},Xu=({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=Gs(f=>f.activeProjectId),[g,c]=o.useState({}),v=o.useMemo(()=>a||Zu(),[l,a]),m=Ye(f=>f.loadProviders);o.useEffect(()=>{a&&m({directory:a,source:"settings:providers"})},[m,a]),o.useEffect(()=>{if(n.length===0){c({});return}let f=!1;return(async()=>{const x=n.map(async N=>{try{const u=v?`?directory=${encodeURIComponent(v)}`:"",A=await vt(`/api/provider/${encodeURIComponent(N.id)}/source${u}`,{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(w=>({...w,[N.id]:I}))}catch{}});await Promise.all(x)})(),()=>{f=!0}},[v,n]);const y="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",y),children:[s.jsxs("div",{className:"border-b px-3 pt-4 pb-3",children:[s.jsx("h2",{className:`${pn} 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(Yu),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(bs,{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=pt.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 v;e[0]!==c?(v=fe("group relative flex items-center rounded-md px-1.5 py-1 transition-all duration-200",c),e[0]=c,e[1]=v):v=e[1];let m;e[2]!==a.id?(m=s.jsx(Un,{providerId:a.id,className:"h-4 w-4 flex-shrink-0"}),e[2]=a.id,e[3]=m):m=e[3];const y=a.name||a.id;let d;e[4]!==y?(d=s.jsx("span",{className:"typography-ui-label font-normal truncate flex-1 min-w-0 text-foreground",children:y}),e[4]=y,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]!==m||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:[m,d,C]}),e[8]=r,e[9]=m,e[10]=d,e[11]=C,e[12]=f):f=e[12];let P;return e[13]!==a.id||e[14]!==v||e[15]!==f?(P=s.jsx("div",{className:v,children:f},g),e[13]=a.id,e[14]=v,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 pg(t){const e=t.trim();if(!e)return{};const n=e.match(og)?.[1]?.trim();return n?{env:n}:{key:e}}function mg(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)&&mg(t):!1}function zo(t){return t?.custom?.exists?"custom":t?.project?.exists?"project":"user"}function ug(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(v=>typeof v[0]=="string"&&typeof v[1]=="string").map(([v,m])=>({row:Ci(),key:v,value:m})),i=Array.isArray(t.models)?t.models:t.models&&typeof t.models=="object"?Object.entries(t.models).map(([v,m])=>({id:v,name:m&&typeof m=="object"&&"name"in m&&typeof m.name=="string"?m.name:v})):[],l=i.length>0?i.map(v=>({row:Ci(),id:typeof v?.id=="string"?v.id:"",name:typeof v?.name=="string"?v.name:typeof v?.id=="string"?v.id:""})):[Er()],g=Array.isArray(t.env)?t.env.find(v=>typeof v=="string"&&v.trim().length>0)?.trim():void 0,c=i.find(v=>"api"in v);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}=pg(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"),v=a?void 0:t.t("settings.providers.page.custom.error.name.required"),m=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}}),u=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:$}}),w=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])),j={providerID:c??P,name:v,baseURL:m,apiKey:d};return!c&&!P&&!v&&!m&&!d&&u&&w?{err:j,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:j,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=pt.c(234),{existingProviderIDs:a,disabledProviders:n,busy:r,mode:i,initialValues:l,allowExistingAuth:g,authFailureHint:c,onSubmit:v,onCancel:m,onDisconnect:y}=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:u}=tt(),A=P==="edit";let R;e[2]!==l?(R=()=>l??cg(),e[2]=l,e[3]=R):R=e[3];const[I,w]=o.useState(R);let h;e[4]===Symbol.for("react.memo_cache_sentinel")?(h={},e[4]=h):h=e[4];const[j,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),G=o.useRef(null);let D,L;e[7]!==l||e[8]!==A?(D=()=>{l&&(A&&G.current===l.providerID||(G.current=A?l.providerID:null,w(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=(wt,At)=>{w(Ut=>({...Ut,[wt]:At})),O(Ut=>({...Ut,[wt]:void 0}))},e[11]=J):J=e[11];const ee=J;let U;e[12]===Symbol.for("react.memo_cache_sentinel")?(U=(wt,At,Ut)=>{w(Ot=>({...Ot,models:Ot.models.map((ns,Ds)=>Ds===wt?{...ns,[At]:Ut}:ns)})),M(Ot=>{const ns=[...Ot];return ns[wt]={...ns[wt]??{},[At]:void 0},ns})},e[12]=U):U=e[12];const re=U;let _;e[13]===Symbol.for("react.memo_cache_sentinel")?(_=(wt,At,Ut)=>{w(Ot=>({...Ot,headers:Ot.headers.map((ns,Ds)=>Ds===wt?{...ns,[At]:Ut}:ns)})),k(Ot=>{const ns=[...Ot];return ns[wt]={...ns[wt]??{},[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]!==v||e[21]!==u?(z=async wt=>{if(wt.preventDefault(),f)return;const At=gg({form:I,t:((Ut,Ot)=>u(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 v(At.result)},e[14]=x,e[15]=f,e[16]=C,e[17]=a,e[18]=I,e[19]=A,e[20]=v,e[21]=u,e[22]=z):z=e[22];const K=z;let te;e[23]!==A||e[24]!==u?(te=u(A?"settings.providers.page.custom.editTitle":"settings.providers.page.custom.title"),e[23]=A,e[24]=u,e[25]=te):te=e[25];let Y;e[26]!==u?(Y=u("settings.providers.page.custom.description"),e[26]=u,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 ue;e[30]!==N?(ue=N?s.jsx("p",{className:"typography-meta text-[var(--status-warning)]",role:"status",children:N}):null,e[30]=N,e[31]=ue):ue=e[31];let de;e[32]!==u?(de=u("settings.providers.page.custom.field.providerID.label"),e[32]=u,e[33]=de):de=e[33];let xe;e[34]!==u?(xe=u("settings.providers.page.custom.field.providerID.info"),e[34]=u,e[35]=xe):xe=e[35];const ae=I.providerID;let le;e[36]===Symbol.for("react.memo_cache_sentinel")?(le=wt=>ee("providerID",wt.target.value),e[36]=le):le=e[36];let ge;e[37]!==u?(ge=u("settings.providers.page.custom.field.providerID.placeholder"),e[37]=u,e[38]=ge):ge=e[38];const Ae=!A,Se=A||f,Ce=!!j.providerID;let he;e[39]!==u?(he=u("settings.providers.page.custom.field.providerID.label"),e[39]=u,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]!==j.providerID?(Ue=j.providerID?s.jsx("p",{className:"mt-1 typography-meta text-[var(--status-error)]",children:j.providerID}):null,e[48]=j.providerID,e[49]=Ue):Ue=e[49];let ke;e[50]!==de||e[51]!==xe||e[52]!==_e||e[53]!==Ue?(ke=s.jsxs(Wt,{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]!==u?(Oe=u("settings.providers.page.custom.field.protocol.label"),e[55]=u,e[56]=Oe):Oe=e[56];let Ve;e[57]!==u?(Ve=u("settings.providers.page.custom.field.protocol.info"),e[57]=u,e[58]=Ve):Ve=e[58];const Ge=I.protocol;let be;e[59]===Symbol.for("react.memo_cache_sentinel")?(be=wt=>{wt in Tr&&w(At=>({...At,protocol:wt}))},e[59]=be):be=e[59];let Z;e[60]!==u?(Z=u("settings.providers.page.custom.field.protocol.label"),e[60]=u,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 ve;e[63]!==Z?(ve=s.jsx(Ct,{"aria-label":Z,className:"w-full",children:se}),e[63]=Z,e[64]=ve):ve=e[64];let ye;e[65]!==u?(ye=u("settings.providers.page.custom.field.protocol.openaiChat"),e[65]=u,e[66]=ye):ye=e[66];let Re;e[67]!==ye?(Re=s.jsx(at,{value:"openai-chat",children:ye}),e[67]=ye,e[68]=Re):Re=e[68];let Fe;e[69]!==u?(Fe=u("settings.providers.page.custom.field.protocol.openaiResponses"),e[69]=u,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]!==u?(Ee=u("settings.providers.page.custom.field.protocol.anthropicMessages"),e[73]=u,e[74]=Ee):Ee=e[74];let je;e[75]!==Ee?(je=s.jsx(at,{value:"anthropic-messages",children:Ee}),e[75]=Ee,e[76]=je):je=e[76];let Ze;e[77]!==Re||e[78]!==Ke||e[79]!==je?(Ze=s.jsxs(It,{children:[Re,Ke,je]}),e[77]=Re,e[78]=Ke,e[79]=je,e[80]=Ze):Ze=e[80];let me;e[81]!==f||e[82]!==I.protocol||e[83]!==ve||e[84]!==Ze?(me=s.jsxs(St,{value:Ge,onValueChange:be,disabled:f,children:[ve,Ze]}),e[81]=f,e[82]=I.protocol,e[83]=ve,e[84]=Ze,e[85]=me):me=e[85];let Ne;e[86]!==Oe||e[87]!==Ve||e[88]!==me?(Ne=s.jsx(Wt,{label:Oe,info:Ve,children:me}),e[86]=Oe,e[87]=Ve,e[88]=me,e[89]=Ne):Ne=e[89];let Le;e[90]!==u?(Le=u("settings.providers.page.custom.field.name.label"),e[90]=u,e[91]=Le):Le=e[91];let Xe;e[92]!==u?(Xe=u("settings.providers.page.custom.field.name.info"),e[92]=u,e[93]=Xe):Xe=e[93];const W=I.name;let we;e[94]===Symbol.for("react.memo_cache_sentinel")?(we=wt=>ee("name",wt.target.value),e[94]=we):we=e[94];let Ie;e[95]!==u?(Ie=u("settings.providers.page.custom.field.name.placeholder"),e[95]=u,e[96]=Ie):Ie=e[96];const Je=!!j.name;let ot;e[97]!==u?(ot=u("settings.providers.page.custom.field.name.label"),e[97]=u,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:W,onChange:we,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 ut;e[104]!==j.name?(ut=j.name?s.jsx("p",{className:"mt-1 typography-meta text-[var(--status-error)]",children:j.name}):null,e[104]=j.name,e[105]=ut):ut=e[105];let bt;e[106]!==Le||e[107]!==Xe||e[108]!==st||e[109]!==ut?(bt=s.jsxs(Wt,{label:Le,info:Xe,children:[st,ut]}),e[106]=Le,e[107]=Xe,e[108]=st,e[109]=ut,e[110]=bt):bt=e[110];let q;e[111]!==u?(q=u("settings.providers.page.custom.field.baseURL.label"),e[111]=u,e[112]=q):q=e[112];let qe;e[113]!==u?(qe=u("settings.providers.page.custom.field.baseURL.info"),e[113]=u,e[114]=qe):qe=e[114];const nt=I.baseURL;let lt;e[115]===Symbol.for("react.memo_cache_sentinel")?(lt=wt=>ee("baseURL",wt.target.value),e[115]=lt):lt=e[115];let ht;e[116]!==u?(ht=u("settings.providers.page.custom.field.baseURL.placeholder"),e[116]=u,e[117]=ht):ht=e[117];const Lt=!!j.baseURL;let et;e[118]!==u?(et=u("settings.providers.page.custom.field.baseURL.label"),e[118]=u,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 yt;e[125]!==j.baseURL?(yt=j.baseURL?s.jsx("p",{className:"mt-1 typography-meta text-[var(--status-error)]",children:j.baseURL}):null,e[125]=j.baseURL,e[126]=yt):yt=e[126];let Be;e[127]!==q||e[128]!==qe||e[129]!==ft||e[130]!==yt?(Be=s.jsxs(Wt,{label:q,info:qe,children:[ft,yt]}),e[127]=q,e[128]=qe,e[129]=ft,e[130]=yt,e[131]=Be):Be=e[131];let Et;e[132]!==u?(Et=u("settings.providers.page.custom.field.apiKey.label"),e[132]=u,e[133]=Et):Et=e[133];let Me;e[134]!==x||e[135]!==A||e[136]!==u?(Me=u(A&&x?"settings.providers.page.custom.field.apiKey.editInfo":"settings.providers.page.custom.field.apiKey.info"),e[134]=x,e[135]=A,e[136]=u,e[137]=Me):Me=e[137];const jt=I.apiKey;let Q;e[138]===Symbol.for("react.memo_cache_sentinel")?(Q=wt=>ee("apiKey",wt.target.value),e[138]=Q):Q=e[138];let pe;e[139]!==x||e[140]!==A||e[141]!==u?(pe=u(A&&x?"settings.providers.page.custom.field.apiKey.editPlaceholder":"settings.providers.page.custom.field.apiKey.placeholder"),e[139]=x,e[140]=A,e[141]=u,e[142]=pe):pe=e[142];const De=!!j.apiKey;let Pe;e[143]!==u?(Pe=u("settings.providers.page.custom.field.apiKey.label"),e[143]=u,e[144]=Pe):Pe=e[144];let it;e[145]!==I.apiKey||e[146]!==pe||e[147]!==De||e[148]!==Pe?(it=s.jsx(He,{type:"password",value:jt,onChange:Q,placeholder:pe,className:"h-8 rounded-md px-3 font-mono text-xs","aria-invalid":De,"aria-label":Pe}),e[145]=I.apiKey,e[146]=pe,e[147]=De,e[148]=Pe,e[149]=it):it=e[149];let rt;e[150]!==j.apiKey?(rt=j.apiKey?s.jsx("p",{className:"mt-1 typography-meta text-[var(--status-error)]",children:j.apiKey}):null,e[150]=j.apiKey,e[151]=rt):rt=e[151];let We;e[152]!==Et||e[153]!==Me||e[154]!==it||e[155]!==rt?(We=s.jsxs(Wt,{label:Et,info:Me,children:[it,rt]}),e[152]=Et,e[153]=Me,e[154]=it,e[155]=rt,e[156]=We):We=e[156];let Pt;e[157]!==te||e[158]!==ne||e[159]!==ue||e[160]!==ke||e[161]!==Ne||e[162]!==bt||e[163]!==Be||e[164]!==We?(Pt=s.jsxs(ze,{title:te,divider:!1,settingsItem:"providers.custom",contentClassName:Qs,children:[ne,ue,ke,Ne,bt,Be,We]}),e[157]=te,e[158]=ne,e[159]=ue,e[160]=ke,e[161]=Ne,e[162]=bt,e[163]=Be,e[164]=We,e[165]=Pt):Pt=e[165];let vs;e[166]!==u?(vs=u("settings.providers.page.custom.models.title"),e[166]=u,e[167]=vs):vs=e[167];let Xt;if(e[168]!==I.models||e[169]!==S||e[170]!==u){let wt;e[172]!==I.models.length||e[173]!==S||e[174]!==u?(wt=(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:u("settings.providers.page.custom.models.idLabel")}),s.jsx(He,{value:At.id,onChange:Ot=>re(Ut,"id",Ot.target.value),placeholder:u("settings.providers.page.custom.models.idPlaceholder"),className:"mt-1 h-8 rounded-md px-3 font-mono text-xs","aria-label":u("settings.providers.page.custom.models.idLabel")}),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:u("settings.providers.page.custom.models.nameLabel")}),s.jsx(He,{value:At.name,onChange:Ot=>re(Ut,"name",Ot.target.value),placeholder:u("settings.providers.page.custom.models.namePlaceholder"),className:"mt-1 h-8 rounded-md px-3","aria-label":u("settings.providers.page.custom.models.nameLabel")}),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||(w(Ot=>({...Ot,models:Ot.models.filter((ns,Ds)=>Ds!==Ut)})),M(Ot=>Ot.filter((ns,Ds)=>Ds!==Ut)))},"aria-label":u("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]=u,e[175]=wt):wt=e[175],Xt=I.models.map(wt),e[168]=I.models,e[169]=S,e[170]=u,e[171]=Xt}else Xt=e[171];let Os;e[176]===Symbol.for("react.memo_cache_sentinel")?(Os=()=>{w(xg),M(bg)},e[176]=Os):Os=e[176];let qt;e[177]!==u?(qt=u("settings.providers.page.custom.models.add"),e[177]=u,e[178]=qt):qt=e[178];let is;e[179]!==qt?(is=s.jsx(B,{type:"button",variant:"outline",size:"xs",className:"!font-normal",onClick:Os,children:qt}),e[179]=qt,e[180]=is):is=e[180];let Ht;e[181]!==vs||e[182]!==Xt||e[183]!==is?(Ht=s.jsxs(ze,{title:vs,contentClassName:Qs,children:[Xt,is]}),e[181]=vs,e[182]=Xt,e[183]=is,e[184]=Ht):Ht=e[184];let ys;e[185]!==u?(ys=u("settings.providers.page.custom.headers.title"),e[185]=u,e[186]=ys):ys=e[186];let gs;e[187]!==u?(gs=u("settings.providers.page.custom.headers.description"),e[187]=u,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]!==u){let wt;e[195]!==I.headers.length||e[196]!==$||e[197]!==u?(wt=(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:u("settings.providers.page.custom.headers.keyLabel")}),s.jsx(He,{value:At.key,onChange:Ot=>H(Ut,"key",Ot.target.value),placeholder:u("settings.providers.page.custom.headers.keyPlaceholder"),className:"mt-1 h-8 rounded-md px-3 font-mono text-xs","aria-label":u("settings.providers.page.custom.headers.keyLabel")}),$[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:u("settings.providers.page.custom.headers.valueLabel")}),s.jsx(He,{value:At.value,onChange:Ot=>H(Ut,"value",Ot.target.value),placeholder:u("settings.providers.page.custom.headers.valuePlaceholder"),className:"mt-1 h-8 rounded-md px-3 font-mono text-xs","aria-label":u("settings.providers.page.custom.headers.valueLabel")}),$[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||(w(Ot=>({...Ot,headers:Ot.headers.filter((ns,Ds)=>Ds!==Ut)})),k(Ot=>Ot.filter((ns,Ds)=>Ds!==Ut)))},"aria-label":u("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]=u,e[198]=wt):wt=e[198],ds=I.headers.map(wt),e[191]=I.headers,e[192]=$,e[193]=u,e[194]=ds}else ds=e[194];let Es;e[199]===Symbol.for("react.memo_cache_sentinel")?(Es=()=>{w(vg),k(yg)},e[199]=Es):Es=e[199];let oe;e[200]!==u?(oe=u("settings.providers.page.custom.headers.add"),e[200]=u,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]!==ys||e[205]!==hs||e[206]!==ds||e[207]!==ct?(xt=s.jsxs(ze,{title:ys,contentClassName:Qs,children:[hs,ds,ct]}),e[204]=ys,e[205]=hs,e[206]=ds,e[207]=ct,e[208]=xt):xt=e[208];let Qt;e[209]!==f||e[210]!==m||e[211]!==u?(Qt=m?s.jsx(B,{type:"button",variant:"outline",size:"xs",className:"!font-normal",onClick:m,disabled:f,children:u("settings.providers.page.custom.actions.back")}):null,e[209]=f,e[210]=m,e[211]=u,e[212]=Qt):Qt=e[212];let Yt;e[213]!==f||e[214]!==y||e[215]!==u?(Yt=y?s.jsx(B,{type:"button",variant:"destructive",size:"xs",className:"!font-normal",onClick:()=>{y()},disabled:f,children:u("settings.providers.page.actions.disconnect")}):null,e[213]=f,e[214]=y,e[215]=u,e[216]=Yt):Yt=e[216];let Bt;e[217]!==f||e[218]!==A||e[219]!==u?(Bt=u(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]=u,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 js;e[224]!==Qt||e[225]!==Yt||e[226]!==rs?(js=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]=js):js=e[227];let ss;return e[228]!==K||e[229]!==Pt||e[230]!==Ht||e[231]!==xt||e[232]!==js?(ss=s.jsxs("form",{onSubmit:K,className:"space-y-0",children:[Pt,Ht,xt,js]}),e[228]=K,e[229]=Pt,e[230]=Ht,e[231]=xt,e[232]=js,e[233]=ss):ss=e[233],ss};function xg(t){return{...t,models:[...t.models,Er()]}}function bg(t){return[...t,{}]}function vg(t){return{...t,headers:[...t.headers,Dr()]}}function yg(t){return[...t,{}]}const jg=(t,e)=>!!e&&t!=="claude-code",wg=/[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?wg.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({}),[v,m]=o.useState(""),y=o.useRef(null);o.useEffect(()=>()=>y.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,j,O)=>{const T=await Ka(h);if(T.ok){E.success(r(j));return}console.error("Failed to copy OAuth value:",T.error),E.error(r(O))},P=async(h,j)=>{const O=new AbortController;y.current?.abort(),y.current=O;try{const T=await fn.getSdkClient().provider.oauth.callback({providerID:t,method:h,...j?{code:j}:{}},{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{y.current===O&&(y.current=null)}},x=async(h,j)=>{l({phase:"authorizing",methodIndex:h});let O;try{const T=await fn.getSdkClient().provider.oauth.authorize({providerID:t,method:h,...Object.keys(j).length>0?{inputs:j}:{}});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&&jg(t,O.url)&&Pn(O.url),O.method==="code"){m(""),l({phase:"awaitingCode",methodIndex:h,authorization:O,submitting:!1});return}l({phase:"waiting",methodIndex:h,authorization:O}),await P(h)},N=h=>{const j=Sg(h.prompts);if(j.length===0){x(h.index,{});return}c(Ig(j)),l({phase:"prompting",methodIndex:h.index,prompts:j,error:null})},u=()=>{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=v.trim();h&&(l({...i,submitting:!0}),P(i.methodIndex,h))},R=()=>{y.current?.abort(),y.current=null,l(er)},I=h=>{const j=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:j,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:j,onChange:T=>O(T.target.value),placeholder:h.placeholder,className:"max-w-[24rem] text-xs"})]},h.key)},w=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 j=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")})]}),j&&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:u,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")})]})]}),j&&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")]}),j&&i.phase==="waiting"&&s.jsxs("div",{className:"space-y-3",children:[w(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")})]}),j&&i.phase==="awaitingCode"&&s.jsxs("div",{className:"space-y-3",children:[w(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:v,onChange:O=>m(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||v.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")})]})]}),j&&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(W=>Cl(W,e)),n=Ye(W=>W.selectedProviderId),r=Ye(W=>W.setSelectedProvider),i=Ye(W=>W.getModelMetadata),l=ie(W=>W.hiddenModels),g=ie(W=>W.toggleHiddenModel),c=ie(W=>W.hideAllModels),v=ie(W=>W.showAllModels),[m,y]=o.useState({}),[d,C]=o.useState(!1),[f,P]=o.useState({}),[x,N]=o.useState(null),[u,A]=o.useState(""),[R,I]=o.useState([]),[w,h]=o.useState(!1),[j,O]=o.useState(null),[T,S]=o.useState(""),[M,V]=o.useState(""),[$,k]=o.useState(!1),[G,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),[ue,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 W=!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(!W)return;y(sg(Ie.data))}catch(Ie){if(!W)return;console.error("Failed to load provider auth methods:",Ie),E.error(t("settings.providers.page.toast.authMethodsLoadFailed"))}finally{W&&C(!1)}})(),()=>{W=!1}},[n,t]),o.useEffect(()=>{if(!eg(le))return;let W=!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(!W)return;I(Mg(Ie.data))}catch(Ie){if(!W)return;console.error("Failed to load available providers:",Ie),O(t("settings.providers.page.state.unableToLoadProviderList"))}finally{W&&h(!1)}})(),()=>{W=!1}},[le,t]);const Se=o.useMemo(()=>new Set(a.map(W=>W.id)),[a]),Ce=o.useMemo(()=>R.filter(W=>!Se.has(W.id)).sort((W,we)=>{const Ie=(W.name||W.id).toLowerCase(),Je=(we.name||we.id).toLowerCase();return Ie.localeCompare(Je)}),[R,Se]);o.useEffect(()=>{n===Ea&&T&&T!==Kn&&!Ce.some(W=>W.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 W=G[n];if(!W)return;const we=a.find(ot=>ot.id===n),Ie=Fo({key:we?.key,authSourceExists:W.auth.exists,optionsApiKey:we?.options?.apiKey??null,envDeclared:Vo(we)}),Je=!!(we&&Ko(we,W));ig({hasCredentials:Ie,userDismissed:re===n,isEditableCustomProvider:Je})&&U(!0)},[n,G,a,re]),o.useEffect(()=>{if(!n||n===Ea)return;let W=!1;return(async()=>{try{const Ie=e?`?directory=${encodeURIComponent(e)}`:"",Je=await vt(`/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;!W&&st&&D(ut=>({...ut,[n]:st}))}catch(Ie){W||console.error("Failed to load provider sources:",Ie)}})(),()=>{W=!0}},[n,L,e,t]);const he=o.useCallback(()=>{J(W=>W+1)},[]),_e=o.useCallback(W=>{D(we=>{const Ie=we[W];return{...we,[W]:{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(W),he()},[he,r]),Ue=o.useCallback(async(W,we)=>{try{return await Il({scopes:[W],mode:"active"}),"reloaded"}catch(Ie){if(Ie?.requiresManualRestart===!0)return we&&$n(W,{id:we}),"manual-restart";throw Ie}},[]),ke=a.find(W=>W.id===n),Oe=n?G[n]:void 0,Ve=async W=>{const we=f[W]?.trim()??"";if(!we){E.error(t("settings.providers.page.toast.apiKeyRequired"));return}const Ie=`api:${W}`;N(Ie);try{if((await fn.getSdkClient().auth.set({providerID:W,auth:{type:"api",key:we}})).error)throw new Error(t("settings.providers.page.toast.apiKeySaveFailed"));E.success(t("settings.providers.page.toast.apiKeySaved")),P(ot=>({...ot,[W]:""})),await Ue("providers",W),_e(W)}catch(Je){console.error("Failed to save API key:",Je),E.error(t("settings.providers.page.toast.apiKeySaveFailed"))}finally{N(null)}},Ge=async W=>{const we=`custom:${W.providerID}`;N(we),ae(W.providerID),de(null);try{const Ie=hg(W);if(Ie&&(await fn.getSdkClient().auth.set(Ie)).error)throw new Error(t("settings.providers.page.toast.apiKeySaveFailed"));const Je=fg(W,{scope:H?Y??zo(G[H]):"user"}),ot=await vt(`/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:W.name})),S(""),z(null),te(null),ne(null),de(null),ae(null),await Ue("providers",W.providerID),_e(W.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)}},be=W=>t("settings.providers.page.auth.oauthMethodFallback",{index:String(W+1)}),Z=W=>{U(!1),ng(W)&&$n("providers",{id:W}),_e(W)},se=async W=>{const we=`disconnect:${W}`;N(we);try{const Ie=await vt(`/api/provider/${encodeURIComponent(W)}/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",W),_(null),he()}catch(Ie){console.error("Failed to disconnect provider:",Ie),E.error(t("settings.providers.page.toast.providerDisconnectFailed"))}finally{N(null)}},ve=async W=>{W&&(await se(W),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")}),w?s.jsx("p",{className:"typography-meta text-muted-foreground",children:t("settings.providers.page.state.loading")}):j?s.jsx("p",{className:"typography-meta text-muted-foreground",children:j}):s.jsxs(cn,{open:$,onOpenChange:W=>{k(W),W||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(W=>W.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:W=>W.preventDefault(),children:[s.jsxs("div",{className:"flex items-center gap-2 border-b border-[var(--surface-subtle)] px-3 py-2",onKeyDown:W=>W.stopPropagation(),children:[s.jsx(F,{name:"search",className:"h-4 w-4 text-muted-foreground"}),s.jsx("input",{type:"text",value:M,onChange:W=>V(W.target.value),onKeyDown:W=>W.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(bs,{outerClassName:"max-h-[240px]",className:"p-1",children:(()=>{const W=t("settings.providers.page.custom.optionLabel"),we=Oc([W,"other","custom"],M),Ie=ki(Ce,M,Je=>[Je.name||Je.id,Je.id]);return Ie.length===0&&!we?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)),we?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:W})]}),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:ue,onCancel:()=>{S(""),de(null),ae(null)},onDisconnect:ue&&xe?()=>{ve(xe)}:void 0,onSubmit:Ge}):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 W=m[T]??[],we=Ho(Oo(W),be),Ie=Lo(W);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,we.length>0?s.jsx($o,{providerId:T,methods:we,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 ye=Array.isArray(ke.models)?ke.models:[],Re=m[ke.id]??[],Fe=Ho(Oo(Re),be),Ke=Lo(Re),Ee=!!Oe,je=Ee&&Ko(ke,Oe),Ze=Fo({key:ke.key,authSourceExists:Oe?.auth.exists,optionsApiKey:ke.options?.apiKey??null,envDeclared:Vo(ke)}),me=tg(Ee,Ze,je),Ne=ag({modelCount:ye.length,sourcesLoaded:Ee,hasCredentials:Ze,isEditableCustomProvider:je}),Le=!Ke&&Fe.length>0?t("settings.providers.page.auth.useReconnectHint"):t("settings.providers.page.auth.incompleteHint"),Xe=ki(ye,u,W=>[typeof W?.name=="string"?W.name:"",typeof W?.id=="string"?W.id:""]);return Ae&&je&&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:ue,onCancel:()=>{z(null),te(null),ne(null),de(null),ae(null)},onDisconnect:()=>{ve(ke.id)},onSubmit:Ge})}):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:[je?s.jsx(B,{variant:"outline",size:"xs",className:"!font-normal",onClick:()=>{de(null),te(ug(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 W=!ee;U(W),_(W?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:W=>P(we=>({...we,[ke.id]:W.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)]}):me?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:["(",ye.length,")"]}),headerAction:s.jsxs("div",{className:"flex items-center gap-1",children:[s.jsx(B,{variant:"outline",size:"xs",className:"!font-normal",onClick:()=>{const W=ye.map(we=>typeof we?.id=="string"?we.id:"").filter(we=>we.length>0);c(ke.id,W)},children:t("settings.providers.page.actions.hideAll")}),s.jsx(B,{variant:"outline",size:"xs",className:"!font-normal",onClick:()=>v(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:u,onChange:W=>A(W.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(W=>{const we=typeof W?.id=="string"?W.id:"",Ie=typeof W?.name=="string"?W.name:we,Je=we?i(ke.id,we):void 0,ot=l.some(q=>q.providerID===ke.id&&q.modelID===we),st=Bo(Je?.limit?.context),ut=Bo(Je?.limit?.output),bt=[];return Je?.tool_call&&bt.push({key:"tools",icon:"tools",label:t("settings.providers.page.models.capability.toolCalling")}),Je?.reasoning&&bt.push({key:"reasoning",icon:"brain-ai-3",label:t("settings.providers.page.models.capability.reasoning")}),Je?.attachment&&bt.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||ut)&&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&&ut?" · ":"",ut?`${ut} ${t("settings.providers.page.models.tokenBadge.output")}`:""]}),bt.length>0&&s.jsx("div",{className:"flex items-center gap-1 flex-shrink-0",children:bt.map(({key:q,icon:qe,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:qe,className:"h-3 w-3"})},q))}),s.jsx("button",{type:"button",onClick:()=>g(ke.id,we),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"})})]})]})},we)})})]}):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=pt.c(75),{onItemSelect:a}=t,{t:n}=tt(),r=Zt(Fg),i=Zt(Kg),l=Zt(zg),g=Zt(Ug),c=Zt(_g),v=Zt($g),m=Zt(Vg),y=Zt(Bg);let d,C;e[0]!==y?(d=()=>{y()},C=[y],e[0]=y,e[1]=d,e[2]=C):(d=e[1],C=e[2]),o.useEffect(d,C);const f=Hg;let P;e[3]!==m?(P=ne=>{ne!=="usage"&&ne!=="remaining"||(m(ne),f({usageDisplayMode:ne}))},e[3]=m,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 u;e[6]!==n?(u=n("settings.usage.sidebar.title"),e[6]=n,e[7]=u):u=e[7];let A;e[8]!==u?(A=s.jsx("h2",{className:`${pn} mb-3`,children:u}),e[8]=u,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 w;e[14]!==g?(w=()=>g(),e[14]=g,e[15]=w):w=e[15];let h;e[16]!==n?(h=n("settings.usage.sidebar.actions.refreshAria"),e[16]=n,e[17]=h):h=e[17];let j;e[18]!==n?(j=n("settings.usage.sidebar.actions.refreshTitle"),e[18]=n,e[19]=j):j=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]!==j||e[27]!==S||e[28]!==w?(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:w,"aria-label":h,title:j,disabled:c,children:S})}),e[24]=c,e[25]=h,e[26]=j,e[27]=S,e[28]=w,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 G;e[37]!==n?(G=n("settings.usage.sidebar.field.displayModePlaceholder"),e[37]=n,e[38]=G):G=e[38];let D;e[39]!==G?(D=s.jsx(Ct,{className:"w-fit",children:s.jsx(Mt,{placeholder:G})}),e[39]=G,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]!==v?(_=s.jsxs(St,{value:v,onValueChange:x,children:[D,re]}),e[52]=x,e[53]=D,e[54]=re,e[55]=v,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 ue=r.find(Ae=>Ae.providerId===ne.id),de=Lg(ue?.usage),xe=Pl(de),ae=ne.id===i,le=ue?.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(bs,{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 mt(t)}catch(e){console.warn("Failed to save usage settings:",e)}}const Gg=t=>{const e=pt.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 v=c;let m;e[4]!==v?(m=v==="critical"?{backgroundColor:"var(--status-error)"}:v==="warn"?{backgroundColor:"var(--status-warning)"}:{backgroundColor:"var(--status-success)"},e[4]=v,e[5]=m):m=e[5];const y=m;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]!==y||e[9]!==C?(f={...y,width:C},e[8]=y,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=pt.c(44),{title:a,window:n,subtitle:r,showToggle:i,toggleEnabled:l,onToggle:g}=t,c=i===void 0?!1:i,v=l===void 0?!1:l,m=Zt(qg),y=ie(Wg),d=m==="remaining"?n.remainingPercent:n.usedPercent,C=m==="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]!==y||e[5]!==n.resetAt?(N=zc(n.resetAt,x,y),e[3]=x,e[4]=y,e[5]=n.resetAt,e[6]=N):N=e[6];const u=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]!==v?(I=c&&s.jsx(cr,{checked:v,onChange:ee=>g?.(ee),ariaLabel:"Show in dropdown"}),e[9]=g,e[10]=c,e[11]=v,e[12]=I):I=e[12];let w;e[13]!==R?(w=s.jsx("span",{className:"typography-ui-label text-foreground truncate",children:R}),e[13]=R,e[14]=w):w=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 j;e[17]!==w||e[18]!==h?(j=s.jsxs("div",{className:"min-w-0 flex flex-col",children:[w,h]}),e[17]=w,e[18]=h,e[19]=j):j=e[19];let O;e[20]!==j||e[21]!==I?(O=s.jsxs("div",{className:"min-w-0 flex-1 flex items-center gap-2",children:[I,j]}),e[20]=j,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(Gg,{percent:d,tonePercent:n.usedPercent,className:"h-1.5"}),e[28]=d,e[29]=n.usedPercent,e[30]=V):V=e[30];const $=u?`Resets ${u}`:"";let k;e[31]!==$?(k=s.jsx("span",{className:"typography-micro text-muted-foreground",children:$}),e[31]=$,e[32]=k):k=e[32];let G;e[33]!==C?(G=s.jsx("span",{className:"typography-micro text-muted-foreground",children:C}),e[33]=C,e[34]=G):G=e[34];let D;e[35]!==k||e[36]!==G?(D=s.jsxs("div",{className:"mt-1 flex items-center justify-between",children:[k,G]}),e[35]=k,e[36]=G,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 qg(t){return t.displayMode}function Wg(t){return t.timeFormatPreference}const Jg=`ssh exe.dev "ssh-key generate-api-key --label=openchamber --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),v=`/api/quota/credentials/${t}`;o.useEffect(()=>{vt(v).then(async d=>{if(!d.ok)throw new Error;const C=await d.json();r(C),l({})}).catch(()=>r({configured:!1}))},[v]);const m=async(d,C,f)=>{c(!0);try{const P=await vt(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)}},y=(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"&&y("cookie",a("settings.providers.page.openCodeGo.authCookie"),"aid=...; __Secure-session=..."),t==="exe-dev"&&y("usageToken",a("settings.providers.page.quotaCredentials.usageToken"),a("settings.providers.page.quotaCredentials.tokenPlaceholder")),t==="cursor"&&y("accessToken",a("settings.providers.page.quotaCredentials.accessToken"),a("settings.providers.page.quotaCredentials.tokenPlaceholder")),t==="cursor"&&y("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:()=>m(v,"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:()=>m(`${v}/validate`,"POST"),children:a("settings.providers.page.openCodeGo.validate")}),t==="cursor"&&s.jsx(B,{variant:"outline",size:"xs",disabled:g,onClick:()=>m(`${v}/import`,"POST"),children:a("settings.providers.page.actions.connect")}),n?.configured&&s.jsx(B,{variant:"destructive",size:"xs",disabled:g,onClick:()=>m(v,"DELETE"),children:a("settings.providers.page.openCodeGo.delete")})]})]})]})},Go=(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),v=Zt(D=>D.error),m=Zt(D=>D.refreshErrors),y=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,u=Ni.find(D=>D.id===n)?.name??n??t("settings.usage.sidebar.title"),A=x?.usage,R=n?m[n]:void 0,I=R?A?t("header.services.usageRefreshFailedStale",{error:R}):R:x?.configured&&!x.ok?x.error:null,w=n?y.includes(n):!1,h=n==="exe-dev"||n==="ollama-cloud"||n==="cursor",j=o.useCallback(D=>{if(!n)return;const L=D?Array.from(new Set([...y,n])):y.filter(J=>J!==n);d(L),mt({usageDropdownProviders:L})},[y,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};mt({usageSelectedModels:U})},[n,C,f]),G=n?C[n]??[]:[];return n?s.jsxs(es,{title:t("settings.usage.page.header.providerUsage",{provider:u}),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:Go(c,e)}):t("settings.usage.page.header.lastUpdated",{time:Go(c,e)}),showSaveStatus:!0,children:[s.jsx(ze,{divider:!1,settingsItem:"usage.work-status-panel",children:s.jsx(dt,{checked:w,onChange:j,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")}),(v||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??v})]}),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:u}),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=G.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],_=G.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=pt.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 v;e[3]===Symbol.for("react.memo_cache_sentinel")?(v={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]=v):v=e[3];let m;e[4]===Symbol.for("react.memo_cache_sentinel")?(m=[l,g,c,v,{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]=m):m=e[4];const y=m;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:pn,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(bs,{outerClassName:"flex-1 min-h-0",className:"space-y-3 px-3 py-2 overflow-x-hidden",children:y.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 u;return e[21]!==x||e[22]!==N?(u=s.jsxs("div",{className:"flex h-full flex-col bg-background",children:[x,N]}),e[21]=x,e[22]=N,e[23]=u):u=e[23],u};function eh(t){return t.selectedPromptId}function th(t){return t.setSelectedPromptId}const qo={"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"}]}},Wo=(t,e)=>Object.prototype.hasOwnProperty.call(t,e),sr=t=>t.endsWith(".visible"),sh=()=>{const{t}=tt(),e=o.useCallback(w=>t(w),[t]),a=xr(w=>w.selectedPromptId),[n,r]=o.useState(!0),[i,l]=o.useState({}),[g,c]=o.useState({}),[v,m]=o.useState({}),[y,d]=o.useState({}),[C,f]=o.useState(!1);o.useEffect(()=>{let w=!0;return(async()=>{r(!0);try{const j=await Wc();if(!w)return;l(j)}catch(j){console.warn("Failed to load magic prompts:",j),E.error(t("settings.magicPrompts.page.toast.loadFailed"))}finally{w&&r(!1)}})(),()=>{w=!1}},[t]);const P=qo[a]??qo["git.commit.generate"],x=o.useCallback(w=>Wo(i,w)?i[w]:Hi(w),[i]),N=o.useCallback(w=>g[w]??x(w),[g,x]),u=o.useCallback((w,h)=>{c(j=>j[w]===h?j:{...j,[w]:h})},[]),A=o.useCallback(async w=>{const h=N(w);if(sr(w)&&h.trim().length===0){E.error(t("settings.magicPrompts.page.toast.visiblePromptRequired"));return}m(j=>({...j,[w]:!0}));try{const j=h===Hi(w)?await _r(w):await Hc(w,h);l(j.overrides),E.success(t("settings.magicPrompts.page.toast.saved"))}catch(j){const O=j instanceof Error?j.message:String(j);E.error(t("settings.magicPrompts.page.toast.saveFailed"),{description:O})}finally{m(j=>({...j,[w]:!1}))}},[N,t]),R=o.useCallback(async w=>{d(h=>({...h,[w]:!0}));try{const h=await _r(w);l(h.overrides),c(j=>({...j,[w]:Hi(w)})),E.success(t("settings.magicPrompts.page.toast.resetSuccess"))}catch(h){const j=h instanceof Error?h.message:String(h);E.error(t("settings.magicPrompts.page.toast.resetFailed"),{description:j})}finally{d(h=>({...h,[w]:!1}))}},[t]),I=o.useCallback(async()=>{f(!0);try{const w=await Gc();l(w.overrides),c({}),E.success(t("settings.magicPrompts.page.toast.resetAllSuccess"))}catch(w){const h=w instanceof Error?w.message:String(w);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((w,h)=>{const j=qc(w.id),O=x(w.id),T=N(w.id),S=Wo(i,w.id),M=T!==O,V=sr(w.id)&&T.trim().length===0,$=v[w.id]===!0,k=y[w.id]===!0;return s.jsxs(ze,{title:e(w.titleKey),info:j.description,description:j.placeholders&&j.placeholders.length>0?`${t("settings.magicPrompts.page.placeholdersLabel")} ${j.placeholders.map(G=>`{{${G.key}}}`).join(", ")}`:void 0,divider:h>0,settingsItem:sr(w.id)?"magic-prompts.visible-prompt":"magic-prompts.instructions",contentClassName:"space-y-3",children:[s.jsx(Ts,{value:T,onChange:G=>u(w.id,G.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(w.id)},disabled:!S||$||k,children:t(k?"settings.magicPrompts.page.actions.resetting":"settings.magicPrompts.page.actions.resetToDefault")}),s.jsx(B,{size:"sm",onClick:()=>{A(w.id)},disabled:!M||$||k||V,children:t($?"settings.common.actions.saving":"settings.magicPrompts.page.actions.save")})]})]})]},w.id)})})},nh=t=>{const e=pt.c(89),{onItemSelect:a}=t,{t:n}=tt(),[r,i]=o.useState(null),[l,g]=o.useState(null),[c,v]=o.useState(null),{selectedSnippetName:m,snippets:y,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 u;e[3]!==a||e[4]!==d||e[5]!==C||e[6]!==y?(u=async()=>{const Se=new Set(y.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]=y,e[7]=u):u=e[7];const A=u;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 w;e[12]!==y?(w=[...y].sort(rh),e[12]=y,e[13]=w):w=e[13];const h=w;let j;e[14]===Symbol.for("react.memo_cache_sentinel")?(j=fe("flex h-full flex-col","bg-background"),e[14]=j):j=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:`${pn} mb-3`,children:O}),e[17]=O,e[18]=T):T=e[18];let S;e[19]!==y.length||e[20]!==n?(S=n("settings.snippets.sidebar.total",{count:y.length}),e[19]=y.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 G;e[30]!==M||e[31]!==k?(G=s.jsxs("div",{className:"flex items-center justify-between gap-2",children:[M,k]}),e[30]=M,e[31]=k,e[32]=G):G=e[32];let D;e[33]!==G||e[34]!==T?(D=s.jsxs("div",{className:"border-b px-3 pt-4 pb-3",children:[T,G]}),e[33]=G,e[34]=T,e[35]=D):D=e[35];let L;if(e[36]!==a||e[37]!==l||e[38]!==c||e[39]!==m||e[40]!==d||e[41]!==h||e[42]!==n){let Se;e[44]!==a||e[45]!==l||e[46]!==c||e[47]!==m||e[48]!==d||e[49]!==n?(Se=Ce=>s.jsxs(Qn,{open:c===Ce.name,onOpenChange:he=>v(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",m===Ce.name?"bg-interactive-selection":"hover:bg-interactive-hover"),onContextMenu:he=>{he.preventDefault(),v(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&&v(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(qn,{className:"w-fit min-w-20",children:s.jsxs(Wn,{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]=m,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]=m,e[40]=d,e[41]=h,e[42]=n,e[43]=L}else L=e[43];let J;e[51]!==L?(J=s.jsx(bs,{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 ue;e[69]!==ne?(ue=s.jsx(B,{size:"sm",variant:"ghost",onClick:Y,children:ne}),e[69]=ne,e[70]=ue):ue=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]!==ue||e[77]!==xe?(ae=s.jsxs(ts,{children:[ue,xe]}),e[76]=ue,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:j,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(j=>({selectedSnippetName:j.selectedSnippetName,snippets:j.snippets,snippetDraft:j.snippetDraft,setSnippetDraft:j.setSnippetDraft,updateSnippet:j.updateSnippet,createSnippet:j.createSnippet}))),g=o.useMemo(()=>e?a.find(j=>j.name===e||j.aliases.includes(e))??null:null,[e,a]),c=!!(n&&n.name===e&&!g),[v,m]=o.useState(""),[y,d]=o.useState("global"),[C,f]=o.useState(""),[P,x]=o.useState(""),[N,u]=o.useState(""),[A,R]=o.useState(!1),I=o.useRef(null);o.useEffect(()=>{if(c&&n){const j={draftName:n.name||"",draftScope:n.scope||"global",description:n.description||"",aliases:(n.aliases||[]).join(", "),content:n.content||""};m(j.draftName),d(j.draftScope),f(j.description),x(j.aliases),u(j.content),I.current=j}else if(g){const j={draftName:"",draftScope:"global",description:g.description??"",aliases:g.aliases.join(", "),content:g.content};f(j.description),x(j.aliases),u(j.content),I.current=j}},[g,c,e,n]);const w=o.useMemo(()=>{const j=I.current;return j?c&&v!==j.draftName||c&&y!==j.draftScope?!0:C!==j.description||P!==j.aliases||N!==j.content:!1},[P,N,C,v,y,c]),h=async()=>{const j=c?v.trim().replace(/\s+/g,"-"):e?.trim();if(!j){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(j,N,{aliases:O,description:C,scope:y}):await i(j,{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:v,onChange:j=>m(j.target.value),placeholder:t("settings.snippets.page.field.namePlaceholder"),className:"h-7 w-44 px-2"}),s.jsxs(St,{value:y,onValueChange:j=>d(j),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(Wt,{label:t("settings.common.field.description"),children:s.jsx(He,{value:C,onChange:j=>f(j.target.value),placeholder:t("settings.snippets.page.field.descriptionPlaceholder"),className:"h-7 w-full max-w-sm px-2"})}),s.jsx(Wt,{label:t("settings.snippets.page.field.aliases"),children:s.jsx(He,{value:P,onChange:j=>x(j.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:j=>u(j.target.value),placeholder:t("settings.snippets.page.field.contentPlaceholder"),rows:12,className:"mt-1.5 w-full font-mono typography-meta min-h-[160px] max-h-[60vh] bg-transparent"}),s.jsx("div",{className:"pt-3",children:s.jsx(B,{onClick:h,disabled:A||!w,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(y=>y.settingsGitmojiEnabled),a=Ye(y=>y.setSettingsGitmojiEnabled),n=Id(),r=ie(y=>y.gitChangesViewMode),i=ie(y=>y.setGitChangesViewMode),[l,g]=o.useState(!0),c=o.useMemo(()=>[{id:"flat",label:t("settings.openchamber.git.option.flatList")},{id:"tree",label:t("settings.openchamber.git.option.treeView")}],[t]);o.useEffect(()=>{(async()=>{try{const d=await mn();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 v=o.useCallback(async y=>{a(y);try{await mt({gitmojiEnabled:y})}catch(d){console.warn("Failed to save gitmoji setting:",d)}},[a]),m=o.useCallback(y=>{y!==r&&(i(y),mt({gitChangesViewMode:y}))},[r,i]);return l?null:s.jsx(ze,{title:t("settings.openchamber.git.title"),children:s.jsxs("div",{className:fs,children:[s.jsx(Ss,{settingsItem:"git.changes-view",title:t("settings.openchamber.git.changesViewTitle"),children:s.jsx(Js,{"aria-label":t("settings.openchamber.git.changesViewAria"),children:c.map(y=>s.jsx(Bs,{selected:r===y.id,onSelect:()=>{m(y.id)},label:y.label,ariaLabel:t("settings.openchamber.git.optionAria",{option:y.label})},y.id))})}),s.jsx(dt,{settingsItem:"git.gitmoji",checked:e,onChange:y=>{v(y)},label:t("settings.openchamber.git.enableGitmoji"),ariaLabel:t("settings.openchamber.git.enableGitmojiAria")}),s.jsx(dt,{settingsItem:"git.gitignored-files",checked:n,onChange:Pd,label:t("settings.openchamber.git.showGitignored"),ariaLabel:t("settings.openchamber.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),v=o.useMemo(()=>a&&a!=="new"&&!n?i(a):null,[a,i,n]),m=a==="new"||n!=null,y=a==="global",[d,C]=o.useState(""),[f,P]=o.useState(""),[x,N]=o.useState(""),[u,A]=o.useState("ssh"),[R,I]=o.useState(""),[w,h]=o.useState(!1),[j,O]=o.useState(""),[T,S]=o.useState(""),[M,V]=o.useState("keyword"),[$,k]=o.useState("branch"),[G,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(m)C(""),P(""),N(""),A("ssh"),I(""),h(!1),O(""),S(""),V("keyword"),k("branch");else if(v)C(v.name),P(v.userName),N(v.userEmail),A(v.authType||"ssh"),I(v.sshKey||""),h(v.signCommits===!0),O(v.signingKey||""),S(v.host||""),V(v.color||"keyword"),k(v.icon||"branch");else if(y){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,v,m,n,y,i]);const re=async()=>{if(!f.trim()||!x.trim()){E.error(r("settings.gitIdentities.editor.toast.userNameEmailRequired"));return}if(u==="token"&&!T.trim()){E.error(r("settings.gitIdentities.editor.toast.hostRequiredForToken"));return}if(w&&!j.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:u,sshKey:u==="ssh"&&R.trim()||null,signCommits:w,signingKey:j.trim()||null,host:u==="token"&&T.trim()||null,color:M,icon:$};let te;if(m)te=await l(K);else if(a)te=await g(a,K);else return;te?(E.success(r(m?"settings.gitIdentities.editor.toast.profileCreated":"settings.gitIdentities.editor.toast.profileUpdated")),e(!1)):E.error(r(m?"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||m)){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"):m?r("settings.gitIdentities.editor.title.newIdentity"):y?r("settings.gitIdentities.editor.title.globalIdentity"):v?.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(y?"settings.gitIdentities.editor.description.globalReadOnly":m?"settings.gitIdentities.editor.description.newProfile":"settings.gitIdentities.editor.description.editProfile")})]}),s.jsxs("div",{className:"space-y-5 py-2",children:[!y&&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)})})]})]}),!y&&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")}),!y&&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:!y,readOnly:y,disabled:y,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")}),!y&&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:!y,readOnly:y,disabled:y,className:"h-8"})]})]}),!y&&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":u==="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":u==="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")]})]})]}),u==="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:w,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:j,onChange:K=>O(K.target.value),placeholder:r("settings.gitIdentities.editor.field.signingKeyPlaceholder"),disabled:!w,className:"h-8 font-mono text-xs"})]})]}),u==="token"&&s.jsxs("div",{children:[s.jsxs("div",{className:"flex items-center gap-1.5 mb-1.5",children:[s.jsx("label",{className: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:[!y&&!m&&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(y?"settings.gitIdentities.editor.actions.close":"settings.common.actions.cancel")}),!y&&s.jsx(B,{size:"sm",onClick:re,disabled:G,children:r(G?"settings.common.actions.saving":m?"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:v?.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"},ph={keyword:"var(--syntax-keyword)",error:"var(--status-error)",string:"var(--syntax-string)",function:"var(--syntax-function)",type:"var(--syntax-type)"},mh=()=>{const t=pt.c(112),{t:e}=tt(),{profiles:a,globalIdentity:n,defaultGitIdentityId:r,deleteProfile:i,loadProfiles:l,loadGlobalIdentity:g,loadDiscoveredCredentials:c,loadDefaultGitIdentityId:v,setDefaultGitIdentityId:m,getUnimportedCredentials:y}=_n(Us(gh)),[d,C]=o.useState(!1),[f,P]=o.useState(null),[x,N]=o.useState(null),[u,A]=o.useState(null),[R,I]=o.useState(!1);let w,h;t[0]!==v||t[1]!==c||t[2]!==g||t[3]!==l?(w=()=>{l(),g(),c(),v()},h=[l,g,c,v],t[0]=v,t[1]=c,t[2]=g,t[3]=l,t[4]=w,t[5]=h):(w=t[4],h=t[5]),o.useEffect(w,h);let j,O,T,S,M,V,$,k,G,D,L,J,ee,U;if(t[6]!==r||t[7]!==u||t[8]!==i||t[9]!==y||t[10]!==n||t[11]!==a||t[12]!==m||t[13]!==e){const Ge=y();let be;t[28]===Symbol.for("react.memo_cache_sentinel")?(be=(Ee,je)=>{P(Ee),N(je??null),C(!0)},t[28]=be):be=t[28];const Z=be;let se;t[29]!==r||t[30]!==m||t[31]!==e?(se=async Ee=>{const je=r===Ee?null:Ee;if(!await m(je)){E.error(e("settings.gitIdentities.page.toast.updateDefaultFailed"));return}E.success(e(je?"settings.gitIdentities.page.toast.defaultUpdated":"settings.gitIdentities.page.toast.defaultUnset"))},t[29]=r,t[30]=m,t[31]=e,t[32]=se):se=t[32];const ve=se;let ye;t[33]!==u||t[34]!==i||t[35]!==e?(ye=async()=>{if(!u)return;I(!0),await i(u.id)?(E.success(e("settings.gitIdentities.page.toast.profileDeleted",{name:u.name})),A(null)):E.error(e("settings.gitIdentities.page.toast.deleteProfileFailed")),I(!1)},t[33]=u,t[34]=i,t[35]=e,t[36]=ye):ye=t[36],T=ye,O=es,t[37]!==e?(M=e("settings.page.git.title"),t[37]=e,t[38]=M):M=t[38],V=!0,j=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:()=>ve("global"),isReadOnly:!0,hasBorder:a.length>0||Ge.length>0}),G=a.map((Ee,je)=>s.jsx(Qo,{profile:Ee,isDefault:r===Ee.id,onEdit:()=>Z(Ee.id),onToggleDefault:()=>ve(Ee.id),onDelete:()=>A(Ee),hasBorder:je<a.length-1||Ge.length>0},Ee.id)),D=!n&&a.length===0&&Ge.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=Ge.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")})}),Ge.map((Ee,je)=>s.jsx(uh,{credential:Ee,onImport:()=>Z("new",{host:Ee.host,username:Ee.username}),hasBorder:je<Ge.length-1},`${Ee.host}-${Ee.username}`))]}),t[6]=r,t[7]=u,t[8]=i,t[9]=y,t[10]=n,t[11]=a,t[12]=m,t[13]=e,t[14]=j,t[15]=O,t[16]=T,t[17]=S,t[18]=M,t[19]=V,t[20]=$,t[21]=k,t[22]=G,t[23]=D,t[24]=L,t[25]=J,t[26]=ee,t[27]=U}else j=t[14],O=t[15],T=t[16],S=t[17],M=t[18],V=t[19],$=t[20],k=t[21],G=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]!==G||t[50]!==D||t[51]!==L?(re=s.jsxs("div",{className:$,children:[k,G,D,L]}),t[47]=$,t[48]=k,t[49]=G,t[50]=D,t[51]=L,t[52]=re):re=t[52];let _;t[53]!==j||t[54]!==S||t[55]!==re||t[56]!==J||t[57]!==ee||t[58]!==U?(_=s.jsx(j,{title:J,divider:ee,headerAction:U,settingsItem:S,children:re}),t[53]=j,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=u!==null;let Y;t[70]!==R?(Y=Ge=>{R||Ge||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 ue;t[74]!==ne?(ue=s.jsx($t,{children:ne}),t[74]=ne,t[75]=ue):ue=t[75];const de=u?.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]!==ue||t[82]!==ae?(le=s.jsxs(_t,{children:[ue,ae]}),t[81]=ue,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=pt.c(56),{profile:a,isDefault:n,onEdit:r,onToggleDefault:i,onDelete:l,isReadOnly:g,hasBorder:c}=t,{t:v}=tt(),[m,y]=o.useState(!1),d=dh[a.icon||"branch"]||"git-branch",C=ph[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]!==v?(N=_=>s.jsxs(s.Fragment,{children:[s.jsx(_,{onClick:H=>{H.stopPropagation(),i()},children:v(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"}),v("settings.common.actions.delete")]})]}),e[2]=n,e[3]=g,e[4]=l,e[5]=i,e[6]=v,e[7]=N):N=e[7];const u=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(),y(!0)},e[10]=I):I=e[10];let w;e[11]!==x||e[12]!==r||e[13]!==R?(w=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]=w):w=e[14];let h;e[15]!==C?(h={color:C},e[15]=C,e[16]=h):h=e[16];let j;e[17]!==d||e[18]!==h?(j=s.jsx(F,{name:d,className:"w-4 h-4 shrink-0",style:h}),e[17]=d,e[18]=h,e[19]=j):j=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]!==v?(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:v("settings.gitIdentities.page.badge.default")}),e[24]=n,e[25]=v,e[26]=S):S=e[26];let M;e[27]!==g||e[28]!==v?(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:v("settings.agents.sidebar.badge.system")}),e[27]=g,e[28]=v,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 G;e[37]!==V||e[38]!==k?(G=s.jsxs("div",{className:"min-w-0",children:[V,k]}),e[37]=V,e[38]=k,e[39]=G):G=e[39];let D;e[40]!==G||e[41]!==j?(D=s.jsxs("div",{className:"flex items-center gap-3 min-w-0",children:[j,G]}),e[40]=G,e[41]=j,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]!==u?(J=s.jsxs(cn,{children:[L,s.jsx(ln,{align:"end",className:"w-fit min-w-28",children:u(dn)})]}),e[44]=u,e[45]=J):J=e[45];let ee;e[46]!==D||e[47]!==J||e[48]!==w?(ee=s.jsxs(Jn,{render:w,children:[D,J]}),e[46]=D,e[47]=J,e[48]=w,e[49]=ee):ee=e[49];let U;e[50]!==u?(U=s.jsx(qn,{className:"w-fit min-w-28",children:u(Wn)}),e[50]=u,e[51]=U):U=e[51];let re;return e[52]!==m||e[53]!==ee||e[54]!==U?(re=s.jsxs(Qn,{open:m,onOpenChange:y,children:[ee,U]}),e[52]=m,e[53]=ee,e[54]=U,e[55]=re):re=e[55],re},uh=t=>{const e=pt.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,v=a.host.includes("/"),m=r&&"border-b border-[var(--surface-subtle)]";let y;e[2]!==m?(y=fe("flex items-center justify-between gap-3 px-4 py-2.5 transition-colors hover:bg-[var(--interactive-hover)]/30",m),e[2]=m,e[3]=y):y=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=v?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 u;e[14]!==n||e[15]!==N?(u=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]=u):u=e[16];let A;return e[17]!==u||e[18]!==y||e[19]!==P?(A=s.jsxs("div",{className:y,children:[P,u]}),e[17]=u,e[18]=y,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}=ja(),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),v=o.useCallback(async k=>{await Pn(k)},[]),[m,y]=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 u=o.useCallback(async()=>{y(!0);try{const k=n?await n.authStart():await(async()=>{const D=await vt("/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 G=k.verificationUriComplete||k.verificationUri;v(G)}catch(k){console.error("Failed to start GitHub connect:",k),E.error(e("settings.github.page.toast.startConnectFailed"))}finally{y(!1)}},[v,n,e]),A=o.useCallback(async k=>{if(n)return n.authComplete(k);const G=await vt("/api/github/auth/complete",{method:"POST",headers:{"Content-Type":"application/json",Accept:"application/json"},body:JSON.stringify({deviceCode:k})}),D=await G.json().catch(()=>null);if(!G.ok||!D)throw new Error(D?.error||G.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(G=>G?G+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=>{y(!0);try{if(n)await n.authSetGhCliDisabled(k);else{const G=await vt("/api/github/auth/gh-cli",{method:"POST",headers:{"Content-Type":"application/json",Accept:"application/json"},body:JSON.stringify({disabled:k})}),D=await G.json().catch(()=>null);if(!G.ok)throw new Error(D?.error||G.statusText)}E.success(e(k?"settings.github.page.toast.ghCliDisabled":"settings.github.page.toast.ghCliEnabled")),await g(n,{force:!0})}catch(G){console.error("Failed to update gh CLI setting:",G),E.error(e("settings.github.page.toast.ghCliUpdateFailed"))}finally{y(!1)}},[g,n,e]),I=o.useCallback(async()=>{y(!0);try{if(N(),C(null),n)await n.authDisconnect();else{const k=await vt("/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{y(!1)}},[g,n,N,e]),w=o.useCallback(async k=>{if(k){y(!0);try{const G=n?await n.authActivate(k):await(async()=>{const D=await vt("/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(G),E.success(e("settings.github.page.toast.accountSwitched"))}catch(G){console.error("Failed to switch GitHub account:",G),E.error(e("settings.github.page.toast.accountSwitchFailed"))}finally{y(!1)}}},[n,c,e]);if(i&&!l)return null;const h=!!r?.connected,j=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:[j?.avatarUrl?s.jsx("img",{src:j.avatarUrl,alt:j.login?e("settings.github.page.avatarAlt.withLogin",{login:j.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:j?.name?.trim()||j?.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:j?.login||e("settings.github.page.label.unknownUser")}),j?.email&&s.jsx("span",{className:"opacity-50",children:"•"}),j?.email&&s.jsx("span",{children:j.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:m,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:m,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:u,disabled:m,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 G=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:[G?.avatarUrl?s.jsx("img",{src:G.avatarUrl,alt:G.login?e("settings.github.page.avatarAlt.withLogin",{login:G.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:G?.name?.trim()||G?.login||"GitHub"}),G?.login&&s.jsxs("span",{className:"typography-micro text-muted-foreground truncate",children:[s.jsx("span",{className:"font-mono",children:G.login}),s.jsx("span",{className:"mx-1 opacity-50",children:"·"}),s.jsx("span",{children:D})]})]})]}),s.jsx(B,{size:"sm",variant:"ghost",onClick:()=>w(k.id),disabled:m,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:u,disabled:m,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:m,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:m,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=pt.c(37),{t:e}=tt(),a=Cn(bh),n=Cn(vh),r=Cn(yh),[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 v=c,m=g?"bg-[var(--status-success)]/15 text-[var(--status-success)]":"bg-[var(--surface-muted)] text-muted-foreground";let y;t[6]===Symbol.for("react.memo_cache_sentinel")?(y=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]=y):y=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]!==m?(N=fe("max-w-36 shrink-0 truncate rounded-full px-2 py-0.5 text-[10px] font-medium",m),t[18]=m,t[19]=N):N=t[19];let u;t[20]!==v||t[21]!==N?(u=s.jsx("span",{"aria-live":"polite",className:N,children:v}),t[20]=v,t[21]=N,t[22]=u):u=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 w;t[27]!==I||t[28]!==x||t[29]!==u?(w=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:[y,x,u,I]}),t[27]=I,t[28]=x,t[29]=u,t[30]=w):w=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 j;t[32]!==w?(j=s.jsxs("div",{"data-settings-item":"integrations.github",className:"overflow-hidden rounded-xl border border-[var(--interactive-border)] bg-[var(--surface-elevated)]",children:[w,h]}),t[32]=w,t[33]=j):j=t[33];let O;return t[34]!==i||t[35]!==j?(O=s.jsx(An,{open:i,onOpenChange:l,children:j}),t[34]=i,t[35]=j,t[36]=O):O=t[36],O};function bh(t){return t.status}function vh(t){return t.isLoading}function yh(t){return t.hasChecked}const ui="__none__",gi="__inherit__";function jh({linear:t,connected:e,organizationId:a}){const{t:n}=tt(),r=Gs(x=>x.projects),[i,l]=o.useState(null),[g,c]=o.useState(!1),[v,m]=o.useState(!1),y=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(()=>{y()},[y,a]);const d=o.useCallback(async x=>{const N={};for(const u of x.teams??[])u.projectPath&&(N[u.id]=u.projectPath);m(!0),ga("saving");try{const u=await t.mappingSet({defaultProjectPath:x.defaultProjectPath??null,teamProjectPaths:N});if(u.connected===!1){l(null),ga("error");return}l(u),c(!1),ga("saved")}catch(u){console.error("Failed to save Linear mapping:",u),ga("error")}finally{m(!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(u=>u.path===x)?.label?.trim()||x,f=x=>!x||x===ui?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||ui,disabled:v||r.length===0,onValueChange:x=>{d({...i,defaultProjectPath:x===ui?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:ui,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:v||r.length===0,onValueChange:N=>{d({...i,teams:(i.teams??[]).map(u=>u.id===x.id?{...u,projectPath:N===gi?null:N}:u)})},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 wh({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 m=!1;return t.preferencesGet().then(y=>{m||(r(y.sessionComments),l(!1))}).catch(()=>{m||l(!0)}),()=>{m=!0}},[e,t]);const v=o.useCallback(async m=>{const y=n;r(m),c(!0);try{const d=await t.preferencesSet({sessionComments:m});r(d.sessionComments),ga("saved")}catch{r(y),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:m=>{v(m)},"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),[v,m]=o.useState(!1),[y,d]=o.useState(!1),C=o.useRef(null),f=o.useCallback(()=>{C.current!=null&&(window.clearInterval(C.current),C.current=null),m(!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");m(!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 u=!!a?.connected,A=a?.user,R=a?.organization,w=(a?.workspaces??[]).filter(S=>!S.current),h=A?.displayName?.trim()||A?.name?.trim()||t("settings.integrations.linear.label.unknownUser"),j=v?t("settings.integrations.linear.status.waiting"):n&&!r?t("common.loading"):u?R?.name?.trim()||t("settings.integrations.linear.status.connected"):t("settings.integrations.linear.status.notConnected"),O=v?"bg-[var(--status-warning)]/15 text-[var(--status-warning)]":u?"bg-[var(--status-success)]/15 text-[var(--status-success)]":"bg-[var(--surface-muted)] text-muted-foreground",T=v||y;return s.jsx(An,{open:T,onOpenChange:S=>{if(v){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:j}),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:[u?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(" · ")})]})]}):v?s.jsx("p",{className:"text-xs text-muted-foreground",children:t("settings.integrations.linear.flow.description")}):null,u?s.jsxs(s.Fragment,{children:[s.jsx(jh,{linear:e,connected:u,organizationId:R?.id??null}),s.jsx(wh,{linear:e,connected:u}),w.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:w.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||v,"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")})]})]}):v?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=pt.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 v,m;t[9]===Symbol.for("react.memo_cache_sentinel")?(v=n?s.jsx(xh,{}):null,m=r?s.jsx(Ch,{}):null,t[9]=v,t[10]=m):(v=t[9],m=t[10]);let y;t[11]!==g||t[12]!==c?(y=s.jsxs(ze,{title:g,info:c,divider:!1,settingsItem:"integrations.first-party",contentClassName:"space-y-3",children:[v,m]}),t[11]=g,t[12]=c,t[13]=y):y=t[13];let d;return t[14]!==i||t[15]!==l||t[16]!==y?(d=s.jsx(es,{title:i,description:l,showSaveStatus:!0,children:y}),t[14]=i,t[15]=l,t[16]=y,t[17]=d):d=t[17],d},Ph=[{value:"system",labelKey:"settings.openchamber.visual.option.themeMode.system",descriptionKey:"settings.openchamber.visual.option.themeMode.system.description"},{value:"light",labelKey:"settings.openchamber.visual.option.themeMode.light",descriptionKey:"settings.openchamber.visual.option.themeMode.light.description"},{value:"dark",labelKey:"settings.openchamber.visual.option.themeMode.dark",descriptionKey:"settings.openchamber.visual.option.themeMode.dark.description"}],Ah=[{id:"dynamic",labelKey:"settings.openchamber.visual.option.diffLayout.dynamic.label",descriptionKey:"settings.openchamber.visual.option.diffLayout.dynamic.description"},{id:"inline",labelKey:"settings.openchamber.visual.option.diffLayout.inline.label",descriptionKey:"settings.openchamber.visual.option.diffLayout.inline.description"},{id:"side-by-side",labelKey:"settings.openchamber.visual.option.diffLayout.sideBySide.label",descriptionKey:"settings.openchamber.visual.option.diffLayout.sideBySide.description"}],Th=[{id:"svg",labelKey:"settings.openchamber.visual.option.mermaidRendering.svg.label",descriptionKey:"settings.openchamber.visual.option.mermaidRendering.svg.description"},{id:"ascii",labelKey:"settings.openchamber.visual.option.mermaidRendering.ascii.label",descriptionKey:"settings.openchamber.visual.option.mermaidRendering.ascii.description"}],Da="OpenChamber - AI Coding Assistant",Zo=[{id:"system",labelKey:"settings.openchamber.visual.option.pwaOrientation.system.label",descriptionKey:"settings.openchamber.visual.option.pwaOrientation.system.description"},{id:"portrait",labelKey:"settings.openchamber.visual.option.pwaOrientation.portrait.label",descriptionKey:"settings.openchamber.visual.option.pwaOrientation.portrait.description"},{id:"landscape",labelKey:"settings.openchamber.visual.option.pwaOrientation.landscape.label",descriptionKey:"settings.openchamber.visual.option.pwaOrientation.landscape.description"}],Xo=[{id:"native",labelKey:"settings.openchamber.visual.option.mobileKeyboardMode.native.label",descriptionKey:"settings.openchamber.visual.option.mobileKeyboardMode.native.description"},{id:"resize-content",labelKey:"settings.openchamber.visual.option.mobileKeyboardMode.resizeContent.label",descriptionKey:"settings.openchamber.visual.option.mobileKeyboardMode.resizeContent.description"}],nr=t=>t==="portrait"||t==="landscape"?t:"system",Eh=[{id:"markdown",labelKey:"settings.openchamber.visual.option.userMessageRendering.markdown.label",descriptionKey:"settings.openchamber.visual.option.userMessageRendering.markdown.description"},{id:"plain",labelKey:"settings.openchamber.visual.option.userMessageRendering.plain.label",descriptionKey:"settings.openchamber.visual.option.userMessageRendering.plain.description"}],Dh=[{id:"sorted",labelKey:"settings.openchamber.visual.option.chatRenderMode.sorted.label",descriptionKey:"settings.openchamber.visual.option.chatRenderMode.sorted.description"},{id:"live",labelKey:"settings.openchamber.visual.option.chatRenderMode.live.label",descriptionKey:"settings.openchamber.visual.option.chatRenderMode.live.description"}],el=[{id:"auto",labelKey:"settings.openchamber.visual.option.messageTransport.auto.label",descriptionKey:"settings.openchamber.visual.option.messageTransport.auto.description"},{id:"ws",labelKey:"settings.openchamber.visual.option.messageTransport.ws.label",descriptionKey:"settings.openchamber.visual.option.messageTransport.ws.description"},{id:"sse",labelKey:"settings.openchamber.visual.option.messageTransport.sse.label",descriptionKey:"settings.openchamber.visual.option.messageTransport.sse.description"}],Mh=[{id:"collapsed",labelKey:"settings.openchamber.visual.option.activityRenderMode.collapsed.label",descriptionKey:"settings.openchamber.visual.option.activityRenderMode.collapsed.description"},{id:"summary",labelKey:"settings.openchamber.visual.option.activityRenderMode.summary.label",descriptionKey:"settings.openchamber.visual.option.activityRenderMode.summary.description"}],tl=[{id:"auto",labelKey:"settings.openchamber.visual.option.timeFormat.auto.label",descriptionKey:"settings.openchamber.visual.option.timeFormat.auto.description"},{id:"24h",labelKey:"settings.openchamber.visual.option.timeFormat.24h.label",descriptionKey:"settings.openchamber.visual.option.timeFormat.24h.description"},{id:"12h",labelKey:"settings.openchamber.visual.option.timeFormat.12h.label",descriptionKey:"settings.openchamber.visual.option.timeFormat.12h.description"}],sl=[{id:"auto",labelKey:"settings.openchamber.visual.option.weekStart.auto.label",descriptionKey:"settings.openchamber.visual.option.weekStart.auto.description"},{id:"monday",labelKey:"settings.openchamber.visual.option.weekStart.monday.label"},{id:"sunday",labelKey:"settings.openchamber.visual.option.weekStart.sunday.label"}],Rh=[{id:"steer",labelKey:"settings.openchamber.visual.option.followUpBehavior.steer.label"},{id:"queue",labelKey:"settings.openchamber.visual.option.followUpBehavior.queue.label"}],Lh=[{id:"ask",labelKey:"settings.openchamber.visual.option.largeTextPaste.ask.label"},{id:"attach",labelKey:"settings.openchamber.visual.option.largeTextPaste.attach.label"},{id:"inline",labelKey:"settings.openchamber.visual.option.largeTextPaste.inline.label"}],Oh=[{id:"global",labelKey:"settings.openchamber.visual.option.inputHistoryScope.global.label"},{id:"session",labelKey:"settings.openchamber.visual.option.inputHistoryScope.session.label"}],Fh=t=>t==="markdown"?"markdown":"plain",Kh=[{id:"left",labelKey:"settings.openchamber.desktopNetwork.option.windowControlsLeft"},{id:"right",labelKey:"settings.openchamber.desktopNetwork.option.windowControlsRight"}],zh=[{id:"classic",labelKey:"settings.openchamber.desktopNetwork.option.windowControlsClassic"},{id:"traffic-lights",labelKey:"settings.openchamber.desktopNetwork.option.windowControlsTrafficLights"}],Pi=({visibleSettings:t})=>{const{locale:e,locales:a,setLocale:n,label:r,t:i}=tt(),l=o.useCallback(p=>i(p),[i]),{isMobile:g}=ja(),{terminal:c}=Nl(),{browserTab:v}=Wd(),m=Td(),y=ie(p=>p.showReasoningTraces),d=ie(p=>p.sessionRecapEnabled),C=ie(p=>p.sessionSuggestionEnabled),f=ie(p=>p.setSessionRecapEnabled),P=ie(p=>p.setSessionSuggestionEnabled),x=ie(p=>p.sessionGoalEnabled),N=ie(p=>p.setSessionGoalEnabled),u=ie(p=>p.sessionGoalDefaultBudgetEnabled),A=ie(p=>p.setSessionGoalDefaultBudgetEnabled),R=ie(p=>p.sessionGoalDefaultBudget),I=ie(p=>p.setSessionGoalDefaultBudget),w=ie(p=>p.setShowReasoningTraces),h=ie(p=>p.streamingAutoFollowEnabled),j=ie(p=>p.setStreamingAutoFollowEnabled),O=ie(p=>p.collapsibleThinkingBlocks),T=ie(p=>p.setCollapsibleThinkingBlocks),S=ie(p=>p.mermaidRenderingMode),M=ie(p=>p.setMermaidRenderingMode),V=ie(p=>p.userMessageRenderingMode),$=ie(p=>p.setUserMessageRenderingMode),k=ie(p=>p.collapsibleUserMessages),G=ie(p=>p.setCollapsibleUserMessages),D=ie(p=>p.stickyUserHeader),L=ie(p=>p.promptNavigatorEnabled),J=ie(p=>p.setStickyUserHeader),ee=ie(p=>p.setPromptNavigatorEnabled),U=ie(p=>p.autoSaveEnabled),re=ie(p=>p.setAutoSaveEnabled),_=ie(p=>p.wideChatLayoutEnabled),H=ie(p=>p.setWideChatLayoutEnabled),z=ie(p=>p.codeBlockLineWrap),K=ie(p=>p.setCodeBlockLineWrap),te=ie(p=>p.chatRenderMode),Y=ie(p=>p.setChatRenderMode),ne=ie(p=>p.activityRenderMode),ue=ie(p=>p.setActivityRenderMode),de=ie(p=>p.fontSize),xe=ie(p=>p.setFontSize),ae=ie(p=>p.terminalFontSize),le=ie(p=>p.setTerminalFontSize),ge=ie(p=>p.terminalShell),Ae=ie(p=>p.setTerminalShell),Se=ie(p=>p.terminalLoginShells),Ce=ie(p=>p.setTerminalLoginShells),he=ie(p=>p.editorFontSize),_e=ie(p=>p.setEditorFontSize),Ue=ie(p=>p.uiFont),ke=ie(p=>p.setUiFont),Oe=ie(p=>p.monoFont),Ve=ie(p=>p.setMonoFont),Ge=ie(p=>p.padding),be=ie(p=>p.setPadding),Z=ie(p=>p.inputBarOffset),se=ie(p=>p.setInputBarOffset),ve=ie(p=>p.mobileKeyboardMode),ye=ie(p=>p.setMobileKeyboardMode),Re=ie(p=>p.diffLayoutPreference),Fe=ie(p=>p.setDiffLayoutPreference),Ke=ie(p=>p.showTerminalQuickKeysOnDesktop),Ee=ie(p=>p.sessionTabsEnabled),je=ie(p=>p.setSessionTabsEnabled),Ze=ie(p=>p.setShowTerminalQuickKeysOnDesktop),me=ie(p=>p.fileEditorKeymap),Ne=ie(p=>p.setFileEditorKeymap),Le=Yr(p=>p.followUpBehavior),Xe=Yr(p=>p.setFollowUpBehavior),W=ai(p=>p.scope),we=ai(p=>p.entryLimit),Ie=ai(p=>p.applyScope),Je=ai(p=>p.applyEntryLimit),ot=ie(p=>p.persistChatDraft),st=ie(p=>p.setPersistChatDraft),ut=ie(p=>p.inputSpellcheckEnabled),bt=ie(p=>p.setInputSpellcheckEnabled),q=ie(p=>p.largeTextPasteBehavior),qe=ie(p=>p.setLargeTextPasteBehavior),nt=ie(p=>p.enterToSend),lt=ie(p=>p.setEnterToSend),ht=ie(p=>p.enterToSendConfigured),Lt=ie(p=>p.setEnterToSendConfigured),et=ht?nt:!g,ft=ie(p=>p.showToolFileIcons),yt=ie(p=>p.setShowToolFileIcons),Be=ie(p=>p.showTurnChangedFiles),Et=ie(p=>p.setShowTurnChangedFiles),Me=ie(p=>p.showExpandedBashTools),jt=ie(p=>p.setShowExpandedBashTools),Q=ie(p=>p.showExpandedEditTools),pe=ie(p=>p.setShowExpandedEditTools),De=ie(p=>p.timeFormatPreference),Pe=ie(p=>p.setTimeFormatPreference),it=ie(p=>p.weekStartPreference),rt=ie(p=>p.setWeekStartPreference),We=ie(p=>p.showSplitAssistantMessageActions),Pt=ie(p=>p.setShowSplitAssistantMessageActions),vs=ie(p=>p.allowPromptingSubagentSessions),Xt=ie(p=>p.setAllowPromptingSubagentSessions),Os=ie(p=>p.draftStartersVisible),qt=ie(p=>p.setDraftStartersVisible),is=Ye(p=>p.settingsMessageStreamTransport),Ht=Ye(p=>p.setSettingsMessageStreamTransport),ys=is,gs=Ye(p=>p.settingsDefaultFileViewerPreview),hs=Ye(p=>p.setSettingsDefaultFileViewerPreview),ds=ie(p=>p.isSettingsDialogOpen),{themeMode:Es,setThemeMode:oe,availableThemes:ct,customThemesLoading:xt,reloadCustomThemes:Qt,lightThemeId:Yt,darkThemeId:Bt,setLightThemePreference:rs,setDarkThemePreference:js}=Cr(),[ss,wt]=o.useState(!1),At=o.useMemo(()=>as()&&typeof window<"u"&&window.__OPENCHAMBER_PLATFORM__==="darwin",[]),Ut=ie(p=>p.dockBadgeEnabled),Ot=ie(p=>p.setDockBadgeEnabled),ns=ie(p=>p.alwaysShowScrollbars===!0),Ds=ie(p=>p.setAlwaysShowScrollbars),Ai=Ed(),Ti=ie(p=>p.desktopWindowControlsPosition),Ha=ie(p=>p.setDesktopWindowControlsPosition),Ei=ie(p=>p.desktopWindowControlsStyle),Fs=ie(p=>p.setDesktopWindowControlsStyle),[wa,Di]=o.useState(0),Ga=ie(p=>p.reportUsage),qa=ie(p=>p.setReportUsage),Mi=o.useCallback(p=>{qa(p),mt({reportUsage:p})},[qa]),Ri=o.useCallback(p=>{Ha(p),mt({desktopWindowControlsPosition:p})},[Ha]),Li=o.useCallback(p=>{Fs(p),mt({desktopWindowControlsStyle:p})},[Fs]),Wa=(ds||g||cs())&&(t?t.includes("chatRenderMode"):!0);o.useEffect(()=>{if(!Wa)return;let p=null,gt=Date.now();const ms=()=>{const sn=Date.now();sn-gt>=420&&(Di(Fn=>(Fn+1)%24),gt=sn),p=requestAnimationFrame(ms)};(typeof document>"u"||document.visibilityState==="visible")&&(p=requestAnimationFrame(ms));const Rs=()=>{document.visibilityState==="visible"&&p===null?p=requestAnimationFrame(ms):document.visibilityState!=="visible"&&p!==null&&(cancelAnimationFrame(p),p=null)};return document.addEventListener("visibilitychange",Rs),()=>{document.removeEventListener("visibilitychange",Rs),p!==null&&cancelAnimationFrame(p)}},[Wa]);const ws=o.useCallback(p=>{$(p),mt({userMessageRenderingMode:p})},[$]),qs=o.useCallback(p=>{J(p),mt({stickyUserHeader:p})},[J]),Zn=o.useCallback(p=>{ee(p),mt({promptNavigatorEnabled:p})},[ee]),un=o.useCallback(p=>{qt(p),mt({draftStartersVisible:p})},[qt]),xn=o.useCallback(p=>{G(p),mt({collapsibleUserMessages:p})},[G]),Or=o.useCallback(p=>{H(p),mt({wideChatLayoutEnabled:p})},[H]),Xs=o.useCallback(p=>{Pt(p),mt({showSplitAssistantMessageActions:p})},[Pt]),Oi=o.useCallback(p=>{bt(p),mt({inputSpellcheckEnabled:p})},[bt]),Dn=o.useCallback(p=>{lt(p),Lt(!0),mt({enterToSend:p,enterToSendConfigured:!0})},[lt,Lt]),Xn=o.useCallback(p=>{Y(p),mt({chatRenderMode:p})},[Y]),Mn=o.useCallback(p=>{Ht(p),mt({messageStreamTransport:p})},[Ht]),ka=o.useCallback(p=>{Ie(p),mt({inputHistoryScope:p})},[Ie]),Fi=o.useCallback(p=>{const gt=Math.round(p);Dd(gt)&&(Je(gt),mt({inputHistoryLimit:gt}))},[Je]),os=o.useCallback(p=>{ue(p),mt({activityRenderMode:p})},[ue]),Ki=o.useCallback(p=>{M(p),mt({mermaidRenderingMode:p})},[M]),ea=o.useCallback(p=>{yt(p),mt({showToolFileIcons:p})},[yt]),ta=o.useCallback(p=>{Et(p),mt({showTurnChangedFiles:p})},[Et]),zi=o.useCallback(p=>{hs(p),mt({defaultFileViewerPreview:p}),window.dispatchEvent(new CustomEvent("openchamber:file-viewer-preview-mode-changed",{detail:{enabled:p}}))},[hs]),Ja=o.useCallback(p=>{jt(p),mt({showExpandedBashTools:p})},[jt]),Ui=o.useCallback(p=>{pe(p),mt({showExpandedEditTools:p})},[pe]),Qa=o.useCallback(p=>{Pe(p),mt({timeFormatPreference:p})},[Pe]),sa=o.useCallback(p=>{rt(p),mt({weekStartPreference:p})},[rt]),gn=o.useMemo(()=>ct.filter(p=>p.metadata.variant==="light").sort((p,gt)=>p.metadata.name.localeCompare(gt.metadata.name)),[ct]),Rn=o.useMemo(()=>ct.filter(p=>p.metadata.variant==="dark").sort((p,gt)=>p.metadata.name.localeCompare(gt.metadata.name)),[ct]),Na=o.useMemo(()=>gn.find(p=>p.metadata.id===Yt)??gn[0],[gn,Yt]),bn=o.useMemo(()=>Rn.find(p=>p.metadata.id===Bt)??Rn[0],[Rn,Bt]),na=o.useCallback((p,gt)=>{const ms=gt==="dark"?" Dark":" Light";return p.endsWith(ms)?p.slice(0,-ms.length):p},[]),ce=p=>t?t.includes(p):!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"),vn=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"),b=Xa||ei||ti,X=ce("pwaInstallName")&&Bn()&&v&&!as()&&!ls,Te=ce("pwaOrientation")&&Bn()&&!as()&&!ls,Qe=ce("mobileKeyboardMode")&&Bn()&&!as()&&!ls&&Md(),Dt=(ce("terminalShell")||ce("terminalLoginShell"))&&!ls,[ks,ps]=o.useState([]),[$s,Ns]=o.useState(0);o.useEffect(()=>Ml(()=>{ps([]),Ns(p=>p+1)}),[]),o.useEffect(()=>{let p=!1;if(!(!Dt||!c.listShells))return c.listShells().then(gt=>{p||ps(gt)}).catch(()=>{p||ps([])}),()=>{p=!0}},[Dt,c,$s]);const Ws=o.useMemo(()=>{const p=ks.filter(gt=>gt.id!=="auto");return ge==="auto"||p.some(gt=>gt.id===ge)?p:[{id:ge,name:ge,supportsLogin:!1},...p]},[ks,ge]),Sa=ks.find(p=>p.id===ge)?.supportsLogin===!0,Ln=Se.includes(ge),Ca=p=>{Ce(p?[...Se.filter(gt=>gt!==ge),ge]:Se.filter(gt=>gt!==ge))},[kt,Gt]=o.useState(""),[tn,Nt]=o.useState("system"),Ms=o.useMemo(()=>{const p=tl.find(gt=>gt.id===De);return l(p?.labelKey??"settings.openchamber.visual.option.timeFormat.auto.label")},[De,l]),On=o.useMemo(()=>{const p=sl.find(gt=>gt.id===it);return l(p?.labelKey??"settings.openchamber.visual.option.weekStart.auto.label")},[it,l]),ra=o.useMemo(()=>{const p=Zo.find(gt=>gt.id===tn);return p?l(p.labelKey):void 0},[tn,l]),si=o.useMemo(()=>{const p=Xo.find(gt=>gt.id===ve);return p?l(p.labelKey):void 0},[ve,l]),Vi=o.useCallback(async p=>{if(typeof window>"u")return;const gt=window,Rs=p.trim().replace(/\s+/g," ").slice(0,64);if(await mt({pwaAppName:Rs}),typeof gt.__OPENCHAMBER_SET_PWA_INSTALL_NAME__=="function"){const sn=gt.__OPENCHAMBER_SET_PWA_INSTALL_NAME__(Rs);Gt(sn);return}Gt(Rs||Da),gt.__OPENCHAMBER_UPDATE_PWA_MANIFEST__?.()},[]),Fr=o.useCallback(async p=>{if(typeof window>"u")return;const gt=window,ms=nr(p);if(await mt({pwaOrientation:ms}),typeof gt.__OPENCHAMBER_SET_PWA_ORIENTATION__=="function"){const Rs=gt.__OPENCHAMBER_SET_PWA_ORIENTATION__(ms);Nt(Rs);return}Nt(ms),gt.__OPENCHAMBER_UPDATE_PWA_MANIFEST__?.()},[]);o.useEffect(()=>{if(typeof window>"u"||!X&&!Te&&!Qe)return;let p=!1;return(async()=>{try{const ms=await mn();if(!ms){p||Gt(Da);return}const sn=(ms.pwaAppName??"").trim().replace(/\s+/g," ").slice(0,64),Fn=nr(ms.pwaOrientation),ni=so(ms.mobileKeyboardMode);p||(X&&Gt(sn||Da),Te&&Nt(Fn),Qe&&ye(ni))}catch{p||(X&&Gt(Da),Te&&Nt("system"),Qe&&ye("native"))}})(),()=>{p=!0}},[ye,Qe,X,Te]);const Bi=ce("scrollbars")?s.jsx(dt,{checked:ns,onChange:Ds,label:i("settings.openchamber.visual.field.alwaysShowScrollbars"),info:i("settings.openchamber.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.openchamber.visual.section.colorModeAndTheme"),divider:!1,children:[s.jsxs(Sn,{children:[s.jsx("div",{className:Qs,children:s.jsx(Js,{"aria-label":i("settings.openchamber.visual.section.colorMode"),children:Ph.map(p=>s.jsx(Bs,{selected:Es===p.value,onSelect:()=>oe(p.value),label:l(p.labelKey),ariaLabel:l(p.labelKey)},p.value))})}),s.jsxs("div",{className:Qs,children:[s.jsx(Wt,{label:i("settings.openchamber.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.openchamber.visual.field.selectLightThemeAria"),size:Ft,className:yn,children:s.jsx(Mt,{placeholder:i("settings.openchamber.visual.field.selectThemePlaceholder"),children:Na?na(Na.metadata.name,"light"):void 0})}),s.jsx(It,{children:gn.map(p=>s.jsx(at,{value:p.metadata.id,children:na(p.metadata.name,"light")},p.metadata.id))})]})}),s.jsx(Wt,{label:i("settings.openchamber.visual.field.darkTheme"),settingsItem:"appearance.dark-theme",children:s.jsxs(St,{value:bn?.metadata.id??"",onValueChange:js,children:[s.jsx(Ct,{"aria-label":i("settings.openchamber.visual.field.selectDarkThemeAria"),size:Ft,className:yn,children:s.jsx(Mt,{placeholder:i("settings.openchamber.visual.field.selectThemePlaceholder"),children:bn?na(bn.metadata.name,"dark"):void 0})}),s.jsx(It,{children:Rn.map(p=>s.jsx(at,{value:p.metadata.id,children:na(p.metadata.name,"dark")},p.metadata.id))})]})}),s.jsxs("div",{className:"flex items-center gap-2 pt-1",children:[s.jsxs("button",{type:"button",disabled:xt||ss,onClick:()=>{const p=Date.now();wt(!0),Qt().finally(()=>{const gt=Date.now()-p;if(gt<500){window.setTimeout(()=>{wt(!1)},500-gt);return}wt(!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.openchamber.visual.actions.reloadingThemes":"settings.openchamber.visual.actions.reloadThemes")]}),s.jsx(Jt,{children:i("settings.openchamber.visual.field.themeImportInfoTooltip")})]})]})]}),At&&s.jsx(ya,{settingsItem:"appearance.dock-badge",children:s.jsx(dt,{checked:Ut,onChange:Ot,label:i("settings.openchamber.visual.field.dockBadge"),info:i("settings.openchamber.visual.field.dockBadgeHint"),ariaLabel:i("settings.openchamber.visual.field.dockBadge")})}),Bi&&s.jsx(ya,{children:Bi})]}),Ya&&s.jsx(ze,{title:i("settings.openchamber.desktopNetwork.field.windowControls"),info:i("settings.openchamber.desktopNetwork.field.windowControlsPositionDescription"),divider:aa,children:s.jsxs(Sn,{children:[s.jsx(Wt,{label:i("settings.openchamber.desktopNetwork.field.windowControlsPosition"),settingsItem:"sessions.desktop-window-controls-position",children:s.jsx(Ys,{value:Ti,options:Kh.map(p=>({value:p.id,label:l(p.labelKey)})),onChange:Ri,"aria-label":i("settings.openchamber.desktopNetwork.field.windowControlsPositionAria")})}),s.jsx(Wt,{label:i("settings.openchamber.desktopNetwork.field.windowControlsStyle"),settingsItem:"sessions.desktop-window-controls-style",children:s.jsx(Ys,{value:Ei,options:zh.map(p=>({value:p.id,label:l(p.labelKey)})),onChange:Li,"aria-label":i("settings.openchamber.desktopNetwork.field.windowControlsStyleAria")})})]})}),Za&&s.jsx(ze,{title:i("settings.openchamber.visual.section.localization"),children:s.jsxs(Sn,{children:[s.jsx(Wt,{label:i("settings.appearance.language.label"),info:i("settings.appearance.language.description"),settingsItem:"appearance.language",children:s.jsxs(St,{value:e,onValueChange:p=>n(p),children:[s.jsx(Ct,{"aria-label":i("settings.appearance.language.select"),size:Ft,className:yn,children:s.jsx(Mt,{children:r(e)})}),s.jsx(It,{children:a.map(p=>s.jsx(at,{value:p,children:r(p)},p))})]})}),(ce("timeFormat")||ce("weekStart"))&&s.jsxs("div",{className:Qs,children:[ce("timeFormat")&&s.jsx(Wt,{label:i("settings.openchamber.visual.field.timeFormat"),settingsItem:"appearance.time-format",children:s.jsxs(St,{value:De,onValueChange:p=>Qa(p),children:[s.jsx(Ct,{"aria-label":i("settings.openchamber.visual.field.selectTimeFormatAria"),size:Ft,className:yn,children:s.jsx(Mt,{children:Ms})}),s.jsx(It,{children:tl.map(p=>s.jsx(at,{value:p.id,children:l(p.labelKey)},p.id))})]})}),ce("weekStart")&&s.jsx(Wt,{label:i("settings.openchamber.visual.field.weekStartsOn"),settingsItem:"appearance.week-start",children:s.jsxs(St,{value:it,onValueChange:p=>sa(p),children:[s.jsx(Ct,{"aria-label":i("settings.openchamber.visual.field.selectWeekStartAria"),size:Ft,className:yn,children:s.jsx(Mt,{children:On})}),s.jsx(It,{children:sl.map(p=>s.jsx(at,{value:p.id,children:l(p.labelKey)},p.id))})]})})]})]})}),(X||Te||Qe)&&s.jsxs(ze,{title:i("settings.openchamber.visual.section.appInstall"),contentClassName:Qs,children:[X&&s.jsxs(Rt,{label:i("settings.openchamber.visual.field.installAppName"),info:i("settings.openchamber.visual.field.installAppNameHint"),settingsItem:"appearance.pwa-install-name",alignEnd:!1,controlClassName:zs,children:[s.jsx(He,{value:kt,onChange:p=>{Gt(p.target.value)},onBlur:()=>{Vi(kt)},onKeyDown:p=>{p.key==="Enter"&&(p.preventDefault(),Vi(kt))},className:"min-w-0 flex-1",maxLength:64,"aria-label":i("settings.openchamber.visual.field.pwaInstallAppNameAria")}),s.jsx(B,{size:"sm",type:"button",variant:"ghost",onClick:()=>{Gt(Da),Vi("")},className:Cs,"aria-label":i("settings.openchamber.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.openchamber.visual.field.installOrientation"),description:i("settings.openchamber.visual.field.installOrientationHint"),settingsItem:"appearance.pwa-orientation",alignEnd:!1,controlClassName:zs,children:[s.jsxs(St,{value:tn,onValueChange:p=>{const gt=nr(p);Nt(gt),Fr(gt)},children:[s.jsx(Ct,{"aria-label":i("settings.openchamber.visual.field.pwaInstallOrientationAria"),size:Ft,className:$r,children:s.jsx(Mt,{placeholder:i("settings.openchamber.visual.field.selectOrientationPlaceholder"),children:ra})}),s.jsx(It,{children:Zo.map(p=>s.jsx(at,{value:p.id,children:l(p.labelKey)},p.id))})]}),s.jsx(B,{size:"sm",type:"button",variant:"ghost",onClick:()=>{Nt("system"),Fr("system")},disabled:tn==="system",className:Cs,"aria-label":i("settings.openchamber.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.openchamber.visual.field.mobileKeyboardMode"),info:i("settings.openchamber.visual.field.mobileKeyboardModeHint"),settingsItem:"appearance.mobile-keyboard-mode",alignEnd:!1,controlClassName:zs,children:[s.jsxs(St,{value:ve,onValueChange:p=>{const gt=so(p);ye(gt),mt({mobileKeyboardMode:gt})},children:[s.jsx(Ct,{"aria-label":i("settings.openchamber.visual.field.mobileKeyboardModeAria"),size:Ft,className:$r,children:s.jsx(Mt,{placeholder:i("settings.openchamber.visual.field.selectMobileKeyboardModePlaceholder"),children:si})}),s.jsx(It,{children:Xo.map(p=>s.jsx(at,{value:p.id,children:l(p.labelKey)},p.id))})]}),s.jsx(B,{size:"sm",type:"button",variant:"ghost",onClick:()=>{ye("native"),mt({mobileKeyboardMode:"native"})},disabled:ve==="native",className:Cs,"aria-label":i("settings.openchamber.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.openchamber.visual.section.densityAndType"),contentClassName:Qs,children:[ce("fontSize")&&!g||ce("terminalFontSize")?s.jsxs(Sn,{children:[ce("fontSize")&&!g&&s.jsxs(Wt,{label:i("settings.openchamber.visual.field.interfaceFont"),settingsItem:"appearance.interface-font-size",controlClassName:"w-full",children:[s.jsxs(St,{value:Ue,onValueChange:p=>ke(p),children:[s.jsx(Ct,{"aria-label":i("settings.openchamber.visual.field.selectInterfaceFontAria"),size:Ft,className:yn,children:s.jsx(Mt,{children:Zr.find(p=>p.id===Ue)?.label})}),s.jsx(It,{children:Zr.map(p=>s.jsx(at,{value:p.id,children:s.jsx("span",{style:{fontFamily:p.stack},children:p.label})},p.id))})]}),s.jsx(B,{size:"sm",type:"button",variant:"ghost",onClick:()=>ke(Xr),disabled:Ue===Xr,className:Cs,"aria-label":i("settings.openchamber.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(Wt,{label:i("settings.openchamber.visual.field.codeFont"),controlClassName:"w-full",children:[s.jsxs(St,{value:Oe,onValueChange:p=>Ve(p),children:[s.jsx(Ct,{"aria-label":i("settings.openchamber.visual.field.selectCodeFontAria"),size:Ft,className:yn,children:s.jsx(Mt,{children:eo.find(p=>p.id===Oe)?.label})}),s.jsx(It,{children:eo.map(p=>s.jsx(at,{value:p.id,children:s.jsx("span",{style:{fontFamily:p.stack},children:p.label})},p.id))})]}),s.jsx(B,{size:"sm",type:"button",variant:"ghost",onClick:()=>Ve(to),disabled:Oe===to,className:Cs,"aria-label":i("settings.openchamber.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(Wt,{label:i("settings.openchamber.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.openchamber.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.openchamber.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(Wt,{label:i("settings.openchamber.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.openchamber.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(Wt,{label:i("settings.openchamber.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.openchamber.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(Wt,{label:i("settings.openchamber.visual.field.spacingDensity"),settingsItem:"appearance.spacing-density",controlClassName:"w-full",children:s.jsxs("div",{className:la,children:[s.jsx(xs,{value:Ge,onValueChange:be,min:50,max:200,step:5,className:Ps}),s.jsx("span",{className:ca,children:"%"}),s.jsx(B,{size:"sm",type:"button",variant:"ghost",onClick:()=>be(100),disabled:Ge===100,className:Cs,"aria-label":i("settings.openchamber.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(Wt,{label:i("settings.openchamber.visual.field.inputBarOffset"),info:i("settings.openchamber.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.openchamber.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.openchamber.visual.section.navigation"),contentClassName:"space-y-4",children:[ce("fileEditorKeymap")&&s.jsx(Ss,{title:i("settings.openchamber.visual.field.fileEditorKeymap"),settingsItem:"appearance.file-editor-keymap",children:s.jsx(Js,{"aria-label":i("settings.openchamber.visual.field.fileEditorKeymap"),children:["default","vim"].map(p=>s.jsx(Bs,{selected:me===p,onSelect:()=>Ne(p),label:i(`settings.openchamber.visual.option.fileEditorKeymap.${p}`),ariaLabel:i(`settings.openchamber.visual.option.fileEditorKeymap.${p}`)},p))})}),s.jsxs("div",{className:fs,children:[ce("autoSaveEnabled")&&s.jsx(dt,{checked:U,onChange:re,label:i("settings.openchamber.visual.field.autoSaveEnabled"),ariaLabel:i("settings.openchamber.visual.field.autoSaveEnabledAria"),info:i("settings.openchamber.visual.field.autoSaveEnabledInfo"),settingsItem:"appearance.auto-save-enabled"}),Dt&&s.jsx(Wt,{label:i("settings.openchamber.visual.field.terminalShell"),info:i("settings.openchamber.visual.field.terminalShellHint"),settingsItem:"appearance.terminal-shell",className:"pt-2",children:s.jsxs(St,{value:ge,onValueChange:p=>{Rd(p)&&Ae(p)},children:[s.jsx(Ct,{"aria-label":i("settings.openchamber.visual.field.terminalShellAria"),size:Ft,className:yn,children:s.jsx(Mt,{})}),s.jsxs(It,{children:[s.jsx(at,{value:"auto",children:i("settings.openchamber.visual.option.terminalShell.auto")}),Ws.map(p=>s.jsx(at,{value:p.id,children:p.name},p.id))]})]})}),Dt&&Sa&&s.jsx(dt,{checked:Ln,onChange:Ca,label:i("settings.openchamber.visual.field.terminalLoginShell"),ariaLabel:i("settings.openchamber.visual.field.terminalLoginShell"),settingsItem:"appearance.terminal-login-shell"}),ce("terminalQuickKeys")&&!g&&s.jsx(dt,{checked:Ke,onChange:Ze,label:i("settings.openchamber.visual.field.terminalQuickKeys"),ariaLabel:i("settings.openchamber.visual.field.terminalQuickKeysAria"),settingsItem:"appearance.terminal-quick-keys",info:i("settings.openchamber.visual.field.terminalQuickKeysTooltip",{control:Gn("ctrl"),alt:Gn("alt")})})]}),ce("sessionTabs")&&!ls&&!g&&s.jsx(Ss,{title:i("settings.openchamber.visual.field.sessionTabsGroup"),settingsItem:"appearance.session-tabs",children:s.jsx(dt,{checked:Ee,onChange:je,label:i("settings.openchamber.visual.field.sessionTabs"),ariaLabel:i("settings.openchamber.visual.field.sessionTabsAria"),info:i("settings.openchamber.visual.field.sessionTabsInfo")})})]}),_i&&s.jsxs(s.Fragment,{children:[en&&s.jsxs(ze,{title:i("settings.openchamber.visual.section.chatDisplay"),divider:b,contentClassName:"space-y-6",children:[ce("chatRenderMode")&&s.jsx(Ss,{title:i("settings.openchamber.visual.section.chatRenderMode"),settingsItem:"chat.render-mode",children:s.jsx("div",{role:"radiogroup","aria-label":i("settings.openchamber.visual.section.chatRenderModeAria"),className:"grid w-full max-w-[26rem] grid-cols-1 gap-3 @xl:grid-cols-2",children:Dh.map(p=>{const gt=te===p.id,ms=wa%12;return s.jsxs("button",{type:"button",onClick:()=>Xn(p.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(p.labelKey)}),s.jsx("div",{className:"mt-2 w-full rounded-md border border-border/60 bg-muted/30 p-2",children:p.id==="live"?s.jsx("div",{className:"space-y-1.5",children:[0,1,2].map(Rs=>{const sn=Rs*3+1,Fn=ms-sn+1,ni=Fn<=0?0:Fn===1?42:Fn===2?68:92,mc=ni>0;return s.jsxs("div",{className:fe("flex items-center gap-1.5 transition-all duration-300 motion-reduce:transition-none",mc?"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=ms>=(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)})})})]},p.id)})})}),ce("activityRenderMode")&&s.jsx(Ss,{title:i("settings.openchamber.visual.section.activityDefault"),settingsItem:"chat.activity-default",children:s.jsx(Js,{"aria-label":i("settings.openchamber.visual.section.activityDefaultAria"),children:Mh.map(p=>s.jsx(Bs,{selected:ne===p.id,onSelect:()=>os(p.id),label:l(p.labelKey),ariaLabel:i("settings.openchamber.visual.field.activityDefaultModeAria",{option:l(p.labelKey)})},p.id))})})]}),vn&&s.jsxs(ze,{title:i("settings.openchamber.visual.section.messageStreamTransport"),divider:en||b,settingsItem:"chat.message-transport",contentClassName:"space-y-2",children:[s.jsx(Ys,{value:ys,options:el.map(p=>({value:p.id,label:l(p.labelKey)})),onChange:Mn,"aria-label":i("settings.openchamber.visual.section.messageStreamTransport")}),(()=>{const p=el.find(gt=>gt.id===ys);return p?.descriptionKey?s.jsx("span",{className:"typography-meta text-muted-foreground",children:l(p.descriptionKey)}):null})()]}),ia&&s.jsx(ze,{title:i("settings.openchamber.visual.section.chatMessageOptions"),divider:en||vn||b,children:s.jsxs(Sn,{className:"lg:gap-y-6",children:[ce("userMessageRendering")&&s.jsx(Ss,{title:i("settings.openchamber.visual.section.userMessageRendering"),children:s.jsx(Js,{"aria-label":i("settings.openchamber.visual.section.userMessageRenderingAria"),children:Eh.map(p=>s.jsx(Bs,{selected:Fh(V)===p.id,onSelect:()=>ws(p.id),label:l(p.labelKey),ariaLabel:i("settings.openchamber.visual.field.userMessageRenderingAria",{option:l(p.labelKey)})},p.id))})}),ce("mermaidRendering")&&s.jsx(Ss,{title:i("settings.openchamber.visual.section.mermaidRendering"),children:s.jsx(Js,{"aria-label":i("settings.openchamber.visual.section.mermaidRenderingAria"),children:Th.map(p=>s.jsx(Bs,{selected:S===p.id,onSelect:()=>Ki(p.id),label:l(p.labelKey),ariaLabel:i("settings.openchamber.visual.field.mermaidRenderingAria",{option:l(p.labelKey)})},p.id))})}),ce("diffLayout")&&!ls&&s.jsx(Ss,{title:i("settings.openchamber.visual.section.diffLayout"),children:s.jsx(Js,{"aria-label":i("settings.openchamber.visual.section.diffLayoutAria"),children:Ah.map(p=>s.jsx(Bs,{selected:Re===p.id,onSelect:()=>Fe(p.id),label:l(p.labelKey),ariaLabel:i("settings.openchamber.visual.field.diffLayoutAria",{option:l(p.labelKey)})},p.id))})}),ce("followUpBehavior")&&s.jsx(Ss,{title:i("settings.openchamber.visual.section.followUpBehavior"),settingsItem:"chat.follow-up-behavior",children:s.jsx(Js,{"aria-label":i("settings.openchamber.visual.section.followUpBehaviorAria"),children:Rh.map(p=>s.jsx(Bs,{selected:Le===p.id,onSelect:()=>Xe(p.id),label:l(p.labelKey),ariaLabel:i("settings.openchamber.visual.field.followUpBehaviorAria",{option:l(p.labelKey)})},p.id))})}),ce("inputHistoryScope")&&s.jsx(Ss,{title:i("settings.openchamber.visual.field.inputHistoryScope"),info:i("settings.openchamber.visual.field.inputHistoryScopeDescription"),settingsItem:"chat.input-history-scope",children:s.jsx(Js,{"aria-label":i("settings.openchamber.visual.section.inputHistoryScopeAria"),children:Oh.map(p=>s.jsx(Bs,{selected:W===p.id,onSelect:()=>ka(p.id),label:l(p.labelKey),ariaLabel:l(p.labelKey)},p.id))})}),ce("inputHistoryLimit")&&s.jsx(Ss,{title:i("settings.openchamber.visual.field.inputHistoryLimit"),description:i("settings.openchamber.visual.field.inputHistoryLimitDescription"),contentClassName:zs,settingsItem:"chat.input-history-limit",children:s.jsxs("div",{className:la,children:[s.jsx(xs,{value:we,onValueChange:Fi,min:Od,max:Ld,step:1,className:Ps,deferExternalValueWhileFocused:!0,"aria-label":i("settings.openchamber.visual.field.inputHistoryLimitAria")}),s.jsx("span",{className:ca,children:i("settings.openchamber.visual.field.inputHistoryLimitUnit")})]})})]})}),$i&&s.jsxs(s.Fragment,{children:[ce("expandedTools")&&s.jsxs(ze,{title:i("settings.openchamber.visual.section.showToolsOpenedByDefault"),divider:en||vn||ia||b,contentClassName:fs,children:[s.jsx(dt,{checked:Me,onChange:Ja,label:i("settings.openchamber.visual.field.bash"),ariaLabel:i("settings.openchamber.visual.field.showExpandedBashToolsAria")}),s.jsx(dt,{checked:Q,onChange:Ui,label:i("settings.openchamber.visual.field.editTools"),ariaLabel:i("settings.openchamber.visual.field.showExpandedEditToolsAria")})]}),s.jsxs(ze,{title:i("settings.openchamber.visual.section.sessionAssistance"),settingsItem:"chat.session-assistance",contentClassName:fs,children:[s.jsx(dt,{checked:Os,onChange:un,label:i("settings.openchamber.visual.field.draftStartersVisible"),ariaLabel:i("settings.openchamber.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.openchamber.visual.field.sessionRecap"),ariaLabel:i("settings.openchamber.visual.field.sessionRecapAria"),settingsItem:"chat.session-recap"}),s.jsx(dt,{checked:C,onChange:P,label:i("settings.openchamber.visual.field.sessionSuggestion"),ariaLabel:i("settings.openchamber.visual.field.sessionSuggestionAria"),settingsItem:"chat.session-suggestion"})]}),ce("subagentReadOnlyBanner")&&s.jsx(dt,{checked:vs,onChange:Xt,label:i("settings.openchamber.visual.field.allowPromptingSubagentSessions"),ariaLabel:i("settings.openchamber.visual.field.allowPromptingSubagentSessionsAria"),settingsItem:"chat.subagent-read-only-banner"})]}),ce("sessionGoal")&&!ls&&s.jsxs(ze,{title:i("settings.openchamber.visual.goal.sectionTitle"),info:i("settings.openchamber.visual.goal.description"),contentClassName:fs,children:[s.jsx(dt,{checked:x,onChange:N,label:i("settings.openchamber.visual.field.sessionGoal"),ariaLabel:i("settings.openchamber.visual.field.sessionGoalAria"),settingsItem:"chat.session-goal"}),s.jsxs("div",{"data-settings-item":"chat.session-goal-budget",className:"flex items-center gap-2",children:[s.jsx(dt,{checked:u,onChange:A,disabled:!x,label:i("settings.openchamber.visual.goal.budgetLabel"),ariaLabel:i("settings.openchamber.visual.goal.budgetAria")}),x&&u?s.jsx(xs,{value:R,onValueChange:p=>{typeof p=="number"&&Number.isFinite(p)&&p>0&&I(Math.floor(p))},min:1e3,max:1e8,step:5e4}):null]})]}),ce("reasoning")&&s.jsxs(ze,{title:i("settings.openchamber.visual.section.reasoning"),settingsItem:"chat.reasoning",contentClassName:fs,children:[s.jsx(dt,{checked:y,onChange:w,label:i("settings.openchamber.visual.field.showReasoningTraces"),ariaLabel:i("settings.openchamber.visual.field.showReasoningTracesAria"),settingsItem:"chat.reasoning-traces"}),y&&s.jsx(dt,{checked:O,onChange:T,label:i("settings.openchamber.visual.field.collapsibleThinkingBlocks"),ariaLabel:i("settings.openchamber.visual.field.collapsibleThinkingBlocksAria")})]}),s.jsx(ze,{title:i("settings.openchamber.visual.section.streaming"),settingsItem:"chat.streaming",contentClassName:fs,children:s.jsx(dt,{checked:h,onChange:j,label:i("settings.openchamber.visual.field.streamingAutoFollow"),ariaLabel:i("settings.openchamber.visual.field.streamingAutoFollowAria"),info:i("settings.openchamber.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.openchamber.visual.section.messageAppearance"),settingsItem:"chat.message-appearance",contentClassName:fs,children:[ce("collapsibleUserMessages")&&s.jsx(dt,{checked:k,onChange:xn,label:i("settings.openchamber.visual.field.collapsibleUserMessages"),ariaLabel:i("settings.openchamber.visual.field.collapsibleUserMessagesAria"),settingsItem:"chat.collapsible-user-messages"}),ce("stickyUserHeader")&&s.jsx(dt,{checked:D,onChange:qs,label:i("settings.openchamber.visual.field.stickyUserHeader"),ariaLabel:i("settings.openchamber.visual.field.stickyUserHeaderAria"),settingsItem:"chat.sticky-user-header"}),ce("promptNavigatorEnabled")&&!ls&&s.jsx(dt,{checked:L,onChange:Zn,label:i("settings.openchamber.visual.field.promptNavigatorEnabled"),ariaLabel:i("settings.openchamber.visual.field.promptNavigatorEnabledAria"),settingsItem:"chat.prompt-navigator"}),ce("wideChatLayout")&&s.jsx(dt,{checked:_,onChange:Or,label:i("settings.openchamber.visual.field.wideChatLayout"),ariaLabel:i("settings.openchamber.visual.field.wideChatLayoutAria"),settingsItem:"chat.wide-layout"}),ce("splitAssistantMessageActions")&&s.jsx(dt,{checked:We,onChange:Xs,label:i("settings.openchamber.visual.field.showSplitAssistantMessageActions"),ariaLabel:i("settings.openchamber.visual.field.showSplitAssistantMessageActionsAria"),settingsItem:"chat.inline-assistant-actions",info:i("settings.openchamber.visual.field.showSplitAssistantMessageActionsTooltip")}),ce("codeBlockLineWrap")&&s.jsx(dt,{checked:z,onChange:K,label:i("settings.openchamber.visual.field.codeBlockLineWrap"),ariaLabel:i("settings.openchamber.visual.field.codeBlockLineWrapAria"),settingsItem:"chat.code-block-line-wrap"})]}),(ce("showToolFileIcons")||ce("showTurnChangedFiles")||ce("dotfiles")&&!cs()||ce("fileViewerPreview"))&&s.jsxs(ze,{title:i("settings.openchamber.visual.section.toolsAndFiles"),settingsItem:"chat.tools-and-files",contentClassName:fs,children:[ce("showToolFileIcons")&&s.jsx(dt,{checked:ft,onChange:ea,label:i("settings.openchamber.visual.field.showToolFileIcons"),ariaLabel:i("settings.openchamber.visual.field.showToolFileIconsAria"),settingsItem:"chat.tool-file-icons"}),ce("showTurnChangedFiles")&&s.jsx(dt,{checked:Be,onChange:ta,label:i("settings.openchamber.visual.field.showTurnChangedFiles"),ariaLabel:i("settings.openchamber.visual.field.showTurnChangedFilesAria"),settingsItem:"chat.changed-files"}),ce("dotfiles")&&!cs()&&s.jsx(dt,{checked:m,onChange:Fd,label:i("settings.openchamber.visual.field.showDotfiles"),ariaLabel:i("settings.openchamber.visual.field.showDotfilesAria"),settingsItem:"chat.dotfiles"}),ce("fileViewerPreview")&&s.jsx(dt,{checked:gs,onChange:zi,label:i("settings.openchamber.defaults.field.openFilesPreview"),ariaLabel:i("settings.openchamber.defaults.field.openFilesPreviewAria")})]}),(ce("persistDraft")||ce("largeTextPaste")||!g&&ce("inputSpellcheck")||ce("enterToSend"))&&s.jsxs(ze,{title:i("settings.openchamber.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.openchamber.visual.field.persistDraftMessages"),ariaLabel:i("settings.openchamber.visual.field.persistDraftMessagesAria"),settingsItem:"chat.persist-drafts"}),!g&&ce("inputSpellcheck")&&s.jsx(dt,{checked:ut,onChange:Oi,label:i("settings.openchamber.visual.field.enableSpellcheckInTextInputs"),ariaLabel:i("settings.openchamber.visual.field.enableSpellcheckInTextInputsAria"),settingsItem:"chat.spellcheck"})]}),ce("largeTextPaste")&&s.jsx(Ss,{title:i("settings.openchamber.visual.field.largeTextPaste"),description:i("settings.openchamber.visual.field.largeTextPasteHint"),settingsItem:"chat.large-text-paste",children:s.jsx(Js,{"aria-label":i("settings.openchamber.visual.field.largeTextPasteAria"),children:Lh.map(p=>s.jsx(Bs,{selected:q===p.id,onSelect:()=>qe(p.id),label:l(p.labelKey),ariaLabel:i("settings.openchamber.visual.field.largeTextPasteOptionAria",{option:l(p.labelKey)})},p.id))})}),ce("enterToSend")&&s.jsx(Ss,{title:i("settings.openchamber.visual.field.enterToSend"),description:i("settings.openchamber.visual.field.enterToSendHint"),settingsItem:"chat.enter-to-send",children:s.jsxs(Js,{"aria-label":i("settings.openchamber.visual.field.enterToSend"),children:[s.jsx(Bs,{selected:et,onSelect:()=>Dn(!0),label:i("settings.openchamber.visual.option.enterToSend.enter.label"),ariaLabel:i("settings.openchamber.visual.option.enterToSend.enter.label")}),s.jsx(Bs,{selected:!et,onSelect:()=>Dn(!1),label:i("settings.openchamber.visual.option.enterToSend.modifier.label"),ariaLabel:i("settings.openchamber.visual.option.enterToSend.modifier.label")})]})})]})]})]}),ce("reportUsage")&&s.jsx(ze,{title:i("settings.openchamber.visual.section.privacy"),children:s.jsx(dt,{checked:Ga,onChange:Mi,label:i("settings.openchamber.visual.field.sendAnonymousUsageReports"),info:i("settings.openchamber.visual.field.sendAnonymousUsageReportsHint"),ariaLabel:i("settings.openchamber.visual.field.sendAnonymousUsageReportsAria"),settingsItem:"appearance.usage-reports"})})]})},Uh=1,_h=365,nl=30,$h=[{value:"archive",labelKey:"settings.openchamber.sessionRetention.action.archive"},{value:"delete",labelKey:"settings.openchamber.sessionRetention.action.delete"}],ec=()=>{const t=pt.c(88),{t:e}=tt(),a=ie(Vh),n=ie(Bh),r=ie(Hh),i=ie(Gh),l=ie(qh),g=ie(Wh);let c;t[0]===Symbol.for("react.memo_cache_sentinel")?(c={autoRun:!1},t[0]=c):c=t[0];const{candidates:v,isRunning:m,runCleanup:y,action:d}=Jc(c),C=v.length;let f;t[1]!==y||t[2]!==e?(f=async()=>{const de=await y({force:!0});if(de.completedIds.length===0&&de.failedIds.length===0){E.message(de.action==="archive"?e("settings.openchamber.sessionRetention.toast.noneEligibleArchive"):e("settings.openchamber.sessionRetention.toast.noneEligibleDelete"));return}de.completedIds.length>0&&E.success(de.action==="archive"?e("settings.openchamber.sessionRetention.toast.archivedCount",{count:de.completedIds.length}):e("settings.openchamber.sessionRetention.toast.deletedCount",{count:de.completedIds.length})),de.failedIds.length>0&&E.error(de.action==="archive"?e("settings.openchamber.sessionRetention.toast.failedArchiveCount",{count:de.failedIds.length}):e("settings.openchamber.sessionRetention.toast.failedDeleteCount",{count:de.failedIds.length}))},t[1]=y,t[2]=e,t[3]=f):f=t[3];const P=f;let x;t[4]!==e?(x=e("settings.openchamber.sessionRetention.title"),t[4]=e,t[5]=x):x=t[5];let N;t[6]!==e?(N=e("settings.openchamber.sessionRetention.tooltip"),t[6]=e,t[7]=N):N=t[7];let u;t[8]!==e?(u=e("settings.openchamber.sessionRetention.field.enableAutoCleanup"),t[8]=e,t[9]=u):u=t[9];let A;t[10]!==e?(A=e("settings.openchamber.sessionRetention.field.enableAutoCleanupAria"),t[10]=e,t[11]=A):A=t[11];let R;t[12]!==a||t[13]!==i||t[14]!==u||t[15]!==A?(R=s.jsx(dt,{settingsItem:"sessions.auto-cleanup",checked:a,onChange:i,label:u,ariaLabel:A}),t[12]=a,t[13]=i,t[14]=u,t[15]=A,t[16]=R):R=t[16];let I;t[17]!==e?(I=e("settings.openchamber.sessionRetention.field.retentionPeriod"),t[17]=e,t[18]=I):I=t[18];let w;t[19]!==e?(w=e("settings.openchamber.sessionRetention.field.retentionPeriodAria"),t[19]=e,t[20]=w):w=t[20];let h;t[21]===Symbol.for("react.memo_cache_sentinel")?(h=fe(Ps,"tabular-nums"),t[21]=h):h=t[21];let j;t[22]!==n||t[23]!==l||t[24]!==w?(j=s.jsx(xs,{value:n,onValueChange:l,min:Uh,max:_h,step:1,"aria-label":w,className:h}),t[22]=n,t[23]=l,t[24]=w,t[25]=j):j=t[25];let O;t[26]!==e?(O=e("settings.openchamber.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.openchamber.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 G;t[37]!==S||t[38]!==M||t[39]!==V||t[40]!==$?(G=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]=G):G=t[41];let D;t[42]!==j||t[43]!==T||t[44]!==G||t[45]!==I?(D=s.jsxs(Rt,{settingsItem:"sessions.retention-period",label:I,children:[j,T,G]}),t[42]=j,t[43]=T,t[44]=G,t[45]=I,t[46]=D):D=t[46];let L;t[47]!==e?(L=e("settings.openchamber.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(ya,{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.openchamber.sessionRetention.manualCleanup.title"),t[61]=e,t[62]=_):_=t[62];let H;t[63]!==m||t[64]!==e?(H=e(m?"settings.openchamber.sessionRetention.actions.cleaningUp":"settings.openchamber.sessionRetention.actions.runCleanupNow"),t[63]=m,t[64]=e,t[65]=H):H=t[65];let z;t[66]!==P||t[67]!==m||t[68]!==H?(z=s.jsx(B,{type:"button",variant:"outline",size:"xs",onClick:P,disabled:m,className:"!font-normal",children:H}),t[66]=P,t[67]=m,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.openchamber.sessionRetention.manualCleanup.eligibleArchiveNow",{count:C}):e("settings.openchamber.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 ue;return t[82]!==x||t[83]!==re||t[84]!==N||t[85]!==ne||t[86]!==R?(ue=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]=ue):ue=t[87],ue};function Vh(t){return t.autoDeleteEnabled}function Bh(t){return t.autoDeleteAfterDays}function Hh(t){return t.sessionRetentionAction}function Gh(t){return t.setAutoDeleteEnabled}function qh(t){return t.setAutoDeleteAfterDays}function Wh(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,v]=o.useState(null),[m,y]=o.useState(!1),[d,C]=o.useState([]),[f,P]=o.useState(Qc),[x,N]=o.useState(""),u=o.useMemo(()=>Yc(),[]),A=o.useCallback(async()=>{i(!0),N("");try{const h=await Zc();C(h)}catch(h){const j=h instanceof Error?h.message:t("settings.openchamber.passkeys.toast.loadFailed");N(j)}finally{i(!1)}},[t]);o.useEffect(()=>{let h=!1;return(async()=>{try{if(!u.supported){h||(n(!1),i(!1));return}h||n(!0)}catch{h||n(!1)}if(!h){const j=await Gi();if(P(j),!j.enabled){C([]),i(!1);return}await A()}})(),()=>{h=!0,Vr()}},[A,u.supported]);const R=o.useCallback(async()=>{if(!f.enabled){const h=t("settings.openchamber.passkeys.toast.enableUiPasswordFirst");N(h),E.message(h);return}if(!a){N(u.reason),E.message(u.reason);return}if(l){Vr(),g(!1);return}N(""),g(!0);try{await Xc(),P(await Gi()),await A(),E.success(t("settings.openchamber.passkeys.toast.added"))}catch(h){if(ed(h)){E.message(t("settings.openchamber.passkeys.toast.setupCanceled"));return}const j=h instanceof Error?h.message:t("settings.openchamber.passkeys.toast.addFailed");N(j),E.error(j)}finally{g(!1)}},[l,A,f.enabled,u.reason,a,t]),I=o.useCallback(async h=>{v(h),N("");try{await td(h),P(await Gi()),await A(),E.success(t("settings.openchamber.passkeys.toast.removed"))}catch(j){const O=j instanceof Error?j.message:t("settings.openchamber.passkeys.toast.removeFailed");N(O),E.error(O)}finally{v(null)}},[A,t]),w=o.useCallback(async()=>{y(!0),N("");try{await sd(),window.location.reload()}catch(h){const j=h instanceof Error?h.message:t("settings.openchamber.passkeys.toast.clearAuthFailed");N(j),E.error(j),y(!1)}},[t]);return s.jsxs(ze,{title:t("settings.openchamber.passkeys.title"),children:[s.jsxs("div",{className:"space-y-2",children:[s.jsxs(Rt,{label:t("settings.openchamber.passkeys.field.currentDevice"),children:[s.jsx(B,{type:"button",variant:l?"secondary":"outline",size:"xs",onClick:()=>{R()},disabled:r||m,className:"!font-normal",children:t(l?"settings.openchamber.passkeys.actions.cancelSetup":"settings.openchamber.passkeys.actions.add")}),s.jsx(B,{type:"button",variant:"ghost",size:"xs",onClick:()=>{w()},disabled:r||l||m,className:"!font-normal text-muted-foreground hover:text-foreground",children:t(m?"settings.openchamber.passkeys.actions.signingOut":"settings.openchamber.passkeys.actions.signOutEverywhere")})]}),!f.enabled&&s.jsx("p",{className:"typography-meta text-muted-foreground",children:t("settings.openchamber.passkeys.state.uiPasswordRequired")}),f.enabled&&!a&&s.jsx("p",{className:"typography-meta text-muted-foreground",children:u.reason}),r?s.jsx("p",{className:"typography-meta text-muted-foreground",children:t("settings.openchamber.passkeys.state.loading")}):d.length===0?s.jsx("p",{className:"typography-meta text-muted-foreground",children:t("settings.openchamber.passkeys.state.noneSaved")}):s.jsx("div",{className:"space-y-1 pt-1",children: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.openchamber.passkeys.item.lastUsed",{time:al(h.lastUsedAt,t("settings.openchamber.passkeys.time.neverUsed"),e)}):t("settings.openchamber.passkeys.item.added",{time:al(h.createdAt,t("settings.openchamber.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.openchamber.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=pt.c(14),{t:e}=tt(),a=Br(Jh),n=Br(Qh);let r;t[0]!==e?(r=e("settings.openchamber.appLinks.title"),t[0]=e,t[1]=r):r=t[1];let i;t[2]!==e?(i=e("settings.openchamber.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.openchamber.appLinks.empty")}):a.map(v=>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:`${v}://`}),s.jsx(B,{type:"button",variant:"ghost",size:"xs",onClick:()=>n(v),className:"!font-normal text-muted-foreground hover:text-foreground","aria-label":e("settings.openchamber.appLinks.removeAria",{scheme:`${v}://`}),children:e("settings.common.actions.delete")})]},v)),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),v=Ye(ae=>ae.selectionSource==="manual"),m=nd(ae=>ae.currentSessionId),y=Hr(ae=>ae.getSessionModelSelection),d=Hr(ae=>ae.getSessionAgentSelection),C=!!(v&&m&&y(m)),f=!!(v&&m&&d(m)),P=ie(ae=>ae.showDeletionDialog),x=ie(ae=>ae.setShowDeletionDialog),N=Ye(ae=>ae.providers),u=Ye(ae=>ae.modelsMetadata),[A,R]=o.useState(),[I,w]=o.useState(),[h,j]=o.useState(),[O,T]=o.useState(!0),[S,M]=o.useState(),[V,$]=o.useState([]),[k,G]=o.useState(),[D,L]=o.useState(!0),J=o.useMemo(()=>ar(A),[A]);o.useEffect(()=>{(async()=>{try{const le=await mn();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&&w(Ae),Se!==void 0&&j(Se),le.smallModelUseDefault!==void 0&&T(le.smallModelUseDefault);const Ce=le.smallModelOverride?.trim();Ce&&M(Ce);const he=le.walkthroughModelOverride?.trim();he&&G(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),w(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 mt({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.openchamber.defaults.option.default"):ae.charAt(0).toUpperCase()+ae.slice(1),[t]),_=o.useCallback(async ae=>{const le=ae===U?void 0:ae||void 0;w(le),g(le),C||i(le??null,le);try{await mt({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;j(le),c(le),ae&&!f&&n(ae);try{await mt({defaultAgent:le??""})}catch(ge){console.warn("Failed to save default agent:",ge)}},[f,n,c]),z=o.useCallback(async ae=>{T(ae);try{await mt({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 mt({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;G(ge);try{await mt({walkthroughModelOverride:ge??""})}catch(Ae){console.warn("Failed to save walkthrough model override:",Ae)}},[]),Y=o.useCallback((ae,le)=>u.get(`${ae}/${le}`)?.structured_output!==!1,[u]),ne=o.useMemo(()=>ar(S),[S]),ue=o.useMemo(()=>ar(k),[k]);o.useEffect(()=>{let ae=!1;return(async()=>{try{const le=await vt("/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&&(w(void 0),g(void 0),C||r(void 0),mt({defaultVariant:""}).catch(()=>{}))},[C,I,r,g,xe]),D?null:s.jsx(s.Fragment,{children:s.jsx(ze,{title:t("settings.openchamber.defaults.title"),divider:!1,children:s.jsxs("div",{className:"space-y-0",children:[s.jsxs("div",{className:"mt-0 mb-1 typography-meta text-muted-foreground",children:[t("settings.openchamber.defaults.summaryPrefix")," ",J.providerId?s.jsxs("span",{className:"text-foreground",children:[J.providerId,"/",J.modelId,xe?` (${I??t("settings.openchamber.defaults.option.defaultLowercase")})`:""]}):s.jsx("span",{className:"text-foreground",children:t("settings.openchamber.defaults.summaryOpenCodeDefault")}),h&&s.jsxs(s.Fragment,{children:[" / ",s.jsx("span",{className:"text-foreground",children:h})]})]}),s.jsxs("div",{children:[s.jsx(Rt,{settingsItem:"sessions.default-model",label:t("settings.openchamber.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.openchamber.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.openchamber.defaults.field.thinkingPlaceholder"),children:re(I??U)})}),s.jsxs(It,{children:[s.jsx(at,{value:U,children:t("settings.openchamber.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.openchamber.defaults.field.defaultAgent"),children:s.jsx(yl,{agentName:h||"",onChange:H,filter:ae=>ad(ae.mode),className:In})})]}),s.jsx(ya,{className:fs,children:s.jsx(dt,{settingsItem:"sessions.deletion-dialog",checked:P,onChange:x,label:t("settings.openchamber.defaults.field.showDeletionDialog"),ariaLabel:t("settings.openchamber.defaults.field.showDeletionDialogAria")})}),s.jsxs("div",{className:"space-y-3 pt-6",children:[s.jsxs("div",{className:"flex items-center gap-1.5",children:[s.jsx(Zs,{children:t("settings.openchamber.defaults.smallModel.title")}),s.jsx(Jt,{children:t("settings.openchamber.defaults.smallModel.description")})]}),s.jsx(dt,{settingsItem:"sessions.small-model",checked:O,onChange:ae=>{z(ae)},label:t("settings.openchamber.defaults.smallModel.useDefault"),ariaLabel:t("settings.openchamber.defaults.smallModel.useDefaultAria")}),O?null:s.jsx(Rt,{label:t("settings.openchamber.defaults.smallModel.overrideModel"),children:s.jsx(Fa,{providerId:ne.providerId,modelId:ne.modelId,onChange:K,allowedProviderIds:V,className:In})}),s.jsxs(ya,{className:fs,children:[s.jsxs("div",{className:"flex items-center gap-1.5",children:[s.jsx(Zs,{children:t("settings.openchamber.defaults.walkthroughModel.title")}),s.jsx(Jt,{children:t("settings.openchamber.defaults.walkthroughModel.description")})]}),s.jsx(Rt,{settingsItem:"sessions.walkthrough-model",label:t("settings.openchamber.defaults.walkthroughModel.overrideModel"),children:s.jsx(Fa,{providerId:ue.providerId,modelId:ue.modelId,onChange:te,allowedProviderIds:V,isModelAllowed:Y,placeholder:t("settings.openchamber.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),v=ie(_=>_.notifyOnSubtasks),m=ie(_=>_.setNotifyOnSubtasks),y=ie(_=>_.notifyOnCompletion),d=ie(_=>_.setNotifyOnCompletion),C=ie(_=>_.notifyOnError),f=ie(_=>_.setNotifyOnError),P=ie(_=>_.notifyOnQuestion),x=ie(_=>_.setNotifyOnQuestion),N=ie(_=>_.notificationTemplates),u=ie(_=>_.setNotificationTemplates),[A,R]=o.useState("default"),[I,w]=o.useState(!1),[h,j]=o.useState(!1),[O,T]=o.useState(!1);o.useEffect(()=>{if(!r){w(!1),j(!1);return}typeof Notification<"u"&&R(Notification.permission);const _=typeof window<"u"&&"serviceWorker"in navigator&&"PushManager"in window&&"Notification"in window;w(_),(async()=>{if(!_){j(!1);return}try{const z=await navigator.serviceWorker.getRegistration();if(!z){j(!1);return}const K=await z.pushManager.getSubscription();j(!!K)}catch{j(!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)=>{u(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)}},G=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 G(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 G(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}j(!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){j(!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){j(!1);return}const K=z.endpoint;await z.unsubscribe(),await _.push.unsubscribe({endpoint:K}),j(!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:y,onChange:d,label:t("settings.notifications.page.events.completionLabel"),ariaLabel:t("settings.notifications.page.events.completionAria")}),s.jsx(dt,{checked:v,onChange:m,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=pt.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 vt("/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 v=Array.from(r.values()).some(d=>d.downloading);$e.useEffect(()=>{if(!v)return;const d=setInterval(()=>{c()},2e3);return()=>clearInterval(d)},[v,c]);const m=async d=>{g(d);try{await vt(`/api/dictation/models/${encodeURIComponent(d)}/download`,{method:"POST"}),await c()}catch{}finally{g(null)}},y=async d=>{g(d);try{await vt(`/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(wr,{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:()=>{y(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:()=>{m(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)"}],br="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 vt("/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 v=c==="POST"?`/api/dictation/models/${g}/download`:`/api/dictation/models/${g}`;await vt(v,{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:br,speakerId:a.id,label:a.label}));for(const a of t)if(!(a.id===br||!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=pt.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 m=a.filter(df);if(m.length===0){c=null;break e}l="flex flex-col";let y;e[7]!==r||e[8]!==n||e[9]!==i?(y=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]=y):y=e[10],g=m.map(y)}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 v;return e[11]!==l||e[12]!==g?(v=s.jsx("div",{className:l,children:g}),e[11]=l,e[12]=g,e[13]=v):v=e[13],v},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}=ja(),a=Ye(q=>q.voiceProvider),n=Ye(q=>q.setVoiceProvider),r=Ye(q=>q.speechRate),i=Ye(q=>q.setSpeechRate),l=Ye(q=>q.speechPitch),g=Ye(q=>q.setSpeechPitch),c=Ye(q=>q.speechVolume),v=Ye(q=>q.setSpeechVolume),m=Ye(q=>q.sayVoice),y=Ye(q=>q.setSayVoice),d=Ye(q=>q.localTtsVoiceId),C=Ye(q=>q.localTtsModelId),f=Ye(q=>q.setLocalTtsModelId),P=af(),x=$e.useMemo(()=>rf(P.models),[P.models]),N=Ye(q=>q.ttsFollowTextLanguage),u=Ye(q=>q.setTtsFollowTextLanguage),A=Ye(q=>q.setLocalTtsVoiceId),{speak:R,stop:I,isPlaying:w,error:h}=id(),j=$e.useCallback(()=>{if(w){I();return}const q=x.find(qe=>qe.modelId===C&&qe.speakerId===d)?.label??String(d);R(t("settings.voice.page.preview.voiceLine",{voiceName:q}),{model:C,speakerId:d,speed:Ye.getState().speechRate})},[w,C,d,x,R,I,t]),O=Ye(q=>q.browserVoice),T=Ye(q=>q.setBrowserVoice),S=Ye(q=>q.openaiVoice),M=Ye(q=>q.setOpenaiVoice),V=Ye(q=>q.openaiApiKey),$=Ye(q=>q.setOpenaiApiKey),k=Ye(q=>q.openaiCompatibleUrl),G=Ye(q=>q.setOpenaiCompatibleUrl),D=Ye(q=>q.openaiCompatibleApiKey),L=Ye(q=>q.setOpenaiCompatibleApiKey),J=Ye(q=>q.openaiCompatibleVoice),ee=Ye(q=>q.setOpenaiCompatibleVoice),U=Ye(q=>q.openaiCompatibleTtsModel),re=Ye(q=>q.setOpenaiCompatibleTtsModel),_=Ye(q=>q.showMessageTTSButtons),H=Ye(q=>q.ttsInputMode),z=Ye(q=>q.setTtsInputMode),K=Ye(q=>q.sttProvider),te=Ye(q=>q.setSttProvider),Y=Ye(q=>q.sttServerUrl),ne=Ye(q=>q.setSttServerUrl),ue=Ye(q=>q.sttApiKey),de=Ye(q=>q.setSttApiKey),xe=Ye(q=>q.sttModel),ae=Ye(q=>q.setSttModel),le=Ye(q=>q.sttLocalModel),ge=Ye(q=>q.setSttLocalModel),Ae=Ye(q=>q.sttLanguage),Se=Ye(q=>q.setSttLanguage),Ce=Ye(q=>q.setShowMessageTTSButtons),he=Ye(q=>q.dictationEnabled),_e=Ye(q=>q.setDictationEnabled),[Ue,ke]=$e.useState(!1),[Oe,Ve]=$e.useState([]),[Ge,be]=$e.useState(!1),[Z,se]=$e.useState(null),[ve,ye]=$e.useState(!1),[Re,Fe]=$e.useState(!1),[Ke,Ee]=$e.useState(null),[je,Ze]=$e.useState(!1),[me,Ne]=$e.useState(null),[Le,Xe]=$e.useState([]),[W,we]=$e.useState(!1);$e.useEffect(()=>((async()=>{const qe=await qi.waitForVoices();Xe(qe)})(),"speechSynthesis"in window&&(window.speechSynthesis.onvoiceschanged=()=>{Xe(window.speechSynthesis.getVoices())}),()=>{"speechSynthesis"in window&&(window.speechSynthesis.onvoiceschanged=null)}),[]);const Ie=$e.useMemo(()=>Le.filter(q=>q.lang).sort((q,qe)=>{const nt=q.lang.startsWith("en"),lt=qe.lang.startsWith("en");if(nt&&!lt)return-1;if(!nt&<)return 1;const ht=q.lang.localeCompare(qe.lang);return ht!==0?ht:q.name.localeCompare(qe.name)}),[Le]),Je=$e.useCallback(()=>{if(W){qi.cancelSpeech(),we(!1);return}const q=Le.find(ht=>ht.name===O),qe=q?.name??t("settings.voice.page.preview.browserVoiceFallback"),nt=t("settings.voice.page.preview.voiceLine",{voiceName:qe});we(!0);const lt=new SpeechSynthesisUtterance(nt);lt.rate=r,lt.pitch=l,lt.volume=c,q&&(lt.voice=q,lt.lang=q.lang),lt.onend=()=>we(!1),lt.onerror=()=>we(!1),window.speechSynthesis.cancel(),window.speechSynthesis.speak(lt)},[O,Le,r,l,c,W,t]);$e.useEffect(()=>()=>{W&&qi.cancelSpeech()},[W]),$e.useEffect(()=>{if(!_||a!=="openai"&&a!=="openai-compatible"){ye(V.trim().length>0);return}(async()=>{try{const lt=(await(await vt("/api/tts/status")).json()).available,ht=V.trim().length>0;ye(lt||ht)}catch{ye(V.trim().length>0)}})()},[V,_,a]),$e.useEffect(()=>{if(!_){ke(!1),Ve([]);return}vt("/api/tts/say/status").then(q=>q.json()).then(q=>{if(ke(q.available),q.voices){const qe=q.voices.filter((nt,lt,ht)=>ht.findIndex(Lt=>Lt.name===nt.name)===lt).sort((nt,lt)=>nt.name.localeCompare(lt.name));Ve(qe)}}).catch(()=>{ke(!1)})},[_]);const ot=$e.useCallback(async()=>{if(Z){Ls(Z),se(null),be(!1);return}be(!0);let q=null;try{const qe=await vt("/api/tts/say/speak",{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify({text:t("settings.voice.page.preview.voiceLine",{voiceName:m}),voice:m,rate:Math.round(100+(r-.5)*200)})});if(!qe.ok)throw new Error("Preview failed");const nt=await qe.blob(),lt=URL.createObjectURL(nt);q=new Audio(lt),q.onended=()=>{Ls(q),se(null),be(!1)},q.onerror=()=>{Ls(q),se(null),be(!1)},se(q),await q.play()}catch{Ls(q),se(null),be(!1)}},[m,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 q=null;try{const qe=await vt("/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(!qe.ok){const ht=await qe.json().catch(()=>({error:"Unknown error"}));throw new Error(ht.error||`HTTP ${qe.status}`)}const nt=await qe.blob(),lt=URL.createObjectURL(nt);q=new Audio(lt),q.onended=()=>{Ls(q),Ee(null),Fe(!1)},q.onerror=()=>{Ls(q),Ee(null),Fe(!1)},Ee(q),await q.play()}catch{Ls(q),Ee(null),Fe(!1)}},[S,r,Ke,V,t]);$e.useEffect(()=>()=>{Ls(Ke)},[Ke]);const ut=$e.useCallback(async()=>{if(me){Ls(me),Ne(null),Ze(!1);return}if(!k.trim())return;Ze(!0);let q=null;try{const qe=await vt("/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(!qe.ok){const ht=await qe.json().catch(()=>({error:"Unknown error"}));throw new Error(ht.error||`HTTP ${qe.status}`)}const nt=await qe.blob(),lt=URL.createObjectURL(nt);q=new Audio(lt),q.onended=()=>{Ls(q),Ne(null),Ze(!1)},q.onerror=()=>{Ls(q),Ne(null),Ze(!1)},Ne(q),await q.play()}catch{Ls(q),Ne(null),Ze(!1)}},[k,J,U,D,r,me,t]);$e.useEffect(()=>()=>{Ls(me)},[me]);const bt="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,!ve&&"text-[var(--status-error)]"),children:t("settings.voice.page.field.apiKey")}),s.jsx("span",{className:fe(zn,!ve&&"text-[var(--status-error)]/80"),children:t(ve&&!V?"settings.voice.page.field.apiKeyHintUsingConfig":ve?"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:q=>$(q.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:q=>G(q.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:()=>G(""),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:q=>L(q.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:q=>re(q.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:q=>ee(q.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:ut,title:t("settings.voice.page.actions.preview"),disabled:!k.trim(),children:je?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:u,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:q=>{const qe=x.find(nt=>Ma(nt.modelId,nt.speakerId)===q);qe&&(f(qe.modelId),A(qe.speakerId))},children:[s.jsx(Ct,{size:Ft,className:rn,children:s.jsx(Mt,{placeholder:t("settings.voice.page.field.selectVoicePlaceholder"),children:q=>x.find(qe=>Ma(qe.modelId,qe.speakerId)===q)?.label??q})}),s.jsx(It,{children:x.map(q=>s.jsx(at,{value:Ma(q.modelId,q.speakerId),children:q.label},Ma(q.modelId,q.speakerId)))})]}),s.jsx(B,{size:"xs",variant:"ghost",onClick:j,title:t("settings.voice.page.actions.preview"),children:w?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"&&ve&&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(q=>s.jsx(at,{value:q.value,children:q.label},q.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:m,onValueChange:y,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(q=>s.jsx(at,{value:q.name,children:q.name},q.name))})]}),s.jsx(B,{size:"xs",variant:"ghost",onClick:ot,title:t("settings.voice.page.actions.preview"),children:Ge?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:q=>T(q==="$auto"?"":q),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(q=>s.jsxs(at,{value:q.name,children:[q.name," (",q.lang,")"]},q.name))]})]}),s.jsx(B,{size:"xs",variant:"ghost",onClick:Je,title:t("settings.voice.page.actions.preview"),children:W?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:q=>i(Number(q.target.value)),className:bt}),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:q=>g(Number(q.target.value)),className:bt}),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:q=>v(Number(q.target.value)),className:bt}),e?s.jsx(xs,{value:Math.round(c*100),onValueChange:q=>v(q/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:q=>ne(q.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:ue,onChange:q=>de(q.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"}),ue&&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:q=>ae(q.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:q=>Se(q.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===br||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}],pf="https://developers.cloudflare.com/cloudflare-one/networks/connectors/cloudflare-tunnel/get-started/create-remote-tunnel/",mf="https://developers.cloudflare.com/cloudflare-one/networks/connectors/cloudflare-tunnel/do-more-with-tunnels/local-management/configuration-file/",ir=[{value:"quick",labelKey:"settings.openchamber.tunnel.option.mode.quick.label",tooltipKey:"settings.openchamber.tunnel.option.mode.quick.tooltip"},{value:"managed-remote",labelKey:"settings.openchamber.tunnel.option.mode.managedRemote.label",tooltipKey:"settings.openchamber.tunnel.option.mode.managedRemote.tooltip"},{value:"managed-local",labelKey:"settings.openchamber.tunnel.option.mode.managedLocal.label",tooltipKey:"settings.openchamber.tunnel.option.mode.managedLocal.tooltip"}],uf=[".yml",".yaml",".json"],gf="settings.openchamber.tunnel.error.invalidConfigExtension",Ra=t=>{const e=t.trim().toLowerCase();return uf.some(a=>e.endsWith(a))},hf=t=>t==="ngrok"?"ngrok":"cloudflared",ac=()=>{if(typeof window<"u"&&typeof window.__OPENCHAMBER_PLATFORM__=="string"){const e=window.__OPENCHAMBER_PLATFORM__;if(e==="win32"||e==="darwin"||e==="linux")return e}const t=typeof navigator<"u"?`${navigator.platform||""} ${navigator.userAgent||""}`.toLowerCase():"";return t.includes("win")?"win32":t.includes("mac")?"darwin":"linux"},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=pt.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 v;e[4]!==c?(v=s.jsx(F,{name:"cloud",className:c}),e[4]=c,e[5]=v):v=e[5];let m;e[6]!==r?(m=s.jsx("span",{children:r}),e[6]=r,e[7]=m):m=e[7];let y;return e[8]!==v||e[9]!==m?(y=s.jsxs("span",{className:"flex items-center gap-2",children:[v,m]}),e[8]=v,e[9]=m,e[10]=y):y=e[10],y},Nn=t=>t==="quick"?"quick":t==="managed-remote"?"managed-remote":t==="managed-local"?"managed-local":"quick",vr=(t,e,a)=>t.find(r=>r.ms===e)?.value||a,ll=(t,e,a)=>{const n=vr(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"}),wi=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()}},bf=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=wi(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},vf=()=>typeof crypto<"u"&&typeof crypto.randomUUID=="function"?crypto.randomUUID():`${Date.now()}-${Math.random().toString(36).slice(2,10)}`,yf=()=>{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),[v,m]=o.useState(null),[y,d]=o.useState(null),[C,f]=o.useState(null),[P,x]=o.useState(!1),[N,u]=o.useState(!1),[A,R]=o.useState(!1),[I,w]=o.useState("cloudflare"),[h,j]=o.useState(()=>rr("cloudflare")),[O,T]=o.useState([]),[S,M]=o.useState("quick"),[V,$]=o.useState(null),[k,G]=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,ue]=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),Ge=t(gf),be=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]),ve=o.useMemo(()=>he.map(Q=>{const pe=Q.expiresAt<=Ue,De=Q.status==="active"&&!pe,Pe=De?cl(Q.expiresAt-Ue):Q.inactiveReason==="expired"||pe?"expired":"inactive",it=Pe==="expired"?t("settings.openchamber.tunnel.state.expired"):Q.inactiveReason==="tunnel-revoked"?t("settings.openchamber.tunnel.state.revoked"):t("settings.openchamber.tunnel.state.inactive"),rt=Nn(Q.mode);return{...Q,isActive:De,mode:rt,remainingTextForSession:Pe,inactiveLabel:it}}),[Ue,he,t]),ye=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 pe=$a()||window.location.href;let De=0;try{De=Number(new URL(pe).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]),je=o.useMemo(()=>{const Q=new Set(Ee?.modes?.map(pe=>pe.key).filter(pe=>pe==="quick"||pe==="managed-remote"||pe==="managed-local"));return Q.size===0?ir:ir.filter(pe=>Q.has(pe.value))},[Ee]),Ze=o.useMemo(()=>je.some(Q=>Q.value==="managed-remote"||Q.value==="managed-local"),[je]),me=o.useMemo(()=>h.provider===I?h:rr(I),[h,I]),Ne=o.useCallback(async Q=>{await Pn(Q)},[]),Le=o.useCallback((Q,pe)=>(j(rr(pe,Q)),Q.available===!0),[]),Xe=o.useCallback(async(Q,pe)=>{try{const De=await vt("/api/openchamber/tunnel/check",{query:{provider:Q},...pe?{signal:pe}:{}});if(!De.ok)return null;const Pe=await De.json();if(pe?.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]),W=o.useCallback(async Q=>{try{const[pe,De,Pe,it]=await Promise.all([vt("/api/openchamber/tunnel/check",{signal:Q}),vt("/api/openchamber/tunnel/status",{signal:Q}),mn(),vt("/api/openchamber/tunnel/providers",{signal:Q})]),rt=await pe.json(),We=await De.json(),Pt=Pe??{},vs=it.ok?await it.json():{},Xt=We.ttlConfig?.bootstrapTtlMs??(Pt.tunnelBootstrapTtlMs===void 0?1800*1e3:Pt.tunnelBootstrapTtlMs),Os=typeof We.ttlConfig?.sessionTtlMs=="number"?We.ttlConfig.sessionTtlMs:Pt.tunnelSessionTtlMs??480*60*1e3,qt=Nn(We.mode??Pt.tunnelMode),is=Pt.tunnelProvider??"cloudflare",Ht=Pt.managedLocalTunnelConfigPath??null,ys=Le(rt,is),gs=bf(We?.managedRemoteTunnelPresets),hs=typeof We.managedRemoteTunnelHostname=="string"?We.managedRemoteTunnelHostname:"",ds=gs.length>0?gs:hs?[{id:`legacy-${wi(hs)}`,name:hs,hostname:wi(hs)}]:[],Es=ds[0]?.id||"";if(le(Xt),Ae(Os),w(is),T(Array.isArray(vs?.providers)?vs.providers:[]),M(qt),$(Ht),G(ds),ee(Es),_e(Array.isArray(We.activeSessions)?We.activeSessions:[]),c(We.activeTunnelMode?Nn(We.activeTunnelMode):We.active&&We.mode?Nn(We.mode):null),H(new Set(Array.isArray(We.managedRemoteTunnelTokenPresetIds)?We.managedRemoteTunnelTokenPresetIds:[])),Ve(typeof We.localPort=="number"?We.localPort:null),We.active&&We.url){l({url:We.url,connectUrl:null,bootstrapExpiresAt:typeof We.bootstrapExpiresAt=="number"?We.bootstrapExpiresAt:null}),r("active");return}r(ys?"idle":"not-available")}catch{Q.aborted||(r("error"),d(t("settings.openchamber.tunnel.toast.checkAvailabilityFailed")))}},[Le,t]);o.useEffect(()=>{const Q=new AbortController;return W(Q.signal),()=>Q.abort()},[W]),o.useEffect(()=>{if(!i?.connectUrl){m(null);return}let Q=!1;return zl.toDataURL(i.connectUrl,{width:256,margin:2,color:{dark:"#000000",light:"#ffffff"}}).then(pe=>{Q||m(pe)}).catch(()=>{Q||m(null)}),()=>{Q=!0}},[i?.connectUrl]),o.useEffect(()=>{if(!i?.bootstrapExpiresAt){Ce(t("settings.openchamber.tunnel.state.noExpiry"));return}let Q=null,pe=Date.now();const De=()=>{const rt=i.bootstrapExpiresAt?i.bootstrapExpiresAt-Date.now():0;rt<=0?Ce(t("settings.openchamber.tunnel.state.expired")):Ce(cl(rt))},Pe=()=>{const rt=Date.now();rt-pe>=1e3&&(De(),pe=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,pe=Date.now();const De=()=>{const it=Date.now();it-pe>=1e3&&(ke(it),pe=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 pe=async()=>{try{const Pe=await vt("/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"||pe()},5e3);return()=>{Q=!0,window.clearInterval(De)}},[n]);const we=o.useCallback(async Q=>{R(!0);try{await mt(Q),Object.prototype.hasOwnProperty.call(Q,"tunnelMode")&&Q.tunnelMode&&M(Q.tunnelMode),Object.prototype.hasOwnProperty.call(Q,"tunnelProvider")&&typeof Q.tunnelProvider=="string"&&w(Q.tunnelProvider),Object.prototype.hasOwnProperty.call(Q,"managedLocalTunnelConfigPath")&&$(Q.managedLocalTunnelConfigPath??null),Object.prototype.hasOwnProperty.call(Q,"managedRemoteTunnelPresets")&&Q.managedRemoteTunnelPresets&&G(Q.managedRemoteTunnelPresets)}catch{E.error(t("settings.openchamber.tunnel.toast.saveSettingsFailed"))}finally{R(!1)}},[t]),Ie=o.useCallback(async(Q,pe)=>{u(!0);try{await mt({tunnelBootstrapTtlMs:Q,tunnelSessionTtlMs:pe})}catch{E.error(t("settings.openchamber.tunnel.toast.saveTtlFailed"))}finally{u(!1)}},[t]),Je=o.useCallback(async Q=>{const pe=Q.token.trim();if(pe)try{const De={...U,[Q.presetId]:pe};await mt({managedRemoteTunnelPresetTokens:De}),H(Pe=>{const it=new Set(Pe);return it.add(Q.presetId),it})}catch{E.error(t("settings.openchamber.tunnel.toast.saveTokenFailed"))}},[U,t]),ot=o.useCallback(async Q=>{f(null),d(null);const pe=O.find(Pe=>Pe.provider===Q),De=pe?.modes?.some(Pe=>Pe.key===S)?S:Nn(pe?.modes?.[0]?.key);await we({tunnelProvider:Q,tunnelMode:De}),Xe(Q)},[O,Xe,we,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 pe=Q.path.trim();if(!Ra(pe)){E.error(Ge);return}$(pe),await we({managedLocalTunnelConfigPath:pe});return}be.current?.click()},[Ge,we]),ut=o.useCallback(Q=>{const pe=Q.trim();$(pe.length>0?pe:null)},[]),bt=o.useCallback(async()=>{if(V&&!Ra(V)){E.error(Ge);return}await we({managedLocalTunnelConfigPath:V})},[Ge,V,we]),q=o.useCallback(async()=>{$(null),await we({managedLocalTunnelConfigPath:null})},[we]),qe=o.useCallback(async Q=>{const pe=Q.target.files?.[0];if(!pe)return;const De=pe.name.trim();if(De.length!==0){if(!Ra(De)){E.error(Ge);return}$(De),await we({managedLocalTunnelConfigPath:De}),Q.target.value=""}},[Ge,we]),nt=o.useCallback(async()=>{if(d(null),f(null),S==="managed-local"&&V&&!Ra(V)){d(Ge),E.error(Ge);return}r("starting");try{let Q="",pe="";if(S==="managed-remote"){if(!se){r("idle"),f(t("settings.openchamber.tunnel.toast.selectOrAddManagedRemoteFirst")),E.error(t("settings.openchamber.tunnel.toast.selectOrAddManagedRemoteFirst"));return}Q=se.hostname,pe=(U[se.id]||"").trim(),await we({tunnelMode:"managed-remote",managedRemoteTunnelPresets:k})}const De=await vt("/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"&&pe?{managedRemoteTunnelToken:pe}:{},...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.openchamber.tunnel.toast.managedRemoteTokenRequiredBeforeStarting")),E.error(t("settings.openchamber.tunnel.toast.addManagedRemoteTokenBeforeStarting"));return}r("error"),d(Pe.error||t("settings.openchamber.tunnel.toast.startFailed")),E.error(Pe.error||t("settings.openchamber.tunnel.toast.startFailed"));return}const it=typeof Pe.url=="string"?Pe.url:"";if(!it){r("error"),d(t("settings.openchamber.tunnel.toast.startedButNoPublicUrl")),E.error(t("settings.openchamber.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,We=typeof Pe.invalidatedSessionCount=="number"?Pe.invalidatedSessionCount:0;rt===1&&We===1?E.warning(t("settings.openchamber.tunnel.toast.replacedTunnelSingleSingle")):rt===1?E.warning(t("settings.openchamber.tunnel.toast.replacedTunnelSingleManySessions",{invalidatedSessionCount:We})):We===1?E.warning(t("settings.openchamber.tunnel.toast.replacedTunnelManyLinksSingleSession",{revokedBootstrapCount:rt})):E.warning(t("settings.openchamber.tunnel.toast.replacedTunnelManyMany",{revokedBootstrapCount:rt,invalidatedSessionCount:We}))}else E.success(t("settings.openchamber.tunnel.toast.linkReady"))}catch{r("error"),d(t("settings.openchamber.tunnel.toast.startFailed")),E.error(t("settings.openchamber.tunnel.toast.startFailed"))}},[Ge,k,we,se,U,t,I,S,V]),lt=o.useCallback(async()=>{r("stopping");try{await vt("/api/openchamber/tunnel/stop",{method:"POST"});const Q=await vt("/api/openchamber/tunnel/status");if(Q.ok){const pe=await Q.json();_e(Array.isArray(pe.activeSessions)?pe.activeSessions:[]),H(new Set(Array.isArray(pe.managedRemoteTunnelTokenPresetIds)?pe.managedRemoteTunnelTokenPresetIds:[])),Ve(typeof pe.localPort=="number"?pe.localPort:null)}l(null),c(null),m(null),r("idle"),E.success(t("settings.openchamber.tunnel.toast.stopped"))}catch{r("error"),d(t("settings.openchamber.tunnel.toast.stopFailed")),E.error(t("settings.openchamber.tunnel.toast.stopFailed"))}},[t]),ht=o.useCallback(async()=>{if(i?.connectUrl)try{await navigator.clipboard.writeText(i.connectUrl),x(!0),E.success(t("settings.openchamber.tunnel.toast.connectLinkCopied")),setTimeout(()=>x(!1),2e3)}catch{E.error(t("settings.openchamber.tunnel.toast.copyUrlFailed"))}},[t,i?.connectUrl]),Lt=o.useCallback(async Q=>{const pe=hi.find(De=>De.value===Q);pe&&(le(pe.ms),await Ie(pe.ms,ge))},[Ie,ge]),et=o.useCallback(async Q=>{const pe=fi.find(De=>De.value===Q);!pe||pe.ms===null||(Ae(pe.ms),await Ie(ae,pe.ms))},[ae,Ie]),ft=o.useCallback(async Q=>{f(null),d(null),n!=="active"&&n!=="stopping"&&n!=="starting"&&r("idle"),await we({tunnelMode:Q,managedRemoteTunnelPresets:k})},[k,we,n]),yt=o.useCallback(async(Q,pe)=>{try{await mt({managedRemoteTunnelPresets:pe})}catch{E.error(t("settings.openchamber.tunnel.toast.saveSelectedManagedRemoteFailed"))}},[t]),Be=o.useCallback(Q=>{const pe=k.find(De=>De.id===Q);pe&&(ee(pe.id),f(null),yt(pe,k))},[k,yt]),Et=o.useCallback(async()=>{const Q=te.trim(),pe=wi(ne),De=de.trim();if(!Q){E.error(t("settings.openchamber.tunnel.toast.tunnelNameRequired"));return}if(!pe){E.error(t("settings.openchamber.tunnel.toast.managedRemoteHostnameRequired"));return}if(!De){E.error(t("settings.openchamber.tunnel.toast.managedRemoteTokenRequired"));return}if(k.some(rt=>rt.hostname===pe)){E.error(t("settings.openchamber.tunnel.toast.hostnameAlreadyExists"));return}const Pe={id:vf(),name:Q,hostname:pe},it=[...k,Pe];G(it),ee(Pe.id),L(rt=>({...rt,[Pe.id]:!0})),re(rt=>({...rt,[Pe.id]:De})),f(null),K(!1),Y(""),ue(""),xe(""),await we({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.openchamber.tunnel.toast.managedRemoteSaved"))},[k,ne,te,de,Je,we,U,t]),Me=o.useCallback(async Q=>{const pe=k.find(We=>We.id===Q);if(!pe)return;const De=k.filter(We=>We.id!==pe.id),Pe=De[0]?.id||"",it=J===pe.id?Pe:J,rt=Object.fromEntries(Object.entries(U).filter(([We,Pt])=>We!==pe.id&&Pt.trim().length>0));G(De),ee(it),L(We=>{const Pt={...We};return delete Pt[pe.id],Pt}),re(We=>{const Pt={...We};return delete Pt[pe.id],Pt}),H(We=>{const Pt=new Set(We);return Pt.delete(pe.id),Pt}),f(null),await we({managedRemoteTunnelPresets:De,managedRemoteTunnelPresetTokens:rt}),E.success(t("settings.openchamber.tunnel.toast.managedRemoteRemoved"))},[k,we,J,U,t]),jt="gap-2 border-[var(--primary-base)] bg-[var(--primary-base)] text-[var(--primary-foreground)] hover:bg-[var(--primary-hover)] hover:text-[var(--primary-foreground)]";return n==="checking"?s.jsx("div",{className:"flex items-center justify-center py-12",children:s.jsx("span",{className:"h-1.5 w-1.5 rounded-full bg-current animate-busy-pulse","aria-label":t("settings.openchamber.tunnel.state.loading")})}):s.jsx(ze,{title:t("settings.openchamber.tunnel.title"),info:s.jsxs("div",{className:"space-y-1",children:[s.jsx("p",{children:t("settings.openchamber.tunnel.description")}),s.jsx("p",{children:t("settings.openchamber.tunnel.note.serverSideEnforced")}),s.jsx("p",{children:t("settings.openchamber.tunnel.note.connectLinksOneTime")})]}),divider:!1,children:s.jsxs("div",{className:"space-y-6",children:[ve.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:Gr,children:t("settings.openchamber.tunnel.section.redeemedAccessLinks")})]}),s.jsx("div",{className:"space-y-1",children:ve.map(Q=>{const pe=Q.mode==="quick",De=Q.mode==="managed-remote",Pe=pe?"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?pe?"text-[var(--status-warning)]":De?"text-[var(--status-info)]":"text-[var(--status-success)]":"text-muted-foreground/50",rt=t(pe?"settings.openchamber.tunnel.badge.quick":De?"settings.openchamber.tunnel.badge.remote":"settings.openchamber.tunnel.badge.local");return s.jsxs("div",{className:"flex flex-wrap items-center gap-x-2 gap-y-1 rounded border border-[var(--surface-subtle)] bg-[var(--surface-elevated)] px-2 py-1.5",children:[s.jsx(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.openchamber.tunnel.session.redeemedAt",{time:xf(Q.createdAt,e)})}),s.jsx("span",{className:"typography-meta text-foreground",children:Q.isActive?t("settings.openchamber.tunnel.session.expiresIn",{remaining:Q.remainingTextForSession}):Q.inactiveLabel===t("settings.openchamber.tunnel.state.inactive")?t("settings.openchamber.tunnel.state.inactive"):t("settings.openchamber.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:Gr,children:t("settings.openchamber.tunnel.notAvailable.dependencyNotFound",{dependency:me.dependency})}),s.jsx("p",{className:"typography-meta text-muted-foreground/70",children:t("settings.openchamber.tunnel.notAvailable.installHint")}),s.jsx("code",{className:"typography-code block rounded bg-muted/50 px-2 py-1 text-xs text-foreground",children:me.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.openchamber.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.openchamber.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.openchamber.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.openchamber.tunnel.field.tunnelType")}),s.jsx("div",{className:"flex flex-wrap items-center gap-1",children:je.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.openchamber.tunnel.field.connectLinkTtl")}),s.jsxs(St,{value:vr(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.openchamber.tunnel.field.tunnelSessionTtl")}),s.jsxs(St,{value:vr(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.openchamber.tunnel.option.mode.quick.tooltip")}),Ze&&s.jsx("p",{className:"typography-meta mt-1 text-[var(--status-warning)]",children:t("settings.openchamber.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.openchamber.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.openchamber.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,pe)=>{const De=U[Q.id]||"",Pe=_.has(Q.id),it=D[Q.id]??!1;return s.jsx("div",{className:fe(pe<k.length-1&&"border-b border-[var(--surface-subtle)]"),children:s.jsxs(An,{open:it,onOpenChange:rt=>{L(We=>({...We,[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.openchamber.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.openchamber.tunnel.field.hostnameLabel")," ",s.jsx("code",{children:Q.hostname})]}),s.jsx(He,{type:"password",value:De,onChange:rt=>{const We=rt.target.value;f(null),re(Pt=>({...Pt,[Q.id]:We}))},onBlur:rt=>{const We=rt.currentTarget.value.trim();We&&Je({presetId:Q.id,presetName:Q.name,hostname:Q.hostname,token:We})},placeholder:t(Pe?"settings.openchamber.tunnel.field.savedTokenAvailablePlaceholder":"settings.openchamber.tunnel.field.pasteTokenPlaceholder"),className:"h-7",disabled:n==="starting"||n==="stopping"}),s.jsx("div",{className:"flex items-center justify-end",children:s.jsx(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.openchamber.tunnel.actions.saveToken")})})]})})]})},Q.id)})}):s.jsx("p",{className:"typography-meta text-muted-foreground/70",children:t("settings.openchamber.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.openchamber.tunnel.field.newPresetNamePlaceholder"),className:"h-7",disabled:A||n==="starting"||n==="stopping"}),s.jsx(He,{value:ne,onChange:Q=>ue(Q.target.value),placeholder:t("settings.openchamber.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.openchamber.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.openchamber.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(""),ue(""),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.openchamber.tunnel.note.tokensSavedPerTunnel")}),s.jsx(Jt,{children:t("settings.openchamber.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.openchamber.tunnel.field.configurationFile")}),s.jsx("input",{ref:be,type:"file",accept:".yml,.yaml,.json",className:"hidden",onChange:Q=>{qe(Q)}}),s.jsxs("div",{className:"flex items-center gap-2",children:[s.jsx(He,{value:V||"",onChange:Q=>{ut(Q.target.value)},onBlur:()=>{bt()},placeholder:t("settings.openchamber.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.openchamber.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.openchamber.tunnel.actions.clearConfigFileAria"),onClick:()=>{q()},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.openchamber.tunnel.note.customConfigUsed":"settings.openchamber.tunnel.note.defaultConfigUsed")}),Z&&s.jsx("p",{className:"typography-meta text-[var(--status-error)]",children:Ge})]})}),!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.openchamber.tunnel.note.managedRemoteRequiresDomain")}),s.jsxs("button",{type:"button",className:"typography-meta inline-flex items-center gap-1 text-[var(--status-info)] underline underline-offset-2 hover:opacity-90",onClick:()=>{Ne(pf)},children:[t("settings.openchamber.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.openchamber.tunnel.note.managedLocalUsesConfig")}),s.jsxs("button",{type:"button",className:"typography-meta inline-flex items-center gap-1 text-[var(--status-info)] underline underline-offset-2 hover:opacity-90",onClick:()=>{Ne(mf)},children:[t("settings.openchamber.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.openchamber.tunnel.note.startModeAndGenerateLink",{mode:a(ir.find(Q=>Q.value===S)?.labelKey??"settings.openchamber.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.openchamber.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.openchamber.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.openchamber.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(jt,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.openchamber.tunnel.actions.startingTunnel")]}):t("settings.openchamber.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.openchamber.tunnel.state.tunnelReady")})]}),s.jsxs("div",{children:[s.jsx("p",{className:"typography-meta mb-1 text-muted-foreground/70",children:t("settings.openchamber.tunnel.field.publicUrlHint")}),s.jsx("code",{className:"typography-code block truncate rounded bg-muted/50 px-2 py-1 text-xs text-foreground",children:i.url})]}),ye&&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.openchamber.tunnel.field.connectLink")}),s.jsxs("div",{className:"flex items-center gap-2",children:[s.jsx("code",{className:"typography-code flex-1 truncate rounded bg-muted/50 px-2 py-1 text-xs text-foreground",children: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.openchamber.tunnel.actions.copied":"settings.common.actions.copyAll")]})]}),s.jsxs("p",{className:"typography-meta mt-1 text-muted-foreground/70",children:[t("settings.openchamber.tunnel.field.expires"),": ",i.bootstrapExpiresAt?Se:t("settings.openchamber.tunnel.state.never")]})]}),s.jsxs("div",{className:"flex flex-col items-center gap-2 rounded-lg border border-border/50 bg-[var(--surface-elevated)] p-4",children:[v?s.jsx("img",{src:v,alt:t("settings.openchamber.tunnel.field.connectQrAlt"),className:"size-48"}):s.jsx("div",{className:"size-48 rounded bg-muted/30"}),s.jsx("p",{className:"typography-meta text-muted-foreground",children:t("settings.openchamber.tunnel.note.scanQrToConnect")})]})]})]}),s.jsx("div",{className:"pt-1",children:s.jsxs("div",{className:"flex flex-wrap items-center gap-2",children:[s.jsxs(B,{size:"sm",variant:"outline",onClick:nt,disabled:n==="stopping"||A||S==="managed-local"&&Z,className:jt,children:[s.jsx(F,{name:"restart",className:"size-3.5"}),t("settings.openchamber.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.openchamber.tunnel.actions.stopping")]}):t("settings.openchamber.tunnel.actions.stopTunnel")})]})})]}),n==="error"&&y&&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:y}),s.jsx(B,{size:"sm",variant:"ghost",onClick:nt,children:t("settings.openchamber.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 mn();if(d||!C)return;a(C.opencodeBinary??"")}catch{}finally{d||r(!1)}})(),()=>{d=!0}},[]);const v=$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{}},[]),m=$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 mt({opencodeBinary:C}),$n("cli",{id:"opencode-binary"}),E.success(t("settings.view.pendingRestart.saved"))}finally{l(!1)}},[t,e]),y=$e.useCallback(d=>{c(d),mt({showOpenCodeUpdateNotifications:d})},[c]);return s.jsx(ze,{title:t("settings.openchamber.opencodeCli.title"),children:s.jsxs("div",{className:"space-y-0.5",children:[s.jsxs(Rt,{settingsItem:"sessions.opencode-binary",label:t("settings.openchamber.opencodeCli.field.binaryPath"),info:s.jsxs(s.Fragment,{children:[t("settings.openchamber.opencodeCli.tipPrefix")," ",s.jsx("span",{className:"font-mono",children:"OPENCODE_BINARY"})," ",t("settings.openchamber.opencodeCli.tipMiddle")," ",s.jsx("span",{className:"font-mono",children:"~/.config/openchamber/settings.json"}),"."]}),alignEnd:!1,controlClassName:"@xl:w-[20rem]",children:[s.jsx(He,{value:e,onChange:d=>a(d.target.value),placeholder:t("settings.openchamber.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:v,disabled:n||i||!as(),className:Cs,"aria-label":t("settings.openchamber.opencodeCli.actions.browseAria"),title:t("settings.openchamber.opencodeCli.actions.browse"),children:s.jsx(F,{name:"folder",className:"h-4 w-4"})})]}),s.jsxs(ya,{className:fs,children:[!Ll()&&s.jsx(dt,{settingsItem:"sessions.opencode-update-notifications",checked:g,onChange:y,label:t("settings.openchamber.opencodeCli.field.showUpdateNotifications"),ariaLabel:t("settings.openchamber.opencodeCli.field.showUpdateNotificationsAria")}),s.jsx("div",{className:"flex justify-start py-1.5",children:s.jsx(B,{type:"button",size:"xs",onClick:m,disabled:n||i,className:"shrink-0 !font-normal",children:t(i?"settings.common.actions.saving":"settings.common.actions.saveChanges")})})]})]})})},oc=()=>{const t=pt.c(44),{t:e}=tt(),a=ie(jf),n=ie(wf),r=ie(kf),i=ie(Nf),l=ie(Sf),g=ie(Cf),c=ie(If);let v;t[0]!==n?(v=S=>{n(S),mt({agentControlToolEnabled:S}),$n("cli",{id:"agent-control-tool"})},t[0]=n,t[1]=v):v=t[1];const m=v;let y;t[2]!==i?(y=S=>{i(S),mt({agentWebToolEnabled:S}),$n("cli",{id:"agent-web-tool"})},t[2]=i,t[3]=y):y=t[3];const d=y;let C;t[4]!==c?(C=S=>{c(S),mt({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.openchamber.tools.title"),t[6]=e,t[7]=P):P=t[7];let x;t[8]!==e?(x=e("settings.openchamber.tools.field.agentControlTool"),t[8]=e,t[9]=x):x=t[9];let N;t[10]!==e?(N=e("settings.openchamber.tools.field.agentControlToolAria"),t[10]=e,t[11]=N):N=t[11];let u;t[12]!==e?(u=e("settings.openchamber.tools.field.agentControlToolInfo"),t[12]=e,t[13]=u):u=t[13];let A;t[14]!==a||t[15]!==m||t[16]!==x||t[17]!==N||t[18]!==u?(A=s.jsx(dt,{settingsItem:"sessions.agent-control-tool",checked:a,onChange:m,label:x,ariaLabel:N,info:u}),t[14]=a,t[15]=m,t[16]=x,t[17]=N,t[18]=u,t[19]=A):A=t[19];let R;t[20]!==e?(R=e("settings.openchamber.tools.field.agentWebTool"),t[20]=e,t[21]=R):R=t[21];let I;t[22]!==e?(I=e("settings.openchamber.tools.field.agentWebToolAria"),t[22]=e,t[23]=I):I=t[23];let w;t[24]!==e?(w=e("settings.openchamber.tools.field.agentWebToolInfo"),t[24]=e,t[25]=w):w=t[25];let h;t[26]!==r||t[27]!==d||t[28]!==w||t[29]!==R||t[30]!==I?(h=s.jsx(dt,{settingsItem:"sessions.agent-web-tool",checked:r,onChange:d,label:R,ariaLabel:I,info:w}),t[26]=r,t[27]=d,t[28]=w,t[29]=R,t[30]=I,t[31]=h):h=t[31];let j;t[32]!==g||t[33]!==l||t[34]!==f||t[35]!==e?(j=g?s.jsx(dt,{settingsItem:"sessions.agent-memory-tool",checked:l,onChange:f,label:e("settings.openchamber.tools.field.agentMemoryTool"),ariaLabel:e("settings.openchamber.tools.field.agentMemoryToolAria"),info:e("settings.openchamber.tools.field.agentMemoryToolInfo")}):null,t[32]=g,t[33]=l,t[34]=f,t[35]=e,t[36]=j):j=t[36];let O;t[37]!==h||t[38]!==j||t[39]!==A?(O=s.jsxs("div",{className:fs,children:[A,h,j]}),t[37]=h,t[38]=j,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 jf(t){return t.agentControlToolEnabled}function wf(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.__OPENCHAMBER_PLATFORM__==="darwin",[n,r]=$e.useState(!1),[i,l]=$e.useState(!1),[g,c]=$e.useState(!1),[v,m]=$e.useState(""),[y,d]=$e.useState(!1),[C,f]=$e.useState(!1),[P,x]=$e.useState(null),[N,u]=$e.useState(!0),[A,R]=$e.useState(!1),[I,w]=$e.useState(!1),[h,j]=$e.useState(!1),[O,T]=$e.useState(!1),[S,M]=$e.useState(!1),[V,$]=$e.useState(!1),[k,G]=$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,ue]=$e.useState(null);$e.useEffect(()=>{if(!e){u(!1);return}let be=!1;return(async()=>{try{const Z=await mn();if(!Z)throw new Error(t("settings.openchamber.desktopNetwork.error.loadFailed"));if(be)return;const se=Z.desktopLanAccessEnabled===!0;r(se),l(se),c(Z.hasDesktopUiPassword===!0),m(""),d(!1),f(Z.desktopLanAccessActive===!0),x(Z.desktopLanAccessBlockedReason??null);const ve=Z.desktopMacMenuBarEnabled!==!1;L(ve),ee(ve),Y(null)}catch(Z){be||Y(Z instanceof Error?Z.message:t("settings.openchamber.desktopNetwork.error.loadFailed"))}finally{be||u(!1)}})(),()=>{be=!0}},[e,t]),$e.useEffect(()=>{if(!e){w(!1);return}let be=!1;return(async()=>{const Z=await zd();be||(w(Z?.supported===!0),j(Z?.enabled===!0))})(),()=>{be=!0}},[e]),$e.useEffect(()=>{if(!e){M(!1);return}let be=!1;return(async()=>{const Z=await Ud();be||(M(Z?.supported===!0),$(Z?.enabled===!0))})(),()=>{be=!0}},[e]),$e.useEffect(()=>{if(!e){re(!1);return}let be=!1;return(async()=>{const Z=await _d();be||(re(Z?.supported===!0),H(Z?.enabled===!0))})(),()=>{be=!0}},[e]),$e.useEffect(()=>{if(!e||!i){ue(null);return}let be=!1;return(async()=>{const Z=await Dl();be||ue(Z)})(),()=>{be=!0}},[i,e]);const de=v.trim(),xe=de.length>0||y,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&&!y,Se=i&&!Ae,Ce=n&&!C&&P==="missing-password",he=N||A||!ae||Se,_e=$e.useCallback(be=>{m(be),be.trim()&&d(!1)},[]),Ue=$e.useCallback(()=>{m(""),d(!0),l(!1)},[]),ke=$e.useCallback(async()=>{if(!I||O)return;const be=!h;j(be),T(!0),Y(null);try{const Z=await $d(be);if(!Z?.supported)throw new Error(t("settings.openchamber.desktopNetwork.error.launchAtLoginUnsupported"));j(Z.enabled)}catch(Z){j(!be),Y(Z instanceof Error?Z.message:t("settings.openchamber.desktopNetwork.error.launchAtLoginSaveFailed"))}finally{T(!1)}},[O,h,I,t]),Oe=$e.useCallback(async()=>{if(!S||k)return;const be=!V;$(be),G(!0),Y(null);try{const Z=await Vd(be);if(!Z)throw new Error(t("settings.openchamber.desktopNetwork.error.minimizeToTraySaveFailed"));if(!Z.supported)throw new Error(t("settings.openchamber.desktopNetwork.error.minimizeToTrayUnsupported"));$(Z.enabled)}catch(Z){$(!be),Y(Z instanceof Error?Z.message:t("settings.openchamber.desktopNetwork.error.minimizeToTraySaveFailed"))}finally{G(!1)}},[k,V,S,t]),Ve=$e.useCallback(async()=>{if(!U||z)return;const be=!_;H(be),K(!0),Y(null);try{const Z=await Bd(be);if(!Z?.supported)throw new Error(t("settings.openchamber.desktopNetwork.error.keepAwakeUnsupported"));H(Z.enabled)}catch(Z){H(!be),Y(Z instanceof Error?Z.message:t("settings.openchamber.desktopNetwork.error.keepAwakeSaveFailed"))}finally{K(!1)}},[z,_,U,t]),Ge=$e.useCallback(async()=>{if(ae){R(!0),Y(null);try{if(!(await mt({desktopLanAccessEnabled:i,...de?{desktopUiPassword:de}:y?{desktopUiPassword:""}:{},desktopMacMenuBarEnabled:J})).ok)throw new Error(t("settings.openchamber.desktopNetwork.error.saveFailed"));if(r(i),de?c(!0):y&&c(!1),m(""),d(!1),L(J),!await Hd())throw new Error(t("settings.openchamber.desktopNetwork.error.savedRestartFailed"))}catch(be){Y(be instanceof Error?be.message:t("settings.openchamber.desktopNetwork.error.saveFailed")),R(!1)}}},[J,i,ae,de,y,t]);return e?s.jsx(ze,{title:t("settings.openchamber.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:be=>{be!==h&&ke()},disabled:O,label:t("settings.openchamber.desktopNetwork.field.launchAtLogin"),info:t("settings.openchamber.desktopNetwork.field.launchAtLoginDescription"),ariaLabel:t("settings.openchamber.desktopNetwork.field.launchAtLoginAria")}):null,a?s.jsx(dt,{settingsItem:"sessions.desktop-mac-menu-bar",checked:J,onChange:ee,disabled:N||A,label:t("settings.openchamber.desktopNetwork.field.macMenuBar"),info:t("settings.openchamber.desktopNetwork.field.macMenuBarDescription"),ariaLabel:t("settings.openchamber.desktopNetwork.field.macMenuBarAria")}):null,S?s.jsx(dt,{settingsItem:"sessions.desktop-minimize-to-tray",checked:V,onChange:be=>{be!==V&&Oe()},disabled:k,label:t("settings.openchamber.desktopNetwork.field.minimizeToTray"),info:t("settings.openchamber.desktopNetwork.field.minimizeToTrayDescription"),ariaLabel:t("settings.openchamber.desktopNetwork.field.minimizeToTrayAria")}):null,U?s.jsx(dt,{settingsItem:"sessions.desktop-keep-awake",checked:_,onChange:be=>{be!==_&&Ve()},disabled:z,label:t("settings.openchamber.desktopNetwork.field.keepAwake"),info:t("settings.openchamber.desktopNetwork.field.keepAwakeDescription"),ariaLabel:t("settings.openchamber.desktopNetwork.field.keepAwakeAria")}):null]}):null,s.jsxs(Wt,{settingsItem:"sessions.desktop-ui-password",label:s.jsx("label",{htmlFor:"desktop-ui-password",children:t("settings.openchamber.desktopPassword.field.password")}),info:t("settings.openchamber.desktopPassword.field.passwordDescription"),children:[s.jsx(He,{id:"desktop-ui-password",type:"password",className:"h-8 min-w-0 flex-1",value:v,onChange:be=>_e(be.target.value),placeholder:t(g&&!y?"settings.openchamber.desktopPassword.field.passwordSetPlaceholder":"settings.openchamber.desktopPassword.field.passwordPlaceholder"),disabled:N||A,required:i&&!Ae,"aria-invalid":Se}),g&&!y?s.jsx(B,{type:"button",variant:"ghost",size:"xs",onClick:Ue,disabled:N||A,className:"shrink-0 !font-normal",children:t("settings.openchamber.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.openchamber.desktopNetwork.field.allowLanAccess"),info:t("settings.openchamber.desktopNetwork.field.allowLanAccessDescription"),description:s.jsxs(s.Fragment,{children:[s.jsx("span",{className:"block text-[var(--status-warning)]/85",children:t("settings.openchamber.desktopNetwork.field.warning")}),Se||Ce?s.jsx("span",{className:"block text-[var(--status-warning)]/85",children:t("settings.openchamber.desktopNetwork.field.passwordRequiredWarning")}):null]}),ariaLabel:t("settings.openchamber.desktopNetwork.field.allowLanAccessAria")})}),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.openchamber.desktopNetwork.hint.openAfterRestart":"settings.openchamber.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:Ge,disabled:he,className:"shrink-0 !font-normal",children:t(A?"settings.common.actions.saving":"settings.openchamber.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 pl(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=pt.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 v;e[2]!==c?(v=le=>le.action.customizable?c(le.action):Gn(le.action.defaultBinding),e[2]=c,e[3]=v):v=e[3];const m=v;let y;e[4]===Symbol.for("react.memo_cache_sentinel")?(y={chords:[],livePreview:null,settled:!1},e[4]=y):y=e[4];const[d,C]=o.useState(y),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 u,A;e[8]!==N?(u=()=>{if(!N)return;const le=window.setTimeout(()=>C(pl),Pf);return()=>window.clearTimeout(le)},A=[N],e[8]=N,e[9]=u,e[10]=A):(u=e[9],A=e[10]),o.useEffect(u,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 w;e[13]!==a||e[14]!==I||e[15]!==n?(w=a&&I?od(a.id,I,n):[],e[13]=a,e[14]=I,e[15]=n,e[16]=w):w=e[16];const h=w;let j;e[17]!==h?(j=h.find(Rf),e[17]=h,e[18]=j):j=e[18];const O=j;let T,S,M,V,$,k,G,D,L,J,ee,U,re,_,H;if(e[19]!==a||e[20]!==c||e[21]!==I||e[22]!==m||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(pl),!(!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 je=Ef(Re);if(je){C({chords:[je],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",G=f,D=!1;let _e;e[49]!==a||e[50]!==c||e[51]!==l?(_e=a?l("settings.openchamber.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.openchamber.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,Ge;e[62]!==he?(Ve=Re=>he(Re,"keydown"),Ge=Re=>he(Re,"keyup"),e[62]=he,e[63]=Ve,e[64]=Ge):(Ve=e[63],Ge=e[64]);let be;e[65]===Symbol.for("react.memo_cache_sentinel")?(be=()=>C(zf),e[65]=be):be=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:Gn(d.livePreview)}):null,e[68]=d.livePreview,e[69]=se):se=e[69];let ve;e[70]!==d.chords.length||e[71]!==d.livePreview||e[72]!==l?(ve=d.chords.length===0&&!d.livePreview?s.jsx("span",{className:"typography-ui-label text-muted-foreground",children:l("settings.openchamber.keyboardShortcuts.dialog.recording")}):null,e[70]=d.chords.length,e[71]=d.livePreview,e[72]=l,e[73]=ve):ve=e[73];let ye;e[74]!==Z||e[75]!==se||e[76]!==ve?(ye=s.jsxs("div",{className:"flex flex-wrap items-center justify-center gap-2",children:[Z,se,ve]}),e[74]=Z,e[75]=se,e[76]=ve,e[77]=ye):ye=e[77],e[78]!==Ve||e[79]!==Ge||e[80]!==ye?(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:Ge,onBlur:be,children:ye}),e[78]=Ve,e[79]=Ge,e[80]=ye,e[81]=J):J=e[81],ee=d.settled&&O?s.jsx("p",{className:"typography-meta text-[var(--status-error)]",children:l("settings.openchamber.keyboardShortcuts.error.internalConflict")}):d.settled&&$?s.jsx("p",{className:"typography-meta text-[var(--status-error)]",children:l("settings.openchamber.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.openchamber.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.openchamber.keyboardShortcuts.warning.contextualPrefix",{action:m(Ae)})}):null,e[19]=a,e[20]=c,e[21]=I,e[22]=m,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]=G,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],G=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.openchamber.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.openchamber.keyboardShortcuts.actions.confirm"),e[91]=l,e[92]=ne):ne=e[92];let ue;e[93]!==V||e[94]!==Y||e[95]!==ne?(ue=s.jsx(B,{type:"button",size:"sm",disabled:Y,onClick:V,children:ne}),e[93]=V,e[94]=Y,e[95]=ne,e[96]=ue):ue=e[96];let de;e[97]!==te||e[98]!==ue?(de=s.jsxs(ts,{children:[te,ue]}),e[97]=te,e[98]=ue,e[99]=de):de=e[99];let xe;e[100]!==T||e[101]!==k||e[102]!==G||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:G,showCloseButton:D,children:[L,J,ee,U,re,z,de]}),e[100]=T,e[101]=k,e[102]=G,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:Gn(t)},`${t}-${e}`)}const _f=["session","models","panels","navigation","application"],$f=()=>{const t=pt.c(24),{t:e}=tt(),a=ie(Vf),n=ie(Bf),r=ie(Hf),i=ie(Gf),[l,g]=o.useState(null);let c;if(t[0]===Symbol.for("react.memo_cache_sentinel")){const I=pd();c=cs()?I.filter(qf):I,t[0]=c}else c=t[0];const v=c,m=Wf;let y;t[1]!==n||t[2]!==a?(y=(I,w,h)=>{const j={...a,[I]:w};h&&(j[h]=Wi),n(I,w),h&&n(h,Wi),m(j)},t[1]=n,t[2]=a,t[3]=y):y=t[3];const d=y;let C;t[4]!==r||t[5]!==a?(C=I=>{const w={...a};delete w[I],r(I),m(w)},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 w="prefixStyle"in I&&I.prefixStyle,h=w?md(I.id,a):Tl(I.id,a),j=Gn(h,e("settings.openchamber.keyboardShortcuts.unassigned"));if(!w||!h||h===Wi)return j;const O=I.id==="switch_session_tab"?e("settings.openchamber.keyboardShortcuts.action.switch_session_tab.suffix"):e("settings.openchamber.keyboardShortcuts.action.switch_context_surface.suffix");return`${j}${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,w)=>{const h=v.filter(j=>j.category===I);return h.length===0?null:s.jsx(ze,{settingsItem:w===0?"shortcuts.keyboard-shortcuts":void 0,title:e(`settings.openchamber.keyboardShortcuts.category.${I}`),divider:w!==0,info:w===0?e("settings.openchamber.keyboardShortcuts.tooltip"):void 0,headerAction:w===0?s.jsx(B,{type:"button",variant:"outline",size:"xs",className:"!font-normal",onClick:()=>{i(),m({})},children:e("settings.openchamber.keyboardShortcuts.actions.resetAll")}):void 0,children:s.jsx("div",{className:"space-y-2",children:h.map(j=>s.jsxs(Rt,{label:e(j.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(j)}),s.jsx(B,{type:"button",variant:"secondary",size:"xs",className:"!font-normal",onClick:()=>g(j),children:e("settings.openchamber.keyboardShortcuts.actions.edit")}),j.id in a?s.jsx(B,{type:"button",variant:"ghost",size:"xs",className:"!font-normal",onClick:()=>f(j.id),children:e("settings.common.actions.reset")}):null]},j.id))})},I)}),t[10]=i,t[11]=f,t[12]=x,t[13]=a,t[14]=e,t[15]=N):N=t[15];let u;t[16]===Symbol.for("react.memo_cache_sentinel")?(u=I=>{I||g(null)},t[16]=u):u=t[16];let A;t[17]!==l||t[18]!==d||t[19]!==a?(A=s.jsx(Mf,{action:l,overrides:a,onSave:d,onOpenChange:u}),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 Gf(t){return t.resetAllShortcutOverrides}function qf(t){return t.id!=="toggle_prompt_navigator"}function Wf(t){mt({shortcutOverrides:t})}const dc=()=>{const t=pt.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=pt.c(80),{section:a}=t,{t:n}=tt(),{isMobile:r}=ja();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 v;e[3]===Symbol.for("react.memo_cache_sentinel")?(v=as()&&Va(),e[3]=v):v=e[3];const m=v;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=m&&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 ue;return e[14]!==ne?(ue=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]=ue):ue=e[15],ue}let y;e[16]!==a?(y=()=>{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]=y):y=e[17];const d=y;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 u;e[28]!==n?(u=n("settings.page.git.title"),e[28]=n,e[29]=u):u=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 w;e[36]!==n?(w=n("settings.page.tunnel.title"),e[36]=n,e[37]=w):w=e[37];let h;e[38]!==u||e[39]!==A||e[40]!==R||e[41]!==I||e[42]!==w||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:u,github:A,notifications:R,voice:I,tunnel:w},e[38]=u,e[39]=A,e[40]=R,e[41]=I,e[42]=w,e[43]=C,e[44]=f,e[45]=P,e[46]=x,e[47]=N,e[48]=h):h=e[48];const j=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 G;e[63]!==n?(G=n("settings.page.tunnel.description"),e[63]=n,e[64]=G):G=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]!==G?(D={general:O,visual:T,chat:S,sessions:M,shortcuts:V,git:void 0,github:void 0,notifications:$,voice:k,tunnel:G},e[65]=O,e[66]=T,e[67]=S,e[68]=M,e[69]=V,e[70]=$,e[71]=k,e[72]=G,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]!==j||e[78]!==J?(ee=s.jsx(es,{title:j,description:L,showSaveStatus:!0,className:"openchamber-page-body",children:J}),e[76]=L,e[77]=j,e[78]=J,e[79]=ee):ee=e[79],ee},Qf=()=>{const t=pt.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=pt.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,v,m,y;t[3]===Symbol.for("react.memo_cache_sentinel")?(g=r&&s.jsx(lc,{}),c=l&&s.jsx(tc,{}),v=s.jsx(sc,{}),m=!a&&s.jsx(rc,{}),y=!a&&s.jsx(oc,{}),t[3]=g,t[4]=c,t[5]=v,t[6]=m,t[7]=y):(g=t[3],c=t[4],v=t[5],m=t[6],y=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,v,m,y,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=pt.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=pt.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=pt.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=pt.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=pt.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=pt.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=pt.c(1);if(cs())return null;let e;return t[0]===Symbol.for("react.memo_cache_sentinel")?(e=s.jsx(yf,{}),t[0]=e):e=t[0],e};function ix(t){return t+1}const rx=t=>{const e=pt.c(85),{className:a}=t,{t:n}=tt(),r=Vn(El),i=Vn(ox),l=ie(lx),g=ie(cx),[c,v]=$e.useState(!1),[m,y]=$e.useState(!1),d=r>0;let C;e[0]!==n?(C=async()=>{try{const Se=await ud({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]!==m||e[5]!==f||e[6]!==g?(N=()=>{m&&g(!1),v(!1),y(!1),f()},e[4]=m,e[5]=f,e[6]=g,e[7]=N):N=e[7];const u=N;let A;e[8]!==d||e[9]!==f||e[10]!==x||e[11]!==l?(A=()=>{if(!d){x();return}if(l){y(!1),v(!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 w=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 j=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]!==w?(V=s.jsx("span",{className:"truncate",children:w}),e[28]=w,e[29]=V):V=e[29];let $;e[30]!==R||e[31]!==i||e[32]!==M||e[33]!==V||e[34]!==S||e[35]!==j?($=s.jsxs("button",{type:"button",disabled:i,title:j,"aria-label":j,onClick:R,className:S,children:[M,V]}),e[30]=R,e[31]=i,e[32]=M,e[33]=V,e[34]=S,e[35]=j,e[36]=$):$=e[36];let k;e[37]===Symbol.for("react.memo_cache_sentinel")?(k=Se=>{v(Se),Se||y(!1)},e[37]=k):k=e[37];let G;e[38]!==n?(G=n("settings.view.pendingRestart.confirm.title"),e[38]=n,e[39]=G):G=e[39];let D;e[40]!==G?(D=s.jsx($t,{children:G}),e[40]=G,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=()=>v(!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]!==u||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:u,children:K})}),e[58]=u,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=()=>y(dx),e[64]=ne):ne=e[64];let ue;e[65]!==m?(ue=m?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]=m,e[66]=ue):ue=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]!==m||e[70]!==ue||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":m,children:[ue,de]}),e[69]=m,e[70]=ue,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 px=[{id:"chat.activity-default",page:"chat",titleKey:"settings.openchamber.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.openchamber.visual.field.timeFormat",keywords:["clock","12h","24h"]},{id:"appearance.week-start",page:"appearance",titleKey:"settings.openchamber.visual.field.weekStartsOn",keywords:["calendar","monday","sunday"]},{id:"appearance.light-theme",page:"appearance",titleKey:"settings.openchamber.visual.field.lightTheme",keywords:["theme","color","light mode"],isAvailable:t=>!t.isVSCode},{id:"appearance.dark-theme",page:"appearance",titleKey:"settings.openchamber.visual.field.darkTheme",keywords:["theme","color","dark mode"],isAvailable:t=>!t.isVSCode},{id:"appearance.dock-badge",page:"appearance",titleKey:"settings.openchamber.visual.field.dockBadge",descriptionKey:"settings.openchamber.visual.field.dockBadgeHint",keywords:["dock","badge","unread","unseen","counter","count","notification","macos"],isAvailable:t=>t.isMac},{id:"appearance.scrollbars",page:"appearance",titleKey:"settings.openchamber.visual.field.alwaysShowScrollbars",descriptionKey:"settings.openchamber.visual.field.alwaysShowScrollbarsHint",keywords:["scrollbar","scrollbars","scroll","mouse","wheel","accessibility","always visible"]},{id:"appearance.pwa-install-name",page:"appearance",titleKey:"settings.openchamber.visual.field.installAppName",descriptionKey:"settings.openchamber.visual.field.installAppNameHint",keywords:["pwa","installed app"],isAvailable:t=>t.isWeb&&!t.isDesktop&&!t.isVSCode},{id:"appearance.pwa-orientation",page:"appearance",titleKey:"settings.openchamber.visual.field.installOrientation",descriptionKey:"settings.openchamber.visual.field.installOrientationHint",keywords:["pwa","portrait","landscape"],isAvailable:t=>t.isWeb&&!t.isDesktop&&!t.isVSCode},{id:"appearance.mobile-keyboard-mode",page:"appearance",titleKey:"settings.openchamber.visual.field.mobileKeyboardMode",descriptionKey:"settings.openchamber.visual.field.mobileKeyboardModeHint",keywords:["mobile","keyboard","resize"],isAvailable:t=>t.isMobile&&t.isWeb&&!t.isDesktop&&!t.isVSCode},{id:"appearance.interface-font-size",page:"appearance",titleKey:"settings.openchamber.visual.field.interfaceFontSize",keywords:["font","text size","ui scale"],isAvailable:t=>!t.isMobile},{id:"appearance.terminal-font-size",page:"appearance",titleKey:"settings.openchamber.visual.field.terminalFontSize",keywords:["terminal","font","text size"]},{id:"appearance.terminal-shell",page:"general",titleKey:"settings.openchamber.visual.field.terminalShell",descriptionKey:"settings.openchamber.visual.field.terminalShellHint",keywords:["terminal","shell","bash","zsh","fish","pwsh","powershell"],isAvailable:t=>!t.isVSCode},{id:"appearance.editor-font-size",page:"appearance",titleKey:"settings.openchamber.visual.field.editorFontSize",keywords:["editor","font","text size","code"]},{id:"appearance.spacing-density",page:"appearance",titleKey:"settings.openchamber.visual.field.spacingDensity",keywords:["density","compact","comfortable","spacing"]},{id:"appearance.input-bar-offset",page:"appearance",titleKey:"settings.openchamber.visual.field.inputBarOffset",descriptionKey:"settings.openchamber.visual.field.inputBarOffsetTooltip",keywords:["input","home bar","offset"],isAvailable:t=>t.isMobile},{id:"appearance.auto-save-enabled",page:"general",titleKey:"settings.openchamber.visual.field.autoSaveEnabled",descriptionKey:"settings.openchamber.visual.field.autoSaveEnabledInfo",keywords:["editor","autosave","auto-save","files","save"]},{id:"appearance.file-editor-keymap",page:"general",titleKey:"settings.openchamber.visual.field.fileEditorKeymap",keywords:["editor","vim","keymap"]},{id:"appearance.session-tabs",page:"general",titleKey:"settings.openchamber.visual.field.sessionTabsGroup",descriptionKey:"settings.openchamber.visual.field.sessionTabsInfo",keywords:["session","tabs","header","working set"],isAvailable:t=>!t.isMobile&&!t.isVSCode},{id:"appearance.terminal-quick-keys",page:"general",titleKey:"settings.openchamber.visual.field.terminalQuickKeys",descriptionKey:"settings.openchamber.visual.field.terminalQuickKeysTooltip",keywords:["terminal","keyboard","esc","ctrl","arrows"],isAvailable:t=>!t.isMobile&&!t.isVSCode},{id:"appearance.usage-reports",page:"general",titleKey:"settings.openchamber.visual.field.sendAnonymousUsageReports",descriptionKey:"settings.openchamber.visual.field.sendAnonymousUsageReportsHint",keywords:["telemetry","analytics"]},{id:"general.app-links",page:"general",titleKey:"settings.openchamber.appLinks.title",descriptionKey:"settings.openchamber.appLinks.info",keywords:["security","app link","deep link","scheme","protocol","obsidian","notion"]},{id:"chat.render-mode",page:"chat",titleKey:"settings.openchamber.visual.section.chatRenderMode",keywords:["messages","conversation","rendering"]},{id:"chat.message-transport",page:"general",titleKey:"settings.openchamber.visual.section.messageStreamTransport",keywords:["streaming","sse","websocket"]},{id:"chat.session-recap",page:"chat",titleKey:"settings.openchamber.visual.field.sessionRecap",keywords:["recap","assist","small model","summary"]},{id:"chat.session-assistance",page:"chat",titleKey:"settings.openchamber.visual.section.sessionAssistance",keywords:["recap","suggestion","subagent"]},{id:"chat.session-suggestion",page:"chat",titleKey:"settings.openchamber.visual.field.sessionSuggestion",keywords:["suggestion","assist","small model","follow up"]},{id:"chat.session-goal",page:"chat",titleKey:"settings.openchamber.visual.field.sessionGoal",keywords:["goal","objective","auto continue","small model"],isAvailable:t=>!t.isVSCode},{id:"chat.session-goal-budget",page:"chat",titleKey:"settings.openchamber.visual.goal.budgetLabel",keywords:["goal","budget","tokens","limit"],isAvailable:t=>!t.isVSCode},{id:"chat.reasoning-traces",page:"chat",titleKey:"settings.openchamber.visual.field.showReasoningTraces",keywords:["thinking","reasoning"]},{id:"chat.reasoning",page:"chat",titleKey:"settings.openchamber.visual.section.reasoning",keywords:["thinking","traces"]},{id:"chat.streaming",page:"chat",titleKey:"settings.openchamber.visual.section.streaming",keywords:["stream","scroll"]},{id:"chat.streaming-auto-follow",page:"chat",titleKey:"settings.openchamber.visual.field.streamingAutoFollow",descriptionKey:"settings.openchamber.visual.field.streamingAutoFollowInfo",keywords:["autoscroll","auto-scroll","follow","stick to bottom","streaming"]},{id:"chat.sticky-user-header",page:"chat",titleKey:"settings.openchamber.visual.field.stickyUserHeader",keywords:["messages","header"]},{id:"chat.prompt-navigator",page:"chat",titleKey:"settings.openchamber.visual.field.promptNavigatorEnabled",keywords:["prompt","navigator","navigation","timeline","scroll"],isAvailable:t=>!t.isVSCode},{id:"chat.collapsible-user-messages",page:"chat",titleKey:"settings.openchamber.visual.field.collapsibleUserMessages",keywords:["collapse","expand","clamp","long messages","user messages"]},{id:"chat.wide-layout",page:"chat",titleKey:"settings.openchamber.visual.field.wideChatLayout",keywords:["layout","wide","messages"]},{id:"chat.message-appearance",page:"chat",titleKey:"settings.openchamber.visual.section.messageAppearance",keywords:["layout","messages","appearance"]},{id:"chat.code-block-line-wrap",page:"chat",titleKey:"settings.openchamber.visual.field.codeBlockLineWrap",keywords:["code","wrap","line wrap","markdown"]},{id:"chat.inline-assistant-actions",page:"chat",titleKey:"settings.openchamber.visual.field.showSplitAssistantMessageActions",descriptionKey:"settings.openchamber.visual.field.showSplitAssistantMessageActionsTooltip",keywords:["copy","save image","read aloud"]},{id:"chat.draft-starters-visible",page:"chat",titleKey:"settings.openchamber.visual.field.draftStartersVisible",keywords:["starter","starters","new session","welcome","suggestions"]},{id:"chat.subagent-read-only-banner",page:"chat",titleKey:"settings.openchamber.visual.field.allowPromptingSubagentSessions",keywords:["subagent","read only","prompt","banner"]},{id:"chat.tool-file-icons",page:"chat",titleKey:"settings.openchamber.visual.field.showToolFileIcons",keywords:["tools","files","icons"]},{id:"chat.tools-and-files",page:"chat",titleKey:"settings.openchamber.visual.section.toolsAndFiles",keywords:["tools","files","dotfiles"]},{id:"chat.changed-files",page:"chat",titleKey:"settings.openchamber.visual.field.showTurnChangedFiles",keywords:["changed files","turns"]},{id:"chat.dotfiles",page:"chat",titleKey:"settings.openchamber.visual.field.showDotfiles",keywords:["hidden files"],isAvailable:t=>!t.isVSCode},{id:"chat.follow-up-behavior",page:"chat",titleKey:"settings.openchamber.visual.section.followUpBehavior",descriptionKey:"settings.openchamber.visual.field.followUpBehaviorDescription",keywords:["follow up","queue","steer","send immediately"]},{id:"chat.input-history-scope",page:"chat",titleKey:"settings.openchamber.visual.field.inputHistoryScope",descriptionKey:"settings.openchamber.visual.field.inputHistoryScopeDescription",keywords:["input history","composer history","global","session","reuse"]},{id:"chat.input-history-limit",page:"chat",titleKey:"settings.openchamber.visual.field.inputHistoryLimit",descriptionKey:"settings.openchamber.visual.field.inputHistoryLimitDescription",keywords:["history limit","prompt recall","remember prompts","composer history","submitted prompts","trim history"]},{id:"chat.persist-drafts",page:"chat",titleKey:"settings.openchamber.visual.field.persistDraftMessages",keywords:["draft","message"]},{id:"chat.composer",page:"chat",titleKey:"settings.openchamber.visual.section.composer",keywords:["input","draft","spellcheck","paste"]},{id:"chat.spellcheck",page:"chat",titleKey:"settings.openchamber.visual.field.enableSpellcheckInTextInputs",keywords:["spelling","input"],isAvailable:t=>!t.isMobile},{id:"chat.large-text-paste",page:"chat",titleKey:"settings.openchamber.visual.field.largeTextPaste",descriptionKey:"settings.openchamber.visual.field.largeTextPasteHint",keywords:["paste","clipboard","attachment","large","text","file"]},{id:"chat.enter-to-send",page:"chat",titleKey:"settings.openchamber.visual.field.enterToSend",descriptionKey:"settings.openchamber.visual.field.enterToSendHint",keywords:["enter","shift enter","ctrl enter","cmd enter","mod enter","send","newline"]},{id:"sessions.default-model",page:"sessions",titleKey:"settings.openchamber.defaults.field.defaultModel",keywords:["model","provider","new sessions"]},{id:"sessions.default-thinking",page:"sessions",titleKey:"settings.openchamber.defaults.field.defaultThinking",keywords:["thinking","reasoning","variant"]},{id:"sessions.default-agent",page:"sessions",titleKey:"settings.openchamber.defaults.field.defaultAgent",keywords:["agent","new sessions"]},{id:"sessions.deletion-dialog",page:"sessions",titleKey:"settings.openchamber.defaults.field.showDeletionDialog",keywords:["delete","confirmation"]},{id:"sessions.small-model",page:"sessions",titleKey:"settings.openchamber.defaults.smallModel.title",descriptionKey:"settings.openchamber.defaults.smallModel.description",keywords:["small model","utility","summary","recap","cheap","override"]},{id:"sessions.walkthrough-model",page:"sessions",titleKey:"settings.openchamber.defaults.walkthroughModel.title",descriptionKey:"settings.openchamber.defaults.walkthroughModel.description",keywords:["walkthrough","diff","review","changes","structured output","model","override"]},{id:"sessions.auto-cleanup",page:"sessions",titleKey:"settings.openchamber.sessionRetention.field.enableAutoCleanup",descriptionKey:"settings.openchamber.sessionRetention.tooltip",keywords:["retention","archive","delete"]},{id:"sessions.retention-period",page:"sessions",titleKey:"settings.openchamber.sessionRetention.field.retentionPeriod",keywords:["days","cleanup","retention"]},{id:"sessions.retention-action",page:"sessions",titleKey:"settings.openchamber.sessionRetention.field.whenSessionsExpire",keywords:["archive","delete","expire"]},{id:"sessions.desktop-launch-at-login",page:"general",titleKey:"settings.openchamber.desktopNetwork.field.launchAtLogin",descriptionKey:"settings.openchamber.desktopNetwork.field.launchAtLoginDescription",keywords:["desktop","startup","login","launch","background","autostart"],isAvailable:t=>t.isDesktopLocalOrigin},{id:"sessions.desktop-window-controls-position",page:"appearance",titleKey:"settings.openchamber.desktopNetwork.field.windowControlsPosition",descriptionKey:"settings.openchamber.desktopNetwork.field.windowControlsPositionDescription",keywords:["desktop","window","controls","minimize","maximize","close","titlebar","linux","windows"],isAvailable:t=>t.isDesktop&&(t.isWindows||!t.isMac)},{id:"sessions.desktop-window-controls-style",page:"appearance",titleKey:"settings.openchamber.desktopNetwork.field.windowControlsStyle",keywords:["desktop","window","controls","style","traffic","lights","classic","macos","titlebar"],isAvailable:t=>t.isDesktop&&(t.isWindows||!t.isMac)},{id:"sessions.desktop-mac-menu-bar",page:"general",titleKey:"settings.openchamber.desktopNetwork.field.macMenuBar",descriptionKey:"settings.openchamber.desktopNetwork.field.macMenuBarDescription",keywords:["desktop","menu bar","tray","status item","macos","background"],isAvailable:t=>t.isDesktopLocalOrigin&&t.isMac},{id:"sessions.desktop-minimize-to-tray",page:"general",titleKey:"settings.openchamber.desktopNetwork.field.minimizeToTray",descriptionKey:"settings.openchamber.desktopNetwork.field.minimizeToTrayDescription",keywords:["desktop","tray","system tray","minimize","close","background","windows","linux"],isAvailable:t=>t.isDesktopLocalOrigin&&(t.isWindows||t.isLinux)},{id:"sessions.desktop-keep-awake",page:"general",titleKey:"settings.openchamber.desktopNetwork.field.keepAwake",descriptionKey:"settings.openchamber.desktopNetwork.field.keepAwakeDescription",keywords:["desktop","sleep","awake","server","mobile","phone"],isAvailable:t=>t.isDesktopLocalOrigin},{id:"sessions.desktop-ui-password",page:"general",titleKey:"settings.openchamber.desktopPassword.field.password",descriptionKey:"settings.openchamber.desktopPassword.field.passwordDescription",keywords:["desktop","password","auth","login"],isAvailable:t=>t.isDesktopLocalOrigin},{id:"sessions.desktop-lan-access",page:"general",titleKey:"settings.openchamber.desktopNetwork.field.allowLanAccess",descriptionKey:"settings.openchamber.desktopNetwork.field.allowLanAccessDescription",keywords:["desktop","lan","network","phone","tablet"],isAvailable:t=>t.isDesktopLocalOrigin},{id:"sessions.opencode-binary",page:"general",titleKey:"settings.openchamber.opencodeCli.field.binaryPath",keywords:["opencode","cli","binary","path"],isAvailable:t=>!t.isVSCode},{id:"sessions.opencode-update-notifications",page:"general",titleKey:"settings.openchamber.opencodeCli.field.showUpdateNotifications",keywords:["opencode","cli","updates"],isAvailable:t=>!t.isVSCode&&!t.isWindowsArm64},{id:"sessions.agent-control-tool",page:"general",titleKey:"settings.openchamber.tools.field.agentControlTool",descriptionKey:"settings.openchamber.tools.field.agentControlToolInfo",keywords:["agent","tool","orchestration","openchamber","sessions","schedule","control"],isAvailable:t=>!t.isVSCode},{id:"sessions.agent-web-tool",page:"general",titleKey:"settings.openchamber.tools.field.agentWebTool",descriptionKey:"settings.openchamber.tools.field.agentWebToolInfo",keywords:["agent","tool","web","browser","page","preview","openchamber"],isAvailable:t=>!t.isVSCode},{id:"sessions.agent-memory-tool",page:"general",titleKey:"settings.openchamber.tools.field.agentMemoryTool",descriptionKey:"settings.openchamber.tools.field.agentMemoryToolInfo",keywords:["agent","tool","memory","remember","recall","preferences","openchamber"],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.openchamber.git.changesViewTitle",keywords:["changes","flat list","tree view"]},{id:"git.gitmoji",page:"git",titleKey:"settings.openchamber.git.enableGitmoji",keywords:["commit","emoji"]},{id:"git.gitignored-files",page:"git",titleKey:"settings.openchamber.git.showGitignored",keywords:["ignored","files","gitignore"]},{id:"usage.work-status-panel",page:"usage",titleKey:"settings.usage.page.options.showInWorkStatus",descriptionKey:"settings.usage.page.options.showInWorkStatusTooltip",keywords:["quota","work","status","panel"]},{id:"usage.model-quotas",page:"usage",titleKey:"settings.usage.page.section.modelQuotas",keywords:["models","quota","limits","tokens"]},{id:"projects.name",page:"projects",titleKey:"settings.projects.page.field.projectName",keywords:["label","display name","project metadata"]},{id:"projects.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.openchamber.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",".openchamber","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.openchamber.keyboardShortcuts.title",descriptionKey:"settings.openchamber.keyboardShortcuts.tooltip",keywords:["keyboard","hotkeys","bindings"]},{id:"voice.playback",page:"voice",titleKey:"settings.voice.page.section.playbackAndSummary",keywords:["tts","read aloud","voice","provider","speech rate","speech pitch","speech volume","tts input mode","markdown"]},{id:"voice.speech-recognition",page:"voice",titleKey:"settings.voice.page.section.speechRecognition",keywords:["stt","dictation","voice input","transcribe","whisper","parakeet","microphone"]},{id:"tunnel.provider",page:"tunnel",titleKey:"settings.openchamber.tunnel.field.provider",descriptionKey:"settings.openchamber.tunnel.description",keywords:["remote access","cloudflare","ngrok"],isAvailable:t=>!t.isVSCode},{id:"tunnel.type",page:"tunnel",titleKey:"settings.openchamber.tunnel.field.tunnelType",keywords:["quick","managed remote","managed local"],isAvailable:t=>!t.isVSCode},{id:"tunnel.ttl",page:"tunnel",titleKey:"settings.openchamber.tunnel.field.connectLinkTtl",descriptionKey:"settings.openchamber.tunnel.field.tunnelSessionTtl",keywords:["expiry","expiration","session ttl","connect link ttl"],isAvailable:t=>!t.isVSCode},{id:"tunnel.managed-remote",page:"tunnel",titleKey:"settings.openchamber.tunnel.section.savedManagedRemoteTunnels",keywords:["cloudflare","hostname","token","managed remote"],isAvailable:t=>!t.isVSCode},{id:"tunnel.managed-local-config",page:"tunnel",titleKey:"settings.openchamber.tunnel.field.configurationFile",descriptionKey:"settings.openchamber.tunnel.note.managedLocalUsesConfig",keywords:["cloudflared","config","yaml","json","managed local"],isAvailable:t=>!t.isVSCode},{id:"tunnel.start",page:"tunnel",titleKey:"settings.openchamber.tunnel.actions.startTunnel",descriptionKey:"settings.openchamber.tunnel.note.connectLinksOneTime",keywords:["connect link","qr code","public url","remote access"],isAvailable:t=>!t.isVSCode},{id:"notifications.delivery",page:"notifications",titleKey:"settings.notifications.page.delivery.title",keywords:["desktop notifications","system notifications"]},{id:"notifications.events",page:"notifications",titleKey:"settings.notifications.page.events.title",keywords:["completion","subtasks","errors","questions"]},{id:"notifications.push",page:"notifications",titleKey:"settings.notifications.page.push.title",keywords:["background","push"],isAvailable:t=>t.isWeb&&!t.isDesktop&&!t.isVSCode},{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 ml(t){return t.trim().toLocaleLowerCase()}function mx({query:t,runtimeCtx:e,visiblePageSlugs:a,t:n,getPageTitle:r}){const i=ml(t);if(!i)return[];const l=a?new Set(a):null,g=i.split(/\s+/).filter(Boolean);return px.flatMap(c=>{if(l&&!l.has(c.page))return[];const v=ma(c.page);if(!v||v.isAvailable&&!v.isAvailable(e)||c.isAvailable&&!c.isAvailable(e))return[];const m=n(c.titleKey),y=c.descriptionKey?n(c.descriptionKey):null,d=ml([m,y,r(c.page),...c.keywords??[]].filter(Boolean).join(" "));return g.every(C=>d.includes(C))?[{...c,title:m,description:y,pageTitle:r(c.page)}]:[]})}const ul=256,gl=280,pc="__openchamberSettingsDetail",ux=["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 yr(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(!yr(t))return null;const e=t[pc];if(!yr(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"||!yr(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=ja(),c=e??g.isMobile,v=Vn(El),m=ie(Z=>Z.settingsPage),y=ie(Z=>Z.isSettingsDialogOpen),d=ie(Z=>Z.setSettingsPage),C=ie(Z=>Z.shortcutOverrides.open_settings),f=Fl(m),[P,x]=o.useState(r),N=o.useRef(r==="nav"?f:null);o.useEffect(()=>{!c&&f==="home"&&d("general")},[c,d,f]);const[u,A]=o.useState(""),[R,I]=o.useState(null),[w,h]=o.useState(0),j=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.__OPENCHAMBER_PLATFORM__==="darwin",[]),G=o.useMemo(()=>as()&&typeof window<"u"&&window.__OPENCHAMBER_PLATFORM__==="win32",[]),D=o.useMemo(()=>as()&&typeof window<"u"&&window.__OPENCHAMBER_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(ux.map((se,ve)=>[se,ve]));return ee.slice().sort((se,ve)=>(Z.get(se.slug)??999)-(Z.get(ve.slug)??999))},[ee]),re=Gs(Z=>Z.activeProjectId),_=_s();o.useEffect(()=>{if(!(!y&&!J.isVSCode&&!a)){if(f==="agents"){Hn.getState().loadAgents(_);return}if(f==="commands"){ba.getState().loadCommands(_);return}if(f==="mcp"){va.getState().loadMcpConfigs({directory:_});return}if(f==="plugins"){us.getState().loadPlugins();return}(f==="skills.installed"||f==="skills.catalog")&&(Hs.getState().loadSkills(_),hn.getState().loadCatalog()),f==="snippets"&&Si.getState().loadSnippets()}},[re,y,a,J.isVSCode,_,f]);const H=o.useCallback(Z=>{if(d(Z),N.current=Z,!c)return;const se=ma(Z);if(!se||se.slug==="home"){x("nav");return}x(se.kind==="split"?"page-sidebar":"page-content")},[c,d]),z=o.useMemo(()=>ma(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(()=>mx({query:u,runtimeCtx:{...J,isDesktopLocalOrigin:$,isMac:k,isWindows:G,isLinux:D,isWindowsArm64:L},visiblePageSlugs:n,t:l,getPageTitle:te}),[te,L,$,k,G,D,J,u,l,n]),ne=o.useCallback(Z=>{if(Z.id.startsWith("agents.")){const se=Hn.getState(),ve=La("new-agent",se.agents.map(ye=>ye.name));return se.setAgentDraft({name:ve,scope:"user"}),se.setSelectedAgent(ve),Z.id==="agents.create"?"agents.name":Z.id}if(Z.id.startsWith("commands.")){const se=ba.getState(),ve=La("new-command",se.commands.map(ye=>ye.name));return se.setCommandDraft({name:ve,scope:"user"}),se.setSelectedCommand(ve),Z.id==="commands.create"?"commands.name":Z.id}if(Z.id.startsWith("mcp.")){const se=va.getState(),ve=La("new-mcp-server",se.mcpServers.map(ye=>ye.name));return se.setMcpDraft({name:ve,scope:"user",type:"local",command:[],url:"",environment:[],headers:[],oauthEnabled:!0,oauthClientId:"",oauthClientSecret:"",oauthScope:"",oauthRedirectUri:"",timeout:"",enabled:!0}),se.setSelectedMcp(ve),Z.id==="mcp.create"?"mcp.server":Z.id}if(Z.id.startsWith("snippets.")){const se=Si.getState(),ve=La("new-snippet",se.snippets.map(ye=>ye.name));return se.setSnippetDraft({name:ve,scope:"global"}),se.setSelectedSnippet(ve),Z.id==="snippets.create"?"snippets.content":Z.id}if(Z.id.startsWith("skills.")){const se=Hs.getState(),ve=La("new-skill",se.skills.map(ye=>ye.name));return se.setSkillDraft({name:ve,scope:"user",source:"opencode",description:"",instructions:""}),se.setSelectedSkill(ve),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},[]),ue=o.useMemo(()=>{const Z=[],se=new Map;for(const ve of Y){let ye=se.get(ve.page);ye||(ye={page:ve.page,pageTitle:ve.pageTitle,results:[]},se.set(ve.page,ye),Z.push(ye)),ye.results.push(ve)}return Z},[Y]);o.useEffect(()=>{h(0),S.current=0,M.current=!1},[u]),o.useEffect(()=>{S.current=w},[w]),o.useEffect(()=>{T.current[w]?.scrollIntoView({block:"nearest"})},[w]),o.useEffect(()=>{w>=Y.length&&h(Math.max(0,Y.length-1)),T.current.length=Y.length},[w,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("openchamber:settings-open-plugin-add"))},50)},[c,H,ne]),xe=o.useCallback(Z=>{if(u.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,ve=Y[se]??Y[0];ve&&de(ve)}}}},[de,u,Y]);o.useEffect(()=>{const Z=R;if(!Z)return;let se=!1;const ve=window.requestAnimationFrame(()=>{if(se)return;const ye=typeof CSS<"u"&&CSS.escape?CSS.escape(Z):Z.replace(/[^a-zA-Z0-9_-]/g,"\\$&"),Re=j.current?.querySelector(`[data-settings-item="${ye}"]`);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(ve)}},[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(Su,{onItemSelect:se.onItemSelect});case"agents":return s.jsx(yp,{onItemSelect:se.onItemSelect});case"commands":return s.jsx(Kp,{onItemSelect:se.onItemSelect});case"mcp":return s.jsx(Gp,{onItemSelect:se.onItemSelect});case"plugins":return s.jsx(Mm,{onItemSelect:se.onItemSelect});case"skills.installed":return s.jsx(qm,{onItemSelect:se.onItemSelect});case"providers":return s.jsx(Xu,{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=ma(Z);if(se&&!hl(se,J))return ae();switch(Z){case"projects":return s.jsx(Tu,{});case"remote-instances":return s.jsx(Qu,{});case"agents":return s.jsx(Ep,{});case"behavior":return s.jsx(Fp,{});case"commands":return s.jsx(Hp,{});case"mcp":return s.jsx(gm,{});case"plugins":return s.jsx(Hm,{});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(mh,{});case"integrations":return s.jsx(Ih,{});case"general":case"appearance":case"chat":case"shortcuts":case"sessions":case"notifications":case"voice":case"tunnel":{const ve=K[Z]??"visual";return s.jsx(Jf,{section:ve})}default:return null}},[K,ae,J,l]);o.useEffect(()=>{if(!c||P!=="nav"||f==="home"||N.current===f)return;const Z=ma(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:Gn(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(),[pc]:{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(()=>{j.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(ma(f)?.kind!=="split")return;if(or(se.state)?.page===f){x("page-content");return}x(ye=>ye==="page-content"?"page-sidebar":ye)};return window.addEventListener("popstate",Z),()=>{window.removeEventListener("popstate",Z)}},[c,J.isVSCode,f]);const Ve=()=>{const Z=u.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:u,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(bs,{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 ue.map(ve=>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:ve.pageTitle}),ve.results.map(ye=>{const Re=se;se+=1;const Fe=Re===w,Ke=!!ye.description;return s.jsxs("button",{type:"button",ref:Ee=>{T.current[Re]=Ee},onMouseMove:()=>{M.current=!1,h(Re)},onClick:()=>de(ye),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:ye.title}),Ke&&s.jsx("span",{className:"typography-micro text-muted-foreground/70 line-clamp-2",children:ye.description})]},ye.id)})]},ve.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 ye of U){const Re=ye.group,Fe=se.get(Re);Fe?Fe.push(ye):se.set(Re,[ye])}return gx.map(ye=>({group:ye,pages:se.get(ye)??[]})).filter(ye=>ye.pages.length>0).map(({group:ye,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.${ye}`)}),Re.map(Ke=>{const Ee=f===Ke.slug&&!(c&&P==="nav"),je=Qd(Ke.slug);return!je&&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:je,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)})]},ye))})()})}),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||v>0)&&s.jsx(rx,{})})})]})},Ge=()=>{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(jn,{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(bs,{outerClassName:"flex-1 min-h-0",className:"bg-background",disableHorizontal:!0,children:s.jsx(jn,{children:se})})}return s.jsx(bs,{outerClassName:"flex-1 min-h-0",className:"bg-background",disableHorizontal:!0,children:s.jsx(jn,{children:le(f,{onItemSelect:ke})})})}const Z=ge(f);return s.jsx(bs,{outerClassName:"flex-1 min-h-0",className:"bg-background",disableHorizontal:!0,children:s.jsx(jn,{children:Z})})},be=()=>!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(jn,{children:le(f,{})})}),s.jsx(bs,{outerClassName:"flex-1 min-h-0",className:"bg-background",disableHorizontal:!0,children:s.jsx(jn,{children:ge(f)})})]}):s.jsx(bs,{outerClassName:"h-full min-h-0",className:"bg-background",disableHorizontal:!0,children:s.jsx(jn,{children:ge(f)})});return s.jsxs("div",{ref:j,"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?Ge():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:`${ul}px`,minWidth:`${ul}px`,borderColor:"var(--interactive-border)"},children:s.jsx(jn,{children:Ve()})}),s.jsx("div",{className:"flex-1 overflow-hidden bg-background",children:be()})]})})]})};export{Ul as A,Ax as S};
|