@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
|
@@ -0,0 +1,28 @@
|
|
|
1
|
+
import{R as o,j as s,f as lt,r as Qe}from"./vendor-react-BUCujlKS.js";import{f as nt,B,I as L,o as In,bo as da,t as D,O as sc,fv as nc,eo as $e,fw as It,b as qs,h as we,fx as ac,a$ as Zs,b1 as en,fy as ic,b2 as tn,ef as Un,fz as nl,fA as rc,fB as ia,fC as nn,c0 as Vs,bE as Rt,bF as Ot,bG as Kt,bH as Ut,bI as zt,bJ as es,S as We,fD as La,a_ as sn,e3 as Qi,fE as al,fF as Rn,eq as Jt,fG as Gs,l as et,eC as Vt,bS as At,bT as Et,eA as $t,bU as Ft,bV as Tt,bW as ot,fH as Wt,bX as Is,dr as Da,eB as Sn,eE as oa,eD as Cn,fI as hs,dw as Ss,fJ as Ps,fK as oc,ck as pt,fL as il,fM as lc,fN as Fn,fO as rl,fP as cc,fQ as la,fR as $s,fS as ra,fT as ol,fU as cr,ds as ll,fV as gn,a5 as ca,a4 as Os,fW as cl,fX as Cr,aa as dc,e1 as dl,g as Ma,fY as pc,fZ as Xs,e0 as mc,f_ as uc,f$ as gc,g0 as dr,a6 as pr,a7 as mr,a8 as pl,g1 as mn,a0 as li,b9 as ur,L as gr,g2 as Pr,al as hc,bY as fc,cB as xc,Q as bc,N as vc,R as yc,V as ml,g3 as jc,g4 as wc,bP as kc,bZ as Yi,g5 as ul,a9 as Pi,g6 as gl,P as On,g7 as Nn,en as Us,e8 as hl,$ as Nc,n as ss,dX as ci,x as fl,w as Sc,i as Cc,j as Pc,dY as Ic,p as Ac,g8 as Ec,g9 as Tc,ga as Ir,dx as xl,gb as Dc,gc as Ii,gd as Ar,ge as Mc,gf as Rc,gg as Oc,gh as Lc,dD as di,gi as fs,gj as Ks,gk as dn,gl as pn,as as va,gm as kn,gn as bn,go as Fa,gp as Er,gq as ya,gr as ja,bB as zn,gs as Fc,gt as Kc,gu as Uc,gv as zc,gw as Ai,gx as Tr,gy as _c,gz as $c,gA as Vc,gB as Bc,gC as Dr,y as Hc,m as Mr,cO as Gc,gD as qc,gE as Ei,gF as Rr,d_ as Wc,gG as mi,gH as Jc,gI as Qc,gJ as Yc,gK as Xc,gL as Zc,gM as Ti,cl as ed,bC as bl,gN as vl,gO as td,an as vn,ap as sd}from"./useAppFontEffects-KP8_yiGW.js";import{r as rt,u as de,F as ps,cC as nd,cD as Or,w as un,ap as Di,W as ad,$ as xt,o as Pn,z as ds,K as Lr,c5 as Fr,c8 as Kr,L as wa,p as id,cE as rd,j as od,c4 as aa,cF as ld,a8 as cd,c7 as dd,cG as pd,cH as md,s as ud,e as Ka,c6 as gd,A as Ua,cI as yl,S as hd,cJ as fd,R as xd,aG as Ur,aw as bd,_ as Kn,cK as vd,v as jl,cL as zr,cB as _r,cM as $r,au as Vr,cN as yd,cO as jd,cP as Br,b as wd,as as wl,cQ as kl,cR as kd,cS as Nd,cT as Sd,cU as Cd,cV as Pd,cW as Id,aj as Ad,i as Nl}from"./index-DIvDEKE-.js";import{u as Ed,U as Hr,w as _n,y as $n,z as Vn,A as Bn,b as hr,q as Hn,v as Gn,s as qn,R as Ln,F as Td,h as Cs,M as Dd,V as Ea,X as Sl,B as Md,E as Rd}from"./runtimeEndpointReset-D6SmNZaP.js";import{u as Ds,c as Cl,d as Od,p as Ld}from"./vendor-zustand-BAGL70zf.js";import{s as Fd,p as Kd}from"./vendor-yaml-3778uTud.js";import{c as Gr,s as Ud,C as qr,P as zd}from"./shikiHighlight-fGmFkxAM.js";import{getResolvedShikiTheme as _d}from"./appThemeRegistry-BK0dHKa6.js";import{E as Wr}from"./vendor-codemirror-view-CiLROUVV.js";import{Q as Pl}from"./vendor-qrcode-DTJ12-WC.js";const Jr=()=>{const{t}=nt(),[e,a]=o.useState(null);o.useEffect(()=>{let i=!1;const r=typeof AbortController<"u"?new AbortController:void 0;return(async()=>{try{const u=await rt("/api/system/info",{signal:r?.signal,headers:{Accept:"application/json"}});if(!u.ok)return;const g=await u.json().catch(()=>null);if(!g||i)return;const x=typeof g.port=="number"&&Number.isFinite(g.port)&&g.port>0?g.port:null,d=typeof g.tunnelUrl=="string"&&g.tunnelUrl.trim().length>0?g.tunnelUrl.trim():null;a({port:x,tunnelUrl:d})}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:()=>{In(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",$d="https://discord.gg/ZYRSdnwwKA",Yr="https://x.com/openchamber_dev",Vd=800,Il=({initialUpdateDialogOpen:t=!1})=>{const{t:e}=nt(),[a,n]=o.useState(t),[i,r]=o.useState(!1),[l,u]=o.useState(null),[g,x]=o.useState(null),d=Ed(Ds(C=>({info:C.info,checking:C.checking,available:C.available,error:C.error,downloading:C.downloading,downloaded:C.downloaded,progress:C.progress,runtimeType:C.runtimeType,checkForUpdates:C.checkForUpdates,downloadUpdate:C.downloadUpdate,restartToUpdate:C.restartToUpdate}))),{isMobile:v}=da(),c=l||d.info?.currentVersion||"unknown";o.useEffect(()=>{let C=!1;return(async()=>{try{const A=await rt("/api/system/info",{method:"GET",headers:{Accept:"application/json"}});if(!A.ok)return;const h=await A.json().catch(()=>null),E=typeof h?.openchamberVersion=="string"&&h.openchamberVersion.trim().length>0?h.openchamberVersion.trim():null;C||u(E)}catch{C||u(null)}})(),()=>{C=!0}},[]),o.useEffect(()=>{let C=!1;return(async()=>{try{const A=await rt("/api/opencode/upgrade-status",{method:"GET",headers:{Accept:"application/json"}});if(!A.ok)return;const h=await A.json().catch(()=>null),E=typeof h?.currentVersion=="string"&&h.currentVersion.trim().length>0?h.currentVersion.trim():null;C||x(E)}catch{C||x(null)}})(),()=>{C=!0}},[]);const N=o.useRef(!1);o.useEffect(()=>{if(d.checking)r(!0),N.current=!0;else if(i){const C=setTimeout(()=>{r(!1),N.current&&!d.available&&!d.error&&(D.success(e("settings.openchamber.about.toast.latestVersion")),N.current=!1)},Vd);return()=>clearTimeout(C)}},[e,d.checking,i,d.available,d.error]);const b=d.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(sc,{width:72,height:72}),s.jsx("h2",{className:`mt-4 ${nc}`,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:c})}),s.jsx("p",{children:e("aboutDialog.openCodeVersionLabel",{version:g||e("settings.openchamber.about.state.unknown")})})]}),s.jsx(Jr,{})]}),s.jsxs("div",{className:"flex justify-center",children:[!d.available&&!d.error&&s.jsxs(B,{type:"button",variant:"outline",size:"sm",onClick:()=>d.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&&d.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:d.info?.version||""})]})]}),d.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:d.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:$d,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:d.info,downloading:d.downloading,downloaded:d.downloaded,progress:d.progress,error:d.error,onDownload:d.downloadUpdate,onRestart:d.restartToUpdate,runtimeType:d.runtimeType})]}):s.jsxs($e,{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:It,children:e("settings.openchamber.about.field.version")}),s.jsx("span",{className:"typography-meta text-muted-foreground font-mono",children:c})]}),s.jsxs("div",{className:"flex min-w-0 flex-col",children:[s.jsx("span",{className:It,children:e("settings.openchamber.about.field.openCodeVersion")}),s.jsx("span",{className:"typography-meta text-muted-foreground font-mono",children:g||e("settings.openchamber.about.state.unknown")})]}),s.jsxs("div",{className:"flex items-center gap-3",children:[d.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")})]}),!d.checking&&d.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:d.info?.version||""})]}),!d.checking&&!d.available&&!d.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:()=>d.checkForUpdates(),disabled:d.checking,children:e("settings.openchamber.about.actions.checkForUpdates")})]})]}),d.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:d.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:It,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:d.info,downloading:d.downloading,downloaded:d.downloaded,progress:d.progress,error:d.error,onDownload:d.downloadUpdate,onRestart:d.restartToUpdate,runtimeType:d.runtimeType})]})},Bd=(t,e,a)=>t&&e.some(i=>i.path===t)?t:(e.find(i=>i.id===a)??e[0])?.path??null,zs=()=>{const t=lt.c(4),e=de(Hd),a=qs(Gd),n=qs(qd);let i;return t[0]!==n||t[1]!==a||t[2]!==e?(i=Bd(e,a,n),t[0]=n,t[1]=a,t[2]=e,t[3]=i):i=t[3],i};function Hd(t){return t.settingsProjectPath}function Gd(t){return t.projects}function qd(t){return t.activeProjectId}const Al=t=>t.trim(),za=t=>{const e=lt.c(40),{className:a}=t,{t:n}=nt(),i=qs(Wd),r=zs(),l=de(Jd),u=ps();let g;e[0]!==i?(g=[...i].sort(Qd),e[0]=i,e[1]=g):g=e[1];const x=g;let d;e:{if(x.length===0){d=null;break e}let H;e[2]!==r||e[3]!==x?(H=x.find(P=>P.path===r)??x[0],e[2]=r,e[3]=x,e[4]=H):H=e[4],d=H}const v=d;if(u||x.length===0)return null;let c;e[5]!==v||e[6]!==n?(c=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]=c):c=e[7];const N=c;let b;e[8]!==N?(b=Al(N),e[8]=N,e[9]=b):b=e[9];const C=b;let k;e[10]!==a?(k=we(a),e[10]=a,e[11]=k):k=e[11];let A;e[12]!==n?(A=n("settings.shared.projectSelector.switchProjectAria"),e[12]=n,e[13]=A):A=e[13];let h;e[14]!==n?(h=n("settings.shared.projectSelector.switchProjectTitle"),e[14]=n,e[15]=h):h=e[15];let E,F;e[16]===Symbol.for("react.memo_cache_sentinel")?(E=we("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"),F=s.jsx(L,{name:"folder",className:"h-4 w-4 opacity-70"}),e[16]=E,e[17]=F):(E=e[16],F=e[17]);let I;e[18]!==C?(I=s.jsx("span",{className:"min-w-0 flex-1 truncate typography-ui-label font-medium",children:C}),e[18]=C,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]!==A||e[23]!==h?(m=s.jsx(Zs,{asChild:!0,children:s.jsxs("button",{type:"button","aria-label":A,title:h,className:E,children:[F,I,w]})}),e[21]=I,e[22]=A,e[23]=h,e[24]=m):m=e[24];const y=v?.id??"";let U;e[25]!==l||e[26]!==x?(U=H=>{if(!H)return;const P=x.find(G=>G.id===H);P&&l(P.path)},e[25]=l,e[26]=x,e[27]=U):U=e[27];let S;e[28]!==x?(S=x.map(Yd),e[28]=x,e[29]=S):S=e[29];let M;e[30]!==y||e[31]!==U||e[32]!==S?(M=s.jsx(en,{align:"start",className:"w-auto",children:s.jsx(ic,{value:y,onValueChange:U,children:S})}),e[30]=y,e[31]=U,e[32]=S,e[33]=M):M=e[33];let j;e[34]!==m||e[35]!==M?(j=s.jsxs(tn,{children:[m,M]}),e[34]=m,e[35]=M,e[36]=j):j=e[36];let R;return e[37]!==j||e[38]!==k?(R=s.jsx("div",{className:k,children:j}),e[37]=j,e[38]=k,e[39]=R):R=e[39],R};function Wd(t){return t.projects}function Jd(t){return t.setSettingsProjectPath}function Qd(t,e){return(t.label||t.path).localeCompare(e.label||e.path)}function Yd(t){const e=t.label?.trim()?t.label.trim():t.path.split("/").filter(Boolean).pop()||t.path,a=Al(e);return s.jsx(ac,{value:t.id,children:s.jsx("span",{className:"min-w-0 truncate typography-ui",children:a})},t.id)}function Xd(t,e){return`opencode:sidebar-group:${t}:${e}`}const Xi=t=>{const e=lt.c(33),{label:a,count:n,storageKey:i,defaultExpanded:r,children:l}=t,u=r===void 0?!0:r;let g;e[0]!==a||e[1]!==i?(g=Xd(i,a),e[0]=a,e[1]=i,e[2]=g):g=e[2];const x=g,d=o.useId();let v;e[3]!==u||e[4]!==x?(v=()=>{try{const M=localStorage.getItem(x);if(M!==null)return M==="true"}catch{}return u},e[3]=u,e[4]=x,e[5]=v):v=e[5];const[c,N]=Qe.useState(v);let b,C;e[6]!==c||e[7]!==x?(b=()=>{try{localStorage.setItem(x,String(c))}catch{}},C=[x,c],e[6]=c,e[7]=x,e[8]=b,e[9]=C):(b=e[8],C=e[9]),Qe.useEffect(b,C);let k;e[10]===Symbol.for("react.memo_cache_sentinel")?(k=()=>N(Zd),e[10]=k):k=e[10];let A;e[11]===Symbol.for("react.memo_cache_sentinel")?(A=we("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]=A):A=e[11];const h=!c&&"-rotate-90";let E;e[12]!==h?(E=we("h-3.5 w-3.5 flex-shrink-0 transition-transform duration-200",h),e[12]=h,e[13]=E):E=e[13];let F;e[14]!==E?(F=s.jsx(L,{name:"arrow-down-s",className:E}),e[14]=E,e[15]=F):F=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]!==d||e[21]!==c||e[22]!==F||e[23]!==I||e[24]!==w?(m=s.jsxs("button",{type:"button",onClick:k,"aria-expanded":c,"aria-controls":d,className:A,children:[F,I,w]}),e[20]=d,e[21]=c,e[22]=F,e[23]=I,e[24]=w,e[25]=m):m=e[25];const y=!c;let U;e[26]!==l||e[27]!==d||e[28]!==y?(U=s.jsx("div",{id:d,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]=d,e[28]=y,e[29]=U):U=e[29];let S;return e[30]!==m||e[31]!==U?(S=s.jsxs("div",{children:[m,U]}),e[30]=m,e[31]=U,e[32]=S):S=e[32],S};function Zd(t){return!t}const ep=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},tp=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())},Xr=t=>{const e=tp(ep(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},sp=({onItemSelect:t})=>{const{t:e}=nt(),[a,n]=o.useState(null),[i,r]=o.useState(""),[l,u]=o.useState(null),[g,x]=o.useState(null),[d,v]=o.useState(!1),[c,N]=o.useState(null),{selectedAgentName:b,setSelectedAgent:C,setAgentDraft:k,createAgent:A,deleteAgent:h,loadAgents:E}=Un(Ds(K=>({selectedAgentName:K.selectedAgentName,setSelectedAgent:K.setSelectedAgent,setAgentDraft:K.setAgentDraft,createAgent:K.createAgent,deleteAgent:K.deleteAgent,loadAgents:K.loadAgents}))),F=zs(),I=Un(K=>nl(K,F));o.useEffect(()=>{E(F)},[E,F]);const w="bg-background",m=()=>{const K="new-agent";let te=K,$=1;for(;I.some(V=>V.name===te);)te=`${K}-${$}`,$++;k({name:te,scope:"user"}),C(te),t?.()},y=async K=>{if(ia(K)){D.error(e("settings.agents.sidebar.toast.builtInCannotDelete"));return}u(K),x("delete")},U=async K=>{ia(K)&&(u(K),x("reset"))},S=()=>{u(null),x(null)},M=async()=>{if(!(!l||!g)){v(!0);try{const K=await h(l.name,l.scope,F);K.ok?(K.requiresManualRestart?D.warning(e("settings.agents.page.toast.savedManualRestart")):K.restartDeferred?D.success(e("settings.view.pendingRestart.saved")):g==="delete"?D.success(e("settings.agents.sidebar.toast.agentDeleted",{name:l.name})):D.success(e("settings.agents.sidebar.toast.agentReset",{name:l.name})),S()):g==="delete"?D.error(e("settings.agents.sidebar.toast.deleteFailed")):D.error(e("settings.agents.sidebar.toast.resetFailed"))}catch(K){const te=K instanceof Error?K.message:"",$=/built-in|not deletable|not found/i.test(te);g==="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=K=>{const te=K.name;let $=1,V=`${te}-copy`;for(;I.some(Y=>Y.name===V);)$++,V=`${te}-copy-${$}`;const _=K,z=K.model?.providerID&&K.model?.modelID?`${K.model.providerID}/${K.model.modelID}`:null,Z=K;k({name:V,scope:_.scope||"user",description:K.description,model:z,variant:K.variant,temperature:K.temperature,top_p:K.topP,prompt:K.prompt,mode:K.mode,permission:Xr(K.permission),disable:Z.disable}),C(V),t?.()},R=K=>{r(K.name),n(K)},H=async()=>{if(!a)return;const K=i.trim().replace(/\s+/g,"-");if(!K){D.error(e("settings.agents.sidebar.toast.agentNameRequired"));return}if(K===a.name){n(null);return}if(I.some(_=>_.name===K)){D.error(e("settings.agents.sidebar.toast.agentExists"));return}const te=a.model?.providerID&&a.model?.modelID?`${a.model.providerID}/${a.model.modelID}`:null,$=a,V=await A({name:K,description:a.description,model:te,variant:a.variant,temperature:a.temperature,top_p:a.topP,prompt:a.prompt,mode:a.mode,permission:Xr(a.permission),disable:$.disable,scope:$.scope},F);if(V.ok){const _=await h(a.name,$.scope,F);_.ok?(V.requiresManualRestart||_.requiresManualRestart?D.warning(e("settings.agents.page.toast.savedManualRestart")):D.success(e("settings.agents.sidebar.toast.agentRenamed",{name:K})),C(K)):D.error(e("settings.agents.sidebar.toast.removeOldAfterRenameFailed"))}else D.error(e("settings.agents.sidebar.toast.renameFailed"));n(null)},P=K=>{switch(K){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}},G=I.filter(K=>!rc(K)),J=G.filter(ia),T=G.filter(K=>!ia(K)),{groupedCustomAgents:W,ungroupedCustomAgents:X}=Qe.useMemo(()=>{const K={},te=[];for(const V of T){const _=V;_.group?(K[_.group]||(K[_.group]=[]),K[_.group].push(V)):te.push(V)}return{groupedCustomAgents:Object.keys(K).sort((V,_)=>V.localeCompare(_)).map(V=>({name:V,agents:K[V]})),ungroupedCustomAgents:te}},[T]);return s.jsxs("div",{className:we("flex h-full flex-col",w),children:[s.jsxs("div",{className:"border-b px-3 pt-4 pb-3",children:[s.jsx("h2",{className:`${nn} mb-3`,children:e("settings.agents.sidebar.title")}),s.jsx(za,{className:"mb-3"}),s.jsxs("div",{className:"flex items-center justify-between gap-2",children:[s.jsx("span",{className:"typography-meta text-muted-foreground",children:e("settings.agents.sidebar.total",{count:G.length})}),s.jsx(B,{size:"sm","data-settings-item":"agents.create",variant:"ghost",className:"h-7 w-7 px-0 -my-1 text-muted-foreground",onClick: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:G.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:[J.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")}),J.map(K=>s.jsx(Mi,{agent:K,isSelected:b===K.name,onSelect:()=>{C(K.name),t?.()},onReset:()=>U(K),onDuplicate:()=>j(K),getAgentModeIcon:P,isMenuOpen:c===K.name,onMenuOpenChange:te=>N(te?K.name:null)},K.name))]}),T.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:K,agents:te})=>s.jsx(Xi,{label:K,count:te.length,storageKey:"agents",children:te.map($=>s.jsx(Mi,{agent:$,isSelected:b===$.name,onSelect:()=>{C($.name),t?.()},onRename:()=>R($),onDelete:()=>y($),onDuplicate:()=>j($),getAgentModeIcon:P,isMenuOpen:c===$.name,onMenuOpenChange:V=>N(V?$.name:null)},$.name))},K)),X.map(K=>s.jsx(Mi,{agent:K,isSelected:b===K.name,onSelect:()=>{C(K.name),t?.()},onRename:()=>R(K),onDelete:()=>y(K),onDuplicate:()=>j(K),getAgentModeIcon:P,isMenuOpen:c===K.name,onMenuOpenChange:te=>N(te?K.name:null)},K.name))]})]})}),s.jsx(Rt,{open:l!==null&&g!==null,onOpenChange:K=>{!K&&!d&&S()},children:s.jsxs(Ot,{className:"max-w-md",children:[s.jsxs(Kt,{children:[s.jsx(Ut,{children:e(g==="delete"?"settings.agents.sidebar.dialog.deleteTitle":"settings.agents.sidebar.dialog.resetTitle")}),s.jsx(zt,{children:g==="delete"?e("settings.agents.sidebar.dialog.deleteDescription",{name:l?.name??""}):e("settings.agents.sidebar.dialog.resetDescription",{name:l?.name??""})})]}),s.jsxs(es,{children:[s.jsx(B,{size:"sm",variant:"ghost",onClick:S,disabled:d,children:e("settings.common.actions.cancel")}),s.jsx(B,{size:"sm",onClick:M,disabled:d,children:e(g==="delete"?"settings.common.actions.delete":"settings.common.actions.reset")})]})]})}),s.jsx(Rt,{open:a!==null,onOpenChange:K=>!K&&n(null),children:s.jsxs(Ot,{children:[s.jsxs(Kt,{children:[s.jsx(Ut,{children:e("settings.agents.sidebar.renameDialog.title")}),s.jsx(zt,{children:e("settings.agents.sidebar.renameDialog.description",{name:a?.name??""})})]}),s.jsx(We,{value:i,onChange:K=>r(K.target.value),placeholder:e("settings.agents.sidebar.renameDialog.placeholder"),className:"text-foreground placeholder:text-muted-foreground",onKeyDown:K=>{K.key==="Enter"&&H()}}),s.jsxs(es,{children:[s.jsx(B,{size:"sm",variant:"ghost",onClick:()=>n(null),children:e("settings.common.actions.cancel")}),s.jsx(B,{size:"sm",onClick:H,children:e("settings.common.actions.rename")})]})]})})]})},Mi=t=>{const e=lt.c(52),{agent:a,isSelected:n,onSelect:i,onDelete:r,onReset:l,onRename:u,onDuplicate:g,getAgentModeIcon:x,isMenuOpen:d,onMenuOpenChange:v}=t,{t:c}=nt(),N=a;let b;e[0]===Symbol.for("react.memo_cache_sentinel")?(b=La(),e[0]=b):b=e[0];const C=b,[k,A]=o.useState(!1);let h;e[1]!==r||e[2]!==g||e[3]!==u||e[4]!==l||e[5]!==c?(h=te=>s.jsxs(s.Fragment,{children:[u&&s.jsxs(te,{onClick:$=>{$.stopPropagation(),u()},children:[s.jsx(L,{name:"edit",className:"h-4 w-4 mr-px"}),c("settings.common.actions.rename")]}),s.jsxs(te,{onClick:$=>{$.stopPropagation(),g()},children:[s.jsx(L,{name:"file-copy",className:"h-4 w-4 mr-px"}),c("settings.common.actions.duplicate")]}),l&&s.jsxs(te,{onClick:$=>{$.stopPropagation(),l()},children:[s.jsx(L,{name:"restart",className:"h-4 w-4 mr-px"}),c("settings.common.actions.reset")]}),r&&s.jsxs(te,{onClick:$=>{$.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[1]=r,e[2]=g,e[3]=u,e[4]=l,e[5]=c,e[6]=h):h=e[6];const E=h,F=n?"bg-interactive-selection":"hover:bg-interactive-hover";let I;e[7]!==F?(I=we("group relative flex items-center rounded-md px-1.5 py-1 transition-all duration-200 select-none",F),e[7]=F,e[8]=I):I=e[8];let w;e[9]===Symbol.for("react.memo_cache_sentinel")?(w=C?void 0:te=>{te.preventDefault(),A(!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 U;e[14]!==a.mode||e[15]!==x?(U=x(a.mode),e[14]=a.mode,e[15]=x,e[16]=U):U=e[16];let S;e[17]!==a||e[18]!==N.scope||e[19]!==c?(S=(N.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)?c("settings.agents.sidebar.badge.system"):N.scope}),e[17]=a,e[18]=N.scope,e[19]=c,e[20]=S):S=e[20];let M;e[21]!==y||e[22]!==U||e[23]!==S?(M=s.jsxs("div",{className:"flex items-center gap-1.5",children:[y,U,S]}),e[21]=y,e[22]=U,e[23]=S,e[24]=M):M=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]!==M||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:[M,j]}),e[27]=i,e[28]=M,e[29]=j,e[30]=R):R=e[30];let H;e[31]!==v?(H=te=>{te&&A(!1),v(te)},e[31]=v,e[32]=H):H=e[32];let P;e[33]===Symbol.for("react.memo_cache_sentinel")?(P=s.jsx(Zs,{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]=P):P=e[33];let G;e[34]!==E?(G=s.jsx(en,{align:"end",className:"w-fit min-w-20",children:E(sn)}),e[34]=E,e[35]=G):G=e[35];let J;e[36]!==d||e[37]!==H||e[38]!==G?(J=s.jsxs(tn,{open:d,onOpenChange:H,children:[P,G]}),e[36]=d,e[37]=H,e[38]=G,e[39]=J):J=e[39];let T;e[40]!==R||e[41]!==J?(T=s.jsxs("div",{className:"flex min-w-0 flex-1 items-center",children:[R,J]}),e[40]=R,e[41]=J,e[42]=T):T=e[42];let W;e[43]!==T||e[44]!==m?(W=s.jsx(Vn,{render:m,children:T}),e[43]=T,e[44]=m,e[45]=W):W=e[45];let X;e[46]!==E?(X=s.jsx(_n,{className:"w-fit min-w-20",children:E($n)}),e[46]=E,e[47]=X):X=e[47];let K;return e[48]!==k||e[49]!==W||e[50]!==X?(K=s.jsxs(Bn,{open:k,onOpenChange:A,children:[W,X]}),e[48]=k,e[49]=W,e[50]=X,e[51]=K):K=e[51],K},ns=t=>{const e=lt.c(21),{children:a,className:n,outerClassName:i,title:r,titleLeading:l,titleAccessory:u,description:g,headerEnd:x,showSaveStatus:d}=t,v=d===void 0?!1:d,c=r!=null||g!=null||x!=null||v,N=typeof r=="string"||typeof r=="number",b=l!=null||u!=null;let C;e[0]!==i?(C=we("h-full",i),e[0]=i,e[1]=C):C=e[1];let k;e[2]!==n?(k=we("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]=k):k=e[3];let A;e[4]!==g||e[5]!==c||e[6]!==b||e[7]!==x||e[8]!==N||e[9]!==v||e[10]!==r||e[11]!==u||e[12]!==l?(A=c&&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?N?b?s.jsxs("div",{className:"flex min-w-0 items-center gap-2",children:[l,s.jsx("h1",{"data-settings-page-heading":!0,tabIndex:-1,className:we(Qi,"min-w-0 truncate"),children:r}),s.jsx("span",{className:"shrink-0",children:u})]}):s.jsx("h1",{"data-settings-page-heading":!0,tabIndex:-1,className:Qi,children:r}):r:null,g!=null?typeof g=="string"||typeof g=="number"?s.jsx("p",{className:al,children:g}):g:null]}),s.jsxs("div",{className:"flex shrink-0 flex-wrap items-center justify-end gap-3",children:[x,v&&s.jsx(ap,{})]})]}),e[4]=g,e[5]=c,e[6]=b,e[7]=x,e[8]=N,e[9]=v,e[10]=r,e[11]=u,e[12]=l,e[13]=A):A=e[13];let h;e[14]!==a||e[15]!==k||e[16]!==A?(h=s.jsxs("div",{className:k,children:[A,a]}),e[14]=a,e[15]=k,e[16]=A,e[17]=h):h=e[17];let E;return e[18]!==C||e[19]!==h?(E=s.jsx(Vs,{outerClassName:C,className:"w-full @container",children:h}),e[18]=C,e[19]=h,e[20]=E):E=e[20],E},np=500,ap=()=>{const t=lt.c(13),{t:e}=nt(),a=o.useSyncExternalStore(nd,Or,Or),[n,i]=o.useState(!1);let r,l;if(t[0]!==a?(r=()=>{if(a!=="saving"){i(!1);return}const d=setTimeout(()=>i(!0),np);return()=>clearTimeout(d)},l=[a],t[0]=a,t[1]=r,t[2]=l):(r=t[1],l=t[2]),o.useEffect(r,l),a==="error"){let d;t[3]===Symbol.for("react.memo_cache_sentinel")?(d=s.jsx(L,{name:"error-warning",className:"size-3.5"}),t[3]=d):d=t[3];let v;t[4]!==e?(v=e("settings.common.status.saveFailed"),t[4]=e,t[5]=v):v=t[5];let c;return t[6]!==v?(c=s.jsxs("div",{"aria-live":"assertive",className:"flex shrink-0 items-center gap-1.5 typography-meta text-[var(--status-error)]",children:[d,s.jsx("span",{children:v})]}),t[6]=v,t[7]=c):c=t[7],c}if(a!=="saving"||!n)return null;let u;t[8]===Symbol.for("react.memo_cache_sentinel")?(u=s.jsx(L,{name:"loader-4",className:"size-3.5 animate-spin"}),t[8]=u):u=t[8];let g;t[9]!==e?(g=e("settings.common.actions.saving"),t[9]=e,t[10]=g):g=t[10];let x;return t[11]!==g?(x=s.jsxs("div",{"aria-live":"polite",className:"flex shrink-0 items-center gap-1.5 typography-meta text-muted-foreground",children:[u,s.jsx("span",{children:g})]}),t[11]=g,t[12]=x):x=t[12],x},ip=["allow","ask","deny"],Ta=t=>t==="allow"||t==="ask"||t==="deny",Zi=()=>({global:null,keys:{}}),rp=t=>{const e=Zi();if(t==null)return e;if(typeof t=="string")return Ta(t)&&(e.global=t),e;if(typeof t!="object"||Array.isArray(t))return e;for(const[a,n]of Object.entries(t)){if(a==="*"){Ta(n)&&(e.global=n);continue}const i={action:null,patterns:[]};if(Ta(n))i.action=n;else if(n&&typeof n=="object"&&!Array.isArray(n))for(const[r,l]of Object.entries(n))Ta(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},op=(t,e)=>JSON.stringify(er(t))===JSON.stringify(er(e)),yn=t=>JSON.parse(JSON.stringify(t)),lp=["edit","external_directory","doom_loop","plan_enter","plan_exit"],cp=new Set(["read","edit","glob","grep","list","bash","task","external_directory","lsp","skill"]),Zr=new Set(["write","patch","apply_patch","multiedit","invalid"]),dp=t=>t.split(/[_-]/).filter(Boolean).map(e=>e.charAt(0).toUpperCase()+e.slice(1)).join(" "),pp=({agent:t})=>{const{t:e}=nt(),a=Un(_=>_.updateAgent),[n,i]=o.useState(Zi),[r,l]=o.useState(Zi),[u,g]=o.useState(!0),[x,d]=o.useState(!1),[v,c]=o.useState(!1),[N,b]=o.useState({}),[C,k]=o.useState([]),[A,h]=o.useState(""),[E,F]=o.useState(0),I=t.name,w=zs();o.useEffect(()=>{let _=!1;return g(!0),d(!1),(async()=>{try{const z=w,Z=z?`?directory=${encodeURIComponent(z)}`:"",Y=await rt(`/api/config/agents/${encodeURIComponent(I)}/config${Z}`,{headers:{"Cache-Control":"no-cache",...z?{"x-opencode-directory":z}:{}}});if(!Y.ok)throw new Error(String(Y.status));const se=await Y.json().catch(()=>null);if(_)return;const ge=rp(se?.config?.permission);i(yn(ge)),l(ge)}catch{_||d(!0)}finally{_||g(!1)}})(),()=>{_=!0}},[I,E,w]),o.useEffect(()=>{let _=!1;return(async()=>{try{const z=await un.listToolIds({directory:w});!_&&Array.isArray(z)&&k(z.filter(Z=>typeof Z=="string"&&!Zr.has(Z)))}catch{}})(),()=>{_=!0}},[I,w]);const m=o.useMemo(()=>{const _=t.permission;if(!Array.isArray(_))return[];const z=[];for(const Z of _){if(!Z||typeof Z!="object")continue;const{permission:Y,pattern:se,action:ge}=Z;typeof Y=="string"&&typeof se=="string"&&Ta(ge)&&z.push({permission:Y,pattern:se,action:ge})}return z},[t]),y=o.useCallback(_=>{const z=m.find(Y=>Y.permission===_&&Y.pattern==="*");if(z)return z.action;const Z=m.find(Y=>Y.permission==="*"&&Y.pattern==="*");return Z?Z.action:null},[m]),U=o.useCallback(_=>{const z=r.keys[_]?.patterns??[],Z=new Set(z.map(Y=>Y.pattern));return m.filter(Y=>Y.permission===_&&Y.pattern!=="*"&&!Z.has(Y.pattern))},[m,r.keys]),S=o.useMemo(()=>{const _=new Set;for(const z of C)_.add(z);for(const z of lp)_.add(z);for(const z of Object.keys(r.keys))_.add(z);for(const z of Zr)_.delete(z);return Array.from(_).sort((z,Z)=>z.localeCompare(Z))},[C,r.keys]),M=o.useMemo(()=>!op(r,n),[r,n]),j=_=>{l(z=>({...z,global:_}))},R=(_,z)=>{l(Z=>{const Y=yn(Z),se=Y.keys[_]??{action:null,patterns:[]};return se.action=z,se.action===null&&se.patterns.length===0?delete Y.keys[_]:Y.keys[_]=se,Y})},H=(_,z,Z,Y)=>{l(se=>{const ge=yn(se),ce=ge.keys[_]??{action:null,patterns:[]};return ce.patterns[z]={pattern:Z,action:Y},ge.keys[_]=ce,ge})},P=_=>{l(z=>{const Z=yn(z),Y=Z.keys[_]??{action:null,patterns:[]};return Y.patterns.push({pattern:"",action:"allow"}),Z.keys[_]=Y,Z}),b(z=>({...z,[_]:!0}))},G=(_,z)=>{l(Z=>{const Y=yn(Z),se=Y.keys[_];return se?(se.patterns.splice(z,1),se.action===null&&se.patterns.length===0&&delete Y.keys[_],Y):Z})},J=()=>{const _=A.trim();!_||_==="*"||(l(z=>{if(z.keys[_])return z;const Z=yn(z);return Z.keys[_]={action:"ask",patterns:[]},Z}),b(z=>({...z,[_]:!0})),h(""))},T=async()=>{c(!0);try{const _=er(r),z=await a(I,{permission:_});z.ok?(i(yn(r)),D.success(z.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{c(!1)}},W=()=>{l(yn(n))},X=_=>e(_==="allow"?"settings.agents.page.permissionsEditor.action.allow":_==="ask"?"settings.agents.page.permissionsEditor.action.ask":"settings.agents.page.permissionsEditor.action.deny"),K=e("settings.agents.page.permissionsEditor.action.inherit"),te=e("settings.agents.page.permissionsEditor.action.default"),$=_=>[..._?[{value:"inherit",label:_}]:[],...ip.map(z=>({value:z,label:X(z)}))],V=(_,z,Z,Y=K)=>s.jsx(Gs,{value:_??"inherit",options:$(Y),onChange:se=>z(se==="inherit"?null:se),"aria-label":Z});return u?s.jsx($e,{title:e("settings.agents.page.section.toolPermissions"),children:s.jsx("p",{className:Rn,children:e("common.loading")})}):x?s.jsx($e,{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:()=>F(_=>_+1),children:e("settings.agents.page.permissionsEditor.actions.retry")})]})}):s.jsxs($e,{title:e("settings.agents.page.section.toolPermissions"),settingsItem:"agents.permissions",info:e("settings.agents.page.permissionsEditor.sectionInfo"),headerAction:M?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:()=>{T()},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:It,children:e("settings.agents.page.permissionsEditor.defaultLabel")}),s.jsx(Jt,{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:X(y("*")??"allow")})})]}),V(r.global,j,e("settings.agents.page.permissionsEditor.defaultAria"),te)]}),s.jsx("div",{children:S.map(_=>{const z=r.keys[_]??{action:null,patterns:[]},Z=U(_),Y=cp.has(_)||z.patterns.length>0,se=Y||Z.length>0,ge=N[_]===!0,ce=y(_);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:se?()=>b(be=>({...be,[_]:!ge})):void 0,className:we("flex min-w-0 items-center gap-1.5 text-left",!se&&"cursor-default"),"aria-expanded":se?ge:void 0,children:[s.jsx(L,{name:ge&&se?"arrow-down-s":"arrow-right-s",className:we("h-3.5 w-3.5 shrink-0 text-muted-foreground",!se&&"opacity-0")}),s.jsx("span",{className:It,children:dp(_)}),s.jsx("span",{className:"typography-micro font-mono text-muted-foreground/70",children:_}),z.action===null&&ce!==null&&s.jsx("span",{className:"typography-micro text-muted-foreground",children:e("settings.agents.page.permissionsEditor.effectiveHint",{action:X(ce)})}),z.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(z.patterns.length)})})]}),V(z.action,be=>R(_,be),e("settings.agents.page.permissionsEditor.keyAria",{key:_}))]}),ge&&se&&s.jsxs("div",{className:"mt-2 space-y-2 pl-5",children:[z.patterns.map((be,ne)=>s.jsxs("div",{className:"flex flex-wrap items-center gap-2",children:[s.jsx(We,{value:be.pattern,onChange:ae=>H(_,ne,ae.target.value,be.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(Gs,{value:be.action,options:$(),onChange:ae=>H(_,ne,be.pattern,ae),"aria-label":e("settings.agents.page.permissionsEditor.patternActionAria",{key:_})}),s.jsx(B,{variant:"ghost",size:"icon",className:"h-7 w-7 shrink-0 text-muted-foreground hover:bg-destructive/10 hover:text-destructive",onClick:()=>G(_,ne),"aria-label":e("settings.agents.page.permissionsEditor.actions.removeRuleAria"),children:s.jsx(L,{name:"close",className:"h-3.5 w-3.5"})})]},ne)),Y&&s.jsxs(B,{variant:"outline",size:"xs",className:"!font-normal",onClick:()=>P(_),children:[s.jsx(L,{name:"add",className:"mr-1 h-3.5 w-3.5"}),e("settings.agents.page.permissionsEditor.actions.addRule")]}),Z.length>0&&s.jsxs("div",{className:"space-y-1 pt-1",children:[s.jsxs("div",{className:"flex items-center gap-1.5",children:[s.jsx("span",{className:"typography-micro font-medium text-muted-foreground",children:e("settings.agents.page.permissionsEditor.sessionRulesTitle")}),s.jsx(Jt,{children:e("settings.agents.page.permissionsEditor.sessionRulesInfo")})]}),Z.map(be=>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:be.pattern}),s.jsx("span",{className:"typography-micro text-muted-foreground",children:X(be.action)})]},`${be.pattern}-${be.action}`))]})]})]},_)})}),s.jsxs("div",{className:"flex flex-wrap items-center gap-2 border-t border-border/40 pt-3",children:[s.jsx(We,{value:A,onChange:_=>h(_.target.value),onKeyDown:_=>{_.key==="Enter"&&(_.preventDefault(),J())},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:J,disabled:!A.trim(),children:[s.jsx(L,{name:"add",className:"mr-1 h-3.5 w-3.5"}),e("settings.agents.page.permissionsEditor.actions.addKey")]})]})]})},mp=(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):[]},up=()=>{const{t}=nt(),e=et(V=>V.providers),{selectedAgentName:a,getAgentByName:n,createAgent:i,updateAgent:r,agentDraft:l,setAgentDraft:u}=Un(Ds(V=>({selectedAgentName:V.selectedAgentName,getAgentByName:V.getAgentByName,createAgent:V.createAgent,updateAgent:V.updateAgent,agentDraft:V.agentDraft,setAgentDraft:V.setAgentDraft}))),g=zs(),x=Un(V=>nl(V,g)),d=a?n(a,g):null,v=!!(l&&l.name===a&&!d),[c,N]=o.useState(""),[b,C]=o.useState("user"),[k,A]=o.useState(""),[h,E]=o.useState("subagent"),[F,I]=o.useState(""),[w,m]=o.useState(""),[y,U]=o.useState(void 0),[S,M]=o.useState(void 0),[j,R]=o.useState(""),[H,P]=o.useState(!1),G=o.useRef(null),J=o.useMemo(()=>mp(e,F),[F,e]),T=J.length>0,W=w||"__default",X=T,K=o.useMemo(()=>w&&!J.includes(w)?[w,...J]:J,[w,J]);o.useEffect(()=>{if(v&&l){const V=l.name||"",_=l.scope||"user",z=l.description||"",Z=l.mode||"subagent",Y=l.model||"",se=l.variant||"",ge=l.temperature??void 0,ce=l.top_p??void 0,be=l.prompt||"";N(V),C(_),A(z),E(Z),I(Y),m(se),U(ge),M(ce),R(be),G.current={draftName:V,draftScope:_,description:z,mode:Z,model:Y,variant:se,temperature:ge,topP:ce,prompt:be};return}if(d&&a===d.name){const V=d.description||"",_=d.mode||"subagent",z=d.model?.providerID&&d.model?.modelID?`${d.model.providerID}/${d.model.modelID}`:"",Z=d.variant||"",Y=d.temperature??void 0,se=d.topP??void 0,ge=d.prompt||"";A(V),E(_),I(z),m(Z),U(Y),M(se),R(ge),G.current={draftName:"",draftScope:"user",description:V,mode:_,model:z,variant:Z,temperature:Y,topP:se,prompt:ge}}},[l,v,d,a]);const te=o.useMemo(()=>{const V=G.current;return V?!!(v&&(c!==V.draftName||b!==V.draftScope)||k!==V.description||h!==V.mode||F!==V.model||w!==V.variant||y!==V.temperature||S!==V.topP||j!==V.prompt):!1},[k,c,b,v,h,F,j,y,S,w]),$=async()=>{const V=v?c.trim().replace(/\s+/g,"-"):a?.trim();if(!V){D.error(t("settings.agents.sidebar.toast.agentNameRequired"));return}if(v&&x.some(_=>_.name===V)){D.error(t("settings.agents.sidebar.toast.agentExists"));return}P(!0);try{const _=F.trim(),z=w.trim(),Z=j.trim(),Y={name:V,...k.trim()?{description:k.trim()}:{},mode:h,model:_===""?null:_,variant:z===""?null:z||void 0,temperature:y??null,top_p:S??null,prompt:Z||(v?void 0:null),...v&&b?{scope:b}:{}};let se;v?(se=await i(Y,g),se.ok&&u(null)):se=await r(V,Y,g),se.ok?se.requiresManualRestart?D.warning(t("settings.agents.page.toast.savedManualRestart")):se.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(_){console.error("Error saving agent:",_);const z=_ instanceof Error&&_.message?_.message:t("settings.agents.page.toast.saveUnexpectedError");D.error(z)}finally{P(!1)}};return a?s.jsxs(ns,{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($e,{title:t("settings.agents.page.section.identityRole"),divider:!1,contentClassName:"space-y-0",children:[v&&s.jsxs(Vt,{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(We,{value:c,onChange:V=>N(V.target.value),placeholder:t("settings.agents.page.field.agentNamePlaceholder"),className:"h-7 w-40 px-2"})]}),s.jsxs(At,{value:b,onValueChange:V=>C(V),children:[s.jsx(Et,{size:$t,className:"w-fit min-w-[100px]",children:s.jsx(Ft,{placeholder:t("settings.agents.page.field.scopePlaceholder")})}),s.jsxs(Tt,{align:"end",children:[s.jsx(ot,{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(ot,{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(Wt,{label:t("settings.common.field.description"),controlClassName:"w-full max-w-none",children:s.jsx(Is,{value:k,onChange:V=>A(V.target.value),placeholder:t("settings.agents.page.field.descriptionPlaceholder"),rows:2,className:"w-full resize-none min-h-[60px] bg-transparent"})}),s.jsx(Wt,{settingsItem:"agents.mode",label:t("settings.agents.page.field.mode"),info:t("settings.agents.page.field.modeTooltip"),children:s.jsx(Gs,{"aria-label":t("settings.agents.page.field.mode"),value:h,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($e,{title:t("settings.agents.page.section.modelParameters"),contentClassName:"space-y-3",children:[s.jsx(Vt,{settingsItem:"agents.model",label:t("settings.agents.page.field.overrideModel"),children:s.jsx(Da,{providerId:oa(F)?.providerId??"",modelId:oa(F)?.modelId??"",onChange:(V,_)=>{I(V&&_?`${V}/${_}`:""),m("")},className:Sn})}),s.jsx(Vt,{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:X?s.jsxs(At,{value:W,onValueChange:V=>m(V==="__default"?"":V),children:[s.jsx(Et,{size:$t,className:Cn,children:s.jsx(Ft,{placeholder:t("settings.agents.page.field.variantPlaceholder"),children:V=>V==="__default"?t("chat.modelControls.default"):V})}),s.jsxs(Tt,{children:[s.jsx(ot,{value:"__default",children:t("chat.modelControls.default")}),K.map(V=>s.jsx(ot,{value:V,children:V},V))]})]}):s.jsxs(s.Fragment,{children:[s.jsx(We,{value:w,onChange:V=>m(V.target.value),placeholder:t("settings.agents.page.field.variantPlaceholder"),disabled:!F&&!w,className:"h-8 w-40 rounded-md px-3"}),w&&s.jsx(B,{size:"sm",type:"button",variant:"ghost",onClick:()=>m(""),className:hs,"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(Vt,{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(Ss,{value:y,fallbackValue:.7,onValueChange:U,onClear:()=>U(void 0),min:0,max:2,step:.1,inputMode:"decimal",placeholder:"—",emptyLabel:"—",className:Ps}),y!==void 0&&s.jsx(B,{size:"sm",type:"button",variant:"ghost",onClick:()=>U(void 0),className:hs,"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(Vt,{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(Ss,{value:S,fallbackValue:.9,onValueChange:M,onClear:()=>M(void 0),min:0,max:1,step:.1,inputMode:"decimal",placeholder:"—",emptyLabel:"—",className:Ps}),S!==void 0&&s.jsx(B,{size:"sm",type:"button",variant:"ghost",onClick:()=>M(void 0),className:hs,"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($e,{title:t("settings.agents.page.section.systemPrompt"),settingsItem:"agents.system-prompt",children:s.jsx(Is,{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&&d&&s.jsx(pp,{agent:d}),s.jsx("div",{className:"pb-8",children:s.jsx(B,{onClick:$,disabled:H||!te,size:"xs",className:"!font-normal",children:t(H?"settings.common.actions.saving":"settings.common.actions.saveChanges")})})]}):s.jsx("div",{className:"flex h-full items-center justify-center",children:s.jsxs("div",{className:"text-center text-muted-foreground",children:[s.jsx(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")})]})})},gp="~/.config/opencode/AGENTS.md",El=async(t,e)=>{const a=await t.json().catch(()=>null);return typeof a?.error=="string"&&a.error.trim()?a.error:e},hp=t=>t.length>0&&!t.endsWith(`
|
|
2
|
+
`)?`${t}
|
|
3
|
+
`:t,qa={prompt:"",optimizeSystemPrompt:!1,responseStyleEnabled:!1,responseStylePreset:"concise",responseStyleCustomInstructions:""},fp=(t,e)=>t==="custom"?e:cc(t),xp=t=>t==="custom"?"custom":il(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 rt("/api/config/settings",{method:"PUT",headers:{"Content-Type":"application/json",Accept:"application/json"},body:JSON.stringify(t)});if(!a.ok)throw new Error(await El(a,e));Di("saved")}catch(a){throw Di("error"),a}},bp=()=>{const{t}=nt(),e=oc(),[a,n]=o.useState(""),[i,r]=o.useState(!1),[l,u]=o.useState(qa.responseStyleEnabled),[g,x]=o.useState(qa.responseStylePreset),[d,v]=o.useState(qa.responseStyleCustomInstructions),[c,N]=o.useState(!0),[b,C]=o.useState(!1),[k,A]=o.useState(!1),[h,E]=o.useState(""),[F,I]=o.useState(!1),w=o.useRef(null);o.useEffect(()=>{const j=new AbortController;return(async()=>{try{const[H,P]=await Promise.all([rt("/api/config/settings",{method:"GET",headers:{Accept:"application/json"},signal:j.signal}),rt("/api/behavior/agents-md",{method:"GET",headers:{Accept:"application/json"},signal:j.signal})]);let G=qa;if(H.ok){const J=await H.json();G={...G,optimizeSystemPrompt:J.optimizeSystemPrompt===!0,responseStyleEnabled:J.responseStyleEnabled===!0,responseStylePreset:xp(J.responseStylePreset),responseStyleCustomInstructions:typeof J.responseStyleCustomInstructions=="string"?J.responseStyleCustomInstructions:""},typeof J.globalBehaviorPrompt=="string"&&(G={...G,prompt:J.globalBehaviorPrompt})}if(!G.prompt.trim()&&P.ok){const J=await P.json();typeof J.content=="string"&&(G={...G,prompt:J.content})}n(G.prompt),r(G.optimizeSystemPrompt),I(G.optimizeSystemPrompt),u(G.responseStyleEnabled),x(G.responseStylePreset),v(G.responseStyleCustomInstructions),E(G.prompt),w.current={enabled:G.responseStyleEnabled,preset:G.responseStylePreset,custom:G.responseStyleCustomInstructions}}catch(H){H.name!=="AbortError"&&console.warn("Failed to load behavior settings:",H)}finally{N(!1)}})(),()=>j.abort()},[]),o.useEffect(()=>{if(c)return;const j=w.current;if(j&&j.enabled===l&&j.preset===g&&j.custom===d)return;const R={enabled:l,preset:g,custom:d},H=setTimeout(async()=>{try{await Ri({responseStyleEnabled:R.enabled,responseStylePreset:R.preset,responseStyleCustomInstructions:R.custom},t("settings.behavior.page.toast.saveFailed")),w.current=R}catch(P){const G=P instanceof Error?P.message:t("settings.behavior.page.toast.saveFailed");D.error(G)}},400);return()=>clearTimeout(H)},[l,g,d,c,t]);const m=fp(g,d),y=a!==h,U=i!==F,S=async()=>{C(!0);try{const j=hp(a),R=await rt("/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 El(R,t("settings.behavior.page.toast.saveFailed")));const H=await R.json().catch(()=>null),P=rl(H,"behavior",{id:"agents-md"});await Ri({globalBehaviorPrompt:j},t("settings.behavior.page.toast.saveFailed")),n(j),E(j),D.success(t(P?"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{C(!1)}},M=async()=>{A(!0);try{await Ri({optimizeSystemPrompt:i},t("settings.behavior.page.toast.saveFailed")),I(i),Fn("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{A(!1)}};return s.jsxs(ns,{title:t("settings.behavior.page.title"),description:t("settings.page.behavior.description"),showSaveStatus:!0,children:[!e&&s.jsxs($e,{title:t("settings.behavior.page.section.systemPromptOptimization"),divider:!1,settingsItem:"behavior.system-prompt-optimization",contentClassName:"space-y-3",children:[s.jsx(pt,{checked:i,onChange:r,disabled:c||k,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:()=>{M()},disabled:c||k||!U,className:"!font-normal",children:t(k?"settings.common.actions.saving":"settings.common.actions.saveChanges")})]}),s.jsxs($e,{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:gp})})]}),settingsItem:"behavior.system-prompt",contentClassName:"space-y-3",children:[s.jsx(Is,{value:a,onChange:j=>n(j.target.value),placeholder:t("settings.behavior.page.field.systemPromptPlaceholder"),rows:12,disabled:c,outerClassName:"min-h-[160px] max-h-[70vh]",className:"w-full font-mono typography-meta bg-transparent"}),s.jsx(B,{onClick:S,disabled:b||!y||c,size:"xs",className:"!font-normal",children:t(b?"settings.common.actions.saving":"settings.common.actions.saveChanges")})]}),s.jsxs($e,{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(pt,{checked:l,onChange:u,disabled:c,label:t("settings.behavior.page.responseStyle.enable"),ariaLabel:t("settings.behavior.page.responseStyle.enableAria")}),s.jsx(Vt,{label:t("settings.behavior.page.responseStyle.preset"),alignEnd:!1,children:s.jsxs(At,{value:g,onValueChange:j=>x(j),disabled:c||!l,children:[s.jsx(Et,{size:$t,className:Cn,children:s.jsx(Ft,{children:j=>j==="custom"?t("settings.behavior.page.responseStyle.option.custom"):il(j)?t(eo[j]):null})}),s.jsxs(Tt,{children:[lc.map(j=>s.jsx(ot,{value:j,children:t(eo[j])},j)),s.jsx(ot,{value:"custom",children:t("settings.behavior.page.responseStyle.option.custom")})]})]})}),s.jsx(Is,{value:m,onChange:j=>v(j.target.value),placeholder:t("settings.behavior.page.responseStyle.customPlaceholder"),rows:5,disabled:c||!l||g!=="custom",outerClassName:"min-h-[120px]",className:"w-full font-mono typography-meta bg-transparent"})]})]})},vp=t=>{const e=lt.c(176),{onItemSelect:a}=t,{t:n}=nt(),[i,r]=o.useState(null),[l,u]=o.useState(""),[g,x]=o.useState(null),[d,v]=o.useState(null),[c,N]=o.useState(!1),[b,C]=o.useState(null),{selectedCommandName:k,setSelectedCommand:A,setCommandDraft:h,createCommand:E,deleteCommand:F,loadCommands:I}=la(Ds(yp)),w=zs();let m;e[0]!==w?(m=Ue=>ol(Ue,w),e[0]=w,e[1]=m):m=e[1];const y=la(m);let U;e[2]!==w?(U=Ue=>cr(Ue,w),e[2]=w,e[3]=U):U=e[3];const S=$s(U),M=$s(jp);let j,R;e[4]!==I||e[5]!==M||e[6]!==w?(j=()=>{I(w),M(w)},R=[I,M,w],e[4]=I,e[5]=M,e[6]=w,e[7]=j,e[8]=R):(j=e[7],R=e[8]),o.useEffect(j,R);let H;e[9]!==S?(H=new Set(S.map(wp)),e[9]=S,e[10]=H):H=e[10];const P=H;let G;if(e[11]!==y||e[12]!==P){let Ue;e[14]!==P?(Ue=jt=>!P.has(jt.name),e[14]=P,e[15]=Ue):Ue=e[15],G=y.filter(Ue),e[11]=y,e[12]=P,e[13]=G}else G=e[13];const J=G;let T,W;e[16]!==k||e[17]!==A||e[18]!==P?(T=()=>{k&&P.has(k)&&A(null)},W=[k,A,P],e[16]=k,e[17]=A,e[18]=P,e[19]=T,e[20]=W):(T=e[19],W=e[20]),o.useEffect(T,W);let X;e[21]!==y||e[22]!==a||e[23]!==h||e[24]!==A?(X=()=>{let Ue="new-command",jt=1;for(;y.some(Ae=>Ae.name===Ue);)Ue=`new-command-${jt}`,jt++;h({name:Ue,scope:"user"}),A(Ue),a?.()},e[21]=y,e[22]=a,e[23]=h,e[24]=A,e[25]=X):X=e[25];const K=X;let te;e[26]!==n?(te=async Ue=>{if(ra(Ue)){D.error(n("settings.commands.sidebar.toast.builtInCannotDelete"));return}x(Ue),v("delete")},e[26]=n,e[27]=te):te=e[27];const $=te;let V;e[28]===Symbol.for("react.memo_cache_sentinel")?(V=async Ue=>{ra(Ue)&&(x(Ue),v("reset"))},e[28]=V):V=e[28];const _=V;let z;e[29]===Symbol.for("react.memo_cache_sentinel")?(z=()=>{x(null),v(null)},e[29]=z):z=e[29];const Z=z;let Y;e[30]!==g||e[31]!==d||e[32]!==F||e[33]!==w||e[34]!==n?(Y=async()=>{if(!g||!d)return;N(!0),await F(g.name,w)?(d==="delete"?D.success(n("settings.commands.sidebar.toast.commandDeleted",{name:g.name})):D.success(n("settings.commands.sidebar.toast.commandReset",{name:g.name})),Z()):d==="delete"?D.error(n("settings.commands.sidebar.toast.deleteFailed")):D.error(n("settings.commands.sidebar.toast.resetFailed")),N(!1)},e[30]=g,e[31]=d,e[32]=F,e[33]=w,e[34]=n,e[35]=Y):Y=e[35];const se=Y;let ge;e[36]!==y||e[37]!==h||e[38]!==A?(ge=Ue=>{const jt=Ue.name;let Ae=1,yt=`${jt}-copy`;for(;y.some(Q=>Q.name===yt);)Ae++,yt=`${jt}-copy-${Ae}`;h({name:yt,scope:Ue.scope||"user",description:Ue.description,template:Ue.template,agent:Ue.agent,model:Ue.model}),A(yt)},e[36]=y,e[37]=h,e[38]=A,e[39]=ge):ge=e[39];const ce=ge;let be;e[40]===Symbol.for("react.memo_cache_sentinel")?(be=Ue=>{u(Ue.name),r(Ue)},e[40]=be):be=e[40];const ne=be;let ae;e[41]!==y||e[42]!==E||e[43]!==F||e[44]!==i||e[45]!==l||e[46]!==A||e[47]!==w||e[48]!==n?(ae=async()=>{if(!i)return;const Ue=l.trim().replace(/\s+/g,"-");if(!Ue){D.error(n("settings.commands.sidebar.toast.commandNameRequired"));return}if(Ue===i.name){r(null);return}if(y.some(Ae=>Ae.name===Ue)){D.error(n("settings.commands.sidebar.toast.commandExists"));return}await E({name:Ue,description:i.description,template:i.template,agent:i.agent,model:i.model},w)?await F(i.name,w)?(D.success(`Command renamed to "${Ue}"`),A(Ue)):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]=F,e[44]=i,e[45]=l,e[46]=A,e[47]=w,e[48]=n,e[49]=ae):ae=e[49];const me=ae;let Pe,Ne,Se,je,Me,Re;if(e[50]!==J||e[51]!==K||e[52]!==$||e[53]!==ce||e[54]!==a||e[55]!==b||e[56]!==k||e[57]!==A||e[58]!==n){const Ue=J.filter(ra),jt=J.filter(kp);e[65]===Symbol.for("react.memo_cache_sentinel")?(Me=we("flex h-full flex-col","bg-background"),e[65]=Me):Me=e[65];let Ae;e[66]!==n?(Ae=n("settings.commands.sidebar.title"),e[66]=n,e[67]=Ae):Ae=e[67];let yt;e[68]!==Ae?(yt=s.jsx("h2",{className:`${nn} mb-3`,children:Ae}),e[68]=Ae,e[69]=yt):yt=e[69];let Q;e[70]===Symbol.for("react.memo_cache_sentinel")?(Q=s.jsx(za,{className:"mb-3"}),e[70]=Q):Q=e[70];let he;e[71]!==J.length||e[72]!==n?(he=n("settings.commands.sidebar.total",{count:J.length}),e[71]=J.length,e[72]=n,e[73]=he):he=e[73];let ze;e[74]!==he?(ze=s.jsx("span",{className:"typography-meta text-muted-foreground",children:he}),e[74]=he,e[75]=ze):ze=e[75];let De;e[76]===Symbol.for("react.memo_cache_sentinel")?(De=s.jsx(L,{name:"add",className:"h-3.5 w-3.5"}),e[76]=De):De=e[76];let it;e[77]!==K?(it=s.jsx(B,{size:"sm","data-settings-item":"commands.create",variant:"ghost",className:"h-7 w-7 px-0 -my-1 text-muted-foreground",onClick:K,children:De}),e[77]=K,e[78]=it):it=e[78];let at;e[79]!==ze||e[80]!==it?(at=s.jsxs("div",{className:"flex items-center justify-between gap-2",children:[ze,it]}),e[79]=ze,e[80]=it,e[81]=at):at=e[81],e[82]!==yt||e[83]!==at?(Re=s.jsxs("div",{className:"border-b px-3 pt-4 pb-3",children:[yt,Q,at]}),e[82]=yt,e[83]=at,e[84]=Re):Re=e[84],Pe=Vs,Ne="flex-1 min-h-0",Se="space-y-1 px-3 py-2",je=J.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:[Ue.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")}),[...Ue].sort(Np).map(Je=>s.jsx(to,{command:Je,isSelected:k===Je.name,onSelect:()=>{A(Je.name),a?.()},onReset:()=>_(Je),onDuplicate:()=>ce(Je),isMenuOpen:b===Je.name,onMenuOpenChange:Nt=>C(Nt?Je.name:null)},Je.name))]}),jt.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")}),[...jt].sort(Sp).map(Je=>s.jsx(to,{command:Je,isSelected:k===Je.name,onSelect:()=>{A(Je.name),a?.()},onRename:()=>ne(Je),onDelete:()=>$(Je),onDuplicate:()=>ce(Je),isMenuOpen:b===Je.name,onMenuOpenChange:Nt=>C(Nt?Je.name:null)},Je.name))]})]}),e[50]=J,e[51]=K,e[52]=$,e[53]=ce,e[54]=a,e[55]=b,e[56]=k,e[57]=A,e[58]=n,e[59]=Pe,e[60]=Ne,e[61]=Se,e[62]=je,e[63]=Me,e[64]=Re}else Pe=e[59],Ne=e[60],Se=e[61],je=e[62],Me=e[63],Re=e[64];let re;e[85]!==Pe||e[86]!==Ne||e[87]!==Se||e[88]!==je?(re=s.jsx(Pe,{outerClassName:Ne,className:Se,children:je}),e[85]=Pe,e[86]=Ne,e[87]=Se,e[88]=je,e[89]=re):re=e[89];const fe=g!==null&&d!==null;let Ee;e[90]!==c?(Ee=Ue=>{!Ue&&!c&&Z()},e[90]=c,e[91]=Ee):Ee=e[91];let Be;e[92]!==d||e[93]!==n?(Be=n(d==="delete"?"settings.commands.sidebar.dialog.deleteTitle":"settings.commands.sidebar.dialog.resetTitle"),e[92]=d,e[93]=n,e[94]=Be):Be=e[94];let Ve;e[95]!==Be?(Ve=s.jsx(Ut,{children:Be}),e[95]=Be,e[96]=Ve):Ve=e[96];let Ge;e[97]!==g?.name||e[98]!==d||e[99]!==n?(Ge=d==="delete"?n("settings.commands.sidebar.dialog.deleteDescription",{name:g?.name??""}):n("settings.commands.sidebar.dialog.resetDescription",{name:g?.name??""}),e[97]=g?.name,e[98]=d,e[99]=n,e[100]=Ge):Ge=e[100];let Ke;e[101]!==Ge?(Ke=s.jsx(zt,{children:Ge}),e[101]=Ge,e[102]=Ke):Ke=e[102];let oe;e[103]!==Ve||e[104]!==Ke?(oe=s.jsxs(Kt,{children:[Ve,Ke]}),e[103]=Ve,e[104]=Ke,e[105]=oe):oe=e[105];let ie;e[106]!==n?(ie=n("settings.common.actions.cancel"),e[106]=n,e[107]=ie):ie=e[107];let ye;e[108]!==c||e[109]!==ie?(ye=s.jsx(B,{size:"sm",variant:"ghost",onClick:Z,disabled:c,children:ie}),e[108]=c,e[109]=ie,e[110]=ye):ye=e[110];let ve;e[111]!==d||e[112]!==n?(ve=n(d==="delete"?"settings.common.actions.delete":"settings.common.actions.reset"),e[111]=d,e[112]=n,e[113]=ve):ve=e[113];let Oe;e[114]!==se||e[115]!==c||e[116]!==ve?(Oe=s.jsx(B,{size:"sm",onClick:se,disabled:c,children:ve}),e[114]=se,e[115]=c,e[116]=ve,e[117]=Oe):Oe=e[117];let Te;e[118]!==ye||e[119]!==Oe?(Te=s.jsxs(es,{children:[ye,Oe]}),e[118]=ye,e[119]=Oe,e[120]=Te):Te=e[120];let xe;e[121]!==oe||e[122]!==Te?(xe=s.jsxs(Ot,{className:"max-w-md",children:[oe,Te]}),e[121]=oe,e[122]=Te,e[123]=xe):xe=e[123];let He;e[124]!==fe||e[125]!==Ee||e[126]!==xe?(He=s.jsx(Rt,{open:fe,onOpenChange:Ee,children:xe}),e[124]=fe,e[125]=Ee,e[126]=xe,e[127]=He):He=e[127];const ue=i!==null;let Ie;e[128]===Symbol.for("react.memo_cache_sentinel")?(Ie=Ue=>!Ue&&r(null),e[128]=Ie):Ie=e[128];let Le;e[129]!==n?(Le=n("settings.commands.sidebar.renameDialog.title"),e[129]=n,e[130]=Le):Le=e[130];let Ye;e[131]!==Le?(Ye=s.jsx(Ut,{children:Le}),e[131]=Le,e[132]=Ye):Ye=e[132];const q=i?.name??"";let ke;e[133]!==n||e[134]!==q?(ke=n("settings.commands.sidebar.renameDialog.description",{name:q}),e[133]=n,e[134]=q,e[135]=ke):ke=e[135];let O;e[136]!==ke?(O=s.jsx(zt,{children:ke}),e[136]=ke,e[137]=O):O=e[137];let Ce;e[138]!==Ye||e[139]!==O?(Ce=s.jsxs(Kt,{children:[Ye,O]}),e[138]=Ye,e[139]=O,e[140]=Ce):Ce=e[140];let qe;e[141]===Symbol.for("react.memo_cache_sentinel")?(qe=Ue=>u(Ue.target.value),e[141]=qe):qe=e[141];let _e;e[142]!==n?(_e=n("settings.commands.sidebar.renameDialog.placeholder"),e[142]=n,e[143]=_e):_e=e[143];let tt;e[144]!==me?(tt=Ue=>{Ue.key==="Enter"&&me()},e[144]=me,e[145]=tt):tt=e[145];let ht;e[146]!==l||e[147]!==_e||e[148]!==tt?(ht=s.jsx(We,{value:l,onChange:qe,placeholder:_e,className:"text-foreground placeholder:text-muted-foreground",onKeyDown:tt}),e[146]=l,e[147]=_e,e[148]=tt,e[149]=ht):ht=e[149];let mt;e[150]===Symbol.for("react.memo_cache_sentinel")?(mt=()=>r(null),e[150]=mt):mt=e[150];let ut;e[151]!==n?(ut=n("settings.common.actions.cancel"),e[151]=n,e[152]=ut):ut=e[152];let ft;e[153]!==ut?(ft=s.jsx(B,{size:"sm",variant:"ghost",onClick:mt,children:ut}),e[153]=ut,e[154]=ft):ft=e[154];let kt;e[155]!==n?(kt=n("settings.common.actions.rename"),e[155]=n,e[156]=kt):kt=e[156];let vt;e[157]!==me||e[158]!==kt?(vt=s.jsx(B,{size:"sm",onClick:me,children:kt}),e[157]=me,e[158]=kt,e[159]=vt):vt=e[159];let Ct;e[160]!==ft||e[161]!==vt?(Ct=s.jsxs(es,{children:[ft,vt]}),e[160]=ft,e[161]=vt,e[162]=Ct):Ct=e[162];let Ze;e[163]!==Ce||e[164]!==ht||e[165]!==Ct?(Ze=s.jsxs(Ot,{children:[Ce,ht,Ct]}),e[163]=Ce,e[164]=ht,e[165]=Ct,e[166]=Ze):Ze=e[166];let Xe;e[167]!==ue||e[168]!==Ze?(Xe=s.jsx(Rt,{open:ue,onOpenChange:Ie,children:Ze}),e[167]=ue,e[168]=Ze,e[169]=Xe):Xe=e[169];let ct;return e[170]!==Me||e[171]!==Re||e[172]!==re||e[173]!==He||e[174]!==Xe?(ct=s.jsxs("div",{className:Me,children:[Re,re,He,Xe]}),e[170]=Me,e[171]=Re,e[172]=re,e[173]=He,e[174]=Xe,e[175]=ct):ct=e[175],ct},to=t=>{const e=lt.c(47),{command:a,isSelected:n,onSelect:i,onDelete:r,onReset:l,onRename:u,onDuplicate:g,isMenuOpen:x,onMenuOpenChange:d}=t,{t:v}=nt();let c;e[0]===Symbol.for("react.memo_cache_sentinel")?(c=La(),e[0]=c):c=e[0];const N=c,[b,C]=o.useState(!1);let k;e[1]!==r||e[2]!==g||e[3]!==u||e[4]!==l||e[5]!==v?(k=W=>s.jsxs(s.Fragment,{children:[u&&s.jsxs(W,{onClick:X=>{X.stopPropagation(),u()},children:[s.jsx(L,{name:"edit",className:"h-4 w-4 mr-px"}),v("settings.common.actions.rename")]}),s.jsxs(W,{onClick:X=>{X.stopPropagation(),g()},children:[s.jsx(L,{name:"file-copy",className:"h-4 w-4 mr-px"}),v("settings.common.actions.duplicate")]}),l&&s.jsxs(W,{onClick:X=>{X.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:X=>{X.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]=g,e[3]=u,e[4]=l,e[5]=v,e[6]=k):k=e[6];const A=k,h=n?"bg-interactive-selection":"hover:bg-interactive-hover";let E;e[7]!==h?(E=we("group relative flex items-center rounded-md px-1.5 py-1 transition-all duration-200 select-none",h),e[7]=h,e[8]=E):E=e[8];let F;e[9]===Symbol.for("react.memo_cache_sentinel")?(F=N?void 0:W=>{W.preventDefault(),C(!0)},e[9]=F):F=e[9];let I;e[10]!==E?(I=s.jsx("div",{className:E,onContextMenu:F}),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 U;e[20]!==a.description?(U=a.description&&s.jsx("div",{className:"typography-micro text-muted-foreground/60 truncate leading-tight",children:a.description}),e[20]=a.description,e[21]=U):U=e[21];let S;e[22]!==i||e[23]!==U||e[24]!==y?(S=s.jsxs("button",{onClick:i,className:"flex min-w-0 flex-1 flex-col gap-0 rounded-sm text-left focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-primary/50",tabIndex:0,children:[y,U]}),e[22]=i,e[23]=U,e[24]=y,e[25]=S):S=e[25];let M;e[26]!==d?(M=W=>{W&&C(!1),d(W)},e[26]=d,e[27]=M):M=e[27];let j;e[28]===Symbol.for("react.memo_cache_sentinel")?(j=s.jsx(Zs,{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]!==A?(R=s.jsx(en,{align:"end",className:"w-fit min-w-20",children:A(sn)}),e[29]=A,e[30]=R):R=e[30];let H;e[31]!==x||e[32]!==M||e[33]!==R?(H=s.jsxs(tn,{open:x,onOpenChange:M,children:[j,R]}),e[31]=x,e[32]=M,e[33]=R,e[34]=H):H=e[34];let P;e[35]!==S||e[36]!==H?(P=s.jsxs("div",{className:"flex min-w-0 flex-1 items-center",children:[S,H]}),e[35]=S,e[36]=H,e[37]=P):P=e[37];let G;e[38]!==P||e[39]!==I?(G=s.jsx(Vn,{render:I,children:P}),e[38]=P,e[39]=I,e[40]=G):G=e[40];let J;e[41]!==A?(J=s.jsx(_n,{className:"w-fit min-w-20",children:A($n)}),e[41]=A,e[42]=J):J=e[42];let T;return e[43]!==b||e[44]!==G||e[45]!==J?(T=s.jsxs(Bn,{open:b,onOpenChange:C,children:[G,J]}),e[43]=b,e[44]=G,e[45]=J,e[46]=T):T=e[46],T};function yp(t){return{selectedCommandName:t.selectedCommandName,setSelectedCommand:t.setSelectedCommand,setCommandDraft:t.setCommandDraft,createCommand:t.createCommand,deleteCommand:t.deleteCommand,loadCommands:t.loadCommands}}function jp(t){return t.loadSkills}function wp(t){return t.name}function kp(t){return!ra(t)}function Np(t,e){return t.name.localeCompare(e.name)}function Sp(t,e){return t.name.localeCompare(e.name)}const Cp=()=>{const{t}=nt(),{selectedCommandName:e,getCommandByName:a,createCommand:n,updateCommand:i,commandDraft:r,setCommandDraft:l}=la(Ds(j=>({selectedCommandName:j.selectedCommandName,getCommandByName:j.getCommandByName,createCommand:j.createCommand,updateCommand:j.updateCommand,commandDraft:j.commandDraft,setCommandDraft:j.setCommandDraft}))),u=zs(),g=la(j=>ol(j,u)),x=e?a(e,u):null,d=!!(r&&r.name===e&&!x),[v,c]=o.useState(""),[N,b]=o.useState("user"),[C,k]=o.useState(""),[A,h]=o.useState(""),[E,F]=o.useState(""),[I,w]=o.useState(""),[m,y]=o.useState(!1),U=o.useRef(null);o.useEffect(()=>{if(d&&r){const j=r.name||"",R=r.scope||"user",H=r.description||"",P=r.agent||"",G=r.model||"",J=r.template||"";c(j),b(R),k(H),h(P),F(G),w(J),U.current={draftName:j,draftScope:R,description:H,agent:P,model:G,template:J}}else if(x){const j=x.description||"",R=x.agent||"",H=x.model||"",P=x.template||"";k(j),h(R),F(H),w(P),U.current={draftName:"",draftScope:"user",description:j,agent:R,model:H,template:P}}},[x,d,e,g,r]);const S=o.useMemo(()=>{const j=U.current;return j?!!(d&&(v!==j.draftName||N!==j.draftScope)||C!==j.description||A!==j.agent||E!==j.model||I!==j.template):!1},[A,C,v,N,d,E,I]),M=async()=>{const j=d?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(d&&g.some(R=>R.name===j)){D.error(t("settings.commands.sidebar.toast.commandExists"));return}y(!0);try{const R=A.trim(),H=E.trim(),P=I.trim(),G={name:j,description:C.trim()||void 0,agent:R===""?null:R,model:H===""?null:H,template:P,scope:d?N:void 0};let J;if(d?(J=await n(G,u),J&&l(null)):J=await i(j,G,u),J){const T=gn.getState().changes.some(W=>W.scope==="commands"&&W.id.startsWith(`commands:${j}:`));D.success(t(T?"settings.view.pendingRestart.saved":d?"settings.commands.page.toast.created":"settings.commands.page.toast.updated"))}else D.error(t(d?"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(ns,{title:d?t("settings.commands.page.title.new"):`/${e}`,description:t(d?"settings.commands.page.subtitle.new":"settings.commands.page.subtitle.edit"),showSaveStatus:!1,children:[s.jsxs($e,{title:t("settings.commands.page.section.identity"),divider:!1,contentClassName:"space-y-0",children:[d&&s.jsxs(Vt,{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(We,{value:v,onChange:j=>c(j.target.value),placeholder:t("settings.commands.page.field.commandNamePlaceholder"),className:"h-7 w-40 px-2"})]}),s.jsxs(At,{value:N,onValueChange:j=>b(j),children:[s.jsx(Et,{size:$t,className:"w-fit min-w-[100px]",children:s.jsx(Ft,{placeholder:t("settings.agents.page.field.scopePlaceholder")})}),s.jsxs(Tt,{align:"end",children:[s.jsx(ot,{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(ot,{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(Is,{value:C,onChange:j=>k(j.target.value),placeholder:t("settings.commands.page.field.descriptionPlaceholder"),rows:2,className:"w-full resize-none min-h-[60px] bg-transparent"})})]})]}),s.jsxs($e,{title:t("settings.commands.page.section.executionContext"),contentClassName:"space-y-0",children:[s.jsx(Vt,{settingsItem:"commands.agent",label:t("settings.commands.page.field.overrideAgent"),children:s.jsx(ll,{agentName:A,onChange:j=>h(j),className:Sn})}),s.jsx(Vt,{settingsItem:"commands.model",label:t("settings.agents.page.field.overrideModel"),children:s.jsx(Da,{providerId:oa(E)?.providerId??"",modelId:oa(E)?.modelId??"",onChange:(j,R)=>{F(j&&R?`${j}/${R}`:"")},className:Sn})})]}),s.jsxs($e,{title:t("settings.commands.page.section.template"),settingsItem:"commands.template",children:[s.jsx(Is,{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:M,disabled:m||!S,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=lt.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=we("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},Pp=t=>{const e=lt.c(124),{onItemSelect:a}=t,{t:n}=nt(),{selectedMcpName:i,setSelectedMcp:r,setMcpDraft:l,loadMcpConfigs:u,deleteMcp:g}=ca(Ds(Ip)),x=zs();let d;e[0]!==x?(d=q=>cl(q,x),e[0]=x,e[1]=d):d=e[1];const v=ca(d);let c;e[2]!==x?(c=q=>q.getStatusForDirectory(x),e[2]=x,e[3]=c):c=e[3];const N=Os(c),b=Os(Ap),C=Os(Ep),[k,A]=o.useState(null),[h,E]=o.useState(!1),[F,I]=o.useState(null),[w,m]=o.useState(null),[y,U]=o.useState(!1);let S;e[4]!==v?(S=v.filter(Tp),e[4]=v,e[5]=S):S=e[5];const M=S;let j;e[6]!==v?(j=v.filter(Dp),e[6]=v,e[7]=j):j=e[7];const R=j;let H,P;e[8]!==u||e[9]!==x?(H=()=>{u({directory:x})},P=[u,x],e[8]=u,e[9]=x,e[10]=H,e[11]=P):(H=e[10],P=e[11]),o.useEffect(H,P);let G;e[12]!==C||e[13]!==y||e[14]!==b||e[15]!==x?(G=()=>{if(y)return;U(!0);const q=new Promise(Mp);Promise.all([b({directory:x,silent:!0}),q]).then(()=>{const ke=C(x);ke&&D.error(ke)}).finally(()=>{U(!1)})},e[12]=C,e[13]=y,e[14]=b,e[15]=x,e[16]=G):G=e[16];const J=G;let T;e[17]!==v||e[18]!==a||e[19]!==l||e[20]!==r?(T=()=>{let q="new-mcp-server",ke=1;for(;v.some(Ce=>Ce.name===q);)q=`new-mcp-server-${ke}`,ke++;l({name:q,scope:"user",type:"local",command:[],url:"",environment:[],headers:[],oauthEnabled:!0,oauthClientId:"",oauthClientSecret:"",oauthScope:"",oauthRedirectUri:"",timeout:"",enabled:!0}),r(q),a?.()},e[17]=v,e[18]=a,e[19]=l,e[20]=r,e[21]=T):T=e[21];const W=T;let X;e[22]!==g||e[23]!==k||e[24]!==x||e[25]!==n?(X=async()=>{if(!k)return;E(!0);const q=await g(k.name,x);q.ok?q.reloadFailed?D.warning(q.message||`MCP server "${k.name}" deleted, but OpenCode reload failed`,{description:q.warning||n("settings.mcp.sidebar.toast.refreshListIfStale")}):D.success(q.message||n("settings.mcp.sidebar.toast.serverDeleted",{name:k.name})):D.error(n("settings.mcp.sidebar.toast.deleteFailed")),A(null),E(!1)},e[22]=g,e[23]=k,e[24]=x,e[25]=n,e[26]=X):X=e[26];const K=X;let te;e[27]!==n?(te=(q,ke)=>s.jsxs(ke,{onClick:O=>{O.stopPropagation(),A(q)},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]=te):te=e[28];const $=te;let V;e[29]===Symbol.for("react.memo_cache_sentinel")?(V=we("flex h-full flex-col","bg-background"),e[29]=V):V=e[29];let _;e[30]!==n?(_=n("settings.mcp.sidebar.title"),e[30]=n,e[31]=_):_=e[31];let z;e[32]!==_?(z=s.jsx("h2",{className:nn,children:_}),e[32]=_,e[33]=z):z=e[33];let Z;e[34]!==n?(Z=n("settings.mcp.sidebar.actions.refreshStatusAria"),e[34]=n,e[35]=Z):Z=e[35];let Y;e[36]!==n?(Y=n("settings.mcp.sidebar.actions.refreshStatusTitle"),e[36]=n,e[37]=Y):Y=e[37];const se=y&&"animate-spin";let ge;e[38]!==se?(ge=we("h-4 w-4",se),e[38]=se,e[39]=ge):ge=e[39];let ce;e[40]!==ge?(ce=s.jsx(L,{name:"refresh",className:ge}),e[40]=ge,e[41]=ce):ce=e[41];let be;e[42]!==J||e[43]!==y||e[44]!==Z||e[45]!==Y||e[46]!==ce?(be=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:J,"aria-label":Z,title:Y,children:ce}),e[42]=J,e[43]=y,e[44]=Z,e[45]=Y,e[46]=ce,e[47]=be):be=e[47];let ne;e[48]!==z||e[49]!==be?(ne=s.jsxs("div",{className:"mb-3 flex items-center justify-between gap-3",children:[z,be]}),e[48]=z,e[49]=be,e[50]=ne):ne=e[50];let ae;e[51]===Symbol.for("react.memo_cache_sentinel")?(ae=s.jsx(za,{className:"mb-3"}),e[51]=ae):ae=e[51];let me;e[52]!==v.length||e[53]!==n?(me=n("settings.mcp.sidebar.total",{count:v.length}),e[52]=v.length,e[53]=n,e[54]=me):me=e[54];let Pe;e[55]!==me?(Pe=s.jsx("span",{className:"typography-meta text-muted-foreground",children:me}),e[55]=me,e[56]=Pe):Pe=e[56];let Ne;e[57]!==n?(Ne=n("settings.mcp.sidebar.actions.addServerTitle"),e[57]=n,e[58]=Ne):Ne=e[58];let Se;e[59]===Symbol.for("react.memo_cache_sentinel")?(Se=s.jsx(L,{name:"add",className:"h-3.5 w-3.5"}),e[59]=Se):Se=e[59];let je;e[60]!==W||e[61]!==Ne?(je=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:Ne,children:Se}),e[60]=W,e[61]=Ne,e[62]=je):je=e[62];let Me;e[63]!==Pe||e[64]!==je?(Me=s.jsxs("div",{className:"flex items-center justify-between gap-2",children:[Pe,je]}),e[63]=Pe,e[64]=je,e[65]=Me):Me=e[65];let Re;e[66]!==ne||e[67]!==Me?(Re=s.jsxs("div",{className:"border-b px-3 pt-4 pb-3",children:[ne,ae,Me]}),e[66]=ne,e[67]=Me,e[68]=Re):Re=e[68];let re;e[69]!==v.length||e[70]!==N||e[71]!==a||e[72]!==F||e[73]!==M||e[74]!==$||e[75]!==w||e[76]!==i||e[77]!==l||e[78]!==r||e[79]!==n||e[80]!==R?(re=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:[M.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")}),M.map(q=>{const ke=N[q.name],O=so(ke?.status),Ce=i===q.name,qe=La();return s.jsxs(Bn,{open:w===q.name,onOpenChange:_e=>m(_e?q.name:null),children:[s.jsxs(Vn,{render:s.jsx("div",{className:we("group relative flex items-center rounded-md px-1.5 py-1 transition-all duration-200 select-none",Ce?"bg-interactive-selection":"hover:bg-interactive-hover"),onContextMenu:qe?void 0:_e=>{_e.preventDefault(),m(q.name)}}),children:[s.jsxs("button",{onClick:()=>{r(q.name),l(null),a?.()},className:"flex min-w-0 flex-1 flex-col gap-0 rounded-sm text-left focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-primary/50",children:[s.jsxs("div",{className:"flex items-center gap-2",children:[s.jsx(no,{tone:O,enabled:q.enabled}),s.jsx("span",{className:"typography-ui-label font-normal truncate text-foreground",children:q.name}),s.jsx("span",{title:q.type==="local"?n("settings.mcp.sidebar.serverType.localTitle"):n("settings.mcp.sidebar.serverType.remoteTitle"),children:q.type==="local"?s.jsx(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:q.type==="local"?q.command?.join(" ")??"":q.url??""})]}),s.jsxs(tn,{open:F===q.name,onOpenChange:_e=>{_e&&m(null),I(_e?q.name:null)},children:[s.jsx(Zs,{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(en,{align:"end",className:"w-fit min-w-20",children:$(q,sn)})]})]}),s.jsx(_n,{className:"w-fit min-w-20",children:$(q,$n)})]},q.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(q=>{const ke=N[q.name],O=so(ke?.status),Ce=i===q.name,qe=La();return s.jsxs(Bn,{open:w===q.name,onOpenChange:_e=>m(_e?q.name:null),children:[s.jsxs(Vn,{render:s.jsx("div",{className:we("group relative flex items-center rounded-md px-1.5 py-1 transition-all duration-200 select-none",Ce?"bg-interactive-selection":"hover:bg-interactive-hover"),onContextMenu:qe?void 0:_e=>{_e.preventDefault(),m(q.name)}}),children:[s.jsxs("button",{onClick:()=>{r(q.name),l(null),a?.()},className:"flex min-w-0 flex-1 flex-col gap-0 rounded-sm text-left focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-primary/50",children:[s.jsxs("div",{className:"flex items-center gap-2",children:[s.jsx(no,{tone:O,enabled:q.enabled}),s.jsx("span",{className:"typography-ui-label font-normal truncate text-foreground",children:q.name}),s.jsx("span",{title:q.type==="local"?n("settings.mcp.sidebar.serverType.localTitle"):n("settings.mcp.sidebar.serverType.remoteTitle"),children:q.type==="local"?s.jsx(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:q.type==="local"?q.command?.join(" ")??"":q.url??""})]}),s.jsxs(tn,{open:F===q.name,onOpenChange:_e=>{_e&&m(null),I(_e?q.name:null)},children:[s.jsx(Zs,{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(en,{align:"end",className:"w-fit min-w-20",children:$(q,sn)})]})]}),s.jsx(_n,{className:"w-fit min-w-20",children:$(q,$n)})]},q.name)})]})]})}),e[69]=v.length,e[70]=N,e[71]=a,e[72]=F,e[73]=M,e[74]=$,e[75]=w,e[76]=i,e[77]=l,e[78]=r,e[79]=n,e[80]=R,e[81]=re):re=e[81];const fe=k!==null;let Ee;e[82]!==h?(Ee=q=>{!q&&!h&&A(null)},e[82]=h,e[83]=Ee):Ee=e[83];let Be;e[84]!==n?(Be=n("settings.mcp.sidebar.deleteDialog.title"),e[84]=n,e[85]=Be):Be=e[85];let Ve;e[86]!==Be?(Ve=s.jsx(Ut,{children:Be}),e[86]=Be,e[87]=Ve):Ve=e[87];const Ge=k?.name||"";let Ke;e[88]!==n||e[89]!==Ge?(Ke=n("settings.mcp.sidebar.deleteDialog.descriptionPrefix",{name:Ge}),e[88]=n,e[89]=Ge,e[90]=Ke):Ke=e[90];let oe;e[91]===Symbol.for("react.memo_cache_sentinel")?(oe=s.jsx("code",{className:"text-foreground",children:"opencode.json"}),e[91]=oe):oe=e[91];let ie;e[92]!==Ke?(ie=s.jsxs(zt,{children:[Ke," ",oe,"."]}),e[92]=Ke,e[93]=ie):ie=e[93];let ye;e[94]!==Ve||e[95]!==ie?(ye=s.jsxs(Kt,{children:[Ve,ie]}),e[94]=Ve,e[95]=ie,e[96]=ye):ye=e[96];let ve;e[97]===Symbol.for("react.memo_cache_sentinel")?(ve=()=>A(null),e[97]=ve):ve=e[97];let Oe;e[98]!==n?(Oe=n("settings.common.actions.cancel"),e[98]=n,e[99]=Oe):Oe=e[99];let Te;e[100]!==h||e[101]!==Oe?(Te=s.jsx(B,{size:"sm",variant:"ghost",onClick:ve,disabled:h,children:Oe}),e[100]=h,e[101]=Oe,e[102]=Te):Te=e[102];let xe;e[103]!==h||e[104]!==n?(xe=n(h?"settings.mcp.sidebar.actions.deleting":"settings.common.actions.delete"),e[103]=h,e[104]=n,e[105]=xe):xe=e[105];let He;e[106]!==K||e[107]!==h||e[108]!==xe?(He=s.jsx(B,{size:"sm",onClick:K,disabled:h,children:xe}),e[106]=K,e[107]=h,e[108]=xe,e[109]=He):He=e[109];let ue;e[110]!==Te||e[111]!==He?(ue=s.jsxs(es,{children:[Te,He]}),e[110]=Te,e[111]=He,e[112]=ue):ue=e[112];let Ie;e[113]!==ye||e[114]!==ue?(Ie=s.jsxs(Ot,{className:"max-w-md",children:[ye,ue]}),e[113]=ye,e[114]=ue,e[115]=Ie):Ie=e[115];let Le;e[116]!==fe||e[117]!==Ee||e[118]!==Ie?(Le=s.jsx(Rt,{open:fe,onOpenChange:Ee,children:Ie}),e[116]=fe,e[117]=Ee,e[118]=Ie,e[119]=Le):Le=e[119];let Ye;return e[120]!==Re||e[121]!==re||e[122]!==Le?(Ye=s.jsxs("div",{className:V,children:[Re,re,Le]}),e[120]=Re,e[121]=re,e[122]=Le,e[123]=Ye):Ye=e[123],Ye};function Ip(t){return{selectedMcpName:t.selectedMcpName,setSelectedMcp:t.setSelectedMcp,setMcpDraft:t.setMcpDraft,loadMcpConfigs:t.loadMcpConfigs,deleteMcp:t.deleteMcp}}function Ap(t){return t.refresh}function Ep(t){return t.getErrorForDirectory}function Tp(t){return t.scope==="project"}function Dp(t){return t.scope!=="project"}function Mp(t){return setTimeout(t,500)}function Ys(t){return typeof t=="object"&&t!==null&&!Array.isArray(t)}function ka(t){return Array.isArray(t)&&t.every(e=>typeof e=="string")}function Qs(t,e){return e!==void 0?{ok:!1,error:t,parsed:e}:{ok:!1,error:t}}function Wa(t,e,a){const n=Rp(a),i=typeof a.url=="string"?a.url.trim():"",r=ao(a,"env","environment"),l=ao(a,"headers"),u=Op(a),g=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():"",d=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():"",c=Lp(a),N=Fp(a);return{ok:!0,name:t,type:e,command:n,url:i,environment:r,headers:l,oauthEnabled:u,oauthClientId:g,oauthClientSecret:x,oauthScope:d,oauthRedirectUri:v,timeout:c,enabled:N}}function Rp(t){const e=t.command,a=t.args;if(ka(e)&&ka(a))return[...e,...a];if(ka(e))return e;if(typeof e=="string"&&e.trim()){const n=e.trim().split(/\s+/);return ka(a)?[...n,...a]:n}return ka(a)?a:[]}function ao(t,...e){for(const a of e){const n=t[a];if(!Ys(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 Op(t){if(t.oauth===!1||t.oauth===null||t.oauth===void 0||!Ys(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 Lp(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 Fp(t){return"disabled"in t&&t.disabled===!0?!1:"enabled"in t?!!t.enabled:!0}function Kp(t){const e=t.mcpServers;if(Ys(e)){const n=Object.keys(e);if(n.length===1){const i=n[0],r=e[i];if(Ys(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"&&Ys(i)});if(a.length===1){const n=a[0],i=t[n];if(Tl(i))return{name:n,entry:i}}return null}function Tl(t){return t.type==="local"||t.type==="remote"||Array.isArray(t.command)||typeof t.url=="string"||Array.isArray(t.args)}function Up(t,e){let a;try{const u=t.trim();if(!u)return Qs("No JSON content provided");a=JSON.parse(u)}catch(u){return Qs(u instanceof Error?`Invalid JSON: ${u.message}`:"Invalid JSON")}if(!Ys(a))return Qs("Expected a JSON object, not an array or primitive");const n=a,i=n.mcpServers;if(Ys(i)){const u=Object.keys(i);if(u.length===0)return Qs("mcpServers object is empty",a);if(u.length>1)return Qs("Paste one server at a time. Found "+u.length+" servers in mcpServers",a);const g=u[0],x=i[g];return Ys(x)?Wa(g,Ja(x),x):Qs("Server entry is not a valid object",a)}const r=n.mcp;if(Ys(r)){const u=Object.keys(r);if(u.length===0)return Qs("mcp object is empty",a);if(u.length>1)return Qs("Paste one server at a time. Found "+u.length+" servers in mcp",a);const g=u[0],x=r[g];return Ys(x)?Wa(g,Ja(x),x):Qs("Server entry in mcp is not a valid object",a)}const l=Kp(n);if(l)return Wa(l.name,Ja(l.entry),l.entry);if(Tl(n)){const u=Ja(n),g=typeof n.name=="string"&&n.name.trim()?n.name.trim():e?.fallbackName;return Wa(g,u,n)}return Qs("No recognizable MCP server configuration found in JSON",a)}function Ja(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 zp(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 Dl(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 _p(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:mc(a.searchParams),stateKey:dl(a.searchParams)}}catch{}return{code:e,context:null,stateKey:null}}const $p=t=>{const e=lt.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[u,g]=o.useState(l),x=o.useRef(a);let d,v;e[2]!==a?(d=()=>{JSON.stringify(x.current)!==JSON.stringify(a)&&(x.current=a,g(a.join(`
|
|
5
|
+
`)))},v=[a],e[2]=a,e[3]=d,e[4]=v):(d=e[3],v=e[4]),o.useEffect(d,v);let c;e[5]!==n||e[6]!==r?(c=w=>{const m=w.split(`
|
|
6
|
+
`).filter(Qp);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]=c):c=e[7];const N=c;let b;e[8]!==n?(b=w=>{const y=w.clipboardData.getData("text").trim();if(!y||y.includes(`
|
|
7
|
+
`)||!/\s/.test(y))return;const U=w.currentTarget;if(U.selectionStart!==0||U.selectionEnd!==U.value.length)return;w.preventDefault();const S=Dl(y);g(S.join(`
|
|
8
|
+
`)),n(S)},e[8]=n,e[9]=b):b=e[9];const C=b;let k;e[10]!==N?(k=w=>{g(w.target.value),N(w.target.value)},e[10]=N,e[11]=k):k=e[11];let A;e[12]!==N||e[13]!==u?(A=()=>{const w=u.split(`
|
|
9
|
+
`).map(Yp).join(`
|
|
10
|
+
`);g(w),N(w)},e[12]=N,e[13]=u,e[14]=A):A=e[14];const h=Math.max(4,a.length+1);let E;e[15]!==C||e[16]!==k||e[17]!==A||e[18]!==h||e[19]!==u?(E=s.jsx(Is,{onPaste:C,value:u,onChange:k,onBlur:A,placeholder:`npx
|
|
11
|
+
-y
|
|
12
|
+
@modelcontextprotocol/server-postgres
|
|
13
|
+
postgresql://user:pass@host/db`,rows:h,className:"font-mono typography-meta min-h-[80px]",spellCheck:!1}),e[15]=C,e[16]=k,e[17]=A,e[18]=h,e[19]=u,e[20]=E):E=e[20];let F;e[21]!==i||e[22]!==a?(F=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(Xp)})})]}),e[21]=i,e[22]=a,e[23]=F):F=e[23];let I;return e[24]!==F||e[25]!==E?(I=s.jsxs("div",{className:"space-y-2","data-bwignore":"true","data-1p-ignore":"true","data-lpignore":"true",children:[E,F]}),e[24]=F,e[25]=E,e[26]=I):I=e[26],I},Vp=t=>t.toUpperCase().replace(/[^A-Z0-9_]/g,"_"),io=({value:t,onChange:e,keyTransform:a=Vp,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:u,importSuccess:g,clipboardReadFailed:x,keyLabel:d,valueLabel:v,valuePlaceholder:c,hideValueTitle:N,showValueTitle:b,addVariable:C,plainTextWarning:k,removeVariableAria:A})=>{const[h,E]=o.useState(new Set),F=()=>e([...t,{key:"",value:""}]),I=S=>{e(t.filter((M,j)=>j!==S)),E(M=>{const j=new Set(M);return j.delete(S),j})},w=(S,M,j)=>{const R=[...t];R[S]={...R[S],[M]:j},e(R)},m=S=>{E(M=>{const j=new Set(M);return j.has(S)?j.delete(S):j.add(S),j})},y=async()=>{try{const S=await navigator.clipboard.readText(),M=[];for(const R of S.split(`
|
|
14
|
+
`)){const H=R.trim();if(!H||H.startsWith("#"))continue;const P=H.indexOf("=");if(P===-1)continue;const G=H.slice(0,P).trim();let J=H.slice(P+1).trim();(J.startsWith('"')&&J.endsWith('"')||J.startsWith("'")&&J.endsWith("'"))&&(J=J.slice(1,-1)),G&&M.push({key:G,value:J})}if(M.length===0){D.error(u);return}const j=[...t];for(const R of M){const H=j.findIndex(P=>P.key===R.key);H!==-1?j[H]=R:j.push(R)}e(j),D.success(g(M.length))}catch{D.error(x)}},U=t.some(S=>S.value.length>0);return s.jsxs("div",{className:"space-y-2",children:[s.jsxs("div",{className:"flex items-center justify-between gap-2",children:[s.jsxs("div",{className:"flex items-center gap-3",children:[s.jsx("span",{className:"typography-micro text-muted-foreground w-32 shrink-0",children:d}),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((S,M)=>s.jsxs("div",{className:"flex items-center gap-2",children:[s.jsx(We,{value:S.key,onChange:j=>w(M,"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(We,{type:h.has(M)?"text":"password",value:S.value,onChange:j=>w(M,"value",j.target.value),placeholder:c,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(M),className:"absolute right-2 text-muted-foreground/60 hover:text-muted-foreground",title:h.has(M)?N:b,children:h.has(M)?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(M),"aria-label":A,children:s.jsx(L,{name:"delete-bin",className:"h-3.5 w-3.5"})})]},M))}),s.jsxs(B,{variant:"outline",size:"xs",className:"!font-normal gap-1.5",onClick:F,type:"button",children:[s.jsx(L,{name:"add",className:"h-3.5 w-3.5"}),C]}),U&&s.jsx("p",{className:"typography-micro text-muted-foreground/60",children:k})]})},Oi=t=>{const e=lt.c(14),{status:a,enabled:n,getStatusLabel:i,variant:r}=t,l=r===void 0?"compact":r;if(!n||!a)return null;let u,g;if(e[0]!==i||e[1]!==a||e[2]!==l){g=Symbol.for("react.early_return_sentinel");e:{const c={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 N=we("typography-micro font-medium rounded-full px-2 py-0.5",c.text,c.bg);let b;e[5]!==i||e[6]!==a?(b=i(a),e[5]=i,e[6]=a,e[7]=b):b=e[7],g=s.jsxs("span",{className:N,children:["● ",b]});break e}u=we("typography-micro font-medium",c.text)}e[0]=i,e[1]=a,e[2]=l,e[3]=u,e[4]=g}else u=e[3],g=e[4];if(g!==Symbol.for("react.early_return_sentinel"))return g;let x;e[8]!==i||e[9]!==a?(x=i(a),e[8]=i,e[9]=a,e[10]=x):x=e[10];let d;return e[11]!==u||e[12]!==x?(d=s.jsxs("span",{className:u,children:["● ",x]}),e[11]=u,e[12]=x,e[13]=d):d=e[13],d},Bp=(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")}},Hp=t=>{switch(t){case"failed":return"border-[var(--status-error-border)] bg-[var(--status-error-background)]";case"needs_auth":case"needs_client_registration":return"border-[var(--status-warning-border)] bg-[var(--status-warning-background)]";default:return"border-[var(--interactive-border)] bg-[var(--surface-elevated)]"}},Gp=(t,e,a,n)=>!!(t==="failed"||t==="needs_auth"||t==="needs_client_registration"||e||a||n),qp=async t=>{const e=await rt(`/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},Na=async t=>{typeof t!="string"||!t.trim()||await rt(`/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},Wp=(t,e)=>{const a=typeof e=="string"&&e.trim()?e.trim():"__global__";return`${t??"__none__"}::${a}`},Jp=()=>{const{t}=nt(),e=o.useCallback((le,dt)=>t(le,dt),[t]),{selectedMcpName:a,mcpDraft:n,setMcpDraft:i,setSelectedMcp:r,getMcpByName:l,createMcp:u,updateMcp:g,deleteMcp:x}=ca(Ds(le=>({selectedMcpName:le.selectedMcpName,mcpDraft:le.mcpDraft,setMcpDraft:le.setMcpDraft,setSelectedMcp:le.setSelectedMcp,getMcpByName:le.getMcpByName,createMcp:le.createMcp,updateMcp:le.updateMcp,deleteMcp:le.deleteMcp}))),d=zs(),v=o.useMemo(()=>ps(),[]),c=Os(le=>le.getStatusForDirectory(d)),N=Os(le=>le.getDiagnosticForDirectory(d)),b=Os(le=>le.refresh),C=Os(le=>le.connect),k=Os(le=>le.disconnect),A=Os(le=>le.completeAuth),h=Os(le=>le.clearAuth),E=Os(le=>le.testConnection),F=gn(le=>le.changes),I=ca(le=>cl(le,d)),w=a?l(a,d):null,m=!!(n&&n.name===a&&!w),[y,U]=o.useState(""),[S,M]=o.useState("user"),[j,R]=o.useState("local"),[H,P]=o.useState([]),[G,J]=o.useState(""),[T,W]=o.useState([]),[X,K]=o.useState([]),[te,$]=o.useState(!0),[V,_]=o.useState(""),[z,Z]=o.useState(""),[Y,se]=o.useState(""),[ge,ce]=o.useState(""),[be,ne]=o.useState(""),[ae,me]=o.useState(!0),[Pe,Ne]=o.useState(!1),[Se,je]=o.useState(!1),[Me,Re]=o.useState(!1),[re,fe]=o.useState(!1),[Ee,Be]=o.useState(!1),[Ve,Ge]=o.useState(!1),[Ke,oe]=o.useState(!1),[ie,ye]=o.useState(!1),[ve,Oe]=o.useState(null),[Te,xe]=o.useState(null),[He,ue]=o.useState(""),[Ie,Le]=o.useState(!1),Ye=o.useRef(0),q=o.useRef(!1),[ke,O]=o.useState(!1),[Ce,qe]=o.useState(!1),[_e,tt]=o.useState(""),[ht,mt]=o.useState(null),ut=o.useMemo(()=>Wp(a,d),[d,a]),ft=o.useRef(ut),kt=o.useRef(null),vt=o.useCallback(()=>{Oe(null),xe(null),ue(""),Le(!1),Ye.current=0,ye(!1),Be(!1),Ge(!1),q.current=!1},[]),Ct=o.useCallback(()=>{tt(""),mt(null),qe(!0)},[]),Ze=o.useCallback(async()=>{try{const le=await navigator.clipboard.readText();tt(le),mt(null)}catch{D.error(t("settings.mcp.page.toast.clipboardReadFailed"))}},[t]),Xe=o.useCallback(()=>{const le=Up(_e,{fallbackName:y});if(!le.ok){mt(le.error);return}const bt=zp(le,{name:y,scope:S,type:j,command:H,url:G,environment:T,headers:X,oauthEnabled:te,oauthClientId:V,oauthClientSecret:z,oauthScope:Y,oauthRedirectUri:ge,timeout:be,enabled:ae},{isNewServer:m});U(bt.name),R(bt.type),P(bt.command??[]),J(bt.url??""),W(bt.environment??[]),K(bt.headers??[]),$(bt.oauthEnabled??!1),_(bt.oauthClientId??""),Z(bt.oauthClientSecret??""),se(bt.oauthScope??""),ce(bt.oauthRedirectUri??""),ne(bt.timeout??""),me(bt.enabled??!0),qe(!1),tt(""),mt(null),D.success(t("settings.mcp.page.toast.configImported"))},[_e,y,S,j,H,G,T,X,te,V,z,Y,ge,be,ae,m,t]);o.useEffect(()=>{if(m&&n){U(n.name),M(n.scope||"user"),R(n.type),P(n.command),J(n.url),W(n.environment),K(n.headers),$(n.oauthEnabled),_(n.oauthClientId),Z(n.oauthClientSecret),se(n.oauthScope),ce(n.oauthRedirectUri),ne(n.timeout),me(n.enabled),O(!1),kt.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){M(w.scope==="project"?"project":"user");const le=Cr(w.environment),dt=w.type==="remote"?w:null,bt=Cr(dt?.headers),Qt=dt?.oauth,Yt=Qt&&typeof Qt=="object"?Qt:null,Ht=Qt!==!1,as=w.type,js=as==="local"?w.command??[]:[],ls=as==="remote"?w.url??"":"",St=typeof dt?.timeout=="number"&&Number.isFinite(dt.timeout)?String(dt.timeout):"";R(as),P(js),J(ls),W(le),K(bt),$(Ht),_(Ht?Yt?.clientId??"":""),Z(Ht?Yt?.clientSecret??"":""),se(Ht?Yt?.scope??"":""),ce(Ht?Yt?.redirectUri??"":""),ne(St),me(w.enabled),O(!1),kt.current={mcpType:as,command:js,url:ls,envEntries:le,headerEntries:bt,oauthEnabled:Ht,oauthClientId:Ht?Yt?.clientId??"":"",oauthClientSecret:Ht?Yt?.clientSecret??"":"",oauthScope:Ht?Yt?.scope??"":"",oauthRedirectUri:Ht?Yt?.redirectUri??"":"",timeout:St,enabled:w.enabled}}},[w,m,n]);const ct=o.useMemo(()=>{const le=kt.current;return le?j!==le.mcpType||ae!==le.enabled||JSON.stringify(H)!==JSON.stringify(le.command)||G!==le.url||JSON.stringify(T)!==JSON.stringify(le.envEntries)||JSON.stringify(X)!==JSON.stringify(le.headerEntries)||te!==le.oauthEnabled||V!==le.oauthClientId||z!==le.oauthClientSecret||Y!==le.oauthScope||ge!==le.oauthRedirectUri||be!==le.timeout:!1},[j,H,G,T,X,te,V,z,Y,ge,be,ae]),Ue=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]),jt=o.useCallback(le=>{R("remote"),J(le),P([])},[]),Ae=o.useCallback(le=>{J(le);const dt=le.trim();dt&&!/^[a-z][a-z0-9+.-]*:\/\//i.test(dt)&&/\s/.test(dt)&&(R("local"),P(Dl(dt)),J(""))},[]),yt=async()=>{const le=m?y.trim():a??"";if(!le){D.error(t("settings.mcp.page.toast.nameRequired"));return}if(m&&I.some(bt=>bt.name===le)){D.error(t("settings.mcp.page.toast.serverNameExists"));return}if(j==="local"&&H.filter(Boolean).length===0){D.error(t("settings.mcp.page.toast.localCommandRequired"));return}if(j==="remote"&&!G.trim()){D.error(t("settings.mcp.page.toast.remoteUrlRequired"));return}const dt={name:le,scope:S,type:j,command:H,url:G,environment:T,headers:X,oauthEnabled:te,oauthClientId:V,oauthClientSecret:z,oauthScope:Y,oauthRedirectUri:ge,timeout:be,enabled:ae};Ne(!0);try{const bt=m?await u(dt,d):await g(le,dt,d);bt.ok?(await Na(Te),vt(),m&&(i(null),r(le)),await b({directory:d,silent:!0}),bt.reloadFailed?D.warning(bt.message||t(m?"settings.mcp.page.toast.serverCreatedReloadFailed":"settings.mcp.page.toast.savedReloadFailed"),{description:bt.warning||t("settings.mcp.page.toast.retryRefreshHint")}):bt.restartDeferred?D.success(t("settings.view.pendingRestart.saved")):D.success(bt.message||t(m?"settings.mcp.page.toast.serverCreatedReloading":"settings.mcp.page.toast.savedReloading"))):D.error(t("settings.mcp.page.toast.saveFailed"))}catch(bt){D.error(bt instanceof Error?bt.message:t("settings.mcp.page.toast.unexpectedError"))}finally{Ne(!1)}},Q=async()=>{if(!a)return;Re(!0);const le=await x(a,d);le.ok?(await Na(Te),vt(),le.reloadFailed?D.warning(le.message||t("settings.mcp.page.toast.serverDeletedReloadFailed",{name:a}),{description:le.warning||t("settings.mcp.page.toast.refreshListIfStale")}):D.success(le.message||t("settings.mcp.page.toast.serverDeleted",{name:a})),je(!1)):D.error(t("settings.mcp.page.toast.deleteFailed")),Re(!1)},he=async()=>{if(a){fe(!0);try{if(c[a]?.status==="connected")await k(a,d),D.success(t("settings.mcp.page.toast.disconnected"));else{await C(a,d),await b({directory:d,silent:!0});const dt=Os.getState().getStatusForDirectory(d)[a];dt?.status==="connected"?D.success(t("settings.mcp.page.toast.connected")):dt?.status==="needs_auth"?D.message(t("settings.mcp.page.toast.connectionNeedsAuthorization")):dt?.status==="needs_client_registration"?D.message(t("settings.mcp.page.toast.connectionNeedsClientRegistration")):dt?.status==="failed"?D.error(dt.error||t("settings.mcp.page.toast.connectionFailed")):D.message(t("settings.mcp.page.toast.connectionAttemptFinished"));return}await b({directory:d,silent:!0})}catch(le){D.error(le instanceof Error?le.message:t("settings.mcp.page.toast.connectionFailed"))}finally{fe(!1)}}},ze=o.useCallback(()=>m?(D.error(t("settings.mcp.page.toast.createServerBeforeLiveActions")),!1):ct?(D.error(t("settings.mcp.page.toast.saveBeforeLiveActions")),!1):!0,[ct,m,t]),De=o.useCallback(async(le=!1)=>{try{await b({directory:d,silent:le})}catch(dt){le||D.error(dt instanceof Error?dt.message:t("settings.mcp.page.toast.refreshStatusFailed"))}},[d,b,t]);o.useEffect(()=>{De(!0)},[De]),o.useEffect(()=>{ft.current=ut,fe(!1),oe(!1),vt()},[vt,ut]);const it=o.useCallback(async()=>{if(!a||j!=="remote"||!ze())return;Be(!0);const le=ut;let dt=null;try{const bt=Os.getState().getStatusForDirectory(d)[a]?.status;q.current=bt==="needs_auth"||bt==="needs_client_registration";const{authorizationUrl:Qt,opened:Yt,nativeFlow:Ht,completion:as}=await dc({name:a,directory:d});if(Ht){if(ft.current!==le)return;Oe(null),xe(null),Le(!0),Ye.current=0,D.message(t("settings.mcp.page.toast.completeAuthorizationInBrowser")),as?.then(()=>{ft.current===le&&(Le(!1),Ye.current=0,q.current=!1,D.success(t("settings.mcp.page.toast.authorizationCompleted")))}).catch(ls=>{ft.current===le&&(Le(!1),Ye.current=0,q.current=!1,D.error(Qa(ls,t("settings.mcp.page.toast.authorizationFailed"),e)))});return}const js=dl(new URL(Qt).searchParams);if(dt=js,ft.current!==le||(Oe(Qt),xe(js??null),Le(!0),Ye.current=0,ft.current!==le))return;Yt?D.message(t(v?"settings.mcp.page.toast.completeAuthorizationInBrowserWithPaste":"settings.mcp.page.toast.completeAuthorizationInBrowser")):D.error(t("settings.mcp.page.toast.openAuthorizationUrlFailed"))}catch(bt){await Na(dt),ft.current===le&&D.error(Qa(bt,t("settings.mcp.page.toast.authorizationStartFailed"),e))}finally{ft.current===le&&Be(!1)}},[d,v,j,ze,ut,a,t,e]),at=o.useCallback(async()=>{if(!a||!ze())return;Ge(!0);const le=ut;try{if(await h(a,d),ft.current!==le)return;Oe(null),xe(null),ue(""),Le(!1),Ye.current=0,await Na(Te),D.success(t("settings.mcp.page.toast.savedAuthorizationRemoved"))}catch(dt){ft.current===le&&D.error(Qa(dt,t("settings.mcp.page.toast.clearAuthorizationFailed"),e))}finally{ft.current===le&&Ge(!1)}},[Te,h,d,ze,ut,a,t,e]),Je=o.useCallback(async()=>{if(!ve)return;if((await Ma(ve)).ok){D.success(t("settings.mcp.page.toast.authorizationUrlCopied"));return}D.error(t("settings.mcp.page.toast.authorizationUrlCopyFailed"))},[ve,t]),Nt=o.useCallback(async()=>{const le=_p(He);if(!le.code){D.error(t("settings.mcp.page.toast.pasteCallbackOrCodeFirst"));return}const dt=le.stateKey?await qp(le.stateKey):null,bt=le.context??dt,Qt=bt?.name??a,Yt=bt?.directory??d;if(!Qt){D.error(t("settings.mcp.page.toast.missingServerDetails"));return}if(!bt&&!ze())return;ye(!0);const Ht=ut;try{if(await A(Qt,le.code,Yt),await Na(le.stateKey??Te),ft.current!==Ht)return;ue(""),Oe(null),xe(null),Le(!1),Ye.current=0,D.success(Qt===a?t("settings.mcp.page.toast.authorizationCompleted"):t("settings.mcp.page.toast.authorizationCompletedFor",{name:Qt}))}catch(as){ft.current===Ht&&D.error(Qa(as,t("settings.mcp.page.toast.authorizationCompleteFailed"),e))}finally{ft.current===Ht&&ye(!1)}},[He,Te,A,d,ze,ut,a,t,e]),xs=o.useCallback(async()=>{if(!(!a||!ze())){if(!ae){D.error(t("settings.mcp.page.toast.enableServerBeforeTest"));return}oe(!0);try{const le=await E(a,d),dt=le.status?.status;le.warning?D.warning(le.warning):dt==="connected"?D.success(t("settings.mcp.page.toast.connectionTestSucceeded")):dt==="needs_auth"?D.message(t("settings.mcp.page.toast.connectionNeedsAuthorization")):dt==="needs_client_registration"?D.message(t("settings.mcp.page.toast.connectionNeedsClientRegistration")):dt==="failed"?D.error(le.status?.error||le.error||t("settings.mcp.page.toast.connectionTestFailed")):le.error?D.error(le.error):D.message(t("settings.mcp.page.toast.connectionTestFinished"))}catch(le){D.error(le instanceof Error?le.message:t("settings.mcp.page.toast.connectionTestFailed"))}finally{oe(!1)}}},[d,ae,ze,a,t,E]);if(o.useEffect(()=>{if(!Ie||!a)return;const le=window.setInterval(()=>{(async()=>{Ye.current+=1,await b({directory:d,silent:!0});const dt=Os.getState().getStatusForDirectory(d)[a];if(dt){if(q.current&&dt.status!=="needs_auth"&&dt.status!=="needs_client_registration"){Le(!1),Ye.current=0,q.current=!1,Oe(null),ue(""),dt.status==="connected"&&D.success(t("settings.mcp.page.toast.authorizationCompleted"));return}if(!q.current&&dt.status==="failed"){Le(!1),Ye.current=0,q.current=!1,D.error(dt.error||t("settings.mcp.page.toast.authorizationFailed"));return}Ye.current>=30&&(Le(!1),Ye.current=0,q.current=!1,D.message(t("settings.mcp.page.toast.authorizationStillInProgress")))}})()},2e3);return()=>{window.clearInterval(le)}},[d,Ie,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 ts=c[a],Ms=a?N[a]:void 0,Bt=ts??Ms,os=!m&&!Bt&&F.some(le=>le.scope==="mcp"&&le.id.startsWith(`mcp:${a}:`)),qt=ts?.status==="connected",bs=ts?.status==="needs_auth"||ts?.status==="needs_client_registration",ms=v||!a?null:pc(a),vs=async()=>{if(ms)try{await navigator.clipboard.writeText(ms),D.success(t("settings.mcp.page.toast.copiedCallbackUrl"))}catch{D.error(t("settings.mcp.page.toast.clipboardWriteFailed"))}},us=Bp(Bt?.status,e,Bt&&"error"in Bt?Bt.error:void 0),ys=le=>{switch(le){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 le}};return s.jsxs(s.Fragment,{children:[s.jsxs(ns,{title:m?t("settings.mcp.page.header.newServer"):a,titleAccessory:m?void 0:s.jsx(Oi,{status:os?"awaiting_restart":Bt?.status,enabled:ae,getStatusLabel:ys,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&&!os?s.jsxs("div",{className:"flex flex-wrap items-center gap-2",children:[s.jsx(B,{variant:qt?"outline":"default",size:"xs",className:"!font-normal",onClick:he,disabled:re||!ae,children:t(re?"settings.mcp.page.actions.working":qt?"settings.mcp.page.actions.disconnect":"settings.mcp.page.actions.connect")}),j==="remote"&&s.jsxs(s.Fragment,{children:[s.jsx(B,{variant:bs?"default":"outline",size:"xs",className:"!font-normal",onClick:()=>{it()},disabled:Ee||!ae,children:t(Ee?"settings.mcp.page.actions.starting":qt?"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:Ve||!ae,children:t(Ve?"settings.mcp.page.actions.clearing":"settings.mcp.page.actions.clearAuth")})]}),qt&&s.jsx(B,{variant:"ghost",size:"xs",className:"!font-normal gap-1 text-muted-foreground",onClick:()=>{xs()},disabled:Ke||!ae,children:t(Ke?"settings.mcp.page.actions.testing":"settings.mcp.page.actions.test")})]}):void 0,showSaveStatus:!1,children:[os&&s.jsx($e,{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:It,children:t("settings.mcp.page.status.runtimeStatus")}),s.jsx(Oi,{status:"awaiting_restart",enabled:ae,getStatusLabel:ys})]}),s.jsx("p",{className:"typography-meta text-muted-foreground",children:t("settings.mcp.page.status.description.awaitingRestart")})]})})}),!m&&!os&&Gp(Bt?.status,ve,bs,Ie)&&s.jsx($e,{divider:!1,children:s.jsxs("div",{className:we("rounded-lg border p-3",Hp(Bt?.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:It,children:t("settings.mcp.page.status.runtimeStatus")}),s.jsx(Oi,{status:Bt?.status,enabled:ae,getStatusLabel:ys})]}),s.jsx("p",{className:"typography-meta text-muted-foreground",children:us}),s.jsx("p",{className:"typography-micro text-muted-foreground/80",children:S==="project"?t("settings.mcp.page.status.projectScopedTo",{directory:d??t("settings.mcp.page.status.activeProject")}):t("settings.mcp.page.status.userScoped")})]}),s.jsx("div",{className:"flex flex-wrap items-center gap-2",children:!qt&&s.jsx(B,{variant:"outline",size:"xs",className:"!font-normal",onClick:()=>{xs()},disabled:Ke||!ae,children:t(Ke?"settings.mcp.page.actions.testing":"settings.mcp.page.actions.testConnection")})}),Bt?.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(Xs,{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")})]}),ms&&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:ms}),s.jsxs(B,{variant:"outline",size:"xs",className:"!font-normal",onClick:()=>{vs()},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(Wt,{label:t("settings.mcp.page.registration.clientId"),children:s.jsx(We,{value:V,onChange:le=>{_(le.target.value),$(!0)},className:"font-mono typography-meta","data-bwignore":"true","data-1p-ignore":"true"})}),s.jsx(Wt,{label:t("settings.mcp.page.registration.clientSecret"),children:s.jsx(We,{type:"password",value:z,onChange:le=>{Z(le.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")})]}),ve&&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:ve}),s.jsxs("div",{className:"flex flex-wrap items-center gap-2",children:[s.jsxs(B,{variant:"outline",size:"xs",className:"!font-normal",onClick:()=>{In(ve)},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"&&(bs||Ie||ve)&&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(Xs,{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(Is,{value:He,onChange:le=>ue(le.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:()=>{Nt()},disabled:ie,children:t(ie?"settings.mcp.page.actions.completing":"settings.mcp.page.actions.completeAuthorization")})})]})})]}),Ie&&s.jsx("p",{className:"mt-4 typography-micro text-muted-foreground",children:t("settings.mcp.page.auth.waitingForOpenCode")})]})}),s.jsxs($e,{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:Ct,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(Vt,{label:t("settings.mcp.page.server.name"),controlClassName:"flex-wrap @xl:w-auto @xl:flex-1",children:[s.jsx(We,{value:y,onChange:le=>U(le.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(At,{value:S,onValueChange:le=>M(le),children:[s.jsxs(Et,{size:$t,className:"!h-7 min-w-0 max-w-full gap-1.5 px-2",children:[s.jsx(L,{name:S==="user"?"user-3":"folder",className:"h-3.5 w-3.5 shrink-0"}),s.jsx("span",{className:"truncate",children:t(S==="user"?"settings.mcp.page.scope.everywhere":"settings.mcp.page.scope.thisProject")})]}),s.jsxs(Tt,{align:"end",children:[s.jsx(ot,{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(ot,{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(pt,{checked:ae,onChange:me,label:t("settings.mcp.page.server.enable"),ariaLabel:t("settings.mcp.page.server.enableAria")})]}),s.jsxs($e,{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:Ue,activeId:j,onSelect:le=>R(le),layoutMode:"fit",variant:"active-pill",activePillLowercase:!1,className:"h-10"}),j==="local"?s.jsx($p,{value:H,onChange:P,preview:le=>t("settings.mcp.page.connection.previewArgs",{count:le}),onDetectUrl:jt}):s.jsx(We,{value:G,onChange:le=>Ae(le.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($e,{title:t("settings.mcp.page.advanced.title"),settingsItem:"mcp.advanced",children:s.jsxs(Hn,{open:ke,onOpenChange:O,children:[s.jsxs(Gn,{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:["(",X.length," ",t("settings.mcp.page.advanced.headers"),be?` · ${be}ms`:"",")"]})]}),ke?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(qn,{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:It,children:t("settings.mcp.page.advanced.timeoutMs")}),s.jsx(Jt,{children:t("settings.mcp.page.advanced.timeoutHint")})]}),s.jsx("div",{className:"flex items-center gap-2",children:s.jsx(We,{type:"number",min:"1",step:"1",value:be,onChange:le=>ne(le.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(Xs,{as:"div",className:"mb-2",children:[t("settings.mcp.page.advanced.requestHeaders"),X.length>0&&s.jsxs("span",{className:"ml-1.5 typography-micro text-muted-foreground font-normal",children:["(",X.length,")"]})]}),s.jsx(io,{value:X,onChange:K,keyTransform:le=>le.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:le=>t("settings.mcp.page.toast.importedVariablesCount",{count:le}),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($e,{title:t("settings.mcp.page.env.title"),description:t("settings.mcp.page.env.description"),titleAccessory:T.length>0?s.jsxs("span",{className:"typography-micro text-muted-foreground font-normal",children:["(",T.length,")"]}):null,settingsItem:"mcp.environment",children:T.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:T,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:le=>t("settings.mcp.page.toast.importedVariablesCount",{count:le}),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:yt,disabled:Pe||!ct&&!m,size:"xs",className:"!font-normal",children:t(Pe?"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:()=>je(!0),children:t("settings.common.actions.delete")})]})," "]}),s.jsx(Rt,{open:Ce,onOpenChange:le=>{le||(qe(!1),tt(""),mt(null))},children:s.jsxs(Ot,{className:"max-w-md",children:[s.jsxs(Kt,{children:[s.jsx(Ut,{children:t("settings.mcp.page.importDialog.title")}),s.jsx(zt,{children:t("settings.mcp.page.importDialog.description")})]}),s.jsxs("div",{className:"space-y-3",children:[s.jsx(Is,{value:_e,onChange:le=>{tt(le.target.value),mt(null)},placeholder:`{
|
|
15
|
+
"mcpServers": {
|
|
16
|
+
"postgres": {
|
|
17
|
+
"command": "npx",
|
|
18
|
+
"args": ["-y", "@modelcontextprotocol/server-postgres"]
|
|
19
|
+
}
|
|
20
|
+
}
|
|
21
|
+
}`,rows:8,className:"font-mono typography-meta",spellCheck:!1,"data-bwignore":"true","data-1p-ignore":"true"}),ht&&s.jsx("p",{className:"typography-micro text-[var(--status-error)]",children:ht}),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:Ze,type:"button",children:[s.jsx(L,{name:"clipboard",className:"h-3.5 w-3.5"}),t("settings.mcp.page.importDialog.pasteFromClipboard")]})})]}),s.jsxs(es,{children:[s.jsx(B,{variant:"outline",onClick:()=>{qe(!1),tt(""),mt(null)},className:"text-foreground",children:t("settings.common.actions.cancel")}),s.jsx(B,{onClick:Xe,disabled:!_e.trim(),size:"sm",children:t("settings.common.actions.import")})]})]})}),s.jsx(Rt,{open:Se,onOpenChange:le=>{!le&&!Me&&je(!1)},children:s.jsxs(Ot,{className:"max-w-md",children:[s.jsxs(Kt,{children:[s.jsx(Ut,{children:t("settings.mcp.page.deleteDialog.title",{name:a??""})}),s.jsxs(zt,{children:[t("settings.mcp.page.deleteDialog.descriptionPrefix")," ",s.jsx("code",{className:"text-foreground",children:"opencode.json"}),"."," ",t("settings.mcp.page.deleteDialog.descriptionSuffix")]})]}),s.jsxs(es,{children:[s.jsx(B,{variant:"outline",onClick:()=>je(!1),disabled:Me,className:"text-foreground",children:t("settings.common.actions.cancel")}),s.jsx(B,{variant:"destructive",size:"sm",onClick:Q,disabled:Me,children:t(Me?"settings.mcp.page.actions.deleting":"settings.common.actions.delete")})]})]})})]})};function Qp(t){return t.trim().length>0}function Yp(t){return t.trimEnd()}function Xp(t,e){return s.jsxs("span",{className:"block",children:[s.jsxs("span",{className:"text-muted-foreground select-none mr-2",children:["[",e,"]"]}),t]},e)}const ni=()=>{try{const e=qs.getState().getActiveProject?.();if(e?.path?.trim())return e.path.trim();const a=un.getDirectory();if(a?.trim())return a.trim()}catch(t){console.warn("[PluginsStore] Error resolving config directory:",t)}return null},Zp=800,em=5e3,tm="__default__",tr=new Map,Li=new Map,sm=1500,Ml=t=>t?.trim()||tm,nm=t=>{tr.delete(Ml(t))},rs=Cl()(Od(Ld((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=ni(),i=Ml(n),r=Date.now(),l=tr.get(i)??0,u=e().entries.length>0||e().files.length>0;if(!a?.force&&u&&r-l<em)return!0;const g=Li.get(i);if(!a?.force&&g)return g;const x=(async()=>{t({isLoading:!0});try{const d=await rt(jn("/api/config/plugins",n),{headers:Sa(n)});if(!d.ok)throw new Error("Failed to load plugins");const v=await ai(d);return t({entries:v.entries??[],files:v.files??[],isLoading:!1}),tr.set(i,Date.now()),a?.force||e().loadRegistryInfo(),!0}catch(d){return console.error("[PluginsStore] Failed to load plugins:",d),t({isLoading:!1}),!1}})();Li.set(i,x);try{return await x}finally{Li.delete(i)}},loadRegistryInfo:async a=>{const n=im(a?.specs??e().entries.map(i=>i.spec));if(n.length===0)return t({isLoadingRegistry:!1}),!0;t({isLoadingRegistry:!0});try{const i=ni(),r={...e().registryInfo};for(const l of rm(n)){const u=await rt(am(l,a?.force===!0,i),{headers:Sa(i)});if(!u.ok)throw new Error("Failed to load plugin registry info");const g=await ai(u);for(const x of g.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 rt(jn("/api/config/plugins/entry",i),{method:"POST",headers:Ya(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(u=>u.id===a)?.spec,r=n.spec??i,l=await na("Updating plugin entry…",async u=>await rt(jn(`/api/config/plugins/entry/${encodeURIComponent(a)}`,u),{method:"PATCH",headers:Ya(u),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 rt(jn(`/api/config/plugins/entry/${encodeURIComponent(a)}`,r),{method:"DELETE",headers:Sa(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=ni(),i=await rt(jn(`/api/config/plugins/file/${encodeURIComponent(a)}`,n),{headers:Sa(n)});if(!i.ok)throw new Error("Failed to read plugin file");return await ai(i)}catch(n){return console.error("[PluginsStore] Failed to read plugin file:",n),null}},createFile:async a=>na("Creating plugin file…",async n=>await rt(jn("/api/config/plugins/file",n),{method:"POST",headers:Ya(n),body:JSON.stringify(a)}),e,{restartId:a.fileName}),updateFile:async(a,n)=>na("Updating plugin file…",async i=>await rt(jn(`/api/config/plugins/file/${encodeURIComponent(a)}`,i),{method:"PUT",headers:Ya(i),body:JSON.stringify(n)}),e,{restartId:a}),deleteFile:async a=>{const n=await na("Deleting plugin file…",async i=>await rt(jn(`/api/config/plugins/file/${encodeURIComponent(a)}`,i),{method:"DELETE",headers:Sa(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:ad(),partialize:t=>({selectedId:t.selectedId})}),{name:"plugins-store"}));function jn(t,e){const a=e?`?directory=${encodeURIComponent(e)}`:"";return`${t}${a}`}function am(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 im(t){return Array.from(new Set(t.map(e=>e.trim()).filter(Boolean)))}function rm(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>sm?(e.push(a),a=[i],n=r.length):(a.push(i),n=l)}return a.length>0&&e.push(a),e}function Sa(t){return t?{"x-opencode-directory":t}:void 0}function Ya(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=ni(),r=await e(i),l=await ai(r).catch(()=>null);if(!r.ok)throw new Error(l?.error||"Failed to update plugin configuration");return nm(i),l?.requiresManualRestart?(await a().loadPlugins({force:!0}),{ok:!0,requiresManualRestart:!0,reloadFailed:l?.reloadFailed===!0,message:l?.message,warning:l?.warning}):rl(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&&(uc(t),await gc({message:l.message,delayMs:l.reloadDelayMs??Zp,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 ai(t){return await t.json()}const om=/^[a-z0-9][a-z0-9-_.]*\.(js|ts|mjs|cjs)$/;function lm(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 cm=({open:t,onOpenChange:e,defaultScope:a="user"})=>{const{t:n}=nt(),i=rs(P=>P.createEntry),r=rs(P=>P.createFile),[l,u]=o.useState("npm"),[g,x]=o.useState(""),[d,v]=o.useState(""),[c,N]=o.useState(""),[b,C]=o.useState(""),[k,A]=o.useState(a),[h,E]=o.useState(!1),F=o.useCallback(()=>{x(""),v(""),N(""),C(""),A(a)},[a]);o.useEffect(()=>{t&&(u("npm"),F())},[t,F]);const I=P=>{P!==l&&(u(P),F())},w=o.useMemo(()=>lm(d),[d]),m=!w.ok,y=l==="file"&&c.trim()!==""&&!om.test(c.trim()),U=(l==="npm"||l==="path")&&g.trim()==="",S=l==="file"&&b.trim()==="",M=l==="file"&&c.trim()==="",j=h||m||l==="npm"&&U||l==="path"&&U||l==="file"&&(M||y||S),R=async()=>{if(!j){E(!0);try{let P;l==="file"?P=await r({fileName:c.trim(),content:b,scope:k}):P=await i({spec:g.trim(),options:w.ok?w.value:void 0,scope:k}),P.ok?(P.restartDeferred?D.success(n("settings.view.pendingRestart.saved")):D.success(P.message||n("settings.plugins.toast.created")),P.reloadFailed&&D.warning(n("settings.plugins.toast.reloadFailed")),e(!1)):D.error(P.message||n("settings.plugins.sidebar.toast.deleteFailed"))}finally{E(!1)}}},H=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(Rt,{open:t,onOpenChange:P=>{!P&&h||e(P)},children:s.jsxs(Ot,{className:"max-w-xl",children:[s.jsxs(Kt,{children:[s.jsx(Ut,{children:n("settings.plugins.dialog.add.title")}),s.jsx(zt,{children:n("settings.plugins.sidebar.empty.description")})]}),s.jsx(hr,{items:H,activeId:l,onSelect:P=>I(P),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(We,{id:"plugin-spec",value:g,onChange:P=>x(P.target.value),placeholder:n("settings.plugins.page.field.spec.placeholder"),"aria-invalid":U?!1:void 0,disabled:h}),U&&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(Is,{id:"plugin-options",value:d,onChange:P=>v(P.target.value),rows:5,className:"font-mono",hasError:m,disabled:h}),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(We,{id:"plugin-filename",value:c,onChange:P=>N(P.target.value),placeholder:"my-plugin.ts","aria-invalid":y||void 0,disabled:h}),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(Is,{id:"plugin-content",value:b,onChange:P=>C(P.target.value),rows:16,className:"font-mono",disabled:h})]})]}),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(P=>{const G=k===P,J=n(P==="user"?"settings.plugins.scope.user":"settings.plugins.scope.project");return s.jsxs("button",{type:"button",onClick:()=>A(P),disabled:h,className:"flex items-center gap-2 py-1 text-left disabled:opacity-50",children:[s.jsx(dr,{checked:G,onChange:()=>A(P),ariaLabel:J}),s.jsx("span",{className:we("typography-ui-label font-normal",G?"text-foreground":"text-foreground/60"),children:J})]},P)})})]})]}),s.jsxs(es,{children:[s.jsx(B,{size:"sm",variant:"ghost",onClick:()=>e(!1),disabled:h,children:n("settings.plugins.dialog.add.action.cancel")}),s.jsxs(B,{size:"sm",onClick:()=>{R()},disabled:j,children:[h?s.jsx(L,{name:"loader-4",className:"h-3.5 w-3.5 animate-spin"}):null,n("settings.plugins.dialog.add.action.submit")]})]})]})})},dm=t=>{const e=lt.c(33),{spec:a}=t;let n;e[0]!==a?(n=u=>u.registryInfo[a],e[0]=a,e[1]=n):n=e[1];const i=rs(n),{t:r}=nt();if(!i)return null;const l=pm;switch(i.kind){case"npm-ok":{if(!i.hasUpdate||!i.latestVersion)return null;let u;e[2]===Symbol.for("react.memo_cache_sentinel")?(u=s.jsx(L,{name:"arrow-up-s",className:"h-3 w-3"}),e[2]=u):u=e[2];let g;e[3]!==i.latestVersion?(g=s.jsxs("span",{className:"inline-flex items-center gap-0.5 text-[var(--status-success)]",children:[u,i.latestVersion]}),e[3]=i.latestVersion,e[4]=g):g=e[4];let x;return e[5]!==i.currentVersion||e[6]!==i.latestVersion||e[7]!==r||e[8]!==g?(x=l(g,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]=g,e[9]=x):x=e[9],x}case"npm-missing-version":{let u;e[10]===Symbol.for("react.memo_cache_sentinel")?(u=s.jsx(L,{name:"error-warning",className:"h-3 w-3 text-[var(--status-warning)]"}),e[10]=u):u=e[10];let g;return e[11]!==i.currentVersion||e[12]!==i.name||e[13]!==r?(g=l(u,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]=g):g=e[14],g}case"npm-missing-package":{let u;e[15]===Symbol.for("react.memo_cache_sentinel")?(u=s.jsx(L,{name:"error-warning",className:"h-3 w-3 text-[var(--status-error)]"}),e[15]=u):u=e[15];let g;return e[16]!==i.name||e[17]!==r?(g=l(u,r("settings.plugins.registry.badge.missingPackage.tooltip",{name:i.name})),e[16]=i.name,e[17]=r,e[18]=g):g=e[18],g}case"npm-malformed":{let u;e[19]===Symbol.for("react.memo_cache_sentinel")?(u=s.jsx(L,{name:"error-warning",className:"h-3 w-3 text-[var(--status-error)]"}),e[19]=u):u=e[19];let g;return e[20]!==r?(g=l(u,r("settings.plugins.registry.badge.malformed.tooltip")),e[20]=r,e[21]=g):g=e[21],g}case"npm-network":{let u;e[22]===Symbol.for("react.memo_cache_sentinel")?(u=s.jsx(L,{name:"cloud-off",className:"h-3 w-3 text-muted-foreground"}),e[22]=u):u=e[22];let g;return e[23]!==r?(g=l(u,r("settings.plugins.registry.badge.network.tooltip")),e[23]=r,e[24]=g):g=e[24],g}case"path-missing":{let u;e[25]===Symbol.for("react.memo_cache_sentinel")?(u=s.jsx(L,{name:"error-warning",className:"h-3 w-3 text-[var(--status-error)]"}),e[25]=u):u=e[25];let g;return e[26]!==i.absolutePath||e[27]!==r?(g=l(u,r("settings.plugins.registry.badge.pathMissing.tooltip",{path:i.absolutePath})),e[26]=i.absolutePath,e[27]=r,e[28]=g):g=e[28],g}case"path-unreadable":{let u;e[29]===Symbol.for("react.memo_cache_sentinel")?(u=s.jsx(L,{name:"error-warning",className:"h-3 w-3 text-[var(--status-warning)]"}),e[29]=u):u=e[29];let g;return e[30]!==i.absolutePath||e[31]!==r?(g=l(u,r("settings.plugins.registry.badge.pathUnreadable.tooltip",{path:i.absolutePath})),e[30]=i.absolutePath,e[31]=r,e[32]=g):g=e[32],g}case"path-ok":return null;default:return null}};function pm(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(pl,{children:e})]})}const Rl=t=>{const e=lt.c(26),{header:a,footer:n,children:i,className:r,variant:l}=t,u=l===void 0?"sidebar":l,g=ps(),x=o.useRef(null),[d,v]=o.useState(!1),[c,N]=o.useState(!1),b=u==="background"||g?"bg-background":"bg-sidebar",C=b==="bg-background"?"var(--surface-background)":"var(--surface-muted)";let k;e[0]===Symbol.for("react.memo_cache_sentinel")?(k=()=>{const j=x.current;if(!j){v(!1),N(!1);return}if(!(j.scrollHeight>j.clientHeight+1)){v(!1),N(!1);return}v(j.scrollTop>1),N(j.scrollTop+j.clientHeight<j.scrollHeight-1)},e[0]=k):k=e[0];const A=k;let h;e[1]===Symbol.for("react.memo_cache_sentinel")?(h=()=>{A()},e[1]=h):h=e[1];let E;e[2]!==i?(E=[i,A],e[2]=i,e[3]=E):E=e[3],o.useEffect(h,E);let F,I;e[4]===Symbol.for("react.memo_cache_sentinel")?(F=()=>{const j=x.current;if(!j)return;const R=()=>A();return j.addEventListener("scroll",R,{passive:!0}),()=>j.removeEventListener("scroll",R)},I=[A],e[4]=F,e[5]=I):(F=e[4],I=e[5]),o.useEffect(F,I);let w;e[6]!==b||e[7]!==r?(w=we("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]!==C||e[12]!==d?(y=d&&s.jsx("div",{className:"pointer-events-none absolute inset-x-0 top-0 h-4",style:{background:`linear-gradient(to bottom, ${C} 0%, transparent 100%)`}}),e[11]=C,e[12]=d,e[13]=y):y=e[13];let U;e[14]!==C||e[15]!==c?(U=c&&s.jsx("div",{className:"pointer-events-none absolute inset-x-0 bottom-0 h-6",style:{background:`linear-gradient(to top, ${C} 0%, transparent 100%)`}}),e[14]=C,e[15]=c,e[16]=U):U=e[16];let S;e[17]!==U||e[18]!==m||e[19]!==y?(S=s.jsxs("div",{className:"relative flex flex-1 min-h-0 flex-col",children:[m,y,U]}),e[17]=U,e[18]=m,e[19]=y,e[20]=S):S=e[20];let M;return e[21]!==n||e[22]!==a||e[23]!==S||e[24]!==w?(M=s.jsxs("div",{className:w,children:[a,S,n]}),e[21]=n,e[22]=a,e[23]=S,e[24]=w,e[25]=M):M=e[25],M},sr=t=>{const e=lt.c(23),{title:a,metadata:n,selected:i,onSelect:r,icon:l,actions:u,className:g}=t,x=i===void 0?!1:i,d=u&&u.length>0,v=x?"bg-interactive-selection":"hover:bg-interactive-hover";let c;e[0]!==g||e[1]!==v?(c=we("group relative flex items-center rounded-md px-1.5 py-0.5 transition-all duration-200",v,g),e[0]=g,e[1]=v,e[2]=c):c=e[2];let N;e[3]!==a?(N=s.jsx("span",{className:"typography-ui-label font-normal truncate text-foreground",children:a}),e[3]=a,e[4]=N):N=e[4];let b;e[5]!==l||e[6]!==N?(b=s.jsxs("div",{className:"flex items-center gap-1.5",children:[l,N]}),e[5]=l,e[6]=N,e[7]=b):b=e[7];let C;e[8]!==n?(C=n&&s.jsx("div",{className:"typography-micro text-muted-foreground/60 truncate leading-tight",children:n}),e[8]=n,e[9]=C):C=e[9];let k;e[10]!==r||e[11]!==b||e[12]!==C?(k=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,C]}),e[10]=r,e[11]=b,e[12]=C,e[13]=k):k=e[13];let A;e[14]!==u||e[15]!==d?(A=d&&s.jsxs(tn,{children:[s.jsx(Zs,{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(en,{align:"end",className:"w-fit min-w-20",children:u.map(mm)})]}),e[14]=u,e[15]=d,e[16]=A):A=e[16];let h;e[17]!==k||e[18]!==A?(h=s.jsxs("div",{className:"flex min-w-0 flex-1 items-center",children:[k,A]}),e[17]=k,e[18]=A,e[19]=h):h=e[19];let E;return e[20]!==c||e[21]!==h?(E=s.jsx("div",{className:c,children:h}),e[20]=c,e[21]=h,e[22]=E):E=e[22],E};function mm(t){const e=t.icon;return s.jsxs(sn,{onClick:a=>{a.stopPropagation(),t.onClick()},className:we(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 um=t=>t.parsedKind==="npm"?"code-box":"folder",gm=t=>{const e=lt.c(144),{onItemSelect:a,onAddClick:n}=t,{t:i}=nt(),{entries:r,files:l,selectedId:u,setSelected:g,deleteEntry:x,deleteFile:d,loadPlugins:v}=rs(Ds(hm)),c=rs(fm),N=rs(xm),b=rs(bm),C=rs(vm),[k,A]=o.useState(null),[h,E]=o.useState(!1),[F,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,U;e[3]===Symbol.for("react.memo_cache_sentinel")?(y=()=>{const Ze=()=>I(!0);return window.addEventListener("openchamber:settings-open-plugin-add",Ze),()=>window.removeEventListener("openchamber:settings-open-plugin-add",Ze)},U=[],e[3]=y,e[4]=U):(y=e[3],U=e[4]),o.useEffect(y,U);let S;if(e[5]!==r||e[6]!==c){S={userEntries:0,projectEntries:0};for(const Ze of r){const Xe=c[Ze.spec];Xe?.kind==="npm-ok"&&Xe.hasUpdate&&(Ze.scope==="user"?S.userEntries=S.userEntries+1:Ze.scope==="project"&&(S.projectEntries=S.projectEntries+1))}e[5]=r,e[6]=c,e[7]=S}else S=e[7];const M=S;let j;e[8]!==r?(j=r.filter(ym),e[8]=r,e[9]=j):j=e[9];const R=j;let H;e[10]!==r?(H=r.filter(jm),e[10]=r,e[11]=H):H=e[11];const P=H;let G;e[12]!==l?(G=l.filter(wm),e[12]=l,e[13]=G):G=e[13];const J=G;let T;e[14]!==l?(T=l.filter(km),e[14]=l,e[15]=T):T=e[15];const W=T,X=r.length+l.length,K=X===0;let te;e[16]!==n?(te=()=>{n?n():I(!0)},e[16]=n,e[17]=te):te=e[17];const $=te;let V;e[18]!==a||e[19]!==g?(V=Ze=>{g(Ze),a?.()},e[18]=a,e[19]=g,e[20]=V):V=e[20];const _=V;let z;e[21]!==r||e[22]!==c||e[23]!==i||e[24]!==C?(z=async Ze=>{const Xe=r.find(Ae=>Ae.id===Ze);if(!Xe)return;const ct=c[Xe.spec];if(!ct||ct.kind!=="npm-ok"||!ct.hasUpdate||!ct.latestVersion)return;const Ue=ct.latestVersion;(await C(Ze)).ok?D.success(i("settings.plugins.toast.updatedToLatest",{version:Ue})):D.error(i("settings.plugins.toast.refreshFailed"))},e[21]=r,e[22]=c,e[23]=i,e[24]=C,e[25]=z):z=e[25];const Z=z;let Y;e[26]!==b||e[27]!==i?(Y=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]=Y):Y=e[28];const se=Y;let ge;e[29]!==x||e[30]!==d||e[31]!==k||e[32]!==i?(ge=async()=>{if(!k)return;E(!0);const Ze=k.kind==="entry"?await x(k.id):await d(k.id);Ze.ok?D.success(Ze.message||i("settings.plugins.sidebar.toast.deleted",{name:k.label})):D.error(i("settings.plugins.sidebar.toast.deleteFailed")),A(null),E(!1)},e[29]=x,e[30]=d,e[31]=k,e[32]=i,e[33]=ge):ge=e[33];const ce=ge;let be;e[34]!==_||e[35]!==Z||e[36]!==c||e[37]!==u||e[38]!==i?(be=Ze=>{const Xe=c[Ze.spec],ct=Xe?.kind==="npm-ok"&&Xe.hasUpdate&&!!Xe.latestVersion,Ue=[];return ct&&Ue.push({label:i("settings.plugins.sidebar.actions.updateToLatest"),icon:"arrow-up-s",onClick:()=>{Z(Ze.id)}}),Ue.push({label:i("settings.common.actions.delete"),icon:"delete-bin",destructive:!0,onClick:()=>A({kind:"entry",id:Ze.id,label:Ze.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:Ze.spec}),s.jsx(dm,{spec:Ze.spec})]}),metadata:Ze.parsedKind==="npm"?i("settings.plugins.sidebar.kind.npm"):i("settings.plugins.sidebar.kind.path"),selected:u===Ze.id,onSelect:()=>_(Ze.id),icon:s.jsx(L,{name:um(Ze),className:"h-4 w-4 flex-shrink-0 text-muted-foreground/70"}),actions:Ue},Ze.id)},e[34]=_,e[35]=Z,e[36]=c,e[37]=u,e[38]=i,e[39]=be):be=e[39];const ne=be;let ae;e[40]!==_||e[41]!==u||e[42]!==i?(ae=Ze=>s.jsx(sr,{title:Ze.fileName,metadata:i("settings.plugins.sidebar.kind.file"),selected:u===Ze.id,onSelect:()=>_(Ze.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:()=>A({kind:"file",id:Ze.id,label:Ze.fileName})}]},Ze.id),e[40]=_,e[41]=u,e[42]=i,e[43]=ae):ae=e[43];const me=ae;let Pe;e[44]!==i?(Pe=(Ze,Xe,ct)=>{const Ue=ct===void 0?0:ct;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:[Ze,Ue>0&&s.jsx("span",{className:"ml-2 normal-case font-normal text-[var(--status-success)]",children:i(Ue===1?"settings.plugins.sidebar.group.updatesAvailable_one":"settings.plugins.sidebar.group.updatesAvailable_other",{count:Ue})})]}),Xe]})},e[44]=i,e[45]=Pe):Pe=e[45];const Ne=Pe;let Se;e[46]!==i?(Se=i("settings.plugins.sidebar.title"),e[46]=i,e[47]=Se):Se=e[47];let je;e[48]!==Se?(je=s.jsx("div",{className:"mb-3 flex items-center justify-between gap-3",children:s.jsx("h2",{className:nn,children:Se})}),e[48]=Se,e[49]=je):je=e[49];let Me;e[50]!==i||e[51]!==X?(Me=i("settings.plugins.sidebar.total",{count:X}),e[50]=i,e[51]=X,e[52]=Me):Me=e[52];let Re;e[53]!==Me?(Re=s.jsx("span",{className:"typography-meta text-muted-foreground",children:Me}),e[53]=Me,e[54]=Re):Re=e[54];let re;e[55]!==se?(re=()=>{se()},e[55]=se,e[56]=re):re=e[56];let fe;e[57]!==i?(fe=i("settings.plugins.sidebar.actions.refresh"),e[57]=i,e[58]=fe):fe=e[58];let Ee;e[59]!==i?(Ee=i("settings.plugins.sidebar.actions.refresh"),e[59]=i,e[60]=Ee):Ee=e[60];const Be=N?"size-4 animate-spin":"size-4";let Ve;e[61]!==Be?(Ve=s.jsx(L,{name:"refresh",className:Be}),e[61]=Be,e[62]=Ve):Ve=e[62];let Ge;e[63]!==N||e[64]!==re||e[65]!==fe||e[66]!==Ee||e[67]!==Ve?(Ge=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:re,disabled:N,"aria-label":fe,title:Ee,children:Ve}),e[63]=N,e[64]=re,e[65]=fe,e[66]=Ee,e[67]=Ve,e[68]=Ge):Ge=e[68];let Ke;e[69]!==i?(Ke=i("settings.plugins.sidebar.actions.addTitle"),e[69]=i,e[70]=Ke):Ke=e[70];let oe;e[71]!==i?(oe=i("settings.plugins.sidebar.actions.addTitle"),e[71]=i,e[72]=oe):oe=e[72];let ie;e[73]===Symbol.for("react.memo_cache_sentinel")?(ie=s.jsx(L,{name:"add",className:"size-4"}),e[73]=ie):ie=e[73];let ye;e[74]!==$||e[75]!==Ke||e[76]!==oe?(ye=s.jsx(B,{type:"button",variant:"ghost",size:"icon",className:"h-7 w-7 -my-1 text-muted-foreground",onClick:$,"aria-label":Ke,title:oe,children:ie}),e[74]=$,e[75]=Ke,e[76]=oe,e[77]=ye):ye=e[77];let ve;e[78]!==Ge||e[79]!==ye?(ve=s.jsxs("div",{className:"flex items-center gap-1",children:[Ge,ye]}),e[78]=Ge,e[79]=ye,e[80]=ve):ve=e[80];let Oe;e[81]!==Re||e[82]!==ve?(Oe=s.jsxs("div",{className:"flex items-center justify-between gap-2",children:[Re,ve]}),e[81]=Re,e[82]=ve,e[83]=Oe):Oe=e[83];let Te;e[84]!==je||e[85]!==Oe?(Te=s.jsxs("div",{className:"border-b px-3 pt-4 pb-3",children:[je,Oe]}),e[84]=je,e[85]=Oe,e[86]=Te):Te=e[86];let xe;e[87]!==K||e[88]!==P||e[89]!==W||e[90]!==ne||e[91]!==me||e[92]!==Ne||e[93]!==i||e[94]!==M||e[95]!==R||e[96]!==J?(xe=K?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&&Ne(i("settings.plugins.sidebar.group.userEntries"),R.map(ne),M.userEntries),J.length>0&&Ne(i("settings.plugins.sidebar.group.userFiles"),J.map(me)),P.length>0&&Ne(i("settings.plugins.sidebar.group.projectEntries"),P.map(ne),M.projectEntries),W.length>0&&Ne(i("settings.plugins.sidebar.group.projectFiles"),W.map(me))]}),e[87]=K,e[88]=P,e[89]=W,e[90]=ne,e[91]=me,e[92]=Ne,e[93]=i,e[94]=M,e[95]=R,e[96]=J,e[97]=xe):xe=e[97];let He;e[98]!==Te||e[99]!==xe?(He=s.jsx(Rl,{variant:"background",header:Te,children:xe}),e[98]=Te,e[99]=xe,e[100]=He):He=e[100];let ue;e[101]!==F?(ue=s.jsx(cm,{open:F,onOpenChange:I}),e[101]=F,e[102]=ue):ue=e[102];const Ie=k!==null;let Le;e[103]!==h?(Le=Ze=>{!Ze&&!h&&A(null)},e[103]=h,e[104]=Le):Le=e[104];let Ye;e[105]!==i?(Ye=i("settings.plugins.sidebar.deleteDialog.title"),e[105]=i,e[106]=Ye):Ye=e[106];let q;e[107]!==Ye?(q=s.jsx(Ut,{children:Ye}),e[107]=Ye,e[108]=q):q=e[108];const ke=k?.label??"";let O;e[109]!==i||e[110]!==ke?(O=i("settings.plugins.sidebar.deleteDialog.description",{name:ke}),e[109]=i,e[110]=ke,e[111]=O):O=e[111];let Ce;e[112]!==O?(Ce=s.jsx(zt,{children:O}),e[112]=O,e[113]=Ce):Ce=e[113];let qe;e[114]!==q||e[115]!==Ce?(qe=s.jsxs(Kt,{children:[q,Ce]}),e[114]=q,e[115]=Ce,e[116]=qe):qe=e[116];let _e;e[117]===Symbol.for("react.memo_cache_sentinel")?(_e=()=>A(null),e[117]=_e):_e=e[117];let tt;e[118]!==i?(tt=i("settings.common.actions.cancel"),e[118]=i,e[119]=tt):tt=e[119];let ht;e[120]!==h||e[121]!==tt?(ht=s.jsx(B,{size:"sm",variant:"ghost",onClick:_e,disabled:h,children:tt}),e[120]=h,e[121]=tt,e[122]=ht):ht=e[122];let mt;e[123]!==h||e[124]!==i?(mt=i(h?"settings.plugins.sidebar.actions.deleting":"settings.common.actions.delete"),e[123]=h,e[124]=i,e[125]=mt):mt=e[125];let ut;e[126]!==ce||e[127]!==h||e[128]!==mt?(ut=s.jsx(B,{size:"sm",variant:"destructive",onClick:ce,disabled:h,children:mt}),e[126]=ce,e[127]=h,e[128]=mt,e[129]=ut):ut=e[129];let ft;e[130]!==ht||e[131]!==ut?(ft=s.jsxs(es,{children:[ht,ut]}),e[130]=ht,e[131]=ut,e[132]=ft):ft=e[132];let kt;e[133]!==qe||e[134]!==ft?(kt=s.jsxs(Ot,{className:"max-w-md",children:[qe,ft]}),e[133]=qe,e[134]=ft,e[135]=kt):kt=e[135];let vt;e[136]!==Ie||e[137]!==Le||e[138]!==kt?(vt=s.jsx(Rt,{open:Ie,onOpenChange:Le,children:kt}),e[136]=Ie,e[137]=Le,e[138]=kt,e[139]=vt):vt=e[139];let Ct;return e[140]!==He||e[141]!==ue||e[142]!==vt?(Ct=s.jsxs(s.Fragment,{children:[He,ue,vt]}),e[140]=He,e[141]=ue,e[142]=vt,e[143]=Ct):Ct=e[143],Ct};function hm(t){return{entries:t.entries,files:t.files,selectedId:t.selectedId,setSelected:t.setSelected,deleteEntry:t.deleteEntry,deleteFile:t.deleteFile,loadPlugins:t.loadPlugins}}function fm(t){return t.registryInfo}function xm(t){return t.isLoadingRegistry}function bm(t){return t.loadRegistryInfo}function vm(t){return t.updateToLatest}function ym(t){return t.scope==="user"}function jm(t){return t.scope==="project"}function wm(t){return t.scope==="user"}function km(t){return t.scope==="project"}const Nm=({entryId:t,spec:e})=>{const{t:a}=nt(),n=rs(v=>v.registryInfo[e]),i=rs(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,c=n.currentVersion??"",N=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:c,latest:v})})]}),s.jsx(B,{variant:"default",size:"sm",onClick:()=>{N()},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 u=n.kind==="path-unreadable",g=u?"var(--status-warning)":"var(--status-error)",x=u?"alert":"error-warning",d=(()=>{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:g}}),s.jsxs("div",{className:"flex-1 min-w-0",children:[s.jsx("p",{className:"typography-label",style:{color:g},children:a("settings.plugins.registry.banner.invalid.title")}),s.jsx("p",{className:"typography-micro text-muted-foreground mt-0.5",children:d})]})]})};function Sm(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 Ol(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:Ol(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=lt.c(4),{scope:a,label:n}=t;let i;e[0]===Symbol.for("react.memo_cache_sentinel")?(i=we("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},Cm=()=>{const{t}=nt(),e=rs(k=>k.selectedId),a=rs(k=>k.entries),n=rs(k=>k.files),i=rs(k=>k.draft),r=rs(k=>k.setDraft),l=rs(k=>k.updateEntry),u=rs(k=>k.updateFile),g=rs(k=>k.readFile),x=o.useMemo(()=>e?a.find(k=>k.id===e)??null:null,[a,e]),d=o.useMemo(()=>e?n.find(k=>k.id===e)??null:null,[n,e]),[v,c]=o.useState(!1),[N,b]=o.useState(!1),C=o.useRef(new Map);if(o.useEffect(()=>{let k=!1;return x?(r(oo(x)),()=>{k=!0}):d?(b(!0),(async()=>{const A=await g(d.id);if(k)return;b(!1);const h=A?.content??"";C.current.set(d.id,h),r(lo(d,h))})(),()=>{k=!0}):(r(null),()=>{k=!0})},[x,d,g,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 k=Sm(i.optionsJson),A=k.ok,h=i.spec!==x.spec||i.optionsJson!==Ol(x.options),E=()=>{r(oo(x))},F=async()=>{if(!A)return;const I=i.spec.trim();if(!I){D.error(t("settings.plugins.validation.specRequired"));return}c(!0);try{const w=await l(x.id,{spec:I,options:k.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{c(!1)}};return s.jsxs(ns,{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($e,{divider:!1,children:s.jsx(Nm,{entryId:x.id,spec:x.spec})}),s.jsx($e,{title:t("settings.plugins.page.field.spec"),settingsItem:"plugins.spec",children:s.jsx(We,{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($e,{title:t("settings.plugins.page.field.options"),settingsItem:"plugins.options",children:[s.jsx(Is,{value:i.optionsJson,onChange:I=>r({...i,optionsJson:I.target.value}),rows:10,className:we("font-mono typography-meta min-h-[200px]",!A&&"border-[var(--status-error-border)]"),spellCheck:!1,placeholder:"{ }"}),!A&&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:()=>{F()},disabled:!h||!A||v,children:t("settings.plugins.page.action.save")}),s.jsx(B,{variant:"outline",size:"sm",onClick:E,disabled:!h||v,children:t("settings.plugins.page.action.discard")})]})]})]})}if(d&&i&&i.mode==="file"){const k=C.current.get(d.id)??"",A=i.content!==k||i.fileName!==d.fileName,h=()=>{(async()=>{b(!0);const I=(await g(d.id))?.content??"";b(!1),C.current.set(d.id,I),r(lo(d,I))})()},E=async()=>{c(!0);try{const F=await u(d.id,{content:i.content});F.ok?(C.current.set(d.id,i.content),F.reloadFailed?D.warning(F.message||t("settings.plugins.toast.reloadFailed"),{description:F.warning}):F.restartDeferred?D.success(t("settings.view.pendingRestart.saved")):D.success(F.message||t("settings.plugins.toast.updated"))):D.error(F.message||t("settings.plugins.toast.reloadFailed"))}finally{c(!1)}};return s.jsx(ns,{title:t("settings.plugins.page.header.file"),titleAccessory:s.jsxs(s.Fragment,{children:[s.jsx(co,{scope:d.scope,label:d.scope==="project"?t("settings.plugins.sidebar.group.projectFiles"):t("settings.plugins.sidebar.group.userFiles")}),s.jsx("span",{className:we("typography-micro font-mono rounded-full px-2 py-0.5","bg-[var(--surface-elevated)] text-foreground","border border-[var(--interactive-border)]"),children:d.fileName})]}),showSaveStatus:!1,children:s.jsxs($e,{title:t("settings.plugins.page.field.content"),divider:!1,settingsItem:"plugins.content",children:[s.jsx(Is,{value:i.content,onChange:F=>r({...i,content:F.target.value}),rows:16,className:"font-mono typography-meta min-h-[320px]",spellCheck:!1,disabled:N}),s.jsxs("div",{className:"flex items-center gap-2 pt-3",children:[s.jsx(B,{variant:"default",size:"sm",onClick:()=>{E()},disabled:!A||v||N,children:t("settings.plugins.page.action.save")}),s.jsx(B,{variant:"outline",size:"sm",onClick:h,disabled:v||N,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"})})})},Pm="<built-in>",Ra=t=>t?.path===Pm,nr=t=>!!t&&!Ra(t)&&t.renamable===!0,Im=t=>{const e=lt.c(157),{onItemSelect:a}=t,{t:n}=nt(),[i,r]=o.useState(null),[l,u]=o.useState(""),[g,x]=o.useState(null),[d,v]=o.useState(!1),[c,N]=o.useState(null),{selectedSkillName:b,setSelectedSkill:C,setSkillDraft:k,deleteSkill:A,renameSkill:h,getSkillDetail:E}=$s(Ds(Am)),F=zs();let I;e[0]!==F?(I=Ae=>cr(Ae,F),e[0]=F,e[1]=I):I=e[1];const w=$s(I),m=$s(Em);let y,U;e[2]!==m||e[3]!==F?(y=()=>{m(F)},U=[m,F],e[2]=m,e[3]=F,e[4]=y,e[5]=U):(y=e[4],U=e[5]),o.useEffect(y,U);let S;e[6]!==a||e[7]!==C||e[8]!==k||e[9]!==w?(S=()=>{let Ae="new-skill",yt=1;for(;w.some(Q=>Q.name===Ae);)Ae=`new-skill-${yt}`,yt++;k({name:Ae,scope:"user",source:"opencode",description:""}),C(Ae),a?.()},e[6]=a,e[7]=C,e[8]=k,e[9]=w,e[10]=S):S=e[10];const M=S;let j;e[11]===Symbol.for("react.memo_cache_sentinel")?(j=async Ae=>{Ra(Ae)||x(Ae)},e[11]=j):j=e[11];const R=j;let H;e[12]!==g||e[13]!==A||e[14]!==F||e[15]!==n?(H=async()=>{if(!g)return;if(Ra(g)){x(null);return}v(!0),await A(g.name,F)?(D.success(n("settings.skills.sidebar.toast.skillDeleted",{name:g.name})),x(null)):D.error(n("settings.skills.sidebar.toast.deleteSkillFailed")),v(!1)},e[12]=g,e[13]=A,e[14]=F,e[15]=n,e[16]=H):H=e[16];const P=H;let G;e[17]!==E||e[18]!==C||e[19]!==k||e[20]!==F||e[21]!==w||e[22]!==n?(G=async Ae=>{if(Ra(Ae))return;const yt=Ae.name;let Q=1,he=`${yt}-copy`;for(;w.some(De=>De.name===he);)Q++,he=`${yt}-copy-${Q}`;const ze=await E(Ae.name,F);if(!ze){D.error(n("settings.skills.sidebar.toast.duplicateLoadFailed"));return}k({name:he,scope:Ae.scope||"user",source:Ae.source||"opencode",description:(ze.sources.md.fields.includes("description"),""),instructions:""}),C(he)},e[17]=E,e[18]=C,e[19]=k,e[20]=F,e[21]=w,e[22]=n,e[23]=G):G=e[23];const J=G;let T;e[24]===Symbol.for("react.memo_cache_sentinel")?(T=Ae=>{nr(Ae)&&(u(Ae.name),r(Ae))},e[24]=T):T=e[24];const W=T;let X;e[25]!==i||e[26]!==l||e[27]!==h||e[28]!==C||e[29]!==F||e[30]!==w||e[31]!==n?(X=async()=>{if(!i)return;if(!nr(i)){r(null);return}const Ae=l.trim().replace(/\s+/g,"-").toLowerCase();if(!Ae){D.error(n("settings.skills.page.toast.skillNameRequired"));return}if(Ae===i.name){r(null);return}if(w.some(Q=>Q.name===Ae)){D.error(n("settings.skills.page.toast.skillExists"));return}await h(i.name,Ae,F)?(D.success(n("settings.skills.sidebar.toast.skillRenamed",{name:Ae})),C(Ae)):D.error(n("settings.skills.sidebar.toast.renameFailed")),r(null)},e[25]=i,e[26]=l,e[27]=h,e[28]=C,e[29]=F,e[30]=w,e[31]=n,e[32]=X):X=e[32];const K=X;let te;e[33]!==w?(te=w.filter(Tm),e[33]=w,e[34]=te):te=e[34];const $=te;let V;e[35]!==w?(V=w.filter(Dm),e[35]=w,e[36]=V):V=e[36];const _=V;let z;e[37]===Symbol.for("react.memo_cache_sentinel")?(z=function(yt){const Q={},he=[];for(const De of yt)De.group?(Q[De.group]||(Q[De.group]=[]),Q[De.group].push(De)):he.push(De);const ze=Object.keys(Q).sort(Mm).map(De=>({name:De,skills:[...Q[De]].sort(Rm)}));return he.sort(Om),{sortedGroups:ze,ungrouped:he}},e[37]=z):z=e[37];const Z=z;let Y;e[38]!==$?(Y=Z($),e[38]=$,e[39]=Y):Y=e[39];const se=Y;let ge;e[40]!==_?(ge=Z(_),e[40]=_,e[41]=ge):ge=e[41];const ce=ge;let be;e[42]===Symbol.for("react.memo_cache_sentinel")?(be=we("flex h-full flex-col","bg-background"),e[42]=be):be=e[42];let ne;e[43]!==n?(ne=n("settings.skills.sidebar.title"),e[43]=n,e[44]=ne):ne=e[44];let ae;e[45]!==ne?(ae=s.jsx("h2",{className:`${nn} mb-3`,children:ne}),e[45]=ne,e[46]=ae):ae=e[46];let me;e[47]===Symbol.for("react.memo_cache_sentinel")?(me=s.jsx(za,{className:"mb-3"}),e[47]=me):me=e[47];let Pe;e[48]!==w.length||e[49]!==n?(Pe=n("settings.skills.sidebar.total",{count:w.length}),e[48]=w.length,e[49]=n,e[50]=Pe):Pe=e[50];let Ne;e[51]!==Pe?(Ne=s.jsx("span",{className:"typography-meta text-muted-foreground",children:Pe}),e[51]=Pe,e[52]=Ne):Ne=e[52];let Se;e[53]===Symbol.for("react.memo_cache_sentinel")?(Se=s.jsx(L,{name:"add",className:"h-3.5 w-3.5"}),e[53]=Se):Se=e[53];let je;e[54]!==M?(je=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:M,children:Se}),e[54]=M,e[55]=je):je=e[55];let Me;e[56]!==Ne||e[57]!==je?(Me=s.jsxs("div",{className:"flex items-center justify-between gap-2",children:[Ne,je]}),e[56]=Ne,e[57]=je,e[58]=Me):Me=e[58];let Re;e[59]!==ae||e[60]!==Me?(Re=s.jsxs("div",{className:"border-b px-3 pt-4 pb-3",children:[ae,me,Me]}),e[59]=ae,e[60]=Me,e[61]=Re):Re=e[61];let re;e[62]!==se||e[63]!==ce||e[64]!==J||e[65]!==a||e[66]!==c||e[67]!==$||e[68]!==b||e[69]!==C||e[70]!==w.length||e[71]!==n||e[72]!==_?(re=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")}),se.sortedGroups.map(Ae=>{const{name:yt,skills:Q}=Ae;return s.jsx(Xi,{label:yt,count:Q.length,storageKey:"project-skills",children:Q.map(he=>s.jsx(Xa,{skill:he,isSelected:b===he.name,onSelect:()=>{C(he.name),a?.()},onRename:()=>W(he),onDelete:()=>R(he),onDuplicate:()=>J(he),isMenuOpen:c===he.name,onMenuOpenChange:ze=>N(ze?he.name:null)},he.name))},yt)}),se.ungrouped.map(Ae=>s.jsx(Xa,{skill:Ae,isSelected:b===Ae.name,onSelect:()=>{C(Ae.name),a?.()},onRename:()=>W(Ae),onDelete:()=>R(Ae),onDuplicate:()=>J(Ae),isMenuOpen:c===Ae.name,onMenuOpenChange:yt=>N(yt?Ae.name:null)},Ae.name))]}),_.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")}),ce.sortedGroups.map(Ae=>{const{name:yt,skills:Q}=Ae;return s.jsx(Xi,{label:yt,count:Q.length,storageKey:"user-skills",children:Q.map(he=>s.jsx(Xa,{skill:he,isSelected:b===he.name,onSelect:()=>{C(he.name),a?.()},onRename:()=>W(he),onDelete:()=>R(he),onDuplicate:()=>J(he),isMenuOpen:c===he.name,onMenuOpenChange:ze=>N(ze?he.name:null)},he.name))},yt)}),ce.ungrouped.map(Ae=>s.jsx(Xa,{skill:Ae,isSelected:b===Ae.name,onSelect:()=>{C(Ae.name),a?.()},onRename:()=>W(Ae),onDelete:()=>R(Ae),onDuplicate:()=>J(Ae),isMenuOpen:c===Ae.name,onMenuOpenChange:yt=>N(yt?Ae.name:null)},Ae.name))]})]})}),e[62]=se,e[63]=ce,e[64]=J,e[65]=a,e[66]=c,e[67]=$,e[68]=b,e[69]=C,e[70]=w.length,e[71]=n,e[72]=_,e[73]=re):re=e[73];const fe=g!==null;let Ee;e[74]!==d?(Ee=Ae=>{!Ae&&!d&&x(null)},e[74]=d,e[75]=Ee):Ee=e[75];let Be;e[76]!==n?(Be=n("settings.skills.sidebar.deleteDialog.title"),e[76]=n,e[77]=Be):Be=e[77];let Ve;e[78]!==Be?(Ve=s.jsx(Ut,{children:Be}),e[78]=Be,e[79]=Ve):Ve=e[79];const Ge=g?.name??"";let Ke;e[80]!==n||e[81]!==Ge?(Ke=n("settings.skills.sidebar.deleteDialog.description",{name:Ge}),e[80]=n,e[81]=Ge,e[82]=Ke):Ke=e[82];let oe;e[83]!==Ke?(oe=s.jsx(zt,{children:Ke}),e[83]=Ke,e[84]=oe):oe=e[84];let ie;e[85]!==Ve||e[86]!==oe?(ie=s.jsxs(Kt,{children:[Ve,oe]}),e[85]=Ve,e[86]=oe,e[87]=ie):ie=e[87];let ye;e[88]===Symbol.for("react.memo_cache_sentinel")?(ye=()=>x(null),e[88]=ye):ye=e[88];let ve;e[89]!==n?(ve=n("settings.common.actions.cancel"),e[89]=n,e[90]=ve):ve=e[90];let Oe;e[91]!==d||e[92]!==ve?(Oe=s.jsx(B,{size:"sm",className:"text-foreground hover:bg-interactive-hover hover:text-foreground",variant:"ghost",onClick:ye,disabled:d,children:ve}),e[91]=d,e[92]=ve,e[93]=Oe):Oe=e[93];let Te;e[94]!==n?(Te=n("settings.common.actions.delete"),e[94]=n,e[95]=Te):Te=e[95];let xe;e[96]!==P||e[97]!==d||e[98]!==Te?(xe=s.jsx(B,{size:"sm",onClick:P,disabled:d,children:Te}),e[96]=P,e[97]=d,e[98]=Te,e[99]=xe):xe=e[99];let He;e[100]!==Oe||e[101]!==xe?(He=s.jsxs(es,{children:[Oe,xe]}),e[100]=Oe,e[101]=xe,e[102]=He):He=e[102];let ue;e[103]!==ie||e[104]!==He?(ue=s.jsxs(Ot,{className:"max-w-md",children:[ie,He]}),e[103]=ie,e[104]=He,e[105]=ue):ue=e[105];let Ie;e[106]!==fe||e[107]!==Ee||e[108]!==ue?(Ie=s.jsx(Rt,{open:fe,onOpenChange:Ee,children:ue}),e[106]=fe,e[107]=Ee,e[108]=ue,e[109]=Ie):Ie=e[109];const Le=i!==null;let Ye;e[110]===Symbol.for("react.memo_cache_sentinel")?(Ye=Ae=>!Ae&&r(null),e[110]=Ye):Ye=e[110];let q;e[111]!==n?(q=n("settings.skills.sidebar.renameDialog.title"),e[111]=n,e[112]=q):q=e[112];let ke;e[113]!==q?(ke=s.jsx(Ut,{children:q}),e[113]=q,e[114]=ke):ke=e[114];const O=i?.name??"";let Ce;e[115]!==n||e[116]!==O?(Ce=n("settings.skills.sidebar.renameDialog.description",{name:O}),e[115]=n,e[116]=O,e[117]=Ce):Ce=e[117];let qe;e[118]!==Ce?(qe=s.jsx(zt,{children:Ce}),e[118]=Ce,e[119]=qe):qe=e[119];let _e;e[120]!==ke||e[121]!==qe?(_e=s.jsxs(Kt,{children:[ke,qe]}),e[120]=ke,e[121]=qe,e[122]=_e):_e=e[122];let tt;e[123]===Symbol.for("react.memo_cache_sentinel")?(tt=Ae=>u(Ae.target.value),e[123]=tt):tt=e[123];let ht;e[124]!==n?(ht=n("settings.skills.sidebar.renameDialog.placeholder"),e[124]=n,e[125]=ht):ht=e[125];let mt;e[126]!==K?(mt=Ae=>{Ae.key==="Enter"&&K()},e[126]=K,e[127]=mt):mt=e[127];let ut;e[128]!==l||e[129]!==ht||e[130]!==mt?(ut=s.jsx(We,{value:l,onChange:tt,placeholder:ht,className:"text-foreground placeholder:text-muted-foreground",onKeyDown:mt}),e[128]=l,e[129]=ht,e[130]=mt,e[131]=ut):ut=e[131];let ft;e[132]===Symbol.for("react.memo_cache_sentinel")?(ft=()=>r(null),e[132]=ft):ft=e[132];let kt;e[133]!==n?(kt=n("settings.common.actions.cancel"),e[133]=n,e[134]=kt):kt=e[134];let vt;e[135]!==kt?(vt=s.jsx(B,{size:"sm",className:"text-foreground hover:bg-interactive-hover hover:text-foreground",variant:"ghost",onClick:ft,children:kt}),e[135]=kt,e[136]=vt):vt=e[136];let Ct;e[137]!==n?(Ct=n("settings.common.actions.rename"),e[137]=n,e[138]=Ct):Ct=e[138];let Ze;e[139]!==K||e[140]!==Ct?(Ze=s.jsx(B,{size:"sm",onClick:K,children:Ct}),e[139]=K,e[140]=Ct,e[141]=Ze):Ze=e[141];let Xe;e[142]!==vt||e[143]!==Ze?(Xe=s.jsxs(es,{children:[vt,Ze]}),e[142]=vt,e[143]=Ze,e[144]=Xe):Xe=e[144];let ct;e[145]!==_e||e[146]!==ut||e[147]!==Xe?(ct=s.jsxs(Ot,{children:[_e,ut,Xe]}),e[145]=_e,e[146]=ut,e[147]=Xe,e[148]=ct):ct=e[148];let Ue;e[149]!==Le||e[150]!==ct?(Ue=s.jsx(Rt,{open:Le,onOpenChange:Ye,children:ct}),e[149]=Le,e[150]=ct,e[151]=Ue):Ue=e[151];let jt;return e[152]!==Re||e[153]!==re||e[154]!==Ie||e[155]!==Ue?(jt=s.jsxs("div",{className:be,children:[Re,re,Ie,Ue]}),e[152]=Re,e[153]=re,e[154]=Ie,e[155]=Ue,e[156]=jt):jt=e[156],jt},Xa=t=>{const e=lt.c(41),{skill:a,isSelected:n,onSelect:i,onDelete:r,onRename:l,onDuplicate:u,isMenuOpen:g,onMenuOpenChange:x}=t,{t:d}=nt();let v;e[0]===Symbol.for("react.memo_cache_sentinel")?(v=La(),e[0]=v):v=e[0];const c=v;let N;e[1]!==a?(N=Ra(a),e[1]=a,e[2]=N):N=e[2];const b=N;let C;e[3]!==a?(C=nr(a),e[3]=a,e[4]=C):C=e[4];const k=C,[A,h]=o.useState(!1);let E;e[5]!==k||e[6]!==r||e[7]!==u||e[8]!==l||e[9]!==d?(E=J=>s.jsxs(s.Fragment,{children:[k?s.jsxs(J,{onClick:T=>{T.stopPropagation(),l()},children:[s.jsx(L,{name:"edit",className:"h-4 w-4 mr-px"}),d("settings.common.actions.rename")]}):null,s.jsxs(J,{onClick:T=>{T.stopPropagation(),u()},children:[s.jsx(L,{name:"file-copy",className:"h-4 w-4 mr-px"}),d("settings.common.actions.duplicate")]}),s.jsxs(J,{onClick:T=>{T.stopPropagation(),r()},className:"text-destructive focus:text-destructive",children:[s.jsx(L,{name:"delete-bin",className:"h-4 w-4 mr-px"}),d("settings.common.actions.delete")]})]}),e[5]=k,e[6]=r,e[7]=u,e[8]=l,e[9]=d,e[10]=E):E=e[10];const F=E,I=!b&&A,w=n?"bg-interactive-selection":"hover:bg-interactive-hover";let m;e[11]!==w?(m=we("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=!c&&!b?J=>{J.preventDefault(),h(!0)}:void 0,e[13]=b,e[14]=y):y=e[14];let U;e[15]!==m||e[16]!==y?(U=s.jsx("div",{className:m,onContextMenu:y}),e[15]=m,e[16]=y,e[17]=U):U=e[17];let S;e[18]!==a.name?(S=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]=S):S=e[19];let M;e[20]!==i||e[21]!==S?(M=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:S}),e[20]=i,e[21]=S,e[22]=M):M=e[22];let j;e[23]!==b||e[24]!==g||e[25]!==x||e[26]!==F?(j=b?null:s.jsxs(tn,{open:g,onOpenChange:J=>{J&&h(!1),x(J)},children:[s.jsx(Zs,{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(en,{align:"end",className:"w-fit min-w-20",children:F(sn)})]}),e[23]=b,e[24]=g,e[25]=x,e[26]=F,e[27]=j):j=e[27];let R;e[28]!==M||e[29]!==j?(R=s.jsxs("div",{className:"flex min-w-0 flex-1 items-center",children:[M,j]}),e[28]=M,e[29]=j,e[30]=R):R=e[30];let H;e[31]!==R||e[32]!==U?(H=s.jsx(Vn,{render:U,children:R}),e[31]=R,e[32]=U,e[33]=H):H=e[33];let P;e[34]!==b||e[35]!==F?(P=b?null:s.jsx(_n,{className:"w-fit min-w-20",children:F($n)}),e[34]=b,e[35]=F,e[36]=P):P=e[36];let G;return e[37]!==H||e[38]!==P||e[39]!==I?(G=s.jsxs(Bn,{open:I,onOpenChange:h,children:[H,P]}),e[37]=H,e[38]=P,e[39]=I,e[40]=G):G=e[40],G};function Am(t){return{selectedSkillName:t.selectedSkillName,setSelectedSkill:t.setSelectedSkill,setSkillDraft:t.setSkillDraft,deleteSkill:t.deleteSkill,renameSkill:t.renameSkill,getSkillDetail:t.getSkillDetail}}function Em(t){return t.loadSkills}function Tm(t){return t.scope==="project"}function Dm(t){return t.scope==="user"}function Mm(t,e){return t.localeCompare(e)}function Rm(t,e){return t.name.localeCompare(e.name)}function Om(t,e){return t.name.localeCompare(e.name)}const Lm=()=>`custom:${Date.now()}-${Math.random().toString(16).slice(2)}`,Fm=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},Km=async()=>{try{const t=Pn()?.settings;if(t)return(await t.load())?.settings||{};const e=await rt("/api/config/settings",{method:"GET",headers:{Accept:"application/json"}});return e.ok?await e.json().catch(()=>null):null}catch{return null}},Um=t=>{const e=lt.c(162),{open:a,onOpenChange:n}=t,{t:i}=nt(),r=mn(zm),l=mn(_m),u=mn($m),g=mn(Vm),x=mn(Bm),d=Ln(Hm),v=Ln(Gm),[c,N]=o.useState(""),[b,C]=o.useState(""),[k,A]=o.useState("");let h;e[0]===Symbol.for("react.memo_cache_sentinel")?(h=[],e[0]=h):h=e[0];const[E,F]=o.useState(h),[I,w]=o.useState(null),[m,y]=o.useState(!1);let U;e[1]===Symbol.for("react.memo_cache_sentinel")?(U=[],e[1]=U):U=e[1];const[S,M]=o.useState(U),[j,R]=o.useState(null),H=o.useRef(0);let P;e[2]===Symbol.for("react.memo_cache_sentinel")?(P=Xe=>{H.current=H.current+1,y(!1),w(null),Xe?.clearIdentity&&(M([]),R(null))},e[2]=P):P=e[2];const G=P;let J,T;e[3]!==v||e[4]!==a?(J=()=>{a&&(H.current=H.current+1,N(""),C(""),A(""),w(null),y(!1),M([]),R(null),v(),(async()=>{const Xe=await Km(),ct=Array.isArray(Xe?.skillCatalogs)?Xe?.skillCatalogs:[];F(ct||[])})())},T=[a,v],e[3]=v,e[4]=a,e[5]=J,e[6]=T):(J=e[5],T=e[6]),o.useEffect(J,T);let W;e[7]!==b?(W=b.trim(),e[7]=b,e[8]=W):W=e[8];const X=W;let K;e[9]!==k?(K=k.trim(),e[9]=k,e[10]=K):K=e[10];const te=K;let $;if(e[11]!==E||e[12]!==X||e[13]!==te){let Xe;e[15]!==X||e[16]!==te?(Xe=ct=>{const Ue=(ct.source||"").trim(),jt=(ct.subpath||"").trim();return Ue===X&&jt===te},e[15]=X,e[16]=te,e[17]=Xe):Xe=e[17],$=E.some(Xe),e[11]=E,e[12]=X,e[13]=te,e[14]=$}else $=e[14];const V=$;let _;e[18]!==d||e[19]!==j||e[20]!==c||e[21]!==r||e[22]!==b||e[23]!==k||e[24]!==i?(_=async()=>{const Xe=b.trim();if(!Xe){D.error(i("settings.skills.catalog.add.toast.repositoryRequired"));return}c.trim()||N(Fm(Xe)),y(!1),w(null);const ct=H.current+1;H.current=ct;const Ue=await r({source:Xe,subpath:k.trim()||void 0,gitIdentityId:j||void 0});if(H.current!==ct)return;if(!Ue.ok){if(Ue.error?.kind==="authRequired"){if(ps()){D.error(i("settings.skills.catalog.shared.toast.privateRepoNotSupportedVsCode"));return}const Ae=Ue.error.identities||[];if(M(Ae),!j&&Ae.length>0){const yt=d&&d!=="global"&&Ae.some(Q=>Q.id===d)?d:Ae[0].id;R(yt)}D.error(i("settings.skills.catalog.add.toast.authenticationRequiredScan"));return}D.error(Ue.error?.message||i("settings.skills.catalog.add.toast.scanFailed"));return}const jt=Ue.items?.length||0;if(w(jt),jt===0){D.error(i("settings.skills.catalog.add.toast.noSkillsFound")),y(!1);return}M([]),y(!0),D.success(i("settings.skills.catalog.shared.toast.foundSkills",{count:jt}))},e[18]=d,e[19]=j,e[20]=c,e[21]=r,e[22]=b,e[23]=k,e[24]=i,e[25]=_):_=e[25];const z=_;let Z;e[26]!==E||e[27]!==j||e[28]!==V||e[29]!==c||e[30]!==l||e[31]!==u||e[32]!==n||e[33]!==m||e[34]!==g||e[35]!==b||e[36]!==k||e[37]!==i?(Z=async()=>{const Xe=c.trim(),ct=b.trim(),Ue=k.trim();if(!Xe){D.error(i("settings.skills.catalog.add.toast.catalogNameRequired"));return}if(!ct){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 jt={id:Lm(),label:Xe,source:ct,...Ue?{subpath:Ue}:{},...j?{gitIdentityId:j}:{}},Ae=[...E,jt];try{await xt({skillCatalogs:Ae}),F(Ae),D.success(i("settings.skills.catalog.add.toast.catalogAdded")),await l({refresh:!0}),await u(jt.id,{refresh:!0}),g(jt.id),n(!1)}catch(yt){const Q=yt;D.error(Q instanceof Error?Q.message:i("settings.skills.catalog.add.toast.saveFailed"))}},e[26]=E,e[27]=j,e[28]=V,e[29]=c,e[30]=l,e[31]=u,e[32]=n,e[33]=m,e[34]=g,e[35]=b,e[36]=k,e[37]=i,e[38]=Z):Z=e[38];const Y=Z;let se;e[39]!==i?(se=i("settings.skills.catalog.add.title"),e[39]=i,e[40]=se):se=e[40];let ge;e[41]!==se?(ge=s.jsx(Ut,{children:se}),e[41]=se,e[42]=ge):ge=e[42];let ce;e[43]!==i?(ce=i("settings.skills.catalog.add.descriptionPrefix"),e[43]=i,e[44]=ce):ce=e[44];let be;e[45]===Symbol.for("react.memo_cache_sentinel")?(be=s.jsx("code",{className:"font-mono",children:"SKILL.md"}),e[45]=be):be=e[45];let ne;e[46]!==i?(ne=i("settings.skills.catalog.add.descriptionSuffix"),e[46]=i,e[47]=ne):ne=e[47];let ae;e[48]!==ce||e[49]!==ne?(ae=s.jsxs(zt,{children:[ce," ",be,ne]}),e[48]=ce,e[49]=ne,e[50]=ae):ae=e[50];let me;e[51]!==ge||e[52]!==ae?(me=s.jsxs(Kt,{children:[ge,ae]}),e[51]=ge,e[52]=ae,e[53]=me):me=e[53];let Pe;e[54]!==i?(Pe=i("settings.skills.catalog.add.field.catalogName"),e[54]=i,e[55]=Pe):Pe=e[55];let Ne;e[56]!==Pe?(Ne=s.jsx("label",{className:"typography-ui-label text-foreground",children:Pe}),e[56]=Pe,e[57]=Ne):Ne=e[57];let Se;e[58]===Symbol.for("react.memo_cache_sentinel")?(Se=Xe=>N(Xe.target.value),e[58]=Se):Se=e[58];let je;e[59]!==i?(je=i("settings.skills.catalog.add.field.catalogNamePlaceholder"),e[59]=i,e[60]=je):je=e[60];let Me;e[61]!==c||e[62]!==je?(Me=s.jsx(We,{value:c,onChange:Se,placeholder:je}),e[61]=c,e[62]=je,e[63]=Me):Me=e[63];let Re;e[64]!==Ne||e[65]!==Me?(Re=s.jsxs("div",{className:"space-y-2",children:[Ne,Me]}),e[64]=Ne,e[65]=Me,e[66]=Re):Re=e[66];let re;e[67]!==i?(re=i("settings.skills.catalog.add.field.repository"),e[67]=i,e[68]=re):re=e[68];let fe;e[69]!==re?(fe=s.jsx("label",{className:"typography-ui-label text-foreground",children:re}),e[69]=re,e[70]=fe):fe=e[70];let Ee;e[71]!==i?(Ee=i("settings.skills.catalog.add.field.repositoryHint"),e[71]=i,e[72]=Ee):Ee=e[72];let Be;e[73]!==Ee?(Be=s.jsx(Jt,{children:Ee}),e[73]=Ee,e[74]=Be):Be=e[74];let Ve;e[75]!==fe||e[76]!==Be?(Ve=s.jsxs("div",{className:"flex items-center gap-1",children:[fe,Be]}),e[75]=fe,e[76]=Be,e[77]=Ve):Ve=e[77];let Ge;e[78]===Symbol.for("react.memo_cache_sentinel")?(Ge=Xe=>{C(Xe.target.value),G({clearIdentity:!0})},e[78]=Ge):Ge=e[78];let Ke;e[79]!==i?(Ke=i("settings.skills.catalog.shared.field.repositoryPlaceholder"),e[79]=i,e[80]=Ke):Ke=e[80];let oe;e[81]!==b||e[82]!==Ke?(oe=s.jsx(We,{value:b,onChange:Ge,placeholder:Ke}),e[81]=b,e[82]=Ke,e[83]=oe):oe=e[83];let ie;e[84]!==Ve||e[85]!==oe?(ie=s.jsxs("div",{className:"space-y-2",children:[Ve,oe]}),e[84]=Ve,e[85]=oe,e[86]=ie):ie=e[86];let ye;e[87]!==i?(ye=i("settings.skills.catalog.add.field.optionalSubpath"),e[87]=i,e[88]=ye):ye=e[88];let ve;e[89]!==ye?(ve=s.jsx("label",{className:"typography-ui-label text-foreground",children:ye}),e[89]=ye,e[90]=ve):ve=e[90];let Oe;e[91]===Symbol.for("react.memo_cache_sentinel")?(Oe=Xe=>{A(Xe.target.value),G({clearIdentity:!0})},e[91]=Oe):Oe=e[91];let Te;e[92]!==i?(Te=i("settings.skills.catalog.shared.field.subpathPlaceholder"),e[92]=i,e[93]=Te):Te=e[93];let xe;e[94]!==k||e[95]!==Te?(xe=s.jsx(We,{value:k,onChange:Oe,placeholder:Te}),e[94]=k,e[95]=Te,e[96]=xe):xe=e[96];let He;e[97]!==ve||e[98]!==xe?(He=s.jsxs("div",{className:"space-y-2",children:[ve,xe]}),e[97]=ve,e[98]=xe,e[99]=He):He=e[99];let ue;e[100]!==j||e[101]!==S||e[102]!==i?(ue=S.length>0&&!ps()?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(Jt,{className:"ml-1",children:i("settings.skills.catalog.shared.auth.footerHint")})]}),s.jsxs(At,{value:j||"",onValueChange:Xe=>{R(Xe),G()},children:[s.jsx(Et,{className:"w-fit",children:s.jsx("span",{children:S.find(Xe=>Xe.id===j)?.name||i("settings.skills.catalog.shared.auth.chooseIdentity")})}),s.jsx(Tt,{align:"start",children:S.map(qm)})]})]}):null,e[100]=j,e[101]=S,e[102]=i,e[103]=ue):ue=e[103];let Ie;e[104]!==I||e[105]!==i?(Ie=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]=Ie):Ie=e[106];let Le;e[107]!==V||e[108]!==i?(Le=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]=Le):Le=e[109];let Ye;e[110]!==Re||e[111]!==ie||e[112]!==He||e[113]!==ue||e[114]!==Ie||e[115]!==Le?(Ye=s.jsxs("div",{className:"space-y-4",children:[Re,ie,He,ue,Ie,Le]}),e[110]=Re,e[111]=ie,e[112]=He,e[113]=ue,e[114]=Ie,e[115]=Le,e[116]=Ye):Ye=e[116];let q;e[117]!==n?(q=()=>n(!1),e[117]=n,e[118]=q):q=e[118];let ke;e[119]!==i?(ke=i("settings.common.actions.cancel"),e[119]=i,e[120]=ke):ke=e[120];let O;e[121]!==q||e[122]!==ke?(O=s.jsx(B,{size:"sm",variant:"ghost",onClick:q,children:ke}),e[121]=q,e[122]=ke,e[123]=O):O=e[123];let Ce;e[124]!==z?(Ce=()=>{z()},e[124]=z,e[125]=Ce):Ce=e[125];let qe;e[126]!==x||e[127]!==b?(qe=x||!b.trim(),e[126]=x,e[127]=b,e[128]=qe):qe=e[128];let _e;e[129]===Symbol.for("react.memo_cache_sentinel")?(_e=s.jsx(L,{name:"git-repository",className:"h-4 w-4"}),e[129]=_e):_e=e[129];let tt;e[130]!==x||e[131]!==i?(tt=i(x?"settings.skills.catalog.shared.actions.scanning":"settings.skills.catalog.shared.actions.scan"),e[130]=x,e[131]=i,e[132]=tt):tt=e[132];let ht;e[133]!==Ce||e[134]!==qe||e[135]!==tt?(ht=s.jsxs(B,{size:"sm",className:"gap-2",variant:"ghost",onClick:Ce,disabled:qe,children:[_e,tt]}),e[133]=Ce,e[134]=qe,e[135]=tt,e[136]=ht):ht=e[136];let mt;e[137]!==Y?(mt=()=>{Y()},e[137]=Y,e[138]=mt):mt=e[138];let ut;e[139]!==V||e[140]!==c||e[141]!==m||e[142]!==b?(ut=!m||V||!c.trim()||!b.trim(),e[139]=V,e[140]=c,e[141]=m,e[142]=b,e[143]=ut):ut=e[143];let ft;e[144]!==i?(ft=i("settings.skills.catalog.add.actions.addCatalog"),e[144]=i,e[145]=ft):ft=e[145];let kt;e[146]!==mt||e[147]!==ut||e[148]!==ft?(kt=s.jsx(B,{size:"sm",onClick:mt,disabled:ut,children:ft}),e[146]=mt,e[147]=ut,e[148]=ft,e[149]=kt):kt=e[149];let vt;e[150]!==O||e[151]!==ht||e[152]!==kt?(vt=s.jsxs(es,{children:[O,ht,kt]}),e[150]=O,e[151]=ht,e[152]=kt,e[153]=vt):vt=e[153];let Ct;e[154]!==me||e[155]!==Ye||e[156]!==vt?(Ct=s.jsxs(Ot,{className:"max-w-xl",children:[me,Ye,vt]}),e[154]=me,e[155]=Ye,e[156]=vt,e[157]=Ct):Ct=e[157];let Ze;return e[158]!==n||e[159]!==a||e[160]!==Ct?(Ze=s.jsx(Rt,{open:a,onOpenChange:n,children:Ct}),e[158]=n,e[159]=a,e[160]=Ct,e[161]=Ze):Ze=e[161],Ze};function zm(t){return t.scanRepo}function _m(t){return t.loadCatalog}function $m(t){return t.loadSource}function Vm(t){return t.setSelectedSource}function Bm(t){return t.isScanning}function Hm(t){return t.defaultGitIdentityId}function Gm(t){return t.loadDefaultGitIdentityId}function qm(t){return s.jsx(ot,{value:t.id,children:t.name},t.id)}const Wm=t=>{const e=lt.c(85),{open:a,onOpenChange:n,conflicts:i,onConfirm:r}=t,{t:l}=nt();let u;e[0]===Symbol.for("react.memo_cache_sentinel")?(u={},e[0]=u):u=e[0];const[g,x]=o.useState(u);let d,v;e[1]!==i||e[2]!==a?(d=()=>{if(!a)return;const Y={};for(const se of i)Y[se.skillName]="skip";x(Y)},v=[a,i],e[1]=i,e[2]=a,e[3]=d,e[4]=v):(d=e[3],v=e[4]),o.useEffect(d,v);let c;e[5]!==i?(c=Y=>{const se={};for(const ge of i)se[ge.skillName]=Y;x(se)},e[5]=i,e[6]=c):c=e[6];const N=c;let b;e[7]!==i||e[8]!==g?(b=i.length>0&&i.every(Y=>g[Y.skillName]),e[7]=i,e[8]=g,e[9]=b):b=e[9];const C=b;let k;e[10]!==l?(k=l("settings.skills.catalog.conflicts.title"),e[10]=l,e[11]=k):k=e[11];let A;e[12]!==k?(A=s.jsx(Ut,{children:k}),e[12]=k,e[13]=A):A=e[13];let h;e[14]!==l?(h=l("settings.skills.catalog.conflicts.description"),e[14]=l,e[15]=h):h=e[15];let E;e[16]!==h?(E=s.jsx(zt,{children:h}),e[16]=h,e[17]=E):E=e[17];let F;e[18]!==A||e[19]!==E?(F=s.jsxs(Kt,{children:[A,E]}),e[18]=A,e[19]=E,e[20]=F):F=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]!==N?(m=()=>N("skip"),e[26]=N,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 U;e[30]!==m||e[31]!==y?(U=s.jsx(B,{variant:"outline",size:"xs",className:"!font-normal",onClick:m,children:y}),e[30]=m,e[31]=y,e[32]=U):U=e[32];let S;e[33]!==N?(S=()=>N("overwrite"),e[33]=N,e[34]=S):S=e[34];let M;e[35]!==l?(M=l("settings.skills.catalog.conflicts.actions.overwriteAll"),e[35]=l,e[36]=M):M=e[36];let j;e[37]!==S||e[38]!==M?(j=s.jsx(B,{variant:"outline",size:"xs",className:"!font-normal",onClick:S,children:M}),e[37]=S,e[38]=M,e[39]=j):j=e[39];let R;e[40]!==U||e[41]!==j?(R=s.jsxs("div",{className:"flex items-center gap-2",children:[U,j]}),e[40]=U,e[41]=j,e[42]=R):R=e[42];let H;e[43]!==w||e[44]!==R?(H=s.jsxs("div",{className:"flex items-center justify-between gap-2",children:[w,R]}),e[43]=w,e[44]=R,e[45]=H):H=e[45];let P;if(e[46]!==i||e[47]!==g||e[48]!==l){let Y;e[50]!==g||e[51]!==l?(Y=se=>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:se.skillName}),s.jsx("div",{className:"typography-micro text-muted-foreground",children:l("settings.skills.catalog.conflicts.installedIn",{scope:se.scope==="project"?l("settings.skills.catalog.conflicts.scope.project"):l("settings.skills.catalog.conflicts.scope.user"),source:se.source==="agents"?l("settings.skills.catalog.conflicts.source.agents"):l("settings.skills.catalog.conflicts.source.opencode")})})]}),s.jsxs(At,{value:g[se.skillName]||"skip",onValueChange:ge=>x(ce=>({...ce,[se.skillName]:ge})),children:[s.jsx(Et,{className:"w-fit",children:s.jsx("span",{className:"capitalize",children:(g[se.skillName]||"skip")==="overwrite"?l("settings.skills.catalog.conflicts.decision.overwrite"):l("settings.skills.catalog.conflicts.decision.skip")})}),s.jsxs(Tt,{align:"end",children:[s.jsx(ot,{value:"skip",className:"pr-2 [&>span:first-child]:hidden",children:l("settings.skills.catalog.conflicts.decision.skip")}),s.jsx(ot,{value:"overwrite",className:"pr-2 [&>span:first-child]:hidden",children:l("settings.skills.catalog.conflicts.decision.overwrite")})]})]})]},se.skillName),e[50]=g,e[51]=l,e[52]=Y):Y=e[52],P=i.map(Y),e[46]=i,e[47]=g,e[48]=l,e[49]=P}else P=e[49];let G;e[53]!==P?(G=s.jsx("div",{className:"space-y-2",children:P}),e[53]=P,e[54]=G):G=e[54];let J;e[55]!==H||e[56]!==G?(J=s.jsxs("div",{className:"space-y-3",children:[H,G]}),e[55]=H,e[56]=G,e[57]=J):J=e[57];let T;e[58]!==n?(T=()=>n(!1),e[58]=n,e[59]=T):T=e[59];let W;e[60]!==l?(W=l("settings.common.actions.cancel"),e[60]=l,e[61]=W):W=e[61];let X;e[62]!==T||e[63]!==W?(X=s.jsx(B,{size:"sm",variant:"ghost",onClick:T,children:W}),e[62]=T,e[63]=W,e[64]=X):X=e[64];let K;e[65]!==g||e[66]!==r?(K=()=>r(g),e[65]=g,e[66]=r,e[67]=K):K=e[67];const te=!C;let $;e[68]!==l?($=l("settings.skills.catalog.conflicts.actions.continue"),e[68]=l,e[69]=$):$=e[69];let V;e[70]!==K||e[71]!==te||e[72]!==$?(V=s.jsx(B,{size:"sm",onClick:K,disabled:te,children:$}),e[70]=K,e[71]=te,e[72]=$,e[73]=V):V=e[73];let _;e[74]!==X||e[75]!==V?(_=s.jsxs(es,{children:[X,V]}),e[74]=X,e[75]=V,e[76]=_):_=e[76];let z;e[77]!==F||e[78]!==J||e[79]!==_?(z=s.jsxs(Ot,{className:"max-w-2xl",children:[F,J,_]}),e[77]=F,e[78]=J,e[79]=_,e[80]=z):z=e[80];let Z;return e[81]!==n||e[82]!==a||e[83]!==z?(Z=s.jsx(Rt,{open:a,onOpenChange:n,children:z}),e[81]=n,e[82]=a,e[83]=z,e[84]=Z):Z=e[84],Z},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 Oa(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 Ll(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 Jm=t=>{const e=lt.c(124),{open:a,onOpenChange:n,item:i}=t,{t:r}=nt(),l=mn(Qm),u=mn(Ym),[g,x]=o.useState("user"),[d,v]=o.useState("opencode"),c=qs(Xm),N=qs(Zm),[b,C]=o.useState(null),[k,A]=o.useState(!1);let h;e[0]===Symbol.for("react.memo_cache_sentinel")?(h=[],e[0]=h):h=e[0];const[E,F]=o.useState(h),[I,w]=o.useState(null);let m,y;e[1]!==N||e[2]!==a?(m=()=>{a&&(x("user"),v("opencode"),C(N),A(!1),F([]),w(null))},y=[a,N],e[1]=N,e[2]=a,e[3]=m,e[4]=y):(m=e[3],y=e[4]),o.useEffect(m,y);let U;e[5]!==r?(U=xe=>{switch(xe){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]=U):U=e[6];const S=U;let M;e[7]!==r?(M=xe=>{switch(xe){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]=M):M=e[8];const j=M;let R;e:{if(c.length===0){R=null;break e}if(b&&c.some(xe=>xe.id===b)){R=b;break e}if(N&&c.some(xe=>xe.id===N)){R=N;break e}R=c[0]?.id??null}const H=R;let P;e:{if(g!=="project"){P=null;break e}const xe=H;if(!xe){P=null;break e}let He;if(e[9]!==xe||e[10]!==c){let Ie;e[12]!==xe?(Ie=Le=>Le.id===xe,e[12]=xe,e[13]=Ie):Ie=e[13],He=c.find(Ie),e[9]=xe,e[10]=c,e[11]=He}else He=e[11];P=He?.path??null}const G=P;let J;e[14]!==l||e[15]!==i?.gitIdentityId||e[16]!==n||e[17]!==r?(J=async xe=>{const He=await l({source:xe.source,subpath:xe.subpath,gitIdentityId:i?.gitIdentityId,scope:xe.scope,targetSource:xe.targetSource,selections:[{skillDir:xe.skillDir}],conflictPolicy:"prompt",conflictDecisions:xe.conflictDecisions},{directory:xe.directoryOverride??null});if(He.ok){D.success(r("settings.skills.catalog.installSkill.toast.installed")),n(!1);return}if(He.error?.kind==="conflicts"){w({source:xe.source,subpath:xe.subpath,scope:xe.scope,targetSource:xe.targetSource,skillDir:xe.skillDir,directoryOverride:xe.directoryOverride??null}),F(He.error.conflicts),A(!0);return}if(He.error?.kind==="authRequired"){D.error(He.error.message||r("settings.skills.catalog.installSkill.toast.authRequired"));return}D.error(He.error?.message||r("settings.skills.catalog.installSkill.toast.installFailed"))},e[14]=l,e[15]=i?.gitIdentityId,e[16]=n,e[17]=r,e[18]=J):J=e[18];const T=J;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 X;e[21]!==W?(X=s.jsx(Ut,{children:W}),e[21]=W,e[22]=X):X=e[22];let K;e[23]!==r?(K=r("settings.skills.catalog.installSkill.descriptionPrefix"),e[23]=r,e[24]=K):K=e[24];let te;e[25]!==i.skillName?(te=s.jsx("span",{className:"font-semibold text-foreground",children:i.skillName}),e[25]=i.skillName,e[26]=te):te=e[26];let $;e[27]!==r?($=r("settings.skills.catalog.installSkill.descriptionSuffix"),e[27]=r,e[28]=$):$=e[28];let V;e[29]!==K||e[30]!==te||e[31]!==$?(V=s.jsxs(zt,{children:[K," ",te," ",$]}),e[29]=K,e[30]=te,e[31]=$,e[32]=V):V=e[32];let _;e[33]!==X||e[34]!==V?(_=s.jsxs(Kt,{children:[X,V]}),e[33]=X,e[34]=V,e[35]=_):_=e[35];let z;e[36]!==r?(z=r("settings.skills.catalog.installSkill.field.destination"),e[36]=r,e[37]=z):z=e[37];let Z;e[38]!==z?(Z=s.jsx("span",{className:"typography-ui-label text-foreground",children:z}),e[38]=z,e[39]=Z):Z=e[39];let Y;e[40]!==g||e[41]!==d?(Y=Oa(g,d),e[40]=g,e[41]=d,e[42]=Y):Y=e[42];let se;e[43]===Symbol.for("react.memo_cache_sentinel")?(se=xe=>{const He=Ll(xe);x(He.scope),v(He.source==="agents"?"agents":"opencode")},e[43]=se):se=e[43];let ge;e[44]!==g?(ge=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"}),e[44]=g,e[45]=ge):ge=e[45];let ce;e[46]!==d?(ce=d==="agents"?s.jsx(L,{name:"robot-2",className:"h-3.5 w-3.5"}):null,e[46]=d,e[47]=ce):ce=e[47];let be;e[48]!==S||e[49]!==g||e[50]!==d?(be=S(Oa(g,d)),e[48]=S,e[49]=g,e[50]=d,e[51]=be):be=e[51];let ne;e[52]!==be?(ne=s.jsx("span",{children:be}),e[52]=be,e[53]=ne):ne=e[53];let ae;e[54]!==ge||e[55]!==ce||e[56]!==ne?(ae=s.jsxs(Et,{className:"w-fit gap-1.5",children:[ge,ce,ne]}),e[54]=ge,e[55]=ce,e[56]=ne,e[57]=ae):ae=e[57];let me;e[58]!==j||e[59]!==S?(me=fr.map(xe=>s.jsx(ot,{value:xe.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:[xe.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"}),xe.source==="agents"?s.jsx(L,{name:"robot-2",className:"h-3.5 w-3.5"}):null,s.jsx("span",{children:S(xe.value)})]}),s.jsx("span",{className:"typography-micro text-muted-foreground ml-5",children:j(xe.value)})]})},xe.value)),e[58]=j,e[59]=S,e[60]=me):me=e[60];let Pe;e[61]!==me?(Pe=s.jsx(Tt,{align:"start",children:me}),e[61]=me,e[62]=Pe):Pe=e[62];let Ne;e[63]!==Y||e[64]!==ae||e[65]!==Pe?(Ne=s.jsxs(At,{value:Y,onValueChange:se,children:[ae,Pe]}),e[63]=Y,e[64]=ae,e[65]=Pe,e[66]=Ne):Ne=e[66];let Se;e[67]!==Z||e[68]!==Ne?(Se=s.jsxs("div",{className:"flex flex-wrap items-center gap-2",children:[Z,Ne]}),e[67]=Z,e[68]=Ne,e[69]=Se):Se=e[69];let je;e[70]!==c||e[71]!==H||e[72]!==g||e[73]!==r?(je=g==="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")}),c.length===0?s.jsx("span",{className:"typography-meta text-muted-foreground",children:r("settings.skills.catalog.installSkill.field.noProjects")}):s.jsxs(At,{value:H??"",onValueChange:xe=>C(xe),disabled:c.length===1,children:[s.jsx(Et,{className:"w-fit",children:s.jsx(Ft,{placeholder:r("settings.skills.catalog.installSkill.field.chooseProjectPlaceholder")})}),s.jsx(Tt,{align:"start",children:c.map(eu)})]})]}),e[70]=c,e[71]=H,e[72]=g,e[73]=r,e[74]=je):je=e[74];let Me;e[75]!==i.warnings?(Me=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]=Me):Me=e[76];let Re;e[77]!==Se||e[78]!==je||e[79]!==Me?(Re=s.jsxs("div",{className:"mt-2 space-y-3",children:[Se,je,Me]}),e[77]=Se,e[78]=je,e[79]=Me,e[80]=Re):Re=e[80];let re;e[81]!==n?(re=()=>n(!1),e[81]=n,e[82]=re):re=e[82];let fe;e[83]!==r?(fe=r("settings.common.actions.cancel"),e[83]=r,e[84]=fe):fe=e[84];let Ee;e[85]!==re||e[86]!==fe?(Ee=s.jsx(B,{size:"sm",variant:"ghost",onClick:re,children:fe}),e[85]=re,e[86]=fe,e[87]=Ee):Ee=e[87];const Be=u||!i.installable||g==="project"&&!G;let Ve;e[88]!==G||e[89]!==T||e[90]!==i.repoSource||e[91]!==i.repoSubpath||e[92]!==i.skillDir||e[93]!==g||e[94]!==d?(Ve=()=>{T({source:i.repoSource,subpath:i.repoSubpath,scope:g,targetSource:d,skillDir:i.skillDir,directoryOverride:G})},e[88]=G,e[89]=T,e[90]=i.repoSource,e[91]=i.repoSubpath,e[92]=i.skillDir,e[93]=g,e[94]=d,e[95]=Ve):Ve=e[95];let Ge;e[96]!==u||e[97]!==r?(Ge=r(u?"settings.skills.catalog.installSkill.actions.installing":"settings.skills.catalog.installSkill.actions.install"),e[96]=u,e[97]=r,e[98]=Ge):Ge=e[98];let Ke;e[99]!==Be||e[100]!==Ve||e[101]!==Ge?(Ke=s.jsx(B,{size:"sm",disabled:Be,onClick:Ve,children:Ge}),e[99]=Be,e[100]=Ve,e[101]=Ge,e[102]=Ke):Ke=e[102];let oe;e[103]!==Ee||e[104]!==Ke?(oe=s.jsxs(es,{children:[Ee,Ke]}),e[103]=Ee,e[104]=Ke,e[105]=oe):oe=e[105];let ie;e[106]!==_||e[107]!==Re||e[108]!==oe?(ie=s.jsxs(Ot,{className:"max-w-md",children:[_,Re,oe]}),e[106]=_,e[107]=Re,e[108]=oe,e[109]=ie):ie=e[109];let ye;e[110]!==n||e[111]!==a||e[112]!==ie?(ye=s.jsx(Rt,{open:a,onOpenChange:n,children:ie}),e[110]=n,e[111]=a,e[112]=ie,e[113]=ye):ye=e[113];let ve;e[114]!==I||e[115]!==T?(ve=xe=>{I&&(T({source:I.source,subpath:I.subpath,scope:I.scope,targetSource:I.targetSource,skillDir:I.skillDir,conflictDecisions:xe,directoryOverride:I.directoryOverride??null}),A(!1))},e[114]=I,e[115]=T,e[116]=ve):ve=e[116];let Oe;e[117]!==E||e[118]!==k||e[119]!==ve?(Oe=s.jsx(Wm,{open:k,onOpenChange:A,conflicts:E,onConfirm:ve}),e[117]=E,e[118]=k,e[119]=ve,e[120]=Oe):Oe=e[120];let Te;return e[121]!==ye||e[122]!==Oe?(Te=s.jsxs(s.Fragment,{children:[ye,Oe]}),e[121]=ye,e[122]=Oe,e[123]=Te):Te=e[123],Te};function Qm(t){return t.installSkills}function Ym(t){return t.isInstalling}function Xm(t){return t.projects}function Zm(t){return t.activeProjectId}function eu(t){return s.jsx(ot,{value:t.id,children:t.label||t.path},t.id)}const tu=/^[A-Za-z0-9_.-]+\/[A-Za-z0-9_.-]+$/,su=t=>{const e=t.trim();return tu.test(e)?`https://github.com/${e}`:null},nu=t=>{const e=su(t.repoSource);if(!e)return null;const a=[t.repoSubpath,t.skillDir].filter(Boolean).join("/");return a?`${e}/tree/HEAD/${a}`:e};let Za=null;const au=t=>{const e=ur();return(!Za||Za.locale!==e)&&(Za={locale:e,formatter:new Intl.NumberFormat(e,{notation:"compact"})}),Za.formatter.format(t)},iu=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)}},ru=async()=>{try{const t=Pn()?.settings;if(t)return(await t.load())?.settings||{};const e=await rt("/api/config/settings",{method:"GET",headers:{Accept:"application/json"}});return e.ok?await e.json().catch(()=>null):null}catch{return null}},ou=t=>{const e=lt.c(50),{source:a,isActive:n,isLoading:i,skillsCount:r,onSelect:l,t:u}=t,g=a.stars??null;let x,d,v,c,N,b,C,k,A,h;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]!==g||e[8]!==u){const w=a.repoUpdatedAt?iu(a.repoUpdatedAt):null;k="button",A=l,h=n;const m=n?"border-primary":"border-[var(--surface-subtle)] hover:border-[var(--interactive-border-hover)]";e[19]!==m?(d=we("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]=d):d=e[20],N="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 U;e[23]!==i||e[24]!==r||e[25]!==u?(U=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:u("settings.skills.catalog.page.source.skillsCount",{count:r})}),e[23]=i,e[24]=r,e[25]=u,e[26]=U):U=e[26],e[27]!==y||e[28]!==U?(b=s.jsxs("span",{className:"flex items-center gap-2",children:[y,U]}),e[27]=y,e[28]=U,e[29]=b):b=e[29],e[30]!==a.source?(C=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]=C):C=e[31],x="flex items-center gap-3 mt-1",e[32]!==g||e[33]!==u?(v=g!==null&&s.jsxs("span",{className:"typography-micro text-muted-foreground flex items-center gap-1",title:u("settings.skills.catalog.page.source.stars",{count:g}),children:[s.jsx(L,{name:"star",className:"h-3 w-3"}),au(g)]}),e[32]=g,e[33]=u,e[34]=v):v=e[34],c=w&&s.jsx("span",{className:"typography-micro text-muted-foreground",children:w.key==="common.relative.justNow"?u(w.key):u("settings.skills.catalog.page.source.updated",{time:u(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]=g,e[8]=u,e[9]=x,e[10]=d,e[11]=v,e[12]=c,e[13]=N,e[14]=b,e[15]=C,e[16]=k,e[17]=A,e[18]=h}else x=e[9],d=e[10],v=e[11],c=e[12],N=e[13],b=e[14],C=e[15],k=e[16],A=e[17],h=e[18];let E;e[35]!==x||e[36]!==v||e[37]!==c?(E=s.jsxs("span",{className:x,children:[v,c]}),e[35]=x,e[36]=v,e[37]=c,e[38]=E):E=e[38];let F;e[39]!==E||e[40]!==N||e[41]!==b||e[42]!==C?(F=s.jsxs("span",{className:N,children:[b,C,E]}),e[39]=E,e[40]=N,e[41]=b,e[42]=C,e[43]=F):F=e[43];let I;return e[44]!==d||e[45]!==F||e[46]!==k||e[47]!==A||e[48]!==h?(I=s.jsx("button",{type:k,onClick:A,"aria-pressed":h,className:d,children:F}),e[44]=d,e[45]=F,e[46]=k,e[47]=A,e[48]=h,e[49]=I):I=e[49],I},lu=({mode:t,onModeChange:e,showModeTabs:a=!0})=>{const{t:n}=nt(),{sources:i,itemsBySource:r,selectedSourceId:l,setSelectedSource:u,loadCatalog:g,loadSource:x,isLoadingCatalog:d,isLoadingSource:v,loadedSourceIds:c,lastCatalogError:N}=mn(Ds(T=>({sources:T.sources,itemsBySource:T.itemsBySource,selectedSourceId:T.selectedSourceId,setSelectedSource:T.setSelectedSource,loadCatalog:T.loadCatalog,loadSource:T.loadSource,isLoadingCatalog:T.isLoadingCatalog,isLoadingSource:T.isLoadingSource,loadedSourceIds:T.loadedSourceIds,lastCatalogError:T.lastCatalogError}))),[b,C]=o.useState(""),[k,A]=o.useState(!1),[h,E]=o.useState(!1),[F,I]=o.useState(null),[w,m]=o.useState(!1),[y,U]=o.useState(!1),S=o.useRef(null);o.useEffect(()=>{g()},[g]),o.useEffect(()=>{const T=i.filter(K=>!c[K.id]);if(T.length===0)return;let W=!1;return(async()=>{for(const K of T){if(W)return;await x(K.id)}})(),()=>{W=!0}},[i,c,x]),o.useEffect(()=>{!l||c[l]||x(l)},[l,c,x]),o.useEffect(()=>{const T=W=>{(W.metaKey||W.ctrlKey)&&W.key.toLowerCase()==="k"&&(W.preventDefault(),S.current?.focus())};return window.addEventListener("keydown",T),()=>window.removeEventListener("keydown",T)},[]);const M=b.trim().length>0,j=o.useMemo(()=>M?li(i.flatMap(T=>r[T.id]||[]),b,T=>[T.skillName,T.frontmatterName,T.description]):l?r[l]||[]:[],[i,r,l,b,M]),R=o.useMemo(()=>i.find(T=>T.id===l)||null,[i,l]),H=!!(l&&l.startsWith("custom:")),P=async()=>{if(!(!l||!H)){m(!0);try{const T=await ru(),X=(Array.isArray(T?.skillCatalogs)?T?.skillCatalogs:[]).filter(K=>K.id!==l);await xt({skillCatalogs:X}),await g({refresh:!0}),U(!1)}finally{m(!1)}}},G=M?n("settings.skills.catalog.page.list.searchTitle"):R?.label??"",J=!M&&l!==null&&!c[l]&&(v||d);return s.jsxs(s.Fragment,{children:[s.jsxs(ns,{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:T=>e(T),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(We,{ref:S,value:b,onChange:T=>C(T.target.value),placeholder:n("settings.skills.catalog.page.searchAllPlaceholder"),className:we("h-8 pl-8 w-full",b&&"pr-8")}),b&&s.jsx("button",{type:"button",onClick:()=>{C(""),S.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($e,{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(T=>s.jsx(ou,{source:T,isActive:T.id===l,isLoading:v&&!c[T.id],skillsCount:c[T.id]?(r[T.id]||[]).length:null,onSelect:()=>u(T.id),t:n},T.id)),s.jsxs("button",{type:"button","data-settings-item":"skills.catalog.add-catalog",onClick:()=>A(!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")})]})]})]})}),N&&s.jsx($e,{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:N.message})]})}),s.jsxs($e,{children:[s.jsxs("div",{className:"flex items-center justify-between gap-2 pb-2",children:[s.jsxs("div",{className:"flex items-center gap-2 min-w-0",children:[s.jsx("span",{className:"typography-micro font-medium uppercase tracking-wide text-muted-foreground truncate",children:G}),s.jsx("span",{className:"typography-micro text-muted-foreground/70 shrink-0",children:n("settings.skills.catalog.page.foundCount",{count: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&&!M?x(l,{refresh:!0}):g({refresh:!0})},disabled:d||v,title:n("settings.skills.catalog.page.actions.refreshTitle"),children:s.jsx(L,{name:"refresh",className:we("h-3.5 w-3.5",(d||v)&&"animate-spin")})}),H&&!M&&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:()=>U(!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"})})]})]}),J||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(T=>{const W=T.installed?.isInstalled,X=T.installed?.scope,K=nu(T);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:T.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:X||n("settings.skills.catalog.page.badge.unknown")})}),!T.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")})]}),T.description?s.jsx("div",{className:"typography-meta text-muted-foreground mt-0.5 line-clamp-2",children:T.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:[K?s.jsxs("a",{href:K,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"}),T.repoSource]}):s.jsx("span",{className:"font-mono truncate",children:T.repoSource}),T.skillDir&&s.jsxs(s.Fragment,{children:[s.jsx("span",{className:"opacity-40",children:"·"}),s.jsx("span",{className:"truncate",children:T.skillDir})]})]}),T.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:T.warnings.join(" · ")}):null]}),s.jsxs("div",{className:"flex items-center gap-1.5 shrink-0",children:[K&&s.jsx(B,{variant:"ghost",size:"xs",className:"!font-normal h-6 w-6 px-0",onClick:()=>window.open(K,"_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:X||""}),children:s.jsx(L,{name:"check",className:"h-4 w-4"})}):s.jsx(B,{variant:"outline",size:"xs",className:"!font-normal",disabled:!T.installable,onClick:()=>{I(T),E(!0)},children:n("settings.skills.catalog.shared.actions.install")})]})]})},`${T.sourceId}:${T.skillDir}`)})})]})]}),s.jsx(Um,{open:k,onOpenChange:A}),s.jsx(Jm,{open:h,onOpenChange:E,item:F}),s.jsx(Rt,{open:y,onOpenChange:T=>{w||U(T)},children:s.jsxs(Ot,{className:"max-w-md",children:[s.jsxs(Kt,{children:[s.jsx(Ut,{children:n("settings.skills.catalog.page.removeDialog.title")}),s.jsx(zt,{children:n("settings.skills.catalog.page.removeDialog.description")})]}),s.jsxs(es,{children:[s.jsx(B,{size:"sm",variant:"ghost",onClick:()=>U(!1),disabled:w,children:n("settings.common.actions.cancel")}),s.jsx(B,{size:"sm",variant:"destructive",onClick:()=>{P()},disabled:w,children:n("settings.skills.catalog.page.actions.removeCatalog")})]})]})})]})},cu=()=>{const t=lt.c(1);let e;return t[0]===Symbol.for("react.memo_cache_sentinel")?(e=s.jsx(lu,{mode:"external",onModeChange:hu,showModeTabs:!1}),t[0]=e):e=t[0],e},du="SKILL.md",pu="h-[clamp(320px,58dvh,680px)] min-h-[260px] max-h-[calc(100dvh-220px)]",ii=(t,e)=>{const a=Fd({description:t}).trimEnd(),n=e.trimStart();return`---
|
|
22
|
+
${a}
|
|
23
|
+
---${n?`
|
|
24
|
+
|
|
25
|
+
${n}`:`
|
|
26
|
+
`}`},mu=t=>typeof t=="object"&&t!==null&&!Array.isArray(t),Fl=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=Kd(e[1]);if(mu(n)){const i=n.description;typeof i=="string"&&(a=i)}}catch{a=null}return{description:a,instructions:e[2].replace(/^\r?\n/,"")}},uu=(t,e)=>{const a=Fl(t);return ii(e,a.instructions)},gu=()=>{const{t}=nt(),{currentTheme:e}=gr(),{selectedSkillName:a,getSkillByName:n,getSkillDetail:i,createSkill:r,updateSkill:l,skillDraft:u,setSkillDraft:g,setSelectedSkill:x}=$s(Ds(ue=>({selectedSkillName:ue.selectedSkillName,getSkillByName:ue.getSkillByName,getSkillDetail:ue.getSkillDetail,createSkill:ue.createSkill,updateSkill:ue.updateSkill,skillDraft:ue.skillDraft,setSkillDraft:ue.setSkillDraft,setSelectedSkill:ue.setSelectedSkill}))),d=zs(),v=$s(ue=>cr(ue,d)),c=a?n(a,d):null,N=!!(u&&u.name===a&&!c),b=!!(a&&!c&&!u),C=c?.path==="<built-in>";o.useEffect(()=>{b&&x(null)},[b,x]);const[k,A]=o.useState(""),[h,E]=o.useState("user"),[F,I]=o.useState("opencode"),[w,m]=o.useState(""),[y,U]=o.useState(""),[S,M]=o.useState(()=>ii("","")),[j,R]=o.useState("edit"),[H,P]=o.useState([]),[G,J]=o.useState([]),[T,W]=o.useState(!1),[X,K]=o.useState(!1),[te,$]=o.useState(""),[V,_]=o.useState(""),[z,Z]=o.useState(!1),[Y,se]=o.useState(""),[ge,ce]=o.useState(""),[be,ne]=o.useState(null),[ae,me]=o.useState(!1),[Pe,Ne]=o.useState(""),[Se,je]=o.useState(null),[Me,Re]=o.useState(!1),re=N?k.trim()!==""||w.trim()!==""||y.trim()!==""||G.length>0:w!==te||y!==V,fe=be?ge!==Pe:Y.trim()!=="",Ee=o.useCallback(ue=>{switch(ue){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]),Be=o.useCallback(ue=>{switch(ue){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(N&&u){const Ie=u.description||"",Le=u.instructions||"";A(u.name||""),E(u.scope||"user"),I(u.source==="agents"?"agents":"opencode"),m(Ie),U(Le),M(ii(Ie,Le)),$(""),_(""),P([]),J(u.pendingFiles||[])}else if(a&&c){K(!0);try{const Ie=await i(a,d);if(Ie){const Le=Ie.sources.md,Ye=Le.description||"",q=Le.instructions||"";m(Ye),U(q),M(ii(Ye,q)),$(Ye),_(q),P(Le.supportingFiles||[])}}catch(Ie){console.error("Failed to load skill details:",Ie)}finally{K(!1)}}})()},[c,N,a,d,v,u,i]);const Ve=de(ue=>ue.editorFontSize),Ge=o.useMemo(()=>{const ue=[Gr(e,{fontSize:Ve})],Ie=Pr(du);return Ie&&ue.push(Ie),ue.push(Wr.lineWrapping),ue},[e,Ve]),Ke=o.useMemo(()=>{const ue=Y.trim()||"supporting-file.md",Ie=hc(ue),Le=!!Ie&&Ie!=="markdown",Ye=[Gr(e,Le?{syntaxColors:!1,fontSize:Ve}:{fontSize:Ve})],q=Pr(ue);return q&&Ye.push(q),Le&&Ie&&Ye.push(Ud({language:Ie,themeName:e.metadata.id,theme:_d(e)})),Ye.push(Wr.lineWrapping),Ye},[e,Y,Ve]),oe=o.useCallback(ue=>{m(ue),M(Ie=>uu(Ie,ue))},[]),ie=o.useCallback(ue=>{M(ue);const Ie=Fl(ue);m(Ie.description??""),U(Ie.instructions)},[]),ye=async()=>{const ue=N?k.trim().replace(/\s+/g,"-").toLowerCase():a?.trim();if(!ue){D.error(t("settings.skills.page.toast.skillNameRequired"));return}if(!/^[a-z0-9][a-z0-9-]*[a-z0-9]$|^[a-z0-9]$/.test(ue)||ue.length>64){D.error(t("settings.skills.page.toast.invalidSkillName"));return}if(!w.trim()){D.error(t("settings.skills.page.toast.descriptionRequired"));return}if(N&&v.some(Ie=>Ie.name===ue)){D.error(t("settings.skills.page.toast.skillExists"));return}W(!0);try{const Ie={name:ue,description:w.trim(),instructions:y.trim()||void 0,scope:N?h:void 0,source:N?F:void 0,targetPath:N?void 0:c?.path,supportingFiles:N&&G.length>0?G:void 0};let Le;if(N?(Le=await r(Ie,d),Le&&(g(null),J([]),x(ue))):(Le=await l(ue,Ie,d),Le&&($(w.trim()),_(y.trim()))),Le){const Ye=gn.getState().changes.some(q=>q.scope==="skills"&&q.id.startsWith(`skills:${ue}:`));D.success(t(Ye?"settings.view.pendingRestart.saved":N?"settings.skills.page.toast.skillCreated":"settings.skills.page.toast.skillUpdated"))}else D.error(t(N?"settings.skills.page.toast.createSkillFailed":"settings.skills.page.toast.updateSkillFailed"))}catch(Ie){console.error("Error saving skill:",Ie),D.error(t("settings.skills.page.toast.saveUnexpectedError"))}finally{W(!1)}},ve=()=>{ne(null),se(""),ce(""),Ne(""),Z(!0)},Oe=async ue=>{if(ne(ue),se(ue),N){const Le=G.find(Ye=>Ye.path===ue)?.content||"";ce(Le),Ne(Le),Z(!0);return}if(a){me(!0),Z(!0);try{const{readSupportingFile:Ie}=$s.getState(),Le=await Ie(a,ue,d);ce(Le||""),Ne(Le||"")}catch{D.error(t("settings.skills.page.toast.loadFileContentFailed")),ce(""),Ne("")}finally{me(!1)}}},Te=async()=>{if(!Y.trim()){D.error(t("settings.skills.page.toast.fileNameRequired"));return}const ue=Y.trim(),Ie=be!==null;if(N){if(Ie)J(q=>q.map(ke=>ke.path===be?{path:ue,content:ge}:ke)),D.success(t("settings.skills.page.toast.fileUpdated",{path:ue}));else{if(G.some(q=>q.path===ue)){D.error(t("settings.skills.page.toast.fileExists"));return}J(q=>[...q,{path:ue,content:ge}]),D.success(t("settings.skills.page.toast.fileAdded",{path:ue}))}Z(!1),ne(null);return}if(!a){D.error(t("settings.skills.page.toast.noSkillSelected"));return}const{writeSupportingFile:Le}=$s.getState();if(await Le(a,ue,ge,d)){D.success(Ie?t("settings.skills.page.toast.fileUpdated",{path:ue}):t("settings.skills.page.toast.fileCreated",{path:ue})),Z(!1),ne(null);const q=await i(a,d);q&&P(q.sources.md.supportingFiles||[])}else D.error(t(Ie?"settings.skills.page.toast.updateFileFailed":"settings.skills.page.toast.createFileFailed"))},xe=ue=>{if(N){J(Ie=>Ie.filter(Le=>Le.path!==ue)),D.success(t("settings.skills.page.toast.fileRemoved",{path:ue}));return}a&&je(ue)},He=async()=>{if(!Se||!a)return;Re(!0);const{deleteSupportingFile:ue}=$s.getState();if(await ue(a,Se,d)){D.success(t("settings.skills.page.toast.fileDeleted",{path:Se}));const Le=await i(a,d);Le&&P(Le.sources.md.supportingFiles||[]),je(null)}else D.error(t("settings.skills.page.toast.deleteFileFailed"));Re(!1)};return!a&&!u||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")})]})}):X?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(ns,{title:N?t("settings.skills.page.title.newSkill"):a,description:c?t("settings.skills.page.subtitle.skillLocation",{location:Ee(Oa(c.scope,c.source))}):t("settings.skills.page.subtitle.newSkill"),showSaveStatus:!1,children:[s.jsxs($e,{title:t("settings.skills.page.section.basicInformation"),divider:!1,settingsItem:"skills.basic-information",contentClassName:"space-y-0",children:[N&&s.jsxs(Vt,{label:t("settings.skills.page.field.skillNameLocation"),info:t("settings.skills.page.field.skillNameHint"),children:[s.jsx(We,{value:k,onChange:ue=>A(ue.target.value.toLowerCase().replace(/\s+/g,"-")),placeholder:t("settings.skills.page.field.skillNamePlaceholder"),className:"h-7 w-40 px-2"}),s.jsxs(At,{value:Oa(h,F),onValueChange:ue=>{const Ie=Ll(ue);E(Ie.scope),I(Ie.source==="agents"?"agents":"opencode")},children:[s.jsxs(Et,{size:$t,className:"w-fit gap-1.5",children:[h==="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"}),F==="agents"?s.jsx(L,{name:"robot-2",className:"h-3.5 w-3.5"}):null,s.jsx("span",{children:Ee(Oa(h,F))})]}),s.jsx(Tt,{align:"start",children:fr.map(ue=>s.jsx(ot,{value:ue.value,children:s.jsxs("div",{className:"flex flex-col gap-0.5",children:[s.jsxs("div",{className:"flex items-center gap-2",children:[ue.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"}),ue.source==="agents"?s.jsx(L,{name:"robot-2",className:"h-3.5 w-3.5"}):null,s.jsx("span",{children:Ee(ue.value)})]}),s.jsx("span",{className:"typography-micro text-muted-foreground ml-6",children:Be(ue.value)})]})},ue.value))})]})]}),s.jsx(Wt,{label:s.jsxs(s.Fragment,{children:[t("settings.common.field.description")," ",s.jsx("span",{className:"text-[var(--status-error)]",children:"*"})]}),info:t("settings.skills.page.field.descriptionHint"),controlClassName:"w-full max-w-none",children:s.jsx(Is,{value:w,onChange:ue=>oe(ue.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:C})})]}),s.jsx($e,{title:t("settings.skills.page.section.instructions"),headerAction:s.jsx(zd,{currentMode:j==="preview"?"preview":"edit",onToggle:()=>R(ue=>ue==="preview"?"edit":"preview")}),settingsItem:"skills.instructions",children:s.jsx("div",{className:we("overflow-hidden rounded-md border border-[var(--surface-subtle)] bg-background",pu),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(fc,{content:S,className:"typography-markdown-body",stripFrontmatter:!0,enableFileReferences:!1})})}):s.jsx(qr,{value:S,onChange:ie,readOnly:C,extensions:Ge,className:"h-full",enableSearch:!0})})}),s.jsx($e,{title:t("settings.skills.page.section.supportingFiles"),headerAction:s.jsxs(B,{variant:"outline",size:"xs",className:"!font-normal gap-1",onClick:ve,disabled:C,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 ue=N?G:H;return ue.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:ue.map(Ie=>s.jsxs("div",{className:"flex items-center gap-2 py-1.5 cursor-pointer group",onClick:()=>Oe(Ie.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:Ie.path}),N&&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")}),!C&&s.jsx(B,{size:"sm",variant:"ghost",className:"h-5 w-5 px-0 flex-shrink-0 text-muted-foreground hover:text-[var(--status-error)] opacity-0 group-hover:opacity-100 transition-opacity",onClick:Le=>{Le.stopPropagation(),xe(Ie.path)},children:s.jsx(L,{name:"delete-bin",className:"h-3 w-3"})})]},Ie.path))})})()}),s.jsx($e,{children:s.jsx(B,{onClick:ye,disabled:C||T||!re,size:"xs",className:"!font-normal",children:t(T?"settings.common.actions.saving":N?"settings.skills.page.actions.createSkill":"settings.common.actions.saveChanges")})})]}),s.jsx(Rt,{open:Se!==null,onOpenChange:ue=>{!ue&&!Me&&je(null)},children:s.jsxs(Ot,{className:"max-w-md",children:[s.jsxs(Kt,{children:[s.jsx(Ut,{children:t("settings.skills.page.deleteFileDialog.title")}),s.jsx(zt,{children:t("settings.skills.page.deleteFileDialog.description",{path:Se??""})})]}),s.jsxs(es,{children:[s.jsx(B,{size:"sm",variant:"ghost",onClick:()=>je(null),disabled:Me,children:t("settings.common.actions.cancel")}),s.jsx(B,{size:"sm",variant:"destructive",onClick:He,disabled:Me,children:t("settings.common.actions.delete")})]})]})}),s.jsx(Rt,{open:z,onOpenChange:ue=>{Z(ue),ue||ne(null)},children:s.jsxs(Ot,{className:"max-w-3xl max-h-[85vh] flex flex-col",children:[s.jsxs(Kt,{className:"flex-shrink-0",children:[s.jsx(Ut,{children:t(be?"settings.skills.page.fileDialog.titleEdit":"settings.skills.page.fileDialog.titleAdd")}),s.jsx(zt,{children:t(be?"settings.skills.page.fileDialog.descriptionEdit":"settings.skills.page.fileDialog.descriptionAdd")})]}),ae?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:It,children:t("settings.skills.page.fileDialog.field.filePath")}),!be&&s.jsx(Jt,{children:t("settings.skills.page.fileDialog.field.filePathHint")})]}),s.jsx(We,{value:Y,onChange:ue=>se(ue.target.value),placeholder:t("settings.skills.page.fileDialog.field.filePathPlaceholder"),className:"text-foreground placeholder:text-muted-foreground focus-visible:ring-[var(--primary-base)]",disabled:be!==null})]}),s.jsxs("div",{className:"space-y-2 flex-1 min-h-0 flex flex-col",children:[s.jsx("label",{className:`${It} 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:ge,onChange:ce,extensions:Ke,className:"h-full",enableSearch:!0})})]})]}),s.jsxs(es,{className:"mt-4",children:[s.jsx(B,{size:"sm",variant:"ghost",onClick:()=>{Z(!1),ne(null)},children:t("settings.common.actions.cancel")}),s.jsx(B,{size:"sm",onClick:Te,disabled:ae||!fe,children:t(be?"settings.common.actions.saveChanges":"settings.skills.page.actions.createFile")})]})]})})]})},po=t=>{const e=lt.c(2),{view:a}=t,n=a===void 0?"installed":a;let i;return e[0]!==n?(i=n==="catalog"?s.jsx(cu,{}):s.jsx(gu,{}),e[0]=n,e[1]=i):i=e[1],i};function hu(){}const fu=t=>{const e=lt.c(38),{onItemSelect:a}=t,{t:n}=nt(),i=qs(xu),r=de(bu),l=de(vu),{currentTheme:u}=gr();let g;e[0]===Symbol.for("react.memo_cache_sentinel")?(g=ps(),e[0]=g):g=e[0];const x=g,d=yu;let v,c;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)},c=[i,r,l],e[1]=i,e[2]=r,e[3]=l,e[4]=v,e[5]=c):(v=e[4],c=e[5]),o.useEffect(v,c);let N;e[6]===Symbol.for("react.memo_cache_sentinel")?(N=we("border-b px-3","pt-4 pb-3"),e[6]=N):N=e[6];let b;e[7]!==n?(b=n("settings.page.projects.title"),e[7]=n,e[8]=b):b=e[8];let C;e[9]!==b?(C=s.jsx("h2",{className:`${nn} mb-3`,children:b}),e[9]=b,e[10]=C):C=e[10];let k;e[11]!==i.length||e[12]!==n?(k=n("settings.projects.sidebar.total",{count:i.length}),e[11]=i.length,e[12]=n,e[13]=k):k=e[13];let A;e[14]!==k?(A=s.jsx("span",{className:"typography-meta text-muted-foreground",children:k}),e[14]=k,e[15]=A):A=e[15];let h;e[16]!==n?(h=!x&&s.jsx(B,{type:"button",variant:"ghost",size:"icon",className:"h-7 w-7 -my-1 text-muted-foreground",onClick:d,"aria-label":n("settings.projects.sidebar.actions.addProject"),children:s.jsx(L,{name:"add",className:"size-4"})}),e[16]=n,e[17]=h):h=e[17];let E;e[18]!==A||e[19]!==h?(E=s.jsxs("div",{className:"flex items-center justify-between gap-2",children:[A,h]}),e[18]=A,e[19]=h,e[20]=E):E=e[20];let F;e[21]!==E||e[22]!==C?(F=s.jsxs("div",{className:N,children:[C,E]}),e[21]=E,e[22]=C,e[23]=F):F=e[23];let I;if(e[24]!==u||e[25]!==a||e[26]!==i||e[27]!==r||e[28]!==l){let m;e[30]!==u||e[31]!==a||e[32]!==r||e[33]!==l?(m=y=>{const U=y.id===r,S=y.icon?bc[y.icon]:null,M=y.color?vc[y.color]??null:null,j=S?s.jsx(L,{name:S,className:we("h-4 w-4",U?"text-foreground":"text-muted-foreground/70"),style:M?{color:M}:void 0}):s.jsx(L,{name:"folder",className:we("h-4 w-4",U?"text-foreground":"text-muted-foreground/70"),style:M?{color:M}: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(yc,{project:y,options:{themeVariant:u.metadata.variant,iconColor:u.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:U,onSelect:()=>{l(y.id),a?.()}},y.id)},e[30]=u,e[31]=a,e[32]=r,e[33]=l,e[34]=m):m=e[34],I=i.map(m),e[24]=u,e[25]=a,e[26]=i,e[27]=r,e[28]=l,e[29]=I}else I=e[29];let w;return e[35]!==F||e[36]!==I?(w=s.jsx(Rl,{variant:"background",header:F,children:I}),e[35]=F,e[36]=I,e[37]=w):w=e[37],w};function xu(t){return t.projects}function bu(t){return t.settingsProjectsSelectedId}function vu(t){return t.setSettingsProjectsSelectedId}function yu(){xc.requestDirectoryDialog()}const ju=()=>{const t=lt.c(30),{t:e}=nt(),a=qs(wu),n=qs(ku),i=de(Nu),r=de(Su);let l;e:{if(!i){l=null;break e}let k;t[0]!==a||t[1]!==i?(k=a.find(A=>A.id===i)??null,t[0]=a,t[1]=i,t[2]=k):k=t[2],l=k}const u=l;let g,x;t[3]!==a||t[4]!==i||t[5]!==r?(g=()=>{if(a.length===0){r(null);return}i&&a.some(k=>k.id===i)||r(a[0].id)},x=[a,i,r],t[3]=a,t[4]=i,t[5]=r,t[6]=g,t[7]=x):(g=t[6],x=t[7]),o.useEffect(g,x);let d;t[8]!==u||t[9]!==n?(d=async k=>{u&&n(u.id,{label:k.label,icon:k.icon,color:k.color,iconBackground:k.iconBackground,defaultModel:k.defaultModel??null,defaultVariant:k.defaultVariant??null})},t[8]=u,t[9]=n,t[10]=d):d=t[10];const v=d;if(!u){let k;t[11]!==e?(k=e("settings.page.projects.title"),t[11]=e,t[12]=k):k=t[12];let A;t[13]!==e?(A=e("settings.projects.page.empty.noProjects"),t[13]=e,t[14]=A):A=t[14];let h;t[15]!==A?(h=s.jsx("p",{className:"typography-meta text-muted-foreground",children:A}),t[15]=A,t[16]=h):h=t[16];let E;return t[17]!==k||t[18]!==h?(E=s.jsx(ns,{title:k,showSaveStatus:!0,children:h}),t[17]=k,t[18]=h,t[19]=E):E=t[19],E}let c;t[20]!==u.label||t[21]!==e?(c=u.label??e("settings.projects.page.title.default"),t[20]=u.label,t[21]=e,t[22]=c):c=t[22];const N=c;let b;t[23]!==v||t[24]!==u?(b=s.jsx(Td,{project:u,onIdentitySave:v}),t[23]=v,t[24]=u,t[25]=b):b=t[25];let C;return t[26]!==N||t[27]!==u.path||t[28]!==b?(C=s.jsx(ns,{title:N,description:u.path,showSaveStatus:!0,outerClassName:"bg-background",children:b}),t[26]=N,t[27]=u.path,t[28]=b,t[29]=C):C=t[29],C};function wu(t){return t.projects}function ku(t){return t.updateProjectMeta}function Nu(t){return t.settingsProjectsSelectedId}function Su(t){return t.setSettingsProjectsSelectedId}const ri=()=>Math.floor(2e4+Math.random()*3e4),Cu=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")},Pu=()=>{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"}},Iu=new Set(["config_resolved","auth_check","master_connecting","remote_probe","installing","updating","server_detecting","server_starting","forwarding"]),xr=t=>!!(t&&Iu.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"}},Au=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"},Eu=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",Tu=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}`,Du=()=>({id:`forward-${Date.now()}-${Math.random().toString(16).slice(2)}`,enabled:!0,type:"local",localHost:"127.0.0.1",localPort:ri(),remoteHost:"127.0.0.1",remotePort:80}),Mu=t=>t.trim().replace(/\*/g,"host").replace(/\?/g,"x")||"user@host",_s=t=>{const e=lt.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(Jt,{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 ${It}`,children:[i,r]}),e[4]=i,e[5]=r,e[6]=l):l=e[6],l},Ru=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}`},Ou=t=>{const e=(t||"").trim();return!e||e==="0.0.0.0"||e==="::"?"127.0.0.1":e},Lu=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}),Fu=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&&!Fu(n)&&(e[n]=i)}return Object.keys(e).length>0?e:void 0},Ku=t=>Object.entries(t||{}).map(([e,a])=>ar(e,a)),Kl=()=>{if(typeof window>"u")return null;const e=Ka()||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}},Uu=async()=>{const t=aa(Ka())||window.location.origin;if(!ds()||!Ua())return t;let e;try{e=await rt("/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 yl(),i=Kl();return!n||!i?t:`http://${n}:${i}`},ei=t=>{const e=t.trim();if(e)try{window.location.assign(e)}catch{window.location.href=e}},zu=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}},_u=()=>{const{t}=nt(),e=de(f=>f.timeFormatPreference),{clientAuth:a}=ml(),n=ds(),i=Cs(f=>f.instances),r=Cs(f=>f.statusesById),l=Cs(f=>f.importCandidates),u=Cs(f=>f.isLoading),g=Cs(f=>f.isImportsLoading),x=Cs(f=>f.isSaving),d=Cs(f=>f.error),v=Cs(f=>f.load),c=Cs(f=>f.loadImports),N=Cs(f=>f.refreshStatuses),b=Cs(f=>f.upsertInstance),C=Cs(f=>f.createFromCommand),k=Cs(f=>f.removeInstance),A=Cs(f=>f.connect),h=Cs(f=>f.disconnect),E=Cs(f=>f.retry),F=de(f=>f.settingsRemoteInstancesSelectedId),I=de(f=>f.setSettingsRemoteInstancesSelectedId),w=o.useMemo(()=>F&&i.find(f=>f.id===F)||null,[i,F]),[m,y]=o.useState(null),[U,S]=o.useState(!1),[M,j]=o.useState(!1),[R,H]=o.useState(null),[P,G]=o.useState([]),[J,T]=o.useState(null),[W,X]=o.useState(""),[K,te]=o.useState(!1),[$,V]=o.useState({}),[_,z]=o.useState(!1),[Z,Y]=o.useState(!1),[se,ge]=o.useState(()=>Date.now()),[ce,be]=o.useState([]),[ne,ae]=o.useState({}),[me,Pe]=o.useState("local"),[Ne,Se]=o.useState(!1),[je,Me]=o.useState(!1),[Re,re]=o.useState(""),[fe,Ee]=o.useState(""),[Be,Ve]=o.useState(""),[Ge,Ke]=o.useState([]),[oe,ie]=o.useState(""),[ye,ve]=o.useState(null),[Oe,Te]=o.useState(!1),[xe,He]=o.useState(!1),[ue,Ie]=o.useState(null),[Le,Ye]=o.useState(""),[q,ke]=o.useState(""),[O,Ce]=o.useState(""),[qe,_e]=o.useState([]),[tt,ht]=o.useState([]),[mt,ut]=o.useState([]),[ft,kt]=o.useState(!1),[vt,Ct]=o.useState(""),[Ze,Xe]=o.useState(null),[ct,Ue]=o.useState(null),[jt,Ae]=o.useState(null),[yt,Q]=o.useState(null),[he,ze]=o.useState(!1),[De,it]=o.useState(!1),[at,Je]=o.useState("configure"),[Nt,xs]=o.useState(!1),[ts,Ms]=o.useState("relay"),[Bt,os]=o.useState(!0),[qt,bs]=o.useState(null),ms=o.useMemo(()=>tt.filter(f=>!!f.revokedAt).length,[tt]),[vs,us]=o.useState(!1),[ys,le]=o.useState("saved"),[dt,bt]=o.useState(""),[Qt,Yt]=o.useState(""),[Ht,as]=o.useState(""),[js,ls]=o.useState(!1);o.useEffect(()=>{v(),c()},[v,c]);const St=o.useCallback(async()=>{Se(!0),ve(null);try{const f=await Lr();be(f.hosts||[]),Pe(f.defaultHostId||"local")}catch(f){ve(f instanceof Error?f.message:String(f))}finally{Se(!1)}},[]);o.useEffect(()=>{St()},[St]);const Pt=o.useCallback(async(f,ee=me)=>{Me(!0),ve(null);try{await Fr({hosts:f,defaultHostId:ee,initialHostChoiceCompleted:!0}),be(f),Pe(ee)}catch(Fe){ve(Fe instanceof Error?Fe.message:String(Fe))}finally{Me(!1)}},[me]),_t=o.useCallback(async()=>{const f=Kr(fe);if(!f){ve(t("desktopHostSwitcher.error.invalidUrl"));return}const ee=f.persistedUrl,st={id:typeof crypto<"u"&&typeof crypto.randomUUID=="function"?crypto.randomUUID():`host-${Date.now()}-${Math.random().toString(16).slice(2)}`,label:Re.trim()||wa(ee),url:ee,apiUrl:ee,...Be.trim()?{clientToken:Be.trim()}:{},...Fi(Ge)?{requestHeaders:Fi(Ge)}:{}};await Pt([st,...ce],me),re(""),Ee(""),Ve(""),Ke([]),Te(!1),f.redeemUrl&&ei(f.redeemUrl)},[me,Ge,ce,Re,Be,fe,Pt,t]),Mt=o.useCallback(async()=>{const f=id(oe);if(!f){ve(t("settings.remoteInstances.direct.error.invalidConnectLink"));return}const ee=await rd().catch(()=>""),Fe=JSON.stringify({pairingId:f.pairingId,secret:f.secret,clientLabel:f.label||"OpenChamber Desktop",clientKind:"desktop",deviceName:"OpenChamber Desktop",devicePlatform:Pu(),...ee?{dedupeKey:`desktop:${ee}`}:{}}),st={method:"POST",headers:{"Content-Type":"application/json",Accept:"application/json"},body:Fe},Lt=async Dt=>{if(!Dt.ok)return null;const Fs=await Dt.json().catch(()=>null);return(typeof Fs?.clientToken=="string"?Fs.clientToken.trim():"")||null},Es=[...f.candidates].sort((Dt,Fs)=>(Dt.type==="relay"?1:0)-(Fs.type==="relay"?1:0));let ks=null;for(const Dt of Es){if(Dt.type==="relay"){const ba=od({relayUrl:Dt.relayUrl,serverId:Dt.serverId,hostEncPubJwk:Dt.hostEncPubJwk,...Dt.grant?{grant:Dt.grant}:{}});try{const Ga=await ba.fetch("/api/client-auth/pairing/redeem",st),Sr=await Lt(Ga);if(Sr){ks={kind:"relay",relay:{relayUrl:Dt.relayUrl,serverId:Dt.serverId,hostEncPubJwk:Dt.hostEncPubJwk},token:Sr};break}}catch{}finally{ba.close()}continue}const Fs=aa(Dt.url);if(Fs)try{const ba=await fetch(`${Fs}/api/client-auth/pairing/redeem`,st),Ga=await Lt(ba);if(Ga){ks={kind:"direct",url:Fs,token:Ga};break}}catch{}}if(!ks){ve(t("desktopHostSwitcher.error.invalidUrl"));return}const Rs=()=>typeof crypto<"u"&&typeof crypto.randomUUID=="function"?crypto.randomUUID():`host-${Date.now()}-${Math.random().toString(16).slice(2)}`,gs=f.candidates.find(Dt=>Dt.type==="relay"),p=ks.kind==="relay"?ks.relay:gs?{relayUrl:gs.relayUrl,serverId:gs.serverId,hostEncPubJwk:gs.hostEncPubJwk}:void 0,gt=f.candidates.filter(Dt=>Dt.type!=="relay").map(Dt=>aa(Dt.url)).find(Dt=>!!Dt),Xt=ks.kind==="direct"?ks.url:gt,{token:Zt}=ks,wt=Xt||(p?ld(p.serverId):null);if(!wt){ve(t("desktopHostSwitcher.error.invalidUrl"));return}const Gt={url:wt,apiUrl:Xt||void 0,clientToken:Zt,...p?{relay:p}:{}},Js=ce.find(Dt=>p?Dt.relay?.serverId===p.serverId:!Dt.relay&&aa(Dt.apiUrl||Dt.url)===wt);if(Js){const Dt=ce.map(Fs=>Fs.id===Js.id?{...Fs,label:f.label||Fs.label,...Gt}:Fs);await Pt(Dt,me)}else await Pt([{id:Rs(),label:f.label||wa(wt),...Gt},...ce],me);ie(""),ve(null),He(!1)},[oe,me,ce,Pt,t]),is=o.useCallback(async f=>{const ee=ce.filter(st=>st.id!==f);await Pt(ee,me===f?"local":me),ue===f&&Ie(null)},[me,ue,ce,Pt]),As=o.useCallback(f=>{Ie(f.id),Ye(f.label),ke(f.apiUrl||f.url),Ce(f.clientToken||""),_e(Ku(f.requestHeaders)),ve(null)},[]),gi=o.useCallback(async()=>{if(!ue)return;const f=Kr(q);if(!f){ve(t("desktopHostSwitcher.error.invalidUrl"));return}const ee=f.persistedUrl,Fe=ce.map(st=>st.id===ue?{...st,label:Le.trim()||wa(ee),url:ee,apiUrl:ee,clientToken:O.trim()||void 0,requestHeaders:Fi(qe)}:st);await Pt(Fe,me),Ie(null),f.redeemUrl&&ei(f.redeemUrl)},[me,qe,Le,O,q,ue,ce,Pt,t]),_a=o.useCallback(async()=>{const f=Qt.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 C(ee,f,Ht.trim()||t("settings.remoteInstances.sidebar.newSshInstanceName")),I(ee),us(!1),Yt(""),as(""),D.success(t("settings.remoteInstances.page.toast.instanceCreated"))}catch(Fe){D.error(t("settings.remoteInstances.sidebar.toast.createFailed"),{description:Fe instanceof Error?Fe.message:String(Fe)})}},[C,I,Qt,Ht,t]),hi=o.useCallback(()=>{bt(""),le(l.length>0?"saved":"manual"),us(!0)},[l.length]),fi=o.useCallback(async f=>{await Pt(ce,f)},[ce,Pt]);o.useEffect(()=>{if(!n||ce.length===0)return;let f=!1;return Promise.all(ce.map(async ee=>{const Fe=()=>gd(ee.relay,{clientToken:ee.clientToken||null,requestHeaders:ee.requestHeaders||null}).catch(()=>({status:"unreachable",latencyMs:0}));if(ee.relay&&!ee.apiUrl)return[ee.id,await Fe()];const st=aa(cd(ee));if(!st)return[ee.id,ee.relay?await Fe():{status:"unreachable",latencyMs:0}];const Lt=await dd(st,{clientToken:ee.clientToken||null,requestHeaders:ee.requestHeaders||null}).catch(()=>({status:"unreachable",latencyMs:0}));if(Lt.status==="unreachable"&&ee.relay){const Es=await Fe();if(Es.status==="ok")return[ee.id,Es]}return[ee.id,Lt]})).then(ee=>{f||ae(Object.fromEntries(ee))}),()=>{f=!0}},[ce,n]);const Ls=o.useCallback(async f=>{if(a){f?.silent||kt(!0),f?.silent||Xe(null);try{const[ee,Fe]=await Promise.all([a.listClients(),a.listPendingPairings().catch(()=>null)]);ht(ee),Fe&&ut(Fe)}catch(ee){f?.silent||Xe(ee instanceof Error?ee.message:String(ee))}finally{f?.silent||kt(!1)}}},[a]),pa=o.useRef(!1);o.useEffect(()=>{if(!(!De||at!=="result"||!jt)){if(mt.some(f=>f.id===jt)){pa.current=!0;return}pa.current&&(Ae(null),it(!1),tt.some(f=>f.pairingId===jt)&&D.success(t("settings.remoteInstances.clientAuth.addDevice.connectedToast")))}},[De,at,jt,mt,tt,t]);const xi=o.useCallback(async f=>{if(a)try{await a.cancelPairing(f),ut(ee=>ee.filter(Fe=>Fe.id!==f)),await Ls({silent:!0})}catch(ee){Xe(ee instanceof Error?ee.message:String(ee))}},[a,Ls]);o.useEffect(()=>{if(!a)return;Ls();const f=window.setInterval(()=>{typeof document<"u"&&document.visibilityState!=="visible"||Ls({silent:!0})},5e3);return()=>window.clearInterval(f)},[a,Ls]);const $a=o.useCallback(async()=>{if(a?.getPairingTransports)try{const st=await a.getPairingTransports();return{localUrl:st.local,lanUrl:st.lan,relayAvailable:st.relayAvailable}}catch{}const f=Kl(),ee=f?`http://127.0.0.1:${f}`:vo(window.location.origin)?window.location.origin:null;let Fe=null;try{const st=aa(await Uu());Fe=st&&!vo(st)?st:null}catch{}return{localUrl:ee,lanUrl:Fe,relayAvailable:!0}},[a]),bi=o.useCallback(async()=>{Xe(null),Ue(null),Q(null),ze(!1),Ae(null),Je("configure"),os(!0),it(!0);const f=await $a();bs(f),Ms(f.relayAvailable?"relay":f.lanUrl?"lan":"local")},[$a]),vi=o.useCallback(async()=>{if(!(!a?.createPairingSession||!qt)){Xe(null),xs(!0);try{const f=vt.trim()||void 0;let ee,Fe,st=!0;ts==="local"?(ee=qt.localUrl??void 0,Fe=!1):ts==="lan"?(ee=qt.lanUrl??void 0,Fe=Bt):Bt&&qt.lanUrl?(ee=qt.lanUrl,Fe=!0):(st=!1,Fe=!0);const{pairing:Lt,server:Es}=await a.createPairingSession({label:f,allowedClientKinds:["mobile","desktop"],serverUrl:ee,includeRelay:Fe,includeDirect:st}),ks=pd({pairingId:Lt.id,secret:Lt.secret,label:Es.label,fingerprint:Lt.fingerprint??void 0,expiresAt:Lt.expiresAt,candidates:Es.candidates}),Rs=md(ks);Ue(Rs),Q(await Pl.toDataURL(Rs,{width:1024,margin:2,errorCorrectionLevel:"L"})),ze(!1),pa.current=!1,Ae(Lt.id),Je("result"),await Ls({silent:!0})}catch(f){Xe(f instanceof Error?f.message:String(f))}finally{xs(!1)}}},[a,qt,ts,Bt,vt,Ls]),yi=o.useCallback(()=>{ct&&Ma(ct).then(f=>{f.ok&&(ze(!0),window.setTimeout(()=>ze(!1),2e3))})},[ct]),ji=o.useCallback(async f=>{if(!a)return;const ee=f.clientKind==="desktop-local";Xe(null);try{if(await a.revokeClient(f.id),ee&&ds()){const Fe=await Lr();await Fr({hosts:Fe.hosts,defaultHostId:Fe.defaultHostId,initialHostChoiceCompleted:Fe.initialHostChoiceCompleted,localClientToken:null}),ht(st=>st.map(Lt=>Lt.id===f.id?{...Lt,revokedAt:new Date().toISOString()}:Lt)),ud({apiBaseUrl:Ka(),clientToken:null,runtimeKey:"local"});return}await Ls()}catch(Fe){Xe(Fe instanceof Error?Fe.message:String(Fe))}},[a,Ls]),wi=o.useCallback(async()=>{if(a){Xe(null);try{await a.purgeRevokedClients(),await Ls()}catch(f){Xe(f instanceof Error?f.message:String(f))}}},[a,Ls]);o.useEffect(()=>{y(w)},[w]),o.useEffect(()=>{ls(!1)},[F]),o.useEffect(()=>{if(!F)return;const f=window.setInterval(()=>{typeof document<"u"&&document.visibilityState!=="visible"||N()},2e3);return()=>{window.clearInterval(f)}},[N,F]),o.useEffect(()=>{let f=null,ee=Date.now();const Fe=()=>{const Lt=Date.now();Lt-ee>=1e3&&(ge(Lt),ee=Lt),f=requestAnimationFrame(Fe)};(typeof document>"u"||document.visibilityState==="visible")&&(f=requestAnimationFrame(Fe));const st=()=>{document.visibilityState==="visible"&&f===null?f=requestAnimationFrame(Fe):document.visibilityState!=="visible"&&f!==null&&(cancelAnimationFrame(f),f=null)};return document.addEventListener("visibilitychange",st),()=>{document.removeEventListener("visibilitychange",st),f!==null&&cancelAnimationFrame(f)}},[]);const ws=F?r[F]:null,Bs=ws?.phase,Jn=Bs==="ready",an=Bs==="degraded",hn=xr(Bs),Ws=Jn||(hn||an),ki=ws?Math.max(0,se-ws.updatedAtMs):0,rn=an&&ki>12e3,on=go(Bs),ln=on==="error"?Au(ws?.detail):null,An=Eu(ln),Qn=o.useMemo(()=>!m||!w?!1:JSON.stringify(m)!==JSON.stringify(w),[m,w]),pe=o.useCallback(f=>{y(ee=>ee&&f(ee))},[]),cs=o.useCallback(async()=>{if(!m)return;const f=zu(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(()=>cn.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 Fe=`ssh-${Date.now()}-${Math.random().toString(16).slice(2)}`;try{return await C(Fe,`ssh ${ee}`,f),I(Fe),D.success(t("settings.remoteInstances.page.toast.instanceCreated")),!0}catch(st){return D.error(t("settings.remoteInstances.sidebar.toast.createFailed"),{description:st instanceof Error?st.message:String(st)}),!1}},[C,I,t]),Tn=o.useCallback(()=>{K||(T(null),X(""))},[K]),Va=o.useCallback((f,ee)=>{if(us(!1),ee){T(f),X(Mu(f));return}En(f,f)},[En]),ma=o.useMemo(()=>li(l,dt,f=>[f.host,f.sshCommand]),[l,dt]),Ba=o.useCallback(f=>{const ee=(f||"").trim();if(!ee){D.error(t("settings.remoteInstances.page.toast.instanceUrlUnavailable"));return}ei(ee)},[t]),ua=o.useCallback(async()=>{const f=J,ee=W.trim();if(f){if(!ee){D.error(t("settings.remoteInstances.page.toast.destinationRequired"));return}te(!0);try{await En(f,ee)&&(T(null),X(""))}finally{te(!1)}}},[En,W,J,t]),Yn=o.useCallback(async()=>{if(w)try{await A(w.id);return}catch(f){if(!Cu(f)||!window.confirm(t("settings.remoteInstances.sidebar.confirm.localPortInUseRetry")))throw f;const Fe={...w,localForward:{...w.localForward,preferredLocalPort:ri()}};await b(Fe),await A(Fe.id),D.success(t("settings.remoteInstances.sidebar.toast.retriedWithRandomPort"))}},[A,w,t,b]),cn=o.useRef(null),Xn=o.useRef(null),Ha=o.useCallback(async f=>{if(w){if(f==="localPort"){const ee={...w,localForward:{...w.localForward,preferredLocalPort:ri()}};try{await b(ee),await A(ee.id),D.success(t("settings.remoteInstances.sidebar.toast.retriedWithRandomPort"))}catch(Fe){D.error(t("settings.remoteInstances.page.toast.connectFailed"),{description:Fe instanceof Error?Fe.message:String(Fe)})}return}ls(!0),window.setTimeout(()=>{if(f==="uiPassword"){cn.current?.focus();return}Xn.current?.scrollIntoView({block:"center"})},0)}},[A,w,t,b]),Zn=o.useCallback(async f=>(await jc(f,600)).map(Fe=>Lu(Fe)),[]),ea=o.useCallback(async()=>{if(m){S(!0),j(!0),H(null);try{const f=await Zn(m.id);G(f)}catch(f){G([]),H(f instanceof Error?f.message:String(f))}finally{j(!1)}}},[m,Zn]);o.useEffect(()=>{if(!U||!m)return;let f=!1;const ee=async()=>{try{const st=await Zn(m.id);f||(G(st),H(null))}catch(st){f||H(st instanceof Error?st.message:String(st))}};ee();const Fe=window.setInterval(()=>{typeof document<"u"&&document.visibilityState!=="visible"||ee()},1e3);return()=>{f=!0,window.clearInterval(Fe)}},[m,U,Zn]);const Hs=o.useMemo(()=>P.join(`
|
|
27
|
+
`),[P]),fn=o.useCallback(()=>{if(!Hs.trim()){D.error(t("settings.remoteInstances.page.toast.noLogsToCopy"));return}Ma(Hs).then(f=>{f.ok&&D.success(t("settings.remoteInstances.page.toast.logsCopied"))})},[Hs,t]),xn=o.useCallback(async()=>{if(m)try{await wc(m.id),G([]),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]),ta=o.useCallback(async()=>{if(!ws?.localUrl){D.error(t("settings.remoteInstances.page.toast.instanceUrlUnavailable"));return}const f=ws.localUrl.trim();if(!f){D.error(t("settings.remoteInstances.page.toast.instanceUrlUnavailable"));return}ei(f)},[ws?.localUrl,t]),ga=o.useCallback(()=>{if(!m)return;if(!Ws&&m.remoteOpenchamber.mode==="external"&&!m.remoteOpenchamber.preferredPort){D.error(t("settings.remoteInstances.page.validation.externalPortRequired")),ls(!0);return}if(!Ws&&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(()=>cn.current?.focus(),0);return}z(!0),(Ws?h(m.id):Yn()).catch(ee=>{const Fe=Ws?Jn?"settings.remoteInstances.page.toast.disconnectFailed":"settings.remoteInstances.page.toast.cancelConnectionFailed":"settings.remoteInstances.page.toast.connectFailed";D.error(t(Fe),{description:ee instanceof Error?ee.message:String(ee)})}).finally(()=>{z(!1)})},[Ws,Yn,h,m,Jn,t]),ha=o.useCallback(()=>{if(!m||hn)return;Y(!0),(an?h(m.id).then(()=>Yn()):E(m.id)).catch(ee=>{D.error(t("settings.remoteInstances.page.toast.retryFailed"),{description:ee instanceof Error?ee.message:String(ee)})}).finally(()=>{Y(!1)})},[Yn,h,m,hn,an,E,t]),Ni=t(hn?"settings.remoteInstances.page.actions.connecting":an?rn?"settings.remoteInstances.page.actions.reconnectNow":"settings.remoteInstances.page.actions.reconnecting":"settings.remoteInstances.sidebar.actions.retry"),Si=!_&&!Z&&(Bs==="error"||Bs==="idle"||!Bs||an&&rn)&&!hn,Ci=t(Jn?"settings.remoteInstances.sidebar.actions.disconnect":Ws?"settings.remoteInstances.page.actions.cancel":"settings.remoteInstances.sidebar.actions.connect");if(!m)return s.jsxs(ns,{title:t("settings.page.remoteInstances.title"),children:[a?s.jsxs($e,{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:()=>{bi()},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:[ms>0?s.jsx("div",{className:"flex justify-end",children:s.jsx(B,{type:"button",variant:"ghost",size:"xs",className:"!font-normal",onClick:()=>{wi()},children:t("settings.remoteInstances.clientAuth.actions.clearRevoked")})}):null,ft&&tt.length===0&&mt.length===0?s.jsx("p",{className:"typography-meta text-muted-foreground",children:t("settings.remoteInstances.clientAuth.state.loading")}):tt.length===0&&mt.length===0?s.jsx("p",{className:"typography-meta text-muted-foreground",children:t("settings.remoteInstances.clientAuth.state.empty")}):s.jsxs(s.Fragment,{children:[mt.map(f=>s.jsxs("div",{className:"flex items-center justify-between gap-3 py-1.5",children:[s.jsxs("div",{className:"min-w-0 space-y-0.5",children:[s.jsxs("div",{className:"flex min-w-0 items-center gap-2",children:[s.jsx("span",{className:"h-2 w-2 shrink-0 rounded-full bg-[var(--status-warning)] animate-pulse"}),s.jsx("p",{className:"typography-ui-label text-foreground truncate",children:f.label||t("settings.remoteInstances.clientAuth.field.labelPlaceholder")}),f.usesRelay?s.jsx("span",{className:"typography-micro text-muted-foreground bg-muted px-1 rounded shrink-0 leading-none pb-px border border-border/50",children:t("settings.remoteInstances.clientAuth.state.viaRelay")}):null]}),s.jsx("p",{className:"typography-micro text-muted-foreground truncate",children:t("settings.remoteInstances.clientAuth.state.pending")})]}),s.jsx(B,{type:"button",variant:"ghost",size:"xs",className:"!font-normal",onClick:()=>{xi(f.id)},children:t("settings.common.actions.cancel")})]},`pending-${f.id}`)),tt.map(f=>{const ee=f.clientKind==="desktop-local",Fe=f.lastUsedAt?Date.parse(f.lastUsedAt):Number.NaN,st=!f.revokedAt&&(ee||Number.isFinite(Fe)&&Date.now()-Fe<9e4),Lt=f.revokedAt?t("settings.remoteInstances.clientAuth.state.revoked"):st?f.lastTransport==="relay"&&!ee?t("settings.remoteInstances.clientAuth.state.connectedRelay"):t("settings.remoteInstances.clientAuth.state.connectedDirect"):Number.isFinite(Fe)?t("settings.remoteInstances.clientAuth.lastUsed",{date:kc(Fe,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:we("h-2 w-2 shrink-0 rounded-full",f.revokedAt?"bg-muted-foreground/20":st?"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:we("typography-micro truncate",st&&!f.revokedAt?"text-[var(--status-success)]":"text-muted-foreground"),children:Lt})]})}),s.jsx(B,{type:"button",variant:"ghost",size:"xs",className:"!font-normal",onClick:()=>{ji(f)},disabled:!!f.revokedAt,children:t("settings.remoteInstances.clientAuth.actions.revoke")})]},f.id)})]})]}),Ze?s.jsx("p",{className:"typography-meta text-[var(--status-error)]",children:Ze}):null]}):null,n?s.jsxs($e,{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:()=>He(!0),disabled:je,children:t("settings.remoteInstances.direct.import.action")}),s.jsxs(B,{type:"button",variant:"outline",size:"xs",className:"!font-normal",onClick:()=>Te(!0),disabled:je,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:Ne?s.jsx("p",{className:"typography-meta text-muted-foreground",children:t("settings.remoteInstances.direct.state.loading")}):ce.length===0?s.jsx("p",{className:"typography-meta text-muted-foreground",children:t("settings.remoteInstances.direct.state.empty")}):ce.map(f=>{const ee=ne[f.id],Fe=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",st=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:we("h-2 w-2 shrink-0 rounded-full",ee?st?"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:wa(f.label)}),me===f.id?s.jsx("span",{className:"typography-micro text-muted-foreground shrink-0",children:t("desktopHostSwitcher.header.default")}):null,s.jsxs("span",{className:we("typography-micro shrink-0",st?"text-[var(--status-success)]":"text-muted-foreground"),children:[t(Fe),st&&typeof ee?.latencyMs=="number"?t("desktopHostSwitcher.status.ping",{ms:Math.max(0,Math.round(ee.latencyMs))}):""]})]}),s.jsx("p",{className:we("typography-micro text-muted-foreground truncate",f.apiUrl&&"font-mono"),children:f.relay&&!f.apiUrl?t("mobile.connect.relay.badge"):wa(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:()=>{fi(f.id)},disabled:je||me===f.id,"aria-label":t("desktopHostSwitcher.actions.setAsDefaultAria"),children:me===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:()=>As(f),disabled:je,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:()=>{is(f.id)},disabled:je,children:[s.jsx(L,{name:"delete-bin",className:"h-3.5 w-3.5"}),t("settings.common.actions.delete")]})]})]})},f.id)})}),ye?s.jsx("p",{className:"typography-meta text-[var(--status-error)]",children:ye}):null]}):null,n?s.jsx(Rt,{open:Oe,onOpenChange:Te,children:s.jsxs(Ot,{className:"sm:max-w-lg",children:[s.jsxs(Kt,{children:[s.jsx(Ut,{children:t("settings.remoteInstances.direct.actions.add")}),s.jsx(zt,{children:t("settings.remoteInstances.direct.addDialog.description")})]}),s.jsxs("form",{className:"space-y-3",onSubmit:f=>{f.preventDefault(),_t()},children:[s.jsx(We,{className:"h-8",value:Re,onChange:f=>re(f.target.value),placeholder:t("settings.remoteInstances.direct.field.labelPlaceholder"),disabled:je}),s.jsx(We,{className:"h-8",value:fe,onChange:f=>Ee(f.target.value),placeholder:t("settings.remoteInstances.direct.field.urlPlaceholder"),disabled:je,autoFocus:!0}),s.jsxs("div",{className:"space-y-1",children:[s.jsx(We,{className:"h-8",value:Be,onChange:f=>Ve(f.target.value),placeholder:t("settings.remoteInstances.direct.field.tokenPlaceholder"),type:"password",disabled:je}),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(Xs,{children:t("settings.remoteInstances.direct.headers.title")}),s.jsx(Jt,{children:t("settings.remoteInstances.direct.headers.description")})]}),Ge.map(f=>s.jsxs("div",{className:"flex w-full gap-2",children:[s.jsx(We,{className:"h-8 font-mono text-xs",value:f.name,onChange:ee=>Ke(Fe=>Fe.map(st=>st.id===f.id?{...st,name:ee.target.value}:st)),placeholder:t("settings.remoteInstances.direct.headers.field.namePlaceholder"),disabled:je}),s.jsx(We,{className:"h-8 font-mono text-xs",value:f.value,onChange:ee=>Ke(Fe=>Fe.map(st=>st.id===f.id?{...st,value:ee.target.value}:st)),placeholder:t("settings.remoteInstances.direct.headers.field.valuePlaceholder"),type:"password",disabled:je}),s.jsx("button",{type:"button",onClick:()=>Ke(ee=>ee.filter(Fe=>Fe.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:je,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:()=>Ke(f=>[...f,ar()]),disabled:je,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:()=>Te(!1),disabled:je,children:t("settings.common.actions.cancel")}),s.jsx(B,{type:"submit",size:"xs",className:"!font-normal",disabled:je||!fe.trim(),children:t("settings.remoteInstances.direct.actions.add")})]})]})]})}):null,n?s.jsx(Rt,{open:!!ue,onOpenChange:f=>{f||Ie(null)},children:s.jsxs(Ot,{className:"sm:max-w-lg",children:[s.jsxs(Kt,{children:[s.jsx(Ut,{children:t("desktopHostSwitcher.actions.edit")}),s.jsx(zt,{children:t("settings.remoteInstances.direct.description")})]}),s.jsxs("form",{className:"space-y-3",onSubmit:f=>{f.preventDefault(),gi()},children:[s.jsx(We,{className:"h-8",value:Le,onChange:f=>Ye(f.target.value),placeholder:t("settings.remoteInstances.direct.field.labelPlaceholder"),disabled:je}),s.jsx(We,{className:"h-8",value:q,onChange:f=>ke(f.target.value),placeholder:t("settings.remoteInstances.direct.field.urlPlaceholder"),disabled:je,autoFocus:!0}),s.jsx(We,{className:"h-8",value:O,onChange:f=>Ce(f.target.value),placeholder:t("settings.remoteInstances.direct.field.tokenPlaceholder"),type:"password",disabled:je}),s.jsxs("div",{className:"space-y-2",children:[s.jsxs("div",{className:"flex items-center gap-1.5",children:[s.jsx(Xs,{children:t("settings.remoteInstances.direct.headers.title")}),s.jsx(Jt,{children:t("settings.remoteInstances.direct.headers.description")})]}),qe.map(f=>s.jsxs("div",{className:"flex w-full gap-2",children:[s.jsx(We,{className:"h-8 font-mono text-xs",value:f.name,onChange:ee=>_e(Fe=>Fe.map(st=>st.id===f.id?{...st,name:ee.target.value}:st)),placeholder:t("settings.remoteInstances.direct.headers.field.namePlaceholder"),disabled:je}),s.jsx(We,{className:"h-8 font-mono text-xs",value:f.value,onChange:ee=>_e(Fe=>Fe.map(st=>st.id===f.id?{...st,value:ee.target.value}:st)),placeholder:t("settings.remoteInstances.direct.headers.field.valuePlaceholder"),type:"password",disabled:je}),s.jsx("button",{type:"button",onClick:()=>_e(ee=>ee.filter(Fe=>Fe.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:je,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:()=>_e(f=>[...f,ar()]),disabled:je,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:()=>Ie(null),disabled:je,children:t("settings.common.actions.cancel")}),s.jsx(B,{type:"submit",size:"xs",className:"!font-normal",disabled:je,children:t("settings.common.actions.saveChanges")})]})]})]})}):null,n?s.jsx(Rt,{open:xe,onOpenChange:He,children:s.jsxs(Ot,{className:"sm:max-w-lg",children:[s.jsxs(Kt,{children:[s.jsx(Ut,{children:t("settings.remoteInstances.direct.import.action")}),s.jsx(zt,{children:t("settings.remoteInstances.direct.import.description")})]}),s.jsxs("form",{className:"space-y-3",onSubmit:f=>{f.preventDefault(),Mt()},children:[s.jsx(We,{className:"h-8",value:oe,onChange:f=>ie(f.target.value),placeholder:t("settings.remoteInstances.direct.import.placeholder"),disabled:je,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:()=>He(!1),disabled:je,children:t("settings.common.actions.cancel")}),s.jsx(B,{type:"submit",size:"xs",className:"!font-normal",disabled:je||!oe.trim(),children:t("settings.remoteInstances.direct.import.action")})]})]})]})}):null,s.jsx(Rt,{open:De,onOpenChange:it,children:s.jsxs(Ot,{className:at==="result"?"sm:max-w-lg":"sm:max-w-md",children:[s.jsxs(Kt,{children:[s.jsx(Ut,{children:t(at==="result"?"settings.remoteInstances.clientAuth.qrDialogTitle":"settings.remoteInstances.clientAuth.actions.addDevice")}),s.jsx(zt,{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(),vi()},children:[s.jsx(We,{className:"h-8",value:vt,onChange:f=>Ct(f.target.value),placeholder:t("settings.remoteInstances.clientAuth.field.labelPlaceholder"),autoFocus:!0}),s.jsxs("div",{className:"space-y-1.5",children:[s.jsx("p",{className:"typography-ui-label text-foreground",children:t("settings.remoteInstances.clientAuth.addDevice.transportLabel")}),s.jsx("div",{role:"radiogroup","aria-label":t("settings.remoteInstances.clientAuth.addDevice.transportLabel"),className:"space-y-1.5",children:[{key:"relay",label:t("settings.remoteInstances.clientAuth.addDevice.transport.relay"),hint:t("settings.remoteInstances.clientAuth.addDevice.transport.relayHint"),available:!!qt?.relayAvailable},{key:"lan",label:t("settings.remoteInstances.clientAuth.addDevice.transport.lan"),hint:t("settings.remoteInstances.clientAuth.addDevice.transport.lanHint"),available:!!qt?.lanUrl},{key:"local",label:t("settings.remoteInstances.clientAuth.addDevice.transport.local"),hint:t("settings.remoteInstances.clientAuth.addDevice.transport.localHint"),available:!!qt?.localUrl}].map(f=>{const ee=ts===f.key;return s.jsxs("div",{className:we("flex items-start gap-2 py-0.5",f.available?"cursor-pointer":"opacity-45"),onClick:()=>{f.available&&Ms(f.key)},role:"presentation",children:[s.jsx(dr,{checked:ee,disabled:!f.available,onChange:()=>Ms(f.key),ariaLabel:f.label,className:"mt-0.5"}),s.jsxs("div",{className:"min-w-0",children:[s.jsx("p",{className:we("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)})}),ts==="lan"?s.jsxs("label",{className:"flex w-fit cursor-pointer items-center gap-2 pt-1",children:[s.jsx(Yi,{checked:Bt,onChange:os,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,ts==="relay"&&qt?.lanUrl?s.jsxs("label",{className:"flex w-fit cursor-pointer items-center gap-2 pt-1",children:[s.jsx(Yi,{checked:Bt,onChange:os,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]}),Ze?s.jsx("p",{className:"typography-meta text-[var(--status-error)]",children:Ze}):null,s.jsxs("div",{className:"flex justify-end gap-2",children:[s.jsx(B,{type:"button",variant:"outline",size:"xs",className:"!font-normal",onClick:()=>it(!1),disabled:Nt,children:t("settings.common.actions.cancel")}),s.jsx(B,{type:"submit",size:"xs",className:"!font-normal",disabled:Nt||!qt,children:t("settings.remoteInstances.clientAuth.addDevice.create")})]})]}):s.jsxs("div",{className:"space-y-3",children:[yt?s.jsx("div",{className:"flex justify-center",children:s.jsx("img",{src:yt,alt:t("settings.remoteInstances.clientAuth.qrAlt"),className:"w-full max-w-[420px] rounded-md bg-white p-4"})}):null,ct?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:ct}),s.jsxs(B,{type:"button",variant:"outline",size:"xs",className:"!font-normal shrink-0",onClick:yi,children:[s.jsx(L,{name:he?"check":"file-copy",className:we("h-3.5 w-3.5",he&&"text-[var(--status-success)]")}),t(he?"settings.remoteInstances.clientAuth.actions.copied":"settings.common.actions.copyAll")]})]}):null,s.jsx("div",{className:"flex justify-end",children:s.jsx(B,{type:"button",size:"xs",className:"!font-normal",onClick:()=>it(!1),children:t("settings.remoteInstances.clientAuth.addDevice.done")})})]})]})}),n?s.jsx($e,{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:hi,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:u?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],Fe=f.nickname?.trim()||f.sshParsed?.destination||f.id,st=ee?.phase,Lt=st==="ready",Es=go(st),ks=Es==="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(st)}`}),s.jsx("p",{className:"typography-ui-label text-foreground truncate",children:Fe})]}),s.jsxs("p",{className:"typography-micro text-muted-foreground truncate",children:[t(ho(Es)),Es==="connecting"?` · ${t(uo(st))}`:"",Lt&&ee?.localUrl?` · ${ee.localUrl}`:""]})]}),s.jsxs("div",{className:"flex shrink-0 items-center gap-1",children:[Lt?s.jsxs(B,{type:"button",variant:"ghost",size:"xs",className:"!font-normal",onClick:()=>Ba(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:()=>{(Lt?h(f.id):A(f.id)).catch(gs=>D.error(t(Lt?"settings.remoteInstances.sidebar.toast.disconnectFailed":"settings.remoteInstances.sidebar.toast.connectFailed"),{description:gs instanceof Error?gs.message:String(gs)}))},children:[Lt?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(Lt?"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"))&&k(f.id).catch(gs=>D.error(t("settings.remoteInstances.page.toast.removeInstanceFailed"),{description:gs instanceof Error?gs.message:String(gs)}))},children:[s.jsx(L,{name:"delete-bin",className:"h-3.5 w-3.5"}),t("settings.common.actions.delete")]})]})]}),ks?s.jsx("p",{className:"typography-micro text-[var(--status-error)] break-words",children:ks}):null]},f.id)})}):null,n?s.jsx(Rt,{open:vs,onOpenChange:us,children:s.jsxs(Ot,{className:"sm:max-w-lg",children:[s.jsxs(Kt,{children:[s.jsx(Ut,{children:t("settings.remoteInstances.sidebar.actions.addSshInstance")}),s.jsx(zt,{children:t("settings.remoteInstances.page.addDialog.description")})]}),s.jsx(Gs,{value:ys,onChange:le,"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")}]}),ys==="saved"?s.jsxs("div",{className:"space-y-2",children:[s.jsx(We,{className:"h-8",value:dt,onChange:f=>bt(f.target.value),placeholder:t("settings.remoteInstances.page.addDialog.searchPlaceholder"),autoFocus:!0}),g?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:()=>{Va(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(),_a()},children:[s.jsx(We,{className:"h-8",value:Ht,onChange:f=>as(f.target.value),placeholder:t("settings.remoteInstances.page.field.nicknamePlaceholder"),disabled:x}),s.jsx(We,{className:"h-8",value:Qt,onChange:f=>Yt(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:()=>us(!1),disabled:x,children:t("settings.common.actions.cancel")}),s.jsx(B,{type:"submit",size:"xs",className:"!font-normal",disabled:x||!Qt.trim(),children:t("settings.common.actions.create")})]})]})]})}):null,s.jsx(Rt,{open:!!J,onOpenChange:f=>{f||Tn()},children:s.jsxs(Ot,{className:"sm:max-w-md",children:[s.jsxs(Kt,{children:[s.jsx(Ut,{children:t("settings.remoteInstances.page.patternDialog.title")}),s.jsx(zt,{children:J?t("settings.remoteInstances.page.patternDialog.descriptionWithHost",{host:J}):t("settings.remoteInstances.page.patternDialog.description")})]}),s.jsxs("form",{className:"space-y-3",onSubmit:f=>{f.preventDefault(),ua()},children:[s.jsx(We,{value:W,onChange:f=>X(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:K,children:t("settings.common.actions.cancel")}),s.jsx(B,{type:"submit",size:"xs",className:"!font-normal",disabled:K,children:t("settings.remoteInstances.page.actions.create")})]})]})]})})]});const Dn=m.remoteOpenchamber.mode==="managed",sa=Dn&&m.remoteOpenchamber.bindHost==="0.0.0.0",fa=sa&&!m.auth.openchamberPassword?.value?.trim(),xa=m.nickname?.trim()||m.sshParsed?.destination||m.id;return s.jsx(Rt,{open:!!m,onOpenChange:f=>{f||I(null)},children:s.jsxs(Ot,{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:xa}),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(on))}),on==="connecting"?s.jsx("span",{children:t(uo(Bs))}):null,ws?.localUrl?s.jsx("span",{className:"font-mono text-foreground/80",children:ws.localUrl}):null,rn?s.jsx("span",{children:t("settings.remoteInstances.page.status.reconnectStale")}):null]})]}),s.jsxs($e,{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:Ws?"outline":"default",size:"xs",className:"!font-normal",onClick:ga,disabled:_||Z,children:[Ws?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:ha,disabled:!Si,children:[s.jsx(L,{name:"refresh",className:`h-3.5 w-3.5 ${hn||an&&!rn?"animate-spin":""}`}),Ni]}),s.jsxs(B,{type:"button",variant:"outline",size:"xs",className:"!font-normal",onClick:()=>{ea()},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"))&&k(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")]})]}),on==="error"&&ws?.detail?s.jsxs("div",{className:"space-y-2 rounded-md border border-[var(--status-error)]/30 bg-[var(--status-error-background)] p-3",children:[s.jsx("p",{className:"typography-meta text-[var(--status-error)] break-words",children:ws.detail}),An?s.jsx("p",{className:"typography-micro text-muted-foreground",children:t(An)}):null,ln&&!An?s.jsx(B,{type:"button",variant:"outline",size:"xs",className:"!font-normal",onClick:()=>{Ha(ln)},children:t(ln==="uiPassword"?"settings.remoteInstances.page.error.action.setUiPassword":ln==="localPort"?"settings.remoteInstances.page.error.action.pickRandomPort":"settings.remoteInstances.page.error.action.setRemotePort")}):null]}):null,ws?.localUrl?s.jsxs("div",{className:"flex flex-wrap items-center gap-2 typography-meta text-muted-foreground",children:[s.jsx("span",{children:t("settings.remoteInstances.page.status.currentLocalUrl")}),s.jsx("span",{className:"font-mono text-foreground/90",children:ws.localUrl})]}):null]}),s.jsxs($e,{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(We,{className:"h-7 md:max-w-xl",value:m.sshCommand,onChange:f=>pe(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(We,{className:"h-7 md:max-w-sm",value:m.nickname||"",onChange:f=>pe(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(_s,{label:t("settings.remoteInstances.page.field.mode"),hint:t("settings.remoteInstances.page.field.modeHint")})}),s.jsxs(At,{value:m.remoteOpenchamber.mode,onValueChange:f=>pe(ee=>({...ee,remoteOpenchamber:{...ee.remoteOpenchamber,mode:f==="external"?"external":"managed"}})),children:[s.jsx(Et,{size:$t,className:"w-fit min-w-[140px]",children:s.jsx(Ft,{placeholder:t("settings.remoteInstances.page.field.modePlaceholder")})}),s.jsxs(Tt,{children:[s.jsx(ot,{value:"managed",children:t("settings.remoteInstances.page.field.modeManaged")}),s.jsx(ot,{value:"external",children:t("settings.remoteInstances.page.field.modeExternal")})]})]})]})]}),s.jsxs(Hn,{open:js,onOpenChange:ls,children:[s.jsxs(Gn,{className:"mt-6 w-auto justify-start gap-1.5",children:[s.jsx("span",{className:ul,children:t("settings.remoteInstances.page.section.advanced")}),s.jsx(L,{name:js?"arrow-up-s":"arrow-down-s",className:"h-4 w-4 text-muted-foreground"})]}),s.jsxs(qn,{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(Ss,{containerClassName:"w-fit",min:5,max:240,step:1,className:we(Ps,"tabular-nums"),value:m.connectionTimeoutSec,onValueChange:f=>{pe(ee=>({...ee,connectionTimeoutSec:Number.isFinite(f)?f:ee.connectionTimeoutSec}))}})]}),s.jsxs($e,{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:Xn,children:s.jsx(_s,{label:t("settings.remoteInstances.page.field.preferredRemotePort"),hint:t("settings.remoteInstances.page.field.preferredRemotePortHint")})}),s.jsx(Ss,{containerClassName:"w-fit",min:1,max:65535,step:1,className:we(Ps,"tabular-nums"),value:m.remoteOpenchamber.preferredPort,onValueChange:f=>{pe(ee=>({...ee,remoteOpenchamber:{...ee.remoteOpenchamber,preferredPort:Number.isFinite(f)&&f>0?f:void 0}}))},onClear:()=>{pe(f=>({...f,remoteOpenchamber:{...f.remoteOpenchamber,preferredPort:void 0}}))},emptyLabel:t("settings.remoteInstances.page.field.auto")})]}),Dn?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(_s,{label:t("settings.remoteInstances.page.field.installMethod"),hint:t("settings.remoteInstances.page.field.installMethodHint")})}),s.jsxs(At,{value:m.remoteOpenchamber.installMethod,onValueChange:f=>pe(ee=>({...ee,remoteOpenchamber:{...ee.remoteOpenchamber,installMethod:f==="npm"||f==="bun"?f:"auto"}})),children:[s.jsx(Et,{size:$t,className:"w-fit min-w-[140px]",children:s.jsx(Ft,{placeholder:t("settings.remoteInstances.page.field.selectInstallMethodPlaceholder")})}),s.jsxs(Tt,{children:[s.jsx(ot,{value:"auto",children:t("settings.remoteInstances.page.field.installMethodAuto")}),s.jsx(ot,{value:"bun",children:"bun"}),s.jsx(ot,{value:"npm",children:"npm"})]})]})]}):null,Dn?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(_s,{label:t("settings.remoteInstances.page.field.remoteLanAccess"),hint:t("settings.remoteInstances.page.field.remoteLanAccessHint")})}),s.jsx(Pi,{checked:sa,onCheckedChange:f=>pe(ee=>({...ee,remoteOpenchamber:{...ee.remoteOpenchamber,bindHost:f?"0.0.0.0":"127.0.0.1"}})),"aria-label":t("settings.remoteInstances.page.field.remoteLanAccess")})]}),sa?s.jsx("p",{className:"mt-2 typography-micro text-[var(--status-warning)] md:pl-[16rem]",children:t("settings.remoteInstances.page.field.remoteLanAccessWarning")}):null]}):null,Dn?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(_s,{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=>pe(ee=>({...ee,remoteOpenchamber:{...ee.remoteOpenchamber,keepRunning:f}}))})})]}):null]}),s.jsxs($e,{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(_s,{label:t("settings.remoteInstances.page.field.bindHost"),hint:t("settings.remoteInstances.page.field.bindHostHint")})}),s.jsxs(At,{value:m.localForward.bindHost,onValueChange:f=>{f==="0.0.0.0"&&!window.confirm(t("settings.remoteInstances.page.confirm.bindAllInterfaces"))||pe(ee=>({...ee,localForward:{...ee.localForward,bindHost:f==="localhost"||f==="0.0.0.0"?f:"127.0.0.1"}}))},children:[s.jsx(Et,{size:$t,className:"w-fit min-w-[240px]",children:s.jsx(Ft,{placeholder:t("settings.remoteInstances.page.field.selectBindHostPlaceholder")})}),s.jsxs(Tt,{children:[s.jsx(ot,{value:"127.0.0.1",children:t("settings.remoteInstances.page.field.bindHostOption.loopback")}),s.jsx(ot,{value:"localhost",children:t("settings.remoteInstances.page.field.bindHostOption.localhost")}),s.jsx(ot,{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(_s,{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(Ss,{containerClassName:"w-fit",min:1,max:65535,step:1,className:we(Ps,"tabular-nums"),value:m.localForward.preferredLocalPort,onValueChange:f=>{pe(ee=>({...ee,localForward:{...ee.localForward,preferredLocalPort:Number.isFinite(f)&&f>0?f:void 0}}))},onClear:()=>{pe(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:()=>pe(f=>({...f,localForward:{...f.localForward,preferredLocalPort:ri()}})),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($e,{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(_s,{label:t("settings.remoteInstances.page.field.sshPasswordOptional"),hint:t("settings.remoteInstances.page.field.sshPasswordHint")})}),s.jsx(We,{className:"h-7 md:max-w-sm",type:"password",value:m.auth.sshPassword?.value||"",onChange:f=>pe(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(_s,{label:t(sa?"settings.remoteInstances.page.field.uiPasswordRequired":"settings.remoteInstances.page.field.uiPasswordOptional"),hint:t(Dn?"settings.remoteInstances.page.field.uiPasswordHintManaged":"settings.remoteInstances.page.field.uiPasswordHintExternal")})}),s.jsx(We,{className:we("h-7 md:max-w-sm",fa&&"border-[var(--status-error)]"),type:"password",ref:cn,"aria-invalid":fa,value:m.auth.openchamberPassword?.value||"",onChange:f=>pe(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")})]}),fa?s.jsx("p",{className:"typography-micro text-[var(--status-error)] md:pl-[16rem]",children:t("settings.remoteInstances.page.field.uiPasswordMissingForLan")}):null]}),s.jsxs($e,{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 Fe=wt=>{pe(Gt=>({...Gt,portForwards:Gt.portForwards.map((Js,Dt)=>Dt===ee?wt(Js):Js)}))},st=f.type==="remote"?"Local target":"Local listen",Lt=f.type==="remote"?"Local host and port on your machine that receives traffic from remote -R listener.":"Local host and port where this forward listens on your machine.",Es=f.type==="remote"?"Remote listen":"Remote target",ks=f.type==="remote"?"Remote host and port where SSH creates the -R listener.":"Remote host and port that receives traffic from local -L listener.",Rs=bo(f.localHost||"localhost",f.localPort),gs=bo(f.remoteHost||"localhost",f.remotePort),p=f.type==="local"&&typeof f.localPort=="number"&&f.localPort>0,gt=p?`http://${Ou(f.localHost)}:${f.localPort}`:"",Xt=!!$[f.id],Zt=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(Hn,{open:Xt,onOpenChange:wt=>{V(Gt=>({...Gt,[f.id]:wt}))},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(Gn,{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 ${Xt?"rotate-180":""}`}),s.jsx("span",{className:"typography-ui-label text-foreground truncate",children:Tu(f)}),s.jsx("span",{className:"typography-micro text-muted-foreground/70 shrink-0",children:Zt})]})}),s.jsxs("div",{className:"flex items-center gap-2",children:[s.jsx(Pi,{checked:f.enabled,onCheckedChange:wt=>Fe(Gt=>({...Gt,enabled:wt})),"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:()=>pe(wt=>({...wt,portForwards:wt.portForwards.filter(Gt=>Gt.id!==f.id)})),children:s.jsx(L,{name:"delete-bin",className:"h-3.5 w-3.5"})})]})]}),s.jsx(qn,{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(_s,{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(Ru(f.type))})]})})}),s.jsxs(At,{value:f.type,onValueChange:wt=>Fe(Gt=>({...Gt,type:wt==="dynamic"||wt==="remote"?wt:"local"})),children:[s.jsx(Et,{size:$t,className:"w-fit min-w-[140px]",children:s.jsx(Ft,{placeholder:t("settings.remoteInstances.page.field.typePlaceholder")})}),s.jsxs(Tt,{children:[s.jsx(ot,{value:"local",children:t("settings.remoteInstances.page.forwardType.local")}),s.jsx(ot,{value:"remote",children:t("settings.remoteInstances.page.forwardType.remote")}),s.jsx(ot,{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(_s,{label:st,hint:Lt})}),s.jsxs("div",{className:"flex items-center gap-1.5",children:[s.jsx(We,{className:"h-7 w-32",value:f.localHost||"127.0.0.1",onChange:wt=>Fe(Gt=>({...Gt,localHost:wt.target.value})),placeholder:t("settings.remoteInstances.page.field.localHostPlaceholder")}),s.jsx("span",{className:"text-muted-foreground",children:":"}),s.jsx(Ss,{containerClassName:"w-fit",min:1,max:65535,step:1,className:we(Ps,"tabular-nums"),value:f.localPort,onValueChange:wt=>{Fe(Gt=>({...Gt,localPort:Number.isFinite(wt)&&wt>0?wt:void 0}))},onClear:()=>{Fe(wt=>({...wt,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(_s,{label:Es,hint:ks})}),s.jsxs("div",{className:"flex items-center gap-1.5",children:[s.jsx(We,{className:"h-7 w-32",value:f.remoteHost||"",onChange:wt=>Fe(Gt=>({...Gt,remoteHost:wt.target.value})),placeholder:t("settings.remoteInstances.page.field.remoteHostPlaceholder")}),s.jsx("span",{className:"text-muted-foreground",children:":"}),s.jsx(Ss,{containerClassName:"w-fit",min:1,max:65535,step:1,className:we(Ps,"tabular-nums"),value:f.remotePort,onValueChange:wt=>{Fe(Gt=>({...Gt,remotePort:Number.isFinite(wt)&&wt>0?wt:void 0}))},onClear:()=>{Fe(wt=>({...wt,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:Rs}),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:gs}),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:Rs}),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:Rs}),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:gs}),s.jsx("span",{children:t("settings.remoteInstances.page.preview.remote")})]})}),p?s.jsxs(B,{type:"button",variant:"outline",size:"xs",className:"!font-normal",onClick:()=>{In(gt).then(wt=>{wt||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=Du();pe(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:()=>{cs()},disabled:!Qn||x,children:t("settings.common.actions.saveChanges")}),ws?.localUrl?s.jsxs(s.Fragment,{children:[s.jsxs(B,{type:"button",variant:"outline",size:"xs",className:"!font-normal",onClick:()=>{Ma(ws.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:()=>{ta()},children:[s.jsx(L,{name:"external-link",className:"h-3.5 w-3.5"}),t("settings.remoteInstances.page.actions.open")]})]}):null,d?s.jsx("div",{className:"ml-auto typography-meta text-[var(--status-error)]",children:d}):null]})}),s.jsx(Rt,{open:U,onOpenChange:S,children:s.jsxs(Ot,{className:"sm:max-w-2xl",children:[s.jsxs(Kt,{children:[s.jsx(Ut,{children:t("settings.remoteInstances.page.logsDialog.title")}),s.jsx(zt,{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:fn,disabled:M||!Hs.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:()=>{xn()},disabled:M,children:[s.jsx(L,{name:"delete-bin",className:"h-3.5 w-3.5"}),t("settings.common.actions.clear")]})]}),M?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:P.length>0?P.join(`
|
|
28
|
+
`):t("settings.remoteInstances.page.logsDialog.empty")})]})}),s.jsx(Rt,{open:!!J,onOpenChange:f=>{f||Tn()},children:s.jsxs(Ot,{className:"sm:max-w-md",children:[s.jsxs(Kt,{children:[s.jsx(Ut,{children:t("settings.remoteInstances.page.patternDialog.title")}),s.jsx(zt,{children:J?t("settings.remoteInstances.page.patternDialog.descriptionWithHost",{host:J}):t("settings.remoteInstances.page.patternDialog.description")})]}),s.jsxs("form",{className:"space-y-3",onSubmit:f=>{f.preventDefault(),ua()},children:[s.jsx(We,{value:W,onChange:f=>X(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:K,children:t("settings.common.actions.cancel")}),s.jsx(B,{type:"submit",size:"xs",className:"!font-normal",disabled:K,children:t("settings.common.actions.create")})]})]})]})})]})})},$u="__add_provider__",Vu=()=>{const t=un.getDirectory();return typeof t=="string"&&t.trim().length>0?t.trim():null},Bu=({onItemSelect:t})=>{const{t:e}=nt(),a=zs(),n=et(b=>gl(b,a)),i=et(b=>b.selectedProviderId),r=et(b=>b.setSelectedProvider),l=qs(b=>b.activeProjectId),[u,g]=o.useState({}),x=o.useMemo(()=>a||Vu(),[l,a]),d=et(b=>b.loadProviders);o.useEffect(()=>{a&&d({directory:a,source:"settings:providers"})},[d,a]),o.useEffect(()=>{if(n.length===0){g({});return}let b=!1;return(async()=>{const k=n.map(async A=>{try{const h=x?`?directory=${encodeURIComponent(x)}`:"",E=await rt(`/api/provider/${encodeURIComponent(A.id)}/source${h}`,{method:"GET",headers:{Accept:"application/json"}});if(!E.ok)return;const F=await E.json().catch(()=>null),I=F?.sources??F?.data?.sources;if(!I||b)return;g(w=>({...w,[A.id]:I}))}catch{}});await Promise.all(k)})(),()=>{b=!0}},[x,n]);const v="bg-background",c=o.useMemo(()=>n.filter(b=>!!u[b.id]?.project?.exists),[n,u]),N=o.useMemo(()=>n.filter(b=>!u[b.id]?.project?.exists),[n,u]);return s.jsxs("div",{className:we("flex h-full flex-col",v),children:[s.jsxs("div",{className:"border-b px-3 pt-4 pb-3",children:[s.jsx("h2",{className:`${nn} mb-3`,children:e("settings.providers.sidebar.title")}),s.jsx(za,{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($u),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:[N.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")}),N.map(b=>s.jsx(yo,{provider:b,selectedProviderId:i,onSelect:()=>{r(b.id),t?.()}},b.id))]}),c.length>0&&s.jsxs(s.Fragment,{children:[s.jsx("div",{className:we("px-2 pb-1.5 text-xs font-semibold uppercase tracking-wide text-muted-foreground",N.length>0?"pt-3":"pt-2"),children:e("settings.providers.sidebar.section.projectProviders")}),c.map(b=>s.jsx(yo,{provider:b,selectedProviderId:i,onSelect:()=>{r(b.id),t?.()}},b.id))]})]})})]})},yo=t=>{const e=lt.c(17),{provider:a,selectedProviderId:n,onSelect:i}=t,r=Array.isArray(a.models)?a.models.length:0,l=a.id===n,u=a.id,g=l?"bg-interactive-selection":"hover:bg-interactive-hover";let x;e[0]!==g?(x=we("group relative flex items-center rounded-md px-1.5 py-1 transition-all duration-200",g),e[0]=g,e[1]=x):x=e[1];let d;e[2]!==a.id?(d=s.jsx(On,{providerId:a.id,className:"h-4 w-4 flex-shrink-0"}),e[2]=a.id,e[3]=d):d=e[3];const v=a.name||a.id;let c;e[4]!==v?(c=s.jsx("span",{className:"typography-ui-label font-normal truncate flex-1 min-w-0 text-foreground",children:v}),e[4]=v,e[5]=c):c=e[5];let N;e[6]!==r?(N=s.jsx("span",{className:"typography-micro text-muted-foreground/60 flex-shrink-0",children:r}),e[6]=r,e[7]=N):N=e[7];let b;e[8]!==i||e[9]!==d||e[10]!==c||e[11]!==N?(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:[d,c,N]}),e[8]=i,e[9]=d,e[10]=c,e[11]=N,e[12]=b):b=e[12];let C;return e[13]!==a.id||e[14]!==x||e[15]!==b?(C=s.jsx("div",{className:x,children:b},u),e[13]=a.id,e[14]=x,e[15]=b,e[16]=C):C=e[16],C},Hu=t=>t,Gu=(t,e,a)=>t&&!e&&!a,jo=t=>typeof t=="object"&&t!==null,Ul=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()},qu=t=>{if(!jo(t))return{};const e={};for(const[a,n]of Object.entries(t))Array.isArray(n)&&(e[a]=n.filter(i=>jo(i)));return e},wo=t=>t.length===0?!0:t.some(e=>Ul(e)==="api"),ko=t=>t.map((e,a)=>({method:e,methodIndex:a})).filter(({method:e})=>Ul(e)==="oauth"),Wu=t=>t!=="claude-code",No=t=>typeof t.key=="string"&&t.key.trim().length>0||typeof t.optionsApiKey=="string"&&t.optionsApiKey.trim().length>0||t.envDeclared===!0?!0:t.authSourceExists===!0,Ju=t=>t.modelCount>0&&(!t.sourcesLoaded||t.hasCredentials||!!t.isEditableCustomProvider),Qu=t=>!t.hasCredentials&&!t.userDismissed&&!t.isEditableCustomProvider,br={"openai-chat":"@ai-sdk/openai-compatible","openai-responses":"@ai-sdk/openai","anthropic-messages":"@ai-sdk/anthropic"},Mn="__custom_provider__",Yu=/^[a-z0-9][a-z0-9-_]*$/,zl=/^https?:\/\//,Xu=/^\{env:([^}]+)\}$/;let Zu=0;const pi=()=>`row-${Zu++}`,vr=()=>({row:pi(),id:"",name:""}),yr=()=>({row:pi(),key:"",value:""}),eg=()=>({providerID:"",name:"",protocol:"openai-chat",baseURL:"",apiKey:"",models:[vr()],headers:[yr()]});function tg(t){switch(t){case"@ai-sdk/openai":return"openai-responses";case"@ai-sdk/anthropic":return"anthropic-messages";default:return"openai-chat"}}function sg(t){const e=t.trim();if(!e)return{};const n=e.match(Xu)?.[1]?.trim();return n?{env:n}:{key:e}}function ng(t){const e=t.options&&typeof t.options=="object"?t.options:null,a=typeof e?.baseURL=="string"?e.baseURL.trim():"";return a&&zl.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)&&ng(t):!1}function Co(t){return t?.custom?.exists?"custom":t?.project?.exists?"project":"user"}function ag(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,d])=>({row:pi(),key:x,value:d})),r=Array.isArray(t.models)?t.models:t.models&&typeof t.models=="object"?Object.entries(t.models).map(([x,d])=>({id:x,name:d&&typeof d=="object"&&"name"in d&&typeof d.name=="string"?d.name:x})):[],l=r.length>0?r.map(x=>({row:pi(),id:typeof x?.id=="string"?x.id:"",name:typeof x?.name=="string"?x.name:typeof x?.id=="string"?x.id:""})):[vr()],u=Array.isArray(t.env)?t.env.find(x=>typeof x=="string"&&x.trim().length>0)?.trim():void 0,g=r.find(x=>"api"in x);return{providerID:t.id,name:typeof t.name=="string"&&t.name.trim()?t.name:t.id,protocol:tg(g?.api?.npm),baseURL:a,apiKey:u?`{env:${u}}`:"",models:l,headers:i.length>0?i:[yr()]}}function ig(t){const e=t.form.providerID.trim(),a=t.form.name.trim(),n=t.form.baseURL.trim(),{env:i,key:r}=sg(t.form.apiKey),l=t.disabledProviders??[],u=t.editingProviderID?.trim(),g=e?Yu.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"),d=n?zl.test(n)?void 0:t.t("settings.providers.page.custom.error.baseURL.format"):t.t("settings.providers.page.custom.error.baseURL.required"),c=!!(i||r||u&&t.allowExistingAuth&&u===e)?void 0:t.t("settings.providers.page.custom.error.apiKey.required"),N=l.includes(e),C=g||!!(u&&u===e)?void 0:t.existingProviderIDs.has(e)&&!N?t.t("settings.providers.page.custom.error.providerID.exists"):void 0,k=new Set,A=t.form.models.map(S=>{const M=S.id.trim(),j=M?k.has(M)?t.t("settings.providers.page.custom.error.duplicate"):void k.add(M):t.t("settings.providers.page.custom.error.required"),R=S.name.trim()?void 0:t.t("settings.providers.page.custom.error.required");return{id:j,name:R}}),h=A.every(S=>!S.id&&!S.name),E=Object.fromEntries(t.form.models.map(S=>[S.id.trim(),{name:S.name.trim()}])),F=new Set,I=t.form.headers.map(S=>{const M=S.key.trim(),j=S.value.trim();if(!M&&!j)return{};const R=M?F.has(M.toLowerCase())?t.t("settings.providers.page.custom.error.duplicate"):void F.add(M.toLowerCase()):t.t("settings.providers.page.custom.error.required"),H=j?void 0:t.t("settings.providers.page.custom.error.required");return{key:R,value:H}}),w=I.every(S=>!S.key&&!S.value),m=Object.fromEntries(t.form.headers.map(S=>({key:S.key.trim(),value:S.value.trim()})).filter(S=>S.key&&S.value).map(S=>[S.key,S.value])),y={providerID:g??C,name:x,baseURL:d,apiKey:c};return!g&&!C&&!x&&!d&&!c&&h&&w?{err:y,models:A,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:A,headers:I}}function rg(t){return t.apiKey?{providerID:t.providerID,auth:{type:"api",key:t.apiKey}}:null}function og(t,e){return{providerID:t.providerID,config:t.config,scope:e?.scope??"user"}}const Po=t=>{const e=lt.c(234),{existingProviderIDs:a,disabledProviders:n,busy:i,mode:r,initialValues:l,allowExistingAuth:u,authFailureHint:g,onSubmit:x,onCancel:d,onDisconnect:v}=t;let c;e[0]!==n?(c=n===void 0?[]:n,e[0]=n,e[1]=c):c=e[1];const N=c,b=i===void 0?!1:i,C=r===void 0?"create":r,k=u===void 0?!1:u,A=g===void 0?null:g,{t:h}=nt(),E=C==="edit";let F;e[2]!==l?(F=()=>l??eg(),e[2]=l,e[3]=F):F=e[3];const[I,w]=o.useState(F);let m;e[4]===Symbol.for("react.memo_cache_sentinel")?(m={},e[4]=m):m=e[4];const[y,U]=o.useState(m);let S;e[5]===Symbol.for("react.memo_cache_sentinel")?(S=[],e[5]=S):S=e[5];const[M,j]=o.useState(S);let R;e[6]===Symbol.for("react.memo_cache_sentinel")?(R=[],e[6]=R):R=e[6];const[H,P]=o.useState(R),G=o.useRef(null);let J,T;e[7]!==l||e[8]!==E?(J=()=>{l&&(E&&G.current===l.providerID||(G.current=E?l.providerID:null,w(l),U({}),j([]),P([])))},T=[l,E],e[7]=l,e[8]=E,e[9]=J,e[10]=T):(J=e[9],T=e[10]),o.useEffect(J,T);let W;e[11]===Symbol.for("react.memo_cache_sentinel")?(W=(St,Pt)=>{w(_t=>({..._t,[St]:Pt})),U(_t=>({..._t,[St]:void 0}))},e[11]=W):W=e[11];const X=W;let K;e[12]===Symbol.for("react.memo_cache_sentinel")?(K=(St,Pt,_t)=>{w(Mt=>({...Mt,models:Mt.models.map((is,As)=>As===St?{...is,[Pt]:_t}:is)})),j(Mt=>{const is=[...Mt];return is[St]={...is[St]??{},[Pt]:void 0},is})},e[12]=K):K=e[12];const te=K;let $;e[13]===Symbol.for("react.memo_cache_sentinel")?($=(St,Pt,_t)=>{w(Mt=>({...Mt,headers:Mt.headers.map((is,As)=>As===St?{...is,[Pt]:_t}:is)})),P(Mt=>{const is=[...Mt];return is[St]={...is[St]??{},[Pt]:void 0},is})},e[13]=$):$=e[13];const V=$;let _;e[14]!==k||e[15]!==b||e[16]!==N||e[17]!==a||e[18]!==I||e[19]!==E||e[20]!==x||e[21]!==h?(_=async St=>{if(St.preventDefault(),b)return;const Pt=ig({form:I,t:((_t,Mt)=>h(_t,Mt)),existingProviderIDs:a,disabledProviders:N,editingProviderID:E?I.providerID:void 0,allowExistingAuth:E&&k});U(Pt.err),j(Pt.models),P(Pt.headers),Pt.result&&await x(Pt.result)},e[14]=k,e[15]=b,e[16]=N,e[17]=a,e[18]=I,e[19]=E,e[20]=x,e[21]=h,e[22]=_):_=e[22];const z=_;let Z;e[23]!==E||e[24]!==h?(Z=h(E?"settings.providers.page.custom.editTitle":"settings.providers.page.custom.title"),e[23]=E,e[24]=h,e[25]=Z):Z=e[25];let Y;e[26]!==h?(Y=h("settings.providers.page.custom.description"),e[26]=h,e[27]=Y):Y=e[27];let se;e[28]!==Y?(se=s.jsx("p",{className:Rn,children:Y}),e[28]=Y,e[29]=se):se=e[29];let ge;e[30]!==A?(ge=A?s.jsx("p",{className:"typography-meta text-[var(--status-warning)]",role:"status",children:A}):null,e[30]=A,e[31]=ge):ge=e[31];let ce;e[32]!==h?(ce=h("settings.providers.page.custom.field.providerID.label"),e[32]=h,e[33]=ce):ce=e[33];let be;e[34]!==h?(be=h("settings.providers.page.custom.field.providerID.info"),e[34]=h,e[35]=be):be=e[35];const ne=I.providerID;let ae;e[36]===Symbol.for("react.memo_cache_sentinel")?(ae=St=>X("providerID",St.target.value),e[36]=ae):ae=e[36];let me;e[37]!==h?(me=h("settings.providers.page.custom.field.providerID.placeholder"),e[37]=h,e[38]=me):me=e[38];const Pe=!E,Ne=E||b,Se=!!y.providerID;let je;e[39]!==h?(je=h("settings.providers.page.custom.field.providerID.label"),e[39]=h,e[40]=je):je=e[40];let Me;e[41]!==I.providerID||e[42]!==me||e[43]!==Pe||e[44]!==Ne||e[45]!==Se||e[46]!==je?(Me=s.jsx(We,{value:ne,onChange:ae,placeholder:me,className:"h-8 rounded-md px-3 font-mono text-xs",autoFocus:Pe,disabled:Ne,"aria-invalid":Se,"aria-label":je}),e[41]=I.providerID,e[42]=me,e[43]=Pe,e[44]=Ne,e[45]=Se,e[46]=je,e[47]=Me):Me=e[47];let Re;e[48]!==y.providerID?(Re=y.providerID?s.jsx("p",{className:"mt-1 typography-meta text-[var(--status-error)]",children:y.providerID}):null,e[48]=y.providerID,e[49]=Re):Re=e[49];let re;e[50]!==ce||e[51]!==be||e[52]!==Me||e[53]!==Re?(re=s.jsxs(Wt,{label:ce,info:be,children:[Me,Re]}),e[50]=ce,e[51]=be,e[52]=Me,e[53]=Re,e[54]=re):re=e[54];let fe;e[55]!==h?(fe=h("settings.providers.page.custom.field.protocol.label"),e[55]=h,e[56]=fe):fe=e[56];let Ee;e[57]!==h?(Ee=h("settings.providers.page.custom.field.protocol.info"),e[57]=h,e[58]=Ee):Ee=e[58];const Be=I.protocol;let Ve;e[59]===Symbol.for("react.memo_cache_sentinel")?(Ve=St=>{St in br&&w(Pt=>({...Pt,protocol:St}))},e[59]=Ve):Ve=e[59];let Ge;e[60]!==h?(Ge=h("settings.providers.page.custom.field.protocol.label"),e[60]=h,e[61]=Ge):Ge=e[61];let Ke;e[62]===Symbol.for("react.memo_cache_sentinel")?(Ke=s.jsx(Ft,{}),e[62]=Ke):Ke=e[62];let oe;e[63]!==Ge?(oe=s.jsx(Et,{"aria-label":Ge,className:"w-full",children:Ke}),e[63]=Ge,e[64]=oe):oe=e[64];let ie;e[65]!==h?(ie=h("settings.providers.page.custom.field.protocol.openaiChat"),e[65]=h,e[66]=ie):ie=e[66];let ye;e[67]!==ie?(ye=s.jsx(ot,{value:"openai-chat",children:ie}),e[67]=ie,e[68]=ye):ye=e[68];let ve;e[69]!==h?(ve=h("settings.providers.page.custom.field.protocol.openaiResponses"),e[69]=h,e[70]=ve):ve=e[70];let Oe;e[71]!==ve?(Oe=s.jsx(ot,{value:"openai-responses",children:ve}),e[71]=ve,e[72]=Oe):Oe=e[72];let Te;e[73]!==h?(Te=h("settings.providers.page.custom.field.protocol.anthropicMessages"),e[73]=h,e[74]=Te):Te=e[74];let xe;e[75]!==Te?(xe=s.jsx(ot,{value:"anthropic-messages",children:Te}),e[75]=Te,e[76]=xe):xe=e[76];let He;e[77]!==ye||e[78]!==Oe||e[79]!==xe?(He=s.jsxs(Tt,{children:[ye,Oe,xe]}),e[77]=ye,e[78]=Oe,e[79]=xe,e[80]=He):He=e[80];let ue;e[81]!==b||e[82]!==I.protocol||e[83]!==oe||e[84]!==He?(ue=s.jsxs(At,{value:Be,onValueChange:Ve,disabled:b,children:[oe,He]}),e[81]=b,e[82]=I.protocol,e[83]=oe,e[84]=He,e[85]=ue):ue=e[85];let Ie;e[86]!==fe||e[87]!==Ee||e[88]!==ue?(Ie=s.jsx(Wt,{label:fe,info:Ee,children:ue}),e[86]=fe,e[87]=Ee,e[88]=ue,e[89]=Ie):Ie=e[89];let Le;e[90]!==h?(Le=h("settings.providers.page.custom.field.name.label"),e[90]=h,e[91]=Le):Le=e[91];let Ye;e[92]!==h?(Ye=h("settings.providers.page.custom.field.name.info"),e[92]=h,e[93]=Ye):Ye=e[93];const q=I.name;let ke;e[94]===Symbol.for("react.memo_cache_sentinel")?(ke=St=>X("name",St.target.value),e[94]=ke):ke=e[94];let O;e[95]!==h?(O=h("settings.providers.page.custom.field.name.placeholder"),e[95]=h,e[96]=O):O=e[96];const Ce=!!y.name;let qe;e[97]!==h?(qe=h("settings.providers.page.custom.field.name.label"),e[97]=h,e[98]=qe):qe=e[98];let _e;e[99]!==I.name||e[100]!==O||e[101]!==Ce||e[102]!==qe?(_e=s.jsx(We,{value:q,onChange:ke,placeholder:O,className:"h-8 rounded-md px-3","aria-invalid":Ce,"aria-label":qe}),e[99]=I.name,e[100]=O,e[101]=Ce,e[102]=qe,e[103]=_e):_e=e[103];let tt;e[104]!==y.name?(tt=y.name?s.jsx("p",{className:"mt-1 typography-meta text-[var(--status-error)]",children:y.name}):null,e[104]=y.name,e[105]=tt):tt=e[105];let ht;e[106]!==Le||e[107]!==Ye||e[108]!==_e||e[109]!==tt?(ht=s.jsxs(Wt,{label:Le,info:Ye,children:[_e,tt]}),e[106]=Le,e[107]=Ye,e[108]=_e,e[109]=tt,e[110]=ht):ht=e[110];let mt;e[111]!==h?(mt=h("settings.providers.page.custom.field.baseURL.label"),e[111]=h,e[112]=mt):mt=e[112];let ut;e[113]!==h?(ut=h("settings.providers.page.custom.field.baseURL.info"),e[113]=h,e[114]=ut):ut=e[114];const ft=I.baseURL;let kt;e[115]===Symbol.for("react.memo_cache_sentinel")?(kt=St=>X("baseURL",St.target.value),e[115]=kt):kt=e[115];let vt;e[116]!==h?(vt=h("settings.providers.page.custom.field.baseURL.placeholder"),e[116]=h,e[117]=vt):vt=e[117];const Ct=!!y.baseURL;let Ze;e[118]!==h?(Ze=h("settings.providers.page.custom.field.baseURL.label"),e[118]=h,e[119]=Ze):Ze=e[119];let Xe;e[120]!==I.baseURL||e[121]!==vt||e[122]!==Ct||e[123]!==Ze?(Xe=s.jsx(We,{value:ft,onChange:kt,placeholder:vt,className:"h-8 rounded-md px-3 font-mono text-xs","aria-invalid":Ct,"aria-label":Ze}),e[120]=I.baseURL,e[121]=vt,e[122]=Ct,e[123]=Ze,e[124]=Xe):Xe=e[124];let ct;e[125]!==y.baseURL?(ct=y.baseURL?s.jsx("p",{className:"mt-1 typography-meta text-[var(--status-error)]",children:y.baseURL}):null,e[125]=y.baseURL,e[126]=ct):ct=e[126];let Ue;e[127]!==mt||e[128]!==ut||e[129]!==Xe||e[130]!==ct?(Ue=s.jsxs(Wt,{label:mt,info:ut,children:[Xe,ct]}),e[127]=mt,e[128]=ut,e[129]=Xe,e[130]=ct,e[131]=Ue):Ue=e[131];let jt;e[132]!==h?(jt=h("settings.providers.page.custom.field.apiKey.label"),e[132]=h,e[133]=jt):jt=e[133];let Ae;e[134]!==k||e[135]!==E||e[136]!==h?(Ae=h(E&&k?"settings.providers.page.custom.field.apiKey.editInfo":"settings.providers.page.custom.field.apiKey.info"),e[134]=k,e[135]=E,e[136]=h,e[137]=Ae):Ae=e[137];const yt=I.apiKey;let Q;e[138]===Symbol.for("react.memo_cache_sentinel")?(Q=St=>X("apiKey",St.target.value),e[138]=Q):Q=e[138];let he;e[139]!==k||e[140]!==E||e[141]!==h?(he=h(E&&k?"settings.providers.page.custom.field.apiKey.editPlaceholder":"settings.providers.page.custom.field.apiKey.placeholder"),e[139]=k,e[140]=E,e[141]=h,e[142]=he):he=e[142];const ze=!!y.apiKey;let De;e[143]!==h?(De=h("settings.providers.page.custom.field.apiKey.label"),e[143]=h,e[144]=De):De=e[144];let it;e[145]!==I.apiKey||e[146]!==he||e[147]!==ze||e[148]!==De?(it=s.jsx(We,{type:"password",value:yt,onChange:Q,placeholder:he,className:"h-8 rounded-md px-3 font-mono text-xs","aria-invalid":ze,"aria-label":De}),e[145]=I.apiKey,e[146]=he,e[147]=ze,e[148]=De,e[149]=it):it=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]!==jt||e[153]!==Ae||e[154]!==it||e[155]!==at?(Je=s.jsxs(Wt,{label:jt,info:Ae,children:[it,at]}),e[152]=jt,e[153]=Ae,e[154]=it,e[155]=at,e[156]=Je):Je=e[156];let Nt;e[157]!==Z||e[158]!==se||e[159]!==ge||e[160]!==re||e[161]!==Ie||e[162]!==ht||e[163]!==Ue||e[164]!==Je?(Nt=s.jsxs($e,{title:Z,divider:!1,settingsItem:"providers.custom",contentClassName:Nn,children:[se,ge,re,Ie,ht,Ue,Je]}),e[157]=Z,e[158]=se,e[159]=ge,e[160]=re,e[161]=Ie,e[162]=ht,e[163]=Ue,e[164]=Je,e[165]=Nt):Nt=e[165];let xs;e[166]!==h?(xs=h("settings.providers.page.custom.models.title"),e[166]=h,e[167]=xs):xs=e[167];let ts;if(e[168]!==I.models||e[169]!==M||e[170]!==h){let St;e[172]!==I.models.length||e[173]!==M||e[174]!==h?(St=(Pt,_t)=>s.jsx("div",{className:`${Us} 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:It,children:h("settings.providers.page.custom.models.idLabel")}),s.jsx(We,{value:Pt.id,onChange:Mt=>te(_t,"id",Mt.target.value),placeholder:h("settings.providers.page.custom.models.idPlaceholder"),className:"mt-1 h-8 rounded-md px-3 font-mono text-xs","aria-label":h("settings.providers.page.custom.models.idLabel")}),M[_t]?.id?s.jsx("p",{className:"mt-1 typography-meta text-[var(--status-error)]",children:M[_t]?.id}):null]}),s.jsxs("div",{children:[s.jsx("label",{className:It,children:h("settings.providers.page.custom.models.nameLabel")}),s.jsx(We,{value:Pt.name,onChange:Mt=>te(_t,"name",Mt.target.value),placeholder:h("settings.providers.page.custom.models.namePlaceholder"),className:"mt-1 h-8 rounded-md px-3","aria-label":h("settings.providers.page.custom.models.nameLabel")}),M[_t]?.name?s.jsx("p",{className:"mt-1 typography-meta text-[var(--status-error)]",children:M[_t]?.name}):null]})]}),s.jsx(B,{type:"button",variant:"ghost",size:"icon",className:hs,disabled:I.models.length<=1,onClick:()=>{I.models.length<=1||(w(Mt=>({...Mt,models:Mt.models.filter((is,As)=>As!==_t)})),j(Mt=>Mt.filter((is,As)=>As!==_t)))},"aria-label":h("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]=M,e[174]=h,e[175]=St):St=e[175],ts=I.models.map(St),e[168]=I.models,e[169]=M,e[170]=h,e[171]=ts}else ts=e[171];let Ms;e[176]===Symbol.for("react.memo_cache_sentinel")?(Ms=()=>{w(lg),j(cg)},e[176]=Ms):Ms=e[176];let Bt;e[177]!==h?(Bt=h("settings.providers.page.custom.models.add"),e[177]=h,e[178]=Bt):Bt=e[178];let os;e[179]!==Bt?(os=s.jsx(B,{type:"button",variant:"outline",size:"xs",className:"!font-normal",onClick:Ms,children:Bt}),e[179]=Bt,e[180]=os):os=e[180];let qt;e[181]!==xs||e[182]!==ts||e[183]!==os?(qt=s.jsxs($e,{title:xs,contentClassName:Nn,children:[ts,os]}),e[181]=xs,e[182]=ts,e[183]=os,e[184]=qt):qt=e[184];let bs;e[185]!==h?(bs=h("settings.providers.page.custom.headers.title"),e[185]=h,e[186]=bs):bs=e[186];let ms;e[187]!==h?(ms=h("settings.providers.page.custom.headers.description"),e[187]=h,e[188]=ms):ms=e[188];let vs;e[189]!==ms?(vs=s.jsx("p",{className:Rn,children:ms}),e[189]=ms,e[190]=vs):vs=e[190];let us;if(e[191]!==I.headers||e[192]!==H||e[193]!==h){let St;e[195]!==I.headers.length||e[196]!==H||e[197]!==h?(St=(Pt,_t)=>s.jsx("div",{className:`${Us} 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:It,children:h("settings.providers.page.custom.headers.keyLabel")}),s.jsx(We,{value:Pt.key,onChange:Mt=>V(_t,"key",Mt.target.value),placeholder:h("settings.providers.page.custom.headers.keyPlaceholder"),className:"mt-1 h-8 rounded-md px-3 font-mono text-xs","aria-label":h("settings.providers.page.custom.headers.keyLabel")}),H[_t]?.key?s.jsx("p",{className:"mt-1 typography-meta text-[var(--status-error)]",children:H[_t]?.key}):null]}),s.jsxs("div",{children:[s.jsx("label",{className:It,children:h("settings.providers.page.custom.headers.valueLabel")}),s.jsx(We,{value:Pt.value,onChange:Mt=>V(_t,"value",Mt.target.value),placeholder:h("settings.providers.page.custom.headers.valuePlaceholder"),className:"mt-1 h-8 rounded-md px-3 font-mono text-xs","aria-label":h("settings.providers.page.custom.headers.valueLabel")}),H[_t]?.value?s.jsx("p",{className:"mt-1 typography-meta text-[var(--status-error)]",children:H[_t]?.value}):null]})]}),s.jsx(B,{type:"button",variant:"ghost",size:"icon",className:hs,disabled:I.headers.length<=1,onClick:()=>{I.headers.length<=1||(w(Mt=>({...Mt,headers:Mt.headers.filter((is,As)=>As!==_t)})),P(Mt=>Mt.filter((is,As)=>As!==_t)))},"aria-label":h("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]=H,e[197]=h,e[198]=St):St=e[198],us=I.headers.map(St),e[191]=I.headers,e[192]=H,e[193]=h,e[194]=us}else us=e[194];let ys;e[199]===Symbol.for("react.memo_cache_sentinel")?(ys=()=>{w(dg),P(pg)},e[199]=ys):ys=e[199];let le;e[200]!==h?(le=h("settings.providers.page.custom.headers.add"),e[200]=h,e[201]=le):le=e[201];let dt;e[202]!==le?(dt=s.jsx(B,{type:"button",variant:"outline",size:"xs",className:"!font-normal",onClick:ys,children:le}),e[202]=le,e[203]=dt):dt=e[203];let bt;e[204]!==bs||e[205]!==vs||e[206]!==us||e[207]!==dt?(bt=s.jsxs($e,{title:bs,contentClassName:Nn,children:[vs,us,dt]}),e[204]=bs,e[205]=vs,e[206]=us,e[207]=dt,e[208]=bt):bt=e[208];let Qt;e[209]!==b||e[210]!==d||e[211]!==h?(Qt=d?s.jsx(B,{type:"button",variant:"outline",size:"xs",className:"!font-normal",onClick:d,disabled:b,children:h("settings.providers.page.custom.actions.back")}):null,e[209]=b,e[210]=d,e[211]=h,e[212]=Qt):Qt=e[212];let Yt;e[213]!==b||e[214]!==v||e[215]!==h?(Yt=v?s.jsx(B,{type:"button",variant:"destructive",size:"xs",className:"!font-normal",onClick:()=>{v()},disabled:b,children:h("settings.providers.page.actions.disconnect")}):null,e[213]=b,e[214]=v,e[215]=h,e[216]=Yt):Yt=e[216];let Ht;e[217]!==b||e[218]!==E||e[219]!==h?(Ht=h(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]=h,e[220]=Ht):Ht=e[220];let as;e[221]!==b||e[222]!==Ht?(as=s.jsx(B,{type:"submit",size:"xs",className:"!font-normal",disabled:b,children:Ht}),e[221]=b,e[222]=Ht,e[223]=as):as=e[223];let js;e[224]!==Qt||e[225]!==Yt||e[226]!==as?(js=s.jsxs("div",{className:"flex flex-wrap items-center gap-2 py-4",children:[Qt,Yt,as]}),e[224]=Qt,e[225]=Yt,e[226]=as,e[227]=js):js=e[227];let ls;return e[228]!==z||e[229]!==Nt||e[230]!==qt||e[231]!==bt||e[232]!==js?(ls=s.jsxs("form",{onSubmit:z,className:"space-y-0",children:[Nt,qt,bt,js]}),e[228]=z,e[229]=Nt,e[230]=qt,e[231]=bt,e[232]=js,e[233]=ls):ls=e[233],ls};function lg(t){return{...t,models:[...t.models,vr()]}}function cg(t){return[...t,{}]}function dg(t){return{...t,headers:[...t.headers,yr()]}}function pg(t){return[...t,{}]}const mg=(t,e)=>!!e&&t!=="claude-code",ug=/[A-Z0-9]{4}-[A-Z0-9]{4,5}/,Wn=t=>typeof t=="object"&&t!==null&&!Array.isArray(t),Ns=t=>typeof t=="string"&&t.length>0?t:void 0,gg=t=>{if(!Array.isArray(t))return[];const e=[];for(const a of t){if(!Wn(a))continue;const n=Ns(a.value);n!==void 0&&e.push({value:n,label:Ns(a.label)??n,...Ns(a.hint)?{hint:Ns(a.hint)}:{}})}return e},hg=t=>{if(!Wn(t))return;const e=Ns(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}},fg=t=>{if(!Array.isArray(t))return[];const e=[];for(const a of t){if(!Wn(a))continue;const n=Ns(a.key);if(!n)continue;const i=a.type==="select"?"select":"text",r=i==="select"?gg(a.options):[];if(i==="select"&&r.length===0)continue;const l=hg(a.when);e.push({type:i,key:n,message:Ns(a.message)??n,options:r,...Ns(a.placeholder)?{placeholder:Ns(a.placeholder)}:{},...l?{when:l}:{}})}return e},xg=(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=>xg(a,e)),bg=t=>{const e={};for(const a of t)e[a.key]=a.type==="select"?a.options[0]?.value??"":"";return e},vg=(t,e)=>jr(t,e).find(a=>(e[a.key]??"").trim().length===0)??null,yg=(t,e)=>{const a={};for(const n of jr(t,e))a[n.key]=(e[n.key]??"").trim();return a},jg=t=>{const e=Wn(t)?t:{},a=Wn(e.data)?e.data:e,n=Ns(a.url)??Ns(a.verification_uri_complete)??Ns(a.verification_uri),i=Ns(a.instructions)??Ns(a.message);if(!n&&!i)return null;const r=Ns(a.user_code)??Ns(a.userCode)??(i?ug.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=Wn(t)?t:{},i=Wn(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 Ns(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}=nt(),[r,l]=o.useState(Ki),[u,g]=o.useState({}),[x,d]=o.useState(""),v=o.useRef(null);o.useEffect(()=>()=>v.current?.abort(),[]);const c=r.phase==="idle"?null:r.methodIndex,N=r.phase==="authorizing"||r.phase==="waiting"||r.phase==="awaitingCode"&&r.submitting,b=async(m,y,U)=>{const S=await Ma(m);if(S.ok){D.success(i(y));return}console.error("Failed to copy OAuth value:",S.error),D.error(i(U))},C=async(m,y)=>{const U=new AbortController;v.current?.abort(),v.current=U;try{const S=await un.getSdkClient().provider.oauth.callback({providerID:t,method:m,...y?{code:y}:{}},{signal:U.signal});if(U.signal.aborted)return;if(S.error)throw S.error;l(Ki),D.success(i("settings.providers.page.toast.oauthCompleted")),await a()}catch(S){if(U.signal.aborted)return;console.error("Failed to complete OAuth flow:",S),l({phase:"failed",methodIndex:m,message:Io(S,i,"settings.providers.page.toast.oauthCompleteFailed")})}finally{v.current===U&&(v.current=null)}},k=async(m,y)=>{l({phase:"authorizing",methodIndex:m});let U;try{const S=await un.getSdkClient().provider.oauth.authorize({providerID:t,method:m,...Object.keys(y).length>0?{inputs:y}:{}});if(S.error)throw S.error;const M=jg(S.data);if(!M){l({phase:"failed",methodIndex:m,message:i("settings.providers.page.toast.oauthDetailsMissing")});return}U=M}catch(S){console.error("Failed to start OAuth flow:",S),l({phase:"failed",methodIndex:m,message:Io(S,i,"settings.providers.page.toast.oauthStartFailed")});return}if(U.url&&mg(t,U.url)&&In(U.url),U.method==="code"){d(""),l({phase:"awaitingCode",methodIndex:m,authorization:U,submitting:!1});return}l({phase:"waiting",methodIndex:m,authorization:U}),await C(m)},A=m=>{const y=fg(m.prompts);if(y.length===0){k(m.index,{});return}g(bg(y)),l({phase:"prompting",methodIndex:m.index,prompts:y,error:null})},h=()=>{if(r.phase!=="prompting")return;const m=vg(r.prompts,u);if(m){l({...r,error:i("settings.providers.page.auth.oauth.promptRequired",{field:m.message})});return}k(r.methodIndex,yg(r.prompts,u))},E=()=>{if(r.phase!=="awaitingCode")return;const m=x.trim();m&&(l({...r,submitting:!0}),C(r.methodIndex,m))},F=()=>{v.current?.abort(),v.current=null,l(Ki)},I=m=>{const y=u[m.key]??"",U=S=>g(M=>({...M,[m.key]:S}));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(At,{value:y,onValueChange:U,children:[s.jsx(Et,{size:$t,className:Cn,children:s.jsx(Ft,{children:S=>m.options.find(M=>M.value===S)?.label??null})}),s.jsx(Tt,{children:m.options.map(S=>s.jsx(ot,{value:S.value,children:S.hint?`${S.label} · ${S.hint}`:S.label},S.value))})]}):s.jsx(We,{value:y,onChange:S=>U(S.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(We,{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(We,{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:()=>{In(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:we("space-y-4",n),children:e.map(m=>{const y=c===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:()=>A(m),disabled:N,children:i("settings.providers.page.actions.connect")})]}),y&&r.phase==="prompting"&&s.jsxs("div",{className:"space-y-3",children:[jr(r.prompts,u).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:h,children:i("settings.providers.page.actions.continue")}),s.jsx(B,{variant:"ghost",size:"xs",className:"!font-normal",onClick:F,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:F,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(We,{value:x,onChange:U=>d(U.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:F,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:()=>A(m),children:i("settings.providers.page.actions.tryAgain")})]})]},m.index)})})},Eo=t=>Array.isArray(t?.env)&&t.env.some(e=>e.trim().length>0),wg=t=>new Intl.NumberFormat(ur(),{notation:"compact",compactDisplay:"short",maximumFractionDigits:1,minimumFractionDigits:0}).format(t),To=t=>{if(typeof t!="number"||Number.isNaN(t))return null;if(t===0)return"0";const e=wg(t);return e.endsWith(".0")?e.slice(0,-2):e},Ca="__add_provider__",_l=t=>typeof t=="object"&&t!==null,Do=(t,e)=>t.map(({method:a,methodIndex:n})=>({index:n,label:a.label||a.name||e(n),prompts:a.prompts})),kg=t=>{if(typeof t=="string")return{id:t};if(!_l(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}},Ng=t=>{let e=[];Array.isArray(t)?e=t:_l(t)&&(Array.isArray(t.all)?e=t.all:Array.isArray(t.providers)&&(e=t.providers));const a=e.map(i=>kg(i)).filter(i=>!!i),n=new Set;return a.filter(i=>n.has(i.id)?!1:(n.add(i.id),!0))},Sg=()=>{const{t}=nt(),e=zs(),a=et(q=>gl(q,e)),n=et(q=>q.selectedProviderId),i=et(q=>q.setSelectedProvider),r=et(q=>q.getModelMetadata),l=de(q=>q.hiddenModels),u=de(q=>q.toggleHiddenModel),g=de(q=>q.hideAllModels),x=de(q=>q.showAllModels),[d,v]=o.useState({}),[c,N]=o.useState(!1),[b,C]=o.useState({}),[k,A]=o.useState(null),[h,E]=o.useState(""),[F,I]=o.useState([]),[w,m]=o.useState(!1),[y,U]=o.useState(null),[S,M]=o.useState(""),[j,R]=o.useState(""),[H,P]=o.useState(!1),[G,J]=o.useState({}),[T,W]=o.useState(0),[X,K]=o.useState(!1),[te,$]=o.useState(null),[V,_]=o.useState(null),[z,Z]=o.useState(null),[Y,se]=o.useState(null),[ge,ce]=o.useState(null),[be,ne]=o.useState(null),ae=n===Ca,me=ae&&S===Mn,Pe=!!(V&&n&&V===n&&!ae);o.useEffect(()=>{!n&&a.length>0&&i(a[0].id)},[a,n,i]),o.useEffect(()=>{if(!n)return;let q=!0;return(async()=>{N(!0);try{const O=await un.getSdkClient().provider.auth();if(O.error)throw new Error(`provider.auth failed: ${String(O.error)}`);if(!q)return;v(qu(O.data))}catch(O){if(!q)return;console.error("Failed to load provider auth methods:",O),D.error(t("settings.providers.page.toast.authMethodsLoadFailed"))}finally{q&&N(!1)}})(),()=>{q=!1}},[n,t]),o.useEffect(()=>{if(!Hu(ae))return;let q=!0;return(async()=>{m(!0),U(null);try{const O=await un.getSdkClient().provider.list();if(O.error)throw new Error(`provider.list failed: ${String(O.error)}`);if(!q)return;I(Ng(O.data))}catch(O){if(!q)return;console.error("Failed to load available providers:",O),U(t("settings.providers.page.state.unableToLoadProviderList"))}finally{q&&m(!1)}})(),()=>{q=!1}},[ae,t]);const Ne=o.useMemo(()=>new Set(a.map(q=>q.id)),[a]),Se=o.useMemo(()=>F.filter(q=>!Ne.has(q.id)).sort((q,ke)=>{const O=(q.name||q.id).toLowerCase(),Ce=(ke.name||ke.id).toLowerCase();return O.localeCompare(Ce)}),[F,Ne]);o.useEffect(()=>{n===Ca&&S&&S!==Mn&&!Se.some(q=>q.id===S)&&M("")},[n,S,Se]),o.useEffect(()=>{if(n===Ca){K(!0),$(null),_(null),Z(null),se(null),ce(null);return}K(!1),$(null),V&&V!==n&&(_(null),Z(null),se(null),ce(null))},[n,V]),o.useEffect(()=>{if(!n||n===Ca)return;const q=G[n];if(!q)return;const ke=a.find(qe=>qe.id===n),O=No({key:ke?.key,authSourceExists:q.auth.exists,optionsApiKey:ke?.options?.apiKey??null,envDeclared:Eo(ke)}),Ce=!!(ke&&So(ke,q));Qu({hasCredentials:O,userDismissed:te===n,isEditableCustomProvider:Ce})&&K(!0)},[n,G,a,te]),o.useEffect(()=>{if(!n||n===Ca)return;let q=!1;return(async()=>{try{const O=e?`?directory=${encodeURIComponent(e)}`:"",Ce=await rt(`/api/provider/${encodeURIComponent(n)}/source${O}`,{method:"GET",headers:{Accept:"application/json"}}),qe=await Ce.json().catch(()=>null);if(!Ce.ok)throw new Error(qe?.error||t("settings.providers.page.toast.providerSourcesLoadFailed"));const _e=qe?.sources??qe?.data?.sources;!q&&_e&&J(tt=>({...tt,[n]:_e}))}catch(O){q||console.error("Failed to load provider sources:",O)}})(),()=>{q=!0}},[n,T,e,t]);const je=o.useCallback(()=>{W(q=>q+1)},[]),Me=o.useCallback(q=>{J(ke=>{const O=ke[q];return{...ke,[q]:{auth:{exists:!0,path:O?.auth.path??null},user:O?.user??{exists:!1,path:null},project:O?.project??{exists:!1,path:null},...O?.custom?{custom:O.custom}:{}}}}),$(null),K(!1),i(q),je()},[je,i]),Re=o.useCallback(async(q,ke)=>{try{return await hl({scopes:[q],mode:"active"}),"reloaded"}catch(O){if(O?.requiresManualRestart===!0)return ke&&Fn(q,{id:ke}),"manual-restart";throw O}},[]),re=a.find(q=>q.id===n),fe=n?G[n]:void 0,Ee=async q=>{const ke=b[q]?.trim()??"";if(!ke){D.error(t("settings.providers.page.toast.apiKeyRequired"));return}const O=`api:${q}`;A(O);try{if((await un.getSdkClient().auth.set({providerID:q,auth:{type:"api",key:ke}})).error)throw new Error(t("settings.providers.page.toast.apiKeySaveFailed"));D.success(t("settings.providers.page.toast.apiKeySaved")),C(qe=>({...qe,[q]:""})),await Re("providers",q),Me(q)}catch(Ce){console.error("Failed to save API key:",Ce),D.error(t("settings.providers.page.toast.apiKeySaveFailed"))}finally{A(null)}},Be=async q=>{const ke=`custom:${q.providerID}`;A(ke),ne(q.providerID),ce(null);try{const O=rg(q);if(O&&(await un.getSdkClient().auth.set(O)).error)throw new Error(t("settings.providers.page.toast.apiKeySaveFailed"));const Ce=og(q,{scope:V?Y??Co(G[V]):"user"}),qe=await rt(`/api/provider${e?`?directory=${encodeURIComponent(e)}`:""}`,{method:"PUT",headers:{Accept:"application/json","Content-Type":"application/json"},body:JSON.stringify(Ce)}),_e=await qe.json().catch(()=>null);if(!qe.ok)throw O&&ce(t("settings.providers.page.custom.authFailure.configAfterAuth")),new Error(_e?.error||t("settings.providers.page.toast.customProviderSaveFailed"));D.success(t("settings.providers.page.toast.customProviderSaved",{provider:q.name})),M(""),_(null),Z(null),se(null),ce(null),ne(null),await Re("providers",q.providerID),Me(q.providerID)}catch(O){console.error("Failed to save custom provider:",O),D.error(O instanceof Error&&O.message?O.message:t("settings.providers.page.toast.customProviderSaveFailed"))}finally{A(null)}},Ve=q=>t("settings.providers.page.auth.oauthMethodFallback",{index:String(q+1)}),Ge=q=>{K(!1),Wu(q)&&Fn("providers",{id:q}),Me(q)},Ke=async q=>{const ke=`disconnect:${q}`;A(ke);try{const O=await rt(`/api/provider/${encodeURIComponent(q)}/auth?scope=all${e?`&directory=${encodeURIComponent(e)}`:""}`,{method:"DELETE",headers:{Accept:"application/json"}}),Ce=await O.json().catch(()=>null);if(!O.ok)throw new Error(Ce?.error||t("settings.providers.page.toast.providerDisconnectFailed"));D.success(t("settings.providers.page.toast.providerDisconnected")),await Re("providers",q),$(null),je()}catch(O){console.error("Failed to disconnect provider:",O),D.error(t("settings.providers.page.toast.providerDisconnectFailed"))}finally{A(null)}},oe=async q=>{q&&(await Ke(q),_(null),Z(null),se(null),ce(null),ne(null),M(""))};if(!ae&&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(ae)return s.jsxs(ns,{title:t("settings.providers.page.connect.title"),showSaveStatus:!1,children:[s.jsx($e,{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(tn,{open:H,onOpenChange:q=>{P(q),q||R("")},children:[s.jsx(Zs,{asChild:!0,children:s.jsxs("button",{type:"button",className:Sn,children:[s.jsxs("span",{className:"flex items-center gap-2 min-w-0",children:[S&&S!==Mn?s.jsx(On,{providerId:S,className:"h-3.5 w-3.5 flex-shrink-0"}):null,s.jsx("span",{className:we("truncate typography-ui-label font-normal",S?"text-foreground":"text-muted-foreground"),children:S===Mn?t("settings.providers.page.custom.optionLabel"):S?Se.find(q=>q.id===S)?.name||S: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(en,{align:"start",className:"w-[280px] p-0",onCloseAutoFocus:q=>q.preventDefault(),children:[s.jsxs("div",{className:"flex items-center gap-2 border-b border-[var(--surface-subtle)] px-3 py-2",onKeyDown:q=>q.stopPropagation(),children:[s.jsx(L,{name:"search",className:"h-4 w-4 text-muted-foreground"}),s.jsx("input",{type:"text",value:j,onChange:q=>R(q.target.value),onKeyDown:q=>q.stopPropagation(),placeholder:t("settings.providers.page.connect.searchProvidersPlaceholder"),className:"flex-1 bg-transparent typography-meta outline-none placeholder:text-muted-foreground",autoFocus:!0})]}),s.jsx(Vs,{outerClassName:"max-h-[240px]",className:"p-1",children:(()=>{const q=t("settings.providers.page.custom.optionLabel"),ke=Nc([q,"other","custom"],j),O=li(Se,j,Ce=>[Ce.name||Ce.id,Ce.id]);return O.length===0&&!ke?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:[O.map(Ce=>s.jsxs(sn,{onSelect:()=>{M(Ce.id),P(!1),R("")},className:"flex items-center justify-between",children:[s.jsxs("span",{className:"flex items-center gap-2 min-w-0",children:[s.jsx(On,{providerId:Ce.id,className:"h-4 w-4 flex-shrink-0"}),s.jsx("span",{className:"truncate",children:Ce.name||Ce.id})]}),S===Ce.id&&s.jsx(L,{name:"check",className:"h-4 w-4 text-[var(--primary-base)]"})]},Ce.id)),ke?s.jsxs(sn,{onSelect:()=>{M(Mn),P(!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:q})]}),S===Mn&&s.jsx(L,{name:"check",className:"h-4 w-4 text-[var(--primary-base)]"})]},Mn):null]})})()})]})]})]})}),me?s.jsx(Po,{mode:"create",existingProviderIDs:Ne,busy:k?.startsWith("custom:")??!1,authFailureHint:ge,onCancel:()=>{M(""),ce(null),ne(null)},onDisconnect:ge&&be?()=>{oe(be)}:void 0,onSubmit:Be}):S?s.jsx($e,{title:t("settings.providers.page.auth.title"),settingsItem:"providers.auth",contentClassName:"space-y-4",children:c?s.jsx("p",{className:"typography-meta text-muted-foreground",children:t("settings.providers.page.auth.loadingMethods")}):s.jsx(s.Fragment,{children:(()=>{const q=d[S]??[],ke=Do(ko(q),Ve),O=wo(q);return s.jsxs(s.Fragment,{children:[O?s.jsxs("div",{className:"py-1.5",children:[s.jsxs("label",{className:"typography-ui-label text-foreground flex items-center gap-1.5",children:[t("settings.providers.page.auth.apiKeyLabel"),s.jsx(Jt,{children:t("settings.providers.page.auth.apiKeyTooltip")})]}),s.jsxs("div",{className:"flex flex-col @xl:flex-row @xl:items-center gap-2 mt-1.5",children:[s.jsx(We,{type:"password",value:b[S]??"",onChange:Ce=>C(qe=>({...qe,[S]:Ce.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:()=>Ee(S),disabled:k===`api:${S}`,children:k===`api:${S}`?t("settings.providers.page.actions.saving"):t("settings.providers.page.actions.saveKey")})]})]}):null,ke.length>0?s.jsx(Ao,{providerId:S,methods:ke,onConnected:()=>Ge(S),className:we(O&&"border-t border-[var(--surface-subtle)] pt-2")},S):null]})})()})}):null]});if(!re)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 ie=Array.isArray(re.models)?re.models:[],ye=d[re.id]??[],ve=Do(ko(ye),Ve),Oe=wo(ye),Te=!!fe,xe=Te&&So(re,fe),He=No({key:re.key,authSourceExists:fe?.auth.exists,optionsApiKey:re.options?.apiKey??null,envDeclared:Eo(re)}),ue=Gu(Te,He,xe),Ie=Ju({modelCount:ie.length,sourcesLoaded:Te,hasCredentials:He,isEditableCustomProvider:xe}),Le=!Oe&&ve.length>0?t("settings.providers.page.auth.useReconnectHint"):t("settings.providers.page.auth.incompleteHint"),Ye=li(ie,h,q=>[typeof q?.name=="string"?q.name:"",typeof q?.id=="string"?q.id:""]);return Pe&&xe&&z?s.jsx(ns,{title:re.name||re.id,titleLeading:s.jsx(On,{providerId:re.id,className:"h-5 w-5 shrink-0"}),description:s.jsx("span",{className:"font-mono typography-settings-description text-muted-foreground",children:re.id}),showSaveStatus:!1,children:s.jsx(Po,{mode:"edit",existingProviderIDs:Ne,initialValues:z,allowExistingAuth:He||!Te,busy:k?.startsWith("custom:")??!1,authFailureHint:ge,onCancel:()=>{_(null),Z(null),se(null),ce(null),ne(null)},onDisconnect:()=>{oe(re.id)},onSubmit:Be})}):s.jsxs(ns,{title:re.name||re.id,titleLeading:s.jsx(On,{providerId:re.id,className:"h-5 w-5 shrink-0"}),description:s.jsx("span",{className:"font-mono typography-settings-description text-muted-foreground",children:re.id}),showSaveStatus:!1,children:[s.jsx($e,{title:t("settings.providers.page.auth.title"),divider:!1,headerAction:s.jsxs("div",{className:"flex items-center gap-1",children:[xe?s.jsx(B,{variant:"outline",size:"xs",className:"!font-normal",onClick:()=>{ce(null),Z(ag(re)),se(Co(fe)),_(re.id)},children:t("settings.providers.page.actions.edit")}):null,s.jsx(B,{variant:"outline",size:"xs",className:"!font-normal",onClick:()=>{const q=!X;K(q),$(q?null:re.id)},children:t(X?"settings.providers.page.actions.hide":"settings.providers.page.actions.reconnect")})]}),settingsItem:"providers.auth",children:X?c?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:[Oe?s.jsxs("div",{className:"py-1.5",children:[s.jsxs("label",{className:"typography-ui-label text-foreground flex items-center gap-1.5",children:[t("settings.providers.page.auth.apiKeyLabel"),s.jsx(Jt,{children:t("settings.providers.page.auth.apiKeyTooltip")})]}),s.jsxs("div",{className:"flex flex-col @xl:flex-row @xl:items-center gap-2 mt-1.5",children:[s.jsx(We,{type:"password",value:b[re.id]??"",onChange:q=>C(ke=>({...ke,[re.id]:q.target.value})),placeholder:t("settings.providers.page.auth.apiKeyPlaceholder"),className:"flex-1 font-mono text-xs"}),s.jsx(B,{size:"xs",className:"!font-normal shrink-0",onClick:()=>Ee(re.id),disabled:k===`api:${re.id}`,children:k===`api:${re.id}`?t("settings.providers.page.actions.saving"):t("settings.providers.page.actions.saveKey")})]})]}):null,ve.length>0&&s.jsx(Ao,{providerId:re.id,methods:ve,onConnected:()=>Ge(re.id),className:we(Oe&&"border-t border-[var(--surface-subtle)] pt-2")},re.id)]}):ue?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(Jt,{children:Le})]}):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(Jt,{children:t("settings.providers.page.auth.useReconnectHint")})]})}),s.jsx($e,{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:fe&&(fe.auth.exists||fe.user.exists||fe.project.exists||fe.custom?.exists)?s.jsxs("span",{className:"typography-meta text-muted-foreground",children:[t("settings.providers.page.connectionDetails.configuredIn")," ",[fe.auth.exists?t("settings.providers.page.connectionDetails.source.authCredentials"):null,fe.user.exists?t("settings.providers.page.connectionDetails.source.userConfig"):null,fe.project.exists?t("settings.providers.page.connectionDetails.source.projectConfig"):null,fe.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:()=>Ke(re.id),disabled:k===`disconnect:${re.id}`,children:k===`disconnect:${re.id}`?t("settings.providers.page.actions.disconnecting"):t("settings.providers.page.actions.disconnect")})]})}),Ie?s.jsxs($e,{title:t("settings.providers.page.models.title"),titleAccessory:s.jsxs("span",{className:"typography-micro text-muted-foreground font-normal",children:["(",ie.length,")"]}),headerAction:s.jsxs("div",{className:"flex items-center gap-1",children:[s.jsx(B,{variant:"outline",size:"xs",className:"!font-normal",onClick:()=>{const q=ie.map(ke=>typeof ke?.id=="string"?ke.id:"").filter(ke=>ke.length>0);g(re.id,q)},children:t("settings.providers.page.actions.hideAll")}),s.jsx(B,{variant:"outline",size:"xs",className:"!font-normal",onClick:()=>x(re.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(We,{value:h,onChange:q=>E(q.target.value),placeholder:t("settings.providers.page.models.filterPlaceholder"),className:"h-7 pl-8 w-full"})]}),Ye.length===0?s.jsx("p",{className:"typography-meta text-muted-foreground py-4 text-center",children:t("settings.providers.page.models.noModelsMatchFilter")}):s.jsx("div",{className:"divide-y divide-[var(--surface-subtle)]",children:Ye.map(q=>{const ke=typeof q?.id=="string"?q.id:"",O=typeof q?.name=="string"?q.name:ke,Ce=ke?r(re.id,ke):void 0,qe=l.some(mt=>mt.providerID===re.id&&mt.modelID===ke),_e=To(Ce?.limit?.context),tt=To(Ce?.limit?.output),ht=[];return Ce?.tool_call&&ht.push({key:"tools",icon:"tools",label:t("settings.providers.page.models.capability.toolCalling")}),Ce?.reasoning&&ht.push({key:"reasoning",icon:"brain-ai-3",label:t("settings.providers.page.models.capability.reasoning")}),Ce?.attachment&&ht.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:we("flex items-center gap-3",qe&&"opacity-50"),children:[s.jsx("span",{className:"typography-meta font-medium text-foreground truncate flex-1 min-w-0",children:O}),s.jsxs("div",{className:"flex items-center gap-2 flex-shrink-0",children:[(_e||tt)&&s.jsxs("span",{className:"typography-micro text-muted-foreground flex-shrink-0 bg-[var(--surface-muted)] px-1.5 py-0.5 rounded",children:[_e?`${_e} ${t("settings.providers.page.models.tokenBadge.context")}`:"",_e&&tt?" · ":"",tt?`${tt} ${t("settings.providers.page.models.tokenBadge.output")}`:""]}),ht.length>0&&s.jsx("div",{className:"flex items-center gap-1 flex-shrink-0",children:ht.map(({key:mt,icon:ut,label:ft})=>s.jsx("span",{className:"flex h-5 w-5 rounded items-center justify-center text-muted-foreground bg-[var(--surface-muted)]",title:ft,"aria-label":ft,children:s.jsx(L,{name:ut,className:"h-3 w-3"})},mt))}),s.jsx("button",{type:"button",onClick:()=>u(re.id,ke),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(qe?"settings.providers.page.models.actions.showModelInSelectors":"settings.providers.page.models.actions.hideModelFromSelectors"),"aria-label":t(qe?"settings.providers.page.models.actions.showModel":"settings.providers.page.models.actions.hideModel"),children:qe?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"})})]})]})},ke)})})]}):null]})},Cg=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)},Pg=t=>{const e=lt.c(75),{onItemSelect:a}=t,{t:n}=nt(),i=ss(Ig),r=ss(Ag),l=ss(Eg),u=ss(Tg),g=ss(Dg),x=ss(Mg),d=ss(Rg),v=ss(Og);let c,N;e[0]!==v?(c=()=>{v()},N=[v],e[0]=v,e[1]=c,e[2]=N):(c=e[1],N=e[2]),o.useEffect(c,N);const b=Lg;let C;e[3]!==d?(C=se=>{se!=="usage"&&se!=="remaining"||(d(se),b({usageDisplayMode:se}))},e[3]=d,e[4]=C):C=e[4];const k=C;let A;e[5]===Symbol.for("react.memo_cache_sentinel")?(A=we("flex h-full flex-col","bg-background"),e[5]=A):A=e[5];let h;e[6]!==n?(h=n("settings.usage.sidebar.title"),e[6]=n,e[7]=h):h=e[7];let E;e[8]!==h?(E=s.jsx("h2",{className:`${nn} mb-3`,children:h}),e[8]=h,e[9]=E):E=e[9];let F;e[10]!==n?(F=n("settings.usage.sidebar.total",{count:ci.length}),e[10]=n,e[11]=F):F=e[11];let I;e[12]!==F?(I=s.jsx("span",{className:"typography-meta text-muted-foreground",children:F}),e[12]=F,e[13]=I):I=e[13];let w;e[14]!==u?(w=()=>u(),e[14]=u,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 U=g&&"animate-spin";let S;e[20]!==U?(S=we("h-3.5 w-3.5",U),e[20]=U,e[21]=S):S=e[21];let M;e[22]!==S?(M=s.jsx(L,{name:"refresh",className:S}),e[22]=S,e[23]=M):M=e[23];let j;e[24]!==g||e[25]!==m||e[26]!==y||e[27]!==M||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:g,children:M})}),e[24]=g,e[25]=m,e[26]=y,e[27]=M,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 H;e[33]!==n?(H=n("settings.usage.sidebar.field.display"),e[33]=n,e[34]=H):H=e[34];let P;e[35]!==H?(P=s.jsx("span",{className:"typography-micro text-muted-foreground",children:H}),e[35]=H,e[36]=P):P=e[36];let G;e[37]!==n?(G=n("settings.usage.sidebar.field.displayModePlaceholder"),e[37]=n,e[38]=G):G=e[38];let J;e[39]!==G?(J=s.jsx(Et,{className:"w-fit",children:s.jsx(Ft,{placeholder:G})}),e[39]=G,e[40]=J):J=e[40];let T;e[41]!==n?(T=n("settings.usage.sidebar.field.displayModeUsage"),e[41]=n,e[42]=T):T=e[42];let W;e[43]!==T?(W=s.jsx(ot,{value:"usage",children:T}),e[43]=T,e[44]=W):W=e[44];let X;e[45]!==n?(X=n("settings.usage.sidebar.field.displayModeRemaining"),e[45]=n,e[46]=X):X=e[46];let K;e[47]!==X?(K=s.jsx(ot,{value:"remaining",children:X}),e[47]=X,e[48]=K):K=e[48];let te;e[49]!==W||e[50]!==K?(te=s.jsxs(Tt,{children:[W,K]}),e[49]=W,e[50]=K,e[51]=te):te=e[51];let $;e[52]!==k||e[53]!==J||e[54]!==te||e[55]!==x?($=s.jsxs(At,{value:x,onValueChange:k,children:[J,te]}),e[52]=k,e[53]=J,e[54]=te,e[55]=x,e[56]=$):$=e[56];let V;e[57]!==P||e[58]!==$?(V=s.jsxs("div",{className:"mt-2 flex items-center justify-between gap-2",children:[P,$]}),e[57]=P,e[58]=$,e[59]=V):V=e[59];let _;e[60]!==R||e[61]!==V||e[62]!==E?(_=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]=_):_=e[63];let z;e[64]!==a||e[65]!==i||e[66]!==r||e[67]!==l||e[68]!==n?(z=ci.map(se=>{const ge=i.find(Pe=>Pe.providerId===se.id),ce=Cg(ge?.usage),be=fl(ce),ne=se.id===r,ae=ge?.configured??!1,me=ae?be==="critical"?{backgroundColor:"var(--status-error)"}:be==="warn"?{backgroundColor:"var(--status-warning)"}:{backgroundColor:"var(--status-success)"}:{backgroundColor:"var(--surface-muted-foreground)",opacity:.4};return s.jsx("div",{className:we("group relative flex items-center rounded-md px-1.5 py-1 transition-all duration-200",ne?"bg-interactive-selection":"hover:bg-interactive-hover"),children:s.jsxs("button",{type:"button",onClick:()=>{l(se.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:me}),s.jsx(On,{providerId:se.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:se.name}),!ae&&s.jsx("span",{className:"typography-micro text-muted-foreground/60 flex-shrink-0",children:n("settings.usage.sidebar.status.notSet")})]})},se.id)}),e[64]=a,e[65]=i,e[66]=r,e[67]=l,e[68]=n,e[69]=z):z=e[69];let Z;e[70]!==z?(Z=s.jsx(Vs,{outerClassName:"flex-1 min-h-0",className:"space-y-1 px-3 py-2 overflow-x-hidden",children:z}),e[70]=z,e[71]=Z):Z=e[71];let Y;return e[72]!==_||e[73]!==Z?(Y=s.jsxs("div",{className:A,children:[_,Z]}),e[72]=_,e[73]=Z,e[74]=Y):Y=e[74],Y};function Ig(t){return t.results}function Ag(t){return t.selectedProviderId}function Eg(t){return t.setSelectedProvider}function Tg(t){return t.fetchAllQuotas}function Dg(t){return t.isLoading}function Mg(t){return t.displayMode}function Rg(t){return t.setDisplayMode}function Og(t){return t.loadSettings}async function Lg(t){try{await xt(t)}catch(e){console.warn("Failed to save usage settings:",e)}}const Fg=t=>{const e=lt.c(17),{percent:a,tonePercent:n,className:i}=t;let r;e[0]!==a?(r=Sc(a)??0,e[0]=a,e[1]=r):r=e[1];const l=r,u=n??a;let g;e[2]!==u?(g=fl(u),e[2]=u,e[3]=g):g=e[3];const x=g;let d;e[4]!==x?(d=x==="critical"?{backgroundColor:"var(--status-error)"}:x==="warn"?{backgroundColor:"var(--status-warning)"}:{backgroundColor:"var(--status-success)"},e[4]=x,e[5]=d):d=e[5];const v=d;let c;e[6]!==i?(c=we("relative h-2.5 rounded-full bg-[var(--interactive-border)] overflow-hidden",i),e[6]=i,e[7]=c):c=e[7];const N=`${l}%`;let b;e[8]!==v||e[9]!==N?(b={...v,width:N},e[8]=v,e[9]=N,e[10]=b):b=e[10];let C;e[11]!==l||e[12]!==b?(C=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]=C):C=e[13];let k;return e[14]!==c||e[15]!==C?(k=s.jsx("div",{className:c,children:C}),e[14]=c,e[15]=C,e[16]=k):k=e[16],k},Ui=t=>{const e=lt.c(44),{title:a,window:n,subtitle:i,showToggle:r,toggleEnabled:l,onToggle:u}=t,g=r===void 0?!1:r,x=l===void 0?!1:l,d=ss(Kg),v=de(Ug),c=d==="remaining"?n.remainingPercent:n.usedPercent,N=d==="remaining"?"remaining":"used";let b;e[0]!==c||e[1]!==n.valueLabel?(b=Cc(n.valueLabel,c),e[0]=c,e[1]=n.valueLabel,e[2]=b):b=e[2];const C=b,k=n.resetAfterFormatted??n.resetAtFormatted;let A;e[3]!==k||e[4]!==v||e[5]!==n.resetAt?(A=Pc(n.resetAt,k,v),e[3]=k,e[4]=v,e[5]=n.resetAt,e[6]=A):A=e[6];const h=A;let E;e[7]!==a?(E=Ic(a),e[7]=a,e[8]=E):E=e[8];const F=E;let I;e[9]!==u||e[10]!==g||e[11]!==x?(I=g&&s.jsx(Yi,{checked:x,onChange:X=>u?.(X),ariaLabel:"Show in dropdown"}),e[9]=u,e[10]=g,e[11]=x,e[12]=I):I=e[12];let w;e[13]!==F?(w=s.jsx("span",{className:"typography-ui-label text-foreground truncate",children:F}),e[13]=F,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 U;e[20]!==y||e[21]!==I?(U=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]=U):U=e[22];const S=C==="-"?"":C;let M;e[23]!==S?(M=s.jsx("div",{className:"typography-ui-label text-foreground tabular-nums flex items-center justify-end",children:S}),e[23]=S,e[24]=M):M=e[24];let j;e[25]!==U||e[26]!==M?(j=s.jsxs("div",{className:"flex items-center justify-between gap-3",children:[U,M]}),e[25]=U,e[26]=M,e[27]=j):j=e[27];let R;e[28]!==c||e[29]!==n.usedPercent?(R=s.jsx(Fg,{percent:c,tonePercent:n.usedPercent,className:"h-1.5"}),e[28]=c,e[29]=n.usedPercent,e[30]=R):R=e[30];const H=h?`Resets ${h}`:"";let P;e[31]!==H?(P=s.jsx("span",{className:"typography-micro text-muted-foreground",children:H}),e[31]=H,e[32]=P):P=e[32];let G;e[33]!==N?(G=s.jsx("span",{className:"typography-micro text-muted-foreground",children:N}),e[33]=N,e[34]=G):G=e[34];let J;e[35]!==P||e[36]!==G?(J=s.jsxs("div",{className:"mt-1 flex items-center justify-between",children:[P,G]}),e[35]=P,e[36]=G,e[37]=J):J=e[37];let T;e[38]!==R||e[39]!==J?(T=s.jsxs("div",{className:"mt-2.5",children:[R,J]}),e[38]=R,e[39]=J,e[40]=T):T=e[40];let W;return e[41]!==j||e[42]!==T?(W=s.jsxs("div",{className:"py-3",children:[j,T]}),e[41]=j,e[42]=T,e[43]=W):W=e[43],W};function Kg(t){return t.displayMode}function Ug(t){return t.timeFormatPreference}const zg=({providerId:t,providerName:e})=>{const{t:a}=nt(),[n,i]=o.useState(null),[r,l]=o.useState({}),[u,g]=o.useState(!1),x=`/api/quota/credentials/${t}`;o.useEffect(()=>{rt(x).then(async c=>{if(!c.ok)throw new Error;const N=await c.json();i(N),l({})}).catch(()=>i({configured:!1}))},[x]);const d=async(c,N,b)=>{g(!0);try{const C=await rt(c,{method:N,headers:b?{"Content-Type":"application/json"}:void 0,body:b?JSON.stringify(b):void 0}),k=await C.json().catch(()=>null);if(!C.ok)throw new Error(k?.error);k?.configured!==void 0&&i(k),l({}),D.success(a("settings.providers.page.quotaCredentials.saved",{provider:e}))}catch(C){D.error(C instanceof Error&&C.message?C.message:a("settings.providers.page.openCodeGo.saveFailed"))}finally{g(!1)}},v=(c,N,b)=>s.jsxs("label",{className:"block typography-ui-label text-foreground",children:[N,s.jsx(We,{className:"mt-1 h-7 font-mono text-xs",type:"password",autoComplete:"off",value:r[c]??"",onChange:C=>l(k=>({...k,[c]:C.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:u,onClick:()=>d(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:u,onClick:()=>d(`${x}/validate`,"POST"),children:a("settings.providers.page.openCodeGo.validate")}),t==="cursor"&&s.jsx(B,{variant:"outline",size:"xs",disabled:u,onClick:()=>d(`${x}/import`,"POST"),children:a("settings.providers.page.actions.connect")}),n?.configured&&s.jsx(B,{variant:"destructive",size:"xs",disabled:u,onClick:()=>d(x,"DELETE"),children:a("settings.providers.page.openCodeGo.delete")})]})]})]})},Mo=(t,e)=>{if(!t)return"-";try{return xl(t,e,{fallback:"-"})}catch{return"-"}},_g=()=>{const{t}=nt(),e=de(P=>P.timeFormatPreference),a=ss(P=>P.results),n=ss(P=>P.selectedProviderId),i=ss(P=>P.setSelectedProvider),r=ss(P=>P.loadSettings),l=ss(P=>P.fetchAllQuotas),u=ss(P=>P.isLoading),g=ss(P=>P.lastUpdated),x=ss(P=>P.error),d=ss(P=>P.dropdownProviderIds),v=ss(P=>P.setDropdownProviderIds),c=ss(P=>P.selectedModels),N=ss(P=>P.toggleModelSelected),b=ss(P=>P.applyDefaultSelections);Ac(),o.useEffect(()=>{r(),l()},[r,l]),o.useEffect(()=>{if(n||a.length===0)return;const P=a.find(G=>G.configured)?.providerId;i(P??ci[0]?.id??null)},[a,n,i]);const C=a.find(P=>P.providerId===n)??null,A=ci.find(P=>P.id===n)?.name??n??t("settings.usage.sidebar.title"),h=C?.usage,E=C?.configured&&!C.ok?C.error:null,F=n?d.includes(n):!1,I=n==="ollama-cloud"||n==="cursor",w=o.useCallback(P=>{if(!n)return;const G=P?Array.from(new Set([...d,n])):d.filter(J=>J!==n);v(G),xt({usageDropdownProviders:G})},[d,n,v]),m=o.useMemo(()=>h?.models?Object.entries(h.models).map(([P,G])=>({name:P,windows:G})).filter(P=>Object.keys(P.windows.windows).length>0):[],[h?.models]);o.useEffect(()=>{n&&m.length>0&&b(n,m.map(P=>P.name))},[n,m,b]);const y=o.useMemo(()=>!n||m.length===0?new Map:Ec(m,P=>P.name,n),[m,n]),U=o.useMemo(()=>{if(!n)return[];const P=Dc(n);return Tc(P)},[n]),[S,M]=o.useState(()=>({})),j=o.useCallback(P=>{M(G=>({...G,[P]:!G[P]}))},[]),R=o.useCallback(P=>{if(!n)return;N(n,P);const G=c[n]??[],T=G.includes(P)?G.filter(X=>X!==P):[...G,P],W={...c,[n]:T};xt({usageSelectedModels:W})},[n,c,N]),H=n?c[n]??[]:[];return n?s.jsxs(ns,{title:t("settings.usage.page.header.providerUsage",{provider:A}),titleLeading:s.jsx(On,{providerId:n,className:"h-5 w-5 shrink-0"}),description:u?s.jsx("span",{className:"animate-pulse typography-settings-description text-muted-foreground",children:t("settings.usage.page.header.refreshing")}):C?.planLabel?t("settings.usage.page.header.lastUpdatedWithPlan",{plan:C.planLabel,time:Mo(g,e)}):t("settings.usage.page.header.lastUpdated",{time:Mo(g,e)}),showSaveStatus:!0,children:[s.jsx($e,{divider:!1,settingsItem:"usage.work-status-panel",children:s.jsx(pt,{checked:F,onChange:w,label:t("settings.usage.page.options.showInWorkStatus"),ariaLabel:t("settings.usage.page.options.showInWorkStatusAria"),info:t("settings.usage.page.options.showInWorkStatusTooltip")})}),!C&&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})]}),C&&!C.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(zg,{providerId:n,providerName:A}),h?.windows&&Object.keys(h.windows).length>0&&s.jsx($e,{settingsItem:"usage.model-quotas",children:s.jsx("div",{className:"divide-y divide-[var(--surface-subtle)]",children:Object.entries(h.windows).map(([P,G])=>s.jsx(Ui,{title:P,window:G},P))})}),m.length>0&&s.jsxs($e,{title:t("settings.usage.page.section.modelQuotas"),contentClassName:"space-y-3",children:[U.map(P=>{const G=y.get(P.id)??[];if(G.length===0)return null;const J=S[P.id]??!1;return s.jsx("section",{className:"p-2",children:s.jsxs(Hn,{open:!J,onOpenChange:()=>j(P.id),children:[s.jsxs(Gn,{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:P.label}),s.jsxs("span",{className:"typography-micro text-muted-foreground",children:["(",G.length,")"]})]}),J?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(qn,{children:s.jsx("div",{className:"divide-y divide-[var(--surface-subtle)] mt-1",children:G.map(T=>{const W=Object.entries(T.windows.windows);if(W.length===0)return null;const[X,K]=W[0],te=H.includes(T.name);return s.jsx(Ui,{title:X,subtitle:Ir(T.name),window:K,showToggle:!0,toggleEnabled:te,onToggle:()=>R(T.name)},T.name)})})})]})},P.id)}),(()=>{const P=y.get(null)??[];if(P.length===0)return null;const G=S.other??!1;return s.jsx("section",{className:"p-2",children:s.jsxs(Hn,{open:!G,onOpenChange:()=>j("other"),children:[s.jsxs(Gn,{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:["(",P.length,")"]})]}),G?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(qn,{children:s.jsx("div",{className:"divide-y divide-[var(--surface-subtle)] mt-1",children:P.map(J=>{const T=Object.entries(J.windows.windows);if(T.length===0)return null;const[W,X]=T[0],K=H.includes(J.name);return s.jsx(Ui,{title:W,subtitle:Ir(J.name),window:X,showToggle:!0,toggleEnabled:K,onToggle:()=>R(J.name)},J.name)})})})]})})})()]}),C?.configured&&h&&Object.keys(h.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")})})},$g="git.commit.generate",ir=Cl(t=>({selectedPromptId:$g,setSelectedPromptId:e=>{t(a=>a.selectedPromptId===e?a:{selectedPromptId:e})}})),Vg=t=>{const e=lt.c(23),{onItemSelect:a}=t,{t:n}=nt(),i=ir(Bg),r=ir(Hg);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 u;e[1]===Symbol.for("react.memo_cache_sentinel")?(u={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]=u):u=e[1];let g;e[2]===Symbol.for("react.memo_cache_sentinel")?(g={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]=g):g=e[2];let x;e[3]===Symbol.for("react.memo_cache_sentinel")?(x=[l,u,g,{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 d=x;let v;e[4]!==n?(v=n("settings.magicPrompts.sidebar.title"),e[4]=n,e[5]=v):v=e[5];let c;e[6]!==v?(c=s.jsx("h2",{className:nn,children:v}),e[6]=v,e[7]=c):c=e[7];let N;e[8]!==n?(N=n("settings.magicPrompts.sidebar.description"),e[8]=n,e[9]=N):N=e[9];let b;e[10]!==N?(b=s.jsx("p",{className:"typography-meta mt-1 text-muted-foreground",children:N}),e[10]=N,e[11]=b):b=e[11];let C;e[12]!==c||e[13]!==b?(C=s.jsxs("div",{className:"border-b px-3 pt-4 pb-3",children:[c,b]}),e[12]=c,e[13]=b,e[14]=C):C=e[14];let k;e[15]!==a||e[16]!==i||e[17]!==r||e[18]!==n?(k=s.jsx(Vs,{outerClassName:"flex-1 min-h-0",className:"space-y-3 px-3 py-2 overflow-x-hidden",children:d.map(h=>s.jsxs("div",{className:"space-y-1",children:[s.jsx("div",{className:"typography-micro px-1 text-muted-foreground",children:n(h.groupKey)}),h.items.map(E=>{const F=i===E.id;return s.jsx("button",{type:"button",onClick:()=>{r(E.id),a?.()},className:we("flex w-full items-center rounded-md px-2 py-1.5 text-left transition-colors",F?"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)})]},h.groupKey))}),e[15]=a,e[16]=i,e[17]=r,e[18]=n,e[19]=k):k=e[19];let A;return e[20]!==k||e[21]!==C?(A=s.jsxs("div",{className:"flex h-full flex-col bg-background",children:[C,k]}),e[20]=k,e[21]=C,e[22]=A):A=e[22],A};function Bg(t){return t.selectedPromptId}function Hg(t){return t.setSelectedPromptId}const Ro={"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"}]}},Oo=(t,e)=>Object.prototype.hasOwnProperty.call(t,e),zi=t=>t.endsWith(".visible"),Gg=()=>{const{t}=nt(),e=o.useCallback(w=>t(w),[t]),a=ir(w=>w.selectedPromptId),[n,i]=o.useState(!0),[r,l]=o.useState({}),[u,g]=o.useState({}),[x,d]=o.useState({}),[v,c]=o.useState({}),[N,b]=o.useState(!1);o.useEffect(()=>{let w=!0;return(async()=>{i(!0);try{const y=await Lc();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 C=Ro[a]??Ro["git.commit.generate"],k=o.useCallback(w=>Oo(r,w)?r[w]:Ii(w),[r]),A=o.useCallback(w=>u[w]??k(w),[u,k]),h=o.useCallback((w,m)=>{g(y=>y[w]===m?y:{...y,[w]:m})},[]),E=o.useCallback(async w=>{const m=A(w);if(zi(w)&&m.trim().length===0){D.error(t("settings.magicPrompts.page.toast.visiblePromptRequired"));return}d(y=>({...y,[w]:!0}));try{const y=m===Ii(w)?await Ar(w):await Mc(w,m);l(y.overrides),D.success(t("settings.magicPrompts.page.toast.saved"))}catch(y){const U=y instanceof Error?y.message:String(y);D.error(t("settings.magicPrompts.page.toast.saveFailed"),{description:U})}finally{d(y=>({...y,[w]:!1}))}},[A,t]),F=o.useCallback(async w=>{c(m=>({...m,[w]:!0}));try{const m=await Ar(w);l(m.overrides),g(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{c(m=>({...m,[w]:!1}))}},[t]),I=o.useCallback(async()=>{b(!0);try{const w=await Rc();l(w.overrides),g({}),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(ns,{title:e(C.titleKey),titleAccessory:s.jsx(Jt,{contentClassName:"max-w-xs",children:e(C.descriptionKey)}),headerEnd:s.jsx(B,{"data-settings-item":"magic-prompts.reset-overrides",variant:"outline",size:"sm",onClick:()=>{I()},disabled:N||Object.keys(r).length===0,children:t(N?"settings.magicPrompts.page.actions.resetting":"settings.magicPrompts.page.actions.resetAllOverrides")}),showSaveStatus:!1,children:C.blocks.map((w,m)=>{const y=Oc(w.id),U=k(w.id),S=A(w.id),M=Oo(r,w.id),j=S!==U,R=zi(w.id)&&S.trim().length===0,H=x[w.id]===!0,P=v[w.id]===!0;return s.jsxs($e,{title:e(w.titleKey),info:y.description,description:y.placeholders&&y.placeholders.length>0?`${t("settings.magicPrompts.page.placeholdersLabel")} ${y.placeholders.map(G=>`{{${G.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(Is,{value:S,onChange:G=>h(w.id,G.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":M?"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:()=>{F(w.id)},disabled:!M||H||P,children:t(P?"settings.magicPrompts.page.actions.resetting":"settings.magicPrompts.page.actions.resetToDefault")}),s.jsx(B,{size:"sm",onClick:()=>{E(w.id)},disabled:!j||H||P||R,children:t(H?"settings.common.actions.saving":"settings.magicPrompts.page.actions.save")})]})]})]},w.id)})})},qg=t=>{const e=lt.c(89),{onItemSelect:a}=t,{t:n}=nt(),[i,r]=o.useState(null),[l,u]=o.useState(null),[g,x]=o.useState(null),{selectedSnippetName:d,snippets:v,setSelectedSnippet:c,setSnippetDraft:N,deleteSnippet:b,loadSnippets:C}=di(Ds(Wg));let k,A;e[0]!==C?(k=()=>{C()},A=[C],e[0]=C,e[1]=k,e[2]=A):(k=e[1],A=e[2]),o.useEffect(k,A);let h;e[3]!==a||e[4]!==c||e[5]!==N||e[6]!==v?(h=async()=>{const Ne=new Set(v.map(Jg));let Se="new-snippet",je=1;for(;Ne.has(Se);)Se=`new-snippet-${je++}`;N({name:Se,scope:"global"}),c(Se),a?.()},e[3]=a,e[4]=c,e[5]=N,e[6]=v,e[7]=h):h=e[7];const E=h;let F;e[8]!==i||e[9]!==b||e[10]!==n?(F=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]=F):F=e[11];const I=F;let w;e[12]!==v?(w=[...v].sort(Qg),e[12]=v,e[13]=w):w=e[13];const m=w;let y;e[14]===Symbol.for("react.memo_cache_sentinel")?(y=we("flex h-full flex-col","bg-background"),e[14]=y):y=e[14];let U;e[15]!==n?(U=n("settings.snippets.sidebar.title"),e[15]=n,e[16]=U):U=e[16];let S;e[17]!==U?(S=s.jsx("h2",{className:`${nn} mb-3`,children:U}),e[17]=U,e[18]=S):S=e[18];let M;e[19]!==v.length||e[20]!==n?(M=n("settings.snippets.sidebar.total",{count:v.length}),e[19]=v.length,e[20]=n,e[21]=M):M=e[21];let j;e[22]!==M?(j=s.jsx("span",{className:"typography-meta text-muted-foreground",children:M}),e[22]=M,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 H;e[26]===Symbol.for("react.memo_cache_sentinel")?(H=s.jsx(L,{name:"add",className:"h-3.5 w-3.5"}),e[26]=H):H=e[26];let P;e[27]!==E||e[28]!==R?(P=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:H}),e[27]=E,e[28]=R,e[29]=P):P=e[29];let G;e[30]!==j||e[31]!==P?(G=s.jsxs("div",{className:"flex items-center justify-between gap-2",children:[j,P]}),e[30]=j,e[31]=P,e[32]=G):G=e[32];let J;e[33]!==G||e[34]!==S?(J=s.jsxs("div",{className:"border-b px-3 pt-4 pb-3",children:[S,G]}),e[33]=G,e[34]=S,e[35]=J):J=e[35];let T;if(e[36]!==a||e[37]!==l||e[38]!==g||e[39]!==d||e[40]!==c||e[41]!==m||e[42]!==n){let Ne;e[44]!==a||e[45]!==l||e[46]!==g||e[47]!==d||e[48]!==c||e[49]!==n?(Ne=Se=>s.jsxs(Bn,{open:g===Se.name,onOpenChange:je=>x(je?Se.name:null),children:[s.jsxs(Vn,{render:s.jsx("div",{className:we("group relative flex items-center rounded-md px-1.5 py-1 transition-all duration-200 select-none",d===Se.name?"bg-interactive-selection":"hover:bg-interactive-hover"),onContextMenu:je=>{je.preventDefault(),x(Se.name)}}),children:[s.jsxs("button",{onClick:()=>{c(Se.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:["#",Se.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.${Se.source}`)})]}),s.jsx("div",{className:"typography-micro text-muted-foreground/60 truncate leading-tight",children:Se.description||Se.content.replace(/\s+/g," ").substring(0,80)})]}),s.jsxs(tn,{open:l===Se.name,onOpenChange:je=>{je&&x(null),u(je?Se.name:null)},children:[s.jsx(Zs,{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:Se.name}),children:s.jsx(L,{name:"more-2",className:"h-3.5 w-3.5"})})}),s.jsx(en,{align:"end",className:"w-fit min-w-20",children:s.jsxs(sn,{onClick:je=>{je.stopPropagation(),r(Se)},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(_n,{className:"w-fit min-w-20",children:s.jsxs($n,{onClick:je=>{je.stopPropagation(),r(Se)},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")]})})]},`${Se.source}:${Se.filePath}`),e[44]=a,e[45]=l,e[46]=g,e[47]=d,e[48]=c,e[49]=n,e[50]=Ne):Ne=e[50],T=m.map(Ne),e[36]=a,e[37]=l,e[38]=g,e[39]=d,e[40]=c,e[41]=m,e[42]=n,e[43]=T}else T=e[43];let W;e[51]!==T?(W=s.jsx(Vs,{outerClassName:"flex-1 min-h-0",className:"space-y-1 px-3 py-2",children:T}),e[51]=T,e[52]=W):W=e[52];const X=i!==null;let K;e[53]===Symbol.for("react.memo_cache_sentinel")?(K=Ne=>{Ne||r(null)},e[53]=K):K=e[53];let te;e[54]!==n?(te=n("settings.snippets.sidebar.dialog.deleteTitle"),e[54]=n,e[55]=te):te=e[55];let $;e[56]!==te?($=s.jsx(Ut,{children:te}),e[56]=te,e[57]=$):$=e[57];const V=i?.name??"";let _;e[58]!==n||e[59]!==V?(_=n("settings.snippets.sidebar.dialog.deleteDescription",{name:V}),e[58]=n,e[59]=V,e[60]=_):_=e[60];let z;e[61]!==_?(z=s.jsx(zt,{children:_}),e[61]=_,e[62]=z):z=e[62];let Z;e[63]!==$||e[64]!==z?(Z=s.jsxs(Kt,{children:[$,z]}),e[63]=$,e[64]=z,e[65]=Z):Z=e[65];let Y;e[66]===Symbol.for("react.memo_cache_sentinel")?(Y=()=>r(null),e[66]=Y):Y=e[66];let se;e[67]!==n?(se=n("settings.common.actions.cancel"),e[67]=n,e[68]=se):se=e[68];let ge;e[69]!==se?(ge=s.jsx(B,{size:"sm",variant:"ghost",onClick:Y,children:se}),e[69]=se,e[70]=ge):ge=e[70];let ce;e[71]!==n?(ce=n("settings.common.actions.delete"),e[71]=n,e[72]=ce):ce=e[72];let be;e[73]!==I||e[74]!==ce?(be=s.jsx(B,{size:"sm",onClick:I,children:ce}),e[73]=I,e[74]=ce,e[75]=be):be=e[75];let ne;e[76]!==ge||e[77]!==be?(ne=s.jsxs(es,{children:[ge,be]}),e[76]=ge,e[77]=be,e[78]=ne):ne=e[78];let ae;e[79]!==Z||e[80]!==ne?(ae=s.jsxs(Ot,{className:"max-w-md",children:[Z,ne]}),e[79]=Z,e[80]=ne,e[81]=ae):ae=e[81];let me;e[82]!==X||e[83]!==ae?(me=s.jsx(Rt,{open:X,onOpenChange:K,children:ae}),e[82]=X,e[83]=ae,e[84]=me):me=e[84];let Pe;return e[85]!==J||e[86]!==W||e[87]!==me?(Pe=s.jsxs("div",{className:y,children:[J,W,me]}),e[85]=J,e[86]=W,e[87]=me,e[88]=Pe):Pe=e[88],Pe};function Wg(t){return{selectedSnippetName:t.selectedSnippetName,snippets:t.snippets,setSelectedSnippet:t.setSelectedSnippet,setSnippetDraft:t.setSnippetDraft,deleteSnippet:t.deleteSnippet,loadSnippets:t.loadSnippets}}function Jg(t){return t.name}function Qg(t,e){return t.name.localeCompare(e.name)}const Yg=()=>{const{t}=nt(),{selectedSnippetName:e,snippets:a,snippetDraft:n,setSnippetDraft:i,updateSnippet:r,createSnippet:l}=di(Ds(y=>({selectedSnippetName:y.selectedSnippetName,snippets:y.snippets,snippetDraft:y.snippetDraft,setSnippetDraft:y.setSnippetDraft,updateSnippet:y.updateSnippet,createSnippet:y.createSnippet}))),u=o.useMemo(()=>e?a.find(y=>y.name===e||y.aliases.includes(e))??null:null,[e,a]),g=!!(n&&n.name===e&&!u),[x,d]=o.useState(""),[v,c]=o.useState("global"),[N,b]=o.useState(""),[C,k]=o.useState(""),[A,h]=o.useState(""),[E,F]=o.useState(!1),I=o.useRef(null);o.useEffect(()=>{if(g&&n){const y={draftName:n.name||"",draftScope:n.scope||"global",description:n.description||"",aliases:(n.aliases||[]).join(", "),content:n.content||""};d(y.draftName),c(y.draftScope),b(y.description),k(y.aliases),h(y.content),I.current=y}else if(u){const y={draftName:"",draftScope:"global",description:u.description??"",aliases:u.aliases.join(", "),content:u.content};b(y.description),k(y.aliases),h(y.content),I.current=y}},[u,g,e,n]);const w=o.useMemo(()=>{const y=I.current;return y?g&&x!==y.draftName||g&&v!==y.draftScope?!0:N!==y.description||C!==y.aliases||A!==y.content:!1},[C,A,N,x,v,g]),m=async()=>{const y=g?x.trim().replace(/\s+/g,"-"):e?.trim();if(!y){D.error(t("settings.snippets.page.toast.nameRequired"));return}if(!A.trim()){D.error(t("settings.snippets.page.toast.contentRequired"));return}const U=C.split(",").map(S=>S.trim()).filter(Boolean);F(!0);try{if(!(g?await l(y,A,{aliases:U,description:N,scope:v}):await r(y,{content:A,aliases:U,description:N}))){D.error(t("settings.snippets.page.toast.saveFailed"));return}D.success(t("settings.snippets.page.toast.saved")),g&&i(null)}finally{F(!1)}};return e?s.jsxs(ns,{title:g?t("settings.snippets.page.title.new"):`#${e}`,description:u?u.filePath:void 0,showSaveStatus:!1,children:[s.jsxs($e,{divider:!1,contentClassName:"space-y-0",children:[g?s.jsxs(Vt,{label:"#",children:[s.jsx(We,{value:x,onChange:y=>d(y.target.value),placeholder:t("settings.snippets.page.field.namePlaceholder"),className:"h-7 w-44 px-2"}),s.jsxs(At,{value:v,onValueChange:y=>c(y),children:[s.jsx(Et,{size:$t,className:"w-fit min-w-[100px]",children:s.jsx(Ft,{})}),s.jsxs(Tt,{align:"end",children:[s.jsx(ot,{value:"global",children:t("settings.common.scope.global")}),s.jsx(ot,{value:"project",children:t("settings.common.scope.project")})]})]})]}):null,s.jsx(Wt,{label:t("settings.common.field.description"),children:s.jsx(We,{value:N,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(Wt,{label:t("settings.snippets.page.field.aliases"),children:s.jsx(We,{value:C,onChange:y=>k(y.target.value),placeholder:t("settings.snippets.page.field.aliasesPlaceholder"),className:"h-7 w-full max-w-sm px-2"})})]}),s.jsxs($e,{settingsItem:"snippets.content",children:[s.jsxs("div",{className:"flex items-center gap-1",children:[s.jsx("span",{className:"typography-ui-label text-foreground",children:t("settings.snippets.page.field.content")}),s.jsx(Jt,{children:t("settings.snippets.page.hint")})]}),s.jsx(Is,{value:A,onChange:y=>h(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")})]})})},$l=()=>{const{t}=nt(),e=et(v=>v.settingsGitmojiEnabled),a=et(v=>v.setSettingsGitmojiEnabled),n=hd(),i=de(v=>v.gitChangesViewMode),r=de(v=>v.setGitChangesViewMode),[l,u]=o.useState(!0),g=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 c=null;if(!c){const N=Pn()?.settings;if(N)try{const C=(await N.load())?.settings;C&&(c={gitmojiEnabled:typeof C.gitmojiEnabled=="boolean"?C.gitmojiEnabled:void 0,gitChangesViewMode:C.gitChangesViewMode==="flat"||C.gitChangesViewMode==="tree"?C.gitChangesViewMode:void 0})}catch{}}if(!c){const N=await rt("/api/config/settings",{method:"GET",headers:{Accept:"application/json"}});N.ok&&(c=await N.json())}c&&(typeof c.gitmojiEnabled=="boolean"&&a(c.gitmojiEnabled),(c.gitChangesViewMode==="flat"||c.gitChangesViewMode==="tree")&&r(c.gitChangesViewMode))}catch(c){console.warn("Failed to load git settings:",c)}finally{u(!1)}})()},[r,a]);const x=o.useCallback(async v=>{a(v);try{await xt({gitmojiEnabled:v})}catch(c){console.warn("Failed to save gitmoji setting:",c)}},[a]),d=o.useCallback(v=>{v!==i&&(r(v),xt({gitChangesViewMode:v}))},[i,r]);return l?null:s.jsx($e,{title:t("settings.openchamber.git.title"),children:s.jsxs("div",{className:fs,children:[s.jsx(Ks,{settingsItem:"git.changes-view",title:t("settings.openchamber.git.changesViewTitle"),children:s.jsx(dn,{"aria-label":t("settings.openchamber.git.changesViewAria"),children:g.map(v=>s.jsx(pn,{selected:i===v.id,onSelect:()=>{d(v.id)},label:v.label,ariaLabel:t("settings.openchamber.git.optionAria",{option:v.label})},v.id))})}),s.jsx(pt,{settingsItem:"git.gitmoji",checked:e,onChange:v=>{x(v)},label:t("settings.openchamber.git.enableGitmoji"),ariaLabel:t("settings.openchamber.git.enableGitmojiAria")}),s.jsx(pt,{settingsItem:"git.gitignored-files",checked:n,onChange:fd,label:t("settings.openchamber.git.showGitignored"),ariaLabel:t("settings.openchamber.git.showGitignoredAria")})]})})},Vl=()=>{const{t}=nt(),{isMobile:e}=da(),a=Pn()?.github,n=va(j=>j.status),i=va(j=>j.isLoading),r=va(j=>j.hasChecked),l=va(j=>j.refreshStatus),u=va(j=>j.setStatus),g=o.useCallback(async j=>{await In(j)},[]),[x,d]=o.useState(!1),[v,c]=o.useState(null),[N,b]=o.useState(null),C=o.useRef(null),k=o.useCallback(()=>{C.current!=null&&(window.clearInterval(C.current),C.current=null),b(null)},[]);o.useEffect(()=>((async()=>{try{r||await l(a)}catch(j){console.warn("Failed to load GitHub auth status:",j)}})(),()=>{k()}),[r,l,a,k]);const A=o.useCallback(async()=>{d(!0);try{const j=a?await a.authStart():await(async()=>{const H=await rt("/api/github/auth/start",{method:"POST",headers:{"Content-Type":"application/json",Accept:"application/json"},body:JSON.stringify({})}),P=await H.json().catch(()=>null);if(!H.ok||!P||!("deviceCode"in P))throw new Error(P?.error||H.statusText);return P})();c(j),b(Math.max(1,j.interval)*1e3);const R=j.verificationUriComplete||j.verificationUri;g(R)}catch(j){console.error("Failed to start GitHub connect:",j),D.error(t("settings.github.page.toast.startConnectFailed"))}finally{d(!1)}},[g,a,t]),h=o.useCallback(async j=>{if(a)return a.authComplete(j);const R=await rt("/api/github/auth/complete",{method:"POST",headers:{"Content-Type":"application/json",Accept:"application/json"},body:JSON.stringify({deviceCode:j})}),H=await R.json().catch(()=>null);if(!R.ok||!H)throw new Error(H?.error||R.statusText);return H},[a]);o.useEffect(()=>{if(!(!v?.deviceCode||!N)&&C.current==null)return C.current=window.setInterval(()=>{(async()=>{try{const j=await h(v.deviceCode);if(j.connected){D.success(t("settings.github.page.toast.connected")),c(null),k(),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")),c(null),k())}catch(j){console.warn("GitHub polling failed:",j)}})()},N),()=>{C.current!=null&&(window.clearInterval(C.current),C.current=null)}},[v,N,h,l,a,k,t]);const E=o.useCallback(async j=>{d(!0);try{if(a)await a.authSetGhCliDisabled(j);else{const R=await rt("/api/github/auth/gh-cli",{method:"POST",headers:{"Content-Type":"application/json",Accept:"application/json"},body:JSON.stringify({disabled:j})}),H=await R.json().catch(()=>null);if(!R.ok)throw new Error(H?.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{d(!1)}},[l,a,t]),F=o.useCallback(async()=>{d(!0);try{if(k(),c(null),a)await a.authDisconnect();else{const j=await rt("/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{d(!1)}},[l,a,k,t]),I=o.useCallback(async j=>{if(j){d(!0);try{const R=a?await a.authActivate(j):await(async()=>{const H=await rt("/api/github/auth/activate",{method:"POST",headers:{"Content-Type":"application/json",Accept:"application/json"},body:JSON.stringify({accountId:j})}),P=await H.json().catch(()=>null);if(!H.ok||!P)throw new Error(P?.error||H.statusText);return P})();u(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{d(!1)}}},[a,u,t]);if(i&&!r)return null;const w=!!n?.connected,m=n?.user,U=(n?.accounts??[]).filter(j=>!j.current),S=n?.ghCli??null,M=S?.active?t("settings.github.page.accountSource.cli"):t("settings.github.page.accountSource.oauth");return s.jsxs(s.Fragment,{children:[s.jsxs($e,{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:we("px-4 py-3",e?"flex flex-col gap-3":"flex items-center justify-between gap-4"),children:[s.jsxs("div",{className:we("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:we("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:M})]}),n?.scope&&s.jsx("div",{className:"typography-micro text-muted-foreground/70 mt-0.5",children:t("settings.github.page.label.scopes",{value:n.scope})}),S?.active&&s.jsx("div",{className:"typography-micro text-muted-foreground/70 mt-0.5",children:t("settings.github.page.ghCli.activeDescription")})]})]}),S?.active?s.jsx(B,{size:"sm",variant:"outline",onClick:()=>E(!0),disabled:x,className:we(e?"w-full":void 0),children:t("settings.github.page.ghCli.actions.disable")}):s.jsx(B,{size:"sm",variant:"outline",onClick:F,disabled:x,className:we("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:A,disabled:x,children:t("settings.github.page.actions.connect")})]}),U.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:U.map(j=>{const R=j.user,H=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:H})]})]})]}),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:A,disabled:x,className:we(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(Xs,{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:()=>{k(),c(null)},children:t("settings.common.actions.cancel")})]})]})]}),S?.available&&!S?.active&&(!S.user||S.disabled)&&s.jsx($e,{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:we("px-4 py-3",e?"flex flex-col gap-3":"flex items-center justify-between gap-4"),children:[s.jsxs("div",{className:we("flex min-w-0 items-center gap-4",e?"w-full":void 0),children:[S.user?.avatarUrl?s.jsx("img",{src:S.user.avatarUrl,alt:S.user.login?t("settings.github.page.avatarAlt.withLogin",{login:S.user.login}):t("settings.github.page.avatarAlt.fallback"),className:"h-10 w-10 shrink-0 rounded-full border border-[var(--interactive-border)] bg-[var(--surface-muted)] object-cover",loading:"lazy",referrerPolicy:"no-referrer"}):s.jsx("div",{className:"flex h-10 w-10 shrink-0 items-center justify-center rounded-full border border-[var(--interactive-border)] bg-[var(--surface-muted)]",children:s.jsx(L,{name:"github-fill",className:"h-4 w-4 text-muted-foreground"})}),s.jsxs("div",{className:"min-w-0 flex-1",children:[!S.disabled&&S.user&&s.jsx("div",{className:"typography-ui-label text-foreground truncate",children:S.user.name?.trim()||S.user.login||"GitHub"}),!S.disabled&&S.user?.login&&s.jsxs("div",{className:we("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:S.user.login}),S.user.email&&s.jsx("span",{className:"opacity-50",children:"•"}),S.user.email&&s.jsx("span",{children:S.user.email})]}),s.jsx("div",{className:we("typography-meta text-muted-foreground",S.disabled?"opacity-60":void 0),children:S.disabled?t("settings.github.page.ghCli.disabledDescription"):t("settings.github.page.ghCli.fallbackDescription")})]})]}),s.jsx(B,{size:"sm",variant:"outline",onClick:()=>E(!S.disabled),disabled:x,className:we(e?"w-full":void 0),children:S.disabled?t("settings.github.page.ghCli.actions.enable"):t("settings.github.page.ghCli.actions.disable")})]})})})]})},Lo=[{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)"}],Xg=[{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"}],Zg=({open:t,onOpenChange:e,profileId:a,importData:n})=>{const{t:i}=nt(),r=Ln(z=>z.getProfileById),l=Ln(z=>z.createProfile),u=Ln(z=>z.updateProfile),g=Ln(z=>z.deleteProfile),x=o.useMemo(()=>a&&a!=="new"&&!n?r(a):null,[a,r,n]),d=a==="new"||n!=null,v=a==="global",[c,N]=o.useState(""),[b,C]=o.useState(""),[k,A]=o.useState(""),[h,E]=o.useState("ssh"),[F,I]=o.useState(""),[w,m]=o.useState(!1),[y,U]=o.useState(""),[S,M]=o.useState(""),[j,R]=o.useState("keyword"),[H,P]=o.useState("branch"),[G,J]=o.useState(!1),[T,W]=o.useState(!1),[X,K]=o.useState(!1);o.useEffect(()=>{if(t){if(n){const z=n.host.split("/"),Z=z.length>=3?z[z.length-1]:n.host;N(Z),C(n.username),A(""),E("token"),I(""),m(!1),U(""),M(n.host),R("string"),P("code")}else if(d)N(""),C(""),A(""),E("ssh"),I(""),m(!1),U(""),M(""),R("keyword"),P("branch");else if(x)N(x.name),C(x.userName),A(x.userEmail),E(x.authType||"ssh"),I(x.sshKey||""),m(x.signCommits===!0),U(x.signingKey||""),M(x.host||""),R(x.color||"keyword"),P(x.icon||"branch");else if(v){const z=r("global");z&&(N(z.name),C(z.userName),A(z.userEmail),E(z.authType||"ssh"),I(z.sshKey||""),m(!1),U(""),M(z.host||""),R(z.color||"keyword"),P(z.icon||"branch"))}}},[t,a,x,d,n,v,r]);const te=async()=>{if(!b.trim()||!k.trim()){D.error(i("settings.gitIdentities.editor.toast.userNameEmailRequired"));return}if(h==="token"&&!S.trim()){D.error(i("settings.gitIdentities.editor.toast.hostRequiredForToken"));return}if(w&&!y.trim()){D.error(i("settings.gitIdentities.editor.toast.signingKeyRequired"));return}J(!0);try{const z={name:c.trim()||b.trim(),userName:b.trim(),userEmail:k.trim(),authType:h,sshKey:h==="ssh"&&F.trim()||null,signCommits:w,signingKey:y.trim()||null,host:h==="token"&&S.trim()||null,color:j,icon:H};let Z;if(d)Z=await l(z);else if(a)Z=await u(a,z);else return;Z?(D.success(i(d?"settings.gitIdentities.editor.toast.profileCreated":"settings.gitIdentities.editor.toast.profileUpdated")),e(!1)):D.error(i(d?"settings.gitIdentities.editor.toast.createProfileFailed":"settings.gitIdentities.editor.toast.updateProfileFailed"))}catch(z){console.error("Error saving profile:",z),D.error(i("settings.gitIdentities.editor.toast.saveUnexpectedError"))}finally{J(!1)}},$=async()=>{if(!(!a||d)){K(!0);try{await g(a)?(D.success(i("settings.gitIdentities.editor.toast.profileDeleted")),W(!1),e(!1)):D.error(i("settings.gitIdentities.editor.toast.deleteProfileFailed"))}catch(z){console.error("Error deleting profile:",z),D.error(i("settings.gitIdentities.editor.toast.deleteUnexpectedError"))}finally{K(!1)}}},V=o.useMemo(()=>Lo.find(Z=>Z.key===j)?.cssVar||"var(--syntax-keyword)",[j]),_=n?i("settings.gitIdentities.editor.title.importCredential"):d?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(Rt,{open:t,onOpenChange:e,children:s.jsxs(Ot,{className:"max-w-lg max-h-[85vh] overflow-y-auto",children:[s.jsxs(Kt,{children:[s.jsx(Ut,{children:_}),s.jsx(zt,{children:i(v?"settings.gitIdentities.editor.description.globalReadOnly":d?"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:`${It} block mb-1.5`,children:i("settings.gitIdentities.editor.field.profileName")}),s.jsx(We,{value:c,onChange:z=>N(z.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:Lo.map(z=>s.jsx("button",{type:"button",onClick:()=>R(z.key),className:we("w-6 h-6 rounded-md border-2 transition-all cursor-pointer",j===z.key?"border-foreground scale-110":"border-transparent hover:border-border"),style:{backgroundColor:z.cssVar},title:z.label},z.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:Xg.map(z=>{const Z=z.Icon;return s.jsx("button",{type:"button",onClick:()=>P(z.key),className:we("w-7 h-7 rounded-md border-2 transition-all flex items-center justify-center cursor-pointer",H===z.key?"border-[var(--interactive-border)] bg-[var(--surface-muted)]":"border-transparent hover:border-[var(--interactive-border)] hover:bg-[var(--surface-muted)]/50"),title:z.label,children:s.jsx(L,{name:Z,className:"w-3.5 h-3.5",style:{color:H===z.key?V:"var(--surface-muted-foreground)"}})},z.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:It,children:i("settings.gitIdentities.editor.field.userName")}),!v&&s.jsx("span",{className:"text-[var(--status-error)] text-xs",children:"*"}),s.jsx(Jt,{contentClassName:"max-w-xs",children:i("settings.gitIdentities.editor.field.userNameTooltip")})]}),s.jsx(We,{value:b,onChange:z=>C(z.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:It,children:i("settings.gitIdentities.editor.field.emailAddress")}),!v&&s.jsx("span",{className:"text-[var(--status-error)] text-xs",children:"*"}),s.jsx(Jt,{contentClassName:"max-w-xs",children:i("settings.gitIdentities.editor.field.emailAddressTooltip")})]}),s.jsx(We,{type:"email",value:k,onChange:z=>A(z.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":h==="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":h==="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")]})]})]}),h==="ssh"&&s.jsxs("div",{children:[s.jsxs("div",{className:"flex items-center gap-1.5 mb-1.5",children:[s.jsx("label",{className:It,children:i("settings.gitIdentities.editor.field.sshKeyPath")}),s.jsx(Jt,{contentClassName:"max-w-xs",children:i("settings.gitIdentities.editor.field.sshKeyPathTooltip")})]}),s.jsx(We,{value:F,onChange:z=>I(z.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(pt,{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:It,children:i("settings.gitIdentities.editor.field.signingKey")})}),s.jsx(We,{value:y,onChange:z=>U(z.target.value),placeholder:i("settings.gitIdentities.editor.field.signingKeyPlaceholder"),disabled:!w,className:"h-8 font-mono text-xs"})]})]}),h==="token"&&s.jsxs("div",{children:[s.jsxs("div",{className:"flex items-center gap-1.5 mb-1.5",children:[s.jsx("label",{className:It,children:i("settings.gitIdentities.editor.field.host")}),s.jsx("span",{className:"text-[var(--status-error)] text-xs",children:"*"}),s.jsx(Jt,{contentClassName:"max-w-xs",children:i("settings.gitIdentities.editor.field.hostTooltip")})]}),s.jsx(We,{value:S,onChange:z=>M(z.target.value),placeholder:i("settings.gitIdentities.editor.field.hostPlaceholder"),required:!0,className:"h-8 font-mono text-xs"})]})]})]})]}),s.jsxs(es,{className:"gap-2",children:[!v&&!d&&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:te,disabled:G,children:i(G?"settings.common.actions.saving":d?"settings.gitIdentities.editor.actions.create":"settings.gitIdentities.editor.actions.save")})]})]})}),s.jsx(Rt,{open:T,onOpenChange:z=>{X||W(z)},children:s.jsxs(Ot,{className:"max-w-md",children:[s.jsxs(Kt,{children:[s.jsx(Ut,{children:i("settings.gitIdentities.page.deleteDialog.title")}),s.jsx(zt,{children:i("settings.gitIdentities.page.deleteDialog.description",{name:x?.name||c})})]}),s.jsxs(es,{children:[s.jsx(B,{variant:"ghost",onClick:()=>W(!1),disabled:X,children:i("settings.common.actions.cancel")}),s.jsx(B,{size:"sm",variant:"destructive",onClick:()=>{$()},disabled:X,children:i("settings.common.actions.delete")})]})]})})]})},eh={branch:"git-branch",briefcase:"briefcase",house:"home",graduation:"graduation-cap",code:"code",heart:"heart"},th={keyword:"var(--syntax-keyword)",error:"var(--status-error)",string:"var(--syntax-string)",function:"var(--syntax-function)",type:"var(--syntax-type)"},sh=()=>{const t=lt.c(113),{t:e}=nt(),{profiles:a,globalIdentity:n,defaultGitIdentityId:i,deleteProfile:r,loadProfiles:l,loadGlobalIdentity:u,loadDiscoveredCredentials:g,loadDefaultGitIdentityId:x,setDefaultGitIdentityId:d,getUnimportedCredentials:v}=Ln(Ds(ah)),[c,N]=o.useState(!1),[b,C]=o.useState(null),[k,A]=o.useState(null),[h,E]=o.useState(null),[F,I]=o.useState(!1);let w,m;t[0]!==x||t[1]!==g||t[2]!==u||t[3]!==l?(w=()=>{l(),u(),g(),x()},m=[l,u,g,x],t[0]=x,t[1]=g,t[2]=u,t[3]=l,t[4]=w,t[5]=m):(w=t[4],m=t[5]),o.useEffect(w,m);let y,U,S,M,j,R,H,P,G,J,T,W,X,K;if(t[6]!==i||t[7]!==h||t[8]!==r||t[9]!==v||t[10]!==n||t[11]!==a||t[12]!==d||t[13]!==e){const Be=v();let Ve;t[28]===Symbol.for("react.memo_cache_sentinel")?(Ve=(Te,xe)=>{C(Te),A(xe??null),N(!0)},t[28]=Ve):Ve=t[28];const Ge=Ve;let Ke;t[29]!==i||t[30]!==d||t[31]!==e?(Ke=async Te=>{const xe=i===Te?null:Te;if(!await d(xe)){D.error(e("settings.gitIdentities.page.toast.updateDefaultFailed"));return}D.success(e(xe?"settings.gitIdentities.page.toast.defaultUpdated":"settings.gitIdentities.page.toast.defaultUnset"))},t[29]=i,t[30]=d,t[31]=e,t[32]=Ke):Ke=t[32];const oe=Ke;let ie;t[33]!==h||t[34]!==r||t[35]!==e?(ie=async()=>{if(!h)return;I(!0),await r(h.id)?(D.success(e("settings.gitIdentities.page.toast.profileDeleted",{name:h.name})),E(null)):D.error(e("settings.gitIdentities.page.toast.deleteProfileFailed")),I(!1)},t[33]=h,t[34]=r,t[35]=e,t[36]=ie):ie=t[36],S=ie,U=ns,t[37]!==e?(M=e("settings.page.git.title"),t[37]=e,t[38]=M):M=t[38],j=!0,t[39]===Symbol.for("react.memo_cache_sentinel")?(R=s.jsx(Vl,{}),t[39]=R):R=t[39],y=$e,t[40]!==e?(W=e("settings.gitIdentities.page.section.title"),t[40]=e,t[41]=W):W=t[41];let ye,ve;t[42]===Symbol.for("react.memo_cache_sentinel")?(ye=()=>Ge("new"),ve=s.jsx(L,{name:"add",className:"w-3.5 h-3.5 mr-1"}),t[42]=ye,t[43]=ve):(ye=t[42],ve=t[43]);let Oe;t[44]!==e?(Oe=e("settings.common.badge.new"),t[44]=e,t[45]=Oe):Oe=t[45],t[46]!==Oe?(X=s.jsxs(B,{size:"sm",variant:"outline",onClick:ye,children:[ve," ",Oe]}),t[46]=Oe,t[47]=X):X=t[47],K="git.identities",H="rounded-lg bg-[var(--surface-elevated)]/70 overflow-hidden flex flex-col",P=n&&s.jsx(Fo,{profile:n,isDefault:i==="global",onEdit:()=>Ge("global"),onToggleDefault:()=>oe("global"),isReadOnly:!0,hasBorder:a.length>0||Be.length>0}),G=a.map((Te,xe)=>s.jsx(Fo,{profile:Te,isDefault:i===Te.id,onEdit:()=>Ge(Te.id),onToggleDefault:()=>oe(Te.id),onDelete:()=>E(Te),hasBorder:xe<a.length-1||Be.length>0},Te.id)),J=!n&&a.length===0&&Be.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")})]}),T=Be.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")})}),Be.map((Te,xe)=>s.jsx(nh,{credential:Te,onImport:()=>Ge("new",{host:Te.host,username:Te.username}),hasBorder:xe<Be.length-1},`${Te.host}-${Te.username}`))]}),t[6]=i,t[7]=h,t[8]=r,t[9]=v,t[10]=n,t[11]=a,t[12]=d,t[13]=e,t[14]=y,t[15]=U,t[16]=S,t[17]=M,t[18]=j,t[19]=R,t[20]=H,t[21]=P,t[22]=G,t[23]=J,t[24]=T,t[25]=W,t[26]=X,t[27]=K}else y=t[14],U=t[15],S=t[16],M=t[17],j=t[18],R=t[19],H=t[20],P=t[21],G=t[22],J=t[23],T=t[24],W=t[25],X=t[26],K=t[27];let te;t[48]!==H||t[49]!==P||t[50]!==G||t[51]!==J||t[52]!==T?(te=s.jsxs("div",{className:H,children:[P,G,J,T]}),t[48]=H,t[49]=P,t[50]=G,t[51]=J,t[52]=T,t[53]=te):te=t[53];let $;t[54]!==y||t[55]!==te||t[56]!==W||t[57]!==X||t[58]!==K?($=s.jsx(y,{title:W,headerAction:X,settingsItem:K,children:te}),t[54]=y,t[55]=te,t[56]=W,t[57]=X,t[58]=K,t[59]=$):$=t[59];let V;t[60]===Symbol.for("react.memo_cache_sentinel")?(V=s.jsx($l,{}),t[60]=V):V=t[60];let _;t[61]!==U||t[62]!==M||t[63]!==j||t[64]!==R||t[65]!==$?(_=s.jsxs(U,{title:M,showSaveStatus:j,children:[R,$,V]}),t[61]=U,t[62]=M,t[63]=j,t[64]=R,t[65]=$,t[66]=_):_=t[66];let z;t[67]!==k||t[68]!==c||t[69]!==b?(z=s.jsx(Zg,{open:c,onOpenChange:N,profileId:b,importData:k}),t[67]=k,t[68]=c,t[69]=b,t[70]=z):z=t[70];const Z=h!==null;let Y;t[71]!==F?(Y=Be=>{F||Be||E(null)},t[71]=F,t[72]=Y):Y=t[72];let se;t[73]!==e?(se=e("settings.gitIdentities.page.deleteDialog.title"),t[73]=e,t[74]=se):se=t[74];let ge;t[75]!==se?(ge=s.jsx(Ut,{children:se}),t[75]=se,t[76]=ge):ge=t[76];const ce=h?.name??"";let be;t[77]!==e||t[78]!==ce?(be=e("settings.gitIdentities.page.deleteDialog.description",{name:ce}),t[77]=e,t[78]=ce,t[79]=be):be=t[79];let ne;t[80]!==be?(ne=s.jsx(zt,{children:be}),t[80]=be,t[81]=ne):ne=t[81];let ae;t[82]!==ge||t[83]!==ne?(ae=s.jsxs(Kt,{children:[ge,ne]}),t[82]=ge,t[83]=ne,t[84]=ae):ae=t[84];let me;t[85]===Symbol.for("react.memo_cache_sentinel")?(me=()=>E(null),t[85]=me):me=t[85];let Pe;t[86]!==e?(Pe=e("settings.common.actions.cancel"),t[86]=e,t[87]=Pe):Pe=t[87];let Ne;t[88]!==F||t[89]!==Pe?(Ne=s.jsx(B,{variant:"ghost",onClick:me,disabled:F,children:Pe}),t[88]=F,t[89]=Pe,t[90]=Ne):Ne=t[90];let Se;t[91]!==S?(Se=()=>{S()},t[91]=S,t[92]=Se):Se=t[92];let je;t[93]!==e?(je=e("settings.common.actions.delete"),t[93]=e,t[94]=je):je=t[94];let Me;t[95]!==F||t[96]!==Se||t[97]!==je?(Me=s.jsx(B,{size:"sm",variant:"destructive",onClick:Se,disabled:F,children:je}),t[95]=F,t[96]=Se,t[97]=je,t[98]=Me):Me=t[98];let Re;t[99]!==Ne||t[100]!==Me?(Re=s.jsxs(es,{children:[Ne,Me]}),t[99]=Ne,t[100]=Me,t[101]=Re):Re=t[101];let re;t[102]!==ae||t[103]!==Re?(re=s.jsxs(Ot,{className:"max-w-md",children:[ae,Re]}),t[102]=ae,t[103]=Re,t[104]=re):re=t[104];let fe;t[105]!==Z||t[106]!==Y||t[107]!==re?(fe=s.jsx(Rt,{open:Z,onOpenChange:Y,children:re}),t[105]=Z,t[106]=Y,t[107]=re,t[108]=fe):fe=t[108];let Ee;return t[109]!==_||t[110]!==z||t[111]!==fe?(Ee=s.jsxs(s.Fragment,{children:[_,z,fe]}),t[109]=_,t[110]=z,t[111]=fe,t[112]=Ee):Ee=t[112],Ee},Fo=t=>{const e=lt.c(56),{profile:a,isDefault:n,onEdit:i,onToggleDefault:r,onDelete:l,isReadOnly:u,hasBorder:g}=t,{t:x}=nt(),[d,v]=o.useState(!1),c=eh[a.icon||"branch"]||"git-branch",N=th[a.color||""],b=a.authType||"ssh";let C;e[0]!==i?(C=$=>{$.currentTarget===$.target&&($.key!=="Enter"&&$.key!==" "||($.preventDefault(),i()))},e[0]=i,e[1]=C):C=e[1];const k=C;let A;e[2]!==n||e[3]!==u||e[4]!==l||e[5]!==r||e[6]!==x?(A=$=>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")}),!u&&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]=u,e[4]=l,e[5]=r,e[6]=x,e[7]=A):A=e[7];const h=A,E=g&&"border-b border-[var(--surface-subtle)]";let F;e[8]!==E?(F=we("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]=F):F=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]!==k||e[12]!==i||e[13]!==F?(w=s.jsx("div",{className:F,onClick:i,role:"button",tabIndex:0,onKeyDown:k,onContextMenu:I}),e[11]=k,e[12]=i,e[13]=F,e[14]=w):w=e[14];let m;e[15]!==N?(m={color:N},e[15]=N,e[16]=m):m=e[16];let y;e[17]!==c||e[18]!==m?(y=s.jsx(L,{name:c,className:"w-4 h-4 shrink-0",style:m}),e[17]=c,e[18]=m,e[19]=y):y=e[19];let U;e[20]!==a.name?(U=s.jsx("span",{className:"typography-ui-label text-foreground truncate",children:a.name}),e[20]=a.name,e[21]=U):U=e[21];let S;e[22]!==b?(S=s.jsx("span",{className:"typography-micro text-muted-foreground bg-muted px-1 rounded flex-shrink-0 leading-none pb-px border border-border/50",children:b}),e[22]=b,e[23]=S):S=e[23];let M;e[24]!==n||e[25]!==x?(M=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]=M):M=e[26];let j;e[27]!==u||e[28]!==x?(j=u&&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]=u,e[28]=x,e[29]=j):j=e[29];let R;e[30]!==S||e[31]!==M||e[32]!==j||e[33]!==U?(R=s.jsxs("div",{className:"flex items-center gap-1.5",children:[U,S,M,j]}),e[30]=S,e[31]=M,e[32]=j,e[33]=U,e[34]=R):R=e[34];const H=b==="token"&&a.host?a.host:a.userEmail;let P;e[35]!==H?(P=s.jsx("div",{className:"typography-micro text-muted-foreground/60 truncate leading-tight",children:H}),e[35]=H,e[36]=P):P=e[36];let G;e[37]!==R||e[38]!==P?(G=s.jsxs("div",{className:"min-w-0",children:[R,P]}),e[37]=R,e[38]=P,e[39]=G):G=e[39];let J;e[40]!==G||e[41]!==y?(J=s.jsxs("div",{className:"flex items-center gap-3 min-w-0",children:[y,G]}),e[40]=G,e[41]=y,e[42]=J):J=e[42];let T;e[43]===Symbol.for("react.memo_cache_sentinel")?(T=s.jsx(Zs,{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:ih,children:s.jsx(L,{name:"more-2",className:"h-3.5 w-3.5"})})}),e[43]=T):T=e[43];let W;e[44]!==h?(W=s.jsxs(tn,{children:[T,s.jsx(en,{align:"end",className:"w-fit min-w-28",children:h(sn)})]}),e[44]=h,e[45]=W):W=e[45];let X;e[46]!==J||e[47]!==W||e[48]!==w?(X=s.jsxs(Vn,{render:w,children:[J,W]}),e[46]=J,e[47]=W,e[48]=w,e[49]=X):X=e[49];let K;e[50]!==h?(K=s.jsx(_n,{className:"w-fit min-w-28",children:h($n)}),e[50]=h,e[51]=K):K=e[51];let te;return e[52]!==d||e[53]!==X||e[54]!==K?(te=s.jsxs(Bn,{open:d,onOpenChange:v,children:[X,K]}),e[52]=d,e[53]=X,e[54]=K,e[55]=te):te=e[55],te},nh=t=>{const e=lt.c(21),{credential:a,onImport:n,hasBorder:i}=t,{t:r}=nt();let l;e[0]!==a.host?(l=a.host.split("/"),e[0]=a.host,e[1]=l):l=e[1];const u=l,g=u.length>=3?u[u.length-1]:a.host,x=a.host.includes("/"),d=i&&"border-b border-[var(--surface-subtle)]";let v;e[2]!==d?(v=we("flex items-center justify-between gap-3 px-4 py-2.5 transition-colors hover:bg-[var(--interactive-hover)]/30",d),e[2]=d,e[3]=v):v=e[3];let c;e[4]!==g?(c=s.jsx("span",{className:"typography-ui-label text-foreground truncate block",children:g}),e[4]=g,e[5]=c):c=e[5];const N=x?a.host:a.username;let b;e[6]!==N?(b=s.jsx("span",{className:"typography-micro text-muted-foreground/60 truncate block leading-tight",children:N}),e[6]=N,e[7]=b):b=e[7];let C;e[8]!==c||e[9]!==b?(C=s.jsxs("div",{className:"min-w-0",children:[c,b]}),e[8]=c,e[9]=b,e[10]=C):C=e[10];let k;e[11]===Symbol.for("react.memo_cache_sentinel")?(k=s.jsx(L,{name:"download",className:"h-3 w-3"}),e[11]=k):k=e[11];let A;e[12]!==r?(A=r("settings.gitIdentities.page.actions.import"),e[12]=r,e[13]=A):A=e[13];let h;e[14]!==n||e[15]!==A?(h=s.jsxs(B,{size:"sm",variant:"ghost",onClick:n,className:"gap-1 shrink-0",children:[k,A]}),e[14]=n,e[15]=A,e[16]=h):h=e[16];let E;return e[17]!==h||e[18]!==v||e[19]!==C?(E=s.jsxs("div",{className:v,children:[C,h]}),e[17]=h,e[18]=v,e[19]=C,e[20]=E):E=e[20],E};function ah(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 ih(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"}],rh=(t,e)=>t===e||t.startsWith(`${e}@`);function $i(t,e,a){const n=t.filter(g=>rh(g.spec,e)),i=n.filter(g=>g.scope==="user"),r=n.filter(g=>g.scope==="project"),l=i.length===1?i[0]:null,u=a[l?.spec??e]??a[e]??null;return{userEntry:l,userEntryIsAmbiguous:i.length>1,projectEntries:r,registry:u}}function rr(t,e){return e?.kind!=="npm-ok"||e.name!==t||!e.latestVersion?null:`${t}@${e.latestVersion}`}function Ko(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 oh(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 lh=t=>t.restartDeferred===!0||t.requiresManualRestart===!0||t.reloadFailed===!0,ch=({divider:t=!0,onOpenProviderSetup:e,onOpenPluginManager:a})=>{const{t:n}=nt(),{entries:i,registryInfo:r,loadPlugins:l,loadRegistryInfo:u,createEntry:g,updateEntry:x,deleteEntry:d}=rs(Ds(T=>({entries:T.entries,registryInfo:T.registryInfo,loadPlugins:T.loadPlugins,loadRegistryInfo:T.loadRegistryInfo,createEntry:T.createEntry,updateEntry:T.updateEntry,deleteEntry:T.deleteEntry}))),[v,c]=o.useState(!1),[N,b]=o.useState(null),[C,k]=o.useState(()=>new Set),[A,h]=o.useState(()=>new Set),[E,F]=o.useState(null),[I,w]=o.useState(()=>new Set),m=o.useCallback(async()=>{if(!await l({force:!0})){c(!0);return}const W=rs.getState().entries,X=new Set(_i.map(te=>te.packageName));for(const te of W)_i.some($=>te.spec===$.packageName||te.spec.startsWith(`${$.packageName}@`))&&X.add(te.spec);const K=await u({specs:[...X],force:!0});c(!K)},[l,u]);o.useEffect(()=>{m()},[m]);const y=gn(T=>T.changes.filter(W=>W.scope==="plugins").length),U=gn(T=>T.isApplying),S=o.useRef(y);o.useEffect(()=>{const T=S.current;S.current=y,!U&&(T<=0||y>0||(k(new Set),h(new Set),m()))},[U,y,m]);const M=o.useCallback((T,W)=>{k(X=>{const K=new Set(X);return W?K.add(T):K.delete(T),K})},[]),j=o.useCallback((T,W)=>{h(X=>{const K=new Set(X);return W?K.add(T):K.delete(T),K})},[]),R=o.useCallback(async(T,W,X)=>{b({pluginId:T.id,action:W});try{const K=await X();if(!K.ok){D.error(n("settings.integrations.thirdParty.toast.actionFailed"));return}j(T.id,!1);const te=lh(K);M(T.id,te);const $=te?{description:n("settings.integrations.thirdParty.toast.restartRequired")}:void 0;W==="install"?D.success(n("settings.integrations.thirdParty.toast.installed",{name:n(T.nameKey)}),$):W==="update"?D.success(n("settings.integrations.thirdParty.toast.updated",{name:n(T.nameKey)}),$):D.success(n("settings.integrations.thirdParty.toast.removed",{name:n(T.nameKey)}),$),await m()}finally{b(null)}},[m,j,M,n]),H=o.useCallback(async T=>{const W=$i(i,T.packageName,r),X=Ko(W,T.packageName);if(X==="manage"){a();return}if(X==="setup"){b({pluginId:T.id,action:X});try{const te=await e(T.providerId);j(T.id,!te),te||D.error(n("settings.integrations.thirdParty.toast.providerUnavailable"))}finally{b(null)}return}const K=rr(T.packageName,W.registry);if(!K){c(!0);return}if(X==="install"){await R(T,"install",()=>g({spec:K,scope:"user"}));return}W.userEntry&&await R(T,"update",()=>x(W.userEntry.id,{spec:K}))},[g,i,a,e,r,R,j,n,x]),P=o.useCallback(async()=>{const T=E;if(!T)return;const W=$i(i,T.packageName,r);if(!W.userEntry||W.userEntryIsAmbiguous){F(null),a();return}F(null),await R(T,"remove",()=>d(W.userEntry.id))},[d,i,a,r,E,R]),G=o.useCallback((T,W)=>{w(X=>{const K=new Set(X);return W?K.add(T):K.delete(T),K})},[]),J=T=>{const W=$i(i,T.packageName,r),X=Ko(W,T.packageName),K=rr(T.packageName,W.registry),te=N?.pluginId===T.id,$=C.has(T.id),V=A.has(T.id),_=v||W.registry?.kind==="npm-network",z=te||$||(X==="install"||X==="update")&&(_||!K),Z=oh(W,{registryUnavailable:_,restartRequired:$,providerUnavailable:V});let Y;switch(Z.status){case"installed-version":Y=Z.latestVersion?n("settings.integrations.thirdParty.status.installedVersion",{version:Z.latestVersion}):n("settings.integrations.thirdParty.status.installed");break;case"update-available":Y=Z.latestVersion?n("settings.integrations.thirdParty.status.updateAvailable",{version:Z.latestVersion}):n("settings.integrations.thirdParty.status.unpinned");break;case"not-installed":Y=n("settings.integrations.thirdParty.status.notInstalled");break;case"installed":Y=n("settings.integrations.thirdParty.status.installed");break;case"unpinned":Y=n("settings.integrations.thirdParty.status.unpinned");break;case"ambiguous":Y=n("settings.integrations.thirdParty.status.ambiguous");break;case"restart-required":Y=n("settings.integrations.thirdParty.status.restartRequired");break;case"registry-unavailable":Y=n("settings.integrations.thirdParty.status.registryUnavailable");break;case"provider-unavailable":Y=n("settings.integrations.thirdParty.status.providerUnavailable");break}const se=Z.status==="installed-version"?"bg-[var(--status-success)]/15 text-[var(--status-success)]":Z.status==="update-available"||Z.status==="ambiguous"||Z.status==="restart-required"||Z.status==="registry-unavailable"||Z.status==="provider-unavailable"?"bg-[var(--status-warning)]/15 text-[var(--status-warning)]":"bg-[var(--surface-muted)] text-muted-foreground",ge={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")}[X],ce=I.has(T.id);return s.jsx(Hn,{open:ce,onOpenChange:be=>G(T.id,be),children:s.jsxs("div",{"data-settings-item":`integrations.third-party.${T.id}`,className:"overflow-hidden rounded-xl border border-[var(--interactive-border)] bg-[var(--surface-elevated)]",children:[s.jsxs(Gn,{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:T.icon,className:we("size-5",T.brandClassName)})}),s.jsxs("div",{className:"min-w-0 flex-1",children:[s.jsx("div",{className:"truncate text-sm font-semibold text-foreground",children:n(T.nameKey)}),s.jsx("p",{className:"mt-0.5 line-clamp-1 text-xs leading-snug text-muted-foreground",children:n(T.descriptionKey)})]}),s.jsx("span",{"aria-live":"polite",className:we("max-w-36 shrink-0 truncate rounded-full px-2 py-0.5 text-[10px] font-medium",se),children:Y}),s.jsx(L,{name:"arrow-down-s",className:we("size-4 shrink-0 text-muted-foreground transition-transform duration-150 ease-out motion-reduce:transition-none",ce&&"rotate-180")})]}),s.jsx(qn,{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:X==="manage"?"outline":"default",onClick:()=>{H(T)},disabled:z,children:[te?s.jsx(L,{name:"loader-4",className:"size-3.5 animate-spin"}):X==="setup"?s.jsx(L,{name:"plug-2",className:"size-3.5"}):null,ge]}),s.jsxs(B,{type:"button",size:"sm",variant:"secondary",onClick:()=>{In(T.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:()=>F(T),disabled:te,children:[s.jsx(L,{name:"delete-bin",className:"size-3.5"}),n("settings.integrations.thirdParty.actions.remove")]}):null]})]})})]})},T.id)};return s.jsxs(s.Fragment,{children:[s.jsx($e,{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(J)}),s.jsx(Rt,{open:E!==null,onOpenChange:T=>!T&&F(null),children:s.jsxs(Ot,{className:"max-w-md",children:[s.jsxs(Kt,{children:[s.jsx(Ut,{children:n("settings.integrations.thirdParty.dialog.remove.title")}),s.jsx(zt,{children:n("settings.integrations.thirdParty.dialog.remove.description",{name:E?n(E.nameKey):""})})]}),s.jsxs(es,{children:[s.jsx(B,{type:"button",size:"sm",variant:"ghost",onClick:()=>F(null),children:n("settings.common.actions.cancel")}),s.jsx(B,{type:"button",size:"sm",variant:"destructive",onClick:()=>{P()},children:n("settings.integrations.thirdParty.actions.remove")})]})]})})]})},dh=t=>{const e=lt.c(21),{onOpenProviderSetup:a,onOpenPluginManager:n}=t,{t:i}=nt();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 u;e[4]!==l?(u=s.jsx("p",{className:al,children:l}),e[4]=l,e[5]=u):u=e[5];let g;e[6]===Symbol.for("react.memo_cache_sentinel")?(g=s.jsx(L,{name:"error-warning",className:"mt-0.5 size-4 shrink-0 text-[var(--status-warning)]"}),e[6]=g):g=e[6];let x;e[7]!==i?(x=i("settings.integrations.experimentalWarning"),e[7]=i,e[8]=x):x=e[8];let d;e[9]!==x?(d=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:[g,s.jsx("p",{className:"typography-meta text-[var(--status-warning)]",children:x})]}),e[9]=x,e[10]=d):d=e[10];let v;e[11]!==u||e[12]!==d?(v=s.jsxs("div",{className:"space-y-3",children:[u,d]}),e[11]=u,e[12]=d,e[13]=v):v=e[13];let c;e[14]!==n||e[15]!==a?(c=s.jsx(ch,{divider:!1,onOpenProviderSetup:a,onOpenPluginManager:n}),e[14]=n,e[15]=a,e[16]=c):c=e[16];let N;return e[17]!==r||e[18]!==v||e[19]!==c?(N=s.jsx(ns,{title:r,description:v,showSaveStatus:!1,children:c}),e[17]=r,e[18]=v,e[19]=c,e[20]=N):N=e[20],N},ph=[{value:"system",labelKey:"settings.openchamber.visual.option.themeMode.system",descriptionKey:"settings.openchamber.visual.option.themeMode.system.description"},{value:"light",labelKey:"settings.openchamber.visual.option.themeMode.light",descriptionKey:"settings.openchamber.visual.option.themeMode.light.description"},{value:"dark",labelKey:"settings.openchamber.visual.option.themeMode.dark",descriptionKey:"settings.openchamber.visual.option.themeMode.dark.description"}],mh=[{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"}],uh=[{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"}],Pa="OpenChamber - AI Coding Assistant",Uo=[{id:"system",labelKey:"settings.openchamber.visual.option.pwaOrientation.system.label",descriptionKey:"settings.openchamber.visual.option.pwaOrientation.system.description"},{id:"portrait",labelKey:"settings.openchamber.visual.option.pwaOrientation.portrait.label",descriptionKey:"settings.openchamber.visual.option.pwaOrientation.portrait.description"},{id:"landscape",labelKey:"settings.openchamber.visual.option.pwaOrientation.landscape.label",descriptionKey:"settings.openchamber.visual.option.pwaOrientation.landscape.description"}],zo=[{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",gh=[{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"}],hh=[{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"}],_o=[{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"}],fh=[{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"}],Vo=[{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"}],xh=[{id:"steer",labelKey:"settings.openchamber.visual.option.followUpBehavior.steer.label"},{id:"queue",labelKey:"settings.openchamber.visual.option.followUpBehavior.queue.label"}],bh=[{id:"ask",labelKey:"settings.openchamber.visual.option.largeTextPaste.ask.label"},{id:"attach",labelKey:"settings.openchamber.visual.option.largeTextPaste.attach.label"},{id:"inline",labelKey:"settings.openchamber.visual.option.largeTextPaste.inline.label"}],vh=t=>t==="markdown"?"markdown":"plain",yh=[{id:"left",labelKey:"settings.openchamber.desktopNetwork.option.windowControlsLeft"},{id:"right",labelKey:"settings.openchamber.desktopNetwork.option.windowControlsRight"}],jh=[{id:"classic",labelKey:"settings.openchamber.desktopNetwork.option.windowControlsClassic"},{id:"traffic-lights",labelKey:"settings.openchamber.desktopNetwork.option.windowControlsTrafficLights"}],ui=({visibleSettings:t})=>{const{locale:e,locales:a,setLocale:n,label:i,t:r}=nt(),l=o.useCallback(p=>r(p),[r]),{isMobile:u}=da(),{terminal:g}=ml(),{browserTab:x}=Dd(),d=xd(),v=de(p=>p.showReasoningTraces),c=de(p=>p.sessionRecapEnabled),N=de(p=>p.sessionSuggestionEnabled),b=de(p=>p.setSessionRecapEnabled),C=de(p=>p.setSessionSuggestionEnabled),k=de(p=>p.sessionGoalEnabled),A=de(p=>p.setSessionGoalEnabled),h=de(p=>p.sessionGoalDefaultBudgetEnabled),E=de(p=>p.setSessionGoalDefaultBudgetEnabled),F=de(p=>p.sessionGoalDefaultBudget),I=de(p=>p.setSessionGoalDefaultBudget),w=de(p=>p.setShowReasoningTraces),m=de(p=>p.streamingAutoFollowEnabled),y=de(p=>p.setStreamingAutoFollowEnabled),U=de(p=>p.collapsibleThinkingBlocks),S=de(p=>p.setCollapsibleThinkingBlocks),M=de(p=>p.mermaidRenderingMode),j=de(p=>p.setMermaidRenderingMode),R=de(p=>p.userMessageRenderingMode),H=de(p=>p.setUserMessageRenderingMode),P=de(p=>p.collapsibleUserMessages),G=de(p=>p.setCollapsibleUserMessages),J=de(p=>p.stickyUserHeader),T=de(p=>p.promptNavigatorEnabled),W=de(p=>p.setStickyUserHeader),X=de(p=>p.setPromptNavigatorEnabled),K=de(p=>p.autoSaveEnabled),te=de(p=>p.setAutoSaveEnabled),$=de(p=>p.wideChatLayoutEnabled),V=de(p=>p.setWideChatLayoutEnabled),_=de(p=>p.codeBlockLineWrap),z=de(p=>p.setCodeBlockLineWrap),Z=de(p=>p.chatRenderMode),Y=de(p=>p.setChatRenderMode),se=de(p=>p.activityRenderMode),ge=de(p=>p.setActivityRenderMode),ce=de(p=>p.fontSize),be=de(p=>p.setFontSize),ne=de(p=>p.terminalFontSize),ae=de(p=>p.setTerminalFontSize),me=de(p=>p.terminalShell),Pe=de(p=>p.setTerminalShell),Ne=de(p=>p.terminalLoginShells),Se=de(p=>p.setTerminalLoginShells),je=de(p=>p.editorFontSize),Me=de(p=>p.setEditorFontSize),Re=de(p=>p.uiFont),re=de(p=>p.setUiFont),fe=de(p=>p.monoFont),Ee=de(p=>p.setMonoFont),Be=de(p=>p.padding),Ve=de(p=>p.setPadding),Ge=de(p=>p.inputBarOffset),Ke=de(p=>p.setInputBarOffset),oe=de(p=>p.mobileKeyboardMode),ie=de(p=>p.setMobileKeyboardMode),ye=de(p=>p.diffLayoutPreference),ve=de(p=>p.setDiffLayoutPreference),Oe=de(p=>p.showTerminalQuickKeysOnDesktop),Te=de(p=>p.sessionTabsEnabled),xe=de(p=>p.setSessionTabsEnabled),He=de(p=>p.setShowTerminalQuickKeysOnDesktop),ue=de(p=>p.fileEditorKeymap),Ie=de(p=>p.setFileEditorKeymap),Le=Ur(p=>p.followUpBehavior),Ye=Ur(p=>p.setFollowUpBehavior),q=de(p=>p.persistChatDraft),ke=de(p=>p.setPersistChatDraft),O=de(p=>p.inputSpellcheckEnabled),Ce=de(p=>p.setInputSpellcheckEnabled),qe=de(p=>p.largeTextPasteBehavior),_e=de(p=>p.setLargeTextPasteBehavior),tt=de(p=>p.showToolFileIcons),ht=de(p=>p.setShowToolFileIcons),mt=de(p=>p.showTurnChangedFiles),ut=de(p=>p.setShowTurnChangedFiles),ft=de(p=>p.showExpandedBashTools),kt=de(p=>p.setShowExpandedBashTools),vt=de(p=>p.showExpandedEditTools),Ct=de(p=>p.setShowExpandedEditTools),Ze=de(p=>p.timeFormatPreference),Xe=de(p=>p.setTimeFormatPreference),ct=de(p=>p.weekStartPreference),Ue=de(p=>p.setWeekStartPreference),jt=de(p=>p.showSplitAssistantMessageActions),Ae=de(p=>p.setShowSplitAssistantMessageActions),yt=de(p=>p.allowPromptingSubagentSessions),Q=de(p=>p.setAllowPromptingSubagentSessions),he=de(p=>p.draftStartersVisible),ze=de(p=>p.setDraftStartersVisible),De=et(p=>p.settingsMessageStreamTransport),it=et(p=>p.setSettingsMessageStreamTransport),at=De,Je=et(p=>p.settingsDefaultFileViewerPreview),Nt=et(p=>p.setSettingsDefaultFileViewerPreview),xs=de(p=>p.isSettingsDialogOpen),{themeMode:ts,setThemeMode:Ms,availableThemes:Bt,customThemesLoading:os,reloadCustomThemes:qt,lightThemeId:bs,darkThemeId:ms,setLightThemePreference:vs,setDarkThemePreference:us}=gr(),[ys,le]=o.useState(!1),dt=o.useMemo(()=>ds()&&typeof window<"u"&&window.__OPENCHAMBER_PLATFORM__==="darwin",[]),bt=de(p=>p.dockBadgeEnabled),Qt=de(p=>p.setDockBadgeEnabled),Yt=bd(),Ht=de(p=>p.desktopWindowControlsPosition),as=de(p=>p.setDesktopWindowControlsPosition),js=de(p=>p.desktopWindowControlsStyle),ls=de(p=>p.setDesktopWindowControlsStyle),[St,Pt]=o.useState(0),_t=de(p=>p.reportUsage),Mt=de(p=>p.setReportUsage),is=o.useCallback(p=>{Mt(p),xt({reportUsage:p})},[Mt]),As=o.useCallback(p=>{as(p),xt({desktopWindowControlsPosition:p})},[as]),gi=o.useCallback(p=>{ls(p),xt({desktopWindowControlsStyle:p})},[ls]),_a=(xs||u||ps())&&(t?t.includes("chatRenderMode"):!0);o.useEffect(()=>{if(!_a)return;let p=null,gt=Date.now();const Xt=()=>{const wt=Date.now();wt-gt>=420&&(Pt(Gt=>(Gt+1)%24),gt=wt),p=requestAnimationFrame(Xt)};(typeof document>"u"||document.visibilityState==="visible")&&(p=requestAnimationFrame(Xt));const Zt=()=>{document.visibilityState==="visible"&&p===null?p=requestAnimationFrame(Xt):document.visibilityState!=="visible"&&p!==null&&(cancelAnimationFrame(p),p=null)};return document.addEventListener("visibilitychange",Zt),()=>{document.removeEventListener("visibilitychange",Zt),p!==null&&cancelAnimationFrame(p)}},[_a]);const hi=o.useCallback(p=>{H(p),xt({userMessageRenderingMode:p})},[H]),fi=o.useCallback(p=>{W(p),xt({stickyUserHeader:p})},[W]),Ls=o.useCallback(p=>{X(p),xt({promptNavigatorEnabled:p})},[X]),pa=o.useCallback(p=>{ze(p),xt({draftStartersVisible:p})},[ze]),xi=o.useCallback(p=>{G(p),xt({collapsibleUserMessages:p})},[G]),$a=o.useCallback(p=>{V(p),xt({wideChatLayoutEnabled:p})},[V]),bi=o.useCallback(p=>{Ae(p),xt({showSplitAssistantMessageActions:p})},[Ae]),vi=o.useCallback(p=>{Ce(p),xt({inputSpellcheckEnabled:p})},[Ce]),yi=o.useCallback(p=>{Y(p),xt({chatRenderMode:p})},[Y]),ji=o.useCallback(p=>{it(p),xt({messageStreamTransport:p})},[it]),wi=o.useCallback(p=>{ge(p),xt({activityRenderMode:p})},[ge]),ws=o.useCallback(p=>{j(p),xt({mermaidRenderingMode:p})},[j]),Bs=o.useCallback(p=>{ht(p),xt({showToolFileIcons:p})},[ht]),Jn=o.useCallback(p=>{ut(p),xt({showTurnChangedFiles:p})},[ut]),an=o.useCallback(p=>{Nt(p),xt({defaultFileViewerPreview:p}),window.dispatchEvent(new CustomEvent("openchamber:file-viewer-preview-mode-changed",{detail:{enabled:p}}))},[Nt]),hn=o.useCallback(p=>{kt(p),xt({showExpandedBashTools:p})},[kt]),Nr=o.useCallback(p=>{Ct(p),xt({showExpandedEditTools:p})},[Ct]),Ws=o.useCallback(p=>{Xe(p),xt({timeFormatPreference:p})},[Xe]),ki=o.useCallback(p=>{Ue(p),xt({weekStartPreference:p})},[Ue]),rn=o.useMemo(()=>Bt.filter(p=>p.metadata.variant==="light").sort((p,gt)=>p.metadata.name.localeCompare(gt.metadata.name)),[Bt]),on=o.useMemo(()=>Bt.filter(p=>p.metadata.variant==="dark").sort((p,gt)=>p.metadata.name.localeCompare(gt.metadata.name)),[Bt]),ln=o.useMemo(()=>rn.find(p=>p.metadata.id===bs)??rn[0],[rn,bs]),An=o.useMemo(()=>on.find(p=>p.metadata.id===ms)??on[0],[on,ms]),Qn=o.useCallback((p,gt)=>{const Xt=gt==="dark"?" Dark":" Light";return p.endsWith(Xt)?p.slice(0,-Xt.length):p},[]),pe=p=>t?t.includes(p):!0,cs=ps(),En=pe("theme")&&!cs,Tn=pe("windowControlsPosition")&&Yt,Va=pe("theme")||pe("timeFormat")||pe("weekStart"),ma=cs?Va:pe("theme")||Tn||pe("pwaInstallName")||pe("pwaOrientation")||pe("timeFormat")||pe("weekStart"),Ba=pe("fontSize")||pe("terminalFontSize")||pe("editorFontSize")||pe("spacing")||pe("inputBarOffset")&&u,ua=pe("terminalQuickKeys")&&!u||(pe("terminalShell")||pe("terminalLoginShell"))&&!cs||pe("fileEditorKeymap")||pe("autoSaveEnabled")||pe("sessionTabs")&&!cs&&!u,Yn=pe("mermaidRendering")||pe("sessionGoal")&&!cs||pe("userMessageRendering")||pe("chatRenderMode")||pe("messageTransport")||pe("activityRenderMode")&&Z==="sorted"||pe("collapsibleUserMessages")||pe("stickyUserHeader")||pe("promptNavigatorEnabled")&&!cs||pe("wideChatLayout")||pe("codeBlockLineWrap")||pe("splitAssistantMessageActions")||pe("subagentReadOnlyBanner")||pe("diffLayout")||pe("dotfiles")||pe("fileViewerPreview")||pe("reasoning")||pe("followUpBehavior")||pe("persistDraft")||pe("largeTextPaste")||pe("showToolFileIcons")||pe("expandedTools")||!u&&pe("inputSpellcheck"),cn=pe("chatRenderMode")||pe("activityRenderMode")&&Z==="sorted",Xn=pe("messageTransport"),Ha=pe("userMessageRendering")||pe("mermaidRendering")||pe("diffLayout")&&!cs||pe("followUpBehavior"),Zn=pe("sessionAssist")||pe("sessionGoal")&&!cs||pe("subagentReadOnlyBanner")||pe("collapsibleUserMessages")||pe("stickyUserHeader")||pe("promptNavigatorEnabled")&&!cs||pe("wideChatLayout")||pe("codeBlockLineWrap")||pe("splitAssistantMessageActions")||pe("dotfiles")||pe("fileViewerPreview")||pe("persistDraft")||pe("largeTextPaste")||pe("showToolFileIcons")||pe("showTurnChangedFiles")||!u&&pe("inputSpellcheck")||pe("reasoning")||pe("expandedTools"),ea=ma||Ba||ua,Hs=pe("pwaInstallName")&&Kn()&&x&&!ds()&&!cs,fn=pe("pwaOrientation")&&Kn()&&!ds()&&!cs,xn=pe("mobileKeyboardMode")&&Kn()&&!ds()&&!cs&&vd(),ta=(pe("terminalShell")||pe("terminalLoginShell"))&&!cs,[ga,ha]=o.useState([]),[Ni,Si]=o.useState(0);o.useEffect(()=>jl(()=>{ha([]),Si(p=>p+1)}),[]),o.useEffect(()=>{let p=!1;if(!(!ta||!g.listShells))return g.listShells().then(gt=>{p||ha(gt)}).catch(()=>{p||ha([])}),()=>{p=!0}},[ta,g,Ni]);const Ci=o.useMemo(()=>{const p=ga.filter(gt=>gt.id!=="auto");return me==="auto"||p.some(gt=>gt.id===me)?p:[{id:me,name:me,supportsLogin:!1},...p]},[ga,me]),Dn=ga.find(p=>p.id===me)?.supportsLogin===!0,sa=Ne.includes(me),fa=p=>{Se(p?[...Ne.filter(gt=>gt!==me),me]:Ne.filter(gt=>gt!==me))},[xa,f]=o.useState(""),[ee,Fe]=o.useState("system"),st=o.useMemo(()=>{const p=$o.find(gt=>gt.id===Ze);return l(p?.labelKey??"settings.openchamber.visual.option.timeFormat.auto.label")},[Ze,l]),Lt=o.useMemo(()=>{const p=Vo.find(gt=>gt.id===ct);return l(p?.labelKey??"settings.openchamber.visual.option.weekStart.auto.label")},[ct,l]),Es=o.useMemo(()=>{const p=Uo.find(gt=>gt.id===ee);return p?l(p.labelKey):void 0},[ee,l]),ks=o.useMemo(()=>{const p=zo.find(gt=>gt.id===oe);return p?l(p.labelKey):void 0},[oe,l]),Rs=o.useCallback(async p=>{if(typeof window>"u")return;const gt=window,Zt=p.trim().replace(/\s+/g," ").slice(0,64);if(await xt({pwaAppName:Zt}),typeof gt.__OPENCHAMBER_SET_PWA_INSTALL_NAME__=="function"){const wt=gt.__OPENCHAMBER_SET_PWA_INSTALL_NAME__(Zt);f(wt);return}f(Zt||Pa),gt.__OPENCHAMBER_UPDATE_PWA_MANIFEST__?.()},[]),gs=o.useCallback(async p=>{if(typeof window>"u")return;const gt=window,Xt=Vi(p);if(await xt({pwaOrientation:Xt}),typeof gt.__OPENCHAMBER_SET_PWA_ORIENTATION__=="function"){const Zt=gt.__OPENCHAMBER_SET_PWA_ORIENTATION__(Xt);Fe(Zt);return}Fe(Xt),gt.__OPENCHAMBER_UPDATE_PWA_MANIFEST__?.()},[]);return o.useEffect(()=>{if(typeof window>"u"||!Hs&&!fn&&!xn)return;let p=!1;return(async()=>{try{const Xt=await rt("/api/config/settings",{method:"GET",headers:{Accept:"application/json"},cache:"no-store"});if(!Xt.ok){p||f(Pa);return}const Zt=await Xt.json().catch(()=>({})),Gt=(typeof Zt?.pwaAppName=="string"?Zt.pwaAppName:"").trim().replace(/\s+/g," ").slice(0,64),Js=Vi(Zt?.pwaOrientation),Dt=Br(Zt?.mobileKeyboardMode);p||(Hs&&f(Gt||Pa),fn&&Fe(Js),xn&&ie(Dt))}catch{p||(Hs&&f(Pa),fn&&Fe("system"),xn&&ie("native"))}})(),()=>{p=!0}},[ie,xn,Hs,fn]),s.jsxs("div",{className:"space-y-0",children:[ma&&s.jsxs("div",{className:"space-y-0",children:[En&&s.jsxs($e,{title:r("settings.openchamber.visual.section.colorModeAndTheme"),divider:!1,children:[s.jsxs(kn,{children:[s.jsx("div",{className:Nn,children:s.jsx(dn,{"aria-label":r("settings.openchamber.visual.section.colorMode"),children:ph.map(p=>s.jsx(pn,{selected:ts===p.value,onSelect:()=>Ms(p.value),label:l(p.labelKey),ariaLabel:l(p.labelKey)},p.value))})}),s.jsxs("div",{className:Nn,children:[s.jsx(Wt,{label:r("settings.openchamber.visual.field.lightTheme"),settingsItem:"appearance.light-theme",children:s.jsxs(At,{value:ln?.metadata.id??"",onValueChange:vs,children:[s.jsx(Et,{"aria-label":r("settings.openchamber.visual.field.selectLightThemeAria"),size:$t,className:bn,children:s.jsx(Ft,{placeholder:r("settings.openchamber.visual.field.selectThemePlaceholder"),children:ln?Qn(ln.metadata.name,"light"):void 0})}),s.jsx(Tt,{children:rn.map(p=>s.jsx(ot,{value:p.metadata.id,children:Qn(p.metadata.name,"light")},p.metadata.id))})]})}),s.jsx(Wt,{label:r("settings.openchamber.visual.field.darkTheme"),settingsItem:"appearance.dark-theme",children:s.jsxs(At,{value:An?.metadata.id??"",onValueChange:us,children:[s.jsx(Et,{"aria-label":r("settings.openchamber.visual.field.selectDarkThemeAria"),size:$t,className:bn,children:s.jsx(Ft,{placeholder:r("settings.openchamber.visual.field.selectThemePlaceholder"),children:An?Qn(An.metadata.name,"dark"):void 0})}),s.jsx(Tt,{children:on.map(p=>s.jsx(ot,{value:p.metadata.id,children:Qn(p.metadata.name,"dark")},p.metadata.id))})]})}),s.jsxs("div",{className:"flex items-center gap-2 pt-1",children:[s.jsxs("button",{type:"button",disabled:os||ys,onClick:()=>{const p=Date.now();le(!0),qt().finally(()=>{const gt=Date.now()-p;if(gt<500){window.setTimeout(()=>{le(!1)},500-gt);return}le(!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:we("h-3.5 w-3.5",ys&&"animate-spin")}),r(ys?"settings.openchamber.visual.actions.reloadingThemes":"settings.openchamber.visual.actions.reloadThemes")]}),s.jsx(Jt,{children:r("settings.openchamber.visual.field.themeImportInfoTooltip")})]})]})]}),dt&&s.jsx(Fa,{settingsItem:"appearance.dock-badge",children:s.jsx(pt,{checked:bt,onChange:Qt,label:r("settings.openchamber.visual.field.dockBadge"),info:r("settings.openchamber.visual.field.dockBadgeHint"),ariaLabel:r("settings.openchamber.visual.field.dockBadge")})})]}),Tn&&s.jsx($e,{title:r("settings.openchamber.desktopNetwork.field.windowControls"),info:r("settings.openchamber.desktopNetwork.field.windowControlsPositionDescription"),divider:En,children:s.jsxs(kn,{children:[s.jsx(Wt,{label:r("settings.openchamber.desktopNetwork.field.windowControlsPosition"),settingsItem:"sessions.desktop-window-controls-position",children:s.jsx(Gs,{value:Ht,options:yh.map(p=>({value:p.id,label:l(p.labelKey)})),onChange:As,"aria-label":r("settings.openchamber.desktopNetwork.field.windowControlsPositionAria")})}),s.jsx(Wt,{label:r("settings.openchamber.desktopNetwork.field.windowControlsStyle"),settingsItem:"sessions.desktop-window-controls-style",children:s.jsx(Gs,{value:js,options:jh.map(p=>({value:p.id,label:l(p.labelKey)})),onChange:gi,"aria-label":r("settings.openchamber.desktopNetwork.field.windowControlsStyleAria")})})]})}),Va&&s.jsx($e,{title:r("settings.openchamber.visual.section.localization"),children:s.jsxs(kn,{children:[s.jsx(Wt,{label:r("settings.appearance.language.label"),info:r("settings.appearance.language.description"),settingsItem:"appearance.language",children:s.jsxs(At,{value:e,onValueChange:p=>n(p),children:[s.jsx(Et,{"aria-label":r("settings.appearance.language.select"),size:$t,className:bn,children:s.jsx(Ft,{children:i(e)})}),s.jsx(Tt,{children:a.map(p=>s.jsx(ot,{value:p,children:i(p)},p))})]})}),(pe("timeFormat")||pe("weekStart"))&&s.jsxs("div",{className:Nn,children:[pe("timeFormat")&&s.jsx(Wt,{label:r("settings.openchamber.visual.field.timeFormat"),settingsItem:"appearance.time-format",children:s.jsxs(At,{value:Ze,onValueChange:p=>Ws(p),children:[s.jsx(Et,{"aria-label":r("settings.openchamber.visual.field.selectTimeFormatAria"),size:$t,className:bn,children:s.jsx(Ft,{children:st})}),s.jsx(Tt,{children:$o.map(p=>s.jsx(ot,{value:p.id,children:l(p.labelKey)},p.id))})]})}),pe("weekStart")&&s.jsx(Wt,{label:r("settings.openchamber.visual.field.weekStartsOn"),settingsItem:"appearance.week-start",children:s.jsxs(At,{value:ct,onValueChange:p=>ki(p),children:[s.jsx(Et,{"aria-label":r("settings.openchamber.visual.field.selectWeekStartAria"),size:$t,className:bn,children:s.jsx(Ft,{children:Lt})}),s.jsx(Tt,{children:Vo.map(p=>s.jsx(ot,{value:p.id,children:l(p.labelKey)},p.id))})]})})]})]})}),(Hs||fn||xn)&&s.jsxs($e,{title:r("settings.openchamber.visual.section.appInstall"),contentClassName:Nn,children:[Hs&&s.jsxs(Vt,{label:r("settings.openchamber.visual.field.installAppName"),info:r("settings.openchamber.visual.field.installAppNameHint"),settingsItem:"appearance.pwa-install-name",alignEnd:!1,controlClassName:Us,children:[s.jsx(We,{value:xa,onChange:p=>{f(p.target.value)},onBlur:()=>{Rs(xa)},onKeyDown:p=>{p.key==="Enter"&&(p.preventDefault(),Rs(xa))},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:()=>{f(Pa),Rs("")},className:hs,"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"})})]}),fn&&s.jsxs(Vt,{label:r("settings.openchamber.visual.field.installOrientation"),description:r("settings.openchamber.visual.field.installOrientationHint"),settingsItem:"appearance.pwa-orientation",alignEnd:!1,controlClassName:Us,children:[s.jsxs(At,{value:ee,onValueChange:p=>{const gt=Vi(p);Fe(gt),gs(gt)},children:[s.jsx(Et,{"aria-label":r("settings.openchamber.visual.field.pwaInstallOrientationAria"),size:$t,className:Er,children:s.jsx(Ft,{placeholder:r("settings.openchamber.visual.field.selectOrientationPlaceholder"),children:Es})}),s.jsx(Tt,{children:Uo.map(p=>s.jsx(ot,{value:p.id,children:l(p.labelKey)},p.id))})]}),s.jsx(B,{size:"sm",type:"button",variant:"ghost",onClick:()=>{Fe("system"),gs("system")},disabled:ee==="system",className:hs,"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"})})]}),xn&&s.jsxs(Vt,{label:r("settings.openchamber.visual.field.mobileKeyboardMode"),info:r("settings.openchamber.visual.field.mobileKeyboardModeHint"),settingsItem:"appearance.mobile-keyboard-mode",alignEnd:!1,controlClassName:Us,children:[s.jsxs(At,{value:oe,onValueChange:p=>{const gt=Br(p);ie(gt),xt({mobileKeyboardMode:gt})},children:[s.jsx(Et,{"aria-label":r("settings.openchamber.visual.field.mobileKeyboardModeAria"),size:$t,className:Er,children:s.jsx(Ft,{placeholder:r("settings.openchamber.visual.field.selectMobileKeyboardModePlaceholder"),children:ks})}),s.jsx(Tt,{children:zo.map(p=>s.jsx(ot,{value:p.id,children:l(p.labelKey)},p.id))})]}),s.jsx(B,{size:"sm",type:"button",variant:"ghost",onClick:()=>{ie("native"),xt({mobileKeyboardMode:"native"})},disabled:oe==="native",className:hs,"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"})})]})]})]}),Ba&&s.jsxs($e,{title:r("settings.openchamber.visual.section.densityAndType"),contentClassName:Nn,children:[pe("fontSize")&&!u||pe("terminalFontSize")?s.jsxs(kn,{children:[pe("fontSize")&&!u&&s.jsxs(Wt,{label:r("settings.openchamber.visual.field.interfaceFont"),settingsItem:"appearance.interface-font-size",controlClassName:"w-full",children:[s.jsxs(At,{value:Re,onValueChange:p=>re(p),children:[s.jsx(Et,{"aria-label":r("settings.openchamber.visual.field.selectInterfaceFontAria"),size:$t,className:bn,children:s.jsx(Ft,{children:zr.find(p=>p.id===Re)?.label})}),s.jsx(Tt,{children:zr.map(p=>s.jsx(ot,{value:p.id,children:s.jsx("span",{style:{fontFamily:p.stack},children:p.label})},p.id))})]}),s.jsx(B,{size:"sm",type:"button",variant:"ghost",onClick:()=>re(_r),disabled:Re===_r,className:hs,"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"})})]}),pe("terminalFontSize")&&s.jsxs(Wt,{label:r("settings.openchamber.visual.field.codeFont"),controlClassName:"w-full",children:[s.jsxs(At,{value:fe,onValueChange:p=>Ee(p),children:[s.jsx(Et,{"aria-label":r("settings.openchamber.visual.field.selectCodeFontAria"),size:$t,className:bn,children:s.jsx(Ft,{children:$r.find(p=>p.id===fe)?.label})}),s.jsx(Tt,{children:$r.map(p=>s.jsx(ot,{value:p.id,children:s.jsx("span",{style:{fontFamily:p.stack},children:p.label})},p.id))})]}),s.jsx(B,{size:"sm",type:"button",variant:"ghost",onClick:()=>Ee(Vr),disabled:fe===Vr,className:hs,"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,pe("fontSize")&&!u||pe("terminalFontSize")||pe("editorFontSize")?s.jsxs(kn,{children:[pe("fontSize")&&!u&&s.jsx(Wt,{label:r("settings.openchamber.visual.field.interfaceFontSize"),controlClassName:"w-full",children:s.jsxs("div",{className:ya,children:[s.jsx(Ss,{value:ce,onValueChange:be,min:50,max:200,step:5,className:Ps,"aria-label":r("settings.openchamber.visual.field.fontSizePercentageAria")}),s.jsx("span",{className:ja,children:"%"}),s.jsx(B,{size:"sm",type:"button",variant:"ghost",onClick:()=>be(100),disabled:ce===100,className:hs,"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"})})]})}),pe("terminalFontSize")&&s.jsx(Wt,{label:r("settings.openchamber.visual.field.terminalFontSize"),settingsItem:"appearance.terminal-font-size",controlClassName:"w-full",children:s.jsxs("div",{className:ya,children:[s.jsx(Ss,{value:ne,onValueChange:ae,min:9,max:52,step:1,className:Ps}),s.jsx("span",{className:ja,children:"px"}),s.jsx(B,{size:"sm",type:"button",variant:"ghost",onClick:()=>ae(13),disabled:ne===13,className:hs,"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"})})]})}),pe("editorFontSize")&&s.jsx(Wt,{label:r("settings.openchamber.visual.field.editorFontSize"),settingsItem:"appearance.editor-font-size",controlClassName:"w-full",children:s.jsxs("div",{className:ya,children:[s.jsx(Ss,{value:je,onValueChange:Me,min:9,max:32,step:1,className:Ps}),s.jsx("span",{className:ja,children:"px"}),s.jsx(B,{size:"sm",type:"button",variant:"ghost",onClick:()=>Me(13),disabled:je===13,className:hs,"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,pe("spacing")||pe("inputBarOffset")&&u?s.jsxs(kn,{children:[pe("spacing")&&s.jsx(Wt,{label:r("settings.openchamber.visual.field.spacingDensity"),settingsItem:"appearance.spacing-density",controlClassName:"w-full",children:s.jsxs("div",{className:ya,children:[s.jsx(Ss,{value:Be,onValueChange:Ve,min:50,max:200,step:5,className:Ps}),s.jsx("span",{className:ja,children:"%"}),s.jsx(B,{size:"sm",type:"button",variant:"ghost",onClick:()=>Ve(100),disabled:Be===100,className:hs,"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"})})]})}),pe("inputBarOffset")&&u&&s.jsx(Wt,{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:ya,children:[s.jsx(Ss,{value:Ge,onValueChange:Ke,min:0,max:100,step:5,className:Ps}),s.jsx("span",{className:ja,children:"px"}),s.jsx(B,{size:"sm",type:"button",variant:"ghost",onClick:()=>Ke(0),disabled:Ge===0,className:hs,"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]}),ua&&s.jsxs($e,{title:r("settings.openchamber.visual.section.navigation"),contentClassName:"space-y-4",children:[pe("fileEditorKeymap")&&s.jsx(Ks,{title:r("settings.openchamber.visual.field.fileEditorKeymap"),settingsItem:"appearance.file-editor-keymap",children:s.jsx(dn,{"aria-label":r("settings.openchamber.visual.field.fileEditorKeymap"),children:["default","vim"].map(p=>s.jsx(pn,{selected:ue===p,onSelect:()=>Ie(p),label:r(`settings.openchamber.visual.option.fileEditorKeymap.${p}`),ariaLabel:r(`settings.openchamber.visual.option.fileEditorKeymap.${p}`)},p))})}),s.jsxs("div",{className:fs,children:[pe("autoSaveEnabled")&&s.jsx(pt,{checked:K,onChange:te,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(Wt,{label:r("settings.openchamber.visual.field.terminalShell"),info:r("settings.openchamber.visual.field.terminalShellHint"),settingsItem:"appearance.terminal-shell",className:"pt-2",children:s.jsxs(At,{value:me,onValueChange:p=>{yd(p)&&Pe(p)},children:[s.jsx(Et,{"aria-label":r("settings.openchamber.visual.field.terminalShellAria"),size:$t,className:bn,children:s.jsx(Ft,{})}),s.jsxs(Tt,{children:[s.jsx(ot,{value:"auto",children:r("settings.openchamber.visual.option.terminalShell.auto")}),Ci.map(p=>s.jsx(ot,{value:p.id,children:p.name},p.id))]})]})}),ta&&Dn&&s.jsx(pt,{checked:sa,onChange:fa,label:r("settings.openchamber.visual.field.terminalLoginShell"),ariaLabel:r("settings.openchamber.visual.field.terminalLoginShell"),settingsItem:"appearance.terminal-login-shell"}),pe("terminalQuickKeys")&&!u&&s.jsx(pt,{checked:Oe,onChange:He,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:zn("ctrl"),alt:zn("alt")})})]}),pe("sessionTabs")&&!cs&&!u&&s.jsx(Ks,{title:r("settings.openchamber.visual.field.sessionTabsGroup"),settingsItem:"appearance.session-tabs",children:s.jsx(pt,{checked:Te,onChange:xe,label:r("settings.openchamber.visual.field.sessionTabs"),ariaLabel:r("settings.openchamber.visual.field.sessionTabsAria"),info:r("settings.openchamber.visual.field.sessionTabsInfo")})})]}),Yn&&s.jsxs(s.Fragment,{children:[cn&&s.jsxs($e,{title:r("settings.openchamber.visual.section.chatDisplay"),divider:ea,contentClassName:"space-y-6",children:[pe("chatRenderMode")&&s.jsx(Ks,{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:hh.map(p=>{const gt=Z===p.id,Xt=St%12;return s.jsxs("button",{type:"button",onClick:()=>yi(p.id),"aria-pressed":gt,className:we("flex flex-col items-start gap-1 rounded-lg border p-3 text-left transition-colors",gt?"border-primary bg-primary/5":"border-border hover:border-border/80 hover:bg-muted/50"),children:[s.jsx("span",{className:we("typography-ui-label",gt?"text-foreground":"text-muted-foreground"),children:l(p.labelKey)}),s.jsx("div",{className:"mt-2 w-full rounded-md border border-border/60 bg-muted/30 p-2",children:p.id==="live"?s.jsx("div",{className:"space-y-1.5",children:[0,1,2].map(Zt=>{const wt=Zt*3+1,Gt=Xt-wt+1,Js=Gt<=0?0:Gt===1?42:Gt===2?68:92,Dt=Js>0;return s.jsxs("div",{className:we("flex items-center gap-1.5 transition-all duration-300 motion-reduce:transition-none",Dt?"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:`${Js}%`}})]},Zt)})}):s.jsx("div",{className:"space-y-1.5",children:[0,1,2].map(Zt=>{const wt=Xt>=(Zt+1)*3;return s.jsxs("div",{className:we("flex items-center gap-1.5 transition-all duration-300 motion-reduce:transition-none",wt?"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%"}})]},Zt)})})})]},p.id)})})}),pe("activityRenderMode")&&Z==="sorted"&&s.jsx(Ks,{title:r("settings.openchamber.visual.section.activityDefault"),children:s.jsx(dn,{"aria-label":r("settings.openchamber.visual.section.activityDefaultAria"),children:fh.map(p=>s.jsx(pn,{selected:se===p.id,onSelect:()=>wi(p.id),label:l(p.labelKey),ariaLabel:r("settings.openchamber.visual.field.activityDefaultModeAria",{option:l(p.labelKey)})},p.id))})})]}),Xn&&s.jsxs($e,{title:r("settings.openchamber.visual.section.messageStreamTransport"),divider:cn||ea,settingsItem:"chat.message-transport",contentClassName:"space-y-2",children:[s.jsx(Gs,{value:at,options:_o.map(p=>({value:p.id,label:l(p.labelKey)})),onChange:ji,"aria-label":r("settings.openchamber.visual.section.messageStreamTransport")}),(()=>{const p=_o.find(gt=>gt.id===at);return p?.descriptionKey?s.jsx("span",{className:"typography-meta text-muted-foreground",children:l(p.descriptionKey)}):null})()]}),Ha&&s.jsx($e,{title:r("settings.openchamber.visual.section.chatMessageOptions"),divider:cn||Xn||ea,children:s.jsxs(kn,{className:"lg:gap-y-6",children:[pe("userMessageRendering")&&s.jsx(Ks,{title:r("settings.openchamber.visual.section.userMessageRendering"),children:s.jsx(dn,{"aria-label":r("settings.openchamber.visual.section.userMessageRenderingAria"),children:gh.map(p=>s.jsx(pn,{selected:vh(R)===p.id,onSelect:()=>hi(p.id),label:l(p.labelKey),ariaLabel:r("settings.openchamber.visual.field.userMessageRenderingAria",{option:l(p.labelKey)})},p.id))})}),pe("mermaidRendering")&&s.jsx(Ks,{title:r("settings.openchamber.visual.section.mermaidRendering"),children:s.jsx(dn,{"aria-label":r("settings.openchamber.visual.section.mermaidRenderingAria"),children:uh.map(p=>s.jsx(pn,{selected:M===p.id,onSelect:()=>ws(p.id),label:l(p.labelKey),ariaLabel:r("settings.openchamber.visual.field.mermaidRenderingAria",{option:l(p.labelKey)})},p.id))})}),pe("diffLayout")&&!cs&&s.jsx(Ks,{title:r("settings.openchamber.visual.section.diffLayout"),children:s.jsx(dn,{"aria-label":r("settings.openchamber.visual.section.diffLayoutAria"),children:mh.map(p=>s.jsx(pn,{selected:ye===p.id,onSelect:()=>ve(p.id),label:l(p.labelKey),ariaLabel:r("settings.openchamber.visual.field.diffLayoutAria",{option:l(p.labelKey)})},p.id))})}),pe("followUpBehavior")&&s.jsx(Ks,{title:r("settings.openchamber.visual.section.followUpBehavior"),settingsItem:"chat.follow-up-behavior",children:s.jsx(dn,{"aria-label":r("settings.openchamber.visual.section.followUpBehaviorAria"),children:xh.map(p=>s.jsx(pn,{selected:Le===p.id,onSelect:()=>Ye(p.id),label:l(p.labelKey),ariaLabel:r("settings.openchamber.visual.field.followUpBehaviorAria",{option:l(p.labelKey)})},p.id))})})]})}),Zn&&s.jsxs(s.Fragment,{children:[pe("expandedTools")&&s.jsxs($e,{title:r("settings.openchamber.visual.section.showToolsOpenedByDefault"),divider:cn||Xn||Ha||ea,contentClassName:fs,children:[s.jsx(pt,{checked:ft,onChange:hn,label:r("settings.openchamber.visual.field.bash"),ariaLabel:r("settings.openchamber.visual.field.showExpandedBashToolsAria")}),s.jsx(pt,{checked:vt,onChange:Nr,label:r("settings.openchamber.visual.field.editTools"),ariaLabel:r("settings.openchamber.visual.field.showExpandedEditToolsAria")})]}),s.jsxs($e,{title:r("settings.openchamber.visual.section.sessionAssistance"),settingsItem:"chat.session-assistance",contentClassName:fs,children:[s.jsx(pt,{checked:he,onChange:pa,label:r("settings.openchamber.visual.field.draftStartersVisible"),ariaLabel:r("settings.openchamber.visual.field.draftStartersVisibleAria"),settingsItem:"chat.draft-starters-visible"}),pe("sessionAssist")&&s.jsxs(s.Fragment,{children:[s.jsx(pt,{checked:c,onChange:b,label:r("settings.openchamber.visual.field.sessionRecap"),ariaLabel:r("settings.openchamber.visual.field.sessionRecapAria"),settingsItem:"chat.session-recap"}),s.jsx(pt,{checked:N,onChange:C,label:r("settings.openchamber.visual.field.sessionSuggestion"),ariaLabel:r("settings.openchamber.visual.field.sessionSuggestionAria"),settingsItem:"chat.session-suggestion"})]}),pe("subagentReadOnlyBanner")&&s.jsx(pt,{checked:yt,onChange:Q,label:r("settings.openchamber.visual.field.allowPromptingSubagentSessions"),ariaLabel:r("settings.openchamber.visual.field.allowPromptingSubagentSessionsAria"),settingsItem:"chat.subagent-read-only-banner"})]}),pe("sessionGoal")&&!cs&&s.jsxs($e,{title:r("settings.openchamber.visual.goal.sectionTitle"),info:r("settings.openchamber.visual.goal.description"),contentClassName:fs,children:[s.jsx(pt,{checked:k,onChange:A,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(pt,{checked:h,onChange:E,disabled:!k,label:r("settings.openchamber.visual.goal.budgetLabel"),ariaLabel:r("settings.openchamber.visual.goal.budgetAria")}),k&&h?s.jsx(Ss,{value:F,onValueChange:p=>{typeof p=="number"&&Number.isFinite(p)&&p>0&&I(Math.floor(p))},min:1e3,max:1e8,step:5e4}):null]})]}),pe("reasoning")&&s.jsxs($e,{title:r("settings.openchamber.visual.section.reasoning"),settingsItem:"chat.reasoning",contentClassName:fs,children:[s.jsx(pt,{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(pt,{checked:U,onChange:S,label:r("settings.openchamber.visual.field.collapsibleThinkingBlocks"),ariaLabel:r("settings.openchamber.visual.field.collapsibleThinkingBlocksAria")})]}),s.jsx($e,{title:r("settings.openchamber.visual.section.streaming"),settingsItem:"chat.streaming",contentClassName:fs,children:s.jsx(pt,{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"})}),(pe("collapsibleUserMessages")||pe("stickyUserHeader")||pe("promptNavigatorEnabled")&&!cs||pe("wideChatLayout")||pe("splitAssistantMessageActions")||pe("codeBlockLineWrap"))&&s.jsxs($e,{title:r("settings.openchamber.visual.section.messageAppearance"),settingsItem:"chat.message-appearance",contentClassName:fs,children:[pe("collapsibleUserMessages")&&s.jsx(pt,{checked:P,onChange:xi,label:r("settings.openchamber.visual.field.collapsibleUserMessages"),ariaLabel:r("settings.openchamber.visual.field.collapsibleUserMessagesAria"),settingsItem:"chat.collapsible-user-messages"}),pe("stickyUserHeader")&&s.jsx(pt,{checked:J,onChange:fi,label:r("settings.openchamber.visual.field.stickyUserHeader"),ariaLabel:r("settings.openchamber.visual.field.stickyUserHeaderAria"),settingsItem:"chat.sticky-user-header"}),pe("promptNavigatorEnabled")&&!cs&&s.jsx(pt,{checked:T,onChange:Ls,label:r("settings.openchamber.visual.field.promptNavigatorEnabled"),ariaLabel:r("settings.openchamber.visual.field.promptNavigatorEnabledAria"),settingsItem:"chat.prompt-navigator"}),pe("wideChatLayout")&&s.jsx(pt,{checked:$,onChange:$a,label:r("settings.openchamber.visual.field.wideChatLayout"),ariaLabel:r("settings.openchamber.visual.field.wideChatLayoutAria"),settingsItem:"chat.wide-layout"}),pe("splitAssistantMessageActions")&&s.jsx(pt,{checked:jt,onChange:bi,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")}),pe("codeBlockLineWrap")&&s.jsx(pt,{checked:_,onChange:z,label:r("settings.openchamber.visual.field.codeBlockLineWrap"),ariaLabel:r("settings.openchamber.visual.field.codeBlockLineWrapAria"),settingsItem:"chat.code-block-line-wrap"})]}),(pe("showToolFileIcons")||pe("showTurnChangedFiles")||pe("dotfiles")&&!ps()||pe("fileViewerPreview"))&&s.jsxs($e,{title:r("settings.openchamber.visual.section.toolsAndFiles"),settingsItem:"chat.tools-and-files",contentClassName:fs,children:[pe("showToolFileIcons")&&s.jsx(pt,{checked:tt,onChange:Bs,label:r("settings.openchamber.visual.field.showToolFileIcons"),ariaLabel:r("settings.openchamber.visual.field.showToolFileIconsAria"),settingsItem:"chat.tool-file-icons"}),pe("showTurnChangedFiles")&&s.jsx(pt,{checked:mt,onChange:Jn,label:r("settings.openchamber.visual.field.showTurnChangedFiles"),ariaLabel:r("settings.openchamber.visual.field.showTurnChangedFilesAria"),settingsItem:"chat.changed-files"}),pe("dotfiles")&&!ps()&&s.jsx(pt,{checked:d,onChange:jd,label:r("settings.openchamber.visual.field.showDotfiles"),ariaLabel:r("settings.openchamber.visual.field.showDotfilesAria"),settingsItem:"chat.dotfiles"}),pe("fileViewerPreview")&&s.jsx(pt,{checked:Je,onChange:an,label:r("settings.openchamber.defaults.field.openFilesPreview"),ariaLabel:r("settings.openchamber.defaults.field.openFilesPreviewAria")})]}),(pe("persistDraft")||pe("largeTextPaste")||!u&&pe("inputSpellcheck"))&&s.jsxs($e,{title:r("settings.openchamber.visual.section.composer"),settingsItem:"chat.composer",contentClassName:fs,children:[pe("persistDraft")&&s.jsx(pt,{checked:q,onChange:ke,label:r("settings.openchamber.visual.field.persistDraftMessages"),ariaLabel:r("settings.openchamber.visual.field.persistDraftMessagesAria"),settingsItem:"chat.persist-drafts"}),!u&&pe("inputSpellcheck")&&s.jsx(pt,{checked:O,onChange:vi,label:r("settings.openchamber.visual.field.enableSpellcheckInTextInputs"),ariaLabel:r("settings.openchamber.visual.field.enableSpellcheckInTextInputsAria"),settingsItem:"chat.spellcheck"}),pe("largeTextPaste")&&s.jsx(Ks,{title:r("settings.openchamber.visual.field.largeTextPaste"),info:r("settings.openchamber.visual.field.largeTextPasteHint"),settingsItem:"chat.large-text-paste",children:s.jsx(dn,{"aria-label":r("settings.openchamber.visual.field.largeTextPasteAria"),children:bh.map(p=>s.jsx(pn,{selected:qe===p.id,onSelect:()=>_e(p.id),label:l(p.labelKey),ariaLabel:r("settings.openchamber.visual.field.largeTextPasteOptionAria",{option:l(p.labelKey)})},p.id))})})]})]})]}),pe("reportUsage")&&s.jsx($e,{title:r("settings.openchamber.visual.section.privacy"),children:s.jsx(pt,{checked:_t,onChange:is,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"})})]})},wh=1,kh=365,Bo=30,Nh=[{value:"archive",labelKey:"settings.openchamber.sessionRetention.action.archive"},{value:"delete",labelKey:"settings.openchamber.sessionRetention.action.delete"}],Bl=()=>{const t=lt.c(88),{t:e}=nt(),a=de(Sh),n=de(Ch),i=de(Ph),r=de(Ih),l=de(Ah),u=de(Eh);let g;t[0]===Symbol.for("react.memo_cache_sentinel")?(g={autoRun:!1},t[0]=g):g=t[0];const{candidates:x,isRunning:d,runCleanup:v,action:c}=Fc(g),N=x.length;let b;t[1]!==v||t[2]!==e?(b=async()=>{const ce=await v({force:!0});if(ce.completedIds.length===0&&ce.failedIds.length===0){D.message(ce.action==="archive"?e("settings.openchamber.sessionRetention.toast.noneEligibleArchive"):e("settings.openchamber.sessionRetention.toast.noneEligibleDelete"));return}ce.completedIds.length>0&&D.success(ce.action==="archive"?e("settings.openchamber.sessionRetention.toast.archivedCount",{count:ce.completedIds.length}):e("settings.openchamber.sessionRetention.toast.deletedCount",{count:ce.completedIds.length})),ce.failedIds.length>0&&D.error(ce.action==="archive"?e("settings.openchamber.sessionRetention.toast.failedArchiveCount",{count:ce.failedIds.length}):e("settings.openchamber.sessionRetention.toast.failedDeleteCount",{count:ce.failedIds.length}))},t[1]=v,t[2]=e,t[3]=b):b=t[3];const C=b;let k;t[4]!==e?(k=e("settings.openchamber.sessionRetention.title"),t[4]=e,t[5]=k):k=t[5];let A;t[6]!==e?(A=e("settings.openchamber.sessionRetention.tooltip"),t[6]=e,t[7]=A):A=t[7];let h;t[8]!==e?(h=e("settings.openchamber.sessionRetention.field.enableAutoCleanup"),t[8]=e,t[9]=h):h=t[9];let E;t[10]!==e?(E=e("settings.openchamber.sessionRetention.field.enableAutoCleanupAria"),t[10]=e,t[11]=E):E=t[11];let F;t[12]!==a||t[13]!==r||t[14]!==h||t[15]!==E?(F=s.jsx(pt,{settingsItem:"sessions.auto-cleanup",checked:a,onChange:r,label:h,ariaLabel:E}),t[12]=a,t[13]=r,t[14]=h,t[15]=E,t[16]=F):F=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]===Symbol.for("react.memo_cache_sentinel")?(m=we(Ps,"tabular-nums"),t[21]=m):m=t[21];let y;t[22]!==n||t[23]!==l||t[24]!==w?(y=s.jsx(Ss,{value:n,onValueChange:l,min:wh,max:kh,step:1,"aria-label":w,className:m}),t[22]=n,t[23]=l,t[24]=w,t[25]=y):y=t[25];let U;t[26]!==e?(U=e("settings.openchamber.sessionRetention.field.days"),t[26]=e,t[27]=U):U=t[27];let S;t[28]!==U?(S=s.jsx("span",{className:"typography-ui-label text-muted-foreground",children:U}),t[28]=U,t[29]=S):S=t[29];let M;t[30]!==l?(M=()=>l(Bo),t[30]=l,t[31]=M):M=t[31];const j=n===Bo;let R;t[32]!==e?(R=e("settings.openchamber.sessionRetention.actions.resetRetentionAria"),t[32]=e,t[33]=R):R=t[33];let H;t[34]!==e?(H=e("settings.common.actions.reset"),t[34]=e,t[35]=H):H=t[35];let P;t[36]===Symbol.for("react.memo_cache_sentinel")?(P=s.jsx(L,{name:"restart",className:"h-3.5 w-3.5"}),t[36]=P):P=t[36];let G;t[37]!==M||t[38]!==j||t[39]!==R||t[40]!==H?(G=s.jsx(B,{size:"sm",type:"button",variant:"ghost",onClick:M,disabled:j,className:hs,"aria-label":R,title:H,children:P}),t[37]=M,t[38]=j,t[39]=R,t[40]=H,t[41]=G):G=t[41];let J;t[42]!==y||t[43]!==S||t[44]!==G||t[45]!==I?(J=s.jsxs(Vt,{settingsItem:"sessions.retention-period",label:I,children:[y,S,G]}),t[42]=y,t[43]=S,t[44]=G,t[45]=I,t[46]=J):J=t[46];let T;t[47]!==e?(T=e("settings.openchamber.sessionRetention.field.whenSessionsExpire"),t[47]=e,t[48]=T):T=t[48];let W;t[49]!==e?(W=Nh.map(ce=>({value:ce.value,label:e(ce.labelKey)})),t[49]=e,t[50]=W):W=t[50];let X;t[51]!==i||t[52]!==u||t[53]!==W?(X=s.jsx(Gs,{value:i,onChange:u,options:W}),t[51]=i,t[52]=u,t[53]=W,t[54]=X):X=t[54];let K;t[55]!==T||t[56]!==X?(K=s.jsx(Vt,{settingsItem:"sessions.retention-action",label:T,children:X}),t[55]=T,t[56]=X,t[57]=K):K=t[57];let te;t[58]!==J||t[59]!==K?(te=s.jsxs(Fa,{className:"space-y-0",children:[J,K]}),t[58]=J,t[59]=K,t[60]=te):te=t[60];let $;t[61]!==e?($=e("settings.openchamber.sessionRetention.manualCleanup.title"),t[61]=e,t[62]=$):$=t[62];let V;t[63]!==d||t[64]!==e?(V=e(d?"settings.openchamber.sessionRetention.actions.cleaningUp":"settings.openchamber.sessionRetention.actions.runCleanupNow"),t[63]=d,t[64]=e,t[65]=V):V=t[65];let _;t[66]!==C||t[67]!==d||t[68]!==V?(_=s.jsx(B,{type:"button",variant:"outline",size:"xs",onClick:C,disabled:d,className:"!font-normal",children:V}),t[66]=C,t[67]=d,t[68]=V,t[69]=_):_=t[69];let z;t[70]!==$||t[71]!==_?(z=s.jsx(Vt,{label:$,children:_}),t[70]=$,t[71]=_,t[72]=z):z=t[72];let Z;t[73]!==c||t[74]!==N||t[75]!==e?(Z=c==="archive"?e("settings.openchamber.sessionRetention.manualCleanup.eligibleArchiveNow",{count:N}):e("settings.openchamber.sessionRetention.manualCleanup.eligibleDeleteNow",{count:N}),t[73]=c,t[74]=N,t[75]=e,t[76]=Z):Z=t[76];let Y;t[77]!==Z?(Y=s.jsx("p",{className:"typography-meta text-muted-foreground",children:Z}),t[77]=Z,t[78]=Y):Y=t[78];let se;t[79]!==z||t[80]!==Y?(se=s.jsxs("div",{className:"mt-1 py-1.5 space-y-1",children:[z,Y]}),t[79]=z,t[80]=Y,t[81]=se):se=t[81];let ge;return t[82]!==k||t[83]!==te||t[84]!==A||t[85]!==se||t[86]!==F?(ge=s.jsxs($e,{title:k,info:A,children:[F,te,se]}),t[82]=k,t[83]=te,t[84]=A,t[85]=se,t[86]=F,t[87]=ge):ge=t[87],ge};function Sh(t){return t.autoDeleteEnabled}function Ch(t){return t.autoDeleteAfterDays}function Ph(t){return t.sessionRetentionAction}function Ih(t){return t.setAutoDeleteEnabled}function Ah(t){return t.setAutoDeleteAfterDays}function Eh(t){return t.setSessionRetentionAction}const Ho=(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),Hl=()=>{const{t}=nt(),e=de(m=>m.timeFormatPreference),[a,n]=o.useState(!1),[i,r]=o.useState(!0),[l,u]=o.useState(!1),[g,x]=o.useState(null),[d,v]=o.useState(!1),[c,N]=o.useState([]),[b,C]=o.useState(Kc),[k,A]=o.useState(""),h=o.useMemo(()=>Uc(),[]),E=o.useCallback(async()=>{r(!0),A("");try{const m=await zc();N(m)}catch(m){const y=m instanceof Error?m.message:t("settings.openchamber.passkeys.toast.loadFailed");A(y)}finally{r(!1)}},[t]);o.useEffect(()=>{let m=!1;return(async()=>{try{if(!h.supported){m||(n(!1),r(!1));return}m||n(!0)}catch{m||n(!1)}if(!m){const y=await Ai();if(C(y),!y.enabled){N([]),r(!1);return}await E()}})(),()=>{m=!0,Tr()}},[E,h.supported]);const F=o.useCallback(async()=>{if(!b.enabled){const m=t("settings.openchamber.passkeys.toast.enableUiPasswordFirst");A(m),D.message(m);return}if(!a){A(h.reason),D.message(h.reason);return}if(l){Tr(),u(!1);return}A(""),u(!0);try{await _c(),C(await Ai()),await E(),D.success(t("settings.openchamber.passkeys.toast.added"))}catch(m){if($c(m)){D.message(t("settings.openchamber.passkeys.toast.setupCanceled"));return}const y=m instanceof Error?m.message:t("settings.openchamber.passkeys.toast.addFailed");A(y),D.error(y)}finally{u(!1)}},[l,E,b.enabled,h.reason,a,t]),I=o.useCallback(async m=>{x(m),A("");try{await Vc(m),C(await Ai()),await E(),D.success(t("settings.openchamber.passkeys.toast.removed"))}catch(y){const U=y instanceof Error?y.message:t("settings.openchamber.passkeys.toast.removeFailed");A(U),D.error(U)}finally{x(null)}},[E,t]),w=o.useCallback(async()=>{v(!0),A("");try{await Bc(),window.location.reload()}catch(m){const y=m instanceof Error?m.message:t("settings.openchamber.passkeys.toast.clearAuthFailed");A(y),D.error(y),v(!1)}},[t]);return s.jsxs($e,{title:t("settings.openchamber.passkeys.title"),children:[s.jsxs("div",{className:"space-y-2",children:[s.jsxs(Vt,{label:t("settings.openchamber.passkeys.field.currentDevice"),children:[s.jsx(B,{type:"button",variant:l?"secondary":"outline",size:"xs",onClick:()=>{F()},disabled:i||d,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||d,className:"!font-normal text-muted-foreground hover:text-foreground",children:t(d?"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:h.reason}),i?s.jsx("p",{className:"typography-meta text-muted-foreground",children:t("settings.openchamber.passkeys.state.loading")}):c.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:c.map(m=>s.jsxs(Vt,{label:s.jsx("span",{title:m.label,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:Ho(m.lastUsedAt,t("settings.openchamber.passkeys.time.neverUsed"),e)}):t("settings.openchamber.passkeys.item.added",{time:Ho(m.createdAt,t("settings.openchamber.passkeys.time.neverUsed"),e)})}),s.jsx(B,{type:"button",variant:"ghost",size:"xs",onClick:()=>{I(m.id)},disabled:g===m.id,className:"!font-normal text-muted-foreground hover:text-foreground",children:g===m.id?t("settings.openchamber.passkeys.actions.removing"):t("settings.common.actions.delete")})]},m.id))})]}),k&&s.jsx("div",{className:"mt-1 py-1.5",children:s.jsx("p",{className:"typography-meta text-[var(--status-error)]",children:k})})]})},Gl=()=>{const t=lt.c(14),{t:e}=nt(),a=Dr(Th),n=Dr(Dh);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 u;t[8]!==l?(u=s.jsx("div",{className:"space-y-1","data-settings-item":"general.app-links",children:l}),t[8]=l,t[9]=u):u=t[9];let g;return t[10]!==i||t[11]!==r||t[12]!==u?(g=s.jsx($e,{title:i,description:r,children:u}),t[10]=i,t[11]=r,t[12]=u,t[13]=g):g=t[13],g};function Th(t){return t.trustedSchemes}function Dh(t){return t.removeTrustedScheme}const Bi=t=>{const e=oa(t);return e||{providerId:"",modelId:""}},ql=()=>{const{t}=nt(),e=et(ne=>ne.setProvider),a=et(ne=>ne.setModel),n=et(ne=>ne.setAgent),i=et(ne=>ne.setCurrentVariant),r=et(ne=>ne.setCurrentVariantOverride),l=et(ne=>ne.setSettingsDefaultModel),u=et(ne=>ne.setSettingsDefaultVariant),g=et(ne=>ne.setSettingsDefaultAgent),x=et(ne=>ne.selectionSource==="manual"),d=Hc(ne=>ne.currentSessionId),v=Mr(ne=>ne.getSessionModelSelection),c=Mr(ne=>ne.getSessionAgentSelection),N=!!(x&&d&&v(d)),b=!!(x&&d&&c(d)),C=de(ne=>ne.showDeletionDialog),k=de(ne=>ne.setShowDeletionDialog),A=et(ne=>ne.providers),h=et(ne=>ne.modelsMetadata),[E,F]=o.useState(),[I,w]=o.useState(),[m,y]=o.useState(),[U,S]=o.useState(!0),[M,j]=o.useState(),[R,H]=o.useState([]),[P,G]=o.useState(),[J,T]=o.useState(!0),W=o.useMemo(()=>Bi(E),[E]);o.useEffect(()=>{(async()=>{try{let ae=null;if(!ae){const me=Pn()?.settings;if(me)try{const Ne=(await me.load())?.settings;if(Ne){const Se=Ne;ae={defaultModel:typeof Ne.defaultModel=="string"?Ne.defaultModel:void 0,defaultVariant:typeof Se.defaultVariant=="string"?Se.defaultVariant:void 0,defaultAgent:typeof Ne.defaultAgent=="string"?Ne.defaultAgent:void 0,smallModelUseDefault:typeof Se.smallModelUseDefault=="boolean"?Se.smallModelUseDefault:void 0,smallModelOverride:typeof Se.smallModelOverride=="string"?Se.smallModelOverride:void 0,walkthroughModelOverride:typeof Se.walkthroughModelOverride=="string"?Se.walkthroughModelOverride:void 0}}}catch{}}if(!ae){const me=await rt("/api/config/settings",{method:"GET",headers:{Accept:"application/json"}});me.ok&&(ae=await me.json())}if(ae){const me=typeof ae.defaultModel=="string"&&ae.defaultModel.trim().length>0?ae.defaultModel.trim():void 0,Pe=typeof ae.defaultVariant=="string"&&ae.defaultVariant.trim().length>0?ae.defaultVariant.trim():void 0,Ne=typeof ae.defaultAgent=="string"&&ae.defaultAgent.trim().length>0?ae.defaultAgent.trim():void 0;me!==void 0&&F(me),Pe!==void 0&&w(Pe),Ne!==void 0&&y(Ne),typeof ae.smallModelUseDefault=="boolean"&&S(ae.smallModelUseDefault),typeof ae.smallModelOverride=="string"&&ae.smallModelOverride.trim()&&j(ae.smallModelOverride.trim()),typeof ae.walkthroughModelOverride=="string"&&ae.walkthroughModelOverride.trim()&&G(ae.walkthroughModelOverride.trim())}}catch(ae){console.warn("Failed to load defaults settings:",ae)}finally{T(!1)}})()},[]);const X=o.useCallback(async(ne,ae)=>{const me=ne&&ae?`${ne}/${ae}`:void 0;F(me),w(void 0),u(void 0),l(me),N||(i(void 0),ne&&ae&&A.find(Ne=>Ne.id===ne)&&(e(ne),a(ae)));try{await xt({defaultModel:me??"",defaultVariant:""});const Pe=await rt("/api/config/settings",{method:"PUT",headers:{"Content-Type":"application/json"},body:JSON.stringify({defaultModel:me})});Pe.ok||console.warn("Failed to save default model to server:",Pe.status,Pe.statusText)}catch(Pe){console.warn("Failed to save default model:",Pe)}},[N,A,i,a,e,l,u]),K="__default__",te=o.useCallback(ne=>ne===K?t("settings.openchamber.defaults.option.default"):ne.charAt(0).toUpperCase()+ne.slice(1),[t]),$=o.useCallback(async ne=>{const ae=ne===K?void 0:ne||void 0;w(ae),u(ae),N||r(ae??null,ae);try{await xt({defaultVariant:ae??""})}catch(me){console.warn("Failed to save default variant:",me)}},[N,r,u]),V=o.useCallback(async ne=>{const ae=ne||void 0;y(ae),g(ae),ne&&!b&&n(ne);try{await xt({defaultAgent:ae??""})}catch(me){console.warn("Failed to save default agent:",me)}},[b,n,g]),_=o.useCallback(async ne=>{S(ne);try{await xt({smallModelUseDefault:ne})}catch(ae){console.warn("Failed to save small model preference:",ae)}},[]),z=o.useCallback(async(ne,ae)=>{const me=ne&&ae?`${ne}/${ae}`:void 0;j(me);try{await xt({smallModelOverride:me??""})}catch(Pe){console.warn("Failed to save small model override:",Pe)}},[]),Z=o.useCallback(async(ne,ae)=>{const me=ne&&ae?`${ne}/${ae}`:void 0;G(me);try{await xt({walkthroughModelOverride:me??""})}catch(Pe){console.warn("Failed to save walkthrough model override:",Pe)}},[]),Y=o.useCallback((ne,ae)=>h.get(`${ne}/${ae}`)?.structured_output!==!1,[h]),se=o.useMemo(()=>Bi(M),[M]),ge=o.useMemo(()=>Bi(P),[P]);o.useEffect(()=>{let ne=!1;return(async()=>{try{const ae=await rt("/api/small-model",{method:"GET",headers:{Accept:"application/json"}});if(!ae.ok)return;const me=await ae.json().catch(()=>null);!ne&&Array.isArray(me?.authenticatedProviders)&&H(me.authenticatedProviders.filter(Pe=>typeof Pe=="string"))}catch{}})(),()=>{ne=!0}},[]);const ce=o.useMemo(()=>{if(!W.providerId||!W.modelId)return[];const me=A.find(Pe=>Pe.id===W.providerId)?.models.find(Pe=>Pe.id===W.modelId)?.variants;return me?Object.keys(me):[]},[W.modelId,W.providerId,A]),be=ce.length>0;return o.useEffect(()=>{!be&&I&&(w(void 0),u(void 0),N||i(void 0),xt({defaultVariant:""}).catch(()=>{}))},[N,I,i,u,be]),J?null:s.jsx(s.Fragment,{children:s.jsx($e,{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,be?` (${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(Vt,{settingsItem:"sessions.default-model",label:t("settings.openchamber.defaults.field.defaultModel"),children:s.jsx(Da,{providerId:W.providerId,modelId:W.modelId,onChange:X,className:Sn})}),s.jsx(Vt,{settingsItem:"sessions.default-thinking",label:t("settings.openchamber.defaults.field.defaultThinking"),children:s.jsxs(At,{value:I??K,onValueChange:$,disabled:!be,children:[s.jsx(Et,{size:$t,className:Cn,children:s.jsx(Ft,{placeholder:t("settings.openchamber.defaults.field.thinkingPlaceholder"),children:te(I??K)})}),s.jsxs(Tt,{children:[s.jsx(ot,{value:K,children:t("settings.openchamber.defaults.option.default")}),ce.map(ne=>s.jsx(ot,{value:ne,children:te(ne)},ne))]})]})}),s.jsx(Vt,{settingsItem:"sessions.default-agent",label:t("settings.openchamber.defaults.field.defaultAgent"),children:s.jsx(ll,{agentName:m||"",onChange:V,filter:ne=>Gc(ne.mode),className:Sn})})]}),s.jsx(Fa,{className:fs,children:s.jsx(pt,{settingsItem:"sessions.deletion-dialog",checked:C,onChange:k,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(Xs,{children:t("settings.openchamber.defaults.smallModel.title")}),s.jsx(Jt,{children:t("settings.openchamber.defaults.smallModel.description")})]}),s.jsx(pt,{settingsItem:"sessions.small-model",checked:U,onChange:ne=>{_(ne)},label:t("settings.openchamber.defaults.smallModel.useDefault"),ariaLabel:t("settings.openchamber.defaults.smallModel.useDefaultAria")}),U?null:s.jsx(Vt,{label:t("settings.openchamber.defaults.smallModel.overrideModel"),children:s.jsx(Da,{providerId:se.providerId,modelId:se.modelId,onChange:z,allowedProviderIds:R,className:Sn})}),s.jsxs(Fa,{className:fs,children:[s.jsxs("div",{className:"flex items-center gap-1.5",children:[s.jsx(Xs,{children:t("settings.openchamber.defaults.walkthroughModel.title")}),s.jsx(Jt,{children:t("settings.openchamber.defaults.walkthroughModel.description")})]}),s.jsx(Vt,{settingsItem:"sessions.walkthrough-model",label:t("settings.openchamber.defaults.walkthroughModel.overrideModel"),children:s.jsx(Da,{providerId:ge.providerId,modelId:ge.modelId,onChange:Z,allowedProviderIds:R,isModelAllowed:Y,placeholder:t("settings.openchamber.defaults.walkthroughModel.usesSmallModel"),className:Sn})})]})]})]})})})},Go={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"}},Mh={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"},Rh=()=>{const{t}=nt(),e=o.useMemo(()=>ds(),[]),a=o.useMemo(()=>ps(),[]),n=o.useMemo(()=>typeof window>"u"?!1:window.Capacitor?.isNativePlatform?.()===!0||window.location.protocol==="capacitor:",[]),i=!e&&!a&&!n,r=de($=>$.nativeNotificationsEnabled),l=de($=>$.setNativeNotificationsEnabled),u=de($=>$.notificationMode),g=de($=>$.setNotificationMode),x=de($=>$.notifyOnSubtasks),d=de($=>$.setNotifyOnSubtasks),v=de($=>$.notifyOnCompletion),c=de($=>$.setNotifyOnCompletion),N=de($=>$.notifyOnError),b=de($=>$.setNotifyOnError),C=de($=>$.notifyOnQuestion),k=de($=>$.setNotifyOnQuestion),A=de($=>$.notificationTemplates),h=de($=>$.setNotificationTemplates),[E,F]=o.useState("default"),[I,w]=o.useState(!1),[m,y]=o.useState(!1),[U,S]=o.useState(!1);o.useEffect(()=>{if(!i){w(!1),y(!1);return}typeof Notification<"u"&&F(Notification.permission);const $=typeof window<"u"&&"serviceWorker"in navigator&&"PushManager"in window&&"Notification"in window;w($),(async()=>{if(!$){y(!1);return}try{const _=await navigator.serviceWorker.getRegistration();if(!_){y(!1);return}const z=await _.pushManager.getSubscription();y(!!z)}catch{y(!1)}})()},[i]);const M=async $=>{if(e){l($);return}if(!i){l($);return}if($&&typeof Notification<"u"&&Notification.permission==="default")try{const V=await Notification.requestPermission();F(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,_)=>{h(z=>({...z,[$]:{...z[$],[V]:_}}))},H=$=>{const V="=".repeat((4-$.length%4)%4),_=($+V).replace(/-/g,"+").replace(/_/g,"/"),z=atob(_),Z=new Uint8Array(z.length);for(let Y=0;Y<z.length;Y+=1)Z[Y]=z.charCodeAt(Y);return Z},P=async($,V,_)=>{let z=null;const Z=new Promise((Y,se)=>{z=setTimeout(()=>{se(new Error(_))},V)});try{return await Promise.race([$,Z])}finally{z&&clearTimeout(z)}},G=async $=>{if($.active)return;const V=$.installing||$.waiting;V&&V.state!=="activated"&&await P(new Promise(_=>{const z=()=>{V.state==="activated"&&(V.removeEventListener("statechange",z),_())};V.addEventListener("statechange",z),z()}),15e3,"Service worker activation timed out")},J=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 _ of $)try{const z=_.opts?navigator.serviceWorker.register("/sw.js",_.opts):navigator.serviceWorker.register("/sw.js");return await P(z,1e4,`Service worker registration timed out (${_.label})`)}catch(z){V=z}throw V instanceof Error?V:new Error("Service worker registration failed")},T=async()=>{if(!("serviceWorker"in navigator))throw new Error("Service worker not supported");const $=await navigator.serviceWorker.getRegistration();if($)return $;const V=await J();try{await V.update()}catch{}return await G(V),V},W=$=>{const V=$,_=[`type=${typeof $}`,`toString=${String($)}`,`name=${String(V?.name??"")}`,`message=${String(V?.message??"")}`];let z="";try{z=JSON.stringify($)}catch{}return{summary:_.filter(Boolean).join(" | "),json:z,stack:typeof V?.stack=="string"?V.stack:""}},X=async()=>{const $=Pn();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"))}},K=async()=>{if(!I){D.error(t("settings.notifications.page.toast.pushUnsupported"));return}const $=Pn();if(!$?.push){D.error(t("settings.notifications.page.toast.pushApiUnavailable"));return}S(!0);try{if(typeof Notification<"u"&&Notification.permission==="default"){const ce=await Notification.requestPermission();if(F(ce),ce!=="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 _=await T();await G(_);const z=await _.pushManager.getSubscription();if(!("pushManager"in _)||!_.pushManager)throw new Error("PushManager unavailable (requires installed PWA + iOS 16.4+)");const Y=(z??await P(_.pushManager.subscribe({userVisibleOnly:!0,applicationServerKey:H(V.publicKey)}),15e3,"Push subscription timed out")).toJSON(),se=Y.keys;if(!Y.endpoint||!se?.p256dh||!se.auth)throw new Error("Push subscription missing keys");if(!(await P($.push.subscribe({endpoint:Y.endpoint,keys:{p256dh:se.p256dh,auth:se.auth},origin:typeof window<"u"?window.location.origin:void 0,platform:wd()}),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 _=W(V);D.error(t("settings.notifications.page.toast.enableBackgroundFailed"),{description:_.summary})}finally{S(!1)}},te=async()=>{if(!I){y(!1);return}const $=Pn();if(!$?.push){D.error(t("settings.notifications.page.toast.pushApiUnavailable"));return}S(!0);try{const _=await(await T()).pushManager.getSubscription();if(!_){y(!1);return}const z=_.endpoint;await _.unsubscribe(),await $.push.unsubscribe({endpoint:z}),y(!1),D.success(t("settings.notifications.page.toast.backgroundDisabled"))}finally{S(!1)}};return s.jsxs(s.Fragment,{children:[s.jsxs($e,{settingsItem:"notifications.delivery",title:t("settings.notifications.page.delivery.title"),divider:!1,children:[s.jsxs("div",{className:fs,children:[s.jsx(pt,{checked:r&&j,onChange:$=>{M($)},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(pt,{checked:u==="always",onChange:$=>g($?"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:()=>{X()},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($e,{settingsItem:"notifications.events",title:t("settings.notifications.page.events.title"),children:s.jsxs("div",{className:fs,children:[s.jsx(pt,{checked:v,onChange:c,label:t("settings.notifications.page.events.completionLabel"),ariaLabel:t("settings.notifications.page.events.completionAria")}),s.jsx(pt,{checked:x,onChange:d,label:t("settings.notifications.page.events.subtaskLabel"),ariaLabel:t("settings.notifications.page.events.subtaskAria")}),s.jsx(pt,{checked:N,onChange:b,label:t("settings.notifications.page.events.errorLabel"),ariaLabel:t("settings.notifications.page.events.errorAria")}),s.jsx(pt,{checked:C,onChange:k,label:t("settings.notifications.page.events.questionLabel"),ariaLabel:t("settings.notifications.page.events.questionAria")})]})}),!n&&s.jsx($e,{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(kn,{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(Xs,{className:"capitalize",children:t(Mh[$])}),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(We,{value:A[$].title,onChange:V=>R($,"title",V.target.value),className:"h-7",placeholder:t(Go[$].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(We,{value:A[$].message,onChange:V=>R($,"message",V.target.value),className:"h-7",placeholder:t(Go[$].messageKey)})]})]})]},$))})})]}),i&&s.jsx($e,{settingsItem:"notifications.push",title:t("settings.notifications.page.push.title"),children:s.jsx(pt,{checked:I?m:!1,disabled:!I||U,onChange:$=>{$?K():te()},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:U?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})})]})},Ts=t=>{if(!t)return;t.pause();const{src:e}=t;e.startsWith("blob:")&&URL.revokeObjectURL(e),t.removeAttribute("src"),t.load()},Oh=[{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"}],qo=t=>{const e=lt.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 u;e[2]!==n?(u=s.jsx("span",{className:"typography-ui-compact text-muted-foreground",children:n}),e[2]=n,e[3]=u):u=e[3];let g;return e[4]!==i||e[5]!==l||e[6]!==u?(g=s.jsxs("span",{className:"flex items-center gap-1.5",title:i,children:[l,u]}),e[4]=i,e[5]=l,e[6]=u,e[7]=g):g=e[7],g},Lh=({selectedModelId:t,onSelect:e})=>{const{t:a}=nt(),n=Qe.useCallback(c=>a(c),[a]),[i,r]=Qe.useState(new Map),[l,u]=Qe.useState(null),g=Qe.useCallback(async()=>{try{const c=await rt("/api/dictation/status",{query:{provider:"local"}});if(!c.ok)return;const N=await c.json();Array.isArray(N?.models)&&r(new Map(N.models.map(b=>[b.id,b])))}catch{}},[]);Qe.useEffect(()=>{g()},[g]);const x=Array.from(i.values()).some(c=>c.downloading);Qe.useEffect(()=>{if(!x)return;const c=setInterval(()=>{g()},2e3);return()=>clearInterval(c)},[x,g]);const d=async c=>{u(c);try{await rt(`/api/dictation/models/${encodeURIComponent(c)}/download`,{method:"POST"}),await g()}catch{}finally{u(null)}},v=async c=>{u(c);try{await rt(`/api/dictation/models/${encodeURIComponent(c)}`,{method:"DELETE"}),await g()}catch{}finally{u(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:Oh.map(c=>{const N=t===c.id,b=i.get(c.id)??null;return s.jsx("div",{className:we("rounded-lg border border-[var(--interactive-border)] p-3",N&&"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(c.id),onKeyDown:C=>{(C.key===" "||C.key==="Enter")&&(C.preventDefault(),e(c.id))},children:[s.jsx("div",{className:"pt-0.5",children:s.jsx(dr,{checked:N,onChange:()=>e(c.id),ariaLabel:n(c.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:we("typography-ui-label font-normal",N?"text-foreground":"text-foreground/50"),children:n(c.labelKey)}),c.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(c.badgeKey)}):null]}),s.jsxs("div",{className:"flex flex-col gap-1.5",children:[s.jsx(qo,{value:c.accuracy,label:a("settings.voice.page.stt.meta.accuracy")}),s.jsx(qo,{value:c.speed,label:a("settings.voice.page.stt.meta.speed")}),s.jsx("span",{className:"typography-ui-compact tabular-nums text-muted-foreground",children:c.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===c.id,onClick:()=>{v(c.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===c.id,onClick:()=>{d(c.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"})})})]})},c.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",Fh=()=>{const{t}=nt(),[e,a]=Qe.useState(null),[n,i]=Qe.useState(!1),r=Qe.useCallback(async()=>{try{const u=await rt("/api/dictation/status",{query:{provider:"local"}});if(!u.ok)return;const g=await u.json(),x=Array.isArray(g?.ttsModels)?g.ttsModels.find(d=>d.id===Gi):null;x&&a(x)}catch{}},[]);Qe.useEffect(()=>{r()},[r]),Qe.useEffect(()=>{if(!e?.downloading)return;const u=setInterval(()=>{r()},2e3);return()=>clearInterval(u)},[e?.downloading,r]);const l=async u=>{i(!0);try{const g=u==="POST"?`/api/dictation/models/${Gi}/download`:`/api/dictation/models/${Gi}`;await rt(g,{method:u}),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},Kh=[{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"}],Uh=()=>{const{t}=nt(),{isMobile:e}=da(),a=et(O=>O.voiceProvider),n=et(O=>O.setVoiceProvider),i=et(O=>O.speechRate),r=et(O=>O.setSpeechRate),l=et(O=>O.speechPitch),u=et(O=>O.setSpeechPitch),g=et(O=>O.speechVolume),x=et(O=>O.setSpeechVolume),d=et(O=>O.sayVoice),v=et(O=>O.setSayVoice),c=et(O=>O.localTtsVoiceId),N=et(O=>O.setLocalTtsVoiceId),{speak:b,stop:C,isPlaying:k,error:A}=qc(),h=Qe.useCallback(()=>{if(k){C();return}const O=Hi.find(Ce=>Ce.id===c)?.label??String(c);b(t("settings.voice.page.preview.voiceLine",{voiceName:O}),{speakerId:c,speed:et.getState().speechRate})},[k,c,b,C,t]),E=et(O=>O.browserVoice),F=et(O=>O.setBrowserVoice),I=et(O=>O.openaiVoice),w=et(O=>O.setOpenaiVoice),m=et(O=>O.openaiApiKey),y=et(O=>O.setOpenaiApiKey),U=et(O=>O.openaiCompatibleUrl),S=et(O=>O.setOpenaiCompatibleUrl),M=et(O=>O.openaiCompatibleApiKey),j=et(O=>O.setOpenaiCompatibleApiKey),R=et(O=>O.openaiCompatibleVoice),H=et(O=>O.setOpenaiCompatibleVoice),P=et(O=>O.openaiCompatibleTtsModel),G=et(O=>O.setOpenaiCompatibleTtsModel),J=et(O=>O.showMessageTTSButtons),T=et(O=>O.ttsInputMode),W=et(O=>O.setTtsInputMode),X=et(O=>O.sttProvider),K=et(O=>O.setSttProvider),te=et(O=>O.sttServerUrl),$=et(O=>O.setSttServerUrl),V=et(O=>O.sttApiKey),_=et(O=>O.setSttApiKey),z=et(O=>O.sttModel),Z=et(O=>O.setSttModel),Y=et(O=>O.sttLocalModel),se=et(O=>O.setSttLocalModel),ge=et(O=>O.sttLanguage),ce=et(O=>O.setSttLanguage),be=et(O=>O.setShowMessageTTSButtons),ne=et(O=>O.dictationEnabled),ae=et(O=>O.setDictationEnabled),[me,Pe]=Qe.useState(!1),[Ne,Se]=Qe.useState([]),[je,Me]=Qe.useState(!1),[Re,re]=Qe.useState(null),[fe,Ee]=Qe.useState(!1),[Be,Ve]=Qe.useState(!1),[Ge,Ke]=Qe.useState(null),[oe,ie]=Qe.useState(!1),[ye,ve]=Qe.useState(null),[Oe,Te]=Qe.useState([]),[xe,He]=Qe.useState(!1);Qe.useEffect(()=>((async()=>{const Ce=await Ei.waitForVoices();Te(Ce)})(),"speechSynthesis"in window&&(window.speechSynthesis.onvoiceschanged=()=>{Te(window.speechSynthesis.getVoices())}),()=>{"speechSynthesis"in window&&(window.speechSynthesis.onvoiceschanged=null)}),[]);const ue=Qe.useMemo(()=>Oe.filter(O=>O.lang).sort((O,Ce)=>{const qe=O.lang.startsWith("en"),_e=Ce.lang.startsWith("en");if(qe&&!_e)return-1;if(!qe&&_e)return 1;const tt=O.lang.localeCompare(Ce.lang);return tt!==0?tt:O.name.localeCompare(Ce.name)}),[Oe]),Ie=Qe.useCallback(()=>{if(xe){Ei.cancelSpeech(),He(!1);return}const O=Oe.find(tt=>tt.name===E),Ce=O?.name??t("settings.voice.page.preview.browserVoiceFallback"),qe=t("settings.voice.page.preview.voiceLine",{voiceName:Ce});He(!0);const _e=new SpeechSynthesisUtterance(qe);_e.rate=i,_e.pitch=l,_e.volume=g,O&&(_e.voice=O,_e.lang=O.lang),_e.onend=()=>He(!1),_e.onerror=()=>He(!1),window.speechSynthesis.cancel(),window.speechSynthesis.speak(_e)},[E,Oe,i,l,g,xe,t]);Qe.useEffect(()=>()=>{xe&&Ei.cancelSpeech()},[xe]),Qe.useEffect(()=>{if(!J||a!=="openai"&&a!=="openai-compatible"){Ee(m.trim().length>0);return}(async()=>{try{const _e=(await(await rt("/api/tts/status")).json()).available,tt=m.trim().length>0;Ee(_e||tt)}catch{Ee(m.trim().length>0)}})()},[m,J,a]),Qe.useEffect(()=>{if(!J){Pe(!1),Se([]);return}rt("/api/tts/say/status").then(O=>O.json()).then(O=>{if(Pe(O.available),O.voices){const Ce=O.voices.filter((qe,_e,tt)=>tt.findIndex(ht=>ht.name===qe.name)===_e).sort((qe,_e)=>qe.name.localeCompare(_e.name));Se(Ce)}}).catch(()=>{Pe(!1)})},[J]);const Le=Qe.useCallback(async()=>{if(Re){Ts(Re),re(null),Me(!1);return}Me(!0);let O=null;try{const Ce=await rt("/api/tts/say/speak",{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify({text:t("settings.voice.page.preview.voiceLine",{voiceName:d}),voice:d,rate:Math.round(100+(i-.5)*200)})});if(!Ce.ok)throw new Error("Preview failed");const qe=await Ce.blob(),_e=URL.createObjectURL(qe);O=new Audio(_e),O.onended=()=>{Ts(O),re(null),Me(!1)},O.onerror=()=>{Ts(O),re(null),Me(!1)},re(O),await O.play()}catch{Ts(O),re(null),Me(!1)}},[d,i,Re,t]);Qe.useEffect(()=>()=>{Ts(Re)},[Re]);const Ye=Qe.useCallback(async()=>{if(Ge){Ts(Ge),Ke(null),Ve(!1);return}Ve(!0);let O=null;try{const Ce=await rt("/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(!Ce.ok){const tt=await Ce.json().catch(()=>({error:"Unknown error"}));throw new Error(tt.error||`HTTP ${Ce.status}`)}const qe=await Ce.blob(),_e=URL.createObjectURL(qe);O=new Audio(_e),O.onended=()=>{Ts(O),Ke(null),Ve(!1)},O.onerror=()=>{Ts(O),Ke(null),Ve(!1)},Ke(O),await O.play()}catch{Ts(O),Ke(null),Ve(!1)}},[I,i,Ge,m,t]);Qe.useEffect(()=>()=>{Ts(Ge)},[Ge]);const q=Qe.useCallback(async()=>{if(ye){Ts(ye),ve(null),ie(!1);return}if(!U.trim())return;ie(!0);let O=null;try{const Ce=await rt("/api/tts/speak",{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify({text:t("settings.voice.page.preview.customServerLine"),voice:R,model:P||void 0,speed:i,baseURL:U,apiKey:M||void 0})});if(!Ce.ok){const tt=await Ce.json().catch(()=>({error:"Unknown error"}));throw new Error(tt.error||`HTTP ${Ce.status}`)}const qe=await Ce.blob(),_e=URL.createObjectURL(qe);O=new Audio(_e),O.onended=()=>{Ts(O),ve(null),ie(!1)},O.onerror=()=>{Ts(O),ve(null),ie(!1)},ve(O),await O.play()}catch{Ts(O),ve(null),ie(!1)}},[U,R,P,M,i,ye,t]);Qe.useEffect(()=>()=>{Ts(ye)},[ye]);const ke="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($e,{settingsItem:"voice.playback",title:t("settings.voice.page.section.playbackAndSummary"),divider:!1,contentClassName:"space-y-4",children:[s.jsx(pt,{checked:J,onChange:be,label:t("settings.voice.page.field.messageReadAloudButton"),ariaLabel:t("settings.voice.page.field.messageReadAloudButtonAria")}),J&&s.jsxs(s.Fragment,{children:[s.jsx(Ks,{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(Gs,{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")},...me?[{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:we(It,!fe&&"text-[var(--status-error)]"),children:t("settings.voice.page.field.apiKey")}),s.jsx("span",{className:we(Rn,!fe&&"text-[var(--status-error)]/80"),children:t(fe&&!m?"settings.voice.page.field.apiKeyHintUsingConfig":fe?"settings.voice.page.field.apiKeyHintProvide":"settings.voice.page.field.apiKeyHintRequired")}),s.jsxs("div",{className:we("relative",Us),children:[s.jsx("input",{type:"password",value:m,onChange:O=>y(O.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:we(It,!U.trim()&&"text-[var(--status-error)]"),children:t("settings.voice.page.field.serverUrl")}),s.jsx(Jt,{children:t("settings.voice.page.field.serverUrlHint")})]}),s.jsxs("div",{className:we("relative",Us),children:[s.jsx("input",{type:"text",value:U,onChange:O=>S(O.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"}),U&&s.jsx("button",{type:"button",onClick:()=>S(""),className:"absolute right-2 top-1/2 -translate-y-1/2 text-muted-foreground hover:text-foreground",children:s.jsx(L,{name:"close",className:"w-3.5 h-3.5"})})]})]}),s.jsxs("div",{className:"space-y-1.5",children:[s.jsx("span",{className:It,children:"API Key"}),s.jsx("span",{className:Rn,children:"Optional"}),s.jsxs("div",{className:we("relative",Us),children:[s.jsx("input",{type:"password",value:M,onChange:O=>j(O.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:()=>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:It,children:t("settings.voice.page.field.model")}),s.jsx("div",{className:we("relative",Us),children:s.jsx("input",{type:"text",value:P,onChange:O=>G(O.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:It,children:t("settings.voice.page.field.voice")}),s.jsx(Jt,{children:t("settings.voice.page.field.voiceIdentifierHint")})]}),s.jsxs("div",{className:we("flex items-center gap-2",Us),children:[s.jsx("div",{className:"relative min-w-0 flex-1",children:s.jsx("input",{type:"text",value:R,onChange:O=>H(O.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:q,title:t("settings.voice.page.actions.preview"),disabled:!U.trim(),children:oe?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(Fh,{}),s.jsxs(Vt,{label:t("settings.voice.page.field.voice"),children:[a==="local"&&s.jsxs(s.Fragment,{children:[s.jsxs(At,{value:String(c),onValueChange:O=>N(Number.parseInt(O,10)||0),children:[s.jsx(Et,{size:$t,className:Cn,children:s.jsx(Ft,{placeholder:t("settings.voice.page.field.selectVoicePlaceholder"),children:O=>Hi.find(Ce=>String(Ce.id)===O)?.label??O})}),s.jsx(Tt,{children:Hi.map(O=>s.jsx(ot,{value:String(O.id),children:O.label},O.id))})]}),s.jsx(B,{size:"xs",variant:"ghost",onClick:h,title:t("settings.voice.page.actions.preview"),children:k?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?s.jsx("span",{className:"typography-meta text-[var(--status-error)]",children:A}):null]}),a==="openai"&&fe&&s.jsxs(s.Fragment,{children:[s.jsxs(At,{value:I,onValueChange:w,children:[s.jsx(Et,{size:$t,className:Cn,children:s.jsx(Ft,{placeholder:t("settings.voice.page.field.selectVoicePlaceholder")})}),s.jsx(Tt,{children:Kh.map(O=>s.jsx(ot,{value:O.value,children:O.label},O.value))})]}),s.jsx(B,{size:"xs",variant:"ghost",onClick:Ye,title:t("settings.voice.page.actions.preview"),children:Be?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:Rn,children:t("settings.voice.page.field.configuredAbove")}),a==="say"&&me&&Ne.length>0&&s.jsxs(s.Fragment,{children:[s.jsxs(At,{value:d,onValueChange:v,children:[s.jsx(Et,{size:$t,className:Cn,children:s.jsx(Ft,{placeholder:t("settings.voice.page.field.selectVoicePlaceholder")})}),s.jsx(Tt,{children:Ne.map(O=>s.jsx(ot,{value:O.name,children:O.name},O.name))})]}),s.jsx(B,{size:"xs",variant:"ghost",onClick:Le,title:t("settings.voice.page.actions.preview"),children:je?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"&&ue.length>0&&s.jsxs(s.Fragment,{children:[s.jsxs(At,{value:E||"$auto",onValueChange:O=>F(O==="$auto"?"":O),children:[s.jsx(Et,{size:$t,className:Cn,children:s.jsx(Ft,{placeholder:t("settings.voice.page.field.auto")})}),s.jsxs(Tt,{children:[s.jsx(ot,{value:"$auto",children:t("settings.voice.page.field.auto")}),ue.map(O=>s.jsxs(ot,{value:O.name,children:[O.name," (",O.lang,")"]},O.name))]})]}),s.jsx(B,{size:"xs",variant:"ghost",onClick:Ie,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"})})]})]}),s.jsxs(Vt,{label:t("settings.voice.page.field.speechRate"),children:[!e&&s.jsx("input",{type:"range",min:.5,max:2,step:.1,value:i,onChange:O=>r(Number(O.target.value)),className:ke}),s.jsx(Ss,{value:i,onValueChange:r,min:.5,max:2,step:.1,className:we(Ps,"tabular-nums")})]}),s.jsxs(Vt,{label:t("settings.voice.page.field.speechPitch"),children:[!e&&s.jsx("input",{type:"range",min:.5,max:2,step:.1,value:l,onChange:O=>u(Number(O.target.value)),className:ke}),s.jsx(Ss,{value:l,onValueChange:u,min:.5,max:2,step:.1,className:we(Ps,"tabular-nums")})]}),s.jsxs(Vt,{label:t("settings.voice.page.field.speechVolume"),children:[!e&&s.jsx("input",{type:"range",min:0,max:1,step:.1,value:g,onChange:O=>x(Number(O.target.value)),className:ke}),e?s.jsx(Ss,{value:Math.round(g*100),onValueChange:O=>x(O/100),min:0,max:100,step:10,className:we(Ps,"tabular-nums")}):s.jsxs("span",{className:"typography-ui-label text-foreground tabular-nums min-w-[3rem] text-right",children:[Math.round(g*100),"%"]})]}),s.jsx(Ks,{title:t("settings.voice.page.field.ttsInputMode"),children:s.jsx(Gs,{value:T,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($e,{settingsItem:"voice.speech-recognition",title:t("settings.voice.page.section.speechRecognition"),contentClassName:"space-y-4",children:[s.jsx(pt,{checked:ne,onChange:ae,label:t("settings.voice.page.field.enableVoiceInput"),ariaLabel:t("settings.voice.page.field.enableVoiceInputAria")}),ne&&s.jsxs(s.Fragment,{children:[s.jsx(Ks,{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(Gs,{value:X,onChange:K,"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")}]})}),X==="local"&&s.jsxs("div",{className:"space-y-1.5",children:[s.jsx("span",{className:It,children:t("settings.voice.page.field.model")}),s.jsx(Lh,{selectedModelId:Y,onSelect:se})]}),X==="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:we(It,!te.trim()&&"text-[var(--status-error)]"),children:t("settings.voice.page.field.serverUrl")}),s.jsx(Jt,{children:t("settings.voice.page.field.sttServerUrlHint")})]}),s.jsxs("div",{className:we("relative",Us),children:[s.jsx("input",{type:"text",value:te,onChange:O=>$(O.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"}),te&&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:It,children:"API Key"}),s.jsx("span",{className:Rn,children:"Optional"}),s.jsxs("div",{className:we("relative",Us),children:[s.jsx("input",{type:"password",value:V,onChange:O=>_(O.target.value),placeholder:"sk-...",className:"w-full h-7 rounded-lg border border-input bg-transparent px-2 typography-ui-label text-foreground placeholder:text-muted-foreground focus:outline-none focus:ring-1 focus:ring-primary/50 focus:border-primary/70"}),V&&s.jsx("button",{type:"button",onClick:()=>_(""),className:"absolute right-2 top-1/2 -translate-y-1/2 text-muted-foreground hover:text-foreground",children:s.jsx(L,{name:"close",className:"w-3.5 h-3.5"})})]})]}),s.jsxs("div",{className:"space-y-1.5",children:[s.jsx("span",{className:It,children:t("settings.voice.page.field.model")}),s.jsx("div",{className:we("relative",Us),children:s.jsx("input",{type:"text",value:z,onChange:O=>Z(O.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:It,children:t("settings.voice.page.field.language")}),s.jsx(Jt,{children:t("settings.voice.page.field.sttLanguageHint")})]}),s.jsx("div",{className:"relative max-w-[8rem]",children:s.jsx("input",{type:"text",value:ge,onChange:O=>ce(O.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"})})]})]})]})]})]})},ti=[{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}],si=[{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}],zh="https://developers.cloudflare.com/cloudflare-one/networks/connectors/cloudflare-tunnel/get-started/create-remote-tunnel/",_h="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"}],$h=[".yml",".yaml",".json"],Vh="settings.openchamber.tunnel.error.invalidConfigExtension",Ia=t=>{const e=t.trim().toLowerCase();return $h.some(a=>e.endsWith(a))},Bh=t=>t==="ngrok"?"ngrok":"cloudflared",Wl=()=>{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"},Hh=(t,e=Wl())=>t==="ngrok"?e==="win32"?"winget install ngrok -s msstore":e==="darwin"?"brew install ngrok":"https://ngrok.com/download":e==="win32"?"winget install --id Cloudflare.cloudflared":e==="darwin"?"brew install cloudflared":"https://developers.cloudflare.com/cloudflare-one/networks/connectors/cloudflare-tunnel/downloads/",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():Bh(a),i=typeof e?.platform=="string"&&e.platform.trim().length>0?e.platform.trim():Wl(),r=typeof e?.installCommand=="string"&&e.installCommand.trim().length>0?e.installCommand.trim():Hh(a,i);return{provider:a,dependency:n,installCommand:r}},Jl=t=>t==="cloudflare"?"Cloudflare":t==="ngrok"?"Ngrok":t,Wo=t=>{const e=lt.c(11),{provider:a}=t;let n;e[0]!==a?(n=Jl(a),e[0]=a,e[1]=n):n=e[1];const i=n,u=a==="cloudflare"||a==="ngrok"?"text-[var(--status-warning)]":"text-muted-foreground";let g;e[2]!==u?(g=we("size-4 shrink-0",u),e[2]=u,e[3]=g):g=e[3];let x;e[4]!==g?(x=s.jsx(L,{name:"cloud",className:g}),e[4]=g,e[5]=x):x=e[5];let d;e[6]!==i?(d=s.jsx("span",{children:i}),e[6]=i,e[7]=d):d=e[7];let v;return e[8]!==x||e[9]!==d?(v=s.jsxs("span",{className:"flex items-center gap-2",children:[x,d]}),e[8]=x,e[9]=d,e[10]=v):v=e[10],v},wn=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,Jo=(t,e,a)=>{const n=or(t,e,a);return t.find(i=>i.value===n)?.label||n},Qo=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`},Gh=(t,e)=>xl(t,e,{hour:"2-digit",precision:"second"}),oi=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()}},qh=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():"",u=typeof r.name=="string"?r.name.trim():"",g=oi(typeof r.hostname=="string"?r.hostname:"");!l||!u||!g||e.has(l)||a.has(g)||(e.add(l),a.add(g),n.push({id:l,name:u,hostname:g}))}return n},Wh=()=>typeof crypto<"u"&&typeof crypto.randomUUID=="function"?crypto.randomUUID():`${Date.now()}-${Math.random().toString(36).slice(2,10)}`,Jh=()=>{const{t}=nt(),e=de(Q=>Q.timeFormatPreference),a=o.useCallback(Q=>t(Q),[t]),[n,i]=o.useState("checking"),[r,l]=o.useState(null),[u,g]=o.useState(null),[x,d]=o.useState(null),[v,c]=o.useState(null),[N,b]=o.useState(null),[C,k]=o.useState(!1),[A,h]=o.useState(!1),[E,F]=o.useState(!1),[I,w]=o.useState("cloudflare"),[m,y]=o.useState(()=>Wi("cloudflare")),[U,S]=o.useState([]),[M,j]=o.useState("quick"),[R,H]=o.useState(null),[P,G]=o.useState([]),[J,T]=o.useState({}),[W,X]=o.useState(""),[K,te]=o.useState({}),[$,V]=o.useState(new Set),[_,z]=o.useState(!1),[Z,Y]=o.useState(""),[se,ge]=o.useState(""),[ce,be]=o.useState(""),[ne,ae]=o.useState(1800*1e3),[me,Pe]=o.useState(480*60*1e3),[Ne,Se]=o.useState(""),[je,Me]=o.useState([]),[Re,re]=o.useState(()=>Date.now()),[fe,Ee]=o.useState(null),Be=t(Vh),Ve=o.useRef(null),Ge=o.useMemo(()=>R?!Ia(R):!1,[R]),Ke=o.useMemo(()=>P.find(Q=>Q.id===W)||P[0]||null,[P,W]),oe=o.useMemo(()=>je.map(Q=>{const he=Q.expiresAt<=Re,ze=Q.status==="active"&&!he,De=ze?Qo(Q.expiresAt-Re):Q.inactiveReason==="expired"||he?"expired":"inactive",it=De==="expired"?t("settings.openchamber.tunnel.state.expired"):Q.inactiveReason==="tunnel-revoked"?t("settings.openchamber.tunnel.state.revoked"):t("settings.openchamber.tunnel.state.inactive"),at=wn(Q.mode);return{...Q,isActive:ze,mode:at,remainingTextForSession:De,inactiveLabel:it}}),[Re,je,t]),ie=o.useMemo(()=>r?.connectUrl?r.bootstrapExpiresAt===null?!0:r.bootstrapExpiresAt>Re:!1,[Re,r?.bootstrapExpiresAt,r?.connectUrl]),ye=o.useMemo(()=>!r||n!=="active"&&n!=="stopping"?!1:u===M,[u,n,r,M]),ve=o.useMemo(()=>!r||n!=="active"||!u?!1:u!==M,[u,n,r,M]),Oe=o.useMemo(()=>{if(typeof fe=="number"&&Number.isFinite(fe)&&fe>0)return fe;if(typeof window>"u")return null;const he=Ka()||window.location.href;let ze=0;try{ze=Number(new URL(he).port)}catch{ze=Number(window.location.port)}return Number.isFinite(ze)&&ze>0?ze:null},[fe]),Te=o.useMemo(()=>U.find(Q=>Q.provider===I)??null,[U,I]),xe=o.useMemo(()=>{const Q=new Set(Te?.modes?.map(he=>he.key).filter(he=>he==="quick"||he==="managed-remote"||he==="managed-local"));return Q.size===0?qi:qi.filter(he=>Q.has(he.value))},[Te]),He=o.useMemo(()=>xe.some(Q=>Q.value==="managed-remote"||Q.value==="managed-local"),[xe]),ue=o.useMemo(()=>m.provider===I?m:Wi(I),[m,I]),Ie=o.useCallback(async Q=>{await In(Q)},[]),Le=o.useCallback((Q,he)=>(y(Wi(he,Q)),Q.available===!0),[]),Ye=o.useCallback(async(Q,he)=>{try{const ze=await rt("/api/openchamber/tunnel/check",{query:{provider:Q},...he?{signal:he}:{}});if(!ze.ok)return null;const De=await ze.json();if(he?.aborted)return null;const it=Le(De,Q);return i(at=>at==="checking"||at==="starting"||at==="active"||at==="stopping"?at:it?"idle":"not-available"),it}catch{return null}},[Le]),q=o.useCallback(async Q=>{try{const[he,ze,De,it]=await Promise.all([rt("/api/openchamber/tunnel/check",{signal:Q}),rt("/api/openchamber/tunnel/status",{signal:Q}),rt("/api/config/settings",{signal:Q,headers:{Accept:"application/json"}}),rt("/api/openchamber/tunnel/providers",{signal:Q})]),at=await he.json(),Je=await ze.json(),Nt=De.ok?await De.json():{},xs=it.ok?await it.json():{},ts=Je.ttlConfig?.bootstrapTtlMs??(Nt?.tunnelBootstrapTtlMs===null?null:typeof Nt?.tunnelBootstrapTtlMs=="number"?Nt.tunnelBootstrapTtlMs:1800*1e3),Ms=typeof Je.ttlConfig?.sessionTtlMs=="number"?Je.ttlConfig.sessionTtlMs:typeof Nt?.tunnelSessionTtlMs=="number"?Nt.tunnelSessionTtlMs:480*60*1e3,Bt=wn(Je.mode??Nt?.tunnelMode),os=typeof Nt?.tunnelProvider=="string"&&Nt.tunnelProvider.trim().length>0?Nt.tunnelProvider.trim().toLowerCase():"cloudflare",qt=typeof Nt?.managedLocalTunnelConfigPath=="string"&&Nt.managedLocalTunnelConfigPath.trim()||null,bs=Le(at,os),ms=qh(Je?.managedRemoteTunnelPresets),vs=typeof Je.managedRemoteTunnelHostname=="string"?Je.managedRemoteTunnelHostname:"",us=ms.length>0?ms:vs?[{id:`legacy-${oi(vs)}`,name:vs,hostname:oi(vs)}]:[],ys=us[0]?.id||"";if(ae(ts),Pe(Ms),w(os),S(Array.isArray(xs?.providers)?xs.providers:[]),j(Bt),H(qt),G(us),X(ys),Me(Array.isArray(Je.activeSessions)?Je.activeSessions:[]),g(Je.activeTunnelMode?wn(Je.activeTunnelMode):Je.active&&Je.mode?wn(Je.mode):null),V(new Set(Array.isArray(Je.managedRemoteTunnelTokenPresetIds)?Je.managedRemoteTunnelTokenPresetIds:[])),Ee(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(bs?"idle":"not-available")}catch{Q.aborted||(i("error"),c(t("settings.openchamber.tunnel.toast.checkAvailabilityFailed")))}},[Le,t]);o.useEffect(()=>{const Q=new AbortController;return q(Q.signal),()=>Q.abort()},[q]),o.useEffect(()=>{if(!r?.connectUrl){d(null);return}let Q=!1;return Pl.toDataURL(r.connectUrl,{width:256,margin:2,color:{dark:"#000000",light:"#ffffff"}}).then(he=>{Q||d(he)}).catch(()=>{Q||d(null)}),()=>{Q=!0}},[r?.connectUrl]),o.useEffect(()=>{if(!r?.bootstrapExpiresAt){Se(t("settings.openchamber.tunnel.state.noExpiry"));return}let Q=null,he=Date.now();const ze=()=>{const at=r.bootstrapExpiresAt?r.bootstrapExpiresAt-Date.now():0;at<=0?Se(t("settings.openchamber.tunnel.state.expired")):Se(Qo(at))},De=()=>{const at=Date.now();at-he>=1e3&&(ze(),he=at),Q=requestAnimationFrame(De)};ze(),(typeof document>"u"||document.visibilityState==="visible")&&(Q=requestAnimationFrame(De));const it=()=>{document.visibilityState==="visible"&&Q===null?Q=requestAnimationFrame(De):document.visibilityState!=="visible"&&Q!==null&&(cancelAnimationFrame(Q),Q=null)};return document.addEventListener("visibilitychange",it),()=>{document.removeEventListener("visibilitychange",it),Q!==null&&cancelAnimationFrame(Q)}},[t,r?.bootstrapExpiresAt]),o.useEffect(()=>{let Q=null,he=Date.now();const ze=()=>{const it=Date.now();it-he>=1e3&&(re(it),he=it),Q=requestAnimationFrame(ze)};(typeof document>"u"||document.visibilityState==="visible")&&(Q=requestAnimationFrame(ze));const De=()=>{document.visibilityState==="visible"&&Q===null?Q=requestAnimationFrame(ze):document.visibilityState!=="visible"&&Q!==null&&(cancelAnimationFrame(Q),Q=null)};return document.addEventListener("visibilitychange",De),()=>{document.removeEventListener("visibilitychange",De),Q!==null&&cancelAnimationFrame(Q)}},[]),o.useEffect(()=>{if(n==="starting"||n==="stopping"||n==="checking")return;let Q=!1;const he=async()=>{try{const De=await rt("/api/openchamber/tunnel/status");if(!De.ok||Q)return;const it=await De.json();if(Q)return;Me(Array.isArray(it.activeSessions)?it.activeSessions:[]),V(new Set(Array.isArray(it.managedRemoteTunnelTokenPresetIds)?it.managedRemoteTunnelTokenPresetIds:[])),Ee(typeof it.localPort=="number"?it.localPort:null)}catch{}},ze=window.setInterval(()=>{typeof document<"u"&&document.visibilityState!=="visible"||he()},5e3);return()=>{Q=!0,window.clearInterval(ze)}},[n]);const ke=o.useCallback(async Q=>{F(!0);try{await xt(Q),Object.prototype.hasOwnProperty.call(Q,"tunnelMode")&&Q.tunnelMode&&j(Q.tunnelMode),Object.prototype.hasOwnProperty.call(Q,"tunnelProvider")&&typeof Q.tunnelProvider=="string"&&w(Q.tunnelProvider),Object.prototype.hasOwnProperty.call(Q,"managedLocalTunnelConfigPath")&&H(Q.managedLocalTunnelConfigPath??null),Object.prototype.hasOwnProperty.call(Q,"managedRemoteTunnelPresets")&&Q.managedRemoteTunnelPresets&&G(Q.managedRemoteTunnelPresets)}catch{D.error(t("settings.openchamber.tunnel.toast.saveSettingsFailed"))}finally{F(!1)}},[t]),O=o.useCallback(async(Q,he)=>{h(!0);try{await xt({tunnelBootstrapTtlMs:Q,tunnelSessionTtlMs:he})}catch{D.error(t("settings.openchamber.tunnel.toast.saveTtlFailed"))}finally{h(!1)}},[t]),Ce=o.useCallback(async Q=>{const he=Q.token.trim();if(he)try{const ze={...K,[Q.presetId]:he};await xt({managedRemoteTunnelPresetTokens:ze}),V(De=>{const it=new Set(De);return it.add(Q.presetId),it})}catch{D.error(t("settings.openchamber.tunnel.toast.saveTokenFailed"))}},[K,t]),qe=o.useCallback(async Q=>{b(null),c(null);const he=U.find(De=>De.provider===Q),ze=he?.modes?.some(De=>De.key===M)?M:wn(he?.modes?.[0]?.key);await ke({tunnelProvider:Q,tunnelMode:ze}),Ye(Q)},[U,Ye,ke,M]),_e=o.useCallback(async()=>{const Q=await wl({filters:[{name:"Config",extensions:["yml","yaml","json"]}]});if(Q.success&&typeof Q.path=="string"&&Q.path.trim().length>0){const he=Q.path.trim();if(!Ia(he)){D.error(Be);return}H(he),await ke({managedLocalTunnelConfigPath:he});return}Ve.current?.click()},[Be,ke]),tt=o.useCallback(Q=>{const he=Q.trim();H(he.length>0?he:null)},[]),ht=o.useCallback(async()=>{if(R&&!Ia(R)){D.error(Be);return}await ke({managedLocalTunnelConfigPath:R})},[Be,R,ke]),mt=o.useCallback(async()=>{H(null),await ke({managedLocalTunnelConfigPath:null})},[ke]),ut=o.useCallback(async Q=>{const he=Q.target.files?.[0];if(!he)return;const ze=he.name.trim();if(ze.length!==0){if(!Ia(ze)){D.error(Be);return}H(ze),await ke({managedLocalTunnelConfigPath:ze}),Q.target.value=""}},[Be,ke]),ft=o.useCallback(async()=>{if(c(null),b(null),M==="managed-local"&&R&&!Ia(R)){c(Be),D.error(Be);return}i("starting");try{let Q="",he="";if(M==="managed-remote"){if(!Ke){i("idle"),b(t("settings.openchamber.tunnel.toast.selectOrAddManagedRemoteFirst")),D.error(t("settings.openchamber.tunnel.toast.selectOrAddManagedRemoteFirst"));return}Q=Ke.hostname,he=(K[Ke.id]||"").trim(),await ke({tunnelMode:"managed-remote",managedRemoteTunnelPresets:P})}const ze=await rt("/api/openchamber/tunnel/start",{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify({provider:I,mode:M,...M==="managed-remote"&&Ke?{managedRemoteTunnelPresetId:Ke.id,managedRemoteTunnelPresetName:Ke.name}:{},...M==="managed-remote"&&Q?{managedRemoteTunnelHostname:Q}:{},...M==="managed-remote"&&he?{managedRemoteTunnelToken:he}:{},...M==="managed-local"&&R?{configPath:R}:{}})}),De=await ze.json();if(!ze.ok||!De.ok){if(M==="managed-remote"&&typeof De.error=="string"&&De.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"),c(De.error||t("settings.openchamber.tunnel.toast.startFailed")),D.error(De.error||t("settings.openchamber.tunnel.toast.startFailed"));return}const it=typeof De.url=="string"?De.url:"";if(!it){i("error"),c(t("settings.openchamber.tunnel.toast.startedButNoPublicUrl")),D.error(t("settings.openchamber.tunnel.toast.startedButNoPublicUrl"));return}if(l({url:it,connectUrl:typeof De.connectUrl=="string"?De.connectUrl:null,bootstrapExpiresAt:typeof De.bootstrapExpiresAt=="number"?De.bootstrapExpiresAt:null}),g(De.activeTunnelMode?wn(De.activeTunnelMode):De.mode?wn(De.mode):M),Me(Array.isArray(De.activeSessions)?De.activeSessions:[]),Array.isArray(De.managedRemoteTunnelTokenPresetIds)&&V(new Set(De.managedRemoteTunnelTokenPresetIds)),typeof De.localPort=="number"&&Ee(De.localPort),typeof De.mode=="string"&&j(wn(De.mode)),i("active"),De.replacedTunnel){const at=typeof De.revokedBootstrapCount=="number"?De.revokedBootstrapCount:0,Je=typeof De.invalidatedSessionCount=="number"?De.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"),c(t("settings.openchamber.tunnel.toast.startFailed")),D.error(t("settings.openchamber.tunnel.toast.startFailed"))}},[Be,P,ke,Ke,K,t,I,M,R]),kt=o.useCallback(async()=>{i("stopping");try{await rt("/api/openchamber/tunnel/stop",{method:"POST"});const Q=await rt("/api/openchamber/tunnel/status");if(Q.ok){const he=await Q.json();Me(Array.isArray(he.activeSessions)?he.activeSessions:[]),V(new Set(Array.isArray(he.managedRemoteTunnelTokenPresetIds)?he.managedRemoteTunnelTokenPresetIds:[])),Ee(typeof he.localPort=="number"?he.localPort:null)}l(null),g(null),d(null),i("idle"),D.success(t("settings.openchamber.tunnel.toast.stopped"))}catch{i("error"),c(t("settings.openchamber.tunnel.toast.stopFailed")),D.error(t("settings.openchamber.tunnel.toast.stopFailed"))}},[t]),vt=o.useCallback(async()=>{if(r?.connectUrl)try{await navigator.clipboard.writeText(r.connectUrl),k(!0),D.success(t("settings.openchamber.tunnel.toast.connectLinkCopied")),setTimeout(()=>k(!1),2e3)}catch{D.error(t("settings.openchamber.tunnel.toast.copyUrlFailed"))}},[t,r?.connectUrl]),Ct=o.useCallback(async Q=>{const he=ti.find(ze=>ze.value===Q);he&&(ae(he.ms),await O(he.ms,me))},[O,me]),Ze=o.useCallback(async Q=>{const he=si.find(ze=>ze.value===Q);!he||he.ms===null||(Pe(he.ms),await O(ne,he.ms))},[ne,O]),Xe=o.useCallback(async Q=>{b(null),c(null),n!=="active"&&n!=="stopping"&&n!=="starting"&&i("idle"),await ke({tunnelMode:Q,managedRemoteTunnelPresets:P})},[P,ke,n]),ct=o.useCallback(async(Q,he)=>{try{await xt({managedRemoteTunnelPresets:he})}catch{D.error(t("settings.openchamber.tunnel.toast.saveSelectedManagedRemoteFailed"))}},[t]),Ue=o.useCallback(Q=>{const he=P.find(ze=>ze.id===Q);he&&(X(he.id),b(null),ct(he,P))},[P,ct]),jt=o.useCallback(async()=>{const Q=Z.trim(),he=oi(se),ze=ce.trim();if(!Q){D.error(t("settings.openchamber.tunnel.toast.tunnelNameRequired"));return}if(!he){D.error(t("settings.openchamber.tunnel.toast.managedRemoteHostnameRequired"));return}if(!ze){D.error(t("settings.openchamber.tunnel.toast.managedRemoteTokenRequired"));return}if(P.some(at=>at.hostname===he)){D.error(t("settings.openchamber.tunnel.toast.hostnameAlreadyExists"));return}const De={id:Wh(),name:Q,hostname:he},it=[...P,De];G(it),X(De.id),T(at=>({...at,[De.id]:!0})),te(at=>({...at,[De.id]:ze})),b(null),z(!1),Y(""),ge(""),be(""),await ke({tunnelMode:"managed-remote",managedRemoteTunnelPresets:it,managedRemoteTunnelPresetTokens:{...K,[De.id]:ze}}),await Ce({presetId:De.id,presetName:De.name,hostname:De.hostname,token:ze}),D.success(t("settings.openchamber.tunnel.toast.managedRemoteSaved"))},[P,se,Z,ce,Ce,ke,K,t]),Ae=o.useCallback(async Q=>{const he=P.find(Je=>Je.id===Q);if(!he)return;const ze=P.filter(Je=>Je.id!==he.id),De=ze[0]?.id||"",it=W===he.id?De:W,at=Object.fromEntries(Object.entries(K).filter(([Je,Nt])=>Je!==he.id&&Nt.trim().length>0));G(ze),X(it),T(Je=>{const Nt={...Je};return delete Nt[he.id],Nt}),te(Je=>{const Nt={...Je};return delete Nt[he.id],Nt}),V(Je=>{const Nt=new Set(Je);return Nt.delete(he.id),Nt}),b(null),await ke({managedRemoteTunnelPresets:ze,managedRemoteTunnelPresetTokens:at}),D.success(t("settings.openchamber.tunnel.toast.managedRemoteRemoved"))},[P,ke,W,K,t]),yt="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($e,{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:[oe.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:oe.map(Q=>{const he=Q.mode==="quick",ze=Q.mode==="managed-remote",De=he?"border-[var(--status-warning-border)] bg-[var(--status-warning-background)] text-[var(--status-warning)]":ze?"border-[var(--status-info-border)] bg-[var(--status-info-background)] text-[var(--status-info)]":"border-[var(--status-success-border)] bg-[var(--status-success-background)] text-[var(--status-success)]",it=Q.isActive?he?"text-[var(--status-warning)]":ze?"text-[var(--status-info)]":"text-[var(--status-success)]":"text-muted-foreground/50",at=t(he?"settings.openchamber.tunnel.badge.quick":ze?"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:we("size-2.5 shrink-0",it)}),s.jsx("span",{className:we("typography-micro rounded border px-1.5 py-0.5 uppercase",De),children:at}),s.jsx("span",{className:"typography-meta text-muted-foreground/80",children:t("settings.openchamber.tunnel.session.redeemedAt",{time:Gh(Q.createdAt,e)})}),s.jsx("span",{className:"typography-meta text-foreground",children:Q.isActive?t("settings.openchamber.tunnel.session.expiresIn",{remaining:Q.remainingTextForSession}):Q.inactiveLabel===t("settings.openchamber.tunnel.state.inactive")?t("settings.openchamber.tunnel.state.inactive"):t("settings.openchamber.tunnel.session.inactiveWithReason",{reason:Q.inactiveLabel})})]},Q.sessionId)})})]})}),n==="not-available"&&s.jsx("section",{className:"space-y-2 px-2 pb-2 pt-0",children:s.jsxs("div",{className:"flex items-start gap-2 rounded-lg border border-[var(--status-warning)]/30 bg-[var(--status-warning)]/5 p-3",children:[s.jsx(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:ue.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:ue.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:It,children:t("settings.openchamber.tunnel.field.provider")}),s.jsxs(At,{value:I,onValueChange:Q=>{qe(Q)},disabled:E||n==="starting"||n==="stopping",children:[s.jsx(Et,{size:$t,className:"max-w-[16rem]",children:s.jsx(Ft,{placeholder:t("settings.openchamber.tunnel.field.providerPlaceholder"),children:Jl(I)})}),s.jsxs(Tt,{children:[U.length>0?U.map(Q=>s.jsx(ot,{value:Q.provider,children:s.jsx(Wo,{provider:Q.provider})},Q.provider)):s.jsx(ot,{value:"cloudflare",children:s.jsx(Wo,{provider:"cloudflare"})}),s.jsx(ot,{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:It,children:t("settings.openchamber.tunnel.field.tunnelType")}),s.jsx("div",{className:"flex flex-wrap items-center gap-1",children:xe.map(Q=>s.jsxs(pr,{children:[s.jsx(mr,{asChild:!0,children:s.jsx(B,{variant:"chip",size:"xs","aria-pressed":M===Q.value,className:"!font-normal",onClick:()=>{Xe(Q.value)},disabled:E||n==="starting"||n==="stopping",children:a(Q.labelKey)})}),s.jsx(pl,{sideOffset:8,className:"max-w-xs",children:a(Q.tooltipKey)})]},Q.value))})]})]}),s.jsxs("div",{"data-settings-item":"tunnel.ttl",className:"mt-2 grid grid-cols-1 gap-2 py-1.5 md:grid-cols-[14rem_auto] md:gap-x-8 md:gap-y-2",children:[s.jsxs("div",{className:"flex min-w-0 items-center gap-2",children:[s.jsx("span",{className:we(It,"shrink-0"),children:t("settings.openchamber.tunnel.field.connectLinkTtl")}),s.jsxs(At,{value:or(ti,ne,"1800000"),onValueChange:Q=>{Ct(Q)},disabled:A||E||n==="starting"||n==="stopping",children:[s.jsx(Et,{size:$t,className:"max-w-[11rem] min-w-0",children:s.jsx(Ft,{className:"truncate",children:Jo(ti,ne,"1800000")})}),s.jsx(Tt,{children:ti.map(Q=>s.jsx(ot,{value:Q.value,children:Q.label},Q.value))})]})]}),s.jsxs("div",{className:"flex min-w-0 items-center gap-2",children:[s.jsx("span",{className:we(It,"shrink-0"),children:t("settings.openchamber.tunnel.field.tunnelSessionTtl")}),s.jsxs(At,{value:or(si,me,"28800000"),onValueChange:Q=>{Ze(Q)},disabled:A||E||n==="starting"||n==="stopping",children:[s.jsx(Et,{size:$t,className:"max-w-[11rem] min-w-0",children:s.jsx(Ft,{className:"truncate",children:Jo(si,me,"28800000")})}),s.jsx(Tt,{children:si.map(Q=>s.jsx(ot,{value:Q.value,children:Q.label},Q.value))})]})]})]}),M==="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")}),He&&s.jsx("p",{className:"typography-meta mt-1 text-[var(--status-warning)]",children:t("settings.openchamber.tunnel.warning.quickModeReliability")})]})]})}),M==="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 Oe=="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:",Oe]})]})}),s.jsxs("div",{className:"mb-1 flex items-center justify-between gap-3",children:[s.jsx(Xs,{children:t("settings.openchamber.tunnel.section.savedManagedRemoteTunnels")}),s.jsxs(B,{variant:"ghost",size:"xs",className:"!font-normal",onClick:()=>z(Q=>!Q),disabled:n==="starting"||n==="stopping"||E,children:[s.jsx(L,{name:"add",className:"h-3.5 w-3.5"}),t("settings.common.actions.create")]})]}),P.length>0?s.jsx("div",{className:"overflow-hidden rounded-md border border-[var(--surface-subtle)]",children:P.map((Q,he)=>{const ze=K[Q.id]||"",De=$.has(Q.id),it=J[Q.id]??!1;return s.jsx("div",{className:we(he<P.length-1&&"border-b border-[var(--surface-subtle)]"),children:s.jsxs(Hn,{open:it,onOpenChange:at=>{T(Je=>({...Je,[Q.id]:at})),at&&Ue(Q.id)},className:"py-1.5",children:[s.jsxs("div",{className:"flex items-start gap-2 px-3",children:[s.jsxs(Gn,{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:[it?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:Q.name})]}),s.jsx(B,{variant:"ghost",size:"xs",className:"h-7 w-7 p-0 text-muted-foreground hover:text-[var(--status-error)]","aria-label":t("settings.openchamber.tunnel.actions.removePresetAria",{name:Q.name}),onClick:()=>{Ae(Q.id)},disabled:n==="starting"||n==="stopping"||E,children:s.jsx(L,{name:"delete-bin",className:"h-3.5 w-3.5"})})]}),s.jsx(qn,{className:"pt-1.5",children:s.jsxs("div",{className:"space-y-1 px-3 pb-2",children:[s.jsxs("p",{className:"typography-meta text-muted-foreground/70",children:[t("settings.openchamber.tunnel.field.hostnameLabel")," ",s.jsx("code",{children:Q.hostname})]}),s.jsx(We,{type:"password",value:ze,onChange:at=>{const Je=at.target.value;b(null),te(Nt=>({...Nt,[Q.id]:Je}))},onBlur:at=>{const Je=at.currentTarget.value.trim();Je&&Ce({presetId:Q.id,presetName:Q.name,hostname:Q.hostname,token:Je})},placeholder:t(De?"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"||ze.trim().length===0,onClick:()=>{Ce({presetId:Q.id,presetName:Q.name,hostname:Q.hostname,token:ze})},children:t("settings.openchamber.tunnel.actions.saveToken")})})]})})]})},Q.id)})}):s.jsx("p",{className:"typography-meta text-muted-foreground/70",children:t("settings.openchamber.tunnel.empty.noManagedRemoteTunnels")}),_&&s.jsxs("div",{className:"space-y-2 rounded-md border border-[var(--surface-subtle)] p-2",children:[s.jsx(We,{value:Z,onChange:Q=>Y(Q.target.value),placeholder:t("settings.openchamber.tunnel.field.newPresetNamePlaceholder"),className:"h-7",disabled:E||n==="starting"||n==="stopping"}),s.jsx(We,{value:se,onChange:Q=>ge(Q.target.value),placeholder:t("settings.openchamber.tunnel.field.newPresetHostnamePlaceholder"),className:"h-7",disabled:E||n==="starting"||n==="stopping"}),s.jsx(We,{type:"password",value:ce,onChange:Q=>be(Q.target.value),placeholder:t("settings.openchamber.tunnel.field.newPresetTokenPlaceholder"),className:"h-7",disabled:E||n==="starting"||n==="stopping"}),typeof Oe=="number"&&s.jsxs("p",{className:"typography-meta text-muted-foreground/70",children:[t("settings.openchamber.tunnel.note.cloudflareConnectorTargetUse")," ",s.jsxs("code",{children:["http://localhost:",Oe]}),"."]}),s.jsxs("div",{className:"flex items-center gap-2",children:[s.jsx(B,{variant:"ghost",size:"xs",className:"!font-normal",onClick:()=>{jt()},disabled:E||n==="starting"||n==="stopping",children:t("settings.common.actions.saveChanges")}),s.jsx(B,{variant:"ghost",size:"xs",className:"!font-normal",onClick:()=>{z(!1),Y(""),ge(""),be("")},disabled:E||n==="starting"||n==="stopping",children:t("settings.common.actions.cancel")})]})]}),s.jsxs("div",{className:"flex items-center gap-1.5",children:[s.jsx("p",{className:"typography-meta text-muted-foreground/80",children:t("settings.openchamber.tunnel.note.tokensSavedPerTunnel")}),s.jsx(Jt,{children:t("settings.openchamber.tunnel.tooltip.tokensSavedPath")})]}),!Ke&&N&&s.jsx("p",{className:"typography-meta text-[var(--status-error)]",children:N})]}),M==="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:It,children:t("settings.openchamber.tunnel.field.configurationFile")}),s.jsx("input",{ref:Ve,type:"file",accept:".yml,.yaml,.json",className:"hidden",onChange:Q=>{ut(Q)}}),s.jsxs("div",{className:"flex items-center gap-2",children:[s.jsx(We,{value:R||"",onChange:Q=>{tt(Q.target.value)},onBlur:()=>{ht()},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:()=>{_e()},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:()=>{mt()},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")}),Ge&&s.jsx("p",{className:"typography-meta text-[var(--status-error)]",children:Be})]})}),!ye&&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:[M==="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:()=>{Ie(zh)},children:[t("settings.openchamber.tunnel.actions.openManagedRemoteDocs"),s.jsx(L,{name:"external-link",className:"size-3.5"})]})]}),M==="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:()=>{Ie(_h)},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(Q=>Q.value===M)?.labelKey??"settings.openchamber.tunnel.option.mode.quick.label")})})]})]})}),M==="managed-remote"&&s.jsxs("div",{className:"space-y-1.5",children:[s.jsx("p",{className:It,children:t("settings.openchamber.tunnel.field.managedRemoteTunnelToConnect")}),s.jsxs(At,{value:W||(P[0]?.id??""),onValueChange:Q=>{Ue(Q)},disabled:E||n==="starting"||n==="stopping"||P.length<=1,children:[s.jsx(Et,{size:$t,children:s.jsx(Ft,{placeholder:t("settings.openchamber.tunnel.field.selectSavedTunnelPlaceholder"),children:Ke?.name})}),s.jsx(Tt,{fitContent:!0,children:P.map(Q=>s.jsx(ot,{value:Q.id,children:Q.name},Q.id))})]})]}),ve&&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:ft,disabled:n==="starting"||E||M==="managed-remote"&&!Ke||M==="managed-local"&&Ge,className:we(yt,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")})]})]}),ye&&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})]}),ie&&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:vt,className:"shrink-0 gap-1.5",children:[C?s.jsx(L,{name:"check",className:"size-3.5 text-[var(--status-success)]"}):s.jsx(L,{name:"file-copy",className:"size-3.5"}),t(C?"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?Ne: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:ft,disabled:n==="stopping"||E||M==="managed-local"&&Ge,className:yt,children:[s.jsx(L,{name:"restart",className:"size-3.5"}),t("settings.openchamber.tunnel.actions.newConnectLink")]}),s.jsx(B,{size:"sm",variant:"ghost",onClick:kt,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:ft,children:t("settings.openchamber.tunnel.actions.retry")})]})]})})},Ql=()=>{const{t}=nt(),[e,a]=Qe.useState(""),[n,i]=Qe.useState(!0),[r,l]=Qe.useState(!1),u=de(c=>c.showOpenCodeUpdateNotifications),g=de(c=>c.setShowOpenCodeUpdateNotifications);Qe.useEffect(()=>{let c=!1;return(async()=>{try{const N=await rt("/api/config/settings",{method:"GET",headers:{Accept:"application/json"}});if(!N.ok)return;const b=await N.json().catch(()=>null);if(c||!b)return;const C=typeof b.opencodeBinary=="string"?b.opencodeBinary.trim():"";a(C)}catch{}finally{c||i(!1)}})(),()=>{c=!0}},[]);const x=Qe.useCallback(async()=>{if(!(typeof window>"u")&&ds())try{const c=await wl();c.success&&c.path&&c.path.trim().length>0&&a(c.path.trim())}catch{}},[]),d=Qe.useCallback(async()=>{l(!0);try{const c=e.trim(),N=c.length>=2&&(c.startsWith('"')&&c.endsWith('"')||c.startsWith("'")&&c.endsWith("'"))?c.slice(1,-1).trim():c;await xt({opencodeBinary:N}),Fn("cli",{id:"opencode-binary"}),D.success(t("settings.view.pendingRestart.saved"))}finally{l(!1)}},[t,e]),v=Qe.useCallback(c=>{g(c),xt({showOpenCodeUpdateNotifications:c})},[g]);return s.jsx($e,{title:t("settings.openchamber.opencodeCli.title"),children:s.jsxs("div",{className:"space-y-0.5",children:[s.jsxs(Vt,{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(We,{value:e,onChange:c=>a(c.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||!ds(),className:hs,"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(Fa,{className:fs,children:[!kl()&&s.jsx(pt,{settingsItem:"sessions.opencode-update-notifications",checked:u,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:d,disabled:n||r,className:"shrink-0 !font-normal",children:t(r?"settings.common.actions.saving":"settings.common.actions.saveChanges")})})]})]})})},Yl=()=>{const t=lt.c(44),{t:e}=nt(),a=de(Qh),n=de(Yh),i=de(Xh),r=de(Zh),l=de(ef),u=de(tf),g=de(sf);let x;t[0]!==n?(x=M=>{n(M),xt({agentControlToolEnabled:M}),Fn("cli",{id:"agent-control-tool"})},t[0]=n,t[1]=x):x=t[1];const d=x;let v;t[2]!==r?(v=M=>{r(M),xt({agentWebToolEnabled:M}),Fn("cli",{id:"agent-web-tool"})},t[2]=r,t[3]=v):v=t[3];const c=v;let N;t[4]!==g?(N=M=>{g(M),xt({agentMemoryToolEnabled:M}).finally(()=>{M&&Wc.getState().refresh()}),Fn("cli",{id:"agent-memory-tool"})},t[4]=g,t[5]=N):N=t[5];const b=N;let C;t[6]!==e?(C=e("settings.openchamber.tools.title"),t[6]=e,t[7]=C):C=t[7];let k;t[8]!==e?(k=e("settings.openchamber.tools.field.agentControlTool"),t[8]=e,t[9]=k):k=t[9];let A;t[10]!==e?(A=e("settings.openchamber.tools.field.agentControlToolAria"),t[10]=e,t[11]=A):A=t[11];let h;t[12]!==e?(h=e("settings.openchamber.tools.field.agentControlToolInfo"),t[12]=e,t[13]=h):h=t[13];let E;t[14]!==a||t[15]!==d||t[16]!==k||t[17]!==A||t[18]!==h?(E=s.jsx(pt,{settingsItem:"sessions.agent-control-tool",checked:a,onChange:d,label:k,ariaLabel:A,info:h}),t[14]=a,t[15]=d,t[16]=k,t[17]=A,t[18]=h,t[19]=E):E=t[19];let F;t[20]!==e?(F=e("settings.openchamber.tools.field.agentWebTool"),t[20]=e,t[21]=F):F=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]!==c||t[28]!==w||t[29]!==F||t[30]!==I?(m=s.jsx(pt,{settingsItem:"sessions.agent-web-tool",checked:i,onChange:c,label:F,ariaLabel:I,info:w}),t[26]=i,t[27]=c,t[28]=w,t[29]=F,t[30]=I,t[31]=m):m=t[31];let y;t[32]!==u||t[33]!==l||t[34]!==b||t[35]!==e?(y=u?s.jsx(pt,{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]=u,t[33]=l,t[34]=b,t[35]=e,t[36]=y):y=t[36];let U;t[37]!==m||t[38]!==y||t[39]!==E?(U=s.jsxs("div",{className:fs,children:[E,m,y]}),t[37]=m,t[38]=y,t[39]=E,t[40]=U):U=t[40];let S;return t[41]!==U||t[42]!==C?(S=s.jsx($e,{title:C,children:U}),t[41]=U,t[42]=C,t[43]=S):S=t[43],S};function Qh(t){return t.agentControlToolEnabled}function Yh(t){return t.setAgentControlToolEnabled}function Xh(t){return t.agentWebToolEnabled}function Zh(t){return t.setAgentWebToolEnabled}function ef(t){return t.agentMemoryToolEnabled}function tf(t){return t.agentMemoryFeatureAvailable}function sf(t){return t.setAgentMemoryToolEnabled}const Xl=()=>{const{t}=nt(),e=ds()&&Ua(),a=e&&typeof window<"u"&&window.__OPENCHAMBER_PLATFORM__==="darwin",[n,i]=Qe.useState(!1),[r,l]=Qe.useState(!1),[u,g]=Qe.useState(""),[x,d]=Qe.useState(""),[v,c]=Qe.useState(!1),[N,b]=Qe.useState(!1),[C,k]=Qe.useState(null),[A,h]=Qe.useState(!0),[E,F]=Qe.useState(!1),[I,w]=Qe.useState(!1),[m,y]=Qe.useState(!1),[U,S]=Qe.useState(!1),[M,j]=Qe.useState(!1),[R,H]=Qe.useState(!1),[P,G]=Qe.useState(!1),[J,T]=Qe.useState(!0),[W,X]=Qe.useState(!0),[K,te]=Qe.useState(!1),[$,V]=Qe.useState(!1),[_,z]=Qe.useState(!1),[Z,Y]=Qe.useState(null),[se,ge]=Qe.useState(null);Qe.useEffect(()=>{if(!e){h(!1);return}let re=!1;return(async()=>{try{const fe=await rt("/api/config/settings",{method:"GET",headers:{Accept:"application/json"}});if(!fe.ok)throw new Error(t("settings.openchamber.desktopNetwork.error.loadFailed"));const Ee=await fe.json().catch(()=>null);if(re)return;const Be=Ee?.desktopLanAccessEnabled===!0,Ve=typeof Ee?.desktopUiPassword=="string"?Ee.desktopUiPassword:"";i(Be),l(Be),g(Ve),d(Ve),b(Ee?.desktopLanAccessActive===!0),k(typeof Ee?.desktopLanAccessBlockedReason=="string"?Ee.desktopLanAccessBlockedReason:null);const Ge=Ee?.desktopMacMenuBarEnabled!==!1;T(Ge),X(Ge),Y(null)}catch(fe){re||Y(fe instanceof Error?fe.message:t("settings.openchamber.desktopNetwork.error.loadFailed"))}finally{re||h(!1)}})(),()=>{re=!0}},[e,t]),Qe.useEffect(()=>{if(!e){w(!1);return}let re=!1;return(async()=>{const fe=await kd();re||(w(fe?.supported===!0),y(fe?.enabled===!0))})(),()=>{re=!0}},[e]),Qe.useEffect(()=>{if(!e){j(!1);return}let re=!1;return(async()=>{const fe=await Nd();re||(j(fe?.supported===!0),H(fe?.enabled===!0))})(),()=>{re=!0}},[e]),Qe.useEffect(()=>{if(!e){te(!1);return}let re=!1;return(async()=>{const fe=await Sd();re||(te(fe?.supported===!0),V(fe?.enabled===!0))})(),()=>{re=!0}},[e]),Qe.useEffect(()=>{if(!e||!r){ge(null);return}let re=!1;return(async()=>{const fe=await yl();re||ge(fe)})(),()=>{re=!0}},[r,e]);const ce=r!==n||x!==u||W!==J,be=Qe.useMemo(()=>{if(typeof window>"u")return null;const fe=Ka()||window.location.href;let Ee=0;try{Ee=Number(new URL(fe).port)}catch{Ee=Number(window.location.port)}return Number.isFinite(Ee)&&Ee>0?Ee:null},[]),ne=r&&N&&se&&be?`http://${se}:${be}`:null,ae=r&&!x.trim(),me=n&&!N&&C==="missing-password",Pe=A||E||!ce||ae,Ne=Qe.useCallback(re=>{d(re),re.trim()||l(!1)},[]),Se=Qe.useCallback(async()=>{if(!I||U)return;const re=!m;y(re),S(!0),Y(null);try{const fe=await Cd(re);if(!fe?.supported)throw new Error(t("settings.openchamber.desktopNetwork.error.launchAtLoginUnsupported"));y(fe.enabled)}catch(fe){y(!re),Y(fe instanceof Error?fe.message:t("settings.openchamber.desktopNetwork.error.launchAtLoginSaveFailed"))}finally{S(!1)}},[U,m,I,t]),je=Qe.useCallback(async()=>{if(!M||P)return;const re=!R;H(re),G(!0),Y(null);try{const fe=await Pd(re);if(!fe)throw new Error(t("settings.openchamber.desktopNetwork.error.minimizeToTraySaveFailed"));if(!fe.supported)throw new Error(t("settings.openchamber.desktopNetwork.error.minimizeToTrayUnsupported"));H(fe.enabled)}catch(fe){H(!re),Y(fe instanceof Error?fe.message:t("settings.openchamber.desktopNetwork.error.minimizeToTraySaveFailed"))}finally{G(!1)}},[P,R,M,t]),Me=Qe.useCallback(async()=>{if(!K||_)return;const re=!$;V(re),z(!0),Y(null);try{const fe=await Id(re);if(!fe?.supported)throw new Error(t("settings.openchamber.desktopNetwork.error.keepAwakeUnsupported"));V(fe.enabled)}catch(fe){V(!re),Y(fe instanceof Error?fe.message:t("settings.openchamber.desktopNetwork.error.keepAwakeSaveFailed"))}finally{z(!1)}},[_,$,K,t]),Re=Qe.useCallback(async()=>{if(ce){F(!0),Y(null);try{if(!(await rt("/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),g(x),T(W),!await Ad())throw new Error(t("settings.openchamber.desktopNetwork.error.savedRestartFailed"))}catch(re){Y(re instanceof Error?re.message:t("settings.openchamber.desktopNetwork.error.saveFailed")),F(!1)}}},[W,x,r,ce,t]);return e?s.jsx($e,{title:t("settings.openchamber.desktopNetwork.title"),children:s.jsxs("div",{className:"space-y-3",children:[I||a||M||K?s.jsxs("div",{className:fs,children:[I?s.jsx(pt,{settingsItem:"sessions.desktop-launch-at-login",checked:m,onChange:re=>{re!==m&&Se()},disabled:U,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(pt,{settingsItem:"sessions.desktop-mac-menu-bar",checked:W,onChange:X,disabled:A||E,label:t("settings.openchamber.desktopNetwork.field.macMenuBar"),info:t("settings.openchamber.desktopNetwork.field.macMenuBarDescription"),ariaLabel:t("settings.openchamber.desktopNetwork.field.macMenuBarAria")}):null,M?s.jsx(pt,{settingsItem:"sessions.desktop-minimize-to-tray",checked:R,onChange:re=>{re!==R&&je()},disabled:P,label:t("settings.openchamber.desktopNetwork.field.minimizeToTray"),info:t("settings.openchamber.desktopNetwork.field.minimizeToTrayDescription"),ariaLabel:t("settings.openchamber.desktopNetwork.field.minimizeToTrayAria")}):null,K?s.jsx(pt,{settingsItem:"sessions.desktop-keep-awake",checked:$,onChange:re=>{re!==$&&Me()},disabled:_,label:t("settings.openchamber.desktopNetwork.field.keepAwake"),info:t("settings.openchamber.desktopNetwork.field.keepAwakeDescription"),ariaLabel:t("settings.openchamber.desktopNetwork.field.keepAwakeAria")}):null]}):null,s.jsxs(Wt,{settingsItem:"sessions.desktop-ui-password",label:s.jsx("label",{htmlFor:"desktop-ui-password",children:t("settings.openchamber.desktopPassword.field.password")}),info:t("settings.openchamber.desktopPassword.field.passwordDescription"),children:[s.jsx(We,{id:"desktop-ui-password",type:v?"text":"password",className:"h-8 min-w-0 flex-1",value:x,onChange:re=>Ne(re.target.value),placeholder:t("settings.openchamber.desktopPassword.field.passwordPlaceholder"),disabled:A||E,required:r,"aria-invalid":ae}),s.jsx(B,{type:"button",variant:"ghost",size:"xs",onClick:()=>c(re=>!re),className:hs,"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:fs,children:s.jsx(pt,{settingsItem:"sessions.desktop-lan-access",checked:r,onChange:l,disabled:A||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")}),ae||me?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")})}),Z?s.jsx("div",{className:"typography-micro text-[var(--status-error)]",children:Z}):null,ne?s.jsxs("div",{className:"typography-micro text-muted-foreground/80",children:[t(ce&&!n?"settings.openchamber.desktopNetwork.hint.openAfterRestart":"settings.openchamber.desktopNetwork.hint.openNow"),s.jsx("span",{className:"font-mono text-foreground",children:ne})]}):null,s.jsx("div",{className:"flex justify-start py-1.5",children:s.jsx(B,{type:"button",size:"xs",onClick:Re,disabled:Pe,className:"shrink-0 !font-normal",children:t(E?"settings.common.actions.saving":"settings.openchamber.desktopNetwork.actions.saveAndRestart")})})]})}):null},Zl=new Set(["shift","control","alt","meta"]),wr=3,nf=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 af(t){return t.action.customizable}function Yo(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?mi(e.join("+")):null}function rf(t){if(Zl.has(t.key.toLowerCase())||kr(t,!0)>wr)return null;const e=Yc(Xc(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),mi(a.join("+"))}function of(t){const e=t.key.toLowerCase();if(!Zl.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?mi(a.join("+")):null}function Xo(t){return t.chords.length>0?{...t,livePreview:null,settled:!0}:t}function lf(t,e,a){if(e.repeat||e.isComposing)return t;if(a==="keyup")return{...t,livePreview:Yo(e)};if(e.key==="Backspace")return{chords:t.chords.slice(0,-1),livePreview:null,settled:!1};const n=rf(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:Yo(e)}}const cf=t=>{const e=lt.c(117),{action:a,overrides:n,onSave:i,onOpenChange:r}=t,{t:l}=nt();let u;e[0]!==l?(u=ae=>l(ae.settingsLabelKey),e[0]=l,e[1]=u):u=e[1];const g=u;let x;e[2]!==g?(x=ae=>ae.action.customizable?g(ae.action):zn(ae.action.defaultBinding),e[2]=g,e[3]=x):x=e[3];const d=x;let v;e[4]===Symbol.for("react.memo_cache_sentinel")?(v={chords:[],livePreview:null,settled:!1},e[4]=v):v=e[4];const[c,N]=o.useState(v),b=o.useRef(null);let C,k;e[5]!==a?(C=()=>{a&&(N({chords:[],livePreview:null,settled:!1}),b.current?.focus())},k=[a],e[5]=a,e[6]=C,e[7]=k):(C=e[6],k=e[7]),o.useEffect(C,k);const A=c.chords.length===1&&!c.settled;let h,E;e[8]!==A?(h=()=>{if(!A)return;const ae=window.setTimeout(()=>N(Xo),nf);return()=>window.clearTimeout(ae)},E=[A],e[8]=A,e[9]=h,e[10]=E):(h=e[9],E=e[10]),o.useEffect(h,E);let F;e[11]!==c.chords?(F=mi(c.chords.join(" ")),e[11]=c.chords,e[12]=F):F=e[12];const I=F;let w;e[13]!==a||e[14]!==I||e[15]!==n?(w=a&&I?Jc(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(df),e[17]=m,e[18]=y):y=e[18];const U=y;let S,M,j,R,H,P,G,J,T,W,X,K,te,$,V;if(e[19]!==a||e[20]!==g||e[21]!==I||e[22]!==d||e[23]!==m||e[24]!==r||e[25]!==i||e[26]!==U||e[27]!==c||e[28]!==l){const ae=m.filter(af);H=ae.find(pf);const me=ae.find(mf),Pe=m.find(uf);let Ne;e[44]!==r?(Ne=()=>r(!1),e[44]=r,e[45]=Ne):Ne=e[45],j=Ne,R=()=>{c.settled||N(Xo),!(!a||!I||U||H)&&(i(a.id,I,me?.action.id),j())};let Se;e[46]!==a||e[47]!==c?(Se=(ye,ve)=>{ye.preventDefault(),ye.stopPropagation();const Oe=!!(a&&"prefixStyle"in a&&a.prefixStyle);if(ve==="keyup"&&Oe&&c.chords.length===0){const xe=of(ye);if(xe){N({chords:[xe],livePreview:null,settled:!0});return}}const Te=lf(c,{altKey:ye.altKey,code:ye.nativeEvent.code,ctrlKey:ye.ctrlKey,isComposing:ye.nativeEvent.isComposing,key:ye.key,metaKey:ye.metaKey,repeat:ye.repeat,shiftKey:ye.shiftKey},ve);N(Oe&&Te.chords.length>1?c:Te)},e[46]=a,e[47]=c,e[48]=Se):Se=e[48];const je=Se;M=Rt,$=a!==null,V=gf,S=Ot,P="max-w-md",G=b,J=!1;let Me;e[49]!==a||e[50]!==g||e[51]!==l?(Me=a?l("settings.openchamber.keyboardShortcuts.dialog.title",{action:g(a)}):"",e[49]=a,e[50]=g,e[51]=l,e[52]=Me):Me=e[52];let Re;e[53]!==Me?(Re=s.jsx(Ut,{children:Me}),e[53]=Me,e[54]=Re):Re=e[54];let re;e[55]!==l?(re=l("settings.openchamber.keyboardShortcuts.dialog.instructions"),e[55]=l,e[56]=re):re=e[56];let fe;e[57]!==re?(fe=s.jsx(zt,{children:re}),e[57]=re,e[58]=fe):fe=e[58],e[59]!==Re||e[60]!==fe?(T=s.jsxs(Kt,{children:[Re,fe]}),e[59]=Re,e[60]=fe,e[61]=T):T=e[61];let Ee,Be;e[62]!==je?(Ee=ye=>je(ye,"keydown"),Be=ye=>je(ye,"keyup"),e[62]=je,e[63]=Ee,e[64]=Be):(Ee=e[63],Be=e[64]);let Ve;e[65]===Symbol.for("react.memo_cache_sentinel")?(Ve=()=>N(hf),e[65]=Ve):Ve=e[65];let Ge;e[66]!==c.chords?(Ge=c.chords.map(ff),e[66]=c.chords,e[67]=Ge):Ge=e[67];let Ke;e[68]!==c.livePreview?(Ke=c.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:zn(c.livePreview)}):null,e[68]=c.livePreview,e[69]=Ke):Ke=e[69];let oe;e[70]!==c.chords.length||e[71]!==c.livePreview||e[72]!==l?(oe=c.chords.length===0&&!c.livePreview?s.jsx("span",{className:"typography-ui-label text-muted-foreground",children:l("settings.openchamber.keyboardShortcuts.dialog.recording")}):null,e[70]=c.chords.length,e[71]=c.livePreview,e[72]=l,e[73]=oe):oe=e[73];let ie;e[74]!==Ge||e[75]!==Ke||e[76]!==oe?(ie=s.jsxs("div",{className:"flex flex-wrap items-center justify-center gap-2",children:[Ge,Ke,oe]}),e[74]=Ge,e[75]=Ke,e[76]=oe,e[77]=ie):ie=e[77],e[78]!==Ee||e[79]!==Be||e[80]!==ie?(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:Ee,onKeyUp:Be,onBlur:Ve,children:ie}),e[78]=Ee,e[79]=Be,e[80]=ie,e[81]=W):W=e[81],X=c.settled&&U?s.jsx("p",{className:"typography-meta text-[var(--status-error)]",children:l("settings.openchamber.keyboardShortcuts.error.internalConflict")}):c.settled&&H?s.jsx("p",{className:"typography-meta text-[var(--status-error)]",children:l("settings.openchamber.keyboardShortcuts.error.prefixConflict",{action:g(H.action)})}):null,K=c.settled&&me&&!U&&!H?s.jsx("p",{className:"typography-meta text-[var(--status-warning)]",children:l("settings.openchamber.keyboardShortcuts.error.exactConflict",{action:g(me.action)})}):null,te=c.settled&&Pe&&!U&&!H?s.jsx("p",{className:"typography-meta text-[var(--status-warning)]",children:l("settings.openchamber.keyboardShortcuts.warning.contextualPrefix",{action:d(Pe)})}):null,e[19]=a,e[20]=g,e[21]=I,e[22]=d,e[23]=m,e[24]=r,e[25]=i,e[26]=U,e[27]=c,e[28]=l,e[29]=S,e[30]=M,e[31]=j,e[32]=R,e[33]=H,e[34]=P,e[35]=G,e[36]=J,e[37]=T,e[38]=W,e[39]=X,e[40]=K,e[41]=te,e[42]=$,e[43]=V}else S=e[29],M=e[30],j=e[31],R=e[32],H=e[33],P=e[34],G=e[35],J=e[36],T=e[37],W=e[38],X=e[39],K=e[40],te=e[41],$=e[42],V=e[43];let _;e[82]!==I||e[83]!==c.settled||e[84]!==l?(_=c.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]=c.settled,e[84]=l,e[85]=_):_=e[85];let z;e[86]!==l?(z=l("settings.common.actions.cancel"),e[86]=l,e[87]=z):z=e[87];let Z;e[88]!==j||e[89]!==z?(Z=s.jsx(B,{type:"button",variant:"ghost",size:"sm",onClick:j,children:z}),e[88]=j,e[89]=z,e[90]=Z):Z=e[90];const Y=!I||c.settled&&(!!U||!!H);let se;e[91]!==l?(se=l("settings.openchamber.keyboardShortcuts.actions.confirm"),e[91]=l,e[92]=se):se=e[92];let ge;e[93]!==R||e[94]!==Y||e[95]!==se?(ge=s.jsx(B,{type:"button",size:"sm",disabled:Y,onClick:R,children:se}),e[93]=R,e[94]=Y,e[95]=se,e[96]=ge):ge=e[96];let ce;e[97]!==Z||e[98]!==ge?(ce=s.jsxs(es,{children:[Z,ge]}),e[97]=Z,e[98]=ge,e[99]=ce):ce=e[99];let be;e[100]!==S||e[101]!==P||e[102]!==G||e[103]!==J||e[104]!==T||e[105]!==W||e[106]!==X||e[107]!==K||e[108]!==te||e[109]!==_||e[110]!==ce?(be=s.jsxs(S,{className:P,initialFocus:G,showCloseButton:J,children:[T,W,X,K,te,_,ce]}),e[100]=S,e[101]=P,e[102]=G,e[103]=J,e[104]=T,e[105]=W,e[106]=X,e[107]=K,e[108]=te,e[109]=_,e[110]=ce,e[111]=be):be=e[111];let ne;return e[112]!==M||e[113]!==$||e[114]!==V||e[115]!==be?(ne=s.jsx(M,{open:$,onOpenChange:V,children:be}),e[112]=M,e[113]=$,e[114]=V,e[115]=be,e[116]=ne):ne=e[116],ne};function df(t){return!t.action.customizable&&t.kind!=="contextual-prefix"}function pf(t){return t.kind==="prefix"}function mf(t){return t.kind==="exact"}function uf(t){return t.kind==="contextual-prefix"}function gf(t,e){t||e.cancel()}function hf(t){return{...t,livePreview:null}}function ff(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:zn(t)},`${t}-${e}`)}const xf=["session","models","panels","navigation","application"],bf=()=>{const t=lt.c(24),{t:e}=nt(),a=de(vf),n=de(yf),i=de(jf),r=de(wf),[l,u]=o.useState(null);let g;if(t[0]===Symbol.for("react.memo_cache_sentinel")){const I=Zc();g=ps()?I.filter(kf):I,t[0]=g}else g=t[0];const x=g,d=Nf;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),d(y)},t[1]=n,t[2]=a,t[3]=v):v=t[3];const c=v;let N;t[4]!==i||t[5]!==a?(N=I=>{const w={...a};delete w[I],i(I),d(w)},t[4]=i,t[5]=a,t[6]=N):N=t[6];const b=N;let C;t[7]!==a||t[8]!==e?(C=I=>{const w="prefixStyle"in I&&I.prefixStyle,m=w?ed(I.id,a):bl(I.id,a),y=zn(m,e("settings.openchamber.keyboardShortcuts.unassigned"));if(!w||!m||m===Ti)return y;const U=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}${U}`},t[7]=a,t[8]=e,t[9]=C):C=t[9];const k=C;let A;t[10]!==r||t[11]!==b||t[12]!==k||t[13]!==a||t[14]!==e?(A=xf.map((I,w)=>{const m=x.filter(y=>y.category===I);return m.length===0?null:s.jsx($e,{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(),d({})},children:e("settings.openchamber.keyboardShortcuts.actions.resetAll")}):void 0,children:s.jsx("div",{className:"space-y-2",children:m.map(y=>s.jsxs(Vt,{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:k(y)}),s.jsx(B,{type:"button",variant:"secondary",size:"xs",className:"!font-normal",onClick:()=>u(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]=k,t[13]=a,t[14]=e,t[15]=A):A=t[15];let h;t[16]===Symbol.for("react.memo_cache_sentinel")?(h=I=>{I||u(null)},t[16]=h):h=t[16];let E;t[17]!==l||t[18]!==c||t[19]!==a?(E=s.jsx(cf,{action:l,overrides:a,onSave:c,onOpenChange:h}),t[17]=l,t[18]=c,t[19]=a,t[20]=E):E=t[20];let F;return t[21]!==A||t[22]!==E?(F=s.jsxs(s.Fragment,{children:[A,E]}),t[21]=A,t[22]=E,t[23]=F):F=t[23],F};function vf(t){return t.shortcutOverrides}function yf(t){return t.setShortcutOverride}function jf(t){return t.clearShortcutOverride}function wf(t){return t.resetAllShortcutOverrides}function kf(t){return t.id!=="toggle_prompt_navigator"}function Nf(t){xt({shortcutOverrides:t})}const ec=()=>{const t=lt.c(2),[e,a]=o.useState(0);let n,i;return t[0]===Symbol.for("react.memo_cache_sentinel")?(n=()=>jl(()=>a(Lf)),i=[],t[0]=n,t[1]=i):(n=t[0],i=t[1]),o.useEffect(n,i),e},Sf=t=>{const e=lt.c(80),{section:a}=t,{t:n}=nt(),{isMobile:i}=da();ec();let r;e[0]!==i?(r=i&&Kn(),e[0]=i,e[1]=r):r=e[1];const l=r;let u;e[2]===Symbol.for("react.memo_cache_sentinel")?(u=ps(),e[2]=u):u=e[2];const g=u;let x;e[3]===Symbol.for("react.memo_cache_sentinel")?(x=ds()&&Ua(),e[3]=x):x=e[3];const d=x;if(!a){let K,te,$,V,_,z,Z,Y;e[4]===Symbol.for("react.memo_cache_sentinel")?($=s.jsx(ui,{}),V=s.jsx(ql,{}),_=d&&s.jsx(Xl,{}),z=!g&&s.jsx(Ql,{}),Z=!g&&s.jsx(Yl,{}),Y=s.jsx(Bl,{}),K=s.jsx(Gl,{}),te=Kn()&&!ds()&&!g&&!Nl()&&s.jsx(Hl,{}),e[4]=K,e[5]=te,e[6]=$,e[7]=V,e[8]=_,e[9]=z,e[10]=Z,e[11]=Y):(K=e[4],te=e[5],$=e[6],V=e[7],_=e[8],z=e[9],Z=e[10],Y=e[11]);let se;e[12]!==l?(se=l&&s.jsx(Il,{}),e[12]=l,e[13]=se):se=e[13];let ge;return e[14]!==se?(ge=s.jsxs(ns,{showSaveStatus:!0,className:"openchamber-page-body space-y-3 sm:space-y-6",children:[$,V,_,z,Z,Y,K,te,se]}),e[14]=se,e[15]=ge):ge=e[15],ge}let v;e[16]!==a?(v=()=>{switch(a){case"general":return s.jsx(Pf,{});case"visual":return s.jsx(If,{});case"chat":return s.jsx(Af,{});case"sessions":return s.jsx(Ef,{});case"shortcuts":return s.jsx(Cf,{});case"git":return s.jsx(Tf,{});case"github":return s.jsx(Df,{});case"notifications":return s.jsx(Mf,{});case"voice":return s.jsx(Rf,{});case"tunnel":return s.jsx(Of,{});default:return null}},e[16]=a,e[17]=v):v=e[17];const c=v;let N;e[18]!==n?(N=n("settings.page.general.title"),e[18]=n,e[19]=N):N=e[19];let b;e[20]!==n?(b=n("settings.page.appearance.title"),e[20]=n,e[21]=b):b=e[21];let C;e[22]!==n?(C=n("settings.page.chat.title"),e[22]=n,e[23]=C):C=e[23];let k;e[24]!==n?(k=n("settings.page.sessions.title"),e[24]=n,e[25]=k):k=e[25];let A;e[26]!==n?(A=n("settings.page.shortcuts.title"),e[26]=n,e[27]=A):A=e[27];let h;e[28]!==n?(h=n("settings.page.git.title"),e[28]=n,e[29]=h):h=e[29];let E;e[30]!==n?(E=n("settings.page.git.title"),e[30]=n,e[31]=E):E=e[31];let F;e[32]!==n?(F=n("settings.page.notifications.title"),e[32]=n,e[33]=F):F=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]!==h||e[39]!==E||e[40]!==F||e[41]!==I||e[42]!==w||e[43]!==N||e[44]!==b||e[45]!==C||e[46]!==k||e[47]!==A?(m={general:N,visual:b,chat:C,sessions:k,shortcuts:A,git:h,github:E,notifications:F,voice:I,tunnel:w},e[38]=h,e[39]=E,e[40]=F,e[41]=I,e[42]=w,e[43]=N,e[44]=b,e[45]=C,e[46]=k,e[47]=A,e[48]=m):m=e[48];const y=m[a];let U;e[49]!==n?(U=n("settings.page.general.description"),e[49]=n,e[50]=U):U=e[50];let S;e[51]!==n?(S=n("settings.page.appearance.description"),e[51]=n,e[52]=S):S=e[52];let M;e[53]!==n?(M=n("settings.page.chat.description"),e[53]=n,e[54]=M):M=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 H;e[59]!==n?(H=n("settings.page.notifications.description"),e[59]=n,e[60]=H):H=e[60];let P;e[61]!==n?(P=n("settings.page.voice.description"),e[61]=n,e[62]=P):P=e[62];let G;e[63]!==n?(G=n("settings.page.tunnel.description"),e[63]=n,e[64]=G):G=e[64];let J;e[65]!==U||e[66]!==S||e[67]!==M||e[68]!==j||e[69]!==R||e[70]!==H||e[71]!==P||e[72]!==G?(J={general:U,visual:S,chat:M,sessions:j,shortcuts:R,git:void 0,github:void 0,notifications:H,voice:P,tunnel:G},e[65]=U,e[66]=S,e[67]=M,e[68]=j,e[69]=R,e[70]=H,e[71]=P,e[72]=G,e[73]=J):J=e[73];const T=J[a];let W;e[74]!==c?(W=c(),e[74]=c,e[75]=W):W=e[75];let X;return e[76]!==T||e[77]!==y||e[78]!==W?(X=s.jsx(ns,{title:y,description:T,showSaveStatus:!0,className:"openchamber-page-body",children:W}),e[76]=T,e[77]=y,e[78]=W,e[79]=X):X=e[79],X},Cf=()=>{const t=lt.c(1);let e;return t[0]===Symbol.for("react.memo_cache_sentinel")?(e=s.jsx(bf,{}),t[0]=e):e=t[0],e},Pf=()=>{const t=lt.c(10);let e;t[0]===Symbol.for("react.memo_cache_sentinel")?(e=ps(),t[0]=e):e=t[0];const a=e;ec();let n;t[1]===Symbol.for("react.memo_cache_sentinel")?(n=ds()&&Ua(),t[1]=n):n=t[1];const i=n;let r;t[2]===Symbol.for("react.memo_cache_sentinel")?(r=Kn()&&!ds()&&!a&&!Nl(),t[2]=r):r=t[2];const l=r;let u,g,x,d,v;t[3]===Symbol.for("react.memo_cache_sentinel")?(u=i&&s.jsx(Xl,{}),g=l&&s.jsx(Hl,{}),x=s.jsx(Gl,{}),d=!a&&s.jsx(Ql,{}),v=!a&&s.jsx(Yl,{}),t[3]=u,t[4]=g,t[5]=x,t[6]=d,t[7]=v):(u=t[3],g=t[4],x=t[5],d=t[6],v=t[7]);let c;t[8]===Symbol.for("react.memo_cache_sentinel")?(c=a?[]:["sessionTabs"],t[8]=c):c=t[8];let N;return t[9]===Symbol.for("react.memo_cache_sentinel")?(N=s.jsxs(s.Fragment,{children:[u,g,x,d,v,s.jsx(ui,{visibleSettings:["fileEditorKeymap",...c,"autoSaveEnabled",...a?[]:["terminalQuickKeys"],...a?[]:["terminalShell"],...a?[]:["terminalLoginShell"],"messageTransport","reportUsage"]})]}),t[9]=N):N=t[9],N},If=()=>{const t=lt.c(2);let e;t[0]===Symbol.for("react.memo_cache_sentinel")?(e=ps(),t[0]=e):e=t[0];const a=e;let n;return t[1]===Symbol.for("react.memo_cache_sentinel")?(n=s.jsx(ui,{visibleSettings:["theme","windowControlsPosition","pwaInstallName","pwaOrientation","mobileKeyboardMode","timeFormat",...a?[]:["weekStart"],"fontSize","terminalFontSize","editorFontSize","spacing","inputBarOffset"]}),t[1]=n):n=t[1],n},Af=()=>{const t=lt.c(2);let e;t[0]===Symbol.for("react.memo_cache_sentinel")?(e=ps(),t[0]=e):e=t[0];const a=e;let n;return t[1]===Symbol.for("react.memo_cache_sentinel")?(n=s.jsx(ui,{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","largeTextPaste"]}),t[1]=n):n=t[1],n},Ef=()=>{const t=lt.c(1);let e;return t[0]===Symbol.for("react.memo_cache_sentinel")?(e=s.jsxs(s.Fragment,{children:[s.jsx(ql,{}),s.jsx(Bl,{})]}),t[0]=e):e=t[0],e},Tf=()=>{const t=lt.c(1);let e;return t[0]===Symbol.for("react.memo_cache_sentinel")?(e=s.jsx($l,{}),t[0]=e):e=t[0],e},Df=()=>{const t=lt.c(1);if(ps())return null;let e;return t[0]===Symbol.for("react.memo_cache_sentinel")?(e=s.jsx(Vl,{}),t[0]=e):e=t[0],e},Mf=()=>{const t=lt.c(1);let e;return t[0]===Symbol.for("react.memo_cache_sentinel")?(e=s.jsx(Rh,{}),t[0]=e):e=t[0],e},Rf=()=>{const t=lt.c(1);if(ps())return null;let e;return t[0]===Symbol.for("react.memo_cache_sentinel")?(e=s.jsx(Uh,{}),t[0]=e):e=t[0],e},Of=()=>{const t=lt.c(1);if(ps())return null;let e;return t[0]===Symbol.for("react.memo_cache_sentinel")?(e=s.jsx(Jh,{}),t[0]=e):e=t[0],e};function Lf(t){return t+1}const Ff=t=>{const e=lt.c(85),{className:a}=t,{t:n}=nt(),i=gn(vl),r=gn(Kf),l=de(Uf),u=de(zf),[g,x]=Qe.useState(!1),[d,v]=Qe.useState(!1),c=i>0;let N;e[0]!==n?(N=async()=>{try{const Ne=await td({message:n("settings.view.pendingRestart.applying")});if(Ne.requiresManualRestart){D.warning(n("settings.view.pendingRestart.manualRestartRequired"));return}Ne.ok&&D.success(n("settings.view.pendingRestart.applied"))}catch(Ne){const Se=Ne,je=Se instanceof Error&&Se.message?Se.message:n("settings.view.pendingRestart.applyFailed");D.error(je)}},e[0]=n,e[1]=N):N=e[1];const b=N;let C;e[2]!==n?(C=async()=>{try{await hl({message:n("settings.view.pendingRestart.applying"),mode:"projects",scopes:["all"]}),gn.getState().clear()}catch{}},e[2]=n,e[3]=C):C=e[3];const k=C;let A;e[4]!==d||e[5]!==b||e[6]!==u?(A=()=>{d&&u(!1),x(!1),v(!1),b()},e[4]=d,e[5]=b,e[6]=u,e[7]=A):A=e[7];const h=A;let E;e[8]!==c||e[9]!==b||e[10]!==k||e[11]!==l?(E=()=>{if(!c){k();return}if(l){v(!1),x(!0);return}b()},e[8]=c,e[9]=b,e[10]=k,e[11]=l,e[12]=E):E=e[12];const F=E;let I;e[13]!==c||e[14]!==r||e[15]!==n?(I=n(c?r?"settings.view.pendingRestart.applying":"settings.view.actions.applyAndRestartOpenCode":"settings.view.actions.reloadOpenCode"),e[13]=c,e[14]=r,e[15]=n,e[16]=I):I=e[16];const w=I;let m;e[17]!==c||e[18]!==i||e[19]!==n?(m=c?i===1?n("settings.view.actions.applyAndRestartOpenCodeTooltipSingle"):n("settings.view.actions.applyAndRestartOpenCodeTooltipPlural",{count:i}):n("settings.view.actions.reloadOpenCodeTooltip"),e[17]=c,e[18]=i,e[19]=n,e[20]=m):m=e[20];const y=m,U=c?"bg-primary text-primary-foreground typography-ui-label font-semibold hover:bg-primary/90":"text-sm font-semibold text-sidebar-foreground/90 hover:text-sidebar-foreground hover:bg-interactive-hover",S=r&&"opacity-80";let M;e[21]!==a||e[22]!==U||e[23]!==S?(M=we("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",U,S,a),e[21]=a,e[22]=U,e[23]=S,e[24]=M):M=e[24];let j;e[25]!==c||e[26]!==i?(j=c?s.jsx("span",{className:we("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]=c,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 H;e[30]!==F||e[31]!==r||e[32]!==j||e[33]!==R||e[34]!==M||e[35]!==y?(H=s.jsxs("button",{type:"button",disabled:r,title:y,"aria-label":y,onClick:F,className:M,children:[j,R]}),e[30]=F,e[31]=r,e[32]=j,e[33]=R,e[34]=M,e[35]=y,e[36]=H):H=e[36];let P;e[37]===Symbol.for("react.memo_cache_sentinel")?(P=Ne=>{x(Ne),Ne||v(!1)},e[37]=P):P=e[37];let G;e[38]!==n?(G=n("settings.view.pendingRestart.confirm.title"),e[38]=n,e[39]=G):G=e[39];let J;e[40]!==G?(J=s.jsx(Ut,{children:G}),e[40]=G,e[41]=J):J=e[41];let T;e[42]!==n?(T=n("settings.view.pendingRestart.confirm.description"),e[42]=n,e[43]=T):T=e[43];let W;e[44]!==T?(W=s.jsx(zt,{children:T}),e[44]=T,e[45]=W):W=e[45];let X;e[46]!==J||e[47]!==W?(X=s.jsxs(Kt,{children:[J,W]}),e[46]=J,e[47]=W,e[48]=X):X=e[48];let K;e[49]===Symbol.for("react.memo_cache_sentinel")?(K={width:"40%"},e[49]=K):K=e[49];let te;e[50]===Symbol.for("react.memo_cache_sentinel")?(te=()=>x(!1),e[50]=te):te=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:K,children:s.jsx(B,{type:"button",variant:"outline",className:"h-9 w-full normal-case",onClick:te,children:$})}),e[53]=$,e[54]=V):V=e[54];let _;e[55]===Symbol.for("react.memo_cache_sentinel")?(_={width:"40%"},e[55]=_):_=e[55];let z;e[56]!==n?(z=n("settings.view.actions.applyAndRestartOpenCode"),e[56]=n,e[57]=z):z=e[57];let Z;e[58]!==h||e[59]!==z?(Z=s.jsx("div",{className:"min-w-0 shrink-0",style:_,children:s.jsx(B,{type:"button",variant:"default",className:"h-9 w-full normal-case",onClick:h,children:z})}),e[58]=h,e[59]=z,e[60]=Z):Z=e[60];let Y;e[61]!==V||e[62]!==Z?(Y=s.jsxs("div",{className:"flex w-full items-stretch justify-center gap-3",children:[V,Z]}),e[61]=V,e[62]=Z,e[63]=Y):Y=e[63];let se;e[64]===Symbol.for("react.memo_cache_sentinel")?(se=()=>v(_f),e[64]=se):se=e[64];let ge;e[65]!==d?(ge=d?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]=d,e[66]=ge):ge=e[66];let ce;e[67]!==n?(ce=n("settings.view.pendingRestart.confirm.dontShowAgain"),e[67]=n,e[68]=ce):ce=e[68];let be;e[69]!==d||e[70]!==ge||e[71]!==ce?(be=s.jsxs("button",{type:"button",onClick:se,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":d,children:[ge,ce]}),e[69]=d,e[70]=ge,e[71]=ce,e[72]=be):be=e[72];let ne;e[73]!==Y||e[74]!==be?(ne=s.jsxs("div",{className:"flex w-full flex-col items-center gap-3",children:[Y,be]}),e[73]=Y,e[74]=be,e[75]=ne):ne=e[75];let ae;e[76]!==X||e[77]!==ne?(ae=s.jsxs(Ot,{showCloseButton:!1,className:"max-w-md gap-5",children:[X,ne]}),e[76]=X,e[77]=ne,e[78]=ae):ae=e[78];let me;e[79]!==g||e[80]!==ae?(me=s.jsx(Rt,{open:g,onOpenChange:P,children:ae}),e[79]=g,e[80]=ae,e[81]=me):me=e[81];let Pe;return e[82]!==H||e[83]!==me?(Pe=s.jsxs(s.Fragment,{children:[H,me]}),e[82]=H,e[83]=me,e[84]=Pe):Pe=e[84],Pe};function Kf(t){return t.isApplying}function Uf(t){return t.showOpenCodeRestartConfirm}function zf(t){return t.setShowOpenCodeRestartConfirm}function _f(t){return!t}const $f=[{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","paste"]},{id:"chat.spellcheck",page:"chat",titleKey:"settings.openchamber.visual.field.enableSpellcheckInTextInputs",keywords:["spelling","input"],isAvailable:t=>!t.isMobile},{id:"chat.large-text-paste",page:"chat",titleKey:"settings.openchamber.visual.field.largeTextPaste",descriptionKey:"settings.openchamber.visual.field.largeTextPasteHint",keywords:["paste","clipboard","attachment","large","text","file"]},{id:"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&&de.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 Vf({query:t,runtimeCtx:e,visiblePageSlugs:a,t:n,getPageTitle:i}){const r=Zo(t);if(!r)return[];const l=a?new Set(a):null,u=r.split(/\s+/).filter(Boolean);return $f.flatMap(g=>{if(l&&!l.has(g.page))return[];const x=Ea(g.page);if(!x||x.isAvailable&&!x.isAvailable(e)||g.isAvailable&&!g.isAvailable(e))return[];const d=n(g.titleKey),v=g.descriptionKey?n(g.descriptionKey):null,c=Zo([d,v,i(g.page),...g.keywords??[]].filter(Boolean).join(" "));return u.every(N=>c.includes(N))?[{...g,title:d,description:v,pageTitle:i(g.page)}]:[]})}const el=256,tl=280,tc="__openchamberSettingsDetail",Bf=["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"],Hf=["general","projects","opencode","content"],Gf="__add_provider__";function qf(t,e){const a=ps(),n=!t&&Kn();return{isVSCode:a,isWeb:n,isDesktop:t,isMobile:e}}function sl(t,e){return t.isAvailable?t.isAvailable(e):!0}function lr(t){return typeof t=="object"&&t!==null&&!Array.isArray(t)}function Aa(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[tc];if(!lr(e))return null;const a=e.page,n=e.stage;return typeof a!="string"||n!=="page-content"?null:{page:Sl(a),stage:n}}function Wf(){return typeof window>"u"||!lr(window.history.state)?{}:window.history.state}const ix=({onClose:t,forceMobile:e,isWindowed:a,visiblePageSlugs:n,initialMobileStage:i="nav"})=>{const{t:r}=nt(),l=da(),u=e??l.isMobile,g=gn(vl),x=de(oe=>oe.settingsPage),d=de(oe=>oe.isSettingsDialogOpen),v=de(oe=>oe.setSettingsPage),c=de(oe=>oe.shortcutOverrides.open_settings),N=Sl(x),[b,C]=o.useState(i),k=o.useRef(i==="nav"?N:null);o.useEffect(()=>{!u&&N==="home"&&v("general")},[u,v,N]);const[A,h]=o.useState(""),[E,F]=o.useState(null),[I,w]=o.useState(0),m=o.useRef(null),y=o.useRef(!1),U=o.useRef([]),S=o.useRef(0),M=o.useRef(!1),j=o.useMemo(()=>ds(),[]),R=o.useMemo(()=>ds()&&Ua(),[]),H=o.useMemo(()=>ds()&&typeof window<"u"&&window.__OPENCHAMBER_PLATFORM__==="darwin",[]),P=o.useMemo(()=>ds()&&typeof window<"u"&&window.__OPENCHAMBER_PLATFORM__==="win32",[]),G=o.useMemo(()=>ds()&&typeof window<"u"&&window.__OPENCHAMBER_PLATFORM__==="linux",[]),J=o.useMemo(()=>kl(),[]),T=o.useMemo(()=>qf(j,u),[j,u]),W=o.useMemo(()=>{const oe=n?new Set(n):null;return Md.filter(ie=>ie.slug!=="home").filter(ie=>!oe||oe.has(ie.slug)).filter(ie=>sl(ie,T)).filter(ie=>!(T.isVSCode&&ie.slug==="projects")).filter(ie=>!(u&&ie.slug==="shortcuts"))},[T,u,n]),X=o.useMemo(()=>{const oe=new Map(Bf.map((ie,ye)=>[ie,ye]));return W.slice().sort((ie,ye)=>(oe.get(ie.slug)??999)-(oe.get(ye.slug)??999))},[W]),K=qs(oe=>oe.activeProjectId),te=zs();o.useEffect(()=>{if(!(!d&&!T.isVSCode&&!a)){if(N==="agents"){Un.getState().loadAgents(te);return}if(N==="commands"){la.getState().loadCommands(te);return}if(N==="mcp"){ca.getState().loadMcpConfigs({directory:te});return}if(N==="plugins"){rs.getState().loadPlugins();return}(N==="skills.installed"||N==="skills.catalog")&&($s.getState().loadSkills(te),mn.getState().loadCatalog()),N==="snippets"&&di.getState().loadSnippets()}},[K,d,a,T.isVSCode,te,N]);const $=o.useCallback(oe=>{if(v(oe),k.current=oe,!u)return;const ie=Ea(oe);if(!ie||ie.slug==="home"){C("nav");return}C(ie.kind==="split"?"page-sidebar":"page-content")},[u,v]),V=o.useCallback(async oe=>{const ie=et.getState();return await ie.loadProviders({source:"settings:third-party-provider-setup"}),et.getState().providers.some(ve=>ve.id===oe)?(ie.setSelectedProvider(oe),$("providers"),u&&C("page-content"),!0):!1},[u,$]),_=o.useMemo(()=>Ea(N),[N]),z=o.useMemo(()=>({general:"general",appearance:"visual",chat:"chat",shortcuts:"shortcuts",sessions:"sessions",notifications:"notifications",voice:"voice",tunnel:"tunnel"}),[]),Z=o.useCallback(oe=>{switch(oe){case"general":return r("settings.page.general.title");case"projects":return r("settings.page.projects.title");case"remote-instances":return r("settings.page.remoteInstances.title");case"providers":return r("settings.page.providers.title");case"usage":return r("settings.page.usage.title");case"agents":return r("settings.page.agents.title");case"behavior":return r("settings.page.behavior.title");case"commands":return r("settings.page.commands.title");case"mcp":return r("settings.page.mcp.title");case"plugins":return r("settings.page.plugins.title");case"skills.installed":return r("settings.page.skills.title");case"skills.catalog":return r("settings.page.skillsCatalog.title");case"git":return r("settings.page.git.title");case"integrations":return r("settings.page.integrations.title");case"appearance":return r("settings.page.appearance.title");case"chat":return r("settings.page.chat.title");case"shortcuts":return r("settings.page.shortcuts.title");case"sessions":return r("settings.page.sessions.title");case"magic-prompts":return r("settings.page.magicPrompts.title");case"snippets":return r("settings.page.snippets.title");case"notifications":return r("settings.page.notifications.title");case"voice":return r("settings.page.voice.title");case"tunnel":return r("settings.page.tunnel.title");case"about":return r("settings.page.about.title");default:return r("settings.view.home.title")}},[r]),Y=o.useMemo(()=>Vf({query:A,runtimeCtx:{...T,isDesktopLocalOrigin:R,isMac:H,isWindows:P,isLinux:G,isWindowsArm64:J},visiblePageSlugs:n,t:r,getPageTitle:Z}),[Z,J,R,H,P,G,T,A,r,n]),se=o.useCallback(oe=>{if(oe.id.startsWith("agents.")){const ie=Un.getState(),ye=Aa("new-agent",ie.agents.map(ve=>ve.name));return ie.setAgentDraft({name:ye,scope:"user"}),ie.setSelectedAgent(ye),oe.id==="agents.create"?"agents.name":oe.id}if(oe.id.startsWith("commands.")){const ie=la.getState(),ye=Aa("new-command",ie.commands.map(ve=>ve.name));return ie.setCommandDraft({name:ye,scope:"user"}),ie.setSelectedCommand(ye),oe.id==="commands.create"?"commands.name":oe.id}if(oe.id.startsWith("mcp.")){const ie=ca.getState(),ye=Aa("new-mcp-server",ie.mcpServers.map(ve=>ve.name));return ie.setMcpDraft({name:ye,scope:"user",type:"local",command:[],url:"",environment:[],headers:[],oauthEnabled:!0,oauthClientId:"",oauthClientSecret:"",oauthScope:"",oauthRedirectUri:"",timeout:"",enabled:!0}),ie.setSelectedMcp(ye),oe.id==="mcp.create"?"mcp.server":oe.id}if(oe.id.startsWith("snippets.")){const ie=di.getState(),ye=Aa("new-snippet",ie.snippets.map(ve=>ve.name));return ie.setSnippetDraft({name:ye,scope:"global"}),ie.setSelectedSnippet(ye),oe.id==="snippets.create"?"snippets.content":oe.id}if(oe.id.startsWith("skills.")){const ie=$s.getState(),ye=Aa("new-skill",ie.skills.map(ve=>ve.name));return ie.setSkillDraft({name:ye,scope:"user",source:"opencode",description:"",instructions:""}),ie.setSelectedSkill(ye),oe.id==="skills.create"?"skills.basic-information":oe.id}return oe.id==="providers.connect"&&et.getState().setSelectedProvider(Gf),oe.id==="plugins.create"?"plugins.spec":oe.id},[]),ge=o.useMemo(()=>{const oe=[],ie=new Map;for(const ye of Y){let ve=ie.get(ye.page);ve||(ve={page:ye.page,pageTitle:ye.pageTitle,results:[]},ie.set(ye.page,ve),oe.push(ve)),ve.results.push(ye)}return oe},[Y]);o.useEffect(()=>{w(0),S.current=0,M.current=!1},[A]),o.useEffect(()=>{S.current=I},[I]),o.useEffect(()=>{U.current[I]?.scrollIntoView({block:"nearest"})},[I]),o.useEffect(()=>{I>=Y.length&&w(Math.max(0,Y.length-1)),U.current.length=Y.length},[I,Y.length]);const ce=o.useCallback(oe=>{const ie=se(oe);F(ie),$(oe.page),u&&C("page-content"),oe.id==="plugins.create"&&typeof window<"u"&&window.setTimeout(()=>{window.dispatchEvent(new CustomEvent("openchamber:settings-open-plugin-add"))},50)},[u,$,se]),be=o.useCallback(oe=>{if(A.trim()){if(oe.key==="Escape"){oe.preventDefault(),h("");return}if(Y.length!==0){if(oe.key==="ArrowDown"){oe.preventDefault(),M.current=!0,w(ie=>(ie+1)%Y.length);return}if(oe.key==="ArrowUp"){oe.preventDefault(),M.current=!0,w(ie=>(ie-1+Y.length)%Y.length);return}if(oe.key==="Enter"){oe.preventDefault();const ie=(S.current%Y.length+Y.length)%Y.length,ye=Y[ie]??Y[0];ye&&ce(ye)}}}},[ce,A,Y]);o.useEffect(()=>{const oe=E;if(!oe)return;let ie=!1;const ye=window.requestAnimationFrame(()=>{if(ie)return;const ve=typeof CSS<"u"&&CSS.escape?CSS.escape(oe):oe.replace(/[^a-zA-Z0-9_-]/g,"\\$&"),Oe=m.current?.querySelector(`[data-settings-item="${ve}"]`);Oe&&(F(null),Oe.scrollIntoView({block:"center",behavior:"smooth"}),Oe.setAttribute("data-settings-search-highlight","true"),window.setTimeout(()=>{Oe.removeAttribute("data-settings-search-highlight")},1600))});return()=>{ie=!0,window.cancelAnimationFrame(ye)}},[E,N]);const ne=o.useCallback(()=>s.jsx("div",{className:"flex h-full items-center justify-center px-6",children:s.jsxs("div",{className:"max-w-md text-center",children:[s.jsx("div",{className:ul,children:r("settings.view.unavailable.title")}),s.jsx("p",{className:"typography-ui text-muted-foreground mt-1",children:r("settings.view.unavailable.description")})]})}),[r]),ae=o.useCallback((oe,ie)=>{switch(oe){case"projects":return s.jsx(fu,{onItemSelect:ie.onItemSelect});case"agents":return s.jsx(sp,{onItemSelect:ie.onItemSelect});case"commands":return s.jsx(vp,{onItemSelect:ie.onItemSelect});case"mcp":return s.jsx(Pp,{onItemSelect:ie.onItemSelect});case"plugins":return s.jsx(gm,{onItemSelect:ie.onItemSelect});case"skills.installed":return s.jsx(Im,{onItemSelect:ie.onItemSelect});case"providers":return s.jsx(Bu,{onItemSelect:ie.onItemSelect});case"usage":return s.jsx(Pg,{onItemSelect:ie.onItemSelect});case"magic-prompts":return s.jsx(Vg,{onItemSelect:ie.onItemSelect});case"snippets":return s.jsx(qg,{onItemSelect:ie.onItemSelect});default:return null}},[]),me=o.useCallback(oe=>{const ie=Ea(oe);if(ie&&!sl(ie,T))return ne();switch(oe){case"projects":return s.jsx(ju,{});case"remote-instances":return s.jsx(_u,{});case"agents":return s.jsx(up,{});case"behavior":return s.jsx(bp,{});case"commands":return s.jsx(Cp,{});case"mcp":return s.jsx(Jp,{});case"plugins":return s.jsx(Cm,{});case"skills.installed":return s.jsx(po,{view:"installed"});case"skills.catalog":return s.jsx(po,{view:"catalog"});case"providers":return s.jsx(Sg,{});case"usage":return s.jsx(_g,{});case"about":return s.jsx(ns,{title:r("settings.page.about.title"),showSaveStatus:!1,children:s.jsx(Il,{})});case"magic-prompts":return s.jsx(Gg,{});case"snippets":return s.jsx(Yg,{});case"git":return s.jsx(sh,{});case"integrations":return s.jsx(dh,{onOpenProviderSetup:V,onOpenPluginManager:()=>$("plugins")});case"general":case"appearance":case"chat":case"shortcuts":case"sessions":case"notifications":case"voice":case"tunnel":{const ye=z[oe]??"visual";return s.jsx(Sf,{section:ye})}default:return null}},[z,$,V,ne,T,r]);o.useEffect(()=>{if(!u||b!=="nav"||N==="home"||k.current===N)return;const oe=Ea(N);!oe||oe.slug==="home"||(k.current=N,C(oe.kind==="split"?"page-sidebar":"page-content"))},[u,b,N]);const Pe=u&&b!=="nav",Ne=u&&b==="page-content"&&N==="skills.installed",Se=b==="page-content"&&_?.kind==="split"&&!Ne,je=r(Ne?"settings.view.actions.back":Pe?"settings.view.actions.backToSettings":"settings.view.actions.closeSettings"),Me=bl("open_settings",c===void 0?void 0:{open_settings:c}),Re=Me?r("settings.view.actions.closeSettingsWithShortcut",{shortcut:zn(Me)}):r("settings.view.actions.closeSettings"),re=o.useCallback(oe=>{if(typeof window>"u"||T.isVSCode)return;const ie=Ji(window.history.state);ie?.page===oe&&ie.stage==="page-content"||window.history.pushState({...Wf(),[tc]:{page:oe,stage:"page-content"}},"",window.location.href)},[T.isVSCode]),fe=o.useCallback(()=>{y.current=!0,C("page-content"),N==="skills.installed"&&re(N)},[re,N]);o.useEffect(()=>{if(!u||b!=="page-content"||!y.current)return;y.current=!1;const oe=window.requestAnimationFrame(()=>{m.current?.querySelector("[data-settings-page-heading]")?.focus({preventScroll:!0})});return()=>{window.cancelAnimationFrame(oe)}},[u,b,N]);const Ee=o.useCallback(()=>{if(Ne){if((typeof window<"u"?Ji(window.history.state):null)?.page===N&&!T.isVSCode){window.history.back();return}C("page-sidebar");return}C("nav")},[Ne,T.isVSCode,N]);o.useEffect(()=>{if(!u||T.isVSCode)return;const oe=ie=>{if(N!=="skills.installed")return;if(Ji(ie.state)?.page==="skills.installed"){C("page-content");return}C(ve=>ve==="page-content"?"page-sidebar":ve)};return window.addEventListener("popstate",oe),()=>{window.removeEventListener("popstate",oe)}},[u,T.isVSCode,N]);const Be=o.useCallback(()=>{C("page-sidebar")},[]),Ve=()=>{const oe=A.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:A,onChange:ie=>h(ie.target.value),onKeyDown:be,placeholder:r("settings.view.search.placeholder"),"aria-label":r("settings.view.search.aria"),className:"typography-ui min-w-0 flex-1 bg-transparent text-foreground outline-none placeholder:text-muted-foreground/70"}),oe&&s.jsx("button",{type:"button",onClick:()=>h(""),"aria-label":r("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:oe?Y.length>0?(()=>{let ie=0;return ge.map(ye=>s.jsxs("div",{className:"space-y-0.5",children:[s.jsx("div",{className:"px-2 pb-0.5 pt-2 typography-micro font-medium text-muted-foreground/70",children:ye.pageTitle}),ye.results.map(ve=>{const Oe=ie;ie+=1;const Te=Oe===I,xe=!!ve.description;return s.jsxs("button",{type:"button",ref:He=>{U.current[Oe]=He},onMouseMove:()=>{M.current=!1,w(Oe)},onClick:()=>ce(ve),className:we("flex w-full flex-col rounded-md px-2 text-left focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-primary/50",xe?"min-h-11 py-1.5":"py-2",Te?"bg-interactive-selection":"hover:bg-interactive-hover"),children:[s.jsx("span",{className:"typography-ui-label text-foreground truncate",children:ve.title}),xe&&s.jsx("span",{className:"typography-micro text-muted-foreground/70 line-clamp-2",children:ve.description})]},ve.id)})]},ye.page))})():s.jsx("div",{className:"px-2 py-6 text-center typography-ui text-muted-foreground",children:r("settings.view.search.noResults")}):(()=>{const ie=new Map;for(const ve of X){const Oe=ve.group,Te=ie.get(Oe);Te?Te.push(ve):ie.set(Oe,[ve])}return Hf.map(ve=>({group:ve,pages:ie.get(ve)??[]})).filter(ve=>ve.pages.length>0).map(({group:ve,pages:Oe},Te)=>s.jsxs("div",{className:"space-y-0.5",children:[s.jsx("div",{className:we("px-3 pb-1 typography-micro font-semibold uppercase tracking-wide text-muted-foreground sm:px-2 sm:pb-0.5",Te===0?"pt-1":"pt-4 sm:pt-3"),children:r(`settings.view.nav.group.${ve}`)}),Oe.map(xe=>{const He=N===xe.slug&&!(u&&b==="nav"),ue=Rd(xe.slug);return!ue&&xe.slug!=="mcp"?null:s.jsx(pr,{children:s.jsx(mr,{asChild:!0,children:s.jsxs("button",{type:"button",onClick:()=>$(xe.slug),"aria-current":He?"page":void 0,className:we("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",He?"bg-interactive-selection text-foreground":"text-foreground hover:bg-interactive-hover"),children:[xe.slug==="mcp"?s.jsx(sd,{className:"h-[18px] w-[18px] shrink-0 sm:h-4 sm:w-4"}):s.jsx(L,{name:ue,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:Z(xe.slug)}),(xe.slug==="tunnel"||xe.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:r("settings.view.badge.beta")})]})]})})},xe.slug)})]},ve))})()})}),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:(!T.isVSCode||g>0)&&s.jsx(Ff,{})})})]})},Ge=()=>{if(b==="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(vn,{children:Ve()})})});if(!_)return s.jsx("div",{className:"flex-1 bg-background"});if(b==="page-sidebar"){if(_.kind!=="split"){const ie=me(N);return s.jsx("div",{className:"flex-1 min-h-0 overflow-y-scroll overflow-x-hidden bg-background",children:s.jsx(vn,{children:ie})})}return s.jsx("div",{className:"flex-1 min-h-0 overflow-y-scroll overflow-x-hidden bg-background",children:s.jsx(vn,{children:ae(N,{onItemSelect:fe})})})}const oe=me(N);return s.jsx("div",{className:"flex-1 min-h-0 overflow-y-scroll overflow-x-hidden bg-background",children:s.jsx(vn,{children:oe})})},Ke=()=>!_||N==="home"?null:_.kind==="split"?s.jsxs("div",{className:"flex h-full min-h-0 overflow-hidden",children:[s.jsx("div",{className:we("border-r",T.isVSCode?"bg-background":"bg-sidebar"),style:{width:tl,minWidth:tl,borderColor:"var(--interactive-border)"},children:s.jsx(vn,{children:ae(N,{})})}),s.jsx("div",{className:"flex-1 min-h-0 overflow-y-scroll overflow-x-hidden bg-background",children:s.jsx(vn,{children:me(N)})})]}):s.jsx("div",{className:"h-full min-h-0 overflow-y-scroll overflow-x-hidden bg-background",children:s.jsx(vn,{children:me(N)})});return s.jsxs("div",{ref:m,"data-settings-view":"true",className:we("relative flex h-full min-h-0 flex-col overflow-hidden bg-background"),children:[u?s.jsxs("div",{className:we("flex h-[var(--oc-header-height,56px)] shrink-0 items-center gap-2 px-3",b!=="nav"&&"border-b","bg-background"),style:b!=="nav"?{borderColor:"var(--interactive-border)"}:void 0,children:[Pe?s.jsx("button",{type:"button",onClick:Ee,"aria-label":je,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:b==="nav"?r("settings.view.home.title"):_?Z(_.slug):r("settings.view.home.title")}),Se&&s.jsx("button",{type:"button",onClick:Be,"aria-label":r("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"})}),t&&s.jsx("button",{type:"button",onClick:t,"aria-label":r("settings.view.actions.closeSettings"),title:Re,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:[Pe&&s.jsx("div",{className:we("absolute left-3 z-50",a?"top-2":"top-3"),children:s.jsx("button",{type:"button",onClick:Ee,"aria-label":r("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"})})}),t&&s.jsx("div",{className:we("absolute right-0.5 z-50",a?"top-0.5":"top-1"),children:s.jsx("button",{type:"button",onClick:t,"aria-label":r("settings.view.actions.closeSettings"),title:Re,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"})})})]}),s.jsx("div",{className:"flex flex-1 min-h-0 overflow-hidden",children:u?Ge():s.jsxs(s.Fragment,{children:[s.jsx("div",{className:we("relative flex h-full min-h-0 flex-col overflow-hidden border-r",j?"bg-sidebar":T.isVSCode?"bg-background":"bg-sidebar"),style:{width:`${el}px`,minWidth:`${el}px`,borderColor:"var(--interactive-border)"},children:s.jsx(vn,{children:Ve()})}),s.jsx("div",{className:"flex-1 overflow-hidden bg-background",children:Ke()})]})})]})};export{Il as A,ix as S};
|