@aiworker/web 1.22.2 → 1.23.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/bin/cli.js +7 -0
- package/dist/assets/{CodeMirrorCommentWidgets-CSICpWQD.js → CodeMirrorCommentWidgets-teB3HmBT.js} +1 -1
- package/dist/assets/DiffView-DC9RX3MF.js +4 -0
- package/dist/assets/{DirtyBranchSwitchDialog-C22HdWj4.js → DirtyBranchSwitchDialog-DwPkzXsS.js} +1 -1
- package/dist/assets/FilesView-BFZkuu4O.js +13 -0
- package/dist/assets/{GitView-VQQkYuUw.js → GitView-B_x52MHY.js} +4 -4
- package/dist/assets/{JsonTreeView-6lrhwD3q.js → JsonTreeView-cmAzUTiw.js} +1 -1
- package/dist/assets/{LinearIssuesView-Ba6Q9569.js → LinearIssuesView-Dehh5afm.js} +1 -1
- package/dist/assets/MarkdownImageGallery-DgNOqqhE.js +1 -0
- package/dist/assets/MarkdownRendererImpl-DusmMZ_p.js +12 -0
- package/dist/assets/OnboardingScreen-B8fm1H4m.js +1 -0
- package/dist/assets/{PatchDiff-BzcZPlOq.js → PatchDiff-BVr7gJU0.js} +1 -1
- package/dist/assets/PierreDiffViewer-DzLt-nel.js +161 -0
- package/dist/assets/PlanView-BmQUYT_z.js +5 -0
- package/dist/assets/SettingsView-ChWmAcZT.js +28 -0
- package/dist/assets/{SettingsWindow-DDQYaKWQ.js → SettingsWindow-Dy3M6ZB9.js} +1 -1
- package/dist/assets/SymbolsNerdFontMono-Regular-aK5vsLov.woff2 +0 -0
- package/dist/assets/{ToolOutputDialog-iYF8Y2bz.js → ToolOutputDialog-cTl_eLIH.js} +5 -5
- package/dist/assets/{ToolPartDiffPreview-CdjbOVMM.js → ToolPartDiffPreview-C_3iYNJQ.js} +1 -1
- package/dist/assets/{VirtualizedFileDiff-fFFm2QgH.js → VirtualizedFileDiff-CAWthkoy.js} +4 -4
- package/dist/assets/WalkthroughView-C7AHOpCA.js +4 -0
- package/dist/assets/{computeVirtualFileMetrics-CzgLum_K.js → computeVirtualFileMetrics-BkiDSlTW.js} +2 -2
- package/dist/assets/contextPanelEmbeddedChat-BdA6bdky.js +1 -0
- package/dist/assets/de-DJsQr-p7.js +10 -0
- package/dist/assets/es-BuYMlA9g.js +16 -0
- package/dist/assets/fr-ePDay33C.js +14 -0
- package/dist/assets/ghostty-vt-DdA0Zryv.wasm +0 -0
- package/dist/assets/index-BD8ILbxF.js +40 -0
- package/dist/assets/{index-Bl3LSbjn.js → index-n6O3hklM.js} +1 -1
- package/dist/assets/index-zhgg-SDz.css +1 -0
- package/dist/assets/{isDiffPlainText-Dx-dB_8l.js → isDiffPlainText-GMdPz-71.js} +1 -1
- package/dist/assets/{isFilePlainText-CWFPwmnU.js → isFilePlainText-BVuH1zH9.js} +1 -1
- package/dist/assets/ja-BzR9xOY_.js +16 -0
- package/dist/assets/ko-BEjHAm14.js +16 -0
- package/dist/assets/main-BydQ1tr_.js +930 -0
- package/dist/assets/{main-DnBAoktx.js → main-D3ZDQglc.js} +2 -2
- package/dist/assets/markdownCore-Cb2MdZnV.js +5 -0
- package/dist/assets/{miniChat-BKyvLseN.js → miniChat-d01k801U.js} +2 -2
- package/dist/assets/{mobile-DKjeFgMN.js → mobile-D7VV-Ufz.js} +2 -2
- package/dist/assets/patchFileDiff-CdztVMz0.js +13 -0
- package/dist/assets/pl-rQmpxNIF.js +16 -0
- package/dist/assets/pt-BR-CorbsSW-.js +16 -0
- package/dist/assets/renderElectronMiniChatApp-BGG9UIlh.js +2 -0
- package/dist/assets/renderMobileApp-BRP3J1iv.js +25 -0
- package/dist/assets/runtimeEndpointReset-BhT_-c52.js +41 -0
- package/dist/assets/scheduledTasksApi-BEuUF_cj.js +1 -0
- package/dist/assets/{shikiHighlight-TEQCmzW8.js → shikiHighlight-BzXUjlby.js} +1 -1
- package/dist/assets/surface-COKb77Ua.js +1 -0
- package/dist/assets/tr-CoAMXPtI.js +7 -0
- package/dist/assets/uk-YlAX0rRU.js +16 -0
- package/dist/assets/{useAppFontEffects-D7sNpuL2.js → useAppFontEffects-Cwyhjfl5.js} +141 -140
- package/dist/assets/useGitComparison-BCZVefdE.js +1 -0
- package/dist/assets/useInlineCommentController-DDkpBEU8.js +2 -0
- package/dist/assets/useRootScrollLock-CwjoWuC4.js +1 -0
- package/dist/assets/{vendor-base-ui-BeMD8X_w.js → vendor-base-ui-BY_5qla_.js} +1 -1
- package/dist/assets/{vendor-codemirror-language-data-Dp3KMRQG.js → vendor-codemirror-language-data-Cb1YnICj.js} +2 -2
- package/dist/assets/vendor-legendapp-list-BuBPBC3R.js +1 -0
- package/dist/assets/vendor-zod-B6551dwG.js +39 -0
- package/dist/assets/{web-components-_mNEMjFY.js → web-components-LV3vjTxy.js} +1 -1
- package/dist/assets/zh-CN-DDYg0Jl7.js +16 -0
- package/dist/assets/zh-TW-CQKaCayr.js +16 -0
- package/dist/index.html +5 -43
- package/dist/mini-chat.html +4 -4
- package/dist/mobile.html +4 -4
- package/package.json +2 -3
- package/server/index.d.ts +15 -0
- package/server/index.js +48 -22
- package/server/lib/agent-memory/runtime.js +7 -2
- package/server/lib/agent-memory/runtime.test.js +22 -0
- package/server/lib/data-dir-migration.js +40 -0
- package/server/lib/data-dir-migration.test.js +59 -0
- package/server/lib/event-stream/DOCUMENTATION.md +3 -0
- package/server/lib/event-stream/global-hub.js +29 -4
- package/server/lib/event-stream/global-hub.test.js +22 -0
- package/server/lib/event-stream/global-ws-bridge.js +15 -18
- package/server/lib/event-stream/protocol.js +21 -7
- package/server/lib/event-stream/runtime.js +9 -6
- package/server/lib/event-stream/runtime.test.js +72 -12
- package/server/lib/fs/DOCUMENTATION.md +3 -0
- package/server/lib/fs/routes.js +31 -0
- package/server/lib/fs/routes.test.js +110 -1
- package/server/lib/git/DOCUMENTATION.md +39 -6
- package/server/lib/git/routes.js +45 -12
- package/server/lib/git/routes.test.js +78 -0
- package/server/lib/git/service.js +343 -202
- package/server/lib/git/service.test.js +496 -25
- package/server/lib/github/DOCUMENTATION.md +5 -0
- package/server/lib/github/routes.js +2 -2
- package/server/lib/inherited-env.js +16 -9
- package/server/lib/inherited-env.test.js +8 -9
- package/server/lib/message-queue/DOCUMENTATION.md +11 -1
- package/server/lib/message-queue/runtime.js +13 -0
- package/server/lib/message-queue/runtime.test.js +31 -1
- package/server/lib/network-defaults.js +23 -0
- package/server/lib/network-defaults.test.js +52 -0
- package/server/lib/notifications/DOCUMENTATION.md +1 -1
- package/server/lib/notifications/emitter-runtime.js +4 -3
- package/server/lib/opencode/DOCUMENTATION.md +35 -5
- package/server/lib/opencode/bootstrap-runtime.js +2 -0
- package/server/lib/opencode/env-runtime.js +5 -1
- package/server/lib/opencode/env-runtime.test.js +72 -0
- package/server/lib/opencode/feature-routes-runtime.js +17 -1
- package/server/lib/opencode/lifecycle.js +4 -3
- package/server/lib/opencode/lifecycle.test.js +29 -0
- package/server/lib/opencode/managed-plugin-config.js +1 -1
- package/server/lib/opencode/openchamber-routes.js +64 -4
- package/server/lib/opencode/openchamber-routes.test.js +128 -1
- package/server/lib/opencode/proxy.js +33 -0
- package/server/lib/opencode/routes.js +5 -3
- package/server/lib/opencode/settings-files.js +214 -0
- package/server/lib/opencode/settings-helpers.js +88 -41
- package/server/lib/opencode/settings-helpers.test.js +176 -1
- package/server/lib/opencode/settings-registry.json +750 -0
- package/server/lib/opencode/settings-runtime.js +175 -27
- package/server/lib/opencode/settings-runtime.test.js +321 -7
- package/server/lib/project-context/DOCUMENTATION.md +38 -4
- package/server/lib/project-context/routes.http.test.js +18 -0
- package/server/lib/project-context/routes.js +15 -0
- package/server/lib/project-context/runtime.js +256 -25
- package/server/lib/project-context/runtime.test.js +160 -3
- package/server/lib/projects/DOCUMENTATION.md +77 -0
- package/server/lib/projects/project-config.js +179 -17
- package/server/lib/projects/project-config.test.js +97 -0
- package/server/lib/projects/project-id.js +43 -0
- package/server/lib/projects/project-setup.js +409 -0
- package/server/lib/projects/project-setup.test.js +557 -0
- package/server/lib/projects/routes.js +59 -0
- package/server/lib/quota/DOCUMENTATION.md +31 -1
- package/server/lib/quota/providers/cline-pass.js +125 -0
- package/server/lib/quota/providers/cline-pass.test.js +103 -0
- package/server/lib/quota/providers/index.js +7 -0
- package/server/lib/quota/providers/neuralwatt.js +3 -6
- package/server/lib/quota/providers/neuralwatt.test.js +7 -7
- package/server/lib/quota/providers/ollama-cloud.js +31 -0
- package/server/lib/quota/providers/ollama-cloud.test.js +33 -1
- package/server/lib/quota/providers/opencode-go.js +1 -1
- package/server/lib/quota/providers/opencode-go.test.js +26 -1
- package/server/lib/quota/providers/openrouter.js +119 -24
- package/server/lib/quota/providers/openrouter.test.js +330 -0
- package/server/lib/relay/DOCUMENTATION.md +75 -0
- package/server/lib/relay/cross-compat.test.js +26 -0
- package/server/lib/relay/downstream-scheduler.js +154 -0
- package/server/lib/relay/downstream-scheduler.test.js +162 -0
- package/server/lib/relay/e2ee.js +10 -8
- package/server/lib/relay/flow-control.test.js +177 -0
- package/server/lib/relay/host-client.js +44 -8
- package/server/lib/relay/host-client.test.js +14 -0
- package/server/lib/relay/tunnel-codec.js +9 -0
- package/server/lib/relay/tunnel-host.js +66 -17
- package/server/lib/scheduled-tasks/DOCUMENTATION.md +9 -1
- package/server/lib/scheduled-tasks/issue-2710-double-execution.test.js +28 -0
- package/server/lib/scheduled-tasks/runtime.js +12 -2
- package/server/lib/scheduled-tasks/runtime.test.js +53 -0
- package/server/lib/session-assist/DOCUMENTATION.md +131 -66
- package/server/lib/session-assist/context.js +127 -0
- package/server/lib/session-assist/context.test.js +132 -0
- package/server/lib/session-assist/prompt.js +54 -0
- package/server/lib/session-assist/runtime.js +117 -267
- package/server/lib/session-assist/runtime.test.js +203 -0
- package/server/lib/session-goal/runtime.js +4 -9
- package/server/lib/small-model/DOCUMENTATION.md +3 -2
- package/server/lib/small-model/call.js +9 -4
- package/server/lib/small-model/call.test.js +29 -0
- package/server/lib/small-model/index.js +5 -10
- package/server/lib/small-model/runtime-providers.js +15 -7
- package/server/lib/small-model/runtime-providers.test.js +7 -1
- package/server/lib/terminal/DOCUMENTATION.md +4 -4
- package/server/lib/terminal/runtime.js +11 -6
- package/server/lib/terminal/runtime.test.js +20 -13
- package/server/lib/walkthrough/DOCUMENTATION.md +49 -20
- package/server/lib/walkthrough/model-settings.js +8 -12
- package/server/lib/walkthrough/pr-source.test.js +21 -0
- package/server/lib/walkthrough/prompt.js +3 -1
- package/server/lib/walkthrough/pull-request.js +7 -4
- package/server/lib/walkthrough/pull-request.test.js +16 -0
- package/server/lib/walkthrough/routes.js +19 -0
- package/server/lib/walkthrough/routes.test.js +26 -0
- package/server/lib/walkthrough/sources.js +36 -4
- package/server/opencode-worktree-readiness.test.js +130 -0
- package/dist/assets/DiffView-hDBKesA_.js +0 -4
- package/dist/assets/FilesView-CdWzeOp9.js +0 -17
- package/dist/assets/MarkdownImageGallery-Czv_mhvS.js +0 -1
- package/dist/assets/MarkdownRendererImpl-BrMcswiy.js +0 -12
- package/dist/assets/OnboardingScreen-ChxQoAkx.js +0 -1
- package/dist/assets/PierreDiffViewer-BchBtZlp.js +0 -157
- package/dist/assets/PlanView-DyDt_nZ_.js +0 -5
- package/dist/assets/SettingsView-BKf5xBsP.js +0 -28
- package/dist/assets/WalkthroughView-DOeCsMju.js +0 -4
- package/dist/assets/contextPanelEmbeddedChat-C0ZLAepL.js +0 -1
- package/dist/assets/de-B5JaA3SA.js +0 -10
- package/dist/assets/es-EPIH88ii.js +0 -16
- package/dist/assets/fr-CAMfxUdZ.js +0 -14
- package/dist/assets/index-DF5kMP-i.js +0 -39
- package/dist/assets/index-Dl3xbAB_.css +0 -1
- package/dist/assets/ja-CifOE1VN.js +0 -16
- package/dist/assets/ko-BBDyAyYQ.js +0 -16
- package/dist/assets/main-MhSaOZoB.js +0 -930
- package/dist/assets/markdownCore-BrBwOOMn.js +0 -3
- package/dist/assets/patchFileDiff-o8ms1me8.js +0 -10
- package/dist/assets/pl-DgEHYfFM.js +0 -16
- package/dist/assets/pt-BR-DuWHojUw.js +0 -16
- package/dist/assets/renderElectronMiniChatApp-CDgBwwCS.js +0 -2
- package/dist/assets/renderMobileApp-DJIKIK1r.js +0 -25
- package/dist/assets/runtimeEndpointReset-CYJ9O_xX.js +0 -17
- package/dist/assets/scheduledTasksApi-D8yamh1b.js +0 -1
- package/dist/assets/tr-D5m2yIWL.js +0 -7
- package/dist/assets/uk-D_q60oog.js +0 -16
- package/dist/assets/useInlineCommentController-Brz_cLcQ.js +0 -2
- package/dist/assets/useRootScrollLock-lXEnWlaU.js +0 -1
- package/dist/assets/vendor-ghostty-web-CrxinGGH.js +0 -13
- package/dist/assets/vendor-legendapp-list-gg7YLRW7.js +0 -1
- package/dist/assets/vendor-zod-CK21ihK-.js +0 -39
- package/dist/assets/zh-CN-D8QvsVeg.js +0 -16
- package/dist/assets/zh-TW-B9t7rQQO.js +0 -16
- package/server/lib/mcp-reconnect/DOCUMENTATION.md +0 -55
- package/server/lib/mcp-reconnect/runtime.js +0 -122
- package/server/lib/mcp-reconnect/runtime.test.js +0 -140
|
@@ -0,0 +1,28 @@
|
|
|
1
|
+
import{R as o,j as s,f as ut,r as $e}from"./vendor-react-BUCujlKS.js";import{f as tt,B as V,I as O,o as Pn,bd as wa,t as E,O as mc,g1 as gc,eF as ze,g2 as Tt,b as Gs,h as xe,at as hc,ap as on,ar as ln,as as fc,ao as cn,ev as Hn,g3 as fl,g4 as xc,g5 as ma,g6 as un,bT as vs,bN as Kt,bO as zt,bP as _t,bQ as $t,bR as Vt,bS as ts,V as He,g7 as _a,bb as dn,ei as lr,g8 as vc,g9 as zn,eK as Jt,ga as Ys,l as Ye,eY as Rt,c2 as St,c3 as Ct,eV as Ft,c4 as Mt,c5 as It,c6 as at,gb as qt,c7 as Ts,dG as Fa,eX as In,e_ as xa,eZ as rn,gc as Cs,dL as xs,gd as Ps,ge as yc,cy as dt,gf as xl,gg as bc,gh as $n,gi as vl,gj as wc,gk as va,fD as Hs,gl as ha,gm as yl,gn as wr,dH as bl,go as Vn,a8 as ya,a7 as Ks,gp as wl,gq as Kr,ad as jc,eg as jl,g as Ka,gr as kc,gs as Zs,b$ as An,ca as Tn,c0 as En,ef as Nc,gt as Sc,gu as Cc,gv as jr,a9 as kr,aa as Nr,ab as kl,gw as hn,a3 as ki,bo as Sr,R as Cr,gx as zr,au as Ic,c8 as Pc,cO as Ac,T as Tc,S as Ec,U as Dc,Y as Nl,gy as Mc,gz as Rc,bZ as Lc,c9 as cr,gA as Sl,ac as xi,gB as Cl,P as Un,gC as Qs,eE as zs,eo as Il,a2 as Oc,n as Zt,ea as Ni,x as Pl,w as Fc,i as Kc,j as zc,eb as Uc,p as _c,gD as $c,gE as Vc,gF as Ur,dM as Al,gG as Bc,gH as Hi,gI as _r,gJ as Hc,gK as Gc,gL as Wc,gM as qc,dS as Si,gN as fs,gO as Ss,gP as Js,gQ as Bs,aB as Cn,aC as oa,gR as Sn,eU as bn,gS as ba,gT as $r,gU as la,gV as ca,bK as Gn,gW as Jc,gX as Qc,gY as Yc,gZ as Zc,g_ as Gi,g$ as Vr,h0 as Xc,h1 as ed,h2 as td,h3 as sd,h4 as Br,y as nd,m as Hr,d0 as ad,h5 as id,h6 as Wi,h7 as Gr,ed as rd,h8 as Ii,h9 as od,ha as ld,hb as cd,hc as dd,hd as ud,he as qi,cz as pd,bL as Tl,hf as El,hg as md,ax as wn,ay as gd}from"./useAppFontEffects-Cwyhjfl5.js";import{h as yt,u as ie,K as cs,d9 as hd,da as Wr,A as fn,aB as pn,q as gt,a2 as fd,D as as,Q as qr,cr as Jr,cy as Qr,V as Ia,p as xd,db as vd,k as yd,cq as ua,dc as bd,ak as wd,cv as jd,dd as kd,de as Nd,s as Sd,e as $a,cw as Cd,E as Va,df as Dl,$ as Id,dg as Pd,v as fa,aA as ga,c$ as Ad,_ as Td,aM as Yr,a$ as ai,aN as Ed,dh as Dd,aa as Bn,di as Md,z as Ml,dj as Zr,d8 as Xr,dk as eo,aK as to,dl as Rd,dm as Ld,dn as Od,dp as Fd,dq as so,b as Kd,aH as Rl,dr as Ll,ds as zd,dt as Ud,du as _d,dv as $d,dw as Vd,dx as Bd,av as Hd,i as Ol}from"./index-BD8ILbxF.js";import{u as Gd,U as no,K as Wn,M as qn,Q as Jn,R as Qn,f as Ir,a6 as _n,X as Wd,n as As,a4 as qd,a7 as pa,a8 as Fl,V as Jd,W as Qd}from"./runtimeEndpointReset-BhT_-c52.js";import{u as Us,c as Kl,d as Yd,p as Zd}from"./vendor-zustand-BAGL70zf.js";import{o as Xd,s as ao,b as eu}from"./vendor-zod-B6551dwG.js";import{s as tu,p as su}from"./vendor-yaml-3778uTud.js";import{c as io,s as nu,C as ro,P as au}from"./shikiHighlight-BzXUjlby.js";import{getResolvedShikiTheme as iu}from"./appThemeRegistry-BK0dHKa6.js";import{E as oo}from"./vendor-codemirror-view-CiLROUVV.js";import{Q as zl}from"./vendor-qrcode-DTJ12-WC.js";const lo=()=>{const{t}=tt(),[e,a]=o.useState(null);o.useEffect(()=>{let r=!1;const i=typeof AbortController<"u"?new AbortController:void 0;return(async()=>{try{const g=await yt("/api/system/info",{signal:i?.signal,headers:{Accept:"application/json"}});if(!g.ok)return;const c=await g.json().catch(()=>null);if(!c||r)return;const y=typeof c.port=="number"&&Number.isFinite(c.port)&&c.port>0?c.port:null,p=typeof c.tunnelUrl=="string"&&c.tunnelUrl.trim().length>0?c.tunnelUrl.trim():null;a({port:y,tunnelUrl:p})}catch{}})(),()=>{r=!0,i?.abort()}},[]);const n=[];return e?.port!==null&&e?.port!==void 0&&n.push({key:"application",label:t("settings.aiworker.about.field.applicationUrl"),url:`http://localhost:${e.port}/`}),e?.tunnelUrl&&n.push({key:"tunnel",label:t("settings.aiworker.about.field.tunnelUrl"),url:e.tunnelUrl}),n.length===0?null:s.jsx("div",{className:"flex flex-wrap items-center gap-2",children:n.map(r=>s.jsxs(V,{type:"button",variant:"outline",size:"sm",title:r.label,className:"max-w-full gap-1.5 px-2.5",onClick:()=>{Pn(r.url)},children:[s.jsx(O,{name:"external-link",className:"size-3.5 shrink-0"}),s.jsx("span",{className:"max-w-64 truncate font-mono typography-micro",children:r.url})]},r.key))})},co="https://roweb.cn/roweb/openchamber",ru="https://discord.gg/ZYRSdnwwKA",uo="https://x.com/openchamber_dev",ou=800,Ul=({initialUpdateDialogOpen:t=!1})=>{const{t:e}=tt(),[a,n]=o.useState(t),[r,i]=o.useState(!1),[l,g]=o.useState(null),[c,y]=o.useState(null),p=Gd(Us(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:b}=wa(),d=l||p.info?.currentVersion||"unknown";o.useEffect(()=>{let C=!1;return(async()=>{try{const N=await yt("/api/system/info",{method:"GET",headers:{Accept:"application/json"}});if(!N.ok)return;const m=await N.json().catch(()=>null),A=typeof m?.aiworkerVersion=="string"&&m.aiworkerVersion.trim().length>0?m.aiworkerVersion.trim():null;C||g(A)}catch{C||g(null)}})(),()=>{C=!0}},[]),o.useEffect(()=>{let C=!1;return(async()=>{try{const N=await yt("/api/opencode/upgrade-status",{method:"GET",headers:{Accept:"application/json"}});if(!N.ok)return;const m=await N.json().catch(()=>null),A=typeof m?.currentVersion=="string"&&m.currentVersion.trim().length>0?m.currentVersion.trim():null;C||y(A)}catch{C||y(null)}})(),()=>{C=!0}},[]);const P=o.useRef(!1);o.useEffect(()=>{if(p.checking)i(!0),P.current=!0;else if(r){const C=setTimeout(()=>{i(!1),P.current&&!p.available&&!p.error&&(E.success(e("settings.aiworker.about.toast.latestVersion")),P.current=!1)},ou);return()=>clearTimeout(C)}},[e,p.checking,r,p.available,p.error]);const f=p.checking||r;return b?s.jsxs("div",{className:"w-full space-y-6 pb-2",children:[s.jsxs("div",{className:"flex flex-col items-center text-center",children:[s.jsx(mc,{width:72,height:72}),s.jsx("h2",{className:`mt-4 ${gc}`,children:"AiWorker"}),s.jsxs("div",{className:"mt-2 space-y-1 typography-ui text-muted-foreground",children:[s.jsx("p",{children:e("aboutDialog.openChamberVersionLabel",{version:d})}),s.jsx("p",{children:e("aboutDialog.openCodeVersionLabel",{version:c||e("settings.aiworker.about.state.unknown")})})]}),s.jsx(lo,{})]}),s.jsxs("div",{className:"flex justify-center",children:[!p.available&&!p.error&&s.jsxs(V,{type:"button",variant:"outline",size:"sm",onClick:()=>p.checkForUpdates(),disabled:f,className:"h-10 w-auto justify-center gap-2 rounded-xl px-4",children:[f?s.jsx(O,{name:"loader",className:"size-4 animate-spin"}):s.jsx(O,{name:"refresh",className:"size-4"}),e(f?"settings.aiworker.about.state.checking":"settings.aiworker.about.actions.checkForUpdates")]}),!f&&p.available&&s.jsxs(V,{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(O,{name:"download",className:"size-4"}),e("settings.aiworker.about.actions.updateToVersion",{version:p.info?.version||""})]})]}),p.error&&s.jsx("p",{className:"rounded-xl border border-[var(--status-error-border)] bg-[var(--status-error-background)] px-3 py-2 typography-meta text-[var(--status-error)]",children:p.error}),s.jsxs("div",{className:"flex flex-col items-center gap-3 text-center",children:[s.jsxs("div",{className:"flex items-center justify-center gap-5",children:[s.jsxs("a",{href:co,target:"_blank",rel:"noopener noreferrer",className:"flex items-center gap-1.5 typography-ui-label text-muted-foreground transition-colors hover:text-foreground",children:[s.jsx(O,{name:"github-fill",className:"size-5"}),s.jsx("span",{children:"GitHub"})]}),s.jsxs("a",{href:ru,target:"_blank",rel:"noopener noreferrer",className:"flex items-center gap-1.5 typography-ui-label text-muted-foreground transition-colors hover:text-foreground",children:[s.jsx(O,{name:"discord-fill",className:"size-5"}),s.jsx("span",{children:"Discord"})]})]}),s.jsxs("a",{href:uo,target:"_blank",rel:"noopener noreferrer",className:"flex items-center gap-1.5 typography-ui-label text-muted-foreground transition-colors hover:text-foreground",children:[s.jsx(O,{name:"twitter-xfill",className:"size-5"}),s.jsx("span",{children:"@aiworker_dev"})]})]}),s.jsx("p",{className:"text-center typography-ui text-muted-foreground/60",children:e("aboutDialog.footerNote")}),s.jsx(no,{open:a,onOpenChange:n,info:p.info,downloading:p.downloading,downloaded:p.downloaded,progress:p.progress,error:p.error,onDownload:p.downloadUpdate,onRestart:p.restartToUpdate,runtimeType:p.runtimeType})]}):s.jsxs(ze,{divider:!1,children:[s.jsxs("div",{className:"rounded-lg bg-[var(--surface-elevated)]/70 overflow-hidden flex flex-col",children:[s.jsxs("div",{className:"flex flex-col @xl:flex-row @xl:items-center justify-between gap-4 px-4 py-3 border-b border-border/40",children:[s.jsxs("div",{className:"flex min-w-0 flex-col",children:[s.jsx("span",{className:Tt,children:e("settings.aiworker.about.field.version")}),s.jsx("span",{className:"typography-meta text-muted-foreground font-mono",children:d})]}),s.jsxs("div",{className:"flex min-w-0 flex-col",children:[s.jsx("span",{className:Tt,children:e("settings.aiworker.about.field.openCodeVersion")}),s.jsx("span",{className:"typography-meta text-muted-foreground font-mono",children:c||e("settings.aiworker.about.state.unknown")})]}),s.jsxs("div",{className:"flex items-center gap-3",children:[p.checking&&s.jsxs("div",{className:"flex items-center gap-2 text-muted-foreground",children:[s.jsx(O,{name:"loader",className:"h-4 w-4 animate-spin"}),s.jsx("span",{className:"typography-meta",children:e("settings.aiworker.about.state.checking")})]}),!p.checking&&p.available&&s.jsxs(V,{size:"sm",variant:"default",onClick:()=>n(!0),children:[s.jsx(O,{name:"download",className:"h-4 w-4 mr-1"}),e("settings.aiworker.about.actions.updateToVersion",{version:p.info?.version||""})]}),!p.checking&&!p.available&&!p.error&&s.jsx("span",{className:"typography-meta text-muted-foreground",children:e("settings.aiworker.about.state.upToDate")}),s.jsx(V,{size:"sm",variant:"outline",onClick:()=>p.checkForUpdates(),disabled:p.checking,children:e("settings.aiworker.about.actions.checkForUpdates")})]})]}),p.error&&s.jsx("div",{className:"px-3 py-2 border-b border-border/40",children:s.jsx("p",{className:"typography-meta text-[var(--status-error)]",children:p.error})}),s.jsxs("div",{className:"flex flex-col gap-2 border-b border-border/40 px-4 py-3 @xl:flex-row @xl:items-center @xl:justify-between",children:[s.jsx("span",{className:Tt,children:e("settings.aiworker.about.field.instanceUrls")}),s.jsx(lo,{})]}),s.jsxs("div",{className:"flex items-center gap-4 px-4 py-4",children:[s.jsxs("a",{href:co,target:"_blank",rel:"noopener noreferrer",className:"flex items-center gap-1.5 text-muted-foreground hover:text-foreground typography-meta transition-colors",children:[s.jsx(O,{name:"github-fill",className:"h-4 w-4"}),s.jsx("span",{children:"GitHub"})]}),s.jsxs("a",{href:uo,target:"_blank",rel:"noopener noreferrer",className:"flex items-center gap-1.5 text-muted-foreground hover:text-foreground typography-meta transition-colors",children:[s.jsx(O,{name:"twitter-xfill",className:"h-4 w-4"}),s.jsx("span",{children:"@aiworker_dev"})]})]})]}),s.jsx(no,{open:a,onOpenChange:n,info:p.info,downloading:p.downloading,downloaded:p.downloaded,progress:p.progress,error:p.error,onDownload:p.downloadUpdate,onRestart:p.restartToUpdate,runtimeType:p.runtimeType})]})},lu=(t,e,a)=>t&&e.some(r=>r.path===t)?t:(e.find(r=>r.id===a)??e[0])?.path??null,_s=()=>{const t=ut.c(4),e=ie(cu),a=Gs(du),n=Gs(uu);let r;return t[0]!==n||t[1]!==a||t[2]!==e?(r=lu(e,a,n),t[0]=n,t[1]=a,t[2]=e,t[3]=r):r=t[3],r};function cu(t){return t.settingsProjectPath}function du(t){return t.projects}function uu(t){return t.activeProjectId}const _l=t=>t.trim(),Ba=t=>{const e=ut.c(40),{className:a}=t,{t:n}=tt(),r=Gs(pu),i=_s(),l=ie(mu),g=cs();let c;e[0]!==r?(c=[...r].sort(gu),e[0]=r,e[1]=c):c=e[1];const y=c;let p;e:{if(y.length===0){p=null;break e}let B;e[2]!==i||e[3]!==y?(B=y.find(k=>k.path===i)??y[0],e[2]=i,e[3]=y,e[4]=B):B=e[4],p=B}const b=p;if(g||y.length===0)return null;let d;e[5]!==b||e[6]!==n?(d=b?.label&&b.label.trim().length>0?b.label:b?.path.split("/").filter(Boolean).pop()||b?.path||n("settings.shared.projectSelector.fallbackProject"),e[5]=b,e[6]=n,e[7]=d):d=e[7];const P=d;let f;e[8]!==P?(f=_l(P),e[8]=P,e[9]=f):f=e[9];const C=f;let v;e[10]!==a?(v=xe(a),e[10]=a,e[11]=v):v=e[11];let N;e[12]!==n?(N=n("settings.shared.projectSelector.switchProjectAria"),e[12]=n,e[13]=N):N=e[13];let m;e[14]!==n?(m=n("settings.shared.projectSelector.switchProjectTitle"),e[14]=n,e[15]=m):m=e[15];let A,R;e[16]===Symbol.for("react.memo_cache_sentinel")?(A=xe("text-foreground border border-border/80 appearance-none flex h-8 w-full min-w-0 rounded-lg bg-transparent px-3 py-1 outline-none","hover:border-input focus-visible:ring-1 focus-visible:ring-primary/50 focus-visible:border-primary/70","flex items-center gap-1.5 text-left"),R=s.jsx(O,{name:"folder",className:"h-4 w-4 opacity-70"}),e[16]=A,e[17]=R):(A=e[16],R=e[17]);let I;e[18]!==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 j;e[20]===Symbol.for("react.memo_cache_sentinel")?(j=s.jsx(O,{name:"arrow-down-s",className:"size-4 opacity-50"}),e[20]=j):j=e[20];let h;e[21]!==I||e[22]!==N||e[23]!==m?(h=s.jsx(on,{asChild:!0,children:s.jsxs("button",{type:"button","aria-label":N,title:m,className:A,children:[R,I,j]})}),e[21]=I,e[22]=N,e[23]=m,e[24]=h):h=e[24];const w=b?.id??"";let F;e[25]!==l||e[26]!==y?(F=B=>{if(!B)return;const k=y.find(G=>G.id===B);k&&l(k.path)},e[25]=l,e[26]=y,e[27]=F):F=e[27];let T;e[28]!==y?(T=y.map(hu),e[28]=y,e[29]=T):T=e[29];let S;e[30]!==w||e[31]!==F||e[32]!==T?(S=s.jsx(ln,{align:"start",className:"w-auto",children:s.jsx(fc,{value:w,onValueChange:F,children:T})}),e[30]=w,e[31]=F,e[32]=T,e[33]=S):S=e[33];let D;e[34]!==h||e[35]!==S?(D=s.jsxs(cn,{children:[h,S]}),e[34]=h,e[35]=S,e[36]=D):D=e[36];let $;return e[37]!==D||e[38]!==v?($=s.jsx("div",{className:v,children:D}),e[37]=D,e[38]=v,e[39]=$):$=e[39],$};function pu(t){return t.projects}function mu(t){return t.setSettingsProjectPath}function gu(t,e){return(t.label||t.path).localeCompare(e.label||e.path)}function hu(t){const e=t.label?.trim()?t.label.trim():t.path.split("/").filter(Boolean).pop()||t.path,a=_l(e);return s.jsx(hc,{value:t.id,children:s.jsx("span",{className:"min-w-0 truncate typography-ui",children:a})},t.id)}function fu(t,e){return`opencode:sidebar-group:${t}:${e}`}const dr=t=>{const e=ut.c(33),{label:a,count:n,storageKey:r,defaultExpanded:i,children:l}=t,g=i===void 0?!0:i;let c;e[0]!==a||e[1]!==r?(c=fu(r,a),e[0]=a,e[1]=r,e[2]=c):c=e[2];const y=c,p=o.useId();let b;e[3]!==g||e[4]!==y?(b=()=>{try{const S=localStorage.getItem(y);if(S!==null)return S==="true"}catch{}return g},e[3]=g,e[4]=y,e[5]=b):b=e[5];const[d,P]=$e.useState(b);let f,C;e[6]!==d||e[7]!==y?(f=()=>{try{localStorage.setItem(y,String(d))}catch{}},C=[y,d],e[6]=d,e[7]=y,e[8]=f,e[9]=C):(f=e[8],C=e[9]),$e.useEffect(f,C);let v;e[10]===Symbol.for("react.memo_cache_sentinel")?(v=()=>P(xu),e[10]=v):v=e[10];let N;e[11]===Symbol.for("react.memo_cache_sentinel")?(N=xe("flex w-full items-center gap-1 rounded-md px-2 py-1 text-left","text-xs font-semibold uppercase tracking-wide text-muted-foreground","hover:bg-[var(--interactive-hover)] transition-colors duration-150","focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-primary/50"),e[11]=N):N=e[11];const m=!d&&"-rotate-90";let A;e[12]!==m?(A=xe("h-3.5 w-3.5 flex-shrink-0 transition-transform duration-200",m),e[12]=m,e[13]=A):A=e[13];let R;e[14]!==A?(R=s.jsx(O,{name:"arrow-down-s",className:A}),e[14]=A,e[15]=R):R=e[15];let I;e[16]!==a?(I=s.jsx("span",{className:"flex-1 truncate",children:a}),e[16]=a,e[17]=I):I=e[17];let j;e[18]!==n?(j=s.jsx("span",{className:"ml-1 tabular-nums opacity-60",children:n}),e[18]=n,e[19]=j):j=e[19];let h;e[20]!==p||e[21]!==d||e[22]!==R||e[23]!==I||e[24]!==j?(h=s.jsxs("button",{type:"button",onClick:v,"aria-expanded":d,"aria-controls":p,className:N,children:[R,I,j]}),e[20]=p,e[21]=d,e[22]=R,e[23]=I,e[24]=j,e[25]=h):h=e[25];const w=!d;let F;e[26]!==l||e[27]!==p||e[28]!==w?(F=s.jsx("div",{id:p,hidden:w,className:"mt-0.5 space-y-0.5 ml-2 pl-3 border-l-2 border-[var(--interactive-border)]",children:l}),e[26]=l,e[27]=p,e[28]=w,e[29]=F):F=e[29];let T;return e[30]!==h||e[31]!==F?(T=s.jsxs("div",{children:[h,F]}),e[30]=h,e[31]=F,e[32]=T):T=e[32],T};function xu(t){return!t}const vu=t=>{if(!Array.isArray(t))return[];const e=[];for(const a of t){if(!a||typeof a!="object")continue;const n=a;typeof n.permission!="string"||typeof n.pattern!="string"||typeof n.action!="string"||n.action!=="allow"&&n.action!=="ask"&&n.action!=="deny"||e.push({permission:n.permission,pattern:n.pattern,action:n.action})}return e},yu=t=>{const e=new Map;for(const a of t)!a.permission||a.permission==="invalid"||a.pattern&&e.set(`${a.permission}::${a.pattern}`,a);return Array.from(e.values())},po=t=>{const e=yu(vu(t));if(e.length===0)return;const a={};for(const r of e)r.permission&&((a[r.permission]||={})[r.pattern]=r.action);const n={};for(const[r,i]of Object.entries(a)){const l=Object.keys(i);if(l.length===1&&l[0]==="*"){n[r]=i["*"];continue}n[r]=i}return Object.keys(n).length>0?n:void 0},bu=({onItemSelect:t})=>{const{t:e}=tt(),[a,n]=o.useState(null),[r,i]=o.useState(""),[l,g]=o.useState(null),[c,y]=o.useState(null),[p,b]=o.useState(!1),[d,P]=o.useState(null),{selectedAgentName:f,setSelectedAgent:C,setAgentDraft:v,createAgent:N,deleteAgent:m,loadAgents:A}=Hn(Us(U=>({selectedAgentName:U.selectedAgentName,setSelectedAgent:U.setSelectedAgent,setAgentDraft:U.setAgentDraft,createAgent:U.createAgent,deleteAgent:U.deleteAgent,loadAgents:U.loadAgents}))),R=_s(),I=Hn(U=>fl(U,R));o.useEffect(()=>{A(R)},[A,R]);const j="bg-background",h=()=>{const U="new-agent";let le=U,_=1;for(;I.some(H=>H.name===le);)le=`${U}-${_}`,_++;v({name:le,scope:"user"}),C(le),t?.()},w=async U=>{if(ma(U)){E.error(e("settings.agents.sidebar.toast.builtInCannotDelete"));return}g(U),y("delete")},F=async U=>{ma(U)&&(g(U),y("reset"))},T=()=>{g(null),y(null)},S=async()=>{if(!(!l||!c)){b(!0);try{const U=await m(l.name,l.scope,R);U.ok?(U.requiresManualRestart?E.warning(e("settings.agents.page.toast.savedManualRestart")):U.restartDeferred?E.success(e("settings.view.pendingRestart.saved")):c==="delete"?E.success(e("settings.agents.sidebar.toast.agentDeleted",{name:l.name})):E.success(e("settings.agents.sidebar.toast.agentReset",{name:l.name})),T()):c==="delete"?E.error(e("settings.agents.sidebar.toast.deleteFailed")):E.error(e("settings.agents.sidebar.toast.resetFailed"))}catch(U){const le=U instanceof Error?U.message:"",_=/built-in|not deletable|not found/i.test(le);c==="delete"?E.error(e(_?"settings.agents.sidebar.toast.definitionNotFound":"settings.agents.sidebar.toast.deleteFailed")):E.error(e("settings.agents.sidebar.toast.resetFailed"))}b(!1)}},D=U=>{const le=U.name;let _=1,H=`${le}-copy`;for(;I.some(Y=>Y.name===H);)_++,H=`${le}-copy-${_}`;const z=U,K=U.model?.providerID&&U.model?.modelID?`${U.model.providerID}/${U.model.modelID}`:null,te=U;v({name:H,scope:z.scope||"user",description:U.description,model:K,variant:U.variant,temperature:U.temperature,top_p:U.topP,prompt:U.prompt,mode:U.mode,permission:po(U.permission),disable:te.disable}),C(H),t?.()},$=U=>{i(U.name),n(U)},B=async()=>{if(!a)return;const U=r.trim().replace(/\s+/g,"-");if(!U){E.error(e("settings.agents.sidebar.toast.agentNameRequired"));return}if(U===a.name){n(null);return}if(I.some(z=>z.name===U)){E.error(e("settings.agents.sidebar.toast.agentExists"));return}const le=a.model?.providerID&&a.model?.modelID?`${a.model.providerID}/${a.model.modelID}`:null,_=a,H=await N({name:U,description:a.description,model:le,variant:a.variant,temperature:a.temperature,top_p:a.topP,prompt:a.prompt,mode:a.mode,permission:po(a.permission),disable:_.disable,scope:_.scope},R);if(H.ok){const z=await m(a.name,_.scope,R);z.ok?(H.requiresManualRestart||z.requiresManualRestart?E.warning(e("settings.agents.page.toast.savedManualRestart")):E.success(e("settings.agents.sidebar.toast.agentRenamed",{name:U})),C(U)):E.error(e("settings.agents.sidebar.toast.removeOldAfterRenameFailed"))}else E.error(e("settings.agents.sidebar.toast.renameFailed"));n(null)},k=U=>{switch(U){case"primary":return s.jsx(O,{name:"ai-agent",className:"h-3 w-3 text-primary"});case"all":return s.jsx(O,{name:"ai-agent-fill",className:"h-3 w-3 text-primary"});case"subagent":return s.jsx(O,{name:"robot",className:"h-3 w-3 text-primary"});default:return null}},G=I.filter(U=>!xc(U)),M=G.filter(ma),L=G.filter(U=>!ma(U)),{groupedCustomAgents:J,ungroupedCustomAgents:ee}=$e.useMemo(()=>{const U={},le=[];for(const H of L){const z=H;z.group?(U[z.group]||(U[z.group]=[]),U[z.group].push(H)):le.push(H)}return{groupedCustomAgents:Object.keys(U).sort((H,z)=>H.localeCompare(z)).map(H=>({name:H,agents:U[H]})),ungroupedCustomAgents:le}},[L]);return s.jsxs("div",{className:xe("flex h-full flex-col",j),children:[s.jsxs("div",{className:"border-b px-3 pt-4 pb-3",children:[s.jsx("h2",{className:`${un} mb-3`,children:e("settings.agents.sidebar.title")}),s.jsx(Ba,{className:"mb-3"}),s.jsxs("div",{className:"flex items-center justify-between gap-2",children:[s.jsx("span",{className:"typography-meta text-muted-foreground",children:e("settings.agents.sidebar.total",{count:G.length})}),s.jsx(V,{size:"sm","data-settings-item":"agents.create",variant:"ghost",className:"h-7 w-7 px-0 -my-1 text-muted-foreground",onClick:h,children:s.jsx(O,{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(O,{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:[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:e("settings.agents.sidebar.section.builtIn")}),M.map(U=>s.jsx(Ji,{agent:U,isSelected:f===U.name,onSelect:()=>{C(U.name),t?.()},onReset:()=>F(U),onDuplicate:()=>D(U),getAgentModeIcon:k,isMenuOpen:d===U.name,onMenuOpenChange:le=>P(le?U.name:null)},U.name))]}),L.length>0&&s.jsxs(s.Fragment,{children:[s.jsx("div",{className:"px-2 pb-1.5 pt-3 text-xs font-semibold uppercase tracking-wide text-muted-foreground",children:e("settings.agents.sidebar.section.custom")}),J.map(({name:U,agents:le})=>s.jsx(dr,{label:U,count:le.length,storageKey:"agents",children:le.map(_=>s.jsx(Ji,{agent:_,isSelected:f===_.name,onSelect:()=>{C(_.name),t?.()},onRename:()=>$(_),onDelete:()=>w(_),onDuplicate:()=>D(_),getAgentModeIcon:k,isMenuOpen:d===_.name,onMenuOpenChange:H=>P(H?_.name:null)},_.name))},U)),ee.map(U=>s.jsx(Ji,{agent:U,isSelected:f===U.name,onSelect:()=>{C(U.name),t?.()},onRename:()=>$(U),onDelete:()=>w(U),onDuplicate:()=>D(U),getAgentModeIcon:k,isMenuOpen:d===U.name,onMenuOpenChange:le=>P(le?U.name:null)},U.name))]})]})}),s.jsx(Kt,{open:l!==null&&c!==null,onOpenChange:U=>{!U&&!p&&T()},children:s.jsxs(zt,{className:"max-w-md",children:[s.jsxs(_t,{children:[s.jsx($t,{children:e(c==="delete"?"settings.agents.sidebar.dialog.deleteTitle":"settings.agents.sidebar.dialog.resetTitle")}),s.jsx(Vt,{children:c==="delete"?e("settings.agents.sidebar.dialog.deleteDescription",{name:l?.name??""}):e("settings.agents.sidebar.dialog.resetDescription",{name:l?.name??""})})]}),s.jsxs(ts,{children:[s.jsx(V,{size:"sm",variant:"ghost",onClick:T,disabled:p,children:e("settings.common.actions.cancel")}),s.jsx(V,{size:"sm",onClick:S,disabled:p,children:e(c==="delete"?"settings.common.actions.delete":"settings.common.actions.reset")})]})]})}),s.jsx(Kt,{open:a!==null,onOpenChange:U=>!U&&n(null),children:s.jsxs(zt,{children:[s.jsxs(_t,{children:[s.jsx($t,{children:e("settings.agents.sidebar.renameDialog.title")}),s.jsx(Vt,{children:e("settings.agents.sidebar.renameDialog.description",{name:a?.name??""})})]}),s.jsx(He,{value:r,onChange:U=>i(U.target.value),placeholder:e("settings.agents.sidebar.renameDialog.placeholder"),className:"text-foreground placeholder:text-muted-foreground",onKeyDown:U=>{U.key==="Enter"&&B()}}),s.jsxs(ts,{children:[s.jsx(V,{size:"sm",variant:"ghost",onClick:()=>n(null),children:e("settings.common.actions.cancel")}),s.jsx(V,{size:"sm",onClick:B,children:e("settings.common.actions.rename")})]})]})})]})},Ji=t=>{const e=ut.c(52),{agent:a,isSelected:n,onSelect:r,onDelete:i,onReset:l,onRename:g,onDuplicate:c,getAgentModeIcon:y,isMenuOpen:p,onMenuOpenChange:b}=t,{t:d}=tt(),P=a;let f;e[0]===Symbol.for("react.memo_cache_sentinel")?(f=_a(),e[0]=f):f=e[0];const C=f,[v,N]=o.useState(!1);let m;e[1]!==i||e[2]!==c||e[3]!==g||e[4]!==l||e[5]!==d?(m=le=>s.jsxs(s.Fragment,{children:[g&&s.jsxs(le,{onClick:_=>{_.stopPropagation(),g()},children:[s.jsx(O,{name:"edit",className:"h-4 w-4 mr-px"}),d("settings.common.actions.rename")]}),s.jsxs(le,{onClick:_=>{_.stopPropagation(),c()},children:[s.jsx(O,{name:"file-copy",className:"h-4 w-4 mr-px"}),d("settings.common.actions.duplicate")]}),l&&s.jsxs(le,{onClick:_=>{_.stopPropagation(),l()},children:[s.jsx(O,{name:"restart",className:"h-4 w-4 mr-px"}),d("settings.common.actions.reset")]}),i&&s.jsxs(le,{onClick:_=>{_.stopPropagation(),i()},className:"text-destructive focus:text-destructive",children:[s.jsx(O,{name:"delete-bin",className:"h-4 w-4 mr-px"}),d("settings.common.actions.delete")]})]}),e[1]=i,e[2]=c,e[3]=g,e[4]=l,e[5]=d,e[6]=m):m=e[6];const A=m,R=n?"bg-interactive-selection":"hover:bg-interactive-hover";let I;e[7]!==R?(I=xe("group relative flex items-center rounded-md px-1.5 py-1 transition-all duration-200 select-none",R),e[7]=R,e[8]=I):I=e[8];let j;e[9]===Symbol.for("react.memo_cache_sentinel")?(j=C?void 0:le=>{le.preventDefault(),N(!0)},e[9]=j):j=e[9];let h;e[10]!==I?(h=s.jsx("div",{className:I,onContextMenu:j}),e[10]=I,e[11]=h):h=e[11];let w;e[12]!==a.name?(w=s.jsx("span",{className:"typography-ui-label font-normal truncate text-foreground",children:a.name}),e[12]=a.name,e[13]=w):w=e[13];let F;e[14]!==a.mode||e[15]!==y?(F=y(a.mode),e[14]=a.mode,e[15]=y,e[16]=F):F=e[16];let T;e[17]!==a||e[18]!==P.scope||e[19]!==d?(T=(P.scope||ma(a))&&s.jsx("span",{className:"typography-micro text-muted-foreground bg-muted px-1 rounded flex-shrink-0 leading-none pb-px border border-border/50",children:ma(a)?d("settings.agents.sidebar.badge.system"):P.scope}),e[17]=a,e[18]=P.scope,e[19]=d,e[20]=T):T=e[20];let S;e[21]!==w||e[22]!==F||e[23]!==T?(S=s.jsxs("div",{className:"flex items-center gap-1.5",children:[w,F,T]}),e[21]=w,e[22]=F,e[23]=T,e[24]=S):S=e[24];let D;e[25]!==a.description?(D=a.description&&s.jsx("div",{className:"typography-micro text-muted-foreground/60 truncate leading-tight",children:a.description}),e[25]=a.description,e[26]=D):D=e[26];let $;e[27]!==r||e[28]!==S||e[29]!==D?($=s.jsxs("button",{onClick:r,className:"flex min-w-0 flex-1 flex-col gap-0 rounded-sm text-left focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-primary/50",tabIndex:0,children:[S,D]}),e[27]=r,e[28]=S,e[29]=D,e[30]=$):$=e[30];let B;e[31]!==b?(B=le=>{le&&N(!1),b(le)},e[31]=b,e[32]=B):B=e[32];let k;e[33]===Symbol.for("react.memo_cache_sentinel")?(k=s.jsx(on,{asChild:!0,children:s.jsx(V,{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(O,{name:"more-2",className:"h-3.5 w-3.5"})})}),e[33]=k):k=e[33];let G;e[34]!==A?(G=s.jsx(ln,{align:"end",className:"w-fit min-w-20",children:A(dn)}),e[34]=A,e[35]=G):G=e[35];let M;e[36]!==p||e[37]!==B||e[38]!==G?(M=s.jsxs(cn,{open:p,onOpenChange:B,children:[k,G]}),e[36]=p,e[37]=B,e[38]=G,e[39]=M):M=e[39];let L;e[40]!==$||e[41]!==M?(L=s.jsxs("div",{className:"flex min-w-0 flex-1 items-center",children:[$,M]}),e[40]=$,e[41]=M,e[42]=L):L=e[42];let J;e[43]!==L||e[44]!==h?(J=s.jsx(Jn,{render:h,children:L}),e[43]=L,e[44]=h,e[45]=J):J=e[45];let ee;e[46]!==A?(ee=s.jsx(Wn,{className:"w-fit min-w-20",children:A(qn)}),e[46]=A,e[47]=ee):ee=e[47];let U;return e[48]!==v||e[49]!==J||e[50]!==ee?(U=s.jsxs(Qn,{open:v,onOpenChange:N,children:[J,ee]}),e[48]=v,e[49]=J,e[50]=ee,e[51]=U):U=e[51],U},es=t=>{const e=ut.c(21),{children:a,className:n,outerClassName:r,title:i,titleLeading:l,titleAccessory:g,description:c,headerEnd:y,showSaveStatus:p}=t,b=p===void 0?!1:p,d=i!=null||c!=null||y!=null||b,P=typeof i=="string"||typeof i=="number",f=l!=null||g!=null;let C;e[0]!==r?(C=xe("h-full",r),e[0]=r,e[1]=C):C=e[1];let v;e[2]!==n?(v=xe("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]=v):v=e[3];let N;e[4]!==c||e[5]!==d||e[6]!==f||e[7]!==y||e[8]!==P||e[9]!==b||e[10]!==i||e[11]!==g||e[12]!==l?(N=d&&s.jsxs("div",{className:"mb-2 flex flex-wrap items-start justify-between gap-x-4 gap-y-3 pb-6",children:[s.jsxs("div",{className:"min-w-0 flex-1 basis-64 space-y-1",children:[i!=null?P?f?s.jsxs("div",{className:"flex min-w-0 items-center gap-2",children:[l,s.jsx("h1",{"data-settings-page-heading":!0,tabIndex:-1,className:xe(lr,"min-w-0 truncate"),children:i}),s.jsx("span",{className:"shrink-0",children:g})]}):s.jsx("h1",{"data-settings-page-heading":!0,tabIndex:-1,className:lr,children:i}):i:null,c!=null?typeof c=="string"||typeof c=="number"?s.jsx("p",{className:vc,children:c}):c:null]}),s.jsxs("div",{className:"flex shrink-0 flex-wrap items-center justify-end gap-3",children:[y,b&&s.jsx(ju,{})]})]}),e[4]=c,e[5]=d,e[6]=f,e[7]=y,e[8]=P,e[9]=b,e[10]=i,e[11]=g,e[12]=l,e[13]=N):N=e[13];let m;e[14]!==a||e[15]!==v||e[16]!==N?(m=s.jsxs("div",{className:v,children:[N,a]}),e[14]=a,e[15]=v,e[16]=N,e[17]=m):m=e[17];let A;return e[18]!==C||e[19]!==m?(A=s.jsx(vs,{outerClassName:C,className:"w-full @container",children:m}),e[18]=C,e[19]=m,e[20]=A):A=e[20],A},wu=500,ju=()=>{const t=ut.c(13),{t:e}=tt(),a=o.useSyncExternalStore(hd,Wr,Wr),[n,r]=o.useState(!1);let i,l;if(t[0]!==a?(i=()=>{if(a!=="saving"){r(!1);return}const p=setTimeout(()=>r(!0),wu);return()=>clearTimeout(p)},l=[a],t[0]=a,t[1]=i,t[2]=l):(i=t[1],l=t[2]),o.useEffect(i,l),a==="error"){let p;t[3]===Symbol.for("react.memo_cache_sentinel")?(p=s.jsx(O,{name:"error-warning",className:"size-3.5"}),t[3]=p):p=t[3];let b;t[4]!==e?(b=e("settings.common.status.saveFailed"),t[4]=e,t[5]=b):b=t[5];let d;return t[6]!==b?(d=s.jsxs("div",{"aria-live":"assertive",className:"flex shrink-0 items-center gap-1.5 typography-meta text-[var(--status-error)]",children:[p,s.jsx("span",{children:b})]}),t[6]=b,t[7]=d):d=t[7],d}if(a!=="saving"||!n)return null;let g;t[8]===Symbol.for("react.memo_cache_sentinel")?(g=s.jsx(O,{name:"loader-4",className:"size-3.5 animate-spin"}),t[8]=g):g=t[8];let c;t[9]!==e?(c=e("settings.common.actions.saving"),t[9]=e,t[10]=c):c=t[10];let y;return t[11]!==c?(y=s.jsxs("div",{"aria-live":"polite",className:"flex shrink-0 items-center gap-1.5 typography-meta text-muted-foreground",children:[g,s.jsx("span",{children:c})]}),t[11]=c,t[12]=y):y=t[12],y},ku=["allow","ask","deny"],Oa=t=>t==="allow"||t==="ask"||t==="deny",ur=()=>({global:null,keys:{}}),Nu=t=>{const e=ur();if(t==null)return e;if(typeof t=="string")return Oa(t)&&(e.global=t),e;if(typeof t!="object"||Array.isArray(t))return e;for(const[a,n]of Object.entries(t)){if(a==="*"){Oa(n)&&(e.global=n);continue}const r={action:null,patterns:[]};if(Oa(n))r.action=n;else if(n&&typeof n=="object"&&!Array.isArray(n))for(const[i,l]of Object.entries(n))Oa(l)&&(i==="*"?r.action=l:r.patterns.push({pattern:i,action:l}));else continue;e.keys[a]=r}return e},pr=t=>{const e={};t.global!==null&&(e["*"]=t.global);for(const[a,n]of Object.entries(t.keys)){const r=n.patterns.filter(i=>i.pattern.trim().length>0);if(n.action!==null&&r.length===0)e[a]=n.action;else if(r.length>0){const i={};n.action!==null&&(i["*"]=n.action);for(const l of r)i[l.pattern]=l.action;e[a]=i}}return Object.keys(e).length>0?e:null},Su=(t,e)=>JSON.stringify(pr(t))===JSON.stringify(pr(e)),jn=t=>JSON.parse(JSON.stringify(t)),Cu=["edit","external_directory","doom_loop","plan_enter","plan_exit"],Iu=new Set(["read","edit","glob","grep","list","bash","task","external_directory","lsp","skill"]),mo=new Set(["write","patch","apply_patch","multiedit","invalid"]),Pu=t=>t.split(/[_-]/).filter(Boolean).map(e=>e.charAt(0).toUpperCase()+e.slice(1)).join(" "),Au=({agent:t})=>{const{t:e}=tt(),a=Hn(z=>z.updateAgent),[n,r]=o.useState(ur),[i,l]=o.useState(ur),[g,c]=o.useState(!0),[y,p]=o.useState(!1),[b,d]=o.useState(!1),[P,f]=o.useState({}),[C,v]=o.useState([]),[N,m]=o.useState(""),[A,R]=o.useState(0),I=t.name,j=_s();o.useEffect(()=>{let z=!1;return c(!0),p(!1),(async()=>{try{const K=j,te=K?`?directory=${encodeURIComponent(K)}`:"",Y=await yt(`/api/config/agents/${encodeURIComponent(I)}/config${te}`,{headers:{"Cache-Control":"no-cache",...K?{"x-opencode-directory":K}:{}}});if(!Y.ok)throw new Error(String(Y.status));const ae=await Y.json().catch(()=>null);if(z)return;const ge=Nu(ae?.config?.permission);r(jn(ge)),l(ge)}catch{z||p(!0)}finally{z||c(!1)}})(),()=>{z=!0}},[I,A,j]),o.useEffect(()=>{let z=!1;return(async()=>{try{const K=await fn.listToolIds({directory:j});!z&&Array.isArray(K)&&v(K.filter(te=>typeof te=="string"&&!mo.has(te)))}catch{}})(),()=>{z=!0}},[I,j]);const h=o.useMemo(()=>{const z=t.permission;if(!Array.isArray(z))return[];const K=[];for(const te of z){if(!te||typeof te!="object")continue;const{permission:Y,pattern:ae,action:ge}=te;typeof Y=="string"&&typeof ae=="string"&&Oa(ge)&&K.push({permission:Y,pattern:ae,action:ge})}return K},[t]),w=o.useCallback(z=>{const K=h.find(Y=>Y.permission===z&&Y.pattern==="*");if(K)return K.action;const te=h.find(Y=>Y.permission==="*"&&Y.pattern==="*");return te?te.action:null},[h]),F=o.useCallback(z=>{const K=i.keys[z]?.patterns??[],te=new Set(K.map(Y=>Y.pattern));return h.filter(Y=>Y.permission===z&&Y.pattern!=="*"&&!te.has(Y.pattern))},[h,i.keys]),T=o.useMemo(()=>{const z=new Set;for(const K of C)z.add(K);for(const K of Cu)z.add(K);for(const K of Object.keys(i.keys))z.add(K);for(const K of mo)z.delete(K);return Array.from(z).sort((K,te)=>K.localeCompare(te))},[C,i.keys]),S=o.useMemo(()=>!Su(i,n),[i,n]),D=z=>{l(K=>({...K,global:z}))},$=(z,K)=>{l(te=>{const Y=jn(te),ae=Y.keys[z]??{action:null,patterns:[]};return ae.action=K,ae.action===null&&ae.patterns.length===0?delete Y.keys[z]:Y.keys[z]=ae,Y})},B=(z,K,te,Y)=>{l(ae=>{const ge=jn(ae),de=ge.keys[z]??{action:null,patterns:[]};return de.patterns[K]={pattern:te,action:Y},ge.keys[z]=de,ge})},k=z=>{l(K=>{const te=jn(K),Y=te.keys[z]??{action:null,patterns:[]};return Y.patterns.push({pattern:"",action:"allow"}),te.keys[z]=Y,te}),f(K=>({...K,[z]:!0}))},G=(z,K)=>{l(te=>{const Y=jn(te),ae=Y.keys[z];return ae?(ae.patterns.splice(K,1),ae.action===null&&ae.patterns.length===0&&delete Y.keys[z],Y):te})},M=()=>{const z=N.trim();!z||z==="*"||(l(K=>{if(K.keys[z])return K;const te=jn(K);return te.keys[z]={action:"ask",patterns:[]},te}),f(K=>({...K,[z]:!0})),m(""))},L=async()=>{d(!0);try{const z=pr(i),K=await a(I,{permission:z});K.ok?(r(jn(i)),E.success(K.requiresManualRestart?e("settings.agents.page.permissionsEditor.toast.savedRestartRequired"):e("settings.agents.page.permissionsEditor.toast.saved"))):E.error(e("settings.agents.page.permissionsEditor.toast.saveFailed"))}finally{d(!1)}},J=()=>{l(jn(n))},ee=z=>e(z==="allow"?"settings.agents.page.permissionsEditor.action.allow":z==="ask"?"settings.agents.page.permissionsEditor.action.ask":"settings.agents.page.permissionsEditor.action.deny"),U=e("settings.agents.page.permissionsEditor.action.inherit"),le=e("settings.agents.page.permissionsEditor.action.default"),_=z=>[...z?[{value:"inherit",label:z}]:[],...ku.map(K=>({value:K,label:ee(K)}))],H=(z,K,te,Y=U)=>s.jsx(Ys,{value:z??"inherit",options:_(Y),onChange:ae=>K(ae==="inherit"?null:ae),"aria-label":te});return g?s.jsx(ze,{title:e("settings.agents.page.section.toolPermissions"),children:s.jsx("p",{className:zn,children:e("common.loading")})}):y?s.jsx(ze,{title:e("settings.agents.page.section.toolPermissions"),children:s.jsxs("div",{className:"flex items-center gap-3",children:[s.jsx("p",{className:"typography-meta text-[var(--status-error)]",children:e("settings.agents.page.permissionsEditor.state.loadFailed")}),s.jsx(V,{variant:"outline",size:"xs",onClick:()=>R(z=>z+1),children:e("settings.agents.page.permissionsEditor.actions.retry")})]})}):s.jsxs(ze,{title:e("settings.agents.page.section.toolPermissions"),settingsItem:"agents.permissions",info:e("settings.agents.page.permissionsEditor.sectionInfo"),headerAction:S?s.jsxs("div",{className:"flex items-center gap-2",children:[s.jsx(V,{variant:"ghost",size:"xs",className:"!font-normal",onClick:J,disabled:b,children:e("settings.agents.page.permissionsEditor.actions.discard")}),s.jsx(V,{size:"xs",className:"!font-normal",onClick:()=>{L()},disabled:b,children:e(b?"settings.common.actions.saving":"settings.agents.page.permissionsEditor.actions.save")})]}):void 0,contentClassName:"space-y-4",children:[s.jsxs("div",{className:"flex flex-col gap-2 pb-2 @xl:flex-row @xl:items-center @xl:justify-between",children:[s.jsxs("div",{className:"flex items-center gap-1.5",children:[s.jsx("span",{className:Tt,children:e("settings.agents.page.permissionsEditor.defaultLabel")}),s.jsx(Jt,{children:e("settings.agents.page.permissionsEditor.defaultInfo")}),i.global===null&&s.jsx("span",{className:"typography-micro text-muted-foreground",children:e("settings.agents.page.permissionsEditor.effectiveHint",{action:ee(w("*")??"allow")})})]}),H(i.global,D,e("settings.agents.page.permissionsEditor.defaultAria"),le)]}),s.jsx("div",{children:T.map(z=>{const K=i.keys[z]??{action:null,patterns:[]},te=F(z),Y=Iu.has(z)||K.patterns.length>0,ae=Y||te.length>0,ge=P[z]===!0,de=w(z);return s.jsxs("div",{className:"border-t border-border/40 py-2",children:[s.jsxs("div",{className:"flex flex-col gap-2 @xl:flex-row @xl:items-center @xl:justify-between",children:[s.jsxs("button",{type:"button",onClick:ae?()=>f(he=>({...he,[z]:!ge})):void 0,className:xe("flex min-w-0 items-center gap-1.5 text-left",!ae&&"cursor-default"),"aria-expanded":ae?ge:void 0,children:[s.jsx(O,{name:ge&&ae?"arrow-down-s":"arrow-right-s",className:xe("h-3.5 w-3.5 shrink-0 text-muted-foreground",!ae&&"opacity-0")}),s.jsx("span",{className:Tt,children:Pu(z)}),s.jsx("span",{className:"typography-micro font-mono text-muted-foreground/70",children:z}),K.action===null&&de!==null&&s.jsx("span",{className:"typography-micro text-muted-foreground",children:e("settings.agents.page.permissionsEditor.effectiveHint",{action:ee(de)})}),K.patterns.length>0&&s.jsx("span",{className:"typography-micro rounded bg-muted px-1 text-muted-foreground",children:e("settings.agents.page.permissionsEditor.ruleCount",{count:String(K.patterns.length)})})]}),H(K.action,he=>$(z,he),e("settings.agents.page.permissionsEditor.keyAria",{key:z}))]}),ge&&ae&&s.jsxs("div",{className:"mt-2 space-y-2 pl-5",children:[K.patterns.map((he,se)=>s.jsxs("div",{className:"flex flex-wrap items-center gap-2",children:[s.jsx(He,{value:he.pattern,onChange:re=>B(z,se,re.target.value,he.action),placeholder:e("settings.agents.page.permissionsEditor.patternPlaceholder"),className:"h-8 w-full max-w-[24rem] min-w-0 flex-1 font-mono text-xs"}),s.jsx(Ys,{value:he.action,options:_(),onChange:re=>B(z,se,he.pattern,re),"aria-label":e("settings.agents.page.permissionsEditor.patternActionAria",{key:z})}),s.jsx(V,{variant:"ghost",size:"icon",className:"h-7 w-7 shrink-0 text-muted-foreground hover:bg-destructive/10 hover:text-destructive",onClick:()=>G(z,se),"aria-label":e("settings.agents.page.permissionsEditor.actions.removeRuleAria"),children:s.jsx(O,{name:"close",className:"h-3.5 w-3.5"})})]},se)),Y&&s.jsxs(V,{variant:"outline",size:"xs",className:"!font-normal",onClick:()=>k(z),children:[s.jsx(O,{name:"add",className:"mr-1 h-3.5 w-3.5"}),e("settings.agents.page.permissionsEditor.actions.addRule")]}),te.length>0&&s.jsxs("div",{className:"space-y-1 pt-1",children:[s.jsxs("div",{className:"flex items-center gap-1.5",children:[s.jsx("span",{className:"typography-micro font-medium text-muted-foreground",children:e("settings.agents.page.permissionsEditor.sessionRulesTitle")}),s.jsx(Jt,{children:e("settings.agents.page.permissionsEditor.sessionRulesInfo")})]}),te.map(he=>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:he.pattern}),s.jsx("span",{className:"typography-micro text-muted-foreground",children:ee(he.action)})]},`${he.pattern}-${he.action}`))]})]})]},z)})}),s.jsxs("div",{className:"flex flex-wrap items-center gap-2 border-t border-border/40 pt-3",children:[s.jsx(He,{value:N,onChange:z=>m(z.target.value),onKeyDown:z=>{z.key==="Enter"&&(z.preventDefault(),M())},placeholder:e("settings.agents.page.permissionsEditor.customKeyPlaceholder"),className:"h-8 w-full max-w-[16rem] font-mono text-xs"}),s.jsxs(V,{variant:"outline",size:"xs",className:"!font-normal",onClick:M,disabled:!N.trim(),children:[s.jsx(O,{name:"add",className:"mr-1 h-3.5 w-3.5"}),e("settings.agents.page.permissionsEditor.actions.addKey")]})]})]})},Tu=(t,e)=>{const a=xa(e);if(!a)return[];const r=t.find(i=>i.id===a.providerId)?.models?.find(i=>i.id===a.modelId);return r?.variants?Object.keys(r.variants):[]},Eu=()=>{const{t}=tt(),e=Ye(H=>H.providers),{selectedAgentName:a,getAgentByName:n,createAgent:r,updateAgent:i,agentDraft:l,setAgentDraft:g}=Hn(Us(H=>({selectedAgentName:H.selectedAgentName,getAgentByName:H.getAgentByName,createAgent:H.createAgent,updateAgent:H.updateAgent,agentDraft:H.agentDraft,setAgentDraft:H.setAgentDraft}))),c=_s(),y=Hn(H=>fl(H,c)),p=a?n(a,c):null,b=!!(l&&l.name===a&&!p),[d,P]=o.useState(""),[f,C]=o.useState("user"),[v,N]=o.useState(""),[m,A]=o.useState("subagent"),[R,I]=o.useState(""),[j,h]=o.useState(""),[w,F]=o.useState(void 0),[T,S]=o.useState(void 0),[D,$]=o.useState(""),[B,k]=o.useState(!1),G=o.useRef(null),M=o.useMemo(()=>Tu(e,R),[R,e]),L=M.length>0,J=j||"__default",ee=L,U=o.useMemo(()=>j&&!M.includes(j)?[j,...M]:M,[j,M]);o.useEffect(()=>{if(b&&l){const H=l.name||"",z=l.scope||"user",K=l.description||"",te=l.mode||"subagent",Y=l.model||"",ae=l.variant||"",ge=l.temperature??void 0,de=l.top_p??void 0,he=l.prompt||"";P(H),C(z),N(K),A(te),I(Y),h(ae),F(ge),S(de),$(he),G.current={draftName:H,draftScope:z,description:K,mode:te,model:Y,variant:ae,temperature:ge,topP:de,prompt:he};return}if(p&&a===p.name){const H=p.description||"",z=p.mode||"subagent",K=p.model?.providerID&&p.model?.modelID?`${p.model.providerID}/${p.model.modelID}`:"",te=p.variant||"",Y=p.temperature??void 0,ae=p.topP??void 0,ge=p.prompt||"";N(H),A(z),I(K),h(te),F(Y),S(ae),$(ge),G.current={draftName:"",draftScope:"user",description:H,mode:z,model:K,variant:te,temperature:Y,topP:ae,prompt:ge}}},[l,b,p,a]);const le=o.useMemo(()=>{const H=G.current;return H?!!(b&&(d!==H.draftName||f!==H.draftScope)||v!==H.description||m!==H.mode||R!==H.model||j!==H.variant||w!==H.temperature||T!==H.topP||D!==H.prompt):!1},[v,d,f,b,m,R,D,w,T,j]),_=async()=>{const H=b?d.trim().replace(/\s+/g,"-"):a?.trim();if(!H){E.error(t("settings.agents.sidebar.toast.agentNameRequired"));return}if(b&&y.some(z=>z.name===H)){E.error(t("settings.agents.sidebar.toast.agentExists"));return}k(!0);try{const z=R.trim(),K=j.trim(),te=D.trim(),Y={name:H,...v.trim()?{description:v.trim()}:{},mode:m,model:z===""?null:z,variant:K===""?null:K||void 0,temperature:w??null,top_p:T??null,prompt:te||(b?void 0:null),...b&&f?{scope:f}:{}};let ae;b?(ae=await r(Y,c),ae.ok&&g(null)):ae=await i(H,Y,c),ae.ok?ae.requiresManualRestart?E.warning(t("settings.agents.page.toast.savedManualRestart")):ae.restartDeferred?E.success(t("settings.view.pendingRestart.saved")):E.success(t(b?"settings.agents.page.toast.created":"settings.agents.page.toast.updated")):E.error(t(b?"settings.agents.page.toast.createFailed":"settings.agents.page.toast.updateFailed"))}catch(z){console.error("Error saving agent:",z);const K=z instanceof Error&&z.message?z.message:t("settings.agents.page.toast.saveUnexpectedError");E.error(K)}finally{k(!1)}};return a?s.jsxs(es,{title:b?t("settings.agents.page.title.new"):a,description:t(b?"settings.agents.page.subtitle.new":"settings.agents.page.subtitle.edit"),showSaveStatus:!1,children:[s.jsxs(ze,{title:t("settings.agents.page.section.identityRole"),divider:!1,contentClassName:"space-y-0",children:[b&&s.jsxs(Rt,{settingsItem:"agents.name",label:t("settings.agents.page.field.agentName"),children:[s.jsxs("div",{className:"flex items-center",children:[s.jsx("span",{className:"typography-ui-label text-muted-foreground mr-1",children:"@"}),s.jsx(He,{value:d,onChange:H=>P(H.target.value),placeholder:t("settings.agents.page.field.agentNamePlaceholder"),className:"h-7 w-40 px-2"})]}),s.jsxs(St,{value:f,onValueChange:H=>C(H),children:[s.jsx(Ct,{size:Ft,className:"w-fit min-w-[100px]",children:s.jsx(Mt,{placeholder:t("settings.agents.page.field.scopePlaceholder")})}),s.jsxs(It,{align:"end",children:[s.jsx(at,{value:"user",children:s.jsxs("div",{className:"flex items-center gap-2",children:[s.jsx(O,{name:"user-3",className:"h-3.5 w-3.5"}),s.jsx("span",{children:t("settings.common.scope.global")})]})}),s.jsx(at,{value:"project",children:s.jsxs("div",{className:"flex items-center gap-2",children:[s.jsx(O,{name:"folder",className:"h-3.5 w-3.5"}),s.jsx("span",{children:t("settings.common.scope.project")})]})})]})]})]}),s.jsx(qt,{label:t("settings.common.field.description"),controlClassName:"w-full max-w-none",children:s.jsx(Ts,{value:v,onChange:H=>N(H.target.value),placeholder:t("settings.agents.page.field.descriptionPlaceholder"),rows:2,className:"w-full resize-none min-h-[60px] bg-transparent"})}),s.jsx(qt,{settingsItem:"agents.mode",label:t("settings.agents.page.field.mode"),info:t("settings.agents.page.field.modeTooltip"),children:s.jsx(Ys,{"aria-label":t("settings.agents.page.field.mode"),value:m,onChange:A,options:[{value:"primary",label:t("settings.agents.page.mode.primary")},{value:"subagent",label:t("settings.agents.page.mode.subagent")},{value:"all",label:t("settings.agents.page.mode.all")}]})})]}),s.jsxs(ze,{title:t("settings.agents.page.section.modelParameters"),contentClassName:"space-y-3",children:[s.jsx(Rt,{settingsItem:"agents.model",label:t("settings.agents.page.field.overrideModel"),children:s.jsx(Fa,{providerId:xa(R)?.providerId??"",modelId:xa(R)?.modelId??"",onChange:(H,z)=>{I(H&&z?`${H}/${z}`:""),h("")},className:In})}),s.jsx(Rt,{settingsItem:"agents.variant",label:t("settings.agents.page.field.variant"),info:s.jsxs("div",{className:"space-y-1",children:[s.jsx("p",{children:t("settings.agents.page.field.variantTooltip")}),s.jsx("p",{children:t("settings.agents.page.field.variantHint")})]}),children:ee?s.jsxs(St,{value:J,onValueChange:H=>h(H==="__default"?"":H),children:[s.jsx(Ct,{size:Ft,className:rn,children:s.jsx(Mt,{placeholder:t("settings.agents.page.field.variantPlaceholder"),children:H=>H==="__default"?t("chat.modelControls.default"):H})}),s.jsxs(It,{children:[s.jsx(at,{value:"__default",children:t("chat.modelControls.default")}),U.map(H=>s.jsx(at,{value:H,children:H},H))]})]}):s.jsxs(s.Fragment,{children:[s.jsx(He,{value:j,onChange:H=>h(H.target.value),placeholder:t("settings.agents.page.field.variantPlaceholder"),disabled:!R&&!j,className:"h-8 w-40 rounded-md px-3"}),j&&s.jsx(V,{size:"sm",type:"button",variant:"ghost",onClick:()=>h(""),className:Cs,"aria-label":t("settings.common.actions.clear"),title:t("settings.common.actions.clear"),children:s.jsx(O,{name:"close",className:"h-3.5 w-3.5"})})]})}),s.jsxs(Rt,{settingsItem:"agents.temperature",label:t("settings.agents.page.field.temperature"),info:s.jsxs("div",{className:"space-y-1",children:[s.jsx("p",{children:t("settings.agents.page.field.temperatureTooltip")}),s.jsx("p",{children:t("settings.agents.page.field.temperatureRange")})]}),children:[s.jsx(xs,{value:w,fallbackValue:.7,onValueChange:F,onClear:()=>F(void 0),min:0,max:2,step:.1,inputMode:"decimal",placeholder:"—",emptyLabel:"—",className:Ps}),w!==void 0&&s.jsx(V,{size:"sm",type:"button",variant:"ghost",onClick:()=>F(void 0),className:Cs,"aria-label":t("settings.agents.page.field.clearTemperatureAria"),title:t("settings.common.actions.clear"),children:s.jsx(O,{name:"close",className:"h-3.5 w-3.5"})})]}),s.jsxs(Rt,{settingsItem:"agents.top-p",label:t("settings.agents.page.field.topP"),info:s.jsxs("div",{className:"space-y-1",children:[s.jsx("p",{children:t("settings.agents.page.field.topPTooltip")}),s.jsx("p",{children:t("settings.agents.page.field.topPRange")})]}),children:[s.jsx(xs,{value:T,fallbackValue:.9,onValueChange:S,onClear:()=>S(void 0),min:0,max:1,step:.1,inputMode:"decimal",placeholder:"—",emptyLabel:"—",className:Ps}),T!==void 0&&s.jsx(V,{size:"sm",type:"button",variant:"ghost",onClick:()=>S(void 0),className:Cs,"aria-label":t("settings.agents.page.field.clearTopPAria"),title:t("settings.common.actions.clear"),children:s.jsx(O,{name:"close",className:"h-3.5 w-3.5"})})]})]}),s.jsx(ze,{title:t("settings.agents.page.section.systemPrompt"),settingsItem:"agents.system-prompt",children:s.jsx(Ts,{value:D,onChange:H=>$(H.target.value),placeholder:t("settings.agents.page.field.systemPromptPlaceholder"),rows:8,className:"w-full font-mono typography-meta min-h-[120px] max-h-[60vh] bg-transparent resize-y"})}),!b&&p&&s.jsx(Au,{agent:p}),s.jsx("div",{className:"pb-8",children:s.jsx(V,{onClick:_,disabled:B||!le,size:"xs",className:"!font-normal",children:t(B?"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(O,{name:"robot-2",className:"mx-auto mb-3 h-12 w-12 opacity-50"}),s.jsx("p",{className:"typography-body",children:t("settings.agents.page.empty.title")}),s.jsx("p",{className:"typography-meta mt-1 opacity-75",children:t("settings.agents.page.empty.description")})]})})},Du=Xd({content:ao(),exists:eu(),path:ao().min(1).optional()}),Mu=async(t,e)=>{const a=await t.json().catch(()=>null);return typeof a?.error=="string"&&a.error.trim()?a.error:e},Ru=t=>t.length>0&&!t.endsWith(`
|
|
2
|
+
`)?`${t}
|
|
3
|
+
`:t,ii={prompt:"",optimizeSystemPrompt:!1,responseStyleEnabled:!1,responseStylePreset:"concise",responseStyleCustomInstructions:""},Lu=(t,e)=>t==="custom"?e:wc(t),Ou=t=>t==="custom"?"custom":xl(t)?t:"concise",go={concise:"settings.behavior.page.responseStyle.option.concise",detailed:"settings.behavior.page.responseStyle.option.detailed",mentor:"settings.behavior.page.responseStyle.option.mentor",pushback:"settings.behavior.page.responseStyle.option.pushback",noFiller:"settings.behavior.page.responseStyle.option.noFiller",matchEnergy:"settings.behavior.page.responseStyle.option.matchEnergy",warmPeer:"settings.behavior.page.responseStyle.option.warmPeer"},Qi=async(t,e)=>{if(!(await gt(t)).ok)throw new Error(e)},Fu=()=>{const{t}=tt(),e=yc(),[a,n]=o.useState(""),[r,i]=o.useState("AGENTS.md"),[l,g]=o.useState(!1),[c,y]=o.useState(ii.responseStyleEnabled),[p,b]=o.useState(ii.responseStylePreset),[d,P]=o.useState(ii.responseStyleCustomInstructions),[f,C]=o.useState(!0),[v,N]=o.useState(!1),[m,A]=o.useState(!1),[R,I]=o.useState(""),[j,h]=o.useState(!1),w=o.useRef(null);o.useEffect(()=>{const B=new AbortController;return(async()=>{try{const[G,M]=await Promise.all([pn(),yt("/api/behavior/agents-md",{method:"GET",headers:{Accept:"application/json"},signal:B.signal})]);let L=ii;if(G&&(L={...L,optimizeSystemPrompt:G.optimizeSystemPrompt===!0,responseStyleEnabled:G.responseStyleEnabled===!0,responseStylePreset:Ou(G.responseStylePreset),responseStyleCustomInstructions:G.responseStyleCustomInstructions??""},G.globalBehaviorPrompt!==void 0&&(L={...L,prompt:G.globalBehaviorPrompt})),M.ok){const J=Du.parse(await M.json());if(B.signal.aborted)return;i(J.path??"AGENTS.md"),L.prompt.trim()||(L={...L,prompt:J.content})}n(L.prompt),g(L.optimizeSystemPrompt),h(L.optimizeSystemPrompt),y(L.responseStyleEnabled),b(L.responseStylePreset),P(L.responseStyleCustomInstructions),I(L.prompt),w.current={enabled:L.responseStyleEnabled,preset:L.responseStylePreset,custom:L.responseStyleCustomInstructions}}catch(G){G.name!=="AbortError"&&console.warn("Failed to load behavior settings:",G)}finally{C(!1)}})(),()=>B.abort()},[]),o.useEffect(()=>{if(f)return;const B=w.current;if(B&&B.enabled===c&&B.preset===p&&B.custom===d)return;const k={enabled:c,preset:p,custom:d},G=setTimeout(async()=>{try{await Qi({responseStyleEnabled:k.enabled,responseStylePreset:k.preset,responseStyleCustomInstructions:k.custom},t("settings.behavior.page.toast.saveFailed")),w.current=k}catch(M){const L=M instanceof Error?M.message:t("settings.behavior.page.toast.saveFailed");E.error(L)}},400);return()=>clearTimeout(G)},[c,p,d,f,t]);const F=Lu(p,d),T=a!==R,S=l!==j,D=async()=>{N(!0);try{const B=Ru(a),k=await yt("/api/behavior/agents-md",{method:"PUT",headers:{"Content-Type":"application/json",Accept:"application/json"},body:JSON.stringify({content:B})});if(!k.ok)throw new Error(await Mu(k,t("settings.behavior.page.toast.saveFailed")));const G=await k.json().catch(()=>null),M=vl(G,"behavior",{id:"agents-md"});await Qi({globalBehaviorPrompt:B},t("settings.behavior.page.toast.saveFailed")),n(B),I(B),E.success(t(M?"settings.view.pendingRestart.saved":"settings.behavior.page.toast.saved"))}catch(B){console.error("Failed to save behavior:",B);const k=B instanceof Error?B.message:t("settings.behavior.page.toast.saveFailed");E.error(k)}finally{N(!1)}},$=async()=>{A(!0);try{await Qi({optimizeSystemPrompt:l},t("settings.behavior.page.toast.saveFailed")),h(l),$n("behavior",{id:"optimize-system-prompt"}),E.success(t("settings.view.pendingRestart.saved"))}catch(B){const k=B instanceof Error?B.message:t("settings.behavior.page.toast.saveFailed");E.error(k)}finally{A(!1)}};return s.jsxs(es,{title:t("settings.behavior.page.title"),description:t("settings.page.behavior.description"),showSaveStatus:!0,children:[!e&&s.jsxs(ze,{title:t("settings.behavior.page.section.systemPromptOptimization"),divider:!1,settingsItem:"behavior.system-prompt-optimization",contentClassName:"space-y-3",children:[s.jsx(dt,{checked:l,onChange:g,disabled:f||m,label:t("settings.behavior.page.systemPromptOptimization.enable"),ariaLabel:t("settings.behavior.page.systemPromptOptimization.enableAria"),info:t("settings.behavior.page.systemPromptOptimization.info")}),s.jsx(V,{type:"button",size:"xs",onClick:()=>{$()},disabled:f||m||!S,className:"!font-normal",children:t(m?"settings.common.actions.saving":"settings.common.actions.saveChanges")})]}),s.jsxs(ze,{title:t("settings.behavior.page.section.systemPrompt"),info:s.jsxs("div",{className:"space-y-1",children:[s.jsx("p",{className:"font-medium text-foreground",children:t("settings.behavior.page.warning.title")}),s.jsx("p",{children:t("settings.behavior.page.warning.description",{path:r})})]}),settingsItem:"behavior.system-prompt",contentClassName:"space-y-3",children:[s.jsx(Ts,{value:a,onChange:B=>n(B.target.value),placeholder:t("settings.behavior.page.field.systemPromptPlaceholder"),rows:12,disabled:f,outerClassName:"min-h-[160px] max-h-[70vh]",className:"w-full font-mono typography-meta bg-transparent"}),s.jsx(V,{onClick:D,disabled:v||!T||f,size:"xs",className:"!font-normal",children:t(v?"settings.common.actions.saving":"settings.common.actions.saveChanges")})]}),s.jsxs(ze,{title:t("settings.behavior.page.section.responseStyle"),info:t("settings.behavior.page.responseStyle.tooltip"),settingsItem:"behavior.response-style",contentClassName:"space-y-3",children:[s.jsx(dt,{checked:c,onChange:y,disabled:f,label:t("settings.behavior.page.responseStyle.enable"),ariaLabel:t("settings.behavior.page.responseStyle.enableAria")}),s.jsx(Rt,{label:t("settings.behavior.page.responseStyle.preset"),alignEnd:!1,children:s.jsxs(St,{value:p,onValueChange:B=>b(B),disabled:f||!c,children:[s.jsx(Ct,{size:Ft,className:rn,children:s.jsx(Mt,{children:B=>B==="custom"?t("settings.behavior.page.responseStyle.option.custom"):xl(B)?t(go[B]):null})}),s.jsxs(It,{children:[bc.map(B=>s.jsx(at,{value:B,children:t(go[B])},B)),s.jsx(at,{value:"custom",children:t("settings.behavior.page.responseStyle.option.custom")})]})]})}),s.jsx(Ts,{value:F,onChange:B=>P(B.target.value),placeholder:t("settings.behavior.page.responseStyle.customPlaceholder"),rows:5,disabled:f||!c||p!=="custom",outerClassName:"min-h-[120px]",className:"w-full font-mono typography-meta bg-transparent"})]})]})},Ku=t=>{const e=ut.c(176),{onItemSelect:a}=t,{t:n}=tt(),[r,i]=o.useState(null),[l,g]=o.useState(""),[c,y]=o.useState(null),[p,b]=o.useState(null),[d,P]=o.useState(!1),[f,C]=o.useState(null),{selectedCommandName:v,setSelectedCommand:N,setCommandDraft:m,createCommand:A,deleteCommand:R,loadCommands:I}=va(Us(zu)),j=_s();let h;e[0]!==j?(h=Be=>yl(Be,j),e[0]=j,e[1]=h):h=e[1];const w=va(h);let F;e[2]!==j?(F=Be=>wr(Be,j),e[2]=j,e[3]=F):F=e[3];const T=Hs(F),S=Hs(Uu);let D,$;e[4]!==I||e[5]!==S||e[6]!==j?(D=()=>{I(j),S(j)},$=[I,S,j],e[4]=I,e[5]=S,e[6]=j,e[7]=D,e[8]=$):(D=e[7],$=e[8]),o.useEffect(D,$);let B;e[9]!==T?(B=new Set(T.map(_u)),e[9]=T,e[10]=B):B=e[10];const k=B;let G;if(e[11]!==w||e[12]!==k){let Be;e[14]!==k?(Be=Et=>!k.has(Et.name),e[14]=k,e[15]=Be):Be=e[15],G=w.filter(Be),e[11]=w,e[12]=k,e[13]=G}else G=e[13];const M=G;let L,J;e[16]!==v||e[17]!==N||e[18]!==k?(L=()=>{v&&k.has(v)&&N(null)},J=[v,N,k],e[16]=v,e[17]=N,e[18]=k,e[19]=L,e[20]=J):(L=e[19],J=e[20]),o.useEffect(L,J);let ee;e[21]!==w||e[22]!==a||e[23]!==m||e[24]!==N?(ee=()=>{let Be="new-command",Et=1;for(;w.some(Me=>Me.name===Be);)Be=`new-command-${Et}`,Et++;m({name:Be,scope:"user"}),N(Be),a?.()},e[21]=w,e[22]=a,e[23]=m,e[24]=N,e[25]=ee):ee=e[25];const U=ee;let le;e[26]!==n?(le=async Be=>{if(ha(Be)){E.error(n("settings.commands.sidebar.toast.builtInCannotDelete"));return}y(Be),b("delete")},e[26]=n,e[27]=le):le=e[27];const _=le;let H;e[28]===Symbol.for("react.memo_cache_sentinel")?(H=async Be=>{ha(Be)&&(y(Be),b("reset"))},e[28]=H):H=e[28];const z=H;let K;e[29]===Symbol.for("react.memo_cache_sentinel")?(K=()=>{y(null),b(null)},e[29]=K):K=e[29];const te=K;let Y;e[30]!==c||e[31]!==p||e[32]!==R||e[33]!==j||e[34]!==n?(Y=async()=>{if(!c||!p)return;P(!0),await R(c.name,j)?(p==="delete"?E.success(n("settings.commands.sidebar.toast.commandDeleted",{name:c.name})):E.success(n("settings.commands.sidebar.toast.commandReset",{name:c.name})),te()):p==="delete"?E.error(n("settings.commands.sidebar.toast.deleteFailed")):E.error(n("settings.commands.sidebar.toast.resetFailed")),P(!1)},e[30]=c,e[31]=p,e[32]=R,e[33]=j,e[34]=n,e[35]=Y):Y=e[35];const ae=Y;let ge;e[36]!==w||e[37]!==m||e[38]!==N?(ge=Be=>{const Et=Be.name;let Me=1,wt=`${Et}-copy`;for(;w.some(Q=>Q.name===wt);)Me++,wt=`${Et}-copy-${Me}`;m({name:wt,scope:Be.scope||"user",description:Be.description,template:Be.template,agent:Be.agent,model:Be.model}),N(wt)},e[36]=w,e[37]=m,e[38]=N,e[39]=ge):ge=e[39];const de=ge;let he;e[40]===Symbol.for("react.memo_cache_sentinel")?(he=Be=>{g(Be.name),i(Be)},e[40]=he):he=e[40];const se=he;let re;e[41]!==w||e[42]!==A||e[43]!==R||e[44]!==r||e[45]!==l||e[46]!==N||e[47]!==j||e[48]!==n?(re=async()=>{if(!r)return;const Be=l.trim().replace(/\s+/g,"-");if(!Be){E.error(n("settings.commands.sidebar.toast.commandNameRequired"));return}if(Be===r.name){i(null);return}if(w.some(Me=>Me.name===Be)){E.error(n("settings.commands.sidebar.toast.commandExists"));return}await A({name:Be,description:r.description,template:r.template,agent:r.agent,model:r.model},j)?await R(r.name,j)?(E.success(`Command renamed to "${Be}"`),N(Be)):E.error(n("settings.commands.sidebar.toast.removeOldAfterRenameFailed")):E.error(n("settings.commands.sidebar.toast.renameFailed")),i(null)},e[41]=w,e[42]=A,e[43]=R,e[44]=r,e[45]=l,e[46]=N,e[47]=j,e[48]=n,e[49]=re):re=e[49];const ue=re;let Ce,Se,ye,fe,_e,Ue;if(e[50]!==M||e[51]!==U||e[52]!==_||e[53]!==de||e[54]!==a||e[55]!==f||e[56]!==v||e[57]!==N||e[58]!==n){const Be=M.filter(ha),Et=M.filter($u);e[65]===Symbol.for("react.memo_cache_sentinel")?(_e=xe("flex h-full flex-col","bg-background"),e[65]=_e):_e=e[65];let Me;e[66]!==n?(Me=n("settings.commands.sidebar.title"),e[66]=n,e[67]=Me):Me=e[67];let wt;e[68]!==Me?(wt=s.jsx("h2",{className:`${un} mb-3`,children:Me}),e[68]=Me,e[69]=wt):wt=e[69];let Q;e[70]===Symbol.for("react.memo_cache_sentinel")?(Q=s.jsx(Ba,{className:"mb-3"}),e[70]=Q):Q=e[70];let pe;e[71]!==M.length||e[72]!==n?(pe=n("settings.commands.sidebar.total",{count:M.length}),e[71]=M.length,e[72]=n,e[73]=pe):pe=e[73];let De;e[74]!==pe?(De=s.jsx("span",{className:"typography-meta text-muted-foreground",children:pe}),e[74]=pe,e[75]=De):De=e[75];let Ae;e[76]===Symbol.for("react.memo_cache_sentinel")?(Ae=s.jsx(O,{name:"add",className:"h-3.5 w-3.5"}),e[76]=Ae):Ae=e[76];let it;e[77]!==U?(it=s.jsx(V,{size:"sm","data-settings-item":"commands.create",variant:"ghost",className:"h-7 w-7 px-0 -my-1 text-muted-foreground",onClick:U,children:Ae}),e[77]=U,e[78]=it):it=e[78];let rt;e[79]!==De||e[80]!==it?(rt=s.jsxs("div",{className:"flex items-center justify-between gap-2",children:[De,it]}),e[79]=De,e[80]=it,e[81]=rt):rt=e[81],e[82]!==wt||e[83]!==rt?(Ue=s.jsxs("div",{className:"border-b px-3 pt-4 pb-3",children:[wt,Q,rt]}),e[82]=wt,e[83]=rt,e[84]=Ue):Ue=e[84],Ce=vs,Se="flex-1 min-h-0",ye="space-y-1 px-3 py-2",fe=M.length===0?s.jsxs("div",{className:"py-12 px-4 text-center text-muted-foreground",children:[s.jsx(O,{name:"terminal-box",className:"mx-auto mb-3 h-10 w-10 opacity-50"}),s.jsx("p",{className:"typography-ui-label font-medium",children:n("settings.commands.sidebar.empty.title")}),s.jsx("p",{className:"typography-meta mt-1 opacity-75",children:n("settings.commands.sidebar.empty.description")})]}):s.jsxs(s.Fragment,{children:[Be.length>0&&s.jsxs(s.Fragment,{children:[s.jsx("div",{className:"px-2 pb-1.5 pt-2 text-xs font-semibold uppercase tracking-wide text-muted-foreground",children:n("settings.commands.sidebar.section.builtIn")}),[...Be].sort(Vu).map(qe=>s.jsx(ho,{command:qe,isSelected:v===qe.name,onSelect:()=>{N(qe.name),a?.()},onReset:()=>z(qe),onDuplicate:()=>de(qe),isMenuOpen:f===qe.name,onMenuOpenChange:Pt=>C(Pt?qe.name:null)},qe.name))]}),Et.length>0&&s.jsxs(s.Fragment,{children:[s.jsx("div",{className:"px-2 pb-1.5 pt-3 text-xs font-semibold uppercase tracking-wide text-muted-foreground",children:n("settings.commands.sidebar.section.custom")}),[...Et].sort(Bu).map(qe=>s.jsx(ho,{command:qe,isSelected:v===qe.name,onSelect:()=>{N(qe.name),a?.()},onRename:()=>se(qe),onDelete:()=>_(qe),onDuplicate:()=>de(qe),isMenuOpen:f===qe.name,onMenuOpenChange:Pt=>C(Pt?qe.name:null)},qe.name))]})]}),e[50]=M,e[51]=U,e[52]=_,e[53]=de,e[54]=a,e[55]=f,e[56]=v,e[57]=N,e[58]=n,e[59]=Ce,e[60]=Se,e[61]=ye,e[62]=fe,e[63]=_e,e[64]=Ue}else Ce=e[59],Se=e[60],ye=e[61],fe=e[62],_e=e[63],Ue=e[64];let Ne;e[85]!==Ce||e[86]!==Se||e[87]!==ye||e[88]!==fe?(Ne=s.jsx(Ce,{outerClassName:Se,className:ye,children:fe}),e[85]=Ce,e[86]=Se,e[87]=ye,e[88]=fe,e[89]=Ne):Ne=e[89];const Oe=c!==null&&p!==null;let Ve;e[90]!==d?(Ve=Be=>{!Be&&!d&&te()},e[90]=d,e[91]=Ve):Ve=e[91];let Ge;e[92]!==p||e[93]!==n?(Ge=n(p==="delete"?"settings.commands.sidebar.dialog.deleteTitle":"settings.commands.sidebar.dialog.resetTitle"),e[92]=p,e[93]=n,e[94]=Ge):Ge=e[94];let ve;e[95]!==Ge?(ve=s.jsx($t,{children:Ge}),e[95]=Ge,e[96]=ve):ve=e[96];let Z;e[97]!==c?.name||e[98]!==p||e[99]!==n?(Z=p==="delete"?n("settings.commands.sidebar.dialog.deleteDescription",{name:c?.name??""}):n("settings.commands.sidebar.dialog.resetDescription",{name:c?.name??""}),e[97]=c?.name,e[98]=p,e[99]=n,e[100]=Z):Z=e[100];let ne;e[101]!==Z?(ne=s.jsx(Vt,{children:Z}),e[101]=Z,e[102]=ne):ne=e[102];let be;e[103]!==ve||e[104]!==ne?(be=s.jsxs(_t,{children:[ve,ne]}),e[103]=ve,e[104]=ne,e[105]=be):be=e[105];let we;e[106]!==n?(we=n("settings.common.actions.cancel"),e[106]=n,e[107]=we):we=e[107];let Re;e[108]!==d||e[109]!==we?(Re=s.jsx(V,{size:"sm",variant:"ghost",onClick:te,disabled:d,children:we}),e[108]=d,e[109]=we,e[110]=Re):Re=e[110];let Fe;e[111]!==p||e[112]!==n?(Fe=n(p==="delete"?"settings.common.actions.delete":"settings.common.actions.reset"),e[111]=p,e[112]=n,e[113]=Fe):Fe=e[113];let Ke;e[114]!==ae||e[115]!==d||e[116]!==Fe?(Ke=s.jsx(V,{size:"sm",onClick:ae,disabled:d,children:Fe}),e[114]=ae,e[115]=d,e[116]=Fe,e[117]=Ke):Ke=e[117];let Ee;e[118]!==Re||e[119]!==Ke?(Ee=s.jsxs(ts,{children:[Re,Ke]}),e[118]=Re,e[119]=Ke,e[120]=Ee):Ee=e[120];let je;e[121]!==be||e[122]!==Ee?(je=s.jsxs(zt,{className:"max-w-md",children:[be,Ee]}),e[121]=be,e[122]=Ee,e[123]=je):je=e[123];let Ze;e[124]!==Oe||e[125]!==Ve||e[126]!==je?(Ze=s.jsx(Kt,{open:Oe,onOpenChange:Ve,children:je}),e[124]=Oe,e[125]=Ve,e[126]=je,e[127]=Ze):Ze=e[127];const me=r!==null;let Ie;e[128]===Symbol.for("react.memo_cache_sentinel")?(Ie=Be=>!Be&&i(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 Xe;e[131]!==Le?(Xe=s.jsx($t,{children:Le}),e[131]=Le,e[132]=Xe):Xe=e[132];const q=r?.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 Pe;e[136]!==ke?(Pe=s.jsx(Vt,{children:ke}),e[136]=ke,e[137]=Pe):Pe=e[137];let Je;e[138]!==Xe||e[139]!==Pe?(Je=s.jsxs(_t,{children:[Xe,Pe]}),e[138]=Xe,e[139]=Pe,e[140]=Je):Je=e[140];let ot;e[141]===Symbol.for("react.memo_cache_sentinel")?(ot=Be=>g(Be.target.value),e[141]=ot):ot=e[141];let st;e[142]!==n?(st=n("settings.commands.sidebar.renameDialog.placeholder"),e[142]=n,e[143]=st):st=e[143];let pt;e[144]!==ue?(pt=Be=>{Be.key==="Enter"&&ue()},e[144]=ue,e[145]=pt):pt=e[145];let vt;e[146]!==l||e[147]!==st||e[148]!==pt?(vt=s.jsx(He,{value:l,onChange:ot,placeholder:st,className:"text-foreground placeholder:text-muted-foreground",onKeyDown:pt}),e[146]=l,e[147]=st,e[148]=pt,e[149]=vt):vt=e[149];let W;e[150]===Symbol.for("react.memo_cache_sentinel")?(W=()=>i(null),e[150]=W):W=e[150];let We;e[151]!==n?(We=n("settings.common.actions.cancel"),e[151]=n,e[152]=We):We=e[152];let nt;e[153]!==We?(nt=s.jsx(V,{size:"sm",variant:"ghost",onClick:W,children:We}),e[153]=We,e[154]=nt):nt=e[154];let lt;e[155]!==n?(lt=n("settings.common.actions.rename"),e[155]=n,e[156]=lt):lt=e[156];let ht;e[157]!==ue||e[158]!==lt?(ht=s.jsx(V,{size:"sm",onClick:ue,children:lt}),e[157]=ue,e[158]=lt,e[159]=ht):ht=e[159];let Lt;e[160]!==nt||e[161]!==ht?(Lt=s.jsxs(ts,{children:[nt,ht]}),e[160]=nt,e[161]=ht,e[162]=Lt):Lt=e[162];let et;e[163]!==Je||e[164]!==vt||e[165]!==Lt?(et=s.jsxs(zt,{children:[Je,vt,Lt]}),e[163]=Je,e[164]=vt,e[165]=Lt,e[166]=et):et=e[166];let ft;e[167]!==me||e[168]!==et?(ft=s.jsx(Kt,{open:me,onOpenChange:Ie,children:et}),e[167]=me,e[168]=et,e[169]=ft):ft=e[169];let bt;return e[170]!==_e||e[171]!==Ue||e[172]!==Ne||e[173]!==Ze||e[174]!==ft?(bt=s.jsxs("div",{className:_e,children:[Ue,Ne,Ze,ft]}),e[170]=_e,e[171]=Ue,e[172]=Ne,e[173]=Ze,e[174]=ft,e[175]=bt):bt=e[175],bt},ho=t=>{const e=ut.c(47),{command:a,isSelected:n,onSelect:r,onDelete:i,onReset:l,onRename:g,onDuplicate:c,isMenuOpen:y,onMenuOpenChange:p}=t,{t:b}=tt();let d;e[0]===Symbol.for("react.memo_cache_sentinel")?(d=_a(),e[0]=d):d=e[0];const P=d,[f,C]=o.useState(!1);let v;e[1]!==i||e[2]!==c||e[3]!==g||e[4]!==l||e[5]!==b?(v=J=>s.jsxs(s.Fragment,{children:[g&&s.jsxs(J,{onClick:ee=>{ee.stopPropagation(),g()},children:[s.jsx(O,{name:"edit",className:"h-4 w-4 mr-px"}),b("settings.common.actions.rename")]}),s.jsxs(J,{onClick:ee=>{ee.stopPropagation(),c()},children:[s.jsx(O,{name:"file-copy",className:"h-4 w-4 mr-px"}),b("settings.common.actions.duplicate")]}),l&&s.jsxs(J,{onClick:ee=>{ee.stopPropagation(),l()},children:[s.jsx(O,{name:"restart",className:"h-4 w-4 mr-px"}),b("settings.common.actions.reset")]}),i&&s.jsxs(J,{onClick:ee=>{ee.stopPropagation(),i()},className:"text-destructive focus:text-destructive",children:[s.jsx(O,{name:"delete-bin",className:"h-4 w-4 mr-px"}),b("settings.common.actions.delete")]})]}),e[1]=i,e[2]=c,e[3]=g,e[4]=l,e[5]=b,e[6]=v):v=e[6];const N=v,m=n?"bg-interactive-selection":"hover:bg-interactive-hover";let A;e[7]!==m?(A=xe("group relative flex items-center rounded-md px-1.5 py-1 transition-all duration-200 select-none",m),e[7]=m,e[8]=A):A=e[8];let R;e[9]===Symbol.for("react.memo_cache_sentinel")?(R=P?void 0:J=>{J.preventDefault(),C(!0)},e[9]=R):R=e[9];let I;e[10]!==A?(I=s.jsx("div",{className:A,onContextMenu:R}),e[10]=A,e[11]=I):I=e[11];let j;e[12]!==a.name?(j=s.jsxs("span",{className:"typography-ui-label font-normal truncate text-foreground",children:["/",a.name]}),e[12]=a.name,e[13]=j):j=e[13];let h;e[14]!==a||e[15]!==b?(h=(a.scope||ha(a))&&s.jsx("span",{className:"typography-micro text-muted-foreground bg-muted px-1 rounded flex-shrink-0 leading-none pb-px border border-border/50",children:ha(a)?b("settings.agents.sidebar.badge.system"):a.scope}),e[14]=a,e[15]=b,e[16]=h):h=e[16];let w;e[17]!==j||e[18]!==h?(w=s.jsxs("div",{className:"flex items-center gap-2",children:[j,h]}),e[17]=j,e[18]=h,e[19]=w):w=e[19];let F;e[20]!==a.description?(F=a.description&&s.jsx("div",{className:"typography-micro text-muted-foreground/60 truncate leading-tight",children:a.description}),e[20]=a.description,e[21]=F):F=e[21];let T;e[22]!==r||e[23]!==F||e[24]!==w?(T=s.jsxs("button",{onClick:r,className:"flex min-w-0 flex-1 flex-col gap-0 rounded-sm text-left focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-primary/50",tabIndex:0,children:[w,F]}),e[22]=r,e[23]=F,e[24]=w,e[25]=T):T=e[25];let S;e[26]!==p?(S=J=>{J&&C(!1),p(J)},e[26]=p,e[27]=S):S=e[27];let D;e[28]===Symbol.for("react.memo_cache_sentinel")?(D=s.jsx(on,{asChild:!0,children:s.jsx(V,{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(O,{name:"more-2",className:"h-3.5 w-3.5"})})}),e[28]=D):D=e[28];let $;e[29]!==N?($=s.jsx(ln,{align:"end",className:"w-fit min-w-20",children:N(dn)}),e[29]=N,e[30]=$):$=e[30];let B;e[31]!==y||e[32]!==S||e[33]!==$?(B=s.jsxs(cn,{open:y,onOpenChange:S,children:[D,$]}),e[31]=y,e[32]=S,e[33]=$,e[34]=B):B=e[34];let k;e[35]!==T||e[36]!==B?(k=s.jsxs("div",{className:"flex min-w-0 flex-1 items-center",children:[T,B]}),e[35]=T,e[36]=B,e[37]=k):k=e[37];let G;e[38]!==k||e[39]!==I?(G=s.jsx(Jn,{render:I,children:k}),e[38]=k,e[39]=I,e[40]=G):G=e[40];let M;e[41]!==N?(M=s.jsx(Wn,{className:"w-fit min-w-20",children:N(qn)}),e[41]=N,e[42]=M):M=e[42];let L;return e[43]!==f||e[44]!==G||e[45]!==M?(L=s.jsxs(Qn,{open:f,onOpenChange:C,children:[G,M]}),e[43]=f,e[44]=G,e[45]=M,e[46]=L):L=e[46],L};function zu(t){return{selectedCommandName:t.selectedCommandName,setSelectedCommand:t.setSelectedCommand,setCommandDraft:t.setCommandDraft,createCommand:t.createCommand,deleteCommand:t.deleteCommand,loadCommands:t.loadCommands}}function Uu(t){return t.loadSkills}function _u(t){return t.name}function $u(t){return!ha(t)}function Vu(t,e){return t.name.localeCompare(e.name)}function Bu(t,e){return t.name.localeCompare(e.name)}const Hu=()=>{const{t}=tt(),{selectedCommandName:e,getCommandByName:a,createCommand:n,updateCommand:r,commandDraft:i,setCommandDraft:l}=va(Us(D=>({selectedCommandName:D.selectedCommandName,getCommandByName:D.getCommandByName,createCommand:D.createCommand,updateCommand:D.updateCommand,commandDraft:D.commandDraft,setCommandDraft:D.setCommandDraft}))),g=_s(),c=va(D=>yl(D,g)),y=e?a(e,g):null,p=!!(i&&i.name===e&&!y),[b,d]=o.useState(""),[P,f]=o.useState("user"),[C,v]=o.useState(""),[N,m]=o.useState(""),[A,R]=o.useState(""),[I,j]=o.useState(""),[h,w]=o.useState(!1),F=o.useRef(null);o.useEffect(()=>{if(p&&i){const D=i.name||"",$=i.scope||"user",B=i.description||"",k=i.agent||"",G=i.model||"",M=i.template||"";d(D),f($),v(B),m(k),R(G),j(M),F.current={draftName:D,draftScope:$,description:B,agent:k,model:G,template:M}}else if(y){const D=y.description||"",$=y.agent||"",B=y.model||"",k=y.template||"";v(D),m($),R(B),j(k),F.current={draftName:"",draftScope:"user",description:D,agent:$,model:B,template:k}}},[y,p,e,c,i]);const T=o.useMemo(()=>{const D=F.current;return D?!!(p&&(b!==D.draftName||P!==D.draftScope)||C!==D.description||N!==D.agent||A!==D.model||I!==D.template):!1},[N,C,b,P,p,A,I]),S=async()=>{const D=p?b.trim().replace(/\s+/g,"-"):e?.trim();if(!D){E.error(t("settings.commands.sidebar.toast.commandNameRequired"));return}if(!I.trim()){E.error(t("settings.commands.page.toast.templateRequired"));return}if(p&&c.some($=>$.name===D)){E.error(t("settings.commands.sidebar.toast.commandExists"));return}w(!0);try{const $=N.trim(),B=A.trim(),k=I.trim(),G={name:D,description:C.trim()||void 0,agent:$===""?null:$,model:B===""?null:B,template:k,scope:p?P:void 0};let M;if(p?(M=await n(G,g),M&&l(null)):M=await r(D,G,g),M){const L=Vn.getState().changes.some(J=>J.scope==="commands"&&J.id.startsWith(`commands:${D}:`));E.success(t(L?"settings.view.pendingRestart.saved":p?"settings.commands.page.toast.created":"settings.commands.page.toast.updated"))}else E.error(t(p?"settings.commands.page.toast.createFailed":"settings.commands.page.toast.updateFailed"))}catch($){console.error("Error saving command:",$),E.error(t("settings.commands.page.toast.saveUnexpectedError"))}finally{w(!1)}};return e?s.jsxs(es,{title:p?t("settings.commands.page.title.new"):`/${e}`,description:t(p?"settings.commands.page.subtitle.new":"settings.commands.page.subtitle.edit"),showSaveStatus:!1,children:[s.jsxs(ze,{title:t("settings.commands.page.section.identity"),divider:!1,contentClassName:"space-y-0",children:[p&&s.jsxs(Rt,{settingsItem:"commands.name",label:t("settings.commands.page.field.commandName"),children:[s.jsxs("div",{className:"flex items-center",children:[s.jsx("span",{className:"typography-ui-label text-muted-foreground mr-1",children:"/"}),s.jsx(He,{value:b,onChange:D=>d(D.target.value),placeholder:t("settings.commands.page.field.commandNamePlaceholder"),className:"h-7 w-40 px-2"})]}),s.jsxs(St,{value:P,onValueChange:D=>f(D),children:[s.jsx(Ct,{size:Ft,className:"w-fit min-w-[100px]",children:s.jsx(Mt,{placeholder:t("settings.agents.page.field.scopePlaceholder")})}),s.jsxs(It,{align:"end",children:[s.jsx(at,{value:"user",children:s.jsxs("div",{className:"flex items-center gap-2",children:[s.jsx(O,{name:"user-3",className:"h-3.5 w-3.5"}),s.jsx("span",{children:t("settings.common.scope.global")})]})}),s.jsx(at,{value:"project",children:s.jsxs("div",{className:"flex items-center gap-2",children:[s.jsx(O,{name:"folder",className:"h-3.5 w-3.5"}),s.jsx("span",{children:t("settings.common.scope.project")})]})})]})]})]}),s.jsxs("div",{className:"py-1.5",children:[s.jsx("span",{className:"typography-ui-label text-foreground",children:t("settings.common.field.description")}),s.jsx("div",{className:"mt-1.5",children:s.jsx(Ts,{value:C,onChange:D=>v(D.target.value),placeholder:t("settings.commands.page.field.descriptionPlaceholder"),rows:2,className:"w-full resize-none min-h-[60px] bg-transparent"})})]})]}),s.jsxs(ze,{title:t("settings.commands.page.section.executionContext"),contentClassName:"space-y-0",children:[s.jsx(Rt,{settingsItem:"commands.agent",label:t("settings.commands.page.field.overrideAgent"),children:s.jsx(bl,{agentName:N,onChange:D=>m(D),className:In})}),s.jsx(Rt,{settingsItem:"commands.model",label:t("settings.agents.page.field.overrideModel"),children:s.jsx(Fa,{providerId:xa(A)?.providerId??"",modelId:xa(A)?.modelId??"",onChange:(D,$)=>{R(D&&$?`${D}/${$}`:"")},className:In})})]}),s.jsxs(ze,{title:t("settings.commands.page.section.template"),settingsItem:"commands.template",children:[s.jsx(Ts,{value:I,onChange:D=>j(D.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(V,{onClick:S,disabled:h||!T,size:"xs",className:"!font-normal",children:t(h?"settings.common.actions.saving":"settings.common.actions.saveChanges")})})]})]}):s.jsx("div",{className:"flex h-full items-center justify-center",children:s.jsxs("div",{className:"text-center text-muted-foreground",children:[s.jsx(O,{name:"terminal-box",className:"mx-auto mb-3 h-12 w-12 opacity-50"}),s.jsx("p",{className:"typography-body",children:t("settings.commands.page.empty.title")}),s.jsx("p",{className:"typography-meta mt-1 opacity-75",children:t("settings.commands.page.empty.description")})]})})},fo=t=>{switch(t){case"connected":return"success";case"failed":return"error";case"needs_auth":case"needs_client_registration":return"warning";default:return"idle"}},xo=t=>{const e=ut.c(5),{tone:a,enabled:n}=t;if(!n){let l;return e[0]===Symbol.for("react.memo_cache_sentinel")?(l=s.jsx("span",{className:"inline-block h-2 w-2 rounded-full bg-muted-foreground/30 flex-shrink-0"}),e[0]=l):l=e[0],l}let r;e[1]!==a?(r=xe("inline-block h-2 w-2 rounded-full flex-shrink-0",{success:"bg-[var(--status-success)]",error:"bg-[var(--status-error)]",warning:"bg-[var(--status-warning)]",idle:"bg-muted-foreground/40"}[a]),e[1]=a,e[2]=r):r=e[2];let i;return e[3]!==r?(i=s.jsx("span",{className:r}),e[3]=r,e[4]=i):i=e[4],i},Gu=t=>{const e=ut.c(124),{onItemSelect:a}=t,{t:n}=tt(),{selectedMcpName:r,setSelectedMcp:i,setMcpDraft:l,loadMcpConfigs:g,deleteMcp:c}=ya(Us(Wu)),y=_s();let p;e[0]!==y?(p=q=>wl(q,y),e[0]=y,e[1]=p):p=e[1];const b=ya(p);let d;e[2]!==y?(d=q=>q.getStatusForDirectory(y),e[2]=y,e[3]=d):d=e[3];const P=Ks(d),f=Ks(qu),C=Ks(Ju),[v,N]=o.useState(null),[m,A]=o.useState(!1),[R,I]=o.useState(null),[j,h]=o.useState(null),[w,F]=o.useState(!1);let T;e[4]!==b?(T=b.filter(Qu),e[4]=b,e[5]=T):T=e[5];const S=T;let D;e[6]!==b?(D=b.filter(Yu),e[6]=b,e[7]=D):D=e[7];const $=D;let B,k;e[8]!==g||e[9]!==y?(B=()=>{g({directory:y})},k=[g,y],e[8]=g,e[9]=y,e[10]=B,e[11]=k):(B=e[10],k=e[11]),o.useEffect(B,k);let G;e[12]!==C||e[13]!==w||e[14]!==f||e[15]!==y?(G=()=>{if(w)return;F(!0);const q=new Promise(Zu);Promise.all([f({directory:y,silent:!0}),q]).then(()=>{const ke=C(y);ke&&E.error(ke)}).finally(()=>{F(!1)})},e[12]=C,e[13]=w,e[14]=f,e[15]=y,e[16]=G):G=e[16];const M=G;let L;e[17]!==b||e[18]!==a||e[19]!==l||e[20]!==i?(L=()=>{let q="new-mcp-server",ke=1;for(;b.some(Je=>Je.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}),i(q),a?.()},e[17]=b,e[18]=a,e[19]=l,e[20]=i,e[21]=L):L=e[21];const J=L;let ee;e[22]!==c||e[23]!==v||e[24]!==y||e[25]!==n?(ee=async()=>{if(!v)return;A(!0);const q=await c(v.name,y);q.ok?q.reloadFailed?E.warning(q.message||`MCP server "${v.name}" deleted, but OpenCode reload failed`,{description:q.warning||n("settings.mcp.sidebar.toast.refreshListIfStale")}):E.success(q.message||n("settings.mcp.sidebar.toast.serverDeleted",{name:v.name})):E.error(n("settings.mcp.sidebar.toast.deleteFailed")),N(null),A(!1)},e[22]=c,e[23]=v,e[24]=y,e[25]=n,e[26]=ee):ee=e[26];const U=ee;let le;e[27]!==n?(le=(q,ke)=>s.jsxs(ke,{onClick:Pe=>{Pe.stopPropagation(),N(q)},className:"text-destructive focus:text-destructive",children:[s.jsx(O,{name:"delete-bin",className:"h-4 w-4 mr-px"}),n("settings.common.actions.delete")]}),e[27]=n,e[28]=le):le=e[28];const _=le;let H;e[29]===Symbol.for("react.memo_cache_sentinel")?(H=xe("flex h-full flex-col","bg-background"),e[29]=H):H=e[29];let z;e[30]!==n?(z=n("settings.mcp.sidebar.title"),e[30]=n,e[31]=z):z=e[31];let K;e[32]!==z?(K=s.jsx("h2",{className:un,children:z}),e[32]=z,e[33]=K):K=e[33];let te;e[34]!==n?(te=n("settings.mcp.sidebar.actions.refreshStatusAria"),e[34]=n,e[35]=te):te=e[35];let Y;e[36]!==n?(Y=n("settings.mcp.sidebar.actions.refreshStatusTitle"),e[36]=n,e[37]=Y):Y=e[37];const ae=w&&"animate-spin";let ge;e[38]!==ae?(ge=xe("h-4 w-4",ae),e[38]=ae,e[39]=ge):ge=e[39];let de;e[40]!==ge?(de=s.jsx(O,{name:"refresh",className:ge}),e[40]=ge,e[41]=de):de=e[41];let he;e[42]!==M||e[43]!==w||e[44]!==te||e[45]!==Y||e[46]!==de?(he=s.jsx("button",{type:"button",className:"inline-flex h-7 w-7 items-center justify-center rounded-md text-muted-foreground transition-colors hover:text-foreground hover:bg-interactive-hover focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-primary",disabled:w,onClick:M,"aria-label":te,title:Y,children:de}),e[42]=M,e[43]=w,e[44]=te,e[45]=Y,e[46]=de,e[47]=he):he=e[47];let se;e[48]!==K||e[49]!==he?(se=s.jsxs("div",{className:"mb-3 flex items-center justify-between gap-3",children:[K,he]}),e[48]=K,e[49]=he,e[50]=se):se=e[50];let re;e[51]===Symbol.for("react.memo_cache_sentinel")?(re=s.jsx(Ba,{className:"mb-3"}),e[51]=re):re=e[51];let ue;e[52]!==b.length||e[53]!==n?(ue=n("settings.mcp.sidebar.total",{count:b.length}),e[52]=b.length,e[53]=n,e[54]=ue):ue=e[54];let Ce;e[55]!==ue?(Ce=s.jsx("span",{className:"typography-meta text-muted-foreground",children:ue}),e[55]=ue,e[56]=Ce):Ce=e[56];let Se;e[57]!==n?(Se=n("settings.mcp.sidebar.actions.addServerTitle"),e[57]=n,e[58]=Se):Se=e[58];let ye;e[59]===Symbol.for("react.memo_cache_sentinel")?(ye=s.jsx(O,{name:"add",className:"h-3.5 w-3.5"}),e[59]=ye):ye=e[59];let fe;e[60]!==J||e[61]!==Se?(fe=s.jsx(V,{size:"sm","data-settings-item":"mcp.create",variant:"ghost",className:"h-7 w-7 px-0 -my-1 text-muted-foreground",onClick:J,title:Se,children:ye}),e[60]=J,e[61]=Se,e[62]=fe):fe=e[62];let _e;e[63]!==Ce||e[64]!==fe?(_e=s.jsxs("div",{className:"flex items-center justify-between gap-2",children:[Ce,fe]}),e[63]=Ce,e[64]=fe,e[65]=_e):_e=e[65];let Ue;e[66]!==se||e[67]!==_e?(Ue=s.jsxs("div",{className:"border-b px-3 pt-4 pb-3",children:[se,re,_e]}),e[66]=se,e[67]=_e,e[68]=Ue):Ue=e[68];let Ne;e[69]!==b.length||e[70]!==P||e[71]!==a||e[72]!==R||e[73]!==S||e[74]!==_||e[75]!==j||e[76]!==r||e[77]!==l||e[78]!==i||e[79]!==n||e[80]!==$?(Ne=s.jsx(vs,{outerClassName:"flex-1 min-h-0",className:"space-y-1 px-3 py-2 overflow-x-hidden",children:b.length===0?s.jsxs("div",{className:"py-12 px-4 text-center text-muted-foreground",children:[s.jsx(O,{name:"plug",className:"mx-auto mb-3 h-10 w-10 opacity-50"}),s.jsx("p",{className:"typography-ui-label font-medium",children:n("settings.mcp.sidebar.empty.title")}),s.jsx("p",{className:"typography-meta mt-1 opacity-75",children:n("settings.mcp.sidebar.empty.description")})]}):s.jsxs(s.Fragment,{children:[S.length>0&&s.jsxs(s.Fragment,{children:[s.jsx("div",{className:"px-2 pb-1.5 pt-2 text-xs font-semibold uppercase tracking-wide text-muted-foreground",children:n("settings.mcp.sidebar.group.projectServers")}),S.map(q=>{const ke=P[q.name],Pe=fo(ke?.status),Je=r===q.name,ot=_a();return s.jsxs(Qn,{open:j===q.name,onOpenChange:st=>h(st?q.name:null),children:[s.jsxs(Jn,{render:s.jsx("div",{className:xe("group relative flex items-center rounded-md px-1.5 py-1 transition-all duration-200 select-none",Je?"bg-interactive-selection":"hover:bg-interactive-hover"),onContextMenu:ot?void 0:st=>{st.preventDefault(),h(q.name)}}),children:[s.jsxs("button",{onClick:()=>{i(q.name),l(null),a?.()},className:"flex min-w-0 flex-1 flex-col gap-0 rounded-sm text-left focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-primary/50",children:[s.jsxs("div",{className:"flex items-center gap-2",children:[s.jsx(xo,{tone:Pe,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(O,{name:"server",className:"h-3 w-3 text-muted-foreground/60 flex-shrink-0"}):s.jsx(O,{name:"global",className:"h-3 w-3 text-muted-foreground/60 flex-shrink-0"})})]}),s.jsx("div",{className:"typography-micro text-muted-foreground/60 truncate leading-tight pl-4",children:q.type==="local"?q.command?.join(" ")??"":q.url??""})]}),s.jsxs(cn,{open:R===q.name,onOpenChange:st=>{st&&h(null),I(st?q.name:null)},children:[s.jsx(on,{asChild:!0,children:s.jsx(V,{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(O,{name:"more-2",className:"h-3.5 w-3.5"})})}),s.jsx(ln,{align:"end",className:"w-fit min-w-20",children:_(q,dn)})]})]}),s.jsx(Wn,{className:"w-fit min-w-20",children:_(q,qn)})]},q.name)})]}),$.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")}),$.map(q=>{const ke=P[q.name],Pe=fo(ke?.status),Je=r===q.name,ot=_a();return s.jsxs(Qn,{open:j===q.name,onOpenChange:st=>h(st?q.name:null),children:[s.jsxs(Jn,{render:s.jsx("div",{className:xe("group relative flex items-center rounded-md px-1.5 py-1 transition-all duration-200 select-none",Je?"bg-interactive-selection":"hover:bg-interactive-hover"),onContextMenu:ot?void 0:st=>{st.preventDefault(),h(q.name)}}),children:[s.jsxs("button",{onClick:()=>{i(q.name),l(null),a?.()},className:"flex min-w-0 flex-1 flex-col gap-0 rounded-sm text-left focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-primary/50",children:[s.jsxs("div",{className:"flex items-center gap-2",children:[s.jsx(xo,{tone:Pe,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(O,{name:"server",className:"h-3 w-3 text-muted-foreground/60 flex-shrink-0"}):s.jsx(O,{name:"global",className:"h-3 w-3 text-muted-foreground/60 flex-shrink-0"})})]}),s.jsx("div",{className:"typography-micro text-muted-foreground/60 truncate leading-tight pl-4",children:q.type==="local"?q.command?.join(" ")??"":q.url??""})]}),s.jsxs(cn,{open:R===q.name,onOpenChange:st=>{st&&h(null),I(st?q.name:null)},children:[s.jsx(on,{asChild:!0,children:s.jsx(V,{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(O,{name:"more-2",className:"h-3.5 w-3.5"})})}),s.jsx(ln,{align:"end",className:"w-fit min-w-20",children:_(q,dn)})]})]}),s.jsx(Wn,{className:"w-fit min-w-20",children:_(q,qn)})]},q.name)})]})]})}),e[69]=b.length,e[70]=P,e[71]=a,e[72]=R,e[73]=S,e[74]=_,e[75]=j,e[76]=r,e[77]=l,e[78]=i,e[79]=n,e[80]=$,e[81]=Ne):Ne=e[81];const Oe=v!==null;let Ve;e[82]!==m?(Ve=q=>{!q&&!m&&N(null)},e[82]=m,e[83]=Ve):Ve=e[83];let Ge;e[84]!==n?(Ge=n("settings.mcp.sidebar.deleteDialog.title"),e[84]=n,e[85]=Ge):Ge=e[85];let ve;e[86]!==Ge?(ve=s.jsx($t,{children:Ge}),e[86]=Ge,e[87]=ve):ve=e[87];const Z=v?.name||"";let ne;e[88]!==n||e[89]!==Z?(ne=n("settings.mcp.sidebar.deleteDialog.descriptionPrefix",{name:Z}),e[88]=n,e[89]=Z,e[90]=ne):ne=e[90];let be;e[91]===Symbol.for("react.memo_cache_sentinel")?(be=s.jsx("code",{className:"text-foreground",children:"opencode.json"}),e[91]=be):be=e[91];let we;e[92]!==ne?(we=s.jsxs(Vt,{children:[ne," ",be,"."]}),e[92]=ne,e[93]=we):we=e[93];let Re;e[94]!==ve||e[95]!==we?(Re=s.jsxs(_t,{children:[ve,we]}),e[94]=ve,e[95]=we,e[96]=Re):Re=e[96];let Fe;e[97]===Symbol.for("react.memo_cache_sentinel")?(Fe=()=>N(null),e[97]=Fe):Fe=e[97];let Ke;e[98]!==n?(Ke=n("settings.common.actions.cancel"),e[98]=n,e[99]=Ke):Ke=e[99];let Ee;e[100]!==m||e[101]!==Ke?(Ee=s.jsx(V,{size:"sm",variant:"ghost",onClick:Fe,disabled:m,children:Ke}),e[100]=m,e[101]=Ke,e[102]=Ee):Ee=e[102];let je;e[103]!==m||e[104]!==n?(je=n(m?"settings.mcp.sidebar.actions.deleting":"settings.common.actions.delete"),e[103]=m,e[104]=n,e[105]=je):je=e[105];let Ze;e[106]!==U||e[107]!==m||e[108]!==je?(Ze=s.jsx(V,{size:"sm",onClick:U,disabled:m,children:je}),e[106]=U,e[107]=m,e[108]=je,e[109]=Ze):Ze=e[109];let me;e[110]!==Ee||e[111]!==Ze?(me=s.jsxs(ts,{children:[Ee,Ze]}),e[110]=Ee,e[111]=Ze,e[112]=me):me=e[112];let Ie;e[113]!==Re||e[114]!==me?(Ie=s.jsxs(zt,{className:"max-w-md",children:[Re,me]}),e[113]=Re,e[114]=me,e[115]=Ie):Ie=e[115];let Le;e[116]!==Oe||e[117]!==Ve||e[118]!==Ie?(Le=s.jsx(Kt,{open:Oe,onOpenChange:Ve,children:Ie}),e[116]=Oe,e[117]=Ve,e[118]=Ie,e[119]=Le):Le=e[119];let Xe;return e[120]!==Ue||e[121]!==Ne||e[122]!==Le?(Xe=s.jsxs("div",{className:H,children:[Ue,Ne,Le]}),e[120]=Ue,e[121]=Ne,e[122]=Le,e[123]=Xe):Xe=e[123],Xe};function Wu(t){return{selectedMcpName:t.selectedMcpName,setSelectedMcp:t.setSelectedMcp,setMcpDraft:t.setMcpDraft,loadMcpConfigs:t.loadMcpConfigs,deleteMcp:t.deleteMcp}}function qu(t){return t.refresh}function Ju(t){return t.getErrorForDirectory}function Qu(t){return t.scope==="project"}function Yu(t){return t.scope!=="project"}function Zu(t){return setTimeout(t,500)}function an(t){return typeof t=="object"&&t!==null&&!Array.isArray(t)}function Pa(t){return Array.isArray(t)&&t.every(e=>typeof e=="string")}function nn(t,e){return e!==void 0?{ok:!1,error:t,parsed:e}:{ok:!1,error:t}}function ri(t,e,a){const n=Xu(a),r=typeof a.url=="string"?a.url.trim():"",i=vo(a,"env","environment"),l=vo(a,"headers"),g=ep(a),c=typeof a.oauth=="object"&&a.oauth!==null?String(a.oauth.clientId??"").trim():"",y=typeof a.oauth=="object"&&a.oauth!==null?String(a.oauth.clientSecret??"").trim():"",p=typeof a.oauth=="object"&&a.oauth!==null?String(a.oauth.scope??"").trim():"",b=typeof a.oauth=="object"&&a.oauth!==null?String(a.oauth.redirectUri??"").trim():"",d=tp(a),P=sp(a);return{ok:!0,name:t,type:e,command:n,url:r,environment:i,headers:l,oauthEnabled:g,oauthClientId:c,oauthClientSecret:y,oauthScope:p,oauthRedirectUri:b,timeout:d,enabled:P}}function Xu(t){const e=t.command,a=t.args;if(Pa(e)&&Pa(a))return[...e,...a];if(Pa(e))return e;if(typeof e=="string"&&e.trim()){const n=e.trim().split(/\s+/);return Pa(a)?[...n,...a]:n}return Pa(a)?a:[]}function vo(t,...e){for(const a of e){const n=t[a];if(!an(n))continue;const r=Object.entries(n).filter(([i,l])=>i&&typeof l=="string");if(r.length>0)return r.map(([i,l])=>({key:i,value:String(l)}))}return[]}function ep(t){if(t.oauth===!1||t.oauth===null||t.oauth===void 0||!an(t.oauth))return!1;const e=t.oauth;return!!(typeof e.clientId=="string"&&e.clientId.trim()||typeof e.clientSecret=="string"&&e.clientSecret.trim()||typeof e.scope=="string"&&e.scope.trim()||typeof e.redirectUri=="string"&&e.redirectUri.trim())}function tp(t){const e=t.timeout;if(typeof e=="number"&&Number.isFinite(e)&&e>0)return String(Math.floor(e));if(typeof e=="string"&&e.trim()){const a=Number(e);if(Number.isFinite(a)&&a>0)return String(Math.floor(a))}return""}function sp(t){return"disabled"in t&&t.disabled===!0?!1:"enabled"in t?!!t.enabled:!0}function np(t){const e=t.mcpServers;if(an(e)){const n=Object.keys(e);if(n.length===1){const r=n[0],i=e[r];if(an(i))return{name:r,entry:i}}if(n.length>1)return null}const a=Object.keys(t).filter(n=>{const r=t[n];return n!=="mcpServers"&&an(r)});if(a.length===1){const n=a[0],r=t[n];if($l(r))return{name:n,entry:r}}return null}function $l(t){return t.type==="local"||t.type==="remote"||Array.isArray(t.command)||typeof t.url=="string"||Array.isArray(t.args)}function ap(t,e){let a;try{const g=t.trim();if(!g)return nn("No JSON content provided");a=JSON.parse(g)}catch(g){return nn(g instanceof Error?`Invalid JSON: ${g.message}`:"Invalid JSON")}if(!an(a))return nn("Expected a JSON object, not an array or primitive");const n=a,r=n.mcpServers;if(an(r)){const g=Object.keys(r);if(g.length===0)return nn("mcpServers object is empty",a);if(g.length>1)return nn("Paste one server at a time. Found "+g.length+" servers in mcpServers",a);const c=g[0],y=r[c];return an(y)?ri(c,oi(y),y):nn("Server entry is not a valid object",a)}const i=n.mcp;if(an(i)){const g=Object.keys(i);if(g.length===0)return nn("mcp object is empty",a);if(g.length>1)return nn("Paste one server at a time. Found "+g.length+" servers in mcp",a);const c=g[0],y=i[c];return an(y)?ri(c,oi(y),y):nn("Server entry in mcp is not a valid object",a)}const l=np(n);if(l)return ri(l.name,oi(l.entry),l.entry);if($l(n)){const g=oi(n),c=typeof n.name=="string"&&n.name.trim()?n.name.trim():e?.fallbackName;return ri(c,g,n)}return nn("No recognizable MCP server configuration found in JSON",a)}function oi(t){return t.type==="remote"?"remote":t.type==="local"?"local":typeof t.url=="string"&&t.url.trim()?"remote":(Array.isArray(t.command)||typeof t.command=="string"||Array.isArray(t.args),"local")}function ip(t,e,a){const n=a?.isNewServer??!1,r=t.name,i=n&&r?r:e.name??"";return{...e,name:i,type:t.type,command:t.type==="local"?t.command:[],url:t.type==="remote"?t.url:"",environment:t.environment,headers:t.type==="remote"?t.headers:[],oauthEnabled:t.type==="remote"?t.oauthEnabled:!1,oauthClientId:t.type==="remote"?t.oauthClientId:"",oauthClientSecret:t.type==="remote"?t.oauthClientSecret:"",oauthScope:t.type==="remote"?t.oauthScope:"",oauthRedirectUri:t.type==="remote"?t.oauthRedirectUri:"",timeout:t.type==="remote"?t.timeout:"",enabled:t.enabled}}function Vl(t){const e=[];let a="",n=!1,r=!1;for(let i=0;i<t.length;i++){const l=t[i];if(l==="'"&&!r){n=!n;continue}if(l==='"'&&!n){r=!r;continue}if((l===" "||l===" ")&&!n&&!r){a&&(e.push(a),a="");continue}a+=l}return a&&e.push(a),e}function rp(t){const e=t.trim();if(!e)return{code:null,context:null,stateKey:null};try{const a=new URL(e),n=a.searchParams.get("code");if(typeof n=="string"&&n.trim())return{code:n.trim(),context:Nc(a.searchParams),stateKey:jl(a.searchParams)}}catch{}return{code:e,context:null,stateKey:null}}const op=t=>{const e=ut.c(27),{value:a,onChange:n,preview:r,onDetectUrl:i}=t;let l;e[0]!==a?(l=()=>a.join(`
|
|
4
|
+
`),e[0]=a,e[1]=l):l=e[1];const[g,c]=o.useState(l),y=o.useRef(a);let p,b;e[2]!==a?(p=()=>{JSON.stringify(y.current)!==JSON.stringify(a)&&(y.current=a,c(a.join(`
|
|
5
|
+
`)))},b=[a],e[2]=a,e[3]=p,e[4]=b):(p=e[3],b=e[4]),o.useEffect(p,b);let d;e[5]!==n||e[6]!==i?(d=j=>{const h=j.split(`
|
|
6
|
+
`).filter(hp);if(i&&h.length===1&&/^https?:\/\/\S+$/i.test(h[0].trim())){i(h[0].trim());return}n(h)},e[5]=n,e[6]=i,e[7]=d):d=e[7];const P=d;let f;e[8]!==n?(f=j=>{const w=j.clipboardData.getData("text").trim();if(!w||w.includes(`
|
|
7
|
+
`)||!/\s/.test(w))return;const F=j.currentTarget;if(F.selectionStart!==0||F.selectionEnd!==F.value.length)return;j.preventDefault();const T=Vl(w);c(T.join(`
|
|
8
|
+
`)),n(T)},e[8]=n,e[9]=f):f=e[9];const C=f;let v;e[10]!==P?(v=j=>{c(j.target.value),P(j.target.value)},e[10]=P,e[11]=v):v=e[11];let N;e[12]!==P||e[13]!==g?(N=()=>{const j=g.split(`
|
|
9
|
+
`).map(fp).join(`
|
|
10
|
+
`);c(j),P(j)},e[12]=P,e[13]=g,e[14]=N):N=e[14];const m=Math.max(4,a.length+1);let A;e[15]!==C||e[16]!==v||e[17]!==N||e[18]!==m||e[19]!==g?(A=s.jsx(Ts,{onPaste:C,value:g,onChange:v,onBlur:N,placeholder:`npx
|
|
11
|
+
-y
|
|
12
|
+
@modelcontextprotocol/server-postgres
|
|
13
|
+
postgresql://user:pass@host/db`,rows:m,className:"font-mono typography-meta min-h-[80px]",spellCheck:!1}),e[15]=C,e[16]=v,e[17]=N,e[18]=m,e[19]=g,e[20]=A):A=e[20];let R;e[21]!==r||e[22]!==a?(R=a.length>0&&s.jsxs("details",{className:"group",children:[s.jsx("summary",{className:"typography-micro text-muted-foreground/60 cursor-pointer select-none hover:text-muted-foreground",children:r(a.length)}),s.jsx("div",{className:"mt-1 rounded-md bg-[var(--surface-elevated)] px-3 py-2 overflow-x-auto",children:s.jsx("code",{className:"typography-micro text-foreground/80 whitespace-pre",children:a.map(xp)})})]}),e[21]=r,e[22]=a,e[23]=R):R=e[23];let I;return e[24]!==R||e[25]!==A?(I=s.jsxs("div",{className:"space-y-2","data-bwignore":"true","data-1p-ignore":"true","data-lpignore":"true",children:[A,R]}),e[24]=R,e[25]=A,e[26]=I):I=e[26],I},lp=t=>t.toUpperCase().replace(/[^A-Z0-9_]/g,"_"),yo=({value:t,onChange:e,keyTransform:a=lp,keyPlaceholder:n="API_KEY",keyInputClassName:r="w-36 shrink-0 font-mono typography-meta uppercase",pasteLabel:i="Paste .env",pasteTitle:l="Paste KEY=VALUE lines from clipboard",noPairsFoundError:g,importSuccess:c,clipboardReadFailed:y,keyLabel:p,valueLabel:b,valuePlaceholder:d,hideValueTitle:P,showValueTitle:f,addVariable:C,plainTextWarning:v,removeVariableAria:N})=>{const[m,A]=o.useState(new Set),R=()=>e([...t,{key:"",value:""}]),I=T=>{e(t.filter((S,D)=>D!==T)),A(S=>{const D=new Set(S);return D.delete(T),D})},j=(T,S,D)=>{const $=[...t];$[T]={...$[T],[S]:D},e($)},h=T=>{A(S=>{const D=new Set(S);return D.has(T)?D.delete(T):D.add(T),D})},w=async()=>{try{const T=await navigator.clipboard.readText(),S=[];for(const $ of T.split(`
|
|
14
|
+
`)){const B=$.trim();if(!B||B.startsWith("#"))continue;const k=B.indexOf("=");if(k===-1)continue;const G=B.slice(0,k).trim();let M=B.slice(k+1).trim();(M.startsWith('"')&&M.endsWith('"')||M.startsWith("'")&&M.endsWith("'"))&&(M=M.slice(1,-1)),G&&S.push({key:G,value:M})}if(S.length===0){E.error(g);return}const D=[...t];for(const $ of S){const B=D.findIndex(k=>k.key===$.key);B!==-1?D[B]=$:D.push($)}e(D),E.success(c(S.length))}catch{E.error(y)}},F=t.some(T=>T.value.length>0);return s.jsxs("div",{className:"space-y-2",children:[s.jsxs("div",{className:"flex items-center justify-between gap-2",children:[s.jsxs("div",{className:"flex items-center gap-3",children:[s.jsx("span",{className:"typography-micro text-muted-foreground w-32 shrink-0",children:p}),s.jsx("span",{className:"typography-micro text-muted-foreground",children:b})]}),s.jsxs(V,{variant:"ghost",size:"xs",className:"!font-normal gap-1 text-muted-foreground",onClick:w,type:"button",title:l,children:[s.jsx(O,{name:"clipboard",className:"h-3 w-3"}),i]})]}),s.jsx("div",{className:"space-y-1.5",children:t.map((T,S)=>s.jsxs("div",{className:"flex items-center gap-2",children:[s.jsx(He,{value:T.key,onChange:D=>j(S,"key",a(D.target.value)),placeholder:n,className:r,"data-bwignore":"true","data-1p-ignore":"true","data-lpignore":"true",spellCheck:!1}),s.jsxs("div",{className:"relative flex-1 flex items-center",children:[s.jsx(He,{type:m.has(S)?"text":"password",value:T.value,onChange:D=>j(S,"value",D.target.value),placeholder:d,className:"font-mono typography-meta pr-8 w-full",autoComplete:"new-password","data-bwignore":"true","data-1p-ignore":"true","data-lpignore":"true",spellCheck:!1}),s.jsx("button",{type:"button",onClick:()=>h(S),className:"absolute right-2 text-muted-foreground/60 hover:text-muted-foreground",title:m.has(S)?P:f,children:m.has(S)?s.jsx(O,{name:"eye-off",className:"h-3.5 w-3.5"}):s.jsx(O,{name:"eye",className:"h-3.5 w-3.5"})})]}),s.jsx(V,{size:"sm",variant:"ghost",className:"h-7 w-7 px-0 shrink-0 text-muted-foreground hover:text-[var(--status-error)]",onClick:()=>I(S),"aria-label":N,children:s.jsx(O,{name:"delete-bin",className:"h-3.5 w-3.5"})})]},S))}),s.jsxs(V,{variant:"outline",size:"xs",className:"!font-normal gap-1.5",onClick:R,type:"button",children:[s.jsx(O,{name:"add",className:"h-3.5 w-3.5"}),C]}),F&&s.jsx("p",{className:"typography-micro text-muted-foreground/60",children:v})]})},Yi=t=>{const e=ut.c(14),{status:a,enabled:n,getStatusLabel:r,variant:i}=t,l=i===void 0?"compact":i;if(!n||!a)return null;let g,c;if(e[0]!==r||e[1]!==a||e[2]!==l){c=Symbol.for("react.early_return_sentinel");e:{const d={connected:{text:"text-[var(--status-success)]",bg:"bg-[var(--status-success)]/10"},failed:{text:"text-[var(--status-error)]",bg:"bg-[var(--status-error)]/10"},needs_auth:{text:"text-[var(--status-warning)]",bg:"bg-[var(--status-warning)]/10"},needs_client_registration:{text:"text-[var(--status-warning)]",bg:"bg-[var(--status-warning)]/10"},awaiting_restart:{text:"text-[var(--status-warning)]",bg:"bg-[var(--status-warning)]/10"}}[a]??{text:"text-muted-foreground",bg:""};if(l==="pill"){const P=xe("typography-micro font-medium rounded-full px-2 py-0.5",d.text,d.bg);let f;e[5]!==r||e[6]!==a?(f=r(a),e[5]=r,e[6]=a,e[7]=f):f=e[7],c=s.jsxs("span",{className:P,children:["● ",f]});break e}g=xe("typography-micro font-medium",d.text)}e[0]=r,e[1]=a,e[2]=l,e[3]=g,e[4]=c}else g=e[3],c=e[4];if(c!==Symbol.for("react.early_return_sentinel"))return c;let y;e[8]!==r||e[9]!==a?(y=r(a),e[8]=r,e[9]=a,e[10]=y):y=e[10];let p;return e[11]!==g||e[12]!==y?(p=s.jsxs("span",{className:g,children:["● ",y]}),e[11]=g,e[12]=y,e[13]=p):p=e[13],p},cp=(t,e,a)=>{switch(t){case"connected":return e("settings.mcp.page.status.description.connected");case"failed":return a?.trim()||e("settings.mcp.page.status.description.failedDefault");case"needs_auth":return e("settings.mcp.page.status.description.needsAuth");case"needs_client_registration":return a?.trim()||e("settings.mcp.page.status.description.needsClientRegistrationDefault");case"disabled":return e("settings.mcp.page.status.description.disabled");default:return e("settings.mcp.page.status.description.default")}},dp=t=>{switch(t){case"failed":return"border-[var(--status-error-border)] bg-[var(--status-error-background)]";case"needs_auth":case"needs_client_registration":return"border-[var(--status-warning-border)] bg-[var(--status-warning-background)]";default:return"border-[var(--interactive-border)] bg-[var(--surface-elevated)]"}},up=(t,e,a,n)=>!!(t==="failed"||t==="needs_auth"||t==="needs_client_registration"||e||a||n),pp=async t=>{const e=await yt(`/api/mcp/auth/pending?state=${encodeURIComponent(t)}`);if(!e.ok)return null;const a=await e.json().catch(()=>null);return a?.name?.trim()?{name:a.name.trim(),directory:typeof a.directory=="string"&&a.directory.trim()?a.directory.trim():null}:null},Aa=async t=>{typeof t!="string"||!t.trim()||await yt(`/api/mcp/auth/pending?state=${encodeURIComponent(t.trim())}`,{method:"DELETE"}).catch(()=>{})},li=(t,e,a)=>{const n=t instanceof Error?t.message:e;return/oauth state required/i.test(n)?a("settings.mcp.page.toast.authSessionExpired"):n},mp=(t,e)=>{const a=typeof e=="string"&&e.trim()?e.trim():"__global__";return`${t??"__none__"}::${a}`},gp=()=>{const{t}=tt(),e=o.useCallback((oe,ct)=>t(oe,ct),[t]),{selectedMcpName:a,mcpDraft:n,setMcpDraft:r,setSelectedMcp:i,getMcpByName:l,createMcp:g,updateMcp:c,deleteMcp:y}=ya(Us(oe=>({selectedMcpName:oe.selectedMcpName,mcpDraft:oe.mcpDraft,setMcpDraft:oe.setMcpDraft,setSelectedMcp:oe.setSelectedMcp,getMcpByName:oe.getMcpByName,createMcp:oe.createMcp,updateMcp:oe.updateMcp,deleteMcp:oe.deleteMcp}))),p=_s(),b=o.useMemo(()=>cs(),[]),d=Ks(oe=>oe.getStatusForDirectory(p)),P=Ks(oe=>oe.getDiagnosticForDirectory(p)),f=Ks(oe=>oe.refresh),C=Ks(oe=>oe.connect),v=Ks(oe=>oe.disconnect),N=Ks(oe=>oe.completeAuth),m=Ks(oe=>oe.clearAuth),A=Ks(oe=>oe.testConnection),R=Vn(oe=>oe.changes),I=ya(oe=>wl(oe,p)),j=a?l(a,p):null,h=!!(n&&n.name===a&&!j),[w,F]=o.useState(""),[T,S]=o.useState("user"),[D,$]=o.useState("local"),[B,k]=o.useState([]),[G,M]=o.useState(""),[L,J]=o.useState([]),[ee,U]=o.useState([]),[le,_]=o.useState(!0),[H,z]=o.useState(""),[K,te]=o.useState(""),[Y,ae]=o.useState(""),[ge,de]=o.useState(""),[he,se]=o.useState(""),[re,ue]=o.useState(!0),[Ce,Se]=o.useState(!1),[ye,fe]=o.useState(!1),[_e,Ue]=o.useState(!1),[Ne,Oe]=o.useState(!1),[Ve,Ge]=o.useState(!1),[ve,Z]=o.useState(!1),[ne,be]=o.useState(!1),[we,Re]=o.useState(!1),[Fe,Ke]=o.useState(null),[Ee,je]=o.useState(null),[Ze,me]=o.useState(""),[Ie,Le]=o.useState(!1),Xe=o.useRef(0),q=o.useRef(!1),[ke,Pe]=o.useState(!1),[Je,ot]=o.useState(!1),[st,pt]=o.useState(""),[vt,W]=o.useState(null),We=o.useMemo(()=>mp(a,p),[p,a]),nt=o.useRef(We),lt=o.useRef(null),ht=o.useCallback(()=>{Ke(null),je(null),me(""),Le(!1),Xe.current=0,Re(!1),Ge(!1),Z(!1),q.current=!1},[]),Lt=o.useCallback(()=>{pt(""),W(null),ot(!0)},[]),et=o.useCallback(async()=>{try{const oe=await navigator.clipboard.readText();pt(oe),W(null)}catch{E.error(t("settings.mcp.page.toast.clipboardReadFailed"))}},[t]),ft=o.useCallback(()=>{const oe=ap(st,{fallbackName:w});if(!oe.ok){W(oe.error);return}const xt=ip(oe,{name:w,scope:T,type:D,command:B,url:G,environment:L,headers:ee,oauthEnabled:le,oauthClientId:H,oauthClientSecret:K,oauthScope:Y,oauthRedirectUri:ge,timeout:he,enabled:re},{isNewServer:h});F(xt.name),$(xt.type),k(xt.command??[]),M(xt.url??""),J(xt.environment??[]),U(xt.headers??[]),_(xt.oauthEnabled??!1),z(xt.oauthClientId??""),te(xt.oauthClientSecret??""),ae(xt.oauthScope??""),de(xt.oauthRedirectUri??""),se(xt.timeout??""),ue(xt.enabled??!0),ot(!1),pt(""),W(null),E.success(t("settings.mcp.page.toast.configImported"))},[st,w,T,D,B,G,L,ee,le,H,K,Y,ge,he,re,h,t]);o.useEffect(()=>{if(h&&n){F(n.name),S(n.scope||"user"),$(n.type),k(n.command),M(n.url),J(n.environment),U(n.headers),_(n.oauthEnabled),z(n.oauthClientId),te(n.oauthClientSecret),ae(n.oauthScope),de(n.oauthRedirectUri),se(n.timeout),ue(n.enabled),Pe(!1),lt.current={mcpType:n.type,command:n.command,url:n.url,envEntries:n.environment,headerEntries:n.headers,oauthEnabled:n.oauthEnabled,oauthClientId:n.oauthClientId,oauthClientSecret:n.oauthClientSecret,oauthScope:n.oauthScope,oauthRedirectUri:n.oauthRedirectUri,timeout:n.timeout,enabled:n.enabled};return}if(j){S(j.scope==="project"?"project":"user");const oe=Kr(j.environment),ct=j.type==="remote"?j:null,xt=Kr(ct?.headers),Qt=ct?.oauth,Yt=Qt&&typeof Qt=="object"?Qt:null,Bt=Qt!==!1,rs=j.type,ws=rs==="local"?j.command??[]:[],ss=rs==="remote"?j.url??"":"",jt=typeof ct?.timeout=="number"&&Number.isFinite(ct.timeout)?String(ct.timeout):"";$(rs),k(ws),M(ss),J(oe),U(xt),_(Bt),z(Bt?Yt?.clientId??"":""),te(Bt?Yt?.clientSecret??"":""),ae(Bt?Yt?.scope??"":""),de(Bt?Yt?.redirectUri??"":""),se(jt),ue(j.enabled),Pe(!1),lt.current={mcpType:rs,command:ws,url:ss,envEntries:oe,headerEntries:xt,oauthEnabled:Bt,oauthClientId:Bt?Yt?.clientId??"":"",oauthClientSecret:Bt?Yt?.clientSecret??"":"",oauthScope:Bt?Yt?.scope??"":"",oauthRedirectUri:Bt?Yt?.redirectUri??"":"",timeout:jt,enabled:j.enabled}}},[j,h,n]);const bt=o.useMemo(()=>{const oe=lt.current;return oe?D!==oe.mcpType||re!==oe.enabled||JSON.stringify(B)!==JSON.stringify(oe.command)||G!==oe.url||JSON.stringify(L)!==JSON.stringify(oe.envEntries)||JSON.stringify(ee)!==JSON.stringify(oe.headerEntries)||le!==oe.oauthEnabled||H!==oe.oauthClientId||K!==oe.oauthClientSecret||Y!==oe.oauthScope||ge!==oe.oauthRedirectUri||he!==oe.timeout:!1},[D,B,G,L,ee,le,H,K,Y,ge,he,re]),Be=o.useMemo(()=>[{id:"local",label:t("settings.mcp.page.connection.kindCommand"),icon:s.jsx(O,{name:"terminal",className:"h-3.5 w-3.5"})},{id:"remote",label:t("settings.mcp.page.connection.kindLink"),icon:s.jsx(O,{name:"global",className:"h-3.5 w-3.5"})}],[t]),Et=o.useCallback(oe=>{$("remote"),M(oe),k([])},[]),Me=o.useCallback(oe=>{M(oe);const ct=oe.trim();ct&&!/^[a-z][a-z0-9+.-]*:\/\//i.test(ct)&&/\s/.test(ct)&&($("local"),k(Vl(ct)),M(""))},[]),wt=async()=>{const oe=h?w.trim():a??"";if(!oe){E.error(t("settings.mcp.page.toast.nameRequired"));return}if(h&&I.some(xt=>xt.name===oe)){E.error(t("settings.mcp.page.toast.serverNameExists"));return}if(D==="local"&&B.filter(Boolean).length===0){E.error(t("settings.mcp.page.toast.localCommandRequired"));return}if(D==="remote"&&!G.trim()){E.error(t("settings.mcp.page.toast.remoteUrlRequired"));return}const ct={name:oe,scope:T,type:D,command:B,url:G,environment:L,headers:ee,oauthEnabled:le,oauthClientId:H,oauthClientSecret:K,oauthScope:Y,oauthRedirectUri:ge,timeout:he,enabled:re};Se(!0);try{const xt=h?await g(ct,p):await c(oe,ct,p);xt.ok?(await Aa(Ee),ht(),h&&(r(null),i(oe)),await f({directory:p,silent:!0}),xt.reloadFailed?E.warning(xt.message||t(h?"settings.mcp.page.toast.serverCreatedReloadFailed":"settings.mcp.page.toast.savedReloadFailed"),{description:xt.warning||t("settings.mcp.page.toast.retryRefreshHint")}):xt.restartDeferred?E.success(t("settings.view.pendingRestart.saved")):E.success(xt.message||t(h?"settings.mcp.page.toast.serverCreatedReloading":"settings.mcp.page.toast.savedReloading"))):E.error(t("settings.mcp.page.toast.saveFailed"))}catch(xt){E.error(xt instanceof Error?xt.message:t("settings.mcp.page.toast.unexpectedError"))}finally{Se(!1)}},Q=async()=>{if(!a)return;Ue(!0);const oe=await y(a,p);oe.ok?(await Aa(Ee),ht(),oe.reloadFailed?E.warning(oe.message||t("settings.mcp.page.toast.serverDeletedReloadFailed",{name:a}),{description:oe.warning||t("settings.mcp.page.toast.refreshListIfStale")}):E.success(oe.message||t("settings.mcp.page.toast.serverDeleted",{name:a})),fe(!1)):E.error(t("settings.mcp.page.toast.deleteFailed")),Ue(!1)},pe=async()=>{if(a){Oe(!0);try{if(d[a]?.status==="connected")await v(a,p),E.success(t("settings.mcp.page.toast.disconnected"));else{await C(a,p),await f({directory:p,silent:!0});const ct=Ks.getState().getStatusForDirectory(p)[a];ct?.status==="connected"?E.success(t("settings.mcp.page.toast.connected")):ct?.status==="needs_auth"?E.message(t("settings.mcp.page.toast.connectionNeedsAuthorization")):ct?.status==="needs_client_registration"?E.message(t("settings.mcp.page.toast.connectionNeedsClientRegistration")):ct?.status==="failed"?E.error(ct.error||t("settings.mcp.page.toast.connectionFailed")):E.message(t("settings.mcp.page.toast.connectionAttemptFinished"));return}await f({directory:p,silent:!0})}catch(oe){E.error(oe instanceof Error?oe.message:t("settings.mcp.page.toast.connectionFailed"))}finally{Oe(!1)}}},De=o.useCallback(()=>h?(E.error(t("settings.mcp.page.toast.createServerBeforeLiveActions")),!1):bt?(E.error(t("settings.mcp.page.toast.saveBeforeLiveActions")),!1):!0,[bt,h,t]),Ae=o.useCallback(async(oe=!1)=>{try{await f({directory:p,silent:oe})}catch(ct){oe||E.error(ct instanceof Error?ct.message:t("settings.mcp.page.toast.refreshStatusFailed"))}},[p,f,t]);o.useEffect(()=>{Ae(!0)},[Ae]),o.useEffect(()=>{nt.current=We,Oe(!1),be(!1),ht()},[ht,We]);const it=o.useCallback(async()=>{if(!a||D!=="remote"||!De())return;Ge(!0);const oe=We;let ct=null;try{const xt=Ks.getState().getStatusForDirectory(p)[a]?.status;q.current=xt==="needs_auth"||xt==="needs_client_registration";const{authorizationUrl:Qt,opened:Yt,nativeFlow:Bt,completion:rs}=await jc({name:a,directory:p});if(Bt){if(nt.current!==oe)return;Ke(null),je(null),Le(!0),Xe.current=0,E.message(t("settings.mcp.page.toast.completeAuthorizationInBrowser")),rs?.then(()=>{nt.current===oe&&(Le(!1),Xe.current=0,q.current=!1,E.success(t("settings.mcp.page.toast.authorizationCompleted")))}).catch(ss=>{nt.current===oe&&(Le(!1),Xe.current=0,q.current=!1,E.error(li(ss,t("settings.mcp.page.toast.authorizationFailed"),e)))});return}const ws=jl(new URL(Qt).searchParams);if(ct=ws,nt.current!==oe||(Ke(Qt),je(ws??null),Le(!0),Xe.current=0,nt.current!==oe))return;Yt?E.message(t(b?"settings.mcp.page.toast.completeAuthorizationInBrowserWithPaste":"settings.mcp.page.toast.completeAuthorizationInBrowser")):E.error(t("settings.mcp.page.toast.openAuthorizationUrlFailed"))}catch(xt){await Aa(ct),nt.current===oe&&E.error(li(xt,t("settings.mcp.page.toast.authorizationStartFailed"),e))}finally{nt.current===oe&&Ge(!1)}},[p,b,D,De,We,a,t,e]),rt=o.useCallback(async()=>{if(!a||!De())return;Z(!0);const oe=We;try{if(await m(a,p),nt.current!==oe)return;Ke(null),je(null),me(""),Le(!1),Xe.current=0,await Aa(Ee),E.success(t("settings.mcp.page.toast.savedAuthorizationRemoved"))}catch(ct){nt.current===oe&&E.error(li(ct,t("settings.mcp.page.toast.clearAuthorizationFailed"),e))}finally{nt.current===oe&&Z(!1)}},[Ee,m,p,De,We,a,t,e]),qe=o.useCallback(async()=>{if(!Fe)return;if((await Ka(Fe)).ok){E.success(t("settings.mcp.page.toast.authorizationUrlCopied"));return}E.error(t("settings.mcp.page.toast.authorizationUrlCopyFailed"))},[Fe,t]),Pt=o.useCallback(async()=>{const oe=rp(Ze);if(!oe.code){E.error(t("settings.mcp.page.toast.pasteCallbackOrCodeFirst"));return}const ct=oe.stateKey?await pp(oe.stateKey):null,xt=oe.context??ct,Qt=xt?.name??a,Yt=xt?.directory??p;if(!Qt){E.error(t("settings.mcp.page.toast.missingServerDetails"));return}if(!xt&&!De())return;Re(!0);const Bt=We;try{if(await N(Qt,oe.code,Yt),await Aa(oe.stateKey??Ee),nt.current!==Bt)return;me(""),Ke(null),je(null),Le(!1),Xe.current=0,E.success(Qt===a?t("settings.mcp.page.toast.authorizationCompleted"):t("settings.mcp.page.toast.authorizationCompletedFor",{name:Qt}))}catch(rs){nt.current===Bt&&E.error(li(rs,t("settings.mcp.page.toast.authorizationCompleteFailed"),e))}finally{nt.current===Bt&&Re(!1)}},[Ze,Ee,N,p,De,We,a,t,e]),ys=o.useCallback(async()=>{if(!(!a||!De())){if(!re){E.error(t("settings.mcp.page.toast.enableServerBeforeTest"));return}be(!0);try{const oe=await A(a,p),ct=oe.status?.status;oe.warning?E.warning(oe.warning):ct==="connected"?E.success(t("settings.mcp.page.toast.connectionTestSucceeded")):ct==="needs_auth"?E.message(t("settings.mcp.page.toast.connectionNeedsAuthorization")):ct==="needs_client_registration"?E.message(t("settings.mcp.page.toast.connectionNeedsClientRegistration")):ct==="failed"?E.error(oe.status?.error||oe.error||t("settings.mcp.page.toast.connectionTestFailed")):oe.error?E.error(oe.error):E.message(t("settings.mcp.page.toast.connectionTestFinished"))}catch(oe){E.error(oe instanceof Error?oe.message:t("settings.mcp.page.toast.connectionTestFailed"))}finally{be(!1)}}},[p,re,De,a,t,A]);if(o.useEffect(()=>{if(!Ie||!a)return;const oe=window.setInterval(()=>{(async()=>{Xe.current+=1,await f({directory:p,silent:!0});const ct=Ks.getState().getStatusForDirectory(p)[a];if(ct){if(q.current&&ct.status!=="needs_auth"&&ct.status!=="needs_client_registration"){Le(!1),Xe.current=0,q.current=!1,Ke(null),me(""),ct.status==="connected"&&E.success(t("settings.mcp.page.toast.authorizationCompleted"));return}if(!q.current&&ct.status==="failed"){Le(!1),Xe.current=0,q.current=!1,E.error(ct.error||t("settings.mcp.page.toast.authorizationFailed"));return}Xe.current>=30&&(Le(!1),Xe.current=0,q.current=!1,E.message(t("settings.mcp.page.toast.authorizationStillInProgress")))}})()},2e3);return()=>{window.clearInterval(oe)}},[p,Ie,f,a,t]),!a)return s.jsx("div",{className:"flex h-full items-center justify-center",children:s.jsxs("div",{className:"text-center text-muted-foreground",children:[s.jsx(O,{name:"plug",className:"mx-auto mb-3 h-12 w-12 opacity-50"}),s.jsx("p",{className:"typography-body",children:t("settings.mcp.page.empty.selectServer")}),s.jsx("p",{className:"typography-meta mt-1 opacity-75",children:t("settings.mcp.page.empty.addNewOne")})]})});const Xt=d[a],Os=a?P[a]:void 0,Wt=Xt??Os,is=!h&&!Wt&&R.some(oe=>oe.scope==="mcp"&&oe.id.startsWith(`mcp:${a}:`)),Ht=Xt?.status==="connected",bs=Xt?.status==="needs_auth"||Xt?.status==="needs_client_registration",gs=b||!a?null:kc(a),hs=async()=>{if(gs)try{await navigator.clipboard.writeText(gs),E.success(t("settings.mcp.page.toast.copiedCallbackUrl"))}catch{E.error(t("settings.mcp.page.toast.clipboardWriteFailed"))}},ds=cp(Wt?.status,e,Wt&&"error"in Wt?Wt.error:void 0),Es=oe=>{switch(oe){case"connected":return t("settings.mcp.page.status.label.connected");case"failed":return t("settings.mcp.page.status.label.failed");case"needs_auth":return t("settings.mcp.page.status.label.needsAuth");case"needs_client_registration":return t("settings.mcp.page.status.label.needsRegistration");case"awaiting_restart":return t("settings.mcp.page.status.label.awaitingRestart");default:return oe}};return s.jsxs(s.Fragment,{children:[s.jsxs(es,{title:h?t("settings.mcp.page.header.newServer"):a,titleAccessory:h?void 0:s.jsx(Yi,{status:is?"awaiting_restart":Wt?.status,enabled:re,getStatusLabel:Es,variant:"pill"}),description:h?t("settings.mcp.page.header.configureNewServer"):t("settings.mcp.page.header.transport",{type:t(D==="local"?"settings.mcp.page.transport.local":"settings.mcp.page.transport.remote")}),headerEnd:!h&&!is?s.jsxs("div",{className:"flex flex-wrap items-center gap-2",children:[s.jsx(V,{variant:Ht?"outline":"default",size:"xs",className:"!font-normal",onClick:pe,disabled:Ne||!re,children:t(Ne?"settings.mcp.page.actions.working":Ht?"settings.mcp.page.actions.disconnect":"settings.mcp.page.actions.connect")}),D==="remote"&&s.jsxs(s.Fragment,{children:[s.jsx(V,{variant:bs?"default":"outline",size:"xs",className:"!font-normal",onClick:()=>{it()},disabled:Ve||!re,children:t(Ve?"settings.mcp.page.actions.starting":Ht?"settings.mcp.page.actions.reauthorize":"settings.mcp.page.actions.authorize")}),s.jsx(V,{variant:"ghost",size:"xs",className:"!font-normal gap-1 text-muted-foreground",onClick:()=>{rt()},disabled:ve||!re,children:t(ve?"settings.mcp.page.actions.clearing":"settings.mcp.page.actions.clearAuth")})]}),Ht&&s.jsx(V,{variant:"ghost",size:"xs",className:"!font-normal gap-1 text-muted-foreground",onClick:()=>{ys()},disabled:ne||!re,children:t(ne?"settings.mcp.page.actions.testing":"settings.mcp.page.actions.test")})]}):void 0,showSaveStatus:!1,children:[is&&s.jsx(ze,{divider:!1,children:s.jsx("div",{className:"rounded-lg border p-3 border-[var(--status-warning-border)] bg-[var(--status-warning-background)]",children:s.jsxs("div",{className:"min-w-0 space-y-1",children:[s.jsxs("div",{className:"flex flex-wrap items-center gap-x-2 gap-y-1",children:[s.jsx("span",{className:Tt,children:t("settings.mcp.page.status.runtimeStatus")}),s.jsx(Yi,{status:"awaiting_restart",enabled:re,getStatusLabel:Es})]}),s.jsx("p",{className:"typography-meta text-muted-foreground",children:t("settings.mcp.page.status.description.awaitingRestart")})]})})}),!h&&!is&&up(Wt?.status,Fe,bs,Ie)&&s.jsx(ze,{divider:!1,children:s.jsxs("div",{className:xe("rounded-lg border p-3",dp(Wt?.status)),children:[s.jsxs("div",{className:"space-y-4",children:[s.jsxs("div",{className:"min-w-0 space-y-1",children:[s.jsxs("div",{className:"flex flex-wrap items-center gap-x-2 gap-y-1",children:[s.jsx("span",{className:Tt,children:t("settings.mcp.page.status.runtimeStatus")}),s.jsx(Yi,{status:Wt?.status,enabled:re,getStatusLabel:Es})]}),s.jsx("p",{className:"typography-meta text-muted-foreground",children:ds}),s.jsx("p",{className:"typography-micro text-muted-foreground/80",children:T==="project"?t("settings.mcp.page.status.projectScopedTo",{directory:p??t("settings.mcp.page.status.activeProject")}):t("settings.mcp.page.status.userScoped")})]}),s.jsx("div",{className:"flex flex-wrap items-center gap-2",children:!Ht&&s.jsx(V,{variant:"outline",size:"xs",className:"!font-normal",onClick:()=>{ys()},disabled:ne||!re,children:t(ne?"settings.mcp.page.actions.testing":"settings.mcp.page.actions.testConnection")})}),Wt?.status==="needs_client_registration"&&s.jsxs("div",{className:"space-y-3 rounded-md border border-[var(--interactive-border)] bg-[var(--surface-background)] px-3 py-3",children:[s.jsxs("div",{children:[s.jsx(Zs,{as:"div",children:t("settings.mcp.page.registration.title")}),s.jsx("p",{className:"mt-1 typography-micro text-muted-foreground",children:t("settings.mcp.page.registration.description")})]}),gs&&s.jsxs("div",{children:[s.jsx("div",{className:"typography-micro text-muted-foreground",children:t("settings.mcp.page.registration.callbackLabel")}),s.jsxs("div",{className:"mt-1 flex items-start gap-2",children:[s.jsx("span",{className:"min-w-0 flex-1 break-all font-mono typography-micro text-foreground/80",children:gs}),s.jsxs(V,{variant:"outline",size:"xs",className:"!font-normal",onClick:()=>{hs()},children:[s.jsx(O,{name:"clipboard",className:"h-3.5 w-3.5"}),t("settings.mcp.page.actions.copyLink")]})]})]}),s.jsxs("div",{className:"grid gap-3 @xl:grid-cols-2",children:[s.jsx(qt,{label:t("settings.mcp.page.registration.clientId"),children:s.jsx(He,{value:H,onChange:oe=>{z(oe.target.value),_(!0)},className:"font-mono typography-meta","data-bwignore":"true","data-1p-ignore":"true"})}),s.jsx(qt,{label:t("settings.mcp.page.registration.clientSecret"),children:s.jsx(He,{type:"password",value:K,onChange:oe=>{te(oe.target.value),_(!0)},className:"font-mono typography-meta","data-bwignore":"true","data-1p-ignore":"true"})})]}),s.jsx("p",{className:"typography-micro text-muted-foreground",children:t("settings.mcp.page.registration.afterSaving")})]}),Fe&&s.jsx("div",{className:"rounded-md border border-[var(--interactive-border)] bg-[var(--surface-background)] px-3 py-2",children:s.jsxs("div",{className:"space-y-2",children:[s.jsx("div",{className:"typography-micro text-muted-foreground",children:t("settings.mcp.page.auth.authorizationUrl")}),s.jsx("div",{className:"break-all typography-micro text-foreground font-mono",children:Fe}),s.jsxs("div",{className:"flex flex-wrap items-center gap-2",children:[s.jsxs(V,{variant:"outline",size:"xs",className:"!font-normal",onClick:()=>{Pn(Fe)},children:[s.jsx(O,{name:"external-link",className:"h-3.5 w-3.5"}),t("settings.mcp.page.actions.openInBrowser")]}),s.jsxs(V,{variant:"outline",size:"xs",className:"!font-normal",onClick:()=>{qe()},children:[s.jsx(O,{name:"clipboard",className:"h-3.5 w-3.5"}),t("settings.mcp.page.actions.copyLink")]})]})]})}),b&&D==="remote"&&(bs||Ie||Fe)&&s.jsx("div",{className:"rounded-md border border-[var(--interactive-border)] bg-[var(--surface-background)] px-3 py-3",children:s.jsxs("div",{className:"space-y-2",children:[s.jsxs("div",{children:[s.jsx(Zs,{as:"div",children:t("settings.mcp.page.auth.manualFallbackTitle")}),s.jsx("p",{className:"mt-1 typography-micro text-muted-foreground",children:t("settings.mcp.page.auth.manualFallbackDescription")})]}),s.jsx(Ts,{value:Ze,onChange:oe=>me(oe.target.value),placeholder:t("settings.mcp.page.auth.callbackInputPlaceholder"),rows:3,className:"font-mono typography-meta","data-bwignore":"true","data-1p-ignore":"true",spellCheck:!1}),s.jsx("div",{className:"flex flex-wrap items-center gap-2",children:s.jsx(V,{variant:"outline",size:"xs",className:"!font-normal",onClick:()=>{Pt()},disabled:we,children:t(we?"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(ze,{title:t("settings.mcp.page.server.title"),divider:!1,settingsItem:"mcp.server",contentClassName:"space-y-0",titleAccessory:h?s.jsxs(V,{variant:"ghost",size:"xs",className:"!font-normal gap-1.5 text-muted-foreground",onClick:Lt,type:"button",title:t("settings.mcp.page.server.importJsonTitle"),children:[s.jsx(O,{name:"file-code",className:"h-3.5 w-3.5"}),t("settings.mcp.page.server.importJson")]}):null,children:[h&&s.jsxs(Rt,{label:t("settings.mcp.page.server.name"),controlClassName:"flex-wrap @xl:w-auto @xl:flex-1",children:[s.jsx(He,{value:w,onChange:oe=>F(oe.target.value.toLowerCase().replace(/[^a-z0-9_-]/g,"-")),placeholder:t("settings.mcp.page.server.namePlaceholder"),className:"h-7 w-48 min-w-0 max-w-full shrink font-mono px-2",autoFocus:!0}),s.jsxs(St,{value:T,onValueChange:oe=>S(oe),children:[s.jsxs(Ct,{size:Ft,className:"!h-7 min-w-0 max-w-full gap-1.5 px-2",children:[s.jsx(O,{name:T==="user"?"user-3":"folder",className:"h-3.5 w-3.5 shrink-0"}),s.jsx("span",{className:"truncate",children:t(T==="user"?"settings.mcp.page.scope.everywhere":"settings.mcp.page.scope.thisProject")})]}),s.jsxs(It,{align:"end",children:[s.jsx(at,{value:"user",children:s.jsxs("div",{className:"flex items-center gap-2",children:[s.jsx(O,{name:"user-3",className:"h-3.5 w-3.5"}),s.jsx("span",{children:t("settings.mcp.page.scope.everywhere")})]})}),s.jsx(at,{value:"project",children:s.jsxs("div",{className:"flex items-center gap-2",children:[s.jsx(O,{name:"folder",className:"h-3.5 w-3.5"}),s.jsx("span",{children:t("settings.mcp.page.scope.thisProject")})]})})]})]})]}),s.jsx(dt,{checked:re,onChange:ue,label:t("settings.mcp.page.server.enable"),ariaLabel:t("settings.mcp.page.server.enableAria")})]}),s.jsxs(ze,{title:t("settings.mcp.page.connection.title"),description:t("settings.mcp.page.connection.description"),settingsItem:"mcp.command",contentClassName:"space-y-2",children:[s.jsx(Ir,{items:Be,activeId:D,onSelect:oe=>$(oe),layoutMode:"fit",variant:"active-pill",activePillLowercase:!1,className:"h-10"}),D==="local"?s.jsx(op,{value:B,onChange:k,preview:oe=>t("settings.mcp.page.connection.previewArgs",{count:oe}),onDetectUrl:Et}):s.jsx(He,{value:G,onChange:oe=>Me(oe.target.value),placeholder:t("settings.mcp.page.connection.serverUrlPlaceholder"),className:"font-mono typography-meta"}),s.jsx("p",{className:"typography-micro text-muted-foreground",children:t(D==="local"?"settings.mcp.page.connection.hintCommand":"settings.mcp.page.connection.hintLink")})]}),D==="remote"&&s.jsx(ze,{title:t("settings.mcp.page.advanced.title"),settingsItem:"mcp.advanced",children:s.jsxs(An,{open:ke,onOpenChange:Pe,children:[s.jsxs(Tn,{className:"flex w-full items-center justify-between py-0.5 group",children:[s.jsxs("div",{className:"flex items-center gap-1.5 text-left",children:[s.jsx("span",{className:"typography-ui-label font-normal text-foreground",children:t("settings.mcp.page.advanced.configure")}),s.jsxs("span",{className:"typography-micro text-muted-foreground",children:["(",ee.length," ",t("settings.mcp.page.advanced.headers"),he?` · ${he}ms`:"",")"]})]}),ke?s.jsx(O,{name:"arrow-down-s",className:"h-4 w-4 text-muted-foreground group-hover:text-foreground transition-colors"}):s.jsx(O,{name:"arrow-right-s",className:"h-4 w-4 text-muted-foreground group-hover:text-foreground transition-colors"})]}),s.jsx(En,{className:"pt-2",children:s.jsxs("div",{className:"space-y-4",children:[s.jsx("div",{className:"space-y-2",children:s.jsxs("div",{className:"flex flex-col gap-2 @xl:flex-row @xl:items-center @xl:gap-8",children:[s.jsxs("div",{className:"flex min-w-0 flex-row items-center gap-1 @xl:w-56 shrink-0",children:[s.jsx("span",{className:Tt,children:t("settings.mcp.page.advanced.timeoutMs")}),s.jsx(Jt,{children:t("settings.mcp.page.advanced.timeoutHint")})]}),s.jsx("div",{className:"flex items-center gap-2",children:s.jsx(He,{type:"number",min:"1",step:"1",value:he,onChange:oe=>se(oe.target.value),placeholder:"5000",className:"h-7 w-32 font-mono px-2","data-bwignore":"true","data-1p-ignore":"true"})})]})}),s.jsxs("div",{children:[s.jsxs(Zs,{as:"div",className:"mb-2",children:[t("settings.mcp.page.advanced.requestHeaders"),ee.length>0&&s.jsxs("span",{className:"ml-1.5 typography-micro text-muted-foreground font-normal",children:["(",ee.length,")"]})]}),s.jsx(yo,{value:ee,onChange:U,keyTransform:oe=>oe.trimStart(),keyPlaceholder:t("settings.mcp.page.advanced.headerNamePlaceholder"),keyInputClassName:"w-36 shrink-0 font-mono typography-meta",pasteLabel:t("settings.mcp.page.advanced.pasteHeaders"),pasteTitle:t("settings.mcp.page.advanced.pasteHeadersTitle"),noPairsFoundError:t("settings.mcp.page.toast.noKeyValuePairsFound"),importSuccess:oe=>t("settings.mcp.page.toast.importedVariablesCount",{count:oe}),clipboardReadFailed:t("settings.mcp.page.toast.clipboardReadFailed"),keyLabel:t("settings.mcp.page.env.key"),valueLabel:t("settings.mcp.page.env.value"),valuePlaceholder:t("settings.mcp.page.env.valuePlaceholder"),hideValueTitle:t("settings.mcp.page.env.hide"),showValueTitle:t("settings.mcp.page.env.show"),addVariable:t("settings.mcp.page.env.addVariable"),plainTextWarning:t("settings.mcp.page.env.plainTextWarning"),removeVariableAria:t("settings.mcp.page.env.removeVariableAria")})]})]})})]})}),s.jsx(ze,{title:t("settings.mcp.page.env.title"),description:t("settings.mcp.page.env.description"),titleAccessory:L.length>0?s.jsxs("span",{className:"typography-micro text-muted-foreground font-normal",children:["(",L.length,")"]}):null,settingsItem:"mcp.environment",children:L.length===0?s.jsxs(V,{variant:"outline",size:"xs",className:"!font-normal gap-1.5",onClick:()=>J([{key:"",value:""}]),children:[s.jsx(O,{name:"add",className:"h-3.5 w-3.5"}),t("settings.mcp.page.env.addEnvironmentVariable")]}):s.jsx(yo,{value:L,onChange:J,keyPlaceholder:t("settings.mcp.page.env.keyPlaceholder"),pasteLabel:t("settings.mcp.page.env.pasteEnv"),pasteTitle:t("settings.mcp.page.env.pasteEnvTitle"),noPairsFoundError:t("settings.mcp.page.toast.noKeyValuePairsFound"),importSuccess:oe=>t("settings.mcp.page.toast.importedVariablesCount",{count:oe}),clipboardReadFailed:t("settings.mcp.page.toast.clipboardReadFailed"),keyLabel:t("settings.mcp.page.env.key"),valueLabel:t("settings.mcp.page.env.value"),valuePlaceholder:t("settings.mcp.page.env.valuePlaceholder"),hideValueTitle:t("settings.mcp.page.env.hide"),showValueTitle:t("settings.mcp.page.env.show"),addVariable:t("settings.mcp.page.env.addVariable"),plainTextWarning:t("settings.mcp.page.env.plainTextWarning"),removeVariableAria:t("settings.mcp.page.env.removeVariableAria")})}),s.jsxs("div",{className:"flex items-center gap-2 pb-8",children:[s.jsx(V,{onClick:wt,disabled:Ce||!bt&&!h,size:"xs",className:"!font-normal",children:t(Ce?"settings.common.actions.saving":h?"settings.common.actions.create":"settings.common.actions.saveChanges")}),!h&&s.jsx(V,{variant:"destructive",size:"xs",className:"!font-normal",onClick:()=>fe(!0),children:t("settings.common.actions.delete")})]})," "]}),s.jsx(Kt,{open:Je,onOpenChange:oe=>{oe||(ot(!1),pt(""),W(null))},children:s.jsxs(zt,{className:"max-w-md",children:[s.jsxs(_t,{children:[s.jsx($t,{children:t("settings.mcp.page.importDialog.title")}),s.jsx(Vt,{children:t("settings.mcp.page.importDialog.description")})]}),s.jsxs("div",{className:"space-y-3",children:[s.jsx(Ts,{value:st,onChange:oe=>{pt(oe.target.value),W(null)},placeholder:`{
|
|
15
|
+
"mcpServers": {
|
|
16
|
+
"postgres": {
|
|
17
|
+
"command": "npx",
|
|
18
|
+
"args": ["-y", "@modelcontextprotocol/server-postgres"]
|
|
19
|
+
}
|
|
20
|
+
}
|
|
21
|
+
}`,rows:8,className:"font-mono typography-meta",spellCheck:!1,"data-bwignore":"true","data-1p-ignore":"true"}),vt&&s.jsx("p",{className:"typography-micro text-[var(--status-error)]",children:vt}),s.jsx("div",{className:"flex flex-wrap items-center gap-2",children:s.jsxs(V,{variant:"outline",size:"xs",className:"!font-normal gap-1",onClick:et,type:"button",children:[s.jsx(O,{name:"clipboard",className:"h-3.5 w-3.5"}),t("settings.mcp.page.importDialog.pasteFromClipboard")]})})]}),s.jsxs(ts,{children:[s.jsx(V,{variant:"outline",onClick:()=>{ot(!1),pt(""),W(null)},className:"text-foreground",children:t("settings.common.actions.cancel")}),s.jsx(V,{onClick:ft,disabled:!st.trim(),size:"sm",children:t("settings.common.actions.import")})]})]})}),s.jsx(Kt,{open:ye,onOpenChange:oe=>{!oe&&!_e&&fe(!1)},children:s.jsxs(zt,{className:"max-w-md",children:[s.jsxs(_t,{children:[s.jsx($t,{children:t("settings.mcp.page.deleteDialog.title",{name:a??""})}),s.jsxs(Vt,{children:[t("settings.mcp.page.deleteDialog.descriptionPrefix")," ",s.jsx("code",{className:"text-foreground",children:"opencode.json"}),"."," ",t("settings.mcp.page.deleteDialog.descriptionSuffix")]})]}),s.jsxs(ts,{children:[s.jsx(V,{variant:"outline",onClick:()=>fe(!1),disabled:_e,className:"text-foreground",children:t("settings.common.actions.cancel")}),s.jsx(V,{variant:"destructive",size:"sm",onClick:Q,disabled:_e,children:t(_e?"settings.mcp.page.actions.deleting":"settings.common.actions.delete")})]})]})})]})};function hp(t){return t.trim().length>0}function fp(t){return t.trimEnd()}function xp(t,e){return s.jsxs("span",{className:"block",children:[s.jsxs("span",{className:"text-muted-foreground select-none mr-2",children:["[",e,"]"]}),t]},e)}const vi=()=>{try{const e=Gs.getState().getActiveProject?.();if(e?.path?.trim())return e.path.trim();const a=fn.getDirectory();if(a?.trim())return a.trim()}catch(t){console.warn("[PluginsStore] Error resolving config directory:",t)}return null},vp=800,yp=5e3,bp="__default__",mr=new Map,Zi=new Map,wp=1500,Bl=t=>t?.trim()||bp,jp=t=>{mr.delete(Bl(t))},ms=Kl()(Yd(Zd((t,e)=>({entries:[],files:[],selectedId:null,isLoading:!1,registryInfo:{},isLoadingRegistry:!1,draft:null,setSelected:a=>t({selectedId:a}),setDraft:a=>t({draft:a}),loadPlugins:async a=>{const n=vi(),r=Bl(n),i=Date.now(),l=mr.get(r)??0,g=e().entries.length>0||e().files.length>0;if(!a?.force&&g&&i-l<yp)return!0;const c=Zi.get(r);if(!a?.force&&c)return c;const y=(async()=>{t({isLoading:!0});try{const p=await yt(kn("/api/config/plugins",n),{headers:Ta(n)});if(!p.ok)throw new Error("Failed to load plugins");const b=await yi(p);return t({entries:b.entries??[],files:b.files??[],isLoading:!1}),mr.set(r,Date.now()),a?.force||e().loadRegistryInfo(),!0}catch(p){return console.error("[PluginsStore] Failed to load plugins:",p),t({isLoading:!1}),!1}})();Zi.set(r,y);try{return await y}finally{Zi.delete(r)}},loadRegistryInfo:async a=>{const n=Np(a?.specs??e().entries.map(r=>r.spec));if(n.length===0)return t({isLoadingRegistry:!1}),!0;t({isLoadingRegistry:!0});try{const r=vi(),i={...e().registryInfo};for(const l of Sp(n)){const g=await yt(kp(l,a?.force===!0,r),{headers:Ta(r)});if(!g.ok)throw new Error("Failed to load plugin registry info");const c=await yi(g);for(const y of c.results??[])i[y.spec]=y}return t({registryInfo:i,isLoadingRegistry:!1}),!0}catch(r){return console.error("[PluginsStore] Failed to load plugin registry info:",r),t({isLoadingRegistry:!1}),!1}},updateToLatest:async a=>{const n=e().entries.find(i=>i.id===a);if(!n)return{ok:!1};const r=e().registryInfo[n.spec];return!r||r.kind!=="npm-ok"||!r.hasUpdate||!r.latestVersion?{ok:!1}:await e().updateEntry(a,{spec:`${r.name}@${r.latestVersion}`})},createEntry:async a=>{const n=await da("Creating plugin entry…",async r=>await yt(kn("/api/config/plugins/entry",r),{method:"POST",headers:ci(r),body:JSON.stringify(bo(a))}),e,{restartId:a.spec});return n.ok&&e().loadRegistryInfo({specs:[a.spec],force:!0}),n},updateEntry:async(a,n)=>{const r=e().entries.find(g=>g.id===a)?.spec,i=n.spec??r,l=await da("Updating plugin entry…",async g=>await yt(kn(`/api/config/plugins/entry/${encodeURIComponent(a)}`,g),{method:"PATCH",headers:ci(g),body:JSON.stringify(bo(n))}),e,{restartId:a});return l.ok&&i&&e().loadRegistryInfo({specs:[i],force:!0}),l},deleteEntry:async a=>{const n=e().entries.find(i=>i.id===a),r=await da("Deleting plugin entry…",async i=>await yt(kn(`/api/config/plugins/entry/${encodeURIComponent(a)}`,i),{method:"DELETE",headers:Ta(i)}),e,{restartId:a});if(r.ok&&e().selectedId===a&&t({selectedId:null}),r.ok&&n){const i={...e().registryInfo};delete i[n.spec],t({registryInfo:i})}return r},readFile:async a=>{try{const n=vi(),r=await yt(kn(`/api/config/plugins/file/${encodeURIComponent(a)}`,n),{headers:Ta(n)});if(!r.ok)throw new Error("Failed to read plugin file");return await yi(r)}catch(n){return console.error("[PluginsStore] Failed to read plugin file:",n),null}},createFile:async a=>da("Creating plugin file…",async n=>await yt(kn("/api/config/plugins/file",n),{method:"POST",headers:ci(n),body:JSON.stringify(a)}),e,{restartId:a.fileName}),updateFile:async(a,n)=>da("Updating plugin file…",async r=>await yt(kn(`/api/config/plugins/file/${encodeURIComponent(a)}`,r),{method:"PUT",headers:ci(r),body:JSON.stringify(n)}),e,{restartId:a}),deleteFile:async a=>{const n=await da("Deleting plugin file…",async r=>await yt(kn(`/api/config/plugins/file/${encodeURIComponent(a)}`,r),{method:"DELETE",headers:Ta(r)}),e,{restartId:a});return n.ok&&e().selectedId===a&&t({selectedId:null}),n},getById:a=>e().entries.find(n=>n.id===a)??e().files.find(n=>n.id===a)}),{name:"plugins-store",storage:fd(),partialize:t=>({selectedId:t.selectedId})}),{name:"plugins-store"}));function kn(t,e){const a=e?`?directory=${encodeURIComponent(e)}`:"";return`${t}${a}`}function kp(t,e,a){const n=new URLSearchParams;e&&n.set("refresh","true"),a&&n.set("directory",a);const r=n.toString();return`/api/config/plugins/registry?${`specs=${t.map(encodeURIComponent).join(",")}`}${r?`&${r}`:""}`}function Np(t){return Array.from(new Set(t.map(e=>e.trim()).filter(Boolean)))}function Sp(t){const e=[];let a=[],n=0;for(const r of t){const i=encodeURIComponent(r),l=a.length===0?i.length:n+1+i.length;a.length>0&&l>wp?(e.push(a),a=[r],n=i.length):(a.push(r),n=l)}return a.length>0&&e.push(a),e}function Ta(t){return t?{"x-opencode-directory":t}:void 0}function ci(t){return{"Content-Type":"application/json",...t?{"x-opencode-directory":t}:{}}}function bo(t){const e={};return t.spec!==void 0&&(e.spec=t.spec),t.options!==void 0&&(e.options=t.options),t.scope!==void 0&&(e.scope=t.scope),e}async function da(t,e,a,n){try{const r=vi(),i=await e(r),l=await yi(i).catch(()=>null);if(!i.ok)throw new Error(l?.error||"Failed to update plugin configuration");return jp(r),l?.requiresManualRestart?(await a().loadPlugins({force:!0}),{ok:!0,requiresManualRestart:!0,reloadFailed:l?.reloadFailed===!0,message:l?.message,warning:l?.warning}):vl(l,"plugins",{id:n?.restartId})?(await a().loadPlugins({force:!0}),{ok:!0,restartDeferred:!0,reloadFailed:l?.reloadFailed===!0,message:l?.message,warning:l?.warning}):(l?.requiresReload&&(Sc(t),await Cc({message:l.message,delayMs:l.reloadDelayMs??vp,scopes:["all"]})),await a().loadPlugins({force:!0}),{ok:!0,reloadFailed:l?.reloadFailed===!0,message:l?.message,warning:l?.warning})}catch(r){return console.error("[PluginsStore] Failed to update plugin configuration:",r),{ok:!1}}}async function yi(t){return await t.json()}const Cp=/^[a-z0-9][a-z0-9-_.]*\.(js|ts|mjs|cjs)$/;function Ip(t){const e=t.trim();if(e==="")return{ok:!0,value:void 0};try{const a=JSON.parse(e);return a===null||typeof a!="object"||Array.isArray(a)?{ok:!1}:{ok:!0,value:a}}catch{return{ok:!1}}}const Pp=({open:t,onOpenChange:e,defaultScope:a="user"})=>{const{t:n}=tt(),r=ms(k=>k.createEntry),i=ms(k=>k.createFile),[l,g]=o.useState("npm"),[c,y]=o.useState(""),[p,b]=o.useState(""),[d,P]=o.useState(""),[f,C]=o.useState(""),[v,N]=o.useState(a),[m,A]=o.useState(!1),R=o.useCallback(()=>{y(""),b(""),P(""),C(""),N(a)},[a]);o.useEffect(()=>{t&&(g("npm"),R())},[t,R]);const I=k=>{k!==l&&(g(k),R())},j=o.useMemo(()=>Ip(p),[p]),h=!j.ok,w=l==="file"&&d.trim()!==""&&!Cp.test(d.trim()),F=(l==="npm"||l==="path")&&c.trim()==="",T=l==="file"&&f.trim()==="",S=l==="file"&&d.trim()==="",D=m||h||l==="npm"&&F||l==="path"&&F||l==="file"&&(S||w||T),$=async()=>{if(!D){A(!0);try{let k;l==="file"?k=await i({fileName:d.trim(),content:f,scope:v}):k=await r({spec:c.trim(),options:j.ok?j.value:void 0,scope:v}),k.ok?(k.restartDeferred?E.success(n("settings.view.pendingRestart.saved")):E.success(k.message||n("settings.plugins.toast.created")),k.reloadFailed&&E.warning(n("settings.plugins.toast.reloadFailed")),e(!1)):E.error(k.message||n("settings.plugins.sidebar.toast.deleteFailed"))}finally{A(!1)}}},B=o.useMemo(()=>[{id:"npm",label:n("settings.plugins.dialog.add.tab.npm")},{id:"path",label:n("settings.plugins.dialog.add.tab.path")},{id:"file",label:n("settings.plugins.dialog.add.tab.file")}],[n]);return s.jsx(Kt,{open:t,onOpenChange:k=>{!k&&m||e(k)},children:s.jsxs(zt,{className:"max-w-xl",children:[s.jsxs(_t,{children:[s.jsx($t,{children:n("settings.plugins.dialog.add.title")}),s.jsx(Vt,{children:n("settings.plugins.sidebar.empty.description")})]}),s.jsx(Ir,{items:B,activeId:l,onSelect:k=>I(k),layoutMode:"fit",variant:"active-pill",activePillLowercase:!1,className:"h-10"}),s.jsxs("div",{className:"flex flex-col gap-4",children:[(l==="npm"||l==="path")&&s.jsxs(s.Fragment,{children:[s.jsxs("div",{"data-settings-item":"plugins.spec",className:"flex flex-col gap-1.5",children:[s.jsx("label",{htmlFor:"plugin-spec",className:"typography-ui-label text-foreground",children:n("settings.plugins.page.field.spec")}),s.jsx(He,{id:"plugin-spec",value:c,onChange:k=>y(k.target.value),placeholder:n("settings.plugins.page.field.spec.placeholder"),"aria-invalid":F?!1:void 0,disabled:m}),F&&s.jsx("p",{className:"typography-meta text-muted-foreground",children:n("settings.plugins.validation.specRequired")})]}),s.jsxs("div",{"data-settings-item":"plugins.options",className:"flex flex-col gap-1.5",children:[s.jsx("label",{htmlFor:"plugin-options",className:"typography-ui-label text-foreground",children:n("settings.plugins.page.field.options")}),s.jsx(Ts,{id:"plugin-options",value:p,onChange:k=>b(k.target.value),rows:5,className:"font-mono",hasError:h,disabled:m}),h&&s.jsx("p",{className:"typography-meta text-[var(--status-error)]",children:n("settings.plugins.page.field.options.invalidJson")})]})]}),l==="file"&&s.jsxs(s.Fragment,{children:[s.jsxs("div",{"data-settings-item":"plugins.content",className:"flex flex-col gap-1.5",children:[s.jsx("label",{htmlFor:"plugin-filename",className:"typography-ui-label text-foreground",children:n("settings.plugins.page.field.fileName")}),s.jsx(He,{id:"plugin-filename",value:d,onChange:k=>P(k.target.value),placeholder:"my-plugin.ts","aria-invalid":w||void 0,disabled:m}),w&&s.jsx("p",{className:"typography-meta text-[var(--status-error)]",children:n("settings.plugins.validation.fileName")})]}),s.jsxs("div",{className:"flex flex-col gap-1.5",children:[s.jsx("label",{htmlFor:"plugin-content",className:"typography-ui-label text-foreground",children:n("settings.plugins.page.field.content")}),s.jsx(Ts,{id:"plugin-content",value:f,onChange:k=>C(k.target.value),rows:16,className:"font-mono",disabled:m})]})]}),s.jsxs("div",{className:"flex flex-col gap-1.5",children:[s.jsx("span",{className:"typography-ui-label text-foreground",children:n("settings.plugins.page.field.scope")}),s.jsx("div",{className:"flex items-center gap-4",children:["user","project"].map(k=>{const G=v===k,M=n(k==="user"?"settings.plugins.scope.user":"settings.plugins.scope.project");return s.jsxs("button",{type:"button",onClick:()=>N(k),disabled:m,className:"flex items-center gap-2 py-1 text-left disabled:opacity-50",children:[s.jsx(jr,{checked:G,onChange:()=>N(k),ariaLabel:M}),s.jsx("span",{className:xe("typography-ui-label font-normal",G?"text-foreground":"text-foreground/60"),children:M})]},k)})})]})]}),s.jsxs(ts,{children:[s.jsx(V,{size:"sm",variant:"ghost",onClick:()=>e(!1),disabled:m,children:n("settings.plugins.dialog.add.action.cancel")}),s.jsxs(V,{size:"sm",onClick:()=>{$()},disabled:D,children:[m?s.jsx(O,{name:"loader-4",className:"h-3.5 w-3.5 animate-spin"}):null,n("settings.plugins.dialog.add.action.submit")]})]})]})})},Ap=t=>{const e=ut.c(33),{spec:a}=t;let n;e[0]!==a?(n=g=>g.registryInfo[a],e[0]=a,e[1]=n):n=e[1];const r=ms(n),{t:i}=tt();if(!r)return null;const l=Tp;switch(r.kind){case"npm-ok":{if(!r.hasUpdate||!r.latestVersion)return null;let g;e[2]===Symbol.for("react.memo_cache_sentinel")?(g=s.jsx(O,{name:"arrow-up-s",className:"h-3 w-3"}),e[2]=g):g=e[2];let c;e[3]!==r.latestVersion?(c=s.jsxs("span",{className:"inline-flex items-center gap-0.5 text-[var(--status-success)]",children:[g,r.latestVersion]}),e[3]=r.latestVersion,e[4]=c):c=e[4];let y;return e[5]!==r.currentVersion||e[6]!==r.latestVersion||e[7]!==i||e[8]!==c?(y=l(c,i("settings.plugins.registry.badge.update.tooltip",{current:r.currentVersion??"",latest:r.latestVersion})),e[5]=r.currentVersion,e[6]=r.latestVersion,e[7]=i,e[8]=c,e[9]=y):y=e[9],y}case"npm-missing-version":{let g;e[10]===Symbol.for("react.memo_cache_sentinel")?(g=s.jsx(O,{name:"error-warning",className:"h-3 w-3 text-[var(--status-warning)]"}),e[10]=g):g=e[10];let c;return e[11]!==r.currentVersion||e[12]!==r.name||e[13]!==i?(c=l(g,i("settings.plugins.registry.badge.missingVersion.tooltip",{version:r.currentVersion,name:r.name})),e[11]=r.currentVersion,e[12]=r.name,e[13]=i,e[14]=c):c=e[14],c}case"npm-missing-package":{let g;e[15]===Symbol.for("react.memo_cache_sentinel")?(g=s.jsx(O,{name:"error-warning",className:"h-3 w-3 text-[var(--status-error)]"}),e[15]=g):g=e[15];let c;return e[16]!==r.name||e[17]!==i?(c=l(g,i("settings.plugins.registry.badge.missingPackage.tooltip",{name:r.name})),e[16]=r.name,e[17]=i,e[18]=c):c=e[18],c}case"npm-malformed":{let g;e[19]===Symbol.for("react.memo_cache_sentinel")?(g=s.jsx(O,{name:"error-warning",className:"h-3 w-3 text-[var(--status-error)]"}),e[19]=g):g=e[19];let c;return e[20]!==i?(c=l(g,i("settings.plugins.registry.badge.malformed.tooltip")),e[20]=i,e[21]=c):c=e[21],c}case"npm-network":{let g;e[22]===Symbol.for("react.memo_cache_sentinel")?(g=s.jsx(O,{name:"cloud-off",className:"h-3 w-3 text-muted-foreground"}),e[22]=g):g=e[22];let c;return e[23]!==i?(c=l(g,i("settings.plugins.registry.badge.network.tooltip")),e[23]=i,e[24]=c):c=e[24],c}case"path-missing":{let g;e[25]===Symbol.for("react.memo_cache_sentinel")?(g=s.jsx(O,{name:"error-warning",className:"h-3 w-3 text-[var(--status-error)]"}),e[25]=g):g=e[25];let c;return e[26]!==r.absolutePath||e[27]!==i?(c=l(g,i("settings.plugins.registry.badge.pathMissing.tooltip",{path:r.absolutePath})),e[26]=r.absolutePath,e[27]=i,e[28]=c):c=e[28],c}case"path-unreadable":{let g;e[29]===Symbol.for("react.memo_cache_sentinel")?(g=s.jsx(O,{name:"error-warning",className:"h-3 w-3 text-[var(--status-warning)]"}),e[29]=g):g=e[29];let c;return e[30]!==r.absolutePath||e[31]!==i?(c=l(g,i("settings.plugins.registry.badge.pathUnreadable.tooltip",{path:r.absolutePath})),e[30]=r.absolutePath,e[31]=i,e[32]=c):c=e[32],c}case"path-ok":return null;default:return null}};function Tp(t,e){return s.jsxs(kr,{children:[s.jsx(Nr,{asChild:!0,children:s.jsx("span",{className:"inline-flex shrink-0 items-center gap-0.5 text-xs",children:t})}),s.jsx(kl,{children:e})]})}const Hl=t=>{const e=ut.c(26),{header:a,footer:n,children:r,className:i,variant:l}=t,g=l===void 0?"sidebar":l,c=cs(),y=o.useRef(null),[p,b]=o.useState(!1),[d,P]=o.useState(!1),f=g==="background"||c?"bg-background":"bg-sidebar",C=f==="bg-background"?"var(--surface-background)":"var(--surface-muted)";let v;e[0]===Symbol.for("react.memo_cache_sentinel")?(v=()=>{const D=y.current;if(!D){b(!1),P(!1);return}if(!(D.scrollHeight>D.clientHeight+1)){b(!1),P(!1);return}b(D.scrollTop>1),P(D.scrollTop+D.clientHeight<D.scrollHeight-1)},e[0]=v):v=e[0];const N=v;let m;e[1]===Symbol.for("react.memo_cache_sentinel")?(m=()=>{N()},e[1]=m):m=e[1];let A;e[2]!==r?(A=[r,N],e[2]=r,e[3]=A):A=e[3],o.useEffect(m,A);let R,I;e[4]===Symbol.for("react.memo_cache_sentinel")?(R=()=>{const D=y.current;if(!D)return;const $=()=>N();return D.addEventListener("scroll",$,{passive:!0}),()=>D.removeEventListener("scroll",$)},I=[N],e[4]=R,e[5]=I):(R=e[4],I=e[5]),o.useEffect(R,I);let j;e[6]!==f||e[7]!==i?(j=xe("flex h-full flex-col",f,i),e[6]=f,e[7]=i,e[8]=j):j=e[8];let h;e[9]!==r?(h=s.jsx(vs,{ref:y,outerClassName:"flex-1 min-h-0",className:"space-y-0.5 px-3 py-2 overflow-x-hidden",children:r}),e[9]=r,e[10]=h):h=e[10];let w;e[11]!==C||e[12]!==p?(w=p&&s.jsx("div",{className:"pointer-events-none absolute inset-x-0 top-0 h-4",style:{background:`linear-gradient(to bottom, ${C} 0%, transparent 100%)`}}),e[11]=C,e[12]=p,e[13]=w):w=e[13];let F;e[14]!==C||e[15]!==d?(F=d&&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]=d,e[16]=F):F=e[16];let T;e[17]!==F||e[18]!==h||e[19]!==w?(T=s.jsxs("div",{className:"relative flex flex-1 min-h-0 flex-col",children:[h,w,F]}),e[17]=F,e[18]=h,e[19]=w,e[20]=T):T=e[20];let S;return e[21]!==n||e[22]!==a||e[23]!==T||e[24]!==j?(S=s.jsxs("div",{className:j,children:[a,T,n]}),e[21]=n,e[22]=a,e[23]=T,e[24]=j,e[25]=S):S=e[25],S},gr=t=>{const e=ut.c(23),{title:a,metadata:n,selected:r,onSelect:i,icon:l,actions:g,className:c}=t,y=r===void 0?!1:r,p=g&&g.length>0,b=y?"bg-interactive-selection":"hover:bg-interactive-hover";let d;e[0]!==c||e[1]!==b?(d=xe("group relative flex items-center rounded-md px-1.5 py-0.5 transition-all duration-200",b,c),e[0]=c,e[1]=b,e[2]=d):d=e[2];let P;e[3]!==a?(P=s.jsx("span",{className:"typography-ui-label font-normal truncate text-foreground",children:a}),e[3]=a,e[4]=P):P=e[4];let f;e[5]!==l||e[6]!==P?(f=s.jsxs("div",{className:"flex items-center gap-1.5",children:[l,P]}),e[5]=l,e[6]=P,e[7]=f):f=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 v;e[10]!==i||e[11]!==f||e[12]!==C?(v=s.jsxs("button",{onClick:i,className:"flex min-w-0 flex-1 flex-col gap-0 rounded-sm text-left focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-primary/50",tabIndex:0,children:[f,C]}),e[10]=i,e[11]=f,e[12]=C,e[13]=v):v=e[13];let N;e[14]!==g||e[15]!==p?(N=p&&s.jsxs(cn,{children:[s.jsx(on,{asChild:!0,children:s.jsx(V,{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(O,{name:"more-2",className:"h-3.5 w-3.5"})})}),s.jsx(ln,{align:"end",className:"w-fit min-w-20",children:g.map(Ep)})]}),e[14]=g,e[15]=p,e[16]=N):N=e[16];let m;e[17]!==v||e[18]!==N?(m=s.jsxs("div",{className:"flex min-w-0 flex-1 items-center",children:[v,N]}),e[17]=v,e[18]=N,e[19]=m):m=e[19];let A;return e[20]!==d||e[21]!==m?(A=s.jsx("div",{className:d,children:m}),e[20]=d,e[21]=m,e[22]=A):A=e[22],A};function Ep(t){const e=t.icon;return s.jsxs(dn,{onClick:a=>{a.stopPropagation(),t.onClick()},className:xe(t.destructive&&"text-destructive focus:text-destructive"),children:[e&&s.jsx(O,{name:e,className:"h-4 w-4 mr-px"}),t.label]},t.label)}const Dp=t=>t.parsedKind==="npm"?"code-box":"folder",Mp=t=>{const e=ut.c(144),{onItemSelect:a,onAddClick:n}=t,{t:r}=tt(),{entries:i,files:l,selectedId:g,setSelected:c,deleteEntry:y,deleteFile:p,loadPlugins:b}=ms(Us(Rp)),d=ms(Lp),P=ms(Op),f=ms(Fp),C=ms(Kp),[v,N]=o.useState(null),[m,A]=o.useState(!1),[R,I]=o.useState(!1);let j,h;e[0]!==b?(j=()=>{b()},h=[b],e[0]=b,e[1]=j,e[2]=h):(j=e[1],h=e[2]),o.useEffect(j,h);let w,F;e[3]===Symbol.for("react.memo_cache_sentinel")?(w=()=>{const et=()=>I(!0);return window.addEventListener("aiworker:settings-open-plugin-add",et),()=>window.removeEventListener("aiworker:settings-open-plugin-add",et)},F=[],e[3]=w,e[4]=F):(w=e[3],F=e[4]),o.useEffect(w,F);let T;if(e[5]!==i||e[6]!==d){T={userEntries:0,projectEntries:0};for(const et of i){const ft=d[et.spec];ft?.kind==="npm-ok"&&ft.hasUpdate&&(et.scope==="user"?T.userEntries=T.userEntries+1:et.scope==="project"&&(T.projectEntries=T.projectEntries+1))}e[5]=i,e[6]=d,e[7]=T}else T=e[7];const S=T;let D;e[8]!==i?(D=i.filter(zp),e[8]=i,e[9]=D):D=e[9];const $=D;let B;e[10]!==i?(B=i.filter(Up),e[10]=i,e[11]=B):B=e[11];const k=B;let G;e[12]!==l?(G=l.filter(_p),e[12]=l,e[13]=G):G=e[13];const M=G;let L;e[14]!==l?(L=l.filter($p),e[14]=l,e[15]=L):L=e[15];const J=L,ee=i.length+l.length,U=ee===0;let le;e[16]!==n?(le=()=>{n?n():I(!0)},e[16]=n,e[17]=le):le=e[17];const _=le;let H;e[18]!==a||e[19]!==c?(H=et=>{c(et),a?.()},e[18]=a,e[19]=c,e[20]=H):H=e[20];const z=H;let K;e[21]!==i||e[22]!==d||e[23]!==r||e[24]!==C?(K=async et=>{const ft=i.find(Me=>Me.id===et);if(!ft)return;const bt=d[ft.spec];if(!bt||bt.kind!=="npm-ok"||!bt.hasUpdate||!bt.latestVersion)return;const Be=bt.latestVersion;(await C(et)).ok?E.success(r("settings.plugins.toast.updatedToLatest",{version:Be})):E.error(r("settings.plugins.toast.refreshFailed"))},e[21]=i,e[22]=d,e[23]=r,e[24]=C,e[25]=K):K=e[25];const te=K;let Y;e[26]!==f||e[27]!==r?(Y=async()=>{E.info(r("settings.plugins.toast.refreshing"));try{await f({force:!0})}catch{E.error(r("settings.plugins.toast.refreshFailed"))}},e[26]=f,e[27]=r,e[28]=Y):Y=e[28];const ae=Y;let ge;e[29]!==y||e[30]!==p||e[31]!==v||e[32]!==r?(ge=async()=>{if(!v)return;A(!0);const et=v.kind==="entry"?await y(v.id):await p(v.id);et.ok?E.success(et.message||r("settings.plugins.sidebar.toast.deleted",{name:v.label})):E.error(r("settings.plugins.sidebar.toast.deleteFailed")),N(null),A(!1)},e[29]=y,e[30]=p,e[31]=v,e[32]=r,e[33]=ge):ge=e[33];const de=ge;let he;e[34]!==z||e[35]!==te||e[36]!==d||e[37]!==g||e[38]!==r?(he=et=>{const ft=d[et.spec],bt=ft?.kind==="npm-ok"&&ft.hasUpdate&&!!ft.latestVersion,Be=[];return bt&&Be.push({label:r("settings.plugins.sidebar.actions.updateToLatest"),icon:"arrow-up-s",onClick:()=>{te(et.id)}}),Be.push({label:r("settings.common.actions.delete"),icon:"delete-bin",destructive:!0,onClick:()=>N({kind:"entry",id:et.id,label:et.spec})}),s.jsx(gr,{title:s.jsxs("span",{className:"flex min-w-0 items-center gap-1.5",children:[s.jsx("span",{className:"min-w-0 flex-1 truncate",children:et.spec}),s.jsx(Ap,{spec:et.spec})]}),metadata:et.parsedKind==="npm"?r("settings.plugins.sidebar.kind.npm"):r("settings.plugins.sidebar.kind.path"),selected:g===et.id,onSelect:()=>z(et.id),icon:s.jsx(O,{name:Dp(et),className:"h-4 w-4 flex-shrink-0 text-muted-foreground/70"}),actions:Be},et.id)},e[34]=z,e[35]=te,e[36]=d,e[37]=g,e[38]=r,e[39]=he):he=e[39];const se=he;let re;e[40]!==z||e[41]!==g||e[42]!==r?(re=et=>s.jsx(gr,{title:et.fileName,metadata:r("settings.plugins.sidebar.kind.file"),selected:g===et.id,onSelect:()=>z(et.id),icon:s.jsx(O,{name:"file-text",className:"h-4 w-4 flex-shrink-0 text-muted-foreground/70"}),actions:[{label:r("settings.common.actions.delete"),icon:"delete-bin",destructive:!0,onClick:()=>N({kind:"file",id:et.id,label:et.fileName})}]},et.id),e[40]=z,e[41]=g,e[42]=r,e[43]=re):re=e[43];const ue=re;let Ce;e[44]!==r?(Ce=(et,ft,bt)=>{const Be=bt===void 0?0:bt;return s.jsxs(s.Fragment,{children:[s.jsxs("div",{className:"px-2 pb-1.5 pt-2 text-xs font-semibold uppercase tracking-wide text-muted-foreground",children:[et,Be>0&&s.jsx("span",{className:"ml-2 normal-case font-normal text-[var(--status-success)]",children:r(Be===1?"settings.plugins.sidebar.group.updatesAvailable_one":"settings.plugins.sidebar.group.updatesAvailable_other",{count:Be})})]}),ft]})},e[44]=r,e[45]=Ce):Ce=e[45];const Se=Ce;let ye;e[46]!==r?(ye=r("settings.plugins.sidebar.title"),e[46]=r,e[47]=ye):ye=e[47];let fe;e[48]!==ye?(fe=s.jsx("div",{className:"mb-3 flex items-center justify-between gap-3",children:s.jsx("h2",{className:un,children:ye})}),e[48]=ye,e[49]=fe):fe=e[49];let _e;e[50]!==r||e[51]!==ee?(_e=r("settings.plugins.sidebar.total",{count:ee}),e[50]=r,e[51]=ee,e[52]=_e):_e=e[52];let Ue;e[53]!==_e?(Ue=s.jsx("span",{className:"typography-meta text-muted-foreground",children:_e}),e[53]=_e,e[54]=Ue):Ue=e[54];let Ne;e[55]!==ae?(Ne=()=>{ae()},e[55]=ae,e[56]=Ne):Ne=e[56];let Oe;e[57]!==r?(Oe=r("settings.plugins.sidebar.actions.refresh"),e[57]=r,e[58]=Oe):Oe=e[58];let Ve;e[59]!==r?(Ve=r("settings.plugins.sidebar.actions.refresh"),e[59]=r,e[60]=Ve):Ve=e[60];const Ge=P?"size-4 animate-spin":"size-4";let ve;e[61]!==Ge?(ve=s.jsx(O,{name:"refresh",className:Ge}),e[61]=Ge,e[62]=ve):ve=e[62];let Z;e[63]!==P||e[64]!==Ne||e[65]!==Oe||e[66]!==Ve||e[67]!==ve?(Z=s.jsx(V,{type:"button","data-settings-item":"plugins.create",variant:"ghost",size:"icon",className:"h-7 w-7 -my-1 text-muted-foreground",onClick:Ne,disabled:P,"aria-label":Oe,title:Ve,children:ve}),e[63]=P,e[64]=Ne,e[65]=Oe,e[66]=Ve,e[67]=ve,e[68]=Z):Z=e[68];let ne;e[69]!==r?(ne=r("settings.plugins.sidebar.actions.addTitle"),e[69]=r,e[70]=ne):ne=e[70];let be;e[71]!==r?(be=r("settings.plugins.sidebar.actions.addTitle"),e[71]=r,e[72]=be):be=e[72];let we;e[73]===Symbol.for("react.memo_cache_sentinel")?(we=s.jsx(O,{name:"add",className:"size-4"}),e[73]=we):we=e[73];let Re;e[74]!==_||e[75]!==ne||e[76]!==be?(Re=s.jsx(V,{type:"button",variant:"ghost",size:"icon",className:"h-7 w-7 -my-1 text-muted-foreground",onClick:_,"aria-label":ne,title:be,children:we}),e[74]=_,e[75]=ne,e[76]=be,e[77]=Re):Re=e[77];let Fe;e[78]!==Z||e[79]!==Re?(Fe=s.jsxs("div",{className:"flex items-center gap-1",children:[Z,Re]}),e[78]=Z,e[79]=Re,e[80]=Fe):Fe=e[80];let Ke;e[81]!==Ue||e[82]!==Fe?(Ke=s.jsxs("div",{className:"flex items-center justify-between gap-2",children:[Ue,Fe]}),e[81]=Ue,e[82]=Fe,e[83]=Ke):Ke=e[83];let Ee;e[84]!==fe||e[85]!==Ke?(Ee=s.jsxs("div",{className:"border-b px-3 pt-4 pb-3",children:[fe,Ke]}),e[84]=fe,e[85]=Ke,e[86]=Ee):Ee=e[86];let je;e[87]!==U||e[88]!==k||e[89]!==J||e[90]!==se||e[91]!==ue||e[92]!==Se||e[93]!==r||e[94]!==S||e[95]!==$||e[96]!==M?(je=U?s.jsxs("div",{className:"py-12 px-4 text-center text-muted-foreground",children:[s.jsx(O,{name:"plug",className:"mx-auto mb-3 h-10 w-10 opacity-50"}),s.jsx("p",{className:"typography-ui-label font-medium",children:r("settings.plugins.sidebar.empty.title")}),s.jsx("p",{className:"typography-meta mt-1 opacity-75",children:r("settings.plugins.sidebar.empty.description")})]}):s.jsxs(s.Fragment,{children:[$.length>0&&Se(r("settings.plugins.sidebar.group.userEntries"),$.map(se),S.userEntries),M.length>0&&Se(r("settings.plugins.sidebar.group.userFiles"),M.map(ue)),k.length>0&&Se(r("settings.plugins.sidebar.group.projectEntries"),k.map(se),S.projectEntries),J.length>0&&Se(r("settings.plugins.sidebar.group.projectFiles"),J.map(ue))]}),e[87]=U,e[88]=k,e[89]=J,e[90]=se,e[91]=ue,e[92]=Se,e[93]=r,e[94]=S,e[95]=$,e[96]=M,e[97]=je):je=e[97];let Ze;e[98]!==Ee||e[99]!==je?(Ze=s.jsx(Hl,{variant:"background",header:Ee,children:je}),e[98]=Ee,e[99]=je,e[100]=Ze):Ze=e[100];let me;e[101]!==R?(me=s.jsx(Pp,{open:R,onOpenChange:I}),e[101]=R,e[102]=me):me=e[102];const Ie=v!==null;let Le;e[103]!==m?(Le=et=>{!et&&!m&&N(null)},e[103]=m,e[104]=Le):Le=e[104];let Xe;e[105]!==r?(Xe=r("settings.plugins.sidebar.deleteDialog.title"),e[105]=r,e[106]=Xe):Xe=e[106];let q;e[107]!==Xe?(q=s.jsx($t,{children:Xe}),e[107]=Xe,e[108]=q):q=e[108];const ke=v?.label??"";let Pe;e[109]!==r||e[110]!==ke?(Pe=r("settings.plugins.sidebar.deleteDialog.description",{name:ke}),e[109]=r,e[110]=ke,e[111]=Pe):Pe=e[111];let Je;e[112]!==Pe?(Je=s.jsx(Vt,{children:Pe}),e[112]=Pe,e[113]=Je):Je=e[113];let ot;e[114]!==q||e[115]!==Je?(ot=s.jsxs(_t,{children:[q,Je]}),e[114]=q,e[115]=Je,e[116]=ot):ot=e[116];let st;e[117]===Symbol.for("react.memo_cache_sentinel")?(st=()=>N(null),e[117]=st):st=e[117];let pt;e[118]!==r?(pt=r("settings.common.actions.cancel"),e[118]=r,e[119]=pt):pt=e[119];let vt;e[120]!==m||e[121]!==pt?(vt=s.jsx(V,{size:"sm",variant:"ghost",onClick:st,disabled:m,children:pt}),e[120]=m,e[121]=pt,e[122]=vt):vt=e[122];let W;e[123]!==m||e[124]!==r?(W=r(m?"settings.plugins.sidebar.actions.deleting":"settings.common.actions.delete"),e[123]=m,e[124]=r,e[125]=W):W=e[125];let We;e[126]!==de||e[127]!==m||e[128]!==W?(We=s.jsx(V,{size:"sm",variant:"destructive",onClick:de,disabled:m,children:W}),e[126]=de,e[127]=m,e[128]=W,e[129]=We):We=e[129];let nt;e[130]!==vt||e[131]!==We?(nt=s.jsxs(ts,{children:[vt,We]}),e[130]=vt,e[131]=We,e[132]=nt):nt=e[132];let lt;e[133]!==ot||e[134]!==nt?(lt=s.jsxs(zt,{className:"max-w-md",children:[ot,nt]}),e[133]=ot,e[134]=nt,e[135]=lt):lt=e[135];let ht;e[136]!==Ie||e[137]!==Le||e[138]!==lt?(ht=s.jsx(Kt,{open:Ie,onOpenChange:Le,children:lt}),e[136]=Ie,e[137]=Le,e[138]=lt,e[139]=ht):ht=e[139];let Lt;return e[140]!==Ze||e[141]!==me||e[142]!==ht?(Lt=s.jsxs(s.Fragment,{children:[Ze,me,ht]}),e[140]=Ze,e[141]=me,e[142]=ht,e[143]=Lt):Lt=e[143],Lt};function Rp(t){return{entries:t.entries,files:t.files,selectedId:t.selectedId,setSelected:t.setSelected,deleteEntry:t.deleteEntry,deleteFile:t.deleteFile,loadPlugins:t.loadPlugins}}function Lp(t){return t.registryInfo}function Op(t){return t.isLoadingRegistry}function Fp(t){return t.loadRegistryInfo}function Kp(t){return t.updateToLatest}function zp(t){return t.scope==="user"}function Up(t){return t.scope==="project"}function _p(t){return t.scope==="user"}function $p(t){return t.scope==="project"}const Vp=({entryId:t,spec:e})=>{const{t:a}=tt(),n=ms(b=>b.registryInfo[e]),r=ms(b=>b.updateToLatest),[i,l]=o.useState(!1);if(!n)return null;if(n.kind==="npm-ok"){if(!n.hasUpdate||!n.latestVersion)return null;const b=n.latestVersion,d=n.currentVersion??"",P=async()=>{l(!0);try{(await r(t)).ok?E.success(a("settings.plugins.toast.updatedToLatest",{version:b})):E.error(a("settings.plugins.toast.refreshFailed"))}finally{l(!1)}};return s.jsxs("div",{className:"rounded-md border border-border bg-card p-3 flex items-start gap-3",children:[s.jsx(O,{name:"arrow-up",className:"h-5 w-5 text-[var(--status-success)] shrink-0 mt-0.5"}),s.jsxs("div",{className:"flex-1 min-w-0",children:[s.jsx("p",{className:"typography-label text-[var(--status-success)]",children:a("settings.plugins.registry.banner.updateAvailable.title")}),s.jsx("p",{className:"typography-micro text-muted-foreground mt-0.5",children:a("settings.plugins.registry.banner.updateAvailable.description",{current:d,latest:b})})]}),s.jsx(V,{variant:"default",size:"sm",onClick:()=>{P()},disabled:i,children:a("settings.plugins.registry.banner.updateAvailable.action",{latest:b})})]})}if(n.kind==="path-ok")return null;if(n.kind==="npm-network")return s.jsxs("div",{className:"rounded-md border border-border bg-card p-3 flex items-start gap-3",children:[s.jsx(O,{name:"cloud-off",className:"h-5 w-5 text-muted-foreground shrink-0 mt-0.5"}),s.jsx("div",{className:"flex-1 min-w-0",children:s.jsx("p",{className:"typography-micro text-muted-foreground",children:a("settings.plugins.registry.badge.network.tooltip")})})]});const g=n.kind==="path-unreadable",c=g?"var(--status-warning)":"var(--status-error)",y=g?"alert":"error-warning",p=(()=>{switch(n.kind){case"npm-missing-version":return a("settings.plugins.registry.banner.invalid.missingVersion");case"npm-missing-package":return a("settings.plugins.registry.banner.invalid.missingPackage");case"npm-malformed":return a("settings.plugins.registry.banner.invalid.malformed");case"path-missing":return a("settings.plugins.registry.banner.invalid.pathMissing");case"path-unreadable":return a("settings.plugins.registry.banner.invalid.pathUnreadable")}})();return s.jsxs("div",{className:"rounded-md border border-border bg-card p-3 flex items-start gap-3",children:[s.jsx(O,{name:y,className:"h-5 w-5 shrink-0 mt-0.5",style:{color:c}}),s.jsxs("div",{className:"flex-1 min-w-0",children:[s.jsx("p",{className:"typography-label",style:{color:c},children:a("settings.plugins.registry.banner.invalid.title")}),s.jsx("p",{className:"typography-micro text-muted-foreground mt-0.5",children:p})]})]})};function Bp(t){const e=t.trim();if(e.length===0)return{ok:!0,value:void 0};try{const a=JSON.parse(e);return a===null||typeof a!="object"||Array.isArray(a)?{ok:!1}:{ok:!0,value:a}}catch{return{ok:!1}}}function Gl(t){return!t||Object.keys(t).length===0?"":JSON.stringify(t,null,2)}function wo(t){return{mode:"entry",scope:t.scope,spec:t.spec,optionsJson:Gl(t.options),fileName:"",content:""}}function jo(t,e){return{mode:"file",scope:t.scope,spec:"",optionsJson:"",fileName:t.fileName,content:e}}const ko=t=>{const e=ut.c(4),{scope:a,label:n}=t;let r;e[0]===Symbol.for("react.memo_cache_sentinel")?(r=xe("typography-micro font-medium rounded-full px-2 py-0.5","bg-[var(--surface-elevated)] text-muted-foreground","border border-[var(--interactive-border)]"),e[0]=r):r=e[0];let i;return e[1]!==n||e[2]!==a?(i=s.jsx("span",{className:r,"data-scope":a,children:n}),e[1]=n,e[2]=a,e[3]=i):i=e[3],i},Hp=()=>{const{t}=tt(),e=ms(v=>v.selectedId),a=ms(v=>v.entries),n=ms(v=>v.files),r=ms(v=>v.draft),i=ms(v=>v.setDraft),l=ms(v=>v.updateEntry),g=ms(v=>v.updateFile),c=ms(v=>v.readFile),y=o.useMemo(()=>e?a.find(v=>v.id===e)??null:null,[a,e]),p=o.useMemo(()=>e?n.find(v=>v.id===e)??null:null,[n,e]),[b,d]=o.useState(!1),[P,f]=o.useState(!1),C=o.useRef(new Map);if(o.useEffect(()=>{let v=!1;return y?(i(wo(y)),()=>{v=!0}):p?(f(!0),(async()=>{const N=await c(p.id);if(v)return;f(!1);const m=N?.content??"";C.current.set(p.id,m),i(jo(p,m))})(),()=>{v=!0}):(i(null),()=>{v=!0})},[y,p,c,i]),!e)return s.jsx("div",{className:"flex h-full items-center justify-center",children:s.jsxs("div",{className:"text-center text-muted-foreground",children:[s.jsx(O,{name:"plug",className:"mx-auto mb-3 h-12 w-12 opacity-50"}),s.jsx("p",{className:"typography-body",children:t("settings.plugins.page.empty.select")}),s.jsx("p",{className:"typography-meta mt-1 opacity-75",children:t("settings.plugins.page.empty.add")})]})});if(y&&r&&r.mode==="entry"){const v=Bp(r.optionsJson),N=v.ok,m=r.spec!==y.spec||r.optionsJson!==Gl(y.options),A=()=>{i(wo(y))},R=async()=>{if(!N)return;const I=r.spec.trim();if(!I){E.error(t("settings.plugins.validation.specRequired"));return}d(!0);try{const j=await l(y.id,{spec:I,options:v.value});j.ok?j.reloadFailed?E.warning(j.message||t("settings.plugins.toast.reloadFailed"),{description:j.warning}):j.restartDeferred?E.success(t("settings.view.pendingRestart.saved")):E.success(j.message||t("settings.plugins.toast.updated")):E.error(j.message||t("settings.plugins.toast.reloadFailed"))}finally{d(!1)}};return s.jsxs(es,{title:t("settings.plugins.page.header.entry"),titleAccessory:s.jsx(ko,{scope:y.scope,label:y.scope==="project"?t("settings.plugins.sidebar.group.projectEntries"):t("settings.plugins.sidebar.group.userEntries")}),showSaveStatus:!1,children:[s.jsx(ze,{divider:!1,children:s.jsx(Vp,{entryId:y.id,spec:y.spec})}),s.jsx(ze,{title:t("settings.plugins.page.field.spec"),settingsItem:"plugins.spec",children:s.jsx(He,{value:r.spec,onChange:I=>i({...r,spec:I.target.value}),placeholder:t("settings.plugins.page.field.spec.placeholder"),className:"font-mono typography-meta",spellCheck:!1})}),s.jsxs(ze,{title:t("settings.plugins.page.field.options"),settingsItem:"plugins.options",children:[s.jsx(Ts,{value:r.optionsJson,onChange:I=>i({...r,optionsJson:I.target.value}),rows:10,className:xe("font-mono typography-meta min-h-[200px]",!N&&"border-[var(--status-error-border)]"),spellCheck:!1,placeholder:"{ }"}),!N&&s.jsx("p",{className:"typography-micro text-[var(--status-error)]",children:t("settings.plugins.page.field.options.invalidJson")}),s.jsxs("div",{className:"flex items-center gap-2 pt-3",children:[s.jsx(V,{variant:"default",size:"sm",onClick:()=>{R()},disabled:!m||!N||b,children:t("settings.plugins.page.action.save")}),s.jsx(V,{variant:"outline",size:"sm",onClick:A,disabled:!m||b,children:t("settings.plugins.page.action.discard")})]})]})]})}if(p&&r&&r.mode==="file"){const v=C.current.get(p.id)??"",N=r.content!==v||r.fileName!==p.fileName,m=()=>{(async()=>{f(!0);const I=(await c(p.id))?.content??"";f(!1),C.current.set(p.id,I),i(jo(p,I))})()},A=async()=>{d(!0);try{const R=await g(p.id,{content:r.content});R.ok?(C.current.set(p.id,r.content),R.reloadFailed?E.warning(R.message||t("settings.plugins.toast.reloadFailed"),{description:R.warning}):R.restartDeferred?E.success(t("settings.view.pendingRestart.saved")):E.success(R.message||t("settings.plugins.toast.updated"))):E.error(R.message||t("settings.plugins.toast.reloadFailed"))}finally{d(!1)}};return s.jsx(es,{title:t("settings.plugins.page.header.file"),titleAccessory:s.jsxs(s.Fragment,{children:[s.jsx(ko,{scope:p.scope,label:p.scope==="project"?t("settings.plugins.sidebar.group.projectFiles"):t("settings.plugins.sidebar.group.userFiles")}),s.jsx("span",{className:xe("typography-micro font-mono rounded-full px-2 py-0.5","bg-[var(--surface-elevated)] text-foreground","border border-[var(--interactive-border)]"),children:p.fileName})]}),showSaveStatus:!1,children:s.jsxs(ze,{title:t("settings.plugins.page.field.content"),divider:!1,settingsItem:"plugins.content",children:[s.jsx(Ts,{value:r.content,onChange:R=>i({...r,content:R.target.value}),rows:16,className:"font-mono typography-meta min-h-[320px]",spellCheck:!1,disabled:P}),s.jsxs("div",{className:"flex items-center gap-2 pt-3",children:[s.jsx(V,{variant:"default",size:"sm",onClick:()=>{A()},disabled:!N||b||P,children:t("settings.plugins.page.action.save")}),s.jsx(V,{variant:"outline",size:"sm",onClick:m,disabled:b||P,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(O,{name:"loader-4",className:"mx-auto mb-3 h-6 w-6 animate-spin opacity-50"})})})},Gp="<built-in>",za=t=>t?.path===Gp,hr=t=>!!t&&!za(t)&&t.renamable===!0,Wp=t=>{const e=ut.c(157),{onItemSelect:a}=t,{t:n}=tt(),[r,i]=o.useState(null),[l,g]=o.useState(""),[c,y]=o.useState(null),[p,b]=o.useState(!1),[d,P]=o.useState(null),{selectedSkillName:f,setSelectedSkill:C,setSkillDraft:v,deleteSkill:N,renameSkill:m,getSkillDetail:A}=Hs(Us(qp)),R=_s();let I;e[0]!==R?(I=Me=>wr(Me,R),e[0]=R,e[1]=I):I=e[1];const j=Hs(I),h=Hs(Jp);let w,F;e[2]!==h||e[3]!==R?(w=()=>{h(R)},F=[h,R],e[2]=h,e[3]=R,e[4]=w,e[5]=F):(w=e[4],F=e[5]),o.useEffect(w,F);let T;e[6]!==a||e[7]!==C||e[8]!==v||e[9]!==j?(T=()=>{let Me="new-skill",wt=1;for(;j.some(Q=>Q.name===Me);)Me=`new-skill-${wt}`,wt++;v({name:Me,scope:"user",source:"opencode",description:""}),C(Me),a?.()},e[6]=a,e[7]=C,e[8]=v,e[9]=j,e[10]=T):T=e[10];const S=T;let D;e[11]===Symbol.for("react.memo_cache_sentinel")?(D=async Me=>{za(Me)||y(Me)},e[11]=D):D=e[11];const $=D;let B;e[12]!==c||e[13]!==N||e[14]!==R||e[15]!==n?(B=async()=>{if(!c)return;if(za(c)){y(null);return}b(!0),await N(c.name,R)?(E.success(n("settings.skills.sidebar.toast.skillDeleted",{name:c.name})),y(null)):E.error(n("settings.skills.sidebar.toast.deleteSkillFailed")),b(!1)},e[12]=c,e[13]=N,e[14]=R,e[15]=n,e[16]=B):B=e[16];const k=B;let G;e[17]!==A||e[18]!==C||e[19]!==v||e[20]!==R||e[21]!==j||e[22]!==n?(G=async Me=>{if(za(Me))return;const wt=Me.name;let Q=1,pe=`${wt}-copy`;for(;j.some(Ae=>Ae.name===pe);)Q++,pe=`${wt}-copy-${Q}`;const De=await A(Me.name,R);if(!De){E.error(n("settings.skills.sidebar.toast.duplicateLoadFailed"));return}v({name:pe,scope:Me.scope||"user",source:Me.source||"opencode",description:(De.sources.md.fields.includes("description"),""),instructions:""}),C(pe)},e[17]=A,e[18]=C,e[19]=v,e[20]=R,e[21]=j,e[22]=n,e[23]=G):G=e[23];const M=G;let L;e[24]===Symbol.for("react.memo_cache_sentinel")?(L=Me=>{hr(Me)&&(g(Me.name),i(Me))},e[24]=L):L=e[24];const J=L;let ee;e[25]!==r||e[26]!==l||e[27]!==m||e[28]!==C||e[29]!==R||e[30]!==j||e[31]!==n?(ee=async()=>{if(!r)return;if(!hr(r)){i(null);return}const Me=l.trim().replace(/\s+/g,"-").toLowerCase();if(!Me){E.error(n("settings.skills.page.toast.skillNameRequired"));return}if(Me===r.name){i(null);return}if(j.some(Q=>Q.name===Me)){E.error(n("settings.skills.page.toast.skillExists"));return}await m(r.name,Me,R)?(E.success(n("settings.skills.sidebar.toast.skillRenamed",{name:Me})),C(Me)):E.error(n("settings.skills.sidebar.toast.renameFailed")),i(null)},e[25]=r,e[26]=l,e[27]=m,e[28]=C,e[29]=R,e[30]=j,e[31]=n,e[32]=ee):ee=e[32];const U=ee;let le;e[33]!==j?(le=j.filter(Qp),e[33]=j,e[34]=le):le=e[34];const _=le;let H;e[35]!==j?(H=j.filter(Yp),e[35]=j,e[36]=H):H=e[36];const z=H;let K;e[37]===Symbol.for("react.memo_cache_sentinel")?(K=function(wt){const Q={},pe=[];for(const Ae of wt)Ae.group?(Q[Ae.group]||(Q[Ae.group]=[]),Q[Ae.group].push(Ae)):pe.push(Ae);const De=Object.keys(Q).sort(Zp).map(Ae=>({name:Ae,skills:[...Q[Ae]].sort(Xp)}));return pe.sort(em),{sortedGroups:De,ungrouped:pe}},e[37]=K):K=e[37];const te=K;let Y;e[38]!==_?(Y=te(_),e[38]=_,e[39]=Y):Y=e[39];const ae=Y;let ge;e[40]!==z?(ge=te(z),e[40]=z,e[41]=ge):ge=e[41];const de=ge;let he;e[42]===Symbol.for("react.memo_cache_sentinel")?(he=xe("flex h-full flex-col","bg-background"),e[42]=he):he=e[42];let se;e[43]!==n?(se=n("settings.skills.sidebar.title"),e[43]=n,e[44]=se):se=e[44];let re;e[45]!==se?(re=s.jsx("h2",{className:`${un} mb-3`,children:se}),e[45]=se,e[46]=re):re=e[46];let ue;e[47]===Symbol.for("react.memo_cache_sentinel")?(ue=s.jsx(Ba,{className:"mb-3"}),e[47]=ue):ue=e[47];let Ce;e[48]!==j.length||e[49]!==n?(Ce=n("settings.skills.sidebar.total",{count:j.length}),e[48]=j.length,e[49]=n,e[50]=Ce):Ce=e[50];let Se;e[51]!==Ce?(Se=s.jsx("span",{className:"typography-meta text-muted-foreground",children:Ce}),e[51]=Ce,e[52]=Se):Se=e[52];let ye;e[53]===Symbol.for("react.memo_cache_sentinel")?(ye=s.jsx(O,{name:"add",className:"h-3.5 w-3.5"}),e[53]=ye):ye=e[53];let fe;e[54]!==S?(fe=s.jsx(V,{size:"sm","data-settings-item":"skills.create",variant:"ghost",className:"h-7 w-7 px-0 -my-1 text-muted-foreground",onClick:S,children:ye}),e[54]=S,e[55]=fe):fe=e[55];let _e;e[56]!==Se||e[57]!==fe?(_e=s.jsxs("div",{className:"flex items-center justify-between gap-2",children:[Se,fe]}),e[56]=Se,e[57]=fe,e[58]=_e):_e=e[58];let Ue;e[59]!==re||e[60]!==_e?(Ue=s.jsxs("div",{className:"border-b px-3 pt-4 pb-3",children:[re,ue,_e]}),e[59]=re,e[60]=_e,e[61]=Ue):Ue=e[61];let Ne;e[62]!==ae||e[63]!==de||e[64]!==M||e[65]!==a||e[66]!==d||e[67]!==_||e[68]!==f||e[69]!==C||e[70]!==j.length||e[71]!==n||e[72]!==z?(Ne=s.jsx(vs,{outerClassName:"flex-1 min-h-0",className:"space-y-1 px-3 py-2 overflow-x-hidden",children:j.length===0?s.jsxs("div",{className:"py-12 px-4 text-center text-muted-foreground",children:[s.jsx(O,{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")}),ae.sortedGroups.map(Me=>{const{name:wt,skills:Q}=Me;return s.jsx(dr,{label:wt,count:Q.length,storageKey:"project-skills",children:Q.map(pe=>s.jsx(di,{skill:pe,isSelected:f===pe.name,onSelect:()=>{C(pe.name),a?.()},onRename:()=>J(pe),onDelete:()=>$(pe),onDuplicate:()=>M(pe),isMenuOpen:d===pe.name,onMenuOpenChange:De=>P(De?pe.name:null)},pe.name))},wt)}),ae.ungrouped.map(Me=>s.jsx(di,{skill:Me,isSelected:f===Me.name,onSelect:()=>{C(Me.name),a?.()},onRename:()=>J(Me),onDelete:()=>$(Me),onDuplicate:()=>M(Me),isMenuOpen:d===Me.name,onMenuOpenChange:wt=>P(wt?Me.name:null)},Me.name))]}),z.length>0&&s.jsxs(s.Fragment,{children:[s.jsx("div",{className:"px-2 pb-1.5 pt-3 text-xs font-semibold uppercase tracking-wide text-muted-foreground",children:n("settings.skills.sidebar.section.user")}),de.sortedGroups.map(Me=>{const{name:wt,skills:Q}=Me;return s.jsx(dr,{label:wt,count:Q.length,storageKey:"user-skills",children:Q.map(pe=>s.jsx(di,{skill:pe,isSelected:f===pe.name,onSelect:()=>{C(pe.name),a?.()},onRename:()=>J(pe),onDelete:()=>$(pe),onDuplicate:()=>M(pe),isMenuOpen:d===pe.name,onMenuOpenChange:De=>P(De?pe.name:null)},pe.name))},wt)}),de.ungrouped.map(Me=>s.jsx(di,{skill:Me,isSelected:f===Me.name,onSelect:()=>{C(Me.name),a?.()},onRename:()=>J(Me),onDelete:()=>$(Me),onDuplicate:()=>M(Me),isMenuOpen:d===Me.name,onMenuOpenChange:wt=>P(wt?Me.name:null)},Me.name))]})]})}),e[62]=ae,e[63]=de,e[64]=M,e[65]=a,e[66]=d,e[67]=_,e[68]=f,e[69]=C,e[70]=j.length,e[71]=n,e[72]=z,e[73]=Ne):Ne=e[73];const Oe=c!==null;let Ve;e[74]!==p?(Ve=Me=>{!Me&&!p&&y(null)},e[74]=p,e[75]=Ve):Ve=e[75];let Ge;e[76]!==n?(Ge=n("settings.skills.sidebar.deleteDialog.title"),e[76]=n,e[77]=Ge):Ge=e[77];let ve;e[78]!==Ge?(ve=s.jsx($t,{children:Ge}),e[78]=Ge,e[79]=ve):ve=e[79];const Z=c?.name??"";let ne;e[80]!==n||e[81]!==Z?(ne=n("settings.skills.sidebar.deleteDialog.description",{name:Z}),e[80]=n,e[81]=Z,e[82]=ne):ne=e[82];let be;e[83]!==ne?(be=s.jsx(Vt,{children:ne}),e[83]=ne,e[84]=be):be=e[84];let we;e[85]!==ve||e[86]!==be?(we=s.jsxs(_t,{children:[ve,be]}),e[85]=ve,e[86]=be,e[87]=we):we=e[87];let Re;e[88]===Symbol.for("react.memo_cache_sentinel")?(Re=()=>y(null),e[88]=Re):Re=e[88];let Fe;e[89]!==n?(Fe=n("settings.common.actions.cancel"),e[89]=n,e[90]=Fe):Fe=e[90];let Ke;e[91]!==p||e[92]!==Fe?(Ke=s.jsx(V,{size:"sm",className:"text-foreground hover:bg-interactive-hover hover:text-foreground",variant:"ghost",onClick:Re,disabled:p,children:Fe}),e[91]=p,e[92]=Fe,e[93]=Ke):Ke=e[93];let Ee;e[94]!==n?(Ee=n("settings.common.actions.delete"),e[94]=n,e[95]=Ee):Ee=e[95];let je;e[96]!==k||e[97]!==p||e[98]!==Ee?(je=s.jsx(V,{size:"sm",onClick:k,disabled:p,children:Ee}),e[96]=k,e[97]=p,e[98]=Ee,e[99]=je):je=e[99];let Ze;e[100]!==Ke||e[101]!==je?(Ze=s.jsxs(ts,{children:[Ke,je]}),e[100]=Ke,e[101]=je,e[102]=Ze):Ze=e[102];let me;e[103]!==we||e[104]!==Ze?(me=s.jsxs(zt,{className:"max-w-md",children:[we,Ze]}),e[103]=we,e[104]=Ze,e[105]=me):me=e[105];let Ie;e[106]!==Oe||e[107]!==Ve||e[108]!==me?(Ie=s.jsx(Kt,{open:Oe,onOpenChange:Ve,children:me}),e[106]=Oe,e[107]=Ve,e[108]=me,e[109]=Ie):Ie=e[109];const Le=r!==null;let Xe;e[110]===Symbol.for("react.memo_cache_sentinel")?(Xe=Me=>!Me&&i(null),e[110]=Xe):Xe=e[110];let q;e[111]!==n?(q=n("settings.skills.sidebar.renameDialog.title"),e[111]=n,e[112]=q):q=e[112];let ke;e[113]!==q?(ke=s.jsx($t,{children:q}),e[113]=q,e[114]=ke):ke=e[114];const Pe=r?.name??"";let Je;e[115]!==n||e[116]!==Pe?(Je=n("settings.skills.sidebar.renameDialog.description",{name:Pe}),e[115]=n,e[116]=Pe,e[117]=Je):Je=e[117];let ot;e[118]!==Je?(ot=s.jsx(Vt,{children:Je}),e[118]=Je,e[119]=ot):ot=e[119];let st;e[120]!==ke||e[121]!==ot?(st=s.jsxs(_t,{children:[ke,ot]}),e[120]=ke,e[121]=ot,e[122]=st):st=e[122];let pt;e[123]===Symbol.for("react.memo_cache_sentinel")?(pt=Me=>g(Me.target.value),e[123]=pt):pt=e[123];let vt;e[124]!==n?(vt=n("settings.skills.sidebar.renameDialog.placeholder"),e[124]=n,e[125]=vt):vt=e[125];let W;e[126]!==U?(W=Me=>{Me.key==="Enter"&&U()},e[126]=U,e[127]=W):W=e[127];let We;e[128]!==l||e[129]!==vt||e[130]!==W?(We=s.jsx(He,{value:l,onChange:pt,placeholder:vt,className:"text-foreground placeholder:text-muted-foreground",onKeyDown:W}),e[128]=l,e[129]=vt,e[130]=W,e[131]=We):We=e[131];let nt;e[132]===Symbol.for("react.memo_cache_sentinel")?(nt=()=>i(null),e[132]=nt):nt=e[132];let lt;e[133]!==n?(lt=n("settings.common.actions.cancel"),e[133]=n,e[134]=lt):lt=e[134];let ht;e[135]!==lt?(ht=s.jsx(V,{size:"sm",className:"text-foreground hover:bg-interactive-hover hover:text-foreground",variant:"ghost",onClick:nt,children:lt}),e[135]=lt,e[136]=ht):ht=e[136];let Lt;e[137]!==n?(Lt=n("settings.common.actions.rename"),e[137]=n,e[138]=Lt):Lt=e[138];let et;e[139]!==U||e[140]!==Lt?(et=s.jsx(V,{size:"sm",onClick:U,children:Lt}),e[139]=U,e[140]=Lt,e[141]=et):et=e[141];let ft;e[142]!==ht||e[143]!==et?(ft=s.jsxs(ts,{children:[ht,et]}),e[142]=ht,e[143]=et,e[144]=ft):ft=e[144];let bt;e[145]!==st||e[146]!==We||e[147]!==ft?(bt=s.jsxs(zt,{children:[st,We,ft]}),e[145]=st,e[146]=We,e[147]=ft,e[148]=bt):bt=e[148];let Be;e[149]!==Le||e[150]!==bt?(Be=s.jsx(Kt,{open:Le,onOpenChange:Xe,children:bt}),e[149]=Le,e[150]=bt,e[151]=Be):Be=e[151];let Et;return e[152]!==Ue||e[153]!==Ne||e[154]!==Ie||e[155]!==Be?(Et=s.jsxs("div",{className:he,children:[Ue,Ne,Ie,Be]}),e[152]=Ue,e[153]=Ne,e[154]=Ie,e[155]=Be,e[156]=Et):Et=e[156],Et},di=t=>{const e=ut.c(41),{skill:a,isSelected:n,onSelect:r,onDelete:i,onRename:l,onDuplicate:g,isMenuOpen:c,onMenuOpenChange:y}=t,{t:p}=tt();let b;e[0]===Symbol.for("react.memo_cache_sentinel")?(b=_a(),e[0]=b):b=e[0];const d=b;let P;e[1]!==a?(P=za(a),e[1]=a,e[2]=P):P=e[2];const f=P;let C;e[3]!==a?(C=hr(a),e[3]=a,e[4]=C):C=e[4];const v=C,[N,m]=o.useState(!1);let A;e[5]!==v||e[6]!==i||e[7]!==g||e[8]!==l||e[9]!==p?(A=M=>s.jsxs(s.Fragment,{children:[v?s.jsxs(M,{onClick:L=>{L.stopPropagation(),l()},children:[s.jsx(O,{name:"edit",className:"h-4 w-4 mr-px"}),p("settings.common.actions.rename")]}):null,s.jsxs(M,{onClick:L=>{L.stopPropagation(),g()},children:[s.jsx(O,{name:"file-copy",className:"h-4 w-4 mr-px"}),p("settings.common.actions.duplicate")]}),s.jsxs(M,{onClick:L=>{L.stopPropagation(),i()},className:"text-destructive focus:text-destructive",children:[s.jsx(O,{name:"delete-bin",className:"h-4 w-4 mr-px"}),p("settings.common.actions.delete")]})]}),e[5]=v,e[6]=i,e[7]=g,e[8]=l,e[9]=p,e[10]=A):A=e[10];const R=A,I=!f&&N,j=n?"bg-interactive-selection":"hover:bg-interactive-hover";let h;e[11]!==j?(h=xe("group relative flex items-center rounded-md px-1.5 py-1 transition-all duration-200 select-none",j),e[11]=j,e[12]=h):h=e[12];let w;e[13]!==f?(w=!d&&!f?M=>{M.preventDefault(),m(!0)}:void 0,e[13]=f,e[14]=w):w=e[14];let F;e[15]!==h||e[16]!==w?(F=s.jsx("div",{className:h,onContextMenu:w}),e[15]=h,e[16]=w,e[17]=F):F=e[17];let T;e[18]!==a.name?(T=s.jsx("div",{className:"flex items-center gap-1.5",children:s.jsx("span",{className:"typography-ui-label font-normal truncate text-foreground",children:a.name})}),e[18]=a.name,e[19]=T):T=e[19];let S;e[20]!==r||e[21]!==T?(S=s.jsx("button",{onClick:r,className:"flex min-w-0 flex-1 flex-col gap-0 rounded-sm text-left focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-primary/50",tabIndex:0,children:T}),e[20]=r,e[21]=T,e[22]=S):S=e[22];let D;e[23]!==f||e[24]!==c||e[25]!==y||e[26]!==R?(D=f?null:s.jsxs(cn,{open:c,onOpenChange:M=>{M&&m(!1),y(M)},children:[s.jsx(on,{asChild:!0,children:s.jsx(V,{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(O,{name:"more-2",className:"h-3.5 w-3.5"})})}),s.jsx(ln,{align:"end",className:"w-fit min-w-20",children:R(dn)})]}),e[23]=f,e[24]=c,e[25]=y,e[26]=R,e[27]=D):D=e[27];let $;e[28]!==S||e[29]!==D?($=s.jsxs("div",{className:"flex min-w-0 flex-1 items-center",children:[S,D]}),e[28]=S,e[29]=D,e[30]=$):$=e[30];let B;e[31]!==$||e[32]!==F?(B=s.jsx(Jn,{render:F,children:$}),e[31]=$,e[32]=F,e[33]=B):B=e[33];let k;e[34]!==f||e[35]!==R?(k=f?null:s.jsx(Wn,{className:"w-fit min-w-20",children:R(qn)}),e[34]=f,e[35]=R,e[36]=k):k=e[36];let G;return e[37]!==B||e[38]!==k||e[39]!==I?(G=s.jsxs(Qn,{open:I,onOpenChange:m,children:[B,k]}),e[37]=B,e[38]=k,e[39]=I,e[40]=G):G=e[40],G};function qp(t){return{selectedSkillName:t.selectedSkillName,setSelectedSkill:t.setSelectedSkill,setSkillDraft:t.setSkillDraft,deleteSkill:t.deleteSkill,renameSkill:t.renameSkill,getSkillDetail:t.getSkillDetail}}function Jp(t){return t.loadSkills}function Qp(t){return t.scope==="project"}function Yp(t){return t.scope==="user"}function Zp(t,e){return t.localeCompare(e)}function Xp(t,e){return t.name.localeCompare(e.name)}function em(t,e){return t.name.localeCompare(e.name)}const tm=()=>`custom:${Date.now()}-${Math.random().toString(16).slice(2)}`,sm=t=>{const e=t.trim(),a=e.startsWith("https://")?"https":e.startsWith("git@")?"ssh":"shorthand";if(a==="ssh")return`${e.split(":")[1].replace(/\.git$/i,"")}`;if(a==="https")return e.split("/").slice(3).filter(Boolean).join("/").replace(/\.git$/i,"");const n=e.match(/^([^/\s]+)\/([^/\s]+)(?:\/.+)?$/);return n?`${n[1]}/${n[2].replace(/\.git$/i,"")}`:e},nm=({open:t,onOpenChange:e})=>{const{t:a}=tt(),n=hn(k=>k.scanRepo),r=hn(k=>k.loadCatalog),i=hn(k=>k.loadSource),l=hn(k=>k.setSelectedSource),g=hn(k=>k.isScanning),c=_n(k=>k.defaultGitIdentityId),y=_n(k=>k.loadDefaultGitIdentityId),[p,b]=o.useState(""),[d,P]=o.useState(""),[f,C]=o.useState(""),[v,N]=o.useState(null),[m,A]=o.useState(null),[R,I]=o.useState(!1),[j,h]=o.useState([]),[w,F]=o.useState(null),T=o.useRef(0),S=o.useCallback(k=>{T.current+=1,I(!1),A(null),k?.clearIdentity&&(h([]),F(null))},[]);o.useEffect(()=>{t&&(T.current+=1,b(""),P(""),C(""),A(null),I(!1),h([]),F(null),y(),N(null),(async()=>{const k=await pn();N(k?k.skillCatalogs??[]:null)})())},[t,y]);const D=o.useMemo(()=>{const k=d.trim(),G=f.trim();return(v??[]).some(M=>{const L=(M.source||"").trim(),J=(M.subpath||"").trim();return L===k&&J===G})},[v,d,f]),$=async()=>{const k=d.trim();if(!k){E.error(a("settings.skills.catalog.add.toast.repositoryRequired"));return}p.trim()||b(sm(k)),I(!1),A(null);const G=T.current+1;T.current=G;const M=await n({source:k,subpath:f.trim()||void 0,gitIdentityId:w||void 0});if(T.current!==G)return;if(!M.ok){if(M.error?.kind==="authRequired"){if(cs()){E.error(a("settings.skills.catalog.shared.toast.privateRepoNotSupportedVsCode"));return}const J=M.error.identities||[];if(h(J),!w&&J.length>0){const ee=c&&c!=="global"&&J.some(U=>U.id===c)?c:J[0].id;F(ee)}E.error(a("settings.skills.catalog.add.toast.authenticationRequiredScan"));return}E.error(M.error?.message||a("settings.skills.catalog.add.toast.scanFailed"));return}const L=M.items?.length||0;if(A(L),L===0){E.error(a("settings.skills.catalog.add.toast.noSkillsFound")),I(!1);return}h([]),I(!0),E.success(a("settings.skills.catalog.shared.toast.foundSkills",{count:L}))},B=async()=>{const k=p.trim(),G=d.trim(),M=f.trim();if(!k){E.error(a("settings.skills.catalog.add.toast.catalogNameRequired"));return}if(!G){E.error(a("settings.skills.catalog.add.toast.repositoryRequired"));return}if(!R){E.error(a("settings.skills.catalog.add.toast.scanBeforeAdd"));return}if(D){E.error(a("settings.skills.catalog.add.toast.catalogAlreadyExists"));return}const L={id:tm(),label:k,source:G,...M?{subpath:M}:{},...w?{gitIdentityId:w}:{}};if(v===null){E.error(a("settings.skills.catalog.add.toast.saveFailed"));return}const J=[...v,L];try{if(!(await gt({skillCatalogs:J})).ok)throw new Error(a("settings.skills.catalog.add.toast.saveFailed"));N(J),E.success(a("settings.skills.catalog.add.toast.catalogAdded")),await r({refresh:!0}),await i(L.id,{refresh:!0}),l(L.id),e(!1)}catch(ee){E.error(ee instanceof Error?ee.message:a("settings.skills.catalog.add.toast.saveFailed"))}};return s.jsx(Kt,{open:t,onOpenChange:e,children:s.jsxs(zt,{className:"max-w-xl",children:[s.jsxs(_t,{children:[s.jsx($t,{children:a("settings.skills.catalog.add.title")}),s.jsxs(Vt,{children:[a("settings.skills.catalog.add.descriptionPrefix")," ",s.jsx("code",{className:"font-mono",children:"SKILL.md"}),a("settings.skills.catalog.add.descriptionSuffix")]})]}),s.jsxs("div",{className:"space-y-4",children:[s.jsxs("div",{className:"space-y-2",children:[s.jsx("label",{className:"typography-ui-label text-foreground",children:a("settings.skills.catalog.add.field.catalogName")}),s.jsx(He,{value:p,onChange:k=>b(k.target.value),placeholder:a("settings.skills.catalog.add.field.catalogNamePlaceholder")})]}),s.jsxs("div",{className:"space-y-2",children:[s.jsxs("div",{className:"flex items-center gap-1",children:[s.jsx("label",{className:"typography-ui-label text-foreground",children:a("settings.skills.catalog.add.field.repository")}),s.jsx(Jt,{children:a("settings.skills.catalog.add.field.repositoryHint")})]}),s.jsx(He,{value:d,onChange:k=>{P(k.target.value),S({clearIdentity:!0})},placeholder:a("settings.skills.catalog.shared.field.repositoryPlaceholder")})]}),s.jsxs("div",{className:"space-y-2",children:[s.jsx("label",{className:"typography-ui-label text-foreground",children:a("settings.skills.catalog.add.field.optionalSubpath")}),s.jsx(He,{value:f,onChange:k=>{C(k.target.value),S({clearIdentity:!0})},placeholder:a("settings.skills.catalog.shared.field.subpathPlaceholder")})]}),j.length>0&&!cs()?s.jsxs("div",{className:"space-y-2",children:[s.jsxs("div",{className:"flex items-center",children:[s.jsx("span",{className:"typography-ui-label text-[var(--status-warning)]",children:a("settings.skills.catalog.shared.auth.title")}),s.jsx("span",{className:"typography-meta text-muted-foreground ml-2",children:a("settings.skills.catalog.shared.auth.description")}),s.jsx(Jt,{className:"ml-1",children:a("settings.skills.catalog.shared.auth.footerHint")})]}),s.jsxs(St,{value:w||"",onValueChange:k=>{F(k),S()},children:[s.jsx(Ct,{className:"w-fit",children:s.jsx("span",{children:j.find(k=>k.id===w)?.name||a("settings.skills.catalog.shared.auth.chooseIdentity")})}),s.jsx(It,{align:"start",children:j.map(k=>s.jsx(at,{value:k.id,children:k.name},k.id))})]})]}):null,m!==null?s.jsx("div",{className:"typography-meta text-muted-foreground",children:a("settings.skills.catalog.add.scanResult",{count:m})}):null,D?s.jsx("div",{className:"typography-meta text-muted-foreground",children:a("settings.skills.catalog.add.duplicateMessage")}):null]}),s.jsxs(ts,{children:[s.jsx(V,{size:"sm",variant:"ghost",onClick:()=>e(!1),children:a("settings.common.actions.cancel")}),s.jsxs(V,{size:"sm",className:"gap-2",variant:"ghost",onClick:()=>{$()},disabled:g||!d.trim(),children:[s.jsx(O,{name:"git-repository",className:"h-4 w-4"}),a(g?"settings.skills.catalog.shared.actions.scanning":"settings.skills.catalog.shared.actions.scan")]}),s.jsx(V,{size:"sm",onClick:()=>{B()},disabled:!R||D||v===null||!p.trim()||!d.trim(),children:a("settings.skills.catalog.add.actions.addCatalog")})]})]})})},am=t=>{const e=ut.c(85),{open:a,onOpenChange:n,conflicts:r,onConfirm:i}=t,{t:l}=tt();let g;e[0]===Symbol.for("react.memo_cache_sentinel")?(g={},e[0]=g):g=e[0];const[c,y]=o.useState(g);let p,b;e[1]!==r||e[2]!==a?(p=()=>{if(!a)return;const Y={};for(const ae of r)Y[ae.skillName]="skip";y(Y)},b=[a,r],e[1]=r,e[2]=a,e[3]=p,e[4]=b):(p=e[3],b=e[4]),o.useEffect(p,b);let d;e[5]!==r?(d=Y=>{const ae={};for(const ge of r)ae[ge.skillName]=Y;y(ae)},e[5]=r,e[6]=d):d=e[6];const P=d;let f;e[7]!==r||e[8]!==c?(f=r.length>0&&r.every(Y=>c[Y.skillName]),e[7]=r,e[8]=c,e[9]=f):f=e[9];const C=f;let v;e[10]!==l?(v=l("settings.skills.catalog.conflicts.title"),e[10]=l,e[11]=v):v=e[11];let N;e[12]!==v?(N=s.jsx($t,{children:v}),e[12]=v,e[13]=N):N=e[13];let m;e[14]!==l?(m=l("settings.skills.catalog.conflicts.description"),e[14]=l,e[15]=m):m=e[15];let A;e[16]!==m?(A=s.jsx(Vt,{children:m}),e[16]=m,e[17]=A):A=e[17];let R;e[18]!==N||e[19]!==A?(R=s.jsxs(_t,{children:[N,A]}),e[18]=N,e[19]=A,e[20]=R):R=e[20];let I;e[21]!==r.length||e[22]!==l?(I=l("settings.skills.catalog.conflicts.count",{count:r.length}),e[21]=r.length,e[22]=l,e[23]=I):I=e[23];let j;e[24]!==I?(j=s.jsx("span",{className:"typography-meta text-muted-foreground",children:I}),e[24]=I,e[25]=j):j=e[25];let h;e[26]!==P?(h=()=>P("skip"),e[26]=P,e[27]=h):h=e[27];let w;e[28]!==l?(w=l("settings.skills.catalog.conflicts.actions.skipAll"),e[28]=l,e[29]=w):w=e[29];let F;e[30]!==h||e[31]!==w?(F=s.jsx(V,{variant:"outline",size:"xs",className:"!font-normal",onClick:h,children:w}),e[30]=h,e[31]=w,e[32]=F):F=e[32];let T;e[33]!==P?(T=()=>P("overwrite"),e[33]=P,e[34]=T):T=e[34];let S;e[35]!==l?(S=l("settings.skills.catalog.conflicts.actions.overwriteAll"),e[35]=l,e[36]=S):S=e[36];let D;e[37]!==T||e[38]!==S?(D=s.jsx(V,{variant:"outline",size:"xs",className:"!font-normal",onClick:T,children:S}),e[37]=T,e[38]=S,e[39]=D):D=e[39];let $;e[40]!==F||e[41]!==D?($=s.jsxs("div",{className:"flex items-center gap-2",children:[F,D]}),e[40]=F,e[41]=D,e[42]=$):$=e[42];let B;e[43]!==j||e[44]!==$?(B=s.jsxs("div",{className:"flex items-center justify-between gap-2",children:[j,$]}),e[43]=j,e[44]=$,e[45]=B):B=e[45];let k;if(e[46]!==r||e[47]!==c||e[48]!==l){let Y;e[50]!==c||e[51]!==l?(Y=ae=>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:ae.skillName}),s.jsx("div",{className:"typography-micro text-muted-foreground",children:l("settings.skills.catalog.conflicts.installedIn",{scope:ae.scope==="project"?l("settings.skills.catalog.conflicts.scope.project"):l("settings.skills.catalog.conflicts.scope.user"),source:ae.source==="agents"?l("settings.skills.catalog.conflicts.source.agents"):l("settings.skills.catalog.conflicts.source.opencode")})})]}),s.jsxs(St,{value:c[ae.skillName]||"skip",onValueChange:ge=>y(de=>({...de,[ae.skillName]:ge})),children:[s.jsx(Ct,{className:"w-fit",children:s.jsx("span",{className:"capitalize",children:(c[ae.skillName]||"skip")==="overwrite"?l("settings.skills.catalog.conflicts.decision.overwrite"):l("settings.skills.catalog.conflicts.decision.skip")})}),s.jsxs(It,{align:"end",children:[s.jsx(at,{value:"skip",className:"pr-2 [&>span:first-child]:hidden",children:l("settings.skills.catalog.conflicts.decision.skip")}),s.jsx(at,{value:"overwrite",className:"pr-2 [&>span:first-child]:hidden",children:l("settings.skills.catalog.conflicts.decision.overwrite")})]})]})]},ae.skillName),e[50]=c,e[51]=l,e[52]=Y):Y=e[52],k=r.map(Y),e[46]=r,e[47]=c,e[48]=l,e[49]=k}else k=e[49];let G;e[53]!==k?(G=s.jsx("div",{className:"space-y-2",children:k}),e[53]=k,e[54]=G):G=e[54];let M;e[55]!==B||e[56]!==G?(M=s.jsxs("div",{className:"space-y-3",children:[B,G]}),e[55]=B,e[56]=G,e[57]=M):M=e[57];let L;e[58]!==n?(L=()=>n(!1),e[58]=n,e[59]=L):L=e[59];let J;e[60]!==l?(J=l("settings.common.actions.cancel"),e[60]=l,e[61]=J):J=e[61];let ee;e[62]!==L||e[63]!==J?(ee=s.jsx(V,{size:"sm",variant:"ghost",onClick:L,children:J}),e[62]=L,e[63]=J,e[64]=ee):ee=e[64];let U;e[65]!==c||e[66]!==i?(U=()=>i(c),e[65]=c,e[66]=i,e[67]=U):U=e[67];const le=!C;let _;e[68]!==l?(_=l("settings.skills.catalog.conflicts.actions.continue"),e[68]=l,e[69]=_):_=e[69];let H;e[70]!==U||e[71]!==le||e[72]!==_?(H=s.jsx(V,{size:"sm",onClick:U,disabled:le,children:_}),e[70]=U,e[71]=le,e[72]=_,e[73]=H):H=e[73];let z;e[74]!==ee||e[75]!==H?(z=s.jsxs(ts,{children:[ee,H]}),e[74]=ee,e[75]=H,e[76]=z):z=e[76];let K;e[77]!==R||e[78]!==M||e[79]!==z?(K=s.jsxs(zt,{className:"max-w-2xl",children:[R,M,z]}),e[77]=R,e[78]=M,e[79]=z,e[80]=K):K=e[80];let te;return e[81]!==n||e[82]!==a||e[83]!==K?(te=s.jsx(Kt,{open:a,onOpenChange:n,children:K}),e[81]=n,e[82]=a,e[83]=K,e[84]=te):te=e[84],te},Pr=[{value:"user-opencode",scope:"user",source:"opencode",label:"User / OpenCode",description:"Global OpenCode config location"},{value:"project-opencode",scope:"project",source:"opencode",label:"Project / OpenCode",description:"Current project .opencode location"},{value:"user-agents",scope:"user",source:"agents",label:"User / Agents",description:"Global .agents compatibility location"},{value:"project-agents",scope:"project",source:"agents",label:"Project / Agents",description:"Current project .agents compatibility location"}];function Ua(t,e){return t==="project"&&e==="claude"?"project-claude":t==="project"&&e==="agents"?"project-agents":e==="claude"?"user-claude":t==="project"?"project-opencode":e==="agents"?"user-agents":"user-opencode"}function Wl(t){if(t==="user-claude")return{scope:"user",source:"claude"};if(t==="project-claude")return{scope:"project",source:"claude"};const e=Pr.find(a=>a.value===t);return e?{scope:e.scope,source:e.source}:{scope:"user",source:"opencode"}}const im=t=>{const e=ut.c(124),{open:a,onOpenChange:n,item:r}=t,{t:i}=tt(),l=hn(rm),g=hn(om),[c,y]=o.useState("user"),[p,b]=o.useState("opencode"),d=Gs(lm),P=Gs(cm),[f,C]=o.useState(null),[v,N]=o.useState(!1);let m;e[0]===Symbol.for("react.memo_cache_sentinel")?(m=[],e[0]=m):m=e[0];const[A,R]=o.useState(m),[I,j]=o.useState(null);let h,w;e[1]!==P||e[2]!==a?(h=()=>{a&&(y("user"),b("opencode"),C(P),N(!1),R([]),j(null))},w=[a,P],e[1]=P,e[2]=a,e[3]=h,e[4]=w):(h=e[3],w=e[4]),o.useEffect(h,w);let F;e[5]!==i?(F=je=>{switch(je){case"project-opencode":return i("settings.skills.location.option.projectOpencode.label");case"user-agents":return i("settings.skills.location.option.userAgents.label");case"project-agents":return i("settings.skills.location.option.projectAgents.label");default:return i("settings.skills.location.option.userOpencode.label")}},e[5]=i,e[6]=F):F=e[6];const T=F;let S;e[7]!==i?(S=je=>{switch(je){case"project-opencode":return i("settings.skills.location.option.projectOpencode.description");case"user-agents":return i("settings.skills.location.option.userAgents.description");case"project-agents":return i("settings.skills.location.option.projectAgents.description");default:return i("settings.skills.location.option.userOpencode.description")}},e[7]=i,e[8]=S):S=e[8];const D=S;let $;e:{if(d.length===0){$=null;break e}if(f&&d.some(je=>je.id===f)){$=f;break e}if(P&&d.some(je=>je.id===P)){$=P;break e}$=d[0]?.id??null}const B=$;let k;e:{if(c!=="project"){k=null;break e}const je=B;if(!je){k=null;break e}let Ze;if(e[9]!==je||e[10]!==d){let Ie;e[12]!==je?(Ie=Le=>Le.id===je,e[12]=je,e[13]=Ie):Ie=e[13],Ze=d.find(Ie),e[9]=je,e[10]=d,e[11]=Ze}else Ze=e[11];k=Ze?.path??null}const G=k;let M;e[14]!==l||e[15]!==r?.gitIdentityId||e[16]!==n||e[17]!==i?(M=async je=>{const Ze=await l({source:je.source,subpath:je.subpath,gitIdentityId:r?.gitIdentityId,scope:je.scope,targetSource:je.targetSource,selections:[{skillDir:je.skillDir}],conflictPolicy:"prompt",conflictDecisions:je.conflictDecisions},{directory:je.directoryOverride??null});if(Ze.ok){E.success(i("settings.skills.catalog.installSkill.toast.installed")),n(!1);return}if(Ze.error?.kind==="conflicts"){j({source:je.source,subpath:je.subpath,scope:je.scope,targetSource:je.targetSource,skillDir:je.skillDir,directoryOverride:je.directoryOverride??null}),R(Ze.error.conflicts),N(!0);return}if(Ze.error?.kind==="authRequired"){E.error(Ze.error.message||i("settings.skills.catalog.installSkill.toast.authRequired"));return}E.error(Ze.error?.message||i("settings.skills.catalog.installSkill.toast.installFailed"))},e[14]=l,e[15]=r?.gitIdentityId,e[16]=n,e[17]=i,e[18]=M):M=e[18];const L=M;if(!r)return null;let J;e[19]!==i?(J=i("settings.skills.catalog.installSkill.title"),e[19]=i,e[20]=J):J=e[20];let ee;e[21]!==J?(ee=s.jsx($t,{children:J}),e[21]=J,e[22]=ee):ee=e[22];let U;e[23]!==i?(U=i("settings.skills.catalog.installSkill.descriptionPrefix"),e[23]=i,e[24]=U):U=e[24];let le;e[25]!==r.skillName?(le=s.jsx("span",{className:"font-semibold text-foreground",children:r.skillName}),e[25]=r.skillName,e[26]=le):le=e[26];let _;e[27]!==i?(_=i("settings.skills.catalog.installSkill.descriptionSuffix"),e[27]=i,e[28]=_):_=e[28];let H;e[29]!==U||e[30]!==le||e[31]!==_?(H=s.jsxs(Vt,{children:[U," ",le," ",_]}),e[29]=U,e[30]=le,e[31]=_,e[32]=H):H=e[32];let z;e[33]!==ee||e[34]!==H?(z=s.jsxs(_t,{children:[ee,H]}),e[33]=ee,e[34]=H,e[35]=z):z=e[35];let K;e[36]!==i?(K=i("settings.skills.catalog.installSkill.field.destination"),e[36]=i,e[37]=K):K=e[37];let te;e[38]!==K?(te=s.jsx("span",{className:"typography-ui-label text-foreground",children:K}),e[38]=K,e[39]=te):te=e[39];let Y;e[40]!==c||e[41]!==p?(Y=Ua(c,p),e[40]=c,e[41]=p,e[42]=Y):Y=e[42];let ae;e[43]===Symbol.for("react.memo_cache_sentinel")?(ae=je=>{const Ze=Wl(je);y(Ze.scope),b(Ze.source==="agents"?"agents":"opencode")},e[43]=ae):ae=e[43];let ge;e[44]!==c?(ge=c==="user"?s.jsx(O,{name:"user-3",className:"h-3.5 w-3.5"}):s.jsx(O,{name:"folder",className:"h-3.5 w-3.5"}),e[44]=c,e[45]=ge):ge=e[45];let de;e[46]!==p?(de=p==="agents"?s.jsx(O,{name:"robot-2",className:"h-3.5 w-3.5"}):null,e[46]=p,e[47]=de):de=e[47];let he;e[48]!==T||e[49]!==c||e[50]!==p?(he=T(Ua(c,p)),e[48]=T,e[49]=c,e[50]=p,e[51]=he):he=e[51];let se;e[52]!==he?(se=s.jsx("span",{children:he}),e[52]=he,e[53]=se):se=e[53];let re;e[54]!==ge||e[55]!==de||e[56]!==se?(re=s.jsxs(Ct,{className:"w-fit gap-1.5",children:[ge,de,se]}),e[54]=ge,e[55]=de,e[56]=se,e[57]=re):re=e[57];let ue;e[58]!==D||e[59]!==T?(ue=Pr.map(je=>s.jsx(at,{value:je.value,className:"pr-2 [&>span:first-child]:hidden",children:s.jsxs("div",{className:"flex flex-col gap-0.5",children:[s.jsxs("div",{className:"flex items-center gap-2",children:[je.scope==="user"?s.jsx(O,{name:"user-3",className:"h-3.5 w-3.5"}):s.jsx(O,{name:"folder",className:"h-3.5 w-3.5"}),je.source==="agents"?s.jsx(O,{name:"robot-2",className:"h-3.5 w-3.5"}):null,s.jsx("span",{children:T(je.value)})]}),s.jsx("span",{className:"typography-micro text-muted-foreground ml-5",children:D(je.value)})]})},je.value)),e[58]=D,e[59]=T,e[60]=ue):ue=e[60];let Ce;e[61]!==ue?(Ce=s.jsx(It,{align:"start",children:ue}),e[61]=ue,e[62]=Ce):Ce=e[62];let Se;e[63]!==Y||e[64]!==re||e[65]!==Ce?(Se=s.jsxs(St,{value:Y,onValueChange:ae,children:[re,Ce]}),e[63]=Y,e[64]=re,e[65]=Ce,e[66]=Se):Se=e[66];let ye;e[67]!==te||e[68]!==Se?(ye=s.jsxs("div",{className:"flex flex-wrap items-center gap-2",children:[te,Se]}),e[67]=te,e[68]=Se,e[69]=ye):ye=e[69];let fe;e[70]!==d||e[71]!==B||e[72]!==c||e[73]!==i?(fe=c==="project"&&s.jsxs("div",{className:"flex flex-wrap items-center gap-2",children:[s.jsx("span",{className:"typography-ui-label text-foreground",children:i("settings.skills.catalog.installSkill.field.project")}),d.length===0?s.jsx("span",{className:"typography-meta text-muted-foreground",children:i("settings.skills.catalog.installSkill.field.noProjects")}):s.jsxs(St,{value:B??"",onValueChange:je=>C(je),disabled:d.length===1,children:[s.jsx(Ct,{className:"w-fit",children:s.jsx(Mt,{placeholder:i("settings.skills.catalog.installSkill.field.chooseProjectPlaceholder")})}),s.jsx(It,{align:"start",children:d.map(dm)})]})]}),e[70]=d,e[71]=B,e[72]=c,e[73]=i,e[74]=fe):fe=e[74];let _e;e[75]!==r.warnings?(_e=r.warnings?.length?s.jsx("div",{className:"typography-micro text-[var(--status-warning)] bg-[var(--status-warning)]/10 px-2 py-1.5 rounded",children:r.warnings.join(" · ")}):null,e[75]=r.warnings,e[76]=_e):_e=e[76];let Ue;e[77]!==ye||e[78]!==fe||e[79]!==_e?(Ue=s.jsxs("div",{className:"mt-2 space-y-3",children:[ye,fe,_e]}),e[77]=ye,e[78]=fe,e[79]=_e,e[80]=Ue):Ue=e[80];let Ne;e[81]!==n?(Ne=()=>n(!1),e[81]=n,e[82]=Ne):Ne=e[82];let Oe;e[83]!==i?(Oe=i("settings.common.actions.cancel"),e[83]=i,e[84]=Oe):Oe=e[84];let Ve;e[85]!==Ne||e[86]!==Oe?(Ve=s.jsx(V,{size:"sm",variant:"ghost",onClick:Ne,children:Oe}),e[85]=Ne,e[86]=Oe,e[87]=Ve):Ve=e[87];const Ge=g||!r.installable||c==="project"&&!G;let ve;e[88]!==G||e[89]!==L||e[90]!==r.repoSource||e[91]!==r.repoSubpath||e[92]!==r.skillDir||e[93]!==c||e[94]!==p?(ve=()=>{L({source:r.repoSource,subpath:r.repoSubpath,scope:c,targetSource:p,skillDir:r.skillDir,directoryOverride:G})},e[88]=G,e[89]=L,e[90]=r.repoSource,e[91]=r.repoSubpath,e[92]=r.skillDir,e[93]=c,e[94]=p,e[95]=ve):ve=e[95];let Z;e[96]!==g||e[97]!==i?(Z=i(g?"settings.skills.catalog.installSkill.actions.installing":"settings.skills.catalog.installSkill.actions.install"),e[96]=g,e[97]=i,e[98]=Z):Z=e[98];let ne;e[99]!==Ge||e[100]!==ve||e[101]!==Z?(ne=s.jsx(V,{size:"sm",disabled:Ge,onClick:ve,children:Z}),e[99]=Ge,e[100]=ve,e[101]=Z,e[102]=ne):ne=e[102];let be;e[103]!==Ve||e[104]!==ne?(be=s.jsxs(ts,{children:[Ve,ne]}),e[103]=Ve,e[104]=ne,e[105]=be):be=e[105];let we;e[106]!==z||e[107]!==Ue||e[108]!==be?(we=s.jsxs(zt,{className:"max-w-md",children:[z,Ue,be]}),e[106]=z,e[107]=Ue,e[108]=be,e[109]=we):we=e[109];let Re;e[110]!==n||e[111]!==a||e[112]!==we?(Re=s.jsx(Kt,{open:a,onOpenChange:n,children:we}),e[110]=n,e[111]=a,e[112]=we,e[113]=Re):Re=e[113];let Fe;e[114]!==I||e[115]!==L?(Fe=je=>{I&&(L({source:I.source,subpath:I.subpath,scope:I.scope,targetSource:I.targetSource,skillDir:I.skillDir,conflictDecisions:je,directoryOverride:I.directoryOverride??null}),N(!1))},e[114]=I,e[115]=L,e[116]=Fe):Fe=e[116];let Ke;e[117]!==A||e[118]!==v||e[119]!==Fe?(Ke=s.jsx(am,{open:v,onOpenChange:N,conflicts:A,onConfirm:Fe}),e[117]=A,e[118]=v,e[119]=Fe,e[120]=Ke):Ke=e[120];let Ee;return e[121]!==Re||e[122]!==Ke?(Ee=s.jsxs(s.Fragment,{children:[Re,Ke]}),e[121]=Re,e[122]=Ke,e[123]=Ee):Ee=e[123],Ee};function rm(t){return t.installSkills}function om(t){return t.isInstalling}function lm(t){return t.projects}function cm(t){return t.activeProjectId}function dm(t){return s.jsx(at,{value:t.id,children:t.label||t.path},t.id)}const um=/^[A-Za-z0-9_.-]+\/[A-Za-z0-9_.-]+$/,pm=t=>{const e=t.trim();return um.test(e)?`https://github.com/${e}`:null},mm=t=>{const e=pm(t.repoSource);if(!e)return null;const a=[t.repoSubpath,t.skillDir].filter(Boolean).join("/");return a?`${e}/tree/HEAD/${a}`:e};let ui=null;const gm=t=>{const e=Sr();return(!ui||ui.locale!==e)&&(ui={locale:e,formatter:new Intl.NumberFormat(e,{notation:"compact"})}),ui.formatter.format(t)},hm=t=>{const e=Date.parse(t);if(Number.isNaN(e))return null;const a=Date.now()-e;if(a<6e4)return{key:"common.relative.justNow",count:0};const n=Math.floor(a/6e4);if(n<60)return{key:"common.relative.minutesAgoShort",count:n};const r=Math.floor(n/60);if(r<24)return{key:"common.relative.hoursAgoShort",count:r};const i=Math.floor(r/24);if(i<7)return{key:"common.relative.daysAgoShort",count:i};const l=Math.floor(i/7);return l<52?{key:"common.relative.weeksAgoShort",count:l}:{key:"common.relative.yearsAgoShort",count:Math.floor(i/365)}},fm=t=>{const e=ut.c(50),{source:a,isActive:n,isLoading:r,skillsCount:i,onSelect:l,t:g}=t,c=a.stars??null;let y,p,b,d,P,f,C,v,N,m;if(e[0]!==n||e[1]!==r||e[2]!==l||e[3]!==i||e[4]!==a.label||e[5]!==a.repoUpdatedAt||e[6]!==a.source||e[7]!==c||e[8]!==g){const j=a.repoUpdatedAt?hm(a.repoUpdatedAt):null;v="button",N=l,m=n;const h=n?"border-primary":"border-[var(--surface-subtle)] hover:border-[var(--interactive-border-hover)]";e[19]!==h?(p=xe("w-full min-h-24 text-left rounded-lg border bg-[var(--surface-elevated)] p-3.5 flex gap-3 items-start transition-colors","focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-ring",h),e[19]=h,e[20]=p):p=e[20],P="min-w-0 flex-1 block";let w;e[21]!==a.label?(w=s.jsx("span",{className:"typography-ui-label font-medium text-foreground truncate",children:a.label}),e[21]=a.label,e[22]=w):w=e[22];let F;e[23]!==r||e[24]!==i||e[25]!==g?(F=r?s.jsx(O,{name:"refresh",className:"h-3 w-3 animate-spin text-muted-foreground shrink-0"}):i!==null&&s.jsx("span",{className:"typography-micro text-muted-foreground shrink-0",children:g("settings.skills.catalog.page.source.skillsCount",{count:i})}),e[23]=r,e[24]=i,e[25]=g,e[26]=F):F=e[26],e[27]!==w||e[28]!==F?(f=s.jsxs("span",{className:"flex items-center gap-2",children:[w,F]}),e[27]=w,e[28]=F,e[29]=f):f=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],y="flex items-center gap-3 mt-1",e[32]!==c||e[33]!==g?(b=c!==null&&s.jsxs("span",{className:"typography-micro text-muted-foreground flex items-center gap-1",title:g("settings.skills.catalog.page.source.stars",{count:c}),children:[s.jsx(O,{name:"star",className:"h-3 w-3"}),gm(c)]}),e[32]=c,e[33]=g,e[34]=b):b=e[34],d=j&&s.jsx("span",{className:"typography-micro text-muted-foreground",children:j.key==="common.relative.justNow"?g(j.key):g("settings.skills.catalog.page.source.updated",{time:g(j.key,{count:j.count})})}),e[0]=n,e[1]=r,e[2]=l,e[3]=i,e[4]=a.label,e[5]=a.repoUpdatedAt,e[6]=a.source,e[7]=c,e[8]=g,e[9]=y,e[10]=p,e[11]=b,e[12]=d,e[13]=P,e[14]=f,e[15]=C,e[16]=v,e[17]=N,e[18]=m}else y=e[9],p=e[10],b=e[11],d=e[12],P=e[13],f=e[14],C=e[15],v=e[16],N=e[17],m=e[18];let A;e[35]!==y||e[36]!==b||e[37]!==d?(A=s.jsxs("span",{className:y,children:[b,d]}),e[35]=y,e[36]=b,e[37]=d,e[38]=A):A=e[38];let R;e[39]!==A||e[40]!==P||e[41]!==f||e[42]!==C?(R=s.jsxs("span",{className:P,children:[f,C,A]}),e[39]=A,e[40]=P,e[41]=f,e[42]=C,e[43]=R):R=e[43];let I;return e[44]!==p||e[45]!==R||e[46]!==v||e[47]!==N||e[48]!==m?(I=s.jsx("button",{type:v,onClick:N,"aria-pressed":m,className:p,children:R}),e[44]=p,e[45]=R,e[46]=v,e[47]=N,e[48]=m,e[49]=I):I=e[49],I},xm=({mode:t,onModeChange:e,showModeTabs:a=!0})=>{const{t:n}=tt(),{sources:r,itemsBySource:i,selectedSourceId:l,setSelectedSource:g,loadCatalog:c,loadSource:y,isLoadingCatalog:p,isLoadingSource:b,loadedSourceIds:d,lastCatalogError:P}=hn(Us(L=>({sources:L.sources,itemsBySource:L.itemsBySource,selectedSourceId:L.selectedSourceId,setSelectedSource:L.setSelectedSource,loadCatalog:L.loadCatalog,loadSource:L.loadSource,isLoadingCatalog:L.isLoadingCatalog,isLoadingSource:L.isLoadingSource,loadedSourceIds:L.loadedSourceIds,lastCatalogError:L.lastCatalogError}))),[f,C]=o.useState(""),[v,N]=o.useState(!1),[m,A]=o.useState(!1),[R,I]=o.useState(null),[j,h]=o.useState(!1),[w,F]=o.useState(!1),T=o.useRef(null);o.useEffect(()=>{c()},[c]),o.useEffect(()=>{const L=r.filter(U=>!d[U.id]);if(L.length===0)return;let J=!1;return(async()=>{for(const U of L){if(J)return;await y(U.id)}})(),()=>{J=!0}},[r,d,y]),o.useEffect(()=>{!l||d[l]||y(l)},[l,d,y]),o.useEffect(()=>{const L=J=>{(J.metaKey||J.ctrlKey)&&J.key.toLowerCase()==="k"&&(J.preventDefault(),T.current?.focus())};return window.addEventListener("keydown",L),()=>window.removeEventListener("keydown",L)},[]);const S=f.trim().length>0,D=o.useMemo(()=>S?ki(r.flatMap(L=>i[L.id]||[]),f,L=>[L.skillName,L.frontmatterName,L.description]):l?i[l]||[]:[],[r,i,l,f,S]),$=o.useMemo(()=>r.find(L=>L.id===l)||null,[r,l]),B=!!(l&&l.startsWith("custom:")),k=async()=>{if(!(!l||!B)){h(!0);try{const L=await pn();if(!L)return;const ee=(L.skillCatalogs??[]).filter(U=>U.id!==l);await gt({skillCatalogs:ee}),await c({refresh:!0}),F(!1)}finally{h(!1)}}},G=S?n("settings.skills.catalog.page.list.searchTitle"):$?.label??"",M=!S&&l!==null&&!d[l]&&(b||p);return s.jsxs(s.Fragment,{children:[s.jsxs(es,{title:n("settings.skills.catalog.page.title"),showSaveStatus:!1,children:[a&&s.jsx("div",{className:"mb-4",children:s.jsx("div",{className:"h-10",children:s.jsx(Ir,{items:[{id:"manual",label:n("settings.skills.catalog.page.mode.manual")},{id:"external",label:n("settings.skills.catalog.page.mode.external")}],activeId:t,onSelect:L=>e(L),layoutMode:"fit",variant:"animated",animateActivePill:!1,className:"h-full"})})}),s.jsx("p",{className:"typography-meta text-muted-foreground mb-4",children:n("settings.skills.catalog.page.subtitle")}),s.jsx("div",{"data-settings-item":"skills.catalog.search",className:"mb-5",children:s.jsxs("div",{className:"relative max-w-md",children:[s.jsx(O,{name:"search",className:"absolute left-2.5 top-1/2 -translate-y-1/2 h-3.5 w-3.5 text-muted-foreground"}),s.jsx(He,{ref:T,value:f,onChange:L=>C(L.target.value),placeholder:n("settings.skills.catalog.page.searchAllPlaceholder"),className:xe("h-8 pl-8 w-full",f&&"pr-8")}),f&&s.jsx("button",{type:"button",onClick:()=>{C(""),T.current?.focus()},className:"absolute right-2 top-1/2 -translate-y-1/2 flex items-center justify-center h-4 w-4 rounded text-muted-foreground hover:text-foreground transition-colors",title:n("settings.skills.catalog.page.search.clear"),children:s.jsx(O,{name:"close",className:"h-3 w-3"})})]})}),s.jsx(ze,{title:n("settings.skills.catalog.page.section.sources"),divider:!1,settingsItem:"skills.catalog.source",contentClassName:"space-y-0",children:s.jsxs("div",{className:"grid grid-cols-1 sm:grid-cols-2 gap-3 py-1.5",children:[r.map(L=>s.jsx(fm,{source:L,isActive:L.id===l,isLoading:b&&!d[L.id],skillsCount:d[L.id]?(i[L.id]||[]).length:null,onSelect:()=>g(L.id),t:n},L.id)),s.jsxs("button",{type:"button","data-settings-item":"skills.catalog.add-catalog",onClick:()=>N(!0),className:"min-h-24 text-left rounded-lg border border-dashed border-[var(--interactive-border)] hover:border-[var(--interactive-border-hover)] hover:bg-[var(--surface-muted)] p-3.5 flex gap-3 items-start transition-colors",children:[s.jsx("span",{className:"flex items-center justify-center rounded-md bg-transparent text-muted-foreground w-8 h-8 shrink-0",children:s.jsx(O,{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")})]})]})]})}),P&&s.jsx(ze,{children:s.jsxs("div",{className:"rounded-lg border border-[var(--status-error-border)] bg-[var(--status-error-background)] px-4 py-3",children:[s.jsx("div",{className:"typography-ui-label font-medium text-[var(--status-error)]",children:n("settings.skills.catalog.page.error.catalogTitle")}),s.jsx("div",{className:"typography-meta text-[var(--status-error)]/80 mt-1",children:P.message})]})}),s.jsxs(ze,{children:[s.jsxs("div",{className:"flex items-center justify-between gap-2 pb-2",children:[s.jsxs("div",{className:"flex items-center gap-2 min-w-0",children:[s.jsx("span",{className:"typography-micro font-medium uppercase tracking-wide text-muted-foreground truncate",children:G}),s.jsx("span",{className:"typography-micro text-muted-foreground/70 shrink-0",children:n("settings.skills.catalog.page.foundCount",{count:D.length})})]}),s.jsxs("div",{className:"flex items-center gap-1 shrink-0",children:[s.jsx(V,{variant:"ghost",size:"xs",className:"!font-normal h-6 w-6 px-0",onClick:()=>{l&&!S?y(l,{refresh:!0}):c({refresh:!0})},disabled:p||b,title:n("settings.skills.catalog.page.actions.refreshTitle"),children:s.jsx(O,{name:"refresh",className:xe("h-3.5 w-3.5",(p||b)&&"animate-spin")})}),B&&!S&&s.jsx(V,{variant:"ghost",size:"xs",className:"!font-normal h-6 w-6 px-0 text-[var(--status-error)] hover:text-[var(--status-error)]",onClick:()=>F(!0),disabled:j,title:n("settings.skills.catalog.page.actions.removeCatalogTitle"),children:s.jsx(O,{name:"delete-bin",className:"h-3.5 w-3.5"})})]})]}),M||b&&D.length===0?s.jsxs("div",{className:"py-8 text-center text-muted-foreground",children:[s.jsx(O,{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")})]}):D.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:D.map(L=>{const J=L.installed?.isInstalled,ee=L.installed?.scope,U=mm(L);return s.jsx("div",{className:"py-2",children:s.jsxs("div",{className:"flex items-start justify-between gap-4",children:[s.jsxs("div",{className:"min-w-0 flex-1",children:[s.jsxs("div",{className:"flex items-center gap-2",children:[s.jsx("span",{className:"typography-ui-label font-medium text-foreground truncate",children:L.skillName}),J&&s.jsx("span",{className:"typography-micro text-[var(--status-success)] bg-[var(--status-success)]/10 px-1.5 py-0.5 rounded flex-shrink-0",children:n("settings.skills.catalog.page.badge.installed",{scope:ee||n("settings.skills.catalog.page.badge.unknown")})}),!L.installable&&s.jsx("span",{className:"typography-micro text-[var(--status-warning)] bg-[var(--status-warning)]/10 px-1.5 py-0.5 rounded flex-shrink-0",children:n("settings.skills.catalog.page.badge.notInstallable")})]}),L.description?s.jsx("div",{className:"typography-meta text-muted-foreground mt-0.5 line-clamp-2",children:L.description}):s.jsx("div",{className:"typography-meta text-muted-foreground/50 mt-0.5 italic",children:n("settings.skills.catalog.shared.noDescription")}),s.jsxs("div",{className:"typography-micro text-muted-foreground/80 mt-1 flex items-center gap-2 min-w-0",children:[U?s.jsxs("a",{href:U,target:"_blank",rel:"noreferrer",className:"font-mono hover:underline truncate inline-flex items-center gap-1",title:n("settings.skills.catalog.page.skill.viewOnGithub"),children:[s.jsx(O,{name:"github",className:"h-3 w-3 shrink-0"}),L.repoSource]}):s.jsx("span",{className:"font-mono truncate",children:L.repoSource}),L.skillDir&&s.jsxs(s.Fragment,{children:[s.jsx("span",{className:"opacity-40",children:"·"}),s.jsx("span",{className:"truncate",children:L.skillDir})]})]}),L.warnings?.length?s.jsx("div",{className:"typography-micro text-[var(--status-warning)] mt-1.5 bg-[var(--status-warning)]/10 px-2 py-1 rounded w-fit",children:L.warnings.join(" · ")}):null]}),s.jsxs("div",{className:"flex items-center gap-1.5 shrink-0",children:[U&&s.jsx(V,{variant:"ghost",size:"xs",className:"!font-normal h-6 w-6 px-0",onClick:()=>window.open(U,"_blank","noreferrer"),title:n("settings.skills.catalog.page.skill.viewOnGithub"),children:s.jsx(O,{name:"external-link",className:"h-3.5 w-3.5"})}),J?s.jsx("span",{className:"text-[var(--status-success)] flex items-center justify-center w-7 h-7",title:n("settings.skills.catalog.page.badge.installed",{scope:ee||""}),children:s.jsx(O,{name:"check",className:"h-4 w-4"})}):s.jsx(V,{variant:"outline",size:"xs",className:"!font-normal",disabled:!L.installable,onClick:()=>{I(L),A(!0)},children:n("settings.skills.catalog.shared.actions.install")})]})]})},`${L.sourceId}:${L.skillDir}`)})})]})]}),s.jsx(nm,{open:v,onOpenChange:N}),s.jsx(im,{open:m,onOpenChange:A,item:R}),s.jsx(Kt,{open:w,onOpenChange:L=>{j||F(L)},children:s.jsxs(zt,{className:"max-w-md",children:[s.jsxs(_t,{children:[s.jsx($t,{children:n("settings.skills.catalog.page.removeDialog.title")}),s.jsx(Vt,{children:n("settings.skills.catalog.page.removeDialog.description")})]}),s.jsxs(ts,{children:[s.jsx(V,{size:"sm",variant:"ghost",onClick:()=>F(!1),disabled:j,children:n("settings.common.actions.cancel")}),s.jsx(V,{size:"sm",variant:"destructive",onClick:()=>{k()},disabled:j,children:n("settings.skills.catalog.page.actions.removeCatalog")})]})]})})]})},vm=()=>{const t=ut.c(1);let e;return t[0]===Symbol.for("react.memo_cache_sentinel")?(e=s.jsx(xm,{mode:"external",onModeChange:Nm,showModeTabs:!1}),t[0]=e):e=t[0],e},ym="SKILL.md",bm="h-[clamp(320px,58dvh,680px)] min-h-[260px] max-h-[calc(100dvh-220px)]",bi=(t,e)=>{const a=tu({description:t}).trimEnd(),n=e.trimStart();return`---
|
|
22
|
+
${a}
|
|
23
|
+
---${n?`
|
|
24
|
+
|
|
25
|
+
${n}`:`
|
|
26
|
+
`}`},wm=t=>typeof t=="object"&&t!==null&&!Array.isArray(t),ql=t=>{const e=t.match(/^---\r?\n([\s\S]*?)\r?\n---(?:\r?\n|$)([\s\S]*)$/);if(!e)return{description:null,instructions:t};let a=null;try{const n=su(e[1]);if(wm(n)){const r=n.description;typeof r=="string"&&(a=r)}}catch{a=null}return{description:a,instructions:e[2].replace(/^\r?\n/,"")}},jm=(t,e)=>{const a=ql(t);return bi(e,a.instructions)},km=()=>{const{t}=tt(),{currentTheme:e}=Cr(),{selectedSkillName:a,getSkillByName:n,getSkillDetail:r,createSkill:i,updateSkill:l,skillDraft:g,setSkillDraft:c,setSelectedSkill:y}=Hs(Us(me=>({selectedSkillName:me.selectedSkillName,getSkillByName:me.getSkillByName,getSkillDetail:me.getSkillDetail,createSkill:me.createSkill,updateSkill:me.updateSkill,skillDraft:me.skillDraft,setSkillDraft:me.setSkillDraft,setSelectedSkill:me.setSelectedSkill}))),p=_s(),b=Hs(me=>wr(me,p)),d=a?n(a,p):null,P=!!(g&&g.name===a&&!d),f=!!(a&&!d&&!g),C=d?.path==="<built-in>";o.useEffect(()=>{f&&y(null)},[f,y]);const[v,N]=o.useState(""),[m,A]=o.useState("user"),[R,I]=o.useState("opencode"),[j,h]=o.useState(""),[w,F]=o.useState(""),[T,S]=o.useState(()=>bi("","")),[D,$]=o.useState("edit"),[B,k]=o.useState([]),[G,M]=o.useState([]),[L,J]=o.useState(!1),[ee,U]=o.useState(!1),[le,_]=o.useState(""),[H,z]=o.useState(""),[K,te]=o.useState(!1),[Y,ae]=o.useState(""),[ge,de]=o.useState(""),[he,se]=o.useState(null),[re,ue]=o.useState(!1),[Ce,Se]=o.useState(""),[ye,fe]=o.useState(null),[_e,Ue]=o.useState(!1),Ne=P?v.trim()!==""||j.trim()!==""||w.trim()!==""||G.length>0:j!==le||w!==H,Oe=he?ge!==Ce:Y.trim()!=="",Ve=o.useCallback(me=>{switch(me){case"project-opencode":return t("settings.skills.location.option.projectOpencode.label");case"user-claude":return t("settings.skills.location.option.userClaude.label");case"project-claude":return t("settings.skills.location.option.projectClaude.label");case"user-agents":return t("settings.skills.location.option.userAgents.label");case"project-agents":return t("settings.skills.location.option.projectAgents.label");default:return t("settings.skills.location.option.userOpencode.label")}},[t]),Ge=o.useCallback(me=>{switch(me){case"project-opencode":return t("settings.skills.location.option.projectOpencode.description");case"user-claude":return t("settings.skills.location.option.userClaude.description");case"project-claude":return t("settings.skills.location.option.projectClaude.description");case"user-agents":return t("settings.skills.location.option.userAgents.description");case"project-agents":return t("settings.skills.location.option.projectAgents.description");default:return t("settings.skills.location.option.userOpencode.description")}},[t]);o.useEffect(()=>{(async()=>{if(P&&g){const Ie=g.description||"",Le=g.instructions||"";N(g.name||""),A(g.scope||"user"),I(g.source==="agents"?"agents":"opencode"),h(Ie),F(Le),S(bi(Ie,Le)),_(""),z(""),k([]),M(g.pendingFiles||[])}else if(a&&d){U(!0);try{const Ie=await r(a,p);if(Ie){const Le=Ie.sources.md,Xe=Le.description||"",q=Le.instructions||"";h(Xe),F(q),S(bi(Xe,q)),_(Xe),z(q),k(Le.supportingFiles||[])}}catch(Ie){console.error("Failed to load skill details:",Ie)}finally{U(!1)}}})()},[d,P,a,p,b,g,r]);const ve=ie(me=>me.editorFontSize),Z=o.useMemo(()=>{const me=[io(e,{fontSize:ve})],Ie=zr(ym);return Ie&&me.push(Ie),me.push(oo.lineWrapping),me},[e,ve]),ne=o.useMemo(()=>{const me=Y.trim()||"supporting-file.md",Ie=Ic(me),Le=!!Ie&&Ie!=="markdown",Xe=[io(e,Le?{syntaxColors:!1,fontSize:ve}:{fontSize:ve})],q=zr(me);return q&&Xe.push(q),Le&&Ie&&Xe.push(nu({language:Ie,themeName:e.metadata.id,theme:iu(e)})),Xe.push(oo.lineWrapping),Xe},[e,Y,ve]),be=o.useCallback(me=>{h(me),S(Ie=>jm(Ie,me))},[]),we=o.useCallback(me=>{S(me);const Ie=ql(me);h(Ie.description??""),F(Ie.instructions)},[]),Re=async()=>{const me=P?v.trim().replace(/\s+/g,"-").toLowerCase():a?.trim();if(!me){E.error(t("settings.skills.page.toast.skillNameRequired"));return}if(!/^[a-z0-9][a-z0-9-]*[a-z0-9]$|^[a-z0-9]$/.test(me)||me.length>64){E.error(t("settings.skills.page.toast.invalidSkillName"));return}if(!j.trim()){E.error(t("settings.skills.page.toast.descriptionRequired"));return}if(P&&b.some(Ie=>Ie.name===me)){E.error(t("settings.skills.page.toast.skillExists"));return}J(!0);try{const Ie={name:me,description:j.trim(),instructions:w.trim()||void 0,scope:P?m:void 0,source:P?R:void 0,targetPath:P?void 0:d?.path,supportingFiles:P&&G.length>0?G:void 0};let Le;if(P?(Le=await i(Ie,p),Le&&(c(null),M([]),y(me))):(Le=await l(me,Ie,p),Le&&(_(j.trim()),z(w.trim()))),Le){const Xe=Vn.getState().changes.some(q=>q.scope==="skills"&&q.id.startsWith(`skills:${me}:`));E.success(t(Xe?"settings.view.pendingRestart.saved":P?"settings.skills.page.toast.skillCreated":"settings.skills.page.toast.skillUpdated"))}else E.error(t(P?"settings.skills.page.toast.createSkillFailed":"settings.skills.page.toast.updateSkillFailed"))}catch(Ie){console.error("Error saving skill:",Ie),E.error(t("settings.skills.page.toast.saveUnexpectedError"))}finally{J(!1)}},Fe=()=>{se(null),ae(""),de(""),Se(""),te(!0)},Ke=async me=>{if(se(me),ae(me),P){const Le=G.find(Xe=>Xe.path===me)?.content||"";de(Le),Se(Le),te(!0);return}if(a){ue(!0),te(!0);try{const{readSupportingFile:Ie}=Hs.getState(),Le=await Ie(a,me,p);de(Le||""),Se(Le||"")}catch{E.error(t("settings.skills.page.toast.loadFileContentFailed")),de(""),Se("")}finally{ue(!1)}}},Ee=async()=>{if(!Y.trim()){E.error(t("settings.skills.page.toast.fileNameRequired"));return}const me=Y.trim(),Ie=he!==null;if(P){if(Ie)M(q=>q.map(ke=>ke.path===he?{path:me,content:ge}:ke)),E.success(t("settings.skills.page.toast.fileUpdated",{path:me}));else{if(G.some(q=>q.path===me)){E.error(t("settings.skills.page.toast.fileExists"));return}M(q=>[...q,{path:me,content:ge}]),E.success(t("settings.skills.page.toast.fileAdded",{path:me}))}te(!1),se(null);return}if(!a){E.error(t("settings.skills.page.toast.noSkillSelected"));return}const{writeSupportingFile:Le}=Hs.getState();if(await Le(a,me,ge,p)){E.success(Ie?t("settings.skills.page.toast.fileUpdated",{path:me}):t("settings.skills.page.toast.fileCreated",{path:me})),te(!1),se(null);const q=await r(a,p);q&&k(q.sources.md.supportingFiles||[])}else E.error(t(Ie?"settings.skills.page.toast.updateFileFailed":"settings.skills.page.toast.createFileFailed"))},je=me=>{if(P){M(Ie=>Ie.filter(Le=>Le.path!==me)),E.success(t("settings.skills.page.toast.fileRemoved",{path:me}));return}a&&fe(me)},Ze=async()=>{if(!ye||!a)return;Ue(!0);const{deleteSupportingFile:me}=Hs.getState();if(await me(a,ye,p)){E.success(t("settings.skills.page.toast.fileDeleted",{path:ye}));const Le=await r(a,p);Le&&k(Le.sources.md.supportingFiles||[]),fe(null)}else E.error(t("settings.skills.page.toast.deleteFileFailed"));Ue(!1)};return!a&&!g||f?s.jsx("div",{className:"flex h-full items-center justify-center px-4",children:s.jsxs("div",{className:"text-center text-muted-foreground",children:[s.jsx(O,{name:"book-open",className:"mx-auto mb-3 h-10 w-10 sm:h-12 sm:w-12 opacity-50"}),s.jsx("p",{className:"typography-body",children:t("settings.skills.page.empty.title")}),s.jsx("p",{className:"typography-meta mt-1 opacity-75",children:t("settings.skills.page.empty.description")})]})}):ee?s.jsx("div",{className:"flex h-full items-center justify-center px-4",children:s.jsx("div",{className:"text-center text-muted-foreground",children:s.jsx("p",{className:"typography-body",children:t("settings.skills.page.loading.details")})})}):s.jsxs(s.Fragment,{children:[s.jsxs(es,{title:P?t("settings.skills.page.title.newSkill"):a,description:d?t("settings.skills.page.subtitle.skillLocation",{location:Ve(Ua(d.scope,d.source))}):t("settings.skills.page.subtitle.newSkill"),showSaveStatus:!1,children:[s.jsxs(ze,{title:t("settings.skills.page.section.basicInformation"),divider:!1,settingsItem:"skills.basic-information",contentClassName:"space-y-0",children:[P&&s.jsxs(Rt,{label:t("settings.skills.page.field.skillNameLocation"),info:t("settings.skills.page.field.skillNameHint"),children:[s.jsx(He,{value:v,onChange:me=>N(me.target.value.toLowerCase().replace(/\s+/g,"-")),placeholder:t("settings.skills.page.field.skillNamePlaceholder"),className:"h-7 w-40 px-2"}),s.jsxs(St,{value:Ua(m,R),onValueChange:me=>{const Ie=Wl(me);A(Ie.scope),I(Ie.source==="agents"?"agents":"opencode")},children:[s.jsxs(Ct,{size:Ft,className:"w-fit gap-1.5",children:[m==="user"?s.jsx(O,{name:"user-3",className:"h-3.5 w-3.5"}):s.jsx(O,{name:"folder",className:"h-3.5 w-3.5"}),R==="agents"?s.jsx(O,{name:"robot-2",className:"h-3.5 w-3.5"}):null,s.jsx("span",{children:Ve(Ua(m,R))})]}),s.jsx(It,{align:"start",children:Pr.map(me=>s.jsx(at,{value:me.value,children:s.jsxs("div",{className:"flex flex-col gap-0.5",children:[s.jsxs("div",{className:"flex items-center gap-2",children:[me.scope==="user"?s.jsx(O,{name:"user-3",className:"h-3.5 w-3.5"}):s.jsx(O,{name:"folder",className:"h-3.5 w-3.5"}),me.source==="agents"?s.jsx(O,{name:"robot-2",className:"h-3.5 w-3.5"}):null,s.jsx("span",{children:Ve(me.value)})]}),s.jsx("span",{className:"typography-micro text-muted-foreground ml-6",children:Ge(me.value)})]})},me.value))})]})]}),s.jsx(qt,{label:s.jsxs(s.Fragment,{children:[t("settings.common.field.description")," ",s.jsx("span",{className:"text-[var(--status-error)]",children:"*"})]}),info:t("settings.skills.page.field.descriptionHint"),controlClassName:"w-full max-w-none",children:s.jsx(Ts,{value:j,onChange:me=>be(me.target.value),placeholder:t("settings.skills.page.field.descriptionPlaceholder"),rows:2,className:"w-full resize-none min-h-[60px] max-h-32 bg-transparent",disabled:C})})]}),s.jsx(ze,{title:t("settings.skills.page.section.instructions"),headerAction:s.jsx(au,{currentMode:D==="preview"?"preview":"edit",onToggle:()=>$(me=>me==="preview"?"edit":"preview")}),settingsItem:"skills.instructions",children:s.jsx("div",{className:xe("overflow-hidden rounded-md border border-[var(--surface-subtle)] bg-background",bm),children:D==="preview"?s.jsx(vs,{outerClassName:"h-full",className:"h-full",children:s.jsx("div",{className:"min-h-full px-4 py-3",children:s.jsx(Pc,{content:T,className:"typography-markdown-body",stripFrontmatter:!0,enableFileReferences:!1})})}):s.jsx(ro,{value:T,onChange:we,readOnly:C,extensions:Z,className:"h-full",enableSearch:!0})})}),s.jsx(ze,{title:t("settings.skills.page.section.supportingFiles"),headerAction:s.jsxs(V,{variant:"outline",size:"xs",className:"!font-normal gap-1",onClick:Fe,disabled:C,children:[s.jsx(O,{name:"add",className:"h-3.5 w-3.5"})," ",t("settings.skills.page.actions.addFile")]}),settingsItem:"skills.supporting-files",children:(()=>{const me=P?G:B;return me.length===0?s.jsx("p",{className:"typography-meta text-muted-foreground py-1.5",children:t("settings.skills.page.supportingFiles.empty")}):s.jsx("div",{className:"divide-y divide-[var(--surface-subtle)]",children:me.map(Ie=>s.jsxs("div",{className:"flex items-center gap-2 py-1.5 cursor-pointer group",onClick:()=>Ke(Ie.path),children:[s.jsx(O,{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}),P&&s.jsx("span",{className:"typography-micro text-[var(--status-warning)] bg-[var(--status-warning)]/10 px-1.5 py-0.5 rounded flex-shrink-0",children:t("settings.skills.page.badge.pending")}),!C&&s.jsx(V,{size:"sm",variant:"ghost",className:"h-5 w-5 px-0 flex-shrink-0 text-muted-foreground hover:text-[var(--status-error)] opacity-0 group-hover:opacity-100 transition-opacity",onClick:Le=>{Le.stopPropagation(),je(Ie.path)},children:s.jsx(O,{name:"delete-bin",className:"h-3 w-3"})})]},Ie.path))})})()}),s.jsx(ze,{children:s.jsx(V,{onClick:Re,disabled:C||L||!Ne,size:"xs",className:"!font-normal",children:t(L?"settings.common.actions.saving":P?"settings.skills.page.actions.createSkill":"settings.common.actions.saveChanges")})})]}),s.jsx(Kt,{open:ye!==null,onOpenChange:me=>{!me&&!_e&&fe(null)},children:s.jsxs(zt,{className:"max-w-md",children:[s.jsxs(_t,{children:[s.jsx($t,{children:t("settings.skills.page.deleteFileDialog.title")}),s.jsx(Vt,{children:t("settings.skills.page.deleteFileDialog.description",{path:ye??""})})]}),s.jsxs(ts,{children:[s.jsx(V,{size:"sm",variant:"ghost",onClick:()=>fe(null),disabled:_e,children:t("settings.common.actions.cancel")}),s.jsx(V,{size:"sm",variant:"destructive",onClick:Ze,disabled:_e,children:t("settings.common.actions.delete")})]})]})}),s.jsx(Kt,{open:K,onOpenChange:me=>{te(me),me||se(null)},children:s.jsxs(zt,{className:"max-w-3xl max-h-[85vh] flex flex-col",children:[s.jsxs(_t,{className:"flex-shrink-0",children:[s.jsx($t,{children:t(he?"settings.skills.page.fileDialog.titleEdit":"settings.skills.page.fileDialog.titleAdd")}),s.jsx(Vt,{children:t(he?"settings.skills.page.fileDialog.descriptionEdit":"settings.skills.page.fileDialog.descriptionAdd")})]}),re?s.jsx("div",{className:"flex-1 flex items-center justify-center py-8",children:s.jsx("span",{className:"typography-meta text-muted-foreground",children:t("settings.skills.page.loading.fileContent")})}):s.jsxs("div",{className:"space-y-4 flex-1 min-h-0 flex flex-col pt-2",children:[s.jsxs("div",{className:"space-y-2 flex-shrink-0",children:[s.jsxs("div",{className:"flex items-center gap-1",children:[s.jsx("label",{className:Tt,children:t("settings.skills.page.fileDialog.field.filePath")}),!he&&s.jsx(Jt,{children:t("settings.skills.page.fileDialog.field.filePathHint")})]}),s.jsx(He,{value:Y,onChange:me=>ae(me.target.value),placeholder:t("settings.skills.page.fileDialog.field.filePathPlaceholder"),className:"text-foreground placeholder:text-muted-foreground focus-visible:ring-[var(--primary-base)]",disabled:he!==null})]}),s.jsxs("div",{className:"space-y-2 flex-1 min-h-0 flex flex-col",children:[s.jsx("label",{className:`${Tt} flex-shrink-0`,children:t("settings.skills.page.fileDialog.field.content")}),s.jsx("div",{className:"h-[45vh] min-h-[250px] max-h-[55vh] overflow-hidden rounded-md border border-[var(--surface-subtle)] bg-background",children:s.jsx(ro,{value:ge,onChange:de,extensions:ne,className:"h-full",enableSearch:!0})})]})]}),s.jsxs(ts,{className:"mt-4",children:[s.jsx(V,{size:"sm",variant:"ghost",onClick:()=>{te(!1),se(null)},children:t("settings.common.actions.cancel")}),s.jsx(V,{size:"sm",onClick:Ee,disabled:re||!Oe,children:t(he?"settings.common.actions.saveChanges":"settings.skills.page.actions.createFile")})]})]})})]})},No=t=>{const e=ut.c(2),{view:a}=t,n=a===void 0?"installed":a;let r;return e[0]!==n?(r=n==="catalog"?s.jsx(vm,{}):s.jsx(km,{}),e[0]=n,e[1]=r):r=e[1],r};function Nm(){}const Sm=t=>{const e=ut.c(38),{onItemSelect:a}=t,{t:n}=tt(),r=Gs(Cm),i=ie(Im),l=ie(Pm),{currentTheme:g}=Cr();let c;e[0]===Symbol.for("react.memo_cache_sentinel")?(c=cs(),e[0]=c):c=e[0];const y=c,p=Am;let b,d;e[1]!==r||e[2]!==i||e[3]!==l?(b=()=>{if(r.length===0){i!==null&&l(null);return}i&&r.some(h=>h.id===i)||l(r[0].id)},d=[r,i,l],e[1]=r,e[2]=i,e[3]=l,e[4]=b,e[5]=d):(b=e[4],d=e[5]),o.useEffect(b,d);let P;e[6]===Symbol.for("react.memo_cache_sentinel")?(P=xe("border-b px-3","pt-4 pb-3"),e[6]=P):P=e[6];let f;e[7]!==n?(f=n("settings.page.projects.title"),e[7]=n,e[8]=f):f=e[8];let C;e[9]!==f?(C=s.jsx("h2",{className:`${un} mb-3`,children:f}),e[9]=f,e[10]=C):C=e[10];let v;e[11]!==r.length||e[12]!==n?(v=n("settings.projects.sidebar.total",{count:r.length}),e[11]=r.length,e[12]=n,e[13]=v):v=e[13];let N;e[14]!==v?(N=s.jsx("span",{className:"typography-meta text-muted-foreground",children:v}),e[14]=v,e[15]=N):N=e[15];let m;e[16]!==n?(m=!y&&s.jsx(V,{type:"button",variant:"ghost",size:"icon",className:"h-7 w-7 -my-1 text-muted-foreground",onClick:p,"aria-label":n("settings.projects.sidebar.actions.addProject"),children:s.jsx(O,{name:"add",className:"size-4"})}),e[16]=n,e[17]=m):m=e[17];let A;e[18]!==N||e[19]!==m?(A=s.jsxs("div",{className:"flex items-center justify-between gap-2",children:[N,m]}),e[18]=N,e[19]=m,e[20]=A):A=e[20];let R;e[21]!==A||e[22]!==C?(R=s.jsxs("div",{className:P,children:[C,A]}),e[21]=A,e[22]=C,e[23]=R):R=e[23];let I;if(e[24]!==g||e[25]!==a||e[26]!==r||e[27]!==i||e[28]!==l){let h;e[30]!==g||e[31]!==a||e[32]!==i||e[33]!==l?(h=w=>{const F=w.id===i,T=w.icon?Tc[w.icon]:null,S=w.color?Ec[w.color]??null:null,D=T?s.jsx(O,{name:T,className:xe("h-4 w-4",F?"text-foreground":"text-muted-foreground/70"),style:S?{color:S}:void 0}):s.jsx(O,{name:"folder",className:xe("h-4 w-4",F?"text-foreground":"text-muted-foreground/70"),style:S?{color:S}:void 0}),$=w.iconImage?s.jsx("span",{className:"inline-flex h-4 w-4 items-center justify-center overflow-hidden rounded-[2px]",style:w.iconBackground?{backgroundColor:w.iconBackground}:void 0,children:s.jsx(Dc,{project:w,options:{themeVariant:g.metadata.variant,iconColor:g.colors.surface.foreground},className:"h-full w-full object-contain",fallback:D})}):D;return s.jsx(gr,{title:w.label||w.path,icon:$,selected:F,onSelect:()=>{l(w.id),a?.()}},w.id)},e[30]=g,e[31]=a,e[32]=i,e[33]=l,e[34]=h):h=e[34],I=r.map(h),e[24]=g,e[25]=a,e[26]=r,e[27]=i,e[28]=l,e[29]=I}else I=e[29];let j;return e[35]!==R||e[36]!==I?(j=s.jsx(Hl,{variant:"background",header:R,children:I}),e[35]=R,e[36]=I,e[37]=j):j=e[37],j};function Cm(t){return t.projects}function Im(t){return t.settingsProjectsSelectedId}function Pm(t){return t.setSettingsProjectsSelectedId}function Am(){Ac.requestDirectoryDialog()}const Tm=()=>{const t=ut.c(30),{t:e}=tt(),a=Gs(Em),n=Gs(Dm),r=ie(Mm),i=ie(Rm);let l;e:{if(!r){l=null;break e}let v;t[0]!==a||t[1]!==r?(v=a.find(N=>N.id===r)??null,t[0]=a,t[1]=r,t[2]=v):v=t[2],l=v}const g=l;let c,y;t[3]!==a||t[4]!==r||t[5]!==i?(c=()=>{if(a.length===0){i(null);return}r&&a.some(v=>v.id===r)||i(a[0].id)},y=[a,r,i],t[3]=a,t[4]=r,t[5]=i,t[6]=c,t[7]=y):(c=t[6],y=t[7]),o.useEffect(c,y);let p;t[8]!==g||t[9]!==n?(p=async v=>{g&&n(g.id,{label:v.label,icon:v.icon,color:v.color,iconBackground:v.iconBackground,defaultModel:v.defaultModel??null,defaultVariant:v.defaultVariant??null})},t[8]=g,t[9]=n,t[10]=p):p=t[10];const b=p;if(!g){let v;t[11]!==e?(v=e("settings.page.projects.title"),t[11]=e,t[12]=v):v=t[12];let N;t[13]!==e?(N=e("settings.projects.page.empty.noProjects"),t[13]=e,t[14]=N):N=t[14];let m;t[15]!==N?(m=s.jsx("p",{className:"typography-meta text-muted-foreground",children:N}),t[15]=N,t[16]=m):m=t[16];let A;return t[17]!==v||t[18]!==m?(A=s.jsx(es,{title:v,showSaveStatus:!0,children:m}),t[17]=v,t[18]=m,t[19]=A):A=t[19],A}let d;t[20]!==g.label||t[21]!==e?(d=g.label??e("settings.projects.page.title.default"),t[20]=g.label,t[21]=e,t[22]=d):d=t[22];const P=d;let f;t[23]!==b||t[24]!==g?(f=s.jsx(Wd,{project:g,onIdentitySave:b}),t[23]=b,t[24]=g,t[25]=f):f=t[25];let C;return t[26]!==P||t[27]!==g.path||t[28]!==f?(C=s.jsx(es,{title:P,description:g.path,showSaveStatus:!0,outerClassName:"bg-background",children:f}),t[26]=P,t[27]=g.path,t[28]=f,t[29]=C):C=t[29],C};function Em(t){return t.projects}function Dm(t){return t.updateProjectMeta}function Mm(t){return t.settingsProjectsSelectedId}function Rm(t){return t.setSettingsProjectsSelectedId}const wi=()=>Math.floor(2e4+Math.random()*3e4),Lm=t=>{const e=(t instanceof Error?t.message:String(t)).toLowerCase();return e.includes("address already in use")||e.includes("eaddrinuse")||e.includes("port already in use")},Om=()=>{if(typeof navigator>"u")return;const t=(navigator.userAgent||"").toLowerCase();if(t.includes("mac"))return"macos";if(t.includes("win"))return"windows";if(t.includes("linux"))return"linux"},So=t=>{switch((t||"").toLowerCase()){case"ios":return"iOS";case"android":return"Android";case"macos":case"darwin":return"macOS";case"windows":case"win32":return"Windows";case"linux":return"Linux";default:return null}},Co=t=>{switch(t){case"config_resolved":return"settings.remoteInstances.page.phase.resolvingConfiguration";case"auth_check":return"settings.remoteInstances.page.phase.checkingAuth";case"master_connecting":return"settings.remoteInstances.page.phase.establishingSsh";case"remote_probe":return"settings.remoteInstances.page.phase.probingRemote";case"installing":return"settings.remoteInstances.page.phase.installingAiWorker";case"updating":return"settings.remoteInstances.page.phase.updatingAiWorker";case"server_detecting":return"settings.remoteInstances.page.phase.detectingServer";case"server_starting":return"settings.remoteInstances.page.phase.startingServer";case"forwarding":return"settings.remoteInstances.page.phase.forwardingPorts";case"ready":return"settings.remoteInstances.sidebar.phase.ready";case"degraded":return"settings.remoteInstances.page.phase.reconnecting";case"error":return"settings.remoteInstances.sidebar.phase.error";default:return"settings.remoteInstances.sidebar.phase.idle"}},Fm=new Set(["config_resolved","auth_check","master_connecting","remote_probe","installing","updating","server_detecting","server_starting","forwarding"]),Ar=t=>!!(t&&Fm.has(t)),Io=t=>t==="ready"?"ready":t==="error"?"error":t==="degraded"||Ar(t)?"connecting":"idle",Po=t=>{switch(t){case"ready":return"settings.remoteInstances.page.state.ready";case"connecting":return"settings.remoteInstances.page.state.connecting";case"error":return"settings.remoteInstances.page.state.problem";default:return"settings.remoteInstances.page.state.notConnected"}},Km=t=>{const e=(t||"").toLowerCase();return e?e.includes("ui authentication")||e.includes("ui password")?"uiPassword":e.includes("already in use")||e.includes("eaddrinuse")?"localPort":e.includes("neither bun nor npm")?"noRuntime":e.includes("opencode cli is not installed")?"noOpencode":e.includes("requires a ui password")?"uiPassword":e.includes("preferred remote aiworker port")?"externalPort":null:null},Ao={noRuntime:"settings.remoteInstances.page.error.hint.noRuntime",noOpencode:"settings.remoteInstances.page.error.hint.noOpencode"},zm=t=>t==="noRuntime"?Ao.noRuntime:t==="noOpencode"?Ao.noOpencode:null,To=t=>t==="ready"?"bg-[var(--status-success)] animate-pulse":t==="error"?"bg-[var(--status-error)] animate-pulse":t==="degraded"||Ar(t)?"bg-[var(--status-warning)] animate-pulse":"bg-muted-foreground/40",Um=t=>t.type==="dynamic"?`${t.localHost||"127.0.0.1"}:${t.localPort||0}`:t.type==="remote"?`${t.remoteHost||"127.0.0.1"}:${t.remotePort||0} -> ${t.localHost||"127.0.0.1"}:${t.localPort||0}`:`${t.localHost||"127.0.0.1"}:${t.localPort||0} -> ${t.remoteHost||"127.0.0.1"}:${t.remotePort||0}`,_m=()=>({id:`forward-${Date.now()}-${Math.random().toString(16).slice(2)}`,enabled:!0,type:"local",localHost:"127.0.0.1",localPort:wi(),remoteHost:"127.0.0.1",remotePort:80}),$m=t=>t.trim().replace(/\*/g,"host").replace(/\?/g,"x")||"user@host",Vs=t=>{const e=ut.c(7),{label:a,hint:n}=t;let r;e[0]!==a?(r=s.jsx("span",{children:a}),e[0]=a,e[1]=r):r=e[1];let i;e[2]!==n?(i=s.jsx(Jt,{contentClassName:"max-w-xs",children:n}),e[2]=n,e[3]=i):i=e[3];let l;return e[4]!==r||e[5]!==i?(l=s.jsxs("span",{className:`inline-flex items-center gap-1 ${Tt}`,children:[r,i]}),e[4]=r,e[5]=i,e[6]=l):l=e[6],l},Vm=t=>{switch(t){case"remote":return"settings.remoteInstances.page.forwardTypeDescription.remote";case"dynamic":return"settings.remoteInstances.page.forwardTypeDescription.dynamic";default:return"settings.remoteInstances.page.forwardTypeDescription.local"}},Eo=(t,e)=>{const a=(t||"").trim();return`${!a||a==="127.0.0.1"||a==="::1"?"localhost":a}:${e||0}`},Bm=t=>{const e=(t||"").trim();return!e||e==="0.0.0.0"||e==="::"?"127.0.0.1":e},Hm=t=>{const e=t.match(/^\[(\d{10,})\]\s*(?:\[([A-Z]+)\]\s*)?(.*)$/);if(!e)return t;const a=Number(e[1]),n=Number.isFinite(a)?new Date(a).toISOString():e[1],r=(e[2]||"INFO").toUpperCase(),i=e[3]||"";return`[${n}] [${r}] ${i}`},fr=(t="",e="")=>({id:typeof crypto<"u"&&typeof crypto.randomUUID=="function"?crypto.randomUUID():`header-${Date.now()}-${Math.random().toString(16).slice(2)}`,name:t,value:e}),Gm=t=>t.trim().toLowerCase()==="authorization",Xi=t=>{const e={};for(const a of t){const n=a.name.trim(),r=a.value.trim();n&&r&&!Gm(n)&&(e[n]=r)}return Object.keys(e).length>0?e:void 0},Wm=t=>Object.entries(t||{}).map(([e,a])=>fr(e,a)),Jl=()=>{if(typeof window>"u")return null;const e=$a()||window.location.href;try{const a=Number(new URL(e).port||window.location.port);return Number.isFinite(a)&&a>0?a:null}catch{const a=Number(window.location.port);return Number.isFinite(a)&&a>0?a:null}},Do=t=>{try{const e=new URL(t).hostname.toLowerCase();return e==="localhost"||e==="127.0.0.1"||e==="::1"||e==="[::1]"}catch{return!1}},qm=async()=>{const t=ua($a())||window.location.origin;if(!as()||!Va()||(await pn())?.desktopLanAccessActive!==!0)return t;const a=await Dl(),n=Jl();return!a||!n?t:`http://${a}:${n}`},pi=t=>{const e=t.trim();if(e)try{window.location.assign(e)}catch{window.location.href=e}},Jm=t=>{const e=t.sshCommand.trim(),a=t.nickname?.trim(),n=t.portForwards.map(r=>({...r,localHost:r.localHost?.trim()||"127.0.0.1",localPort:typeof r.localPort=="number"?Math.max(1,Math.min(65535,Math.round(r.localPort))):void 0,remoteHost:r.remoteHost?.trim(),remotePort:typeof r.remotePort=="number"?Math.max(1,Math.min(65535,Math.round(r.remotePort))):void 0}));return{...t,sshCommand:e,...a?{nickname:a}:{nickname:void 0},connectionTimeoutSec:Math.max(5,Math.min(240,Math.round(t.connectionTimeoutSec||60))),localForward:{...t.localForward,bindHost:t.localForward.bindHost==="localhost"||t.localForward.bindHost==="0.0.0.0"?t.localForward.bindHost:"127.0.0.1",preferredLocalPort:typeof t.localForward.preferredLocalPort=="number"?Math.max(1,Math.min(65535,Math.round(t.localForward.preferredLocalPort))):void 0},remoteOpenchamber:{...t.remoteOpenchamber,preferredPort:typeof t.remoteOpenchamber.preferredPort=="number"?Math.max(1,Math.min(65535,Math.round(t.remoteOpenchamber.preferredPort))):void 0},portForwards:n}},Qm=()=>{const{t}=tt(),e=ie(x=>x.timeFormatPreference),{clientAuth:a}=Nl(),n=as(),r=As(x=>x.instances),i=As(x=>x.statusesById),l=As(x=>x.importCandidates),g=As(x=>x.isLoading),c=As(x=>x.isImportsLoading),y=As(x=>x.isSaving),p=As(x=>x.error),b=As(x=>x.load),d=As(x=>x.loadImports),P=As(x=>x.refreshStatuses),f=As(x=>x.upsertInstance),C=As(x=>x.createFromCommand),v=As(x=>x.removeInstance),N=As(x=>x.connect),m=As(x=>x.disconnect),A=As(x=>x.retry),R=ie(x=>x.settingsRemoteInstancesSelectedId),I=ie(x=>x.setSettingsRemoteInstancesSelectedId),j=o.useMemo(()=>R&&r.find(x=>x.id===R)||null,[r,R]),[h,w]=o.useState(null),[F,T]=o.useState(!1),[S,D]=o.useState(!1),[$,B]=o.useState(null),[k,G]=o.useState([]),[M,L]=o.useState(null),[J,ee]=o.useState(""),[U,le]=o.useState(!1),[_,H]=o.useState({}),[z,K]=o.useState(!1),[te,Y]=o.useState(!1),[ae,ge]=o.useState(()=>Date.now()),[de,he]=o.useState([]),[se,re]=o.useState({}),[ue,Ce]=o.useState("local"),[Se,ye]=o.useState(!1),[fe,_e]=o.useState(!1),[Ue,Ne]=o.useState(""),[Oe,Ve]=o.useState(""),[Ge,ve]=o.useState(""),[Z,ne]=o.useState([]),[be,we]=o.useState(""),[Re,Fe]=o.useState(null),[Ke,Ee]=o.useState(!1),[je,Ze]=o.useState(!1),[me,Ie]=o.useState(null),[Le,Xe]=o.useState(""),[q,ke]=o.useState(""),[Pe,Je]=o.useState(""),[ot,st]=o.useState([]),[pt,vt]=o.useState([]),[W,We]=o.useState([]),[nt,lt]=o.useState(!1),[ht,Lt]=o.useState(""),[et,ft]=o.useState(null),[bt,Be]=o.useState(null),[Et,Me]=o.useState(null),[wt,Q]=o.useState(null),[pe,De]=o.useState(!1),[Ae,it]=o.useState(!1),[rt,qe]=o.useState("configure"),[Pt,ys]=o.useState(!1),[Xt,Os]=o.useState("relay"),[Wt,is]=o.useState(!0),[Ht,bs]=o.useState(null),gs=o.useMemo(()=>pt.filter(x=>!!x.revokedAt).length,[pt]),[hs,ds]=o.useState(!1),[Es,oe]=o.useState("saved"),[ct,xt]=o.useState(""),[Qt,Yt]=o.useState(""),[Bt,rs]=o.useState(""),[ws,ss]=o.useState(!1);o.useEffect(()=>{b(),d()},[b,d]);const jt=o.useCallback(async()=>{ye(!0),Fe(null);try{const x=await qr();he(x.hosts||[]),Ce(x.defaultHostId||"local")}catch(x){Fe(x instanceof Error?x.message:String(x))}finally{ye(!1)}},[]);o.useEffect(()=>{jt()},[jt]);const At=o.useCallback(async(x,X=ue)=>{_e(!0),Fe(null);try{await Jr({hosts:x,defaultHostId:X,initialHostChoiceCompleted:!0}),he(x),Ce(X)}catch(Te){Fe(Te instanceof Error?Te.message:String(Te))}finally{_e(!1)}},[ue]),Ut=o.useCallback(async()=>{const x=Qr(Oe);if(!x){Fe(t("desktopHostSwitcher.error.invalidUrl"));return}const X=x.persistedUrl,Qe={id:typeof crypto<"u"&&typeof crypto.randomUUID=="function"?crypto.randomUUID():`host-${Date.now()}-${Math.random().toString(16).slice(2)}`,label:Ue.trim()||Ia(X),url:X,apiUrl:X,...Ge.trim()?{clientToken:Ge.trim()}:{},...Xi(Z)?{requestHeaders:Xi(Z)}:{}};await At([Qe,...de],ue),Ne(""),Ve(""),ve(""),ne([]),Ee(!1),x.redeemUrl&&pi(x.redeemUrl)},[ue,Z,de,Ue,Ge,Oe,At,t]),Ot=o.useCallback(async()=>{const x=xd(be);if(!x){Fe(t("settings.remoteInstances.direct.error.invalidConnectLink"));return}const X=await vd().catch(()=>""),Te=JSON.stringify({pairingId:x.pairingId,secret:x.secret,clientLabel:x.label||"AiWorker Desktop",clientKind:"desktop",deviceName:"AiWorker Desktop",devicePlatform:Om(),...X?{dedupeKey:`desktop:${X}`}:{}}),Qe={method:"POST",headers:{"Content-Type":"application/json",Accept:"application/json"},body:Te},Dt=async Nt=>{if(!Nt.ok)return null;const Ms=await Nt.json().catch(()=>null);return(typeof Ms?.clientToken=="string"?Ms.clientToken.trim():"")||null},ks=[...x.candidates].sort((Nt,Ms)=>(Nt.type==="relay"?1:0)-(Ms.type==="relay"?1:0));let us=null;for(const Nt of ks){if(Nt.type==="relay"){const On=yd({relayUrl:Nt.relayUrl,serverId:Nt.serverId,hostEncPubJwk:Nt.hostEncPubJwk,...Nt.grant?{grant:Nt.grant}:{}});try{const ra=await On.fetch("/api/client-auth/pairing/redeem",Qe),si=await Dt(ra);if(si){us={kind:"relay",relay:{relayUrl:Nt.relayUrl,serverId:Nt.serverId,hostEncPubJwk:Nt.hostEncPubJwk},token:si};break}}catch{}finally{On.close()}continue}const Ms=ua(Nt.url);if(Ms)try{const On=await fetch(`${Ms}/api/client-auth/pairing/redeem`,Qe),ra=await Dt(On);if(ra){us={kind:"direct",url:Ms,token:ra};break}}catch{}}if(!us){Fe(t("desktopHostSwitcher.error.invalidUrl"));return}const $s=()=>typeof crypto<"u"&&typeof crypto.randomUUID=="function"?crypto.randomUUID():`host-${Date.now()}-${Math.random().toString(16).slice(2)}`,Ns=x.candidates.find(Nt=>Nt.type==="relay"),qs=us.kind==="relay"?us.relay:Ns?{relayUrl:Ns.relayUrl,serverId:Ns.serverId,hostEncPubJwk:Ns.hostEncPubJwk}:void 0,Sa=x.candidates.filter(Nt=>Nt.type!=="relay").map(Nt=>ua(Nt.url)).find(Nt=>!!Nt),Ln=us.kind==="direct"?us.url:Sa,{token:Ca}=us,kt=Ln||(qs?bd(qs.serverId):null);if(!kt){Fe(t("desktopHostSwitcher.error.invalidUrl"));return}const Gt={url:kt,apiUrl:Ln||void 0,clientToken:Ca,...qs?{relay:qs}:{}},tn=de.find(Nt=>qs?Nt.relay?.serverId===qs.serverId:!Nt.relay&&ua(Nt.apiUrl||Nt.url)===kt);if(tn){const Nt=de.map(Ms=>Ms.id===tn.id?{...Ms,label:x.label||Ms.label,...Gt}:Ms);await At(Nt,ue)}else await At([{id:$s(),label:x.label||Ia(kt),...Gt},...de],ue);we(""),Fe(null),Ze(!1)},[be,ue,de,At,t]),ns=o.useCallback(async x=>{const X=de.filter(Qe=>Qe.id!==x);await At(X,ue===x?"local":ue),me===x&&Ie(null)},[ue,me,de,At]),Ds=o.useCallback(x=>{Ie(x.id),Xe(x.label),ke(x.apiUrl||x.url),Je(x.clientToken||""),st(Wm(x.requestHeaders)),Fe(null)},[]),Ai=o.useCallback(async()=>{if(!me)return;const x=Qr(q);if(!x){Fe(t("desktopHostSwitcher.error.invalidUrl"));return}const X=x.persistedUrl,Te=de.map(Qe=>Qe.id===me?{...Qe,label:Le.trim()||Ia(X),url:X,apiUrl:X,clientToken:Pe.trim()||void 0,requestHeaders:Xi(ot)}:Qe);await At(Te,ue),Ie(null),x.redeemUrl&&pi(x.redeemUrl)},[ue,ot,Le,Pe,q,me,de,At,t]),Ti=o.useCallback(async()=>{const x=Qt.trim();if(!x){E.error(t("settings.remoteInstances.page.toast.sshCommandRequired"));return}const X=`ssh-${Date.now()}-${Math.random().toString(16).slice(2)}`;try{await C(X,x,Bt.trim()||t("settings.remoteInstances.sidebar.newSshInstanceName")),I(X),ds(!1),Yt(""),rs(""),E.success(t("settings.remoteInstances.page.toast.instanceCreated"))}catch(Te){E.error(t("settings.remoteInstances.sidebar.toast.createFailed"),{description:Te instanceof Error?Te.message:String(Te)})}},[C,I,Qt,Bt,t]),Ha=o.useCallback(()=>{xt(""),oe(l.length>0?"saved":"manual"),ds(!0)},[l.length]),Ei=o.useCallback(async x=>{await At(de,x)},[de,At]);o.useEffect(()=>{if(!n||de.length===0)return;let x=!1;return Promise.all(de.map(async X=>{const Te=()=>Cd(X.relay,{clientToken:X.clientToken||null,requestHeaders:X.requestHeaders||null}).catch(()=>({status:"unreachable",latencyMs:0}));if(X.relay&&!X.apiUrl)return[X.id,await Te()];const Qe=ua(wd(X));if(!Qe)return[X.id,X.relay?await Te():{status:"unreachable",latencyMs:0}];const Dt=await jd(Qe,{clientToken:X.clientToken||null,requestHeaders:X.requestHeaders||null}).catch(()=>({status:"unreachable",latencyMs:0}));if(Dt.status==="unreachable"&&X.relay){const ks=await Te();if(ks.status==="ok")return[X.id,ks]}return[X.id,Dt]})).then(X=>{x||re(Object.fromEntries(X))}),()=>{x=!0}},[de,n]);const Fs=o.useCallback(async x=>{if(a){x?.silent||lt(!0),x?.silent||ft(null);try{const[X,Te]=await Promise.all([a.listClients(),a.listPendingPairings().catch(()=>null)]);vt(X),Te&&We(Te)}catch(X){x?.silent||ft(X instanceof Error?X.message:String(X))}finally{x?.silent||lt(!1)}}},[a]),ja=o.useRef(!1);o.useEffect(()=>{if(!(!Ae||rt!=="result"||!Et)){if(W.some(x=>x.id===Et)){ja.current=!0;return}ja.current&&(Me(null),it(!1),pt.some(x=>x.pairingId===Et)&&E.success(t("settings.remoteInstances.clientAuth.addDevice.connectedToast")))}},[Ae,rt,Et,W,pt,t]);const Di=o.useCallback(async x=>{if(a)try{await a.cancelPairing(x),We(X=>X.filter(Te=>Te.id!==x)),await Fs({silent:!0})}catch(X){ft(X instanceof Error?X.message:String(X))}},[a,Fs]);o.useEffect(()=>{if(!a)return;Fs();const x=window.setInterval(()=>{typeof document<"u"&&document.visibilityState!=="visible"||Fs({silent:!0})},5e3);return()=>window.clearInterval(x)},[a,Fs]);const Ga=o.useCallback(async()=>{if(a?.getPairingTransports)try{const Qe=await a.getPairingTransports();return{localUrl:Qe.local,lanUrl:Qe.lan,relayAvailable:Qe.relayAvailable}}catch{}const x=Jl(),X=x?`http://127.0.0.1:${x}`:Do(window.location.origin)?window.location.origin:null;let Te=null;try{const Qe=ua(await qm());Te=Qe&&!Do(Qe)?Qe:null}catch{}return{localUrl:X,lanUrl:Te,relayAvailable:!0}},[a]),Wa=o.useCallback(async()=>{ft(null),Be(null),Q(null),De(!1),Me(null),qe("configure"),is(!0),it(!0);const x=await Ga();bs(x),Os(x.relayAvailable?"relay":x.lanUrl?"lan":"local")},[Ga]),Mi=o.useCallback(async()=>{if(!(!a?.createPairingSession||!Ht)){ft(null),ys(!0);try{const x=ht.trim()||void 0;let X,Te,Qe=!0;Xt==="local"?(X=Ht.localUrl??void 0,Te=!1):Xt==="lan"?(X=Ht.lanUrl??void 0,Te=Wt):Wt&&Ht.lanUrl?(X=Ht.lanUrl,Te=!0):(Qe=!1,Te=!0);const{pairing:Dt,server:ks}=await a.createPairingSession({label:x,allowedClientKinds:["mobile","desktop"],serverUrl:X,includeRelay:Te,includeDirect:Qe}),us=kd({pairingId:Dt.id,secret:Dt.secret,label:ks.label,fingerprint:Dt.fingerprint??void 0,expiresAt:Dt.expiresAt,candidates:ks.candidates}),$s=Nd(us);Be($s),Q(await zl.toDataURL($s,{width:1024,margin:2,errorCorrectionLevel:"L"})),De(!1),ja.current=!1,Me(Dt.id),qe("result"),await Fs({silent:!0})}catch(x){ft(x instanceof Error?x.message:String(x))}finally{ys(!1)}}},[a,Ht,Xt,Wt,ht,Fs]),Ri=o.useCallback(()=>{bt&&Ka(bt).then(x=>{x.ok&&(De(!0),window.setTimeout(()=>De(!1),2e3))})},[bt]),Li=o.useCallback(async x=>{if(!a)return;const X=x.clientKind==="desktop-local";ft(null);try{if(await a.revokeClient(x.id),X&&as()){const Te=await qr();await Jr({hosts:Te.hosts,defaultHostId:Te.defaultHostId,initialHostChoiceCompleted:Te.initialHostChoiceCompleted,localClientToken:null}),vt(Qe=>Qe.map(Dt=>Dt.id===x.id?{...Dt,revokedAt:new Date().toISOString()}:Dt)),Sd({apiBaseUrl:$a(),clientToken:null,runtimeKey:"local"});return}await Fs()}catch(Te){ft(Te instanceof Error?Te.message:String(Te))}},[a,Fs]),qa=o.useCallback(async()=>{if(a){ft(null);try{await a.purgeRevokedClients(),await Fs()}catch(x){ft(x instanceof Error?x.message:String(x))}}},[a,Fs]);o.useEffect(()=>{w(j)},[j]),o.useEffect(()=>{ss(!1)},[R]),o.useEffect(()=>{if(!R)return;const x=window.setInterval(()=>{typeof document<"u"&&document.visibilityState!=="visible"||P()},2e3);return()=>{window.clearInterval(x)}},[P,R]),o.useEffect(()=>{let x=null,X=Date.now();const Te=()=>{const Dt=Date.now();Dt-X>=1e3&&(ge(Dt),X=Dt),x=requestAnimationFrame(Te)};(typeof document>"u"||document.visibilityState==="visible")&&(x=requestAnimationFrame(Te));const Qe=()=>{document.visibilityState==="visible"&&x===null?x=requestAnimationFrame(Te):document.visibilityState!=="visible"&&x!==null&&(cancelAnimationFrame(x),x=null)};return document.addEventListener("visibilitychange",Qe),()=>{document.removeEventListener("visibilitychange",Qe),x!==null&&cancelAnimationFrame(x)}},[]);const js=R?i[R]:null,Ws=js?.phase,Zn=Ws==="ready",mn=Ws==="degraded",xn=Ar(Ws),Xs=Zn||(xn||mn),Oi=js?Math.max(0,ae-js.updatedAtMs):0,Dn=mn&&Oi>12e3,Xn=Io(Ws),Mn=Xn==="error"?Km(js?.detail):null,ka=zm(Mn),Fi=o.useMemo(()=>!h||!j?!1:JSON.stringify(h)!==JSON.stringify(j),[h,j]),os=o.useCallback(x=>{w(X=>X&&x(X))},[]),Ki=o.useCallback(async()=>{if(!h)return;const x=Jm(h);if(!x.sshCommand.trim()){E.error(t("settings.remoteInstances.page.toast.sshCommandRequired"));return}if(x.remoteOpenchamber.mode==="external"&&!x.remoteOpenchamber.preferredPort){E.error(t("settings.remoteInstances.page.validation.externalPortRequired")),ss(!0);return}if(x.remoteOpenchamber.mode==="managed"&&x.remoteOpenchamber.bindHost==="0.0.0.0"&&!x.auth.aiworkerPassword?.value?.trim()){E.error(t("settings.remoteInstances.page.validation.remoteLanNeedsPassword")),ss(!0),window.setTimeout(()=>gn.current?.focus(),0);return}if(!(x.localForward.bindHost==="0.0.0.0"&&!window.confirm(t("settings.remoteInstances.page.confirm.bindAllInterfaces")))){if(x.auth.sshPassword?.enabled&&x.auth.sshPassword.value?.trim()&&x.auth.sshPassword.store!=="settings"){const X=window.confirm(t("settings.remoteInstances.page.confirm.storeSshPasswordPlaintext"));x.auth.sshPassword.store=X?"settings":"never",X||(x.auth.sshPassword.value=void 0)}if(x.auth.aiworkerPassword?.enabled&&x.auth.aiworkerPassword.value?.trim()&&x.auth.aiworkerPassword.store!=="settings"){const X=window.confirm(t("settings.remoteInstances.page.confirm.storeUiPasswordPlaintext"));x.auth.aiworkerPassword.store=X?"settings":"never",X||(x.auth.aiworkerPassword.value=void 0)}try{await f(x),E.success(t("settings.remoteInstances.page.toast.instanceSaved"))}catch(X){E.error(t("settings.remoteInstances.page.toast.saveFailed"),{description:X instanceof Error?X.message:String(X)})}}},[h,t,f]),ea=o.useCallback(async(x,X)=>{const Te=`ssh-${Date.now()}-${Math.random().toString(16).slice(2)}`;try{return await C(Te,`ssh ${X}`,x),I(Te),E.success(t("settings.remoteInstances.page.toast.instanceCreated")),!0}catch(Qe){return E.error(t("settings.remoteInstances.sidebar.toast.createFailed"),{description:Qe instanceof Error?Qe.message:String(Qe)}),!1}},[C,I,t]),ta=o.useCallback(()=>{U||(L(null),ee(""))},[U]),zi=o.useCallback((x,X)=>{if(ds(!1),X){L(x),ee($m(x));return}ea(x,x)},[ea]),Ja=o.useMemo(()=>ki(l,ct,x=>[x.host,x.sshCommand]),[l,ct]),Ui=o.useCallback(x=>{const X=(x||"").trim();if(!X){E.error(t("settings.remoteInstances.page.toast.instanceUrlUnavailable"));return}pi(X)},[t]),Qa=o.useCallback(async()=>{const x=M,X=J.trim();if(x){if(!X){E.error(t("settings.remoteInstances.page.toast.destinationRequired"));return}le(!0);try{await ea(x,X)&&(L(null),ee(""))}finally{le(!1)}}},[ea,J,M,t]),sa=o.useCallback(async()=>{if(j)try{await N(j.id);return}catch(x){if(!Lm(x)||!window.confirm(t("settings.remoteInstances.sidebar.confirm.localPortInUseRetry")))throw x;const Te={...j,localForward:{...j.localForward,preferredLocalPort:wi()}};await f(Te),await N(Te.id),E.success(t("settings.remoteInstances.sidebar.toast.retriedWithRandomPort"))}},[N,j,t,f]),gn=o.useRef(null),Rn=o.useRef(null),Na=o.useCallback(async x=>{if(j){if(x==="localPort"){const X={...j,localForward:{...j.localForward,preferredLocalPort:wi()}};try{await f(X),await N(X.id),E.success(t("settings.remoteInstances.sidebar.toast.retriedWithRandomPort"))}catch(Te){E.error(t("settings.remoteInstances.page.toast.connectFailed"),{description:Te instanceof Error?Te.message:String(Te)})}return}ss(!0),window.setTimeout(()=>{if(x==="uiPassword"){gn.current?.focus();return}Rn.current?.scrollIntoView({block:"center"})},0)}},[N,j,t,f]),vn=o.useCallback(async x=>(await Mc(x,600)).map(Te=>Hm(Te)),[]),na=o.useCallback(async()=>{if(h){T(!0),D(!0),B(null);try{const x=await vn(h.id);G(x)}catch(x){G([]),B(x instanceof Error?x.message:String(x))}finally{D(!1)}}},[h,vn]);o.useEffect(()=>{if(!F||!h)return;let x=!1;const X=async()=>{try{const Qe=await vn(h.id);x||(G(Qe),B(null))}catch(Qe){x||B(Qe instanceof Error?Qe.message:String(Qe))}};X();const Te=window.setInterval(()=>{typeof document<"u"&&document.visibilityState!=="visible"||X()},1e3);return()=>{x=!0,window.clearInterval(Te)}},[h,F,vn]);const ce=o.useMemo(()=>k.join(`
|
|
27
|
+
`),[k]),ls=o.useCallback(()=>{if(!ce.trim()){E.error(t("settings.remoteInstances.page.toast.noLogsToCopy"));return}Ka(ce).then(x=>{x.ok&&E.success(t("settings.remoteInstances.page.toast.logsCopied"))})},[ce,t]),aa=o.useCallback(async()=>{if(h)try{await Rc(h.id),G([]),E.success(t("settings.remoteInstances.page.toast.logsCleared"))}catch(x){E.error(t("settings.remoteInstances.page.toast.clearLogsFailed"),{description:x instanceof Error?x.message:String(x)})}},[h,t]),Ya=o.useCallback(async()=>{if(!js?.localUrl){E.error(t("settings.remoteInstances.page.toast.instanceUrlUnavailable"));return}const x=js.localUrl.trim();if(!x){E.error(t("settings.remoteInstances.page.toast.instanceUrlUnavailable"));return}pi(x)},[js?.localUrl,t]),Za=o.useCallback(()=>{if(!h)return;if(!Xs&&h.remoteOpenchamber.mode==="external"&&!h.remoteOpenchamber.preferredPort){E.error(t("settings.remoteInstances.page.validation.externalPortRequired")),ss(!0);return}if(!Xs&&h.remoteOpenchamber.mode==="managed"&&h.remoteOpenchamber.bindHost==="0.0.0.0"&&!h.auth.aiworkerPassword?.value?.trim()){E.error(t("settings.remoteInstances.page.validation.remoteLanNeedsPassword")),ss(!0),window.setTimeout(()=>gn.current?.focus(),0);return}K(!0),(Xs?m(h.id):sa()).catch(X=>{const Te=Xs?Zn?"settings.remoteInstances.page.toast.disconnectFailed":"settings.remoteInstances.page.toast.cancelConnectionFailed":"settings.remoteInstances.page.toast.connectFailed";E.error(t(Te),{description:X instanceof Error?X.message:String(X)})}).finally(()=>{K(!1)})},[Xs,sa,m,h,Zn,t]),Xa=o.useCallback(()=>{if(!h||xn)return;Y(!0),(mn?m(h.id).then(()=>sa()):A(h.id)).catch(X=>{E.error(t("settings.remoteInstances.page.toast.retryFailed"),{description:X instanceof Error?X.message:String(X)})}).finally(()=>{Y(!1)})},[sa,m,h,xn,mn,A,t]),ei=t(xn?"settings.remoteInstances.page.actions.connecting":mn?Dn?"settings.remoteInstances.page.actions.reconnectNow":"settings.remoteInstances.page.actions.reconnecting":"settings.remoteInstances.sidebar.actions.retry"),ti=!z&&!te&&(Ws==="error"||Ws==="idle"||!Ws||mn&&Dn)&&!xn,_i=t(Zn?"settings.remoteInstances.sidebar.actions.disconnect":Xs?"settings.remoteInstances.page.actions.cancel":"settings.remoteInstances.sidebar.actions.connect");if(!h)return s.jsxs(es,{title:t("settings.page.remoteInstances.title"),children:[a?s.jsxs(ze,{title:t("settings.remoteInstances.clientAuth.title"),info:t("settings.remoteInstances.clientAuth.description"),divider:!1,settingsItem:"remote-instances.client-auth",contentClassName:"space-y-3",children:[s.jsx("div",{children:s.jsxs(V,{type:"button",size:"xs",className:"!font-normal",onClick:()=>{Wa()},children:[s.jsx(O,{name:"add",className:"h-3.5 w-3.5"}),t("settings.remoteInstances.clientAuth.actions.addDevice")]})}),s.jsxs("div",{className:"space-y-2.5",children:[gs>0?s.jsx("div",{className:"flex justify-end",children:s.jsx(V,{type:"button",variant:"ghost",size:"xs",className:"!font-normal",onClick:()=>{qa()},children:t("settings.remoteInstances.clientAuth.actions.clearRevoked")})}):null,nt&&pt.length===0&&W.length===0?s.jsx("p",{className:"typography-meta text-muted-foreground",children:t("settings.remoteInstances.clientAuth.state.loading")}):pt.length===0&&W.length===0?s.jsx("p",{className:"typography-meta text-muted-foreground",children:t("settings.remoteInstances.clientAuth.state.empty")}):s.jsxs(s.Fragment,{children:[W.map(x=>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:x.label||t("settings.remoteInstances.clientAuth.field.labelPlaceholder")}),x.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(V,{type:"button",variant:"ghost",size:"xs",className:"!font-normal",onClick:()=>{Di(x.id)},children:t("settings.common.actions.cancel")})]},`pending-${x.id}`)),pt.map(x=>{const X=x.clientKind==="desktop-local",Te=x.lastUsedAt?Date.parse(x.lastUsedAt):Number.NaN,Qe=!x.revokedAt&&(X||Number.isFinite(Te)&&Date.now()-Te<9e4),Dt=x.revokedAt?t("settings.remoteInstances.clientAuth.state.revoked"):Qe?x.lastTransport==="relay"&&!X?t("settings.remoteInstances.clientAuth.state.connectedRelay"):t("settings.remoteInstances.clientAuth.state.connectedDirect"):Number.isFinite(Te)?t("settings.remoteInstances.clientAuth.lastUsed",{date:Lc(Te,e,{month:"short",day:"numeric",hour:"numeric",minute:"2-digit"})}):t("settings.remoteInstances.clientAuth.neverUsed");return s.jsxs("div",{className:"flex items-center justify-between gap-3 py-1.5",children:[s.jsx("div",{className:"min-w-0",children:s.jsxs("div",{className:"flex min-w-0 flex-wrap items-center gap-x-2 gap-y-0.5",children:[s.jsx("span",{className:xe("h-2 w-2 shrink-0 rounded-full",x.revokedAt?"bg-muted-foreground/20":Qe?"bg-[var(--status-success)]":"bg-muted-foreground/30")}),s.jsx("p",{className:"typography-ui-label text-foreground truncate",children:x.label}),So(x.devicePlatform)?s.jsx("span",{className:"typography-micro text-muted-foreground bg-muted px-1 rounded shrink-0 leading-none pb-px border border-border/50",children:So(x.devicePlatform)}):null,X?s.jsx("span",{className:"typography-micro text-muted-foreground bg-muted px-1 rounded flex-shrink-0 leading-none pb-px border border-border/50",children:t("settings.remoteInstances.clientAuth.state.thisDevice")}):null,s.jsx("span",{className:xe("typography-micro truncate",Qe&&!x.revokedAt?"text-[var(--status-success)]":"text-muted-foreground"),children:Dt})]})}),s.jsx(V,{type:"button",variant:"ghost",size:"xs",className:"!font-normal",onClick:()=>{Li(x)},disabled:!!x.revokedAt,children:t("settings.remoteInstances.clientAuth.actions.revoke")})]},x.id)})]})]}),et?s.jsx("p",{className:"typography-meta text-[var(--status-error)]",children:et}):null]}):null,n?s.jsxs(ze,{title:t("settings.remoteInstances.direct.title"),info:t("settings.remoteInstances.direct.description"),settingsItem:"remote-instances.direct-hosts",contentClassName:"space-y-4",headerAction:s.jsxs("div",{className:"flex shrink-0 items-center gap-2",children:[s.jsx(V,{type:"button",size:"xs",className:"!font-normal",onClick:()=>Ze(!0),disabled:fe,children:t("settings.remoteInstances.direct.import.action")}),s.jsxs(V,{type:"button",variant:"outline",size:"xs",className:"!font-normal",onClick:()=>Ee(!0),disabled:fe,children:[s.jsx(O,{name:"add",className:"h-3.5 w-3.5"}),t("settings.remoteInstances.direct.actions.add")]})]}),children:[s.jsx("div",{className:"space-y-2.5",children:Se?s.jsx("p",{className:"typography-meta text-muted-foreground",children:t("settings.remoteInstances.direct.state.loading")}):de.length===0?s.jsx("p",{className:"typography-meta text-muted-foreground",children:t("settings.remoteInstances.direct.state.empty")}):de.map(x=>{const X=se[x.id],Te=X?X.status==="ok"?"desktopHostSwitcher.status.connected":X.status==="auth"?"desktopHostSwitcher.status.authRequired":X.status==="update-recommended"?"desktopHostSwitcher.status.updateRecommended":X.status==="incompatible"?"desktopHostSwitcher.status.incompatible":X.status==="wrong-service"?"desktopHostSwitcher.status.wrongService":"desktopHostSwitcher.status.unreachable":"desktopHostSwitcher.status.checking",Qe=X?.status==="ok";return s.jsx("div",{className:"py-1.5",children:s.jsxs("div",{className:"flex items-center justify-between gap-3",children:[s.jsxs("div",{className:"min-w-0 space-y-0.5",children:[s.jsxs("div",{className:"flex min-w-0 items-center gap-2",children:[s.jsx("span",{className:xe("h-2 w-2 shrink-0 rounded-full",X?Qe?"bg-[var(--status-success)]":"bg-[var(--status-error)]":"bg-muted-foreground/30 animate-pulse")}),s.jsx("p",{className:"typography-ui-label text-foreground truncate",children:Ia(x.label)}),ue===x.id?s.jsx("span",{className:"typography-micro text-muted-foreground shrink-0",children:t("desktopHostSwitcher.header.default")}):null,s.jsxs("span",{className:xe("typography-micro shrink-0",Qe?"text-[var(--status-success)]":"text-muted-foreground"),children:[t(Te),Qe&&typeof X?.latencyMs=="number"?t("desktopHostSwitcher.status.ping",{ms:Math.max(0,Math.round(X.latencyMs))}):""]})]}),s.jsx("p",{className:xe("typography-micro text-muted-foreground truncate",x.apiUrl&&"font-mono"),children:x.relay&&!x.apiUrl?t("mobile.connect.relay.badge"):Ia(x.apiUrl||x.url)})]}),s.jsxs("div",{className:"flex shrink-0 items-center gap-1",children:[s.jsx(V,{type:"button",variant:"ghost",size:"xs",className:"!font-normal",onClick:()=>{Ei(x.id)},disabled:fe||ue===x.id,"aria-label":t("desktopHostSwitcher.actions.setAsDefaultAria"),children:ue===x.id?s.jsx(O,{name:"star-fill",className:"h-3.5 w-3.5"}):s.jsx(O,{name:"star",className:"h-3.5 w-3.5"})}),x.relay&&!x.apiUrl?null:s.jsxs(V,{type:"button",variant:"ghost",size:"xs",className:"!font-normal",onClick:()=>Ds(x),disabled:fe,children:[s.jsx(O,{name:"pencil",className:"h-3.5 w-3.5"}),t("desktopHostSwitcher.actions.edit")]}),s.jsxs(V,{type:"button",variant:"ghost",size:"xs",className:"!font-normal",onClick:()=>{ns(x.id)},disabled:fe,children:[s.jsx(O,{name:"delete-bin",className:"h-3.5 w-3.5"}),t("settings.common.actions.delete")]})]})]})},x.id)})}),Re?s.jsx("p",{className:"typography-meta text-[var(--status-error)]",children:Re}):null]}):null,n?s.jsx(Kt,{open:Ke,onOpenChange:Ee,children:s.jsxs(zt,{className:"sm:max-w-lg",children:[s.jsxs(_t,{children:[s.jsx($t,{children:t("settings.remoteInstances.direct.actions.add")}),s.jsx(Vt,{children:t("settings.remoteInstances.direct.addDialog.description")})]}),s.jsxs("form",{className:"space-y-3",onSubmit:x=>{x.preventDefault(),Ut()},children:[s.jsx(He,{className:"h-8",value:Ue,onChange:x=>Ne(x.target.value),placeholder:t("settings.remoteInstances.direct.field.labelPlaceholder"),disabled:fe}),s.jsx(He,{className:"h-8",value:Oe,onChange:x=>Ve(x.target.value),placeholder:t("settings.remoteInstances.direct.field.urlPlaceholder"),disabled:fe,autoFocus:!0}),s.jsxs("div",{className:"space-y-1",children:[s.jsx(He,{className:"h-8",value:Ge,onChange:x=>ve(x.target.value),placeholder:t("settings.remoteInstances.direct.field.tokenPlaceholder"),type:"password",disabled:fe}),s.jsx("p",{className:"px-1 typography-micro text-muted-foreground",children:t("settings.remoteInstances.direct.note")})]}),s.jsxs("div",{className:"space-y-2",children:[s.jsxs("div",{className:"flex items-center gap-1.5",children:[s.jsx(Zs,{children:t("settings.remoteInstances.direct.headers.title")}),s.jsx(Jt,{children:t("settings.remoteInstances.direct.headers.description")})]}),Z.map(x=>s.jsxs("div",{className:"flex w-full gap-2",children:[s.jsx(He,{className:"h-8 font-mono text-xs",value:x.name,onChange:X=>ne(Te=>Te.map(Qe=>Qe.id===x.id?{...Qe,name:X.target.value}:Qe)),placeholder:t("settings.remoteInstances.direct.headers.field.namePlaceholder"),disabled:fe}),s.jsx(He,{className:"h-8 font-mono text-xs",value:x.value,onChange:X=>ne(Te=>Te.map(Qe=>Qe.id===x.id?{...Qe,value:X.target.value}:Qe)),placeholder:t("settings.remoteInstances.direct.headers.field.valuePlaceholder"),type:"password",disabled:fe}),s.jsx("button",{type:"button",onClick:()=>ne(X=>X.filter(Te=>Te.id!==x.id)),className:"flex h-8 w-8 flex-shrink-0 items-center justify-center rounded-md text-muted-foreground hover:bg-[var(--status-error-background)] hover:text-[var(--status-error)] focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-[var(--interactive-focus-ring)]","aria-label":t("settings.remoteInstances.direct.headers.removeAria"),disabled:fe,children:s.jsx(O,{name:"close",className:"h-4 w-4"})})]},x.id)),s.jsxs(V,{type:"button",variant:"ghost",size:"xs",className:"!font-normal",onClick:()=>ne(x=>[...x,fr()]),disabled:fe,children:[s.jsx(O,{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(V,{type:"button",variant:"outline",size:"xs",className:"!font-normal",onClick:()=>Ee(!1),disabled:fe,children:t("settings.common.actions.cancel")}),s.jsx(V,{type:"submit",size:"xs",className:"!font-normal",disabled:fe||!Oe.trim(),children:t("settings.remoteInstances.direct.actions.add")})]})]})]})}):null,n?s.jsx(Kt,{open:!!me,onOpenChange:x=>{x||Ie(null)},children:s.jsxs(zt,{className:"sm:max-w-lg",children:[s.jsxs(_t,{children:[s.jsx($t,{children:t("desktopHostSwitcher.actions.edit")}),s.jsx(Vt,{children:t("settings.remoteInstances.direct.description")})]}),s.jsxs("form",{className:"space-y-3",onSubmit:x=>{x.preventDefault(),Ai()},children:[s.jsx(He,{className:"h-8",value:Le,onChange:x=>Xe(x.target.value),placeholder:t("settings.remoteInstances.direct.field.labelPlaceholder"),disabled:fe}),s.jsx(He,{className:"h-8",value:q,onChange:x=>ke(x.target.value),placeholder:t("settings.remoteInstances.direct.field.urlPlaceholder"),disabled:fe,autoFocus:!0}),s.jsx(He,{className:"h-8",value:Pe,onChange:x=>Je(x.target.value),placeholder:t("settings.remoteInstances.direct.field.tokenPlaceholder"),type:"password",disabled:fe}),s.jsxs("div",{className:"space-y-2",children:[s.jsxs("div",{className:"flex items-center gap-1.5",children:[s.jsx(Zs,{children:t("settings.remoteInstances.direct.headers.title")}),s.jsx(Jt,{children:t("settings.remoteInstances.direct.headers.description")})]}),ot.map(x=>s.jsxs("div",{className:"flex w-full gap-2",children:[s.jsx(He,{className:"h-8 font-mono text-xs",value:x.name,onChange:X=>st(Te=>Te.map(Qe=>Qe.id===x.id?{...Qe,name:X.target.value}:Qe)),placeholder:t("settings.remoteInstances.direct.headers.field.namePlaceholder"),disabled:fe}),s.jsx(He,{className:"h-8 font-mono text-xs",value:x.value,onChange:X=>st(Te=>Te.map(Qe=>Qe.id===x.id?{...Qe,value:X.target.value}:Qe)),placeholder:t("settings.remoteInstances.direct.headers.field.valuePlaceholder"),type:"password",disabled:fe}),s.jsx("button",{type:"button",onClick:()=>st(X=>X.filter(Te=>Te.id!==x.id)),className:"flex h-8 w-8 flex-shrink-0 items-center justify-center rounded-md text-muted-foreground hover:bg-[var(--status-error-background)] hover:text-[var(--status-error)] focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-[var(--interactive-focus-ring)]","aria-label":t("settings.remoteInstances.direct.headers.removeAria"),disabled:fe,children:s.jsx(O,{name:"close",className:"h-4 w-4"})})]},x.id)),s.jsxs(V,{type:"button",variant:"ghost",size:"xs",className:"!font-normal",onClick:()=>st(x=>[...x,fr()]),disabled:fe,children:[s.jsx(O,{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(V,{type:"button",variant:"outline",size:"xs",className:"!font-normal",onClick:()=>Ie(null),disabled:fe,children:t("settings.common.actions.cancel")}),s.jsx(V,{type:"submit",size:"xs",className:"!font-normal",disabled:fe,children:t("settings.common.actions.saveChanges")})]})]})]})}):null,n?s.jsx(Kt,{open:je,onOpenChange:Ze,children:s.jsxs(zt,{className:"sm:max-w-lg",children:[s.jsxs(_t,{children:[s.jsx($t,{children:t("settings.remoteInstances.direct.import.action")}),s.jsx(Vt,{children:t("settings.remoteInstances.direct.import.description")})]}),s.jsxs("form",{className:"space-y-3",onSubmit:x=>{x.preventDefault(),Ot()},children:[s.jsx(He,{className:"h-8",value:be,onChange:x=>we(x.target.value),placeholder:t("settings.remoteInstances.direct.import.placeholder"),disabled:fe,autoFocus:!0}),s.jsxs("div",{className:"flex justify-end gap-2",children:[s.jsx(V,{type:"button",variant:"outline",size:"xs",className:"!font-normal",onClick:()=>Ze(!1),disabled:fe,children:t("settings.common.actions.cancel")}),s.jsx(V,{type:"submit",size:"xs",className:"!font-normal",disabled:fe||!be.trim(),children:t("settings.remoteInstances.direct.import.action")})]})]})]})}):null,s.jsx(Kt,{open:Ae,onOpenChange:it,children:s.jsxs(zt,{className:rt==="result"?"sm:max-w-lg":"sm:max-w-md",children:[s.jsxs(_t,{children:[s.jsx($t,{children:t(rt==="result"?"settings.remoteInstances.clientAuth.qrDialogTitle":"settings.remoteInstances.clientAuth.actions.addDevice")}),s.jsx(Vt,{children:t(rt==="result"?"settings.remoteInstances.clientAuth.qrScanHint":"settings.remoteInstances.clientAuth.addDevice.subtitle")})]}),rt==="configure"?s.jsxs("form",{className:"space-y-4",onSubmit:x=>{x.preventDefault(),Mi()},children:[s.jsx(He,{className:"h-8",value:ht,onChange:x=>Lt(x.target.value),placeholder:t("settings.remoteInstances.clientAuth.field.labelPlaceholder"),autoFocus:!0}),s.jsxs("div",{className:"space-y-1.5",children:[s.jsx("p",{className:"typography-ui-label text-foreground",children:t("settings.remoteInstances.clientAuth.addDevice.transportLabel")}),s.jsx("div",{role:"radiogroup","aria-label":t("settings.remoteInstances.clientAuth.addDevice.transportLabel"),className:"space-y-1.5",children:[{key:"relay",label:t("settings.remoteInstances.clientAuth.addDevice.transport.relay"),hint:t("settings.remoteInstances.clientAuth.addDevice.transport.relayHint"),available:!!Ht?.relayAvailable},{key:"lan",label:t("settings.remoteInstances.clientAuth.addDevice.transport.lan"),hint:t("settings.remoteInstances.clientAuth.addDevice.transport.lanHint"),available:!!Ht?.lanUrl},{key:"local",label:t("settings.remoteInstances.clientAuth.addDevice.transport.local"),hint:t("settings.remoteInstances.clientAuth.addDevice.transport.localHint"),available:!!Ht?.localUrl}].map(x=>{const X=Xt===x.key;return s.jsxs("div",{className:xe("flex items-start gap-2 py-0.5",x.available?"cursor-pointer":"opacity-45"),onClick:()=>{x.available&&Os(x.key)},role:"presentation",children:[s.jsx(jr,{checked:X,disabled:!x.available,onChange:()=>Os(x.key),ariaLabel:x.label,className:"mt-0.5"}),s.jsxs("div",{className:"min-w-0",children:[s.jsx("p",{className:xe("typography-ui-label font-normal",X?"text-foreground":"text-foreground/70"),children:x.label}),s.jsx("p",{className:"typography-meta text-muted-foreground",children:x.hint})]})]},x.key)})}),Xt==="lan"?s.jsxs("label",{className:"flex w-fit cursor-pointer items-center gap-2 pt-1",children:[s.jsx(cr,{checked:Wt,onChange:is,ariaLabel:t("settings.remoteInstances.clientAuth.addDevice.fallback.relay")}),s.jsx("span",{className:"typography-meta text-muted-foreground",children:t("settings.remoteInstances.clientAuth.addDevice.fallback.relay")})]}):null,Xt==="relay"&&Ht?.lanUrl?s.jsxs("label",{className:"flex w-fit cursor-pointer items-center gap-2 pt-1",children:[s.jsx(cr,{checked:Wt,onChange:is,ariaLabel:t("settings.remoteInstances.clientAuth.addDevice.fallback.preferLocal")}),s.jsx("span",{className:"typography-meta text-muted-foreground",children:t("settings.remoteInstances.clientAuth.addDevice.fallback.preferLocal")})]}):null]}),et?s.jsx("p",{className:"typography-meta text-[var(--status-error)]",children:et}):null,s.jsxs("div",{className:"flex justify-end gap-2",children:[s.jsx(V,{type:"button",variant:"outline",size:"xs",className:"!font-normal",onClick:()=>it(!1),disabled:Pt,children:t("settings.common.actions.cancel")}),s.jsx(V,{type:"submit",size:"xs",className:"!font-normal",disabled:Pt||!Ht,children:t("settings.remoteInstances.clientAuth.addDevice.create")})]})]}):s.jsxs("div",{className:"space-y-3",children:[wt?s.jsx("div",{className:"flex justify-center",children:s.jsx("img",{src:wt,alt:t("settings.remoteInstances.clientAuth.qrAlt"),className:"w-full max-w-[420px] rounded-md bg-white p-4"})}):null,bt?s.jsxs("div",{className:"flex items-center gap-2 rounded-md border border-[var(--interactive-border)] p-2",children:[s.jsx("code",{className:"min-w-0 flex-1 truncate typography-code text-muted-foreground",children:bt}),s.jsxs(V,{type:"button",variant:"outline",size:"xs",className:"!font-normal shrink-0",onClick:Ri,children:[s.jsx(O,{name:pe?"check":"file-copy",className:xe("h-3.5 w-3.5",pe&&"text-[var(--status-success)]")}),t(pe?"settings.remoteInstances.clientAuth.actions.copied":"settings.common.actions.copyAll")]})]}):null,s.jsx("div",{className:"flex justify-end",children:s.jsx(V,{type:"button",size:"xs",className:"!font-normal",onClick:()=>it(!1),children:t("settings.remoteInstances.clientAuth.addDevice.done")})})]})]})}),n?s.jsx(ze,{title:t("settings.remoteInstances.sidebar.title"),description:t("settings.remoteInstances.sidebar.total",{count:r.length}),headerAction:s.jsxs(V,{type:"button",size:"xs",className:"!font-normal",onClick:Ha,children:[s.jsx(O,{name:"add",className:"h-3.5 w-3.5"}),t("settings.remoteInstances.sidebar.actions.addSshInstance")]}),contentClassName:"space-y-2.5",children:g?s.jsx("p",{className:"typography-meta text-muted-foreground",children:t("settings.remoteInstances.page.state.loadingInstances")}):r.length===0?s.jsx("p",{className:"typography-meta text-muted-foreground",children:l.length===1?t("settings.remoteInstances.page.empty.noInstancesWithOneImport"):l.length>1?t("settings.remoteInstances.page.empty.noInstancesWithImports",{count:l.length}):t("settings.remoteInstances.page.empty.noInstances")}):r.map(x=>{const X=i[x.id],Te=x.nickname?.trim()||x.sshParsed?.destination||x.id,Qe=X?.phase,Dt=Qe==="ready",ks=Io(Qe),us=ks==="error"?X?.detail:void 0;return s.jsxs("div",{className:"space-y-1.5 py-1.5",children:[s.jsxs("div",{className:"flex items-center justify-between gap-3",children:[s.jsxs("div",{className:"min-w-0 space-y-0.5",children:[s.jsxs("div",{className:"flex min-w-0 items-center gap-2",children:[s.jsx("span",{className:`h-2 w-2 rounded-full ${To(Qe)}`}),s.jsx("p",{className:"typography-ui-label text-foreground truncate",children:Te})]}),s.jsxs("p",{className:"typography-micro text-muted-foreground truncate",children:[t(Po(ks)),ks==="connecting"?` · ${t(Co(Qe))}`:"",Dt&&X?.localUrl?` · ${X.localUrl}`:""]})]}),s.jsxs("div",{className:"flex shrink-0 items-center gap-1",children:[Dt?s.jsxs(V,{type:"button",variant:"ghost",size:"xs",className:"!font-normal",onClick:()=>Ui(X?.localUrl),children:[s.jsx(O,{name:"external-link",className:"h-3.5 w-3.5"}),t("settings.remoteInstances.page.actions.open")]}):null,s.jsxs(V,{type:"button",variant:"ghost",size:"xs",className:"!font-normal",onClick:()=>{(Dt?m(x.id):N(x.id)).catch(Ns=>E.error(t(Dt?"settings.remoteInstances.sidebar.toast.disconnectFailed":"settings.remoteInstances.sidebar.toast.connectFailed"),{description:Ns instanceof Error?Ns.message:String(Ns)}))},children:[Dt?s.jsx(O,{name:"stop",className:"h-3.5 w-3.5"}):s.jsx(O,{name:"plug-2",className:"h-3.5 w-3.5"}),t(Dt?"settings.remoteInstances.sidebar.actions.disconnect":"settings.remoteInstances.sidebar.actions.connect")]}),s.jsxs(V,{type:"button",variant:"ghost",size:"xs",className:"!font-normal",onClick:()=>I(x.id),children:[s.jsx(O,{name:"pencil",className:"h-3.5 w-3.5"}),t("desktopHostSwitcher.actions.edit")]}),s.jsxs(V,{type:"button",variant:"ghost",size:"xs",className:"!font-normal",onClick:()=>{window.confirm(t("settings.remoteInstances.page.confirm.removeInstance"))&&v(x.id).catch(Ns=>E.error(t("settings.remoteInstances.page.toast.removeInstanceFailed"),{description:Ns instanceof Error?Ns.message:String(Ns)}))},children:[s.jsx(O,{name:"delete-bin",className:"h-3.5 w-3.5"}),t("settings.common.actions.delete")]})]})]}),us?s.jsx("p",{className:"typography-micro text-[var(--status-error)] break-words",children:us}):null]},x.id)})}):null,n?s.jsx(Kt,{open:hs,onOpenChange:ds,children:s.jsxs(zt,{className:"sm:max-w-lg",children:[s.jsxs(_t,{children:[s.jsx($t,{children:t("settings.remoteInstances.sidebar.actions.addSshInstance")}),s.jsx(Vt,{children:t("settings.remoteInstances.page.addDialog.description")})]}),s.jsx(Ys,{value:Es,onChange:oe,"aria-label":t("settings.remoteInstances.page.addDialog.sourceLabel"),options:[{value:"saved",label:t("settings.remoteInstances.page.addDialog.tab.saved")},{value:"manual",label:t("settings.remoteInstances.page.addDialog.tab.manual")}]}),Es==="saved"?s.jsxs("div",{className:"space-y-2",children:[s.jsx(He,{className:"h-8",value:ct,onChange:x=>xt(x.target.value),placeholder:t("settings.remoteInstances.page.addDialog.searchPlaceholder"),autoFocus:!0}),c?s.jsx("p",{className:"typography-meta text-muted-foreground",children:t("settings.remoteInstances.page.import.loading")}):l.length===0?s.jsx("p",{className:"typography-meta text-muted-foreground",children:t("settings.remoteInstances.page.addDialog.emptySaved")}):Ja.length===0?s.jsx("p",{className:"typography-meta text-muted-foreground",children:t("settings.remoteInstances.page.addDialog.searchEmpty")}):s.jsx("div",{className:"max-h-[45vh] overflow-auto",children:Ja.map(x=>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:[x.host,x.pattern?` ${t("settings.remoteInstances.page.import.patternSuffix")}`:""]}),s.jsx("div",{className:"typography-meta text-muted-foreground truncate",children:x.sshCommand})]}),s.jsx(V,{type:"button",variant:"outline",size:"xs",className:"!font-normal",onClick:()=>{zi(x.host,x.pattern)},children:t("settings.remoteInstances.page.addDialog.use")})]},`${x.source}:${x.host}`))})]}):s.jsxs("form",{className:"space-y-3",onSubmit:x=>{x.preventDefault(),Ti()},children:[s.jsx(He,{className:"h-8",value:Bt,onChange:x=>rs(x.target.value),placeholder:t("settings.remoteInstances.page.field.nicknamePlaceholder"),disabled:y}),s.jsx(He,{className:"h-8",value:Qt,onChange:x=>Yt(x.target.value),placeholder:t("settings.remoteInstances.page.field.sshCommandPlaceholder"),disabled:y,autoFocus:!0}),s.jsxs("div",{className:"flex justify-end gap-2",children:[s.jsx(V,{type:"button",variant:"outline",size:"xs",className:"!font-normal",onClick:()=>ds(!1),disabled:y,children:t("settings.common.actions.cancel")}),s.jsx(V,{type:"submit",size:"xs",className:"!font-normal",disabled:y||!Qt.trim(),children:t("settings.common.actions.create")})]})]})]})}):null,s.jsx(Kt,{open:!!M,onOpenChange:x=>{x||ta()},children:s.jsxs(zt,{className:"sm:max-w-md",children:[s.jsxs(_t,{children:[s.jsx($t,{children:t("settings.remoteInstances.page.patternDialog.title")}),s.jsx(Vt,{children:M?t("settings.remoteInstances.page.patternDialog.descriptionWithHost",{host:M}):t("settings.remoteInstances.page.patternDialog.description")})]}),s.jsxs("form",{className:"space-y-3",onSubmit:x=>{x.preventDefault(),Qa()},children:[s.jsx(He,{value:J,onChange:x=>ee(x.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(V,{type:"button",variant:"outline",size:"xs",className:"!font-normal",onClick:ta,disabled:U,children:t("settings.common.actions.cancel")}),s.jsx(V,{type:"submit",size:"xs",className:"!font-normal",disabled:U,children:t("settings.remoteInstances.page.actions.create")})]})]})]})})]});const en=h.remoteOpenchamber.mode==="managed",yn=en&&h.remoteOpenchamber.bindHost==="0.0.0.0",ia=yn&&!h.auth.aiworkerPassword?.value?.trim(),$i=h.nickname?.trim()||h.sshParsed?.destination||h.id;return s.jsx(Kt,{open:!!h,onOpenChange:x=>{x||I(null)},children:s.jsxs(zt,{className:"sm:max-w-4xl max-h-[90vh] overflow-auto",children:[s.jsxs("div",{className:"mb-6 px-1",children:[s.jsx("h1",{className:`${lr} truncate`,children:$i}),s.jsxs("div",{className:"mt-1 flex flex-wrap items-center gap-2 typography-meta text-muted-foreground",children:[s.jsx("span",{className:`h-2.5 w-2.5 rounded-full ${To(Ws)}`}),s.jsx("span",{className:"text-foreground",children:t(Po(Xn))}),Xn==="connecting"?s.jsx("span",{children:t(Co(Ws))}):null,js?.localUrl?s.jsx("span",{className:"font-mono text-foreground/80",children:js.localUrl}):null,Dn?s.jsx("span",{children:t("settings.remoteInstances.page.status.reconnectStale")}):null]})]}),s.jsxs(ze,{title:t("settings.remoteInstances.page.section.actions"),info:t("settings.remoteInstances.page.section.actionsDescription"),divider:!1,contentClassName:"space-y-3",children:[s.jsxs("div",{className:"flex flex-wrap items-center gap-2",children:[s.jsxs(V,{type:"button",variant:Xs?"outline":"default",size:"xs",className:"!font-normal",onClick:Za,disabled:z||te,children:[Xs?s.jsx(O,{name:"stop",className:"h-3.5 w-3.5"}):s.jsx(O,{name:"plug-2",className:"h-3.5 w-3.5"}),_i]}),s.jsxs(V,{type:"button",variant:"outline",size:"xs",className:"!font-normal",onClick:Xa,disabled:!ti,children:[s.jsx(O,{name:"refresh",className:`h-3.5 w-3.5 ${xn||mn&&!Dn?"animate-spin":""}`}),ei]}),s.jsxs(V,{type:"button",variant:"outline",size:"xs",className:"!font-normal",onClick:()=>{na()},children:[s.jsx(O,{name:"terminal-window",className:"h-3.5 w-3.5"}),t("settings.remoteInstances.page.actions.logs")]}),s.jsxs(V,{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"))&&v(h.id).then(()=>{I(null),E.success(t("settings.remoteInstances.page.toast.instanceRemoved"))}).catch(X=>{E.error(t("settings.remoteInstances.page.toast.removeInstanceFailed"),{description:X instanceof Error?X.message:String(X)})})},children:[s.jsx(O,{name:"delete-bin",className:"h-3.5 w-3.5"}),t("settings.remoteInstances.sidebar.actions.remove")]})]}),Xn==="error"&&js?.detail?s.jsxs("div",{className:"space-y-2 rounded-md border border-[var(--status-error)]/30 bg-[var(--status-error-background)] p-3",children:[s.jsx("p",{className:"typography-meta text-[var(--status-error)] break-words",children:js.detail}),ka?s.jsx("p",{className:"typography-micro text-muted-foreground",children:t(ka)}):null,Mn&&!ka?s.jsx(V,{type:"button",variant:"outline",size:"xs",className:"!font-normal",onClick:()=>{Na(Mn)},children:t(Mn==="uiPassword"?"settings.remoteInstances.page.error.action.setUiPassword":Mn==="localPort"?"settings.remoteInstances.page.error.action.pickRandomPort":"settings.remoteInstances.page.error.action.setRemotePort")}):null]}):null,js?.localUrl?s.jsxs("div",{className:"flex flex-wrap items-center gap-2 typography-meta text-muted-foreground",children:[s.jsx("span",{children:t("settings.remoteInstances.page.status.currentLocalUrl")}),s.jsx("span",{className:"font-mono text-foreground/90",children:js.localUrl})]}):null]}),s.jsxs(ze,{title:t("settings.remoteInstances.page.section.instance"),info:t("settings.remoteInstances.page.section.instanceDescription"),contentClassName:"space-y-3",children:[s.jsxs("div",{className:"flex flex-col gap-1.5 py-1.5 md:flex-row md:items-center md:gap-8",children:[s.jsx("span",{className:"typography-ui-label text-foreground w-56 shrink-0",children:t("settings.remoteInstances.page.field.sshCommand")}),s.jsx(He,{className:"h-7 md:max-w-xl",value:h.sshCommand,onChange:x=>os(X=>({...X,sshCommand:x.target.value})),placeholder:t("settings.remoteInstances.page.field.sshCommandPlaceholder")})]}),s.jsxs("div",{className:"flex flex-col gap-1.5 py-1.5 md:flex-row md:items-center md:gap-8",children:[s.jsx("span",{className:"typography-ui-label text-foreground w-56 shrink-0",children:t("settings.remoteInstances.page.field.nickname")}),s.jsx(He,{className:"h-7 md:max-w-sm",value:h.nickname||"",onChange:x=>os(X=>({...X,nickname:x.target.value})),placeholder:t("settings.remoteInstances.page.field.nicknamePlaceholder")})]}),s.jsxs("div",{className:"flex flex-col gap-1.5 py-1.5 md:flex-row md:items-center md:gap-8",children:[s.jsx("div",{className:"w-56 shrink-0",children:s.jsx(Vs,{label:t("settings.remoteInstances.page.field.mode"),hint:t("settings.remoteInstances.page.field.modeHint")})}),s.jsxs(St,{value:h.remoteOpenchamber.mode,onValueChange:x=>os(X=>({...X,remoteOpenchamber:{...X.remoteOpenchamber,mode:x==="external"?"external":"managed"}})),children:[s.jsx(Ct,{size:Ft,className:"w-fit min-w-[140px]",children:s.jsx(Mt,{placeholder:t("settings.remoteInstances.page.field.modePlaceholder")})}),s.jsxs(It,{children:[s.jsx(at,{value:"managed",children:t("settings.remoteInstances.page.field.modeManaged")}),s.jsx(at,{value:"external",children:t("settings.remoteInstances.page.field.modeExternal")})]})]})]})]}),s.jsxs(An,{open:ws,onOpenChange:ss,children:[s.jsxs(Tn,{className:"mt-6 w-auto justify-start gap-1.5",children:[s.jsx("span",{className:Sl,children:t("settings.remoteInstances.page.section.advanced")}),s.jsx(O,{name:ws?"arrow-up-s":"arrow-down-s",className:"h-4 w-4 text-muted-foreground"})]}),s.jsxs(En,{children:[s.jsx("p",{className:"px-2 pb-2 typography-micro text-muted-foreground",children:t("settings.remoteInstances.page.section.advancedHint")}),s.jsxs("div",{className:"flex flex-col gap-1.5 px-2 py-1.5 md:flex-row md:items-center md:gap-8",children:[s.jsx("span",{className:"typography-ui-label text-foreground w-56 shrink-0",children:t("settings.remoteInstances.page.field.connectionTimeoutSeconds")}),s.jsx(xs,{containerClassName:"w-fit",min:5,max:240,step:1,className:xe(Ps,"tabular-nums"),value:h.connectionTimeoutSec,onValueChange:x=>{os(X=>({...X,connectionTimeoutSec:Number.isFinite(x)?x:X.connectionTimeoutSec}))}})]}),s.jsxs(ze,{title:t("settings.remoteInstances.page.section.remoteServer"),info:t("settings.remoteInstances.page.section.remoteServerDescription"),contentClassName:"space-y-3",children:[s.jsxs("div",{className:"flex flex-col gap-1.5 py-1.5 md:flex-row md:items-center md:gap-8",children:[s.jsx("div",{className:"w-56 shrink-0",ref:Rn,children:s.jsx(Vs,{label:t("settings.remoteInstances.page.field.preferredRemotePort"),hint:t("settings.remoteInstances.page.field.preferredRemotePortHint")})}),s.jsx(xs,{containerClassName:"w-fit",min:1,max:65535,step:1,className:xe(Ps,"tabular-nums"),value:h.remoteOpenchamber.preferredPort,onValueChange:x=>{os(X=>({...X,remoteOpenchamber:{...X.remoteOpenchamber,preferredPort:Number.isFinite(x)&&x>0?x:void 0}}))},onClear:()=>{os(x=>({...x,remoteOpenchamber:{...x.remoteOpenchamber,preferredPort:void 0}}))},emptyLabel:t("settings.remoteInstances.page.field.auto")})]}),en?s.jsxs("div",{className:"flex flex-col gap-1.5 py-1.5 md:flex-row md:items-center md:gap-8",children:[s.jsx("div",{className:"w-56 shrink-0",children:s.jsx(Vs,{label:t("settings.remoteInstances.page.field.installMethod"),hint:t("settings.remoteInstances.page.field.installMethodHint")})}),s.jsxs(St,{value:h.remoteOpenchamber.installMethod,onValueChange:x=>os(X=>({...X,remoteOpenchamber:{...X.remoteOpenchamber,installMethod:x==="npm"||x==="bun"?x:"auto"}})),children:[s.jsx(Ct,{size:Ft,className:"w-fit min-w-[140px]",children:s.jsx(Mt,{placeholder:t("settings.remoteInstances.page.field.selectInstallMethodPlaceholder")})}),s.jsxs(It,{children:[s.jsx(at,{value:"auto",children:t("settings.remoteInstances.page.field.installMethodAuto")}),s.jsx(at,{value:"bun",children:"bun"}),s.jsx(at,{value:"npm",children:"npm"})]})]})]}):null,en?s.jsxs("div",{className:"py-1.5",children:[s.jsxs("div",{className:"flex flex-col gap-1.5 md:flex-row md:items-center md:gap-8",children:[s.jsx("div",{className:"w-56 shrink-0",children:s.jsx(Vs,{label:t("settings.remoteInstances.page.field.remoteLanAccess"),hint:t("settings.remoteInstances.page.field.remoteLanAccessHint")})}),s.jsx(xi,{checked:yn,onCheckedChange:x=>os(X=>({...X,remoteOpenchamber:{...X.remoteOpenchamber,bindHost:x?"0.0.0.0":"127.0.0.1"}})),"aria-label":t("settings.remoteInstances.page.field.remoteLanAccess")})]}),yn?s.jsx("p",{className:"mt-2 typography-micro text-[var(--status-warning)] md:pl-[16rem]",children:t("settings.remoteInstances.page.field.remoteLanAccessWarning")}):null]}):null,en?s.jsxs("div",{className:"flex flex-col gap-1.5 py-1.5 md:flex-row md:items-center md:gap-8",children:[s.jsx("div",{className:"w-56 shrink-0",children:s.jsx(Vs,{label:t("settings.remoteInstances.page.field.keepServerRunning"),hint:t("settings.remoteInstances.page.field.keepServerRunningHint")})}),s.jsx("div",{className:"flex w-full items-center gap-2 md:max-w-xs",children:s.jsx(xi,{checked:h.remoteOpenchamber.keepRunning,onCheckedChange:x=>os(X=>({...X,remoteOpenchamber:{...X.remoteOpenchamber,keepRunning:x}}))})})]}):null]}),s.jsxs(ze,{title:t("settings.remoteInstances.page.section.mainTunnel"),info:t("settings.remoteInstances.page.section.mainTunnelDescription"),contentClassName:"space-y-3",children:[s.jsxs("div",{className:"flex flex-col gap-1.5 py-1.5 md:flex-row md:items-center md:gap-8",children:[s.jsx("div",{className:"w-56 shrink-0",children:s.jsx(Vs,{label:t("settings.remoteInstances.page.field.bindHost"),hint:t("settings.remoteInstances.page.field.bindHostHint")})}),s.jsxs(St,{value:h.localForward.bindHost,onValueChange:x=>{x==="0.0.0.0"&&!window.confirm(t("settings.remoteInstances.page.confirm.bindAllInterfaces"))||os(X=>({...X,localForward:{...X.localForward,bindHost:x==="localhost"||x==="0.0.0.0"?x:"127.0.0.1"}}))},children:[s.jsx(Ct,{size:Ft,className:"w-fit min-w-[240px]",children:s.jsx(Mt,{placeholder:t("settings.remoteInstances.page.field.selectBindHostPlaceholder")})}),s.jsxs(It,{children:[s.jsx(at,{value:"127.0.0.1",children:t("settings.remoteInstances.page.field.bindHostOption.loopback")}),s.jsx(at,{value:"localhost",children:t("settings.remoteInstances.page.field.bindHostOption.localhost")}),s.jsx(at,{value:"0.0.0.0",children:t("settings.remoteInstances.page.field.bindHostOption.lan")})]})]})]}),s.jsxs("div",{className:"flex flex-col gap-1.5 py-1.5 md:flex-row md:items-center md:gap-8",children:[s.jsx("div",{className:"w-56 shrink-0",children:s.jsx(Vs,{label:t("settings.remoteInstances.page.field.preferredLocalPort"),hint:t("settings.remoteInstances.page.field.preferredLocalPortHint")})}),s.jsxs("div",{className:"flex w-full items-center gap-2 md:max-w-sm",children:[s.jsx(xs,{containerClassName:"w-fit",min:1,max:65535,step:1,className:xe(Ps,"tabular-nums"),value:h.localForward.preferredLocalPort,onValueChange:x=>{os(X=>({...X,localForward:{...X.localForward,preferredLocalPort:Number.isFinite(x)&&x>0?x:void 0}}))},onClear:()=>{os(x=>({...x,localForward:{...x.localForward,preferredLocalPort:void 0}}))},emptyLabel:t("settings.remoteInstances.page.field.auto")}),s.jsx(V,{type:"button",variant:"outline",size:"xs",className:"!font-normal h-7 w-7 px-0",title:t("settings.remoteInstances.page.actions.pickRandomPort"),onClick:()=>os(x=>({...x,localForward:{...x.localForward,preferredLocalPort:wi()}})),children:s.jsx(O,{name:"shuffle",className:"h-3.5 w-3.5"})})]})]}),s.jsxs("div",{className:"space-y-1 pt-1",children:[s.jsx("p",{className:"typography-micro text-muted-foreground",children:t("settings.remoteInstances.page.tunnelPreview.caption")}),s.jsx("p",{className:"typography-micro font-mono text-foreground/80 break-all",children:`${h.localForward.bindHost}:${h.localForward.preferredLocalPort||"auto"} → ${h.sshParsed?.destination||h.nickname||"remote"}:${h.remoteOpenchamber.preferredPort||"auto"}`})]})]}),s.jsxs(ze,{title:t("settings.remoteInstances.page.section.authentication"),info:t("settings.remoteInstances.page.section.authenticationDescription"),contentClassName:"space-y-3",children:[s.jsxs("div",{className:"flex flex-col gap-1.5 py-1.5 md:flex-row md:items-center md:gap-8",children:[s.jsx("div",{className:"w-56 shrink-0",children:s.jsx(Vs,{label:t("settings.remoteInstances.page.field.sshPasswordOptional"),hint:t("settings.remoteInstances.page.field.sshPasswordHint")})}),s.jsx(He,{className:"h-7 md:max-w-sm",type:"password",value:h.auth.sshPassword?.value||"",onChange:x=>os(X=>({...X,auth:{...X.auth,sshPassword:{enabled:x.target.value.trim().length>0,value:x.target.value,store:X.auth.sshPassword?.store||"never"}}})),placeholder:t("settings.remoteInstances.page.field.sshPasswordPlaceholder")})]}),s.jsxs("div",{className:"flex flex-col gap-1.5 py-1.5 md:flex-row md:items-center md:gap-8",children:[s.jsx("div",{className:"w-56 shrink-0",children:s.jsx(Vs,{label:t(yn?"settings.remoteInstances.page.field.uiPasswordRequired":"settings.remoteInstances.page.field.uiPasswordOptional"),hint:t(en?"settings.remoteInstances.page.field.uiPasswordHintManaged":"settings.remoteInstances.page.field.uiPasswordHintExternal")})}),s.jsx(He,{className:xe("h-7 md:max-w-sm",ia&&"border-[var(--status-error)]"),type:"password",ref:gn,"aria-invalid":ia,value:h.auth.aiworkerPassword?.value||"",onChange:x=>os(X=>({...X,auth:{...X.auth,aiworkerPassword:{enabled:x.target.value.trim().length>0,value:x.target.value,store:X.auth.aiworkerPassword?.store||"never"}}})),placeholder:t("settings.remoteInstances.page.field.uiPasswordPlaceholder")})]}),ia?s.jsx("p",{className:"typography-micro text-[var(--status-error)] md:pl-[16rem]",children:t("settings.remoteInstances.page.field.uiPasswordMissingForLan")}):null]}),s.jsxs(ze,{title:t("settings.remoteInstances.page.section.portForwards"),info:t("settings.remoteInstances.page.section.portForwardsDescription"),contentClassName:"space-y-2",children:[h.portForwards.length===0?s.jsx("p",{className:"typography-micro text-muted-foreground/80",children:t("settings.remoteInstances.page.empty.noExtraForwards")}):null,h.portForwards.map((x,X)=>{const Te=kt=>{os(Gt=>({...Gt,portForwards:Gt.portForwards.map((tn,Nt)=>Nt===X?kt(tn):tn)}))},Qe=x.type==="remote"?"Local target":"Local listen",Dt=x.type==="remote"?"Local host and port on your machine that receives traffic from remote -R listener.":"Local host and port where this forward listens on your machine.",ks=x.type==="remote"?"Remote listen":"Remote target",us=x.type==="remote"?"Remote host and port where SSH creates the -R listener.":"Remote host and port that receives traffic from local -L listener.",$s=Eo(x.localHost||"localhost",x.localPort),Ns=Eo(x.remoteHost||"localhost",x.remotePort),qs=x.type==="local"&&typeof x.localPort=="number"&&x.localPort>0,Sa=qs?`http://${Bm(x.localHost)}:${x.localPort}`:"",Ln=!!_[x.id],Ca=x.type==="local"?t("settings.remoteInstances.page.forwardType.local"):x.type==="remote"?t("settings.remoteInstances.page.forwardType.remote"):t("settings.remoteInstances.page.forwardType.dynamic");return s.jsxs(An,{open:Ln,onOpenChange:kt=>{H(Gt=>({...Gt,[x.id]:kt}))},className:`${X>0?"border-t border-[var(--surface-subtle)]":""} py-2`,children:[s.jsxs("div",{className:"flex items-center justify-between gap-2",children:[s.jsx("div",{className:"min-w-0 flex items-center gap-2",children:s.jsxs(Tn,{className:"flex items-center gap-2 group",children:[s.jsx(O,{name:"arrow-down-s",className:`h-4 w-4 text-muted-foreground transition-transform ${Ln?"rotate-180":""}`}),s.jsx("span",{className:"typography-ui-label text-foreground truncate",children:Um(x)}),s.jsx("span",{className:"typography-micro text-muted-foreground/70 shrink-0",children:Ca})]})}),s.jsxs("div",{className:"flex items-center gap-2",children:[s.jsx(xi,{checked:x.enabled,onCheckedChange:kt=>Te(Gt=>({...Gt,enabled:kt})),"aria-label":t("settings.remoteInstances.page.actions.enableForwardAria")}),s.jsx(V,{type:"button",variant:"ghost",size:"xs",className:"!font-normal h-6 w-6 px-0 text-[var(--status-error)] hover:text-[var(--status-error)]",onClick:()=>os(kt=>({...kt,portForwards:kt.portForwards.filter(Gt=>Gt.id!==x.id)})),children:s.jsx(O,{name:"delete-bin",className:"h-3.5 w-3.5"})})]})]}),s.jsx(En,{className:"pt-2",children:s.jsxs("div",{className:"space-y-0 pb-2",children:[s.jsxs("div",{className:"flex flex-col gap-1.5 py-1.5 md:flex-row md:items-center md:gap-8",children:[s.jsx("div",{className:"w-56 shrink-0",children:s.jsx(Vs,{label:t("settings.remoteInstances.page.field.forwardType"),hint:s.jsxs("div",{className:"space-y-1",children:[s.jsx("p",{children:t("settings.remoteInstances.page.field.forwardTypeHint")}),s.jsx("p",{children:t(Vm(x.type))})]})})}),s.jsxs(St,{value:x.type,onValueChange:kt=>Te(Gt=>({...Gt,type:kt==="dynamic"||kt==="remote"?kt:"local"})),children:[s.jsx(Ct,{size:Ft,className:"w-fit min-w-[140px]",children:s.jsx(Mt,{placeholder:t("settings.remoteInstances.page.field.typePlaceholder")})}),s.jsxs(It,{children:[s.jsx(at,{value:"local",children:t("settings.remoteInstances.page.forwardType.local")}),s.jsx(at,{value:"remote",children:t("settings.remoteInstances.page.forwardType.remote")}),s.jsx(at,{value:"dynamic",children:t("settings.remoteInstances.page.forwardType.dynamic")})]})]})]}),s.jsxs("div",{className:"flex flex-col gap-1.5 py-1.5 md:flex-row md:items-center md:gap-8",children:[s.jsx("div",{className:"w-56 shrink-0",children:s.jsx(Vs,{label:Qe,hint:Dt})}),s.jsxs("div",{className:"flex items-center gap-1.5",children:[s.jsx(He,{className:"h-7 w-32",value:x.localHost||"127.0.0.1",onChange:kt=>Te(Gt=>({...Gt,localHost:kt.target.value})),placeholder:t("settings.remoteInstances.page.field.localHostPlaceholder")}),s.jsx("span",{className:"text-muted-foreground",children:":"}),s.jsx(xs,{containerClassName:"w-fit",min:1,max:65535,step:1,className:xe(Ps,"tabular-nums"),value:x.localPort,onValueChange:kt=>{Te(Gt=>({...Gt,localPort:Number.isFinite(kt)&&kt>0?kt:void 0}))},onClear:()=>{Te(kt=>({...kt,localPort:void 0}))},emptyLabel:t("settings.remoteInstances.page.field.auto")})]})]}),x.type!=="dynamic"?s.jsxs("div",{className:"flex flex-col gap-1.5 py-1.5 md:flex-row md:items-center md:gap-8",children:[s.jsx("div",{className:"w-56 shrink-0",children:s.jsx(Vs,{label:ks,hint:us})}),s.jsxs("div",{className:"flex items-center gap-1.5",children:[s.jsx(He,{className:"h-7 w-32",value:x.remoteHost||"",onChange:kt=>Te(Gt=>({...Gt,remoteHost:kt.target.value})),placeholder:t("settings.remoteInstances.page.field.remoteHostPlaceholder")}),s.jsx("span",{className:"text-muted-foreground",children:":"}),s.jsx(xs,{containerClassName:"w-fit",min:1,max:65535,step:1,className:xe(Ps,"tabular-nums"),value:x.remotePort,onValueChange:kt=>{Te(Gt=>({...Gt,remotePort:Number.isFinite(kt)&&kt>0?kt:void 0}))},onClear:()=>{Te(kt=>({...kt,remotePort:void 0}))},emptyLabel:t("settings.remoteInstances.page.field.auto")})]})]}):null,s.jsxs("div",{className:"mt-2 flex flex-wrap items-center justify-between gap-2 rounded-md bg-[var(--surface-subtle)] p-2",children:[s.jsx("div",{className:"flex flex-wrap items-center gap-1 typography-micro text-muted-foreground/80",children:x.type==="dynamic"?s.jsxs(s.Fragment,{children:[s.jsx(O,{name:"computer",className:"h-3.5 w-3.5"}),s.jsx("span",{className:"font-mono text-foreground",children:$s}),s.jsx("span",{children:t("settings.remoteInstances.page.preview.localSocks5")})]}):x.type==="remote"?s.jsxs(s.Fragment,{children:[s.jsx(O,{name:"server",className:"h-3.5 w-3.5"}),s.jsx("span",{className:"font-mono text-foreground",children:Ns}),s.jsx("span",{children:t("settings.remoteInstances.page.preview.remote")}),s.jsx(O,{name:"arrow-right",className:"h-3.5 w-3.5"}),s.jsx(O,{name:"computer",className:"h-3.5 w-3.5"}),s.jsx("span",{className:"font-mono text-foreground",children:$s}),s.jsx("span",{children:t("settings.remoteInstances.page.preview.local")})]}):s.jsxs(s.Fragment,{children:[s.jsx(O,{name:"computer",className:"h-3.5 w-3.5"}),s.jsx("span",{className:"font-mono text-foreground",children:$s}),s.jsx("span",{children:t("settings.remoteInstances.page.preview.local")}),s.jsx(O,{name:"arrow-right",className:"h-3.5 w-3.5"}),s.jsx(O,{name:"server",className:"h-3.5 w-3.5"}),s.jsx("span",{className:"font-mono text-foreground",children:Ns}),s.jsx("span",{children:t("settings.remoteInstances.page.preview.remote")})]})}),qs?s.jsxs(V,{type:"button",variant:"outline",size:"xs",className:"!font-normal",onClick:()=>{Pn(Sa).then(kt=>{kt||E.error(t("settings.remoteInstances.page.toast.openLocalEndpointFailed"))})},children:[s.jsx(O,{name:"external-link",className:"h-3.5 w-3.5"}),t("settings.remoteInstances.page.actions.openLocal")]}):null]})]})})]},x.id)}),s.jsxs(V,{type:"button",variant:"outline",size:"xs",className:"!font-normal mt-1",onClick:()=>{const x=_m();os(X=>({...X,portForwards:[...X.portForwards,x]})),H(X=>({...X,[x.id]:!0}))},children:[s.jsx(O,{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(V,{type:"button",size:"xs",className:"!font-normal",onClick:()=>{Ki()},disabled:!Fi||y,children:t("settings.common.actions.saveChanges")}),js?.localUrl?s.jsxs(s.Fragment,{children:[s.jsxs(V,{type:"button",variant:"outline",size:"xs",className:"!font-normal",onClick:()=>{Ka(js.localUrl||"").then(x=>{x.ok&&E.success(t("settings.remoteInstances.page.toast.localUrlCopied"))})},children:[s.jsx(O,{name:"file-copy",className:"h-3.5 w-3.5"}),t("settings.remoteInstances.page.actions.copyLocalUrl")]}),s.jsxs(V,{type:"button",variant:"outline",size:"xs",className:"!font-normal",onClick:()=>{Ya()},children:[s.jsx(O,{name:"external-link",className:"h-3.5 w-3.5"}),t("settings.remoteInstances.page.actions.open")]})]}):null,p?s.jsx("div",{className:"ml-auto typography-meta text-[var(--status-error)]",children:p}):null]})}),s.jsx(Kt,{open:F,onOpenChange:T,children:s.jsxs(zt,{className:"sm:max-w-2xl",children:[s.jsxs(_t,{children:[s.jsx($t,{children:t("settings.remoteInstances.page.logsDialog.title")}),s.jsx(Vt,{children:h?.nickname?.trim()||h?.sshParsed?.destination||h?.id||t("settings.remoteInstances.page.logsDialog.selectedInstanceFallback")})]}),s.jsxs("div",{className:"flex items-center justify-end gap-2",children:[s.jsxs(V,{type:"button",variant:"outline",size:"xs",className:"!font-normal",onClick:ls,disabled:S||!ce.trim(),children:[s.jsx(O,{name:"file-copy",className:"h-3.5 w-3.5"}),t("settings.common.actions.copyAll")]}),s.jsxs(V,{type:"button",variant:"outline",size:"xs",className:"!font-normal",onClick:()=>{aa()},disabled:S,children:[s.jsx(O,{name:"delete-bin",className:"h-3.5 w-3.5"}),t("settings.common.actions.clear")]})]}),S?s.jsx("div",{className:"typography-meta text-muted-foreground",children:t("settings.remoteInstances.page.logsDialog.loading")}):$?s.jsx("div",{className:"typography-meta text-[var(--status-error)]",children:$}):s.jsx("pre",{className:"max-h-[55vh] overflow-auto rounded-md border border-[var(--interactive-border)] bg-[var(--surface-elevated)] p-3 typography-micro text-foreground whitespace-pre-wrap break-words",children:k.length>0?k.join(`
|
|
28
|
+
`):t("settings.remoteInstances.page.logsDialog.empty")})]})}),s.jsx(Kt,{open:!!M,onOpenChange:x=>{x||ta()},children:s.jsxs(zt,{className:"sm:max-w-md",children:[s.jsxs(_t,{children:[s.jsx($t,{children:t("settings.remoteInstances.page.patternDialog.title")}),s.jsx(Vt,{children:M?t("settings.remoteInstances.page.patternDialog.descriptionWithHost",{host:M}):t("settings.remoteInstances.page.patternDialog.description")})]}),s.jsxs("form",{className:"space-y-3",onSubmit:x=>{x.preventDefault(),Qa()},children:[s.jsx(He,{value:J,onChange:x=>ee(x.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(V,{type:"button",variant:"outline",size:"xs",className:"!font-normal",onClick:ta,disabled:U,children:t("settings.common.actions.cancel")}),s.jsx(V,{type:"submit",size:"xs",className:"!font-normal",disabled:U,children:t("settings.common.actions.create")})]})]})]})})]})})},Ym="__add_provider__",Zm=()=>{const t=fn.getDirectory();return typeof t=="string"&&t.trim().length>0?t.trim():null},Xm=({onItemSelect:t})=>{const{t:e}=tt(),a=_s(),n=Ye(f=>Cl(f,a)),r=Ye(f=>f.selectedProviderId),i=Ye(f=>f.setSelectedProvider),l=Gs(f=>f.activeProjectId),[g,c]=o.useState({}),y=o.useMemo(()=>a||Zm(),[l,a]),p=Ye(f=>f.loadProviders);o.useEffect(()=>{a&&p({directory:a,source:"settings:providers"})},[p,a]),o.useEffect(()=>{if(n.length===0){c({});return}let f=!1;return(async()=>{const v=n.map(async N=>{try{const m=y?`?directory=${encodeURIComponent(y)}`:"",A=await yt(`/api/provider/${encodeURIComponent(N.id)}/source${m}`,{method:"GET",headers:{Accept:"application/json"}});if(!A.ok)return;const R=await A.json().catch(()=>null),I=R?.sources??R?.data?.sources;if(!I||f)return;c(j=>({...j,[N.id]:I}))}catch{}});await Promise.all(v)})(),()=>{f=!0}},[y,n]);const b="bg-background",d=o.useMemo(()=>n.filter(f=>!!g[f.id]?.project?.exists),[n,g]),P=o.useMemo(()=>n.filter(f=>!g[f.id]?.project?.exists),[n,g]);return s.jsxs("div",{className:xe("flex h-full flex-col",b),children:[s.jsxs("div",{className:"border-b px-3 pt-4 pb-3",children:[s.jsx("h2",{className:`${un} mb-3`,children:e("settings.providers.sidebar.title")}),s.jsx(Ba,{className:"mb-3"}),s.jsxs("div",{className:"flex items-center justify-between gap-2",children:[s.jsx("span",{className:"typography-meta text-muted-foreground",children:e("settings.providers.sidebar.total",{count:n.length})}),s.jsx(V,{size:"sm",variant:"ghost",className:"h-7 w-7 px-0 -my-1 text-muted-foreground",onClick:()=>{i(Ym),t?.()},"aria-label":e("settings.providers.sidebar.actions.connectProviderAria"),title:e("settings.providers.sidebar.actions.connectProviderTitle"),children:s.jsx(O,{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(O,{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:[P.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")}),P.map(f=>s.jsx(Mo,{provider:f,selectedProviderId:r,onSelect:()=>{i(f.id),t?.()}},f.id))]}),d.length>0&&s.jsxs(s.Fragment,{children:[s.jsx("div",{className:xe("px-2 pb-1.5 text-xs font-semibold uppercase tracking-wide text-muted-foreground",P.length>0?"pt-3":"pt-2"),children:e("settings.providers.sidebar.section.projectProviders")}),d.map(f=>s.jsx(Mo,{provider:f,selectedProviderId:r,onSelect:()=>{i(f.id),t?.()}},f.id))]})]})})]})},Mo=t=>{const e=ut.c(17),{provider:a,selectedProviderId:n,onSelect:r}=t,i=Array.isArray(a.models)?a.models.length:0,l=a.id===n,g=a.id,c=l?"bg-interactive-selection":"hover:bg-interactive-hover";let y;e[0]!==c?(y=xe("group relative flex items-center rounded-md px-1.5 py-1 transition-all duration-200",c),e[0]=c,e[1]=y):y=e[1];let p;e[2]!==a.id?(p=s.jsx(Un,{providerId:a.id,className:"h-4 w-4 flex-shrink-0"}),e[2]=a.id,e[3]=p):p=e[3];const b=a.name||a.id;let d;e[4]!==b?(d=s.jsx("span",{className:"typography-ui-label font-normal truncate flex-1 min-w-0 text-foreground",children:b}),e[4]=b,e[5]=d):d=e[5];let P;e[6]!==i?(P=s.jsx("span",{className:"typography-micro text-muted-foreground/60 flex-shrink-0",children:i}),e[6]=i,e[7]=P):P=e[7];let f;e[8]!==r||e[9]!==p||e[10]!==d||e[11]!==P?(f=s.jsxs("button",{type:"button",onClick:r,className:"flex min-w-0 flex-1 items-center gap-2 rounded-sm text-left focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-primary/50",tabIndex:0,children:[p,d,P]}),e[8]=r,e[9]=p,e[10]=d,e[11]=P,e[12]=f):f=e[12];let C;return e[13]!==a.id||e[14]!==y||e[15]!==f?(C=s.jsx("div",{className:y,children:f},g),e[13]=a.id,e[14]=y,e[15]=f,e[16]=C):C=e[16],C},eg=t=>t,tg=(t,e,a)=>t&&!e&&!a,Ro=t=>typeof t=="object"&&t!==null,Ql=t=>{const e=typeof t.type=="string"?t.type:"",a=`${t.name??""} ${t.label??""}`.toLowerCase(),n=`${e} ${a}`.toLowerCase();return n.includes("oauth")?"oauth":n.includes("api")?"api":e.toLowerCase()},sg=t=>{if(!Ro(t))return{};const e={};for(const[a,n]of Object.entries(t))Array.isArray(n)&&(e[a]=n.filter(r=>Ro(r)));return e},Lo=t=>t.length===0?!0:t.some(e=>Ql(e)==="api"),Oo=t=>t.map((e,a)=>({method:e,methodIndex:a})).filter(({method:e})=>Ql(e)==="oauth"),ng=t=>t!=="claude-code",Fo=t=>typeof t.key=="string"&&t.key.trim().length>0||typeof t.optionsApiKey=="string"&&t.optionsApiKey.trim().length>0||t.envDeclared===!0?!0:t.authSourceExists===!0,ag=t=>t.modelCount>0&&(!t.sourcesLoaded||t.hasCredentials||!!t.isEditableCustomProvider),ig=t=>!t.hasCredentials&&!t.userDismissed&&!t.isEditableCustomProvider,Tr={"openai-chat":"@ai-sdk/openai-compatible","openai-responses":"@ai-sdk/openai","anthropic-messages":"@ai-sdk/anthropic"},Kn="__custom_provider__",rg=/^[a-z0-9][a-z0-9-_]*$/,Yl=/^https?:\/\//,og=/^\{env:([^}]+)\}$/;let lg=0;const Ci=()=>`row-${lg++}`,Er=()=>({row:Ci(),id:"",name:""}),Dr=()=>({row:Ci(),key:"",value:""}),cg=()=>({providerID:"",name:"",protocol:"openai-chat",baseURL:"",apiKey:"",models:[Er()],headers:[Dr()]});function dg(t){switch(t){case"@ai-sdk/openai":return"openai-responses";case"@ai-sdk/anthropic":return"anthropic-messages";default:return"openai-chat"}}function ug(t){const e=t.trim();if(!e)return{};const n=e.match(og)?.[1]?.trim();return n?{env:n}:{key:e}}function pg(t){const e=t.options&&typeof t.options=="object"?t.options:null,a=typeof e?.baseURL=="string"?e.baseURL.trim():"";return a&&Yl.test(a)?!0:(Array.isArray(t.models)?t.models:t.models&&typeof t.models=="object"?Object.values(t.models):[]).some(r=>{if(!r||typeof r!="object")return!1;const i="api"in r&&r.api&&typeof r.api=="object"?r.api:null;return typeof i?.npm=="string"&&new Set(Object.values(Tr)).has(i.npm)})}function Ko(t,e){return e?!!(e.user?.exists||e.project?.exists||e.custom?.exists)&&pg(t):!1}function zo(t){return t?.custom?.exists?"custom":t?.project?.exists?"project":"user"}function mg(t){const e=t.options&&typeof t.options=="object"?t.options:{},a=typeof e.baseURL=="string"?e.baseURL:"",n=e.headers&&typeof e.headers=="object"&&!Array.isArray(e.headers)?e.headers:{},r=Object.entries(n).filter(y=>typeof y[0]=="string"&&typeof y[1]=="string").map(([y,p])=>({row:Ci(),key:y,value:p})),i=Array.isArray(t.models)?t.models:t.models&&typeof t.models=="object"?Object.entries(t.models).map(([y,p])=>({id:y,name:p&&typeof p=="object"&&"name"in p&&typeof p.name=="string"?p.name:y})):[],l=i.length>0?i.map(y=>({row:Ci(),id:typeof y?.id=="string"?y.id:"",name:typeof y?.name=="string"?y.name:typeof y?.id=="string"?y.id:""})):[Er()],g=Array.isArray(t.env)?t.env.find(y=>typeof y=="string"&&y.trim().length>0)?.trim():void 0,c=i.find(y=>"api"in y);return{providerID:t.id,name:typeof t.name=="string"&&t.name.trim()?t.name:t.id,protocol:dg(c?.api?.npm),baseURL:a,apiKey:g?`{env:${g}}`:"",models:l,headers:r.length>0?r:[Dr()]}}function gg(t){const e=t.form.providerID.trim(),a=t.form.name.trim(),n=t.form.baseURL.trim(),{env:r,key:i}=ug(t.form.apiKey),l=t.disabledProviders??[],g=t.editingProviderID?.trim(),c=e?rg.test(e)?void 0:t.t("settings.providers.page.custom.error.providerID.format"):t.t("settings.providers.page.custom.error.providerID.required"),y=a?void 0:t.t("settings.providers.page.custom.error.name.required"),p=n?Yl.test(n)?void 0:t.t("settings.providers.page.custom.error.baseURL.format"):t.t("settings.providers.page.custom.error.baseURL.required"),d=!!(r||i||g&&t.allowExistingAuth&&g===e)?void 0:t.t("settings.providers.page.custom.error.apiKey.required"),P=l.includes(e),C=c||!!(g&&g===e)?void 0:t.existingProviderIDs.has(e)&&!P?t.t("settings.providers.page.custom.error.providerID.exists"):void 0,v=new Set,N=t.form.models.map(T=>{const S=T.id.trim(),D=S?v.has(S)?t.t("settings.providers.page.custom.error.duplicate"):void v.add(S):t.t("settings.providers.page.custom.error.required"),$=T.name.trim()?void 0:t.t("settings.providers.page.custom.error.required");return{id:D,name:$}}),m=N.every(T=>!T.id&&!T.name),A=Object.fromEntries(t.form.models.map(T=>[T.id.trim(),{name:T.name.trim()}])),R=new Set,I=t.form.headers.map(T=>{const S=T.key.trim(),D=T.value.trim();if(!S&&!D)return{};const $=S?R.has(S.toLowerCase())?t.t("settings.providers.page.custom.error.duplicate"):void R.add(S.toLowerCase()):t.t("settings.providers.page.custom.error.required"),B=D?void 0:t.t("settings.providers.page.custom.error.required");return{key:$,value:B}}),j=I.every(T=>!T.key&&!T.value),h=Object.fromEntries(t.form.headers.map(T=>({key:T.key.trim(),value:T.value.trim()})).filter(T=>T.key&&T.value).map(T=>[T.key,T.value])),w={providerID:c??C,name:y,baseURL:p,apiKey:d};return!c&&!C&&!y&&!p&&!d&&m&&j?{err:w,models:N,headers:I,result:{providerID:e,name:a,apiKey:i,config:{npm:Tr[t.form.protocol],name:a,...r?{env:[r]}:{},options:{baseURL:n,...Object.keys(h).length>0?{headers:h}:{}},models:A}}}:{err:w,models:N,headers:I}}function hg(t){return t.apiKey?{providerID:t.providerID,auth:{type:"api",key:t.apiKey}}:null}function fg(t,e){return{providerID:t.providerID,config:t.config,scope:e?.scope??"user"}}const Uo=t=>{const e=ut.c(234),{existingProviderIDs:a,disabledProviders:n,busy:r,mode:i,initialValues:l,allowExistingAuth:g,authFailureHint:c,onSubmit:y,onCancel:p,onDisconnect:b}=t;let d;e[0]!==n?(d=n===void 0?[]:n,e[0]=n,e[1]=d):d=e[1];const P=d,f=r===void 0?!1:r,C=i===void 0?"create":i,v=g===void 0?!1:g,N=c===void 0?null:c,{t:m}=tt(),A=C==="edit";let R;e[2]!==l?(R=()=>l??cg(),e[2]=l,e[3]=R):R=e[3];const[I,j]=o.useState(R);let h;e[4]===Symbol.for("react.memo_cache_sentinel")?(h={},e[4]=h):h=e[4];const[w,F]=o.useState(h);let T;e[5]===Symbol.for("react.memo_cache_sentinel")?(T=[],e[5]=T):T=e[5];const[S,D]=o.useState(T);let $;e[6]===Symbol.for("react.memo_cache_sentinel")?($=[],e[6]=$):$=e[6];const[B,k]=o.useState($),G=o.useRef(null);let M,L;e[7]!==l||e[8]!==A?(M=()=>{l&&(A&&G.current===l.providerID||(G.current=A?l.providerID:null,j(l),F({}),D([]),k([])))},L=[l,A],e[7]=l,e[8]=A,e[9]=M,e[10]=L):(M=e[9],L=e[10]),o.useEffect(M,L);let J;e[11]===Symbol.for("react.memo_cache_sentinel")?(J=(jt,At)=>{j(Ut=>({...Ut,[jt]:At})),F(Ut=>({...Ut,[jt]:void 0}))},e[11]=J):J=e[11];const ee=J;let U;e[12]===Symbol.for("react.memo_cache_sentinel")?(U=(jt,At,Ut)=>{j(Ot=>({...Ot,models:Ot.models.map((ns,Ds)=>Ds===jt?{...ns,[At]:Ut}:ns)})),D(Ot=>{const ns=[...Ot];return ns[jt]={...ns[jt]??{},[At]:void 0},ns})},e[12]=U):U=e[12];const le=U;let _;e[13]===Symbol.for("react.memo_cache_sentinel")?(_=(jt,At,Ut)=>{j(Ot=>({...Ot,headers:Ot.headers.map((ns,Ds)=>Ds===jt?{...ns,[At]:Ut}:ns)})),k(Ot=>{const ns=[...Ot];return ns[jt]={...ns[jt]??{},[At]:void 0},ns})},e[13]=_):_=e[13];const H=_;let z;e[14]!==v||e[15]!==f||e[16]!==P||e[17]!==a||e[18]!==I||e[19]!==A||e[20]!==y||e[21]!==m?(z=async jt=>{if(jt.preventDefault(),f)return;const At=gg({form:I,t:((Ut,Ot)=>m(Ut,Ot)),existingProviderIDs:a,disabledProviders:P,editingProviderID:A?I.providerID:void 0,allowExistingAuth:A&&v});F(At.err),D(At.models),k(At.headers),At.result&&await y(At.result)},e[14]=v,e[15]=f,e[16]=P,e[17]=a,e[18]=I,e[19]=A,e[20]=y,e[21]=m,e[22]=z):z=e[22];const K=z;let te;e[23]!==A||e[24]!==m?(te=m(A?"settings.providers.page.custom.editTitle":"settings.providers.page.custom.title"),e[23]=A,e[24]=m,e[25]=te):te=e[25];let Y;e[26]!==m?(Y=m("settings.providers.page.custom.description"),e[26]=m,e[27]=Y):Y=e[27];let ae;e[28]!==Y?(ae=s.jsx("p",{className:zn,children:Y}),e[28]=Y,e[29]=ae):ae=e[29];let ge;e[30]!==N?(ge=N?s.jsx("p",{className:"typography-meta text-[var(--status-warning)]",role:"status",children:N}):null,e[30]=N,e[31]=ge):ge=e[31];let de;e[32]!==m?(de=m("settings.providers.page.custom.field.providerID.label"),e[32]=m,e[33]=de):de=e[33];let he;e[34]!==m?(he=m("settings.providers.page.custom.field.providerID.info"),e[34]=m,e[35]=he):he=e[35];const se=I.providerID;let re;e[36]===Symbol.for("react.memo_cache_sentinel")?(re=jt=>ee("providerID",jt.target.value),e[36]=re):re=e[36];let ue;e[37]!==m?(ue=m("settings.providers.page.custom.field.providerID.placeholder"),e[37]=m,e[38]=ue):ue=e[38];const Ce=!A,Se=A||f,ye=!!w.providerID;let fe;e[39]!==m?(fe=m("settings.providers.page.custom.field.providerID.label"),e[39]=m,e[40]=fe):fe=e[40];let _e;e[41]!==I.providerID||e[42]!==ue||e[43]!==Ce||e[44]!==Se||e[45]!==ye||e[46]!==fe?(_e=s.jsx(He,{value:se,onChange:re,placeholder:ue,className:"h-8 rounded-md px-3 font-mono text-xs",autoFocus:Ce,disabled:Se,"aria-invalid":ye,"aria-label":fe}),e[41]=I.providerID,e[42]=ue,e[43]=Ce,e[44]=Se,e[45]=ye,e[46]=fe,e[47]=_e):_e=e[47];let Ue;e[48]!==w.providerID?(Ue=w.providerID?s.jsx("p",{className:"mt-1 typography-meta text-[var(--status-error)]",children:w.providerID}):null,e[48]=w.providerID,e[49]=Ue):Ue=e[49];let Ne;e[50]!==de||e[51]!==he||e[52]!==_e||e[53]!==Ue?(Ne=s.jsxs(qt,{label:de,info:he,children:[_e,Ue]}),e[50]=de,e[51]=he,e[52]=_e,e[53]=Ue,e[54]=Ne):Ne=e[54];let Oe;e[55]!==m?(Oe=m("settings.providers.page.custom.field.protocol.label"),e[55]=m,e[56]=Oe):Oe=e[56];let Ve;e[57]!==m?(Ve=m("settings.providers.page.custom.field.protocol.info"),e[57]=m,e[58]=Ve):Ve=e[58];const Ge=I.protocol;let ve;e[59]===Symbol.for("react.memo_cache_sentinel")?(ve=jt=>{jt in Tr&&j(At=>({...At,protocol:jt}))},e[59]=ve):ve=e[59];let Z;e[60]!==m?(Z=m("settings.providers.page.custom.field.protocol.label"),e[60]=m,e[61]=Z):Z=e[61];let ne;e[62]===Symbol.for("react.memo_cache_sentinel")?(ne=s.jsx(Mt,{}),e[62]=ne):ne=e[62];let be;e[63]!==Z?(be=s.jsx(Ct,{"aria-label":Z,className:"w-full",children:ne}),e[63]=Z,e[64]=be):be=e[64];let we;e[65]!==m?(we=m("settings.providers.page.custom.field.protocol.openaiChat"),e[65]=m,e[66]=we):we=e[66];let Re;e[67]!==we?(Re=s.jsx(at,{value:"openai-chat",children:we}),e[67]=we,e[68]=Re):Re=e[68];let Fe;e[69]!==m?(Fe=m("settings.providers.page.custom.field.protocol.openaiResponses"),e[69]=m,e[70]=Fe):Fe=e[70];let Ke;e[71]!==Fe?(Ke=s.jsx(at,{value:"openai-responses",children:Fe}),e[71]=Fe,e[72]=Ke):Ke=e[72];let Ee;e[73]!==m?(Ee=m("settings.providers.page.custom.field.protocol.anthropicMessages"),e[73]=m,e[74]=Ee):Ee=e[74];let je;e[75]!==Ee?(je=s.jsx(at,{value:"anthropic-messages",children:Ee}),e[75]=Ee,e[76]=je):je=e[76];let Ze;e[77]!==Re||e[78]!==Ke||e[79]!==je?(Ze=s.jsxs(It,{children:[Re,Ke,je]}),e[77]=Re,e[78]=Ke,e[79]=je,e[80]=Ze):Ze=e[80];let me;e[81]!==f||e[82]!==I.protocol||e[83]!==be||e[84]!==Ze?(me=s.jsxs(St,{value:Ge,onValueChange:ve,disabled:f,children:[be,Ze]}),e[81]=f,e[82]=I.protocol,e[83]=be,e[84]=Ze,e[85]=me):me=e[85];let Ie;e[86]!==Oe||e[87]!==Ve||e[88]!==me?(Ie=s.jsx(qt,{label:Oe,info:Ve,children:me}),e[86]=Oe,e[87]=Ve,e[88]=me,e[89]=Ie):Ie=e[89];let Le;e[90]!==m?(Le=m("settings.providers.page.custom.field.name.label"),e[90]=m,e[91]=Le):Le=e[91];let Xe;e[92]!==m?(Xe=m("settings.providers.page.custom.field.name.info"),e[92]=m,e[93]=Xe):Xe=e[93];const q=I.name;let ke;e[94]===Symbol.for("react.memo_cache_sentinel")?(ke=jt=>ee("name",jt.target.value),e[94]=ke):ke=e[94];let Pe;e[95]!==m?(Pe=m("settings.providers.page.custom.field.name.placeholder"),e[95]=m,e[96]=Pe):Pe=e[96];const Je=!!w.name;let ot;e[97]!==m?(ot=m("settings.providers.page.custom.field.name.label"),e[97]=m,e[98]=ot):ot=e[98];let st;e[99]!==I.name||e[100]!==Pe||e[101]!==Je||e[102]!==ot?(st=s.jsx(He,{value:q,onChange:ke,placeholder:Pe,className:"h-8 rounded-md px-3","aria-invalid":Je,"aria-label":ot}),e[99]=I.name,e[100]=Pe,e[101]=Je,e[102]=ot,e[103]=st):st=e[103];let pt;e[104]!==w.name?(pt=w.name?s.jsx("p",{className:"mt-1 typography-meta text-[var(--status-error)]",children:w.name}):null,e[104]=w.name,e[105]=pt):pt=e[105];let vt;e[106]!==Le||e[107]!==Xe||e[108]!==st||e[109]!==pt?(vt=s.jsxs(qt,{label:Le,info:Xe,children:[st,pt]}),e[106]=Le,e[107]=Xe,e[108]=st,e[109]=pt,e[110]=vt):vt=e[110];let W;e[111]!==m?(W=m("settings.providers.page.custom.field.baseURL.label"),e[111]=m,e[112]=W):W=e[112];let We;e[113]!==m?(We=m("settings.providers.page.custom.field.baseURL.info"),e[113]=m,e[114]=We):We=e[114];const nt=I.baseURL;let lt;e[115]===Symbol.for("react.memo_cache_sentinel")?(lt=jt=>ee("baseURL",jt.target.value),e[115]=lt):lt=e[115];let ht;e[116]!==m?(ht=m("settings.providers.page.custom.field.baseURL.placeholder"),e[116]=m,e[117]=ht):ht=e[117];const Lt=!!w.baseURL;let et;e[118]!==m?(et=m("settings.providers.page.custom.field.baseURL.label"),e[118]=m,e[119]=et):et=e[119];let ft;e[120]!==I.baseURL||e[121]!==ht||e[122]!==Lt||e[123]!==et?(ft=s.jsx(He,{value:nt,onChange:lt,placeholder:ht,className:"h-8 rounded-md px-3 font-mono text-xs","aria-invalid":Lt,"aria-label":et}),e[120]=I.baseURL,e[121]=ht,e[122]=Lt,e[123]=et,e[124]=ft):ft=e[124];let bt;e[125]!==w.baseURL?(bt=w.baseURL?s.jsx("p",{className:"mt-1 typography-meta text-[var(--status-error)]",children:w.baseURL}):null,e[125]=w.baseURL,e[126]=bt):bt=e[126];let Be;e[127]!==W||e[128]!==We||e[129]!==ft||e[130]!==bt?(Be=s.jsxs(qt,{label:W,info:We,children:[ft,bt]}),e[127]=W,e[128]=We,e[129]=ft,e[130]=bt,e[131]=Be):Be=e[131];let Et;e[132]!==m?(Et=m("settings.providers.page.custom.field.apiKey.label"),e[132]=m,e[133]=Et):Et=e[133];let Me;e[134]!==v||e[135]!==A||e[136]!==m?(Me=m(A&&v?"settings.providers.page.custom.field.apiKey.editInfo":"settings.providers.page.custom.field.apiKey.info"),e[134]=v,e[135]=A,e[136]=m,e[137]=Me):Me=e[137];const wt=I.apiKey;let Q;e[138]===Symbol.for("react.memo_cache_sentinel")?(Q=jt=>ee("apiKey",jt.target.value),e[138]=Q):Q=e[138];let pe;e[139]!==v||e[140]!==A||e[141]!==m?(pe=m(A&&v?"settings.providers.page.custom.field.apiKey.editPlaceholder":"settings.providers.page.custom.field.apiKey.placeholder"),e[139]=v,e[140]=A,e[141]=m,e[142]=pe):pe=e[142];const De=!!w.apiKey;let Ae;e[143]!==m?(Ae=m("settings.providers.page.custom.field.apiKey.label"),e[143]=m,e[144]=Ae):Ae=e[144];let it;e[145]!==I.apiKey||e[146]!==pe||e[147]!==De||e[148]!==Ae?(it=s.jsx(He,{type:"password",value:wt,onChange:Q,placeholder:pe,className:"h-8 rounded-md px-3 font-mono text-xs","aria-invalid":De,"aria-label":Ae}),e[145]=I.apiKey,e[146]=pe,e[147]=De,e[148]=Ae,e[149]=it):it=e[149];let rt;e[150]!==w.apiKey?(rt=w.apiKey?s.jsx("p",{className:"mt-1 typography-meta text-[var(--status-error)]",children:w.apiKey}):null,e[150]=w.apiKey,e[151]=rt):rt=e[151];let qe;e[152]!==Et||e[153]!==Me||e[154]!==it||e[155]!==rt?(qe=s.jsxs(qt,{label:Et,info:Me,children:[it,rt]}),e[152]=Et,e[153]=Me,e[154]=it,e[155]=rt,e[156]=qe):qe=e[156];let Pt;e[157]!==te||e[158]!==ae||e[159]!==ge||e[160]!==Ne||e[161]!==Ie||e[162]!==vt||e[163]!==Be||e[164]!==qe?(Pt=s.jsxs(ze,{title:te,divider:!1,settingsItem:"providers.custom",contentClassName:Qs,children:[ae,ge,Ne,Ie,vt,Be,qe]}),e[157]=te,e[158]=ae,e[159]=ge,e[160]=Ne,e[161]=Ie,e[162]=vt,e[163]=Be,e[164]=qe,e[165]=Pt):Pt=e[165];let ys;e[166]!==m?(ys=m("settings.providers.page.custom.models.title"),e[166]=m,e[167]=ys):ys=e[167];let Xt;if(e[168]!==I.models||e[169]!==S||e[170]!==m){let jt;e[172]!==I.models.length||e[173]!==S||e[174]!==m?(jt=(At,Ut)=>s.jsx("div",{className:`${zs} space-y-2`,children:s.jsxs("div",{className:"flex items-start gap-2",children:[s.jsxs("div",{className:"min-w-0 flex-1 space-y-2",children:[s.jsxs("div",{children:[s.jsx("label",{className:Tt,children:m("settings.providers.page.custom.models.idLabel")}),s.jsx(He,{value:At.id,onChange:Ot=>le(Ut,"id",Ot.target.value),placeholder:m("settings.providers.page.custom.models.idPlaceholder"),className:"mt-1 h-8 rounded-md px-3 font-mono text-xs","aria-label":m("settings.providers.page.custom.models.idLabel")}),S[Ut]?.id?s.jsx("p",{className:"mt-1 typography-meta text-[var(--status-error)]",children:S[Ut]?.id}):null]}),s.jsxs("div",{children:[s.jsx("label",{className:Tt,children:m("settings.providers.page.custom.models.nameLabel")}),s.jsx(He,{value:At.name,onChange:Ot=>le(Ut,"name",Ot.target.value),placeholder:m("settings.providers.page.custom.models.namePlaceholder"),className:"mt-1 h-8 rounded-md px-3","aria-label":m("settings.providers.page.custom.models.nameLabel")}),S[Ut]?.name?s.jsx("p",{className:"mt-1 typography-meta text-[var(--status-error)]",children:S[Ut]?.name}):null]})]}),s.jsx(V,{type:"button",variant:"ghost",size:"icon",className:Cs,disabled:I.models.length<=1,onClick:()=>{I.models.length<=1||(j(Ot=>({...Ot,models:Ot.models.filter((ns,Ds)=>Ds!==Ut)})),D(Ot=>Ot.filter((ns,Ds)=>Ds!==Ut)))},"aria-label":m("settings.providers.page.custom.models.remove"),children:s.jsx(O,{name:"delete-bin",className:"size-4"})})]})},At.row),e[172]=I.models.length,e[173]=S,e[174]=m,e[175]=jt):jt=e[175],Xt=I.models.map(jt),e[168]=I.models,e[169]=S,e[170]=m,e[171]=Xt}else Xt=e[171];let Os;e[176]===Symbol.for("react.memo_cache_sentinel")?(Os=()=>{j(xg),D(vg)},e[176]=Os):Os=e[176];let Wt;e[177]!==m?(Wt=m("settings.providers.page.custom.models.add"),e[177]=m,e[178]=Wt):Wt=e[178];let is;e[179]!==Wt?(is=s.jsx(V,{type:"button",variant:"outline",size:"xs",className:"!font-normal",onClick:Os,children:Wt}),e[179]=Wt,e[180]=is):is=e[180];let Ht;e[181]!==ys||e[182]!==Xt||e[183]!==is?(Ht=s.jsxs(ze,{title:ys,contentClassName:Qs,children:[Xt,is]}),e[181]=ys,e[182]=Xt,e[183]=is,e[184]=Ht):Ht=e[184];let bs;e[185]!==m?(bs=m("settings.providers.page.custom.headers.title"),e[185]=m,e[186]=bs):bs=e[186];let gs;e[187]!==m?(gs=m("settings.providers.page.custom.headers.description"),e[187]=m,e[188]=gs):gs=e[188];let hs;e[189]!==gs?(hs=s.jsx("p",{className:zn,children:gs}),e[189]=gs,e[190]=hs):hs=e[190];let ds;if(e[191]!==I.headers||e[192]!==B||e[193]!==m){let jt;e[195]!==I.headers.length||e[196]!==B||e[197]!==m?(jt=(At,Ut)=>s.jsx("div",{className:`${zs} space-y-2`,children:s.jsxs("div",{className:"flex items-start gap-2",children:[s.jsxs("div",{className:"min-w-0 flex-1 space-y-2",children:[s.jsxs("div",{children:[s.jsx("label",{className:Tt,children:m("settings.providers.page.custom.headers.keyLabel")}),s.jsx(He,{value:At.key,onChange:Ot=>H(Ut,"key",Ot.target.value),placeholder:m("settings.providers.page.custom.headers.keyPlaceholder"),className:"mt-1 h-8 rounded-md px-3 font-mono text-xs","aria-label":m("settings.providers.page.custom.headers.keyLabel")}),B[Ut]?.key?s.jsx("p",{className:"mt-1 typography-meta text-[var(--status-error)]",children:B[Ut]?.key}):null]}),s.jsxs("div",{children:[s.jsx("label",{className:Tt,children:m("settings.providers.page.custom.headers.valueLabel")}),s.jsx(He,{value:At.value,onChange:Ot=>H(Ut,"value",Ot.target.value),placeholder:m("settings.providers.page.custom.headers.valuePlaceholder"),className:"mt-1 h-8 rounded-md px-3 font-mono text-xs","aria-label":m("settings.providers.page.custom.headers.valueLabel")}),B[Ut]?.value?s.jsx("p",{className:"mt-1 typography-meta text-[var(--status-error)]",children:B[Ut]?.value}):null]})]}),s.jsx(V,{type:"button",variant:"ghost",size:"icon",className:Cs,disabled:I.headers.length<=1,onClick:()=>{I.headers.length<=1||(j(Ot=>({...Ot,headers:Ot.headers.filter((ns,Ds)=>Ds!==Ut)})),k(Ot=>Ot.filter((ns,Ds)=>Ds!==Ut)))},"aria-label":m("settings.providers.page.custom.headers.remove"),children:s.jsx(O,{name:"delete-bin",className:"size-4"})})]})},At.row),e[195]=I.headers.length,e[196]=B,e[197]=m,e[198]=jt):jt=e[198],ds=I.headers.map(jt),e[191]=I.headers,e[192]=B,e[193]=m,e[194]=ds}else ds=e[194];let Es;e[199]===Symbol.for("react.memo_cache_sentinel")?(Es=()=>{j(yg),k(bg)},e[199]=Es):Es=e[199];let oe;e[200]!==m?(oe=m("settings.providers.page.custom.headers.add"),e[200]=m,e[201]=oe):oe=e[201];let ct;e[202]!==oe?(ct=s.jsx(V,{type:"button",variant:"outline",size:"xs",className:"!font-normal",onClick:Es,children:oe}),e[202]=oe,e[203]=ct):ct=e[203];let xt;e[204]!==bs||e[205]!==hs||e[206]!==ds||e[207]!==ct?(xt=s.jsxs(ze,{title:bs,contentClassName:Qs,children:[hs,ds,ct]}),e[204]=bs,e[205]=hs,e[206]=ds,e[207]=ct,e[208]=xt):xt=e[208];let Qt;e[209]!==f||e[210]!==p||e[211]!==m?(Qt=p?s.jsx(V,{type:"button",variant:"outline",size:"xs",className:"!font-normal",onClick:p,disabled:f,children:m("settings.providers.page.custom.actions.back")}):null,e[209]=f,e[210]=p,e[211]=m,e[212]=Qt):Qt=e[212];let Yt;e[213]!==f||e[214]!==b||e[215]!==m?(Yt=b?s.jsx(V,{type:"button",variant:"destructive",size:"xs",className:"!font-normal",onClick:()=>{b()},disabled:f,children:m("settings.providers.page.actions.disconnect")}):null,e[213]=f,e[214]=b,e[215]=m,e[216]=Yt):Yt=e[216];let Bt;e[217]!==f||e[218]!==A||e[219]!==m?(Bt=m(f?"settings.providers.page.actions.saving":A?"settings.providers.page.custom.actions.update":"settings.providers.page.custom.actions.save"),e[217]=f,e[218]=A,e[219]=m,e[220]=Bt):Bt=e[220];let rs;e[221]!==f||e[222]!==Bt?(rs=s.jsx(V,{type:"submit",size:"xs",className:"!font-normal",disabled:f,children:Bt}),e[221]=f,e[222]=Bt,e[223]=rs):rs=e[223];let ws;e[224]!==Qt||e[225]!==Yt||e[226]!==rs?(ws=s.jsxs("div",{className:"flex flex-wrap items-center gap-2 py-4",children:[Qt,Yt,rs]}),e[224]=Qt,e[225]=Yt,e[226]=rs,e[227]=ws):ws=e[227];let ss;return e[228]!==K||e[229]!==Pt||e[230]!==Ht||e[231]!==xt||e[232]!==ws?(ss=s.jsxs("form",{onSubmit:K,className:"space-y-0",children:[Pt,Ht,xt,ws]}),e[228]=K,e[229]=Pt,e[230]=Ht,e[231]=xt,e[232]=ws,e[233]=ss):ss=e[233],ss};function xg(t){return{...t,models:[...t.models,Er()]}}function vg(t){return[...t,{}]}function yg(t){return{...t,headers:[...t.headers,Dr()]}}function bg(t){return[...t,{}]}const wg=(t,e)=>!!e&&t!=="claude-code",jg=/[A-Z0-9]{4}-[A-Z0-9]{4,5}/,Yn=t=>typeof t=="object"&&t!==null&&!Array.isArray(t),Is=t=>typeof t=="string"&&t.length>0?t:void 0,kg=t=>{if(!Array.isArray(t))return[];const e=[];for(const a of t){if(!Yn(a))continue;const n=Is(a.value);n!==void 0&&e.push({value:n,label:Is(a.label)??n,...Is(a.hint)?{hint:Is(a.hint)}:{}})}return e},Ng=t=>{if(!Yn(t))return;const e=Is(t.key),a=t.op==="eq"||t.op==="neq"?t.op:void 0;if(!(!e||!a||typeof t.value!="string"))return{key:e,op:a,value:t.value}},Sg=t=>{if(!Array.isArray(t))return[];const e=[];for(const a of t){if(!Yn(a))continue;const n=Is(a.key);if(!n)continue;const r=a.type==="select"?"select":"text",i=r==="select"?kg(a.options):[];if(r==="select"&&i.length===0)continue;const l=Ng(a.when);e.push({type:r,key:n,message:Is(a.message)??n,options:i,...Is(a.placeholder)?{placeholder:Is(a.placeholder)}:{},...l?{when:l}:{}})}return e},Cg=(t,e)=>{if(!t.when)return!0;const a=e[t.when.key]??"";return t.when.op==="eq"?a===t.when.value:a!==t.when.value},Mr=(t,e)=>t.filter(a=>Cg(a,e)),Ig=t=>{const e={};for(const a of t)e[a.key]=a.type==="select"?a.options[0]?.value??"":"";return e},Pg=(t,e)=>Mr(t,e).find(a=>(e[a.key]??"").trim().length===0)??null,Ag=(t,e)=>{const a={};for(const n of Mr(t,e))a[n.key]=(e[n.key]??"").trim();return a},Tg=t=>{const e=Yn(t)?t:{},a=Yn(e.data)?e.data:e,n=Is(a.url)??Is(a.verification_uri_complete)??Is(a.verification_uri),r=Is(a.instructions)??Is(a.message);if(!n&&!r)return null;const i=Is(a.user_code)??Is(a.userCode)??(r?jg.exec(r)?.[0]:void 0);return{method:a.method==="code"?"code":"auto",...n?{url:n}:{},...r?{instructions:r}:{},...i?{userCode:i}:{}}},_o=(t,e,a)=>{const n=Yn(t)?t:{},r=Yn(n.data)?n.data:{};switch(n.name){case"ProviderAuthOauthMissing":return e("settings.providers.page.auth.oauth.error.sessionExpired");case"ProviderAuthOauthCodeMissing":return e("settings.providers.page.auth.oauth.error.codeRequired");case"ProviderAuthOauthCallbackFailed":return e("settings.providers.page.auth.oauth.error.declined");case"ProviderAuthValidationFailed":return Is(r.message)??e("settings.providers.page.auth.oauth.error.invalidInput");default:return e(a)}},er={phase:"idle"},$o=({providerId:t,methods:e,onConnected:a,className:n})=>{const{t:r}=tt(),[i,l]=o.useState(er),[g,c]=o.useState({}),[y,p]=o.useState(""),b=o.useRef(null);o.useEffect(()=>()=>b.current?.abort(),[]);const d=i.phase==="idle"?null:i.methodIndex,P=i.phase==="authorizing"||i.phase==="waiting"||i.phase==="awaitingCode"&&i.submitting,f=async(h,w,F)=>{const T=await Ka(h);if(T.ok){E.success(r(w));return}console.error("Failed to copy OAuth value:",T.error),E.error(r(F))},C=async(h,w)=>{const F=new AbortController;b.current?.abort(),b.current=F;try{const T=await fn.getSdkClient().provider.oauth.callback({providerID:t,method:h,...w?{code:w}:{}},{signal:F.signal});if(F.signal.aborted)return;if(T.error)throw T.error;l(er),E.success(r("settings.providers.page.toast.oauthCompleted")),await a()}catch(T){if(F.signal.aborted)return;console.error("Failed to complete OAuth flow:",T),l({phase:"failed",methodIndex:h,message:_o(T,r,"settings.providers.page.toast.oauthCompleteFailed")})}finally{b.current===F&&(b.current=null)}},v=async(h,w)=>{l({phase:"authorizing",methodIndex:h});let F;try{const T=await fn.getSdkClient().provider.oauth.authorize({providerID:t,method:h,...Object.keys(w).length>0?{inputs:w}:{}});if(T.error)throw T.error;const S=Tg(T.data);if(!S){l({phase:"failed",methodIndex:h,message:r("settings.providers.page.toast.oauthDetailsMissing")});return}F=S}catch(T){console.error("Failed to start OAuth flow:",T),l({phase:"failed",methodIndex:h,message:_o(T,r,"settings.providers.page.toast.oauthStartFailed")});return}if(F.url&&wg(t,F.url)&&Pn(F.url),F.method==="code"){p(""),l({phase:"awaitingCode",methodIndex:h,authorization:F,submitting:!1});return}l({phase:"waiting",methodIndex:h,authorization:F}),await C(h)},N=h=>{const w=Sg(h.prompts);if(w.length===0){v(h.index,{});return}c(Ig(w)),l({phase:"prompting",methodIndex:h.index,prompts:w,error:null})},m=()=>{if(i.phase!=="prompting")return;const h=Pg(i.prompts,g);if(h){l({...i,error:r("settings.providers.page.auth.oauth.promptRequired",{field:h.message})});return}v(i.methodIndex,Ag(i.prompts,g))},A=()=>{if(i.phase!=="awaitingCode")return;const h=y.trim();h&&(l({...i,submitting:!0}),C(i.methodIndex,h))},R=()=>{b.current?.abort(),b.current=null,l(er)},I=h=>{const w=g[h.key]??"",F=T=>c(S=>({...S,[h.key]:T}));return s.jsxs("div",{className:"space-y-1.5",children:[s.jsx("label",{className:"typography-ui-label text-foreground",children:h.message}),h.type==="select"?s.jsxs(St,{value:w,onValueChange:F,children:[s.jsx(Ct,{size:Ft,className:rn,children:s.jsx(Mt,{children:T=>h.options.find(S=>S.value===T)?.label??null})}),s.jsx(It,{children:h.options.map(T=>s.jsx(at,{value:T.value,children:T.hint?`${T.label} · ${T.hint}`:T.label},T.value))})]}):s.jsx(He,{value:w,onChange:T=>F(T.target.value),placeholder:h.placeholder,className:"max-w-[24rem] text-xs"})]},h.key)},j=h=>s.jsxs(s.Fragment,{children:[h.instructions&&s.jsx("p",{className:"typography-meta text-[var(--primary-base)] bg-[var(--primary-base)]/10 px-2 py-1.5 rounded",children:h.instructions}),h.userCode&&s.jsxs("div",{className:"flex items-center gap-2",children:[s.jsx(He,{value:h.userCode,readOnly:!0,"aria-label":r("settings.providers.page.auth.oauth.deviceCodeLabel"),className:"font-mono text-center tracking-widest"}),s.jsx(V,{variant:"outline",size:"xs",className:"!font-normal shrink-0",onClick:()=>{f(h.userCode??"","settings.providers.page.toast.deviceCodeCopied","settings.providers.page.toast.deviceCodeCopyFailed")},children:r("settings.providers.page.actions.copyCode")})]}),h.url&&s.jsxs("div",{className:"flex items-center gap-2",children:[s.jsx(He,{value:h.url,readOnly:!0,"aria-label":r("settings.providers.page.auth.oauth.linkLabel"),className:"text-xs text-muted-foreground"}),s.jsxs("div",{className:"flex gap-1 shrink-0",children:[s.jsx(V,{variant:"outline",size:"xs",className:"!font-normal",onClick:()=>{Pn(h.url??"")},children:r("settings.providers.page.actions.open")}),s.jsx(V,{variant:"outline",size:"xs",className:"!font-normal",onClick:()=>{f(h.url??"","settings.providers.page.toast.oauthLinkCopied","settings.providers.page.toast.oauthLinkCopyFailed")},children:r("settings.providers.page.actions.copy")})]})]})]});return s.jsx("div",{className:xe("space-y-4",n),children:e.map(h=>{const w=d===h.index;return s.jsxs("div",{className:"space-y-3",children:[s.jsxs("div",{className:"flex items-center justify-between gap-2",children:[s.jsx("div",{className:"typography-ui-label text-foreground",children:h.label}),s.jsx(V,{variant:"outline",size:"xs",className:"!font-normal shrink-0",onClick:()=>N(h),disabled:P,children:r("settings.providers.page.actions.connect")})]}),w&&i.phase==="prompting"&&s.jsxs("div",{className:"space-y-3",children:[Mr(i.prompts,g).map(I),i.error&&s.jsx("p",{className:"typography-meta text-[var(--status-error)]",children:i.error}),s.jsxs("div",{className:"flex items-center gap-2",children:[s.jsx(V,{size:"xs",className:"!font-normal",onClick:m,children:r("settings.providers.page.actions.continue")}),s.jsx(V,{variant:"ghost",size:"xs",className:"!font-normal",onClick:R,children:r("settings.providers.page.actions.cancel")})]})]}),w&&i.phase==="authorizing"&&s.jsxs("p",{className:"typography-meta text-muted-foreground flex items-center gap-2",children:[s.jsx(O,{name:"loader",className:"h-3.5 w-3.5 animate-spin"}),r("settings.providers.page.auth.oauth.starting")]}),w&&i.phase==="waiting"&&s.jsxs("div",{className:"space-y-3",children:[j(i.authorization),s.jsxs("div",{className:"flex items-center justify-between gap-2",children:[s.jsxs("p",{className:"typography-meta text-muted-foreground flex items-center gap-2",children:[s.jsx(O,{name:"loader",className:"h-3.5 w-3.5 animate-spin"}),r("settings.providers.page.auth.oauth.waiting")]}),s.jsx(V,{variant:"ghost",size:"xs",className:"!font-normal shrink-0",onClick:R,children:r("settings.providers.page.actions.cancel")})]}),s.jsx("p",{className:"typography-meta text-muted-foreground",children:r("settings.providers.page.auth.oauth.waitingHint")})]}),w&&i.phase==="awaitingCode"&&s.jsxs("div",{className:"space-y-3",children:[j(i.authorization),s.jsx("p",{className:"typography-meta text-muted-foreground",children:r("settings.providers.page.auth.oauth.codeHint")}),s.jsxs("div",{className:"flex items-center gap-2",children:[s.jsx(He,{value:y,onChange:F=>p(F.target.value),placeholder:r("settings.providers.page.auth.pasteAuthorizationCodePlaceholder"),className:"font-mono text-xs",disabled:i.submitting}),s.jsx(V,{size:"xs",className:"!font-normal shrink-0",onClick:A,disabled:i.submitting||y.trim().length===0,children:i.submitting?r("settings.providers.page.actions.saving"):r("settings.providers.page.actions.complete")}),s.jsx(V,{variant:"ghost",size:"xs",className:"!font-normal shrink-0",onClick:R,disabled:i.submitting,children:r("settings.providers.page.actions.cancel")})]})]}),w&&i.phase==="failed"&&s.jsxs("div",{className:"space-y-2",children:[s.jsx("p",{className:"typography-meta text-[var(--status-error)]",children:i.message}),s.jsx(V,{variant:"outline",size:"xs",className:"!font-normal",onClick:()=>N(h),children:r("settings.providers.page.actions.tryAgain")})]})]},h.index)})})},Vo=t=>Array.isArray(t?.env)&&t.env.some(e=>e.trim().length>0),Eg=t=>new Intl.NumberFormat(Sr(),{notation:"compact",compactDisplay:"short",maximumFractionDigits:1,minimumFractionDigits:0}).format(t),Bo=t=>{if(typeof t!="number"||Number.isNaN(t))return null;if(t===0)return"0";const e=Eg(t);return e.endsWith(".0")?e.slice(0,-2):e},Ea="__add_provider__",Zl=t=>typeof t=="object"&&t!==null,Ho=(t,e)=>t.map(({method:a,methodIndex:n})=>({index:n,label:a.label||a.name||e(n),prompts:a.prompts})),Dg=t=>{if(typeof t=="string")return{id:t};if(!Zl(t))return null;const e=typeof t.id=="string"&&t.id||typeof t.providerID=="string"&&t.providerID||typeof t.slug=="string"&&t.slug||typeof t.name=="string"&&t.name;if(!e)return null;const a=typeof t.name=="string"?t.name:void 0;return{id:e,name:a}},Mg=t=>{let e=[];Array.isArray(t)?e=t:Zl(t)&&(Array.isArray(t.all)?e=t.all:Array.isArray(t.providers)&&(e=t.providers));const a=e.map(r=>Dg(r)).filter(r=>!!r),n=new Set;return a.filter(r=>n.has(r.id)?!1:(n.add(r.id),!0))},Rg=()=>{const{t}=tt(),e=_s(),a=Ye(q=>Cl(q,e)),n=Ye(q=>q.selectedProviderId),r=Ye(q=>q.setSelectedProvider),i=Ye(q=>q.getModelMetadata),l=ie(q=>q.hiddenModels),g=ie(q=>q.toggleHiddenModel),c=ie(q=>q.hideAllModels),y=ie(q=>q.showAllModels),[p,b]=o.useState({}),[d,P]=o.useState(!1),[f,C]=o.useState({}),[v,N]=o.useState(null),[m,A]=o.useState(""),[R,I]=o.useState([]),[j,h]=o.useState(!1),[w,F]=o.useState(null),[T,S]=o.useState(""),[D,$]=o.useState(""),[B,k]=o.useState(!1),[G,M]=o.useState({}),[L,J]=o.useState(0),[ee,U]=o.useState(!1),[le,_]=o.useState(null),[H,z]=o.useState(null),[K,te]=o.useState(null),[Y,ae]=o.useState(null),[ge,de]=o.useState(null),[he,se]=o.useState(null),re=n===Ea,ue=re&&T===Kn,Ce=!!(H&&n&&H===n&&!re);o.useEffect(()=>{!n&&a.length>0&&r(a[0].id)},[a,n,r]),o.useEffect(()=>{if(!n)return;let q=!0;return(async()=>{P(!0);try{const Pe=await fn.getSdkClient().provider.auth();if(Pe.error)throw new Error(`provider.auth failed: ${String(Pe.error)}`);if(!q)return;b(sg(Pe.data))}catch(Pe){if(!q)return;console.error("Failed to load provider auth methods:",Pe),E.error(t("settings.providers.page.toast.authMethodsLoadFailed"))}finally{q&&P(!1)}})(),()=>{q=!1}},[n,t]),o.useEffect(()=>{if(!eg(re))return;let q=!0;return(async()=>{h(!0),F(null);try{const Pe=await fn.getSdkClient().provider.list();if(Pe.error)throw new Error(`provider.list failed: ${String(Pe.error)}`);if(!q)return;I(Mg(Pe.data))}catch(Pe){if(!q)return;console.error("Failed to load available providers:",Pe),F(t("settings.providers.page.state.unableToLoadProviderList"))}finally{q&&h(!1)}})(),()=>{q=!1}},[re,t]);const Se=o.useMemo(()=>new Set(a.map(q=>q.id)),[a]),ye=o.useMemo(()=>R.filter(q=>!Se.has(q.id)).sort((q,ke)=>{const Pe=(q.name||q.id).toLowerCase(),Je=(ke.name||ke.id).toLowerCase();return Pe.localeCompare(Je)}),[R,Se]);o.useEffect(()=>{n===Ea&&T&&T!==Kn&&!ye.some(q=>q.id===T)&&S("")},[n,T,ye]),o.useEffect(()=>{if(n===Ea){U(!0),_(null),z(null),te(null),ae(null),de(null);return}U(!1),_(null),H&&H!==n&&(z(null),te(null),ae(null),de(null))},[n,H]),o.useEffect(()=>{if(!n||n===Ea)return;const q=G[n];if(!q)return;const ke=a.find(ot=>ot.id===n),Pe=Fo({key:ke?.key,authSourceExists:q.auth.exists,optionsApiKey:ke?.options?.apiKey??null,envDeclared:Vo(ke)}),Je=!!(ke&&Ko(ke,q));ig({hasCredentials:Pe,userDismissed:le===n,isEditableCustomProvider:Je})&&U(!0)},[n,G,a,le]),o.useEffect(()=>{if(!n||n===Ea)return;let q=!1;return(async()=>{try{const Pe=e?`?directory=${encodeURIComponent(e)}`:"",Je=await yt(`/api/provider/${encodeURIComponent(n)}/source${Pe}`,{method:"GET",headers:{Accept:"application/json"}}),ot=await Je.json().catch(()=>null);if(!Je.ok)throw new Error(ot?.error||t("settings.providers.page.toast.providerSourcesLoadFailed"));const st=ot?.sources??ot?.data?.sources;!q&&st&&M(pt=>({...pt,[n]:st}))}catch(Pe){q||console.error("Failed to load provider sources:",Pe)}})(),()=>{q=!0}},[n,L,e,t]);const fe=o.useCallback(()=>{J(q=>q+1)},[]),_e=o.useCallback(q=>{M(ke=>{const Pe=ke[q];return{...ke,[q]:{auth:{exists:!0,path:Pe?.auth.path??null},user:Pe?.user??{exists:!1,path:null},project:Pe?.project??{exists:!1,path:null},...Pe?.custom?{custom:Pe.custom}:{}}}}),_(null),U(!1),r(q),fe()},[fe,r]),Ue=o.useCallback(async(q,ke)=>{try{return await Il({scopes:[q],mode:"active"}),"reloaded"}catch(Pe){if(Pe?.requiresManualRestart===!0)return ke&&$n(q,{id:ke}),"manual-restart";throw Pe}},[]),Ne=a.find(q=>q.id===n),Oe=n?G[n]:void 0,Ve=async q=>{const ke=f[q]?.trim()??"";if(!ke){E.error(t("settings.providers.page.toast.apiKeyRequired"));return}const Pe=`api:${q}`;N(Pe);try{if((await fn.getSdkClient().auth.set({providerID:q,auth:{type:"api",key:ke}})).error)throw new Error(t("settings.providers.page.toast.apiKeySaveFailed"));E.success(t("settings.providers.page.toast.apiKeySaved")),C(ot=>({...ot,[q]:""})),await Ue("providers",q),_e(q)}catch(Je){console.error("Failed to save API key:",Je),E.error(t("settings.providers.page.toast.apiKeySaveFailed"))}finally{N(null)}},Ge=async q=>{const ke=`custom:${q.providerID}`;N(ke),se(q.providerID),de(null);try{const Pe=hg(q);if(Pe&&(await fn.getSdkClient().auth.set(Pe)).error)throw new Error(t("settings.providers.page.toast.apiKeySaveFailed"));const Je=fg(q,{scope:H?Y??zo(G[H]):"user"}),ot=await yt(`/api/provider${e?`?directory=${encodeURIComponent(e)}`:""}`,{method:"PUT",headers:{Accept:"application/json","Content-Type":"application/json"},body:JSON.stringify(Je)}),st=await ot.json().catch(()=>null);if(!ot.ok)throw Pe&&de(t("settings.providers.page.custom.authFailure.configAfterAuth")),new Error(st?.error||t("settings.providers.page.toast.customProviderSaveFailed"));E.success(t("settings.providers.page.toast.customProviderSaved",{provider:q.name})),S(""),z(null),te(null),ae(null),de(null),se(null),await Ue("providers",q.providerID),_e(q.providerID)}catch(Pe){console.error("Failed to save custom provider:",Pe),E.error(Pe instanceof Error&&Pe.message?Pe.message:t("settings.providers.page.toast.customProviderSaveFailed"))}finally{N(null)}},ve=q=>t("settings.providers.page.auth.oauthMethodFallback",{index:String(q+1)}),Z=q=>{U(!1),ng(q)&&$n("providers",{id:q}),_e(q)},ne=async q=>{const ke=`disconnect:${q}`;N(ke);try{const Pe=await yt(`/api/provider/${encodeURIComponent(q)}/auth?scope=all${e?`&directory=${encodeURIComponent(e)}`:""}`,{method:"DELETE",headers:{Accept:"application/json"}}),Je=await Pe.json().catch(()=>null);if(!Pe.ok)throw new Error(Je?.error||t("settings.providers.page.toast.providerDisconnectFailed"));E.success(t("settings.providers.page.toast.providerDisconnected")),await Ue("providers",q),_(null),fe()}catch(Pe){console.error("Failed to disconnect provider:",Pe),E.error(t("settings.providers.page.toast.providerDisconnectFailed"))}finally{N(null)}},be=async q=>{q&&(await ne(q),z(null),te(null),ae(null),de(null),se(null),S(""))};if(!re&&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(O,{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(re)return s.jsxs(es,{title:t("settings.providers.page.connect.title"),showSaveStatus:!1,children:[s.jsx(ze,{title:t("settings.providers.page.connect.selectProviderTitle"),divider:!1,settingsItem:"providers.connect",children:s.jsxs("div",{className:"flex flex-wrap items-center gap-2 py-1.5",children:[s.jsx("span",{className:"typography-ui-label text-foreground",children:t("settings.providers.page.connect.providerField")}),j?s.jsx("p",{className:"typography-meta text-muted-foreground",children:t("settings.providers.page.state.loading")}):w?s.jsx("p",{className:"typography-meta text-muted-foreground",children:w}):s.jsxs(cn,{open:B,onOpenChange:q=>{k(q),q||$("")},children:[s.jsx(on,{asChild:!0,children:s.jsxs("button",{type:"button",className:In,children:[s.jsxs("span",{className:"flex items-center gap-2 min-w-0",children:[T&&T!==Kn?s.jsx(Un,{providerId:T,className:"h-3.5 w-3.5 flex-shrink-0"}):null,s.jsx("span",{className:xe("truncate typography-ui-label font-normal",T?"text-foreground":"text-muted-foreground"),children:T===Kn?t("settings.providers.page.custom.optionLabel"):T?ye.find(q=>q.id===T)?.name||T:t("settings.providers.page.connect.selectProviderPlaceholder")})]}),s.jsx(O,{name:"arrow-down-s",className:"h-4 w-4 flex-shrink-0 text-muted-foreground/50"})]})}),s.jsxs(ln,{align:"start",className:"w-[280px] p-0",onCloseAutoFocus:q=>q.preventDefault(),children:[s.jsxs("div",{className:"flex items-center gap-2 border-b border-[var(--surface-subtle)] px-3 py-2",onKeyDown:q=>q.stopPropagation(),children:[s.jsx(O,{name:"search",className:"h-4 w-4 text-muted-foreground"}),s.jsx("input",{type:"text",value:D,onChange:q=>$(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=Oc([q,"other","custom"],D),Pe=ki(ye,D,Je=>[Je.name||Je.id,Je.id]);return Pe.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:[Pe.map(Je=>s.jsxs(dn,{onSelect:()=>{S(Je.id),k(!1),$("")},className:"flex items-center justify-between",children:[s.jsxs("span",{className:"flex items-center gap-2 min-w-0",children:[s.jsx(Un,{providerId:Je.id,className:"h-4 w-4 flex-shrink-0"}),s.jsx("span",{className:"truncate",children:Je.name||Je.id})]}),T===Je.id&&s.jsx(O,{name:"check",className:"h-4 w-4 text-[var(--primary-base)]"})]},Je.id)),ke?s.jsxs(dn,{onSelect:()=>{S(Kn),k(!1),$("")},className:"flex items-center justify-between",children:[s.jsxs("span",{className:"flex items-center gap-2 min-w-0",children:[s.jsx(O,{name:"add",className:"h-4 w-4 flex-shrink-0"}),s.jsx("span",{className:"truncate",children:q})]}),T===Kn&&s.jsx(O,{name:"check",className:"h-4 w-4 text-[var(--primary-base)]"})]},Kn):null]})})()})]})]})]})}),ue?s.jsx(Uo,{mode:"create",existingProviderIDs:Se,busy:v?.startsWith("custom:")??!1,authFailureHint:ge,onCancel:()=>{S(""),de(null),se(null)},onDisconnect:ge&&he?()=>{be(he)}:void 0,onSubmit:Ge}):T?s.jsx(ze,{title:t("settings.providers.page.auth.title"),settingsItem:"providers.auth",contentClassName:"space-y-4",children:d?s.jsx("p",{className:"typography-meta text-muted-foreground",children:t("settings.providers.page.auth.loadingMethods")}):s.jsx(s.Fragment,{children:(()=>{const q=p[T]??[],ke=Ho(Oo(q),ve),Pe=Lo(q);return s.jsxs(s.Fragment,{children:[Pe?s.jsxs("div",{className:"py-1.5",children:[s.jsxs("label",{className:"typography-ui-label text-foreground flex items-center gap-1.5",children:[t("settings.providers.page.auth.apiKeyLabel"),s.jsx(Jt,{children:t("settings.providers.page.auth.apiKeyTooltip")})]}),s.jsxs("div",{className:"flex flex-col @xl:flex-row @xl:items-center gap-2 mt-1.5",children:[s.jsx(He,{type:"password",value:f[T]??"",onChange:Je=>C(ot=>({...ot,[T]:Je.target.value})),placeholder:t("settings.providers.page.auth.apiKeyPlaceholder"),className:"flex-1 font-mono text-xs"}),s.jsx(V,{size:"xs",className:"!font-normal shrink-0",onClick:()=>Ve(T),disabled:v===`api:${T}`,children:v===`api:${T}`?t("settings.providers.page.actions.saving"):t("settings.providers.page.actions.saveKey")})]})]}):null,ke.length>0?s.jsx($o,{providerId:T,methods:ke,onConnected:()=>Z(T),className:xe(Pe&&"border-t border-[var(--surface-subtle)] pt-2")},T):null]})})()})}):null]});if(!Ne)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(O,{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 we=Array.isArray(Ne.models)?Ne.models:[],Re=p[Ne.id]??[],Fe=Ho(Oo(Re),ve),Ke=Lo(Re),Ee=!!Oe,je=Ee&&Ko(Ne,Oe),Ze=Fo({key:Ne.key,authSourceExists:Oe?.auth.exists,optionsApiKey:Ne.options?.apiKey??null,envDeclared:Vo(Ne)}),me=tg(Ee,Ze,je),Ie=ag({modelCount:we.length,sourcesLoaded:Ee,hasCredentials:Ze,isEditableCustomProvider:je}),Le=!Ke&&Fe.length>0?t("settings.providers.page.auth.useReconnectHint"):t("settings.providers.page.auth.incompleteHint"),Xe=ki(we,m,q=>[typeof q?.name=="string"?q.name:"",typeof q?.id=="string"?q.id:""]);return Ce&&je&&K?s.jsx(es,{title:Ne.name||Ne.id,titleLeading:s.jsx(Un,{providerId:Ne.id,className:"h-5 w-5 shrink-0"}),description:s.jsx("span",{className:"font-mono typography-settings-description text-muted-foreground",children:Ne.id}),showSaveStatus:!1,children:s.jsx(Uo,{mode:"edit",existingProviderIDs:Se,initialValues:K,allowExistingAuth:Ze||!Ee,busy:v?.startsWith("custom:")??!1,authFailureHint:ge,onCancel:()=>{z(null),te(null),ae(null),de(null),se(null)},onDisconnect:()=>{be(Ne.id)},onSubmit:Ge})}):s.jsxs(es,{title:Ne.name||Ne.id,titleLeading:s.jsx(Un,{providerId:Ne.id,className:"h-5 w-5 shrink-0"}),description:s.jsx("span",{className:"font-mono typography-settings-description text-muted-foreground",children:Ne.id}),showSaveStatus:!1,children:[s.jsx(ze,{title:t("settings.providers.page.auth.title"),divider:!1,headerAction:s.jsxs("div",{className:"flex items-center gap-1",children:[je?s.jsx(V,{variant:"outline",size:"xs",className:"!font-normal",onClick:()=>{de(null),te(mg(Ne)),ae(zo(Oe)),z(Ne.id)},children:t("settings.providers.page.actions.edit")}):null,s.jsx(V,{variant:"outline",size:"xs",className:"!font-normal",onClick:()=>{const q=!ee;U(q),_(q?null:Ne.id)},children:t(ee?"settings.providers.page.actions.hide":"settings.providers.page.actions.reconnect")})]}),settingsItem:"providers.auth",children:ee?d?s.jsx("div",{className:"py-1.5 typography-meta text-muted-foreground",children:t("settings.providers.page.auth.loadingMethods")}):s.jsxs("div",{className:"space-y-4",children:[Ke?s.jsxs("div",{className:"py-1.5",children:[s.jsxs("label",{className:"typography-ui-label text-foreground flex items-center gap-1.5",children:[t("settings.providers.page.auth.apiKeyLabel"),s.jsx(Jt,{children:t("settings.providers.page.auth.apiKeyTooltip")})]}),s.jsxs("div",{className:"flex flex-col @xl:flex-row @xl:items-center gap-2 mt-1.5",children:[s.jsx(He,{type:"password",value:f[Ne.id]??"",onChange:q=>C(ke=>({...ke,[Ne.id]:q.target.value})),placeholder:t("settings.providers.page.auth.apiKeyPlaceholder"),className:"flex-1 font-mono text-xs"}),s.jsx(V,{size:"xs",className:"!font-normal shrink-0",onClick:()=>Ve(Ne.id),disabled:v===`api:${Ne.id}`,children:v===`api:${Ne.id}`?t("settings.providers.page.actions.saving"):t("settings.providers.page.actions.saveKey")})]})]}):null,Fe.length>0&&s.jsx($o,{providerId:Ne.id,methods:Fe,onConnected:()=>Z(Ne.id),className:xe(Ke&&"border-t border-[var(--surface-subtle)] pt-2")},Ne.id)]}):me?s.jsxs("div",{className:"flex items-center gap-1.5 py-1.5",children:[s.jsx(O,{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(O,{name:"check",className:"w-4 h-4 text-[var(--status-success)] shrink-0"}),s.jsx("span",{className:"typography-ui-label text-foreground",children:t("settings.providers.page.auth.connected")}),s.jsx(Jt,{children:t("settings.providers.page.auth.useReconnectHint")})]})}),s.jsx(ze,{title:t("settings.providers.page.connectionDetails.title"),settingsItem:"providers.connection-details",children:s.jsxs("div",{className:"flex flex-col gap-2 py-1.5 @xl:flex-row @xl:items-center @xl:justify-between @xl:gap-8",children:[s.jsx("div",{className:"flex min-w-0 flex-col",children:Oe&&(Oe.auth.exists||Oe.user.exists||Oe.project.exists||Oe.custom?.exists)?s.jsxs("span",{className:"typography-meta text-muted-foreground",children:[t("settings.providers.page.connectionDetails.configuredIn")," ",[Oe.auth.exists?t("settings.providers.page.connectionDetails.source.authCredentials"):null,Oe.user.exists?t("settings.providers.page.connectionDetails.source.userConfig"):null,Oe.project.exists?t("settings.providers.page.connectionDetails.source.projectConfig"):null,Oe.custom?.exists?t("settings.providers.page.connectionDetails.source.customConfig"):null].filter(Boolean).join(", ")]}):s.jsx("span",{className:"typography-meta text-muted-foreground",children:t("settings.providers.page.connectionDetails.noActiveSource")})}),s.jsx(V,{variant:"ghost",size:"xs",className:"!font-normal text-[var(--status-error)] hover:text-[var(--status-error)]",onClick:()=>ne(Ne.id),disabled:v===`disconnect:${Ne.id}`,children:v===`disconnect:${Ne.id}`?t("settings.providers.page.actions.disconnecting"):t("settings.providers.page.actions.disconnect")})]})}),Ie?s.jsxs(ze,{title:t("settings.providers.page.models.title"),titleAccessory:s.jsxs("span",{className:"typography-micro text-muted-foreground font-normal",children:["(",we.length,")"]}),headerAction:s.jsxs("div",{className:"flex items-center gap-1",children:[s.jsx(V,{variant:"outline",size:"xs",className:"!font-normal",onClick:()=>{const q=we.map(ke=>typeof ke?.id=="string"?ke.id:"").filter(ke=>ke.length>0);c(Ne.id,q)},children:t("settings.providers.page.actions.hideAll")}),s.jsx(V,{variant:"outline",size:"xs",className:"!font-normal",onClick:()=>y(Ne.id),children:t("settings.providers.page.actions.showAll")})]}),settingsItem:"providers.models",children:[s.jsxs("div",{className:"relative mb-2",children:[s.jsx(O,{name:"search",className:"absolute left-2 top-1/2 -translate-y-1/2 h-3.5 w-3.5 text-muted-foreground"}),s.jsx(He,{value:m,onChange:q=>A(q.target.value),placeholder:t("settings.providers.page.models.filterPlaceholder"),className:"h-7 pl-8 w-full"})]}),Xe.length===0?s.jsx("p",{className:"typography-meta text-muted-foreground py-4 text-center",children:t("settings.providers.page.models.noModelsMatchFilter")}):s.jsx("div",{className:"divide-y divide-[var(--surface-subtle)]",children:Xe.map(q=>{const ke=typeof q?.id=="string"?q.id:"",Pe=typeof q?.name=="string"?q.name:ke,Je=ke?i(Ne.id,ke):void 0,ot=l.some(W=>W.providerID===Ne.id&&W.modelID===ke),st=Bo(Je?.limit?.context),pt=Bo(Je?.limit?.output),vt=[];return Je?.tool_call&&vt.push({key:"tools",icon:"tools",label:t("settings.providers.page.models.capability.toolCalling")}),Je?.reasoning&&vt.push({key:"reasoning",icon:"brain-ai-3",label:t("settings.providers.page.models.capability.reasoning")}),Je?.attachment&&vt.push({key:"image",icon:"file-image",label:t("settings.providers.page.models.capability.imageInput")}),s.jsx("div",{className:"py-1.5",children:s.jsxs("div",{className:xe("flex items-center gap-3",ot&&"opacity-50"),children:[s.jsx("span",{className:"typography-meta font-medium text-foreground truncate flex-1 min-w-0",children:Pe}),s.jsxs("div",{className:"flex items-center gap-2 flex-shrink-0",children:[(st||pt)&&s.jsxs("span",{className:"typography-micro text-muted-foreground flex-shrink-0 bg-[var(--surface-muted)] px-1.5 py-0.5 rounded",children:[st?`${st} ${t("settings.providers.page.models.tokenBadge.context")}`:"",st&&pt?" · ":"",pt?`${pt} ${t("settings.providers.page.models.tokenBadge.output")}`:""]}),vt.length>0&&s.jsx("div",{className:"flex items-center gap-1 flex-shrink-0",children:vt.map(({key:W,icon:We,label:nt})=>s.jsx("span",{className:"flex h-5 w-5 rounded items-center justify-center text-muted-foreground bg-[var(--surface-muted)]",title:nt,"aria-label":nt,children:s.jsx(O,{name:We,className:"h-3 w-3"})},W))}),s.jsx("button",{type:"button",onClick:()=>g(Ne.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(ot?"settings.providers.page.models.actions.showModelInSelectors":"settings.providers.page.models.actions.hideModelFromSelectors"),"aria-label":t(ot?"settings.providers.page.models.actions.showModel":"settings.providers.page.models.actions.hideModel"),children:ot?s.jsx(O,{name:"eye-off",className:"h-3.5 w-3.5"}):s.jsx(O,{name:"eye",className:"h-3.5 w-3.5"})})]})]})},ke)})})]}):null]})},Lg=t=>{const e=t?.windows??{},a=Object.values(e).map(n=>n.usedPercent).filter(n=>typeof n=="number");return a.length===0?null:Math.max(...a)},Og=t=>{const e=ut.c(75),{onItemSelect:a}=t,{t:n}=tt(),r=Zt(Fg),i=Zt(Kg),l=Zt(zg),g=Zt(Ug),c=Zt(_g),y=Zt($g),p=Zt(Vg),b=Zt(Bg);let d,P;e[0]!==b?(d=()=>{b()},P=[b],e[0]=b,e[1]=d,e[2]=P):(d=e[1],P=e[2]),o.useEffect(d,P);const f=Hg;let C;e[3]!==p?(C=ae=>{ae!=="usage"&&ae!=="remaining"||(p(ae),f({usageDisplayMode:ae}))},e[3]=p,e[4]=C):C=e[4];const v=C;let N;e[5]===Symbol.for("react.memo_cache_sentinel")?(N=xe("flex h-full flex-col","bg-background"),e[5]=N):N=e[5];let m;e[6]!==n?(m=n("settings.usage.sidebar.title"),e[6]=n,e[7]=m):m=e[7];let A;e[8]!==m?(A=s.jsx("h2",{className:`${un} mb-3`,children:m}),e[8]=m,e[9]=A):A=e[9];let R;e[10]!==n?(R=n("settings.usage.sidebar.total",{count:Ni.length}),e[10]=n,e[11]=R):R=e[11];let I;e[12]!==R?(I=s.jsx("span",{className:"typography-meta text-muted-foreground",children:R}),e[12]=R,e[13]=I):I=e[13];let j;e[14]!==g?(j=()=>g(),e[14]=g,e[15]=j):j=e[15];let h;e[16]!==n?(h=n("settings.usage.sidebar.actions.refreshAria"),e[16]=n,e[17]=h):h=e[17];let w;e[18]!==n?(w=n("settings.usage.sidebar.actions.refreshTitle"),e[18]=n,e[19]=w):w=e[19];const F=c&&"animate-spin";let T;e[20]!==F?(T=xe("h-3.5 w-3.5",F),e[20]=F,e[21]=T):T=e[21];let S;e[22]!==T?(S=s.jsx(O,{name:"refresh",className:T}),e[22]=T,e[23]=S):S=e[23];let D;e[24]!==c||e[25]!==h||e[26]!==w||e[27]!==S||e[28]!==j?(D=s.jsx("div",{className:"flex items-center gap-2",children:s.jsx(V,{size:"sm",variant:"ghost",className:"h-7 w-7 px-0 text-muted-foreground",onClick:j,"aria-label":h,title:w,disabled:c,children:S})}),e[24]=c,e[25]=h,e[26]=w,e[27]=S,e[28]=j,e[29]=D):D=e[29];let $;e[30]!==D||e[31]!==I?($=s.jsxs("div",{className:"flex items-center justify-between gap-2",children:[I,D]}),e[30]=D,e[31]=I,e[32]=$):$=e[32];let B;e[33]!==n?(B=n("settings.usage.sidebar.field.display"),e[33]=n,e[34]=B):B=e[34];let k;e[35]!==B?(k=s.jsx("span",{className:"typography-micro text-muted-foreground",children:B}),e[35]=B,e[36]=k):k=e[36];let G;e[37]!==n?(G=n("settings.usage.sidebar.field.displayModePlaceholder"),e[37]=n,e[38]=G):G=e[38];let M;e[39]!==G?(M=s.jsx(Ct,{className:"w-fit",children:s.jsx(Mt,{placeholder:G})}),e[39]=G,e[40]=M):M=e[40];let L;e[41]!==n?(L=n("settings.usage.sidebar.field.displayModeUsage"),e[41]=n,e[42]=L):L=e[42];let J;e[43]!==L?(J=s.jsx(at,{value:"usage",children:L}),e[43]=L,e[44]=J):J=e[44];let ee;e[45]!==n?(ee=n("settings.usage.sidebar.field.displayModeRemaining"),e[45]=n,e[46]=ee):ee=e[46];let U;e[47]!==ee?(U=s.jsx(at,{value:"remaining",children:ee}),e[47]=ee,e[48]=U):U=e[48];let le;e[49]!==J||e[50]!==U?(le=s.jsxs(It,{children:[J,U]}),e[49]=J,e[50]=U,e[51]=le):le=e[51];let _;e[52]!==v||e[53]!==M||e[54]!==le||e[55]!==y?(_=s.jsxs(St,{value:y,onValueChange:v,children:[M,le]}),e[52]=v,e[53]=M,e[54]=le,e[55]=y,e[56]=_):_=e[56];let H;e[57]!==k||e[58]!==_?(H=s.jsxs("div",{className:"mt-2 flex items-center justify-between gap-2",children:[k,_]}),e[57]=k,e[58]=_,e[59]=H):H=e[59];let z;e[60]!==$||e[61]!==H||e[62]!==A?(z=s.jsxs("div",{className:"border-b px-3 pt-4 pb-3",children:[A,$,H]}),e[60]=$,e[61]=H,e[62]=A,e[63]=z):z=e[63];let K;e[64]!==a||e[65]!==r||e[66]!==i||e[67]!==l||e[68]!==n?(K=Ni.map(ae=>{const ge=r.find(Ce=>Ce.providerId===ae.id),de=Lg(ge?.usage),he=Pl(de),se=ae.id===i,re=ge?.configured,ue=re?he==="critical"?{backgroundColor:"var(--status-error)"}:he==="warn"?{backgroundColor:"var(--status-warning)"}:{backgroundColor:"var(--status-success)"}:{backgroundColor:"var(--surface-muted-foreground)",opacity:.4};return s.jsx("div",{className:xe("group relative flex items-center rounded-md px-1.5 py-1 transition-all duration-200",se?"bg-interactive-selection":"hover:bg-interactive-hover"),children:s.jsxs("button",{type:"button",onClick:()=>{l(ae.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:ue}),s.jsx(Un,{providerId:ae.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:ae.name}),re===!1&&s.jsx("span",{className:"typography-micro text-muted-foreground/60 flex-shrink-0",children:n("settings.usage.sidebar.status.notSet")})]})},ae.id)}),e[64]=a,e[65]=r,e[66]=i,e[67]=l,e[68]=n,e[69]=K):K=e[69];let te;e[70]!==K?(te=s.jsx(vs,{outerClassName:"flex-1 min-h-0",className:"space-y-1 px-3 py-2 overflow-x-hidden",children:K}),e[70]=K,e[71]=te):te=e[71];let Y;return e[72]!==z||e[73]!==te?(Y=s.jsxs("div",{className:N,children:[z,te]}),e[72]=z,e[73]=te,e[74]=Y):Y=e[74],Y};function Fg(t){return t.results}function Kg(t){return t.selectedProviderId}function zg(t){return t.setSelectedProvider}function Ug(t){return t.fetchAllQuotas}function _g(t){return t.isLoading}function $g(t){return t.displayMode}function Vg(t){return t.setDisplayMode}function Bg(t){return t.loadSettings}async function Hg(t){try{await gt(t)}catch(e){console.warn("Failed to save usage settings:",e)}}const Gg=t=>{const e=ut.c(17),{percent:a,tonePercent:n,className:r}=t;let i;e[0]!==a?(i=Fc(a)??0,e[0]=a,e[1]=i):i=e[1];const l=i,g=n??a;let c;e[2]!==g?(c=Pl(g),e[2]=g,e[3]=c):c=e[3];const y=c;let p;e[4]!==y?(p=y==="critical"?{backgroundColor:"var(--status-error)"}:y==="warn"?{backgroundColor:"var(--status-warning)"}:{backgroundColor:"var(--status-success)"},e[4]=y,e[5]=p):p=e[5];const b=p;let d;e[6]!==r?(d=xe("relative h-2.5 rounded-full bg-[var(--interactive-border)] overflow-hidden",r),e[6]=r,e[7]=d):d=e[7];const P=`${l}%`;let f;e[8]!==b||e[9]!==P?(f={...b,width:P},e[8]=b,e[9]=P,e[10]=f):f=e[10];let C;e[11]!==l||e[12]!==f?(C=s.jsx("div",{className:"h-full transition-all duration-300",style:f,role:"progressbar","aria-valuenow":l,"aria-valuemin":0,"aria-valuemax":100}),e[11]=l,e[12]=f,e[13]=C):C=e[13];let v;return e[14]!==d||e[15]!==C?(v=s.jsx("div",{className:d,children:C}),e[14]=d,e[15]=C,e[16]=v):v=e[16],v},tr=t=>{const e=ut.c(44),{title:a,window:n,subtitle:r,showToggle:i,toggleEnabled:l,onToggle:g}=t,c=i===void 0?!1:i,y=l===void 0?!1:l,p=Zt(Wg),b=ie(qg),d=p==="remaining"?n.remainingPercent:n.usedPercent,P=p==="remaining"?"remaining":"used";let f;e[0]!==d||e[1]!==n.valueLabel?(f=Kc(n.valueLabel,d),e[0]=d,e[1]=n.valueLabel,e[2]=f):f=e[2];const C=f,v=n.resetAfterFormatted??n.resetAtFormatted;let N;e[3]!==v||e[4]!==b||e[5]!==n.resetAt?(N=zc(n.resetAt,v,b),e[3]=v,e[4]=b,e[5]=n.resetAt,e[6]=N):N=e[6];const m=N;let A;e[7]!==a?(A=Uc(a),e[7]=a,e[8]=A):A=e[8];const R=A;let I;e[9]!==g||e[10]!==c||e[11]!==y?(I=c&&s.jsx(cr,{checked:y,onChange:ee=>g?.(ee),ariaLabel:"Show in dropdown"}),e[9]=g,e[10]=c,e[11]=y,e[12]=I):I=e[12];let j;e[13]!==R?(j=s.jsx("span",{className:"typography-ui-label text-foreground truncate",children:R}),e[13]=R,e[14]=j):j=e[14];let h;e[15]!==r?(h=r&&s.jsx("span",{className:"typography-meta text-muted-foreground truncate",children:r}),e[15]=r,e[16]=h):h=e[16];let w;e[17]!==j||e[18]!==h?(w=s.jsxs("div",{className:"min-w-0 flex flex-col",children:[j,h]}),e[17]=j,e[18]=h,e[19]=w):w=e[19];let F;e[20]!==w||e[21]!==I?(F=s.jsxs("div",{className:"min-w-0 flex-1 flex items-center gap-2",children:[I,w]}),e[20]=w,e[21]=I,e[22]=F):F=e[22];const T=C==="-"?"":C;let S;e[23]!==T?(S=s.jsx("div",{className:"typography-ui-label text-foreground tabular-nums flex items-center justify-end",children:T}),e[23]=T,e[24]=S):S=e[24];let D;e[25]!==F||e[26]!==S?(D=s.jsxs("div",{className:"flex items-center justify-between gap-3",children:[F,S]}),e[25]=F,e[26]=S,e[27]=D):D=e[27];let $;e[28]!==d||e[29]!==n.usedPercent?($=s.jsx(Gg,{percent:d,tonePercent:n.usedPercent,className:"h-1.5"}),e[28]=d,e[29]=n.usedPercent,e[30]=$):$=e[30];const B=m?`Resets ${m}`:"";let k;e[31]!==B?(k=s.jsx("span",{className:"typography-micro text-muted-foreground",children:B}),e[31]=B,e[32]=k):k=e[32];let G;e[33]!==P?(G=s.jsx("span",{className:"typography-micro text-muted-foreground",children:P}),e[33]=P,e[34]=G):G=e[34];let M;e[35]!==k||e[36]!==G?(M=s.jsxs("div",{className:"mt-1 flex items-center justify-between",children:[k,G]}),e[35]=k,e[36]=G,e[37]=M):M=e[37];let L;e[38]!==$||e[39]!==M?(L=s.jsxs("div",{className:"mt-2.5",children:[$,M]}),e[38]=$,e[39]=M,e[40]=L):L=e[40];let J;return e[41]!==D||e[42]!==L?(J=s.jsxs("div",{className:"py-3",children:[D,L]}),e[41]=D,e[42]=L,e[43]=J):J=e[43],J};function Wg(t){return t.displayMode}function qg(t){return t.timeFormatPreference}const Jg=`ssh exe.dev "ssh-key generate-api-key --label=aiworker --exp=30d --cmds='billing credits usage'"`,Qg=({providerId:t,providerName:e})=>{const{t:a}=tt(),[n,r]=o.useState(null),[i,l]=o.useState({}),[g,c]=o.useState(!1),y=`/api/quota/credentials/${t}`;o.useEffect(()=>{yt(y).then(async d=>{if(!d.ok)throw new Error;const P=await d.json();r(P),l({})}).catch(()=>r({configured:!1}))},[y]);const p=async(d,P,f)=>{c(!0);try{const C=await yt(d,{method:P,headers:f?{"Content-Type":"application/json"}:void 0,body:f?JSON.stringify(f):void 0}),v=await C.json().catch(()=>null);if(!C.ok)throw new Error(v?.error);v?.configured!==void 0&&r(v),l({}),E.success(a("settings.providers.page.quotaCredentials.saved",{provider:e}))}catch(C){E.error(C instanceof Error&&C.message?C.message:a("settings.providers.page.openCodeGo.saveFailed"))}finally{c(!1)}},b=(d,P,f)=>s.jsxs("label",{className:"block typography-ui-label text-foreground",children:[P,s.jsx(He,{className:"mt-1 h-7 font-mono text-xs",type:"password",autoComplete:"off",value:i[d]??"",onChange:C=>l(v=>({...v,[d]:C.target.value})),placeholder:n?.secretMasked??f})]});return s.jsxs("div",{"data-settings-item":`usage.${t}-credentials`,className:"mb-8",children:[s.jsx("div",{className:"mb-1 px-1",children:s.jsx("h3",{className:"typography-ui-header font-medium text-foreground",children:e})}),s.jsxs("section",{className:"space-y-3 px-2 pb-2 pt-0",children:[t==="exe-dev"&&s.jsxs("div",{className:"space-y-1.5",children:[s.jsx("p",{className:"typography-meta text-muted-foreground",children:a("settings.providers.page.quotaCredentials.exeDevTokenInstructions")}),s.jsx("code",{className:"typography-code block whitespace-pre-wrap break-all rounded bg-muted/50 px-2 py-1.5 text-xs text-foreground",children:Jg})]}),t==="ollama-cloud"&&b("cookie",a("settings.providers.page.openCodeGo.authCookie"),"aid=...; __Secure-session=..."),t==="exe-dev"&&b("usageToken",a("settings.providers.page.quotaCredentials.usageToken"),a("settings.providers.page.quotaCredentials.tokenPlaceholder")),t==="cursor"&&b("accessToken",a("settings.providers.page.quotaCredentials.accessToken"),a("settings.providers.page.quotaCredentials.tokenPlaceholder")),t==="cursor"&&b("refreshToken",a("settings.providers.page.quotaCredentials.refreshToken"),a("settings.providers.page.quotaCredentials.tokenPlaceholder")),s.jsxs("div",{className:"flex flex-wrap gap-2",children:[s.jsx(V,{size:"xs",disabled:g,onClick:()=>p(y,"PUT",i),children:n?.configured?a("settings.providers.page.openCodeGo.replace"):a("settings.providers.page.openCodeGo.save")}),n?.configured&&s.jsx(V,{variant:"outline",size:"xs",disabled:g,onClick:()=>p(`${y}/validate`,"POST"),children:a("settings.providers.page.openCodeGo.validate")}),t==="cursor"&&s.jsx(V,{variant:"outline",size:"xs",disabled:g,onClick:()=>p(`${y}/import`,"POST"),children:a("settings.providers.page.actions.connect")}),n?.configured&&s.jsx(V,{variant:"destructive",size:"xs",disabled:g,onClick:()=>p(y,"DELETE"),children:a("settings.providers.page.openCodeGo.delete")})]})]})]})},Go=(t,e)=>{if(!t)return"-";try{return Al(t,e,{fallback:"-"})}catch{return"-"}},Yg=()=>{const{t}=tt(),e=ie(M=>M.timeFormatPreference),a=Zt(M=>M.results),n=Zt(M=>M.selectedProviderId),r=Zt(M=>M.setSelectedProvider),i=Zt(M=>M.loadSettings),l=Zt(M=>M.fetchAllQuotas),g=Zt(M=>M.isLoading),c=Zt(M=>M.lastUpdated),y=Zt(M=>M.error),p=Zt(M=>M.refreshErrors),b=Zt(M=>M.dropdownProviderIds),d=Zt(M=>M.setDropdownProviderIds),P=Zt(M=>M.selectedModels),f=Zt(M=>M.toggleModelSelected),C=Zt(M=>M.applyDefaultSelections);_c(),o.useEffect(()=>{i(),l()},[i,l]),o.useEffect(()=>{if(n||a.length===0)return;const M=a.find(L=>L.configured)?.providerId;r(M??Ni[0]?.id??null)},[a,n,r]);const v=a.find(M=>M.providerId===n)??null,m=Ni.find(M=>M.id===n)?.name??n??t("settings.usage.sidebar.title"),A=v?.usage,R=n?p[n]:void 0,I=R?A?t("header.services.usageRefreshFailedStale",{error:R}):R:v?.configured&&!v.ok?v.error:null,j=n?b.includes(n):!1,h=n==="exe-dev"||n==="ollama-cloud"||n==="cursor",w=o.useCallback(M=>{if(!n)return;const L=M?Array.from(new Set([...b,n])):b.filter(J=>J!==n);d(L),gt({usageDropdownProviders:L})},[b,n,d]),F=o.useMemo(()=>A?.models?Object.entries(A.models).map(([M,L])=>({name:M,windows:L})).filter(M=>Object.keys(M.windows.windows).length>0):[],[A?.models]);o.useEffect(()=>{n&&F.length>0&&C(n,F.map(M=>M.name))},[n,F,C]);const T=o.useMemo(()=>!n||F.length===0?new Map:$c(F,M=>M.name,n),[F,n]),S=o.useMemo(()=>{if(!n)return[];const M=Bc(n);return Vc(M)},[n]),[D,$]=o.useState(()=>({})),B=o.useCallback(M=>{$(L=>({...L,[M]:!L[M]}))},[]),k=o.useCallback(M=>{if(!n)return;f(n,M);const L=P[n]??[],ee=L.includes(M)?L.filter(le=>le!==M):[...L,M],U={...P,[n]:ee};gt({usageSelectedModels:U})},[n,P,f]),G=n?P[n]??[]:[];return n?s.jsxs(es,{title:t("settings.usage.page.header.providerUsage",{provider:m}),titleLeading:s.jsx(Un,{providerId:n,className:"h-5 w-5 shrink-0"}),description:g?s.jsx("span",{className:"animate-pulse typography-settings-description text-muted-foreground",children:t("settings.usage.page.header.refreshing")}):v?.planLabel?t("settings.usage.page.header.lastUpdatedWithPlan",{plan:v.planLabel,time:Go(c,e)}):t("settings.usage.page.header.lastUpdated",{time:Go(c,e)}),showSaveStatus:!0,children:[s.jsx(ze,{divider:!1,settingsItem:"usage.work-status-panel",children:s.jsx(dt,{checked:j,onChange:w,label:t("settings.usage.page.options.showInWorkStatus"),ariaLabel:t("settings.usage.page.options.showInWorkStatusAria"),info:t("settings.usage.page.options.showInWorkStatusTooltip")})}),!v&&s.jsx("p",{className:"typography-ui-label text-foreground pb-8",children:t("settings.usage.page.state.noData")}),(y||I)&&s.jsxs("div",{className:"mb-8 rounded-lg border border-[var(--status-error-border)] bg-[var(--status-error-background)] px-4 py-3",children:[s.jsx("p",{className:"typography-ui-label font-medium text-[var(--status-error)]",children:t("settings.usage.page.state.refreshFailedTitle")}),s.jsx("p",{className:"typography-meta text-[var(--status-error)]/80 mt-1",children:I??y})]}),v&&!v.configured&&!h&&s.jsxs("div",{className:"mb-8 rounded-lg border border-[var(--status-warning-border)] bg-[var(--status-warning-background)] px-4 py-3",children:[s.jsx("p",{className:"typography-ui-label font-medium text-[var(--status-warning)]",children:t("settings.usage.page.state.providerNotConfiguredTitle")}),s.jsx("p",{className:"typography-meta text-[var(--status-warning)]/80 mt-1",children:t("settings.usage.page.state.providerNotConfiguredDescription")})]}),(n==="exe-dev"||n==="ollama-cloud"||n==="cursor")&&s.jsx(Qg,{providerId:n,providerName:m}),A?.windows&&Object.keys(A.windows).length>0&&s.jsx(ze,{settingsItem:"usage.model-quotas",children:s.jsx("div",{className:"divide-y divide-[var(--surface-subtle)]",children:Object.entries(A.windows).map(([M,L])=>s.jsx(tr,{title:M,window:L},M))})}),F.length>0&&s.jsxs(ze,{title:t("settings.usage.page.section.modelQuotas"),contentClassName:"space-y-3",children:[S.map(M=>{const L=T.get(M.id)??[];if(L.length===0)return null;const J=D[M.id]??!1;return s.jsx("section",{className:"p-2",children:s.jsxs(An,{open:!J,onOpenChange:()=>B(M.id),children:[s.jsxs(Tn,{className:"flex w-full items-center justify-between py-0.5 group",children:[s.jsxs("div",{className:"flex items-center gap-1.5 text-left",children:[s.jsx("span",{className:"typography-ui-label font-normal text-foreground",children:M.label}),s.jsxs("span",{className:"typography-micro text-muted-foreground",children:["(",L.length,")"]})]}),J?s.jsx(O,{name:"arrow-right-s",className:"h-4 w-4 text-muted-foreground group-hover:text-foreground transition-colors"}):s.jsx(O,{name:"arrow-down-s",className:"h-4 w-4 text-muted-foreground group-hover:text-foreground transition-colors"})]}),s.jsx(En,{children:s.jsx("div",{className:"divide-y divide-[var(--surface-subtle)] mt-1",children:L.map(ee=>{const U=Object.entries(ee.windows.windows);if(U.length===0)return null;const[le,_]=U[0],H=G.includes(ee.name);return s.jsx(tr,{title:le,subtitle:Ur(ee.name),window:_,showToggle:!0,toggleEnabled:H,onToggle:()=>k(ee.name)},ee.name)})})})]})},M.id)}),(()=>{const M=T.get(null)??[];if(M.length===0)return null;const L=D.other??!1;return s.jsx("section",{className:"p-2",children:s.jsxs(An,{open:!L,onOpenChange:()=>B("other"),children:[s.jsxs(Tn,{className:"flex w-full items-center justify-between py-0.5 group",children:[s.jsxs("div",{className:"flex items-center gap-1.5 text-left",children:[s.jsx("span",{className:"typography-ui-label font-normal text-foreground",children:t("settings.usage.page.section.otherModels")}),s.jsxs("span",{className:"typography-micro text-muted-foreground",children:["(",M.length,")"]})]}),L?s.jsx(O,{name:"arrow-right-s",className:"h-4 w-4 text-muted-foreground group-hover:text-foreground transition-colors"}):s.jsx(O,{name:"arrow-down-s",className:"h-4 w-4 text-muted-foreground group-hover:text-foreground transition-colors"})]}),s.jsx(En,{children:s.jsx("div",{className:"divide-y divide-[var(--surface-subtle)] mt-1",children:M.map(J=>{const ee=Object.entries(J.windows.windows);if(ee.length===0)return null;const[U,le]=ee[0],_=G.includes(J.name);return s.jsx(tr,{title:U,subtitle:Ur(J.name),window:le,showToggle:!0,toggleEnabled:_,onToggle:()=>k(J.name)},J.name)})})})]})})})()]}),v?.configured&&A&&Object.keys(A.windows??{}).length===0&&F.length===0&&s.jsxs("div",{className:"pb-8",children:[s.jsx("p",{className:"typography-ui-label text-foreground",children:t("settings.usage.page.state.noQuotaWindowsTitle")}),s.jsx("p",{className:"typography-meta text-muted-foreground mt-1",children:t("settings.usage.page.state.noQuotaWindowsDescription")})]})]}):s.jsx("div",{className:"flex h-full items-center justify-center text-muted-foreground",children:s.jsx("p",{className:"typography-body",children:t("settings.usage.page.empty.selectProvider")})})},Zg="git.commit.generate",xr=Kl(t=>({selectedPromptId:Zg,setSelectedPromptId:e=>{t(a=>a.selectedPromptId===e?a:{selectedPromptId:e})}})),Xg=t=>{const e=ut.c(24),{onItemSelect:a}=t,{t:n}=tt(),r=xr(eh),i=xr(th);let l;e[0]===Symbol.for("react.memo_cache_sentinel")?(l={groupKey:"settings.magicPrompts.sidebar.group.git",items:[{id:"git.commit.generate",titleKey:"settings.magicPrompts.sidebar.item.gitCommitGenerate"},{id:"git.pr.generate",titleKey:"settings.magicPrompts.sidebar.item.gitPrGenerate"},{id:"git.conflict.resolve",titleKey:"settings.magicPrompts.sidebar.item.gitConflictResolve"},{id:"git.integrate.cherrypick.resolve",titleKey:"settings.magicPrompts.sidebar.item.gitCherrypickConflictResolve"}]},e[0]=l):l=e[0];let g;e[1]===Symbol.for("react.memo_cache_sentinel")?(g={groupKey:"settings.magicPrompts.sidebar.group.github",items:[{id:"github.pr.review",titleKey:"settings.magicPrompts.sidebar.item.githubPrReview"},{id:"github.issue.review",titleKey:"settings.magicPrompts.sidebar.item.githubIssueReview"},{id:"github.pr.checks.review",titleKey:"settings.magicPrompts.sidebar.item.githubPrFailedChecksReview"},{id:"github.pr.comments.review",titleKey:"settings.magicPrompts.sidebar.item.githubPrCommentsReview"},{id:"github.pr.comment.single",titleKey:"settings.magicPrompts.sidebar.item.githubSinglePrCommentReview"}]},e[1]=g):g=e[1];let c;e[2]===Symbol.for("react.memo_cache_sentinel")?(c={groupKey:"settings.magicPrompts.sidebar.group.linear",items:[{id:"linear.issue.review",titleKey:"settings.magicPrompts.sidebar.item.linearIssueReview"}]},e[2]=c):c=e[2];let y;e[3]===Symbol.for("react.memo_cache_sentinel")?(y={groupKey:"settings.magicPrompts.sidebar.group.planning",items:[{id:"plan.todo",titleKey:"settings.magicPrompts.sidebar.item.planTodo"},{id:"plan.improve",titleKey:"settings.magicPrompts.sidebar.item.planImprove"},{id:"plan.implement",titleKey:"settings.magicPrompts.sidebar.item.planImplement"}]},e[3]=y):y=e[3];let p;e[4]===Symbol.for("react.memo_cache_sentinel")?(p=[l,g,c,y,{groupKey:"settings.magicPrompts.sidebar.group.session",items:[{id:"session.explore",titleKey:"settings.magicPrompts.sidebar.item.sessionExplore"},{id:"session.summary",titleKey:"settings.magicPrompts.sidebar.item.sessionSummary"},{id:"session.review",titleKey:"settings.magicPrompts.sidebar.item.sessionWorkspaceReview"},{id:"session.plan",titleKey:"settings.magicPrompts.sidebar.item.sessionFeaturePlan"},{id:"session.craftGoal",titleKey:"settings.magicPrompts.sidebar.item.sessionCraftGoal"},{id:"session.catchup",titleKey:"settings.magicPrompts.sidebar.item.sessionCatchUp"},{id:"session.debug",titleKey:"settings.magicPrompts.sidebar.item.sessionDebug"},{id:"session.weigh",titleKey:"settings.magicPrompts.sidebar.item.sessionWeigh"},{id:"session.fusion",titleKey:"settings.magicPrompts.sidebar.item.sessionFusion"}]}],e[4]=p):p=e[4];const b=p;let d;e[5]!==n?(d=n("settings.magicPrompts.sidebar.title"),e[5]=n,e[6]=d):d=e[6];let P;e[7]!==d?(P=s.jsx("h2",{className:un,children:d}),e[7]=d,e[8]=P):P=e[8];let f;e[9]!==n?(f=n("settings.magicPrompts.sidebar.description"),e[9]=n,e[10]=f):f=e[10];let C;e[11]!==f?(C=s.jsx("p",{className:"typography-meta mt-1 text-muted-foreground",children:f}),e[11]=f,e[12]=C):C=e[12];let v;e[13]!==P||e[14]!==C?(v=s.jsxs("div",{className:"border-b px-3 pt-4 pb-3",children:[P,C]}),e[13]=P,e[14]=C,e[15]=v):v=e[15];let N;e[16]!==a||e[17]!==r||e[18]!==i||e[19]!==n?(N=s.jsx(vs,{outerClassName:"flex-1 min-h-0",className:"space-y-3 px-3 py-2 overflow-x-hidden",children:b.map(A=>s.jsxs("div",{className:"space-y-1",children:[s.jsx("div",{className:"typography-micro px-1 text-muted-foreground",children:n(A.groupKey)}),A.items.map(R=>{const I=r===R.id;return s.jsx("button",{type:"button",onClick:()=>{i(R.id),a?.()},className:xe("flex w-full items-center rounded-md px-2 py-1.5 text-left transition-colors",I?"bg-interactive-selection text-foreground":"text-foreground hover:bg-interactive-hover"),children:s.jsx("span",{className:"typography-ui-label truncate font-normal",children:n(R.titleKey)})},R.id)})]},A.groupKey))}),e[16]=a,e[17]=r,e[18]=i,e[19]=n,e[20]=N):N=e[20];let m;return e[21]!==v||e[22]!==N?(m=s.jsxs("div",{className:"flex h-full flex-col bg-background",children:[v,N]}),e[21]=v,e[22]=N,e[23]=m):m=e[23],m};function eh(t){return t.selectedPromptId}function th(t){return t.setSelectedPromptId}const Wo={"git.commit.generate":{titleKey:"settings.magicPrompts.page.group.gitCommitGenerate.title",descriptionKey:"settings.magicPrompts.page.group.gitCommitGenerate.description",blocks:[{id:"git.commit.generate.visible",titleKey:"settings.magicPrompts.page.block.visiblePrompt"},{id:"git.commit.generate.instructions",titleKey:"settings.magicPrompts.page.block.instructions"}]},"git.pr.generate":{titleKey:"settings.magicPrompts.page.group.gitPrGenerate.title",descriptionKey:"settings.magicPrompts.page.group.gitPrGenerate.description",blocks:[{id:"git.pr.generate.visible",titleKey:"settings.magicPrompts.page.block.visiblePrompt"},{id:"git.pr.generate.instructions",titleKey:"settings.magicPrompts.page.block.instructions"}]},"github.pr.review":{titleKey:"settings.magicPrompts.page.group.githubPrReview.title",descriptionKey:"settings.magicPrompts.page.group.githubPrReview.description",blocks:[{id:"github.pr.review.visible",titleKey:"settings.magicPrompts.page.block.visiblePrompt"},{id:"github.pr.review.instructions",titleKey:"settings.magicPrompts.page.block.instructions"}]},"github.issue.review":{titleKey:"settings.magicPrompts.page.group.githubIssueReview.title",descriptionKey:"settings.magicPrompts.page.group.githubIssueReview.description",blocks:[{id:"github.issue.review.visible",titleKey:"settings.magicPrompts.page.block.visiblePrompt"},{id:"github.issue.review.instructions",titleKey:"settings.magicPrompts.page.block.instructions"}]},"linear.issue.review":{titleKey:"settings.magicPrompts.page.group.linearIssueReview.title",descriptionKey:"settings.magicPrompts.page.group.linearIssueReview.description",blocks:[{id:"linear.issue.review.visible",titleKey:"settings.magicPrompts.page.block.visiblePrompt"},{id:"linear.issue.review.instructions",titleKey:"settings.magicPrompts.page.block.instructions"}]},"github.pr.checks.review":{titleKey:"settings.magicPrompts.page.group.githubPrFailedChecksReview.title",descriptionKey:"settings.magicPrompts.page.group.githubPrFailedChecksReview.description",blocks:[{id:"github.pr.checks.review.visible",titleKey:"settings.magicPrompts.page.block.visiblePrompt"},{id:"github.pr.checks.review.instructions",titleKey:"settings.magicPrompts.page.block.instructions"}]},"github.pr.comments.review":{titleKey:"settings.magicPrompts.page.group.githubPrCommentsReview.title",descriptionKey:"settings.magicPrompts.page.group.githubPrCommentsReview.description",blocks:[{id:"github.pr.comments.review.visible",titleKey:"settings.magicPrompts.page.block.visiblePrompt"},{id:"github.pr.comments.review.instructions",titleKey:"settings.magicPrompts.page.block.instructions"}]},"github.pr.comment.single":{titleKey:"settings.magicPrompts.page.group.githubSinglePrCommentReview.title",descriptionKey:"settings.magicPrompts.page.group.githubSinglePrCommentReview.description",blocks:[{id:"github.pr.comment.single.visible",titleKey:"settings.magicPrompts.page.block.visiblePrompt"},{id:"github.pr.comment.single.instructions",titleKey:"settings.magicPrompts.page.block.instructions"}]},"git.conflict.resolve":{titleKey:"settings.magicPrompts.page.group.gitConflictResolve.title",descriptionKey:"settings.magicPrompts.page.group.gitConflictResolve.description",blocks:[{id:"git.conflict.resolve.visible",titleKey:"settings.magicPrompts.page.block.visiblePrompt"},{id:"git.conflict.resolve.instructions",titleKey:"settings.magicPrompts.page.block.instructions"}]},"git.integrate.cherrypick.resolve":{titleKey:"settings.magicPrompts.page.group.gitCherrypickConflictResolve.title",descriptionKey:"settings.magicPrompts.page.group.gitCherrypickConflictResolve.description",blocks:[{id:"git.integrate.cherrypick.resolve.visible",titleKey:"settings.magicPrompts.page.block.visiblePrompt"},{id:"git.integrate.cherrypick.resolve.instructions",titleKey:"settings.magicPrompts.page.block.instructions"}]},"plan.improve":{titleKey:"settings.magicPrompts.page.group.planImprove.title",descriptionKey:"settings.magicPrompts.page.group.planImprove.description",blocks:[{id:"plan.improve.visible",titleKey:"settings.magicPrompts.page.block.visiblePrompt"},{id:"plan.improve.instructions",titleKey:"settings.magicPrompts.page.block.instructions"}]},"plan.todo":{titleKey:"settings.magicPrompts.page.group.planTodo.title",descriptionKey:"settings.magicPrompts.page.group.planTodo.description",blocks:[{id:"plan.todo.visible",titleKey:"settings.magicPrompts.page.block.visiblePrompt"},{id:"plan.todo.instructions",titleKey:"settings.magicPrompts.page.block.instructions"}]},"plan.implement":{titleKey:"settings.magicPrompts.page.group.planImplement.title",descriptionKey:"settings.magicPrompts.page.group.planImplement.description",blocks:[{id:"plan.implement.visible",titleKey:"settings.magicPrompts.page.block.visiblePrompt"},{id:"plan.implement.instructions",titleKey:"settings.magicPrompts.page.block.instructions"}]},"session.summary":{titleKey:"settings.magicPrompts.page.group.sessionSummary.title",descriptionKey:"settings.magicPrompts.page.group.sessionSummary.description",blocks:[{id:"session.summary.visible",titleKey:"settings.magicPrompts.page.block.visiblePrompt"},{id:"session.summary.instructions",titleKey:"settings.magicPrompts.page.block.instructions"}]},"session.review":{titleKey:"settings.magicPrompts.page.group.sessionWorkspaceReview.title",descriptionKey:"settings.magicPrompts.page.group.sessionWorkspaceReview.description",blocks:[{id:"session.review.visible",titleKey:"settings.magicPrompts.page.block.visiblePrompt"},{id:"session.review.instructions",titleKey:"settings.magicPrompts.page.block.instructions"}]},"session.plan":{titleKey:"settings.magicPrompts.page.group.sessionFeaturePlan.title",descriptionKey:"settings.magicPrompts.page.group.sessionFeaturePlan.description",blocks:[{id:"session.plan.visible",titleKey:"settings.magicPrompts.page.block.visiblePrompt"},{id:"session.plan.instructions",titleKey:"settings.magicPrompts.page.block.instructions"}]},"session.craftGoal":{titleKey:"settings.magicPrompts.page.group.sessionCraftGoal.title",descriptionKey:"settings.magicPrompts.page.group.sessionCraftGoal.description",blocks:[{id:"session.craftGoal.visible",titleKey:"settings.magicPrompts.page.block.visiblePrompt"},{id:"session.craftGoal.instructions",titleKey:"settings.magicPrompts.page.block.instructions"}]},"session.catchup":{titleKey:"settings.magicPrompts.page.group.sessionCatchUp.title",descriptionKey:"settings.magicPrompts.page.group.sessionCatchUp.description",blocks:[{id:"session.catchup.visible",titleKey:"settings.magicPrompts.page.block.visiblePrompt"},{id:"session.catchup.instructions",titleKey:"settings.magicPrompts.page.block.instructions"}]},"session.debug":{titleKey:"settings.magicPrompts.page.group.sessionDebug.title",descriptionKey:"settings.magicPrompts.page.group.sessionDebug.description",blocks:[{id:"session.debug.visible",titleKey:"settings.magicPrompts.page.block.visiblePrompt"},{id:"session.debug.instructions",titleKey:"settings.magicPrompts.page.block.instructions"}]},"session.weigh":{titleKey:"settings.magicPrompts.page.group.sessionWeigh.title",descriptionKey:"settings.magicPrompts.page.group.sessionWeigh.description",blocks:[{id:"session.weigh.visible",titleKey:"settings.magicPrompts.page.block.visiblePrompt"},{id:"session.weigh.instructions",titleKey:"settings.magicPrompts.page.block.instructions"}]},"session.explore":{titleKey:"settings.magicPrompts.page.group.sessionExplore.title",descriptionKey:"settings.magicPrompts.page.group.sessionExplore.description",blocks:[{id:"session.explore.visible",titleKey:"settings.magicPrompts.page.block.visiblePrompt"},{id:"session.explore.instructions",titleKey:"settings.magicPrompts.page.block.instructions"}]},"session.fusion":{titleKey:"settings.magicPrompts.page.group.sessionFusion.title",descriptionKey:"settings.magicPrompts.page.group.sessionFusion.description",blocks:[{id:"session.fusion.visible",titleKey:"settings.magicPrompts.page.block.visiblePrompt"},{id:"session.fusion.instructions",titleKey:"settings.magicPrompts.page.block.instructions"}]}},qo=(t,e)=>Object.prototype.hasOwnProperty.call(t,e),sr=t=>t.endsWith(".visible"),sh=()=>{const{t}=tt(),e=o.useCallback(j=>t(j),[t]),a=xr(j=>j.selectedPromptId),[n,r]=o.useState(!0),[i,l]=o.useState({}),[g,c]=o.useState({}),[y,p]=o.useState({}),[b,d]=o.useState({}),[P,f]=o.useState(!1);o.useEffect(()=>{let j=!0;return(async()=>{r(!0);try{const w=await qc();if(!j)return;l(w)}catch(w){console.warn("Failed to load magic prompts:",w),E.error(t("settings.magicPrompts.page.toast.loadFailed"))}finally{j&&r(!1)}})(),()=>{j=!1}},[t]);const C=Wo[a]??Wo["git.commit.generate"],v=o.useCallback(j=>qo(i,j)?i[j]:Hi(j),[i]),N=o.useCallback(j=>g[j]??v(j),[g,v]),m=o.useCallback((j,h)=>{c(w=>w[j]===h?w:{...w,[j]:h})},[]),A=o.useCallback(async j=>{const h=N(j);if(sr(j)&&h.trim().length===0){E.error(t("settings.magicPrompts.page.toast.visiblePromptRequired"));return}p(w=>({...w,[j]:!0}));try{const w=h===Hi(j)?await _r(j):await Hc(j,h);l(w.overrides),E.success(t("settings.magicPrompts.page.toast.saved"))}catch(w){const F=w instanceof Error?w.message:String(w);E.error(t("settings.magicPrompts.page.toast.saveFailed"),{description:F})}finally{p(w=>({...w,[j]:!1}))}},[N,t]),R=o.useCallback(async j=>{d(h=>({...h,[j]:!0}));try{const h=await _r(j);l(h.overrides),c(w=>({...w,[j]:Hi(j)})),E.success(t("settings.magicPrompts.page.toast.resetSuccess"))}catch(h){const w=h instanceof Error?h.message:String(h);E.error(t("settings.magicPrompts.page.toast.resetFailed"),{description:w})}finally{d(h=>({...h,[j]:!1}))}},[t]),I=o.useCallback(async()=>{f(!0);try{const j=await Gc();l(j.overrides),c({}),E.success(t("settings.magicPrompts.page.toast.resetAllSuccess"))}catch(j){const h=j instanceof Error?j.message:String(j);E.error(t("settings.magicPrompts.page.toast.resetAllFailed"),{description:h})}finally{f(!1)}},[t]);return n?s.jsxs("div",{className:"py-6 px-6 flex items-center gap-2 text-muted-foreground",children:[s.jsx("span",{className:"inline-block h-1.5 w-1.5 rounded-full bg-current animate-busy-pulse","aria-label":t("settings.magicPrompts.page.loading.aria")}),s.jsx("span",{className:"typography-ui",children:t("settings.magicPrompts.page.loading.text")})]}):s.jsx(es,{title:e(C.titleKey),titleAccessory:s.jsx(Jt,{contentClassName:"max-w-xs",children:e(C.descriptionKey)}),headerEnd:s.jsx(V,{"data-settings-item":"magic-prompts.reset-overrides",variant:"outline",size:"sm",onClick:()=>{I()},disabled:P||Object.keys(i).length===0,children:t(P?"settings.magicPrompts.page.actions.resetting":"settings.magicPrompts.page.actions.resetAllOverrides")}),showSaveStatus:!1,children:C.blocks.map((j,h)=>{const w=Wc(j.id),F=v(j.id),T=N(j.id),S=qo(i,j.id),D=T!==F,$=sr(j.id)&&T.trim().length===0,B=y[j.id]===!0,k=b[j.id]===!0;return s.jsxs(ze,{title:e(j.titleKey),info:w.description,description:w.placeholders&&w.placeholders.length>0?`${t("settings.magicPrompts.page.placeholdersLabel")} ${w.placeholders.map(G=>`{{${G.key}}}`).join(", ")}`:void 0,divider:h>0,settingsItem:sr(j.id)?"magic-prompts.visible-prompt":"magic-prompts.instructions",contentClassName:"space-y-3",children:[s.jsx(Ts,{value:T,onChange:G=>m(j.id,G.target.value),className:"min-h-[220px] font-mono text-sm"}),$&&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(D?"settings.magicPrompts.page.status.unsavedChanges":S?"settings.magicPrompts.page.status.usingSavedOverride":"settings.magicPrompts.page.status.usingBuiltinDefault")}),s.jsxs("div",{className:"flex items-center gap-2",children:[s.jsx(V,{variant:"outline",size:"sm",onClick:()=>{R(j.id)},disabled:!S||B||k,children:t(k?"settings.magicPrompts.page.actions.resetting":"settings.magicPrompts.page.actions.resetToDefault")}),s.jsx(V,{size:"sm",onClick:()=>{A(j.id)},disabled:!D||B||k||$,children:t(B?"settings.common.actions.saving":"settings.magicPrompts.page.actions.save")})]})]})]},j.id)})})},nh=t=>{const e=ut.c(89),{onItemSelect:a}=t,{t:n}=tt(),[r,i]=o.useState(null),[l,g]=o.useState(null),[c,y]=o.useState(null),{selectedSnippetName:p,snippets:b,setSelectedSnippet:d,setSnippetDraft:P,deleteSnippet:f,loadSnippets:C}=Si(Us(ah));let v,N;e[0]!==C?(v=()=>{C()},N=[C],e[0]=C,e[1]=v,e[2]=N):(v=e[1],N=e[2]),o.useEffect(v,N);let m;e[3]!==a||e[4]!==d||e[5]!==P||e[6]!==b?(m=async()=>{const Se=new Set(b.map(ih));let ye="new-snippet",fe=1;for(;Se.has(ye);)ye=`new-snippet-${fe++}`;P({name:ye,scope:"global"}),d(ye),a?.()},e[3]=a,e[4]=d,e[5]=P,e[6]=b,e[7]=m):m=e[7];const A=m;let R;e[8]!==r||e[9]!==f||e[10]!==n?(R=async()=>{if(!r)return;await f(r.name)?(E.success(n("settings.snippets.sidebar.toast.deleted")),i(null)):E.error(n("settings.snippets.sidebar.toast.deleteFailed"))},e[8]=r,e[9]=f,e[10]=n,e[11]=R):R=e[11];const I=R;let j;e[12]!==b?(j=[...b].sort(rh),e[12]=b,e[13]=j):j=e[13];const h=j;let w;e[14]===Symbol.for("react.memo_cache_sentinel")?(w=xe("flex h-full flex-col","bg-background"),e[14]=w):w=e[14];let F;e[15]!==n?(F=n("settings.snippets.sidebar.title"),e[15]=n,e[16]=F):F=e[16];let T;e[17]!==F?(T=s.jsx("h2",{className:`${un} mb-3`,children:F}),e[17]=F,e[18]=T):T=e[18];let S;e[19]!==b.length||e[20]!==n?(S=n("settings.snippets.sidebar.total",{count:b.length}),e[19]=b.length,e[20]=n,e[21]=S):S=e[21];let D;e[22]!==S?(D=s.jsx("span",{className:"typography-meta text-muted-foreground",children:S}),e[22]=S,e[23]=D):D=e[23];let $;e[24]!==n?($=n("settings.snippets.sidebar.actions.create"),e[24]=n,e[25]=$):$=e[25];let B;e[26]===Symbol.for("react.memo_cache_sentinel")?(B=s.jsx(O,{name:"add",className:"h-3.5 w-3.5"}),e[26]=B):B=e[26];let k;e[27]!==A||e[28]!==$?(k=s.jsx(V,{size:"sm","data-settings-item":"snippets.create",variant:"ghost",className:"h-7 w-7 px-0 -my-1 text-muted-foreground",onClick:A,"aria-label":$,children:B}),e[27]=A,e[28]=$,e[29]=k):k=e[29];let G;e[30]!==D||e[31]!==k?(G=s.jsxs("div",{className:"flex items-center justify-between gap-2",children:[D,k]}),e[30]=D,e[31]=k,e[32]=G):G=e[32];let M;e[33]!==G||e[34]!==T?(M=s.jsxs("div",{className:"border-b px-3 pt-4 pb-3",children:[T,G]}),e[33]=G,e[34]=T,e[35]=M):M=e[35];let L;if(e[36]!==a||e[37]!==l||e[38]!==c||e[39]!==p||e[40]!==d||e[41]!==h||e[42]!==n){let Se;e[44]!==a||e[45]!==l||e[46]!==c||e[47]!==p||e[48]!==d||e[49]!==n?(Se=ye=>s.jsxs(Qn,{open:c===ye.name,onOpenChange:fe=>y(fe?ye.name:null),children:[s.jsxs(Jn,{render:s.jsx("div",{className:xe("group relative flex items-center rounded-md px-1.5 py-1 transition-all duration-200 select-none",p===ye.name?"bg-interactive-selection":"hover:bg-interactive-hover"),onContextMenu:fe=>{fe.preventDefault(),y(ye.name)}}),children:[s.jsxs("button",{onClick:()=>{d(ye.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:["#",ye.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.${ye.source}`)})]}),s.jsx("div",{className:"typography-micro text-muted-foreground/60 truncate leading-tight",children:ye.description||ye.content.replace(/\s+/g," ").substring(0,80)})]}),s.jsxs(cn,{open:l===ye.name,onOpenChange:fe=>{fe&&y(null),g(fe?ye.name:null)},children:[s.jsx(on,{asChild:!0,children:s.jsx(V,{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:ye.name}),children:s.jsx(O,{name:"more-2",className:"h-3.5 w-3.5"})})}),s.jsx(ln,{align:"end",className:"w-fit min-w-20",children:s.jsxs(dn,{onClick:fe=>{fe.stopPropagation(),i(ye)},className:"text-destructive focus:text-destructive",children:[s.jsx(O,{name:"delete-bin",className:"h-4 w-4 mr-px"}),n("settings.common.actions.delete")]})})]})]}),s.jsx(Wn,{className:"w-fit min-w-20",children:s.jsxs(qn,{onClick:fe=>{fe.stopPropagation(),i(ye)},className:"text-destructive focus:text-destructive",children:[s.jsx(O,{name:"delete-bin",className:"h-4 w-4 mr-px"}),n("settings.common.actions.delete")]})})]},`${ye.source}:${ye.filePath}`),e[44]=a,e[45]=l,e[46]=c,e[47]=p,e[48]=d,e[49]=n,e[50]=Se):Se=e[50],L=h.map(Se),e[36]=a,e[37]=l,e[38]=c,e[39]=p,e[40]=d,e[41]=h,e[42]=n,e[43]=L}else L=e[43];let J;e[51]!==L?(J=s.jsx(vs,{outerClassName:"flex-1 min-h-0",className:"space-y-1 px-3 py-2",children:L}),e[51]=L,e[52]=J):J=e[52];const ee=r!==null;let U;e[53]===Symbol.for("react.memo_cache_sentinel")?(U=Se=>{Se||i(null)},e[53]=U):U=e[53];let le;e[54]!==n?(le=n("settings.snippets.sidebar.dialog.deleteTitle"),e[54]=n,e[55]=le):le=e[55];let _;e[56]!==le?(_=s.jsx($t,{children:le}),e[56]=le,e[57]=_):_=e[57];const H=r?.name??"";let z;e[58]!==n||e[59]!==H?(z=n("settings.snippets.sidebar.dialog.deleteDescription",{name:H}),e[58]=n,e[59]=H,e[60]=z):z=e[60];let K;e[61]!==z?(K=s.jsx(Vt,{children:z}),e[61]=z,e[62]=K):K=e[62];let te;e[63]!==_||e[64]!==K?(te=s.jsxs(_t,{children:[_,K]}),e[63]=_,e[64]=K,e[65]=te):te=e[65];let Y;e[66]===Symbol.for("react.memo_cache_sentinel")?(Y=()=>i(null),e[66]=Y):Y=e[66];let ae;e[67]!==n?(ae=n("settings.common.actions.cancel"),e[67]=n,e[68]=ae):ae=e[68];let ge;e[69]!==ae?(ge=s.jsx(V,{size:"sm",variant:"ghost",onClick:Y,children:ae}),e[69]=ae,e[70]=ge):ge=e[70];let de;e[71]!==n?(de=n("settings.common.actions.delete"),e[71]=n,e[72]=de):de=e[72];let he;e[73]!==I||e[74]!==de?(he=s.jsx(V,{size:"sm",onClick:I,children:de}),e[73]=I,e[74]=de,e[75]=he):he=e[75];let se;e[76]!==ge||e[77]!==he?(se=s.jsxs(ts,{children:[ge,he]}),e[76]=ge,e[77]=he,e[78]=se):se=e[78];let re;e[79]!==te||e[80]!==se?(re=s.jsxs(zt,{className:"max-w-md",children:[te,se]}),e[79]=te,e[80]=se,e[81]=re):re=e[81];let ue;e[82]!==ee||e[83]!==re?(ue=s.jsx(Kt,{open:ee,onOpenChange:U,children:re}),e[82]=ee,e[83]=re,e[84]=ue):ue=e[84];let Ce;return e[85]!==M||e[86]!==J||e[87]!==ue?(Ce=s.jsxs("div",{className:w,children:[M,J,ue]}),e[85]=M,e[86]=J,e[87]=ue,e[88]=Ce):Ce=e[88],Ce};function ah(t){return{selectedSnippetName:t.selectedSnippetName,snippets:t.snippets,setSelectedSnippet:t.setSelectedSnippet,setSnippetDraft:t.setSnippetDraft,deleteSnippet:t.deleteSnippet,loadSnippets:t.loadSnippets}}function ih(t){return t.name}function rh(t,e){return t.name.localeCompare(e.name)}const oh=()=>{const{t}=tt(),{selectedSnippetName:e,snippets:a,snippetDraft:n,setSnippetDraft:r,updateSnippet:i,createSnippet:l}=Si(Us(w=>({selectedSnippetName:w.selectedSnippetName,snippets:w.snippets,snippetDraft:w.snippetDraft,setSnippetDraft:w.setSnippetDraft,updateSnippet:w.updateSnippet,createSnippet:w.createSnippet}))),g=o.useMemo(()=>e?a.find(w=>w.name===e||w.aliases.includes(e))??null:null,[e,a]),c=!!(n&&n.name===e&&!g),[y,p]=o.useState(""),[b,d]=o.useState("global"),[P,f]=o.useState(""),[C,v]=o.useState(""),[N,m]=o.useState(""),[A,R]=o.useState(!1),I=o.useRef(null);o.useEffect(()=>{if(c&&n){const w={draftName:n.name||"",draftScope:n.scope||"global",description:n.description||"",aliases:(n.aliases||[]).join(", "),content:n.content||""};p(w.draftName),d(w.draftScope),f(w.description),v(w.aliases),m(w.content),I.current=w}else if(g){const w={draftName:"",draftScope:"global",description:g.description??"",aliases:g.aliases.join(", "),content:g.content};f(w.description),v(w.aliases),m(w.content),I.current=w}},[g,c,e,n]);const j=o.useMemo(()=>{const w=I.current;return w?c&&y!==w.draftName||c&&b!==w.draftScope?!0:P!==w.description||C!==w.aliases||N!==w.content:!1},[C,N,P,y,b,c]),h=async()=>{const w=c?y.trim().replace(/\s+/g,"-"):e?.trim();if(!w){E.error(t("settings.snippets.page.toast.nameRequired"));return}if(!N.trim()){E.error(t("settings.snippets.page.toast.contentRequired"));return}const F=C.split(",").map(T=>T.trim()).filter(Boolean);R(!0);try{if(!(c?await l(w,N,{aliases:F,description:P,scope:b}):await i(w,{content:N,aliases:F,description:P}))){E.error(t("settings.snippets.page.toast.saveFailed"));return}E.success(t("settings.snippets.page.toast.saved")),c&&r(null)}finally{R(!1)}};return e?s.jsxs(es,{title:c?t("settings.snippets.page.title.new"):`#${e}`,description:g?g.filePath:void 0,showSaveStatus:!1,children:[s.jsxs(ze,{divider:!1,contentClassName:"space-y-0",children:[c?s.jsxs(Rt,{label:"#",children:[s.jsx(He,{value:y,onChange:w=>p(w.target.value),placeholder:t("settings.snippets.page.field.namePlaceholder"),className:"h-7 w-44 px-2"}),s.jsxs(St,{value:b,onValueChange:w=>d(w),children:[s.jsx(Ct,{size:Ft,className:"w-fit min-w-[100px]",children:s.jsx(Mt,{})}),s.jsxs(It,{align:"end",children:[s.jsx(at,{value:"global",children:t("settings.common.scope.global")}),s.jsx(at,{value:"project",children:t("settings.common.scope.project")})]})]})]}):null,s.jsx(qt,{label:t("settings.common.field.description"),children:s.jsx(He,{value:P,onChange:w=>f(w.target.value),placeholder:t("settings.snippets.page.field.descriptionPlaceholder"),className:"h-7 w-full max-w-sm px-2"})}),s.jsx(qt,{label:t("settings.snippets.page.field.aliases"),children:s.jsx(He,{value:C,onChange:w=>v(w.target.value),placeholder:t("settings.snippets.page.field.aliasesPlaceholder"),className:"h-7 w-full max-w-sm px-2"})})]}),s.jsxs(ze,{settingsItem:"snippets.content",children:[s.jsxs("div",{className:"flex items-center gap-1",children:[s.jsx("span",{className:"typography-ui-label text-foreground",children:t("settings.snippets.page.field.content")}),s.jsx(Jt,{children:t("settings.snippets.page.hint")})]}),s.jsx(Ts,{value:N,onChange:w=>m(w.target.value),placeholder:t("settings.snippets.page.field.contentPlaceholder"),rows:12,className:"mt-1.5 w-full font-mono typography-meta min-h-[160px] max-h-[60vh] bg-transparent"}),s.jsx("div",{className:"pt-3",children:s.jsx(V,{onClick:h,disabled:A||!j,size:"xs",className:"!font-normal",children:t(A?"settings.common.actions.saving":"settings.common.actions.saveChanges")})})]})]}):s.jsx("div",{className:"flex h-full items-center justify-center",children:s.jsxs("div",{className:"text-center text-muted-foreground",children:[s.jsx(O,{name:"file-text",className:"mx-auto mb-3 h-12 w-12 opacity-50"}),s.jsx("p",{className:"typography-body",children:t("settings.snippets.page.empty.title")}),s.jsx("p",{className:"typography-meta mt-1 opacity-75",children:t("settings.snippets.page.empty.description")})]})})},Xl=()=>{const{t}=tt(),e=Ye(b=>b.settingsGitmojiEnabled),a=Ye(b=>b.setSettingsGitmojiEnabled),n=Id(),r=ie(b=>b.gitChangesViewMode),i=ie(b=>b.setGitChangesViewMode),[l,g]=o.useState(!0),c=o.useMemo(()=>[{id:"flat",label:t("settings.aiworker.git.option.flatList")},{id:"tree",label:t("settings.aiworker.git.option.treeView")}],[t]);o.useEffect(()=>{(async()=>{try{const d=await pn();d&&(d.gitmojiEnabled!==void 0&&a(d.gitmojiEnabled),d.gitChangesViewMode!==void 0&&i(d.gitChangesViewMode))}catch(d){console.warn("Failed to load git settings:",d)}finally{g(!1)}})()},[i,a]);const y=o.useCallback(async b=>{a(b);try{await gt({gitmojiEnabled:b})}catch(d){console.warn("Failed to save gitmoji setting:",d)}},[a]),p=o.useCallback(b=>{b!==r&&(i(b),gt({gitChangesViewMode:b}))},[r,i]);return l?null:s.jsx(ze,{title:t("settings.aiworker.git.title"),children:s.jsxs("div",{className:fs,children:[s.jsx(Ss,{settingsItem:"git.changes-view",title:t("settings.aiworker.git.changesViewTitle"),children:s.jsx(Js,{"aria-label":t("settings.aiworker.git.changesViewAria"),children:c.map(b=>s.jsx(Bs,{selected:r===b.id,onSelect:()=>{p(b.id)},label:b.label,ariaLabel:t("settings.aiworker.git.optionAria",{option:b.label})},b.id))})}),s.jsx(dt,{settingsItem:"git.gitmoji",checked:e,onChange:b=>{y(b)},label:t("settings.aiworker.git.enableGitmoji"),ariaLabel:t("settings.aiworker.git.enableGitmojiAria")}),s.jsx(dt,{settingsItem:"git.gitignored-files",checked:n,onChange:Pd,label:t("settings.aiworker.git.showGitignored"),ariaLabel:t("settings.aiworker.git.showGitignoredAria")})]})})},Jo=[{key:"keyword",label:"Green",cssVar:"var(--syntax-keyword)"},{key:"error",label:"Red",cssVar:"var(--status-error)"},{key:"string",label:"Cyan",cssVar:"var(--syntax-string)"},{key:"function",label:"Orange",cssVar:"var(--syntax-function)"},{key:"type",label:"Yellow",cssVar:"var(--syntax-type)"}],lh=[{key:"branch",Icon:"git-branch",label:"Branch"},{key:"briefcase",Icon:"briefcase",label:"Work"},{key:"house",Icon:"home",label:"Personal"},{key:"graduation",Icon:"graduation-cap",label:"School"},{key:"code",Icon:"code",label:"Code"}],ch=({open:t,onOpenChange:e,profileId:a,importData:n})=>{const{t:r}=tt(),i=_n(K=>K.getProfileById),l=_n(K=>K.createProfile),g=_n(K=>K.updateProfile),c=_n(K=>K.deleteProfile),y=o.useMemo(()=>a&&a!=="new"&&!n?i(a):null,[a,i,n]),p=a==="new"||n!=null,b=a==="global",[d,P]=o.useState(""),[f,C]=o.useState(""),[v,N]=o.useState(""),[m,A]=o.useState("ssh"),[R,I]=o.useState(""),[j,h]=o.useState(!1),[w,F]=o.useState(""),[T,S]=o.useState(""),[D,$]=o.useState("keyword"),[B,k]=o.useState("branch"),[G,M]=o.useState(!1),[L,J]=o.useState(!1),[ee,U]=o.useState(!1);o.useEffect(()=>{if(t){if(n){const K=n.host.split("/"),te=K.length>=3?K[K.length-1]:n.host;P(te),C(n.username),N(""),A("token"),I(""),h(!1),F(""),S(n.host),$("string"),k("code")}else if(p)P(""),C(""),N(""),A("ssh"),I(""),h(!1),F(""),S(""),$("keyword"),k("branch");else if(y)P(y.name),C(y.userName),N(y.userEmail),A(y.authType||"ssh"),I(y.sshKey||""),h(y.signCommits===!0),F(y.signingKey||""),S(y.host||""),$(y.color||"keyword"),k(y.icon||"branch");else if(b){const K=i("global");K&&(P(K.name),C(K.userName),N(K.userEmail),A(K.authType||"ssh"),I(K.sshKey||""),h(!1),F(""),S(K.host||""),$(K.color||"keyword"),k(K.icon||"branch"))}}},[t,a,y,p,n,b,i]);const le=async()=>{if(!f.trim()||!v.trim()){E.error(r("settings.gitIdentities.editor.toast.userNameEmailRequired"));return}if(m==="token"&&!T.trim()){E.error(r("settings.gitIdentities.editor.toast.hostRequiredForToken"));return}if(j&&!w.trim()){E.error(r("settings.gitIdentities.editor.toast.signingKeyRequired"));return}M(!0);try{const K={name:d.trim()||f.trim(),userName:f.trim(),userEmail:v.trim(),authType:m,sshKey:m==="ssh"&&R.trim()||null,signCommits:j,signingKey:w.trim()||null,host:m==="token"&&T.trim()||null,color:D,icon:B};let te;if(p)te=await l(K);else if(a)te=await g(a,K);else return;te?(E.success(r(p?"settings.gitIdentities.editor.toast.profileCreated":"settings.gitIdentities.editor.toast.profileUpdated")),e(!1)):E.error(r(p?"settings.gitIdentities.editor.toast.createProfileFailed":"settings.gitIdentities.editor.toast.updateProfileFailed"))}catch(K){console.error("Error saving profile:",K),E.error(r("settings.gitIdentities.editor.toast.saveUnexpectedError"))}finally{M(!1)}},_=async()=>{if(!(!a||p)){U(!0);try{await c(a)?(E.success(r("settings.gitIdentities.editor.toast.profileDeleted")),J(!1),e(!1)):E.error(r("settings.gitIdentities.editor.toast.deleteProfileFailed"))}catch(K){console.error("Error deleting profile:",K),E.error(r("settings.gitIdentities.editor.toast.deleteUnexpectedError"))}finally{U(!1)}}},H=o.useMemo(()=>Jo.find(te=>te.key===D)?.cssVar||"var(--syntax-keyword)",[D]),z=n?r("settings.gitIdentities.editor.title.importCredential"):p?r("settings.gitIdentities.editor.title.newIdentity"):b?r("settings.gitIdentities.editor.title.globalIdentity"):y?.name||r("settings.gitIdentities.editor.title.editIdentity");return s.jsxs(s.Fragment,{children:[s.jsx(Kt,{open:t,onOpenChange:e,children:s.jsxs(zt,{className:"max-w-lg max-h-[85vh] overflow-y-auto",children:[s.jsxs(_t,{children:[s.jsx($t,{children:z}),s.jsx(Vt,{children:r(b?"settings.gitIdentities.editor.description.globalReadOnly":p?"settings.gitIdentities.editor.description.newProfile":"settings.gitIdentities.editor.description.editProfile")})]}),s.jsxs("div",{className:"space-y-5 py-2",children:[!b&&s.jsxs("div",{className:"space-y-3",children:[s.jsxs("div",{children:[s.jsx("label",{className:`${Tt} block mb-1.5`,children:r("settings.gitIdentities.editor.field.profileName")}),s.jsx(He,{value:d,onChange:K=>P(K.target.value),placeholder:r("settings.gitIdentities.editor.field.profileNamePlaceholder"),className:"h-8"})]}),s.jsxs("div",{className:"flex items-center justify-between gap-4",children:[s.jsx("span",{className:"typography-ui-label text-foreground",children:r("settings.gitIdentities.editor.field.color")}),s.jsx("div",{className:"flex gap-1.5",children:Jo.map(K=>s.jsx("button",{type:"button",onClick:()=>$(K.key),className:xe("w-6 h-6 rounded-md border-2 transition-all cursor-pointer",D===K.key?"border-foreground scale-110":"border-transparent hover:border-border"),style:{backgroundColor:K.cssVar},title:K.label},K.key))})]}),s.jsxs("div",{className:"flex items-center justify-between gap-4",children:[s.jsx("span",{className:"typography-ui-label text-foreground",children:r("settings.gitIdentities.editor.field.icon")}),s.jsx("div",{className:"flex gap-1.5",children:lh.map(K=>{const te=K.Icon;return s.jsx("button",{type:"button",onClick:()=>k(K.key),className:xe("w-7 h-7 rounded-md border-2 transition-all flex items-center justify-center cursor-pointer",B===K.key?"border-[var(--interactive-border)] bg-[var(--surface-muted)]":"border-transparent hover:border-[var(--interactive-border)] hover:bg-[var(--surface-muted)]/50"),title:K.label,children:s.jsx(O,{name:te,className:"w-3.5 h-3.5",style:{color:B===K.key?H:"var(--surface-muted-foreground)"}})},K.key)})})]})]}),!b&&s.jsx("div",{className:"border-t border-border/40"}),s.jsxs("div",{className:"space-y-3",children:[s.jsxs("div",{children:[s.jsxs("div",{className:"flex items-center gap-1.5 mb-1.5",children:[s.jsx("label",{className:Tt,children:r("settings.gitIdentities.editor.field.userName")}),!b&&s.jsx("span",{className:"text-[var(--status-error)] text-xs",children:"*"}),s.jsx(Jt,{contentClassName:"max-w-xs",children:r("settings.gitIdentities.editor.field.userNameTooltip")})]}),s.jsx(He,{value:f,onChange:K=>C(K.target.value),placeholder:r("settings.gitIdentities.editor.field.userNamePlaceholder"),required:!b,readOnly:b,disabled:b,className:"h-8"})]}),s.jsxs("div",{children:[s.jsxs("div",{className:"flex items-center gap-1.5 mb-1.5",children:[s.jsx("label",{className:Tt,children:r("settings.gitIdentities.editor.field.emailAddress")}),!b&&s.jsx("span",{className:"text-[var(--status-error)] text-xs",children:"*"}),s.jsx(Jt,{contentClassName:"max-w-xs",children:r("settings.gitIdentities.editor.field.emailAddressTooltip")})]}),s.jsx(He,{type:"email",value:v,onChange:K=>N(K.target.value),placeholder:r("settings.gitIdentities.editor.field.emailAddressPlaceholder"),required:!b,readOnly:b,disabled:b,className:"h-8"})]})]}),!b&&s.jsxs(s.Fragment,{children:[s.jsx("div",{className:"border-t border-border/40"}),s.jsxs("div",{className:"space-y-3",children:[s.jsxs("div",{className:"flex items-center justify-between gap-4",children:[s.jsx("span",{className:"typography-ui-label text-foreground",children:r("settings.gitIdentities.editor.field.authMethod")}),s.jsxs("div",{className:"flex items-center gap-1",children:[s.jsxs(V,{size:"sm",type:"button",variant:"chip","aria-pressed":m==="ssh",onClick:()=>A("ssh"),children:[s.jsx(O,{name:"lock-2",className:"w-3.5 h-3.5 mr-1"})," SSH"]}),s.jsxs(V,{size:"sm",type:"button",variant:"chip","aria-pressed":m==="token",onClick:()=>A("token"),children:[s.jsx(O,{name:"key",className:"w-3.5 h-3.5 mr-1"})," ",r("settings.gitIdentities.editor.field.authToken")]})]})]}),m==="ssh"&&s.jsxs("div",{children:[s.jsxs("div",{className:"flex items-center gap-1.5 mb-1.5",children:[s.jsx("label",{className:Tt,children:r("settings.gitIdentities.editor.field.sshKeyPath")}),s.jsx(Jt,{contentClassName:"max-w-xs",children:r("settings.gitIdentities.editor.field.sshKeyPathTooltip")})]}),s.jsx(He,{value:R,onChange:K=>I(K.target.value),placeholder:r("settings.gitIdentities.editor.field.sshKeyPathPlaceholder"),className:"h-8 font-mono text-xs"})]}),s.jsxs("div",{className:"border-t border-border/40 pt-3 space-y-3",children:[s.jsx(dt,{checked:j,onChange:h,label:r("settings.gitIdentities.editor.field.signCommits"),info:r("settings.gitIdentities.editor.section.commitSigning"),ariaLabel:r("settings.gitIdentities.editor.field.signCommits")}),s.jsxs("div",{children:[s.jsx("div",{className:"flex items-center gap-1.5 mb-1.5",children:s.jsx("label",{className:Tt,children:r("settings.gitIdentities.editor.field.signingKey")})}),s.jsx(He,{value:w,onChange:K=>F(K.target.value),placeholder:r("settings.gitIdentities.editor.field.signingKeyPlaceholder"),disabled:!j,className:"h-8 font-mono text-xs"})]})]}),m==="token"&&s.jsxs("div",{children:[s.jsxs("div",{className:"flex items-center gap-1.5 mb-1.5",children:[s.jsx("label",{className:Tt,children:r("settings.gitIdentities.editor.field.host")}),s.jsx("span",{className:"text-[var(--status-error)] text-xs",children:"*"}),s.jsx(Jt,{contentClassName:"max-w-xs",children:r("settings.gitIdentities.editor.field.hostTooltip")})]}),s.jsx(He,{value:T,onChange:K=>S(K.target.value),placeholder:r("settings.gitIdentities.editor.field.hostPlaceholder"),required:!0,className:"h-8 font-mono text-xs"})]})]})]})]}),s.jsxs(ts,{className:"gap-2",children:[!b&&!p&&s.jsxs(V,{variant:"outline",size:"sm",onClick:()=>J(!0),className:"text-[var(--status-error)] hover:text-[var(--status-error)] border-[var(--status-error)]/30 hover:bg-[var(--status-error)]/10 mr-auto",children:[s.jsx(O,{name:"delete-bin",className:"w-3.5 h-3.5 mr-1"})," ",r("settings.common.actions.delete")]}),s.jsx(V,{variant:"ghost",size:"sm",onClick:()=>e(!1),className:"text-foreground hover:bg-interactive-hover hover:text-foreground",children:r(b?"settings.gitIdentities.editor.actions.close":"settings.common.actions.cancel")}),!b&&s.jsx(V,{size:"sm",onClick:le,disabled:G,children:r(G?"settings.common.actions.saving":p?"settings.gitIdentities.editor.actions.create":"settings.gitIdentities.editor.actions.save")})]})]})}),s.jsx(Kt,{open:L,onOpenChange:K=>{ee||J(K)},children:s.jsxs(zt,{className:"max-w-md",children:[s.jsxs(_t,{children:[s.jsx($t,{children:r("settings.gitIdentities.page.deleteDialog.title")}),s.jsx(Vt,{children:r("settings.gitIdentities.page.deleteDialog.description",{name:y?.name||d})})]}),s.jsxs(ts,{children:[s.jsx(V,{variant:"ghost",onClick:()=>J(!1),disabled:ee,children:r("settings.common.actions.cancel")}),s.jsx(V,{size:"sm",variant:"destructive",onClick:()=>{_()},disabled:ee,children:r("settings.common.actions.delete")})]})]})})]})},dh={branch:"git-branch",briefcase:"briefcase",house:"home",graduation:"graduation-cap",code:"code",heart:"heart"},uh={keyword:"var(--syntax-keyword)",error:"var(--status-error)",string:"var(--syntax-string)",function:"var(--syntax-function)",type:"var(--syntax-type)"},ph=()=>{const t=ut.c(112),{t:e}=tt(),{profiles:a,globalIdentity:n,defaultGitIdentityId:r,deleteProfile:i,loadProfiles:l,loadGlobalIdentity:g,loadDiscoveredCredentials:c,loadDefaultGitIdentityId:y,setDefaultGitIdentityId:p,getUnimportedCredentials:b}=_n(Us(gh)),[d,P]=o.useState(!1),[f,C]=o.useState(null),[v,N]=o.useState(null),[m,A]=o.useState(null),[R,I]=o.useState(!1);let j,h;t[0]!==y||t[1]!==c||t[2]!==g||t[3]!==l?(j=()=>{l(),g(),c(),y()},h=[l,g,c,y],t[0]=y,t[1]=c,t[2]=g,t[3]=l,t[4]=j,t[5]=h):(j=t[4],h=t[5]),o.useEffect(j,h);let w,F,T,S,D,$,B,k,G,M,L,J,ee,U;if(t[6]!==r||t[7]!==m||t[8]!==i||t[9]!==b||t[10]!==n||t[11]!==a||t[12]!==p||t[13]!==e){const Ge=b();let ve;t[28]===Symbol.for("react.memo_cache_sentinel")?(ve=(Ee,je)=>{C(Ee),N(je??null),P(!0)},t[28]=ve):ve=t[28];const Z=ve;let ne;t[29]!==r||t[30]!==p||t[31]!==e?(ne=async Ee=>{const je=r===Ee?null:Ee;if(!await p(je)){E.error(e("settings.gitIdentities.page.toast.updateDefaultFailed"));return}E.success(e(je?"settings.gitIdentities.page.toast.defaultUpdated":"settings.gitIdentities.page.toast.defaultUnset"))},t[29]=r,t[30]=p,t[31]=e,t[32]=ne):ne=t[32];const be=ne;let we;t[33]!==m||t[34]!==i||t[35]!==e?(we=async()=>{if(!m)return;I(!0),await i(m.id)?(E.success(e("settings.gitIdentities.page.toast.profileDeleted",{name:m.name})),A(null)):E.error(e("settings.gitIdentities.page.toast.deleteProfileFailed")),I(!1)},t[33]=m,t[34]=i,t[35]=e,t[36]=we):we=t[36],T=we,F=es,t[37]!==e?(D=e("settings.page.git.title"),t[37]=e,t[38]=D):D=t[38],$=!0,w=ze,t[39]!==e?(J=e("settings.gitIdentities.page.section.title"),t[39]=e,t[40]=J):J=t[40],ee=!1;let Re,Fe;t[41]===Symbol.for("react.memo_cache_sentinel")?(Re=()=>Z("new"),Fe=s.jsx(O,{name:"add",className:"w-3.5 h-3.5 mr-1"}),t[41]=Re,t[42]=Fe):(Re=t[41],Fe=t[42]);let Ke;t[43]!==e?(Ke=e("settings.common.badge.new"),t[43]=e,t[44]=Ke):Ke=t[44],t[45]!==Ke?(U=s.jsxs(V,{size:"sm",variant:"outline",onClick:Re,children:[Fe," ",Ke]}),t[45]=Ke,t[46]=U):U=t[46],S="git.identities",B="rounded-lg bg-[var(--surface-elevated)]/70 overflow-hidden flex flex-col",k=n&&s.jsx(Qo,{profile:n,isDefault:r==="global",onEdit:()=>Z("global"),onToggleDefault:()=>be("global"),isReadOnly:!0,hasBorder:a.length>0||Ge.length>0}),G=a.map((Ee,je)=>s.jsx(Qo,{profile:Ee,isDefault:r===Ee.id,onEdit:()=>Z(Ee.id),onToggleDefault:()=>be(Ee.id),onDelete:()=>A(Ee),hasBorder:je<a.length-1||Ge.length>0},Ee.id)),M=!n&&a.length===0&&Ge.length===0&&s.jsxs("div",{className:"py-8 px-4 text-center text-muted-foreground",children:[s.jsx(O,{name:"shield-keyhole",className:"mx-auto mb-2 h-8 w-8 opacity-40"}),s.jsx("p",{className:"typography-ui-label",children:e("settings.gitIdentities.page.empty.title")}),s.jsx("p",{className:"typography-meta mt-1 opacity-75",children:e("settings.gitIdentities.page.empty.description")})]}),L=Ge.length>0&&s.jsxs(s.Fragment,{children:[s.jsx("div",{className:"px-4 py-2 border-t border-[var(--surface-subtle)]",children:s.jsx("span",{className:"typography-micro text-muted-foreground",children:e("settings.gitIdentities.page.discoveredCredentials.title")})}),Ge.map((Ee,je)=>s.jsx(mh,{credential:Ee,onImport:()=>Z("new",{host:Ee.host,username:Ee.username}),hasBorder:je<Ge.length-1},`${Ee.host}-${Ee.username}`))]}),t[6]=r,t[7]=m,t[8]=i,t[9]=b,t[10]=n,t[11]=a,t[12]=p,t[13]=e,t[14]=w,t[15]=F,t[16]=T,t[17]=S,t[18]=D,t[19]=$,t[20]=B,t[21]=k,t[22]=G,t[23]=M,t[24]=L,t[25]=J,t[26]=ee,t[27]=U}else w=t[14],F=t[15],T=t[16],S=t[17],D=t[18],$=t[19],B=t[20],k=t[21],G=t[22],M=t[23],L=t[24],J=t[25],ee=t[26],U=t[27];let le;t[47]!==B||t[48]!==k||t[49]!==G||t[50]!==M||t[51]!==L?(le=s.jsxs("div",{className:B,children:[k,G,M,L]}),t[47]=B,t[48]=k,t[49]=G,t[50]=M,t[51]=L,t[52]=le):le=t[52];let _;t[53]!==w||t[54]!==S||t[55]!==le||t[56]!==J||t[57]!==ee||t[58]!==U?(_=s.jsx(w,{title:J,divider:ee,headerAction:U,settingsItem:S,children:le}),t[53]=w,t[54]=S,t[55]=le,t[56]=J,t[57]=ee,t[58]=U,t[59]=_):_=t[59];let H;t[60]===Symbol.for("react.memo_cache_sentinel")?(H=s.jsx(Xl,{}),t[60]=H):H=t[60];let z;t[61]!==F||t[62]!==D||t[63]!==$||t[64]!==_?(z=s.jsxs(F,{title:D,showSaveStatus:$,children:[_,H]}),t[61]=F,t[62]=D,t[63]=$,t[64]=_,t[65]=z):z=t[65];let K;t[66]!==v||t[67]!==d||t[68]!==f?(K=s.jsx(ch,{open:d,onOpenChange:P,profileId:f,importData:v}),t[66]=v,t[67]=d,t[68]=f,t[69]=K):K=t[69];const te=m!==null;let Y;t[70]!==R?(Y=Ge=>{R||Ge||A(null)},t[70]=R,t[71]=Y):Y=t[71];let ae;t[72]!==e?(ae=e("settings.gitIdentities.page.deleteDialog.title"),t[72]=e,t[73]=ae):ae=t[73];let ge;t[74]!==ae?(ge=s.jsx($t,{children:ae}),t[74]=ae,t[75]=ge):ge=t[75];const de=m?.name??"";let he;t[76]!==e||t[77]!==de?(he=e("settings.gitIdentities.page.deleteDialog.description",{name:de}),t[76]=e,t[77]=de,t[78]=he):he=t[78];let se;t[79]!==he?(se=s.jsx(Vt,{children:he}),t[79]=he,t[80]=se):se=t[80];let re;t[81]!==ge||t[82]!==se?(re=s.jsxs(_t,{children:[ge,se]}),t[81]=ge,t[82]=se,t[83]=re):re=t[83];let ue;t[84]===Symbol.for("react.memo_cache_sentinel")?(ue=()=>A(null),t[84]=ue):ue=t[84];let Ce;t[85]!==e?(Ce=e("settings.common.actions.cancel"),t[85]=e,t[86]=Ce):Ce=t[86];let Se;t[87]!==R||t[88]!==Ce?(Se=s.jsx(V,{variant:"ghost",onClick:ue,disabled:R,children:Ce}),t[87]=R,t[88]=Ce,t[89]=Se):Se=t[89];let ye;t[90]!==T?(ye=()=>{T()},t[90]=T,t[91]=ye):ye=t[91];let fe;t[92]!==e?(fe=e("settings.common.actions.delete"),t[92]=e,t[93]=fe):fe=t[93];let _e;t[94]!==R||t[95]!==ye||t[96]!==fe?(_e=s.jsx(V,{size:"sm",variant:"destructive",onClick:ye,disabled:R,children:fe}),t[94]=R,t[95]=ye,t[96]=fe,t[97]=_e):_e=t[97];let Ue;t[98]!==Se||t[99]!==_e?(Ue=s.jsxs(ts,{children:[Se,_e]}),t[98]=Se,t[99]=_e,t[100]=Ue):Ue=t[100];let Ne;t[101]!==re||t[102]!==Ue?(Ne=s.jsxs(zt,{className:"max-w-md",children:[re,Ue]}),t[101]=re,t[102]=Ue,t[103]=Ne):Ne=t[103];let Oe;t[104]!==te||t[105]!==Y||t[106]!==Ne?(Oe=s.jsx(Kt,{open:te,onOpenChange:Y,children:Ne}),t[104]=te,t[105]=Y,t[106]=Ne,t[107]=Oe):Oe=t[107];let Ve;return t[108]!==z||t[109]!==K||t[110]!==Oe?(Ve=s.jsxs(s.Fragment,{children:[z,K,Oe]}),t[108]=z,t[109]=K,t[110]=Oe,t[111]=Ve):Ve=t[111],Ve},Qo=t=>{const e=ut.c(56),{profile:a,isDefault:n,onEdit:r,onToggleDefault:i,onDelete:l,isReadOnly:g,hasBorder:c}=t,{t:y}=tt(),[p,b]=o.useState(!1),d=dh[a.icon||"branch"]||"git-branch",P=uh[a.color||""],f=a.authType||"ssh";let C;e[0]!==r?(C=_=>{_.currentTarget===_.target&&(_.key!=="Enter"&&_.key!==" "||(_.preventDefault(),r()))},e[0]=r,e[1]=C):C=e[1];const v=C;let N;e[2]!==n||e[3]!==g||e[4]!==l||e[5]!==i||e[6]!==y?(N=_=>s.jsxs(s.Fragment,{children:[s.jsx(_,{onClick:H=>{H.stopPropagation(),i()},children:y(n?"settings.gitIdentities.page.actions.unsetDefault":"settings.gitIdentities.page.actions.setAsDefault")}),!g&&l&&s.jsxs(_,{onClick:H=>{H.stopPropagation(),l()},className:"text-destructive focus:text-destructive",children:[s.jsx(O,{name:"delete-bin",className:"h-4 w-4 mr-px"}),y("settings.common.actions.delete")]})]}),e[2]=n,e[3]=g,e[4]=l,e[5]=i,e[6]=y,e[7]=N):N=e[7];const m=N,A=c&&"border-b border-[var(--surface-subtle)]";let R;e[8]!==A?(R=xe("group flex items-center justify-between gap-3 px-4 py-2.5 transition-colors hover:bg-[var(--interactive-hover)]/30 cursor-pointer",A),e[8]=A,e[9]=R):R=e[9];let I;e[10]===Symbol.for("react.memo_cache_sentinel")?(I=_=>{_.preventDefault(),b(!0)},e[10]=I):I=e[10];let j;e[11]!==v||e[12]!==r||e[13]!==R?(j=s.jsx("div",{className:R,onClick:r,role:"button",tabIndex:0,onKeyDown:v,onContextMenu:I}),e[11]=v,e[12]=r,e[13]=R,e[14]=j):j=e[14];let h;e[15]!==P?(h={color:P},e[15]=P,e[16]=h):h=e[16];let w;e[17]!==d||e[18]!==h?(w=s.jsx(O,{name:d,className:"w-4 h-4 shrink-0",style:h}),e[17]=d,e[18]=h,e[19]=w):w=e[19];let F;e[20]!==a.name?(F=s.jsx("span",{className:"typography-ui-label text-foreground truncate",children:a.name}),e[20]=a.name,e[21]=F):F=e[21];let T;e[22]!==f?(T=s.jsx("span",{className:"typography-micro text-muted-foreground bg-muted px-1 rounded flex-shrink-0 leading-none pb-px border border-border/50",children:f}),e[22]=f,e[23]=T):T=e[23];let S;e[24]!==n||e[25]!==y?(S=n&&s.jsx("span",{className:"typography-micro text-primary bg-primary/12 px-1 rounded flex-shrink-0 leading-none pb-px border border-primary/25",children:y("settings.gitIdentities.page.badge.default")}),e[24]=n,e[25]=y,e[26]=S):S=e[26];let D;e[27]!==g||e[28]!==y?(D=g&&s.jsx("span",{className:"typography-micro text-muted-foreground bg-muted px-1 rounded flex-shrink-0 leading-none pb-px border border-border/50",children:y("settings.agents.sidebar.badge.system")}),e[27]=g,e[28]=y,e[29]=D):D=e[29];let $;e[30]!==T||e[31]!==S||e[32]!==D||e[33]!==F?($=s.jsxs("div",{className:"flex items-center gap-1.5",children:[F,T,S,D]}),e[30]=T,e[31]=S,e[32]=D,e[33]=F,e[34]=$):$=e[34];const B=f==="token"&&a.host?a.host:a.userEmail;let k;e[35]!==B?(k=s.jsx("div",{className:"typography-micro text-muted-foreground/60 truncate leading-tight",children:B}),e[35]=B,e[36]=k):k=e[36];let G;e[37]!==$||e[38]!==k?(G=s.jsxs("div",{className:"min-w-0",children:[$,k]}),e[37]=$,e[38]=k,e[39]=G):G=e[39];let M;e[40]!==G||e[41]!==w?(M=s.jsxs("div",{className:"flex items-center gap-3 min-w-0",children:[w,G]}),e[40]=G,e[41]=w,e[42]=M):M=e[42];let L;e[43]===Symbol.for("react.memo_cache_sentinel")?(L=s.jsx(on,{asChild:!0,children:s.jsx(V,{size:"icon",variant:"ghost",className:"h-6 w-6 shrink-0 opacity-100 transition-opacity md:opacity-0 md:group-hover:opacity-100",onClick:hh,children:s.jsx(O,{name:"more-2",className:"h-3.5 w-3.5"})})}),e[43]=L):L=e[43];let J;e[44]!==m?(J=s.jsxs(cn,{children:[L,s.jsx(ln,{align:"end",className:"w-fit min-w-28",children:m(dn)})]}),e[44]=m,e[45]=J):J=e[45];let ee;e[46]!==M||e[47]!==J||e[48]!==j?(ee=s.jsxs(Jn,{render:j,children:[M,J]}),e[46]=M,e[47]=J,e[48]=j,e[49]=ee):ee=e[49];let U;e[50]!==m?(U=s.jsx(Wn,{className:"w-fit min-w-28",children:m(qn)}),e[50]=m,e[51]=U):U=e[51];let le;return e[52]!==p||e[53]!==ee||e[54]!==U?(le=s.jsxs(Qn,{open:p,onOpenChange:b,children:[ee,U]}),e[52]=p,e[53]=ee,e[54]=U,e[55]=le):le=e[55],le},mh=t=>{const e=ut.c(21),{credential:a,onImport:n,hasBorder:r}=t,{t:i}=tt();let l;e[0]!==a.host?(l=a.host.split("/"),e[0]=a.host,e[1]=l):l=e[1];const g=l,c=g.length>=3?g[g.length-1]:a.host,y=a.host.includes("/"),p=r&&"border-b border-[var(--surface-subtle)]";let b;e[2]!==p?(b=xe("flex items-center justify-between gap-3 px-4 py-2.5 transition-colors hover:bg-[var(--interactive-hover)]/30",p),e[2]=p,e[3]=b):b=e[3];let d;e[4]!==c?(d=s.jsx("span",{className:"typography-ui-label text-foreground truncate block",children:c}),e[4]=c,e[5]=d):d=e[5];const P=y?a.host:a.username;let f;e[6]!==P?(f=s.jsx("span",{className:"typography-micro text-muted-foreground/60 truncate block leading-tight",children:P}),e[6]=P,e[7]=f):f=e[7];let C;e[8]!==d||e[9]!==f?(C=s.jsxs("div",{className:"min-w-0",children:[d,f]}),e[8]=d,e[9]=f,e[10]=C):C=e[10];let v;e[11]===Symbol.for("react.memo_cache_sentinel")?(v=s.jsx(O,{name:"download",className:"h-3 w-3"}),e[11]=v):v=e[11];let N;e[12]!==i?(N=i("settings.gitIdentities.page.actions.import"),e[12]=i,e[13]=N):N=e[13];let m;e[14]!==n||e[15]!==N?(m=s.jsxs(V,{size:"sm",variant:"ghost",onClick:n,className:"gap-1 shrink-0",children:[v,N]}),e[14]=n,e[15]=N,e[16]=m):m=e[16];let A;return e[17]!==m||e[18]!==b||e[19]!==C?(A=s.jsxs("div",{className:b,children:[C,m]}),e[17]=m,e[18]=b,e[19]=C,e[20]=A):A=e[20],A};function gh(t){return{profiles:t.profiles,globalIdentity:t.globalIdentity,defaultGitIdentityId:t.defaultGitIdentityId,deleteProfile:t.deleteProfile,loadProfiles:t.loadProfiles,loadGlobalIdentity:t.loadGlobalIdentity,loadDiscoveredCredentials:t.loadDiscoveredCredentials,loadDefaultGitIdentityId:t.loadDefaultGitIdentityId,setDefaultGitIdentityId:t.setDefaultGitIdentityId,getUnimportedCredentials:t.getUnimportedCredentials}}function hh(t){return t.stopPropagation()}const fh=({embedded:t=!1})=>{const{t:e}=tt(),{isMobile:a}=wa(),n=fa()?.github,r=Cn(k=>k.status),i=Cn(k=>k.isLoading),l=Cn(k=>k.hasChecked),g=Cn(k=>k.refreshStatus),c=Cn(k=>k.setStatus),y=o.useCallback(async k=>{await Pn(k)},[]),[p,b]=o.useState(!1),[d,P]=o.useState(null),[f,C]=o.useState(null),v=o.useRef(null),N=o.useCallback(()=>{v.current!=null&&(window.clearInterval(v.current),v.current=null),C(null)},[]);o.useEffect(()=>((async()=>{try{l||await g(n)}catch(k){console.warn("Failed to load GitHub auth status:",k)}})(),()=>{N()}),[l,g,n,N]);const m=o.useCallback(async()=>{b(!0);try{const k=n?await n.authStart():await(async()=>{const M=await yt("/api/github/auth/start",{method:"POST",headers:{"Content-Type":"application/json",Accept:"application/json"},body:JSON.stringify({})}),L=await M.json().catch(()=>null);if(!M.ok||!L||!("deviceCode"in L))throw new Error(L?.error||M.statusText);return L})();P(k),C(Math.max(1,k.interval)*1e3);const G=k.verificationUriComplete||k.verificationUri;y(G)}catch(k){console.error("Failed to start GitHub connect:",k),E.error(e("settings.github.page.toast.startConnectFailed"))}finally{b(!1)}},[y,n,e]),A=o.useCallback(async k=>{if(n)return n.authComplete(k);const G=await yt("/api/github/auth/complete",{method:"POST",headers:{"Content-Type":"application/json",Accept:"application/json"},body:JSON.stringify({deviceCode:k})}),M=await G.json().catch(()=>null);if(!G.ok||!M)throw new Error(M?.error||G.statusText);return M},[n]);o.useEffect(()=>{if(!(!d?.deviceCode||!f)&&v.current==null)return v.current=window.setInterval(()=>{(async()=>{try{const k=await A(d.deviceCode);if(k.connected){E.success(e("settings.github.page.toast.connected")),P(null),N(),await g(n,{force:!0});return}k.status==="slow_down"&&C(G=>G?G+5e3:5e3),(k.status==="expired_token"||k.status==="access_denied")&&(E.error(k.error||e("settings.github.page.toast.authorizationFailed")),P(null),N())}catch(k){console.warn("GitHub polling failed:",k)}})()},f),()=>{v.current!=null&&(window.clearInterval(v.current),v.current=null)}},[d,f,A,g,n,N,e]);const R=o.useCallback(async k=>{b(!0);try{if(n)await n.authSetGhCliDisabled(k);else{const G=await yt("/api/github/auth/gh-cli",{method:"POST",headers:{"Content-Type":"application/json",Accept:"application/json"},body:JSON.stringify({disabled:k})}),M=await G.json().catch(()=>null);if(!G.ok)throw new Error(M?.error||G.statusText)}E.success(e(k?"settings.github.page.toast.ghCliDisabled":"settings.github.page.toast.ghCliEnabled")),await g(n,{force:!0})}catch(G){console.error("Failed to update gh CLI setting:",G),E.error(e("settings.github.page.toast.ghCliUpdateFailed"))}finally{b(!1)}},[g,n,e]),I=o.useCallback(async()=>{b(!0);try{if(N(),P(null),n)await n.authDisconnect();else{const k=await yt("/api/github/auth",{method:"DELETE",headers:{Accept:"application/json"}});if(!k.ok)throw new Error(k.statusText)}E.success(e("settings.github.page.toast.disconnected")),await g(n,{force:!0})}catch(k){console.error("Failed to disconnect GitHub:",k),E.error(e("settings.github.page.toast.disconnectFailed"))}finally{b(!1)}},[g,n,N,e]),j=o.useCallback(async k=>{if(k){b(!0);try{const G=n?await n.authActivate(k):await(async()=>{const M=await yt("/api/github/auth/activate",{method:"POST",headers:{"Content-Type":"application/json",Accept:"application/json"},body:JSON.stringify({accountId:k})}),L=await M.json().catch(()=>null);if(!M.ok||!L)throw new Error(L?.error||M.statusText);return L})();c(G),E.success(e("settings.github.page.toast.accountSwitched"))}catch(G){console.error("Failed to switch GitHub account:",G),E.error(e("settings.github.page.toast.accountSwitchFailed"))}finally{b(!1)}}},[n,c,e]);if(i&&!l)return null;const h=!!r?.connected,w=r?.user,T=(r?.accounts??[]).filter(k=>!k.current),S=r?.ghCli??null,D=S?.active?e("settings.github.page.accountSource.cli"):e("settings.github.page.accountSource.oauth"),$=s.jsxs(s.Fragment,{children:[s.jsxs("div",{className:"rounded-lg bg-[var(--surface-elevated)]/70 overflow-hidden flex flex-col",children:[h?s.jsxs("div",{className:xe("px-4 py-3",a?"flex flex-col gap-3":"flex items-center justify-between gap-4"),children:[s.jsxs("div",{className:xe("flex min-w-0 items-center gap-4",a?"w-full":void 0),children:[w?.avatarUrl?s.jsx("img",{src:w.avatarUrl,alt:w.login?e("settings.github.page.avatarAlt.withLogin",{login:w.login}):e("settings.github.page.avatarAlt.fallback"),className:"h-10 w-10 shrink-0 rounded-full border border-[var(--interactive-border)] bg-[var(--surface-muted)] object-cover",loading:"lazy",referrerPolicy:"no-referrer"}):s.jsx("div",{className:"h-10 w-10 shrink-0 rounded-full border border-[var(--interactive-border)] bg-[var(--surface-muted)]"}),s.jsxs("div",{className:"min-w-0 flex-1",children:[s.jsx("div",{className:"typography-ui-label text-foreground",children:w?.name?.trim()||w?.login||"GitHub"}),s.jsxs("div",{className:xe("flex items-center gap-2 typography-meta text-muted-foreground mt-0.5",a?"flex-wrap":"truncate"),children:[s.jsx(O,{name:"github-fill",className:"h-3.5 w-3.5 shrink-0"}),s.jsx("span",{className:"font-mono",children:w?.login||e("settings.github.page.label.unknownUser")}),w?.email&&s.jsx("span",{className:"opacity-50",children:"•"}),w?.email&&s.jsx("span",{children:w.email}),s.jsx("span",{className:"opacity-50",children:"•"}),s.jsx("span",{children:D})]}),r?.scope&&s.jsx("div",{className:"typography-micro text-muted-foreground/70 mt-0.5",children:e("settings.github.page.label.scopes",{value:r.scope})}),S?.active&&s.jsx("div",{className:"typography-micro text-muted-foreground/70 mt-0.5",children:e("settings.github.page.ghCli.activeDescription")})]})]}),S?.active?s.jsx(V,{size:"sm",variant:"outline",onClick:()=>R(!0),disabled:p,className:xe(a?"w-full":void 0),children:e("settings.github.page.ghCli.actions.disable")}):s.jsx(V,{size:"sm",variant:"outline",onClick:I,disabled:p,className:xe("text-[var(--status-error)] hover:text-[var(--status-error)]",a?"w-full":void 0),children:e("settings.github.page.actions.disconnect")})]}):s.jsxs("div",{className:"flex items-center justify-between gap-4 px-4 py-4",children:[s.jsx("div",{className:"flex min-w-0 flex-col",children:s.jsx("span",{className:"typography-ui-label text-foreground",children:e("settings.github.page.status.notConnected")})}),s.jsx(V,{size:"sm",variant:"default",onClick:m,disabled:p,children:e("settings.github.page.actions.connect")})]}),T.length>0&&s.jsxs("div",{className:"mt-2 border-t border-[var(--surface-subtle)] pt-2 px-2 pb-1",children:[s.jsx("div",{className:"typography-micro text-muted-foreground mb-2 px-1",children:e("settings.github.page.label.otherAccounts")}),s.jsx("div",{className:"space-y-1",children:T.map(k=>{const G=k.user,M=k.source==="gh-cli"?e("settings.github.page.accountSource.cli"):e("settings.github.page.accountSource.oauth");return s.jsxs("div",{className:"flex items-center justify-between gap-3 rounded-md border border-[var(--surface-subtle)] bg-[var(--surface-muted)] px-3 py-2",children:[s.jsxs("div",{className:"flex min-w-0 items-center gap-3",children:[G?.avatarUrl?s.jsx("img",{src:G.avatarUrl,alt:G.login?e("settings.github.page.avatarAlt.withLogin",{login:G.login}):e("settings.github.page.avatarAlt.fallback"),className:"h-6 w-6 shrink-0 rounded-full border border-[var(--interactive-border)] bg-[var(--surface-muted)] object-cover",loading:"lazy",referrerPolicy:"no-referrer"}):s.jsx("div",{className:"flex h-6 w-6 shrink-0 items-center justify-center rounded-full border border-[var(--interactive-border)] bg-[var(--surface-muted)]",children:s.jsx(O,{name:"github-fill",className:"h-3 w-3 text-muted-foreground"})}),s.jsxs("div",{className:"min-w-0 flex flex-col",children:[s.jsx("span",{className:"typography-ui-label text-foreground truncate",children:G?.name?.trim()||G?.login||"GitHub"}),G?.login&&s.jsxs("span",{className:"typography-micro text-muted-foreground truncate",children:[s.jsx("span",{className:"font-mono",children:G.login}),s.jsx("span",{className:"mx-1 opacity-50",children:"·"}),s.jsx("span",{children:M})]})]})]}),s.jsx(V,{size:"sm",variant:"ghost",onClick:()=>j(k.id),disabled:p,children:e("settings.github.page.actions.switchTo")})]},k.id)})})]})]}),h&&s.jsx("div",{className:"mt-2 px-2 pb-2",children:s.jsx(V,{size:"sm",variant:"outline",onClick:m,disabled:p,className:xe(a?"w-full":void 0),children:e("settings.github.page.actions.addAccount")})}),d&&s.jsxs("div",{className:"mt-4 rounded-lg bg-[var(--surface-elevated)]/70 p-4 border border-[var(--interactive-border)]",children:[s.jsxs("div",{className:"space-y-1",children:[s.jsx(Zs,{children:e("settings.github.page.flow.title")}),s.jsx("p",{className:"typography-meta text-muted-foreground",children:e("settings.github.page.flow.description")})]}),s.jsxs("div",{className:"flex items-center justify-between gap-3 mt-4",children:[s.jsx("div",{className:"font-mono text-xl tracking-widest text-foreground bg-[var(--surface-muted)] px-3 py-1.5 rounded-md border border-[var(--interactive-border)]",children:d.userCode}),s.jsx(V,{size:"sm",asChild:!0,children:s.jsx("a",{href:d.verificationUriComplete||d.verificationUri,target:"_blank",rel:"noopener noreferrer",children:e("settings.github.page.actions.openGithub")})})]}),s.jsxs("div",{className:"mt-4 flex items-center justify-between",children:[s.jsx("span",{className:"typography-micro text-muted-foreground animate-pulse",children:e("settings.github.page.flow.waiting")}),s.jsx(V,{size:"sm",variant:"ghost",disabled:p,onClick:()=>{N(),P(null)},children:e("settings.common.actions.cancel")})]})]})]}),B=S?.available&&!S?.active&&(!S.user||S.disabled)?s.jsx(s.Fragment,{children:s.jsx("div",{className:"rounded-lg bg-[var(--surface-elevated)]/70 overflow-hidden",children:s.jsxs("div",{className:xe("px-4 py-3",a?"flex flex-col gap-3":"flex items-center justify-between gap-4"),children:[s.jsxs("div",{className:xe("flex min-w-0 items-center gap-4",a?"w-full":void 0),children:[S.user?.avatarUrl?s.jsx("img",{src:S.user.avatarUrl,alt:S.user.login?e("settings.github.page.avatarAlt.withLogin",{login:S.user.login}):e("settings.github.page.avatarAlt.fallback"),className:"h-10 w-10 shrink-0 rounded-full border border-[var(--interactive-border)] bg-[var(--surface-muted)] object-cover",loading:"lazy",referrerPolicy:"no-referrer"}):s.jsx("div",{className:"flex h-10 w-10 shrink-0 items-center justify-center rounded-full border border-[var(--interactive-border)] bg-[var(--surface-muted)]",children:s.jsx(O,{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:xe("flex items-center gap-2 typography-meta text-muted-foreground mt-0.5",a?"flex-wrap":"truncate"),children:[s.jsx(O,{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:xe("typography-meta text-muted-foreground",S.disabled?"opacity-60":void 0),children:S.disabled?e("settings.github.page.ghCli.disabledDescription"):e("settings.github.page.ghCli.fallbackDescription")})]})]}),s.jsx(V,{size:"sm",variant:"outline",onClick:()=>R(!S.disabled),disabled:p,className:xe(a?"w-full":void 0),children:S.disabled?e("settings.github.page.ghCli.actions.enable"):e("settings.github.page.ghCli.actions.disable")})]})})}):null;return t?s.jsxs("div",{className:"space-y-4",children:[$,B?s.jsxs("div",{className:"space-y-2",children:[s.jsx(Zs,{children:e("settings.github.page.ghCli.title")}),B]}):null]}):s.jsxs(s.Fragment,{children:[s.jsx(ze,{title:e("settings.github.page.oauth.title"),divider:!1,settingsItem:"git.github-account",info:e("settings.github.page.tooltip.connectAccount"),children:$}),B?s.jsx(ze,{title:e("settings.github.page.ghCli.title"),children:B}):null]})},xh=()=>{const t=ut.c(37),{t:e}=tt(),a=Cn(vh),n=Cn(yh),r=Cn(bh),[i,l]=o.useState(!1),g=a?.connected===!0;let c;t[0]!==g||t[1]!==r||t[2]!==n||t[3]!==a?.user?.login||t[4]!==e?(c=n&&!r?e("common.loading"):g?a?.user?.login?.trim()||e("settings.github.page.status.active"):e("settings.integrations.github.status.notConnected"),t[0]=g,t[1]=r,t[2]=n,t[3]=a?.user?.login,t[4]=e,t[5]=c):c=t[5];const y=c,p=g?"bg-[var(--status-success)]/15 text-[var(--status-success)]":"bg-[var(--surface-muted)] text-muted-foreground";let b;t[6]===Symbol.for("react.memo_cache_sentinel")?(b=s.jsx("div",{className:"flex size-10 shrink-0 items-center justify-center rounded-[10px] bg-[var(--surface-muted)]",children:s.jsx(O,{name:"github-fill",className:"size-5 text-foreground"})}),t[6]=b):b=t[6];let d;t[7]!==e?(d=e("settings.integrations.github.title"),t[7]=e,t[8]=d):d=t[8];let P;t[9]!==d?(P=s.jsx("div",{className:"truncate text-sm font-semibold text-foreground",children:d}),t[9]=d,t[10]=P):P=t[10];let f;t[11]!==e?(f=e("settings.integrations.github.description"),t[11]=e,t[12]=f):f=t[12];let C;t[13]!==f?(C=s.jsx("p",{className:"mt-0.5 line-clamp-1 text-xs leading-snug text-muted-foreground",children:f}),t[13]=f,t[14]=C):C=t[14];let v;t[15]!==P||t[16]!==C?(v=s.jsxs("div",{className:"min-w-0 flex-1",children:[P,C]}),t[15]=P,t[16]=C,t[17]=v):v=t[17];let N;t[18]!==p?(N=xe("max-w-36 shrink-0 truncate rounded-full px-2 py-0.5 text-[10px] font-medium",p),t[18]=p,t[19]=N):N=t[19];let m;t[20]!==y||t[21]!==N?(m=s.jsx("span",{"aria-live":"polite",className:N,children:y}),t[20]=y,t[21]=N,t[22]=m):m=t[22];const A=i&&"rotate-180";let R;t[23]!==A?(R=xe("size-4 shrink-0 text-muted-foreground transition-transform duration-150 ease-out motion-reduce:transition-none",A),t[23]=A,t[24]=R):R=t[24];let I;t[25]!==R?(I=s.jsx(O,{name:"arrow-down-s",className:R}),t[25]=R,t[26]=I):I=t[26];let j;t[27]!==I||t[28]!==v||t[29]!==m?(j=s.jsxs(Tn,{className:"flex w-full min-w-0 items-center gap-3 px-4 py-3 text-left hover:bg-[var(--interactive-hover)]/50 focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-inset focus-visible:ring-[var(--interactive-focus-ring)]",children:[b,v,m,I]}),t[27]=I,t[28]=v,t[29]=m,t[30]=j):j=t[30];let h;t[31]===Symbol.for("react.memo_cache_sentinel")?(h=s.jsx(En,{className:"border-t border-[var(--interactive-border)] px-4 py-4",children:s.jsx(fh,{embedded:!0})}),t[31]=h):h=t[31];let w;t[32]!==j?(w=s.jsxs("div",{"data-settings-item":"integrations.github",className:"overflow-hidden rounded-xl border border-[var(--interactive-border)] bg-[var(--surface-elevated)]",children:[j,h]}),t[32]=j,t[33]=w):w=t[33];let F;return t[34]!==i||t[35]!==w?(F=s.jsx(An,{open:i,onOpenChange:l,children:w}),t[34]=i,t[35]=w,t[36]=F):F=t[36],F};function vh(t){return t.status}function yh(t){return t.isLoading}function bh(t){return t.hasChecked}const mi="__none__",gi="__inherit__";function wh({linear:t,connected:e,organizationId:a}){const{t:n}=tt(),r=Gs(v=>v.projects),[i,l]=o.useState(null),[g,c]=o.useState(!1),[y,p]=o.useState(!1),b=o.useCallback(async()=>{if(!e){l(null),c(!1);return}try{const v=await t.mappingGet();if(v.connected===!1){l(null),c(!1);return}l(v),c(!1)}catch(v){console.error("Failed to load Linear mapping:",v),c(!0)}},[e,t]);o.useEffect(()=>{b()},[b,a]);const d=o.useCallback(async v=>{const N={};for(const m of v.teams??[])m.projectPath&&(N[m.id]=m.projectPath);p(!0),ga("saving");try{const m=await t.mappingSet({defaultProjectPath:v.defaultProjectPath??null,teamProjectPaths:N});if(m.connected===!1){l(null),ga("error");return}l(m),c(!1),ga("saved")}catch(m){console.error("Failed to save Linear mapping:",m),ga("error")}finally{p(!1)}},[t]);if(!e)return null;if(g&&!i)return s.jsx("p",{className:"text-xs text-muted-foreground",children:n("settings.integrations.linear.mapping.loadFailed")});if(!i)return null;const P=v=>r.find(m=>m.path===v)?.label?.trim()||v,f=v=>!v||v===mi?n("settings.integrations.linear.mapping.defaultProject.placeholder"):P(v),C=v=>!v||v===gi?n("settings.integrations.linear.mapping.teams.useDefault"):P(v);return s.jsxs("div",{className:Qs,children:[r.length===0?s.jsx("p",{className:"text-xs text-muted-foreground",children:n("settings.integrations.linear.mapping.emptyProjects")}):null,s.jsx(Rt,{label:n("settings.integrations.linear.mapping.defaultProject"),info:n("settings.integrations.linear.mapping.defaultProject.info"),settingsItem:"integrations.linear.mapping",children:s.jsxs(St,{value:i.defaultProjectPath||mi,disabled:y||r.length===0,onValueChange:v=>{d({...i,defaultProjectPath:v===mi?null:v})},children:[s.jsx(Ct,{size:Ft,className:rn,"aria-label":n("settings.integrations.linear.mapping.defaultProject.aria"),children:s.jsx(Mt,{placeholder:n("settings.integrations.linear.mapping.defaultProject.placeholder"),children:f})}),s.jsxs(It,{children:[s.jsx(at,{value:mi,children:n("settings.integrations.linear.mapping.defaultProject.placeholder")}),i.defaultProjectPath&&!r.some(v=>v.path===i.defaultProjectPath)?s.jsx(at,{value:i.defaultProjectPath,children:i.defaultProjectPath}):null,r.map(v=>s.jsx(at,{value:v.path,children:P(v.path)},v.id))]})]})}),s.jsx(Ss,{title:n("settings.integrations.linear.mapping.teams"),info:n("settings.integrations.linear.mapping.teams.info"),children:(i.teams??[]).length===0?s.jsx("p",{className:"text-xs text-muted-foreground",children:n("settings.integrations.linear.mapping.emptyTeams")}):s.jsx("div",{className:Qs,children:(i.teams??[]).map(v=>s.jsx(Rt,{label:`${v.key} · ${v.name}`,children:s.jsxs(St,{value:v.projectPath||gi,disabled:y||r.length===0,onValueChange:N=>{d({...i,teams:(i.teams??[]).map(m=>m.id===v.id?{...m,projectPath:N===gi?null:N}:m)})},children:[s.jsx(Ct,{size:Ft,className:rn,"aria-label":n("settings.integrations.linear.mapping.teams.aria",{team:v.key}),children:s.jsx(Mt,{placeholder:n("settings.integrations.linear.mapping.teams.useDefault"),children:C})}),s.jsxs(It,{children:[s.jsx(at,{value:gi,children:n("settings.integrations.linear.mapping.teams.useDefault")}),v.projectPath&&!r.some(N=>N.path===v.projectPath)?s.jsx(at,{value:v.projectPath,children:v.projectPath}):null,r.map(N=>s.jsx(at,{value:N.path,children:P(N.path)},N.id))]})]})},v.id))})})]})}function jh({linear:t,connected:e}){const{t:a}=tt(),[n,r]=o.useState(null),[i,l]=o.useState(!1),[g,c]=o.useState(!1);o.useEffect(()=>{if(!e){r(null),l(!1);return}let p=!1;return t.preferencesGet().then(b=>{p||(r(b.sessionComments),l(!1))}).catch(()=>{p||l(!0)}),()=>{p=!0}},[e,t]);const y=o.useCallback(async p=>{const b=n;r(p),c(!0);try{const d=await t.preferencesSet({sessionComments:p});r(d.sessionComments),ga("saved")}catch{r(b),ga("error")}finally{c(!1)}},[n,t]);return e?i?s.jsx("p",{className:"text-xs text-muted-foreground",children:a("settings.integrations.linear.sessionComments.loadFailed")}):s.jsx("div",{className:Qs,children:s.jsx(Rt,{label:a("settings.integrations.linear.sessionComments.label"),info:a("settings.integrations.linear.sessionComments.info"),settingsItem:"integrations.linear.session-comments",children:s.jsx(xi,{checked:n===!0,disabled:n===null||g,onCheckedChange:p=>{y(p)},"aria-label":a("settings.integrations.linear.sessionComments.aria")})})}):null}const kh=3*6e4,Nh=1500;function Yo(t){const e=t?.workspaces??[],a=e.find(n=>n.current);return{connected:!!t?.connected,ids:e.map(n=>n.id).slice().sort().join(","),currentId:a?.id||t?.organization?.id||"",currentAuthorizedAt:a?.authorizedAt??0}}function Sh(t,e){return e.connected?t.connected?e.ids!==t.ids||e.currentId!==t.currentId||e.currentAuthorizedAt!==t.currentAuthorizedAt:!0:!1}const Ch=()=>{const{t}=tt(),e=fa()?.linear,a=oa(S=>S.status),n=oa(S=>S.isLoading),r=oa(S=>S.hasChecked),i=oa(S=>S.refreshStatus),l=oa(S=>S.setStatus),[g,c]=o.useState(!1),[y,p]=o.useState(!1),[b,d]=o.useState(!1),P=o.useRef(null),f=o.useCallback(()=>{P.current!=null&&(window.clearInterval(P.current),P.current=null),p(!1)},[]);o.useEffect(()=>{if(e)return r||i(e),()=>{f()}},[r,i,e,f]);const C=o.useCallback(async()=>{if(!e)return;f(),c(!0);const S=Yo(oa.getState().status);try{const D=await e.authStart(as()?"desktop":"web");p(!0),d(!0),Pn(D.authorizationUrl);const $=Date.now()+kh;P.current=window.setInterval(()=>{(async()=>{if(Date.now()>$){f(),E.error(t("settings.integrations.linear.toast.authorizationFailed"));return}const B=await i(e,{force:!0});Sh(S,Yo(B))&&(f(),E.success(t("settings.integrations.linear.toast.connected")),Ad())})()},Nh)}catch(D){console.error("Failed to start Linear connect:",D),E.error(t("settings.integrations.linear.toast.startConnectFailed")),f()}finally{c(!1)}},[i,e,f,t]),v=o.useCallback(async S=>{if(!(!e||!S)){c(!0);try{const D=await e.authActivate(S);l(D),E.success(t("settings.integrations.linear.toast.workspaceSwitched"))}catch(D){console.error("Failed to switch Linear workspace:",D),E.error(t("settings.integrations.linear.toast.workspaceSwitchFailed"))}finally{c(!1)}}},[e,l,t]),N=o.useCallback(async()=>{if(e){c(!0);try{f(),await e.authDisconnect(),E.success(t("settings.integrations.linear.toast.disconnected")),await i(e,{force:!0})}catch(S){console.error("Failed to disconnect Linear:",S),E.error(t("settings.integrations.linear.toast.disconnectFailed"))}finally{c(!1)}}},[i,e,f,t]);if(!e)return null;const m=!!a?.connected,A=a?.user,R=a?.organization,j=(a?.workspaces??[]).filter(S=>!S.current),h=A?.displayName?.trim()||A?.name?.trim()||t("settings.integrations.linear.label.unknownUser"),w=y?t("settings.integrations.linear.status.waiting"):n&&!r?t("common.loading"):m?R?.name?.trim()||t("settings.integrations.linear.status.connected"):t("settings.integrations.linear.status.notConnected"),F=y?"bg-[var(--status-warning)]/15 text-[var(--status-warning)]":m?"bg-[var(--status-success)]/15 text-[var(--status-success)]":"bg-[var(--surface-muted)] text-muted-foreground",T=y||b;return s.jsx(An,{open:T,onOpenChange:S=>{if(y){d(!0);return}d(S)},children:s.jsxs("div",{"data-settings-item":"integrations.linear",className:"overflow-hidden rounded-xl border border-[var(--interactive-border)] bg-[var(--surface-elevated)]",children:[s.jsxs(Tn,{className:"flex w-full min-w-0 items-center gap-3 px-4 py-3 text-left hover:bg-[var(--interactive-hover)]/50 focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-inset focus-visible:ring-[var(--interactive-focus-ring)]",children:[s.jsx("div",{className:"flex size-10 shrink-0 items-center justify-center rounded-[10px] bg-[var(--surface-muted)]",children:s.jsx(O,{name:"linear",className:"size-5 text-foreground"})}),s.jsxs("div",{className:"min-w-0 flex-1",children:[s.jsx("div",{className:"truncate text-sm font-semibold text-foreground",children:t("settings.integrations.linear.title")}),s.jsx("p",{className:"mt-0.5 line-clamp-1 text-xs leading-snug text-muted-foreground",children:t("settings.integrations.linear.description")})]}),s.jsx("span",{"aria-live":"polite",className:xe("max-w-36 shrink-0 truncate rounded-full px-2 py-0.5 text-[10px] font-medium",F),children:w}),s.jsx(O,{name:"arrow-down-s",className:xe("size-4 shrink-0 text-muted-foreground transition-transform duration-150 ease-out motion-reduce:transition-none",T&&"rotate-180")})]}),s.jsx(En,{className:"border-t border-[var(--interactive-border)] px-4 py-4",children:s.jsxs("div",{className:"space-y-3",children:[m?s.jsxs("div",{className:"flex min-w-0 items-center gap-3",children:[A?.avatarUrl?s.jsx("img",{src:A.avatarUrl,alt:t("settings.integrations.linear.avatarAlt.withName",{name:h}),className:"size-10 shrink-0 rounded-full border border-[var(--interactive-border)] bg-[var(--surface-muted)] object-cover",loading:"lazy",referrerPolicy:"no-referrer"}):s.jsx("div",{className:"flex size-10 shrink-0 items-center justify-center rounded-full border border-[var(--interactive-border)] bg-[var(--surface-muted)]",children:s.jsx(O,{name:"linear",className:"size-4 text-muted-foreground"})}),s.jsxs("div",{className:"min-w-0 flex-1",children:[s.jsx("div",{className:"truncate text-sm font-medium text-foreground",children:h}),s.jsx("p",{className:"mt-0.5 truncate text-xs text-muted-foreground",children:[R?.name,A?.email].filter(Boolean).join(" · ")})]})]}):y?s.jsx("p",{className:"text-xs text-muted-foreground",children:t("settings.integrations.linear.flow.description")}):null,m?s.jsxs(s.Fragment,{children:[s.jsx(wh,{linear:e,connected:m,organizationId:R?.id??null}),s.jsx(jh,{linear:e,connected:m}),j.length>0?s.jsxs("div",{className:"space-y-2",children:[s.jsx("p",{className:"typography-micro text-muted-foreground",children:t("settings.integrations.linear.label.otherWorkspaces")}),s.jsx("div",{className:"space-y-1",children:j.map(S=>{const D=S.user,$=S.name?.trim()||t("settings.integrations.linear.status.connected");return s.jsxs("div",{className:"flex items-center justify-between gap-3 rounded-md border border-[var(--surface-subtle)] bg-[var(--surface-muted)] px-3 py-2",children:[s.jsxs("div",{className:"min-w-0",children:[s.jsx("div",{className:"truncate text-sm font-medium text-foreground",children:$}),D?.email?s.jsx("p",{className:"truncate text-xs text-muted-foreground",children:D.email}):null]}),s.jsx(V,{type:"button",size:"sm",variant:"ghost",onClick:()=>{v(S.id)},disabled:g,children:t("settings.integrations.linear.actions.switchTo")})]},S.id)})})]}):null,s.jsxs("div",{className:"flex flex-wrap items-center gap-2",children:[s.jsx(V,{type:"button",size:"sm",variant:"outline",onClick:()=>{C()},disabled:g||y,"data-settings-item":"integrations.linear.add-workspace",children:t("settings.integrations.linear.actions.addWorkspace")}),s.jsx(V,{type:"button",size:"sm",variant:"destructive",onClick:()=>{N()},disabled:g,children:t("settings.integrations.linear.actions.disconnect")})]})]}):y?s.jsxs("div",{className:"flex flex-wrap items-center gap-2",children:[s.jsx("span",{className:"typography-micro text-muted-foreground animate-pulse",children:t("settings.integrations.linear.flow.waiting")}),s.jsx(V,{type:"button",size:"sm",variant:"ghost",disabled:g,onClick:f,children:t("settings.common.actions.cancel")})]}):s.jsxs(V,{type:"button",size:"sm",variant:"default",onClick:()=>{C()},disabled:g||n&&!r,children:[g?s.jsx(O,{name:"loader-4",className:"size-3.5 animate-spin"}):null,t("settings.integrations.linear.actions.connect")]})]})})]})})},Ih=()=>{const t=ut.c(18),{t:e}=tt();let a;t[0]===Symbol.for("react.memo_cache_sentinel")?(a=cs(),t[0]=a):a=t[0];const n=!a,r=!!fa()?.linear;let i;t[1]!==e?(i=e("settings.page.integrations.title"),t[1]=e,t[2]=i):i=t[2];let l;t[3]!==e?(l=e("settings.page.integrations.description"),t[3]=e,t[4]=l):l=t[4];let g;t[5]!==e?(g=e("settings.integrations.firstParty.title"),t[5]=e,t[6]=g):g=t[6];let c;t[7]!==e?(c=e("settings.integrations.firstParty.info"),t[7]=e,t[8]=c):c=t[8];let y,p;t[9]===Symbol.for("react.memo_cache_sentinel")?(y=n?s.jsx(xh,{}):null,p=r?s.jsx(Ch,{}):null,t[9]=y,t[10]=p):(y=t[9],p=t[10]);let b;t[11]!==g||t[12]!==c?(b=s.jsxs(ze,{title:g,info:c,divider:!1,settingsItem:"integrations.first-party",contentClassName:"space-y-3",children:[y,p]}),t[11]=g,t[12]=c,t[13]=b):b=t[13];let d;return t[14]!==i||t[15]!==l||t[16]!==b?(d=s.jsx(es,{title:i,description:l,showSaveStatus:!0,children:b}),t[14]=i,t[15]=l,t[16]=b,t[17]=d):d=t[17],d},Ph=[{value:"system",labelKey:"settings.aiworker.visual.option.themeMode.system",descriptionKey:"settings.aiworker.visual.option.themeMode.system.description"},{value:"light",labelKey:"settings.aiworker.visual.option.themeMode.light",descriptionKey:"settings.aiworker.visual.option.themeMode.light.description"},{value:"dark",labelKey:"settings.aiworker.visual.option.themeMode.dark",descriptionKey:"settings.aiworker.visual.option.themeMode.dark.description"}],Ah=[{id:"dynamic",labelKey:"settings.aiworker.visual.option.diffLayout.dynamic.label",descriptionKey:"settings.aiworker.visual.option.diffLayout.dynamic.description"},{id:"inline",labelKey:"settings.aiworker.visual.option.diffLayout.inline.label",descriptionKey:"settings.aiworker.visual.option.diffLayout.inline.description"},{id:"side-by-side",labelKey:"settings.aiworker.visual.option.diffLayout.sideBySide.label",descriptionKey:"settings.aiworker.visual.option.diffLayout.sideBySide.description"}],Th=[{id:"svg",labelKey:"settings.aiworker.visual.option.mermaidRendering.svg.label",descriptionKey:"settings.aiworker.visual.option.mermaidRendering.svg.description"},{id:"ascii",labelKey:"settings.aiworker.visual.option.mermaidRendering.ascii.label",descriptionKey:"settings.aiworker.visual.option.mermaidRendering.ascii.description"}],Da="AiWorker - AI Coding Assistant",Zo=[{id:"system",labelKey:"settings.aiworker.visual.option.pwaOrientation.system.label",descriptionKey:"settings.aiworker.visual.option.pwaOrientation.system.description"},{id:"portrait",labelKey:"settings.aiworker.visual.option.pwaOrientation.portrait.label",descriptionKey:"settings.aiworker.visual.option.pwaOrientation.portrait.description"},{id:"landscape",labelKey:"settings.aiworker.visual.option.pwaOrientation.landscape.label",descriptionKey:"settings.aiworker.visual.option.pwaOrientation.landscape.description"}],Xo=[{id:"native",labelKey:"settings.aiworker.visual.option.mobileKeyboardMode.native.label",descriptionKey:"settings.aiworker.visual.option.mobileKeyboardMode.native.description"},{id:"resize-content",labelKey:"settings.aiworker.visual.option.mobileKeyboardMode.resizeContent.label",descriptionKey:"settings.aiworker.visual.option.mobileKeyboardMode.resizeContent.description"}],nr=t=>t==="portrait"||t==="landscape"?t:"system",Eh=[{id:"markdown",labelKey:"settings.aiworker.visual.option.userMessageRendering.markdown.label",descriptionKey:"settings.aiworker.visual.option.userMessageRendering.markdown.description"},{id:"plain",labelKey:"settings.aiworker.visual.option.userMessageRendering.plain.label",descriptionKey:"settings.aiworker.visual.option.userMessageRendering.plain.description"}],Dh=[{id:"sorted",labelKey:"settings.aiworker.visual.option.chatRenderMode.sorted.label",descriptionKey:"settings.aiworker.visual.option.chatRenderMode.sorted.description"},{id:"live",labelKey:"settings.aiworker.visual.option.chatRenderMode.live.label",descriptionKey:"settings.aiworker.visual.option.chatRenderMode.live.description"}],el=[{id:"auto",labelKey:"settings.aiworker.visual.option.messageTransport.auto.label",descriptionKey:"settings.aiworker.visual.option.messageTransport.auto.description"},{id:"ws",labelKey:"settings.aiworker.visual.option.messageTransport.ws.label",descriptionKey:"settings.aiworker.visual.option.messageTransport.ws.description"},{id:"sse",labelKey:"settings.aiworker.visual.option.messageTransport.sse.label",descriptionKey:"settings.aiworker.visual.option.messageTransport.sse.description"}],Mh=[{id:"collapsed",labelKey:"settings.aiworker.visual.option.activityRenderMode.collapsed.label",descriptionKey:"settings.aiworker.visual.option.activityRenderMode.collapsed.description"},{id:"summary",labelKey:"settings.aiworker.visual.option.activityRenderMode.summary.label",descriptionKey:"settings.aiworker.visual.option.activityRenderMode.summary.description"}],tl=[{id:"auto",labelKey:"settings.aiworker.visual.option.timeFormat.auto.label",descriptionKey:"settings.aiworker.visual.option.timeFormat.auto.description"},{id:"24h",labelKey:"settings.aiworker.visual.option.timeFormat.24h.label",descriptionKey:"settings.aiworker.visual.option.timeFormat.24h.description"},{id:"12h",labelKey:"settings.aiworker.visual.option.timeFormat.12h.label",descriptionKey:"settings.aiworker.visual.option.timeFormat.12h.description"}],sl=[{id:"auto",labelKey:"settings.aiworker.visual.option.weekStart.auto.label",descriptionKey:"settings.aiworker.visual.option.weekStart.auto.description"},{id:"monday",labelKey:"settings.aiworker.visual.option.weekStart.monday.label"},{id:"sunday",labelKey:"settings.aiworker.visual.option.weekStart.sunday.label"}],Rh=[{id:"steer",labelKey:"settings.aiworker.visual.option.followUpBehavior.steer.label"},{id:"queue",labelKey:"settings.aiworker.visual.option.followUpBehavior.queue.label"}],Lh=[{id:"ask",labelKey:"settings.aiworker.visual.option.largeTextPaste.ask.label"},{id:"attach",labelKey:"settings.aiworker.visual.option.largeTextPaste.attach.label"},{id:"inline",labelKey:"settings.aiworker.visual.option.largeTextPaste.inline.label"}],Oh=[{id:"global",labelKey:"settings.aiworker.visual.option.inputHistoryScope.global.label"},{id:"session",labelKey:"settings.aiworker.visual.option.inputHistoryScope.session.label"}],Fh=t=>t==="markdown"?"markdown":"plain",Kh=[{id:"left",labelKey:"settings.aiworker.desktopNetwork.option.windowControlsLeft"},{id:"right",labelKey:"settings.aiworker.desktopNetwork.option.windowControlsRight"}],zh=[{id:"classic",labelKey:"settings.aiworker.desktopNetwork.option.windowControlsClassic"},{id:"traffic-lights",labelKey:"settings.aiworker.desktopNetwork.option.windowControlsTrafficLights"}],Pi=({visibleSettings:t})=>{const{locale:e,locales:a,setLocale:n,label:r,t:i}=tt(),l=o.useCallback(u=>i(u),[i]),{isMobile:g}=wa(),{terminal:c}=Nl(),{browserTab:y}=qd(),p=Td(),b=ie(u=>u.showReasoningTraces),d=ie(u=>u.sessionRecapEnabled),P=ie(u=>u.sessionSuggestionEnabled),f=ie(u=>u.setSessionRecapEnabled),C=ie(u=>u.setSessionSuggestionEnabled),v=ie(u=>u.sessionGoalEnabled),N=ie(u=>u.setSessionGoalEnabled),m=ie(u=>u.sessionGoalDefaultBudgetEnabled),A=ie(u=>u.setSessionGoalDefaultBudgetEnabled),R=ie(u=>u.sessionGoalDefaultBudget),I=ie(u=>u.setSessionGoalDefaultBudget),j=ie(u=>u.setShowReasoningTraces),h=ie(u=>u.streamingAutoFollowEnabled),w=ie(u=>u.setStreamingAutoFollowEnabled),F=ie(u=>u.collapsibleThinkingBlocks),T=ie(u=>u.setCollapsibleThinkingBlocks),S=ie(u=>u.mermaidRenderingMode),D=ie(u=>u.setMermaidRenderingMode),$=ie(u=>u.userMessageRenderingMode),B=ie(u=>u.setUserMessageRenderingMode),k=ie(u=>u.collapsibleUserMessages),G=ie(u=>u.setCollapsibleUserMessages),M=ie(u=>u.stickyUserHeader),L=ie(u=>u.promptNavigatorEnabled),J=ie(u=>u.setStickyUserHeader),ee=ie(u=>u.setPromptNavigatorEnabled),U=ie(u=>u.autoSaveEnabled),le=ie(u=>u.setAutoSaveEnabled),_=ie(u=>u.wideChatLayoutEnabled),H=ie(u=>u.setWideChatLayoutEnabled),z=ie(u=>u.codeBlockLineWrap),K=ie(u=>u.setCodeBlockLineWrap),te=ie(u=>u.chatRenderMode),Y=ie(u=>u.setChatRenderMode),ae=ie(u=>u.activityRenderMode),ge=ie(u=>u.setActivityRenderMode),de=ie(u=>u.fontSize),he=ie(u=>u.setFontSize),se=ie(u=>u.terminalFontSize),re=ie(u=>u.setTerminalFontSize),ue=ie(u=>u.terminalShell),Ce=ie(u=>u.setTerminalShell),Se=ie(u=>u.terminalLoginShells),ye=ie(u=>u.setTerminalLoginShells),fe=ie(u=>u.editorFontSize),_e=ie(u=>u.setEditorFontSize),Ue=ie(u=>u.uiFont),Ne=ie(u=>u.setUiFont),Oe=ie(u=>u.monoFont),Ve=ie(u=>u.setMonoFont),Ge=ie(u=>u.padding),ve=ie(u=>u.setPadding),Z=ie(u=>u.inputBarOffset),ne=ie(u=>u.setInputBarOffset),be=ie(u=>u.mobileKeyboardMode),we=ie(u=>u.setMobileKeyboardMode),Re=ie(u=>u.diffLayoutPreference),Fe=ie(u=>u.setDiffLayoutPreference),Ke=ie(u=>u.showTerminalQuickKeysOnDesktop),Ee=ie(u=>u.sessionTabsEnabled),je=ie(u=>u.setSessionTabsEnabled),Ze=ie(u=>u.setShowTerminalQuickKeysOnDesktop),me=ie(u=>u.fileEditorKeymap),Ie=ie(u=>u.setFileEditorKeymap),Le=Yr(u=>u.followUpBehavior),Xe=Yr(u=>u.setFollowUpBehavior),q=ai(u=>u.scope),ke=ai(u=>u.entryLimit),Pe=ai(u=>u.applyScope),Je=ai(u=>u.applyEntryLimit),ot=ie(u=>u.persistChatDraft),st=ie(u=>u.setPersistChatDraft),pt=ie(u=>u.inputSpellcheckEnabled),vt=ie(u=>u.setInputSpellcheckEnabled),W=ie(u=>u.largeTextPasteBehavior),We=ie(u=>u.setLargeTextPasteBehavior),nt=ie(u=>u.enterToSend),lt=ie(u=>u.setEnterToSend),ht=ie(u=>u.enterToSendConfigured),Lt=ie(u=>u.setEnterToSendConfigured),et=ht?nt:!g,ft=ie(u=>u.showToolFileIcons),bt=ie(u=>u.setShowToolFileIcons),Be=ie(u=>u.showTurnChangedFiles),Et=ie(u=>u.setShowTurnChangedFiles),Me=ie(u=>u.showExpandedBashTools),wt=ie(u=>u.setShowExpandedBashTools),Q=ie(u=>u.showExpandedEditTools),pe=ie(u=>u.setShowExpandedEditTools),De=ie(u=>u.timeFormatPreference),Ae=ie(u=>u.setTimeFormatPreference),it=ie(u=>u.weekStartPreference),rt=ie(u=>u.setWeekStartPreference),qe=ie(u=>u.showSplitAssistantMessageActions),Pt=ie(u=>u.setShowSplitAssistantMessageActions),ys=ie(u=>u.allowPromptingSubagentSessions),Xt=ie(u=>u.setAllowPromptingSubagentSessions),Os=ie(u=>u.draftStartersVisible),Wt=ie(u=>u.setDraftStartersVisible),is=Ye(u=>u.settingsMessageStreamTransport),Ht=Ye(u=>u.setSettingsMessageStreamTransport),bs=is,gs=Ye(u=>u.settingsDefaultFileViewerPreview),hs=Ye(u=>u.setSettingsDefaultFileViewerPreview),ds=ie(u=>u.isSettingsDialogOpen),{themeMode:Es,setThemeMode:oe,availableThemes:ct,customThemesLoading:xt,reloadCustomThemes:Qt,lightThemeId:Yt,darkThemeId:Bt,setLightThemePreference:rs,setDarkThemePreference:ws}=Cr(),[ss,jt]=o.useState(!1),At=o.useMemo(()=>as()&&typeof window<"u"&&window.__AIWORKER_PLATFORM__==="darwin",[]),Ut=ie(u=>u.dockBadgeEnabled),Ot=ie(u=>u.setDockBadgeEnabled),ns=ie(u=>u.alwaysShowScrollbars===!0),Ds=ie(u=>u.setAlwaysShowScrollbars),Ai=Ed(),Ti=ie(u=>u.desktopWindowControlsPosition),Ha=ie(u=>u.setDesktopWindowControlsPosition),Ei=ie(u=>u.desktopWindowControlsStyle),Fs=ie(u=>u.setDesktopWindowControlsStyle),[ja,Di]=o.useState(0),Ga=ie(u=>u.reportUsage),Wa=ie(u=>u.setReportUsage),Mi=o.useCallback(u=>{Wa(u),gt({reportUsage:u})},[Wa]),Ri=o.useCallback(u=>{Ha(u),gt({desktopWindowControlsPosition:u})},[Ha]),Li=o.useCallback(u=>{Fs(u),gt({desktopWindowControlsStyle:u})},[Fs]),qa=(ds||g||cs())&&(t?t.includes("chatRenderMode"):!0);o.useEffect(()=>{if(!qa)return;let u=null,mt=Date.now();const ps=()=>{const sn=Date.now();sn-mt>=420&&(Di(Fn=>(Fn+1)%24),mt=sn),u=requestAnimationFrame(ps)};(typeof document>"u"||document.visibilityState==="visible")&&(u=requestAnimationFrame(ps));const Rs=()=>{document.visibilityState==="visible"&&u===null?u=requestAnimationFrame(ps):document.visibilityState!=="visible"&&u!==null&&(cancelAnimationFrame(u),u=null)};return document.addEventListener("visibilitychange",Rs),()=>{document.removeEventListener("visibilitychange",Rs),u!==null&&cancelAnimationFrame(u)}},[qa]);const js=o.useCallback(u=>{B(u),gt({userMessageRenderingMode:u})},[B]),Ws=o.useCallback(u=>{J(u),gt({stickyUserHeader:u})},[J]),Zn=o.useCallback(u=>{ee(u),gt({promptNavigatorEnabled:u})},[ee]),mn=o.useCallback(u=>{Wt(u),gt({draftStartersVisible:u})},[Wt]),xn=o.useCallback(u=>{G(u),gt({collapsibleUserMessages:u})},[G]),Or=o.useCallback(u=>{H(u),gt({wideChatLayoutEnabled:u})},[H]),Xs=o.useCallback(u=>{Pt(u),gt({showSplitAssistantMessageActions:u})},[Pt]),Oi=o.useCallback(u=>{vt(u),gt({inputSpellcheckEnabled:u})},[vt]),Dn=o.useCallback(u=>{lt(u),Lt(!0),gt({enterToSend:u,enterToSendConfigured:!0})},[lt,Lt]),Xn=o.useCallback(u=>{Y(u),gt({chatRenderMode:u})},[Y]),Mn=o.useCallback(u=>{Ht(u),gt({messageStreamTransport:u})},[Ht]),ka=o.useCallback(u=>{Pe(u),gt({inputHistoryScope:u})},[Pe]),Fi=o.useCallback(u=>{const mt=Math.round(u);Dd(mt)&&(Je(mt),gt({inputHistoryLimit:mt}))},[Je]),os=o.useCallback(u=>{ge(u),gt({activityRenderMode:u})},[ge]),Ki=o.useCallback(u=>{D(u),gt({mermaidRenderingMode:u})},[D]),ea=o.useCallback(u=>{bt(u),gt({showToolFileIcons:u})},[bt]),ta=o.useCallback(u=>{Et(u),gt({showTurnChangedFiles:u})},[Et]),zi=o.useCallback(u=>{hs(u),gt({defaultFileViewerPreview:u}),window.dispatchEvent(new CustomEvent("aiworker:file-viewer-preview-mode-changed",{detail:{enabled:u}}))},[hs]),Ja=o.useCallback(u=>{wt(u),gt({showExpandedBashTools:u})},[wt]),Ui=o.useCallback(u=>{pe(u),gt({showExpandedEditTools:u})},[pe]),Qa=o.useCallback(u=>{Ae(u),gt({timeFormatPreference:u})},[Ae]),sa=o.useCallback(u=>{rt(u),gt({weekStartPreference:u})},[rt]),gn=o.useMemo(()=>ct.filter(u=>u.metadata.variant==="light").sort((u,mt)=>u.metadata.name.localeCompare(mt.metadata.name)),[ct]),Rn=o.useMemo(()=>ct.filter(u=>u.metadata.variant==="dark").sort((u,mt)=>u.metadata.name.localeCompare(mt.metadata.name)),[ct]),Na=o.useMemo(()=>gn.find(u=>u.metadata.id===Yt)??gn[0],[gn,Yt]),vn=o.useMemo(()=>Rn.find(u=>u.metadata.id===Bt)??Rn[0],[Rn,Bt]),na=o.useCallback((u,mt)=>{const ps=mt==="dark"?" Dark":" Light";return u.endsWith(ps)?u.slice(0,-ps.length):u},[]),ce=u=>t?t.includes(u):!0,ls=cs(),aa=ce("theme")&&!ls,Ya=ce("windowControlsPosition")&&Ai,Za=ce("theme")||ce("timeFormat")||ce("weekStart"),Xa=ls?Za:ce("theme")||Ya||ce("pwaInstallName")||ce("pwaOrientation")||ce("timeFormat")||ce("weekStart"),ei=ce("fontSize")||ce("terminalFontSize")||ce("editorFontSize")||ce("spacing")||ce("scrollbars")&&!aa||ce("inputBarOffset")&&g,ti=ce("terminalQuickKeys")&&!g||(ce("terminalShell")||ce("terminalLoginShell"))&&!ls||ce("fileEditorKeymap")||ce("autoSaveEnabled")||ce("sessionTabs")&&!ls&&!g,_i=ce("mermaidRendering")||ce("sessionGoal")&&!ls||ce("userMessageRendering")||ce("chatRenderMode")||ce("messageTransport")||ce("activityRenderMode")||ce("collapsibleUserMessages")||ce("stickyUserHeader")||ce("promptNavigatorEnabled")&&!ls||ce("wideChatLayout")||ce("codeBlockLineWrap")||ce("splitAssistantMessageActions")||ce("subagentReadOnlyBanner")||ce("diffLayout")||ce("dotfiles")||ce("fileViewerPreview")||ce("reasoning")||ce("followUpBehavior")||ce("inputHistoryScope")||ce("inputHistoryLimit")||ce("persistDraft")||ce("largeTextPaste")||ce("showToolFileIcons")||ce("expandedTools")||!g&&ce("inputSpellcheck")||ce("enterToSend"),en=ce("chatRenderMode")||ce("activityRenderMode"),yn=ce("messageTransport"),ia=ce("userMessageRendering")||ce("mermaidRendering")||ce("diffLayout")&&!ls||ce("followUpBehavior")||ce("inputHistoryScope")||ce("inputHistoryLimit"),$i=ce("sessionAssist")||ce("sessionGoal")&&!ls||ce("subagentReadOnlyBanner")||ce("collapsibleUserMessages")||ce("stickyUserHeader")||ce("promptNavigatorEnabled")&&!ls||ce("wideChatLayout")||ce("codeBlockLineWrap")||ce("splitAssistantMessageActions")||ce("dotfiles")||ce("fileViewerPreview")||ce("persistDraft")||ce("largeTextPaste")||ce("showToolFileIcons")||ce("showTurnChangedFiles")||!g&&ce("inputSpellcheck")||ce("enterToSend")||ce("reasoning")||ce("expandedTools"),x=Xa||ei||ti,X=ce("pwaInstallName")&&Bn()&&y&&!as()&&!ls,Te=ce("pwaOrientation")&&Bn()&&!as()&&!ls,Qe=ce("mobileKeyboardMode")&&Bn()&&!as()&&!ls&&Md(),Dt=(ce("terminalShell")||ce("terminalLoginShell"))&&!ls,[ks,us]=o.useState([]),[$s,Ns]=o.useState(0);o.useEffect(()=>Ml(()=>{us([]),Ns(u=>u+1)}),[]),o.useEffect(()=>{let u=!1;if(!(!Dt||!c.listShells))return c.listShells().then(mt=>{u||us(mt)}).catch(()=>{u||us([])}),()=>{u=!0}},[Dt,c,$s]);const qs=o.useMemo(()=>{const u=ks.filter(mt=>mt.id!=="auto");return ue==="auto"||u.some(mt=>mt.id===ue)?u:[{id:ue,name:ue,supportsLogin:!1},...u]},[ks,ue]),Sa=ks.find(u=>u.id===ue)?.supportsLogin===!0,Ln=Se.includes(ue),Ca=u=>{ye(u?[...Se.filter(mt=>mt!==ue),ue]:Se.filter(mt=>mt!==ue))},[kt,Gt]=o.useState(""),[tn,Nt]=o.useState("system"),Ms=o.useMemo(()=>{const u=tl.find(mt=>mt.id===De);return l(u?.labelKey??"settings.aiworker.visual.option.timeFormat.auto.label")},[De,l]),On=o.useMemo(()=>{const u=sl.find(mt=>mt.id===it);return l(u?.labelKey??"settings.aiworker.visual.option.weekStart.auto.label")},[it,l]),ra=o.useMemo(()=>{const u=Zo.find(mt=>mt.id===tn);return u?l(u.labelKey):void 0},[tn,l]),si=o.useMemo(()=>{const u=Xo.find(mt=>mt.id===be);return u?l(u.labelKey):void 0},[be,l]),Vi=o.useCallback(async u=>{if(typeof window>"u")return;const mt=window,Rs=u.trim().replace(/\s+/g," ").slice(0,64);if(await gt({pwaAppName:Rs}),typeof mt.__AIWORKER_SET_PWA_INSTALL_NAME__=="function"){const sn=mt.__AIWORKER_SET_PWA_INSTALL_NAME__(Rs);Gt(sn);return}Gt(Rs||Da),mt.__AIWORKER_UPDATE_PWA_MANIFEST__?.()},[]),Fr=o.useCallback(async u=>{if(typeof window>"u")return;const mt=window,ps=nr(u);if(await gt({pwaOrientation:ps}),typeof mt.__AIWORKER_SET_PWA_ORIENTATION__=="function"){const Rs=mt.__AIWORKER_SET_PWA_ORIENTATION__(ps);Nt(Rs);return}Nt(ps),mt.__AIWORKER_UPDATE_PWA_MANIFEST__?.()},[]);o.useEffect(()=>{if(typeof window>"u"||!X&&!Te&&!Qe)return;let u=!1;return(async()=>{try{const ps=await pn();if(!ps){u||Gt(Da);return}const sn=(ps.pwaAppName??"").trim().replace(/\s+/g," ").slice(0,64),Fn=nr(ps.pwaOrientation),ni=so(ps.mobileKeyboardMode);u||(X&&Gt(sn||Da),Te&&Nt(Fn),Qe&&we(ni))}catch{u||(X&&Gt(Da),Te&&Nt("system"),Qe&&we("native"))}})(),()=>{u=!0}},[we,Qe,X,Te]);const Bi=ce("scrollbars")?s.jsx(dt,{checked:ns,onChange:Ds,label:i("settings.aiworker.visual.field.alwaysShowScrollbars"),info:i("settings.aiworker.visual.field.alwaysShowScrollbarsHint"),settingsItem:"appearance.scrollbars"}):null;return s.jsxs("div",{className:"space-y-0",children:[Xa&&s.jsxs("div",{className:"space-y-0",children:[aa&&s.jsxs(ze,{title:i("settings.aiworker.visual.section.colorModeAndTheme"),divider:!1,children:[s.jsxs(Sn,{children:[s.jsx("div",{className:Qs,children:s.jsx(Js,{"aria-label":i("settings.aiworker.visual.section.colorMode"),children:Ph.map(u=>s.jsx(Bs,{selected:Es===u.value,onSelect:()=>oe(u.value),label:l(u.labelKey),ariaLabel:l(u.labelKey)},u.value))})}),s.jsxs("div",{className:Qs,children:[s.jsx(qt,{label:i("settings.aiworker.visual.field.lightTheme"),settingsItem:"appearance.light-theme",children:s.jsxs(St,{value:Na?.metadata.id??"",onValueChange:rs,children:[s.jsx(Ct,{"aria-label":i("settings.aiworker.visual.field.selectLightThemeAria"),size:Ft,className:bn,children:s.jsx(Mt,{placeholder:i("settings.aiworker.visual.field.selectThemePlaceholder"),children:Na?na(Na.metadata.name,"light"):void 0})}),s.jsx(It,{children:gn.map(u=>s.jsx(at,{value:u.metadata.id,children:na(u.metadata.name,"light")},u.metadata.id))})]})}),s.jsx(qt,{label:i("settings.aiworker.visual.field.darkTheme"),settingsItem:"appearance.dark-theme",children:s.jsxs(St,{value:vn?.metadata.id??"",onValueChange:ws,children:[s.jsx(Ct,{"aria-label":i("settings.aiworker.visual.field.selectDarkThemeAria"),size:Ft,className:bn,children:s.jsx(Mt,{placeholder:i("settings.aiworker.visual.field.selectThemePlaceholder"),children:vn?na(vn.metadata.name,"dark"):void 0})}),s.jsx(It,{children:Rn.map(u=>s.jsx(at,{value:u.metadata.id,children:na(u.metadata.name,"dark")},u.metadata.id))})]})}),s.jsxs("div",{className:"flex items-center gap-2 pt-1",children:[s.jsxs("button",{type:"button",disabled:xt||ss,onClick:()=>{const u=Date.now();jt(!0),Qt().finally(()=>{const mt=Date.now()-u;if(mt<500){window.setTimeout(()=>{jt(!1)},500-mt);return}jt(!1)})},className:"typography-settings-link inline-flex items-center gap-1.5 disabled:cursor-not-allowed disabled:opacity-50 disabled:no-underline",children:[s.jsx(O,{name:"restart",className:xe("h-3.5 w-3.5",ss&&"animate-spin")}),i(ss?"settings.aiworker.visual.actions.reloadingThemes":"settings.aiworker.visual.actions.reloadThemes")]}),s.jsx(Jt,{children:i("settings.aiworker.visual.field.themeImportInfoTooltip")})]})]})]}),At&&s.jsx(ba,{settingsItem:"appearance.dock-badge",children:s.jsx(dt,{checked:Ut,onChange:Ot,label:i("settings.aiworker.visual.field.dockBadge"),info:i("settings.aiworker.visual.field.dockBadgeHint"),ariaLabel:i("settings.aiworker.visual.field.dockBadge")})}),Bi&&s.jsx(ba,{children:Bi})]}),Ya&&s.jsx(ze,{title:i("settings.aiworker.desktopNetwork.field.windowControls"),info:i("settings.aiworker.desktopNetwork.field.windowControlsPositionDescription"),divider:aa,children:s.jsxs(Sn,{children:[s.jsx(qt,{label:i("settings.aiworker.desktopNetwork.field.windowControlsPosition"),settingsItem:"sessions.desktop-window-controls-position",children:s.jsx(Ys,{value:Ti,options:Kh.map(u=>({value:u.id,label:l(u.labelKey)})),onChange:Ri,"aria-label":i("settings.aiworker.desktopNetwork.field.windowControlsPositionAria")})}),s.jsx(qt,{label:i("settings.aiworker.desktopNetwork.field.windowControlsStyle"),settingsItem:"sessions.desktop-window-controls-style",children:s.jsx(Ys,{value:Ei,options:zh.map(u=>({value:u.id,label:l(u.labelKey)})),onChange:Li,"aria-label":i("settings.aiworker.desktopNetwork.field.windowControlsStyleAria")})})]})}),Za&&s.jsx(ze,{title:i("settings.aiworker.visual.section.localization"),children:s.jsxs(Sn,{children:[s.jsx(qt,{label:i("settings.appearance.language.label"),info:i("settings.appearance.language.description"),settingsItem:"appearance.language",children:s.jsxs(St,{value:e,onValueChange:u=>n(u),children:[s.jsx(Ct,{"aria-label":i("settings.appearance.language.select"),size:Ft,className:bn,children:s.jsx(Mt,{children:r(e)})}),s.jsx(It,{children:a.map(u=>s.jsx(at,{value:u,children:r(u)},u))})]})}),(ce("timeFormat")||ce("weekStart"))&&s.jsxs("div",{className:Qs,children:[ce("timeFormat")&&s.jsx(qt,{label:i("settings.aiworker.visual.field.timeFormat"),settingsItem:"appearance.time-format",children:s.jsxs(St,{value:De,onValueChange:u=>Qa(u),children:[s.jsx(Ct,{"aria-label":i("settings.aiworker.visual.field.selectTimeFormatAria"),size:Ft,className:bn,children:s.jsx(Mt,{children:Ms})}),s.jsx(It,{children:tl.map(u=>s.jsx(at,{value:u.id,children:l(u.labelKey)},u.id))})]})}),ce("weekStart")&&s.jsx(qt,{label:i("settings.aiworker.visual.field.weekStartsOn"),settingsItem:"appearance.week-start",children:s.jsxs(St,{value:it,onValueChange:u=>sa(u),children:[s.jsx(Ct,{"aria-label":i("settings.aiworker.visual.field.selectWeekStartAria"),size:Ft,className:bn,children:s.jsx(Mt,{children:On})}),s.jsx(It,{children:sl.map(u=>s.jsx(at,{value:u.id,children:l(u.labelKey)},u.id))})]})})]})]})}),(X||Te||Qe)&&s.jsxs(ze,{title:i("settings.aiworker.visual.section.appInstall"),contentClassName:Qs,children:[X&&s.jsxs(Rt,{label:i("settings.aiworker.visual.field.installAppName"),info:i("settings.aiworker.visual.field.installAppNameHint"),settingsItem:"appearance.pwa-install-name",alignEnd:!1,controlClassName:zs,children:[s.jsx(He,{value:kt,onChange:u=>{Gt(u.target.value)},onBlur:()=>{Vi(kt)},onKeyDown:u=>{u.key==="Enter"&&(u.preventDefault(),Vi(kt))},className:"min-w-0 flex-1",maxLength:64,"aria-label":i("settings.aiworker.visual.field.pwaInstallAppNameAria")}),s.jsx(V,{size:"sm",type:"button",variant:"ghost",onClick:()=>{Gt(Da),Vi("")},className:Cs,"aria-label":i("settings.aiworker.visual.actions.resetInstallAppNameAria"),title:i("settings.common.actions.reset"),children:s.jsx(O,{name:"restart",className:"h-3.5 w-3.5"})})]}),Te&&s.jsxs(Rt,{label:i("settings.aiworker.visual.field.installOrientation"),description:i("settings.aiworker.visual.field.installOrientationHint"),settingsItem:"appearance.pwa-orientation",alignEnd:!1,controlClassName:zs,children:[s.jsxs(St,{value:tn,onValueChange:u=>{const mt=nr(u);Nt(mt),Fr(mt)},children:[s.jsx(Ct,{"aria-label":i("settings.aiworker.visual.field.pwaInstallOrientationAria"),size:Ft,className:$r,children:s.jsx(Mt,{placeholder:i("settings.aiworker.visual.field.selectOrientationPlaceholder"),children:ra})}),s.jsx(It,{children:Zo.map(u=>s.jsx(at,{value:u.id,children:l(u.labelKey)},u.id))})]}),s.jsx(V,{size:"sm",type:"button",variant:"ghost",onClick:()=>{Nt("system"),Fr("system")},disabled:tn==="system",className:Cs,"aria-label":i("settings.aiworker.visual.actions.resetInstallOrientationAria"),title:i("settings.common.actions.reset"),children:s.jsx(O,{name:"restart",className:"h-3.5 w-3.5"})})]}),Qe&&s.jsxs(Rt,{label:i("settings.aiworker.visual.field.mobileKeyboardMode"),info:i("settings.aiworker.visual.field.mobileKeyboardModeHint"),settingsItem:"appearance.mobile-keyboard-mode",alignEnd:!1,controlClassName:zs,children:[s.jsxs(St,{value:be,onValueChange:u=>{const mt=so(u);we(mt),gt({mobileKeyboardMode:mt})},children:[s.jsx(Ct,{"aria-label":i("settings.aiworker.visual.field.mobileKeyboardModeAria"),size:Ft,className:$r,children:s.jsx(Mt,{placeholder:i("settings.aiworker.visual.field.selectMobileKeyboardModePlaceholder"),children:si})}),s.jsx(It,{children:Xo.map(u=>s.jsx(at,{value:u.id,children:l(u.labelKey)},u.id))})]}),s.jsx(V,{size:"sm",type:"button",variant:"ghost",onClick:()=>{we("native"),gt({mobileKeyboardMode:"native"})},disabled:be==="native",className:Cs,"aria-label":i("settings.aiworker.visual.actions.resetMobileKeyboardModeAria"),title:i("settings.common.actions.reset"),children:s.jsx(O,{name:"restart",className:"h-3.5 w-3.5"})})]})]})]}),ei&&s.jsxs(ze,{title:i("settings.aiworker.visual.section.densityAndType"),contentClassName:Qs,children:[ce("fontSize")&&!g||ce("terminalFontSize")?s.jsxs(Sn,{children:[ce("fontSize")&&!g&&s.jsxs(qt,{label:i("settings.aiworker.visual.field.interfaceFont"),settingsItem:"appearance.interface-font-size",controlClassName:"w-full",children:[s.jsxs(St,{value:Ue,onValueChange:u=>Ne(u),children:[s.jsx(Ct,{"aria-label":i("settings.aiworker.visual.field.selectInterfaceFontAria"),size:Ft,className:bn,children:s.jsx(Mt,{children:Zr.find(u=>u.id===Ue)?.label})}),s.jsx(It,{children:Zr.map(u=>s.jsx(at,{value:u.id,children:s.jsx("span",{style:{fontFamily:u.stack},children:u.label})},u.id))})]}),s.jsx(V,{size:"sm",type:"button",variant:"ghost",onClick:()=>Ne(Xr),disabled:Ue===Xr,className:Cs,"aria-label":i("settings.aiworker.visual.actions.resetInterfaceFontAria"),title:i("settings.common.actions.reset"),children:s.jsx(O,{name:"restart",className:"h-3.5 w-3.5"})})]}),ce("terminalFontSize")&&s.jsxs(qt,{label:i("settings.aiworker.visual.field.codeFont"),controlClassName:"w-full",children:[s.jsxs(St,{value:Oe,onValueChange:u=>Ve(u),children:[s.jsx(Ct,{"aria-label":i("settings.aiworker.visual.field.selectCodeFontAria"),size:Ft,className:bn,children:s.jsx(Mt,{children:eo.find(u=>u.id===Oe)?.label})}),s.jsx(It,{children:eo.map(u=>s.jsx(at,{value:u.id,children:s.jsx("span",{style:{fontFamily:u.stack},children:u.label})},u.id))})]}),s.jsx(V,{size:"sm",type:"button",variant:"ghost",onClick:()=>Ve(to),disabled:Oe===to,className:Cs,"aria-label":i("settings.aiworker.visual.actions.resetCodeFontAria"),title:i("settings.common.actions.reset"),children:s.jsx(O,{name:"restart",className:"h-3.5 w-3.5"})})]})]}):null,ce("fontSize")&&!g||ce("terminalFontSize")||ce("editorFontSize")?s.jsxs(Sn,{children:[ce("fontSize")&&!g&&s.jsx(qt,{label:i("settings.aiworker.visual.field.interfaceFontSize"),controlClassName:"w-full",children:s.jsxs("div",{className:la,children:[s.jsx(xs,{value:de,onValueChange:he,min:50,max:200,step:5,className:Ps,"aria-label":i("settings.aiworker.visual.field.fontSizePercentageAria")}),s.jsx("span",{className:ca,children:"%"}),s.jsx(V,{size:"sm",type:"button",variant:"ghost",onClick:()=>he(100),disabled:de===100,className:Cs,"aria-label":i("settings.aiworker.visual.actions.resetFontSizeAria"),title:i("settings.common.actions.reset"),children:s.jsx(O,{name:"restart",className:"h-3.5 w-3.5"})})]})}),ce("terminalFontSize")&&s.jsx(qt,{label:i("settings.aiworker.visual.field.terminalFontSize"),settingsItem:"appearance.terminal-font-size",controlClassName:"w-full",children:s.jsxs("div",{className:la,children:[s.jsx(xs,{value:se,onValueChange:re,min:9,max:52,step:1,className:Ps}),s.jsx("span",{className:ca,children:"px"}),s.jsx(V,{size:"sm",type:"button",variant:"ghost",onClick:()=>re(13),disabled:se===13,className:Cs,"aria-label":i("settings.aiworker.visual.actions.resetTerminalFontSizeAria"),title:i("settings.common.actions.reset"),children:s.jsx(O,{name:"restart",className:"h-3.5 w-3.5"})})]})}),ce("editorFontSize")&&s.jsx(qt,{label:i("settings.aiworker.visual.field.editorFontSize"),settingsItem:"appearance.editor-font-size",controlClassName:"w-full",children:s.jsxs("div",{className:la,children:[s.jsx(xs,{value:fe,onValueChange:_e,min:9,max:32,step:1,className:Ps}),s.jsx("span",{className:ca,children:"px"}),s.jsx(V,{size:"sm",type:"button",variant:"ghost",onClick:()=>_e(13),disabled:fe===13,className:Cs,"aria-label":i("settings.aiworker.visual.actions.resetEditorFontSizeAria"),title:i("settings.common.actions.reset"),children:s.jsx(O,{name:"restart",className:"h-3.5 w-3.5"})})]})})]}):null,ce("spacing")||ce("inputBarOffset")&&g?s.jsxs(Sn,{children:[ce("spacing")&&s.jsx(qt,{label:i("settings.aiworker.visual.field.spacingDensity"),settingsItem:"appearance.spacing-density",controlClassName:"w-full",children:s.jsxs("div",{className:la,children:[s.jsx(xs,{value:Ge,onValueChange:ve,min:50,max:200,step:5,className:Ps}),s.jsx("span",{className:ca,children:"%"}),s.jsx(V,{size:"sm",type:"button",variant:"ghost",onClick:()=>ve(100),disabled:Ge===100,className:Cs,"aria-label":i("settings.aiworker.visual.actions.resetSpacingAria"),title:i("settings.common.actions.reset"),children:s.jsx(O,{name:"restart",className:"h-3.5 w-3.5"})})]})}),ce("inputBarOffset")&&g&&s.jsx(qt,{label:i("settings.aiworker.visual.field.inputBarOffset"),info:i("settings.aiworker.visual.field.inputBarOffsetTooltip"),settingsItem:"appearance.input-bar-offset",controlClassName:"w-full",children:s.jsxs("div",{className:la,children:[s.jsx(xs,{value:Z,onValueChange:ne,min:0,max:100,step:5,className:Ps}),s.jsx("span",{className:ca,children:"px"}),s.jsx(V,{size:"sm",type:"button",variant:"ghost",onClick:()=>ne(0),disabled:Z===0,className:Cs,"aria-label":i("settings.aiworker.visual.actions.resetInputBarOffsetAria"),title:i("settings.common.actions.reset"),children:s.jsx(O,{name:"restart",className:"h-3.5 w-3.5"})})]})})]}):null,!aa&&Bi]}),ti&&s.jsxs(ze,{title:i("settings.aiworker.visual.section.navigation"),contentClassName:"space-y-4",children:[ce("fileEditorKeymap")&&s.jsx(Ss,{title:i("settings.aiworker.visual.field.fileEditorKeymap"),settingsItem:"appearance.file-editor-keymap",children:s.jsx(Js,{"aria-label":i("settings.aiworker.visual.field.fileEditorKeymap"),children:["default","vim"].map(u=>s.jsx(Bs,{selected:me===u,onSelect:()=>Ie(u),label:i(`settings.aiworker.visual.option.fileEditorKeymap.${u}`),ariaLabel:i(`settings.aiworker.visual.option.fileEditorKeymap.${u}`)},u))})}),s.jsxs("div",{className:fs,children:[ce("autoSaveEnabled")&&s.jsx(dt,{checked:U,onChange:le,label:i("settings.aiworker.visual.field.autoSaveEnabled"),ariaLabel:i("settings.aiworker.visual.field.autoSaveEnabledAria"),info:i("settings.aiworker.visual.field.autoSaveEnabledInfo"),settingsItem:"appearance.auto-save-enabled"}),Dt&&s.jsx(qt,{label:i("settings.aiworker.visual.field.terminalShell"),info:i("settings.aiworker.visual.field.terminalShellHint"),settingsItem:"appearance.terminal-shell",className:"pt-2",children:s.jsxs(St,{value:ue,onValueChange:u=>{Rd(u)&&Ce(u)},children:[s.jsx(Ct,{"aria-label":i("settings.aiworker.visual.field.terminalShellAria"),size:Ft,className:bn,children:s.jsx(Mt,{})}),s.jsxs(It,{children:[s.jsx(at,{value:"auto",children:i("settings.aiworker.visual.option.terminalShell.auto")}),qs.map(u=>s.jsx(at,{value:u.id,children:u.name},u.id))]})]})}),Dt&&Sa&&s.jsx(dt,{checked:Ln,onChange:Ca,label:i("settings.aiworker.visual.field.terminalLoginShell"),ariaLabel:i("settings.aiworker.visual.field.terminalLoginShell"),settingsItem:"appearance.terminal-login-shell"}),ce("terminalQuickKeys")&&!g&&s.jsx(dt,{checked:Ke,onChange:Ze,label:i("settings.aiworker.visual.field.terminalQuickKeys"),ariaLabel:i("settings.aiworker.visual.field.terminalQuickKeysAria"),settingsItem:"appearance.terminal-quick-keys",info:i("settings.aiworker.visual.field.terminalQuickKeysTooltip",{control:Gn("ctrl"),alt:Gn("alt")})})]}),ce("sessionTabs")&&!ls&&!g&&s.jsx(Ss,{title:i("settings.aiworker.visual.field.sessionTabsGroup"),settingsItem:"appearance.session-tabs",children:s.jsx(dt,{checked:Ee,onChange:je,label:i("settings.aiworker.visual.field.sessionTabs"),ariaLabel:i("settings.aiworker.visual.field.sessionTabsAria"),info:i("settings.aiworker.visual.field.sessionTabsInfo")})})]}),_i&&s.jsxs(s.Fragment,{children:[en&&s.jsxs(ze,{title:i("settings.aiworker.visual.section.chatDisplay"),divider:x,contentClassName:"space-y-6",children:[ce("chatRenderMode")&&s.jsx(Ss,{title:i("settings.aiworker.visual.section.chatRenderMode"),settingsItem:"chat.render-mode",children:s.jsx("div",{role:"radiogroup","aria-label":i("settings.aiworker.visual.section.chatRenderModeAria"),className:"grid w-full max-w-[26rem] grid-cols-1 gap-3 @xl:grid-cols-2",children:Dh.map(u=>{const mt=te===u.id,ps=ja%12;return s.jsxs("button",{type:"button",onClick:()=>Xn(u.id),"aria-pressed":mt,className:xe("flex flex-col items-start gap-1 rounded-lg border p-3 text-left transition-colors",mt?"border-primary bg-primary/5":"border-border hover:border-border/80 hover:bg-muted/50"),children:[s.jsx("span",{className:xe("typography-ui-label",mt?"text-foreground":"text-muted-foreground"),children:l(u.labelKey)}),s.jsx("div",{className:"mt-2 w-full rounded-md border border-border/60 bg-muted/30 p-2",children:u.id==="live"?s.jsx("div",{className:"space-y-1.5",children:[0,1,2].map(Rs=>{const sn=Rs*3+1,Fn=ps-sn+1,ni=Fn<=0?0:Fn===1?42:Fn===2?68:92,pc=ni>0;return s.jsxs("div",{className:xe("flex items-center gap-1.5 transition-all duration-300 motion-reduce:transition-none",pc?"translate-y-0 opacity-100":"translate-y-1 opacity-0"),children:[s.jsx("span",{className:"h-2 w-2 shrink-0 rounded-full bg-muted-foreground/55"}),s.jsx("span",{className:"h-1.5 rounded bg-muted-foreground/30 transition-all duration-300 motion-reduce:transition-none",style:{width:`${ni}%`}})]},Rs)})}):s.jsx("div",{className:"space-y-1.5",children:[0,1,2].map(Rs=>{const sn=ps>=(Rs+1)*3;return s.jsxs("div",{className:xe("flex items-center gap-1.5 transition-all duration-300 motion-reduce:transition-none",sn?"translate-y-0 opacity-100":"translate-y-1 opacity-0"),children:[s.jsx("span",{className:"h-2 w-2 shrink-0 rounded-full bg-muted-foreground/55"}),s.jsx("span",{className:"h-1.5 rounded bg-muted-foreground/30",style:{width:"92%"}})]},Rs)})})})]},u.id)})})}),ce("activityRenderMode")&&s.jsx(Ss,{title:i("settings.aiworker.visual.section.activityDefault"),settingsItem:"chat.activity-default",children:s.jsx(Js,{"aria-label":i("settings.aiworker.visual.section.activityDefaultAria"),children:Mh.map(u=>s.jsx(Bs,{selected:ae===u.id,onSelect:()=>os(u.id),label:l(u.labelKey),ariaLabel:i("settings.aiworker.visual.field.activityDefaultModeAria",{option:l(u.labelKey)})},u.id))})})]}),yn&&s.jsxs(ze,{title:i("settings.aiworker.visual.section.messageStreamTransport"),divider:en||x,settingsItem:"chat.message-transport",contentClassName:"space-y-2",children:[s.jsx(Ys,{value:bs,options:el.map(u=>({value:u.id,label:l(u.labelKey)})),onChange:Mn,"aria-label":i("settings.aiworker.visual.section.messageStreamTransport")}),(()=>{const u=el.find(mt=>mt.id===bs);return u?.descriptionKey?s.jsx("span",{className:"typography-meta text-muted-foreground",children:l(u.descriptionKey)}):null})()]}),ia&&s.jsx(ze,{title:i("settings.aiworker.visual.section.chatMessageOptions"),divider:en||yn||x,children:s.jsxs(Sn,{className:"lg:gap-y-6",children:[ce("userMessageRendering")&&s.jsx(Ss,{title:i("settings.aiworker.visual.section.userMessageRendering"),children:s.jsx(Js,{"aria-label":i("settings.aiworker.visual.section.userMessageRenderingAria"),children:Eh.map(u=>s.jsx(Bs,{selected:Fh($)===u.id,onSelect:()=>js(u.id),label:l(u.labelKey),ariaLabel:i("settings.aiworker.visual.field.userMessageRenderingAria",{option:l(u.labelKey)})},u.id))})}),ce("mermaidRendering")&&s.jsx(Ss,{title:i("settings.aiworker.visual.section.mermaidRendering"),children:s.jsx(Js,{"aria-label":i("settings.aiworker.visual.section.mermaidRenderingAria"),children:Th.map(u=>s.jsx(Bs,{selected:S===u.id,onSelect:()=>Ki(u.id),label:l(u.labelKey),ariaLabel:i("settings.aiworker.visual.field.mermaidRenderingAria",{option:l(u.labelKey)})},u.id))})}),ce("diffLayout")&&!ls&&s.jsx(Ss,{title:i("settings.aiworker.visual.section.diffLayout"),children:s.jsx(Js,{"aria-label":i("settings.aiworker.visual.section.diffLayoutAria"),children:Ah.map(u=>s.jsx(Bs,{selected:Re===u.id,onSelect:()=>Fe(u.id),label:l(u.labelKey),ariaLabel:i("settings.aiworker.visual.field.diffLayoutAria",{option:l(u.labelKey)})},u.id))})}),ce("followUpBehavior")&&s.jsx(Ss,{title:i("settings.aiworker.visual.section.followUpBehavior"),settingsItem:"chat.follow-up-behavior",children:s.jsx(Js,{"aria-label":i("settings.aiworker.visual.section.followUpBehaviorAria"),children:Rh.map(u=>s.jsx(Bs,{selected:Le===u.id,onSelect:()=>Xe(u.id),label:l(u.labelKey),ariaLabel:i("settings.aiworker.visual.field.followUpBehaviorAria",{option:l(u.labelKey)})},u.id))})}),ce("inputHistoryScope")&&s.jsx(Ss,{title:i("settings.aiworker.visual.field.inputHistoryScope"),info:i("settings.aiworker.visual.field.inputHistoryScopeDescription"),settingsItem:"chat.input-history-scope",children:s.jsx(Js,{"aria-label":i("settings.aiworker.visual.section.inputHistoryScopeAria"),children:Oh.map(u=>s.jsx(Bs,{selected:q===u.id,onSelect:()=>ka(u.id),label:l(u.labelKey),ariaLabel:l(u.labelKey)},u.id))})}),ce("inputHistoryLimit")&&s.jsx(Ss,{title:i("settings.aiworker.visual.field.inputHistoryLimit"),description:i("settings.aiworker.visual.field.inputHistoryLimitDescription"),contentClassName:zs,settingsItem:"chat.input-history-limit",children:s.jsxs("div",{className:la,children:[s.jsx(xs,{value:ke,onValueChange:Fi,min:Od,max:Ld,step:1,className:Ps,deferExternalValueWhileFocused:!0,"aria-label":i("settings.aiworker.visual.field.inputHistoryLimitAria")}),s.jsx("span",{className:ca,children:i("settings.aiworker.visual.field.inputHistoryLimitUnit")})]})})]})}),$i&&s.jsxs(s.Fragment,{children:[ce("expandedTools")&&s.jsxs(ze,{title:i("settings.aiworker.visual.section.showToolsOpenedByDefault"),divider:en||yn||ia||x,contentClassName:fs,children:[s.jsx(dt,{checked:Me,onChange:Ja,label:i("settings.aiworker.visual.field.bash"),ariaLabel:i("settings.aiworker.visual.field.showExpandedBashToolsAria")}),s.jsx(dt,{checked:Q,onChange:Ui,label:i("settings.aiworker.visual.field.editTools"),ariaLabel:i("settings.aiworker.visual.field.showExpandedEditToolsAria")})]}),s.jsxs(ze,{title:i("settings.aiworker.visual.section.sessionAssistance"),settingsItem:"chat.session-assistance",contentClassName:fs,children:[s.jsx(dt,{checked:Os,onChange:mn,label:i("settings.aiworker.visual.field.draftStartersVisible"),ariaLabel:i("settings.aiworker.visual.field.draftStartersVisibleAria"),settingsItem:"chat.draft-starters-visible"}),ce("sessionAssist")&&s.jsxs(s.Fragment,{children:[s.jsx(dt,{checked:d,onChange:f,label:i("settings.aiworker.visual.field.sessionRecap"),ariaLabel:i("settings.aiworker.visual.field.sessionRecapAria"),settingsItem:"chat.session-recap"}),s.jsx(dt,{checked:P,onChange:C,label:i("settings.aiworker.visual.field.sessionSuggestion"),ariaLabel:i("settings.aiworker.visual.field.sessionSuggestionAria"),settingsItem:"chat.session-suggestion"})]}),ce("subagentReadOnlyBanner")&&s.jsx(dt,{checked:ys,onChange:Xt,label:i("settings.aiworker.visual.field.allowPromptingSubagentSessions"),ariaLabel:i("settings.aiworker.visual.field.allowPromptingSubagentSessionsAria"),settingsItem:"chat.subagent-read-only-banner"})]}),ce("sessionGoal")&&!ls&&s.jsxs(ze,{title:i("settings.aiworker.visual.goal.sectionTitle"),info:i("settings.aiworker.visual.goal.description"),contentClassName:fs,children:[s.jsx(dt,{checked:v,onChange:N,label:i("settings.aiworker.visual.field.sessionGoal"),ariaLabel:i("settings.aiworker.visual.field.sessionGoalAria"),settingsItem:"chat.session-goal"}),s.jsxs("div",{"data-settings-item":"chat.session-goal-budget",className:"flex items-center gap-2",children:[s.jsx(dt,{checked:m,onChange:A,disabled:!v,label:i("settings.aiworker.visual.goal.budgetLabel"),ariaLabel:i("settings.aiworker.visual.goal.budgetAria")}),v&&m?s.jsx(xs,{value:R,onValueChange:u=>{typeof u=="number"&&Number.isFinite(u)&&u>0&&I(Math.floor(u))},min:1e3,max:1e8,step:5e4}):null]})]}),ce("reasoning")&&s.jsxs(ze,{title:i("settings.aiworker.visual.section.reasoning"),settingsItem:"chat.reasoning",contentClassName:fs,children:[s.jsx(dt,{checked:b,onChange:j,label:i("settings.aiworker.visual.field.showReasoningTraces"),ariaLabel:i("settings.aiworker.visual.field.showReasoningTracesAria"),settingsItem:"chat.reasoning-traces"}),b&&s.jsx(dt,{checked:F,onChange:T,label:i("settings.aiworker.visual.field.collapsibleThinkingBlocks"),ariaLabel:i("settings.aiworker.visual.field.collapsibleThinkingBlocksAria")})]}),s.jsx(ze,{title:i("settings.aiworker.visual.section.streaming"),settingsItem:"chat.streaming",contentClassName:fs,children:s.jsx(dt,{checked:h,onChange:w,label:i("settings.aiworker.visual.field.streamingAutoFollow"),ariaLabel:i("settings.aiworker.visual.field.streamingAutoFollowAria"),info:i("settings.aiworker.visual.field.streamingAutoFollowInfo"),settingsItem:"chat.streaming-auto-follow"})}),(ce("collapsibleUserMessages")||ce("stickyUserHeader")||ce("promptNavigatorEnabled")&&!ls||ce("wideChatLayout")||ce("splitAssistantMessageActions")||ce("codeBlockLineWrap"))&&s.jsxs(ze,{title:i("settings.aiworker.visual.section.messageAppearance"),settingsItem:"chat.message-appearance",contentClassName:fs,children:[ce("collapsibleUserMessages")&&s.jsx(dt,{checked:k,onChange:xn,label:i("settings.aiworker.visual.field.collapsibleUserMessages"),ariaLabel:i("settings.aiworker.visual.field.collapsibleUserMessagesAria"),settingsItem:"chat.collapsible-user-messages"}),ce("stickyUserHeader")&&s.jsx(dt,{checked:M,onChange:Ws,label:i("settings.aiworker.visual.field.stickyUserHeader"),ariaLabel:i("settings.aiworker.visual.field.stickyUserHeaderAria"),settingsItem:"chat.sticky-user-header"}),ce("promptNavigatorEnabled")&&!ls&&s.jsx(dt,{checked:L,onChange:Zn,label:i("settings.aiworker.visual.field.promptNavigatorEnabled"),ariaLabel:i("settings.aiworker.visual.field.promptNavigatorEnabledAria"),settingsItem:"chat.prompt-navigator"}),ce("wideChatLayout")&&s.jsx(dt,{checked:_,onChange:Or,label:i("settings.aiworker.visual.field.wideChatLayout"),ariaLabel:i("settings.aiworker.visual.field.wideChatLayoutAria"),settingsItem:"chat.wide-layout"}),ce("splitAssistantMessageActions")&&s.jsx(dt,{checked:qe,onChange:Xs,label:i("settings.aiworker.visual.field.showSplitAssistantMessageActions"),ariaLabel:i("settings.aiworker.visual.field.showSplitAssistantMessageActionsAria"),settingsItem:"chat.inline-assistant-actions",info:i("settings.aiworker.visual.field.showSplitAssistantMessageActionsTooltip")}),ce("codeBlockLineWrap")&&s.jsx(dt,{checked:z,onChange:K,label:i("settings.aiworker.visual.field.codeBlockLineWrap"),ariaLabel:i("settings.aiworker.visual.field.codeBlockLineWrapAria"),settingsItem:"chat.code-block-line-wrap"})]}),(ce("showToolFileIcons")||ce("showTurnChangedFiles")||ce("dotfiles")&&!cs()||ce("fileViewerPreview"))&&s.jsxs(ze,{title:i("settings.aiworker.visual.section.toolsAndFiles"),settingsItem:"chat.tools-and-files",contentClassName:fs,children:[ce("showToolFileIcons")&&s.jsx(dt,{checked:ft,onChange:ea,label:i("settings.aiworker.visual.field.showToolFileIcons"),ariaLabel:i("settings.aiworker.visual.field.showToolFileIconsAria"),settingsItem:"chat.tool-file-icons"}),ce("showTurnChangedFiles")&&s.jsx(dt,{checked:Be,onChange:ta,label:i("settings.aiworker.visual.field.showTurnChangedFiles"),ariaLabel:i("settings.aiworker.visual.field.showTurnChangedFilesAria"),settingsItem:"chat.changed-files"}),ce("dotfiles")&&!cs()&&s.jsx(dt,{checked:p,onChange:Fd,label:i("settings.aiworker.visual.field.showDotfiles"),ariaLabel:i("settings.aiworker.visual.field.showDotfilesAria"),settingsItem:"chat.dotfiles"}),ce("fileViewerPreview")&&s.jsx(dt,{checked:gs,onChange:zi,label:i("settings.aiworker.defaults.field.openFilesPreview"),ariaLabel:i("settings.aiworker.defaults.field.openFilesPreviewAria")})]}),(ce("persistDraft")||ce("largeTextPaste")||!g&&ce("inputSpellcheck")||ce("enterToSend"))&&s.jsxs(ze,{title:i("settings.aiworker.visual.section.composer"),settingsItem:"chat.composer",contentClassName:"space-y-6",children:[(ce("persistDraft")||!g&&ce("inputSpellcheck"))&&s.jsxs("div",{className:fs,children:[ce("persistDraft")&&s.jsx(dt,{checked:ot,onChange:st,label:i("settings.aiworker.visual.field.persistDraftMessages"),ariaLabel:i("settings.aiworker.visual.field.persistDraftMessagesAria"),settingsItem:"chat.persist-drafts"}),!g&&ce("inputSpellcheck")&&s.jsx(dt,{checked:pt,onChange:Oi,label:i("settings.aiworker.visual.field.enableSpellcheckInTextInputs"),ariaLabel:i("settings.aiworker.visual.field.enableSpellcheckInTextInputsAria"),settingsItem:"chat.spellcheck"})]}),ce("largeTextPaste")&&s.jsx(Ss,{title:i("settings.aiworker.visual.field.largeTextPaste"),description:i("settings.aiworker.visual.field.largeTextPasteHint"),settingsItem:"chat.large-text-paste",children:s.jsx(Js,{"aria-label":i("settings.aiworker.visual.field.largeTextPasteAria"),children:Lh.map(u=>s.jsx(Bs,{selected:W===u.id,onSelect:()=>We(u.id),label:l(u.labelKey),ariaLabel:i("settings.aiworker.visual.field.largeTextPasteOptionAria",{option:l(u.labelKey)})},u.id))})}),ce("enterToSend")&&s.jsx(Ss,{title:i("settings.aiworker.visual.field.enterToSend"),description:i("settings.aiworker.visual.field.enterToSendHint"),settingsItem:"chat.enter-to-send",children:s.jsxs(Js,{"aria-label":i("settings.aiworker.visual.field.enterToSend"),children:[s.jsx(Bs,{selected:et,onSelect:()=>Dn(!0),label:i("settings.aiworker.visual.option.enterToSend.enter.label"),ariaLabel:i("settings.aiworker.visual.option.enterToSend.enter.label")}),s.jsx(Bs,{selected:!et,onSelect:()=>Dn(!1),label:i("settings.aiworker.visual.option.enterToSend.modifier.label"),ariaLabel:i("settings.aiworker.visual.option.enterToSend.modifier.label")})]})})]})]})]}),ce("reportUsage")&&s.jsx(ze,{title:i("settings.aiworker.visual.section.privacy"),children:s.jsx(dt,{checked:Ga,onChange:Mi,label:i("settings.aiworker.visual.field.sendAnonymousUsageReports"),info:i("settings.aiworker.visual.field.sendAnonymousUsageReportsHint"),ariaLabel:i("settings.aiworker.visual.field.sendAnonymousUsageReportsAria"),settingsItem:"appearance.usage-reports"})})]})},Uh=1,_h=365,nl=30,$h=[{value:"archive",labelKey:"settings.aiworker.sessionRetention.action.archive"},{value:"delete",labelKey:"settings.aiworker.sessionRetention.action.delete"}],ec=()=>{const t=ut.c(105),{t:e}=tt(),a=ie(Vh),n=ie(Bh),r=ie(Hh),i=ie(Gh),l=ie(Wh),g=ie(qh),c=ie(Jh);let y;t[0]===Symbol.for("react.memo_cache_sentinel")?(y={autoRun:!1},t[0]=y):y=t[0];const{candidates:p,isRunning:b,runCleanup:d,action:P,status:f}=Jc(y),C=p.length;let v;t[1]!==d||t[2]!==e?(v=async()=>{const ye=await d({force:!0}).catch(()=>(E.error(e("sessions.sidebar.group.empty.loadFailed")),null));if(!(!ye||ye.skippedReason&&ye.skippedReason!=="no-candidates")){if(ye.completedIds.length===0&&ye.failedIds.length===0){E.message(ye.action==="archive"?e("settings.aiworker.sessionRetention.toast.noneEligibleArchive"):e("settings.aiworker.sessionRetention.toast.noneEligibleDelete"));return}ye.completedIds.length>0&&E.success(ye.action==="archive"?e("settings.aiworker.sessionRetention.toast.archivedCount",{count:ye.completedIds.length}):e("settings.aiworker.sessionRetention.toast.deletedCount",{count:ye.completedIds.length})),ye.failedIds.length>0&&E.error(ye.action==="archive"?e("settings.aiworker.sessionRetention.toast.failedArchiveCount",{count:ye.failedIds.length}):e("settings.aiworker.sessionRetention.toast.failedDeleteCount",{count:ye.failedIds.length}))}},t[1]=d,t[2]=e,t[3]=v):v=t[3];const N=v;let m;t[4]!==e?(m=e("settings.aiworker.sessionRetention.title"),t[4]=e,t[5]=m):m=t[5];const A=r?"settings.aiworker.sessionRetention.archivedTooltip":"settings.aiworker.sessionRetention.tooltip";let R;t[6]!==e||t[7]!==A?(R=e(A),t[6]=e,t[7]=A,t[8]=R):R=t[8];let I;t[9]!==e?(I=e("settings.aiworker.sessionRetention.field.enableAutoCleanup"),t[9]=e,t[10]=I):I=t[10];let j;t[11]!==e?(j=e("settings.aiworker.sessionRetention.field.enableAutoCleanupAria"),t[11]=e,t[12]=j):j=t[12];let h;t[13]!==a||t[14]!==i||t[15]!==I||t[16]!==j?(h=s.jsx(dt,{settingsItem:"sessions.auto-cleanup",checked:a,onChange:i,label:I,ariaLabel:j}),t[13]=a,t[14]=i,t[15]=I,t[16]=j,t[17]=h):h=t[17];let w;t[18]!==e?(w=e("settings.aiworker.sessionRetention.field.onlyArchived"),t[18]=e,t[19]=w):w=t[19];let F;t[20]!==e?(F=e("settings.aiworker.sessionRetention.field.onlyArchived"),t[20]=e,t[21]=F):F=t[21];let T;t[22]!==e?(T=e("settings.aiworker.sessionRetention.field.onlyArchivedDescription"),t[22]=e,t[23]=T):T=t[23];let S;t[24]!==b||t[25]!==r||t[26]!==c||t[27]!==T||t[28]!==w||t[29]!==F?(S=s.jsx(dt,{settingsItem:"sessions.retention-only-archived",checked:r,onChange:c,disabled:b,label:w,ariaLabel:F,info:T}),t[24]=b,t[25]=r,t[26]=c,t[27]=T,t[28]=w,t[29]=F,t[30]=S):S=t[30];let D;t[31]!==e?(D=e("settings.aiworker.sessionRetention.field.retentionPeriod"),t[31]=e,t[32]=D):D=t[32];let $;t[33]!==e?($=e("settings.aiworker.sessionRetention.field.retentionPeriodAria"),t[33]=e,t[34]=$):$=t[34];let B;t[35]===Symbol.for("react.memo_cache_sentinel")?(B=xe(Ps,"tabular-nums"),t[35]=B):B=t[35];let k;t[36]!==n||t[37]!==l||t[38]!==$?(k=s.jsx(xs,{value:n,onValueChange:l,min:Uh,max:_h,step:1,"aria-label":$,className:B}),t[36]=n,t[37]=l,t[38]=$,t[39]=k):k=t[39];let G;t[40]!==e?(G=e("settings.aiworker.sessionRetention.field.days"),t[40]=e,t[41]=G):G=t[41];let M;t[42]!==G?(M=s.jsx("span",{className:"typography-ui-label text-muted-foreground",children:G}),t[42]=G,t[43]=M):M=t[43];let L;t[44]!==l?(L=()=>l(nl),t[44]=l,t[45]=L):L=t[45];const J=n===nl;let ee;t[46]!==e?(ee=e("settings.aiworker.sessionRetention.actions.resetRetentionAria"),t[46]=e,t[47]=ee):ee=t[47];let U;t[48]!==e?(U=e("settings.common.actions.reset"),t[48]=e,t[49]=U):U=t[49];let le;t[50]===Symbol.for("react.memo_cache_sentinel")?(le=s.jsx(O,{name:"restart",className:"h-3.5 w-3.5"}),t[50]=le):le=t[50];let _;t[51]!==L||t[52]!==J||t[53]!==ee||t[54]!==U?(_=s.jsx(V,{size:"sm",type:"button",variant:"ghost",onClick:L,disabled:J,className:Cs,"aria-label":ee,title:U,children:le}),t[51]=L,t[52]=J,t[53]=ee,t[54]=U,t[55]=_):_=t[55];let H;t[56]!==D||t[57]!==k||t[58]!==M||t[59]!==_?(H=s.jsxs(Rt,{settingsItem:"sessions.retention-period",label:D,children:[k,M,_]}),t[56]=D,t[57]=k,t[58]=M,t[59]=_,t[60]=H):H=t[60];let z;t[61]!==e?(z=e("settings.aiworker.sessionRetention.field.whenSessionsExpire"),t[61]=e,t[62]=z):z=t[62];let K;t[63]!==r||t[64]!==e?(K=$h.map(ye=>({value:ye.value,label:e(ye.labelKey),disabled:r&&ye.value==="archive"})),t[63]=r,t[64]=e,t[65]=K):K=t[65];let te;t[66]!==P||t[67]!==g||t[68]!==K?(te=s.jsx(Ys,{value:P,onChange:g,options:K}),t[66]=P,t[67]=g,t[68]=K,t[69]=te):te=t[69];let Y;t[70]!==z||t[71]!==te?(Y=s.jsx(Rt,{settingsItem:"sessions.retention-action",label:z,children:te}),t[70]=z,t[71]=te,t[72]=Y):Y=t[72];let ae;t[73]!==S||t[74]!==H||t[75]!==Y?(ae=s.jsxs(ba,{className:"space-y-0",children:[S,H,Y]}),t[73]=S,t[74]=H,t[75]=Y,t[76]=ae):ae=t[76];let ge;t[77]!==e?(ge=e("settings.aiworker.sessionRetention.manualCleanup.title"),t[77]=e,t[78]=ge):ge=t[78];let de;t[79]!==b||t[80]!==e?(de=e(b?"settings.aiworker.sessionRetention.actions.cleaningUp":"settings.aiworker.sessionRetention.actions.runCleanupNow"),t[79]=b,t[80]=e,t[81]=de):de=t[81];let he;t[82]!==N||t[83]!==b||t[84]!==de?(he=s.jsx(V,{type:"button",variant:"outline",size:"xs",onClick:N,disabled:b,className:"!font-normal",children:de}),t[82]=N,t[83]=b,t[84]=de,t[85]=he):he=t[85];let se;t[86]!==ge||t[87]!==he?(se=s.jsx(Rt,{label:ge,children:he}),t[86]=ge,t[87]=he,t[88]=se):se=t[88];let re;t[89]!==P||t[90]!==C||t[91]!==f||t[92]!==e?(re=f==="error"?e("sessions.sidebar.group.empty.loadFailed"):f!=="ready"?e("sessions.sidebar.group.empty.loadingSessions"):P==="archive"?e("settings.aiworker.sessionRetention.manualCleanup.eligibleArchiveNow",{count:C}):e("settings.aiworker.sessionRetention.manualCleanup.eligibleDeleteNow",{count:C}),t[89]=P,t[90]=C,t[91]=f,t[92]=e,t[93]=re):re=t[93];let ue;t[94]!==re?(ue=s.jsx("p",{className:"typography-meta text-muted-foreground",children:re}),t[94]=re,t[95]=ue):ue=t[95];let Ce;t[96]!==se||t[97]!==ue?(Ce=s.jsxs("div",{className:"mt-1 py-1.5 space-y-1",children:[se,ue]}),t[96]=se,t[97]=ue,t[98]=Ce):Ce=t[98];let Se;return t[99]!==m||t[100]!==ae||t[101]!==Ce||t[102]!==R||t[103]!==h?(Se=s.jsxs(ze,{title:m,info:R,children:[h,ae,Ce]}),t[99]=m,t[100]=ae,t[101]=Ce,t[102]=R,t[103]=h,t[104]=Se):Se=t[104],Se};function Vh(t){return t.autoDeleteEnabled}function Bh(t){return t.autoDeleteAfterDays}function Hh(t){return t.sessionRetentionOnlyArchived}function Gh(t){return t.setAutoDeleteEnabled}function Wh(t){return t.setAutoDeleteAfterDays}function qh(t){return t.setSessionRetentionAction}function Jh(t){return t.setSessionRetentionOnlyArchived}const al=(t,e,a)=>!t||!Number.isFinite(t)?e:new Intl.DateTimeFormat(Sr(),{dateStyle:"medium",timeStyle:"short",hour12:a==="auto"?void 0:a==="12h"}).format(t),tc=()=>{const{t}=tt(),e=ie(h=>h.timeFormatPreference),[a,n]=o.useState(!1),[r,i]=o.useState(!0),[l,g]=o.useState(!1),[c,y]=o.useState(null),[p,b]=o.useState(!1),[d,P]=o.useState([]),[f,C]=o.useState(Qc),[v,N]=o.useState(""),m=o.useMemo(()=>Yc(),[]),A=o.useCallback(async()=>{i(!0),N("");try{const h=await Zc();P(h)}catch(h){const w=h instanceof Error?h.message:t("settings.aiworker.passkeys.toast.loadFailed");N(w)}finally{i(!1)}},[t]);o.useEffect(()=>{let h=!1;return(async()=>{try{if(!m.supported){h||(n(!1),i(!1));return}h||n(!0)}catch{h||n(!1)}if(!h){const w=await Gi();if(C(w),!w.enabled){P([]),i(!1);return}await A()}})(),()=>{h=!0,Vr()}},[A,m.supported]);const R=o.useCallback(async()=>{if(!f.enabled){const h=t("settings.aiworker.passkeys.toast.enableUiPasswordFirst");N(h),E.message(h);return}if(!a){N(m.reason),E.message(m.reason);return}if(l){Vr(),g(!1);return}N(""),g(!0);try{await Xc(),C(await Gi()),await A(),E.success(t("settings.aiworker.passkeys.toast.added"))}catch(h){if(ed(h)){E.message(t("settings.aiworker.passkeys.toast.setupCanceled"));return}const w=h instanceof Error?h.message:t("settings.aiworker.passkeys.toast.addFailed");N(w),E.error(w)}finally{g(!1)}},[l,A,f.enabled,m.reason,a,t]),I=o.useCallback(async h=>{y(h),N("");try{await td(h),C(await Gi()),await A(),E.success(t("settings.aiworker.passkeys.toast.removed"))}catch(w){const F=w instanceof Error?w.message:t("settings.aiworker.passkeys.toast.removeFailed");N(F),E.error(F)}finally{y(null)}},[A,t]),j=o.useCallback(async()=>{b(!0),N("");try{await sd(),window.location.reload()}catch(h){const w=h instanceof Error?h.message:t("settings.aiworker.passkeys.toast.clearAuthFailed");N(w),E.error(w),b(!1)}},[t]);return s.jsxs(ze,{title:t("settings.aiworker.passkeys.title"),children:[s.jsxs("div",{className:"space-y-2",children:[s.jsxs(Rt,{label:t("settings.aiworker.passkeys.field.currentDevice"),children:[s.jsx(V,{type:"button",variant:l?"secondary":"outline",size:"xs",onClick:()=>{R()},disabled:r||p,className:"!font-normal",children:t(l?"settings.aiworker.passkeys.actions.cancelSetup":"settings.aiworker.passkeys.actions.add")}),s.jsx(V,{type:"button",variant:"ghost",size:"xs",onClick:()=>{j()},disabled:r||l||p,className:"!font-normal text-muted-foreground hover:text-foreground",children:t(p?"settings.aiworker.passkeys.actions.signingOut":"settings.aiworker.passkeys.actions.signOutEverywhere")})]}),!f.enabled&&s.jsx("p",{className:"typography-meta text-muted-foreground",children:t("settings.aiworker.passkeys.state.uiPasswordRequired")}),f.enabled&&!a&&s.jsx("p",{className:"typography-meta text-muted-foreground",children:m.reason}),r?s.jsx("p",{className:"typography-meta text-muted-foreground",children:t("settings.aiworker.passkeys.state.loading")}):d.length===0?s.jsx("p",{className:"typography-meta text-muted-foreground",children:t("settings.aiworker.passkeys.state.noneSaved")}):s.jsx("div",{className:"space-y-1 pt-1",children:d.map(h=>s.jsxs(Rt,{label:s.jsx("span",{title:h.label,children:h.label}),alignEnd:!1,controlClassName:"justify-between sm:flex-1",children:[s.jsx("span",{className:"typography-meta text-muted-foreground truncate",children:h.lastUsedAt?t("settings.aiworker.passkeys.item.lastUsed",{time:al(h.lastUsedAt,t("settings.aiworker.passkeys.time.neverUsed"),e)}):t("settings.aiworker.passkeys.item.added",{time:al(h.createdAt,t("settings.aiworker.passkeys.time.neverUsed"),e)})}),s.jsx(V,{type:"button",variant:"ghost",size:"xs",onClick:()=>{I(h.id)},disabled:c===h.id,className:"!font-normal text-muted-foreground hover:text-foreground",children:c===h.id?t("settings.aiworker.passkeys.actions.removing"):t("settings.common.actions.delete")})]},h.id))})]}),v&&s.jsx("div",{className:"mt-1 py-1.5",children:s.jsx("p",{className:"typography-meta text-[var(--status-error)]",children:v})})]})},sc=()=>{const t=ut.c(14),{t:e}=tt(),a=Br(Qh),n=Br(Yh);let r;t[0]!==e?(r=e("settings.aiworker.appLinks.title"),t[0]=e,t[1]=r):r=t[1];let i;t[2]!==e?(i=e("settings.aiworker.appLinks.info"),t[2]=e,t[3]=i):i=t[3];let l;t[4]!==n||t[5]!==e||t[6]!==a?(l=a.length===0?s.jsx("p",{className:"typography-meta text-muted-foreground",children:e("settings.aiworker.appLinks.empty")}):a.map(y=>s.jsxs("div",{className:"flex items-center justify-between gap-2 py-0.5",children:[s.jsx("span",{className:"min-w-0 truncate font-mono text-[13px]",children:`${y}://`}),s.jsx(V,{type:"button",variant:"ghost",size:"xs",onClick:()=>n(y),className:"!font-normal text-muted-foreground hover:text-foreground","aria-label":e("settings.aiworker.appLinks.removeAria",{scheme:`${y}://`}),children:e("settings.common.actions.delete")})]},y)),t[4]=n,t[5]=e,t[6]=a,t[7]=l):l=t[7];let g;t[8]!==l?(g=s.jsx("div",{className:"space-y-1","data-settings-item":"general.app-links",children:l}),t[8]=l,t[9]=g):g=t[9];let c;return t[10]!==r||t[11]!==i||t[12]!==g?(c=s.jsx(ze,{title:r,description:i,children:g}),t[10]=r,t[11]=i,t[12]=g,t[13]=c):c=t[13],c};function Qh(t){return t.trustedSchemes}function Yh(t){return t.removeTrustedScheme}const ar=t=>{const e=xa(t);return e||{providerId:"",modelId:""}},nc=()=>{const{t}=tt(),e=Ye(se=>se.setProvider),a=Ye(se=>se.setModel),n=Ye(se=>se.setAgent),r=Ye(se=>se.setCurrentVariant),i=Ye(se=>se.setCurrentVariantOverride),l=Ye(se=>se.setSettingsDefaultModel),g=Ye(se=>se.setSettingsDefaultVariant),c=Ye(se=>se.setSettingsDefaultAgent),y=Ye(se=>se.selectionSource==="manual"),p=nd(se=>se.currentSessionId),b=Hr(se=>se.getSessionModelSelection),d=Hr(se=>se.getSessionAgentSelection),P=!!(y&&p&&b(p)),f=!!(y&&p&&d(p)),C=ie(se=>se.showDeletionDialog),v=ie(se=>se.setShowDeletionDialog),N=Ye(se=>se.providers),m=Ye(se=>se.modelsMetadata),[A,R]=o.useState(),[I,j]=o.useState(),[h,w]=o.useState(),[F,T]=o.useState(!0),[S,D]=o.useState(),[$,B]=o.useState([]),[k,G]=o.useState(),[M,L]=o.useState(!0),J=o.useMemo(()=>ar(A),[A]);o.useEffect(()=>{(async()=>{try{const re=await pn();if(re){const ue=re.defaultModel?.trim()||void 0,Ce=re.defaultVariant?.trim()||void 0,Se=re.defaultAgent?.trim()||void 0;ue!==void 0&&R(ue),Ce!==void 0&&j(Ce),Se!==void 0&&w(Se),re.smallModelUseDefault!==void 0&&T(re.smallModelUseDefault);const ye=re.smallModelOverride?.trim();ye&&D(ye);const fe=re.walkthroughModelOverride?.trim();fe&&G(fe)}}catch(re){console.warn("Failed to load defaults settings:",re)}finally{L(!1)}})()},[]);const ee=o.useCallback(async(se,re)=>{const ue=se&&re?`${se}/${re}`:void 0;R(ue),j(void 0),g(void 0),l(ue),P||(r(void 0),se&&re&&N.find(Se=>Se.id===se)&&(e(se),a(re)));try{await gt({defaultModel:ue??"",defaultVariant:""})}catch(Ce){console.warn("Failed to save default model:",Ce)}},[P,N,r,a,e,l,g]),U="__default__",le=o.useCallback(se=>se===U?t("settings.aiworker.defaults.option.default"):se.charAt(0).toUpperCase()+se.slice(1),[t]),_=o.useCallback(async se=>{const re=se===U?void 0:se||void 0;j(re),g(re),P||i(re??null,re);try{await gt({defaultVariant:re??""})}catch(ue){console.warn("Failed to save default variant:",ue)}},[P,i,g]),H=o.useCallback(async se=>{const re=se||void 0;w(re),c(re),se&&!f&&n(se);try{await gt({defaultAgent:re??""})}catch(ue){console.warn("Failed to save default agent:",ue)}},[f,n,c]),z=o.useCallback(async se=>{T(se);try{await gt({smallModelUseDefault:se})}catch(re){console.warn("Failed to save small model preference:",re)}},[]),K=o.useCallback(async(se,re)=>{const ue=se&&re?`${se}/${re}`:void 0;D(ue);try{await gt({smallModelOverride:ue??""})}catch(Ce){console.warn("Failed to save small model override:",Ce)}},[]),te=o.useCallback(async(se,re)=>{const ue=se&&re?`${se}/${re}`:void 0;G(ue);try{await gt({walkthroughModelOverride:ue??""})}catch(Ce){console.warn("Failed to save walkthrough model override:",Ce)}},[]),Y=o.useCallback((se,re)=>m.get(`${se}/${re}`)?.structured_output!==!1,[m]),ae=o.useMemo(()=>ar(S),[S]),ge=o.useMemo(()=>ar(k),[k]);o.useEffect(()=>{let se=!1;return(async()=>{try{const re=await yt("/api/small-model",{method:"GET",headers:{Accept:"application/json"}});if(!re.ok)return;const ue=await re.json().catch(()=>null);!se&&Array.isArray(ue?.authenticatedProviders)&&B(ue.authenticatedProviders.filter(Ce=>typeof Ce=="string"))}catch{}})(),()=>{se=!0}},[]);const de=o.useMemo(()=>{if(!J.providerId||!J.modelId)return[];const ue=N.find(Ce=>Ce.id===J.providerId)?.models.find(Ce=>Ce.id===J.modelId)?.variants;return ue?Object.keys(ue):[]},[J.modelId,J.providerId,N]),he=de.length>0;return M?null:s.jsx(s.Fragment,{children:s.jsx(ze,{title:t("settings.aiworker.defaults.title"),divider:!1,children:s.jsxs("div",{className:"space-y-0",children:[s.jsxs("div",{className:"mt-0 mb-1 typography-meta text-muted-foreground",children:[t("settings.aiworker.defaults.summaryPrefix")," ",J.providerId?s.jsxs("span",{className:"text-foreground",children:[J.providerId,"/",J.modelId,he?` (${I??t("settings.aiworker.defaults.option.defaultLowercase")})`:""]}):s.jsx("span",{className:"text-foreground",children:t("settings.aiworker.defaults.summaryOpenCodeDefault")}),h&&s.jsxs(s.Fragment,{children:[" / ",s.jsx("span",{className:"text-foreground",children:h})]})]}),s.jsxs("div",{children:[s.jsx(Rt,{settingsItem:"sessions.default-model",label:t("settings.aiworker.defaults.field.defaultModel"),children:s.jsx(Fa,{providerId:J.providerId,modelId:J.modelId,onChange:ee,className:In})}),s.jsx(Rt,{settingsItem:"sessions.default-thinking",label:t("settings.aiworker.defaults.field.defaultThinking"),children:s.jsxs(St,{value:I??U,onValueChange:_,disabled:!he,children:[s.jsx(Ct,{size:Ft,className:rn,children:s.jsx(Mt,{placeholder:t("settings.aiworker.defaults.field.thinkingPlaceholder"),children:le(I??U)})}),s.jsxs(It,{children:[s.jsx(at,{value:U,children:t("settings.aiworker.defaults.option.default")}),de.map(se=>s.jsx(at,{value:se,children:le(se)},se))]})]})}),s.jsx(Rt,{settingsItem:"sessions.default-agent",label:t("settings.aiworker.defaults.field.defaultAgent"),children:s.jsx(bl,{agentName:h||"",onChange:H,filter:se=>ad(se.mode),className:In})})]}),s.jsx(ba,{className:fs,children:s.jsx(dt,{settingsItem:"sessions.deletion-dialog",checked:C,onChange:v,label:t("settings.aiworker.defaults.field.showDeletionDialog"),ariaLabel:t("settings.aiworker.defaults.field.showDeletionDialogAria")})}),s.jsxs("div",{className:"space-y-3 pt-6",children:[s.jsxs("div",{className:"flex items-center gap-1.5",children:[s.jsx(Zs,{children:t("settings.aiworker.defaults.smallModel.title")}),s.jsx(Jt,{children:t("settings.aiworker.defaults.smallModel.description")})]}),s.jsx(dt,{settingsItem:"sessions.small-model",checked:F,onChange:se=>{z(se)},label:t("settings.aiworker.defaults.smallModel.useDefault"),ariaLabel:t("settings.aiworker.defaults.smallModel.useDefaultAria")}),F?null:s.jsx(Rt,{label:t("settings.aiworker.defaults.smallModel.overrideModel"),children:s.jsx(Fa,{providerId:ae.providerId,modelId:ae.modelId,onChange:K,allowedProviderIds:$,className:In})}),s.jsxs(ba,{className:fs,children:[s.jsxs("div",{className:"flex items-center gap-1.5",children:[s.jsx(Zs,{children:t("settings.aiworker.defaults.walkthroughModel.title")}),s.jsx(Jt,{children:t("settings.aiworker.defaults.walkthroughModel.description")})]}),s.jsx(Rt,{settingsItem:"sessions.walkthrough-model",label:t("settings.aiworker.defaults.walkthroughModel.overrideModel"),children:s.jsx(Fa,{providerId:ge.providerId,modelId:ge.modelId,onChange:te,allowedProviderIds:$,isModelAllowed:Y,placeholder:t("settings.aiworker.defaults.walkthroughModel.usesSmallModel"),className:In})})]})]})]})})})},il={completion:{titleKey:"settings.notifications.page.template.defaults.completion.title",messageKey:"settings.notifications.page.template.defaults.completion.message"},error:{titleKey:"settings.notifications.page.template.defaults.error.title",messageKey:"settings.notifications.page.template.defaults.error.message"},question:{titleKey:"settings.notifications.page.template.defaults.question.title",messageKey:"settings.notifications.page.template.defaults.question.message"},subtask:{titleKey:"settings.notifications.page.template.defaults.subtask.title",messageKey:"settings.notifications.page.template.defaults.subtask.message"}},Zh={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"},Xh=()=>{const{t}=tt(),e=o.useMemo(()=>as(),[]),a=o.useMemo(()=>cs(),[]),n=o.useMemo(()=>typeof window>"u"?!1:window.Capacitor?.isNativePlatform?.()===!0||window.location.protocol==="capacitor:",[]),r=!e&&!a&&!n,i=ie(_=>_.nativeNotificationsEnabled),l=ie(_=>_.setNativeNotificationsEnabled),g=ie(_=>_.notificationMode),c=ie(_=>_.setNotificationMode),y=ie(_=>_.notifyOnSubtasks),p=ie(_=>_.setNotifyOnSubtasks),b=ie(_=>_.notifyOnCompletion),d=ie(_=>_.setNotifyOnCompletion),P=ie(_=>_.notifyOnError),f=ie(_=>_.setNotifyOnError),C=ie(_=>_.notifyOnQuestion),v=ie(_=>_.setNotifyOnQuestion),N=ie(_=>_.notificationTemplates),m=ie(_=>_.setNotificationTemplates),[A,R]=o.useState("default"),[I,j]=o.useState(!1),[h,w]=o.useState(!1),[F,T]=o.useState(!1);o.useEffect(()=>{if(!r){j(!1),w(!1);return}typeof Notification<"u"&&R(Notification.permission);const _=typeof window<"u"&&"serviceWorker"in navigator&&"PushManager"in window&&"Notification"in window;j(_),(async()=>{if(!_){w(!1);return}try{const z=await navigator.serviceWorker.getRegistration();if(!z){w(!1);return}const K=await z.pushManager.getSubscription();w(!!K)}catch{w(!1)}})()},[r]);const S=async _=>{if(e){l(_);return}if(!r){l(_);return}if(_&&typeof Notification<"u"&&Notification.permission==="default")try{const H=await Notification.requestPermission();R(H),H==="granted"?l(!0):E.error(t("settings.notifications.page.toast.permissionDenied.title"),{description:t("settings.notifications.page.toast.permissionDenied.description")})}catch(H){console.error("Failed to request notification permission:",H),E.error(t("settings.notifications.page.toast.requestPermissionFailed"))}else l(!!(_&&A==="granted"))},D=e||a||n||r&&typeof Notification<"u"&&Notification.permission==="granted",$=(_,H,z)=>{m(K=>({...K,[_]:{...K[_],[H]:z}}))},B=_=>{const H="=".repeat((4-_.length%4)%4),z=(_+H).replace(/-/g,"+").replace(/_/g,"/"),K=atob(z),te=new Uint8Array(K.length);for(let Y=0;Y<K.length;Y+=1)te[Y]=K.charCodeAt(Y);return te},k=async(_,H,z)=>{let K=null;const te=new Promise((Y,ae)=>{K=setTimeout(()=>{ae(new Error(z))},H)});try{return await Promise.race([_,te])}finally{K&&clearTimeout(K)}},G=async _=>{if(_.active)return;const H=_.installing||_.waiting;H&&H.state!=="activated"&&await k(new Promise(z=>{const K=()=>{H.state==="activated"&&(H.removeEventListener("statechange",K),z())};H.addEventListener("statechange",K),K()}),15e3,"Service worker activation timed out")},M=async()=>{if(typeof navigator.serviceWorker.register!="function")throw new Error("navigator.serviceWorker.register unavailable");const _=[{label:"no-options",opts:null},{label:"scope-root",opts:{scope:"/"}},{label:"type-classic",opts:{type:"classic"}},{label:"type-classic-scope",opts:{type:"classic",scope:"/"}},{label:"updateViaCache-none",opts:{type:"classic",updateViaCache:"none",scope:"/"}}];let H=null;for(const z of _)try{const K=z.opts?navigator.serviceWorker.register("/sw.js",z.opts):navigator.serviceWorker.register("/sw.js");return await k(K,1e4,`Service worker registration timed out (${z.label})`)}catch(K){H=K}throw H instanceof Error?H:new Error("Service worker registration failed")},L=async()=>{if(!("serviceWorker"in navigator))throw new Error("Service worker not supported");const _=await navigator.serviceWorker.getRegistration();if(_)return _;const H=await M();try{await H.update()}catch{}return await G(H),H},J=_=>{const H=_,z=[`type=${typeof _}`,`toString=${String(_)}`,`name=${String(H?.name??"")}`,`message=${String(H?.message??"")}`];let K="";try{K=JSON.stringify(_)}catch{}return{summary:z.filter(Boolean).join(" | "),json:K,stack:typeof H?.stack=="string"?H.stack:""}},ee=async()=>{const _=fa();if(!_?.notifications){E.error(t("settings.notifications.page.toast.notificationsApiUnavailable"));return}try{await _.notifications.notifyAgentCompletion({title:t("settings.notifications.page.testNotification.title"),body:t("settings.notifications.page.testNotification.body"),tag:"openchamber-test"})?E.success(t("settings.notifications.page.toast.testNotificationSent")):E.error(t("settings.notifications.page.toast.testNotificationFailed"))}catch(H){console.error("Test notification failed:",H),E.error(t("settings.notifications.page.toast.testNotificationFailed"))}},U=async()=>{if(!I){E.error(t("settings.notifications.page.toast.pushUnsupported"));return}const _=fa();if(!_?.push){E.error(t("settings.notifications.page.toast.pushApiUnavailable"));return}T(!0);try{if(typeof Notification<"u"&&Notification.permission==="default"){const de=await Notification.requestPermission();if(R(de),de!=="granted"){E.error(t("settings.notifications.page.toast.permissionDenied.title"),{description:t("settings.notifications.page.toast.permissionDenied.enableInBrowser")});return}}if(typeof Notification<"u"&&Notification.permission!=="granted"){E.error(t("settings.notifications.page.toast.permissionDenied.title"),{description:t("settings.notifications.page.toast.permissionDenied.enableInBrowser")});return}const H=await _.push.getVapidPublicKey();if(!H?.publicKey){E.error(t("settings.notifications.page.toast.pushKeyLoadFailed"));return}const z=await L();await G(z);const K=await z.pushManager.getSubscription();if(!("pushManager"in z)||!z.pushManager)throw new Error("PushManager unavailable (requires installed PWA + iOS 16.4+)");const Y=(K??await k(z.pushManager.subscribe({userVisibleOnly:!0,applicationServerKey:B(H.publicKey)}),15e3,"Push subscription timed out")).toJSON(),ae=Y.keys;if(!Y.endpoint||!ae?.p256dh||!ae.auth)throw new Error("Push subscription missing keys");if(!(await k(_.push.subscribe({endpoint:Y.endpoint,keys:{p256dh:ae.p256dh,auth:ae.auth},origin:typeof window<"u"?window.location.origin:void 0,platform:Kd()}),15e3,"Push subscribe request timed out"))?.ok){E.error(t("settings.notifications.page.toast.enableBackgroundFailed"));return}w(!0),E.success(t("settings.notifications.page.toast.backgroundEnabled"))}catch(H){console.error("[Push] Enable failed:",H);const z=J(H);E.error(t("settings.notifications.page.toast.enableBackgroundFailed"),{description:z.summary})}finally{T(!1)}},le=async()=>{if(!I){w(!1);return}const _=fa();if(!_?.push){E.error(t("settings.notifications.page.toast.pushApiUnavailable"));return}T(!0);try{const z=await(await L()).pushManager.getSubscription();if(!z){w(!1);return}const K=z.endpoint;await z.unsubscribe(),await _.push.unsubscribe({endpoint:K}),w(!1),E.success(t("settings.notifications.page.toast.backgroundDisabled"))}finally{T(!1)}};return s.jsxs(s.Fragment,{children:[s.jsxs(ze,{settingsItem:"notifications.delivery",title:t("settings.notifications.page.delivery.title"),divider:!1,children:[s.jsxs("div",{className:fs,children:[s.jsx(dt,{checked:i&&D,onChange:_=>{S(_)},label:t("settings.notifications.page.delivery.enableLabel"),info:r?t("settings.notifications.page.delivery.browserPermissionHint"):a?t("settings.notifications.page.delivery.vscodeHint"):void 0,ariaLabel:t("settings.notifications.page.delivery.enableAria")}),i&&D&&!n&&s.jsxs(s.Fragment,{children:[s.jsx(dt,{checked:g==="always",onChange:_=>c(_?"always":"hidden-only"),label:t("settings.notifications.page.delivery.focusedLabel"),ariaLabel:t("settings.notifications.page.delivery.focusedAria")}),s.jsx("div",{className:"py-2",children:s.jsx(V,{type:"button",variant:"outline",size:"sm",onClick:()=>{ee()},children:t("settings.notifications.page.delivery.testAction")})})]})]}),r&&s.jsxs("div",{className:"mt-1",children:[A==="denied"&&s.jsx("p",{className:"typography-meta text-[var(--status-error)] mt-1",children:t("settings.notifications.page.delivery.permissionDenied")}),A==="granted"&&!i&&s.jsx("p",{className:"typography-meta text-muted-foreground/70 mt-1",children:t("settings.notifications.page.delivery.permissionGrantedButDisabled")})]})]}),i&&D&&s.jsxs(s.Fragment,{children:[s.jsx(ze,{settingsItem:"notifications.events",title:t("settings.notifications.page.events.title"),children:s.jsxs("div",{className:fs,children:[s.jsx(dt,{checked:b,onChange:d,label:t("settings.notifications.page.events.completionLabel"),ariaLabel:t("settings.notifications.page.events.completionAria")}),s.jsx(dt,{checked:y,onChange:p,label:t("settings.notifications.page.events.subtaskLabel"),ariaLabel:t("settings.notifications.page.events.subtaskAria")}),s.jsx(dt,{checked:P,onChange:f,label:t("settings.notifications.page.events.errorLabel"),ariaLabel:t("settings.notifications.page.events.errorAria")}),s.jsx(dt,{checked:C,onChange:v,label:t("settings.notifications.page.events.questionLabel"),ariaLabel:t("settings.notifications.page.events.questionAria")})]})}),!n&&s.jsx(ze,{title:t("settings.notifications.page.template.title"),description:s.jsxs(s.Fragment,{children:[t("settings.notifications.page.template.variablesLabel")," ",s.jsx("code",{className:"text-[var(--primary-base)]",children:"{project_name}"})," ",s.jsx("code",{className:"text-[var(--primary-base)]",children:"{worktree}"})," ",s.jsx("code",{className:"text-[var(--primary-base)]",children:"{branch}"})," ",s.jsx("code",{className:"text-[var(--primary-base)]",children:"{session_name}"})," ",s.jsx("code",{className:"text-[var(--primary-base)]",children:"{agent_name}"})," ",s.jsx("code",{className:"text-[var(--primary-base)]",children:"{model_name}"})," ",s.jsx("code",{className:"text-[var(--primary-base)]",children:"{last_message}"})]}),children:s.jsx(Sn,{className:"gap-2 md:grid-cols-2 md:gap-3 lg:gap-3",children:["completion","subtask","error","question"].map(_=>s.jsxs("section",{className:"p-2",children:[s.jsx(Zs,{className:"capitalize",children:t(Zh[_])}),s.jsxs("div",{className:"mt-1.5 space-y-2",children:[s.jsxs("div",{children:[s.jsx("label",{className:"typography-micro text-muted-foreground block mb-1",children:t("settings.notifications.page.template.field.title")}),s.jsx(He,{value:N[_].title,onChange:H=>$(_,"title",H.target.value),className:"h-7",placeholder:t(il[_].titleKey)})]}),s.jsxs("div",{children:[s.jsx("label",{className:"typography-micro text-muted-foreground block mb-1",children:t("settings.notifications.page.template.field.message")}),s.jsx(He,{value:N[_].message,onChange:H=>$(_,"message",H.target.value),className:"h-7",placeholder:t(il[_].messageKey)})]})]})]},_))})})]}),r&&s.jsx(ze,{settingsItem:"notifications.push",title:t("settings.notifications.page.push.title"),children:s.jsx(dt,{checked:I?h:!1,disabled:!I||F,onChange:_=>{_?U():le()},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:F?s.jsx("span",{className:"inline-block h-1.5 w-1.5 rounded-full bg-current text-muted-foreground animate-busy-pulse","aria-label":t("settings.notifications.page.push.loadingAria")}):null})})]})},Ls=t=>{if(!t)return;t.pause();const{src:e}=t;e.startsWith("blob:")&&URL.revokeObjectURL(e),t.removeAttribute("src"),t.load()},ef=[{id:"parakeet-tdt-0.6b-v2-int8",labelKey:"settings.voice.page.stt.model.parakeetV2",badgeKey:"settings.voice.page.stt.badge.bestForEnglish",accuracy:5,speed:5,size:"460 MB"},{id:"parakeet-tdt-0.6b-v3-int8",labelKey:"settings.voice.page.stt.model.parakeetV3",badgeKey:"settings.voice.page.stt.badge.bestForMultilingual",accuracy:5,speed:4,size:"465 MB"},{id:"whisper-base-int8",labelKey:"settings.voice.page.stt.model.whisperBase",badgeKey:null,accuracy:3,speed:3,size:"200 MB"},{id:"whisper-tiny-int8",labelKey:"settings.voice.page.stt.model.whisperTiny",badgeKey:null,accuracy:2,speed:4,size:"115 MB"}],rl=t=>{const e=ut.c(8),{value:a,label:n}=t,r=`${n}: ${a}/5`,i=`${a/5*100}%`;let l;e[0]!==i?(l=s.jsx("span",{className:"h-1.5 w-12 flex-shrink-0 overflow-hidden rounded-full bg-[var(--interactive-border)]","aria-hidden":"true",children:s.jsx("span",{className:"block h-full rounded-full bg-[var(--primary-base)]",style:{width:i}})}),e[0]=i,e[1]=l):l=e[1];let g;e[2]!==n?(g=s.jsx("span",{className:"typography-ui-compact text-muted-foreground",children:n}),e[2]=n,e[3]=g):g=e[3];let c;return e[4]!==r||e[5]!==l||e[6]!==g?(c=s.jsxs("span",{className:"flex items-center gap-1.5",title:r,children:[l,g]}),e[4]=r,e[5]=l,e[6]=g,e[7]=c):c=e[7],c},tf=({selectedModelId:t,onSelect:e})=>{const{t:a}=tt(),n=$e.useCallback(d=>a(d),[a]),[r,i]=$e.useState(new Map),[l,g]=$e.useState(null),c=$e.useCallback(async()=>{try{const d=await yt("/api/dictation/status",{query:{provider:"local"}});if(!d.ok)return;const P=await d.json();Array.isArray(P?.models)&&i(new Map(P.models.map(f=>[f.id,f])))}catch{}},[]);$e.useEffect(()=>{c()},[c]);const y=Array.from(r.values()).some(d=>d.downloading);$e.useEffect(()=>{if(!y)return;const d=setInterval(()=>{c()},2e3);return()=>clearInterval(d)},[y,c]);const p=async d=>{g(d);try{await yt(`/api/dictation/models/${encodeURIComponent(d)}/download`,{method:"POST"}),await c()}catch{}finally{g(null)}},b=async d=>{g(d);try{await yt(`/api/dictation/models/${encodeURIComponent(d)}`,{method:"DELETE"}),await c()}catch{}finally{g(null)}};return s.jsx("div",{role:"radiogroup","aria-label":a("settings.voice.page.field.model"),className:"mt-1.5 grid w-full grid-cols-1 gap-3 @xl:grid-cols-2",children:ef.map(d=>{const P=t===d.id,f=r.get(d.id)??null;return s.jsx("div",{className:xe("rounded-lg border border-[var(--interactive-border)] p-3",P&&"border-[var(--primary-base)] bg-[var(--primary-base)]/5"),children:s.jsxs("div",{className:"flex items-start justify-between gap-2",children:[s.jsxs("div",{className:"flex min-w-0 flex-1 cursor-pointer items-start gap-2",role:"button",tabIndex:0,onClick:()=>e(d.id),onKeyDown:C=>{(C.key===" "||C.key==="Enter")&&(C.preventDefault(),e(d.id))},children:[s.jsx("div",{className:"pt-0.5",children:s.jsx(jr,{checked:P,onChange:()=>e(d.id),ariaLabel:n(d.labelKey)})}),s.jsxs("div",{className:"min-w-0 flex-1 space-y-2",children:[s.jsxs("div",{className:"flex flex-wrap items-center gap-2",children:[s.jsx("span",{className:xe("typography-ui-label font-normal",P?"text-foreground":"text-foreground/50"),children:n(d.labelKey)}),d.badgeKey?s.jsx("span",{className:"rounded border border-[var(--status-success-border)] bg-[var(--status-success-background)] px-1 text-[9px] font-medium uppercase leading-[14px] tracking-wide text-[var(--status-success)]",children:n(d.badgeKey)}):null]}),s.jsxs("div",{className:"flex flex-col gap-1.5",children:[s.jsx(rl,{value:d.accuracy,label:a("settings.voice.page.stt.meta.accuracy")}),s.jsx(rl,{value:d.speed,label:a("settings.voice.page.stt.meta.speed")}),s.jsx("span",{className:"typography-ui-compact tabular-nums text-muted-foreground",children:d.size})]}),f?.downloadError?s.jsx("p",{className:"typography-meta text-[var(--status-error)]",children:f.downloadError}):null]})]}),s.jsx("div",{className:"flex shrink-0 items-center gap-1",children:f?.installed?s.jsxs(s.Fragment,{children:[s.jsx(V,{variant:"ghost",size:"xs",className:"h-6 w-6 p-0 text-muted-foreground hover:text-[var(--status-error)]",disabled:l===d.id,onClick:()=>{b(d.id)},title:a("settings.voice.page.stt.modelDelete"),"aria-label":a("settings.voice.page.stt.modelDelete"),children:s.jsx(O,{name:"delete-bin",className:"h-4 w-4"})}),s.jsx(O,{name:"checkbox-circle",className:"h-4 w-4 flex-shrink-0 text-[var(--status-success)]","aria-label":a("settings.voice.page.stt.modelInstalled")})]}):f?.downloading?s.jsxs("span",{className:"flex items-center gap-1.5",children:[s.jsx(O,{name:"loader-4",className:"h-3.5 w-3.5 animate-spin text-muted-foreground"}),s.jsx("span",{className:"typography-ui-compact tabular-nums text-muted-foreground",children:typeof f.downloadProgress=="number"?`${f.downloadProgress}%`:""})]}):s.jsx(V,{variant:"ghost",size:"xs",className:"h-6 w-6 p-0",disabled:l===d.id,onClick:()=>{p(d.id)},title:a("settings.voice.page.stt.modelDownload"),"aria-label":a("settings.voice.page.stt.modelDownload"),children:s.jsx(O,{name:"download",className:"h-4 w-4"})})})]})},d.id)})})},sf=[{id:0,label:"Alloy (af)"},{id:1,label:"Bella (af)"},{id:2,label:"Nicole (af)"},{id:3,label:"Sarah (af)"},{id:4,label:"Sky (af)"},{id:5,label:"Adam (am)"},{id:6,label:"Michael (am)"},{id:7,label:"Emma (bf)"},{id:8,label:"Isabella (bf)"},{id:9,label:"George (bm)"},{id:10,label:"Lewis (bm)"}],vr="kokoro-en-v0_19",nf="kokoro-multi-lang-v1_1",af=[{id:0,label:"Maple (af)"},{id:1,label:"Sol (af)"},{id:2,label:"Vale (bf)"},{id:3,label:"Xiaoxiao (zf)"},{id:58,label:"Yunxi (zm)"}],Ma=(t,e)=>`${t}:${e}`,rf=()=>{const[t,e]=$e.useState([]),[a,n]=$e.useState(null),r=$e.useCallback(async()=>{try{const g=await yt("/api/dictation/status",{query:{provider:"local"}});if(!g.ok)return;const c=await g.json();Array.isArray(c?.ttsModels)&&e(c.ttsModels)}catch{}},[]);$e.useEffect(()=>{r()},[r]);const i=t.some(g=>g.downloading);$e.useEffect(()=>{if(!i)return;const g=setInterval(()=>{r()},2e3);return()=>clearInterval(g)},[i,r]);const l=$e.useCallback(async(g,c)=>{n(g);try{const y=c==="POST"?`/api/dictation/models/${g}/download`:`/api/dictation/models/${g}`;await yt(y,{method:c}),await r()}catch{}finally{n(null)}},[r]);return{models:t,requestingId:a,request:l,refresh:r}},of=t=>{const e=sf.map(a=>({modelId:vr,speakerId:a.id,label:a.label}));for(const a of t)if(!(a.id===vr||!a.installed)){if(a.id===nf){for(const n of af)e.push({modelId:a.id,speakerId:n.id,label:`${n.label} · Kokoro zh/en`});continue}e.push({modelId:a.id,speakerId:0,label:a.description??a.id})}return e},lf=t=>{const e=ut.c(14),{models:a,requestingId:n,request:r}=t,{t:i}=tt();let l,g,c;if(e[0]!==a||e[1]!==r||e[2]!==n||e[3]!==i){c=Symbol.for("react.early_return_sentinel");e:{const p=a.filter(uf);if(p.length===0){c=null;break e}l="flex flex-col";let b;e[7]!==r||e[8]!==n||e[9]!==i?(b=d=>s.jsxs("div",{className:"flex items-center gap-2 py-1.5",children:[s.jsx("span",{className:"typography-ui-label text-foreground",children:d.description??d.id}),d.installed?s.jsxs(s.Fragment,{children:[s.jsx(O,{name:"checkbox-circle",className:"h-4 w-4 text-[var(--status-success)]","aria-label":i("settings.voice.page.stt.modelInstalled")}),s.jsx(V,{variant:"ghost",size:"xs",className:"h-6 w-6 p-0 text-muted-foreground hover:text-[var(--status-error)]",disabled:n!==null,onClick:()=>{r(d.id,"DELETE")},title:i("settings.voice.page.stt.modelDelete"),"aria-label":i("settings.voice.page.stt.modelDelete"),children:s.jsx(O,{name:"delete-bin",className:"h-4 w-4"})})]}):d.downloading?s.jsxs("span",{className:"flex items-center gap-1.5",children:[s.jsx(O,{name:"loader-4",className:"h-3.5 w-3.5 animate-spin text-muted-foreground"}),s.jsx("span",{className:"typography-ui-compact tabular-nums text-muted-foreground",children:typeof d.downloadProgress=="number"?`${d.downloadProgress}%`:""})]}):s.jsx(V,{variant:"ghost",size:"xs",className:"h-6 w-6 p-0",disabled:n!==null,onClick:()=>{r(d.id,"POST")},title:i("settings.voice.page.stt.modelDownload"),"aria-label":i("settings.voice.page.stt.modelDownload"),children:s.jsx(O,{name:"download",className:"h-4 w-4"})}),d.downloadError?s.jsx("span",{className:"typography-meta text-[var(--status-error)]",children:d.downloadError}):null]},d.id),e[7]=r,e[8]=n,e[9]=i,e[10]=b):b=e[10],g=p.map(b)}e[0]=a,e[1]=r,e[2]=n,e[3]=i,e[4]=l,e[5]=g,e[6]=c}else l=e[4],g=e[5],c=e[6];if(c!==Symbol.for("react.early_return_sentinel"))return c;let y;return e[11]!==l||e[12]!==g?(y=s.jsx("div",{className:l,children:g}),e[11]=l,e[12]=g,e[13]=y):y=e[13],y},cf=[{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"}],df=()=>{const{t}=tt(),{isMobile:e}=wa(),a=Ye(W=>W.voiceProvider),n=Ye(W=>W.setVoiceProvider),r=Ye(W=>W.speechRate),i=Ye(W=>W.setSpeechRate),l=Ye(W=>W.speechPitch),g=Ye(W=>W.setSpeechPitch),c=Ye(W=>W.speechVolume),y=Ye(W=>W.setSpeechVolume),p=Ye(W=>W.sayVoice),b=Ye(W=>W.setSayVoice),d=Ye(W=>W.localTtsVoiceId),P=Ye(W=>W.localTtsModelId),f=Ye(W=>W.setLocalTtsModelId),C=rf(),v=$e.useMemo(()=>of(C.models),[C.models]),N=Ye(W=>W.ttsFollowTextLanguage),m=Ye(W=>W.setTtsFollowTextLanguage),A=Ye(W=>W.setLocalTtsVoiceId),{speak:R,stop:I,isPlaying:j,error:h}=id(),w=$e.useCallback(()=>{if(j){I();return}const W=v.find(We=>We.modelId===P&&We.speakerId===d)?.label??String(d);R(t("settings.voice.page.preview.voiceLine",{voiceName:W}),{model:P,speakerId:d,speed:Ye.getState().speechRate})},[j,P,d,v,R,I,t]),F=Ye(W=>W.browserVoice),T=Ye(W=>W.setBrowserVoice),S=Ye(W=>W.openaiVoice),D=Ye(W=>W.setOpenaiVoice),$=Ye(W=>W.openaiApiKey),B=Ye(W=>W.setOpenaiApiKey),k=Ye(W=>W.openaiCompatibleUrl),G=Ye(W=>W.setOpenaiCompatibleUrl),M=Ye(W=>W.openaiCompatibleApiKey),L=Ye(W=>W.setOpenaiCompatibleApiKey),J=Ye(W=>W.openaiCompatibleVoice),ee=Ye(W=>W.setOpenaiCompatibleVoice),U=Ye(W=>W.openaiCompatibleTtsModel),le=Ye(W=>W.setOpenaiCompatibleTtsModel),_=Ye(W=>W.showMessageTTSButtons),H=Ye(W=>W.ttsInputMode),z=Ye(W=>W.setTtsInputMode),K=Ye(W=>W.sttProvider),te=Ye(W=>W.setSttProvider),Y=Ye(W=>W.sttServerUrl),ae=Ye(W=>W.setSttServerUrl),ge=Ye(W=>W.sttApiKey),de=Ye(W=>W.setSttApiKey),he=Ye(W=>W.sttModel),se=Ye(W=>W.setSttModel),re=Ye(W=>W.sttLocalModel),ue=Ye(W=>W.setSttLocalModel),Ce=Ye(W=>W.sttLanguage),Se=Ye(W=>W.setSttLanguage),ye=Ye(W=>W.setShowMessageTTSButtons),fe=Ye(W=>W.dictationEnabled),_e=Ye(W=>W.setDictationEnabled),[Ue,Ne]=$e.useState(!1),[Oe,Ve]=$e.useState([]),[Ge,ve]=$e.useState(!1),[Z,ne]=$e.useState(null),[be,we]=$e.useState(!1),[Re,Fe]=$e.useState(!1),[Ke,Ee]=$e.useState(null),[je,Ze]=$e.useState(!1),[me,Ie]=$e.useState(null),[Le,Xe]=$e.useState([]),[q,ke]=$e.useState(!1);$e.useEffect(()=>((async()=>{const We=await Wi.waitForVoices();Xe(We)})(),"speechSynthesis"in window&&(window.speechSynthesis.onvoiceschanged=()=>{Xe(window.speechSynthesis.getVoices())}),()=>{"speechSynthesis"in window&&(window.speechSynthesis.onvoiceschanged=null)}),[]);const Pe=$e.useMemo(()=>Le.filter(W=>W.lang).sort((W,We)=>{const nt=W.lang.startsWith("en"),lt=We.lang.startsWith("en");if(nt&&!lt)return-1;if(!nt&<)return 1;const ht=W.lang.localeCompare(We.lang);return ht!==0?ht:W.name.localeCompare(We.name)}),[Le]),Je=$e.useCallback(()=>{if(q){Wi.cancelSpeech(),ke(!1);return}const W=Le.find(ht=>ht.name===F),We=W?.name??t("settings.voice.page.preview.browserVoiceFallback"),nt=t("settings.voice.page.preview.voiceLine",{voiceName:We});ke(!0);const lt=new SpeechSynthesisUtterance(nt);lt.rate=r,lt.pitch=l,lt.volume=c,W&&(lt.voice=W,lt.lang=W.lang),lt.onend=()=>ke(!1),lt.onerror=()=>ke(!1),window.speechSynthesis.cancel(),window.speechSynthesis.speak(lt)},[F,Le,r,l,c,q,t]);$e.useEffect(()=>()=>{q&&Wi.cancelSpeech()},[q]),$e.useEffect(()=>{if(!_||a!=="openai"&&a!=="openai-compatible"){we($.trim().length>0);return}(async()=>{try{const lt=(await(await yt("/api/tts/status")).json()).available,ht=$.trim().length>0;we(lt||ht)}catch{we($.trim().length>0)}})()},[$,_,a]),$e.useEffect(()=>{if(!_){Ne(!1),Ve([]);return}yt("/api/tts/say/status").then(W=>W.json()).then(W=>{if(Ne(W.available),W.voices){const We=W.voices.filter((nt,lt,ht)=>ht.findIndex(Lt=>Lt.name===nt.name)===lt).sort((nt,lt)=>nt.name.localeCompare(lt.name));Ve(We)}}).catch(()=>{Ne(!1)})},[_]);const ot=$e.useCallback(async()=>{if(Z){Ls(Z),ne(null),ve(!1);return}ve(!0);let W=null;try{const We=await yt("/api/tts/say/speak",{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify({text:t("settings.voice.page.preview.voiceLine",{voiceName:p}),voice:p,rate:Math.round(100+(r-.5)*200)})});if(!We.ok)throw new Error("Preview failed");const nt=await We.blob(),lt=URL.createObjectURL(nt);W=new Audio(lt),W.onended=()=>{Ls(W),ne(null),ve(!1)},W.onerror=()=>{Ls(W),ne(null),ve(!1)},ne(W),await W.play()}catch{Ls(W),ne(null),ve(!1)}},[p,r,Z,t]);$e.useEffect(()=>()=>{Ls(Z)},[Z]);const st=$e.useCallback(async()=>{if(Ke){Ls(Ke),Ee(null),Fe(!1);return}Fe(!0);let W=null;try{const We=await yt("/api/tts/speak",{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify({text:t("settings.voice.page.preview.voiceLine",{voiceName:S}),voice:S,speed:r,apiKey:$||void 0})});if(!We.ok){const ht=await We.json().catch(()=>({error:"Unknown error"}));throw new Error(ht.error||`HTTP ${We.status}`)}const nt=await We.blob(),lt=URL.createObjectURL(nt);W=new Audio(lt),W.onended=()=>{Ls(W),Ee(null),Fe(!1)},W.onerror=()=>{Ls(W),Ee(null),Fe(!1)},Ee(W),await W.play()}catch{Ls(W),Ee(null),Fe(!1)}},[S,r,Ke,$,t]);$e.useEffect(()=>()=>{Ls(Ke)},[Ke]);const pt=$e.useCallback(async()=>{if(me){Ls(me),Ie(null),Ze(!1);return}if(!k.trim())return;Ze(!0);let W=null;try{const We=await yt("/api/tts/speak",{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify({text:t("settings.voice.page.preview.customServerLine"),voice:J,model:U||void 0,speed:r,baseURL:k,apiKey:M||void 0})});if(!We.ok){const ht=await We.json().catch(()=>({error:"Unknown error"}));throw new Error(ht.error||`HTTP ${We.status}`)}const nt=await We.blob(),lt=URL.createObjectURL(nt);W=new Audio(lt),W.onended=()=>{Ls(W),Ie(null),Ze(!1)},W.onerror=()=>{Ls(W),Ie(null),Ze(!1)},Ie(W),await W.play()}catch{Ls(W),Ie(null),Ze(!1)}},[k,J,U,M,r,me,t]);$e.useEffect(()=>()=>{Ls(me)},[me]);const vt="flex-1 min-w-0 h-1.5 bg-[var(--interactive-border)] rounded-full appearance-none cursor-pointer [&::-webkit-slider-thumb]:appearance-none [&::-webkit-slider-thumb]:w-4 [&::-webkit-slider-thumb]:h-4 [&::-webkit-slider-thumb]:rounded-full [&::-webkit-slider-thumb]:bg-[var(--primary-base)] [&::-moz-range-thumb]:w-4 [&::-moz-range-thumb]:h-4 [&::-moz-range-thumb]:rounded-full [&::-moz-range-thumb]:bg-[var(--primary-base)] [&::-moz-range-thumb]:border-0 disabled:opacity-50";return s.jsxs(s.Fragment,{children:[s.jsxs(ze,{settingsItem:"voice.playback",title:t("settings.voice.page.section.playbackAndSummary"),divider:!1,contentClassName:"space-y-4",children:[s.jsx(dt,{checked:_,onChange:ye,label:t("settings.voice.page.field.messageReadAloudButton"),ariaLabel:t("settings.voice.page.field.messageReadAloudButtonAria")}),_&&s.jsxs(s.Fragment,{children:[s.jsx(Ss,{title:t("settings.voice.page.field.provider"),info:s.jsxs("ul",{className:"space-y-1",children:[s.jsxs("li",{children:[s.jsx("strong",{children:t("settings.voice.page.provider.browser")})," ",t("settings.voice.page.tooltip.browser")]}),s.jsxs("li",{children:[s.jsx("strong",{children:t("settings.voice.page.provider.local")})," ",t("settings.voice.page.tooltip.localTts")]}),s.jsxs("li",{children:[s.jsx("strong",{children:t("settings.voice.page.provider.openai")})," ",t("settings.voice.page.tooltip.openai")]}),s.jsxs("li",{children:[s.jsx("strong",{children:t("settings.voice.page.provider.custom")})," ",t("settings.voice.page.tooltip.custom")]}),s.jsxs("li",{children:[s.jsx("strong",{children:t("settings.voice.page.provider.say")})," ",t("settings.voice.page.tooltip.say")]})]}),children:s.jsx(Ys,{value:a,onChange:n,"aria-label":t("settings.voice.page.field.provider"),className:"w-full gap-1.5 sm:gap-2",options:[{value:"browser",label:t("settings.voice.page.provider.browser")},{value:"local",label:t("settings.voice.page.provider.local")},{value:"openai",label:t("settings.voice.page.provider.openai")},{value:"openai-compatible",label:t("settings.voice.page.provider.custom")},...Ue?[{value:"say",label:s.jsxs(s.Fragment,{children:[s.jsx(O,{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:xe(Tt,!be&&"text-[var(--status-error)]"),children:t("settings.voice.page.field.apiKey")}),s.jsx("span",{className:xe(zn,!be&&"text-[var(--status-error)]/80"),children:t(be&&!$?"settings.voice.page.field.apiKeyHintUsingConfig":be?"settings.voice.page.field.apiKeyHintProvide":"settings.voice.page.field.apiKeyHintRequired")}),s.jsxs("div",{className:xe("relative",zs),children:[s.jsx("input",{type:"password",value:$,onChange:W=>B(W.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"}),$&&s.jsx("button",{type:"button",onClick:()=>B(""),className:"absolute right-2 top-1/2 -translate-y-1/2 text-muted-foreground hover:text-foreground",children:s.jsx(O,{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:xe(Tt,!k.trim()&&"text-[var(--status-error)]"),children:t("settings.voice.page.field.serverUrl")}),s.jsx(Jt,{children:t("settings.voice.page.field.serverUrlHint")})]}),s.jsxs("div",{className:xe("relative",zs),children:[s.jsx("input",{type:"text",value:k,onChange:W=>G(W.target.value),placeholder:"http://localhost:8880/v1",className:"w-full h-7 rounded-lg border border-input bg-transparent px-2 typography-ui-label text-foreground placeholder:text-muted-foreground focus:outline-none focus:ring-1 focus:ring-primary/50 focus:border-primary/70"}),k&&s.jsx("button",{type:"button",onClick:()=>G(""),className:"absolute right-2 top-1/2 -translate-y-1/2 text-muted-foreground hover:text-foreground",children:s.jsx(O,{name:"close",className:"w-3.5 h-3.5"})})]})]}),s.jsxs("div",{className:"space-y-1.5",children:[s.jsx("span",{className:Tt,children:"API Key"}),s.jsx("span",{className:zn,children:"Optional"}),s.jsxs("div",{className:xe("relative",zs),children:[s.jsx("input",{type:"password",value:M,onChange:W=>L(W.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:()=>L(""),className:"absolute right-2 top-1/2 -translate-y-1/2 text-muted-foreground hover:text-foreground",children:s.jsx(O,{name:"close",className:"w-3.5 h-3.5"})})]})]}),s.jsxs("div",{className:"space-y-1.5",children:[s.jsx("span",{className:Tt,children:t("settings.voice.page.field.model")}),s.jsx("div",{className:xe("relative",zs),children:s.jsx("input",{type:"text",value:U,onChange:W=>le(W.target.value),placeholder:"speaches-ai/Kokoro-82M-v1.0-ONNX",className:"w-full h-7 rounded-lg border border-input bg-transparent px-2 typography-ui-label text-foreground placeholder:text-muted-foreground focus:outline-none focus:ring-1 focus:ring-primary/50 focus:border-primary/70"})})]}),s.jsxs("div",{className:"space-y-1.5",children:[s.jsxs("span",{className:"flex items-center gap-1.5",children:[s.jsx("span",{className:Tt,children:t("settings.voice.page.field.voice")}),s.jsx(Jt,{children:t("settings.voice.page.field.voiceIdentifierHint")})]}),s.jsxs("div",{className:xe("flex items-center gap-2",zs),children:[s.jsx("div",{className:"relative min-w-0 flex-1",children:s.jsx("input",{type:"text",value:J,onChange:W=>ee(W.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(V,{size:"xs",variant:"ghost",onClick:pt,title:t("settings.voice.page.actions.preview"),disabled:!k.trim(),children:je?s.jsx(O,{name:"stop",className:"w-3.5 h-3.5"}):s.jsx(O,{name:"play",className:"w-3.5 h-3.5"})})]})]})]}),a==="local"&&s.jsx(lf,{...C}),(a==="local"||a==="say")&&s.jsx(dt,{checked:N,onChange:m,label:t("settings.voice.page.field.followTextLanguage"),ariaLabel:t("settings.voice.page.field.followTextLanguageAria"),info:t("settings.voice.page.field.followTextLanguageInfo")}),s.jsxs(Rt,{label:t("settings.voice.page.field.voice"),children:[a==="local"&&s.jsxs(s.Fragment,{children:[s.jsxs(St,{value:Ma(P,d),onValueChange:W=>{const We=v.find(nt=>Ma(nt.modelId,nt.speakerId)===W);We&&(f(We.modelId),A(We.speakerId))},children:[s.jsx(Ct,{size:Ft,className:rn,children:s.jsx(Mt,{placeholder:t("settings.voice.page.field.selectVoicePlaceholder"),children:W=>v.find(We=>Ma(We.modelId,We.speakerId)===W)?.label??W})}),s.jsx(It,{children:v.map(W=>s.jsx(at,{value:Ma(W.modelId,W.speakerId),children:W.label},Ma(W.modelId,W.speakerId)))})]}),s.jsx(V,{size:"xs",variant:"ghost",onClick:w,title:t("settings.voice.page.actions.preview"),children:j?s.jsx(O,{name:"stop",className:"w-3.5 h-3.5"}):s.jsx(O,{name:"play",className:"w-3.5 h-3.5"})}),h?s.jsx("span",{className:"typography-meta text-[var(--status-error)]",children:h}):null]}),a==="openai"&&be&&s.jsxs(s.Fragment,{children:[s.jsxs(St,{value:S,onValueChange:D,children:[s.jsx(Ct,{size:Ft,className:rn,children:s.jsx(Mt,{placeholder:t("settings.voice.page.field.selectVoicePlaceholder")})}),s.jsx(It,{children:cf.map(W=>s.jsx(at,{value:W.value,children:W.label},W.value))})]}),s.jsx(V,{size:"xs",variant:"ghost",onClick:st,title:t("settings.voice.page.actions.preview"),children:Re?s.jsx(O,{name:"stop",className:"w-3.5 h-3.5"}):s.jsx(O,{name:"play",className:"w-3.5 h-3.5"})})]}),a==="openai-compatible"&&s.jsx("span",{className:zn,children:t("settings.voice.page.field.configuredAbove")}),a==="say"&&Ue&&Oe.length>0&&s.jsxs(s.Fragment,{children:[s.jsxs(St,{value:p,onValueChange:b,children:[s.jsx(Ct,{size:Ft,className:rn,children:s.jsx(Mt,{placeholder:t("settings.voice.page.field.selectVoicePlaceholder")})}),s.jsx(It,{children:Oe.map(W=>s.jsx(at,{value:W.name,children:W.name},W.name))})]}),s.jsx(V,{size:"xs",variant:"ghost",onClick:ot,title:t("settings.voice.page.actions.preview"),children:Ge?s.jsx(O,{name:"stop",className:"w-3.5 h-3.5"}):s.jsx(O,{name:"play",className:"w-3.5 h-3.5"})})]}),a==="browser"&&Pe.length>0&&s.jsxs(s.Fragment,{children:[s.jsxs(St,{value:F||"$auto",onValueChange:W=>T(W==="$auto"?"":W),children:[s.jsx(Ct,{size:Ft,className:rn,children:s.jsx(Mt,{placeholder:t("settings.voice.page.field.auto")})}),s.jsxs(It,{children:[s.jsx(at,{value:"$auto",children:t("settings.voice.page.field.auto")}),Pe.map(W=>s.jsxs(at,{value:W.name,children:[W.name," (",W.lang,")"]},W.name))]})]}),s.jsx(V,{size:"xs",variant:"ghost",onClick:Je,title:t("settings.voice.page.actions.preview"),children:q?s.jsx(O,{name:"stop",className:"w-3.5 h-3.5"}):s.jsx(O,{name:"play",className:"w-3.5 h-3.5"})})]})]}),s.jsxs(Rt,{label:t("settings.voice.page.field.speechRate"),children:[!e&&s.jsx("input",{type:"range",min:.5,max:2,step:.1,value:r,onChange:W=>i(Number(W.target.value)),className:vt}),s.jsx(xs,{value:r,onValueChange:i,min:.5,max:2,step:.1,className:xe(Ps,"tabular-nums")})]}),s.jsxs(Rt,{label:t("settings.voice.page.field.speechPitch"),children:[!e&&s.jsx("input",{type:"range",min:.5,max:2,step:.1,value:l,onChange:W=>g(Number(W.target.value)),className:vt}),s.jsx(xs,{value:l,onValueChange:g,min:.5,max:2,step:.1,className:xe(Ps,"tabular-nums")})]}),s.jsxs(Rt,{label:t("settings.voice.page.field.speechVolume"),children:[!e&&s.jsx("input",{type:"range",min:0,max:1,step:.1,value:c,onChange:W=>y(Number(W.target.value)),className:vt}),e?s.jsx(xs,{value:Math.round(c*100),onValueChange:W=>y(W/100),min:0,max:100,step:10,className:xe(Ps,"tabular-nums")}):s.jsxs("span",{className:"typography-ui-label text-foreground tabular-nums min-w-[3rem] text-right",children:[Math.round(c*100),"%"]})]}),s.jsx(Ss,{title:t("settings.voice.page.field.ttsInputMode"),children:s.jsx(Ys,{value:H,onChange:z,"aria-label":t("settings.voice.page.field.ttsInputMode"),className:"w-full gap-1.5 sm:gap-2",options:[{value:"sanitized",label:t("settings.voice.page.field.ttsInputModeSanitized")},{value:"raw",label:t("settings.voice.page.field.ttsInputModeRaw")},{value:"summarized",label:t("settings.voice.page.field.ttsInputModeSummarized")}]})})]})]}),s.jsxs(ze,{settingsItem:"voice.speech-recognition",title:t("settings.voice.page.section.speechRecognition"),contentClassName:"space-y-4",children:[s.jsx(dt,{checked:fe,onChange:_e,label:t("settings.voice.page.field.enableVoiceInput"),ariaLabel:t("settings.voice.page.field.enableVoiceInputAria")}),fe&&s.jsxs(s.Fragment,{children:[s.jsx(Ss,{title:t("settings.voice.page.field.provider"),info:s.jsxs("ul",{className:"space-y-1",children:[s.jsxs("li",{children:[s.jsx("strong",{children:t("settings.voice.page.provider.local")})," ",t("settings.voice.page.tooltip.sttLocal")]}),s.jsxs("li",{children:[s.jsx("strong",{children:t("settings.voice.page.provider.server")})," ",t("settings.voice.page.tooltip.sttServer")]})]}),children:s.jsx(Ys,{value:K,onChange:te,"aria-label":t("settings.voice.page.field.provider"),className:"w-full gap-1.5 sm:gap-2",options:[{value:"local",label:t("settings.voice.page.provider.local")},{value:"openai-compatible",label:t("settings.voice.page.provider.server")}]})}),K==="local"&&s.jsxs("div",{className:"space-y-1.5",children:[s.jsx("span",{className:Tt,children:t("settings.voice.page.field.model")}),s.jsx(tf,{selectedModelId:re,onSelect:ue})]}),K==="openai-compatible"&&s.jsxs("div",{className:"space-y-3",children:[s.jsxs("div",{className:"space-y-1.5",children:[s.jsxs("span",{className:"flex items-center gap-1.5",children:[s.jsx("span",{className:xe(Tt,!Y.trim()&&"text-[var(--status-error)]"),children:t("settings.voice.page.field.serverUrl")}),s.jsx(Jt,{children:t("settings.voice.page.field.sttServerUrlHint")})]}),s.jsxs("div",{className:xe("relative",zs),children:[s.jsx("input",{type:"text",value:Y,onChange:W=>ae(W.target.value),placeholder:"http://localhost:8001/v1",className:"w-full h-7 rounded-lg border border-input bg-transparent px-2 typography-ui-label text-foreground placeholder:text-muted-foreground focus:outline-none focus:ring-1 focus:ring-primary/50 focus:border-primary/70"}),Y&&s.jsx("button",{type:"button",onClick:()=>ae(""),className:"absolute right-2 top-1/2 -translate-y-1/2 text-muted-foreground hover:text-foreground",children:s.jsx(O,{name:"close",className:"w-3.5 h-3.5"})})]})]}),s.jsxs("div",{className:"space-y-1.5",children:[s.jsx("span",{className:Tt,children:"API Key"}),s.jsx("span",{className:zn,children:"Optional"}),s.jsxs("div",{className:xe("relative",zs),children:[s.jsx("input",{type:"password",value:ge,onChange:W=>de(W.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"}),ge&&s.jsx("button",{type:"button",onClick:()=>de(""),className:"absolute right-2 top-1/2 -translate-y-1/2 text-muted-foreground hover:text-foreground",children:s.jsx(O,{name:"close",className:"w-3.5 h-3.5"})})]})]}),s.jsxs("div",{className:"space-y-1.5",children:[s.jsx("span",{className:Tt,children:t("settings.voice.page.field.model")}),s.jsx("div",{className:xe("relative",zs),children:s.jsx("input",{type:"text",value:he,onChange:W=>se(W.target.value),placeholder:"deepdml/faster-whisper-large-v3-turbo-ct2",className:"w-full h-7 rounded-lg border border-input bg-transparent px-2 typography-ui-label text-foreground placeholder:text-muted-foreground focus:outline-none focus:ring-1 focus:ring-primary/50 focus:border-primary/70"})})]}),s.jsxs("div",{className:"space-y-1.5",children:[s.jsxs("span",{className:"flex items-center gap-1.5",children:[s.jsx("span",{className:Tt,children:t("settings.voice.page.field.language")}),s.jsx(Jt,{children:t("settings.voice.page.field.sttLanguageHint")})]}),s.jsx("div",{className:"relative max-w-[8rem]",children:s.jsx("input",{type:"text",value:Ce,onChange:W=>Se(W.target.value),placeholder:"auto",className:"w-full h-7 rounded-lg border border-input bg-transparent px-2 typography-ui-label text-foreground placeholder:text-muted-foreground focus:outline-none focus:ring-1 focus:ring-primary/50 focus:border-primary/70"})})]})]})]})]})]})};function uf(t){return t.id===vr||t.installed||t.downloading}const hi=[{value:"1800000",label:"30m",ms:1800*1e3},{value:"180000",label:"3m",ms:180*1e3},{value:"7200000",label:"2h",ms:7200*1e3},{value:"28800000",label:"8h",ms:480*60*1e3},{value:"86400000",label:"24h",ms:1440*60*1e3}],fi=[{value:"3600000",label:"1h",ms:3600*1e3},{value:"28800000",label:"8h",ms:480*60*1e3},{value:"43200000",label:"12h",ms:720*60*1e3},{value:"86400000",label:"24h",ms:1440*60*1e3},{value:"604800000",label:"1w",ms:10080*60*1e3},{value:"2592000000",label:"30d",ms:720*60*60*1e3}],pf="https://developers.cloudflare.com/cloudflare-one/networks/connectors/cloudflare-tunnel/get-started/create-remote-tunnel/",mf="https://developers.cloudflare.com/cloudflare-one/networks/connectors/cloudflare-tunnel/do-more-with-tunnels/local-management/configuration-file/",ir=[{value:"quick",labelKey:"settings.aiworker.tunnel.option.mode.quick.label",tooltipKey:"settings.aiworker.tunnel.option.mode.quick.tooltip"},{value:"managed-remote",labelKey:"settings.aiworker.tunnel.option.mode.managedRemote.label",tooltipKey:"settings.aiworker.tunnel.option.mode.managedRemote.tooltip"},{value:"managed-local",labelKey:"settings.aiworker.tunnel.option.mode.managedLocal.label",tooltipKey:"settings.aiworker.tunnel.option.mode.managedLocal.tooltip"}],gf=[".yml",".yaml",".json"],hf="settings.aiworker.tunnel.error.invalidConfigExtension",Ra=t=>{const e=t.trim().toLowerCase();return gf.some(a=>e.endsWith(a))},ff=t=>t==="ngrok"?"ngrok":"cloudflared",ac=()=>{if(typeof window<"u"&&typeof window.__AIWORKER_PLATFORM__=="string"){const e=window.__AIWORKER_PLATFORM__;if(e==="win32"||e==="darwin"||e==="linux")return e}const t=typeof navigator<"u"?`${navigator.platform||""} ${navigator.userAgent||""}`.toLowerCase():"";return t.includes("win")?"win32":t.includes("mac")?"darwin":"linux"},xf=(t,e=ac())=>t==="ngrok"?e==="win32"?"winget install ngrok -s msstore":e==="darwin"?"brew install ngrok":"https://ngrok.com/download":e==="win32"?"winget install --id Cloudflare.cloudflared":e==="darwin"?"brew install cloudflared":"https://developers.cloudflare.com/cloudflare-one/networks/connectors/cloudflare-tunnel/downloads/",rr=(t,e)=>{const a=typeof e?.provider=="string"&&e.provider.trim().length>0?e.provider.trim().toLowerCase():t,n=typeof e?.dependency=="string"&&e.dependency.trim().length>0?e.dependency.trim():ff(a),r=typeof e?.platform=="string"&&e.platform.trim().length>0?e.platform.trim():ac(),i=typeof e?.installCommand=="string"&&e.installCommand.trim().length>0?e.installCommand.trim():xf(a,r);return{provider:a,dependency:n,installCommand:i}},ic=t=>t==="cloudflare"?"Cloudflare":t==="ngrok"?"Ngrok":t,ol=t=>{const e=ut.c(11),{provider:a}=t;let n;e[0]!==a?(n=ic(a),e[0]=a,e[1]=n):n=e[1];const r=n,g=a==="cloudflare"||a==="ngrok"?"text-[var(--status-warning)]":"text-muted-foreground";let c;e[2]!==g?(c=xe("size-4 shrink-0",g),e[2]=g,e[3]=c):c=e[3];let y;e[4]!==c?(y=s.jsx(O,{name:"cloud",className:c}),e[4]=c,e[5]=y):y=e[5];let p;e[6]!==r?(p=s.jsx("span",{children:r}),e[6]=r,e[7]=p):p=e[7];let b;return e[8]!==y||e[9]!==p?(b=s.jsxs("span",{className:"flex items-center gap-2",children:[y,p]}),e[8]=y,e[9]=p,e[10]=b):b=e[10],b},Nn=t=>t==="quick"?"quick":t==="managed-remote"?"managed-remote":t==="managed-local"?"managed-local":"quick",yr=(t,e,a)=>t.find(r=>r.ms===e)?.value||a,ll=(t,e,a)=>{const n=yr(t,e,a);return t.find(r=>r.value===n)?.label||n},cl=t=>{const e=Math.max(0,t),a=Math.floor(e/1e3),n=Math.floor(a/3600),r=Math.floor(a%3600/60),i=a%60;return n>0?`${n}h ${r}m`:r>0?`${r}m ${i}s`:`${i}s`},vf=(t,e)=>Al(t,e,{hour:"2-digit",precision:"second"}),ji=t=>{const e=t.trim();if(!e)return"";try{return(e.includes("://")?new URL(e):new URL(`https://${e}`)).hostname.trim().toLowerCase()}catch{return e.toLowerCase()}},yf=t=>{if(!Array.isArray(t))return[];const e=new Set,a=new Set,n=[];for(const r of t){if(!r||typeof r!="object")continue;const i=r,l=typeof i.id=="string"?i.id.trim():"",g=typeof i.name=="string"?i.name.trim():"",c=ji(typeof i.hostname=="string"?i.hostname:"");!l||!g||!c||e.has(l)||a.has(c)||(e.add(l),a.add(c),n.push({id:l,name:g,hostname:c}))}return n},bf=()=>typeof crypto<"u"&&typeof crypto.randomUUID=="function"?crypto.randomUUID():`${Date.now()}-${Math.random().toString(36).slice(2,10)}`,wf=()=>{const{t}=tt(),e=ie(Q=>Q.timeFormatPreference),a=o.useCallback(Q=>t(Q),[t]),[n,r]=o.useState("checking"),[i,l]=o.useState(null),[g,c]=o.useState(null),[y,p]=o.useState(null),[b,d]=o.useState(null),[P,f]=o.useState(null),[C,v]=o.useState(!1),[N,m]=o.useState(!1),[A,R]=o.useState(!1),[I,j]=o.useState("cloudflare"),[h,w]=o.useState(()=>rr("cloudflare")),[F,T]=o.useState([]),[S,D]=o.useState("quick"),[$,B]=o.useState(null),[k,G]=o.useState([]),[M,L]=o.useState({}),[J,ee]=o.useState(""),[U,le]=o.useState({}),[_,H]=o.useState(new Set),[z,K]=o.useState(!1),[te,Y]=o.useState(""),[ae,ge]=o.useState(""),[de,he]=o.useState(""),[se,re]=o.useState(1800*1e3),[ue,Ce]=o.useState(480*60*1e3),[Se,ye]=o.useState(""),[fe,_e]=o.useState([]),[Ue,Ne]=o.useState(()=>Date.now()),[Oe,Ve]=o.useState(null),Ge=t(hf),ve=o.useRef(null),Z=o.useMemo(()=>$?!Ra($):!1,[$]),ne=o.useMemo(()=>k.find(Q=>Q.id===J)||k[0]||null,[k,J]),be=o.useMemo(()=>fe.map(Q=>{const pe=Q.expiresAt<=Ue,De=Q.status==="active"&&!pe,Ae=De?cl(Q.expiresAt-Ue):Q.inactiveReason==="expired"||pe?"expired":"inactive",it=Ae==="expired"?t("settings.aiworker.tunnel.state.expired"):Q.inactiveReason==="tunnel-revoked"?t("settings.aiworker.tunnel.state.revoked"):t("settings.aiworker.tunnel.state.inactive"),rt=Nn(Q.mode);return{...Q,isActive:De,mode:rt,remainingTextForSession:Ae,inactiveLabel:it}}),[Ue,fe,t]),we=o.useMemo(()=>i?.connectUrl?i.bootstrapExpiresAt===null?!0:i.bootstrapExpiresAt>Ue:!1,[Ue,i?.bootstrapExpiresAt,i?.connectUrl]),Re=o.useMemo(()=>!i||n!=="active"&&n!=="stopping"?!1:g===S,[g,n,i,S]),Fe=o.useMemo(()=>!i||n!=="active"||!g?!1:g!==S,[g,n,i,S]),Ke=o.useMemo(()=>{if(typeof Oe=="number"&&Number.isFinite(Oe)&&Oe>0)return Oe;if(typeof window>"u")return null;const pe=$a()||window.location.href;let De=0;try{De=Number(new URL(pe).port)}catch{De=Number(window.location.port)}return Number.isFinite(De)&&De>0?De:null},[Oe]),Ee=o.useMemo(()=>F.find(Q=>Q.provider===I)??null,[F,I]),je=o.useMemo(()=>{const Q=new Set(Ee?.modes?.map(pe=>pe.key).filter(pe=>pe==="quick"||pe==="managed-remote"||pe==="managed-local"));return Q.size===0?ir:ir.filter(pe=>Q.has(pe.value))},[Ee]),Ze=o.useMemo(()=>je.some(Q=>Q.value==="managed-remote"||Q.value==="managed-local"),[je]),me=o.useMemo(()=>h.provider===I?h:rr(I),[h,I]),Ie=o.useCallback(async Q=>{await Pn(Q)},[]),Le=o.useCallback((Q,pe)=>(w(rr(pe,Q)),Q.available===!0),[]),Xe=o.useCallback(async(Q,pe)=>{try{const De=await yt("/api/openchamber/tunnel/check",{query:{provider:Q},...pe?{signal:pe}:{}});if(!De.ok)return null;const Ae=await De.json();if(pe?.aborted)return null;const it=Le(Ae,Q);return r(rt=>rt==="checking"||rt==="starting"||rt==="active"||rt==="stopping"?rt:it?"idle":"not-available"),it}catch{return null}},[Le]),q=o.useCallback(async Q=>{try{const[pe,De,Ae,it]=await Promise.all([yt("/api/openchamber/tunnel/check",{signal:Q}),yt("/api/openchamber/tunnel/status",{signal:Q}),pn(),yt("/api/openchamber/tunnel/providers",{signal:Q})]),rt=await pe.json(),qe=await De.json(),Pt=Ae??{},ys=it.ok?await it.json():{},Xt=qe.ttlConfig?.bootstrapTtlMs??(Pt.tunnelBootstrapTtlMs===void 0?1800*1e3:Pt.tunnelBootstrapTtlMs),Os=typeof qe.ttlConfig?.sessionTtlMs=="number"?qe.ttlConfig.sessionTtlMs:Pt.tunnelSessionTtlMs??480*60*1e3,Wt=Nn(qe.mode??Pt.tunnelMode),is=Pt.tunnelProvider??"cloudflare",Ht=Pt.managedLocalTunnelConfigPath??null,bs=Le(rt,is),gs=yf(qe?.managedRemoteTunnelPresets),hs=typeof qe.managedRemoteTunnelHostname=="string"?qe.managedRemoteTunnelHostname:"",ds=gs.length>0?gs:hs?[{id:`legacy-${ji(hs)}`,name:hs,hostname:ji(hs)}]:[],Es=ds[0]?.id||"";if(re(Xt),Ce(Os),j(is),T(Array.isArray(ys?.providers)?ys.providers:[]),D(Wt),B(Ht),G(ds),ee(Es),_e(Array.isArray(qe.activeSessions)?qe.activeSessions:[]),c(qe.activeTunnelMode?Nn(qe.activeTunnelMode):qe.active&&qe.mode?Nn(qe.mode):null),H(new Set(Array.isArray(qe.managedRemoteTunnelTokenPresetIds)?qe.managedRemoteTunnelTokenPresetIds:[])),Ve(typeof qe.localPort=="number"?qe.localPort:null),qe.active&&qe.url){l({url:qe.url,connectUrl:null,bootstrapExpiresAt:typeof qe.bootstrapExpiresAt=="number"?qe.bootstrapExpiresAt:null}),r("active");return}r(bs?"idle":"not-available")}catch{Q.aborted||(r("error"),d(t("settings.aiworker.tunnel.toast.checkAvailabilityFailed")))}},[Le,t]);o.useEffect(()=>{const Q=new AbortController;return q(Q.signal),()=>Q.abort()},[q]),o.useEffect(()=>{if(!i?.connectUrl){p(null);return}let Q=!1;return zl.toDataURL(i.connectUrl,{width:256,margin:2,color:{dark:"#000000",light:"#ffffff"}}).then(pe=>{Q||p(pe)}).catch(()=>{Q||p(null)}),()=>{Q=!0}},[i?.connectUrl]),o.useEffect(()=>{if(!i?.bootstrapExpiresAt){ye(t("settings.aiworker.tunnel.state.noExpiry"));return}let Q=null,pe=Date.now();const De=()=>{const rt=i.bootstrapExpiresAt?i.bootstrapExpiresAt-Date.now():0;rt<=0?ye(t("settings.aiworker.tunnel.state.expired")):ye(cl(rt))},Ae=()=>{const rt=Date.now();rt-pe>=1e3&&(De(),pe=rt),Q=requestAnimationFrame(Ae)};De(),(typeof document>"u"||document.visibilityState==="visible")&&(Q=requestAnimationFrame(Ae));const it=()=>{document.visibilityState==="visible"&&Q===null?Q=requestAnimationFrame(Ae):document.visibilityState!=="visible"&&Q!==null&&(cancelAnimationFrame(Q),Q=null)};return document.addEventListener("visibilitychange",it),()=>{document.removeEventListener("visibilitychange",it),Q!==null&&cancelAnimationFrame(Q)}},[t,i?.bootstrapExpiresAt]),o.useEffect(()=>{let Q=null,pe=Date.now();const De=()=>{const it=Date.now();it-pe>=1e3&&(Ne(it),pe=it),Q=requestAnimationFrame(De)};(typeof document>"u"||document.visibilityState==="visible")&&(Q=requestAnimationFrame(De));const Ae=()=>{document.visibilityState==="visible"&&Q===null?Q=requestAnimationFrame(De):document.visibilityState!=="visible"&&Q!==null&&(cancelAnimationFrame(Q),Q=null)};return document.addEventListener("visibilitychange",Ae),()=>{document.removeEventListener("visibilitychange",Ae),Q!==null&&cancelAnimationFrame(Q)}},[]),o.useEffect(()=>{if(n==="starting"||n==="stopping"||n==="checking")return;let Q=!1;const pe=async()=>{try{const Ae=await yt("/api/openchamber/tunnel/status");if(!Ae.ok||Q)return;const it=await Ae.json();if(Q)return;_e(Array.isArray(it.activeSessions)?it.activeSessions:[]),H(new Set(Array.isArray(it.managedRemoteTunnelTokenPresetIds)?it.managedRemoteTunnelTokenPresetIds:[])),Ve(typeof it.localPort=="number"?it.localPort:null)}catch{}},De=window.setInterval(()=>{typeof document<"u"&&document.visibilityState!=="visible"||pe()},5e3);return()=>{Q=!0,window.clearInterval(De)}},[n]);const ke=o.useCallback(async Q=>{R(!0);try{await gt(Q),Object.prototype.hasOwnProperty.call(Q,"tunnelMode")&&Q.tunnelMode&&D(Q.tunnelMode),Object.prototype.hasOwnProperty.call(Q,"tunnelProvider")&&typeof Q.tunnelProvider=="string"&&j(Q.tunnelProvider),Object.prototype.hasOwnProperty.call(Q,"managedLocalTunnelConfigPath")&&B(Q.managedLocalTunnelConfigPath??null),Object.prototype.hasOwnProperty.call(Q,"managedRemoteTunnelPresets")&&Q.managedRemoteTunnelPresets&&G(Q.managedRemoteTunnelPresets)}catch{E.error(t("settings.aiworker.tunnel.toast.saveSettingsFailed"))}finally{R(!1)}},[t]),Pe=o.useCallback(async(Q,pe)=>{m(!0);try{await gt({tunnelBootstrapTtlMs:Q,tunnelSessionTtlMs:pe})}catch{E.error(t("settings.aiworker.tunnel.toast.saveTtlFailed"))}finally{m(!1)}},[t]),Je=o.useCallback(async Q=>{const pe=Q.token.trim();if(pe)try{const De={...U,[Q.presetId]:pe};await gt({managedRemoteTunnelPresetTokens:De}),H(Ae=>{const it=new Set(Ae);return it.add(Q.presetId),it})}catch{E.error(t("settings.aiworker.tunnel.toast.saveTokenFailed"))}},[U,t]),ot=o.useCallback(async Q=>{f(null),d(null);const pe=F.find(Ae=>Ae.provider===Q),De=pe?.modes?.some(Ae=>Ae.key===S)?S:Nn(pe?.modes?.[0]?.key);await ke({tunnelProvider:Q,tunnelMode:De}),Xe(Q)},[F,Xe,ke,S]),st=o.useCallback(async()=>{const Q=await Rl({filters:[{name:"Config",extensions:["yml","yaml","json"]}]});if(Q.success&&typeof Q.path=="string"&&Q.path.trim().length>0){const pe=Q.path.trim();if(!Ra(pe)){E.error(Ge);return}B(pe),await ke({managedLocalTunnelConfigPath:pe});return}ve.current?.click()},[Ge,ke]),pt=o.useCallback(Q=>{const pe=Q.trim();B(pe.length>0?pe:null)},[]),vt=o.useCallback(async()=>{if($&&!Ra($)){E.error(Ge);return}await ke({managedLocalTunnelConfigPath:$})},[Ge,$,ke]),W=o.useCallback(async()=>{B(null),await ke({managedLocalTunnelConfigPath:null})},[ke]),We=o.useCallback(async Q=>{const pe=Q.target.files?.[0];if(!pe)return;const De=pe.name.trim();if(De.length!==0){if(!Ra(De)){E.error(Ge);return}B(De),await ke({managedLocalTunnelConfigPath:De}),Q.target.value=""}},[Ge,ke]),nt=o.useCallback(async()=>{if(d(null),f(null),S==="managed-local"&&$&&!Ra($)){d(Ge),E.error(Ge);return}r("starting");try{let Q="",pe="";if(S==="managed-remote"){if(!ne){r("idle"),f(t("settings.aiworker.tunnel.toast.selectOrAddManagedRemoteFirst")),E.error(t("settings.aiworker.tunnel.toast.selectOrAddManagedRemoteFirst"));return}Q=ne.hostname,pe=(U[ne.id]||"").trim(),await ke({tunnelMode:"managed-remote",managedRemoteTunnelPresets:k})}const De=await yt("/api/openchamber/tunnel/start",{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify({provider:I,mode:S,...S==="managed-remote"&&ne?{managedRemoteTunnelPresetId:ne.id,managedRemoteTunnelPresetName:ne.name}:{},...S==="managed-remote"&&Q?{managedRemoteTunnelHostname:Q}:{},...S==="managed-remote"&&pe?{managedRemoteTunnelToken:pe}:{},...S==="managed-local"&&$?{configPath:$}:{}})}),Ae=await De.json();if(!De.ok||!Ae.ok){if(S==="managed-remote"&&typeof Ae.error=="string"&&Ae.error.includes("Managed remote tunnel token is required")){r("idle"),f(t("settings.aiworker.tunnel.toast.managedRemoteTokenRequiredBeforeStarting")),E.error(t("settings.aiworker.tunnel.toast.addManagedRemoteTokenBeforeStarting"));return}r("error"),d(Ae.error||t("settings.aiworker.tunnel.toast.startFailed")),E.error(Ae.error||t("settings.aiworker.tunnel.toast.startFailed"));return}const it=typeof Ae.url=="string"?Ae.url:"";if(!it){r("error"),d(t("settings.aiworker.tunnel.toast.startedButNoPublicUrl")),E.error(t("settings.aiworker.tunnel.toast.startedButNoPublicUrl"));return}if(l({url:it,connectUrl:typeof Ae.connectUrl=="string"?Ae.connectUrl:null,bootstrapExpiresAt:typeof Ae.bootstrapExpiresAt=="number"?Ae.bootstrapExpiresAt:null}),c(Ae.activeTunnelMode?Nn(Ae.activeTunnelMode):Ae.mode?Nn(Ae.mode):S),_e(Array.isArray(Ae.activeSessions)?Ae.activeSessions:[]),Array.isArray(Ae.managedRemoteTunnelTokenPresetIds)&&H(new Set(Ae.managedRemoteTunnelTokenPresetIds)),typeof Ae.localPort=="number"&&Ve(Ae.localPort),typeof Ae.mode=="string"&&D(Nn(Ae.mode)),r("active"),Ae.replacedTunnel){const rt=typeof Ae.revokedBootstrapCount=="number"?Ae.revokedBootstrapCount:0,qe=typeof Ae.invalidatedSessionCount=="number"?Ae.invalidatedSessionCount:0;rt===1&&qe===1?E.warning(t("settings.aiworker.tunnel.toast.replacedTunnelSingleSingle")):rt===1?E.warning(t("settings.aiworker.tunnel.toast.replacedTunnelSingleManySessions",{invalidatedSessionCount:qe})):qe===1?E.warning(t("settings.aiworker.tunnel.toast.replacedTunnelManyLinksSingleSession",{revokedBootstrapCount:rt})):E.warning(t("settings.aiworker.tunnel.toast.replacedTunnelManyMany",{revokedBootstrapCount:rt,invalidatedSessionCount:qe}))}else E.success(t("settings.aiworker.tunnel.toast.linkReady"))}catch{r("error"),d(t("settings.aiworker.tunnel.toast.startFailed")),E.error(t("settings.aiworker.tunnel.toast.startFailed"))}},[Ge,k,ke,ne,U,t,I,S,$]),lt=o.useCallback(async()=>{r("stopping");try{await yt("/api/openchamber/tunnel/stop",{method:"POST"});const Q=await yt("/api/openchamber/tunnel/status");if(Q.ok){const pe=await Q.json();_e(Array.isArray(pe.activeSessions)?pe.activeSessions:[]),H(new Set(Array.isArray(pe.managedRemoteTunnelTokenPresetIds)?pe.managedRemoteTunnelTokenPresetIds:[])),Ve(typeof pe.localPort=="number"?pe.localPort:null)}l(null),c(null),p(null),r("idle"),E.success(t("settings.aiworker.tunnel.toast.stopped"))}catch{r("error"),d(t("settings.aiworker.tunnel.toast.stopFailed")),E.error(t("settings.aiworker.tunnel.toast.stopFailed"))}},[t]),ht=o.useCallback(async()=>{if(i?.connectUrl)try{await navigator.clipboard.writeText(i.connectUrl),v(!0),E.success(t("settings.aiworker.tunnel.toast.connectLinkCopied")),setTimeout(()=>v(!1),2e3)}catch{E.error(t("settings.aiworker.tunnel.toast.copyUrlFailed"))}},[t,i?.connectUrl]),Lt=o.useCallback(async Q=>{const pe=hi.find(De=>De.value===Q);pe&&(re(pe.ms),await Pe(pe.ms,ue))},[Pe,ue]),et=o.useCallback(async Q=>{const pe=fi.find(De=>De.value===Q);!pe||pe.ms===null||(Ce(pe.ms),await Pe(se,pe.ms))},[se,Pe]),ft=o.useCallback(async Q=>{f(null),d(null),n!=="active"&&n!=="stopping"&&n!=="starting"&&r("idle"),await ke({tunnelMode:Q,managedRemoteTunnelPresets:k})},[k,ke,n]),bt=o.useCallback(async(Q,pe)=>{try{await gt({managedRemoteTunnelPresets:pe})}catch{E.error(t("settings.aiworker.tunnel.toast.saveSelectedManagedRemoteFailed"))}},[t]),Be=o.useCallback(Q=>{const pe=k.find(De=>De.id===Q);pe&&(ee(pe.id),f(null),bt(pe,k))},[k,bt]),Et=o.useCallback(async()=>{const Q=te.trim(),pe=ji(ae),De=de.trim();if(!Q){E.error(t("settings.aiworker.tunnel.toast.tunnelNameRequired"));return}if(!pe){E.error(t("settings.aiworker.tunnel.toast.managedRemoteHostnameRequired"));return}if(!De){E.error(t("settings.aiworker.tunnel.toast.managedRemoteTokenRequired"));return}if(k.some(rt=>rt.hostname===pe)){E.error(t("settings.aiworker.tunnel.toast.hostnameAlreadyExists"));return}const Ae={id:bf(),name:Q,hostname:pe},it=[...k,Ae];G(it),ee(Ae.id),L(rt=>({...rt,[Ae.id]:!0})),le(rt=>({...rt,[Ae.id]:De})),f(null),K(!1),Y(""),ge(""),he(""),await ke({tunnelMode:"managed-remote",managedRemoteTunnelPresets:it,managedRemoteTunnelPresetTokens:{...U,[Ae.id]:De}}),await Je({presetId:Ae.id,presetName:Ae.name,hostname:Ae.hostname,token:De}),E.success(t("settings.aiworker.tunnel.toast.managedRemoteSaved"))},[k,ae,te,de,Je,ke,U,t]),Me=o.useCallback(async Q=>{const pe=k.find(qe=>qe.id===Q);if(!pe)return;const De=k.filter(qe=>qe.id!==pe.id),Ae=De[0]?.id||"",it=J===pe.id?Ae:J,rt=Object.fromEntries(Object.entries(U).filter(([qe,Pt])=>qe!==pe.id&&Pt.trim().length>0));G(De),ee(it),L(qe=>{const Pt={...qe};return delete Pt[pe.id],Pt}),le(qe=>{const Pt={...qe};return delete Pt[pe.id],Pt}),H(qe=>{const Pt=new Set(qe);return Pt.delete(pe.id),Pt}),f(null),await ke({managedRemoteTunnelPresets:De,managedRemoteTunnelPresetTokens:rt}),E.success(t("settings.aiworker.tunnel.toast.managedRemoteRemoved"))},[k,ke,J,U,t]),wt="gap-2 border-[var(--primary-base)] bg-[var(--primary-base)] text-[var(--primary-foreground)] hover:bg-[var(--primary-hover)] hover:text-[var(--primary-foreground)]";return n==="checking"?s.jsx("div",{className:"flex items-center justify-center py-12",children:s.jsx("span",{className:"h-1.5 w-1.5 rounded-full bg-current animate-busy-pulse","aria-label":t("settings.aiworker.tunnel.state.loading")})}):s.jsx(ze,{title:t("settings.aiworker.tunnel.title"),info:s.jsxs("div",{className:"space-y-1",children:[s.jsx("p",{children:t("settings.aiworker.tunnel.description")}),s.jsx("p",{children:t("settings.aiworker.tunnel.note.serverSideEnforced")}),s.jsx("p",{children:t("settings.aiworker.tunnel.note.connectLinksOneTime")})]}),divider:!1,children:s.jsxs("div",{className:"space-y-6",children:[be.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(O,{name:"information",className:"size-4 text-[var(--status-info)]"}),s.jsx("p",{className:Gr,children:t("settings.aiworker.tunnel.section.redeemedAccessLinks")})]}),s.jsx("div",{className:"space-y-1",children:be.map(Q=>{const pe=Q.mode==="quick",De=Q.mode==="managed-remote",Ae=pe?"border-[var(--status-warning-border)] bg-[var(--status-warning-background)] text-[var(--status-warning)]":De?"border-[var(--status-info-border)] bg-[var(--status-info-background)] text-[var(--status-info)]":"border-[var(--status-success-border)] bg-[var(--status-success-background)] text-[var(--status-success)]",it=Q.isActive?pe?"text-[var(--status-warning)]":De?"text-[var(--status-info)]":"text-[var(--status-success)]":"text-muted-foreground/50",rt=t(pe?"settings.aiworker.tunnel.badge.quick":De?"settings.aiworker.tunnel.badge.remote":"settings.aiworker.tunnel.badge.local");return s.jsxs("div",{className:"flex flex-wrap items-center gap-x-2 gap-y-1 rounded border border-[var(--surface-subtle)] bg-[var(--surface-elevated)] px-2 py-1.5",children:[s.jsx(O,{name:"checkbox-blank-circle-fill",className:xe("size-2.5 shrink-0",it)}),s.jsx("span",{className:xe("typography-micro rounded border px-1.5 py-0.5 uppercase",Ae),children:rt}),s.jsx("span",{className:"typography-meta text-muted-foreground/80",children:t("settings.aiworker.tunnel.session.redeemedAt",{time:vf(Q.createdAt,e)})}),s.jsx("span",{className:"typography-meta text-foreground",children:Q.isActive?t("settings.aiworker.tunnel.session.expiresIn",{remaining:Q.remainingTextForSession}):Q.inactiveLabel===t("settings.aiworker.tunnel.state.inactive")?t("settings.aiworker.tunnel.state.inactive"):t("settings.aiworker.tunnel.session.inactiveWithReason",{reason:Q.inactiveLabel})})]},Q.sessionId)})})]})}),n==="not-available"&&s.jsx("section",{className:"space-y-2 px-2 pb-2 pt-0",children:s.jsxs("div",{className:"flex items-start gap-2 rounded-lg border border-[var(--status-warning)]/30 bg-[var(--status-warning)]/5 p-3",children:[s.jsx(O,{name:"error-warning",className:"mt-0.5 size-4 shrink-0 text-[var(--status-warning)]"}),s.jsxs("div",{className:"space-y-1",children:[s.jsx("p",{className:Gr,children:t("settings.aiworker.tunnel.notAvailable.dependencyNotFound",{dependency:me.dependency})}),s.jsx("p",{className:"typography-meta text-muted-foreground/70",children:t("settings.aiworker.tunnel.notAvailable.installHint")}),s.jsx("code",{className:"typography-code block rounded bg-muted/50 px-2 py-1 text-xs text-foreground",children:me.installCommand})]})]})}),s.jsxs("section",{className:"space-y-4 px-2 pb-2 pt-0",children:[s.jsxs("div",{className:"space-y-3",children:[s.jsxs("div",{"data-settings-item":"tunnel.provider",className:"space-y-1.5",children:[s.jsx("p",{className:Tt,children:t("settings.aiworker.tunnel.field.provider")}),s.jsxs(St,{value:I,onValueChange:Q=>{ot(Q)},disabled:A||n==="starting"||n==="stopping",children:[s.jsx(Ct,{size:Ft,className:"max-w-[16rem]",children:s.jsx(Mt,{placeholder:t("settings.aiworker.tunnel.field.providerPlaceholder"),children:ic(I)})}),s.jsxs(It,{children:[F.length>0?F.map(Q=>s.jsx(at,{value:Q.provider,children:s.jsx(ol,{provider:Q.provider})},Q.provider)):s.jsx(at,{value:"cloudflare",children:s.jsx(ol,{provider:"cloudflare"})}),s.jsx(at,{value:"__more-soon",disabled:!0,children:t("settings.aiworker.tunnel.option.moreProvidersSoon")})]})]})]}),s.jsxs("div",{"data-settings-item":"tunnel.type",className:"space-y-1.5",children:[s.jsx("p",{className:Tt,children:t("settings.aiworker.tunnel.field.tunnelType")}),s.jsx("div",{className:"flex flex-wrap items-center gap-1",children:je.map(Q=>s.jsxs(kr,{children:[s.jsx(Nr,{asChild:!0,children:s.jsx(V,{variant:"chip",size:"xs","aria-pressed":S===Q.value,className:"!font-normal",onClick:()=>{ft(Q.value)},disabled:A||n==="starting"||n==="stopping",children:a(Q.labelKey)})}),s.jsx(kl,{sideOffset:8,className:"max-w-xs",children:a(Q.tooltipKey)})]},Q.value))})]})]}),s.jsxs("div",{"data-settings-item":"tunnel.ttl",className:"mt-2 grid grid-cols-1 gap-2 py-1.5 md:grid-cols-[14rem_auto] md:gap-x-8 md:gap-y-2",children:[s.jsxs("div",{className:"flex min-w-0 items-center gap-2",children:[s.jsx("span",{className:xe(Tt,"shrink-0"),children:t("settings.aiworker.tunnel.field.connectLinkTtl")}),s.jsxs(St,{value:yr(hi,se,"1800000"),onValueChange:Q=>{Lt(Q)},disabled:N||A||n==="starting"||n==="stopping",children:[s.jsx(Ct,{size:Ft,className:"max-w-[11rem] min-w-0",children:s.jsx(Mt,{className:"truncate",children:ll(hi,se,"1800000")})}),s.jsx(It,{children:hi.map(Q=>s.jsx(at,{value:Q.value,children:Q.label},Q.value))})]})]}),s.jsxs("div",{className:"flex min-w-0 items-center gap-2",children:[s.jsx("span",{className:xe(Tt,"shrink-0"),children:t("settings.aiworker.tunnel.field.tunnelSessionTtl")}),s.jsxs(St,{value:yr(fi,ue,"28800000"),onValueChange:Q=>{et(Q)},disabled:N||A||n==="starting"||n==="stopping",children:[s.jsx(Ct,{size:Ft,className:"max-w-[11rem] min-w-0",children:s.jsx(Mt,{className:"truncate",children:ll(fi,ue,"28800000")})}),s.jsx(It,{children:fi.map(Q=>s.jsx(at,{value:Q.value,children:Q.label},Q.value))})]})]})]}),S==="quick"&&s.jsx("div",{className:"rounded-lg border border-[var(--status-warning)]/35 bg-[var(--status-warning)]/10 p-3",children:s.jsxs("div",{className:"flex items-start gap-2",children:[s.jsx(O,{name:"error-warning",className:"mt-0.5 size-4 shrink-0 text-[var(--status-warning)]"}),s.jsxs("div",{children:[s.jsx("p",{className:"typography-meta text-[var(--status-warning)]",children:t("settings.aiworker.tunnel.option.mode.quick.tooltip")}),Ze&&s.jsx("p",{className:"typography-meta mt-1 text-[var(--status-warning)]",children:t("settings.aiworker.tunnel.warning.quickModeReliability")})]})]})}),S==="managed-remote"&&s.jsxs("div",{"data-settings-item":"tunnel.managed-remote",className:"space-y-2 rounded-lg border border-[var(--interactive-border)] bg-[var(--surface-elevated)] p-3",children:[typeof Ke=="number"&&s.jsx("div",{className:"rounded-md border border-[var(--status-info-border)] bg-[var(--status-info-background)]/35 px-2 py-1.5",children:s.jsxs("p",{className:"typography-meta text-[var(--status-info)]",children:[t("settings.aiworker.tunnel.note.cloudflareConnectorTarget")," ",s.jsxs("code",{children:["http://localhost:",Ke]})]})}),s.jsxs("div",{className:"mb-1 flex items-center justify-between gap-3",children:[s.jsx(Zs,{children:t("settings.aiworker.tunnel.section.savedManagedRemoteTunnels")}),s.jsxs(V,{variant:"ghost",size:"xs",className:"!font-normal",onClick:()=>K(Q=>!Q),disabled:n==="starting"||n==="stopping"||A,children:[s.jsx(O,{name:"add",className:"h-3.5 w-3.5"}),t("settings.common.actions.create")]})]}),k.length>0?s.jsx("div",{className:"overflow-hidden rounded-md border border-[var(--surface-subtle)]",children:k.map((Q,pe)=>{const De=U[Q.id]||"",Ae=_.has(Q.id),it=M[Q.id]??!1;return s.jsx("div",{className:xe(pe<k.length-1&&"border-b border-[var(--surface-subtle)]"),children:s.jsxs(An,{open:it,onOpenChange:rt=>{L(qe=>({...qe,[Q.id]:rt})),rt&&Be(Q.id)},className:"py-1.5",children:[s.jsxs("div",{className:"flex items-start gap-2 px-3",children:[s.jsxs(Tn,{type:"button",className:"group flex-1 justify-start gap-2 rounded-md px-0 py-1 pr-1 text-left hover:bg-[var(--interactive-hover)]",disabled:n==="starting"||n==="stopping"||A,children:[it?s.jsx(O,{name:"arrow-down-s",className:"h-4 w-4 text-muted-foreground"}):s.jsx(O,{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(V,{variant:"ghost",size:"xs",className:"h-7 w-7 p-0 text-muted-foreground hover:text-[var(--status-error)]","aria-label":t("settings.aiworker.tunnel.actions.removePresetAria",{name:Q.name}),onClick:()=>{Me(Q.id)},disabled:n==="starting"||n==="stopping"||A,children:s.jsx(O,{name:"delete-bin",className:"h-3.5 w-3.5"})})]}),s.jsx(En,{className:"pt-1.5",children:s.jsxs("div",{className:"space-y-1 px-3 pb-2",children:[s.jsxs("p",{className:"typography-meta text-muted-foreground/70",children:[t("settings.aiworker.tunnel.field.hostnameLabel")," ",s.jsx("code",{children:Q.hostname})]}),s.jsx(He,{type:"password",value:De,onChange:rt=>{const qe=rt.target.value;f(null),le(Pt=>({...Pt,[Q.id]:qe}))},onBlur:rt=>{const qe=rt.currentTarget.value.trim();qe&&Je({presetId:Q.id,presetName:Q.name,hostname:Q.hostname,token:qe})},placeholder:t(Ae?"settings.aiworker.tunnel.field.savedTokenAvailablePlaceholder":"settings.aiworker.tunnel.field.pasteTokenPlaceholder"),className:"h-7",disabled:n==="starting"||n==="stopping"}),s.jsx("div",{className:"flex items-center justify-end",children:s.jsx(V,{variant:"ghost",size:"xs",className:"!font-normal",disabled:n==="starting"||n==="stopping"||De.trim().length===0,onClick:()=>{Je({presetId:Q.id,presetName:Q.name,hostname:Q.hostname,token:De})},children:t("settings.aiworker.tunnel.actions.saveToken")})})]})})]})},Q.id)})}):s.jsx("p",{className:"typography-meta text-muted-foreground/70",children:t("settings.aiworker.tunnel.empty.noManagedRemoteTunnels")}),z&&s.jsxs("div",{className:"space-y-2 rounded-md border border-[var(--surface-subtle)] p-2",children:[s.jsx(He,{value:te,onChange:Q=>Y(Q.target.value),placeholder:t("settings.aiworker.tunnel.field.newPresetNamePlaceholder"),className:"h-7",disabled:A||n==="starting"||n==="stopping"}),s.jsx(He,{value:ae,onChange:Q=>ge(Q.target.value),placeholder:t("settings.aiworker.tunnel.field.newPresetHostnamePlaceholder"),className:"h-7",disabled:A||n==="starting"||n==="stopping"}),s.jsx(He,{type:"password",value:de,onChange:Q=>he(Q.target.value),placeholder:t("settings.aiworker.tunnel.field.newPresetTokenPlaceholder"),className:"h-7",disabled:A||n==="starting"||n==="stopping"}),typeof Ke=="number"&&s.jsxs("p",{className:"typography-meta text-muted-foreground/70",children:[t("settings.aiworker.tunnel.note.cloudflareConnectorTargetUse")," ",s.jsxs("code",{children:["http://localhost:",Ke]}),"."]}),s.jsxs("div",{className:"flex items-center gap-2",children:[s.jsx(V,{variant:"ghost",size:"xs",className:"!font-normal",onClick:()=>{Et()},disabled:A||n==="starting"||n==="stopping",children:t("settings.common.actions.saveChanges")}),s.jsx(V,{variant:"ghost",size:"xs",className:"!font-normal",onClick:()=>{K(!1),Y(""),ge(""),he("")},disabled:A||n==="starting"||n==="stopping",children:t("settings.common.actions.cancel")})]})]}),s.jsxs("div",{className:"flex items-center gap-1.5",children:[s.jsx("p",{className:"typography-meta text-muted-foreground/80",children:t("settings.aiworker.tunnel.note.tokensSavedPerTunnel")}),s.jsx(Jt,{children:t("settings.aiworker.tunnel.tooltip.tokensSavedPath")})]}),!ne&&P&&s.jsx("p",{className:"typography-meta text-[var(--status-error)]",children:P})]}),S==="managed-local"&&s.jsx("div",{"data-settings-item":"tunnel.managed-local-config",className:"space-y-2 rounded-lg border border-[var(--interactive-border)] bg-[var(--surface-elevated)] p-3",children:s.jsxs("div",{className:"space-y-1.5",children:[s.jsx("p",{className:Tt,children:t("settings.aiworker.tunnel.field.configurationFile")}),s.jsx("input",{ref:ve,type:"file",accept:".yml,.yaml,.json",className:"hidden",onChange:Q=>{We(Q)}}),s.jsxs("div",{className:"flex items-center gap-2",children:[s.jsx(He,{value:$||"",onChange:Q=>{pt(Q.target.value)},onBlur:()=>{vt()},placeholder:t("settings.aiworker.tunnel.field.configurationFilePlaceholder"),className:"h-7",disabled:n==="starting"||n==="stopping"||A}),s.jsx(V,{variant:"outline",size:"xs",className:"h-7 w-7 p-0","aria-label":t("settings.aiworker.tunnel.actions.browseConfigFileAria"),onClick:()=>{st()},disabled:n==="starting"||n==="stopping"||A,children:s.jsx(O,{name:"folder",className:"size-3.5"})}),$&&s.jsx(V,{variant:"ghost",size:"xs",className:"h-7 w-7 p-0","aria-label":t("settings.aiworker.tunnel.actions.clearConfigFileAria"),onClick:()=>{W()},disabled:n==="starting"||n==="stopping"||A,children:s.jsx(O,{name:"close",className:"size-3.5"})})]}),s.jsx("p",{className:"typography-meta text-muted-foreground/70",children:t($?"settings.aiworker.tunnel.note.customConfigUsed":"settings.aiworker.tunnel.note.defaultConfigUsed")}),Z&&s.jsx("p",{className:"typography-meta text-[var(--status-error)]",children:Ge})]})}),!Re&&s.jsxs("div",{"data-settings-item":"tunnel.start",className:"space-y-6",children:[s.jsx("div",{className:"rounded-lg border border-[var(--status-info-border)] bg-[var(--status-info-background)] p-3",children:s.jsxs("div",{className:"flex items-start gap-2",children:[s.jsx(O,{name:"information",className:"mt-0.5 size-4 shrink-0 text-[var(--status-info)]"}),s.jsxs("div",{className:"space-y-1",children:[S==="managed-remote"&&s.jsxs(s.Fragment,{children:[s.jsx("p",{className:"typography-meta text-[var(--status-info)]",children:t("settings.aiworker.tunnel.note.managedRemoteRequiresDomain")}),s.jsxs("button",{type:"button",className:"typography-meta inline-flex items-center gap-1 text-[var(--status-info)] underline underline-offset-2 hover:opacity-90",onClick:()=>{Ie(pf)},children:[t("settings.aiworker.tunnel.actions.openManagedRemoteDocs"),s.jsx(O,{name:"external-link",className:"size-3.5"})]})]}),S==="managed-local"&&s.jsxs(s.Fragment,{children:[s.jsx("p",{className:"typography-meta text-[var(--status-info)]",children:t("settings.aiworker.tunnel.note.managedLocalUsesConfig")}),s.jsxs("button",{type:"button",className:"typography-meta inline-flex items-center gap-1 text-[var(--status-info)] underline underline-offset-2 hover:opacity-90",onClick:()=>{Ie(mf)},children:[t("settings.aiworker.tunnel.actions.openManagedLocalDocs"),s.jsx(O,{name:"external-link",className:"size-3.5"})]})]}),s.jsx("p",{className:"typography-meta text-[var(--status-info)]",children:t("settings.aiworker.tunnel.note.startModeAndGenerateLink",{mode:a(ir.find(Q=>Q.value===S)?.labelKey??"settings.aiworker.tunnel.option.mode.quick.label")})})]})]})}),S==="managed-remote"&&s.jsxs("div",{className:"space-y-1.5",children:[s.jsx("p",{className:Tt,children:t("settings.aiworker.tunnel.field.managedRemoteTunnelToConnect")}),s.jsxs(St,{value:J||(k[0]?.id??""),onValueChange:Q=>{Be(Q)},disabled:A||n==="starting"||n==="stopping"||k.length<=1,children:[s.jsx(Ct,{size:Ft,children:s.jsx(Mt,{placeholder:t("settings.aiworker.tunnel.field.selectSavedTunnelPlaceholder"),children:ne?.name})}),s.jsx(It,{fitContent:!0,children:k.map(Q=>s.jsx(at,{value:Q.id,children:Q.name},Q.id))})]})]}),Fe&&s.jsx("div",{className:"rounded-lg border border-[var(--status-warning-border)] bg-[var(--status-warning-background)] p-3",children:s.jsxs("div",{className:"flex items-start gap-2",children:[s.jsx(O,{name:"error-warning",className:"mt-0.5 size-4 shrink-0 text-[var(--status-warning)]"}),s.jsx("p",{className:"typography-meta text-[var(--status-warning)]",children:t("settings.aiworker.tunnel.warning.replacesActiveTunnel")})]})}),s.jsx(V,{size:"sm",variant:"outline",onClick:nt,disabled:n==="starting"||A||S==="managed-remote"&&!ne||S==="managed-local"&&Z,className:xe(wt,n==="starting"&&"opacity-70"),children:n==="starting"?s.jsxs(s.Fragment,{children:[s.jsx(O,{name:"loader-4",className:"size-3.5 animate-spin"})," ",t("settings.aiworker.tunnel.actions.startingTunnel")]}):t("settings.aiworker.tunnel.actions.startTunnel")})]})]}),Re&&i&&s.jsxs("section",{"data-settings-item":"tunnel.start",className:"space-y-4 px-2 pb-2 pt-0",children:[s.jsxs("div",{className:"space-y-3",children:[s.jsxs("div",{className:"flex items-center gap-2",children:[s.jsx("div",{className:"size-2 shrink-0 rounded-full bg-[var(--status-success)]"}),s.jsx("p",{className:"typography-meta font-medium text-foreground",children:t("settings.aiworker.tunnel.state.tunnelReady")})]}),s.jsxs("div",{children:[s.jsx("p",{className:"typography-meta mb-1 text-muted-foreground/70",children:t("settings.aiworker.tunnel.field.publicUrlHint")}),s.jsx("code",{className:"typography-code block truncate rounded bg-muted/50 px-2 py-1 text-xs text-foreground",children:i.url})]}),we&&i.connectUrl&&s.jsxs(s.Fragment,{children:[s.jsxs("div",{children:[s.jsx("p",{className:"typography-meta mb-1 text-muted-foreground/70",children:t("settings.aiworker.tunnel.field.connectLink")}),s.jsxs("div",{className:"flex items-center gap-2",children:[s.jsx("code",{className:"typography-code flex-1 truncate rounded bg-muted/50 px-2 py-1 text-xs text-foreground",children:i.connectUrl}),s.jsxs(V,{size:"sm",variant:"ghost",onClick:ht,className:"shrink-0 gap-1.5",children:[C?s.jsx(O,{name:"check",className:"size-3.5 text-[var(--status-success)]"}):s.jsx(O,{name:"file-copy",className:"size-3.5"}),t(C?"settings.aiworker.tunnel.actions.copied":"settings.common.actions.copyAll")]})]}),s.jsxs("p",{className:"typography-meta mt-1 text-muted-foreground/70",children:[t("settings.aiworker.tunnel.field.expires"),": ",i.bootstrapExpiresAt?Se:t("settings.aiworker.tunnel.state.never")]})]}),s.jsxs("div",{className:"flex flex-col items-center gap-2 rounded-lg border border-border/50 bg-[var(--surface-elevated)] p-4",children:[y?s.jsx("img",{src:y,alt:t("settings.aiworker.tunnel.field.connectQrAlt"),className:"size-48"}):s.jsx("div",{className:"size-48 rounded bg-muted/30"}),s.jsx("p",{className:"typography-meta text-muted-foreground",children:t("settings.aiworker.tunnel.note.scanQrToConnect")})]})]})]}),s.jsx("div",{className:"pt-1",children:s.jsxs("div",{className:"flex flex-wrap items-center gap-2",children:[s.jsxs(V,{size:"sm",variant:"outline",onClick:nt,disabled:n==="stopping"||A||S==="managed-local"&&Z,className:wt,children:[s.jsx(O,{name:"restart",className:"size-3.5"}),t("settings.aiworker.tunnel.actions.newConnectLink")]}),s.jsx(V,{size:"sm",variant:"ghost",onClick:lt,disabled:n==="stopping"||A,className:"gap-2 text-[var(--status-error)]",children:n==="stopping"?s.jsxs(s.Fragment,{children:[s.jsx(O,{name:"loader-4",className:"size-3.5 animate-spin"})," ",t("settings.aiworker.tunnel.actions.stopping")]}):t("settings.aiworker.tunnel.actions.stopTunnel")})]})})]}),n==="error"&&b&&s.jsxs("section",{className:"space-y-3 px-2 pb-2 pt-0",children:[s.jsx("p",{className:"typography-meta text-[var(--status-error)]",children:b}),s.jsx(V,{size:"sm",variant:"ghost",onClick:nt,children:t("settings.aiworker.tunnel.actions.retry")})]})]})})},rc=()=>{const{t}=tt(),[e,a]=$e.useState(""),[n,r]=$e.useState(!0),[i,l]=$e.useState(!1),g=ie(d=>d.showOpenCodeUpdateNotifications),c=ie(d=>d.setShowOpenCodeUpdateNotifications);$e.useEffect(()=>{let d=!1;return(async()=>{try{const P=await pn();if(d||!P)return;a(P.opencodeBinary??"")}catch{}finally{d||r(!1)}})(),()=>{d=!0}},[]);const y=$e.useCallback(async()=>{if(!(typeof window>"u")&&as())try{const d=await Rl();d.success&&d.path&&d.path.trim().length>0&&a(d.path.trim())}catch{}},[]),p=$e.useCallback(async()=>{l(!0);try{const d=e.trim(),P=d.length>=2&&(d.startsWith('"')&&d.endsWith('"')||d.startsWith("'")&&d.endsWith("'"))?d.slice(1,-1).trim():d;await gt({opencodeBinary:P}),$n("cli",{id:"opencode-binary"}),E.success(t("settings.view.pendingRestart.saved"))}finally{l(!1)}},[t,e]),b=$e.useCallback(d=>{c(d),gt({showOpenCodeUpdateNotifications:d})},[c]);return s.jsx(ze,{title:t("settings.aiworker.opencodeCli.title"),children:s.jsxs("div",{className:"space-y-0.5",children:[s.jsxs(Rt,{settingsItem:"sessions.opencode-binary",label:t("settings.aiworker.opencodeCli.field.binaryPath"),info:s.jsxs(s.Fragment,{children:[t("settings.aiworker.opencodeCli.tipPrefix")," ",s.jsx("span",{className:"font-mono",children:"OPENCODE_BINARY"})," ",t("settings.aiworker.opencodeCli.tipMiddle")," ",s.jsx("span",{className:"font-mono",children:"~/.config/openchamber/settings.json"}),"."]}),alignEnd:!1,controlClassName:"@xl:w-[20rem]",children:[s.jsx(He,{value:e,onChange:d=>a(d.target.value),placeholder:t("settings.aiworker.opencodeCli.field.binaryPathPlaceholder"),disabled:n||i,className:"h-8 min-w-0 flex-1 font-mono text-xs"}),s.jsx(V,{type:"button",variant:"outline",size:"xs",onClick:y,disabled:n||i||!as(),className:Cs,"aria-label":t("settings.aiworker.opencodeCli.actions.browseAria"),title:t("settings.aiworker.opencodeCli.actions.browse"),children:s.jsx(O,{name:"folder",className:"h-4 w-4"})})]}),s.jsxs(ba,{className:fs,children:[!Ll()&&s.jsx(dt,{settingsItem:"sessions.opencode-update-notifications",checked:g,onChange:b,label:t("settings.aiworker.opencodeCli.field.showUpdateNotifications"),ariaLabel:t("settings.aiworker.opencodeCli.field.showUpdateNotificationsAria")}),s.jsx("div",{className:"flex justify-start py-1.5",children:s.jsx(V,{type:"button",size:"xs",onClick:p,disabled:n||i,className:"shrink-0 !font-normal",children:t(i?"settings.common.actions.saving":"settings.common.actions.saveChanges")})})]})]})})},oc=()=>{const t=ut.c(44),{t:e}=tt(),a=ie(jf),n=ie(kf),r=ie(Nf),i=ie(Sf),l=ie(Cf),g=ie(If),c=ie(Pf);let y;t[0]!==n?(y=S=>{n(S),gt({agentControlToolEnabled:S}),$n("cli",{id:"agent-control-tool"})},t[0]=n,t[1]=y):y=t[1];const p=y;let b;t[2]!==i?(b=S=>{i(S),gt({agentWebToolEnabled:S}),$n("cli",{id:"agent-web-tool"})},t[2]=i,t[3]=b):b=t[3];const d=b;let P;t[4]!==c?(P=S=>{c(S),gt({agentMemoryToolEnabled:S}).finally(()=>{S&&rd.getState().refresh()}),$n("cli",{id:"agent-memory-tool"})},t[4]=c,t[5]=P):P=t[5];const f=P;let C;t[6]!==e?(C=e("settings.aiworker.tools.title"),t[6]=e,t[7]=C):C=t[7];let v;t[8]!==e?(v=e("settings.aiworker.tools.field.agentControlTool"),t[8]=e,t[9]=v):v=t[9];let N;t[10]!==e?(N=e("settings.aiworker.tools.field.agentControlToolAria"),t[10]=e,t[11]=N):N=t[11];let m;t[12]!==e?(m=e("settings.aiworker.tools.field.agentControlToolInfo"),t[12]=e,t[13]=m):m=t[13];let A;t[14]!==a||t[15]!==p||t[16]!==v||t[17]!==N||t[18]!==m?(A=s.jsx(dt,{settingsItem:"sessions.agent-control-tool",checked:a,onChange:p,label:v,ariaLabel:N,info:m}),t[14]=a,t[15]=p,t[16]=v,t[17]=N,t[18]=m,t[19]=A):A=t[19];let R;t[20]!==e?(R=e("settings.aiworker.tools.field.agentWebTool"),t[20]=e,t[21]=R):R=t[21];let I;t[22]!==e?(I=e("settings.aiworker.tools.field.agentWebToolAria"),t[22]=e,t[23]=I):I=t[23];let j;t[24]!==e?(j=e("settings.aiworker.tools.field.agentWebToolInfo"),t[24]=e,t[25]=j):j=t[25];let h;t[26]!==r||t[27]!==d||t[28]!==j||t[29]!==R||t[30]!==I?(h=s.jsx(dt,{settingsItem:"sessions.agent-web-tool",checked:r,onChange:d,label:R,ariaLabel:I,info:j}),t[26]=r,t[27]=d,t[28]=j,t[29]=R,t[30]=I,t[31]=h):h=t[31];let w;t[32]!==g||t[33]!==l||t[34]!==f||t[35]!==e?(w=g?s.jsx(dt,{settingsItem:"sessions.agent-memory-tool",checked:l,onChange:f,label:e("settings.aiworker.tools.field.agentMemoryTool"),ariaLabel:e("settings.aiworker.tools.field.agentMemoryToolAria"),info:e("settings.aiworker.tools.field.agentMemoryToolInfo")}):null,t[32]=g,t[33]=l,t[34]=f,t[35]=e,t[36]=w):w=t[36];let F;t[37]!==h||t[38]!==w||t[39]!==A?(F=s.jsxs("div",{className:fs,children:[A,h,w]}),t[37]=h,t[38]=w,t[39]=A,t[40]=F):F=t[40];let T;return t[41]!==F||t[42]!==C?(T=s.jsx(ze,{title:C,children:F}),t[41]=F,t[42]=C,t[43]=T):T=t[43],T};function jf(t){return t.agentControlToolEnabled}function kf(t){return t.setAgentControlToolEnabled}function Nf(t){return t.agentWebToolEnabled}function Sf(t){return t.setAgentWebToolEnabled}function Cf(t){return t.agentMemoryToolEnabled}function If(t){return t.agentMemoryFeatureAvailable}function Pf(t){return t.setAgentMemoryToolEnabled}const lc=()=>{const{t}=tt(),e=as()&&Va(),a=e&&typeof window<"u"&&window.__AIWORKER_PLATFORM__==="darwin",[n,r]=$e.useState(!1),[i,l]=$e.useState(!1),[g,c]=$e.useState(!1),[y,p]=$e.useState(""),[b,d]=$e.useState(!1),[P,f]=$e.useState(!1),[C,v]=$e.useState(null),[N,m]=$e.useState(!0),[A,R]=$e.useState(!1),[I,j]=$e.useState(!1),[h,w]=$e.useState(!1),[F,T]=$e.useState(!1),[S,D]=$e.useState(!1),[$,B]=$e.useState(!1),[k,G]=$e.useState(!1),[M,L]=$e.useState(!0),[J,ee]=$e.useState(!0),[U,le]=$e.useState(!1),[_,H]=$e.useState(!1),[z,K]=$e.useState(!1),[te,Y]=$e.useState(null),[ae,ge]=$e.useState(null);$e.useEffect(()=>{if(!e){m(!1);return}let ve=!1;return(async()=>{try{const Z=await pn();if(!Z)throw new Error(t("settings.aiworker.desktopNetwork.error.loadFailed"));if(ve)return;const ne=Z.desktopLanAccessEnabled===!0;r(ne),l(ne),c(Z.hasDesktopUiPassword===!0),p(""),d(!1),f(Z.desktopLanAccessActive===!0),v(Z.desktopLanAccessBlockedReason??null);const be=Z.desktopMacMenuBarEnabled!==!1;L(be),ee(be),Y(null)}catch(Z){ve||Y(Z instanceof Error?Z.message:t("settings.aiworker.desktopNetwork.error.loadFailed"))}finally{ve||m(!1)}})(),()=>{ve=!0}},[e,t]),$e.useEffect(()=>{if(!e){j(!1);return}let ve=!1;return(async()=>{const Z=await zd();ve||(j(Z?.supported===!0),w(Z?.enabled===!0))})(),()=>{ve=!0}},[e]),$e.useEffect(()=>{if(!e){D(!1);return}let ve=!1;return(async()=>{const Z=await Ud();ve||(D(Z?.supported===!0),B(Z?.enabled===!0))})(),()=>{ve=!0}},[e]),$e.useEffect(()=>{if(!e){le(!1);return}let ve=!1;return(async()=>{const Z=await _d();ve||(le(Z?.supported===!0),H(Z?.enabled===!0))})(),()=>{ve=!0}},[e]),$e.useEffect(()=>{if(!e||!i){ge(null);return}let ve=!1;return(async()=>{const Z=await Dl();ve||ge(Z)})(),()=>{ve=!0}},[i,e]);const de=y.trim(),he=de.length>0||b,se=i!==n||he||J!==M,re=$e.useMemo(()=>{if(typeof window>"u")return null;const Z=$a()||window.location.href;let ne=0;try{ne=Number(new URL(Z).port)}catch{ne=Number(window.location.port)}return Number.isFinite(ne)&&ne>0?ne:null},[]),ue=i&&P&&ae&&re?`http://${ae}:${re}`:null,Ce=de.length>0||g&&!b,Se=i&&!Ce,ye=n&&!P&&C==="missing-password",fe=N||A||!se||Se,_e=$e.useCallback(ve=>{p(ve),ve.trim()&&d(!1)},[]),Ue=$e.useCallback(()=>{p(""),d(!0),l(!1)},[]),Ne=$e.useCallback(async()=>{if(!I||F)return;const ve=!h;w(ve),T(!0),Y(null);try{const Z=await $d(ve);if(!Z?.supported)throw new Error(t("settings.aiworker.desktopNetwork.error.launchAtLoginUnsupported"));w(Z.enabled)}catch(Z){w(!ve),Y(Z instanceof Error?Z.message:t("settings.aiworker.desktopNetwork.error.launchAtLoginSaveFailed"))}finally{T(!1)}},[F,h,I,t]),Oe=$e.useCallback(async()=>{if(!S||k)return;const ve=!$;B(ve),G(!0),Y(null);try{const Z=await Vd(ve);if(!Z)throw new Error(t("settings.aiworker.desktopNetwork.error.minimizeToTraySaveFailed"));if(!Z.supported)throw new Error(t("settings.aiworker.desktopNetwork.error.minimizeToTrayUnsupported"));B(Z.enabled)}catch(Z){B(!ve),Y(Z instanceof Error?Z.message:t("settings.aiworker.desktopNetwork.error.minimizeToTraySaveFailed"))}finally{G(!1)}},[k,$,S,t]),Ve=$e.useCallback(async()=>{if(!U||z)return;const ve=!_;H(ve),K(!0),Y(null);try{const Z=await Bd(ve);if(!Z?.supported)throw new Error(t("settings.aiworker.desktopNetwork.error.keepAwakeUnsupported"));H(Z.enabled)}catch(Z){H(!ve),Y(Z instanceof Error?Z.message:t("settings.aiworker.desktopNetwork.error.keepAwakeSaveFailed"))}finally{K(!1)}},[z,_,U,t]),Ge=$e.useCallback(async()=>{if(se){R(!0),Y(null);try{if(!(await gt({desktopLanAccessEnabled:i,...de?{desktopUiPassword:de}:b?{desktopUiPassword:""}:{},desktopMacMenuBarEnabled:J})).ok)throw new Error(t("settings.aiworker.desktopNetwork.error.saveFailed"));if(r(i),de?c(!0):b&&c(!1),p(""),d(!1),L(J),!await Hd())throw new Error(t("settings.aiworker.desktopNetwork.error.savedRestartFailed"))}catch(ve){Y(ve instanceof Error?ve.message:t("settings.aiworker.desktopNetwork.error.saveFailed")),R(!1)}}},[J,i,se,de,b,t]);return e?s.jsx(ze,{title:t("settings.aiworker.desktopNetwork.title"),children:s.jsxs("div",{className:"space-y-3",children:[I||a||S||U?s.jsxs("div",{className:fs,children:[I?s.jsx(dt,{settingsItem:"sessions.desktop-launch-at-login",checked:h,onChange:ve=>{ve!==h&&Ne()},disabled:F,label:t("settings.aiworker.desktopNetwork.field.launchAtLogin"),info:t("settings.aiworker.desktopNetwork.field.launchAtLoginDescription"),ariaLabel:t("settings.aiworker.desktopNetwork.field.launchAtLoginAria")}):null,a?s.jsx(dt,{settingsItem:"sessions.desktop-mac-menu-bar",checked:J,onChange:ee,disabled:N||A,label:t("settings.aiworker.desktopNetwork.field.macMenuBar"),info:t("settings.aiworker.desktopNetwork.field.macMenuBarDescription"),ariaLabel:t("settings.aiworker.desktopNetwork.field.macMenuBarAria")}):null,S?s.jsx(dt,{settingsItem:"sessions.desktop-minimize-to-tray",checked:$,onChange:ve=>{ve!==$&&Oe()},disabled:k,label:t("settings.aiworker.desktopNetwork.field.minimizeToTray"),info:t("settings.aiworker.desktopNetwork.field.minimizeToTrayDescription"),ariaLabel:t("settings.aiworker.desktopNetwork.field.minimizeToTrayAria")}):null,U?s.jsx(dt,{settingsItem:"sessions.desktop-keep-awake",checked:_,onChange:ve=>{ve!==_&&Ve()},disabled:z,label:t("settings.aiworker.desktopNetwork.field.keepAwake"),info:t("settings.aiworker.desktopNetwork.field.keepAwakeDescription"),ariaLabel:t("settings.aiworker.desktopNetwork.field.keepAwakeAria")}):null]}):null,s.jsxs(qt,{settingsItem:"sessions.desktop-ui-password",label:s.jsx("label",{htmlFor:"desktop-ui-password",children:t("settings.aiworker.desktopPassword.field.password")}),info:t("settings.aiworker.desktopPassword.field.passwordDescription"),children:[s.jsx(He,{id:"desktop-ui-password",type:"password",className:"h-8 min-w-0 flex-1",value:y,onChange:ve=>_e(ve.target.value),placeholder:t(g&&!b?"settings.aiworker.desktopPassword.field.passwordSetPlaceholder":"settings.aiworker.desktopPassword.field.passwordPlaceholder"),disabled:N||A,required:i&&!Ce,"aria-invalid":Se}),g&&!b?s.jsx(V,{type:"button",variant:"ghost",size:"xs",onClick:Ue,disabled:N||A,className:"shrink-0 !font-normal",children:t("settings.aiworker.desktopPassword.actions.removePassword")}):null]}),s.jsx("div",{className:fs,children:s.jsx(dt,{settingsItem:"sessions.desktop-lan-access",checked:i,onChange:l,disabled:N||A,label:t("settings.aiworker.desktopNetwork.field.allowLanAccess"),info:t("settings.aiworker.desktopNetwork.field.allowLanAccessDescription"),description:s.jsxs(s.Fragment,{children:[s.jsx("span",{className:"block text-[var(--status-warning)]/85",children:t("settings.aiworker.desktopNetwork.field.warning")}),Se||ye?s.jsx("span",{className:"block text-[var(--status-warning)]/85",children:t("settings.aiworker.desktopNetwork.field.passwordRequiredWarning")}):null]}),ariaLabel:t("settings.aiworker.desktopNetwork.field.allowLanAccessAria")})}),te?s.jsx("div",{className:"typography-micro text-[var(--status-error)]",children:te}):null,ue?s.jsxs("div",{className:"typography-micro text-muted-foreground/80",children:[t(se&&!n?"settings.aiworker.desktopNetwork.hint.openAfterRestart":"settings.aiworker.desktopNetwork.hint.openNow"),s.jsx("span",{className:"font-mono text-foreground",children:ue})]}):null,s.jsx("div",{className:"flex justify-start py-1.5",children:s.jsx(V,{type:"button",size:"xs",onClick:Ge,disabled:fe,className:"shrink-0 !font-normal",children:t(A?"settings.common.actions.saving":"settings.aiworker.desktopNetwork.actions.saveAndRestart")})})]})}):null},cc=new Set(["shift","control","alt","meta"]),Rr=3,Af=3e3;function Lr(t,e=!1){const a=new Set;return t.altKey&&a.add("alt"),t.ctrlKey&&a.add("control"),t.metaKey&&a.add("meta"),t.shiftKey&&a.add("shift"),e&&a.add(t.key.toLowerCase()),a.size}function Tf(t){return t.action.customizable}function dl(t){if(Lr(t)>Rr)return null;const e=[];return(t.metaKey||t.ctrlKey)&&e.push("mod"),t.shiftKey&&e.push("shift"),t.altKey&&e.push("alt"),e.length>0?Ii(e.join("+")):null}function Ef(t){if(cc.has(t.key.toLowerCase())||Lr(t,!0)>Rr)return null;const e=cd(dd(t));if(!e)return null;const a=[];return(t.metaKey||t.ctrlKey)&&a.push("mod"),t.shiftKey&&a.push("shift"),t.altKey&&a.push("alt"),a.push(e),Ii(a.join("+"))}function Df(t){const e=t.key.toLowerCase();if(!cc.has(e)||Lr(t,!0)>Rr)return null;const a=[];return(t.metaKey||t.ctrlKey||e==="meta"||e==="control")&&a.push("mod"),(t.shiftKey||e==="shift")&&a.push("shift"),(t.altKey||e==="alt")&&a.push("alt"),a.length>0?Ii(a.join("+")):null}function ul(t){return t.chords.length>0?{...t,livePreview:null,settled:!0}:t}function Mf(t,e,a){if(e.repeat||e.isComposing)return t;if(a==="keyup")return{...t,livePreview:dl(e)};if(e.key==="Backspace")return{chords:t.chords.slice(0,-1),livePreview:null,settled:!1};const n=Ef(e);if(n){if(t.settled)return{chords:[n],livePreview:null,settled:!1};const r=t.chords.length<2?[...t.chords,n]:t.chords;return{chords:r,livePreview:null,settled:r.length===2}}return{...t,livePreview:dl(e)}}const Rf=t=>{const e=ut.c(117),{action:a,overrides:n,onSave:r,onOpenChange:i}=t,{t:l}=tt();let g;e[0]!==l?(g=re=>l(re.settingsLabelKey),e[0]=l,e[1]=g):g=e[1];const c=g;let y;e[2]!==c?(y=re=>re.action.customizable?c(re.action):Gn(re.action.defaultBinding),e[2]=c,e[3]=y):y=e[3];const p=y;let b;e[4]===Symbol.for("react.memo_cache_sentinel")?(b={chords:[],livePreview:null,settled:!1},e[4]=b):b=e[4];const[d,P]=o.useState(b),f=o.useRef(null);let C,v;e[5]!==a?(C=()=>{a&&(P({chords:[],livePreview:null,settled:!1}),f.current?.focus())},v=[a],e[5]=a,e[6]=C,e[7]=v):(C=e[6],v=e[7]),o.useEffect(C,v);const N=d.chords.length===1&&!d.settled;let m,A;e[8]!==N?(m=()=>{if(!N)return;const re=window.setTimeout(()=>P(ul),Af);return()=>window.clearTimeout(re)},A=[N],e[8]=N,e[9]=m,e[10]=A):(m=e[9],A=e[10]),o.useEffect(m,A);let R;e[11]!==d.chords?(R=Ii(d.chords.join(" ")),e[11]=d.chords,e[12]=R):R=e[12];const I=R;let j;e[13]!==a||e[14]!==I||e[15]!==n?(j=a&&I?od(a.id,I,n):[],e[13]=a,e[14]=I,e[15]=n,e[16]=j):j=e[16];const h=j;let w;e[17]!==h?(w=h.find(Lf),e[17]=h,e[18]=w):w=e[18];const F=w;let T,S,D,$,B,k,G,M,L,J,ee,U,le,_,H;if(e[19]!==a||e[20]!==c||e[21]!==I||e[22]!==p||e[23]!==h||e[24]!==i||e[25]!==r||e[26]!==F||e[27]!==d||e[28]!==l){const re=h.filter(Tf);B=re.find(Of);const ue=re.find(Ff),Ce=h.find(Kf);let Se;e[44]!==i?(Se=()=>i(!1),e[44]=i,e[45]=Se):Se=e[45],D=Se,$=()=>{d.settled||P(ul),!(!a||!I||F||B)&&(r(a.id,I,ue?.action.id),D())};let ye;e[46]!==a||e[47]!==d?(ye=(Re,Fe)=>{Re.preventDefault(),Re.stopPropagation();const Ke=!!(a&&"prefixStyle"in a&&a.prefixStyle);if(Fe==="keyup"&&Ke&&d.chords.length===0){const je=Df(Re);if(je){P({chords:[je],livePreview:null,settled:!0});return}}const Ee=Mf(d,{altKey:Re.altKey,code:Re.nativeEvent.code,ctrlKey:Re.ctrlKey,isComposing:Re.nativeEvent.isComposing,key:Re.key,metaKey:Re.metaKey,repeat:Re.repeat,shiftKey:Re.shiftKey},Fe);P(Ke&&Ee.chords.length>1?d:Ee)},e[46]=a,e[47]=d,e[48]=ye):ye=e[48];const fe=ye;S=Kt,_=a!==null,H=zf,T=zt,k="max-w-md",G=f,M=!1;let _e;e[49]!==a||e[50]!==c||e[51]!==l?(_e=a?l("settings.aiworker.keyboardShortcuts.dialog.title",{action:c(a)}):"",e[49]=a,e[50]=c,e[51]=l,e[52]=_e):_e=e[52];let Ue;e[53]!==_e?(Ue=s.jsx($t,{children:_e}),e[53]=_e,e[54]=Ue):Ue=e[54];let Ne;e[55]!==l?(Ne=l("settings.aiworker.keyboardShortcuts.dialog.instructions"),e[55]=l,e[56]=Ne):Ne=e[56];let Oe;e[57]!==Ne?(Oe=s.jsx(Vt,{children:Ne}),e[57]=Ne,e[58]=Oe):Oe=e[58],e[59]!==Ue||e[60]!==Oe?(L=s.jsxs(_t,{children:[Ue,Oe]}),e[59]=Ue,e[60]=Oe,e[61]=L):L=e[61];let Ve,Ge;e[62]!==fe?(Ve=Re=>fe(Re,"keydown"),Ge=Re=>fe(Re,"keyup"),e[62]=fe,e[63]=Ve,e[64]=Ge):(Ve=e[63],Ge=e[64]);let ve;e[65]===Symbol.for("react.memo_cache_sentinel")?(ve=()=>P(Uf),e[65]=ve):ve=e[65];let Z;e[66]!==d.chords?(Z=d.chords.map(_f),e[66]=d.chords,e[67]=Z):Z=e[67];let ne;e[68]!==d.livePreview?(ne=d.livePreview?s.jsx("kbd",{className:"rounded-md border border-dashed border-border bg-muted px-3 py-2 typography-ui-label font-mono text-muted-foreground",children:Gn(d.livePreview)}):null,e[68]=d.livePreview,e[69]=ne):ne=e[69];let be;e[70]!==d.chords.length||e[71]!==d.livePreview||e[72]!==l?(be=d.chords.length===0&&!d.livePreview?s.jsx("span",{className:"typography-ui-label text-muted-foreground",children:l("settings.aiworker.keyboardShortcuts.dialog.recording")}):null,e[70]=d.chords.length,e[71]=d.livePreview,e[72]=l,e[73]=be):be=e[73];let we;e[74]!==Z||e[75]!==ne||e[76]!==be?(we=s.jsxs("div",{className:"flex flex-wrap items-center justify-center gap-2",children:[Z,ne,be]}),e[74]=Z,e[75]=ne,e[76]=be,e[77]=we):we=e[77],e[78]!==Ve||e[79]!==Ge||e[80]!==we?(J=s.jsx("div",{className:"flex min-h-28 items-center justify-center rounded-lg border border-border bg-[var(--surface-elevated)] px-4 py-5 text-center outline-none focus-visible:ring-2 focus-visible:ring-ring",tabIndex:0,ref:f,onKeyDown:Ve,onKeyUp:Ge,onBlur:ve,children:we}),e[78]=Ve,e[79]=Ge,e[80]=we,e[81]=J):J=e[81],ee=d.settled&&F?s.jsx("p",{className:"typography-meta text-[var(--status-error)]",children:l("settings.aiworker.keyboardShortcuts.error.internalConflict")}):d.settled&&B?s.jsx("p",{className:"typography-meta text-[var(--status-error)]",children:l("settings.aiworker.keyboardShortcuts.error.prefixConflict",{action:c(B.action)})}):null,U=d.settled&&ue&&!F&&!B?s.jsx("p",{className:"typography-meta text-[var(--status-warning)]",children:l("settings.aiworker.keyboardShortcuts.error.exactConflict",{action:c(ue.action)})}):null,le=d.settled&&Ce&&!F&&!B?s.jsx("p",{className:"typography-meta text-[var(--status-warning)]",children:l("settings.aiworker.keyboardShortcuts.warning.contextualPrefix",{action:p(Ce)})}):null,e[19]=a,e[20]=c,e[21]=I,e[22]=p,e[23]=h,e[24]=i,e[25]=r,e[26]=F,e[27]=d,e[28]=l,e[29]=T,e[30]=S,e[31]=D,e[32]=$,e[33]=B,e[34]=k,e[35]=G,e[36]=M,e[37]=L,e[38]=J,e[39]=ee,e[40]=U,e[41]=le,e[42]=_,e[43]=H}else T=e[29],S=e[30],D=e[31],$=e[32],B=e[33],k=e[34],G=e[35],M=e[36],L=e[37],J=e[38],ee=e[39],U=e[40],le=e[41],_=e[42],H=e[43];let z;e[82]!==I||e[83]!==d.settled||e[84]!==l?(z=d.settled&&I&&ld(I)?s.jsx("p",{className:"typography-meta text-[var(--status-warning)]",children:l("settings.aiworker.keyboardShortcuts.warning.riskyBrowserShortcut")}):null,e[82]=I,e[83]=d.settled,e[84]=l,e[85]=z):z=e[85];let K;e[86]!==l?(K=l("settings.common.actions.cancel"),e[86]=l,e[87]=K):K=e[87];let te;e[88]!==D||e[89]!==K?(te=s.jsx(V,{type:"button",variant:"ghost",size:"sm",onClick:D,children:K}),e[88]=D,e[89]=K,e[90]=te):te=e[90];const Y=!I||d.settled&&(!!F||!!B);let ae;e[91]!==l?(ae=l("settings.aiworker.keyboardShortcuts.actions.confirm"),e[91]=l,e[92]=ae):ae=e[92];let ge;e[93]!==$||e[94]!==Y||e[95]!==ae?(ge=s.jsx(V,{type:"button",size:"sm",disabled:Y,onClick:$,children:ae}),e[93]=$,e[94]=Y,e[95]=ae,e[96]=ge):ge=e[96];let de;e[97]!==te||e[98]!==ge?(de=s.jsxs(ts,{children:[te,ge]}),e[97]=te,e[98]=ge,e[99]=de):de=e[99];let he;e[100]!==T||e[101]!==k||e[102]!==G||e[103]!==M||e[104]!==L||e[105]!==J||e[106]!==ee||e[107]!==U||e[108]!==le||e[109]!==z||e[110]!==de?(he=s.jsxs(T,{className:k,initialFocus:G,showCloseButton:M,children:[L,J,ee,U,le,z,de]}),e[100]=T,e[101]=k,e[102]=G,e[103]=M,e[104]=L,e[105]=J,e[106]=ee,e[107]=U,e[108]=le,e[109]=z,e[110]=de,e[111]=he):he=e[111];let se;return e[112]!==S||e[113]!==_||e[114]!==H||e[115]!==he?(se=s.jsx(S,{open:_,onOpenChange:H,children:he}),e[112]=S,e[113]=_,e[114]=H,e[115]=he,e[116]=se):se=e[116],se};function Lf(t){return!t.action.customizable&&t.kind!=="contextual-prefix"}function Of(t){return t.kind==="prefix"}function Ff(t){return t.kind==="exact"}function Kf(t){return t.kind==="contextual-prefix"}function zf(t,e){t||e.cancel()}function Uf(t){return{...t,livePreview:null}}function _f(t,e){return s.jsx("kbd",{className:"rounded-md border border-border bg-muted px-3 py-2 typography-ui-label font-mono text-foreground",children:Gn(t)},`${t}-${e}`)}const $f=["session","models","panels","navigation","application"],Vf=()=>{const t=ut.c(24),{t:e}=tt(),a=ie(Bf),n=ie(Hf),r=ie(Gf),i=ie(Wf),[l,g]=o.useState(null);let c;if(t[0]===Symbol.for("react.memo_cache_sentinel")){const I=ud();c=cs()?I.filter(qf):I,t[0]=c}else c=t[0];const y=c,p=Jf;let b;t[1]!==n||t[2]!==a?(b=(I,j,h)=>{const w={...a,[I]:j};h&&(w[h]=qi),n(I,j),h&&n(h,qi),p(w)},t[1]=n,t[2]=a,t[3]=b):b=t[3];const d=b;let P;t[4]!==r||t[5]!==a?(P=I=>{const j={...a};delete j[I],r(I),p(j)},t[4]=r,t[5]=a,t[6]=P):P=t[6];const f=P;let C;t[7]!==a||t[8]!==e?(C=I=>{const j="prefixStyle"in I&&I.prefixStyle,h=j?pd(I.id,a):Tl(I.id,a),w=Gn(h,e("settings.aiworker.keyboardShortcuts.unassigned"));if(!j||!h||h===qi)return w;const F=I.id==="switch_session_tab"?e("settings.aiworker.keyboardShortcuts.action.switch_session_tab.suffix"):e("settings.aiworker.keyboardShortcuts.action.switch_context_surface.suffix");return`${w}${F}`},t[7]=a,t[8]=e,t[9]=C):C=t[9];const v=C;let N;t[10]!==i||t[11]!==f||t[12]!==v||t[13]!==a||t[14]!==e?(N=$f.map((I,j)=>{const h=y.filter(w=>w.category===I);return h.length===0?null:s.jsx(ze,{settingsItem:j===0?"shortcuts.keyboard-shortcuts":void 0,title:e(`settings.aiworker.keyboardShortcuts.category.${I}`),divider:j!==0,info:j===0?e("settings.aiworker.keyboardShortcuts.tooltip"):void 0,headerAction:j===0?s.jsx(V,{type:"button",variant:"outline",size:"xs",className:"!font-normal",onClick:()=>{i(),p({})},children:e("settings.aiworker.keyboardShortcuts.actions.resetAll")}):void 0,children:s.jsx("div",{className:"space-y-2",children:h.map(w=>s.jsxs(Rt,{label:e(w.settingsLabelKey),children:[s.jsx("kbd",{className:"min-w-32 rounded-md border border-border bg-muted px-2 py-1 text-center typography-meta font-mono text-foreground",children:v(w)}),s.jsx(V,{type:"button",variant:"secondary",size:"xs",className:"!font-normal",onClick:()=>g(w),children:e("settings.aiworker.keyboardShortcuts.actions.edit")}),w.id in a?s.jsx(V,{type:"button",variant:"ghost",size:"xs",className:"!font-normal",onClick:()=>f(w.id),children:e("settings.common.actions.reset")}):null]},w.id))})},I)}),t[10]=i,t[11]=f,t[12]=v,t[13]=a,t[14]=e,t[15]=N):N=t[15];let m;t[16]===Symbol.for("react.memo_cache_sentinel")?(m=I=>{I||g(null)},t[16]=m):m=t[16];let A;t[17]!==l||t[18]!==d||t[19]!==a?(A=s.jsx(Rf,{action:l,overrides:a,onSave:d,onOpenChange:m}),t[17]=l,t[18]=d,t[19]=a,t[20]=A):A=t[20];let R;return t[21]!==N||t[22]!==A?(R=s.jsxs(s.Fragment,{children:[N,A]}),t[21]=N,t[22]=A,t[23]=R):R=t[23],R};function Bf(t){return t.shortcutOverrides}function Hf(t){return t.setShortcutOverride}function Gf(t){return t.clearShortcutOverride}function Wf(t){return t.resetAllShortcutOverrides}function qf(t){return t.id!=="toggle_prompt_navigator"}function Jf(t){gt({shortcutOverrides:t})}const dc=()=>{const t=ut.c(2),[e,a]=o.useState(0);let n,r;return t[0]===Symbol.for("react.memo_cache_sentinel")?(n=()=>Ml(()=>a(rx)),r=[],t[0]=n,t[1]=r):(n=t[0],r=t[1]),o.useEffect(n,r),e},Qf=t=>{const e=ut.c(83),{section:a}=t,{t:n}=tt(),{isMobile:r}=wa(),i=dc();let l;e[0]!==r?(l=r&&Bn(),e[0]=r,e[1]=l):l=e[1];const g=l;let c;e[2]===Symbol.for("react.memo_cache_sentinel")?(c=cs(),e[2]=c):c=e[2];const y=c;let p;e[3]===Symbol.for("react.memo_cache_sentinel")?(p=as()&&Va(),e[3]=p):p=e[3];const b=p;if(!a){let le;e[4]===Symbol.for("react.memo_cache_sentinel")?(le=s.jsx(Pi,{}),e[4]=le):le=e[4];let _;e[5]!==i?(_=s.jsx(nc,{},i),e[5]=i,e[6]=_):_=e[6];let H,z,K,te,Y,ae;e[7]===Symbol.for("react.memo_cache_sentinel")?(K=b&&s.jsx(lc,{}),te=!y&&s.jsx(rc,{}),Y=!y&&s.jsx(oc,{}),ae=s.jsx(ec,{}),H=s.jsx(sc,{}),z=Bn()&&!as()&&!y&&!Ol()&&s.jsx(tc,{}),e[7]=H,e[8]=z,e[9]=K,e[10]=te,e[11]=Y,e[12]=ae):(H=e[7],z=e[8],K=e[9],te=e[10],Y=e[11],ae=e[12]);let ge;e[13]!==g?(ge=g&&s.jsx(Ul,{}),e[13]=g,e[14]=ge):ge=e[14];let de;return e[15]!==ge||e[16]!==_?(de=s.jsxs(es,{showSaveStatus:!0,className:"openchamber-page-body space-y-3 sm:space-y-6",children:[le,_,K,te,Y,ae,H,z,ge]}),e[15]=ge,e[16]=_,e[17]=de):de=e[17],de}let d;e[18]!==i||e[19]!==a?(d=()=>{switch(a){case"general":return s.jsx(Zf,{});case"visual":return s.jsx(Xf,{});case"chat":return s.jsx(ex,{});case"sessions":return s.jsx(tx,{runtimeEndpointEpoch:i});case"shortcuts":return s.jsx(Yf,{});case"git":return s.jsx(sx,{});case"notifications":return s.jsx(nx,{});case"voice":return s.jsx(ax,{});case"tunnel":return s.jsx(ix,{});default:return null}},e[18]=i,e[19]=a,e[20]=d):d=e[20];const P=d;let f;e[21]!==n?(f=n("settings.page.general.title"),e[21]=n,e[22]=f):f=e[22];let C;e[23]!==n?(C=n("settings.page.appearance.title"),e[23]=n,e[24]=C):C=e[24];let v;e[25]!==n?(v=n("settings.page.chat.title"),e[25]=n,e[26]=v):v=e[26];let N;e[27]!==n?(N=n("settings.page.sessions.title"),e[27]=n,e[28]=N):N=e[28];let m;e[29]!==n?(m=n("settings.page.shortcuts.title"),e[29]=n,e[30]=m):m=e[30];let A;e[31]!==n?(A=n("settings.page.git.title"),e[31]=n,e[32]=A):A=e[32];let R;e[33]!==n?(R=n("settings.page.git.title"),e[33]=n,e[34]=R):R=e[34];let I;e[35]!==n?(I=n("settings.page.notifications.title"),e[35]=n,e[36]=I):I=e[36];let j;e[37]!==n?(j=n("settings.page.voice.title"),e[37]=n,e[38]=j):j=e[38];let h;e[39]!==n?(h=n("settings.page.tunnel.title"),e[39]=n,e[40]=h):h=e[40];let w;e[41]!==A||e[42]!==R||e[43]!==I||e[44]!==j||e[45]!==h||e[46]!==f||e[47]!==C||e[48]!==v||e[49]!==N||e[50]!==m?(w={general:f,visual:C,chat:v,sessions:N,shortcuts:m,git:A,github:R,notifications:I,voice:j,tunnel:h},e[41]=A,e[42]=R,e[43]=I,e[44]=j,e[45]=h,e[46]=f,e[47]=C,e[48]=v,e[49]=N,e[50]=m,e[51]=w):w=e[51];const F=w[a];let T;e[52]!==n?(T=n("settings.page.general.description"),e[52]=n,e[53]=T):T=e[53];let S;e[54]!==n?(S=n("settings.page.appearance.description"),e[54]=n,e[55]=S):S=e[55];let D;e[56]!==n?(D=n("settings.page.chat.description"),e[56]=n,e[57]=D):D=e[57];let $;e[58]!==n?($=n("settings.page.sessions.description"),e[58]=n,e[59]=$):$=e[59];let B;e[60]!==n?(B=n("settings.page.shortcuts.description"),e[60]=n,e[61]=B):B=e[61];let k;e[62]!==n?(k=n("settings.page.notifications.description"),e[62]=n,e[63]=k):k=e[63];let G;e[64]!==n?(G=n("settings.page.voice.description"),e[64]=n,e[65]=G):G=e[65];let M;e[66]!==n?(M=n("settings.page.tunnel.description"),e[66]=n,e[67]=M):M=e[67];let L;e[68]!==T||e[69]!==S||e[70]!==D||e[71]!==$||e[72]!==B||e[73]!==k||e[74]!==G||e[75]!==M?(L={general:T,visual:S,chat:D,sessions:$,shortcuts:B,git:void 0,github:void 0,notifications:k,voice:G,tunnel:M},e[68]=T,e[69]=S,e[70]=D,e[71]=$,e[72]=B,e[73]=k,e[74]=G,e[75]=M,e[76]=L):L=e[76];const J=L[a];let ee;e[77]!==P?(ee=P(),e[77]=P,e[78]=ee):ee=e[78];let U;return e[79]!==J||e[80]!==F||e[81]!==ee?(U=s.jsx(es,{title:F,description:J,showSaveStatus:!0,className:"openchamber-page-body",children:ee}),e[79]=J,e[80]=F,e[81]=ee,e[82]=U):U=e[82],U},Yf=()=>{const t=ut.c(1);let e;return t[0]===Symbol.for("react.memo_cache_sentinel")?(e=s.jsx(Vf,{}),t[0]=e):e=t[0],e},Zf=()=>{const t=ut.c(10);let e;t[0]===Symbol.for("react.memo_cache_sentinel")?(e=cs(),t[0]=e):e=t[0];const a=e;dc();let n;t[1]===Symbol.for("react.memo_cache_sentinel")?(n=as()&&Va(),t[1]=n):n=t[1];const r=n;let i;t[2]===Symbol.for("react.memo_cache_sentinel")?(i=Bn()&&!as()&&!a&&!Ol(),t[2]=i):i=t[2];const l=i;let g,c,y,p,b;t[3]===Symbol.for("react.memo_cache_sentinel")?(g=r&&s.jsx(lc,{}),c=l&&s.jsx(tc,{}),y=s.jsx(sc,{}),p=!a&&s.jsx(rc,{}),b=!a&&s.jsx(oc,{}),t[3]=g,t[4]=c,t[5]=y,t[6]=p,t[7]=b):(g=t[3],c=t[4],y=t[5],p=t[6],b=t[7]);let d;t[8]===Symbol.for("react.memo_cache_sentinel")?(d=a?[]:["sessionTabs"],t[8]=d):d=t[8];let P;return t[9]===Symbol.for("react.memo_cache_sentinel")?(P=s.jsxs(s.Fragment,{children:[g,c,y,p,b,s.jsx(Pi,{visibleSettings:["fileEditorKeymap",...d,"autoSaveEnabled",...a?[]:["terminalQuickKeys"],...a?[]:["terminalShell"],...a?[]:["terminalLoginShell"],"messageTransport","reportUsage"]})]}),t[9]=P):P=t[9],P},Xf=()=>{const t=ut.c(2);let e;t[0]===Symbol.for("react.memo_cache_sentinel")?(e=cs(),t[0]=e):e=t[0];const a=e;let n;return t[1]===Symbol.for("react.memo_cache_sentinel")?(n=s.jsx(Pi,{visibleSettings:["theme","windowControlsPosition","pwaInstallName","pwaOrientation","mobileKeyboardMode","timeFormat",...a?[]:["weekStart"],"fontSize","terminalFontSize","editorFontSize","spacing","scrollbars","inputBarOffset"]}),t[1]=n):n=t[1],n},ex=()=>{const t=ut.c(2);let e;t[0]===Symbol.for("react.memo_cache_sentinel")?(e=cs(),t[0]=e):e=t[0];const a=e;let n;return t[1]===Symbol.for("react.memo_cache_sentinel")?(n=s.jsx(Pi,{visibleSettings:["sessionGoal","sessionAssist","chatRenderMode","activityRenderMode","userMessageRendering","mermaidRendering","reasoning","showToolFileIcons","showTurnChangedFiles","expandedTools","collapsibleUserMessages","stickyUserHeader",...a?[]:["promptNavigatorEnabled"],"wideChatLayout","codeBlockLineWrap","splitAssistantMessageActions","subagentReadOnlyBanner","diffLayout","inputHistoryScope","inputHistoryLimit","dotfiles","fileViewerPreview","followUpBehavior","persistDraft","inputSpellcheck","largeTextPaste","enterToSend"]}),t[1]=n):n=t[1],n},tx=t=>{const e=ut.c(5),{runtimeEndpointEpoch:a}=t;let n;e[0]!==a?(n=s.jsx(nc,{},a),e[0]=a,e[1]=n):n=e[1];let r;e[2]===Symbol.for("react.memo_cache_sentinel")?(r=s.jsx(ec,{}),e[2]=r):r=e[2];let i;return e[3]!==n?(i=s.jsxs(s.Fragment,{children:[n,r]}),e[3]=n,e[4]=i):i=e[4],i},sx=()=>{const t=ut.c(1);let e;return t[0]===Symbol.for("react.memo_cache_sentinel")?(e=s.jsx(Xl,{}),t[0]=e):e=t[0],e},nx=()=>{const t=ut.c(1);let e;return t[0]===Symbol.for("react.memo_cache_sentinel")?(e=s.jsx(Xh,{}),t[0]=e):e=t[0],e},ax=()=>{const t=ut.c(1);if(cs())return null;let e;return t[0]===Symbol.for("react.memo_cache_sentinel")?(e=s.jsx(df,{}),t[0]=e):e=t[0],e},ix=()=>{const t=ut.c(1);if(cs())return null;let e;return t[0]===Symbol.for("react.memo_cache_sentinel")?(e=s.jsx(wf,{}),t[0]=e):e=t[0],e};function rx(t){return t+1}const ox=t=>{const e=ut.c(85),{className:a}=t,{t:n}=tt(),r=Vn(El),i=Vn(lx),l=ie(cx),g=ie(dx),[c,y]=$e.useState(!1),[p,b]=$e.useState(!1),d=r>0;let P;e[0]!==n?(P=async()=>{try{const Se=await md({message:n("settings.view.pendingRestart.applying")});if(Se.requiresManualRestart){E.warning(n("settings.view.pendingRestart.manualRestartRequired"));return}Se.ok&&E.success(n("settings.view.pendingRestart.applied"))}catch(Se){const ye=Se,fe=ye instanceof Error&&ye.message?ye.message:n("settings.view.pendingRestart.applyFailed");E.error(fe)}},e[0]=n,e[1]=P):P=e[1];const f=P;let C;e[2]!==n?(C=async()=>{try{await Il({message:n("settings.view.pendingRestart.applying"),mode:"projects",scopes:["all"]}),Vn.getState().clear()}catch{}},e[2]=n,e[3]=C):C=e[3];const v=C;let N;e[4]!==p||e[5]!==f||e[6]!==g?(N=()=>{p&&g(!1),y(!1),b(!1),f()},e[4]=p,e[5]=f,e[6]=g,e[7]=N):N=e[7];const m=N;let A;e[8]!==d||e[9]!==f||e[10]!==v||e[11]!==l?(A=()=>{if(!d){v();return}if(l){b(!1),y(!0);return}f()},e[8]=d,e[9]=f,e[10]=v,e[11]=l,e[12]=A):A=e[12];const R=A;let I;e[13]!==d||e[14]!==i||e[15]!==n?(I=n(d?i?"settings.view.pendingRestart.applying":"settings.view.actions.applyAndRestartOpenCode":"settings.view.actions.reloadOpenCode"),e[13]=d,e[14]=i,e[15]=n,e[16]=I):I=e[16];const j=I;let h;e[17]!==d||e[18]!==r||e[19]!==n?(h=d?r===1?n("settings.view.actions.applyAndRestartOpenCodeTooltipSingle"):n("settings.view.actions.applyAndRestartOpenCodeTooltipPlural",{count:r}):n("settings.view.actions.reloadOpenCodeTooltip"),e[17]=d,e[18]=r,e[19]=n,e[20]=h):h=e[20];const w=h,F=d?"bg-primary text-primary-foreground typography-ui-label font-semibold hover:bg-primary/90":"text-sm font-semibold text-sidebar-foreground/90 hover:text-sidebar-foreground hover:bg-interactive-hover",T=i&&"opacity-80";let S;e[21]!==a||e[22]!==F||e[23]!==T?(S=xe("flex w-full items-center gap-2 rounded-md overflow-hidden whitespace-nowrap","h-11 px-3 sm:h-8 sm:px-2","focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-primary/50",F,T,a),e[21]=a,e[22]=F,e[23]=T,e[24]=S):S=e[24];let D;e[25]!==d||e[26]!==r?(D=d?s.jsx("span",{className:xe("inline-flex h-5 min-w-5 shrink-0 items-center justify-center rounded-full px-1.5","bg-background text-foreground typography-micro font-semibold tabular-nums"),"aria-hidden":"true",children:r}):s.jsx(O,{name:"restart",className:"h-4 w-4 shrink-0"}),e[25]=d,e[26]=r,e[27]=D):D=e[27];let $;e[28]!==j?($=s.jsx("span",{className:"truncate",children:j}),e[28]=j,e[29]=$):$=e[29];let B;e[30]!==R||e[31]!==i||e[32]!==D||e[33]!==$||e[34]!==S||e[35]!==w?(B=s.jsxs("button",{type:"button",disabled:i,title:w,"aria-label":w,onClick:R,className:S,children:[D,$]}),e[30]=R,e[31]=i,e[32]=D,e[33]=$,e[34]=S,e[35]=w,e[36]=B):B=e[36];let k;e[37]===Symbol.for("react.memo_cache_sentinel")?(k=Se=>{y(Se),Se||b(!1)},e[37]=k):k=e[37];let G;e[38]!==n?(G=n("settings.view.pendingRestart.confirm.title"),e[38]=n,e[39]=G):G=e[39];let M;e[40]!==G?(M=s.jsx($t,{children:G}),e[40]=G,e[41]=M):M=e[41];let L;e[42]!==n?(L=n("settings.view.pendingRestart.confirm.description"),e[42]=n,e[43]=L):L=e[43];let J;e[44]!==L?(J=s.jsx(Vt,{children:L}),e[44]=L,e[45]=J):J=e[45];let ee;e[46]!==M||e[47]!==J?(ee=s.jsxs(_t,{children:[M,J]}),e[46]=M,e[47]=J,e[48]=ee):ee=e[48];let U;e[49]===Symbol.for("react.memo_cache_sentinel")?(U={width:"40%"},e[49]=U):U=e[49];let le;e[50]===Symbol.for("react.memo_cache_sentinel")?(le=()=>y(!1),e[50]=le):le=e[50];let _;e[51]!==n?(_=n("settings.view.pendingRestart.confirm.cancel"),e[51]=n,e[52]=_):_=e[52];let H;e[53]!==_?(H=s.jsx("div",{className:"min-w-0 shrink-0",style:U,children:s.jsx(V,{type:"button",variant:"outline",className:"h-9 w-full normal-case",onClick:le,children:_})}),e[53]=_,e[54]=H):H=e[54];let z;e[55]===Symbol.for("react.memo_cache_sentinel")?(z={width:"40%"},e[55]=z):z=e[55];let K;e[56]!==n?(K=n("settings.view.actions.applyAndRestartOpenCode"),e[56]=n,e[57]=K):K=e[57];let te;e[58]!==m||e[59]!==K?(te=s.jsx("div",{className:"min-w-0 shrink-0",style:z,children:s.jsx(V,{type:"button",variant:"default",className:"h-9 w-full normal-case",onClick:m,children:K})}),e[58]=m,e[59]=K,e[60]=te):te=e[60];let Y;e[61]!==H||e[62]!==te?(Y=s.jsxs("div",{className:"flex w-full items-stretch justify-center gap-3",children:[H,te]}),e[61]=H,e[62]=te,e[63]=Y):Y=e[63];let ae;e[64]===Symbol.for("react.memo_cache_sentinel")?(ae=()=>b(ux),e[64]=ae):ae=e[64];let ge;e[65]!==p?(ge=p?s.jsx(O,{name:"checkbox",className:"h-4 w-4 text-primary"}):s.jsx(O,{name:"checkbox-blank",className:"h-4 w-4"}),e[65]=p,e[66]=ge):ge=e[66];let de;e[67]!==n?(de=n("settings.view.pendingRestart.confirm.dontShowAgain"),e[67]=n,e[68]=de):de=e[68];let he;e[69]!==p||e[70]!==ge||e[71]!==de?(he=s.jsxs("button",{type:"button",onClick:ae,className:"inline-flex items-center justify-center gap-1.5 typography-ui-label text-muted-foreground transition-colors hover:text-foreground focus-visible:outline-none focus-visible:ring-1 focus-visible:ring-primary/50","aria-pressed":p,children:[ge,de]}),e[69]=p,e[70]=ge,e[71]=de,e[72]=he):he=e[72];let se;e[73]!==Y||e[74]!==he?(se=s.jsxs("div",{className:"flex w-full flex-col items-center gap-3",children:[Y,he]}),e[73]=Y,e[74]=he,e[75]=se):se=e[75];let re;e[76]!==ee||e[77]!==se?(re=s.jsxs(zt,{showCloseButton:!1,className:"max-w-md gap-5",children:[ee,se]}),e[76]=ee,e[77]=se,e[78]=re):re=e[78];let ue;e[79]!==c||e[80]!==re?(ue=s.jsx(Kt,{open:c,onOpenChange:k,children:re}),e[79]=c,e[80]=re,e[81]=ue):ue=e[81];let Ce;return e[82]!==B||e[83]!==ue?(Ce=s.jsxs(s.Fragment,{children:[B,ue]}),e[82]=B,e[83]=ue,e[84]=Ce):Ce=e[84],Ce};function lx(t){return t.isApplying}function cx(t){return t.showOpenCodeRestartConfirm}function dx(t){return t.setShowOpenCodeRestartConfirm}function ux(t){return!t}const px=[{id:"chat.activity-default",page:"chat",titleKey:"settings.aiworker.visual.section.activityDefault",keywords:["activity","collapsed","expanded","live","tools","history"]},{id:"appearance.language",page:"appearance",titleKey:"settings.appearance.language.label",descriptionKey:"settings.appearance.language.description",keywords:["locale","translation","ui language"]},{id:"appearance.time-format",page:"appearance",titleKey:"settings.aiworker.visual.field.timeFormat",keywords:["clock","12h","24h"]},{id:"appearance.week-start",page:"appearance",titleKey:"settings.aiworker.visual.field.weekStartsOn",keywords:["calendar","monday","sunday"]},{id:"appearance.light-theme",page:"appearance",titleKey:"settings.aiworker.visual.field.lightTheme",keywords:["theme","color","light mode"],isAvailable:t=>!t.isVSCode},{id:"appearance.dark-theme",page:"appearance",titleKey:"settings.aiworker.visual.field.darkTheme",keywords:["theme","color","dark mode"],isAvailable:t=>!t.isVSCode},{id:"appearance.dock-badge",page:"appearance",titleKey:"settings.aiworker.visual.field.dockBadge",descriptionKey:"settings.aiworker.visual.field.dockBadgeHint",keywords:["dock","badge","unread","unseen","counter","count","notification","macos"],isAvailable:t=>t.isMac},{id:"appearance.scrollbars",page:"appearance",titleKey:"settings.aiworker.visual.field.alwaysShowScrollbars",descriptionKey:"settings.aiworker.visual.field.alwaysShowScrollbarsHint",keywords:["scrollbar","scrollbars","scroll","mouse","wheel","accessibility","always visible"]},{id:"appearance.pwa-install-name",page:"appearance",titleKey:"settings.aiworker.visual.field.installAppName",descriptionKey:"settings.aiworker.visual.field.installAppNameHint",keywords:["pwa","installed app"],isAvailable:t=>t.isWeb&&!t.isDesktop&&!t.isVSCode},{id:"appearance.pwa-orientation",page:"appearance",titleKey:"settings.aiworker.visual.field.installOrientation",descriptionKey:"settings.aiworker.visual.field.installOrientationHint",keywords:["pwa","portrait","landscape"],isAvailable:t=>t.isWeb&&!t.isDesktop&&!t.isVSCode},{id:"appearance.mobile-keyboard-mode",page:"appearance",titleKey:"settings.aiworker.visual.field.mobileKeyboardMode",descriptionKey:"settings.aiworker.visual.field.mobileKeyboardModeHint",keywords:["mobile","keyboard","resize"],isAvailable:t=>t.isMobile&&t.isWeb&&!t.isDesktop&&!t.isVSCode},{id:"appearance.interface-font-size",page:"appearance",titleKey:"settings.aiworker.visual.field.interfaceFontSize",keywords:["font","text size","ui scale"],isAvailable:t=>!t.isMobile},{id:"appearance.terminal-font-size",page:"appearance",titleKey:"settings.aiworker.visual.field.terminalFontSize",keywords:["terminal","font","text size"]},{id:"appearance.terminal-shell",page:"general",titleKey:"settings.aiworker.visual.field.terminalShell",descriptionKey:"settings.aiworker.visual.field.terminalShellHint",keywords:["terminal","shell","bash","zsh","fish","pwsh","powershell"],isAvailable:t=>!t.isVSCode},{id:"appearance.editor-font-size",page:"appearance",titleKey:"settings.aiworker.visual.field.editorFontSize",keywords:["editor","font","text size","code"]},{id:"appearance.spacing-density",page:"appearance",titleKey:"settings.aiworker.visual.field.spacingDensity",keywords:["density","compact","comfortable","spacing"]},{id:"appearance.input-bar-offset",page:"appearance",titleKey:"settings.aiworker.visual.field.inputBarOffset",descriptionKey:"settings.aiworker.visual.field.inputBarOffsetTooltip",keywords:["input","home bar","offset"],isAvailable:t=>t.isMobile},{id:"appearance.auto-save-enabled",page:"general",titleKey:"settings.aiworker.visual.field.autoSaveEnabled",descriptionKey:"settings.aiworker.visual.field.autoSaveEnabledInfo",keywords:["editor","autosave","auto-save","files","save"]},{id:"appearance.file-editor-keymap",page:"general",titleKey:"settings.aiworker.visual.field.fileEditorKeymap",keywords:["editor","vim","keymap"]},{id:"appearance.session-tabs",page:"general",titleKey:"settings.aiworker.visual.field.sessionTabsGroup",descriptionKey:"settings.aiworker.visual.field.sessionTabsInfo",keywords:["session","tabs","header","working set"],isAvailable:t=>!t.isMobile&&!t.isVSCode},{id:"appearance.terminal-quick-keys",page:"general",titleKey:"settings.aiworker.visual.field.terminalQuickKeys",descriptionKey:"settings.aiworker.visual.field.terminalQuickKeysTooltip",keywords:["terminal","keyboard","esc","ctrl","arrows"],isAvailable:t=>!t.isMobile&&!t.isVSCode},{id:"appearance.usage-reports",page:"general",titleKey:"settings.aiworker.visual.field.sendAnonymousUsageReports",descriptionKey:"settings.aiworker.visual.field.sendAnonymousUsageReportsHint",keywords:["telemetry","analytics"]},{id:"general.app-links",page:"general",titleKey:"settings.aiworker.appLinks.title",descriptionKey:"settings.aiworker.appLinks.info",keywords:["security","app link","deep link","scheme","protocol","obsidian","notion"]},{id:"chat.render-mode",page:"chat",titleKey:"settings.aiworker.visual.section.chatRenderMode",keywords:["messages","conversation","rendering"]},{id:"chat.message-transport",page:"general",titleKey:"settings.aiworker.visual.section.messageStreamTransport",keywords:["streaming","sse","websocket"]},{id:"chat.session-recap",page:"chat",titleKey:"settings.aiworker.visual.field.sessionRecap",keywords:["recap","assist","small model","summary"]},{id:"chat.session-assistance",page:"chat",titleKey:"settings.aiworker.visual.section.sessionAssistance",keywords:["recap","suggestion","subagent"]},{id:"chat.session-suggestion",page:"chat",titleKey:"settings.aiworker.visual.field.sessionSuggestion",keywords:["suggestion","assist","small model","follow up"]},{id:"chat.session-goal",page:"chat",titleKey:"settings.aiworker.visual.field.sessionGoal",keywords:["goal","objective","auto continue","small model"],isAvailable:t=>!t.isVSCode},{id:"chat.session-goal-budget",page:"chat",titleKey:"settings.aiworker.visual.goal.budgetLabel",keywords:["goal","budget","tokens","limit"],isAvailable:t=>!t.isVSCode},{id:"chat.reasoning-traces",page:"chat",titleKey:"settings.aiworker.visual.field.showReasoningTraces",keywords:["thinking","reasoning"]},{id:"chat.reasoning",page:"chat",titleKey:"settings.aiworker.visual.section.reasoning",keywords:["thinking","traces"]},{id:"chat.streaming",page:"chat",titleKey:"settings.aiworker.visual.section.streaming",keywords:["stream","scroll"]},{id:"chat.streaming-auto-follow",page:"chat",titleKey:"settings.aiworker.visual.field.streamingAutoFollow",descriptionKey:"settings.aiworker.visual.field.streamingAutoFollowInfo",keywords:["autoscroll","auto-scroll","follow","stick to bottom","streaming"]},{id:"chat.sticky-user-header",page:"chat",titleKey:"settings.aiworker.visual.field.stickyUserHeader",keywords:["messages","header"]},{id:"chat.prompt-navigator",page:"chat",titleKey:"settings.aiworker.visual.field.promptNavigatorEnabled",keywords:["prompt","navigator","navigation","timeline","scroll"],isAvailable:t=>!t.isVSCode},{id:"chat.collapsible-user-messages",page:"chat",titleKey:"settings.aiworker.visual.field.collapsibleUserMessages",keywords:["collapse","expand","clamp","long messages","user messages"]},{id:"chat.wide-layout",page:"chat",titleKey:"settings.aiworker.visual.field.wideChatLayout",keywords:["layout","wide","messages"]},{id:"chat.message-appearance",page:"chat",titleKey:"settings.aiworker.visual.section.messageAppearance",keywords:["layout","messages","appearance"]},{id:"chat.code-block-line-wrap",page:"chat",titleKey:"settings.aiworker.visual.field.codeBlockLineWrap",keywords:["code","wrap","line wrap","markdown"]},{id:"chat.inline-assistant-actions",page:"chat",titleKey:"settings.aiworker.visual.field.showSplitAssistantMessageActions",descriptionKey:"settings.aiworker.visual.field.showSplitAssistantMessageActionsTooltip",keywords:["copy","save image","read aloud"]},{id:"chat.draft-starters-visible",page:"chat",titleKey:"settings.aiworker.visual.field.draftStartersVisible",keywords:["starter","starters","new session","welcome","suggestions"]},{id:"chat.subagent-read-only-banner",page:"chat",titleKey:"settings.aiworker.visual.field.allowPromptingSubagentSessions",keywords:["subagent","read only","prompt","banner"]},{id:"chat.tool-file-icons",page:"chat",titleKey:"settings.aiworker.visual.field.showToolFileIcons",keywords:["tools","files","icons"]},{id:"chat.tools-and-files",page:"chat",titleKey:"settings.aiworker.visual.section.toolsAndFiles",keywords:["tools","files","dotfiles"]},{id:"chat.changed-files",page:"chat",titleKey:"settings.aiworker.visual.field.showTurnChangedFiles",keywords:["changed files","turns"]},{id:"chat.dotfiles",page:"chat",titleKey:"settings.aiworker.visual.field.showDotfiles",keywords:["hidden files"],isAvailable:t=>!t.isVSCode},{id:"chat.follow-up-behavior",page:"chat",titleKey:"settings.aiworker.visual.section.followUpBehavior",descriptionKey:"settings.aiworker.visual.field.followUpBehaviorDescription",keywords:["follow up","queue","steer","send immediately"]},{id:"chat.input-history-scope",page:"chat",titleKey:"settings.aiworker.visual.field.inputHistoryScope",descriptionKey:"settings.aiworker.visual.field.inputHistoryScopeDescription",keywords:["input history","composer history","global","session","reuse"]},{id:"chat.input-history-limit",page:"chat",titleKey:"settings.aiworker.visual.field.inputHistoryLimit",descriptionKey:"settings.aiworker.visual.field.inputHistoryLimitDescription",keywords:["history limit","prompt recall","remember prompts","composer history","submitted prompts","trim history"]},{id:"chat.persist-drafts",page:"chat",titleKey:"settings.aiworker.visual.field.persistDraftMessages",keywords:["draft","message"]},{id:"chat.composer",page:"chat",titleKey:"settings.aiworker.visual.section.composer",keywords:["input","draft","spellcheck","paste"]},{id:"chat.spellcheck",page:"chat",titleKey:"settings.aiworker.visual.field.enableSpellcheckInTextInputs",keywords:["spelling","input"],isAvailable:t=>!t.isMobile},{id:"chat.large-text-paste",page:"chat",titleKey:"settings.aiworker.visual.field.largeTextPaste",descriptionKey:"settings.aiworker.visual.field.largeTextPasteHint",keywords:["paste","clipboard","attachment","large","text","file"]},{id:"chat.enter-to-send",page:"chat",titleKey:"settings.aiworker.visual.field.enterToSend",descriptionKey:"settings.aiworker.visual.field.enterToSendHint",keywords:["enter","shift enter","ctrl enter","cmd enter","mod enter","send","newline"]},{id:"sessions.default-model",page:"sessions",titleKey:"settings.aiworker.defaults.field.defaultModel",keywords:["model","provider","new sessions"]},{id:"sessions.default-thinking",page:"sessions",titleKey:"settings.aiworker.defaults.field.defaultThinking",keywords:["thinking","reasoning","variant"]},{id:"sessions.default-agent",page:"sessions",titleKey:"settings.aiworker.defaults.field.defaultAgent",keywords:["agent","new sessions"]},{id:"sessions.deletion-dialog",page:"sessions",titleKey:"settings.aiworker.defaults.field.showDeletionDialog",keywords:["delete","confirmation"]},{id:"sessions.small-model",page:"sessions",titleKey:"settings.aiworker.defaults.smallModel.title",descriptionKey:"settings.aiworker.defaults.smallModel.description",keywords:["small model","utility","summary","recap","cheap","override"]},{id:"sessions.walkthrough-model",page:"sessions",titleKey:"settings.aiworker.defaults.walkthroughModel.title",descriptionKey:"settings.aiworker.defaults.walkthroughModel.description",keywords:["walkthrough","diff","review","changes","structured output","model","override"]},{id:"sessions.auto-cleanup",page:"sessions",titleKey:"settings.aiworker.sessionRetention.field.enableAutoCleanup",descriptionKey:"settings.aiworker.sessionRetention.tooltip",keywords:["retention","archive","delete"]},{id:"sessions.retention-only-archived",page:"sessions",titleKey:"settings.aiworker.sessionRetention.field.onlyArchived",descriptionKey:"settings.aiworker.sessionRetention.field.onlyArchivedDescription",keywords:["archive","archived","only","delete","cleanup","retention"]},{id:"sessions.retention-period",page:"sessions",titleKey:"settings.aiworker.sessionRetention.field.retentionPeriod",keywords:["days","cleanup","retention"]},{id:"sessions.retention-action",page:"sessions",titleKey:"settings.aiworker.sessionRetention.field.whenSessionsExpire",keywords:["archive","delete","expire"]},{id:"sessions.desktop-launch-at-login",page:"general",titleKey:"settings.aiworker.desktopNetwork.field.launchAtLogin",descriptionKey:"settings.aiworker.desktopNetwork.field.launchAtLoginDescription",keywords:["desktop","startup","login","launch","background","autostart"],isAvailable:t=>t.isDesktopLocalOrigin},{id:"sessions.desktop-window-controls-position",page:"appearance",titleKey:"settings.aiworker.desktopNetwork.field.windowControlsPosition",descriptionKey:"settings.aiworker.desktopNetwork.field.windowControlsPositionDescription",keywords:["desktop","window","controls","minimize","maximize","close","titlebar","linux","windows"],isAvailable:t=>t.isDesktop&&(t.isWindows||!t.isMac)},{id:"sessions.desktop-window-controls-style",page:"appearance",titleKey:"settings.aiworker.desktopNetwork.field.windowControlsStyle",keywords:["desktop","window","controls","style","traffic","lights","classic","macos","titlebar"],isAvailable:t=>t.isDesktop&&(t.isWindows||!t.isMac)},{id:"sessions.desktop-mac-menu-bar",page:"general",titleKey:"settings.aiworker.desktopNetwork.field.macMenuBar",descriptionKey:"settings.aiworker.desktopNetwork.field.macMenuBarDescription",keywords:["desktop","menu bar","tray","status item","macos","background"],isAvailable:t=>t.isDesktopLocalOrigin&&t.isMac},{id:"sessions.desktop-minimize-to-tray",page:"general",titleKey:"settings.aiworker.desktopNetwork.field.minimizeToTray",descriptionKey:"settings.aiworker.desktopNetwork.field.minimizeToTrayDescription",keywords:["desktop","tray","system tray","minimize","close","background","windows","linux"],isAvailable:t=>t.isDesktopLocalOrigin&&(t.isWindows||t.isLinux)},{id:"sessions.desktop-keep-awake",page:"general",titleKey:"settings.aiworker.desktopNetwork.field.keepAwake",descriptionKey:"settings.aiworker.desktopNetwork.field.keepAwakeDescription",keywords:["desktop","sleep","awake","server","mobile","phone"],isAvailable:t=>t.isDesktopLocalOrigin},{id:"sessions.desktop-ui-password",page:"general",titleKey:"settings.aiworker.desktopPassword.field.password",descriptionKey:"settings.aiworker.desktopPassword.field.passwordDescription",keywords:["desktop","password","auth","login"],isAvailable:t=>t.isDesktopLocalOrigin},{id:"sessions.desktop-lan-access",page:"general",titleKey:"settings.aiworker.desktopNetwork.field.allowLanAccess",descriptionKey:"settings.aiworker.desktopNetwork.field.allowLanAccessDescription",keywords:["desktop","lan","network","phone","tablet"],isAvailable:t=>t.isDesktopLocalOrigin},{id:"sessions.opencode-binary",page:"general",titleKey:"settings.aiworker.opencodeCli.field.binaryPath",keywords:["opencode","cli","binary","path"],isAvailable:t=>!t.isVSCode},{id:"sessions.opencode-update-notifications",page:"general",titleKey:"settings.aiworker.opencodeCli.field.showUpdateNotifications",keywords:["opencode","cli","updates"],isAvailable:t=>!t.isVSCode&&!t.isWindowsArm64},{id:"sessions.agent-control-tool",page:"general",titleKey:"settings.aiworker.tools.field.agentControlTool",descriptionKey:"settings.aiworker.tools.field.agentControlToolInfo",keywords:["agent","tool","orchestration","aiworker","sessions","schedule","control"],isAvailable:t=>!t.isVSCode},{id:"sessions.agent-web-tool",page:"general",titleKey:"settings.aiworker.tools.field.agentWebTool",descriptionKey:"settings.aiworker.tools.field.agentWebToolInfo",keywords:["agent","tool","web","browser","page","preview","aiworker"],isAvailable:t=>!t.isVSCode},{id:"sessions.agent-memory-tool",page:"general",titleKey:"settings.aiworker.tools.field.agentMemoryTool",descriptionKey:"settings.aiworker.tools.field.agentMemoryToolInfo",keywords:["agent","tool","memory","remember","recall","preferences","aiworker"],isAvailable:t=>!t.isVSCode&&ie.getState().agentMemoryFeatureAvailable},{id:"git.identities",page:"git",titleKey:"settings.gitIdentities.page.section.title",descriptionKey:"settings.gitIdentities.page.empty.description",keywords:["identity","profile","author","email","credentials","signing","commit signing","ssh signing","gpg"]},{id:"git.changes-view",page:"git",titleKey:"settings.aiworker.git.changesViewTitle",keywords:["changes","flat list","tree view"]},{id:"git.gitmoji",page:"git",titleKey:"settings.aiworker.git.enableGitmoji",keywords:["commit","emoji"]},{id:"git.gitignored-files",page:"git",titleKey:"settings.aiworker.git.showGitignored",keywords:["ignored","files","gitignore"]},{id:"usage.work-status-panel",page:"usage",titleKey:"settings.usage.page.options.showInWorkStatus",descriptionKey:"settings.usage.page.options.showInWorkStatusTooltip",keywords:["quota","work","status","panel"]},{id:"usage.model-quotas",page:"usage",titleKey:"settings.usage.page.section.modelQuotas",keywords:["models","quota","limits","tokens"]},{id:"projects.name",page:"projects",titleKey:"settings.projects.page.field.projectName",keywords:["label","display name","project metadata"]},{id:"projects.default-model",page:"projects",titleKey:"settings.projects.page.field.projectModel",keywords:["model","default","new chat","project metadata"]},{id:"projects.default-thinking",page:"projects",titleKey:"settings.projects.page.field.projectThinking",keywords:["thinking","variant","reasoning","effort","model","project metadata"]},{id:"projects.accent-color",page:"projects",titleKey:"settings.projects.page.field.accentColor",keywords:["color","appearance","project metadata"]},{id:"projects.icon",page:"projects",titleKey:"settings.projects.page.field.projectIcon",keywords:["icon","favicon","upload","project metadata"]},{id:"projects.worktree",page:"projects",titleKey:"settings.projects.page.section.worktree",keywords:["worktree","branch","repository"]},{id:"projects.worktree.setup.wait",page:"projects",titleKey:"settings.aiworker.worktrees.setup.waitForCommands",keywords:["worktree","setup commands","bootstrap","wait"]},{id:"projects.worktree.setup.replace",page:"projects",titleKey:"settings.projects.shared.replaceMode",keywords:["worktree","setup commands","shared","team","only mine"]},{id:"projects.shared",page:"projects",titleKey:"settings.projects.shared.title",descriptionKey:"settings.projects.shared.description",keywords:["shared","team","repository",".aiworker","project.json","trust"]},{id:"projects.shared.plansDir",page:"projects",titleKey:"settings.projects.shared.plansDir",descriptionKey:"settings.projects.shared.plansDirInfo",keywords:["plans","folder","shared","team","docs"]},{id:"remote-instances.client-auth",page:"remote-instances",titleKey:"settings.remoteInstances.clientAuth.title",descriptionKey:"settings.remoteInstances.clientAuth.description",keywords:["pairing link","client token","connect desktop","remote access","relay","devices","connect from anywhere"],isAvailable:t=>!t.isVSCode},{id:"remote-instances.direct-hosts",page:"remote-instances",titleKey:"settings.remoteInstances.direct.title",descriptionKey:"settings.remoteInstances.direct.description",keywords:["server url","connection token","import link","host switcher","additional headers","request headers","cloudflare access","service token"],isAvailable:t=>t.isDesktop},{id:"behavior.system-prompt-optimization",page:"behavior",titleKey:"settings.behavior.page.section.systemPromptOptimization",descriptionKey:"settings.behavior.page.systemPromptOptimization.info",keywords:["system prompt","tokens","context","optimize","minimal"],isAvailable:t=>!t.isVSCode},{id:"behavior.system-prompt",page:"behavior",titleKey:"settings.behavior.page.section.systemPrompt",descriptionKey:"settings.behavior.page.warning.title",keywords:["agents.md","global instructions","system prompt"]},{id:"behavior.response-style",page:"behavior",titleKey:"settings.behavior.page.section.responseStyle",descriptionKey:"settings.behavior.page.responseStyle.tooltip",keywords:["tone","concise","detailed","custom instructions"]},{id:"agents.create",page:"agents",titleKey:"settings.agents.page.title.new",keywords:["create","add","new agent"]},{id:"agents.name",page:"agents",titleKey:"settings.agents.page.field.agentName",keywords:["agent","name"]},{id:"agents.mode",page:"agents",titleKey:"settings.agents.page.field.mode",descriptionKey:"settings.agents.page.field.modeTooltip",keywords:["primary","subagent","visibility"]},{id:"agents.model",page:"agents",titleKey:"settings.agents.page.field.overrideModel",keywords:["model","provider"]},{id:"agents.variant",page:"agents",titleKey:"settings.agents.page.field.variant",descriptionKey:"settings.agents.page.field.variantTooltip",keywords:["thinking","reasoning","variant","depth"]},{id:"agents.temperature",page:"agents",titleKey:"settings.agents.page.field.temperature",descriptionKey:"settings.agents.page.field.temperatureTooltip",keywords:["randomness","creative"]},{id:"agents.top-p",page:"agents",titleKey:"settings.agents.page.field.topP",descriptionKey:"settings.agents.page.field.topPTooltip",keywords:["sampling","nucleus"]},{id:"agents.system-prompt",page:"agents",titleKey:"settings.agents.page.section.systemPrompt",keywords:["prompt","instructions"]},{id:"agents.permissions",page:"agents",titleKey:"settings.agents.page.section.toolPermissions",keywords:["tools","permissions","allow","ask","deny"]},{id:"commands.create",page:"commands",titleKey:"settings.commands.page.title.new",keywords:["create","add","new command"]},{id:"commands.name",page:"commands",titleKey:"settings.commands.page.field.commandName",keywords:["slash command","name"]},{id:"commands.agent",page:"commands",titleKey:"settings.commands.page.field.overrideAgent",keywords:["agent","execution"]},{id:"commands.model",page:"commands",titleKey:"settings.agents.page.field.overrideModel",keywords:["model","provider"]},{id:"commands.template",page:"commands",titleKey:"settings.commands.page.section.template",keywords:["prompt","template","arguments","shell","file"]},{id:"mcp.create",page:"mcp",titleKey:"settings.mcp.sidebar.actions.addServerTitle",keywords:["create","add","server"]},{id:"mcp.server",page:"mcp",titleKey:"settings.mcp.page.server.title",keywords:["server","name","transport"]},{id:"mcp.command",page:"mcp",titleKey:"settings.mcp.page.connection.command",keywords:["stdio","local","command"]},{id:"mcp.environment",page:"mcp",titleKey:"settings.mcp.page.env.title",keywords:["env","variables","api key"]},{id:"mcp.advanced",page:"mcp",titleKey:"settings.mcp.page.advanced.title",keywords:["oauth","headers","timeout"]},{id:"plugins.create",page:"plugins",titleKey:"settings.plugins.sidebar.actions.addTitle",keywords:["add","plugin","npm","path","file"]},{id:"plugins.spec",page:"plugins",titleKey:"settings.plugins.page.field.spec",keywords:["npm","package","path"]},{id:"plugins.options",page:"plugins",titleKey:"settings.plugins.page.field.options",keywords:["json","configuration"]},{id:"plugins.content",page:"plugins",titleKey:"settings.plugins.page.field.content",keywords:["file","code"]},{id:"snippets.create",page:"snippets",titleKey:"settings.snippets.sidebar.actions.create",keywords:["add","new snippet"]},{id:"snippets.content",page:"snippets",titleKey:"settings.snippets.page.field.content",keywords:["markdown","prompt","template"]},{id:"providers.connect",page:"providers",titleKey:"settings.providers.page.connect.title",keywords:["add provider","connect provider","credentials"]},{id:"providers.custom",page:"providers",titleKey:"settings.providers.page.custom.title",descriptionKey:"settings.providers.page.custom.description",keywords:["other","custom","openai-compatible","base url","api key"]},{id:"providers.auth",page:"providers",titleKey:"settings.providers.page.auth.title",keywords:["api key","oauth","credentials"]},{id:"providers.connection-details",page:"providers",titleKey:"settings.providers.page.connectionDetails.title",keywords:["config","source","disconnect"]},{id:"providers.models",page:"providers",titleKey:"settings.providers.page.models.title",keywords:["models","hide","show"]},{id:"skills.create",page:"skills.installed",titleKey:"settings.skills.page.title.newSkill",keywords:["create","add","new skill"]},{id:"skills.basic-information",page:"skills.installed",titleKey:"settings.skills.page.section.basicInformation",keywords:["name","location","description"]},{id:"skills.instructions",page:"skills.installed",titleKey:"settings.skills.page.section.instructions",keywords:["markdown","skill.md","content"]},{id:"skills.supporting-files",page:"skills.installed",titleKey:"settings.skills.page.section.supportingFiles",keywords:["files","resources"]},{id:"skills.catalog.source",page:"skills.catalog",titleKey:"settings.skills.catalog.page.section.sourceRepository",keywords:["catalog","repository","source","refresh"]},{id:"skills.catalog.search",page:"skills.catalog",titleKey:"settings.skills.catalog.shared.field.searchSkillsPlaceholder",keywords:["find skills","install skills","catalog search"]},{id:"skills.catalog.add-catalog",page:"skills.catalog",titleKey:"settings.skills.catalog.page.actions.addCatalog",keywords:["external repository","add source","catalog"]},{id:"magic-prompts.visible-prompt",page:"magic-prompts",titleKey:"settings.magicPrompts.page.block.visiblePrompt",keywords:["prompt text","user message","template"],isAvailable:t=>!t.isVSCode},{id:"magic-prompts.instructions",page:"magic-prompts",titleKey:"settings.magicPrompts.page.block.instructions",keywords:["hidden prompt","instructions","template"],isAvailable:t=>!t.isVSCode},{id:"magic-prompts.reset-overrides",page:"magic-prompts",titleKey:"settings.magicPrompts.page.actions.resetAllOverrides",keywords:["reset","default prompts","overrides"],isAvailable:t=>!t.isVSCode},{id:"shortcuts.keyboard-shortcuts",page:"shortcuts",titleKey:"settings.aiworker.keyboardShortcuts.title",descriptionKey:"settings.aiworker.keyboardShortcuts.tooltip",keywords:["keyboard","hotkeys","bindings"]},{id:"voice.playback",page:"voice",titleKey:"settings.voice.page.section.playbackAndSummary",keywords:["tts","read aloud","voice","provider","speech rate","speech pitch","speech volume","tts input mode","markdown"]},{id:"voice.speech-recognition",page:"voice",titleKey:"settings.voice.page.section.speechRecognition",keywords:["stt","dictation","voice input","transcribe","whisper","parakeet","microphone"]},{id:"tunnel.provider",page:"tunnel",titleKey:"settings.aiworker.tunnel.field.provider",descriptionKey:"settings.aiworker.tunnel.description",keywords:["remote access","cloudflare","ngrok"],isAvailable:t=>!t.isVSCode},{id:"tunnel.type",page:"tunnel",titleKey:"settings.aiworker.tunnel.field.tunnelType",keywords:["quick","managed remote","managed local"],isAvailable:t=>!t.isVSCode},{id:"tunnel.ttl",page:"tunnel",titleKey:"settings.aiworker.tunnel.field.connectLinkTtl",descriptionKey:"settings.aiworker.tunnel.field.tunnelSessionTtl",keywords:["expiry","expiration","session ttl","connect link ttl"],isAvailable:t=>!t.isVSCode},{id:"tunnel.managed-remote",page:"tunnel",titleKey:"settings.aiworker.tunnel.section.savedManagedRemoteTunnels",keywords:["cloudflare","hostname","token","managed remote"],isAvailable:t=>!t.isVSCode},{id:"tunnel.managed-local-config",page:"tunnel",titleKey:"settings.aiworker.tunnel.field.configurationFile",descriptionKey:"settings.aiworker.tunnel.note.managedLocalUsesConfig",keywords:["cloudflared","config","yaml","json","managed local"],isAvailable:t=>!t.isVSCode},{id:"tunnel.start",page:"tunnel",titleKey:"settings.aiworker.tunnel.actions.startTunnel",descriptionKey:"settings.aiworker.tunnel.note.connectLinksOneTime",keywords:["connect link","qr code","public url","remote access"],isAvailable:t=>!t.isVSCode},{id:"notifications.delivery",page:"notifications",titleKey:"settings.notifications.page.delivery.title",keywords:["desktop notifications","system notifications"]},{id:"notifications.events",page:"notifications",titleKey:"settings.notifications.page.events.title",keywords:["completion","subtasks","errors","questions"]},{id:"notifications.push",page:"notifications",titleKey:"settings.notifications.page.push.title",keywords:["background","push"],isAvailable:t=>t.isWeb&&!t.isDesktop&&!t.isVSCode},{id:"integrations.first-party",page:"integrations",titleKey:"settings.integrations.firstParty.title",descriptionKey:"settings.integrations.firstParty.info",keywords:["built-in","first-party","native","github","linear"],isAvailable:t=>!t.isVSCode},{id:"integrations.github",page:"integrations",titleKey:"settings.integrations.github.title",descriptionKey:"settings.integrations.github.description",keywords:["github","account","oauth","gh","cli","prs","pull request","issues","connect"],isAvailable:t=>!t.isVSCode},{id:"integrations.linear",page:"integrations",titleKey:"settings.integrations.linear.title",descriptionKey:"settings.integrations.linear.description",keywords:["linear","issues","oauth","connect","workspace"],isAvailable:t=>!t.isVSCode},{id:"integrations.linear.add-workspace",page:"integrations",titleKey:"settings.integrations.linear.actions.addWorkspace",descriptionKey:"settings.integrations.linear.description",keywords:["linear","workspace","add","connect","oauth"],isAvailable:t=>!t.isVSCode},{id:"integrations.linear.mapping",page:"integrations",titleKey:"settings.integrations.linear.mapping.defaultProject",descriptionKey:"settings.integrations.linear.mapping.defaultProject.info",keywords:["linear","project","team","map","workspace","directory"],isAvailable:t=>!t.isVSCode}];function pl(t){return t.trim().toLocaleLowerCase()}function mx({query:t,runtimeCtx:e,visiblePageSlugs:a,t:n,getPageTitle:r}){const i=pl(t);if(!i)return[];const l=a?new Set(a):null,g=i.split(/\s+/).filter(Boolean);return px.flatMap(c=>{if(l&&!l.has(c.page))return[];const y=pa(c.page);if(!y||y.isAvailable&&!y.isAvailable(e)||c.isAvailable&&!c.isAvailable(e))return[];const p=n(c.titleKey),b=c.descriptionKey?n(c.descriptionKey):null,d=pl([p,b,r(c.page),...c.keywords??[]].filter(Boolean).join(" "));return g.every(P=>d.includes(P))?[{...c,title:p,description:b,pageTitle:r(c.page)}]:[]})}const ml=256,gl=280,uc="__aiworkerSettingsDetail",gx=["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"],hx=["general","projects","opencode","content"],fx="__add_provider__";function xx(t,e){const a=cs(),n=!t&&Bn();return{isVSCode:a,isWeb:n,isDesktop:t,isMobile:e}}function hl(t,e){return t.isAvailable?t.isAvailable(e):!0}function br(t){return typeof t=="object"&&t!==null&&!Array.isArray(t)}function La(t,e){const a=new Set(e);let n=t,r=1;for(;a.has(n);)n=`${t}-${r}`,r+=1;return n}function or(t){if(!br(t))return null;const e=t[uc];if(!br(e))return null;const a=e.page,n=e.stage;return typeof a!="string"||n!=="page-content"?null:{page:Fl(a),stage:n}}function vx(){return typeof window>"u"||!br(window.history.state)?{}:window.history.state}const Tx=({onClose:t,forceMobile:e,isWindowed:a,visiblePageSlugs:n,initialMobileStage:r="nav",registerBackHandler:i})=>{const{t:l}=tt(),g=wa(),c=e??g.isMobile,y=Vn(El),p=ie(Z=>Z.settingsPage),b=ie(Z=>Z.isSettingsDialogOpen),d=ie(Z=>Z.setSettingsPage),P=ie(Z=>Z.shortcutOverrides.open_settings),f=Fl(p),[C,v]=o.useState(r),N=o.useRef(r==="nav"?f:null);o.useEffect(()=>{!c&&f==="home"&&d("general")},[c,d,f]);const[m,A]=o.useState(""),[R,I]=o.useState(null),[j,h]=o.useState(0),w=o.useRef(null),F=o.useRef(!1),T=o.useRef([]),S=o.useRef(0),D=o.useRef(!1),$=o.useMemo(()=>as(),[]),B=o.useMemo(()=>as()&&Va(),[]),k=o.useMemo(()=>as()&&typeof window<"u"&&window.__AIWORKER_PLATFORM__==="darwin",[]),G=o.useMemo(()=>as()&&typeof window<"u"&&window.__AIWORKER_PLATFORM__==="win32",[]),M=o.useMemo(()=>as()&&typeof window<"u"&&window.__AIWORKER_PLATFORM__==="linux",[]),L=o.useMemo(()=>Ll(),[]),J=o.useMemo(()=>xx($,c),[$,c]),ee=o.useMemo(()=>{const Z=n?new Set(n):null;return Jd.filter(ne=>ne.slug!=="home").filter(ne=>!Z||Z.has(ne.slug)).filter(ne=>hl(ne,J)).filter(ne=>!(J.isVSCode&&ne.slug==="projects")).filter(ne=>!(c&&ne.slug==="shortcuts"))},[J,c,n]),U=o.useMemo(()=>{const Z=new Map(gx.map((ne,be)=>[ne,be]));return ee.slice().sort((ne,be)=>(Z.get(ne.slug)??999)-(Z.get(be.slug)??999))},[ee]),le=Gs(Z=>Z.activeProjectId),_=_s();o.useEffect(()=>{if(!(!b&&!J.isVSCode&&!a)){if(f==="agents"){Hn.getState().loadAgents(_);return}if(f==="commands"){va.getState().loadCommands(_);return}if(f==="mcp"){ya.getState().loadMcpConfigs({directory:_});return}if(f==="plugins"){ms.getState().loadPlugins();return}(f==="skills.installed"||f==="skills.catalog")&&(Hs.getState().loadSkills(_),hn.getState().loadCatalog()),f==="snippets"&&Si.getState().loadSnippets()}},[le,b,a,J.isVSCode,_,f]);const H=o.useCallback(Z=>{if(d(Z),N.current=Z,!c)return;const ne=pa(Z);if(!ne||ne.slug==="home"){v("nav");return}v(ne.kind==="split"?"page-sidebar":"page-content")},[c,d]),z=o.useMemo(()=>pa(f),[f]),K=o.useMemo(()=>({general:"general",appearance:"visual",chat:"chat",shortcuts:"shortcuts",sessions:"sessions",notifications:"notifications",voice:"voice",tunnel:"tunnel"}),[]),te=o.useCallback(Z=>{switch(Z){case"general":return l("settings.page.general.title");case"projects":return l("settings.page.projects.title");case"remote-instances":return l("settings.page.remoteInstances.title");case"providers":return l("settings.page.providers.title");case"usage":return l("settings.page.usage.title");case"agents":return l("settings.page.agents.title");case"behavior":return l("settings.page.behavior.title");case"commands":return l("settings.page.commands.title");case"mcp":return l("settings.page.mcp.title");case"plugins":return l("settings.page.plugins.title");case"skills.installed":return l("settings.page.skills.title");case"skills.catalog":return l("settings.page.skillsCatalog.title");case"git":return l("settings.page.git.title");case"integrations":return l("settings.page.integrations.title");case"appearance":return l("settings.page.appearance.title");case"chat":return l("settings.page.chat.title");case"shortcuts":return l("settings.page.shortcuts.title");case"sessions":return l("settings.page.sessions.title");case"magic-prompts":return l("settings.page.magicPrompts.title");case"snippets":return l("settings.page.snippets.title");case"notifications":return l("settings.page.notifications.title");case"voice":return l("settings.page.voice.title");case"tunnel":return l("settings.page.tunnel.title");case"about":return l("settings.page.about.title");default:return l("settings.view.home.title")}},[l]),Y=o.useMemo(()=>mx({query:m,runtimeCtx:{...J,isDesktopLocalOrigin:B,isMac:k,isWindows:G,isLinux:M,isWindowsArm64:L},visiblePageSlugs:n,t:l,getPageTitle:te}),[te,L,B,k,G,M,J,m,l,n]),ae=o.useCallback(Z=>{if(Z.id.startsWith("agents.")){const ne=Hn.getState(),be=La("new-agent",ne.agents.map(we=>we.name));return ne.setAgentDraft({name:be,scope:"user"}),ne.setSelectedAgent(be),Z.id==="agents.create"?"agents.name":Z.id}if(Z.id.startsWith("commands.")){const ne=va.getState(),be=La("new-command",ne.commands.map(we=>we.name));return ne.setCommandDraft({name:be,scope:"user"}),ne.setSelectedCommand(be),Z.id==="commands.create"?"commands.name":Z.id}if(Z.id.startsWith("mcp.")){const ne=ya.getState(),be=La("new-mcp-server",ne.mcpServers.map(we=>we.name));return ne.setMcpDraft({name:be,scope:"user",type:"local",command:[],url:"",environment:[],headers:[],oauthEnabled:!0,oauthClientId:"",oauthClientSecret:"",oauthScope:"",oauthRedirectUri:"",timeout:"",enabled:!0}),ne.setSelectedMcp(be),Z.id==="mcp.create"?"mcp.server":Z.id}if(Z.id.startsWith("snippets.")){const ne=Si.getState(),be=La("new-snippet",ne.snippets.map(we=>we.name));return ne.setSnippetDraft({name:be,scope:"global"}),ne.setSelectedSnippet(be),Z.id==="snippets.create"?"snippets.content":Z.id}if(Z.id.startsWith("skills.")){const ne=Hs.getState(),be=La("new-skill",ne.skills.map(we=>we.name));return ne.setSkillDraft({name:be,scope:"user",source:"opencode",description:"",instructions:""}),ne.setSelectedSkill(be),Z.id==="skills.create"?"skills.basic-information":Z.id}return Z.id==="providers.connect"&&Ye.getState().setSelectedProvider(fx),Z.id==="plugins.create"?"plugins.spec":Z.id},[]),ge=o.useMemo(()=>{const Z=[],ne=new Map;for(const be of Y){let we=ne.get(be.page);we||(we={page:be.page,pageTitle:be.pageTitle,results:[]},ne.set(be.page,we),Z.push(we)),we.results.push(be)}return Z},[Y]);o.useEffect(()=>{h(0),S.current=0,D.current=!1},[m]),o.useEffect(()=>{S.current=j},[j]),o.useEffect(()=>{T.current[j]?.scrollIntoView({block:"nearest"})},[j]),o.useEffect(()=>{j>=Y.length&&h(Math.max(0,Y.length-1)),T.current.length=Y.length},[j,Y.length]);const de=o.useCallback(Z=>{const ne=ae(Z);I(ne),H(Z.page),c&&v("page-content"),Z.id==="plugins.create"&&typeof window<"u"&&window.setTimeout(()=>{window.dispatchEvent(new CustomEvent("aiworker:settings-open-plugin-add"))},50)},[c,H,ae]),he=o.useCallback(Z=>{if(m.trim()){if(Z.key==="Escape"){Z.preventDefault(),A("");return}if(Y.length!==0){if(Z.key==="ArrowDown"){Z.preventDefault(),D.current=!0,h(ne=>(ne+1)%Y.length);return}if(Z.key==="ArrowUp"){Z.preventDefault(),D.current=!0,h(ne=>(ne-1+Y.length)%Y.length);return}if(Z.key==="Enter"){Z.preventDefault();const ne=(S.current%Y.length+Y.length)%Y.length,be=Y[ne]??Y[0];be&&de(be)}}}},[de,m,Y]);o.useEffect(()=>{const Z=R;if(!Z)return;let ne=!1;const be=window.requestAnimationFrame(()=>{if(ne)return;const we=typeof CSS<"u"&&CSS.escape?CSS.escape(Z):Z.replace(/[^a-zA-Z0-9_-]/g,"\\$&"),Re=w.current?.querySelector(`[data-settings-item="${we}"]`);Re&&(I(null),Re.scrollIntoView({block:"center",behavior:"smooth"}),Re.setAttribute("data-settings-search-highlight","true"),window.setTimeout(()=>{Re.removeAttribute("data-settings-search-highlight")},1600))});return()=>{ne=!0,window.cancelAnimationFrame(be)}},[R,f]);const se=o.useCallback(()=>s.jsx("div",{className:"flex h-full items-center justify-center px-6",children:s.jsxs("div",{className:"max-w-md text-center",children:[s.jsx("div",{className:Sl,children:l("settings.view.unavailable.title")}),s.jsx("p",{className:"typography-ui text-muted-foreground mt-1",children:l("settings.view.unavailable.description")})]})}),[l]),re=o.useCallback((Z,ne)=>{switch(Z){case"projects":return s.jsx(Sm,{onItemSelect:ne.onItemSelect});case"agents":return s.jsx(bu,{onItemSelect:ne.onItemSelect});case"commands":return s.jsx(Ku,{onItemSelect:ne.onItemSelect});case"mcp":return s.jsx(Gu,{onItemSelect:ne.onItemSelect});case"plugins":return s.jsx(Mp,{onItemSelect:ne.onItemSelect});case"skills.installed":return s.jsx(Wp,{onItemSelect:ne.onItemSelect});case"providers":return s.jsx(Xm,{onItemSelect:ne.onItemSelect});case"usage":return s.jsx(Og,{onItemSelect:ne.onItemSelect});case"magic-prompts":return s.jsx(Xg,{onItemSelect:ne.onItemSelect});case"snippets":return s.jsx(nh,{onItemSelect:ne.onItemSelect});default:return null}},[]),ue=o.useCallback(Z=>{const ne=pa(Z);if(ne&&!hl(ne,J))return se();switch(Z){case"projects":return s.jsx(Tm,{});case"remote-instances":return s.jsx(Qm,{});case"agents":return s.jsx(Eu,{});case"behavior":return s.jsx(Fu,{});case"commands":return s.jsx(Hu,{});case"mcp":return s.jsx(gp,{});case"plugins":return s.jsx(Hp,{});case"skills.installed":return s.jsx(No,{view:"installed"});case"skills.catalog":return s.jsx(No,{view:"catalog"});case"providers":return s.jsx(Rg,{});case"usage":return s.jsx(Yg,{});case"about":return s.jsx(es,{title:l("settings.page.about.title"),showSaveStatus:!1,children:s.jsx(Ul,{})});case"magic-prompts":return s.jsx(sh,{});case"snippets":return s.jsx(oh,{});case"git":return s.jsx(ph,{});case"integrations":return s.jsx(Ih,{});case"general":case"appearance":case"chat":case"shortcuts":case"sessions":case"notifications":case"voice":case"tunnel":{const be=K[Z]??"visual";return s.jsx(Qf,{section:be})}default:return null}},[K,se,J,l]);o.useEffect(()=>{if(!c||C!=="nav"||f==="home"||N.current===f)return;const Z=pa(f);!Z||Z.slug==="home"||(N.current=f,v(Z.kind==="split"?"page-sidebar":"page-content"))},[c,C,f]);const Ce=c&&C!=="nav",Se=c&&C==="page-content"&&z?.kind==="split",ye=l(Se?"settings.view.actions.back":Ce?"settings.view.actions.backToSettings":"settings.view.actions.closeSettings"),fe=Tl("open_settings",P===void 0?void 0:{open_settings:P}),_e=fe?l("settings.view.actions.closeSettingsWithShortcut",{shortcut:Gn(fe)}):l("settings.view.actions.closeSettings"),Ue=o.useCallback(Z=>{if(typeof window>"u"||J.isVSCode)return;const ne=or(window.history.state);ne?.page===Z&&ne.stage==="page-content"||window.history.pushState({...vx(),[uc]:{page:Z,stage:"page-content"}},"",window.location.href)},[J.isVSCode]),Ne=o.useCallback(()=>{F.current=!0,v("page-content"),Ue(f)},[Ue,f]);o.useEffect(()=>{if(!c||C!=="page-content"||!F.current)return;F.current=!1;const Z=window.requestAnimationFrame(()=>{w.current?.querySelector("[data-settings-page-heading]")?.focus({preventScroll:!0})});return()=>{window.cancelAnimationFrame(Z)}},[c,C,f]);const Oe=o.useCallback(()=>{if(Se){if((typeof window<"u"?or(window.history.state):null)?.page===f&&!J.isVSCode){window.history.back();return}v("page-sidebar");return}v("nav")},[Se,J.isVSCode,f]);o.useEffect(()=>{if(i)return i(()=>!c||C==="nav"?!1:(Oe(),!0)),()=>i(null)},[Oe,c,C,i]),o.useEffect(()=>{if(!c||J.isVSCode)return;const Z=ne=>{if(pa(f)?.kind!=="split")return;if(or(ne.state)?.page===f){v("page-content");return}v(we=>we==="page-content"?"page-sidebar":we)};return window.addEventListener("popstate",Z),()=>{window.removeEventListener("popstate",Z)}},[c,J.isVSCode,f]);const Ve=()=>{const Z=m.trim().length>0;return s.jsxs("div",{className:"flex h-full flex-col overflow-hidden",children:[s.jsx("div",{className:"px-4 pt-3",children:s.jsxs("div",{className:"flex h-10 items-center gap-1.5 rounded-md border border-border bg-background/70 px-2 text-muted-foreground focus-within:ring-2 focus-within:ring-primary/40 sm:h-8",children:[s.jsx(O,{name:"search",className:"h-4 w-4 shrink-0"}),s.jsx("input",{value:m,onChange:ne=>A(ne.target.value),onKeyDown:he,placeholder:l("settings.view.search.placeholder"),"aria-label":l("settings.view.search.aria"),className:"typography-ui min-w-0 flex-1 bg-transparent text-foreground outline-none placeholder:text-muted-foreground/70"}),Z&&s.jsx("button",{type:"button",onClick:()=>A(""),"aria-label":l("settings.view.search.clear"),className:"inline-flex h-7 w-7 shrink-0 items-center justify-center rounded text-muted-foreground hover:bg-interactive-hover hover:text-foreground sm:h-5 sm:w-5",children:s.jsx(O,{name:"close",className:"h-3.5 w-3.5"})})]})}),s.jsx(vs,{outerClassName:"flex-1 min-h-0",disableHorizontal:!0,children:s.jsx("div",{className:"flex flex-col gap-0.5 px-4 pt-4 pb-2",children:Z?Y.length>0?(()=>{let ne=0;return ge.map(be=>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:be.pageTitle}),be.results.map(we=>{const Re=ne;ne+=1;const Fe=Re===j,Ke=!!we.description;return s.jsxs("button",{type:"button",ref:Ee=>{T.current[Re]=Ee},onMouseMove:()=>{D.current=!1,h(Re)},onClick:()=>de(we),className:xe("flex w-full flex-col rounded-md px-2 text-left focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-primary/50",Ke?"min-h-11 py-1.5":"py-2",Fe?"bg-interactive-selection":"hover:bg-interactive-hover"),children:[s.jsx("span",{className:"typography-ui-label text-foreground truncate",children:we.title}),Ke&&s.jsx("span",{className:"typography-micro text-muted-foreground/70 line-clamp-2",children:we.description})]},we.id)})]},be.page))})():s.jsx("div",{className:"px-2 py-6 text-center typography-ui text-muted-foreground",children:l("settings.view.search.noResults")}):(()=>{const ne=new Map;for(const we of U){const Re=we.group,Fe=ne.get(Re);Fe?Fe.push(we):ne.set(Re,[we])}return hx.map(we=>({group:we,pages:ne.get(we)??[]})).filter(we=>we.pages.length>0).map(({group:we,pages:Re},Fe)=>s.jsxs("div",{className:"space-y-0.5",children:[s.jsx("div",{className:xe("px-3 pb-1 typography-micro font-semibold uppercase tracking-wide text-muted-foreground sm:px-2 sm:pb-0.5",Fe===0?"pt-1":"pt-4 sm:pt-3"),children:l(`settings.view.nav.group.${we}`)}),Re.map(Ke=>{const Ee=f===Ke.slug&&!(c&&C==="nav"),je=Qd(Ke.slug);return!je&&Ke.slug!=="mcp"?null:s.jsx(kr,{children:s.jsx(Nr,{asChild:!0,children:s.jsxs("button",{type:"button",onClick:()=>H(Ke.slug),"aria-current":Ee?"page":void 0,className:xe("flex h-11 w-full items-center gap-2.5 rounded-md px-3 overflow-hidden sm:h-8 sm:gap-2 sm:px-2",Ee?"bg-interactive-selection text-foreground":"text-foreground hover:bg-interactive-hover"),children:[Ke.slug==="mcp"?s.jsx(gd,{className:"h-[18px] w-[18px] shrink-0 sm:h-4 sm:w-4"}):s.jsx(O,{name:je,className:"h-[18px] w-[18px] shrink-0 sm:h-4 sm:w-4"}),s.jsxs("span",{className:"flex items-center gap-1.5 whitespace-nowrap overflow-hidden transition-opacity duration-150 opacity-100",children:[s.jsx("span",{className:"typography-ui-label font-normal truncate",children:te(Ke.slug)}),Ke.slug==="tunnel"&&s.jsx("span",{className:"shrink-0 typography-micro px-1 rounded leading-none pb-px text-[var(--status-warning)] bg-[var(--status-warning)]/10",children:l("settings.view.badge.beta")})]})]})})},Ke.slug)})]},we))})()})}),s.jsx("div",{className:"overflow-hidden transition-opacity duration-150 opacity-100",children:s.jsx("div",{className:"border-t border-border bg-background px-4 py-1.5 space-y-0.5 sm:bg-sidebar",children:(!J.isVSCode||y>0)&&s.jsx(ox,{})})})]})},Ge=()=>{if(C==="nav")return s.jsx("div",{className:"flex-1 min-h-0 overflow-hidden bg-background",children:s.jsx("div",{className:"flex h-full min-h-0 flex-col",children:s.jsx(wn,{children:Ve()})})});if(!z)return s.jsx("div",{className:"flex-1 bg-background"});if(C==="page-sidebar"){if(z.kind!=="split"){const ne=ue(f);return s.jsx(vs,{outerClassName:"flex-1 min-h-0",className:"bg-background",disableHorizontal:!0,children:s.jsx(wn,{children:ne})})}return s.jsx(vs,{outerClassName:"flex-1 min-h-0",className:"bg-background",disableHorizontal:!0,children:s.jsx(wn,{children:re(f,{onItemSelect:Ne})})})}const Z=ue(f);return s.jsx(vs,{outerClassName:"flex-1 min-h-0",className:"bg-background",disableHorizontal:!0,children:s.jsx(wn,{children:Z})})},ve=()=>!z||f==="home"?null:z.kind==="split"?s.jsxs("div",{className:"flex h-full min-h-0 overflow-hidden",children:[s.jsx("div",{className:xe("border-r",J.isVSCode?"bg-background":"bg-sidebar"),style:{width:gl,minWidth:gl,borderColor:"var(--interactive-border)"},children:s.jsx(wn,{children:re(f,{})})}),s.jsx(vs,{outerClassName:"flex-1 min-h-0",className:"bg-background",disableHorizontal:!0,children:s.jsx(wn,{children:ue(f)})})]}):s.jsx(vs,{outerClassName:"h-full min-h-0",className:"bg-background",disableHorizontal:!0,children:s.jsx(wn,{children:ue(f)})});return s.jsxs("div",{ref:w,"data-settings-view":"true",className:xe("relative flex h-full min-h-0 flex-col overflow-hidden bg-background"),children:[c?s.jsxs("div",{className:xe("flex h-[var(--oc-header-height,56px)] shrink-0 items-center gap-2 px-3",C!=="nav"&&"border-b","bg-background"),style:C!=="nav"?{borderColor:"var(--interactive-border)"}:void 0,children:[Ce?s.jsx("button",{type:"button",onClick:Oe,"aria-label":ye,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(O,{name:"arrow-left-s",className:"h-5 w-5"})}):null,s.jsx("div",{className:"min-w-0 flex-1 px-2 typography-ui-label font-medium text-foreground truncate",children:C==="nav"?l("settings.view.home.title"):z?te(z.slug):l("settings.view.home.title")}),t&&s.jsx("button",{type:"button",onClick:t,"aria-label":l("settings.view.actions.closeSettings"),title:_e,className:"inline-flex h-9 w-9 flex-shrink-0 items-center justify-center rounded-lg p-2 text-muted-foreground hover:text-foreground hover:bg-interactive-hover/50 focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-primary",children:s.jsx(O,{name:"close",className:"h-5 w-5"})})]}):s.jsxs(s.Fragment,{children:[Ce&&s.jsx("div",{className:xe("absolute left-3 z-50",a?"top-2":"top-3"),children:s.jsx("button",{type:"button",onClick:Oe,"aria-label":l("settings.view.actions.back"),className:"inline-flex h-9 w-9 items-center justify-center rounded-lg p-2 text-muted-foreground hover:text-foreground hover:bg-interactive-hover/50 focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-primary",children:s.jsx(O,{name:"arrow-left-s",className:"h-5 w-5"})})}),t&&s.jsx("div",{className:xe("absolute right-0.5 z-50",a?"top-0.5":"top-1"),children:s.jsx("button",{type:"button",onClick:t,"aria-label":l("settings.view.actions.closeSettings"),title:_e,className:"inline-flex h-7 w-7 items-center justify-center rounded-md p-0.5 text-muted-foreground hover:text-foreground hover:bg-interactive-hover/50 focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-primary",children:s.jsx(O,{name:"close",className:"h-5 w-5"})})})]}),s.jsx("div",{className:"flex flex-1 min-h-0 overflow-hidden",children:c?Ge():s.jsxs(s.Fragment,{children:[s.jsx("div",{className:xe("relative flex h-full min-h-0 flex-col overflow-hidden border-r",$?"bg-sidebar":J.isVSCode?"bg-background":"bg-sidebar"),style:{width:`${ml}px`,minWidth:`${ml}px`,borderColor:"var(--interactive-border)"},children:s.jsx(wn,{children:Ve()})}),s.jsx("div",{className:"flex-1 overflow-hidden bg-background",children:ve()})]})})]})};export{Ul as A,Tx as S};
|