@openchamber/web 1.21.0 → 1.21.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/bin/cli.test.js +35 -0
- package/bin/lib/DOCUMENTATION.md +12 -0
- package/bin/lib/cli-settings-accessors.js +111 -0
- package/bin/lib/cli-settings-accessors.test.js +189 -0
- package/bin/lib/cli-startup.js +29 -9
- package/bin/lib/commands-connect-url.js +12 -14
- package/dist/assets/{CodeMirrorCommentWidgets-C2BopIs3.js → CodeMirrorCommentWidgets-BGj8TJxW.js} +1 -1
- package/dist/assets/CommitSection-DwGiXyjf.js +1 -0
- package/dist/assets/{DiffView-D5cvbEPb.js → DiffView-Db6bjVv1.js} +3 -3
- package/dist/assets/FilesView-DQOa7Lgz.js +17 -0
- package/dist/assets/GitView-CHzJxTi0.js +6 -0
- package/dist/assets/{JsonTreeView-osju7J70.js → JsonTreeView-CggOsLot.js} +1 -1
- package/dist/assets/MarkdownImageGallery-DoZpaHev.js +1 -0
- package/dist/assets/MarkdownRendererImpl-B5Y5xCOz.js +12 -0
- package/dist/assets/{OnboardingScreen-w2VG4fWY.js → OnboardingScreen-C98d69Fp.js} +1 -1
- package/dist/assets/{PatchDiff-Dan3mADn.js → PatchDiff-DJYMUiXA.js} +1 -1
- package/dist/assets/{PierreDiffViewer-CGoI2v0q.js → PierreDiffViewer-CY2bx_SB.js} +3 -3
- package/dist/assets/PlanView-PkiOY_9H.js +5 -0
- package/dist/assets/SettingsView-D-K3ELCM.js +28 -0
- package/dist/assets/{SettingsWindow-DXF-MTHG.js → SettingsWindow-oyOm2fHR.js} +1 -1
- package/dist/assets/{ToolOutputDialog-DrCa1JRk.js → ToolOutputDialog-lKyeQTPL.js} +6 -6
- package/dist/assets/{ToolPartDiffPreview-B_tfvlNF.js → ToolPartDiffPreview-C7kBQNAA.js} +2 -2
- package/dist/assets/{VirtualizedFileDiff-CN_BctrR.js → VirtualizedFileDiff-BP7ebDFF.js} +1 -1
- package/dist/assets/{WalkthroughView-D9Q4lr5x.js → WalkthroughView-MuJodAHD.js} +2 -2
- package/dist/assets/{computeVirtualFileMetrics-Gi1d5eU1.js → computeVirtualFileMetrics-CZ0xPeaT.js} +1 -1
- package/dist/assets/{contextPanelEmbeddedChat-CpzVNWAv.js → contextPanelEmbeddedChat-C9abMBTb.js} +1 -1
- package/dist/assets/de-CEoCz3j6.js +9 -0
- package/dist/assets/es-DwyXCqaL.js +15 -0
- package/dist/assets/{fr-5qJM0nFS.js → fr-CS7Csln9.js} +5 -5
- package/dist/assets/index-CUKcHnUA.css +1 -0
- package/dist/assets/{index-Brm3X9rs.js → index-CaPAjwXQ.js} +1 -1
- package/dist/assets/index-DIvDEKE-.js +7 -0
- package/dist/assets/{isDiffPlainText-pH9kAJQH.js → isDiffPlainText-ZBvDxhVB.js} +1 -1
- package/dist/assets/{isFilePlainText-CVKy_dgB.js → isFilePlainText-DiLRrkJr.js} +1 -1
- package/dist/assets/ja-vnwqLcx6.js +15 -0
- package/dist/assets/ko-CXuSfZv5.js +15 -0
- package/dist/assets/{main-vUCh0VB0.js → main-D5RWr6sJ.js} +2 -2
- package/dist/assets/main-DLlfDjQ_.js +926 -0
- package/dist/assets/{markdown-shiki.worker-CKGJ1J33.js → markdown-shiki.worker-D5fBU-lw.js} +5 -5
- package/dist/assets/markdownCore-CcTcLsQF.js +3 -0
- package/dist/assets/{miniChat-BlzGEYgE.js → miniChat-CqR3icsk.js} +2 -2
- package/dist/assets/{mobile-CkX6H-IT.js → mobile-RN_UTTlB.js} +2 -2
- package/dist/assets/{patchFileDiff-BCTsE43U.js → patchFileDiff-CjRR5ESs.js} +3 -3
- package/dist/assets/pl-BJxry0Mi.js +15 -0
- package/dist/assets/pt-BR-DxLmkhdv.js +15 -0
- package/dist/assets/{renderElectronMiniChatApp-CJYe_KOL.js → renderElectronMiniChatApp-1wC94fQK.js} +2 -2
- package/dist/assets/renderMobileApp-ltva2Plg.js +25 -0
- package/dist/assets/runtimeEndpointReset-D6SmNZaP.js +15 -0
- package/dist/assets/{scheduledTasksApi-CAGPh_gZ.js → scheduledTasksApi-mjMDet_H.js} +1 -1
- package/dist/assets/{shikiHighlight-BgTPSITe.js → shikiHighlight-fGmFkxAM.js} +1 -1
- package/dist/assets/tr-5Mk_hQ2Q.js +6 -0
- package/dist/assets/uk-ClgQjmlw.js +15 -0
- package/dist/assets/{useAppFontEffects-Cll4gnsh.js → useAppFontEffects-KP8_yiGW.js} +143 -141
- package/dist/assets/{useInlineCommentController-DFFv0hae.js → useInlineCommentController-HIjtuhxD.js} +2 -2
- package/dist/assets/useRootScrollLock-BSiQ5F75.js +1 -0
- package/dist/assets/{vendor-base-ui-_6j2xOWl.js → vendor-base-ui-BeMD8X_w.js} +1 -1
- package/dist/assets/{vendor-codemirror-language-data-DkQX2EBa.js → vendor-codemirror-language-data-DrTPkHl4.js} +2 -2
- package/dist/assets/{vendor-floating-ui-core-CXmKXOXc.js → vendor-floating-ui-core-PuGzNPnN.js} +1 -1
- package/dist/assets/{vendor-floating-ui-dom-WyXykhNi.js → vendor-floating-ui-dom-BTvzWks8.js} +1 -1
- package/dist/assets/{vendor-floating-ui-react-dom-DKpLs02S.js → vendor-floating-ui-react-dom-DxYCWdHj.js} +1 -1
- package/dist/assets/{vendor-floating-ui-utils-BzXdqYpP.js → vendor-floating-ui-utils-D6FqdtJt.js} +1 -1
- package/dist/assets/vendor-linkify-it-DZCzzDkK.js +1 -0
- package/dist/assets/vendor-marked-linkify-it-CXI_LHIE.js +1 -0
- package/dist/assets/vendor-uc.micro-BAd0H0z4.js +1 -0
- package/dist/assets/{web-components-DLnGY4fs.js → web-components-DOXvU-tB.js} +1 -1
- package/dist/assets/zh-CN-Ba6y8H-i.js +15 -0
- package/dist/assets/zh-TW-Dv8yyhN1.js +15 -0
- package/dist/index.html +5 -5
- package/dist/mini-chat.html +3 -3
- package/dist/mobile.html +3 -3
- package/dist/site.webmanifest +1 -1
- package/dist/sw.js +1 -1
- package/package.json +2 -2
- package/public/site.webmanifest +1 -1
- package/server/index.js +2 -2
- package/server/lib/cloudflare-tunnel.js +1 -1
- package/server/lib/fs/DOCUMENTATION.md +1 -0
- package/server/lib/fs/routes.js +21 -0
- package/server/lib/fs/routes.test.js +89 -3
- package/server/lib/git/DOCUMENTATION.md +4 -3
- package/server/lib/git/service.js +128 -6
- package/server/lib/git/service.test.js +191 -1
- package/server/lib/markdown-image-grants/DOCUMENTATION.md +4 -0
- package/server/lib/markdown-image-grants/routes.js +3 -1
- package/server/lib/markdown-image-grants/routes.test.js +14 -0
- package/server/lib/openchamber-sessions/routes.js +4 -1
- package/server/lib/openchamber-sessions/routes.test.js +23 -0
- package/server/lib/opencode/env-runtime.js +17 -1
- package/server/lib/opencode/env-runtime.test.js +56 -0
- package/server/lib/opencode/lifecycle.js +48 -9
- package/server/lib/opencode/lifecycle.test.js +125 -1
- package/server/lib/opencode/managed-process-registry.d.ts +13 -0
- package/server/lib/opencode/managed-process-registry.js +213 -163
- package/server/lib/opencode/managed-process-registry.test.mjs +285 -0
- package/server/lib/opencode/project-directory-runtime.js +16 -11
- package/server/lib/opencode/project-directory-runtime.test.js +32 -12
- package/server/lib/opencode/pwa-manifest-routes.js +1 -1
- package/server/lib/opencode/routes-upgrade.test.js +96 -12
- package/server/lib/opencode/routes.js +53 -5
- package/server/lib/opencode/settings-helpers.js +3 -0
- package/server/lib/opencode/settings-helpers.test.js +10 -0
- package/server/lib/opencode/theme-runtime.js +1 -1
- package/server/lib/opencode/theme-runtime.test.js +129 -0
- package/server/lib/quota/DOCUMENTATION.md +19 -0
- package/server/lib/quota/providers/copilot.js +26 -10
- package/server/lib/quota/providers/copilot.test.js +78 -0
- package/server/lib/small-model/DOCUMENTATION.md +11 -5
- package/server/lib/small-model/call.js +64 -20
- package/server/lib/small-model/call.test.js +184 -2
- package/server/lib/tunnels/install-help.js +2 -2
- package/server/lib/tunnels/install-help.test.js +9 -0
- package/server/lib/walkthrough/languages.js +1 -0
- package/dist/assets/CommitSection-HJeMUAWb.js +0 -1
- package/dist/assets/FilesView-DPU8aNPL.js +0 -17
- package/dist/assets/GitView-Ct6xWrVH.js +0 -6
- package/dist/assets/MarkdownImageGallery-EujHSZ2M.js +0 -1
- package/dist/assets/MarkdownRendererImpl-CPzu4kIr.js +0 -12
- package/dist/assets/PlanView-Dgg-WTEc.js +0 -4
- package/dist/assets/SessionSwitcherDropdown-CJTrc8K7.js +0 -1
- package/dist/assets/SettingsView-D9yRuFZw.js +0 -28
- package/dist/assets/de-B_LdJwEM.js +0 -9
- package/dist/assets/es-CubfsAYV.js +0 -15
- package/dist/assets/index-BW82eK5v.css +0 -1
- package/dist/assets/index-rlLjZUM5.js +0 -7
- package/dist/assets/ja-DJYIBUlH.js +0 -15
- package/dist/assets/ko-DcUBkB7y.js +0 -15
- package/dist/assets/main-DLBxKIoX.js +0 -926
- package/dist/assets/markdownCore-DG6GHLF4.js +0 -3
- package/dist/assets/pl-rB6BLcio.js +0 -15
- package/dist/assets/pt-BR-DcwtlO-o.js +0 -15
- package/dist/assets/renderMobileApp-hQJTnr8B.js +0 -25
- package/dist/assets/runtimeEndpointReset-BDh7r8BL.js +0 -15
- package/dist/assets/uk-INZlFD9A.js +0 -15
- package/dist/assets/zh-CN-Dzda8xa1.js +0 -15
- package/dist/assets/zh-TW-Cwn3rNYZ.js +0 -15
|
@@ -1,28 +0,0 @@
|
|
|
1
|
-
import{R as o,j as s,f as mt,r as Xe}from"./vendor-react-BUCujlKS.js";import{f as ot,B,I as L,o as An,bj as da,t as D,O as Xl,fs as ec,en as Be,ft as Rt,b as Qs,h as je,fu as tc,aZ as tn,a$ as sn,fv as sc,b0 as nn,ee as _n,fw as sl,fx as nc,fy as ia,fz as rn,bX as Vs,bz as zt,bA as _t,bB as Gt,bC as qt,bD as Wt,bE as ms,S as Ye,fA as Ra,aY as an,e2 as Qi,fB as nl,fC as Ln,ep as ss,fD as Js,l as tt,eB as Qt,bN as Ot,bO as Lt,ez as Jt,bP as Ht,bQ as Ft,bR as ut,fE as es,bS as Es,dq as Ea,eA as Cn,eD as oa,eC as Pn,fF as ks,dv as Is,fG as ac,cf as ht,fH as al,fI as ic,fJ as Un,fK as ii,fL as rc,fM as la,fN as $s,fO as ra,fP as il,fQ as cr,dr as rl,fR as dn,a3 as ca,a2 as Rs,fS as ol,fT as Cr,a8 as oc,e0 as ll,g as Ta,fU as lc,fV as en,d$ as cc,fW as dc,fX as pc,fY as dr,a4 as pr,a5 as mr,a6 as cl,fZ as ln,_ as ri,b7 as ur,L as gr,f_ as Pr,aj as mc,bT as uc,cw as gc,Q as hc,N as fc,R as xc,V as dl,f$ as bc,g0 as vc,bK as yc,bU as Yi,g1 as pl,a7 as Pi,g2 as ml,P as Fn,g3 as Sn,em as Ks,Z as jc,n as us,dW as oi,x as ul,w as wc,i as kc,j as Nc,dX as Sc,p as Cc,g4 as Pc,g5 as Ic,g6 as Ir,dw as gl,g7 as Ac,g8 as Ii,g9 as Ar,ga as Ec,gb as Tc,gc as Dc,gd as Mc,dC as ci,ge as Ns,gf as _s,gg as wn,gh as kn,aq as xa,gi as Nn,gj as xn,gk as Oa,gl as Er,gm as ba,gn as va,bw as $n,go as Rc,gp as Oc,gq as Lc,gr as Fc,gs as Ai,gt as Tr,gu as Kc,gv as Uc,gw as zc,gx as _c,gy as Dr,y as $c,m as Mr,cL as Vc,gz as Bc,gA as Ei,gB as Rr,dZ as Hc,gC as di,gD as Gc,gE as qc,gF as Wc,gG as Jc,gH as Qc,gI as Ti,cg as Yc,bx as hl,gJ as fl,gK as Zc,e7 as Xc,al as bn,an as ed}from"./useAppFontEffects-Cll4gnsh.js";import{r as pt,u as ce,F as vs,cx as td,cy as Or,w as cn,ap as Di,W as sd,$ as Nt,o as In,z as bs,K as Lr,c1 as Fr,c4 as Kr,L as ya,p as nd,cz as ad,j as id,c0 as aa,cA as rd,a8 as od,c3 as ld,cB as cd,cC as dd,s as pd,e as La,c2 as md,A as Fa,cD as xl,S as ud,cE as gd,R as hd,aE as Ur,aw as fd,_ as zn,cF as xd,v as bl,cG as zr,cw as _r,cH as $r,au as Vr,cI as bd,cJ as vd,cK as Br,b as yd,as as vl,cL as yl,cM as jd,cN as wd,cO as kd,cP as Nd,cQ as Sd,cR as Cd,aj as Pd,i as jl}from"./index-rlLjZUM5.js";import{u as Id,U as Hr,v as Vn,x as Bn,y as Hn,z as Gn,b as hr,p as qn,s as Wn,q as Jn,I as Kn,E as Ad,h as As,G as Ed,J as Ia,K as wl,A as Td,B as Dd}from"./runtimeEndpointReset-BDh7r8BL.js";import{u as Ms,c as kl,d as Md,p as Rd}from"./vendor-zustand-BAGL70zf.js";import{s as Od,p as Ld}from"./vendor-yaml-3778uTud.js";import{c as Gr,s as Fd,C as qr,P as Kd}from"./shikiHighlight-BgTPSITe.js";import{getResolvedShikiTheme as Ud}from"./appThemeRegistry-BK0dHKa6.js";import{E as Wr}from"./vendor-codemirror-view-CiLROUVV.js";import{Q as Nl}from"./vendor-qrcode-DTJ12-WC.js";const Jr=()=>{const{t}=ot(),[e,a]=o.useState(null);o.useEffect(()=>{let i=!1;const r=typeof AbortController<"u"?new AbortController:void 0;return(async()=>{try{const h=await pt("/api/system/info",{signal:r?.signal,headers:{Accept:"application/json"}});if(!h.ok)return;const d=await h.json().catch(()=>null);if(!d||i)return;const x=typeof d.port=="number"&&Number.isFinite(d.port)&&d.port>0?d.port:null,c=typeof d.tunnelUrl=="string"&&d.tunnelUrl.trim().length>0?d.tunnelUrl.trim():null;a({port:x,tunnelUrl:c})}catch{}})(),()=>{i=!0,r?.abort()}},[]);const n=[];return e?.port!==null&&e?.port!==void 0&&n.push({key:"application",label:t("settings.openchamber.about.field.applicationUrl"),url:`http://localhost:${e.port}/`}),e?.tunnelUrl&&n.push({key:"tunnel",label:t("settings.openchamber.about.field.tunnelUrl"),url:e.tunnelUrl}),n.length===0?null:s.jsx("div",{className:"flex flex-wrap items-center gap-2",children:n.map(i=>s.jsxs(B,{type:"button",variant:"outline",size:"sm",title:i.label,className:"max-w-full gap-1.5 px-2.5",onClick:()=>{An(i.url)},children:[s.jsx(L,{name:"external-link",className:"size-3.5 shrink-0"}),s.jsx("span",{className:"max-w-64 truncate font-mono typography-micro",children:i.url})]},i.key))})},Qr="https://github.com/openchamber/openchamber",zd="https://discord.gg/ZYRSdnwwKA",Yr="https://x.com/openchamber_dev",_d=800,Sl=({initialUpdateDialogOpen:t=!1})=>{const{t:e}=ot(),[a,n]=o.useState(t),[i,r]=o.useState(!1),[l,h]=o.useState(null),[d,x]=o.useState(null),c=Id(Ms(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:v}=da(),p=l||c.info?.currentVersion||"unknown";o.useEffect(()=>{let P=!1;return(async()=>{try{const k=await pt("/api/system/info",{method:"GET",headers:{Accept:"application/json"}});if(!k.ok)return;const g=await k.json().catch(()=>null),E=typeof g?.openchamberVersion=="string"&&g.openchamberVersion.trim().length>0?g.openchamberVersion.trim():null;P||h(E)}catch{P||h(null)}})(),()=>{P=!0}},[]),o.useEffect(()=>{let P=!1;return(async()=>{try{const k=await pt("/api/opencode/upgrade-status",{method:"GET",headers:{Accept:"application/json"}});if(!k.ok)return;const g=await k.json().catch(()=>null),E=typeof g?.currentVersion=="string"&&g.currentVersion.trim().length>0?g.currentVersion.trim():null;P||x(E)}catch{P||x(null)}})(),()=>{P=!0}},[]);const A=o.useRef(!1);o.useEffect(()=>{if(c.checking)r(!0),A.current=!0;else if(i){const P=setTimeout(()=>{r(!1),A.current&&!c.available&&!c.error&&(D.success(e("settings.openchamber.about.toast.latestVersion")),A.current=!1)},_d);return()=>clearTimeout(P)}},[e,c.checking,i,c.available,c.error]);const b=c.checking||i;return v?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(Xl,{width:72,height:72}),s.jsx("h2",{className:`mt-4 ${ec}`,children:"OpenChamber"}),s.jsxs("div",{className:"mt-2 space-y-1 typography-ui text-muted-foreground",children:[s.jsx("p",{children:e("aboutDialog.openChamberVersionLabel",{version:p})}),s.jsx("p",{children:e("aboutDialog.openCodeVersionLabel",{version:d||e("settings.openchamber.about.state.unknown")})})]}),s.jsx(Jr,{})]}),s.jsxs("div",{className:"flex justify-center",children:[!c.available&&!c.error&&s.jsxs(B,{type:"button",variant:"outline",size:"sm",onClick:()=>c.checkForUpdates(),disabled:b,className:"h-10 w-auto justify-center gap-2 rounded-xl px-4",children:[b?s.jsx(L,{name:"loader",className:"size-4 animate-spin"}):s.jsx(L,{name:"refresh",className:"size-4"}),e(b?"settings.openchamber.about.state.checking":"settings.openchamber.about.actions.checkForUpdates")]}),!b&&c.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(L,{name:"download",className:"size-4"}),e("settings.openchamber.about.actions.updateToVersion",{version:c.info?.version||""})]})]}),c.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:c.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:Qr,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(L,{name:"github-fill",className:"size-5"}),s.jsx("span",{children:"GitHub"})]}),s.jsxs("a",{href:zd,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(L,{name:"discord-fill",className:"size-5"}),s.jsx("span",{children:"Discord"})]})]}),s.jsxs("a",{href:Yr,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(L,{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(Hr,{open:a,onOpenChange:n,info:c.info,downloading:c.downloading,downloaded:c.downloaded,progress:c.progress,error:c.error,onDownload:c.downloadUpdate,onRestart:c.restartToUpdate,runtimeType:c.runtimeType})]}):s.jsxs(Be,{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:Rt,children:e("settings.openchamber.about.field.version")}),s.jsx("span",{className:"typography-meta text-muted-foreground font-mono",children:p})]}),s.jsxs("div",{className:"flex min-w-0 flex-col",children:[s.jsx("span",{className:Rt,children:e("settings.openchamber.about.field.openCodeVersion")}),s.jsx("span",{className:"typography-meta text-muted-foreground font-mono",children:d||e("settings.openchamber.about.state.unknown")})]}),s.jsxs("div",{className:"flex items-center gap-3",children:[c.checking&&s.jsxs("div",{className:"flex items-center gap-2 text-muted-foreground",children:[s.jsx(L,{name:"loader",className:"h-4 w-4 animate-spin"}),s.jsx("span",{className:"typography-meta",children:e("settings.openchamber.about.state.checking")})]}),!c.checking&&c.available&&s.jsxs(B,{size:"sm",variant:"default",onClick:()=>n(!0),children:[s.jsx(L,{name:"download",className:"h-4 w-4 mr-1"}),e("settings.openchamber.about.actions.updateToVersion",{version:c.info?.version||""})]}),!c.checking&&!c.available&&!c.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:()=>c.checkForUpdates(),disabled:c.checking,children:e("settings.openchamber.about.actions.checkForUpdates")})]})]}),c.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:c.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:Rt,children:e("settings.openchamber.about.field.instanceUrls")}),s.jsx(Jr,{})]}),s.jsxs("div",{className:"flex items-center gap-4 px-4 py-4",children:[s.jsxs("a",{href:Qr,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(L,{name:"github-fill",className:"h-4 w-4"}),s.jsx("span",{children:"GitHub"})]}),s.jsxs("a",{href:Yr,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(L,{name:"twitter-xfill",className:"h-4 w-4"}),s.jsx("span",{children:"@openchamber_dev"})]})]})]}),s.jsx(Hr,{open:a,onOpenChange:n,info:c.info,downloading:c.downloading,downloaded:c.downloaded,progress:c.progress,error:c.error,onDownload:c.downloadUpdate,onRestart:c.restartToUpdate,runtimeType:c.runtimeType})]})},$d=(t,e,a)=>t&&e.some(i=>i.path===t)?t:(e.find(i=>i.id===a)??e[0])?.path??null,Us=()=>{const t=mt.c(4),e=ce(Vd),a=Qs(Bd),n=Qs(Hd);let i;return t[0]!==n||t[1]!==a||t[2]!==e?(i=$d(e,a,n),t[0]=n,t[1]=a,t[2]=e,t[3]=i):i=t[3],i};function Vd(t){return t.settingsProjectPath}function Bd(t){return t.projects}function Hd(t){return t.activeProjectId}const Cl=t=>t.trim(),Ka=t=>{const e=mt.c(40),{className:a}=t,{t:n}=ot(),i=Qs(Gd),r=Us(),l=ce(qd),h=vs();let d;e[0]!==i?(d=[...i].sort(Wd),e[0]=i,e[1]=d):d=e[1];const x=d;let c;e:{if(x.length===0){c=null;break e}let G;e[2]!==r||e[3]!==x?(G=x.find(S=>S.path===r)??x[0],e[2]=r,e[3]=x,e[4]=G):G=e[4],c=G}const v=c;if(h||x.length===0)return null;let p;e[5]!==v||e[6]!==n?(p=v?.label&&v.label.trim().length>0?v.label:v?.path.split("/").filter(Boolean).pop()||v?.path||n("settings.shared.projectSelector.fallbackProject"),e[5]=v,e[6]=n,e[7]=p):p=e[7];const A=p;let b;e[8]!==A?(b=Cl(A),e[8]=A,e[9]=b):b=e[9];const P=b;let N;e[10]!==a?(N=je(a),e[10]=a,e[11]=N):N=e[11];let k;e[12]!==n?(k=n("settings.shared.projectSelector.switchProjectAria"),e[12]=n,e[13]=k):k=e[13];let g;e[14]!==n?(g=n("settings.shared.projectSelector.switchProjectTitle"),e[14]=n,e[15]=g):g=e[15];let E,O;e[16]===Symbol.for("react.memo_cache_sentinel")?(E=je("text-foreground border border-border/80 appearance-none flex h-8 w-full min-w-0 rounded-lg bg-transparent px-3 py-1 outline-none","hover:border-input focus-visible:ring-1 focus-visible:ring-primary/50 focus-visible:border-primary/70","flex items-center gap-1.5 text-left"),O=s.jsx(L,{name:"folder",className:"h-4 w-4 opacity-70"}),e[16]=E,e[17]=O):(E=e[16],O=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(L,{name:"arrow-down-s",className:"size-4 opacity-50"}),e[20]=w):w=e[20];let m;e[21]!==I||e[22]!==k||e[23]!==g?(m=s.jsx(tn,{asChild:!0,children:s.jsxs("button",{type:"button","aria-label":k,title:g,className:E,children:[O,I,w]})}),e[21]=I,e[22]=k,e[23]=g,e[24]=m):m=e[24];const y=v?.id??"";let K;e[25]!==l||e[26]!==x?(K=G=>{if(!G)return;const S=x.find(q=>q.id===G);S&&l(S.path)},e[25]=l,e[26]=x,e[27]=K):K=e[27];let C;e[28]!==x?(C=x.map(Jd),e[28]=x,e[29]=C):C=e[29];let T;e[30]!==y||e[31]!==K||e[32]!==C?(T=s.jsx(sn,{align:"start",className:"w-auto",children:s.jsx(sc,{value:y,onValueChange:K,children:C})}),e[30]=y,e[31]=K,e[32]=C,e[33]=T):T=e[33];let j;e[34]!==m||e[35]!==T?(j=s.jsxs(nn,{children:[m,T]}),e[34]=m,e[35]=T,e[36]=j):j=e[36];let R;return e[37]!==j||e[38]!==N?(R=s.jsx("div",{className:N,children:j}),e[37]=j,e[38]=N,e[39]=R):R=e[39],R};function Gd(t){return t.projects}function qd(t){return t.setSettingsProjectPath}function Wd(t,e){return(t.label||t.path).localeCompare(e.label||e.path)}function Jd(t){const e=t.label?.trim()?t.label.trim():t.path.split("/").filter(Boolean).pop()||t.path,a=Cl(e);return s.jsx(tc,{value:t.id,children:s.jsx("span",{className:"min-w-0 truncate typography-ui",children:a})},t.id)}function Qd(t,e){return`opencode:sidebar-group:${t}:${e}`}const Zi=t=>{const e=mt.c(33),{label:a,count:n,storageKey:i,defaultExpanded:r,children:l}=t,h=r===void 0?!0:r;let d;e[0]!==a||e[1]!==i?(d=Qd(i,a),e[0]=a,e[1]=i,e[2]=d):d=e[2];const x=d,c=o.useId();let v;e[3]!==h||e[4]!==x?(v=()=>{try{const T=localStorage.getItem(x);if(T!==null)return T==="true"}catch{}return h},e[3]=h,e[4]=x,e[5]=v):v=e[5];const[p,A]=Xe.useState(v);let b,P;e[6]!==p||e[7]!==x?(b=()=>{try{localStorage.setItem(x,String(p))}catch{}},P=[x,p],e[6]=p,e[7]=x,e[8]=b,e[9]=P):(b=e[8],P=e[9]),Xe.useEffect(b,P);let N;e[10]===Symbol.for("react.memo_cache_sentinel")?(N=()=>A(Yd),e[10]=N):N=e[10];let k;e[11]===Symbol.for("react.memo_cache_sentinel")?(k=je("flex w-full items-center gap-1 rounded-md px-2 py-1 text-left","text-xs font-semibold uppercase tracking-wide text-muted-foreground","hover:bg-[var(--interactive-hover)] transition-colors duration-150","focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-primary/50"),e[11]=k):k=e[11];const g=!p&&"-rotate-90";let E;e[12]!==g?(E=je("h-3.5 w-3.5 flex-shrink-0 transition-transform duration-200",g),e[12]=g,e[13]=E):E=e[13];let O;e[14]!==E?(O=s.jsx(L,{name:"arrow-down-s",className:E}),e[14]=E,e[15]=O):O=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 m;e[20]!==c||e[21]!==p||e[22]!==O||e[23]!==I||e[24]!==w?(m=s.jsxs("button",{type:"button",onClick:N,"aria-expanded":p,"aria-controls":c,className:k,children:[O,I,w]}),e[20]=c,e[21]=p,e[22]=O,e[23]=I,e[24]=w,e[25]=m):m=e[25];const y=!p;let K;e[26]!==l||e[27]!==c||e[28]!==y?(K=s.jsx("div",{id:c,hidden:y,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]=c,e[28]=y,e[29]=K):K=e[29];let C;return e[30]!==m||e[31]!==K?(C=s.jsxs("div",{children:[m,K]}),e[30]=m,e[31]=K,e[32]=C):C=e[32],C};function Yd(t){return!t}const Zd=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},Xd=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())},Zr=t=>{const e=Xd(Zd(t));if(e.length===0)return;const a={};for(const i of e)i.permission&&((a[i.permission]||={})[i.pattern]=i.action);const n={};for(const[i,r]of Object.entries(a)){const l=Object.keys(r);if(l.length===1&&l[0]==="*"){n[i]=r["*"];continue}n[i]=r}return Object.keys(n).length>0?n:void 0},ep=({onItemSelect:t})=>{const{t:e}=ot(),[a,n]=o.useState(null),[i,r]=o.useState(""),[l,h]=o.useState(null),[d,x]=o.useState(null),[c,v]=o.useState(!1),[p,A]=o.useState(null),{selectedAgentName:b,setSelectedAgent:P,setAgentDraft:N,createAgent:k,deleteAgent:g,loadAgents:E}=_n(Ms(F=>({selectedAgentName:F.selectedAgentName,setSelectedAgent:F.setSelectedAgent,setAgentDraft:F.setAgentDraft,createAgent:F.createAgent,deleteAgent:F.deleteAgent,loadAgents:F.loadAgents}))),O=Us(),I=_n(F=>sl(F,O));o.useEffect(()=>{E(O)},[E,O]);const w="bg-background",m=()=>{const F="new-agent";let se=F,_=1;for(;I.some(V=>V.name===se);)se=`${F}-${_}`,_++;N({name:se,scope:"user"}),P(se),t?.()},y=async F=>{if(ia(F)){D.error(e("settings.agents.sidebar.toast.builtInCannotDelete"));return}h(F),x("delete")},K=async F=>{ia(F)&&(h(F),x("reset"))},C=()=>{h(null),x(null)},T=async()=>{if(!(!l||!d)){v(!0);try{const F=await g(l.name,l.scope,O);F.ok?(F.requiresManualRestart?D.warning(e("settings.agents.page.toast.savedManualRestart")):F.restartDeferred?D.success(e("settings.view.pendingRestart.saved")):d==="delete"?D.success(e("settings.agents.sidebar.toast.agentDeleted",{name:l.name})):D.success(e("settings.agents.sidebar.toast.agentReset",{name:l.name})),C()):d==="delete"?D.error(e("settings.agents.sidebar.toast.deleteFailed")):D.error(e("settings.agents.sidebar.toast.resetFailed"))}catch(F){const se=F instanceof Error?F.message:"",_=/built-in|not deletable|not found/i.test(se);d==="delete"?D.error(e(_?"settings.agents.sidebar.toast.definitionNotFound":"settings.agents.sidebar.toast.deleteFailed")):D.error(e("settings.agents.sidebar.toast.resetFailed"))}v(!1)}},j=F=>{const se=F.name;let _=1,V=`${se}-copy`;for(;I.some(Z=>Z.name===V);)_++,V=`${se}-copy-${_}`;const z=F,U=F.model?.providerID&&F.model?.modelID?`${F.model.providerID}/${F.model.modelID}`:null,X=F;N({name:V,scope:z.scope||"user",description:F.description,model:U,variant:F.variant,temperature:F.temperature,top_p:F.topP,prompt:F.prompt,mode:F.mode,permission:Zr(F.permission),disable:X.disable}),P(V)},R=F=>{r(F.name),n(F)},G=async()=>{if(!a)return;const F=i.trim().replace(/\s+/g,"-");if(!F){D.error(e("settings.agents.sidebar.toast.agentNameRequired"));return}if(F===a.name){n(null);return}if(I.some(z=>z.name===F)){D.error(e("settings.agents.sidebar.toast.agentExists"));return}const se=a.model?.providerID&&a.model?.modelID?`${a.model.providerID}/${a.model.modelID}`:null,_=a,V=await k({name:F,description:a.description,model:se,variant:a.variant,temperature:a.temperature,top_p:a.topP,prompt:a.prompt,mode:a.mode,permission:Zr(a.permission),disable:_.disable,scope:_.scope},O);if(V.ok){const z=await g(a.name,_.scope,O);z.ok?(V.requiresManualRestart||z.requiresManualRestart?D.warning(e("settings.agents.page.toast.savedManualRestart")):D.success(e("settings.agents.sidebar.toast.agentRenamed",{name:F})),P(F)):D.error(e("settings.agents.sidebar.toast.removeOldAfterRenameFailed"))}else D.error(e("settings.agents.sidebar.toast.renameFailed"));n(null)},S=F=>{switch(F){case"primary":return s.jsx(L,{name:"ai-agent",className:"h-3 w-3 text-primary"});case"all":return s.jsx(L,{name:"ai-agent-fill",className:"h-3 w-3 text-primary"});case"subagent":return s.jsx(L,{name:"robot",className:"h-3 w-3 text-primary"});default:return null}},q=I.filter(F=>!nc(F)),Q=q.filter(ia),M=q.filter(F=>!ia(F)),{groupedCustomAgents:W,ungroupedCustomAgents:Y}=Xe.useMemo(()=>{const F={},se=[];for(const V of M){const z=V;z.group?(F[z.group]||(F[z.group]=[]),F[z.group].push(V)):se.push(V)}return{groupedCustomAgents:Object.keys(F).sort((V,z)=>V.localeCompare(z)).map(V=>({name:V,agents:F[V]})),ungroupedCustomAgents:se}},[M]);return s.jsxs("div",{className:je("flex h-full flex-col",w),children:[s.jsxs("div",{className:"border-b px-3 pt-4 pb-3",children:[s.jsx("h2",{className:`${rn} mb-3`,children:e("settings.agents.sidebar.title")}),s.jsx(Ka,{className:"mb-3"}),s.jsxs("div",{className:"flex items-center justify-between gap-2",children:[s.jsx("span",{className:"typography-meta text-muted-foreground",children:e("settings.agents.sidebar.total",{count:q.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:m,children:s.jsx(L,{name:"add",className:"h-3.5 w-3.5"})})]})]}),s.jsx(Vs,{outerClassName:"flex-1 min-h-0",className:"space-y-1 px-3 py-2 overflow-x-hidden",children:q.length===0?s.jsxs("div",{className:"py-12 px-4 text-center text-muted-foreground",children:[s.jsx(L,{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:[Q.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")}),Q.map(F=>s.jsx(Mi,{agent:F,isSelected:b===F.name,onSelect:()=>{P(F.name),t?.()},onReset:()=>K(F),onDuplicate:()=>j(F),getAgentModeIcon:S,isMenuOpen:p===F.name,onMenuOpenChange:se=>A(se?F.name:null)},F.name))]}),M.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")}),W.map(({name:F,agents:se})=>s.jsx(Zi,{label:F,count:se.length,storageKey:"agents",children:se.map(_=>s.jsx(Mi,{agent:_,isSelected:b===_.name,onSelect:()=>{P(_.name),t?.()},onRename:()=>R(_),onDelete:()=>y(_),onDuplicate:()=>j(_),getAgentModeIcon:S,isMenuOpen:p===_.name,onMenuOpenChange:V=>A(V?_.name:null)},_.name))},F)),Y.map(F=>s.jsx(Mi,{agent:F,isSelected:b===F.name,onSelect:()=>{P(F.name),t?.()},onRename:()=>R(F),onDelete:()=>y(F),onDuplicate:()=>j(F),getAgentModeIcon:S,isMenuOpen:p===F.name,onMenuOpenChange:se=>A(se?F.name:null)},F.name))]})]})}),s.jsx(zt,{open:l!==null&&d!==null,onOpenChange:F=>{!F&&!c&&C()},children:s.jsxs(_t,{className:"max-w-md",children:[s.jsxs(Gt,{children:[s.jsx(qt,{children:e(d==="delete"?"settings.agents.sidebar.dialog.deleteTitle":"settings.agents.sidebar.dialog.resetTitle")}),s.jsx(Wt,{children:d==="delete"?e("settings.agents.sidebar.dialog.deleteDescription",{name:l?.name??""}):e("settings.agents.sidebar.dialog.resetDescription",{name:l?.name??""})})]}),s.jsxs(ms,{children:[s.jsx(B,{size:"sm",variant:"ghost",onClick:C,disabled:c,children:e("settings.common.actions.cancel")}),s.jsx(B,{size:"sm",onClick:T,disabled:c,children:e(d==="delete"?"settings.common.actions.delete":"settings.common.actions.reset")})]})]})}),s.jsx(zt,{open:a!==null,onOpenChange:F=>!F&&n(null),children:s.jsxs(_t,{children:[s.jsxs(Gt,{children:[s.jsx(qt,{children:e("settings.agents.sidebar.renameDialog.title")}),s.jsx(Wt,{children:e("settings.agents.sidebar.renameDialog.description",{name:a?.name??""})})]}),s.jsx(Ye,{value:i,onChange:F=>r(F.target.value),placeholder:e("settings.agents.sidebar.renameDialog.placeholder"),className:"text-foreground placeholder:text-muted-foreground",onKeyDown:F=>{F.key==="Enter"&&G()}}),s.jsxs(ms,{children:[s.jsx(B,{size:"sm",variant:"ghost",onClick:()=>n(null),children:e("settings.common.actions.cancel")}),s.jsx(B,{size:"sm",onClick:G,children:e("settings.common.actions.rename")})]})]})})]})},Mi=t=>{const e=mt.c(52),{agent:a,isSelected:n,onSelect:i,onDelete:r,onReset:l,onRename:h,onDuplicate:d,getAgentModeIcon:x,isMenuOpen:c,onMenuOpenChange:v}=t,{t:p}=ot(),A=a;let b;e[0]===Symbol.for("react.memo_cache_sentinel")?(b=Ra(),e[0]=b):b=e[0];const P=b,[N,k]=o.useState(!1);let g;e[1]!==r||e[2]!==d||e[3]!==h||e[4]!==l||e[5]!==p?(g=se=>s.jsxs(s.Fragment,{children:[h&&s.jsxs(se,{onClick:_=>{_.stopPropagation(),h()},children:[s.jsx(L,{name:"edit",className:"h-4 w-4 mr-px"}),p("settings.common.actions.rename")]}),s.jsxs(se,{onClick:_=>{_.stopPropagation(),d()},children:[s.jsx(L,{name:"file-copy",className:"h-4 w-4 mr-px"}),p("settings.common.actions.duplicate")]}),l&&s.jsxs(se,{onClick:_=>{_.stopPropagation(),l()},children:[s.jsx(L,{name:"restart",className:"h-4 w-4 mr-px"}),p("settings.common.actions.reset")]}),r&&s.jsxs(se,{onClick:_=>{_.stopPropagation(),r()},className:"text-destructive focus:text-destructive",children:[s.jsx(L,{name:"delete-bin",className:"h-4 w-4 mr-px"}),p("settings.common.actions.delete")]})]}),e[1]=r,e[2]=d,e[3]=h,e[4]=l,e[5]=p,e[6]=g):g=e[6];const E=g,O=n?"bg-interactive-selection":"hover:bg-interactive-hover";let I;e[7]!==O?(I=je("group relative flex items-center rounded-md px-1.5 py-1 transition-all duration-200 select-none",O),e[7]=O,e[8]=I):I=e[8];let w;e[9]===Symbol.for("react.memo_cache_sentinel")?(w=P?void 0:se=>{se.preventDefault(),k(!0)},e[9]=w):w=e[9];let m;e[10]!==I?(m=s.jsx("div",{className:I,onContextMenu:w}),e[10]=I,e[11]=m):m=e[11];let y;e[12]!==a.name?(y=s.jsx("span",{className:"typography-ui-label font-normal truncate text-foreground",children:a.name}),e[12]=a.name,e[13]=y):y=e[13];let K;e[14]!==a.mode||e[15]!==x?(K=x(a.mode),e[14]=a.mode,e[15]=x,e[16]=K):K=e[16];let C;e[17]!==a||e[18]!==A.scope||e[19]!==p?(C=(A.scope||ia(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:ia(a)?p("settings.agents.sidebar.badge.system"):A.scope}),e[17]=a,e[18]=A.scope,e[19]=p,e[20]=C):C=e[20];let T;e[21]!==y||e[22]!==K||e[23]!==C?(T=s.jsxs("div",{className:"flex items-center gap-1.5",children:[y,K,C]}),e[21]=y,e[22]=K,e[23]=C,e[24]=T):T=e[24];let j;e[25]!==a.description?(j=a.description&&s.jsx("div",{className:"typography-micro text-muted-foreground/60 truncate leading-tight",children:a.description}),e[25]=a.description,e[26]=j):j=e[26];let R;e[27]!==i||e[28]!==T||e[29]!==j?(R=s.jsxs("button",{onClick:i,className:"flex min-w-0 flex-1 flex-col gap-0 rounded-sm text-left focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-primary/50",tabIndex:0,children:[T,j]}),e[27]=i,e[28]=T,e[29]=j,e[30]=R):R=e[30];let G;e[31]!==v?(G=se=>{se&&k(!1),v(se)},e[31]=v,e[32]=G):G=e[32];let S;e[33]===Symbol.for("react.memo_cache_sentinel")?(S=s.jsx(tn,{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(L,{name:"more-2",className:"h-3.5 w-3.5"})})}),e[33]=S):S=e[33];let q;e[34]!==E?(q=s.jsx(sn,{align:"end",className:"w-fit min-w-20",children:E(an)}),e[34]=E,e[35]=q):q=e[35];let Q;e[36]!==c||e[37]!==G||e[38]!==q?(Q=s.jsxs(nn,{open:c,onOpenChange:G,children:[S,q]}),e[36]=c,e[37]=G,e[38]=q,e[39]=Q):Q=e[39];let M;e[40]!==R||e[41]!==Q?(M=s.jsxs("div",{className:"flex min-w-0 flex-1 items-center",children:[R,Q]}),e[40]=R,e[41]=Q,e[42]=M):M=e[42];let W;e[43]!==M||e[44]!==m?(W=s.jsx(Hn,{render:m,children:M}),e[43]=M,e[44]=m,e[45]=W):W=e[45];let Y;e[46]!==E?(Y=s.jsx(Vn,{className:"w-fit min-w-20",children:E(Bn)}),e[46]=E,e[47]=Y):Y=e[47];let F;return e[48]!==N||e[49]!==W||e[50]!==Y?(F=s.jsxs(Gn,{open:N,onOpenChange:k,children:[W,Y]}),e[48]=N,e[49]=W,e[50]=Y,e[51]=F):F=e[51],F},gs=t=>{const e=mt.c(21),{children:a,className:n,outerClassName:i,title:r,titleLeading:l,titleAccessory:h,description:d,headerEnd:x,showSaveStatus:c}=t,v=c===void 0?!1:c,p=r!=null||d!=null||x!=null||v,A=typeof r=="string"||typeof r=="number",b=l!=null||h!=null;let P;e[0]!==i?(P=je("h-full",i),e[0]=i,e[1]=P):P=e[1];let N;e[2]!==n?(N=je("mx-auto max-w-[840px] space-y-0 px-6 py-6 @3xl:px-12 @3xl:py-8","[&>section:first-of-type]:border-t-0 [&>section:first-of-type]:pt-0",n),e[2]=n,e[3]=N):N=e[3];let k;e[4]!==d||e[5]!==p||e[6]!==b||e[7]!==x||e[8]!==A||e[9]!==v||e[10]!==r||e[11]!==h||e[12]!==l?(k=p&&s.jsxs("div",{className:"mb-2 flex flex-wrap items-start justify-between gap-x-4 gap-y-3 pb-6",children:[s.jsxs("div",{className:"min-w-0 flex-1 basis-64 space-y-1",children:[r!=null?A?b?s.jsxs("div",{className:"flex min-w-0 items-center gap-2",children:[l,s.jsx("h1",{className:je(Qi,"min-w-0 truncate"),children:r}),s.jsx("span",{className:"shrink-0",children:h})]}):s.jsx("h1",{className:Qi,children:r}):r:null,d!=null?typeof d=="string"||typeof d=="number"?s.jsx("p",{className:nl,children:d}):d:null]}),s.jsxs("div",{className:"flex shrink-0 flex-wrap items-center justify-end gap-3",children:[x,v&&s.jsx(sp,{})]})]}),e[4]=d,e[5]=p,e[6]=b,e[7]=x,e[8]=A,e[9]=v,e[10]=r,e[11]=h,e[12]=l,e[13]=k):k=e[13];let g;e[14]!==a||e[15]!==N||e[16]!==k?(g=s.jsxs("div",{className:N,children:[k,a]}),e[14]=a,e[15]=N,e[16]=k,e[17]=g):g=e[17];let E;return e[18]!==P||e[19]!==g?(E=s.jsx(Vs,{outerClassName:P,className:"w-full @container",children:g}),e[18]=P,e[19]=g,e[20]=E):E=e[20],E},tp=500,sp=()=>{const t=mt.c(13),{t:e}=ot(),a=o.useSyncExternalStore(td,Or,Or),[n,i]=o.useState(!1);let r,l;if(t[0]!==a?(r=()=>{if(a!=="saving"){i(!1);return}const c=setTimeout(()=>i(!0),tp);return()=>clearTimeout(c)},l=[a],t[0]=a,t[1]=r,t[2]=l):(r=t[1],l=t[2]),o.useEffect(r,l),a==="error"){let c;t[3]===Symbol.for("react.memo_cache_sentinel")?(c=s.jsx(L,{name:"error-warning",className:"size-3.5"}),t[3]=c):c=t[3];let v;t[4]!==e?(v=e("settings.common.status.saveFailed"),t[4]=e,t[5]=v):v=t[5];let p;return t[6]!==v?(p=s.jsxs("div",{"aria-live":"assertive",className:"flex shrink-0 items-center gap-1.5 typography-meta text-[var(--status-error)]",children:[c,s.jsx("span",{children:v})]}),t[6]=v,t[7]=p):p=t[7],p}if(a!=="saving"||!n)return null;let h;t[8]===Symbol.for("react.memo_cache_sentinel")?(h=s.jsx(L,{name:"loader-4",className:"size-3.5 animate-spin"}),t[8]=h):h=t[8];let d;t[9]!==e?(d=e("settings.common.actions.saving"),t[9]=e,t[10]=d):d=t[10];let x;return t[11]!==d?(x=s.jsxs("div",{"aria-live":"polite",className:"flex shrink-0 items-center gap-1.5 typography-meta text-muted-foreground",children:[h,s.jsx("span",{children:d})]}),t[11]=d,t[12]=x):x=t[12],x},np=["allow","ask","deny"],Aa=t=>t==="allow"||t==="ask"||t==="deny",Xi=()=>({global:null,keys:{}}),ap=t=>{const e=Xi();if(t==null)return e;if(typeof t=="string")return Aa(t)&&(e.global=t),e;if(typeof t!="object"||Array.isArray(t))return e;for(const[a,n]of Object.entries(t)){if(a==="*"){Aa(n)&&(e.global=n);continue}const i={action:null,patterns:[]};if(Aa(n))i.action=n;else if(n&&typeof n=="object"&&!Array.isArray(n))for(const[r,l]of Object.entries(n))Aa(l)&&(r==="*"?i.action=l:i.patterns.push({pattern:r,action:l}));else continue;e.keys[a]=i}return e},er=t=>{const e={};t.global!==null&&(e["*"]=t.global);for(const[a,n]of Object.entries(t.keys)){const i=n.patterns.filter(r=>r.pattern.trim().length>0);if(n.action!==null&&i.length===0)e[a]=n.action;else if(i.length>0){const r={};n.action!==null&&(r["*"]=n.action);for(const l of i)r[l.pattern]=l.action;e[a]=r}}return Object.keys(e).length>0?e:null},ip=(t,e)=>JSON.stringify(er(t))===JSON.stringify(er(e)),vn=t=>JSON.parse(JSON.stringify(t)),rp=["edit","external_directory","doom_loop","plan_enter","plan_exit"],op=new Set(["read","edit","glob","grep","list","bash","task","external_directory","lsp","skill"]),Xr=new Set(["write","patch","apply_patch","multiedit","invalid"]),lp=t=>t.split(/[_-]/).filter(Boolean).map(e=>e.charAt(0).toUpperCase()+e.slice(1)).join(" "),cp=({agent:t})=>{const{t:e}=ot(),a=_n(z=>z.updateAgent),[n,i]=o.useState(Xi),[r,l]=o.useState(Xi),[h,d]=o.useState(!0),[x,c]=o.useState(!1),[v,p]=o.useState(!1),[A,b]=o.useState({}),[P,N]=o.useState([]),[k,g]=o.useState(""),[E,O]=o.useState(0),I=t.name,w=Us();o.useEffect(()=>{let z=!1;return d(!0),c(!1),(async()=>{try{const U=w,X=U?`?directory=${encodeURIComponent(U)}`:"",Z=await pt(`/api/config/agents/${encodeURIComponent(I)}/config${X}`,{headers:{"Cache-Control":"no-cache",...U?{"x-opencode-directory":U}:{}}});if(!Z.ok)throw new Error(String(Z.status));const ne=await Z.json().catch(()=>null);if(z)return;const le=ap(ne?.config?.permission);i(vn(le)),l(le)}catch{z||c(!0)}finally{z||d(!1)}})(),()=>{z=!0}},[I,E,w]),o.useEffect(()=>{let z=!1;return(async()=>{try{const U=await cn.listToolIds({directory:w});!z&&Array.isArray(U)&&N(U.filter(X=>typeof X=="string"&&!Xr.has(X)))}catch{}})(),()=>{z=!0}},[I,w]);const m=o.useMemo(()=>{const z=t.permission;if(!Array.isArray(z))return[];const U=[];for(const X of z){if(!X||typeof X!="object")continue;const{permission:Z,pattern:ne,action:le}=X;typeof Z=="string"&&typeof ne=="string"&&Aa(le)&&U.push({permission:Z,pattern:ne,action:le})}return U},[t]),y=o.useCallback(z=>{const U=m.find(Z=>Z.permission===z&&Z.pattern==="*");if(U)return U.action;const X=m.find(Z=>Z.permission==="*"&&Z.pattern==="*");return X?X.action:null},[m]),K=o.useCallback(z=>{const U=r.keys[z]?.patterns??[],X=new Set(U.map(Z=>Z.pattern));return m.filter(Z=>Z.permission===z&&Z.pattern!=="*"&&!X.has(Z.pattern))},[m,r.keys]),C=o.useMemo(()=>{const z=new Set;for(const U of P)z.add(U);for(const U of rp)z.add(U);for(const U of Object.keys(r.keys))z.add(U);for(const U of Xr)z.delete(U);return Array.from(z).sort((U,X)=>U.localeCompare(X))},[P,r.keys]),T=o.useMemo(()=>!ip(r,n),[r,n]),j=z=>{l(U=>({...U,global:z}))},R=(z,U)=>{l(X=>{const Z=vn(X),ne=Z.keys[z]??{action:null,patterns:[]};return ne.action=U,ne.action===null&&ne.patterns.length===0?delete Z.keys[z]:Z.keys[z]=ne,Z})},G=(z,U,X,Z)=>{l(ne=>{const le=vn(ne),re=le.keys[z]??{action:null,patterns:[]};return re.patterns[U]={pattern:X,action:Z},le.keys[z]=re,le})},S=z=>{l(U=>{const X=vn(U),Z=X.keys[z]??{action:null,patterns:[]};return Z.patterns.push({pattern:"",action:"allow"}),X.keys[z]=Z,X}),b(U=>({...U,[z]:!0}))},q=(z,U)=>{l(X=>{const Z=vn(X),ne=Z.keys[z];return ne?(ne.patterns.splice(U,1),ne.action===null&&ne.patterns.length===0&&delete Z.keys[z],Z):X})},Q=()=>{const z=k.trim();!z||z==="*"||(l(U=>{if(U.keys[z])return U;const X=vn(U);return X.keys[z]={action:"ask",patterns:[]},X}),b(U=>({...U,[z]:!0})),g(""))},M=async()=>{p(!0);try{const z=er(r),U=await a(I,{permission:z});U.ok?(i(vn(r)),D.success(U.requiresManualRestart?e("settings.agents.page.permissionsEditor.toast.savedRestartRequired"):e("settings.agents.page.permissionsEditor.toast.saved"))):D.error(e("settings.agents.page.permissionsEditor.toast.saveFailed"))}finally{p(!1)}},W=()=>{l(vn(n))},Y=z=>e(z==="allow"?"settings.agents.page.permissionsEditor.action.allow":z==="ask"?"settings.agents.page.permissionsEditor.action.ask":"settings.agents.page.permissionsEditor.action.deny"),F=e("settings.agents.page.permissionsEditor.action.inherit"),se=e("settings.agents.page.permissionsEditor.action.default"),_=z=>[...z?[{value:"inherit",label:z}]:[],...np.map(U=>({value:U,label:Y(U)}))],V=(z,U,X,Z=F)=>s.jsx(Js,{value:z??"inherit",options:_(Z),onChange:ne=>U(ne==="inherit"?null:ne),"aria-label":X});return h?s.jsx(Be,{title:e("settings.agents.page.section.toolPermissions"),children:s.jsx("p",{className:Ln,children:e("common.loading")})}):x?s.jsx(Be,{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:()=>O(z=>z+1),children:e("settings.agents.page.permissionsEditor.actions.retry")})]})}):s.jsxs(Be,{title:e("settings.agents.page.section.toolPermissions"),settingsItem:"agents.permissions",info:e("settings.agents.page.permissionsEditor.sectionInfo"),headerAction:T?s.jsxs("div",{className:"flex items-center gap-2",children:[s.jsx(B,{variant:"ghost",size:"xs",className:"!font-normal",onClick:W,disabled:v,children:e("settings.agents.page.permissionsEditor.actions.discard")}),s.jsx(B,{size:"xs",className:"!font-normal",onClick:()=>{M()},disabled:v,children:e(v?"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:Rt,children:e("settings.agents.page.permissionsEditor.defaultLabel")}),s.jsx(ss,{children:e("settings.agents.page.permissionsEditor.defaultInfo")}),r.global===null&&s.jsx("span",{className:"typography-micro text-muted-foreground",children:e("settings.agents.page.permissionsEditor.effectiveHint",{action:Y(y("*")??"allow")})})]}),V(r.global,j,e("settings.agents.page.permissionsEditor.defaultAria"),se)]}),s.jsx("div",{children:C.map(z=>{const U=r.keys[z]??{action:null,patterns:[]},X=K(z),Z=op.has(z)||U.patterns.length>0,ne=Z||X.length>0,le=A[z]===!0,re=y(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?()=>b(fe=>({...fe,[z]:!le})):void 0,className:je("flex min-w-0 items-center gap-1.5 text-left",!ne&&"cursor-default"),"aria-expanded":ne?le:void 0,children:[s.jsx(L,{name:le&&ne?"arrow-down-s":"arrow-right-s",className:je("h-3.5 w-3.5 shrink-0 text-muted-foreground",!ne&&"opacity-0")}),s.jsx("span",{className:Rt,children:lp(z)}),s.jsx("span",{className:"typography-micro font-mono text-muted-foreground/70",children:z}),U.action===null&&re!==null&&s.jsx("span",{className:"typography-micro text-muted-foreground",children:e("settings.agents.page.permissionsEditor.effectiveHint",{action:Y(re)})}),U.patterns.length>0&&s.jsx("span",{className:"typography-micro rounded bg-muted px-1 text-muted-foreground",children:e("settings.agents.page.permissionsEditor.ruleCount",{count:String(U.patterns.length)})})]}),V(U.action,fe=>R(z,fe),e("settings.agents.page.permissionsEditor.keyAria",{key:z}))]}),le&&ne&&s.jsxs("div",{className:"mt-2 space-y-2 pl-5",children:[U.patterns.map((fe,ae)=>s.jsxs("div",{className:"flex flex-wrap items-center gap-2",children:[s.jsx(Ye,{value:fe.pattern,onChange:ie=>G(z,ae,ie.target.value,fe.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(Js,{value:fe.action,options:_(),onChange:ie=>G(z,ae,fe.pattern,ie),"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:()=>q(z,ae),"aria-label":e("settings.agents.page.permissionsEditor.actions.removeRuleAria"),children:s.jsx(L,{name:"close",className:"h-3.5 w-3.5"})})]},ae)),Z&&s.jsxs(B,{variant:"outline",size:"xs",className:"!font-normal",onClick:()=>S(z),children:[s.jsx(L,{name:"add",className:"mr-1 h-3.5 w-3.5"}),e("settings.agents.page.permissionsEditor.actions.addRule")]}),X.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(ss,{children:e("settings.agents.page.permissionsEditor.sessionRulesInfo")})]}),X.map(fe=>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:fe.pattern}),s.jsx("span",{className:"typography-micro text-muted-foreground",children:Y(fe.action)})]},`${fe.pattern}-${fe.action}`))]})]})]},z)})}),s.jsxs("div",{className:"flex flex-wrap items-center gap-2 border-t border-border/40 pt-3",children:[s.jsx(Ye,{value:k,onChange:z=>g(z.target.value),onKeyDown:z=>{z.key==="Enter"&&(z.preventDefault(),Q())},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:Q,disabled:!k.trim(),children:[s.jsx(L,{name:"add",className:"mr-1 h-3.5 w-3.5"}),e("settings.agents.page.permissionsEditor.actions.addKey")]})]})]})},dp=(t,e)=>{const a=oa(e);if(!a)return[];const i=t.find(r=>r.id===a.providerId)?.models?.find(r=>r.id===a.modelId);return i?.variants?Object.keys(i.variants):[]},pp=()=>{const{t}=ot(),e=tt(V=>V.providers),{selectedAgentName:a,getAgentByName:n,createAgent:i,updateAgent:r,agentDraft:l,setAgentDraft:h}=_n(Ms(V=>({selectedAgentName:V.selectedAgentName,getAgentByName:V.getAgentByName,createAgent:V.createAgent,updateAgent:V.updateAgent,agentDraft:V.agentDraft,setAgentDraft:V.setAgentDraft}))),d=Us(),x=_n(V=>sl(V,d)),c=a?n(a,d):null,v=!!(l&&l.name===a&&!c),[p,A]=o.useState(""),[b,P]=o.useState("user"),[N,k]=o.useState(""),[g,E]=o.useState("subagent"),[O,I]=o.useState(""),[w,m]=o.useState(""),[y,K]=o.useState(void 0),[C,T]=o.useState(void 0),[j,R]=o.useState(""),[G,S]=o.useState(!1),q=o.useRef(null),Q=o.useMemo(()=>dp(e,O),[O,e]),M=Q.length>0,W=w||"__default",Y=M,F=o.useMemo(()=>w&&!Q.includes(w)?[w,...Q]:Q,[w,Q]);o.useEffect(()=>{if(v&&l){const V=l.name||"",z=l.scope||"user",U=l.description||"",X=l.mode||"subagent",Z=l.model||"",ne=l.variant||"",le=l.temperature??void 0,re=l.top_p??void 0,fe=l.prompt||"";A(V),P(z),k(U),E(X),I(Z),m(ne),K(le),T(re),R(fe),q.current={draftName:V,draftScope:z,description:U,mode:X,model:Z,variant:ne,temperature:le,topP:re,prompt:fe};return}if(c&&a===c.name){const V=c.description||"",z=c.mode||"subagent",U=c.model?.providerID&&c.model?.modelID?`${c.model.providerID}/${c.model.modelID}`:"",X=c.variant||"",Z=c.temperature??void 0,ne=c.topP??void 0,le=c.prompt||"";k(V),E(z),I(U),m(X),K(Z),T(ne),R(le),q.current={draftName:"",draftScope:"user",description:V,mode:z,model:U,variant:X,temperature:Z,topP:ne,prompt:le}}},[l,v,c,a]);const se=o.useMemo(()=>{const V=q.current;return V?!!(v&&(p!==V.draftName||b!==V.draftScope)||N!==V.description||g!==V.mode||O!==V.model||w!==V.variant||y!==V.temperature||C!==V.topP||j!==V.prompt):!1},[N,p,b,v,g,O,j,y,C,w]),_=async()=>{const V=v?p.trim().replace(/\s+/g,"-"):a?.trim();if(!V){D.error(t("settings.agents.sidebar.toast.agentNameRequired"));return}if(v&&x.some(z=>z.name===V)){D.error(t("settings.agents.sidebar.toast.agentExists"));return}S(!0);try{const z=O.trim(),U=w.trim(),X=j.trim(),Z={name:V,...N.trim()?{description:N.trim()}:{},mode:g,model:z===""?null:z,variant:U===""?null:U||void 0,temperature:y??null,top_p:C??null,prompt:X||(v?void 0:null),...v&&b?{scope:b}:{}};let ne;v?(ne=await i(Z,d),ne.ok&&h(null)):ne=await r(V,Z,d),ne.ok?ne.requiresManualRestart?D.warning(t("settings.agents.page.toast.savedManualRestart")):ne.restartDeferred?D.success(t("settings.view.pendingRestart.saved")):D.success(t(v?"settings.agents.page.toast.created":"settings.agents.page.toast.updated")):D.error(t(v?"settings.agents.page.toast.createFailed":"settings.agents.page.toast.updateFailed"))}catch(z){console.error("Error saving agent:",z);const U=z instanceof Error&&z.message?z.message:t("settings.agents.page.toast.saveUnexpectedError");D.error(U)}finally{S(!1)}};return a?s.jsxs(gs,{title:v?t("settings.agents.page.title.new"):a,description:t(v?"settings.agents.page.subtitle.new":"settings.agents.page.subtitle.edit"),showSaveStatus:!1,children:[s.jsxs(Be,{title:t("settings.agents.page.section.identityRole"),divider:!1,contentClassName:"space-y-0",children:[v&&s.jsxs(Qt,{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(Ye,{value:p,onChange:V=>A(V.target.value),placeholder:t("settings.agents.page.field.agentNamePlaceholder"),className:"h-7 w-40 px-2"})]}),s.jsxs(Ot,{value:b,onValueChange:V=>P(V),children:[s.jsx(Lt,{size:Jt,className:"w-fit min-w-[100px]",children:s.jsx(Ht,{placeholder:t("settings.agents.page.field.scopePlaceholder")})}),s.jsxs(Ft,{align:"end",children:[s.jsx(ut,{value:"user",children:s.jsxs("div",{className:"flex items-center gap-2",children:[s.jsx(L,{name:"user-3",className:"h-3.5 w-3.5"}),s.jsx("span",{children:t("settings.common.scope.global")})]})}),s.jsx(ut,{value:"project",children:s.jsxs("div",{className:"flex items-center gap-2",children:[s.jsx(L,{name:"folder",className:"h-3.5 w-3.5"}),s.jsx("span",{children:t("settings.common.scope.project")})]})})]})]})]}),s.jsx(es,{label:t("settings.common.field.description"),controlClassName:"w-full max-w-none",children:s.jsx(Es,{value:N,onChange:V=>k(V.target.value),placeholder:t("settings.agents.page.field.descriptionPlaceholder"),rows:2,className:"w-full resize-none min-h-[60px] bg-transparent"})}),s.jsx(es,{settingsItem:"agents.mode",label:t("settings.agents.page.field.mode"),info:t("settings.agents.page.field.modeTooltip"),children:s.jsx(Js,{"aria-label":t("settings.agents.page.field.mode"),value:g,onChange:E,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(Be,{title:t("settings.agents.page.section.modelParameters"),contentClassName:"space-y-3",children:[s.jsx(Qt,{settingsItem:"agents.model",label:t("settings.agents.page.field.overrideModel"),children:s.jsx(Ea,{providerId:oa(O)?.providerId??"",modelId:oa(O)?.modelId??"",onChange:(V,z)=>{I(V&&z?`${V}/${z}`:""),m("")},className:Cn})}),s.jsx(Qt,{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:Y?s.jsxs(Ot,{value:W,onValueChange:V=>m(V==="__default"?"":V),children:[s.jsx(Lt,{size:Jt,className:Pn,children:s.jsx(Ht,{placeholder:t("settings.agents.page.field.variantPlaceholder"),children:V=>V==="__default"?t("chat.modelControls.default"):V})}),s.jsxs(Ft,{children:[s.jsx(ut,{value:"__default",children:t("chat.modelControls.default")}),F.map(V=>s.jsx(ut,{value:V,children:V},V))]})]}):s.jsxs(s.Fragment,{children:[s.jsx(Ye,{value:w,onChange:V=>m(V.target.value),placeholder:t("settings.agents.page.field.variantPlaceholder"),disabled:!O&&!w,className:"h-8 w-40 rounded-md px-3"}),w&&s.jsx(B,{size:"sm",type:"button",variant:"ghost",onClick:()=>m(""),className:ks,"aria-label":t("settings.common.actions.clear"),title:t("settings.common.actions.clear"),children:s.jsx(L,{name:"close",className:"h-3.5 w-3.5"})})]})}),s.jsxs(Qt,{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(Is,{value:y,fallbackValue:.7,onValueChange:K,onClear:()=>K(void 0),min:0,max:2,step:.1,inputMode:"decimal",placeholder:"—",emptyLabel:"—",className:"w-16"}),y!==void 0&&s.jsx(B,{size:"sm",type:"button",variant:"ghost",onClick:()=>K(void 0),className:ks,"aria-label":t("settings.agents.page.field.clearTemperatureAria"),title:t("settings.common.actions.clear"),children:s.jsx(L,{name:"close",className:"h-3.5 w-3.5"})})]}),s.jsxs(Qt,{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(Is,{value:C,fallbackValue:.9,onValueChange:T,onClear:()=>T(void 0),min:0,max:1,step:.1,inputMode:"decimal",placeholder:"—",emptyLabel:"—",className:"w-16"}),C!==void 0&&s.jsx(B,{size:"sm",type:"button",variant:"ghost",onClick:()=>T(void 0),className:ks,"aria-label":t("settings.agents.page.field.clearTopPAria"),title:t("settings.common.actions.clear"),children:s.jsx(L,{name:"close",className:"h-3.5 w-3.5"})})]})]}),s.jsx(Be,{title:t("settings.agents.page.section.systemPrompt"),settingsItem:"agents.system-prompt",children:s.jsx(Es,{value:j,onChange:V=>R(V.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"})}),!v&&c&&s.jsx(cp,{agent:c}),s.jsx("div",{className:"pb-8",children:s.jsx(B,{onClick:_,disabled:G||!se,size:"xs",className:"!font-normal",children:t(G?"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(L,{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")})]})})},mp="~/.config/opencode/AGENTS.md",Pl=async(t,e)=>{const a=await t.json().catch(()=>null);return typeof a?.error=="string"&&a.error.trim()?a.error:e},up=t=>t.length>0&&!t.endsWith(`
|
|
2
|
-
`)?`${t}
|
|
3
|
-
`:t,Ba={prompt:"",optimizeSystemPrompt:!1,responseStyleEnabled:!1,responseStylePreset:"concise",responseStyleCustomInstructions:""},gp=(t,e)=>t==="custom"?e:rc(t),hp=t=>t==="custom"?"custom":al(t)?t:"concise",eo={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"},Ri=async(t,e)=>{Di("saving");try{const a=await pt("/api/config/settings",{method:"PUT",headers:{"Content-Type":"application/json",Accept:"application/json"},body:JSON.stringify(t)});if(!a.ok)throw new Error(await Pl(a,e));Di("saved")}catch(a){throw Di("error"),a}},fp=()=>{const{t}=ot(),e=ac(),[a,n]=o.useState(""),[i,r]=o.useState(!1),[l,h]=o.useState(Ba.responseStyleEnabled),[d,x]=o.useState(Ba.responseStylePreset),[c,v]=o.useState(Ba.responseStyleCustomInstructions),[p,A]=o.useState(!0),[b,P]=o.useState(!1),[N,k]=o.useState(!1),[g,E]=o.useState(""),[O,I]=o.useState(!1),w=o.useRef(null);o.useEffect(()=>{const j=new AbortController;return(async()=>{try{const[G,S]=await Promise.all([pt("/api/config/settings",{method:"GET",headers:{Accept:"application/json"},signal:j.signal}),pt("/api/behavior/agents-md",{method:"GET",headers:{Accept:"application/json"},signal:j.signal})]);let q=Ba;if(G.ok){const Q=await G.json();q={...q,optimizeSystemPrompt:Q.optimizeSystemPrompt===!0,responseStyleEnabled:Q.responseStyleEnabled===!0,responseStylePreset:hp(Q.responseStylePreset),responseStyleCustomInstructions:typeof Q.responseStyleCustomInstructions=="string"?Q.responseStyleCustomInstructions:""},typeof Q.globalBehaviorPrompt=="string"&&(q={...q,prompt:Q.globalBehaviorPrompt})}if(!q.prompt.trim()&&S.ok){const Q=await S.json();typeof Q.content=="string"&&(q={...q,prompt:Q.content})}n(q.prompt),r(q.optimizeSystemPrompt),I(q.optimizeSystemPrompt),h(q.responseStyleEnabled),x(q.responseStylePreset),v(q.responseStyleCustomInstructions),E(q.prompt),w.current={enabled:q.responseStyleEnabled,preset:q.responseStylePreset,custom:q.responseStyleCustomInstructions}}catch(G){G.name!=="AbortError"&&console.warn("Failed to load behavior settings:",G)}finally{A(!1)}})(),()=>j.abort()},[]),o.useEffect(()=>{if(p)return;const j=w.current;if(j&&j.enabled===l&&j.preset===d&&j.custom===c)return;const R={enabled:l,preset:d,custom:c},G=setTimeout(async()=>{try{await Ri({responseStyleEnabled:R.enabled,responseStylePreset:R.preset,responseStyleCustomInstructions:R.custom},t("settings.behavior.page.toast.saveFailed")),w.current=R}catch(S){const q=S instanceof Error?S.message:t("settings.behavior.page.toast.saveFailed");D.error(q)}},400);return()=>clearTimeout(G)},[l,d,c,p,t]);const m=gp(d,c),y=a!==g,K=i!==O,C=async()=>{P(!0);try{const j=up(a),R=await pt("/api/behavior/agents-md",{method:"PUT",headers:{"Content-Type":"application/json",Accept:"application/json"},body:JSON.stringify({content:j})});if(!R.ok)throw new Error(await Pl(R,t("settings.behavior.page.toast.saveFailed")));const G=await R.json().catch(()=>null),S=ii(G,"behavior",{id:"agents-md"});await Ri({globalBehaviorPrompt:j},t("settings.behavior.page.toast.saveFailed")),n(j),E(j),D.success(t(S?"settings.view.pendingRestart.saved":"settings.behavior.page.toast.saved"))}catch(j){console.error("Failed to save behavior:",j);const R=j instanceof Error?j.message:t("settings.behavior.page.toast.saveFailed");D.error(R)}finally{P(!1)}},T=async()=>{k(!0);try{await Ri({optimizeSystemPrompt:i},t("settings.behavior.page.toast.saveFailed")),I(i),Un("behavior",{id:"optimize-system-prompt"}),D.success(t("settings.view.pendingRestart.saved"))}catch(j){const R=j instanceof Error?j.message:t("settings.behavior.page.toast.saveFailed");D.error(R)}finally{k(!1)}};return s.jsxs(gs,{title:t("settings.behavior.page.title"),description:t("settings.page.behavior.description"),showSaveStatus:!0,children:[!e&&s.jsxs(Be,{title:t("settings.behavior.page.section.systemPromptOptimization"),divider:!1,settingsItem:"behavior.system-prompt-optimization",contentClassName:"space-y-3",children:[s.jsx(ht,{checked:i,onChange:r,disabled:p||N,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:()=>{T()},disabled:p||N||!K,className:"!font-normal",children:t(N?"settings.common.actions.saving":"settings.common.actions.saveChanges")})]}),s.jsxs(Be,{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:mp})})]}),settingsItem:"behavior.system-prompt",contentClassName:"space-y-3",children:[s.jsx(Es,{value:a,onChange:j=>n(j.target.value),placeholder:t("settings.behavior.page.field.systemPromptPlaceholder"),rows:12,disabled:p,outerClassName:"min-h-[160px] max-h-[70vh]",className:"w-full font-mono typography-meta bg-transparent"}),s.jsx(B,{onClick:C,disabled:b||!y||p,size:"xs",className:"!font-normal",children:t(b?"settings.common.actions.saving":"settings.common.actions.saveChanges")})]}),s.jsxs(Be,{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(ht,{checked:l,onChange:h,disabled:p,label:t("settings.behavior.page.responseStyle.enable"),ariaLabel:t("settings.behavior.page.responseStyle.enableAria")}),s.jsx(Qt,{label:t("settings.behavior.page.responseStyle.preset"),alignEnd:!1,children:s.jsxs(Ot,{value:d,onValueChange:j=>x(j),disabled:p||!l,children:[s.jsx(Lt,{size:Jt,className:Pn,children:s.jsx(Ht,{children:j=>j==="custom"?t("settings.behavior.page.responseStyle.option.custom"):al(j)?t(eo[j]):null})}),s.jsxs(Ft,{children:[ic.map(j=>s.jsx(ut,{value:j,children:t(eo[j])},j)),s.jsx(ut,{value:"custom",children:t("settings.behavior.page.responseStyle.option.custom")})]})]})}),s.jsx(Es,{value:m,onChange:j=>v(j.target.value),placeholder:t("settings.behavior.page.responseStyle.customPlaceholder"),rows:5,disabled:p||!l||d!=="custom",outerClassName:"min-h-[120px]",className:"w-full font-mono typography-meta bg-transparent"})]})]})},xp=t=>{const e=mt.c(176),{onItemSelect:a}=t,{t:n}=ot(),[i,r]=o.useState(null),[l,h]=o.useState(""),[d,x]=o.useState(null),[c,v]=o.useState(null),[p,A]=o.useState(!1),[b,P]=o.useState(null),{selectedCommandName:N,setSelectedCommand:k,setCommandDraft:g,createCommand:E,deleteCommand:O,loadCommands:I}=la(Ms(bp)),w=Us();let m;e[0]!==w?(m=Ee=>il(Ee,w),e[0]=w,e[1]=m):m=e[1];const y=la(m);let K;e[2]!==w?(K=Ee=>cr(Ee,w),e[2]=w,e[3]=K):K=e[3];const C=$s(K),T=$s(vp);let j,R;e[4]!==I||e[5]!==T||e[6]!==w?(j=()=>{I(w),T(w)},R=[I,T,w],e[4]=I,e[5]=T,e[6]=w,e[7]=j,e[8]=R):(j=e[7],R=e[8]),o.useEffect(j,R);let G;e[9]!==C?(G=new Set(C.map(yp)),e[9]=C,e[10]=G):G=e[10];const S=G;let q;if(e[11]!==y||e[12]!==S){let Ee;e[14]!==S?(Ee=vt=>!S.has(vt.name),e[14]=S,e[15]=Ee):Ee=e[15],q=y.filter(Ee),e[11]=y,e[12]=S,e[13]=q}else q=e[13];const Q=q;let M,W;e[16]!==N||e[17]!==k||e[18]!==S?(M=()=>{N&&S.has(N)&&k(null)},W=[N,k,S],e[16]=N,e[17]=k,e[18]=S,e[19]=M,e[20]=W):(M=e[19],W=e[20]),o.useEffect(M,W);let Y;e[21]!==y||e[22]!==a||e[23]!==g||e[24]!==k?(Y=()=>{let Ee="new-command",vt=1;for(;y.some(Se=>Se.name===Ee);)Ee=`new-command-${vt}`,vt++;g({name:Ee,scope:"user"}),k(Ee),a?.()},e[21]=y,e[22]=a,e[23]=g,e[24]=k,e[25]=Y):Y=e[25];const F=Y;let se;e[26]!==n?(se=async Ee=>{if(ra(Ee)){D.error(n("settings.commands.sidebar.toast.builtInCannotDelete"));return}x(Ee),v("delete")},e[26]=n,e[27]=se):se=e[27];const _=se;let V;e[28]===Symbol.for("react.memo_cache_sentinel")?(V=async Ee=>{ra(Ee)&&(x(Ee),v("reset"))},e[28]=V):V=e[28];const z=V;let U;e[29]===Symbol.for("react.memo_cache_sentinel")?(U=()=>{x(null),v(null)},e[29]=U):U=e[29];const X=U;let Z;e[30]!==d||e[31]!==c||e[32]!==O||e[33]!==w||e[34]!==n?(Z=async()=>{if(!d||!c)return;A(!0),await O(d.name,w)?(c==="delete"?D.success(n("settings.commands.sidebar.toast.commandDeleted",{name:d.name})):D.success(n("settings.commands.sidebar.toast.commandReset",{name:d.name})),X()):c==="delete"?D.error(n("settings.commands.sidebar.toast.deleteFailed")):D.error(n("settings.commands.sidebar.toast.resetFailed")),A(!1)},e[30]=d,e[31]=c,e[32]=O,e[33]=w,e[34]=n,e[35]=Z):Z=e[35];const ne=Z;let le;e[36]!==y||e[37]!==g||e[38]!==k?(le=Ee=>{const vt=Ee.name;let Se=1,kt=`${vt}-copy`;for(;y.some(J=>J.name===kt);)Se++,kt=`${vt}-copy-${Se}`;g({name:kt,scope:Ee.scope||"user",description:Ee.description,template:Ee.template,agent:Ee.agent,model:Ee.model}),k(kt)},e[36]=y,e[37]=g,e[38]=k,e[39]=le):le=e[39];const re=le;let fe;e[40]===Symbol.for("react.memo_cache_sentinel")?(fe=Ee=>{h(Ee.name),r(Ee)},e[40]=fe):fe=e[40];const ae=fe;let ie;e[41]!==y||e[42]!==E||e[43]!==O||e[44]!==i||e[45]!==l||e[46]!==k||e[47]!==w||e[48]!==n?(ie=async()=>{if(!i)return;const Ee=l.trim().replace(/\s+/g,"-");if(!Ee){D.error(n("settings.commands.sidebar.toast.commandNameRequired"));return}if(Ee===i.name){r(null);return}if(y.some(Se=>Se.name===Ee)){D.error(n("settings.commands.sidebar.toast.commandExists"));return}await E({name:Ee,description:i.description,template:i.template,agent:i.agent,model:i.model},w)?await O(i.name,w)?(D.success(`Command renamed to "${Ee}"`),k(Ee)):D.error(n("settings.commands.sidebar.toast.removeOldAfterRenameFailed")):D.error(n("settings.commands.sidebar.toast.renameFailed")),r(null)},e[41]=y,e[42]=E,e[43]=O,e[44]=i,e[45]=l,e[46]=k,e[47]=w,e[48]=n,e[49]=ie):ie=e[49];const te=ie;let ye,we,ke,xe,De,Me;if(e[50]!==Q||e[51]!==F||e[52]!==_||e[53]!==re||e[54]!==a||e[55]!==b||e[56]!==N||e[57]!==k||e[58]!==n){const Ee=Q.filter(ra),vt=Q.filter(jp);e[65]===Symbol.for("react.memo_cache_sentinel")?(De=je("flex h-full flex-col","bg-background"),e[65]=De):De=e[65];let Se;e[66]!==n?(Se=n("settings.commands.sidebar.title"),e[66]=n,e[67]=Se):Se=e[67];let kt;e[68]!==Se?(kt=s.jsx("h2",{className:`${rn} mb-3`,children:Se}),e[68]=Se,e[69]=kt):kt=e[69];let J;e[70]===Symbol.for("react.memo_cache_sentinel")?(J=s.jsx(Ka,{className:"mb-3"}),e[70]=J):J=e[70];let me;e[71]!==Q.length||e[72]!==n?(me=n("settings.commands.sidebar.total",{count:Q.length}),e[71]=Q.length,e[72]=n,e[73]=me):me=e[73];let Te;e[74]!==me?(Te=s.jsx("span",{className:"typography-meta text-muted-foreground",children:me}),e[74]=me,e[75]=Te):Te=e[75];let Ie;e[76]===Symbol.for("react.memo_cache_sentinel")?(Ie=s.jsx(L,{name:"add",className:"h-3.5 w-3.5"}),e[76]=Ie):Ie=e[76];let lt;e[77]!==F?(lt=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:F,children:Ie}),e[77]=F,e[78]=lt):lt=e[78];let at;e[79]!==Te||e[80]!==lt?(at=s.jsxs("div",{className:"flex items-center justify-between gap-2",children:[Te,lt]}),e[79]=Te,e[80]=lt,e[81]=at):at=e[81],e[82]!==kt||e[83]!==at?(Me=s.jsxs("div",{className:"border-b px-3 pt-4 pb-3",children:[kt,J,at]}),e[82]=kt,e[83]=at,e[84]=Me):Me=e[84],ye=Vs,we="flex-1 min-h-0",ke="space-y-1 px-3 py-2",xe=Q.length===0?s.jsxs("div",{className:"py-12 px-4 text-center text-muted-foreground",children:[s.jsx(L,{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:[Ee.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")}),[...Ee].sort(wp).map(Je=>s.jsx(to,{command:Je,isSelected:N===Je.name,onSelect:()=>{k(Je.name),a?.()},onReset:()=>z(Je),onDuplicate:()=>re(Je),isMenuOpen:b===Je.name,onMenuOpenChange:Ct=>P(Ct?Je.name:null)},Je.name))]}),vt.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")}),[...vt].sort(kp).map(Je=>s.jsx(to,{command:Je,isSelected:N===Je.name,onSelect:()=>{k(Je.name),a?.()},onRename:()=>ae(Je),onDelete:()=>_(Je),onDuplicate:()=>re(Je),isMenuOpen:b===Je.name,onMenuOpenChange:Ct=>P(Ct?Je.name:null)},Je.name))]})]}),e[50]=Q,e[51]=F,e[52]=_,e[53]=re,e[54]=a,e[55]=b,e[56]=N,e[57]=k,e[58]=n,e[59]=ye,e[60]=we,e[61]=ke,e[62]=xe,e[63]=De,e[64]=Me}else ye=e[59],we=e[60],ke=e[61],xe=e[62],De=e[63],Me=e[64];let he;e[85]!==ye||e[86]!==we||e[87]!==ke||e[88]!==xe?(he=s.jsx(ye,{outerClassName:we,className:ke,children:xe}),e[85]=ye,e[86]=we,e[87]=ke,e[88]=xe,e[89]=he):he=e[89];const ge=d!==null&&c!==null;let Ae;e[90]!==p?(Ae=Ee=>{!Ee&&!p&&X()},e[90]=p,e[91]=Ae):Ae=e[91];let Ve;e[92]!==c||e[93]!==n?(Ve=n(c==="delete"?"settings.commands.sidebar.dialog.deleteTitle":"settings.commands.sidebar.dialog.resetTitle"),e[92]=c,e[93]=n,e[94]=Ve):Ve=e[94];let _e;e[95]!==Ve?(_e=s.jsx(qt,{children:Ve}),e[95]=Ve,e[96]=_e):_e=e[96];let Le;e[97]!==d?.name||e[98]!==c||e[99]!==n?(Le=c==="delete"?n("settings.commands.sidebar.dialog.deleteDescription",{name:d?.name??""}):n("settings.commands.sidebar.dialog.resetDescription",{name:d?.name??""}),e[97]=d?.name,e[98]=c,e[99]=n,e[100]=Le):Le=e[100];let Re;e[101]!==Le?(Re=s.jsx(Wt,{children:Le}),e[101]=Le,e[102]=Re):Re=e[102];let Ze;e[103]!==_e||e[104]!==Re?(Ze=s.jsxs(Gt,{children:[_e,Re]}),e[103]=_e,e[104]=Re,e[105]=Ze):Ze=e[105];let Ge;e[106]!==n?(Ge=n("settings.common.actions.cancel"),e[106]=n,e[107]=Ge):Ge=e[107];let Oe;e[108]!==p||e[109]!==Ge?(Oe=s.jsx(B,{size:"sm",variant:"ghost",onClick:X,disabled:p,children:Ge}),e[108]=p,e[109]=Ge,e[110]=Oe):Oe=e[110];let Ke;e[111]!==c||e[112]!==n?(Ke=n(c==="delete"?"settings.common.actions.delete":"settings.common.actions.reset"),e[111]=c,e[112]=n,e[113]=Ke):Ke=e[113];let Pe;e[114]!==ne||e[115]!==p||e[116]!==Ke?(Pe=s.jsx(B,{size:"sm",onClick:ne,disabled:p,children:Ke}),e[114]=ne,e[115]=p,e[116]=Ke,e[117]=Pe):Pe=e[117];let Ue;e[118]!==Oe||e[119]!==Pe?(Ue=s.jsxs(ms,{children:[Oe,Pe]}),e[118]=Oe,e[119]=Pe,e[120]=Ue):Ue=e[120];let ve;e[121]!==Ze||e[122]!==Ue?(ve=s.jsxs(_t,{className:"max-w-md",children:[Ze,Ue]}),e[121]=Ze,e[122]=Ue,e[123]=ve):ve=e[123];let We;e[124]!==ge||e[125]!==Ae||e[126]!==ve?(We=s.jsx(zt,{open:ge,onOpenChange:Ae,children:ve}),e[124]=ge,e[125]=Ae,e[126]=ve,e[127]=We):We=e[127];const $=i!==null;let de;e[128]===Symbol.for("react.memo_cache_sentinel")?(de=Ee=>!Ee&&r(null),e[128]=de):de=e[128];let ue;e[129]!==n?(ue=n("settings.commands.sidebar.renameDialog.title"),e[129]=n,e[130]=ue):ue=e[130];let Ne;e[131]!==ue?(Ne=s.jsx(qt,{children:ue}),e[131]=ue,e[132]=Ne):Ne=e[132];const pe=i?.name??"";let Fe;e[133]!==n||e[134]!==pe?(Fe=n("settings.commands.sidebar.renameDialog.description",{name:pe}),e[133]=n,e[134]=pe,e[135]=Fe):Fe=e[135];let H;e[136]!==Fe?(H=s.jsx(Wt,{children:Fe}),e[136]=Fe,e[137]=H):H=e[137];let He;e[138]!==Ne||e[139]!==H?(He=s.jsxs(Gt,{children:[Ne,H]}),e[138]=Ne,e[139]=H,e[140]=He):He=e[140];let et;e[141]===Symbol.for("react.memo_cache_sentinel")?(et=Ee=>h(Ee.target.value),e[141]=et):et=e[141];let ze;e[142]!==n?(ze=n("settings.commands.sidebar.renameDialog.placeholder"),e[142]=n,e[143]=ze):ze=e[143];let st;e[144]!==te?(st=Ee=>{Ee.key==="Enter"&&te()},e[144]=te,e[145]=st):st=e[145];let wt;e[146]!==l||e[147]!==ze||e[148]!==st?(wt=s.jsx(Ye,{value:l,onChange:et,placeholder:ze,className:"text-foreground placeholder:text-muted-foreground",onKeyDown:st}),e[146]=l,e[147]=ze,e[148]=st,e[149]=wt):wt=e[149];let xt;e[150]===Symbol.for("react.memo_cache_sentinel")?(xt=()=>r(null),e[150]=xt):xt=e[150];let gt;e[151]!==n?(gt=n("settings.common.actions.cancel"),e[151]=n,e[152]=gt):gt=e[152];let bt;e[153]!==gt?(bt=s.jsx(B,{size:"sm",variant:"ghost",onClick:xt,children:gt}),e[153]=gt,e[154]=bt):bt=e[154];let St;e[155]!==n?(St=n("settings.common.actions.rename"),e[155]=n,e[156]=St):St=e[156];let yt;e[157]!==te||e[158]!==St?(yt=s.jsx(B,{size:"sm",onClick:te,children:St}),e[157]=te,e[158]=St,e[159]=yt):yt=e[159];let It;e[160]!==bt||e[161]!==yt?(It=s.jsxs(ms,{children:[bt,yt]}),e[160]=bt,e[161]=yt,e[162]=It):It=e[162];let qe;e[163]!==He||e[164]!==wt||e[165]!==It?(qe=s.jsxs(_t,{children:[He,wt,It]}),e[163]=He,e[164]=wt,e[165]=It,e[166]=qe):qe=e[166];let Qe;e[167]!==$||e[168]!==qe?(Qe=s.jsx(zt,{open:$,onOpenChange:de,children:qe}),e[167]=$,e[168]=qe,e[169]=Qe):Qe=e[169];let dt;return e[170]!==De||e[171]!==Me||e[172]!==he||e[173]!==We||e[174]!==Qe?(dt=s.jsxs("div",{className:De,children:[Me,he,We,Qe]}),e[170]=De,e[171]=Me,e[172]=he,e[173]=We,e[174]=Qe,e[175]=dt):dt=e[175],dt},to=t=>{const e=mt.c(47),{command:a,isSelected:n,onSelect:i,onDelete:r,onReset:l,onRename:h,onDuplicate:d,isMenuOpen:x,onMenuOpenChange:c}=t,{t:v}=ot();let p;e[0]===Symbol.for("react.memo_cache_sentinel")?(p=Ra(),e[0]=p):p=e[0];const A=p,[b,P]=o.useState(!1);let N;e[1]!==r||e[2]!==d||e[3]!==h||e[4]!==l||e[5]!==v?(N=W=>s.jsxs(s.Fragment,{children:[h&&s.jsxs(W,{onClick:Y=>{Y.stopPropagation(),h()},children:[s.jsx(L,{name:"edit",className:"h-4 w-4 mr-px"}),v("settings.common.actions.rename")]}),s.jsxs(W,{onClick:Y=>{Y.stopPropagation(),d()},children:[s.jsx(L,{name:"file-copy",className:"h-4 w-4 mr-px"}),v("settings.common.actions.duplicate")]}),l&&s.jsxs(W,{onClick:Y=>{Y.stopPropagation(),l()},children:[s.jsx(L,{name:"restart",className:"h-4 w-4 mr-px"}),v("settings.common.actions.reset")]}),r&&s.jsxs(W,{onClick:Y=>{Y.stopPropagation(),r()},className:"text-destructive focus:text-destructive",children:[s.jsx(L,{name:"delete-bin",className:"h-4 w-4 mr-px"}),v("settings.common.actions.delete")]})]}),e[1]=r,e[2]=d,e[3]=h,e[4]=l,e[5]=v,e[6]=N):N=e[6];const k=N,g=n?"bg-interactive-selection":"hover:bg-interactive-hover";let E;e[7]!==g?(E=je("group relative flex items-center rounded-md px-1.5 py-1 transition-all duration-200 select-none",g),e[7]=g,e[8]=E):E=e[8];let O;e[9]===Symbol.for("react.memo_cache_sentinel")?(O=A?void 0:W=>{W.preventDefault(),P(!0)},e[9]=O):O=e[9];let I;e[10]!==E?(I=s.jsx("div",{className:E,onContextMenu:O}),e[10]=E,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 m;e[14]!==a||e[15]!==v?(m=(a.scope||ra(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:ra(a)?v("settings.agents.sidebar.badge.system"):a.scope}),e[14]=a,e[15]=v,e[16]=m):m=e[16];let y;e[17]!==w||e[18]!==m?(y=s.jsxs("div",{className:"flex items-center gap-2",children:[w,m]}),e[17]=w,e[18]=m,e[19]=y):y=e[19];let K;e[20]!==a.description?(K=a.description&&s.jsx("div",{className:"typography-micro text-muted-foreground/60 truncate leading-tight",children:a.description}),e[20]=a.description,e[21]=K):K=e[21];let C;e[22]!==i||e[23]!==K||e[24]!==y?(C=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:[y,K]}),e[22]=i,e[23]=K,e[24]=y,e[25]=C):C=e[25];let T;e[26]!==c?(T=W=>{W&&P(!1),c(W)},e[26]=c,e[27]=T):T=e[27];let j;e[28]===Symbol.for("react.memo_cache_sentinel")?(j=s.jsx(tn,{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(L,{name:"more-2",className:"h-3.5 w-3.5"})})}),e[28]=j):j=e[28];let R;e[29]!==k?(R=s.jsx(sn,{align:"end",className:"w-fit min-w-20",children:k(an)}),e[29]=k,e[30]=R):R=e[30];let G;e[31]!==x||e[32]!==T||e[33]!==R?(G=s.jsxs(nn,{open:x,onOpenChange:T,children:[j,R]}),e[31]=x,e[32]=T,e[33]=R,e[34]=G):G=e[34];let S;e[35]!==C||e[36]!==G?(S=s.jsxs("div",{className:"flex min-w-0 flex-1 items-center",children:[C,G]}),e[35]=C,e[36]=G,e[37]=S):S=e[37];let q;e[38]!==S||e[39]!==I?(q=s.jsx(Hn,{render:I,children:S}),e[38]=S,e[39]=I,e[40]=q):q=e[40];let Q;e[41]!==k?(Q=s.jsx(Vn,{className:"w-fit min-w-20",children:k(Bn)}),e[41]=k,e[42]=Q):Q=e[42];let M;return e[43]!==b||e[44]!==q||e[45]!==Q?(M=s.jsxs(Gn,{open:b,onOpenChange:P,children:[q,Q]}),e[43]=b,e[44]=q,e[45]=Q,e[46]=M):M=e[46],M};function bp(t){return{selectedCommandName:t.selectedCommandName,setSelectedCommand:t.setSelectedCommand,setCommandDraft:t.setCommandDraft,createCommand:t.createCommand,deleteCommand:t.deleteCommand,loadCommands:t.loadCommands}}function vp(t){return t.loadSkills}function yp(t){return t.name}function jp(t){return!ra(t)}function wp(t,e){return t.name.localeCompare(e.name)}function kp(t,e){return t.name.localeCompare(e.name)}const Np=()=>{const{t}=ot(),{selectedCommandName:e,getCommandByName:a,createCommand:n,updateCommand:i,commandDraft:r,setCommandDraft:l}=la(Ms(j=>({selectedCommandName:j.selectedCommandName,getCommandByName:j.getCommandByName,createCommand:j.createCommand,updateCommand:j.updateCommand,commandDraft:j.commandDraft,setCommandDraft:j.setCommandDraft}))),h=Us(),d=la(j=>il(j,h)),x=e?a(e,h):null,c=!!(r&&r.name===e&&!x),[v,p]=o.useState(""),[A,b]=o.useState("user"),[P,N]=o.useState(""),[k,g]=o.useState(""),[E,O]=o.useState(""),[I,w]=o.useState(""),[m,y]=o.useState(!1),K=o.useRef(null);o.useEffect(()=>{if(c&&r){const j=r.name||"",R=r.scope||"user",G=r.description||"",S=r.agent||"",q=r.model||"",Q=r.template||"";p(j),b(R),N(G),g(S),O(q),w(Q),K.current={draftName:j,draftScope:R,description:G,agent:S,model:q,template:Q}}else if(x){const j=x.description||"",R=x.agent||"",G=x.model||"",S=x.template||"";N(j),g(R),O(G),w(S),K.current={draftName:"",draftScope:"user",description:j,agent:R,model:G,template:S}}},[x,c,e,d,r]);const C=o.useMemo(()=>{const j=K.current;return j?!!(c&&(v!==j.draftName||A!==j.draftScope)||P!==j.description||k!==j.agent||E!==j.model||I!==j.template):!1},[k,P,v,A,c,E,I]),T=async()=>{const j=c?v.trim().replace(/\s+/g,"-"):e?.trim();if(!j){D.error(t("settings.commands.sidebar.toast.commandNameRequired"));return}if(!I.trim()){D.error(t("settings.commands.page.toast.templateRequired"));return}if(c&&d.some(R=>R.name===j)){D.error(t("settings.commands.sidebar.toast.commandExists"));return}y(!0);try{const R=k.trim(),G=E.trim(),S=I.trim(),q={name:j,description:P.trim()||void 0,agent:R===""?null:R,model:G===""?null:G,template:S,scope:c?A:void 0};let Q;if(c?(Q=await n(q,h),Q&&l(null)):Q=await i(j,q,h),Q){const M=dn.getState().changes.some(W=>W.scope==="commands"&&W.id.startsWith(`commands:${j}:`));D.success(t(M?"settings.view.pendingRestart.saved":c?"settings.commands.page.toast.created":"settings.commands.page.toast.updated"))}else D.error(t(c?"settings.commands.page.toast.createFailed":"settings.commands.page.toast.updateFailed"))}catch(R){console.error("Error saving command:",R),D.error(t("settings.commands.page.toast.saveUnexpectedError"))}finally{y(!1)}};return e?s.jsxs(gs,{title:c?t("settings.commands.page.title.new"):`/${e}`,description:t(c?"settings.commands.page.subtitle.new":"settings.commands.page.subtitle.edit"),showSaveStatus:!1,children:[s.jsxs(Be,{title:t("settings.commands.page.section.identity"),divider:!1,contentClassName:"space-y-0",children:[c&&s.jsxs(Qt,{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(Ye,{value:v,onChange:j=>p(j.target.value),placeholder:t("settings.commands.page.field.commandNamePlaceholder"),className:"h-7 w-40 px-2"})]}),s.jsxs(Ot,{value:A,onValueChange:j=>b(j),children:[s.jsx(Lt,{size:Jt,className:"w-fit min-w-[100px]",children:s.jsx(Ht,{placeholder:t("settings.agents.page.field.scopePlaceholder")})}),s.jsxs(Ft,{align:"end",children:[s.jsx(ut,{value:"user",children:s.jsxs("div",{className:"flex items-center gap-2",children:[s.jsx(L,{name:"user-3",className:"h-3.5 w-3.5"}),s.jsx("span",{children:t("settings.common.scope.global")})]})}),s.jsx(ut,{value:"project",children:s.jsxs("div",{className:"flex items-center gap-2",children:[s.jsx(L,{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(Es,{value:P,onChange:j=>N(j.target.value),placeholder:t("settings.commands.page.field.descriptionPlaceholder"),rows:2,className:"w-full resize-none min-h-[60px] bg-transparent"})})]})]}),s.jsxs(Be,{title:t("settings.commands.page.section.executionContext"),contentClassName:"space-y-0",children:[s.jsx(Qt,{settingsItem:"commands.agent",label:t("settings.commands.page.field.overrideAgent"),children:s.jsx(rl,{agentName:k,onChange:j=>g(j),className:Cn})}),s.jsx(Qt,{settingsItem:"commands.model",label:t("settings.agents.page.field.overrideModel"),children:s.jsx(Ea,{providerId:oa(E)?.providerId??"",modelId:oa(E)?.modelId??"",onChange:(j,R)=>{O(j&&R?`${j}/${R}`:"")},className:Cn})})]}),s.jsxs(Be,{title:t("settings.commands.page.section.template"),settingsItem:"commands.template",children:[s.jsx(Es,{value:I,onChange:j=>w(j.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:T,disabled:m||!C,size:"xs",className:"!font-normal",children:t(m?"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(L,{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")})]})})},so=t=>{switch(t){case"connected":return"success";case"failed":return"error";case"needs_auth":case"needs_client_registration":return"warning";default:return"idle"}},no=t=>{const e=mt.c(5),{tone:a,enabled:n}=t;if(!n){let l;return e[0]===Symbol.for("react.memo_cache_sentinel")?(l=s.jsx("span",{className:"inline-block h-2 w-2 rounded-full bg-muted-foreground/30 flex-shrink-0"}),e[0]=l):l=e[0],l}let i;e[1]!==a?(i=je("inline-block h-2 w-2 rounded-full flex-shrink-0",{success:"bg-[var(--status-success)]",error:"bg-[var(--status-error)]",warning:"bg-[var(--status-warning)]",idle:"bg-muted-foreground/40"}[a]),e[1]=a,e[2]=i):i=e[2];let r;return e[3]!==i?(r=s.jsx("span",{className:i}),e[3]=i,e[4]=r):r=e[4],r},Sp=t=>{const e=mt.c(124),{onItemSelect:a}=t,{t:n}=ot(),{selectedMcpName:i,setSelectedMcp:r,setMcpDraft:l,loadMcpConfigs:h,deleteMcp:d}=ca(Ms(Cp)),x=Us();let c;e[0]!==x?(c=pe=>ol(pe,x),e[0]=x,e[1]=c):c=e[1];const v=ca(c);let p;e[2]!==x?(p=pe=>pe.getStatusForDirectory(x),e[2]=x,e[3]=p):p=e[3];const A=Rs(p),b=Rs(Pp),P=Rs(Ip),[N,k]=o.useState(null),[g,E]=o.useState(!1),[O,I]=o.useState(null),[w,m]=o.useState(null),[y,K]=o.useState(!1);let C;e[4]!==v?(C=v.filter(Ap),e[4]=v,e[5]=C):C=e[5];const T=C;let j;e[6]!==v?(j=v.filter(Ep),e[6]=v,e[7]=j):j=e[7];const R=j;let G,S;e[8]!==h||e[9]!==x?(G=()=>{h({directory:x})},S=[h,x],e[8]=h,e[9]=x,e[10]=G,e[11]=S):(G=e[10],S=e[11]),o.useEffect(G,S);let q;e[12]!==P||e[13]!==y||e[14]!==b||e[15]!==x?(q=()=>{if(y)return;K(!0);const pe=new Promise(Tp);Promise.all([b({directory:x,silent:!0}),pe]).then(()=>{const Fe=P(x);Fe&&D.error(Fe)}).finally(()=>{K(!1)})},e[12]=P,e[13]=y,e[14]=b,e[15]=x,e[16]=q):q=e[16];const Q=q;let M;e[17]!==v||e[18]!==a||e[19]!==l||e[20]!==r?(M=()=>{let pe="new-mcp-server",Fe=1;for(;v.some(He=>He.name===pe);)pe=`new-mcp-server-${Fe}`,Fe++;l({name:pe,scope:"user",type:"local",command:[],url:"",environment:[],headers:[],oauthEnabled:!0,oauthClientId:"",oauthClientSecret:"",oauthScope:"",oauthRedirectUri:"",timeout:"",enabled:!0}),r(pe),a?.()},e[17]=v,e[18]=a,e[19]=l,e[20]=r,e[21]=M):M=e[21];const W=M;let Y;e[22]!==d||e[23]!==N||e[24]!==x||e[25]!==n?(Y=async()=>{if(!N)return;E(!0);const pe=await d(N.name,x);pe.ok?pe.reloadFailed?D.warning(pe.message||`MCP server "${N.name}" deleted, but OpenCode reload failed`,{description:pe.warning||n("settings.mcp.sidebar.toast.refreshListIfStale")}):D.success(pe.message||n("settings.mcp.sidebar.toast.serverDeleted",{name:N.name})):D.error(n("settings.mcp.sidebar.toast.deleteFailed")),k(null),E(!1)},e[22]=d,e[23]=N,e[24]=x,e[25]=n,e[26]=Y):Y=e[26];const F=Y;let se;e[27]!==n?(se=(pe,Fe)=>s.jsxs(Fe,{onClick:H=>{H.stopPropagation(),k(pe)},className:"text-destructive focus:text-destructive",children:[s.jsx(L,{name:"delete-bin",className:"h-4 w-4 mr-px"}),n("settings.common.actions.delete")]}),e[27]=n,e[28]=se):se=e[28];const _=se;let V;e[29]===Symbol.for("react.memo_cache_sentinel")?(V=je("flex h-full flex-col","bg-background"),e[29]=V):V=e[29];let z;e[30]!==n?(z=n("settings.mcp.sidebar.title"),e[30]=n,e[31]=z):z=e[31];let U;e[32]!==z?(U=s.jsx("h2",{className:rn,children:z}),e[32]=z,e[33]=U):U=e[33];let X;e[34]!==n?(X=n("settings.mcp.sidebar.actions.refreshStatusAria"),e[34]=n,e[35]=X):X=e[35];let Z;e[36]!==n?(Z=n("settings.mcp.sidebar.actions.refreshStatusTitle"),e[36]=n,e[37]=Z):Z=e[37];const ne=y&&"animate-spin";let le;e[38]!==ne?(le=je("h-4 w-4",ne),e[38]=ne,e[39]=le):le=e[39];let re;e[40]!==le?(re=s.jsx(L,{name:"refresh",className:le}),e[40]=le,e[41]=re):re=e[41];let fe;e[42]!==Q||e[43]!==y||e[44]!==X||e[45]!==Z||e[46]!==re?(fe=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:y,onClick:Q,"aria-label":X,title:Z,children:re}),e[42]=Q,e[43]=y,e[44]=X,e[45]=Z,e[46]=re,e[47]=fe):fe=e[47];let ae;e[48]!==U||e[49]!==fe?(ae=s.jsxs("div",{className:"mb-3 flex items-center justify-between gap-3",children:[U,fe]}),e[48]=U,e[49]=fe,e[50]=ae):ae=e[50];let ie;e[51]===Symbol.for("react.memo_cache_sentinel")?(ie=s.jsx(Ka,{className:"mb-3"}),e[51]=ie):ie=e[51];let te;e[52]!==v.length||e[53]!==n?(te=n("settings.mcp.sidebar.total",{count:v.length}),e[52]=v.length,e[53]=n,e[54]=te):te=e[54];let ye;e[55]!==te?(ye=s.jsx("span",{className:"typography-meta text-muted-foreground",children:te}),e[55]=te,e[56]=ye):ye=e[56];let we;e[57]!==n?(we=n("settings.mcp.sidebar.actions.addServerTitle"),e[57]=n,e[58]=we):we=e[58];let ke;e[59]===Symbol.for("react.memo_cache_sentinel")?(ke=s.jsx(L,{name:"add",className:"h-3.5 w-3.5"}),e[59]=ke):ke=e[59];let xe;e[60]!==W||e[61]!==we?(xe=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:W,title:we,children:ke}),e[60]=W,e[61]=we,e[62]=xe):xe=e[62];let De;e[63]!==ye||e[64]!==xe?(De=s.jsxs("div",{className:"flex items-center justify-between gap-2",children:[ye,xe]}),e[63]=ye,e[64]=xe,e[65]=De):De=e[65];let Me;e[66]!==ae||e[67]!==De?(Me=s.jsxs("div",{className:"border-b px-3 pt-4 pb-3",children:[ae,ie,De]}),e[66]=ae,e[67]=De,e[68]=Me):Me=e[68];let he;e[69]!==v.length||e[70]!==A||e[71]!==a||e[72]!==O||e[73]!==T||e[74]!==_||e[75]!==w||e[76]!==i||e[77]!==l||e[78]!==r||e[79]!==n||e[80]!==R?(he=s.jsx(Vs,{outerClassName:"flex-1 min-h-0",className:"space-y-1 px-3 py-2 overflow-x-hidden",children:v.length===0?s.jsxs("div",{className:"py-12 px-4 text-center text-muted-foreground",children:[s.jsx(L,{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:[T.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")}),T.map(pe=>{const Fe=A[pe.name],H=so(Fe?.status),He=i===pe.name,et=Ra();return s.jsxs(Gn,{open:w===pe.name,onOpenChange:ze=>m(ze?pe.name:null),children:[s.jsxs(Hn,{render:s.jsx("div",{className:je("group relative flex items-center rounded-md px-1.5 py-1 transition-all duration-200 select-none",He?"bg-interactive-selection":"hover:bg-interactive-hover"),onContextMenu:et?void 0:ze=>{ze.preventDefault(),m(pe.name)}}),children:[s.jsxs("button",{onClick:()=>{r(pe.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(no,{tone:H,enabled:pe.enabled}),s.jsx("span",{className:"typography-ui-label font-normal truncate text-foreground",children:pe.name}),s.jsx("span",{title:pe.type==="local"?n("settings.mcp.sidebar.serverType.localTitle"):n("settings.mcp.sidebar.serverType.remoteTitle"),children:pe.type==="local"?s.jsx(L,{name:"server",className:"h-3 w-3 text-muted-foreground/60 flex-shrink-0"}):s.jsx(L,{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:pe.type==="local"?pe.command?.join(" ")??"":pe.url??""})]}),s.jsxs(nn,{open:O===pe.name,onOpenChange:ze=>{ze&&m(null),I(ze?pe.name:null)},children:[s.jsx(tn,{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(L,{name:"more-2",className:"h-3.5 w-3.5"})})}),s.jsx(sn,{align:"end",className:"w-fit min-w-20",children:_(pe,an)})]})]}),s.jsx(Vn,{className:"w-fit min-w-20",children:_(pe,Bn)})]},pe.name)})]}),R.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")}),R.map(pe=>{const Fe=A[pe.name],H=so(Fe?.status),He=i===pe.name,et=Ra();return s.jsxs(Gn,{open:w===pe.name,onOpenChange:ze=>m(ze?pe.name:null),children:[s.jsxs(Hn,{render:s.jsx("div",{className:je("group relative flex items-center rounded-md px-1.5 py-1 transition-all duration-200 select-none",He?"bg-interactive-selection":"hover:bg-interactive-hover"),onContextMenu:et?void 0:ze=>{ze.preventDefault(),m(pe.name)}}),children:[s.jsxs("button",{onClick:()=>{r(pe.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(no,{tone:H,enabled:pe.enabled}),s.jsx("span",{className:"typography-ui-label font-normal truncate text-foreground",children:pe.name}),s.jsx("span",{title:pe.type==="local"?n("settings.mcp.sidebar.serverType.localTitle"):n("settings.mcp.sidebar.serverType.remoteTitle"),children:pe.type==="local"?s.jsx(L,{name:"server",className:"h-3 w-3 text-muted-foreground/60 flex-shrink-0"}):s.jsx(L,{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:pe.type==="local"?pe.command?.join(" ")??"":pe.url??""})]}),s.jsxs(nn,{open:O===pe.name,onOpenChange:ze=>{ze&&m(null),I(ze?pe.name:null)},children:[s.jsx(tn,{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(L,{name:"more-2",className:"h-3.5 w-3.5"})})}),s.jsx(sn,{align:"end",className:"w-fit min-w-20",children:_(pe,an)})]})]}),s.jsx(Vn,{className:"w-fit min-w-20",children:_(pe,Bn)})]},pe.name)})]})]})}),e[69]=v.length,e[70]=A,e[71]=a,e[72]=O,e[73]=T,e[74]=_,e[75]=w,e[76]=i,e[77]=l,e[78]=r,e[79]=n,e[80]=R,e[81]=he):he=e[81];const ge=N!==null;let Ae;e[82]!==g?(Ae=pe=>{!pe&&!g&&k(null)},e[82]=g,e[83]=Ae):Ae=e[83];let Ve;e[84]!==n?(Ve=n("settings.mcp.sidebar.deleteDialog.title"),e[84]=n,e[85]=Ve):Ve=e[85];let _e;e[86]!==Ve?(_e=s.jsx(qt,{children:Ve}),e[86]=Ve,e[87]=_e):_e=e[87];const Le=N?.name||"";let Re;e[88]!==n||e[89]!==Le?(Re=n("settings.mcp.sidebar.deleteDialog.descriptionPrefix",{name:Le}),e[88]=n,e[89]=Le,e[90]=Re):Re=e[90];let Ze;e[91]===Symbol.for("react.memo_cache_sentinel")?(Ze=s.jsx("code",{className:"text-foreground",children:"opencode.json"}),e[91]=Ze):Ze=e[91];let Ge;e[92]!==Re?(Ge=s.jsxs(Wt,{children:[Re," ",Ze,"."]}),e[92]=Re,e[93]=Ge):Ge=e[93];let Oe;e[94]!==_e||e[95]!==Ge?(Oe=s.jsxs(Gt,{children:[_e,Ge]}),e[94]=_e,e[95]=Ge,e[96]=Oe):Oe=e[96];let Ke;e[97]===Symbol.for("react.memo_cache_sentinel")?(Ke=()=>k(null),e[97]=Ke):Ke=e[97];let Pe;e[98]!==n?(Pe=n("settings.common.actions.cancel"),e[98]=n,e[99]=Pe):Pe=e[99];let Ue;e[100]!==g||e[101]!==Pe?(Ue=s.jsx(B,{size:"sm",variant:"ghost",onClick:Ke,disabled:g,children:Pe}),e[100]=g,e[101]=Pe,e[102]=Ue):Ue=e[102];let ve;e[103]!==g||e[104]!==n?(ve=n(g?"settings.mcp.sidebar.actions.deleting":"settings.common.actions.delete"),e[103]=g,e[104]=n,e[105]=ve):ve=e[105];let We;e[106]!==F||e[107]!==g||e[108]!==ve?(We=s.jsx(B,{size:"sm",onClick:F,disabled:g,children:ve}),e[106]=F,e[107]=g,e[108]=ve,e[109]=We):We=e[109];let $;e[110]!==Ue||e[111]!==We?($=s.jsxs(ms,{children:[Ue,We]}),e[110]=Ue,e[111]=We,e[112]=$):$=e[112];let de;e[113]!==Oe||e[114]!==$?(de=s.jsxs(_t,{className:"max-w-md",children:[Oe,$]}),e[113]=Oe,e[114]=$,e[115]=de):de=e[115];let ue;e[116]!==ge||e[117]!==Ae||e[118]!==de?(ue=s.jsx(zt,{open:ge,onOpenChange:Ae,children:de}),e[116]=ge,e[117]=Ae,e[118]=de,e[119]=ue):ue=e[119];let Ne;return e[120]!==Me||e[121]!==he||e[122]!==ue?(Ne=s.jsxs("div",{className:V,children:[Me,he,ue]}),e[120]=Me,e[121]=he,e[122]=ue,e[123]=Ne):Ne=e[123],Ne};function Cp(t){return{selectedMcpName:t.selectedMcpName,setSelectedMcp:t.setSelectedMcp,setMcpDraft:t.setMcpDraft,loadMcpConfigs:t.loadMcpConfigs,deleteMcp:t.deleteMcp}}function Pp(t){return t.refresh}function Ip(t){return t.getErrorForDirectory}function Ap(t){return t.scope==="project"}function Ep(t){return t.scope!=="project"}function Tp(t){return setTimeout(t,500)}function Xs(t){return typeof t=="object"&&t!==null&&!Array.isArray(t)}function ja(t){return Array.isArray(t)&&t.every(e=>typeof e=="string")}function Zs(t,e){return e!==void 0?{ok:!1,error:t,parsed:e}:{ok:!1,error:t}}function Ha(t,e,a){const n=Dp(a),i=typeof a.url=="string"?a.url.trim():"",r=ao(a,"env","environment"),l=ao(a,"headers"),h=Mp(a),d=typeof a.oauth=="object"&&a.oauth!==null?String(a.oauth.clientId??"").trim():"",x=typeof a.oauth=="object"&&a.oauth!==null?String(a.oauth.clientSecret??"").trim():"",c=typeof a.oauth=="object"&&a.oauth!==null?String(a.oauth.scope??"").trim():"",v=typeof a.oauth=="object"&&a.oauth!==null?String(a.oauth.redirectUri??"").trim():"",p=Rp(a),A=Op(a);return{ok:!0,name:t,type:e,command:n,url:i,environment:r,headers:l,oauthEnabled:h,oauthClientId:d,oauthClientSecret:x,oauthScope:c,oauthRedirectUri:v,timeout:p,enabled:A}}function Dp(t){const e=t.command,a=t.args;if(ja(e)&&ja(a))return[...e,...a];if(ja(e))return e;if(typeof e=="string"&&e.trim()){const n=e.trim().split(/\s+/);return ja(a)?[...n,...a]:n}return ja(a)?a:[]}function ao(t,...e){for(const a of e){const n=t[a];if(!Xs(n))continue;const i=Object.entries(n).filter(([r,l])=>r&&typeof l=="string");if(i.length>0)return i.map(([r,l])=>({key:r,value:String(l)}))}return[]}function Mp(t){if(t.oauth===!1||t.oauth===null||t.oauth===void 0||!Xs(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 Rp(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 Op(t){return"disabled"in t&&t.disabled===!0?!1:"enabled"in t?!!t.enabled:!0}function Lp(t){const e=t.mcpServers;if(Xs(e)){const n=Object.keys(e);if(n.length===1){const i=n[0],r=e[i];if(Xs(r))return{name:i,entry:r}}if(n.length>1)return null}const a=Object.keys(t).filter(n=>{const i=t[n];return n!=="mcpServers"&&Xs(i)});if(a.length===1){const n=a[0],i=t[n];if(Il(i))return{name:n,entry:i}}return null}function Il(t){return t.type==="local"||t.type==="remote"||Array.isArray(t.command)||typeof t.url=="string"||Array.isArray(t.args)}function Fp(t,e){let a;try{const h=t.trim();if(!h)return Zs("No JSON content provided");a=JSON.parse(h)}catch(h){return Zs(h instanceof Error?`Invalid JSON: ${h.message}`:"Invalid JSON")}if(!Xs(a))return Zs("Expected a JSON object, not an array or primitive");const n=a,i=n.mcpServers;if(Xs(i)){const h=Object.keys(i);if(h.length===0)return Zs("mcpServers object is empty",a);if(h.length>1)return Zs("Paste one server at a time. Found "+h.length+" servers in mcpServers",a);const d=h[0],x=i[d];return Xs(x)?Ha(d,Ga(x),x):Zs("Server entry is not a valid object",a)}const r=n.mcp;if(Xs(r)){const h=Object.keys(r);if(h.length===0)return Zs("mcp object is empty",a);if(h.length>1)return Zs("Paste one server at a time. Found "+h.length+" servers in mcp",a);const d=h[0],x=r[d];return Xs(x)?Ha(d,Ga(x),x):Zs("Server entry in mcp is not a valid object",a)}const l=Lp(n);if(l)return Ha(l.name,Ga(l.entry),l.entry);if(Il(n)){const h=Ga(n),d=typeof n.name=="string"&&n.name.trim()?n.name.trim():e?.fallbackName;return Ha(d,h,n)}return Zs("No recognizable MCP server configuration found in JSON",a)}function Ga(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 Kp(t,e,a){const n=a?.isNewServer??!1,i=t.name,r=n&&i?i:e.name??"";return{...e,name:r,type:t.type,command:t.type==="local"?t.command:[],url:t.type==="remote"?t.url:"",environment:t.environment,headers:t.type==="remote"?t.headers:[],oauthEnabled:t.type==="remote"?t.oauthEnabled:!1,oauthClientId:t.type==="remote"?t.oauthClientId:"",oauthClientSecret:t.type==="remote"?t.oauthClientSecret:"",oauthScope:t.type==="remote"?t.oauthScope:"",oauthRedirectUri:t.type==="remote"?t.oauthRedirectUri:"",timeout:t.type==="remote"?t.timeout:"",enabled:t.enabled}}function Al(t){const e=[];let a="",n=!1,i=!1;for(let r=0;r<t.length;r++){const l=t[r];if(l==="'"&&!i){n=!n;continue}if(l==='"'&&!n){i=!i;continue}if((l===" "||l===" ")&&!n&&!i){a&&(e.push(a),a="");continue}a+=l}return a&&e.push(a),e}function Up(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:cc(a.searchParams),stateKey:ll(a.searchParams)}}catch{}return{code:e,context:null,stateKey:null}}const zp=t=>{const e=mt.c(27),{value:a,onChange:n,preview:i,onDetectUrl:r}=t;let l;e[0]!==a?(l=()=>a.join(`
|
|
4
|
-
`),e[0]=a,e[1]=l):l=e[1];const[h,d]=o.useState(l),x=o.useRef(a);let c,v;e[2]!==a?(c=()=>{JSON.stringify(x.current)!==JSON.stringify(a)&&(x.current=a,d(a.join(`
|
|
5
|
-
`)))},v=[a],e[2]=a,e[3]=c,e[4]=v):(c=e[3],v=e[4]),o.useEffect(c,v);let p;e[5]!==n||e[6]!==r?(p=w=>{const m=w.split(`
|
|
6
|
-
`).filter(Wp);if(r&&m.length===1&&/^https?:\/\/\S+$/i.test(m[0].trim())){r(m[0].trim());return}n(m)},e[5]=n,e[6]=r,e[7]=p):p=e[7];const A=p;let b;e[8]!==n?(b=w=>{const y=w.clipboardData.getData("text").trim();if(!y||y.includes(`
|
|
7
|
-
`)||!/\s/.test(y))return;const K=w.currentTarget;if(K.selectionStart!==0||K.selectionEnd!==K.value.length)return;w.preventDefault();const C=Al(y);d(C.join(`
|
|
8
|
-
`)),n(C)},e[8]=n,e[9]=b):b=e[9];const P=b;let N;e[10]!==A?(N=w=>{d(w.target.value),A(w.target.value)},e[10]=A,e[11]=N):N=e[11];let k;e[12]!==A||e[13]!==h?(k=()=>{const w=h.split(`
|
|
9
|
-
`).map(Jp).join(`
|
|
10
|
-
`);d(w),A(w)},e[12]=A,e[13]=h,e[14]=k):k=e[14];const g=Math.max(4,a.length+1);let E;e[15]!==P||e[16]!==N||e[17]!==k||e[18]!==g||e[19]!==h?(E=s.jsx(Es,{onPaste:P,value:h,onChange:N,onBlur:k,placeholder:`npx
|
|
11
|
-
-y
|
|
12
|
-
@modelcontextprotocol/server-postgres
|
|
13
|
-
postgresql://user:pass@host/db`,rows:g,className:"font-mono typography-meta min-h-[80px]",spellCheck:!1}),e[15]=P,e[16]=N,e[17]=k,e[18]=g,e[19]=h,e[20]=E):E=e[20];let O;e[21]!==i||e[22]!==a?(O=a.length>0&&s.jsxs("details",{className:"group",children:[s.jsx("summary",{className:"typography-micro text-muted-foreground/60 cursor-pointer select-none hover:text-muted-foreground",children:i(a.length)}),s.jsx("div",{className:"mt-1 rounded-md bg-[var(--surface-elevated)] px-3 py-2 overflow-x-auto",children:s.jsx("code",{className:"typography-micro text-foreground/80 whitespace-pre",children:a.map(Qp)})})]}),e[21]=i,e[22]=a,e[23]=O):O=e[23];let I;return e[24]!==O||e[25]!==E?(I=s.jsxs("div",{className:"space-y-2","data-bwignore":"true","data-1p-ignore":"true","data-lpignore":"true",children:[E,O]}),e[24]=O,e[25]=E,e[26]=I):I=e[26],I},_p=t=>t.toUpperCase().replace(/[^A-Z0-9_]/g,"_"),io=({value:t,onChange:e,keyTransform:a=_p,keyPlaceholder:n="API_KEY",keyInputClassName:i="w-36 shrink-0 font-mono typography-meta uppercase",pasteLabel:r="Paste .env",pasteTitle:l="Paste KEY=VALUE lines from clipboard",noPairsFoundError:h,importSuccess:d,clipboardReadFailed:x,keyLabel:c,valueLabel:v,valuePlaceholder:p,hideValueTitle:A,showValueTitle:b,addVariable:P,plainTextWarning:N,removeVariableAria:k})=>{const[g,E]=o.useState(new Set),O=()=>e([...t,{key:"",value:""}]),I=C=>{e(t.filter((T,j)=>j!==C)),E(T=>{const j=new Set(T);return j.delete(C),j})},w=(C,T,j)=>{const R=[...t];R[C]={...R[C],[T]:j},e(R)},m=C=>{E(T=>{const j=new Set(T);return j.has(C)?j.delete(C):j.add(C),j})},y=async()=>{try{const C=await navigator.clipboard.readText(),T=[];for(const R of C.split(`
|
|
14
|
-
`)){const G=R.trim();if(!G||G.startsWith("#"))continue;const S=G.indexOf("=");if(S===-1)continue;const q=G.slice(0,S).trim();let Q=G.slice(S+1).trim();(Q.startsWith('"')&&Q.endsWith('"')||Q.startsWith("'")&&Q.endsWith("'"))&&(Q=Q.slice(1,-1)),q&&T.push({key:q,value:Q})}if(T.length===0){D.error(h);return}const j=[...t];for(const R of T){const G=j.findIndex(S=>S.key===R.key);G!==-1?j[G]=R:j.push(R)}e(j),D.success(d(T.length))}catch{D.error(x)}},K=t.some(C=>C.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:c}),s.jsx("span",{className:"typography-micro text-muted-foreground",children:v})]}),s.jsxs(B,{variant:"ghost",size:"xs",className:"!font-normal gap-1 text-muted-foreground",onClick:y,type:"button",title:l,children:[s.jsx(L,{name:"clipboard",className:"h-3 w-3"}),r]})]}),s.jsx("div",{className:"space-y-1.5",children:t.map((C,T)=>s.jsxs("div",{className:"flex items-center gap-2",children:[s.jsx(Ye,{value:C.key,onChange:j=>w(T,"key",a(j.target.value)),placeholder:n,className:i,"data-bwignore":"true","data-1p-ignore":"true","data-lpignore":"true",spellCheck:!1}),s.jsxs("div",{className:"relative flex-1 flex items-center",children:[s.jsx(Ye,{type:g.has(T)?"text":"password",value:C.value,onChange:j=>w(T,"value",j.target.value),placeholder:p,className:"font-mono typography-meta pr-8 w-full",autoComplete:"new-password","data-bwignore":"true","data-1p-ignore":"true","data-lpignore":"true",spellCheck:!1}),s.jsx("button",{type:"button",onClick:()=>m(T),className:"absolute right-2 text-muted-foreground/60 hover:text-muted-foreground",title:g.has(T)?A:b,children:g.has(T)?s.jsx(L,{name:"eye-off",className:"h-3.5 w-3.5"}):s.jsx(L,{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(T),"aria-label":k,children:s.jsx(L,{name:"delete-bin",className:"h-3.5 w-3.5"})})]},T))}),s.jsxs(B,{variant:"outline",size:"xs",className:"!font-normal gap-1.5",onClick:O,type:"button",children:[s.jsx(L,{name:"add",className:"h-3.5 w-3.5"}),P]}),K&&s.jsx("p",{className:"typography-micro text-muted-foreground/60",children:N})]})},Oi=t=>{const e=mt.c(14),{status:a,enabled:n,getStatusLabel:i,variant:r}=t,l=r===void 0?"compact":r;if(!n||!a)return null;let h,d;if(e[0]!==i||e[1]!==a||e[2]!==l){d=Symbol.for("react.early_return_sentinel");e:{const p={connected:{text:"text-[var(--status-success)]",bg:"bg-[var(--status-success)]/10"},failed:{text:"text-[var(--status-error)]",bg:"bg-[var(--status-error)]/10"},needs_auth:{text:"text-[var(--status-warning)]",bg:"bg-[var(--status-warning)]/10"},needs_client_registration:{text:"text-[var(--status-warning)]",bg:"bg-[var(--status-warning)]/10"},awaiting_restart:{text:"text-[var(--status-warning)]",bg:"bg-[var(--status-warning)]/10"}}[a]??{text:"text-muted-foreground",bg:""};if(l==="pill"){const A=je("typography-micro font-medium rounded-full px-2 py-0.5",p.text,p.bg);let b;e[5]!==i||e[6]!==a?(b=i(a),e[5]=i,e[6]=a,e[7]=b):b=e[7],d=s.jsxs("span",{className:A,children:["● ",b]});break e}h=je("typography-micro font-medium",p.text)}e[0]=i,e[1]=a,e[2]=l,e[3]=h,e[4]=d}else h=e[3],d=e[4];if(d!==Symbol.for("react.early_return_sentinel"))return d;let x;e[8]!==i||e[9]!==a?(x=i(a),e[8]=i,e[9]=a,e[10]=x):x=e[10];let c;return e[11]!==h||e[12]!==x?(c=s.jsxs("span",{className:h,children:["● ",x]}),e[11]=h,e[12]=x,e[13]=c):c=e[13],c},$p=(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")}},Vp=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)]"}},Bp=(t,e,a,n)=>!!(t==="failed"||t==="needs_auth"||t==="needs_client_registration"||e||a||n),Hp=async t=>{const e=await pt(`/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},wa=async t=>{typeof t!="string"||!t.trim()||await pt(`/api/mcp/auth/pending?state=${encodeURIComponent(t.trim())}`,{method:"DELETE"}).catch(()=>{})},qa=(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},Gp=(t,e)=>{const a=typeof e=="string"&&e.trim()?e.trim():"__global__";return`${t??"__none__"}::${a}`},qp=()=>{const{t}=ot(),e=o.useCallback((oe,ct)=>t(oe,ct),[t]),{selectedMcpName:a,mcpDraft:n,setMcpDraft:i,setSelectedMcp:r,getMcpByName:l,createMcp:h,updateMcp:d,deleteMcp:x}=ca(Ms(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}))),c=Us(),v=o.useMemo(()=>vs(),[]),p=Rs(oe=>oe.getStatusForDirectory(c)),A=Rs(oe=>oe.getDiagnosticForDirectory(c)),b=Rs(oe=>oe.refresh),P=Rs(oe=>oe.connect),N=Rs(oe=>oe.disconnect),k=Rs(oe=>oe.completeAuth),g=Rs(oe=>oe.clearAuth),E=Rs(oe=>oe.testConnection),O=dn(oe=>oe.changes),I=ca(oe=>ol(oe,c)),w=a?l(a,c):null,m=!!(n&&n.name===a&&!w),[y,K]=o.useState(""),[C,T]=o.useState("user"),[j,R]=o.useState("local"),[G,S]=o.useState([]),[q,Q]=o.useState(""),[M,W]=o.useState([]),[Y,F]=o.useState([]),[se,_]=o.useState(!0),[V,z]=o.useState(""),[U,X]=o.useState(""),[Z,ne]=o.useState(""),[le,re]=o.useState(""),[fe,ae]=o.useState(""),[ie,te]=o.useState(!0),[ye,we]=o.useState(!1),[ke,xe]=o.useState(!1),[De,Me]=o.useState(!1),[he,ge]=o.useState(!1),[Ae,Ve]=o.useState(!1),[_e,Le]=o.useState(!1),[Re,Ze]=o.useState(!1),[Ge,Oe]=o.useState(!1),[Ke,Pe]=o.useState(null),[Ue,ve]=o.useState(null),[We,$]=o.useState(""),[de,ue]=o.useState(!1),Ne=o.useRef(0),pe=o.useRef(!1),[Fe,H]=o.useState(!1),[He,et]=o.useState(!1),[ze,st]=o.useState(""),[wt,xt]=o.useState(null),gt=o.useMemo(()=>Gp(a,c),[c,a]),bt=o.useRef(gt),St=o.useRef(null),yt=o.useCallback(()=>{Pe(null),ve(null),$(""),ue(!1),Ne.current=0,Oe(!1),Ve(!1),Le(!1),pe.current=!1},[]),It=o.useCallback(()=>{st(""),xt(null),et(!0)},[]),qe=o.useCallback(async()=>{try{const oe=await navigator.clipboard.readText();st(oe),xt(null)}catch{D.error(t("settings.mcp.page.toast.clipboardReadFailed"))}},[t]),Qe=o.useCallback(()=>{const oe=Fp(ze,{fallbackName:y});if(!oe.ok){xt(oe.error);return}const Ce=Kp(oe,{name:y,scope:C,type:j,command:G,url:q,environment:M,headers:Y,oauthEnabled:se,oauthClientId:V,oauthClientSecret:U,oauthScope:Z,oauthRedirectUri:le,timeout:fe,enabled:ie},{isNewServer:m});K(Ce.name),R(Ce.type),S(Ce.command??[]),Q(Ce.url??""),W(Ce.environment??[]),F(Ce.headers??[]),_(Ce.oauthEnabled??!1),z(Ce.oauthClientId??""),X(Ce.oauthClientSecret??""),ne(Ce.oauthScope??""),re(Ce.oauthRedirectUri??""),ae(Ce.timeout??""),te(Ce.enabled??!0),et(!1),st(""),xt(null),D.success(t("settings.mcp.page.toast.configImported"))},[ze,y,C,j,G,q,M,Y,se,V,U,Z,le,fe,ie,m,t]);o.useEffect(()=>{if(m&&n){K(n.name),T(n.scope||"user"),R(n.type),S(n.command),Q(n.url),W(n.environment),F(n.headers),_(n.oauthEnabled),z(n.oauthClientId),X(n.oauthClientSecret),ne(n.oauthScope),re(n.oauthRedirectUri),ae(n.timeout),te(n.enabled),H(!1),St.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){T(w.scope==="project"?"project":"user");const oe=Cr(w.environment),ct=w.type==="remote"?w:null,Ce=Cr(ct?.headers),it=ct?.oauth,jt=it&&typeof it=="object"?it:null,At=it!==!1,Tt=w.type,Xt=Tt==="local"?w.command??[]:[],ls=Tt==="remote"?w.url??"":"",ft=typeof ct?.timeout=="number"&&Number.isFinite(ct.timeout)?String(ct.timeout):"";R(Tt),S(Xt),Q(ls),W(oe),F(Ce),_(At),z(At?jt?.clientId??"":""),X(At?jt?.clientSecret??"":""),ne(At?jt?.scope??"":""),re(At?jt?.redirectUri??"":""),ae(ft),te(w.enabled),H(!1),St.current={mcpType:Tt,command:Xt,url:ls,envEntries:oe,headerEntries:Ce,oauthEnabled:At,oauthClientId:At?jt?.clientId??"":"",oauthClientSecret:At?jt?.clientSecret??"":"",oauthScope:At?jt?.scope??"":"",oauthRedirectUri:At?jt?.redirectUri??"":"",timeout:ft,enabled:w.enabled}}},[w,m,n]);const dt=o.useMemo(()=>{const oe=St.current;return oe?j!==oe.mcpType||ie!==oe.enabled||JSON.stringify(G)!==JSON.stringify(oe.command)||q!==oe.url||JSON.stringify(M)!==JSON.stringify(oe.envEntries)||JSON.stringify(Y)!==JSON.stringify(oe.headerEntries)||se!==oe.oauthEnabled||V!==oe.oauthClientId||U!==oe.oauthClientSecret||Z!==oe.oauthScope||le!==oe.oauthRedirectUri||fe!==oe.timeout:!1},[j,G,q,M,Y,se,V,U,Z,le,fe,ie]),Ee=o.useMemo(()=>[{id:"local",label:t("settings.mcp.page.connection.kindCommand"),icon:s.jsx(L,{name:"terminal",className:"h-3.5 w-3.5"})},{id:"remote",label:t("settings.mcp.page.connection.kindLink"),icon:s.jsx(L,{name:"global",className:"h-3.5 w-3.5"})}],[t]),vt=o.useCallback(oe=>{R("remote"),Q(oe),S([])},[]),Se=o.useCallback(oe=>{Q(oe);const ct=oe.trim();ct&&!/^[a-z][a-z0-9+.-]*:\/\//i.test(ct)&&/\s/.test(ct)&&(R("local"),S(Al(ct)),Q(""))},[]),kt=async()=>{const oe=m?y.trim():a??"";if(!oe){D.error(t("settings.mcp.page.toast.nameRequired"));return}if(m&&I.some(Ce=>Ce.name===oe)){D.error(t("settings.mcp.page.toast.serverNameExists"));return}if(j==="local"&&G.filter(Boolean).length===0){D.error(t("settings.mcp.page.toast.localCommandRequired"));return}if(j==="remote"&&!q.trim()){D.error(t("settings.mcp.page.toast.remoteUrlRequired"));return}const ct={name:oe,scope:C,type:j,command:G,url:q,environment:M,headers:Y,oauthEnabled:se,oauthClientId:V,oauthClientSecret:U,oauthScope:Z,oauthRedirectUri:le,timeout:fe,enabled:ie};we(!0);try{const Ce=m?await h(ct,c):await d(oe,ct,c);Ce.ok?(await wa(Ue),yt(),m&&(i(null),r(oe)),await b({directory:c,silent:!0}),Ce.reloadFailed?D.warning(Ce.message||t(m?"settings.mcp.page.toast.serverCreatedReloadFailed":"settings.mcp.page.toast.savedReloadFailed"),{description:Ce.warning||t("settings.mcp.page.toast.retryRefreshHint")}):Ce.restartDeferred?D.success(t("settings.view.pendingRestart.saved")):D.success(Ce.message||t(m?"settings.mcp.page.toast.serverCreatedReloading":"settings.mcp.page.toast.savedReloading"))):D.error(t("settings.mcp.page.toast.saveFailed"))}catch(Ce){D.error(Ce instanceof Error?Ce.message:t("settings.mcp.page.toast.unexpectedError"))}finally{we(!1)}},J=async()=>{if(!a)return;Me(!0);const oe=await x(a,c);oe.ok?(await wa(Ue),yt(),oe.reloadFailed?D.warning(oe.message||t("settings.mcp.page.toast.serverDeletedReloadFailed",{name:a}),{description:oe.warning||t("settings.mcp.page.toast.refreshListIfStale")}):D.success(oe.message||t("settings.mcp.page.toast.serverDeleted",{name:a})),xe(!1)):D.error(t("settings.mcp.page.toast.deleteFailed")),Me(!1)},me=async()=>{if(a){ge(!0);try{if(p[a]?.status==="connected")await N(a,c),D.success(t("settings.mcp.page.toast.disconnected"));else{await P(a,c),await b({directory:c,silent:!0});const ct=Rs.getState().getStatusForDirectory(c)[a];ct?.status==="connected"?D.success(t("settings.mcp.page.toast.connected")):ct?.status==="needs_auth"?D.message(t("settings.mcp.page.toast.connectionNeedsAuthorization")):ct?.status==="needs_client_registration"?D.message(t("settings.mcp.page.toast.connectionNeedsClientRegistration")):ct?.status==="failed"?D.error(ct.error||t("settings.mcp.page.toast.connectionFailed")):D.message(t("settings.mcp.page.toast.connectionAttemptFinished"));return}await b({directory:c,silent:!0})}catch(oe){D.error(oe instanceof Error?oe.message:t("settings.mcp.page.toast.connectionFailed"))}finally{ge(!1)}}},Te=o.useCallback(()=>m?(D.error(t("settings.mcp.page.toast.createServerBeforeLiveActions")),!1):dt?(D.error(t("settings.mcp.page.toast.saveBeforeLiveActions")),!1):!0,[dt,m,t]),Ie=o.useCallback(async(oe=!1)=>{try{await b({directory:c,silent:oe})}catch(ct){oe||D.error(ct instanceof Error?ct.message:t("settings.mcp.page.toast.refreshStatusFailed"))}},[c,b,t]);o.useEffect(()=>{Ie(!0)},[Ie]),o.useEffect(()=>{bt.current=gt,ge(!1),Ze(!1),yt()},[yt,gt]);const lt=o.useCallback(async()=>{if(!a||j!=="remote"||!Te())return;Ve(!0);const oe=gt;let ct=null;try{const Ce=Rs.getState().getStatusForDirectory(c)[a]?.status;pe.current=Ce==="needs_auth"||Ce==="needs_client_registration";const{authorizationUrl:it,opened:jt,nativeFlow:At,completion:Tt}=await oc({name:a,directory:c});if(At){if(bt.current!==oe)return;Pe(null),ve(null),ue(!0),Ne.current=0,D.message(t("settings.mcp.page.toast.completeAuthorizationInBrowser")),Tt?.then(()=>{bt.current===oe&&(ue(!1),Ne.current=0,pe.current=!1,D.success(t("settings.mcp.page.toast.authorizationCompleted")))}).catch(ls=>{bt.current===oe&&(ue(!1),Ne.current=0,pe.current=!1,D.error(qa(ls,t("settings.mcp.page.toast.authorizationFailed"),e)))});return}const Xt=ll(new URL(it).searchParams);if(ct=Xt,bt.current!==oe||(Pe(it),ve(Xt??null),ue(!0),Ne.current=0,bt.current!==oe))return;jt?D.message(t(v?"settings.mcp.page.toast.completeAuthorizationInBrowserWithPaste":"settings.mcp.page.toast.completeAuthorizationInBrowser")):D.error(t("settings.mcp.page.toast.openAuthorizationUrlFailed"))}catch(Ce){await wa(ct),bt.current===oe&&D.error(qa(Ce,t("settings.mcp.page.toast.authorizationStartFailed"),e))}finally{bt.current===oe&&Ve(!1)}},[c,v,j,Te,gt,a,t,e]),at=o.useCallback(async()=>{if(!a||!Te())return;Le(!0);const oe=gt;try{if(await g(a,c),bt.current!==oe)return;Pe(null),ve(null),$(""),ue(!1),Ne.current=0,await wa(Ue),D.success(t("settings.mcp.page.toast.savedAuthorizationRemoved"))}catch(ct){bt.current===oe&&D.error(qa(ct,t("settings.mcp.page.toast.clearAuthorizationFailed"),e))}finally{bt.current===oe&&Le(!1)}},[Ue,g,c,Te,gt,a,t,e]),Je=o.useCallback(async()=>{if(!Ke)return;if((await Ta(Ke)).ok){D.success(t("settings.mcp.page.toast.authorizationUrlCopied"));return}D.error(t("settings.mcp.page.toast.authorizationUrlCopyFailed"))},[Ke,t]),Ct=o.useCallback(async()=>{const oe=Up(We);if(!oe.code){D.error(t("settings.mcp.page.toast.pasteCallbackOrCodeFirst"));return}const ct=oe.stateKey?await Hp(oe.stateKey):null,Ce=oe.context??ct,it=Ce?.name??a,jt=Ce?.directory??c;if(!it){D.error(t("settings.mcp.page.toast.missingServerDetails"));return}if(!Ce&&!Te())return;Oe(!0);const At=gt;try{if(await k(it,oe.code,jt),await wa(oe.stateKey??Ue),bt.current!==At)return;$(""),Pe(null),ve(null),ue(!1),Ne.current=0,D.success(it===a?t("settings.mcp.page.toast.authorizationCompleted"):t("settings.mcp.page.toast.authorizationCompletedFor",{name:it}))}catch(Tt){bt.current===At&&D.error(qa(Tt,t("settings.mcp.page.toast.authorizationCompleteFailed"),e))}finally{bt.current===At&&Oe(!1)}},[We,Ue,k,c,Te,gt,a,t,e]),rs=o.useCallback(async()=>{if(!(!a||!Te())){if(!ie){D.error(t("settings.mcp.page.toast.enableServerBeforeTest"));return}Ze(!0);try{const oe=await E(a,c),ct=oe.status?.status;oe.warning?D.warning(oe.warning):ct==="connected"?D.success(t("settings.mcp.page.toast.connectionTestSucceeded")):ct==="needs_auth"?D.message(t("settings.mcp.page.toast.connectionNeedsAuthorization")):ct==="needs_client_registration"?D.message(t("settings.mcp.page.toast.connectionNeedsClientRegistration")):ct==="failed"?D.error(oe.status?.error||oe.error||t("settings.mcp.page.toast.connectionTestFailed")):oe.error?D.error(oe.error):D.message(t("settings.mcp.page.toast.connectionTestFinished"))}catch(oe){D.error(oe instanceof Error?oe.message:t("settings.mcp.page.toast.connectionTestFailed"))}finally{Ze(!1)}}},[c,ie,Te,a,t,E]);if(o.useEffect(()=>{if(!de||!a)return;const oe=window.setInterval(()=>{(async()=>{Ne.current+=1,await b({directory:c,silent:!0});const ct=Rs.getState().getStatusForDirectory(c)[a];if(ct){if(pe.current&&ct.status!=="needs_auth"&&ct.status!=="needs_client_registration"){ue(!1),Ne.current=0,pe.current=!1,Pe(null),$(""),ct.status==="connected"&&D.success(t("settings.mcp.page.toast.authorizationCompleted"));return}if(!pe.current&&ct.status==="failed"){ue(!1),Ne.current=0,pe.current=!1,D.error(ct.error||t("settings.mcp.page.toast.authorizationFailed"));return}Ne.current>=30&&(ue(!1),Ne.current=0,pe.current=!1,D.message(t("settings.mcp.page.toast.authorizationStillInProgress")))}})()},2e3);return()=>{window.clearInterval(oe)}},[c,de,b,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(L,{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 Yt=p[a],ys=a?A[a]:void 0,$t=Yt??ys,cs=!m&&!$t&&O.some(oe=>oe.scope==="mcp"&&oe.id.startsWith(`mcp:${a}:`)),Kt=Yt?.status==="connected",ds=Yt?.status==="needs_auth"||Yt?.status==="needs_client_registration",as=v||!a?null:lc(a),ns=async()=>{if(as)try{await navigator.clipboard.writeText(as),D.success(t("settings.mcp.page.toast.copiedCallbackUrl"))}catch{D.error(t("settings.mcp.page.toast.clipboardWriteFailed"))}},Zt=$p($t?.status,e,$t&&"error"in $t?$t.error:void 0),os=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(gs,{title:m?t("settings.mcp.page.header.newServer"):a,titleAccessory:m?void 0:s.jsx(Oi,{status:cs?"awaiting_restart":$t?.status,enabled:ie,getStatusLabel:os,variant:"pill"}),description:m?t("settings.mcp.page.header.configureNewServer"):t("settings.mcp.page.header.transport",{type:t(j==="local"?"settings.mcp.page.transport.local":"settings.mcp.page.transport.remote")}),headerEnd:!m&&!cs?s.jsxs("div",{className:"flex flex-wrap items-center gap-2",children:[s.jsx(B,{variant:Kt?"outline":"default",size:"xs",className:"!font-normal",onClick:me,disabled:he||!ie,children:t(he?"settings.mcp.page.actions.working":Kt?"settings.mcp.page.actions.disconnect":"settings.mcp.page.actions.connect")}),j==="remote"&&s.jsxs(s.Fragment,{children:[s.jsx(B,{variant:ds?"default":"outline",size:"xs",className:"!font-normal",onClick:()=>{lt()},disabled:Ae||!ie,children:t(Ae?"settings.mcp.page.actions.starting":Kt?"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:()=>{at()},disabled:_e||!ie,children:t(_e?"settings.mcp.page.actions.clearing":"settings.mcp.page.actions.clearAuth")})]}),Kt&&s.jsx(B,{variant:"ghost",size:"xs",className:"!font-normal gap-1 text-muted-foreground",onClick:()=>{rs()},disabled:Re||!ie,children:t(Re?"settings.mcp.page.actions.testing":"settings.mcp.page.actions.test")})]}):void 0,showSaveStatus:!1,children:[cs&&s.jsx(Be,{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:Rt,children:t("settings.mcp.page.status.runtimeStatus")}),s.jsx(Oi,{status:"awaiting_restart",enabled:ie,getStatusLabel:os})]}),s.jsx("p",{className:"typography-meta text-muted-foreground",children:t("settings.mcp.page.status.description.awaitingRestart")})]})})}),!m&&!cs&&Bp($t?.status,Ke,ds,de)&&s.jsx(Be,{divider:!1,children:s.jsxs("div",{className:je("rounded-lg border p-3",Vp($t?.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:Rt,children:t("settings.mcp.page.status.runtimeStatus")}),s.jsx(Oi,{status:$t?.status,enabled:ie,getStatusLabel:os})]}),s.jsx("p",{className:"typography-meta text-muted-foreground",children:Zt}),s.jsx("p",{className:"typography-micro text-muted-foreground/80",children:C==="project"?t("settings.mcp.page.status.projectScopedTo",{directory:c??t("settings.mcp.page.status.activeProject")}):t("settings.mcp.page.status.userScoped")})]}),s.jsx("div",{className:"flex flex-wrap items-center gap-2",children:!Kt&&s.jsx(B,{variant:"outline",size:"xs",className:"!font-normal",onClick:()=>{rs()},disabled:Re||!ie,children:t(Re?"settings.mcp.page.actions.testing":"settings.mcp.page.actions.testConnection")})}),$t?.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(en,{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")})]}),as&&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:as}),s.jsxs(B,{variant:"outline",size:"xs",className:"!font-normal",onClick:()=>{ns()},children:[s.jsx(L,{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(es,{label:t("settings.mcp.page.registration.clientId"),children:s.jsx(Ye,{value:V,onChange:oe=>{z(oe.target.value),_(!0)},className:"font-mono typography-meta","data-bwignore":"true","data-1p-ignore":"true"})}),s.jsx(es,{label:t("settings.mcp.page.registration.clientSecret"),children:s.jsx(Ye,{type:"password",value:U,onChange:oe=>{X(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")})]}),Ke&&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:Ke}),s.jsxs("div",{className:"flex flex-wrap items-center gap-2",children:[s.jsxs(B,{variant:"outline",size:"xs",className:"!font-normal",onClick:()=>{An(Ke)},children:[s.jsx(L,{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:()=>{Je()},children:[s.jsx(L,{name:"clipboard",className:"h-3.5 w-3.5"}),t("settings.mcp.page.actions.copyLink")]})]})]})}),v&&j==="remote"&&(ds||de||Ke)&&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(en,{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(Es,{value:We,onChange:oe=>$(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:()=>{Ct()},disabled:Ge,children:t(Ge?"settings.mcp.page.actions.completing":"settings.mcp.page.actions.completeAuthorization")})})]})})]}),de&&s.jsx("p",{className:"mt-4 typography-micro text-muted-foreground",children:t("settings.mcp.page.auth.waitingForOpenCode")})]})}),s.jsxs(Be,{title:t("settings.mcp.page.server.title"),divider:!1,settingsItem:"mcp.server",contentClassName:"space-y-0",titleAccessory:m?s.jsxs(B,{variant:"ghost",size:"xs",className:"!font-normal gap-1.5 text-muted-foreground",onClick:It,type:"button",title:t("settings.mcp.page.server.importJsonTitle"),children:[s.jsx(L,{name:"file-code",className:"h-3.5 w-3.5"}),t("settings.mcp.page.server.importJson")]}):null,children:[m&&s.jsxs(Qt,{label:t("settings.mcp.page.server.name"),controlClassName:"flex-wrap @xl:w-auto @xl:flex-1",children:[s.jsx(Ye,{value:y,onChange:oe=>K(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(Ot,{value:C,onValueChange:oe=>T(oe),children:[s.jsxs(Lt,{size:Jt,className:"!h-7 min-w-0 max-w-full gap-1.5 px-2",children:[s.jsx(L,{name:C==="user"?"user-3":"folder",className:"h-3.5 w-3.5 shrink-0"}),s.jsx("span",{className:"truncate",children:t(C==="user"?"settings.mcp.page.scope.everywhere":"settings.mcp.page.scope.thisProject")})]}),s.jsxs(Ft,{align:"end",children:[s.jsx(ut,{value:"user",children:s.jsxs("div",{className:"flex items-center gap-2",children:[s.jsx(L,{name:"user-3",className:"h-3.5 w-3.5"}),s.jsx("span",{children:t("settings.mcp.page.scope.everywhere")})]})}),s.jsx(ut,{value:"project",children:s.jsxs("div",{className:"flex items-center gap-2",children:[s.jsx(L,{name:"folder",className:"h-3.5 w-3.5"}),s.jsx("span",{children:t("settings.mcp.page.scope.thisProject")})]})})]})]})]}),s.jsx(ht,{checked:ie,onChange:te,label:t("settings.mcp.page.server.enable"),ariaLabel:t("settings.mcp.page.server.enableAria")})]}),s.jsxs(Be,{title:t("settings.mcp.page.connection.title"),description:t("settings.mcp.page.connection.description"),settingsItem:"mcp.command",contentClassName:"space-y-2",children:[s.jsx(hr,{items:Ee,activeId:j,onSelect:oe=>R(oe),layoutMode:"fit",variant:"active-pill",activePillLowercase:!1,className:"h-10"}),j==="local"?s.jsx(zp,{value:G,onChange:S,preview:oe=>t("settings.mcp.page.connection.previewArgs",{count:oe}),onDetectUrl:vt}):s.jsx(Ye,{value:q,onChange:oe=>Se(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(j==="local"?"settings.mcp.page.connection.hintCommand":"settings.mcp.page.connection.hintLink")})]}),j==="remote"&&s.jsx(Be,{title:t("settings.mcp.page.advanced.title"),settingsItem:"mcp.advanced",children:s.jsxs(qn,{open:Fe,onOpenChange:H,children:[s.jsxs(Wn,{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:["(",Y.length," ",t("settings.mcp.page.advanced.headers"),fe?` · ${fe}ms`:"",")"]})]}),Fe?s.jsx(L,{name:"arrow-down-s",className:"h-4 w-4 text-muted-foreground group-hover:text-foreground transition-colors"}):s.jsx(L,{name:"arrow-right-s",className:"h-4 w-4 text-muted-foreground group-hover:text-foreground transition-colors"})]}),s.jsx(Jn,{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:Rt,children:t("settings.mcp.page.advanced.timeoutMs")}),s.jsx(ss,{children:t("settings.mcp.page.advanced.timeoutHint")})]}),s.jsx("div",{className:"flex items-center gap-2",children:s.jsx(Ye,{type:"number",min:"1",step:"1",value:fe,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(en,{as:"div",className:"mb-2",children:[t("settings.mcp.page.advanced.requestHeaders"),Y.length>0&&s.jsxs("span",{className:"ml-1.5 typography-micro text-muted-foreground font-normal",children:["(",Y.length,")"]})]}),s.jsx(io,{value:Y,onChange:F,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(Be,{title:t("settings.mcp.page.env.title"),description:t("settings.mcp.page.env.description"),titleAccessory:M.length>0?s.jsxs("span",{className:"typography-micro text-muted-foreground font-normal",children:["(",M.length,")"]}):null,settingsItem:"mcp.environment",children:M.length===0?s.jsxs(B,{variant:"outline",size:"xs",className:"!font-normal gap-1.5",onClick:()=>W([{key:"",value:""}]),children:[s.jsx(L,{name:"add",className:"h-3.5 w-3.5"}),t("settings.mcp.page.env.addEnvironmentVariable")]}):s.jsx(io,{value:M,onChange:W,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:kt,disabled:ye||!dt&&!m,size:"xs",className:"!font-normal",children:t(ye?"settings.common.actions.saving":m?"settings.common.actions.create":"settings.common.actions.saveChanges")}),!m&&s.jsx(B,{variant:"destructive",size:"xs",className:"!font-normal",onClick:()=>xe(!0),children:t("settings.common.actions.delete")})]})," "]}),s.jsx(zt,{open:He,onOpenChange:oe=>{oe||(et(!1),st(""),xt(null))},children:s.jsxs(_t,{className:"max-w-md",children:[s.jsxs(Gt,{children:[s.jsx(qt,{children:t("settings.mcp.page.importDialog.title")}),s.jsx(Wt,{children:t("settings.mcp.page.importDialog.description")})]}),s.jsxs("div",{className:"space-y-3",children:[s.jsx(Es,{value:ze,onChange:oe=>{st(oe.target.value),xt(null)},placeholder:`{
|
|
15
|
-
"mcpServers": {
|
|
16
|
-
"postgres": {
|
|
17
|
-
"command": "npx",
|
|
18
|
-
"args": ["-y", "@modelcontextprotocol/server-postgres"]
|
|
19
|
-
}
|
|
20
|
-
}
|
|
21
|
-
}`,rows:8,className:"font-mono typography-meta",spellCheck:!1,"data-bwignore":"true","data-1p-ignore":"true"}),wt&&s.jsx("p",{className:"typography-micro text-[var(--status-error)]",children:wt}),s.jsx("div",{className:"flex flex-wrap items-center gap-2",children:s.jsxs(B,{variant:"outline",size:"xs",className:"!font-normal gap-1",onClick:qe,type:"button",children:[s.jsx(L,{name:"clipboard",className:"h-3.5 w-3.5"}),t("settings.mcp.page.importDialog.pasteFromClipboard")]})})]}),s.jsxs(ms,{children:[s.jsx(B,{variant:"outline",onClick:()=>{et(!1),st(""),xt(null)},className:"text-foreground",children:t("settings.common.actions.cancel")}),s.jsx(B,{onClick:Qe,disabled:!ze.trim(),size:"sm",children:t("settings.common.actions.import")})]})]})}),s.jsx(zt,{open:ke,onOpenChange:oe=>{!oe&&!De&&xe(!1)},children:s.jsxs(_t,{className:"max-w-md",children:[s.jsxs(Gt,{children:[s.jsx(qt,{children:t("settings.mcp.page.deleteDialog.title",{name:a??""})}),s.jsxs(Wt,{children:[t("settings.mcp.page.deleteDialog.descriptionPrefix")," ",s.jsx("code",{className:"text-foreground",children:"opencode.json"}),"."," ",t("settings.mcp.page.deleteDialog.descriptionSuffix")]})]}),s.jsxs(ms,{children:[s.jsx(B,{variant:"outline",onClick:()=>xe(!1),disabled:De,className:"text-foreground",children:t("settings.common.actions.cancel")}),s.jsx(B,{variant:"destructive",size:"sm",onClick:J,disabled:De,children:t(De?"settings.mcp.page.actions.deleting":"settings.common.actions.delete")})]})]})})]})};function Wp(t){return t.trim().length>0}function Jp(t){return t.trimEnd()}function Qp(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 ei=()=>{try{const e=Qs.getState().getActiveProject?.();if(e?.path?.trim())return e.path.trim();const a=cn.getDirectory();if(a?.trim())return a.trim()}catch(t){console.warn("[PluginsStore] Error resolving config directory:",t)}return null},Yp=800,Zp=5e3,Xp="__default__",tr=new Map,Li=new Map,em=1500,El=t=>t?.trim()||Xp,tm=t=>{tr.delete(El(t))},fs=kl()(Md(Rd((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=ei(),i=El(n),r=Date.now(),l=tr.get(i)??0,h=e().entries.length>0||e().files.length>0;if(!a?.force&&h&&r-l<Zp)return!0;const d=Li.get(i);if(!a?.force&&d)return d;const x=(async()=>{t({isLoading:!0});try{const c=await pt(yn("/api/config/plugins",n),{headers:ka(n)});if(!c.ok)throw new Error("Failed to load plugins");const v=await ti(c);return t({entries:v.entries??[],files:v.files??[],isLoading:!1}),tr.set(i,Date.now()),a?.force||e().loadRegistryInfo(),!0}catch(c){return console.error("[PluginsStore] Failed to load plugins:",c),t({isLoading:!1}),!1}})();Li.set(i,x);try{return await x}finally{Li.delete(i)}},loadRegistryInfo:async a=>{const n=nm(a?.specs??e().entries.map(i=>i.spec));if(n.length===0)return t({isLoadingRegistry:!1}),!0;t({isLoadingRegistry:!0});try{const i=ei(),r={...e().registryInfo};for(const l of am(n)){const h=await pt(sm(l,a?.force===!0,i),{headers:ka(i)});if(!h.ok)throw new Error("Failed to load plugin registry info");const d=await ti(h);for(const x of d.results??[])r[x.spec]=x}return t({registryInfo:r,isLoadingRegistry:!1}),!0}catch(i){return console.error("[PluginsStore] Failed to load plugin registry info:",i),t({isLoadingRegistry:!1}),!1}},updateToLatest:async a=>{const n=e().entries.find(r=>r.id===a);if(!n)return{ok:!1};const i=e().registryInfo[n.spec];return!i||i.kind!=="npm-ok"||!i.hasUpdate||!i.latestVersion?{ok:!1}:await e().updateEntry(a,{spec:`${i.name}@${i.latestVersion}`})},createEntry:async a=>{const n=await na("Creating plugin entry…",async i=>await pt(yn("/api/config/plugins/entry",i),{method:"POST",headers:Wa(i),body:JSON.stringify(ro(a))}),e,{restartId:a.spec});return n.ok&&e().loadRegistryInfo({specs:[a.spec],force:!0}),n},updateEntry:async(a,n)=>{const i=e().entries.find(h=>h.id===a)?.spec,r=n.spec??i,l=await na("Updating plugin entry…",async h=>await pt(yn(`/api/config/plugins/entry/${encodeURIComponent(a)}`,h),{method:"PATCH",headers:Wa(h),body:JSON.stringify(ro(n))}),e,{restartId:a});return l.ok&&r&&e().loadRegistryInfo({specs:[r],force:!0}),l},deleteEntry:async a=>{const n=e().entries.find(r=>r.id===a),i=await na("Deleting plugin entry…",async r=>await pt(yn(`/api/config/plugins/entry/${encodeURIComponent(a)}`,r),{method:"DELETE",headers:ka(r)}),e,{restartId:a});if(i.ok&&e().selectedId===a&&t({selectedId:null}),i.ok&&n){const r={...e().registryInfo};delete r[n.spec],t({registryInfo:r})}return i},readFile:async a=>{try{const n=ei(),i=await pt(yn(`/api/config/plugins/file/${encodeURIComponent(a)}`,n),{headers:ka(n)});if(!i.ok)throw new Error("Failed to read plugin file");return await ti(i)}catch(n){return console.error("[PluginsStore] Failed to read plugin file:",n),null}},createFile:async a=>na("Creating plugin file…",async n=>await pt(yn("/api/config/plugins/file",n),{method:"POST",headers:Wa(n),body:JSON.stringify(a)}),e,{restartId:a.fileName}),updateFile:async(a,n)=>na("Updating plugin file…",async i=>await pt(yn(`/api/config/plugins/file/${encodeURIComponent(a)}`,i),{method:"PUT",headers:Wa(i),body:JSON.stringify(n)}),e,{restartId:a}),deleteFile:async a=>{const n=await na("Deleting plugin file…",async i=>await pt(yn(`/api/config/plugins/file/${encodeURIComponent(a)}`,i),{method:"DELETE",headers:ka(i)}),e,{restartId:a});return n.ok&&e().selectedId===a&&t({selectedId:null}),n},getById:a=>e().entries.find(n=>n.id===a)??e().files.find(n=>n.id===a)}),{name:"plugins-store",storage:sd(),partialize:t=>({selectedId:t.selectedId})}),{name:"plugins-store"}));function yn(t,e){const a=e?`?directory=${encodeURIComponent(e)}`:"";return`${t}${a}`}function sm(t,e,a){const n=new URLSearchParams;e&&n.set("refresh","true"),a&&n.set("directory",a);const i=n.toString();return`/api/config/plugins/registry?${`specs=${t.map(encodeURIComponent).join(",")}`}${i?`&${i}`:""}`}function nm(t){return Array.from(new Set(t.map(e=>e.trim()).filter(Boolean)))}function am(t){const e=[];let a=[],n=0;for(const i of t){const r=encodeURIComponent(i),l=a.length===0?r.length:n+1+r.length;a.length>0&&l>em?(e.push(a),a=[i],n=r.length):(a.push(i),n=l)}return a.length>0&&e.push(a),e}function ka(t){return t?{"x-opencode-directory":t}:void 0}function Wa(t){return{"Content-Type":"application/json",...t?{"x-opencode-directory":t}:{}}}function ro(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 na(t,e,a,n){try{const i=ei(),r=await e(i),l=await ti(r).catch(()=>null);if(!r.ok)throw new Error(l?.error||"Failed to update plugin configuration");return tm(i),l?.requiresManualRestart?(await a().loadPlugins({force:!0}),{ok:!0,requiresManualRestart:!0,reloadFailed:l?.reloadFailed===!0,message:l?.message,warning:l?.warning}):ii(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&&(dc(t),await pc({message:l.message,delayMs:l.reloadDelayMs??Yp,scopes:["all"]})),await a().loadPlugins({force:!0}),{ok:!0,reloadFailed:l?.reloadFailed===!0,message:l?.message,warning:l?.warning})}catch(i){return console.error("[PluginsStore] Failed to update plugin configuration:",i),{ok:!1}}}async function ti(t){return await t.json()}const im=/^[a-z0-9][a-z0-9-_.]*\.(js|ts|mjs|cjs)$/;function rm(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 om=({open:t,onOpenChange:e,defaultScope:a="user"})=>{const{t:n}=ot(),i=fs(S=>S.createEntry),r=fs(S=>S.createFile),[l,h]=o.useState("npm"),[d,x]=o.useState(""),[c,v]=o.useState(""),[p,A]=o.useState(""),[b,P]=o.useState(""),[N,k]=o.useState(a),[g,E]=o.useState(!1),O=o.useCallback(()=>{x(""),v(""),A(""),P(""),k(a)},[a]);o.useEffect(()=>{t&&(h("npm"),O())},[t,O]);const I=S=>{S!==l&&(h(S),O())},w=o.useMemo(()=>rm(c),[c]),m=!w.ok,y=l==="file"&&p.trim()!==""&&!im.test(p.trim()),K=(l==="npm"||l==="path")&&d.trim()==="",C=l==="file"&&b.trim()==="",T=l==="file"&&p.trim()==="",j=g||m||l==="npm"&&K||l==="path"&&K||l==="file"&&(T||y||C),R=async()=>{if(!j){E(!0);try{let S;l==="file"?S=await r({fileName:p.trim(),content:b,scope:N}):S=await i({spec:d.trim(),options:w.ok?w.value:void 0,scope:N}),S.ok?(S.restartDeferred?D.success(n("settings.view.pendingRestart.saved")):D.success(S.message||n("settings.plugins.toast.created")),S.reloadFailed&&D.warning(n("settings.plugins.toast.reloadFailed")),e(!1)):D.error(S.message||n("settings.plugins.sidebar.toast.deleteFailed"))}finally{E(!1)}}},G=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(zt,{open:t,onOpenChange:S=>{!S&&g||e(S)},children:s.jsxs(_t,{className:"max-w-xl",children:[s.jsxs(Gt,{children:[s.jsx(qt,{children:n("settings.plugins.dialog.add.title")}),s.jsx(Wt,{children:n("settings.plugins.sidebar.empty.description")})]}),s.jsx(hr,{items:G,activeId:l,onSelect:S=>I(S),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(Ye,{id:"plugin-spec",value:d,onChange:S=>x(S.target.value),placeholder:n("settings.plugins.page.field.spec.placeholder"),"aria-invalid":K?!1:void 0,disabled:g}),K&&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(Es,{id:"plugin-options",value:c,onChange:S=>v(S.target.value),rows:5,className:"font-mono",hasError:m,disabled:g}),m&&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(Ye,{id:"plugin-filename",value:p,onChange:S=>A(S.target.value),placeholder:"my-plugin.ts","aria-invalid":y||void 0,disabled:g}),y&&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(Es,{id:"plugin-content",value:b,onChange:S=>P(S.target.value),rows:16,className:"font-mono",disabled:g})]})]}),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(S=>{const q=N===S,Q=n(S==="user"?"settings.plugins.scope.user":"settings.plugins.scope.project");return s.jsxs("button",{type:"button",onClick:()=>k(S),disabled:g,className:"flex items-center gap-2 py-1 text-left disabled:opacity-50",children:[s.jsx(dr,{checked:q,onChange:()=>k(S),ariaLabel:Q}),s.jsx("span",{className:je("typography-ui-label font-normal",q?"text-foreground":"text-foreground/60"),children:Q})]},S)})})]})]}),s.jsxs(ms,{children:[s.jsx(B,{size:"sm",variant:"ghost",onClick:()=>e(!1),disabled:g,children:n("settings.plugins.dialog.add.action.cancel")}),s.jsxs(B,{size:"sm",onClick:()=>{R()},disabled:j,children:[g?s.jsx(L,{name:"loader-4",className:"h-3.5 w-3.5 animate-spin"}):null,n("settings.plugins.dialog.add.action.submit")]})]})]})})},lm=t=>{const e=mt.c(33),{spec:a}=t;let n;e[0]!==a?(n=h=>h.registryInfo[a],e[0]=a,e[1]=n):n=e[1];const i=fs(n),{t:r}=ot();if(!i)return null;const l=cm;switch(i.kind){case"npm-ok":{if(!i.hasUpdate||!i.latestVersion)return null;let h;e[2]===Symbol.for("react.memo_cache_sentinel")?(h=s.jsx(L,{name:"arrow-up-s",className:"h-3 w-3"}),e[2]=h):h=e[2];let d;e[3]!==i.latestVersion?(d=s.jsxs("span",{className:"inline-flex items-center gap-0.5 text-[var(--status-success)]",children:[h,i.latestVersion]}),e[3]=i.latestVersion,e[4]=d):d=e[4];let x;return e[5]!==i.currentVersion||e[6]!==i.latestVersion||e[7]!==r||e[8]!==d?(x=l(d,r("settings.plugins.registry.badge.update.tooltip",{current:i.currentVersion??"",latest:i.latestVersion})),e[5]=i.currentVersion,e[6]=i.latestVersion,e[7]=r,e[8]=d,e[9]=x):x=e[9],x}case"npm-missing-version":{let h;e[10]===Symbol.for("react.memo_cache_sentinel")?(h=s.jsx(L,{name:"error-warning",className:"h-3 w-3 text-[var(--status-warning)]"}),e[10]=h):h=e[10];let d;return e[11]!==i.currentVersion||e[12]!==i.name||e[13]!==r?(d=l(h,r("settings.plugins.registry.badge.missingVersion.tooltip",{version:i.currentVersion,name:i.name})),e[11]=i.currentVersion,e[12]=i.name,e[13]=r,e[14]=d):d=e[14],d}case"npm-missing-package":{let h;e[15]===Symbol.for("react.memo_cache_sentinel")?(h=s.jsx(L,{name:"error-warning",className:"h-3 w-3 text-[var(--status-error)]"}),e[15]=h):h=e[15];let d;return e[16]!==i.name||e[17]!==r?(d=l(h,r("settings.plugins.registry.badge.missingPackage.tooltip",{name:i.name})),e[16]=i.name,e[17]=r,e[18]=d):d=e[18],d}case"npm-malformed":{let h;e[19]===Symbol.for("react.memo_cache_sentinel")?(h=s.jsx(L,{name:"error-warning",className:"h-3 w-3 text-[var(--status-error)]"}),e[19]=h):h=e[19];let d;return e[20]!==r?(d=l(h,r("settings.plugins.registry.badge.malformed.tooltip")),e[20]=r,e[21]=d):d=e[21],d}case"npm-network":{let h;e[22]===Symbol.for("react.memo_cache_sentinel")?(h=s.jsx(L,{name:"cloud-off",className:"h-3 w-3 text-muted-foreground"}),e[22]=h):h=e[22];let d;return e[23]!==r?(d=l(h,r("settings.plugins.registry.badge.network.tooltip")),e[23]=r,e[24]=d):d=e[24],d}case"path-missing":{let h;e[25]===Symbol.for("react.memo_cache_sentinel")?(h=s.jsx(L,{name:"error-warning",className:"h-3 w-3 text-[var(--status-error)]"}),e[25]=h):h=e[25];let d;return e[26]!==i.absolutePath||e[27]!==r?(d=l(h,r("settings.plugins.registry.badge.pathMissing.tooltip",{path:i.absolutePath})),e[26]=i.absolutePath,e[27]=r,e[28]=d):d=e[28],d}case"path-unreadable":{let h;e[29]===Symbol.for("react.memo_cache_sentinel")?(h=s.jsx(L,{name:"error-warning",className:"h-3 w-3 text-[var(--status-warning)]"}),e[29]=h):h=e[29];let d;return e[30]!==i.absolutePath||e[31]!==r?(d=l(h,r("settings.plugins.registry.badge.pathUnreadable.tooltip",{path:i.absolutePath})),e[30]=i.absolutePath,e[31]=r,e[32]=d):d=e[32],d}case"path-ok":return null;default:return null}};function cm(t,e){return s.jsxs(pr,{children:[s.jsx(mr,{asChild:!0,children:s.jsx("span",{className:"inline-flex shrink-0 items-center gap-0.5 text-xs",children:t})}),s.jsx(cl,{children:e})]})}const Tl=t=>{const e=mt.c(26),{header:a,footer:n,children:i,className:r,variant:l}=t,h=l===void 0?"sidebar":l,d=vs(),x=o.useRef(null),[c,v]=o.useState(!1),[p,A]=o.useState(!1),b=h==="background"||d?"bg-background":"bg-sidebar",P=b==="bg-background"?"var(--surface-background)":"var(--surface-muted)";let N;e[0]===Symbol.for("react.memo_cache_sentinel")?(N=()=>{const j=x.current;if(!j){v(!1),A(!1);return}if(!(j.scrollHeight>j.clientHeight+1)){v(!1),A(!1);return}v(j.scrollTop>1),A(j.scrollTop+j.clientHeight<j.scrollHeight-1)},e[0]=N):N=e[0];const k=N;let g;e[1]===Symbol.for("react.memo_cache_sentinel")?(g=()=>{k()},e[1]=g):g=e[1];let E;e[2]!==i?(E=[i,k],e[2]=i,e[3]=E):E=e[3],o.useEffect(g,E);let O,I;e[4]===Symbol.for("react.memo_cache_sentinel")?(O=()=>{const j=x.current;if(!j)return;const R=()=>k();return j.addEventListener("scroll",R,{passive:!0}),()=>j.removeEventListener("scroll",R)},I=[k],e[4]=O,e[5]=I):(O=e[4],I=e[5]),o.useEffect(O,I);let w;e[6]!==b||e[7]!==r?(w=je("flex h-full flex-col",b,r),e[6]=b,e[7]=r,e[8]=w):w=e[8];let m;e[9]!==i?(m=s.jsx(Vs,{ref:x,outerClassName:"flex-1 min-h-0",className:"space-y-0.5 px-3 py-2 overflow-x-hidden",children:i}),e[9]=i,e[10]=m):m=e[10];let y;e[11]!==P||e[12]!==c?(y=c&&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]=c,e[13]=y):y=e[13];let K;e[14]!==P||e[15]!==p?(K=p&&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]=p,e[16]=K):K=e[16];let C;e[17]!==K||e[18]!==m||e[19]!==y?(C=s.jsxs("div",{className:"relative flex flex-1 min-h-0 flex-col",children:[m,y,K]}),e[17]=K,e[18]=m,e[19]=y,e[20]=C):C=e[20];let T;return e[21]!==n||e[22]!==a||e[23]!==C||e[24]!==w?(T=s.jsxs("div",{className:w,children:[a,C,n]}),e[21]=n,e[22]=a,e[23]=C,e[24]=w,e[25]=T):T=e[25],T},sr=t=>{const e=mt.c(23),{title:a,metadata:n,selected:i,onSelect:r,icon:l,actions:h,className:d}=t,x=i===void 0?!1:i,c=h&&h.length>0,v=x?"bg-interactive-selection":"hover:bg-interactive-hover";let p;e[0]!==d||e[1]!==v?(p=je("group relative flex items-center rounded-md px-1.5 py-0.5 transition-all duration-200",v,d),e[0]=d,e[1]=v,e[2]=p):p=e[2];let A;e[3]!==a?(A=s.jsx("span",{className:"typography-ui-label font-normal truncate text-foreground",children:a}),e[3]=a,e[4]=A):A=e[4];let b;e[5]!==l||e[6]!==A?(b=s.jsxs("div",{className:"flex items-center gap-1.5",children:[l,A]}),e[5]=l,e[6]=A,e[7]=b):b=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 N;e[10]!==r||e[11]!==b||e[12]!==P?(N=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:[b,P]}),e[10]=r,e[11]=b,e[12]=P,e[13]=N):N=e[13];let k;e[14]!==h||e[15]!==c?(k=c&&s.jsxs(nn,{children:[s.jsx(tn,{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(L,{name:"more-2",className:"h-3.5 w-3.5"})})}),s.jsx(sn,{align:"end",className:"w-fit min-w-20",children:h.map(dm)})]}),e[14]=h,e[15]=c,e[16]=k):k=e[16];let g;e[17]!==N||e[18]!==k?(g=s.jsxs("div",{className:"flex min-w-0 flex-1 items-center",children:[N,k]}),e[17]=N,e[18]=k,e[19]=g):g=e[19];let E;return e[20]!==p||e[21]!==g?(E=s.jsx("div",{className:p,children:g}),e[20]=p,e[21]=g,e[22]=E):E=e[22],E};function dm(t){const e=t.icon;return s.jsxs(an,{onClick:a=>{a.stopPropagation(),t.onClick()},className:je(t.destructive&&"text-destructive focus:text-destructive"),children:[e&&s.jsx(L,{name:e,className:"h-4 w-4 mr-px"}),t.label]},t.label)}const pm=t=>t.parsedKind==="npm"?"code-box":"folder",mm=t=>{const e=mt.c(144),{onItemSelect:a,onAddClick:n}=t,{t:i}=ot(),{entries:r,files:l,selectedId:h,setSelected:d,deleteEntry:x,deleteFile:c,loadPlugins:v}=fs(Ms(um)),p=fs(gm),A=fs(hm),b=fs(fm),P=fs(xm),[N,k]=o.useState(null),[g,E]=o.useState(!1),[O,I]=o.useState(!1);let w,m;e[0]!==v?(w=()=>{v()},m=[v],e[0]=v,e[1]=w,e[2]=m):(w=e[1],m=e[2]),o.useEffect(w,m);let y,K;e[3]===Symbol.for("react.memo_cache_sentinel")?(y=()=>{const qe=()=>I(!0);return window.addEventListener("openchamber:settings-open-plugin-add",qe),()=>window.removeEventListener("openchamber:settings-open-plugin-add",qe)},K=[],e[3]=y,e[4]=K):(y=e[3],K=e[4]),o.useEffect(y,K);let C;if(e[5]!==r||e[6]!==p){C={userEntries:0,projectEntries:0};for(const qe of r){const Qe=p[qe.spec];Qe?.kind==="npm-ok"&&Qe.hasUpdate&&(qe.scope==="user"?C.userEntries=C.userEntries+1:qe.scope==="project"&&(C.projectEntries=C.projectEntries+1))}e[5]=r,e[6]=p,e[7]=C}else C=e[7];const T=C;let j;e[8]!==r?(j=r.filter(bm),e[8]=r,e[9]=j):j=e[9];const R=j;let G;e[10]!==r?(G=r.filter(vm),e[10]=r,e[11]=G):G=e[11];const S=G;let q;e[12]!==l?(q=l.filter(ym),e[12]=l,e[13]=q):q=e[13];const Q=q;let M;e[14]!==l?(M=l.filter(jm),e[14]=l,e[15]=M):M=e[15];const W=M,Y=r.length+l.length,F=Y===0;let se;e[16]!==n?(se=()=>{n?n():I(!0)},e[16]=n,e[17]=se):se=e[17];const _=se;let V;e[18]!==a||e[19]!==d?(V=qe=>{d(qe),a?.()},e[18]=a,e[19]=d,e[20]=V):V=e[20];const z=V;let U;e[21]!==r||e[22]!==p||e[23]!==i||e[24]!==P?(U=async qe=>{const Qe=r.find(Se=>Se.id===qe);if(!Qe)return;const dt=p[Qe.spec];if(!dt||dt.kind!=="npm-ok"||!dt.hasUpdate||!dt.latestVersion)return;const Ee=dt.latestVersion;(await P(qe)).ok?D.success(i("settings.plugins.toast.updatedToLatest",{version:Ee})):D.error(i("settings.plugins.toast.refreshFailed"))},e[21]=r,e[22]=p,e[23]=i,e[24]=P,e[25]=U):U=e[25];const X=U;let Z;e[26]!==b||e[27]!==i?(Z=async()=>{D.info(i("settings.plugins.toast.refreshing"));try{await b({force:!0})}catch{D.error(i("settings.plugins.toast.refreshFailed"))}},e[26]=b,e[27]=i,e[28]=Z):Z=e[28];const ne=Z;let le;e[29]!==x||e[30]!==c||e[31]!==N||e[32]!==i?(le=async()=>{if(!N)return;E(!0);const qe=N.kind==="entry"?await x(N.id):await c(N.id);qe.ok?D.success(qe.message||i("settings.plugins.sidebar.toast.deleted",{name:N.label})):D.error(i("settings.plugins.sidebar.toast.deleteFailed")),k(null),E(!1)},e[29]=x,e[30]=c,e[31]=N,e[32]=i,e[33]=le):le=e[33];const re=le;let fe;e[34]!==z||e[35]!==X||e[36]!==p||e[37]!==h||e[38]!==i?(fe=qe=>{const Qe=p[qe.spec],dt=Qe?.kind==="npm-ok"&&Qe.hasUpdate&&!!Qe.latestVersion,Ee=[];return dt&&Ee.push({label:i("settings.plugins.sidebar.actions.updateToLatest"),icon:"arrow-up-s",onClick:()=>{X(qe.id)}}),Ee.push({label:i("settings.common.actions.delete"),icon:"delete-bin",destructive:!0,onClick:()=>k({kind:"entry",id:qe.id,label:qe.spec})}),s.jsx(sr,{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:qe.spec}),s.jsx(lm,{spec:qe.spec})]}),metadata:qe.parsedKind==="npm"?i("settings.plugins.sidebar.kind.npm"):i("settings.plugins.sidebar.kind.path"),selected:h===qe.id,onSelect:()=>z(qe.id),icon:s.jsx(L,{name:pm(qe),className:"h-4 w-4 flex-shrink-0 text-muted-foreground/70"}),actions:Ee},qe.id)},e[34]=z,e[35]=X,e[36]=p,e[37]=h,e[38]=i,e[39]=fe):fe=e[39];const ae=fe;let ie;e[40]!==z||e[41]!==h||e[42]!==i?(ie=qe=>s.jsx(sr,{title:qe.fileName,metadata:i("settings.plugins.sidebar.kind.file"),selected:h===qe.id,onSelect:()=>z(qe.id),icon:s.jsx(L,{name:"file-text",className:"h-4 w-4 flex-shrink-0 text-muted-foreground/70"}),actions:[{label:i("settings.common.actions.delete"),icon:"delete-bin",destructive:!0,onClick:()=>k({kind:"file",id:qe.id,label:qe.fileName})}]},qe.id),e[40]=z,e[41]=h,e[42]=i,e[43]=ie):ie=e[43];const te=ie;let ye;e[44]!==i?(ye=(qe,Qe,dt)=>{const Ee=dt===void 0?0:dt;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:[qe,Ee>0&&s.jsx("span",{className:"ml-2 normal-case font-normal text-[var(--status-success)]",children:i(Ee===1?"settings.plugins.sidebar.group.updatesAvailable_one":"settings.plugins.sidebar.group.updatesAvailable_other",{count:Ee})})]}),Qe]})},e[44]=i,e[45]=ye):ye=e[45];const we=ye;let ke;e[46]!==i?(ke=i("settings.plugins.sidebar.title"),e[46]=i,e[47]=ke):ke=e[47];let xe;e[48]!==ke?(xe=s.jsx("div",{className:"mb-3 flex items-center justify-between gap-3",children:s.jsx("h2",{className:rn,children:ke})}),e[48]=ke,e[49]=xe):xe=e[49];let De;e[50]!==i||e[51]!==Y?(De=i("settings.plugins.sidebar.total",{count:Y}),e[50]=i,e[51]=Y,e[52]=De):De=e[52];let Me;e[53]!==De?(Me=s.jsx("span",{className:"typography-meta text-muted-foreground",children:De}),e[53]=De,e[54]=Me):Me=e[54];let he;e[55]!==ne?(he=()=>{ne()},e[55]=ne,e[56]=he):he=e[56];let ge;e[57]!==i?(ge=i("settings.plugins.sidebar.actions.refresh"),e[57]=i,e[58]=ge):ge=e[58];let Ae;e[59]!==i?(Ae=i("settings.plugins.sidebar.actions.refresh"),e[59]=i,e[60]=Ae):Ae=e[60];const Ve=A?"size-4 animate-spin":"size-4";let _e;e[61]!==Ve?(_e=s.jsx(L,{name:"refresh",className:Ve}),e[61]=Ve,e[62]=_e):_e=e[62];let Le;e[63]!==A||e[64]!==he||e[65]!==ge||e[66]!==Ae||e[67]!==_e?(Le=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:he,disabled:A,"aria-label":ge,title:Ae,children:_e}),e[63]=A,e[64]=he,e[65]=ge,e[66]=Ae,e[67]=_e,e[68]=Le):Le=e[68];let Re;e[69]!==i?(Re=i("settings.plugins.sidebar.actions.addTitle"),e[69]=i,e[70]=Re):Re=e[70];let Ze;e[71]!==i?(Ze=i("settings.plugins.sidebar.actions.addTitle"),e[71]=i,e[72]=Ze):Ze=e[72];let Ge;e[73]===Symbol.for("react.memo_cache_sentinel")?(Ge=s.jsx(L,{name:"add",className:"size-4"}),e[73]=Ge):Ge=e[73];let Oe;e[74]!==_||e[75]!==Re||e[76]!==Ze?(Oe=s.jsx(B,{type:"button",variant:"ghost",size:"icon",className:"h-7 w-7 -my-1 text-muted-foreground",onClick:_,"aria-label":Re,title:Ze,children:Ge}),e[74]=_,e[75]=Re,e[76]=Ze,e[77]=Oe):Oe=e[77];let Ke;e[78]!==Le||e[79]!==Oe?(Ke=s.jsxs("div",{className:"flex items-center gap-1",children:[Le,Oe]}),e[78]=Le,e[79]=Oe,e[80]=Ke):Ke=e[80];let Pe;e[81]!==Me||e[82]!==Ke?(Pe=s.jsxs("div",{className:"flex items-center justify-between gap-2",children:[Me,Ke]}),e[81]=Me,e[82]=Ke,e[83]=Pe):Pe=e[83];let Ue;e[84]!==xe||e[85]!==Pe?(Ue=s.jsxs("div",{className:"border-b px-3 pt-4 pb-3",children:[xe,Pe]}),e[84]=xe,e[85]=Pe,e[86]=Ue):Ue=e[86];let ve;e[87]!==F||e[88]!==S||e[89]!==W||e[90]!==ae||e[91]!==te||e[92]!==we||e[93]!==i||e[94]!==T||e[95]!==R||e[96]!==Q?(ve=F?s.jsxs("div",{className:"py-12 px-4 text-center text-muted-foreground",children:[s.jsx(L,{name:"plug",className:"mx-auto mb-3 h-10 w-10 opacity-50"}),s.jsx("p",{className:"typography-ui-label font-medium",children:i("settings.plugins.sidebar.empty.title")}),s.jsx("p",{className:"typography-meta mt-1 opacity-75",children:i("settings.plugins.sidebar.empty.description")})]}):s.jsxs(s.Fragment,{children:[R.length>0&&we(i("settings.plugins.sidebar.group.userEntries"),R.map(ae),T.userEntries),Q.length>0&&we(i("settings.plugins.sidebar.group.userFiles"),Q.map(te)),S.length>0&&we(i("settings.plugins.sidebar.group.projectEntries"),S.map(ae),T.projectEntries),W.length>0&&we(i("settings.plugins.sidebar.group.projectFiles"),W.map(te))]}),e[87]=F,e[88]=S,e[89]=W,e[90]=ae,e[91]=te,e[92]=we,e[93]=i,e[94]=T,e[95]=R,e[96]=Q,e[97]=ve):ve=e[97];let We;e[98]!==Ue||e[99]!==ve?(We=s.jsx(Tl,{variant:"background",header:Ue,children:ve}),e[98]=Ue,e[99]=ve,e[100]=We):We=e[100];let $;e[101]!==O?($=s.jsx(om,{open:O,onOpenChange:I}),e[101]=O,e[102]=$):$=e[102];const de=N!==null;let ue;e[103]!==g?(ue=qe=>{!qe&&!g&&k(null)},e[103]=g,e[104]=ue):ue=e[104];let Ne;e[105]!==i?(Ne=i("settings.plugins.sidebar.deleteDialog.title"),e[105]=i,e[106]=Ne):Ne=e[106];let pe;e[107]!==Ne?(pe=s.jsx(qt,{children:Ne}),e[107]=Ne,e[108]=pe):pe=e[108];const Fe=N?.label??"";let H;e[109]!==i||e[110]!==Fe?(H=i("settings.plugins.sidebar.deleteDialog.description",{name:Fe}),e[109]=i,e[110]=Fe,e[111]=H):H=e[111];let He;e[112]!==H?(He=s.jsx(Wt,{children:H}),e[112]=H,e[113]=He):He=e[113];let et;e[114]!==pe||e[115]!==He?(et=s.jsxs(Gt,{children:[pe,He]}),e[114]=pe,e[115]=He,e[116]=et):et=e[116];let ze;e[117]===Symbol.for("react.memo_cache_sentinel")?(ze=()=>k(null),e[117]=ze):ze=e[117];let st;e[118]!==i?(st=i("settings.common.actions.cancel"),e[118]=i,e[119]=st):st=e[119];let wt;e[120]!==g||e[121]!==st?(wt=s.jsx(B,{size:"sm",variant:"ghost",onClick:ze,disabled:g,children:st}),e[120]=g,e[121]=st,e[122]=wt):wt=e[122];let xt;e[123]!==g||e[124]!==i?(xt=i(g?"settings.plugins.sidebar.actions.deleting":"settings.common.actions.delete"),e[123]=g,e[124]=i,e[125]=xt):xt=e[125];let gt;e[126]!==re||e[127]!==g||e[128]!==xt?(gt=s.jsx(B,{size:"sm",variant:"destructive",onClick:re,disabled:g,children:xt}),e[126]=re,e[127]=g,e[128]=xt,e[129]=gt):gt=e[129];let bt;e[130]!==wt||e[131]!==gt?(bt=s.jsxs(ms,{children:[wt,gt]}),e[130]=wt,e[131]=gt,e[132]=bt):bt=e[132];let St;e[133]!==et||e[134]!==bt?(St=s.jsxs(_t,{className:"max-w-md",children:[et,bt]}),e[133]=et,e[134]=bt,e[135]=St):St=e[135];let yt;e[136]!==de||e[137]!==ue||e[138]!==St?(yt=s.jsx(zt,{open:de,onOpenChange:ue,children:St}),e[136]=de,e[137]=ue,e[138]=St,e[139]=yt):yt=e[139];let It;return e[140]!==We||e[141]!==$||e[142]!==yt?(It=s.jsxs(s.Fragment,{children:[We,$,yt]}),e[140]=We,e[141]=$,e[142]=yt,e[143]=It):It=e[143],It};function um(t){return{entries:t.entries,files:t.files,selectedId:t.selectedId,setSelected:t.setSelected,deleteEntry:t.deleteEntry,deleteFile:t.deleteFile,loadPlugins:t.loadPlugins}}function gm(t){return t.registryInfo}function hm(t){return t.isLoadingRegistry}function fm(t){return t.loadRegistryInfo}function xm(t){return t.updateToLatest}function bm(t){return t.scope==="user"}function vm(t){return t.scope==="project"}function ym(t){return t.scope==="user"}function jm(t){return t.scope==="project"}const wm=({entryId:t,spec:e})=>{const{t:a}=ot(),n=fs(v=>v.registryInfo[e]),i=fs(v=>v.updateToLatest),[r,l]=o.useState(!1);if(!n)return null;if(n.kind==="npm-ok"){if(!n.hasUpdate||!n.latestVersion)return null;const v=n.latestVersion,p=n.currentVersion??"",A=async()=>{l(!0);try{(await i(t)).ok?D.success(a("settings.plugins.toast.updatedToLatest",{version:v})):D.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(L,{name:"arrow-up",className:"h-5 w-5 text-[var(--status-success)] shrink-0 mt-0.5"}),s.jsxs("div",{className:"flex-1 min-w-0",children:[s.jsx("p",{className:"typography-label text-[var(--status-success)]",children:a("settings.plugins.registry.banner.updateAvailable.title")}),s.jsx("p",{className:"typography-micro text-muted-foreground mt-0.5",children:a("settings.plugins.registry.banner.updateAvailable.description",{current:p,latest:v})})]}),s.jsx(B,{variant:"default",size:"sm",onClick:()=>{A()},disabled:r,children:a("settings.plugins.registry.banner.updateAvailable.action",{latest:v})})]})}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(L,{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 h=n.kind==="path-unreadable",d=h?"var(--status-warning)":"var(--status-error)",x=h?"alert":"error-warning",c=(()=>{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(L,{name:x,className:"h-5 w-5 shrink-0 mt-0.5",style:{color:d}}),s.jsxs("div",{className:"flex-1 min-w-0",children:[s.jsx("p",{className:"typography-label",style:{color:d},children:a("settings.plugins.registry.banner.invalid.title")}),s.jsx("p",{className:"typography-micro text-muted-foreground mt-0.5",children:c})]})]})};function km(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 Dl(t){return!t||Object.keys(t).length===0?"":JSON.stringify(t,null,2)}function oo(t){return{mode:"entry",scope:t.scope,spec:t.spec,optionsJson:Dl(t.options),fileName:"",content:""}}function lo(t,e){return{mode:"file",scope:t.scope,spec:"",optionsJson:"",fileName:t.fileName,content:e}}const co=t=>{const e=mt.c(4),{scope:a,label:n}=t;let i;e[0]===Symbol.for("react.memo_cache_sentinel")?(i=je("typography-micro font-medium rounded-full px-2 py-0.5","bg-[var(--surface-elevated)] text-muted-foreground","border border-[var(--interactive-border)]"),e[0]=i):i=e[0];let r;return e[1]!==n||e[2]!==a?(r=s.jsx("span",{className:i,"data-scope":a,children:n}),e[1]=n,e[2]=a,e[3]=r):r=e[3],r},Nm=()=>{const{t}=ot(),e=fs(N=>N.selectedId),a=fs(N=>N.entries),n=fs(N=>N.files),i=fs(N=>N.draft),r=fs(N=>N.setDraft),l=fs(N=>N.updateEntry),h=fs(N=>N.updateFile),d=fs(N=>N.readFile),x=o.useMemo(()=>e?a.find(N=>N.id===e)??null:null,[a,e]),c=o.useMemo(()=>e?n.find(N=>N.id===e)??null:null,[n,e]),[v,p]=o.useState(!1),[A,b]=o.useState(!1),P=o.useRef(new Map);if(o.useEffect(()=>{let N=!1;return x?(r(oo(x)),()=>{N=!0}):c?(b(!0),(async()=>{const k=await d(c.id);if(N)return;b(!1);const g=k?.content??"";P.current.set(c.id,g),r(lo(c,g))})(),()=>{N=!0}):(r(null),()=>{N=!0})},[x,c,d,r]),!e)return s.jsx("div",{className:"flex h-full items-center justify-center",children:s.jsxs("div",{className:"text-center text-muted-foreground",children:[s.jsx(L,{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(x&&i&&i.mode==="entry"){const N=km(i.optionsJson),k=N.ok,g=i.spec!==x.spec||i.optionsJson!==Dl(x.options),E=()=>{r(oo(x))},O=async()=>{if(!k)return;const I=i.spec.trim();if(!I){D.error(t("settings.plugins.validation.specRequired"));return}p(!0);try{const w=await l(x.id,{spec:I,options:N.value});w.ok?w.reloadFailed?D.warning(w.message||t("settings.plugins.toast.reloadFailed"),{description:w.warning}):w.restartDeferred?D.success(t("settings.view.pendingRestart.saved")):D.success(w.message||t("settings.plugins.toast.updated")):D.error(w.message||t("settings.plugins.toast.reloadFailed"))}finally{p(!1)}};return s.jsxs(gs,{title:t("settings.plugins.page.header.entry"),titleAccessory:s.jsx(co,{scope:x.scope,label:x.scope==="project"?t("settings.plugins.sidebar.group.projectEntries"):t("settings.plugins.sidebar.group.userEntries")}),showSaveStatus:!1,children:[s.jsx(Be,{divider:!1,children:s.jsx(wm,{entryId:x.id,spec:x.spec})}),s.jsx(Be,{title:t("settings.plugins.page.field.spec"),settingsItem:"plugins.spec",children:s.jsx(Ye,{value:i.spec,onChange:I=>r({...i,spec:I.target.value}),placeholder:t("settings.plugins.page.field.spec.placeholder"),className:"font-mono typography-meta",spellCheck:!1})}),s.jsxs(Be,{title:t("settings.plugins.page.field.options"),settingsItem:"plugins.options",children:[s.jsx(Es,{value:i.optionsJson,onChange:I=>r({...i,optionsJson:I.target.value}),rows:10,className:je("font-mono typography-meta min-h-[200px]",!k&&"border-[var(--status-error-border)]"),spellCheck:!1,placeholder:"{ }"}),!k&&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:()=>{O()},disabled:!g||!k||v,children:t("settings.plugins.page.action.save")}),s.jsx(B,{variant:"outline",size:"sm",onClick:E,disabled:!g||v,children:t("settings.plugins.page.action.discard")})]})]})]})}if(c&&i&&i.mode==="file"){const N=P.current.get(c.id)??"",k=i.content!==N||i.fileName!==c.fileName,g=()=>{(async()=>{b(!0);const I=(await d(c.id))?.content??"";b(!1),P.current.set(c.id,I),r(lo(c,I))})()},E=async()=>{p(!0);try{const O=await h(c.id,{content:i.content});O.ok?(P.current.set(c.id,i.content),O.reloadFailed?D.warning(O.message||t("settings.plugins.toast.reloadFailed"),{description:O.warning}):O.restartDeferred?D.success(t("settings.view.pendingRestart.saved")):D.success(O.message||t("settings.plugins.toast.updated"))):D.error(O.message||t("settings.plugins.toast.reloadFailed"))}finally{p(!1)}};return s.jsx(gs,{title:t("settings.plugins.page.header.file"),titleAccessory:s.jsxs(s.Fragment,{children:[s.jsx(co,{scope:c.scope,label:c.scope==="project"?t("settings.plugins.sidebar.group.projectFiles"):t("settings.plugins.sidebar.group.userFiles")}),s.jsx("span",{className:je("typography-micro font-mono rounded-full px-2 py-0.5","bg-[var(--surface-elevated)] text-foreground","border border-[var(--interactive-border)]"),children:c.fileName})]}),showSaveStatus:!1,children:s.jsxs(Be,{title:t("settings.plugins.page.field.content"),divider:!1,settingsItem:"plugins.content",children:[s.jsx(Es,{value:i.content,onChange:O=>r({...i,content:O.target.value}),rows:16,className:"font-mono typography-meta min-h-[320px]",spellCheck:!1,disabled:A}),s.jsxs("div",{className:"flex items-center gap-2 pt-3",children:[s.jsx(B,{variant:"default",size:"sm",onClick:()=>{E()},disabled:!k||v||A,children:t("settings.plugins.page.action.save")}),s.jsx(B,{variant:"outline",size:"sm",onClick:g,disabled:v||A,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(L,{name:"loader-4",className:"mx-auto mb-3 h-6 w-6 animate-spin opacity-50"})})})},Sm="<built-in>",Da=t=>t?.path===Sm,nr=t=>!!t&&!Da(t)&&t.renamable===!0,Cm=t=>{const e=mt.c(157),{onItemSelect:a}=t,{t:n}=ot(),[i,r]=o.useState(null),[l,h]=o.useState(""),[d,x]=o.useState(null),[c,v]=o.useState(!1),[p,A]=o.useState(null),{selectedSkillName:b,setSelectedSkill:P,setSkillDraft:N,deleteSkill:k,renameSkill:g,getSkillDetail:E}=$s(Ms(Pm)),O=Us();let I;e[0]!==O?(I=Se=>cr(Se,O),e[0]=O,e[1]=I):I=e[1];const w=$s(I),m=$s(Im);let y,K;e[2]!==m||e[3]!==O?(y=()=>{m(O)},K=[m,O],e[2]=m,e[3]=O,e[4]=y,e[5]=K):(y=e[4],K=e[5]),o.useEffect(y,K);let C;e[6]!==a||e[7]!==P||e[8]!==N||e[9]!==w?(C=()=>{let Se="new-skill",kt=1;for(;w.some(J=>J.name===Se);)Se=`new-skill-${kt}`,kt++;N({name:Se,scope:"user",source:"opencode",description:""}),P(Se),a?.()},e[6]=a,e[7]=P,e[8]=N,e[9]=w,e[10]=C):C=e[10];const T=C;let j;e[11]===Symbol.for("react.memo_cache_sentinel")?(j=async Se=>{Da(Se)||x(Se)},e[11]=j):j=e[11];const R=j;let G;e[12]!==d||e[13]!==k||e[14]!==O||e[15]!==n?(G=async()=>{if(!d)return;if(Da(d)){x(null);return}v(!0),await k(d.name,O)?(D.success(n("settings.skills.sidebar.toast.skillDeleted",{name:d.name})),x(null)):D.error(n("settings.skills.sidebar.toast.deleteSkillFailed")),v(!1)},e[12]=d,e[13]=k,e[14]=O,e[15]=n,e[16]=G):G=e[16];const S=G;let q;e[17]!==E||e[18]!==P||e[19]!==N||e[20]!==O||e[21]!==w||e[22]!==n?(q=async Se=>{if(Da(Se))return;const kt=Se.name;let J=1,me=`${kt}-copy`;for(;w.some(Ie=>Ie.name===me);)J++,me=`${kt}-copy-${J}`;const Te=await E(Se.name,O);if(!Te){D.error(n("settings.skills.sidebar.toast.duplicateLoadFailed"));return}N({name:me,scope:Se.scope||"user",source:Se.source||"opencode",description:(Te.sources.md.fields.includes("description"),""),instructions:""}),P(me)},e[17]=E,e[18]=P,e[19]=N,e[20]=O,e[21]=w,e[22]=n,e[23]=q):q=e[23];const Q=q;let M;e[24]===Symbol.for("react.memo_cache_sentinel")?(M=Se=>{nr(Se)&&(h(Se.name),r(Se))},e[24]=M):M=e[24];const W=M;let Y;e[25]!==i||e[26]!==l||e[27]!==g||e[28]!==P||e[29]!==O||e[30]!==w||e[31]!==n?(Y=async()=>{if(!i)return;if(!nr(i)){r(null);return}const Se=l.trim().replace(/\s+/g,"-").toLowerCase();if(!Se){D.error(n("settings.skills.page.toast.skillNameRequired"));return}if(Se===i.name){r(null);return}if(w.some(J=>J.name===Se)){D.error(n("settings.skills.page.toast.skillExists"));return}await g(i.name,Se,O)?(D.success(n("settings.skills.sidebar.toast.skillRenamed",{name:Se})),P(Se)):D.error(n("settings.skills.sidebar.toast.renameFailed")),r(null)},e[25]=i,e[26]=l,e[27]=g,e[28]=P,e[29]=O,e[30]=w,e[31]=n,e[32]=Y):Y=e[32];const F=Y;let se;e[33]!==w?(se=w.filter(Am),e[33]=w,e[34]=se):se=e[34];const _=se;let V;e[35]!==w?(V=w.filter(Em),e[35]=w,e[36]=V):V=e[36];const z=V;let U;e[37]===Symbol.for("react.memo_cache_sentinel")?(U=function(kt){const J={},me=[];for(const Ie of kt)Ie.group?(J[Ie.group]||(J[Ie.group]=[]),J[Ie.group].push(Ie)):me.push(Ie);const Te=Object.keys(J).sort(Tm).map(Ie=>({name:Ie,skills:[...J[Ie]].sort(Dm)}));return me.sort(Mm),{sortedGroups:Te,ungrouped:me}},e[37]=U):U=e[37];const X=U;let Z;e[38]!==_?(Z=X(_),e[38]=_,e[39]=Z):Z=e[39];const ne=Z;let le;e[40]!==z?(le=X(z),e[40]=z,e[41]=le):le=e[41];const re=le;let fe;e[42]===Symbol.for("react.memo_cache_sentinel")?(fe=je("flex h-full flex-col","bg-background"),e[42]=fe):fe=e[42];let ae;e[43]!==n?(ae=n("settings.skills.sidebar.title"),e[43]=n,e[44]=ae):ae=e[44];let ie;e[45]!==ae?(ie=s.jsx("h2",{className:`${rn} mb-3`,children:ae}),e[45]=ae,e[46]=ie):ie=e[46];let te;e[47]===Symbol.for("react.memo_cache_sentinel")?(te=s.jsx(Ka,{className:"mb-3"}),e[47]=te):te=e[47];let ye;e[48]!==w.length||e[49]!==n?(ye=n("settings.skills.sidebar.total",{count:w.length}),e[48]=w.length,e[49]=n,e[50]=ye):ye=e[50];let we;e[51]!==ye?(we=s.jsx("span",{className:"typography-meta text-muted-foreground",children:ye}),e[51]=ye,e[52]=we):we=e[52];let ke;e[53]===Symbol.for("react.memo_cache_sentinel")?(ke=s.jsx(L,{name:"add",className:"h-3.5 w-3.5"}),e[53]=ke):ke=e[53];let xe;e[54]!==T?(xe=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:T,children:ke}),e[54]=T,e[55]=xe):xe=e[55];let De;e[56]!==we||e[57]!==xe?(De=s.jsxs("div",{className:"flex items-center justify-between gap-2",children:[we,xe]}),e[56]=we,e[57]=xe,e[58]=De):De=e[58];let Me;e[59]!==ie||e[60]!==De?(Me=s.jsxs("div",{className:"border-b px-3 pt-4 pb-3",children:[ie,te,De]}),e[59]=ie,e[60]=De,e[61]=Me):Me=e[61];let he;e[62]!==ne||e[63]!==re||e[64]!==Q||e[65]!==a||e[66]!==p||e[67]!==_||e[68]!==b||e[69]!==P||e[70]!==w.length||e[71]!==n||e[72]!==z?(he=s.jsx(Vs,{outerClassName:"flex-1 min-h-0",className:"space-y-1 px-3 py-2 overflow-x-hidden",children:w.length===0?s.jsxs("div",{className:"py-12 px-4 text-center text-muted-foreground",children:[s.jsx(L,{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(Se=>{const{name:kt,skills:J}=Se;return s.jsx(Zi,{label:kt,count:J.length,storageKey:"project-skills",children:J.map(me=>s.jsx(Ja,{skill:me,isSelected:b===me.name,onSelect:()=>{P(me.name),a?.()},onRename:()=>W(me),onDelete:()=>R(me),onDuplicate:()=>Q(me),isMenuOpen:p===me.name,onMenuOpenChange:Te=>A(Te?me.name:null)},me.name))},kt)}),ne.ungrouped.map(Se=>s.jsx(Ja,{skill:Se,isSelected:b===Se.name,onSelect:()=>{P(Se.name),a?.()},onRename:()=>W(Se),onDelete:()=>R(Se),onDuplicate:()=>Q(Se),isMenuOpen:p===Se.name,onMenuOpenChange:kt=>A(kt?Se.name:null)},Se.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")}),re.sortedGroups.map(Se=>{const{name:kt,skills:J}=Se;return s.jsx(Zi,{label:kt,count:J.length,storageKey:"user-skills",children:J.map(me=>s.jsx(Ja,{skill:me,isSelected:b===me.name,onSelect:()=>{P(me.name),a?.()},onRename:()=>W(me),onDelete:()=>R(me),onDuplicate:()=>Q(me),isMenuOpen:p===me.name,onMenuOpenChange:Te=>A(Te?me.name:null)},me.name))},kt)}),re.ungrouped.map(Se=>s.jsx(Ja,{skill:Se,isSelected:b===Se.name,onSelect:()=>{P(Se.name),a?.()},onRename:()=>W(Se),onDelete:()=>R(Se),onDuplicate:()=>Q(Se),isMenuOpen:p===Se.name,onMenuOpenChange:kt=>A(kt?Se.name:null)},Se.name))]})]})}),e[62]=ne,e[63]=re,e[64]=Q,e[65]=a,e[66]=p,e[67]=_,e[68]=b,e[69]=P,e[70]=w.length,e[71]=n,e[72]=z,e[73]=he):he=e[73];const ge=d!==null;let Ae;e[74]!==c?(Ae=Se=>{!Se&&!c&&x(null)},e[74]=c,e[75]=Ae):Ae=e[75];let Ve;e[76]!==n?(Ve=n("settings.skills.sidebar.deleteDialog.title"),e[76]=n,e[77]=Ve):Ve=e[77];let _e;e[78]!==Ve?(_e=s.jsx(qt,{children:Ve}),e[78]=Ve,e[79]=_e):_e=e[79];const Le=d?.name??"";let Re;e[80]!==n||e[81]!==Le?(Re=n("settings.skills.sidebar.deleteDialog.description",{name:Le}),e[80]=n,e[81]=Le,e[82]=Re):Re=e[82];let Ze;e[83]!==Re?(Ze=s.jsx(Wt,{children:Re}),e[83]=Re,e[84]=Ze):Ze=e[84];let Ge;e[85]!==_e||e[86]!==Ze?(Ge=s.jsxs(Gt,{children:[_e,Ze]}),e[85]=_e,e[86]=Ze,e[87]=Ge):Ge=e[87];let Oe;e[88]===Symbol.for("react.memo_cache_sentinel")?(Oe=()=>x(null),e[88]=Oe):Oe=e[88];let Ke;e[89]!==n?(Ke=n("settings.common.actions.cancel"),e[89]=n,e[90]=Ke):Ke=e[90];let Pe;e[91]!==c||e[92]!==Ke?(Pe=s.jsx(B,{size:"sm",className:"text-foreground hover:bg-interactive-hover hover:text-foreground",variant:"ghost",onClick:Oe,disabled:c,children:Ke}),e[91]=c,e[92]=Ke,e[93]=Pe):Pe=e[93];let Ue;e[94]!==n?(Ue=n("settings.common.actions.delete"),e[94]=n,e[95]=Ue):Ue=e[95];let ve;e[96]!==S||e[97]!==c||e[98]!==Ue?(ve=s.jsx(B,{size:"sm",onClick:S,disabled:c,children:Ue}),e[96]=S,e[97]=c,e[98]=Ue,e[99]=ve):ve=e[99];let We;e[100]!==Pe||e[101]!==ve?(We=s.jsxs(ms,{children:[Pe,ve]}),e[100]=Pe,e[101]=ve,e[102]=We):We=e[102];let $;e[103]!==Ge||e[104]!==We?($=s.jsxs(_t,{className:"max-w-md",children:[Ge,We]}),e[103]=Ge,e[104]=We,e[105]=$):$=e[105];let de;e[106]!==ge||e[107]!==Ae||e[108]!==$?(de=s.jsx(zt,{open:ge,onOpenChange:Ae,children:$}),e[106]=ge,e[107]=Ae,e[108]=$,e[109]=de):de=e[109];const ue=i!==null;let Ne;e[110]===Symbol.for("react.memo_cache_sentinel")?(Ne=Se=>!Se&&r(null),e[110]=Ne):Ne=e[110];let pe;e[111]!==n?(pe=n("settings.skills.sidebar.renameDialog.title"),e[111]=n,e[112]=pe):pe=e[112];let Fe;e[113]!==pe?(Fe=s.jsx(qt,{children:pe}),e[113]=pe,e[114]=Fe):Fe=e[114];const H=i?.name??"";let He;e[115]!==n||e[116]!==H?(He=n("settings.skills.sidebar.renameDialog.description",{name:H}),e[115]=n,e[116]=H,e[117]=He):He=e[117];let et;e[118]!==He?(et=s.jsx(Wt,{children:He}),e[118]=He,e[119]=et):et=e[119];let ze;e[120]!==Fe||e[121]!==et?(ze=s.jsxs(Gt,{children:[Fe,et]}),e[120]=Fe,e[121]=et,e[122]=ze):ze=e[122];let st;e[123]===Symbol.for("react.memo_cache_sentinel")?(st=Se=>h(Se.target.value),e[123]=st):st=e[123];let wt;e[124]!==n?(wt=n("settings.skills.sidebar.renameDialog.placeholder"),e[124]=n,e[125]=wt):wt=e[125];let xt;e[126]!==F?(xt=Se=>{Se.key==="Enter"&&F()},e[126]=F,e[127]=xt):xt=e[127];let gt;e[128]!==l||e[129]!==wt||e[130]!==xt?(gt=s.jsx(Ye,{value:l,onChange:st,placeholder:wt,className:"text-foreground placeholder:text-muted-foreground",onKeyDown:xt}),e[128]=l,e[129]=wt,e[130]=xt,e[131]=gt):gt=e[131];let bt;e[132]===Symbol.for("react.memo_cache_sentinel")?(bt=()=>r(null),e[132]=bt):bt=e[132];let St;e[133]!==n?(St=n("settings.common.actions.cancel"),e[133]=n,e[134]=St):St=e[134];let yt;e[135]!==St?(yt=s.jsx(B,{size:"sm",className:"text-foreground hover:bg-interactive-hover hover:text-foreground",variant:"ghost",onClick:bt,children:St}),e[135]=St,e[136]=yt):yt=e[136];let It;e[137]!==n?(It=n("settings.common.actions.rename"),e[137]=n,e[138]=It):It=e[138];let qe;e[139]!==F||e[140]!==It?(qe=s.jsx(B,{size:"sm",onClick:F,children:It}),e[139]=F,e[140]=It,e[141]=qe):qe=e[141];let Qe;e[142]!==yt||e[143]!==qe?(Qe=s.jsxs(ms,{children:[yt,qe]}),e[142]=yt,e[143]=qe,e[144]=Qe):Qe=e[144];let dt;e[145]!==ze||e[146]!==gt||e[147]!==Qe?(dt=s.jsxs(_t,{children:[ze,gt,Qe]}),e[145]=ze,e[146]=gt,e[147]=Qe,e[148]=dt):dt=e[148];let Ee;e[149]!==ue||e[150]!==dt?(Ee=s.jsx(zt,{open:ue,onOpenChange:Ne,children:dt}),e[149]=ue,e[150]=dt,e[151]=Ee):Ee=e[151];let vt;return e[152]!==Me||e[153]!==he||e[154]!==de||e[155]!==Ee?(vt=s.jsxs("div",{className:fe,children:[Me,he,de,Ee]}),e[152]=Me,e[153]=he,e[154]=de,e[155]=Ee,e[156]=vt):vt=e[156],vt},Ja=t=>{const e=mt.c(41),{skill:a,isSelected:n,onSelect:i,onDelete:r,onRename:l,onDuplicate:h,isMenuOpen:d,onMenuOpenChange:x}=t,{t:c}=ot();let v;e[0]===Symbol.for("react.memo_cache_sentinel")?(v=Ra(),e[0]=v):v=e[0];const p=v;let A;e[1]!==a?(A=Da(a),e[1]=a,e[2]=A):A=e[2];const b=A;let P;e[3]!==a?(P=nr(a),e[3]=a,e[4]=P):P=e[4];const N=P,[k,g]=o.useState(!1);let E;e[5]!==N||e[6]!==r||e[7]!==h||e[8]!==l||e[9]!==c?(E=Q=>s.jsxs(s.Fragment,{children:[N?s.jsxs(Q,{onClick:M=>{M.stopPropagation(),l()},children:[s.jsx(L,{name:"edit",className:"h-4 w-4 mr-px"}),c("settings.common.actions.rename")]}):null,s.jsxs(Q,{onClick:M=>{M.stopPropagation(),h()},children:[s.jsx(L,{name:"file-copy",className:"h-4 w-4 mr-px"}),c("settings.common.actions.duplicate")]}),s.jsxs(Q,{onClick:M=>{M.stopPropagation(),r()},className:"text-destructive focus:text-destructive",children:[s.jsx(L,{name:"delete-bin",className:"h-4 w-4 mr-px"}),c("settings.common.actions.delete")]})]}),e[5]=N,e[6]=r,e[7]=h,e[8]=l,e[9]=c,e[10]=E):E=e[10];const O=E,I=!b&&k,w=n?"bg-interactive-selection":"hover:bg-interactive-hover";let m;e[11]!==w?(m=je("group relative flex items-center rounded-md px-1.5 py-1 transition-all duration-200 select-none",w),e[11]=w,e[12]=m):m=e[12];let y;e[13]!==b?(y=!p&&!b?Q=>{Q.preventDefault(),g(!0)}:void 0,e[13]=b,e[14]=y):y=e[14];let K;e[15]!==m||e[16]!==y?(K=s.jsx("div",{className:m,onContextMenu:y}),e[15]=m,e[16]=y,e[17]=K):K=e[17];let C;e[18]!==a.name?(C=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]=C):C=e[19];let T;e[20]!==i||e[21]!==C?(T=s.jsx("button",{onClick:i,className:"flex min-w-0 flex-1 flex-col gap-0 rounded-sm text-left focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-primary/50",tabIndex:0,children:C}),e[20]=i,e[21]=C,e[22]=T):T=e[22];let j;e[23]!==b||e[24]!==d||e[25]!==x||e[26]!==O?(j=b?null:s.jsxs(nn,{open:d,onOpenChange:Q=>{Q&&g(!1),x(Q)},children:[s.jsx(tn,{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(L,{name:"more-2",className:"h-3.5 w-3.5"})})}),s.jsx(sn,{align:"end",className:"w-fit min-w-20",children:O(an)})]}),e[23]=b,e[24]=d,e[25]=x,e[26]=O,e[27]=j):j=e[27];let R;e[28]!==T||e[29]!==j?(R=s.jsxs("div",{className:"flex min-w-0 flex-1 items-center",children:[T,j]}),e[28]=T,e[29]=j,e[30]=R):R=e[30];let G;e[31]!==R||e[32]!==K?(G=s.jsx(Hn,{render:K,children:R}),e[31]=R,e[32]=K,e[33]=G):G=e[33];let S;e[34]!==b||e[35]!==O?(S=b?null:s.jsx(Vn,{className:"w-fit min-w-20",children:O(Bn)}),e[34]=b,e[35]=O,e[36]=S):S=e[36];let q;return e[37]!==G||e[38]!==S||e[39]!==I?(q=s.jsxs(Gn,{open:I,onOpenChange:g,children:[G,S]}),e[37]=G,e[38]=S,e[39]=I,e[40]=q):q=e[40],q};function Pm(t){return{selectedSkillName:t.selectedSkillName,setSelectedSkill:t.setSelectedSkill,setSkillDraft:t.setSkillDraft,deleteSkill:t.deleteSkill,renameSkill:t.renameSkill,getSkillDetail:t.getSkillDetail}}function Im(t){return t.loadSkills}function Am(t){return t.scope==="project"}function Em(t){return t.scope==="user"}function Tm(t,e){return t.localeCompare(e)}function Dm(t,e){return t.name.localeCompare(e.name)}function Mm(t,e){return t.name.localeCompare(e.name)}const Rm=()=>`custom:${Date.now()}-${Math.random().toString(16).slice(2)}`,Om=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},Lm=async()=>{try{const t=In()?.settings;if(t)return(await t.load())?.settings||{};const e=await pt("/api/config/settings",{method:"GET",headers:{Accept:"application/json"}});return e.ok?await e.json().catch(()=>null):null}catch{return null}},Fm=t=>{const e=mt.c(162),{open:a,onOpenChange:n}=t,{t:i}=ot(),r=ln(Km),l=ln(Um),h=ln(zm),d=ln(_m),x=ln($m),c=Kn(Vm),v=Kn(Bm),[p,A]=o.useState(""),[b,P]=o.useState(""),[N,k]=o.useState("");let g;e[0]===Symbol.for("react.memo_cache_sentinel")?(g=[],e[0]=g):g=e[0];const[E,O]=o.useState(g),[I,w]=o.useState(null),[m,y]=o.useState(!1);let K;e[1]===Symbol.for("react.memo_cache_sentinel")?(K=[],e[1]=K):K=e[1];const[C,T]=o.useState(K),[j,R]=o.useState(null),G=o.useRef(0);let S;e[2]===Symbol.for("react.memo_cache_sentinel")?(S=Qe=>{G.current=G.current+1,y(!1),w(null),Qe?.clearIdentity&&(T([]),R(null))},e[2]=S):S=e[2];const q=S;let Q,M;e[3]!==v||e[4]!==a?(Q=()=>{a&&(G.current=G.current+1,A(""),P(""),k(""),w(null),y(!1),T([]),R(null),v(),(async()=>{const Qe=await Lm(),dt=Array.isArray(Qe?.skillCatalogs)?Qe?.skillCatalogs:[];O(dt||[])})())},M=[a,v],e[3]=v,e[4]=a,e[5]=Q,e[6]=M):(Q=e[5],M=e[6]),o.useEffect(Q,M);let W;e[7]!==b?(W=b.trim(),e[7]=b,e[8]=W):W=e[8];const Y=W;let F;e[9]!==N?(F=N.trim(),e[9]=N,e[10]=F):F=e[10];const se=F;let _;if(e[11]!==E||e[12]!==Y||e[13]!==se){let Qe;e[15]!==Y||e[16]!==se?(Qe=dt=>{const Ee=(dt.source||"").trim(),vt=(dt.subpath||"").trim();return Ee===Y&&vt===se},e[15]=Y,e[16]=se,e[17]=Qe):Qe=e[17],_=E.some(Qe),e[11]=E,e[12]=Y,e[13]=se,e[14]=_}else _=e[14];const V=_;let z;e[18]!==c||e[19]!==j||e[20]!==p||e[21]!==r||e[22]!==b||e[23]!==N||e[24]!==i?(z=async()=>{const Qe=b.trim();if(!Qe){D.error(i("settings.skills.catalog.add.toast.repositoryRequired"));return}p.trim()||A(Om(Qe)),y(!1),w(null);const dt=G.current+1;G.current=dt;const Ee=await r({source:Qe,subpath:N.trim()||void 0,gitIdentityId:j||void 0});if(G.current!==dt)return;if(!Ee.ok){if(Ee.error?.kind==="authRequired"){if(vs()){D.error(i("settings.skills.catalog.shared.toast.privateRepoNotSupportedVsCode"));return}const Se=Ee.error.identities||[];if(T(Se),!j&&Se.length>0){const kt=c&&c!=="global"&&Se.some(J=>J.id===c)?c:Se[0].id;R(kt)}D.error(i("settings.skills.catalog.add.toast.authenticationRequiredScan"));return}D.error(Ee.error?.message||i("settings.skills.catalog.add.toast.scanFailed"));return}const vt=Ee.items?.length||0;if(w(vt),vt===0){D.error(i("settings.skills.catalog.add.toast.noSkillsFound")),y(!1);return}T([]),y(!0),D.success(i("settings.skills.catalog.shared.toast.foundSkills",{count:vt}))},e[18]=c,e[19]=j,e[20]=p,e[21]=r,e[22]=b,e[23]=N,e[24]=i,e[25]=z):z=e[25];const U=z;let X;e[26]!==E||e[27]!==j||e[28]!==V||e[29]!==p||e[30]!==l||e[31]!==h||e[32]!==n||e[33]!==m||e[34]!==d||e[35]!==b||e[36]!==N||e[37]!==i?(X=async()=>{const Qe=p.trim(),dt=b.trim(),Ee=N.trim();if(!Qe){D.error(i("settings.skills.catalog.add.toast.catalogNameRequired"));return}if(!dt){D.error(i("settings.skills.catalog.add.toast.repositoryRequired"));return}if(!m){D.error(i("settings.skills.catalog.add.toast.scanBeforeAdd"));return}if(V){D.error(i("settings.skills.catalog.add.toast.catalogAlreadyExists"));return}const vt={id:Rm(),label:Qe,source:dt,...Ee?{subpath:Ee}:{},...j?{gitIdentityId:j}:{}},Se=[...E,vt];try{await Nt({skillCatalogs:Se}),O(Se),D.success(i("settings.skills.catalog.add.toast.catalogAdded")),await l({refresh:!0}),await h(vt.id,{refresh:!0}),d(vt.id),n(!1)}catch(kt){const J=kt;D.error(J instanceof Error?J.message:i("settings.skills.catalog.add.toast.saveFailed"))}},e[26]=E,e[27]=j,e[28]=V,e[29]=p,e[30]=l,e[31]=h,e[32]=n,e[33]=m,e[34]=d,e[35]=b,e[36]=N,e[37]=i,e[38]=X):X=e[38];const Z=X;let ne;e[39]!==i?(ne=i("settings.skills.catalog.add.title"),e[39]=i,e[40]=ne):ne=e[40];let le;e[41]!==ne?(le=s.jsx(qt,{children:ne}),e[41]=ne,e[42]=le):le=e[42];let re;e[43]!==i?(re=i("settings.skills.catalog.add.descriptionPrefix"),e[43]=i,e[44]=re):re=e[44];let fe;e[45]===Symbol.for("react.memo_cache_sentinel")?(fe=s.jsx("code",{className:"font-mono",children:"SKILL.md"}),e[45]=fe):fe=e[45];let ae;e[46]!==i?(ae=i("settings.skills.catalog.add.descriptionSuffix"),e[46]=i,e[47]=ae):ae=e[47];let ie;e[48]!==re||e[49]!==ae?(ie=s.jsxs(Wt,{children:[re," ",fe,ae]}),e[48]=re,e[49]=ae,e[50]=ie):ie=e[50];let te;e[51]!==le||e[52]!==ie?(te=s.jsxs(Gt,{children:[le,ie]}),e[51]=le,e[52]=ie,e[53]=te):te=e[53];let ye;e[54]!==i?(ye=i("settings.skills.catalog.add.field.catalogName"),e[54]=i,e[55]=ye):ye=e[55];let we;e[56]!==ye?(we=s.jsx("label",{className:"typography-ui-label text-foreground",children:ye}),e[56]=ye,e[57]=we):we=e[57];let ke;e[58]===Symbol.for("react.memo_cache_sentinel")?(ke=Qe=>A(Qe.target.value),e[58]=ke):ke=e[58];let xe;e[59]!==i?(xe=i("settings.skills.catalog.add.field.catalogNamePlaceholder"),e[59]=i,e[60]=xe):xe=e[60];let De;e[61]!==p||e[62]!==xe?(De=s.jsx(Ye,{value:p,onChange:ke,placeholder:xe}),e[61]=p,e[62]=xe,e[63]=De):De=e[63];let Me;e[64]!==we||e[65]!==De?(Me=s.jsxs("div",{className:"space-y-2",children:[we,De]}),e[64]=we,e[65]=De,e[66]=Me):Me=e[66];let he;e[67]!==i?(he=i("settings.skills.catalog.add.field.repository"),e[67]=i,e[68]=he):he=e[68];let ge;e[69]!==he?(ge=s.jsx("label",{className:"typography-ui-label text-foreground",children:he}),e[69]=he,e[70]=ge):ge=e[70];let Ae;e[71]!==i?(Ae=i("settings.skills.catalog.add.field.repositoryHint"),e[71]=i,e[72]=Ae):Ae=e[72];let Ve;e[73]!==Ae?(Ve=s.jsx(ss,{children:Ae}),e[73]=Ae,e[74]=Ve):Ve=e[74];let _e;e[75]!==ge||e[76]!==Ve?(_e=s.jsxs("div",{className:"flex items-center gap-1",children:[ge,Ve]}),e[75]=ge,e[76]=Ve,e[77]=_e):_e=e[77];let Le;e[78]===Symbol.for("react.memo_cache_sentinel")?(Le=Qe=>{P(Qe.target.value),q({clearIdentity:!0})},e[78]=Le):Le=e[78];let Re;e[79]!==i?(Re=i("settings.skills.catalog.shared.field.repositoryPlaceholder"),e[79]=i,e[80]=Re):Re=e[80];let Ze;e[81]!==b||e[82]!==Re?(Ze=s.jsx(Ye,{value:b,onChange:Le,placeholder:Re}),e[81]=b,e[82]=Re,e[83]=Ze):Ze=e[83];let Ge;e[84]!==_e||e[85]!==Ze?(Ge=s.jsxs("div",{className:"space-y-2",children:[_e,Ze]}),e[84]=_e,e[85]=Ze,e[86]=Ge):Ge=e[86];let Oe;e[87]!==i?(Oe=i("settings.skills.catalog.add.field.optionalSubpath"),e[87]=i,e[88]=Oe):Oe=e[88];let Ke;e[89]!==Oe?(Ke=s.jsx("label",{className:"typography-ui-label text-foreground",children:Oe}),e[89]=Oe,e[90]=Ke):Ke=e[90];let Pe;e[91]===Symbol.for("react.memo_cache_sentinel")?(Pe=Qe=>{k(Qe.target.value),q({clearIdentity:!0})},e[91]=Pe):Pe=e[91];let Ue;e[92]!==i?(Ue=i("settings.skills.catalog.shared.field.subpathPlaceholder"),e[92]=i,e[93]=Ue):Ue=e[93];let ve;e[94]!==N||e[95]!==Ue?(ve=s.jsx(Ye,{value:N,onChange:Pe,placeholder:Ue}),e[94]=N,e[95]=Ue,e[96]=ve):ve=e[96];let We;e[97]!==Ke||e[98]!==ve?(We=s.jsxs("div",{className:"space-y-2",children:[Ke,ve]}),e[97]=Ke,e[98]=ve,e[99]=We):We=e[99];let $;e[100]!==j||e[101]!==C||e[102]!==i?($=C.length>0&&!vs()?s.jsxs("div",{className:"space-y-2",children:[s.jsxs("div",{className:"flex items-center",children:[s.jsx("span",{className:"typography-ui-label text-[var(--status-warning)]",children:i("settings.skills.catalog.shared.auth.title")}),s.jsx("span",{className:"typography-meta text-muted-foreground ml-2",children:i("settings.skills.catalog.shared.auth.description")}),s.jsx(ss,{className:"ml-1",children:i("settings.skills.catalog.shared.auth.footerHint")})]}),s.jsxs(Ot,{value:j||"",onValueChange:Qe=>{R(Qe),q()},children:[s.jsx(Lt,{className:"w-fit",children:s.jsx("span",{children:C.find(Qe=>Qe.id===j)?.name||i("settings.skills.catalog.shared.auth.chooseIdentity")})}),s.jsx(Ft,{align:"start",children:C.map(Hm)})]})]}):null,e[100]=j,e[101]=C,e[102]=i,e[103]=$):$=e[103];let de;e[104]!==I||e[105]!==i?(de=I!==null?s.jsx("div",{className:"typography-meta text-muted-foreground",children:i("settings.skills.catalog.add.scanResult",{count:I})}):null,e[104]=I,e[105]=i,e[106]=de):de=e[106];let ue;e[107]!==V||e[108]!==i?(ue=V?s.jsx("div",{className:"typography-meta text-muted-foreground",children:i("settings.skills.catalog.add.duplicateMessage")}):null,e[107]=V,e[108]=i,e[109]=ue):ue=e[109];let Ne;e[110]!==Me||e[111]!==Ge||e[112]!==We||e[113]!==$||e[114]!==de||e[115]!==ue?(Ne=s.jsxs("div",{className:"space-y-4",children:[Me,Ge,We,$,de,ue]}),e[110]=Me,e[111]=Ge,e[112]=We,e[113]=$,e[114]=de,e[115]=ue,e[116]=Ne):Ne=e[116];let pe;e[117]!==n?(pe=()=>n(!1),e[117]=n,e[118]=pe):pe=e[118];let Fe;e[119]!==i?(Fe=i("settings.common.actions.cancel"),e[119]=i,e[120]=Fe):Fe=e[120];let H;e[121]!==pe||e[122]!==Fe?(H=s.jsx(B,{size:"sm",variant:"ghost",onClick:pe,children:Fe}),e[121]=pe,e[122]=Fe,e[123]=H):H=e[123];let He;e[124]!==U?(He=()=>{U()},e[124]=U,e[125]=He):He=e[125];let et;e[126]!==x||e[127]!==b?(et=x||!b.trim(),e[126]=x,e[127]=b,e[128]=et):et=e[128];let ze;e[129]===Symbol.for("react.memo_cache_sentinel")?(ze=s.jsx(L,{name:"git-repository",className:"h-4 w-4"}),e[129]=ze):ze=e[129];let st;e[130]!==x||e[131]!==i?(st=i(x?"settings.skills.catalog.shared.actions.scanning":"settings.skills.catalog.shared.actions.scan"),e[130]=x,e[131]=i,e[132]=st):st=e[132];let wt;e[133]!==He||e[134]!==et||e[135]!==st?(wt=s.jsxs(B,{size:"sm",className:"gap-2",variant:"ghost",onClick:He,disabled:et,children:[ze,st]}),e[133]=He,e[134]=et,e[135]=st,e[136]=wt):wt=e[136];let xt;e[137]!==Z?(xt=()=>{Z()},e[137]=Z,e[138]=xt):xt=e[138];let gt;e[139]!==V||e[140]!==p||e[141]!==m||e[142]!==b?(gt=!m||V||!p.trim()||!b.trim(),e[139]=V,e[140]=p,e[141]=m,e[142]=b,e[143]=gt):gt=e[143];let bt;e[144]!==i?(bt=i("settings.skills.catalog.add.actions.addCatalog"),e[144]=i,e[145]=bt):bt=e[145];let St;e[146]!==xt||e[147]!==gt||e[148]!==bt?(St=s.jsx(B,{size:"sm",onClick:xt,disabled:gt,children:bt}),e[146]=xt,e[147]=gt,e[148]=bt,e[149]=St):St=e[149];let yt;e[150]!==H||e[151]!==wt||e[152]!==St?(yt=s.jsxs(ms,{children:[H,wt,St]}),e[150]=H,e[151]=wt,e[152]=St,e[153]=yt):yt=e[153];let It;e[154]!==te||e[155]!==Ne||e[156]!==yt?(It=s.jsxs(_t,{className:"max-w-xl",children:[te,Ne,yt]}),e[154]=te,e[155]=Ne,e[156]=yt,e[157]=It):It=e[157];let qe;return e[158]!==n||e[159]!==a||e[160]!==It?(qe=s.jsx(zt,{open:a,onOpenChange:n,children:It}),e[158]=n,e[159]=a,e[160]=It,e[161]=qe):qe=e[161],qe};function Km(t){return t.scanRepo}function Um(t){return t.loadCatalog}function zm(t){return t.loadSource}function _m(t){return t.setSelectedSource}function $m(t){return t.isScanning}function Vm(t){return t.defaultGitIdentityId}function Bm(t){return t.loadDefaultGitIdentityId}function Hm(t){return s.jsx(ut,{value:t.id,children:t.name},t.id)}const Gm=t=>{const e=mt.c(85),{open:a,onOpenChange:n,conflicts:i,onConfirm:r}=t,{t:l}=ot();let h;e[0]===Symbol.for("react.memo_cache_sentinel")?(h={},e[0]=h):h=e[0];const[d,x]=o.useState(h);let c,v;e[1]!==i||e[2]!==a?(c=()=>{if(!a)return;const Z={};for(const ne of i)Z[ne.skillName]="skip";x(Z)},v=[a,i],e[1]=i,e[2]=a,e[3]=c,e[4]=v):(c=e[3],v=e[4]),o.useEffect(c,v);let p;e[5]!==i?(p=Z=>{const ne={};for(const le of i)ne[le.skillName]=Z;x(ne)},e[5]=i,e[6]=p):p=e[6];const A=p;let b;e[7]!==i||e[8]!==d?(b=i.length>0&&i.every(Z=>d[Z.skillName]),e[7]=i,e[8]=d,e[9]=b):b=e[9];const P=b;let N;e[10]!==l?(N=l("settings.skills.catalog.conflicts.title"),e[10]=l,e[11]=N):N=e[11];let k;e[12]!==N?(k=s.jsx(qt,{children:N}),e[12]=N,e[13]=k):k=e[13];let g;e[14]!==l?(g=l("settings.skills.catalog.conflicts.description"),e[14]=l,e[15]=g):g=e[15];let E;e[16]!==g?(E=s.jsx(Wt,{children:g}),e[16]=g,e[17]=E):E=e[17];let O;e[18]!==k||e[19]!==E?(O=s.jsxs(Gt,{children:[k,E]}),e[18]=k,e[19]=E,e[20]=O):O=e[20];let I;e[21]!==i.length||e[22]!==l?(I=l("settings.skills.catalog.conflicts.count",{count:i.length}),e[21]=i.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 m;e[26]!==A?(m=()=>A("skip"),e[26]=A,e[27]=m):m=e[27];let y;e[28]!==l?(y=l("settings.skills.catalog.conflicts.actions.skipAll"),e[28]=l,e[29]=y):y=e[29];let K;e[30]!==m||e[31]!==y?(K=s.jsx(B,{variant:"outline",size:"xs",className:"!font-normal",onClick:m,children:y}),e[30]=m,e[31]=y,e[32]=K):K=e[32];let C;e[33]!==A?(C=()=>A("overwrite"),e[33]=A,e[34]=C):C=e[34];let T;e[35]!==l?(T=l("settings.skills.catalog.conflicts.actions.overwriteAll"),e[35]=l,e[36]=T):T=e[36];let j;e[37]!==C||e[38]!==T?(j=s.jsx(B,{variant:"outline",size:"xs",className:"!font-normal",onClick:C,children:T}),e[37]=C,e[38]=T,e[39]=j):j=e[39];let R;e[40]!==K||e[41]!==j?(R=s.jsxs("div",{className:"flex items-center gap-2",children:[K,j]}),e[40]=K,e[41]=j,e[42]=R):R=e[42];let G;e[43]!==w||e[44]!==R?(G=s.jsxs("div",{className:"flex items-center justify-between gap-2",children:[w,R]}),e[43]=w,e[44]=R,e[45]=G):G=e[45];let S;if(e[46]!==i||e[47]!==d||e[48]!==l){let Z;e[50]!==d||e[51]!==l?(Z=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(Ot,{value:d[ne.skillName]||"skip",onValueChange:le=>x(re=>({...re,[ne.skillName]:le})),children:[s.jsx(Lt,{className:"w-fit",children:s.jsx("span",{className:"capitalize",children:(d[ne.skillName]||"skip")==="overwrite"?l("settings.skills.catalog.conflicts.decision.overwrite"):l("settings.skills.catalog.conflicts.decision.skip")})}),s.jsxs(Ft,{align:"end",children:[s.jsx(ut,{value:"skip",className:"pr-2 [&>span:first-child]:hidden",children:l("settings.skills.catalog.conflicts.decision.skip")}),s.jsx(ut,{value:"overwrite",className:"pr-2 [&>span:first-child]:hidden",children:l("settings.skills.catalog.conflicts.decision.overwrite")})]})]})]},ne.skillName),e[50]=d,e[51]=l,e[52]=Z):Z=e[52],S=i.map(Z),e[46]=i,e[47]=d,e[48]=l,e[49]=S}else S=e[49];let q;e[53]!==S?(q=s.jsx("div",{className:"space-y-2",children:S}),e[53]=S,e[54]=q):q=e[54];let Q;e[55]!==G||e[56]!==q?(Q=s.jsxs("div",{className:"space-y-3",children:[G,q]}),e[55]=G,e[56]=q,e[57]=Q):Q=e[57];let M;e[58]!==n?(M=()=>n(!1),e[58]=n,e[59]=M):M=e[59];let W;e[60]!==l?(W=l("settings.common.actions.cancel"),e[60]=l,e[61]=W):W=e[61];let Y;e[62]!==M||e[63]!==W?(Y=s.jsx(B,{size:"sm",variant:"ghost",onClick:M,children:W}),e[62]=M,e[63]=W,e[64]=Y):Y=e[64];let F;e[65]!==d||e[66]!==r?(F=()=>r(d),e[65]=d,e[66]=r,e[67]=F):F=e[67];const se=!P;let _;e[68]!==l?(_=l("settings.skills.catalog.conflicts.actions.continue"),e[68]=l,e[69]=_):_=e[69];let V;e[70]!==F||e[71]!==se||e[72]!==_?(V=s.jsx(B,{size:"sm",onClick:F,disabled:se,children:_}),e[70]=F,e[71]=se,e[72]=_,e[73]=V):V=e[73];let z;e[74]!==Y||e[75]!==V?(z=s.jsxs(ms,{children:[Y,V]}),e[74]=Y,e[75]=V,e[76]=z):z=e[76];let U;e[77]!==O||e[78]!==Q||e[79]!==z?(U=s.jsxs(_t,{className:"max-w-2xl",children:[O,Q,z]}),e[77]=O,e[78]=Q,e[79]=z,e[80]=U):U=e[80];let X;return e[81]!==n||e[82]!==a||e[83]!==U?(X=s.jsx(zt,{open:a,onOpenChange:n,children:U}),e[81]=n,e[82]=a,e[83]=U,e[84]=X):X=e[84],X},fr=[{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 Ma(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 Ml(t){if(t==="user-claude")return{scope:"user",source:"claude"};if(t==="project-claude")return{scope:"project",source:"claude"};const e=fr.find(a=>a.value===t);return e?{scope:e.scope,source:e.source}:{scope:"user",source:"opencode"}}const qm=t=>{const e=mt.c(124),{open:a,onOpenChange:n,item:i}=t,{t:r}=ot(),l=ln(Wm),h=ln(Jm),[d,x]=o.useState("user"),[c,v]=o.useState("opencode"),p=Qs(Qm),A=Qs(Ym),[b,P]=o.useState(null),[N,k]=o.useState(!1);let g;e[0]===Symbol.for("react.memo_cache_sentinel")?(g=[],e[0]=g):g=e[0];const[E,O]=o.useState(g),[I,w]=o.useState(null);let m,y;e[1]!==A||e[2]!==a?(m=()=>{a&&(x("user"),v("opencode"),P(A),k(!1),O([]),w(null))},y=[a,A],e[1]=A,e[2]=a,e[3]=m,e[4]=y):(m=e[3],y=e[4]),o.useEffect(m,y);let K;e[5]!==r?(K=ve=>{switch(ve){case"project-opencode":return r("settings.skills.location.option.projectOpencode.label");case"user-agents":return r("settings.skills.location.option.userAgents.label");case"project-agents":return r("settings.skills.location.option.projectAgents.label");default:return r("settings.skills.location.option.userOpencode.label")}},e[5]=r,e[6]=K):K=e[6];const C=K;let T;e[7]!==r?(T=ve=>{switch(ve){case"project-opencode":return r("settings.skills.location.option.projectOpencode.description");case"user-agents":return r("settings.skills.location.option.userAgents.description");case"project-agents":return r("settings.skills.location.option.projectAgents.description");default:return r("settings.skills.location.option.userOpencode.description")}},e[7]=r,e[8]=T):T=e[8];const j=T;let R;e:{if(p.length===0){R=null;break e}if(b&&p.some(ve=>ve.id===b)){R=b;break e}if(A&&p.some(ve=>ve.id===A)){R=A;break e}R=p[0]?.id??null}const G=R;let S;e:{if(d!=="project"){S=null;break e}const ve=G;if(!ve){S=null;break e}let We;if(e[9]!==ve||e[10]!==p){let de;e[12]!==ve?(de=ue=>ue.id===ve,e[12]=ve,e[13]=de):de=e[13],We=p.find(de),e[9]=ve,e[10]=p,e[11]=We}else We=e[11];S=We?.path??null}const q=S;let Q;e[14]!==l||e[15]!==i?.gitIdentityId||e[16]!==n||e[17]!==r?(Q=async ve=>{const We=await l({source:ve.source,subpath:ve.subpath,gitIdentityId:i?.gitIdentityId,scope:ve.scope,targetSource:ve.targetSource,selections:[{skillDir:ve.skillDir}],conflictPolicy:"prompt",conflictDecisions:ve.conflictDecisions},{directory:ve.directoryOverride??null});if(We.ok){D.success(r("settings.skills.catalog.installSkill.toast.installed")),n(!1);return}if(We.error?.kind==="conflicts"){w({source:ve.source,subpath:ve.subpath,scope:ve.scope,targetSource:ve.targetSource,skillDir:ve.skillDir,directoryOverride:ve.directoryOverride??null}),O(We.error.conflicts),k(!0);return}if(We.error?.kind==="authRequired"){D.error(We.error.message||r("settings.skills.catalog.installSkill.toast.authRequired"));return}D.error(We.error?.message||r("settings.skills.catalog.installSkill.toast.installFailed"))},e[14]=l,e[15]=i?.gitIdentityId,e[16]=n,e[17]=r,e[18]=Q):Q=e[18];const M=Q;if(!i)return null;let W;e[19]!==r?(W=r("settings.skills.catalog.installSkill.title"),e[19]=r,e[20]=W):W=e[20];let Y;e[21]!==W?(Y=s.jsx(qt,{children:W}),e[21]=W,e[22]=Y):Y=e[22];let F;e[23]!==r?(F=r("settings.skills.catalog.installSkill.descriptionPrefix"),e[23]=r,e[24]=F):F=e[24];let se;e[25]!==i.skillName?(se=s.jsx("span",{className:"font-semibold text-foreground",children:i.skillName}),e[25]=i.skillName,e[26]=se):se=e[26];let _;e[27]!==r?(_=r("settings.skills.catalog.installSkill.descriptionSuffix"),e[27]=r,e[28]=_):_=e[28];let V;e[29]!==F||e[30]!==se||e[31]!==_?(V=s.jsxs(Wt,{children:[F," ",se," ",_]}),e[29]=F,e[30]=se,e[31]=_,e[32]=V):V=e[32];let z;e[33]!==Y||e[34]!==V?(z=s.jsxs(Gt,{children:[Y,V]}),e[33]=Y,e[34]=V,e[35]=z):z=e[35];let U;e[36]!==r?(U=r("settings.skills.catalog.installSkill.field.destination"),e[36]=r,e[37]=U):U=e[37];let X;e[38]!==U?(X=s.jsx("span",{className:"typography-ui-label text-foreground",children:U}),e[38]=U,e[39]=X):X=e[39];let Z;e[40]!==d||e[41]!==c?(Z=Ma(d,c),e[40]=d,e[41]=c,e[42]=Z):Z=e[42];let ne;e[43]===Symbol.for("react.memo_cache_sentinel")?(ne=ve=>{const We=Ml(ve);x(We.scope),v(We.source==="agents"?"agents":"opencode")},e[43]=ne):ne=e[43];let le;e[44]!==d?(le=d==="user"?s.jsx(L,{name:"user-3",className:"h-3.5 w-3.5"}):s.jsx(L,{name:"folder",className:"h-3.5 w-3.5"}),e[44]=d,e[45]=le):le=e[45];let re;e[46]!==c?(re=c==="agents"?s.jsx(L,{name:"robot-2",className:"h-3.5 w-3.5"}):null,e[46]=c,e[47]=re):re=e[47];let fe;e[48]!==C||e[49]!==d||e[50]!==c?(fe=C(Ma(d,c)),e[48]=C,e[49]=d,e[50]=c,e[51]=fe):fe=e[51];let ae;e[52]!==fe?(ae=s.jsx("span",{children:fe}),e[52]=fe,e[53]=ae):ae=e[53];let ie;e[54]!==le||e[55]!==re||e[56]!==ae?(ie=s.jsxs(Lt,{className:"w-fit gap-1.5",children:[le,re,ae]}),e[54]=le,e[55]=re,e[56]=ae,e[57]=ie):ie=e[57];let te;e[58]!==j||e[59]!==C?(te=fr.map(ve=>s.jsx(ut,{value:ve.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:[ve.scope==="user"?s.jsx(L,{name:"user-3",className:"h-3.5 w-3.5"}):s.jsx(L,{name:"folder",className:"h-3.5 w-3.5"}),ve.source==="agents"?s.jsx(L,{name:"robot-2",className:"h-3.5 w-3.5"}):null,s.jsx("span",{children:C(ve.value)})]}),s.jsx("span",{className:"typography-micro text-muted-foreground ml-5",children:j(ve.value)})]})},ve.value)),e[58]=j,e[59]=C,e[60]=te):te=e[60];let ye;e[61]!==te?(ye=s.jsx(Ft,{align:"start",children:te}),e[61]=te,e[62]=ye):ye=e[62];let we;e[63]!==Z||e[64]!==ie||e[65]!==ye?(we=s.jsxs(Ot,{value:Z,onValueChange:ne,children:[ie,ye]}),e[63]=Z,e[64]=ie,e[65]=ye,e[66]=we):we=e[66];let ke;e[67]!==X||e[68]!==we?(ke=s.jsxs("div",{className:"flex flex-wrap items-center gap-2",children:[X,we]}),e[67]=X,e[68]=we,e[69]=ke):ke=e[69];let xe;e[70]!==p||e[71]!==G||e[72]!==d||e[73]!==r?(xe=d==="project"&&s.jsxs("div",{className:"flex flex-wrap items-center gap-2",children:[s.jsx("span",{className:"typography-ui-label text-foreground",children:r("settings.skills.catalog.installSkill.field.project")}),p.length===0?s.jsx("span",{className:"typography-meta text-muted-foreground",children:r("settings.skills.catalog.installSkill.field.noProjects")}):s.jsxs(Ot,{value:G??"",onValueChange:ve=>P(ve),disabled:p.length===1,children:[s.jsx(Lt,{className:"w-fit",children:s.jsx(Ht,{placeholder:r("settings.skills.catalog.installSkill.field.chooseProjectPlaceholder")})}),s.jsx(Ft,{align:"start",children:p.map(Zm)})]})]}),e[70]=p,e[71]=G,e[72]=d,e[73]=r,e[74]=xe):xe=e[74];let De;e[75]!==i.warnings?(De=i.warnings?.length?s.jsx("div",{className:"typography-micro text-[var(--status-warning)] bg-[var(--status-warning)]/10 px-2 py-1.5 rounded",children:i.warnings.join(" · ")}):null,e[75]=i.warnings,e[76]=De):De=e[76];let Me;e[77]!==ke||e[78]!==xe||e[79]!==De?(Me=s.jsxs("div",{className:"mt-2 space-y-3",children:[ke,xe,De]}),e[77]=ke,e[78]=xe,e[79]=De,e[80]=Me):Me=e[80];let he;e[81]!==n?(he=()=>n(!1),e[81]=n,e[82]=he):he=e[82];let ge;e[83]!==r?(ge=r("settings.common.actions.cancel"),e[83]=r,e[84]=ge):ge=e[84];let Ae;e[85]!==he||e[86]!==ge?(Ae=s.jsx(B,{size:"sm",variant:"ghost",onClick:he,children:ge}),e[85]=he,e[86]=ge,e[87]=Ae):Ae=e[87];const Ve=h||!i.installable||d==="project"&&!q;let _e;e[88]!==q||e[89]!==M||e[90]!==i.repoSource||e[91]!==i.repoSubpath||e[92]!==i.skillDir||e[93]!==d||e[94]!==c?(_e=()=>{M({source:i.repoSource,subpath:i.repoSubpath,scope:d,targetSource:c,skillDir:i.skillDir,directoryOverride:q})},e[88]=q,e[89]=M,e[90]=i.repoSource,e[91]=i.repoSubpath,e[92]=i.skillDir,e[93]=d,e[94]=c,e[95]=_e):_e=e[95];let Le;e[96]!==h||e[97]!==r?(Le=r(h?"settings.skills.catalog.installSkill.actions.installing":"settings.skills.catalog.installSkill.actions.install"),e[96]=h,e[97]=r,e[98]=Le):Le=e[98];let Re;e[99]!==Ve||e[100]!==_e||e[101]!==Le?(Re=s.jsx(B,{size:"sm",disabled:Ve,onClick:_e,children:Le}),e[99]=Ve,e[100]=_e,e[101]=Le,e[102]=Re):Re=e[102];let Ze;e[103]!==Ae||e[104]!==Re?(Ze=s.jsxs(ms,{children:[Ae,Re]}),e[103]=Ae,e[104]=Re,e[105]=Ze):Ze=e[105];let Ge;e[106]!==z||e[107]!==Me||e[108]!==Ze?(Ge=s.jsxs(_t,{className:"max-w-md",children:[z,Me,Ze]}),e[106]=z,e[107]=Me,e[108]=Ze,e[109]=Ge):Ge=e[109];let Oe;e[110]!==n||e[111]!==a||e[112]!==Ge?(Oe=s.jsx(zt,{open:a,onOpenChange:n,children:Ge}),e[110]=n,e[111]=a,e[112]=Ge,e[113]=Oe):Oe=e[113];let Ke;e[114]!==I||e[115]!==M?(Ke=ve=>{I&&(M({source:I.source,subpath:I.subpath,scope:I.scope,targetSource:I.targetSource,skillDir:I.skillDir,conflictDecisions:ve,directoryOverride:I.directoryOverride??null}),k(!1))},e[114]=I,e[115]=M,e[116]=Ke):Ke=e[116];let Pe;e[117]!==E||e[118]!==N||e[119]!==Ke?(Pe=s.jsx(Gm,{open:N,onOpenChange:k,conflicts:E,onConfirm:Ke}),e[117]=E,e[118]=N,e[119]=Ke,e[120]=Pe):Pe=e[120];let Ue;return e[121]!==Oe||e[122]!==Pe?(Ue=s.jsxs(s.Fragment,{children:[Oe,Pe]}),e[121]=Oe,e[122]=Pe,e[123]=Ue):Ue=e[123],Ue};function Wm(t){return t.installSkills}function Jm(t){return t.isInstalling}function Qm(t){return t.projects}function Ym(t){return t.activeProjectId}function Zm(t){return s.jsx(ut,{value:t.id,children:t.label||t.path},t.id)}const Xm=/^[A-Za-z0-9_.-]+\/[A-Za-z0-9_.-]+$/,eu=t=>{const e=t.trim();return Xm.test(e)?`https://github.com/${e}`:null},tu=t=>{const e=eu(t.repoSource);if(!e)return null;const a=[t.repoSubpath,t.skillDir].filter(Boolean).join("/");return a?`${e}/tree/HEAD/${a}`:e};let Qa=null;const su=t=>{const e=ur();return(!Qa||Qa.locale!==e)&&(Qa={locale:e,formatter:new Intl.NumberFormat(e,{notation:"compact"})}),Qa.formatter.format(t)},nu=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 i=Math.floor(n/60);if(i<24)return{key:"common.relative.hoursAgoShort",count:i};const r=Math.floor(i/24);if(r<7)return{key:"common.relative.daysAgoShort",count:r};const l=Math.floor(r/7);return l<52?{key:"common.relative.weeksAgoShort",count:l}:{key:"common.relative.yearsAgoShort",count:Math.floor(r/365)}},au=async()=>{try{const t=In()?.settings;if(t)return(await t.load())?.settings||{};const e=await pt("/api/config/settings",{method:"GET",headers:{Accept:"application/json"}});return e.ok?await e.json().catch(()=>null):null}catch{return null}},iu=t=>{const e=mt.c(50),{source:a,isActive:n,isLoading:i,skillsCount:r,onSelect:l,t:h}=t,d=a.stars??null;let x,c,v,p,A,b,P,N,k,g;if(e[0]!==n||e[1]!==i||e[2]!==l||e[3]!==r||e[4]!==a.label||e[5]!==a.repoUpdatedAt||e[6]!==a.source||e[7]!==d||e[8]!==h){const w=a.repoUpdatedAt?nu(a.repoUpdatedAt):null;N="button",k=l,g=n;const m=n?"border-primary":"border-[var(--surface-subtle)] hover:border-[var(--interactive-border-hover)]";e[19]!==m?(c=je("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",m),e[19]=m,e[20]=c):c=e[20],A="min-w-0 flex-1 block";let y;e[21]!==a.label?(y=s.jsx("span",{className:"typography-ui-label font-medium text-foreground truncate",children:a.label}),e[21]=a.label,e[22]=y):y=e[22];let K;e[23]!==i||e[24]!==r||e[25]!==h?(K=i?s.jsx(L,{name:"refresh",className:"h-3 w-3 animate-spin text-muted-foreground shrink-0"}):r!==null&&s.jsx("span",{className:"typography-micro text-muted-foreground shrink-0",children:h("settings.skills.catalog.page.source.skillsCount",{count:r})}),e[23]=i,e[24]=r,e[25]=h,e[26]=K):K=e[26],e[27]!==y||e[28]!==K?(b=s.jsxs("span",{className:"flex items-center gap-2",children:[y,K]}),e[27]=y,e[28]=K,e[29]=b):b=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],x="flex items-center gap-3 mt-1",e[32]!==d||e[33]!==h?(v=d!==null&&s.jsxs("span",{className:"typography-micro text-muted-foreground flex items-center gap-1",title:h("settings.skills.catalog.page.source.stars",{count:d}),children:[s.jsx(L,{name:"star",className:"h-3 w-3"}),su(d)]}),e[32]=d,e[33]=h,e[34]=v):v=e[34],p=w&&s.jsx("span",{className:"typography-micro text-muted-foreground",children:w.key==="common.relative.justNow"?h(w.key):h("settings.skills.catalog.page.source.updated",{time:h(w.key,{count:w.count})})}),e[0]=n,e[1]=i,e[2]=l,e[3]=r,e[4]=a.label,e[5]=a.repoUpdatedAt,e[6]=a.source,e[7]=d,e[8]=h,e[9]=x,e[10]=c,e[11]=v,e[12]=p,e[13]=A,e[14]=b,e[15]=P,e[16]=N,e[17]=k,e[18]=g}else x=e[9],c=e[10],v=e[11],p=e[12],A=e[13],b=e[14],P=e[15],N=e[16],k=e[17],g=e[18];let E;e[35]!==x||e[36]!==v||e[37]!==p?(E=s.jsxs("span",{className:x,children:[v,p]}),e[35]=x,e[36]=v,e[37]=p,e[38]=E):E=e[38];let O;e[39]!==E||e[40]!==A||e[41]!==b||e[42]!==P?(O=s.jsxs("span",{className:A,children:[b,P,E]}),e[39]=E,e[40]=A,e[41]=b,e[42]=P,e[43]=O):O=e[43];let I;return e[44]!==c||e[45]!==O||e[46]!==N||e[47]!==k||e[48]!==g?(I=s.jsx("button",{type:N,onClick:k,"aria-pressed":g,className:c,children:O}),e[44]=c,e[45]=O,e[46]=N,e[47]=k,e[48]=g,e[49]=I):I=e[49],I},ru=({mode:t,onModeChange:e,showModeTabs:a=!0})=>{const{t:n}=ot(),{sources:i,itemsBySource:r,selectedSourceId:l,setSelectedSource:h,loadCatalog:d,loadSource:x,isLoadingCatalog:c,isLoadingSource:v,loadedSourceIds:p,lastCatalogError:A}=ln(Ms(M=>({sources:M.sources,itemsBySource:M.itemsBySource,selectedSourceId:M.selectedSourceId,setSelectedSource:M.setSelectedSource,loadCatalog:M.loadCatalog,loadSource:M.loadSource,isLoadingCatalog:M.isLoadingCatalog,isLoadingSource:M.isLoadingSource,loadedSourceIds:M.loadedSourceIds,lastCatalogError:M.lastCatalogError}))),[b,P]=o.useState(""),[N,k]=o.useState(!1),[g,E]=o.useState(!1),[O,I]=o.useState(null),[w,m]=o.useState(!1),[y,K]=o.useState(!1),C=o.useRef(null);o.useEffect(()=>{d()},[d]),o.useEffect(()=>{const M=i.filter(F=>!p[F.id]);if(M.length===0)return;let W=!1;return(async()=>{for(const F of M){if(W)return;await x(F.id)}})(),()=>{W=!0}},[i,p,x]),o.useEffect(()=>{!l||p[l]||x(l)},[l,p,x]),o.useEffect(()=>{const M=W=>{(W.metaKey||W.ctrlKey)&&W.key.toLowerCase()==="k"&&(W.preventDefault(),C.current?.focus())};return window.addEventListener("keydown",M),()=>window.removeEventListener("keydown",M)},[]);const T=b.trim().length>0,j=o.useMemo(()=>T?ri(i.flatMap(M=>r[M.id]||[]),b,M=>[M.skillName,M.frontmatterName,M.description]):l?r[l]||[]:[],[i,r,l,b,T]),R=o.useMemo(()=>i.find(M=>M.id===l)||null,[i,l]),G=!!(l&&l.startsWith("custom:")),S=async()=>{if(!(!l||!G)){m(!0);try{const M=await au(),Y=(Array.isArray(M?.skillCatalogs)?M?.skillCatalogs:[]).filter(F=>F.id!==l);await Nt({skillCatalogs:Y}),await d({refresh:!0}),K(!1)}finally{m(!1)}}},q=T?n("settings.skills.catalog.page.list.searchTitle"):R?.label??"",Q=!T&&l!==null&&!p[l]&&(v||c);return s.jsxs(s.Fragment,{children:[s.jsxs(gs,{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(hr,{items:[{id:"manual",label:n("settings.skills.catalog.page.mode.manual")},{id:"external",label:n("settings.skills.catalog.page.mode.external")}],activeId:t,onSelect:M=>e(M),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(L,{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(Ye,{ref:C,value:b,onChange:M=>P(M.target.value),placeholder:n("settings.skills.catalog.page.searchAllPlaceholder"),className:je("h-8 pl-8 w-full",b&&"pr-8")}),b&&s.jsx("button",{type:"button",onClick:()=>{P(""),C.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(L,{name:"close",className:"h-3 w-3"})})]})}),s.jsx(Be,{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:[i.map(M=>s.jsx(iu,{source:M,isActive:M.id===l,isLoading:v&&!p[M.id],skillsCount:p[M.id]?(r[M.id]||[]).length:null,onSelect:()=>h(M.id),t:n},M.id)),s.jsxs("button",{type:"button","data-settings-item":"skills.catalog.add-catalog",onClick:()=>k(!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(L,{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")})]})]})]})}),A&&s.jsx(Be,{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:A.message})]})}),s.jsxs(Be,{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:q}),s.jsx("span",{className:"typography-micro text-muted-foreground/70 shrink-0",children:n("settings.skills.catalog.page.foundCount",{count:j.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&&!T?x(l,{refresh:!0}):d({refresh:!0})},disabled:c||v,title:n("settings.skills.catalog.page.actions.refreshTitle"),children:s.jsx(L,{name:"refresh",className:je("h-3.5 w-3.5",(c||v)&&"animate-spin")})}),G&&!T&&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:()=>K(!0),disabled:w,title:n("settings.skills.catalog.page.actions.removeCatalogTitle"),children:s.jsx(L,{name:"delete-bin",className:"h-3.5 w-3.5"})})]})]}),Q||v&&j.length===0?s.jsxs("div",{className:"py-8 text-center text-muted-foreground",children:[s.jsx(L,{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")})]}):j.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:j.map(M=>{const W=M.installed?.isInstalled,Y=M.installed?.scope,F=tu(M);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:M.skillName}),W&&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:Y||n("settings.skills.catalog.page.badge.unknown")})}),!M.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")})]}),M.description?s.jsx("div",{className:"typography-meta text-muted-foreground mt-0.5 line-clamp-2",children:M.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:[F?s.jsxs("a",{href:F,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(L,{name:"github",className:"h-3 w-3 shrink-0"}),M.repoSource]}):s.jsx("span",{className:"font-mono truncate",children:M.repoSource}),M.skillDir&&s.jsxs(s.Fragment,{children:[s.jsx("span",{className:"opacity-40",children:"·"}),s.jsx("span",{className:"truncate",children:M.skillDir})]})]}),M.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:M.warnings.join(" · ")}):null]}),s.jsxs("div",{className:"flex items-center gap-1.5 shrink-0",children:[F&&s.jsx(B,{variant:"ghost",size:"xs",className:"!font-normal h-6 w-6 px-0",onClick:()=>window.open(F,"_blank","noreferrer"),title:n("settings.skills.catalog.page.skill.viewOnGithub"),children:s.jsx(L,{name:"external-link",className:"h-3.5 w-3.5"})}),W?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:Y||""}),children:s.jsx(L,{name:"check",className:"h-4 w-4"})}):s.jsx(B,{variant:"outline",size:"xs",className:"!font-normal",disabled:!M.installable,onClick:()=>{I(M),E(!0)},children:n("settings.skills.catalog.shared.actions.install")})]})]})},`${M.sourceId}:${M.skillDir}`)})})]})]}),s.jsx(Fm,{open:N,onOpenChange:k}),s.jsx(qm,{open:g,onOpenChange:E,item:O}),s.jsx(zt,{open:y,onOpenChange:M=>{w||K(M)},children:s.jsxs(_t,{className:"max-w-md",children:[s.jsxs(Gt,{children:[s.jsx(qt,{children:n("settings.skills.catalog.page.removeDialog.title")}),s.jsx(Wt,{children:n("settings.skills.catalog.page.removeDialog.description")})]}),s.jsxs(ms,{children:[s.jsx(B,{size:"sm",variant:"ghost",onClick:()=>K(!1),disabled:w,children:n("settings.common.actions.cancel")}),s.jsx(B,{size:"sm",variant:"destructive",onClick:()=>{S()},disabled:w,children:n("settings.skills.catalog.page.actions.removeCatalog")})]})]})})]})},ou=()=>{const t=mt.c(1);let e;return t[0]===Symbol.for("react.memo_cache_sentinel")?(e=s.jsx(ru,{mode:"external",onModeChange:uu,showModeTabs:!1}),t[0]=e):e=t[0],e},lu="SKILL.md",cu="h-[clamp(320px,58dvh,680px)] min-h-[260px] max-h-[calc(100dvh-220px)]",si=(t,e)=>{const a=Od({description:t}).trimEnd(),n=e.trimStart();return`---
|
|
22
|
-
${a}
|
|
23
|
-
---${n?`
|
|
24
|
-
|
|
25
|
-
${n}`:`
|
|
26
|
-
`}`},du=t=>typeof t=="object"&&t!==null&&!Array.isArray(t),Rl=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=Ld(e[1]);if(du(n)){const i=n.description;typeof i=="string"&&(a=i)}}catch{a=null}return{description:a,instructions:e[2].replace(/^\r?\n/,"")}},pu=(t,e)=>{const a=Rl(t);return si(e,a.instructions)},mu=()=>{const{t}=ot(),{currentTheme:e}=gr(),{selectedSkillName:a,getSkillByName:n,getSkillDetail:i,createSkill:r,updateSkill:l,skillDraft:h,setSkillDraft:d,setSelectedSkill:x}=$s(Ms($=>({selectedSkillName:$.selectedSkillName,getSkillByName:$.getSkillByName,getSkillDetail:$.getSkillDetail,createSkill:$.createSkill,updateSkill:$.updateSkill,skillDraft:$.skillDraft,setSkillDraft:$.setSkillDraft,setSelectedSkill:$.setSelectedSkill}))),c=Us(),v=$s($=>cr($,c)),p=a?n(a,c):null,A=!!(h&&h.name===a&&!p),b=!!(a&&!p&&!h),P=p?.path==="<built-in>";o.useEffect(()=>{b&&x(null)},[b,x]);const[N,k]=o.useState(""),[g,E]=o.useState("user"),[O,I]=o.useState("opencode"),[w,m]=o.useState(""),[y,K]=o.useState(""),[C,T]=o.useState(()=>si("","")),[j,R]=o.useState("edit"),[G,S]=o.useState([]),[q,Q]=o.useState([]),[M,W]=o.useState(!1),[Y,F]=o.useState(!1),[se,_]=o.useState(""),[V,z]=o.useState(""),[U,X]=o.useState(!1),[Z,ne]=o.useState(""),[le,re]=o.useState(""),[fe,ae]=o.useState(null),[ie,te]=o.useState(!1),[ye,we]=o.useState(""),[ke,xe]=o.useState(null),[De,Me]=o.useState(!1),he=A?N.trim()!==""||w.trim()!==""||y.trim()!==""||q.length>0:w!==se||y!==V,ge=fe?le!==ye:Z.trim()!=="",Ae=o.useCallback($=>{switch($){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]),Ve=o.useCallback($=>{switch($){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(A&&h){const de=h.description||"",ue=h.instructions||"";k(h.name||""),E(h.scope||"user"),I(h.source==="agents"?"agents":"opencode"),m(de),K(ue),T(si(de,ue)),_(""),z(""),S([]),Q(h.pendingFiles||[])}else if(a&&p){F(!0);try{const de=await i(a,c);if(de){const ue=de.sources.md,Ne=ue.description||"",pe=ue.instructions||"";m(Ne),K(pe),T(si(Ne,pe)),_(Ne),z(pe),S(ue.supportingFiles||[])}}catch(de){console.error("Failed to load skill details:",de)}finally{F(!1)}}})()},[p,A,a,c,v,h,i]);const _e=ce($=>$.editorFontSize),Le=o.useMemo(()=>{const $=[Gr(e,{fontSize:_e})],de=Pr(lu);return de&&$.push(de),$.push(Wr.lineWrapping),$},[e,_e]),Re=o.useMemo(()=>{const $=Z.trim()||"supporting-file.md",de=mc($),ue=!!de&&de!=="markdown",Ne=[Gr(e,ue?{syntaxColors:!1,fontSize:_e}:{fontSize:_e})],pe=Pr($);return pe&&Ne.push(pe),ue&&de&&Ne.push(Fd({language:de,themeName:e.metadata.id,theme:Ud(e)})),Ne.push(Wr.lineWrapping),Ne},[e,Z,_e]),Ze=o.useCallback($=>{m($),T(de=>pu(de,$))},[]),Ge=o.useCallback($=>{T($);const de=Rl($);m(de.description??""),K(de.instructions)},[]),Oe=async()=>{const $=A?N.trim().replace(/\s+/g,"-").toLowerCase():a?.trim();if(!$){D.error(t("settings.skills.page.toast.skillNameRequired"));return}if(!/^[a-z0-9][a-z0-9-]*[a-z0-9]$|^[a-z0-9]$/.test($)||$.length>64){D.error(t("settings.skills.page.toast.invalidSkillName"));return}if(!w.trim()){D.error(t("settings.skills.page.toast.descriptionRequired"));return}if(A&&v.some(de=>de.name===$)){D.error(t("settings.skills.page.toast.skillExists"));return}W(!0);try{const de={name:$,description:w.trim(),instructions:y.trim()||void 0,scope:A?g:void 0,source:A?O:void 0,targetPath:A?void 0:p?.path,supportingFiles:A&&q.length>0?q:void 0};let ue;if(A?(ue=await r(de,c),ue&&(d(null),Q([]),x($))):(ue=await l($,de,c),ue&&(_(w.trim()),z(y.trim()))),ue){const Ne=dn.getState().changes.some(pe=>pe.scope==="skills"&&pe.id.startsWith(`skills:${$}:`));D.success(t(Ne?"settings.view.pendingRestart.saved":A?"settings.skills.page.toast.skillCreated":"settings.skills.page.toast.skillUpdated"))}else D.error(t(A?"settings.skills.page.toast.createSkillFailed":"settings.skills.page.toast.updateSkillFailed"))}catch(de){console.error("Error saving skill:",de),D.error(t("settings.skills.page.toast.saveUnexpectedError"))}finally{W(!1)}},Ke=()=>{ae(null),ne(""),re(""),we(""),X(!0)},Pe=async $=>{if(ae($),ne($),A){const ue=q.find(Ne=>Ne.path===$)?.content||"";re(ue),we(ue),X(!0);return}if(a){te(!0),X(!0);try{const{readSupportingFile:de}=$s.getState(),ue=await de(a,$,c);re(ue||""),we(ue||"")}catch{D.error(t("settings.skills.page.toast.loadFileContentFailed")),re(""),we("")}finally{te(!1)}}},Ue=async()=>{if(!Z.trim()){D.error(t("settings.skills.page.toast.fileNameRequired"));return}const $=Z.trim(),de=fe!==null;if(A){if(de)Q(pe=>pe.map(Fe=>Fe.path===fe?{path:$,content:le}:Fe)),D.success(t("settings.skills.page.toast.fileUpdated",{path:$}));else{if(q.some(pe=>pe.path===$)){D.error(t("settings.skills.page.toast.fileExists"));return}Q(pe=>[...pe,{path:$,content:le}]),D.success(t("settings.skills.page.toast.fileAdded",{path:$}))}X(!1),ae(null);return}if(!a){D.error(t("settings.skills.page.toast.noSkillSelected"));return}const{writeSupportingFile:ue}=$s.getState();if(await ue(a,$,le,c)){D.success(de?t("settings.skills.page.toast.fileUpdated",{path:$}):t("settings.skills.page.toast.fileCreated",{path:$})),X(!1),ae(null);const pe=await i(a,c);pe&&S(pe.sources.md.supportingFiles||[])}else D.error(t(de?"settings.skills.page.toast.updateFileFailed":"settings.skills.page.toast.createFileFailed"))},ve=$=>{if(A){Q(de=>de.filter(ue=>ue.path!==$)),D.success(t("settings.skills.page.toast.fileRemoved",{path:$}));return}a&&xe($)},We=async()=>{if(!ke||!a)return;Me(!0);const{deleteSupportingFile:$}=$s.getState();if(await $(a,ke,c)){D.success(t("settings.skills.page.toast.fileDeleted",{path:ke}));const ue=await i(a,c);ue&&S(ue.sources.md.supportingFiles||[]),xe(null)}else D.error(t("settings.skills.page.toast.deleteFileFailed"));Me(!1)};return!a&&!h||b?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(L,{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")})]})}):Y?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(gs,{title:A?t("settings.skills.page.title.newSkill"):a,description:p?t("settings.skills.page.subtitle.skillLocation",{location:Ae(Ma(p.scope,p.source))}):t("settings.skills.page.subtitle.newSkill"),showSaveStatus:!1,children:[s.jsxs(Be,{title:t("settings.skills.page.section.basicInformation"),divider:!1,settingsItem:"skills.basic-information",contentClassName:"space-y-0",children:[A&&s.jsxs(Qt,{label:t("settings.skills.page.field.skillNameLocation"),info:t("settings.skills.page.field.skillNameHint"),children:[s.jsx(Ye,{value:N,onChange:$=>k($.target.value.toLowerCase().replace(/\s+/g,"-")),placeholder:t("settings.skills.page.field.skillNamePlaceholder"),className:"h-7 w-40 px-2"}),s.jsxs(Ot,{value:Ma(g,O),onValueChange:$=>{const de=Ml($);E(de.scope),I(de.source==="agents"?"agents":"opencode")},children:[s.jsxs(Lt,{size:Jt,className:"w-fit gap-1.5",children:[g==="user"?s.jsx(L,{name:"user-3",className:"h-3.5 w-3.5"}):s.jsx(L,{name:"folder",className:"h-3.5 w-3.5"}),O==="agents"?s.jsx(L,{name:"robot-2",className:"h-3.5 w-3.5"}):null,s.jsx("span",{children:Ae(Ma(g,O))})]}),s.jsx(Ft,{align:"start",children:fr.map($=>s.jsx(ut,{value:$.value,children:s.jsxs("div",{className:"flex flex-col gap-0.5",children:[s.jsxs("div",{className:"flex items-center gap-2",children:[$.scope==="user"?s.jsx(L,{name:"user-3",className:"h-3.5 w-3.5"}):s.jsx(L,{name:"folder",className:"h-3.5 w-3.5"}),$.source==="agents"?s.jsx(L,{name:"robot-2",className:"h-3.5 w-3.5"}):null,s.jsx("span",{children:Ae($.value)})]}),s.jsx("span",{className:"typography-micro text-muted-foreground ml-6",children:Ve($.value)})]})},$.value))})]})]}),s.jsx(es,{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(Es,{value:w,onChange:$=>Ze($.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(Be,{title:t("settings.skills.page.section.instructions"),headerAction:s.jsx(Kd,{currentMode:j==="preview"?"preview":"edit",onToggle:()=>R($=>$==="preview"?"edit":"preview")}),settingsItem:"skills.instructions",children:s.jsx("div",{className:je("overflow-hidden rounded-md border border-[var(--surface-subtle)] bg-background",cu),children:j==="preview"?s.jsx(Vs,{outerClassName:"h-full",className:"h-full",children:s.jsx("div",{className:"min-h-full px-4 py-3",children:s.jsx(uc,{content:C,className:"typography-markdown-body",stripFrontmatter:!0,enableFileReferences:!1})})}):s.jsx(qr,{value:C,onChange:Ge,readOnly:P,extensions:Le,className:"h-full",enableSearch:!0})})}),s.jsx(Be,{title:t("settings.skills.page.section.supportingFiles"),headerAction:s.jsxs(B,{variant:"outline",size:"xs",className:"!font-normal gap-1",onClick:Ke,disabled:P,children:[s.jsx(L,{name:"add",className:"h-3.5 w-3.5"})," ",t("settings.skills.page.actions.addFile")]}),settingsItem:"skills.supporting-files",children:(()=>{const $=A?q:G;return $.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:$.map(de=>s.jsxs("div",{className:"flex items-center gap-2 py-1.5 cursor-pointer group",onClick:()=>Pe(de.path),children:[s.jsx(L,{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:de.path}),A&&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:ue=>{ue.stopPropagation(),ve(de.path)},children:s.jsx(L,{name:"delete-bin",className:"h-3 w-3"})})]},de.path))})})()}),s.jsx(Be,{children:s.jsx(B,{onClick:Oe,disabled:P||M||!he,size:"xs",className:"!font-normal",children:t(M?"settings.common.actions.saving":A?"settings.skills.page.actions.createSkill":"settings.common.actions.saveChanges")})})]}),s.jsx(zt,{open:ke!==null,onOpenChange:$=>{!$&&!De&&xe(null)},children:s.jsxs(_t,{className:"max-w-md",children:[s.jsxs(Gt,{children:[s.jsx(qt,{children:t("settings.skills.page.deleteFileDialog.title")}),s.jsx(Wt,{children:t("settings.skills.page.deleteFileDialog.description",{path:ke??""})})]}),s.jsxs(ms,{children:[s.jsx(B,{size:"sm",variant:"ghost",onClick:()=>xe(null),disabled:De,children:t("settings.common.actions.cancel")}),s.jsx(B,{size:"sm",variant:"destructive",onClick:We,disabled:De,children:t("settings.common.actions.delete")})]})]})}),s.jsx(zt,{open:U,onOpenChange:$=>{X($),$||ae(null)},children:s.jsxs(_t,{className:"max-w-3xl max-h-[85vh] flex flex-col",children:[s.jsxs(Gt,{className:"flex-shrink-0",children:[s.jsx(qt,{children:t(fe?"settings.skills.page.fileDialog.titleEdit":"settings.skills.page.fileDialog.titleAdd")}),s.jsx(Wt,{children:t(fe?"settings.skills.page.fileDialog.descriptionEdit":"settings.skills.page.fileDialog.descriptionAdd")})]}),ie?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:Rt,children:t("settings.skills.page.fileDialog.field.filePath")}),!fe&&s.jsx(ss,{children:t("settings.skills.page.fileDialog.field.filePathHint")})]}),s.jsx(Ye,{value:Z,onChange:$=>ne($.target.value),placeholder:t("settings.skills.page.fileDialog.field.filePathPlaceholder"),className:"text-foreground placeholder:text-muted-foreground focus-visible:ring-[var(--primary-base)]",disabled:fe!==null})]}),s.jsxs("div",{className:"space-y-2 flex-1 min-h-0 flex flex-col",children:[s.jsx("label",{className:`${Rt} 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(qr,{value:le,onChange:re,extensions:Re,className:"h-full",enableSearch:!0})})]})]}),s.jsxs(ms,{className:"mt-4",children:[s.jsx(B,{size:"sm",variant:"ghost",onClick:()=>{X(!1),ae(null)},children:t("settings.common.actions.cancel")}),s.jsx(B,{size:"sm",onClick:Ue,disabled:ie||!ge,children:t(fe?"settings.common.actions.saveChanges":"settings.skills.page.actions.createFile")})]})]})})]})},po=t=>{const e=mt.c(2),{view:a}=t,n=a===void 0?"installed":a;let i;return e[0]!==n?(i=n==="catalog"?s.jsx(ou,{}):s.jsx(mu,{}),e[0]=n,e[1]=i):i=e[1],i};function uu(){}const gu=t=>{const e=mt.c(38),{onItemSelect:a}=t,{t:n}=ot(),i=Qs(hu),r=ce(fu),l=ce(xu),{currentTheme:h}=gr();let d;e[0]===Symbol.for("react.memo_cache_sentinel")?(d=vs(),e[0]=d):d=e[0];const x=d,c=bu;let v,p;e[1]!==i||e[2]!==r||e[3]!==l?(v=()=>{if(i.length===0){r!==null&&l(null);return}r&&i.some(m=>m.id===r)||l(i[0].id)},p=[i,r,l],e[1]=i,e[2]=r,e[3]=l,e[4]=v,e[5]=p):(v=e[4],p=e[5]),o.useEffect(v,p);let A;e[6]===Symbol.for("react.memo_cache_sentinel")?(A=je("border-b px-3","pt-4 pb-3"),e[6]=A):A=e[6];let b;e[7]!==n?(b=n("settings.page.projects.title"),e[7]=n,e[8]=b):b=e[8];let P;e[9]!==b?(P=s.jsx("h2",{className:`${rn} mb-3`,children:b}),e[9]=b,e[10]=P):P=e[10];let N;e[11]!==i.length||e[12]!==n?(N=n("settings.projects.sidebar.total",{count:i.length}),e[11]=i.length,e[12]=n,e[13]=N):N=e[13];let k;e[14]!==N?(k=s.jsx("span",{className:"typography-meta text-muted-foreground",children:N}),e[14]=N,e[15]=k):k=e[15];let g;e[16]!==n?(g=!x&&s.jsx(B,{type:"button",variant:"ghost",size:"icon",className:"h-7 w-7 -my-1 text-muted-foreground",onClick:c,"aria-label":n("settings.projects.sidebar.actions.addProject"),children:s.jsx(L,{name:"add",className:"size-4"})}),e[16]=n,e[17]=g):g=e[17];let E;e[18]!==k||e[19]!==g?(E=s.jsxs("div",{className:"flex items-center justify-between gap-2",children:[k,g]}),e[18]=k,e[19]=g,e[20]=E):E=e[20];let O;e[21]!==E||e[22]!==P?(O=s.jsxs("div",{className:A,children:[P,E]}),e[21]=E,e[22]=P,e[23]=O):O=e[23];let I;if(e[24]!==h||e[25]!==a||e[26]!==i||e[27]!==r||e[28]!==l){let m;e[30]!==h||e[31]!==a||e[32]!==r||e[33]!==l?(m=y=>{const K=y.id===r,C=y.icon?hc[y.icon]:null,T=y.color?fc[y.color]??null:null,j=C?s.jsx(L,{name:C,className:je("h-4 w-4",K?"text-foreground":"text-muted-foreground/70"),style:T?{color:T}:void 0}):s.jsx(L,{name:"folder",className:je("h-4 w-4",K?"text-foreground":"text-muted-foreground/70"),style:T?{color:T}:void 0}),R=y.iconImage?s.jsx("span",{className:"inline-flex h-4 w-4 items-center justify-center overflow-hidden rounded-[2px]",style:y.iconBackground?{backgroundColor:y.iconBackground}:void 0,children:s.jsx(xc,{project:y,options:{themeVariant:h.metadata.variant,iconColor:h.colors.surface.foreground},className:"h-full w-full object-contain",fallback:j})}):j;return s.jsx(sr,{title:y.label||y.path,icon:R,selected:K,onSelect:()=>{l(y.id),a?.()}},y.id)},e[30]=h,e[31]=a,e[32]=r,e[33]=l,e[34]=m):m=e[34],I=i.map(m),e[24]=h,e[25]=a,e[26]=i,e[27]=r,e[28]=l,e[29]=I}else I=e[29];let w;return e[35]!==O||e[36]!==I?(w=s.jsx(Tl,{variant:"background",header:O,children:I}),e[35]=O,e[36]=I,e[37]=w):w=e[37],w};function hu(t){return t.projects}function fu(t){return t.settingsProjectsSelectedId}function xu(t){return t.setSettingsProjectsSelectedId}function bu(){gc.requestDirectoryDialog()}const vu=()=>{const t=mt.c(30),{t:e}=ot(),a=Qs(yu),n=Qs(ju),i=ce(wu),r=ce(ku);let l;e:{if(!i){l=null;break e}let N;t[0]!==a||t[1]!==i?(N=a.find(k=>k.id===i)??null,t[0]=a,t[1]=i,t[2]=N):N=t[2],l=N}const h=l;let d,x;t[3]!==a||t[4]!==i||t[5]!==r?(d=()=>{if(a.length===0){r(null);return}i&&a.some(N=>N.id===i)||r(a[0].id)},x=[a,i,r],t[3]=a,t[4]=i,t[5]=r,t[6]=d,t[7]=x):(d=t[6],x=t[7]),o.useEffect(d,x);let c;t[8]!==h||t[9]!==n?(c=async N=>{h&&n(h.id,{label:N.label,icon:N.icon,color:N.color,iconBackground:N.iconBackground,defaultModel:N.defaultModel??null,defaultVariant:N.defaultVariant??null})},t[8]=h,t[9]=n,t[10]=c):c=t[10];const v=c;if(!h){let N;t[11]!==e?(N=e("settings.page.projects.title"),t[11]=e,t[12]=N):N=t[12];let k;t[13]!==e?(k=e("settings.projects.page.empty.noProjects"),t[13]=e,t[14]=k):k=t[14];let g;t[15]!==k?(g=s.jsx("p",{className:"typography-meta text-muted-foreground",children:k}),t[15]=k,t[16]=g):g=t[16];let E;return t[17]!==N||t[18]!==g?(E=s.jsx(gs,{title:N,showSaveStatus:!0,children:g}),t[17]=N,t[18]=g,t[19]=E):E=t[19],E}let p;t[20]!==h.label||t[21]!==e?(p=h.label??e("settings.projects.page.title.default"),t[20]=h.label,t[21]=e,t[22]=p):p=t[22];const A=p;let b;t[23]!==v||t[24]!==h?(b=s.jsx(Ad,{project:h,onIdentitySave:v}),t[23]=v,t[24]=h,t[25]=b):b=t[25];let P;return t[26]!==A||t[27]!==h.path||t[28]!==b?(P=s.jsx(gs,{title:A,description:h.path,showSaveStatus:!0,outerClassName:"bg-background",children:b}),t[26]=A,t[27]=h.path,t[28]=b,t[29]=P):P=t[29],P};function yu(t){return t.projects}function ju(t){return t.updateProjectMeta}function wu(t){return t.settingsProjectsSelectedId}function ku(t){return t.setSettingsProjectsSelectedId}const ni=()=>Math.floor(2e4+Math.random()*3e4),Nu=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")},Su=()=>{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"},mo=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}},uo=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"}},Cu=new Set(["config_resolved","auth_check","master_connecting","remote_probe","installing","updating","server_detecting","server_starting","forwarding"]),xr=t=>!!(t&&Cu.has(t)),go=t=>t==="ready"?"ready":t==="error"?"error":t==="degraded"||xr(t)?"connecting":"idle",ho=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"}},Pu=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},fo={noRuntime:"settings.remoteInstances.page.error.hint.noRuntime",noOpencode:"settings.remoteInstances.page.error.hint.noOpencode"},Iu=t=>t==="noRuntime"?fo.noRuntime:t==="noOpencode"?fo.noOpencode:null,xo=t=>t==="ready"?"bg-[var(--status-success)] animate-pulse":t==="error"?"bg-[var(--status-error)] animate-pulse":t==="degraded"||xr(t)?"bg-[var(--status-warning)] animate-pulse":"bg-muted-foreground/40",Au=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}`,Eu=()=>({id:`forward-${Date.now()}-${Math.random().toString(16).slice(2)}`,enabled:!0,type:"local",localHost:"127.0.0.1",localPort:ni(),remoteHost:"127.0.0.1",remotePort:80}),Tu=t=>t.trim().replace(/\*/g,"host").replace(/\?/g,"x")||"user@host",zs=t=>{const e=mt.c(7),{label:a,hint:n}=t;let i;e[0]!==a?(i=s.jsx("span",{children:a}),e[0]=a,e[1]=i):i=e[1];let r;e[2]!==n?(r=s.jsx(ss,{contentClassName:"max-w-xs",children:n}),e[2]=n,e[3]=r):r=e[3];let l;return e[4]!==i||e[5]!==r?(l=s.jsxs("span",{className:`inline-flex items-center gap-1 ${Rt}`,children:[i,r]}),e[4]=i,e[5]=r,e[6]=l):l=e[6],l},Du=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"}},bo=(t,e)=>{const a=(t||"").trim();return`${!a||a==="127.0.0.1"||a==="::1"?"localhost":a}:${e||0}`},Mu=t=>{const e=(t||"").trim();return!e||e==="0.0.0.0"||e==="::"?"127.0.0.1":e},Ru=t=>{const e=t.match(/^\[(\d{10,})\]\s*(?:\[([A-Z]+)\]\s*)?(.*)$/);if(!e)return t;const a=Number(e[1]),n=Number.isFinite(a)?new Date(a).toISOString():e[1],i=(e[2]||"INFO").toUpperCase(),r=e[3]||"";return`[${n}] [${i}] ${r}`},ar=(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}),Ou=t=>t.trim().toLowerCase()==="authorization",Fi=t=>{const e={};for(const a of t){const n=a.name.trim(),i=a.value.trim();n&&i&&!Ou(n)&&(e[n]=i)}return Object.keys(e).length>0?e:void 0},Lu=t=>Object.entries(t||{}).map(([e,a])=>ar(e,a)),Ol=()=>{if(typeof window>"u")return null;const e=La()||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}},vo=t=>{try{const e=new URL(t).hostname.toLowerCase();return e==="localhost"||e==="127.0.0.1"||e==="::1"||e==="[::1]"}catch{return!1}},Fu=async()=>{const t=aa(La())||window.location.origin;if(!bs()||!Fa())return t;let e;try{e=await pt("/api/config/settings",{method:"GET",headers:{Accept:"application/json"}})}catch{return t}if(!e.ok||(await e.json().catch(()=>null))?.desktopLanAccessActive!==!0)return t;const n=await xl(),i=Ol();return!n||!i?t:`http://${n}:${i}`},Ya=t=>{const e=t.trim();if(e)try{window.location.assign(e)}catch{window.location.href=e}},Ku=t=>{const e=t.sshCommand.trim(),a=t.nickname?.trim(),n=t.portForwards.map(i=>({...i,localHost:i.localHost?.trim()||"127.0.0.1",localPort:typeof i.localPort=="number"?Math.max(1,Math.min(65535,Math.round(i.localPort))):void 0,remoteHost:i.remoteHost?.trim(),remotePort:typeof i.remotePort=="number"?Math.max(1,Math.min(65535,Math.round(i.remotePort))):void 0}));return{...t,sshCommand:e,...a?{nickname:a}:{nickname:void 0},connectionTimeoutSec:Math.max(5,Math.min(240,Math.round(t.connectionTimeoutSec||60))),localForward:{...t.localForward,bindHost:t.localForward.bindHost==="localhost"||t.localForward.bindHost==="0.0.0.0"?t.localForward.bindHost:"127.0.0.1",preferredLocalPort:typeof t.localForward.preferredLocalPort=="number"?Math.max(1,Math.min(65535,Math.round(t.localForward.preferredLocalPort))):void 0},remoteOpenchamber:{...t.remoteOpenchamber,preferredPort:typeof t.remoteOpenchamber.preferredPort=="number"?Math.max(1,Math.min(65535,Math.round(t.remoteOpenchamber.preferredPort))):void 0},portForwards:n}},Uu=()=>{const{t}=ot(),e=ce(f=>f.timeFormatPreference),{clientAuth:a}=dl(),n=bs(),i=As(f=>f.instances),r=As(f=>f.statusesById),l=As(f=>f.importCandidates),h=As(f=>f.isLoading),d=As(f=>f.isImportsLoading),x=As(f=>f.isSaving),c=As(f=>f.error),v=As(f=>f.load),p=As(f=>f.loadImports),A=As(f=>f.refreshStatuses),b=As(f=>f.upsertInstance),P=As(f=>f.createFromCommand),N=As(f=>f.removeInstance),k=As(f=>f.connect),g=As(f=>f.disconnect),E=As(f=>f.retry),O=ce(f=>f.settingsRemoteInstancesSelectedId),I=ce(f=>f.setSettingsRemoteInstancesSelectedId),w=o.useMemo(()=>O&&i.find(f=>f.id===O)||null,[i,O]),[m,y]=o.useState(null),[K,C]=o.useState(!1),[T,j]=o.useState(!1),[R,G]=o.useState(null),[S,q]=o.useState([]),[Q,M]=o.useState(null),[W,Y]=o.useState(""),[F,se]=o.useState(!1),[_,V]=o.useState({}),[z,U]=o.useState(!1),[X,Z]=o.useState(!1),[ne,le]=o.useState(()=>Date.now()),[re,fe]=o.useState([]),[ae,ie]=o.useState({}),[te,ye]=o.useState("local"),[we,ke]=o.useState(!1),[xe,De]=o.useState(!1),[Me,he]=o.useState(""),[ge,Ae]=o.useState(""),[Ve,_e]=o.useState(""),[Le,Re]=o.useState([]),[Ze,Ge]=o.useState(""),[Oe,Ke]=o.useState(null),[Pe,Ue]=o.useState(!1),[ve,We]=o.useState(!1),[$,de]=o.useState(null),[ue,Ne]=o.useState(""),[pe,Fe]=o.useState(""),[H,He]=o.useState(""),[et,ze]=o.useState([]),[st,wt]=o.useState([]),[xt,gt]=o.useState([]),[bt,St]=o.useState(!1),[yt,It]=o.useState(""),[qe,Qe]=o.useState(null),[dt,Ee]=o.useState(null),[vt,Se]=o.useState(null),[kt,J]=o.useState(null),[me,Te]=o.useState(!1),[Ie,lt]=o.useState(!1),[at,Je]=o.useState("configure"),[Ct,rs]=o.useState(!1),[Yt,ys]=o.useState("relay"),[$t,cs]=o.useState(!0),[Kt,ds]=o.useState(null),as=o.useMemo(()=>st.filter(f=>!!f.revokedAt).length,[st]),[ns,Zt]=o.useState(!1),[os,oe]=o.useState("saved"),[ct,Ce]=o.useState(""),[it,jt]=o.useState(""),[At,Tt]=o.useState(""),[Xt,ls]=o.useState(!1);o.useEffect(()=>{v(),p()},[v,p]);const ft=o.useCallback(async()=>{ke(!0),Ke(null);try{const f=await Lr();fe(f.hosts||[]),ye(f.defaultHostId||"local")}catch(f){Ke(f instanceof Error?f.message:String(f))}finally{ke(!1)}},[]);o.useEffect(()=>{ft()},[ft]);const Pt=o.useCallback(async(f,ee=te)=>{De(!0),Ke(null);try{await Fr({hosts:f,defaultHostId:ee,initialHostChoiceCompleted:!0}),fe(f),ye(ee)}catch($e){Ke($e instanceof Error?$e.message:String($e))}finally{De(!1)}},[te]),Dt=o.useCallback(async()=>{const f=Kr(ge);if(!f){Ke(t("desktopHostSwitcher.error.invalidUrl"));return}const ee=f.persistedUrl,nt={id:typeof crypto<"u"&&typeof crypto.randomUUID=="function"?crypto.randomUUID():`host-${Date.now()}-${Math.random().toString(16).slice(2)}`,label:Me.trim()||ya(ee),url:ee,apiUrl:ee,...Ve.trim()?{clientToken:Ve.trim()}:{},...Fi(Le)?{requestHeaders:Fi(Le)}:{}};await Pt([nt,...re],te),he(""),Ae(""),_e(""),Re([]),Ue(!1),f.redeemUrl&&Ya(f.redeemUrl)},[te,Le,re,Me,Ve,ge,Pt,t]),Mt=o.useCallback(async()=>{const f=nd(Ze);if(!f){Ke(t("settings.remoteInstances.direct.error.invalidConnectLink"));return}const ee=await ad().catch(()=>""),$e=JSON.stringify({pairingId:f.pairingId,secret:f.secret,clientLabel:f.label||"OpenChamber Desktop",clientKind:"desktop",deviceName:"OpenChamber Desktop",devicePlatform:Su(),...ee?{dedupeKey:`desktop:${ee}`}:{}}),nt={method:"POST",headers:{"Content-Type":"application/json",Accept:"application/json"},body:$e},Vt=async Bt=>{if(!Bt.ok)return null;const Fs=await Bt.json().catch(()=>null);return(typeof Fs?.clientToken=="string"?Fs.clientToken.trim():"")||null},Cs=[...f.candidates].sort((Bt,Fs)=>(Bt.type==="relay"?1:0)-(Fs.type==="relay"?1:0));let ws=null;for(const Bt of Cs){if(Bt.type==="relay"){const fa=id({relayUrl:Bt.relayUrl,serverId:Bt.serverId,hostEncPubJwk:Bt.hostEncPubJwk,...Bt.grant?{grant:Bt.grant}:{}});try{const Va=await fa.fetch("/api/client-auth/pairing/redeem",nt),Sr=await Vt(Va);if(Sr){ws={kind:"relay",relay:{relayUrl:Bt.relayUrl,serverId:Bt.serverId,hostEncPubJwk:Bt.hostEncPubJwk},token:Sr};break}}catch{}finally{fa.close()}continue}const Fs=aa(Bt.url);if(Fs)try{const fa=await fetch(`${Fs}/api/client-auth/pairing/redeem`,nt),Va=await Vt(fa);if(Va){ws={kind:"direct",url:Fs,token:Va};break}}catch{}}if(!ws){Ke(t("desktopHostSwitcher.error.invalidUrl"));return}const u=()=>typeof crypto<"u"&&typeof crypto.randomUUID=="function"?crypto.randomUUID():`host-${Date.now()}-${Math.random().toString(16).slice(2)}`,rt=f.candidates.find(Bt=>Bt.type==="relay"),ts=ws.kind==="relay"?ws.relay:rt?{relayUrl:rt.relayUrl,serverId:rt.serverId,hostEncPubJwk:rt.hostEncPubJwk}:void 0,ps=f.candidates.filter(Bt=>Bt.type!=="relay").map(Bt=>aa(Bt.url)).find(Bt=>!!Bt),Ts=ws.kind==="direct"?ws.url:ps,{token:Ws}=ws,Et=Ts||(ts?rd(ts.serverId):null);if(!Et){Ke(t("desktopHostSwitcher.error.invalidUrl"));return}const is={url:Et,apiUrl:Ts||void 0,clientToken:Ws,...ts?{relay:ts}:{}},ha=re.find(Bt=>ts?Bt.relay?.serverId===ts.serverId:!Bt.relay&&aa(Bt.apiUrl||Bt.url)===Et);if(ha){const Bt=re.map(Fs=>Fs.id===ha.id?{...Fs,label:f.label||Fs.label,...is}:Fs);await Pt(Bt,te)}else await Pt([{id:u(),label:f.label||ya(Et),...is},...re],te);Ge(""),Ke(null),We(!1)},[Ze,te,re,Pt,t]),Ut=o.useCallback(async f=>{const ee=re.filter(nt=>nt.id!==f);await Pt(ee,te===f?"local":te),$===f&&de(null)},[te,$,re,Pt]),js=o.useCallback(f=>{de(f.id),Ne(f.label),Fe(f.apiUrl||f.url),He(f.clientToken||""),ze(Lu(f.requestHeaders)),Ke(null)},[]),Yn=o.useCallback(async()=>{if(!$)return;const f=Kr(pe);if(!f){Ke(t("desktopHostSwitcher.error.invalidUrl"));return}const ee=f.persistedUrl,$e=re.map(nt=>nt.id===$?{...nt,label:ue.trim()||ya(ee),url:ee,apiUrl:ee,clientToken:H.trim()||void 0,requestHeaders:Fi(et)}:nt);await Pt($e,te),de(null),f.redeemUrl&&Ya(f.redeemUrl)},[te,et,ue,H,pe,$,re,Pt,t]),mi=o.useCallback(async()=>{const f=it.trim();if(!f){D.error(t("settings.remoteInstances.page.toast.sshCommandRequired"));return}const ee=`ssh-${Date.now()}-${Math.random().toString(16).slice(2)}`;try{await P(ee,f,At.trim()||t("settings.remoteInstances.sidebar.newSshInstanceName")),I(ee),Zt(!1),jt(""),Tt(""),D.success(t("settings.remoteInstances.page.toast.instanceCreated"))}catch($e){D.error(t("settings.remoteInstances.sidebar.toast.createFailed"),{description:$e instanceof Error?$e.message:String($e)})}},[P,I,it,At,t]),ui=o.useCallback(()=>{Ce(""),oe(l.length>0?"saved":"manual"),Zt(!0)},[l.length]),gi=o.useCallback(async f=>{await Pt(re,f)},[re,Pt]);o.useEffect(()=>{if(!n||re.length===0)return;let f=!1;return Promise.all(re.map(async ee=>{const $e=()=>md(ee.relay,{clientToken:ee.clientToken||null,requestHeaders:ee.requestHeaders||null}).catch(()=>({status:"unreachable",latencyMs:0}));if(ee.relay&&!ee.apiUrl)return[ee.id,await $e()];const nt=aa(od(ee));if(!nt)return[ee.id,ee.relay?await $e():{status:"unreachable",latencyMs:0}];const Vt=await ld(nt,{clientToken:ee.clientToken||null,requestHeaders:ee.requestHeaders||null}).catch(()=>({status:"unreachable",latencyMs:0}));if(Vt.status==="unreachable"&&ee.relay){const Cs=await $e();if(Cs.status==="ok")return[ee.id,Cs]}return[ee.id,Vt]})).then(ee=>{f||ie(Object.fromEntries(ee))}),()=>{f=!0}},[re,n]);const Os=o.useCallback(async f=>{if(a){f?.silent||St(!0),f?.silent||Qe(null);try{const[ee,$e]=await Promise.all([a.listClients(),a.listPendingPairings().catch(()=>null)]);wt(ee),$e&>($e)}catch(ee){f?.silent||Qe(ee instanceof Error?ee.message:String(ee))}finally{f?.silent||St(!1)}}},[a]),pa=o.useRef(!1);o.useEffect(()=>{if(!(!Ie||at!=="result"||!vt)){if(xt.some(f=>f.id===vt)){pa.current=!0;return}pa.current&&(Se(null),lt(!1),st.some(f=>f.pairingId===vt)&&D.success(t("settings.remoteInstances.clientAuth.addDevice.connectedToast")))}},[Ie,at,vt,xt,st,t]);const hi=o.useCallback(async f=>{if(a)try{await a.cancelPairing(f),gt(ee=>ee.filter($e=>$e.id!==f)),await Os({silent:!0})}catch(ee){Qe(ee instanceof Error?ee.message:String(ee))}},[a,Os]);o.useEffect(()=>{if(!a)return;Os();const f=window.setInterval(()=>{typeof document<"u"&&document.visibilityState!=="visible"||Os({silent:!0})},5e3);return()=>window.clearInterval(f)},[a,Os]);const Ua=o.useCallback(async()=>{if(a?.getPairingTransports)try{const nt=await a.getPairingTransports();return{localUrl:nt.local,lanUrl:nt.lan,relayAvailable:nt.relayAvailable}}catch{}const f=Ol(),ee=f?`http://127.0.0.1:${f}`:vo(window.location.origin)?window.location.origin:null;let $e=null;try{const nt=aa(await Fu());$e=nt&&!vo(nt)?nt:null}catch{}return{localUrl:ee,lanUrl:$e,relayAvailable:!0}},[a]),fi=o.useCallback(async()=>{Qe(null),Ee(null),J(null),Te(!1),Se(null),Je("configure"),cs(!0),lt(!0);const f=await Ua();ds(f),ys(f.relayAvailable?"relay":f.lanUrl?"lan":"local")},[Ua]),xi=o.useCallback(async()=>{if(!(!a?.createPairingSession||!Kt)){Qe(null),rs(!0);try{const f=yt.trim()||void 0;let ee,$e,nt=!0;Yt==="local"?(ee=Kt.localUrl??void 0,$e=!1):Yt==="lan"?(ee=Kt.lanUrl??void 0,$e=$t):$t&&Kt.lanUrl?(ee=Kt.lanUrl,$e=!0):(nt=!1,$e=!0);const{pairing:Vt,server:Cs}=await a.createPairingSession({label:f,allowedClientKinds:["mobile","desktop"],serverUrl:ee,includeRelay:$e,includeDirect:nt}),ws=cd({pairingId:Vt.id,secret:Vt.secret,label:Cs.label,fingerprint:Vt.fingerprint??void 0,expiresAt:Vt.expiresAt,candidates:Cs.candidates}),u=dd(ws);Ee(u),J(await Nl.toDataURL(u,{width:1024,margin:2,errorCorrectionLevel:"L"})),Te(!1),pa.current=!1,Se(Vt.id),Je("result"),await Os({silent:!0})}catch(f){Qe(f instanceof Error?f.message:String(f))}finally{rs(!1)}}},[a,Kt,Yt,$t,yt,Os]),bi=o.useCallback(()=>{dt&&Ta(dt).then(f=>{f.ok&&(Te(!0),window.setTimeout(()=>Te(!1),2e3))})},[dt]),vi=o.useCallback(async f=>{if(!a)return;const ee=f.clientKind==="desktop-local";Qe(null);try{if(await a.revokeClient(f.id),ee&&bs()){const $e=await Lr();await Fr({hosts:$e.hosts,defaultHostId:$e.defaultHostId,initialHostChoiceCompleted:$e.initialHostChoiceCompleted,localClientToken:null}),wt(nt=>nt.map(Vt=>Vt.id===f.id?{...Vt,revokedAt:new Date().toISOString()}:Vt)),pd({apiBaseUrl:La(),clientToken:null,runtimeKey:"local"});return}await Os()}catch($e){Qe($e instanceof Error?$e.message:String($e))}},[a,Os]),yi=o.useCallback(async()=>{if(a){Qe(null);try{await a.purgeRevokedClients(),await Os()}catch(f){Qe(f instanceof Error?f.message:String(f))}}},[a,Os]);o.useEffect(()=>{y(w)},[w]),o.useEffect(()=>{ls(!1)},[O]),o.useEffect(()=>{if(!O)return;const f=window.setInterval(()=>{typeof document<"u"&&document.visibilityState!=="visible"||A()},2e3);return()=>{window.clearInterval(f)}},[A,O]),o.useEffect(()=>{let f=null,ee=Date.now();const $e=()=>{const Vt=Date.now();Vt-ee>=1e3&&(le(Vt),ee=Vt),f=requestAnimationFrame($e)};(typeof document>"u"||document.visibilityState==="visible")&&(f=requestAnimationFrame($e));const nt=()=>{document.visibilityState==="visible"&&f===null?f=requestAnimationFrame($e):document.visibilityState!=="visible"&&f!==null&&(cancelAnimationFrame(f),f=null)};return document.addEventListener("visibilitychange",nt),()=>{document.removeEventListener("visibilitychange",nt),f!==null&&cancelAnimationFrame(f)}},[]);const Ss=O?r[O]:null,Bs=Ss?.phase,Zn=Bs==="ready",on=Bs==="degraded",pn=xr(Bs),Ls=Zn||(pn||on),Xn=Ss?Math.max(0,ne-Ss.updatedAtMs):0,mn=on&&Xn>12e3,un=go(Bs),Ys=un==="error"?Pu(Ss?.detail):null,be=Iu(Ys),xs=o.useMemo(()=>!m||!w?!1:JSON.stringify(m)!==JSON.stringify(w),[m,w]),hs=o.useCallback(f=>{y(ee=>ee&&f(ee))},[]),za=o.useCallback(async()=>{if(!m)return;const f=Ku(m);if(!f.sshCommand.trim()){D.error(t("settings.remoteInstances.page.toast.sshCommandRequired"));return}if(f.remoteOpenchamber.mode==="external"&&!f.remoteOpenchamber.preferredPort){D.error(t("settings.remoteInstances.page.validation.externalPortRequired")),ls(!0);return}if(f.remoteOpenchamber.mode==="managed"&&f.remoteOpenchamber.bindHost==="0.0.0.0"&&!f.auth.openchamberPassword?.value?.trim()){D.error(t("settings.remoteInstances.page.validation.remoteLanNeedsPassword")),ls(!0),window.setTimeout(()=>Mn.current?.focus(),0);return}if(!(f.localForward.bindHost==="0.0.0.0"&&!window.confirm(t("settings.remoteInstances.page.confirm.bindAllInterfaces")))){if(f.auth.sshPassword?.enabled&&f.auth.sshPassword.value?.trim()&&f.auth.sshPassword.store!=="settings"){const ee=window.confirm(t("settings.remoteInstances.page.confirm.storeSshPasswordPlaintext"));f.auth.sshPassword.store=ee?"settings":"never",ee||(f.auth.sshPassword.value=void 0)}if(f.auth.openchamberPassword?.enabled&&f.auth.openchamberPassword.value?.trim()&&f.auth.openchamberPassword.store!=="settings"){const ee=window.confirm(t("settings.remoteInstances.page.confirm.storeUiPasswordPlaintext"));f.auth.openchamberPassword.store=ee?"settings":"never",ee||(f.auth.openchamberPassword.value=void 0)}try{await b(f),D.success(t("settings.remoteInstances.page.toast.instanceSaved"))}catch(ee){D.error(t("settings.remoteInstances.page.toast.saveFailed"),{description:ee instanceof Error?ee.message:String(ee)})}}},[m,t,b]),En=o.useCallback(async(f,ee)=>{const $e=`ssh-${Date.now()}-${Math.random().toString(16).slice(2)}`;try{return await P($e,`ssh ${ee}`,f),I($e),D.success(t("settings.remoteInstances.page.toast.instanceCreated")),!0}catch(nt){return D.error(t("settings.remoteInstances.sidebar.toast.createFailed"),{description:nt instanceof Error?nt.message:String(nt)}),!1}},[P,I,t]),Tn=o.useCallback(()=>{F||(M(null),Y(""))},[F]),_a=o.useCallback((f,ee)=>{if(Zt(!1),ee){M(f),Y(Tu(f));return}En(f,f)},[En]),ma=o.useMemo(()=>ri(l,ct,f=>[f.host,f.sshCommand]),[l,ct]),ji=o.useCallback(f=>{const ee=(f||"").trim();if(!ee){D.error(t("settings.remoteInstances.page.toast.instanceUrlUnavailable"));return}Ya(ee)},[t]),Dn=o.useCallback(async()=>{const f=Q,ee=W.trim();if(f){if(!ee){D.error(t("settings.remoteInstances.page.toast.destinationRequired"));return}se(!0);try{await En(f,ee)&&(M(null),Y(""))}finally{se(!1)}}},[En,W,Q,t]),gn=o.useCallback(async()=>{if(w)try{await k(w.id);return}catch(f){if(!Nu(f)||!window.confirm(t("settings.remoteInstances.sidebar.confirm.localPortInUseRetry")))throw f;const $e={...w,localForward:{...w.localForward,preferredLocalPort:ni()}};await b($e),await k($e.id),D.success(t("settings.remoteInstances.sidebar.toast.retriedWithRandomPort"))}},[k,w,t,b]),Mn=o.useRef(null),$a=o.useRef(null),ea=o.useCallback(async f=>{if(w){if(f==="localPort"){const ee={...w,localForward:{...w.localForward,preferredLocalPort:ni()}};try{await b(ee),await k(ee.id),D.success(t("settings.remoteInstances.sidebar.toast.retriedWithRandomPort"))}catch($e){D.error(t("settings.remoteInstances.page.toast.connectFailed"),{description:$e instanceof Error?$e.message:String($e)})}return}ls(!0),window.setTimeout(()=>{if(f==="uiPassword"){Mn.current?.focus();return}$a.current?.scrollIntoView({block:"center"})},0)}},[k,w,t,b]),Hs=o.useCallback(async f=>(await bc(f,600)).map($e=>Ru($e)),[]),hn=o.useCallback(async()=>{if(m){C(!0),j(!0),G(null);try{const f=await Hs(m.id);q(f)}catch(f){q([]),G(f instanceof Error?f.message:String(f))}finally{j(!1)}}},[m,Hs]);o.useEffect(()=>{if(!K||!m)return;let f=!1;const ee=async()=>{try{const nt=await Hs(m.id);f||(q(nt),G(null))}catch(nt){f||G(nt instanceof Error?nt.message:String(nt))}};ee();const $e=window.setInterval(()=>{typeof document<"u"&&document.visibilityState!=="visible"||ee()},1e3);return()=>{f=!0,window.clearInterval($e)}},[m,K,Hs]);const Gs=o.useMemo(()=>S.join(`
|
|
27
|
-
`),[S]),ta=o.useCallback(()=>{if(!Gs.trim()){D.error(t("settings.remoteInstances.page.toast.noLogsToCopy"));return}Ta(Gs).then(f=>{f.ok&&D.success(t("settings.remoteInstances.page.toast.logsCopied"))})},[Gs,t]),ua=o.useCallback(async()=>{if(m)try{await vc(m.id),q([]),D.success(t("settings.remoteInstances.page.toast.logsCleared"))}catch(f){D.error(t("settings.remoteInstances.page.toast.clearLogsFailed"),{description:f instanceof Error?f.message:String(f)})}},[m,t]),ga=o.useCallback(async()=>{if(!Ss?.localUrl){D.error(t("settings.remoteInstances.page.toast.instanceUrlUnavailable"));return}const f=Ss.localUrl.trim();if(!f){D.error(t("settings.remoteInstances.page.toast.instanceUrlUnavailable"));return}Ya(f)},[Ss?.localUrl,t]),wi=o.useCallback(()=>{if(!m)return;if(!Ls&&m.remoteOpenchamber.mode==="external"&&!m.remoteOpenchamber.preferredPort){D.error(t("settings.remoteInstances.page.validation.externalPortRequired")),ls(!0);return}if(!Ls&&m.remoteOpenchamber.mode==="managed"&&m.remoteOpenchamber.bindHost==="0.0.0.0"&&!m.auth.openchamberPassword?.value?.trim()){D.error(t("settings.remoteInstances.page.validation.remoteLanNeedsPassword")),ls(!0),window.setTimeout(()=>Mn.current?.focus(),0);return}U(!0),(Ls?g(m.id):gn()).catch(ee=>{const $e=Ls?Zn?"settings.remoteInstances.page.toast.disconnectFailed":"settings.remoteInstances.page.toast.cancelConnectionFailed":"settings.remoteInstances.page.toast.connectFailed";D.error(t($e),{description:ee instanceof Error?ee.message:String(ee)})}).finally(()=>{U(!1)})},[Ls,gn,g,m,Zn,t]),ki=o.useCallback(()=>{if(!m||pn)return;Z(!0),(on?g(m.id).then(()=>gn()):E(m.id)).catch(ee=>{D.error(t("settings.remoteInstances.page.toast.retryFailed"),{description:ee instanceof Error?ee.message:String(ee)})}).finally(()=>{Z(!1)})},[gn,g,m,pn,on,E,t]),Ni=t(pn?"settings.remoteInstances.page.actions.connecting":on?mn?"settings.remoteInstances.page.actions.reconnectNow":"settings.remoteInstances.page.actions.reconnecting":"settings.remoteInstances.sidebar.actions.retry"),Si=!z&&!X&&(Bs==="error"||Bs==="idle"||!Bs||on&&mn)&&!pn,Ci=t(Zn?"settings.remoteInstances.sidebar.actions.disconnect":Ls?"settings.remoteInstances.page.actions.cancel":"settings.remoteInstances.sidebar.actions.connect");if(!m)return s.jsxs(gs,{title:t("settings.page.remoteInstances.title"),children:[a?s.jsxs(Be,{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:()=>{fi()},children:[s.jsx(L,{name:"add",className:"h-3.5 w-3.5"}),t("settings.remoteInstances.clientAuth.actions.addDevice")]})}),s.jsxs("div",{className:"space-y-2.5",children:[as>0?s.jsx("div",{className:"flex justify-end",children:s.jsx(B,{type:"button",variant:"ghost",size:"xs",className:"!font-normal",onClick:()=>{yi()},children:t("settings.remoteInstances.clientAuth.actions.clearRevoked")})}):null,bt&&st.length===0&&xt.length===0?s.jsx("p",{className:"typography-meta text-muted-foreground",children:t("settings.remoteInstances.clientAuth.state.loading")}):st.length===0&&xt.length===0?s.jsx("p",{className:"typography-meta text-muted-foreground",children:t("settings.remoteInstances.clientAuth.state.empty")}):s.jsxs(s.Fragment,{children:[xt.map(f=>s.jsxs("div",{className:"flex items-center justify-between gap-3 py-1.5",children:[s.jsxs("div",{className:"min-w-0 space-y-0.5",children:[s.jsxs("div",{className:"flex min-w-0 items-center gap-2",children:[s.jsx("span",{className:"h-2 w-2 shrink-0 rounded-full bg-[var(--status-warning)] animate-pulse"}),s.jsx("p",{className:"typography-ui-label text-foreground truncate",children:f.label||t("settings.remoteInstances.clientAuth.field.labelPlaceholder")}),f.usesRelay?s.jsx("span",{className:"typography-micro text-muted-foreground bg-muted px-1 rounded shrink-0 leading-none pb-px border border-border/50",children:t("settings.remoteInstances.clientAuth.state.viaRelay")}):null]}),s.jsx("p",{className:"typography-micro text-muted-foreground truncate",children:t("settings.remoteInstances.clientAuth.state.pending")})]}),s.jsx(B,{type:"button",variant:"ghost",size:"xs",className:"!font-normal",onClick:()=>{hi(f.id)},children:t("settings.common.actions.cancel")})]},`pending-${f.id}`)),st.map(f=>{const ee=f.clientKind==="desktop-local",$e=f.lastUsedAt?Date.parse(f.lastUsedAt):Number.NaN,nt=!f.revokedAt&&(ee||Number.isFinite($e)&&Date.now()-$e<9e4),Vt=f.revokedAt?t("settings.remoteInstances.clientAuth.state.revoked"):nt?f.lastTransport==="relay"&&!ee?t("settings.remoteInstances.clientAuth.state.connectedRelay"):t("settings.remoteInstances.clientAuth.state.connectedDirect"):Number.isFinite($e)?t("settings.remoteInstances.clientAuth.lastUsed",{date:yc($e,e,{month:"short",day:"numeric",hour:"numeric",minute:"2-digit"})}):t("settings.remoteInstances.clientAuth.neverUsed");return s.jsxs("div",{className:"flex items-center justify-between gap-3 py-1.5",children:[s.jsx("div",{className:"min-w-0",children:s.jsxs("div",{className:"flex min-w-0 flex-wrap items-center gap-x-2 gap-y-0.5",children:[s.jsx("span",{className:je("h-2 w-2 shrink-0 rounded-full",f.revokedAt?"bg-muted-foreground/20":nt?"bg-[var(--status-success)]":"bg-muted-foreground/30")}),s.jsx("p",{className:"typography-ui-label text-foreground truncate",children:f.label}),mo(f.devicePlatform)?s.jsx("span",{className:"typography-micro text-muted-foreground bg-muted px-1 rounded shrink-0 leading-none pb-px border border-border/50",children:mo(f.devicePlatform)}):null,ee?s.jsx("span",{className:"typography-micro text-muted-foreground bg-muted px-1 rounded flex-shrink-0 leading-none pb-px border border-border/50",children:t("settings.remoteInstances.clientAuth.state.thisDevice")}):null,s.jsx("span",{className:je("typography-micro truncate",nt&&!f.revokedAt?"text-[var(--status-success)]":"text-muted-foreground"),children:Vt})]})}),s.jsx(B,{type:"button",variant:"ghost",size:"xs",className:"!font-normal",onClick:()=>{vi(f)},disabled:!!f.revokedAt,children:t("settings.remoteInstances.clientAuth.actions.revoke")})]},f.id)})]})]}),qe?s.jsx("p",{className:"typography-meta text-[var(--status-error)]",children:qe}):null]}):null,n?s.jsxs(Be,{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:()=>We(!0),disabled:xe,children:t("settings.remoteInstances.direct.import.action")}),s.jsxs(B,{type:"button",variant:"outline",size:"xs",className:"!font-normal",onClick:()=>Ue(!0),disabled:xe,children:[s.jsx(L,{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:we?s.jsx("p",{className:"typography-meta text-muted-foreground",children:t("settings.remoteInstances.direct.state.loading")}):re.length===0?s.jsx("p",{className:"typography-meta text-muted-foreground",children:t("settings.remoteInstances.direct.state.empty")}):re.map(f=>{const ee=ae[f.id],$e=ee?ee.status==="ok"?"desktopHostSwitcher.status.connected":ee.status==="auth"?"desktopHostSwitcher.status.authRequired":ee.status==="update-recommended"?"desktopHostSwitcher.status.updateRecommended":ee.status==="incompatible"?"desktopHostSwitcher.status.incompatible":ee.status==="wrong-service"?"desktopHostSwitcher.status.wrongService":"desktopHostSwitcher.status.unreachable":"desktopHostSwitcher.status.checking",nt=ee?.status==="ok";return s.jsx("div",{className:"py-1.5",children:s.jsxs("div",{className:"flex items-center justify-between gap-3",children:[s.jsxs("div",{className:"min-w-0 space-y-0.5",children:[s.jsxs("div",{className:"flex min-w-0 items-center gap-2",children:[s.jsx("span",{className:je("h-2 w-2 shrink-0 rounded-full",ee?nt?"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:ya(f.label)}),te===f.id?s.jsx("span",{className:"typography-micro text-muted-foreground shrink-0",children:t("desktopHostSwitcher.header.default")}):null,s.jsxs("span",{className:je("typography-micro shrink-0",nt?"text-[var(--status-success)]":"text-muted-foreground"),children:[t($e),nt&&typeof ee?.latencyMs=="number"?t("desktopHostSwitcher.status.ping",{ms:Math.max(0,Math.round(ee.latencyMs))}):""]})]}),s.jsx("p",{className:je("typography-micro text-muted-foreground truncate",f.apiUrl&&"font-mono"),children:f.relay&&!f.apiUrl?t("mobile.connect.relay.badge"):ya(f.apiUrl||f.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:()=>{gi(f.id)},disabled:xe||te===f.id,"aria-label":t("desktopHostSwitcher.actions.setAsDefaultAria"),children:te===f.id?s.jsx(L,{name:"star-fill",className:"h-3.5 w-3.5"}):s.jsx(L,{name:"star",className:"h-3.5 w-3.5"})}),f.relay&&!f.apiUrl?null:s.jsxs(B,{type:"button",variant:"ghost",size:"xs",className:"!font-normal",onClick:()=>js(f),disabled:xe,children:[s.jsx(L,{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:()=>{Ut(f.id)},disabled:xe,children:[s.jsx(L,{name:"delete-bin",className:"h-3.5 w-3.5"}),t("settings.common.actions.delete")]})]})]})},f.id)})}),Oe?s.jsx("p",{className:"typography-meta text-[var(--status-error)]",children:Oe}):null]}):null,n?s.jsx(zt,{open:Pe,onOpenChange:Ue,children:s.jsxs(_t,{className:"sm:max-w-lg",children:[s.jsxs(Gt,{children:[s.jsx(qt,{children:t("settings.remoteInstances.direct.actions.add")}),s.jsx(Wt,{children:t("settings.remoteInstances.direct.addDialog.description")})]}),s.jsxs("form",{className:"space-y-3",onSubmit:f=>{f.preventDefault(),Dt()},children:[s.jsx(Ye,{className:"h-8",value:Me,onChange:f=>he(f.target.value),placeholder:t("settings.remoteInstances.direct.field.labelPlaceholder"),disabled:xe}),s.jsx(Ye,{className:"h-8",value:ge,onChange:f=>Ae(f.target.value),placeholder:t("settings.remoteInstances.direct.field.urlPlaceholder"),disabled:xe,autoFocus:!0}),s.jsxs("div",{className:"space-y-1",children:[s.jsx(Ye,{className:"h-8",value:Ve,onChange:f=>_e(f.target.value),placeholder:t("settings.remoteInstances.direct.field.tokenPlaceholder"),type:"password",disabled:xe}),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(en,{children:t("settings.remoteInstances.direct.headers.title")}),s.jsx(ss,{children:t("settings.remoteInstances.direct.headers.description")})]}),Le.map(f=>s.jsxs("div",{className:"flex w-full gap-2",children:[s.jsx(Ye,{className:"h-8 font-mono text-xs",value:f.name,onChange:ee=>Re($e=>$e.map(nt=>nt.id===f.id?{...nt,name:ee.target.value}:nt)),placeholder:t("settings.remoteInstances.direct.headers.field.namePlaceholder"),disabled:xe}),s.jsx(Ye,{className:"h-8 font-mono text-xs",value:f.value,onChange:ee=>Re($e=>$e.map(nt=>nt.id===f.id?{...nt,value:ee.target.value}:nt)),placeholder:t("settings.remoteInstances.direct.headers.field.valuePlaceholder"),type:"password",disabled:xe}),s.jsx("button",{type:"button",onClick:()=>Re(ee=>ee.filter($e=>$e.id!==f.id)),className:"flex h-8 w-8 flex-shrink-0 items-center justify-center rounded-md text-muted-foreground hover:bg-[var(--status-error-background)] hover:text-[var(--status-error)] focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-[var(--interactive-focus-ring)]","aria-label":t("settings.remoteInstances.direct.headers.removeAria"),disabled:xe,children:s.jsx(L,{name:"close",className:"h-4 w-4"})})]},f.id)),s.jsxs(B,{type:"button",variant:"ghost",size:"xs",className:"!font-normal",onClick:()=>Re(f=>[...f,ar()]),disabled:xe,children:[s.jsx(L,{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:()=>Ue(!1),disabled:xe,children:t("settings.common.actions.cancel")}),s.jsx(B,{type:"submit",size:"xs",className:"!font-normal",disabled:xe||!ge.trim(),children:t("settings.remoteInstances.direct.actions.add")})]})]})]})}):null,n?s.jsx(zt,{open:!!$,onOpenChange:f=>{f||de(null)},children:s.jsxs(_t,{className:"sm:max-w-lg",children:[s.jsxs(Gt,{children:[s.jsx(qt,{children:t("desktopHostSwitcher.actions.edit")}),s.jsx(Wt,{children:t("settings.remoteInstances.direct.description")})]}),s.jsxs("form",{className:"space-y-3",onSubmit:f=>{f.preventDefault(),Yn()},children:[s.jsx(Ye,{className:"h-8",value:ue,onChange:f=>Ne(f.target.value),placeholder:t("settings.remoteInstances.direct.field.labelPlaceholder"),disabled:xe}),s.jsx(Ye,{className:"h-8",value:pe,onChange:f=>Fe(f.target.value),placeholder:t("settings.remoteInstances.direct.field.urlPlaceholder"),disabled:xe,autoFocus:!0}),s.jsx(Ye,{className:"h-8",value:H,onChange:f=>He(f.target.value),placeholder:t("settings.remoteInstances.direct.field.tokenPlaceholder"),type:"password",disabled:xe}),s.jsxs("div",{className:"space-y-2",children:[s.jsxs("div",{className:"flex items-center gap-1.5",children:[s.jsx(en,{children:t("settings.remoteInstances.direct.headers.title")}),s.jsx(ss,{children:t("settings.remoteInstances.direct.headers.description")})]}),et.map(f=>s.jsxs("div",{className:"flex w-full gap-2",children:[s.jsx(Ye,{className:"h-8 font-mono text-xs",value:f.name,onChange:ee=>ze($e=>$e.map(nt=>nt.id===f.id?{...nt,name:ee.target.value}:nt)),placeholder:t("settings.remoteInstances.direct.headers.field.namePlaceholder"),disabled:xe}),s.jsx(Ye,{className:"h-8 font-mono text-xs",value:f.value,onChange:ee=>ze($e=>$e.map(nt=>nt.id===f.id?{...nt,value:ee.target.value}:nt)),placeholder:t("settings.remoteInstances.direct.headers.field.valuePlaceholder"),type:"password",disabled:xe}),s.jsx("button",{type:"button",onClick:()=>ze(ee=>ee.filter($e=>$e.id!==f.id)),className:"flex h-8 w-8 flex-shrink-0 items-center justify-center rounded-md text-muted-foreground hover:bg-[var(--status-error-background)] hover:text-[var(--status-error)] focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-[var(--interactive-focus-ring)]","aria-label":t("settings.remoteInstances.direct.headers.removeAria"),disabled:xe,children:s.jsx(L,{name:"close",className:"h-4 w-4"})})]},f.id)),s.jsxs(B,{type:"button",variant:"ghost",size:"xs",className:"!font-normal",onClick:()=>ze(f=>[...f,ar()]),disabled:xe,children:[s.jsx(L,{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:()=>de(null),disabled:xe,children:t("settings.common.actions.cancel")}),s.jsx(B,{type:"submit",size:"xs",className:"!font-normal",disabled:xe,children:t("settings.common.actions.saveChanges")})]})]})]})}):null,n?s.jsx(zt,{open:ve,onOpenChange:We,children:s.jsxs(_t,{className:"sm:max-w-lg",children:[s.jsxs(Gt,{children:[s.jsx(qt,{children:t("settings.remoteInstances.direct.import.action")}),s.jsx(Wt,{children:t("settings.remoteInstances.direct.import.description")})]}),s.jsxs("form",{className:"space-y-3",onSubmit:f=>{f.preventDefault(),Mt()},children:[s.jsx(Ye,{className:"h-8",value:Ze,onChange:f=>Ge(f.target.value),placeholder:t("settings.remoteInstances.direct.import.placeholder"),disabled:xe,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:()=>We(!1),disabled:xe,children:t("settings.common.actions.cancel")}),s.jsx(B,{type:"submit",size:"xs",className:"!font-normal",disabled:xe||!Ze.trim(),children:t("settings.remoteInstances.direct.import.action")})]})]})]})}):null,s.jsx(zt,{open:Ie,onOpenChange:lt,children:s.jsxs(_t,{className:at==="result"?"sm:max-w-lg":"sm:max-w-md",children:[s.jsxs(Gt,{children:[s.jsx(qt,{children:t(at==="result"?"settings.remoteInstances.clientAuth.qrDialogTitle":"settings.remoteInstances.clientAuth.actions.addDevice")}),s.jsx(Wt,{children:t(at==="result"?"settings.remoteInstances.clientAuth.qrScanHint":"settings.remoteInstances.clientAuth.addDevice.subtitle")})]}),at==="configure"?s.jsxs("form",{className:"space-y-4",onSubmit:f=>{f.preventDefault(),xi()},children:[s.jsx(Ye,{className:"h-8",value:yt,onChange:f=>It(f.target.value),placeholder:t("settings.remoteInstances.clientAuth.field.labelPlaceholder"),autoFocus:!0}),s.jsxs("div",{className:"space-y-1.5",children:[s.jsx("p",{className:"typography-ui-label text-foreground",children:t("settings.remoteInstances.clientAuth.addDevice.transportLabel")}),s.jsx("div",{role:"radiogroup","aria-label":t("settings.remoteInstances.clientAuth.addDevice.transportLabel"),className:"space-y-1.5",children:[{key:"relay",label:t("settings.remoteInstances.clientAuth.addDevice.transport.relay"),hint:t("settings.remoteInstances.clientAuth.addDevice.transport.relayHint"),available:!!Kt?.relayAvailable},{key:"lan",label:t("settings.remoteInstances.clientAuth.addDevice.transport.lan"),hint:t("settings.remoteInstances.clientAuth.addDevice.transport.lanHint"),available:!!Kt?.lanUrl},{key:"local",label:t("settings.remoteInstances.clientAuth.addDevice.transport.local"),hint:t("settings.remoteInstances.clientAuth.addDevice.transport.localHint"),available:!!Kt?.localUrl}].map(f=>{const ee=Yt===f.key;return s.jsxs("div",{className:je("flex items-start gap-2 py-0.5",f.available?"cursor-pointer":"opacity-45"),onClick:()=>{f.available&&ys(f.key)},role:"presentation",children:[s.jsx(dr,{checked:ee,disabled:!f.available,onChange:()=>ys(f.key),ariaLabel:f.label,className:"mt-0.5"}),s.jsxs("div",{className:"min-w-0",children:[s.jsx("p",{className:je("typography-ui-label font-normal",ee?"text-foreground":"text-foreground/70"),children:f.label}),s.jsx("p",{className:"typography-meta text-muted-foreground",children:f.hint})]})]},f.key)})}),Yt==="lan"?s.jsxs("label",{className:"flex w-fit cursor-pointer items-center gap-2 pt-1",children:[s.jsx(Yi,{checked:$t,onChange:cs,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,Yt==="relay"&&Kt?.lanUrl?s.jsxs("label",{className:"flex w-fit cursor-pointer items-center gap-2 pt-1",children:[s.jsx(Yi,{checked:$t,onChange:cs,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]}),qe?s.jsx("p",{className:"typography-meta text-[var(--status-error)]",children:qe}):null,s.jsxs("div",{className:"flex justify-end gap-2",children:[s.jsx(B,{type:"button",variant:"outline",size:"xs",className:"!font-normal",onClick:()=>lt(!1),disabled:Ct,children:t("settings.common.actions.cancel")}),s.jsx(B,{type:"submit",size:"xs",className:"!font-normal",disabled:Ct||!Kt,children:t("settings.remoteInstances.clientAuth.addDevice.create")})]})]}):s.jsxs("div",{className:"space-y-3",children:[kt?s.jsx("div",{className:"flex justify-center",children:s.jsx("img",{src:kt,alt:t("settings.remoteInstances.clientAuth.qrAlt"),className:"w-full max-w-[420px] rounded-md bg-white p-4"})}):null,dt?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:dt}),s.jsxs(B,{type:"button",variant:"outline",size:"xs",className:"!font-normal shrink-0",onClick:bi,children:[s.jsx(L,{name:me?"check":"file-copy",className:je("h-3.5 w-3.5",me&&"text-[var(--status-success)]")}),t(me?"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:()=>lt(!1),children:t("settings.remoteInstances.clientAuth.addDevice.done")})})]})]})}),n?s.jsx(Be,{title:t("settings.remoteInstances.sidebar.title"),description:t("settings.remoteInstances.sidebar.total",{count:i.length}),headerAction:s.jsxs(B,{type:"button",size:"xs",className:"!font-normal",onClick:ui,children:[s.jsx(L,{name:"add",className:"h-3.5 w-3.5"}),t("settings.remoteInstances.sidebar.actions.addSshInstance")]}),contentClassName:"space-y-2.5",children:h?s.jsx("p",{className:"typography-meta text-muted-foreground",children:t("settings.remoteInstances.page.state.loadingInstances")}):i.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")}):i.map(f=>{const ee=r[f.id],$e=f.nickname?.trim()||f.sshParsed?.destination||f.id,nt=ee?.phase,Vt=nt==="ready",Cs=go(nt),ws=Cs==="error"?ee?.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 ${xo(nt)}`}),s.jsx("p",{className:"typography-ui-label text-foreground truncate",children:$e})]}),s.jsxs("p",{className:"typography-micro text-muted-foreground truncate",children:[t(ho(Cs)),Cs==="connecting"?` · ${t(uo(nt))}`:"",Vt&&ee?.localUrl?` · ${ee.localUrl}`:""]})]}),s.jsxs("div",{className:"flex shrink-0 items-center gap-1",children:[Vt?s.jsxs(B,{type:"button",variant:"ghost",size:"xs",className:"!font-normal",onClick:()=>ji(ee?.localUrl),children:[s.jsx(L,{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:()=>{(Vt?g(f.id):k(f.id)).catch(rt=>D.error(t(Vt?"settings.remoteInstances.sidebar.toast.disconnectFailed":"settings.remoteInstances.sidebar.toast.connectFailed"),{description:rt instanceof Error?rt.message:String(rt)}))},children:[Vt?s.jsx(L,{name:"stop",className:"h-3.5 w-3.5"}):s.jsx(L,{name:"plug-2",className:"h-3.5 w-3.5"}),t(Vt?"settings.remoteInstances.sidebar.actions.disconnect":"settings.remoteInstances.sidebar.actions.connect")]}),s.jsxs(B,{type:"button",variant:"ghost",size:"xs",className:"!font-normal",onClick:()=>I(f.id),children:[s.jsx(L,{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"))&&N(f.id).catch(rt=>D.error(t("settings.remoteInstances.page.toast.removeInstanceFailed"),{description:rt instanceof Error?rt.message:String(rt)}))},children:[s.jsx(L,{name:"delete-bin",className:"h-3.5 w-3.5"}),t("settings.common.actions.delete")]})]})]}),ws?s.jsx("p",{className:"typography-micro text-[var(--status-error)] break-words",children:ws}):null]},f.id)})}):null,n?s.jsx(zt,{open:ns,onOpenChange:Zt,children:s.jsxs(_t,{className:"sm:max-w-lg",children:[s.jsxs(Gt,{children:[s.jsx(qt,{children:t("settings.remoteInstances.sidebar.actions.addSshInstance")}),s.jsx(Wt,{children:t("settings.remoteInstances.page.addDialog.description")})]}),s.jsx(Js,{value:os,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")}]}),os==="saved"?s.jsxs("div",{className:"space-y-2",children:[s.jsx(Ye,{className:"h-8",value:ct,onChange:f=>Ce(f.target.value),placeholder:t("settings.remoteInstances.page.addDialog.searchPlaceholder"),autoFocus:!0}),d?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")}):ma.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:ma.map(f=>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:[f.host,f.pattern?` ${t("settings.remoteInstances.page.import.patternSuffix")}`:""]}),s.jsx("div",{className:"typography-meta text-muted-foreground truncate",children:f.sshCommand})]}),s.jsx(B,{type:"button",variant:"outline",size:"xs",className:"!font-normal",onClick:()=>{_a(f.host,f.pattern)},children:t("settings.remoteInstances.page.addDialog.use")})]},`${f.source}:${f.host}`))})]}):s.jsxs("form",{className:"space-y-3",onSubmit:f=>{f.preventDefault(),mi()},children:[s.jsx(Ye,{className:"h-8",value:At,onChange:f=>Tt(f.target.value),placeholder:t("settings.remoteInstances.page.field.nicknamePlaceholder"),disabled:x}),s.jsx(Ye,{className:"h-8",value:it,onChange:f=>jt(f.target.value),placeholder:t("settings.remoteInstances.page.field.sshCommandPlaceholder"),disabled:x,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:()=>Zt(!1),disabled:x,children:t("settings.common.actions.cancel")}),s.jsx(B,{type:"submit",size:"xs",className:"!font-normal",disabled:x||!it.trim(),children:t("settings.common.actions.create")})]})]})]})}):null,s.jsx(zt,{open:!!Q,onOpenChange:f=>{f||Tn()},children:s.jsxs(_t,{className:"sm:max-w-md",children:[s.jsxs(Gt,{children:[s.jsx(qt,{children:t("settings.remoteInstances.page.patternDialog.title")}),s.jsx(Wt,{children:Q?t("settings.remoteInstances.page.patternDialog.descriptionWithHost",{host:Q}):t("settings.remoteInstances.page.patternDialog.description")})]}),s.jsxs("form",{className:"space-y-3",onSubmit:f=>{f.preventDefault(),Dn()},children:[s.jsx(Ye,{value:W,onChange:f=>Y(f.target.value),placeholder:t("settings.remoteInstances.page.patternDialog.destinationPlaceholder"),autoFocus:!0}),s.jsxs("div",{className:"flex items-center justify-end gap-2",children:[s.jsx(B,{type:"button",variant:"outline",size:"xs",className:"!font-normal",onClick:Tn,disabled:F,children:t("settings.common.actions.cancel")}),s.jsx(B,{type:"submit",size:"xs",className:"!font-normal",disabled:F,children:t("settings.remoteInstances.page.actions.create")})]})]})]})})]});const Rn=m.remoteOpenchamber.mode==="managed",fn=Rn&&m.remoteOpenchamber.bindHost==="0.0.0.0",qs=fn&&!m.auth.openchamberPassword?.value?.trim(),sa=m.nickname?.trim()||m.sshParsed?.destination||m.id;return s.jsx(zt,{open:!!m,onOpenChange:f=>{f||I(null)},children:s.jsxs(_t,{className:"sm:max-w-4xl max-h-[90vh] overflow-auto",children:[s.jsxs("div",{className:"mb-6 px-1",children:[s.jsx("h1",{className:`${Qi} truncate`,children:sa}),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 ${xo(Bs)}`}),s.jsx("span",{className:"text-foreground",children:t(ho(un))}),un==="connecting"?s.jsx("span",{children:t(uo(Bs))}):null,Ss?.localUrl?s.jsx("span",{className:"font-mono text-foreground/80",children:Ss.localUrl}):null,mn?s.jsx("span",{children:t("settings.remoteInstances.page.status.reconnectStale")}):null]})]}),s.jsxs(Be,{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:Ls?"outline":"default",size:"xs",className:"!font-normal",onClick:wi,disabled:z||X,children:[Ls?s.jsx(L,{name:"stop",className:"h-3.5 w-3.5"}):s.jsx(L,{name:"plug-2",className:"h-3.5 w-3.5"}),Ci]}),s.jsxs(B,{type:"button",variant:"outline",size:"xs",className:"!font-normal",onClick:ki,disabled:!Si,children:[s.jsx(L,{name:"refresh",className:`h-3.5 w-3.5 ${pn||on&&!mn?"animate-spin":""}`}),Ni]}),s.jsxs(B,{type:"button",variant:"outline",size:"xs",className:"!font-normal",onClick:()=>{hn()},children:[s.jsx(L,{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"))&&N(m.id).then(()=>{I(null),D.success(t("settings.remoteInstances.page.toast.instanceRemoved"))}).catch(ee=>{D.error(t("settings.remoteInstances.page.toast.removeInstanceFailed"),{description:ee instanceof Error?ee.message:String(ee)})})},children:[s.jsx(L,{name:"delete-bin",className:"h-3.5 w-3.5"}),t("settings.remoteInstances.sidebar.actions.remove")]})]}),un==="error"&&Ss?.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:Ss.detail}),be?s.jsx("p",{className:"typography-micro text-muted-foreground",children:t(be)}):null,Ys&&!be?s.jsx(B,{type:"button",variant:"outline",size:"xs",className:"!font-normal",onClick:()=>{ea(Ys)},children:t(Ys==="uiPassword"?"settings.remoteInstances.page.error.action.setUiPassword":Ys==="localPort"?"settings.remoteInstances.page.error.action.pickRandomPort":"settings.remoteInstances.page.error.action.setRemotePort")}):null]}):null,Ss?.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:Ss.localUrl})]}):null]}),s.jsxs(Be,{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(Ye,{className:"h-7 md:max-w-xl",value:m.sshCommand,onChange:f=>hs(ee=>({...ee,sshCommand:f.target.value})),placeholder:t("settings.remoteInstances.page.field.sshCommandPlaceholder")})]}),s.jsxs("div",{className:"flex flex-col gap-1.5 py-1.5 md:flex-row md:items-center md:gap-8",children:[s.jsx("span",{className:"typography-ui-label text-foreground w-56 shrink-0",children:t("settings.remoteInstances.page.field.nickname")}),s.jsx(Ye,{className:"h-7 md:max-w-sm",value:m.nickname||"",onChange:f=>hs(ee=>({...ee,nickname:f.target.value})),placeholder:t("settings.remoteInstances.page.field.nicknamePlaceholder")})]}),s.jsxs("div",{className:"flex flex-col gap-1.5 py-1.5 md:flex-row md:items-center md:gap-8",children:[s.jsx("div",{className:"w-56 shrink-0",children:s.jsx(zs,{label:t("settings.remoteInstances.page.field.mode"),hint:t("settings.remoteInstances.page.field.modeHint")})}),s.jsxs(Ot,{value:m.remoteOpenchamber.mode,onValueChange:f=>hs(ee=>({...ee,remoteOpenchamber:{...ee.remoteOpenchamber,mode:f==="external"?"external":"managed"}})),children:[s.jsx(Lt,{size:Jt,className:"w-fit min-w-[140px]",children:s.jsx(Ht,{placeholder:t("settings.remoteInstances.page.field.modePlaceholder")})}),s.jsxs(Ft,{children:[s.jsx(ut,{value:"managed",children:t("settings.remoteInstances.page.field.modeManaged")}),s.jsx(ut,{value:"external",children:t("settings.remoteInstances.page.field.modeExternal")})]})]})]})]}),s.jsxs(qn,{open:Xt,onOpenChange:ls,children:[s.jsxs(Wn,{className:"mt-6 w-auto justify-start gap-1.5",children:[s.jsx("span",{className:pl,children:t("settings.remoteInstances.page.section.advanced")}),s.jsx(L,{name:Xt?"arrow-up-s":"arrow-down-s",className:"h-4 w-4 text-muted-foreground"})]}),s.jsxs(Jn,{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(Is,{containerClassName:"w-fit",min:5,max:240,step:1,className:"w-16 tabular-nums",value:m.connectionTimeoutSec,onValueChange:f=>{hs(ee=>({...ee,connectionTimeoutSec:Number.isFinite(f)?f:ee.connectionTimeoutSec}))}})]}),s.jsxs(Be,{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:$a,children:s.jsx(zs,{label:t("settings.remoteInstances.page.field.preferredRemotePort"),hint:t("settings.remoteInstances.page.field.preferredRemotePortHint")})}),s.jsx(Is,{containerClassName:"w-fit",min:1,max:65535,step:1,className:"w-20 tabular-nums",value:m.remoteOpenchamber.preferredPort,onValueChange:f=>{hs(ee=>({...ee,remoteOpenchamber:{...ee.remoteOpenchamber,preferredPort:Number.isFinite(f)&&f>0?f:void 0}}))},onClear:()=>{hs(f=>({...f,remoteOpenchamber:{...f.remoteOpenchamber,preferredPort:void 0}}))},emptyLabel:t("settings.remoteInstances.page.field.auto")})]}),Rn?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(zs,{label:t("settings.remoteInstances.page.field.installMethod"),hint:t("settings.remoteInstances.page.field.installMethodHint")})}),s.jsxs(Ot,{value:m.remoteOpenchamber.installMethod,onValueChange:f=>hs(ee=>({...ee,remoteOpenchamber:{...ee.remoteOpenchamber,installMethod:f==="npm"||f==="bun"?f:"auto"}})),children:[s.jsx(Lt,{size:Jt,className:"w-fit min-w-[140px]",children:s.jsx(Ht,{placeholder:t("settings.remoteInstances.page.field.selectInstallMethodPlaceholder")})}),s.jsxs(Ft,{children:[s.jsx(ut,{value:"auto",children:t("settings.remoteInstances.page.field.installMethodAuto")}),s.jsx(ut,{value:"bun",children:"bun"}),s.jsx(ut,{value:"npm",children:"npm"})]})]})]}):null,Rn?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(zs,{label:t("settings.remoteInstances.page.field.remoteLanAccess"),hint:t("settings.remoteInstances.page.field.remoteLanAccessHint")})}),s.jsx(Pi,{checked:fn,onCheckedChange:f=>hs(ee=>({...ee,remoteOpenchamber:{...ee.remoteOpenchamber,bindHost:f?"0.0.0.0":"127.0.0.1"}})),"aria-label":t("settings.remoteInstances.page.field.remoteLanAccess")})]}),fn?s.jsx("p",{className:"mt-2 typography-micro text-[var(--status-warning)] md:pl-[16rem]",children:t("settings.remoteInstances.page.field.remoteLanAccessWarning")}):null]}):null,Rn?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(zs,{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(Pi,{checked:m.remoteOpenchamber.keepRunning,onCheckedChange:f=>hs(ee=>({...ee,remoteOpenchamber:{...ee.remoteOpenchamber,keepRunning:f}}))})})]}):null]}),s.jsxs(Be,{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(zs,{label:t("settings.remoteInstances.page.field.bindHost"),hint:t("settings.remoteInstances.page.field.bindHostHint")})}),s.jsxs(Ot,{value:m.localForward.bindHost,onValueChange:f=>{f==="0.0.0.0"&&!window.confirm(t("settings.remoteInstances.page.confirm.bindAllInterfaces"))||hs(ee=>({...ee,localForward:{...ee.localForward,bindHost:f==="localhost"||f==="0.0.0.0"?f:"127.0.0.1"}}))},children:[s.jsx(Lt,{size:Jt,className:"w-fit min-w-[240px]",children:s.jsx(Ht,{placeholder:t("settings.remoteInstances.page.field.selectBindHostPlaceholder")})}),s.jsxs(Ft,{children:[s.jsx(ut,{value:"127.0.0.1",children:t("settings.remoteInstances.page.field.bindHostOption.loopback")}),s.jsx(ut,{value:"localhost",children:t("settings.remoteInstances.page.field.bindHostOption.localhost")}),s.jsx(ut,{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(zs,{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(Is,{containerClassName:"w-fit",min:1,max:65535,step:1,className:"w-20 tabular-nums",value:m.localForward.preferredLocalPort,onValueChange:f=>{hs(ee=>({...ee,localForward:{...ee.localForward,preferredLocalPort:Number.isFinite(f)&&f>0?f:void 0}}))},onClear:()=>{hs(f=>({...f,localForward:{...f.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:()=>hs(f=>({...f,localForward:{...f.localForward,preferredLocalPort:ni()}})),children:s.jsx(L,{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:`${m.localForward.bindHost}:${m.localForward.preferredLocalPort||"auto"} → ${m.sshParsed?.destination||m.nickname||"remote"}:${m.remoteOpenchamber.preferredPort||"auto"}`})]})]}),s.jsxs(Be,{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(zs,{label:t("settings.remoteInstances.page.field.sshPasswordOptional"),hint:t("settings.remoteInstances.page.field.sshPasswordHint")})}),s.jsx(Ye,{className:"h-7 md:max-w-sm",type:"password",value:m.auth.sshPassword?.value||"",onChange:f=>hs(ee=>({...ee,auth:{...ee.auth,sshPassword:{enabled:f.target.value.trim().length>0,value:f.target.value,store:ee.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(zs,{label:t(fn?"settings.remoteInstances.page.field.uiPasswordRequired":"settings.remoteInstances.page.field.uiPasswordOptional"),hint:t(Rn?"settings.remoteInstances.page.field.uiPasswordHintManaged":"settings.remoteInstances.page.field.uiPasswordHintExternal")})}),s.jsx(Ye,{className:je("h-7 md:max-w-sm",qs&&"border-[var(--status-error)]"),type:"password",ref:Mn,"aria-invalid":qs,value:m.auth.openchamberPassword?.value||"",onChange:f=>hs(ee=>({...ee,auth:{...ee.auth,openchamberPassword:{enabled:f.target.value.trim().length>0,value:f.target.value,store:ee.auth.openchamberPassword?.store||"never"}}})),placeholder:t("settings.remoteInstances.page.field.uiPasswordPlaceholder")})]}),qs?s.jsx("p",{className:"typography-micro text-[var(--status-error)] md:pl-[16rem]",children:t("settings.remoteInstances.page.field.uiPasswordMissingForLan")}):null]}),s.jsxs(Be,{title:t("settings.remoteInstances.page.section.portForwards"),info:t("settings.remoteInstances.page.section.portForwardsDescription"),contentClassName:"space-y-2",children:[m.portForwards.length===0?s.jsx("p",{className:"typography-micro text-muted-foreground/80",children:t("settings.remoteInstances.page.empty.noExtraForwards")}):null,m.portForwards.map((f,ee)=>{const $e=Et=>{hs(is=>({...is,portForwards:is.portForwards.map((ha,Bt)=>Bt===ee?Et(ha):ha)}))},nt=f.type==="remote"?"Local target":"Local listen",Vt=f.type==="remote"?"Local host and port on your machine that receives traffic from remote -R listener.":"Local host and port where this forward listens on your machine.",Cs=f.type==="remote"?"Remote listen":"Remote target",ws=f.type==="remote"?"Remote host and port where SSH creates the -R listener.":"Remote host and port that receives traffic from local -L listener.",u=bo(f.localHost||"localhost",f.localPort),rt=bo(f.remoteHost||"localhost",f.remotePort),ts=f.type==="local"&&typeof f.localPort=="number"&&f.localPort>0,ps=ts?`http://${Mu(f.localHost)}:${f.localPort}`:"",Ts=!!_[f.id],Ws=f.type==="local"?t("settings.remoteInstances.page.forwardType.local"):f.type==="remote"?t("settings.remoteInstances.page.forwardType.remote"):t("settings.remoteInstances.page.forwardType.dynamic");return s.jsxs(qn,{open:Ts,onOpenChange:Et=>{V(is=>({...is,[f.id]:Et}))},className:`${ee>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(Wn,{className:"flex items-center gap-2 group",children:[s.jsx(L,{name:"arrow-down-s",className:`h-4 w-4 text-muted-foreground transition-transform ${Ts?"rotate-180":""}`}),s.jsx("span",{className:"typography-ui-label text-foreground truncate",children:Au(f)}),s.jsx("span",{className:"typography-micro text-muted-foreground/70 shrink-0",children:Ws})]})}),s.jsxs("div",{className:"flex items-center gap-2",children:[s.jsx(Pi,{checked:f.enabled,onCheckedChange:Et=>$e(is=>({...is,enabled:Et})),"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:()=>hs(Et=>({...Et,portForwards:Et.portForwards.filter(is=>is.id!==f.id)})),children:s.jsx(L,{name:"delete-bin",className:"h-3.5 w-3.5"})})]})]}),s.jsx(Jn,{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(zs,{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(Du(f.type))})]})})}),s.jsxs(Ot,{value:f.type,onValueChange:Et=>$e(is=>({...is,type:Et==="dynamic"||Et==="remote"?Et:"local"})),children:[s.jsx(Lt,{size:Jt,className:"w-fit min-w-[140px]",children:s.jsx(Ht,{placeholder:t("settings.remoteInstances.page.field.typePlaceholder")})}),s.jsxs(Ft,{children:[s.jsx(ut,{value:"local",children:t("settings.remoteInstances.page.forwardType.local")}),s.jsx(ut,{value:"remote",children:t("settings.remoteInstances.page.forwardType.remote")}),s.jsx(ut,{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(zs,{label:nt,hint:Vt})}),s.jsxs("div",{className:"flex items-center gap-1.5",children:[s.jsx(Ye,{className:"h-7 w-32",value:f.localHost||"127.0.0.1",onChange:Et=>$e(is=>({...is,localHost:Et.target.value})),placeholder:t("settings.remoteInstances.page.field.localHostPlaceholder")}),s.jsx("span",{className:"text-muted-foreground",children:":"}),s.jsx(Is,{containerClassName:"w-fit",min:1,max:65535,step:1,className:"w-16 tabular-nums",value:f.localPort,onValueChange:Et=>{$e(is=>({...is,localPort:Number.isFinite(Et)&&Et>0?Et:void 0}))},onClear:()=>{$e(Et=>({...Et,localPort:void 0}))},emptyLabel:t("settings.remoteInstances.page.field.auto")})]})]}),f.type!=="dynamic"?s.jsxs("div",{className:"flex flex-col gap-1.5 py-1.5 md:flex-row md:items-center md:gap-8",children:[s.jsx("div",{className:"w-56 shrink-0",children:s.jsx(zs,{label:Cs,hint:ws})}),s.jsxs("div",{className:"flex items-center gap-1.5",children:[s.jsx(Ye,{className:"h-7 w-32",value:f.remoteHost||"",onChange:Et=>$e(is=>({...is,remoteHost:Et.target.value})),placeholder:t("settings.remoteInstances.page.field.remoteHostPlaceholder")}),s.jsx("span",{className:"text-muted-foreground",children:":"}),s.jsx(Is,{containerClassName:"w-fit",min:1,max:65535,step:1,className:"w-16 tabular-nums",value:f.remotePort,onValueChange:Et=>{$e(is=>({...is,remotePort:Number.isFinite(Et)&&Et>0?Et:void 0}))},onClear:()=>{$e(Et=>({...Et,remotePort:void 0}))},emptyLabel:t("settings.remoteInstances.page.field.auto")})]})]}):null,s.jsxs("div",{className:"mt-2 flex flex-wrap items-center justify-between gap-2 rounded-md bg-[var(--surface-subtle)] p-2",children:[s.jsx("div",{className:"flex flex-wrap items-center gap-1 typography-micro text-muted-foreground/80",children:f.type==="dynamic"?s.jsxs(s.Fragment,{children:[s.jsx(L,{name:"computer",className:"h-3.5 w-3.5"}),s.jsx("span",{className:"font-mono text-foreground",children:u}),s.jsx("span",{children:t("settings.remoteInstances.page.preview.localSocks5")})]}):f.type==="remote"?s.jsxs(s.Fragment,{children:[s.jsx(L,{name:"server",className:"h-3.5 w-3.5"}),s.jsx("span",{className:"font-mono text-foreground",children:rt}),s.jsx("span",{children:t("settings.remoteInstances.page.preview.remote")}),s.jsx(L,{name:"arrow-right",className:"h-3.5 w-3.5"}),s.jsx(L,{name:"computer",className:"h-3.5 w-3.5"}),s.jsx("span",{className:"font-mono text-foreground",children:u}),s.jsx("span",{children:t("settings.remoteInstances.page.preview.local")})]}):s.jsxs(s.Fragment,{children:[s.jsx(L,{name:"computer",className:"h-3.5 w-3.5"}),s.jsx("span",{className:"font-mono text-foreground",children:u}),s.jsx("span",{children:t("settings.remoteInstances.page.preview.local")}),s.jsx(L,{name:"arrow-right",className:"h-3.5 w-3.5"}),s.jsx(L,{name:"server",className:"h-3.5 w-3.5"}),s.jsx("span",{className:"font-mono text-foreground",children:rt}),s.jsx("span",{children:t("settings.remoteInstances.page.preview.remote")})]})}),ts?s.jsxs(B,{type:"button",variant:"outline",size:"xs",className:"!font-normal",onClick:()=>{An(ps).then(Et=>{Et||D.error(t("settings.remoteInstances.page.toast.openLocalEndpointFailed"))})},children:[s.jsx(L,{name:"external-link",className:"h-3.5 w-3.5"}),t("settings.remoteInstances.page.actions.openLocal")]}):null]})]})})]},f.id)}),s.jsxs(B,{type:"button",variant:"outline",size:"xs",className:"!font-normal mt-1",onClick:()=>{const f=Eu();hs(ee=>({...ee,portForwards:[...ee.portForwards,f]})),V(ee=>({...ee,[f.id]:!0}))},children:[s.jsx(L,{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:()=>{za()},disabled:!xs||x,children:t("settings.common.actions.saveChanges")}),Ss?.localUrl?s.jsxs(s.Fragment,{children:[s.jsxs(B,{type:"button",variant:"outline",size:"xs",className:"!font-normal",onClick:()=>{Ta(Ss.localUrl||"").then(f=>{f.ok&&D.success(t("settings.remoteInstances.page.toast.localUrlCopied"))})},children:[s.jsx(L,{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:()=>{ga()},children:[s.jsx(L,{name:"external-link",className:"h-3.5 w-3.5"}),t("settings.remoteInstances.page.actions.open")]})]}):null,c?s.jsx("div",{className:"ml-auto typography-meta text-[var(--status-error)]",children:c}):null]})}),s.jsx(zt,{open:K,onOpenChange:C,children:s.jsxs(_t,{className:"sm:max-w-2xl",children:[s.jsxs(Gt,{children:[s.jsx(qt,{children:t("settings.remoteInstances.page.logsDialog.title")}),s.jsx(Wt,{children:m?.nickname?.trim()||m?.sshParsed?.destination||m?.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:ta,disabled:T||!Gs.trim(),children:[s.jsx(L,{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:()=>{ua()},disabled:T,children:[s.jsx(L,{name:"delete-bin",className:"h-3.5 w-3.5"}),t("settings.common.actions.clear")]})]}),T?s.jsx("div",{className:"typography-meta text-muted-foreground",children:t("settings.remoteInstances.page.logsDialog.loading")}):R?s.jsx("div",{className:"typography-meta text-[var(--status-error)]",children:R}):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:S.length>0?S.join(`
|
|
28
|
-
`):t("settings.remoteInstances.page.logsDialog.empty")})]})}),s.jsx(zt,{open:!!Q,onOpenChange:f=>{f||Tn()},children:s.jsxs(_t,{className:"sm:max-w-md",children:[s.jsxs(Gt,{children:[s.jsx(qt,{children:t("settings.remoteInstances.page.patternDialog.title")}),s.jsx(Wt,{children:Q?t("settings.remoteInstances.page.patternDialog.descriptionWithHost",{host:Q}):t("settings.remoteInstances.page.patternDialog.description")})]}),s.jsxs("form",{className:"space-y-3",onSubmit:f=>{f.preventDefault(),Dn()},children:[s.jsx(Ye,{value:W,onChange:f=>Y(f.target.value),placeholder:t("settings.remoteInstances.page.patternDialog.destinationPlaceholder"),autoFocus:!0}),s.jsxs("div",{className:"flex items-center justify-end gap-2",children:[s.jsx(B,{type:"button",variant:"outline",size:"xs",className:"!font-normal",onClick:Tn,disabled:F,children:t("settings.common.actions.cancel")}),s.jsx(B,{type:"submit",size:"xs",className:"!font-normal",disabled:F,children:t("settings.common.actions.create")})]})]})]})})]})})},zu="__add_provider__",_u=()=>{const t=cn.getDirectory();return typeof t=="string"&&t.trim().length>0?t.trim():null},$u=({onItemSelect:t})=>{const{t:e}=ot(),a=Us(),n=tt(b=>ml(b,a)),i=tt(b=>b.selectedProviderId),r=tt(b=>b.setSelectedProvider),l=Qs(b=>b.activeProjectId),[h,d]=o.useState({}),x=o.useMemo(()=>a||_u(),[l,a]),c=tt(b=>b.loadProviders);o.useEffect(()=>{a&&c({directory:a,source:"settings:providers"})},[c,a]),o.useEffect(()=>{if(n.length===0){d({});return}let b=!1;return(async()=>{const N=n.map(async k=>{try{const g=x?`?directory=${encodeURIComponent(x)}`:"",E=await pt(`/api/provider/${encodeURIComponent(k.id)}/source${g}`,{method:"GET",headers:{Accept:"application/json"}});if(!E.ok)return;const O=await E.json().catch(()=>null),I=O?.sources??O?.data?.sources;if(!I||b)return;d(w=>({...w,[k.id]:I}))}catch{}});await Promise.all(N)})(),()=>{b=!0}},[x,n]);const v="bg-background",p=o.useMemo(()=>n.filter(b=>!!h[b.id]?.project?.exists),[n,h]),A=o.useMemo(()=>n.filter(b=>!h[b.id]?.project?.exists),[n,h]);return s.jsxs("div",{className:je("flex h-full flex-col",v),children:[s.jsxs("div",{className:"border-b px-3 pt-4 pb-3",children:[s.jsx("h2",{className:`${rn} mb-3`,children:e("settings.providers.sidebar.title")}),s.jsx(Ka,{className:"mb-3"}),s.jsxs("div",{className:"flex items-center justify-between gap-2",children:[s.jsx("span",{className:"typography-meta text-muted-foreground",children:e("settings.providers.sidebar.total",{count:n.length})}),s.jsx(B,{size:"sm",variant:"ghost",className:"h-7 w-7 px-0 -my-1 text-muted-foreground",onClick:()=>{r(zu),t?.()},"aria-label":e("settings.providers.sidebar.actions.connectProviderAria"),title:e("settings.providers.sidebar.actions.connectProviderTitle"),children:s.jsx(L,{name:"add",className:"h-3.5 w-3.5"})})]})]}),s.jsx(Vs,{outerClassName:"flex-1 min-h-0",className:"space-y-1 px-3 py-2 overflow-x-hidden",children:n.length===0?s.jsxs("div",{className:"py-12 px-4 text-center text-muted-foreground",children:[s.jsx(L,{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:[A.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")}),A.map(b=>s.jsx(yo,{provider:b,selectedProviderId:i,onSelect:()=>{r(b.id),t?.()}},b.id))]}),p.length>0&&s.jsxs(s.Fragment,{children:[s.jsx("div",{className:je("px-2 pb-1.5 text-xs font-semibold uppercase tracking-wide text-muted-foreground",A.length>0?"pt-3":"pt-2"),children:e("settings.providers.sidebar.section.projectProviders")}),p.map(b=>s.jsx(yo,{provider:b,selectedProviderId:i,onSelect:()=>{r(b.id),t?.()}},b.id))]})]})})]})},yo=t=>{const e=mt.c(17),{provider:a,selectedProviderId:n,onSelect:i}=t,r=Array.isArray(a.models)?a.models.length:0,l=a.id===n,h=a.id,d=l?"bg-interactive-selection":"hover:bg-interactive-hover";let x;e[0]!==d?(x=je("group relative flex items-center rounded-md px-1.5 py-1 transition-all duration-200",d),e[0]=d,e[1]=x):x=e[1];let c;e[2]!==a.id?(c=s.jsx(Fn,{providerId:a.id,className:"h-4 w-4 flex-shrink-0"}),e[2]=a.id,e[3]=c):c=e[3];const v=a.name||a.id;let p;e[4]!==v?(p=s.jsx("span",{className:"typography-ui-label font-normal truncate flex-1 min-w-0 text-foreground",children:v}),e[4]=v,e[5]=p):p=e[5];let A;e[6]!==r?(A=s.jsx("span",{className:"typography-micro text-muted-foreground/60 flex-shrink-0",children:r}),e[6]=r,e[7]=A):A=e[7];let b;e[8]!==i||e[9]!==c||e[10]!==p||e[11]!==A?(b=s.jsxs("button",{type:"button",onClick:i,className:"flex min-w-0 flex-1 items-center gap-2 rounded-sm text-left focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-primary/50",tabIndex:0,children:[c,p,A]}),e[8]=i,e[9]=c,e[10]=p,e[11]=A,e[12]=b):b=e[12];let P;return e[13]!==a.id||e[14]!==x||e[15]!==b?(P=s.jsx("div",{className:x,children:b},h),e[13]=a.id,e[14]=x,e[15]=b,e[16]=P):P=e[16],P},Vu=t=>t,jo=(t,e,a)=>t&&!e&&!a,wo=t=>typeof t=="object"&&t!==null,Ll=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()},Bu=t=>{if(!wo(t))return{};const e={};for(const[a,n]of Object.entries(t))Array.isArray(n)&&(e[a]=n.filter(i=>wo(i)));return e},ko=t=>t.length===0?!0:t.some(e=>Ll(e)==="api"),No=t=>t.map((e,a)=>({method:e,methodIndex:a})).filter(({method:e})=>Ll(e)==="oauth"),Hu=t=>t!=="claude-code",br={"openai-chat":"@ai-sdk/openai-compatible","openai-responses":"@ai-sdk/openai","anthropic-messages":"@ai-sdk/anthropic"},On="__custom_provider__",Gu=/^[a-z0-9][a-z0-9-_]*$/,Fl=/^https?:\/\//,qu=/^\{env:([^}]+)\}$/;let Wu=0;const li=()=>`row-${Wu++}`,vr=()=>({row:li(),id:"",name:""}),yr=()=>({row:li(),key:"",value:""}),Ju=()=>({providerID:"",name:"",protocol:"openai-chat",baseURL:"",apiKey:"",models:[vr()],headers:[yr()]});function Qu(t){switch(t){case"@ai-sdk/openai":return"openai-responses";case"@ai-sdk/anthropic":return"anthropic-messages";default:return"openai-chat"}}function Yu(t){const e=t.trim();if(!e)return{};const n=e.match(qu)?.[1]?.trim();return n?{env:n}:{key:e}}function Zu(t){const e=t.options&&typeof t.options=="object"?t.options:null,a=typeof e?.baseURL=="string"?e.baseURL.trim():"";return a&&Fl.test(a)?!0:(Array.isArray(t.models)?t.models:t.models&&typeof t.models=="object"?Object.values(t.models):[]).some(i=>{if(!i||typeof i!="object")return!1;const r="api"in i&&i.api&&typeof i.api=="object"?i.api:null;return typeof r?.npm=="string"&&new Set(Object.values(br)).has(r.npm)})}function So(t,e){return e?!!(e.user?.exists||e.project?.exists||e.custom?.exists)&&Zu(t):!1}function Co(t){return t?.custom?.exists?"custom":t?.project?.exists?"project":"user"}function Xu(t){const e=t.options&&typeof t.options=="object"?t.options:{},a=typeof e.baseURL=="string"?e.baseURL:"",n=e.headers&&typeof e.headers=="object"&&!Array.isArray(e.headers)?e.headers:{},i=Object.entries(n).filter(x=>typeof x[0]=="string"&&typeof x[1]=="string").map(([x,c])=>({row:li(),key:x,value:c})),r=Array.isArray(t.models)?t.models:t.models&&typeof t.models=="object"?Object.entries(t.models).map(([x,c])=>({id:x,name:c&&typeof c=="object"&&"name"in c&&typeof c.name=="string"?c.name:x})):[],l=r.length>0?r.map(x=>({row:li(),id:typeof x?.id=="string"?x.id:"",name:typeof x?.name=="string"?x.name:typeof x?.id=="string"?x.id:""})):[vr()],h=Array.isArray(t.env)?t.env.find(x=>typeof x=="string"&&x.trim().length>0)?.trim():void 0,d=r.find(x=>"api"in x);return{providerID:t.id,name:typeof t.name=="string"&&t.name.trim()?t.name:t.id,protocol:Qu(d?.api?.npm),baseURL:a,apiKey:h?`{env:${h}}`:"",models:l,headers:i.length>0?i:[yr()]}}function eg(t){const e=t.form.providerID.trim(),a=t.form.name.trim(),n=t.form.baseURL.trim(),{env:i,key:r}=Yu(t.form.apiKey),l=t.disabledProviders??[],h=t.editingProviderID?.trim(),d=e?Gu.test(e)?void 0:t.t("settings.providers.page.custom.error.providerID.format"):t.t("settings.providers.page.custom.error.providerID.required"),x=a?void 0:t.t("settings.providers.page.custom.error.name.required"),c=n?Fl.test(n)?void 0:t.t("settings.providers.page.custom.error.baseURL.format"):t.t("settings.providers.page.custom.error.baseURL.required"),p=!!(i||r||h&&t.allowExistingAuth&&h===e)?void 0:t.t("settings.providers.page.custom.error.apiKey.required"),A=l.includes(e),P=d||!!(h&&h===e)?void 0:t.existingProviderIDs.has(e)&&!A?t.t("settings.providers.page.custom.error.providerID.exists"):void 0,N=new Set,k=t.form.models.map(C=>{const T=C.id.trim(),j=T?N.has(T)?t.t("settings.providers.page.custom.error.duplicate"):void N.add(T):t.t("settings.providers.page.custom.error.required"),R=C.name.trim()?void 0:t.t("settings.providers.page.custom.error.required");return{id:j,name:R}}),g=k.every(C=>!C.id&&!C.name),E=Object.fromEntries(t.form.models.map(C=>[C.id.trim(),{name:C.name.trim()}])),O=new Set,I=t.form.headers.map(C=>{const T=C.key.trim(),j=C.value.trim();if(!T&&!j)return{};const R=T?O.has(T.toLowerCase())?t.t("settings.providers.page.custom.error.duplicate"):void O.add(T.toLowerCase()):t.t("settings.providers.page.custom.error.required"),G=j?void 0:t.t("settings.providers.page.custom.error.required");return{key:R,value:G}}),w=I.every(C=>!C.key&&!C.value),m=Object.fromEntries(t.form.headers.map(C=>({key:C.key.trim(),value:C.value.trim()})).filter(C=>C.key&&C.value).map(C=>[C.key,C.value])),y={providerID:d??P,name:x,baseURL:c,apiKey:p};return!d&&!P&&!x&&!c&&!p&&g&&w?{err:y,models:k,headers:I,result:{providerID:e,name:a,apiKey:r,config:{npm:br[t.form.protocol],name:a,...i?{env:[i]}:{},options:{baseURL:n,...Object.keys(m).length>0?{headers:m}:{}},models:E}}}:{err:y,models:k,headers:I}}function tg(t){return t.apiKey?{providerID:t.providerID,auth:{type:"api",key:t.apiKey}}:null}function sg(t,e){return{providerID:t.providerID,config:t.config,scope:e?.scope??"user"}}const Po=t=>{const e=mt.c(234),{existingProviderIDs:a,disabledProviders:n,busy:i,mode:r,initialValues:l,allowExistingAuth:h,authFailureHint:d,onSubmit:x,onCancel:c,onDisconnect:v}=t;let p;e[0]!==n?(p=n===void 0?[]:n,e[0]=n,e[1]=p):p=e[1];const A=p,b=i===void 0?!1:i,P=r===void 0?"create":r,N=h===void 0?!1:h,k=d===void 0?null:d,{t:g}=ot(),E=P==="edit";let O;e[2]!==l?(O=()=>l??Ju(),e[2]=l,e[3]=O):O=e[3];const[I,w]=o.useState(O);let m;e[4]===Symbol.for("react.memo_cache_sentinel")?(m={},e[4]=m):m=e[4];const[y,K]=o.useState(m);let C;e[5]===Symbol.for("react.memo_cache_sentinel")?(C=[],e[5]=C):C=e[5];const[T,j]=o.useState(C);let R;e[6]===Symbol.for("react.memo_cache_sentinel")?(R=[],e[6]=R):R=e[6];const[G,S]=o.useState(R),q=o.useRef(null);let Q,M;e[7]!==l||e[8]!==E?(Q=()=>{l&&(E&&q.current===l.providerID||(q.current=E?l.providerID:null,w(l),K({}),j([]),S([])))},M=[l,E],e[7]=l,e[8]=E,e[9]=Q,e[10]=M):(Q=e[9],M=e[10]),o.useEffect(Q,M);let W;e[11]===Symbol.for("react.memo_cache_sentinel")?(W=(ft,Pt)=>{w(Dt=>({...Dt,[ft]:Pt})),K(Dt=>({...Dt,[ft]:void 0}))},e[11]=W):W=e[11];const Y=W;let F;e[12]===Symbol.for("react.memo_cache_sentinel")?(F=(ft,Pt,Dt)=>{w(Mt=>({...Mt,models:Mt.models.map((Ut,js)=>js===ft?{...Ut,[Pt]:Dt}:Ut)})),j(Mt=>{const Ut=[...Mt];return Ut[ft]={...Ut[ft]??{},[Pt]:void 0},Ut})},e[12]=F):F=e[12];const se=F;let _;e[13]===Symbol.for("react.memo_cache_sentinel")?(_=(ft,Pt,Dt)=>{w(Mt=>({...Mt,headers:Mt.headers.map((Ut,js)=>js===ft?{...Ut,[Pt]:Dt}:Ut)})),S(Mt=>{const Ut=[...Mt];return Ut[ft]={...Ut[ft]??{},[Pt]:void 0},Ut})},e[13]=_):_=e[13];const V=_;let z;e[14]!==N||e[15]!==b||e[16]!==A||e[17]!==a||e[18]!==I||e[19]!==E||e[20]!==x||e[21]!==g?(z=async ft=>{if(ft.preventDefault(),b)return;const Pt=eg({form:I,t:((Dt,Mt)=>g(Dt,Mt)),existingProviderIDs:a,disabledProviders:A,editingProviderID:E?I.providerID:void 0,allowExistingAuth:E&&N});K(Pt.err),j(Pt.models),S(Pt.headers),Pt.result&&await x(Pt.result)},e[14]=N,e[15]=b,e[16]=A,e[17]=a,e[18]=I,e[19]=E,e[20]=x,e[21]=g,e[22]=z):z=e[22];const U=z;let X;e[23]!==E||e[24]!==g?(X=g(E?"settings.providers.page.custom.editTitle":"settings.providers.page.custom.title"),e[23]=E,e[24]=g,e[25]=X):X=e[25];let Z;e[26]!==g?(Z=g("settings.providers.page.custom.description"),e[26]=g,e[27]=Z):Z=e[27];let ne;e[28]!==Z?(ne=s.jsx("p",{className:Ln,children:Z}),e[28]=Z,e[29]=ne):ne=e[29];let le;e[30]!==k?(le=k?s.jsx("p",{className:"typography-meta text-[var(--status-warning)]",role:"status",children:k}):null,e[30]=k,e[31]=le):le=e[31];let re;e[32]!==g?(re=g("settings.providers.page.custom.field.providerID.label"),e[32]=g,e[33]=re):re=e[33];let fe;e[34]!==g?(fe=g("settings.providers.page.custom.field.providerID.info"),e[34]=g,e[35]=fe):fe=e[35];const ae=I.providerID;let ie;e[36]===Symbol.for("react.memo_cache_sentinel")?(ie=ft=>Y("providerID",ft.target.value),e[36]=ie):ie=e[36];let te;e[37]!==g?(te=g("settings.providers.page.custom.field.providerID.placeholder"),e[37]=g,e[38]=te):te=e[38];const ye=!E,we=E||b,ke=!!y.providerID;let xe;e[39]!==g?(xe=g("settings.providers.page.custom.field.providerID.label"),e[39]=g,e[40]=xe):xe=e[40];let De;e[41]!==I.providerID||e[42]!==te||e[43]!==ye||e[44]!==we||e[45]!==ke||e[46]!==xe?(De=s.jsx(Ye,{value:ae,onChange:ie,placeholder:te,className:"h-8 rounded-md px-3 font-mono text-xs",autoFocus:ye,disabled:we,"aria-invalid":ke,"aria-label":xe}),e[41]=I.providerID,e[42]=te,e[43]=ye,e[44]=we,e[45]=ke,e[46]=xe,e[47]=De):De=e[47];let Me;e[48]!==y.providerID?(Me=y.providerID?s.jsx("p",{className:"mt-1 typography-meta text-[var(--status-error)]",children:y.providerID}):null,e[48]=y.providerID,e[49]=Me):Me=e[49];let he;e[50]!==re||e[51]!==fe||e[52]!==De||e[53]!==Me?(he=s.jsxs(es,{label:re,info:fe,children:[De,Me]}),e[50]=re,e[51]=fe,e[52]=De,e[53]=Me,e[54]=he):he=e[54];let ge;e[55]!==g?(ge=g("settings.providers.page.custom.field.protocol.label"),e[55]=g,e[56]=ge):ge=e[56];let Ae;e[57]!==g?(Ae=g("settings.providers.page.custom.field.protocol.info"),e[57]=g,e[58]=Ae):Ae=e[58];const Ve=I.protocol;let _e;e[59]===Symbol.for("react.memo_cache_sentinel")?(_e=ft=>{ft in br&&w(Pt=>({...Pt,protocol:ft}))},e[59]=_e):_e=e[59];let Le;e[60]!==g?(Le=g("settings.providers.page.custom.field.protocol.label"),e[60]=g,e[61]=Le):Le=e[61];let Re;e[62]===Symbol.for("react.memo_cache_sentinel")?(Re=s.jsx(Ht,{}),e[62]=Re):Re=e[62];let Ze;e[63]!==Le?(Ze=s.jsx(Lt,{"aria-label":Le,className:"w-full",children:Re}),e[63]=Le,e[64]=Ze):Ze=e[64];let Ge;e[65]!==g?(Ge=g("settings.providers.page.custom.field.protocol.openaiChat"),e[65]=g,e[66]=Ge):Ge=e[66];let Oe;e[67]!==Ge?(Oe=s.jsx(ut,{value:"openai-chat",children:Ge}),e[67]=Ge,e[68]=Oe):Oe=e[68];let Ke;e[69]!==g?(Ke=g("settings.providers.page.custom.field.protocol.openaiResponses"),e[69]=g,e[70]=Ke):Ke=e[70];let Pe;e[71]!==Ke?(Pe=s.jsx(ut,{value:"openai-responses",children:Ke}),e[71]=Ke,e[72]=Pe):Pe=e[72];let Ue;e[73]!==g?(Ue=g("settings.providers.page.custom.field.protocol.anthropicMessages"),e[73]=g,e[74]=Ue):Ue=e[74];let ve;e[75]!==Ue?(ve=s.jsx(ut,{value:"anthropic-messages",children:Ue}),e[75]=Ue,e[76]=ve):ve=e[76];let We;e[77]!==Oe||e[78]!==Pe||e[79]!==ve?(We=s.jsxs(Ft,{children:[Oe,Pe,ve]}),e[77]=Oe,e[78]=Pe,e[79]=ve,e[80]=We):We=e[80];let $;e[81]!==b||e[82]!==I.protocol||e[83]!==Ze||e[84]!==We?($=s.jsxs(Ot,{value:Ve,onValueChange:_e,disabled:b,children:[Ze,We]}),e[81]=b,e[82]=I.protocol,e[83]=Ze,e[84]=We,e[85]=$):$=e[85];let de;e[86]!==ge||e[87]!==Ae||e[88]!==$?(de=s.jsx(es,{label:ge,info:Ae,children:$}),e[86]=ge,e[87]=Ae,e[88]=$,e[89]=de):de=e[89];let ue;e[90]!==g?(ue=g("settings.providers.page.custom.field.name.label"),e[90]=g,e[91]=ue):ue=e[91];let Ne;e[92]!==g?(Ne=g("settings.providers.page.custom.field.name.info"),e[92]=g,e[93]=Ne):Ne=e[93];const pe=I.name;let Fe;e[94]===Symbol.for("react.memo_cache_sentinel")?(Fe=ft=>Y("name",ft.target.value),e[94]=Fe):Fe=e[94];let H;e[95]!==g?(H=g("settings.providers.page.custom.field.name.placeholder"),e[95]=g,e[96]=H):H=e[96];const He=!!y.name;let et;e[97]!==g?(et=g("settings.providers.page.custom.field.name.label"),e[97]=g,e[98]=et):et=e[98];let ze;e[99]!==I.name||e[100]!==H||e[101]!==He||e[102]!==et?(ze=s.jsx(Ye,{value:pe,onChange:Fe,placeholder:H,className:"h-8 rounded-md px-3","aria-invalid":He,"aria-label":et}),e[99]=I.name,e[100]=H,e[101]=He,e[102]=et,e[103]=ze):ze=e[103];let st;e[104]!==y.name?(st=y.name?s.jsx("p",{className:"mt-1 typography-meta text-[var(--status-error)]",children:y.name}):null,e[104]=y.name,e[105]=st):st=e[105];let wt;e[106]!==ue||e[107]!==Ne||e[108]!==ze||e[109]!==st?(wt=s.jsxs(es,{label:ue,info:Ne,children:[ze,st]}),e[106]=ue,e[107]=Ne,e[108]=ze,e[109]=st,e[110]=wt):wt=e[110];let xt;e[111]!==g?(xt=g("settings.providers.page.custom.field.baseURL.label"),e[111]=g,e[112]=xt):xt=e[112];let gt;e[113]!==g?(gt=g("settings.providers.page.custom.field.baseURL.info"),e[113]=g,e[114]=gt):gt=e[114];const bt=I.baseURL;let St;e[115]===Symbol.for("react.memo_cache_sentinel")?(St=ft=>Y("baseURL",ft.target.value),e[115]=St):St=e[115];let yt;e[116]!==g?(yt=g("settings.providers.page.custom.field.baseURL.placeholder"),e[116]=g,e[117]=yt):yt=e[117];const It=!!y.baseURL;let qe;e[118]!==g?(qe=g("settings.providers.page.custom.field.baseURL.label"),e[118]=g,e[119]=qe):qe=e[119];let Qe;e[120]!==I.baseURL||e[121]!==yt||e[122]!==It||e[123]!==qe?(Qe=s.jsx(Ye,{value:bt,onChange:St,placeholder:yt,className:"h-8 rounded-md px-3 font-mono text-xs","aria-invalid":It,"aria-label":qe}),e[120]=I.baseURL,e[121]=yt,e[122]=It,e[123]=qe,e[124]=Qe):Qe=e[124];let dt;e[125]!==y.baseURL?(dt=y.baseURL?s.jsx("p",{className:"mt-1 typography-meta text-[var(--status-error)]",children:y.baseURL}):null,e[125]=y.baseURL,e[126]=dt):dt=e[126];let Ee;e[127]!==xt||e[128]!==gt||e[129]!==Qe||e[130]!==dt?(Ee=s.jsxs(es,{label:xt,info:gt,children:[Qe,dt]}),e[127]=xt,e[128]=gt,e[129]=Qe,e[130]=dt,e[131]=Ee):Ee=e[131];let vt;e[132]!==g?(vt=g("settings.providers.page.custom.field.apiKey.label"),e[132]=g,e[133]=vt):vt=e[133];let Se;e[134]!==N||e[135]!==E||e[136]!==g?(Se=g(E&&N?"settings.providers.page.custom.field.apiKey.editInfo":"settings.providers.page.custom.field.apiKey.info"),e[134]=N,e[135]=E,e[136]=g,e[137]=Se):Se=e[137];const kt=I.apiKey;let J;e[138]===Symbol.for("react.memo_cache_sentinel")?(J=ft=>Y("apiKey",ft.target.value),e[138]=J):J=e[138];let me;e[139]!==N||e[140]!==E||e[141]!==g?(me=g(E&&N?"settings.providers.page.custom.field.apiKey.editPlaceholder":"settings.providers.page.custom.field.apiKey.placeholder"),e[139]=N,e[140]=E,e[141]=g,e[142]=me):me=e[142];const Te=!!y.apiKey;let Ie;e[143]!==g?(Ie=g("settings.providers.page.custom.field.apiKey.label"),e[143]=g,e[144]=Ie):Ie=e[144];let lt;e[145]!==I.apiKey||e[146]!==me||e[147]!==Te||e[148]!==Ie?(lt=s.jsx(Ye,{type:"password",value:kt,onChange:J,placeholder:me,className:"h-8 rounded-md px-3 font-mono text-xs","aria-invalid":Te,"aria-label":Ie}),e[145]=I.apiKey,e[146]=me,e[147]=Te,e[148]=Ie,e[149]=lt):lt=e[149];let at;e[150]!==y.apiKey?(at=y.apiKey?s.jsx("p",{className:"mt-1 typography-meta text-[var(--status-error)]",children:y.apiKey}):null,e[150]=y.apiKey,e[151]=at):at=e[151];let Je;e[152]!==vt||e[153]!==Se||e[154]!==lt||e[155]!==at?(Je=s.jsxs(es,{label:vt,info:Se,children:[lt,at]}),e[152]=vt,e[153]=Se,e[154]=lt,e[155]=at,e[156]=Je):Je=e[156];let Ct;e[157]!==X||e[158]!==ne||e[159]!==le||e[160]!==he||e[161]!==de||e[162]!==wt||e[163]!==Ee||e[164]!==Je?(Ct=s.jsxs(Be,{title:X,divider:!1,settingsItem:"providers.custom",contentClassName:Sn,children:[ne,le,he,de,wt,Ee,Je]}),e[157]=X,e[158]=ne,e[159]=le,e[160]=he,e[161]=de,e[162]=wt,e[163]=Ee,e[164]=Je,e[165]=Ct):Ct=e[165];let rs;e[166]!==g?(rs=g("settings.providers.page.custom.models.title"),e[166]=g,e[167]=rs):rs=e[167];let Yt;if(e[168]!==I.models||e[169]!==T||e[170]!==g){let ft;e[172]!==I.models.length||e[173]!==T||e[174]!==g?(ft=(Pt,Dt)=>s.jsx("div",{className:`${Ks} 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:Rt,children:g("settings.providers.page.custom.models.idLabel")}),s.jsx(Ye,{value:Pt.id,onChange:Mt=>se(Dt,"id",Mt.target.value),placeholder:g("settings.providers.page.custom.models.idPlaceholder"),className:"mt-1 h-8 rounded-md px-3 font-mono text-xs","aria-label":g("settings.providers.page.custom.models.idLabel")}),T[Dt]?.id?s.jsx("p",{className:"mt-1 typography-meta text-[var(--status-error)]",children:T[Dt]?.id}):null]}),s.jsxs("div",{children:[s.jsx("label",{className:Rt,children:g("settings.providers.page.custom.models.nameLabel")}),s.jsx(Ye,{value:Pt.name,onChange:Mt=>se(Dt,"name",Mt.target.value),placeholder:g("settings.providers.page.custom.models.namePlaceholder"),className:"mt-1 h-8 rounded-md px-3","aria-label":g("settings.providers.page.custom.models.nameLabel")}),T[Dt]?.name?s.jsx("p",{className:"mt-1 typography-meta text-[var(--status-error)]",children:T[Dt]?.name}):null]})]}),s.jsx(B,{type:"button",variant:"ghost",size:"icon",className:ks,disabled:I.models.length<=1,onClick:()=>{I.models.length<=1||(w(Mt=>({...Mt,models:Mt.models.filter((Ut,js)=>js!==Dt)})),j(Mt=>Mt.filter((Ut,js)=>js!==Dt)))},"aria-label":g("settings.providers.page.custom.models.remove"),children:s.jsx(L,{name:"delete-bin",className:"size-4"})})]})},Pt.row),e[172]=I.models.length,e[173]=T,e[174]=g,e[175]=ft):ft=e[175],Yt=I.models.map(ft),e[168]=I.models,e[169]=T,e[170]=g,e[171]=Yt}else Yt=e[171];let ys;e[176]===Symbol.for("react.memo_cache_sentinel")?(ys=()=>{w(ng),j(ag)},e[176]=ys):ys=e[176];let $t;e[177]!==g?($t=g("settings.providers.page.custom.models.add"),e[177]=g,e[178]=$t):$t=e[178];let cs;e[179]!==$t?(cs=s.jsx(B,{type:"button",variant:"outline",size:"xs",className:"!font-normal",onClick:ys,children:$t}),e[179]=$t,e[180]=cs):cs=e[180];let Kt;e[181]!==rs||e[182]!==Yt||e[183]!==cs?(Kt=s.jsxs(Be,{title:rs,contentClassName:Sn,children:[Yt,cs]}),e[181]=rs,e[182]=Yt,e[183]=cs,e[184]=Kt):Kt=e[184];let ds;e[185]!==g?(ds=g("settings.providers.page.custom.headers.title"),e[185]=g,e[186]=ds):ds=e[186];let as;e[187]!==g?(as=g("settings.providers.page.custom.headers.description"),e[187]=g,e[188]=as):as=e[188];let ns;e[189]!==as?(ns=s.jsx("p",{className:Ln,children:as}),e[189]=as,e[190]=ns):ns=e[190];let Zt;if(e[191]!==I.headers||e[192]!==G||e[193]!==g){let ft;e[195]!==I.headers.length||e[196]!==G||e[197]!==g?(ft=(Pt,Dt)=>s.jsx("div",{className:`${Ks} 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:Rt,children:g("settings.providers.page.custom.headers.keyLabel")}),s.jsx(Ye,{value:Pt.key,onChange:Mt=>V(Dt,"key",Mt.target.value),placeholder:g("settings.providers.page.custom.headers.keyPlaceholder"),className:"mt-1 h-8 rounded-md px-3 font-mono text-xs","aria-label":g("settings.providers.page.custom.headers.keyLabel")}),G[Dt]?.key?s.jsx("p",{className:"mt-1 typography-meta text-[var(--status-error)]",children:G[Dt]?.key}):null]}),s.jsxs("div",{children:[s.jsx("label",{className:Rt,children:g("settings.providers.page.custom.headers.valueLabel")}),s.jsx(Ye,{value:Pt.value,onChange:Mt=>V(Dt,"value",Mt.target.value),placeholder:g("settings.providers.page.custom.headers.valuePlaceholder"),className:"mt-1 h-8 rounded-md px-3 font-mono text-xs","aria-label":g("settings.providers.page.custom.headers.valueLabel")}),G[Dt]?.value?s.jsx("p",{className:"mt-1 typography-meta text-[var(--status-error)]",children:G[Dt]?.value}):null]})]}),s.jsx(B,{type:"button",variant:"ghost",size:"icon",className:ks,disabled:I.headers.length<=1,onClick:()=>{I.headers.length<=1||(w(Mt=>({...Mt,headers:Mt.headers.filter((Ut,js)=>js!==Dt)})),S(Mt=>Mt.filter((Ut,js)=>js!==Dt)))},"aria-label":g("settings.providers.page.custom.headers.remove"),children:s.jsx(L,{name:"delete-bin",className:"size-4"})})]})},Pt.row),e[195]=I.headers.length,e[196]=G,e[197]=g,e[198]=ft):ft=e[198],Zt=I.headers.map(ft),e[191]=I.headers,e[192]=G,e[193]=g,e[194]=Zt}else Zt=e[194];let os;e[199]===Symbol.for("react.memo_cache_sentinel")?(os=()=>{w(ig),S(rg)},e[199]=os):os=e[199];let oe;e[200]!==g?(oe=g("settings.providers.page.custom.headers.add"),e[200]=g,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:os,children:oe}),e[202]=oe,e[203]=ct):ct=e[203];let Ce;e[204]!==ds||e[205]!==ns||e[206]!==Zt||e[207]!==ct?(Ce=s.jsxs(Be,{title:ds,contentClassName:Sn,children:[ns,Zt,ct]}),e[204]=ds,e[205]=ns,e[206]=Zt,e[207]=ct,e[208]=Ce):Ce=e[208];let it;e[209]!==b||e[210]!==c||e[211]!==g?(it=c?s.jsx(B,{type:"button",variant:"outline",size:"xs",className:"!font-normal",onClick:c,disabled:b,children:g("settings.providers.page.custom.actions.back")}):null,e[209]=b,e[210]=c,e[211]=g,e[212]=it):it=e[212];let jt;e[213]!==b||e[214]!==v||e[215]!==g?(jt=v?s.jsx(B,{type:"button",variant:"destructive",size:"xs",className:"!font-normal",onClick:()=>{v()},disabled:b,children:g("settings.providers.page.actions.disconnect")}):null,e[213]=b,e[214]=v,e[215]=g,e[216]=jt):jt=e[216];let At;e[217]!==b||e[218]!==E||e[219]!==g?(At=g(b?"settings.providers.page.actions.saving":E?"settings.providers.page.custom.actions.update":"settings.providers.page.custom.actions.save"),e[217]=b,e[218]=E,e[219]=g,e[220]=At):At=e[220];let Tt;e[221]!==b||e[222]!==At?(Tt=s.jsx(B,{type:"submit",size:"xs",className:"!font-normal",disabled:b,children:At}),e[221]=b,e[222]=At,e[223]=Tt):Tt=e[223];let Xt;e[224]!==it||e[225]!==jt||e[226]!==Tt?(Xt=s.jsxs("div",{className:"flex flex-wrap items-center gap-2 py-4",children:[it,jt,Tt]}),e[224]=it,e[225]=jt,e[226]=Tt,e[227]=Xt):Xt=e[227];let ls;return e[228]!==U||e[229]!==Ct||e[230]!==Kt||e[231]!==Ce||e[232]!==Xt?(ls=s.jsxs("form",{onSubmit:U,className:"space-y-0",children:[Ct,Kt,Ce,Xt]}),e[228]=U,e[229]=Ct,e[230]=Kt,e[231]=Ce,e[232]=Xt,e[233]=ls):ls=e[233],ls};function ng(t){return{...t,models:[...t.models,vr()]}}function ag(t){return[...t,{}]}function ig(t){return{...t,headers:[...t.headers,yr()]}}function rg(t){return[...t,{}]}const og=(t,e)=>!!e&&t!=="claude-code",lg=/[A-Z0-9]{4}-[A-Z0-9]{4,5}/,Qn=t=>typeof t=="object"&&t!==null&&!Array.isArray(t),Ps=t=>typeof t=="string"&&t.length>0?t:void 0,cg=t=>{if(!Array.isArray(t))return[];const e=[];for(const a of t){if(!Qn(a))continue;const n=Ps(a.value);n!==void 0&&e.push({value:n,label:Ps(a.label)??n,...Ps(a.hint)?{hint:Ps(a.hint)}:{}})}return e},dg=t=>{if(!Qn(t))return;const e=Ps(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}},pg=t=>{if(!Array.isArray(t))return[];const e=[];for(const a of t){if(!Qn(a))continue;const n=Ps(a.key);if(!n)continue;const i=a.type==="select"?"select":"text",r=i==="select"?cg(a.options):[];if(i==="select"&&r.length===0)continue;const l=dg(a.when);e.push({type:i,key:n,message:Ps(a.message)??n,options:r,...Ps(a.placeholder)?{placeholder:Ps(a.placeholder)}:{},...l?{when:l}:{}})}return e},mg=(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},jr=(t,e)=>t.filter(a=>mg(a,e)),ug=t=>{const e={};for(const a of t)e[a.key]=a.type==="select"?a.options[0]?.value??"":"";return e},gg=(t,e)=>jr(t,e).find(a=>(e[a.key]??"").trim().length===0)??null,hg=(t,e)=>{const a={};for(const n of jr(t,e))a[n.key]=(e[n.key]??"").trim();return a},fg=t=>{const e=Qn(t)?t:{},a=Qn(e.data)?e.data:e,n=Ps(a.url)??Ps(a.verification_uri_complete)??Ps(a.verification_uri),i=Ps(a.instructions)??Ps(a.message);if(!n&&!i)return null;const r=Ps(a.user_code)??Ps(a.userCode)??(i?lg.exec(i)?.[0]:void 0);return{method:a.method==="code"?"code":"auto",...n?{url:n}:{},...i?{instructions:i}:{},...r?{userCode:r}:{}}},Io=(t,e,a)=>{const n=Qn(t)?t:{},i=Qn(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 Ps(i.message)??e("settings.providers.page.auth.oauth.error.invalidInput");default:return e(a)}},Ki={phase:"idle"},Ao=({providerId:t,methods:e,onConnected:a,className:n})=>{const{t:i}=ot(),[r,l]=o.useState(Ki),[h,d]=o.useState({}),[x,c]=o.useState(""),v=o.useRef(null);o.useEffect(()=>()=>v.current?.abort(),[]);const p=r.phase==="idle"?null:r.methodIndex,A=r.phase==="authorizing"||r.phase==="waiting"||r.phase==="awaitingCode"&&r.submitting,b=async(m,y,K)=>{const C=await Ta(m);if(C.ok){D.success(i(y));return}console.error("Failed to copy OAuth value:",C.error),D.error(i(K))},P=async(m,y)=>{const K=new AbortController;v.current?.abort(),v.current=K;try{const C=await cn.getSdkClient().provider.oauth.callback({providerID:t,method:m,...y?{code:y}:{}},{signal:K.signal});if(K.signal.aborted)return;if(C.error)throw C.error;l(Ki),D.success(i("settings.providers.page.toast.oauthCompleted")),await a()}catch(C){if(K.signal.aborted)return;console.error("Failed to complete OAuth flow:",C),l({phase:"failed",methodIndex:m,message:Io(C,i,"settings.providers.page.toast.oauthCompleteFailed")})}finally{v.current===K&&(v.current=null)}},N=async(m,y)=>{l({phase:"authorizing",methodIndex:m});let K;try{const C=await cn.getSdkClient().provider.oauth.authorize({providerID:t,method:m,...Object.keys(y).length>0?{inputs:y}:{}});if(C.error)throw C.error;const T=fg(C.data);if(!T){l({phase:"failed",methodIndex:m,message:i("settings.providers.page.toast.oauthDetailsMissing")});return}K=T}catch(C){console.error("Failed to start OAuth flow:",C),l({phase:"failed",methodIndex:m,message:Io(C,i,"settings.providers.page.toast.oauthStartFailed")});return}if(K.url&&og(t,K.url)&&An(K.url),K.method==="code"){c(""),l({phase:"awaitingCode",methodIndex:m,authorization:K,submitting:!1});return}l({phase:"waiting",methodIndex:m,authorization:K}),await P(m)},k=m=>{const y=pg(m.prompts);if(y.length===0){N(m.index,{});return}d(ug(y)),l({phase:"prompting",methodIndex:m.index,prompts:y,error:null})},g=()=>{if(r.phase!=="prompting")return;const m=gg(r.prompts,h);if(m){l({...r,error:i("settings.providers.page.auth.oauth.promptRequired",{field:m.message})});return}N(r.methodIndex,hg(r.prompts,h))},E=()=>{if(r.phase!=="awaitingCode")return;const m=x.trim();m&&(l({...r,submitting:!0}),P(r.methodIndex,m))},O=()=>{v.current?.abort(),v.current=null,l(Ki)},I=m=>{const y=h[m.key]??"",K=C=>d(T=>({...T,[m.key]:C}));return s.jsxs("div",{className:"space-y-1.5",children:[s.jsx("label",{className:"typography-ui-label text-foreground",children:m.message}),m.type==="select"?s.jsxs(Ot,{value:y,onValueChange:K,children:[s.jsx(Lt,{size:Jt,className:Pn,children:s.jsx(Ht,{children:C=>m.options.find(T=>T.value===C)?.label??null})}),s.jsx(Ft,{children:m.options.map(C=>s.jsx(ut,{value:C.value,children:C.hint?`${C.label} · ${C.hint}`:C.label},C.value))})]}):s.jsx(Ye,{value:y,onChange:C=>K(C.target.value),placeholder:m.placeholder,className:"max-w-[24rem] text-xs"})]},m.key)},w=m=>s.jsxs(s.Fragment,{children:[m.instructions&&s.jsx("p",{className:"typography-meta text-[var(--primary-base)] bg-[var(--primary-base)]/10 px-2 py-1.5 rounded",children:m.instructions}),m.userCode&&s.jsxs("div",{className:"flex items-center gap-2",children:[s.jsx(Ye,{value:m.userCode,readOnly:!0,"aria-label":i("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:()=>{b(m.userCode??"","settings.providers.page.toast.deviceCodeCopied","settings.providers.page.toast.deviceCodeCopyFailed")},children:i("settings.providers.page.actions.copyCode")})]}),m.url&&s.jsxs("div",{className:"flex items-center gap-2",children:[s.jsx(Ye,{value:m.url,readOnly:!0,"aria-label":i("settings.providers.page.auth.oauth.linkLabel"),className:"text-xs text-muted-foreground"}),s.jsxs("div",{className:"flex gap-1 shrink-0",children:[s.jsx(B,{variant:"outline",size:"xs",className:"!font-normal",onClick:()=>{An(m.url??"")},children:i("settings.providers.page.actions.open")}),s.jsx(B,{variant:"outline",size:"xs",className:"!font-normal",onClick:()=>{b(m.url??"","settings.providers.page.toast.oauthLinkCopied","settings.providers.page.toast.oauthLinkCopyFailed")},children:i("settings.providers.page.actions.copy")})]})]})]});return s.jsx("div",{className:je("space-y-4",n),children:e.map(m=>{const y=p===m.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:m.label}),s.jsx(B,{variant:"outline",size:"xs",className:"!font-normal shrink-0",onClick:()=>k(m),disabled:A,children:i("settings.providers.page.actions.connect")})]}),y&&r.phase==="prompting"&&s.jsxs("div",{className:"space-y-3",children:[jr(r.prompts,h).map(I),r.error&&s.jsx("p",{className:"typography-meta text-[var(--status-error)]",children:r.error}),s.jsxs("div",{className:"flex items-center gap-2",children:[s.jsx(B,{size:"xs",className:"!font-normal",onClick:g,children:i("settings.providers.page.actions.continue")}),s.jsx(B,{variant:"ghost",size:"xs",className:"!font-normal",onClick:O,children:i("settings.providers.page.actions.cancel")})]})]}),y&&r.phase==="authorizing"&&s.jsxs("p",{className:"typography-meta text-muted-foreground flex items-center gap-2",children:[s.jsx(L,{name:"loader",className:"h-3.5 w-3.5 animate-spin"}),i("settings.providers.page.auth.oauth.starting")]}),y&&r.phase==="waiting"&&s.jsxs("div",{className:"space-y-3",children:[w(r.authorization),s.jsxs("div",{className:"flex items-center justify-between gap-2",children:[s.jsxs("p",{className:"typography-meta text-muted-foreground flex items-center gap-2",children:[s.jsx(L,{name:"loader",className:"h-3.5 w-3.5 animate-spin"}),i("settings.providers.page.auth.oauth.waiting")]}),s.jsx(B,{variant:"ghost",size:"xs",className:"!font-normal shrink-0",onClick:O,children:i("settings.providers.page.actions.cancel")})]}),s.jsx("p",{className:"typography-meta text-muted-foreground",children:i("settings.providers.page.auth.oauth.waitingHint")})]}),y&&r.phase==="awaitingCode"&&s.jsxs("div",{className:"space-y-3",children:[w(r.authorization),s.jsx("p",{className:"typography-meta text-muted-foreground",children:i("settings.providers.page.auth.oauth.codeHint")}),s.jsxs("div",{className:"flex items-center gap-2",children:[s.jsx(Ye,{value:x,onChange:K=>c(K.target.value),placeholder:i("settings.providers.page.auth.pasteAuthorizationCodePlaceholder"),className:"font-mono text-xs",disabled:r.submitting}),s.jsx(B,{size:"xs",className:"!font-normal shrink-0",onClick:E,disabled:r.submitting||x.trim().length===0,children:r.submitting?i("settings.providers.page.actions.saving"):i("settings.providers.page.actions.complete")}),s.jsx(B,{variant:"ghost",size:"xs",className:"!font-normal shrink-0",onClick:O,disabled:r.submitting,children:i("settings.providers.page.actions.cancel")})]})]}),y&&r.phase==="failed"&&s.jsxs("div",{className:"space-y-2",children:[s.jsx("p",{className:"typography-meta text-[var(--status-error)]",children:r.message}),s.jsx(B,{variant:"outline",size:"xs",className:"!font-normal",onClick:()=>k(m),children:i("settings.providers.page.actions.tryAgain")})]})]},m.index)})})},xg=t=>new Intl.NumberFormat(ur(),{notation:"compact",compactDisplay:"short",maximumFractionDigits:1,minimumFractionDigits:0}).format(t),Eo=t=>{if(typeof t!="number"||Number.isNaN(t))return null;if(t===0)return"0";const e=xg(t);return e.endsWith(".0")?e.slice(0,-2):e},Na="__add_provider__",Kl=t=>typeof t=="object"&&t!==null,To=(t,e)=>t.map(({method:a,methodIndex:n})=>({index:n,label:a.label||a.name||e(n),prompts:a.prompts})),bg=t=>{if(typeof t=="string")return{id:t};if(!Kl(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}},vg=t=>{let e=[];Array.isArray(t)?e=t:Kl(t)&&(Array.isArray(t.all)?e=t.all:Array.isArray(t.providers)&&(e=t.providers));const a=e.map(i=>bg(i)).filter(i=>!!i),n=new Set;return a.filter(i=>n.has(i.id)?!1:(n.add(i.id),!0))},yg=()=>{const{t}=ot(),e=Us(),a=tt($=>ml($,e)),n=tt($=>$.selectedProviderId),i=tt($=>$.setSelectedProvider),r=tt($=>$.getModelMetadata),l=ce($=>$.hiddenModels),h=ce($=>$.toggleHiddenModel),d=ce($=>$.hideAllModels),x=ce($=>$.showAllModels),[c,v]=o.useState({}),[p,A]=o.useState(!1),[b,P]=o.useState({}),[N,k]=o.useState(null),[g,E]=o.useState(""),[O,I]=o.useState([]),[w,m]=o.useState(!1),[y,K]=o.useState(null),[C,T]=o.useState(""),[j,R]=o.useState(""),[G,S]=o.useState(!1),[q,Q]=o.useState({}),[M,W]=o.useState(!1),[Y,F]=o.useState(null),[se,_]=o.useState(null),[V,z]=o.useState(null),[U,X]=o.useState(null),[Z,ne]=o.useState(null),le=n===Na,re=le&&C===On,fe=!!(Y&&n&&Y===n&&!le);o.useEffect(()=>{!n&&a.length>0&&i(a[0].id)},[a,n,i]),o.useEffect(()=>{if(!n)return;let $=!0;return(async()=>{A(!0);try{const ue=await cn.getSdkClient().provider.auth();if(ue.error)throw new Error(`provider.auth failed: ${String(ue.error)}`);if(!$)return;v(Bu(ue.data))}catch(ue){if(!$)return;console.error("Failed to load provider auth methods:",ue),D.error(t("settings.providers.page.toast.authMethodsLoadFailed"))}finally{$&&A(!1)}})(),()=>{$=!1}},[n,t]),o.useEffect(()=>{if(!Vu(le))return;let $=!0;return(async()=>{m(!0),K(null);try{const ue=await cn.getSdkClient().provider.list();if(ue.error)throw new Error(`provider.list failed: ${String(ue.error)}`);if(!$)return;I(vg(ue.data))}catch(ue){if(!$)return;console.error("Failed to load available providers:",ue),K(t("settings.providers.page.state.unableToLoadProviderList"))}finally{$&&m(!1)}})(),()=>{$=!1}},[le,t]);const ae=o.useMemo(()=>new Set(a.map($=>$.id)),[a]),ie=o.useMemo(()=>O.filter($=>!ae.has($.id)).sort(($,de)=>{const ue=($.name||$.id).toLowerCase(),Ne=(de.name||de.id).toLowerCase();return ue.localeCompare(Ne)}),[O,ae]);o.useEffect(()=>{n===Na&&C&&C!==On&&!ie.some($=>$.id===C)&&T("")},[n,C,ie]),o.useEffect(()=>{if(n===Na){W(!0),F(null),_(null),z(null),X(null);return}W(!1),Y&&Y!==n&&(F(null),_(null),z(null),X(null))},[n,Y]),o.useEffect(()=>{if(!n||n===Na)return;const $=q[n];if(!$)return;const de=a.find(Fe=>Fe.id===n),ue=Array.isArray(de?.env)?de.env.filter(Fe=>typeof Fe=="string"&&Fe.trim().length>0):[],Ne=!!$.auth.exists||ue.length>0,pe=!!(de&&So(de,$));jo(!0,Ne,pe)&&W(!0)},[n,q,a]),o.useEffect(()=>{if(!n||n===Na)return;let $=!1;return(async()=>{try{const ue=e?`?directory=${encodeURIComponent(e)}`:"",Ne=await pt(`/api/provider/${encodeURIComponent(n)}/source${ue}`,{method:"GET",headers:{Accept:"application/json"}}),pe=await Ne.json().catch(()=>null);if(!Ne.ok)throw new Error(pe?.error||t("settings.providers.page.toast.providerSourcesLoadFailed"));const Fe=pe?.sources??pe?.data?.sources;!$&&Fe&&Q(H=>({...H,[n]:Fe}))}catch(ue){$||console.error("Failed to load provider sources:",ue)}})(),()=>{$=!0}},[n,e,t]);const te=a.find($=>$.id===n),ye=n?q[n]:void 0,we=async $=>{const de=b[$]?.trim()??"";if(!de){D.error(t("settings.providers.page.toast.apiKeyRequired"));return}const ue=`api:${$}`;k(ue);try{if((await cn.getSdkClient().auth.set({providerID:$,auth:{type:"api",key:de}})).error)throw new Error(t("settings.providers.page.toast.apiKeySaveFailed"));D.success(t("settings.providers.page.toast.apiKeySaved")),P(pe=>({...pe,[$]:""})),Un("providers",{id:$}),i($)}catch(Ne){console.error("Failed to save API key:",Ne),D.error(t("settings.providers.page.toast.apiKeySaveFailed"))}finally{k(null)}},ke=async $=>{const de=`custom:${$.providerID}`;k(de),ne($.providerID),X(null);try{const ue=tg($);if(ue&&(await cn.getSdkClient().auth.set(ue)).error)throw new Error(t("settings.providers.page.toast.apiKeySaveFailed"));const Ne=sg($,{scope:Y?V??Co(q[Y]):"user"}),pe=await pt(`/api/provider${e?`?directory=${encodeURIComponent(e)}`:""}`,{method:"PUT",headers:{Accept:"application/json","Content-Type":"application/json"},body:JSON.stringify(Ne)}),Fe=await pe.json().catch(()=>null);if(!pe.ok)throw ue&&X(t("settings.providers.page.custom.authFailure.configAfterAuth")),new Error(Fe?.error||t("settings.providers.page.toast.customProviderSaveFailed"));D.success(t("settings.providers.page.toast.customProviderSaved",{provider:$.name})),T(""),F(null),_(null),z(null),X(null),ne(null),ii(Fe,"providers",{id:$.providerID}),i($.providerID)}catch(ue){console.error("Failed to save custom provider:",ue),D.error(ue instanceof Error&&ue.message?ue.message:t("settings.providers.page.toast.customProviderSaveFailed"))}finally{k(null)}},xe=$=>t("settings.providers.page.auth.oauthMethodFallback",{index:String($+1)}),De=$=>{W(!1),Hu($)&&Un("providers",{id:$}),i($)},Me=async $=>{const de=`disconnect:${$}`;k(de);try{const ue=await pt(`/api/provider/${encodeURIComponent($)}/auth?scope=all${e?`&directory=${encodeURIComponent(e)}`:""}`,{method:"DELETE",headers:{Accept:"application/json"}}),Ne=await ue.json().catch(()=>null);if(!ue.ok)throw new Error(Ne?.error||t("settings.providers.page.toast.providerDisconnectFailed"));D.success(t("settings.providers.page.toast.providerDisconnected")),ii(Ne,"providers",{id:$})}catch(ue){console.error("Failed to disconnect provider:",ue),D.error(t("settings.providers.page.toast.providerDisconnectFailed"))}finally{k(null)}},he=async $=>{$&&(await Me($),F(null),_(null),z(null),X(null),ne(null),T(""))};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(L,{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(gs,{title:t("settings.providers.page.connect.title"),showSaveStatus:!1,children:[s.jsx(Be,{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")}):y?s.jsx("p",{className:"typography-meta text-muted-foreground",children:y}):s.jsxs(nn,{open:G,onOpenChange:$=>{S($),$||R("")},children:[s.jsx(tn,{asChild:!0,children:s.jsxs("button",{type:"button",className:Cn,children:[s.jsxs("span",{className:"flex items-center gap-2 min-w-0",children:[C&&C!==On?s.jsx(Fn,{providerId:C,className:"h-3.5 w-3.5 flex-shrink-0"}):null,s.jsx("span",{className:je("truncate typography-ui-label font-normal",C?"text-foreground":"text-muted-foreground"),children:C===On?t("settings.providers.page.custom.optionLabel"):C?ie.find($=>$.id===C)?.name||C:t("settings.providers.page.connect.selectProviderPlaceholder")})]}),s.jsx(L,{name:"arrow-down-s",className:"h-4 w-4 flex-shrink-0 text-muted-foreground/50"})]})}),s.jsxs(sn,{align:"start",className:"w-[280px] p-0",onCloseAutoFocus:$=>$.preventDefault(),children:[s.jsxs("div",{className:"flex items-center gap-2 border-b border-[var(--surface-subtle)] px-3 py-2",onKeyDown:$=>$.stopPropagation(),children:[s.jsx(L,{name:"search",className:"h-4 w-4 text-muted-foreground"}),s.jsx("input",{type:"text",value:j,onChange:$=>R($.target.value),onKeyDown:$=>$.stopPropagation(),placeholder:t("settings.providers.page.connect.searchProvidersPlaceholder"),className:"flex-1 bg-transparent typography-meta outline-none placeholder:text-muted-foreground",autoFocus:!0})]}),s.jsx(Vs,{outerClassName:"max-h-[240px]",className:"p-1",children:(()=>{const $=t("settings.providers.page.custom.optionLabel"),de=jc([$,"other","custom"],j),ue=ri(ie,j,Ne=>[Ne.name||Ne.id,Ne.id]);return ue.length===0&&!de?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:[ue.map(Ne=>s.jsxs(an,{onSelect:()=>{T(Ne.id),S(!1),R("")},className:"flex items-center justify-between",children:[s.jsxs("span",{className:"flex items-center gap-2 min-w-0",children:[s.jsx(Fn,{providerId:Ne.id,className:"h-4 w-4 flex-shrink-0"}),s.jsx("span",{className:"truncate",children:Ne.name||Ne.id})]}),C===Ne.id&&s.jsx(L,{name:"check",className:"h-4 w-4 text-[var(--primary-base)]"})]},Ne.id)),de?s.jsxs(an,{onSelect:()=>{T(On),S(!1),R("")},className:"flex items-center justify-between",children:[s.jsxs("span",{className:"flex items-center gap-2 min-w-0",children:[s.jsx(L,{name:"add",className:"h-4 w-4 flex-shrink-0"}),s.jsx("span",{className:"truncate",children:$})]}),C===On&&s.jsx(L,{name:"check",className:"h-4 w-4 text-[var(--primary-base)]"})]},On):null]})})()})]})]})]})}),re?s.jsx(Po,{mode:"create",existingProviderIDs:ae,busy:N?.startsWith("custom:")??!1,authFailureHint:U,onCancel:()=>{T(""),X(null),ne(null)},onDisconnect:U&&Z?()=>{he(Z)}:void 0,onSubmit:ke}):C?s.jsx(Be,{title:t("settings.providers.page.auth.title"),settingsItem:"providers.auth",contentClassName:"space-y-4",children:p?s.jsx("p",{className:"typography-meta text-muted-foreground",children:t("settings.providers.page.auth.loadingMethods")}):s.jsx(s.Fragment,{children:(()=>{const $=c[C]??[],de=To(No($),xe),ue=ko($);return s.jsxs(s.Fragment,{children:[ue?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(ss,{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(Ye,{type:"password",value:b[C]??"",onChange:Ne=>P(pe=>({...pe,[C]:Ne.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:()=>we(C),disabled:N===`api:${C}`,children:N===`api:${C}`?t("settings.providers.page.actions.saving"):t("settings.providers.page.actions.saveKey")})]})]}):null,de.length>0?s.jsx(Ao,{providerId:C,methods:de,onConnected:()=>De(C),className:je(ue&&"border-t border-[var(--surface-subtle)] pt-2")},C):null]})})()})}):null]});if(!te)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(L,{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 ge=Array.isArray(te.models)?te.models:[],Ae=c[te.id]??[],Ve=To(No(Ae),xe),_e=ko(Ae),Le=!!ye,Re=Le&&So(te,ye),Ze=Array.isArray(te.env)?te.env.filter($=>typeof $=="string"&&$.trim().length>0):[],Ge=!!ye?.auth.exists,Oe=Ze.length>0,Ke=Ge||Oe,Pe=jo(Le,Ke,Re),Ue=ge.length>0&&!Pe,ve=!_e&&Ve.length>0?t("settings.providers.page.auth.useReconnectHint"):t("settings.providers.page.auth.incompleteHint"),We=ri(ge,g,$=>[typeof $?.name=="string"?$.name:"",typeof $?.id=="string"?$.id:""]);return fe&&Re&&se?s.jsx(gs,{title:te.name||te.id,titleLeading:s.jsx(Fn,{providerId:te.id,className:"h-5 w-5 shrink-0"}),description:s.jsx("span",{className:"font-mono typography-settings-description text-muted-foreground",children:te.id}),showSaveStatus:!1,children:s.jsx(Po,{mode:"edit",existingProviderIDs:ae,initialValues:se,allowExistingAuth:Ke||!Le,busy:N?.startsWith("custom:")??!1,authFailureHint:U,onCancel:()=>{F(null),_(null),z(null),X(null),ne(null)},onDisconnect:()=>{he(te.id)},onSubmit:ke})}):s.jsxs(gs,{title:te.name||te.id,titleLeading:s.jsx(Fn,{providerId:te.id,className:"h-5 w-5 shrink-0"}),description:s.jsx("span",{className:"font-mono typography-settings-description text-muted-foreground",children:te.id}),showSaveStatus:!1,children:[s.jsx(Be,{title:t("settings.providers.page.auth.title"),divider:!1,headerAction:s.jsxs("div",{className:"flex items-center gap-1",children:[Re?s.jsx(B,{variant:"outline",size:"xs",className:"!font-normal",onClick:()=>{X(null),_(Xu(te)),z(Co(ye)),F(te.id)},children:t("settings.providers.page.actions.edit")}):null,s.jsx(B,{variant:"outline",size:"xs",className:"!font-normal",onClick:()=>W($=>!$),children:t(M?"settings.providers.page.actions.hide":"settings.providers.page.actions.reconnect")})]}),settingsItem:"providers.auth",children:M?p?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:[_e?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(ss,{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(Ye,{type:"password",value:b[te.id]??"",onChange:$=>P(de=>({...de,[te.id]:$.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:()=>we(te.id),disabled:N===`api:${te.id}`,children:N===`api:${te.id}`?t("settings.providers.page.actions.saving"):t("settings.providers.page.actions.saveKey")})]})]}):null,Ve.length>0&&s.jsx(Ao,{providerId:te.id,methods:Ve,onConnected:()=>De(te.id),className:je(_e&&"border-t border-[var(--surface-subtle)] pt-2")},te.id)]}):Pe?s.jsxs("div",{className:"flex items-center gap-1.5 py-1.5",children:[s.jsx(L,{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(ss,{children:ve})]}):s.jsxs("div",{className:"flex items-center gap-1.5 py-1.5",children:[s.jsx(L,{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(ss,{children:t("settings.providers.page.auth.useReconnectHint")})]})}),s.jsx(Be,{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:ye&&(ye.auth.exists||ye.user.exists||ye.project.exists||ye.custom?.exists)?s.jsxs("span",{className:"typography-meta text-muted-foreground",children:[t("settings.providers.page.connectionDetails.configuredIn")," ",[ye.auth.exists?t("settings.providers.page.connectionDetails.source.authCredentials"):null,ye.user.exists?t("settings.providers.page.connectionDetails.source.userConfig"):null,ye.project.exists?t("settings.providers.page.connectionDetails.source.projectConfig"):null,ye.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:()=>Me(te.id),disabled:N===`disconnect:${te.id}`,children:N===`disconnect:${te.id}`?t("settings.providers.page.actions.disconnecting"):t("settings.providers.page.actions.disconnect")})]})}),Ue?s.jsxs(Be,{title:t("settings.providers.page.models.title"),titleAccessory:s.jsxs("span",{className:"typography-micro text-muted-foreground font-normal",children:["(",ge.length,")"]}),headerAction:s.jsxs("div",{className:"flex items-center gap-1",children:[s.jsx(B,{variant:"outline",size:"xs",className:"!font-normal",onClick:()=>{const $=ge.map(de=>typeof de?.id=="string"?de.id:"").filter(de=>de.length>0);d(te.id,$)},children:t("settings.providers.page.actions.hideAll")}),s.jsx(B,{variant:"outline",size:"xs",className:"!font-normal",onClick:()=>x(te.id),children:t("settings.providers.page.actions.showAll")})]}),settingsItem:"providers.models",children:[s.jsxs("div",{className:"relative mb-2",children:[s.jsx(L,{name:"search",className:"absolute left-2 top-1/2 -translate-y-1/2 h-3.5 w-3.5 text-muted-foreground"}),s.jsx(Ye,{value:g,onChange:$=>E($.target.value),placeholder:t("settings.providers.page.models.filterPlaceholder"),className:"h-7 pl-8 w-full"})]}),We.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:We.map($=>{const de=typeof $?.id=="string"?$.id:"",ue=typeof $?.name=="string"?$.name:de,Ne=de?r(te.id,de):void 0,pe=l.some(et=>et.providerID===te.id&&et.modelID===de),Fe=Eo(Ne?.limit?.context),H=Eo(Ne?.limit?.output),He=[];return Ne?.tool_call&&He.push({key:"tools",icon:"tools",label:t("settings.providers.page.models.capability.toolCalling")}),Ne?.reasoning&&He.push({key:"reasoning",icon:"brain-ai-3",label:t("settings.providers.page.models.capability.reasoning")}),Ne?.attachment&&He.push({key:"image",icon:"file-image",label:t("settings.providers.page.models.capability.imageInput")}),s.jsx("div",{className:"py-1.5",children:s.jsxs("div",{className:je("flex items-center gap-3",pe&&"opacity-50"),children:[s.jsx("span",{className:"typography-meta font-medium text-foreground truncate flex-1 min-w-0",children:ue}),s.jsxs("div",{className:"flex items-center gap-2 flex-shrink-0",children:[(Fe||H)&&s.jsxs("span",{className:"typography-micro text-muted-foreground flex-shrink-0 bg-[var(--surface-muted)] px-1.5 py-0.5 rounded",children:[Fe?`${Fe} ${t("settings.providers.page.models.tokenBadge.context")}`:"",Fe&&H?" · ":"",H?`${H} ${t("settings.providers.page.models.tokenBadge.output")}`:""]}),He.length>0&&s.jsx("div",{className:"flex items-center gap-1 flex-shrink-0",children:He.map(({key:et,icon:ze,label:st})=>s.jsx("span",{className:"flex h-5 w-5 rounded items-center justify-center text-muted-foreground bg-[var(--surface-muted)]",title:st,"aria-label":st,children:s.jsx(L,{name:ze,className:"h-3 w-3"})},et))}),s.jsx("button",{type:"button",onClick:()=>h(te.id,de),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(pe?"settings.providers.page.models.actions.showModelInSelectors":"settings.providers.page.models.actions.hideModelFromSelectors"),"aria-label":t(pe?"settings.providers.page.models.actions.showModel":"settings.providers.page.models.actions.hideModel"),children:pe?s.jsx(L,{name:"eye-off",className:"h-3.5 w-3.5"}):s.jsx(L,{name:"eye",className:"h-3.5 w-3.5"})})]})]})},de)})})]}):null]})},jg=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)},wg=t=>{const e=mt.c(75),{onItemSelect:a}=t,{t:n}=ot(),i=us(kg),r=us(Ng),l=us(Sg),h=us(Cg),d=us(Pg),x=us(Ig),c=us(Ag),v=us(Eg);let p,A;e[0]!==v?(p=()=>{v()},A=[v],e[0]=v,e[1]=p,e[2]=A):(p=e[1],A=e[2]),o.useEffect(p,A);const b=Tg;let P;e[3]!==c?(P=ne=>{ne!=="usage"&&ne!=="remaining"||(c(ne),b({usageDisplayMode:ne}))},e[3]=c,e[4]=P):P=e[4];const N=P;let k;e[5]===Symbol.for("react.memo_cache_sentinel")?(k=je("flex h-full flex-col","bg-background"),e[5]=k):k=e[5];let g;e[6]!==n?(g=n("settings.usage.sidebar.title"),e[6]=n,e[7]=g):g=e[7];let E;e[8]!==g?(E=s.jsx("h2",{className:`${rn} mb-3`,children:g}),e[8]=g,e[9]=E):E=e[9];let O;e[10]!==n?(O=n("settings.usage.sidebar.total",{count:oi.length}),e[10]=n,e[11]=O):O=e[11];let I;e[12]!==O?(I=s.jsx("span",{className:"typography-meta text-muted-foreground",children:O}),e[12]=O,e[13]=I):I=e[13];let w;e[14]!==h?(w=()=>h(),e[14]=h,e[15]=w):w=e[15];let m;e[16]!==n?(m=n("settings.usage.sidebar.actions.refreshAria"),e[16]=n,e[17]=m):m=e[17];let y;e[18]!==n?(y=n("settings.usage.sidebar.actions.refreshTitle"),e[18]=n,e[19]=y):y=e[19];const K=d&&"animate-spin";let C;e[20]!==K?(C=je("h-3.5 w-3.5",K),e[20]=K,e[21]=C):C=e[21];let T;e[22]!==C?(T=s.jsx(L,{name:"refresh",className:C}),e[22]=C,e[23]=T):T=e[23];let j;e[24]!==d||e[25]!==m||e[26]!==y||e[27]!==T||e[28]!==w?(j=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":m,title:y,disabled:d,children:T})}),e[24]=d,e[25]=m,e[26]=y,e[27]=T,e[28]=w,e[29]=j):j=e[29];let R;e[30]!==j||e[31]!==I?(R=s.jsxs("div",{className:"flex items-center justify-between gap-2",children:[I,j]}),e[30]=j,e[31]=I,e[32]=R):R=e[32];let G;e[33]!==n?(G=n("settings.usage.sidebar.field.display"),e[33]=n,e[34]=G):G=e[34];let S;e[35]!==G?(S=s.jsx("span",{className:"typography-micro text-muted-foreground",children:G}),e[35]=G,e[36]=S):S=e[36];let q;e[37]!==n?(q=n("settings.usage.sidebar.field.displayModePlaceholder"),e[37]=n,e[38]=q):q=e[38];let Q;e[39]!==q?(Q=s.jsx(Lt,{className:"w-fit",children:s.jsx(Ht,{placeholder:q})}),e[39]=q,e[40]=Q):Q=e[40];let M;e[41]!==n?(M=n("settings.usage.sidebar.field.displayModeUsage"),e[41]=n,e[42]=M):M=e[42];let W;e[43]!==M?(W=s.jsx(ut,{value:"usage",children:M}),e[43]=M,e[44]=W):W=e[44];let Y;e[45]!==n?(Y=n("settings.usage.sidebar.field.displayModeRemaining"),e[45]=n,e[46]=Y):Y=e[46];let F;e[47]!==Y?(F=s.jsx(ut,{value:"remaining",children:Y}),e[47]=Y,e[48]=F):F=e[48];let se;e[49]!==W||e[50]!==F?(se=s.jsxs(Ft,{children:[W,F]}),e[49]=W,e[50]=F,e[51]=se):se=e[51];let _;e[52]!==N||e[53]!==Q||e[54]!==se||e[55]!==x?(_=s.jsxs(Ot,{value:x,onValueChange:N,children:[Q,se]}),e[52]=N,e[53]=Q,e[54]=se,e[55]=x,e[56]=_):_=e[56];let V;e[57]!==S||e[58]!==_?(V=s.jsxs("div",{className:"mt-2 flex items-center justify-between gap-2",children:[S,_]}),e[57]=S,e[58]=_,e[59]=V):V=e[59];let z;e[60]!==R||e[61]!==V||e[62]!==E?(z=s.jsxs("div",{className:"border-b px-3 pt-4 pb-3",children:[E,R,V]}),e[60]=R,e[61]=V,e[62]=E,e[63]=z):z=e[63];let U;e[64]!==a||e[65]!==i||e[66]!==r||e[67]!==l||e[68]!==n?(U=oi.map(ne=>{const le=i.find(ye=>ye.providerId===ne.id),re=jg(le?.usage),fe=ul(re),ae=ne.id===r,ie=le?.configured??!1,te=ie?fe==="critical"?{backgroundColor:"var(--status-error)"}:fe==="warn"?{backgroundColor:"var(--status-warning)"}:{backgroundColor:"var(--status-success)"}:{backgroundColor:"var(--surface-muted-foreground)",opacity:.4};return s.jsx("div",{className:je("group relative flex items-center rounded-md px-1.5 py-1 transition-all duration-200",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:te}),s.jsx(Fn,{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}),!ie&&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]=i,e[66]=r,e[67]=l,e[68]=n,e[69]=U):U=e[69];let X;e[70]!==U?(X=s.jsx(Vs,{outerClassName:"flex-1 min-h-0",className:"space-y-1 px-3 py-2 overflow-x-hidden",children:U}),e[70]=U,e[71]=X):X=e[71];let Z;return e[72]!==z||e[73]!==X?(Z=s.jsxs("div",{className:k,children:[z,X]}),e[72]=z,e[73]=X,e[74]=Z):Z=e[74],Z};function kg(t){return t.results}function Ng(t){return t.selectedProviderId}function Sg(t){return t.setSelectedProvider}function Cg(t){return t.fetchAllQuotas}function Pg(t){return t.isLoading}function Ig(t){return t.displayMode}function Ag(t){return t.setDisplayMode}function Eg(t){return t.loadSettings}async function Tg(t){try{await Nt(t)}catch(e){console.warn("Failed to save usage settings:",e)}}const Dg=t=>{const e=mt.c(17),{percent:a,tonePercent:n,className:i}=t;let r;e[0]!==a?(r=wc(a)??0,e[0]=a,e[1]=r):r=e[1];const l=r,h=n??a;let d;e[2]!==h?(d=ul(h),e[2]=h,e[3]=d):d=e[3];const x=d;let c;e[4]!==x?(c=x==="critical"?{backgroundColor:"var(--status-error)"}:x==="warn"?{backgroundColor:"var(--status-warning)"}:{backgroundColor:"var(--status-success)"},e[4]=x,e[5]=c):c=e[5];const v=c;let p;e[6]!==i?(p=je("relative h-2.5 rounded-full bg-[var(--interactive-border)] overflow-hidden",i),e[6]=i,e[7]=p):p=e[7];const A=`${l}%`;let b;e[8]!==v||e[9]!==A?(b={...v,width:A},e[8]=v,e[9]=A,e[10]=b):b=e[10];let P;e[11]!==l||e[12]!==b?(P=s.jsx("div",{className:"h-full transition-all duration-300",style:b,role:"progressbar","aria-valuenow":l,"aria-valuemin":0,"aria-valuemax":100}),e[11]=l,e[12]=b,e[13]=P):P=e[13];let N;return e[14]!==p||e[15]!==P?(N=s.jsx("div",{className:p,children:P}),e[14]=p,e[15]=P,e[16]=N):N=e[16],N},Ui=t=>{const e=mt.c(44),{title:a,window:n,subtitle:i,showToggle:r,toggleEnabled:l,onToggle:h}=t,d=r===void 0?!1:r,x=l===void 0?!1:l,c=us(Mg),v=ce(Rg),p=c==="remaining"?n.remainingPercent:n.usedPercent,A=c==="remaining"?"remaining":"used";let b;e[0]!==p||e[1]!==n.valueLabel?(b=kc(n.valueLabel,p),e[0]=p,e[1]=n.valueLabel,e[2]=b):b=e[2];const P=b,N=n.resetAfterFormatted??n.resetAtFormatted;let k;e[3]!==N||e[4]!==v||e[5]!==n.resetAt?(k=Nc(n.resetAt,N,v),e[3]=N,e[4]=v,e[5]=n.resetAt,e[6]=k):k=e[6];const g=k;let E;e[7]!==a?(E=Sc(a),e[7]=a,e[8]=E):E=e[8];const O=E;let I;e[9]!==h||e[10]!==d||e[11]!==x?(I=d&&s.jsx(Yi,{checked:x,onChange:Y=>h?.(Y),ariaLabel:"Show in dropdown"}),e[9]=h,e[10]=d,e[11]=x,e[12]=I):I=e[12];let w;e[13]!==O?(w=s.jsx("span",{className:"typography-ui-label text-foreground truncate",children:O}),e[13]=O,e[14]=w):w=e[14];let m;e[15]!==i?(m=i&&s.jsx("span",{className:"typography-meta text-muted-foreground truncate",children:i}),e[15]=i,e[16]=m):m=e[16];let y;e[17]!==w||e[18]!==m?(y=s.jsxs("div",{className:"min-w-0 flex flex-col",children:[w,m]}),e[17]=w,e[18]=m,e[19]=y):y=e[19];let K;e[20]!==y||e[21]!==I?(K=s.jsxs("div",{className:"min-w-0 flex-1 flex items-center gap-2",children:[I,y]}),e[20]=y,e[21]=I,e[22]=K):K=e[22];const C=P==="-"?"":P;let T;e[23]!==C?(T=s.jsx("div",{className:"typography-ui-label text-foreground tabular-nums flex items-center justify-end",children:C}),e[23]=C,e[24]=T):T=e[24];let j;e[25]!==K||e[26]!==T?(j=s.jsxs("div",{className:"flex items-center justify-between gap-3",children:[K,T]}),e[25]=K,e[26]=T,e[27]=j):j=e[27];let R;e[28]!==p||e[29]!==n.usedPercent?(R=s.jsx(Dg,{percent:p,tonePercent:n.usedPercent,className:"h-1.5"}),e[28]=p,e[29]=n.usedPercent,e[30]=R):R=e[30];const G=g?`Resets ${g}`:"";let S;e[31]!==G?(S=s.jsx("span",{className:"typography-micro text-muted-foreground",children:G}),e[31]=G,e[32]=S):S=e[32];let q;e[33]!==A?(q=s.jsx("span",{className:"typography-micro text-muted-foreground",children:A}),e[33]=A,e[34]=q):q=e[34];let Q;e[35]!==S||e[36]!==q?(Q=s.jsxs("div",{className:"mt-1 flex items-center justify-between",children:[S,q]}),e[35]=S,e[36]=q,e[37]=Q):Q=e[37];let M;e[38]!==R||e[39]!==Q?(M=s.jsxs("div",{className:"mt-2.5",children:[R,Q]}),e[38]=R,e[39]=Q,e[40]=M):M=e[40];let W;return e[41]!==j||e[42]!==M?(W=s.jsxs("div",{className:"py-3",children:[j,M]}),e[41]=j,e[42]=M,e[43]=W):W=e[43],W};function Mg(t){return t.displayMode}function Rg(t){return t.timeFormatPreference}const Og=({providerId:t,providerName:e})=>{const{t:a}=ot(),[n,i]=o.useState(null),[r,l]=o.useState({}),[h,d]=o.useState(!1),x=`/api/quota/credentials/${t}`;o.useEffect(()=>{pt(x).then(async p=>{if(!p.ok)throw new Error;const A=await p.json();i(A),l({})}).catch(()=>i({configured:!1}))},[x]);const c=async(p,A,b)=>{d(!0);try{const P=await pt(p,{method:A,headers:b?{"Content-Type":"application/json"}:void 0,body:b?JSON.stringify(b):void 0}),N=await P.json().catch(()=>null);if(!P.ok)throw new Error(N?.error);N?.configured!==void 0&&i(N),l({}),D.success(a("settings.providers.page.quotaCredentials.saved",{provider:e}))}catch(P){D.error(P instanceof Error&&P.message?P.message:a("settings.providers.page.openCodeGo.saveFailed"))}finally{d(!1)}},v=(p,A,b)=>s.jsxs("label",{className:"block typography-ui-label text-foreground",children:[A,s.jsx(Ye,{className:"mt-1 h-7 font-mono text-xs",type:"password",autoComplete:"off",value:r[p]??"",onChange:P=>l(N=>({...N,[p]:P.target.value})),placeholder:n?.secretMasked??b})]});return s.jsxs("div",{"data-settings-item":`usage.${t}-credentials`,className:"mb-8",children:[s.jsx("div",{className:"mb-1 px-1",children:s.jsx("h3",{className:"typography-ui-header font-medium text-foreground",children:e})}),s.jsxs("section",{className:"space-y-3 px-2 pb-2 pt-0",children:[t==="ollama-cloud"&&v("cookie",a("settings.providers.page.openCodeGo.authCookie"),"session=..."),t==="cursor"&&v("accessToken",a("settings.providers.page.quotaCredentials.accessToken"),a("settings.providers.page.quotaCredentials.tokenPlaceholder")),t==="cursor"&&v("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:h,onClick:()=>c(x,"PUT",r),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:h,onClick:()=>c(`${x}/validate`,"POST"),children:a("settings.providers.page.openCodeGo.validate")}),t==="cursor"&&s.jsx(B,{variant:"outline",size:"xs",disabled:h,onClick:()=>c(`${x}/import`,"POST"),children:a("settings.providers.page.actions.connect")}),n?.configured&&s.jsx(B,{variant:"destructive",size:"xs",disabled:h,onClick:()=>c(x,"DELETE"),children:a("settings.providers.page.openCodeGo.delete")})]})]})]})},Do=(t,e)=>{if(!t)return"-";try{return gl(t,e,{fallback:"-"})}catch{return"-"}},Lg=()=>{const{t}=ot(),e=ce(S=>S.timeFormatPreference),a=us(S=>S.results),n=us(S=>S.selectedProviderId),i=us(S=>S.setSelectedProvider),r=us(S=>S.loadSettings),l=us(S=>S.fetchAllQuotas),h=us(S=>S.isLoading),d=us(S=>S.lastUpdated),x=us(S=>S.error),c=us(S=>S.dropdownProviderIds),v=us(S=>S.setDropdownProviderIds),p=us(S=>S.selectedModels),A=us(S=>S.toggleModelSelected),b=us(S=>S.applyDefaultSelections);Cc(),o.useEffect(()=>{r(),l()},[r,l]),o.useEffect(()=>{if(n||a.length===0)return;const S=a.find(q=>q.configured)?.providerId;i(S??oi[0]?.id??null)},[a,n,i]);const P=a.find(S=>S.providerId===n)??null,k=oi.find(S=>S.id===n)?.name??n??t("settings.usage.sidebar.title"),g=P?.usage,E=P?.configured&&!P.ok?P.error:null,O=n?c.includes(n):!1,I=n==="ollama-cloud"||n==="cursor",w=o.useCallback(S=>{if(!n)return;const q=S?Array.from(new Set([...c,n])):c.filter(Q=>Q!==n);v(q),Nt({usageDropdownProviders:q})},[c,n,v]),m=o.useMemo(()=>g?.models?Object.entries(g.models).map(([S,q])=>({name:S,windows:q})).filter(S=>Object.keys(S.windows.windows).length>0):[],[g?.models]);o.useEffect(()=>{n&&m.length>0&&b(n,m.map(S=>S.name))},[n,m,b]);const y=o.useMemo(()=>!n||m.length===0?new Map:Pc(m,S=>S.name,n),[m,n]),K=o.useMemo(()=>{if(!n)return[];const S=Ac(n);return Ic(S)},[n]),[C,T]=o.useState(()=>({})),j=o.useCallback(S=>{T(q=>({...q,[S]:!q[S]}))},[]),R=o.useCallback(S=>{if(!n)return;A(n,S);const q=p[n]??[],M=q.includes(S)?q.filter(Y=>Y!==S):[...q,S],W={...p,[n]:M};Nt({usageSelectedModels:W})},[n,p,A]),G=n?p[n]??[]:[];return n?s.jsxs(gs,{title:t("settings.usage.page.header.providerUsage",{provider:k}),titleLeading:s.jsx(Fn,{providerId:n,className:"h-5 w-5 shrink-0"}),description:h?s.jsx("span",{className:"animate-pulse typography-settings-description text-muted-foreground",children:t("settings.usage.page.header.refreshing")}):P?.planLabel?t("settings.usage.page.header.lastUpdatedWithPlan",{plan:P.planLabel,time:Do(d,e)}):t("settings.usage.page.header.lastUpdated",{time:Do(d,e)}),showSaveStatus:!0,children:[s.jsx(Be,{divider:!1,settingsItem:"usage.work-status-panel",children:s.jsx(ht,{checked:O,onChange:w,label:t("settings.usage.page.options.showInWorkStatus"),ariaLabel:t("settings.usage.page.options.showInWorkStatusAria"),info:t("settings.usage.page.options.showInWorkStatusTooltip")})}),!P&&s.jsx("p",{className:"typography-ui-label text-foreground pb-8",children:t("settings.usage.page.state.noData")}),(x||E)&&s.jsxs("div",{className:"mb-8 rounded-lg border border-[var(--status-error-border)] bg-[var(--status-error-background)] px-4 py-3",children:[s.jsx("p",{className:"typography-ui-label font-medium text-[var(--status-error)]",children:t("settings.usage.page.state.refreshFailedTitle")}),s.jsx("p",{className:"typography-meta text-[var(--status-error)]/80 mt-1",children:x??E})]}),P&&!P.configured&&!I&&s.jsxs("div",{className:"mb-8 rounded-lg border border-[var(--status-warning-border)] bg-[var(--status-warning-background)] px-4 py-3",children:[s.jsx("p",{className:"typography-ui-label font-medium text-[var(--status-warning)]",children:t("settings.usage.page.state.providerNotConfiguredTitle")}),s.jsx("p",{className:"typography-meta text-[var(--status-warning)]/80 mt-1",children:t("settings.usage.page.state.providerNotConfiguredDescription")})]}),(n==="ollama-cloud"||n==="cursor")&&s.jsx(Og,{providerId:n,providerName:k}),g?.windows&&Object.keys(g.windows).length>0&&s.jsx(Be,{settingsItem:"usage.model-quotas",children:s.jsx("div",{className:"divide-y divide-[var(--surface-subtle)]",children:Object.entries(g.windows).map(([S,q])=>s.jsx(Ui,{title:S,window:q},S))})}),m.length>0&&s.jsxs(Be,{title:t("settings.usage.page.section.modelQuotas"),contentClassName:"space-y-3",children:[K.map(S=>{const q=y.get(S.id)??[];if(q.length===0)return null;const Q=C[S.id]??!1;return s.jsx("section",{className:"p-2",children:s.jsxs(qn,{open:!Q,onOpenChange:()=>j(S.id),children:[s.jsxs(Wn,{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:S.label}),s.jsxs("span",{className:"typography-micro text-muted-foreground",children:["(",q.length,")"]})]}),Q?s.jsx(L,{name:"arrow-right-s",className:"h-4 w-4 text-muted-foreground group-hover:text-foreground transition-colors"}):s.jsx(L,{name:"arrow-down-s",className:"h-4 w-4 text-muted-foreground group-hover:text-foreground transition-colors"})]}),s.jsx(Jn,{children:s.jsx("div",{className:"divide-y divide-[var(--surface-subtle)] mt-1",children:q.map(M=>{const W=Object.entries(M.windows.windows);if(W.length===0)return null;const[Y,F]=W[0],se=G.includes(M.name);return s.jsx(Ui,{title:Y,subtitle:Ir(M.name),window:F,showToggle:!0,toggleEnabled:se,onToggle:()=>R(M.name)},M.name)})})})]})},S.id)}),(()=>{const S=y.get(null)??[];if(S.length===0)return null;const q=C.other??!1;return s.jsx("section",{className:"p-2",children:s.jsxs(qn,{open:!q,onOpenChange:()=>j("other"),children:[s.jsxs(Wn,{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:["(",S.length,")"]})]}),q?s.jsx(L,{name:"arrow-right-s",className:"h-4 w-4 text-muted-foreground group-hover:text-foreground transition-colors"}):s.jsx(L,{name:"arrow-down-s",className:"h-4 w-4 text-muted-foreground group-hover:text-foreground transition-colors"})]}),s.jsx(Jn,{children:s.jsx("div",{className:"divide-y divide-[var(--surface-subtle)] mt-1",children:S.map(Q=>{const M=Object.entries(Q.windows.windows);if(M.length===0)return null;const[W,Y]=M[0],F=G.includes(Q.name);return s.jsx(Ui,{title:W,subtitle:Ir(Q.name),window:Y,showToggle:!0,toggleEnabled:F,onToggle:()=>R(Q.name)},Q.name)})})})]})})})()]}),P?.configured&&g&&Object.keys(g.windows??{}).length===0&&m.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")})})},Fg="git.commit.generate",ir=kl(t=>({selectedPromptId:Fg,setSelectedPromptId:e=>{t(a=>a.selectedPromptId===e?a:{selectedPromptId:e})}})),Kg=t=>{const e=mt.c(23),{onItemSelect:a}=t,{t:n}=ot(),i=ir(Ug),r=ir(zg);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 h;e[1]===Symbol.for("react.memo_cache_sentinel")?(h={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]=h):h=e[1];let d;e[2]===Symbol.for("react.memo_cache_sentinel")?(d={groupKey:"settings.magicPrompts.sidebar.group.planning",items:[{id:"plan.todo",titleKey:"settings.magicPrompts.sidebar.item.planTodo"},{id:"plan.improve",titleKey:"settings.magicPrompts.sidebar.item.planImprove"},{id:"plan.implement",titleKey:"settings.magicPrompts.sidebar.item.planImplement"}]},e[2]=d):d=e[2];let x;e[3]===Symbol.for("react.memo_cache_sentinel")?(x=[l,h,d,{groupKey:"settings.magicPrompts.sidebar.group.session",items:[{id:"session.explore",titleKey:"settings.magicPrompts.sidebar.item.sessionExplore"},{id:"session.summary",titleKey:"settings.magicPrompts.sidebar.item.sessionSummary"},{id:"session.review",titleKey:"settings.magicPrompts.sidebar.item.sessionWorkspaceReview"},{id:"session.plan",titleKey:"settings.magicPrompts.sidebar.item.sessionFeaturePlan"},{id:"session.craftGoal",titleKey:"settings.magicPrompts.sidebar.item.sessionCraftGoal"},{id:"session.catchup",titleKey:"settings.magicPrompts.sidebar.item.sessionCatchUp"},{id:"session.debug",titleKey:"settings.magicPrompts.sidebar.item.sessionDebug"},{id:"session.weigh",titleKey:"settings.magicPrompts.sidebar.item.sessionWeigh"},{id:"session.fusion",titleKey:"settings.magicPrompts.sidebar.item.sessionFusion"}]}],e[3]=x):x=e[3];const c=x;let v;e[4]!==n?(v=n("settings.magicPrompts.sidebar.title"),e[4]=n,e[5]=v):v=e[5];let p;e[6]!==v?(p=s.jsx("h2",{className:rn,children:v}),e[6]=v,e[7]=p):p=e[7];let A;e[8]!==n?(A=n("settings.magicPrompts.sidebar.description"),e[8]=n,e[9]=A):A=e[9];let b;e[10]!==A?(b=s.jsx("p",{className:"typography-meta mt-1 text-muted-foreground",children:A}),e[10]=A,e[11]=b):b=e[11];let P;e[12]!==p||e[13]!==b?(P=s.jsxs("div",{className:"border-b px-3 pt-4 pb-3",children:[p,b]}),e[12]=p,e[13]=b,e[14]=P):P=e[14];let N;e[15]!==a||e[16]!==i||e[17]!==r||e[18]!==n?(N=s.jsx(Vs,{outerClassName:"flex-1 min-h-0",className:"space-y-3 px-3 py-2 overflow-x-hidden",children:c.map(g=>s.jsxs("div",{className:"space-y-1",children:[s.jsx("div",{className:"typography-micro px-1 text-muted-foreground",children:n(g.groupKey)}),g.items.map(E=>{const O=i===E.id;return s.jsx("button",{type:"button",onClick:()=>{r(E.id),a?.()},className:je("flex w-full items-center rounded-md px-2 py-1.5 text-left transition-colors",O?"bg-interactive-selection text-foreground":"text-foreground hover:bg-interactive-hover"),children:s.jsx("span",{className:"typography-ui-label truncate font-normal",children:n(E.titleKey)})},E.id)})]},g.groupKey))}),e[15]=a,e[16]=i,e[17]=r,e[18]=n,e[19]=N):N=e[19];let k;return e[20]!==N||e[21]!==P?(k=s.jsxs("div",{className:"flex h-full flex-col bg-background",children:[P,N]}),e[20]=N,e[21]=P,e[22]=k):k=e[22],k};function Ug(t){return t.selectedPromptId}function zg(t){return t.setSelectedPromptId}const Mo={"git.commit.generate":{titleKey:"settings.magicPrompts.page.group.gitCommitGenerate.title",descriptionKey:"settings.magicPrompts.page.group.gitCommitGenerate.description",blocks:[{id:"git.commit.generate.visible",titleKey:"settings.magicPrompts.page.block.visiblePrompt"},{id:"git.commit.generate.instructions",titleKey:"settings.magicPrompts.page.block.instructions"}]},"git.pr.generate":{titleKey:"settings.magicPrompts.page.group.gitPrGenerate.title",descriptionKey:"settings.magicPrompts.page.group.gitPrGenerate.description",blocks:[{id:"git.pr.generate.visible",titleKey:"settings.magicPrompts.page.block.visiblePrompt"},{id:"git.pr.generate.instructions",titleKey:"settings.magicPrompts.page.block.instructions"}]},"github.pr.review":{titleKey:"settings.magicPrompts.page.group.githubPrReview.title",descriptionKey:"settings.magicPrompts.page.group.githubPrReview.description",blocks:[{id:"github.pr.review.visible",titleKey:"settings.magicPrompts.page.block.visiblePrompt"},{id:"github.pr.review.instructions",titleKey:"settings.magicPrompts.page.block.instructions"}]},"github.issue.review":{titleKey:"settings.magicPrompts.page.group.githubIssueReview.title",descriptionKey:"settings.magicPrompts.page.group.githubIssueReview.description",blocks:[{id:"github.issue.review.visible",titleKey:"settings.magicPrompts.page.block.visiblePrompt"},{id:"github.issue.review.instructions",titleKey:"settings.magicPrompts.page.block.instructions"}]},"github.pr.checks.review":{titleKey:"settings.magicPrompts.page.group.githubPrFailedChecksReview.title",descriptionKey:"settings.magicPrompts.page.group.githubPrFailedChecksReview.description",blocks:[{id:"github.pr.checks.review.visible",titleKey:"settings.magicPrompts.page.block.visiblePrompt"},{id:"github.pr.checks.review.instructions",titleKey:"settings.magicPrompts.page.block.instructions"}]},"github.pr.comments.review":{titleKey:"settings.magicPrompts.page.group.githubPrCommentsReview.title",descriptionKey:"settings.magicPrompts.page.group.githubPrCommentsReview.description",blocks:[{id:"github.pr.comments.review.visible",titleKey:"settings.magicPrompts.page.block.visiblePrompt"},{id:"github.pr.comments.review.instructions",titleKey:"settings.magicPrompts.page.block.instructions"}]},"github.pr.comment.single":{titleKey:"settings.magicPrompts.page.group.githubSinglePrCommentReview.title",descriptionKey:"settings.magicPrompts.page.group.githubSinglePrCommentReview.description",blocks:[{id:"github.pr.comment.single.visible",titleKey:"settings.magicPrompts.page.block.visiblePrompt"},{id:"github.pr.comment.single.instructions",titleKey:"settings.magicPrompts.page.block.instructions"}]},"git.conflict.resolve":{titleKey:"settings.magicPrompts.page.group.gitConflictResolve.title",descriptionKey:"settings.magicPrompts.page.group.gitConflictResolve.description",blocks:[{id:"git.conflict.resolve.visible",titleKey:"settings.magicPrompts.page.block.visiblePrompt"},{id:"git.conflict.resolve.instructions",titleKey:"settings.magicPrompts.page.block.instructions"}]},"git.integrate.cherrypick.resolve":{titleKey:"settings.magicPrompts.page.group.gitCherrypickConflictResolve.title",descriptionKey:"settings.magicPrompts.page.group.gitCherrypickConflictResolve.description",blocks:[{id:"git.integrate.cherrypick.resolve.visible",titleKey:"settings.magicPrompts.page.block.visiblePrompt"},{id:"git.integrate.cherrypick.resolve.instructions",titleKey:"settings.magicPrompts.page.block.instructions"}]},"plan.improve":{titleKey:"settings.magicPrompts.page.group.planImprove.title",descriptionKey:"settings.magicPrompts.page.group.planImprove.description",blocks:[{id:"plan.improve.visible",titleKey:"settings.magicPrompts.page.block.visiblePrompt"},{id:"plan.improve.instructions",titleKey:"settings.magicPrompts.page.block.instructions"}]},"plan.todo":{titleKey:"settings.magicPrompts.page.group.planTodo.title",descriptionKey:"settings.magicPrompts.page.group.planTodo.description",blocks:[{id:"plan.todo.visible",titleKey:"settings.magicPrompts.page.block.visiblePrompt"},{id:"plan.todo.instructions",titleKey:"settings.magicPrompts.page.block.instructions"}]},"plan.implement":{titleKey:"settings.magicPrompts.page.group.planImplement.title",descriptionKey:"settings.magicPrompts.page.group.planImplement.description",blocks:[{id:"plan.implement.visible",titleKey:"settings.magicPrompts.page.block.visiblePrompt"},{id:"plan.implement.instructions",titleKey:"settings.magicPrompts.page.block.instructions"}]},"session.summary":{titleKey:"settings.magicPrompts.page.group.sessionSummary.title",descriptionKey:"settings.magicPrompts.page.group.sessionSummary.description",blocks:[{id:"session.summary.visible",titleKey:"settings.magicPrompts.page.block.visiblePrompt"},{id:"session.summary.instructions",titleKey:"settings.magicPrompts.page.block.instructions"}]},"session.review":{titleKey:"settings.magicPrompts.page.group.sessionWorkspaceReview.title",descriptionKey:"settings.magicPrompts.page.group.sessionWorkspaceReview.description",blocks:[{id:"session.review.visible",titleKey:"settings.magicPrompts.page.block.visiblePrompt"},{id:"session.review.instructions",titleKey:"settings.magicPrompts.page.block.instructions"}]},"session.plan":{titleKey:"settings.magicPrompts.page.group.sessionFeaturePlan.title",descriptionKey:"settings.magicPrompts.page.group.sessionFeaturePlan.description",blocks:[{id:"session.plan.visible",titleKey:"settings.magicPrompts.page.block.visiblePrompt"},{id:"session.plan.instructions",titleKey:"settings.magicPrompts.page.block.instructions"}]},"session.craftGoal":{titleKey:"settings.magicPrompts.page.group.sessionCraftGoal.title",descriptionKey:"settings.magicPrompts.page.group.sessionCraftGoal.description",blocks:[{id:"session.craftGoal.visible",titleKey:"settings.magicPrompts.page.block.visiblePrompt"},{id:"session.craftGoal.instructions",titleKey:"settings.magicPrompts.page.block.instructions"}]},"session.catchup":{titleKey:"settings.magicPrompts.page.group.sessionCatchUp.title",descriptionKey:"settings.magicPrompts.page.group.sessionCatchUp.description",blocks:[{id:"session.catchup.visible",titleKey:"settings.magicPrompts.page.block.visiblePrompt"},{id:"session.catchup.instructions",titleKey:"settings.magicPrompts.page.block.instructions"}]},"session.debug":{titleKey:"settings.magicPrompts.page.group.sessionDebug.title",descriptionKey:"settings.magicPrompts.page.group.sessionDebug.description",blocks:[{id:"session.debug.visible",titleKey:"settings.magicPrompts.page.block.visiblePrompt"},{id:"session.debug.instructions",titleKey:"settings.magicPrompts.page.block.instructions"}]},"session.weigh":{titleKey:"settings.magicPrompts.page.group.sessionWeigh.title",descriptionKey:"settings.magicPrompts.page.group.sessionWeigh.description",blocks:[{id:"session.weigh.visible",titleKey:"settings.magicPrompts.page.block.visiblePrompt"},{id:"session.weigh.instructions",titleKey:"settings.magicPrompts.page.block.instructions"}]},"session.explore":{titleKey:"settings.magicPrompts.page.group.sessionExplore.title",descriptionKey:"settings.magicPrompts.page.group.sessionExplore.description",blocks:[{id:"session.explore.visible",titleKey:"settings.magicPrompts.page.block.visiblePrompt"},{id:"session.explore.instructions",titleKey:"settings.magicPrompts.page.block.instructions"}]},"session.fusion":{titleKey:"settings.magicPrompts.page.group.sessionFusion.title",descriptionKey:"settings.magicPrompts.page.group.sessionFusion.description",blocks:[{id:"session.fusion.visible",titleKey:"settings.magicPrompts.page.block.visiblePrompt"},{id:"session.fusion.instructions",titleKey:"settings.magicPrompts.page.block.instructions"}]}},Ro=(t,e)=>Object.prototype.hasOwnProperty.call(t,e),zi=t=>t.endsWith(".visible"),_g=()=>{const{t}=ot(),e=o.useCallback(w=>t(w),[t]),a=ir(w=>w.selectedPromptId),[n,i]=o.useState(!0),[r,l]=o.useState({}),[h,d]=o.useState({}),[x,c]=o.useState({}),[v,p]=o.useState({}),[A,b]=o.useState(!1);o.useEffect(()=>{let w=!0;return(async()=>{i(!0);try{const y=await Mc();if(!w)return;l(y)}catch(y){console.warn("Failed to load magic prompts:",y),D.error(t("settings.magicPrompts.page.toast.loadFailed"))}finally{w&&i(!1)}})(),()=>{w=!1}},[t]);const P=Mo[a]??Mo["git.commit.generate"],N=o.useCallback(w=>Ro(r,w)?r[w]:Ii(w),[r]),k=o.useCallback(w=>h[w]??N(w),[h,N]),g=o.useCallback((w,m)=>{d(y=>y[w]===m?y:{...y,[w]:m})},[]),E=o.useCallback(async w=>{const m=k(w);if(zi(w)&&m.trim().length===0){D.error(t("settings.magicPrompts.page.toast.visiblePromptRequired"));return}c(y=>({...y,[w]:!0}));try{const y=m===Ii(w)?await Ar(w):await Ec(w,m);l(y.overrides),D.success(t("settings.magicPrompts.page.toast.saved"))}catch(y){const K=y instanceof Error?y.message:String(y);D.error(t("settings.magicPrompts.page.toast.saveFailed"),{description:K})}finally{c(y=>({...y,[w]:!1}))}},[k,t]),O=o.useCallback(async w=>{p(m=>({...m,[w]:!0}));try{const m=await Ar(w);l(m.overrides),d(y=>({...y,[w]:Ii(w)})),D.success(t("settings.magicPrompts.page.toast.resetSuccess"))}catch(m){const y=m instanceof Error?m.message:String(m);D.error(t("settings.magicPrompts.page.toast.resetFailed"),{description:y})}finally{p(m=>({...m,[w]:!1}))}},[t]),I=o.useCallback(async()=>{b(!0);try{const w=await Tc();l(w.overrides),d({}),D.success(t("settings.magicPrompts.page.toast.resetAllSuccess"))}catch(w){const m=w instanceof Error?w.message:String(w);D.error(t("settings.magicPrompts.page.toast.resetAllFailed"),{description:m})}finally{b(!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(gs,{title:e(P.titleKey),titleAccessory:s.jsx(ss,{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:A||Object.keys(r).length===0,children:t(A?"settings.magicPrompts.page.actions.resetting":"settings.magicPrompts.page.actions.resetAllOverrides")}),showSaveStatus:!1,children:P.blocks.map((w,m)=>{const y=Dc(w.id),K=N(w.id),C=k(w.id),T=Ro(r,w.id),j=C!==K,R=zi(w.id)&&C.trim().length===0,G=x[w.id]===!0,S=v[w.id]===!0;return s.jsxs(Be,{title:e(w.titleKey),info:y.description,description:y.placeholders&&y.placeholders.length>0?`${t("settings.magicPrompts.page.placeholdersLabel")} ${y.placeholders.map(q=>`{{${q.key}}}`).join(", ")}`:void 0,divider:m>0,settingsItem:zi(w.id)?"magic-prompts.visible-prompt":"magic-prompts.instructions",contentClassName:"space-y-3",children:[s.jsx(Es,{value:C,onChange:q=>g(w.id,q.target.value),className:"min-h-[220px] font-mono text-sm"}),R&&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(j?"settings.magicPrompts.page.status.unsavedChanges":T?"settings.magicPrompts.page.status.usingSavedOverride":"settings.magicPrompts.page.status.usingBuiltinDefault")}),s.jsxs("div",{className:"flex items-center gap-2",children:[s.jsx(B,{variant:"outline",size:"sm",onClick:()=>{O(w.id)},disabled:!T||G||S,children:t(S?"settings.magicPrompts.page.actions.resetting":"settings.magicPrompts.page.actions.resetToDefault")}),s.jsx(B,{size:"sm",onClick:()=>{E(w.id)},disabled:!j||G||S||R,children:t(G?"settings.common.actions.saving":"settings.magicPrompts.page.actions.save")})]})]})]},w.id)})})},$g=t=>{const e=mt.c(89),{onItemSelect:a}=t,{t:n}=ot(),[i,r]=o.useState(null),[l,h]=o.useState(null),[d,x]=o.useState(null),{selectedSnippetName:c,snippets:v,setSelectedSnippet:p,setSnippetDraft:A,deleteSnippet:b,loadSnippets:P}=ci(Ms(Vg));let N,k;e[0]!==P?(N=()=>{P()},k=[P],e[0]=P,e[1]=N,e[2]=k):(N=e[1],k=e[2]),o.useEffect(N,k);let g;e[3]!==a||e[4]!==p||e[5]!==A||e[6]!==v?(g=async()=>{const we=new Set(v.map(Bg));let ke="new-snippet",xe=1;for(;we.has(ke);)ke=`new-snippet-${xe++}`;A({name:ke,scope:"global"}),p(ke),a?.()},e[3]=a,e[4]=p,e[5]=A,e[6]=v,e[7]=g):g=e[7];const E=g;let O;e[8]!==i||e[9]!==b||e[10]!==n?(O=async()=>{if(!i)return;await b(i.name)?(D.success(n("settings.snippets.sidebar.toast.deleted")),r(null)):D.error(n("settings.snippets.sidebar.toast.deleteFailed"))},e[8]=i,e[9]=b,e[10]=n,e[11]=O):O=e[11];const I=O;let w;e[12]!==v?(w=[...v].sort(Hg),e[12]=v,e[13]=w):w=e[13];const m=w;let y;e[14]===Symbol.for("react.memo_cache_sentinel")?(y=je("flex h-full flex-col","bg-background"),e[14]=y):y=e[14];let K;e[15]!==n?(K=n("settings.snippets.sidebar.title"),e[15]=n,e[16]=K):K=e[16];let C;e[17]!==K?(C=s.jsx("h2",{className:`${rn} mb-3`,children:K}),e[17]=K,e[18]=C):C=e[18];let T;e[19]!==v.length||e[20]!==n?(T=n("settings.snippets.sidebar.total",{count:v.length}),e[19]=v.length,e[20]=n,e[21]=T):T=e[21];let j;e[22]!==T?(j=s.jsx("span",{className:"typography-meta text-muted-foreground",children:T}),e[22]=T,e[23]=j):j=e[23];let R;e[24]!==n?(R=n("settings.snippets.sidebar.actions.create"),e[24]=n,e[25]=R):R=e[25];let G;e[26]===Symbol.for("react.memo_cache_sentinel")?(G=s.jsx(L,{name:"add",className:"h-3.5 w-3.5"}),e[26]=G):G=e[26];let S;e[27]!==E||e[28]!==R?(S=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:E,"aria-label":R,children:G}),e[27]=E,e[28]=R,e[29]=S):S=e[29];let q;e[30]!==j||e[31]!==S?(q=s.jsxs("div",{className:"flex items-center justify-between gap-2",children:[j,S]}),e[30]=j,e[31]=S,e[32]=q):q=e[32];let Q;e[33]!==q||e[34]!==C?(Q=s.jsxs("div",{className:"border-b px-3 pt-4 pb-3",children:[C,q]}),e[33]=q,e[34]=C,e[35]=Q):Q=e[35];let M;if(e[36]!==a||e[37]!==l||e[38]!==d||e[39]!==c||e[40]!==p||e[41]!==m||e[42]!==n){let we;e[44]!==a||e[45]!==l||e[46]!==d||e[47]!==c||e[48]!==p||e[49]!==n?(we=ke=>s.jsxs(Gn,{open:d===ke.name,onOpenChange:xe=>x(xe?ke.name:null),children:[s.jsxs(Hn,{render:s.jsx("div",{className:je("group relative flex items-center rounded-md px-1.5 py-1 transition-all duration-200 select-none",c===ke.name?"bg-interactive-selection":"hover:bg-interactive-hover"),onContextMenu:xe=>{xe.preventDefault(),x(ke.name)}}),children:[s.jsxs("button",{onClick:()=>{p(ke.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:["#",ke.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.${ke.source}`)})]}),s.jsx("div",{className:"typography-micro text-muted-foreground/60 truncate leading-tight",children:ke.description||ke.content.replace(/\s+/g," ").substring(0,80)})]}),s.jsxs(nn,{open:l===ke.name,onOpenChange:xe=>{xe&&x(null),h(xe?ke.name:null)},children:[s.jsx(tn,{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:ke.name}),children:s.jsx(L,{name:"more-2",className:"h-3.5 w-3.5"})})}),s.jsx(sn,{align:"end",className:"w-fit min-w-20",children:s.jsxs(an,{onClick:xe=>{xe.stopPropagation(),r(ke)},className:"text-destructive focus:text-destructive",children:[s.jsx(L,{name:"delete-bin",className:"h-4 w-4 mr-px"}),n("settings.common.actions.delete")]})})]})]}),s.jsx(Vn,{className:"w-fit min-w-20",children:s.jsxs(Bn,{onClick:xe=>{xe.stopPropagation(),r(ke)},className:"text-destructive focus:text-destructive",children:[s.jsx(L,{name:"delete-bin",className:"h-4 w-4 mr-px"}),n("settings.common.actions.delete")]})})]},`${ke.source}:${ke.filePath}`),e[44]=a,e[45]=l,e[46]=d,e[47]=c,e[48]=p,e[49]=n,e[50]=we):we=e[50],M=m.map(we),e[36]=a,e[37]=l,e[38]=d,e[39]=c,e[40]=p,e[41]=m,e[42]=n,e[43]=M}else M=e[43];let W;e[51]!==M?(W=s.jsx(Vs,{outerClassName:"flex-1 min-h-0",className:"space-y-1 px-3 py-2",children:M}),e[51]=M,e[52]=W):W=e[52];const Y=i!==null;let F;e[53]===Symbol.for("react.memo_cache_sentinel")?(F=we=>{we||r(null)},e[53]=F):F=e[53];let se;e[54]!==n?(se=n("settings.snippets.sidebar.dialog.deleteTitle"),e[54]=n,e[55]=se):se=e[55];let _;e[56]!==se?(_=s.jsx(qt,{children:se}),e[56]=se,e[57]=_):_=e[57];const V=i?.name??"";let z;e[58]!==n||e[59]!==V?(z=n("settings.snippets.sidebar.dialog.deleteDescription",{name:V}),e[58]=n,e[59]=V,e[60]=z):z=e[60];let U;e[61]!==z?(U=s.jsx(Wt,{children:z}),e[61]=z,e[62]=U):U=e[62];let X;e[63]!==_||e[64]!==U?(X=s.jsxs(Gt,{children:[_,U]}),e[63]=_,e[64]=U,e[65]=X):X=e[65];let Z;e[66]===Symbol.for("react.memo_cache_sentinel")?(Z=()=>r(null),e[66]=Z):Z=e[66];let ne;e[67]!==n?(ne=n("settings.common.actions.cancel"),e[67]=n,e[68]=ne):ne=e[68];let le;e[69]!==ne?(le=s.jsx(B,{size:"sm",variant:"ghost",onClick:Z,children:ne}),e[69]=ne,e[70]=le):le=e[70];let re;e[71]!==n?(re=n("settings.common.actions.delete"),e[71]=n,e[72]=re):re=e[72];let fe;e[73]!==I||e[74]!==re?(fe=s.jsx(B,{size:"sm",onClick:I,children:re}),e[73]=I,e[74]=re,e[75]=fe):fe=e[75];let ae;e[76]!==le||e[77]!==fe?(ae=s.jsxs(ms,{children:[le,fe]}),e[76]=le,e[77]=fe,e[78]=ae):ae=e[78];let ie;e[79]!==X||e[80]!==ae?(ie=s.jsxs(_t,{className:"max-w-md",children:[X,ae]}),e[79]=X,e[80]=ae,e[81]=ie):ie=e[81];let te;e[82]!==Y||e[83]!==ie?(te=s.jsx(zt,{open:Y,onOpenChange:F,children:ie}),e[82]=Y,e[83]=ie,e[84]=te):te=e[84];let ye;return e[85]!==Q||e[86]!==W||e[87]!==te?(ye=s.jsxs("div",{className:y,children:[Q,W,te]}),e[85]=Q,e[86]=W,e[87]=te,e[88]=ye):ye=e[88],ye};function Vg(t){return{selectedSnippetName:t.selectedSnippetName,snippets:t.snippets,setSelectedSnippet:t.setSelectedSnippet,setSnippetDraft:t.setSnippetDraft,deleteSnippet:t.deleteSnippet,loadSnippets:t.loadSnippets}}function Bg(t){return t.name}function Hg(t,e){return t.name.localeCompare(e.name)}const Gg=()=>{const{t}=ot(),{selectedSnippetName:e,snippets:a,snippetDraft:n,setSnippetDraft:i,updateSnippet:r,createSnippet:l}=ci(Ms(y=>({selectedSnippetName:y.selectedSnippetName,snippets:y.snippets,snippetDraft:y.snippetDraft,setSnippetDraft:y.setSnippetDraft,updateSnippet:y.updateSnippet,createSnippet:y.createSnippet}))),h=o.useMemo(()=>e?a.find(y=>y.name===e||y.aliases.includes(e))??null:null,[e,a]),d=!!(n&&n.name===e&&!h),[x,c]=o.useState(""),[v,p]=o.useState("global"),[A,b]=o.useState(""),[P,N]=o.useState(""),[k,g]=o.useState(""),[E,O]=o.useState(!1),I=o.useRef(null);o.useEffect(()=>{if(d&&n){const y={draftName:n.name||"",draftScope:n.scope||"global",description:n.description||"",aliases:(n.aliases||[]).join(", "),content:n.content||""};c(y.draftName),p(y.draftScope),b(y.description),N(y.aliases),g(y.content),I.current=y}else if(h){const y={draftName:"",draftScope:"global",description:h.description??"",aliases:h.aliases.join(", "),content:h.content};b(y.description),N(y.aliases),g(y.content),I.current=y}},[h,d,e,n]);const w=o.useMemo(()=>{const y=I.current;return y?d&&x!==y.draftName||d&&v!==y.draftScope?!0:A!==y.description||P!==y.aliases||k!==y.content:!1},[P,k,A,x,v,d]),m=async()=>{const y=d?x.trim().replace(/\s+/g,"-"):e?.trim();if(!y){D.error(t("settings.snippets.page.toast.nameRequired"));return}if(!k.trim()){D.error(t("settings.snippets.page.toast.contentRequired"));return}const K=P.split(",").map(C=>C.trim()).filter(Boolean);O(!0);try{if(!(d?await l(y,k,{aliases:K,description:A,scope:v}):await r(y,{content:k,aliases:K,description:A}))){D.error(t("settings.snippets.page.toast.saveFailed"));return}D.success(t("settings.snippets.page.toast.saved")),d&&i(null)}finally{O(!1)}};return e?s.jsxs(gs,{title:d?t("settings.snippets.page.title.new"):`#${e}`,description:h?h.filePath:void 0,showSaveStatus:!1,children:[s.jsxs(Be,{divider:!1,contentClassName:"space-y-0",children:[d?s.jsxs(Qt,{label:"#",children:[s.jsx(Ye,{value:x,onChange:y=>c(y.target.value),placeholder:t("settings.snippets.page.field.namePlaceholder"),className:"h-7 w-44 px-2"}),s.jsxs(Ot,{value:v,onValueChange:y=>p(y),children:[s.jsx(Lt,{size:Jt,className:"w-fit min-w-[100px]",children:s.jsx(Ht,{})}),s.jsxs(Ft,{align:"end",children:[s.jsx(ut,{value:"global",children:t("settings.common.scope.global")}),s.jsx(ut,{value:"project",children:t("settings.common.scope.project")})]})]})]}):null,s.jsx(es,{label:t("settings.common.field.description"),children:s.jsx(Ye,{value:A,onChange:y=>b(y.target.value),placeholder:t("settings.snippets.page.field.descriptionPlaceholder"),className:"h-7 w-full max-w-sm px-2"})}),s.jsx(es,{label:t("settings.snippets.page.field.aliases"),children:s.jsx(Ye,{value:P,onChange:y=>N(y.target.value),placeholder:t("settings.snippets.page.field.aliasesPlaceholder"),className:"h-7 w-full max-w-sm px-2"})})]}),s.jsxs(Be,{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(ss,{children:t("settings.snippets.page.hint")})]}),s.jsx(Es,{value:k,onChange:y=>g(y.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:m,disabled:E||!w,size:"xs",className:"!font-normal",children:t(E?"settings.common.actions.saving":"settings.common.actions.saveChanges")})})]})]}):s.jsx("div",{className:"flex h-full items-center justify-center",children:s.jsxs("div",{className:"text-center text-muted-foreground",children:[s.jsx(L,{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")})]})})},Ul=()=>{const{t}=ot(),e=tt(v=>v.settingsGitmojiEnabled),a=tt(v=>v.setSettingsGitmojiEnabled),n=ud(),i=ce(v=>v.gitChangesViewMode),r=ce(v=>v.setGitChangesViewMode),[l,h]=o.useState(!0),d=o.useMemo(()=>[{id:"flat",label:t("settings.openchamber.git.option.flatList")},{id:"tree",label:t("settings.openchamber.git.option.treeView")}],[t]);o.useEffect(()=>{(async()=>{try{let p=null;if(!p){const A=In()?.settings;if(A)try{const P=(await A.load())?.settings;P&&(p={gitmojiEnabled:typeof P.gitmojiEnabled=="boolean"?P.gitmojiEnabled:void 0,gitChangesViewMode:P.gitChangesViewMode==="flat"||P.gitChangesViewMode==="tree"?P.gitChangesViewMode:void 0})}catch{}}if(!p){const A=await pt("/api/config/settings",{method:"GET",headers:{Accept:"application/json"}});A.ok&&(p=await A.json())}p&&(typeof p.gitmojiEnabled=="boolean"&&a(p.gitmojiEnabled),(p.gitChangesViewMode==="flat"||p.gitChangesViewMode==="tree")&&r(p.gitChangesViewMode))}catch(p){console.warn("Failed to load git settings:",p)}finally{h(!1)}})()},[r,a]);const x=o.useCallback(async v=>{a(v);try{await Nt({gitmojiEnabled:v})}catch(p){console.warn("Failed to save gitmoji setting:",p)}},[a]),c=o.useCallback(v=>{v!==i&&(r(v),Nt({gitChangesViewMode:v}))},[i,r]);return l?null:s.jsx(Be,{title:t("settings.openchamber.git.title"),children:s.jsxs("div",{className:Ns,children:[s.jsx(_s,{settingsItem:"git.changes-view",title:t("settings.openchamber.git.changesViewTitle"),children:s.jsx(wn,{"aria-label":t("settings.openchamber.git.changesViewAria"),children:d.map(v=>s.jsx(kn,{selected:i===v.id,onSelect:()=>{c(v.id)},label:v.label,ariaLabel:t("settings.openchamber.git.optionAria",{option:v.label})},v.id))})}),s.jsx(ht,{settingsItem:"git.gitmoji",checked:e,onChange:v=>{x(v)},label:t("settings.openchamber.git.enableGitmoji"),ariaLabel:t("settings.openchamber.git.enableGitmojiAria")}),s.jsx(ht,{settingsItem:"git.gitignored-files",checked:n,onChange:gd,label:t("settings.openchamber.git.showGitignored"),ariaLabel:t("settings.openchamber.git.showGitignoredAria")})]})})},zl=()=>{const{t}=ot(),{isMobile:e}=da(),a=In()?.github,n=xa(j=>j.status),i=xa(j=>j.isLoading),r=xa(j=>j.hasChecked),l=xa(j=>j.refreshStatus),h=xa(j=>j.setStatus),d=o.useCallback(async j=>{await An(j)},[]),[x,c]=o.useState(!1),[v,p]=o.useState(null),[A,b]=o.useState(null),P=o.useRef(null),N=o.useCallback(()=>{P.current!=null&&(window.clearInterval(P.current),P.current=null),b(null)},[]);o.useEffect(()=>((async()=>{try{r||await l(a)}catch(j){console.warn("Failed to load GitHub auth status:",j)}})(),()=>{N()}),[r,l,a,N]);const k=o.useCallback(async()=>{c(!0);try{const j=a?await a.authStart():await(async()=>{const G=await pt("/api/github/auth/start",{method:"POST",headers:{"Content-Type":"application/json",Accept:"application/json"},body:JSON.stringify({})}),S=await G.json().catch(()=>null);if(!G.ok||!S||!("deviceCode"in S))throw new Error(S?.error||G.statusText);return S})();p(j),b(Math.max(1,j.interval)*1e3);const R=j.verificationUriComplete||j.verificationUri;d(R)}catch(j){console.error("Failed to start GitHub connect:",j),D.error(t("settings.github.page.toast.startConnectFailed"))}finally{c(!1)}},[d,a,t]),g=o.useCallback(async j=>{if(a)return a.authComplete(j);const R=await pt("/api/github/auth/complete",{method:"POST",headers:{"Content-Type":"application/json",Accept:"application/json"},body:JSON.stringify({deviceCode:j})}),G=await R.json().catch(()=>null);if(!R.ok||!G)throw new Error(G?.error||R.statusText);return G},[a]);o.useEffect(()=>{if(!(!v?.deviceCode||!A)&&P.current==null)return P.current=window.setInterval(()=>{(async()=>{try{const j=await g(v.deviceCode);if(j.connected){D.success(t("settings.github.page.toast.connected")),p(null),N(),await l(a,{force:!0});return}j.status==="slow_down"&&b(R=>R?R+5e3:5e3),(j.status==="expired_token"||j.status==="access_denied")&&(D.error(j.error||t("settings.github.page.toast.authorizationFailed")),p(null),N())}catch(j){console.warn("GitHub polling failed:",j)}})()},A),()=>{P.current!=null&&(window.clearInterval(P.current),P.current=null)}},[v,A,g,l,a,N,t]);const E=o.useCallback(async j=>{c(!0);try{if(a)await a.authSetGhCliDisabled(j);else{const R=await pt("/api/github/auth/gh-cli",{method:"POST",headers:{"Content-Type":"application/json",Accept:"application/json"},body:JSON.stringify({disabled:j})}),G=await R.json().catch(()=>null);if(!R.ok)throw new Error(G?.error||R.statusText)}D.success(t(j?"settings.github.page.toast.ghCliDisabled":"settings.github.page.toast.ghCliEnabled")),await l(a,{force:!0})}catch(R){console.error("Failed to update gh CLI setting:",R),D.error(t("settings.github.page.toast.ghCliUpdateFailed"))}finally{c(!1)}},[l,a,t]),O=o.useCallback(async()=>{c(!0);try{if(N(),p(null),a)await a.authDisconnect();else{const j=await pt("/api/github/auth",{method:"DELETE",headers:{Accept:"application/json"}});if(!j.ok)throw new Error(j.statusText)}D.success(t("settings.github.page.toast.disconnected")),await l(a,{force:!0})}catch(j){console.error("Failed to disconnect GitHub:",j),D.error(t("settings.github.page.toast.disconnectFailed"))}finally{c(!1)}},[l,a,N,t]),I=o.useCallback(async j=>{if(j){c(!0);try{const R=a?await a.authActivate(j):await(async()=>{const G=await pt("/api/github/auth/activate",{method:"POST",headers:{"Content-Type":"application/json",Accept:"application/json"},body:JSON.stringify({accountId:j})}),S=await G.json().catch(()=>null);if(!G.ok||!S)throw new Error(S?.error||G.statusText);return S})();h(R),D.success(t("settings.github.page.toast.accountSwitched"))}catch(R){console.error("Failed to switch GitHub account:",R),D.error(t("settings.github.page.toast.accountSwitchFailed"))}finally{c(!1)}}},[a,h,t]);if(i)return null;const w=!!n?.connected,m=n?.user,K=(n?.accounts??[]).filter(j=>!j.current),C=n?.ghCli??null,T=C?.active?t("settings.github.page.accountSource.cli"):t("settings.github.page.accountSource.oauth");return s.jsxs(s.Fragment,{children:[s.jsxs(Be,{title:t("settings.github.page.oauth.title"),divider:!1,settingsItem:"git.github-account",info:t("settings.github.page.tooltip.connectAccount"),children:[s.jsxs("div",{className:"rounded-lg bg-[var(--surface-elevated)]/70 overflow-hidden flex flex-col",children:[w?s.jsxs("div",{className:je("px-4 py-3",e?"flex flex-col gap-3":"flex items-center justify-between gap-4"),children:[s.jsxs("div",{className:je("flex min-w-0 items-center gap-4",e?"w-full":void 0),children:[m?.avatarUrl?s.jsx("img",{src:m.avatarUrl,alt:m.login?t("settings.github.page.avatarAlt.withLogin",{login:m.login}):t("settings.github.page.avatarAlt.fallback"),className:"h-10 w-10 shrink-0 rounded-full border border-[var(--interactive-border)] bg-[var(--surface-muted)] object-cover",loading:"lazy",referrerPolicy:"no-referrer"}):s.jsx("div",{className:"h-10 w-10 shrink-0 rounded-full border border-[var(--interactive-border)] bg-[var(--surface-muted)]"}),s.jsxs("div",{className:"min-w-0 flex-1",children:[s.jsx("div",{className:"typography-ui-label text-foreground",children:m?.name?.trim()||m?.login||"GitHub"}),s.jsxs("div",{className:je("flex items-center gap-2 typography-meta text-muted-foreground mt-0.5",e?"flex-wrap":"truncate"),children:[s.jsx(L,{name:"github-fill",className:"h-3.5 w-3.5 shrink-0"}),s.jsx("span",{className:"font-mono",children:m?.login||t("settings.github.page.label.unknownUser")}),m?.email&&s.jsx("span",{className:"opacity-50",children:"•"}),m?.email&&s.jsx("span",{children:m.email}),s.jsx("span",{className:"opacity-50",children:"•"}),s.jsx("span",{children:T})]}),n?.scope&&s.jsx("div",{className:"typography-micro text-muted-foreground/70 mt-0.5",children:t("settings.github.page.label.scopes",{value:n.scope})}),C?.active&&s.jsx("div",{className:"typography-micro text-muted-foreground/70 mt-0.5",children:t("settings.github.page.ghCli.activeDescription")})]})]}),C?.active?s.jsx(B,{size:"sm",variant:"outline",onClick:()=>E(!0),disabled:x,className:je(e?"w-full":void 0),children:t("settings.github.page.ghCli.actions.disable")}):s.jsx(B,{size:"sm",variant:"outline",onClick:O,disabled:x,className:je("text-[var(--status-error)] hover:text-[var(--status-error)]",e?"w-full":void 0),children:t("settings.github.page.actions.disconnect")})]}):s.jsxs("div",{className:"flex items-center justify-between gap-4 px-4 py-4",children:[s.jsx("div",{className:"flex min-w-0 flex-col",children:s.jsx("span",{className:"typography-ui-label text-foreground",children:t("settings.github.page.status.notConnected")})}),s.jsx(B,{size:"sm",variant:"default",onClick:k,disabled:x,children:t("settings.github.page.actions.connect")})]}),K.length>0&&s.jsxs("div",{className:"mt-2 border-t border-[var(--surface-subtle)] pt-2 px-2 pb-1",children:[s.jsx("div",{className:"typography-micro text-muted-foreground mb-2 px-1",children:t("settings.github.page.label.otherAccounts")}),s.jsx("div",{className:"space-y-1",children:K.map(j=>{const R=j.user,G=j.source==="gh-cli"?t("settings.github.page.accountSource.cli"):t("settings.github.page.accountSource.oauth");return s.jsxs("div",{className:"flex items-center justify-between gap-3 rounded-md border border-[var(--surface-subtle)] bg-[var(--surface-muted)] px-3 py-2",children:[s.jsxs("div",{className:"flex min-w-0 items-center gap-3",children:[R?.avatarUrl?s.jsx("img",{src:R.avatarUrl,alt:R.login?t("settings.github.page.avatarAlt.withLogin",{login:R.login}):t("settings.github.page.avatarAlt.fallback"),className:"h-6 w-6 shrink-0 rounded-full border border-[var(--interactive-border)] bg-[var(--surface-muted)] object-cover",loading:"lazy",referrerPolicy:"no-referrer"}):s.jsx("div",{className:"flex h-6 w-6 shrink-0 items-center justify-center rounded-full border border-[var(--interactive-border)] bg-[var(--surface-muted)]",children:s.jsx(L,{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:R?.name?.trim()||R?.login||"GitHub"}),R?.login&&s.jsxs("span",{className:"typography-micro text-muted-foreground truncate",children:[s.jsx("span",{className:"font-mono",children:R.login}),s.jsx("span",{className:"mx-1 opacity-50",children:"·"}),s.jsx("span",{children:G})]})]})]}),s.jsx(B,{size:"sm",variant:"ghost",onClick:()=>I(j.id),disabled:x,children:t("settings.github.page.actions.switchTo")})]},j.id)})})]})]}),w&&s.jsx("div",{className:"mt-2 px-2 pb-2",children:s.jsx(B,{size:"sm",variant:"outline",onClick:k,disabled:x,className:je(e?"w-full":void 0),children:t("settings.github.page.actions.addAccount")})}),v&&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(en,{children:t("settings.github.page.flow.title")}),s.jsx("p",{className:"typography-meta text-muted-foreground",children:t("settings.github.page.flow.description")})]}),s.jsxs("div",{className:"flex items-center justify-between gap-3 mt-4",children:[s.jsx("div",{className:"font-mono text-xl tracking-widest text-foreground bg-[var(--surface-muted)] px-3 py-1.5 rounded-md border border-[var(--interactive-border)]",children:v.userCode}),s.jsx(B,{size:"sm",asChild:!0,children:s.jsx("a",{href:v.verificationUriComplete||v.verificationUri,target:"_blank",rel:"noopener noreferrer",children:t("settings.github.page.actions.openGithub")})})]}),s.jsxs("div",{className:"mt-4 flex items-center justify-between",children:[s.jsx("span",{className:"typography-micro text-muted-foreground animate-pulse",children:t("settings.github.page.flow.waiting")}),s.jsx(B,{size:"sm",variant:"ghost",disabled:x,onClick:()=>{N(),p(null)},children:t("settings.common.actions.cancel")})]})]})]}),C?.available&&!C?.active&&(!C.user||C.disabled)&&s.jsx(Be,{title:t("settings.github.page.ghCli.title"),children:s.jsx("div",{className:"rounded-lg bg-[var(--surface-elevated)]/70 overflow-hidden",children:s.jsxs("div",{className:je("px-4 py-3",e?"flex flex-col gap-3":"flex items-center justify-between gap-4"),children:[s.jsxs("div",{className:je("flex min-w-0 items-center gap-4",e?"w-full":void 0),children:[C.user?.avatarUrl?s.jsx("img",{src:C.user.avatarUrl,alt:C.user.login?t("settings.github.page.avatarAlt.withLogin",{login:C.user.login}):t("settings.github.page.avatarAlt.fallback"),className:"h-10 w-10 shrink-0 rounded-full border border-[var(--interactive-border)] bg-[var(--surface-muted)] object-cover",loading:"lazy",referrerPolicy:"no-referrer"}):s.jsx("div",{className:"flex h-10 w-10 shrink-0 items-center justify-center rounded-full border border-[var(--interactive-border)] bg-[var(--surface-muted)]",children:s.jsx(L,{name:"github-fill",className:"h-4 w-4 text-muted-foreground"})}),s.jsxs("div",{className:"min-w-0 flex-1",children:[!C.disabled&&C.user&&s.jsx("div",{className:"typography-ui-label text-foreground truncate",children:C.user.name?.trim()||C.user.login||"GitHub"}),!C.disabled&&C.user?.login&&s.jsxs("div",{className:je("flex items-center gap-2 typography-meta text-muted-foreground mt-0.5",e?"flex-wrap":"truncate"),children:[s.jsx(L,{name:"github-fill",className:"h-3.5 w-3.5 shrink-0"}),s.jsx("span",{className:"font-mono",children:C.user.login}),C.user.email&&s.jsx("span",{className:"opacity-50",children:"•"}),C.user.email&&s.jsx("span",{children:C.user.email})]}),s.jsx("div",{className:je("typography-meta text-muted-foreground",C.disabled?"opacity-60":void 0),children:C.disabled?t("settings.github.page.ghCli.disabledDescription"):t("settings.github.page.ghCli.fallbackDescription")})]})]}),s.jsx(B,{size:"sm",variant:"outline",onClick:()=>E(!C.disabled),disabled:x,className:je(e?"w-full":void 0),children:C.disabled?t("settings.github.page.ghCli.actions.enable"):t("settings.github.page.ghCli.actions.disable")})]})})})]})},Oo=[{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)"}],qg=[{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"}],Wg=({open:t,onOpenChange:e,profileId:a,importData:n})=>{const{t:i}=ot(),r=Kn(U=>U.getProfileById),l=Kn(U=>U.createProfile),h=Kn(U=>U.updateProfile),d=Kn(U=>U.deleteProfile),x=o.useMemo(()=>a&&a!=="new"&&!n?r(a):null,[a,r,n]),c=a==="new"||n!=null,v=a==="global",[p,A]=o.useState(""),[b,P]=o.useState(""),[N,k]=o.useState(""),[g,E]=o.useState("ssh"),[O,I]=o.useState(""),[w,m]=o.useState(!1),[y,K]=o.useState(""),[C,T]=o.useState(""),[j,R]=o.useState("keyword"),[G,S]=o.useState("branch"),[q,Q]=o.useState(!1),[M,W]=o.useState(!1),[Y,F]=o.useState(!1);o.useEffect(()=>{if(t){if(n){const U=n.host.split("/"),X=U.length>=3?U[U.length-1]:n.host;A(X),P(n.username),k(""),E("token"),I(""),m(!1),K(""),T(n.host),R("string"),S("code")}else if(c)A(""),P(""),k(""),E("ssh"),I(""),m(!1),K(""),T(""),R("keyword"),S("branch");else if(x)A(x.name),P(x.userName),k(x.userEmail),E(x.authType||"ssh"),I(x.sshKey||""),m(x.signCommits===!0),K(x.signingKey||""),T(x.host||""),R(x.color||"keyword"),S(x.icon||"branch");else if(v){const U=r("global");U&&(A(U.name),P(U.userName),k(U.userEmail),E(U.authType||"ssh"),I(U.sshKey||""),m(!1),K(""),T(U.host||""),R(U.color||"keyword"),S(U.icon||"branch"))}}},[t,a,x,c,n,v,r]);const se=async()=>{if(!b.trim()||!N.trim()){D.error(i("settings.gitIdentities.editor.toast.userNameEmailRequired"));return}if(g==="token"&&!C.trim()){D.error(i("settings.gitIdentities.editor.toast.hostRequiredForToken"));return}if(w&&!y.trim()){D.error(i("settings.gitIdentities.editor.toast.signingKeyRequired"));return}Q(!0);try{const U={name:p.trim()||b.trim(),userName:b.trim(),userEmail:N.trim(),authType:g,sshKey:g==="ssh"&&O.trim()||null,signCommits:w,signingKey:y.trim()||null,host:g==="token"&&C.trim()||null,color:j,icon:G};let X;if(c)X=await l(U);else if(a)X=await h(a,U);else return;X?(D.success(i(c?"settings.gitIdentities.editor.toast.profileCreated":"settings.gitIdentities.editor.toast.profileUpdated")),e(!1)):D.error(i(c?"settings.gitIdentities.editor.toast.createProfileFailed":"settings.gitIdentities.editor.toast.updateProfileFailed"))}catch(U){console.error("Error saving profile:",U),D.error(i("settings.gitIdentities.editor.toast.saveUnexpectedError"))}finally{Q(!1)}},_=async()=>{if(!(!a||c)){F(!0);try{await d(a)?(D.success(i("settings.gitIdentities.editor.toast.profileDeleted")),W(!1),e(!1)):D.error(i("settings.gitIdentities.editor.toast.deleteProfileFailed"))}catch(U){console.error("Error deleting profile:",U),D.error(i("settings.gitIdentities.editor.toast.deleteUnexpectedError"))}finally{F(!1)}}},V=o.useMemo(()=>Oo.find(X=>X.key===j)?.cssVar||"var(--syntax-keyword)",[j]),z=n?i("settings.gitIdentities.editor.title.importCredential"):c?i("settings.gitIdentities.editor.title.newIdentity"):v?i("settings.gitIdentities.editor.title.globalIdentity"):x?.name||i("settings.gitIdentities.editor.title.editIdentity");return s.jsxs(s.Fragment,{children:[s.jsx(zt,{open:t,onOpenChange:e,children:s.jsxs(_t,{className:"max-w-lg max-h-[85vh] overflow-y-auto",children:[s.jsxs(Gt,{children:[s.jsx(qt,{children:z}),s.jsx(Wt,{children:i(v?"settings.gitIdentities.editor.description.globalReadOnly":c?"settings.gitIdentities.editor.description.newProfile":"settings.gitIdentities.editor.description.editProfile")})]}),s.jsxs("div",{className:"space-y-5 py-2",children:[!v&&s.jsxs("div",{className:"space-y-3",children:[s.jsxs("div",{children:[s.jsx("label",{className:`${Rt} block mb-1.5`,children:i("settings.gitIdentities.editor.field.profileName")}),s.jsx(Ye,{value:p,onChange:U=>A(U.target.value),placeholder:i("settings.gitIdentities.editor.field.profileNamePlaceholder"),className:"h-8"})]}),s.jsxs("div",{className:"flex items-center justify-between gap-4",children:[s.jsx("span",{className:"typography-ui-label text-foreground",children:i("settings.gitIdentities.editor.field.color")}),s.jsx("div",{className:"flex gap-1.5",children:Oo.map(U=>s.jsx("button",{type:"button",onClick:()=>R(U.key),className:je("w-6 h-6 rounded-md border-2 transition-all cursor-pointer",j===U.key?"border-foreground scale-110":"border-transparent hover:border-border"),style:{backgroundColor:U.cssVar},title:U.label},U.key))})]}),s.jsxs("div",{className:"flex items-center justify-between gap-4",children:[s.jsx("span",{className:"typography-ui-label text-foreground",children:i("settings.gitIdentities.editor.field.icon")}),s.jsx("div",{className:"flex gap-1.5",children:qg.map(U=>{const X=U.Icon;return s.jsx("button",{type:"button",onClick:()=>S(U.key),className:je("w-7 h-7 rounded-md border-2 transition-all flex items-center justify-center cursor-pointer",G===U.key?"border-[var(--interactive-border)] bg-[var(--surface-muted)]":"border-transparent hover:border-[var(--interactive-border)] hover:bg-[var(--surface-muted)]/50"),title:U.label,children:s.jsx(L,{name:X,className:"w-3.5 h-3.5",style:{color:G===U.key?V:"var(--surface-muted-foreground)"}})},U.key)})})]})]}),!v&&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:Rt,children:i("settings.gitIdentities.editor.field.userName")}),!v&&s.jsx("span",{className:"text-[var(--status-error)] text-xs",children:"*"}),s.jsx(ss,{contentClassName:"max-w-xs",children:i("settings.gitIdentities.editor.field.userNameTooltip")})]}),s.jsx(Ye,{value:b,onChange:U=>P(U.target.value),placeholder:i("settings.gitIdentities.editor.field.userNamePlaceholder"),required:!v,readOnly:v,disabled:v,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:Rt,children:i("settings.gitIdentities.editor.field.emailAddress")}),!v&&s.jsx("span",{className:"text-[var(--status-error)] text-xs",children:"*"}),s.jsx(ss,{contentClassName:"max-w-xs",children:i("settings.gitIdentities.editor.field.emailAddressTooltip")})]}),s.jsx(Ye,{type:"email",value:N,onChange:U=>k(U.target.value),placeholder:i("settings.gitIdentities.editor.field.emailAddressPlaceholder"),required:!v,readOnly:v,disabled:v,className:"h-8"})]})]}),!v&&s.jsxs(s.Fragment,{children:[s.jsx("div",{className:"border-t border-border/40"}),s.jsxs("div",{className:"space-y-3",children:[s.jsxs("div",{className:"flex items-center justify-between gap-4",children:[s.jsx("span",{className:"typography-ui-label text-foreground",children:i("settings.gitIdentities.editor.field.authMethod")}),s.jsxs("div",{className:"flex items-center gap-1",children:[s.jsxs(B,{size:"sm",type:"button",variant:"chip","aria-pressed":g==="ssh",onClick:()=>E("ssh"),children:[s.jsx(L,{name:"lock-2",className:"w-3.5 h-3.5 mr-1"})," SSH"]}),s.jsxs(B,{size:"sm",type:"button",variant:"chip","aria-pressed":g==="token",onClick:()=>E("token"),children:[s.jsx(L,{name:"key",className:"w-3.5 h-3.5 mr-1"})," ",i("settings.gitIdentities.editor.field.authToken")]})]})]}),g==="ssh"&&s.jsxs("div",{children:[s.jsxs("div",{className:"flex items-center gap-1.5 mb-1.5",children:[s.jsx("label",{className:Rt,children:i("settings.gitIdentities.editor.field.sshKeyPath")}),s.jsx(ss,{contentClassName:"max-w-xs",children:i("settings.gitIdentities.editor.field.sshKeyPathTooltip")})]}),s.jsx(Ye,{value:O,onChange:U=>I(U.target.value),placeholder:i("settings.gitIdentities.editor.field.sshKeyPathPlaceholder"),className:"h-8 font-mono text-xs"})]}),s.jsxs("div",{className:"border-t border-border/40 pt-3 space-y-3",children:[s.jsx(ht,{checked:w,onChange:m,label:i("settings.gitIdentities.editor.field.signCommits"),info:i("settings.gitIdentities.editor.section.commitSigning"),ariaLabel:i("settings.gitIdentities.editor.field.signCommits")}),s.jsxs("div",{children:[s.jsx("div",{className:"flex items-center gap-1.5 mb-1.5",children:s.jsx("label",{className:Rt,children:i("settings.gitIdentities.editor.field.signingKey")})}),s.jsx(Ye,{value:y,onChange:U=>K(U.target.value),placeholder:i("settings.gitIdentities.editor.field.signingKeyPlaceholder"),disabled:!w,className:"h-8 font-mono text-xs"})]})]}),g==="token"&&s.jsxs("div",{children:[s.jsxs("div",{className:"flex items-center gap-1.5 mb-1.5",children:[s.jsx("label",{className:Rt,children:i("settings.gitIdentities.editor.field.host")}),s.jsx("span",{className:"text-[var(--status-error)] text-xs",children:"*"}),s.jsx(ss,{contentClassName:"max-w-xs",children:i("settings.gitIdentities.editor.field.hostTooltip")})]}),s.jsx(Ye,{value:C,onChange:U=>T(U.target.value),placeholder:i("settings.gitIdentities.editor.field.hostPlaceholder"),required:!0,className:"h-8 font-mono text-xs"})]})]})]})]}),s.jsxs(ms,{className:"gap-2",children:[!v&&!c&&s.jsxs(B,{variant:"outline",size:"sm",onClick:()=>W(!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(L,{name:"delete-bin",className:"w-3.5 h-3.5 mr-1"})," ",i("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:i(v?"settings.gitIdentities.editor.actions.close":"settings.common.actions.cancel")}),!v&&s.jsx(B,{size:"sm",onClick:se,disabled:q,children:i(q?"settings.common.actions.saving":c?"settings.gitIdentities.editor.actions.create":"settings.gitIdentities.editor.actions.save")})]})]})}),s.jsx(zt,{open:M,onOpenChange:U=>{Y||W(U)},children:s.jsxs(_t,{className:"max-w-md",children:[s.jsxs(Gt,{children:[s.jsx(qt,{children:i("settings.gitIdentities.page.deleteDialog.title")}),s.jsx(Wt,{children:i("settings.gitIdentities.page.deleteDialog.description",{name:x?.name||p})})]}),s.jsxs(ms,{children:[s.jsx(B,{variant:"ghost",onClick:()=>W(!1),disabled:Y,children:i("settings.common.actions.cancel")}),s.jsx(B,{size:"sm",variant:"destructive",onClick:()=>{_()},disabled:Y,children:i("settings.common.actions.delete")})]})]})})]})},Jg={branch:"git-branch",briefcase:"briefcase",house:"home",graduation:"graduation-cap",code:"code",heart:"heart"},Qg={keyword:"var(--syntax-keyword)",error:"var(--status-error)",string:"var(--syntax-string)",function:"var(--syntax-function)",type:"var(--syntax-type)"},Yg=()=>{const t=mt.c(113),{t:e}=ot(),{profiles:a,globalIdentity:n,defaultGitIdentityId:i,deleteProfile:r,loadProfiles:l,loadGlobalIdentity:h,loadDiscoveredCredentials:d,loadDefaultGitIdentityId:x,setDefaultGitIdentityId:c,getUnimportedCredentials:v}=Kn(Ms(Xg)),[p,A]=o.useState(!1),[b,P]=o.useState(null),[N,k]=o.useState(null),[g,E]=o.useState(null),[O,I]=o.useState(!1);let w,m;t[0]!==x||t[1]!==d||t[2]!==h||t[3]!==l?(w=()=>{l(),h(),d(),x()},m=[l,h,d,x],t[0]=x,t[1]=d,t[2]=h,t[3]=l,t[4]=w,t[5]=m):(w=t[4],m=t[5]),o.useEffect(w,m);let y,K,C,T,j,R,G,S,q,Q,M,W,Y,F;if(t[6]!==i||t[7]!==g||t[8]!==r||t[9]!==v||t[10]!==n||t[11]!==a||t[12]!==c||t[13]!==e){const Ve=v();let _e;t[28]===Symbol.for("react.memo_cache_sentinel")?(_e=(Ue,ve)=>{P(Ue),k(ve??null),A(!0)},t[28]=_e):_e=t[28];const Le=_e;let Re;t[29]!==i||t[30]!==c||t[31]!==e?(Re=async Ue=>{const ve=i===Ue?null:Ue;if(!await c(ve)){D.error(e("settings.gitIdentities.page.toast.updateDefaultFailed"));return}D.success(e(ve?"settings.gitIdentities.page.toast.defaultUpdated":"settings.gitIdentities.page.toast.defaultUnset"))},t[29]=i,t[30]=c,t[31]=e,t[32]=Re):Re=t[32];const Ze=Re;let Ge;t[33]!==g||t[34]!==r||t[35]!==e?(Ge=async()=>{if(!g)return;I(!0),await r(g.id)?(D.success(e("settings.gitIdentities.page.toast.profileDeleted",{name:g.name})),E(null)):D.error(e("settings.gitIdentities.page.toast.deleteProfileFailed")),I(!1)},t[33]=g,t[34]=r,t[35]=e,t[36]=Ge):Ge=t[36],C=Ge,K=gs,t[37]!==e?(T=e("settings.page.git.title"),t[37]=e,t[38]=T):T=t[38],j=!0,t[39]===Symbol.for("react.memo_cache_sentinel")?(R=s.jsx(zl,{}),t[39]=R):R=t[39],y=Be,t[40]!==e?(W=e("settings.gitIdentities.page.section.title"),t[40]=e,t[41]=W):W=t[41];let Oe,Ke;t[42]===Symbol.for("react.memo_cache_sentinel")?(Oe=()=>Le("new"),Ke=s.jsx(L,{name:"add",className:"w-3.5 h-3.5 mr-1"}),t[42]=Oe,t[43]=Ke):(Oe=t[42],Ke=t[43]);let Pe;t[44]!==e?(Pe=e("settings.common.badge.new"),t[44]=e,t[45]=Pe):Pe=t[45],t[46]!==Pe?(Y=s.jsxs(B,{size:"sm",variant:"outline",onClick:Oe,children:[Ke," ",Pe]}),t[46]=Pe,t[47]=Y):Y=t[47],F="git.identities",G="rounded-lg bg-[var(--surface-elevated)]/70 overflow-hidden flex flex-col",S=n&&s.jsx(Lo,{profile:n,isDefault:i==="global",onEdit:()=>Le("global"),onToggleDefault:()=>Ze("global"),isReadOnly:!0,hasBorder:a.length>0||Ve.length>0}),q=a.map((Ue,ve)=>s.jsx(Lo,{profile:Ue,isDefault:i===Ue.id,onEdit:()=>Le(Ue.id),onToggleDefault:()=>Ze(Ue.id),onDelete:()=>E(Ue),hasBorder:ve<a.length-1||Ve.length>0},Ue.id)),Q=!n&&a.length===0&&Ve.length===0&&s.jsxs("div",{className:"py-8 px-4 text-center text-muted-foreground",children:[s.jsx(L,{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")})]}),M=Ve.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")})}),Ve.map((Ue,ve)=>s.jsx(Zg,{credential:Ue,onImport:()=>Le("new",{host:Ue.host,username:Ue.username}),hasBorder:ve<Ve.length-1},`${Ue.host}-${Ue.username}`))]}),t[6]=i,t[7]=g,t[8]=r,t[9]=v,t[10]=n,t[11]=a,t[12]=c,t[13]=e,t[14]=y,t[15]=K,t[16]=C,t[17]=T,t[18]=j,t[19]=R,t[20]=G,t[21]=S,t[22]=q,t[23]=Q,t[24]=M,t[25]=W,t[26]=Y,t[27]=F}else y=t[14],K=t[15],C=t[16],T=t[17],j=t[18],R=t[19],G=t[20],S=t[21],q=t[22],Q=t[23],M=t[24],W=t[25],Y=t[26],F=t[27];let se;t[48]!==G||t[49]!==S||t[50]!==q||t[51]!==Q||t[52]!==M?(se=s.jsxs("div",{className:G,children:[S,q,Q,M]}),t[48]=G,t[49]=S,t[50]=q,t[51]=Q,t[52]=M,t[53]=se):se=t[53];let _;t[54]!==y||t[55]!==se||t[56]!==W||t[57]!==Y||t[58]!==F?(_=s.jsx(y,{title:W,headerAction:Y,settingsItem:F,children:se}),t[54]=y,t[55]=se,t[56]=W,t[57]=Y,t[58]=F,t[59]=_):_=t[59];let V;t[60]===Symbol.for("react.memo_cache_sentinel")?(V=s.jsx(Ul,{}),t[60]=V):V=t[60];let z;t[61]!==K||t[62]!==T||t[63]!==j||t[64]!==R||t[65]!==_?(z=s.jsxs(K,{title:T,showSaveStatus:j,children:[R,_,V]}),t[61]=K,t[62]=T,t[63]=j,t[64]=R,t[65]=_,t[66]=z):z=t[66];let U;t[67]!==N||t[68]!==p||t[69]!==b?(U=s.jsx(Wg,{open:p,onOpenChange:A,profileId:b,importData:N}),t[67]=N,t[68]=p,t[69]=b,t[70]=U):U=t[70];const X=g!==null;let Z;t[71]!==O?(Z=Ve=>{O||Ve||E(null)},t[71]=O,t[72]=Z):Z=t[72];let ne;t[73]!==e?(ne=e("settings.gitIdentities.page.deleteDialog.title"),t[73]=e,t[74]=ne):ne=t[74];let le;t[75]!==ne?(le=s.jsx(qt,{children:ne}),t[75]=ne,t[76]=le):le=t[76];const re=g?.name??"";let fe;t[77]!==e||t[78]!==re?(fe=e("settings.gitIdentities.page.deleteDialog.description",{name:re}),t[77]=e,t[78]=re,t[79]=fe):fe=t[79];let ae;t[80]!==fe?(ae=s.jsx(Wt,{children:fe}),t[80]=fe,t[81]=ae):ae=t[81];let ie;t[82]!==le||t[83]!==ae?(ie=s.jsxs(Gt,{children:[le,ae]}),t[82]=le,t[83]=ae,t[84]=ie):ie=t[84];let te;t[85]===Symbol.for("react.memo_cache_sentinel")?(te=()=>E(null),t[85]=te):te=t[85];let ye;t[86]!==e?(ye=e("settings.common.actions.cancel"),t[86]=e,t[87]=ye):ye=t[87];let we;t[88]!==O||t[89]!==ye?(we=s.jsx(B,{variant:"ghost",onClick:te,disabled:O,children:ye}),t[88]=O,t[89]=ye,t[90]=we):we=t[90];let ke;t[91]!==C?(ke=()=>{C()},t[91]=C,t[92]=ke):ke=t[92];let xe;t[93]!==e?(xe=e("settings.common.actions.delete"),t[93]=e,t[94]=xe):xe=t[94];let De;t[95]!==O||t[96]!==ke||t[97]!==xe?(De=s.jsx(B,{size:"sm",variant:"destructive",onClick:ke,disabled:O,children:xe}),t[95]=O,t[96]=ke,t[97]=xe,t[98]=De):De=t[98];let Me;t[99]!==we||t[100]!==De?(Me=s.jsxs(ms,{children:[we,De]}),t[99]=we,t[100]=De,t[101]=Me):Me=t[101];let he;t[102]!==ie||t[103]!==Me?(he=s.jsxs(_t,{className:"max-w-md",children:[ie,Me]}),t[102]=ie,t[103]=Me,t[104]=he):he=t[104];let ge;t[105]!==X||t[106]!==Z||t[107]!==he?(ge=s.jsx(zt,{open:X,onOpenChange:Z,children:he}),t[105]=X,t[106]=Z,t[107]=he,t[108]=ge):ge=t[108];let Ae;return t[109]!==z||t[110]!==U||t[111]!==ge?(Ae=s.jsxs(s.Fragment,{children:[z,U,ge]}),t[109]=z,t[110]=U,t[111]=ge,t[112]=Ae):Ae=t[112],Ae},Lo=t=>{const e=mt.c(56),{profile:a,isDefault:n,onEdit:i,onToggleDefault:r,onDelete:l,isReadOnly:h,hasBorder:d}=t,{t:x}=ot(),[c,v]=o.useState(!1),p=Jg[a.icon||"branch"]||"git-branch",A=Qg[a.color||""],b=a.authType||"ssh";let P;e[0]!==i?(P=_=>{_.currentTarget===_.target&&(_.key!=="Enter"&&_.key!==" "||(_.preventDefault(),i()))},e[0]=i,e[1]=P):P=e[1];const N=P;let k;e[2]!==n||e[3]!==h||e[4]!==l||e[5]!==r||e[6]!==x?(k=_=>s.jsxs(s.Fragment,{children:[s.jsx(_,{onClick:V=>{V.stopPropagation(),r()},children:x(n?"settings.gitIdentities.page.actions.unsetDefault":"settings.gitIdentities.page.actions.setAsDefault")}),!h&&l&&s.jsxs(_,{onClick:V=>{V.stopPropagation(),l()},className:"text-destructive focus:text-destructive",children:[s.jsx(L,{name:"delete-bin",className:"h-4 w-4 mr-px"}),x("settings.common.actions.delete")]})]}),e[2]=n,e[3]=h,e[4]=l,e[5]=r,e[6]=x,e[7]=k):k=e[7];const g=k,E=d&&"border-b border-[var(--surface-subtle)]";let O;e[8]!==E?(O=je("group flex items-center justify-between gap-3 px-4 py-2.5 transition-colors hover:bg-[var(--interactive-hover)]/30 cursor-pointer",E),e[8]=E,e[9]=O):O=e[9];let I;e[10]===Symbol.for("react.memo_cache_sentinel")?(I=_=>{_.preventDefault(),v(!0)},e[10]=I):I=e[10];let w;e[11]!==N||e[12]!==i||e[13]!==O?(w=s.jsx("div",{className:O,onClick:i,role:"button",tabIndex:0,onKeyDown:N,onContextMenu:I}),e[11]=N,e[12]=i,e[13]=O,e[14]=w):w=e[14];let m;e[15]!==A?(m={color:A},e[15]=A,e[16]=m):m=e[16];let y;e[17]!==p||e[18]!==m?(y=s.jsx(L,{name:p,className:"w-4 h-4 shrink-0",style:m}),e[17]=p,e[18]=m,e[19]=y):y=e[19];let K;e[20]!==a.name?(K=s.jsx("span",{className:"typography-ui-label text-foreground truncate",children:a.name}),e[20]=a.name,e[21]=K):K=e[21];let C;e[22]!==b?(C=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:b}),e[22]=b,e[23]=C):C=e[23];let T;e[24]!==n||e[25]!==x?(T=n&&s.jsx("span",{className:"typography-micro text-primary bg-primary/12 px-1 rounded flex-shrink-0 leading-none pb-px border border-primary/25",children:x("settings.gitIdentities.page.badge.default")}),e[24]=n,e[25]=x,e[26]=T):T=e[26];let j;e[27]!==h||e[28]!==x?(j=h&&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:x("settings.agents.sidebar.badge.system")}),e[27]=h,e[28]=x,e[29]=j):j=e[29];let R;e[30]!==C||e[31]!==T||e[32]!==j||e[33]!==K?(R=s.jsxs("div",{className:"flex items-center gap-1.5",children:[K,C,T,j]}),e[30]=C,e[31]=T,e[32]=j,e[33]=K,e[34]=R):R=e[34];const G=b==="token"&&a.host?a.host:a.userEmail;let S;e[35]!==G?(S=s.jsx("div",{className:"typography-micro text-muted-foreground/60 truncate leading-tight",children:G}),e[35]=G,e[36]=S):S=e[36];let q;e[37]!==R||e[38]!==S?(q=s.jsxs("div",{className:"min-w-0",children:[R,S]}),e[37]=R,e[38]=S,e[39]=q):q=e[39];let Q;e[40]!==q||e[41]!==y?(Q=s.jsxs("div",{className:"flex items-center gap-3 min-w-0",children:[y,q]}),e[40]=q,e[41]=y,e[42]=Q):Q=e[42];let M;e[43]===Symbol.for("react.memo_cache_sentinel")?(M=s.jsx(tn,{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:eh,children:s.jsx(L,{name:"more-2",className:"h-3.5 w-3.5"})})}),e[43]=M):M=e[43];let W;e[44]!==g?(W=s.jsxs(nn,{children:[M,s.jsx(sn,{align:"end",className:"w-fit min-w-28",children:g(an)})]}),e[44]=g,e[45]=W):W=e[45];let Y;e[46]!==Q||e[47]!==W||e[48]!==w?(Y=s.jsxs(Hn,{render:w,children:[Q,W]}),e[46]=Q,e[47]=W,e[48]=w,e[49]=Y):Y=e[49];let F;e[50]!==g?(F=s.jsx(Vn,{className:"w-fit min-w-28",children:g(Bn)}),e[50]=g,e[51]=F):F=e[51];let se;return e[52]!==c||e[53]!==Y||e[54]!==F?(se=s.jsxs(Gn,{open:c,onOpenChange:v,children:[Y,F]}),e[52]=c,e[53]=Y,e[54]=F,e[55]=se):se=e[55],se},Zg=t=>{const e=mt.c(21),{credential:a,onImport:n,hasBorder:i}=t,{t:r}=ot();let l;e[0]!==a.host?(l=a.host.split("/"),e[0]=a.host,e[1]=l):l=e[1];const h=l,d=h.length>=3?h[h.length-1]:a.host,x=a.host.includes("/"),c=i&&"border-b border-[var(--surface-subtle)]";let v;e[2]!==c?(v=je("flex items-center justify-between gap-3 px-4 py-2.5 transition-colors hover:bg-[var(--interactive-hover)]/30",c),e[2]=c,e[3]=v):v=e[3];let p;e[4]!==d?(p=s.jsx("span",{className:"typography-ui-label text-foreground truncate block",children:d}),e[4]=d,e[5]=p):p=e[5];const A=x?a.host:a.username;let b;e[6]!==A?(b=s.jsx("span",{className:"typography-micro text-muted-foreground/60 truncate block leading-tight",children:A}),e[6]=A,e[7]=b):b=e[7];let P;e[8]!==p||e[9]!==b?(P=s.jsxs("div",{className:"min-w-0",children:[p,b]}),e[8]=p,e[9]=b,e[10]=P):P=e[10];let N;e[11]===Symbol.for("react.memo_cache_sentinel")?(N=s.jsx(L,{name:"download",className:"h-3 w-3"}),e[11]=N):N=e[11];let k;e[12]!==r?(k=r("settings.gitIdentities.page.actions.import"),e[12]=r,e[13]=k):k=e[13];let g;e[14]!==n||e[15]!==k?(g=s.jsxs(B,{size:"sm",variant:"ghost",onClick:n,className:"gap-1 shrink-0",children:[N,k]}),e[14]=n,e[15]=k,e[16]=g):g=e[16];let E;return e[17]!==g||e[18]!==v||e[19]!==P?(E=s.jsxs("div",{className:v,children:[P,g]}),e[17]=g,e[18]=v,e[19]=P,e[20]=E):E=e[20],E};function Xg(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 eh(t){return t.stopPropagation()}const _i=[{id:"opencode-claude",packageName:"@openchamber/opencode-claude",providerId:"claude-code",icon:"claude-code",brandClassName:"text-[#D97757]",nameKey:"settings.integrations.thirdParty.opencodeClaude.name",descriptionKey:"settings.integrations.thirdParty.opencodeClaude.description",homepage:"https://github.com/openchamber/opencode-claude"},{id:"opencode-cursor-oauth",packageName:"@openchamber/opencode-cursor",providerId:"cursor",icon:"cursor",brandClassName:"text-foreground",nameKey:"settings.integrations.thirdParty.opencodeCursorOauth.name",descriptionKey:"settings.integrations.thirdParty.opencodeCursorOauth.description",homepage:"https://github.com/openchamber/opencode-cursor"}],th=(t,e)=>t===e||t.startsWith(`${e}@`);function $i(t,e,a){const n=t.filter(d=>th(d.spec,e)),i=n.filter(d=>d.scope==="user"),r=n.filter(d=>d.scope==="project"),l=i.length===1?i[0]:null,h=a[l?.spec??e]??a[e]??null;return{userEntry:l,userEntryIsAmbiguous:i.length>1,projectEntries:r,registry:h}}function rr(t,e){return e?.kind!=="npm-ok"||e.name!==t||!e.latestVersion?null:`${t}@${e.latestVersion}`}function Fo(t,e){if(t.userEntryIsAmbiguous)return"manage";if(!t.userEntry)return"install";const a=rr(e,t.registry);return a&&a!==t.userEntry.spec?"update":"setup"}function sh(t,e={}){const a=t.registry?.kind==="npm-ok"?t.registry.latestVersion:null;return t.userEntryIsAmbiguous?{status:"ambiguous",latestVersion:a}:e.restartRequired?{status:"restart-required",latestVersion:a}:e.providerUnavailable?{status:"provider-unavailable",latestVersion:a}:e.registryUnavailable?{status:"registry-unavailable",latestVersion:a}:t.userEntry?t.registry?.kind==="npm-ok"&&t.registry.currentVersion===t.registry.latestVersion?{status:"installed-version",latestVersion:a}:t.registry?.kind==="npm-ok"&&t.registry.currentVersion===null?{status:"unpinned",latestVersion:a}:t.registry?.kind==="npm-ok"&&a?{status:"update-available",latestVersion:a}:{status:"installed",latestVersion:a}:{status:"not-installed",latestVersion:a}}const nh=t=>t.restartDeferred===!0||t.requiresManualRestart===!0||t.reloadFailed===!0,ah=({divider:t=!0,onOpenProviderSetup:e,onOpenPluginManager:a})=>{const{t:n}=ot(),{entries:i,registryInfo:r,loadPlugins:l,loadRegistryInfo:h,createEntry:d,updateEntry:x,deleteEntry:c}=fs(Ms(M=>({entries:M.entries,registryInfo:M.registryInfo,loadPlugins:M.loadPlugins,loadRegistryInfo:M.loadRegistryInfo,createEntry:M.createEntry,updateEntry:M.updateEntry,deleteEntry:M.deleteEntry}))),[v,p]=o.useState(!1),[A,b]=o.useState(null),[P,N]=o.useState(()=>new Set),[k,g]=o.useState(()=>new Set),[E,O]=o.useState(null),[I,w]=o.useState(()=>new Set),m=o.useCallback(async()=>{if(!await l({force:!0})){p(!0);return}const W=fs.getState().entries,Y=new Set(_i.map(se=>se.packageName));for(const se of W)_i.some(_=>se.spec===_.packageName||se.spec.startsWith(`${_.packageName}@`))&&Y.add(se.spec);const F=await h({specs:[...Y],force:!0});p(!F)},[l,h]);o.useEffect(()=>{m()},[m]);const y=dn(M=>M.changes.filter(W=>W.scope==="plugins").length),K=dn(M=>M.isApplying),C=o.useRef(y);o.useEffect(()=>{const M=C.current;C.current=y,!K&&(M<=0||y>0||(N(new Set),g(new Set),m()))},[K,y,m]);const T=o.useCallback((M,W)=>{N(Y=>{const F=new Set(Y);return W?F.add(M):F.delete(M),F})},[]),j=o.useCallback((M,W)=>{g(Y=>{const F=new Set(Y);return W?F.add(M):F.delete(M),F})},[]),R=o.useCallback(async(M,W,Y)=>{b({pluginId:M.id,action:W});try{const F=await Y();if(!F.ok){D.error(n("settings.integrations.thirdParty.toast.actionFailed"));return}j(M.id,!1);const se=nh(F);T(M.id,se);const _=se?{description:n("settings.integrations.thirdParty.toast.restartRequired")}:void 0;W==="install"?D.success(n("settings.integrations.thirdParty.toast.installed",{name:n(M.nameKey)}),_):W==="update"?D.success(n("settings.integrations.thirdParty.toast.updated",{name:n(M.nameKey)}),_):D.success(n("settings.integrations.thirdParty.toast.removed",{name:n(M.nameKey)}),_),await m()}finally{b(null)}},[m,j,T,n]),G=o.useCallback(async M=>{const W=$i(i,M.packageName,r),Y=Fo(W,M.packageName);if(Y==="manage"){a();return}if(Y==="setup"){b({pluginId:M.id,action:Y});try{const se=await e(M.providerId);j(M.id,!se),se||D.error(n("settings.integrations.thirdParty.toast.providerUnavailable"))}finally{b(null)}return}const F=rr(M.packageName,W.registry);if(!F){p(!0);return}if(Y==="install"){await R(M,"install",()=>d({spec:F,scope:"user"}));return}W.userEntry&&await R(M,"update",()=>x(W.userEntry.id,{spec:F}))},[d,i,a,e,r,R,j,n,x]),S=o.useCallback(async()=>{const M=E;if(!M)return;const W=$i(i,M.packageName,r);if(!W.userEntry||W.userEntryIsAmbiguous){O(null),a();return}O(null),await R(M,"remove",()=>c(W.userEntry.id))},[c,i,a,r,E,R]),q=o.useCallback((M,W)=>{w(Y=>{const F=new Set(Y);return W?F.add(M):F.delete(M),F})},[]),Q=M=>{const W=$i(i,M.packageName,r),Y=Fo(W,M.packageName),F=rr(M.packageName,W.registry),se=A?.pluginId===M.id,_=P.has(M.id),V=k.has(M.id),z=v||W.registry?.kind==="npm-network",U=se||_||(Y==="install"||Y==="update")&&(z||!F),X=sh(W,{registryUnavailable:z,restartRequired:_,providerUnavailable:V});let Z;switch(X.status){case"installed-version":Z=X.latestVersion?n("settings.integrations.thirdParty.status.installedVersion",{version:X.latestVersion}):n("settings.integrations.thirdParty.status.installed");break;case"update-available":Z=X.latestVersion?n("settings.integrations.thirdParty.status.updateAvailable",{version:X.latestVersion}):n("settings.integrations.thirdParty.status.unpinned");break;case"not-installed":Z=n("settings.integrations.thirdParty.status.notInstalled");break;case"installed":Z=n("settings.integrations.thirdParty.status.installed");break;case"unpinned":Z=n("settings.integrations.thirdParty.status.unpinned");break;case"ambiguous":Z=n("settings.integrations.thirdParty.status.ambiguous");break;case"restart-required":Z=n("settings.integrations.thirdParty.status.restartRequired");break;case"registry-unavailable":Z=n("settings.integrations.thirdParty.status.registryUnavailable");break;case"provider-unavailable":Z=n("settings.integrations.thirdParty.status.providerUnavailable");break}const ne=X.status==="installed-version"?"bg-[var(--status-success)]/15 text-[var(--status-success)]":X.status==="update-available"||X.status==="ambiguous"||X.status==="restart-required"||X.status==="registry-unavailable"||X.status==="provider-unavailable"?"bg-[var(--status-warning)]/15 text-[var(--status-warning)]":"bg-[var(--surface-muted)] text-muted-foreground",le={install:n("settings.integrations.thirdParty.actions.install"),update:n("settings.integrations.thirdParty.actions.update"),setup:n("settings.integrations.thirdParty.actions.setup"),manage:n("settings.integrations.thirdParty.actions.managePlugins")}[Y],re=I.has(M.id);return s.jsx(qn,{open:re,onOpenChange:fe=>q(M.id,fe),children:s.jsxs("div",{"data-settings-item":`integrations.third-party.${M.id}`,className:"overflow-hidden rounded-xl border border-[var(--interactive-border)] bg-[var(--surface-elevated)]",children:[s.jsxs(Wn,{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(L,{name:M.icon,className:je("size-5",M.brandClassName)})}),s.jsxs("div",{className:"min-w-0 flex-1",children:[s.jsx("div",{className:"truncate text-sm font-semibold text-foreground",children:n(M.nameKey)}),s.jsx("p",{className:"mt-0.5 line-clamp-1 text-xs leading-snug text-muted-foreground",children:n(M.descriptionKey)})]}),s.jsx("span",{"aria-live":"polite",className:je("max-w-36 shrink-0 truncate rounded-full px-2 py-0.5 text-[10px] font-medium",ne),children:Z}),s.jsx(L,{name:"arrow-down-s",className:je("size-4 shrink-0 text-muted-foreground transition-transform duration-150 ease-out motion-reduce:transition-none",re&&"rotate-180")})]}),s.jsx(Jn,{className:"border-t border-[var(--interactive-border)] px-4 py-4",children:s.jsxs("div",{className:"space-y-3",children:[W.projectEntries.length>0?s.jsx("p",{className:"text-xs text-muted-foreground",children:n("settings.integrations.thirdParty.status.projectInstalled")}):null,s.jsxs("div",{className:"flex flex-wrap items-center gap-2",children:[s.jsxs(B,{type:"button",size:"sm",variant:Y==="manage"?"outline":"default",onClick:()=>{G(M)},disabled:U,children:[se?s.jsx(L,{name:"loader-4",className:"size-3.5 animate-spin"}):Y==="setup"?s.jsx(L,{name:"plug-2",className:"size-3.5"}):null,le]}),s.jsxs(B,{type:"button",size:"sm",variant:"secondary",onClick:()=>{An(M.homepage)},children:[s.jsx(L,{name:"external-link",className:"size-3.5"}),n("settings.integrations.thirdParty.actions.docs")]}),W.userEntry&&!W.userEntryIsAmbiguous?s.jsxs(B,{type:"button",size:"sm",variant:"destructive",onClick:()=>O(M),disabled:se,children:[s.jsx(L,{name:"delete-bin",className:"size-3.5"}),n("settings.integrations.thirdParty.actions.remove")]}):null]})]})})]})},M.id)};return s.jsxs(s.Fragment,{children:[s.jsx(Be,{title:n("settings.integrations.thirdParty.title"),info:n("settings.integrations.thirdParty.info"),divider:t,settingsItem:"integrations.third-party",contentClassName:"space-y-3",children:_i.map(Q)}),s.jsx(zt,{open:E!==null,onOpenChange:M=>!M&&O(null),children:s.jsxs(_t,{className:"max-w-md",children:[s.jsxs(Gt,{children:[s.jsx(qt,{children:n("settings.integrations.thirdParty.dialog.remove.title")}),s.jsx(Wt,{children:n("settings.integrations.thirdParty.dialog.remove.description",{name:E?n(E.nameKey):""})})]}),s.jsxs(ms,{children:[s.jsx(B,{type:"button",size:"sm",variant:"ghost",onClick:()=>O(null),children:n("settings.common.actions.cancel")}),s.jsx(B,{type:"button",size:"sm",variant:"destructive",onClick:()=>{S()},children:n("settings.integrations.thirdParty.actions.remove")})]})]})})]})},ih=t=>{const e=mt.c(21),{onOpenProviderSetup:a,onOpenPluginManager:n}=t,{t:i}=ot();let r;e[0]!==i?(r=i("settings.page.integrations.title"),e[0]=i,e[1]=r):r=e[1];let l;e[2]!==i?(l=i("settings.page.integrations.description"),e[2]=i,e[3]=l):l=e[3];let h;e[4]!==l?(h=s.jsx("p",{className:nl,children:l}),e[4]=l,e[5]=h):h=e[5];let d;e[6]===Symbol.for("react.memo_cache_sentinel")?(d=s.jsx(L,{name:"error-warning",className:"mt-0.5 size-4 shrink-0 text-[var(--status-warning)]"}),e[6]=d):d=e[6];let x;e[7]!==i?(x=i("settings.integrations.experimentalWarning"),e[7]=i,e[8]=x):x=e[8];let c;e[9]!==x?(c=s.jsxs("div",{role:"alert",className:"flex items-start gap-2 rounded-lg border border-[var(--status-warning-border)] bg-[var(--status-warning-background)] p-3",children:[d,s.jsx("p",{className:"typography-meta text-[var(--status-warning)]",children:x})]}),e[9]=x,e[10]=c):c=e[10];let v;e[11]!==h||e[12]!==c?(v=s.jsxs("div",{className:"space-y-3",children:[h,c]}),e[11]=h,e[12]=c,e[13]=v):v=e[13];let p;e[14]!==n||e[15]!==a?(p=s.jsx(ah,{divider:!1,onOpenProviderSetup:a,onOpenPluginManager:n}),e[14]=n,e[15]=a,e[16]=p):p=e[16];let A;return e[17]!==r||e[18]!==v||e[19]!==p?(A=s.jsx(gs,{title:r,description:v,showSaveStatus:!1,children:p}),e[17]=r,e[18]=v,e[19]=p,e[20]=A):A=e[20],A},rh=[{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"}],oh=[{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"}],lh=[{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"}],Sa="OpenChamber - AI Coding Assistant",Ko=[{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"}],Uo=[{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"}],Vi=t=>t==="portrait"||t==="landscape"?t:"system",ch=[{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"}],zo=[{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"}],ph=[{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"}],_o=[{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"}],$o=[{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"}],mh=[{id:"steer",labelKey:"settings.openchamber.visual.option.followUpBehavior.steer.label"},{id:"queue",labelKey:"settings.openchamber.visual.option.followUpBehavior.queue.label"}],uh=t=>t==="markdown"?"markdown":"plain",gh=[{id:"left",labelKey:"settings.openchamber.desktopNetwork.option.windowControlsLeft"},{id:"right",labelKey:"settings.openchamber.desktopNetwork.option.windowControlsRight"}],hh=[{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:i,t:r}=ot(),l=o.useCallback(u=>r(u),[r]),{isMobile:h}=da(),{terminal:d}=dl(),{browserTab:x}=Ed(),c=hd(),v=ce(u=>u.showReasoningTraces),p=ce(u=>u.sessionRecapEnabled),A=ce(u=>u.sessionSuggestionEnabled),b=ce(u=>u.setSessionRecapEnabled),P=ce(u=>u.setSessionSuggestionEnabled),N=ce(u=>u.sessionGoalEnabled),k=ce(u=>u.setSessionGoalEnabled),g=ce(u=>u.sessionGoalDefaultBudgetEnabled),E=ce(u=>u.setSessionGoalDefaultBudgetEnabled),O=ce(u=>u.sessionGoalDefaultBudget),I=ce(u=>u.setSessionGoalDefaultBudget),w=ce(u=>u.setShowReasoningTraces),m=ce(u=>u.streamingAutoFollowEnabled),y=ce(u=>u.setStreamingAutoFollowEnabled),K=ce(u=>u.collapsibleThinkingBlocks),C=ce(u=>u.setCollapsibleThinkingBlocks),T=ce(u=>u.mermaidRenderingMode),j=ce(u=>u.setMermaidRenderingMode),R=ce(u=>u.userMessageRenderingMode),G=ce(u=>u.setUserMessageRenderingMode),S=ce(u=>u.collapsibleUserMessages),q=ce(u=>u.setCollapsibleUserMessages),Q=ce(u=>u.stickyUserHeader),M=ce(u=>u.promptNavigatorEnabled),W=ce(u=>u.setStickyUserHeader),Y=ce(u=>u.setPromptNavigatorEnabled),F=ce(u=>u.autoSaveEnabled),se=ce(u=>u.setAutoSaveEnabled),_=ce(u=>u.wideChatLayoutEnabled),V=ce(u=>u.setWideChatLayoutEnabled),z=ce(u=>u.codeBlockLineWrap),U=ce(u=>u.setCodeBlockLineWrap),X=ce(u=>u.chatRenderMode),Z=ce(u=>u.setChatRenderMode),ne=ce(u=>u.activityRenderMode),le=ce(u=>u.setActivityRenderMode),re=ce(u=>u.fontSize),fe=ce(u=>u.setFontSize),ae=ce(u=>u.terminalFontSize),ie=ce(u=>u.setTerminalFontSize),te=ce(u=>u.terminalShell),ye=ce(u=>u.setTerminalShell),we=ce(u=>u.terminalLoginShells),ke=ce(u=>u.setTerminalLoginShells),xe=ce(u=>u.editorFontSize),De=ce(u=>u.setEditorFontSize),Me=ce(u=>u.uiFont),he=ce(u=>u.setUiFont),ge=ce(u=>u.monoFont),Ae=ce(u=>u.setMonoFont),Ve=ce(u=>u.padding),_e=ce(u=>u.setPadding),Le=ce(u=>u.inputBarOffset),Re=ce(u=>u.setInputBarOffset),Ze=ce(u=>u.mobileKeyboardMode),Ge=ce(u=>u.setMobileKeyboardMode),Oe=ce(u=>u.diffLayoutPreference),Ke=ce(u=>u.setDiffLayoutPreference),Pe=ce(u=>u.showTerminalQuickKeysOnDesktop),Ue=ce(u=>u.sessionTabsEnabled),ve=ce(u=>u.setSessionTabsEnabled),We=ce(u=>u.setShowTerminalQuickKeysOnDesktop),$=ce(u=>u.fileEditorKeymap),de=ce(u=>u.setFileEditorKeymap),ue=Ur(u=>u.followUpBehavior),Ne=Ur(u=>u.setFollowUpBehavior),pe=ce(u=>u.persistChatDraft),Fe=ce(u=>u.setPersistChatDraft),H=ce(u=>u.inputSpellcheckEnabled),He=ce(u=>u.setInputSpellcheckEnabled),et=ce(u=>u.showToolFileIcons),ze=ce(u=>u.setShowToolFileIcons),st=ce(u=>u.showTurnChangedFiles),wt=ce(u=>u.setShowTurnChangedFiles),xt=ce(u=>u.showExpandedBashTools),gt=ce(u=>u.setShowExpandedBashTools),bt=ce(u=>u.showExpandedEditTools),St=ce(u=>u.setShowExpandedEditTools),yt=ce(u=>u.timeFormatPreference),It=ce(u=>u.setTimeFormatPreference),qe=ce(u=>u.weekStartPreference),Qe=ce(u=>u.setWeekStartPreference),dt=ce(u=>u.showSplitAssistantMessageActions),Ee=ce(u=>u.setShowSplitAssistantMessageActions),vt=ce(u=>u.allowPromptingSubagentSessions),Se=ce(u=>u.setAllowPromptingSubagentSessions),kt=ce(u=>u.draftStartersVisible),J=ce(u=>u.setDraftStartersVisible),me=tt(u=>u.settingsMessageStreamTransport),Te=tt(u=>u.setSettingsMessageStreamTransport),Ie=me,lt=tt(u=>u.settingsDefaultFileViewerPreview),at=tt(u=>u.setSettingsDefaultFileViewerPreview),Je=ce(u=>u.isSettingsDialogOpen),{themeMode:Ct,setThemeMode:rs,availableThemes:Yt,customThemesLoading:ys,reloadCustomThemes:$t,lightThemeId:cs,darkThemeId:Kt,setLightThemePreference:ds,setDarkThemePreference:as}=gr(),[ns,Zt]=o.useState(!1),os=o.useMemo(()=>bs()&&typeof window<"u"&&window.__OPENCHAMBER_PLATFORM__==="darwin",[]),oe=ce(u=>u.dockBadgeEnabled),ct=ce(u=>u.setDockBadgeEnabled),Ce=fd(),it=ce(u=>u.desktopWindowControlsPosition),jt=ce(u=>u.setDesktopWindowControlsPosition),At=ce(u=>u.desktopWindowControlsStyle),Tt=ce(u=>u.setDesktopWindowControlsStyle),[Xt,ls]=o.useState(0),ft=ce(u=>u.reportUsage),Pt=ce(u=>u.setReportUsage),Dt=o.useCallback(u=>{Pt(u),Nt({reportUsage:u})},[Pt]),Mt=o.useCallback(u=>{jt(u),Nt({desktopWindowControlsPosition:u})},[jt]),Ut=o.useCallback(u=>{Tt(u),Nt({desktopWindowControlsStyle:u})},[Tt]),js=(Je||h||vs())&&(t?t.includes("chatRenderMode"):!0);o.useEffect(()=>{if(!js)return;let u=null,rt=Date.now();const ts=()=>{const Ts=Date.now();Ts-rt>=420&&(ls(Ws=>(Ws+1)%24),rt=Ts),u=requestAnimationFrame(ts)};(typeof document>"u"||document.visibilityState==="visible")&&(u=requestAnimationFrame(ts));const ps=()=>{document.visibilityState==="visible"&&u===null?u=requestAnimationFrame(ts):document.visibilityState!=="visible"&&u!==null&&(cancelAnimationFrame(u),u=null)};return document.addEventListener("visibilitychange",ps),()=>{document.removeEventListener("visibilitychange",ps),u!==null&&cancelAnimationFrame(u)}},[js]);const Yn=o.useCallback(u=>{G(u),Nt({userMessageRenderingMode:u})},[G]),mi=o.useCallback(u=>{W(u),Nt({stickyUserHeader:u})},[W]),ui=o.useCallback(u=>{Y(u),Nt({promptNavigatorEnabled:u})},[Y]),gi=o.useCallback(u=>{J(u),Nt({draftStartersVisible:u})},[J]),Os=o.useCallback(u=>{q(u),Nt({collapsibleUserMessages:u})},[q]),pa=o.useCallback(u=>{V(u),Nt({wideChatLayoutEnabled:u})},[V]),hi=o.useCallback(u=>{Ee(u),Nt({showSplitAssistantMessageActions:u})},[Ee]),Ua=o.useCallback(u=>{He(u),Nt({inputSpellcheckEnabled:u})},[He]),fi=o.useCallback(u=>{Z(u),Nt({chatRenderMode:u})},[Z]),xi=o.useCallback(u=>{Te(u),Nt({messageStreamTransport:u})},[Te]),bi=o.useCallback(u=>{le(u),Nt({activityRenderMode:u})},[le]),vi=o.useCallback(u=>{j(u),Nt({mermaidRenderingMode:u})},[j]),yi=o.useCallback(u=>{ze(u),Nt({showToolFileIcons:u})},[ze]),Ss=o.useCallback(u=>{wt(u),Nt({showTurnChangedFiles:u})},[wt]),Bs=o.useCallback(u=>{at(u),Nt({defaultFileViewerPreview:u}),window.dispatchEvent(new CustomEvent("openchamber:file-viewer-preview-mode-changed",{detail:{enabled:u}}))},[at]),Zn=o.useCallback(u=>{gt(u),Nt({showExpandedBashTools:u})},[gt]),on=o.useCallback(u=>{St(u),Nt({showExpandedEditTools:u})},[St]),pn=o.useCallback(u=>{It(u),Nt({timeFormatPreference:u})},[It]),Nr=o.useCallback(u=>{Qe(u),Nt({weekStartPreference:u})},[Qe]),Ls=o.useMemo(()=>Yt.filter(u=>u.metadata.variant==="light").sort((u,rt)=>u.metadata.name.localeCompare(rt.metadata.name)),[Yt]),Xn=o.useMemo(()=>Yt.filter(u=>u.metadata.variant==="dark").sort((u,rt)=>u.metadata.name.localeCompare(rt.metadata.name)),[Yt]),mn=o.useMemo(()=>Ls.find(u=>u.metadata.id===cs)??Ls[0],[Ls,cs]),un=o.useMemo(()=>Xn.find(u=>u.metadata.id===Kt)??Xn[0],[Xn,Kt]),Ys=o.useCallback((u,rt)=>{const ts=rt==="dark"?" Dark":" Light";return u.endsWith(ts)?u.slice(0,-ts.length):u},[]),be=u=>t?t.includes(u):!0,xs=vs(),hs=be("theme")&&!xs,za=be("windowControlsPosition")&&Ce,En=be("theme")||be("timeFormat")||be("weekStart"),Tn=xs?En:be("theme")||za||be("pwaInstallName")||be("pwaOrientation")||be("timeFormat")||be("weekStart"),_a=be("fontSize")||be("terminalFontSize")||be("editorFontSize")||be("spacing")||be("inputBarOffset")&&h,ma=be("terminalQuickKeys")&&!h||(be("terminalShell")||be("terminalLoginShell"))&&!xs||be("fileEditorKeymap")||be("autoSaveEnabled")||be("sessionTabs")&&!xs&&!h,ji=be("mermaidRendering")||be("sessionGoal")&&!xs||be("userMessageRendering")||be("chatRenderMode")||be("messageTransport")||be("activityRenderMode")&&X==="sorted"||be("collapsibleUserMessages")||be("stickyUserHeader")||be("promptNavigatorEnabled")&&!xs||be("wideChatLayout")||be("codeBlockLineWrap")||be("splitAssistantMessageActions")||be("subagentReadOnlyBanner")||be("diffLayout")||be("dotfiles")||be("fileViewerPreview")||be("reasoning")||be("followUpBehavior")||be("persistDraft")||be("showToolFileIcons")||be("expandedTools")||!h&&be("inputSpellcheck"),Dn=be("chatRenderMode")||be("activityRenderMode")&&X==="sorted",gn=be("messageTransport"),Mn=be("userMessageRendering")||be("mermaidRendering")||be("diffLayout")&&!xs||be("followUpBehavior"),$a=be("sessionAssist")||be("sessionGoal")&&!xs||be("subagentReadOnlyBanner")||be("collapsibleUserMessages")||be("stickyUserHeader")||be("promptNavigatorEnabled")&&!xs||be("wideChatLayout")||be("codeBlockLineWrap")||be("splitAssistantMessageActions")||be("dotfiles")||be("fileViewerPreview")||be("persistDraft")||be("showToolFileIcons")||be("showTurnChangedFiles")||!h&&be("inputSpellcheck")||be("reasoning")||be("expandedTools"),ea=Tn||_a||ma,Hs=be("pwaInstallName")&&zn()&&x&&!bs()&&!xs,hn=be("pwaOrientation")&&zn()&&!bs()&&!xs,Gs=be("mobileKeyboardMode")&&zn()&&!bs()&&!xs&&xd(),ta=(be("terminalShell")||be("terminalLoginShell"))&&!xs,[ua,ga]=o.useState([]),[wi,ki]=o.useState(0);o.useEffect(()=>bl(()=>{ga([]),ki(u=>u+1)}),[]),o.useEffect(()=>{let u=!1;if(!(!ta||!d.listShells))return d.listShells().then(rt=>{u||ga(rt)}).catch(()=>{u||ga([])}),()=>{u=!0}},[ta,d,wi]);const Ni=o.useMemo(()=>{const u=ua.filter(rt=>rt.id!=="auto");return te==="auto"||u.some(rt=>rt.id===te)?u:[{id:te,name:te,supportsLogin:!1},...u]},[ua,te]),Si=ua.find(u=>u.id===te)?.supportsLogin===!0,Ci=we.includes(te),Rn=u=>{ke(u?[...we.filter(rt=>rt!==te),te]:we.filter(rt=>rt!==te))},[fn,qs]=o.useState(""),[sa,f]=o.useState("system"),ee=o.useMemo(()=>{const u=_o.find(rt=>rt.id===yt);return l(u?.labelKey??"settings.openchamber.visual.option.timeFormat.auto.label")},[yt,l]),$e=o.useMemo(()=>{const u=$o.find(rt=>rt.id===qe);return l(u?.labelKey??"settings.openchamber.visual.option.weekStart.auto.label")},[qe,l]),nt=o.useMemo(()=>{const u=Ko.find(rt=>rt.id===sa);return u?l(u.labelKey):void 0},[sa,l]),Vt=o.useMemo(()=>{const u=Uo.find(rt=>rt.id===Ze);return u?l(u.labelKey):void 0},[Ze,l]),Cs=o.useCallback(async u=>{if(typeof window>"u")return;const rt=window,ps=u.trim().replace(/\s+/g," ").slice(0,64);if(await Nt({pwaAppName:ps}),typeof rt.__OPENCHAMBER_SET_PWA_INSTALL_NAME__=="function"){const Ts=rt.__OPENCHAMBER_SET_PWA_INSTALL_NAME__(ps);qs(Ts);return}qs(ps||Sa),rt.__OPENCHAMBER_UPDATE_PWA_MANIFEST__?.()},[]),ws=o.useCallback(async u=>{if(typeof window>"u")return;const rt=window,ts=Vi(u);if(await Nt({pwaOrientation:ts}),typeof rt.__OPENCHAMBER_SET_PWA_ORIENTATION__=="function"){const ps=rt.__OPENCHAMBER_SET_PWA_ORIENTATION__(ts);f(ps);return}f(ts),rt.__OPENCHAMBER_UPDATE_PWA_MANIFEST__?.()},[]);return o.useEffect(()=>{if(typeof window>"u"||!Hs&&!hn&&!Gs)return;let u=!1;return(async()=>{try{const ts=await pt("/api/config/settings",{method:"GET",headers:{Accept:"application/json"},cache:"no-store"});if(!ts.ok){u||qs(Sa);return}const ps=await ts.json().catch(()=>({})),Ws=(typeof ps?.pwaAppName=="string"?ps.pwaAppName:"").trim().replace(/\s+/g," ").slice(0,64),Et=Vi(ps?.pwaOrientation),is=Br(ps?.mobileKeyboardMode);u||(Hs&&qs(Ws||Sa),hn&&f(Et),Gs&&Ge(is))}catch{u||(Hs&&qs(Sa),hn&&f("system"),Gs&&Ge("native"))}})(),()=>{u=!0}},[Ge,Gs,Hs,hn]),s.jsxs("div",{className:"space-y-0",children:[Tn&&s.jsxs("div",{className:"space-y-0",children:[hs&&s.jsxs(Be,{title:r("settings.openchamber.visual.section.colorModeAndTheme"),divider:!1,children:[s.jsxs(Nn,{children:[s.jsx("div",{className:Sn,children:s.jsx(wn,{"aria-label":r("settings.openchamber.visual.section.colorMode"),children:rh.map(u=>s.jsx(kn,{selected:Ct===u.value,onSelect:()=>rs(u.value),label:l(u.labelKey),ariaLabel:l(u.labelKey)},u.value))})}),s.jsxs("div",{className:Sn,children:[s.jsx(es,{label:r("settings.openchamber.visual.field.lightTheme"),settingsItem:"appearance.light-theme",children:s.jsxs(Ot,{value:mn?.metadata.id??"",onValueChange:ds,children:[s.jsx(Lt,{"aria-label":r("settings.openchamber.visual.field.selectLightThemeAria"),size:Jt,className:xn,children:s.jsx(Ht,{placeholder:r("settings.openchamber.visual.field.selectThemePlaceholder"),children:mn?Ys(mn.metadata.name,"light"):void 0})}),s.jsx(Ft,{children:Ls.map(u=>s.jsx(ut,{value:u.metadata.id,children:Ys(u.metadata.name,"light")},u.metadata.id))})]})}),s.jsx(es,{label:r("settings.openchamber.visual.field.darkTheme"),settingsItem:"appearance.dark-theme",children:s.jsxs(Ot,{value:un?.metadata.id??"",onValueChange:as,children:[s.jsx(Lt,{"aria-label":r("settings.openchamber.visual.field.selectDarkThemeAria"),size:Jt,className:xn,children:s.jsx(Ht,{placeholder:r("settings.openchamber.visual.field.selectThemePlaceholder"),children:un?Ys(un.metadata.name,"dark"):void 0})}),s.jsx(Ft,{children:Xn.map(u=>s.jsx(ut,{value:u.metadata.id,children:Ys(u.metadata.name,"dark")},u.metadata.id))})]})}),s.jsxs("div",{className:"flex items-center gap-2 pt-1",children:[s.jsxs("button",{type:"button",disabled:ys||ns,onClick:()=>{const u=Date.now();Zt(!0),$t().finally(()=>{const rt=Date.now()-u;if(rt<500){window.setTimeout(()=>{Zt(!1)},500-rt);return}Zt(!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(L,{name:"restart",className:je("h-3.5 w-3.5",ns&&"animate-spin")}),r(ns?"settings.openchamber.visual.actions.reloadingThemes":"settings.openchamber.visual.actions.reloadThemes")]}),s.jsx(ss,{children:r("settings.openchamber.visual.field.themeImportInfoTooltip")})]})]})]}),os&&s.jsx(Oa,{settingsItem:"appearance.dock-badge",children:s.jsx(ht,{checked:oe,onChange:ct,label:r("settings.openchamber.visual.field.dockBadge"),info:r("settings.openchamber.visual.field.dockBadgeHint"),ariaLabel:r("settings.openchamber.visual.field.dockBadge")})})]}),za&&s.jsx(Be,{title:r("settings.openchamber.desktopNetwork.field.windowControls"),info:r("settings.openchamber.desktopNetwork.field.windowControlsPositionDescription"),divider:hs,children:s.jsxs(Nn,{children:[s.jsx(es,{label:r("settings.openchamber.desktopNetwork.field.windowControlsPosition"),settingsItem:"sessions.desktop-window-controls-position",children:s.jsx(Js,{value:it,options:gh.map(u=>({value:u.id,label:l(u.labelKey)})),onChange:Mt,"aria-label":r("settings.openchamber.desktopNetwork.field.windowControlsPositionAria")})}),s.jsx(es,{label:r("settings.openchamber.desktopNetwork.field.windowControlsStyle"),settingsItem:"sessions.desktop-window-controls-style",children:s.jsx(Js,{value:At,options:hh.map(u=>({value:u.id,label:l(u.labelKey)})),onChange:Ut,"aria-label":r("settings.openchamber.desktopNetwork.field.windowControlsStyleAria")})})]})}),En&&s.jsx(Be,{title:r("settings.openchamber.visual.section.localization"),children:s.jsxs(Nn,{children:[s.jsx(es,{label:r("settings.appearance.language.label"),info:r("settings.appearance.language.description"),settingsItem:"appearance.language",children:s.jsxs(Ot,{value:e,onValueChange:u=>n(u),children:[s.jsx(Lt,{"aria-label":r("settings.appearance.language.select"),size:Jt,className:xn,children:s.jsx(Ht,{children:i(e)})}),s.jsx(Ft,{children:a.map(u=>s.jsx(ut,{value:u,children:i(u)},u))})]})}),(be("timeFormat")||be("weekStart"))&&s.jsxs("div",{className:Sn,children:[be("timeFormat")&&s.jsx(es,{label:r("settings.openchamber.visual.field.timeFormat"),settingsItem:"appearance.time-format",children:s.jsxs(Ot,{value:yt,onValueChange:u=>pn(u),children:[s.jsx(Lt,{"aria-label":r("settings.openchamber.visual.field.selectTimeFormatAria"),size:Jt,className:xn,children:s.jsx(Ht,{children:ee})}),s.jsx(Ft,{children:_o.map(u=>s.jsx(ut,{value:u.id,children:l(u.labelKey)},u.id))})]})}),be("weekStart")&&s.jsx(es,{label:r("settings.openchamber.visual.field.weekStartsOn"),settingsItem:"appearance.week-start",children:s.jsxs(Ot,{value:qe,onValueChange:u=>Nr(u),children:[s.jsx(Lt,{"aria-label":r("settings.openchamber.visual.field.selectWeekStartAria"),size:Jt,className:xn,children:s.jsx(Ht,{children:$e})}),s.jsx(Ft,{children:$o.map(u=>s.jsx(ut,{value:u.id,children:l(u.labelKey)},u.id))})]})})]})]})}),(Hs||hn||Gs)&&s.jsxs(Be,{title:r("settings.openchamber.visual.section.appInstall"),contentClassName:Sn,children:[Hs&&s.jsxs(Qt,{label:r("settings.openchamber.visual.field.installAppName"),info:r("settings.openchamber.visual.field.installAppNameHint"),settingsItem:"appearance.pwa-install-name",alignEnd:!1,controlClassName:Ks,children:[s.jsx(Ye,{value:fn,onChange:u=>{qs(u.target.value)},onBlur:()=>{Cs(fn)},onKeyDown:u=>{u.key==="Enter"&&(u.preventDefault(),Cs(fn))},className:"min-w-0 flex-1",maxLength:64,"aria-label":r("settings.openchamber.visual.field.pwaInstallAppNameAria")}),s.jsx(B,{size:"sm",type:"button",variant:"ghost",onClick:()=>{qs(Sa),Cs("")},className:ks,"aria-label":r("settings.openchamber.visual.actions.resetInstallAppNameAria"),title:r("settings.common.actions.reset"),children:s.jsx(L,{name:"restart",className:"h-3.5 w-3.5"})})]}),hn&&s.jsxs(Qt,{label:r("settings.openchamber.visual.field.installOrientation"),description:r("settings.openchamber.visual.field.installOrientationHint"),settingsItem:"appearance.pwa-orientation",alignEnd:!1,controlClassName:Ks,children:[s.jsxs(Ot,{value:sa,onValueChange:u=>{const rt=Vi(u);f(rt),ws(rt)},children:[s.jsx(Lt,{"aria-label":r("settings.openchamber.visual.field.pwaInstallOrientationAria"),size:Jt,className:Er,children:s.jsx(Ht,{placeholder:r("settings.openchamber.visual.field.selectOrientationPlaceholder"),children:nt})}),s.jsx(Ft,{children:Ko.map(u=>s.jsx(ut,{value:u.id,children:l(u.labelKey)},u.id))})]}),s.jsx(B,{size:"sm",type:"button",variant:"ghost",onClick:()=>{f("system"),ws("system")},disabled:sa==="system",className:ks,"aria-label":r("settings.openchamber.visual.actions.resetInstallOrientationAria"),title:r("settings.common.actions.reset"),children:s.jsx(L,{name:"restart",className:"h-3.5 w-3.5"})})]}),Gs&&s.jsxs(Qt,{label:r("settings.openchamber.visual.field.mobileKeyboardMode"),info:r("settings.openchamber.visual.field.mobileKeyboardModeHint"),settingsItem:"appearance.mobile-keyboard-mode",alignEnd:!1,controlClassName:Ks,children:[s.jsxs(Ot,{value:Ze,onValueChange:u=>{const rt=Br(u);Ge(rt),Nt({mobileKeyboardMode:rt})},children:[s.jsx(Lt,{"aria-label":r("settings.openchamber.visual.field.mobileKeyboardModeAria"),size:Jt,className:Er,children:s.jsx(Ht,{placeholder:r("settings.openchamber.visual.field.selectMobileKeyboardModePlaceholder"),children:Vt})}),s.jsx(Ft,{children:Uo.map(u=>s.jsx(ut,{value:u.id,children:l(u.labelKey)},u.id))})]}),s.jsx(B,{size:"sm",type:"button",variant:"ghost",onClick:()=>{Ge("native"),Nt({mobileKeyboardMode:"native"})},disabled:Ze==="native",className:ks,"aria-label":r("settings.openchamber.visual.actions.resetMobileKeyboardModeAria"),title:r("settings.common.actions.reset"),children:s.jsx(L,{name:"restart",className:"h-3.5 w-3.5"})})]})]})]}),_a&&s.jsxs(Be,{title:r("settings.openchamber.visual.section.densityAndType"),contentClassName:Sn,children:[be("fontSize")&&!h||be("terminalFontSize")?s.jsxs(Nn,{children:[be("fontSize")&&!h&&s.jsxs(es,{label:r("settings.openchamber.visual.field.interfaceFont"),settingsItem:"appearance.interface-font-size",controlClassName:"w-full",children:[s.jsxs(Ot,{value:Me,onValueChange:u=>he(u),children:[s.jsx(Lt,{"aria-label":r("settings.openchamber.visual.field.selectInterfaceFontAria"),size:Jt,className:xn,children:s.jsx(Ht,{children:zr.find(u=>u.id===Me)?.label})}),s.jsx(Ft,{children:zr.map(u=>s.jsx(ut,{value:u.id,children:s.jsx("span",{style:{fontFamily:u.stack},children:u.label})},u.id))})]}),s.jsx(B,{size:"sm",type:"button",variant:"ghost",onClick:()=>he(_r),disabled:Me===_r,className:ks,"aria-label":r("settings.openchamber.visual.actions.resetInterfaceFontAria"),title:r("settings.common.actions.reset"),children:s.jsx(L,{name:"restart",className:"h-3.5 w-3.5"})})]}),be("terminalFontSize")&&s.jsxs(es,{label:r("settings.openchamber.visual.field.codeFont"),controlClassName:"w-full",children:[s.jsxs(Ot,{value:ge,onValueChange:u=>Ae(u),children:[s.jsx(Lt,{"aria-label":r("settings.openchamber.visual.field.selectCodeFontAria"),size:Jt,className:xn,children:s.jsx(Ht,{children:$r.find(u=>u.id===ge)?.label})}),s.jsx(Ft,{children:$r.map(u=>s.jsx(ut,{value:u.id,children:s.jsx("span",{style:{fontFamily:u.stack},children:u.label})},u.id))})]}),s.jsx(B,{size:"sm",type:"button",variant:"ghost",onClick:()=>Ae(Vr),disabled:ge===Vr,className:ks,"aria-label":r("settings.openchamber.visual.actions.resetCodeFontAria"),title:r("settings.common.actions.reset"),children:s.jsx(L,{name:"restart",className:"h-3.5 w-3.5"})})]})]}):null,be("fontSize")&&!h||be("terminalFontSize")||be("editorFontSize")?s.jsxs(Nn,{children:[be("fontSize")&&!h&&s.jsx(es,{label:r("settings.openchamber.visual.field.interfaceFontSize"),controlClassName:"w-full",children:s.jsxs("div",{className:ba,children:[s.jsx(Is,{value:re,onValueChange:fe,min:50,max:200,step:5,"aria-label":r("settings.openchamber.visual.field.fontSizePercentageAria")}),s.jsx("span",{className:va,children:"%"}),s.jsx(B,{size:"sm",type:"button",variant:"ghost",onClick:()=>fe(100),disabled:re===100,className:ks,"aria-label":r("settings.openchamber.visual.actions.resetFontSizeAria"),title:r("settings.common.actions.reset"),children:s.jsx(L,{name:"restart",className:"h-3.5 w-3.5"})})]})}),be("terminalFontSize")&&s.jsx(es,{label:r("settings.openchamber.visual.field.terminalFontSize"),settingsItem:"appearance.terminal-font-size",controlClassName:"w-full",children:s.jsxs("div",{className:ba,children:[s.jsx(Is,{value:ae,onValueChange:ie,min:9,max:52,step:1}),s.jsx("span",{className:va,children:"px"}),s.jsx(B,{size:"sm",type:"button",variant:"ghost",onClick:()=>ie(13),disabled:ae===13,className:ks,"aria-label":r("settings.openchamber.visual.actions.resetTerminalFontSizeAria"),title:r("settings.common.actions.reset"),children:s.jsx(L,{name:"restart",className:"h-3.5 w-3.5"})})]})}),be("editorFontSize")&&s.jsx(es,{label:r("settings.openchamber.visual.field.editorFontSize"),settingsItem:"appearance.editor-font-size",controlClassName:"w-full",children:s.jsxs("div",{className:ba,children:[s.jsx(Is,{value:xe,onValueChange:De,min:9,max:32,step:1}),s.jsx("span",{className:va,children:"px"}),s.jsx(B,{size:"sm",type:"button",variant:"ghost",onClick:()=>De(13),disabled:xe===13,className:ks,"aria-label":r("settings.openchamber.visual.actions.resetEditorFontSizeAria"),title:r("settings.common.actions.reset"),children:s.jsx(L,{name:"restart",className:"h-3.5 w-3.5"})})]})})]}):null,be("spacing")||be("inputBarOffset")&&h?s.jsxs(Nn,{children:[be("spacing")&&s.jsx(es,{label:r("settings.openchamber.visual.field.spacingDensity"),settingsItem:"appearance.spacing-density",controlClassName:"w-full",children:s.jsxs("div",{className:ba,children:[s.jsx(Is,{value:Ve,onValueChange:_e,min:50,max:200,step:5}),s.jsx("span",{className:va,children:"%"}),s.jsx(B,{size:"sm",type:"button",variant:"ghost",onClick:()=>_e(100),disabled:Ve===100,className:ks,"aria-label":r("settings.openchamber.visual.actions.resetSpacingAria"),title:r("settings.common.actions.reset"),children:s.jsx(L,{name:"restart",className:"h-3.5 w-3.5"})})]})}),be("inputBarOffset")&&h&&s.jsx(es,{label:r("settings.openchamber.visual.field.inputBarOffset"),info:r("settings.openchamber.visual.field.inputBarOffsetTooltip"),settingsItem:"appearance.input-bar-offset",controlClassName:"w-full",children:s.jsxs("div",{className:ba,children:[s.jsx(Is,{value:Le,onValueChange:Re,min:0,max:100,step:5}),s.jsx("span",{className:va,children:"px"}),s.jsx(B,{size:"sm",type:"button",variant:"ghost",onClick:()=>Re(0),disabled:Le===0,className:ks,"aria-label":r("settings.openchamber.visual.actions.resetInputBarOffsetAria"),title:r("settings.common.actions.reset"),children:s.jsx(L,{name:"restart",className:"h-3.5 w-3.5"})})]})})]}):null]}),ma&&s.jsxs(Be,{title:r("settings.openchamber.visual.section.navigation"),contentClassName:"space-y-4",children:[be("fileEditorKeymap")&&s.jsx(_s,{title:r("settings.openchamber.visual.field.fileEditorKeymap"),settingsItem:"appearance.file-editor-keymap",children:s.jsx(wn,{"aria-label":r("settings.openchamber.visual.field.fileEditorKeymap"),children:["default","vim"].map(u=>s.jsx(kn,{selected:$===u,onSelect:()=>de(u),label:r(`settings.openchamber.visual.option.fileEditorKeymap.${u}`),ariaLabel:r(`settings.openchamber.visual.option.fileEditorKeymap.${u}`)},u))})}),s.jsxs("div",{className:Ns,children:[be("autoSaveEnabled")&&s.jsx(ht,{checked:F,onChange:se,label:r("settings.openchamber.visual.field.autoSaveEnabled"),ariaLabel:r("settings.openchamber.visual.field.autoSaveEnabledAria"),info:r("settings.openchamber.visual.field.autoSaveEnabledInfo"),settingsItem:"appearance.auto-save-enabled"}),ta&&s.jsx(es,{label:r("settings.openchamber.visual.field.terminalShell"),info:r("settings.openchamber.visual.field.terminalShellHint"),settingsItem:"appearance.terminal-shell",className:"pt-2",children:s.jsxs(Ot,{value:te,onValueChange:u=>{bd(u)&&ye(u)},children:[s.jsx(Lt,{"aria-label":r("settings.openchamber.visual.field.terminalShellAria"),size:Jt,className:xn,children:s.jsx(Ht,{})}),s.jsxs(Ft,{children:[s.jsx(ut,{value:"auto",children:r("settings.openchamber.visual.option.terminalShell.auto")}),Ni.map(u=>s.jsx(ut,{value:u.id,children:u.name},u.id))]})]})}),ta&&Si&&s.jsx(ht,{checked:Ci,onChange:Rn,label:r("settings.openchamber.visual.field.terminalLoginShell"),ariaLabel:r("settings.openchamber.visual.field.terminalLoginShell"),settingsItem:"appearance.terminal-login-shell"}),be("terminalQuickKeys")&&!h&&s.jsx(ht,{checked:Pe,onChange:We,label:r("settings.openchamber.visual.field.terminalQuickKeys"),ariaLabel:r("settings.openchamber.visual.field.terminalQuickKeysAria"),settingsItem:"appearance.terminal-quick-keys",info:r("settings.openchamber.visual.field.terminalQuickKeysTooltip",{control:$n("ctrl"),alt:$n("alt")})})]}),be("sessionTabs")&&!xs&&!h&&s.jsx(_s,{title:r("settings.openchamber.visual.field.sessionTabsGroup"),settingsItem:"appearance.session-tabs",children:s.jsx(ht,{checked:Ue,onChange:ve,label:r("settings.openchamber.visual.field.sessionTabs"),ariaLabel:r("settings.openchamber.visual.field.sessionTabsAria"),info:r("settings.openchamber.visual.field.sessionTabsInfo")})})]}),ji&&s.jsxs(s.Fragment,{children:[Dn&&s.jsxs(Be,{title:r("settings.openchamber.visual.section.chatDisplay"),divider:ea,contentClassName:"space-y-6",children:[be("chatRenderMode")&&s.jsx(_s,{title:r("settings.openchamber.visual.section.chatRenderMode"),settingsItem:"chat.render-mode",children:s.jsx("div",{role:"radiogroup","aria-label":r("settings.openchamber.visual.section.chatRenderModeAria"),className:"grid w-full max-w-[26rem] grid-cols-1 gap-3 @xl:grid-cols-2",children:dh.map(u=>{const rt=X===u.id,ts=Xt%12;return s.jsxs("button",{type:"button",onClick:()=>fi(u.id),"aria-pressed":rt,className:je("flex flex-col items-start gap-1 rounded-lg border p-3 text-left transition-colors",rt?"border-primary bg-primary/5":"border-border hover:border-border/80 hover:bg-muted/50"),children:[s.jsx("span",{className:je("typography-ui-label",rt?"text-foreground":"text-muted-foreground"),children:l(u.labelKey)}),s.jsx("div",{className:"mt-2 w-full rounded-md border border-border/60 bg-muted/30 p-2",children:u.id==="live"?s.jsx("div",{className:"space-y-1.5",children:[0,1,2].map(ps=>{const Ts=ps*3+1,Ws=ts-Ts+1,Et=Ws<=0?0:Ws===1?42:Ws===2?68:92,is=Et>0;return s.jsxs("div",{className:je("flex items-center gap-1.5 transition-all duration-300 motion-reduce:transition-none",is?"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:`${Et}%`}})]},ps)})}):s.jsx("div",{className:"space-y-1.5",children:[0,1,2].map(ps=>{const Ts=ts>=(ps+1)*3;return s.jsxs("div",{className:je("flex items-center gap-1.5 transition-all duration-300 motion-reduce:transition-none",Ts?"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%"}})]},ps)})})})]},u.id)})})}),be("activityRenderMode")&&X==="sorted"&&s.jsx(_s,{title:r("settings.openchamber.visual.section.activityDefault"),children:s.jsx(wn,{"aria-label":r("settings.openchamber.visual.section.activityDefaultAria"),children:ph.map(u=>s.jsx(kn,{selected:ne===u.id,onSelect:()=>bi(u.id),label:l(u.labelKey),ariaLabel:r("settings.openchamber.visual.field.activityDefaultModeAria",{option:l(u.labelKey)})},u.id))})})]}),gn&&s.jsxs(Be,{title:r("settings.openchamber.visual.section.messageStreamTransport"),divider:Dn||ea,settingsItem:"chat.message-transport",contentClassName:"space-y-2",children:[s.jsx(Js,{value:Ie,options:zo.map(u=>({value:u.id,label:l(u.labelKey)})),onChange:xi,"aria-label":r("settings.openchamber.visual.section.messageStreamTransport")}),(()=>{const u=zo.find(rt=>rt.id===Ie);return u?.descriptionKey?s.jsx("span",{className:"typography-meta text-muted-foreground",children:l(u.descriptionKey)}):null})()]}),Mn&&s.jsx(Be,{title:r("settings.openchamber.visual.section.chatMessageOptions"),divider:Dn||gn||ea,children:s.jsxs(Nn,{className:"lg:gap-y-6",children:[be("userMessageRendering")&&s.jsx(_s,{title:r("settings.openchamber.visual.section.userMessageRendering"),children:s.jsx(wn,{"aria-label":r("settings.openchamber.visual.section.userMessageRenderingAria"),children:ch.map(u=>s.jsx(kn,{selected:uh(R)===u.id,onSelect:()=>Yn(u.id),label:l(u.labelKey),ariaLabel:r("settings.openchamber.visual.field.userMessageRenderingAria",{option:l(u.labelKey)})},u.id))})}),be("mermaidRendering")&&s.jsx(_s,{title:r("settings.openchamber.visual.section.mermaidRendering"),children:s.jsx(wn,{"aria-label":r("settings.openchamber.visual.section.mermaidRenderingAria"),children:lh.map(u=>s.jsx(kn,{selected:T===u.id,onSelect:()=>vi(u.id),label:l(u.labelKey),ariaLabel:r("settings.openchamber.visual.field.mermaidRenderingAria",{option:l(u.labelKey)})},u.id))})}),be("diffLayout")&&!xs&&s.jsx(_s,{title:r("settings.openchamber.visual.section.diffLayout"),children:s.jsx(wn,{"aria-label":r("settings.openchamber.visual.section.diffLayoutAria"),children:oh.map(u=>s.jsx(kn,{selected:Oe===u.id,onSelect:()=>Ke(u.id),label:l(u.labelKey),ariaLabel:r("settings.openchamber.visual.field.diffLayoutAria",{option:l(u.labelKey)})},u.id))})}),be("followUpBehavior")&&s.jsx(_s,{title:r("settings.openchamber.visual.section.followUpBehavior"),settingsItem:"chat.follow-up-behavior",children:s.jsx(wn,{"aria-label":r("settings.openchamber.visual.section.followUpBehaviorAria"),children:mh.map(u=>s.jsx(kn,{selected:ue===u.id,onSelect:()=>Ne(u.id),label:l(u.labelKey),ariaLabel:r("settings.openchamber.visual.field.followUpBehaviorAria",{option:l(u.labelKey)})},u.id))})})]})}),$a&&s.jsxs(s.Fragment,{children:[be("expandedTools")&&s.jsxs(Be,{title:r("settings.openchamber.visual.section.showToolsOpenedByDefault"),divider:Dn||gn||Mn||ea,contentClassName:Ns,children:[s.jsx(ht,{checked:xt,onChange:Zn,label:r("settings.openchamber.visual.field.bash"),ariaLabel:r("settings.openchamber.visual.field.showExpandedBashToolsAria")}),s.jsx(ht,{checked:bt,onChange:on,label:r("settings.openchamber.visual.field.editTools"),ariaLabel:r("settings.openchamber.visual.field.showExpandedEditToolsAria")})]}),s.jsxs(Be,{title:r("settings.openchamber.visual.section.sessionAssistance"),settingsItem:"chat.session-assistance",contentClassName:Ns,children:[s.jsx(ht,{checked:kt,onChange:gi,label:r("settings.openchamber.visual.field.draftStartersVisible"),ariaLabel:r("settings.openchamber.visual.field.draftStartersVisibleAria"),settingsItem:"chat.draft-starters-visible"}),be("sessionAssist")&&s.jsxs(s.Fragment,{children:[s.jsx(ht,{checked:p,onChange:b,label:r("settings.openchamber.visual.field.sessionRecap"),ariaLabel:r("settings.openchamber.visual.field.sessionRecapAria"),settingsItem:"chat.session-recap"}),s.jsx(ht,{checked:A,onChange:P,label:r("settings.openchamber.visual.field.sessionSuggestion"),ariaLabel:r("settings.openchamber.visual.field.sessionSuggestionAria"),settingsItem:"chat.session-suggestion"})]}),be("subagentReadOnlyBanner")&&s.jsx(ht,{checked:vt,onChange:Se,label:r("settings.openchamber.visual.field.allowPromptingSubagentSessions"),ariaLabel:r("settings.openchamber.visual.field.allowPromptingSubagentSessionsAria"),settingsItem:"chat.subagent-read-only-banner"})]}),be("sessionGoal")&&!xs&&s.jsxs(Be,{title:r("settings.openchamber.visual.goal.sectionTitle"),info:r("settings.openchamber.visual.goal.description"),contentClassName:Ns,children:[s.jsx(ht,{checked:N,onChange:k,label:r("settings.openchamber.visual.field.sessionGoal"),ariaLabel:r("settings.openchamber.visual.field.sessionGoalAria"),settingsItem:"chat.session-goal"}),s.jsxs("div",{"data-settings-item":"chat.session-goal-budget",className:"flex items-center gap-2",children:[s.jsx(ht,{checked:g,onChange:E,disabled:!N,label:r("settings.openchamber.visual.goal.budgetLabel"),ariaLabel:r("settings.openchamber.visual.goal.budgetAria")}),N&&g?s.jsx(Is,{value:O,onValueChange:u=>{typeof u=="number"&&Number.isFinite(u)&&u>0&&I(Math.floor(u))},min:1e3,max:1e8,step:5e4}):null]})]}),be("reasoning")&&s.jsxs(Be,{title:r("settings.openchamber.visual.section.reasoning"),settingsItem:"chat.reasoning",contentClassName:Ns,children:[s.jsx(ht,{checked:v,onChange:w,label:r("settings.openchamber.visual.field.showReasoningTraces"),ariaLabel:r("settings.openchamber.visual.field.showReasoningTracesAria"),settingsItem:"chat.reasoning-traces"}),v&&s.jsx(ht,{checked:K,onChange:C,label:r("settings.openchamber.visual.field.collapsibleThinkingBlocks"),ariaLabel:r("settings.openchamber.visual.field.collapsibleThinkingBlocksAria")})]}),s.jsx(Be,{title:r("settings.openchamber.visual.section.streaming"),settingsItem:"chat.streaming",contentClassName:Ns,children:s.jsx(ht,{checked:m,onChange:y,label:r("settings.openchamber.visual.field.streamingAutoFollow"),ariaLabel:r("settings.openchamber.visual.field.streamingAutoFollowAria"),info:r("settings.openchamber.visual.field.streamingAutoFollowInfo"),settingsItem:"chat.streaming-auto-follow"})}),(be("collapsibleUserMessages")||be("stickyUserHeader")||be("promptNavigatorEnabled")&&!xs||be("wideChatLayout")||be("splitAssistantMessageActions")||be("codeBlockLineWrap"))&&s.jsxs(Be,{title:r("settings.openchamber.visual.section.messageAppearance"),settingsItem:"chat.message-appearance",contentClassName:Ns,children:[be("collapsibleUserMessages")&&s.jsx(ht,{checked:S,onChange:Os,label:r("settings.openchamber.visual.field.collapsibleUserMessages"),ariaLabel:r("settings.openchamber.visual.field.collapsibleUserMessagesAria"),settingsItem:"chat.collapsible-user-messages"}),be("stickyUserHeader")&&s.jsx(ht,{checked:Q,onChange:mi,label:r("settings.openchamber.visual.field.stickyUserHeader"),ariaLabel:r("settings.openchamber.visual.field.stickyUserHeaderAria"),settingsItem:"chat.sticky-user-header"}),be("promptNavigatorEnabled")&&!xs&&s.jsx(ht,{checked:M,onChange:ui,label:r("settings.openchamber.visual.field.promptNavigatorEnabled"),ariaLabel:r("settings.openchamber.visual.field.promptNavigatorEnabledAria"),settingsItem:"chat.prompt-navigator"}),be("wideChatLayout")&&s.jsx(ht,{checked:_,onChange:pa,label:r("settings.openchamber.visual.field.wideChatLayout"),ariaLabel:r("settings.openchamber.visual.field.wideChatLayoutAria"),settingsItem:"chat.wide-layout"}),be("splitAssistantMessageActions")&&s.jsx(ht,{checked:dt,onChange:hi,label:r("settings.openchamber.visual.field.showSplitAssistantMessageActions"),ariaLabel:r("settings.openchamber.visual.field.showSplitAssistantMessageActionsAria"),settingsItem:"chat.inline-assistant-actions",info:r("settings.openchamber.visual.field.showSplitAssistantMessageActionsTooltip")}),be("codeBlockLineWrap")&&s.jsx(ht,{checked:z,onChange:U,label:r("settings.openchamber.visual.field.codeBlockLineWrap"),ariaLabel:r("settings.openchamber.visual.field.codeBlockLineWrapAria"),settingsItem:"chat.code-block-line-wrap"})]}),(be("showToolFileIcons")||be("showTurnChangedFiles")||be("dotfiles")&&!vs()||be("fileViewerPreview"))&&s.jsxs(Be,{title:r("settings.openchamber.visual.section.toolsAndFiles"),settingsItem:"chat.tools-and-files",contentClassName:Ns,children:[be("showToolFileIcons")&&s.jsx(ht,{checked:et,onChange:yi,label:r("settings.openchamber.visual.field.showToolFileIcons"),ariaLabel:r("settings.openchamber.visual.field.showToolFileIconsAria"),settingsItem:"chat.tool-file-icons"}),be("showTurnChangedFiles")&&s.jsx(ht,{checked:st,onChange:Ss,label:r("settings.openchamber.visual.field.showTurnChangedFiles"),ariaLabel:r("settings.openchamber.visual.field.showTurnChangedFilesAria"),settingsItem:"chat.changed-files"}),be("dotfiles")&&!vs()&&s.jsx(ht,{checked:c,onChange:vd,label:r("settings.openchamber.visual.field.showDotfiles"),ariaLabel:r("settings.openchamber.visual.field.showDotfilesAria"),settingsItem:"chat.dotfiles"}),be("fileViewerPreview")&&s.jsx(ht,{checked:lt,onChange:Bs,label:r("settings.openchamber.defaults.field.openFilesPreview"),ariaLabel:r("settings.openchamber.defaults.field.openFilesPreviewAria")})]}),(be("persistDraft")||!h&&be("inputSpellcheck"))&&s.jsxs(Be,{title:r("settings.openchamber.visual.section.composer"),settingsItem:"chat.composer",contentClassName:Ns,children:[be("persistDraft")&&s.jsx(ht,{checked:pe,onChange:Fe,label:r("settings.openchamber.visual.field.persistDraftMessages"),ariaLabel:r("settings.openchamber.visual.field.persistDraftMessagesAria"),settingsItem:"chat.persist-drafts"}),!h&&be("inputSpellcheck")&&s.jsx(ht,{checked:H,onChange:Ua,label:r("settings.openchamber.visual.field.enableSpellcheckInTextInputs"),ariaLabel:r("settings.openchamber.visual.field.enableSpellcheckInTextInputsAria"),settingsItem:"chat.spellcheck"})]})]})]}),be("reportUsage")&&s.jsx(Be,{title:r("settings.openchamber.visual.section.privacy"),children:s.jsx(ht,{checked:ft,onChange:Dt,label:r("settings.openchamber.visual.field.sendAnonymousUsageReports"),info:r("settings.openchamber.visual.field.sendAnonymousUsageReportsHint"),ariaLabel:r("settings.openchamber.visual.field.sendAnonymousUsageReportsAria"),settingsItem:"appearance.usage-reports"})})]})},fh=1,xh=365,Vo=30,bh=[{value:"archive",labelKey:"settings.openchamber.sessionRetention.action.archive"},{value:"delete",labelKey:"settings.openchamber.sessionRetention.action.delete"}],_l=()=>{const t=mt.c(87),{t:e}=ot(),a=ce(vh),n=ce(yh),i=ce(jh),r=ce(wh),l=ce(kh),h=ce(Nh);let d;t[0]===Symbol.for("react.memo_cache_sentinel")?(d={autoRun:!1},t[0]=d):d=t[0];const{candidates:x,isRunning:c,runCleanup:v,action:p}=Rc(d),A=x.length;let b;t[1]!==v||t[2]!==e?(b=async()=>{const le=await v({force:!0});if(le.completedIds.length===0&&le.failedIds.length===0){D.message(le.action==="archive"?e("settings.openchamber.sessionRetention.toast.noneEligibleArchive"):e("settings.openchamber.sessionRetention.toast.noneEligibleDelete"));return}le.completedIds.length>0&&D.success(le.action==="archive"?e("settings.openchamber.sessionRetention.toast.archivedCount",{count:le.completedIds.length}):e("settings.openchamber.sessionRetention.toast.deletedCount",{count:le.completedIds.length})),le.failedIds.length>0&&D.error(le.action==="archive"?e("settings.openchamber.sessionRetention.toast.failedArchiveCount",{count:le.failedIds.length}):e("settings.openchamber.sessionRetention.toast.failedDeleteCount",{count:le.failedIds.length}))},t[1]=v,t[2]=e,t[3]=b):b=t[3];const P=b;let N;t[4]!==e?(N=e("settings.openchamber.sessionRetention.title"),t[4]=e,t[5]=N):N=t[5];let k;t[6]!==e?(k=e("settings.openchamber.sessionRetention.tooltip"),t[6]=e,t[7]=k):k=t[7];let g;t[8]!==e?(g=e("settings.openchamber.sessionRetention.field.enableAutoCleanup"),t[8]=e,t[9]=g):g=t[9];let E;t[10]!==e?(E=e("settings.openchamber.sessionRetention.field.enableAutoCleanupAria"),t[10]=e,t[11]=E):E=t[11];let O;t[12]!==a||t[13]!==r||t[14]!==g||t[15]!==E?(O=s.jsx(ht,{settingsItem:"sessions.auto-cleanup",checked:a,onChange:r,label:g,ariaLabel:E}),t[12]=a,t[13]=r,t[14]=g,t[15]=E,t[16]=O):O=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 m;t[21]!==n||t[22]!==l||t[23]!==w?(m=s.jsx(Is,{value:n,onValueChange:l,min:fh,max:xh,step:1,"aria-label":w,className:"w-20 tabular-nums"}),t[21]=n,t[22]=l,t[23]=w,t[24]=m):m=t[24];let y;t[25]!==e?(y=e("settings.openchamber.sessionRetention.field.days"),t[25]=e,t[26]=y):y=t[26];let K;t[27]!==y?(K=s.jsx("span",{className:"typography-ui-label text-muted-foreground",children:y}),t[27]=y,t[28]=K):K=t[28];let C;t[29]!==l?(C=()=>l(Vo),t[29]=l,t[30]=C):C=t[30];const T=n===Vo;let j;t[31]!==e?(j=e("settings.openchamber.sessionRetention.actions.resetRetentionAria"),t[31]=e,t[32]=j):j=t[32];let R;t[33]!==e?(R=e("settings.common.actions.reset"),t[33]=e,t[34]=R):R=t[34];let G;t[35]===Symbol.for("react.memo_cache_sentinel")?(G=s.jsx(L,{name:"restart",className:"h-3.5 w-3.5"}),t[35]=G):G=t[35];let S;t[36]!==C||t[37]!==T||t[38]!==j||t[39]!==R?(S=s.jsx(B,{size:"sm",type:"button",variant:"ghost",onClick:C,disabled:T,className:ks,"aria-label":j,title:R,children:G}),t[36]=C,t[37]=T,t[38]=j,t[39]=R,t[40]=S):S=t[40];let q;t[41]!==K||t[42]!==S||t[43]!==I||t[44]!==m?(q=s.jsxs(Qt,{settingsItem:"sessions.retention-period",label:I,children:[m,K,S]}),t[41]=K,t[42]=S,t[43]=I,t[44]=m,t[45]=q):q=t[45];let Q;t[46]!==e?(Q=e("settings.openchamber.sessionRetention.field.whenSessionsExpire"),t[46]=e,t[47]=Q):Q=t[47];let M;t[48]!==e?(M=bh.map(le=>({value:le.value,label:e(le.labelKey)})),t[48]=e,t[49]=M):M=t[49];let W;t[50]!==i||t[51]!==h||t[52]!==M?(W=s.jsx(Js,{value:i,onChange:h,options:M}),t[50]=i,t[51]=h,t[52]=M,t[53]=W):W=t[53];let Y;t[54]!==Q||t[55]!==W?(Y=s.jsx(Qt,{settingsItem:"sessions.retention-action",label:Q,children:W}),t[54]=Q,t[55]=W,t[56]=Y):Y=t[56];let F;t[57]!==q||t[58]!==Y?(F=s.jsxs(Oa,{className:"space-y-0",children:[q,Y]}),t[57]=q,t[58]=Y,t[59]=F):F=t[59];let se;t[60]!==e?(se=e("settings.openchamber.sessionRetention.manualCleanup.title"),t[60]=e,t[61]=se):se=t[61];let _;t[62]!==c||t[63]!==e?(_=e(c?"settings.openchamber.sessionRetention.actions.cleaningUp":"settings.openchamber.sessionRetention.actions.runCleanupNow"),t[62]=c,t[63]=e,t[64]=_):_=t[64];let V;t[65]!==P||t[66]!==c||t[67]!==_?(V=s.jsx(B,{type:"button",variant:"outline",size:"xs",onClick:P,disabled:c,className:"!font-normal",children:_}),t[65]=P,t[66]=c,t[67]=_,t[68]=V):V=t[68];let z;t[69]!==se||t[70]!==V?(z=s.jsx(Qt,{label:se,children:V}),t[69]=se,t[70]=V,t[71]=z):z=t[71];let U;t[72]!==p||t[73]!==A||t[74]!==e?(U=p==="archive"?e("settings.openchamber.sessionRetention.manualCleanup.eligibleArchiveNow",{count:A}):e("settings.openchamber.sessionRetention.manualCleanup.eligibleDeleteNow",{count:A}),t[72]=p,t[73]=A,t[74]=e,t[75]=U):U=t[75];let X;t[76]!==U?(X=s.jsx("p",{className:"typography-meta text-muted-foreground",children:U}),t[76]=U,t[77]=X):X=t[77];let Z;t[78]!==z||t[79]!==X?(Z=s.jsxs("div",{className:"mt-1 py-1.5 space-y-1",children:[z,X]}),t[78]=z,t[79]=X,t[80]=Z):Z=t[80];let ne;return t[81]!==N||t[82]!==F||t[83]!==k||t[84]!==Z||t[85]!==O?(ne=s.jsxs(Be,{title:N,info:k,children:[O,F,Z]}),t[81]=N,t[82]=F,t[83]=k,t[84]=Z,t[85]=O,t[86]=ne):ne=t[86],ne};function vh(t){return t.autoDeleteEnabled}function yh(t){return t.autoDeleteAfterDays}function jh(t){return t.sessionRetentionAction}function wh(t){return t.setAutoDeleteEnabled}function kh(t){return t.setAutoDeleteAfterDays}function Nh(t){return t.setSessionRetentionAction}const Bo=(t,e,a)=>!t||!Number.isFinite(t)?e:new Intl.DateTimeFormat(ur(),{dateStyle:"medium",timeStyle:"short",hour12:a==="auto"?void 0:a==="12h"}).format(t),$l=()=>{const{t}=ot(),e=ce(m=>m.timeFormatPreference),[a,n]=o.useState(!1),[i,r]=o.useState(!0),[l,h]=o.useState(!1),[d,x]=o.useState(null),[c,v]=o.useState(!1),[p,A]=o.useState([]),[b,P]=o.useState(Oc),[N,k]=o.useState(""),g=o.useMemo(()=>Lc(),[]),E=o.useCallback(async()=>{r(!0),k("");try{const m=await Fc();A(m)}catch(m){const y=m instanceof Error?m.message:t("settings.openchamber.passkeys.toast.loadFailed");k(y)}finally{r(!1)}},[t]);o.useEffect(()=>{let m=!1;return(async()=>{try{if(!g.supported){m||(n(!1),r(!1));return}m||n(!0)}catch{m||n(!1)}if(!m){const y=await Ai();if(P(y),!y.enabled){A([]),r(!1);return}await E()}})(),()=>{m=!0,Tr()}},[E,g.supported]);const O=o.useCallback(async()=>{if(!b.enabled){const m=t("settings.openchamber.passkeys.toast.enableUiPasswordFirst");k(m),D.message(m);return}if(!a){k(g.reason),D.message(g.reason);return}if(l){Tr(),h(!1);return}k(""),h(!0);try{await Kc(),P(await Ai()),await E(),D.success(t("settings.openchamber.passkeys.toast.added"))}catch(m){if(Uc(m)){D.message(t("settings.openchamber.passkeys.toast.setupCanceled"));return}const y=m instanceof Error?m.message:t("settings.openchamber.passkeys.toast.addFailed");k(y),D.error(y)}finally{h(!1)}},[l,E,b.enabled,g.reason,a,t]),I=o.useCallback(async m=>{x(m),k("");try{await zc(m),P(await Ai()),await E(),D.success(t("settings.openchamber.passkeys.toast.removed"))}catch(y){const K=y instanceof Error?y.message:t("settings.openchamber.passkeys.toast.removeFailed");k(K),D.error(K)}finally{x(null)}},[E,t]),w=o.useCallback(async()=>{v(!0),k("");try{await _c(),window.location.reload()}catch(m){const y=m instanceof Error?m.message:t("settings.openchamber.passkeys.toast.clearAuthFailed");k(y),D.error(y),v(!1)}},[t]);return s.jsxs(Be,{title:t("settings.openchamber.passkeys.title"),children:[s.jsxs("div",{className:"space-y-2",children:[s.jsxs(Qt,{label:t("settings.openchamber.passkeys.field.currentDevice"),children:[s.jsx(B,{type:"button",variant:l?"secondary":"outline",size:"xs",onClick:()=>{O()},disabled:i||c,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:i||l||c,className:"!font-normal text-muted-foreground hover:text-foreground",children:t(c?"settings.openchamber.passkeys.actions.signingOut":"settings.openchamber.passkeys.actions.signOutEverywhere")})]}),!b.enabled&&s.jsx("p",{className:"typography-meta text-muted-foreground",children:t("settings.openchamber.passkeys.state.uiPasswordRequired")}),b.enabled&&!a&&s.jsx("p",{className:"typography-meta text-muted-foreground",children:g.reason}),i?s.jsx("p",{className:"typography-meta text-muted-foreground",children:t("settings.openchamber.passkeys.state.loading")}):p.length===0?s.jsx("p",{className:"typography-meta text-muted-foreground",children:t("settings.openchamber.passkeys.state.noneSaved")}):s.jsx("div",{className:"space-y-1 pt-1",children:p.map(m=>s.jsxs(Qt,{label:s.jsx("span",{className:"truncate",children:m.label}),alignEnd:!1,controlClassName:"justify-between sm:flex-1",children:[s.jsx("span",{className:"typography-meta text-muted-foreground truncate",children:m.lastUsedAt?t("settings.openchamber.passkeys.item.lastUsed",{time:Bo(m.lastUsedAt,t("settings.openchamber.passkeys.time.neverUsed"),e)}):t("settings.openchamber.passkeys.item.added",{time:Bo(m.createdAt,t("settings.openchamber.passkeys.time.neverUsed"),e)})}),s.jsx(B,{type:"button",variant:"ghost",size:"xs",onClick:()=>{I(m.id)},disabled:d===m.id,className:"!font-normal text-muted-foreground hover:text-foreground",children:d===m.id?t("settings.openchamber.passkeys.actions.removing"):t("settings.common.actions.delete")})]},m.id))})]}),N&&s.jsx("div",{className:"mt-1 py-1.5",children:s.jsx("p",{className:"typography-meta text-[var(--status-error)]",children:N})})]})},Vl=()=>{const t=mt.c(14),{t:e}=ot(),a=Dr(Sh),n=Dr(Ch);let i;t[0]!==e?(i=e("settings.openchamber.appLinks.title"),t[0]=e,t[1]=i):i=t[1];let r;t[2]!==e?(r=e("settings.openchamber.appLinks.info"),t[2]=e,t[3]=r):r=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(x=>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:`${x}://`}),s.jsx(B,{type:"button",variant:"ghost",size:"xs",onClick:()=>n(x),className:"!font-normal text-muted-foreground hover:text-foreground","aria-label":e("settings.openchamber.appLinks.removeAria",{scheme:`${x}://`}),children:e("settings.common.actions.delete")})]},x)),t[4]=n,t[5]=e,t[6]=a,t[7]=l):l=t[7];let h;t[8]!==l?(h=s.jsx("div",{className:"space-y-1","data-settings-item":"general.app-links",children:l}),t[8]=l,t[9]=h):h=t[9];let d;return t[10]!==i||t[11]!==r||t[12]!==h?(d=s.jsx(Be,{title:i,description:r,children:h}),t[10]=i,t[11]=r,t[12]=h,t[13]=d):d=t[13],d};function Sh(t){return t.trustedSchemes}function Ch(t){return t.removeTrustedScheme}const Bi=t=>{const e=oa(t);return e||{providerId:"",modelId:""}},Bl=()=>{const{t}=ot(),e=tt(ae=>ae.setProvider),a=tt(ae=>ae.setModel),n=tt(ae=>ae.setAgent),i=tt(ae=>ae.setCurrentVariant),r=tt(ae=>ae.setCurrentVariantOverride),l=tt(ae=>ae.setSettingsDefaultModel),h=tt(ae=>ae.setSettingsDefaultVariant),d=tt(ae=>ae.setSettingsDefaultAgent),x=tt(ae=>ae.selectionSource==="manual"),c=$c(ae=>ae.currentSessionId),v=Mr(ae=>ae.getSessionModelSelection),p=Mr(ae=>ae.getSessionAgentSelection),A=!!(x&&c&&v(c)),b=!!(x&&c&&p(c)),P=ce(ae=>ae.showDeletionDialog),N=ce(ae=>ae.setShowDeletionDialog),k=tt(ae=>ae.providers),g=tt(ae=>ae.modelsMetadata),[E,O]=o.useState(),[I,w]=o.useState(),[m,y]=o.useState(),[K,C]=o.useState(!0),[T,j]=o.useState(),[R,G]=o.useState([]),[S,q]=o.useState(),[Q,M]=o.useState(!0),W=o.useMemo(()=>Bi(E),[E]);o.useEffect(()=>{(async()=>{try{let ie=null;if(!ie){const te=In()?.settings;if(te)try{const we=(await te.load())?.settings;if(we){const ke=we;ie={defaultModel:typeof we.defaultModel=="string"?we.defaultModel:void 0,defaultVariant:typeof ke.defaultVariant=="string"?ke.defaultVariant:void 0,defaultAgent:typeof we.defaultAgent=="string"?we.defaultAgent:void 0,smallModelUseDefault:typeof ke.smallModelUseDefault=="boolean"?ke.smallModelUseDefault:void 0,smallModelOverride:typeof ke.smallModelOverride=="string"?ke.smallModelOverride:void 0,walkthroughModelOverride:typeof ke.walkthroughModelOverride=="string"?ke.walkthroughModelOverride:void 0}}}catch{}}if(!ie){const te=await pt("/api/config/settings",{method:"GET",headers:{Accept:"application/json"}});te.ok&&(ie=await te.json())}if(ie){const te=typeof ie.defaultModel=="string"&&ie.defaultModel.trim().length>0?ie.defaultModel.trim():void 0,ye=typeof ie.defaultVariant=="string"&&ie.defaultVariant.trim().length>0?ie.defaultVariant.trim():void 0,we=typeof ie.defaultAgent=="string"&&ie.defaultAgent.trim().length>0?ie.defaultAgent.trim():void 0;te!==void 0&&O(te),ye!==void 0&&w(ye),we!==void 0&&y(we),typeof ie.smallModelUseDefault=="boolean"&&C(ie.smallModelUseDefault),typeof ie.smallModelOverride=="string"&&ie.smallModelOverride.trim()&&j(ie.smallModelOverride.trim()),typeof ie.walkthroughModelOverride=="string"&&ie.walkthroughModelOverride.trim()&&q(ie.walkthroughModelOverride.trim())}}catch(ie){console.warn("Failed to load defaults settings:",ie)}finally{M(!1)}})()},[]);const Y=o.useCallback(async(ae,ie)=>{const te=ae&&ie?`${ae}/${ie}`:void 0;O(te),w(void 0),h(void 0),l(te),A||(i(void 0),ae&&ie&&k.find(we=>we.id===ae)&&(e(ae),a(ie)));try{await Nt({defaultModel:te??"",defaultVariant:""});const ye=await pt("/api/config/settings",{method:"PUT",headers:{"Content-Type":"application/json"},body:JSON.stringify({defaultModel:te})});ye.ok||console.warn("Failed to save default model to server:",ye.status,ye.statusText)}catch(ye){console.warn("Failed to save default model:",ye)}},[A,k,i,a,e,l,h]),F="__default__",se=o.useCallback(ae=>ae===F?t("settings.openchamber.defaults.option.default"):ae.charAt(0).toUpperCase()+ae.slice(1),[t]),_=o.useCallback(async ae=>{const ie=ae===F?void 0:ae||void 0;w(ie),h(ie),A||r(ie??null,ie);try{await Nt({defaultVariant:ie??""})}catch(te){console.warn("Failed to save default variant:",te)}},[A,r,h]),V=o.useCallback(async ae=>{const ie=ae||void 0;y(ie),d(ie),ae&&!b&&n(ae);try{await Nt({defaultAgent:ie??""})}catch(te){console.warn("Failed to save default agent:",te)}},[b,n,d]),z=o.useCallback(async ae=>{C(ae);try{await Nt({smallModelUseDefault:ae})}catch(ie){console.warn("Failed to save small model preference:",ie)}},[]),U=o.useCallback(async(ae,ie)=>{const te=ae&&ie?`${ae}/${ie}`:void 0;j(te);try{await Nt({smallModelOverride:te??""})}catch(ye){console.warn("Failed to save small model override:",ye)}},[]),X=o.useCallback(async(ae,ie)=>{const te=ae&&ie?`${ae}/${ie}`:void 0;q(te);try{await Nt({walkthroughModelOverride:te??""})}catch(ye){console.warn("Failed to save walkthrough model override:",ye)}},[]),Z=o.useCallback((ae,ie)=>g.get(`${ae}/${ie}`)?.structured_output!==!1,[g]),ne=o.useMemo(()=>Bi(T),[T]),le=o.useMemo(()=>Bi(S),[S]);o.useEffect(()=>{let ae=!1;return(async()=>{try{const ie=await pt("/api/small-model",{method:"GET",headers:{Accept:"application/json"}});if(!ie.ok)return;const te=await ie.json().catch(()=>null);!ae&&Array.isArray(te?.authenticatedProviders)&&G(te.authenticatedProviders.filter(ye=>typeof ye=="string"))}catch{}})(),()=>{ae=!0}},[]);const re=o.useMemo(()=>{if(!W.providerId||!W.modelId)return[];const te=k.find(ye=>ye.id===W.providerId)?.models.find(ye=>ye.id===W.modelId)?.variants;return te?Object.keys(te):[]},[W.modelId,W.providerId,k]),fe=re.length>0;return o.useEffect(()=>{!fe&&I&&(w(void 0),h(void 0),A||i(void 0),Nt({defaultVariant:""}).catch(()=>{}))},[A,I,i,h,fe]),Q?null:s.jsx(s.Fragment,{children:s.jsx(Be,{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")," ",W.providerId?s.jsxs("span",{className:"text-foreground",children:[W.providerId,"/",W.modelId,fe?` (${I??t("settings.openchamber.defaults.option.defaultLowercase")})`:""]}):s.jsx("span",{className:"text-foreground",children:t("settings.openchamber.defaults.summaryOpenCodeDefault")}),m&&s.jsxs(s.Fragment,{children:[" / ",s.jsx("span",{className:"text-foreground",children:m})]})]}),s.jsxs("div",{children:[s.jsx(Qt,{settingsItem:"sessions.default-model",label:t("settings.openchamber.defaults.field.defaultModel"),children:s.jsx(Ea,{providerId:W.providerId,modelId:W.modelId,onChange:Y,className:Cn})}),s.jsx(Qt,{settingsItem:"sessions.default-thinking",label:t("settings.openchamber.defaults.field.defaultThinking"),children:s.jsxs(Ot,{value:I??F,onValueChange:_,disabled:!fe,children:[s.jsx(Lt,{size:Jt,className:Pn,children:s.jsx(Ht,{placeholder:t("settings.openchamber.defaults.field.thinkingPlaceholder"),children:se(I??F)})}),s.jsxs(Ft,{children:[s.jsx(ut,{value:F,children:t("settings.openchamber.defaults.option.default")}),re.map(ae=>s.jsx(ut,{value:ae,children:se(ae)},ae))]})]})}),s.jsx(Qt,{settingsItem:"sessions.default-agent",label:t("settings.openchamber.defaults.field.defaultAgent"),children:s.jsx(rl,{agentName:m||"",onChange:V,filter:ae=>Vc(ae.mode),className:Cn})})]}),s.jsx(Oa,{className:Ns,children:s.jsx(ht,{settingsItem:"sessions.deletion-dialog",checked:P,onChange:N,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(en,{children:t("settings.openchamber.defaults.smallModel.title")}),s.jsx(ss,{children:t("settings.openchamber.defaults.smallModel.description")})]}),s.jsx(ht,{settingsItem:"sessions.small-model",checked:K,onChange:ae=>{z(ae)},label:t("settings.openchamber.defaults.smallModel.useDefault"),ariaLabel:t("settings.openchamber.defaults.smallModel.useDefaultAria")}),K?null:s.jsx(Qt,{label:t("settings.openchamber.defaults.smallModel.overrideModel"),children:s.jsx(Ea,{providerId:ne.providerId,modelId:ne.modelId,onChange:U,allowedProviderIds:R,className:Cn})}),s.jsxs(Oa,{className:Ns,children:[s.jsxs("div",{className:"flex items-center gap-1.5",children:[s.jsx(en,{children:t("settings.openchamber.defaults.walkthroughModel.title")}),s.jsx(ss,{children:t("settings.openchamber.defaults.walkthroughModel.description")})]}),s.jsx(Qt,{settingsItem:"sessions.walkthrough-model",label:t("settings.openchamber.defaults.walkthroughModel.overrideModel"),children:s.jsx(Ea,{providerId:le.providerId,modelId:le.modelId,onChange:X,allowedProviderIds:R,isModelAllowed:Z,placeholder:t("settings.openchamber.defaults.walkthroughModel.usesSmallModel"),className:Cn})})]})]})]})})})},Ho={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"}},Ph={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"},Ih=()=>{const{t}=ot(),e=o.useMemo(()=>bs(),[]),a=o.useMemo(()=>vs(),[]),n=o.useMemo(()=>typeof window>"u"?!1:window.Capacitor?.isNativePlatform?.()===!0||window.location.protocol==="capacitor:",[]),i=!e&&!a&&!n,r=ce(_=>_.nativeNotificationsEnabled),l=ce(_=>_.setNativeNotificationsEnabled),h=ce(_=>_.notificationMode),d=ce(_=>_.setNotificationMode),x=ce(_=>_.notifyOnSubtasks),c=ce(_=>_.setNotifyOnSubtasks),v=ce(_=>_.notifyOnCompletion),p=ce(_=>_.setNotifyOnCompletion),A=ce(_=>_.notifyOnError),b=ce(_=>_.setNotifyOnError),P=ce(_=>_.notifyOnQuestion),N=ce(_=>_.setNotifyOnQuestion),k=ce(_=>_.notificationTemplates),g=ce(_=>_.setNotificationTemplates),[E,O]=o.useState("default"),[I,w]=o.useState(!1),[m,y]=o.useState(!1),[K,C]=o.useState(!1);o.useEffect(()=>{if(!i){w(!1),y(!1);return}typeof Notification<"u"&&O(Notification.permission);const _=typeof window<"u"&&"serviceWorker"in navigator&&"PushManager"in window&&"Notification"in window;w(_),(async()=>{if(!_){y(!1);return}try{const z=await navigator.serviceWorker.getRegistration();if(!z){y(!1);return}const U=await z.pushManager.getSubscription();y(!!U)}catch{y(!1)}})()},[i]);const T=async _=>{if(e){l(_);return}if(!i){l(_);return}if(_&&typeof Notification<"u"&&Notification.permission==="default")try{const V=await Notification.requestPermission();O(V),V==="granted"?l(!0):D.error(t("settings.notifications.page.toast.permissionDenied.title"),{description:t("settings.notifications.page.toast.permissionDenied.description")})}catch(V){console.error("Failed to request notification permission:",V),D.error(t("settings.notifications.page.toast.requestPermissionFailed"))}else l(!!(_&&E==="granted"))},j=e||a||n||i&&typeof Notification<"u"&&Notification.permission==="granted",R=(_,V,z)=>{g(U=>({...U,[_]:{...U[_],[V]:z}}))},G=_=>{const V="=".repeat((4-_.length%4)%4),z=(_+V).replace(/-/g,"+").replace(/_/g,"/"),U=atob(z),X=new Uint8Array(U.length);for(let Z=0;Z<U.length;Z+=1)X[Z]=U.charCodeAt(Z);return X},S=async(_,V,z)=>{let U=null;const X=new Promise((Z,ne)=>{U=setTimeout(()=>{ne(new Error(z))},V)});try{return await Promise.race([_,X])}finally{U&&clearTimeout(U)}},q=async _=>{if(_.active)return;const V=_.installing||_.waiting;V&&V.state!=="activated"&&await S(new Promise(z=>{const U=()=>{V.state==="activated"&&(V.removeEventListener("statechange",U),z())};V.addEventListener("statechange",U),U()}),15e3,"Service worker activation timed out")},Q=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 V=null;for(const z of _)try{const U=z.opts?navigator.serviceWorker.register("/sw.js",z.opts):navigator.serviceWorker.register("/sw.js");return await S(U,1e4,`Service worker registration timed out (${z.label})`)}catch(U){V=U}throw V instanceof Error?V:new Error("Service worker registration failed")},M=async()=>{if(!("serviceWorker"in navigator))throw new Error("Service worker not supported");const _=await navigator.serviceWorker.getRegistration();if(_)return _;const V=await Q();try{await V.update()}catch{}return await q(V),V},W=_=>{const V=_,z=[`type=${typeof _}`,`toString=${String(_)}`,`name=${String(V?.name??"")}`,`message=${String(V?.message??"")}`];let U="";try{U=JSON.stringify(_)}catch{}return{summary:z.filter(Boolean).join(" | "),json:U,stack:typeof V?.stack=="string"?V.stack:""}},Y=async()=>{const _=In();if(!_?.notifications){D.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"})?D.success(t("settings.notifications.page.toast.testNotificationSent")):D.error(t("settings.notifications.page.toast.testNotificationFailed"))}catch(V){console.error("Test notification failed:",V),D.error(t("settings.notifications.page.toast.testNotificationFailed"))}},F=async()=>{if(!I){D.error(t("settings.notifications.page.toast.pushUnsupported"));return}const _=In();if(!_?.push){D.error(t("settings.notifications.page.toast.pushApiUnavailable"));return}C(!0);try{if(typeof Notification<"u"&&Notification.permission==="default"){const re=await Notification.requestPermission();if(O(re),re!=="granted"){D.error(t("settings.notifications.page.toast.permissionDenied.title"),{description:t("settings.notifications.page.toast.permissionDenied.enableInBrowser")});return}}if(typeof Notification<"u"&&Notification.permission!=="granted"){D.error(t("settings.notifications.page.toast.permissionDenied.title"),{description:t("settings.notifications.page.toast.permissionDenied.enableInBrowser")});return}const V=await _.push.getVapidPublicKey();if(!V?.publicKey){D.error(t("settings.notifications.page.toast.pushKeyLoadFailed"));return}const z=await M();await q(z);const U=await z.pushManager.getSubscription();if(!("pushManager"in z)||!z.pushManager)throw new Error("PushManager unavailable (requires installed PWA + iOS 16.4+)");const Z=(U??await S(z.pushManager.subscribe({userVisibleOnly:!0,applicationServerKey:G(V.publicKey)}),15e3,"Push subscription timed out")).toJSON(),ne=Z.keys;if(!Z.endpoint||!ne?.p256dh||!ne.auth)throw new Error("Push subscription missing keys");if(!(await S(_.push.subscribe({endpoint:Z.endpoint,keys:{p256dh:ne.p256dh,auth:ne.auth},origin:typeof window<"u"?window.location.origin:void 0,platform:yd()}),15e3,"Push subscribe request timed out"))?.ok){D.error(t("settings.notifications.page.toast.enableBackgroundFailed"));return}y(!0),D.success(t("settings.notifications.page.toast.backgroundEnabled"))}catch(V){console.error("[Push] Enable failed:",V);const z=W(V);D.error(t("settings.notifications.page.toast.enableBackgroundFailed"),{description:z.summary})}finally{C(!1)}},se=async()=>{if(!I){y(!1);return}const _=In();if(!_?.push){D.error(t("settings.notifications.page.toast.pushApiUnavailable"));return}C(!0);try{const z=await(await M()).pushManager.getSubscription();if(!z){y(!1);return}const U=z.endpoint;await z.unsubscribe(),await _.push.unsubscribe({endpoint:U}),y(!1),D.success(t("settings.notifications.page.toast.backgroundDisabled"))}finally{C(!1)}};return s.jsxs(s.Fragment,{children:[s.jsxs(Be,{settingsItem:"notifications.delivery",title:t("settings.notifications.page.delivery.title"),divider:!1,children:[s.jsxs("div",{className:Ns,children:[s.jsx(ht,{checked:r&&j,onChange:_=>{T(_)},label:t("settings.notifications.page.delivery.enableLabel"),info:i?t("settings.notifications.page.delivery.browserPermissionHint"):a?t("settings.notifications.page.delivery.vscodeHint"):void 0,ariaLabel:t("settings.notifications.page.delivery.enableAria")}),r&&j&&!n&&s.jsxs(s.Fragment,{children:[s.jsx(ht,{checked:h==="always",onChange:_=>d(_?"always":"hidden-only"),label:t("settings.notifications.page.delivery.focusedLabel"),ariaLabel:t("settings.notifications.page.delivery.focusedAria")}),s.jsx("div",{className:"py-2",children:s.jsx(B,{type:"button",variant:"outline",size:"sm",onClick:()=>{Y()},children:t("settings.notifications.page.delivery.testAction")})})]})]}),i&&s.jsxs("div",{className:"mt-1",children:[E==="denied"&&s.jsx("p",{className:"typography-meta text-[var(--status-error)] mt-1",children:t("settings.notifications.page.delivery.permissionDenied")}),E==="granted"&&!r&&s.jsx("p",{className:"typography-meta text-muted-foreground/70 mt-1",children:t("settings.notifications.page.delivery.permissionGrantedButDisabled")})]})]}),r&&j&&s.jsxs(s.Fragment,{children:[s.jsx(Be,{settingsItem:"notifications.events",title:t("settings.notifications.page.events.title"),children:s.jsxs("div",{className:Ns,children:[s.jsx(ht,{checked:v,onChange:p,label:t("settings.notifications.page.events.completionLabel"),ariaLabel:t("settings.notifications.page.events.completionAria")}),s.jsx(ht,{checked:x,onChange:c,label:t("settings.notifications.page.events.subtaskLabel"),ariaLabel:t("settings.notifications.page.events.subtaskAria")}),s.jsx(ht,{checked:A,onChange:b,label:t("settings.notifications.page.events.errorLabel"),ariaLabel:t("settings.notifications.page.events.errorAria")}),s.jsx(ht,{checked:P,onChange:N,label:t("settings.notifications.page.events.questionLabel"),ariaLabel:t("settings.notifications.page.events.questionAria")})]})}),!n&&s.jsx(Be,{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(Nn,{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(en,{className:"capitalize",children:t(Ph[_])}),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(Ye,{value:k[_].title,onChange:V=>R(_,"title",V.target.value),className:"h-7",placeholder:t(Ho[_].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(Ye,{value:k[_].message,onChange:V=>R(_,"message",V.target.value),className:"h-7",placeholder:t(Ho[_].messageKey)})]})]})]},_))})})]}),i&&s.jsx(Be,{settingsItem:"notifications.push",title:t("settings.notifications.page.push.title"),children:s.jsx(ht,{checked:I?m:!1,disabled:!I||K,onChange:_=>{_?F():se()},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:K?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})})]})},Ds=t=>{if(!t)return;t.pause();const{src:e}=t;e.startsWith("blob:")&&URL.revokeObjectURL(e),t.removeAttribute("src"),t.load()},Ah=[{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"}],Go=t=>{const e=mt.c(8),{value:a,label:n}=t,i=`${n}: ${a}/5`,r=`${a/5*100}%`;let l;e[0]!==r?(l=s.jsx("span",{className:"h-1.5 w-12 flex-shrink-0 overflow-hidden rounded-full bg-[var(--interactive-border)]","aria-hidden":"true",children:s.jsx("span",{className:"block h-full rounded-full bg-[var(--primary-base)]",style:{width:r}})}),e[0]=r,e[1]=l):l=e[1];let h;e[2]!==n?(h=s.jsx("span",{className:"typography-ui-compact text-muted-foreground",children:n}),e[2]=n,e[3]=h):h=e[3];let d;return e[4]!==i||e[5]!==l||e[6]!==h?(d=s.jsxs("span",{className:"flex items-center gap-1.5",title:i,children:[l,h]}),e[4]=i,e[5]=l,e[6]=h,e[7]=d):d=e[7],d},Eh=({selectedModelId:t,onSelect:e})=>{const{t:a}=ot(),n=Xe.useCallback(p=>a(p),[a]),[i,r]=Xe.useState(new Map),[l,h]=Xe.useState(null),d=Xe.useCallback(async()=>{try{const p=await pt("/api/dictation/status",{query:{provider:"local"}});if(!p.ok)return;const A=await p.json();Array.isArray(A?.models)&&r(new Map(A.models.map(b=>[b.id,b])))}catch{}},[]);Xe.useEffect(()=>{d()},[d]);const x=Array.from(i.values()).some(p=>p.downloading);Xe.useEffect(()=>{if(!x)return;const p=setInterval(()=>{d()},2e3);return()=>clearInterval(p)},[x,d]);const c=async p=>{h(p);try{await pt(`/api/dictation/models/${encodeURIComponent(p)}/download`,{method:"POST"}),await d()}catch{}finally{h(null)}},v=async p=>{h(p);try{await pt(`/api/dictation/models/${encodeURIComponent(p)}`,{method:"DELETE"}),await d()}catch{}finally{h(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:Ah.map(p=>{const A=t===p.id,b=i.get(p.id)??null;return s.jsx("div",{className:je("rounded-lg border border-[var(--interactive-border)] p-3",A&&"border-[var(--primary-base)] bg-[var(--primary-base)]/5"),children:s.jsxs("div",{className:"flex items-start justify-between gap-2",children:[s.jsxs("div",{className:"flex min-w-0 flex-1 cursor-pointer items-start gap-2",role:"button",tabIndex:0,onClick:()=>e(p.id),onKeyDown:P=>{(P.key===" "||P.key==="Enter")&&(P.preventDefault(),e(p.id))},children:[s.jsx("div",{className:"pt-0.5",children:s.jsx(dr,{checked:A,onChange:()=>e(p.id),ariaLabel:n(p.labelKey)})}),s.jsxs("div",{className:"min-w-0 flex-1 space-y-2",children:[s.jsxs("div",{className:"flex flex-wrap items-center gap-2",children:[s.jsx("span",{className:je("typography-ui-label font-normal",A?"text-foreground":"text-foreground/50"),children:n(p.labelKey)}),p.badgeKey?s.jsx("span",{className:"rounded border border-[var(--status-success-border)] bg-[var(--status-success-background)] px-1 text-[9px] font-medium uppercase leading-[14px] tracking-wide text-[var(--status-success)]",children:n(p.badgeKey)}):null]}),s.jsxs("div",{className:"flex flex-col gap-1.5",children:[s.jsx(Go,{value:p.accuracy,label:a("settings.voice.page.stt.meta.accuracy")}),s.jsx(Go,{value:p.speed,label:a("settings.voice.page.stt.meta.speed")}),s.jsx("span",{className:"typography-ui-compact tabular-nums text-muted-foreground",children:p.size})]}),b?.downloadError?s.jsx("p",{className:"typography-meta text-[var(--status-error)]",children:b.downloadError}):null]})]}),s.jsx("div",{className:"flex shrink-0 items-center gap-1",children:b?.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===p.id,onClick:()=>{v(p.id)},title:a("settings.voice.page.stt.modelDelete"),"aria-label":a("settings.voice.page.stt.modelDelete"),children:s.jsx(L,{name:"delete-bin",className:"h-4 w-4"})}),s.jsx(L,{name:"checkbox-circle",className:"h-4 w-4 flex-shrink-0 text-[var(--status-success)]","aria-label":a("settings.voice.page.stt.modelInstalled")})]}):b?.downloading?s.jsxs("span",{className:"flex items-center gap-1.5",children:[s.jsx(L,{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 b.downloadProgress=="number"?`${b.downloadProgress}%`:""})]}):s.jsx(B,{variant:"ghost",size:"xs",className:"h-6 w-6 p-0",disabled:l===p.id,onClick:()=>{c(p.id)},title:a("settings.voice.page.stt.modelDownload"),"aria-label":a("settings.voice.page.stt.modelDownload"),children:s.jsx(L,{name:"download",className:"h-4 w-4"})})})]})},p.id)})})},Hi=[{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)"}],Gi="kokoro-en-v0_19",Th=()=>{const{t}=ot(),[e,a]=Xe.useState(null),[n,i]=Xe.useState(!1),r=Xe.useCallback(async()=>{try{const h=await pt("/api/dictation/status",{query:{provider:"local"}});if(!h.ok)return;const d=await h.json(),x=Array.isArray(d?.ttsModels)?d.ttsModels.find(c=>c.id===Gi):null;x&&a(x)}catch{}},[]);Xe.useEffect(()=>{r()},[r]),Xe.useEffect(()=>{if(!e?.downloading)return;const h=setInterval(()=>{r()},2e3);return()=>clearInterval(h)},[e?.downloading,r]);const l=async h=>{i(!0);try{const d=h==="POST"?`/api/dictation/models/${Gi}/download`:`/api/dictation/models/${Gi}`;await pt(d,{method:h}),await r()}catch{}finally{i(!1)}};return e?s.jsxs("div",{className:"flex items-center gap-2 py-1.5",children:[s.jsx("span",{className:"typography-ui-label text-foreground",children:"Kokoro"}),s.jsx("span",{className:"typography-ui-compact tabular-nums text-muted-foreground",children:"305 MB"}),e.installed?s.jsxs(s.Fragment,{children:[s.jsx(L,{name:"checkbox-circle",className:"h-4 w-4 text-[var(--status-success)]","aria-label":t("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,onClick:()=>{l("DELETE")},title:t("settings.voice.page.stt.modelDelete"),"aria-label":t("settings.voice.page.stt.modelDelete"),children:s.jsx(L,{name:"delete-bin",className:"h-4 w-4"})})]}):e.downloading?s.jsxs("span",{className:"flex items-center gap-1.5",children:[s.jsx(L,{name:"loader-4",className:"h-3.5 w-3.5 animate-spin text-muted-foreground"}),s.jsx("span",{className:"typography-ui-compact tabular-nums text-muted-foreground",children:typeof e.downloadProgress=="number"?`${e.downloadProgress}%`:""})]}):s.jsx(B,{variant:"ghost",size:"xs",className:"h-6 w-6 p-0",disabled:n,onClick:()=>{l("POST")},title:t("settings.voice.page.stt.modelDownload"),"aria-label":t("settings.voice.page.stt.modelDownload"),children:s.jsx(L,{name:"download",className:"h-4 w-4"})}),e.downloadError?s.jsx("span",{className:"typography-meta text-[var(--status-error)]",children:e.downloadError}):null]}):null},Dh=[{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"}],Mh=()=>{const{t}=ot(),{isMobile:e}=da(),a=tt(H=>H.voiceProvider),n=tt(H=>H.setVoiceProvider),i=tt(H=>H.speechRate),r=tt(H=>H.setSpeechRate),l=tt(H=>H.speechPitch),h=tt(H=>H.setSpeechPitch),d=tt(H=>H.speechVolume),x=tt(H=>H.setSpeechVolume),c=tt(H=>H.sayVoice),v=tt(H=>H.setSayVoice),p=tt(H=>H.localTtsVoiceId),A=tt(H=>H.setLocalTtsVoiceId),{speak:b,stop:P,isPlaying:N,error:k}=Bc(),g=Xe.useCallback(()=>{if(N){P();return}const H=Hi.find(He=>He.id===p)?.label??String(p);b(t("settings.voice.page.preview.voiceLine",{voiceName:H}),{speakerId:p,speed:tt.getState().speechRate})},[N,p,b,P,t]),E=tt(H=>H.browserVoice),O=tt(H=>H.setBrowserVoice),I=tt(H=>H.openaiVoice),w=tt(H=>H.setOpenaiVoice),m=tt(H=>H.openaiApiKey),y=tt(H=>H.setOpenaiApiKey),K=tt(H=>H.openaiCompatibleUrl),C=tt(H=>H.setOpenaiCompatibleUrl),T=tt(H=>H.openaiCompatibleApiKey),j=tt(H=>H.setOpenaiCompatibleApiKey),R=tt(H=>H.openaiCompatibleVoice),G=tt(H=>H.setOpenaiCompatibleVoice),S=tt(H=>H.openaiCompatibleTtsModel),q=tt(H=>H.setOpenaiCompatibleTtsModel),Q=tt(H=>H.showMessageTTSButtons),M=tt(H=>H.ttsInputMode),W=tt(H=>H.setTtsInputMode),Y=tt(H=>H.sttProvider),F=tt(H=>H.setSttProvider),se=tt(H=>H.sttServerUrl),_=tt(H=>H.setSttServerUrl),V=tt(H=>H.sttApiKey),z=tt(H=>H.setSttApiKey),U=tt(H=>H.sttModel),X=tt(H=>H.setSttModel),Z=tt(H=>H.sttLocalModel),ne=tt(H=>H.setSttLocalModel),le=tt(H=>H.sttLanguage),re=tt(H=>H.setSttLanguage),fe=tt(H=>H.setShowMessageTTSButtons),ae=tt(H=>H.dictationEnabled),ie=tt(H=>H.setDictationEnabled),[te,ye]=Xe.useState(!1),[we,ke]=Xe.useState([]),[xe,De]=Xe.useState(!1),[Me,he]=Xe.useState(null),[ge,Ae]=Xe.useState(!1),[Ve,_e]=Xe.useState(!1),[Le,Re]=Xe.useState(null),[Ze,Ge]=Xe.useState(!1),[Oe,Ke]=Xe.useState(null),[Pe,Ue]=Xe.useState([]),[ve,We]=Xe.useState(!1);Xe.useEffect(()=>((async()=>{const He=await Ei.waitForVoices();Ue(He)})(),"speechSynthesis"in window&&(window.speechSynthesis.onvoiceschanged=()=>{Ue(window.speechSynthesis.getVoices())}),()=>{"speechSynthesis"in window&&(window.speechSynthesis.onvoiceschanged=null)}),[]);const $=Xe.useMemo(()=>Pe.filter(H=>H.lang).sort((H,He)=>{const et=H.lang.startsWith("en"),ze=He.lang.startsWith("en");if(et&&!ze)return-1;if(!et&&ze)return 1;const st=H.lang.localeCompare(He.lang);return st!==0?st:H.name.localeCompare(He.name)}),[Pe]),de=Xe.useCallback(()=>{if(ve){Ei.cancelSpeech(),We(!1);return}const H=Pe.find(st=>st.name===E),He=H?.name??t("settings.voice.page.preview.browserVoiceFallback"),et=t("settings.voice.page.preview.voiceLine",{voiceName:He});We(!0);const ze=new SpeechSynthesisUtterance(et);ze.rate=i,ze.pitch=l,ze.volume=d,H&&(ze.voice=H,ze.lang=H.lang),ze.onend=()=>We(!1),ze.onerror=()=>We(!1),window.speechSynthesis.cancel(),window.speechSynthesis.speak(ze)},[E,Pe,i,l,d,ve,t]);Xe.useEffect(()=>()=>{ve&&Ei.cancelSpeech()},[ve]),Xe.useEffect(()=>{if(!Q||a!=="openai"&&a!=="openai-compatible"){Ae(m.trim().length>0);return}(async()=>{try{const ze=(await(await pt("/api/tts/status")).json()).available,st=m.trim().length>0;Ae(ze||st)}catch{Ae(m.trim().length>0)}})()},[m,Q,a]),Xe.useEffect(()=>{if(!Q){ye(!1),ke([]);return}pt("/api/tts/say/status").then(H=>H.json()).then(H=>{if(ye(H.available),H.voices){const He=H.voices.filter((et,ze,st)=>st.findIndex(wt=>wt.name===et.name)===ze).sort((et,ze)=>et.name.localeCompare(ze.name));ke(He)}}).catch(()=>{ye(!1)})},[Q]);const ue=Xe.useCallback(async()=>{if(Me){Ds(Me),he(null),De(!1);return}De(!0);let H=null;try{const He=await pt("/api/tts/say/speak",{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify({text:t("settings.voice.page.preview.voiceLine",{voiceName:c}),voice:c,rate:Math.round(100+(i-.5)*200)})});if(!He.ok)throw new Error("Preview failed");const et=await He.blob(),ze=URL.createObjectURL(et);H=new Audio(ze),H.onended=()=>{Ds(H),he(null),De(!1)},H.onerror=()=>{Ds(H),he(null),De(!1)},he(H),await H.play()}catch{Ds(H),he(null),De(!1)}},[c,i,Me,t]);Xe.useEffect(()=>()=>{Ds(Me)},[Me]);const Ne=Xe.useCallback(async()=>{if(Le){Ds(Le),Re(null),_e(!1);return}_e(!0);let H=null;try{const He=await pt("/api/tts/speak",{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify({text:t("settings.voice.page.preview.voiceLine",{voiceName:I}),voice:I,speed:i,apiKey:m||void 0})});if(!He.ok){const st=await He.json().catch(()=>({error:"Unknown error"}));throw new Error(st.error||`HTTP ${He.status}`)}const et=await He.blob(),ze=URL.createObjectURL(et);H=new Audio(ze),H.onended=()=>{Ds(H),Re(null),_e(!1)},H.onerror=()=>{Ds(H),Re(null),_e(!1)},Re(H),await H.play()}catch{Ds(H),Re(null),_e(!1)}},[I,i,Le,m,t]);Xe.useEffect(()=>()=>{Ds(Le)},[Le]);const pe=Xe.useCallback(async()=>{if(Oe){Ds(Oe),Ke(null),Ge(!1);return}if(!K.trim())return;Ge(!0);let H=null;try{const He=await pt("/api/tts/speak",{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify({text:t("settings.voice.page.preview.customServerLine"),voice:R,model:S||void 0,speed:i,baseURL:K,apiKey:T||void 0})});if(!He.ok){const st=await He.json().catch(()=>({error:"Unknown error"}));throw new Error(st.error||`HTTP ${He.status}`)}const et=await He.blob(),ze=URL.createObjectURL(et);H=new Audio(ze),H.onended=()=>{Ds(H),Ke(null),Ge(!1)},H.onerror=()=>{Ds(H),Ke(null),Ge(!1)},Ke(H),await H.play()}catch{Ds(H),Ke(null),Ge(!1)}},[K,R,S,T,i,Oe,t]);Xe.useEffect(()=>()=>{Ds(Oe)},[Oe]);const Fe="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(Be,{settingsItem:"voice.playback",title:t("settings.voice.page.section.playbackAndSummary"),divider:!1,contentClassName:"space-y-4",children:[s.jsx(ht,{checked:Q,onChange:fe,label:t("settings.voice.page.field.messageReadAloudButton"),ariaLabel:t("settings.voice.page.field.messageReadAloudButtonAria")}),Q&&s.jsxs(s.Fragment,{children:[s.jsx(_s,{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(Js,{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")},...te?[{value:"say",label:s.jsxs(s.Fragment,{children:[s.jsx(L,{name:"apple",className:"mr-0.5 h-3.5 w-3.5"}),t("settings.voice.page.provider.say")]})}]:[]]})}),a==="openai"&&s.jsxs("div",{className:"space-y-1.5",children:[s.jsx("span",{className:je(Rt,!ge&&"text-[var(--status-error)]"),children:t("settings.voice.page.field.apiKey")}),s.jsx("span",{className:je(Ln,!ge&&"text-[var(--status-error)]/80"),children:t(ge&&!m?"settings.voice.page.field.apiKeyHintUsingConfig":ge?"settings.voice.page.field.apiKeyHintProvide":"settings.voice.page.field.apiKeyHintRequired")}),s.jsxs("div",{className:je("relative",Ks),children:[s.jsx("input",{type:"password",value:m,onChange:H=>y(H.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"}),m&&s.jsx("button",{type:"button",onClick:()=>y(""),className:"absolute right-2 top-1/2 -translate-y-1/2 text-muted-foreground hover:text-foreground",children:s.jsx(L,{name:"close",className:"w-3.5 h-3.5"})})]})]}),a==="openai-compatible"&&s.jsxs("div",{className:"space-y-3",children:[s.jsxs("div",{className:"space-y-1.5",children:[s.jsxs("span",{className:"flex items-center gap-1.5",children:[s.jsx("span",{className:je(Rt,!K.trim()&&"text-[var(--status-error)]"),children:t("settings.voice.page.field.serverUrl")}),s.jsx(ss,{children:t("settings.voice.page.field.serverUrlHint")})]}),s.jsxs("div",{className:je("relative",Ks),children:[s.jsx("input",{type:"text",value:K,onChange:H=>C(H.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:()=>C(""),className:"absolute right-2 top-1/2 -translate-y-1/2 text-muted-foreground hover:text-foreground",children:s.jsx(L,{name:"close",className:"w-3.5 h-3.5"})})]})]}),s.jsxs("div",{className:"space-y-1.5",children:[s.jsx("span",{className:Rt,children:"API Key"}),s.jsx("span",{className:Ln,children:"Optional"}),s.jsxs("div",{className:je("relative",Ks),children:[s.jsx("input",{type:"password",value:T,onChange:H=>j(H.target.value),placeholder:"sk-...",className:"w-full h-7 rounded-lg border border-input bg-transparent px-2 typography-ui-label text-foreground placeholder:text-muted-foreground focus:outline-none focus:ring-1 focus:ring-primary/50 focus:border-primary/70"}),T&&s.jsx("button",{type:"button",onClick:()=>j(""),className:"absolute right-2 top-1/2 -translate-y-1/2 text-muted-foreground hover:text-foreground",children:s.jsx(L,{name:"close",className:"w-3.5 h-3.5"})})]})]}),s.jsxs("div",{className:"space-y-1.5",children:[s.jsx("span",{className:Rt,children:t("settings.voice.page.field.model")}),s.jsx("div",{className:je("relative",Ks),children:s.jsx("input",{type:"text",value:S,onChange:H=>q(H.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:Rt,children:t("settings.voice.page.field.voice")}),s.jsx(ss,{children:t("settings.voice.page.field.voiceIdentifierHint")})]}),s.jsxs("div",{className:je("flex items-center gap-2",Ks),children:[s.jsx("div",{className:"relative min-w-0 flex-1",children:s.jsx("input",{type:"text",value:R,onChange:H=>G(H.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:pe,title:t("settings.voice.page.actions.preview"),disabled:!K.trim(),children:Ze?s.jsx(L,{name:"stop",className:"w-3.5 h-3.5"}):s.jsx(L,{name:"play",className:"w-3.5 h-3.5"})})]})]})]}),a==="local"&&s.jsx(Th,{}),s.jsxs(Qt,{label:t("settings.voice.page.field.voice"),children:[a==="local"&&s.jsxs(s.Fragment,{children:[s.jsxs(Ot,{value:String(p),onValueChange:H=>A(Number.parseInt(H,10)||0),children:[s.jsx(Lt,{size:Jt,className:Pn,children:s.jsx(Ht,{placeholder:t("settings.voice.page.field.selectVoicePlaceholder"),children:H=>Hi.find(He=>String(He.id)===H)?.label??H})}),s.jsx(Ft,{children:Hi.map(H=>s.jsx(ut,{value:String(H.id),children:H.label},H.id))})]}),s.jsx(B,{size:"xs",variant:"ghost",onClick:g,title:t("settings.voice.page.actions.preview"),children:N?s.jsx(L,{name:"stop",className:"w-3.5 h-3.5"}):s.jsx(L,{name:"play",className:"w-3.5 h-3.5"})}),k?s.jsx("span",{className:"typography-meta text-[var(--status-error)]",children:k}):null]}),a==="openai"&&ge&&s.jsxs(s.Fragment,{children:[s.jsxs(Ot,{value:I,onValueChange:w,children:[s.jsx(Lt,{size:Jt,className:Pn,children:s.jsx(Ht,{placeholder:t("settings.voice.page.field.selectVoicePlaceholder")})}),s.jsx(Ft,{children:Dh.map(H=>s.jsx(ut,{value:H.value,children:H.label},H.value))})]}),s.jsx(B,{size:"xs",variant:"ghost",onClick:Ne,title:t("settings.voice.page.actions.preview"),children:Ve?s.jsx(L,{name:"stop",className:"w-3.5 h-3.5"}):s.jsx(L,{name:"play",className:"w-3.5 h-3.5"})})]}),a==="openai-compatible"&&s.jsx("span",{className:Ln,children:t("settings.voice.page.field.configuredAbove")}),a==="say"&&te&&we.length>0&&s.jsxs(s.Fragment,{children:[s.jsxs(Ot,{value:c,onValueChange:v,children:[s.jsx(Lt,{size:Jt,className:Pn,children:s.jsx(Ht,{placeholder:t("settings.voice.page.field.selectVoicePlaceholder")})}),s.jsx(Ft,{children:we.map(H=>s.jsx(ut,{value:H.name,children:H.name},H.name))})]}),s.jsx(B,{size:"xs",variant:"ghost",onClick:ue,title:t("settings.voice.page.actions.preview"),children:xe?s.jsx(L,{name:"stop",className:"w-3.5 h-3.5"}):s.jsx(L,{name:"play",className:"w-3.5 h-3.5"})})]}),a==="browser"&&$.length>0&&s.jsxs(s.Fragment,{children:[s.jsxs(Ot,{value:E||"$auto",onValueChange:H=>O(H==="$auto"?"":H),children:[s.jsx(Lt,{size:Jt,className:Pn,children:s.jsx(Ht,{placeholder:t("settings.voice.page.field.auto")})}),s.jsxs(Ft,{children:[s.jsx(ut,{value:"$auto",children:t("settings.voice.page.field.auto")}),$.map(H=>s.jsxs(ut,{value:H.name,children:[H.name," (",H.lang,")"]},H.name))]})]}),s.jsx(B,{size:"xs",variant:"ghost",onClick:de,title:t("settings.voice.page.actions.preview"),children:ve?s.jsx(L,{name:"stop",className:"w-3.5 h-3.5"}):s.jsx(L,{name:"play",className:"w-3.5 h-3.5"})})]})]}),s.jsxs(Qt,{label:t("settings.voice.page.field.speechRate"),children:[!e&&s.jsx("input",{type:"range",min:.5,max:2,step:.1,value:i,onChange:H=>r(Number(H.target.value)),className:Fe}),s.jsx(Is,{value:i,onValueChange:r,min:.5,max:2,step:.1,className:"w-16 tabular-nums"})]}),s.jsxs(Qt,{label:t("settings.voice.page.field.speechPitch"),children:[!e&&s.jsx("input",{type:"range",min:.5,max:2,step:.1,value:l,onChange:H=>h(Number(H.target.value)),className:Fe}),s.jsx(Is,{value:l,onValueChange:h,min:.5,max:2,step:.1,className:"w-16 tabular-nums"})]}),s.jsxs(Qt,{label:t("settings.voice.page.field.speechVolume"),children:[!e&&s.jsx("input",{type:"range",min:0,max:1,step:.1,value:d,onChange:H=>x(Number(H.target.value)),className:Fe}),e?s.jsx(Is,{value:Math.round(d*100),onValueChange:H=>x(H/100),min:0,max:100,step:10,className:"w-16 tabular-nums"}):s.jsxs("span",{className:"typography-ui-label text-foreground tabular-nums min-w-[3rem] text-right",children:[Math.round(d*100),"%"]})]}),s.jsx(_s,{title:t("settings.voice.page.field.ttsInputMode"),children:s.jsx(Js,{value:M,onChange:W,"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(Be,{settingsItem:"voice.speech-recognition",title:t("settings.voice.page.section.speechRecognition"),contentClassName:"space-y-4",children:[s.jsx(ht,{checked:ae,onChange:ie,label:t("settings.voice.page.field.enableVoiceInput"),ariaLabel:t("settings.voice.page.field.enableVoiceInputAria")}),ae&&s.jsxs(s.Fragment,{children:[s.jsx(_s,{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(Js,{value:Y,onChange:F,"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")}]})}),Y==="local"&&s.jsxs("div",{className:"space-y-1.5",children:[s.jsx("span",{className:Rt,children:t("settings.voice.page.field.model")}),s.jsx(Eh,{selectedModelId:Z,onSelect:ne})]}),Y==="openai-compatible"&&s.jsxs("div",{className:"space-y-3",children:[s.jsxs("div",{className:"space-y-1.5",children:[s.jsxs("span",{className:"flex items-center gap-1.5",children:[s.jsx("span",{className:je(Rt,!se.trim()&&"text-[var(--status-error)]"),children:t("settings.voice.page.field.serverUrl")}),s.jsx(ss,{children:t("settings.voice.page.field.sttServerUrlHint")})]}),s.jsxs("div",{className:je("relative",Ks),children:[s.jsx("input",{type:"text",value:se,onChange:H=>_(H.target.value),placeholder:"http://localhost:8001/v1",className:"w-full h-7 rounded-lg border border-input bg-transparent px-2 typography-ui-label text-foreground placeholder:text-muted-foreground focus:outline-none focus:ring-1 focus:ring-primary/50 focus:border-primary/70"}),se&&s.jsx("button",{type:"button",onClick:()=>_(""),className:"absolute right-2 top-1/2 -translate-y-1/2 text-muted-foreground hover:text-foreground",children:s.jsx(L,{name:"close",className:"w-3.5 h-3.5"})})]})]}),s.jsxs("div",{className:"space-y-1.5",children:[s.jsx("span",{className:Rt,children:"API Key"}),s.jsx("span",{className:Ln,children:"Optional"}),s.jsxs("div",{className:je("relative",Ks),children:[s.jsx("input",{type:"password",value:V,onChange:H=>z(H.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:()=>z(""),className:"absolute right-2 top-1/2 -translate-y-1/2 text-muted-foreground hover:text-foreground",children:s.jsx(L,{name:"close",className:"w-3.5 h-3.5"})})]})]}),s.jsxs("div",{className:"space-y-1.5",children:[s.jsx("span",{className:Rt,children:t("settings.voice.page.field.model")}),s.jsx("div",{className:je("relative",Ks),children:s.jsx("input",{type:"text",value:U,onChange:H=>X(H.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:Rt,children:t("settings.voice.page.field.language")}),s.jsx(ss,{children:t("settings.voice.page.field.sttLanguageHint")})]}),s.jsx("div",{className:"relative max-w-[8rem]",children:s.jsx("input",{type:"text",value:le,onChange:H=>re(H.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"})})]})]})]})]})]})},Za=[{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}],Xa=[{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}],Rh="https://developers.cloudflare.com/cloudflare-one/networks/connectors/cloudflare-tunnel/get-started/create-remote-tunnel/",Oh="https://developers.cloudflare.com/cloudflare-one/networks/connectors/cloudflare-tunnel/do-more-with-tunnels/local-management/configuration-file/",qi=[{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"}],Lh=[".yml",".yaml",".json"],Fh="settings.openchamber.tunnel.error.invalidConfigExtension",Ca=t=>{const e=t.trim().toLowerCase();return Lh.some(a=>e.endsWith(a))},Kh=t=>t==="ngrok"?"ngrok":"cloudflared",Hl=()=>{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"},Uh=(t,e=Hl())=>t==="ngrok"?e==="win32"?"winget install ngrok -s msstore":e==="darwin"?"brew install ngrok":"https://ngrok.com/download":e==="win32"?"winget install --id Cloudflare.cloudflared":e==="darwin"?"brew install cloudflared":"https://developers.cloudflare.com/cloudflare-one/networks/connectors/cloudflared/downloads/",Wi=(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():Kh(a),i=typeof e?.platform=="string"&&e.platform.trim().length>0?e.platform.trim():Hl(),r=typeof e?.installCommand=="string"&&e.installCommand.trim().length>0?e.installCommand.trim():Uh(a,i);return{provider:a,dependency:n,installCommand:r}},Gl=t=>t==="cloudflare"?"Cloudflare":t==="ngrok"?"Ngrok":t,qo=t=>{const e=mt.c(11),{provider:a}=t;let n;e[0]!==a?(n=Gl(a),e[0]=a,e[1]=n):n=e[1];const i=n,h=a==="cloudflare"||a==="ngrok"?"text-[var(--status-warning)]":"text-muted-foreground";let d;e[2]!==h?(d=je("size-4 shrink-0",h),e[2]=h,e[3]=d):d=e[3];let x;e[4]!==d?(x=s.jsx(L,{name:"cloud",className:d}),e[4]=d,e[5]=x):x=e[5];let c;e[6]!==i?(c=s.jsx("span",{children:i}),e[6]=i,e[7]=c):c=e[7];let v;return e[8]!==x||e[9]!==c?(v=s.jsxs("span",{className:"flex items-center gap-2",children:[x,c]}),e[8]=x,e[9]=c,e[10]=v):v=e[10],v},jn=t=>t==="quick"?"quick":t==="managed-remote"?"managed-remote":t==="managed-local"?"managed-local":"quick",or=(t,e,a)=>t.find(i=>i.ms===e)?.value||a,Wo=(t,e,a)=>{const n=or(t,e,a);return t.find(i=>i.value===n)?.label||n},Jo=t=>{const e=Math.max(0,t),a=Math.floor(e/1e3),n=Math.floor(a/3600),i=Math.floor(a%3600/60),r=a%60;return n>0?`${n}h ${i}m`:i>0?`${i}m ${r}s`:`${r}s`},zh=(t,e)=>gl(t,e,{hour:"2-digit",precision:"second"}),ai=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()}},_h=t=>{if(!Array.isArray(t))return[];const e=new Set,a=new Set,n=[];for(const i of t){if(!i||typeof i!="object")continue;const r=i,l=typeof r.id=="string"?r.id.trim():"",h=typeof r.name=="string"?r.name.trim():"",d=ai(typeof r.hostname=="string"?r.hostname:"");!l||!h||!d||e.has(l)||a.has(d)||(e.add(l),a.add(d),n.push({id:l,name:h,hostname:d}))}return n},$h=()=>typeof crypto<"u"&&typeof crypto.randomUUID=="function"?crypto.randomUUID():`${Date.now()}-${Math.random().toString(36).slice(2,10)}`,Vh=()=>{const{t}=ot(),e=ce(J=>J.timeFormatPreference),a=o.useCallback(J=>t(J),[t]),[n,i]=o.useState("checking"),[r,l]=o.useState(null),[h,d]=o.useState(null),[x,c]=o.useState(null),[v,p]=o.useState(null),[A,b]=o.useState(null),[P,N]=o.useState(!1),[k,g]=o.useState(!1),[E,O]=o.useState(!1),[I,w]=o.useState("cloudflare"),[m,y]=o.useState(()=>Wi("cloudflare")),[K,C]=o.useState([]),[T,j]=o.useState("quick"),[R,G]=o.useState(null),[S,q]=o.useState([]),[Q,M]=o.useState({}),[W,Y]=o.useState(""),[F,se]=o.useState({}),[_,V]=o.useState(new Set),[z,U]=o.useState(!1),[X,Z]=o.useState(""),[ne,le]=o.useState(""),[re,fe]=o.useState(""),[ae,ie]=o.useState(1800*1e3),[te,ye]=o.useState(480*60*1e3),[we,ke]=o.useState(""),[xe,De]=o.useState([]),[Me,he]=o.useState(()=>Date.now()),[ge,Ae]=o.useState(null),Ve=t(Fh),_e=o.useRef(null),Le=o.useMemo(()=>R?!Ca(R):!1,[R]),Re=o.useMemo(()=>S.find(J=>J.id===W)||S[0]||null,[S,W]),Ze=o.useMemo(()=>xe.map(J=>{const me=J.expiresAt<=Me,Te=J.status==="active"&&!me,Ie=Te?Jo(J.expiresAt-Me):J.inactiveReason==="expired"||me?"expired":"inactive",lt=Ie==="expired"?t("settings.openchamber.tunnel.state.expired"):J.inactiveReason==="tunnel-revoked"?t("settings.openchamber.tunnel.state.revoked"):t("settings.openchamber.tunnel.state.inactive"),at=jn(J.mode);return{...J,isActive:Te,mode:at,remainingTextForSession:Ie,inactiveLabel:lt}}),[Me,xe,t]),Ge=o.useMemo(()=>r?.connectUrl?r.bootstrapExpiresAt===null?!0:r.bootstrapExpiresAt>Me:!1,[Me,r?.bootstrapExpiresAt,r?.connectUrl]),Oe=o.useMemo(()=>!r||n!=="active"&&n!=="stopping"?!1:h===T,[h,n,r,T]),Ke=o.useMemo(()=>!r||n!=="active"||!h?!1:h!==T,[h,n,r,T]),Pe=o.useMemo(()=>{if(typeof ge=="number"&&Number.isFinite(ge)&&ge>0)return ge;if(typeof window>"u")return null;const me=La()||window.location.href;let Te=0;try{Te=Number(new URL(me).port)}catch{Te=Number(window.location.port)}return Number.isFinite(Te)&&Te>0?Te:null},[ge]),Ue=o.useMemo(()=>K.find(J=>J.provider===I)??null,[K,I]),ve=o.useMemo(()=>{const J=new Set(Ue?.modes?.map(me=>me.key).filter(me=>me==="quick"||me==="managed-remote"||me==="managed-local"));return J.size===0?qi:qi.filter(me=>J.has(me.value))},[Ue]),We=o.useMemo(()=>ve.some(J=>J.value==="managed-remote"||J.value==="managed-local"),[ve]),$=o.useMemo(()=>m.provider===I?m:Wi(I),[m,I]),de=o.useCallback(async J=>{await An(J)},[]),ue=o.useCallback((J,me)=>(y(Wi(me,J)),J.available===!0),[]),Ne=o.useCallback(async(J,me)=>{try{const Te=await pt("/api/openchamber/tunnel/check",{query:{provider:J},...me?{signal:me}:{}});if(!Te.ok)return null;const Ie=await Te.json();if(me?.aborted)return null;const lt=ue(Ie,J);return i(at=>at==="checking"||at==="starting"||at==="active"||at==="stopping"?at:lt?"idle":"not-available"),lt}catch{return null}},[ue]),pe=o.useCallback(async J=>{try{const[me,Te,Ie,lt]=await Promise.all([pt("/api/openchamber/tunnel/check",{signal:J}),pt("/api/openchamber/tunnel/status",{signal:J}),pt("/api/config/settings",{signal:J,headers:{Accept:"application/json"}}),pt("/api/openchamber/tunnel/providers",{signal:J})]),at=await me.json(),Je=await Te.json(),Ct=Ie.ok?await Ie.json():{},rs=lt.ok?await lt.json():{},Yt=Je.ttlConfig?.bootstrapTtlMs??(Ct?.tunnelBootstrapTtlMs===null?null:typeof Ct?.tunnelBootstrapTtlMs=="number"?Ct.tunnelBootstrapTtlMs:1800*1e3),ys=typeof Je.ttlConfig?.sessionTtlMs=="number"?Je.ttlConfig.sessionTtlMs:typeof Ct?.tunnelSessionTtlMs=="number"?Ct.tunnelSessionTtlMs:480*60*1e3,$t=jn(Je.mode??Ct?.tunnelMode),cs=typeof Ct?.tunnelProvider=="string"&&Ct.tunnelProvider.trim().length>0?Ct.tunnelProvider.trim().toLowerCase():"cloudflare",Kt=typeof Ct?.managedLocalTunnelConfigPath=="string"&&Ct.managedLocalTunnelConfigPath.trim()||null,ds=ue(at,cs),as=_h(Je?.managedRemoteTunnelPresets),ns=typeof Je.managedRemoteTunnelHostname=="string"?Je.managedRemoteTunnelHostname:"",Zt=as.length>0?as:ns?[{id:`legacy-${ai(ns)}`,name:ns,hostname:ai(ns)}]:[],os=Zt[0]?.id||"";if(ie(Yt),ye(ys),w(cs),C(Array.isArray(rs?.providers)?rs.providers:[]),j($t),G(Kt),q(Zt),Y(os),De(Array.isArray(Je.activeSessions)?Je.activeSessions:[]),d(Je.activeTunnelMode?jn(Je.activeTunnelMode):Je.active&&Je.mode?jn(Je.mode):null),V(new Set(Array.isArray(Je.managedRemoteTunnelTokenPresetIds)?Je.managedRemoteTunnelTokenPresetIds:[])),Ae(typeof Je.localPort=="number"?Je.localPort:null),Je.active&&Je.url){l({url:Je.url,connectUrl:null,bootstrapExpiresAt:typeof Je.bootstrapExpiresAt=="number"?Je.bootstrapExpiresAt:null}),i("active");return}i(ds?"idle":"not-available")}catch{J.aborted||(i("error"),p(t("settings.openchamber.tunnel.toast.checkAvailabilityFailed")))}},[ue,t]);o.useEffect(()=>{const J=new AbortController;return pe(J.signal),()=>J.abort()},[pe]),o.useEffect(()=>{if(!r?.connectUrl){c(null);return}let J=!1;return Nl.toDataURL(r.connectUrl,{width:256,margin:2,color:{dark:"#000000",light:"#ffffff"}}).then(me=>{J||c(me)}).catch(()=>{J||c(null)}),()=>{J=!0}},[r?.connectUrl]),o.useEffect(()=>{if(!r?.bootstrapExpiresAt){ke(t("settings.openchamber.tunnel.state.noExpiry"));return}let J=null,me=Date.now();const Te=()=>{const at=r.bootstrapExpiresAt?r.bootstrapExpiresAt-Date.now():0;at<=0?ke(t("settings.openchamber.tunnel.state.expired")):ke(Jo(at))},Ie=()=>{const at=Date.now();at-me>=1e3&&(Te(),me=at),J=requestAnimationFrame(Ie)};Te(),(typeof document>"u"||document.visibilityState==="visible")&&(J=requestAnimationFrame(Ie));const lt=()=>{document.visibilityState==="visible"&&J===null?J=requestAnimationFrame(Ie):document.visibilityState!=="visible"&&J!==null&&(cancelAnimationFrame(J),J=null)};return document.addEventListener("visibilitychange",lt),()=>{document.removeEventListener("visibilitychange",lt),J!==null&&cancelAnimationFrame(J)}},[t,r?.bootstrapExpiresAt]),o.useEffect(()=>{let J=null,me=Date.now();const Te=()=>{const lt=Date.now();lt-me>=1e3&&(he(lt),me=lt),J=requestAnimationFrame(Te)};(typeof document>"u"||document.visibilityState==="visible")&&(J=requestAnimationFrame(Te));const Ie=()=>{document.visibilityState==="visible"&&J===null?J=requestAnimationFrame(Te):document.visibilityState!=="visible"&&J!==null&&(cancelAnimationFrame(J),J=null)};return document.addEventListener("visibilitychange",Ie),()=>{document.removeEventListener("visibilitychange",Ie),J!==null&&cancelAnimationFrame(J)}},[]),o.useEffect(()=>{if(n==="starting"||n==="stopping"||n==="checking")return;let J=!1;const me=async()=>{try{const Ie=await pt("/api/openchamber/tunnel/status");if(!Ie.ok||J)return;const lt=await Ie.json();if(J)return;De(Array.isArray(lt.activeSessions)?lt.activeSessions:[]),V(new Set(Array.isArray(lt.managedRemoteTunnelTokenPresetIds)?lt.managedRemoteTunnelTokenPresetIds:[])),Ae(typeof lt.localPort=="number"?lt.localPort:null)}catch{}},Te=window.setInterval(()=>{typeof document<"u"&&document.visibilityState!=="visible"||me()},5e3);return()=>{J=!0,window.clearInterval(Te)}},[n]);const Fe=o.useCallback(async J=>{O(!0);try{await Nt(J),Object.prototype.hasOwnProperty.call(J,"tunnelMode")&&J.tunnelMode&&j(J.tunnelMode),Object.prototype.hasOwnProperty.call(J,"tunnelProvider")&&typeof J.tunnelProvider=="string"&&w(J.tunnelProvider),Object.prototype.hasOwnProperty.call(J,"managedLocalTunnelConfigPath")&&G(J.managedLocalTunnelConfigPath??null),Object.prototype.hasOwnProperty.call(J,"managedRemoteTunnelPresets")&&J.managedRemoteTunnelPresets&&q(J.managedRemoteTunnelPresets)}catch{D.error(t("settings.openchamber.tunnel.toast.saveSettingsFailed"))}finally{O(!1)}},[t]),H=o.useCallback(async(J,me)=>{g(!0);try{await Nt({tunnelBootstrapTtlMs:J,tunnelSessionTtlMs:me})}catch{D.error(t("settings.openchamber.tunnel.toast.saveTtlFailed"))}finally{g(!1)}},[t]),He=o.useCallback(async J=>{const me=J.token.trim();if(me)try{const Te={...F,[J.presetId]:me};await Nt({managedRemoteTunnelPresetTokens:Te}),V(Ie=>{const lt=new Set(Ie);return lt.add(J.presetId),lt})}catch{D.error(t("settings.openchamber.tunnel.toast.saveTokenFailed"))}},[F,t]),et=o.useCallback(async J=>{b(null),p(null);const me=K.find(Ie=>Ie.provider===J),Te=me?.modes?.some(Ie=>Ie.key===T)?T:jn(me?.modes?.[0]?.key);await Fe({tunnelProvider:J,tunnelMode:Te}),Ne(J)},[K,Ne,Fe,T]),ze=o.useCallback(async()=>{const J=await vl({filters:[{name:"Config",extensions:["yml","yaml","json"]}]});if(J.success&&typeof J.path=="string"&&J.path.trim().length>0){const me=J.path.trim();if(!Ca(me)){D.error(Ve);return}G(me),await Fe({managedLocalTunnelConfigPath:me});return}_e.current?.click()},[Ve,Fe]),st=o.useCallback(J=>{const me=J.trim();G(me.length>0?me:null)},[]),wt=o.useCallback(async()=>{if(R&&!Ca(R)){D.error(Ve);return}await Fe({managedLocalTunnelConfigPath:R})},[Ve,R,Fe]),xt=o.useCallback(async()=>{G(null),await Fe({managedLocalTunnelConfigPath:null})},[Fe]),gt=o.useCallback(async J=>{const me=J.target.files?.[0];if(!me)return;const Te=me.name.trim();if(Te.length!==0){if(!Ca(Te)){D.error(Ve);return}G(Te),await Fe({managedLocalTunnelConfigPath:Te}),J.target.value=""}},[Ve,Fe]),bt=o.useCallback(async()=>{if(p(null),b(null),T==="managed-local"&&R&&!Ca(R)){p(Ve),D.error(Ve);return}i("starting");try{let J="",me="";if(T==="managed-remote"){if(!Re){i("idle"),b(t("settings.openchamber.tunnel.toast.selectOrAddManagedRemoteFirst")),D.error(t("settings.openchamber.tunnel.toast.selectOrAddManagedRemoteFirst"));return}J=Re.hostname,me=(F[Re.id]||"").trim(),await Fe({tunnelMode:"managed-remote",managedRemoteTunnelPresets:S})}const Te=await pt("/api/openchamber/tunnel/start",{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify({provider:I,mode:T,...T==="managed-remote"&&Re?{managedRemoteTunnelPresetId:Re.id,managedRemoteTunnelPresetName:Re.name}:{},...T==="managed-remote"&&J?{managedRemoteTunnelHostname:J}:{},...T==="managed-remote"&&me?{managedRemoteTunnelToken:me}:{},...T==="managed-local"&&R?{configPath:R}:{}})}),Ie=await Te.json();if(!Te.ok||!Ie.ok){if(T==="managed-remote"&&typeof Ie.error=="string"&&Ie.error.includes("Managed remote tunnel token is required")){i("idle"),b(t("settings.openchamber.tunnel.toast.managedRemoteTokenRequiredBeforeStarting")),D.error(t("settings.openchamber.tunnel.toast.addManagedRemoteTokenBeforeStarting"));return}i("error"),p(Ie.error||t("settings.openchamber.tunnel.toast.startFailed")),D.error(Ie.error||t("settings.openchamber.tunnel.toast.startFailed"));return}const lt=typeof Ie.url=="string"?Ie.url:"";if(!lt){i("error"),p(t("settings.openchamber.tunnel.toast.startedButNoPublicUrl")),D.error(t("settings.openchamber.tunnel.toast.startedButNoPublicUrl"));return}if(l({url:lt,connectUrl:typeof Ie.connectUrl=="string"?Ie.connectUrl:null,bootstrapExpiresAt:typeof Ie.bootstrapExpiresAt=="number"?Ie.bootstrapExpiresAt:null}),d(Ie.activeTunnelMode?jn(Ie.activeTunnelMode):Ie.mode?jn(Ie.mode):T),De(Array.isArray(Ie.activeSessions)?Ie.activeSessions:[]),Array.isArray(Ie.managedRemoteTunnelTokenPresetIds)&&V(new Set(Ie.managedRemoteTunnelTokenPresetIds)),typeof Ie.localPort=="number"&&Ae(Ie.localPort),typeof Ie.mode=="string"&&j(jn(Ie.mode)),i("active"),Ie.replacedTunnel){const at=typeof Ie.revokedBootstrapCount=="number"?Ie.revokedBootstrapCount:0,Je=typeof Ie.invalidatedSessionCount=="number"?Ie.invalidatedSessionCount:0;at===1&&Je===1?D.warning(t("settings.openchamber.tunnel.toast.replacedTunnelSingleSingle")):at===1?D.warning(t("settings.openchamber.tunnel.toast.replacedTunnelSingleManySessions",{invalidatedSessionCount:Je})):Je===1?D.warning(t("settings.openchamber.tunnel.toast.replacedTunnelManyLinksSingleSession",{revokedBootstrapCount:at})):D.warning(t("settings.openchamber.tunnel.toast.replacedTunnelManyMany",{revokedBootstrapCount:at,invalidatedSessionCount:Je}))}else D.success(t("settings.openchamber.tunnel.toast.linkReady"))}catch{i("error"),p(t("settings.openchamber.tunnel.toast.startFailed")),D.error(t("settings.openchamber.tunnel.toast.startFailed"))}},[Ve,S,Fe,Re,F,t,I,T,R]),St=o.useCallback(async()=>{i("stopping");try{await pt("/api/openchamber/tunnel/stop",{method:"POST"});const J=await pt("/api/openchamber/tunnel/status");if(J.ok){const me=await J.json();De(Array.isArray(me.activeSessions)?me.activeSessions:[]),V(new Set(Array.isArray(me.managedRemoteTunnelTokenPresetIds)?me.managedRemoteTunnelTokenPresetIds:[])),Ae(typeof me.localPort=="number"?me.localPort:null)}l(null),d(null),c(null),i("idle"),D.success(t("settings.openchamber.tunnel.toast.stopped"))}catch{i("error"),p(t("settings.openchamber.tunnel.toast.stopFailed")),D.error(t("settings.openchamber.tunnel.toast.stopFailed"))}},[t]),yt=o.useCallback(async()=>{if(r?.connectUrl)try{await navigator.clipboard.writeText(r.connectUrl),N(!0),D.success(t("settings.openchamber.tunnel.toast.connectLinkCopied")),setTimeout(()=>N(!1),2e3)}catch{D.error(t("settings.openchamber.tunnel.toast.copyUrlFailed"))}},[t,r?.connectUrl]),It=o.useCallback(async J=>{const me=Za.find(Te=>Te.value===J);me&&(ie(me.ms),await H(me.ms,te))},[H,te]),qe=o.useCallback(async J=>{const me=Xa.find(Te=>Te.value===J);!me||me.ms===null||(ye(me.ms),await H(ae,me.ms))},[ae,H]),Qe=o.useCallback(async J=>{b(null),p(null),n!=="active"&&n!=="stopping"&&n!=="starting"&&i("idle"),await Fe({tunnelMode:J,managedRemoteTunnelPresets:S})},[S,Fe,n]),dt=o.useCallback(async(J,me)=>{try{await Nt({managedRemoteTunnelPresets:me})}catch{D.error(t("settings.openchamber.tunnel.toast.saveSelectedManagedRemoteFailed"))}},[t]),Ee=o.useCallback(J=>{const me=S.find(Te=>Te.id===J);me&&(Y(me.id),b(null),dt(me,S))},[S,dt]),vt=o.useCallback(async()=>{const J=X.trim(),me=ai(ne),Te=re.trim();if(!J){D.error(t("settings.openchamber.tunnel.toast.tunnelNameRequired"));return}if(!me){D.error(t("settings.openchamber.tunnel.toast.managedRemoteHostnameRequired"));return}if(!Te){D.error(t("settings.openchamber.tunnel.toast.managedRemoteTokenRequired"));return}if(S.some(at=>at.hostname===me)){D.error(t("settings.openchamber.tunnel.toast.hostnameAlreadyExists"));return}const Ie={id:$h(),name:J,hostname:me},lt=[...S,Ie];q(lt),Y(Ie.id),M(at=>({...at,[Ie.id]:!0})),se(at=>({...at,[Ie.id]:Te})),b(null),U(!1),Z(""),le(""),fe(""),await Fe({tunnelMode:"managed-remote",managedRemoteTunnelPresets:lt,managedRemoteTunnelPresetTokens:{...F,[Ie.id]:Te}}),await He({presetId:Ie.id,presetName:Ie.name,hostname:Ie.hostname,token:Te}),D.success(t("settings.openchamber.tunnel.toast.managedRemoteSaved"))},[S,ne,X,re,He,Fe,F,t]),Se=o.useCallback(async J=>{const me=S.find(Je=>Je.id===J);if(!me)return;const Te=S.filter(Je=>Je.id!==me.id),Ie=Te[0]?.id||"",lt=W===me.id?Ie:W,at=Object.fromEntries(Object.entries(F).filter(([Je,Ct])=>Je!==me.id&&Ct.trim().length>0));q(Te),Y(lt),M(Je=>{const Ct={...Je};return delete Ct[me.id],Ct}),se(Je=>{const Ct={...Je};return delete Ct[me.id],Ct}),V(Je=>{const Ct=new Set(Je);return Ct.delete(me.id),Ct}),b(null),await Fe({managedRemoteTunnelPresets:Te,managedRemoteTunnelPresetTokens:at}),D.success(t("settings.openchamber.tunnel.toast.managedRemoteRemoved"))},[S,Fe,W,F,t]),kt="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(Be,{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:[Ze.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(L,{name:"information",className:"size-4 text-[var(--status-info)]"}),s.jsx("p",{className:Rr,children:t("settings.openchamber.tunnel.section.redeemedAccessLinks")})]}),s.jsx("div",{className:"space-y-1",children:Ze.map(J=>{const me=J.mode==="quick",Te=J.mode==="managed-remote",Ie=me?"border-[var(--status-warning-border)] bg-[var(--status-warning-background)] text-[var(--status-warning)]":Te?"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)]",lt=J.isActive?me?"text-[var(--status-warning)]":Te?"text-[var(--status-info)]":"text-[var(--status-success)]":"text-muted-foreground/50",at=t(me?"settings.openchamber.tunnel.badge.quick":Te?"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(L,{name:"checkbox-blank-circle-fill",className:je("size-2.5 shrink-0",lt)}),s.jsx("span",{className:je("typography-micro rounded border px-1.5 py-0.5 uppercase",Ie),children:at}),s.jsx("span",{className:"typography-meta text-muted-foreground/80",children:t("settings.openchamber.tunnel.session.redeemedAt",{time:zh(J.createdAt,e)})}),s.jsx("span",{className:"typography-meta text-foreground",children:J.isActive?t("settings.openchamber.tunnel.session.expiresIn",{remaining:J.remainingTextForSession}):J.inactiveLabel===t("settings.openchamber.tunnel.state.inactive")?t("settings.openchamber.tunnel.state.inactive"):t("settings.openchamber.tunnel.session.inactiveWithReason",{reason:J.inactiveLabel})})]},J.sessionId)})})]})}),n==="not-available"&&s.jsx("section",{className:"space-y-2 px-2 pb-2 pt-0",children:s.jsxs("div",{className:"flex items-start gap-2 rounded-lg border border-[var(--status-warning)]/30 bg-[var(--status-warning)]/5 p-3",children:[s.jsx(L,{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:Rr,children:t("settings.openchamber.tunnel.notAvailable.dependencyNotFound",{dependency:$.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:$.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:Rt,children:t("settings.openchamber.tunnel.field.provider")}),s.jsxs(Ot,{value:I,onValueChange:J=>{et(J)},disabled:E||n==="starting"||n==="stopping",children:[s.jsx(Lt,{size:Jt,className:"max-w-[16rem]",children:s.jsx(Ht,{placeholder:t("settings.openchamber.tunnel.field.providerPlaceholder"),children:Gl(I)})}),s.jsxs(Ft,{children:[K.length>0?K.map(J=>s.jsx(ut,{value:J.provider,children:s.jsx(qo,{provider:J.provider})},J.provider)):s.jsx(ut,{value:"cloudflare",children:s.jsx(qo,{provider:"cloudflare"})}),s.jsx(ut,{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:Rt,children:t("settings.openchamber.tunnel.field.tunnelType")}),s.jsx("div",{className:"flex flex-wrap items-center gap-1",children:ve.map(J=>s.jsxs(pr,{children:[s.jsx(mr,{asChild:!0,children:s.jsx(B,{variant:"chip",size:"xs","aria-pressed":T===J.value,className:"!font-normal",onClick:()=>{Qe(J.value)},disabled:E||n==="starting"||n==="stopping",children:a(J.labelKey)})}),s.jsx(cl,{sideOffset:8,className:"max-w-xs",children:a(J.tooltipKey)})]},J.value))})]})]}),s.jsxs("div",{"data-settings-item":"tunnel.ttl",className:"mt-2 grid grid-cols-1 gap-2 py-1.5 md:grid-cols-[14rem_auto] md:gap-x-8 md:gap-y-2",children:[s.jsxs("div",{className:"flex min-w-0 items-center gap-2",children:[s.jsx("span",{className:je(Rt,"shrink-0"),children:t("settings.openchamber.tunnel.field.connectLinkTtl")}),s.jsxs(Ot,{value:or(Za,ae,"1800000"),onValueChange:J=>{It(J)},disabled:k||E||n==="starting"||n==="stopping",children:[s.jsx(Lt,{size:Jt,className:"max-w-[11rem] min-w-0",children:s.jsx(Ht,{className:"truncate",children:Wo(Za,ae,"1800000")})}),s.jsx(Ft,{children:Za.map(J=>s.jsx(ut,{value:J.value,children:J.label},J.value))})]})]}),s.jsxs("div",{className:"flex min-w-0 items-center gap-2",children:[s.jsx("span",{className:je(Rt,"shrink-0"),children:t("settings.openchamber.tunnel.field.tunnelSessionTtl")}),s.jsxs(Ot,{value:or(Xa,te,"28800000"),onValueChange:J=>{qe(J)},disabled:k||E||n==="starting"||n==="stopping",children:[s.jsx(Lt,{size:Jt,className:"max-w-[11rem] min-w-0",children:s.jsx(Ht,{className:"truncate",children:Wo(Xa,te,"28800000")})}),s.jsx(Ft,{children:Xa.map(J=>s.jsx(ut,{value:J.value,children:J.label},J.value))})]})]})]}),T==="quick"&&s.jsx("div",{className:"rounded-lg border border-[var(--status-warning)]/35 bg-[var(--status-warning)]/10 p-3",children:s.jsxs("div",{className:"flex items-start gap-2",children:[s.jsx(L,{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")}),We&&s.jsx("p",{className:"typography-meta mt-1 text-[var(--status-warning)]",children:t("settings.openchamber.tunnel.warning.quickModeReliability")})]})]})}),T==="managed-remote"&&s.jsxs("div",{"data-settings-item":"tunnel.managed-remote",className:"space-y-2 rounded-lg border border-[var(--interactive-border)] bg-[var(--surface-elevated)] p-3",children:[typeof Pe=="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:",Pe]})]})}),s.jsxs("div",{className:"mb-1 flex items-center justify-between gap-3",children:[s.jsx(en,{children:t("settings.openchamber.tunnel.section.savedManagedRemoteTunnels")}),s.jsxs(B,{variant:"ghost",size:"xs",className:"!font-normal",onClick:()=>U(J=>!J),disabled:n==="starting"||n==="stopping"||E,children:[s.jsx(L,{name:"add",className:"h-3.5 w-3.5"}),t("settings.common.actions.create")]})]}),S.length>0?s.jsx("div",{className:"overflow-hidden rounded-md border border-[var(--surface-subtle)]",children:S.map((J,me)=>{const Te=F[J.id]||"",Ie=_.has(J.id),lt=Q[J.id]??!1;return s.jsx("div",{className:je(me<S.length-1&&"border-b border-[var(--surface-subtle)]"),children:s.jsxs(qn,{open:lt,onOpenChange:at=>{M(Je=>({...Je,[J.id]:at})),at&&Ee(J.id)},className:"py-1.5",children:[s.jsxs("div",{className:"flex items-start gap-2 px-3",children:[s.jsxs(Wn,{type:"button",className:"group flex-1 justify-start gap-2 rounded-md px-0 py-1 pr-1 text-left hover:bg-[var(--interactive-hover)]",disabled:n==="starting"||n==="stopping"||E,children:[lt?s.jsx(L,{name:"arrow-down-s",className:"h-4 w-4 text-muted-foreground"}):s.jsx(L,{name:"arrow-right-s",className:"h-4 w-4 text-muted-foreground"}),s.jsx("span",{className:"typography-ui-label min-w-0 flex-1 truncate text-foreground",children:J.name})]}),s.jsx(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:J.name}),onClick:()=>{Se(J.id)},disabled:n==="starting"||n==="stopping"||E,children:s.jsx(L,{name:"delete-bin",className:"h-3.5 w-3.5"})})]}),s.jsx(Jn,{className:"pt-1.5",children:s.jsxs("div",{className:"space-y-1 px-3 pb-2",children:[s.jsxs("p",{className:"typography-meta text-muted-foreground/70",children:[t("settings.openchamber.tunnel.field.hostnameLabel")," ",s.jsx("code",{children:J.hostname})]}),s.jsx(Ye,{type:"password",value:Te,onChange:at=>{const Je=at.target.value;b(null),se(Ct=>({...Ct,[J.id]:Je}))},onBlur:at=>{const Je=at.currentTarget.value.trim();Je&&He({presetId:J.id,presetName:J.name,hostname:J.hostname,token:Je})},placeholder:t(Ie?"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"||Te.trim().length===0,onClick:()=>{He({presetId:J.id,presetName:J.name,hostname:J.hostname,token:Te})},children:t("settings.openchamber.tunnel.actions.saveToken")})})]})})]})},J.id)})}):s.jsx("p",{className:"typography-meta text-muted-foreground/70",children:t("settings.openchamber.tunnel.empty.noManagedRemoteTunnels")}),z&&s.jsxs("div",{className:"space-y-2 rounded-md border border-[var(--surface-subtle)] p-2",children:[s.jsx(Ye,{value:X,onChange:J=>Z(J.target.value),placeholder:t("settings.openchamber.tunnel.field.newPresetNamePlaceholder"),className:"h-7",disabled:E||n==="starting"||n==="stopping"}),s.jsx(Ye,{value:ne,onChange:J=>le(J.target.value),placeholder:t("settings.openchamber.tunnel.field.newPresetHostnamePlaceholder"),className:"h-7",disabled:E||n==="starting"||n==="stopping"}),s.jsx(Ye,{type:"password",value:re,onChange:J=>fe(J.target.value),placeholder:t("settings.openchamber.tunnel.field.newPresetTokenPlaceholder"),className:"h-7",disabled:E||n==="starting"||n==="stopping"}),typeof Pe=="number"&&s.jsxs("p",{className:"typography-meta text-muted-foreground/70",children:[t("settings.openchamber.tunnel.note.cloudflareConnectorTargetUse")," ",s.jsxs("code",{children:["http://localhost:",Pe]}),"."]}),s.jsxs("div",{className:"flex items-center gap-2",children:[s.jsx(B,{variant:"ghost",size:"xs",className:"!font-normal",onClick:()=>{vt()},disabled:E||n==="starting"||n==="stopping",children:t("settings.common.actions.saveChanges")}),s.jsx(B,{variant:"ghost",size:"xs",className:"!font-normal",onClick:()=>{U(!1),Z(""),le(""),fe("")},disabled:E||n==="starting"||n==="stopping",children:t("settings.common.actions.cancel")})]})]}),s.jsxs("div",{className:"flex items-center gap-1.5",children:[s.jsx("p",{className:"typography-meta text-muted-foreground/80",children:t("settings.openchamber.tunnel.note.tokensSavedPerTunnel")}),s.jsx(ss,{children:t("settings.openchamber.tunnel.tooltip.tokensSavedPath")})]}),!Re&&A&&s.jsx("p",{className:"typography-meta text-[var(--status-error)]",children:A})]}),T==="managed-local"&&s.jsx("div",{"data-settings-item":"tunnel.managed-local-config",className:"space-y-2 rounded-lg border border-[var(--interactive-border)] bg-[var(--surface-elevated)] p-3",children:s.jsxs("div",{className:"space-y-1.5",children:[s.jsx("p",{className:Rt,children:t("settings.openchamber.tunnel.field.configurationFile")}),s.jsx("input",{ref:_e,type:"file",accept:".yml,.yaml,.json",className:"hidden",onChange:J=>{gt(J)}}),s.jsxs("div",{className:"flex items-center gap-2",children:[s.jsx(Ye,{value:R||"",onChange:J=>{st(J.target.value)},onBlur:()=>{wt()},placeholder:t("settings.openchamber.tunnel.field.configurationFilePlaceholder"),className:"h-7",disabled:n==="starting"||n==="stopping"||E}),s.jsx(B,{variant:"outline",size:"xs",className:"h-7 w-7 p-0","aria-label":t("settings.openchamber.tunnel.actions.browseConfigFileAria"),onClick:()=>{ze()},disabled:n==="starting"||n==="stopping"||E,children:s.jsx(L,{name:"folder",className:"size-3.5"})}),R&&s.jsx(B,{variant:"ghost",size:"xs",className:"h-7 w-7 p-0","aria-label":t("settings.openchamber.tunnel.actions.clearConfigFileAria"),onClick:()=>{xt()},disabled:n==="starting"||n==="stopping"||E,children:s.jsx(L,{name:"close",className:"size-3.5"})})]}),s.jsx("p",{className:"typography-meta text-muted-foreground/70",children:t(R?"settings.openchamber.tunnel.note.customConfigUsed":"settings.openchamber.tunnel.note.defaultConfigUsed")}),Le&&s.jsx("p",{className:"typography-meta text-[var(--status-error)]",children:Ve})]})}),!Oe&&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(L,{name:"information",className:"mt-0.5 size-4 shrink-0 text-[var(--status-info)]"}),s.jsxs("div",{className:"space-y-1",children:[T==="managed-remote"&&s.jsxs(s.Fragment,{children:[s.jsx("p",{className:"typography-meta text-[var(--status-info)]",children:t("settings.openchamber.tunnel.note.managedRemoteRequiresDomain")}),s.jsxs("button",{type:"button",className:"typography-meta inline-flex items-center gap-1 text-[var(--status-info)] underline underline-offset-2 hover:opacity-90",onClick:()=>{de(Rh)},children:[t("settings.openchamber.tunnel.actions.openManagedRemoteDocs"),s.jsx(L,{name:"external-link",className:"size-3.5"})]})]}),T==="managed-local"&&s.jsxs(s.Fragment,{children:[s.jsx("p",{className:"typography-meta text-[var(--status-info)]",children:t("settings.openchamber.tunnel.note.managedLocalUsesConfig")}),s.jsxs("button",{type:"button",className:"typography-meta inline-flex items-center gap-1 text-[var(--status-info)] underline underline-offset-2 hover:opacity-90",onClick:()=>{de(Oh)},children:[t("settings.openchamber.tunnel.actions.openManagedLocalDocs"),s.jsx(L,{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(qi.find(J=>J.value===T)?.labelKey??"settings.openchamber.tunnel.option.mode.quick.label")})})]})]})}),T==="managed-remote"&&s.jsxs("div",{className:"space-y-1.5",children:[s.jsx("p",{className:Rt,children:t("settings.openchamber.tunnel.field.managedRemoteTunnelToConnect")}),s.jsxs(Ot,{value:W||(S[0]?.id??""),onValueChange:J=>{Ee(J)},disabled:E||n==="starting"||n==="stopping"||S.length<=1,children:[s.jsx(Lt,{size:Jt,children:s.jsx(Ht,{placeholder:t("settings.openchamber.tunnel.field.selectSavedTunnelPlaceholder"),children:Re?.name})}),s.jsx(Ft,{fitContent:!0,children:S.map(J=>s.jsx(ut,{value:J.id,children:J.name},J.id))})]})]}),Ke&&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(L,{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:bt,disabled:n==="starting"||E||T==="managed-remote"&&!Re||T==="managed-local"&&Le,className:je(kt,n==="starting"&&"opacity-70"),children:n==="starting"?s.jsxs(s.Fragment,{children:[s.jsx(L,{name:"loader-4",className:"size-3.5 animate-spin"})," ",t("settings.openchamber.tunnel.actions.startingTunnel")]}):t("settings.openchamber.tunnel.actions.startTunnel")})]})]}),Oe&&r&&s.jsxs("section",{"data-settings-item":"tunnel.start",className:"space-y-4 px-2 pb-2 pt-0",children:[s.jsxs("div",{className:"space-y-3",children:[s.jsxs("div",{className:"flex items-center gap-2",children:[s.jsx("div",{className:"size-2 shrink-0 rounded-full bg-[var(--status-success)]"}),s.jsx("p",{className:"typography-meta font-medium text-foreground",children:t("settings.openchamber.tunnel.state.tunnelReady")})]}),s.jsxs("div",{children:[s.jsx("p",{className:"typography-meta mb-1 text-muted-foreground/70",children:t("settings.openchamber.tunnel.field.publicUrlHint")}),s.jsx("code",{className:"typography-code block truncate rounded bg-muted/50 px-2 py-1 text-xs text-foreground",children:r.url})]}),Ge&&r.connectUrl&&s.jsxs(s.Fragment,{children:[s.jsxs("div",{children:[s.jsx("p",{className:"typography-meta mb-1 text-muted-foreground/70",children:t("settings.openchamber.tunnel.field.connectLink")}),s.jsxs("div",{className:"flex items-center gap-2",children:[s.jsx("code",{className:"typography-code flex-1 truncate rounded bg-muted/50 px-2 py-1 text-xs text-foreground",children:r.connectUrl}),s.jsxs(B,{size:"sm",variant:"ghost",onClick:yt,className:"shrink-0 gap-1.5",children:[P?s.jsx(L,{name:"check",className:"size-3.5 text-[var(--status-success)]"}):s.jsx(L,{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"),": ",r.bootstrapExpiresAt?we: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:[x?s.jsx("img",{src:x,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:bt,disabled:n==="stopping"||E||T==="managed-local"&&Le,className:kt,children:[s.jsx(L,{name:"restart",className:"size-3.5"}),t("settings.openchamber.tunnel.actions.newConnectLink")]}),s.jsx(B,{size:"sm",variant:"ghost",onClick:St,disabled:n==="stopping"||E,className:"gap-2 text-[var(--status-error)]",children:n==="stopping"?s.jsxs(s.Fragment,{children:[s.jsx(L,{name:"loader-4",className:"size-3.5 animate-spin"})," ",t("settings.openchamber.tunnel.actions.stopping")]}):t("settings.openchamber.tunnel.actions.stopTunnel")})]})})]}),n==="error"&&v&&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:v}),s.jsx(B,{size:"sm",variant:"ghost",onClick:bt,children:t("settings.openchamber.tunnel.actions.retry")})]})]})})},ql=()=>{const{t}=ot(),[e,a]=Xe.useState(""),[n,i]=Xe.useState(!0),[r,l]=Xe.useState(!1),h=ce(p=>p.showOpenCodeUpdateNotifications),d=ce(p=>p.setShowOpenCodeUpdateNotifications);Xe.useEffect(()=>{let p=!1;return(async()=>{try{const A=await pt("/api/config/settings",{method:"GET",headers:{Accept:"application/json"}});if(!A.ok)return;const b=await A.json().catch(()=>null);if(p||!b)return;const P=typeof b.opencodeBinary=="string"?b.opencodeBinary.trim():"";a(P)}catch{}finally{p||i(!1)}})(),()=>{p=!0}},[]);const x=Xe.useCallback(async()=>{if(!(typeof window>"u")&&bs())try{const p=await vl();p.success&&p.path&&p.path.trim().length>0&&a(p.path.trim())}catch{}},[]),c=Xe.useCallback(async()=>{l(!0);try{const p=e.trim(),A=p.length>=2&&(p.startsWith('"')&&p.endsWith('"')||p.startsWith("'")&&p.endsWith("'"))?p.slice(1,-1).trim():p;await Nt({opencodeBinary:A}),Un("cli",{id:"opencode-binary"}),D.success(t("settings.view.pendingRestart.saved"))}finally{l(!1)}},[t,e]),v=Xe.useCallback(p=>{d(p),Nt({showOpenCodeUpdateNotifications:p})},[d]);return s.jsx(Be,{title:t("settings.openchamber.opencodeCli.title"),children:s.jsxs("div",{className:"space-y-0.5",children:[s.jsxs(Qt,{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(Ye,{value:e,onChange:p=>a(p.target.value),placeholder:t("settings.openchamber.opencodeCli.field.binaryPathPlaceholder"),disabled:n||r,className:"h-8 min-w-0 flex-1 font-mono text-xs"}),s.jsx(B,{type:"button",variant:"outline",size:"xs",onClick:x,disabled:n||r||!bs(),className:ks,"aria-label":t("settings.openchamber.opencodeCli.actions.browseAria"),title:t("settings.openchamber.opencodeCli.actions.browse"),children:s.jsx(L,{name:"folder",className:"h-4 w-4"})})]}),s.jsxs(Oa,{className:Ns,children:[!yl()&&s.jsx(ht,{settingsItem:"sessions.opencode-update-notifications",checked:h,onChange:v,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:c,disabled:n||r,className:"shrink-0 !font-normal",children:t(r?"settings.common.actions.saving":"settings.common.actions.saveChanges")})})]})]})})},Wl=()=>{const t=mt.c(44),{t:e}=ot(),a=ce(Bh),n=ce(Hh),i=ce(Gh),r=ce(qh),l=ce(Wh),h=ce(Jh),d=ce(Qh);let x;t[0]!==n?(x=T=>{n(T),Nt({agentControlToolEnabled:T}),Un("cli",{id:"agent-control-tool"})},t[0]=n,t[1]=x):x=t[1];const c=x;let v;t[2]!==r?(v=T=>{r(T),Nt({agentWebToolEnabled:T}),Un("cli",{id:"agent-web-tool"})},t[2]=r,t[3]=v):v=t[3];const p=v;let A;t[4]!==d?(A=T=>{d(T),Nt({agentMemoryToolEnabled:T}).finally(()=>{T&&Hc.getState().refresh()}),Un("cli",{id:"agent-memory-tool"})},t[4]=d,t[5]=A):A=t[5];const b=A;let P;t[6]!==e?(P=e("settings.openchamber.tools.title"),t[6]=e,t[7]=P):P=t[7];let N;t[8]!==e?(N=e("settings.openchamber.tools.field.agentControlTool"),t[8]=e,t[9]=N):N=t[9];let k;t[10]!==e?(k=e("settings.openchamber.tools.field.agentControlToolAria"),t[10]=e,t[11]=k):k=t[11];let g;t[12]!==e?(g=e("settings.openchamber.tools.field.agentControlToolInfo"),t[12]=e,t[13]=g):g=t[13];let E;t[14]!==a||t[15]!==c||t[16]!==N||t[17]!==k||t[18]!==g?(E=s.jsx(ht,{settingsItem:"sessions.agent-control-tool",checked:a,onChange:c,label:N,ariaLabel:k,info:g}),t[14]=a,t[15]=c,t[16]=N,t[17]=k,t[18]=g,t[19]=E):E=t[19];let O;t[20]!==e?(O=e("settings.openchamber.tools.field.agentWebTool"),t[20]=e,t[21]=O):O=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 m;t[26]!==i||t[27]!==p||t[28]!==w||t[29]!==O||t[30]!==I?(m=s.jsx(ht,{settingsItem:"sessions.agent-web-tool",checked:i,onChange:p,label:O,ariaLabel:I,info:w}),t[26]=i,t[27]=p,t[28]=w,t[29]=O,t[30]=I,t[31]=m):m=t[31];let y;t[32]!==h||t[33]!==l||t[34]!==b||t[35]!==e?(y=h?s.jsx(ht,{settingsItem:"sessions.agent-memory-tool",checked:l,onChange:b,label:e("settings.openchamber.tools.field.agentMemoryTool"),ariaLabel:e("settings.openchamber.tools.field.agentMemoryToolAria"),info:e("settings.openchamber.tools.field.agentMemoryToolInfo")}):null,t[32]=h,t[33]=l,t[34]=b,t[35]=e,t[36]=y):y=t[36];let K;t[37]!==m||t[38]!==y||t[39]!==E?(K=s.jsxs("div",{className:Ns,children:[E,m,y]}),t[37]=m,t[38]=y,t[39]=E,t[40]=K):K=t[40];let C;return t[41]!==K||t[42]!==P?(C=s.jsx(Be,{title:P,children:K}),t[41]=K,t[42]=P,t[43]=C):C=t[43],C};function Bh(t){return t.agentControlToolEnabled}function Hh(t){return t.setAgentControlToolEnabled}function Gh(t){return t.agentWebToolEnabled}function qh(t){return t.setAgentWebToolEnabled}function Wh(t){return t.agentMemoryToolEnabled}function Jh(t){return t.agentMemoryFeatureAvailable}function Qh(t){return t.setAgentMemoryToolEnabled}const Jl=()=>{const{t}=ot(),e=bs()&&Fa(),a=e&&typeof window<"u"&&window.__OPENCHAMBER_PLATFORM__==="darwin",[n,i]=Xe.useState(!1),[r,l]=Xe.useState(!1),[h,d]=Xe.useState(""),[x,c]=Xe.useState(""),[v,p]=Xe.useState(!1),[A,b]=Xe.useState(!1),[P,N]=Xe.useState(null),[k,g]=Xe.useState(!0),[E,O]=Xe.useState(!1),[I,w]=Xe.useState(!1),[m,y]=Xe.useState(!1),[K,C]=Xe.useState(!1),[T,j]=Xe.useState(!1),[R,G]=Xe.useState(!1),[S,q]=Xe.useState(!1),[Q,M]=Xe.useState(!0),[W,Y]=Xe.useState(!0),[F,se]=Xe.useState(!1),[_,V]=Xe.useState(!1),[z,U]=Xe.useState(!1),[X,Z]=Xe.useState(null),[ne,le]=Xe.useState(null);Xe.useEffect(()=>{if(!e){g(!1);return}let he=!1;return(async()=>{try{const ge=await pt("/api/config/settings",{method:"GET",headers:{Accept:"application/json"}});if(!ge.ok)throw new Error(t("settings.openchamber.desktopNetwork.error.loadFailed"));const Ae=await ge.json().catch(()=>null);if(he)return;const Ve=Ae?.desktopLanAccessEnabled===!0,_e=typeof Ae?.desktopUiPassword=="string"?Ae.desktopUiPassword:"";i(Ve),l(Ve),d(_e),c(_e),b(Ae?.desktopLanAccessActive===!0),N(typeof Ae?.desktopLanAccessBlockedReason=="string"?Ae.desktopLanAccessBlockedReason:null);const Le=Ae?.desktopMacMenuBarEnabled!==!1;M(Le),Y(Le),Z(null)}catch(ge){he||Z(ge instanceof Error?ge.message:t("settings.openchamber.desktopNetwork.error.loadFailed"))}finally{he||g(!1)}})(),()=>{he=!0}},[e,t]),Xe.useEffect(()=>{if(!e){w(!1);return}let he=!1;return(async()=>{const ge=await jd();he||(w(ge?.supported===!0),y(ge?.enabled===!0))})(),()=>{he=!0}},[e]),Xe.useEffect(()=>{if(!e){j(!1);return}let he=!1;return(async()=>{const ge=await wd();he||(j(ge?.supported===!0),G(ge?.enabled===!0))})(),()=>{he=!0}},[e]),Xe.useEffect(()=>{if(!e){se(!1);return}let he=!1;return(async()=>{const ge=await kd();he||(se(ge?.supported===!0),V(ge?.enabled===!0))})(),()=>{he=!0}},[e]),Xe.useEffect(()=>{if(!e||!r){le(null);return}let he=!1;return(async()=>{const ge=await xl();he||le(ge)})(),()=>{he=!0}},[r,e]);const re=r!==n||x!==h||W!==Q,fe=Xe.useMemo(()=>{if(typeof window>"u")return null;const ge=La()||window.location.href;let Ae=0;try{Ae=Number(new URL(ge).port)}catch{Ae=Number(window.location.port)}return Number.isFinite(Ae)&&Ae>0?Ae:null},[]),ae=r&&A&&ne&&fe?`http://${ne}:${fe}`:null,ie=r&&!x.trim(),te=n&&!A&&P==="missing-password",ye=k||E||!re||ie,we=Xe.useCallback(he=>{c(he),he.trim()||l(!1)},[]),ke=Xe.useCallback(async()=>{if(!I||K)return;const he=!m;y(he),C(!0),Z(null);try{const ge=await Nd(he);if(!ge?.supported)throw new Error(t("settings.openchamber.desktopNetwork.error.launchAtLoginUnsupported"));y(ge.enabled)}catch(ge){y(!he),Z(ge instanceof Error?ge.message:t("settings.openchamber.desktopNetwork.error.launchAtLoginSaveFailed"))}finally{C(!1)}},[K,m,I,t]),xe=Xe.useCallback(async()=>{if(!T||S)return;const he=!R;G(he),q(!0),Z(null);try{const ge=await Sd(he);if(!ge)throw new Error(t("settings.openchamber.desktopNetwork.error.minimizeToTraySaveFailed"));if(!ge.supported)throw new Error(t("settings.openchamber.desktopNetwork.error.minimizeToTrayUnsupported"));G(ge.enabled)}catch(ge){G(!he),Z(ge instanceof Error?ge.message:t("settings.openchamber.desktopNetwork.error.minimizeToTraySaveFailed"))}finally{q(!1)}},[S,R,T,t]),De=Xe.useCallback(async()=>{if(!F||z)return;const he=!_;V(he),U(!0),Z(null);try{const ge=await Cd(he);if(!ge?.supported)throw new Error(t("settings.openchamber.desktopNetwork.error.keepAwakeUnsupported"));V(ge.enabled)}catch(ge){V(!he),Z(ge instanceof Error?ge.message:t("settings.openchamber.desktopNetwork.error.keepAwakeSaveFailed"))}finally{U(!1)}},[z,_,F,t]),Me=Xe.useCallback(async()=>{if(re){O(!0),Z(null);try{if(!(await pt("/api/config/settings",{method:"PUT",headers:{"Content-Type":"application/json",Accept:"application/json"},body:JSON.stringify({desktopLanAccessEnabled:r,desktopUiPassword:x,desktopMacMenuBarEnabled:W})})).ok)throw new Error(t("settings.openchamber.desktopNetwork.error.saveFailed"));if(i(r),d(x),M(W),!await Pd())throw new Error(t("settings.openchamber.desktopNetwork.error.savedRestartFailed"))}catch(he){Z(he instanceof Error?he.message:t("settings.openchamber.desktopNetwork.error.saveFailed")),O(!1)}}},[W,x,r,re,t]);return e?s.jsx(Be,{title:t("settings.openchamber.desktopNetwork.title"),children:s.jsxs("div",{className:"space-y-3",children:[I||a||T||F?s.jsxs("div",{className:Ns,children:[I?s.jsx(ht,{settingsItem:"sessions.desktop-launch-at-login",checked:m,onChange:he=>{he!==m&&ke()},disabled:K,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(ht,{settingsItem:"sessions.desktop-mac-menu-bar",checked:W,onChange:Y,disabled:k||E,label:t("settings.openchamber.desktopNetwork.field.macMenuBar"),info:t("settings.openchamber.desktopNetwork.field.macMenuBarDescription"),ariaLabel:t("settings.openchamber.desktopNetwork.field.macMenuBarAria")}):null,T?s.jsx(ht,{settingsItem:"sessions.desktop-minimize-to-tray",checked:R,onChange:he=>{he!==R&&xe()},disabled:S,label:t("settings.openchamber.desktopNetwork.field.minimizeToTray"),info:t("settings.openchamber.desktopNetwork.field.minimizeToTrayDescription"),ariaLabel:t("settings.openchamber.desktopNetwork.field.minimizeToTrayAria")}):null,F?s.jsx(ht,{settingsItem:"sessions.desktop-keep-awake",checked:_,onChange:he=>{he!==_&&De()},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(es,{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(Ye,{id:"desktop-ui-password",type:v?"text":"password",className:"h-8 min-w-0 flex-1",value:x,onChange:he=>we(he.target.value),placeholder:t("settings.openchamber.desktopPassword.field.passwordPlaceholder"),disabled:k||E,required:r,"aria-invalid":ie}),s.jsx(B,{type:"button",variant:"ghost",size:"xs",onClick:()=>p(he=>!he),className:ks,"aria-label":t(v?"settings.openchamber.desktopPassword.actions.hidePassword":"settings.openchamber.desktopPassword.actions.showPassword"),"aria-pressed":v,children:s.jsx(L,{name:v?"eye-off":"eye",className:"h-4 w-4"})})]}),s.jsx("div",{className:Ns,children:s.jsx(ht,{settingsItem:"sessions.desktop-lan-access",checked:r,onChange:l,disabled:k||E,label:t("settings.openchamber.desktopNetwork.field.allowLanAccess"),info:t("settings.openchamber.desktopNetwork.field.allowLanAccessDescription"),description:s.jsxs(s.Fragment,{children:[s.jsx("span",{className:"block text-[var(--status-warning)]/85",children:t("settings.openchamber.desktopNetwork.field.warning")}),ie||te?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")})}),X?s.jsx("div",{className:"typography-micro text-[var(--status-error)]",children:X}):null,ae?s.jsxs("div",{className:"typography-micro text-muted-foreground/80",children:[t(re&&!n?"settings.openchamber.desktopNetwork.hint.openAfterRestart":"settings.openchamber.desktopNetwork.hint.openNow"),s.jsx("span",{className:"font-mono text-foreground",children:ae})]}):null,s.jsx("div",{className:"flex justify-start py-1.5",children:s.jsx(B,{type:"button",size:"xs",onClick:Me,disabled:ye,className:"shrink-0 !font-normal",children:t(E?"settings.common.actions.saving":"settings.openchamber.desktopNetwork.actions.saveAndRestart")})})]})}):null},Ql=new Set(["shift","control","alt","meta"]),wr=3,Yh=3e3;function kr(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 Zh(t){return t.action.customizable}function Qo(t){if(kr(t)>wr)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?di(e.join("+")):null}function Xh(t){if(Ql.has(t.key.toLowerCase())||kr(t,!0)>wr)return null;const e=Wc(Jc(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),di(a.join("+"))}function ef(t){const e=t.key.toLowerCase();if(!Ql.has(e)||kr(t,!0)>wr)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?di(a.join("+")):null}function Yo(t){return t.chords.length>0?{...t,livePreview:null,settled:!0}:t}function tf(t,e,a){if(e.repeat||e.isComposing)return t;if(a==="keyup")return{...t,livePreview:Qo(e)};if(e.key==="Backspace")return{chords:t.chords.slice(0,-1),livePreview:null,settled:!1};const n=Xh(e);if(n){if(t.settled)return{chords:[n],livePreview:null,settled:!1};const i=t.chords.length<2?[...t.chords,n]:t.chords;return{chords:i,livePreview:null,settled:i.length===2}}return{...t,livePreview:Qo(e)}}const sf=t=>{const e=mt.c(117),{action:a,overrides:n,onSave:i,onOpenChange:r}=t,{t:l}=ot();let h;e[0]!==l?(h=ie=>l(ie.settingsLabelKey),e[0]=l,e[1]=h):h=e[1];const d=h;let x;e[2]!==d?(x=ie=>ie.action.customizable?d(ie.action):$n(ie.action.defaultBinding),e[2]=d,e[3]=x):x=e[3];const c=x;let v;e[4]===Symbol.for("react.memo_cache_sentinel")?(v={chords:[],livePreview:null,settled:!1},e[4]=v):v=e[4];const[p,A]=o.useState(v),b=o.useRef(null);let P,N;e[5]!==a?(P=()=>{a&&(A({chords:[],livePreview:null,settled:!1}),b.current?.focus())},N=[a],e[5]=a,e[6]=P,e[7]=N):(P=e[6],N=e[7]),o.useEffect(P,N);const k=p.chords.length===1&&!p.settled;let g,E;e[8]!==k?(g=()=>{if(!k)return;const ie=window.setTimeout(()=>A(Yo),Yh);return()=>window.clearTimeout(ie)},E=[k],e[8]=k,e[9]=g,e[10]=E):(g=e[9],E=e[10]),o.useEffect(g,E);let O;e[11]!==p.chords?(O=di(p.chords.join(" ")),e[11]=p.chords,e[12]=O):O=e[12];const I=O;let w;e[13]!==a||e[14]!==I||e[15]!==n?(w=a&&I?Gc(a.id,I,n):[],e[13]=a,e[14]=I,e[15]=n,e[16]=w):w=e[16];const m=w;let y;e[17]!==m?(y=m.find(nf),e[17]=m,e[18]=y):y=e[18];const K=y;let C,T,j,R,G,S,q,Q,M,W,Y,F,se,_,V;if(e[19]!==a||e[20]!==d||e[21]!==I||e[22]!==c||e[23]!==m||e[24]!==r||e[25]!==i||e[26]!==K||e[27]!==p||e[28]!==l){const ie=m.filter(Zh);G=ie.find(af);const te=ie.find(rf),ye=m.find(of);let we;e[44]!==r?(we=()=>r(!1),e[44]=r,e[45]=we):we=e[45],j=we,R=()=>{p.settled||A(Yo),!(!a||!I||K||G)&&(i(a.id,I,te?.action.id),j())};let ke;e[46]!==a||e[47]!==p?(ke=(Oe,Ke)=>{Oe.preventDefault(),Oe.stopPropagation();const Pe=!!(a&&"prefixStyle"in a&&a.prefixStyle);if(Ke==="keyup"&&Pe&&p.chords.length===0){const ve=ef(Oe);if(ve){A({chords:[ve],livePreview:null,settled:!0});return}}const Ue=tf(p,{altKey:Oe.altKey,code:Oe.nativeEvent.code,ctrlKey:Oe.ctrlKey,isComposing:Oe.nativeEvent.isComposing,key:Oe.key,metaKey:Oe.metaKey,repeat:Oe.repeat,shiftKey:Oe.shiftKey},Ke);A(Pe&&Ue.chords.length>1?p:Ue)},e[46]=a,e[47]=p,e[48]=ke):ke=e[48];const xe=ke;T=zt,_=a!==null,V=lf,C=_t,S="max-w-md",q=b,Q=!1;let De;e[49]!==a||e[50]!==d||e[51]!==l?(De=a?l("settings.openchamber.keyboardShortcuts.dialog.title",{action:d(a)}):"",e[49]=a,e[50]=d,e[51]=l,e[52]=De):De=e[52];let Me;e[53]!==De?(Me=s.jsx(qt,{children:De}),e[53]=De,e[54]=Me):Me=e[54];let he;e[55]!==l?(he=l("settings.openchamber.keyboardShortcuts.dialog.instructions"),e[55]=l,e[56]=he):he=e[56];let ge;e[57]!==he?(ge=s.jsx(Wt,{children:he}),e[57]=he,e[58]=ge):ge=e[58],e[59]!==Me||e[60]!==ge?(M=s.jsxs(Gt,{children:[Me,ge]}),e[59]=Me,e[60]=ge,e[61]=M):M=e[61];let Ae,Ve;e[62]!==xe?(Ae=Oe=>xe(Oe,"keydown"),Ve=Oe=>xe(Oe,"keyup"),e[62]=xe,e[63]=Ae,e[64]=Ve):(Ae=e[63],Ve=e[64]);let _e;e[65]===Symbol.for("react.memo_cache_sentinel")?(_e=()=>A(cf),e[65]=_e):_e=e[65];let Le;e[66]!==p.chords?(Le=p.chords.map(df),e[66]=p.chords,e[67]=Le):Le=e[67];let Re;e[68]!==p.livePreview?(Re=p.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:$n(p.livePreview)}):null,e[68]=p.livePreview,e[69]=Re):Re=e[69];let Ze;e[70]!==p.chords.length||e[71]!==p.livePreview||e[72]!==l?(Ze=p.chords.length===0&&!p.livePreview?s.jsx("span",{className:"typography-ui-label text-muted-foreground",children:l("settings.openchamber.keyboardShortcuts.dialog.recording")}):null,e[70]=p.chords.length,e[71]=p.livePreview,e[72]=l,e[73]=Ze):Ze=e[73];let Ge;e[74]!==Le||e[75]!==Re||e[76]!==Ze?(Ge=s.jsxs("div",{className:"flex flex-wrap items-center justify-center gap-2",children:[Le,Re,Ze]}),e[74]=Le,e[75]=Re,e[76]=Ze,e[77]=Ge):Ge=e[77],e[78]!==Ae||e[79]!==Ve||e[80]!==Ge?(W=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:b,onKeyDown:Ae,onKeyUp:Ve,onBlur:_e,children:Ge}),e[78]=Ae,e[79]=Ve,e[80]=Ge,e[81]=W):W=e[81],Y=p.settled&&K?s.jsx("p",{className:"typography-meta text-[var(--status-error)]",children:l("settings.openchamber.keyboardShortcuts.error.internalConflict")}):p.settled&&G?s.jsx("p",{className:"typography-meta text-[var(--status-error)]",children:l("settings.openchamber.keyboardShortcuts.error.prefixConflict",{action:d(G.action)})}):null,F=p.settled&&te&&!K&&!G?s.jsx("p",{className:"typography-meta text-[var(--status-warning)]",children:l("settings.openchamber.keyboardShortcuts.error.exactConflict",{action:d(te.action)})}):null,se=p.settled&&ye&&!K&&!G?s.jsx("p",{className:"typography-meta text-[var(--status-warning)]",children:l("settings.openchamber.keyboardShortcuts.warning.contextualPrefix",{action:c(ye)})}):null,e[19]=a,e[20]=d,e[21]=I,e[22]=c,e[23]=m,e[24]=r,e[25]=i,e[26]=K,e[27]=p,e[28]=l,e[29]=C,e[30]=T,e[31]=j,e[32]=R,e[33]=G,e[34]=S,e[35]=q,e[36]=Q,e[37]=M,e[38]=W,e[39]=Y,e[40]=F,e[41]=se,e[42]=_,e[43]=V}else C=e[29],T=e[30],j=e[31],R=e[32],G=e[33],S=e[34],q=e[35],Q=e[36],M=e[37],W=e[38],Y=e[39],F=e[40],se=e[41],_=e[42],V=e[43];let z;e[82]!==I||e[83]!==p.settled||e[84]!==l?(z=p.settled&&I&&qc(I)?s.jsx("p",{className:"typography-meta text-[var(--status-warning)]",children:l("settings.openchamber.keyboardShortcuts.warning.riskyBrowserShortcut")}):null,e[82]=I,e[83]=p.settled,e[84]=l,e[85]=z):z=e[85];let U;e[86]!==l?(U=l("settings.common.actions.cancel"),e[86]=l,e[87]=U):U=e[87];let X;e[88]!==j||e[89]!==U?(X=s.jsx(B,{type:"button",variant:"ghost",size:"sm",onClick:j,children:U}),e[88]=j,e[89]=U,e[90]=X):X=e[90];const Z=!I||p.settled&&(!!K||!!G);let ne;e[91]!==l?(ne=l("settings.openchamber.keyboardShortcuts.actions.confirm"),e[91]=l,e[92]=ne):ne=e[92];let le;e[93]!==R||e[94]!==Z||e[95]!==ne?(le=s.jsx(B,{type:"button",size:"sm",disabled:Z,onClick:R,children:ne}),e[93]=R,e[94]=Z,e[95]=ne,e[96]=le):le=e[96];let re;e[97]!==X||e[98]!==le?(re=s.jsxs(ms,{children:[X,le]}),e[97]=X,e[98]=le,e[99]=re):re=e[99];let fe;e[100]!==C||e[101]!==S||e[102]!==q||e[103]!==Q||e[104]!==M||e[105]!==W||e[106]!==Y||e[107]!==F||e[108]!==se||e[109]!==z||e[110]!==re?(fe=s.jsxs(C,{className:S,initialFocus:q,showCloseButton:Q,children:[M,W,Y,F,se,z,re]}),e[100]=C,e[101]=S,e[102]=q,e[103]=Q,e[104]=M,e[105]=W,e[106]=Y,e[107]=F,e[108]=se,e[109]=z,e[110]=re,e[111]=fe):fe=e[111];let ae;return e[112]!==T||e[113]!==_||e[114]!==V||e[115]!==fe?(ae=s.jsx(T,{open:_,onOpenChange:V,children:fe}),e[112]=T,e[113]=_,e[114]=V,e[115]=fe,e[116]=ae):ae=e[116],ae};function nf(t){return!t.action.customizable&&t.kind!=="contextual-prefix"}function af(t){return t.kind==="prefix"}function rf(t){return t.kind==="exact"}function of(t){return t.kind==="contextual-prefix"}function lf(t,e){t||e.cancel()}function cf(t){return{...t,livePreview:null}}function df(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:$n(t)},`${t}-${e}`)}const pf=["session","models","panels","navigation","application"],mf=()=>{const t=mt.c(24),{t:e}=ot(),a=ce(uf),n=ce(gf),i=ce(hf),r=ce(ff),[l,h]=o.useState(null);let d;if(t[0]===Symbol.for("react.memo_cache_sentinel")){const I=Qc();d=vs()?I.filter(xf):I,t[0]=d}else d=t[0];const x=d,c=bf;let v;t[1]!==n||t[2]!==a?(v=(I,w,m)=>{const y={...a,[I]:w};m&&(y[m]=Ti),n(I,w),m&&n(m,Ti),c(y)},t[1]=n,t[2]=a,t[3]=v):v=t[3];const p=v;let A;t[4]!==i||t[5]!==a?(A=I=>{const w={...a};delete w[I],i(I),c(w)},t[4]=i,t[5]=a,t[6]=A):A=t[6];const b=A;let P;t[7]!==a||t[8]!==e?(P=I=>{const w="prefixStyle"in I&&I.prefixStyle,m=w?Yc(I.id,a):hl(I.id,a),y=$n(m,e("settings.openchamber.keyboardShortcuts.unassigned"));if(!w||!m||m===Ti)return y;const K=I.id==="switch_session_tab"?e("settings.openchamber.keyboardShortcuts.action.switch_session_tab.suffix"):e("settings.openchamber.keyboardShortcuts.action.switch_context_surface.suffix");return`${y}${K}`},t[7]=a,t[8]=e,t[9]=P):P=t[9];const N=P;let k;t[10]!==r||t[11]!==b||t[12]!==N||t[13]!==a||t[14]!==e?(k=pf.map((I,w)=>{const m=x.filter(y=>y.category===I);return m.length===0?null:s.jsx(Be,{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:()=>{r(),c({})},children:e("settings.openchamber.keyboardShortcuts.actions.resetAll")}):void 0,children:s.jsx("div",{className:"space-y-2",children:m.map(y=>s.jsxs(Qt,{label:e(y.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:N(y)}),s.jsx(B,{type:"button",variant:"secondary",size:"xs",className:"!font-normal",onClick:()=>h(y),children:e("settings.openchamber.keyboardShortcuts.actions.edit")}),y.id in a?s.jsx(B,{type:"button",variant:"ghost",size:"xs",className:"!font-normal",onClick:()=>b(y.id),children:e("settings.common.actions.reset")}):null]},y.id))})},I)}),t[10]=r,t[11]=b,t[12]=N,t[13]=a,t[14]=e,t[15]=k):k=t[15];let g;t[16]===Symbol.for("react.memo_cache_sentinel")?(g=I=>{I||h(null)},t[16]=g):g=t[16];let E;t[17]!==l||t[18]!==p||t[19]!==a?(E=s.jsx(sf,{action:l,overrides:a,onSave:p,onOpenChange:g}),t[17]=l,t[18]=p,t[19]=a,t[20]=E):E=t[20];let O;return t[21]!==k||t[22]!==E?(O=s.jsxs(s.Fragment,{children:[k,E]}),t[21]=k,t[22]=E,t[23]=O):O=t[23],O};function uf(t){return t.shortcutOverrides}function gf(t){return t.setShortcutOverride}function hf(t){return t.clearShortcutOverride}function ff(t){return t.resetAllShortcutOverrides}function xf(t){return t.id!=="toggle_prompt_navigator"}function bf(t){Nt({shortcutOverrides:t})}const Yl=()=>{const t=mt.c(2),[e,a]=o.useState(0);let n,i;return t[0]===Symbol.for("react.memo_cache_sentinel")?(n=()=>bl(()=>a(Ef)),i=[],t[0]=n,t[1]=i):(n=t[0],i=t[1]),o.useEffect(n,i),e},vf=t=>{const e=mt.c(80),{section:a}=t,{t:n}=ot(),{isMobile:i}=da();Yl();let r;e[0]!==i?(r=i&&zn(),e[0]=i,e[1]=r):r=e[1];const l=r;let h;e[2]===Symbol.for("react.memo_cache_sentinel")?(h=vs(),e[2]=h):h=e[2];const d=h;let x;e[3]===Symbol.for("react.memo_cache_sentinel")?(x=bs()&&Fa(),e[3]=x):x=e[3];const c=x;if(!a){let F,se,_,V,z,U,X,Z;e[4]===Symbol.for("react.memo_cache_sentinel")?(_=s.jsx(pi,{}),V=s.jsx(Bl,{}),z=c&&s.jsx(Jl,{}),U=!d&&s.jsx(ql,{}),X=!d&&s.jsx(Wl,{}),Z=s.jsx(_l,{}),F=s.jsx(Vl,{}),se=zn()&&!bs()&&!d&&!jl()&&s.jsx($l,{}),e[4]=F,e[5]=se,e[6]=_,e[7]=V,e[8]=z,e[9]=U,e[10]=X,e[11]=Z):(F=e[4],se=e[5],_=e[6],V=e[7],z=e[8],U=e[9],X=e[10],Z=e[11]);let ne;e[12]!==l?(ne=l&&s.jsx(Sl,{}),e[12]=l,e[13]=ne):ne=e[13];let le;return e[14]!==ne?(le=s.jsxs(gs,{showSaveStatus:!0,className:"openchamber-page-body space-y-3 sm:space-y-6",children:[_,V,z,U,X,Z,F,se,ne]}),e[14]=ne,e[15]=le):le=e[15],le}let v;e[16]!==a?(v=()=>{switch(a){case"general":return s.jsx(jf,{});case"visual":return s.jsx(wf,{});case"chat":return s.jsx(kf,{});case"sessions":return s.jsx(Nf,{});case"shortcuts":return s.jsx(yf,{});case"git":return s.jsx(Sf,{});case"github":return s.jsx(Cf,{});case"notifications":return s.jsx(Pf,{});case"voice":return s.jsx(If,{});case"tunnel":return s.jsx(Af,{});default:return null}},e[16]=a,e[17]=v):v=e[17];const p=v;let A;e[18]!==n?(A=n("settings.page.general.title"),e[18]=n,e[19]=A):A=e[19];let b;e[20]!==n?(b=n("settings.page.appearance.title"),e[20]=n,e[21]=b):b=e[21];let P;e[22]!==n?(P=n("settings.page.chat.title"),e[22]=n,e[23]=P):P=e[23];let N;e[24]!==n?(N=n("settings.page.sessions.title"),e[24]=n,e[25]=N):N=e[25];let k;e[26]!==n?(k=n("settings.page.shortcuts.title"),e[26]=n,e[27]=k):k=e[27];let g;e[28]!==n?(g=n("settings.page.git.title"),e[28]=n,e[29]=g):g=e[29];let E;e[30]!==n?(E=n("settings.page.git.title"),e[30]=n,e[31]=E):E=e[31];let O;e[32]!==n?(O=n("settings.page.notifications.title"),e[32]=n,e[33]=O):O=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 m;e[38]!==g||e[39]!==E||e[40]!==O||e[41]!==I||e[42]!==w||e[43]!==A||e[44]!==b||e[45]!==P||e[46]!==N||e[47]!==k?(m={general:A,visual:b,chat:P,sessions:N,shortcuts:k,git:g,github:E,notifications:O,voice:I,tunnel:w},e[38]=g,e[39]=E,e[40]=O,e[41]=I,e[42]=w,e[43]=A,e[44]=b,e[45]=P,e[46]=N,e[47]=k,e[48]=m):m=e[48];const y=m[a];let K;e[49]!==n?(K=n("settings.page.general.description"),e[49]=n,e[50]=K):K=e[50];let C;e[51]!==n?(C=n("settings.page.appearance.description"),e[51]=n,e[52]=C):C=e[52];let T;e[53]!==n?(T=n("settings.page.chat.description"),e[53]=n,e[54]=T):T=e[54];let j;e[55]!==n?(j=n("settings.page.sessions.description"),e[55]=n,e[56]=j):j=e[56];let R;e[57]!==n?(R=n("settings.page.shortcuts.description"),e[57]=n,e[58]=R):R=e[58];let G;e[59]!==n?(G=n("settings.page.notifications.description"),e[59]=n,e[60]=G):G=e[60];let S;e[61]!==n?(S=n("settings.page.voice.description"),e[61]=n,e[62]=S):S=e[62];let q;e[63]!==n?(q=n("settings.page.tunnel.description"),e[63]=n,e[64]=q):q=e[64];let Q;e[65]!==K||e[66]!==C||e[67]!==T||e[68]!==j||e[69]!==R||e[70]!==G||e[71]!==S||e[72]!==q?(Q={general:K,visual:C,chat:T,sessions:j,shortcuts:R,git:void 0,github:void 0,notifications:G,voice:S,tunnel:q},e[65]=K,e[66]=C,e[67]=T,e[68]=j,e[69]=R,e[70]=G,e[71]=S,e[72]=q,e[73]=Q):Q=e[73];const M=Q[a];let W;e[74]!==p?(W=p(),e[74]=p,e[75]=W):W=e[75];let Y;return e[76]!==M||e[77]!==y||e[78]!==W?(Y=s.jsx(gs,{title:y,description:M,showSaveStatus:!0,className:"openchamber-page-body",children:W}),e[76]=M,e[77]=y,e[78]=W,e[79]=Y):Y=e[79],Y},yf=()=>{const t=mt.c(1);let e;return t[0]===Symbol.for("react.memo_cache_sentinel")?(e=s.jsx(mf,{}),t[0]=e):e=t[0],e},jf=()=>{const t=mt.c(10);let e;t[0]===Symbol.for("react.memo_cache_sentinel")?(e=vs(),t[0]=e):e=t[0];const a=e;Yl();let n;t[1]===Symbol.for("react.memo_cache_sentinel")?(n=bs()&&Fa(),t[1]=n):n=t[1];const i=n;let r;t[2]===Symbol.for("react.memo_cache_sentinel")?(r=zn()&&!bs()&&!a&&!jl(),t[2]=r):r=t[2];const l=r;let h,d,x,c,v;t[3]===Symbol.for("react.memo_cache_sentinel")?(h=i&&s.jsx(Jl,{}),d=l&&s.jsx($l,{}),x=s.jsx(Vl,{}),c=!a&&s.jsx(ql,{}),v=!a&&s.jsx(Wl,{}),t[3]=h,t[4]=d,t[5]=x,t[6]=c,t[7]=v):(h=t[3],d=t[4],x=t[5],c=t[6],v=t[7]);let p;t[8]===Symbol.for("react.memo_cache_sentinel")?(p=a?[]:["sessionTabs"],t[8]=p):p=t[8];let A;return t[9]===Symbol.for("react.memo_cache_sentinel")?(A=s.jsxs(s.Fragment,{children:[h,d,x,c,v,s.jsx(pi,{visibleSettings:["fileEditorKeymap",...p,"autoSaveEnabled",...a?[]:["terminalQuickKeys"],...a?[]:["terminalShell"],...a?[]:["terminalLoginShell"],"messageTransport","reportUsage"]})]}),t[9]=A):A=t[9],A},wf=()=>{const t=mt.c(2);let e;t[0]===Symbol.for("react.memo_cache_sentinel")?(e=vs(),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","inputBarOffset"]}),t[1]=n):n=t[1],n},kf=()=>{const t=mt.c(2);let e;t[0]===Symbol.for("react.memo_cache_sentinel")?(e=vs(),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","dotfiles","fileViewerPreview","followUpBehavior","persistDraft","inputSpellcheck"]}),t[1]=n):n=t[1],n},Nf=()=>{const t=mt.c(1);let e;return t[0]===Symbol.for("react.memo_cache_sentinel")?(e=s.jsxs(s.Fragment,{children:[s.jsx(Bl,{}),s.jsx(_l,{})]}),t[0]=e):e=t[0],e},Sf=()=>{const t=mt.c(1);let e;return t[0]===Symbol.for("react.memo_cache_sentinel")?(e=s.jsx(Ul,{}),t[0]=e):e=t[0],e},Cf=()=>{const t=mt.c(1);if(vs())return null;let e;return t[0]===Symbol.for("react.memo_cache_sentinel")?(e=s.jsx(zl,{}),t[0]=e):e=t[0],e},Pf=()=>{const t=mt.c(1);let e;return t[0]===Symbol.for("react.memo_cache_sentinel")?(e=s.jsx(Ih,{}),t[0]=e):e=t[0],e},If=()=>{const t=mt.c(1);if(vs())return null;let e;return t[0]===Symbol.for("react.memo_cache_sentinel")?(e=s.jsx(Mh,{}),t[0]=e):e=t[0],e},Af=()=>{const t=mt.c(1);if(vs())return null;let e;return t[0]===Symbol.for("react.memo_cache_sentinel")?(e=s.jsx(Vh,{}),t[0]=e):e=t[0],e};function Ef(t){return t+1}const Tf=t=>{const e=mt.c(85),{className:a}=t,{t:n}=ot(),i=dn(fl),r=dn(Df),l=ce(Mf),h=ce(Rf),[d,x]=Xe.useState(!1),[c,v]=Xe.useState(!1),p=i>0;let A;e[0]!==n?(A=async()=>{try{const we=await Zc({message:n("settings.view.pendingRestart.applying")});if(we.requiresManualRestart){D.warning(n("settings.view.pendingRestart.manualRestartRequired"));return}we.ok&&D.success(n("settings.view.pendingRestart.applied"))}catch(we){const ke=we,xe=ke instanceof Error&&ke.message?ke.message:n("settings.view.pendingRestart.applyFailed");D.error(xe)}},e[0]=n,e[1]=A):A=e[1];const b=A;let P;e[2]!==n?(P=async()=>{try{await Xc({message:n("settings.view.pendingRestart.applying"),mode:"projects",scopes:["all"]}),dn.getState().clear()}catch{}},e[2]=n,e[3]=P):P=e[3];const N=P;let k;e[4]!==c||e[5]!==b||e[6]!==h?(k=()=>{c&&h(!1),x(!1),v(!1),b()},e[4]=c,e[5]=b,e[6]=h,e[7]=k):k=e[7];const g=k;let E;e[8]!==p||e[9]!==b||e[10]!==N||e[11]!==l?(E=()=>{if(!p){N();return}if(l){v(!1),x(!0);return}b()},e[8]=p,e[9]=b,e[10]=N,e[11]=l,e[12]=E):E=e[12];const O=E;let I;e[13]!==p||e[14]!==r||e[15]!==n?(I=n(p?r?"settings.view.pendingRestart.applying":"settings.view.actions.applyAndRestartOpenCode":"settings.view.actions.reloadOpenCode"),e[13]=p,e[14]=r,e[15]=n,e[16]=I):I=e[16];const w=I;let m;e[17]!==p||e[18]!==i||e[19]!==n?(m=p?i===1?n("settings.view.actions.applyAndRestartOpenCodeTooltipSingle"):n("settings.view.actions.applyAndRestartOpenCodeTooltipPlural",{count:i}):n("settings.view.actions.reloadOpenCodeTooltip"),e[17]=p,e[18]=i,e[19]=n,e[20]=m):m=e[20];const y=m,K=p?"bg-primary text-primary-foreground typography-ui-label font-semibold hover:bg-primary/90":"text-sm font-semibold text-sidebar-foreground/90 hover:text-sidebar-foreground hover:bg-interactive-hover",C=r&&"opacity-80";let T;e[21]!==a||e[22]!==K||e[23]!==C?(T=je("flex w-full items-center gap-2 rounded-md overflow-hidden whitespace-nowrap","h-11 px-3 sm:h-8 sm:px-2","focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-primary/50",K,C,a),e[21]=a,e[22]=K,e[23]=C,e[24]=T):T=e[24];let j;e[25]!==p||e[26]!==i?(j=p?s.jsx("span",{className:je("inline-flex h-5 min-w-5 shrink-0 items-center justify-center rounded-full px-1.5","bg-background text-foreground typography-micro font-semibold tabular-nums"),"aria-hidden":"true",children:i}):s.jsx(L,{name:"restart",className:"h-4 w-4 shrink-0"}),e[25]=p,e[26]=i,e[27]=j):j=e[27];let R;e[28]!==w?(R=s.jsx("span",{className:"truncate",children:w}),e[28]=w,e[29]=R):R=e[29];let G;e[30]!==O||e[31]!==r||e[32]!==j||e[33]!==R||e[34]!==T||e[35]!==y?(G=s.jsxs("button",{type:"button",disabled:r,title:y,"aria-label":y,onClick:O,className:T,children:[j,R]}),e[30]=O,e[31]=r,e[32]=j,e[33]=R,e[34]=T,e[35]=y,e[36]=G):G=e[36];let S;e[37]===Symbol.for("react.memo_cache_sentinel")?(S=we=>{x(we),we||v(!1)},e[37]=S):S=e[37];let q;e[38]!==n?(q=n("settings.view.pendingRestart.confirm.title"),e[38]=n,e[39]=q):q=e[39];let Q;e[40]!==q?(Q=s.jsx(qt,{children:q}),e[40]=q,e[41]=Q):Q=e[41];let M;e[42]!==n?(M=n("settings.view.pendingRestart.confirm.description"),e[42]=n,e[43]=M):M=e[43];let W;e[44]!==M?(W=s.jsx(Wt,{children:M}),e[44]=M,e[45]=W):W=e[45];let Y;e[46]!==Q||e[47]!==W?(Y=s.jsxs(Gt,{children:[Q,W]}),e[46]=Q,e[47]=W,e[48]=Y):Y=e[48];let F;e[49]===Symbol.for("react.memo_cache_sentinel")?(F={width:"40%"},e[49]=F):F=e[49];let se;e[50]===Symbol.for("react.memo_cache_sentinel")?(se=()=>x(!1),e[50]=se):se=e[50];let _;e[51]!==n?(_=n("settings.view.pendingRestart.confirm.cancel"),e[51]=n,e[52]=_):_=e[52];let V;e[53]!==_?(V=s.jsx("div",{className:"min-w-0 shrink-0",style:F,children:s.jsx(B,{type:"button",variant:"outline",className:"h-9 w-full normal-case",onClick:se,children:_})}),e[53]=_,e[54]=V):V=e[54];let z;e[55]===Symbol.for("react.memo_cache_sentinel")?(z={width:"40%"},e[55]=z):z=e[55];let U;e[56]!==n?(U=n("settings.view.actions.applyAndRestartOpenCode"),e[56]=n,e[57]=U):U=e[57];let X;e[58]!==g||e[59]!==U?(X=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:g,children:U})}),e[58]=g,e[59]=U,e[60]=X):X=e[60];let Z;e[61]!==V||e[62]!==X?(Z=s.jsxs("div",{className:"flex w-full items-stretch justify-center gap-3",children:[V,X]}),e[61]=V,e[62]=X,e[63]=Z):Z=e[63];let ne;e[64]===Symbol.for("react.memo_cache_sentinel")?(ne=()=>v(Of),e[64]=ne):ne=e[64];let le;e[65]!==c?(le=c?s.jsx(L,{name:"checkbox",className:"h-4 w-4 text-primary"}):s.jsx(L,{name:"checkbox-blank",className:"h-4 w-4"}),e[65]=c,e[66]=le):le=e[66];let re;e[67]!==n?(re=n("settings.view.pendingRestart.confirm.dontShowAgain"),e[67]=n,e[68]=re):re=e[68];let fe;e[69]!==c||e[70]!==le||e[71]!==re?(fe=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":c,children:[le,re]}),e[69]=c,e[70]=le,e[71]=re,e[72]=fe):fe=e[72];let ae;e[73]!==Z||e[74]!==fe?(ae=s.jsxs("div",{className:"flex w-full flex-col items-center gap-3",children:[Z,fe]}),e[73]=Z,e[74]=fe,e[75]=ae):ae=e[75];let ie;e[76]!==Y||e[77]!==ae?(ie=s.jsxs(_t,{showCloseButton:!1,className:"max-w-md gap-5",children:[Y,ae]}),e[76]=Y,e[77]=ae,e[78]=ie):ie=e[78];let te;e[79]!==d||e[80]!==ie?(te=s.jsx(zt,{open:d,onOpenChange:S,children:ie}),e[79]=d,e[80]=ie,e[81]=te):te=e[81];let ye;return e[82]!==G||e[83]!==te?(ye=s.jsxs(s.Fragment,{children:[G,te]}),e[82]=G,e[83]=te,e[84]=ye):ye=e[84],ye};function Df(t){return t.isApplying}function Mf(t){return t.showOpenCodeRestartConfirm}function Rf(t){return t.setShowOpenCodeRestartConfirm}function Of(t){return!t}const Lf=[{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.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.persist-drafts",page:"chat",titleKey:"settings.openchamber.visual.field.persistDraftMessages",keywords:["draft","message"]},{id:"chat.composer",page:"chat",titleKey:"settings.openchamber.visual.section.composer",keywords:["input","draft","spellcheck"]},{id:"chat.spellcheck",page:"chat",titleKey:"settings.openchamber.visual.field.enableSpellcheckInTextInputs",keywords:["spelling","input"],isAvailable:t=>!t.isMobile},{id:"sessions.default-model",page:"sessions",titleKey:"settings.openchamber.defaults.field.defaultModel",keywords:["model","provider","new sessions"]},{id:"sessions.default-thinking",page:"sessions",titleKey:"settings.openchamber.defaults.field.defaultThinking",keywords:["thinking","reasoning","variant"]},{id:"sessions.default-agent",page:"sessions",titleKey:"settings.openchamber.defaults.field.defaultAgent",keywords:["agent","new sessions"]},{id:"sessions.deletion-dialog",page:"sessions",titleKey:"settings.openchamber.defaults.field.showDeletionDialog",keywords:["delete","confirmation"]},{id:"sessions.small-model",page:"sessions",titleKey:"settings.openchamber.defaults.smallModel.title",descriptionKey:"settings.openchamber.defaults.smallModel.description",keywords:["small model","utility","summary","recap","cheap","override"]},{id:"sessions.walkthrough-model",page:"sessions",titleKey:"settings.openchamber.defaults.walkthroughModel.title",descriptionKey:"settings.openchamber.defaults.walkthroughModel.description",keywords:["walkthrough","diff","review","changes","structured output","model","override"]},{id:"sessions.auto-cleanup",page:"sessions",titleKey:"settings.openchamber.sessionRetention.field.enableAutoCleanup",descriptionKey:"settings.openchamber.sessionRetention.tooltip",keywords:["retention","archive","delete"]},{id:"sessions.retention-period",page:"sessions",titleKey:"settings.openchamber.sessionRetention.field.retentionPeriod",keywords:["days","cleanup","retention"]},{id:"sessions.retention-action",page:"sessions",titleKey:"settings.openchamber.sessionRetention.field.whenSessionsExpire",keywords:["archive","delete","expire"]},{id:"sessions.desktop-launch-at-login",page:"general",titleKey:"settings.openchamber.desktopNetwork.field.launchAtLogin",descriptionKey:"settings.openchamber.desktopNetwork.field.launchAtLoginDescription",keywords:["desktop","startup","login","launch","background","autostart"],isAvailable:t=>t.isDesktopLocalOrigin},{id:"sessions.desktop-window-controls-position",page:"appearance",titleKey:"settings.openchamber.desktopNetwork.field.windowControlsPosition",descriptionKey:"settings.openchamber.desktopNetwork.field.windowControlsPositionDescription",keywords:["desktop","window","controls","minimize","maximize","close","titlebar","linux","windows"],isAvailable:t=>t.isDesktop&&(t.isWindows||!t.isMac)},{id:"sessions.desktop-window-controls-style",page:"appearance",titleKey:"settings.openchamber.desktopNetwork.field.windowControlsStyle",keywords:["desktop","window","controls","style","traffic","lights","classic","macos","titlebar"],isAvailable:t=>t.isDesktop&&(t.isWindows||!t.isMac)},{id:"sessions.desktop-mac-menu-bar",page:"general",titleKey:"settings.openchamber.desktopNetwork.field.macMenuBar",descriptionKey:"settings.openchamber.desktopNetwork.field.macMenuBarDescription",keywords:["desktop","menu bar","tray","status item","macos","background"],isAvailable:t=>t.isDesktopLocalOrigin&&t.isMac},{id:"sessions.desktop-minimize-to-tray",page:"general",titleKey:"settings.openchamber.desktopNetwork.field.minimizeToTray",descriptionKey:"settings.openchamber.desktopNetwork.field.minimizeToTrayDescription",keywords:["desktop","tray","system tray","minimize","close","background","windows","linux"],isAvailable:t=>t.isDesktopLocalOrigin&&(t.isWindows||t.isLinux)},{id:"sessions.desktop-keep-awake",page:"general",titleKey:"settings.openchamber.desktopNetwork.field.keepAwake",descriptionKey:"settings.openchamber.desktopNetwork.field.keepAwakeDescription",keywords:["desktop","sleep","awake","server","mobile","phone"],isAvailable:t=>t.isDesktopLocalOrigin},{id:"sessions.desktop-ui-password",page:"general",titleKey:"settings.openchamber.desktopPassword.field.password",descriptionKey:"settings.openchamber.desktopPassword.field.passwordDescription",keywords:["desktop","password","auth","login"],isAvailable:t=>t.isDesktopLocalOrigin},{id:"sessions.desktop-lan-access",page:"general",titleKey:"settings.openchamber.desktopNetwork.field.allowLanAccess",descriptionKey:"settings.openchamber.desktopNetwork.field.allowLanAccessDescription",keywords:["desktop","lan","network","phone","tablet"],isAvailable:t=>t.isDesktopLocalOrigin},{id:"sessions.opencode-binary",page:"general",titleKey:"settings.openchamber.opencodeCli.field.binaryPath",keywords:["opencode","cli","binary","path"],isAvailable:t=>!t.isVSCode},{id:"sessions.opencode-update-notifications",page:"general",titleKey:"settings.openchamber.opencodeCli.field.showUpdateNotifications",keywords:["opencode","cli","updates"],isAvailable:t=>!t.isVSCode&&!t.isWindowsArm64},{id:"sessions.agent-control-tool",page:"general",titleKey:"settings.openchamber.tools.field.agentControlTool",descriptionKey:"settings.openchamber.tools.field.agentControlToolInfo",keywords:["agent","tool","orchestration","openchamber","sessions","schedule","control"],isAvailable:t=>!t.isVSCode},{id:"sessions.agent-web-tool",page:"general",titleKey:"settings.openchamber.tools.field.agentWebTool",descriptionKey:"settings.openchamber.tools.field.agentWebToolInfo",keywords:["agent","tool","web","browser","page","preview","openchamber"],isAvailable:t=>!t.isVSCode},{id:"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&&ce.getState().agentMemoryFeatureAvailable},{id:"git.github-account",page:"git",titleKey:"settings.github.page.actions.connect",keywords:["github","account","oauth","prs","issues"]},{id:"git.identities",page:"git",titleKey:"settings.gitIdentities.page.section.title",descriptionKey:"settings.gitIdentities.page.empty.description",keywords:["identity","profile","author","email","credentials","signing","commit signing","ssh signing","gpg"]},{id:"git.changes-view",page:"git",titleKey:"settings.openchamber.git.changesViewTitle",keywords:["changes","flat list","tree view"]},{id:"git.gitmoji",page:"git",titleKey:"settings.openchamber.git.enableGitmoji",keywords:["commit","emoji"]},{id:"git.gitignored-files",page:"git",titleKey:"settings.openchamber.git.showGitignored",keywords:["ignored","files","gitignore"]},{id:"usage.work-status-panel",page:"usage",titleKey:"settings.usage.page.options.showInWorkStatus",descriptionKey:"settings.usage.page.options.showInWorkStatusTooltip",keywords:["quota","work","status","panel"]},{id:"usage.model-quotas",page:"usage",titleKey:"settings.usage.page.section.modelQuotas",keywords:["models","quota","limits","tokens"]},{id:"projects.name",page:"projects",titleKey:"settings.projects.page.field.projectName",keywords:["label","display name","project metadata"]},{id:"projects.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:"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.third-party",page:"integrations",titleKey:"settings.integrations.thirdParty.title",keywords:["plugin","provider","oauth","install","update","remove"]},{id:"integrations.third-party.opencode-claude",page:"integrations",titleKey:"settings.integrations.thirdParty.opencodeClaude.name",descriptionKey:"settings.integrations.thirdParty.opencodeClaude.description",keywords:["claude","anthropic","claude code","pro","max","agent sdk","@openchamber/opencode-claude"]},{id:"integrations.third-party.opencode-cursor-oauth",page:"integrations",titleKey:"settings.integrations.thirdParty.opencodeCursorOauth.name",descriptionKey:"settings.integrations.thirdParty.opencodeCursorOauth.description",keywords:["cursor","oauth","subscription","openai compatible","@openchamber/opencode-cursor"]}];function Zo(t){return t.trim().toLocaleLowerCase()}function Ff({query:t,runtimeCtx:e,visiblePageSlugs:a,t:n,getPageTitle:i}){const r=Zo(t);if(!r)return[];const l=a?new Set(a):null,h=r.split(/\s+/).filter(Boolean);return Lf.flatMap(d=>{if(l&&!l.has(d.page))return[];const x=Ia(d.page);if(!x||x.isAvailable&&!x.isAvailable(e)||d.isAvailable&&!d.isAvailable(e))return[];const c=n(d.titleKey),v=d.descriptionKey?n(d.descriptionKey):null,p=Zo([c,v,i(d.page),...d.keywords??[]].filter(Boolean).join(" "));return h.every(A=>p.includes(A))?[{...d,title:c,description:v,pageTitle:i(d.page)}]:[]})}const Xo=256,el=280,Zl="__openchamberSettingsDetail",Kf=["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"],Uf=["general","projects","opencode","content"],zf="__add_provider__";function _f(t,e){const a=vs(),n=!t&&zn();return{isVSCode:a,isWeb:n,isDesktop:t,isMobile:e}}function tl(t,e){return t.isAvailable?t.isAvailable(e):!0}function lr(t){return typeof t=="object"&&t!==null&&!Array.isArray(t)}function Pa(t,e){const a=new Set(e);let n=t,i=1;for(;a.has(n);)n=`${t}-${i}`,i+=1;return n}function Ji(t){if(!lr(t))return null;const e=t[Zl];if(!lr(e))return null;const a=e.page,n=e.stage;return typeof a!="string"||n!=="page-content"?null:{page:wl(a),stage:n}}function $f(){return typeof window>"u"||!lr(window.history.state)?{}:window.history.state}const fx=t=>{const e=mt.c(181),{onClose:a,forceMobile:n,isWindowed:i,visiblePageSlugs:r,initialMobileStage:l}=t,h=l===void 0?"nav":l,{t:d}=ot(),x=da(),c=n??x.isMobile,v=dn(fl),p=ce(Vf),A=ce(Bf),b=ce(Hf),P=ce(Gf);let N;e[0]!==p?(N=wl(p),e[0]=p,e[1]=N):N=e[1];const k=N,[g,E]=o.useState(h),O=o.useRef(h==="nav"?k:null);let I,w;e[2]!==c||e[3]!==b||e[4]!==k?(I=()=>{!c&&k==="home"&&b("general")},w=[c,b,k],e[2]=c,e[3]=b,e[4]=k,e[5]=I,e[6]=w):(I=e[5],w=e[6]),o.useEffect(I,w);const[m,y]=o.useState(""),[K,C]=o.useState(null),[T,j]=o.useState(0),R=o.useRef(null);let G;e[7]===Symbol.for("react.memo_cache_sentinel")?(G=[],e[7]=G):G=e[7];const S=o.useRef(G),q=o.useRef(0),Q=o.useRef(!1);let M;e[8]===Symbol.for("react.memo_cache_sentinel")?(M=bs(),e[8]=M):M=e[8];const W=M;let Y;e[9]===Symbol.for("react.memo_cache_sentinel")?(Y=bs()&&Fa(),e[9]=Y):Y=e[9];const F=Y;let se;e[10]===Symbol.for("react.memo_cache_sentinel")?(se=bs()&&typeof window<"u"&&window.__OPENCHAMBER_PLATFORM__==="darwin",e[10]=se):se=e[10];const _=se;let V;e[11]===Symbol.for("react.memo_cache_sentinel")?(V=bs()&&typeof window<"u"&&window.__OPENCHAMBER_PLATFORM__==="win32",e[11]=V):V=e[11];const z=V;let U;e[12]===Symbol.for("react.memo_cache_sentinel")?(U=bs()&&typeof window<"u"&&window.__OPENCHAMBER_PLATFORM__==="linux",e[12]=U):U=e[12];const X=U;let Z;e[13]===Symbol.for("react.memo_cache_sentinel")?(Z=yl(),e[13]=Z):Z=e[13];const ne=Z;let le;e[14]!==c?(le=_f(W,c),e[14]=c,e[15]=le):le=e[15];const re=le;let fe;if(e[16]!==c||e[17]!==re||e[18]!==r){const Ce=r?new Set(r):null;let it;e[20]!==re?(it=Tt=>tl(Tt,re),e[20]=re,e[21]=it):it=e[21];let jt;e[22]!==re.isVSCode?(jt=Tt=>!(re.isVSCode&&Tt.slug==="projects"),e[22]=re.isVSCode,e[23]=jt):jt=e[23];let At;e[24]!==c?(At=Tt=>!(c&&Tt.slug==="shortcuts"),e[24]=c,e[25]=At):At=e[25],fe=Td.filter(qf).filter(Tt=>!Ce||Ce.has(Tt.slug)).filter(it).filter(jt).filter(At),e[16]=c,e[17]=re,e[18]=r,e[19]=fe}else fe=e[19];const ae=fe;let ie;e[26]===Symbol.for("react.memo_cache_sentinel")?(ie=new Map(Kf.map(Wf)),e[26]=ie):ie=e[26];const te=ie;let ye;if(e[27]!==ae){let Ce;e[29]===Symbol.for("react.memo_cache_sentinel")?(Ce=(it,jt)=>(te.get(it.slug)??999)-(te.get(jt.slug)??999),e[29]=Ce):Ce=e[29],ye=ae.slice().sort(Ce),e[27]=ae,e[28]=ye}else ye=e[28];const we=ye,ke=Qs(Jf),xe=Us();let De;e[30]!==A||e[31]!==i||e[32]!==re.isVSCode||e[33]!==xe||e[34]!==k?(De=()=>{if(!(!A&&!re.isVSCode&&!i)){if(k==="agents"){_n.getState().loadAgents(xe);return}if(k==="commands"){la.getState().loadCommands(xe);return}if(k==="mcp"){ca.getState().loadMcpConfigs({directory:xe});return}if(k==="plugins"){fs.getState().loadPlugins();return}(k==="skills.installed"||k==="skills.catalog")&&($s.getState().loadSkills(xe),ln.getState().loadCatalog()),k==="snippets"&&ci.getState().loadSnippets()}},e[30]=A,e[31]=i,e[32]=re.isVSCode,e[33]=xe,e[34]=k,e[35]=De):De=e[35];let Me;e[36]!==ke||e[37]!==A||e[38]!==i||e[39]!==re.isVSCode||e[40]!==xe||e[41]!==k?(Me=[ke,A,i,re.isVSCode,xe,k],e[36]=ke,e[37]=A,e[38]=i,e[39]=re.isVSCode,e[40]=xe,e[41]=k,e[42]=Me):Me=e[42],o.useEffect(De,Me);let he;e[43]!==c||e[44]!==b?(he=Ce=>{if(b(Ce),O.current=Ce,!c)return;const it=Ia(Ce);if(!it||it.slug==="home"){E("nav");return}E(it.kind==="split"?"page-sidebar":"page-content")},e[43]=c,e[44]=b,e[45]=he):he=e[45];const ge=he;let Ae;e[46]!==c||e[47]!==ge?(Ae=async Ce=>{const it=tt.getState();return await it.loadProviders({source:"settings:third-party-provider-setup"}),tt.getState().providers.some(At=>At.id===Ce)?(it.setSelectedProvider(Ce),ge("providers"),c&&E("page-content"),!0):!1},e[46]=c,e[47]=ge,e[48]=Ae):Ae=e[48];const Ve=Ae;let _e;e[49]!==k?(_e=Ia(k),e[49]=k,e[50]=_e):_e=e[50];const Le=_e;let Re;e[51]===Symbol.for("react.memo_cache_sentinel")?(Re={general:"general",appearance:"visual",chat:"chat",shortcuts:"shortcuts",sessions:"sessions",notifications:"notifications",voice:"voice",tunnel:"tunnel"},e[51]=Re):Re=e[51];const Ze=Re;let Ge;e[52]!==d?(Ge=Ce=>{switch(Ce){case"general":return d("settings.page.general.title");case"projects":return d("settings.page.projects.title");case"remote-instances":return d("settings.page.remoteInstances.title");case"providers":return d("settings.page.providers.title");case"usage":return d("settings.page.usage.title");case"agents":return d("settings.page.agents.title");case"behavior":return d("settings.page.behavior.title");case"commands":return d("settings.page.commands.title");case"mcp":return d("settings.page.mcp.title");case"plugins":return d("settings.page.plugins.title");case"skills.installed":return d("settings.page.skills.title");case"skills.catalog":return d("settings.page.skillsCatalog.title");case"git":return d("settings.page.git.title");case"integrations":return d("settings.page.integrations.title");case"appearance":return d("settings.page.appearance.title");case"chat":return d("settings.page.chat.title");case"shortcuts":return d("settings.page.shortcuts.title");case"sessions":return d("settings.page.sessions.title");case"magic-prompts":return d("settings.page.magicPrompts.title");case"snippets":return d("settings.page.snippets.title");case"notifications":return d("settings.page.notifications.title");case"voice":return d("settings.page.voice.title");case"tunnel":return d("settings.page.tunnel.title");case"about":return d("settings.page.about.title");default:return d("settings.view.home.title")}},e[52]=d,e[53]=Ge):Ge=e[53];const Oe=Ge;let Ke;e[54]!==Oe||e[55]!==re||e[56]!==m||e[57]!==d||e[58]!==r?(Ke=Ff({query:m,runtimeCtx:{...re,isDesktopLocalOrigin:F,isMac:_,isWindows:z,isLinux:X,isWindowsArm64:ne},visiblePageSlugs:r,t:d,getPageTitle:Oe}),e[54]=Oe,e[55]=re,e[56]=m,e[57]=d,e[58]=r,e[59]=Ke):Ke=e[59];const Pe=Ke,Ue=tx;let ve;if(e[60]!==Pe){ve=[];const Ce=new Map;for(const it of Pe){let jt=Ce.get(it.page);jt||(jt={page:it.page,pageTitle:it.pageTitle,results:[]},Ce.set(it.page,jt),ve.push(jt)),jt.results.push(it)}e[60]=Pe,e[61]=ve}else ve=e[61];const We=ve;let $;e[62]===Symbol.for("react.memo_cache_sentinel")?($=()=>{j(0),q.current=0,Q.current=!1},e[62]=$):$=e[62];let de;e[63]!==m?(de=[m],e[63]=m,e[64]=de):de=e[64],o.useEffect($,de);let ue,Ne;e[65]!==T?(ue=()=>{q.current=T},Ne=[T],e[65]=T,e[66]=ue,e[67]=Ne):(ue=e[66],Ne=e[67]),o.useEffect(ue,Ne);let pe,Fe;e[68]!==T?(pe=()=>{S.current[T]?.scrollIntoView({block:"nearest"})},Fe=[T],e[68]=T,e[69]=pe,e[70]=Fe):(pe=e[69],Fe=e[70]),o.useEffect(pe,Fe);let H,He;e[71]!==T||e[72]!==Pe.length?(H=()=>{T>=Pe.length&&j(Math.max(0,Pe.length-1)),S.current.length=Pe.length},He=[T,Pe.length],e[71]=T,e[72]=Pe.length,e[73]=H,e[74]=He):(H=e[73],He=e[74]),o.useEffect(H,He);let et;e[75]!==c||e[76]!==ge?(et=Ce=>{const it=Ue(Ce);C(it),ge(Ce.page),c&&E("page-content"),Ce.id==="plugins.create"&&typeof window<"u"&&window.setTimeout(sx,50)},e[75]=c,e[76]=ge,e[77]=et):et=e[77];const ze=et;let st;e[78]!==ze||e[79]!==m||e[80]!==Pe?(st=Ce=>{if(m.trim()){if(Ce.key==="Escape"){Ce.preventDefault(),y("");return}if(Pe.length!==0){if(Ce.key==="ArrowDown"){Ce.preventDefault(),Q.current=!0,j(it=>(it+1)%Pe.length);return}if(Ce.key==="ArrowUp"){Ce.preventDefault(),Q.current=!0,j(it=>(it-1+Pe.length)%Pe.length);return}if(Ce.key==="Enter"){Ce.preventDefault();const it=(q.current%Pe.length+Pe.length)%Pe.length,jt=Pe[it]??Pe[0];jt&&ze(jt)}}}},e[78]=ze,e[79]=m,e[80]=Pe,e[81]=st):st=e[81];const wt=st;let xt;e[82]!==K?(xt=()=>{const Ce=K;if(!Ce)return;let it=!1;const jt=window.requestAnimationFrame(()=>{if(it)return;const At=typeof CSS<"u"&&CSS.escape?CSS.escape(Ce):Ce.replace(/[^a-zA-Z0-9_-]/g,"\\$&"),Tt=R.current?.querySelector(`[data-settings-item="${At}"]`);Tt&&(C(null),Tt.scrollIntoView({block:"center",behavior:"smooth"}),Tt.setAttribute("data-settings-search-highlight","true"),window.setTimeout(()=>{Tt.removeAttribute("data-settings-search-highlight")},1600))});return()=>{it=!0,window.cancelAnimationFrame(jt)}},e[82]=K,e[83]=xt):xt=e[83];let gt;e[84]!==K||e[85]!==k?(gt=[K,k],e[84]=K,e[85]=k,e[86]=gt):gt=e[86],o.useEffect(xt,gt);let bt;e[87]!==d?(bt=()=>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:pl,children:d("settings.view.unavailable.title")}),s.jsx("p",{className:"typography-ui text-muted-foreground mt-1",children:d("settings.view.unavailable.description")})]})}),e[87]=d,e[88]=bt):bt=e[88];const St=bt,yt=nx;let It;e[89]!==ge||e[90]!==Ve||e[91]!==St||e[92]!==re||e[93]!==d?(It=Ce=>{const it=Ia(Ce);if(it&&!tl(it,re))return St();switch(Ce){case"projects":return s.jsx(vu,{});case"remote-instances":return s.jsx(Uu,{});case"agents":return s.jsx(pp,{});case"behavior":return s.jsx(fp,{});case"commands":return s.jsx(Np,{});case"mcp":return s.jsx(qp,{});case"plugins":return s.jsx(Nm,{});case"skills.installed":return s.jsx(po,{view:"installed"});case"skills.catalog":return s.jsx(po,{view:"catalog"});case"providers":return s.jsx(yg,{});case"usage":return s.jsx(Lg,{});case"about":return s.jsx(gs,{title:d("settings.page.about.title"),showSaveStatus:!1,children:s.jsx(Sl,{})});case"magic-prompts":return s.jsx(_g,{});case"snippets":return s.jsx(Gg,{});case"git":return s.jsx(Yg,{});case"integrations":return s.jsx(ih,{onOpenProviderSetup:Ve,onOpenPluginManager:()=>ge("plugins")});case"general":case"appearance":case"chat":case"shortcuts":case"sessions":case"notifications":case"voice":case"tunnel":{const jt=Ze[Ce]??"visual";return s.jsx(vf,{section:jt})}default:return null}},e[89]=ge,e[90]=Ve,e[91]=St,e[92]=re,e[93]=d,e[94]=It):It=e[94];const qe=It;let Qe,dt;e[95]!==c||e[96]!==g||e[97]!==k?(Qe=()=>{if(!c||g!=="nav"||k==="home"||O.current===k)return;const Ce=Ia(k);!Ce||Ce.slug==="home"||(O.current=k,E(Ce.kind==="split"?"page-sidebar":"page-content"))},dt=[c,g,k],e[95]=c,e[96]=g,e[97]=k,e[98]=Qe,e[99]=dt):(Qe=e[98],dt=e[99]),o.useEffect(Qe,dt);const Ee=c&&g!=="nav",vt=c&&g==="page-content"&&k==="skills.installed",Se=g==="page-content"&&Le?.kind==="split"&&!vt;let kt;e[100]!==vt||e[101]!==Ee||e[102]!==d?(kt=d(vt?"settings.view.actions.back":Ee?"settings.view.actions.backToSettings":"settings.view.actions.closeSettings"),e[100]=vt,e[101]=Ee,e[102]=d,e[103]=kt):kt=e[103];const J=kt;let me;if(e[104]!==P||e[105]!==d){const Ce=hl("open_settings",P===void 0?void 0:{open_settings:P});me=Ce?d("settings.view.actions.closeSettingsWithShortcut",{shortcut:$n(Ce)}):d("settings.view.actions.closeSettings"),e[104]=P,e[105]=d,e[106]=me}else me=e[106];const Te=me;let Ie;e[107]!==re.isVSCode?(Ie=Ce=>{if(typeof window>"u"||re.isVSCode)return;const it=Ji(window.history.state);it?.page===Ce&&it.stage==="page-content"||window.history.pushState({...$f(),[Zl]:{page:Ce,stage:"page-content"}},"",window.location.href)},e[107]=re.isVSCode,e[108]=Ie):Ie=e[108];const lt=Ie;let at;e[109]!==lt||e[110]!==k?(at=()=>{E("page-content"),k==="skills.installed"&<(k)},e[109]=lt,e[110]=k,e[111]=at):at=e[111];const Je=at;let Ct;e[112]!==vt||e[113]!==re.isVSCode||e[114]!==k?(Ct=()=>{if(vt){if((typeof window<"u"?Ji(window.history.state):null)?.page===k&&!re.isVSCode){window.history.back();return}E("page-sidebar");return}E("nav")},e[112]=vt,e[113]=re.isVSCode,e[114]=k,e[115]=Ct):Ct=e[115];const rs=Ct;let Yt,ys;e[116]!==c||e[117]!==re.isVSCode||e[118]!==k?(Yt=()=>{if(!c||re.isVSCode)return;const Ce=it=>{if(k!=="skills.installed")return;if(Ji(it.state)?.page==="skills.installed"){E("page-content");return}E(ax)};return window.addEventListener("popstate",Ce),()=>{window.removeEventListener("popstate",Ce)}},ys=[c,re.isVSCode,k],e[116]=c,e[117]=re.isVSCode,e[118]=k,e[119]=Yt,e[120]=ys):(Yt=e[119],ys=e[120]),o.useEffect(Yt,ys);let $t;e[121]===Symbol.for("react.memo_cache_sentinel")?($t=()=>{E("page-sidebar")},e[121]=$t):$t=e[121];const cs=$t;let Kt,ds,as,ns,Zt,os;if(e[122]!==Le||e[123]!==T||e[124]!==Te||e[125]!==Oe||e[126]!==We||e[127]!==rs||e[128]!==Je||e[129]!==wt||e[130]!==c||e[131]!==i||e[132]!==J||e[133]!==g||e[134]!==a||e[135]!==ge||e[136]!==ze||e[137]!==v||e[138]!==qe||e[139]!==re.isVSCode||e[140]!==m||e[141]!==Pe.length||e[142]!==k||e[143]!==Ee||e[144]!==Se||e[145]!==we||e[146]!==d){const Ce=()=>{const Tt=m.trim().length>0;return s.jsxs("div",{className:"flex h-full flex-col overflow-hidden",children:[s.jsx("div",{className:"px-4 pt-3",children:s.jsxs("div",{className:"flex h-10 items-center gap-1.5 rounded-md border border-border bg-background/70 px-2 text-muted-foreground focus-within:ring-2 focus-within:ring-primary/40 sm:h-8",children:[s.jsx(L,{name:"search",className:"h-4 w-4 shrink-0"}),s.jsx("input",{value:m,onChange:Xt=>y(Xt.target.value),onKeyDown:wt,placeholder:d("settings.view.search.placeholder"),"aria-label":d("settings.view.search.aria"),className:"typography-ui min-w-0 flex-1 bg-transparent text-foreground outline-none placeholder:text-muted-foreground/70"}),Tt&&s.jsx("button",{type:"button",onClick:()=>y(""),"aria-label":d("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(L,{name:"close",className:"h-3.5 w-3.5"})})]})}),s.jsx("div",{className:"flex-1 min-h-0 overflow-y-auto overflow-x-hidden",children:s.jsx("div",{className:"flex flex-col gap-0.5 px-4 pt-4 pb-2",children:Tt?Pe.length>0?(()=>{let Xt=0;return We.map(ls=>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:ls.pageTitle}),ls.results.map(ft=>{const Pt=Xt;Xt=Xt+1;const Dt=Pt===T,Mt=!!ft.description;return s.jsxs("button",{type:"button",ref:Ut=>{S.current[Pt]=Ut},onMouseMove:()=>{Q.current=!1,j(Pt)},onClick:()=>ze(ft),className:je("flex w-full flex-col rounded-md px-2 text-left focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-primary/50",Mt?"min-h-11 py-1.5":"py-2",Dt?"bg-interactive-selection":"hover:bg-interactive-hover"),children:[s.jsx("span",{className:"typography-ui-label text-foreground truncate",children:ft.title}),Mt&&s.jsx("span",{className:"typography-micro text-muted-foreground/70 line-clamp-2",children:ft.description})]},ft.id)})]},ls.page))})():s.jsx("div",{className:"px-2 py-6 text-center typography-ui text-muted-foreground",children:d("settings.view.search.noResults")}):(()=>{const Xt=new Map;for(const ft of we){const Pt=ft.group,Dt=Xt.get(Pt);Dt?Dt.push(ft):Xt.set(Pt,[ft])}return Uf.map(ft=>({group:ft,pages:Xt.get(ft)??[]})).filter(ix).map((ft,Pt)=>{const{group:Dt,pages:Mt}=ft;return s.jsxs("div",{className:"space-y-0.5",children:[s.jsx("div",{className:je("px-3 pb-1 typography-micro font-semibold uppercase tracking-wide text-muted-foreground sm:px-2 sm:pb-0.5",Pt===0?"pt-1":"pt-4 sm:pt-3"),children:d(`settings.view.nav.group.${Dt}`)}),Mt.map(Ut=>{const js=k===Ut.slug&&!(c&&g==="nav"),Yn=Dd(Ut.slug);return!Yn&&Ut.slug!=="mcp"?null:s.jsx(pr,{children:s.jsx(mr,{asChild:!0,children:s.jsxs("button",{type:"button",onClick:()=>ge(Ut.slug),"aria-current":js?"page":void 0,className:je("flex h-11 w-full items-center gap-2.5 rounded-md px-3 overflow-hidden sm:h-8 sm:gap-2 sm:px-2",js?"bg-interactive-selection text-foreground":"text-foreground hover:bg-interactive-hover"),children:[Ut.slug==="mcp"?s.jsx(ed,{className:"h-[18px] w-[18px] shrink-0 sm:h-4 sm:w-4"}):s.jsx(L,{name:Yn,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:Oe(Ut.slug)}),(Ut.slug==="tunnel"||Ut.slug==="integrations")&&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:d("settings.view.badge.beta")})]})]})})},Ut.slug)})]},Dt)})})()})}),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:(!re.isVSCode||v>0)&&s.jsx(Tf,{})})})]})},it=()=>{if(g==="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(bn,{children:Ce()})})});if(!Le)return s.jsx("div",{className:"flex-1 bg-background"});if(g==="page-sidebar"){if(Le.kind!=="split"){const Xt=qe(k);return s.jsx("div",{className:"flex-1 min-h-0 overflow-y-scroll overflow-x-hidden bg-background",children:s.jsx(bn,{children:Xt})})}return s.jsx("div",{className:"flex-1 min-h-0 overflow-y-scroll overflow-x-hidden bg-background",children:s.jsx(bn,{children:yt(k,{onItemSelect:Je})})})}const Tt=qe(k);return s.jsx("div",{className:"flex-1 min-h-0 overflow-y-scroll overflow-x-hidden bg-background",children:s.jsx(bn,{children:Tt})})};let jt;e[153]!==Le||e[154]!==qe||e[155]!==re.isVSCode||e[156]!==k?(jt=()=>!Le||k==="home"?null:Le.kind==="split"?s.jsxs("div",{className:"flex h-full min-h-0 overflow-hidden",children:[s.jsx("div",{className:je("border-r",re.isVSCode?"bg-background":"bg-sidebar"),style:{width:el,minWidth:el,borderColor:"var(--interactive-border)"},children:s.jsx(bn,{children:yt(k,{})})}),s.jsx("div",{className:"flex-1 min-h-0 overflow-y-scroll overflow-x-hidden bg-background",children:s.jsx(bn,{children:qe(k)})})]}):s.jsx("div",{className:"h-full min-h-0 overflow-y-scroll overflow-x-hidden bg-background",children:s.jsx(bn,{children:qe(k)})}),e[153]=Le,e[154]=qe,e[155]=re.isVSCode,e[156]=k,e[157]=jt):jt=e[157];const At=jt;as=R,ns="true",e[158]===Symbol.for("react.memo_cache_sentinel")?(Zt=je("relative flex h-full min-h-0 flex-col overflow-hidden bg-background"),e[158]=Zt):Zt=e[158],e[159]!==Le||e[160]!==Te||e[161]!==Oe||e[162]!==rs||e[163]!==c||e[164]!==i||e[165]!==J||e[166]!==g||e[167]!==a||e[168]!==Ee||e[169]!==Se||e[170]!==d?(os=c?s.jsxs("div",{className:je("flex h-[var(--oc-header-height,56px)] shrink-0 items-center gap-2 px-3",g!=="nav"&&"border-b","bg-background"),style:g!=="nav"?{borderColor:"var(--interactive-border)"}:void 0,children:[Ee?s.jsx("button",{type:"button",onClick:rs,"aria-label":J,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(L,{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:g==="nav"?d("settings.view.home.title"):Le?Oe(Le.slug):d("settings.view.home.title")}),Se&&s.jsx("button",{type:"button",onClick:cs,"aria-label":d("settings.view.actions.openSectionList"),className:"inline-flex h-9 w-9 flex-shrink-0 items-center justify-center rounded-lg p-2 text-muted-foreground hover:text-foreground hover:bg-interactive-hover/50 focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-primary",children:s.jsx(L,{name:"list-unordered",className:"h-5 w-5"})}),a&&s.jsx("button",{type:"button",onClick:a,"aria-label":d("settings.view.actions.closeSettings"),title:Te,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(L,{name:"close",className:"h-5 w-5"})})]}):s.jsxs(s.Fragment,{children:[Ee&&s.jsx("div",{className:je("absolute left-3 z-50",i?"top-2":"top-3"),children:s.jsx("button",{type:"button",onClick:rs,"aria-label":d("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(L,{name:"arrow-left-s",className:"h-5 w-5"})})}),a&&s.jsx("div",{className:je("absolute right-0.5 z-50",i?"top-0.5":"top-1"),children:s.jsx("button",{type:"button",onClick:a,"aria-label":d("settings.view.actions.closeSettings"),title:Te,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(L,{name:"close",className:"h-5 w-5"})})})]}),e[159]=Le,e[160]=Te,e[161]=Oe,e[162]=rs,e[163]=c,e[164]=i,e[165]=J,e[166]=g,e[167]=a,e[168]=Ee,e[169]=Se,e[170]=d,e[171]=os):os=e[171],Kt="flex flex-1 min-h-0 overflow-hidden",ds=c?it():s.jsxs(s.Fragment,{children:[s.jsx("div",{className:je("relative flex h-full min-h-0 flex-col overflow-hidden border-r",W?"bg-sidebar":re.isVSCode?"bg-background":"bg-sidebar"),style:{width:`${Xo}px`,minWidth:`${Xo}px`,borderColor:"var(--interactive-border)"},children:s.jsx(bn,{children:Ce()})}),s.jsx("div",{className:"flex-1 overflow-hidden bg-background",children:At()})]}),e[122]=Le,e[123]=T,e[124]=Te,e[125]=Oe,e[126]=We,e[127]=rs,e[128]=Je,e[129]=wt,e[130]=c,e[131]=i,e[132]=J,e[133]=g,e[134]=a,e[135]=ge,e[136]=ze,e[137]=v,e[138]=qe,e[139]=re.isVSCode,e[140]=m,e[141]=Pe.length,e[142]=k,e[143]=Ee,e[144]=Se,e[145]=we,e[146]=d,e[147]=Kt,e[148]=ds,e[149]=as,e[150]=ns,e[151]=Zt,e[152]=os}else Kt=e[147],ds=e[148],as=e[149],ns=e[150],Zt=e[151],os=e[152];let oe;e[172]!==Kt||e[173]!==ds?(oe=s.jsx("div",{className:Kt,children:ds}),e[172]=Kt,e[173]=ds,e[174]=oe):oe=e[174];let ct;return e[175]!==as||e[176]!==ns||e[177]!==Zt||e[178]!==os||e[179]!==oe?(ct=s.jsxs("div",{ref:as,"data-settings-view":ns,className:Zt,children:[os,oe]}),e[175]=as,e[176]=ns,e[177]=Zt,e[178]=os,e[179]=oe,e[180]=ct):ct=e[180],ct};function Vf(t){return t.settingsPage}function Bf(t){return t.isSettingsDialogOpen}function Hf(t){return t.setSettingsPage}function Gf(t){return t.shortcutOverrides.open_settings}function qf(t){return t.slug!=="home"}function Wf(t,e){return[t,e]}function Jf(t){return t.activeProjectId}function Qf(t){return t.name}function Yf(t){return t.name}function Zf(t){return t.name}function Xf(t){return t.name}function ex(t){return t.name}function tx(t){if(t.id.startsWith("agents.")){const e=_n.getState(),a=Pa("new-agent",e.agents.map(Qf));return e.setAgentDraft({name:a,scope:"user"}),e.setSelectedAgent(a),t.id==="agents.create"?"agents.name":t.id}if(t.id.startsWith("commands.")){const e=la.getState(),a=Pa("new-command",e.commands.map(Yf));return e.setCommandDraft({name:a,scope:"user"}),e.setSelectedCommand(a),t.id==="commands.create"?"commands.name":t.id}if(t.id.startsWith("mcp.")){const e=ca.getState(),a=Pa("new-mcp-server",e.mcpServers.map(Zf));return e.setMcpDraft({name:a,scope:"user",type:"local",command:[],url:"",environment:[],headers:[],oauthEnabled:!0,oauthClientId:"",oauthClientSecret:"",oauthScope:"",oauthRedirectUri:"",timeout:"",enabled:!0}),e.setSelectedMcp(a),t.id==="mcp.create"?"mcp.server":t.id}if(t.id.startsWith("snippets.")){const e=ci.getState(),a=Pa("new-snippet",e.snippets.map(Xf));return e.setSnippetDraft({name:a,scope:"global"}),e.setSelectedSnippet(a),t.id==="snippets.create"?"snippets.content":t.id}if(t.id.startsWith("skills.")){const e=$s.getState(),a=Pa("new-skill",e.skills.map(ex));return e.setSkillDraft({name:a,scope:"user",source:"opencode",description:"",instructions:""}),e.setSelectedSkill(a),t.id==="skills.create"?"skills.basic-information":t.id}return t.id==="providers.connect"&&tt.getState().setSelectedProvider(zf),t.id==="plugins.create"?"plugins.spec":t.id}function sx(){window.dispatchEvent(new CustomEvent("openchamber:settings-open-plugin-add"))}function nx(t,e){switch(t){case"projects":return s.jsx(gu,{onItemSelect:e.onItemSelect});case"agents":return s.jsx(ep,{onItemSelect:e.onItemSelect});case"commands":return s.jsx(xp,{onItemSelect:e.onItemSelect});case"mcp":return s.jsx(Sp,{onItemSelect:e.onItemSelect});case"plugins":return s.jsx(mm,{onItemSelect:e.onItemSelect});case"skills.installed":return s.jsx(Cm,{onItemSelect:e.onItemSelect});case"providers":return s.jsx($u,{onItemSelect:e.onItemSelect});case"usage":return s.jsx(wg,{onItemSelect:e.onItemSelect});case"magic-prompts":return s.jsx(Kg,{onItemSelect:e.onItemSelect});case"snippets":return s.jsx($g,{onItemSelect:e.onItemSelect});default:return null}}function ax(t){return t==="page-content"?"page-sidebar":t}function ix(t){return t.pages.length>0}export{Sl as A,fx as S};
|