@aiworker/web 1.23.1 → 1.23.3

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (72) hide show
  1. package/dist/assets/{CodeMirrorCommentWidgets-teB3HmBT.js → CodeMirrorCommentWidgets-pFeKzADY.js} +1 -1
  2. package/dist/assets/{DiffView-DC9RX3MF.js → DiffView-BYwAHIlW.js} +3 -3
  3. package/dist/assets/{DirtyBranchSwitchDialog-DwPkzXsS.js → DirtyBranchSwitchDialog-BeyJczAi.js} +1 -1
  4. package/dist/assets/{FilesView-BFZkuu4O.js → FilesView-lrP5OlzK.js} +6 -6
  5. package/dist/assets/{GitView-B_x52MHY.js → GitView-CCUK73JL.js} +4 -4
  6. package/dist/assets/{JsonTreeView-cmAzUTiw.js → JsonTreeView-CqUi8Ytj.js} +1 -1
  7. package/dist/assets/{LinearIssuesView-Dehh5afm.js → LinearIssuesView-C0WwIDQN.js} +1 -1
  8. package/dist/assets/{MarkdownImageGallery-DgNOqqhE.js → MarkdownImageGallery-0NXPad4K.js} +1 -1
  9. package/dist/assets/{MarkdownRendererImpl-DusmMZ_p.js → MarkdownRendererImpl-q-rUxBkU.js} +4 -4
  10. package/dist/assets/{OnboardingScreen-B8fm1H4m.js → OnboardingScreen-Cy6xZ-IQ.js} +1 -1
  11. package/dist/assets/{PatchDiff-BVr7gJU0.js → PatchDiff-DuYWs-7m.js} +1 -1
  12. package/dist/assets/{PierreDiffViewer-DzLt-nel.js → PierreDiffViewer-C51SEtjJ.js} +1 -1
  13. package/dist/assets/{PlanView-BmQUYT_z.js → PlanView-k63mHfFF.js} +1 -1
  14. package/dist/assets/SettingsView-DNJXHPYC.js +28 -0
  15. package/dist/assets/{SettingsWindow-Dy3M6ZB9.js → SettingsWindow-DFMJqIkx.js} +1 -1
  16. package/dist/assets/{ToolOutputDialog-cTl_eLIH.js → ToolOutputDialog-B4kBDjLK.js} +4 -4
  17. package/dist/assets/{ToolPartDiffPreview-C_3iYNJQ.js → ToolPartDiffPreview-DhVBmwis.js} +2 -2
  18. package/dist/assets/{VirtualizedFileDiff-CAWthkoy.js → VirtualizedFileDiff-C-MFNoKo.js} +1 -1
  19. package/dist/assets/{WalkthroughView-C7AHOpCA.js → WalkthroughView-hmnM70S9.js} +1 -1
  20. package/dist/assets/{computeVirtualFileMetrics-BkiDSlTW.js → computeVirtualFileMetrics-Bv64vrxY.js} +1 -1
  21. package/dist/assets/{de-DJsQr-p7.js → de-i-51iOMQ.js} +2 -2
  22. package/dist/assets/{es-BuYMlA9g.js → es-CNkqJISC.js} +3 -3
  23. package/dist/assets/{fr-ePDay33C.js → fr-a9t4bHWo.js} +3 -3
  24. package/dist/assets/index-BvwlOZOg.js +40 -0
  25. package/dist/assets/{index-n6O3hklM.js → index-C-KjDH6t.js} +1 -1
  26. package/dist/assets/index-n5p3SnES.css +1 -0
  27. package/dist/assets/{isDiffPlainText-GMdPz-71.js → isDiffPlainText-B0pMS3gs.js} +1 -1
  28. package/dist/assets/{isFilePlainText-BVuH1zH9.js → isFilePlainText-IXDeiXmH.js} +1 -1
  29. package/dist/assets/{ja-BzR9xOY_.js → ja-C2HQKC-_.js} +3 -3
  30. package/dist/assets/{ko-BEjHAm14.js → ko-CvVt6P_Q.js} +3 -3
  31. package/dist/assets/main-6ZT1mvpO.js +930 -0
  32. package/dist/assets/{main-D3ZDQglc.js → main-BeWvA5d9.js} +2 -2
  33. package/dist/assets/markdownCore-DTW1POUM.js +5 -0
  34. package/dist/assets/{miniChat-d01k801U.js → miniChat-DzMGD1Hv.js} +2 -2
  35. package/dist/assets/{mobile-D7VV-Ufz.js → mobile-CrDSF4dQ.js} +2 -2
  36. package/dist/assets/{patchFileDiff-CdztVMz0.js → patchFileDiff-DHG-znZQ.js} +3 -3
  37. package/dist/assets/{pl-rQmpxNIF.js → pl-CQi2SXLP.js} +3 -3
  38. package/dist/assets/{pt-BR-CorbsSW-.js → pt-BR-FdnmJOe8.js} +3 -3
  39. package/dist/assets/{renderElectronMiniChatApp-BGG9UIlh.js → renderElectronMiniChatApp-BuaS0XYk.js} +2 -2
  40. package/dist/assets/renderMobileApp-hxXJf_Db.js +25 -0
  41. package/dist/assets/runtimeEndpointReset-DB4KI-ED.js +41 -0
  42. package/dist/assets/{scheduledTasksApi-BEuUF_cj.js → scheduledTasksApi-DZaxQ19y.js} +1 -1
  43. package/dist/assets/{shikiHighlight-BzXUjlby.js → shikiHighlight-B1goMnV6.js} +1 -1
  44. package/dist/assets/{tr-CoAMXPtI.js → tr-BwD9HLzh.js} +2 -2
  45. package/dist/assets/{uk-YlAX0rRU.js → uk-BWNCwGJO.js} +3 -3
  46. package/dist/assets/{useAppFontEffects-Cwyhjfl5.js → useAppFontEffects-cYK1WODe.js} +130 -130
  47. package/dist/assets/useGitComparison-DIetwQtj.js +1 -0
  48. package/dist/assets/{useInlineCommentController-DDkpBEU8.js → useInlineCommentController-DscFZWyI.js} +2 -2
  49. package/dist/assets/{useRootScrollLock-CwjoWuC4.js → useRootScrollLock-CE3HJBOu.js} +1 -1
  50. package/dist/assets/{vendor-codemirror-language-data-Cb1YnICj.js → vendor-codemirror-language-data-CsvoASYk.js} +2 -2
  51. package/dist/assets/{vendor-remixicon-react-Dil0zKKT.js → vendor-remixicon-react-BDmGmFCA.js} +1 -1
  52. package/dist/assets/{web-components-LV3vjTxy.js → web-components-HM6S8xyb.js} +1 -1
  53. package/dist/assets/{zh-CN-DDYg0Jl7.js → zh-CN-CH6L_7cX.js} +6 -6
  54. package/dist/assets/{zh-TW-CQKaCayr.js → zh-TW--py9VFnc.js} +3 -3
  55. package/dist/index.html +3 -3
  56. package/dist/mini-chat.html +3 -3
  57. package/dist/mobile.html +3 -3
  58. package/package.json +2 -2
  59. package/server/lib/opencode/DOCUMENTATION.md +14 -0
  60. package/server/lib/opencode/openchamber-routes.js +72 -14
  61. package/server/lib/opencode/openchamber-routes.test.js +71 -3
  62. package/server/lib/opencode/settings-helpers.js +5 -0
  63. package/server/lib/opencode/settings-helpers.test.js +13 -1
  64. package/server/lib/opencode/settings-registry.json +3 -0
  65. package/dist/assets/SettingsView-ChWmAcZT.js +0 -28
  66. package/dist/assets/index-BD8ILbxF.js +0 -40
  67. package/dist/assets/index-zhgg-SDz.css +0 -1
  68. package/dist/assets/main-BydQ1tr_.js +0 -930
  69. package/dist/assets/markdownCore-Cb2MdZnV.js +0 -5
  70. package/dist/assets/renderMobileApp-BRP3J1iv.js +0 -25
  71. package/dist/assets/runtimeEndpointReset-BhT_-c52.js +0 -41
  72. package/dist/assets/useGitComparison-BCZVefdE.js +0 -1
@@ -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 H,I as L,o as Pn,be as wa,t as E,O as mc,g3 as gc,eG as ze,g4 as Tt,b as Gs,h as xe,at as hc,ap as on,ar as ln,as as fc,ao as cn,ew as Hn,g5 as fl,g6 as xc,g7 as ma,g8 as un,bU as vs,bO as Kt,bP as zt,bQ as _t,bR as $t,bS as Vt,bT as ts,V as He,g9 as _a,bc as dn,ej as lr,ga as vc,gb as zn,eL as Jt,gc as Ys,l as Ye,eZ as Rt,c3 as St,c4 as Ct,eW as Ft,c5 as Mt,c6 as It,c7 as at,gd as qt,c8 as Ts,dH as Fa,eY as In,e$ as xa,e_ as rn,ge as Cs,dM as xs,gf as Ps,gg as yc,cz as dt,gh as xl,gi as bc,gj as $n,gk as vl,gl as wc,fA as va,fF as Hs,gm as ha,gn as yl,go as wr,dI as bl,gp as Vn,a8 as ya,a7 as Ks,gq as wl,gr as Kr,ad as jc,eh as jl,g as Ka,gs as kc,gt as Zs,c0 as An,cb as Tn,c1 as En,eg as Nc,gu as Sc,gv as Cc,gw as jr,a9 as kr,aa as Nr,ab as kl,gx as hn,a3 as ki,bp as Sr,R as Cr,gy as zr,au as Ic,c9 as Pc,cP as Ac,T as Tc,S as Ec,U as Dc,Y as Nl,gz as Mc,gA as Rc,b_ as Lc,ca as cr,gB as Sl,ac as xi,gC as Cl,P as Un,gD as Qs,eF as zs,ep as Il,a2 as Oc,n as Xt,eb as Ni,x as Pl,w as Fc,i as Kc,j as zc,ec as Uc,p as _c,gE as $c,gF as Vc,gG as Ur,dN as Al,gH as Bc,gI as Hi,gJ as _r,gK as Hc,gL as Gc,gM as Wc,gN as qc,dT as Si,gO as fs,gP as Ss,gQ as Js,gR as Bs,aC as Cn,aD as oa,gS as Sn,eV as bn,gT as ba,gU as $r,gV as la,gW as ca,bL as Gn,gX as Jc,gY as Qc,gZ as Yc,g_ as Zc,g$ as Gi,h0 as Vr,h1 as Xc,h2 as ed,h3 as td,h4 as sd,h5 as Br,y as nd,m as Hr,d1 as ad,h6 as id,h7 as Wi,h8 as Gr,ee as rd,h9 as Ii,ha as od,hb as ld,hc as cd,hd as dd,he as ud,hf as qi,cA as pd,bM as Tl,hg as El,hh as md,ax as wn,ay as gd}from"./useAppFontEffects-cYK1WODe.js";import{h as yt,u as ie,L as cs,db as hd,dc as Wr,B as fn,aC as pn,t as gt,a2 as fd,E as as,Q as qr,ct as Jr,cA as Qr,V as Ia,p as xd,dd as vd,k as yd,cs as ua,de as bd,al as wd,cx as jd,df as kd,dg as Nd,s as Sd,e as $a,cy as Cd,F as Va,dh as Dl,$ as Id,di as Pd,x as fa,aB as ga,d1 as Ad,_ as Td,aN as Yr,b0 as ai,aO as Ed,dj as Dd,aa as Bn,dk as Md,A as Ml,dl as Zr,da as Xr,dm as eo,aL as to,dn as Rd,dp as Ld,dq as Od,dr as Fd,ds as so,b as Kd,aI as Rl,dt as Ll,du as zd,dv as Ud,dw as _d,dx as $d,dy as Vd,dz as Bd,aw as Hd,i as Ol}from"./index-BvwlOZOg.js";import{u as Gd,U as no,R as Wn,W as qn,X as Jn,Y as Qn,j as Ir,ab as _n,$ as Wd,v as As,a9 as qd,ac as pa,ad as Fl,Z as Jd,_ as Qd}from"./runtimeEndpointReset-DB4KI-ED.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-B1goMnV6.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 d=await g.json().catch(()=>null);if(!d||r)return;const y=typeof d.port=="number"&&Number.isFinite(d.port)&&d.port>0?d.port:null,p=typeof d.tunnelUrl=="string"&&d.tunnelUrl.trim().length>0?d.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(H,{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(L,{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),[d,y]=o.useState(null),p=Gd(Us(S=>({info:S.info,checking:S.checking,available:S.available,error:S.error,downloading:S.downloading,downloaded:S.downloaded,progress:S.progress,runtimeType:S.runtimeType,checkForUpdates:S.checkForUpdates,downloadUpdate:S.downloadUpdate,restartToUpdate:S.restartToUpdate}))),{isMobile:b}=wa(),c=l||p.info?.currentVersion||"unknown";o.useEffect(()=>{let S=!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),T=typeof m?.aiworkerVersion=="string"&&m.aiworkerVersion.trim().length>0?m.aiworkerVersion.trim():null;S||g(T)}catch{S||g(null)}})(),()=>{S=!0}},[]),o.useEffect(()=>{let S=!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),T=typeof m?.currentVersion=="string"&&m.currentVersion.trim().length>0?m.currentVersion.trim():null;S||y(T)}catch{S||y(null)}})(),()=>{S=!0}},[]);const I=o.useRef(!1);o.useEffect(()=>{if(p.checking)i(!0),I.current=!0;else if(r){const S=setTimeout(()=>{i(!1),I.current&&!p.available&&!p.error&&(E.success(e("settings.aiworker.about.toast.latestVersion")),I.current=!1)},ou);return()=>clearTimeout(S)}},[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:c})}),s.jsx("p",{children:e("aboutDialog.openCodeVersionLabel",{version:d||e("settings.aiworker.about.state.unknown")})})]}),s.jsx(lo,{})]}),s.jsxs("div",{className:"flex justify-center",children:[!p.available&&!p.error&&s.jsxs(H,{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(L,{name:"loader",className:"size-4 animate-spin"}):s.jsx(L,{name:"refresh",className:"size-4"}),e(f?"settings.aiworker.about.state.checking":"settings.aiworker.about.actions.checkForUpdates")]}),!f&&p.available&&s.jsxs(H,{type:"button",variant:"default",size:"sm",onClick:()=>n(!0),className:"h-10 w-auto justify-center gap-2 rounded-xl px-4",children:[s.jsx(L,{name:"download",className:"size-4"}),e("settings.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(L,{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(L,{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(L,{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:c})]}),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:d||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(L,{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(H,{size:"sm",variant:"default",onClick:()=>n(!0),children:[s.jsx(L,{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(H,{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(L,{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(L,{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 d;e[0]!==r?(d=[...r].sort(gu),e[0]=r,e[1]=d):d=e[1];const y=d;let p;e:{if(y.length===0){p=null;break e}let V;e[2]!==i||e[3]!==y?(V=y.find(k=>k.path===i)??y[0],e[2]=i,e[3]=y,e[4]=V):V=e[4],p=V}const b=p;if(g||y.length===0)return null;let c;e[5]!==b||e[6]!==n?(c=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]=c):c=e[7];const I=c;let f;e[8]!==I?(f=_l(I),e[8]=I,e[9]=f):f=e[9];const S=f;let w;e[10]!==a?(w=xe(a),e[10]=a,e[11]=w):w=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 T,R;e[16]===Symbol.for("react.memo_cache_sentinel")?(T=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(L,{name:"folder",className:"h-4 w-4 opacity-70"}),e[16]=T,e[17]=R):(T=e[16],R=e[17]);let P;e[18]!==S?(P=s.jsx("span",{className:"min-w-0 flex-1 truncate typography-ui-label font-medium",children:S}),e[18]=S,e[19]=P):P=e[19];let j;e[20]===Symbol.for("react.memo_cache_sentinel")?(j=s.jsx(L,{name:"arrow-down-s",className:"size-4 opacity-50"}),e[20]=j):j=e[20];let h;e[21]!==P||e[22]!==N||e[23]!==m?(h=s.jsx(on,{asChild:!0,children:s.jsxs("button",{type:"button","aria-label":N,title:m,className:T,children:[R,P,j]})}),e[21]=P,e[22]=N,e[23]=m,e[24]=h):h=e[24];const v=b?.id??"";let O;e[25]!==l||e[26]!==y?(O=V=>{if(!V)return;const k=y.find(D=>D.id===V);k&&l(k.path)},e[25]=l,e[26]=y,e[27]=O):O=e[27];let A;e[28]!==y?(A=y.map(hu),e[28]=y,e[29]=A):A=e[29];let C;e[30]!==v||e[31]!==O||e[32]!==A?(C=s.jsx(ln,{align:"start",className:"w-auto",children:s.jsx(fc,{value:v,onValueChange:O,children:A})}),e[30]=v,e[31]=O,e[32]=A,e[33]=C):C=e[33];let M;e[34]!==h||e[35]!==C?(M=s.jsxs(cn,{children:[h,C]}),e[34]=h,e[35]=C,e[36]=M):M=e[36];let B;return e[37]!==M||e[38]!==w?(B=s.jsx("div",{className:w,children:M}),e[37]=M,e[38]=w,e[39]=B):B=e[39],B};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 d;e[0]!==a||e[1]!==r?(d=fu(r,a),e[0]=a,e[1]=r,e[2]=d):d=e[2];const y=d,p=o.useId();let b;e[3]!==g||e[4]!==y?(b=()=>{try{const C=localStorage.getItem(y);if(C!==null)return C==="true"}catch{}return g},e[3]=g,e[4]=y,e[5]=b):b=e[5];const[c,I]=$e.useState(b);let f,S;e[6]!==c||e[7]!==y?(f=()=>{try{localStorage.setItem(y,String(c))}catch{}},S=[y,c],e[6]=c,e[7]=y,e[8]=f,e[9]=S):(f=e[8],S=e[9]),$e.useEffect(f,S);let w;e[10]===Symbol.for("react.memo_cache_sentinel")?(w=()=>I(xu),e[10]=w):w=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=!c&&"-rotate-90";let T;e[12]!==m?(T=xe("h-3.5 w-3.5 flex-shrink-0 transition-transform duration-200",m),e[12]=m,e[13]=T):T=e[13];let R;e[14]!==T?(R=s.jsx(L,{name:"arrow-down-s",className:T}),e[14]=T,e[15]=R):R=e[15];let P;e[16]!==a?(P=s.jsx("span",{className:"flex-1 truncate",children:a}),e[16]=a,e[17]=P):P=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]!==c||e[22]!==R||e[23]!==P||e[24]!==j?(h=s.jsxs("button",{type:"button",onClick:w,"aria-expanded":c,"aria-controls":p,className:N,children:[R,P,j]}),e[20]=p,e[21]=c,e[22]=R,e[23]=P,e[24]=j,e[25]=h):h=e[25];const v=!c;let O;e[26]!==l||e[27]!==p||e[28]!==v?(O=s.jsx("div",{id:p,hidden:v,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]=v,e[29]=O):O=e[29];let A;return e[30]!==h||e[31]!==O?(A=s.jsxs("div",{children:[h,O]}),e[30]=h,e[31]=O,e[32]=A):A=e[32],A};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),[d,y]=o.useState(null),[p,b]=o.useState(!1),[c,I]=o.useState(null),{selectedAgentName:f,setSelectedAgent:S,setAgentDraft:w,createAgent:N,deleteAgent:m,loadAgents:T}=Hn(Us(U=>({selectedAgentName:U.selectedAgentName,setSelectedAgent:U.setSelectedAgent,setAgentDraft:U.setAgentDraft,createAgent:U.createAgent,deleteAgent:U.deleteAgent,loadAgents:U.loadAgents}))),R=_s(),P=Hn(U=>fl(U,R));o.useEffect(()=>{T(R)},[T,R]);const j="bg-background",h=()=>{const U="new-agent";let le=U,_=1;for(;P.some(G=>G.name===le);)le=`${U}-${_}`,_++;w({name:le,scope:"user"}),S(le),t?.()},v=async U=>{if(ma(U)){E.error(e("settings.agents.sidebar.toast.builtInCannotDelete"));return}g(U),y("delete")},O=async U=>{ma(U)&&(g(U),y("reset"))},A=()=>{g(null),y(null)},C=async()=>{if(!(!l||!d)){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")):d==="delete"?E.success(e("settings.agents.sidebar.toast.agentDeleted",{name:l.name})):E.success(e("settings.agents.sidebar.toast.agentReset",{name:l.name})),A()):d==="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);d==="delete"?E.error(e(_?"settings.agents.sidebar.toast.definitionNotFound":"settings.agents.sidebar.toast.deleteFailed")):E.error(e("settings.agents.sidebar.toast.resetFailed"))}b(!1)}},M=U=>{const le=U.name;let _=1,G=`${le}-copy`;for(;P.some(Y=>Y.name===G);)_++,G=`${le}-copy-${_}`;const z=U,F=U.model?.providerID&&U.model?.modelID?`${U.model.providerID}/${U.model.modelID}`:null,ee=U;w({name:G,scope:z.scope||"user",description:U.description,model:F,variant:U.variant,temperature:U.temperature,top_p:U.topP,prompt:U.prompt,mode:U.mode,permission:po(U.permission),disable:ee.disable}),S(G),t?.()},B=U=>{i(U.name),n(U)},V=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(P.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,G=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(G.ok){const z=await m(a.name,_.scope,R);z.ok?(G.requiresManualRestart||z.requiresManualRestart?E.warning(e("settings.agents.page.toast.savedManualRestart")):E.success(e("settings.agents.sidebar.toast.agentRenamed",{name:U})),S(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(L,{name:"ai-agent",className:"h-3 w-3 text-primary"});case"all":return s.jsx(L,{name:"ai-agent-fill",className:"h-3 w-3 text-primary"});case"subagent":return s.jsx(L,{name:"robot",className:"h-3 w-3 text-primary"});default:return null}},D=P.filter(U=>!xc(U)),$=D.filter(ma),K=D.filter(U=>!ma(U)),{groupedCustomAgents:Q,ungroupedCustomAgents:te}=$e.useMemo(()=>{const U={},le=[];for(const G of K){const z=G;z.group?(U[z.group]||(U[z.group]=[]),U[z.group].push(G)):le.push(G)}return{groupedCustomAgents:Object.keys(U).sort((G,z)=>G.localeCompare(z)).map(G=>({name:G,agents:U[G]})),ungroupedCustomAgents:le}},[K]);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:D.length})}),s.jsx(H,{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(L,{name:"add",className:"h-3.5 w-3.5"})})]})]}),s.jsx(vs,{outerClassName:"flex-1 min-h-0",className:"space-y-1 px-3 py-2 overflow-x-hidden",children:D.length===0?s.jsxs("div",{className:"py-12 px-4 text-center text-muted-foreground",children:[s.jsx(L,{name:"robot-2",className:"mx-auto mb-3 h-10 w-10 opacity-50"}),s.jsx("p",{className:"typography-ui-label font-medium",children:e("settings.agents.sidebar.empty.title")}),s.jsx("p",{className:"typography-meta mt-1 opacity-75",children:e("settings.agents.sidebar.empty.description")})]}):s.jsxs(s.Fragment,{children:[$.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")}),$.map(U=>s.jsx(Ji,{agent:U,isSelected:f===U.name,onSelect:()=>{S(U.name),t?.()},onReset:()=>O(U),onDuplicate:()=>M(U),getAgentModeIcon:k,isMenuOpen:c===U.name,onMenuOpenChange:le=>I(le?U.name:null)},U.name))]}),K.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")}),Q.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:()=>{S(_.name),t?.()},onRename:()=>B(_),onDelete:()=>v(_),onDuplicate:()=>M(_),getAgentModeIcon:k,isMenuOpen:c===_.name,onMenuOpenChange:G=>I(G?_.name:null)},_.name))},U)),te.map(U=>s.jsx(Ji,{agent:U,isSelected:f===U.name,onSelect:()=>{S(U.name),t?.()},onRename:()=>B(U),onDelete:()=>v(U),onDuplicate:()=>M(U),getAgentModeIcon:k,isMenuOpen:c===U.name,onMenuOpenChange:le=>I(le?U.name:null)},U.name))]})]})}),s.jsx(Kt,{open:l!==null&&d!==null,onOpenChange:U=>{!U&&!p&&A()},children:s.jsxs(zt,{className:"max-w-md",children:[s.jsxs(_t,{children:[s.jsx($t,{children:e(d==="delete"?"settings.agents.sidebar.dialog.deleteTitle":"settings.agents.sidebar.dialog.resetTitle")}),s.jsx(Vt,{children:d==="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(H,{size:"sm",variant:"ghost",onClick:A,disabled:p,children:e("settings.common.actions.cancel")}),s.jsx(H,{size:"sm",onClick:C,disabled:p,children:e(d==="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"&&V()}}),s.jsxs(ts,{children:[s.jsx(H,{size:"sm",variant:"ghost",onClick:()=>n(null),children:e("settings.common.actions.cancel")}),s.jsx(H,{size:"sm",onClick:V,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:d,getAgentModeIcon:y,isMenuOpen:p,onMenuOpenChange:b}=t,{t:c}=tt(),I=a;let f;e[0]===Symbol.for("react.memo_cache_sentinel")?(f=_a(),e[0]=f):f=e[0];const S=f,[w,N]=o.useState(!1);let m;e[1]!==i||e[2]!==d||e[3]!==g||e[4]!==l||e[5]!==c?(m=le=>s.jsxs(s.Fragment,{children:[g&&s.jsxs(le,{onClick:_=>{_.stopPropagation(),g()},children:[s.jsx(L,{name:"edit",className:"h-4 w-4 mr-px"}),c("settings.common.actions.rename")]}),s.jsxs(le,{onClick:_=>{_.stopPropagation(),d()},children:[s.jsx(L,{name:"file-copy",className:"h-4 w-4 mr-px"}),c("settings.common.actions.duplicate")]}),l&&s.jsxs(le,{onClick:_=>{_.stopPropagation(),l()},children:[s.jsx(L,{name:"restart",className:"h-4 w-4 mr-px"}),c("settings.common.actions.reset")]}),i&&s.jsxs(le,{onClick:_=>{_.stopPropagation(),i()},className:"text-destructive focus:text-destructive",children:[s.jsx(L,{name:"delete-bin",className:"h-4 w-4 mr-px"}),c("settings.common.actions.delete")]})]}),e[1]=i,e[2]=d,e[3]=g,e[4]=l,e[5]=c,e[6]=m):m=e[6];const T=m,R=n?"bg-interactive-selection":"hover:bg-interactive-hover";let P;e[7]!==R?(P=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]=P):P=e[8];let j;e[9]===Symbol.for("react.memo_cache_sentinel")?(j=S?void 0:le=>{le.preventDefault(),N(!0)},e[9]=j):j=e[9];let h;e[10]!==P?(h=s.jsx("div",{className:P,onContextMenu:j}),e[10]=P,e[11]=h):h=e[11];let v;e[12]!==a.name?(v=s.jsx("span",{className:"typography-ui-label font-normal truncate text-foreground",children:a.name}),e[12]=a.name,e[13]=v):v=e[13];let O;e[14]!==a.mode||e[15]!==y?(O=y(a.mode),e[14]=a.mode,e[15]=y,e[16]=O):O=e[16];let A;e[17]!==a||e[18]!==I.scope||e[19]!==c?(A=(I.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)?c("settings.agents.sidebar.badge.system"):I.scope}),e[17]=a,e[18]=I.scope,e[19]=c,e[20]=A):A=e[20];let C;e[21]!==v||e[22]!==O||e[23]!==A?(C=s.jsxs("div",{className:"flex items-center gap-1.5",children:[v,O,A]}),e[21]=v,e[22]=O,e[23]=A,e[24]=C):C=e[24];let M;e[25]!==a.description?(M=a.description&&s.jsx("div",{className:"typography-micro text-muted-foreground/60 truncate leading-tight",children:a.description}),e[25]=a.description,e[26]=M):M=e[26];let B;e[27]!==r||e[28]!==C||e[29]!==M?(B=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:[C,M]}),e[27]=r,e[28]=C,e[29]=M,e[30]=B):B=e[30];let V;e[31]!==b?(V=le=>{le&&N(!1),b(le)},e[31]=b,e[32]=V):V=e[32];let k;e[33]===Symbol.for("react.memo_cache_sentinel")?(k=s.jsx(on,{asChild:!0,children:s.jsx(H,{size:"sm",variant:"ghost",className:"h-6 w-6 px-0 flex-shrink-0 -mr-1 opacity-100 transition-opacity md:opacity-0 md:group-hover:opacity-100",children:s.jsx(L,{name:"more-2",className:"h-3.5 w-3.5"})})}),e[33]=k):k=e[33];let D;e[34]!==T?(D=s.jsx(ln,{align:"end",className:"w-fit min-w-20",children:T(dn)}),e[34]=T,e[35]=D):D=e[35];let $;e[36]!==p||e[37]!==V||e[38]!==D?($=s.jsxs(cn,{open:p,onOpenChange:V,children:[k,D]}),e[36]=p,e[37]=V,e[38]=D,e[39]=$):$=e[39];let K;e[40]!==B||e[41]!==$?(K=s.jsxs("div",{className:"flex min-w-0 flex-1 items-center",children:[B,$]}),e[40]=B,e[41]=$,e[42]=K):K=e[42];let Q;e[43]!==K||e[44]!==h?(Q=s.jsx(Jn,{render:h,children:K}),e[43]=K,e[44]=h,e[45]=Q):Q=e[45];let te;e[46]!==T?(te=s.jsx(Wn,{className:"w-fit min-w-20",children:T(qn)}),e[46]=T,e[47]=te):te=e[47];let U;return e[48]!==w||e[49]!==Q||e[50]!==te?(U=s.jsxs(Qn,{open:w,onOpenChange:N,children:[Q,te]}),e[48]=w,e[49]=Q,e[50]=te,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:d,headerEnd:y,showSaveStatus:p}=t,b=p===void 0?!1:p,c=i!=null||d!=null||y!=null||b,I=typeof i=="string"||typeof i=="number",f=l!=null||g!=null;let S;e[0]!==r?(S=xe("h-full",r),e[0]=r,e[1]=S):S=e[1];let w;e[2]!==n?(w=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]=w):w=e[3];let N;e[4]!==d||e[5]!==c||e[6]!==f||e[7]!==y||e[8]!==I||e[9]!==b||e[10]!==i||e[11]!==g||e[12]!==l?(N=c&&s.jsxs("div",{className:"mb-2 flex flex-wrap items-start justify-between gap-x-4 gap-y-3 pb-6",children:[s.jsxs("div",{className:"min-w-0 flex-1 basis-64 space-y-1",children:[i!=null?I?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,d!=null?typeof d=="string"||typeof d=="number"?s.jsx("p",{className:vc,children:d}):d:null]}),s.jsxs("div",{className:"flex shrink-0 flex-wrap items-center justify-end gap-3",children:[y,b&&s.jsx(ju,{})]})]}),e[4]=d,e[5]=c,e[6]=f,e[7]=y,e[8]=I,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]!==w||e[16]!==N?(m=s.jsxs("div",{className:w,children:[N,a]}),e[14]=a,e[15]=w,e[16]=N,e[17]=m):m=e[17];let T;return e[18]!==S||e[19]!==m?(T=s.jsx(vs,{outerClassName:S,className:"w-full @container",children:m}),e[18]=S,e[19]=m,e[20]=T):T=e[20],T},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(L,{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 c;return t[6]!==b?(c=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]=c):c=t[7],c}if(a!=="saving"||!n)return null;let g;t[8]===Symbol.for("react.memo_cache_sentinel")?(g=s.jsx(L,{name:"loader-4",className:"size-3.5 animate-spin"}),t[8]=g):g=t[8];let d;t[9]!==e?(d=e("settings.common.actions.saving"),t[9]=e,t[10]=d):d=t[10];let y;return t[11]!==d?(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:d})]}),t[11]=d,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,d]=o.useState(!0),[y,p]=o.useState(!1),[b,c]=o.useState(!1),[I,f]=o.useState({}),[S,w]=o.useState([]),[N,m]=o.useState(""),[T,R]=o.useState(0),P=t.name,j=_s();o.useEffect(()=>{let z=!1;return d(!0),p(!1),(async()=>{try{const F=j,ee=F?`?directory=${encodeURIComponent(F)}`:"",Y=await yt(`/api/config/agents/${encodeURIComponent(P)}/config${ee}`,{headers:{"Cache-Control":"no-cache",...F?{"x-opencode-directory":F}:{}}});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||d(!1)}})(),()=>{z=!0}},[P,T,j]),o.useEffect(()=>{let z=!1;return(async()=>{try{const F=await fn.listToolIds({directory:j});!z&&Array.isArray(F)&&w(F.filter(ee=>typeof ee=="string"&&!mo.has(ee)))}catch{}})(),()=>{z=!0}},[P,j]);const h=o.useMemo(()=>{const z=t.permission;if(!Array.isArray(z))return[];const F=[];for(const ee of z){if(!ee||typeof ee!="object")continue;const{permission:Y,pattern:ae,action:ge}=ee;typeof Y=="string"&&typeof ae=="string"&&Oa(ge)&&F.push({permission:Y,pattern:ae,action:ge})}return F},[t]),v=o.useCallback(z=>{const F=h.find(Y=>Y.permission===z&&Y.pattern==="*");if(F)return F.action;const ee=h.find(Y=>Y.permission==="*"&&Y.pattern==="*");return ee?ee.action:null},[h]),O=o.useCallback(z=>{const F=i.keys[z]?.patterns??[],ee=new Set(F.map(Y=>Y.pattern));return h.filter(Y=>Y.permission===z&&Y.pattern!=="*"&&!ee.has(Y.pattern))},[h,i.keys]),A=o.useMemo(()=>{const z=new Set;for(const F of S)z.add(F);for(const F of Cu)z.add(F);for(const F of Object.keys(i.keys))z.add(F);for(const F of mo)z.delete(F);return Array.from(z).sort((F,ee)=>F.localeCompare(ee))},[S,i.keys]),C=o.useMemo(()=>!Su(i,n),[i,n]),M=z=>{l(F=>({...F,global:z}))},B=(z,F)=>{l(ee=>{const Y=jn(ee),ae=Y.keys[z]??{action:null,patterns:[]};return ae.action=F,ae.action===null&&ae.patterns.length===0?delete Y.keys[z]:Y.keys[z]=ae,Y})},V=(z,F,ee,Y)=>{l(ae=>{const ge=jn(ae),de=ge.keys[z]??{action:null,patterns:[]};return de.patterns[F]={pattern:ee,action:Y},ge.keys[z]=de,ge})},k=z=>{l(F=>{const ee=jn(F),Y=ee.keys[z]??{action:null,patterns:[]};return Y.patterns.push({pattern:"",action:"allow"}),ee.keys[z]=Y,ee}),f(F=>({...F,[z]:!0}))},D=(z,F)=>{l(ee=>{const Y=jn(ee),ae=Y.keys[z];return ae?(ae.patterns.splice(F,1),ae.action===null&&ae.patterns.length===0&&delete Y.keys[z],Y):ee})},$=()=>{const z=N.trim();!z||z==="*"||(l(F=>{if(F.keys[z])return F;const ee=jn(F);return ee.keys[z]={action:"ask",patterns:[]},ee}),f(F=>({...F,[z]:!0})),m(""))},K=async()=>{c(!0);try{const z=pr(i),F=await a(P,{permission:z});F.ok?(r(jn(i)),E.success(F.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{c(!1)}},Q=()=>{l(jn(n))},te=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(F=>({value:F,label:te(F)}))],G=(z,F,ee,Y=U)=>s.jsx(Ys,{value:z??"inherit",options:_(Y),onChange:ae=>F(ae==="inherit"?null:ae),"aria-label":ee});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(H,{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:C?s.jsxs("div",{className:"flex items-center gap-2",children:[s.jsx(H,{variant:"ghost",size:"xs",className:"!font-normal",onClick:Q,disabled:b,children:e("settings.agents.page.permissionsEditor.actions.discard")}),s.jsx(H,{size:"xs",className:"!font-normal",onClick:()=>{K()},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:te(v("*")??"allow")})})]}),G(i.global,M,e("settings.agents.page.permissionsEditor.defaultAria"),le)]}),s.jsx("div",{children:A.map(z=>{const F=i.keys[z]??{action:null,patterns:[]},ee=O(z),Y=Iu.has(z)||F.patterns.length>0,ae=Y||ee.length>0,ge=I[z]===!0,de=v(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(L,{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}),F.action===null&&de!==null&&s.jsx("span",{className:"typography-micro text-muted-foreground",children:e("settings.agents.page.permissionsEditor.effectiveHint",{action:te(de)})}),F.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(F.patterns.length)})})]}),G(F.action,he=>B(z,he),e("settings.agents.page.permissionsEditor.keyAria",{key:z}))]}),ge&&ae&&s.jsxs("div",{className:"mt-2 space-y-2 pl-5",children:[F.patterns.map((he,se)=>s.jsxs("div",{className:"flex flex-wrap items-center gap-2",children:[s.jsx(He,{value:he.pattern,onChange:re=>V(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=>V(z,se,he.pattern,re),"aria-label":e("settings.agents.page.permissionsEditor.patternActionAria",{key:z})}),s.jsx(H,{variant:"ghost",size:"icon",className:"h-7 w-7 shrink-0 text-muted-foreground hover:bg-destructive/10 hover:text-destructive",onClick:()=>D(z,se),"aria-label":e("settings.agents.page.permissionsEditor.actions.removeRuleAria"),children:s.jsx(L,{name:"close",className:"h-3.5 w-3.5"})})]},se)),Y&&s.jsxs(H,{variant:"outline",size:"xs",className:"!font-normal",onClick:()=>k(z),children:[s.jsx(L,{name:"add",className:"mr-1 h-3.5 w-3.5"}),e("settings.agents.page.permissionsEditor.actions.addRule")]}),ee.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")})]}),ee.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:te(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(),$())},placeholder:e("settings.agents.page.permissionsEditor.customKeyPlaceholder"),className:"h-8 w-full max-w-[16rem] font-mono text-xs"}),s.jsxs(H,{variant:"outline",size:"xs",className:"!font-normal",onClick:$,disabled:!N.trim(),children:[s.jsx(L,{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(G=>G.providers),{selectedAgentName:a,getAgentByName:n,createAgent:r,updateAgent:i,agentDraft:l,setAgentDraft:g}=Hn(Us(G=>({selectedAgentName:G.selectedAgentName,getAgentByName:G.getAgentByName,createAgent:G.createAgent,updateAgent:G.updateAgent,agentDraft:G.agentDraft,setAgentDraft:G.setAgentDraft}))),d=_s(),y=Hn(G=>fl(G,d)),p=a?n(a,d):null,b=!!(l&&l.name===a&&!p),[c,I]=o.useState(""),[f,S]=o.useState("user"),[w,N]=o.useState(""),[m,T]=o.useState("subagent"),[R,P]=o.useState(""),[j,h]=o.useState(""),[v,O]=o.useState(void 0),[A,C]=o.useState(void 0),[M,B]=o.useState(""),[V,k]=o.useState(!1),D=o.useRef(null),$=o.useMemo(()=>Tu(e,R),[R,e]),K=$.length>0,Q=j||"__default",te=K,U=o.useMemo(()=>j&&!$.includes(j)?[j,...$]:$,[j,$]);o.useEffect(()=>{if(b&&l){const G=l.name||"",z=l.scope||"user",F=l.description||"",ee=l.mode||"subagent",Y=l.model||"",ae=l.variant||"",ge=l.temperature??void 0,de=l.top_p??void 0,he=l.prompt||"";I(G),S(z),N(F),T(ee),P(Y),h(ae),O(ge),C(de),B(he),D.current={draftName:G,draftScope:z,description:F,mode:ee,model:Y,variant:ae,temperature:ge,topP:de,prompt:he};return}if(p&&a===p.name){const G=p.description||"",z=p.mode||"subagent",F=p.model?.providerID&&p.model?.modelID?`${p.model.providerID}/${p.model.modelID}`:"",ee=p.variant||"",Y=p.temperature??void 0,ae=p.topP??void 0,ge=p.prompt||"";N(G),T(z),P(F),h(ee),O(Y),C(ae),B(ge),D.current={draftName:"",draftScope:"user",description:G,mode:z,model:F,variant:ee,temperature:Y,topP:ae,prompt:ge}}},[l,b,p,a]);const le=o.useMemo(()=>{const G=D.current;return G?!!(b&&(c!==G.draftName||f!==G.draftScope)||w!==G.description||m!==G.mode||R!==G.model||j!==G.variant||v!==G.temperature||A!==G.topP||M!==G.prompt):!1},[w,c,f,b,m,R,M,v,A,j]),_=async()=>{const G=b?c.trim().replace(/\s+/g,"-"):a?.trim();if(!G){E.error(t("settings.agents.sidebar.toast.agentNameRequired"));return}if(b&&y.some(z=>z.name===G)){E.error(t("settings.agents.sidebar.toast.agentExists"));return}k(!0);try{const z=R.trim(),F=j.trim(),ee=M.trim(),Y={name:G,...w.trim()?{description:w.trim()}:{},mode:m,model:z===""?null:z,variant:F===""?null:F||void 0,temperature:v??null,top_p:A??null,prompt:ee||(b?void 0:null),...b&&f?{scope:f}:{}};let ae;b?(ae=await r(Y,d),ae.ok&&g(null)):ae=await i(G,Y,d),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 F=z instanceof Error&&z.message?z.message:t("settings.agents.page.toast.saveUnexpectedError");E.error(F)}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:c,onChange:G=>I(G.target.value),placeholder:t("settings.agents.page.field.agentNamePlaceholder"),className:"h-7 w-40 px-2"})]}),s.jsxs(St,{value:f,onValueChange:G=>S(G),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(L,{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(L,{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:w,onChange:G=>N(G.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:T,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:(G,z)=>{P(G&&z?`${G}/${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:te?s.jsxs(St,{value:Q,onValueChange:G=>h(G==="__default"?"":G),children:[s.jsx(Ct,{size:Ft,className:rn,children:s.jsx(Mt,{placeholder:t("settings.agents.page.field.variantPlaceholder"),children:G=>G==="__default"?t("chat.modelControls.default"):G})}),s.jsxs(It,{children:[s.jsx(at,{value:"__default",children:t("chat.modelControls.default")}),U.map(G=>s.jsx(at,{value:G,children:G},G))]})]}):s.jsxs(s.Fragment,{children:[s.jsx(He,{value:j,onChange:G=>h(G.target.value),placeholder:t("settings.agents.page.field.variantPlaceholder"),disabled:!R&&!j,className:"h-8 w-40 rounded-md px-3"}),j&&s.jsx(H,{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(L,{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:v,fallbackValue:.7,onValueChange:O,onClear:()=>O(void 0),min:0,max:2,step:.1,inputMode:"decimal",placeholder:"—",emptyLabel:"—",className:Ps}),v!==void 0&&s.jsx(H,{size:"sm",type:"button",variant:"ghost",onClick:()=>O(void 0),className:Cs,"aria-label":t("settings.agents.page.field.clearTemperatureAria"),title:t("settings.common.actions.clear"),children:s.jsx(L,{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:A,fallbackValue:.9,onValueChange:C,onClear:()=>C(void 0),min:0,max:1,step:.1,inputMode:"decimal",placeholder:"—",emptyLabel:"—",className:Ps}),A!==void 0&&s.jsx(H,{size:"sm",type:"button",variant:"ghost",onClick:()=>C(void 0),className:Cs,"aria-label":t("settings.agents.page.field.clearTopPAria"),title:t("settings.common.actions.clear"),children:s.jsx(L,{name:"close",className:"h-3.5 w-3.5"})})]})]}),s.jsx(ze,{title:t("settings.agents.page.section.systemPrompt"),settingsItem:"agents.system-prompt",children:s.jsx(Ts,{value:M,onChange:G=>B(G.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(H,{onClick:_,disabled:V||!le,size:"xs",className:"!font-normal",children:t(V?"settings.common.actions.saving":"settings.common.actions.saveChanges")})})]}):s.jsx("div",{className:"flex h-full items-center justify-center",children:s.jsxs("div",{className:"text-center text-muted-foreground",children:[s.jsx(L,{name:"robot-2",className:"mx-auto mb-3 h-12 w-12 opacity-50"}),s.jsx("p",{className:"typography-body",children:t("settings.agents.page.empty.title")}),s.jsx("p",{className:"typography-meta mt-1 opacity-75",children:t("settings.agents.page.empty.description")})]})})},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),[d,y]=o.useState(ii.responseStyleEnabled),[p,b]=o.useState(ii.responseStylePreset),[c,I]=o.useState(ii.responseStyleCustomInstructions),[f,S]=o.useState(!0),[w,N]=o.useState(!1),[m,T]=o.useState(!1),[R,P]=o.useState(""),[j,h]=o.useState(!1),v=o.useRef(null);o.useEffect(()=>{const V=new AbortController;return(async()=>{try{const[D,$]=await Promise.all([pn(),yt("/api/behavior/agents-md",{method:"GET",headers:{Accept:"application/json"},signal:V.signal})]);let K=ii;if(D&&(K={...K,optimizeSystemPrompt:D.optimizeSystemPrompt===!0,responseStyleEnabled:D.responseStyleEnabled===!0,responseStylePreset:Ou(D.responseStylePreset),responseStyleCustomInstructions:D.responseStyleCustomInstructions??""},D.globalBehaviorPrompt!==void 0&&(K={...K,prompt:D.globalBehaviorPrompt})),$.ok){const Q=Du.parse(await $.json());if(V.signal.aborted)return;i(Q.path??"AGENTS.md"),K.prompt.trim()||(K={...K,prompt:Q.content})}n(K.prompt),g(K.optimizeSystemPrompt),h(K.optimizeSystemPrompt),y(K.responseStyleEnabled),b(K.responseStylePreset),I(K.responseStyleCustomInstructions),P(K.prompt),v.current={enabled:K.responseStyleEnabled,preset:K.responseStylePreset,custom:K.responseStyleCustomInstructions}}catch(D){D.name!=="AbortError"&&console.warn("Failed to load behavior settings:",D)}finally{S(!1)}})(),()=>V.abort()},[]),o.useEffect(()=>{if(f)return;const V=v.current;if(V&&V.enabled===d&&V.preset===p&&V.custom===c)return;const k={enabled:d,preset:p,custom:c},D=setTimeout(async()=>{try{await Qi({responseStyleEnabled:k.enabled,responseStylePreset:k.preset,responseStyleCustomInstructions:k.custom},t("settings.behavior.page.toast.saveFailed")),v.current=k}catch($){const K=$ instanceof Error?$.message:t("settings.behavior.page.toast.saveFailed");E.error(K)}},400);return()=>clearTimeout(D)},[d,p,c,f,t]);const O=Lu(p,c),A=a!==R,C=l!==j,M=async()=>{N(!0);try{const V=Ru(a),k=await yt("/api/behavior/agents-md",{method:"PUT",headers:{"Content-Type":"application/json",Accept:"application/json"},body:JSON.stringify({content:V})});if(!k.ok)throw new Error(await Mu(k,t("settings.behavior.page.toast.saveFailed")));const D=await k.json().catch(()=>null),$=vl(D,"behavior",{id:"agents-md"});await Qi({globalBehaviorPrompt:V},t("settings.behavior.page.toast.saveFailed")),n(V),P(V),E.success(t($?"settings.view.pendingRestart.saved":"settings.behavior.page.toast.saved"))}catch(V){console.error("Failed to save behavior:",V);const k=V instanceof Error?V.message:t("settings.behavior.page.toast.saveFailed");E.error(k)}finally{N(!1)}},B=async()=>{T(!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(V){const k=V instanceof Error?V.message:t("settings.behavior.page.toast.saveFailed");E.error(k)}finally{T(!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(H,{type:"button",size:"xs",onClick:()=>{B()},disabled:f||m||!C,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:V=>n(V.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(H,{onClick:M,disabled:w||!A||f,size:"xs",className:"!font-normal",children:t(w?"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:d,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:V=>b(V),disabled:f||!d,children:[s.jsx(Ct,{size:Ft,className:rn,children:s.jsx(Mt,{children:V=>V==="custom"?t("settings.behavior.page.responseStyle.option.custom"):xl(V)?t(go[V]):null})}),s.jsxs(It,{children:[bc.map(V=>s.jsx(at,{value:V,children:t(go[V])},V)),s.jsx(at,{value:"custom",children:t("settings.behavior.page.responseStyle.option.custom")})]})]})}),s.jsx(Ts,{value:O,onChange:V=>I(V.target.value),placeholder:t("settings.behavior.page.responseStyle.customPlaceholder"),rows:5,disabled:f||!d||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(""),[d,y]=o.useState(null),[p,b]=o.useState(null),[c,I]=o.useState(!1),[f,S]=o.useState(null),{selectedCommandName:w,setSelectedCommand:N,setCommandDraft:m,createCommand:T,deleteCommand:R,loadCommands:P}=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 v=va(h);let O;e[2]!==j?(O=Be=>wr(Be,j),e[2]=j,e[3]=O):O=e[3];const A=Hs(O),C=Hs(Uu);let M,B;e[4]!==P||e[5]!==C||e[6]!==j?(M=()=>{P(j),C(j)},B=[P,C,j],e[4]=P,e[5]=C,e[6]=j,e[7]=M,e[8]=B):(M=e[7],B=e[8]),o.useEffect(M,B);let V;e[9]!==A?(V=new Set(A.map(_u)),e[9]=A,e[10]=V):V=e[10];const k=V;let D;if(e[11]!==v||e[12]!==k){let Be;e[14]!==k?(Be=Et=>!k.has(Et.name),e[14]=k,e[15]=Be):Be=e[15],D=v.filter(Be),e[11]=v,e[12]=k,e[13]=D}else D=e[13];const $=D;let K,Q;e[16]!==w||e[17]!==N||e[18]!==k?(K=()=>{w&&k.has(w)&&N(null)},Q=[w,N,k],e[16]=w,e[17]=N,e[18]=k,e[19]=K,e[20]=Q):(K=e[19],Q=e[20]),o.useEffect(K,Q);let te;e[21]!==v||e[22]!==a||e[23]!==m||e[24]!==N?(te=()=>{let Be="new-command",Et=1;for(;v.some(Me=>Me.name===Be);)Be=`new-command-${Et}`,Et++;m({name:Be,scope:"user"}),N(Be),a?.()},e[21]=v,e[22]=a,e[23]=m,e[24]=N,e[25]=te):te=e[25];const U=te;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 G;e[28]===Symbol.for("react.memo_cache_sentinel")?(G=async Be=>{ha(Be)&&(y(Be),b("reset"))},e[28]=G):G=e[28];const z=G;let F;e[29]===Symbol.for("react.memo_cache_sentinel")?(F=()=>{y(null),b(null)},e[29]=F):F=e[29];const ee=F;let Y;e[30]!==d||e[31]!==p||e[32]!==R||e[33]!==j||e[34]!==n?(Y=async()=>{if(!d||!p)return;I(!0),await R(d.name,j)?(p==="delete"?E.success(n("settings.commands.sidebar.toast.commandDeleted",{name:d.name})):E.success(n("settings.commands.sidebar.toast.commandReset",{name:d.name})),ee()):p==="delete"?E.error(n("settings.commands.sidebar.toast.deleteFailed")):E.error(n("settings.commands.sidebar.toast.resetFailed")),I(!1)},e[30]=d,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]!==v||e[37]!==m||e[38]!==N?(ge=Be=>{const Et=Be.name;let Me=1,wt=`${Et}-copy`;for(;v.some(J=>J.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]=v,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]!==v||e[42]!==T||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(v.some(Me=>Me.name===Be)){E.error(n("settings.commands.sidebar.toast.commandExists"));return}await T({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]=v,e[42]=T,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]!==$||e[51]!==U||e[52]!==_||e[53]!==de||e[54]!==a||e[55]!==f||e[56]!==w||e[57]!==N||e[58]!==n){const Be=$.filter(ha),Et=$.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 J;e[70]===Symbol.for("react.memo_cache_sentinel")?(J=s.jsx(Ba,{className:"mb-3"}),e[70]=J):J=e[70];let pe;e[71]!==$.length||e[72]!==n?(pe=n("settings.commands.sidebar.total",{count:$.length}),e[71]=$.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(L,{name:"add",className:"h-3.5 w-3.5"}),e[76]=Ae):Ae=e[76];let it;e[77]!==U?(it=s.jsx(H,{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,J,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=$.length===0?s.jsxs("div",{className:"py-12 px-4 text-center text-muted-foreground",children:[s.jsx(L,{name:"terminal-box",className:"mx-auto mb-3 h-10 w-10 opacity-50"}),s.jsx("p",{className:"typography-ui-label font-medium",children:n("settings.commands.sidebar.empty.title")}),s.jsx("p",{className:"typography-meta mt-1 opacity-75",children:n("settings.commands.sidebar.empty.description")})]}):s.jsxs(s.Fragment,{children:[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:w===qe.name,onSelect:()=>{N(qe.name),a?.()},onReset:()=>z(qe),onDuplicate:()=>de(qe),isMenuOpen:f===qe.name,onMenuOpenChange:Pt=>S(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:w===qe.name,onSelect:()=>{N(qe.name),a?.()},onRename:()=>se(qe),onDelete:()=>_(qe),onDuplicate:()=>de(qe),isMenuOpen:f===qe.name,onMenuOpenChange:Pt=>S(Pt?qe.name:null)},qe.name))]})]}),e[50]=$,e[51]=U,e[52]=_,e[53]=de,e[54]=a,e[55]=f,e[56]=w,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=d!==null&&p!==null;let Ve;e[90]!==c?(Ve=Be=>{!Be&&!c&&ee()},e[90]=c,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]!==d?.name||e[98]!==p||e[99]!==n?(Z=p==="delete"?n("settings.commands.sidebar.dialog.deleteDescription",{name:d?.name??""}):n("settings.commands.sidebar.dialog.resetDescription",{name:d?.name??""}),e[97]=d?.name,e[98]=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]!==c||e[109]!==we?(Re=s.jsx(H,{size:"sm",variant:"ghost",onClick:ee,disabled:c,children:we}),e[108]=c,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]!==c||e[116]!==Fe?(Ke=s.jsx(H,{size:"sm",onClick:ae,disabled:c,children:Fe}),e[114]=ae,e[115]=c,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(H,{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(H,{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:d,isMenuOpen:y,onMenuOpenChange:p}=t,{t:b}=tt();let c;e[0]===Symbol.for("react.memo_cache_sentinel")?(c=_a(),e[0]=c):c=e[0];const I=c,[f,S]=o.useState(!1);let w;e[1]!==i||e[2]!==d||e[3]!==g||e[4]!==l||e[5]!==b?(w=Q=>s.jsxs(s.Fragment,{children:[g&&s.jsxs(Q,{onClick:te=>{te.stopPropagation(),g()},children:[s.jsx(L,{name:"edit",className:"h-4 w-4 mr-px"}),b("settings.common.actions.rename")]}),s.jsxs(Q,{onClick:te=>{te.stopPropagation(),d()},children:[s.jsx(L,{name:"file-copy",className:"h-4 w-4 mr-px"}),b("settings.common.actions.duplicate")]}),l&&s.jsxs(Q,{onClick:te=>{te.stopPropagation(),l()},children:[s.jsx(L,{name:"restart",className:"h-4 w-4 mr-px"}),b("settings.common.actions.reset")]}),i&&s.jsxs(Q,{onClick:te=>{te.stopPropagation(),i()},className:"text-destructive focus:text-destructive",children:[s.jsx(L,{name:"delete-bin",className:"h-4 w-4 mr-px"}),b("settings.common.actions.delete")]})]}),e[1]=i,e[2]=d,e[3]=g,e[4]=l,e[5]=b,e[6]=w):w=e[6];const N=w,m=n?"bg-interactive-selection":"hover:bg-interactive-hover";let T;e[7]!==m?(T=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]=T):T=e[8];let R;e[9]===Symbol.for("react.memo_cache_sentinel")?(R=I?void 0:Q=>{Q.preventDefault(),S(!0)},e[9]=R):R=e[9];let P;e[10]!==T?(P=s.jsx("div",{className:T,onContextMenu:R}),e[10]=T,e[11]=P):P=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 v;e[17]!==j||e[18]!==h?(v=s.jsxs("div",{className:"flex items-center gap-2",children:[j,h]}),e[17]=j,e[18]=h,e[19]=v):v=e[19];let O;e[20]!==a.description?(O=a.description&&s.jsx("div",{className:"typography-micro text-muted-foreground/60 truncate leading-tight",children:a.description}),e[20]=a.description,e[21]=O):O=e[21];let A;e[22]!==r||e[23]!==O||e[24]!==v?(A=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:[v,O]}),e[22]=r,e[23]=O,e[24]=v,e[25]=A):A=e[25];let C;e[26]!==p?(C=Q=>{Q&&S(!1),p(Q)},e[26]=p,e[27]=C):C=e[27];let M;e[28]===Symbol.for("react.memo_cache_sentinel")?(M=s.jsx(on,{asChild:!0,children:s.jsx(H,{size:"sm",variant:"ghost",className:"h-6 w-6 px-0 flex-shrink-0 -mr-1 opacity-100 transition-opacity md:opacity-0 md:group-hover:opacity-100",children:s.jsx(L,{name:"more-2",className:"h-3.5 w-3.5"})})}),e[28]=M):M=e[28];let B;e[29]!==N?(B=s.jsx(ln,{align:"end",className:"w-fit min-w-20",children:N(dn)}),e[29]=N,e[30]=B):B=e[30];let V;e[31]!==y||e[32]!==C||e[33]!==B?(V=s.jsxs(cn,{open:y,onOpenChange:C,children:[M,B]}),e[31]=y,e[32]=C,e[33]=B,e[34]=V):V=e[34];let k;e[35]!==A||e[36]!==V?(k=s.jsxs("div",{className:"flex min-w-0 flex-1 items-center",children:[A,V]}),e[35]=A,e[36]=V,e[37]=k):k=e[37];let D;e[38]!==k||e[39]!==P?(D=s.jsx(Jn,{render:P,children:k}),e[38]=k,e[39]=P,e[40]=D):D=e[40];let $;e[41]!==N?($=s.jsx(Wn,{className:"w-fit min-w-20",children:N(qn)}),e[41]=N,e[42]=$):$=e[42];let K;return e[43]!==f||e[44]!==D||e[45]!==$?(K=s.jsxs(Qn,{open:f,onOpenChange:S,children:[D,$]}),e[43]=f,e[44]=D,e[45]=$,e[46]=K):K=e[46],K};function zu(t){return{selectedCommandName:t.selectedCommandName,setSelectedCommand:t.setSelectedCommand,setCommandDraft:t.setCommandDraft,createCommand:t.createCommand,deleteCommand:t.deleteCommand,loadCommands:t.loadCommands}}function Uu(t){return t.loadSkills}function _u(t){return t.name}function $u(t){return!ha(t)}function Vu(t,e){return t.name.localeCompare(e.name)}function Bu(t,e){return t.name.localeCompare(e.name)}const Hu=()=>{const{t}=tt(),{selectedCommandName:e,getCommandByName:a,createCommand:n,updateCommand:r,commandDraft:i,setCommandDraft:l}=va(Us(M=>({selectedCommandName:M.selectedCommandName,getCommandByName:M.getCommandByName,createCommand:M.createCommand,updateCommand:M.updateCommand,commandDraft:M.commandDraft,setCommandDraft:M.setCommandDraft}))),g=_s(),d=va(M=>yl(M,g)),y=e?a(e,g):null,p=!!(i&&i.name===e&&!y),[b,c]=o.useState(""),[I,f]=o.useState("user"),[S,w]=o.useState(""),[N,m]=o.useState(""),[T,R]=o.useState(""),[P,j]=o.useState(""),[h,v]=o.useState(!1),O=o.useRef(null);o.useEffect(()=>{if(p&&i){const M=i.name||"",B=i.scope||"user",V=i.description||"",k=i.agent||"",D=i.model||"",$=i.template||"";c(M),f(B),w(V),m(k),R(D),j($),O.current={draftName:M,draftScope:B,description:V,agent:k,model:D,template:$}}else if(y){const M=y.description||"",B=y.agent||"",V=y.model||"",k=y.template||"";w(M),m(B),R(V),j(k),O.current={draftName:"",draftScope:"user",description:M,agent:B,model:V,template:k}}},[y,p,e,d,i]);const A=o.useMemo(()=>{const M=O.current;return M?!!(p&&(b!==M.draftName||I!==M.draftScope)||S!==M.description||N!==M.agent||T!==M.model||P!==M.template):!1},[N,S,b,I,p,T,P]),C=async()=>{const M=p?b.trim().replace(/\s+/g,"-"):e?.trim();if(!M){E.error(t("settings.commands.sidebar.toast.commandNameRequired"));return}if(!P.trim()){E.error(t("settings.commands.page.toast.templateRequired"));return}if(p&&d.some(B=>B.name===M)){E.error(t("settings.commands.sidebar.toast.commandExists"));return}v(!0);try{const B=N.trim(),V=T.trim(),k=P.trim(),D={name:M,description:S.trim()||void 0,agent:B===""?null:B,model:V===""?null:V,template:k,scope:p?I:void 0};let $;if(p?($=await n(D,g),$&&l(null)):$=await r(M,D,g),$){const K=Vn.getState().changes.some(Q=>Q.scope==="commands"&&Q.id.startsWith(`commands:${M}:`));E.success(t(K?"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(B){console.error("Error saving command:",B),E.error(t("settings.commands.page.toast.saveUnexpectedError"))}finally{v(!1)}};return e?s.jsxs(es,{title:p?t("settings.commands.page.title.new"):`/${e}`,description:t(p?"settings.commands.page.subtitle.new":"settings.commands.page.subtitle.edit"),showSaveStatus:!1,children:[s.jsxs(ze,{title:t("settings.commands.page.section.identity"),divider:!1,contentClassName:"space-y-0",children:[p&&s.jsxs(Rt,{settingsItem:"commands.name",label:t("settings.commands.page.field.commandName"),children:[s.jsxs("div",{className:"flex items-center",children:[s.jsx("span",{className:"typography-ui-label text-muted-foreground mr-1",children:"/"}),s.jsx(He,{value:b,onChange:M=>c(M.target.value),placeholder:t("settings.commands.page.field.commandNamePlaceholder"),className:"h-7 w-40 px-2"})]}),s.jsxs(St,{value:I,onValueChange:M=>f(M),children:[s.jsx(Ct,{size:Ft,className:"w-fit min-w-[100px]",children:s.jsx(Mt,{placeholder:t("settings.agents.page.field.scopePlaceholder")})}),s.jsxs(It,{align:"end",children:[s.jsx(at,{value:"user",children:s.jsxs("div",{className:"flex items-center gap-2",children:[s.jsx(L,{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(L,{name:"folder",className:"h-3.5 w-3.5"}),s.jsx("span",{children:t("settings.common.scope.project")})]})})]})]})]}),s.jsxs("div",{className:"py-1.5",children:[s.jsx("span",{className:"typography-ui-label text-foreground",children:t("settings.common.field.description")}),s.jsx("div",{className:"mt-1.5",children:s.jsx(Ts,{value:S,onChange:M=>w(M.target.value),placeholder:t("settings.commands.page.field.descriptionPlaceholder"),rows:2,className:"w-full resize-none min-h-[60px] bg-transparent"})})]})]}),s.jsxs(ze,{title:t("settings.commands.page.section.executionContext"),contentClassName:"space-y-0",children:[s.jsx(Rt,{settingsItem:"commands.agent",label:t("settings.commands.page.field.overrideAgent"),children:s.jsx(bl,{agentName:N,onChange:M=>m(M),className:In})}),s.jsx(Rt,{settingsItem:"commands.model",label:t("settings.agents.page.field.overrideModel"),children:s.jsx(Fa,{providerId:xa(T)?.providerId??"",modelId:xa(T)?.modelId??"",onChange:(M,B)=>{R(M&&B?`${M}/${B}`:"")},className:In})})]}),s.jsxs(ze,{title:t("settings.commands.page.section.template"),settingsItem:"commands.template",children:[s.jsx(Ts,{value:P,onChange:M=>j(M.target.value),placeholder:t("settings.commands.page.field.templatePlaceholder"),rows:12,className:"w-full font-mono typography-meta min-h-[160px] max-h-[60vh] bg-transparent resize-y"}),s.jsxs("p",{className:"mt-2 typography-meta text-muted-foreground",children:[s.jsx("code",{className:"text-foreground",children:"$ARGUMENTS"})," ",t("settings.commands.page.templateHint.userInput")," ·"," ",s.jsx("code",{className:"text-foreground",children:"!`cmd`"})," ",t("settings.commands.page.templateHint.shellOutput")," ·"," ",s.jsx("code",{className:"text-foreground",children:"@file"})," ",t("settings.commands.page.templateHint.fileContents")]}),s.jsx("div",{className:"pt-3",children:s.jsx(H,{onClick:C,disabled:h||!A,size:"xs",className:"!font-normal",children:t(h?"settings.common.actions.saving":"settings.common.actions.saveChanges")})})]})]}):s.jsx("div",{className:"flex h-full items-center justify-center",children:s.jsxs("div",{className:"text-center text-muted-foreground",children:[s.jsx(L,{name:"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:d}=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 c;e[2]!==y?(c=q=>q.getStatusForDirectory(y),e[2]=y,e[3]=c):c=e[3];const I=Ks(c),f=Ks(qu),S=Ks(Ju),[w,N]=o.useState(null),[m,T]=o.useState(!1),[R,P]=o.useState(null),[j,h]=o.useState(null),[v,O]=o.useState(!1);let A;e[4]!==b?(A=b.filter(Qu),e[4]=b,e[5]=A):A=e[5];const C=A;let M;e[6]!==b?(M=b.filter(Yu),e[6]=b,e[7]=M):M=e[7];const B=M;let V,k;e[8]!==g||e[9]!==y?(V=()=>{g({directory:y})},k=[g,y],e[8]=g,e[9]=y,e[10]=V,e[11]=k):(V=e[10],k=e[11]),o.useEffect(V,k);let D;e[12]!==S||e[13]!==v||e[14]!==f||e[15]!==y?(D=()=>{if(v)return;O(!0);const q=new Promise(Zu);Promise.all([f({directory:y,silent:!0}),q]).then(()=>{const ke=S(y);ke&&E.error(ke)}).finally(()=>{O(!1)})},e[12]=S,e[13]=v,e[14]=f,e[15]=y,e[16]=D):D=e[16];const $=D;let K;e[17]!==b||e[18]!==a||e[19]!==l||e[20]!==i?(K=()=>{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]=K):K=e[21];const Q=K;let te;e[22]!==d||e[23]!==w||e[24]!==y||e[25]!==n?(te=async()=>{if(!w)return;T(!0);const q=await d(w.name,y);q.ok?q.reloadFailed?E.warning(q.message||`MCP server "${w.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:w.name})):E.error(n("settings.mcp.sidebar.toast.deleteFailed")),N(null),T(!1)},e[22]=d,e[23]=w,e[24]=y,e[25]=n,e[26]=te):te=e[26];const U=te;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(L,{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 G;e[29]===Symbol.for("react.memo_cache_sentinel")?(G=xe("flex h-full flex-col","bg-background"),e[29]=G):G=e[29];let z;e[30]!==n?(z=n("settings.mcp.sidebar.title"),e[30]=n,e[31]=z):z=e[31];let F;e[32]!==z?(F=s.jsx("h2",{className:un,children:z}),e[32]=z,e[33]=F):F=e[33];let ee;e[34]!==n?(ee=n("settings.mcp.sidebar.actions.refreshStatusAria"),e[34]=n,e[35]=ee):ee=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=v&&"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(L,{name:"refresh",className:ge}),e[40]=ge,e[41]=de):de=e[41];let he;e[42]!==$||e[43]!==v||e[44]!==ee||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:v,onClick:$,"aria-label":ee,title:Y,children:de}),e[42]=$,e[43]=v,e[44]=ee,e[45]=Y,e[46]=de,e[47]=he):he=e[47];let se;e[48]!==F||e[49]!==he?(se=s.jsxs("div",{className:"mb-3 flex items-center justify-between gap-3",children:[F,he]}),e[48]=F,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(L,{name:"add",className:"h-3.5 w-3.5"}),e[59]=ye):ye=e[59];let fe;e[60]!==Q||e[61]!==Se?(fe=s.jsx(H,{size:"sm","data-settings-item":"mcp.create",variant:"ghost",className:"h-7 w-7 px-0 -my-1 text-muted-foreground",onClick:Q,title:Se,children:ye}),e[60]=Q,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]!==I||e[71]!==a||e[72]!==R||e[73]!==C||e[74]!==_||e[75]!==j||e[76]!==r||e[77]!==l||e[78]!==i||e[79]!==n||e[80]!==B?(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(L,{name:"plug",className:"mx-auto mb-3 h-10 w-10 opacity-50"}),s.jsx("p",{className:"typography-ui-label font-medium",children:n("settings.mcp.sidebar.empty.title")}),s.jsx("p",{className:"typography-meta mt-1 opacity-75",children:n("settings.mcp.sidebar.empty.description")})]}):s.jsxs(s.Fragment,{children:[C.length>0&&s.jsxs(s.Fragment,{children:[s.jsx("div",{className:"px-2 pb-1.5 pt-2 text-xs font-semibold uppercase tracking-wide text-muted-foreground",children:n("settings.mcp.sidebar.group.projectServers")}),C.map(q=>{const ke=I[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(L,{name:"server",className:"h-3 w-3 text-muted-foreground/60 flex-shrink-0"}):s.jsx(L,{name:"global",className:"h-3 w-3 text-muted-foreground/60 flex-shrink-0"})})]}),s.jsx("div",{className:"typography-micro text-muted-foreground/60 truncate leading-tight pl-4",children:q.type==="local"?q.command?.join(" ")??"":q.url??""})]}),s.jsxs(cn,{open:R===q.name,onOpenChange:st=>{st&&h(null),P(st?q.name:null)},children:[s.jsx(on,{asChild:!0,children:s.jsx(H,{size:"xs",variant:"ghost",className:"flex-shrink-0 -mr-1 opacity-100 transition-opacity md:opacity-0 md:group-hover:opacity-100",children:s.jsx(L,{name:"more-2",className:"h-3.5 w-3.5"})})}),s.jsx(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)})]}),B.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")}),B.map(q=>{const ke=I[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(L,{name:"server",className:"h-3 w-3 text-muted-foreground/60 flex-shrink-0"}):s.jsx(L,{name:"global",className:"h-3 w-3 text-muted-foreground/60 flex-shrink-0"})})]}),s.jsx("div",{className:"typography-micro text-muted-foreground/60 truncate leading-tight pl-4",children:q.type==="local"?q.command?.join(" ")??"":q.url??""})]}),s.jsxs(cn,{open:R===q.name,onOpenChange:st=>{st&&h(null),P(st?q.name:null)},children:[s.jsx(on,{asChild:!0,children:s.jsx(H,{size:"xs",variant:"ghost",className:"flex-shrink-0 -mr-1 opacity-100 transition-opacity md:opacity-0 md:group-hover:opacity-100",children:s.jsx(L,{name:"more-2",className:"h-3.5 w-3.5"})})}),s.jsx(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]=I,e[71]=a,e[72]=R,e[73]=C,e[74]=_,e[75]=j,e[76]=r,e[77]=l,e[78]=i,e[79]=n,e[80]=B,e[81]=Ne):Ne=e[81];const Oe=w!==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=w?.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(H,{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(H,{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:G,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),d=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():"",c=tp(a),I=sp(a);return{ok:!0,name:t,type:e,command:n,url:r,environment:i,headers:l,oauthEnabled:g,oauthClientId:d,oauthClientSecret:y,oauthScope:p,oauthRedirectUri:b,timeout:c,enabled:I}}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 d=g[0],y=r[d];return an(y)?ri(d,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 d=g[0],y=i[d];return an(y)?ri(d,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),d=typeof n.name=="string"&&n.name.trim()?n.name.trim():e?.fallbackName;return ri(d,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,d]=o.useState(l),y=o.useRef(a);let p,b;e[2]!==a?(p=()=>{JSON.stringify(y.current)!==JSON.stringify(a)&&(y.current=a,d(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 c;e[5]!==n||e[6]!==i?(c=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]=c):c=e[7];const I=c;let f;e[8]!==n?(f=j=>{const v=j.clipboardData.getData("text").trim();if(!v||v.includes(`
7
+ `)||!/\s/.test(v))return;const O=j.currentTarget;if(O.selectionStart!==0||O.selectionEnd!==O.value.length)return;j.preventDefault();const A=Vl(v);d(A.join(`
8
+ `)),n(A)},e[8]=n,e[9]=f):f=e[9];const S=f;let w;e[10]!==I?(w=j=>{d(j.target.value),I(j.target.value)},e[10]=I,e[11]=w):w=e[11];let N;e[12]!==I||e[13]!==g?(N=()=>{const j=g.split(`
9
+ `).map(fp).join(`
10
+ `);d(j),I(j)},e[12]=I,e[13]=g,e[14]=N):N=e[14];const m=Math.max(4,a.length+1);let T;e[15]!==S||e[16]!==w||e[17]!==N||e[18]!==m||e[19]!==g?(T=s.jsx(Ts,{onPaste:S,value:g,onChange:w,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]=S,e[16]=w,e[17]=N,e[18]=m,e[19]=g,e[20]=T):T=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 P;return e[24]!==R||e[25]!==T?(P=s.jsxs("div",{className:"space-y-2","data-bwignore":"true","data-1p-ignore":"true","data-lpignore":"true",children:[T,R]}),e[24]=R,e[25]=T,e[26]=P):P=e[26],P},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:d,clipboardReadFailed:y,keyLabel:p,valueLabel:b,valuePlaceholder:c,hideValueTitle:I,showValueTitle:f,addVariable:S,plainTextWarning:w,removeVariableAria:N})=>{const[m,T]=o.useState(new Set),R=()=>e([...t,{key:"",value:""}]),P=A=>{e(t.filter((C,M)=>M!==A)),T(C=>{const M=new Set(C);return M.delete(A),M})},j=(A,C,M)=>{const B=[...t];B[A]={...B[A],[C]:M},e(B)},h=A=>{T(C=>{const M=new Set(C);return M.has(A)?M.delete(A):M.add(A),M})},v=async()=>{try{const A=await navigator.clipboard.readText(),C=[];for(const B of A.split(`
14
+ `)){const V=B.trim();if(!V||V.startsWith("#"))continue;const k=V.indexOf("=");if(k===-1)continue;const D=V.slice(0,k).trim();let $=V.slice(k+1).trim();($.startsWith('"')&&$.endsWith('"')||$.startsWith("'")&&$.endsWith("'"))&&($=$.slice(1,-1)),D&&C.push({key:D,value:$})}if(C.length===0){E.error(g);return}const M=[...t];for(const B of C){const V=M.findIndex(k=>k.key===B.key);V!==-1?M[V]=B:M.push(B)}e(M),E.success(d(C.length))}catch{E.error(y)}},O=t.some(A=>A.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(H,{variant:"ghost",size:"xs",className:"!font-normal gap-1 text-muted-foreground",onClick:v,type:"button",title:l,children:[s.jsx(L,{name:"clipboard",className:"h-3 w-3"}),i]})]}),s.jsx("div",{className:"space-y-1.5",children:t.map((A,C)=>s.jsxs("div",{className:"flex items-center gap-2",children:[s.jsx(He,{value:A.key,onChange:M=>j(C,"key",a(M.target.value)),placeholder:n,className:r,"data-bwignore":"true","data-1p-ignore":"true","data-lpignore":"true",spellCheck:!1}),s.jsxs("div",{className:"relative flex-1 flex items-center",children:[s.jsx(He,{type:m.has(C)?"text":"password",value:A.value,onChange:M=>j(C,"value",M.target.value),placeholder:c,className:"font-mono typography-meta pr-8 w-full",autoComplete:"new-password","data-bwignore":"true","data-1p-ignore":"true","data-lpignore":"true",spellCheck:!1}),s.jsx("button",{type:"button",onClick:()=>h(C),className:"absolute right-2 text-muted-foreground/60 hover:text-muted-foreground",title:m.has(C)?I:f,children:m.has(C)?s.jsx(L,{name:"eye-off",className:"h-3.5 w-3.5"}):s.jsx(L,{name:"eye",className:"h-3.5 w-3.5"})})]}),s.jsx(H,{size:"sm",variant:"ghost",className:"h-7 w-7 px-0 shrink-0 text-muted-foreground hover:text-[var(--status-error)]",onClick:()=>P(C),"aria-label":N,children:s.jsx(L,{name:"delete-bin",className:"h-3.5 w-3.5"})})]},C))}),s.jsxs(H,{variant:"outline",size:"xs",className:"!font-normal gap-1.5",onClick:R,type:"button",children:[s.jsx(L,{name:"add",className:"h-3.5 w-3.5"}),S]}),O&&s.jsx("p",{className:"typography-micro text-muted-foreground/60",children:w})]})},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,d;if(e[0]!==r||e[1]!==a||e[2]!==l){d=Symbol.for("react.early_return_sentinel");e:{const c={connected:{text:"text-[var(--status-success)]",bg:"bg-[var(--status-success)]/10"},failed:{text:"text-[var(--status-error)]",bg:"bg-[var(--status-error)]/10"},needs_auth:{text:"text-[var(--status-warning)]",bg:"bg-[var(--status-warning)]/10"},needs_client_registration:{text:"text-[var(--status-warning)]",bg:"bg-[var(--status-warning)]/10"},awaiting_restart:{text:"text-[var(--status-warning)]",bg:"bg-[var(--status-warning)]/10"}}[a]??{text:"text-muted-foreground",bg:""};if(l==="pill"){const I=xe("typography-micro font-medium rounded-full px-2 py-0.5",c.text,c.bg);let f;e[5]!==r||e[6]!==a?(f=r(a),e[5]=r,e[6]=a,e[7]=f):f=e[7],d=s.jsxs("span",{className:I,children:["● ",f]});break e}g=xe("typography-micro font-medium",c.text)}e[0]=r,e[1]=a,e[2]=l,e[3]=g,e[4]=d}else g=e[3],d=e[4];if(d!==Symbol.for("react.early_return_sentinel"))return d;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:d,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(),[]),c=Ks(oe=>oe.getStatusForDirectory(p)),I=Ks(oe=>oe.getDiagnosticForDirectory(p)),f=Ks(oe=>oe.refresh),S=Ks(oe=>oe.connect),w=Ks(oe=>oe.disconnect),N=Ks(oe=>oe.completeAuth),m=Ks(oe=>oe.clearAuth),T=Ks(oe=>oe.testConnection),R=Vn(oe=>oe.changes),P=ya(oe=>wl(oe,p)),j=a?l(a,p):null,h=!!(n&&n.name===a&&!j),[v,O]=o.useState(""),[A,C]=o.useState("user"),[M,B]=o.useState("local"),[V,k]=o.useState([]),[D,$]=o.useState(""),[K,Q]=o.useState([]),[te,U]=o.useState([]),[le,_]=o.useState(!0),[G,z]=o.useState(""),[F,ee]=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:v});if(!oe.ok){W(oe.error);return}const xt=ip(oe,{name:v,scope:A,type:M,command:V,url:D,environment:K,headers:te,oauthEnabled:le,oauthClientId:G,oauthClientSecret:F,oauthScope:Y,oauthRedirectUri:ge,timeout:he,enabled:re},{isNewServer:h});O(xt.name),B(xt.type),k(xt.command??[]),$(xt.url??""),Q(xt.environment??[]),U(xt.headers??[]),_(xt.oauthEnabled??!1),z(xt.oauthClientId??""),ee(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,v,A,M,V,D,K,te,le,G,F,Y,ge,he,re,h,t]);o.useEffect(()=>{if(h&&n){O(n.name),C(n.scope||"user"),B(n.type),k(n.command),$(n.url),Q(n.environment),U(n.headers),_(n.oauthEnabled),z(n.oauthClientId),ee(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){C(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):"";B(rs),k(ws),$(ss),Q(oe),U(xt),_(Bt),z(Bt?Yt?.clientId??"":""),ee(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?M!==oe.mcpType||re!==oe.enabled||JSON.stringify(V)!==JSON.stringify(oe.command)||D!==oe.url||JSON.stringify(K)!==JSON.stringify(oe.envEntries)||JSON.stringify(te)!==JSON.stringify(oe.headerEntries)||le!==oe.oauthEnabled||G!==oe.oauthClientId||F!==oe.oauthClientSecret||Y!==oe.oauthScope||ge!==oe.oauthRedirectUri||he!==oe.timeout:!1},[M,V,D,K,te,le,G,F,Y,ge,he,re]),Be=o.useMemo(()=>[{id:"local",label:t("settings.mcp.page.connection.kindCommand"),icon:s.jsx(L,{name:"terminal",className:"h-3.5 w-3.5"})},{id:"remote",label:t("settings.mcp.page.connection.kindLink"),icon:s.jsx(L,{name:"global",className:"h-3.5 w-3.5"})}],[t]),Et=o.useCallback(oe=>{B("remote"),$(oe),k([])},[]),Me=o.useCallback(oe=>{$(oe);const ct=oe.trim();ct&&!/^[a-z][a-z0-9+.-]*:\/\//i.test(ct)&&/\s/.test(ct)&&(B("local"),k(Vl(ct)),$(""))},[]),wt=async()=>{const oe=h?v.trim():a??"";if(!oe){E.error(t("settings.mcp.page.toast.nameRequired"));return}if(h&&P.some(xt=>xt.name===oe)){E.error(t("settings.mcp.page.toast.serverNameExists"));return}if(M==="local"&&V.filter(Boolean).length===0){E.error(t("settings.mcp.page.toast.localCommandRequired"));return}if(M==="remote"&&!D.trim()){E.error(t("settings.mcp.page.toast.remoteUrlRequired"));return}const ct={name:oe,scope:A,type:M,command:V,url:D,environment:K,headers:te,oauthEnabled:le,oauthClientId:G,oauthClientSecret:F,oauthScope:Y,oauthRedirectUri:ge,timeout:he,enabled:re};Se(!0);try{const xt=h?await g(ct,p):await d(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)}},J=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(c[a]?.status==="connected")await w(a,p),E.success(t("settings.mcp.page.toast.disconnected"));else{await S(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||M!=="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,M,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 T(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,T]);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(L,{name:"plug",className:"mx-auto mb-3 h-12 w-12 opacity-50"}),s.jsx("p",{className:"typography-body",children:t("settings.mcp.page.empty.selectServer")}),s.jsx("p",{className:"typography-meta mt-1 opacity-75",children:t("settings.mcp.page.empty.addNewOne")})]})});const Zt=c[a],Os=a?I[a]:void 0,Wt=Zt??Os,is=!h&&!Wt&&R.some(oe=>oe.scope==="mcp"&&oe.id.startsWith(`mcp:${a}:`)),Ht=Zt?.status==="connected",bs=Zt?.status==="needs_auth"||Zt?.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(M==="local"?"settings.mcp.page.transport.local":"settings.mcp.page.transport.remote")}),headerEnd:!h&&!is?s.jsxs("div",{className:"flex flex-wrap items-center gap-2",children:[s.jsx(H,{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")}),M==="remote"&&s.jsxs(s.Fragment,{children:[s.jsx(H,{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(H,{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(H,{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:A==="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(H,{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(H,{variant:"outline",size:"xs",className:"!font-normal",onClick:()=>{hs()},children:[s.jsx(L,{name:"clipboard",className:"h-3.5 w-3.5"}),t("settings.mcp.page.actions.copyLink")]})]})]}),s.jsxs("div",{className:"grid gap-3 @xl:grid-cols-2",children:[s.jsx(qt,{label:t("settings.mcp.page.registration.clientId"),children:s.jsx(He,{value:G,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:F,onChange:oe=>{ee(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(H,{variant:"outline",size:"xs",className:"!font-normal",onClick:()=>{Pn(Fe)},children:[s.jsx(L,{name:"external-link",className:"h-3.5 w-3.5"}),t("settings.mcp.page.actions.openInBrowser")]}),s.jsxs(H,{variant:"outline",size:"xs",className:"!font-normal",onClick:()=>{qe()},children:[s.jsx(L,{name:"clipboard",className:"h-3.5 w-3.5"}),t("settings.mcp.page.actions.copyLink")]})]})]})}),b&&M==="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(H,{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(H,{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(L,{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:v,onChange:oe=>O(oe.target.value.toLowerCase().replace(/[^a-z0-9_-]/g,"-")),placeholder:t("settings.mcp.page.server.namePlaceholder"),className:"h-7 w-48 min-w-0 max-w-full shrink font-mono px-2",autoFocus:!0}),s.jsxs(St,{value:A,onValueChange:oe=>C(oe),children:[s.jsxs(Ct,{size:Ft,className:"!h-7 min-w-0 max-w-full gap-1.5 px-2",children:[s.jsx(L,{name:A==="user"?"user-3":"folder",className:"h-3.5 w-3.5 shrink-0"}),s.jsx("span",{className:"truncate",children:t(A==="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(L,{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(L,{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:M,onSelect:oe=>B(oe),layoutMode:"fit",variant:"active-pill",activePillLowercase:!1,className:"h-10"}),M==="local"?s.jsx(op,{value:V,onChange:k,preview:oe=>t("settings.mcp.page.connection.previewArgs",{count:oe}),onDetectUrl:Et}):s.jsx(He,{value:D,onChange:oe=>Me(oe.target.value),placeholder:t("settings.mcp.page.connection.serverUrlPlaceholder"),className:"font-mono typography-meta"}),s.jsx("p",{className:"typography-micro text-muted-foreground",children:t(M==="local"?"settings.mcp.page.connection.hintCommand":"settings.mcp.page.connection.hintLink")})]}),M==="remote"&&s.jsx(ze,{title:t("settings.mcp.page.advanced.title"),settingsItem:"mcp.advanced",children:s.jsxs(An,{open: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:["(",te.length," ",t("settings.mcp.page.advanced.headers"),he?` · ${he}ms`:"",")"]})]}),ke?s.jsx(L,{name:"arrow-down-s",className:"h-4 w-4 text-muted-foreground group-hover:text-foreground transition-colors"}):s.jsx(L,{name:"arrow-right-s",className:"h-4 w-4 text-muted-foreground group-hover:text-foreground transition-colors"})]}),s.jsx(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"),te.length>0&&s.jsxs("span",{className:"ml-1.5 typography-micro text-muted-foreground font-normal",children:["(",te.length,")"]})]}),s.jsx(yo,{value:te,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:K.length>0?s.jsxs("span",{className:"typography-micro text-muted-foreground font-normal",children:["(",K.length,")"]}):null,settingsItem:"mcp.environment",children:K.length===0?s.jsxs(H,{variant:"outline",size:"xs",className:"!font-normal gap-1.5",onClick:()=>Q([{key:"",value:""}]),children:[s.jsx(L,{name:"add",className:"h-3.5 w-3.5"}),t("settings.mcp.page.env.addEnvironmentVariable")]}):s.jsx(yo,{value:K,onChange:Q,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(H,{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(H,{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(H,{variant:"outline",size:"xs",className:"!font-normal gap-1",onClick:et,type:"button",children:[s.jsx(L,{name:"clipboard",className:"h-3.5 w-3.5"}),t("settings.mcp.page.importDialog.pasteFromClipboard")]})})]}),s.jsxs(ts,{children:[s.jsx(H,{variant:"outline",onClick:()=>{ot(!1),pt(""),W(null)},className:"text-foreground",children:t("settings.common.actions.cancel")}),s.jsx(H,{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(H,{variant:"outline",onClick:()=>fe(!1),disabled:_e,className:"text-foreground",children:t("settings.common.actions.cancel")}),s.jsx(H,{variant:"destructive",size:"sm",onClick:J,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 d=Zi.get(r);if(!a?.force&&d)return d;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 d=await yi(g);for(const y of d.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"),[d,y]=o.useState(""),[p,b]=o.useState(""),[c,I]=o.useState(""),[f,S]=o.useState(""),[w,N]=o.useState(a),[m,T]=o.useState(!1),R=o.useCallback(()=>{y(""),b(""),I(""),S(""),N(a)},[a]);o.useEffect(()=>{t&&(g("npm"),R())},[t,R]);const P=k=>{k!==l&&(g(k),R())},j=o.useMemo(()=>Ip(p),[p]),h=!j.ok,v=l==="file"&&c.trim()!==""&&!Cp.test(c.trim()),O=(l==="npm"||l==="path")&&d.trim()==="",A=l==="file"&&f.trim()==="",C=l==="file"&&c.trim()==="",M=m||h||l==="npm"&&O||l==="path"&&O||l==="file"&&(C||v||A),B=async()=>{if(!M){T(!0);try{let k;l==="file"?k=await i({fileName:c.trim(),content:f,scope:w}):k=await r({spec:d.trim(),options:j.ok?j.value:void 0,scope:w}),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{T(!1)}}},V=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:V,activeId:l,onSelect:k=>P(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:d,onChange:k=>y(k.target.value),placeholder:n("settings.plugins.page.field.spec.placeholder"),"aria-invalid":O?!1:void 0,disabled:m}),O&&s.jsx("p",{className:"typography-meta text-muted-foreground",children:n("settings.plugins.validation.specRequired")})]}),s.jsxs("div",{"data-settings-item":"plugins.options",className:"flex flex-col gap-1.5",children:[s.jsx("label",{htmlFor:"plugin-options",className:"typography-ui-label text-foreground",children:n("settings.plugins.page.field.options")}),s.jsx(Ts,{id:"plugin-options",value:p,onChange:k=>b(k.target.value),rows:5,className:"font-mono",hasError:h,disabled:m}),h&&s.jsx("p",{className:"typography-meta text-[var(--status-error)]",children:n("settings.plugins.page.field.options.invalidJson")})]})]}),l==="file"&&s.jsxs(s.Fragment,{children:[s.jsxs("div",{"data-settings-item":"plugins.content",className:"flex flex-col gap-1.5",children:[s.jsx("label",{htmlFor:"plugin-filename",className:"typography-ui-label text-foreground",children:n("settings.plugins.page.field.fileName")}),s.jsx(He,{id:"plugin-filename",value:c,onChange:k=>I(k.target.value),placeholder:"my-plugin.ts","aria-invalid":v||void 0,disabled:m}),v&&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=>S(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 D=w===k,$=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:D,onChange:()=>N(k),ariaLabel:$}),s.jsx("span",{className:xe("typography-ui-label font-normal",D?"text-foreground":"text-foreground/60"),children:$})]},k)})})]})]}),s.jsxs(ts,{children:[s.jsx(H,{size:"sm",variant:"ghost",onClick:()=>e(!1),disabled:m,children:n("settings.plugins.dialog.add.action.cancel")}),s.jsxs(H,{size:"sm",onClick:()=>{B()},disabled:M,children:[m?s.jsx(L,{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(L,{name:"arrow-up-s",className:"h-3 w-3"}),e[2]=g):g=e[2];let d;e[3]!==r.latestVersion?(d=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]=d):d=e[4];let y;return e[5]!==r.currentVersion||e[6]!==r.latestVersion||e[7]!==i||e[8]!==d?(y=l(d,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]=d,e[9]=y):y=e[9],y}case"npm-missing-version":{let g;e[10]===Symbol.for("react.memo_cache_sentinel")?(g=s.jsx(L,{name:"error-warning",className:"h-3 w-3 text-[var(--status-warning)]"}),e[10]=g):g=e[10];let d;return e[11]!==r.currentVersion||e[12]!==r.name||e[13]!==i?(d=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]=d):d=e[14],d}case"npm-missing-package":{let g;e[15]===Symbol.for("react.memo_cache_sentinel")?(g=s.jsx(L,{name:"error-warning",className:"h-3 w-3 text-[var(--status-error)]"}),e[15]=g):g=e[15];let d;return e[16]!==r.name||e[17]!==i?(d=l(g,i("settings.plugins.registry.badge.missingPackage.tooltip",{name:r.name})),e[16]=r.name,e[17]=i,e[18]=d):d=e[18],d}case"npm-malformed":{let g;e[19]===Symbol.for("react.memo_cache_sentinel")?(g=s.jsx(L,{name:"error-warning",className:"h-3 w-3 text-[var(--status-error)]"}),e[19]=g):g=e[19];let d;return e[20]!==i?(d=l(g,i("settings.plugins.registry.badge.malformed.tooltip")),e[20]=i,e[21]=d):d=e[21],d}case"npm-network":{let g;e[22]===Symbol.for("react.memo_cache_sentinel")?(g=s.jsx(L,{name:"cloud-off",className:"h-3 w-3 text-muted-foreground"}),e[22]=g):g=e[22];let d;return e[23]!==i?(d=l(g,i("settings.plugins.registry.badge.network.tooltip")),e[23]=i,e[24]=d):d=e[24],d}case"path-missing":{let g;e[25]===Symbol.for("react.memo_cache_sentinel")?(g=s.jsx(L,{name:"error-warning",className:"h-3 w-3 text-[var(--status-error)]"}),e[25]=g):g=e[25];let d;return e[26]!==r.absolutePath||e[27]!==i?(d=l(g,i("settings.plugins.registry.badge.pathMissing.tooltip",{path:r.absolutePath})),e[26]=r.absolutePath,e[27]=i,e[28]=d):d=e[28],d}case"path-unreadable":{let g;e[29]===Symbol.for("react.memo_cache_sentinel")?(g=s.jsx(L,{name:"error-warning",className:"h-3 w-3 text-[var(--status-warning)]"}),e[29]=g):g=e[29];let d;return e[30]!==r.absolutePath||e[31]!==i?(d=l(g,i("settings.plugins.registry.badge.pathUnreadable.tooltip",{path:r.absolutePath})),e[30]=r.absolutePath,e[31]=i,e[32]=d):d=e[32],d}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,d=cs(),y=o.useRef(null),[p,b]=o.useState(!1),[c,I]=o.useState(!1),f=g==="background"||d?"bg-background":"bg-sidebar",S=f==="bg-background"?"var(--surface-background)":"var(--surface-muted)";let w;e[0]===Symbol.for("react.memo_cache_sentinel")?(w=()=>{const M=y.current;if(!M){b(!1),I(!1);return}if(!(M.scrollHeight>M.clientHeight+1)){b(!1),I(!1);return}b(M.scrollTop>1),I(M.scrollTop+M.clientHeight<M.scrollHeight-1)},e[0]=w):w=e[0];const N=w;let m;e[1]===Symbol.for("react.memo_cache_sentinel")?(m=()=>{N()},e[1]=m):m=e[1];let T;e[2]!==r?(T=[r,N],e[2]=r,e[3]=T):T=e[3],o.useEffect(m,T);let R,P;e[4]===Symbol.for("react.memo_cache_sentinel")?(R=()=>{const M=y.current;if(!M)return;const B=()=>N();return M.addEventListener("scroll",B,{passive:!0}),()=>M.removeEventListener("scroll",B)},P=[N],e[4]=R,e[5]=P):(R=e[4],P=e[5]),o.useEffect(R,P);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 v;e[11]!==S||e[12]!==p?(v=p&&s.jsx("div",{className:"pointer-events-none absolute inset-x-0 top-0 h-4",style:{background:`linear-gradient(to bottom, ${S} 0%, transparent 100%)`}}),e[11]=S,e[12]=p,e[13]=v):v=e[13];let O;e[14]!==S||e[15]!==c?(O=c&&s.jsx("div",{className:"pointer-events-none absolute inset-x-0 bottom-0 h-6",style:{background:`linear-gradient(to top, ${S} 0%, transparent 100%)`}}),e[14]=S,e[15]=c,e[16]=O):O=e[16];let A;e[17]!==O||e[18]!==h||e[19]!==v?(A=s.jsxs("div",{className:"relative flex flex-1 min-h-0 flex-col",children:[h,v,O]}),e[17]=O,e[18]=h,e[19]=v,e[20]=A):A=e[20];let C;return e[21]!==n||e[22]!==a||e[23]!==A||e[24]!==j?(C=s.jsxs("div",{className:j,children:[a,A,n]}),e[21]=n,e[22]=a,e[23]=A,e[24]=j,e[25]=C):C=e[25],C},gr=t=>{const e=ut.c(23),{title:a,metadata:n,selected:r,onSelect:i,icon:l,actions:g,className:d}=t,y=r===void 0?!1:r,p=g&&g.length>0,b=y?"bg-interactive-selection":"hover:bg-interactive-hover";let c;e[0]!==d||e[1]!==b?(c=xe("group relative flex items-center rounded-md px-1.5 py-0.5 transition-all duration-200",b,d),e[0]=d,e[1]=b,e[2]=c):c=e[2];let I;e[3]!==a?(I=s.jsx("span",{className:"typography-ui-label font-normal truncate text-foreground",children:a}),e[3]=a,e[4]=I):I=e[4];let f;e[5]!==l||e[6]!==I?(f=s.jsxs("div",{className:"flex items-center gap-1.5",children:[l,I]}),e[5]=l,e[6]=I,e[7]=f):f=e[7];let S;e[8]!==n?(S=n&&s.jsx("div",{className:"typography-micro text-muted-foreground/60 truncate leading-tight",children:n}),e[8]=n,e[9]=S):S=e[9];let w;e[10]!==i||e[11]!==f||e[12]!==S?(w=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,S]}),e[10]=i,e[11]=f,e[12]=S,e[13]=w):w=e[13];let N;e[14]!==g||e[15]!==p?(N=p&&s.jsxs(cn,{children:[s.jsx(on,{asChild:!0,children:s.jsx(H,{size:"icon",variant:"ghost",className:"h-6 w-6 flex-shrink-0 -mr-1 opacity-100 transition-opacity md:opacity-0 md:group-hover:opacity-100",children:s.jsx(L,{name:"more-2",className:"h-3.5 w-3.5"})})}),s.jsx(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]!==w||e[18]!==N?(m=s.jsxs("div",{className:"flex min-w-0 flex-1 items-center",children:[w,N]}),e[17]=w,e[18]=N,e[19]=m):m=e[19];let T;return e[20]!==c||e[21]!==m?(T=s.jsx("div",{className:c,children:m}),e[20]=c,e[21]=m,e[22]=T):T=e[22],T};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(L,{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:d,deleteEntry:y,deleteFile:p,loadPlugins:b}=ms(Us(Rp)),c=ms(Lp),I=ms(Op),f=ms(Fp),S=ms(Kp),[w,N]=o.useState(null),[m,T]=o.useState(!1),[R,P]=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 v,O;e[3]===Symbol.for("react.memo_cache_sentinel")?(v=()=>{const et=()=>P(!0);return window.addEventListener("aiworker:settings-open-plugin-add",et),()=>window.removeEventListener("aiworker:settings-open-plugin-add",et)},O=[],e[3]=v,e[4]=O):(v=e[3],O=e[4]),o.useEffect(v,O);let A;if(e[5]!==i||e[6]!==c){A={userEntries:0,projectEntries:0};for(const et of i){const ft=c[et.spec];ft?.kind==="npm-ok"&&ft.hasUpdate&&(et.scope==="user"?A.userEntries=A.userEntries+1:et.scope==="project"&&(A.projectEntries=A.projectEntries+1))}e[5]=i,e[6]=c,e[7]=A}else A=e[7];const C=A;let M;e[8]!==i?(M=i.filter(zp),e[8]=i,e[9]=M):M=e[9];const B=M;let V;e[10]!==i?(V=i.filter(Up),e[10]=i,e[11]=V):V=e[11];const k=V;let D;e[12]!==l?(D=l.filter(_p),e[12]=l,e[13]=D):D=e[13];const $=D;let K;e[14]!==l?(K=l.filter($p),e[14]=l,e[15]=K):K=e[15];const Q=K,te=i.length+l.length,U=te===0;let le;e[16]!==n?(le=()=>{n?n():P(!0)},e[16]=n,e[17]=le):le=e[17];const _=le;let G;e[18]!==a||e[19]!==d?(G=et=>{d(et),a?.()},e[18]=a,e[19]=d,e[20]=G):G=e[20];const z=G;let F;e[21]!==i||e[22]!==c||e[23]!==r||e[24]!==S?(F=async et=>{const ft=i.find(Me=>Me.id===et);if(!ft)return;const bt=c[ft.spec];if(!bt||bt.kind!=="npm-ok"||!bt.hasUpdate||!bt.latestVersion)return;const Be=bt.latestVersion;(await S(et)).ok?E.success(r("settings.plugins.toast.updatedToLatest",{version:Be})):E.error(r("settings.plugins.toast.refreshFailed"))},e[21]=i,e[22]=c,e[23]=r,e[24]=S,e[25]=F):F=e[25];const ee=F;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]!==w||e[32]!==r?(ge=async()=>{if(!w)return;T(!0);const et=w.kind==="entry"?await y(w.id):await p(w.id);et.ok?E.success(et.message||r("settings.plugins.sidebar.toast.deleted",{name:w.label})):E.error(r("settings.plugins.sidebar.toast.deleteFailed")),N(null),T(!1)},e[29]=y,e[30]=p,e[31]=w,e[32]=r,e[33]=ge):ge=e[33];const de=ge;let he;e[34]!==z||e[35]!==ee||e[36]!==c||e[37]!==g||e[38]!==r?(he=et=>{const ft=c[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:()=>{ee(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(L,{name:Dp(et),className:"h-4 w-4 flex-shrink-0 text-muted-foreground/70"}),actions:Be},et.id)},e[34]=z,e[35]=ee,e[36]=c,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(L,{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]!==te?(_e=r("settings.plugins.sidebar.total",{count:te}),e[50]=r,e[51]=te,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=I?"size-4 animate-spin":"size-4";let ve;e[61]!==Ge?(ve=s.jsx(L,{name:"refresh",className:Ge}),e[61]=Ge,e[62]=ve):ve=e[62];let Z;e[63]!==I||e[64]!==Ne||e[65]!==Oe||e[66]!==Ve||e[67]!==ve?(Z=s.jsx(H,{type:"button","data-settings-item":"plugins.create",variant:"ghost",size:"icon",className:"h-7 w-7 -my-1 text-muted-foreground",onClick:Ne,disabled:I,"aria-label":Oe,title:Ve,children:ve}),e[63]=I,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(L,{name:"add",className:"size-4"}),e[73]=we):we=e[73];let Re;e[74]!==_||e[75]!==ne||e[76]!==be?(Re=s.jsx(H,{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]!==Q||e[90]!==se||e[91]!==ue||e[92]!==Se||e[93]!==r||e[94]!==C||e[95]!==B||e[96]!==$?(je=U?s.jsxs("div",{className:"py-12 px-4 text-center text-muted-foreground",children:[s.jsx(L,{name:"plug",className:"mx-auto mb-3 h-10 w-10 opacity-50"}),s.jsx("p",{className:"typography-ui-label font-medium",children: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:[B.length>0&&Se(r("settings.plugins.sidebar.group.userEntries"),B.map(se),C.userEntries),$.length>0&&Se(r("settings.plugins.sidebar.group.userFiles"),$.map(ue)),k.length>0&&Se(r("settings.plugins.sidebar.group.projectEntries"),k.map(se),C.projectEntries),Q.length>0&&Se(r("settings.plugins.sidebar.group.projectFiles"),Q.map(ue))]}),e[87]=U,e[88]=k,e[89]=Q,e[90]=se,e[91]=ue,e[92]=Se,e[93]=r,e[94]=C,e[95]=B,e[96]=$,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:P}),e[101]=R,e[102]=me):me=e[102];const Ie=w!==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=w?.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(H,{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(H,{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,c=n.currentVersion??"",I=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(L,{name:"arrow-up",className:"h-5 w-5 text-[var(--status-success)] shrink-0 mt-0.5"}),s.jsxs("div",{className:"flex-1 min-w-0",children:[s.jsx("p",{className:"typography-label text-[var(--status-success)]",children:a("settings.plugins.registry.banner.updateAvailable.title")}),s.jsx("p",{className:"typography-micro text-muted-foreground mt-0.5",children:a("settings.plugins.registry.banner.updateAvailable.description",{current:c,latest:b})})]}),s.jsx(H,{variant:"default",size:"sm",onClick:()=>{I()},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(L,{name:"cloud-off",className:"h-5 w-5 text-muted-foreground shrink-0 mt-0.5"}),s.jsx("div",{className:"flex-1 min-w-0",children:s.jsx("p",{className:"typography-micro text-muted-foreground",children:a("settings.plugins.registry.badge.network.tooltip")})})]});const g=n.kind==="path-unreadable",d=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(L,{name:y,className:"h-5 w-5 shrink-0 mt-0.5",style:{color:d}}),s.jsxs("div",{className:"flex-1 min-w-0",children:[s.jsx("p",{className:"typography-label",style:{color:d},children:a("settings.plugins.registry.banner.invalid.title")}),s.jsx("p",{className:"typography-micro text-muted-foreground mt-0.5",children: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(w=>w.selectedId),a=ms(w=>w.entries),n=ms(w=>w.files),r=ms(w=>w.draft),i=ms(w=>w.setDraft),l=ms(w=>w.updateEntry),g=ms(w=>w.updateFile),d=ms(w=>w.readFile),y=o.useMemo(()=>e?a.find(w=>w.id===e)??null:null,[a,e]),p=o.useMemo(()=>e?n.find(w=>w.id===e)??null:null,[n,e]),[b,c]=o.useState(!1),[I,f]=o.useState(!1),S=o.useRef(new Map);if(o.useEffect(()=>{let w=!1;return y?(i(wo(y)),()=>{w=!0}):p?(f(!0),(async()=>{const N=await d(p.id);if(w)return;f(!1);const m=N?.content??"";S.current.set(p.id,m),i(jo(p,m))})(),()=>{w=!0}):(i(null),()=>{w=!0})},[y,p,d,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(L,{name:"plug",className:"mx-auto mb-3 h-12 w-12 opacity-50"}),s.jsx("p",{className:"typography-body",children:t("settings.plugins.page.empty.select")}),s.jsx("p",{className:"typography-meta mt-1 opacity-75",children:t("settings.plugins.page.empty.add")})]})});if(y&&r&&r.mode==="entry"){const w=Bp(r.optionsJson),N=w.ok,m=r.spec!==y.spec||r.optionsJson!==Gl(y.options),T=()=>{i(wo(y))},R=async()=>{if(!N)return;const P=r.spec.trim();if(!P){E.error(t("settings.plugins.validation.specRequired"));return}c(!0);try{const j=await l(y.id,{spec:P,options:w.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{c(!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:P=>i({...r,spec:P.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:P=>i({...r,optionsJson:P.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(H,{variant:"default",size:"sm",onClick:()=>{R()},disabled:!m||!N||b,children:t("settings.plugins.page.action.save")}),s.jsx(H,{variant:"outline",size:"sm",onClick:T,disabled:!m||b,children:t("settings.plugins.page.action.discard")})]})]})]})}if(p&&r&&r.mode==="file"){const w=S.current.get(p.id)??"",N=r.content!==w||r.fileName!==p.fileName,m=()=>{(async()=>{f(!0);const P=(await d(p.id))?.content??"";f(!1),S.current.set(p.id,P),i(jo(p,P))})()},T=async()=>{c(!0);try{const R=await g(p.id,{content:r.content});R.ok?(S.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{c(!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:I}),s.jsxs("div",{className:"flex items-center gap-2 pt-3",children:[s.jsx(H,{variant:"default",size:"sm",onClick:()=>{T()},disabled:!N||b||I,children:t("settings.plugins.page.action.save")}),s.jsx(H,{variant:"outline",size:"sm",onClick:m,disabled:b||I,children:t("settings.plugins.page.action.discard")})]})]})})}return s.jsx("div",{className:"flex h-full items-center justify-center",children:s.jsx("div",{className:"text-center text-muted-foreground",children:s.jsx(L,{name:"loader-4",className:"mx-auto mb-3 h-6 w-6 animate-spin opacity-50"})})})},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(""),[d,y]=o.useState(null),[p,b]=o.useState(!1),[c,I]=o.useState(null),{selectedSkillName:f,setSelectedSkill:S,setSkillDraft:w,deleteSkill:N,renameSkill:m,getSkillDetail:T}=Hs(Us(qp)),R=_s();let P;e[0]!==R?(P=Me=>wr(Me,R),e[0]=R,e[1]=P):P=e[1];const j=Hs(P),h=Hs(Jp);let v,O;e[2]!==h||e[3]!==R?(v=()=>{h(R)},O=[h,R],e[2]=h,e[3]=R,e[4]=v,e[5]=O):(v=e[4],O=e[5]),o.useEffect(v,O);let A;e[6]!==a||e[7]!==S||e[8]!==w||e[9]!==j?(A=()=>{let Me="new-skill",wt=1;for(;j.some(J=>J.name===Me);)Me=`new-skill-${wt}`,wt++;w({name:Me,scope:"user",source:"opencode",description:""}),S(Me),a?.()},e[6]=a,e[7]=S,e[8]=w,e[9]=j,e[10]=A):A=e[10];const C=A;let M;e[11]===Symbol.for("react.memo_cache_sentinel")?(M=async Me=>{za(Me)||y(Me)},e[11]=M):M=e[11];const B=M;let V;e[12]!==d||e[13]!==N||e[14]!==R||e[15]!==n?(V=async()=>{if(!d)return;if(za(d)){y(null);return}b(!0),await N(d.name,R)?(E.success(n("settings.skills.sidebar.toast.skillDeleted",{name:d.name})),y(null)):E.error(n("settings.skills.sidebar.toast.deleteSkillFailed")),b(!1)},e[12]=d,e[13]=N,e[14]=R,e[15]=n,e[16]=V):V=e[16];const k=V;let D;e[17]!==T||e[18]!==S||e[19]!==w||e[20]!==R||e[21]!==j||e[22]!==n?(D=async Me=>{if(za(Me))return;const wt=Me.name;let J=1,pe=`${wt}-copy`;for(;j.some(Ae=>Ae.name===pe);)J++,pe=`${wt}-copy-${J}`;const De=await T(Me.name,R);if(!De){E.error(n("settings.skills.sidebar.toast.duplicateLoadFailed"));return}w({name:pe,scope:Me.scope||"user",source:Me.source||"opencode",description:(De.sources.md.fields.includes("description"),""),instructions:""}),S(pe)},e[17]=T,e[18]=S,e[19]=w,e[20]=R,e[21]=j,e[22]=n,e[23]=D):D=e[23];const $=D;let K;e[24]===Symbol.for("react.memo_cache_sentinel")?(K=Me=>{hr(Me)&&(g(Me.name),i(Me))},e[24]=K):K=e[24];const Q=K;let te;e[25]!==r||e[26]!==l||e[27]!==m||e[28]!==S||e[29]!==R||e[30]!==j||e[31]!==n?(te=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(J=>J.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})),S(Me)):E.error(n("settings.skills.sidebar.toast.renameFailed")),i(null)},e[25]=r,e[26]=l,e[27]=m,e[28]=S,e[29]=R,e[30]=j,e[31]=n,e[32]=te):te=e[32];const U=te;let le;e[33]!==j?(le=j.filter(Qp),e[33]=j,e[34]=le):le=e[34];const _=le;let G;e[35]!==j?(G=j.filter(Yp),e[35]=j,e[36]=G):G=e[36];const z=G;let F;e[37]===Symbol.for("react.memo_cache_sentinel")?(F=function(wt){const J={},pe=[];for(const Ae of wt)Ae.group?(J[Ae.group]||(J[Ae.group]=[]),J[Ae.group].push(Ae)):pe.push(Ae);const De=Object.keys(J).sort(Zp).map(Ae=>({name:Ae,skills:[...J[Ae]].sort(Xp)}));return pe.sort(em),{sortedGroups:De,ungrouped:pe}},e[37]=F):F=e[37];const ee=F;let Y;e[38]!==_?(Y=ee(_),e[38]=_,e[39]=Y):Y=e[39];const ae=Y;let ge;e[40]!==z?(ge=ee(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(L,{name:"add",className:"h-3.5 w-3.5"}),e[53]=ye):ye=e[53];let fe;e[54]!==C?(fe=s.jsx(H,{size:"sm","data-settings-item":"skills.create",variant:"ghost",className:"h-7 w-7 px-0 -my-1 text-muted-foreground",onClick:C,children:ye}),e[54]=C,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]!==$||e[65]!==a||e[66]!==c||e[67]!==_||e[68]!==f||e[69]!==S||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(L,{name:"book-open",className:"mx-auto mb-3 h-10 w-10 opacity-50"}),s.jsx("p",{className:"typography-ui-label font-medium",children:n("settings.skills.sidebar.empty.title")}),s.jsx("p",{className:"typography-meta mt-1 opacity-75",children:n("settings.skills.sidebar.empty.description")})]}):s.jsxs(s.Fragment,{children:[_.length>0&&s.jsxs(s.Fragment,{children:[s.jsx("div",{className:"px-2 pb-1.5 pt-2 text-xs font-semibold uppercase tracking-wide text-muted-foreground",children:n("settings.skills.sidebar.section.project")}),ae.sortedGroups.map(Me=>{const{name:wt,skills:J}=Me;return s.jsx(dr,{label:wt,count:J.length,storageKey:"project-skills",children:J.map(pe=>s.jsx(di,{skill:pe,isSelected:f===pe.name,onSelect:()=>{S(pe.name),a?.()},onRename:()=>Q(pe),onDelete:()=>B(pe),onDuplicate:()=>$(pe),isMenuOpen:c===pe.name,onMenuOpenChange:De=>I(De?pe.name:null)},pe.name))},wt)}),ae.ungrouped.map(Me=>s.jsx(di,{skill:Me,isSelected:f===Me.name,onSelect:()=>{S(Me.name),a?.()},onRename:()=>Q(Me),onDelete:()=>B(Me),onDuplicate:()=>$(Me),isMenuOpen:c===Me.name,onMenuOpenChange:wt=>I(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:J}=Me;return s.jsx(dr,{label:wt,count:J.length,storageKey:"user-skills",children:J.map(pe=>s.jsx(di,{skill:pe,isSelected:f===pe.name,onSelect:()=>{S(pe.name),a?.()},onRename:()=>Q(pe),onDelete:()=>B(pe),onDuplicate:()=>$(pe),isMenuOpen:c===pe.name,onMenuOpenChange:De=>I(De?pe.name:null)},pe.name))},wt)}),de.ungrouped.map(Me=>s.jsx(di,{skill:Me,isSelected:f===Me.name,onSelect:()=>{S(Me.name),a?.()},onRename:()=>Q(Me),onDelete:()=>B(Me),onDuplicate:()=>$(Me),isMenuOpen:c===Me.name,onMenuOpenChange:wt=>I(wt?Me.name:null)},Me.name))]})]})}),e[62]=ae,e[63]=de,e[64]=$,e[65]=a,e[66]=c,e[67]=_,e[68]=f,e[69]=S,e[70]=j.length,e[71]=n,e[72]=z,e[73]=Ne):Ne=e[73];const Oe=d!==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=d?.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(H,{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(H,{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(H,{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(H,{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:d,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 c=b;let I;e[1]!==a?(I=za(a),e[1]=a,e[2]=I):I=e[2];const f=I;let S;e[3]!==a?(S=hr(a),e[3]=a,e[4]=S):S=e[4];const w=S,[N,m]=o.useState(!1);let T;e[5]!==w||e[6]!==i||e[7]!==g||e[8]!==l||e[9]!==p?(T=$=>s.jsxs(s.Fragment,{children:[w?s.jsxs($,{onClick:K=>{K.stopPropagation(),l()},children:[s.jsx(L,{name:"edit",className:"h-4 w-4 mr-px"}),p("settings.common.actions.rename")]}):null,s.jsxs($,{onClick:K=>{K.stopPropagation(),g()},children:[s.jsx(L,{name:"file-copy",className:"h-4 w-4 mr-px"}),p("settings.common.actions.duplicate")]}),s.jsxs($,{onClick:K=>{K.stopPropagation(),i()},className:"text-destructive focus:text-destructive",children:[s.jsx(L,{name:"delete-bin",className:"h-4 w-4 mr-px"}),p("settings.common.actions.delete")]})]}),e[5]=w,e[6]=i,e[7]=g,e[8]=l,e[9]=p,e[10]=T):T=e[10];const R=T,P=!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 v;e[13]!==f?(v=!c&&!f?$=>{$.preventDefault(),m(!0)}:void 0,e[13]=f,e[14]=v):v=e[14];let O;e[15]!==h||e[16]!==v?(O=s.jsx("div",{className:h,onContextMenu:v}),e[15]=h,e[16]=v,e[17]=O):O=e[17];let A;e[18]!==a.name?(A=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]=A):A=e[19];let C;e[20]!==r||e[21]!==A?(C=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:A}),e[20]=r,e[21]=A,e[22]=C):C=e[22];let M;e[23]!==f||e[24]!==d||e[25]!==y||e[26]!==R?(M=f?null:s.jsxs(cn,{open:d,onOpenChange:$=>{$&&m(!1),y($)},children:[s.jsx(on,{asChild:!0,children:s.jsx(H,{size:"sm",variant:"ghost",className:"h-6 w-6 px-0 flex-shrink-0 -mr-1 opacity-100 transition-opacity md:opacity-0 md:group-hover:opacity-100",children:s.jsx(L,{name:"more-2",className:"h-3.5 w-3.5"})})}),s.jsx(ln,{align:"end",className:"w-fit min-w-20",children:R(dn)})]}),e[23]=f,e[24]=d,e[25]=y,e[26]=R,e[27]=M):M=e[27];let B;e[28]!==C||e[29]!==M?(B=s.jsxs("div",{className:"flex min-w-0 flex-1 items-center",children:[C,M]}),e[28]=C,e[29]=M,e[30]=B):B=e[30];let V;e[31]!==B||e[32]!==O?(V=s.jsx(Jn,{render:O,children:B}),e[31]=B,e[32]=O,e[33]=V):V=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 D;return e[37]!==V||e[38]!==k||e[39]!==P?(D=s.jsxs(Qn,{open:P,onOpenChange:m,children:[V,k]}),e[37]=V,e[38]=k,e[39]=P,e[40]=D):D=e[40],D};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),d=_n(k=>k.defaultGitIdentityId),y=_n(k=>k.loadDefaultGitIdentityId),[p,b]=o.useState(""),[c,I]=o.useState(""),[f,S]=o.useState(""),[w,N]=o.useState(null),[m,T]=o.useState(null),[R,P]=o.useState(!1),[j,h]=o.useState([]),[v,O]=o.useState(null),A=o.useRef(0),C=o.useCallback(k=>{A.current+=1,P(!1),T(null),k?.clearIdentity&&(h([]),O(null))},[]);o.useEffect(()=>{t&&(A.current+=1,b(""),I(""),S(""),T(null),P(!1),h([]),O(null),y(),N(null),(async()=>{const k=await pn();N(k?k.skillCatalogs??[]:null)})())},[t,y]);const M=o.useMemo(()=>{const k=c.trim(),D=f.trim();return(w??[]).some($=>{const K=($.source||"").trim(),Q=($.subpath||"").trim();return K===k&&Q===D})},[w,c,f]),B=async()=>{const k=c.trim();if(!k){E.error(a("settings.skills.catalog.add.toast.repositoryRequired"));return}p.trim()||b(sm(k)),P(!1),T(null);const D=A.current+1;A.current=D;const $=await n({source:k,subpath:f.trim()||void 0,gitIdentityId:v||void 0});if(A.current!==D)return;if(!$.ok){if($.error?.kind==="authRequired"){if(cs()){E.error(a("settings.skills.catalog.shared.toast.privateRepoNotSupportedVsCode"));return}const Q=$.error.identities||[];if(h(Q),!v&&Q.length>0){const te=d&&d!=="global"&&Q.some(U=>U.id===d)?d:Q[0].id;O(te)}E.error(a("settings.skills.catalog.add.toast.authenticationRequiredScan"));return}E.error($.error?.message||a("settings.skills.catalog.add.toast.scanFailed"));return}const K=$.items?.length||0;if(T(K),K===0){E.error(a("settings.skills.catalog.add.toast.noSkillsFound")),P(!1);return}h([]),P(!0),E.success(a("settings.skills.catalog.shared.toast.foundSkills",{count:K}))},V=async()=>{const k=p.trim(),D=c.trim(),$=f.trim();if(!k){E.error(a("settings.skills.catalog.add.toast.catalogNameRequired"));return}if(!D){E.error(a("settings.skills.catalog.add.toast.repositoryRequired"));return}if(!R){E.error(a("settings.skills.catalog.add.toast.scanBeforeAdd"));return}if(M){E.error(a("settings.skills.catalog.add.toast.catalogAlreadyExists"));return}const K={id:tm(),label:k,source:D,...$?{subpath:$}:{},...v?{gitIdentityId:v}:{}};if(w===null){E.error(a("settings.skills.catalog.add.toast.saveFailed"));return}const Q=[...w,K];try{if(!(await gt({skillCatalogs:Q})).ok)throw new Error(a("settings.skills.catalog.add.toast.saveFailed"));N(Q),E.success(a("settings.skills.catalog.add.toast.catalogAdded")),await r({refresh:!0}),await i(K.id,{refresh:!0}),l(K.id),e(!1)}catch(te){E.error(te instanceof Error?te.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:c,onChange:k=>{I(k.target.value),C({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=>{S(k.target.value),C({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:v||"",onValueChange:k=>{O(k),C()},children:[s.jsx(Ct,{className:"w-fit",children:s.jsx("span",{children:j.find(k=>k.id===v)?.name||a("settings.skills.catalog.shared.auth.chooseIdentity")})}),s.jsx(It,{align:"start",children:j.map(k=>s.jsx(at,{value:k.id,children:k.name},k.id))})]})]}):null,m!==null?s.jsx("div",{className:"typography-meta text-muted-foreground",children:a("settings.skills.catalog.add.scanResult",{count:m})}):null,M?s.jsx("div",{className:"typography-meta text-muted-foreground",children:a("settings.skills.catalog.add.duplicateMessage")}):null]}),s.jsxs(ts,{children:[s.jsx(H,{size:"sm",variant:"ghost",onClick:()=>e(!1),children:a("settings.common.actions.cancel")}),s.jsxs(H,{size:"sm",className:"gap-2",variant:"ghost",onClick:()=>{B()},disabled:g||!c.trim(),children:[s.jsx(L,{name:"git-repository",className:"h-4 w-4"}),a(g?"settings.skills.catalog.shared.actions.scanning":"settings.skills.catalog.shared.actions.scan")]}),s.jsx(H,{size:"sm",onClick:()=>{V()},disabled:!R||M||w===null||!p.trim()||!c.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[d,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 c;e[5]!==r?(c=Y=>{const ae={};for(const ge of r)ae[ge.skillName]=Y;y(ae)},e[5]=r,e[6]=c):c=e[6];const I=c;let f;e[7]!==r||e[8]!==d?(f=r.length>0&&r.every(Y=>d[Y.skillName]),e[7]=r,e[8]=d,e[9]=f):f=e[9];const S=f;let w;e[10]!==l?(w=l("settings.skills.catalog.conflicts.title"),e[10]=l,e[11]=w):w=e[11];let N;e[12]!==w?(N=s.jsx($t,{children:w}),e[12]=w,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 T;e[16]!==m?(T=s.jsx(Vt,{children:m}),e[16]=m,e[17]=T):T=e[17];let R;e[18]!==N||e[19]!==T?(R=s.jsxs(_t,{children:[N,T]}),e[18]=N,e[19]=T,e[20]=R):R=e[20];let P;e[21]!==r.length||e[22]!==l?(P=l("settings.skills.catalog.conflicts.count",{count:r.length}),e[21]=r.length,e[22]=l,e[23]=P):P=e[23];let j;e[24]!==P?(j=s.jsx("span",{className:"typography-meta text-muted-foreground",children:P}),e[24]=P,e[25]=j):j=e[25];let h;e[26]!==I?(h=()=>I("skip"),e[26]=I,e[27]=h):h=e[27];let v;e[28]!==l?(v=l("settings.skills.catalog.conflicts.actions.skipAll"),e[28]=l,e[29]=v):v=e[29];let O;e[30]!==h||e[31]!==v?(O=s.jsx(H,{variant:"outline",size:"xs",className:"!font-normal",onClick:h,children:v}),e[30]=h,e[31]=v,e[32]=O):O=e[32];let A;e[33]!==I?(A=()=>I("overwrite"),e[33]=I,e[34]=A):A=e[34];let C;e[35]!==l?(C=l("settings.skills.catalog.conflicts.actions.overwriteAll"),e[35]=l,e[36]=C):C=e[36];let M;e[37]!==A||e[38]!==C?(M=s.jsx(H,{variant:"outline",size:"xs",className:"!font-normal",onClick:A,children:C}),e[37]=A,e[38]=C,e[39]=M):M=e[39];let B;e[40]!==O||e[41]!==M?(B=s.jsxs("div",{className:"flex items-center gap-2",children:[O,M]}),e[40]=O,e[41]=M,e[42]=B):B=e[42];let V;e[43]!==j||e[44]!==B?(V=s.jsxs("div",{className:"flex items-center justify-between gap-2",children:[j,B]}),e[43]=j,e[44]=B,e[45]=V):V=e[45];let k;if(e[46]!==r||e[47]!==d||e[48]!==l){let Y;e[50]!==d||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:d[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:(d[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]=d,e[51]=l,e[52]=Y):Y=e[52],k=r.map(Y),e[46]=r,e[47]=d,e[48]=l,e[49]=k}else k=e[49];let D;e[53]!==k?(D=s.jsx("div",{className:"space-y-2",children:k}),e[53]=k,e[54]=D):D=e[54];let $;e[55]!==V||e[56]!==D?($=s.jsxs("div",{className:"space-y-3",children:[V,D]}),e[55]=V,e[56]=D,e[57]=$):$=e[57];let K;e[58]!==n?(K=()=>n(!1),e[58]=n,e[59]=K):K=e[59];let Q;e[60]!==l?(Q=l("settings.common.actions.cancel"),e[60]=l,e[61]=Q):Q=e[61];let te;e[62]!==K||e[63]!==Q?(te=s.jsx(H,{size:"sm",variant:"ghost",onClick:K,children:Q}),e[62]=K,e[63]=Q,e[64]=te):te=e[64];let U;e[65]!==d||e[66]!==i?(U=()=>i(d),e[65]=d,e[66]=i,e[67]=U):U=e[67];const le=!S;let _;e[68]!==l?(_=l("settings.skills.catalog.conflicts.actions.continue"),e[68]=l,e[69]=_):_=e[69];let G;e[70]!==U||e[71]!==le||e[72]!==_?(G=s.jsx(H,{size:"sm",onClick:U,disabled:le,children:_}),e[70]=U,e[71]=le,e[72]=_,e[73]=G):G=e[73];let z;e[74]!==te||e[75]!==G?(z=s.jsxs(ts,{children:[te,G]}),e[74]=te,e[75]=G,e[76]=z):z=e[76];let F;e[77]!==R||e[78]!==$||e[79]!==z?(F=s.jsxs(zt,{className:"max-w-2xl",children:[R,$,z]}),e[77]=R,e[78]=$,e[79]=z,e[80]=F):F=e[80];let ee;return e[81]!==n||e[82]!==a||e[83]!==F?(ee=s.jsx(Kt,{open:a,onOpenChange:n,children:F}),e[81]=n,e[82]=a,e[83]=F,e[84]=ee):ee=e[84],ee},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),[d,y]=o.useState("user"),[p,b]=o.useState("opencode"),c=Gs(lm),I=Gs(cm),[f,S]=o.useState(null),[w,N]=o.useState(!1);let m;e[0]===Symbol.for("react.memo_cache_sentinel")?(m=[],e[0]=m):m=e[0];const[T,R]=o.useState(m),[P,j]=o.useState(null);let h,v;e[1]!==I||e[2]!==a?(h=()=>{a&&(y("user"),b("opencode"),S(I),N(!1),R([]),j(null))},v=[a,I],e[1]=I,e[2]=a,e[3]=h,e[4]=v):(h=e[3],v=e[4]),o.useEffect(h,v);let O;e[5]!==i?(O=je=>{switch(je){case"project-opencode":return i("settings.skills.location.option.projectOpencode.label");case"user-agents":return i("settings.skills.location.option.userAgents.label");case"project-agents":return i("settings.skills.location.option.projectAgents.label");default:return i("settings.skills.location.option.userOpencode.label")}},e[5]=i,e[6]=O):O=e[6];const A=O;let C;e[7]!==i?(C=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]=C):C=e[8];const M=C;let B;e:{if(c.length===0){B=null;break e}if(f&&c.some(je=>je.id===f)){B=f;break e}if(I&&c.some(je=>je.id===I)){B=I;break e}B=c[0]?.id??null}const V=B;let k;e:{if(d!=="project"){k=null;break e}const je=V;if(!je){k=null;break e}let Ze;if(e[9]!==je||e[10]!==c){let Ie;e[12]!==je?(Ie=Le=>Le.id===je,e[12]=je,e[13]=Ie):Ie=e[13],Ze=c.find(Ie),e[9]=je,e[10]=c,e[11]=Ze}else Ze=e[11];k=Ze?.path??null}const D=k;let $;e[14]!==l||e[15]!==r?.gitIdentityId||e[16]!==n||e[17]!==i?($=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]=$):$=e[18];const K=$;if(!r)return null;let Q;e[19]!==i?(Q=i("settings.skills.catalog.installSkill.title"),e[19]=i,e[20]=Q):Q=e[20];let te;e[21]!==Q?(te=s.jsx($t,{children:Q}),e[21]=Q,e[22]=te):te=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 G;e[29]!==U||e[30]!==le||e[31]!==_?(G=s.jsxs(Vt,{children:[U," ",le," ",_]}),e[29]=U,e[30]=le,e[31]=_,e[32]=G):G=e[32];let z;e[33]!==te||e[34]!==G?(z=s.jsxs(_t,{children:[te,G]}),e[33]=te,e[34]=G,e[35]=z):z=e[35];let F;e[36]!==i?(F=i("settings.skills.catalog.installSkill.field.destination"),e[36]=i,e[37]=F):F=e[37];let ee;e[38]!==F?(ee=s.jsx("span",{className:"typography-ui-label text-foreground",children:F}),e[38]=F,e[39]=ee):ee=e[39];let Y;e[40]!==d||e[41]!==p?(Y=Ua(d,p),e[40]=d,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]!==d?(ge=d==="user"?s.jsx(L,{name:"user-3",className:"h-3.5 w-3.5"}):s.jsx(L,{name:"folder",className:"h-3.5 w-3.5"}),e[44]=d,e[45]=ge):ge=e[45];let de;e[46]!==p?(de=p==="agents"?s.jsx(L,{name:"robot-2",className:"h-3.5 w-3.5"}):null,e[46]=p,e[47]=de):de=e[47];let he;e[48]!==A||e[49]!==d||e[50]!==p?(he=A(Ua(d,p)),e[48]=A,e[49]=d,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]!==M||e[59]!==A?(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(L,{name:"user-3",className:"h-3.5 w-3.5"}):s.jsx(L,{name:"folder",className:"h-3.5 w-3.5"}),je.source==="agents"?s.jsx(L,{name:"robot-2",className:"h-3.5 w-3.5"}):null,s.jsx("span",{children:A(je.value)})]}),s.jsx("span",{className:"typography-micro text-muted-foreground ml-5",children:M(je.value)})]})},je.value)),e[58]=M,e[59]=A,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]!==ee||e[68]!==Se?(ye=s.jsxs("div",{className:"flex flex-wrap items-center gap-2",children:[ee,Se]}),e[67]=ee,e[68]=Se,e[69]=ye):ye=e[69];let fe;e[70]!==c||e[71]!==V||e[72]!==d||e[73]!==i?(fe=d==="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")}),c.length===0?s.jsx("span",{className:"typography-meta text-muted-foreground",children:i("settings.skills.catalog.installSkill.field.noProjects")}):s.jsxs(St,{value:V??"",onValueChange:je=>S(je),disabled:c.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:c.map(dm)})]})]}),e[70]=c,e[71]=V,e[72]=d,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(H,{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||d==="project"&&!D;let ve;e[88]!==D||e[89]!==K||e[90]!==r.repoSource||e[91]!==r.repoSubpath||e[92]!==r.skillDir||e[93]!==d||e[94]!==p?(ve=()=>{K({source:r.repoSource,subpath:r.repoSubpath,scope:d,targetSource:p,skillDir:r.skillDir,directoryOverride:D})},e[88]=D,e[89]=K,e[90]=r.repoSource,e[91]=r.repoSubpath,e[92]=r.skillDir,e[93]=d,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(H,{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]!==P||e[115]!==K?(Fe=je=>{P&&(K({source:P.source,subpath:P.subpath,scope:P.scope,targetSource:P.targetSource,skillDir:P.skillDir,conflictDecisions:je,directoryOverride:P.directoryOverride??null}),N(!1))},e[114]=P,e[115]=K,e[116]=Fe):Fe=e[116];let Ke;e[117]!==T||e[118]!==w||e[119]!==Fe?(Ke=s.jsx(am,{open:w,onOpenChange:N,conflicts:T,onConfirm:Fe}),e[117]=T,e[118]=w,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,d=a.stars??null;let y,p,b,c,I,f,S,w,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]!==d||e[8]!==g){const j=a.repoUpdatedAt?hm(a.repoUpdatedAt):null;w="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],I="min-w-0 flex-1 block";let v;e[21]!==a.label?(v=s.jsx("span",{className:"typography-ui-label font-medium text-foreground truncate",children:a.label}),e[21]=a.label,e[22]=v):v=e[22];let O;e[23]!==r||e[24]!==i||e[25]!==g?(O=r?s.jsx(L,{name:"refresh",className:"h-3 w-3 animate-spin text-muted-foreground shrink-0"}):i!==null&&s.jsx("span",{className:"typography-micro text-muted-foreground shrink-0",children:g("settings.skills.catalog.page.source.skillsCount",{count:i})}),e[23]=r,e[24]=i,e[25]=g,e[26]=O):O=e[26],e[27]!==v||e[28]!==O?(f=s.jsxs("span",{className:"flex items-center gap-2",children:[v,O]}),e[27]=v,e[28]=O,e[29]=f):f=e[29],e[30]!==a.source?(S=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]=S):S=e[31],y="flex items-center gap-3 mt-1",e[32]!==d||e[33]!==g?(b=d!==null&&s.jsxs("span",{className:"typography-micro text-muted-foreground flex items-center gap-1",title:g("settings.skills.catalog.page.source.stars",{count:d}),children:[s.jsx(L,{name:"star",className:"h-3 w-3"}),gm(d)]}),e[32]=d,e[33]=g,e[34]=b):b=e[34],c=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]=d,e[8]=g,e[9]=y,e[10]=p,e[11]=b,e[12]=c,e[13]=I,e[14]=f,e[15]=S,e[16]=w,e[17]=N,e[18]=m}else y=e[9],p=e[10],b=e[11],c=e[12],I=e[13],f=e[14],S=e[15],w=e[16],N=e[17],m=e[18];let T;e[35]!==y||e[36]!==b||e[37]!==c?(T=s.jsxs("span",{className:y,children:[b,c]}),e[35]=y,e[36]=b,e[37]=c,e[38]=T):T=e[38];let R;e[39]!==T||e[40]!==I||e[41]!==f||e[42]!==S?(R=s.jsxs("span",{className:I,children:[f,S,T]}),e[39]=T,e[40]=I,e[41]=f,e[42]=S,e[43]=R):R=e[43];let P;return e[44]!==p||e[45]!==R||e[46]!==w||e[47]!==N||e[48]!==m?(P=s.jsx("button",{type:w,onClick:N,"aria-pressed":m,className:p,children:R}),e[44]=p,e[45]=R,e[46]=w,e[47]=N,e[48]=m,e[49]=P):P=e[49],P},xm=({mode:t,onModeChange:e,showModeTabs:a=!0})=>{const{t:n}=tt(),{sources:r,itemsBySource:i,selectedSourceId:l,setSelectedSource:g,loadCatalog:d,loadSource:y,isLoadingCatalog:p,isLoadingSource:b,loadedSourceIds:c,lastCatalogError:I}=hn(Us(K=>({sources:K.sources,itemsBySource:K.itemsBySource,selectedSourceId:K.selectedSourceId,setSelectedSource:K.setSelectedSource,loadCatalog:K.loadCatalog,loadSource:K.loadSource,isLoadingCatalog:K.isLoadingCatalog,isLoadingSource:K.isLoadingSource,loadedSourceIds:K.loadedSourceIds,lastCatalogError:K.lastCatalogError}))),[f,S]=o.useState(""),[w,N]=o.useState(!1),[m,T]=o.useState(!1),[R,P]=o.useState(null),[j,h]=o.useState(!1),[v,O]=o.useState(!1),A=o.useRef(null);o.useEffect(()=>{d()},[d]),o.useEffect(()=>{const K=r.filter(U=>!c[U.id]);if(K.length===0)return;let Q=!1;return(async()=>{for(const U of K){if(Q)return;await y(U.id)}})(),()=>{Q=!0}},[r,c,y]),o.useEffect(()=>{!l||c[l]||y(l)},[l,c,y]),o.useEffect(()=>{const K=Q=>{(Q.metaKey||Q.ctrlKey)&&Q.key.toLowerCase()==="k"&&(Q.preventDefault(),A.current?.focus())};return window.addEventListener("keydown",K),()=>window.removeEventListener("keydown",K)},[]);const C=f.trim().length>0,M=o.useMemo(()=>C?ki(r.flatMap(K=>i[K.id]||[]),f,K=>[K.skillName,K.frontmatterName,K.description]):l?i[l]||[]:[],[r,i,l,f,C]),B=o.useMemo(()=>r.find(K=>K.id===l)||null,[r,l]),V=!!(l&&l.startsWith("custom:")),k=async()=>{if(!(!l||!V)){h(!0);try{const K=await pn();if(!K)return;const te=(K.skillCatalogs??[]).filter(U=>U.id!==l);await gt({skillCatalogs:te}),await d({refresh:!0}),O(!1)}finally{h(!1)}}},D=C?n("settings.skills.catalog.page.list.searchTitle"):B?.label??"",$=!C&&l!==null&&!c[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:K=>e(K),layoutMode:"fit",variant:"animated",animateActivePill:!1,className:"h-full"})})}),s.jsx("p",{className:"typography-meta text-muted-foreground mb-4",children:n("settings.skills.catalog.page.subtitle")}),s.jsx("div",{"data-settings-item":"skills.catalog.search",className:"mb-5",children:s.jsxs("div",{className:"relative max-w-md",children:[s.jsx(L,{name:"search",className:"absolute left-2.5 top-1/2 -translate-y-1/2 h-3.5 w-3.5 text-muted-foreground"}),s.jsx(He,{ref:A,value:f,onChange:K=>S(K.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:()=>{S(""),A.current?.focus()},className:"absolute right-2 top-1/2 -translate-y-1/2 flex items-center justify-center h-4 w-4 rounded text-muted-foreground hover:text-foreground transition-colors",title:n("settings.skills.catalog.page.search.clear"),children:s.jsx(L,{name:"close",className:"h-3 w-3"})})]})}),s.jsx(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(K=>s.jsx(fm,{source:K,isActive:K.id===l,isLoading:b&&!c[K.id],skillsCount:c[K.id]?(i[K.id]||[]).length:null,onSelect:()=>g(K.id),t:n},K.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(L,{name:"add",className:"h-4 w-4"})}),s.jsxs("span",{className:"min-w-0",children:[s.jsx("span",{className:"typography-ui-label text-muted-foreground block",children:n("settings.skills.catalog.page.source.addOwnTitle")}),s.jsx("span",{className:"typography-micro text-muted-foreground/70 block mt-0.5",children:n("settings.skills.catalog.page.source.addOwnDescription")})]})]})]})}),I&&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:I.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:D}),s.jsx("span",{className:"typography-micro text-muted-foreground/70 shrink-0",children:n("settings.skills.catalog.page.foundCount",{count:M.length})})]}),s.jsxs("div",{className:"flex items-center gap-1 shrink-0",children:[s.jsx(H,{variant:"ghost",size:"xs",className:"!font-normal h-6 w-6 px-0",onClick:()=>{l&&!C?y(l,{refresh:!0}):d({refresh:!0})},disabled:p||b,title:n("settings.skills.catalog.page.actions.refreshTitle"),children:s.jsx(L,{name:"refresh",className:xe("h-3.5 w-3.5",(p||b)&&"animate-spin")})}),V&&!C&&s.jsx(H,{variant:"ghost",size:"xs",className:"!font-normal h-6 w-6 px-0 text-[var(--status-error)] hover:text-[var(--status-error)]",onClick:()=>O(!0),disabled:j,title:n("settings.skills.catalog.page.actions.removeCatalogTitle"),children:s.jsx(L,{name:"delete-bin",className:"h-3.5 w-3.5"})})]})]}),$||b&&M.length===0?s.jsxs("div",{className:"py-8 text-center text-muted-foreground",children:[s.jsx(L,{name:"refresh",className:"mx-auto mb-3 h-5 w-5 animate-spin opacity-50"}),s.jsx("p",{className:"typography-meta",children:n("settings.skills.catalog.page.loading.skills")})]}):M.length===0?s.jsxs("div",{className:"py-8 text-center text-muted-foreground",children:[s.jsx("p",{className:"typography-body",children:n("settings.skills.catalog.page.empty.noSkillsTitle")}),s.jsx("p",{className:"typography-meta mt-1 opacity-75",children:n("settings.skills.catalog.page.empty.noSkillsDescription")})]}):s.jsx("div",{className:"divide-y divide-[var(--surface-subtle)]",children:M.map(K=>{const Q=K.installed?.isInstalled,te=K.installed?.scope,U=mm(K);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:K.skillName}),Q&&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:te||n("settings.skills.catalog.page.badge.unknown")})}),!K.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")})]}),K.description?s.jsx("div",{className:"typography-meta text-muted-foreground mt-0.5 line-clamp-2",children:K.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(L,{name:"github",className:"h-3 w-3 shrink-0"}),K.repoSource]}):s.jsx("span",{className:"font-mono truncate",children:K.repoSource}),K.skillDir&&s.jsxs(s.Fragment,{children:[s.jsx("span",{className:"opacity-40",children:"·"}),s.jsx("span",{className:"truncate",children:K.skillDir})]})]}),K.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:K.warnings.join(" · ")}):null]}),s.jsxs("div",{className:"flex items-center gap-1.5 shrink-0",children:[U&&s.jsx(H,{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(L,{name:"external-link",className:"h-3.5 w-3.5"})}),Q?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:te||""}),children:s.jsx(L,{name:"check",className:"h-4 w-4"})}):s.jsx(H,{variant:"outline",size:"xs",className:"!font-normal",disabled:!K.installable,onClick:()=>{P(K),T(!0)},children:n("settings.skills.catalog.shared.actions.install")})]})]})},`${K.sourceId}:${K.skillDir}`)})})]})]}),s.jsx(nm,{open:w,onOpenChange:N}),s.jsx(im,{open:m,onOpenChange:T,item:R}),s.jsx(Kt,{open:v,onOpenChange:K=>{j||O(K)},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(H,{size:"sm",variant:"ghost",onClick:()=>O(!1),disabled:j,children:n("settings.common.actions.cancel")}),s.jsx(H,{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:d,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)),c=a?n(a,p):null,I=!!(g&&g.name===a&&!c),f=!!(a&&!c&&!g),S=c?.path==="<built-in>";o.useEffect(()=>{f&&y(null)},[f,y]);const[w,N]=o.useState(""),[m,T]=o.useState("user"),[R,P]=o.useState("opencode"),[j,h]=o.useState(""),[v,O]=o.useState(""),[A,C]=o.useState(()=>bi("","")),[M,B]=o.useState("edit"),[V,k]=o.useState([]),[D,$]=o.useState([]),[K,Q]=o.useState(!1),[te,U]=o.useState(!1),[le,_]=o.useState(""),[G,z]=o.useState(""),[F,ee]=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=I?w.trim()!==""||j.trim()!==""||v.trim()!==""||D.length>0:j!==le||v!==G,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(I&&g){const Ie=g.description||"",Le=g.instructions||"";N(g.name||""),T(g.scope||"user"),P(g.source==="agents"?"agents":"opencode"),h(Ie),O(Le),C(bi(Ie,Le)),_(""),z(""),k([]),$(g.pendingFiles||[])}else if(a&&c){U(!0);try{const Ie=await r(a,p);if(Ie){const Le=Ie.sources.md,Xe=Le.description||"",q=Le.instructions||"";h(Xe),O(q),C(bi(Xe,q)),_(Xe),z(q),k(Le.supportingFiles||[])}}catch(Ie){console.error("Failed to load skill details:",Ie)}finally{U(!1)}}})()},[c,I,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),C(Ie=>jm(Ie,me))},[]),we=o.useCallback(me=>{C(me);const Ie=ql(me);h(Ie.description??""),O(Ie.instructions)},[]),Re=async()=>{const me=I?w.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(I&&b.some(Ie=>Ie.name===me)){E.error(t("settings.skills.page.toast.skillExists"));return}Q(!0);try{const Ie={name:me,description:j.trim(),instructions:v.trim()||void 0,scope:I?m:void 0,source:I?R:void 0,targetPath:I?void 0:c?.path,supportingFiles:I&&D.length>0?D:void 0};let Le;if(I?(Le=await i(Ie,p),Le&&(d(null),$([]),y(me))):(Le=await l(me,Ie,p),Le&&(_(j.trim()),z(v.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":I?"settings.skills.page.toast.skillCreated":"settings.skills.page.toast.skillUpdated"))}else E.error(t(I?"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{Q(!1)}},Fe=()=>{se(null),ae(""),de(""),Se(""),ee(!0)},Ke=async me=>{if(se(me),ae(me),I){const Le=D.find(Xe=>Xe.path===me)?.content||"";de(Le),Se(Le),ee(!0);return}if(a){ue(!0),ee(!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(I){if(Ie)$(q=>q.map(ke=>ke.path===he?{path:me,content:ge}:ke)),E.success(t("settings.skills.page.toast.fileUpdated",{path:me}));else{if(D.some(q=>q.path===me)){E.error(t("settings.skills.page.toast.fileExists"));return}$(q=>[...q,{path:me,content:ge}]),E.success(t("settings.skills.page.toast.fileAdded",{path:me}))}ee(!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})),ee(!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(I){$(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(L,{name:"book-open",className:"mx-auto mb-3 h-10 w-10 sm:h-12 sm:w-12 opacity-50"}),s.jsx("p",{className:"typography-body",children:t("settings.skills.page.empty.title")}),s.jsx("p",{className:"typography-meta mt-1 opacity-75",children:t("settings.skills.page.empty.description")})]})}):te?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:I?t("settings.skills.page.title.newSkill"):a,description:c?t("settings.skills.page.subtitle.skillLocation",{location:Ve(Ua(c.scope,c.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:[I&&s.jsxs(Rt,{label:t("settings.skills.page.field.skillNameLocation"),info:t("settings.skills.page.field.skillNameHint"),children:[s.jsx(He,{value:w,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);T(Ie.scope),P(Ie.source==="agents"?"agents":"opencode")},children:[s.jsxs(Ct,{size:Ft,className:"w-fit gap-1.5",children:[m==="user"?s.jsx(L,{name:"user-3",className:"h-3.5 w-3.5"}):s.jsx(L,{name:"folder",className:"h-3.5 w-3.5"}),R==="agents"?s.jsx(L,{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(L,{name:"user-3",className:"h-3.5 w-3.5"}):s.jsx(L,{name:"folder",className:"h-3.5 w-3.5"}),me.source==="agents"?s.jsx(L,{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:S})})]}),s.jsx(ze,{title:t("settings.skills.page.section.instructions"),headerAction:s.jsx(au,{currentMode:M==="preview"?"preview":"edit",onToggle:()=>B(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:M==="preview"?s.jsx(vs,{outerClassName:"h-full",className:"h-full",children:s.jsx("div",{className:"min-h-full px-4 py-3",children:s.jsx(Pc,{content:A,className:"typography-markdown-body",stripFrontmatter:!0,enableFileReferences:!1})})}):s.jsx(ro,{value:A,onChange:we,readOnly:S,extensions:Z,className:"h-full",enableSearch:!0})})}),s.jsx(ze,{title:t("settings.skills.page.section.supportingFiles"),headerAction:s.jsxs(H,{variant:"outline",size:"xs",className:"!font-normal gap-1",onClick:Fe,disabled:S,children:[s.jsx(L,{name:"add",className:"h-3.5 w-3.5"})," ",t("settings.skills.page.actions.addFile")]}),settingsItem:"skills.supporting-files",children:(()=>{const me=I?D:V;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(L,{name:"file",className:"h-3.5 w-3.5 text-muted-foreground flex-shrink-0"}),s.jsx("span",{className:"typography-ui-label text-foreground truncate",children:Ie.path}),I&&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")}),!S&&s.jsx(H,{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(L,{name:"delete-bin",className:"h-3 w-3"})})]},Ie.path))})})()}),s.jsx(ze,{children:s.jsx(H,{onClick:Re,disabled:S||K||!Ne,size:"xs",className:"!font-normal",children:t(K?"settings.common.actions.saving":I?"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(H,{size:"sm",variant:"ghost",onClick:()=>fe(null),disabled:_e,children:t("settings.common.actions.cancel")}),s.jsx(H,{size:"sm",variant:"destructive",onClick:Ze,disabled:_e,children:t("settings.common.actions.delete")})]})]})}),s.jsx(Kt,{open:F,onOpenChange:me=>{ee(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(H,{size:"sm",variant:"ghost",onClick:()=>{ee(!1),se(null)},children:t("settings.common.actions.cancel")}),s.jsx(H,{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 d;e[0]===Symbol.for("react.memo_cache_sentinel")?(d=cs(),e[0]=d):d=e[0];const y=d,p=Am;let b,c;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)},c=[r,i,l],e[1]=r,e[2]=i,e[3]=l,e[4]=b,e[5]=c):(b=e[4],c=e[5]),o.useEffect(b,c);let I;e[6]===Symbol.for("react.memo_cache_sentinel")?(I=xe("border-b px-3","pt-4 pb-3"),e[6]=I):I=e[6];let f;e[7]!==n?(f=n("settings.page.projects.title"),e[7]=n,e[8]=f):f=e[8];let S;e[9]!==f?(S=s.jsx("h2",{className:`${un} mb-3`,children:f}),e[9]=f,e[10]=S):S=e[10];let w;e[11]!==r.length||e[12]!==n?(w=n("settings.projects.sidebar.total",{count:r.length}),e[11]=r.length,e[12]=n,e[13]=w):w=e[13];let N;e[14]!==w?(N=s.jsx("span",{className:"typography-meta text-muted-foreground",children:w}),e[14]=w,e[15]=N):N=e[15];let m;e[16]!==n?(m=!y&&s.jsx(H,{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(L,{name:"add",className:"size-4"})}),e[16]=n,e[17]=m):m=e[17];let T;e[18]!==N||e[19]!==m?(T=s.jsxs("div",{className:"flex items-center justify-between gap-2",children:[N,m]}),e[18]=N,e[19]=m,e[20]=T):T=e[20];let R;e[21]!==T||e[22]!==S?(R=s.jsxs("div",{className:I,children:[S,T]}),e[21]=T,e[22]=S,e[23]=R):R=e[23];let P;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=v=>{const O=v.id===i,A=v.icon?Tc[v.icon]:null,C=v.color?Ec[v.color]??null:null,M=A?s.jsx(L,{name:A,className:xe("h-4 w-4",O?"text-foreground":"text-muted-foreground/70"),style:C?{color:C}:void 0}):s.jsx(L,{name:"folder",className:xe("h-4 w-4",O?"text-foreground":"text-muted-foreground/70"),style:C?{color:C}:void 0}),B=v.iconImage?s.jsx("span",{className:"inline-flex h-4 w-4 items-center justify-center overflow-hidden rounded-[2px]",style:v.iconBackground?{backgroundColor:v.iconBackground}:void 0,children:s.jsx(Dc,{project:v,options:{themeVariant:g.metadata.variant,iconColor:g.colors.surface.foreground},className:"h-full w-full object-contain",fallback:M})}):M;return s.jsx(gr,{title:v.label||v.path,icon:B,selected:O,onSelect:()=>{l(v.id),a?.()}},v.id)},e[30]=g,e[31]=a,e[32]=i,e[33]=l,e[34]=h):h=e[34],P=r.map(h),e[24]=g,e[25]=a,e[26]=r,e[27]=i,e[28]=l,e[29]=P}else P=e[29];let j;return e[35]!==R||e[36]!==P?(j=s.jsx(Hl,{variant:"background",header:R,children:P}),e[35]=R,e[36]=P,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 w;t[0]!==a||t[1]!==r?(w=a.find(N=>N.id===r)??null,t[0]=a,t[1]=r,t[2]=w):w=t[2],l=w}const g=l;let d,y;t[3]!==a||t[4]!==r||t[5]!==i?(d=()=>{if(a.length===0){i(null);return}r&&a.some(w=>w.id===r)||i(a[0].id)},y=[a,r,i],t[3]=a,t[4]=r,t[5]=i,t[6]=d,t[7]=y):(d=t[6],y=t[7]),o.useEffect(d,y);let p;t[8]!==g||t[9]!==n?(p=async w=>{g&&n(g.id,{label:w.label,icon:w.icon,color:w.color,iconBackground:w.iconBackground,defaultModel:w.defaultModel??null,defaultVariant:w.defaultVariant??null})},t[8]=g,t[9]=n,t[10]=p):p=t[10];const b=p;if(!g){let w;t[11]!==e?(w=e("settings.page.projects.title"),t[11]=e,t[12]=w):w=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 T;return t[17]!==w||t[18]!==m?(T=s.jsx(es,{title:w,showSaveStatus:!0,children:m}),t[17]=w,t[18]=m,t[19]=T):T=t[19],T}let c;t[20]!==g.label||t[21]!==e?(c=g.label??e("settings.projects.page.title.default"),t[20]=g.label,t[21]=e,t[22]=c):c=t[22];const I=c;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 S;return t[26]!==I||t[27]!==g.path||t[28]!==f?(S=s.jsx(es,{title:I,description:g.path,showSaveStatus:!0,outerClassName:"bg-background",children:f}),t[26]=I,t[27]=g.path,t[28]=f,t[29]=S):S=t[29],S};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),d=As(x=>x.isImportsLoading),y=As(x=>x.isSaving),p=As(x=>x.error),b=As(x=>x.load),c=As(x=>x.loadImports),I=As(x=>x.refreshStatuses),f=As(x=>x.upsertInstance),S=As(x=>x.createFromCommand),w=As(x=>x.removeInstance),N=As(x=>x.connect),m=As(x=>x.disconnect),T=As(x=>x.retry),R=ie(x=>x.settingsRemoteInstancesSelectedId),P=ie(x=>x.setSettingsRemoteInstancesSelectedId),j=o.useMemo(()=>R&&r.find(x=>x.id===R)||null,[r,R]),[h,v]=o.useState(null),[O,A]=o.useState(!1),[C,M]=o.useState(!1),[B,V]=o.useState(null),[k,D]=o.useState([]),[$,K]=o.useState(null),[Q,te]=o.useState(""),[U,le]=o.useState(!1),[_,G]=o.useState({}),[z,F]=o.useState(!1),[ee,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,J]=o.useState(null),[pe,De]=o.useState(!1),[Ae,it]=o.useState(!1),[rt,qe]=o.useState("configure"),[Pt,ys]=o.useState(!1),[Zt,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(),c()},[b,c]);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 S(X,x,Bt.trim()||t("settings.remoteInstances.sidebar.newSshInstanceName")),P(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)})}},[S,P,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),J(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;Zt==="local"?(X=Ht.localUrl??void 0,Te=!1):Zt==="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),J(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,Zt,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(()=>{v(j)},[j]),o.useEffect(()=>{ss(!1)},[R]),o.useEffect(()=>{if(!R)return;const x=window.setInterval(()=>{typeof document<"u"&&document.visibilityState!=="visible"||I()},2e3);return()=>{window.clearInterval(x)}},[I,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=>{v(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 S(Te,`ssh ${X}`,x),P(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}},[S,P,t]),ta=o.useCallback(()=>{U||(K(null),te(""))},[U]),zi=o.useCallback((x,X)=>{if(ds(!1),X){K(x),te($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=$,X=Q.trim();if(x){if(!X){E.error(t("settings.remoteInstances.page.toast.destinationRequired"));return}le(!0);try{await ea(x,X)&&(K(null),te(""))}finally{le(!1)}}},[ea,Q,$,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){A(!0),M(!0),V(null);try{const x=await vn(h.id);D(x)}catch(x){D([]),V(x instanceof Error?x.message:String(x))}finally{M(!1)}}},[h,vn]);o.useEffect(()=>{if(!O||!h)return;let x=!1;const X=async()=>{try{const Qe=await vn(h.id);x||(D(Qe),V(null))}catch(Qe){x||V(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,O,vn]);const ce=o.useMemo(()=>k.join(`
27
+ `),[k]),ls=o.useCallback(()=>{if(!ce.trim()){E.error(t("settings.remoteInstances.page.toast.noLogsToCopy"));return}Ka(ce).then(x=>{x.ok&&E.success(t("settings.remoteInstances.page.toast.logsCopied"))})},[ce,t]),aa=o.useCallback(async()=>{if(h)try{await Rc(h.id),D([]),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}F(!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(()=>{F(!1)})},[Xs,sa,m,h,Zn,t]),Xa=o.useCallback(()=>{if(!h||xn)return;Y(!0),(mn?m(h.id).then(()=>sa()):T(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,T,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&&!ee&&(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(H,{type:"button",size:"xs",className:"!font-normal",onClick:()=>{Wa()},children:[s.jsx(L,{name:"add",className:"h-3.5 w-3.5"}),t("settings.remoteInstances.clientAuth.actions.addDevice")]})}),s.jsxs("div",{className:"space-y-2.5",children:[gs>0?s.jsx("div",{className:"flex justify-end",children:s.jsx(H,{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(H,{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(H,{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(H,{type:"button",size:"xs",className:"!font-normal",onClick:()=>Ze(!0),disabled:fe,children:t("settings.remoteInstances.direct.import.action")}),s.jsxs(H,{type:"button",variant:"outline",size:"xs",className:"!font-normal",onClick:()=>Ee(!0),disabled:fe,children:[s.jsx(L,{name:"add",className:"h-3.5 w-3.5"}),t("settings.remoteInstances.direct.actions.add")]})]}),children:[s.jsx("div",{className:"space-y-2.5",children: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(H,{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(L,{name:"star-fill",className:"h-3.5 w-3.5"}):s.jsx(L,{name:"star",className:"h-3.5 w-3.5"})}),x.relay&&!x.apiUrl?null:s.jsxs(H,{type:"button",variant:"ghost",size:"xs",className:"!font-normal",onClick:()=>Ds(x),disabled:fe,children:[s.jsx(L,{name:"pencil",className:"h-3.5 w-3.5"}),t("desktopHostSwitcher.actions.edit")]}),s.jsxs(H,{type:"button",variant:"ghost",size:"xs",className:"!font-normal",onClick:()=>{ns(x.id)},disabled:fe,children:[s.jsx(L,{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(L,{name:"close",className:"h-4 w-4"})})]},x.id)),s.jsxs(H,{type:"button",variant:"ghost",size:"xs",className:"!font-normal",onClick:()=>ne(x=>[...x,fr()]),disabled:fe,children:[s.jsx(L,{name:"add",className:"h-3.5 w-3.5"}),t("settings.remoteInstances.direct.headers.actions.add")]})]}),s.jsxs("div",{className:"flex justify-end gap-2",children:[s.jsx(H,{type:"button",variant:"outline",size:"xs",className:"!font-normal",onClick:()=>Ee(!1),disabled:fe,children:t("settings.common.actions.cancel")}),s.jsx(H,{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(L,{name:"close",className:"h-4 w-4"})})]},x.id)),s.jsxs(H,{type:"button",variant:"ghost",size:"xs",className:"!font-normal",onClick:()=>st(x=>[...x,fr()]),disabled:fe,children:[s.jsx(L,{name:"add",className:"h-3.5 w-3.5"}),t("settings.remoteInstances.direct.headers.actions.add")]})]}),s.jsxs("div",{className:"flex justify-end gap-2",children:[s.jsx(H,{type:"button",variant:"outline",size:"xs",className:"!font-normal",onClick:()=>Ie(null),disabled:fe,children:t("settings.common.actions.cancel")}),s.jsx(H,{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(H,{type:"button",variant:"outline",size:"xs",className:"!font-normal",onClick:()=>Ze(!1),disabled:fe,children:t("settings.common.actions.cancel")}),s.jsx(H,{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=Zt===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)})}),Zt==="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,Zt==="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(H,{type:"button",variant:"outline",size:"xs",className:"!font-normal",onClick:()=>it(!1),disabled:Pt,children:t("settings.common.actions.cancel")}),s.jsx(H,{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(H,{type:"button",variant:"outline",size:"xs",className:"!font-normal shrink-0",onClick:Ri,children:[s.jsx(L,{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(H,{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(H,{type:"button",size:"xs",className:"!font-normal",onClick:Ha,children:[s.jsx(L,{name:"add",className:"h-3.5 w-3.5"}),t("settings.remoteInstances.sidebar.actions.addSshInstance")]}),contentClassName:"space-y-2.5",children: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(H,{type:"button",variant:"ghost",size:"xs",className:"!font-normal",onClick:()=>Ui(X?.localUrl),children:[s.jsx(L,{name:"external-link",className:"h-3.5 w-3.5"}),t("settings.remoteInstances.page.actions.open")]}):null,s.jsxs(H,{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(L,{name:"stop",className:"h-3.5 w-3.5"}):s.jsx(L,{name:"plug-2",className:"h-3.5 w-3.5"}),t(Dt?"settings.remoteInstances.sidebar.actions.disconnect":"settings.remoteInstances.sidebar.actions.connect")]}),s.jsxs(H,{type:"button",variant:"ghost",size:"xs",className:"!font-normal",onClick:()=>P(x.id),children:[s.jsx(L,{name:"pencil",className:"h-3.5 w-3.5"}),t("desktopHostSwitcher.actions.edit")]}),s.jsxs(H,{type:"button",variant:"ghost",size:"xs",className:"!font-normal",onClick:()=>{window.confirm(t("settings.remoteInstances.page.confirm.removeInstance"))&&w(x.id).catch(Ns=>E.error(t("settings.remoteInstances.page.toast.removeInstanceFailed"),{description:Ns instanceof Error?Ns.message:String(Ns)}))},children:[s.jsx(L,{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}),d?s.jsx("p",{className:"typography-meta text-muted-foreground",children:t("settings.remoteInstances.page.import.loading")}):l.length===0?s.jsx("p",{className:"typography-meta text-muted-foreground",children:t("settings.remoteInstances.page.addDialog.emptySaved")}):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(H,{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(H,{type:"button",variant:"outline",size:"xs",className:"!font-normal",onClick:()=>ds(!1),disabled:y,children:t("settings.common.actions.cancel")}),s.jsx(H,{type:"submit",size:"xs",className:"!font-normal",disabled:y||!Qt.trim(),children:t("settings.common.actions.create")})]})]})]})}):null,s.jsx(Kt,{open:!!$,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:$?t("settings.remoteInstances.page.patternDialog.descriptionWithHost",{host:$}):t("settings.remoteInstances.page.patternDialog.description")})]}),s.jsxs("form",{className:"space-y-3",onSubmit:x=>{x.preventDefault(),Qa()},children:[s.jsx(He,{value:Q,onChange:x=>te(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(H,{type:"button",variant:"outline",size:"xs",className:"!font-normal",onClick:ta,disabled:U,children:t("settings.common.actions.cancel")}),s.jsx(H,{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||P(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(H,{type:"button",variant:Xs?"outline":"default",size:"xs",className:"!font-normal",onClick:Za,disabled:z||ee,children:[Xs?s.jsx(L,{name:"stop",className:"h-3.5 w-3.5"}):s.jsx(L,{name:"plug-2",className:"h-3.5 w-3.5"}),_i]}),s.jsxs(H,{type:"button",variant:"outline",size:"xs",className:"!font-normal",onClick:Xa,disabled:!ti,children:[s.jsx(L,{name:"refresh",className:`h-3.5 w-3.5 ${xn||mn&&!Dn?"animate-spin":""}`}),ei]}),s.jsxs(H,{type:"button",variant:"outline",size:"xs",className:"!font-normal",onClick:()=>{na()},children:[s.jsx(L,{name:"terminal-window",className:"h-3.5 w-3.5"}),t("settings.remoteInstances.page.actions.logs")]}),s.jsxs(H,{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"))&&w(h.id).then(()=>{P(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(L,{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(H,{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(L,{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(H,{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(L,{name:"shuffle",className:"h-3.5 w-3.5"})})]})]}),s.jsxs("div",{className:"space-y-1 pt-1",children:[s.jsx("p",{className:"typography-micro text-muted-foreground",children:t("settings.remoteInstances.page.tunnelPreview.caption")}),s.jsx("p",{className:"typography-micro font-mono text-foreground/80 break-all",children:`${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=>{G(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(L,{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(H,{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(L,{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(L,{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(L,{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(L,{name:"arrow-right",className:"h-3.5 w-3.5"}),s.jsx(L,{name:"computer",className:"h-3.5 w-3.5"}),s.jsx("span",{className:"font-mono text-foreground",children:$s}),s.jsx("span",{children:t("settings.remoteInstances.page.preview.local")})]}):s.jsxs(s.Fragment,{children:[s.jsx(L,{name:"computer",className:"h-3.5 w-3.5"}),s.jsx("span",{className:"font-mono text-foreground",children:$s}),s.jsx("span",{children:t("settings.remoteInstances.page.preview.local")}),s.jsx(L,{name:"arrow-right",className:"h-3.5 w-3.5"}),s.jsx(L,{name:"server",className:"h-3.5 w-3.5"}),s.jsx("span",{className:"font-mono text-foreground",children:Ns}),s.jsx("span",{children:t("settings.remoteInstances.page.preview.remote")})]})}),qs?s.jsxs(H,{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(L,{name:"external-link",className:"h-3.5 w-3.5"}),t("settings.remoteInstances.page.actions.openLocal")]}):null]})]})})]},x.id)}),s.jsxs(H,{type:"button",variant:"outline",size:"xs",className:"!font-normal mt-1",onClick:()=>{const x=_m();os(X=>({...X,portForwards:[...X.portForwards,x]})),G(X=>({...X,[x.id]:!0}))},children:[s.jsx(L,{name:"add",className:"h-3.5 w-3.5"}),t("settings.remoteInstances.page.actions.addForward")]})]})]})]}),s.jsx("div",{className:"mt-8 border-t border-[var(--interactive-border)] pt-3",children:s.jsxs("div",{className:"flex items-center gap-2",children:[s.jsx(H,{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(H,{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(L,{name:"file-copy",className:"h-3.5 w-3.5"}),t("settings.remoteInstances.page.actions.copyLocalUrl")]}),s.jsxs(H,{type:"button",variant:"outline",size:"xs",className:"!font-normal",onClick:()=>{Ya()},children:[s.jsx(L,{name:"external-link",className:"h-3.5 w-3.5"}),t("settings.remoteInstances.page.actions.open")]})]}):null,p?s.jsx("div",{className:"ml-auto typography-meta text-[var(--status-error)]",children:p}):null]})}),s.jsx(Kt,{open:O,onOpenChange:A,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(H,{type:"button",variant:"outline",size:"xs",className:"!font-normal",onClick:ls,disabled:C||!ce.trim(),children:[s.jsx(L,{name:"file-copy",className:"h-3.5 w-3.5"}),t("settings.common.actions.copyAll")]}),s.jsxs(H,{type:"button",variant:"outline",size:"xs",className:"!font-normal",onClick:()=>{aa()},disabled:C,children:[s.jsx(L,{name:"delete-bin",className:"h-3.5 w-3.5"}),t("settings.common.actions.clear")]})]}),C?s.jsx("div",{className:"typography-meta text-muted-foreground",children:t("settings.remoteInstances.page.logsDialog.loading")}):B?s.jsx("div",{className:"typography-meta text-[var(--status-error)]",children:B}):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:!!$,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:$?t("settings.remoteInstances.page.patternDialog.descriptionWithHost",{host:$}):t("settings.remoteInstances.page.patternDialog.description")})]}),s.jsxs("form",{className:"space-y-3",onSubmit:x=>{x.preventDefault(),Qa()},children:[s.jsx(He,{value:Q,onChange:x=>te(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(H,{type:"button",variant:"outline",size:"xs",className:"!font-normal",onClick:ta,disabled:U,children:t("settings.common.actions.cancel")}),s.jsx(H,{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,d]=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){d({});return}let f=!1;return(async()=>{const w=n.map(async N=>{try{const m=y?`?directory=${encodeURIComponent(y)}`:"",T=await yt(`/api/provider/${encodeURIComponent(N.id)}/source${m}`,{method:"GET",headers:{Accept:"application/json"}});if(!T.ok)return;const R=await T.json().catch(()=>null),P=R?.sources??R?.data?.sources;if(!P||f)return;d(j=>({...j,[N.id]:P}))}catch{}});await Promise.all(w)})(),()=>{f=!0}},[y,n]);const b="bg-background",c=o.useMemo(()=>n.filter(f=>!!g[f.id]?.project?.exists),[n,g]),I=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(H,{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(L,{name:"add",className:"h-3.5 w-3.5"})})]})]}),s.jsx(vs,{outerClassName:"flex-1 min-h-0",className:"space-y-1 px-3 py-2 overflow-x-hidden",children:n.length===0?s.jsxs("div",{className:"py-12 px-4 text-center text-muted-foreground",children:[s.jsx(L,{name:"stack",className:"mx-auto mb-3 h-10 w-10 opacity-50"}),s.jsx("p",{className:"typography-ui-label font-medium",children:e("settings.providers.sidebar.empty.title")}),s.jsx("p",{className:"typography-meta mt-1 opacity-75",children:e("settings.providers.sidebar.empty.description")})]}):s.jsxs(s.Fragment,{children:[I.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")}),I.map(f=>s.jsx(Mo,{provider:f,selectedProviderId:r,onSelect:()=>{i(f.id),t?.()}},f.id))]}),c.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",I.length>0?"pt-3":"pt-2"),children:e("settings.providers.sidebar.section.projectProviders")}),c.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,d=l?"bg-interactive-selection":"hover:bg-interactive-hover";let y;e[0]!==d?(y=xe("group relative flex items-center rounded-md px-1.5 py-1 transition-all duration-200",d),e[0]=d,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 c;e[4]!==b?(c=s.jsx("span",{className:"typography-ui-label font-normal truncate flex-1 min-w-0 text-foreground",children:b}),e[4]=b,e[5]=c):c=e[5];let I;e[6]!==i?(I=s.jsx("span",{className:"typography-micro text-muted-foreground/60 flex-shrink-0",children:i}),e[6]=i,e[7]=I):I=e[7];let f;e[8]!==r||e[9]!==p||e[10]!==c||e[11]!==I?(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,c,I]}),e[8]=r,e[9]=p,e[10]=c,e[11]=I,e[12]=f):f=e[12];let S;return e[13]!==a.id||e[14]!==y||e[15]!==f?(S=s.jsx("div",{className:y,children:f},g),e[13]=a.id,e[14]=y,e[15]=f,e[16]=S):S=e[16],S},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,d=i.find(y=>"api"in y);return{providerID:t.id,name:typeof t.name=="string"&&t.name.trim()?t.name:t.id,protocol:dg(d?.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(),d=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"),c=!!(r||i||g&&t.allowExistingAuth&&g===e)?void 0:t.t("settings.providers.page.custom.error.apiKey.required"),I=l.includes(e),S=d||!!(g&&g===e)?void 0:t.existingProviderIDs.has(e)&&!I?t.t("settings.providers.page.custom.error.providerID.exists"):void 0,w=new Set,N=t.form.models.map(A=>{const C=A.id.trim(),M=C?w.has(C)?t.t("settings.providers.page.custom.error.duplicate"):void w.add(C):t.t("settings.providers.page.custom.error.required"),B=A.name.trim()?void 0:t.t("settings.providers.page.custom.error.required");return{id:M,name:B}}),m=N.every(A=>!A.id&&!A.name),T=Object.fromEntries(t.form.models.map(A=>[A.id.trim(),{name:A.name.trim()}])),R=new Set,P=t.form.headers.map(A=>{const C=A.key.trim(),M=A.value.trim();if(!C&&!M)return{};const B=C?R.has(C.toLowerCase())?t.t("settings.providers.page.custom.error.duplicate"):void R.add(C.toLowerCase()):t.t("settings.providers.page.custom.error.required"),V=M?void 0:t.t("settings.providers.page.custom.error.required");return{key:B,value:V}}),j=P.every(A=>!A.key&&!A.value),h=Object.fromEntries(t.form.headers.map(A=>({key:A.key.trim(),value:A.value.trim()})).filter(A=>A.key&&A.value).map(A=>[A.key,A.value])),v={providerID:d??S,name:y,baseURL:p,apiKey:c};return!d&&!S&&!y&&!p&&!c&&m&&j?{err:v,models:N,headers:P,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:T}}}:{err:v,models:N,headers:P}}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:d,onSubmit:y,onCancel:p,onDisconnect:b}=t;let c;e[0]!==n?(c=n===void 0?[]:n,e[0]=n,e[1]=c):c=e[1];const I=c,f=r===void 0?!1:r,S=i===void 0?"create":i,w=g===void 0?!1:g,N=d===void 0?null:d,{t:m}=tt(),T=S==="edit";let R;e[2]!==l?(R=()=>l??cg(),e[2]=l,e[3]=R):R=e[3];const[P,j]=o.useState(R);let h;e[4]===Symbol.for("react.memo_cache_sentinel")?(h={},e[4]=h):h=e[4];const[v,O]=o.useState(h);let A;e[5]===Symbol.for("react.memo_cache_sentinel")?(A=[],e[5]=A):A=e[5];const[C,M]=o.useState(A);let B;e[6]===Symbol.for("react.memo_cache_sentinel")?(B=[],e[6]=B):B=e[6];const[V,k]=o.useState(B),D=o.useRef(null);let $,K;e[7]!==l||e[8]!==T?($=()=>{l&&(T&&D.current===l.providerID||(D.current=T?l.providerID:null,j(l),O({}),M([]),k([])))},K=[l,T],e[7]=l,e[8]=T,e[9]=$,e[10]=K):($=e[9],K=e[10]),o.useEffect($,K);let Q;e[11]===Symbol.for("react.memo_cache_sentinel")?(Q=(jt,At)=>{j(Ut=>({...Ut,[jt]:At})),O(Ut=>({...Ut,[jt]:void 0}))},e[11]=Q):Q=e[11];const te=Q;let U;e[12]===Symbol.for("react.memo_cache_sentinel")?(U=(jt,At,Ut)=>{j(Ot=>({...Ot,models:Ot.models.map((ns,Ds)=>Ds===jt?{...ns,[At]:Ut}:ns)})),M(Ot=>{const ns=[...Ot];return ns[jt]={...ns[jt]??{},[At]:void 0},ns})},e[12]=U):U=e[12];const 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 G=_;let z;e[14]!==w||e[15]!==f||e[16]!==I||e[17]!==a||e[18]!==P||e[19]!==T||e[20]!==y||e[21]!==m?(z=async jt=>{if(jt.preventDefault(),f)return;const At=gg({form:P,t:((Ut,Ot)=>m(Ut,Ot)),existingProviderIDs:a,disabledProviders:I,editingProviderID:T?P.providerID:void 0,allowExistingAuth:T&&w});O(At.err),M(At.models),k(At.headers),At.result&&await y(At.result)},e[14]=w,e[15]=f,e[16]=I,e[17]=a,e[18]=P,e[19]=T,e[20]=y,e[21]=m,e[22]=z):z=e[22];const F=z;let ee;e[23]!==T||e[24]!==m?(ee=m(T?"settings.providers.page.custom.editTitle":"settings.providers.page.custom.title"),e[23]=T,e[24]=m,e[25]=ee):ee=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=P.providerID;let re;e[36]===Symbol.for("react.memo_cache_sentinel")?(re=jt=>te("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=!T,Se=T||f,ye=!!v.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]!==P.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]=P.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]!==v.providerID?(Ue=v.providerID?s.jsx("p",{className:"mt-1 typography-meta text-[var(--status-error)]",children:v.providerID}):null,e[48]=v.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=P.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]!==P.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]=P.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=P.name;let ke;e[94]===Symbol.for("react.memo_cache_sentinel")?(ke=jt=>te("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=!!v.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]!==P.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]=P.name,e[100]=Pe,e[101]=Je,e[102]=ot,e[103]=st):st=e[103];let pt;e[104]!==v.name?(pt=v.name?s.jsx("p",{className:"mt-1 typography-meta text-[var(--status-error)]",children:v.name}):null,e[104]=v.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=P.baseURL;let lt;e[115]===Symbol.for("react.memo_cache_sentinel")?(lt=jt=>te("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=!!v.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]!==P.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]=P.baseURL,e[121]=ht,e[122]=Lt,e[123]=et,e[124]=ft):ft=e[124];let bt;e[125]!==v.baseURL?(bt=v.baseURL?s.jsx("p",{className:"mt-1 typography-meta text-[var(--status-error)]",children:v.baseURL}):null,e[125]=v.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]!==w||e[135]!==T||e[136]!==m?(Me=m(T&&w?"settings.providers.page.custom.field.apiKey.editInfo":"settings.providers.page.custom.field.apiKey.info"),e[134]=w,e[135]=T,e[136]=m,e[137]=Me):Me=e[137];const wt=P.apiKey;let J;e[138]===Symbol.for("react.memo_cache_sentinel")?(J=jt=>te("apiKey",jt.target.value),e[138]=J):J=e[138];let pe;e[139]!==w||e[140]!==T||e[141]!==m?(pe=m(T&&w?"settings.providers.page.custom.field.apiKey.editPlaceholder":"settings.providers.page.custom.field.apiKey.placeholder"),e[139]=w,e[140]=T,e[141]=m,e[142]=pe):pe=e[142];const De=!!v.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]!==P.apiKey||e[146]!==pe||e[147]!==De||e[148]!==Ae?(it=s.jsx(He,{type:"password",value:wt,onChange:J,placeholder:pe,className:"h-8 rounded-md px-3 font-mono text-xs","aria-invalid":De,"aria-label":Ae}),e[145]=P.apiKey,e[146]=pe,e[147]=De,e[148]=Ae,e[149]=it):it=e[149];let rt;e[150]!==v.apiKey?(rt=v.apiKey?s.jsx("p",{className:"mt-1 typography-meta text-[var(--status-error)]",children:v.apiKey}):null,e[150]=v.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]!==ee||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:ee,divider:!1,settingsItem:"providers.custom",contentClassName:Qs,children:[ae,ge,Ne,Ie,vt,Be,qe]}),e[157]=ee,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 Zt;if(e[168]!==P.models||e[169]!==C||e[170]!==m){let jt;e[172]!==P.models.length||e[173]!==C||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")}),C[Ut]?.id?s.jsx("p",{className:"mt-1 typography-meta text-[var(--status-error)]",children:C[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")}),C[Ut]?.name?s.jsx("p",{className:"mt-1 typography-meta text-[var(--status-error)]",children:C[Ut]?.name}):null]})]}),s.jsx(H,{type:"button",variant:"ghost",size:"icon",className:Cs,disabled:P.models.length<=1,onClick:()=>{P.models.length<=1||(j(Ot=>({...Ot,models:Ot.models.filter((ns,Ds)=>Ds!==Ut)})),M(Ot=>Ot.filter((ns,Ds)=>Ds!==Ut)))},"aria-label":m("settings.providers.page.custom.models.remove"),children:s.jsx(L,{name:"delete-bin",className:"size-4"})})]})},At.row),e[172]=P.models.length,e[173]=C,e[174]=m,e[175]=jt):jt=e[175],Zt=P.models.map(jt),e[168]=P.models,e[169]=C,e[170]=m,e[171]=Zt}else Zt=e[171];let Os;e[176]===Symbol.for("react.memo_cache_sentinel")?(Os=()=>{j(xg),M(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(H,{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]!==Zt||e[183]!==is?(Ht=s.jsxs(ze,{title:ys,contentClassName:Qs,children:[Zt,is]}),e[181]=ys,e[182]=Zt,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]!==P.headers||e[192]!==V||e[193]!==m){let jt;e[195]!==P.headers.length||e[196]!==V||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=>G(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")}),V[Ut]?.key?s.jsx("p",{className:"mt-1 typography-meta text-[var(--status-error)]",children:V[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=>G(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")}),V[Ut]?.value?s.jsx("p",{className:"mt-1 typography-meta text-[var(--status-error)]",children:V[Ut]?.value}):null]})]}),s.jsx(H,{type:"button",variant:"ghost",size:"icon",className:Cs,disabled:P.headers.length<=1,onClick:()=>{P.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(L,{name:"delete-bin",className:"size-4"})})]})},At.row),e[195]=P.headers.length,e[196]=V,e[197]=m,e[198]=jt):jt=e[198],ds=P.headers.map(jt),e[191]=P.headers,e[192]=V,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(H,{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(H,{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(H,{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]!==T||e[219]!==m?(Bt=m(f?"settings.providers.page.actions.saving":T?"settings.providers.page.custom.actions.update":"settings.providers.page.custom.actions.save"),e[217]=f,e[218]=T,e[219]=m,e[220]=Bt):Bt=e[220];let rs;e[221]!==f||e[222]!==Bt?(rs=s.jsx(H,{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]!==F||e[229]!==Pt||e[230]!==Ht||e[231]!==xt||e[232]!==ws?(ss=s.jsxs("form",{onSubmit:F,className:"space-y-0",children:[Pt,Ht,xt,ws]}),e[228]=F,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,d]=o.useState({}),[y,p]=o.useState(""),b=o.useRef(null);o.useEffect(()=>()=>b.current?.abort(),[]);const c=i.phase==="idle"?null:i.methodIndex,I=i.phase==="authorizing"||i.phase==="waiting"||i.phase==="awaitingCode"&&i.submitting,f=async(h,v,O)=>{const A=await Ka(h);if(A.ok){E.success(r(v));return}console.error("Failed to copy OAuth value:",A.error),E.error(r(O))},S=async(h,v)=>{const O=new AbortController;b.current?.abort(),b.current=O;try{const A=await fn.getSdkClient().provider.oauth.callback({providerID:t,method:h,...v?{code:v}:{}},{signal:O.signal});if(O.signal.aborted)return;if(A.error)throw A.error;l(er),E.success(r("settings.providers.page.toast.oauthCompleted")),await a()}catch(A){if(O.signal.aborted)return;console.error("Failed to complete OAuth flow:",A),l({phase:"failed",methodIndex:h,message:_o(A,r,"settings.providers.page.toast.oauthCompleteFailed")})}finally{b.current===O&&(b.current=null)}},w=async(h,v)=>{l({phase:"authorizing",methodIndex:h});let O;try{const A=await fn.getSdkClient().provider.oauth.authorize({providerID:t,method:h,...Object.keys(v).length>0?{inputs:v}:{}});if(A.error)throw A.error;const C=Tg(A.data);if(!C){l({phase:"failed",methodIndex:h,message:r("settings.providers.page.toast.oauthDetailsMissing")});return}O=C}catch(A){console.error("Failed to start OAuth flow:",A),l({phase:"failed",methodIndex:h,message:_o(A,r,"settings.providers.page.toast.oauthStartFailed")});return}if(O.url&&wg(t,O.url)&&Pn(O.url),O.method==="code"){p(""),l({phase:"awaitingCode",methodIndex:h,authorization:O,submitting:!1});return}l({phase:"waiting",methodIndex:h,authorization:O}),await S(h)},N=h=>{const v=Sg(h.prompts);if(v.length===0){w(h.index,{});return}d(Ig(v)),l({phase:"prompting",methodIndex:h.index,prompts:v,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}w(i.methodIndex,Ag(i.prompts,g))},T=()=>{if(i.phase!=="awaitingCode")return;const h=y.trim();h&&(l({...i,submitting:!0}),S(i.methodIndex,h))},R=()=>{b.current?.abort(),b.current=null,l(er)},P=h=>{const v=g[h.key]??"",O=A=>d(C=>({...C,[h.key]:A}));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:v,onValueChange:O,children:[s.jsx(Ct,{size:Ft,className:rn,children:s.jsx(Mt,{children:A=>h.options.find(C=>C.value===A)?.label??null})}),s.jsx(It,{children:h.options.map(A=>s.jsx(at,{value:A.value,children:A.hint?`${A.label} · ${A.hint}`:A.label},A.value))})]}):s.jsx(He,{value:v,onChange:A=>O(A.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(H,{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(H,{variant:"outline",size:"xs",className:"!font-normal",onClick:()=>{Pn(h.url??"")},children:r("settings.providers.page.actions.open")}),s.jsx(H,{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 v=c===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(H,{variant:"outline",size:"xs",className:"!font-normal shrink-0",onClick:()=>N(h),disabled:I,children:r("settings.providers.page.actions.connect")})]}),v&&i.phase==="prompting"&&s.jsxs("div",{className:"space-y-3",children:[Mr(i.prompts,g).map(P),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(H,{size:"xs",className:"!font-normal",onClick:m,children:r("settings.providers.page.actions.continue")}),s.jsx(H,{variant:"ghost",size:"xs",className:"!font-normal",onClick:R,children:r("settings.providers.page.actions.cancel")})]})]}),v&&i.phase==="authorizing"&&s.jsxs("p",{className:"typography-meta text-muted-foreground flex items-center gap-2",children:[s.jsx(L,{name:"loader",className:"h-3.5 w-3.5 animate-spin"}),r("settings.providers.page.auth.oauth.starting")]}),v&&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(L,{name:"loader",className:"h-3.5 w-3.5 animate-spin"}),r("settings.providers.page.auth.oauth.waiting")]}),s.jsx(H,{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")})]}),v&&i.phase==="awaitingCode"&&s.jsxs("div",{className:"space-y-3",children:[j(i.authorization),s.jsx("p",{className:"typography-meta text-muted-foreground",children:r("settings.providers.page.auth.oauth.codeHint")}),s.jsxs("div",{className:"flex items-center gap-2",children:[s.jsx(He,{value:y,onChange:O=>p(O.target.value),placeholder:r("settings.providers.page.auth.pasteAuthorizationCodePlaceholder"),className:"font-mono text-xs",disabled:i.submitting}),s.jsx(H,{size:"xs",className:"!font-normal shrink-0",onClick:T,disabled:i.submitting||y.trim().length===0,children:i.submitting?r("settings.providers.page.actions.saving"):r("settings.providers.page.actions.complete")}),s.jsx(H,{variant:"ghost",size:"xs",className:"!font-normal shrink-0",onClick:R,disabled:i.submitting,children:r("settings.providers.page.actions.cancel")})]})]}),v&&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(H,{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),d=ie(q=>q.hideAllModels),y=ie(q=>q.showAllModels),[p,b]=o.useState({}),[c,I]=o.useState(!1),[f,S]=o.useState({}),[w,N]=o.useState(null),[m,T]=o.useState(""),[R,P]=o.useState([]),[j,h]=o.useState(!1),[v,O]=o.useState(null),[A,C]=o.useState(""),[M,B]=o.useState(""),[V,k]=o.useState(!1),[D,$]=o.useState({}),[K,Q]=o.useState(0),[te,U]=o.useState(!1),[le,_]=o.useState(null),[G,z]=o.useState(null),[F,ee]=o.useState(null),[Y,ae]=o.useState(null),[ge,de]=o.useState(null),[he,se]=o.useState(null),re=n===Ea,ue=re&&A===Kn,Ce=!!(G&&n&&G===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()=>{I(!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&&I(!1)}})(),()=>{q=!1}},[n,t]),o.useEffect(()=>{if(!eg(re))return;let q=!0;return(async()=>{h(!0),O(null);try{const Pe=await fn.getSdkClient().provider.list();if(Pe.error)throw new Error(`provider.list failed: ${String(Pe.error)}`);if(!q)return;P(Mg(Pe.data))}catch(Pe){if(!q)return;console.error("Failed to load available providers:",Pe),O(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&&A&&A!==Kn&&!ye.some(q=>q.id===A)&&C("")},[n,A,ye]),o.useEffect(()=>{if(n===Ea){U(!0),_(null),z(null),ee(null),ae(null),de(null);return}U(!1),_(null),G&&G!==n&&(z(null),ee(null),ae(null),de(null))},[n,G]),o.useEffect(()=>{if(!n||n===Ea)return;const q=D[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,D,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&&$(pt=>({...pt,[n]:st}))}catch(Pe){q||console.error("Failed to load provider sources:",Pe)}})(),()=>{q=!0}},[n,K,e,t]);const fe=o.useCallback(()=>{Q(q=>q+1)},[]),_e=o.useCallback(q=>{$(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?D[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")),S(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:G?Y??zo(D[G]):"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})),C(""),z(null),ee(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),ee(null),ae(null),de(null),se(null),C(""))};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(L,{name:"stack",className:"mx-auto mb-3 h-12 w-12 opacity-50"}),s.jsx("p",{className:"typography-body",children:t("settings.providers.page.empty.noProvidersDetected")}),s.jsx("p",{className:"typography-meta mt-1 opacity-75",children:t("settings.providers.page.empty.checkOpenCodeConfiguration")})]})});if(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")}):v?s.jsx("p",{className:"typography-meta text-muted-foreground",children:v}):s.jsxs(cn,{open:V,onOpenChange:q=>{k(q),q||B("")},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:[A&&A!==Kn?s.jsx(Un,{providerId:A,className:"h-3.5 w-3.5 flex-shrink-0"}):null,s.jsx("span",{className:xe("truncate typography-ui-label font-normal",A?"text-foreground":"text-muted-foreground"),children:A===Kn?t("settings.providers.page.custom.optionLabel"):A?ye.find(q=>q.id===A)?.name||A:t("settings.providers.page.connect.selectProviderPlaceholder")})]}),s.jsx(L,{name:"arrow-down-s",className:"h-4 w-4 flex-shrink-0 text-muted-foreground/50"})]})}),s.jsxs(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(L,{name:"search",className:"h-4 w-4 text-muted-foreground"}),s.jsx("input",{type:"text",value:M,onChange:q=>B(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"],M),Pe=ki(ye,M,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:()=>{C(Je.id),k(!1),B("")},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})]}),A===Je.id&&s.jsx(L,{name:"check",className:"h-4 w-4 text-[var(--primary-base)]"})]},Je.id)),ke?s.jsxs(dn,{onSelect:()=>{C(Kn),k(!1),B("")},className:"flex items-center justify-between",children:[s.jsxs("span",{className:"flex items-center gap-2 min-w-0",children:[s.jsx(L,{name:"add",className:"h-4 w-4 flex-shrink-0"}),s.jsx("span",{className:"truncate",children:q})]}),A===Kn&&s.jsx(L,{name:"check",className:"h-4 w-4 text-[var(--primary-base)]"})]},Kn):null]})})()})]})]})]})}),ue?s.jsx(Uo,{mode:"create",existingProviderIDs:Se,busy:w?.startsWith("custom:")??!1,authFailureHint:ge,onCancel:()=>{C(""),de(null),se(null)},onDisconnect:ge&&he?()=>{be(he)}:void 0,onSubmit:Ge}):A?s.jsx(ze,{title:t("settings.providers.page.auth.title"),settingsItem:"providers.auth",contentClassName:"space-y-4",children:c?s.jsx("p",{className:"typography-meta text-muted-foreground",children:t("settings.providers.page.auth.loadingMethods")}):s.jsx(s.Fragment,{children:(()=>{const q=p[A]??[],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[A]??"",onChange:Je=>S(ot=>({...ot,[A]:Je.target.value})),placeholder:t("settings.providers.page.auth.apiKeyPlaceholder"),className:"flex-1 font-mono text-xs"}),s.jsx(H,{size:"xs",className:"!font-normal shrink-0",onClick:()=>Ve(A),disabled:w===`api:${A}`,children:w===`api:${A}`?t("settings.providers.page.actions.saving"):t("settings.providers.page.actions.saveKey")})]})]}):null,ke.length>0?s.jsx($o,{providerId:A,methods:ke,onConnected:()=>Z(A),className:xe(Pe&&"border-t border-[var(--surface-subtle)] pt-2")},A):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(L,{name:"stack",className:"mx-auto mb-3 h-12 w-12 opacity-50"}),s.jsx("p",{className:"typography-body",children:t("settings.providers.page.empty.selectProviderFromSidebar")}),s.jsx("p",{className:"typography-meta mt-1 opacity-75",children:t("settings.providers.page.empty.reviewDetailsAndConfigureAuth")})]})});const 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&&F?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:F,allowExistingAuth:Ze||!Ee,busy:w?.startsWith("custom:")??!1,authFailureHint:ge,onCancel:()=>{z(null),ee(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(H,{variant:"outline",size:"xs",className:"!font-normal",onClick:()=>{de(null),ee(mg(Ne)),ae(zo(Oe)),z(Ne.id)},children:t("settings.providers.page.actions.edit")}):null,s.jsx(H,{variant:"outline",size:"xs",className:"!font-normal",onClick:()=>{const q=!te;U(q),_(q?null:Ne.id)},children:t(te?"settings.providers.page.actions.hide":"settings.providers.page.actions.reconnect")})]}),settingsItem:"providers.auth",children:te?c?s.jsx("div",{className:"py-1.5 typography-meta text-muted-foreground",children:t("settings.providers.page.auth.loadingMethods")}):s.jsxs("div",{className:"space-y-4",children:[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=>S(ke=>({...ke,[Ne.id]:q.target.value})),placeholder:t("settings.providers.page.auth.apiKeyPlaceholder"),className:"flex-1 font-mono text-xs"}),s.jsx(H,{size:"xs",className:"!font-normal shrink-0",onClick:()=>Ve(Ne.id),disabled:w===`api:${Ne.id}`,children:w===`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(L,{name:"alert",className:"w-4 h-4 text-[var(--status-warning)] shrink-0"}),s.jsx("span",{className:"typography-ui-label text-foreground",children:t("settings.providers.page.auth.incomplete")}),s.jsx(Jt,{children:Le})]}):s.jsxs("div",{className:"flex items-center gap-1.5 py-1.5",children:[s.jsx(L,{name:"check",className:"w-4 h-4 text-[var(--status-success)] shrink-0"}),s.jsx("span",{className:"typography-ui-label text-foreground",children:t("settings.providers.page.auth.connected")}),s.jsx(Jt,{children:t("settings.providers.page.auth.useReconnectHint")})]})}),s.jsx(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(H,{variant:"ghost",size:"xs",className:"!font-normal text-[var(--status-error)] hover:text-[var(--status-error)]",onClick:()=>ne(Ne.id),disabled:w===`disconnect:${Ne.id}`,children:w===`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(H,{variant:"outline",size:"xs",className:"!font-normal",onClick:()=>{const q=we.map(ke=>typeof ke?.id=="string"?ke.id:"").filter(ke=>ke.length>0);d(Ne.id,q)},children:t("settings.providers.page.actions.hideAll")}),s.jsx(H,{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(L,{name:"search",className:"absolute left-2 top-1/2 -translate-y-1/2 h-3.5 w-3.5 text-muted-foreground"}),s.jsx(He,{value:m,onChange:q=>T(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(L,{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(L,{name:"eye-off",className:"h-3.5 w-3.5"}):s.jsx(L,{name:"eye",className:"h-3.5 w-3.5"})})]})]})},ke)})})]}):null]})},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=Xt(Fg),i=Xt(Kg),l=Xt(zg),g=Xt(Ug),d=Xt(_g),y=Xt($g),p=Xt(Vg),b=Xt(Bg);let c,I;e[0]!==b?(c=()=>{b()},I=[b],e[0]=b,e[1]=c,e[2]=I):(c=e[1],I=e[2]),o.useEffect(c,I);const f=Hg;let S;e[3]!==p?(S=ae=>{ae!=="usage"&&ae!=="remaining"||(p(ae),f({usageDisplayMode:ae}))},e[3]=p,e[4]=S):S=e[4];const w=S;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 T;e[8]!==m?(T=s.jsx("h2",{className:`${un} mb-3`,children:m}),e[8]=m,e[9]=T):T=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 P;e[12]!==R?(P=s.jsx("span",{className:"typography-meta text-muted-foreground",children:R}),e[12]=R,e[13]=P):P=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 v;e[18]!==n?(v=n("settings.usage.sidebar.actions.refreshTitle"),e[18]=n,e[19]=v):v=e[19];const O=d&&"animate-spin";let A;e[20]!==O?(A=xe("h-3.5 w-3.5",O),e[20]=O,e[21]=A):A=e[21];let C;e[22]!==A?(C=s.jsx(L,{name:"refresh",className:A}),e[22]=A,e[23]=C):C=e[23];let M;e[24]!==d||e[25]!==h||e[26]!==v||e[27]!==C||e[28]!==j?(M=s.jsx("div",{className:"flex items-center gap-2",children:s.jsx(H,{size:"sm",variant:"ghost",className:"h-7 w-7 px-0 text-muted-foreground",onClick:j,"aria-label":h,title:v,disabled:d,children:C})}),e[24]=d,e[25]=h,e[26]=v,e[27]=C,e[28]=j,e[29]=M):M=e[29];let B;e[30]!==M||e[31]!==P?(B=s.jsxs("div",{className:"flex items-center justify-between gap-2",children:[P,M]}),e[30]=M,e[31]=P,e[32]=B):B=e[32];let V;e[33]!==n?(V=n("settings.usage.sidebar.field.display"),e[33]=n,e[34]=V):V=e[34];let k;e[35]!==V?(k=s.jsx("span",{className:"typography-micro text-muted-foreground",children:V}),e[35]=V,e[36]=k):k=e[36];let D;e[37]!==n?(D=n("settings.usage.sidebar.field.displayModePlaceholder"),e[37]=n,e[38]=D):D=e[38];let $;e[39]!==D?($=s.jsx(Ct,{className:"w-fit",children:s.jsx(Mt,{placeholder:D})}),e[39]=D,e[40]=$):$=e[40];let K;e[41]!==n?(K=n("settings.usage.sidebar.field.displayModeUsage"),e[41]=n,e[42]=K):K=e[42];let Q;e[43]!==K?(Q=s.jsx(at,{value:"usage",children:K}),e[43]=K,e[44]=Q):Q=e[44];let te;e[45]!==n?(te=n("settings.usage.sidebar.field.displayModeRemaining"),e[45]=n,e[46]=te):te=e[46];let U;e[47]!==te?(U=s.jsx(at,{value:"remaining",children:te}),e[47]=te,e[48]=U):U=e[48];let le;e[49]!==Q||e[50]!==U?(le=s.jsxs(It,{children:[Q,U]}),e[49]=Q,e[50]=U,e[51]=le):le=e[51];let _;e[52]!==w||e[53]!==$||e[54]!==le||e[55]!==y?(_=s.jsxs(St,{value:y,onValueChange:w,children:[$,le]}),e[52]=w,e[53]=$,e[54]=le,e[55]=y,e[56]=_):_=e[56];let G;e[57]!==k||e[58]!==_?(G=s.jsxs("div",{className:"mt-2 flex items-center justify-between gap-2",children:[k,_]}),e[57]=k,e[58]=_,e[59]=G):G=e[59];let z;e[60]!==B||e[61]!==G||e[62]!==T?(z=s.jsxs("div",{className:"border-b px-3 pt-4 pb-3",children:[T,B,G]}),e[60]=B,e[61]=G,e[62]=T,e[63]=z):z=e[63];let F;e[64]!==a||e[65]!==r||e[66]!==i||e[67]!==l||e[68]!==n?(F=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]=F):F=e[69];let ee;e[70]!==F?(ee=s.jsx(vs,{outerClassName:"flex-1 min-h-0",className:"space-y-1 px-3 py-2 overflow-x-hidden",children:F}),e[70]=F,e[71]=ee):ee=e[71];let Y;return e[72]!==z||e[73]!==ee?(Y=s.jsxs("div",{className:N,children:[z,ee]}),e[72]=z,e[73]=ee,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 d;e[2]!==g?(d=Pl(g),e[2]=g,e[3]=d):d=e[3];const y=d;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 c;e[6]!==r?(c=xe("relative h-2.5 rounded-full bg-[var(--interactive-border)] overflow-hidden",r),e[6]=r,e[7]=c):c=e[7];const I=`${l}%`;let f;e[8]!==b||e[9]!==I?(f={...b,width:I},e[8]=b,e[9]=I,e[10]=f):f=e[10];let S;e[11]!==l||e[12]!==f?(S=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]=S):S=e[13];let w;return e[14]!==c||e[15]!==S?(w=s.jsx("div",{className:c,children:S}),e[14]=c,e[15]=S,e[16]=w):w=e[16],w},tr=t=>{const e=ut.c(37),{title:a,window:n,subtitle:r,showToggle:i,toggleEnabled:l,onToggle:g}=t,d=i===void 0?!1:i,y=l===void 0?!1:l,p=Xt(Wg),b=ie(qg),c=p==="remaining"?n.remainingPercent:n.usedPercent,I=c!==null,f=p==="remaining"?"remaining":"used";let S;e[0]!==c||e[1]!==n.valueLabel?(S=Kc(n.valueLabel,c),e[0]=c,e[1]=n.valueLabel,e[2]=S):S=e[2];const w=S,N=n.resetAfterFormatted??n.resetAtFormatted;let m;e[3]!==N||e[4]!==b||e[5]!==n.resetAt?(m=zc(n.resetAt,N,b),e[3]=N,e[4]=b,e[5]=n.resetAt,e[6]=m):m=e[6];const T=m,R=T?`Resets ${T}`:"";let P;e[7]!==a?(P=Uc(a),e[7]=a,e[8]=P):P=e[8];const j=P;let h;e[9]!==g||e[10]!==d||e[11]!==y?(h=d&&s.jsx(cr,{checked:y,onChange:$=>g?.($),ariaLabel:"Show in dropdown"}),e[9]=g,e[10]=d,e[11]=y,e[12]=h):h=e[12];let v;e[13]!==j?(v=s.jsx("span",{className:"typography-ui-label text-foreground truncate",children:j}),e[13]=j,e[14]=v):v=e[14];let O;e[15]!==r?(O=r&&s.jsx("span",{className:"typography-meta text-muted-foreground truncate",children:r}),e[15]=r,e[16]=O):O=e[16];let A;e[17]!==v||e[18]!==O?(A=s.jsxs("div",{className:"min-w-0 flex flex-col",children:[v,O]}),e[17]=v,e[18]=O,e[19]=A):A=e[19];let C;e[20]!==A||e[21]!==h?(C=s.jsxs("div",{className:"min-w-0 flex-1 flex items-center gap-2",children:[h,A]}),e[20]=A,e[21]=h,e[22]=C):C=e[22];const M=w==="-"?"":w;let B;e[23]!==M?(B=s.jsx("div",{className:"typography-ui-label text-foreground tabular-nums flex items-center justify-end",children:M}),e[23]=M,e[24]=B):B=e[24];let V;e[25]!==C||e[26]!==B?(V=s.jsxs("div",{className:"flex items-center justify-between gap-3",children:[C,B]}),e[25]=C,e[26]=B,e[27]=V):V=e[27];let k;e[28]!==f||e[29]!==c||e[30]!==I||e[31]!==R||e[32]!==n.usedPercent?(k=I?s.jsxs("div",{className:"mt-2.5",children:[s.jsx(Gg,{percent:c,tonePercent:n.usedPercent,className:"h-1.5"}),s.jsxs("div",{className:"mt-1 flex items-center justify-between",children:[s.jsx("span",{className:"typography-micro text-muted-foreground",children:R}),s.jsx("span",{className:"typography-micro text-muted-foreground",children:f})]})]}):R?s.jsx("div",{className:"mt-1 typography-micro text-muted-foreground",children:R}):null,e[28]=f,e[29]=c,e[30]=I,e[31]=R,e[32]=n.usedPercent,e[33]=k):k=e[33];let D;return e[34]!==V||e[35]!==k?(D=s.jsxs("div",{className:"py-3",children:[V,k]}),e[34]=V,e[35]=k,e[36]=D):D=e[36],D};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,d]=o.useState(!1),y=`/api/quota/credentials/${t}`;o.useEffect(()=>{yt(y).then(async c=>{if(!c.ok)throw new Error;const I=await c.json();r(I),l({})}).catch(()=>r({configured:!1}))},[y]);const p=async(c,I,f)=>{d(!0);try{const S=await yt(c,{method:I,headers:f?{"Content-Type":"application/json"}:void 0,body:f?JSON.stringify(f):void 0}),w=await S.json().catch(()=>null);if(!S.ok)throw new Error(w?.error);w?.configured!==void 0&&r(w),l({}),E.success(a("settings.providers.page.quotaCredentials.saved",{provider:e}))}catch(S){E.error(S instanceof Error&&S.message?S.message:a("settings.providers.page.openCodeGo.saveFailed"))}finally{d(!1)}},b=(c,I,f)=>s.jsxs("label",{className:"block typography-ui-label text-foreground",children:[I,s.jsx(He,{className:"mt-1 h-7 font-mono text-xs",type:"password",autoComplete:"off",value:i[c]??"",onChange:S=>l(w=>({...w,[c]:S.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(H,{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(H,{variant:"outline",size:"xs",disabled:g,onClick:()=>p(`${y}/validate`,"POST"),children:a("settings.providers.page.openCodeGo.validate")}),t==="cursor"&&s.jsx(H,{variant:"outline",size:"xs",disabled:g,onClick:()=>p(`${y}/import`,"POST"),children:a("settings.providers.page.actions.connect")}),n?.configured&&s.jsx(H,{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(D=>D.timeFormatPreference),a=Xt(D=>D.results),n=Xt(D=>D.selectedProviderId),r=Xt(D=>D.setSelectedProvider),i=Xt(D=>D.loadSettings),l=Xt(D=>D.fetchAllQuotas),g=Xt(D=>D.isLoading),d=Xt(D=>D.lastUpdated),y=Xt(D=>D.refreshErrors),p=Xt(D=>D.dropdownProviderIds),b=Xt(D=>D.setDropdownProviderIds),c=Xt(D=>D.selectedModels),I=Xt(D=>D.toggleModelSelected),f=Xt(D=>D.applyDefaultSelections);_c(),o.useEffect(()=>{i(),l()},[i,l]),o.useEffect(()=>{if(n||a.length===0)return;const D=a.find($=>$.configured)?.providerId;r(D??Ni[0]?.id??null)},[a,n,r]);const S=a.find(D=>D.providerId===n)??null,N=Ni.find(D=>D.id===n)?.name??n??t("settings.usage.sidebar.title"),m=S?.usage,T=n?y[n]:void 0,R=T?m?t("header.services.usageRefreshFailedStale",{error:T}):T:S?.configured&&!S.ok?S.error:null,P=n?p.includes(n):!1,j=n==="exe-dev"||n==="ollama-cloud"||n==="cursor",h=o.useCallback(D=>{if(!n)return;const $=D?Array.from(new Set([...p,n])):p.filter(K=>K!==n);b($),gt({usageDropdownProviders:$})},[p,n,b]),v=o.useMemo(()=>m?.models?Object.entries(m.models).map(([D,$])=>({name:D,windows:$})).filter(D=>Object.keys(D.windows.windows).length>0):[],[m?.models]);o.useEffect(()=>{n&&v.length>0&&f(n,v.map(D=>D.name))},[n,v,f]);const O=o.useMemo(()=>!n||v.length===0?new Map:$c(v,D=>D.name,n),[v,n]),A=o.useMemo(()=>{if(!n)return[];const D=Bc(n);return Vc(D)},[n]),[C,M]=o.useState(()=>({})),B=o.useCallback(D=>{M($=>({...$,[D]:!$[D]}))},[]),V=o.useCallback(D=>{if(!n)return;I(n,D);const $=c[n]??[],Q=$.includes(D)?$.filter(U=>U!==D):[...$,D],te={...c,[n]:Q};gt({usageSelectedModels:te})},[n,c,I]),k=n?c[n]??[]:[];return n?s.jsxs(es,{title:t("settings.usage.page.header.providerUsage",{provider:N}),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")}):S?.planLabel?t("settings.usage.page.header.lastUpdatedWithPlan",{plan:S.planLabel,time:Go(d,e)}):t("settings.usage.page.header.lastUpdated",{time:Go(d,e)}),showSaveStatus:!0,children:[s.jsx(ze,{divider:!1,settingsItem:"usage.work-status-panel",children:s.jsx(dt,{checked:P,onChange:h,label:t("settings.usage.page.options.showInWorkStatus"),ariaLabel:t("settings.usage.page.options.showInWorkStatusAria"),info:t("settings.usage.page.options.showInWorkStatusTooltip")})}),!S&&s.jsx("p",{className:"typography-ui-label text-foreground pb-8",children:t("settings.usage.page.state.noData")}),R&&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:R})]}),S&&!S.configured&&!j&&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:N}),m?.windows&&Object.keys(m.windows).length>0&&s.jsx(ze,{settingsItem:"usage.model-quotas",children:s.jsx("div",{className:"divide-y divide-[var(--surface-subtle)]",children:Object.entries(m.windows).map(([D,$])=>s.jsx(tr,{title:D,window:$},D))})}),v.length>0&&s.jsxs(ze,{title:t("settings.usage.page.section.modelQuotas"),contentClassName:"space-y-3",children:[A.map(D=>{const $=O.get(D.id)??[];if($.length===0)return null;const K=C[D.id]??!1;return s.jsx("section",{className:"p-2",children:s.jsxs(An,{open:!K,onOpenChange:()=>B(D.id),children:[s.jsxs(Tn,{className:"flex w-full items-center justify-between py-0.5 group",children:[s.jsxs("div",{className:"flex items-center gap-1.5 text-left",children:[s.jsx("span",{className:"typography-ui-label font-normal text-foreground",children:D.label}),s.jsxs("span",{className:"typography-micro text-muted-foreground",children:["(",$.length,")"]})]}),K?s.jsx(L,{name:"arrow-right-s",className:"h-4 w-4 text-muted-foreground group-hover:text-foreground transition-colors"}):s.jsx(L,{name:"arrow-down-s",className:"h-4 w-4 text-muted-foreground group-hover:text-foreground transition-colors"})]}),s.jsx(En,{children:s.jsx("div",{className:"divide-y divide-[var(--surface-subtle)] mt-1",children:$.map(Q=>{const te=Object.entries(Q.windows.windows);if(te.length===0)return null;const[U,le]=te[0],_=k.includes(Q.name);return s.jsx(tr,{title:U,subtitle:Ur(Q.name),window:le,showToggle:!0,toggleEnabled:_,onToggle:()=>V(Q.name)},Q.name)})})})]})},D.id)}),(()=>{const D=O.get(null)??[];if(D.length===0)return null;const $=C.other??!1;return s.jsx("section",{className:"p-2",children:s.jsxs(An,{open:!$,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:["(",D.length,")"]})]}),$?s.jsx(L,{name:"arrow-right-s",className:"h-4 w-4 text-muted-foreground group-hover:text-foreground transition-colors"}):s.jsx(L,{name:"arrow-down-s",className:"h-4 w-4 text-muted-foreground group-hover:text-foreground transition-colors"})]}),s.jsx(En,{children:s.jsx("div",{className:"divide-y divide-[var(--surface-subtle)] mt-1",children:D.map(K=>{const Q=Object.entries(K.windows.windows);if(Q.length===0)return null;const[te,U]=Q[0],le=k.includes(K.name);return s.jsx(tr,{title:te,subtitle:Ur(K.name),window:U,showToggle:!0,toggleEnabled:le,onToggle:()=>V(K.name)},K.name)})})})]})})})()]}),S?.configured&&m&&Object.keys(m.windows??{}).length===0&&v.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 d;e[2]===Symbol.for("react.memo_cache_sentinel")?(d={groupKey:"settings.magicPrompts.sidebar.group.linear",items:[{id:"linear.issue.review",titleKey:"settings.magicPrompts.sidebar.item.linearIssueReview"}]},e[2]=d):d=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,d,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 c;e[5]!==n?(c=n("settings.magicPrompts.sidebar.title"),e[5]=n,e[6]=c):c=e[6];let I;e[7]!==c?(I=s.jsx("h2",{className:un,children:c}),e[7]=c,e[8]=I):I=e[8];let f;e[9]!==n?(f=n("settings.magicPrompts.sidebar.description"),e[9]=n,e[10]=f):f=e[10];let S;e[11]!==f?(S=s.jsx("p",{className:"typography-meta mt-1 text-muted-foreground",children:f}),e[11]=f,e[12]=S):S=e[12];let w;e[13]!==I||e[14]!==S?(w=s.jsxs("div",{className:"border-b px-3 pt-4 pb-3",children:[I,S]}),e[13]=I,e[14]=S,e[15]=w):w=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(T=>s.jsxs("div",{className:"space-y-1",children:[s.jsx("div",{className:"typography-micro px-1 text-muted-foreground",children:n(T.groupKey)}),T.items.map(R=>{const P=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",P?"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)})]},T.groupKey))}),e[16]=a,e[17]=r,e[18]=i,e[19]=n,e[20]=N):N=e[20];let m;return e[21]!==w||e[22]!==N?(m=s.jsxs("div",{className:"flex h-full flex-col bg-background",children:[w,N]}),e[21]=w,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,d]=o.useState({}),[y,p]=o.useState({}),[b,c]=o.useState({}),[I,f]=o.useState(!1);o.useEffect(()=>{let j=!0;return(async()=>{r(!0);try{const v=await qc();if(!j)return;l(v)}catch(v){console.warn("Failed to load magic prompts:",v),E.error(t("settings.magicPrompts.page.toast.loadFailed"))}finally{j&&r(!1)}})(),()=>{j=!1}},[t]);const S=Wo[a]??Wo["git.commit.generate"],w=o.useCallback(j=>qo(i,j)?i[j]:Hi(j),[i]),N=o.useCallback(j=>g[j]??w(j),[g,w]),m=o.useCallback((j,h)=>{d(v=>v[j]===h?v:{...v,[j]:h})},[]),T=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(v=>({...v,[j]:!0}));try{const v=h===Hi(j)?await _r(j):await Hc(j,h);l(v.overrides),E.success(t("settings.magicPrompts.page.toast.saved"))}catch(v){const O=v instanceof Error?v.message:String(v);E.error(t("settings.magicPrompts.page.toast.saveFailed"),{description:O})}finally{p(v=>({...v,[j]:!1}))}},[N,t]),R=o.useCallback(async j=>{c(h=>({...h,[j]:!0}));try{const h=await _r(j);l(h.overrides),d(v=>({...v,[j]:Hi(j)})),E.success(t("settings.magicPrompts.page.toast.resetSuccess"))}catch(h){const v=h instanceof Error?h.message:String(h);E.error(t("settings.magicPrompts.page.toast.resetFailed"),{description:v})}finally{c(h=>({...h,[j]:!1}))}},[t]),P=o.useCallback(async()=>{f(!0);try{const j=await Gc();l(j.overrides),d({}),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(S.titleKey),titleAccessory:s.jsx(Jt,{contentClassName:"max-w-xs",children:e(S.descriptionKey)}),headerEnd:s.jsx(H,{"data-settings-item":"magic-prompts.reset-overrides",variant:"outline",size:"sm",onClick:()=>{P()},disabled:I||Object.keys(i).length===0,children:t(I?"settings.magicPrompts.page.actions.resetting":"settings.magicPrompts.page.actions.resetAllOverrides")}),showSaveStatus:!1,children:S.blocks.map((j,h)=>{const v=Wc(j.id),O=w(j.id),A=N(j.id),C=qo(i,j.id),M=A!==O,B=sr(j.id)&&A.trim().length===0,V=y[j.id]===!0,k=b[j.id]===!0;return s.jsxs(ze,{title:e(j.titleKey),info:v.description,description:v.placeholders&&v.placeholders.length>0?`${t("settings.magicPrompts.page.placeholdersLabel")} ${v.placeholders.map(D=>`{{${D.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:A,onChange:D=>m(j.id,D.target.value),className:"min-h-[220px] font-mono text-sm"}),B&&s.jsx("div",{className:"typography-micro text-[var(--status-error)]",children:t("settings.magicPrompts.page.validation.visiblePromptRequired")}),s.jsxs("div",{className:"flex items-center justify-between gap-2",children:[s.jsx("span",{className:"typography-micro text-muted-foreground",children:t(M?"settings.magicPrompts.page.status.unsavedChanges":C?"settings.magicPrompts.page.status.usingSavedOverride":"settings.magicPrompts.page.status.usingBuiltinDefault")}),s.jsxs("div",{className:"flex items-center gap-2",children:[s.jsx(H,{variant:"outline",size:"sm",onClick:()=>{R(j.id)},disabled:!C||V||k,children:t(k?"settings.magicPrompts.page.actions.resetting":"settings.magicPrompts.page.actions.resetToDefault")}),s.jsx(H,{size:"sm",onClick:()=>{T(j.id)},disabled:!M||V||k||B,children:t(V?"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),[d,y]=o.useState(null),{selectedSnippetName:p,snippets:b,setSelectedSnippet:c,setSnippetDraft:I,deleteSnippet:f,loadSnippets:S}=Si(Us(ah));let w,N;e[0]!==S?(w=()=>{S()},N=[S],e[0]=S,e[1]=w,e[2]=N):(w=e[1],N=e[2]),o.useEffect(w,N);let m;e[3]!==a||e[4]!==c||e[5]!==I||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++}`;I({name:ye,scope:"global"}),c(ye),a?.()},e[3]=a,e[4]=c,e[5]=I,e[6]=b,e[7]=m):m=e[7];const T=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 P=R;let j;e[12]!==b?(j=[...b].sort(rh),e[12]=b,e[13]=j):j=e[13];const h=j;let v;e[14]===Symbol.for("react.memo_cache_sentinel")?(v=xe("flex h-full flex-col","bg-background"),e[14]=v):v=e[14];let O;e[15]!==n?(O=n("settings.snippets.sidebar.title"),e[15]=n,e[16]=O):O=e[16];let A;e[17]!==O?(A=s.jsx("h2",{className:`${un} mb-3`,children:O}),e[17]=O,e[18]=A):A=e[18];let C;e[19]!==b.length||e[20]!==n?(C=n("settings.snippets.sidebar.total",{count:b.length}),e[19]=b.length,e[20]=n,e[21]=C):C=e[21];let M;e[22]!==C?(M=s.jsx("span",{className:"typography-meta text-muted-foreground",children:C}),e[22]=C,e[23]=M):M=e[23];let B;e[24]!==n?(B=n("settings.snippets.sidebar.actions.create"),e[24]=n,e[25]=B):B=e[25];let V;e[26]===Symbol.for("react.memo_cache_sentinel")?(V=s.jsx(L,{name:"add",className:"h-3.5 w-3.5"}),e[26]=V):V=e[26];let k;e[27]!==T||e[28]!==B?(k=s.jsx(H,{size:"sm","data-settings-item":"snippets.create",variant:"ghost",className:"h-7 w-7 px-0 -my-1 text-muted-foreground",onClick:T,"aria-label":B,children:V}),e[27]=T,e[28]=B,e[29]=k):k=e[29];let D;e[30]!==M||e[31]!==k?(D=s.jsxs("div",{className:"flex items-center justify-between gap-2",children:[M,k]}),e[30]=M,e[31]=k,e[32]=D):D=e[32];let $;e[33]!==D||e[34]!==A?($=s.jsxs("div",{className:"border-b px-3 pt-4 pb-3",children:[A,D]}),e[33]=D,e[34]=A,e[35]=$):$=e[35];let K;if(e[36]!==a||e[37]!==l||e[38]!==d||e[39]!==p||e[40]!==c||e[41]!==h||e[42]!==n){let Se;e[44]!==a||e[45]!==l||e[46]!==d||e[47]!==p||e[48]!==c||e[49]!==n?(Se=ye=>s.jsxs(Qn,{open:d===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:()=>{c(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(H,{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(L,{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(L,{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(L,{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]=d,e[47]=p,e[48]=c,e[49]=n,e[50]=Se):Se=e[50],K=h.map(Se),e[36]=a,e[37]=l,e[38]=d,e[39]=p,e[40]=c,e[41]=h,e[42]=n,e[43]=K}else K=e[43];let Q;e[51]!==K?(Q=s.jsx(vs,{outerClassName:"flex-1 min-h-0",className:"space-y-1 px-3 py-2",children:K}),e[51]=K,e[52]=Q):Q=e[52];const te=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 G=r?.name??"";let z;e[58]!==n||e[59]!==G?(z=n("settings.snippets.sidebar.dialog.deleteDescription",{name:G}),e[58]=n,e[59]=G,e[60]=z):z=e[60];let F;e[61]!==z?(F=s.jsx(Vt,{children:z}),e[61]=z,e[62]=F):F=e[62];let ee;e[63]!==_||e[64]!==F?(ee=s.jsxs(_t,{children:[_,F]}),e[63]=_,e[64]=F,e[65]=ee):ee=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(H,{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]!==P||e[74]!==de?(he=s.jsx(H,{size:"sm",onClick:P,children:de}),e[73]=P,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]!==ee||e[80]!==se?(re=s.jsxs(zt,{className:"max-w-md",children:[ee,se]}),e[79]=ee,e[80]=se,e[81]=re):re=e[81];let ue;e[82]!==te||e[83]!==re?(ue=s.jsx(Kt,{open:te,onOpenChange:U,children:re}),e[82]=te,e[83]=re,e[84]=ue):ue=e[84];let Ce;return e[85]!==$||e[86]!==Q||e[87]!==ue?(Ce=s.jsxs("div",{className:v,children:[$,Q,ue]}),e[85]=$,e[86]=Q,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(v=>({selectedSnippetName:v.selectedSnippetName,snippets:v.snippets,snippetDraft:v.snippetDraft,setSnippetDraft:v.setSnippetDraft,updateSnippet:v.updateSnippet,createSnippet:v.createSnippet}))),g=o.useMemo(()=>e?a.find(v=>v.name===e||v.aliases.includes(e))??null:null,[e,a]),d=!!(n&&n.name===e&&!g),[y,p]=o.useState(""),[b,c]=o.useState("global"),[I,f]=o.useState(""),[S,w]=o.useState(""),[N,m]=o.useState(""),[T,R]=o.useState(!1),P=o.useRef(null);o.useEffect(()=>{if(d&&n){const v={draftName:n.name||"",draftScope:n.scope||"global",description:n.description||"",aliases:(n.aliases||[]).join(", "),content:n.content||""};p(v.draftName),c(v.draftScope),f(v.description),w(v.aliases),m(v.content),P.current=v}else if(g){const v={draftName:"",draftScope:"global",description:g.description??"",aliases:g.aliases.join(", "),content:g.content};f(v.description),w(v.aliases),m(v.content),P.current=v}},[g,d,e,n]);const j=o.useMemo(()=>{const v=P.current;return v?d&&y!==v.draftName||d&&b!==v.draftScope?!0:I!==v.description||S!==v.aliases||N!==v.content:!1},[S,N,I,y,b,d]),h=async()=>{const v=d?y.trim().replace(/\s+/g,"-"):e?.trim();if(!v){E.error(t("settings.snippets.page.toast.nameRequired"));return}if(!N.trim()){E.error(t("settings.snippets.page.toast.contentRequired"));return}const O=S.split(",").map(A=>A.trim()).filter(Boolean);R(!0);try{if(!(d?await l(v,N,{aliases:O,description:I,scope:b}):await i(v,{content:N,aliases:O,description:I}))){E.error(t("settings.snippets.page.toast.saveFailed"));return}E.success(t("settings.snippets.page.toast.saved")),d&&r(null)}finally{R(!1)}};return e?s.jsxs(es,{title:d?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:[d?s.jsxs(Rt,{label:"#",children:[s.jsx(He,{value:y,onChange:v=>p(v.target.value),placeholder:t("settings.snippets.page.field.namePlaceholder"),className:"h-7 w-44 px-2"}),s.jsxs(St,{value:b,onValueChange:v=>c(v),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:I,onChange:v=>f(v.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:S,onChange:v=>w(v.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:v=>m(v.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(H,{onClick:h,disabled:T||!j,size:"xs",className:"!font-normal",children:t(T?"settings.common.actions.saving":"settings.common.actions.saveChanges")})})]})]}):s.jsx("div",{className:"flex h-full items-center justify-center",children:s.jsxs("div",{className:"text-center text-muted-foreground",children:[s.jsx(L,{name:"file-text",className:"mx-auto mb-3 h-12 w-12 opacity-50"}),s.jsx("p",{className:"typography-body",children:t("settings.snippets.page.empty.title")}),s.jsx("p",{className:"typography-meta mt-1 opacity-75",children:t("settings.snippets.page.empty.description")})]})})},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),d=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 c=await pn();c&&(c.gitmojiEnabled!==void 0&&a(c.gitmojiEnabled),c.gitChangesViewMode!==void 0&&i(c.gitChangesViewMode))}catch(c){console.warn("Failed to load git settings:",c)}finally{g(!1)}})()},[i,a]);const y=o.useCallback(async b=>{a(b);try{await gt({gitmojiEnabled:b})}catch(c){console.warn("Failed to save gitmoji setting:",c)}},[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:d.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(F=>F.getProfileById),l=_n(F=>F.createProfile),g=_n(F=>F.updateProfile),d=_n(F=>F.deleteProfile),y=o.useMemo(()=>a&&a!=="new"&&!n?i(a):null,[a,i,n]),p=a==="new"||n!=null,b=a==="global",[c,I]=o.useState(""),[f,S]=o.useState(""),[w,N]=o.useState(""),[m,T]=o.useState("ssh"),[R,P]=o.useState(""),[j,h]=o.useState(!1),[v,O]=o.useState(""),[A,C]=o.useState(""),[M,B]=o.useState("keyword"),[V,k]=o.useState("branch"),[D,$]=o.useState(!1),[K,Q]=o.useState(!1),[te,U]=o.useState(!1);o.useEffect(()=>{if(t){if(n){const F=n.host.split("/"),ee=F.length>=3?F[F.length-1]:n.host;I(ee),S(n.username),N(""),T("token"),P(""),h(!1),O(""),C(n.host),B("string"),k("code")}else if(p)I(""),S(""),N(""),T("ssh"),P(""),h(!1),O(""),C(""),B("keyword"),k("branch");else if(y)I(y.name),S(y.userName),N(y.userEmail),T(y.authType||"ssh"),P(y.sshKey||""),h(y.signCommits===!0),O(y.signingKey||""),C(y.host||""),B(y.color||"keyword"),k(y.icon||"branch");else if(b){const F=i("global");F&&(I(F.name),S(F.userName),N(F.userEmail),T(F.authType||"ssh"),P(F.sshKey||""),h(!1),O(""),C(F.host||""),B(F.color||"keyword"),k(F.icon||"branch"))}}},[t,a,y,p,n,b,i]);const le=async()=>{if(!f.trim()||!w.trim()){E.error(r("settings.gitIdentities.editor.toast.userNameEmailRequired"));return}if(m==="token"&&!A.trim()){E.error(r("settings.gitIdentities.editor.toast.hostRequiredForToken"));return}if(j&&!v.trim()){E.error(r("settings.gitIdentities.editor.toast.signingKeyRequired"));return}$(!0);try{const F={name:c.trim()||f.trim(),userName:f.trim(),userEmail:w.trim(),authType:m,sshKey:m==="ssh"&&R.trim()||null,signCommits:j,signingKey:v.trim()||null,host:m==="token"&&A.trim()||null,color:M,icon:V};let ee;if(p)ee=await l(F);else if(a)ee=await g(a,F);else return;ee?(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(F){console.error("Error saving profile:",F),E.error(r("settings.gitIdentities.editor.toast.saveUnexpectedError"))}finally{$(!1)}},_=async()=>{if(!(!a||p)){U(!0);try{await d(a)?(E.success(r("settings.gitIdentities.editor.toast.profileDeleted")),Q(!1),e(!1)):E.error(r("settings.gitIdentities.editor.toast.deleteProfileFailed"))}catch(F){console.error("Error deleting profile:",F),E.error(r("settings.gitIdentities.editor.toast.deleteUnexpectedError"))}finally{U(!1)}}},G=o.useMemo(()=>Jo.find(ee=>ee.key===M)?.cssVar||"var(--syntax-keyword)",[M]),z=n?r("settings.gitIdentities.editor.title.importCredential"):p?r("settings.gitIdentities.editor.title.newIdentity"):b?r("settings.gitIdentities.editor.title.globalIdentity"):y?.name||r("settings.gitIdentities.editor.title.editIdentity");return s.jsxs(s.Fragment,{children:[s.jsx(Kt,{open:t,onOpenChange:e,children:s.jsxs(zt,{className:"max-w-lg max-h-[85vh] overflow-y-auto",children:[s.jsxs(_t,{children:[s.jsx($t,{children:z}),s.jsx(Vt,{children:r(b?"settings.gitIdentities.editor.description.globalReadOnly":p?"settings.gitIdentities.editor.description.newProfile":"settings.gitIdentities.editor.description.editProfile")})]}),s.jsxs("div",{className:"space-y-5 py-2",children:[!b&&s.jsxs("div",{className:"space-y-3",children:[s.jsxs("div",{children:[s.jsx("label",{className:`${Tt} block mb-1.5`,children:r("settings.gitIdentities.editor.field.profileName")}),s.jsx(He,{value:c,onChange:F=>I(F.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(F=>s.jsx("button",{type:"button",onClick:()=>B(F.key),className:xe("w-6 h-6 rounded-md border-2 transition-all cursor-pointer",M===F.key?"border-foreground scale-110":"border-transparent hover:border-border"),style:{backgroundColor:F.cssVar},title:F.label},F.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(F=>{const ee=F.Icon;return s.jsx("button",{type:"button",onClick:()=>k(F.key),className:xe("w-7 h-7 rounded-md border-2 transition-all flex items-center justify-center cursor-pointer",V===F.key?"border-[var(--interactive-border)] bg-[var(--surface-muted)]":"border-transparent hover:border-[var(--interactive-border)] hover:bg-[var(--surface-muted)]/50"),title:F.label,children:s.jsx(L,{name:ee,className:"w-3.5 h-3.5",style:{color:V===F.key?G:"var(--surface-muted-foreground)"}})},F.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:F=>S(F.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:w,onChange:F=>N(F.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(H,{size:"sm",type:"button",variant:"chip","aria-pressed":m==="ssh",onClick:()=>T("ssh"),children:[s.jsx(L,{name:"lock-2",className:"w-3.5 h-3.5 mr-1"})," SSH"]}),s.jsxs(H,{size:"sm",type:"button",variant:"chip","aria-pressed":m==="token",onClick:()=>T("token"),children:[s.jsx(L,{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:F=>P(F.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:v,onChange:F=>O(F.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:A,onChange:F=>C(F.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(H,{variant:"outline",size:"sm",onClick:()=>Q(!0),className:"text-[var(--status-error)] hover:text-[var(--status-error)] border-[var(--status-error)]/30 hover:bg-[var(--status-error)]/10 mr-auto",children:[s.jsx(L,{name:"delete-bin",className:"w-3.5 h-3.5 mr-1"})," ",r("settings.common.actions.delete")]}),s.jsx(H,{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(H,{size:"sm",onClick:le,disabled:D,children:r(D?"settings.common.actions.saving":p?"settings.gitIdentities.editor.actions.create":"settings.gitIdentities.editor.actions.save")})]})]})}),s.jsx(Kt,{open:K,onOpenChange:F=>{te||Q(F)},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||c})})]}),s.jsxs(ts,{children:[s.jsx(H,{variant:"ghost",onClick:()=>Q(!1),disabled:te,children:r("settings.common.actions.cancel")}),s.jsx(H,{size:"sm",variant:"destructive",onClick:()=>{_()},disabled:te,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:d,loadDefaultGitIdentityId:y,setDefaultGitIdentityId:p,getUnimportedCredentials:b}=_n(Us(gh)),[c,I]=o.useState(!1),[f,S]=o.useState(null),[w,N]=o.useState(null),[m,T]=o.useState(null),[R,P]=o.useState(!1);let j,h;t[0]!==y||t[1]!==d||t[2]!==g||t[3]!==l?(j=()=>{l(),g(),d(),y()},h=[l,g,d,y],t[0]=y,t[1]=d,t[2]=g,t[3]=l,t[4]=j,t[5]=h):(j=t[4],h=t[5]),o.useEffect(j,h);let v,O,A,C,M,B,V,k,D,$,K,Q,te,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)=>{S(Ee),N(je??null),I(!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;P(!0),await i(m.id)?(E.success(e("settings.gitIdentities.page.toast.profileDeleted",{name:m.name})),T(null)):E.error(e("settings.gitIdentities.page.toast.deleteProfileFailed")),P(!1)},t[33]=m,t[34]=i,t[35]=e,t[36]=we):we=t[36],A=we,O=es,t[37]!==e?(M=e("settings.page.git.title"),t[37]=e,t[38]=M):M=t[38],B=!0,v=ze,t[39]!==e?(Q=e("settings.gitIdentities.page.section.title"),t[39]=e,t[40]=Q):Q=t[40],te=!1;let Re,Fe;t[41]===Symbol.for("react.memo_cache_sentinel")?(Re=()=>Z("new"),Fe=s.jsx(L,{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(H,{size:"sm",variant:"outline",onClick:Re,children:[Fe," ",Ke]}),t[45]=Ke,t[46]=U):U=t[46],C="git.identities",V="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}),D=a.map((Ee,je)=>s.jsx(Qo,{profile:Ee,isDefault:r===Ee.id,onEdit:()=>Z(Ee.id),onToggleDefault:()=>be(Ee.id),onDelete:()=>T(Ee),hasBorder:je<a.length-1||Ge.length>0},Ee.id)),$=!n&&a.length===0&&Ge.length===0&&s.jsxs("div",{className:"py-8 px-4 text-center text-muted-foreground",children:[s.jsx(L,{name:"shield-keyhole",className:"mx-auto mb-2 h-8 w-8 opacity-40"}),s.jsx("p",{className:"typography-ui-label",children:e("settings.gitIdentities.page.empty.title")}),s.jsx("p",{className:"typography-meta mt-1 opacity-75",children:e("settings.gitIdentities.page.empty.description")})]}),K=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]=v,t[15]=O,t[16]=A,t[17]=C,t[18]=M,t[19]=B,t[20]=V,t[21]=k,t[22]=D,t[23]=$,t[24]=K,t[25]=Q,t[26]=te,t[27]=U}else v=t[14],O=t[15],A=t[16],C=t[17],M=t[18],B=t[19],V=t[20],k=t[21],D=t[22],$=t[23],K=t[24],Q=t[25],te=t[26],U=t[27];let le;t[47]!==V||t[48]!==k||t[49]!==D||t[50]!==$||t[51]!==K?(le=s.jsxs("div",{className:V,children:[k,D,$,K]}),t[47]=V,t[48]=k,t[49]=D,t[50]=$,t[51]=K,t[52]=le):le=t[52];let _;t[53]!==v||t[54]!==C||t[55]!==le||t[56]!==Q||t[57]!==te||t[58]!==U?(_=s.jsx(v,{title:Q,divider:te,headerAction:U,settingsItem:C,children:le}),t[53]=v,t[54]=C,t[55]=le,t[56]=Q,t[57]=te,t[58]=U,t[59]=_):_=t[59];let G;t[60]===Symbol.for("react.memo_cache_sentinel")?(G=s.jsx(Xl,{}),t[60]=G):G=t[60];let z;t[61]!==O||t[62]!==M||t[63]!==B||t[64]!==_?(z=s.jsxs(O,{title:M,showSaveStatus:B,children:[_,G]}),t[61]=O,t[62]=M,t[63]=B,t[64]=_,t[65]=z):z=t[65];let F;t[66]!==w||t[67]!==c||t[68]!==f?(F=s.jsx(ch,{open:c,onOpenChange:I,profileId:f,importData:w}),t[66]=w,t[67]=c,t[68]=f,t[69]=F):F=t[69];const ee=m!==null;let Y;t[70]!==R?(Y=Ge=>{R||Ge||T(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=()=>T(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(H,{variant:"ghost",onClick:ue,disabled:R,children:Ce}),t[87]=R,t[88]=Ce,t[89]=Se):Se=t[89];let ye;t[90]!==A?(ye=()=>{A()},t[90]=A,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(H,{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]!==ee||t[105]!==Y||t[106]!==Ne?(Oe=s.jsx(Kt,{open:ee,onOpenChange:Y,children:Ne}),t[104]=ee,t[105]=Y,t[106]=Ne,t[107]=Oe):Oe=t[107];let Ve;return t[108]!==z||t[109]!==F||t[110]!==Oe?(Ve=s.jsxs(s.Fragment,{children:[z,F,Oe]}),t[108]=z,t[109]=F,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:d}=t,{t:y}=tt(),[p,b]=o.useState(!1),c=dh[a.icon||"branch"]||"git-branch",I=uh[a.color||""],f=a.authType||"ssh";let S;e[0]!==r?(S=_=>{_.currentTarget===_.target&&(_.key!=="Enter"&&_.key!==" "||(_.preventDefault(),r()))},e[0]=r,e[1]=S):S=e[1];const w=S;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:G=>{G.stopPropagation(),i()},children:y(n?"settings.gitIdentities.page.actions.unsetDefault":"settings.gitIdentities.page.actions.setAsDefault")}),!g&&l&&s.jsxs(_,{onClick:G=>{G.stopPropagation(),l()},className:"text-destructive focus:text-destructive",children:[s.jsx(L,{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,T=d&&"border-b border-[var(--surface-subtle)]";let R;e[8]!==T?(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",T),e[8]=T,e[9]=R):R=e[9];let P;e[10]===Symbol.for("react.memo_cache_sentinel")?(P=_=>{_.preventDefault(),b(!0)},e[10]=P):P=e[10];let j;e[11]!==w||e[12]!==r||e[13]!==R?(j=s.jsx("div",{className:R,onClick:r,role:"button",tabIndex:0,onKeyDown:w,onContextMenu:P}),e[11]=w,e[12]=r,e[13]=R,e[14]=j):j=e[14];let h;e[15]!==I?(h={color:I},e[15]=I,e[16]=h):h=e[16];let v;e[17]!==c||e[18]!==h?(v=s.jsx(L,{name:c,className:"w-4 h-4 shrink-0",style:h}),e[17]=c,e[18]=h,e[19]=v):v=e[19];let O;e[20]!==a.name?(O=s.jsx("span",{className:"typography-ui-label text-foreground truncate",children:a.name}),e[20]=a.name,e[21]=O):O=e[21];let A;e[22]!==f?(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:f}),e[22]=f,e[23]=A):A=e[23];let C;e[24]!==n||e[25]!==y?(C=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]=C):C=e[26];let M;e[27]!==g||e[28]!==y?(M=g&&s.jsx("span",{className:"typography-micro text-muted-foreground bg-muted px-1 rounded flex-shrink-0 leading-none pb-px border border-border/50",children:y("settings.agents.sidebar.badge.system")}),e[27]=g,e[28]=y,e[29]=M):M=e[29];let B;e[30]!==A||e[31]!==C||e[32]!==M||e[33]!==O?(B=s.jsxs("div",{className:"flex items-center gap-1.5",children:[O,A,C,M]}),e[30]=A,e[31]=C,e[32]=M,e[33]=O,e[34]=B):B=e[34];const V=f==="token"&&a.host?a.host:a.userEmail;let k;e[35]!==V?(k=s.jsx("div",{className:"typography-micro text-muted-foreground/60 truncate leading-tight",children:V}),e[35]=V,e[36]=k):k=e[36];let D;e[37]!==B||e[38]!==k?(D=s.jsxs("div",{className:"min-w-0",children:[B,k]}),e[37]=B,e[38]=k,e[39]=D):D=e[39];let $;e[40]!==D||e[41]!==v?($=s.jsxs("div",{className:"flex items-center gap-3 min-w-0",children:[v,D]}),e[40]=D,e[41]=v,e[42]=$):$=e[42];let K;e[43]===Symbol.for("react.memo_cache_sentinel")?(K=s.jsx(on,{asChild:!0,children:s.jsx(H,{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(L,{name:"more-2",className:"h-3.5 w-3.5"})})}),e[43]=K):K=e[43];let Q;e[44]!==m?(Q=s.jsxs(cn,{children:[K,s.jsx(ln,{align:"end",className:"w-fit min-w-28",children:m(dn)})]}),e[44]=m,e[45]=Q):Q=e[45];let te;e[46]!==$||e[47]!==Q||e[48]!==j?(te=s.jsxs(Jn,{render:j,children:[$,Q]}),e[46]=$,e[47]=Q,e[48]=j,e[49]=te):te=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]!==te||e[54]!==U?(le=s.jsxs(Qn,{open:p,onOpenChange:b,children:[te,U]}),e[52]=p,e[53]=te,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,d=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 c;e[4]!==d?(c=s.jsx("span",{className:"typography-ui-label text-foreground truncate block",children:d}),e[4]=d,e[5]=c):c=e[5];const I=y?a.host:a.username;let f;e[6]!==I?(f=s.jsx("span",{className:"typography-micro text-muted-foreground/60 truncate block leading-tight",children:I}),e[6]=I,e[7]=f):f=e[7];let S;e[8]!==c||e[9]!==f?(S=s.jsxs("div",{className:"min-w-0",children:[c,f]}),e[8]=c,e[9]=f,e[10]=S):S=e[10];let w;e[11]===Symbol.for("react.memo_cache_sentinel")?(w=s.jsx(L,{name:"download",className:"h-3 w-3"}),e[11]=w):w=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(H,{size:"sm",variant:"ghost",onClick:n,className:"gap-1 shrink-0",children:[w,N]}),e[14]=n,e[15]=N,e[16]=m):m=e[16];let T;return e[17]!==m||e[18]!==b||e[19]!==S?(T=s.jsxs("div",{className:b,children:[S,m]}),e[17]=m,e[18]=b,e[19]=S,e[20]=T):T=e[20],T};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),d=Cn(k=>k.setStatus),y=o.useCallback(async k=>{await Pn(k)},[]),[p,b]=o.useState(!1),[c,I]=o.useState(null),[f,S]=o.useState(null),w=o.useRef(null),N=o.useCallback(()=>{w.current!=null&&(window.clearInterval(w.current),w.current=null),S(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 $=await yt("/api/github/auth/start",{method:"POST",headers:{"Content-Type":"application/json",Accept:"application/json"},body:JSON.stringify({})}),K=await $.json().catch(()=>null);if(!$.ok||!K||!("deviceCode"in K))throw new Error(K?.error||$.statusText);return K})();I(k),S(Math.max(1,k.interval)*1e3);const D=k.verificationUriComplete||k.verificationUri;y(D)}catch(k){console.error("Failed to start GitHub connect:",k),E.error(e("settings.github.page.toast.startConnectFailed"))}finally{b(!1)}},[y,n,e]),T=o.useCallback(async k=>{if(n)return n.authComplete(k);const D=await yt("/api/github/auth/complete",{method:"POST",headers:{"Content-Type":"application/json",Accept:"application/json"},body:JSON.stringify({deviceCode:k})}),$=await D.json().catch(()=>null);if(!D.ok||!$)throw new Error($?.error||D.statusText);return $},[n]);o.useEffect(()=>{if(!(!c?.deviceCode||!f)&&w.current==null)return w.current=window.setInterval(()=>{(async()=>{try{const k=await T(c.deviceCode);if(k.connected){E.success(e("settings.github.page.toast.connected")),I(null),N(),await g(n,{force:!0});return}k.status==="slow_down"&&S(D=>D?D+5e3:5e3),(k.status==="expired_token"||k.status==="access_denied")&&(E.error(k.error||e("settings.github.page.toast.authorizationFailed")),I(null),N())}catch(k){console.warn("GitHub polling failed:",k)}})()},f),()=>{w.current!=null&&(window.clearInterval(w.current),w.current=null)}},[c,f,T,g,n,N,e]);const R=o.useCallback(async k=>{b(!0);try{if(n)await n.authSetGhCliDisabled(k);else{const D=await yt("/api/github/auth/gh-cli",{method:"POST",headers:{"Content-Type":"application/json",Accept:"application/json"},body:JSON.stringify({disabled:k})}),$=await D.json().catch(()=>null);if(!D.ok)throw new Error($?.error||D.statusText)}E.success(e(k?"settings.github.page.toast.ghCliDisabled":"settings.github.page.toast.ghCliEnabled")),await g(n,{force:!0})}catch(D){console.error("Failed to update gh CLI setting:",D),E.error(e("settings.github.page.toast.ghCliUpdateFailed"))}finally{b(!1)}},[g,n,e]),P=o.useCallback(async()=>{b(!0);try{if(N(),I(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 D=n?await n.authActivate(k):await(async()=>{const $=await yt("/api/github/auth/activate",{method:"POST",headers:{"Content-Type":"application/json",Accept:"application/json"},body:JSON.stringify({accountId:k})}),K=await $.json().catch(()=>null);if(!$.ok||!K)throw new Error(K?.error||$.statusText);return K})();d(D),E.success(e("settings.github.page.toast.accountSwitched"))}catch(D){console.error("Failed to switch GitHub account:",D),E.error(e("settings.github.page.toast.accountSwitchFailed"))}finally{b(!1)}}},[n,d,e]);if(i&&!l)return null;const h=!!r?.connected,v=r?.user,A=(r?.accounts??[]).filter(k=>!k.current),C=r?.ghCli??null,M=C?.active?e("settings.github.page.accountSource.cli"):e("settings.github.page.accountSource.oauth"),B=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:[v?.avatarUrl?s.jsx("img",{src:v.avatarUrl,alt:v.login?e("settings.github.page.avatarAlt.withLogin",{login:v.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:v?.name?.trim()||v?.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(L,{name:"github-fill",className:"h-3.5 w-3.5 shrink-0"}),s.jsx("span",{className:"font-mono",children:v?.login||e("settings.github.page.label.unknownUser")}),v?.email&&s.jsx("span",{className:"opacity-50",children:"•"}),v?.email&&s.jsx("span",{children:v.email}),s.jsx("span",{className:"opacity-50",children:"•"}),s.jsx("span",{children:M})]}),r?.scope&&s.jsx("div",{className:"typography-micro text-muted-foreground/70 mt-0.5",children:e("settings.github.page.label.scopes",{value:r.scope})}),C?.active&&s.jsx("div",{className:"typography-micro text-muted-foreground/70 mt-0.5",children:e("settings.github.page.ghCli.activeDescription")})]})]}),C?.active?s.jsx(H,{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(H,{size:"sm",variant:"outline",onClick:P,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(H,{size:"sm",variant:"default",onClick:m,disabled:p,children:e("settings.github.page.actions.connect")})]}),A.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:A.map(k=>{const D=k.user,$=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:[D?.avatarUrl?s.jsx("img",{src:D.avatarUrl,alt:D.login?e("settings.github.page.avatarAlt.withLogin",{login:D.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(L,{name:"github-fill",className:"h-3 w-3 text-muted-foreground"})}),s.jsxs("div",{className:"min-w-0 flex flex-col",children:[s.jsx("span",{className:"typography-ui-label text-foreground truncate",children:D?.name?.trim()||D?.login||"GitHub"}),D?.login&&s.jsxs("span",{className:"typography-micro text-muted-foreground truncate",children:[s.jsx("span",{className:"font-mono",children:D.login}),s.jsx("span",{className:"mx-1 opacity-50",children:"·"}),s.jsx("span",{children:$})]})]})]}),s.jsx(H,{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(H,{size:"sm",variant:"outline",onClick:m,disabled:p,className:xe(a?"w-full":void 0),children:e("settings.github.page.actions.addAccount")})}),c&&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:c.userCode}),s.jsx(H,{size:"sm",asChild:!0,children:s.jsx("a",{href:c.verificationUriComplete||c.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(H,{size:"sm",variant:"ghost",disabled:p,onClick:()=>{N(),I(null)},children:e("settings.common.actions.cancel")})]})]})]}),V=C?.available&&!C?.active&&(!C.user||C.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:[C.user?.avatarUrl?s.jsx("img",{src:C.user.avatarUrl,alt:C.user.login?e("settings.github.page.avatarAlt.withLogin",{login:C.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(L,{name:"github-fill",className:"h-4 w-4 text-muted-foreground"})}),s.jsxs("div",{className:"min-w-0 flex-1",children:[!C.disabled&&C.user&&s.jsx("div",{className:"typography-ui-label text-foreground truncate",children:C.user.name?.trim()||C.user.login||"GitHub"}),!C.disabled&&C.user?.login&&s.jsxs("div",{className:xe("flex items-center gap-2 typography-meta text-muted-foreground mt-0.5",a?"flex-wrap":"truncate"),children:[s.jsx(L,{name:"github-fill",className:"h-3.5 w-3.5 shrink-0"}),s.jsx("span",{className:"font-mono",children:C.user.login}),C.user.email&&s.jsx("span",{className:"opacity-50",children:"•"}),C.user.email&&s.jsx("span",{children:C.user.email})]}),s.jsx("div",{className:xe("typography-meta text-muted-foreground",C.disabled?"opacity-60":void 0),children:C.disabled?e("settings.github.page.ghCli.disabledDescription"):e("settings.github.page.ghCli.fallbackDescription")})]})]}),s.jsx(H,{size:"sm",variant:"outline",onClick:()=>R(!C.disabled),disabled:p,className:xe(a?"w-full":void 0),children:C.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,V?s.jsxs("div",{className:"space-y-2",children:[s.jsx(Zs,{children:e("settings.github.page.ghCli.title")}),V]}):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}),V?s.jsx(ze,{title:e("settings.github.page.ghCli.title"),children:V}):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 d;t[0]!==g||t[1]!==r||t[2]!==n||t[3]!==a?.user?.login||t[4]!==e?(d=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]=d):d=t[5];const y=d,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(L,{name:"github-fill",className:"size-5 text-foreground"})}),t[6]=b):b=t[6];let c;t[7]!==e?(c=e("settings.integrations.github.title"),t[7]=e,t[8]=c):c=t[8];let I;t[9]!==c?(I=s.jsx("div",{className:"truncate text-sm font-semibold text-foreground",children:c}),t[9]=c,t[10]=I):I=t[10];let f;t[11]!==e?(f=e("settings.integrations.github.description"),t[11]=e,t[12]=f):f=t[12];let S;t[13]!==f?(S=s.jsx("p",{className:"mt-0.5 line-clamp-1 text-xs leading-snug text-muted-foreground",children:f}),t[13]=f,t[14]=S):S=t[14];let w;t[15]!==I||t[16]!==S?(w=s.jsxs("div",{className:"min-w-0 flex-1",children:[I,S]}),t[15]=I,t[16]=S,t[17]=w):w=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 T=i&&"rotate-180";let R;t[23]!==T?(R=xe("size-4 shrink-0 text-muted-foreground transition-transform duration-150 ease-out motion-reduce:transition-none",T),t[23]=T,t[24]=R):R=t[24];let P;t[25]!==R?(P=s.jsx(L,{name:"arrow-down-s",className:R}),t[25]=R,t[26]=P):P=t[26];let j;t[27]!==P||t[28]!==w||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,w,m,P]}),t[27]=P,t[28]=w,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 v;t[32]!==j?(v=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]=v):v=t[33];let O;return t[34]!==i||t[35]!==v?(O=s.jsx(An,{open:i,onOpenChange:l,children:v}),t[34]=i,t[35]=v,t[36]=O):O=t[36],O};function vh(t){return t.status}function yh(t){return t.isLoading}function bh(t){return t.hasChecked}const mi="__none__",gi="__inherit__";function wh({linear:t,connected:e,organizationId:a}){const{t:n}=tt(),r=Gs(w=>w.projects),[i,l]=o.useState(null),[g,d]=o.useState(!1),[y,p]=o.useState(!1),b=o.useCallback(async()=>{if(!e){l(null),d(!1);return}try{const w=await t.mappingGet();if(w.connected===!1){l(null),d(!1);return}l(w),d(!1)}catch(w){console.error("Failed to load Linear mapping:",w),d(!0)}},[e,t]);o.useEffect(()=>{b()},[b,a]);const c=o.useCallback(async w=>{const N={};for(const m of w.teams??[])m.projectPath&&(N[m.id]=m.projectPath);p(!0),ga("saving");try{const m=await t.mappingSet({defaultProjectPath:w.defaultProjectPath??null,teamProjectPaths:N});if(m.connected===!1){l(null),ga("error");return}l(m),d(!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 I=w=>r.find(m=>m.path===w)?.label?.trim()||w,f=w=>!w||w===mi?n("settings.integrations.linear.mapping.defaultProject.placeholder"):I(w),S=w=>!w||w===gi?n("settings.integrations.linear.mapping.teams.useDefault"):I(w);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:w=>{c({...i,defaultProjectPath:w===mi?null:w})},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(w=>w.path===i.defaultProjectPath)?s.jsx(at,{value:i.defaultProjectPath,children:i.defaultProjectPath}):null,r.map(w=>s.jsx(at,{value:w.path,children:I(w.path)},w.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(w=>s.jsx(Rt,{label:`${w.key} · ${w.name}`,children:s.jsxs(St,{value:w.projectPath||gi,disabled:y||r.length===0,onValueChange:N=>{c({...i,teams:(i.teams??[]).map(m=>m.id===w.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:w.key}),children:s.jsx(Mt,{placeholder:n("settings.integrations.linear.mapping.teams.useDefault"),children:S})}),s.jsxs(It,{children:[s.jsx(at,{value:gi,children:n("settings.integrations.linear.mapping.teams.useDefault")}),w.projectPath&&!r.some(N=>N.path===w.projectPath)?s.jsx(at,{value:w.projectPath,children:w.projectPath}):null,r.map(N=>s.jsx(at,{value:N.path,children:I(N.path)},N.id))]})]})},w.id))})})]})}function jh({linear:t,connected:e}){const{t:a}=tt(),[n,r]=o.useState(null),[i,l]=o.useState(!1),[g,d]=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),d(!0);try{const c=await t.preferencesSet({sessionComments:p});r(c.sessionComments),ga("saved")}catch{r(b),ga("error")}finally{d(!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(C=>C.status),n=oa(C=>C.isLoading),r=oa(C=>C.hasChecked),i=oa(C=>C.refreshStatus),l=oa(C=>C.setStatus),[g,d]=o.useState(!1),[y,p]=o.useState(!1),[b,c]=o.useState(!1),I=o.useRef(null),f=o.useCallback(()=>{I.current!=null&&(window.clearInterval(I.current),I.current=null),p(!1)},[]);o.useEffect(()=>{if(e)return r||i(e),()=>{f()}},[r,i,e,f]);const S=o.useCallback(async()=>{if(!e)return;f(),d(!0);const C=Yo(oa.getState().status);try{const M=await e.authStart(as()?"desktop":"web");p(!0),c(!0),Pn(M.authorizationUrl);const B=Date.now()+kh;I.current=window.setInterval(()=>{(async()=>{if(Date.now()>B){f(),E.error(t("settings.integrations.linear.toast.authorizationFailed"));return}const V=await i(e,{force:!0});Sh(C,Yo(V))&&(f(),E.success(t("settings.integrations.linear.toast.connected")),Ad())})()},Nh)}catch(M){console.error("Failed to start Linear connect:",M),E.error(t("settings.integrations.linear.toast.startConnectFailed")),f()}finally{d(!1)}},[i,e,f,t]),w=o.useCallback(async C=>{if(!(!e||!C)){d(!0);try{const M=await e.authActivate(C);l(M),E.success(t("settings.integrations.linear.toast.workspaceSwitched"))}catch(M){console.error("Failed to switch Linear workspace:",M),E.error(t("settings.integrations.linear.toast.workspaceSwitchFailed"))}finally{d(!1)}}},[e,l,t]),N=o.useCallback(async()=>{if(e){d(!0);try{f(),await e.authDisconnect(),E.success(t("settings.integrations.linear.toast.disconnected")),await i(e,{force:!0})}catch(C){console.error("Failed to disconnect Linear:",C),E.error(t("settings.integrations.linear.toast.disconnectFailed"))}finally{d(!1)}}},[i,e,f,t]);if(!e)return null;const m=!!a?.connected,T=a?.user,R=a?.organization,j=(a?.workspaces??[]).filter(C=>!C.current),h=T?.displayName?.trim()||T?.name?.trim()||t("settings.integrations.linear.label.unknownUser"),v=y?t("settings.integrations.linear.status.waiting"):n&&!r?t("common.loading"):m?R?.name?.trim()||t("settings.integrations.linear.status.connected"):t("settings.integrations.linear.status.notConnected"),O=y?"bg-[var(--status-warning)]/15 text-[var(--status-warning)]":m?"bg-[var(--status-success)]/15 text-[var(--status-success)]":"bg-[var(--surface-muted)] text-muted-foreground",A=y||b;return s.jsx(An,{open:A,onOpenChange:C=>{if(y){c(!0);return}c(C)},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(L,{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",O),children:v}),s.jsx(L,{name:"arrow-down-s",className:xe("size-4 shrink-0 text-muted-foreground transition-transform duration-150 ease-out motion-reduce:transition-none",A&&"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:[T?.avatarUrl?s.jsx("img",{src:T.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(L,{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,T?.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(C=>{const M=C.user,B=C.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:B}),M?.email?s.jsx("p",{className:"truncate text-xs text-muted-foreground",children:M.email}):null]}),s.jsx(H,{type:"button",size:"sm",variant:"ghost",onClick:()=>{w(C.id)},disabled:g,children:t("settings.integrations.linear.actions.switchTo")})]},C.id)})})]}):null,s.jsxs("div",{className:"flex flex-wrap items-center gap-2",children:[s.jsx(H,{type:"button",size:"sm",variant:"outline",onClick:()=>{S()},disabled:g||y,"data-settings-item":"integrations.linear.add-workspace",children:t("settings.integrations.linear.actions.addWorkspace")}),s.jsx(H,{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(H,{type:"button",size:"sm",variant:"ghost",disabled:g,onClick:f,children:t("settings.common.actions.cancel")})]}):s.jsxs(H,{type:"button",size:"sm",variant:"default",onClick:()=>{S()},disabled:g||n&&!r,children:[g?s.jsx(L,{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 d;t[7]!==e?(d=e("settings.integrations.firstParty.info"),t[7]=e,t[8]=d):d=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]!==d?(b=s.jsxs(ze,{title:g,info:d,divider:!1,settingsItem:"integrations.first-party",contentClassName:"space-y-3",children:[y,p]}),t[11]=g,t[12]=d,t[13]=b):b=t[13];let c;return t[14]!==i||t[15]!==l||t[16]!==b?(c=s.jsx(es,{title:i,description:l,showSaveStatus:!0,children:b}),t[14]=i,t[15]=l,t[16]=b,t[17]=c):c=t[17],c},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:d}=Nl(),{browserTab:y}=qd(),p=Td(),b=ie(u=>u.showReasoningTraces),c=ie(u=>u.sessionRecapEnabled),I=ie(u=>u.sessionSuggestionEnabled),f=ie(u=>u.setSessionRecapEnabled),S=ie(u=>u.setSessionSuggestionEnabled),w=ie(u=>u.sessionGoalEnabled),N=ie(u=>u.setSessionGoalEnabled),m=ie(u=>u.sessionGoalDefaultBudgetEnabled),T=ie(u=>u.setSessionGoalDefaultBudgetEnabled),R=ie(u=>u.sessionGoalDefaultBudget),P=ie(u=>u.setSessionGoalDefaultBudget),j=ie(u=>u.setShowReasoningTraces),h=ie(u=>u.streamingAutoFollowEnabled),v=ie(u=>u.setStreamingAutoFollowEnabled),O=ie(u=>u.collapsibleThinkingBlocks),A=ie(u=>u.setCollapsibleThinkingBlocks),C=ie(u=>u.mermaidRenderingMode),M=ie(u=>u.setMermaidRenderingMode),B=ie(u=>u.userMessageRenderingMode),V=ie(u=>u.setUserMessageRenderingMode),k=ie(u=>u.collapsibleUserMessages),D=ie(u=>u.setCollapsibleUserMessages),$=ie(u=>u.stickyUserHeader),K=ie(u=>u.promptNavigatorEnabled),Q=ie(u=>u.setStickyUserHeader),te=ie(u=>u.setPromptNavigatorEnabled),U=ie(u=>u.autoSaveEnabled),le=ie(u=>u.setAutoSaveEnabled),_=ie(u=>u.wideChatLayoutEnabled),G=ie(u=>u.setWideChatLayoutEnabled),z=ie(u=>u.codeBlockLineWrap),F=ie(u=>u.setCodeBlockLineWrap),ee=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),J=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),Zt=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=>{V(u),gt({userMessageRenderingMode:u})},[V]),Ws=o.useCallback(u=>{Q(u),gt({stickyUserHeader:u})},[Q]),Zn=o.useCallback(u=>{te(u),gt({promptNavigatorEnabled:u})},[te]),mn=o.useCallback(u=>{Wt(u),gt({draftStartersVisible:u})},[Wt]),xn=o.useCallback(u=>{D(u),gt({collapsibleUserMessages:u})},[D]),Or=o.useCallback(u=>{G(u),gt({wideChatLayoutEnabled:u})},[G]),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=>{M(u),gt({mermaidRenderingMode:u})},[M]),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||!d.listShells))return d.listShells().then(mt=>{u||us(mt)}).catch(()=>{u||us([])}),()=>{u=!0}},[Dt,d,$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(L,{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(H,{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(L,{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(H,{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(L,{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(H,{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(L,{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(H,{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(L,{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(H,{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(L,{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(H,{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(L,{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(H,{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(L,{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(H,{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(L,{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(H,{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(L,{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(H,{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(L,{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=ee===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(B)===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:C===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:J,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:c,onChange:f,label:i("settings.aiworker.visual.field.sessionRecap"),ariaLabel:i("settings.aiworker.visual.field.sessionRecapAria"),settingsItem:"chat.session-recap"}),s.jsx(dt,{checked:I,onChange:S,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:Zt,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:w,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:T,disabled:!w,label:i("settings.aiworker.visual.goal.budgetLabel"),ariaLabel:i("settings.aiworker.visual.goal.budgetAria")}),w&&m?s.jsx(xs,{value:R,onValueChange:u=>{typeof u=="number"&&Number.isFinite(u)&&u>0&&P(Math.floor(u))},min:1e3,max:1e8,step:5e4}):null]})]}),ce("reasoning")&&s.jsxs(ze,{title:i("settings.aiworker.visual.section.reasoning"),settingsItem:"chat.reasoning",contentClassName:fs,children:[s.jsx(dt,{checked:b,onChange:j,label:i("settings.aiworker.visual.field.showReasoningTraces"),ariaLabel:i("settings.aiworker.visual.field.showReasoningTracesAria"),settingsItem:"chat.reasoning-traces"}),b&&s.jsx(dt,{checked:O,onChange:A,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:v,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:$,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:K,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:F,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),d=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:c,action:I,status:f}=Jc(y),S=p.length;let w;t[1]!==c||t[2]!==e?(w=async()=>{const ye=await c({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]=c,t[2]=e,t[3]=w):w=t[3];const N=w;let m;t[4]!==e?(m=e("settings.aiworker.sessionRetention.title"),t[4]=e,t[5]=m):m=t[5];const T=r?"settings.aiworker.sessionRetention.archivedTooltip":"settings.aiworker.sessionRetention.tooltip";let R;t[6]!==e||t[7]!==T?(R=e(T),t[6]=e,t[7]=T,t[8]=R):R=t[8];let P;t[9]!==e?(P=e("settings.aiworker.sessionRetention.field.enableAutoCleanup"),t[9]=e,t[10]=P):P=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]!==P||t[16]!==j?(h=s.jsx(dt,{settingsItem:"sessions.auto-cleanup",checked:a,onChange:i,label:P,ariaLabel:j}),t[13]=a,t[14]=i,t[15]=P,t[16]=j,t[17]=h):h=t[17];let v;t[18]!==e?(v=e("settings.aiworker.sessionRetention.field.onlyArchived"),t[18]=e,t[19]=v):v=t[19];let O;t[20]!==e?(O=e("settings.aiworker.sessionRetention.field.onlyArchived"),t[20]=e,t[21]=O):O=t[21];let A;t[22]!==e?(A=e("settings.aiworker.sessionRetention.field.onlyArchivedDescription"),t[22]=e,t[23]=A):A=t[23];let C;t[24]!==b||t[25]!==r||t[26]!==d||t[27]!==A||t[28]!==v||t[29]!==O?(C=s.jsx(dt,{settingsItem:"sessions.retention-only-archived",checked:r,onChange:d,disabled:b,label:v,ariaLabel:O,info:A}),t[24]=b,t[25]=r,t[26]=d,t[27]=A,t[28]=v,t[29]=O,t[30]=C):C=t[30];let M;t[31]!==e?(M=e("settings.aiworker.sessionRetention.field.retentionPeriod"),t[31]=e,t[32]=M):M=t[32];let B;t[33]!==e?(B=e("settings.aiworker.sessionRetention.field.retentionPeriodAria"),t[33]=e,t[34]=B):B=t[34];let V;t[35]===Symbol.for("react.memo_cache_sentinel")?(V=xe(Ps,"tabular-nums"),t[35]=V):V=t[35];let k;t[36]!==n||t[37]!==l||t[38]!==B?(k=s.jsx(xs,{value:n,onValueChange:l,min:Uh,max:_h,step:1,"aria-label":B,className:V}),t[36]=n,t[37]=l,t[38]=B,t[39]=k):k=t[39];let D;t[40]!==e?(D=e("settings.aiworker.sessionRetention.field.days"),t[40]=e,t[41]=D):D=t[41];let $;t[42]!==D?($=s.jsx("span",{className:"typography-ui-label text-muted-foreground",children:D}),t[42]=D,t[43]=$):$=t[43];let K;t[44]!==l?(K=()=>l(nl),t[44]=l,t[45]=K):K=t[45];const Q=n===nl;let te;t[46]!==e?(te=e("settings.aiworker.sessionRetention.actions.resetRetentionAria"),t[46]=e,t[47]=te):te=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(L,{name:"restart",className:"h-3.5 w-3.5"}),t[50]=le):le=t[50];let _;t[51]!==K||t[52]!==Q||t[53]!==te||t[54]!==U?(_=s.jsx(H,{size:"sm",type:"button",variant:"ghost",onClick:K,disabled:Q,className:Cs,"aria-label":te,title:U,children:le}),t[51]=K,t[52]=Q,t[53]=te,t[54]=U,t[55]=_):_=t[55];let G;t[56]!==M||t[57]!==k||t[58]!==$||t[59]!==_?(G=s.jsxs(Rt,{settingsItem:"sessions.retention-period",label:M,children:[k,$,_]}),t[56]=M,t[57]=k,t[58]=$,t[59]=_,t[60]=G):G=t[60];let z;t[61]!==e?(z=e("settings.aiworker.sessionRetention.field.whenSessionsExpire"),t[61]=e,t[62]=z):z=t[62];let F;t[63]!==r||t[64]!==e?(F=$h.map(ye=>({value:ye.value,label:e(ye.labelKey),disabled:r&&ye.value==="archive"})),t[63]=r,t[64]=e,t[65]=F):F=t[65];let ee;t[66]!==I||t[67]!==g||t[68]!==F?(ee=s.jsx(Ys,{value:I,onChange:g,options:F}),t[66]=I,t[67]=g,t[68]=F,t[69]=ee):ee=t[69];let Y;t[70]!==z||t[71]!==ee?(Y=s.jsx(Rt,{settingsItem:"sessions.retention-action",label:z,children:ee}),t[70]=z,t[71]=ee,t[72]=Y):Y=t[72];let ae;t[73]!==C||t[74]!==G||t[75]!==Y?(ae=s.jsxs(ba,{className:"space-y-0",children:[C,G,Y]}),t[73]=C,t[74]=G,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(H,{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]!==I||t[90]!==S||t[91]!==f||t[92]!==e?(re=f==="error"?e("sessions.sidebar.group.empty.loadFailed"):f!=="ready"?e("sessions.sidebar.group.empty.loadingSessions"):I==="archive"?e("settings.aiworker.sessionRetention.manualCleanup.eligibleArchiveNow",{count:S}):e("settings.aiworker.sessionRetention.manualCleanup.eligibleDeleteNow",{count:S}),t[89]=I,t[90]=S,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),[d,y]=o.useState(null),[p,b]=o.useState(!1),[c,I]=o.useState([]),[f,S]=o.useState(Qc),[w,N]=o.useState(""),m=o.useMemo(()=>Yc(),[]),T=o.useCallback(async()=>{i(!0),N("");try{const h=await Zc();I(h)}catch(h){const v=h instanceof Error?h.message:t("settings.aiworker.passkeys.toast.loadFailed");N(v)}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 v=await Gi();if(S(v),!v.enabled){I([]),i(!1);return}await T()}})(),()=>{h=!0,Vr()}},[T,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(),S(await Gi()),await T(),E.success(t("settings.aiworker.passkeys.toast.added"))}catch(h){if(ed(h)){E.message(t("settings.aiworker.passkeys.toast.setupCanceled"));return}const v=h instanceof Error?h.message:t("settings.aiworker.passkeys.toast.addFailed");N(v),E.error(v)}finally{g(!1)}},[l,T,f.enabled,m.reason,a,t]),P=o.useCallback(async h=>{y(h),N("");try{await td(h),S(await Gi()),await T(),E.success(t("settings.aiworker.passkeys.toast.removed"))}catch(v){const O=v instanceof Error?v.message:t("settings.aiworker.passkeys.toast.removeFailed");N(O),E.error(O)}finally{y(null)}},[T,t]),j=o.useCallback(async()=>{b(!0),N("");try{await sd(),window.location.reload()}catch(h){const v=h instanceof Error?h.message:t("settings.aiworker.passkeys.toast.clearAuthFailed");N(v),E.error(v),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(H,{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(H,{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")}):c.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:c.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(H,{type:"button",variant:"ghost",size:"xs",onClick:()=>{P(h.id)},disabled:d===h.id,className:"!font-normal text-muted-foreground hover:text-foreground",children:d===h.id?t("settings.aiworker.passkeys.actions.removing"):t("settings.common.actions.delete")})]},h.id))})]}),w&&s.jsx("div",{className:"mt-1 py-1.5",children:s.jsx("p",{className:"typography-meta text-[var(--status-error)]",children:w})})]})},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(H,{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 d;return t[10]!==r||t[11]!==i||t[12]!==g?(d=s.jsx(ze,{title:r,description:i,children:g}),t[10]=r,t[11]=i,t[12]=g,t[13]=d):d=t[13],d};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),d=Ye(se=>se.setSettingsDefaultAgent),y=Ye(se=>se.selectionSource==="manual"),p=nd(se=>se.currentSessionId),b=Hr(se=>se.getSessionModelSelection),c=Hr(se=>se.getSessionAgentSelection),I=!!(y&&p&&b(p)),f=!!(y&&p&&c(p)),S=ie(se=>se.showDeletionDialog),w=ie(se=>se.setShowDeletionDialog),N=Ye(se=>se.providers),m=Ye(se=>se.modelsMetadata),[T,R]=o.useState(),[P,j]=o.useState(),[h,v]=o.useState(),[O,A]=o.useState(!0),[C,M]=o.useState(),[B,V]=o.useState([]),[k,D]=o.useState(),[$,K]=o.useState(!0),Q=o.useMemo(()=>ar(T),[T]);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&&v(Se),re.smallModelUseDefault!==void 0&&A(re.smallModelUseDefault);const ye=re.smallModelOverride?.trim();ye&&M(ye);const fe=re.walkthroughModelOverride?.trim();fe&&D(fe)}}catch(re){console.warn("Failed to load defaults settings:",re)}finally{K(!1)}})()},[]);const te=o.useCallback(async(se,re)=>{const ue=se&&re?`${se}/${re}`:void 0;R(ue),j(void 0),g(void 0),l(ue),I||(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)}},[I,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),I||i(re??null,re);try{await gt({defaultVariant:re??""})}catch(ue){console.warn("Failed to save default variant:",ue)}},[I,i,g]),G=o.useCallback(async se=>{const re=se||void 0;v(re),d(re),se&&!f&&n(se);try{await gt({defaultAgent:re??""})}catch(ue){console.warn("Failed to save default agent:",ue)}},[f,n,d]),z=o.useCallback(async se=>{A(se);try{await gt({smallModelUseDefault:se})}catch(re){console.warn("Failed to save small model preference:",re)}},[]),F=o.useCallback(async(se,re)=>{const ue=se&&re?`${se}/${re}`:void 0;M(ue);try{await gt({smallModelOverride:ue??""})}catch(Ce){console.warn("Failed to save small model override:",Ce)}},[]),ee=o.useCallback(async(se,re)=>{const ue=se&&re?`${se}/${re}`:void 0;D(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(C),[C]),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)&&V(ue.authenticatedProviders.filter(Ce=>typeof Ce=="string"))}catch{}})(),()=>{se=!0}},[]);const de=o.useMemo(()=>{if(!Q.providerId||!Q.modelId)return[];const ue=N.find(Ce=>Ce.id===Q.providerId)?.models.find(Ce=>Ce.id===Q.modelId)?.variants;return ue?Object.keys(ue):[]},[Q.modelId,Q.providerId,N]),he=de.length>0;return $?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")," ",Q.providerId?s.jsxs("span",{className:"text-foreground",children:[Q.providerId,"/",Q.modelId,he?` (${P??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:Q.providerId,modelId:Q.modelId,onChange:te,className:In})}),s.jsx(Rt,{settingsItem:"sessions.default-thinking",label:t("settings.aiworker.defaults.field.defaultThinking"),children:s.jsxs(St,{value:P??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(P??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:G,filter:se=>ad(se.mode),className:In})})]}),s.jsx(ba,{className:fs,children:s.jsx(dt,{settingsItem:"sessions.deletion-dialog",checked:S,onChange:w,label:t("settings.aiworker.defaults.field.showDeletionDialog"),ariaLabel:t("settings.aiworker.defaults.field.showDeletionDialogAria")})}),s.jsxs("div",{className:"space-y-3 pt-6",children:[s.jsxs("div",{className:"flex items-center gap-1.5",children:[s.jsx(Zs,{children:t("settings.aiworker.defaults.smallModel.title")}),s.jsx(Jt,{children:t("settings.aiworker.defaults.smallModel.description")})]}),s.jsx(dt,{settingsItem:"sessions.small-model",checked:O,onChange:se=>{z(se)},label:t("settings.aiworker.defaults.smallModel.useDefault"),ariaLabel:t("settings.aiworker.defaults.smallModel.useDefaultAria")}),O?null:s.jsx(Rt,{label:t("settings.aiworker.defaults.smallModel.overrideModel"),children:s.jsx(Fa,{providerId:ae.providerId,modelId:ae.modelId,onChange:F,allowedProviderIds:B,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:ee,allowedProviderIds:B,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),d=ie(_=>_.setNotificationMode),y=ie(_=>_.notifyOnSubtasks),p=ie(_=>_.setNotifyOnSubtasks),b=ie(_=>_.notifyOnCompletion),c=ie(_=>_.setNotifyOnCompletion),I=ie(_=>_.notifyOnError),f=ie(_=>_.setNotifyOnError),S=ie(_=>_.notifyOnQuestion),w=ie(_=>_.setNotifyOnQuestion),N=ie(_=>_.notificationTemplates),m=ie(_=>_.setNotificationTemplates),[T,R]=o.useState("default"),[P,j]=o.useState(!1),[h,v]=o.useState(!1),[O,A]=o.useState(!1);o.useEffect(()=>{if(!r){j(!1),v(!1);return}typeof Notification<"u"&&R(Notification.permission);const _=typeof window<"u"&&"serviceWorker"in navigator&&"PushManager"in window&&"Notification"in window;j(_),(async()=>{if(!_){v(!1);return}try{const z=await navigator.serviceWorker.getRegistration();if(!z){v(!1);return}const F=await z.pushManager.getSubscription();v(!!F)}catch{v(!1)}})()},[r]);const C=async _=>{if(e){l(_);return}if(!r){l(_);return}if(_&&typeof Notification<"u"&&Notification.permission==="default")try{const G=await Notification.requestPermission();R(G),G==="granted"?l(!0):E.error(t("settings.notifications.page.toast.permissionDenied.title"),{description:t("settings.notifications.page.toast.permissionDenied.description")})}catch(G){console.error("Failed to request notification permission:",G),E.error(t("settings.notifications.page.toast.requestPermissionFailed"))}else l(!!(_&&T==="granted"))},M=e||a||n||r&&typeof Notification<"u"&&Notification.permission==="granted",B=(_,G,z)=>{m(F=>({...F,[_]:{...F[_],[G]:z}}))},V=_=>{const G="=".repeat((4-_.length%4)%4),z=(_+G).replace(/-/g,"+").replace(/_/g,"/"),F=atob(z),ee=new Uint8Array(F.length);for(let Y=0;Y<F.length;Y+=1)ee[Y]=F.charCodeAt(Y);return ee},k=async(_,G,z)=>{let F=null;const ee=new Promise((Y,ae)=>{F=setTimeout(()=>{ae(new Error(z))},G)});try{return await Promise.race([_,ee])}finally{F&&clearTimeout(F)}},D=async _=>{if(_.active)return;const G=_.installing||_.waiting;G&&G.state!=="activated"&&await k(new Promise(z=>{const F=()=>{G.state==="activated"&&(G.removeEventListener("statechange",F),z())};G.addEventListener("statechange",F),F()}),15e3,"Service worker activation timed out")},$=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 G=null;for(const z of _)try{const F=z.opts?navigator.serviceWorker.register("/sw.js",z.opts):navigator.serviceWorker.register("/sw.js");return await k(F,1e4,`Service worker registration timed out (${z.label})`)}catch(F){G=F}throw G instanceof Error?G:new Error("Service worker registration failed")},K=async()=>{if(!("serviceWorker"in navigator))throw new Error("Service worker not supported");const _=await navigator.serviceWorker.getRegistration();if(_)return _;const G=await $();try{await G.update()}catch{}return await D(G),G},Q=_=>{const G=_,z=[`type=${typeof _}`,`toString=${String(_)}`,`name=${String(G?.name??"")}`,`message=${String(G?.message??"")}`];let F="";try{F=JSON.stringify(_)}catch{}return{summary:z.filter(Boolean).join(" | "),json:F,stack:typeof G?.stack=="string"?G.stack:""}},te=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(G){console.error("Test notification failed:",G),E.error(t("settings.notifications.page.toast.testNotificationFailed"))}},U=async()=>{if(!P){E.error(t("settings.notifications.page.toast.pushUnsupported"));return}const _=fa();if(!_?.push){E.error(t("settings.notifications.page.toast.pushApiUnavailable"));return}A(!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 G=await _.push.getVapidPublicKey();if(!G?.publicKey){E.error(t("settings.notifications.page.toast.pushKeyLoadFailed"));return}const z=await K();await D(z);const F=await z.pushManager.getSubscription();if(!("pushManager"in z)||!z.pushManager)throw new Error("PushManager unavailable (requires installed PWA + iOS 16.4+)");const Y=(F??await k(z.pushManager.subscribe({userVisibleOnly:!0,applicationServerKey:V(G.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}v(!0),E.success(t("settings.notifications.page.toast.backgroundEnabled"))}catch(G){console.error("[Push] Enable failed:",G);const z=Q(G);E.error(t("settings.notifications.page.toast.enableBackgroundFailed"),{description:z.summary})}finally{A(!1)}},le=async()=>{if(!P){v(!1);return}const _=fa();if(!_?.push){E.error(t("settings.notifications.page.toast.pushApiUnavailable"));return}A(!0);try{const z=await(await K()).pushManager.getSubscription();if(!z){v(!1);return}const F=z.endpoint;await z.unsubscribe(),await _.push.unsubscribe({endpoint:F}),v(!1),E.success(t("settings.notifications.page.toast.backgroundDisabled"))}finally{A(!1)}};return s.jsxs(s.Fragment,{children:[s.jsxs(ze,{settingsItem:"notifications.delivery",title:t("settings.notifications.page.delivery.title"),divider:!1,children:[s.jsxs("div",{className:fs,children:[s.jsx(dt,{checked:i&&M,onChange:_=>{C(_)},label:t("settings.notifications.page.delivery.enableLabel"),info:r?t("settings.notifications.page.delivery.browserPermissionHint"):a?t("settings.notifications.page.delivery.vscodeHint"):void 0,ariaLabel:t("settings.notifications.page.delivery.enableAria")}),i&&M&&!n&&s.jsxs(s.Fragment,{children:[s.jsx(dt,{checked:g==="always",onChange:_=>d(_?"always":"hidden-only"),label:t("settings.notifications.page.delivery.focusedLabel"),ariaLabel:t("settings.notifications.page.delivery.focusedAria")}),s.jsx("div",{className:"py-2",children:s.jsx(H,{type:"button",variant:"outline",size:"sm",onClick:()=>{te()},children:t("settings.notifications.page.delivery.testAction")})})]})]}),r&&s.jsxs("div",{className:"mt-1",children:[T==="denied"&&s.jsx("p",{className:"typography-meta text-[var(--status-error)] mt-1",children:t("settings.notifications.page.delivery.permissionDenied")}),T==="granted"&&!i&&s.jsx("p",{className:"typography-meta text-muted-foreground/70 mt-1",children:t("settings.notifications.page.delivery.permissionGrantedButDisabled")})]})]}),i&&M&&s.jsxs(s.Fragment,{children:[s.jsx(ze,{settingsItem:"notifications.events",title:t("settings.notifications.page.events.title"),children:s.jsxs("div",{className:fs,children:[s.jsx(dt,{checked:b,onChange:c,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:I,onChange:f,label:t("settings.notifications.page.events.errorLabel"),ariaLabel:t("settings.notifications.page.events.errorAria")}),s.jsx(dt,{checked:S,onChange:w,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:G=>B(_,"title",G.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:G=>B(_,"message",G.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:P?h:!1,disabled:!P||O,onChange:_=>{_?U():le()},label:t("settings.notifications.page.push.enableLabel"),description:P?void 0:t("settings.notifications.page.push.unsupportedHint"),info:P?t("settings.notifications.page.push.supportedHint"):void 0,ariaLabel:t("settings.notifications.page.push.enableAria"),labelAccessory:O?s.jsx("span",{className:"inline-block h-1.5 w-1.5 rounded-full bg-current text-muted-foreground animate-busy-pulse","aria-label":t("settings.notifications.page.push.loadingAria")}):null})})]})},Ls=t=>{if(!t)return;t.pause();const{src:e}=t;e.startsWith("blob:")&&URL.revokeObjectURL(e),t.removeAttribute("src"),t.load()},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 d;return e[4]!==r||e[5]!==l||e[6]!==g?(d=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]=d):d=e[7],d},tf=({selectedModelId:t,onSelect:e})=>{const{t:a}=tt(),n=$e.useCallback(c=>a(c),[a]),[r,i]=$e.useState(new Map),[l,g]=$e.useState(null),d=$e.useCallback(async()=>{try{const c=await yt("/api/dictation/status",{query:{provider:"local"}});if(!c.ok)return;const I=await c.json();Array.isArray(I?.models)&&i(new Map(I.models.map(f=>[f.id,f])))}catch{}},[]);$e.useEffect(()=>{d()},[d]);const y=Array.from(r.values()).some(c=>c.downloading);$e.useEffect(()=>{if(!y)return;const c=setInterval(()=>{d()},2e3);return()=>clearInterval(c)},[y,d]);const p=async c=>{g(c);try{await yt(`/api/dictation/models/${encodeURIComponent(c)}/download`,{method:"POST"}),await d()}catch{}finally{g(null)}},b=async c=>{g(c);try{await yt(`/api/dictation/models/${encodeURIComponent(c)}`,{method:"DELETE"}),await d()}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(c=>{const I=t===c.id,f=r.get(c.id)??null;return s.jsx("div",{className:xe("rounded-lg border border-[var(--interactive-border)] p-3",I&&"border-[var(--primary-base)] bg-[var(--primary-base)]/5"),children:s.jsxs("div",{className:"flex items-start justify-between gap-2",children:[s.jsxs("div",{className:"flex min-w-0 flex-1 cursor-pointer items-start gap-2",role:"button",tabIndex:0,onClick:()=>e(c.id),onKeyDown:S=>{(S.key===" "||S.key==="Enter")&&(S.preventDefault(),e(c.id))},children:[s.jsx("div",{className:"pt-0.5",children:s.jsx(jr,{checked:I,onChange:()=>e(c.id),ariaLabel:n(c.labelKey)})}),s.jsxs("div",{className:"min-w-0 flex-1 space-y-2",children:[s.jsxs("div",{className:"flex flex-wrap items-center gap-2",children:[s.jsx("span",{className:xe("typography-ui-label font-normal",I?"text-foreground":"text-foreground/50"),children:n(c.labelKey)}),c.badgeKey?s.jsx("span",{className:"rounded border border-[var(--status-success-border)] bg-[var(--status-success-background)] px-1 text-[9px] font-medium uppercase leading-[14px] tracking-wide text-[var(--status-success)]",children:n(c.badgeKey)}):null]}),s.jsxs("div",{className:"flex flex-col gap-1.5",children:[s.jsx(rl,{value:c.accuracy,label:a("settings.voice.page.stt.meta.accuracy")}),s.jsx(rl,{value:c.speed,label:a("settings.voice.page.stt.meta.speed")}),s.jsx("span",{className:"typography-ui-compact tabular-nums text-muted-foreground",children:c.size})]}),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(H,{variant:"ghost",size:"xs",className:"h-6 w-6 p-0 text-muted-foreground hover:text-[var(--status-error)]",disabled:l===c.id,onClick:()=>{b(c.id)},title:a("settings.voice.page.stt.modelDelete"),"aria-label":a("settings.voice.page.stt.modelDelete"),children:s.jsx(L,{name:"delete-bin",className:"h-4 w-4"})}),s.jsx(L,{name:"checkbox-circle",className:"h-4 w-4 flex-shrink-0 text-[var(--status-success)]","aria-label":a("settings.voice.page.stt.modelInstalled")})]}):f?.downloading?s.jsxs("span",{className:"flex items-center gap-1.5",children:[s.jsx(L,{name:"loader-4",className:"h-3.5 w-3.5 animate-spin text-muted-foreground"}),s.jsx("span",{className:"typography-ui-compact tabular-nums text-muted-foreground",children:typeof f.downloadProgress=="number"?`${f.downloadProgress}%`:""})]}):s.jsx(H,{variant:"ghost",size:"xs",className:"h-6 w-6 p-0",disabled:l===c.id,onClick:()=>{p(c.id)},title:a("settings.voice.page.stt.modelDownload"),"aria-label":a("settings.voice.page.stt.modelDownload"),children:s.jsx(L,{name:"download",className:"h-4 w-4"})})})]})},c.id)})})},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 d=await g.json();Array.isArray(d?.ttsModels)&&e(d.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,d)=>{n(g);try{const y=d==="POST"?`/api/dictation/models/${g}/download`:`/api/dictation/models/${g}`;await yt(y,{method:d}),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,d;if(e[0]!==a||e[1]!==r||e[2]!==n||e[3]!==i){d=Symbol.for("react.early_return_sentinel");e:{const p=a.filter(uf);if(p.length===0){d=null;break e}l="flex flex-col";let b;e[7]!==r||e[8]!==n||e[9]!==i?(b=c=>s.jsxs("div",{className:"flex items-center gap-2 py-1.5",children:[s.jsx("span",{className:"typography-ui-label text-foreground",children:c.description??c.id}),c.installed?s.jsxs(s.Fragment,{children:[s.jsx(L,{name:"checkbox-circle",className:"h-4 w-4 text-[var(--status-success)]","aria-label":i("settings.voice.page.stt.modelInstalled")}),s.jsx(H,{variant:"ghost",size:"xs",className:"h-6 w-6 p-0 text-muted-foreground hover:text-[var(--status-error)]",disabled:n!==null,onClick:()=>{r(c.id,"DELETE")},title:i("settings.voice.page.stt.modelDelete"),"aria-label":i("settings.voice.page.stt.modelDelete"),children:s.jsx(L,{name:"delete-bin",className:"h-4 w-4"})})]}):c.downloading?s.jsxs("span",{className:"flex items-center gap-1.5",children:[s.jsx(L,{name:"loader-4",className:"h-3.5 w-3.5 animate-spin text-muted-foreground"}),s.jsx("span",{className:"typography-ui-compact tabular-nums text-muted-foreground",children:typeof c.downloadProgress=="number"?`${c.downloadProgress}%`:""})]}):s.jsx(H,{variant:"ghost",size:"xs",className:"h-6 w-6 p-0",disabled:n!==null,onClick:()=>{r(c.id,"POST")},title:i("settings.voice.page.stt.modelDownload"),"aria-label":i("settings.voice.page.stt.modelDownload"),children:s.jsx(L,{name:"download",className:"h-4 w-4"})}),c.downloadError?s.jsx("span",{className:"typography-meta text-[var(--status-error)]",children:c.downloadError}):null]},c.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]=d}else l=e[4],g=e[5],d=e[6];if(d!==Symbol.for("react.early_return_sentinel"))return d;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),d=Ye(W=>W.speechVolume),y=Ye(W=>W.setSpeechVolume),p=Ye(W=>W.sayVoice),b=Ye(W=>W.setSayVoice),c=Ye(W=>W.localTtsVoiceId),I=Ye(W=>W.localTtsModelId),f=Ye(W=>W.setLocalTtsModelId),S=rf(),w=$e.useMemo(()=>of(S.models),[S.models]),N=Ye(W=>W.ttsFollowTextLanguage),m=Ye(W=>W.setTtsFollowTextLanguage),T=Ye(W=>W.setLocalTtsVoiceId),{speak:R,stop:P,isPlaying:j,error:h}=id(),v=$e.useCallback(()=>{if(j){P();return}const W=w.find(We=>We.modelId===I&&We.speakerId===c)?.label??String(c);R(t("settings.voice.page.preview.voiceLine",{voiceName:W}),{model:I,speakerId:c,speed:Ye.getState().speechRate})},[j,I,c,w,R,P,t]),O=Ye(W=>W.browserVoice),A=Ye(W=>W.setBrowserVoice),C=Ye(W=>W.openaiVoice),M=Ye(W=>W.setOpenaiVoice),B=Ye(W=>W.openaiApiKey),V=Ye(W=>W.setOpenaiApiKey),k=Ye(W=>W.openaiCompatibleUrl),D=Ye(W=>W.setOpenaiCompatibleUrl),$=Ye(W=>W.openaiCompatibleApiKey),K=Ye(W=>W.setOpenaiCompatibleApiKey),Q=Ye(W=>W.openaiCompatibleVoice),te=Ye(W=>W.setOpenaiCompatibleVoice),U=Ye(W=>W.openaiCompatibleTtsModel),le=Ye(W=>W.setOpenaiCompatibleTtsModel),_=Ye(W=>W.showMessageTTSButtons),G=Ye(W=>W.ttsInputMode),z=Ye(W=>W.setTtsInputMode),F=Ye(W=>W.sttProvider),ee=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&&lt)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===O),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=d,W&&(lt.voice=W,lt.lang=W.lang),lt.onend=()=>ke(!1),lt.onerror=()=>ke(!1),window.speechSynthesis.cancel(),window.speechSynthesis.speak(lt)},[O,Le,r,l,d,q,t]);$e.useEffect(()=>()=>{q&&Wi.cancelSpeech()},[q]),$e.useEffect(()=>{if(!_||a!=="openai"&&a!=="openai-compatible"){we(B.trim().length>0);return}(async()=>{try{const lt=(await(await yt("/api/tts/status")).json()).available,ht=B.trim().length>0;we(lt||ht)}catch{we(B.trim().length>0)}})()},[B,_,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:C}),voice:C,speed:r,apiKey:B||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)}},[C,r,Ke,B,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:Q,model:U||void 0,speed:r,baseURL:k,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),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,Q,U,$,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(L,{name:"apple",className:"mr-0.5 h-3.5 w-3.5"}),t("settings.voice.page.provider.say")]})}]:[]]})}),a==="openai"&&s.jsxs("div",{className:"space-y-1.5",children:[s.jsx("span",{className: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&&!B?"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:B,onChange:W=>V(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"}),B&&s.jsx("button",{type:"button",onClick:()=>V(""),className:"absolute right-2 top-1/2 -translate-y-1/2 text-muted-foreground hover:text-foreground",children:s.jsx(L,{name:"close",className:"w-3.5 h-3.5"})})]})]}),a==="openai-compatible"&&s.jsxs("div",{className:"space-y-3",children:[s.jsxs("div",{className:"space-y-1.5",children:[s.jsxs("span",{className:"flex items-center gap-1.5",children:[s.jsx("span",{className: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=>D(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:()=>D(""),className:"absolute right-2 top-1/2 -translate-y-1/2 text-muted-foreground hover:text-foreground",children:s.jsx(L,{name:"close",className:"w-3.5 h-3.5"})})]})]}),s.jsxs("div",{className:"space-y-1.5",children:[s.jsx("span",{className: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:$,onChange:W=>K(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:()=>K(""),className:"absolute right-2 top-1/2 -translate-y-1/2 text-muted-foreground hover:text-foreground",children:s.jsx(L,{name:"close",className:"w-3.5 h-3.5"})})]})]}),s.jsxs("div",{className:"space-y-1.5",children:[s.jsx("span",{className: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:Q,onChange:W=>te(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(H,{size:"xs",variant:"ghost",onClick:pt,title:t("settings.voice.page.actions.preview"),disabled:!k.trim(),children:je?s.jsx(L,{name:"stop",className:"w-3.5 h-3.5"}):s.jsx(L,{name:"play",className:"w-3.5 h-3.5"})})]})]})]}),a==="local"&&s.jsx(lf,{...S}),(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(I,c),onValueChange:W=>{const We=w.find(nt=>Ma(nt.modelId,nt.speakerId)===W);We&&(f(We.modelId),T(We.speakerId))},children:[s.jsx(Ct,{size:Ft,className:rn,children:s.jsx(Mt,{placeholder:t("settings.voice.page.field.selectVoicePlaceholder"),children:W=>w.find(We=>Ma(We.modelId,We.speakerId)===W)?.label??W})}),s.jsx(It,{children:w.map(W=>s.jsx(at,{value:Ma(W.modelId,W.speakerId),children:W.label},Ma(W.modelId,W.speakerId)))})]}),s.jsx(H,{size:"xs",variant:"ghost",onClick:v,title:t("settings.voice.page.actions.preview"),children:j?s.jsx(L,{name:"stop",className:"w-3.5 h-3.5"}):s.jsx(L,{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:C,onValueChange:M,children:[s.jsx(Ct,{size:Ft,className:rn,children:s.jsx(Mt,{placeholder:t("settings.voice.page.field.selectVoicePlaceholder")})}),s.jsx(It,{children:cf.map(W=>s.jsx(at,{value:W.value,children:W.label},W.value))})]}),s.jsx(H,{size:"xs",variant:"ghost",onClick:st,title:t("settings.voice.page.actions.preview"),children:Re?s.jsx(L,{name:"stop",className:"w-3.5 h-3.5"}):s.jsx(L,{name:"play",className:"w-3.5 h-3.5"})})]}),a==="openai-compatible"&&s.jsx("span",{className: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(H,{size:"xs",variant:"ghost",onClick:ot,title:t("settings.voice.page.actions.preview"),children:Ge?s.jsx(L,{name:"stop",className:"w-3.5 h-3.5"}):s.jsx(L,{name:"play",className:"w-3.5 h-3.5"})})]}),a==="browser"&&Pe.length>0&&s.jsxs(s.Fragment,{children:[s.jsxs(St,{value:O||"$auto",onValueChange:W=>A(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(H,{size:"xs",variant:"ghost",onClick:Je,title:t("settings.voice.page.actions.preview"),children:q?s.jsx(L,{name:"stop",className:"w-3.5 h-3.5"}):s.jsx(L,{name:"play",className:"w-3.5 h-3.5"})})]})]}),s.jsxs(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:d,onChange:W=>y(Number(W.target.value)),className:vt}),e?s.jsx(xs,{value:Math.round(d*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(d*100),"%"]})]}),s.jsx(Ss,{title:t("settings.voice.page.field.ttsInputMode"),children:s.jsx(Ys,{value:G,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:F,onChange:ee,"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")}]})}),F==="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})]}),F==="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(L,{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(L,{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 d;e[2]!==g?(d=xe("size-4 shrink-0",g),e[2]=g,e[3]=d):d=e[3];let y;e[4]!==d?(y=s.jsx(L,{name:"cloud",className:d}),e[4]=d,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():"",d=ji(typeof i.hostname=="string"?i.hostname:"");!l||!g||!d||e.has(l)||a.has(d)||(e.add(l),a.add(d),n.push({id:l,name:g,hostname:d}))}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(J=>J.timeFormatPreference),a=o.useCallback(J=>t(J),[t]),[n,r]=o.useState("checking"),[i,l]=o.useState(null),[g,d]=o.useState(null),[y,p]=o.useState(null),[b,c]=o.useState(null),[I,f]=o.useState(null),[S,w]=o.useState(!1),[N,m]=o.useState(!1),[T,R]=o.useState(!1),[P,j]=o.useState("cloudflare"),[h,v]=o.useState(()=>rr("cloudflare")),[O,A]=o.useState([]),[C,M]=o.useState("quick"),[B,V]=o.useState(null),[k,D]=o.useState([]),[$,K]=o.useState({}),[Q,te]=o.useState(""),[U,le]=o.useState({}),[_,G]=o.useState(new Set),[z,F]=o.useState(!1),[ee,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(()=>B?!Ra(B):!1,[B]),ne=o.useMemo(()=>k.find(J=>J.id===Q)||k[0]||null,[k,Q]),be=o.useMemo(()=>fe.map(J=>{const pe=J.expiresAt<=Ue,De=J.status==="active"&&!pe,Ae=De?cl(J.expiresAt-Ue):J.inactiveReason==="expired"||pe?"expired":"inactive",it=Ae==="expired"?t("settings.aiworker.tunnel.state.expired"):J.inactiveReason==="tunnel-revoked"?t("settings.aiworker.tunnel.state.revoked"):t("settings.aiworker.tunnel.state.inactive"),rt=Nn(J.mode);return{...J,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===C,[g,n,i,C]),Fe=o.useMemo(()=>!i||n!=="active"||!g?!1:g!==C,[g,n,i,C]),Ke=o.useMemo(()=>{if(typeof Oe=="number"&&Number.isFinite(Oe)&&Oe>0)return Oe;if(typeof window>"u")return null;const pe=$a()||window.location.href;let De=0;try{De=Number(new URL(pe).port)}catch{De=Number(window.location.port)}return Number.isFinite(De)&&De>0?De:null},[Oe]),Ee=o.useMemo(()=>O.find(J=>J.provider===P)??null,[O,P]),je=o.useMemo(()=>{const J=new Set(Ee?.modes?.map(pe=>pe.key).filter(pe=>pe==="quick"||pe==="managed-remote"||pe==="managed-local"));return J.size===0?ir:ir.filter(pe=>J.has(pe.value))},[Ee]),Ze=o.useMemo(()=>je.some(J=>J.value==="managed-remote"||J.value==="managed-local"),[je]),me=o.useMemo(()=>h.provider===P?h:rr(P),[h,P]),Ie=o.useCallback(async J=>{await Pn(J)},[]),Le=o.useCallback((J,pe)=>(v(rr(pe,J)),J.available===!0),[]),Xe=o.useCallback(async(J,pe)=>{try{const De=await yt("/api/openchamber/tunnel/check",{query:{provider:J},...pe?{signal:pe}:{}});if(!De.ok)return null;const Ae=await De.json();if(pe?.aborted)return null;const it=Le(Ae,J);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 J=>{try{const[pe,De,Ae,it]=await Promise.all([yt("/api/openchamber/tunnel/check",{signal:J}),yt("/api/openchamber/tunnel/status",{signal:J}),pn(),yt("/api/openchamber/tunnel/providers",{signal:J})]),rt=await pe.json(),qe=await De.json(),Pt=Ae??{},ys=it.ok?await it.json():{},Zt=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(Zt),Ce(Os),j(is),A(Array.isArray(ys?.providers)?ys.providers:[]),M(Wt),V(Ht),D(ds),te(Es),_e(Array.isArray(qe.activeSessions)?qe.activeSessions:[]),d(qe.activeTunnelMode?Nn(qe.activeTunnelMode):qe.active&&qe.mode?Nn(qe.mode):null),G(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{J.aborted||(r("error"),c(t("settings.aiworker.tunnel.toast.checkAvailabilityFailed")))}},[Le,t]);o.useEffect(()=>{const J=new AbortController;return q(J.signal),()=>J.abort()},[q]),o.useEffect(()=>{if(!i?.connectUrl){p(null);return}let J=!1;return zl.toDataURL(i.connectUrl,{width:256,margin:2,color:{dark:"#000000",light:"#ffffff"}}).then(pe=>{J||p(pe)}).catch(()=>{J||p(null)}),()=>{J=!0}},[i?.connectUrl]),o.useEffect(()=>{if(!i?.bootstrapExpiresAt){ye(t("settings.aiworker.tunnel.state.noExpiry"));return}let J=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),J=requestAnimationFrame(Ae)};De(),(typeof document>"u"||document.visibilityState==="visible")&&(J=requestAnimationFrame(Ae));const it=()=>{document.visibilityState==="visible"&&J===null?J=requestAnimationFrame(Ae):document.visibilityState!=="visible"&&J!==null&&(cancelAnimationFrame(J),J=null)};return document.addEventListener("visibilitychange",it),()=>{document.removeEventListener("visibilitychange",it),J!==null&&cancelAnimationFrame(J)}},[t,i?.bootstrapExpiresAt]),o.useEffect(()=>{let J=null,pe=Date.now();const De=()=>{const it=Date.now();it-pe>=1e3&&(Ne(it),pe=it),J=requestAnimationFrame(De)};(typeof document>"u"||document.visibilityState==="visible")&&(J=requestAnimationFrame(De));const Ae=()=>{document.visibilityState==="visible"&&J===null?J=requestAnimationFrame(De):document.visibilityState!=="visible"&&J!==null&&(cancelAnimationFrame(J),J=null)};return document.addEventListener("visibilitychange",Ae),()=>{document.removeEventListener("visibilitychange",Ae),J!==null&&cancelAnimationFrame(J)}},[]),o.useEffect(()=>{if(n==="starting"||n==="stopping"||n==="checking")return;let J=!1;const pe=async()=>{try{const Ae=await yt("/api/openchamber/tunnel/status");if(!Ae.ok||J)return;const it=await Ae.json();if(J)return;_e(Array.isArray(it.activeSessions)?it.activeSessions:[]),G(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()=>{J=!0,window.clearInterval(De)}},[n]);const ke=o.useCallback(async J=>{R(!0);try{await gt(J),Object.prototype.hasOwnProperty.call(J,"tunnelMode")&&J.tunnelMode&&M(J.tunnelMode),Object.prototype.hasOwnProperty.call(J,"tunnelProvider")&&typeof J.tunnelProvider=="string"&&j(J.tunnelProvider),Object.prototype.hasOwnProperty.call(J,"managedLocalTunnelConfigPath")&&V(J.managedLocalTunnelConfigPath??null),Object.prototype.hasOwnProperty.call(J,"managedRemoteTunnelPresets")&&J.managedRemoteTunnelPresets&&D(J.managedRemoteTunnelPresets)}catch{E.error(t("settings.aiworker.tunnel.toast.saveSettingsFailed"))}finally{R(!1)}},[t]),Pe=o.useCallback(async(J,pe)=>{m(!0);try{await gt({tunnelBootstrapTtlMs:J,tunnelSessionTtlMs:pe})}catch{E.error(t("settings.aiworker.tunnel.toast.saveTtlFailed"))}finally{m(!1)}},[t]),Je=o.useCallback(async J=>{const pe=J.token.trim();if(pe)try{const De={...U,[J.presetId]:pe};await gt({managedRemoteTunnelPresetTokens:De}),G(Ae=>{const it=new Set(Ae);return it.add(J.presetId),it})}catch{E.error(t("settings.aiworker.tunnel.toast.saveTokenFailed"))}},[U,t]),ot=o.useCallback(async J=>{f(null),c(null);const pe=O.find(Ae=>Ae.provider===J),De=pe?.modes?.some(Ae=>Ae.key===C)?C:Nn(pe?.modes?.[0]?.key);await ke({tunnelProvider:J,tunnelMode:De}),Xe(J)},[O,Xe,ke,C]),st=o.useCallback(async()=>{const J=await Rl({filters:[{name:"Config",extensions:["yml","yaml","json"]}]});if(J.success&&typeof J.path=="string"&&J.path.trim().length>0){const pe=J.path.trim();if(!Ra(pe)){E.error(Ge);return}V(pe),await ke({managedLocalTunnelConfigPath:pe});return}ve.current?.click()},[Ge,ke]),pt=o.useCallback(J=>{const pe=J.trim();V(pe.length>0?pe:null)},[]),vt=o.useCallback(async()=>{if(B&&!Ra(B)){E.error(Ge);return}await ke({managedLocalTunnelConfigPath:B})},[Ge,B,ke]),W=o.useCallback(async()=>{V(null),await ke({managedLocalTunnelConfigPath:null})},[ke]),We=o.useCallback(async J=>{const pe=J.target.files?.[0];if(!pe)return;const De=pe.name.trim();if(De.length!==0){if(!Ra(De)){E.error(Ge);return}V(De),await ke({managedLocalTunnelConfigPath:De}),J.target.value=""}},[Ge,ke]),nt=o.useCallback(async()=>{if(c(null),f(null),C==="managed-local"&&B&&!Ra(B)){c(Ge),E.error(Ge);return}r("starting");try{let J="",pe="";if(C==="managed-remote"){if(!ne){r("idle"),f(t("settings.aiworker.tunnel.toast.selectOrAddManagedRemoteFirst")),E.error(t("settings.aiworker.tunnel.toast.selectOrAddManagedRemoteFirst"));return}J=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:P,mode:C,...C==="managed-remote"&&ne?{managedRemoteTunnelPresetId:ne.id,managedRemoteTunnelPresetName:ne.name}:{},...C==="managed-remote"&&J?{managedRemoteTunnelHostname:J}:{},...C==="managed-remote"&&pe?{managedRemoteTunnelToken:pe}:{},...C==="managed-local"&&B?{configPath:B}:{}})}),Ae=await De.json();if(!De.ok||!Ae.ok){if(C==="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"),c(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"),c(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}),d(Ae.activeTunnelMode?Nn(Ae.activeTunnelMode):Ae.mode?Nn(Ae.mode):C),_e(Array.isArray(Ae.activeSessions)?Ae.activeSessions:[]),Array.isArray(Ae.managedRemoteTunnelTokenPresetIds)&&G(new Set(Ae.managedRemoteTunnelTokenPresetIds)),typeof Ae.localPort=="number"&&Ve(Ae.localPort),typeof Ae.mode=="string"&&M(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"),c(t("settings.aiworker.tunnel.toast.startFailed")),E.error(t("settings.aiworker.tunnel.toast.startFailed"))}},[Ge,k,ke,ne,U,t,P,C,B]),lt=o.useCallback(async()=>{r("stopping");try{await yt("/api/openchamber/tunnel/stop",{method:"POST"});const J=await yt("/api/openchamber/tunnel/status");if(J.ok){const pe=await J.json();_e(Array.isArray(pe.activeSessions)?pe.activeSessions:[]),G(new Set(Array.isArray(pe.managedRemoteTunnelTokenPresetIds)?pe.managedRemoteTunnelTokenPresetIds:[])),Ve(typeof pe.localPort=="number"?pe.localPort:null)}l(null),d(null),p(null),r("idle"),E.success(t("settings.aiworker.tunnel.toast.stopped"))}catch{r("error"),c(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),w(!0),E.success(t("settings.aiworker.tunnel.toast.connectLinkCopied")),setTimeout(()=>w(!1),2e3)}catch{E.error(t("settings.aiworker.tunnel.toast.copyUrlFailed"))}},[t,i?.connectUrl]),Lt=o.useCallback(async J=>{const pe=hi.find(De=>De.value===J);pe&&(re(pe.ms),await Pe(pe.ms,ue))},[Pe,ue]),et=o.useCallback(async J=>{const pe=fi.find(De=>De.value===J);!pe||pe.ms===null||(Ce(pe.ms),await Pe(se,pe.ms))},[se,Pe]),ft=o.useCallback(async J=>{f(null),c(null),n!=="active"&&n!=="stopping"&&n!=="starting"&&r("idle"),await ke({tunnelMode:J,managedRemoteTunnelPresets:k})},[k,ke,n]),bt=o.useCallback(async(J,pe)=>{try{await gt({managedRemoteTunnelPresets:pe})}catch{E.error(t("settings.aiworker.tunnel.toast.saveSelectedManagedRemoteFailed"))}},[t]),Be=o.useCallback(J=>{const pe=k.find(De=>De.id===J);pe&&(te(pe.id),f(null),bt(pe,k))},[k,bt]),Et=o.useCallback(async()=>{const J=ee.trim(),pe=ji(ae),De=de.trim();if(!J){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:J,hostname:pe},it=[...k,Ae];D(it),te(Ae.id),K(rt=>({...rt,[Ae.id]:!0})),le(rt=>({...rt,[Ae.id]:De})),f(null),F(!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,ee,de,Je,ke,U,t]),Me=o.useCallback(async J=>{const pe=k.find(qe=>qe.id===J);if(!pe)return;const De=k.filter(qe=>qe.id!==pe.id),Ae=De[0]?.id||"",it=Q===pe.id?Ae:Q,rt=Object.fromEntries(Object.entries(U).filter(([qe,Pt])=>qe!==pe.id&&Pt.trim().length>0));D(De),te(it),K(qe=>{const Pt={...qe};return delete Pt[pe.id],Pt}),le(qe=>{const Pt={...qe};return delete Pt[pe.id],Pt}),G(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,Q,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(L,{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(J=>{const pe=J.mode==="quick",De=J.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=J.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(L,{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(J.createdAt,e)})}),s.jsx("span",{className:"typography-meta text-foreground",children:J.isActive?t("settings.aiworker.tunnel.session.expiresIn",{remaining:J.remainingTextForSession}):J.inactiveLabel===t("settings.aiworker.tunnel.state.inactive")?t("settings.aiworker.tunnel.state.inactive"):t("settings.aiworker.tunnel.session.inactiveWithReason",{reason:J.inactiveLabel})})]},J.sessionId)})})]})}),n==="not-available"&&s.jsx("section",{className:"space-y-2 px-2 pb-2 pt-0",children:s.jsxs("div",{className:"flex items-start gap-2 rounded-lg border border-[var(--status-warning)]/30 bg-[var(--status-warning)]/5 p-3",children:[s.jsx(L,{name:"error-warning",className:"mt-0.5 size-4 shrink-0 text-[var(--status-warning)]"}),s.jsxs("div",{className:"space-y-1",children:[s.jsx("p",{className: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:P,onValueChange:J=>{ot(J)},disabled:T||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(P)})}),s.jsxs(It,{children:[O.length>0?O.map(J=>s.jsx(at,{value:J.provider,children:s.jsx(ol,{provider:J.provider})},J.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(J=>s.jsxs(kr,{children:[s.jsx(Nr,{asChild:!0,children:s.jsx(H,{variant:"chip",size:"xs","aria-pressed":C===J.value,className:"!font-normal",onClick:()=>{ft(J.value)},disabled:T||n==="starting"||n==="stopping",children:a(J.labelKey)})}),s.jsx(kl,{sideOffset:8,className:"max-w-xs",children:a(J.tooltipKey)})]},J.value))})]})]}),s.jsxs("div",{"data-settings-item":"tunnel.ttl",className:"mt-2 grid grid-cols-1 gap-2 py-1.5 md:grid-cols-[14rem_auto] md:gap-x-8 md:gap-y-2",children:[s.jsxs("div",{className:"flex min-w-0 items-center gap-2",children:[s.jsx("span",{className:xe(Tt,"shrink-0"),children:t("settings.aiworker.tunnel.field.connectLinkTtl")}),s.jsxs(St,{value:yr(hi,se,"1800000"),onValueChange:J=>{Lt(J)},disabled:N||T||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(J=>s.jsx(at,{value:J.value,children:J.label},J.value))})]})]}),s.jsxs("div",{className:"flex min-w-0 items-center gap-2",children:[s.jsx("span",{className:xe(Tt,"shrink-0"),children:t("settings.aiworker.tunnel.field.tunnelSessionTtl")}),s.jsxs(St,{value:yr(fi,ue,"28800000"),onValueChange:J=>{et(J)},disabled:N||T||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(J=>s.jsx(at,{value:J.value,children:J.label},J.value))})]})]})]}),C==="quick"&&s.jsx("div",{className:"rounded-lg border border-[var(--status-warning)]/35 bg-[var(--status-warning)]/10 p-3",children:s.jsxs("div",{className:"flex items-start gap-2",children:[s.jsx(L,{name:"error-warning",className:"mt-0.5 size-4 shrink-0 text-[var(--status-warning)]"}),s.jsxs("div",{children:[s.jsx("p",{className:"typography-meta text-[var(--status-warning)]",children:t("settings.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")})]})]})}),C==="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(H,{variant:"ghost",size:"xs",className:"!font-normal",onClick:()=>F(J=>!J),disabled:n==="starting"||n==="stopping"||T,children:[s.jsx(L,{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((J,pe)=>{const De=U[J.id]||"",Ae=_.has(J.id),it=$[J.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=>{K(qe=>({...qe,[J.id]:rt})),rt&&Be(J.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"||T,children:[it?s.jsx(L,{name:"arrow-down-s",className:"h-4 w-4 text-muted-foreground"}):s.jsx(L,{name:"arrow-right-s",className:"h-4 w-4 text-muted-foreground"}),s.jsx("span",{className:"typography-ui-label min-w-0 flex-1 truncate text-foreground",children:J.name})]}),s.jsx(H,{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:J.name}),onClick:()=>{Me(J.id)},disabled:n==="starting"||n==="stopping"||T,children:s.jsx(L,{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:J.hostname})]}),s.jsx(He,{type:"password",value:De,onChange:rt=>{const qe=rt.target.value;f(null),le(Pt=>({...Pt,[J.id]:qe}))},onBlur:rt=>{const qe=rt.currentTarget.value.trim();qe&&Je({presetId:J.id,presetName:J.name,hostname:J.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(H,{variant:"ghost",size:"xs",className:"!font-normal",disabled:n==="starting"||n==="stopping"||De.trim().length===0,onClick:()=>{Je({presetId:J.id,presetName:J.name,hostname:J.hostname,token:De})},children:t("settings.aiworker.tunnel.actions.saveToken")})})]})})]})},J.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:ee,onChange:J=>Y(J.target.value),placeholder:t("settings.aiworker.tunnel.field.newPresetNamePlaceholder"),className:"h-7",disabled:T||n==="starting"||n==="stopping"}),s.jsx(He,{value:ae,onChange:J=>ge(J.target.value),placeholder:t("settings.aiworker.tunnel.field.newPresetHostnamePlaceholder"),className:"h-7",disabled:T||n==="starting"||n==="stopping"}),s.jsx(He,{type:"password",value:de,onChange:J=>he(J.target.value),placeholder:t("settings.aiworker.tunnel.field.newPresetTokenPlaceholder"),className:"h-7",disabled:T||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(H,{variant:"ghost",size:"xs",className:"!font-normal",onClick:()=>{Et()},disabled:T||n==="starting"||n==="stopping",children:t("settings.common.actions.saveChanges")}),s.jsx(H,{variant:"ghost",size:"xs",className:"!font-normal",onClick:()=>{F(!1),Y(""),ge(""),he("")},disabled:T||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&&I&&s.jsx("p",{className:"typography-meta text-[var(--status-error)]",children:I})]}),C==="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:J=>{We(J)}}),s.jsxs("div",{className:"flex items-center gap-2",children:[s.jsx(He,{value:B||"",onChange:J=>{pt(J.target.value)},onBlur:()=>{vt()},placeholder:t("settings.aiworker.tunnel.field.configurationFilePlaceholder"),className:"h-7",disabled:n==="starting"||n==="stopping"||T}),s.jsx(H,{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"||T,children:s.jsx(L,{name:"folder",className:"size-3.5"})}),B&&s.jsx(H,{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"||T,children:s.jsx(L,{name:"close",className:"size-3.5"})})]}),s.jsx("p",{className:"typography-meta text-muted-foreground/70",children:t(B?"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(L,{name:"information",className:"mt-0.5 size-4 shrink-0 text-[var(--status-info)]"}),s.jsxs("div",{className:"space-y-1",children:[C==="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(L,{name:"external-link",className:"size-3.5"})]})]}),C==="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(L,{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(J=>J.value===C)?.labelKey??"settings.aiworker.tunnel.option.mode.quick.label")})})]})]})}),C==="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:Q||(k[0]?.id??""),onValueChange:J=>{Be(J)},disabled:T||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(J=>s.jsx(at,{value:J.id,children:J.name},J.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(L,{name:"error-warning",className:"mt-0.5 size-4 shrink-0 text-[var(--status-warning)]"}),s.jsx("p",{className:"typography-meta text-[var(--status-warning)]",children:t("settings.aiworker.tunnel.warning.replacesActiveTunnel")})]})}),s.jsx(H,{size:"sm",variant:"outline",onClick:nt,disabled:n==="starting"||T||C==="managed-remote"&&!ne||C==="managed-local"&&Z,className:xe(wt,n==="starting"&&"opacity-70"),children:n==="starting"?s.jsxs(s.Fragment,{children:[s.jsx(L,{name:"loader-4",className:"size-3.5 animate-spin"})," ",t("settings.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(H,{size:"sm",variant:"ghost",onClick:ht,className:"shrink-0 gap-1.5",children:[S?s.jsx(L,{name:"check",className:"size-3.5 text-[var(--status-success)]"}):s.jsx(L,{name:"file-copy",className:"size-3.5"}),t(S?"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(H,{size:"sm",variant:"outline",onClick:nt,disabled:n==="stopping"||T||C==="managed-local"&&Z,className:wt,children:[s.jsx(L,{name:"restart",className:"size-3.5"}),t("settings.aiworker.tunnel.actions.newConnectLink")]}),s.jsx(H,{size:"sm",variant:"ghost",onClick:lt,disabled:n==="stopping"||T,className:"gap-2 text-[var(--status-error)]",children:n==="stopping"?s.jsxs(s.Fragment,{children:[s.jsx(L,{name:"loader-4",className:"size-3.5 animate-spin"})," ",t("settings.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(H,{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(c=>c.showOpenCodeUpdateNotifications),d=ie(c=>c.setShowOpenCodeUpdateNotifications);$e.useEffect(()=>{let c=!1;return(async()=>{try{const I=await pn();if(c||!I)return;a(I.opencodeBinary??"")}catch{}finally{c||r(!1)}})(),()=>{c=!0}},[]);const y=$e.useCallback(async()=>{if(!(typeof window>"u")&&as())try{const c=await Rl();c.success&&c.path&&c.path.trim().length>0&&a(c.path.trim())}catch{}},[]),p=$e.useCallback(async()=>{l(!0);try{const c=e.trim(),I=c.length>=2&&(c.startsWith('"')&&c.endsWith('"')||c.startsWith("'")&&c.endsWith("'"))?c.slice(1,-1).trim():c;await gt({opencodeBinary:I}),$n("cli",{id:"opencode-binary"}),E.success(t("settings.view.pendingRestart.saved"))}finally{l(!1)}},[t,e]),b=$e.useCallback(c=>{d(c),gt({showOpenCodeUpdateNotifications:c})},[d]);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:c=>a(c.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(H,{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(L,{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(H,{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),d=ie(Pf);let y;t[0]!==n?(y=C=>{n(C),gt({agentControlToolEnabled:C}),$n("cli",{id:"agent-control-tool"})},t[0]=n,t[1]=y):y=t[1];const p=y;let b;t[2]!==i?(b=C=>{i(C),gt({agentWebToolEnabled:C}),$n("cli",{id:"agent-web-tool"})},t[2]=i,t[3]=b):b=t[3];const c=b;let I;t[4]!==d?(I=C=>{d(C),gt({agentMemoryToolEnabled:C}).finally(()=>{C&&rd.getState().refresh()}),$n("cli",{id:"agent-memory-tool"})},t[4]=d,t[5]=I):I=t[5];const f=I;let S;t[6]!==e?(S=e("settings.aiworker.tools.title"),t[6]=e,t[7]=S):S=t[7];let w;t[8]!==e?(w=e("settings.aiworker.tools.field.agentControlTool"),t[8]=e,t[9]=w):w=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 T;t[14]!==a||t[15]!==p||t[16]!==w||t[17]!==N||t[18]!==m?(T=s.jsx(dt,{settingsItem:"sessions.agent-control-tool",checked:a,onChange:p,label:w,ariaLabel:N,info:m}),t[14]=a,t[15]=p,t[16]=w,t[17]=N,t[18]=m,t[19]=T):T=t[19];let R;t[20]!==e?(R=e("settings.aiworker.tools.field.agentWebTool"),t[20]=e,t[21]=R):R=t[21];let P;t[22]!==e?(P=e("settings.aiworker.tools.field.agentWebToolAria"),t[22]=e,t[23]=P):P=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]!==c||t[28]!==j||t[29]!==R||t[30]!==P?(h=s.jsx(dt,{settingsItem:"sessions.agent-web-tool",checked:r,onChange:c,label:R,ariaLabel:P,info:j}),t[26]=r,t[27]=c,t[28]=j,t[29]=R,t[30]=P,t[31]=h):h=t[31];let v;t[32]!==g||t[33]!==l||t[34]!==f||t[35]!==e?(v=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]=v):v=t[36];let O;t[37]!==h||t[38]!==v||t[39]!==T?(O=s.jsxs("div",{className:fs,children:[T,h,v]}),t[37]=h,t[38]=v,t[39]=T,t[40]=O):O=t[40];let A;return t[41]!==O||t[42]!==S?(A=s.jsx(ze,{title:S,children:O}),t[41]=O,t[42]=S,t[43]=A):A=t[43],A};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,d]=$e.useState(!1),[y,p]=$e.useState(""),[b,c]=$e.useState(!1),[I,f]=$e.useState(!1),[S,w]=$e.useState(null),[N,m]=$e.useState(!0),[T,R]=$e.useState(!1),[P,j]=$e.useState(!1),[h,v]=$e.useState(!1),[O,A]=$e.useState(!1),[C,M]=$e.useState(!1),[B,V]=$e.useState(!1),[k,D]=$e.useState(!1),[$,K]=$e.useState(!0),[Q,te]=$e.useState(!0),[U,le]=$e.useState(!1),[_,G]=$e.useState(!1),[z,F]=$e.useState(!1),[ee,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),d(Z.hasDesktopUiPassword===!0),p(""),c(!1),f(Z.desktopLanAccessActive===!0),w(Z.desktopLanAccessBlockedReason??null);const be=Z.desktopMacMenuBarEnabled!==!1;K(be),te(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),v(Z?.enabled===!0))})(),()=>{ve=!0}},[e]),$e.useEffect(()=>{if(!e){M(!1);return}let ve=!1;return(async()=>{const Z=await Ud();ve||(M(Z?.supported===!0),V(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),G(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||Q!==$,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&&I&&ae&&re?`http://${ae}:${re}`:null,Ce=de.length>0||g&&!b,Se=i&&!Ce,ye=n&&!I&&S==="missing-password",fe=N||T||!se||Se,_e=$e.useCallback(ve=>{p(ve),ve.trim()&&c(!1)},[]),Ue=$e.useCallback(()=>{p(""),c(!0),l(!1)},[]),Ne=$e.useCallback(async()=>{if(!P||O)return;const ve=!h;v(ve),A(!0),Y(null);try{const Z=await $d(ve);if(!Z?.supported)throw new Error(t("settings.aiworker.desktopNetwork.error.launchAtLoginUnsupported"));v(Z.enabled)}catch(Z){v(!ve),Y(Z instanceof Error?Z.message:t("settings.aiworker.desktopNetwork.error.launchAtLoginSaveFailed"))}finally{A(!1)}},[O,h,P,t]),Oe=$e.useCallback(async()=>{if(!C||k)return;const ve=!B;V(ve),D(!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"));V(Z.enabled)}catch(Z){V(!ve),Y(Z instanceof Error?Z.message:t("settings.aiworker.desktopNetwork.error.minimizeToTraySaveFailed"))}finally{D(!1)}},[k,B,C,t]),Ve=$e.useCallback(async()=>{if(!U||z)return;const ve=!_;G(ve),F(!0),Y(null);try{const Z=await Bd(ve);if(!Z?.supported)throw new Error(t("settings.aiworker.desktopNetwork.error.keepAwakeUnsupported"));G(Z.enabled)}catch(Z){G(!ve),Y(Z instanceof Error?Z.message:t("settings.aiworker.desktopNetwork.error.keepAwakeSaveFailed"))}finally{F(!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:Q})).ok)throw new Error(t("settings.aiworker.desktopNetwork.error.saveFailed"));if(r(i),de?d(!0):b&&d(!1),p(""),c(!1),K(Q),!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)}}},[Q,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:[P||a||C||U?s.jsxs("div",{className:fs,children:[P?s.jsx(dt,{settingsItem:"sessions.desktop-launch-at-login",checked:h,onChange:ve=>{ve!==h&&Ne()},disabled:O,label:t("settings.aiworker.desktopNetwork.field.launchAtLogin"),info:t("settings.aiworker.desktopNetwork.field.launchAtLoginDescription"),ariaLabel:t("settings.aiworker.desktopNetwork.field.launchAtLoginAria")}):null,a?s.jsx(dt,{settingsItem:"sessions.desktop-mac-menu-bar",checked:Q,onChange:te,disabled:N||T,label:t("settings.aiworker.desktopNetwork.field.macMenuBar"),info:t("settings.aiworker.desktopNetwork.field.macMenuBarDescription"),ariaLabel:t("settings.aiworker.desktopNetwork.field.macMenuBarAria")}):null,C?s.jsx(dt,{settingsItem:"sessions.desktop-minimize-to-tray",checked:B,onChange:ve=>{ve!==B&&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||T,required:i&&!Ce,"aria-invalid":Se}),g&&!b?s.jsx(H,{type:"button",variant:"ghost",size:"xs",onClick:Ue,disabled:N||T,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||T,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")})}),ee?s.jsx("div",{className:"typography-micro text-[var(--status-error)]",children:ee}):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(H,{type:"button",size:"xs",onClick:Ge,disabled:fe,className:"shrink-0 !font-normal",children:t(T?"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 d=g;let y;e[2]!==d?(y=re=>re.action.customizable?d(re.action):Gn(re.action.defaultBinding),e[2]=d,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[c,I]=o.useState(b),f=o.useRef(null);let S,w;e[5]!==a?(S=()=>{a&&(I({chords:[],livePreview:null,settled:!1}),f.current?.focus())},w=[a],e[5]=a,e[6]=S,e[7]=w):(S=e[6],w=e[7]),o.useEffect(S,w);const N=c.chords.length===1&&!c.settled;let m,T;e[8]!==N?(m=()=>{if(!N)return;const re=window.setTimeout(()=>I(ul),Af);return()=>window.clearTimeout(re)},T=[N],e[8]=N,e[9]=m,e[10]=T):(m=e[9],T=e[10]),o.useEffect(m,T);let R;e[11]!==c.chords?(R=Ii(c.chords.join(" ")),e[11]=c.chords,e[12]=R):R=e[12];const P=R;let j;e[13]!==a||e[14]!==P||e[15]!==n?(j=a&&P?od(a.id,P,n):[],e[13]=a,e[14]=P,e[15]=n,e[16]=j):j=e[16];const h=j;let v;e[17]!==h?(v=h.find(Lf),e[17]=h,e[18]=v):v=e[18];const O=v;let A,C,M,B,V,k,D,$,K,Q,te,U,le,_,G;if(e[19]!==a||e[20]!==d||e[21]!==P||e[22]!==p||e[23]!==h||e[24]!==i||e[25]!==r||e[26]!==O||e[27]!==c||e[28]!==l){const re=h.filter(Tf);V=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],M=Se,B=()=>{c.settled||I(ul),!(!a||!P||O||V)&&(r(a.id,P,ue?.action.id),M())};let ye;e[46]!==a||e[47]!==c?(ye=(Re,Fe)=>{Re.preventDefault(),Re.stopPropagation();const Ke=!!(a&&"prefixStyle"in a&&a.prefixStyle);if(Fe==="keyup"&&Ke&&c.chords.length===0){const je=Df(Re);if(je){I({chords:[je],livePreview:null,settled:!0});return}}const Ee=Mf(c,{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);I(Ke&&Ee.chords.length>1?c:Ee)},e[46]=a,e[47]=c,e[48]=ye):ye=e[48];const fe=ye;C=Kt,_=a!==null,G=zf,A=zt,k="max-w-md",D=f,$=!1;let _e;e[49]!==a||e[50]!==d||e[51]!==l?(_e=a?l("settings.aiworker.keyboardShortcuts.dialog.title",{action:d(a)}):"",e[49]=a,e[50]=d,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?(K=s.jsxs(_t,{children:[Ue,Oe]}),e[59]=Ue,e[60]=Oe,e[61]=K):K=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=()=>I(Uf),e[65]=ve):ve=e[65];let Z;e[66]!==c.chords?(Z=c.chords.map(_f),e[66]=c.chords,e[67]=Z):Z=e[67];let ne;e[68]!==c.livePreview?(ne=c.livePreview?s.jsx("kbd",{className:"rounded-md border border-dashed border-border bg-muted px-3 py-2 typography-ui-label font-mono text-muted-foreground",children:Gn(c.livePreview)}):null,e[68]=c.livePreview,e[69]=ne):ne=e[69];let be;e[70]!==c.chords.length||e[71]!==c.livePreview||e[72]!==l?(be=c.chords.length===0&&!c.livePreview?s.jsx("span",{className:"typography-ui-label text-muted-foreground",children:l("settings.aiworker.keyboardShortcuts.dialog.recording")}):null,e[70]=c.chords.length,e[71]=c.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?(Q=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]=Q):Q=e[81],te=c.settled&&O?s.jsx("p",{className:"typography-meta text-[var(--status-error)]",children:l("settings.aiworker.keyboardShortcuts.error.internalConflict")}):c.settled&&V?s.jsx("p",{className:"typography-meta text-[var(--status-error)]",children:l("settings.aiworker.keyboardShortcuts.error.prefixConflict",{action:d(V.action)})}):null,U=c.settled&&ue&&!O&&!V?s.jsx("p",{className:"typography-meta text-[var(--status-warning)]",children:l("settings.aiworker.keyboardShortcuts.error.exactConflict",{action:d(ue.action)})}):null,le=c.settled&&Ce&&!O&&!V?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]=d,e[21]=P,e[22]=p,e[23]=h,e[24]=i,e[25]=r,e[26]=O,e[27]=c,e[28]=l,e[29]=A,e[30]=C,e[31]=M,e[32]=B,e[33]=V,e[34]=k,e[35]=D,e[36]=$,e[37]=K,e[38]=Q,e[39]=te,e[40]=U,e[41]=le,e[42]=_,e[43]=G}else A=e[29],C=e[30],M=e[31],B=e[32],V=e[33],k=e[34],D=e[35],$=e[36],K=e[37],Q=e[38],te=e[39],U=e[40],le=e[41],_=e[42],G=e[43];let z;e[82]!==P||e[83]!==c.settled||e[84]!==l?(z=c.settled&&P&&ld(P)?s.jsx("p",{className:"typography-meta text-[var(--status-warning)]",children:l("settings.aiworker.keyboardShortcuts.warning.riskyBrowserShortcut")}):null,e[82]=P,e[83]=c.settled,e[84]=l,e[85]=z):z=e[85];let F;e[86]!==l?(F=l("settings.common.actions.cancel"),e[86]=l,e[87]=F):F=e[87];let ee;e[88]!==M||e[89]!==F?(ee=s.jsx(H,{type:"button",variant:"ghost",size:"sm",onClick:M,children:F}),e[88]=M,e[89]=F,e[90]=ee):ee=e[90];const Y=!P||c.settled&&(!!O||!!V);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]!==B||e[94]!==Y||e[95]!==ae?(ge=s.jsx(H,{type:"button",size:"sm",disabled:Y,onClick:B,children:ae}),e[93]=B,e[94]=Y,e[95]=ae,e[96]=ge):ge=e[96];let de;e[97]!==ee||e[98]!==ge?(de=s.jsxs(ts,{children:[ee,ge]}),e[97]=ee,e[98]=ge,e[99]=de):de=e[99];let he;e[100]!==A||e[101]!==k||e[102]!==D||e[103]!==$||e[104]!==K||e[105]!==Q||e[106]!==te||e[107]!==U||e[108]!==le||e[109]!==z||e[110]!==de?(he=s.jsxs(A,{className:k,initialFocus:D,showCloseButton:$,children:[K,Q,te,U,le,z,de]}),e[100]=A,e[101]=k,e[102]=D,e[103]=$,e[104]=K,e[105]=Q,e[106]=te,e[107]=U,e[108]=le,e[109]=z,e[110]=de,e[111]=he):he=e[111];let se;return e[112]!==C||e[113]!==_||e[114]!==G||e[115]!==he?(se=s.jsx(C,{open:_,onOpenChange:G,children:he}),e[112]=C,e[113]=_,e[114]=G,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 d;if(t[0]===Symbol.for("react.memo_cache_sentinel")){const P=ud();d=cs()?P.filter(qf):P,t[0]=d}else d=t[0];const y=d,p=Jf;let b;t[1]!==n||t[2]!==a?(b=(P,j,h)=>{const v={...a,[P]:j};h&&(v[h]=qi),n(P,j),h&&n(h,qi),p(v)},t[1]=n,t[2]=a,t[3]=b):b=t[3];const c=b;let I;t[4]!==r||t[5]!==a?(I=P=>{const j={...a};delete j[P],r(P),p(j)},t[4]=r,t[5]=a,t[6]=I):I=t[6];const f=I;let S;t[7]!==a||t[8]!==e?(S=P=>{const j="prefixStyle"in P&&P.prefixStyle,h=j?pd(P.id,a):Tl(P.id,a),v=Gn(h,e("settings.aiworker.keyboardShortcuts.unassigned"));if(!j||!h||h===qi)return v;const O=P.id==="switch_session_tab"?e("settings.aiworker.keyboardShortcuts.action.switch_session_tab.suffix"):e("settings.aiworker.keyboardShortcuts.action.switch_context_surface.suffix");return`${v}${O}`},t[7]=a,t[8]=e,t[9]=S):S=t[9];const w=S;let N;t[10]!==i||t[11]!==f||t[12]!==w||t[13]!==a||t[14]!==e?(N=$f.map((P,j)=>{const h=y.filter(v=>v.category===P);return h.length===0?null:s.jsx(ze,{settingsItem:j===0?"shortcuts.keyboard-shortcuts":void 0,title:e(`settings.aiworker.keyboardShortcuts.category.${P}`),divider:j!==0,info:j===0?e("settings.aiworker.keyboardShortcuts.tooltip"):void 0,headerAction:j===0?s.jsx(H,{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(v=>s.jsxs(Rt,{label:e(v.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:w(v)}),s.jsx(H,{type:"button",variant:"secondary",size:"xs",className:"!font-normal",onClick:()=>g(v),children:e("settings.aiworker.keyboardShortcuts.actions.edit")}),v.id in a?s.jsx(H,{type:"button",variant:"ghost",size:"xs",className:"!font-normal",onClick:()=>f(v.id),children:e("settings.common.actions.reset")}):null]},v.id))})},P)}),t[10]=i,t[11]=f,t[12]=w,t[13]=a,t[14]=e,t[15]=N):N=t[15];let m;t[16]===Symbol.for("react.memo_cache_sentinel")?(m=P=>{P||g(null)},t[16]=m):m=t[16];let T;t[17]!==l||t[18]!==c||t[19]!==a?(T=s.jsx(Rf,{action:l,overrides:a,onSave:c,onOpenChange:m}),t[17]=l,t[18]=c,t[19]=a,t[20]=T):T=t[20];let R;return t[21]!==N||t[22]!==T?(R=s.jsxs(s.Fragment,{children:[N,T]}),t[21]=N,t[22]=T,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 d;e[2]===Symbol.for("react.memo_cache_sentinel")?(d=cs(),e[2]=d):d=e[2];const y=d;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 G,z,F,ee,Y,ae;e[7]===Symbol.for("react.memo_cache_sentinel")?(F=b&&s.jsx(lc,{}),ee=!y&&s.jsx(rc,{}),Y=!y&&s.jsx(oc,{}),ae=s.jsx(ec,{}),G=s.jsx(sc,{}),z=Bn()&&!as()&&!y&&!Ol()&&s.jsx(tc,{}),e[7]=G,e[8]=z,e[9]=F,e[10]=ee,e[11]=Y,e[12]=ae):(G=e[7],z=e[8],F=e[9],ee=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,_,F,ee,Y,ae,G,z,ge]}),e[15]=ge,e[16]=_,e[17]=de):de=e[17],de}let c;e[18]!==i||e[19]!==a?(c=()=>{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]=c):c=e[20];const I=c;let f;e[21]!==n?(f=n("settings.page.general.title"),e[21]=n,e[22]=f):f=e[22];let S;e[23]!==n?(S=n("settings.page.appearance.title"),e[23]=n,e[24]=S):S=e[24];let w;e[25]!==n?(w=n("settings.page.chat.title"),e[25]=n,e[26]=w):w=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 T;e[31]!==n?(T=n("settings.page.git.title"),e[31]=n,e[32]=T):T=e[32];let R;e[33]!==n?(R=n("settings.page.git.title"),e[33]=n,e[34]=R):R=e[34];let P;e[35]!==n?(P=n("settings.page.notifications.title"),e[35]=n,e[36]=P):P=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 v;e[41]!==T||e[42]!==R||e[43]!==P||e[44]!==j||e[45]!==h||e[46]!==f||e[47]!==S||e[48]!==w||e[49]!==N||e[50]!==m?(v={general:f,visual:S,chat:w,sessions:N,shortcuts:m,git:T,github:R,notifications:P,voice:j,tunnel:h},e[41]=T,e[42]=R,e[43]=P,e[44]=j,e[45]=h,e[46]=f,e[47]=S,e[48]=w,e[49]=N,e[50]=m,e[51]=v):v=e[51];const O=v[a];let A;e[52]!==n?(A=n("settings.page.general.description"),e[52]=n,e[53]=A):A=e[53];let C;e[54]!==n?(C=n("settings.page.appearance.description"),e[54]=n,e[55]=C):C=e[55];let M;e[56]!==n?(M=n("settings.page.chat.description"),e[56]=n,e[57]=M):M=e[57];let B;e[58]!==n?(B=n("settings.page.sessions.description"),e[58]=n,e[59]=B):B=e[59];let V;e[60]!==n?(V=n("settings.page.shortcuts.description"),e[60]=n,e[61]=V):V=e[61];let k;e[62]!==n?(k=n("settings.page.notifications.description"),e[62]=n,e[63]=k):k=e[63];let D;e[64]!==n?(D=n("settings.page.voice.description"),e[64]=n,e[65]=D):D=e[65];let $;e[66]!==n?($=n("settings.page.tunnel.description"),e[66]=n,e[67]=$):$=e[67];let K;e[68]!==A||e[69]!==C||e[70]!==M||e[71]!==B||e[72]!==V||e[73]!==k||e[74]!==D||e[75]!==$?(K={general:A,visual:C,chat:M,sessions:B,shortcuts:V,git:void 0,github:void 0,notifications:k,voice:D,tunnel:$},e[68]=A,e[69]=C,e[70]=M,e[71]=B,e[72]=V,e[73]=k,e[74]=D,e[75]=$,e[76]=K):K=e[76];const Q=K[a];let te;e[77]!==I?(te=I(),e[77]=I,e[78]=te):te=e[78];let U;return e[79]!==Q||e[80]!==O||e[81]!==te?(U=s.jsx(es,{title:O,description:Q,showSaveStatus:!0,className:"openchamber-page-body",children:te}),e[79]=Q,e[80]=O,e[81]=te,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,d,y,p,b;t[3]===Symbol.for("react.memo_cache_sentinel")?(g=r&&s.jsx(lc,{}),d=l&&s.jsx(tc,{}),y=s.jsx(sc,{}),p=!a&&s.jsx(rc,{}),b=!a&&s.jsx(oc,{}),t[3]=g,t[4]=d,t[5]=y,t[6]=p,t[7]=b):(g=t[3],d=t[4],y=t[5],p=t[6],b=t[7]);let c;t[8]===Symbol.for("react.memo_cache_sentinel")?(c=a?[]:["sessionTabs"],t[8]=c):c=t[8];let I;return t[9]===Symbol.for("react.memo_cache_sentinel")?(I=s.jsxs(s.Fragment,{children:[g,d,y,p,b,s.jsx(Pi,{visibleSettings:["fileEditorKeymap",...c,"autoSaveEnabled",...a?[]:["terminalQuickKeys"],...a?[]:["terminalShell"],...a?[]:["terminalLoginShell"],"messageTransport","reportUsage"]})]}),t[9]=I):I=t[9],I},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),[d,y]=$e.useState(!1),[p,b]=$e.useState(!1),c=r>0;let I;e[0]!==n?(I=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]=I):I=e[1];const f=I;let S;e[2]!==n?(S=async()=>{try{await Il({message:n("settings.view.pendingRestart.applying"),mode:"projects",scopes:["all"]}),Vn.getState().clear()}catch{}},e[2]=n,e[3]=S):S=e[3];const w=S;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 T;e[8]!==c||e[9]!==f||e[10]!==w||e[11]!==l?(T=()=>{if(!c){w();return}if(l){b(!1),y(!0);return}f()},e[8]=c,e[9]=f,e[10]=w,e[11]=l,e[12]=T):T=e[12];const R=T;let P;e[13]!==c||e[14]!==i||e[15]!==n?(P=n(c?i?"settings.view.pendingRestart.applying":"settings.view.actions.applyAndRestartOpenCode":"settings.view.actions.reloadOpenCode"),e[13]=c,e[14]=i,e[15]=n,e[16]=P):P=e[16];const j=P;let h;e[17]!==c||e[18]!==r||e[19]!==n?(h=c?r===1?n("settings.view.actions.applyAndRestartOpenCodeTooltipSingle"):n("settings.view.actions.applyAndRestartOpenCodeTooltipPlural",{count:r}):n("settings.view.actions.reloadOpenCodeTooltip"),e[17]=c,e[18]=r,e[19]=n,e[20]=h):h=e[20];const v=h,O=c?"bg-primary text-primary-foreground typography-ui-label font-semibold hover:bg-primary/90":"text-sm font-semibold text-sidebar-foreground/90 hover:text-sidebar-foreground hover:bg-interactive-hover",A=i&&"opacity-80";let C;e[21]!==a||e[22]!==O||e[23]!==A?(C=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",O,A,a),e[21]=a,e[22]=O,e[23]=A,e[24]=C):C=e[24];let M;e[25]!==c||e[26]!==r?(M=c?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(L,{name:"restart",className:"h-4 w-4 shrink-0"}),e[25]=c,e[26]=r,e[27]=M):M=e[27];let B;e[28]!==j?(B=s.jsx("span",{className:"truncate",children:j}),e[28]=j,e[29]=B):B=e[29];let V;e[30]!==R||e[31]!==i||e[32]!==M||e[33]!==B||e[34]!==C||e[35]!==v?(V=s.jsxs("button",{type:"button",disabled:i,title:v,"aria-label":v,onClick:R,className:C,children:[M,B]}),e[30]=R,e[31]=i,e[32]=M,e[33]=B,e[34]=C,e[35]=v,e[36]=V):V=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 D;e[38]!==n?(D=n("settings.view.pendingRestart.confirm.title"),e[38]=n,e[39]=D):D=e[39];let $;e[40]!==D?($=s.jsx($t,{children:D}),e[40]=D,e[41]=$):$=e[41];let K;e[42]!==n?(K=n("settings.view.pendingRestart.confirm.description"),e[42]=n,e[43]=K):K=e[43];let Q;e[44]!==K?(Q=s.jsx(Vt,{children:K}),e[44]=K,e[45]=Q):Q=e[45];let te;e[46]!==$||e[47]!==Q?(te=s.jsxs(_t,{children:[$,Q]}),e[46]=$,e[47]=Q,e[48]=te):te=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 G;e[53]!==_?(G=s.jsx("div",{className:"min-w-0 shrink-0",style:U,children:s.jsx(H,{type:"button",variant:"outline",className:"h-9 w-full normal-case",onClick:le,children:_})}),e[53]=_,e[54]=G):G=e[54];let z;e[55]===Symbol.for("react.memo_cache_sentinel")?(z={width:"40%"},e[55]=z):z=e[55];let F;e[56]!==n?(F=n("settings.view.actions.applyAndRestartOpenCode"),e[56]=n,e[57]=F):F=e[57];let ee;e[58]!==m||e[59]!==F?(ee=s.jsx("div",{className:"min-w-0 shrink-0",style:z,children:s.jsx(H,{type:"button",variant:"default",className:"h-9 w-full normal-case",onClick:m,children:F})}),e[58]=m,e[59]=F,e[60]=ee):ee=e[60];let Y;e[61]!==G||e[62]!==ee?(Y=s.jsxs("div",{className:"flex w-full items-stretch justify-center gap-3",children:[G,ee]}),e[61]=G,e[62]=ee,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(L,{name:"checkbox",className:"h-4 w-4 text-primary"}):s.jsx(L,{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]!==te||e[77]!==se?(re=s.jsxs(zt,{showCloseButton:!1,className:"max-w-md gap-5",children:[te,se]}),e[76]=te,e[77]=se,e[78]=re):re=e[78];let ue;e[79]!==d||e[80]!==re?(ue=s.jsx(Kt,{open:d,onOpenChange:k,children:re}),e[79]=d,e[80]=re,e[81]=ue):ue=e[81];let Ce;return e[82]!==V||e[83]!==ue?(Ce=s.jsxs(s.Fragment,{children:[V,ue]}),e[82]=V,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(d=>{if(l&&!l.has(d.page))return[];const y=pa(d.page);if(!y||y.isAvailable&&!y.isAvailable(e)||d.isAvailable&&!d.isAvailable(e))return[];const p=n(d.titleKey),b=d.descriptionKey?n(d.descriptionKey):null,c=pl([p,b,r(d.page),...d.keywords??[]].filter(Boolean).join(" "));return g.every(I=>c.includes(I))?[{...d,title:p,description:b,pageTitle:r(d.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(),d=e??g.isMobile,y=Vn(El),p=ie(Z=>Z.settingsPage),b=ie(Z=>Z.isSettingsDialogOpen),c=ie(Z=>Z.setSettingsPage),I=ie(Z=>Z.shortcutOverrides.open_settings),f=Fl(p),[S,w]=o.useState(r),N=o.useRef(r==="nav"?f:null);o.useEffect(()=>{!d&&f==="home"&&c("general")},[d,c,f]);const[m,T]=o.useState(""),[R,P]=o.useState(null),[j,h]=o.useState(0),v=o.useRef(null),O=o.useRef(!1),A=o.useRef([]),C=o.useRef(0),M=o.useRef(!1),B=o.useMemo(()=>as(),[]),V=o.useMemo(()=>as()&&Va(),[]),k=o.useMemo(()=>as()&&typeof window<"u"&&window.__AIWORKER_PLATFORM__==="darwin",[]),D=o.useMemo(()=>as()&&typeof window<"u"&&window.__AIWORKER_PLATFORM__==="win32",[]),$=o.useMemo(()=>as()&&typeof window<"u"&&window.__AIWORKER_PLATFORM__==="linux",[]),K=o.useMemo(()=>Ll(),[]),Q=o.useMemo(()=>xx(B,d),[B,d]),te=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,Q)).filter(ne=>!(Q.isVSCode&&ne.slug==="projects")).filter(ne=>!(d&&ne.slug==="shortcuts"))},[Q,d,n]),U=o.useMemo(()=>{const Z=new Map(gx.map((ne,be)=>[ne,be]));return te.slice().sort((ne,be)=>(Z.get(ne.slug)??999)-(Z.get(be.slug)??999))},[te]),le=Gs(Z=>Z.activeProjectId),_=_s();o.useEffect(()=>{if(!(!b&&!Q.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,Q.isVSCode,_,f]);const G=o.useCallback(Z=>{if(c(Z),N.current=Z,!d)return;const ne=pa(Z);if(!ne||ne.slug==="home"){w("nav");return}w(ne.kind==="split"?"page-sidebar":"page-content")},[d,c]),z=o.useMemo(()=>pa(f),[f]),F=o.useMemo(()=>({general:"general",appearance:"visual",chat:"chat",shortcuts:"shortcuts",sessions:"sessions",notifications:"notifications",voice:"voice",tunnel:"tunnel"}),[]),ee=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:{...Q,isDesktopLocalOrigin:V,isMac:k,isWindows:D,isLinux:$,isWindowsArm64:K},visiblePageSlugs:n,t:l,getPageTitle:ee}),[ee,K,V,k,D,$,Q,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),C.current=0,M.current=!1},[m]),o.useEffect(()=>{C.current=j},[j]),o.useEffect(()=>{A.current[j]?.scrollIntoView({block:"nearest"})},[j]),o.useEffect(()=>{j>=Y.length&&h(Math.max(0,Y.length-1)),A.current.length=Y.length},[j,Y.length]);const de=o.useCallback(Z=>{const ne=ae(Z);P(ne),G(Z.page),d&&w("page-content"),Z.id==="plugins.create"&&typeof window<"u"&&window.setTimeout(()=>{window.dispatchEvent(new CustomEvent("aiworker:settings-open-plugin-add"))},50)},[d,G,ae]),he=o.useCallback(Z=>{if(m.trim()){if(Z.key==="Escape"){Z.preventDefault(),T("");return}if(Y.length!==0){if(Z.key==="ArrowDown"){Z.preventDefault(),M.current=!0,h(ne=>(ne+1)%Y.length);return}if(Z.key==="ArrowUp"){Z.preventDefault(),M.current=!0,h(ne=>(ne-1+Y.length)%Y.length);return}if(Z.key==="Enter"){Z.preventDefault();const ne=(C.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=v.current?.querySelector(`[data-settings-item="${we}"]`);Re&&(P(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,Q))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=F[Z]??"visual";return s.jsx(Qf,{section:be})}default:return null}},[F,se,Q,l]);o.useEffect(()=>{if(!d||S!=="nav"||f==="home"||N.current===f)return;const Z=pa(f);!Z||Z.slug==="home"||(N.current=f,w(Z.kind==="split"?"page-sidebar":"page-content"))},[d,S,f]);const Ce=d&&S!=="nav",Se=d&&S==="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",I===void 0?void 0:{open_settings:I}),_e=fe?l("settings.view.actions.closeSettingsWithShortcut",{shortcut:Gn(fe)}):l("settings.view.actions.closeSettings"),Ue=o.useCallback(Z=>{if(typeof window>"u"||Q.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)},[Q.isVSCode]),Ne=o.useCallback(()=>{O.current=!0,w("page-content"),Ue(f)},[Ue,f]);o.useEffect(()=>{if(!d||S!=="page-content"||!O.current)return;O.current=!1;const Z=window.requestAnimationFrame(()=>{v.current?.querySelector("[data-settings-page-heading]")?.focus({preventScroll:!0})});return()=>{window.cancelAnimationFrame(Z)}},[d,S,f]);const Oe=o.useCallback(()=>{if(Se){if((typeof window<"u"?or(window.history.state):null)?.page===f&&!Q.isVSCode){window.history.back();return}w("page-sidebar");return}w("nav")},[Se,Q.isVSCode,f]);o.useEffect(()=>{if(i)return i(()=>!d||S==="nav"?!1:(Oe(),!0)),()=>i(null)},[Oe,d,S,i]),o.useEffect(()=>{if(!d||Q.isVSCode)return;const Z=ne=>{if(pa(f)?.kind!=="split")return;if(or(ne.state)?.page===f){w("page-content");return}w(we=>we==="page-content"?"page-sidebar":we)};return window.addEventListener("popstate",Z),()=>{window.removeEventListener("popstate",Z)}},[d,Q.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(L,{name:"search",className:"h-4 w-4 shrink-0"}),s.jsx("input",{value:m,onChange:ne=>T(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:()=>T(""),"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(L,{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=>{A.current[Re]=Ee},onMouseMove:()=>{M.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&&!(d&&S==="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:()=>G(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(L,{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:ee(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:(!Q.isVSCode||y>0)&&s.jsx(ox,{})})})]})},Ge=()=>{if(S==="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(S==="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",Q.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:v,"data-settings-view":"true",className:xe("relative flex h-full min-h-0 flex-col overflow-hidden bg-background"),children:[d?s.jsxs("div",{className:xe("flex h-[var(--oc-header-height,56px)] shrink-0 items-center gap-2 px-3",S!=="nav"&&"border-b","bg-background"),style:S!=="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(L,{name:"arrow-left-s",className:"h-5 w-5"})}):null,s.jsx("div",{className:"min-w-0 flex-1 px-2 typography-ui-label font-medium text-foreground truncate",children:S==="nav"?l("settings.view.home.title"):z?ee(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(L,{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(L,{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(L,{name:"close",className:"h-5 w-5"})})})]}),s.jsx("div",{className:"flex flex-1 min-h-0 overflow-hidden",children:d?Ge():s.jsxs(s.Fragment,{children:[s.jsx("div",{className:xe("relative flex h-full min-h-0 flex-col overflow-hidden border-r",B?"bg-sidebar":Q.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};