@openchamber/web 1.12.2 → 1.12.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.
- package/dist/assets/{MarkdownRendererImpl-2INOOMmV.js → MarkdownRendererImpl-C2snGm6y.js} +1 -1
- package/dist/assets/{MultiRunWindow-BovvaCrr.js → MultiRunWindow-DXXoYCBh.js} +1 -1
- package/dist/assets/{NewWorktreeDialog-6y6rHfOQ.js → NewWorktreeDialog-C6394QE9.js} +1 -1
- package/dist/assets/OnboardingScreen-CLXmHHBW.js +1 -0
- package/dist/assets/{SessionSwitcherDropdown-DSXsR7zB.js → SessionSwitcherDropdown-BMN9gaXo.js} +1 -1
- package/dist/assets/{SettingsWindow-Dll7W_Kd.js → SettingsWindow-DXEjjH2f.js} +1 -1
- package/dist/assets/{TerminalView-D_ktT_L5.js → TerminalView-CePdcScA.js} +1 -1
- package/dist/assets/{es-9Cy-lgBh.js → es-rCA6AcBs.js} +1 -1
- package/dist/assets/{ko-BxmPoeb2.js → ko-CTiirGAp.js} +1 -1
- package/dist/assets/{main-BpZQobwD.js → main-D1IN8sAs.js} +2 -2
- package/dist/assets/{main-D8KFwoUt.js → main-DIwL7PaU.js} +46 -46
- package/dist/assets/{miniChat-BdEth0Oc.js → miniChat-DXW_W4_n.js} +2 -2
- package/dist/assets/{mobile-BxWzNO1C.js → mobile-DWyy0wq-.js} +2 -2
- package/dist/assets/{pl-J7oKZUR2.js → pl-CwJAYYhT.js} +1 -1
- package/dist/assets/{pt-BR-p6gRuJwx.js → pt-BR-xndordtt.js} +1 -1
- package/dist/assets/{renderElectronMiniChatApp-MNKYhIaT.js → renderElectronMiniChatApp-BmvjGDb_.js} +2 -2
- package/dist/assets/{renderMobileApp-DpYY7X9v.js → renderMobileApp-1BEmeUF9.js} +3 -3
- package/dist/assets/{uk-BOvMb8eG.js → uk-C52rE_cP.js} +1 -1
- package/dist/assets/{useAppFontEffects-DEZpweZZ.js → useAppFontEffects-hYm-4PtP.js} +4 -4
- package/dist/assets/{zh-CN-Cv0tBxN1.js → zh-CN-B7IfGwyh.js} +1 -1
- package/dist/assets/{zh-TW-CS7R6Ak3.js → zh-TW-DiO_1_-_.js} +1 -1
- package/dist/index.html +1 -1
- package/dist/mini-chat.html +1 -1
- package/dist/mobile.html +1 -1
- package/package.json +1 -1
- package/server/index.js +0 -15
- package/server/lib/fs/routes.js +28 -2
- package/server/lib/opencode/env-runtime.js +20 -158
- package/server/lib/opencode/env-runtime.test.js +38 -11
- package/server/lib/opencode/lifecycle.js +5 -24
- package/server/lib/opencode/lifecycle.test.js +0 -2
- package/server/lib/opencode/network-runtime.js +1 -1
- package/server/lib/opencode/routes.js +1 -1
- package/dist/assets/OnboardingScreen-B1Ft9kmW.js +0 -1
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import{R as j,c as W,c6 as Ve,c7 as Ue,j as a,c8 as We,c9 as qe,ca as Ke,cb as Ge,cc as Ze,cd as Xe,$ as Ye}from"./vendor-.bun-TPgXvEwq.js";import{a as Se,b as Re,T as pe,u as le,cf as Le,m as A,dP as Je,q as ye,fo as Qe,fp as Te,az as et,aI as be,fq as tt,H as U,fr as rt,ay as ge,fs as nt,ft as ot,c9 as st,fu as at,o as se,t as _e}from"./useAppFontEffects-
|
|
1
|
+
import{R as j,c as W,c6 as Ve,c7 as Ue,j as a,c8 as We,c9 as qe,ca as Ke,cb as Ge,cc as Ze,cd as Xe,$ as Ye}from"./vendor-.bun-TPgXvEwq.js";import{a as Se,b as Re,T as pe,u as le,cf as Le,m as A,dP as Je,q as ye,fo as Qe,fp as Te,az as et,aI as be,fq as tt,H as U,fr as rt,ay as ge,fs as nt,ft as ot,c9 as st,fu as at,o as se,t as _e}from"./useAppFontEffects-hYm-4PtP.js";import{b as lt}from"./index-D9t9eCUC.js";const ve=()=>{const t=W.c(4),e=Je();let n;t[0]===Symbol.for("react.memo_cache_sentinel")?(n=ye(!1),t[0]=n):n=t[0];const s=n;let o;t[1]===Symbol.for("react.memo_cache_sentinel")?(o=ye(!0),t[1]=o):o=t[1];const r=o;let l;return t[2]!==e?.currentTheme?(l=e?.currentTheme??(typeof window<"u"&&window.matchMedia("(prefers-color-scheme: dark)").matches?r:s),t[2]=e?.currentTheme,t[3]=l):l=t[3],l},Me=t=>{const e=W.c(4),{containerRef:n,enabled:s}=t;let o,r;e[0]!==n||e[1]!==s?(o=()=>{if(s===!1)return;const l=n.current;if(!l)return;const d=qt;return l.addEventListener("click",d),()=>{l.removeEventListener("click",d)}},r=[n,s],e[0]=n,e[1]=s,e[2]=o,e[3]=r):(o=e[2],r=e[3]),j.useEffect(o,r)},it=t=>{const e=W.c(5),{href:n}=t,[s,o]=j.useState(!1);let r;e[0]!==n?(r=rt(n),e[0]=n,e[1]=r):r=e[1];const l=r;if(!l||s)return null;let d;e[2]===Symbol.for("react.memo_cache_sentinel")?(d=()=>o(!0),e[2]=d):d=e[2];let i;return e[3]!==l?(i=a.jsx("span",{className:"mr-1 inline-flex size-[18px] items-center justify-center rounded border border-[var(--border)] bg-[var(--interactive-hover)] align-middle",children:a.jsx("img",{src:l,alt:"","aria-hidden":"true",loading:"lazy",decoding:"async",className:"size-3.5 rounded-sm",onError:d})}),e[3]=l,e[4]=i):i=e[4],i},Fe=t=>{const e=[],n=[],s=t.querySelector("thead");s&&s.querySelectorAll("th").forEach(l=>e.push(l.innerText.trim()));const o=t.querySelector("tbody");return o&&o.querySelectorAll("tr").forEach(l=>{const d=l.querySelectorAll("td"),i=[];d.forEach(c=>i.push(c.innerText.trim())),n.push(i)}),{headers:e,rows:n}},Ae=({headers:t,rows:e})=>{const n=o=>o.includes(",")||o.includes('"')||o.includes(`
|
|
2
2
|
`)?`"${o.replace(/"/g,'""')}"`:o,s=[];return t.length>0&&s.push(t.map(n).join(",")),e.forEach(o=>s.push(o.map(n).join(","))),s.join(`
|
|
3
3
|
`)},ct=({headers:t,rows:e})=>{const n=o=>o.replace(/\t/g,"\\t").replace(/\n/g,"\\n").replace(/\r/g,"\\r"),s=[];return t.length>0&&s.push(t.map(n).join(" ")),e.forEach(o=>s.push(o.map(n).join(" "))),s.join(`
|
|
4
4
|
`)},dt=({headers:t,rows:e})=>{if(t.length===0)return"";const n=o=>o.replace(/\\/g,"\\\\").replace(/\|/g,"\\|"),s=[];return s.push(`| ${t.map(n).join(" | ")} |`),s.push(`| ${t.map(()=>"---").join(" | ")} |`),e.forEach(o=>{const r=t.map((l,d)=>n(o[d]||""));s.push(`| ${r.join(" | ")} |`)}),s.join(`
|
|
@@ -1 +1 @@
|
|
|
1
|
-
import{c as N,R as k,j as n,b4 as D,b2 as C,b3 as I,b0 as M,a_ as S}from"./vendor-.bun-TPgXvEwq.js";import{u as z,m as w,H as O}from"./useAppFontEffects-
|
|
1
|
+
import{c as N,R as k,j as n,b4 as D,b2 as C,b3 as I,b0 as M,a_ as S}from"./vendor-.bun-TPgXvEwq.js";import{u as z,m as w,H as O}from"./useAppFontEffects-hYm-4PtP.js";import{M as P}from"./main-DIwL7PaU.js";import"./index-D9t9eCUC.js";import"./NewWorktreeDialog-C6394QE9.js";import"./mobileLayoutPreference-Dio-WWkI.js";import"./SessionSwitcherDropdown-BMN9gaXo.js";const $=R=>{const e=N.c(33),{open:y,onOpenChange:t,initialPrompt:v}=R,i=k.useId(),{t:o}=z(),_=B;let s;e[0]!==t?(s=j=>{!j&&_()||t(j)},e[0]=t,e[1]=s):s=e[1];let x;e[2]===Symbol.for("react.memo_cache_sentinel")?(x=n.jsx(D,{className:w("fixed inset-0 z-50 bg-black/50 dark:bg-black/75","transition-opacity duration-150 ease-out","data-[starting-style]:opacity-0 data-[ending-style]:opacity-0")}),e[2]=x):x=e[2];let g;e[3]===Symbol.for("react.memo_cache_sentinel")?(g=w("relative pointer-events-auto","w-[90vw] max-w-[720px] h-[680px] max-h-[85vh]","flex flex-col rounded-xl border shadow-none overflow-hidden origin-center","bg-background","transition-all duration-150 ease-out","data-[starting-style]:opacity-0 data-[starting-style]:scale-[0.98]","data-[ending-style]:opacity-0 data-[ending-style]:scale-[0.98]"),e[3]=g):g=e[3];let a;e[4]!==t?(a=()=>t(!1),e[4]=t,e[5]=a):a=e[5];let l;e[6]!==o?(l=o("multiRun.window.actions.closeAria"),e[6]=o,e[7]=l):l=e[7];let h;e[8]===Symbol.for("react.memo_cache_sentinel")?(h=n.jsx(O,{name:"close",className:"h-5 w-5"}),e[8]=h):h=e[8];let r;e[9]!==a||e[10]!==l?(r=n.jsx("div",{className:"absolute right-0.5 top-0.5 z-50",children:n.jsx("button",{type:"button",onClick:a,"aria-label":l,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:h})}),e[9]=a,e[10]=l,e[11]=r):r=e[11];let c;e[12]!==o?(c=o("multiRun.window.description"),e[12]=o,e[13]=c):c=e[13];let d;e[14]!==i||e[15]!==c?(d=n.jsx(C,{id:i,className:"sr-only",children:c}),e[14]=i,e[15]=c,e[16]=d):d=e[16];let u,m;e[17]!==t?(u=()=>t(!1),m=()=>t(!1),e[17]=t,e[18]=u,e[19]=m):(u=e[18],m=e[19]);let f;e[20]!==v||e[21]!==u||e[22]!==m?(f=n.jsx(P,{initialPrompt:v,onCreated:u,onCancel:m,isWindowed:!0}),e[20]=v,e[21]=u,e[22]=m,e[23]=f):f=e[23];let p;e[24]!==i||e[25]!==f||e[26]!==r||e[27]!==d?(p=n.jsxs(I,{children:[x,n.jsx("div",{className:"fixed inset-0 z-50 flex items-center justify-center pointer-events-none",children:n.jsxs(M,{"aria-describedby":i,className:g,children:[r,d,f]})})]}),e[24]=i,e[25]=f,e[26]=r,e[27]=d,e[28]=p):p=e[28];let b;return e[29]!==y||e[30]!==s||e[31]!==p?(b=n.jsx(S,{open:y,onOpenChange:s,children:p}),e[29]=y,e[30]=s,e[31]=p,e[32]=b):b=e[32],b};function B(){return typeof document>"u"?!1:!!document.querySelector('[data-slot="dropdown-menu-content"][data-open], [data-slot="select-content"][data-open]')}export{$ as MultiRunWindow};
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import{aa as Kl,c as it,ab as _l,j as t,H as ke,R as l,b as Ws,I as Ln,e as br,L as yr,T as bs,ac as Wl,ad as Hl,ae as Gl,u as ql,g as Jl,k as Ql,o as Yl,C as Xl,S as Zl,af as ec,a5 as tc,D as sc,m as nc,ag as ac,X as Ts,ah as rc,ai as yn,aj as zr,ak as ic,al as oc,am as ka,an as lc,ao as cc,ap as dc,aq as $r,ar as ma,as as Br,f as ta,at as mc,au as _o,av as Wo,aw as uc,ax as Ur,ay as pc,az as gc,aA as hc,aB as fc,aC as Vr,aD as Ae,aE as $n,aF as xc,aG as bc,aH as yc,aI as vc,aJ as jc,aK as wc,aL as Ho,a6 as Nc,aM as kc,aN as Sc,aO as Cc}from"./vendor-.bun-TPgXvEwq.js";import{dP as ha,q as ua,r as pa,dw as Pc,dQ as Ic,dR as Dc,H as F,dS as Ac,B as W,u as ot,y as Cs,dT as Mc,bN as vr,dU as sa,dV as na,dW as aa,D as Qt,X as ns,aI as as,m as ge,c7 as Ec,as as rs,au as is,c6 as Rc,av as os,aY as jr,dX as Tc,dY as un,bH as Kt,b4 as Lt,b3 as Ot,b1 as Bt,b2 as zt,bt as Vt,bQ as Gt,I as nt,dZ as Tn,ap as Ht,t as U,ay as ys,z as gs,dq as Fc,bI as St,bJ as Ct,bK as Rt,bL as Pt,bM as dt,bh as ls,ai as vt,aj as jt,ak as kt,aZ as wr,d_ as xn,bi as Nt,d$ as Go,e0 as Lc,e1 as Oc,e2 as Nr,e3 as Ks,e4 as gn,a$ as qo,az as Ls,o as Xs,T as Oe,e5 as Js,e6 as zc,e7 as $c,e8 as Bc,al as wt,ax as Is,e9 as Uc,ea as Vc,eb as Kc,ec as Zs,p as fa,cb as Kr,v as Za,bY as Jo,E as _c,P as Qo,G as Yo,ce as Wc,Q as _r,db as Hc,dn as Xo,de as Gc,cF as qc,ed as Wr,ee as Jc,ef as Qc,eg as Hr,eh as Yc,ei as Xc,ej as Zc,ek as ed,am as hs,aA as td,el as sd,K as nd,L as ad,a as kr,aJ as Gr,em as qr,en as Jr,aM as wn,eo as Sa,ep as rd,eq as id,R as ct,aC as hn,dC as Mn,aD as Sr,bz as od,er as Ca,es as Qr,et as ld,eu as cd,ev as dd,ew as md,df as Cr,c0 as ud,ex as Pa,U as Fs,ey as pd,b$ as gd,ez as Yr,cm as Ys,eA as hd,eB as Xr,eC as Zr,eD as ei,eE as ti,eF as Ia,cd as Zo,eG as si,eH as fd,eI as ni,eJ as xd,eK as bd,an as xa,eL as yd,eM as vd,eN as jd,eO as wd,eP as Nd,eQ as Da,eR as ai,eS as kd,eT as Sd,eU as Cd,eV as Pd,eW as Id,eX as Aa,eY as Dd,eZ as ri,e_ as In,be as el,e$ as Ad,f0 as Md,f1 as Ed,dN as Rd,f2 as Td,aV as ii,f3 as dn,aU as Fd,f4 as Ld,f5 as oi,f6 as li,$ as Bs,F as Od,S as zd,f7 as $d,cj as Bn,f8 as ci,f9 as Bd,fa as Ud,fb as Vd,bl as er,bm as tr,bn as sr,bo as nr,bp as Rs,bq as Ss,bR as pn,M as En,fc as di,fd as tl,bT as Kd,dj as _d,f as Wd,fe as Ma,ff as Un,bc as Hd,b9 as Vn,bX as Gd,fg as qd,fh as Jd,fi as Qd,fj as Yd}from"./useAppFontEffects-DEZpweZZ.js";import{b as pt,a as Fn,j as Xd,s as Zd}from"./index-D9t9eCUC.js";import{g as em,s as tm}from"./mobileLayoutPreference-Dio-WWkI.js";function sm(){return new Worker(Kl,{type:"module"})}const nm=["typescript","javascript","tsx","jsx","json","markdown"],ar={unified:{poolSize:1,totalASTLRUCacheSize:24,lineDiffType:"none"},split:{poolSize:2,totalASTLRUCacheSize:56,lineDiffType:"word-alt"}};let mi,ui;const pi=s=>{const e=ar[s],n=new _l({workerFactory:sm,poolSize:e.poolSize,totalASTLRUCacheSize:e.totalASTLRUCacheSize},{theme:{light:"pierre-light",dark:"pierre-dark"},langs:nm,lineDiffType:e.lineDiffType,preferredHighlighter:"shiki-wasm"});return n.initialize(),n},am=s=>{if(!(typeof window>"u"))return s==="split"?(ui??=pi("split"),ui):(mi??=pi("unified"),mi)},rm=s=>{const e=it.c(7),{children:n,renderTheme:a}=s,r=rr("unified"),i=rr("split");let o,c;e[0]!==a||e[1]!==i||e[2]!==r?(o=()=>{r&&r.setRenderOptions({theme:a,lineDiffType:ar.unified.lineDiffType}),i&&i.setRenderOptions({theme:a,lineDiffType:ar.split.lineDiffType})},c=[a,i,r],e[0]=a,e[1]=i,e[2]=r,e[3]=o,e[4]=c):(o=e[3],c=e[4]),ke.useEffect(o,c);let d;return e[5]!==n?(d=t.jsx(t.Fragment,{children:n}),e[5]=n,e[6]=d):d=e[6],d},Qb=s=>{const e=it.c(11),{children:n}=s,a=ha();let r,i;if(e[0]!==a?.availableThemes||e[1]!==a?.darkThemeId||e[2]!==a?.lightThemeId){const f=ua(!1),g=ua(!0),u=a?.lightThemeId??f.metadata.id,m=a?.darkThemeId??g.metadata.id;i=a?.availableThemes.find(k=>k.metadata.id===u)??f,r=a?.availableThemes.find(k=>k.metadata.id===m)??g,pa(i),pa(r),e[0]=a?.availableThemes,e[1]=a?.darkThemeId,e[2]=a?.lightThemeId,e[3]=r,e[4]=i}else r=e[3],i=e[4];let o;e[5]!==r.metadata.id||e[6]!==i.metadata.id?(o={light:i.metadata.id,dark:r.metadata.id},e[5]=r.metadata.id,e[6]=i.metadata.id,e[7]=o):o=e[7];const c=o;let d;return e[8]!==n||e[9]!==c?(d=t.jsx(rm,{renderTheme:c,children:n}),e[8]=n,e[9]=c,e[10]=d):d=e[10],d},rr=s=>{const e=it.c(2),n=s===void 0?"unified":s;let a;return e[0]!==n?(a=am(n),e[0]=n,e[1]=a):a=e[1],a};class im extends l.Component{constructor(e){super(e),this.state={hasError:!1}}static getDerivedStateFromError(e){return{hasError:!0,error:e}}componentDidCatch(e,n){this.setState({error:e,errorInfo:n})}handleReset=()=>{this.setState({hasError:!1,error:void 0,errorInfo:void 0})};render(){return this.state.hasError?t.jsx("div",{className:"flex items-center justify-center min-h-screen p-4",children:t.jsxs(Pc,{className:"w-full max-w-md",children:[t.jsx(Ic,{className:"text-center",children:t.jsxs(Dc,{className:"flex items-center justify-center gap-2 text-destructive",children:[t.jsx(F,{name:"chat-3",className:"h-5 w-5"}),this.props.texts.title]})}),t.jsxs(Ac,{className:"space-y-4",children:[t.jsx("p",{className:"text-sm text-muted-foreground text-center",children:this.props.texts.description}),this.props.sessionId&&t.jsxs("div",{className:"text-xs text-muted-foreground text-center",children:[this.props.texts.sessionLabel,": ",this.props.sessionId]}),this.state.error&&t.jsxs("details",{className:"text-xs font-mono bg-muted p-3 rounded",children:[t.jsx("summary",{className:"cursor-pointer hover:bg-interactive-hover/80",children:this.props.texts.detailsSummary}),t.jsx("pre",{className:"mt-2 max-h-48 overflow-auto",children:this.state.error.toString()})]}),t.jsx("div",{className:"flex gap-2",children:t.jsxs(W,{onClick:this.handleReset,variant:"outline",className:"flex-1",children:[t.jsx(F,{name:"restart",className:"h-4 w-4 mr-2"}),this.props.texts.resetAction]})}),t.jsx("div",{className:"text-xs text-muted-foreground text-center",children:this.props.texts.persistentHint})]})]})}):this.props.children}}function om(s){const e=it.c(22),{t:n}=ot();let a;e[0]!==n?(a=n("chat.errorBoundary.title"),e[0]=n,e[1]=a):a=e[1];let r;e[2]!==n?(r=n("chat.errorBoundary.description"),e[2]=n,e[3]=r):r=e[3];let i;e[4]!==n?(i=n("chat.errorBoundary.sessionLabel"),e[4]=n,e[5]=i):i=e[5];let o;e[6]!==n?(o=n("chat.errorBoundary.detailsSummary"),e[6]=n,e[7]=o):o=e[7];let c;e[8]!==n?(c=n("chat.errorBoundary.resetAction"),e[8]=n,e[9]=c):c=e[9];let d;e[10]!==n?(d=n("chat.errorBoundary.persistentHint"),e[10]=n,e[11]=d):d=e[11];let f;e[12]!==a||e[13]!==r||e[14]!==i||e[15]!==o||e[16]!==c||e[17]!==d?(f={title:a,description:r,sessionLabel:i,detailsSummary:o,resetAction:c,persistentHint:d},e[12]=a,e[13]=r,e[14]=i,e[15]=o,e[16]=c,e[17]=d,e[18]=f):f=e[18];let g;return e[19]!==s||e[20]!==f?(g=t.jsx(im,{...s,texts:f}),e[19]=s,e[20]=f,e[21]=g):g=e[21],g}const Yb=s=>{const e=it.c(5),{readOnly:n}=s,a=n===void 0?!1:n,i=Cs(lm)||void 0;let o;e[0]!==a?(o=t.jsx(Mc,{readOnly:a}),e[0]=a,e[1]=o):o=e[1];let c;return e[2]!==i||e[3]!==o?(c=t.jsx(om,{sessionId:i,children:o}),e[2]=i,e[3]=o,e[4]=c):c=e[4],c};function lm(s){return s.currentSessionId}const Kn=()=>{try{const e=Qt.getState().getActiveProject?.();if(e?.path?.trim())return e.path.trim();const n=ns.getDirectory();if(n?.trim())return n.trim()}catch(s){console.warn("[McpConfigStore] Error resolving config directory:",s)}return null},gi=s=>s?Object.entries(s).map(([e,n])=>({key:e,value:n})):[],hi=s=>{const e=s.filter(n=>n.key.trim());if(e.length!==0)return Object.fromEntries(e.map(n=>[n.key.trim(),n.value]))},_n=s=>typeof s!="string"?void 0:s.trim()||void 0,Ea=800,cm=5e3,dm="__default__",ir=new Map,Ra=new Map,sl=s=>s?.trim()||dm,Ta=s=>{ir.delete(sl(s))},Pr=Ws()(Ln(br((s,e)=>({mcpServers:[],selectedMcpName:null,isLoading:!1,mcpDraft:null,setSelectedMcp:n=>s({selectedMcpName:n}),setMcpDraft:n=>s({mcpDraft:n}),loadMcpConfigs:async n=>{const a=Kn(),r=sl(a),i=Date.now(),o=ir.get(r)??0,c=e().mcpServers.length>0;if(!n?.force&&c&&i-o<cm)return!0;const d=Ra.get(r);if(!n?.force&&d)return d;const f=(async()=>{s({isLoading:!0});try{const g=a?`?directory=${encodeURIComponent(a)}`:"",u=await pt(`/api/config/mcp${g}`,{headers:a?{"x-opencode-directory":a}:void 0});if(!u.ok)throw new Error("Failed to load MCP configs");const m=await u.json();return s({mcpServers:m,isLoading:!1}),ir.set(r,Date.now()),!0}catch(g){return console.error("[McpConfigStore] Failed to load MCP configs:",g),s({isLoading:!1}),!1}})();Ra.set(r,f);try{return await f}finally{Ra.delete(r)}},createMcp:async n=>{sa("Creating MCP server configuration…");let a=!1;try{const r=fi(n),i=Kn(),o=i?`?directory=${encodeURIComponent(i)}`:"",c=await pt(`/api/config/mcp/${encodeURIComponent(n.name)}${o}`,{method:"POST",headers:{"Content-Type":"application/json",...i?{"x-opencode-directory":i}:{}},body:JSON.stringify(r)}),d=await c.json().catch(()=>null);if(!c.ok)throw new Error(d?.error||"Failed to create MCP server");return Ta(i),d?.requiresReload?(a=!0,await na({message:d.message,delayMs:d.reloadDelayMs??Ea,scopes:["all"]}),await e().loadMcpConfigs({force:!0}),{ok:!0,reloadFailed:d?.reloadFailed===!0,message:d?.message,warning:d?.warning}):(await e().loadMcpConfigs({force:!0}),{ok:!0,reloadFailed:d?.reloadFailed===!0,message:d?.message,warning:d?.warning})}catch(r){return console.error("[McpConfigStore] Failed to create MCP:",r),{ok:!1}}finally{a||aa()}},updateMcp:async(n,a)=>{sa("Updating MCP server configuration…");let r=!1;try{const i=fi(a),o=Kn(),c=o?`?directory=${encodeURIComponent(o)}`:"",d=await pt(`/api/config/mcp/${encodeURIComponent(n)}${c}`,{method:"PATCH",headers:{"Content-Type":"application/json",...o?{"x-opencode-directory":o}:{}},body:JSON.stringify(i)}),f=await d.json().catch(()=>null);if(!d.ok)throw new Error(f?.error||"Failed to update MCP server");return Ta(o),f?.requiresReload?(r=!0,await na({message:f.message,delayMs:f.reloadDelayMs??Ea,scopes:["all"]}),await e().loadMcpConfigs({force:!0}),{ok:!0,reloadFailed:f?.reloadFailed===!0,message:f?.message,warning:f?.warning}):(await e().loadMcpConfigs({force:!0}),{ok:!0,reloadFailed:f?.reloadFailed===!0,message:f?.message,warning:f?.warning})}catch(i){throw console.error("[McpConfigStore] Failed to update MCP:",i),i}finally{r||aa()}},deleteMcp:async n=>{sa("Deleting MCP server configuration…");let a=!1;try{const r=Kn(),i=r?`?directory=${encodeURIComponent(r)}`:"",o=await pt(`/api/config/mcp/${encodeURIComponent(n)}${i}`,{method:"DELETE",headers:r?{"x-opencode-directory":r}:void 0}),c=await o.json().catch(()=>null);if(!o.ok)throw new Error(c?.error||"Failed to delete MCP server");return Ta(r),c?.requiresReload&&(a=!0,await na({message:c.message,delayMs:c.reloadDelayMs??Ea,scopes:["all"]})),e().selectedMcpName===n&&s({selectedMcpName:null}),await e().loadMcpConfigs({force:!0}),{ok:!0,reloadFailed:c?.reloadFailed===!0,message:c?.message,warning:c?.warning}}catch(r){return console.error("[McpConfigStore] Failed to delete MCP:",r),{ok:!1}}finally{a||aa()}},getMcpByName:n=>e().mcpServers.find(a=>a.name===n)}),{name:"mcp-config-store",storage:yr(()=>vr()),partialize:s=>({selectedMcpName:s.selectedMcpName})}),{name:"mcp-config-store"}));function fi(s){const e={};if(s.scope!==void 0&&(e.scope=s.scope),s.type!==void 0&&(e.type=s.type),(s.type==="local"||s.command!==void 0)&&(e.command=(s.command??[]).filter(n=>n.trim())),(s.type==="remote"||s.url!==void 0)&&(e.url=s.url?.trim()??""),s.environment!==void 0&&(e.environment=hi(s.environment)??{}),s.headers!==void 0&&(e.headers=hi(s.headers)??{}),s.oauthEnabled!==void 0||s.oauthClientId!==void 0||s.oauthClientSecret!==void 0||s.oauthScope!==void 0||s.oauthRedirectUri!==void 0)if(s.oauthEnabled===!1)e.oauth=!1;else{const n={clientId:_n(s.oauthClientId),clientSecret:_n(s.oauthClientSecret),scope:_n(s.oauthScope),redirectUri:_n(s.oauthRedirectUri)};n.clientId||n.clientSecret||n.scope||n.redirectUri?e.oauth=n:s.oauthEnabled?e.oauth={}:e.oauth=!1}if(s.timeout!==void 0){const n=Number(s.timeout);Number.isFinite(n)&&n>0?e.timeout=n:e.timeout=null}return s.enabled!==void 0&&(e.enabled=s.enabled),e}const nl=s=>s.replace(/[-_]/g," ").replace(/\b\w/g,e=>e.toUpperCase()),On=s=>{const e=it.c(39),{className:n}=s,{t:a}=ot(),r=Qt(mm),i=Qt(um),o=Qt(pm),c=as();let d;e[0]!==r?(d=[...r].sort(gm),e[0]=r,e[1]=d):d=e[1];const f=d;let g;e:{if(f.length===0){g=null;break e}let O;e[2]!==i||e[3]!==f?(O=f.find(T=>T.id===i)??f[0],e[2]=i,e[3]=f,e[4]=O):O=e[4],g=O}const u=g;if(c||f.length===0)return null;let m;e[5]!==u||e[6]!==a?(m=u?.label&&u.label.trim().length>0?u.label:u?.path.split("/").filter(Boolean).pop()||u?.path||a("settings.shared.projectSelector.fallbackProject"),e[5]=u,e[6]=a,e[7]=m):m=e[7];const k=m;let h;e[8]!==k?(h=nl(k),e[8]=k,e[9]=h):h=e[9];const v=h;let b;e[10]!==n?(b=ge(n),e[10]=n,e[11]=b):b=e[11];let R;e[12]!==a?(R=a("settings.shared.projectSelector.switchProjectAria"),e[12]=a,e[13]=R):R=e[13];let S;e[14]!==a?(S=a("settings.shared.projectSelector.switchProjectTitle"),e[14]=a,e[15]=S):S=e[15];let j,E;e[16]===Symbol.for("react.memo_cache_sentinel")?(j=ge("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"),E=t.jsx(F,{name:"folder",className:"h-4 w-4 opacity-70"}),e[16]=j,e[17]=E):(j=e[16],E=e[17]);let P;e[18]!==v?(P=t.jsx("span",{className:"min-w-0 flex-1 truncate typography-ui-label font-medium",children:v}),e[18]=v,e[19]=P):P=e[19];let N;e[20]===Symbol.for("react.memo_cache_sentinel")?(N=t.jsx(F,{name:"arrow-down-s",className:"size-4 opacity-50"}),e[20]=N):N=e[20];let x;e[21]!==P||e[22]!==R||e[23]!==S?(x=t.jsx(rs,{asChild:!0,children:t.jsxs("button",{type:"button","aria-label":R,title:S,className:j,children:[E,P,N]})}),e[21]=P,e[22]=R,e[23]=S,e[24]=x):x=e[24];const y=u?.id??"";let z;e[25]!==o?(z=O=>{O&&o(O)},e[25]=o,e[26]=z):z=e[26];let L;e[27]!==f?(L=f.map(hm),e[27]=f,e[28]=L):L=e[28];let I;e[29]!==y||e[30]!==z||e[31]!==L?(I=t.jsx(is,{align:"start",className:"w-auto",children:t.jsx(Rc,{value:y,onValueChange:z,children:L})}),e[29]=y,e[30]=z,e[31]=L,e[32]=I):I=e[32];let A;e[33]!==x||e[34]!==I?(A=t.jsxs(os,{children:[x,I]}),e[33]=x,e[34]=I,e[35]=A):A=e[35];let w;return e[36]!==A||e[37]!==b?(w=t.jsx("div",{className:b,children:A}),e[36]=A,e[37]=b,e[38]=w):w=e[38],w};function mm(s){return s.projects}function um(s){return s.activeProjectId}function pm(s){return s.setActiveProject}function gm(s,e){return(s.label||s.path).localeCompare(e.label||e.path)}function hm(s){const e=s.label?.trim()?s.label.trim():s.path.split("/").filter(Boolean).pop()||s.path,n=nl(e);return t.jsx(Ec,{value:s.id,children:t.jsx("span",{className:"min-w-0 truncate typography-ui",children:n})},s.id)}function fm(s,e){return`opencode:sidebar-group:${s}:${e}`}const or=s=>{const e=it.c(33),{label:n,count:a,storageKey:r,defaultExpanded:i,children:o}=s,c=i===void 0?!0:i;let d;e[0]!==n||e[1]!==r?(d=fm(r,n),e[0]=n,e[1]=r,e[2]=d):d=e[2];const f=d,g=l.useId();let u;e[3]!==c||e[4]!==f?(u=()=>{try{const I=localStorage.getItem(f);if(I!==null)return I==="true"}catch{}return c},e[3]=c,e[4]=f,e[5]=u):u=e[5];const[m,k]=ke.useState(u);let h,v;e[6]!==m||e[7]!==f?(h=()=>{try{localStorage.setItem(f,String(m))}catch{}},v=[f,m],e[6]=m,e[7]=f,e[8]=h,e[9]=v):(h=e[8],v=e[9]),ke.useEffect(h,v);let b;e[10]===Symbol.for("react.memo_cache_sentinel")?(b=()=>k(xm),e[10]=b):b=e[10];let R;e[11]===Symbol.for("react.memo_cache_sentinel")?(R=ge("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]=R):R=e[11];const S=!m&&"-rotate-90";let j;e[12]!==S?(j=ge("h-3.5 w-3.5 flex-shrink-0 transition-transform duration-200",S),e[12]=S,e[13]=j):j=e[13];let E;e[14]!==j?(E=t.jsx(F,{name:"arrow-down-s",className:j}),e[14]=j,e[15]=E):E=e[15];let P;e[16]!==n?(P=t.jsx("span",{className:"flex-1 truncate",children:n}),e[16]=n,e[17]=P):P=e[17];let N;e[18]!==a?(N=t.jsx("span",{className:"ml-1 tabular-nums opacity-60",children:a}),e[18]=a,e[19]=N):N=e[19];let x;e[20]!==g||e[21]!==m||e[22]!==E||e[23]!==P||e[24]!==N?(x=t.jsxs("button",{type:"button",onClick:b,"aria-expanded":m,"aria-controls":g,className:R,children:[E,P,N]}),e[20]=g,e[21]=m,e[22]=E,e[23]=P,e[24]=N,e[25]=x):x=e[25];const y=!m;let z;e[26]!==o||e[27]!==g||e[28]!==y?(z=t.jsx("div",{id:g,hidden:y,className:"mt-0.5 space-y-0.5 ml-2 pl-3 border-l-2 border-[var(--interactive-border)]",children:o}),e[26]=o,e[27]=g,e[28]=y,e[29]=z):z=e[29];let L;return e[30]!==x||e[31]!==z?(L=t.jsxs("div",{children:[x,z]}),e[30]=x,e[31]=z,e[32]=L):L=e[32],L};function xm(s){return!s}const bm=s=>{if(!Array.isArray(s))return[];const e=[];for(const n of s){if(!n||typeof n!="object")continue;const a=n;typeof a.permission!="string"||typeof a.pattern!="string"||typeof a.action!="string"||a.action!=="allow"&&a.action!=="ask"&&a.action!=="deny"||e.push({permission:a.permission,pattern:a.pattern,action:a.action})}return e},ym=s=>{const e=new Map;for(const n of s)!n.permission||n.permission==="invalid"||n.pattern&&e.set(`${n.permission}::${n.pattern}`,n);return Array.from(e.values())},xi=s=>{const e=ym(bm(s));if(e.length===0)return;const n={};for(const r of e)r.permission&&((n[r.permission]||={})[r.pattern]=r.action);const a={};for(const[r,i]of Object.entries(n)){const o=Object.keys(i);if(o.length===1&&o[0]==="*"){a[r]=i["*"];continue}a[r]=i}return Object.keys(a).length>0?a:void 0},vm=({onItemSelect:s})=>{const{t:e}=ot(),[n,a]=l.useState(null),[r,i]=l.useState(""),[o,c]=l.useState(null),[d,f]=l.useState(null),[g,u]=l.useState(!1),[m,k]=l.useState(null),{selectedAgentName:h,agents:v,setSelectedAgent:b,setAgentDraft:R,createAgent:S,deleteAgent:j,loadAgents:E}=jr(bs(D=>({selectedAgentName:D.selectedAgentName,agents:D.agents,setSelectedAgent:D.setSelectedAgent,setAgentDraft:D.setAgentDraft,createAgent:D.createAgent,deleteAgent:D.deleteAgent,loadAgents:D.loadAgents})));l.useEffect(()=>{E()},[E]);const P="bg-background",N=()=>{const D="new-agent";let K=D,C=1;for(;v.some(H=>H.name===K);)K=`${D}-${C}`,C++;R({name:K,scope:"user"}),b(K),s?.()},x=async D=>{if(un(D)){U.error(e("settings.agents.sidebar.toast.builtInCannotDelete"));return}c(D),f("delete")},y=async D=>{un(D)&&(c(D),f("reset"))},z=()=>{c(null),f(null)},L=async()=>{if(!o||!d)return;u(!0),await j(o.name)?(d==="delete"?U.success(e("settings.agents.sidebar.toast.agentDeleted",{name:o.name})):U.success(e("settings.agents.sidebar.toast.agentReset",{name:o.name})),z()):d==="delete"?U.error(e("settings.agents.sidebar.toast.deleteFailed")):U.error(e("settings.agents.sidebar.toast.resetFailed")),u(!1)},I=D=>{const K=D.name;let C=1,H=`${K}-copy`;for(;v.some(re=>re.name===H);)C++,H=`${K}-copy-${C}`;const G=D,se=D.model?.providerID&&D.model?.modelID?`${D.model.providerID}/${D.model.modelID}`:null,oe=D;R({name:H,scope:G.scope||"user",description:D.description,model:se,temperature:D.temperature,top_p:D.topP,prompt:D.prompt,mode:D.mode,permission:xi(D.permission),disable:oe.disable}),b(H)},A=D=>{i(D.name),a(D)},w=async()=>{if(!n)return;const D=r.trim().replace(/\s+/g,"-");if(!D){U.error(e("settings.agents.sidebar.toast.agentNameRequired"));return}if(D===n.name){a(null);return}if(v.some(G=>G.name===D)){U.error(e("settings.agents.sidebar.toast.agentExists"));return}const K=n.model?.providerID&&n.model?.modelID?`${n.model.providerID}/${n.model.modelID}`:null,C=n;await S({name:D,description:n.description,model:K,temperature:n.temperature,top_p:n.topP,prompt:n.prompt,mode:n.mode,permission:xi(n.permission),disable:C.disable,scope:C.scope})?await j(n.name)?(U.success(`Agent renamed to "${D}"`),b(D)):U.error(e("settings.agents.sidebar.toast.removeOldAfterRenameFailed")):U.error(e("settings.agents.sidebar.toast.renameFailed")),a(null)},O=D=>{switch(D){case"primary":return t.jsx(F,{name:"ai-agent",className:"h-3 w-3 text-primary"});case"all":return t.jsx(F,{name:"ai-agent-fill",className:"h-3 w-3 text-primary"});case"subagent":return t.jsx(F,{name:"robot",className:"h-3 w-3 text-primary"});default:return null}},T=v.filter(D=>!Tc(D)),_=T.filter(un),V=T.filter(D=>!un(D)),{groupedCustomAgents:J,ungroupedCustomAgents:B}=ke.useMemo(()=>{const D={},K=[];for(const H of V){const G=H;G.group?(D[G.group]||(D[G.group]=[]),D[G.group].push(H)):K.push(H)}return{groupedCustomAgents:Object.keys(D).sort((H,G)=>H.localeCompare(G)).map(H=>({name:H,agents:D[H]})),ungroupedCustomAgents:K}},[V]);return t.jsxs("div",{className:ge("flex h-full flex-col",P),children:[t.jsxs("div",{className:"border-b px-3 pt-4 pb-3",children:[t.jsx("h2",{className:"text-base font-semibold text-foreground mb-3",children:e("settings.agents.sidebar.title")}),t.jsx(On,{className:"mb-3"}),t.jsxs("div",{className:"flex items-center justify-between gap-2",children:[t.jsx("span",{className:"typography-meta text-muted-foreground",children:e("settings.agents.sidebar.total",{count:T.length})}),t.jsx(W,{size:"sm",variant:"ghost",className:"h-7 w-7 px-0 -my-1 text-muted-foreground",onClick:N,children:t.jsx(F,{name:"add",className:"h-3.5 w-3.5"})})]})]}),t.jsx(Kt,{outerClassName:"flex-1 min-h-0",className:"space-y-1 px-3 py-2 overflow-x-hidden",children:T.length===0?t.jsxs("div",{className:"py-12 px-4 text-center text-muted-foreground",children:[t.jsx(F,{name:"robot-2",className:"mx-auto mb-3 h-10 w-10 opacity-50"}),t.jsx("p",{className:"typography-ui-label font-medium",children:e("settings.agents.sidebar.empty.title")}),t.jsx("p",{className:"typography-meta mt-1 opacity-75",children:e("settings.agents.sidebar.empty.description")})]}):t.jsxs(t.Fragment,{children:[_.length>0&&t.jsxs(t.Fragment,{children:[t.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(D=>t.jsx(Fa,{agent:D,isSelected:h===D.name,onSelect:()=>{b(D.name),s?.()},onReset:()=>y(D),onDuplicate:()=>I(D),getAgentModeIcon:O,isMenuOpen:m===D.name,onMenuOpenChange:K=>k(K?D.name:null)},D.name))]}),V.length>0&&t.jsxs(t.Fragment,{children:[t.jsx("div",{className:"px-2 pb-1.5 pt-3 text-xs font-semibold uppercase tracking-wide text-muted-foreground",children:e("settings.agents.sidebar.section.custom")}),J.map(({name:D,agents:K})=>t.jsx(or,{label:D,count:K.length,storageKey:"agents",children:K.map(C=>t.jsx(Fa,{agent:C,isSelected:h===C.name,onSelect:()=>{b(C.name),s?.()},onRename:()=>A(C),onDelete:()=>x(C),onDuplicate:()=>I(C),getAgentModeIcon:O,isMenuOpen:m===C.name,onMenuOpenChange:H=>k(H?C.name:null)},C.name))},D)),B.map(D=>t.jsx(Fa,{agent:D,isSelected:h===D.name,onSelect:()=>{b(D.name),s?.()},onRename:()=>A(D),onDelete:()=>x(D),onDuplicate:()=>I(D),getAgentModeIcon:O,isMenuOpen:m===D.name,onMenuOpenChange:K=>k(K?D.name:null)},D.name))]})]})}),t.jsx(Lt,{open:o!==null&&d!==null,onOpenChange:D=>{!D&&!g&&z()},children:t.jsxs(Ot,{className:"max-w-md",children:[t.jsxs(Bt,{children:[t.jsx(zt,{children:e(d==="delete"?"settings.agents.sidebar.dialog.deleteTitle":"settings.agents.sidebar.dialog.resetTitle")}),t.jsx(Vt,{children:d==="delete"?e("settings.agents.sidebar.dialog.deleteDescription",{name:o?.name??""}):e("settings.agents.sidebar.dialog.resetDescription",{name:o?.name??""})})]}),t.jsxs(Gt,{children:[t.jsx(W,{size:"sm",variant:"ghost",onClick:z,disabled:g,children:e("settings.common.actions.cancel")}),t.jsx(W,{size:"sm",onClick:L,disabled:g,children:e(d==="delete"?"settings.common.actions.delete":"settings.common.actions.reset")})]})]})}),t.jsx(Lt,{open:n!==null,onOpenChange:D=>!D&&a(null),children:t.jsxs(Ot,{children:[t.jsxs(Bt,{children:[t.jsx(zt,{children:e("settings.agents.sidebar.renameDialog.title")}),t.jsx(Vt,{children:e("settings.agents.sidebar.renameDialog.description",{name:n?.name??""})})]}),t.jsx(nt,{value:r,onChange:D=>i(D.target.value),placeholder:e("settings.agents.sidebar.renameDialog.placeholder"),className:"text-foreground placeholder:text-muted-foreground",onKeyDown:D=>{D.key==="Enter"&&w()}}),t.jsxs(Gt,{children:[t.jsx(W,{size:"sm",variant:"ghost",onClick:()=>a(null),children:e("settings.common.actions.cancel")}),t.jsx(W,{size:"sm",onClick:w,children:e("settings.common.actions.rename")})]})]})})]})},Fa=s=>{const e=it.c(58),{agent:n,isSelected:a,onSelect:r,onDelete:i,onReset:o,onRename:c,onDuplicate:d,getAgentModeIcon:f,isMenuOpen:g,onMenuOpenChange:u}=s,{t:m}=ot(),k=n;let h;e[0]===Symbol.for("react.memo_cache_sentinel")?(h=Tn(),e[0]=h):h=e[0];const v=h,b=a?"bg-interactive-selection":"hover:bg-interactive-hover";let R;e[1]!==b?(R=ge("group relative flex items-center rounded-md px-1.5 py-1 transition-all duration-200 select-none",b),e[1]=b,e[2]=R):R=e[2];let S;e[3]!==u?(S=v?void 0:K=>{K.preventDefault(),u(!0)},e[3]=u,e[4]=S):S=e[4];let j;e[5]!==n.name?(j=t.jsx("span",{className:"typography-ui-label font-normal truncate text-foreground",children:n.name}),e[5]=n.name,e[6]=j):j=e[6];let E;e[7]!==n.mode||e[8]!==f?(E=f(n.mode),e[7]=n.mode,e[8]=f,e[9]=E):E=e[9];let P;e[10]!==n||e[11]!==k.scope||e[12]!==m?(P=(k.scope||un(n))&&t.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:un(n)?m("settings.agents.sidebar.badge.system"):k.scope}),e[10]=n,e[11]=k.scope,e[12]=m,e[13]=P):P=e[13];let N;e[14]!==j||e[15]!==E||e[16]!==P?(N=t.jsxs("div",{className:"flex items-center gap-1.5",children:[j,E,P]}),e[14]=j,e[15]=E,e[16]=P,e[17]=N):N=e[17];let x;e[18]!==n.description?(x=n.description&&t.jsx("div",{className:"typography-micro text-muted-foreground/60 truncate leading-tight",children:n.description}),e[18]=n.description,e[19]=x):x=e[19];let y;e[20]!==r||e[21]!==N||e[22]!==x?(y=t.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:[N,x]}),e[20]=r,e[21]=N,e[22]=x,e[23]=y):y=e[23];let z;e[24]===Symbol.for("react.memo_cache_sentinel")?(z=t.jsx(rs,{asChild:!0,children:t.jsx(W,{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:t.jsx(F,{name:"more-2",className:"h-3.5 w-3.5"})})}),e[24]=z):z=e[24];let L;e[25]!==c||e[26]!==m?(L=c&&t.jsxs(Ht,{onClick:K=>{K.stopPropagation(),c()},children:[t.jsx(F,{name:"edit",className:"h-4 w-4 mr-px"}),m("settings.common.actions.rename")]}),e[25]=c,e[26]=m,e[27]=L):L=e[27];let I;e[28]!==d?(I=K=>{K.stopPropagation(),d()},e[28]=d,e[29]=I):I=e[29];let A;e[30]===Symbol.for("react.memo_cache_sentinel")?(A=t.jsx(F,{name:"file-copy",className:"h-4 w-4 mr-px"}),e[30]=A):A=e[30];let w;e[31]!==m?(w=m("settings.common.actions.duplicate"),e[31]=m,e[32]=w):w=e[32];let O;e[33]!==I||e[34]!==w?(O=t.jsxs(Ht,{onClick:I,children:[A,w]}),e[33]=I,e[34]=w,e[35]=O):O=e[35];let T;e[36]!==o||e[37]!==m?(T=o&&t.jsxs(Ht,{onClick:K=>{K.stopPropagation(),o()},children:[t.jsx(F,{name:"restart",className:"h-4 w-4 mr-px"}),m("settings.common.actions.reset")]}),e[36]=o,e[37]=m,e[38]=T):T=e[38];let _;e[39]!==i||e[40]!==m?(_=i&&t.jsxs(Ht,{onClick:K=>{K.stopPropagation(),i()},className:"text-destructive focus:text-destructive",children:[t.jsx(F,{name:"delete-bin",className:"h-4 w-4 mr-px"}),m("settings.common.actions.delete")]}),e[39]=i,e[40]=m,e[41]=_):_=e[41];let V;e[42]!==L||e[43]!==O||e[44]!==T||e[45]!==_?(V=t.jsxs(is,{align:"end",className:"w-fit min-w-20",children:[L,O,T,_]}),e[42]=L,e[43]=O,e[44]=T,e[45]=_,e[46]=V):V=e[46];let J;e[47]!==g||e[48]!==u||e[49]!==V?(J=t.jsxs(os,{open:g,onOpenChange:u,children:[z,V]}),e[47]=g,e[48]=u,e[49]=V,e[50]=J):J=e[50];let B;e[51]!==y||e[52]!==J?(B=t.jsxs("div",{className:"flex min-w-0 flex-1 items-center",children:[y,J]}),e[51]=y,e[52]=J,e[53]=B):B=e[53];let D;return e[54]!==B||e[55]!==R||e[56]!==S?(D=t.jsx("div",{className:R,onContextMenu:S,children:B}),e[54]=B,e[55]=R,e[56]=S,e[57]=D):D=e[57],D};function bi(s,e,n){return Math.min(n,Math.max(e,s))}function jm(s){if(!Number.isFinite(s))return 0;const e=String(s);if(e.includes("e-")){const[,a]=e.split("e-");return Number(a)||0}const n=e.split(".");return n.length===2?n[1].length:0}function yi(s,e){const n=jm(e);return n<=0?s:Number(s.toFixed(n))}const ms=ke.forwardRef((s,e)=>{const n=it.c(125);let a,r,i,o,c,d,f,g,u,m,k,h,v;n[0]!==s?({value:v,onValueChange:f,min:u,max:m,step:k,className:a,containerClassName:r,onBlur:c,disabled:i,fallbackValue:o,onClear:d,emptyLabel:h,...g}=s,n[0]=s,n[1]=a,n[2]=r,n[3]=i,n[4]=o,n[5]=c,n[6]=d,n[7]=f,n[8]=g,n[9]=u,n[10]=m,n[11]=k,n[12]=h,n[13]=v):(a=n[1],r=n[2],i=n[3],o=n[4],c=n[5],d=n[6],f=n[7],g=n[8],u=n[9],m=n[10],k=n[11],h=n[12],v=n[13]);const b=u===void 0?-1/0:u,R=m===void 0?1/0:m,S=k===void 0?1:k,j=h===void 0?"—":h,{t:E}=ot();let P;n[14]!==v?(P=()=>v===void 0?"":String(v),n[14]=v,n[15]=P):P=n[15];const[N,x]=ke.useState(P),{isMobile:y}=ys(),z=ke.useRef(!1),L=ke.useRef(null);let I;n[16]===Symbol.for("react.memo_cache_sentinel")?(I=()=>{if(typeof document>"u"||typeof window>"u")return;L.current?.();const Ee=fe=>{fe.preventDefault(),fe.stopPropagation(),fe.stopImmediatePropagation?.(),L.current?.()},Fe=window.setTimeout(()=>{L.current?.()},700),Y=()=>{window.clearTimeout(Fe),document.removeEventListener("click",Ee,!0),L.current=null};L.current=Y,document.addEventListener("click",Ee,!0)},n[16]=I):I=n[16];const A=I;let w,O;n[17]===Symbol.for("react.memo_cache_sentinel")?(w=()=>()=>{L.current?.()},O=[],n[17]=w,n[18]=O):(w=n[17],O=n[18]),ke.useEffect(w,O);let T,_;n[19]!==v?(_=()=>{x(v===void 0?"":String(v))},T=[v],n[19]=v,n[20]=T,n[21]=_):(T=n[20],_=n[21]),ke.useEffect(_,T);let V;e:{if(v!==void 0){V=v;break e}if(o!==void 0){V=o;break e}if(Number.isFinite(b)){V=b;break e}V=0}const J=V;let B;n[22]!==R||n[23]!==b||n[24]!==f||n[25]!==S?(B=Ee=>{const Fe=bi(Ee,b,R);f(yi(Fe,S))},n[22]=R,n[23]=b,n[24]=f,n[25]=S,n[26]=B):B=n[26];const D=B;let K;n[27]!==D||n[28]!==d?(K=Ee=>{const Fe=Ee.target.value;if(x(Fe),Fe.trim()===""){d?.();return}const Y=Number(Fe);Number.isFinite(Y)&&D(Y)},n[27]=D,n[28]=d,n[29]=K):K=n[29];const C=K;let H;n[30]!==N||n[31]!==R||n[32]!==b||n[33]!==c||n[34]!==d||n[35]!==f||n[36]!==S||n[37]!==v?(H=Ee=>{if(N.trim()===""){d||x(v===void 0?"":String(v)),c?.(Ee);return}const Fe=Number(N);if(!Number.isFinite(Fe))x(v===void 0?"":String(v));else{const Y=bi(Fe,b,R),fe=yi(Y,S);fe!==v&&f(fe),x(String(fe))}c?.(Ee)},n[30]=N,n[31]=R,n[32]=b,n[33]=c,n[34]=d,n[35]=f,n[36]=S,n[37]=v,n[38]=H):H=n[38];const G=H,se=!!(i||J>=R),oe=!!(i||J<=b);let re;n[39]!==J||n[40]!==D||n[41]!==oe||n[42]!==S?(re=()=>{oe||D(J-S)},n[39]=J,n[40]=D,n[41]=oe,n[42]=S,n[43]=re):re=n[43];const me=re;let le;n[44]!==J||n[45]!==D||n[46]!==se||n[47]!==S?(le=()=>{se||D(J+S)},n[44]=J,n[45]=D,n[46]=se,n[47]=S,n[48]=le):le=n[48];const ve=le;let Z;if(n[49]!==a||n[50]!==r||n[51]!==oe||n[52]!==N||n[53]!==j||n[54]!==me||n[55]!==ve||n[56]!==se||n[57]!==y||n[58]!==E||n[59]!==v){Z=Symbol.for("react.early_return_sentinel");e:{const Ee=Y=>fe=>{fe.preventDefault(),fe.stopPropagation(),z.current=!0,A(),Y()},Fe=Y=>fe=>{if(z.current){z.current=!1,fe.preventDefault(),fe.stopPropagation();return}Y()};if(y){let Y;n[61]!==r?(Y=ge("flex h-9 shrink-0 items-stretch overflow-x-hidden overflow-y-hidden rounded-lg border border-border bg-transparent select-none overscroll-contain","[-webkit-user-select:none] [-webkit-touch-callout:none]","disabled:pointer-events-none disabled:opacity-50",r),n[61]=r,n[62]=Y):Y=n[62];let fe;n[63]!==E?(fe=E("numberInput.actions.decreaseAria"),n[63]=E,n[64]=fe):fe=n[64];const Ce=Ee(me),Ie=Fe(me),Le=!oe&&"active:bg-interactive-hover";let $e;n[65]!==Le?($e=ge("grid h-full min-h-0 w-9 place-items-center overflow-x-hidden overflow-y-hidden border-r border-border p-0 leading-none touch-none","text-muted-foreground","disabled:pointer-events-none disabled:opacity-50",Le),n[65]=Le,n[66]=$e):$e=n[66];let te;n[67]===Symbol.for("react.memo_cache_sentinel")?(te=t.jsx(F,{name:"subtract",className:"block h-4 w-4"}),n[67]=te):te=n[67];const ce=t.jsx("button",{type:"button","aria-label":fe,disabled:oe,onTouchStart:Ce,onClick:Ie,className:$e,children:te});let Se;n[68]!==a?(Se=ge("flex h-full min-w-0 w-14 items-center justify-center bg-transparent px-1.5","text-center text-[16px] leading-none text-foreground [font-variant-numeric:tabular-nums]",a),n[68]=a,n[69]=Se):Se=n[69];const Ue=v===void 0?j:N;let Ke;n[70]!==Se||n[71]!==Ue?(Ke=t.jsx("div",{className:Se,"aria-live":"polite",children:Ue}),n[70]=Se,n[71]=Ue,n[72]=Ke):Ke=n[72];let Ye;n[73]!==E?(Ye=E("numberInput.actions.increaseAria"),n[73]=E,n[74]=Ye):Ye=n[74];const Xe=Ee(ve),Ze=Fe(ve),p=!se&&"active:bg-interactive-hover";let ee;n[75]!==p?(ee=ge("grid h-full min-h-0 w-9 place-items-center overflow-x-hidden overflow-y-hidden border-l border-border p-0 leading-none touch-none","text-muted-foreground","disabled:pointer-events-none disabled:opacity-50",p),n[75]=p,n[76]=ee):ee=n[76];let De;n[77]===Symbol.for("react.memo_cache_sentinel")?(De=t.jsx(F,{name:"add",className:"block h-4 w-4"}),n[77]=De):De=n[77];const Te=t.jsx("button",{type:"button","aria-label":Ye,disabled:se,onTouchStart:Xe,onClick:Ze,className:ee,children:De});let We;n[78]!==Y||n[79]!==ce||n[80]!==Ke||n[81]!==Te?(We=t.jsxs("div",{className:Y,children:[ce,Ke,Te]}),n[78]=Y,n[79]=ce,n[80]=Ke,n[81]=Te,n[82]=We):We=n[82],Z=We;break e}}n[49]=a,n[50]=r,n[51]=oe,n[52]=N,n[53]=j,n[54]=me,n[55]=ve,n[56]=se,n[57]=y,n[58]=E,n[59]=v,n[60]=Z}else Z=n[60];if(Z!==Symbol.for("react.early_return_sentinel"))return Z;let X;n[83]!==r?(X=ge("flex h-7 shrink-0 items-stretch overflow-x-hidden overflow-y-hidden rounded-lg border border-border bg-transparent","disabled:pointer-events-none disabled:opacity-50",r),n[83]=r,n[84]=X):X=n[84];let xe;n[85]!==E?(xe=E("numberInput.actions.decreaseAria"),n[85]=E,n[86]=xe):xe=n[86];let ue;n[87]!==J||n[88]!==D||n[89]!==S?(ue=()=>D(J-S),n[87]=J,n[88]=D,n[89]=S,n[90]=ue):ue=n[90];let be,de;n[91]===Symbol.for("react.memo_cache_sentinel")?(be=ge("flex h-full w-7 items-center justify-center overflow-x-hidden overflow-y-hidden border-r border-border p-0 leading-none touch-manipulation","text-muted-foreground hover:bg-interactive-hover hover:text-foreground","disabled:pointer-events-none disabled:opacity-50"),de=t.jsx(F,{name:"subtract",className:"block h-3.5 w-3.5"}),n[91]=be,n[92]=de):(be=n[91],de=n[92]);let we;n[93]!==oe||n[94]!==xe||n[95]!==ue?(we=t.jsx("button",{type:"button","aria-label":xe,disabled:oe,onClick:ue,className:be,children:de}),n[93]=oe,n[94]=xe,n[95]=ue,n[96]=we):we=n[96];const Q=g.inputMode??"numeric";let he;n[97]!==a?(he=ge("h-full min-w-0 w-14 bg-transparent px-1.5 text-center typography-ui-label leading-none text-foreground [font-variant-numeric:tabular-nums]","placeholder:text-muted-foreground selection:bg-primary selection:text-primary-foreground","appearance-none outline-none [appearance:textfield] [scrollbar-width:none] [&::-webkit-scrollbar]:hidden","disabled:pointer-events-none disabled:cursor-not-allowed",a),n[97]=a,n[98]=he):he=n[98];let q;n[99]!==i||n[100]!==N||n[101]!==G||n[102]!==C||n[103]!==g||n[104]!==e||n[105]!==Q||n[106]!==he?(q=t.jsx("input",{...g,ref:e,type:"text",inputMode:Q,value:N,onChange:C,onBlur:G,disabled:i,spellCheck:!1,autoComplete:"off",autoCorrect:"off",autoCapitalize:"off",className:he}),n[99]=i,n[100]=N,n[101]=G,n[102]=C,n[103]=g,n[104]=e,n[105]=Q,n[106]=he,n[107]=q):q=n[107];let ae;n[108]!==E?(ae=E("numberInput.actions.increaseAria"),n[108]=E,n[109]=ae):ae=n[109];let pe;n[110]!==J||n[111]!==D||n[112]!==S?(pe=()=>D(J+S),n[110]=J,n[111]=D,n[112]=S,n[113]=pe):pe=n[113];let je,Me;n[114]===Symbol.for("react.memo_cache_sentinel")?(je=ge("flex h-full w-7 items-center justify-center overflow-x-hidden overflow-y-hidden border-l border-border p-0 leading-none touch-manipulation","text-muted-foreground hover:bg-interactive-hover hover:text-foreground","disabled:pointer-events-none disabled:opacity-50"),Me=t.jsx(F,{name:"add",className:"block h-3.5 w-3.5"}),n[114]=je,n[115]=Me):(je=n[114],Me=n[115]);let Pe;n[116]!==se||n[117]!==ae||n[118]!==pe?(Pe=t.jsx("button",{type:"button","aria-label":ae,disabled:se,onClick:pe,className:je,children:Me}),n[116]=se,n[117]=ae,n[118]=pe,n[119]=Pe):Pe=n[119];let Re;return n[120]!==X||n[121]!==we||n[122]!==q||n[123]!==Pe?(Re=t.jsxs("div",{className:X,children:[we,q,Pe]}),n[120]=X,n[121]=we,n[122]=q,n[123]=Pe,n[124]=Re):Re=n[124],Re});ms.displayName="NumberInput";const vi=["*","read","edit","glob","grep","list","bash","task","skill","lsp","todoread","todowrite","webfetch","websearch","codesearch","external_directory","doom_loop","question","plan_enter","plan_exit"],ra=s=>s==="allow"||s==="ask"||s==="deny",Qs=(s,e)=>`${s}::${e}`,en=s=>{const e=new Map;for(const n of s)!n.permission||n.permission==="invalid"||n.pattern&&ra(n.action)&&e.set(Qs(n.permission,n.pattern),{permission:n.permission,pattern:n.pattern,action:n.action});return Array.from(e.values())},Wn=s=>{const e=new Map;for(const n of en(s))e.set(Qs(n.permission,n.pattern),n);return e},ji=s=>[...s].sort((e,n)=>{const a=e.permission.localeCompare(n.permission);return a!==0?a:e.pattern.localeCompare(n.pattern)}),wm=(s,e)=>{const n=ji(en(s)),a=ji(en(e));return n.length!==a.length?!1:n.every((r,i)=>{const o=a[i];return r.permission===o.permission&&r.pattern===o.pattern&&r.action===o.action})},Nm=s=>s.find(n=>n.permission==="*"&&n.pattern==="*")?.action??"allow",km=(s,e)=>en(s).filter(n=>!(n.permission==="*"&&n.pattern==="*")).filter(n=>n.pattern!=="*"||n.action!==e),Sm=s=>{if(ra(s))return[{permission:"*",pattern:"*",action:s}];if(!s||typeof s!="object"||Array.isArray(s))return[];const e=[];for(const[n,a]of Object.entries(s))if(n!=="__originalKeys"){if(ra(a)){e.push({permission:n,pattern:"*",action:a});continue}if(a&&typeof a=="object"&&!Array.isArray(a))for(const[r,i]of Object.entries(a))ra(i)&&e.push({permission:n,pattern:r,action:i})}return e},Cm=(s,e)=>{const n=en(e),a={};for(const i of n)(a[i.permission]||={})[i.pattern]=i.action;const r={"*":s};for(const[i,o]of Object.entries(a))if(i!=="*"){if(Object.keys(o).length===1&&o["*"]){r[i]=o["*"];continue}r[i]=o}return r},Pm=()=>{const{t:s}=ot(),{isMobile:e}=ys(),{selectedAgentName:n,getAgentByName:a,createAgent:r,updateAgent:i,agents:o,agentDraft:c,setAgentDraft:d}=jr(bs(Y=>({selectedAgentName:Y.selectedAgentName,getAgentByName:Y.getAgentByName,createAgent:Y.createAgent,updateAgent:Y.updateAgent,agents:Y.agents,agentDraft:Y.agentDraft,setAgentDraft:Y.setAgentDraft}))),f=n?a(n):null,g=!!(c&&c.name===n&&!f),[u,m]=l.useState(""),[k,h]=l.useState("user"),[v,b]=l.useState(""),[R,S]=l.useState("subagent"),[j,E]=l.useState(""),[P,N]=l.useState(void 0),[x,y]=l.useState(void 0),[z,L]=l.useState(""),[I,A]=l.useState("allow"),[w,O]=l.useState([]),[T,_]=l.useState([]),[V,J]=l.useState(""),[B,D]=l.useState("*"),[K,C]=l.useState(!1),[H,G]=l.useState(!1),se=l.useRef(null),oe=gs(Y=>Y.currentDirectory??null),[re,me]=l.useState([]),le=Fc(Y=>Y.permission);l.useEffect(()=>{let Y=!1;return(async()=>{const Ce=await ns.listToolIds({directory:oe});if(Y)return;const Ie=new Set(["write","patch","multiedit"]),Le=Ce.map($e=>typeof $e=="string"?$e.trim():"").filter(Boolean).filter($e=>$e!=="*").filter($e=>$e!=="invalid").filter($e=>!Ie.has($e));me(Array.from(new Set(Le)).sort(($e,te)=>$e.localeCompare(te)))})(),()=>{Y=!0}},[oe]);const ve=l.useMemo(()=>{const Y=new Set;for(const fe of o){const Ce=en(Array.isArray(fe.permission)?fe.permission:[]);for(const Ie of Ce)Ie.permission&&Ie.permission!=="*"&&Ie.permission!=="invalid"&&Y.add(Ie.permission)}for(const fe of Object.values(le))for(const Ce of fe){const Ie=Ce.permission?.trim();Ie&&Ie!=="invalid"&&Y.add(Ie)}for(const fe of re)Y.add(fe);return Array.from(Y).sort((fe,Ce)=>fe.localeCompare(Ce))},[o,le,re]),Z=l.useMemo(()=>Wn(w),[w]),X=l.useMemo(()=>Wn(T),[T]),xe=l.useCallback(Y=>X.get(Qs(Y,"*"))?.action,[X]),ue=l.useCallback(Y=>T.filter(fe=>fe.permission===Y&&fe.pattern!=="*").sort((fe,Ce)=>fe.pattern.localeCompare(Ce.pattern)),[T]),be=l.useMemo(()=>{const Y=new Set;for(const fe of vi)Y.add(fe);for(const fe of ve)Y.add(fe);return Array.from(Y).sort((fe,Ce)=>fe.localeCompare(Ce))},[ve]),de=l.useCallback(Y=>{const fe=Y==="*"?I:xe(Y)??I,Ce=ue(Y),Ie=!1,Le=Ce.reduce((te,ce)=>(te[ce.action]=(te[ce.action]??0)+1,te),{allow:0,ask:0,deny:0}),$e=["allow","ask","deny"].filter(te=>Le[te]>0).map(te=>`${Le[te]} ${te}`).join(", ");return{defaultAction:fe,patternRulesCount:Ce.length,patternSummary:$e,hasDefaultHint:Ie}},[ue,xe,I]),we=l.useCallback(Y=>s(Y==="allow"?"settings.common.permission.allow":Y==="deny"?"settings.common.permission.deny":"settings.common.permission.ask"),[s]),Q=l.useCallback(Y=>Y==="global"?s("settings.common.scope.global"):we(Y),[we,s]),he=l.useMemo(()=>{const Y=new Set;for(const fe of vi)Y.add(fe);for(const fe of ve)Y.add(fe);return Array.from(Y).sort((fe,Ce)=>fe.localeCompare(Ce))},[ve]),q=l.useCallback((Y,fe,Ce)=>{_(Ie=>{const Le=Wn(Ie);return Le.set(Qs(Y,fe),{permission:Y,pattern:fe,action:Ce}),Array.from(Le.values())})},[]),ae=l.useCallback((Y,fe)=>{_(Ce=>{const Ie=Wn(Ce);return Ie.delete(Qs(Y,fe)),Array.from(Ie.values())})},[]),pe=l.useCallback((Y,fe)=>{const Ce=Z.get(Qs(Y,fe));if(Ce){q(Y,fe,Ce.action);return}ae(Y,fe)},[Z,ae,q]),je=l.useCallback((Y,fe,Ce)=>{q(Y,fe,Ce)},[q]),Me=l.useCallback(Y=>{A(Y),_(fe=>fe.filter(Ce=>!(Ce.pattern==="*"&&Ce.action===Y)))},[]),Pe=l.useCallback(Y=>{const fe=V.trim();if(!fe){U.error(s("settings.agents.page.toast.permissionNameRequired"));return}const Ce=B.trim()||"*";if(fe==="*"&&Ce==="*"){Me(Y),J(""),D("*");return}Ce==="*"&&fe!=="*"&&Y===I?ae(fe,"*"):q(fe,Ce,Y),J(""),D("*")},[I,V,B,ae,Me,s,q]),Re=l.useCallback(Y=>Y==="*"?s("settings.agents.page.permissions.defaultLabel"):Y==="webfetch"?"WebFetch":Y==="websearch"?"WebSearch":Y==="codesearch"?"CodeSearch":Y==="doom_loop"?"Doom Loop":Y==="external_directory"?"External Directory":Y==="todowrite"?"TodoWrite":Y==="todoread"?"TodoRead":Y.split(/[_-]+/g).filter(Boolean).map(fe=>fe.charAt(0).toUpperCase()+fe.slice(1)).join(" "),[s]);l.useEffect(()=>{J(""),D("*");const Y=fe=>{const Ce=en(fe),Ie=Nm(Ce),Le=km(Ce,Ie);return A(Ie),O(Le),_(Le),{global:Ie,rules:Le}};if(g&&c){const fe=c.name||"",Ce=c.scope||"user",Ie=c.description||"",Le=c.mode||"subagent",$e=c.model||"",te=c.temperature,ce=c.top_p,Se=c.prompt||"";m(fe),h(Ce),b(Ie),S(Le),E($e),N(te),y(ce),L(Se);const Ue=Sm(c.permission),Ke=Y(Ue);se.current={draftName:fe,draftScope:Ce,description:Ie,mode:Le,model:$e,temperature:te,topP:ce,prompt:Se,globalPermission:Ke.global,permissionRules:Ke.rules};return}if(f&&n===f.name){const fe=f.description||"",Ce=f.mode||"subagent",Ie=f.model?.providerID&&f.model?.modelID?`${f.model.providerID}/${f.model.modelID}`:"",Le=f.temperature,$e=f.topP,te=f.prompt||"";b(fe),S(Ce),E(Ie),N(Le),y($e),L(te);const ce=Y(Array.isArray(f.permission)?f.permission:[]);se.current={draftName:"",draftScope:"user",description:fe,mode:Ce,model:Ie,temperature:Le,topP:$e,prompt:te,globalPermission:ce.global,permissionRules:ce.rules}}},[c,g,f,n]);const Ee=l.useMemo(()=>{const Y=se.current;return Y?!!(g&&(u!==Y.draftName||k!==Y.draftScope)||v!==Y.description||R!==Y.mode||j!==Y.model||P!==Y.temperature||x!==Y.topP||z!==Y.prompt||I!==Y.globalPermission||!wm(T,Y.permissionRules)):!1},[v,u,k,I,g,R,j,T,z,P,x]),Fe=async()=>{const Y=g?u.trim().replace(/\s+/g,"-"):n?.trim();if(!Y){U.error(s("settings.agents.sidebar.toast.agentNameRequired"));return}if(g&&o.some(fe=>fe.name===Y)){U.error(s("settings.agents.sidebar.toast.agentExists"));return}G(!0);try{const fe=j.trim(),Ce=Cm(I,T),Ie={name:Y,description:v.trim()||void 0,mode:R,model:fe===""?null:fe,temperature:P,top_p:x,prompt:z.trim()||void 0,permission:Ce,scope:g?k:void 0};let Le;g?(Le=await r(Ie),Le&&d(null)):Le=await i(Y,Ie),Le?U.success(s(g?"settings.agents.page.toast.created":"settings.agents.page.toast.updated")):U.error(s(g?"settings.agents.page.toast.createFailed":"settings.agents.page.toast.updateFailed"))}catch(fe){console.error("Error saving agent:",fe);const Ce=fe instanceof Error&&fe.message?fe.message:s("settings.agents.page.toast.saveUnexpectedError");U.error(Ce)}finally{G(!1)}};return n?t.jsx(Kt,{outerClassName:"h-full",className:"w-full",children:t.jsxs("div",{className:"mx-auto w-full max-w-3xl p-3 sm:p-6 sm:pt-8",children:[t.jsx("div",{className:"mb-4 flex items-center justify-between gap-4",children:t.jsxs("div",{className:"min-w-0",children:[t.jsx("h2",{className:"typography-ui-header font-semibold text-foreground truncate",children:g?s("settings.agents.page.title.new"):n}),t.jsx("p",{className:"typography-meta text-muted-foreground truncate",children:s(g?"settings.agents.page.subtitle.new":"settings.agents.page.subtitle.edit")})]})}),t.jsxs("div",{className:"mb-8",children:[t.jsx("div",{className:"mb-1 px-1",children:t.jsx("h3",{className:"typography-ui-header font-medium text-foreground",children:s("settings.agents.page.section.identityRole")})}),t.jsxs("section",{className:"px-2 pb-2 pt-0 space-y-0",children:[g&&t.jsxs("div",{className:"flex flex-col gap-2 py-1.5 sm:flex-row sm:items-center sm:gap-8",children:[t.jsx("div",{className:"flex min-w-0 flex-col sm:w-56 shrink-0",children:t.jsx("span",{className:"typography-ui-label text-foreground",children:s("settings.agents.page.field.agentName")})}),t.jsxs("div",{className:"flex min-w-0 flex-1 items-center gap-2 sm:w-fit sm:flex-initial",children:[t.jsxs("div",{className:"flex items-center",children:[t.jsx("span",{className:"typography-ui-label text-muted-foreground mr-1",children:"@"}),t.jsx(nt,{value:u,onChange:Y=>m(Y.target.value),placeholder:s("settings.agents.page.field.agentNamePlaceholder"),className:"h-7 w-40 px-2"})]}),t.jsxs(St,{value:k,onValueChange:Y=>h(Y),children:[t.jsx(Ct,{className:"w-fit min-w-[100px]",children:t.jsx(Rt,{placeholder:s("settings.agents.page.field.scopePlaceholder")})}),t.jsxs(Pt,{align:"end",children:[t.jsx(dt,{value:"user",children:t.jsxs("div",{className:"flex items-center gap-2",children:[t.jsx(F,{name:"user-3",className:"h-3.5 w-3.5"}),t.jsx("span",{children:s("settings.common.scope.global")})]})}),t.jsx(dt,{value:"project",children:t.jsxs("div",{className:"flex items-center gap-2",children:[t.jsx(F,{name:"folder",className:"h-3.5 w-3.5"}),t.jsx("span",{children:s("settings.common.scope.project")})]})})]})]})]})]}),t.jsxs("div",{className:"py-1.5",children:[t.jsx("span",{className:"typography-ui-label text-foreground",children:s("settings.common.field.description")}),t.jsx("div",{className:"mt-1.5",children:t.jsx(ls,{value:v,onChange:Y=>b(Y.target.value),placeholder:s("settings.agents.page.field.descriptionPlaceholder"),rows:2,className:"w-full resize-none min-h-[60px] bg-transparent"})})]}),t.jsx("div",{className:"pb-1.5 pt-0.5",children:t.jsxs("div",{className:"flex min-w-0 flex-col gap-1.5",children:[t.jsxs("div",{className:"flex items-center gap-1.5",children:[t.jsx("span",{className:"typography-ui-label text-foreground",children:s("settings.agents.page.field.mode")}),t.jsxs(vt,{children:[t.jsx(jt,{asChild:!0,children:t.jsx(F,{name:"information",className:"h-3.5 w-3.5 text-muted-foreground/60 cursor-help"})}),t.jsx(kt,{sideOffset:8,className:"max-w-xs",children:s("settings.agents.page.field.modeTooltip")})]})]}),t.jsxs("div",{className:"flex flex-wrap items-center gap-1",children:[t.jsx(W,{variant:"chip",size:"xs","aria-pressed":R==="primary",onClick:()=>S("primary"),className:"!font-normal",children:s("settings.agents.page.mode.primary")}),t.jsx(W,{variant:"chip",size:"xs","aria-pressed":R==="subagent",onClick:()=>S("subagent"),className:"!font-normal",children:s("settings.agents.page.mode.subagent")}),t.jsx(W,{variant:"chip",size:"xs","aria-pressed":R==="all",onClick:()=>S("all"),className:"!font-normal",children:s("settings.agents.page.mode.all")})]})]})})]})]}),t.jsxs("div",{className:"mb-8",children:[t.jsx("div",{className:"mb-1 px-1",children:t.jsx("h3",{className:"typography-ui-header font-medium text-foreground",children:s("settings.agents.page.section.modelParameters")})}),t.jsxs("section",{className:"px-2 pb-2 pt-0 space-y-0",children:[t.jsxs("div",{className:"flex flex-col gap-2 py-1.5 sm:flex-row sm:items-center sm:gap-8",children:[t.jsx("div",{className:"flex min-w-0 flex-col sm:w-56 shrink-0",children:t.jsx("span",{className:"typography-ui-label text-foreground",children:s("settings.agents.page.field.overrideModel")})}),t.jsx("div",{className:"flex min-w-0 flex-1 items-center gap-2 sm:w-fit sm:flex-initial",children:t.jsx(wr,{providerId:xn(j)?.providerId??"",modelId:xn(j)?.modelId??"",onChange:(Y,fe)=>{E(Y&&fe?`${Y}/${fe}`:"")}})})]}),t.jsxs("div",{className:ge("py-1.5",e?"flex flex-col gap-3":"flex items-center gap-8"),children:[t.jsxs("div",{className:ge("flex min-w-0 flex-col",e?"w-full":"sm:w-56 shrink-0"),children:[t.jsxs("div",{className:"flex items-center gap-1.5",children:[t.jsx("span",{className:"typography-ui-label text-foreground",children:s("settings.agents.page.field.temperature")}),t.jsxs(vt,{children:[t.jsx(jt,{asChild:!0,children:t.jsx(F,{name:"information",className:"h-3.5 w-3.5 text-muted-foreground/60 cursor-help"})}),t.jsx(kt,{sideOffset:8,className:"max-w-xs",children:s("settings.agents.page.field.temperatureTooltip")})]})]}),t.jsx("span",{className:"typography-meta text-muted-foreground",children:s("settings.agents.page.field.temperatureRange")})]}),t.jsxs("div",{className:ge("flex items-center gap-2",e?"w-full":"w-fit"),children:[t.jsx(ms,{value:P,fallbackValue:.7,onValueChange:N,onClear:()=>N(void 0),min:0,max:2,step:.1,inputMode:"decimal",placeholder:"—",emptyLabel:"—",className:"w-16"}),P!==void 0&&t.jsx(W,{size:"sm",type:"button",variant:"ghost",onClick:()=>N(void 0),className:"h-7 w-7 px-0 text-muted-foreground hover:text-foreground","aria-label":s("settings.agents.page.field.clearTemperatureAria"),title:s("settings.common.actions.clear"),children:t.jsx(F,{name:"close",className:"h-3.5 w-3.5"})})]})]}),t.jsxs("div",{className:ge("py-1.5",e?"flex flex-col gap-3":"flex items-center gap-8"),children:[t.jsxs("div",{className:ge("flex min-w-0 flex-col",e?"w-full":"sm:w-56 shrink-0"),children:[t.jsxs("div",{className:"flex items-center gap-1.5",children:[t.jsx("span",{className:"typography-ui-label text-foreground",children:s("settings.agents.page.field.topP")}),t.jsxs(vt,{children:[t.jsx(jt,{asChild:!0,children:t.jsx(F,{name:"information",className:"h-3.5 w-3.5 text-muted-foreground/60 cursor-help"})}),t.jsx(kt,{sideOffset:8,className:"max-w-xs",children:s("settings.agents.page.field.topPTooltip")})]})]}),t.jsx("span",{className:"typography-meta text-muted-foreground",children:s("settings.agents.page.field.topPRange")})]}),t.jsxs("div",{className:ge("flex items-center gap-2",e?"w-full":"w-fit"),children:[t.jsx(ms,{value:x,fallbackValue:.9,onValueChange:y,onClear:()=>y(void 0),min:0,max:1,step:.1,inputMode:"decimal",placeholder:"—",emptyLabel:"—",className:"w-16"}),x!==void 0&&t.jsx(W,{size:"sm",type:"button",variant:"ghost",onClick:()=>y(void 0),className:"h-7 w-7 px-0 text-muted-foreground hover:text-foreground","aria-label":s("settings.agents.page.field.clearTopPAria"),title:s("settings.common.actions.clear"),children:t.jsx(F,{name:"close",className:"h-3.5 w-3.5"})})]})]})]})]}),t.jsxs("div",{className:"mb-8",children:[t.jsx("div",{className:"mb-1 px-1",children:t.jsx("h3",{className:"typography-ui-header font-medium text-foreground",children:s("settings.agents.page.section.systemPrompt")})}),t.jsx("section",{className:"px-2 pb-2 pt-0",children:t.jsx(ls,{value:z,onChange:Y=>L(Y.target.value),placeholder:s("settings.agents.page.field.systemPromptPlaceholder"),rows:8,className:"w-full font-mono typography-meta min-h-[120px] max-h-[60vh] bg-transparent resize-y"})})]}),t.jsxs("div",{className:"mb-2",children:[t.jsxs("div",{className:"mb-1 px-1 flex items-center justify-between gap-4",children:[t.jsx("h3",{className:"typography-ui-header font-medium text-foreground",children:s("settings.agents.page.section.toolPermissions")}),t.jsx(W,{variant:"outline",size:"xs",className:"!font-normal",onClick:()=>C(Y=>!Y),children:s(K?"settings.agents.page.permissions.hideEditor":"settings.agents.page.permissions.advancedEditor")})]}),K?t.jsxs("div",{className:"space-y-6 px-2",children:[t.jsxs("div",{className:"flex items-center justify-between gap-4 py-1.5",children:[t.jsxs("div",{className:"flex items-center gap-2",children:[t.jsx("span",{className:"typography-ui-label text-foreground",children:s("settings.agents.page.permissions.globalDefault")}),t.jsx("span",{className:"typography-micro text-muted-foreground/70 font-mono",children:"*"})]}),t.jsxs(St,{value:I,onValueChange:Y=>Me(Y),children:[t.jsx(Ct,{className:"w-[100px]",children:t.jsx(Rt,{children:we(I)})}),t.jsxs(Pt,{children:[t.jsx(dt,{value:"allow",children:s("settings.common.permission.allow")}),t.jsx(dt,{value:"ask",children:s("settings.common.permission.ask")}),t.jsx(dt,{value:"deny",children:s("settings.common.permission.deny")})]})]})]}),t.jsx("div",{className:"space-y-4",children:be.filter(Y=>Y!=="*").map(Y=>{const fe=Re(Y),{defaultAction:Ce,patternRulesCount:Ie}=de(Y),Le=xe(Y),$e=Le??"global",te=ue(Y),ce=["allow","ask","deny"].filter(Se=>Se!==I);return t.jsxs("div",{className:"border-t border-[var(--surface-subtle)] pt-2",children:[t.jsxs("div",{className:"flex items-center justify-between py-1",children:[t.jsxs("div",{className:"flex items-center gap-2",children:[t.jsx("span",{className:"typography-ui-label text-foreground",children:fe}),t.jsx("span",{className:"typography-micro text-muted-foreground/70 font-mono",children:Y})]}),t.jsx("div",{className:"typography-micro text-muted-foreground",children:Ie>0?s("settings.agents.page.permissions.globalSummary",{summary:Ce}):Ce})]}),t.jsxs("div",{className:"space-y-1 pl-2 mt-1",children:[t.jsxs("div",{className:"flex flex-wrap items-center justify-between gap-2 py-0.5",children:[t.jsxs("div",{className:"flex items-center gap-2",children:[t.jsx("span",{className:"typography-micro text-muted-foreground",children:s("settings.agents.page.permissions.pattern")}),t.jsx("span",{className:"typography-micro font-mono text-foreground bg-[var(--surface-muted)] px-1 rounded",children:"*"}),Le&&t.jsx(W,{size:"sm",variant:"ghost",onClick:()=>pe(Y,"*"),className:"px-1.5 py-0 h-5",children:t.jsx(F,{name:"subtract",className:"h-3.5 w-3.5 text-muted-foreground hover:text-foreground"})})]}),t.jsxs(St,{value:$e,onValueChange:Se=>{if(Se==="global"){ae(Y,"*");return}q(Y,"*",Se)},children:[t.jsx(Ct,{className:"w-[90px]",children:t.jsx(Rt,{children:Q($e)})}),t.jsxs(Pt,{children:[t.jsx(dt,{value:"global",children:s("settings.common.scope.global")}),ce.map(Se=>t.jsx(dt,{value:Se,className:"capitalize",children:we(Se)},Se))]})]})]}),te.map(Se=>{const Ue=Qs(Se.permission,Se.pattern),Ke=Z.get(Ue),Ye=!Ke,Xe=!!(Ke&&Ke.action!==Se.action);return t.jsxs("div",{className:"flex flex-wrap items-center justify-between gap-2 py-0.5 border-t border-[var(--surface-subtle)]",children:[t.jsxs("div",{className:"flex items-center gap-2",children:[t.jsx("span",{className:"typography-micro text-muted-foreground",children:s("settings.agents.page.permissions.pattern")}),t.jsx("span",{className:"typography-micro font-mono text-foreground bg-[var(--surface-muted)] px-1 rounded",children:Se.pattern}),Ye&&t.jsx("span",{className:"typography-micro text-[var(--status-success)]",children:s("settings.common.badge.new")}),Xe&&t.jsx("span",{className:"typography-micro text-[var(--status-warning)]",children:s("settings.common.badge.modified")}),(Ye||Xe)&&t.jsx(W,{size:"sm",variant:"ghost",onClick:()=>Ye?ae(Se.permission,Se.pattern):pe(Se.permission,Se.pattern),className:"px-1.5 py-0 h-5",children:t.jsx(F,{name:"subtract",className:"h-3.5 w-3.5 text-muted-foreground hover:text-foreground"})})]}),t.jsxs(St,{value:Se.action,onValueChange:Ze=>je(Se.permission,Se.pattern,Ze),children:[t.jsx(Ct,{className:"w-[90px]",children:t.jsx(Rt,{children:we(Se.action)})}),t.jsxs(Pt,{children:[t.jsx(dt,{value:"allow",children:s("settings.common.permission.allow")}),t.jsx(dt,{value:"ask",children:s("settings.common.permission.ask")}),t.jsx(dt,{value:"deny",children:s("settings.common.permission.deny")})]})]})]},Ue)})]})]},Y)})}),t.jsxs("div",{className:"border-t border-[var(--surface-subtle)] pt-3",children:[t.jsx("h4",{className:"typography-ui-label text-foreground mb-2",children:s("settings.agents.page.permissions.addCustomRule")}),t.jsxs("div",{className:"flex flex-col sm:flex-row items-end sm:items-center gap-2",children:[t.jsxs(St,{value:V,onValueChange:J,children:[t.jsx(Ct,{className:"w-full sm:w-[160px]",children:V?t.jsx("span",{className:"truncate",children:Re(V)}):t.jsx("span",{className:"text-muted-foreground",children:s("settings.agents.page.permissions.permissionPlaceholder")})}),t.jsx(Pt,{children:he.map(Y=>t.jsx(dt,{value:Y,children:t.jsx("div",{className:"flex items-center justify-between gap-2 w-full",children:t.jsx("span",{children:Re(Y)})})},Y))})]}),t.jsx(nt,{value:B,onChange:Y=>D(Y.target.value),placeholder:s("settings.agents.page.permissions.patternPlaceholder"),className:"h-7 flex-1 font-mono text-xs"}),t.jsxs("div",{className:"flex gap-1",children:[t.jsx(W,{variant:"outline",size:"xs",className:"!font-normal",onClick:()=>Pe("allow"),children:s("settings.common.permission.allow")}),t.jsx(W,{variant:"outline",size:"xs",className:"!font-normal",onClick:()=>Pe("ask"),children:s("settings.common.permission.ask")}),t.jsx(W,{variant:"outline",size:"xs",className:"!font-normal",onClick:()=>Pe("deny"),children:s("settings.common.permission.deny")})]})]})]})]}):t.jsx("section",{className:"px-2 pb-2 pt-0 space-y-0",children:be.map((Y,fe)=>{const{defaultAction:Ce,patternRulesCount:Ie,patternSummary:Le,hasDefaultHint:$e}=de(Y),te=Re(Y),ce=$e?`${Ce} (env blocked)`:Ce;return t.jsxs("div",{className:ge("flex flex-col gap-1 py-1.5 sm:flex-row sm:items-center sm:justify-between sm:gap-8",fe>0&&"border-t border-[var(--surface-subtle)]"),children:[t.jsxs("div",{className:"flex items-center gap-2",children:[t.jsx("span",{className:"typography-ui-label text-foreground",children:te}),t.jsx("span",{className:"typography-micro text-muted-foreground/70 font-mono hidden sm:inline-block",children:Y})]}),t.jsxs("div",{className:"flex items-center gap-3",children:[Ie>0?t.jsx("span",{className:"typography-micro text-muted-foreground bg-[var(--surface-muted)] px-1.5 py-0.5 rounded",children:s("settings.agents.page.permissions.globalSummary",{summary:ce})}):t.jsx("span",{className:ge("typography-micro capitalize px-1.5 py-0.5 rounded",ce==="allow"?"text-[var(--status-success)] bg-[var(--status-success)]/10":ce==="deny"?"text-[var(--status-error)] bg-[var(--status-error)]/10":"text-[var(--status-warning)] bg-[var(--status-warning)]/10"),children:ce}),Ie>0&&t.jsx("span",{className:"typography-micro text-muted-foreground bg-[var(--surface-muted)] px-1.5 py-0.5 rounded",children:s("settings.agents.page.permissions.rulesSummary",{summary:Le})})]})]},Y)})})]}),t.jsx("div",{className:"px-2 py-1",children:t.jsx(W,{onClick:Fe,disabled:H||!Ee,size:"xs",className:"!font-normal",children:s(H?"settings.common.actions.saving":"settings.common.actions.saveChanges")})})]})}):t.jsx("div",{className:"flex h-full items-center justify-center",children:t.jsxs("div",{className:"text-center text-muted-foreground",children:[t.jsx(F,{name:"robot-2",className:"mx-auto mb-3 h-12 w-12 opacity-50"}),t.jsx("p",{className:"typography-body",children:s("settings.agents.page.empty.title")}),t.jsx("p",{className:"typography-meta mt-1 opacity-75",children:s("settings.agents.page.empty.description")})]})})},Im="~/.config/opencode/AGENTS.md",al=async(s,e)=>{const n=await s.json().catch(()=>null);return typeof n?.error=="string"&&n.error.trim()?n.error:e},Dm=s=>s.length>0&&!s.endsWith(`
|
|
1
|
+
import{aa as Kl,c as it,ab as _l,j as t,H as ke,R as l,b as Ws,I as Ln,e as br,L as yr,T as bs,ac as Wl,ad as Hl,ae as Gl,u as ql,g as Jl,k as Ql,o as Yl,C as Xl,S as Zl,af as ec,a5 as tc,D as sc,m as nc,ag as ac,X as Ts,ah as rc,ai as yn,aj as zr,ak as ic,al as oc,am as ka,an as lc,ao as cc,ap as dc,aq as $r,ar as ma,as as Br,f as ta,at as mc,au as _o,av as Wo,aw as uc,ax as Ur,ay as pc,az as gc,aA as hc,aB as fc,aC as Vr,aD as Ae,aE as $n,aF as xc,aG as bc,aH as yc,aI as vc,aJ as jc,aK as wc,aL as Ho,a6 as Nc,aM as kc,aN as Sc,aO as Cc}from"./vendor-.bun-TPgXvEwq.js";import{dP as ha,q as ua,r as pa,dw as Pc,dQ as Ic,dR as Dc,H as F,dS as Ac,B as W,u as ot,y as Cs,dT as Mc,bN as vr,dU as sa,dV as na,dW as aa,D as Qt,X as ns,aI as as,m as ge,c7 as Ec,as as rs,au as is,c6 as Rc,av as os,aY as jr,dX as Tc,dY as un,bH as Kt,b4 as Lt,b3 as Ot,b1 as Bt,b2 as zt,bt as Vt,bQ as Gt,I as nt,dZ as Tn,ap as Ht,t as U,ay as ys,z as gs,dq as Fc,bI as St,bJ as Ct,bK as Rt,bL as Pt,bM as dt,bh as ls,ai as vt,aj as jt,ak as kt,aZ as wr,d_ as xn,bi as Nt,d$ as Go,e0 as Lc,e1 as Oc,e2 as Nr,e3 as Ks,e4 as gn,a$ as qo,az as Ls,o as Xs,T as Oe,e5 as Js,e6 as zc,e7 as $c,e8 as Bc,al as wt,ax as Is,e9 as Uc,ea as Vc,eb as Kc,ec as Zs,p as fa,cb as Kr,v as Za,bY as Jo,E as _c,P as Qo,G as Yo,ce as Wc,Q as _r,db as Hc,dn as Xo,de as Gc,cF as qc,ed as Wr,ee as Jc,ef as Qc,eg as Hr,eh as Yc,ei as Xc,ej as Zc,ek as ed,am as hs,aA as td,el as sd,K as nd,L as ad,a as kr,aJ as Gr,em as qr,en as Jr,aM as wn,eo as Sa,ep as rd,eq as id,R as ct,aC as hn,dC as Mn,aD as Sr,bz as od,er as Ca,es as Qr,et as ld,eu as cd,ev as dd,ew as md,df as Cr,c0 as ud,ex as Pa,U as Fs,ey as pd,b$ as gd,ez as Yr,cm as Ys,eA as hd,eB as Xr,eC as Zr,eD as ei,eE as ti,eF as Ia,cd as Zo,eG as si,eH as fd,eI as ni,eJ as xd,eK as bd,an as xa,eL as yd,eM as vd,eN as jd,eO as wd,eP as Nd,eQ as Da,eR as ai,eS as kd,eT as Sd,eU as Cd,eV as Pd,eW as Id,eX as Aa,eY as Dd,eZ as ri,e_ as In,be as el,e$ as Ad,f0 as Md,f1 as Ed,dN as Rd,f2 as Td,aV as ii,f3 as dn,aU as Fd,f4 as Ld,f5 as oi,f6 as li,$ as Bs,F as Od,S as zd,f7 as $d,cj as Bn,f8 as ci,f9 as Bd,fa as Ud,fb as Vd,bl as er,bm as tr,bn as sr,bo as nr,bp as Rs,bq as Ss,bR as pn,M as En,fc as di,fd as tl,bT as Kd,dj as _d,f as Wd,fe as Ma,ff as Un,bc as Hd,b9 as Vn,bX as Gd,fg as qd,fh as Jd,fi as Qd,fj as Yd}from"./useAppFontEffects-hYm-4PtP.js";import{b as pt,a as Fn,j as Xd,s as Zd}from"./index-D9t9eCUC.js";import{g as em,s as tm}from"./mobileLayoutPreference-Dio-WWkI.js";function sm(){return new Worker(Kl,{type:"module"})}const nm=["typescript","javascript","tsx","jsx","json","markdown"],ar={unified:{poolSize:1,totalASTLRUCacheSize:24,lineDiffType:"none"},split:{poolSize:2,totalASTLRUCacheSize:56,lineDiffType:"word-alt"}};let mi,ui;const pi=s=>{const e=ar[s],n=new _l({workerFactory:sm,poolSize:e.poolSize,totalASTLRUCacheSize:e.totalASTLRUCacheSize},{theme:{light:"pierre-light",dark:"pierre-dark"},langs:nm,lineDiffType:e.lineDiffType,preferredHighlighter:"shiki-wasm"});return n.initialize(),n},am=s=>{if(!(typeof window>"u"))return s==="split"?(ui??=pi("split"),ui):(mi??=pi("unified"),mi)},rm=s=>{const e=it.c(7),{children:n,renderTheme:a}=s,r=rr("unified"),i=rr("split");let o,c;e[0]!==a||e[1]!==i||e[2]!==r?(o=()=>{r&&r.setRenderOptions({theme:a,lineDiffType:ar.unified.lineDiffType}),i&&i.setRenderOptions({theme:a,lineDiffType:ar.split.lineDiffType})},c=[a,i,r],e[0]=a,e[1]=i,e[2]=r,e[3]=o,e[4]=c):(o=e[3],c=e[4]),ke.useEffect(o,c);let d;return e[5]!==n?(d=t.jsx(t.Fragment,{children:n}),e[5]=n,e[6]=d):d=e[6],d},Qb=s=>{const e=it.c(11),{children:n}=s,a=ha();let r,i;if(e[0]!==a?.availableThemes||e[1]!==a?.darkThemeId||e[2]!==a?.lightThemeId){const f=ua(!1),g=ua(!0),u=a?.lightThemeId??f.metadata.id,m=a?.darkThemeId??g.metadata.id;i=a?.availableThemes.find(k=>k.metadata.id===u)??f,r=a?.availableThemes.find(k=>k.metadata.id===m)??g,pa(i),pa(r),e[0]=a?.availableThemes,e[1]=a?.darkThemeId,e[2]=a?.lightThemeId,e[3]=r,e[4]=i}else r=e[3],i=e[4];let o;e[5]!==r.metadata.id||e[6]!==i.metadata.id?(o={light:i.metadata.id,dark:r.metadata.id},e[5]=r.metadata.id,e[6]=i.metadata.id,e[7]=o):o=e[7];const c=o;let d;return e[8]!==n||e[9]!==c?(d=t.jsx(rm,{renderTheme:c,children:n}),e[8]=n,e[9]=c,e[10]=d):d=e[10],d},rr=s=>{const e=it.c(2),n=s===void 0?"unified":s;let a;return e[0]!==n?(a=am(n),e[0]=n,e[1]=a):a=e[1],a};class im extends l.Component{constructor(e){super(e),this.state={hasError:!1}}static getDerivedStateFromError(e){return{hasError:!0,error:e}}componentDidCatch(e,n){this.setState({error:e,errorInfo:n})}handleReset=()=>{this.setState({hasError:!1,error:void 0,errorInfo:void 0})};render(){return this.state.hasError?t.jsx("div",{className:"flex items-center justify-center min-h-screen p-4",children:t.jsxs(Pc,{className:"w-full max-w-md",children:[t.jsx(Ic,{className:"text-center",children:t.jsxs(Dc,{className:"flex items-center justify-center gap-2 text-destructive",children:[t.jsx(F,{name:"chat-3",className:"h-5 w-5"}),this.props.texts.title]})}),t.jsxs(Ac,{className:"space-y-4",children:[t.jsx("p",{className:"text-sm text-muted-foreground text-center",children:this.props.texts.description}),this.props.sessionId&&t.jsxs("div",{className:"text-xs text-muted-foreground text-center",children:[this.props.texts.sessionLabel,": ",this.props.sessionId]}),this.state.error&&t.jsxs("details",{className:"text-xs font-mono bg-muted p-3 rounded",children:[t.jsx("summary",{className:"cursor-pointer hover:bg-interactive-hover/80",children:this.props.texts.detailsSummary}),t.jsx("pre",{className:"mt-2 max-h-48 overflow-auto",children:this.state.error.toString()})]}),t.jsx("div",{className:"flex gap-2",children:t.jsxs(W,{onClick:this.handleReset,variant:"outline",className:"flex-1",children:[t.jsx(F,{name:"restart",className:"h-4 w-4 mr-2"}),this.props.texts.resetAction]})}),t.jsx("div",{className:"text-xs text-muted-foreground text-center",children:this.props.texts.persistentHint})]})]})}):this.props.children}}function om(s){const e=it.c(22),{t:n}=ot();let a;e[0]!==n?(a=n("chat.errorBoundary.title"),e[0]=n,e[1]=a):a=e[1];let r;e[2]!==n?(r=n("chat.errorBoundary.description"),e[2]=n,e[3]=r):r=e[3];let i;e[4]!==n?(i=n("chat.errorBoundary.sessionLabel"),e[4]=n,e[5]=i):i=e[5];let o;e[6]!==n?(o=n("chat.errorBoundary.detailsSummary"),e[6]=n,e[7]=o):o=e[7];let c;e[8]!==n?(c=n("chat.errorBoundary.resetAction"),e[8]=n,e[9]=c):c=e[9];let d;e[10]!==n?(d=n("chat.errorBoundary.persistentHint"),e[10]=n,e[11]=d):d=e[11];let f;e[12]!==a||e[13]!==r||e[14]!==i||e[15]!==o||e[16]!==c||e[17]!==d?(f={title:a,description:r,sessionLabel:i,detailsSummary:o,resetAction:c,persistentHint:d},e[12]=a,e[13]=r,e[14]=i,e[15]=o,e[16]=c,e[17]=d,e[18]=f):f=e[18];let g;return e[19]!==s||e[20]!==f?(g=t.jsx(im,{...s,texts:f}),e[19]=s,e[20]=f,e[21]=g):g=e[21],g}const Yb=s=>{const e=it.c(5),{readOnly:n}=s,a=n===void 0?!1:n,i=Cs(lm)||void 0;let o;e[0]!==a?(o=t.jsx(Mc,{readOnly:a}),e[0]=a,e[1]=o):o=e[1];let c;return e[2]!==i||e[3]!==o?(c=t.jsx(om,{sessionId:i,children:o}),e[2]=i,e[3]=o,e[4]=c):c=e[4],c};function lm(s){return s.currentSessionId}const Kn=()=>{try{const e=Qt.getState().getActiveProject?.();if(e?.path?.trim())return e.path.trim();const n=ns.getDirectory();if(n?.trim())return n.trim()}catch(s){console.warn("[McpConfigStore] Error resolving config directory:",s)}return null},gi=s=>s?Object.entries(s).map(([e,n])=>({key:e,value:n})):[],hi=s=>{const e=s.filter(n=>n.key.trim());if(e.length!==0)return Object.fromEntries(e.map(n=>[n.key.trim(),n.value]))},_n=s=>typeof s!="string"?void 0:s.trim()||void 0,Ea=800,cm=5e3,dm="__default__",ir=new Map,Ra=new Map,sl=s=>s?.trim()||dm,Ta=s=>{ir.delete(sl(s))},Pr=Ws()(Ln(br((s,e)=>({mcpServers:[],selectedMcpName:null,isLoading:!1,mcpDraft:null,setSelectedMcp:n=>s({selectedMcpName:n}),setMcpDraft:n=>s({mcpDraft:n}),loadMcpConfigs:async n=>{const a=Kn(),r=sl(a),i=Date.now(),o=ir.get(r)??0,c=e().mcpServers.length>0;if(!n?.force&&c&&i-o<cm)return!0;const d=Ra.get(r);if(!n?.force&&d)return d;const f=(async()=>{s({isLoading:!0});try{const g=a?`?directory=${encodeURIComponent(a)}`:"",u=await pt(`/api/config/mcp${g}`,{headers:a?{"x-opencode-directory":a}:void 0});if(!u.ok)throw new Error("Failed to load MCP configs");const m=await u.json();return s({mcpServers:m,isLoading:!1}),ir.set(r,Date.now()),!0}catch(g){return console.error("[McpConfigStore] Failed to load MCP configs:",g),s({isLoading:!1}),!1}})();Ra.set(r,f);try{return await f}finally{Ra.delete(r)}},createMcp:async n=>{sa("Creating MCP server configuration…");let a=!1;try{const r=fi(n),i=Kn(),o=i?`?directory=${encodeURIComponent(i)}`:"",c=await pt(`/api/config/mcp/${encodeURIComponent(n.name)}${o}`,{method:"POST",headers:{"Content-Type":"application/json",...i?{"x-opencode-directory":i}:{}},body:JSON.stringify(r)}),d=await c.json().catch(()=>null);if(!c.ok)throw new Error(d?.error||"Failed to create MCP server");return Ta(i),d?.requiresReload?(a=!0,await na({message:d.message,delayMs:d.reloadDelayMs??Ea,scopes:["all"]}),await e().loadMcpConfigs({force:!0}),{ok:!0,reloadFailed:d?.reloadFailed===!0,message:d?.message,warning:d?.warning}):(await e().loadMcpConfigs({force:!0}),{ok:!0,reloadFailed:d?.reloadFailed===!0,message:d?.message,warning:d?.warning})}catch(r){return console.error("[McpConfigStore] Failed to create MCP:",r),{ok:!1}}finally{a||aa()}},updateMcp:async(n,a)=>{sa("Updating MCP server configuration…");let r=!1;try{const i=fi(a),o=Kn(),c=o?`?directory=${encodeURIComponent(o)}`:"",d=await pt(`/api/config/mcp/${encodeURIComponent(n)}${c}`,{method:"PATCH",headers:{"Content-Type":"application/json",...o?{"x-opencode-directory":o}:{}},body:JSON.stringify(i)}),f=await d.json().catch(()=>null);if(!d.ok)throw new Error(f?.error||"Failed to update MCP server");return Ta(o),f?.requiresReload?(r=!0,await na({message:f.message,delayMs:f.reloadDelayMs??Ea,scopes:["all"]}),await e().loadMcpConfigs({force:!0}),{ok:!0,reloadFailed:f?.reloadFailed===!0,message:f?.message,warning:f?.warning}):(await e().loadMcpConfigs({force:!0}),{ok:!0,reloadFailed:f?.reloadFailed===!0,message:f?.message,warning:f?.warning})}catch(i){throw console.error("[McpConfigStore] Failed to update MCP:",i),i}finally{r||aa()}},deleteMcp:async n=>{sa("Deleting MCP server configuration…");let a=!1;try{const r=Kn(),i=r?`?directory=${encodeURIComponent(r)}`:"",o=await pt(`/api/config/mcp/${encodeURIComponent(n)}${i}`,{method:"DELETE",headers:r?{"x-opencode-directory":r}:void 0}),c=await o.json().catch(()=>null);if(!o.ok)throw new Error(c?.error||"Failed to delete MCP server");return Ta(r),c?.requiresReload&&(a=!0,await na({message:c.message,delayMs:c.reloadDelayMs??Ea,scopes:["all"]})),e().selectedMcpName===n&&s({selectedMcpName:null}),await e().loadMcpConfigs({force:!0}),{ok:!0,reloadFailed:c?.reloadFailed===!0,message:c?.message,warning:c?.warning}}catch(r){return console.error("[McpConfigStore] Failed to delete MCP:",r),{ok:!1}}finally{a||aa()}},getMcpByName:n=>e().mcpServers.find(a=>a.name===n)}),{name:"mcp-config-store",storage:yr(()=>vr()),partialize:s=>({selectedMcpName:s.selectedMcpName})}),{name:"mcp-config-store"}));function fi(s){const e={};if(s.scope!==void 0&&(e.scope=s.scope),s.type!==void 0&&(e.type=s.type),(s.type==="local"||s.command!==void 0)&&(e.command=(s.command??[]).filter(n=>n.trim())),(s.type==="remote"||s.url!==void 0)&&(e.url=s.url?.trim()??""),s.environment!==void 0&&(e.environment=hi(s.environment)??{}),s.headers!==void 0&&(e.headers=hi(s.headers)??{}),s.oauthEnabled!==void 0||s.oauthClientId!==void 0||s.oauthClientSecret!==void 0||s.oauthScope!==void 0||s.oauthRedirectUri!==void 0)if(s.oauthEnabled===!1)e.oauth=!1;else{const n={clientId:_n(s.oauthClientId),clientSecret:_n(s.oauthClientSecret),scope:_n(s.oauthScope),redirectUri:_n(s.oauthRedirectUri)};n.clientId||n.clientSecret||n.scope||n.redirectUri?e.oauth=n:s.oauthEnabled?e.oauth={}:e.oauth=!1}if(s.timeout!==void 0){const n=Number(s.timeout);Number.isFinite(n)&&n>0?e.timeout=n:e.timeout=null}return s.enabled!==void 0&&(e.enabled=s.enabled),e}const nl=s=>s.replace(/[-_]/g," ").replace(/\b\w/g,e=>e.toUpperCase()),On=s=>{const e=it.c(39),{className:n}=s,{t:a}=ot(),r=Qt(mm),i=Qt(um),o=Qt(pm),c=as();let d;e[0]!==r?(d=[...r].sort(gm),e[0]=r,e[1]=d):d=e[1];const f=d;let g;e:{if(f.length===0){g=null;break e}let O;e[2]!==i||e[3]!==f?(O=f.find(T=>T.id===i)??f[0],e[2]=i,e[3]=f,e[4]=O):O=e[4],g=O}const u=g;if(c||f.length===0)return null;let m;e[5]!==u||e[6]!==a?(m=u?.label&&u.label.trim().length>0?u.label:u?.path.split("/").filter(Boolean).pop()||u?.path||a("settings.shared.projectSelector.fallbackProject"),e[5]=u,e[6]=a,e[7]=m):m=e[7];const k=m;let h;e[8]!==k?(h=nl(k),e[8]=k,e[9]=h):h=e[9];const v=h;let b;e[10]!==n?(b=ge(n),e[10]=n,e[11]=b):b=e[11];let R;e[12]!==a?(R=a("settings.shared.projectSelector.switchProjectAria"),e[12]=a,e[13]=R):R=e[13];let S;e[14]!==a?(S=a("settings.shared.projectSelector.switchProjectTitle"),e[14]=a,e[15]=S):S=e[15];let j,E;e[16]===Symbol.for("react.memo_cache_sentinel")?(j=ge("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"),E=t.jsx(F,{name:"folder",className:"h-4 w-4 opacity-70"}),e[16]=j,e[17]=E):(j=e[16],E=e[17]);let P;e[18]!==v?(P=t.jsx("span",{className:"min-w-0 flex-1 truncate typography-ui-label font-medium",children:v}),e[18]=v,e[19]=P):P=e[19];let N;e[20]===Symbol.for("react.memo_cache_sentinel")?(N=t.jsx(F,{name:"arrow-down-s",className:"size-4 opacity-50"}),e[20]=N):N=e[20];let x;e[21]!==P||e[22]!==R||e[23]!==S?(x=t.jsx(rs,{asChild:!0,children:t.jsxs("button",{type:"button","aria-label":R,title:S,className:j,children:[E,P,N]})}),e[21]=P,e[22]=R,e[23]=S,e[24]=x):x=e[24];const y=u?.id??"";let z;e[25]!==o?(z=O=>{O&&o(O)},e[25]=o,e[26]=z):z=e[26];let L;e[27]!==f?(L=f.map(hm),e[27]=f,e[28]=L):L=e[28];let I;e[29]!==y||e[30]!==z||e[31]!==L?(I=t.jsx(is,{align:"start",className:"w-auto",children:t.jsx(Rc,{value:y,onValueChange:z,children:L})}),e[29]=y,e[30]=z,e[31]=L,e[32]=I):I=e[32];let A;e[33]!==x||e[34]!==I?(A=t.jsxs(os,{children:[x,I]}),e[33]=x,e[34]=I,e[35]=A):A=e[35];let w;return e[36]!==A||e[37]!==b?(w=t.jsx("div",{className:b,children:A}),e[36]=A,e[37]=b,e[38]=w):w=e[38],w};function mm(s){return s.projects}function um(s){return s.activeProjectId}function pm(s){return s.setActiveProject}function gm(s,e){return(s.label||s.path).localeCompare(e.label||e.path)}function hm(s){const e=s.label?.trim()?s.label.trim():s.path.split("/").filter(Boolean).pop()||s.path,n=nl(e);return t.jsx(Ec,{value:s.id,children:t.jsx("span",{className:"min-w-0 truncate typography-ui",children:n})},s.id)}function fm(s,e){return`opencode:sidebar-group:${s}:${e}`}const or=s=>{const e=it.c(33),{label:n,count:a,storageKey:r,defaultExpanded:i,children:o}=s,c=i===void 0?!0:i;let d;e[0]!==n||e[1]!==r?(d=fm(r,n),e[0]=n,e[1]=r,e[2]=d):d=e[2];const f=d,g=l.useId();let u;e[3]!==c||e[4]!==f?(u=()=>{try{const I=localStorage.getItem(f);if(I!==null)return I==="true"}catch{}return c},e[3]=c,e[4]=f,e[5]=u):u=e[5];const[m,k]=ke.useState(u);let h,v;e[6]!==m||e[7]!==f?(h=()=>{try{localStorage.setItem(f,String(m))}catch{}},v=[f,m],e[6]=m,e[7]=f,e[8]=h,e[9]=v):(h=e[8],v=e[9]),ke.useEffect(h,v);let b;e[10]===Symbol.for("react.memo_cache_sentinel")?(b=()=>k(xm),e[10]=b):b=e[10];let R;e[11]===Symbol.for("react.memo_cache_sentinel")?(R=ge("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]=R):R=e[11];const S=!m&&"-rotate-90";let j;e[12]!==S?(j=ge("h-3.5 w-3.5 flex-shrink-0 transition-transform duration-200",S),e[12]=S,e[13]=j):j=e[13];let E;e[14]!==j?(E=t.jsx(F,{name:"arrow-down-s",className:j}),e[14]=j,e[15]=E):E=e[15];let P;e[16]!==n?(P=t.jsx("span",{className:"flex-1 truncate",children:n}),e[16]=n,e[17]=P):P=e[17];let N;e[18]!==a?(N=t.jsx("span",{className:"ml-1 tabular-nums opacity-60",children:a}),e[18]=a,e[19]=N):N=e[19];let x;e[20]!==g||e[21]!==m||e[22]!==E||e[23]!==P||e[24]!==N?(x=t.jsxs("button",{type:"button",onClick:b,"aria-expanded":m,"aria-controls":g,className:R,children:[E,P,N]}),e[20]=g,e[21]=m,e[22]=E,e[23]=P,e[24]=N,e[25]=x):x=e[25];const y=!m;let z;e[26]!==o||e[27]!==g||e[28]!==y?(z=t.jsx("div",{id:g,hidden:y,className:"mt-0.5 space-y-0.5 ml-2 pl-3 border-l-2 border-[var(--interactive-border)]",children:o}),e[26]=o,e[27]=g,e[28]=y,e[29]=z):z=e[29];let L;return e[30]!==x||e[31]!==z?(L=t.jsxs("div",{children:[x,z]}),e[30]=x,e[31]=z,e[32]=L):L=e[32],L};function xm(s){return!s}const bm=s=>{if(!Array.isArray(s))return[];const e=[];for(const n of s){if(!n||typeof n!="object")continue;const a=n;typeof a.permission!="string"||typeof a.pattern!="string"||typeof a.action!="string"||a.action!=="allow"&&a.action!=="ask"&&a.action!=="deny"||e.push({permission:a.permission,pattern:a.pattern,action:a.action})}return e},ym=s=>{const e=new Map;for(const n of s)!n.permission||n.permission==="invalid"||n.pattern&&e.set(`${n.permission}::${n.pattern}`,n);return Array.from(e.values())},xi=s=>{const e=ym(bm(s));if(e.length===0)return;const n={};for(const r of e)r.permission&&((n[r.permission]||={})[r.pattern]=r.action);const a={};for(const[r,i]of Object.entries(n)){const o=Object.keys(i);if(o.length===1&&o[0]==="*"){a[r]=i["*"];continue}a[r]=i}return Object.keys(a).length>0?a:void 0},vm=({onItemSelect:s})=>{const{t:e}=ot(),[n,a]=l.useState(null),[r,i]=l.useState(""),[o,c]=l.useState(null),[d,f]=l.useState(null),[g,u]=l.useState(!1),[m,k]=l.useState(null),{selectedAgentName:h,agents:v,setSelectedAgent:b,setAgentDraft:R,createAgent:S,deleteAgent:j,loadAgents:E}=jr(bs(D=>({selectedAgentName:D.selectedAgentName,agents:D.agents,setSelectedAgent:D.setSelectedAgent,setAgentDraft:D.setAgentDraft,createAgent:D.createAgent,deleteAgent:D.deleteAgent,loadAgents:D.loadAgents})));l.useEffect(()=>{E()},[E]);const P="bg-background",N=()=>{const D="new-agent";let K=D,C=1;for(;v.some(H=>H.name===K);)K=`${D}-${C}`,C++;R({name:K,scope:"user"}),b(K),s?.()},x=async D=>{if(un(D)){U.error(e("settings.agents.sidebar.toast.builtInCannotDelete"));return}c(D),f("delete")},y=async D=>{un(D)&&(c(D),f("reset"))},z=()=>{c(null),f(null)},L=async()=>{if(!o||!d)return;u(!0),await j(o.name)?(d==="delete"?U.success(e("settings.agents.sidebar.toast.agentDeleted",{name:o.name})):U.success(e("settings.agents.sidebar.toast.agentReset",{name:o.name})),z()):d==="delete"?U.error(e("settings.agents.sidebar.toast.deleteFailed")):U.error(e("settings.agents.sidebar.toast.resetFailed")),u(!1)},I=D=>{const K=D.name;let C=1,H=`${K}-copy`;for(;v.some(re=>re.name===H);)C++,H=`${K}-copy-${C}`;const G=D,se=D.model?.providerID&&D.model?.modelID?`${D.model.providerID}/${D.model.modelID}`:null,oe=D;R({name:H,scope:G.scope||"user",description:D.description,model:se,temperature:D.temperature,top_p:D.topP,prompt:D.prompt,mode:D.mode,permission:xi(D.permission),disable:oe.disable}),b(H)},A=D=>{i(D.name),a(D)},w=async()=>{if(!n)return;const D=r.trim().replace(/\s+/g,"-");if(!D){U.error(e("settings.agents.sidebar.toast.agentNameRequired"));return}if(D===n.name){a(null);return}if(v.some(G=>G.name===D)){U.error(e("settings.agents.sidebar.toast.agentExists"));return}const K=n.model?.providerID&&n.model?.modelID?`${n.model.providerID}/${n.model.modelID}`:null,C=n;await S({name:D,description:n.description,model:K,temperature:n.temperature,top_p:n.topP,prompt:n.prompt,mode:n.mode,permission:xi(n.permission),disable:C.disable,scope:C.scope})?await j(n.name)?(U.success(`Agent renamed to "${D}"`),b(D)):U.error(e("settings.agents.sidebar.toast.removeOldAfterRenameFailed")):U.error(e("settings.agents.sidebar.toast.renameFailed")),a(null)},O=D=>{switch(D){case"primary":return t.jsx(F,{name:"ai-agent",className:"h-3 w-3 text-primary"});case"all":return t.jsx(F,{name:"ai-agent-fill",className:"h-3 w-3 text-primary"});case"subagent":return t.jsx(F,{name:"robot",className:"h-3 w-3 text-primary"});default:return null}},T=v.filter(D=>!Tc(D)),_=T.filter(un),V=T.filter(D=>!un(D)),{groupedCustomAgents:J,ungroupedCustomAgents:B}=ke.useMemo(()=>{const D={},K=[];for(const H of V){const G=H;G.group?(D[G.group]||(D[G.group]=[]),D[G.group].push(H)):K.push(H)}return{groupedCustomAgents:Object.keys(D).sort((H,G)=>H.localeCompare(G)).map(H=>({name:H,agents:D[H]})),ungroupedCustomAgents:K}},[V]);return t.jsxs("div",{className:ge("flex h-full flex-col",P),children:[t.jsxs("div",{className:"border-b px-3 pt-4 pb-3",children:[t.jsx("h2",{className:"text-base font-semibold text-foreground mb-3",children:e("settings.agents.sidebar.title")}),t.jsx(On,{className:"mb-3"}),t.jsxs("div",{className:"flex items-center justify-between gap-2",children:[t.jsx("span",{className:"typography-meta text-muted-foreground",children:e("settings.agents.sidebar.total",{count:T.length})}),t.jsx(W,{size:"sm",variant:"ghost",className:"h-7 w-7 px-0 -my-1 text-muted-foreground",onClick:N,children:t.jsx(F,{name:"add",className:"h-3.5 w-3.5"})})]})]}),t.jsx(Kt,{outerClassName:"flex-1 min-h-0",className:"space-y-1 px-3 py-2 overflow-x-hidden",children:T.length===0?t.jsxs("div",{className:"py-12 px-4 text-center text-muted-foreground",children:[t.jsx(F,{name:"robot-2",className:"mx-auto mb-3 h-10 w-10 opacity-50"}),t.jsx("p",{className:"typography-ui-label font-medium",children:e("settings.agents.sidebar.empty.title")}),t.jsx("p",{className:"typography-meta mt-1 opacity-75",children:e("settings.agents.sidebar.empty.description")})]}):t.jsxs(t.Fragment,{children:[_.length>0&&t.jsxs(t.Fragment,{children:[t.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(D=>t.jsx(Fa,{agent:D,isSelected:h===D.name,onSelect:()=>{b(D.name),s?.()},onReset:()=>y(D),onDuplicate:()=>I(D),getAgentModeIcon:O,isMenuOpen:m===D.name,onMenuOpenChange:K=>k(K?D.name:null)},D.name))]}),V.length>0&&t.jsxs(t.Fragment,{children:[t.jsx("div",{className:"px-2 pb-1.5 pt-3 text-xs font-semibold uppercase tracking-wide text-muted-foreground",children:e("settings.agents.sidebar.section.custom")}),J.map(({name:D,agents:K})=>t.jsx(or,{label:D,count:K.length,storageKey:"agents",children:K.map(C=>t.jsx(Fa,{agent:C,isSelected:h===C.name,onSelect:()=>{b(C.name),s?.()},onRename:()=>A(C),onDelete:()=>x(C),onDuplicate:()=>I(C),getAgentModeIcon:O,isMenuOpen:m===C.name,onMenuOpenChange:H=>k(H?C.name:null)},C.name))},D)),B.map(D=>t.jsx(Fa,{agent:D,isSelected:h===D.name,onSelect:()=>{b(D.name),s?.()},onRename:()=>A(D),onDelete:()=>x(D),onDuplicate:()=>I(D),getAgentModeIcon:O,isMenuOpen:m===D.name,onMenuOpenChange:K=>k(K?D.name:null)},D.name))]})]})}),t.jsx(Lt,{open:o!==null&&d!==null,onOpenChange:D=>{!D&&!g&&z()},children:t.jsxs(Ot,{className:"max-w-md",children:[t.jsxs(Bt,{children:[t.jsx(zt,{children:e(d==="delete"?"settings.agents.sidebar.dialog.deleteTitle":"settings.agents.sidebar.dialog.resetTitle")}),t.jsx(Vt,{children:d==="delete"?e("settings.agents.sidebar.dialog.deleteDescription",{name:o?.name??""}):e("settings.agents.sidebar.dialog.resetDescription",{name:o?.name??""})})]}),t.jsxs(Gt,{children:[t.jsx(W,{size:"sm",variant:"ghost",onClick:z,disabled:g,children:e("settings.common.actions.cancel")}),t.jsx(W,{size:"sm",onClick:L,disabled:g,children:e(d==="delete"?"settings.common.actions.delete":"settings.common.actions.reset")})]})]})}),t.jsx(Lt,{open:n!==null,onOpenChange:D=>!D&&a(null),children:t.jsxs(Ot,{children:[t.jsxs(Bt,{children:[t.jsx(zt,{children:e("settings.agents.sidebar.renameDialog.title")}),t.jsx(Vt,{children:e("settings.agents.sidebar.renameDialog.description",{name:n?.name??""})})]}),t.jsx(nt,{value:r,onChange:D=>i(D.target.value),placeholder:e("settings.agents.sidebar.renameDialog.placeholder"),className:"text-foreground placeholder:text-muted-foreground",onKeyDown:D=>{D.key==="Enter"&&w()}}),t.jsxs(Gt,{children:[t.jsx(W,{size:"sm",variant:"ghost",onClick:()=>a(null),children:e("settings.common.actions.cancel")}),t.jsx(W,{size:"sm",onClick:w,children:e("settings.common.actions.rename")})]})]})})]})},Fa=s=>{const e=it.c(58),{agent:n,isSelected:a,onSelect:r,onDelete:i,onReset:o,onRename:c,onDuplicate:d,getAgentModeIcon:f,isMenuOpen:g,onMenuOpenChange:u}=s,{t:m}=ot(),k=n;let h;e[0]===Symbol.for("react.memo_cache_sentinel")?(h=Tn(),e[0]=h):h=e[0];const v=h,b=a?"bg-interactive-selection":"hover:bg-interactive-hover";let R;e[1]!==b?(R=ge("group relative flex items-center rounded-md px-1.5 py-1 transition-all duration-200 select-none",b),e[1]=b,e[2]=R):R=e[2];let S;e[3]!==u?(S=v?void 0:K=>{K.preventDefault(),u(!0)},e[3]=u,e[4]=S):S=e[4];let j;e[5]!==n.name?(j=t.jsx("span",{className:"typography-ui-label font-normal truncate text-foreground",children:n.name}),e[5]=n.name,e[6]=j):j=e[6];let E;e[7]!==n.mode||e[8]!==f?(E=f(n.mode),e[7]=n.mode,e[8]=f,e[9]=E):E=e[9];let P;e[10]!==n||e[11]!==k.scope||e[12]!==m?(P=(k.scope||un(n))&&t.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:un(n)?m("settings.agents.sidebar.badge.system"):k.scope}),e[10]=n,e[11]=k.scope,e[12]=m,e[13]=P):P=e[13];let N;e[14]!==j||e[15]!==E||e[16]!==P?(N=t.jsxs("div",{className:"flex items-center gap-1.5",children:[j,E,P]}),e[14]=j,e[15]=E,e[16]=P,e[17]=N):N=e[17];let x;e[18]!==n.description?(x=n.description&&t.jsx("div",{className:"typography-micro text-muted-foreground/60 truncate leading-tight",children:n.description}),e[18]=n.description,e[19]=x):x=e[19];let y;e[20]!==r||e[21]!==N||e[22]!==x?(y=t.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:[N,x]}),e[20]=r,e[21]=N,e[22]=x,e[23]=y):y=e[23];let z;e[24]===Symbol.for("react.memo_cache_sentinel")?(z=t.jsx(rs,{asChild:!0,children:t.jsx(W,{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:t.jsx(F,{name:"more-2",className:"h-3.5 w-3.5"})})}),e[24]=z):z=e[24];let L;e[25]!==c||e[26]!==m?(L=c&&t.jsxs(Ht,{onClick:K=>{K.stopPropagation(),c()},children:[t.jsx(F,{name:"edit",className:"h-4 w-4 mr-px"}),m("settings.common.actions.rename")]}),e[25]=c,e[26]=m,e[27]=L):L=e[27];let I;e[28]!==d?(I=K=>{K.stopPropagation(),d()},e[28]=d,e[29]=I):I=e[29];let A;e[30]===Symbol.for("react.memo_cache_sentinel")?(A=t.jsx(F,{name:"file-copy",className:"h-4 w-4 mr-px"}),e[30]=A):A=e[30];let w;e[31]!==m?(w=m("settings.common.actions.duplicate"),e[31]=m,e[32]=w):w=e[32];let O;e[33]!==I||e[34]!==w?(O=t.jsxs(Ht,{onClick:I,children:[A,w]}),e[33]=I,e[34]=w,e[35]=O):O=e[35];let T;e[36]!==o||e[37]!==m?(T=o&&t.jsxs(Ht,{onClick:K=>{K.stopPropagation(),o()},children:[t.jsx(F,{name:"restart",className:"h-4 w-4 mr-px"}),m("settings.common.actions.reset")]}),e[36]=o,e[37]=m,e[38]=T):T=e[38];let _;e[39]!==i||e[40]!==m?(_=i&&t.jsxs(Ht,{onClick:K=>{K.stopPropagation(),i()},className:"text-destructive focus:text-destructive",children:[t.jsx(F,{name:"delete-bin",className:"h-4 w-4 mr-px"}),m("settings.common.actions.delete")]}),e[39]=i,e[40]=m,e[41]=_):_=e[41];let V;e[42]!==L||e[43]!==O||e[44]!==T||e[45]!==_?(V=t.jsxs(is,{align:"end",className:"w-fit min-w-20",children:[L,O,T,_]}),e[42]=L,e[43]=O,e[44]=T,e[45]=_,e[46]=V):V=e[46];let J;e[47]!==g||e[48]!==u||e[49]!==V?(J=t.jsxs(os,{open:g,onOpenChange:u,children:[z,V]}),e[47]=g,e[48]=u,e[49]=V,e[50]=J):J=e[50];let B;e[51]!==y||e[52]!==J?(B=t.jsxs("div",{className:"flex min-w-0 flex-1 items-center",children:[y,J]}),e[51]=y,e[52]=J,e[53]=B):B=e[53];let D;return e[54]!==B||e[55]!==R||e[56]!==S?(D=t.jsx("div",{className:R,onContextMenu:S,children:B}),e[54]=B,e[55]=R,e[56]=S,e[57]=D):D=e[57],D};function bi(s,e,n){return Math.min(n,Math.max(e,s))}function jm(s){if(!Number.isFinite(s))return 0;const e=String(s);if(e.includes("e-")){const[,a]=e.split("e-");return Number(a)||0}const n=e.split(".");return n.length===2?n[1].length:0}function yi(s,e){const n=jm(e);return n<=0?s:Number(s.toFixed(n))}const ms=ke.forwardRef((s,e)=>{const n=it.c(125);let a,r,i,o,c,d,f,g,u,m,k,h,v;n[0]!==s?({value:v,onValueChange:f,min:u,max:m,step:k,className:a,containerClassName:r,onBlur:c,disabled:i,fallbackValue:o,onClear:d,emptyLabel:h,...g}=s,n[0]=s,n[1]=a,n[2]=r,n[3]=i,n[4]=o,n[5]=c,n[6]=d,n[7]=f,n[8]=g,n[9]=u,n[10]=m,n[11]=k,n[12]=h,n[13]=v):(a=n[1],r=n[2],i=n[3],o=n[4],c=n[5],d=n[6],f=n[7],g=n[8],u=n[9],m=n[10],k=n[11],h=n[12],v=n[13]);const b=u===void 0?-1/0:u,R=m===void 0?1/0:m,S=k===void 0?1:k,j=h===void 0?"—":h,{t:E}=ot();let P;n[14]!==v?(P=()=>v===void 0?"":String(v),n[14]=v,n[15]=P):P=n[15];const[N,x]=ke.useState(P),{isMobile:y}=ys(),z=ke.useRef(!1),L=ke.useRef(null);let I;n[16]===Symbol.for("react.memo_cache_sentinel")?(I=()=>{if(typeof document>"u"||typeof window>"u")return;L.current?.();const Ee=fe=>{fe.preventDefault(),fe.stopPropagation(),fe.stopImmediatePropagation?.(),L.current?.()},Fe=window.setTimeout(()=>{L.current?.()},700),Y=()=>{window.clearTimeout(Fe),document.removeEventListener("click",Ee,!0),L.current=null};L.current=Y,document.addEventListener("click",Ee,!0)},n[16]=I):I=n[16];const A=I;let w,O;n[17]===Symbol.for("react.memo_cache_sentinel")?(w=()=>()=>{L.current?.()},O=[],n[17]=w,n[18]=O):(w=n[17],O=n[18]),ke.useEffect(w,O);let T,_;n[19]!==v?(_=()=>{x(v===void 0?"":String(v))},T=[v],n[19]=v,n[20]=T,n[21]=_):(T=n[20],_=n[21]),ke.useEffect(_,T);let V;e:{if(v!==void 0){V=v;break e}if(o!==void 0){V=o;break e}if(Number.isFinite(b)){V=b;break e}V=0}const J=V;let B;n[22]!==R||n[23]!==b||n[24]!==f||n[25]!==S?(B=Ee=>{const Fe=bi(Ee,b,R);f(yi(Fe,S))},n[22]=R,n[23]=b,n[24]=f,n[25]=S,n[26]=B):B=n[26];const D=B;let K;n[27]!==D||n[28]!==d?(K=Ee=>{const Fe=Ee.target.value;if(x(Fe),Fe.trim()===""){d?.();return}const Y=Number(Fe);Number.isFinite(Y)&&D(Y)},n[27]=D,n[28]=d,n[29]=K):K=n[29];const C=K;let H;n[30]!==N||n[31]!==R||n[32]!==b||n[33]!==c||n[34]!==d||n[35]!==f||n[36]!==S||n[37]!==v?(H=Ee=>{if(N.trim()===""){d||x(v===void 0?"":String(v)),c?.(Ee);return}const Fe=Number(N);if(!Number.isFinite(Fe))x(v===void 0?"":String(v));else{const Y=bi(Fe,b,R),fe=yi(Y,S);fe!==v&&f(fe),x(String(fe))}c?.(Ee)},n[30]=N,n[31]=R,n[32]=b,n[33]=c,n[34]=d,n[35]=f,n[36]=S,n[37]=v,n[38]=H):H=n[38];const G=H,se=!!(i||J>=R),oe=!!(i||J<=b);let re;n[39]!==J||n[40]!==D||n[41]!==oe||n[42]!==S?(re=()=>{oe||D(J-S)},n[39]=J,n[40]=D,n[41]=oe,n[42]=S,n[43]=re):re=n[43];const me=re;let le;n[44]!==J||n[45]!==D||n[46]!==se||n[47]!==S?(le=()=>{se||D(J+S)},n[44]=J,n[45]=D,n[46]=se,n[47]=S,n[48]=le):le=n[48];const ve=le;let Z;if(n[49]!==a||n[50]!==r||n[51]!==oe||n[52]!==N||n[53]!==j||n[54]!==me||n[55]!==ve||n[56]!==se||n[57]!==y||n[58]!==E||n[59]!==v){Z=Symbol.for("react.early_return_sentinel");e:{const Ee=Y=>fe=>{fe.preventDefault(),fe.stopPropagation(),z.current=!0,A(),Y()},Fe=Y=>fe=>{if(z.current){z.current=!1,fe.preventDefault(),fe.stopPropagation();return}Y()};if(y){let Y;n[61]!==r?(Y=ge("flex h-9 shrink-0 items-stretch overflow-x-hidden overflow-y-hidden rounded-lg border border-border bg-transparent select-none overscroll-contain","[-webkit-user-select:none] [-webkit-touch-callout:none]","disabled:pointer-events-none disabled:opacity-50",r),n[61]=r,n[62]=Y):Y=n[62];let fe;n[63]!==E?(fe=E("numberInput.actions.decreaseAria"),n[63]=E,n[64]=fe):fe=n[64];const Ce=Ee(me),Ie=Fe(me),Le=!oe&&"active:bg-interactive-hover";let $e;n[65]!==Le?($e=ge("grid h-full min-h-0 w-9 place-items-center overflow-x-hidden overflow-y-hidden border-r border-border p-0 leading-none touch-none","text-muted-foreground","disabled:pointer-events-none disabled:opacity-50",Le),n[65]=Le,n[66]=$e):$e=n[66];let te;n[67]===Symbol.for("react.memo_cache_sentinel")?(te=t.jsx(F,{name:"subtract",className:"block h-4 w-4"}),n[67]=te):te=n[67];const ce=t.jsx("button",{type:"button","aria-label":fe,disabled:oe,onTouchStart:Ce,onClick:Ie,className:$e,children:te});let Se;n[68]!==a?(Se=ge("flex h-full min-w-0 w-14 items-center justify-center bg-transparent px-1.5","text-center text-[16px] leading-none text-foreground [font-variant-numeric:tabular-nums]",a),n[68]=a,n[69]=Se):Se=n[69];const Ue=v===void 0?j:N;let Ke;n[70]!==Se||n[71]!==Ue?(Ke=t.jsx("div",{className:Se,"aria-live":"polite",children:Ue}),n[70]=Se,n[71]=Ue,n[72]=Ke):Ke=n[72];let Ye;n[73]!==E?(Ye=E("numberInput.actions.increaseAria"),n[73]=E,n[74]=Ye):Ye=n[74];const Xe=Ee(ve),Ze=Fe(ve),p=!se&&"active:bg-interactive-hover";let ee;n[75]!==p?(ee=ge("grid h-full min-h-0 w-9 place-items-center overflow-x-hidden overflow-y-hidden border-l border-border p-0 leading-none touch-none","text-muted-foreground","disabled:pointer-events-none disabled:opacity-50",p),n[75]=p,n[76]=ee):ee=n[76];let De;n[77]===Symbol.for("react.memo_cache_sentinel")?(De=t.jsx(F,{name:"add",className:"block h-4 w-4"}),n[77]=De):De=n[77];const Te=t.jsx("button",{type:"button","aria-label":Ye,disabled:se,onTouchStart:Xe,onClick:Ze,className:ee,children:De});let We;n[78]!==Y||n[79]!==ce||n[80]!==Ke||n[81]!==Te?(We=t.jsxs("div",{className:Y,children:[ce,Ke,Te]}),n[78]=Y,n[79]=ce,n[80]=Ke,n[81]=Te,n[82]=We):We=n[82],Z=We;break e}}n[49]=a,n[50]=r,n[51]=oe,n[52]=N,n[53]=j,n[54]=me,n[55]=ve,n[56]=se,n[57]=y,n[58]=E,n[59]=v,n[60]=Z}else Z=n[60];if(Z!==Symbol.for("react.early_return_sentinel"))return Z;let X;n[83]!==r?(X=ge("flex h-7 shrink-0 items-stretch overflow-x-hidden overflow-y-hidden rounded-lg border border-border bg-transparent","disabled:pointer-events-none disabled:opacity-50",r),n[83]=r,n[84]=X):X=n[84];let xe;n[85]!==E?(xe=E("numberInput.actions.decreaseAria"),n[85]=E,n[86]=xe):xe=n[86];let ue;n[87]!==J||n[88]!==D||n[89]!==S?(ue=()=>D(J-S),n[87]=J,n[88]=D,n[89]=S,n[90]=ue):ue=n[90];let be,de;n[91]===Symbol.for("react.memo_cache_sentinel")?(be=ge("flex h-full w-7 items-center justify-center overflow-x-hidden overflow-y-hidden border-r border-border p-0 leading-none touch-manipulation","text-muted-foreground hover:bg-interactive-hover hover:text-foreground","disabled:pointer-events-none disabled:opacity-50"),de=t.jsx(F,{name:"subtract",className:"block h-3.5 w-3.5"}),n[91]=be,n[92]=de):(be=n[91],de=n[92]);let we;n[93]!==oe||n[94]!==xe||n[95]!==ue?(we=t.jsx("button",{type:"button","aria-label":xe,disabled:oe,onClick:ue,className:be,children:de}),n[93]=oe,n[94]=xe,n[95]=ue,n[96]=we):we=n[96];const Q=g.inputMode??"numeric";let he;n[97]!==a?(he=ge("h-full min-w-0 w-14 bg-transparent px-1.5 text-center typography-ui-label leading-none text-foreground [font-variant-numeric:tabular-nums]","placeholder:text-muted-foreground selection:bg-primary selection:text-primary-foreground","appearance-none outline-none [appearance:textfield] [scrollbar-width:none] [&::-webkit-scrollbar]:hidden","disabled:pointer-events-none disabled:cursor-not-allowed",a),n[97]=a,n[98]=he):he=n[98];let q;n[99]!==i||n[100]!==N||n[101]!==G||n[102]!==C||n[103]!==g||n[104]!==e||n[105]!==Q||n[106]!==he?(q=t.jsx("input",{...g,ref:e,type:"text",inputMode:Q,value:N,onChange:C,onBlur:G,disabled:i,spellCheck:!1,autoComplete:"off",autoCorrect:"off",autoCapitalize:"off",className:he}),n[99]=i,n[100]=N,n[101]=G,n[102]=C,n[103]=g,n[104]=e,n[105]=Q,n[106]=he,n[107]=q):q=n[107];let ae;n[108]!==E?(ae=E("numberInput.actions.increaseAria"),n[108]=E,n[109]=ae):ae=n[109];let pe;n[110]!==J||n[111]!==D||n[112]!==S?(pe=()=>D(J+S),n[110]=J,n[111]=D,n[112]=S,n[113]=pe):pe=n[113];let je,Me;n[114]===Symbol.for("react.memo_cache_sentinel")?(je=ge("flex h-full w-7 items-center justify-center overflow-x-hidden overflow-y-hidden border-l border-border p-0 leading-none touch-manipulation","text-muted-foreground hover:bg-interactive-hover hover:text-foreground","disabled:pointer-events-none disabled:opacity-50"),Me=t.jsx(F,{name:"add",className:"block h-3.5 w-3.5"}),n[114]=je,n[115]=Me):(je=n[114],Me=n[115]);let Pe;n[116]!==se||n[117]!==ae||n[118]!==pe?(Pe=t.jsx("button",{type:"button","aria-label":ae,disabled:se,onClick:pe,className:je,children:Me}),n[116]=se,n[117]=ae,n[118]=pe,n[119]=Pe):Pe=n[119];let Re;return n[120]!==X||n[121]!==we||n[122]!==q||n[123]!==Pe?(Re=t.jsxs("div",{className:X,children:[we,q,Pe]}),n[120]=X,n[121]=we,n[122]=q,n[123]=Pe,n[124]=Re):Re=n[124],Re});ms.displayName="NumberInput";const vi=["*","read","edit","glob","grep","list","bash","task","skill","lsp","todoread","todowrite","webfetch","websearch","codesearch","external_directory","doom_loop","question","plan_enter","plan_exit"],ra=s=>s==="allow"||s==="ask"||s==="deny",Qs=(s,e)=>`${s}::${e}`,en=s=>{const e=new Map;for(const n of s)!n.permission||n.permission==="invalid"||n.pattern&&ra(n.action)&&e.set(Qs(n.permission,n.pattern),{permission:n.permission,pattern:n.pattern,action:n.action});return Array.from(e.values())},Wn=s=>{const e=new Map;for(const n of en(s))e.set(Qs(n.permission,n.pattern),n);return e},ji=s=>[...s].sort((e,n)=>{const a=e.permission.localeCompare(n.permission);return a!==0?a:e.pattern.localeCompare(n.pattern)}),wm=(s,e)=>{const n=ji(en(s)),a=ji(en(e));return n.length!==a.length?!1:n.every((r,i)=>{const o=a[i];return r.permission===o.permission&&r.pattern===o.pattern&&r.action===o.action})},Nm=s=>s.find(n=>n.permission==="*"&&n.pattern==="*")?.action??"allow",km=(s,e)=>en(s).filter(n=>!(n.permission==="*"&&n.pattern==="*")).filter(n=>n.pattern!=="*"||n.action!==e),Sm=s=>{if(ra(s))return[{permission:"*",pattern:"*",action:s}];if(!s||typeof s!="object"||Array.isArray(s))return[];const e=[];for(const[n,a]of Object.entries(s))if(n!=="__originalKeys"){if(ra(a)){e.push({permission:n,pattern:"*",action:a});continue}if(a&&typeof a=="object"&&!Array.isArray(a))for(const[r,i]of Object.entries(a))ra(i)&&e.push({permission:n,pattern:r,action:i})}return e},Cm=(s,e)=>{const n=en(e),a={};for(const i of n)(a[i.permission]||={})[i.pattern]=i.action;const r={"*":s};for(const[i,o]of Object.entries(a))if(i!=="*"){if(Object.keys(o).length===1&&o["*"]){r[i]=o["*"];continue}r[i]=o}return r},Pm=()=>{const{t:s}=ot(),{isMobile:e}=ys(),{selectedAgentName:n,getAgentByName:a,createAgent:r,updateAgent:i,agents:o,agentDraft:c,setAgentDraft:d}=jr(bs(Y=>({selectedAgentName:Y.selectedAgentName,getAgentByName:Y.getAgentByName,createAgent:Y.createAgent,updateAgent:Y.updateAgent,agents:Y.agents,agentDraft:Y.agentDraft,setAgentDraft:Y.setAgentDraft}))),f=n?a(n):null,g=!!(c&&c.name===n&&!f),[u,m]=l.useState(""),[k,h]=l.useState("user"),[v,b]=l.useState(""),[R,S]=l.useState("subagent"),[j,E]=l.useState(""),[P,N]=l.useState(void 0),[x,y]=l.useState(void 0),[z,L]=l.useState(""),[I,A]=l.useState("allow"),[w,O]=l.useState([]),[T,_]=l.useState([]),[V,J]=l.useState(""),[B,D]=l.useState("*"),[K,C]=l.useState(!1),[H,G]=l.useState(!1),se=l.useRef(null),oe=gs(Y=>Y.currentDirectory??null),[re,me]=l.useState([]),le=Fc(Y=>Y.permission);l.useEffect(()=>{let Y=!1;return(async()=>{const Ce=await ns.listToolIds({directory:oe});if(Y)return;const Ie=new Set(["write","patch","multiedit"]),Le=Ce.map($e=>typeof $e=="string"?$e.trim():"").filter(Boolean).filter($e=>$e!=="*").filter($e=>$e!=="invalid").filter($e=>!Ie.has($e));me(Array.from(new Set(Le)).sort(($e,te)=>$e.localeCompare(te)))})(),()=>{Y=!0}},[oe]);const ve=l.useMemo(()=>{const Y=new Set;for(const fe of o){const Ce=en(Array.isArray(fe.permission)?fe.permission:[]);for(const Ie of Ce)Ie.permission&&Ie.permission!=="*"&&Ie.permission!=="invalid"&&Y.add(Ie.permission)}for(const fe of Object.values(le))for(const Ce of fe){const Ie=Ce.permission?.trim();Ie&&Ie!=="invalid"&&Y.add(Ie)}for(const fe of re)Y.add(fe);return Array.from(Y).sort((fe,Ce)=>fe.localeCompare(Ce))},[o,le,re]),Z=l.useMemo(()=>Wn(w),[w]),X=l.useMemo(()=>Wn(T),[T]),xe=l.useCallback(Y=>X.get(Qs(Y,"*"))?.action,[X]),ue=l.useCallback(Y=>T.filter(fe=>fe.permission===Y&&fe.pattern!=="*").sort((fe,Ce)=>fe.pattern.localeCompare(Ce.pattern)),[T]),be=l.useMemo(()=>{const Y=new Set;for(const fe of vi)Y.add(fe);for(const fe of ve)Y.add(fe);return Array.from(Y).sort((fe,Ce)=>fe.localeCompare(Ce))},[ve]),de=l.useCallback(Y=>{const fe=Y==="*"?I:xe(Y)??I,Ce=ue(Y),Ie=!1,Le=Ce.reduce((te,ce)=>(te[ce.action]=(te[ce.action]??0)+1,te),{allow:0,ask:0,deny:0}),$e=["allow","ask","deny"].filter(te=>Le[te]>0).map(te=>`${Le[te]} ${te}`).join(", ");return{defaultAction:fe,patternRulesCount:Ce.length,patternSummary:$e,hasDefaultHint:Ie}},[ue,xe,I]),we=l.useCallback(Y=>s(Y==="allow"?"settings.common.permission.allow":Y==="deny"?"settings.common.permission.deny":"settings.common.permission.ask"),[s]),Q=l.useCallback(Y=>Y==="global"?s("settings.common.scope.global"):we(Y),[we,s]),he=l.useMemo(()=>{const Y=new Set;for(const fe of vi)Y.add(fe);for(const fe of ve)Y.add(fe);return Array.from(Y).sort((fe,Ce)=>fe.localeCompare(Ce))},[ve]),q=l.useCallback((Y,fe,Ce)=>{_(Ie=>{const Le=Wn(Ie);return Le.set(Qs(Y,fe),{permission:Y,pattern:fe,action:Ce}),Array.from(Le.values())})},[]),ae=l.useCallback((Y,fe)=>{_(Ce=>{const Ie=Wn(Ce);return Ie.delete(Qs(Y,fe)),Array.from(Ie.values())})},[]),pe=l.useCallback((Y,fe)=>{const Ce=Z.get(Qs(Y,fe));if(Ce){q(Y,fe,Ce.action);return}ae(Y,fe)},[Z,ae,q]),je=l.useCallback((Y,fe,Ce)=>{q(Y,fe,Ce)},[q]),Me=l.useCallback(Y=>{A(Y),_(fe=>fe.filter(Ce=>!(Ce.pattern==="*"&&Ce.action===Y)))},[]),Pe=l.useCallback(Y=>{const fe=V.trim();if(!fe){U.error(s("settings.agents.page.toast.permissionNameRequired"));return}const Ce=B.trim()||"*";if(fe==="*"&&Ce==="*"){Me(Y),J(""),D("*");return}Ce==="*"&&fe!=="*"&&Y===I?ae(fe,"*"):q(fe,Ce,Y),J(""),D("*")},[I,V,B,ae,Me,s,q]),Re=l.useCallback(Y=>Y==="*"?s("settings.agents.page.permissions.defaultLabel"):Y==="webfetch"?"WebFetch":Y==="websearch"?"WebSearch":Y==="codesearch"?"CodeSearch":Y==="doom_loop"?"Doom Loop":Y==="external_directory"?"External Directory":Y==="todowrite"?"TodoWrite":Y==="todoread"?"TodoRead":Y.split(/[_-]+/g).filter(Boolean).map(fe=>fe.charAt(0).toUpperCase()+fe.slice(1)).join(" "),[s]);l.useEffect(()=>{J(""),D("*");const Y=fe=>{const Ce=en(fe),Ie=Nm(Ce),Le=km(Ce,Ie);return A(Ie),O(Le),_(Le),{global:Ie,rules:Le}};if(g&&c){const fe=c.name||"",Ce=c.scope||"user",Ie=c.description||"",Le=c.mode||"subagent",$e=c.model||"",te=c.temperature,ce=c.top_p,Se=c.prompt||"";m(fe),h(Ce),b(Ie),S(Le),E($e),N(te),y(ce),L(Se);const Ue=Sm(c.permission),Ke=Y(Ue);se.current={draftName:fe,draftScope:Ce,description:Ie,mode:Le,model:$e,temperature:te,topP:ce,prompt:Se,globalPermission:Ke.global,permissionRules:Ke.rules};return}if(f&&n===f.name){const fe=f.description||"",Ce=f.mode||"subagent",Ie=f.model?.providerID&&f.model?.modelID?`${f.model.providerID}/${f.model.modelID}`:"",Le=f.temperature,$e=f.topP,te=f.prompt||"";b(fe),S(Ce),E(Ie),N(Le),y($e),L(te);const ce=Y(Array.isArray(f.permission)?f.permission:[]);se.current={draftName:"",draftScope:"user",description:fe,mode:Ce,model:Ie,temperature:Le,topP:$e,prompt:te,globalPermission:ce.global,permissionRules:ce.rules}}},[c,g,f,n]);const Ee=l.useMemo(()=>{const Y=se.current;return Y?!!(g&&(u!==Y.draftName||k!==Y.draftScope)||v!==Y.description||R!==Y.mode||j!==Y.model||P!==Y.temperature||x!==Y.topP||z!==Y.prompt||I!==Y.globalPermission||!wm(T,Y.permissionRules)):!1},[v,u,k,I,g,R,j,T,z,P,x]),Fe=async()=>{const Y=g?u.trim().replace(/\s+/g,"-"):n?.trim();if(!Y){U.error(s("settings.agents.sidebar.toast.agentNameRequired"));return}if(g&&o.some(fe=>fe.name===Y)){U.error(s("settings.agents.sidebar.toast.agentExists"));return}G(!0);try{const fe=j.trim(),Ce=Cm(I,T),Ie={name:Y,description:v.trim()||void 0,mode:R,model:fe===""?null:fe,temperature:P,top_p:x,prompt:z.trim()||void 0,permission:Ce,scope:g?k:void 0};let Le;g?(Le=await r(Ie),Le&&d(null)):Le=await i(Y,Ie),Le?U.success(s(g?"settings.agents.page.toast.created":"settings.agents.page.toast.updated")):U.error(s(g?"settings.agents.page.toast.createFailed":"settings.agents.page.toast.updateFailed"))}catch(fe){console.error("Error saving agent:",fe);const Ce=fe instanceof Error&&fe.message?fe.message:s("settings.agents.page.toast.saveUnexpectedError");U.error(Ce)}finally{G(!1)}};return n?t.jsx(Kt,{outerClassName:"h-full",className:"w-full",children:t.jsxs("div",{className:"mx-auto w-full max-w-3xl p-3 sm:p-6 sm:pt-8",children:[t.jsx("div",{className:"mb-4 flex items-center justify-between gap-4",children:t.jsxs("div",{className:"min-w-0",children:[t.jsx("h2",{className:"typography-ui-header font-semibold text-foreground truncate",children:g?s("settings.agents.page.title.new"):n}),t.jsx("p",{className:"typography-meta text-muted-foreground truncate",children:s(g?"settings.agents.page.subtitle.new":"settings.agents.page.subtitle.edit")})]})}),t.jsxs("div",{className:"mb-8",children:[t.jsx("div",{className:"mb-1 px-1",children:t.jsx("h3",{className:"typography-ui-header font-medium text-foreground",children:s("settings.agents.page.section.identityRole")})}),t.jsxs("section",{className:"px-2 pb-2 pt-0 space-y-0",children:[g&&t.jsxs("div",{className:"flex flex-col gap-2 py-1.5 sm:flex-row sm:items-center sm:gap-8",children:[t.jsx("div",{className:"flex min-w-0 flex-col sm:w-56 shrink-0",children:t.jsx("span",{className:"typography-ui-label text-foreground",children:s("settings.agents.page.field.agentName")})}),t.jsxs("div",{className:"flex min-w-0 flex-1 items-center gap-2 sm:w-fit sm:flex-initial",children:[t.jsxs("div",{className:"flex items-center",children:[t.jsx("span",{className:"typography-ui-label text-muted-foreground mr-1",children:"@"}),t.jsx(nt,{value:u,onChange:Y=>m(Y.target.value),placeholder:s("settings.agents.page.field.agentNamePlaceholder"),className:"h-7 w-40 px-2"})]}),t.jsxs(St,{value:k,onValueChange:Y=>h(Y),children:[t.jsx(Ct,{className:"w-fit min-w-[100px]",children:t.jsx(Rt,{placeholder:s("settings.agents.page.field.scopePlaceholder")})}),t.jsxs(Pt,{align:"end",children:[t.jsx(dt,{value:"user",children:t.jsxs("div",{className:"flex items-center gap-2",children:[t.jsx(F,{name:"user-3",className:"h-3.5 w-3.5"}),t.jsx("span",{children:s("settings.common.scope.global")})]})}),t.jsx(dt,{value:"project",children:t.jsxs("div",{className:"flex items-center gap-2",children:[t.jsx(F,{name:"folder",className:"h-3.5 w-3.5"}),t.jsx("span",{children:s("settings.common.scope.project")})]})})]})]})]})]}),t.jsxs("div",{className:"py-1.5",children:[t.jsx("span",{className:"typography-ui-label text-foreground",children:s("settings.common.field.description")}),t.jsx("div",{className:"mt-1.5",children:t.jsx(ls,{value:v,onChange:Y=>b(Y.target.value),placeholder:s("settings.agents.page.field.descriptionPlaceholder"),rows:2,className:"w-full resize-none min-h-[60px] bg-transparent"})})]}),t.jsx("div",{className:"pb-1.5 pt-0.5",children:t.jsxs("div",{className:"flex min-w-0 flex-col gap-1.5",children:[t.jsxs("div",{className:"flex items-center gap-1.5",children:[t.jsx("span",{className:"typography-ui-label text-foreground",children:s("settings.agents.page.field.mode")}),t.jsxs(vt,{children:[t.jsx(jt,{asChild:!0,children:t.jsx(F,{name:"information",className:"h-3.5 w-3.5 text-muted-foreground/60 cursor-help"})}),t.jsx(kt,{sideOffset:8,className:"max-w-xs",children:s("settings.agents.page.field.modeTooltip")})]})]}),t.jsxs("div",{className:"flex flex-wrap items-center gap-1",children:[t.jsx(W,{variant:"chip",size:"xs","aria-pressed":R==="primary",onClick:()=>S("primary"),className:"!font-normal",children:s("settings.agents.page.mode.primary")}),t.jsx(W,{variant:"chip",size:"xs","aria-pressed":R==="subagent",onClick:()=>S("subagent"),className:"!font-normal",children:s("settings.agents.page.mode.subagent")}),t.jsx(W,{variant:"chip",size:"xs","aria-pressed":R==="all",onClick:()=>S("all"),className:"!font-normal",children:s("settings.agents.page.mode.all")})]})]})})]})]}),t.jsxs("div",{className:"mb-8",children:[t.jsx("div",{className:"mb-1 px-1",children:t.jsx("h3",{className:"typography-ui-header font-medium text-foreground",children:s("settings.agents.page.section.modelParameters")})}),t.jsxs("section",{className:"px-2 pb-2 pt-0 space-y-0",children:[t.jsxs("div",{className:"flex flex-col gap-2 py-1.5 sm:flex-row sm:items-center sm:gap-8",children:[t.jsx("div",{className:"flex min-w-0 flex-col sm:w-56 shrink-0",children:t.jsx("span",{className:"typography-ui-label text-foreground",children:s("settings.agents.page.field.overrideModel")})}),t.jsx("div",{className:"flex min-w-0 flex-1 items-center gap-2 sm:w-fit sm:flex-initial",children:t.jsx(wr,{providerId:xn(j)?.providerId??"",modelId:xn(j)?.modelId??"",onChange:(Y,fe)=>{E(Y&&fe?`${Y}/${fe}`:"")}})})]}),t.jsxs("div",{className:ge("py-1.5",e?"flex flex-col gap-3":"flex items-center gap-8"),children:[t.jsxs("div",{className:ge("flex min-w-0 flex-col",e?"w-full":"sm:w-56 shrink-0"),children:[t.jsxs("div",{className:"flex items-center gap-1.5",children:[t.jsx("span",{className:"typography-ui-label text-foreground",children:s("settings.agents.page.field.temperature")}),t.jsxs(vt,{children:[t.jsx(jt,{asChild:!0,children:t.jsx(F,{name:"information",className:"h-3.5 w-3.5 text-muted-foreground/60 cursor-help"})}),t.jsx(kt,{sideOffset:8,className:"max-w-xs",children:s("settings.agents.page.field.temperatureTooltip")})]})]}),t.jsx("span",{className:"typography-meta text-muted-foreground",children:s("settings.agents.page.field.temperatureRange")})]}),t.jsxs("div",{className:ge("flex items-center gap-2",e?"w-full":"w-fit"),children:[t.jsx(ms,{value:P,fallbackValue:.7,onValueChange:N,onClear:()=>N(void 0),min:0,max:2,step:.1,inputMode:"decimal",placeholder:"—",emptyLabel:"—",className:"w-16"}),P!==void 0&&t.jsx(W,{size:"sm",type:"button",variant:"ghost",onClick:()=>N(void 0),className:"h-7 w-7 px-0 text-muted-foreground hover:text-foreground","aria-label":s("settings.agents.page.field.clearTemperatureAria"),title:s("settings.common.actions.clear"),children:t.jsx(F,{name:"close",className:"h-3.5 w-3.5"})})]})]}),t.jsxs("div",{className:ge("py-1.5",e?"flex flex-col gap-3":"flex items-center gap-8"),children:[t.jsxs("div",{className:ge("flex min-w-0 flex-col",e?"w-full":"sm:w-56 shrink-0"),children:[t.jsxs("div",{className:"flex items-center gap-1.5",children:[t.jsx("span",{className:"typography-ui-label text-foreground",children:s("settings.agents.page.field.topP")}),t.jsxs(vt,{children:[t.jsx(jt,{asChild:!0,children:t.jsx(F,{name:"information",className:"h-3.5 w-3.5 text-muted-foreground/60 cursor-help"})}),t.jsx(kt,{sideOffset:8,className:"max-w-xs",children:s("settings.agents.page.field.topPTooltip")})]})]}),t.jsx("span",{className:"typography-meta text-muted-foreground",children:s("settings.agents.page.field.topPRange")})]}),t.jsxs("div",{className:ge("flex items-center gap-2",e?"w-full":"w-fit"),children:[t.jsx(ms,{value:x,fallbackValue:.9,onValueChange:y,onClear:()=>y(void 0),min:0,max:1,step:.1,inputMode:"decimal",placeholder:"—",emptyLabel:"—",className:"w-16"}),x!==void 0&&t.jsx(W,{size:"sm",type:"button",variant:"ghost",onClick:()=>y(void 0),className:"h-7 w-7 px-0 text-muted-foreground hover:text-foreground","aria-label":s("settings.agents.page.field.clearTopPAria"),title:s("settings.common.actions.clear"),children:t.jsx(F,{name:"close",className:"h-3.5 w-3.5"})})]})]})]})]}),t.jsxs("div",{className:"mb-8",children:[t.jsx("div",{className:"mb-1 px-1",children:t.jsx("h3",{className:"typography-ui-header font-medium text-foreground",children:s("settings.agents.page.section.systemPrompt")})}),t.jsx("section",{className:"px-2 pb-2 pt-0",children:t.jsx(ls,{value:z,onChange:Y=>L(Y.target.value),placeholder:s("settings.agents.page.field.systemPromptPlaceholder"),rows:8,className:"w-full font-mono typography-meta min-h-[120px] max-h-[60vh] bg-transparent resize-y"})})]}),t.jsxs("div",{className:"mb-2",children:[t.jsxs("div",{className:"mb-1 px-1 flex items-center justify-between gap-4",children:[t.jsx("h3",{className:"typography-ui-header font-medium text-foreground",children:s("settings.agents.page.section.toolPermissions")}),t.jsx(W,{variant:"outline",size:"xs",className:"!font-normal",onClick:()=>C(Y=>!Y),children:s(K?"settings.agents.page.permissions.hideEditor":"settings.agents.page.permissions.advancedEditor")})]}),K?t.jsxs("div",{className:"space-y-6 px-2",children:[t.jsxs("div",{className:"flex items-center justify-between gap-4 py-1.5",children:[t.jsxs("div",{className:"flex items-center gap-2",children:[t.jsx("span",{className:"typography-ui-label text-foreground",children:s("settings.agents.page.permissions.globalDefault")}),t.jsx("span",{className:"typography-micro text-muted-foreground/70 font-mono",children:"*"})]}),t.jsxs(St,{value:I,onValueChange:Y=>Me(Y),children:[t.jsx(Ct,{className:"w-[100px]",children:t.jsx(Rt,{children:we(I)})}),t.jsxs(Pt,{children:[t.jsx(dt,{value:"allow",children:s("settings.common.permission.allow")}),t.jsx(dt,{value:"ask",children:s("settings.common.permission.ask")}),t.jsx(dt,{value:"deny",children:s("settings.common.permission.deny")})]})]})]}),t.jsx("div",{className:"space-y-4",children:be.filter(Y=>Y!=="*").map(Y=>{const fe=Re(Y),{defaultAction:Ce,patternRulesCount:Ie}=de(Y),Le=xe(Y),$e=Le??"global",te=ue(Y),ce=["allow","ask","deny"].filter(Se=>Se!==I);return t.jsxs("div",{className:"border-t border-[var(--surface-subtle)] pt-2",children:[t.jsxs("div",{className:"flex items-center justify-between py-1",children:[t.jsxs("div",{className:"flex items-center gap-2",children:[t.jsx("span",{className:"typography-ui-label text-foreground",children:fe}),t.jsx("span",{className:"typography-micro text-muted-foreground/70 font-mono",children:Y})]}),t.jsx("div",{className:"typography-micro text-muted-foreground",children:Ie>0?s("settings.agents.page.permissions.globalSummary",{summary:Ce}):Ce})]}),t.jsxs("div",{className:"space-y-1 pl-2 mt-1",children:[t.jsxs("div",{className:"flex flex-wrap items-center justify-between gap-2 py-0.5",children:[t.jsxs("div",{className:"flex items-center gap-2",children:[t.jsx("span",{className:"typography-micro text-muted-foreground",children:s("settings.agents.page.permissions.pattern")}),t.jsx("span",{className:"typography-micro font-mono text-foreground bg-[var(--surface-muted)] px-1 rounded",children:"*"}),Le&&t.jsx(W,{size:"sm",variant:"ghost",onClick:()=>pe(Y,"*"),className:"px-1.5 py-0 h-5",children:t.jsx(F,{name:"subtract",className:"h-3.5 w-3.5 text-muted-foreground hover:text-foreground"})})]}),t.jsxs(St,{value:$e,onValueChange:Se=>{if(Se==="global"){ae(Y,"*");return}q(Y,"*",Se)},children:[t.jsx(Ct,{className:"w-[90px]",children:t.jsx(Rt,{children:Q($e)})}),t.jsxs(Pt,{children:[t.jsx(dt,{value:"global",children:s("settings.common.scope.global")}),ce.map(Se=>t.jsx(dt,{value:Se,className:"capitalize",children:we(Se)},Se))]})]})]}),te.map(Se=>{const Ue=Qs(Se.permission,Se.pattern),Ke=Z.get(Ue),Ye=!Ke,Xe=!!(Ke&&Ke.action!==Se.action);return t.jsxs("div",{className:"flex flex-wrap items-center justify-between gap-2 py-0.5 border-t border-[var(--surface-subtle)]",children:[t.jsxs("div",{className:"flex items-center gap-2",children:[t.jsx("span",{className:"typography-micro text-muted-foreground",children:s("settings.agents.page.permissions.pattern")}),t.jsx("span",{className:"typography-micro font-mono text-foreground bg-[var(--surface-muted)] px-1 rounded",children:Se.pattern}),Ye&&t.jsx("span",{className:"typography-micro text-[var(--status-success)]",children:s("settings.common.badge.new")}),Xe&&t.jsx("span",{className:"typography-micro text-[var(--status-warning)]",children:s("settings.common.badge.modified")}),(Ye||Xe)&&t.jsx(W,{size:"sm",variant:"ghost",onClick:()=>Ye?ae(Se.permission,Se.pattern):pe(Se.permission,Se.pattern),className:"px-1.5 py-0 h-5",children:t.jsx(F,{name:"subtract",className:"h-3.5 w-3.5 text-muted-foreground hover:text-foreground"})})]}),t.jsxs(St,{value:Se.action,onValueChange:Ze=>je(Se.permission,Se.pattern,Ze),children:[t.jsx(Ct,{className:"w-[90px]",children:t.jsx(Rt,{children:we(Se.action)})}),t.jsxs(Pt,{children:[t.jsx(dt,{value:"allow",children:s("settings.common.permission.allow")}),t.jsx(dt,{value:"ask",children:s("settings.common.permission.ask")}),t.jsx(dt,{value:"deny",children:s("settings.common.permission.deny")})]})]})]},Ue)})]})]},Y)})}),t.jsxs("div",{className:"border-t border-[var(--surface-subtle)] pt-3",children:[t.jsx("h4",{className:"typography-ui-label text-foreground mb-2",children:s("settings.agents.page.permissions.addCustomRule")}),t.jsxs("div",{className:"flex flex-col sm:flex-row items-end sm:items-center gap-2",children:[t.jsxs(St,{value:V,onValueChange:J,children:[t.jsx(Ct,{className:"w-full sm:w-[160px]",children:V?t.jsx("span",{className:"truncate",children:Re(V)}):t.jsx("span",{className:"text-muted-foreground",children:s("settings.agents.page.permissions.permissionPlaceholder")})}),t.jsx(Pt,{children:he.map(Y=>t.jsx(dt,{value:Y,children:t.jsx("div",{className:"flex items-center justify-between gap-2 w-full",children:t.jsx("span",{children:Re(Y)})})},Y))})]}),t.jsx(nt,{value:B,onChange:Y=>D(Y.target.value),placeholder:s("settings.agents.page.permissions.patternPlaceholder"),className:"h-7 flex-1 font-mono text-xs"}),t.jsxs("div",{className:"flex gap-1",children:[t.jsx(W,{variant:"outline",size:"xs",className:"!font-normal",onClick:()=>Pe("allow"),children:s("settings.common.permission.allow")}),t.jsx(W,{variant:"outline",size:"xs",className:"!font-normal",onClick:()=>Pe("ask"),children:s("settings.common.permission.ask")}),t.jsx(W,{variant:"outline",size:"xs",className:"!font-normal",onClick:()=>Pe("deny"),children:s("settings.common.permission.deny")})]})]})]})]}):t.jsx("section",{className:"px-2 pb-2 pt-0 space-y-0",children:be.map((Y,fe)=>{const{defaultAction:Ce,patternRulesCount:Ie,patternSummary:Le,hasDefaultHint:$e}=de(Y),te=Re(Y),ce=$e?`${Ce} (env blocked)`:Ce;return t.jsxs("div",{className:ge("flex flex-col gap-1 py-1.5 sm:flex-row sm:items-center sm:justify-between sm:gap-8",fe>0&&"border-t border-[var(--surface-subtle)]"),children:[t.jsxs("div",{className:"flex items-center gap-2",children:[t.jsx("span",{className:"typography-ui-label text-foreground",children:te}),t.jsx("span",{className:"typography-micro text-muted-foreground/70 font-mono hidden sm:inline-block",children:Y})]}),t.jsxs("div",{className:"flex items-center gap-3",children:[Ie>0?t.jsx("span",{className:"typography-micro text-muted-foreground bg-[var(--surface-muted)] px-1.5 py-0.5 rounded",children:s("settings.agents.page.permissions.globalSummary",{summary:ce})}):t.jsx("span",{className:ge("typography-micro capitalize px-1.5 py-0.5 rounded",ce==="allow"?"text-[var(--status-success)] bg-[var(--status-success)]/10":ce==="deny"?"text-[var(--status-error)] bg-[var(--status-error)]/10":"text-[var(--status-warning)] bg-[var(--status-warning)]/10"),children:ce}),Ie>0&&t.jsx("span",{className:"typography-micro text-muted-foreground bg-[var(--surface-muted)] px-1.5 py-0.5 rounded",children:s("settings.agents.page.permissions.rulesSummary",{summary:Le})})]})]},Y)})})]}),t.jsx("div",{className:"px-2 py-1",children:t.jsx(W,{onClick:Fe,disabled:H||!Ee,size:"xs",className:"!font-normal",children:s(H?"settings.common.actions.saving":"settings.common.actions.saveChanges")})})]})}):t.jsx("div",{className:"flex h-full items-center justify-center",children:t.jsxs("div",{className:"text-center text-muted-foreground",children:[t.jsx(F,{name:"robot-2",className:"mx-auto mb-3 h-12 w-12 opacity-50"}),t.jsx("p",{className:"typography-body",children:s("settings.agents.page.empty.title")}),t.jsx("p",{className:"typography-meta mt-1 opacity-75",children:s("settings.agents.page.empty.description")})]})})},Im="~/.config/opencode/AGENTS.md",al=async(s,e)=>{const n=await s.json().catch(()=>null);return typeof n?.error=="string"&&n.error.trim()?n.error:e},Dm=s=>s.length>0&&!s.endsWith(`
|
|
2
2
|
`)?`${s}
|
|
3
3
|
`:s,Hn={prompt:"",responseStyleEnabled:!1,responseStylePreset:"concise",responseStyleCustomInstructions:""},Am=(s,e)=>s==="custom"?e:Oc(s),Mm=s=>s==="custom"?"custom":Go(s)?s:"concise",wi={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"},Ni=async(s,e)=>{const n=await pt("/api/config/settings",{method:"PUT",headers:{"Content-Type":"application/json",Accept:"application/json"},body:JSON.stringify(s)});if(!n.ok)throw new Error(await al(n,e))},Em=()=>{const{t:s}=ot(),[e,n]=l.useState(""),[a,r]=l.useState(Hn.responseStyleEnabled),[i,o]=l.useState(Hn.responseStylePreset),[c,d]=l.useState(Hn.responseStyleCustomInstructions),[f,g]=l.useState(!0),[u,m]=l.useState(!1),[k,h]=l.useState(""),v=l.useRef(null);l.useEffect(()=>{const j=new AbortController;return(async()=>{try{const[P,N]=await Promise.all([pt("/api/config/settings",{method:"GET",headers:{Accept:"application/json"},signal:j.signal}),pt("/api/behavior/agents-md",{method:"GET",headers:{Accept:"application/json"},signal:j.signal})]);let x=Hn;if(P.ok){const y=await P.json();x={...x,responseStyleEnabled:y.responseStyleEnabled===!0,responseStylePreset:Mm(y.responseStylePreset),responseStyleCustomInstructions:typeof y.responseStyleCustomInstructions=="string"?y.responseStyleCustomInstructions:""},typeof y.globalBehaviorPrompt=="string"&&(x={...x,prompt:y.globalBehaviorPrompt})}if(!x.prompt.trim()&&N.ok){const y=await N.json();typeof y.content=="string"&&(x={...x,prompt:y.content})}n(x.prompt),r(x.responseStyleEnabled),o(x.responseStylePreset),d(x.responseStyleCustomInstructions),h(x.prompt),v.current={enabled:x.responseStyleEnabled,preset:x.responseStylePreset,custom:x.responseStyleCustomInstructions}}catch(P){P.name!=="AbortError"&&console.warn("Failed to load behavior settings:",P)}finally{g(!1)}})(),()=>j.abort()},[]),l.useEffect(()=>{if(f)return;const j=v.current;if(j&&j.enabled===a&&j.preset===i&&j.custom===c)return;const E={enabled:a,preset:i,custom:c},P=setTimeout(async()=>{try{await Ni({responseStyleEnabled:E.enabled,responseStylePreset:E.preset,responseStyleCustomInstructions:E.custom},s("settings.behavior.page.toast.saveFailed")),v.current=E}catch(N){const x=N instanceof Error?N.message:s("settings.behavior.page.toast.saveFailed");U.error(x)}},400);return()=>clearTimeout(P)},[a,i,c,f,s]);const b=Am(i,c),R=e!==k,S=async()=>{m(!0);try{const j=Dm(e),E=await pt("/api/behavior/agents-md",{method:"PUT",headers:{"Content-Type":"application/json",Accept:"application/json"},body:JSON.stringify({content:j})});if(!E.ok)throw new Error(await al(E,s("settings.behavior.page.toast.saveFailed")));await Ni({globalBehaviorPrompt:j},s("settings.behavior.page.toast.saveFailed")),n(j),h(j),U.success(s("settings.behavior.page.toast.saved"))}catch(j){console.error("Failed to save behavior:",j);const E=j instanceof Error?j.message:s("settings.behavior.page.toast.saveFailed");U.error(E)}finally{m(!1)}};return t.jsx(Kt,{outerClassName:"h-full",className:"w-full",children:t.jsxs("div",{className:"mx-auto w-full max-w-3xl p-3 sm:p-6 sm:pt-8 space-y-6",children:[t.jsx("div",{className:"space-y-1",children:t.jsx("h2",{className:"typography-ui-header font-semibold text-foreground",children:s("settings.behavior.page.title")})}),t.jsxs("div",{children:[t.jsx("div",{className:"mb-1 px-1",children:t.jsxs("div",{className:"flex items-center gap-1.5",children:[t.jsx("h3",{className:"typography-ui-header font-medium text-foreground",children:s("settings.behavior.page.section.systemPrompt")}),t.jsxs(vt,{children:[t.jsx(jt,{asChild:!0,children:t.jsx(F,{name:"information",className:"h-3.5 w-3.5 text-muted-foreground/60 cursor-help"})}),t.jsx(kt,{sideOffset:8,className:"max-w-xs",children:t.jsxs("div",{className:"space-y-1",children:[t.jsx("p",{className:"font-medium text-foreground",children:s("settings.behavior.page.warning.title")}),t.jsx("p",{children:s("settings.behavior.page.warning.description",{path:Im})})]})})]})]})}),t.jsxs("section",{className:"px-2 pb-2 pt-0 space-y-3",children:[t.jsx(ls,{value:e,onChange:j=>n(j.target.value),placeholder:s("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"}),t.jsx(W,{onClick:S,disabled:u||!R||f,size:"xs",className:"!font-normal",children:s(u?"settings.common.actions.saving":"settings.common.actions.saveChanges")})]})]}),t.jsxs("div",{children:[t.jsx("div",{className:"mb-1 px-1",children:t.jsxs("div",{className:"flex items-center gap-1.5",children:[t.jsx("h3",{className:"typography-ui-header font-medium text-foreground",children:s("settings.behavior.page.section.responseStyle")}),t.jsxs(vt,{children:[t.jsx(jt,{asChild:!0,children:t.jsx(F,{name:"information",className:"h-3.5 w-3.5 text-muted-foreground/60 cursor-help"})}),t.jsx(kt,{sideOffset:8,className:"max-w-xs",children:s("settings.behavior.page.responseStyle.tooltip")})]})]})}),t.jsxs("section",{className:"px-2 pb-2 pt-0 space-y-3",children:[t.jsxs("label",{className:"flex items-center gap-2 typography-ui-label text-foreground",children:[t.jsx(Nt,{checked:a,onChange:r,disabled:f,ariaLabel:s("settings.behavior.page.responseStyle.enableAria")}),s("settings.behavior.page.responseStyle.enable")]}),t.jsxs(St,{value:i,onValueChange:j=>o(j),disabled:f||!a,children:[t.jsx(Ct,{className:"w-full sm:w-56",size:"lg",children:t.jsx(Rt,{children:j=>j==="custom"?s("settings.behavior.page.responseStyle.option.custom"):Go(j)?s(wi[j]):null})}),t.jsxs(Pt,{children:[Lc.map(j=>t.jsx(dt,{value:j,children:s(wi[j])},j)),t.jsx(dt,{value:"custom",children:s("settings.behavior.page.responseStyle.option.custom")})]})]}),t.jsx(ls,{value:b,onChange:j=>d(j.target.value),placeholder:s("settings.behavior.page.responseStyle.customPlaceholder"),rows:5,disabled:f||!a||i!=="custom",outerClassName:"min-h-[120px]",className:"w-full font-mono typography-meta bg-transparent"})]})]})]})})},Rm=s=>{const e=it.c(169),{onItemSelect:n}=s,{t:a}=ot(),[r,i]=l.useState(null),[o,c]=l.useState(""),[d,f]=l.useState(null),[g,u]=l.useState(null),[m,k]=l.useState(!1),[h,v]=l.useState(null),{selectedCommandName:b,commands:R,setSelectedCommand:S,setCommandDraft:j,createCommand:E,deleteCommand:P,loadCommands:N}=Nr(bs(Tm)),x=Ks(Fm),y=Ks(Lm);let z,L;e[0]!==N||e[1]!==y?(z=()=>{N(),y()},L=[N,y],e[0]=N,e[1]=y,e[2]=z,e[3]=L):(z=e[2],L=e[3]),l.useEffect(z,L);let I;e[4]!==x?(I=new Set(x.map(Om)),e[4]=x,e[5]=I):I=e[5];const A=I;let w;if(e[6]!==R||e[7]!==A){let ye;e[9]!==A?(ye=tt=>!A.has(tt.name),e[9]=A,e[10]=ye):ye=e[10],w=R.filter(ye),e[6]=R,e[7]=A,e[8]=w}else w=e[8];const O=w;let T,_;e[11]!==b||e[12]!==S||e[13]!==A?(T=()=>{b&&A.has(b)&&S(null)},_=[b,S,A],e[11]=b,e[12]=S,e[13]=A,e[14]=T,e[15]=_):(T=e[14],_=e[15]),l.useEffect(T,_);let V;e[16]!==R||e[17]!==n||e[18]!==j||e[19]!==S?(V=()=>{let ye="new-command",tt=1;for(;R.some(st=>st.name===ye);)ye=`new-command-${tt}`,tt++;j({name:ye,scope:"user"}),S(ye),n?.()},e[16]=R,e[17]=n,e[18]=j,e[19]=S,e[20]=V):V=e[20];const J=V;let B;e[21]!==a?(B=async ye=>{if(gn(ye)){U.error(a("settings.commands.sidebar.toast.builtInCannotDelete"));return}f(ye),u("delete")},e[21]=a,e[22]=B):B=e[22];const D=B;let K;e[23]===Symbol.for("react.memo_cache_sentinel")?(K=async ye=>{gn(ye)&&(f(ye),u("reset"))},e[23]=K):K=e[23];const C=K;let H;e[24]===Symbol.for("react.memo_cache_sentinel")?(H=()=>{f(null),u(null)},e[24]=H):H=e[24];const G=H;let se;e[25]!==d||e[26]!==g||e[27]!==P||e[28]!==a?(se=async()=>{if(!d||!g)return;k(!0),await P(d.name)?(g==="delete"?U.success(a("settings.commands.sidebar.toast.commandDeleted",{name:d.name})):U.success(a("settings.commands.sidebar.toast.commandReset",{name:d.name})),G()):g==="delete"?U.error(a("settings.commands.sidebar.toast.deleteFailed")):U.error(a("settings.commands.sidebar.toast.resetFailed")),k(!1)},e[25]=d,e[26]=g,e[27]=P,e[28]=a,e[29]=se):se=e[29];const oe=se;let re;e[30]!==R||e[31]!==j||e[32]!==S?(re=ye=>{const tt=ye.name;let st=1,qe=`${tt}-copy`;for(;R.some(yt=>yt.name===qe);)st++,qe=`${tt}-copy-${st}`;j({name:qe,scope:ye.scope||"user",description:ye.description,template:ye.template,agent:ye.agent,model:ye.model}),S(qe)},e[30]=R,e[31]=j,e[32]=S,e[33]=re):re=e[33];const me=re;let le;e[34]===Symbol.for("react.memo_cache_sentinel")?(le=ye=>{c(ye.name),i(ye)},e[34]=le):le=e[34];const ve=le;let Z;e[35]!==R||e[36]!==E||e[37]!==P||e[38]!==r||e[39]!==o||e[40]!==S||e[41]!==a?(Z=async()=>{if(!r)return;const ye=o.trim().replace(/\s+/g,"-");if(!ye){U.error(a("settings.commands.sidebar.toast.commandNameRequired"));return}if(ye===r.name){i(null);return}if(R.some(st=>st.name===ye)){U.error(a("settings.commands.sidebar.toast.commandExists"));return}await E({name:ye,description:r.description,template:r.template,agent:r.agent,model:r.model})?await P(r.name)?(U.success(`Command renamed to "${ye}"`),S(ye)):U.error(a("settings.commands.sidebar.toast.removeOldAfterRenameFailed")):U.error(a("settings.commands.sidebar.toast.renameFailed")),i(null)},e[35]=R,e[36]=E,e[37]=P,e[38]=r,e[39]=o,e[40]=S,e[41]=a,e[42]=Z):Z=e[42];const X=Z;let xe,ue,be,de,we,Q;if(e[43]!==O||e[44]!==J||e[45]!==D||e[46]!==me||e[47]!==n||e[48]!==h||e[49]!==b||e[50]!==S||e[51]!==a){const ye=O.filter(gn),tt=O.filter(zm);e[58]===Symbol.for("react.memo_cache_sentinel")?(we=ge("flex h-full flex-col","bg-background"),e[58]=we):we=e[58];let st;e[59]!==a?(st=a("settings.commands.sidebar.title"),e[59]=a,e[60]=st):st=e[60];let qe;e[61]!==st?(qe=t.jsx("h2",{className:"text-base font-semibold text-foreground mb-3",children:st}),e[61]=st,e[62]=qe):qe=e[62];let yt;e[63]===Symbol.for("react.memo_cache_sentinel")?(yt=t.jsx(On,{className:"mb-3"}),e[63]=yt):yt=e[63];let It;e[64]!==O.length||e[65]!==a?(It=a("settings.commands.sidebar.total",{count:O.length}),e[64]=O.length,e[65]=a,e[66]=It):It=e[66];let Tt;e[67]!==It?(Tt=t.jsx("span",{className:"typography-meta text-muted-foreground",children:It}),e[67]=It,e[68]=Tt):Tt=e[68];let ne;e[69]===Symbol.for("react.memo_cache_sentinel")?(ne=t.jsx(F,{name:"add",className:"h-3.5 w-3.5"}),e[69]=ne):ne=e[69];let Be;e[70]!==J?(Be=t.jsx(W,{size:"sm",variant:"ghost",className:"h-7 w-7 px-0 -my-1 text-muted-foreground",onClick:J,children:ne}),e[70]=J,e[71]=Be):Be=e[71];let Ge;e[72]!==Tt||e[73]!==Be?(Ge=t.jsxs("div",{className:"flex items-center justify-between gap-2",children:[Tt,Be]}),e[72]=Tt,e[73]=Be,e[74]=Ge):Ge=e[74],e[75]!==qe||e[76]!==Ge?(Q=t.jsxs("div",{className:"border-b px-3 pt-4 pb-3",children:[qe,yt,Ge]}),e[75]=qe,e[76]=Ge,e[77]=Q):Q=e[77],xe=Kt,ue="flex-1 min-h-0",be="space-y-1 px-3 py-2",de=O.length===0?t.jsxs("div",{className:"py-12 px-4 text-center text-muted-foreground",children:[t.jsx(F,{name:"terminal-box",className:"mx-auto mb-3 h-10 w-10 opacity-50"}),t.jsx("p",{className:"typography-ui-label font-medium",children:a("settings.commands.sidebar.empty.title")}),t.jsx("p",{className:"typography-meta mt-1 opacity-75",children:a("settings.commands.sidebar.empty.description")})]}):t.jsxs(t.Fragment,{children:[ye.length>0&&t.jsxs(t.Fragment,{children:[t.jsx("div",{className:"px-2 pb-1.5 pt-2 text-xs font-semibold uppercase tracking-wide text-muted-foreground",children:a("settings.commands.sidebar.section.builtIn")}),[...ye].sort($m).map(He=>t.jsx(ki,{command:He,isSelected:b===He.name,onSelect:()=>{S(He.name),n?.()},onReset:()=>C(He),onDuplicate:()=>me(He),isMenuOpen:h===He.name,onMenuOpenChange:ht=>v(ht?He.name:null)},He.name))]}),tt.length>0&&t.jsxs(t.Fragment,{children:[t.jsx("div",{className:"px-2 pb-1.5 pt-3 text-xs font-semibold uppercase tracking-wide text-muted-foreground",children:a("settings.commands.sidebar.section.custom")}),[...tt].sort(Bm).map(He=>t.jsx(ki,{command:He,isSelected:b===He.name,onSelect:()=>{S(He.name),n?.()},onRename:()=>ve(He),onDelete:()=>D(He),onDuplicate:()=>me(He),isMenuOpen:h===He.name,onMenuOpenChange:ht=>v(ht?He.name:null)},He.name))]})]}),e[43]=O,e[44]=J,e[45]=D,e[46]=me,e[47]=n,e[48]=h,e[49]=b,e[50]=S,e[51]=a,e[52]=xe,e[53]=ue,e[54]=be,e[55]=de,e[56]=we,e[57]=Q}else xe=e[52],ue=e[53],be=e[54],de=e[55],we=e[56],Q=e[57];let he;e[78]!==xe||e[79]!==ue||e[80]!==be||e[81]!==de?(he=t.jsx(xe,{outerClassName:ue,className:be,children:de}),e[78]=xe,e[79]=ue,e[80]=be,e[81]=de,e[82]=he):he=e[82];const q=d!==null&&g!==null;let ae;e[83]!==m?(ae=ye=>{!ye&&!m&&G()},e[83]=m,e[84]=ae):ae=e[84];let pe;e[85]!==g||e[86]!==a?(pe=a(g==="delete"?"settings.commands.sidebar.dialog.deleteTitle":"settings.commands.sidebar.dialog.resetTitle"),e[85]=g,e[86]=a,e[87]=pe):pe=e[87];let je;e[88]!==pe?(je=t.jsx(zt,{children:pe}),e[88]=pe,e[89]=je):je=e[89];let Me;e[90]!==d?.name||e[91]!==g||e[92]!==a?(Me=g==="delete"?a("settings.commands.sidebar.dialog.deleteDescription",{name:d?.name??""}):a("settings.commands.sidebar.dialog.resetDescription",{name:d?.name??""}),e[90]=d?.name,e[91]=g,e[92]=a,e[93]=Me):Me=e[93];let Pe;e[94]!==Me?(Pe=t.jsx(Vt,{children:Me}),e[94]=Me,e[95]=Pe):Pe=e[95];let Re;e[96]!==je||e[97]!==Pe?(Re=t.jsxs(Bt,{children:[je,Pe]}),e[96]=je,e[97]=Pe,e[98]=Re):Re=e[98];let Ee;e[99]!==a?(Ee=a("settings.common.actions.cancel"),e[99]=a,e[100]=Ee):Ee=e[100];let Fe;e[101]!==m||e[102]!==Ee?(Fe=t.jsx(W,{size:"sm",variant:"ghost",onClick:G,disabled:m,children:Ee}),e[101]=m,e[102]=Ee,e[103]=Fe):Fe=e[103];let Y;e[104]!==g||e[105]!==a?(Y=a(g==="delete"?"settings.common.actions.delete":"settings.common.actions.reset"),e[104]=g,e[105]=a,e[106]=Y):Y=e[106];let fe;e[107]!==oe||e[108]!==m||e[109]!==Y?(fe=t.jsx(W,{size:"sm",onClick:oe,disabled:m,children:Y}),e[107]=oe,e[108]=m,e[109]=Y,e[110]=fe):fe=e[110];let Ce;e[111]!==Fe||e[112]!==fe?(Ce=t.jsxs(Gt,{children:[Fe,fe]}),e[111]=Fe,e[112]=fe,e[113]=Ce):Ce=e[113];let Ie;e[114]!==Re||e[115]!==Ce?(Ie=t.jsxs(Ot,{className:"max-w-md",children:[Re,Ce]}),e[114]=Re,e[115]=Ce,e[116]=Ie):Ie=e[116];let Le;e[117]!==q||e[118]!==ae||e[119]!==Ie?(Le=t.jsx(Lt,{open:q,onOpenChange:ae,children:Ie}),e[117]=q,e[118]=ae,e[119]=Ie,e[120]=Le):Le=e[120];const $e=r!==null;let te;e[121]===Symbol.for("react.memo_cache_sentinel")?(te=ye=>!ye&&i(null),e[121]=te):te=e[121];let ce;e[122]!==a?(ce=a("settings.commands.sidebar.renameDialog.title"),e[122]=a,e[123]=ce):ce=e[123];let Se;e[124]!==ce?(Se=t.jsx(zt,{children:ce}),e[124]=ce,e[125]=Se):Se=e[125];const Ue=r?.name??"";let Ke;e[126]!==a||e[127]!==Ue?(Ke=a("settings.commands.sidebar.renameDialog.description",{name:Ue}),e[126]=a,e[127]=Ue,e[128]=Ke):Ke=e[128];let Ye;e[129]!==Ke?(Ye=t.jsx(Vt,{children:Ke}),e[129]=Ke,e[130]=Ye):Ye=e[130];let Xe;e[131]!==Se||e[132]!==Ye?(Xe=t.jsxs(Bt,{children:[Se,Ye]}),e[131]=Se,e[132]=Ye,e[133]=Xe):Xe=e[133];let Ze;e[134]===Symbol.for("react.memo_cache_sentinel")?(Ze=ye=>c(ye.target.value),e[134]=Ze):Ze=e[134];let p;e[135]!==a?(p=a("settings.commands.sidebar.renameDialog.placeholder"),e[135]=a,e[136]=p):p=e[136];let ee;e[137]!==X?(ee=ye=>{ye.key==="Enter"&&X()},e[137]=X,e[138]=ee):ee=e[138];let De;e[139]!==o||e[140]!==p||e[141]!==ee?(De=t.jsx(nt,{value:o,onChange:Ze,placeholder:p,className:"text-foreground placeholder:text-muted-foreground",onKeyDown:ee}),e[139]=o,e[140]=p,e[141]=ee,e[142]=De):De=e[142];let Te;e[143]===Symbol.for("react.memo_cache_sentinel")?(Te=()=>i(null),e[143]=Te):Te=e[143];let We;e[144]!==a?(We=a("settings.common.actions.cancel"),e[144]=a,e[145]=We):We=e[145];let lt;e[146]!==We?(lt=t.jsx(W,{size:"sm",variant:"ghost",onClick:Te,children:We}),e[146]=We,e[147]=lt):lt=e[147];let Qe;e[148]!==a?(Qe=a("settings.common.actions.rename"),e[148]=a,e[149]=Qe):Qe=e[149];let at;e[150]!==X||e[151]!==Qe?(at=t.jsx(W,{size:"sm",onClick:X,children:Qe}),e[150]=X,e[151]=Qe,e[152]=at):at=e[152];let et;e[153]!==lt||e[154]!==at?(et=t.jsxs(Gt,{children:[lt,at]}),e[153]=lt,e[154]=at,e[155]=et):et=e[155];let Je;e[156]!==Xe||e[157]!==De||e[158]!==et?(Je=t.jsxs(Ot,{children:[Xe,De,et]}),e[156]=Xe,e[157]=De,e[158]=et,e[159]=Je):Je=e[159];let ie;e[160]!==$e||e[161]!==Je?(ie=t.jsx(Lt,{open:$e,onOpenChange:te,children:Je}),e[160]=$e,e[161]=Je,e[162]=ie):ie=e[162];let Ve;return e[163]!==we||e[164]!==Q||e[165]!==he||e[166]!==Le||e[167]!==ie?(Ve=t.jsxs("div",{className:we,children:[Q,he,Le,ie]}),e[163]=we,e[164]=Q,e[165]=he,e[166]=Le,e[167]=ie,e[168]=Ve):Ve=e[168],Ve},ki=s=>{const e=it.c(53),{command:n,isSelected:a,onSelect:r,onDelete:i,onReset:o,onRename:c,onDuplicate:d,isMenuOpen:f,onMenuOpenChange:g}=s,{t:u}=ot();let m;e[0]===Symbol.for("react.memo_cache_sentinel")?(m=Tn(),e[0]=m):m=e[0];const k=m,h=a?"bg-interactive-selection":"hover:bg-interactive-hover";let v;e[1]!==h?(v=ge("group relative flex items-center rounded-md px-1.5 py-1 transition-all duration-200 select-none",h),e[1]=h,e[2]=v):v=e[2];let b;e[3]!==g?(b=k?void 0:J=>{J.preventDefault(),g(!0)},e[3]=g,e[4]=b):b=e[4];let R;e[5]!==n.name?(R=t.jsxs("span",{className:"typography-ui-label font-normal truncate text-foreground",children:["/",n.name]}),e[5]=n.name,e[6]=R):R=e[6];let S;e[7]!==n||e[8]!==u?(S=(n.scope||gn(n))&&t.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:gn(n)?u("settings.agents.sidebar.badge.system"):n.scope}),e[7]=n,e[8]=u,e[9]=S):S=e[9];let j;e[10]!==R||e[11]!==S?(j=t.jsxs("div",{className:"flex items-center gap-2",children:[R,S]}),e[10]=R,e[11]=S,e[12]=j):j=e[12];let E;e[13]!==n.description?(E=n.description&&t.jsx("div",{className:"typography-micro text-muted-foreground/60 truncate leading-tight",children:n.description}),e[13]=n.description,e[14]=E):E=e[14];let P;e[15]!==r||e[16]!==j||e[17]!==E?(P=t.jsxs("button",{onClick:r,className:"flex min-w-0 flex-1 flex-col gap-0 rounded-sm text-left focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-primary/50",tabIndex:0,children:[j,E]}),e[15]=r,e[16]=j,e[17]=E,e[18]=P):P=e[18];let N;e[19]===Symbol.for("react.memo_cache_sentinel")?(N=t.jsx(rs,{asChild:!0,children:t.jsx(W,{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:t.jsx(F,{name:"more-2",className:"h-3.5 w-3.5"})})}),e[19]=N):N=e[19];let x;e[20]!==c||e[21]!==u?(x=c&&t.jsxs(Ht,{onClick:J=>{J.stopPropagation(),c()},children:[t.jsx(F,{name:"edit",className:"h-4 w-4 mr-px"}),u("settings.common.actions.rename")]}),e[20]=c,e[21]=u,e[22]=x):x=e[22];let y;e[23]!==d?(y=J=>{J.stopPropagation(),d()},e[23]=d,e[24]=y):y=e[24];let z;e[25]===Symbol.for("react.memo_cache_sentinel")?(z=t.jsx(F,{name:"file-copy",className:"h-4 w-4 mr-px"}),e[25]=z):z=e[25];let L;e[26]!==u?(L=u("settings.common.actions.duplicate"),e[26]=u,e[27]=L):L=e[27];let I;e[28]!==y||e[29]!==L?(I=t.jsxs(Ht,{onClick:y,children:[z,L]}),e[28]=y,e[29]=L,e[30]=I):I=e[30];let A;e[31]!==o||e[32]!==u?(A=o&&t.jsxs(Ht,{onClick:J=>{J.stopPropagation(),o()},children:[t.jsx(F,{name:"restart",className:"h-4 w-4 mr-px"}),u("settings.common.actions.reset")]}),e[31]=o,e[32]=u,e[33]=A):A=e[33];let w;e[34]!==i||e[35]!==u?(w=i&&t.jsxs(Ht,{onClick:J=>{J.stopPropagation(),i()},className:"text-destructive focus:text-destructive",children:[t.jsx(F,{name:"delete-bin",className:"h-4 w-4 mr-px"}),u("settings.common.actions.delete")]}),e[34]=i,e[35]=u,e[36]=w):w=e[36];let O;e[37]!==x||e[38]!==I||e[39]!==A||e[40]!==w?(O=t.jsxs(is,{align:"end",className:"w-fit min-w-20",children:[x,I,A,w]}),e[37]=x,e[38]=I,e[39]=A,e[40]=w,e[41]=O):O=e[41];let T;e[42]!==f||e[43]!==g||e[44]!==O?(T=t.jsxs(os,{open:f,onOpenChange:g,children:[N,O]}),e[42]=f,e[43]=g,e[44]=O,e[45]=T):T=e[45];let _;e[46]!==T||e[47]!==P?(_=t.jsxs("div",{className:"flex min-w-0 flex-1 items-center",children:[P,T]}),e[46]=T,e[47]=P,e[48]=_):_=e[48];let V;return e[49]!==_||e[50]!==v||e[51]!==b?(V=t.jsx("div",{className:v,onContextMenu:b,children:_}),e[49]=_,e[50]=v,e[51]=b,e[52]=V):V=e[52],V};function Tm(s){return{selectedCommandName:s.selectedCommandName,commands:s.commands,setSelectedCommand:s.setSelectedCommand,setCommandDraft:s.setCommandDraft,createCommand:s.createCommand,deleteCommand:s.deleteCommand,loadCommands:s.loadCommands}}function Fm(s){return s.skills}function Lm(s){return s.loadSkills}function Om(s){return s.name}function zm(s){return!gn(s)}function $m(s,e){return s.name.localeCompare(e.name)}function Bm(s,e){return s.name.localeCompare(e.name)}const Um=()=>{const{t:s}=ot(),{selectedCommandName:e,getCommandByName:n,createCommand:a,updateCommand:r,commands:i,commandDraft:o,setCommandDraft:c}=Nr(bs(I=>({selectedCommandName:I.selectedCommandName,getCommandByName:I.getCommandByName,createCommand:I.createCommand,updateCommand:I.updateCommand,commands:I.commands,commandDraft:I.commandDraft,setCommandDraft:I.setCommandDraft}))),d=e?n(e):null,f=!!(o&&o.name===e&&!d),[g,u]=l.useState(""),[m,k]=l.useState("user"),[h,v]=l.useState(""),[b,R]=l.useState(""),[S,j]=l.useState(""),[E,P]=l.useState(""),[N,x]=l.useState(!1),y=l.useRef(null);l.useEffect(()=>{if(f&&o){const I=o.name||"",A=o.scope||"user",w=o.description||"",O=o.agent||"",T=o.model||"",_=o.template||"";u(I),k(A),v(w),R(O),j(T),P(_),y.current={draftName:I,draftScope:A,description:w,agent:O,model:T,template:_}}else if(d){const I=d.description||"",A=d.agent||"",w=d.model||"",O=d.template||"";v(I),R(A),j(w),P(O),y.current={draftName:"",draftScope:"user",description:I,agent:A,model:w,template:O}}},[d,f,e,i,o]);const z=l.useMemo(()=>{const I=y.current;return I?!!(f&&(g!==I.draftName||m!==I.draftScope)||h!==I.description||b!==I.agent||S!==I.model||E!==I.template):!1},[b,h,g,m,f,S,E]),L=async()=>{const I=f?g.trim().replace(/\s+/g,"-"):e?.trim();if(!I){U.error(s("settings.commands.sidebar.toast.commandNameRequired"));return}if(!E.trim()){U.error(s("settings.commands.page.toast.templateRequired"));return}if(f&&i.some(A=>A.name===I)){U.error(s("settings.commands.sidebar.toast.commandExists"));return}x(!0);try{const A=b.trim(),w=S.trim(),O=E.trim(),T={name:I,description:h.trim()||void 0,agent:A===""?null:A,model:w===""?null:w,template:O,scope:f?m:void 0};let _;f?(_=await a(T),_&&c(null)):_=await r(I,T),_?U.success(s(f?"settings.commands.page.toast.created":"settings.commands.page.toast.updated")):U.error(s(f?"settings.commands.page.toast.createFailed":"settings.commands.page.toast.updateFailed"))}catch(A){console.error("Error saving command:",A),U.error(s("settings.commands.page.toast.saveUnexpectedError"))}finally{x(!1)}};return e?t.jsx(Kt,{outerClassName:"h-full",className:"w-full",children:t.jsxs("div",{className:"mx-auto w-full max-w-3xl p-3 sm:p-6 sm:pt-8",children:[t.jsx("div",{className:"mb-4 flex items-center justify-between gap-4",children:t.jsxs("div",{className:"min-w-0",children:[t.jsx("h2",{className:"typography-ui-header font-semibold text-foreground truncate",children:f?s("settings.commands.page.title.new"):`/${e}`}),t.jsx("p",{className:"typography-meta text-muted-foreground truncate",children:s(f?"settings.commands.page.subtitle.new":"settings.commands.page.subtitle.edit")})]})}),t.jsxs("div",{className:"mb-8",children:[t.jsx("div",{className:"mb-1 px-1",children:t.jsx("h3",{className:"typography-ui-header font-medium text-foreground",children:s("settings.commands.page.section.identity")})}),t.jsxs("section",{className:"px-2 pb-2 pt-0 space-y-0",children:[f&&t.jsxs("div",{className:"flex flex-col gap-2 py-1.5 sm:flex-row sm:items-center sm:gap-8",children:[t.jsx("div",{className:"flex min-w-0 flex-col sm:w-56 shrink-0",children:t.jsx("span",{className:"typography-ui-label text-foreground",children:s("settings.commands.page.field.commandName")})}),t.jsxs("div",{className:"flex min-w-0 flex-1 items-center gap-2 sm:w-fit sm:flex-initial",children:[t.jsxs("div",{className:"flex items-center",children:[t.jsx("span",{className:"typography-ui-label text-muted-foreground mr-1",children:"/"}),t.jsx(nt,{value:g,onChange:I=>u(I.target.value),placeholder:s("settings.commands.page.field.commandNamePlaceholder"),className:"h-7 w-40 px-2"})]}),t.jsxs(St,{value:m,onValueChange:I=>k(I),children:[t.jsx(Ct,{className:"w-fit min-w-[100px]",children:t.jsx(Rt,{placeholder:s("settings.agents.page.field.scopePlaceholder")})}),t.jsxs(Pt,{align:"end",children:[t.jsx(dt,{value:"user",children:t.jsxs("div",{className:"flex items-center gap-2",children:[t.jsx(F,{name:"user-3",className:"h-3.5 w-3.5"}),t.jsx("span",{children:s("settings.common.scope.global")})]})}),t.jsx(dt,{value:"project",children:t.jsxs("div",{className:"flex items-center gap-2",children:[t.jsx(F,{name:"folder",className:"h-3.5 w-3.5"}),t.jsx("span",{children:s("settings.common.scope.project")})]})})]})]})]})]}),t.jsxs("div",{className:"py-1.5",children:[t.jsx("span",{className:"typography-ui-label text-foreground",children:s("settings.common.field.description")}),t.jsx("div",{className:"mt-1.5",children:t.jsx(ls,{value:h,onChange:I=>v(I.target.value),placeholder:s("settings.commands.page.field.descriptionPlaceholder"),rows:2,className:"w-full resize-none min-h-[60px] bg-transparent"})})]})]})]}),t.jsxs("div",{className:"mb-8",children:[t.jsx("div",{className:"mb-1 px-1",children:t.jsx("h3",{className:"typography-ui-header font-medium text-foreground",children:s("settings.commands.page.section.executionContext")})}),t.jsxs("section",{className:"px-2 pb-2 pt-0 space-y-0",children:[t.jsxs("div",{className:"flex flex-col gap-2 py-1.5 sm:flex-row sm:items-center sm:gap-8",children:[t.jsx("div",{className:"flex min-w-0 flex-col sm:w-56 shrink-0",children:t.jsx("span",{className:"typography-ui-label text-foreground",children:s("settings.commands.page.field.overrideAgent")})}),t.jsx("div",{className:"flex min-w-0 flex-1 items-center gap-2 sm:w-fit sm:flex-initial",children:t.jsx(qo,{agentName:b,onChange:I=>R(I)})})]}),t.jsxs("div",{className:"flex flex-col gap-2 py-1.5 sm:flex-row sm:items-center sm:gap-8",children:[t.jsx("div",{className:"flex min-w-0 flex-col sm:w-56 shrink-0",children:t.jsx("span",{className:"typography-ui-label text-foreground",children:s("settings.agents.page.field.overrideModel")})}),t.jsx("div",{className:"flex min-w-0 flex-1 items-center gap-2 sm:w-fit sm:flex-initial",children:t.jsx(wr,{providerId:xn(S)?.providerId??"",modelId:xn(S)?.modelId??"",onChange:(I,A)=>{j(I&&A?`${I}/${A}`:"")}})})]})]})]}),t.jsxs("div",{className:"mb-2",children:[t.jsx("div",{className:"mb-1 px-1",children:t.jsx("h3",{className:"typography-ui-header font-medium text-foreground",children:s("settings.commands.page.section.template")})}),t.jsx("section",{className:"px-2 pb-2 pt-0",children:t.jsx(ls,{value:E,onChange:I=>P(I.target.value),placeholder:s("settings.commands.page.field.templatePlaceholder"),rows:12,className:"w-full font-mono typography-meta min-h-[160px] max-h-[60vh] bg-transparent resize-y"})}),t.jsx("div",{className:"mt-2 px-2",children:t.jsxs("p",{className:"typography-meta text-muted-foreground",children:[t.jsx("code",{className:"text-foreground",children:"$ARGUMENTS"})," ",s("settings.commands.page.templateHint.userInput")," ·"," ",t.jsx("code",{className:"text-foreground",children:"!`cmd`"})," ",s("settings.commands.page.templateHint.shellOutput")," ·"," ",t.jsx("code",{className:"text-foreground",children:"@file"})," ",s("settings.commands.page.templateHint.fileContents")]})})]}),t.jsx("div",{className:"px-2 py-1",children:t.jsx(W,{onClick:L,disabled:N||!z,size:"xs",className:"!font-normal",children:s(N?"settings.common.actions.saving":"settings.common.actions.saveChanges")})})]})}):t.jsx("div",{className:"flex h-full items-center justify-center",children:t.jsxs("div",{className:"text-center text-muted-foreground",children:[t.jsx(F,{name:"terminal-box",className:"mx-auto mb-3 h-12 w-12 opacity-50"}),t.jsx("p",{className:"typography-body",children:s("settings.commands.page.empty.title")}),t.jsx("p",{className:"typography-meta mt-1 opacity-75",children:s("settings.commands.page.empty.description")})]})})},Vm={},Km={},Es=s=>{if(typeof s!="string")return null;const e=s.trim();if(!e)return null;const n=e.replace(/\\/g,"/");return n.length>1?n.replace(/\/+$/,""):n},ln=s=>Es(s)??"__global__",Hs=s=>{const e=Es(s);return e?ns.getScopedApiClient(e):ns.getApiClient()},ps=Ws()(Ln((s,e)=>({byDirectory:{},diagnosticsByDirectory:{},loadingKeys:{},lastErrorKeys:{},getStatusForDirectory:n=>{const a=ln(n??gs.getState().currentDirectory);return e().byDirectory[a]??Vm},getDiagnosticForDirectory:n=>{const a=ln(n??gs.getState().currentDirectory);return e().diagnosticsByDirectory[a]??Km},getErrorForDirectory:n=>{const a=ln(n??gs.getState().currentDirectory);return e().lastErrorKeys[a]??null},refresh:async n=>{const a=Es(n?.directory??gs.getState().currentDirectory),r=ln(a);n?.silent||s(i=>({loadingKeys:{...i.loadingKeys,[r]:!0},lastErrorKeys:{...i.lastErrorKeys,[r]:null}}));try{const c=(await Hs(a).mcp.status()).data??{};s(d=>({byDirectory:{...d.byDirectory,[r]:c},diagnosticsByDirectory:{...d.diagnosticsByDirectory,[r]:Object.fromEntries(Object.entries(d.diagnosticsByDirectory[r]??{}).filter(([f])=>!c[f]))},loadingKeys:{...d.loadingKeys,[r]:!1},lastErrorKeys:{...d.lastErrorKeys,[r]:null}}))}catch(i){const o=i instanceof Error?i.message:"Failed to load MCP status";s(c=>({loadingKeys:{...c.loadingKeys,[r]:!1},lastErrorKeys:{...c.lastErrorKeys,[r]:o}}))}},connect:async(n,a)=>{const r=Es(a??gs.getState().currentDirectory),i=ln(r),o=Hs(r);try{await o.mcp.connect({name:n},{throwOnError:!0})}catch(c){const d=c instanceof Error?c.message:"Connection failed";throw s(f=>({diagnosticsByDirectory:{...f.diagnosticsByDirectory,[i]:{...f.diagnosticsByDirectory[i]??{},[n]:{status:"failed",error:d}}}})),c}await e().refresh({directory:r,silent:!0})},disconnect:async(n,a)=>{const r=Es(a??gs.getState().currentDirectory);await Hs(r).mcp.disconnect({name:n},{throwOnError:!0}),await e().refresh({directory:r,silent:!0})},startAuth:async(n,a)=>{const r=Es(a??gs.getState().currentDirectory),c=(await Hs(r).mcp.auth.start({name:n},{throwOnError:!0})).data?.authorizationUrl;if(!c)throw new Error("Authorization URL was not returned");return c},completeAuth:async(n,a,r)=>{const i=Es(r??gs.getState().currentDirectory);await Hs(i).mcp.auth.callback({name:n,code:a},{throwOnError:!0}),await e().refresh({directory:i,silent:!0})},clearAuth:async(n,a)=>{const r=Es(a??gs.getState().currentDirectory);await Hs(r).mcp.auth.remove({name:n},{throwOnError:!0}),await e().refresh({directory:r,silent:!0})},testConnection:async(n,a)=>{const r=Es(a??gs.getState().currentDirectory),i=ln(r),o=Hs(r),d=e().getStatusForDirectory(r)[n]?.status==="connected";let f,g;try{await o.mcp.connect({name:n},{throwOnError:!0})}catch(k){f=k instanceof Error?k.message:"Connection failed",s(h=>({diagnosticsByDirectory:{...h.diagnosticsByDirectory,[i]:{...h.diagnosticsByDirectory[i]??{},[n]:{status:"failed",error:f??"Connection failed"}}}}))}await e().refresh({directory:r,silent:!0});const u=e().getStatusForDirectory(r)[n],m=u;if(!d&&u?.status==="connected"){try{await o.mcp.disconnect({name:n},{throwOnError:!0})}catch(k){g=`Connection test succeeded, but cleanup disconnect failed: ${k instanceof Error?k.message:"Disconnect failed"}`}await e().refresh({directory:r,silent:!0})}return{status:m??e().getStatusForDirectory(r)[n],error:f,warning:g}}}))),Si=s=>{switch(s){case"connected":return"success";case"failed":return"error";case"needs_auth":case"needs_client_registration":return"warning";default:return"idle"}},Ci=s=>{const e=it.c(5),{tone:n,enabled:a}=s;if(!a){let o;return e[0]===Symbol.for("react.memo_cache_sentinel")?(o=t.jsx("span",{className:"inline-block h-2 w-2 rounded-full bg-muted-foreground/30 flex-shrink-0"}),e[0]=o):o=e[0],o}let r;e[1]!==n?(r=ge("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"}[n]),e[1]=n,e[2]=r):r=e[2];let i;return e[3]!==r?(i=t.jsx("span",{className:r}),e[3]=r,e[4]=i):i=e[4],i},_m=s=>{const e=it.c(116),{onItemSelect:n}=s,{t:a}=ot(),{mcpServers:r,selectedMcpName:i,setSelectedMcp:o,setMcpDraft:c,loadMcpConfigs:d,deleteMcp:f}=Pr(bs(Wm)),g=gs(Hm);let u;e[0]!==g?(u=ce=>ce.getStatusForDirectory(g??null),e[0]=g,e[1]=u):u=e[1];const m=ps(u),k=ps(Gm),h=ps(qm),[v,b]=l.useState(null),[R,S]=l.useState(!1),[j,E]=l.useState(null),[P,N]=l.useState(!1);let x;e[2]!==r?(x=r.filter(Jm),e[2]=r,e[3]=x):x=e[3];const y=x;let z;e[4]!==r?(z=r.filter(Qm),e[4]=r,e[5]=z):z=e[5];const L=z;let I,A;e[6]!==d?(I=()=>{d()},A=[d],e[6]=d,e[7]=I,e[8]=A):(I=e[7],A=e[8]),l.useEffect(I,A);let w;e[9]!==g||e[10]!==h||e[11]!==P||e[12]!==k?(w=()=>{if(P)return;N(!0);const ce=new Promise(Ym);Promise.all([k({directory:g,silent:!0}),ce]).then(()=>{const Se=h(g);Se&&U.error(Se)}).finally(()=>{N(!1)})},e[9]=g,e[10]=h,e[11]=P,e[12]=k,e[13]=w):w=e[13];const O=w;let T;e[14]!==r||e[15]!==n||e[16]!==c||e[17]!==o?(T=()=>{let ce="new-mcp-server",Se=1;for(;r.some(Ke=>Ke.name===ce);)ce=`new-mcp-server-${Se}`,Se++;c({name:ce,scope:"user",type:"local",command:[],url:"",environment:[],headers:[],oauthEnabled:!0,oauthClientId:"",oauthClientSecret:"",oauthScope:"",oauthRedirectUri:"",timeout:"",enabled:!0}),o(ce),n?.()},e[14]=r,e[15]=n,e[16]=c,e[17]=o,e[18]=T):T=e[18];const _=T;let V;e[19]!==f||e[20]!==v||e[21]!==a?(V=async()=>{if(!v)return;S(!0);const ce=await f(v.name);ce.ok?ce.reloadFailed?U.warning(ce.message||`MCP server "${v.name}" deleted, but OpenCode reload failed`,{description:ce.warning||a("settings.mcp.sidebar.toast.refreshListIfStale")}):U.success(ce.message||a("settings.mcp.sidebar.toast.serverDeleted",{name:v.name})):U.error(a("settings.mcp.sidebar.toast.deleteFailed")),b(null),S(!1)},e[19]=f,e[20]=v,e[21]=a,e[22]=V):V=e[22];const J=V;let B;e[23]===Symbol.for("react.memo_cache_sentinel")?(B=ge("flex h-full flex-col","bg-background"),e[23]=B):B=e[23];let D;e[24]!==a?(D=a("settings.mcp.sidebar.title"),e[24]=a,e[25]=D):D=e[25];let K;e[26]!==D?(K=t.jsx("h2",{className:"text-base font-semibold text-foreground",children:D}),e[26]=D,e[27]=K):K=e[27];let C;e[28]!==a?(C=a("settings.mcp.sidebar.actions.refreshStatusAria"),e[28]=a,e[29]=C):C=e[29];let H;e[30]!==a?(H=a("settings.mcp.sidebar.actions.refreshStatusTitle"),e[30]=a,e[31]=H):H=e[31];const G=P&&"animate-spin";let se;e[32]!==G?(se=ge("h-4 w-4",G),e[32]=G,e[33]=se):se=e[33];let oe;e[34]!==se?(oe=t.jsx(F,{name:"refresh",className:se}),e[34]=se,e[35]=oe):oe=e[35];let re;e[36]!==O||e[37]!==P||e[38]!==C||e[39]!==H||e[40]!==oe?(re=t.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:P,onClick:O,"aria-label":C,title:H,children:oe}),e[36]=O,e[37]=P,e[38]=C,e[39]=H,e[40]=oe,e[41]=re):re=e[41];let me;e[42]!==K||e[43]!==re?(me=t.jsxs("div",{className:"mb-3 flex items-center justify-between gap-3",children:[K,re]}),e[42]=K,e[43]=re,e[44]=me):me=e[44];let le;e[45]===Symbol.for("react.memo_cache_sentinel")?(le=t.jsx(On,{className:"mb-3"}),e[45]=le):le=e[45];let ve;e[46]!==r.length||e[47]!==a?(ve=a("settings.mcp.sidebar.total",{count:r.length}),e[46]=r.length,e[47]=a,e[48]=ve):ve=e[48];let Z;e[49]!==ve?(Z=t.jsx("span",{className:"typography-meta text-muted-foreground",children:ve}),e[49]=ve,e[50]=Z):Z=e[50];let X;e[51]!==a?(X=a("settings.mcp.sidebar.actions.addServerTitle"),e[51]=a,e[52]=X):X=e[52];let xe;e[53]===Symbol.for("react.memo_cache_sentinel")?(xe=t.jsx(F,{name:"add",className:"h-3.5 w-3.5"}),e[53]=xe):xe=e[53];let ue;e[54]!==_||e[55]!==X?(ue=t.jsx(W,{size:"sm",variant:"ghost",className:"h-7 w-7 px-0 -my-1 text-muted-foreground",onClick:_,title:X,children:xe}),e[54]=_,e[55]=X,e[56]=ue):ue=e[56];let be;e[57]!==Z||e[58]!==ue?(be=t.jsxs("div",{className:"flex items-center justify-between gap-2",children:[Z,ue]}),e[57]=Z,e[58]=ue,e[59]=be):be=e[59];let de;e[60]!==me||e[61]!==be?(de=t.jsxs("div",{className:"border-b px-3 pt-4 pb-3",children:[me,le,be]}),e[60]=me,e[61]=be,e[62]=de):de=e[62];let we;e[63]!==r.length||e[64]!==m||e[65]!==n||e[66]!==j||e[67]!==y||e[68]!==i||e[69]!==c||e[70]!==o||e[71]!==a||e[72]!==L?(we=t.jsx(Kt,{outerClassName:"flex-1 min-h-0",className:"space-y-1 px-3 py-2 overflow-x-hidden",children:r.length===0?t.jsxs("div",{className:"py-12 px-4 text-center text-muted-foreground",children:[t.jsx(F,{name:"plug",className:"mx-auto mb-3 h-10 w-10 opacity-50"}),t.jsx("p",{className:"typography-ui-label font-medium",children:a("settings.mcp.sidebar.empty.title")}),t.jsx("p",{className:"typography-meta mt-1 opacity-75",children:a("settings.mcp.sidebar.empty.description")})]}):t.jsxs(t.Fragment,{children:[y.length>0&&t.jsxs(t.Fragment,{children:[t.jsx("div",{className:"px-2 pb-1.5 pt-2 text-xs font-semibold uppercase tracking-wide text-muted-foreground",children:a("settings.mcp.sidebar.group.projectServers")}),y.map(ce=>{const Se=m[ce.name],Ue=Si(Se?.status),Ke=i===ce.name,Ye=Tn();return t.jsxs("div",{className:ge("group relative flex items-center rounded-md px-1.5 py-1 transition-all duration-200 select-none",Ke?"bg-interactive-selection":"hover:bg-interactive-hover"),onContextMenu:Ye?void 0:Xe=>{Xe.preventDefault(),E(ce.name)},children:[t.jsxs("button",{onClick:()=>{o(ce.name),c(null),n?.()},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:[t.jsxs("div",{className:"flex items-center gap-2",children:[t.jsx(Ci,{tone:Ue,enabled:ce.enabled}),t.jsx("span",{className:"typography-ui-label font-normal truncate text-foreground",children:ce.name}),t.jsx("span",{title:ce.type==="local"?a("settings.mcp.sidebar.serverType.localTitle"):a("settings.mcp.sidebar.serverType.remoteTitle"),children:ce.type==="local"?t.jsx(F,{name:"server",className:"h-3 w-3 text-muted-foreground/60 flex-shrink-0"}):t.jsx(F,{name:"global",className:"h-3 w-3 text-muted-foreground/60 flex-shrink-0"})})]}),t.jsx("div",{className:"typography-micro text-muted-foreground/60 truncate leading-tight pl-4",children:ce.type==="local"?ce.command?.join(" ")??"":ce.url??""})]}),t.jsxs(os,{open:j===ce.name,onOpenChange:Xe=>E(Xe?ce.name:null),children:[t.jsx(rs,{asChild:!0,children:t.jsx(W,{size:"xs",variant:"ghost",className:"flex-shrink-0 -mr-1 opacity-100 transition-opacity md:opacity-0 md:group-hover:opacity-100",children:t.jsx(F,{name:"more-2",className:"h-3.5 w-3.5"})})}),t.jsx(is,{align:"end",className:"w-fit min-w-20",children:t.jsxs(Ht,{onClick:Xe=>{Xe.stopPropagation(),b(ce)},className:"text-destructive focus:text-destructive",children:[t.jsx(F,{name:"delete-bin",className:"h-4 w-4 mr-px"}),a("settings.common.actions.delete")]})})]})]},ce.name)})]}),L.length>0&&t.jsxs(t.Fragment,{children:[t.jsx("div",{className:"px-2 pb-1.5 pt-2 text-xs font-semibold uppercase tracking-wide text-muted-foreground",children:a("settings.mcp.sidebar.group.userServers")}),L.map(ce=>{const Se=m[ce.name],Ue=Si(Se?.status),Ke=i===ce.name,Ye=Tn();return t.jsxs("div",{className:ge("group relative flex items-center rounded-md px-1.5 py-1 transition-all duration-200 select-none",Ke?"bg-interactive-selection":"hover:bg-interactive-hover"),onContextMenu:Ye?void 0:Xe=>{Xe.preventDefault(),E(ce.name)},children:[t.jsxs("button",{onClick:()=>{o(ce.name),c(null),n?.()},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:[t.jsxs("div",{className:"flex items-center gap-2",children:[t.jsx(Ci,{tone:Ue,enabled:ce.enabled}),t.jsx("span",{className:"typography-ui-label font-normal truncate text-foreground",children:ce.name}),t.jsx("span",{title:ce.type==="local"?a("settings.mcp.sidebar.serverType.localTitle"):a("settings.mcp.sidebar.serverType.remoteTitle"),children:ce.type==="local"?t.jsx(F,{name:"server",className:"h-3 w-3 text-muted-foreground/60 flex-shrink-0"}):t.jsx(F,{name:"global",className:"h-3 w-3 text-muted-foreground/60 flex-shrink-0"})})]}),t.jsx("div",{className:"typography-micro text-muted-foreground/60 truncate leading-tight pl-4",children:ce.type==="local"?ce.command?.join(" ")??"":ce.url??""})]}),t.jsxs(os,{open:j===ce.name,onOpenChange:Xe=>E(Xe?ce.name:null),children:[t.jsx(rs,{asChild:!0,children:t.jsx(W,{size:"xs",variant:"ghost",className:"flex-shrink-0 -mr-1 opacity-100 transition-opacity md:opacity-0 md:group-hover:opacity-100",children:t.jsx(F,{name:"more-2",className:"h-3.5 w-3.5"})})}),t.jsx(is,{align:"end",className:"w-fit min-w-20",children:t.jsxs(Ht,{onClick:Xe=>{Xe.stopPropagation(),b(ce)},className:"text-destructive focus:text-destructive",children:[t.jsx(F,{name:"delete-bin",className:"h-4 w-4 mr-px"}),a("settings.common.actions.delete")]})})]})]},ce.name)})]})]})}),e[63]=r.length,e[64]=m,e[65]=n,e[66]=j,e[67]=y,e[68]=i,e[69]=c,e[70]=o,e[71]=a,e[72]=L,e[73]=we):we=e[73];const Q=v!==null;let he;e[74]!==R?(he=ce=>{!ce&&!R&&b(null)},e[74]=R,e[75]=he):he=e[75];let q;e[76]!==a?(q=a("settings.mcp.sidebar.deleteDialog.title"),e[76]=a,e[77]=q):q=e[77];let ae;e[78]!==q?(ae=t.jsx(zt,{children:q}),e[78]=q,e[79]=ae):ae=e[79];const pe=v?.name||"";let je;e[80]!==a||e[81]!==pe?(je=a("settings.mcp.sidebar.deleteDialog.descriptionPrefix",{name:pe}),e[80]=a,e[81]=pe,e[82]=je):je=e[82];let Me;e[83]===Symbol.for("react.memo_cache_sentinel")?(Me=t.jsx("code",{className:"text-foreground",children:"opencode.json"}),e[83]=Me):Me=e[83];let Pe;e[84]!==je?(Pe=t.jsxs(Vt,{children:[je," ",Me,"."]}),e[84]=je,e[85]=Pe):Pe=e[85];let Re;e[86]!==ae||e[87]!==Pe?(Re=t.jsxs(Bt,{children:[ae,Pe]}),e[86]=ae,e[87]=Pe,e[88]=Re):Re=e[88];let Ee;e[89]===Symbol.for("react.memo_cache_sentinel")?(Ee=()=>b(null),e[89]=Ee):Ee=e[89];let Fe;e[90]!==a?(Fe=a("settings.common.actions.cancel"),e[90]=a,e[91]=Fe):Fe=e[91];let Y;e[92]!==R||e[93]!==Fe?(Y=t.jsx(W,{size:"sm",variant:"ghost",onClick:Ee,disabled:R,children:Fe}),e[92]=R,e[93]=Fe,e[94]=Y):Y=e[94];let fe;e[95]!==R||e[96]!==a?(fe=a(R?"settings.mcp.sidebar.actions.deleting":"settings.common.actions.delete"),e[95]=R,e[96]=a,e[97]=fe):fe=e[97];let Ce;e[98]!==J||e[99]!==R||e[100]!==fe?(Ce=t.jsx(W,{size:"sm",onClick:J,disabled:R,children:fe}),e[98]=J,e[99]=R,e[100]=fe,e[101]=Ce):Ce=e[101];let Ie;e[102]!==Y||e[103]!==Ce?(Ie=t.jsxs(Gt,{children:[Y,Ce]}),e[102]=Y,e[103]=Ce,e[104]=Ie):Ie=e[104];let Le;e[105]!==Re||e[106]!==Ie?(Le=t.jsxs(Ot,{className:"max-w-md",children:[Re,Ie]}),e[105]=Re,e[106]=Ie,e[107]=Le):Le=e[107];let $e;e[108]!==Q||e[109]!==he||e[110]!==Le?($e=t.jsx(Lt,{open:Q,onOpenChange:he,children:Le}),e[108]=Q,e[109]=he,e[110]=Le,e[111]=$e):$e=e[111];let te;return e[112]!==de||e[113]!==we||e[114]!==$e?(te=t.jsxs("div",{className:B,children:[de,we,$e]}),e[112]=de,e[113]=we,e[114]=$e,e[115]=te):te=e[115],te};function Wm(s){return{mcpServers:s.mcpServers,selectedMcpName:s.selectedMcpName,setSelectedMcp:s.setSelectedMcp,setMcpDraft:s.setMcpDraft,loadMcpConfigs:s.loadMcpConfigs,deleteMcp:s.deleteMcp}}function Hm(s){return s.currentDirectory}function Gm(s){return s.refresh}function qm(s){return s.getErrorForDirectory}function Jm(s){return s.scope==="project"}function Qm(s){return s.scope!=="project"}function Ym(s){return setTimeout(s,500)}function _s(s){return typeof s=="object"&&s!==null&&!Array.isArray(s)}function Nn(s){return Array.isArray(s)&&s.every(e=>typeof e=="string")}function Gs(s,e){return e!==void 0?{ok:!1,error:s,parsed:e}:{ok:!1,error:s}}function La(s,e,n){const a=Xm(n),r=typeof n.url=="string"?n.url.trim():"",i=Pi(n,"env","environment"),o=Pi(n,"headers"),c=Zm(n),d=typeof n.oauth=="object"&&n.oauth!==null?String(n.oauth.clientId??"").trim():"",f=typeof n.oauth=="object"&&n.oauth!==null?String(n.oauth.clientSecret??"").trim():"",g=typeof n.oauth=="object"&&n.oauth!==null?String(n.oauth.scope??"").trim():"",u=typeof n.oauth=="object"&&n.oauth!==null?String(n.oauth.redirectUri??"").trim():"",m=eu(n),k=tu(n);return{ok:!0,name:s,type:e,command:a,url:r,environment:i,headers:o,oauthEnabled:c,oauthClientId:d,oauthClientSecret:f,oauthScope:g,oauthRedirectUri:u,timeout:m,enabled:k}}function Xm(s){const e=s.command,n=s.args;if(Nn(e)&&Nn(n))return[...e,...n];if(Nn(e))return e;if(typeof e=="string"&&e.trim()){const a=e.trim().split(/\s+/);return Nn(n)?[...a,...n]:a}return Nn(n)?n:[]}function Pi(s,...e){for(const n of e){const a=s[n];if(!_s(a))continue;const r=Object.entries(a).filter(([i,o])=>i&&typeof o=="string");if(r.length>0)return r.map(([i,o])=>({key:i,value:String(o)}))}return[]}function Zm(s){if(s.oauth===!1||s.oauth===null||s.oauth===void 0||!_s(s.oauth))return!1;const e=s.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 eu(s){const e=s.timeout;if(typeof e=="number"&&Number.isFinite(e)&&e>0)return String(Math.floor(e));if(typeof e=="string"&&e.trim()){const n=Number(e);if(Number.isFinite(n)&&n>0)return String(Math.floor(n))}return""}function tu(s){return"disabled"in s&&s.disabled===!0?!1:"enabled"in s?!!s.enabled:!0}function su(s){const e=s.mcpServers;if(_s(e)){const a=Object.keys(e);if(a.length===1){const r=a[0],i=e[r];if(_s(i))return{name:r,entry:i}}if(a.length>1)return null}const n=Object.keys(s).filter(a=>{const r=s[a];return a!=="mcpServers"&&_s(r)});if(n.length===1){const a=n[0],r=s[a];if(rl(r))return{name:a,entry:r}}return null}function rl(s){return s.type==="local"||s.type==="remote"||Array.isArray(s.command)||typeof s.url=="string"||Array.isArray(s.args)}function nu(s,e){let n;try{const o=s.trim();if(!o)return Gs("No JSON content provided");n=JSON.parse(o)}catch(o){return Gs(o instanceof Error?`Invalid JSON: ${o.message}`:"Invalid JSON")}if(!_s(n))return Gs("Expected a JSON object, not an array or primitive");const a=n,r=a.mcpServers;if(_s(r)){const o=Object.keys(r);if(o.length===0)return Gs("mcpServers object is empty",n);if(o.length>1)return Gs("Paste one server at a time. Found "+o.length+" servers in mcpServers",n);const c=o[0],d=r[c];return _s(d)?La(c,Oa(d),d):Gs("Server entry is not a valid object",n)}const i=su(a);if(i)return La(i.name,Oa(i.entry),i.entry);if(rl(a)){const o=Oa(a),c=typeof a.name=="string"&&a.name.trim()?a.name.trim():e?.fallbackName;return La(c,o,a)}return Gs("No recognizable MCP server configuration found in JSON",n)}function Oa(s){return s.type==="remote"?"remote":s.type==="local"?"local":typeof s.url=="string"&&s.url.trim()?"remote":(Array.isArray(s.command)||typeof s.command=="string"||Array.isArray(s.args),"local")}function au(s,e,n){const a=n?.isNewServer??!1,r=s.name,i=a&&r?r:e.name??"";return{...e,name:i,type:s.type,command:s.type==="local"?s.command:[],url:s.type==="remote"?s.url:"",environment:s.environment,headers:s.type==="remote"?s.headers:[],oauthEnabled:s.type==="remote"?s.oauthEnabled:!1,oauthClientId:s.type==="remote"?s.oauthClientId:"",oauthClientSecret:s.type==="remote"?s.oauthClientSecret:"",oauthScope:s.type==="remote"?s.oauthScope:"",oauthRedirectUri:s.type==="remote"?s.oauthRedirectUri:"",timeout:s.type==="remote"?s.timeout:"",enabled:s.enabled}}const ru="/mcp/oauth/callback",iu=s=>{if(typeof window>"u")return null;try{const e=s.replace(/-/g,"+").replace(/_/g,"/"),n=e.length%4===0?"":"=".repeat(4-e.length%4),a=window.atob(e+n),r=Uint8Array.from(a,i=>i.charCodeAt(0));return new TextDecoder().decode(r)}catch{return null}},ou=s=>{const e=lu(s.get("state"));if(e)return e;const n=s.get("server");if(typeof n!="string"||!n.trim())return null;const a=s.get("directory");return{name:n.trim(),directory:typeof a=="string"&&a.trim()?a.trim():null}},il=s=>{const e=s.get("state");return typeof e!="string"?null:e.trim()||null},lu=s=>{if(typeof s!="string"||!s.trim())return null;const e=iu(s.trim());if(!e)return null;try{const n=JSON.parse(e);return n?.v!==1||typeof n.n!="string"||!n.n.trim()?null:{name:n.n.trim(),directory:typeof n.d=="string"&&n.d.trim()?n.d.trim():null}}catch{return null}},tn=Hl,sn=s=>{const e=it.c(14);let n,a,r,i;e[0]!==s?({className:r,asChild:n,children:a,...i}=s,e[0]=s,e[1]=n,e[2]=a,e[3]=r,e[4]=i):(n=e[1],a=e[2],r=e[3],i=e[4]);let o;e[5]!==n||e[6]!==a?(o=n&&ke.isValidElement(a)?{render:a}:{children:a},e[5]=n,e[6]=a,e[7]=o):o=e[7];const c=o;let d;e[8]!==r?(d=ge("flex w-full items-center justify-between rounded-lg px-2 py-1.5 text-left text-foreground hover:bg-interactive-hover focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-primary",r),e[8]=r,e[9]=d):d=e[9];let f;return e[10]!==i||e[11]!==c||e[12]!==d?(f=t.jsx(Wl,{className:d,...i,...c}),e[10]=i,e[11]=c,e[12]=d,e[13]=f):f=e[13],f},nn=s=>{const e=it.c(8);let n,a;e[0]!==s?({className:n,...a}=s,e[0]=s,e[1]=n,e[2]=a):(n=e[1],a=e[2]);let r;e[3]!==n?(r=ge("overflow-hidden data-[closed]:animate-collapsible-up data-[open]:animate-collapsible-down",n),e[3]=n,e[4]=r):r=e[4];let i;return e[5]!==a||e[6]!==r?(i=t.jsx(Gl,{className:r,...a}),e[5]=a,e[6]=r,e[7]=i):i=e[7],i};function cu(s){const e=[];let n="",a=!1,r=!1;for(let i=0;i<s.length;i++){const o=s[i];if(o==="'"&&!r){a=!a;continue}if(o==='"'&&!a){r=!r;continue}if((o===" "||o===" ")&&!a&&!r){n&&(e.push(n),n="");continue}n+=o}return n&&e.push(n),e}function du(s){const e=s.trim();if(!e)return{code:null,context:null,stateKey:null};try{const n=new URL(e),a=n.searchParams.get("code");if(typeof a=="string"&&a.trim())return{code:a.trim(),context:ou(n.searchParams),stateKey:il(n.searchParams)}}catch{}return{code:e,context:null,stateKey:null}}const mu=({value:s,onChange:e,pasteCommandTitle:n,pasteCommandLabel:a,pasteSuccess:r,clipboardReadFailed:i,preview:o})=>{const[c,d]=l.useState(()=>s.join(`
|
|
4
4
|
`)),f=l.useRef(s);l.useEffect(()=>{JSON.stringify(f.current)!==JSON.stringify(s)&&(f.current=s,d(s.join(`
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
import{H as I,j as t,R as a,c as z}from"./vendor-.bun-TPgXvEwq.js";import{u as V,en as me,fv as oe,aJ as Z,em as ee,am as M,dN as B,B as U,I as W,aT as re,be as ae,al as le,o as ce,m as J,H as T,aM as Q}from"./useAppFontEffects-hYm-4PtP.js";import{b as O}from"./index-D9t9eCUC.js";function pe(r){switch(r){case"ok":return null;case"auth":return"onboarding.remoteConnection.probe.authMessage";case"update-recommended":return"onboarding.remoteConnection.probe.updateRecommendedMessage";case"incompatible":return"onboarding.remoteConnection.probe.incompatibleMessage";case"wrong-service":return"onboarding.remoteConnection.probe.wrongServiceMessage";case"unreachable":return"onboarding.remoteConnection.probe.unreachableMessage";default:return null}}function q(r){return r==="wrong-service"||r==="unreachable"||r==="incompatible"}function ie({onBack:r,showBackButton:e=!0,initialUrl:c="",initialLabel:n="",isRecoveryMode:o=!1,onConnect:f,onSwitchToLocal:i}){const{t:s}=V(),[h,y]=I.useState(c),[x,S]=I.useState(n),[N,b]=I.useState("idle"),[m,v]=I.useState(null),[R,C]=I.useState(""),j=me(h),p=j?.persistedUrl??null,w=I.useCallback(d=>{y(d.target.value),b("idle"),v(null),C("")},[]),g=I.useCallback(d=>{S(d.target.value)},[]),k=I.useCallback(async()=>{if(p){b("testing"),v(null),C("");try{const d=await oe(p);v(d),b(d.status==="ok"||d.status==="update-recommended"?"success":"error")}catch(d){C(d instanceof Error?d.message:s("onboarding.remoteConnection.errors.connectionTestFailed")),b("error")}}},[p,s]),K=I.useCallback(async()=>{if(!j)return;const d=j.persistedUrl;b("testing"),v(null),C("");try{const D=await oe(d);if(v(D),q(D.status)){b("error");return}const F=await Z(),de=x.trim()||d,G=F.hosts.find($=>$.url===d),Y=G?G.id:`host-${Date.now().toString(16)}`,te={id:Y,label:de,url:d,apiUrl:d},ue=G?F.hosts.map($=>$.id===Y?te:$):[...F.hosts,te];if(await ee({hosts:ue,defaultHostId:Y,initialHostChoiceCompleted:!0}),f?.(),j.redeemUrl){window.location.assign(j.redeemUrl);return}M()&&await B()}catch(D){C(D instanceof Error?D.message:s("onboarding.remoteConnection.errors.failedToSaveConnection")),b("error")}},[j,x,f,s]),L=N==="testing",A=p!==null&&!L,_=p!==null&&!L&&!q(m?.status??null),P=pe(m?.status??null),H=m?.status==="ok",u=m?.status==="update-recommended",E=m?.status==="auth",l=q(m?.status??null);return t.jsx("div",{className:"flex flex-col items-center justify-center h-full p-8",children:t.jsxs("div",{className:"w-full max-w-md space-y-6",children:[e&&t.jsx("div",{className:"flex items-center",children:t.jsx(U,{variant:"ghost",onClick:r,className:"p-0 text-muted-foreground hover:text-foreground",children:s("onboarding.common.actions.back")})}),t.jsxs("div",{className:"space-y-2 text-center",children:[t.jsx("h1",{className:"typography-ui-header text-xl font-semibold text-foreground",children:s(o?"onboarding.remoteConnection.titleRecovery":"onboarding.remoteConnection.title")}),t.jsx("p",{className:"text-muted-foreground text-sm",children:s("onboarding.remoteConnection.description")})]}),t.jsxs("div",{className:"space-y-4",children:[t.jsxs("div",{className:"space-y-2",children:[t.jsx("label",{htmlFor:"remote-url",className:"text-sm text-foreground",children:s("onboarding.remoteConnection.field.serverAddress")}),t.jsx(W,{id:"remote-url",type:"url",value:h,onChange:w,placeholder:s("onboarding.remoteConnection.field.serverAddressPlaceholder"),disabled:L})]}),t.jsxs("div",{className:"space-y-2",children:[t.jsx("label",{htmlFor:"remote-label",className:"text-sm text-foreground",children:s("onboarding.remoteConnection.field.nameOptional")}),t.jsx(W,{id:"remote-label",type:"text",value:x,onChange:g,placeholder:s("onboarding.remoteConnection.field.namePlaceholder"),disabled:L})]})]}),m&&H&&t.jsx("div",{className:"rounded-lg border p-3 text-sm",style:{borderColor:"var(--status-success)",color:"var(--status-success)"},children:s("onboarding.remoteConnection.status.connectedSuccessfully",{latencyMs:m.latencyMs})}),m&&E&&t.jsx("div",{className:"rounded-lg border p-3 text-sm",style:{borderColor:"var(--status-warning)",color:"var(--status-warning)"},children:s("onboarding.remoteConnection.status.authWarning")}),m&&u&&t.jsx("div",{className:"rounded-lg border p-3 text-sm",style:{borderColor:"var(--status-warning)",color:"var(--status-warning)"},children:P?s(P):null}),m&&l&&t.jsxs("div",{className:"rounded-lg border p-3 text-sm space-y-3",style:{borderColor:"var(--status-error)",color:"var(--status-error)"},children:[t.jsxs("div",{children:[t.jsx("div",{className:"font-semibold mb-1",children:s("onboarding.remoteConnection.status.connectionFailed")}),t.jsx("div",{className:"opacity-90",children:P?s(P):null})]}),t.jsx("div",{className:"text-xs opacity-80",children:m.status==="unreachable"?s("onboarding.remoteConnection.status.suggestionsUnreachable"):s("onboarding.remoteConnection.status.suggestionsWrongService")})]}),R&&t.jsx("div",{className:"rounded-lg border p-3 text-sm",style:{borderColor:"var(--status-error)",color:"var(--status-error)"},children:R}),t.jsxs("div",{className:"flex gap-3",children:[t.jsx(U,{variant:"outline",onClick:k,disabled:!A,children:s(L?"onboarding.remoteConnection.actions.testing":"onboarding.remoteConnection.actions.testConnection")}),t.jsx(U,{onClick:K,disabled:!_,children:s("onboarding.remoteConnection.actions.connectAndRestart")})]}),l&&t.jsxs("div",{className:"flex flex-col gap-2 pt-2 border-t border-border",children:[t.jsx("div",{className:"text-xs text-muted-foreground text-center",children:s("onboarding.remoteConnection.actions.whatToDo")}),t.jsxs("div",{className:"flex gap-2",children:[t.jsx(U,{variant:"outline",size:"sm",onClick:r,className:"flex-1",children:s("onboarding.remoteConnection.actions.chooseDifferentServer")}),!o&&i&&t.jsx(U,{variant:"outline",size:"sm",onClick:i,className:"flex-1",children:s("onboarding.remoteConnection.actions.useLocalInstead")})]})]})]})})}const he="curl -fsSL https://opencode.ai/install | bash",be="https://opencode.ai/docs",se=2500;function fe(r){const e=z.c(5),{onCopy:c,copyTitle:n}=r;let o;e[0]===Symbol.for("react.memo_cache_sentinel")?(o=t.jsxs("code",{className:"flex-1 text-left overflow-x-auto whitespace-nowrap",children:[t.jsx("span",{style:{color:"var(--syntax-keyword)"},children:"curl"}),t.jsx("span",{className:"text-muted-foreground",children:" -fsSL "}),t.jsx("span",{style:{color:"var(--syntax-string)"},children:"https://opencode.ai/install"}),t.jsx("span",{className:"text-muted-foreground",children:" | "}),t.jsx("span",{style:{color:"var(--syntax-keyword)"},children:"bash"})]}),e[0]=o):o=e[0];let f;e[1]===Symbol.for("react.memo_cache_sentinel")?(f=t.jsx(T,{name:"file-copy",className:"h-4 w-4"}),e[1]=f):f=e[1];let i;return e[2]!==n||e[3]!==c?(i=t.jsxs("div",{className:"flex items-center justify-between gap-3 w-full",children:[o,t.jsx("button",{onClick:c,className:"inline-flex items-center text-muted-foreground hover:text-foreground transition-colors shrink-0",title:n,"aria-label":n,children:f})]}),e[2]=n,e[3]=c,e[4]=i):i=e[4],i}function xe({onCliAvailable:r}){const{t:e}=V(),[c,n]=a.useState(!1),[o,f]=a.useState(!1),[i,s]=a.useState(!1),[h,y]=a.useState(!1),[x,S]=a.useState(""),[N,b]=a.useState("unknown"),[m,v]=a.useState("local"),[R,C]=a.useState(!1),[j,p]=a.useState(!1);a.useEffect(()=>{f(M())},[]),a.useEffect(()=>{if(typeof navigator>"u"){b("unknown");return}const l=navigator.userAgent||"";/Windows/i.test(l)?b("windows"):/Macintosh|Mac OS X/i.test(l)?b("macos"):/Linux/i.test(l)?b("linux"):b("unknown")},[]),a.useEffect(()=>{let l=!1;return(async()=>{try{const d=await O("/api/config/settings",{method:"GET",headers:{Accept:"application/json"}});if(!d.ok)return;const D=await d.json().catch(()=>null);if(!D||l)return;const F=typeof D.opencodeBinary=="string"?D.opencodeBinary.trim():"";F&&S(F)}catch{}})(),()=>{l=!0}},[]);const w=a.useCallback(async l=>{const d=l.target;d.closest(".app-region-no-drag")||d.closest("button, a, input, select, textarea, code, summary, details")||l.button===0&&o&&await re()},[o]),g=a.useCallback(async()=>{try{const l=await O("/health");if(!l.ok)return!1;const d=await l.json();return d.openCodeRunning===!0||d.isOpenCodeReady===!0}catch{return!1}},[]),k=a.useCallback(async l=>{if(!o)return;const d=await Z();await ee({...d,...l==="local"?{defaultHostId:"local"}:{},initialHostChoiceCompleted:!0})},[o]),K=a.useCallback(async()=>{o&&await k("local"),r?.()},[o,r,k]);a.useEffect(()=>{if(m!=="local")return;let l=!1,d=null;const D=async()=>{if(!l){try{const F=await g();if(l)return;if(F){await K();return}}catch{}l||(d=setTimeout(D,se))}};return d=setTimeout(D,se),()=>{l=!0,d&&clearTimeout(d)}},[m,g,K]);const L=a.useCallback(async()=>{y(!0);try{await g()&&await K()}finally{y(!1)}},[g,K]),A=a.useCallback(async()=>{if(!(typeof window>"u")&&o)try{const l=await ae();l.success&&l.path&&l.path.trim().length>0&&S(l.path.trim())}catch{}},[o]),_=a.useCallback(async()=>{s(!0);try{if(await le({opencodeBinary:x.trim()}),o){await k("local"),await B();return}await O("/api/config/reload",{method:"POST"})}finally{setTimeout(()=>s(!1),1e3)}},[o,x,k]),P=a.useCallback(async()=>{const l=await ce(he);l.ok?(n(!0),setTimeout(()=>n(!1),2e3)):console.error("Failed to copy:",l.error)},[]),H=be,u=N==="windows"?"C:\\Users\\you\\AppData\\Roaming\\npm\\opencode.cmd":N==="linux"?"/home/you/.bun/bin/opencode":"/Users/you/.bun/bin/opencode",E=!o||m==="local";return t.jsx("div",{className:"app-region-drag h-full flex items-center justify-center bg-transparent p-8 cursor-default select-none overflow-y-auto",onMouseDown:w,children:t.jsxs("div",{className:"w-full max-w-md space-y-7",children:[t.jsxs("header",{className:"text-center space-y-1.5",children:[t.jsx("h1",{className:"text-2xl font-semibold tracking-tight text-foreground",children:e("onboarding.chooser.title")}),t.jsx("p",{className:"text-sm text-muted-foreground",children:e("onboarding.chooser.description")})]}),o&&t.jsxs("div",{className:"app-region-no-drag flex gap-1.5",children:[t.jsx("button",{type:"button",className:J("flex-1 px-4 py-2 rounded-lg border transition-colors text-sm",m==="local"?"border-[var(--interactive-selection)] text-foreground bg-[var(--interactive-selection)]/10":"border-border text-muted-foreground hover:text-foreground hover:border-muted-foreground"),onClick:()=>v("local"),children:e("onboarding.chooser.tabs.localInstall")}),t.jsx("button",{type:"button",className:J("flex-1 px-4 py-2 rounded-lg border transition-colors text-sm",m==="remote"?"border-[var(--interactive-selection)] text-foreground bg-[var(--interactive-selection)]/10":"border-border text-muted-foreground hover:text-foreground hover:border-muted-foreground"),onClick:()=>v("remote"),children:e("onboarding.chooser.tabs.connectRemote")})]}),o&&m==="remote"?t.jsx("div",{className:"app-region-no-drag",children:t.jsx(ie,{onBack:()=>v("local"),showBackButton:!1,onSwitchToLocal:()=>v("local")})}):null,E&&t.jsxs("div",{className:"space-y-4",children:[N==="windows"&&t.jsxs("div",{className:"rounded-lg border border-border bg-background/50 p-4",children:[t.jsx("div",{className:"text-sm text-foreground",children:e("onboarding.localSetup.windows.title")}),t.jsxs("ol",{className:"mt-2 list-decimal space-y-1 pl-5 text-sm text-muted-foreground",children:[t.jsx("li",{children:e("onboarding.localSetup.windows.stepRunInstallInWsl")}),t.jsx("li",{children:e("onboarding.localSetup.windows.stepSetBinaryPath")})]})]}),t.jsx("p",{className:"text-sm text-muted-foreground text-center leading-relaxed",children:e("onboarding.localSetup.intro")}),t.jsx("div",{className:"app-region-no-drag rounded-lg border border-border bg-background/60 backdrop-blur-sm px-4 py-3 font-mono text-sm",children:c?t.jsxs("div",{className:"flex items-center gap-2",style:{color:"var(--status-success)"},children:[t.jsx(T,{name:"check",className:"h-4 w-4"}),e("onboarding.common.status.copiedToClipboard")]}):t.jsx(fe,{onCopy:P,copyTitle:e("onboarding.common.copyToClipboard")})}),t.jsxs("div",{className:"app-region-no-drag flex items-center justify-between",children:[t.jsxs("a",{href:H,target:"_blank",rel:"noopener noreferrer",className:"text-xs text-muted-foreground hover:text-foreground transition-colors inline-flex items-center gap-1",children:[e(N==="windows"?"onboarding.localSetup.docs.windows":"onboarding.localSetup.docs.default"),t.jsx(T,{name:"external-link",className:"h-3 w-3"})]}),t.jsx("button",{type:"button",onClick:L,disabled:h,className:"text-xs text-muted-foreground hover:text-foreground transition-colors disabled:opacity-50",children:e(h?"onboarding.localSetup.actions.checking":"onboarding.localSetup.actions.checkNow")})]}),t.jsxs("div",{className:"rounded-lg border px-4 py-3 flex items-center gap-3",style:{borderColor:"color-mix(in srgb, var(--primary-base) 20%, transparent)",backgroundColor:"color-mix(in srgb, var(--primary-base) 6%, transparent)"},role:"status","aria-live":"polite",children:[t.jsxs("span",{className:"relative inline-flex h-2.5 w-2.5 shrink-0","aria-hidden":!0,children:[t.jsx("span",{className:"absolute inset-0 rounded-full",style:{backgroundColor:"var(--primary-base)",animation:"pulse-opacity 1.6s ease-in-out infinite"}}),t.jsx("span",{className:"absolute inset-[-4px] rounded-full",style:{backgroundColor:"var(--primary-base)",animation:"pulse-opacity-dim 1.6s ease-in-out infinite",opacity:0}})]}),t.jsxs("div",{className:"flex-1 min-w-0",children:[t.jsx("div",{className:"text-sm text-foreground leading-tight",children:e("onboarding.localSetup.status.watching")}),t.jsx("div",{className:"text-xs text-muted-foreground leading-tight mt-0.5",children:e("onboarding.localSetup.status.autoContinue")})]})]}),t.jsxs("details",{className:"app-region-no-drag group rounded-lg border border-border/60 px-4 open:bg-background/40 transition-colors",open:R,onToggle:l=>C(l.currentTarget.open),children:[t.jsxs("summary",{className:"flex items-center justify-between cursor-pointer py-2.5 text-sm text-muted-foreground hover:text-foreground transition-colors list-none [&::-webkit-details-marker]:hidden",children:[t.jsx("span",{children:e("onboarding.localSetup.advanced.title")}),t.jsx(T,{name:"arrow-down-s",className:"h-4 w-4 transition-transform group-open:rotate-180"})]}),t.jsxs("div",{className:"pb-4 space-y-2",children:[t.jsxs("div",{className:"flex gap-2",children:[t.jsx(W,{value:x,onChange:l=>S(l.target.value),placeholder:u,disabled:i,className:"flex-1 font-mono text-xs"}),t.jsx(U,{type:"button",variant:"secondary",size:"sm",onClick:A,disabled:i||!o,children:e("onboarding.localSetup.actions.browse")}),t.jsx(U,{type:"button",size:"sm",onClick:_,disabled:i||!x.trim(),children:e("onboarding.localSetup.actions.apply")})]}),t.jsx("p",{className:"text-xs text-muted-foreground/70",children:e("onboarding.localSetup.helper.saveAndReload")})]})]}),t.jsxs("details",{className:"app-region-no-drag group rounded-lg border border-border/60 px-4 open:bg-background/40 transition-colors",open:j,onToggle:l=>p(l.currentTarget.open),children:[t.jsxs("summary",{className:"flex items-center justify-between cursor-pointer py-2.5 text-sm text-muted-foreground hover:text-foreground transition-colors list-none [&::-webkit-details-marker]:hidden",children:[t.jsx("span",{children:e("onboarding.localSetup.troubleshoot.title")}),t.jsx(T,{name:"arrow-down-s",className:"h-4 w-4 transition-transform group-open:rotate-180"})]}),t.jsx("ul",{className:"pb-4 space-y-1.5 text-xs text-muted-foreground list-disc pl-4",children:N==="windows"?t.jsx(t.Fragment,{children:t.jsx("li",{children:e("onboarding.localSetup.windows.hintDetectionFailed")})}):t.jsxs(t.Fragment,{children:[t.jsx("li",{children:e("onboarding.localSetup.hint.ensurePath")}),t.jsx("li",{children:e("onboarding.localSetup.hint.setEnv")}),t.jsx("li",{children:e("onboarding.localSetup.hint.missingRuntime")})]})})]})]})]})})}const ge="curl -fsSL https://opencode.ai/install | bash",ye="https://opencode.ai/docs";function ve(r){const e=z.c(5),{onCopy:c,copyTitle:n}=r;let o;e[0]===Symbol.for("react.memo_cache_sentinel")?(o=t.jsxs("code",{children:[t.jsx("span",{style:{color:"var(--syntax-keyword)"},children:"curl"}),t.jsx("span",{className:"text-muted-foreground",children:" -fsSL "}),t.jsx("span",{style:{color:"var(--syntax-string)"},children:"https://opencode.ai/install"}),t.jsx("span",{className:"text-muted-foreground",children:" | "}),t.jsx("span",{style:{color:"var(--syntax-keyword)"},children:"bash"})]}),e[0]=o):o=e[0];let f;e[1]===Symbol.for("react.memo_cache_sentinel")?(f=t.jsx(T,{name:"file-copy",className:"h-4 w-4"}),e[1]=f):f=e[1];let i;return e[2]!==n||e[3]!==c?(i=t.jsxs("div",{className:"flex items-center justify-center gap-3",children:[o,t.jsx("button",{onClick:c,className:"inline-flex items-center text-muted-foreground hover:text-foreground transition-colors",title:n,children:f})]}),e[2]=n,e[3]=c,e[4]=i):i=e[4],i}const we=3e4;function je({onBack:r,onCliAvailable:e,isFromRecovery:c=!1,onSwitchToRemote:n}){const{t:o}=V(),[f,i]=a.useState(!1),[s,h]=a.useState(!1),[y,x]=a.useState(!1),[S,N]=a.useState(!1),[b,m]=a.useState(!1),[v,R]=a.useState(null),[C,j]=a.useState(""),[p,w]=a.useState("unknown");a.useEffect(()=>{const u=setTimeout(()=>h(!0),we);return()=>clearTimeout(u)},[]),a.useEffect(()=>{x(M())},[]),a.useEffect(()=>{if(typeof navigator>"u"){w("unknown");return}const u=navigator.userAgent||"";if(/Windows/i.test(u)){w("windows");return}if(/Macintosh|Mac OS X/i.test(u)){w("macos");return}if(/Linux/i.test(u)){w("linux");return}w("unknown")},[]),a.useEffect(()=>{let u=!1;return(async()=>{try{const E=await O("/api/config/settings",{method:"GET",headers:{Accept:"application/json"}});if(!E.ok)return;const l=await E.json().catch(()=>null);if(!l||u)return;const d=typeof l.opencodeBinary=="string"?l.opencodeBinary.trim():"";d&&j(d)}catch{}})(),()=>{u=!0}},[]);const g=a.useCallback(async u=>{u.target.closest("button, a, input, select, textarea, code")||u.button===0&&y&&await re()},[y]),k=a.useCallback(async()=>{try{const u=await O("/health");if(!u.ok)return!1;const E=await u.json();return E.openCodeRunning===!0||E.isOpenCodeReady===!0}catch{return!1}},[]),K=a.useCallback(async()=>{if(!(typeof window>"u")&&y)try{const u=await ae();u.success&&u.path&&u.path.trim().length>0&&j(u.path.trim())}catch{}},[y]),L=a.useCallback(async()=>{N(!0);try{if(await le({opencodeBinary:C.trim()}),y){await B();return}await O("/api/config/reload",{method:"POST"})}finally{setTimeout(()=>N(!1),1e3)}},[y,C]),A=a.useCallback(async()=>{const u=await ce(ge);u.ok?(i(!0),setTimeout(()=>i(!1),2e3)):console.error("Failed to copy:",u.error)},[]),_=a.useCallback(async()=>{m(!0),R(null);try{await k()?e?.():R(o("onboarding.localSetup.errors.cliNotReady"))}catch(u){R(u instanceof Error?u.message:o("onboarding.localSetup.errors.detectionFailed"))}finally{m(!1)}},[k,e,o]),P=ye,H=p==="windows"?"C:\\Users\\you\\AppData\\Roaming\\npm\\opencode.cmd":p==="linux"?"/home/you/.bun/bin/opencode":"/Users/you/.bun/bin/opencode";return t.jsxs("div",{className:"h-full flex items-center justify-center bg-transparent p-8 relative cursor-default select-none",onMouseDown:g,children:[t.jsxs("div",{className:"w-full max-w-lg space-y-4 text-center",children:[t.jsx("div",{className:"flex items-center",children:t.jsx(U,{variant:"ghost",onClick:r,className:"p-0 text-muted-foreground hover:text-foreground",children:o("onboarding.common.actions.back")})}),t.jsxs("div",{className:"space-y-4",children:[t.jsx("h1",{className:"text-3xl font-semibold tracking-tight text-foreground",children:o("onboarding.localSetup.title")}),t.jsx("p",{className:"text-muted-foreground",children:o("onboarding.localSetup.description")})]}),p==="windows"&&t.jsxs("div",{className:"mx-auto max-w-2xl rounded-lg border border-border bg-background/50 p-4 text-left",children:[t.jsx("div",{className:"text-sm text-foreground",children:o("onboarding.localSetup.windows.title")}),t.jsxs("ol",{className:"mt-2 list-decimal space-y-1 pl-5 text-sm text-muted-foreground",children:[t.jsx("li",{children:o("onboarding.localSetup.windows.stepRunInstallInWsl")}),t.jsx("li",{children:o("onboarding.localSetup.windows.stepSetBinaryPath")})]})]}),t.jsx("div",{className:"flex justify-center",children:t.jsx("div",{className:"bg-background/60 backdrop-blur-sm border border-border rounded-lg px-5 py-3 font-mono text-sm w-fit",children:f?t.jsxs("div",{className:"flex items-center justify-center gap-2",style:{color:"var(--status-success)"},children:[t.jsx(T,{name:"check",className:"h-4 w-4"}),o("onboarding.common.status.copiedToClipboard")]}):t.jsx(ve,{onCopy:A,copyTitle:o("onboarding.common.copyToClipboard")})})}),t.jsxs("a",{href:P,target:"_blank",rel:"noopener noreferrer",className:"text-sm text-muted-foreground hover:text-foreground transition-colors inline-flex items-center gap-1 justify-center",children:[o(p==="windows"?"onboarding.localSetup.docs.windows":"onboarding.localSetup.docs.default"),t.jsx(T,{name:"external-link",className:"h-3 w-3"})]}),v&&t.jsx("div",{className:"mx-auto max-w-md rounded-lg border border-destructive/50 bg-destructive/10 p-3 text-sm text-destructive",children:v}),t.jsxs("div",{className:"space-y-3",children:[t.jsx(U,{type:"button",onClick:_,disabled:b,className:"w-full max-w-xs",size:"lg",children:o(b?"onboarding.localSetup.actions.checking":"onboarding.localSetup.actions.checkAndContinue")}),t.jsx("p",{className:"text-xs text-muted-foreground",children:o("onboarding.localSetup.helper.checkAndContinue")})]}),t.jsx("div",{className:"mx-auto w-full max-w-xl pt-4",children:t.jsxs("div",{className:"space-y-2",children:[t.jsx("div",{className:"text-sm text-muted-foreground",children:o("onboarding.localSetup.field.alreadyInstalled")}),t.jsxs("div",{className:"flex gap-2",children:[t.jsx(W,{value:C,onChange:u=>j(u.target.value),placeholder:H,disabled:S,className:"flex-1 font-mono text-xs"}),t.jsx(U,{type:"button",variant:"secondary",onClick:K,disabled:S||!y,children:o("onboarding.localSetup.actions.browse")}),t.jsx(U,{type:"button",onClick:L,disabled:S,children:o("onboarding.localSetup.actions.apply")})]}),t.jsx("div",{className:"text-xs text-muted-foreground/70",children:o("onboarding.localSetup.helper.saveAndReload")})]})}),c&&n&&t.jsxs("div",{className:"text-center pt-4",children:[t.jsx("p",{className:"text-sm text-muted-foreground mb-2",children:o("onboarding.localSetup.remotePreference")}),t.jsx(U,{variant:"link",onClick:n,children:o("onboarding.localSetup.actions.connectRemoteServer")})]})]}),s&&t.jsx("div",{className:"absolute bottom-8 left-0 right-0 text-center space-y-1",children:p==="windows"?t.jsx(t.Fragment,{children:t.jsx("p",{className:"text-sm text-muted-foreground/70",children:o("onboarding.localSetup.windows.hintDetectionFailed")})}):t.jsxs(t.Fragment,{children:[t.jsx("p",{className:"text-sm text-muted-foreground/70",children:o("onboarding.localSetup.hint.ensurePath")}),t.jsx("p",{className:"text-sm text-muted-foreground/70",children:o("onboarding.localSetup.hint.setEnv")}),t.jsx("p",{className:"text-sm text-muted-foreground/70",children:o("onboarding.localSetup.hint.missingRuntime")})]})})]})}function X(r,e){if(r?.trim())return Q(r.trim());if(e)return Q(e)}function ke(r,e,c){switch(r){case"local-unavailable":return{title:"Local OpenCode Unavailable",description:"OpenCode CLI could not be started or is not installed. Install OpenCode or connect to a remote server instead.",titleKey:"onboarding.desktopRecovery.localUnavailable.title",descriptionKey:"onboarding.desktopRecovery.localUnavailable.description",iconKey:"local",showRetry:!0,retryLabel:"Retry Local",retryLabelKey:"onboarding.desktopRecovery.localUnavailable.retry",showUseLocal:!0,showUseRemote:!0,useLocalLabel:"Set Up Local",useLocalLabelKey:"onboarding.desktopRecovery.localUnavailable.useLocal",useRemoteLabel:"Use Remote",useRemoteLabelKey:"onboarding.desktopRecovery.common.useRemote"};case"remote-missing":return{title:"No Default Connection",description:"Your saved default connection could not be found. Choose how you want to connect.",titleKey:"onboarding.desktopRecovery.noDefaultConnection.title",descriptionKey:"onboarding.desktopRecovery.noDefaultConnection.description",iconKey:"local",showRetry:!1,showUseLocal:!0,showUseRemote:!0,useLocalLabel:"Use Local",useLocalLabelKey:"onboarding.desktopRecovery.common.useLocal",useRemoteLabel:"Use Remote",useRemoteLabelKey:"onboarding.desktopRecovery.common.useRemote"};case"remote-unreachable":{const n=X(e,c);return{title:"Remote Server Unreachable",description:`Could not connect to "${n||"the remote server"}". Check your network connection and verify the server address.`,titleKey:"onboarding.desktopRecovery.remoteUnreachable.title",descriptionKey:"onboarding.desktopRecovery.remoteUnreachable.description",descriptionParams:n?{host:n}:void 0,iconKey:"remote",showRetry:!0,retryLabel:"Retry Connection",retryLabelKey:"onboarding.desktopRecovery.remoteUnreachable.retry",showUseLocal:!0,showUseRemote:!0,useLocalLabel:"Use Local",useLocalLabelKey:"onboarding.desktopRecovery.common.useLocal",useRemoteLabel:"Use Remote",useRemoteLabelKey:"onboarding.desktopRecovery.common.useRemote"}}case"remote-wrong-service":{const n=X(e,c);return{title:"Incompatible Server",description:`The server at "${n||"unknown"}" is not running OpenChamber. Verify the address points to an OpenChamber server.`,titleKey:"onboarding.desktopRecovery.incompatibleServer.title",descriptionKey:"onboarding.desktopRecovery.incompatibleServer.description",descriptionParams:n?{host:n}:void 0,iconKey:"remote",showRetry:!1,showUseLocal:!0,showUseRemote:!0,useLocalLabel:"Use Local",useLocalLabelKey:"onboarding.desktopRecovery.common.useLocal",useRemoteLabel:"Use Remote",useRemoteLabelKey:"onboarding.desktopRecovery.common.useRemote"}}case"remote-incompatible":{const n=X(e,c);return{title:"Server Update Required",description:`The OpenChamber server at "${n||"unknown"}" is not compatible with this app version. Update OpenChamber on the server, then try again.`,titleKey:"onboarding.desktopRecovery.remoteIncompatible.title",descriptionKey:"onboarding.desktopRecovery.remoteIncompatible.description",descriptionParams:n?{host:n}:void 0,iconKey:"remote",showRetry:!0,retryLabel:"Retry Connection",retryLabelKey:"onboarding.desktopRecovery.remoteUnreachable.retry",showUseLocal:!0,showUseRemote:!0,useLocalLabel:"Use Local",useLocalLabelKey:"onboarding.desktopRecovery.common.useLocal",useRemoteLabel:"Use Remote",useRemoteLabelKey:"onboarding.desktopRecovery.common.useRemote"}}case"missing-default-host":return{title:"No Default Connection",description:"Your saved default connection could not be found. Choose how you want to connect.",titleKey:"onboarding.desktopRecovery.noDefaultConnection.title",descriptionKey:"onboarding.desktopRecovery.noDefaultConnection.description",iconKey:"local",showRetry:!1,showUseLocal:!0,showUseRemote:!0,useLocalLabel:"Use Local",useLocalLabelKey:"onboarding.desktopRecovery.common.useLocal",useRemoteLabel:"Use Remote",useRemoteLabelKey:"onboarding.desktopRecovery.common.useRemote"};default:{const n=r;throw new Error(`Unknown recovery variant: ${n}`)}}}function Ce(r){switch(r){case"local":return t.jsx(T,{name:"macbook",className:"h-8 w-8"});case"remote":return t.jsx(T,{name:"server",className:"h-8 w-8"})}}function Ne({variant:r,hostLabel:e,hostUrl:c,onRetry:n,onUseLocal:o,onUseRemote:f,isRetrying:i=!1}){const{t:s}=V(),h=ke(r,e,c),y=h.retryLabelKey??"onboarding.desktopRecovery.actions.retryConnection",x=a.useMemo(()=>{if(h.descriptionParams?.host)return h.descriptionParams;if(r==="remote-unreachable")return{host:s("onboarding.desktopRecovery.placeholders.remoteServer")};if(r==="remote-wrong-service"||r==="remote-incompatible")return{host:s("onboarding.desktopRecovery.placeholders.unknownServer")}},[h.descriptionParams,s,r]);return t.jsx("div",{className:"flex flex-col items-center justify-center h-full p-8",children:t.jsxs("div",{className:"w-full max-w-md space-y-6",children:[t.jsxs("div",{className:"flex flex-col items-center space-y-3 text-center",children:[t.jsx("div",{className:"p-3 rounded-full",style:{backgroundColor:"var(--status-warning)",opacity:.15},children:t.jsx("div",{style:{color:"var(--status-warning)"},children:Ce(h.iconKey)})}),t.jsx("h1",{className:"typography-ui-header text-xl font-semibold text-foreground",children:s(h.titleKey)}),t.jsx("p",{className:"text-muted-foreground text-sm max-w-sm",children:s(h.descriptionKey,x)})]}),c&&(r==="remote-unreachable"||r==="remote-wrong-service"||r==="remote-incompatible")&&t.jsxs("div",{className:"rounded-lg border border-border bg-background/50 p-3",children:[t.jsx("div",{className:"text-xs text-muted-foreground mb-1",children:s("onboarding.remoteConnection.field.serverAddress")}),t.jsx("div",{className:"font-mono text-sm text-foreground truncate",children:Q(c)})]}),t.jsxs("div",{className:"flex flex-col gap-2",children:[h.showRetry&&n&&t.jsxs(U,{onClick:n,disabled:i,className:"w-full",children:[t.jsx(T,{name:"refresh",className:J("h-4 w-4",i&&"animate-spin")}),s(i?"onboarding.desktopRecovery.actions.retrying":y)]}),t.jsxs("div",{className:"flex gap-2",children:[h.showUseLocal&&o&&t.jsxs(U,{variant:"outline",onClick:o,disabled:i,className:"flex-1",children:[t.jsx(T,{name:"macbook",className:"h-4 w-4"}),s(h.useLocalLabelKey)]}),h.showUseRemote&&f&&t.jsxs(U,{variant:"outline",onClick:f,disabled:i,className:"flex-1",children:[t.jsx(T,{name:"server",className:"h-4 w-4"}),s(h.useRemoteLabelKey)]})]})]})]})})}function ne(r,e){if(e==="use-remote")return{kind:"remote-form"};switch(r){case"local-unavailable":return{kind:"local-setup"};case"remote-unreachable":case"remote-incompatible":case"remote-wrong-service":case"remote-missing":case"missing-default-host":return{kind:"switch-default-to-local"};default:{const c=r;throw new Error(`Unhandled RecoveryVariant: ${c}`)}}}function Re(r){const e=z.c(27),{variant:c,hostUrl:n,hostLabel:o,onRetry:f,onChooseRemote:i,showRemoteForm:s,onCloseRemoteForm:h,onSwitchToLocalFromRemote:y,onEnterLocalSetup:x,isRetrying:S}=r,N=s===void 0?!1:s,b=S===void 0?!1:S,m=Se;let v;e[0]!==f?(v=async()=>{if(M()){await B();return}await O("/api/config/reload",{method:"POST"}),f?.()},e[0]=f,e[1]=v):v=e[1];const R=v;let C;e[2]!==x||e[3]!==c?(C=async()=>{if(ne(c,"use-local").kind==="local-setup"){x?.();return}if(await m("local"),M()){await B();return}window.location.reload()},e[2]=x,e[3]=c,e[4]=C):C=e[4];const j=C;let p;e[5]!==i||e[6]!==c?(p=()=>{ne(c,"use-remote").kind==="remote-form"&&i?.()},e[5]=i,e[6]=c,e[7]=p):p=e[7];const w=p;if(N){const k=c==="remote-wrong-service"?"":n||"",K=c==="remote-wrong-service"?"":o||"";let L;e[8]!==i||e[9]!==h?(L=h||(()=>i?.()),e[8]=i,e[9]=h,e[10]=L):L=e[10];let A;e[11]!==x||e[12]!==y?(A=y||(()=>{m("local").then(()=>{M()?B():x?.()})}),e[11]=x,e[12]=y,e[13]=A):A=e[13];let _;return e[14]!==K||e[15]!==k||e[16]!==L||e[17]!==A?(_=t.jsx(ie,{onBack:L,initialUrl:k,initialLabel:K,isRecoveryMode:!0,onSwitchToLocal:A}),e[14]=K,e[15]=k,e[16]=L,e[17]=A,e[18]=_):_=e[18],_}let g;return e[19]!==R||e[20]!==j||e[21]!==w||e[22]!==o||e[23]!==n||e[24]!==b||e[25]!==c?(g=t.jsx(Ne,{variant:c,hostLabel:o,hostUrl:n,onRetry:R,onUseLocal:j,onUseRemote:w,isRetrying:b}),e[19]=R,e[20]=j,e[21]=w,e[22]=o,e[23]=n,e[24]=b,e[25]=c,e[26]=g):g=e[26],g}async function Se(r){if(!M())return;const e=await Z();await ee({...e,...r==="local"?{defaultHostId:"local"}:{},initialHostChoiceCompleted:!0})}function Ke(r){const e=z.c(26),{onBack:c,onCliAvailable:n,mode:o,recoveryVariant:f,recoveryHostUrl:i,recoveryHostLabel:s,onEnterLocalSetup:h}=r,y=o===void 0?"first-launch":o,x=f===void 0?"missing-default-host":f,[S,N]=a.useState(!1),[b,m]=a.useState(!1);let v;e[0]===Symbol.for("react.memo_cache_sentinel")?(v=()=>{m(!1),N(!1)},e[0]=v):v=e[0];let R;e[1]!==y||e[2]!==s||e[3]!==i||e[4]!==x?(R=[y,x,i,s],e[1]=y,e[2]=s,e[3]=i,e[4]=x,e[5]=R):R=e[5],a.useEffect(v,R);const C=b?"local-setup":y;if(C==="recovery"){let p,w;e[6]===Symbol.for("react.memo_cache_sentinel")?(p=()=>N(!1),w=()=>{N(!1),m(!0)},e[6]=p,e[7]=w):(p=e[6],w=e[7]);let g;e[8]!==h?(g=()=>{m(!0),h?.()},e[8]=h,e[9]=g):g=e[9];let k;return e[10]!==s||e[11]!==i||e[12]!==x||e[13]!==S||e[14]!==g?(k=t.jsx(Re,{variant:x,hostUrl:i,hostLabel:s,showRemoteForm:S,onCloseRemoteForm:p,onSwitchToLocalFromRemote:w,onEnterLocalSetup:g}),e[10]=s,e[11]=i,e[12]=x,e[13]=S,e[14]=g,e[15]=k):k=e[15],k}if(C==="local-setup"){let p;e[16]!==c||e[17]!==b?(p=()=>{b?m(!1):c?.()},e[16]=c,e[17]=b,e[18]=p):p=e[18];let w;e[19]===Symbol.for("react.memo_cache_sentinel")?(w=()=>N(!0),e[19]=w):w=e[19];let g;return e[20]!==n||e[21]!==b||e[22]!==p?(g=t.jsx(je,{onBack:p,onCliAvailable:n,isFromRecovery:b,onSwitchToRemote:w}),e[20]=n,e[21]=b,e[22]=p,e[23]=g):g=e[23],g}let j;return e[24]!==n?(j=t.jsx(xe,{onCliAvailable:n}),e[24]=n,e[25]=j):j=e[25],j}export{Ke as OnboardingScreen};
|