xedoc-cli 0.1.17 → 0.1.20

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.
@@ -0,0 +1 @@
1
+ import{F as e,M as t,R as s,c as a,j as n,k as r,s as i,t as o}from"./jsx-runtime-BD6xVgfN.js";import{Ht as l,Wt as c,Xt as d,_n as u,an as m,cn as h,dn as x}from"./usePositioner-DoPOYGgd.js";import{At as p,B as g,Ct as f,Dt as b,E as j,Et as v,G as y,H as N,J as w,K as k,L as C,Mt as S,Nt as A,O as E,Ot as P,P as T,St as z,T as M,Tt as I,U,V as O,W as R,Z as F,bt as L,d as q,f as D,ft as $,g as H,gt as K,ht as _,jt as Q,kt as G,nt as V,p as B,pt as W,q as J,tt as Z,vt as X,wt as Y,xt as ee}from"./popover-DTbjnDSA.js";import{c as te,i as se,n as ae,o as ne,r as re,s as ie,u as oe}from"./document-title-CVCGo83t.js";import{D as le,H as ce,J as de,L as ue,N as me,O as he,P as xe,S as pe,T as ge,U as fe,Ut as be,V as je,Wt as ve,a as ye,i as Ne,j as we,k as ke,l as Ce,o as Se,p as Ae,r as Ee,s as Pe,u as Te,w as ze,z as Me}from"./api-Bq1vju8d.js";import{A as Ie,C as Ue,E as Oe,O as Re,S as Fe,T as Le,_ as qe,a as De,b as $e,c as He,d as Ke,g as _e,h as Qe,k as Ge,l as Ve,m as Be,n as We,o as Je,p as Ze,r as Xe,s as Ye,t as et,u as tt,v as st,w as at,x as nt,y as rt}from"./header-menu-BZ8Qg4Vi.js";import{t as it}from"./folder-open-BGVSSdnS.js";import{n as ot,t as lt}from"./label-PRFnRUMj.js";import{n as ct}from"./session-provider-Bxa1AL3n.js";import{c as dt,l as ut,t as mt}from"./input-DmJ6N0Sh.js";function ht(e,t){const s=new Set(t);return e.filter(e=>!s.has(e))}var xt=class extends u{#e;#t;#s;#a;#n;#r;#i;#o;#l;#c=[];constructor(e,t,s){super(),this.#e=e,this.#a=s,this.#s=[],this.#n=[],this.#t=[],this.setQueries(t)}onSubscribe(){1===this.listeners.size&&this.#n.forEach(e=>{e.subscribe(t=>{this.#d(e,t)})})}onUnsubscribe(){this.listeners.size||this.destroy()}destroy(){this.listeners=new Set,this.#n.forEach(e=>{e.destroy()})}setQueries(e,t){this.#s=e,this.#a=t,d.batch(()=>{const e=this.#n,t=this.#u(this.#s);t.forEach(e=>e.observer.setOptions(e.defaultedQueryOptions));const s=t.map(e=>e.observer),a=s.map(e=>e.getCurrentResult()),n=e.length!==s.length,r=s.some((t,s)=>t!==e[s]),i=n||r,o=!!i||a.some((e,t)=>{const s=this.#t[t];return!s||!x(e,s)});(i||o)&&(i&&(this.#c=t,this.#n=s),this.#t=a,this.hasListeners()&&(i&&(ht(e,s).forEach(e=>{e.destroy()}),ht(s,e).forEach(e=>{e.subscribe(t=>{this.#d(e,t)})})),this.#m()))})}getCurrentResult(){return this.#t}getQueries(){return this.#n.map(e=>e.getCurrentQuery())}getObservers(){return this.#n}getOptimisticResult(e,t){const s=this.#u(e),a=s.map(e=>e.observer.getOptimisticResult(e.defaultedQueryOptions)),n=s.map(e=>e.defaultedQueryOptions.queryHash);return[a,e=>this.#h(e??a,t,n),()=>this.#x(a,s)]}#x(e,t){return t.map((s,a)=>{const n=e[a];return s.defaultedQueryOptions.notifyOnChangeProps?n:s.observer.trackResult(n,e=>{t.forEach(t=>{t.observer.trackProp(e)})})})}#h(e,t,s){if(t){const a=this.#l,n=void 0!==s&&void 0!==a&&(a.length!==s.length||s.some((e,t)=>e!==a[t]));return this.#r&&this.#t===this.#o&&!n&&t===this.#i||(this.#i=t,this.#o=this.#t,void 0!==s&&(this.#l=s),this.#r=h(this.#r,t(e))),this.#r}return e}#p(){return void 0!==this.#a?.combine&&this.#n.some((e,t)=>e.options.suspense&&void 0===this.#t[t]?.data)}#u(e){const t=new Map;this.#n.forEach(e=>{const s=e.options.queryHash;if(!s)return;const a=t.get(s);a?a.push(e):t.set(s,[e])});const s=[];return e.forEach(e=>{const a=this.#e.defaultQueryOptions(e),n=t.get(a.queryHash)?.shift()??new A(this.#e,a);s.push({defaultedQueryOptions:a,observer:n})}),s}#d(e,t){const s=this.#n.indexOf(e);-1!==s&&(this.#t=function(e,t,s){const a=e.slice(0);return a[t]=s,a}(this.#t,s,t),this.#m())}#m(){if(this.hasListeners()){const e=this.#x(this.#t,this.#c),t=this.#p(),s=this.#r,a=t?s:this.#h(e,this.#a?.combine);(t||s!==a)&&d.batch(()=>{this.listeners.forEach(e=>{e(this.#t)})})}}},pt=s(e(),1);var gt=ve("archive",[["rect",{width:"20",height:"5",x:"2",y:"3",rx:"1",key:"1wp1u1"}],["path",{d:"M4 8v11a2 2 0 0 0 2 2h12a2 2 0 0 0 2-2V8",key:"1s80jp"}],["path",{d:"M10 12h4",key:"a56b0p"}]]),ft=ve("circle-alert",[["circle",{cx:"12",cy:"12",r:"10",key:"1mglay"}],["line",{x1:"12",x2:"12",y1:"8",y2:"12",key:"1pkeuh"}],["line",{x1:"12",x2:"12.01",y1:"16",y2:"16",key:"4dfq90"}]]),bt=ve("copy",[["rect",{width:"14",height:"14",x:"8",y:"8",rx:"2",ry:"2",key:"17jyea"}],["path",{d:"M4 16c-1.1 0-2-.9-2-2V4c0-1.1.9-2 2-2h10c1.1 0 2 .9 2 2",key:"zix9uf"}]]),jt=ve("ellipsis-vertical",[["circle",{cx:"12",cy:"12",r:"1",key:"41hilf"}],["circle",{cx:"12",cy:"5",r:"1",key:"gxeob9"}],["circle",{cx:"12",cy:"19",r:"1",key:"lyex9k"}]]),vt=ve("ellipsis",[["circle",{cx:"12",cy:"12",r:"1",key:"41hilf"}],["circle",{cx:"19",cy:"12",r:"1",key:"1wjl8i"}],["circle",{cx:"5",cy:"12",r:"1",key:"1pcz8c"}]]),yt=ve("external-link",[["path",{d:"M15 3h6v6",key:"1q9fwt"}],["path",{d:"M10 14 21 3",key:"gplh6r"}],["path",{d:"M18 13v6a2 2 0 0 1-2 2H5a2 2 0 0 1-2-2V8a2 2 0 0 1 2-2h6",key:"a6xqqp"}]]),Nt=ve("eye-off",[["path",{d:"M10.733 5.076a10.744 10.744 0 0 1 11.205 6.575 1 1 0 0 1 0 .696 10.747 10.747 0 0 1-1.444 2.49",key:"ct8e1f"}],["path",{d:"M14.084 14.158a3 3 0 0 1-4.242-4.242",key:"151rxh"}],["path",{d:"M17.479 17.499a10.75 10.75 0 0 1-15.417-5.151 1 1 0 0 1 0-.696 10.75 10.75 0 0 1 4.446-5.143",key:"13bj9a"}],["path",{d:"m2 2 20 20",key:"1ooewy"}]]),wt=ve("folder-plus",[["path",{d:"M12 10v6",key:"1bos4e"}],["path",{d:"M9 13h6",key:"1uhe8q"}],["path",{d:"M20 20a2 2 0 0 0 2-2V8a2 2 0 0 0-2-2h-7.9a2 2 0 0 1-1.69-.9L9.6 3.9A2 2 0 0 0 7.93 3H4a2 2 0 0 0-2 2v13a2 2 0 0 0 2 2Z",key:"1kt360"}]]),kt=ve("folder",[["path",{d:"M20 20a2 2 0 0 0 2-2V8a2 2 0 0 0-2-2h-7.9a2 2 0 0 1-1.69-.9L9.6 3.9A2 2 0 0 0 7.93 3H4a2 2 0 0 0-2 2v13a2 2 0 0 0 2 2Z",key:"1kt360"}]]),Ct=ve("house",[["path",{d:"M15 21v-8a1 1 0 0 0-1-1h-4a1 1 0 0 0-1 1v8",key:"5wwlr5"}],["path",{d:"M3 10a2 2 0 0 1 .709-1.528l7-6a2 2 0 0 1 2.582 0l7 6A2 2 0 0 1 21 10v9a2 2 0 0 1-2 2H5a2 2 0 0 1-2-2z",key:"r6nss1"}]]),St=ve("import",[["path",{d:"M12 3v12",key:"1x0j5s"}],["path",{d:"m8 11 4 4 4-4",key:"1dohi6"}],["path",{d:"M8 5H4a2 2 0 0 0-2 2v10a2 2 0 0 0 2 2h16a2 2 0 0 0 2-2V7a2 2 0 0 0-2-2h-4",key:"1ywtjm"}]]),At=ve("laptop",[["path",{d:"M18 5a2 2 0 0 1 2 2v8.526a2 2 0 0 0 .212.897l1.068 2.127a1 1 0 0 1-.9 1.45H3.62a1 1 0 0 1-.9-1.45l1.068-2.127A2 2 0 0 0 4 15.526V7a2 2 0 0 1 2-2z",key:"1pdavp"}],["path",{d:"M20.054 15.987H3.946",key:"14rxg9"}]]),Et=ve("mail",[["path",{d:"m22 7-8.991 5.727a2 2 0 0 1-2.009 0L2 7",key:"132q7q"}],["rect",{x:"2",y:"4",width:"20",height:"16",rx:"2",key:"izxlao"}]]),Pt=ve("menu",[["path",{d:"M4 5h16",key:"1tepv9"}],["path",{d:"M4 12h16",key:"1lakjw"}],["path",{d:"M4 19h16",key:"1djgab"}]]),Tt=ve("message-square",[["path",{d:"M22 17a2 2 0 0 1-2 2H6.828a2 2 0 0 0-1.414.586l-2.202 2.202A.71.71 0 0 1 2 21.286V5a2 2 0 0 1 2-2h16a2 2 0 0 1 2 2z",key:"18887p"}]]),zt=ve("moon",[["path",{d:"M20.985 12.486a9 9 0 1 1-9.473-9.472c.405-.022.617.46.402.803a6 6 0 0 0 8.268 8.268c.344-.215.825-.004.803.401",key:"kfwtm"}]]),Mt=ve("panel-left",[["rect",{width:"18",height:"18",x:"3",y:"3",rx:"2",key:"afitv7"}],["path",{d:"M9 3v18",key:"fh3hqa"}]]),It=ve("pencil",[["path",{d:"M21.174 6.812a1 1 0 0 0-3.986-3.987L3.842 16.174a2 2 0 0 0-.5.83l-1.321 4.352a.5.5 0 0 0 .623.622l4.353-1.32a2 2 0 0 0 .83-.497z",key:"1a8usu"}],["path",{d:"m15 5 4 4",key:"1mk7zo"}]]),Ut=ve("power-off",[["path",{d:"M18.36 6.64A9 9 0 0 1 20.77 15",key:"dxknvb"}],["path",{d:"M6.16 6.16a9 9 0 1 0 12.68 12.68",key:"1x7qb5"}],["path",{d:"M12 2v4",key:"3427ic"}],["path",{d:"m2 2 20 20",key:"1ooewy"}]]),Ot=ve("rotate-cw",[["path",{d:"M21 12a9 9 0 1 1-9-9c2.52 0 4.93 1 6.74 2.74L21 8",key:"1p45f6"}],["path",{d:"M21 3v5h-5",key:"1q7to0"}]]),Rt=ve("save",[["path",{d:"M15.2 3a2 2 0 0 1 1.4.6l3.8 3.8a2 2 0 0 1 .6 1.4V19a2 2 0 0 1-2 2H5a2 2 0 0 1-2-2V5a2 2 0 0 1 2-2z",key:"1c8476"}],["path",{d:"M17 21v-7a1 1 0 0 0-1-1H8a1 1 0 0 0-1 1v7",key:"1ydtos"}],["path",{d:"M7 3v4a1 1 0 0 0 1 1h7",key:"t51u73"}]]),Ft=ve("search",[["path",{d:"m21 21-4.34-4.34",key:"14j7rj"}],["circle",{cx:"11",cy:"11",r:"8",key:"4ej97u"}]]),Lt=ve("settings",[["path",{d:"M9.671 4.136a2.34 2.34 0 0 1 4.659 0 2.34 2.34 0 0 0 3.319 1.915 2.34 2.34 0 0 1 2.33 4.033 2.34 2.34 0 0 0 0 3.831 2.34 2.34 0 0 1-2.33 4.033 2.34 2.34 0 0 0-3.319 1.915 2.34 2.34 0 0 1-4.659 0 2.34 2.34 0 0 0-3.32-1.915 2.34 2.34 0 0 1-2.33-4.033 2.34 2.34 0 0 0 0-3.831A2.34 2.34 0 0 1 6.35 6.051a2.34 2.34 0 0 0 3.319-1.915",key:"1i5ecw"}],["circle",{cx:"12",cy:"12",r:"3",key:"1v7zrd"}]]),qt=ve("sun",[["circle",{cx:"12",cy:"12",r:"4",key:"4exip2"}],["path",{d:"M12 2v2",key:"tus03m"}],["path",{d:"M12 20v2",key:"1lh1kg"}],["path",{d:"m4.93 4.93 1.41 1.41",key:"149t6j"}],["path",{d:"m17.66 17.66 1.41 1.41",key:"ptbguv"}],["path",{d:"M2 12h2",key:"1t8f8n"}],["path",{d:"M20 12h2",key:"1q8mjw"}],["path",{d:"m6.34 17.66-1.41 1.41",key:"1m8zz5"}],["path",{d:"m19.07 4.93-1.41 1.41",key:"1shlcs"}]]),Dt=ve("trash-2",[["path",{d:"M10 11v6",key:"nco0om"}],["path",{d:"M14 11v6",key:"outv1u"}],["path",{d:"M19 6v14a2 2 0 0 1-2 2H7a2 2 0 0 1-2-2V6",key:"miytrc"}],["path",{d:"M3 6h18",key:"d0wm0j"}],["path",{d:"M8 6V4a2 2 0 0 1 2-2h4a2 2 0 0 1 2 2v2",key:"e791ji"}]]),$t=o();function Ht(e){const{children:t,open:s,defaultOpen:a=!1,onOpenChange:n,onOpenChangeComplete:r,actionsRef:i,handle:o,triggerId:l,defaultTriggerId:c=null}=e,d=Ue(!0),u=Boolean(d),m=nt.useStore(o?.store,{open:a,openProp:s,activeTriggerId:c,triggerIdProp:l,modal:!0,disablePointerDismissal:!0,nested:u,role:"alertdialog"});m.useControlledProp("openProp",s),m.useControlledProp("triggerIdProp",l),m.useSyncedValue("nested",u),m.useContextCallback("onOpenChange",n),m.useContextCallback("onOpenChangeComplete",r);const h=m.useState("payload");at({store:m,actionsRef:i,parentContext:d?.store.context,isDrawer:!1,onOpenChange:n,triggerIdProp:l});const x=pt.useMemo(()=>({store:m}),[m]);return(0,$t.jsx)($e.Provider,{value:!1,children:(0,$t.jsx)(Fe.Provider,{value:x,children:"function"==typeof t?t({payload:h}):t})})}function Kt({...e}){return(0,$t.jsx)(Ht,{"data-slot":"alert-dialog",...e})}function _t({...e}){return(0,$t.jsx)(Be,{"data-slot":"alert-dialog-portal",...e})}function Qt({className:e,...t}){return(0,$t.jsx)(st,{"data-slot":"alert-dialog-overlay",className:fe("fixed inset-0 isolate z-50 bg-black/10 duration-100 supports-backdrop-filter:backdrop-blur-xs data-open:animate-in data-open:fade-in-0 data-closed:animate-out data-closed:fade-out-0",e),...t})}function Gt({className:e,size:t="default",...s}){return(0,$t.jsxs)(_t,{children:[(0,$t.jsx)(Qt,{}),(0,$t.jsx)(Qe,{"data-slot":"alert-dialog-content","data-size":t,className:fe("group/alert-dialog-content fixed top-1/2 left-1/2 z-50 grid w-full -translate-x-1/2 -translate-y-1/2 gap-4 rounded-xl bg-popover p-4 text-popover-foreground ring-1 ring-foreground/10 duration-100 outline-none data-[size=default]:max-w-xs data-[size=sm]:max-w-xs data-[size=default]:sm:max-w-sm data-open:animate-in data-open:fade-in-0 data-open:zoom-in-95 data-closed:animate-out data-closed:fade-out-0 data-closed:zoom-out-95",e),...s})]})}function Vt({className:e,...t}){return(0,$t.jsx)("div",{"data-slot":"alert-dialog-header",className:fe("grid grid-rows-[auto_1fr] place-items-center gap-1.5 text-center has-data-[slot=alert-dialog-media]:grid-rows-[auto_auto_1fr] has-data-[slot=alert-dialog-media]:gap-x-4 sm:group-data-[size=default]/alert-dialog-content:place-items-start sm:group-data-[size=default]/alert-dialog-content:text-left sm:group-data-[size=default]/alert-dialog-content:has-data-[slot=alert-dialog-media]:grid-rows-[auto_1fr]",e),...t})}function Bt({className:e,...t}){return(0,$t.jsx)("div",{"data-slot":"alert-dialog-footer",className:fe("-mx-4 -mb-4 flex flex-col-reverse gap-2 rounded-b-xl border-t bg-muted/50 p-4 group-data-[size=sm]/alert-dialog-content:grid group-data-[size=sm]/alert-dialog-content:grid-cols-2 sm:flex-row sm:justify-end",e),...t})}function Wt({className:e,...t}){return(0,$t.jsx)(Ze,{"data-slot":"alert-dialog-title",className:fe("font-heading text-base font-medium sm:group-data-[size=default]/alert-dialog-content:group-has-data-[slot=alert-dialog-media]/alert-dialog-content:col-start-2",e),...t})}function Jt({className:e,...t}){return(0,$t.jsx)(_e,{"data-slot":"alert-dialog-description",className:fe("text-sm text-balance text-muted-foreground md:text-pretty *:[a]:underline *:[a]:underline-offset-3 *:[a]:hover:text-foreground",e),...t})}function Zt({className:e,...t}){return(0,$t.jsx)(dt,{"data-slot":"alert-dialog-action",className:fe(e),...t})}function Xt({className:e,variant:t="outline",size:s="default",...a}){return(0,$t.jsx)(qe,{"data-slot":"alert-dialog-cancel",className:fe(e),render:(0,$t.jsx)(dt,{variant:t,size:s}),...a})}function Yt({callbackUrl:e,cancelPending:t,completePending:s,state:a,onCallbackUrlChange:n,onCancelAuthentication:r,onClose:i,onComplete:o,onCopyDeviceCode:l,onReopen:c}){const d="device"===a?.mode,u="CONNECTED"===a?.status;return(0,$t.jsx)(Je,{open:!!a,onOpenChange:e=>{e||i()},children:(0,$t.jsxs)(Ye,{className:"max-w-2xl",children:[(0,$t.jsxs)(tt,{children:[(0,$t.jsx)(Ke,{children:d?"Device authentication":"Normal authentication"}),(0,$t.jsx)(He,{children:a?.accountName??"Codex account"})]}),(0,$t.jsxs)("div",{className:"grid gap-4",children:[(0,$t.jsx)("div",{className:fe("rounded-md border px-3 py-2 text-sm",u?"border-emerald-300 bg-emerald-50 text-emerald-800 dark:border-emerald-900/70 dark:bg-emerald-950/35 dark:text-emerald-200":"bg-muted/35 text-muted-foreground"),children:u?"Codex reported this account as connected. xedoc will use the email from the authenticated account as its name.":d?"Open the verification link, enter the device code, then use the response URL field if Codex does not finish automatically.":"Complete the browser login. If the browser lands on a localhost callback page, paste that full URL below."}),a?.authUrl?(0,$t.jsxs)("div",{className:"grid gap-2",children:[(0,$t.jsx)(lt,{htmlFor:"account-auth-url",children:d?"Verification link":"Authentication link"}),(0,$t.jsxs)("div",{className:"grid gap-2 sm:grid-cols-[minmax(0,1fr)_auto]",children:[(0,$t.jsx)(mt,{className:"font-mono text-xs",id:"account-auth-url",readOnly:!0,value:a.authUrl}),(0,$t.jsxs)(dt,{variant:"outline",onClick:c,children:[(0,$t.jsx)(yt,{}),"Reopen"]})]})]}):null,d&&a?.userCode?(0,$t.jsxs)("div",{className:"grid gap-2",children:[(0,$t.jsx)(lt,{htmlFor:"account-device-code",children:"Device code"}),(0,$t.jsxs)("div",{className:"grid gap-2 sm:grid-cols-[minmax(0,1fr)_auto]",children:[(0,$t.jsx)(mt,{className:"font-mono text-sm tracking-wider",id:"account-device-code",readOnly:!0,value:a.userCode}),(0,$t.jsxs)(dt,{variant:"outline",onClick:l,children:[(0,$t.jsx)(bt,{}),"Copy"]})]})]}):null,(0,$t.jsxs)("div",{className:"grid gap-2",children:[(0,$t.jsx)(lt,{htmlFor:"account-callback-url",children:"Response URL"}),(0,$t.jsx)(y,{className:"min-h-24 font-mono text-xs",id:"account-callback-url",placeholder:"http://localhost:1455/auth/callback?code=...",value:e,onChange:e=>n(e.target.value)}),(0,$t.jsx)("p",{className:"text-xs text-muted-foreground",children:"Paste the complete localhost callback URL from the Codex browser tab when automatic completion is blocked."})]}),a?.message?(0,$t.jsx)("p",{className:"rounded-md border bg-background px-3 py-2 text-sm text-muted-foreground",children:a.message}):null]}),(0,$t.jsxs)(Ve,{children:[(0,$t.jsxs)(dt,{variant:"outline",onClick:i,children:[(0,$t.jsx)($,{}),"Close"]}),"AUTHENTICATING"===a?.status?(0,$t.jsxs)(dt,{disabled:!a.accountId||t,variant:"destructive",onClick:r,children:[t?(0,$t.jsx)(be,{className:"animate-spin"}):(0,$t.jsx)($,{}),"Cancel Auth"]}):null,(0,$t.jsxs)(dt,{disabled:!a?.authUrl,variant:"secondary",onClick:c,children:[(0,$t.jsx)(yt,{}),"Reopen Link"]}),(0,$t.jsxs)(dt,{disabled:!a?.accountId||!e.trim()||s,onClick:o,children:[s?(0,$t.jsx)(be,{className:"animate-spin"}):(0,$t.jsx)(te,{}),"Submit Response URL"]})]})]})})}function es(e){return"browser"===e||"device"===e?e:null}function ts(e,t){return{accountId:e?.id??"",accountName:e?.displayName??"Codex account",authUrl:e?.lastAuthUrl??null,message:"AUTHENTICATING"===e?.status?"Authentication is in progress.":"Starting Codex authentication.",mode:t,status:e?.status??"AUTHENTICATING",userCode:e?.lastAuthUserCode??null}}function ss({account:e,authPending:t,authPendingMode:s,cancelPending:a,localActivePending:n,quotaLabel:r,quotaPending:i,quotaSnapshot:o,onAuthenticate:l,onCancelAuthentication:c,onDelete:d,onEdit:u,onSetLocalActive:m,onShowAuthentication:h}){const x=es(e.lastAuthMode)??"browser",p=t&&"browser"===s,g=t&&"device"===s,f="AUTHENTICATING"===e.status?x:"browser",b="AUTHENTICATING"===e.status?"Check":"CONNECTED"===e.status?"Re-authenticate":"Authenticate",j="CONNECTED"===e.status&&!e.isLocalCodexActive,v="device"===x?"Device login pending":"Browser login pending";return(0,$t.jsx)("div",{className:fe("rounded-md border bg-background px-3 py-3 text-sm",e.isLocalCodexActive&&"border-primary/40 bg-primary/5 dark:bg-primary/10"),children:(0,$t.jsxs)("div",{className:"grid gap-3",children:[(0,$t.jsxs)("div",{className:"flex min-w-0 items-start justify-between gap-3",children:[(0,$t.jsxs)("div",{className:"grid min-w-0 gap-1.5",children:[(0,$t.jsxs)("div",{className:"flex min-w-0 flex-wrap items-center gap-2",children:[(0,$t.jsx)("div",{className:"min-w-0 max-w-full truncate font-medium",children:e.displayName}),(0,$t.jsx)(as,{planType:o?.planType}),e.isLocalCodexActive?(0,$t.jsx)(ns,{}):null]}),(0,$t.jsx)("div",{className:"truncate text-xs text-muted-foreground",children:os(e)})]}),(0,$t.jsxs)("div",{className:"flex shrink-0 items-center gap-2",children:[(0,$t.jsx)(rs,{account:e}),(0,$t.jsxs)(k,{children:[(0,$t.jsxs)(Z,{render:(0,$t.jsx)(dt,{size:"icon-sm",variant:"ghost"}),children:[t||a||n?(0,$t.jsx)(be,{className:"animate-spin"}):(0,$t.jsx)(jt,{}),(0,$t.jsx)("span",{className:"sr-only",children:"Account actions"})]}),(0,$t.jsxs)(J,{align:"end",className:"w-48",children:[(0,$t.jsxs)(w,{disabled:t,onClick:()=>l(f),children:[p?(0,$t.jsx)(be,{className:"animate-spin"}):"AUTHENTICATING"===e.status?(0,$t.jsx)(Ot,{}):(0,$t.jsx)(yt,{}),"AUTHENTICATING"===e.status?b:"Normal Auth"]}),(0,$t.jsxs)(w,{disabled:t,onClick:()=>l("device"),children:[g?(0,$t.jsx)(be,{className:"animate-spin"}):(0,$t.jsx)(ot,{}),"Device Auth"]}),(0,$t.jsxs)(w,{disabled:!j||n,onClick:m,children:[n?(0,$t.jsx)(be,{className:"animate-spin"}):(0,$t.jsx)(At,{}),e.isLocalCodexActive?"Local Active":"Make Local Active"]}),"AUTHENTICATING"===e.status?(0,$t.jsxs)(w,{disabled:a,variant:"destructive",onClick:c,children:[a?(0,$t.jsx)(be,{className:"animate-spin"}):(0,$t.jsx)($,{}),"Cancel Auth"]}):null,"AUTHENTICATING"===e.status||e.lastAuthUrl?(0,$t.jsxs)(w,{onClick:h,children:[(0,$t.jsx)(yt,{}),"Authentication Details"]}):null,(0,$t.jsx)(F,{}),(0,$t.jsxs)(w,{onClick:u,children:[(0,$t.jsx)(It,{}),"Edit"]}),(0,$t.jsxs)(w,{variant:"destructive",onClick:d,children:[(0,$t.jsx)(Dt,{}),"Delete"]})]})]})]})]}),(0,$t.jsxs)("div",{className:"grid gap-2 sm:grid-cols-[minmax(0,1fr)_auto] sm:items-end",children:[(0,$t.jsxs)("div",{className:"grid min-w-0 gap-1.5",children:[(0,$t.jsx)(is,{accountStatus:e.status,label:r,pending:i,snapshot:o}),"AUTHENTICATING"===e.status?(0,$t.jsx)("span",{className:"text-xs text-muted-foreground",children:v}):null]}),"AUTHENTICATING"===e.status?(0,$t.jsxs)(dt,{className:"min-w-0 sm:w-auto",disabled:a,size:"sm",variant:"destructive",onClick:c,children:[a?(0,$t.jsx)(be,{className:"animate-spin"}):(0,$t.jsx)($,{}),"Cancel"]}):null]})]})})}function as({planType:e}){return e?(0,$t.jsx)(U,{className:"border-emerald-300 bg-emerald-50 text-emerald-700 dark:border-emerald-900/70 dark:bg-emerald-950/35 dark:text-emerald-300",variant:"outline",children:(t=e,t.split("_").filter(Boolean).map(e=>e.slice(0,1).toUpperCase()+e.slice(1)).join(" "))}):null;var t}function ns(){return(0,$t.jsxs)(U,{className:"border-sky-300 bg-sky-50 text-sky-700 dark:border-sky-900/70 dark:bg-sky-950/35 dark:text-sky-300",variant:"outline",children:[(0,$t.jsx)(At,{}),"local active"]})}function rs({account:e}){const t=e.lastError?.trim();return t?(0,$t.jsxs)(re,{children:[(0,$t.jsx)(ne,{render:(0,$t.jsx)("span",{className:"inline-flex cursor-help"}),children:(0,$t.jsx)(De,{status:e.status})}),(0,$t.jsx)(se,{align:"start",className:"max-w-96 whitespace-pre-wrap break-words text-left leading-relaxed",side:"right",children:t})]}):(0,$t.jsx)(De,{status:e.status})}function is({accountStatus:e,label:t,pending:s,snapshot:a}){if("CONNECTED"!==e)return(0,$t.jsx)("div",{className:"text-xs text-muted-foreground",children:"INVALIDATED"===e?"Re-authenticate account to load quota.":"Connect account to load quota."});const n=t??O(a),r=N(a);return(0,$t.jsx)("div",{className:"grid gap-1.5",children:(0,$t.jsxs)("div",{className:fe("inline-flex w-fit items-center gap-1.5 rounded-md border px-2 py-1 text-xs","fiveHour"===r&&"border-orange-300 bg-orange-50 text-orange-700 dark:border-orange-900/70 dark:bg-orange-950/35 dark:text-orange-300","weekly"===r&&"border-red-300 bg-red-50 text-red-700 dark:border-red-900/70 dark:bg-red-950/35 dark:text-red-300"),children:[s?(0,$t.jsx)(be,{className:"size-3 animate-spin"}):null,(0,$t.jsx)("span",{children:n})]})})}function os(e){return[e.command,...e.args??[]].filter(Boolean).join(" ")}var ls={args:"",command:"",displayName:"",environment:""};function cs({accounts:e,accountRateLimitFetching:t,accountRateLimitSnapshots:s,accountUsageSummaries:a,createFocusKey:n=0,session:r}){const[i,o]=(0,pt.useState)(!1),[d,u]=(0,pt.useState)(null),[m,h]=(0,pt.useState)(""),[x,p]=(0,pt.useState)(""),[g,b]=(0,pt.useState)(null),[j,v]=(0,pt.useState)(ls),[y,N]=(0,pt.useState)(null),C=(0,pt.useRef)(null),S=(0,pt.useRef)(null),A=c(),E=(0,pt.useMemo)(()=>["login-callback-port",r.serverUrl],[r.serverUrl]),P=Y({queryKey:E,queryFn:()=>xe(r),refetchInterval:e=>e.state.data?.inUse?5e3:15e3,retry:1,staleTime:3e3});(0,pt.useEffect)(()=>{if(n<=0)return;const e=window.setTimeout(()=>{o(!0)},80);return()=>window.clearTimeout(e)},[n]),(0,pt.useEffect)(()=>{u(t=>{if(!t?.accountId)return t;const s=e.find(e=>e.id===t.accountId);if(!s)return t;const a=es(s.lastAuthMode)??t.mode,n="AUTHENTICATING"===s.status?s.lastAuthUrl??t.authUrl:s.lastAuthUrl,r="AUTHENTICATING"===s.status?s.lastAuthUserCode??t.userCode:s.lastAuthUserCode,i={...t,accountName:s.displayName,authUrl:n??null,mode:a,status:s.status,userCode:r??null};return l=i,(o=t).accountId===l.accountId&&o.accountName===l.accountName&&o.authUrl===l.authUrl&&o.message===l.message&&o.mode===l.mode&&o.status===l.status&&o.userCode===l.userCode?t:i;var o,l})},[e]),(0,pt.useEffect)(()=>{d?.accountId&&"CONNECTED"!==d.status&&"CONNECTED"===e.find(e=>e.id===d.accountId)?.status&&(X(),u(null),h(""),l.success("Account connected."))},[e,d?.accountId,d?.status]);const T=()=>A.invalidateQueries({queryKey:["accounts"]}),z=(0,pt.useMemo)(()=>function(e,t){const s=t.trim().toLocaleLowerCase();return s?e.filter(e=>[e.displayName,e.status,e.command,e.args.join(" "),e.defaultModel,e.defaultPermissionMode,e.defaultReasoningEffort,e.defaultServiceTier,e.lastError,e.environment?JSON.stringify(e.environment):null].filter(Boolean).some(e=>String(e).toLocaleLowerCase().includes(s))):e}(e,x),[e,x]),M=(0,pt.useMemo)(()=>e.some(e=>"AUTHENTICATING"===e.status&&"device"!==es(e.lastAuthMode)),[e]),I=f({mutationFn:async e=>{const t=await Pe(r,{});return{account:t,auth:await Ne(r,t.id,{mode:e.authMode}),popup:e.popup}},onError:(e,t)=>{X(t?.popup??null),u(t=>t?{...t,message:ps(e),status:"ERROR"}:t),l.error(ps(e))},onSuccess:({account:e,auth:t,popup:s})=>{T(),W(t,s,e)}}),U=f({mutationFn:()=>{if(!g)throw new Error("Select an account to edit.");return Me(r,g.id,{...ms(j),displayName:j.displayName.trim()})},onError:e=>l.error(ps(e)),onSuccess:()=>{b(null),v(ls),l.success("Account updated."),T()}}),O=f({mutationFn:({accountId:e,mode:t})=>Ne(r,e,{mode:t}),onError:(e,t)=>{X(t?.popup??null),u(t=>t?{...t,message:ps(e),status:"ERROR"}:t),l.error(ps(e))},onSuccess:(t,s)=>{T();const a=e.find(e=>e.id===s.accountId);W(t,s.popup,a)}}),R=f({mutationFn:e=>ye(r,e),onError:e=>l.error(ps(e)),onSuccess:e=>{X(),u(null),h(""),l.success(`Canceled authentication for ${e.displayName}.`),T()}}),L=f({mutationFn:({accountId:e,redirectUrl:t})=>Se(r,e,{redirectUrl:t.trim()}),onError:e=>{u(t=>t?{...t,message:ps(e),status:"ERROR"}:t),l.error(ps(e))},onSuccess:e=>{h(""),T(),W(e)}}),q=f({mutationFn:e=>Te(r,e),onError:e=>l.error(ps(e)),onSuccess:()=>{N(null),l.success("Account deleted."),T(),A.invalidateQueries({queryKey:["chats"]})}}),D=f({mutationFn:()=>Ae(r),onError:e=>l.error(ps(e)),onSuccess:e=>{!function(e){const t=new Blob([`${JSON.stringify(e,null,2)}\n`],{type:"application/json"}),s=URL.createObjectURL(t),a=window.document.createElement("a");a.href=s,a.download=`xedoc-accounts-${(new Date).toISOString().slice(0,10)}.json`,window.document.body.append(a),a.click(),a.remove(),URL.revokeObjectURL(s)}(e),l.success(`Exported ${e.accounts.length} ${xs(e.accounts.length)}. Keep the file private; it may include Codex auth tokens.`)}}),H=f({mutationFn:()=>le(r),onError:e=>l.error(ps(e)),onSuccess:e=>{A.setQueryData(E,e),e.inUse?l.warning(`${e.host}:${e.port} is still in use. The process may need more time to exit.`):l.success(function(e){const t=e.killedProcessIds??[];return t.length?`Killed ${1===t.length?"process":"processes"} ${t.join(", ")}.`:"Login callback port is available."}(e))}}),_=f({mutationFn:e=>ze(r,{accounts:e.accounts}),onError:(e,t)=>{t?.popup?.close(),l.error(ps(e))},onSuccess:(e,t)=>{l.success(`Imported ${e.imported} ${xs(e.imported)}.`),T(),A.invalidateQueries({queryKey:["chats"]}),function(e,t){const s=e.find(e=>e.authUrl);if(s){W(s,t);const a=e.filter(e=>e.authUrl&&e!==s).length;return void(a&&l.info(`${a} more ${xs(a)} need authentication.`))}t?.close();const a=e.filter(e=>"CONNECTED"===e.status).length;a&&l.success(`Connected ${a} imported ${xs(a)}.`)}(e.authentications,t.popup)}}),Q=f({mutationFn:()=>ge(r),onError:e=>l.error(ps(e)),onSuccess:e=>{l.success(`Imported ${e.imported} local ${xs(e.imported)}.`),T(),A.invalidateQueries({queryKey:["chats"]})}}),G=f({mutationFn:e=>ue(r,e),onError:e=>l.error(ps(e)),onSuccess:e=>{l.success(`${e.displayName} is now active in local Codex.`),T()}});async function V(){const e=P.data?.inUse?P.data:(await P.refetch()).data;return!e?.inUse||(l.error(`${e.host}:${e.port} is already in use. Kill the process or use Device Auth.`),!1)}async function B(e){if("browser"===e&&!(await V()))return void o(!1);const t=gs();C.current=t,o(!1),h(""),u({accountId:"",accountName:"Codex account",authUrl:null,message:"Creating account and starting Codex authentication.",mode:e,status:"AUTHENTICATING",userCode:null}),I.mutate({authMode:e,popup:t})}function W(e,t,s){if(u(function(e,t){return{accountId:e.accountId,accountName:t?.displayName??"Codex account",authUrl:e.authUrl??t?.lastAuthUrl??null,message:e.message??null,mode:e.authMode??es(t?.lastAuthMode)??"browser",status:e.status,userCode:e.userCode??t?.lastAuthUserCode??null}}(e,s)),e.authUrl)return C.current=t??C.current,fs(e.authUrl,t),void l.info("device"===e.authMode?"Device login page opened.":"Authentication page opened. xedoc is listening for the Codex callback.");X(t),"AUTHENTICATING"!==e.status?l.success(e.message??"Account is connected."):l.info(e.message??"Authentication is still in progress.")}function X(e=C.current){e&&!e.closed&&e.close(),e&&e!==C.current||(C.current=null)}return(0,$t.jsxs)($t.Fragment,{children:[(0,$t.jsx)("div",{className:"grid gap-5",children:(0,$t.jsxs)("section",{className:"grid gap-4",children:[(0,$t.jsx)("div",{className:"flex flex-wrap items-start justify-between gap-3",children:(0,$t.jsxs)("div",{children:[(0,$t.jsx)("h3",{className:"text-sm font-semibold",children:"Accounts"}),(0,$t.jsx)("p",{className:"text-sm text-muted-foreground",children:"Search, authenticate, and inspect current Codex quota."})]})}),(0,$t.jsx)(us,{browserAuthenticationInProgress:M,checking:P.isFetching,killing:H.isPending,status:P.data,onKill:()=>H.mutate(),onRefresh:()=>{P.refetch()}}),(0,$t.jsxs)("div",{className:"flex flex-col gap-3 sm:flex-row sm:items-center sm:justify-between",children:[(0,$t.jsxs)("div",{className:"relative min-w-0 flex-1 sm:min-w-64",children:[(0,$t.jsx)(Ft,{className:"pointer-events-none absolute top-1/2 left-2.5 size-4 -translate-y-1/2 text-muted-foreground"}),(0,$t.jsx)(mt,{className:"pl-8",placeholder:"Search accounts",value:x,onChange:e=>p(e.target.value)})]}),(0,$t.jsxs)("div",{className:"grid w-full grid-cols-2 gap-2 sm:flex sm:w-auto sm:flex-wrap sm:justify-end",children:[(0,$t.jsx)("input",{ref:S,accept:"application/json,.json",className:"hidden",type:"file",onChange:async function(e){const t=e.currentTarget.files?.[0];if(e.currentTarget.value="",!t)return;const s=gs();try{const e=JSON.parse(await t.text());_.mutate({accounts:hs(e),popup:s})}catch(a){s?.close(),l.error(ps(a))}}}),(0,$t.jsxs)(dt,{className:"w-full sm:w-auto",disabled:_.isPending,variant:"outline",onClick:()=>S.current?.click(),children:[_.isPending?(0,$t.jsx)(be,{className:"animate-spin"}):(0,$t.jsx)(Le,{}),"Import"]}),(0,$t.jsxs)(dt,{className:"w-full sm:w-auto",disabled:D.isPending,variant:"outline",onClick:()=>D.mutate(),children:[D.isPending?(0,$t.jsx)(be,{className:"animate-spin"}):(0,$t.jsx)(Ge,{}),"Export"]}),(0,$t.jsxs)(k,{open:i,onOpenChange:o,children:[(0,$t.jsxs)(Z,{render:(0,$t.jsx)(dt,{className:"w-full sm:w-auto"}),children:[I.isPending||Q.isPending?(0,$t.jsx)(be,{className:"animate-spin"}):(0,$t.jsx)(K,{}),"Add",(0,$t.jsx)(Ie,{"data-icon":"inline-end"})]}),(0,$t.jsxs)(J,{align:"end",className:"w-56",children:[(0,$t.jsxs)(w,{disabled:I.isPending,onClick:()=>B("browser"),children:[(0,$t.jsx)(yt,{}),"Normal Auth"]}),(0,$t.jsxs)(w,{disabled:I.isPending,onClick:()=>B("device"),children:[(0,$t.jsx)(ot,{}),"Device Auth"]}),(0,$t.jsx)(F,{}),(0,$t.jsxs)(w,{disabled:Q.isPending,onClick:()=>{o(!1),Q.mutate()},children:[Q.isPending?(0,$t.jsx)(be,{className:"animate-spin"}):(0,$t.jsx)(St,{}),"Import Local"]})]})]})]})]}),(0,$t.jsx)("div",{className:"grid gap-2",children:z.length?z.map(n=>(0,$t.jsx)(ss,{account:n,authPending:O.isPending&&O.variables?.accountId===n.id,authPendingMode:O.variables?.mode??"browser",cancelPending:R.isPending&&R.variables===n.id,localActivePending:G.isPending&&G.variables===n.id,quotaLabel:a[n.id],quotaPending:!!t[n.id],quotaSnapshot:s[n.id],onDelete:()=>N(n),onEdit:()=>function(e){var t;b(e),v({args:e.args.join(" "),command:e.command,displayName:e.displayName,environment:(t=e.environment,t?JSON.stringify(t,null,2):"")})}(n),onAuthenticate:t=>async function(t,s="browser"){if("browser"===s&&!(await V()))return;const a=e.find(e=>e.id===t),n=gs();C.current=n,h(""),u(ts(a,s)),O.mutate({accountId:t,mode:s,popup:n})}(n.id,t),onCancelAuthentication:()=>R.mutate(n.id),onSetLocalActive:()=>G.mutate(n.id),onShowAuthentication:()=>function(e){h(""),u(ts(e,es(e.lastAuthMode)??"browser"))}(n)},n.id)):(0,$t.jsx)("div",{className:"rounded-md border bg-background px-3 py-8 text-center text-sm text-muted-foreground",children:e.length?"No accounts match the current search.":"No accounts yet. Add an account or import account records."})})]})}),(0,$t.jsx)(Yt,{callbackUrl:m,cancelPending:R.isPending&&R.variables===d?.accountId,completePending:L.isPending,state:d,onCallbackUrlChange:h,onClose:()=>{u(null),h("")},onCancelAuthentication:()=>{d?.accountId&&R.mutate(d.accountId)},onComplete:()=>{d?.accountId&&L.mutate({accountId:d.accountId,redirectUrl:m})},onCopyDeviceCode:()=>{!async function(e){if(!e)return;try{await navigator.clipboard.writeText(e),l.success("Device code copied.")}catch{l.error("Could not copy device code.")}}(d?.userCode??"")},onReopen:()=>fs(d?.authUrl)}),(0,$t.jsx)(Je,{open:!!g,onOpenChange:e=>{e||U.isPending||(b(null),v(ls))},children:(0,$t.jsxs)(Ye,{className:"max-w-2xl",children:[(0,$t.jsxs)(tt,{children:[(0,$t.jsxs)(Ke,{children:["Edit ",g?.displayName??"account"]}),(0,$t.jsx)(He,{children:"Saving runtime settings disconnects the account until it is authenticated again."})]}),(0,$t.jsx)(ds,{form:j,onChange:v,prefix:`edit-account-${g?.id??"selected"}`}),(0,$t.jsxs)(Ve,{children:[(0,$t.jsxs)(dt,{variant:"outline",onClick:()=>{b(null),v(ls)},children:[(0,$t.jsx)($,{}),"Cancel"]}),(0,$t.jsxs)(dt,{disabled:!j.displayName.trim()||U.isPending,onClick:()=>U.mutate(),children:[U.isPending?(0,$t.jsx)(be,{className:"animate-spin"}):(0,$t.jsx)(te,{}),"Save account"]})]})]})}),(0,$t.jsx)(Kt,{open:!!y,onOpenChange:e=>{e||N(null)},children:(0,$t.jsxs)(Gt,{children:[(0,$t.jsxs)(Vt,{children:[(0,$t.jsx)(Wt,{children:"Delete account?"}),(0,$t.jsxs)(Jt,{children:["This removes ",y?.displayName??"the account"," from xedoc. Chats that reference it may no longer run."]})]}),(0,$t.jsxs)(Bt,{children:[(0,$t.jsx)(Xt,{children:"Cancel"}),(0,$t.jsxs)(Zt,{disabled:q.isPending,variant:"destructive",onClick:()=>{y&&q.mutate(y.id)},children:[q.isPending?(0,$t.jsx)(be,{className:"animate-spin"}):(0,$t.jsx)(Dt,{}),"Delete"]})]})]})})]})}function ds({form:e,onChange:t,prefix:s}){return(0,$t.jsxs)("div",{className:"grid gap-3",children:[(0,$t.jsxs)("div",{className:"grid gap-2",children:[(0,$t.jsx)(lt,{htmlFor:`${s}-name`,children:"Display name"}),(0,$t.jsx)(mt,{id:`${s}-name`,placeholder:"Work Codex",value:e.displayName,onChange:s=>t({...e,displayName:s.target.value})})]}),(0,$t.jsxs)("div",{className:"grid gap-3 md:grid-cols-2",children:[(0,$t.jsxs)("div",{className:"grid gap-2",children:[(0,$t.jsx)(lt,{htmlFor:`${s}-command`,children:"Command"}),(0,$t.jsx)(mt,{id:`${s}-command`,placeholder:"codex",value:e.command,onChange:s=>t({...e,command:s.target.value})})]}),(0,$t.jsxs)("div",{className:"grid gap-2",children:[(0,$t.jsx)(lt,{htmlFor:`${s}-args`,children:"Arguments"}),(0,$t.jsx)(mt,{id:`${s}-args`,placeholder:"app-server",value:e.args,onChange:s=>t({...e,args:s.target.value})})]})]}),(0,$t.jsxs)("div",{className:"grid gap-2",children:[(0,$t.jsx)(lt,{htmlFor:`${s}-environment`,children:"Environment JSON"}),(0,$t.jsx)(y,{className:"min-h-20 font-mono text-xs",id:`${s}-environment`,placeholder:'{"OPENAI_BASE_URL":"https://..."}',value:e.environment,onChange:s=>t({...e,environment:s.target.value})})]})]})}function us({browserAuthenticationInProgress:e,checking:t,killing:s,status:a,onKill:n,onRefresh:r}){if(!a?.inUse)return null;const i=function(e){return e.processes.length?e.processes.map(e=>[e.command??"process",`PID ${e.pid}`,e.user?`user ${e.user}`:null].filter(Boolean).join(" ")).join(", "):null}(a),o=1===a.processes.length?"Kill Process":"Kill Processes";return(0,$t.jsxs)("div",{className:"flex flex-col gap-3 rounded-md border border-amber-300 bg-amber-50 px-3 py-3 text-amber-950 dark:border-amber-900/70 dark:bg-amber-950/35 dark:text-amber-100 sm:flex-row sm:items-start sm:justify-between",children:[(0,$t.jsxs)("div",{className:"flex min-w-0 gap-2",children:[(0,$t.jsx)(ft,{className:"mt-0.5 size-4 shrink-0 text-amber-600 dark:text-amber-300"}),(0,$t.jsxs)("div",{className:"grid min-w-0 gap-1",children:[(0,$t.jsx)("div",{className:"text-sm font-medium",children:"Login callback port is busy"}),(0,$t.jsx)("p",{className:"text-sm leading-relaxed",children:e?`${a.host}:${a.port} is already listening for a browser login. Starting another Normal Auth can fail while this listener is active.`:`${a.host}:${a.port} is already listening. Normal Auth can fail until this process is stopped.`}),(0,$t.jsx)("p",{className:"break-words text-xs text-amber-800 dark:text-amber-200/80",children:i??"Process details are unavailable."})]})]}),(0,$t.jsxs)("div",{className:"flex shrink-0 flex-wrap gap-2 sm:justify-end",children:[(0,$t.jsxs)(dt,{disabled:t||s,size:"sm",variant:"outline",onClick:r,children:[t?(0,$t.jsx)(be,{className:"animate-spin"}):(0,$t.jsx)(Ot,{}),"Refresh"]}),(0,$t.jsxs)(dt,{disabled:!a.killable||s,size:"sm",variant:"destructive",onClick:n,children:[s?(0,$t.jsx)(be,{className:"animate-spin"}):(0,$t.jsx)(Ut,{}),o]})]})]})}function ms(e){const t={};if(e.command.trim()&&(t.command=e.command.trim()),e.args.trim()&&(t.args=e.args.split(/\s+/).map(e=>e.trim()).filter(Boolean)),e.environment.trim()){const s=JSON.parse(e.environment);if(!s||"object"!=typeof s||Array.isArray(s))throw new Error("Environment must be a JSON object.");t.environment=s}return t}function hs(e){if(Array.isArray(e))return e;if(e&&"object"==typeof e){const t=e.accounts;if(Array.isArray(t))return t}throw new Error("Import file must contain an accounts array.")}function xs(e){return 1===e?"account":"accounts"}function ps(e){return e instanceof Error?e.message:"Request failed."}function gs(){const e=window.open("about:blank","_blank");return e&&(e.opener=null),e}function fs(e,t){e?!t||t.closed?window.open(e,"_blank","noopener,noreferrer"):t.location.href=e:t?.close()}function bs({className:e,orientation:t="horizontal",...s}){return(0,$t.jsx)(V,{"data-slot":"separator",orientation:t,className:fe("shrink-0 bg-border data-horizontal:h-px data-horizontal:w-full data-vertical:w-px data-vertical:self-stretch",e),...s})}function js({accounts:e,accountRateLimitFetching:t,accountRateLimitSnapshots:s,accountUsageSummaries:a,activeTab:n,createFocusKey:r,onOpenChange:i,onTabChange:o,open:l,session:c}){return(0,$t.jsx)(Je,{open:l,onOpenChange:i,children:(0,$t.jsxs)(Ye,{className:"max-h-[92vh] max-w-5xl gap-0 overflow-hidden p-0",children:[(0,$t.jsxs)(tt,{className:"px-5 py-4",children:[(0,$t.jsx)(Ke,{children:"Settings"}),(0,$t.jsx)(He,{children:"Manage accounts, personalization, and project details."})]}),(0,$t.jsx)(bs,{}),(0,$t.jsxs)("div",{className:"grid min-h-0 md:grid-cols-[11rem_minmax(0,1fr)]",children:[(0,$t.jsxs)("nav",{className:"flex gap-2 overflow-x-auto border-b p-3 md:flex-col md:border-r md:border-b-0",children:[(0,$t.jsx)(vs,{active:"accounts"===n,icon:(0,$t.jsx)(W,{}),label:"Accounts",onClick:()=>o("accounts")}),(0,$t.jsx)(vs,{active:"personalization"===n,icon:(0,$t.jsx)(z,{}),label:"Personalization",onClick:()=>o("personalization")}),(0,$t.jsx)(vs,{active:"info"===n,icon:(0,$t.jsx)(ie,{}),label:"Info",onClick:()=>o("info")})]}),(0,$t.jsx)(C,{className:"h-[74vh]",children:(0,$t.jsxs)("div",{className:"p-5",children:["personalization"===n?(0,$t.jsx)(ys,{session:c}):null,"accounts"===n?(0,$t.jsx)(cs,{accounts:e,accountRateLimitFetching:t,accountRateLimitSnapshots:s,accountUsageSummaries:a,createFocusKey:r,session:c}):null,"info"===n?(0,$t.jsx)(Ns,{}):null]})})]})]})})}function vs({active:e,icon:t,label:s,onClick:a}){return(0,$t.jsxs)(dt,{"aria-pressed":e,className:fe("justify-start",e&&"bg-muted text-foreground hover:bg-muted"),variant:"ghost",onClick:a,children:[t,s]})}function ys({session:e}){const[t,s]=(0,pt.useState)(""),a=c(),n=Y({queryKey:["account-personalization"],queryFn:()=>pe(e)});(0,pt.useEffect)(()=>{n.data&&s(n.data.instructions)},[n.data]);const r=f({mutationFn:()=>ce(e,{instructions:t}),onError:e=>l.error(ws(e)),onSuccess:e=>{a.setQueryData(["account-personalization"],e),a.invalidateQueries({queryKey:["account-personalization"]}),l.success("Personalization saved.")}}),i=(0,pt.useMemo)(()=>(new TextEncoder).encode(t).length,[t]),o=n.data?.maxBytes??32768,d=!!n.data&&t!==n.data.instructions,u=i>o;return(0,$t.jsxs)("div",{className:"grid gap-5",children:[(0,$t.jsxs)("div",{className:"flex flex-wrap items-start justify-between gap-3",children:[(0,$t.jsxs)("div",{children:[(0,$t.jsx)("h3",{className:"flex items-center text-sm font-semibold",children:"Custom instructions"}),(0,$t.jsx)("p",{className:"mt-1 text-sm text-muted-foreground",children:"Saved to the shared Codex personalization file."})]}),(0,$t.jsxs)("div",{className:fe("text-xs text-muted-foreground",u&&"text-destructive"),children:[i.toLocaleString()," / ",o.toLocaleString()," bytes"]})]}),(0,$t.jsxs)("div",{className:"grid gap-2",children:[(0,$t.jsx)(lt,{htmlFor:"personalization-instructions",children:"AGENTS.md"}),(0,$t.jsx)(y,{className:"min-h-72 font-mono text-xs leading-relaxed",disabled:n.isLoading||r.isPending,id:"personalization-instructions",placeholder:"## Working agreements\n\n- Prefer concise answers.\n- Run relevant tests after code changes.",value:t,onChange:e=>s(e.target.value)})]}),n.error?(0,$t.jsx)("p",{className:"rounded-md border border-destructive/30 bg-destructive/10 px-3 py-2 text-sm text-destructive",children:ws(n.error)}):null,(0,$t.jsxs)("div",{className:"flex flex-wrap items-center justify-between gap-3",children:[(0,$t.jsx)("div",{}),(0,$t.jsxs)("div",{className:"flex flex-wrap justify-end gap-2",children:[(0,$t.jsxs)(dt,{disabled:n.isFetching,variant:"outline",onClick:()=>{n.refetch()},children:[n.isFetching?(0,$t.jsx)(be,{className:"animate-spin"}):(0,$t.jsx)(_,{}),"Reload"]}),(0,$t.jsxs)(dt,{disabled:!d||r.isPending,variant:"secondary",onClick:()=>s(n.data?.instructions??""),children:[(0,$t.jsx)(_,{}),"Reset"]}),(0,$t.jsxs)(dt,{disabled:!d||u||n.isLoading||r.isPending,onClick:()=>r.mutate(),children:[r.isPending?(0,$t.jsx)(be,{className:"animate-spin"}):(0,$t.jsx)(Rt,{}),"Save"]})]})]})]})}function Ns(){return(0,$t.jsxs)("div",{className:"grid gap-4",children:[(0,$t.jsxs)("section",{className:"rounded-md border bg-muted/30 p-4",children:[(0,$t.jsxs)("div",{className:"flex items-center gap-2 text-sm font-medium",children:[(0,$t.jsx)(ie,{}),"Project"]}),(0,$t.jsx)("div",{className:"mt-2 text-sm text-muted-foreground",children:"xedoc"})]}),(0,$t.jsxs)("section",{className:"grid gap-3 rounded-md border bg-muted/30 p-4",children:[(0,$t.jsx)("h3",{className:"text-sm font-semibold",children:"Contact"}),(0,$t.jsxs)("a",{className:"inline-flex w-fit items-center gap-2 text-sm text-primary underline-offset-4 hover:underline",href:"https://github.com/monokaijs/xedoc",rel:"noreferrer",target:"_blank",children:[(0,$t.jsx)(yt,{className:"size-4"}),"GitHub: monokaijs/xedoc"]}),(0,$t.jsxs)("a",{className:"inline-flex w-fit items-center gap-2 text-sm text-primary underline-offset-4 hover:underline",href:"mailto:monokaijs@gmail.com",children:[(0,$t.jsx)(Et,{className:"size-4"}),"Email: monokaijs@gmail.com"]})]})]})}function ws(e){return e instanceof Error?e.message:"Request failed."}function ks(){const{setTheme:e,theme:t}=oe(),s=t??"system";return(0,$t.jsxs)(k,{children:[(0,$t.jsxs)(Z,{render:(0,$t.jsx)(dt,{size:"icon",variant:"ghost"}),children:[(0,$t.jsx)(qt,{className:"size-4 dark:hidden"}),(0,$t.jsx)(zt,{className:"hidden size-4 dark:block"}),(0,$t.jsx)("span",{className:"sr-only",children:"Theme"})]}),(0,$t.jsxs)(J,{align:"end",className:"w-40",children:[(0,$t.jsxs)(w,{onClick:()=>e("light"),children:[(0,$t.jsx)(qt,{}),"Light","light"===s?(0,$t.jsx)(ee,{className:"ml-auto"}):null]}),(0,$t.jsxs)(w,{onClick:()=>e("dark"),children:[(0,$t.jsx)(zt,{}),"Dark","dark"===s?(0,$t.jsx)(ee,{className:"ml-auto"}):null]}),(0,$t.jsxs)(w,{onClick:()=>e("system"),children:[(0,$t.jsx)(At,{}),"System","system"===s?(0,$t.jsx)(ee,{className:"ml-auto"}):null]})]})]})}function Cs({...e}){return(0,$t.jsx)(rt,{"data-slot":"sheet",...e})}function Ss({...e}){return(0,$t.jsx)(Be,{"data-slot":"sheet-portal",...e})}function As({className:e,...t}){return(0,$t.jsx)(st,{"data-slot":"sheet-overlay",className:fe("fixed inset-0 z-50 bg-black/10 transition-opacity duration-150 data-ending-style:opacity-0 data-starting-style:opacity-0 supports-backdrop-filter:backdrop-blur-xs",e),...t})}function Es({className:e,children:t,side:s="right",showCloseButton:a=!0,...n}){return(0,$t.jsxs)(Ss,{children:[(0,$t.jsx)(As,{}),(0,$t.jsxs)(Qe,{"data-slot":"sheet-content","data-side":s,className:fe("fixed z-50 flex flex-col gap-4 bg-popover bg-clip-padding text-sm text-popover-foreground shadow-lg transition duration-200 ease-in-out data-ending-style:opacity-0 data-starting-style:opacity-0 data-[side=bottom]:inset-x-0 data-[side=bottom]:bottom-0 data-[side=bottom]:h-auto data-[side=bottom]:border-t data-[side=bottom]:data-ending-style:translate-y-[2.5rem] data-[side=bottom]:data-starting-style:translate-y-[2.5rem] data-[side=left]:inset-y-0 data-[side=left]:left-0 data-[side=left]:h-full data-[side=left]:w-3/4 data-[side=left]:border-r data-[side=left]:data-ending-style:translate-x-[-2.5rem] data-[side=left]:data-starting-style:translate-x-[-2.5rem] data-[side=right]:inset-y-0 data-[side=right]:right-0 data-[side=right]:h-full data-[side=right]:w-3/4 data-[side=right]:border-l data-[side=right]:data-ending-style:translate-x-[2.5rem] data-[side=right]:data-starting-style:translate-x-[2.5rem] data-[side=top]:inset-x-0 data-[side=top]:top-0 data-[side=top]:h-auto data-[side=top]:border-b data-[side=top]:data-ending-style:translate-y-[-2.5rem] data-[side=top]:data-starting-style:translate-y-[-2.5rem] data-[side=left]:sm:max-w-sm data-[side=right]:sm:max-w-sm",e),...n,children:[t,a&&(0,$t.jsxs)(qe,{"data-slot":"sheet-close",render:(0,$t.jsx)(dt,{variant:"ghost",className:"absolute top-3 right-3",size:"icon-sm"}),children:[(0,$t.jsx)($,{}),(0,$t.jsx)("span",{className:"sr-only",children:"Close"})]})]})]})}function Ps({className:e,...t}){return(0,$t.jsx)("div",{"data-slot":"sheet-header",className:fe("flex flex-col gap-0.5 p-4",e),...t})}function Ts({className:e,...t}){return(0,$t.jsx)(Ze,{"data-slot":"sheet-title",className:fe("font-heading text-base font-medium text-foreground",e),...t})}function zs({className:e,...t}){return(0,$t.jsx)(_e,{"data-slot":"sheet-description",className:fe("text-sm text-muted-foreground",e),...t})}var Ms=pt.createContext(null);function Is(){const e=pt.useContext(Ms);if(!e)throw new Error("useSidebar must be used within a SidebarProvider.");return e}function Us({defaultOpen:e=!0,open:t,onOpenChange:s,className:a,style:n,children:r,...i}){const o=function(){const[e,t]=pt.useState(()=>"undefined"!=typeof window&&window.innerWidth<768);return pt.useEffect(()=>{const e=window.matchMedia("(max-width: 767px)"),s=()=>{t(window.innerWidth<768)};return e.addEventListener("change",s),()=>e.removeEventListener("change",s)},[]),e}(),[l,c]=pt.useState(!1),[d,u]=pt.useState(e),m=t??d,h=pt.useCallback(e=>{const t="function"==typeof e?e(m):e;s?s(t):u(t),document.cookie=`sidebar_state=${t}; path=/; max-age=604800`},[s,m]),x=pt.useCallback(()=>o?c(e=>!e):h(e=>!e),[o,h,c]);pt.useEffect(()=>{const e=e=>{"b"===e.key&&(e.metaKey||e.ctrlKey)&&(e.preventDefault(),x())};return window.addEventListener("keydown",e),()=>window.removeEventListener("keydown",e)},[x]);const p=m?"expanded":"collapsed",g=pt.useMemo(()=>({state:p,open:m,setOpen:h,isMobile:o,openMobile:l,setOpenMobile:c,toggleSidebar:x}),[p,m,h,o,l,c,x]);return(0,$t.jsx)(Ms.Provider,{value:g,children:(0,$t.jsx)("div",{"data-slot":"sidebar-wrapper",style:{"--sidebar-width":"16rem","--sidebar-width-icon":"3rem",...n},className:fe("group/sidebar-wrapper flex min-h-svh w-full has-data-[variant=inset]:bg-sidebar",a),...i,children:r})})}function Os({side:e="left",variant:t="sidebar",collapsible:s="offcanvas",className:a,children:n,dir:r,...i}){const{isMobile:o,state:l,openMobile:c,setOpenMobile:d}=Is();return"none"===s?(0,$t.jsx)("div",{"data-slot":"sidebar",className:fe("flex h-full w-(--sidebar-width) flex-col bg-sidebar text-sidebar-foreground",a),...i,children:n}):o?(0,$t.jsx)(Cs,{open:c,onOpenChange:d,...i,children:(0,$t.jsxs)(Es,{dir:r,"data-sidebar":"sidebar","data-slot":"sidebar","data-mobile":"true",className:"w-(--sidebar-width) bg-sidebar p-0 text-sidebar-foreground [&>button]:hidden",style:{"--sidebar-width":"18rem"},side:e,children:[(0,$t.jsxs)(Ps,{className:"sr-only",children:[(0,$t.jsx)(Ts,{children:"Sidebar"}),(0,$t.jsx)(zs,{children:"Displays the mobile sidebar."})]}),(0,$t.jsx)("div",{className:"flex h-full w-full flex-col",children:n})]})}):(0,$t.jsxs)("div",{className:"group peer hidden text-sidebar-foreground md:block","data-state":l,"data-collapsible":"collapsed"===l?s:"","data-variant":t,"data-side":e,"data-slot":"sidebar",children:[(0,$t.jsx)("div",{"data-slot":"sidebar-gap",className:fe("relative w-(--sidebar-width) bg-transparent transition-[width] duration-200 ease-linear","group-data-[collapsible=offcanvas]:w-0","group-data-[side=right]:rotate-180","floating"===t||"inset"===t?"group-data-[collapsible=icon]:w-[calc(var(--sidebar-width-icon)+(--spacing(4)))]":"group-data-[collapsible=icon]:w-(--sidebar-width-icon)")}),(0,$t.jsx)("div",{"data-slot":"sidebar-container","data-side":e,className:fe("fixed inset-y-0 z-10 hidden h-svh w-(--sidebar-width) transition-[left,right,width] duration-200 ease-linear data-[side=left]:left-0 data-[side=left]:group-data-[collapsible=offcanvas]:left-[calc(var(--sidebar-width)*-1)] data-[side=right]:right-0 data-[side=right]:group-data-[collapsible=offcanvas]:right-[calc(var(--sidebar-width)*-1)] md:flex","floating"===t||"inset"===t?"p-2 group-data-[collapsible=icon]:w-[calc(var(--sidebar-width-icon)+(--spacing(4))+2px)]":"group-data-[collapsible=icon]:w-(--sidebar-width-icon) group-data-[side=left]:border-r group-data-[side=right]:border-l",a),...i,children:(0,$t.jsx)("div",{"data-sidebar":"sidebar","data-slot":"sidebar-inner",className:"flex size-full flex-col bg-sidebar group-data-[variant=floating]:rounded-lg group-data-[variant=floating]:shadow-sm group-data-[variant=floating]:ring-1 group-data-[variant=floating]:ring-sidebar-border",children:n})})]})}function Rs({className:e,onClick:t,...s}){const{toggleSidebar:a}=Is();return(0,$t.jsxs)(dt,{"data-sidebar":"trigger","data-slot":"sidebar-trigger",variant:"ghost",size:"icon-sm",className:fe(e),onClick:e=>{t?.(e),a()},...s,children:[(0,$t.jsx)(Mt,{}),(0,$t.jsx)("span",{className:"sr-only",children:"Toggle Sidebar"})]})}function Fs({className:e,...t}){return(0,$t.jsx)("main",{"data-slot":"sidebar-inset",className:fe("relative flex w-full flex-1 flex-col bg-background md:peer-data-[variant=inset]:m-2 md:peer-data-[variant=inset]:ml-0 md:peer-data-[variant=inset]:rounded-xl md:peer-data-[variant=inset]:shadow-sm md:peer-data-[variant=inset]:peer-data-[state=collapsed]:ml-2",e),...t})}function Ls({className:e,...t}){return(0,$t.jsx)("div",{"data-slot":"sidebar-header","data-sidebar":"header",className:fe("flex flex-col gap-2 p-2",e),...t})}function qs({className:e,...t}){return(0,$t.jsx)("div",{"data-slot":"sidebar-footer","data-sidebar":"footer",className:fe("flex flex-col gap-2 p-2",e),...t})}function Ds({className:e,...t}){return(0,$t.jsx)("div",{"data-slot":"sidebar-content","data-sidebar":"content",className:fe("no-scrollbar flex min-h-0 flex-1 flex-col gap-0 overflow-auto group-data-[collapsible=icon]:overflow-hidden",e),...t})}function $s({className:e,...t}){return(0,$t.jsx)("div",{"data-slot":"sidebar-group","data-sidebar":"group",className:fe("relative flex w-full min-w-0 flex-col p-2",e),...t})}function Hs({className:e,render:t,...s}){return R({defaultTagName:"div",props:de({className:fe("flex h-8 shrink-0 items-center rounded-md px-2 text-xs font-medium text-sidebar-foreground/70 ring-sidebar-ring outline-hidden transition-[margin,opacity] duration-200 ease-linear group-data-[collapsible=icon]:-mt-8 group-data-[collapsible=icon]:opacity-0 focus-visible:ring-2 [&>svg]:size-4 [&>svg]:shrink-0",e)},s),render:t,state:{slot:"sidebar-group-label",sidebar:"group-label"}})}function Ks({className:e,...t}){return(0,$t.jsx)("div",{"data-slot":"sidebar-group-content","data-sidebar":"group-content",className:fe("w-full text-sm",e),...t})}function _s({className:e,...t}){return(0,$t.jsx)("ul",{"data-slot":"sidebar-menu","data-sidebar":"menu",className:fe("flex w-full min-w-0 flex-col gap-0",e),...t})}function Qs({className:e,...t}){return(0,$t.jsx)("li",{"data-slot":"sidebar-menu-item","data-sidebar":"menu-item",className:fe("group/menu-item relative",e),...t})}var Gs=ut("peer/menu-button group/menu-button flex w-full items-center gap-2 overflow-hidden rounded-md p-2 text-left text-sm ring-sidebar-ring outline-hidden transition-[width,height,padding] group-has-data-[sidebar=menu-action]/menu-item:pr-8 group-data-[collapsible=icon]:size-8! group-data-[collapsible=icon]:p-2! hover:bg-sidebar-accent hover:text-sidebar-accent-foreground focus-visible:ring-2 active:bg-sidebar-accent active:text-sidebar-accent-foreground disabled:pointer-events-none disabled:opacity-50 aria-disabled:pointer-events-none aria-disabled:opacity-50 data-open:hover:bg-sidebar-accent data-open:hover:text-sidebar-accent-foreground data-active:bg-sidebar-accent data-active:font-medium data-active:text-sidebar-accent-foreground [&_svg]:size-4 [&_svg]:shrink-0 [&>span:last-child]:truncate",{variants:{variant:{default:"hover:bg-sidebar-accent hover:text-sidebar-accent-foreground",outline:"bg-background shadow-[0_0_0_1px_var(--sidebar-border)] hover:bg-sidebar-accent hover:text-sidebar-accent-foreground hover:shadow-[0_0_0_1px_var(--sidebar-accent)]"},size:{default:"h-8 text-sm",sm:"h-7 text-xs",lg:"h-12 text-sm group-data-[collapsible=icon]:p-0!"}},defaultVariants:{variant:"default",size:"default"}});function Vs({render:e,isActive:t=!1,variant:s="default",size:a="default",tooltip:n,className:r,...i}){const{isMobile:o,state:l}=Is(),c=R({defaultTagName:"button",props:de({className:fe(Gs({variant:s,size:a}),r)},i),render:n?(0,$t.jsx)(ne,{render:e}):e,state:{slot:"sidebar-menu-button",sidebar:"menu-button",size:a,active:t}});return n?("string"==typeof n&&(n={children:n}),(0,$t.jsxs)(re,{children:[c,(0,$t.jsx)(se,{side:"right",align:"center",hidden:"collapsed"!==l||o,...n})]})):c}function Bs({initialPath:e,mode:t="directory",onOpenChange:s,onSelect:a,open:n,session:r}){const i=c(),[o,d]=(0,pt.useState)(new Set),[u,m]=(0,pt.useState)(e??""),[h,x]=(0,pt.useState)("directory"),[p,g]=(0,pt.useState)(e??""),[b,j]=(0,pt.useState)(""),[v,y]=(0,pt.useState)(!0),[N,w]=(0,pt.useState)(!1),[k,S]=(0,pt.useState)(""),[A,E]=(0,pt.useState)(""),P=Y({enabled:n,queryKey:ta(r,void 0),queryFn:()=>we(r,void 0)}),T=P.data,z=T?.root??T?.path??"",M=u||T?.path||"",I=f({mutationFn:()=>{const e=k||M||T?.path,t=A.trim();if(!e)throw new Error("Select a folder first.");if(!t)throw new Error("Enter a folder name.");return Ce(r,{parentPath:e,name:t})},onError:e=>l.error(function(e){return e instanceof Error?e.message:"Request failed."}(e)),onSuccess:e=>{w(!1),S(""),E(""),l.success("Folder created."),i.invalidateQueries({queryKey:["workspace-directory",r.serverUrl]}),O(e.path)}});function U(e,t="directory"){m(e),x(t),g(e),z&&d(t=>{const s=new Set(t);for(const a of sa(e,z))s.add(a);return s})}function O(e){m(e),x("directory"),g(e),d(t=>new Set(t).add(e))}function R(){const e=p.trim()||T?.path;e&&U(e)}return(0,pt.useEffect)(()=>{n&&(d(new Set),m(e??""),x("directory"),g(e??""),j(""),y(!0),w(!1),S(""),E(""))},[e,n]),(0,pt.useEffect)(()=>{if(!T)return;const t=e||T.path;m(e=>e||t),g(e=>e||t),d(e=>{const s=new Set(e);for(const a of sa(t,T.root))s.add(a);return s})},[e,T]),(0,$t.jsx)(Je,{open:n,onOpenChange:s,children:(0,$t.jsxs)(Ye,{className:"flex max-h-[88vh] max-w-2xl flex-col gap-0 overflow-hidden rounded-xl bg-background p-0 ring-border sm:max-w-2xl",children:[(0,$t.jsxs)(tt,{className:"gap-1 px-4 pb-2 pt-3",children:[(0,$t.jsx)(Ke,{children:"file"===t?"Choose Workspace File":"Choose Working Directory"}),(0,$t.jsx)(He,{className:"truncate",children:T?.root?`Workspace root: ${T.root}`:"file"===t?"Pick a file from the workspace.":"Pick a project folder for Codex."})]}),(0,$t.jsxs)("div",{className:"grid min-h-0 flex-1 grid-rows-[auto_minmax(0,1fr)]",children:[(0,$t.jsxs)("div",{className:"grid gap-1.5 px-3 pb-2 pt-1",children:[(0,$t.jsxs)("div",{className:"flex min-w-0 items-center gap-1",children:[(0,$t.jsx)(ea,{label:"Home",onClick:function(){T?.path&&O(T.path)},children:(0,$t.jsx)(Ct,{})}),(0,$t.jsx)(ea,{disabled:!M||I.isPending,label:"New folder",onClick:function(){const e=M||T?.path;e&&(m(e),x("directory"),g(e),j(""),w(!0),S(e),E(""),d(t=>{const s=new Set(t);if(z)for(const a of sa(e,z))s.add(a);return s.add(e),s}))},children:(0,$t.jsx)(wt,{})}),(0,$t.jsx)(ea,{label:"Refresh",onClick:function(){i.invalidateQueries({queryKey:["workspace-directory",r.serverUrl]})},children:(0,$t.jsx)(_,{className:fe(P.isFetching&&"animate-spin")})}),(0,$t.jsxs)("div",{className:"ml-auto flex min-w-0 items-center gap-2",children:[(0,$t.jsx)(Ys,{showPath:v,onClick:()=>y(e=>!e)}),(0,$t.jsxs)("div",{className:"relative hidden min-w-0 sm:block",children:[(0,$t.jsx)(Ft,{className:"pointer-events-none absolute left-2 top-1.5 size-4 text-muted-foreground"}),(0,$t.jsx)(mt,{className:"h-7 w-44 border-border/70 bg-muted/40 pl-7 text-xs",placeholder:"Filter",value:b,onChange:e=>j(e.target.value)})]})]})]}),v?(0,$t.jsxs)("div",{className:"flex min-w-0 items-center gap-1",children:[(0,$t.jsx)(mt,{autoCapitalize:"none",className:"h-8 min-w-0 border-border/70 bg-muted/40 font-mono text-xs",spellCheck:!1,value:p,onChange:e=>g(e.target.value),onKeyDown:e=>{"Enter"===e.key&&R()}}),(0,$t.jsx)(ea,{label:"Open path",onClick:R,children:(0,$t.jsx)(L,{})})]}):null,(0,$t.jsxs)("div",{className:"flex min-w-0 items-center gap-2 sm:hidden",children:[(0,$t.jsx)(Ys,{showPath:v,onClick:()=>y(e=>!e)}),(0,$t.jsxs)("div",{className:"relative min-w-0 flex-1",children:[(0,$t.jsx)(Ft,{className:"pointer-events-none absolute left-2 top-1.5 size-4 text-muted-foreground"}),(0,$t.jsx)(mt,{className:"h-7 border-border/70 bg-muted/40 pl-7 text-xs",placeholder:"Filter",value:b,onChange:e=>j(e.target.value)})]})]})]}),(0,$t.jsx)("div",{className:"min-h-0 bg-background",children:P.error?(0,$t.jsx)("div",{className:"m-3 rounded-md border border-destructive/30 bg-destructive/10 px-3 py-2 text-sm text-destructive",children:P.error.message||"Unable to browse workspace."}):(0,$t.jsx)(C,{className:"h-[46vh] min-h-72",children:(0,$t.jsxs)("div",{className:"p-1",children:[P.isLoading?(0,$t.jsx)("div",{className:"px-3 py-8 text-center text-sm text-muted-foreground",children:"Loading directories..."}):null,T?(0,$t.jsx)(Ws,{directory:T,entry:{name:(F=T.path,F.replace(/[\\/]+$/,"").split(/[\\/]/).filter(Boolean).at(-1)||F),path:T.path,type:"directory"},expandedPaths:o,filter:b,level:0,createFolderName:A,createFolderParentPath:k,createFolderPending:I.isPending,selectedPath:M,selectedType:h,session:r,showCreateFolder:N,onCancelCreateFolder:()=>{w(!1),S(""),E("")},onCreateFolderNameChange:E,onCreateFolderSubmit:()=>I.mutate(),onOpen:O,onSelect:U,onToggle:function(e){m(e),x("directory"),g(e),d(t=>{const s=new Set(t);return s.has(e)?s.delete(e):s.add(e),s})}}):null]})})})]}),(0,$t.jsxs)(Ve,{className:"mx-0 mb-0 rounded-none border-t bg-muted/35 px-3 py-2 sm:items-center sm:justify-between",children:[(0,$t.jsxs)("div",{className:"min-w-0 flex-1 truncate text-xs text-muted-foreground",children:[(0,$t.jsx)("span",{className:"mr-1 font-medium text-foreground",children:"Selected:"}),(0,$t.jsx)("span",{className:"font-mono",children:"file"===t&&"file"!==h?"Choose a file":M||z||"None"})]}),(0,$t.jsxs)("div",{className:"flex shrink-0 justify-end gap-2",children:[(0,$t.jsxs)(dt,{disabled:!M||"file"===t&&"file"!==h,size:"sm",type:"button",onClick:function(){!M||"file"===t&&"file"!==h||(a(M),s(!1))},children:[(0,$t.jsx)(ee,{}),"file"===t?"Attach":"OK"]}),(0,$t.jsx)(dt,{size:"sm",type:"button",variant:"outline",onClick:()=>s(!1),children:"Cancel"})]})]})]})});var F}function Ws({createFolderName:e,createFolderParentPath:t,createFolderPending:s,directory:a,entry:n,expandedPaths:r,filter:i,level:o,onCancelCreateFolder:l,onCreateFolderNameChange:c,onCreateFolderSubmit:d,onOpen:u,onSelect:m,onToggle:h,selectedPath:x,selectedType:p,session:g,showCreateFolder:f}){const b=r.has(n.path),j=ra(x)===ra(n.path),v=f&&ra(t)===ra(n.path),y=Y({enabled:b&&!a,queryKey:ta(g,n.path),queryFn:()=>we(g,n.path)}),N=a??y.data,w=(0,pt.useMemo)(()=>function(e,t){const s=t.trim().toLocaleLowerCase();return(s?e.filter(e=>e.name.toLocaleLowerCase().includes(s)):e).slice(0,400)}(N?.entries??[],i),[N?.entries,i]),k=w.filter(e=>"directory"===e.type),C=w.filter(e=>"directory"!==e.type);return(0,$t.jsxs)("div",{className:"min-w-0",children:[(0,$t.jsx)(Zs,{entry:n,expanded:b,level:o,loading:y.isFetching,selected:j,onOpen:u,onSelect:m,onToggle:h}),b?(0,$t.jsxs)("div",{className:"min-w-0",children:[y.error?(0,$t.jsx)("div",{className:"h-7 truncate px-2 text-xs leading-7 text-destructive",style:{paddingLeft:34+18*(o+1)+"px"},children:y.error.message||"Unable to load folder."}):null,y.isLoading?(0,$t.jsx)("div",{className:"h-7 truncate px-2 text-xs leading-7 text-muted-foreground",style:{paddingLeft:34+18*(o+1)+"px"},children:"Loading..."}):null,v?(0,$t.jsx)(Js,{level:o+1,name:e,pending:s,onCancel:l,onNameChange:c,onSubmit:d}):null,k.map(a=>(0,$t.jsx)(Ws,{createFolderName:e,createFolderParentPath:t,createFolderPending:s,entry:a,expandedPaths:r,filter:i,level:o+1,showCreateFolder:f,selectedPath:x,selectedType:p,session:g,onCancelCreateFolder:l,onCreateFolderNameChange:c,onCreateFolderSubmit:d,onOpen:u,onSelect:m,onToggle:h},a.path)),C.map(e=>(0,$t.jsx)(Xs,{entry:e,level:o+1,selected:"file"===p&&ra(x)===ra(e.path),onSelect:m},e.path)),!N||w.length||v?null:(0,$t.jsx)("div",{className:"h-7 truncate px-2 text-xs leading-7 text-muted-foreground",style:{paddingLeft:34+18*(o+1)+"px"},children:"No matching entries."})]}):null]})}function Js({level:e,name:t,onCancel:s,onNameChange:a,onSubmit:n,pending:r}){return(0,$t.jsxs)("form",{className:"grid h-8 min-w-0 grid-cols-[1.5rem_1rem_minmax(0,1fr)_auto_auto] items-center gap-1 rounded-sm px-1 text-sm",style:{paddingLeft:4+18*e+"px"},onSubmit:e=>{e.preventDefault(),n()},children:[(0,$t.jsx)("span",{}),(0,$t.jsx)(wt,{className:"size-4 shrink-0 text-muted-foreground"}),(0,$t.jsx)(mt,{autoCapitalize:"none",autoFocus:!0,className:"h-7 min-w-0 border-border/70 bg-muted/40 text-xs",disabled:r,placeholder:"Folder name",spellCheck:!1,value:t,onChange:e=>a(e.target.value)}),(0,$t.jsx)(ea,{disabled:!t.trim()||r,label:"Create folder",onClick:n,children:(0,$t.jsx)(ee,{})}),(0,$t.jsx)(ea,{disabled:r,label:"Cancel new folder",onClick:s,children:(0,$t.jsx)($,{})})]})}function Zs({entry:e,expanded:t,level:s,loading:a,onOpen:n,onSelect:r,onToggle:i,selected:o}){return(0,$t.jsxs)("div",{className:fe("group grid h-7 min-w-0 grid-cols-[1.5rem_1rem_minmax(0,1fr)] items-center gap-1 rounded-sm px-1 text-sm",o?"bg-accent text-accent-foreground":"text-foreground hover:bg-accent/55"),style:{paddingLeft:4+18*s+"px"},children:[(0,$t.jsx)("button",{className:"flex size-6 items-center justify-center rounded-sm text-muted-foreground hover:bg-muted hover:text-foreground",title:t?"Collapse":"Expand",type:"button",onClick:()=>i(e.path),children:(0,$t.jsx)(L,{className:fe("size-4 transition-transform",t&&"rotate-90",a&&"opacity-50")})}),t?(0,$t.jsx)(it,{className:"size-4 shrink-0 text-muted-foreground"}):(0,$t.jsx)(kt,{className:"size-4 shrink-0 text-muted-foreground"}),(0,$t.jsx)("button",{className:"min-w-0 truncate text-left",title:e.path,type:"button",onClick:()=>r(e.path),onDoubleClick:()=>n(e.path),children:e.name})]})}function Xs({entry:e,level:t,onSelect:s,selected:a}){return(0,$t.jsxs)("button",{className:fe("grid h-7 min-w-0 w-full grid-cols-[1.5rem_1rem_minmax(0,1fr)] items-center gap-1 rounded-sm px-1 text-left text-sm",a?"bg-accent text-accent-foreground":"text-muted-foreground hover:bg-accent/55 hover:text-foreground"),style:{paddingLeft:4+18*t+"px"},title:e.path,type:"button",onClick:()=>s(e.path,"file"),children:[(0,$t.jsx)("span",{}),(0,$t.jsx)(X,{className:"size-4 shrink-0"}),(0,$t.jsx)("span",{className:"min-w-0 truncate",children:e.name})]})}function Ys({onClick:e,showPath:t}){return(0,$t.jsx)(ea,{label:t?"Hide path":"Show path",pressed:t,onClick:e,children:t?(0,$t.jsx)(Re,{}):(0,$t.jsx)(Nt,{})})}function ea({children:e,disabled:t,label:s,onClick:a,pressed:n}){return(0,$t.jsxs)(dt,{"aria-pressed":n,className:fe("size-7 p-0",n&&"bg-muted text-foreground"),disabled:t,size:"icon",title:s,type:"button",variant:"ghost",onClick:a,children:[e,(0,$t.jsx)("span",{className:"sr-only",children:s})]})}function ta(e,t){return["workspace-directory",e.serverUrl,t]}function sa(e,t){const s=na(t),a=na(e);if(!s||!a.startsWith(s))return s?[s]:[];const n=[s],r=a.slice(s.length).replace(/^[\\/]+/,"");let i=s;for(const o of r.split(/[\\/]/).filter(Boolean))i=aa(i,o),n.push(i);return n}function aa(e,t){const s=e.includes("\\")?"\\":"/";return`${na(e)}${s}${t}`}function na(e){return"/"===e||/^[A-Za-z]:[\\/]?$/.test(e)?e.replace(/[\\/]+$/,"")||e:e.replace(/[\\/]+$/,"")}function ra(e){return na(e).toLocaleLowerCase()}function ia({chats:e,session:t}){const s=r(),{chatId:a}=n(),i=c(),[o,d]=(0,pt.useState)(null),[u,m]=(0,pt.useState)(""),[h,x]=(0,pt.useState)(null),[p,g]=(0,pt.useState)(()=>new Set),[b,v]=(0,pt.useState)(()=>new Set),y=(0,pt.useMemo)(()=>e.map(e=>({chat:e,dateLabel:H(e.lastActivityAt),folderKey:q(e.workingDirectory),folderName:D(e.workingDirectory),folderPath:B(e.workingDirectory)})),[e]),N=(0,pt.useMemo)(()=>{const e=new Map;for(const t of y){const s=new Date(t.chat.lastActivityAt).getTime(),a=e.get(t.folderKey);a?(a.items.push(t),a.latestActivityAt=Math.max(a.latestActivityAt,s)):e.set(t.folderKey,{items:[t],key:t.folderKey,latestActivityAt:s,name:t.folderName,path:t.folderPath})}return Array.from(e.values()).map(e=>({...e,items:e.items.sort((e,t)=>new Date(t.chat.lastActivityAt).getTime()-new Date(e.chat.lastActivityAt).getTime()||e.chat.title.localeCompare(t.chat.title,void 0,{sensitivity:"base"}))})).sort((e,t)=>t.latestActivityAt-e.latestActivityAt||e.name.localeCompare(t.name,void 0,{sensitivity:"base"}))},[y]),C=f({mutationFn:()=>{if(!o)throw new Error("Select a chat to rename.");return je(t,o.id,{title:u.trim()||"Untitled chat"})},onError:e=>l.error(E(e)),onSuccess:()=>{d(null),m(""),i.invalidateQueries({queryKey:["chats"]})}}),S=f({mutationFn:e=>Ee(t,e.id),onError:e=>l.error(E(e)),onSuccess:(e,t)=>{x(null),i.invalidateQueries({queryKey:["chats"]}),a===t.id&&s("/")}});return(0,$t.jsxs)($t.Fragment,{children:[(0,$t.jsx)(_s,{className:"gap-1",children:N.length?N.map(e=>{const t=p.has(e.key),n=b.has(e.key),r=n?e.items:e.items.slice(0,4),i=e.items.length-r.length,o=j(e.path);return(0,$t.jsxs)(Qs,{children:[(0,$t.jsxs)("div",{className:"flex min-w-0 items-center gap-1 pr-1",children:[(0,$t.jsxs)("button",{className:"flex h-8 min-w-0 flex-1 items-center gap-2 rounded-md px-2 text-left text-xs font-medium text-sidebar-foreground/75 outline-none hover:bg-sidebar-accent hover:text-sidebar-accent-foreground focus-visible:bg-sidebar-accent",title:e.path,type:"button",onClick:()=>g(t=>{const s=new Set(t);return s.has(e.key)?s.delete(e.key):s.add(e.key),s}),children:[(0,$t.jsx)(kt,{className:"size-3.5 shrink-0 text-cyan-500"}),(0,$t.jsx)("span",{className:"min-w-0 flex-1 truncate",children:e.name}),(0,$t.jsx)("span",{className:"shrink-0 text-[0.68rem] font-normal text-muted-foreground",children:e.items.length}),(0,$t.jsx)(Ie,{className:fe("size-3 shrink-0 text-muted-foreground transition-transform",t&&"-rotate-90")})]}),o?(0,$t.jsx)(dt,{"aria-label":`New chat in ${e.name}`,className:"size-7 shrink-0",size:"icon-sm",title:`New chat in ${e.path}`,type:"button",variant:"ghost",onClick:()=>s("/",{state:{workingDirectory:e.path}}),children:(0,$t.jsx)(K,{className:"size-3.5"})}):null]}),t?null:(0,$t.jsxs)(_s,{className:"gap-0.5 pl-4",children:[r.map(({chat:e,dateLabel:t,folderName:n})=>(0,$t.jsxs)(Qs,{className:"flex min-w-0 items-center",children:[(0,$t.jsxs)(Vs,{className:"h-7 min-w-0 flex-1 px-2 pr-2! text-xs",isActive:e.id===a,size:"sm",tooltip:`${e.title} · ${t} · ${n}`,onClick:()=>s(`/chat/${e.id}`),children:[(0,$t.jsx)(Tt,{className:"size-3.5 text-muted-foreground"}),(0,$t.jsx)("span",{className:"min-w-0 flex-1 truncate",children:e.title})]}),(0,$t.jsxs)(k,{children:[(0,$t.jsxs)(Z,{render:(0,$t.jsx)(dt,{"aria-label":"Chat actions",className:"pointer-events-none h-7 w-0 shrink-0 overflow-hidden opacity-0 transition-[width,opacity] group-hover/menu-item:pointer-events-auto group-hover/menu-item:ml-1 group-hover/menu-item:w-7 group-hover/menu-item:opacity-100 group-focus-within/menu-item:pointer-events-auto group-focus-within/menu-item:ml-1 group-focus-within/menu-item:w-7 group-focus-within/menu-item:opacity-100 aria-expanded:pointer-events-auto aria-expanded:ml-1 aria-expanded:w-7 aria-expanded:opacity-100",size:"icon-sm",variant:"ghost"}),children:[(0,$t.jsx)(vt,{className:"size-4"}),(0,$t.jsx)("span",{className:"sr-only",children:"Chat actions"})]}),(0,$t.jsxs)(J,{align:"end",className:"w-40",children:[(0,$t.jsxs)(w,{onClick:()=>{d(e),m(e.title)},children:[(0,$t.jsx)(It,{}),"Rename"]}),(0,$t.jsxs)(w,{onClick:()=>x(e),children:[(0,$t.jsx)(gt,{}),"Archive"]})]})]})]},e.id)),i>0?(0,$t.jsx)("li",{children:(0,$t.jsxs)("button",{className:"flex h-7 w-full items-center gap-2 rounded-md px-2 text-left text-xs text-muted-foreground outline-none hover:bg-sidebar-accent hover:text-sidebar-accent-foreground focus-visible:bg-sidebar-accent",type:"button",onClick:()=>v(t=>new Set(t).add(e.key)),children:[(0,$t.jsx)(Ie,{className:"size-3.5 shrink-0"}),(0,$t.jsxs)("span",{className:"min-w-0 truncate",children:["Show ",i," more"]})]})}):n&&e.items.length>4?(0,$t.jsx)("li",{children:(0,$t.jsxs)("button",{className:"flex h-7 w-full items-center gap-2 rounded-md px-2 text-left text-xs text-muted-foreground outline-none hover:bg-sidebar-accent hover:text-sidebar-accent-foreground focus-visible:bg-sidebar-accent",type:"button",onClick:()=>v(t=>{const s=new Set(t);return s.delete(e.key),s}),children:[(0,$t.jsx)(Ie,{className:"size-3.5 shrink-0 rotate-180"}),(0,$t.jsx)("span",{className:"min-w-0 truncate",children:"Show less"})]})}):null]})]},e.key)}):(0,$t.jsx)("div",{className:"px-2 py-3 text-sm text-muted-foreground",children:"No chats yet."})}),(0,$t.jsx)(Je,{open:!!o,onOpenChange:e=>{e||(d(null),m(""))},children:(0,$t.jsxs)(Ye,{children:[(0,$t.jsxs)(tt,{children:[(0,$t.jsx)(Ke,{children:"Rename chat"}),(0,$t.jsx)(He,{children:"Choose a short title for the sidebar."})]}),(0,$t.jsx)(mt,{value:u,onChange:e=>m(e.target.value),onKeyDown:e=>{"Enter"===e.key&&C.mutate()}}),(0,$t.jsx)(Ve,{children:(0,$t.jsx)(dt,{disabled:C.isPending,onClick:()=>C.mutate(),children:"Save"})})]})}),(0,$t.jsx)(Je,{open:!!h,onOpenChange:e=>{e||x(null)},children:(0,$t.jsxs)(Ye,{children:[(0,$t.jsxs)(tt,{children:[(0,$t.jsx)(Ke,{children:"Archive chat?"}),(0,$t.jsxs)(He,{children:["This removes ",h?.title??"the chat"," from the active chat list. Message history stays on the server."]})]}),(0,$t.jsxs)(Ve,{children:[(0,$t.jsx)(dt,{variant:"outline",onClick:()=>x(null),children:"Cancel"}),(0,$t.jsxs)(dt,{disabled:S.isPending||!h,variant:"destructive",onClick:()=>{h&&S.mutate(h)},children:[(0,$t.jsx)(gt,{}),"Archive"]})]})]})})]})}function oa(){const{loading:e,session:t}=ct(),{chatId:s}=n(),o=function(e){const[t,s]=(0,pt.useState)(!1),[a,n]=(0,pt.useState)(0),[r,i]=(0,pt.useState)(null);return(0,pt.useEffect)(()=>{if(!e)return s(!1),n(0),void i(null);const t=T(e,{onClose:()=>s(!1),onCount:e=>n(Math.max(0,e.count)),onError:()=>s(!1),onOpen:()=>s(!0)});return i(t.socket),()=>{t.disconnect(),s(!1),i(null)}},[e?.serverUrl,e?.token]),{connected:t,count:a,socket:r}}(t),[l,u]=(0,pt.useState)(""),[h,x]=(0,pt.useState)(null),[f,j]=(0,pt.useState)(0),[y,N]=(0,pt.useState)(!1),[w,k]=(0,pt.useState)("accounts"),[C,E]=(0,pt.useState)(!1),[z,U]=(0,pt.useState)(null),R=r(),F=c(),L=(0,pt.useCallback)(e=>{j(e?.focusCreate?e=>e+1:0),k("accounts"),N(!0)},[]),q=(0,pt.useCallback)(e=>{"accounts"===e&&j(0),k(e)},[]),D=(0,pt.useCallback)((e="accounts")=>{k(e),N(!0)},[]),$=Y({enabled:!!t,queryKey:["accounts"],queryFn:()=>he(t),refetchInterval:e=>!!e.state.data?.some(e=>"AUTHENTICATING"===e.status)&&1500}),H=Y({enabled:!!t,queryKey:["chats"],queryFn:()=>ke(t),refetchInterval:5e3}),K=(0,pt.useMemo)(()=>$.data??[],[$.data]),_=(0,pt.useMemo)(()=>H.data??[],[H.data]),V=(0,pt.useMemo)(()=>s?_.find(e=>e.id===s)??null:null,[s,_]),B=V?.title??null;(0,pt.useEffect)(()=>{s&&x(s)},[s]);const W=(0,pt.useMemo)(()=>{if(s){const e=_.find(e=>e.id===s);if(e)return e}if(h){const e=_.find(e=>e.id===h);if(e)return e}return _[0]??null},[s,_,h]),J=(0,pt.useMemo)(()=>K.filter(e=>"CONNECTED"===e.status),[K]);ae(B);const Z=function({queries:e,...t},s){const a=c(s),n=S(),r=Q(),i=pt.useMemo(()=>e.map(e=>{const t=a.defaultQueryOptions(e);return t._optimisticResults=n?"isRestoring":"optimistic",t}),[e,a,n]);i.forEach(e=>{I(e),P(e,r,a.getQueryCache().get(e.queryHash))}),p(r);const[o]=pt.useState(()=>new xt(a,i,t)),[l,u,h]=o.getOptimisticResult(i,t.combine),x=!n&&!1!==t.subscribed;pt.useSyncExternalStore(pt.useCallback(e=>x?o.subscribe(d.batchCalls(e)):m,[o,x]),()=>o.getCurrentResult(),()=>o.getCurrentResult()),pt.useEffect(()=>{o.setQueries(i,t)},[i,t,o]);const g=l.some((e,t)=>b(i[t],e))?l.flatMap((e,t)=>{const s=i[t];return s&&b(s,e)?v(s,new A(a,s),r):[]}):[];if(g.length>0)throw Promise.all(g);const f=l.find((e,t)=>{const s=i[t];return s&&G({result:e,errorResetBoundary:r,throwOnError:s.throwOnError,query:a.getQueryCache().get(s.queryHash),suspense:s.suspense})});if(f?.error)throw f.error;return u(h())}({queries:J.map(e=>({enabled:!!t,queryKey:["rate-limits",e.id],queryFn:()=>me(t,e.id),refetchInterval:6e4,retry:!1,staleTime:3e4}))}),X=(0,pt.useMemo)(()=>Object.fromEntries(J.map((e,t)=>{const s=g(Z[t]?.data);return s?[e.id,s]:null}).filter(e=>!!e)),[Z,J]),ee=(0,pt.useMemo)(()=>Object.fromEntries(J.map(e=>{const t=X[e.id];return t?[e.id,O(t)]:null}).filter(e=>!!e)),[X,J]),te=(0,pt.useMemo)(()=>Object.fromEntries(J.map((e,t)=>[e.id,Z[t]?.isFetching??!1])),[Z,J]),se=Z.some(e=>M(e.error));if((0,pt.useEffect)(()=>{se&&F.invalidateQueries({queryKey:["accounts"]})},[se,F]),(0,pt.useEffect)(()=>{l.trim()||E(!1)},[l]),e)return(0,$t.jsx)(la,{});if(!t)return(0,$t.jsx)(i,{replace:!0,to:"/connect"});const ne={accounts:K,accountRateLimitFetching:te,accountRateLimitSnapshots:X,accountUsageSummaries:ee,activeProjectPath:l,chats:_,connectedAccounts:J,lastOpenedChat:W,openAccountManagement:L,openWorkspacePicker:U,session:t,setActiveProjectPath:u,setTerminalOpen:E,terminalCount:o.count,terminalOpen:C,terminalSocket:o.socket,terminalSocketConnected:o.connected};return(0,$t.jsxs)($t.Fragment,{children:[(0,$t.jsxs)(Us,{className:"h-svh min-h-0 overflow-hidden",children:[(0,$t.jsxs)(Os,{collapsible:"offcanvas",variant:"inset",children:[(0,$t.jsx)(Ls,{children:(0,$t.jsxs)(dt,{className:"w-full justify-start",variant:"ghost",onClick:()=>R("/"),children:[(0,$t.jsx)(Oe,{}),(0,$t.jsx)("span",{children:"New chat"})]})}),(0,$t.jsx)(Ds,{children:(0,$t.jsxs)($s,{className:"p-0",children:[(0,$t.jsx)(Hs,{children:"Chats"}),(0,$t.jsx)(Ks,{children:(0,$t.jsx)(ia,{chats:_,session:t})})]})}),(0,$t.jsx)(qs,{children:(0,$t.jsxs)(dt,{className:"justify-start",variant:"ghost",onClick:()=>D(),children:[(0,$t.jsx)(Lt,{}),(0,$t.jsx)("span",{children:"Settings"})]})})]}),(0,$t.jsxs)(Fs,{className:"min-h-0 min-w-0 overflow-hidden",children:[(0,$t.jsxs)("header",{className:"flex h-12 shrink-0 items-center justify-between gap-2 border-b px-2",children:[(0,$t.jsxs)("div",{className:"flex min-w-0 flex-1 items-center gap-2",children:[(0,$t.jsx)(Rs,{variant:"ghost",children:(0,$t.jsx)(Pt,{})}),(0,$t.jsx)("h1",{className:"min-w-0 flex-1 truncate text-sm font-semibold tracking-normal",children:B??(s?"Chat":"New chat")})]}),(0,$t.jsxs)("div",{className:"flex shrink-0 items-center gap-1",children:[V?(0,$t.jsxs)($t.Fragment,{children:[(0,$t.jsx)(We,{active:C,className:fe("md:hidden",C&&"text-foreground"),compact:!0,count:o.count,disabled:!l.trim(),onToggle:()=>E(!C)}),(0,$t.jsx)(Xe,{chatId:V.id,className:"md:hidden",compact:!0,disabled:"RUNNING"===V.status,session:t})]}):null,(0,$t.jsx)(et,{onAddAccount:()=>L({focusCreate:!0}),onNewChat:()=>R("/")}),(0,$t.jsx)(ks,{})]})]}),$.error||H.error?(0,$t.jsx)("div",{className:"border-b border-destructive/30 bg-destructive/10 px-4 py-2 text-sm text-destructive",children:$.error?.message??H.error?.message??"Unable to load workspace data."}):null,(0,$t.jsx)("div",{className:"flex min-h-0 min-w-0 flex-1 flex-col overflow-hidden",children:(0,$t.jsx)(a,{context:ne})})]})]}),(0,$t.jsx)(js,{accounts:K,accountRateLimitFetching:te,accountRateLimitSnapshots:X,accountUsageSummaries:ee,activeTab:w,createFocusKey:f,open:y,session:t,onTabChange:q,onOpenChange:N}),z?(0,$t.jsx)(Bs,{initialPath:z.initialPath,mode:z.mode,open:!!z,session:t,onOpenChange:e=>{e||U(null)},onSelect:z.onSelect}):null]})}function la(){return(0,$t.jsx)("div",{className:"flex min-h-svh items-center justify-center bg-background",children:(0,$t.jsx)(be,{className:"size-5 animate-spin text-muted-foreground"})})}var ca=t(function(){return(0,$t.jsx)(oa,{})});export{ca as default};