remote-codex 0.11.51 → 0.11.53

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,22 @@
1
+ import{j as e,r as n,L as Be,u as rt,d as qt,b as vn,e as ma,f as Qo,N as ps,B as el,h as bn,i as Ae,O as tl,k as sl,c as al}from"./react-vendor-Dfg_6BLf.js";import{u as Vt,a as yn,C as js,t as rl,f as Ar,T as nl,b as ol,c as ll,d as il,e as dl,g as cl,L as ul,P as ml,h as hl,A as fl}from"./thread-ui-C5pxOmDJ.js";import{l as z}from"./ui-vendor-CuR8GHb0.js";import"./graph-vendor-DVQUpZ8C.js";import"./terminal-vendor-C5bTa-Ka.js";import"./markdown-vendor-BG6PurxI.js";(function(){const s=document.createElement("link").relList;if(s&&s.supports&&s.supports("modulepreload"))return;for(const o of document.querySelectorAll('link[rel="modulepreload"]'))r(o);new MutationObserver(o=>{for(const l of o)if(l.type==="childList")for(const d of l.addedNodes)d.tagName==="LINK"&&d.rel==="modulepreload"&&r(d)}).observe(document,{childList:!0,subtree:!0});function a(o){const l={};return o.integrity&&(l.integrity=o.integrity),o.referrerPolicy&&(l.referrerPolicy=o.referrerPolicy),o.crossOrigin==="use-credentials"?l.credentials="include":o.crossOrigin==="anonymous"?l.credentials="omit":l.credentials="same-origin",l}function r(o){if(o.ep)return;o.ep=!0;const l=a(o);fetch(o.href,l)}})();var pl=["codex","claude","opencode","acp"],st="codex",Ir={codex:{displayName:"Codex",description:"Local Codex app-server runtime.",defaultTransport:"stdio",homeEnvVar:"CODEX_HOME",commandEnvVar:"CODEX_COMMAND",defaultHomeDir:".codex",defaultCommand:"codex"},claude:{displayName:"Claude Code",description:"Local Claude Code Agent SDK runtime.",defaultTransport:"sdk",homeEnvVar:"CLAUDE_HOME",commandEnvVar:"CLAUDE_COMMAND",defaultHomeDir:".claude",defaultCommand:"claude"},opencode:{displayName:"OpenCode",description:"Local OpenCode runtime.",defaultTransport:"sdk",homeEnvVar:"OPENCODE_HOME",commandEnvVar:"OPENCODE_COMMAND",defaultHomeDir:".opencode",defaultCommand:"opencode"},acp:{displayName:"ACP Agent",description:"Agent Client Protocol runtime over stdio.",defaultTransport:"stdio",homeEnvVar:"ACP_HOME",commandEnvVar:"ACP_COMMAND",defaultHomeDir:".acp",defaultCommand:"grok agent stdio"}};function xl(t){return typeof t=="string"&&pl.includes(t)}function gl(t){return xl(t)?t:null}var Pr=15;function vl(t){return t.replace(/\s+/g," ").trim()}function bl(t){const s=vl(t);if(!s)return"";const a=Array.from(s);return a.length<=Pr?s:`${a.slice(0,Pr).join("")}...`}function yl(t,s){const a=new Set(t.map(r=>r.id));return[...s.filter(r=>!a.has(r.id)),...t]}function wl(t,s,a=null){var v;const r=new Set,o=s.reduceRight((c,h)=>(r.has(h.id)||(r.add(h.id),c.unshift(h)),c),[]),l=new Map(o.map(c=>[c.id,c])),d=o.filter(c=>c.items.some(h=>h.kind==="userMessage")),u=new Set,p=new Set,g=t.reduceRight((c,h)=>(p.has(h.id)||(p.add(h.id),c.unshift(h)),c),[]);for(const c of g){if(l.has(c.id)){u.add(c.id);continue}if(c.status!=="inProgress")continue;const h=(v=c.items.find(O=>O.kind==="userMessage"))==null?void 0:v.text.trim(),D=c.startedAt?Date.parse(c.startedAt):Number.NaN;if(!h||!Number.isFinite(D))continue;d.find(O=>{var G;const E=(G=O.items.find(te=>te.kind==="userMessage"))==null?void 0:G.text.trim(),U=O.startedAt?Date.parse(O.startedAt):Number.NaN;return E===h&&Number.isFinite(U)&&Math.abs(U-D)<=15e3})&&u.add(c.id)}const x=[...g.filter(c=>!l.has(c.id)&&!u.has(c.id)),...o];if(!a)return x;const N=x.find(c=>c.id===a);return N?[...x.filter(c=>c.id!==a),N]:x}const jl=["codex","claude","opencode","acp"],wn="codex",jn={codex:{displayName:"Codex",description:"Local Codex app-server runtime.",defaultTransport:"stdio",homeEnvVar:"CODEX_HOME",commandEnvVar:"CODEX_COMMAND",defaultHomeDir:".codex",defaultCommand:"codex"},claude:{displayName:"Claude Code",description:"Local Claude Code Agent SDK runtime.",defaultTransport:"sdk",homeEnvVar:"CLAUDE_HOME",commandEnvVar:"CLAUDE_COMMAND",defaultHomeDir:".claude",defaultCommand:"claude"},opencode:{displayName:"OpenCode",description:"Local OpenCode runtime.",defaultTransport:"sdk",homeEnvVar:"OPENCODE_HOME",commandEnvVar:"OPENCODE_COMMAND",defaultHomeDir:".opencode",defaultCommand:"opencode"},acp:{displayName:"ACP Agent",description:"Agent Client Protocol runtime over stdio.",defaultTransport:"stdio",homeEnvVar:"ACP_HOME",commandEnvVar:"ACP_COMMAND",defaultHomeDir:".acp",defaultCommand:"grok agent stdio"}},Lr=15;function Nl(t){return t.replace(/\s+/g," ").trim()}function kl(t){const s=Nl(t);if(!s)return"";const a=Array.from(s);return a.length<=Lr?s:`${a.slice(0,Lr).join("")}...`}function Ms(){return e.jsx("svg",{"aria-hidden":"true",viewBox:"0 0 16 16",className:"h-4 w-4 fill-current",children:e.jsx("path",{d:"M3.22 2.47 8 7.25l4.78-4.78 1.06 1.06L9.06 8.31l4.78 4.78-1.06 1.06L8 9.37l-4.78 4.78-1.06-1.06 4.78-4.78-4.78-4.78 1.06-1.06Z"})})}const Sl=[{value:"light",label:"Light",description:"Always use the bright theme."},{value:"dark",label:"Dark",description:"Always use the dark theme."},{value:"system",label:"System",description:"Follow the operating system appearance."}],Nn={hostConfigFiles:[],toolboxItems:[],hookCommandTemplates:[],providerConfigFormat:"none",mcpConfigFormat:"none",configArchives:!1,buildRestart:!1},Cl={codex:{packageName:"@openai/codex",installCommand:null,updateCommand:"npm install -g @openai/codex@latest"},claude:{packageName:"@anthropic-ai/claude-agent-sdk",installCommand:"npm install -g @anthropic-ai/claude-code @anthropic-ai/claude-agent-sdk",updateCommand:"npm install -g @anthropic-ai/claude-code@latest @anthropic-ai/claude-agent-sdk@latest"},opencode:{packageName:"opencode-ai",installCommand:"npm install -g opencode-ai @opencode-ai/sdk",updateCommand:"npm install -g opencode-ai@latest @opencode-ai/sdk@latest"},acp:{packageName:null,installCommand:null,updateCommand:null}};function ea(t){const s=Cl[t];return{packageName:s.packageName,installed:t==="codex",installedVersion:null,latestVersion:null,installCommand:s.installCommand,updateCommand:s.updateCommand,busy:!1,lastError:null}}function Tl(t,s){const a=t==="acp"?"This device supervisor does not advertise ACP. Update and restart Remote Codex, or add acp to REMOTE_CODEX_ENABLED_AGENT_PROVIDERS.":"Backend descriptor is not available.";return{provider:t,displayName:s,description:`${s} backend descriptor is not available.`,enabled:!1,isDefault:t===wn,status:{state:"stopped",transport:jn[t].defaultTransport,lastStartedAt:null,lastError:a,restartCount:0},capabilities:{sessions:{list:!1,read:!1,resume:!1,importLocal:!1},turns:{start:!1,streamInput:!1,steer:!1,interrupt:!1,compact:!1},branching:{fork:!1,hardRollback:!1,resumeAt:!1,rewindFiles:!1},controls:{planMode:!1,permissionRequests:!1,sandboxMode:!1,performanceMode:!1,goals:!1},management:{models:!1,mcpStatus:!1,skills:!1,hooks:!1,hookTrust:!1,hostConfigFiles:!1,providerSettings:!1},usage:{contextWindow:!1,tokenUsage:!1,costUsd:!1}},managementSchema:Nn,installation:ea(t)}}function _s(t){const s=t.installation??ea(t.provider);return{...t,installation:{...ea(t.provider),...s}}}const St=[...jl.map(t=>Tl(t,jn[t].displayName))];function El(t){var s;return((s=St.find(a=>a.provider===t))==null?void 0:s.managementSchema)??Nn}function Rl(t){const s=new Date(t);return Number.isNaN(s.getTime())?t:s.toLocaleString(void 0,{month:"short",day:"numeric",hour:"2-digit",minute:"2-digit"})}function Al(t){const s=t.payload.details,a=typeof(s==null?void 0:s.stderr)=="string"&&s.stderr.trim()?s.stderr.trim():typeof(s==null?void 0:s.stdout)=="string"&&s.stdout.trim()?s.stdout.trim():null;return a?`${t.message}
2
+ ${a}`:t.message}function Ut(t){return{path:t,exists:!1,originalContent:"",draftContent:"",loading:!1,saving:!1,error:null,saveMessage:null}}const Il=/^\/devices\/([^/]+)(?:\/|$)/,Pl=/^(?:\/devices\/[^/]+)?\/threads\/([^/?#]+)(?:[/?#]|$)/;function kn(t){const s=Il.exec(t);return s?decodeURIComponent(s[1]??""):null}function at(){return typeof window>"u"?null:kn(window.location.pathname)}function Ll(t){const s=Pl.exec(t);return s?decodeURIComponent(s[1]??""):null}function Ol(){return typeof window>"u"?null:Ll(window.location.pathname)}function Gt(t,s){if(!s)return t;const a=t.startsWith("/")?t:`/${t}`;return`/devices/${encodeURIComponent(s)}${a}`}function Or(t){return Gt(t,at())}function ta(t,s){return Gt(`/threads/${encodeURIComponent(t)}`,s)}function Fe(t){return ta(t,at())}function Ul(t,s){const a=t?`?workspaceId=${encodeURIComponent(t)}`:"";return Gt(`/threads${a}`,s)}function Wt(t){return Ul(t,at())}function $l(t,s){const a=t?`?workspaceId=${encodeURIComponent(t)}`:"";return Gt(`/threads/new${a}`,s)}function xs(t){return $l(t,at())}function sa(t){return Gt("/workspaces",t)}function Ns(){return sa(at())}class ce extends Error{constructor(s,a){super(a.message),this.statusCode=s,this.payload=a}}const aa="remote-codex-auth-token",ra="remote-codex-relay-token",na="remote-codex-relay-admin-token",Sn="remote-codex-relay-mode",oa="remote-codex-relay-device-id",la="remote-codex-relay-thread-id",ia="remote-codex:hosted-vm-wake";function Ur(t){typeof window<"u"&&window.dispatchEvent(new CustomEvent(ia,{detail:t}))}function Dl(t,s){return new Promise((a,r)=>{const o=window.setTimeout(a,t);s==null||s.addEventListener("abort",()=>{window.clearTimeout(o),r(s.reason??new DOMException("Request aborted.","AbortError"))},{once:!0})})}function Cn(){return typeof window>"u"?null:window.localStorage.getItem(aa)}function Ml(t){if(!(typeof window>"u")){if(t){window.localStorage.setItem(aa,t);return}window.localStorage.removeItem(aa)}}function Tn(){return typeof window>"u"?null:window.localStorage.getItem(ra)}function _l(){return typeof window>"u"?null:window.localStorage.getItem(na)}function ha(t){if(!(typeof window>"u")){if(t){window.localStorage.setItem(ra,t);return}window.localStorage.removeItem(ra)}}function En(t){if(!(typeof window>"u")){if(t){window.localStorage.setItem(na,t);return}window.localStorage.removeItem(na)}}function Ct(){var t;return typeof window>"u"?!1:((t=window.__REMOTE_CODEX_BOOTSTRAP__)==null?void 0:t.mode)==="relay"||window.location.pathname.startsWith("/relay-portal")||window.location.pathname.startsWith("/relay-admin")||window.location.pathname.startsWith("/relay-account")||window.location.pathname.startsWith("/relay-devices")||window.location.pathname.startsWith("/relay-guide")||window.location.search.includes("relay=1")||window.localStorage.getItem(Sn)==="true"}function Ze(){typeof window>"u"||window.localStorage.setItem(Sn,"true")}function ht(){return Ct()}function Rn(){return typeof window>"u"?null:at()??window.localStorage.getItem(oa)}function ms(t){if(!(typeof window>"u")){if(t){window.localStorage.setItem(oa,t);return}window.localStorage.removeItem(oa)}}function Hl(){return typeof window>"u"?null:Ol()??window.localStorage.getItem(la)}function hs(t){if(!(typeof window>"u")){if(t){window.localStorage.setItem(la,t);return}window.localStorage.removeItem(la)}}function fa(t){if(!Ct())return t;if(t.startsWith("/api/")){const s=Rn();return s?`/relay/devices/${encodeURIComponent(s)}${t}`:`/relay${t}`}return t}function An(t){return fa(t)}function Bl(t){return t===400?"bad_request":t===401?"unauthorized":t===403?"forbidden":t===404?"not_found":t===409?"conflict":t===429||t===503?"service_unavailable":"internal_error"}function Wl(t,s){const a=s==null?void 0:s.trim(),r=a?`${t} ${a}`:`${t}`;return t===429?`Too many requests (${r}).`:t===503?`Upstream service unavailable (${r}).`:`Request failed (${r}).`}function jt(t,s,a){const r=typeof(s==null?void 0:s.message)=="string"&&s.message.trim()?s.message.trim():a,o=s!=null&&s.details&&typeof s.details=="object"?s.details:void 0;return{code:(s==null?void 0:s.code)??Bl(t.status),message:r,...o?{details:o}:{}}}async function In(t){var o,l;const s=Wl(t.status,t.statusText),a=((l=(o=t.headers)==null?void 0:o.get)==null?void 0:l.call(o,"content-type"))??"",r=async()=>jt(t,await t.json(),s);if(a.includes("application/json"))try{return await r()}catch{return jt(t,null,s)}try{if(typeof t.text!="function")try{return await r()}catch{return jt(t,null,s)}const d=(await t.text()).trim();if(d.startsWith("{"))try{return jt(t,JSON.parse(d),s)}catch{}return jt(t,d?{message:`${s}
3
+ ${d}`}:null,s)}catch{try{return await r()}catch{return jt(t,null,s)}}}async function A(t,s,a={}){var d;const r=new Headers(s==null?void 0:s.headers);(s==null?void 0:s.body)!==void 0&&!(s.body instanceof FormData)&&!r.has("Content-Type")&&r.set("Content-Type","application/json");const o=Ln({...s,headers:r},a.auth);let l=0;for(;;){const u=await fetch(fa(String(t)),o);if(u.ok)return l>0&&Ur({state:"connected",attempt:l}),await u.json();const p=await In(u);if(!(u.status===503&&((d=p.details)==null?void 0:d.reason)==="hosted_sandbox_starting")||l>=60)throw new ce(u.status,p);l+=1,Ur({state:"starting",attempt:l}),await Dl(1500,o.signal)}}function Fl(t){const s=String(t);return s.includes("/exports/pdf")?s.includes("format=html")?"remote-codex-transcript.html":"remote-codex-transcript.pdf":"download"}function ql(t){var o;if(!t)return null;const s=t.match(/filename\*=UTF-8''([^;]+)/i);if(s!=null&&s[1])try{return decodeURIComponent(s[1].trim())}catch{return s[1].trim()}const a=t.match(/filename="([^"]+)"/i);if(a!=null&&a[1])return a[1].trim();const r=t.match(/filename=([^;]+)/i);return((o=r==null?void 0:r[1])==null?void 0:o.trim())??null}async function Pn(t,s){const a=await fetch(fa(String(t)),Ln(s));if(!a.ok){const o=await In(a);throw new ce(a.status,o)}const r=ql(a.headers.get("content-disposition"))??Fl(t);return{blob:await a.blob(),filename:r}}function Ln(t={},s="default"){const a=new Headers(t.headers),r=Ct();if(s!=="none"&&!a.has("Authorization"))if(s==="relay-admin"){const o=_l();o&&a.set("Authorization",`Bearer ${o}`)}else{const o=Tn(),l=Cn();r&&o?a.set("Authorization",`Bearer ${o}`):!r&&l&&a.set("Authorization",`Bearer ${l}`)}return{...t,credentials:t.credentials??"same-origin",headers:a}}function $r(t,s){const a=t.originalName.trim();if(a)return a;const r=t.file.name.trim();return r||(t.kind==="photo"?`photo-${s+1}.jpg`:`file-${s+1}`)}function Vl(){return A("/api/config/runtime")}function Gl(){return A("/api/auth/session",{cache:"no-store"})}async function zl(t){const s=await A("/api/auth/login",{method:"POST",body:JSON.stringify(t)});return Ml(s.token??null),s}function Et(){return A("/relay/auth/session",{cache:"no-store"})}async function Jl(t){Ze();const s=await A("/relay/auth/login",{method:"POST",body:JSON.stringify(t)},{auth:"none"});return ha(s.token),s}function On(){return Ze(),A("/relay/auth/session",{cache:"no-store"},{auth:"relay-admin"})}async function Kl(t){Ze();const s=await A("/relay/auth/login",{method:"POST",body:JSON.stringify({identifier:t.username,password:t.password})},{auth:"none"});return En(s.token),s}async function Yl(){return En(null),On()}async function Xl(t){Ze();const s=await A("/relay/auth/register",{method:"POST",body:JSON.stringify(t)},{auth:"none"});return ha(s.token??null),s}async function Zl(){const t=await A("/relay/auth/logout",{method:"POST"});return ha(null),ms(null),hs(null),t}function Un(){return A("/relay/portal")}function Ql(t){const s=new URLSearchParams({deviceId:t.deviceId});return t.threadId&&s.set("threadId",t.threadId),t.workspaceId&&s.set("workspaceId",t.workspaceId),A(`/relay/access?${s.toString()}`)}function ei(t){return A("/relay/devices",{method:"POST",body:JSON.stringify(t)})}function ti(t){return A(`/relay/devices/${encodeURIComponent(t)}`,{method:"DELETE"})}function si(t){return A("/relay/account",{method:"PATCH",body:JSON.stringify(t)})}function ai(t){return A("/relay/account/password",{method:"PATCH",body:JSON.stringify(t)})}function ri(t){return A("/relay/shares",{method:"POST",body:JSON.stringify(t)})}function ni(t,s){return A(`/relay/shares/${encodeURIComponent(t)}`,{method:"PATCH",body:JSON.stringify(s)})}function $n(t){return A(`/relay/shares/${encodeURIComponent(t)}`,{method:"DELETE"})}function oi(t){return A("/relay/grants",{method:"POST",body:JSON.stringify(t)})}function li(t,s){return A(`/relay/grants/${encodeURIComponent(t)}`,{method:"PATCH",body:JSON.stringify(s)})}function ii(t){return A(`/relay/grants/${encodeURIComponent(t)}`,{method:"DELETE"})}function di(t){const s=t?`?days=${encodeURIComponent(String(t))}`:"";return A(`/relay/admin${s}`,void 0,{auth:"relay-admin"})}function ci(){return A("/relay/admin/hosted-sandboxes/capability",void 0,{auth:"relay-admin"})}function ui(){return A("/relay/admin/hosted-sandboxes",void 0,{auth:"relay-admin"})}function mi(){return A("/relay/admin/hosted-sandboxes/reconciliation",void 0,{auth:"relay-admin"})}function hi(){return A("/relay/admin/hosted-sandboxes/reconciliation/run",{method:"POST"},{auth:"relay-admin"})}function fi(t){return A(`/relay/admin/hosted-sandboxes/reconciliation/orphan-instances/${encodeURIComponent(t)}`,{method:"DELETE"},{auth:"relay-admin"})}function pi(t){return A(`/relay/admin/hosted-sandboxes/reconciliation/orphan-credentials/${encodeURIComponent(t)}`,{method:"DELETE"},{auth:"relay-admin"})}function xi(t){return A("/relay/admin/hosted-sandboxes",{method:"POST",body:JSON.stringify(t)},{auth:"relay-admin"})}function Dr(t,s){return A(`/relay/admin/hosted-sandboxes/${encodeURIComponent(t)}/members`,{method:"PUT",body:JSON.stringify({assignedUserIds:s})},{auth:"relay-admin"})}function gi(t,s){return A(`/relay/admin/hosted-sandboxes/${encodeURIComponent(t)}/settings`,{method:"PATCH",body:JSON.stringify(s)},{auth:"relay-admin"})}function Mr(t,s){return A(`/relay/admin/hosted-sandboxes/${encodeURIComponent(t)}/${s}`,{method:"POST"},{auth:"relay-admin"})}function vi(t,s){return A(`/relay/admin/hosted-sandboxes/${encodeURIComponent(t)}/snapshots`,{method:"POST",body:JSON.stringify({name:s})},{auth:"relay-admin"})}function bi(t){return A(`/relay/admin/hosted-sandboxes/${encodeURIComponent(t)}/backends/codex/files`,void 0,{auth:"relay-admin"})}function yi(t,s){return A(`/relay/admin/hosted-sandboxes/${encodeURIComponent(t)}/backends/codex/files`,{method:"PUT",body:JSON.stringify(s)},{auth:"relay-admin"})}function wi(t){return A(`/relay/admin/hosted-sandboxes/${encodeURIComponent(t)}`,{method:"DELETE"},{auth:"relay-admin"})}function ji(t){return A("/relay/admin/settings/registration",{method:"PATCH",body:JSON.stringify(t)},{auth:"relay-admin"})}function Ni(t,s){return A(`/relay/admin/users/${encodeURIComponent(t)}`,{method:"PATCH",body:JSON.stringify({enabled:s})},{auth:"relay-admin"})}function ki(t){return A(`/relay/admin/users/${encodeURIComponent(t)}`,{method:"DELETE"},{auth:"relay-admin"})}function Si(t,s){return A(`/relay/admin/users/${encodeURIComponent(t)}/reset-password`,{method:"POST",body:JSON.stringify({password:s})},{auth:"relay-admin"})}function Ci(t){return A(`/relay/admin/registrations/${encodeURIComponent(t)}/approve`,{method:"POST"},{auth:"relay-admin"})}function Ti(t){return A(`/relay/admin/registrations/${encodeURIComponent(t)}/reject`,{method:"POST"},{auth:"relay-admin"})}function Dn(){return A("/api/config/workspace-settings",{cache:"no-store"})}function Ei(t){return A("/api/config/workspace-settings",{method:"PATCH",body:JSON.stringify(t)})}function Tt(){return A("/api/agent-runtimes",{cache:"no-store"})}function Mn(t){return A(`/api/agent-runtimes/${encodeURIComponent(t)}/status`,{cache:"no-store"})}function Ri(t){return A(`/api/agent-runtimes/${encodeURIComponent(t)}/subscription-usage`,{cache:"no-store"})}function Ai(t){return A(`/api/agent-runtimes/${encodeURIComponent(t)}/restart`,{method:"POST"})}function da(t,s,a){return A(`/api/agent-runtimes/${encodeURIComponent(t)}/install`,{method:"POST",body:JSON.stringify({action:s,...a?{modelId:a}:{}})})}function ca(t){return pa(t)}function pa(t,s={}){const a=new URLSearchParams;s.agentId&&a.set("agentId",s.agentId),s.cwd&&a.set("cwd",s.cwd);const r=a.size>0?`?${a.toString()}`:"";return A(`/api/agent-runtimes/${encodeURIComponent(t)}/models${r}`,{cache:"no-store"})}function _t(t){return A(`/api/agent-runtimes/${encodeURIComponent(t)}/agents`,{cache:"no-store"})}function Ii(t,s){return A(`/api/agent-runtimes/${encodeURIComponent(t)}/capabilities?agentId=${encodeURIComponent(s)}`,{cache:"no-store"})}function _n(t,s){return A(`/api/config/providers/${encodeURIComponent(t)}/files/${encodeURIComponent(s)}`,{cache:"no-store"})}function Hn(t,s,a){return A(`/api/config/providers/${encodeURIComponent(t)}/files/${encodeURIComponent(s)}`,{method:"PATCH",body:JSON.stringify(a)})}function Pi(t){return A(`/api/config/providers/${encodeURIComponent(t)}/archives`,{cache:"no-store"})}function Li(t,s={}){return A(`/api/config/providers/${encodeURIComponent(t)}/archives`,{method:"POST",body:JSON.stringify(s)})}function Oi(t,s,a){return A(`/api/config/providers/${encodeURIComponent(t)}/archives/${encodeURIComponent(s)}`,{method:"PATCH",body:JSON.stringify(a)})}function Ui(t,s){return A(`/api/config/providers/${encodeURIComponent(t)}/archives/${encodeURIComponent(s)}/apply`,{method:"POST"})}function $i(){return A("/api/service/build-restart",{method:"POST"})}function Di(){return A("/healthz",{cache:"no-store"})}function xa(){return A("/api/workspaces")}function Mi(t,s={}){const a=new URLSearchParams;s.path&&a.set("path",s.path);const r=a.size>0?`?${a.toString()}`:"";return A(`/api/workspaces/${encodeURIComponent(t)}/files/tree${r}`,{cache:"no-store"})}function _i(t,s){const a=new URLSearchParams({path:s.path});return s.offset!==void 0&&a.set("offset",String(s.offset)),s.limit!==void 0&&a.set("limit",String(s.limit)),A(`/api/workspaces/${encodeURIComponent(t)}/files/preview?${a.toString()}`,{cache:"no-store"})}function Hi(t,s){const a=new URLSearchParams({path:s.path});return An(`/api/workspaces/${encodeURIComponent(t)}/files/raw?${a.toString()}`)}function Bi(t,s){const a=new URLSearchParams({path:s.path});return An(`/api/threads/${encodeURIComponent(t)}/assets/image?${a.toString()}`)}function Wi(t,s){const a=new URLSearchParams({path:s.path});return Pn(`/api/workspaces/${encodeURIComponent(t)}/files/download?${a.toString()}`,{cache:"no-store"})}function Fi(t,s){const a=new FormData;return a.append("file",s.file,s.file.name),A(`/api/workspaces/${encodeURIComponent(t)}/files/upload`,{method:"POST",body:a})}function qi(t,s){return A(`/api/workspaces/${encodeURIComponent(t)}/files`,{method:"PUT",body:JSON.stringify(s)})}function ga(){return A("/api/threads")}function _r(t,s={}){const a=new URLSearchParams;return s.limit!==void 0&&a.set("limit",String(s.limit)),s.beforeTurnId&&a.set("beforeTurnId",s.beforeTurnId),A(`/api/threads/${t}${a.size>0?`?${a.toString()}`:""}`)}function Vi(t,s){return A(`/api/threads/${t}/items/${encodeURIComponent(s)}/detail`)}function Gi(){return A("/api/plugins",{cache:"no-store"})}function zi(t){return A("/api/plugins/import",{method:"POST",body:JSON.stringify(t)})}function Ji(t,s){return A(`/api/plugins/${encodeURIComponent(t)}`,{method:"PATCH",body:JSON.stringify(s)})}function Ki(t){return A(`/api/plugins/${encodeURIComponent(t)}`,{method:"DELETE"})}function Yi(t){return A(`/api/threads/${t}/export-turns`,{cache:"no-store"})}function Xi(t,s){var r,o,l;const a=new URLSearchParams;return s.format!==void 0&&a.set("format",s.format),a.set("mode",s.mode),s.limit!==void 0&&a.set("limit",String(s.limit)),s.turnIds!==void 0&&a.set("turnIds",s.turnIds.join(",")),s.profile!==void 0&&a.set("profile",s.profile),((r=s.options)==null?void 0:r.includeTokenAndPrice)!==void 0&&a.set("includeTokenAndPrice",String(s.options.includeTokenAndPrice)),((o=s.options)==null?void 0:o.includeCommandOutput)!==void 0&&a.set("includeCommandOutput",String(s.options.includeCommandOutput)),((l=s.options)==null?void 0:l.includeAbsolutePaths)!==void 0&&a.set("includeAbsolutePaths",String(s.options.includeAbsolutePaths)),`/api/threads/${encodeURIComponent(t)}/exports/pdf?${a.toString()}`}function Zi(t,s){return Pn(Xi(t,s),{cache:"no-store"})}function Qi(t){return A(`/api/threads/${t}/shell`)}function ed(t){return A("/api/threads/start",{method:"POST",body:JSON.stringify(t)})}function td(t){return A("/api/threads/import",{method:"POST",body:JSON.stringify(typeof t=="string"?{sessionId:t}:t)})}function sd(t,s){const a=new URLSearchParams({provider:t});return s&&a.set("agentId",s),A(`/api/threads/import-candidates?${a.toString()}`)}function ad(t,s={}){return A(`/api/threads/${t}/shell`,{method:"POST",...Object.keys(s).length>0?{body:JSON.stringify(s)}:{}})}function rd(t){return A(`/api/shells/${t}/terminate`,{method:"POST"})}function nd(t,s){return A(`/api/shells/${t}`,{method:"PATCH",body:JSON.stringify(s)})}function Hs(t,s={}){return A(`/api/threads/${t}/resume`,{method:"POST",...Object.keys(s).length>0?{body:JSON.stringify(s)}:{}})}function od(t){return A(`/api/threads/${t}/disconnect`,{method:"POST"})}function ld(t,s){const a=s.attachments??[];if(a.length===0)return A(`/api/threads/${t}/prompt`,{method:"POST",body:JSON.stringify(s)});const r=new FormData;r.append("prompt",s.prompt),s.clientRequestId!==void 0&&r.append("clientRequestId",s.clientRequestId),s.model!==void 0&&r.append("model",s.model),s.reasoningEffort!==void 0&&s.reasoningEffort!==null&&r.append("reasoningEffort",s.reasoningEffort),s.collaborationMode!==void 0&&r.append("collaborationMode",s.collaborationMode);const o=a.map((l,d)=>({clientId:l.clientId,kind:l.kind,originalName:$r(l,d),placeholder:l.placeholder}));r.append("attachmentManifest",JSON.stringify(o));for(const[l,d]of a.entries())r.append("attachments",d.file,$r(d,l));return A(`/api/threads/${t}/prompt`,{method:"POST",body:r})}function Hr(t,s={}){return A(`/api/threads/${t}/interrupt`,{method:"POST",body:JSON.stringify(s)})}function Bn(t,s){return A(`/api/threads/${t}`,{method:"PATCH",body:JSON.stringify(s)})}function Wn(t){return A(`/api/threads/${t}`,{method:"DELETE"})}function id(t,s){return A(`/api/threads/${t}/pending-steers/${encodeURIComponent(s)}`,{method:"DELETE"})}function dd(t,s){return A(`/api/threads/${t}/pending-steers/${encodeURIComponent(s)}/steer`,{method:"POST"})}function cd(t,s){return A(`/api/threads/${t}/settings`,{method:"PATCH",body:JSON.stringify(s)})}function ud(t){return A(`/api/threads/${t}/compact`,{method:"POST"})}function md(t){return A(`/api/threads/${t}/goal`,{cache:"no-store"})}function hd(t,s){return A(`/api/threads/${t}/goal`,{method:"PATCH",body:JSON.stringify(s)})}function fd(t){return A(`/api/threads/${t}/goal`,{method:"DELETE"})}function pd(t){return A(`/api/threads/${t}/fork-turns`,{cache:"no-store"})}function Br(t,s){return A(`/api/threads/${t}/fork`,{method:"POST",body:JSON.stringify(s)})}function xd(t){return A(`/api/threads/${t}/skills`,{cache:"no-store"})}function gd(t){return A(`/api/threads/${t}/mcp-servers`,{cache:"no-store"})}function vd(t){return A(`/api/threads/${t}/hooks`,{cache:"no-store"})}function bd(t,s){return A(`/api/threads/${t}/hooks`,{method:"POST",body:JSON.stringify(s)})}function yd(t,s){return A(`/api/threads/${t}/hooks`,{method:"PUT",body:JSON.stringify(s)})}function wd(t,s){return A(`/api/threads/${t}/hooks/trust`,{method:"POST",body:JSON.stringify(s)})}function jd(t,s){return A(`/api/threads/${t}/hooks/untrust`,{method:"POST",body:JSON.stringify(s)})}function Nd(t,s,a){return A(`/api/threads/${t}/requests/${encodeURIComponent(s)}/respond`,{method:"POST",body:JSON.stringify(a)})}function kd(t){return A("/api/workspaces",{method:"POST",body:JSON.stringify(t)})}function Sd(t,s){return A(`/api/workspaces/${t}`,{method:"PATCH",body:JSON.stringify(s)})}function Cd(t,s){return A(`/api/workspaces/${t}`,{method:"DELETE",body:JSON.stringify(s)})}function Td(t,s){return A(`/api/workspaces/${t}/favorite`,{method:"POST",body:JSON.stringify(s)})}function Fn(t){const s=window.location.protocol==="https:"?"wss:":"ws:",a=new WebSocket(qn(s));return a.addEventListener("message",r=>{try{const o=JSON.parse(r.data);Rd(o)&&t(o)}catch{}}),a}function Ed(t={}){const s=window.location.protocol==="https:"?"wss:":"ws:",a=new WebSocket(qn(s));return a.addEventListener("message",r=>{var o,l;try{const d=JSON.parse(r.data);if(d.type==="supervisor.connected"){(o=t.onConnected)==null||o.call(t,d);return}Ad(d)&&((l=t.onShellEvent)==null||l.call(t,d))}catch{}}),{socket:a,send(r){a.send(JSON.stringify(r))}}}function qn(t){const s=new URL(`${t}//${window.location.host}/ws`);if(Ct()){const l=Rn();s.pathname=l?`/relay/devices/${encodeURIComponent(l)}/ws`:"/relay/ws"}const a=Cn(),r=Tn(),o=Hl();return Ct()&&r&&s.searchParams.set("relaySession",r),Ct()&&o&&s.searchParams.set("threadId",o),a&&s.searchParams.set("token",a),s.toString()}function Rd(t){return"threadId"in t&&t.type.startsWith("thread.")&&typeof t.payload=="object"&&t.payload!==null}function Ad(t){return"shellId"in t&&t.type.startsWith("shell.")&&typeof t.payload=="object"&&t.payload!==null}function Bs(t){if(!t||typeof t!="object")return null;const s=t;return s.available===!1&&typeof s.unavailableReason=="string"?s.unavailableReason:null}function va({embedded:t=!1}={}){const s=Vt(),a=yn(),[r,o]=n.useState(""),[l,d]=n.useState({busy:!1,message:null,error:null}),[u,p]=n.useState(!1),[g,b]=n.useState(null),[x,N]=n.useState({}),v=g?x[g]:null,[c,h]=n.useState({busy:!1,message:null,error:null}),[D,H]=n.useState([]),[O,E]=n.useState(St),[U,G]=n.useState({loading:!1,saving:!1,error:null,operatingProvider:null,operatingAction:null,message:null}),[te,Q]=n.useState(null),[I,se]=n.useState({devHomeDraft:"",loading:!1,saving:!1,message:null,error:null}),[J,ee]=n.useState({loading:!1,creating:!1,applyingId:null,renamingId:null,renameDraft:"",message:null,error:null}),i=(s==null?void 0:s.themeMode)??"system",W=t||!!(s!=null&&s.settingsOpen);async function fe(){const f=r.trim();if(!(!f||l.busy)){d({busy:!0,message:null,error:null});try{await a.importPluginManifest({manifestJson:f,enabled:!0}),o(""),d({busy:!1,message:"Plugin manifest imported.",error:null})}catch(j){d({busy:!1,message:null,error:j instanceof Error?j.message:"Unable to import plugin manifest."})}}}const ae=(s==null?void 0:s.effectiveTheme)??"dark",we=(s==null?void 0:s.autoCollapseCompletedTurns)??!0,ge=(s==null?void 0:s.defaultBackend)??wn,Ne=a.plugins.filter(f=>f.enabled).length,K=a.loading?"Loading...":`${Ne}/${a.plugins.length} enabled`,M=O.find(f=>f.provider===ge)??St.find(f=>f.provider===ge)??St[0],ne=M.managementSchema??El(M.provider),P=ne.hostConfigFiles;n.useEffect(()=>{if(!W||t||!s||!ne.configArchives)return;const f=s;function j($){$.key==="Escape"&&f.closeSettings()}return window.addEventListener("keydown",j),()=>{window.removeEventListener("keydown",j)}},[ne.configArchives,t,W,s]),n.useEffect(()=>{if(!W)return;let f=!1;return G(j=>({...j,loading:!0,error:null})),Tt().then(j=>{if(f)return;const $=[...j.map(_s),...St.filter(re=>!j.some(je=>je.provider===re.provider))];E($),G(re=>({...re,loading:!1}))}).catch(j=>{f||(E(St),G($=>({...$,loading:!1,error:j instanceof ce?j.message:"Unable to load backend settings."})))}),()=>{f=!0}},[W]),n.useEffect(()=>{if(!W)return;let f=!1;return se(j=>({...j,loading:!0,message:null,error:null})),Dn().then(j=>{f||(Q(j),se($=>({...$,devHomeDraft:j.devHome,loading:!1})))}).catch(j=>{f||se($=>({...$,loading:!1,error:j instanceof ce?j.message:"Unable to load workspace settings."}))}),()=>{f=!0}},[W]),n.useEffect(()=>{if(!W||!M.capabilities.management.hostConfigFiles)return;let f=!1;async function j(){N(re=>{const je={...re};for(const Ue of P)je[Ue.name]={...Ut(Ue.name),...re[Ue.name],loading:!0,saving:!1,error:null,saveMessage:null};return je});const $=await Promise.allSettled(P.map(async re=>({name:re.name,result:await _n(M.provider,re.name)})));f||N(re=>{var Ue,ze;const je={...re};for(const S of $){if(S.status==="fulfilled"){const{name:ye,result:ke}=S.value;je[ye]={path:ke.path,exists:ke.exists,originalContent:ke.content,draftContent:ke.content,loading:!1,saving:!1,error:null,saveMessage:null};continue}const R=S.reason instanceof ce?S.reason.message:"Unable to load the file.",oe=((Ue=P[$.indexOf(S)])==null?void 0:Ue.name)??((ze=P[0])==null?void 0:ze.name);oe&&(je[oe]={...Ut(oe),...je[oe],loading:!1,saving:!1,error:R,saveMessage:null})}return je})}return j(),()=>{f=!0}},[M.capabilities.management.hostConfigFiles,M.provider,P,W]),n.useEffect(()=>{if(!W)return;let f=!1;async function j(){ee($=>({...$,loading:!0,error:null,message:null}));try{const $=await Pi(M.provider);if(f)return;H($),ee(re=>({...re,loading:!1}))}catch($){if(f)return;ee(re=>({...re,loading:!1,error:$ instanceof ce?$.message:"Unable to load config archives."}))}}return j(),()=>{f=!0}},[M.provider,ne.configArchives,W]);async function V(){if(!(c.busy||U.saving)){h({busy:!0,message:null,error:null});try{const f=await Ai(M.provider),j=_s(f);h({busy:!1,message:j.status.state==="ready"?`${j.displayName} backend restarted.`:`${j.displayName} backend state: ${j.status.state}`,error:null}),E($=>$.map(re=>re.provider===j.provider?j:re))}catch(f){h({busy:!1,message:null,error:f instanceof ce?f.message:"Unable to restart the app server."})}}}async function Y(f,j){if(c.busy||U.saving)return;const $=O.find(re=>re.provider===f);G(re=>({...re,saving:!0,operatingProvider:f,operatingAction:j,message:null,error:null}));try{const re=await da(f,j),je=_s(re);E(Ue=>Ue.map(ze=>ze.provider===je.provider?je:ze)),G(Ue=>({...Ue,saving:!1,operatingProvider:null,operatingAction:null,message:je.installation.lastError?`${je.displayName} ${j==="install"?"installed":"updated"}, but requires attention:
4
+ ${je.installation.lastError}`:`${je.displayName} ${j==="install"?"installed":"updated"}.`,error:null}))}catch(re){G(je=>({...je,saving:!1,operatingProvider:null,operatingAction:null,message:null,error:re instanceof ce?Al(re):`Unable to ${j} ${($==null?void 0:$.displayName)??f}.`}))}}async function Ce(){if(!(c.busy||U.saving)){h({busy:!0,message:null,error:null});try{await $i(),h({busy:!1,message:"Build and restart launched. The page may disconnect briefly.",error:null})}catch(f){h({busy:!1,message:null,error:f instanceof ce?f.message:"Unable to launch build and restart."})}}}async function De(){const f=I.devHomeDraft.trim();if(!(!f||I.saving)){se(j=>({...j,saving:!0,message:null,error:null}));try{const j=await Ei({devHome:f});Q(j),se($=>({...$,devHomeDraft:j.devHome,saving:!1,message:"Workspace defaults saved."}))}catch(j){se($=>({...$,saving:!1,error:j instanceof ce?j.message:"Unable to save workspace settings."}))}}}async function qe(f){const j=x[f];if(!(!j||j.saving)){N($=>({...$,[f]:{...Ut(f),...$[f],saving:!0,error:null,saveMessage:null}}));try{const $=await Hn(M.provider,f,{content:j.draftContent});N(re=>({...re,[f]:{path:$.path,exists:$.exists,originalContent:$.content,draftContent:$.content,loading:!1,saving:!1,error:null,saveMessage:"Saved"}}))}catch($){N(re=>({...re,[f]:{...Ut(f),...re[f],saving:!1,error:$ instanceof ce?$.message:"Unable to save the file.",saveMessage:null}}))}}}async function be(){if(!J.creating){ee(f=>({...f,creating:!0,message:null,error:null}));try{const f=await Li(M.provider);H(j=>[f,...j]),ee(j=>({...j,creating:!1,message:"Backup created."}))}catch(f){ee(j=>({...j,creating:!1,error:f instanceof ce?f.message:"Unable to create a config backup."}))}}}async function B(f){if(!J.applyingId){ee(j=>({...j,applyingId:f.id,message:null,error:null}));try{const j=await Ui(M.provider,f.id);ee($=>({...$,applyingId:null,message:j.status.state==="ready"?`Applied "${j.archive.label}" and restarted ${M.displayName}.`:`Applied "${j.archive.label}". ${M.displayName} state: ${j.status.state}.`}))}catch(j){ee($=>({...$,applyingId:null,error:j instanceof ce?j.message:"Unable to apply the config archive."}))}}}async function L(f){const j=J.renameDraft.trim();if(!(!j||J.renamingId!==f.id)){ee($=>({...$,message:null,error:null}));try{const $=await Oi(M.provider,f.id,{label:j});H(re=>re.map(je=>je.id===f.id?$:je)),ee(re=>({...re,renamingId:null,renameDraft:"",message:"Backup renamed."}))}catch($){ee(re=>({...re,error:$ instanceof ce?$.message:"Unable to rename the config backup."}))}}}if(!W)return null;const le=e.jsxs(e.Fragment,{children:[e.jsxs("div",{className:"mt-3 grid gap-2",children:[a.plugins.map(f=>e.jsxs("label",{className:"flex items-start justify-between gap-3 rounded-[1rem] border border-[var(--theme-border)] bg-[var(--theme-surface-strong)] px-3 py-2.5",children:[e.jsxs("span",{className:"min-w-0",children:[e.jsx("span",{className:"block text-sm font-medium text-[var(--theme-fg)]",children:f.name}),e.jsx("span",{className:"mt-1 block text-xs leading-5 text-[var(--theme-fg-muted)]",children:f.description}),e.jsx("span",{className:"mt-2 block text-[10px] uppercase tracking-[0.16em] text-[var(--theme-fg-muted)]",children:[...f.capabilities.artifactTypes.map(j=>j.type),...f.capabilities.threadPanels.map(j=>j.kind??j.id)].join(", ")||"utility"}),e.jsx("span",{className:"mt-1 block text-[10px] uppercase tracking-[0.16em] text-[var(--theme-fg-muted)]",children:f.source==="imported"?"Imported manifest":"Built-in module"}),Bs(f)?e.jsx("span",{className:"mt-1 block text-xs leading-5 text-amber-300",children:Bs(f)}):null]}),e.jsx("input",{type:"checkbox",checked:f.enabled,disabled:Bs(f)!==null,"aria-label":`${f.name} enabled`,onChange:j=>void a.setPluginEnabled(f.id,j.currentTarget.checked),className:"mt-1 h-4 w-4 shrink-0 accent-[var(--theme-accent-solid)] disabled:cursor-not-allowed disabled:opacity-50"})]},f.id)),a.plugins.length===0&&e.jsx("p",{className:"rounded-[1rem] border border-[var(--theme-border)] bg-[var(--theme-surface-strong)] px-3 py-3 text-xs text-[var(--theme-fg-muted)]",children:"No plugins are registered."})]}),e.jsxs("div",{className:"mt-3 border-t border-[var(--theme-border)] pt-3",children:[e.jsx("label",{className:"block text-xs font-medium text-[var(--theme-fg)]",children:"Import manifest JSON"}),e.jsx("textarea",{value:r,onChange:f=>{o(f.currentTarget.value),(l.message||l.error)&&d({busy:!1,message:null,error:null})},placeholder:'{"id":"example.viewer","name":"Example Viewer","version":"0.1.0",...}',rows:4,className:"mt-2 min-h-28 w-full resize-y rounded-[0.9rem] border border-[var(--theme-border)] bg-[var(--theme-surface-strong)] px-3 py-2 font-mono text-xs leading-5 text-[var(--theme-fg)] outline-none transition placeholder:text-[var(--theme-fg-muted)] focus:border-[var(--theme-accent-border)]"}),e.jsxs("div",{className:"mt-2 flex flex-wrap items-center justify-between gap-2",children:[e.jsx("p",{className:"max-w-[42rem] text-xs leading-5 text-[var(--theme-fg-muted)]",children:"Imports register manifest-declared artifact types. Rendering code still needs a trusted built-in frontend module."}),e.jsx("button",{type:"button",onClick:()=>void fe(),disabled:!r.trim()||l.busy,className:"rounded-full border border-[var(--theme-accent-border)] bg-[var(--theme-accent-soft)] px-3 py-1.5 text-xs font-medium text-[var(--theme-accent-strong)] transition hover:bg-[var(--theme-hover)] disabled:cursor-not-allowed disabled:border-[var(--theme-border)] disabled:bg-[var(--theme-muted)] disabled:text-[var(--theme-fg-muted)]",children:l.busy?"Importing...":"Import"})]}),l.error&&e.jsx("p",{className:"mt-2 text-xs text-rose-300",children:l.error}),l.message&&e.jsx("p",{className:"mt-2 text-xs text-emerald-300",children:l.message})]}),a.error&&e.jsx("p",{className:"mt-2 text-xs text-rose-300",children:a.error})]}),T=e.jsxs(e.Fragment,{children:[t?null:e.jsx("div",{className:"shrink-0 p-5 pb-0",children:e.jsxs("div",{className:"flex items-start justify-between gap-3",children:[e.jsxs("div",{children:[e.jsx("p",{className:"text-xs uppercase tracking-[0.24em] text-[var(--theme-fg-muted)]",children:"Settings"}),e.jsx("h2",{className:"mt-2 text-xl font-semibold text-[var(--theme-fg)]",children:"Settings"}),e.jsx("p",{className:"mt-2 text-sm leading-6 text-[var(--theme-fg-soft)]",children:"Choose the default backend and manage host-side runtime files."})]}),e.jsx("button",{type:"button","aria-label":"Close Settings",onClick:s==null?void 0:s.closeSettings,className:"inline-flex h-9 w-9 items-center justify-center rounded-full border border-[var(--theme-border-strong)] bg-[var(--theme-surface-strong)] text-[var(--theme-fg)] transition hover:border-[var(--theme-border-contrast)] hover:bg-[var(--theme-hover)]",children:e.jsx(Ms,{})})]})}),e.jsx("div",{className:`min-h-0 flex-1 overflow-y-auto ${t?"p-0":"p-5 pt-5"}`,children:e.jsxs("div",{className:"space-y-2",children:[t?null:e.jsxs("div",{className:"rounded-[1.1rem] border border-[var(--theme-border)] bg-[var(--theme-surface)] px-3 py-3",children:[e.jsx("div",{className:"flex items-start justify-between gap-3",children:e.jsxs("div",{className:"min-w-0",children:[e.jsx("p",{className:"text-sm font-medium text-[var(--theme-fg)]",children:"Appearance"}),e.jsxs("p",{className:"mt-1 text-xs leading-5 text-[var(--theme-fg-muted)]",children:["Choose light, dark, or follow the system setting. Active:"," ",ae,"."]})]})}),e.jsx("div",{className:"mt-3 grid gap-2 sm:grid-cols-3",children:Sl.map(f=>{const j=i===f.value;return e.jsxs("button",{type:"button",onClick:()=>s==null?void 0:s.setThemeMode(f.value),className:`block rounded-[1rem] border px-3 py-2.5 text-left transition ${j?"border-[var(--theme-accent-border)] bg-[var(--theme-accent-soft)]":"border-[var(--theme-border)] bg-[var(--theme-surface-strong)] hover:bg-[var(--theme-hover)]"}`,children:[e.jsxs("div",{className:"flex items-center justify-between gap-3",children:[e.jsx("span",{className:"text-sm font-medium text-[var(--theme-fg)]",children:f.label}),j?e.jsx("span",{className:"rounded-full border border-[var(--theme-accent-border)] bg-[var(--theme-accent-soft)] px-2 py-0.5 text-[10px] uppercase tracking-[0.18em] text-[var(--theme-accent-strong)]",children:"Active"}):null]}),e.jsx("p",{className:"mt-1 text-xs leading-5 text-[var(--theme-fg-muted)]",children:f.description})]},f.value)})})]}),s!=null&&s.setAutoCollapseCompletedTurns?e.jsx("div",{className:"rounded-[1.1rem] border border-[var(--theme-border)] bg-[var(--theme-surface)] px-3 py-3",children:e.jsxs("div",{className:"flex items-start justify-between gap-4",children:[e.jsxs("div",{className:"min-w-0",children:[e.jsx("p",{className:"text-sm font-medium text-[var(--theme-fg)]",children:"Thread timeline"}),e.jsx("p",{className:"mt-1 text-xs leading-5 text-[var(--theme-fg-muted)]",children:"Collapse completed turns into prompt, elapsed work, and final reply."})]}),e.jsxs("label",{className:"inline-flex min-h-10 shrink-0 items-center gap-2 text-xs font-medium text-[var(--theme-fg-soft)]",children:[e.jsx("input",{type:"checkbox",checked:we,onChange:f=>{var j;return(j=s.setAutoCollapseCompletedTurns)==null?void 0:j.call(s,f.currentTarget.checked)},className:"h-4 w-4 accent-[var(--theme-accent-solid)]"}),e.jsx("span",{children:"Auto collapse"})]})]})}):null,e.jsxs("div",{className:"rounded-[1.1rem] border border-[var(--theme-border)] bg-[var(--theme-surface)] px-3 py-3",children:[e.jsxs("div",{className:"flex items-start justify-between gap-3",children:[e.jsxs("div",{className:"min-w-0",children:[e.jsx("p",{className:"text-sm font-medium text-[var(--theme-fg)]",children:"Plugins"}),e.jsx("p",{className:"mt-1 text-xs leading-5 text-[var(--theme-fg-muted)]",children:"Enable renderers and thread extensions loaded by this supervisor."})]}),e.jsx("button",{type:"button",onClick:()=>void a.refresh(),disabled:a.loading,className:"rounded-full border border-[var(--theme-border)] bg-[var(--theme-surface-strong)] px-3 py-1.5 text-xs font-medium text-[var(--theme-fg)] transition hover:bg-[var(--theme-hover)] disabled:cursor-not-allowed disabled:text-[var(--theme-fg-muted)]",children:a.loading?"Loading...":"Refresh"})]}),t?e.jsxs("div",{className:"mt-3 flex flex-wrap items-center justify-between gap-2 rounded-[0.95rem] border border-[var(--theme-border)] bg-[var(--theme-surface-strong)] px-3 py-2",children:[e.jsx("span",{className:"text-xs text-[var(--theme-fg-muted)]",children:K}),e.jsx("button",{type:"button",onClick:()=>p(!0),className:"rounded-full border border-[var(--theme-border-strong)] bg-[var(--theme-panel)] px-3 py-1.5 text-xs font-medium text-[var(--theme-fg)] transition hover:bg-[var(--theme-hover)]",children:"Manage"})]}):le]}),e.jsxs("div",{className:"rounded-[1.1rem] border border-[var(--theme-border)] bg-[var(--theme-surface)] px-3 py-3",children:[e.jsx("div",{className:"flex items-start justify-between gap-3",children:e.jsxs("div",{className:"min-w-0",children:[e.jsx("p",{className:"text-sm font-medium text-[var(--theme-fg)]",children:"Workspace defaults"}),e.jsx("p",{className:"mt-1 text-xs leading-5 text-[var(--theme-fg-muted)]",children:"Git projects clone into dev home. New workspace directories can create one missing child under this path."})]})}),e.jsxs("div",{className:"mt-3 grid gap-3",children:[e.jsxs("div",{children:[e.jsx("p",{className:"text-[11px] uppercase tracking-[0.18em] text-[var(--theme-fg-muted)]",children:"Workspace root"}),e.jsx("p",{title:(te==null?void 0:te.workspaceRoot)??"Loading workspace root",className:"mt-1 truncate rounded-[0.9rem] border border-[var(--theme-border)] bg-[var(--theme-surface-strong)] px-3 py-2 font-mono text-xs text-[var(--theme-fg-soft)]",children:I.loading&&!te?"Loading...":(te==null?void 0:te.workspaceRoot)??"Unavailable"})]}),e.jsxs("div",{children:[e.jsx("label",{htmlFor:"settings-dev-home",className:"text-[11px] uppercase tracking-[0.18em] text-[var(--theme-fg-muted)]",children:"Dev home"}),e.jsxs("div",{className:"mt-1 flex flex-col gap-2 sm:flex-row",children:[e.jsx("input",{id:"settings-dev-home",value:I.devHomeDraft,onChange:f=>se(j=>({...j,devHomeDraft:f.target.value,message:null,error:null})),placeholder:"/Users/name/dev",className:"min-w-0 flex-1 rounded-full border border-[var(--theme-border)] bg-[var(--theme-panel)] px-3 py-2 text-sm text-[var(--theme-fg)] outline-none focus:border-[var(--theme-accent-border)]"}),e.jsx("button",{type:"button","aria-label":"Save workspace defaults",onClick:()=>void De(),disabled:I.loading||I.saving||!I.devHomeDraft.trim(),className:"rounded-full bg-[var(--theme-accent-solid)] px-4 py-2 text-xs font-medium text-[var(--theme-accent-solid-fg)] transition hover:bg-[var(--theme-accent-solid-hover)] disabled:cursor-not-allowed disabled:bg-[var(--theme-muted)] disabled:text-[var(--theme-fg-muted)]",children:I.saving?"Saving...":"Save"})]})]})]}),I.error?e.jsx("p",{className:"mt-2 text-xs text-rose-300",children:I.error}):I.message?e.jsx("p",{className:"mt-2 text-xs text-emerald-300",children:I.message}):null]}),e.jsxs("div",{className:"rounded-[1.1rem] border border-[var(--theme-border)] bg-[var(--theme-surface)] px-3 py-3",children:[e.jsxs("div",{className:"flex items-start justify-between gap-3",children:[e.jsxs("div",{className:"min-w-0",children:[e.jsx("p",{className:"text-sm font-medium text-[var(--theme-fg)]",children:"Runtime controls"}),e.jsx("p",{className:"mt-1 text-xs leading-5 text-[var(--theme-fg-muted)]",children:"Inspect installed backend versions, install optional runtimes, or restart the selected backend."})]}),e.jsxs("div",{className:"flex shrink-0 flex-wrap justify-end gap-2",children:[e.jsx("button",{type:"button",onClick:()=>void V(),disabled:c.busy||U.saving,className:"rounded-full border border-sky-400/35 bg-sky-400/10 px-3 py-1.5 text-xs font-medium text-sky-500 transition hover:bg-sky-400/16 disabled:cursor-not-allowed disabled:border-[var(--theme-border)] disabled:bg-[var(--theme-muted)] disabled:text-[var(--theme-fg-muted)]",children:c.busy?"Restarting...":"Restart"}),e.jsx("button",{type:"button",onClick:()=>void Ce(),disabled:c.busy||U.saving,className:"rounded-full border border-[var(--status-warning-border)] bg-[var(--status-warning-bg)] px-3 py-1.5 text-xs font-medium text-[var(--status-warning-fg)] transition hover:bg-[var(--theme-hover)] disabled:cursor-not-allowed disabled:border-[var(--theme-border)] disabled:bg-[var(--theme-muted)] disabled:text-[var(--theme-fg-muted)]",children:c.busy?"Working...":"Build and restart"})]})]}),e.jsx("div",{className:"mt-3 grid gap-2",children:O.map(f=>{const j=f.installation,$=!j.installed&&!!j.installCommand,re=j.installed&&!!j.updateCommand,je=U.saving&&U.operatingProvider===f.provider,Ue=$?"Install":"Update";return e.jsxs("div",{className:"flex flex-col gap-2 rounded-[0.95rem] border border-[var(--theme-border)] bg-[var(--theme-surface-strong)] px-3 py-2 sm:flex-row sm:items-center sm:justify-between",children:[e.jsxs("div",{className:"min-w-0",children:[e.jsxs("div",{className:"flex flex-wrap items-center gap-2",children:[e.jsx("span",{className:"text-sm font-medium text-[var(--theme-fg)]",children:f.displayName}),e.jsx("span",{className:`rounded-full border px-2 py-0.5 text-[10px] uppercase tracking-[0.16em] ${f.enabled?"border-emerald-400/35 bg-emerald-400/10 text-emerald-400":"border-[var(--theme-border)] bg-[var(--theme-muted)] text-[var(--theme-fg-muted)]"}`,children:f.enabled?f.provider==="acp"&&f.status.state!=="ready"?"Needs agent":"Ready":j.installed?f.status.state:"Not installed"})]}),e.jsxs("p",{className:"mt-1 truncate text-xs text-[var(--theme-fg-muted)]",children:["Version:"," ",j.installedVersion??(j.installed?"Installed":"Unavailable"),j.latestVersion?` · Latest: ${j.latestVersion}`:""]}),j.lastError?e.jsx("p",{className:"mt-1 line-clamp-2 text-xs text-rose-300",children:j.lastError}):null]}),$||re?e.jsx("button",{type:"button","aria-label":`${$?"Install":"Update"} ${f.displayName}`,onClick:()=>void Y(f.provider,$?"install":"update"),disabled:c.busy||U.saving||!$&&!re,className:"shrink-0 rounded-full border border-[var(--theme-border-strong)] bg-[var(--theme-panel)] px-3 py-1.5 text-xs font-medium text-[var(--theme-fg)] transition hover:bg-[var(--theme-hover)] disabled:cursor-not-allowed disabled:bg-[var(--theme-muted)] disabled:text-[var(--theme-fg-muted)]",children:je?U.operatingAction==="install"?"Installing...":"Updating...":Ue}):null]},f.provider)})}),c.error?e.jsx("p",{className:"mt-2 text-xs text-rose-300",children:c.error}):c.message?e.jsx("p",{className:"mt-2 text-xs text-emerald-300",children:c.message}):U.message?e.jsx("p",{className:`mt-2 whitespace-pre-line text-xs ${U.message.includes("requires attention")?"text-[var(--status-warning-fg)]":"text-emerald-300"}`,children:U.message}):U.error?e.jsx("p",{className:"mt-2 whitespace-pre-line text-xs text-rose-300",children:U.error}):null]}),e.jsxs("div",{className:"rounded-[1.1rem] border border-[var(--theme-border)] bg-[var(--theme-surface)] px-3 py-3",children:[e.jsx("div",{className:"flex items-start justify-between gap-3",children:e.jsxs("div",{className:"min-w-0",children:[e.jsx("p",{className:"text-sm font-medium text-[var(--theme-fg)]",children:"Provider host files"}),e.jsxs("p",{className:"mt-1 text-xs leading-5 text-[var(--theme-fg-muted)]",children:[M.displayName," exposes these editable files through its backend schema."]})]})}),e.jsxs("div",{className:"mt-3 grid gap-2 sm:grid-cols-2",children:[P.map(f=>{const j=x[f.name]??{path:f.name,exists:!1,originalContent:"",draftContent:"",loading:!1},$=j.draftContent!==j.originalContent;return e.jsx("button",{type:"button",onClick:()=>b(f.name),className:"block rounded-[1.1rem] border border-[var(--theme-border)] bg-[var(--theme-surface-strong)] px-3 py-3 text-left transition hover:bg-[var(--theme-hover)]",children:e.jsxs("div",{className:"flex items-start justify-between gap-3",children:[e.jsxs("div",{className:"min-w-0",children:[e.jsx("p",{className:"truncate text-sm font-medium text-[var(--theme-fg)]",children:f.label}),e.jsx("p",{className:"mt-1 text-xs leading-5 text-[var(--theme-fg-muted)]",children:f.description})]}),e.jsx("div",{className:"shrink-0",children:j.loading?e.jsx("span",{className:"text-[11px] uppercase tracking-[0.2em] text-[var(--theme-fg-muted)]",children:"Loading"}):$?e.jsx("span",{className:"rounded-full border border-[var(--theme-accent-border)] bg-[var(--theme-accent-soft)] px-2 py-0.5 text-[10px] uppercase tracking-[0.18em] text-[var(--theme-accent-strong)]",children:"Unsaved"}):j.exists?e.jsx("span",{className:"rounded-full border border-emerald-400/25 bg-emerald-400/10 px-2 py-0.5 text-[10px] uppercase tracking-[0.18em] text-emerald-600 dark:text-emerald-100",children:"Ready"}):e.jsx("span",{className:"rounded-full border border-sky-300/25 bg-sky-300/10 px-2 py-0.5 text-[10px] uppercase tracking-[0.18em] text-sky-600 dark:text-sky-100",children:"New"})})]})},f.name)}),P.length===0?e.jsx("p",{className:"rounded-[1rem] border border-[var(--theme-border)] bg-[var(--theme-surface-strong)] px-3 py-3 text-xs text-[var(--theme-fg-muted)]",children:"This backend does not expose editable host files."}):null]})]}),ne.configArchives?e.jsxs("div",{className:"rounded-[1.1rem] border border-[var(--theme-border)] bg-[var(--theme-surface)] px-3 py-3",children:[e.jsxs("div",{className:"flex items-start justify-between gap-3",children:[e.jsxs("div",{className:"min-w-0",children:[e.jsx("p",{className:"text-sm font-medium text-[var(--theme-fg)]",children:"Config archives"}),e.jsx("p",{className:"mt-1 text-xs leading-5 text-[var(--theme-fg-muted)]",children:"Backup the selected backend host files, then apply a saved archive with a backend restart."})]}),e.jsx("button",{type:"button",onClick:()=>void be(),disabled:J.creating,className:"shrink-0 rounded-full border border-[var(--theme-accent-border)] bg-[var(--theme-accent-soft)] px-3 py-1.5 text-xs font-medium text-[var(--theme-accent-strong)] transition hover:bg-[var(--theme-hover)] disabled:cursor-not-allowed disabled:border-[var(--theme-border)] disabled:bg-[var(--theme-muted)] disabled:text-[var(--theme-fg-muted)]",children:J.creating?"Creating...":"Create backup"})]}),J.error?e.jsx("p",{className:"mt-2 text-xs text-rose-300",children:J.error}):J.message?e.jsx("p",{className:"mt-2 text-xs text-emerald-300",children:J.message}):null,e.jsx("div",{className:"mt-3 space-y-2",children:J.loading?e.jsx("p",{className:"rounded-[1rem] border border-[var(--theme-border)] bg-[var(--theme-surface-strong)] px-3 py-3 text-xs text-[var(--theme-fg-muted)]",children:"Loading backups..."}):D.length===0?e.jsx("p",{className:"rounded-[1rem] border border-[var(--theme-border)] bg-[var(--theme-surface-strong)] px-3 py-3 text-xs text-[var(--theme-fg-muted)]",children:"No config backups yet."}):D.map(f=>{const j=J.renamingId===f.id;return e.jsx("div",{className:"rounded-[1.1rem] border border-[var(--theme-border)] bg-[var(--theme-surface-strong)] px-3 py-3",children:e.jsxs("div",{className:"flex flex-col gap-3 sm:flex-row sm:items-start sm:justify-between",children:[e.jsxs("div",{className:"min-w-0",children:[j?e.jsxs("div",{className:"flex max-w-xl gap-2",children:[e.jsx("input",{"aria-label":`Rename ${f.label}`,value:J.renameDraft,onChange:$=>ee(re=>({...re,renameDraft:$.target.value,error:null,message:null})),className:"min-w-0 flex-1 rounded-full border border-[var(--theme-border)] bg-[var(--theme-panel)] px-3 py-1.5 text-sm text-[var(--theme-fg)] outline-none focus:border-[var(--theme-accent-border)]"}),e.jsx("button",{type:"button","aria-label":`Save archive name ${f.label}`,onClick:()=>void L(f),className:"rounded-full bg-[var(--theme-accent-solid)] px-3 py-1.5 text-xs font-medium text-[var(--theme-accent-solid-fg)] transition hover:bg-[var(--theme-accent-solid-hover)]",children:"Save"}),e.jsx("button",{type:"button",onClick:()=>ee($=>({...$,renamingId:null,renameDraft:""})),className:"rounded-full border border-[var(--theme-border)] bg-[var(--theme-panel)] px-3 py-1.5 text-xs font-medium text-[var(--theme-fg)] transition hover:bg-[var(--theme-hover)]",children:"Cancel"})]}):e.jsx("p",{className:"truncate text-sm font-medium text-[var(--theme-fg)]",children:f.label}),e.jsxs("div",{className:"mt-2 flex flex-wrap items-center gap-2 text-[11px] text-[var(--theme-fg-muted)]",children:[e.jsxs("span",{children:["Created ",Rl(f.createdAt)]}),P.map($=>{var re;return e.jsxs("span",{className:"rounded-full border border-[var(--theme-border)] bg-[var(--theme-panel)] px-2 py-0.5 font-mono",children:[$.name,":"," ",(re=f.files[$.name])!=null&&re.exists?"saved":"missing"]},$.name)})]})]}),e.jsxs("div",{className:"flex shrink-0 flex-wrap gap-2",children:[e.jsx("button",{type:"button",onClick:()=>ee($=>({...$,renamingId:f.id,renameDraft:f.label,message:null,error:null})),disabled:j,className:"rounded-full border border-[var(--theme-border)] bg-[var(--theme-panel)] px-3 py-1.5 text-xs font-medium text-[var(--theme-fg)] transition hover:bg-[var(--theme-hover)] disabled:cursor-not-allowed disabled:text-[var(--theme-fg-muted)]",children:"Rename"}),e.jsx("button",{type:"button",onClick:()=>void B(f),disabled:J.applyingId!==null,className:"rounded-full border border-emerald-400/35 bg-emerald-400/10 px-3 py-1.5 text-xs font-medium text-emerald-600 transition hover:bg-emerald-400/16 disabled:cursor-not-allowed disabled:border-[var(--theme-border)] disabled:bg-[var(--theme-muted)] disabled:text-[var(--theme-fg-muted)] dark:text-emerald-100",children:J.applyingId===f.id?"Applying...":"Apply"})]})]})},f.id)})})]}):null]})})]});return t?e.jsxs("div",{className:"flex min-h-0 flex-col overflow-hidden",children:[T,u?e.jsxs("div",{className:"fixed inset-0 z-[90] flex items-start justify-center p-4 pt-[max(env(safe-area-inset-top),4rem)] sm:items-center sm:pt-4",children:[e.jsx("button",{type:"button","aria-label":"Close plugins panel",onClick:()=>p(!1),className:"ui-overlay-scrim absolute inset-0 backdrop-blur-[2px]"}),e.jsxs("section",{className:"relative z-10 flex max-h-[min(82vh,42rem)] w-full max-w-2xl flex-col overflow-hidden rounded-lg border border-[var(--theme-border)] bg-[var(--theme-panel)] shadow-[var(--theme-shadow)]",children:[e.jsxs("div",{className:"flex items-center justify-between gap-3 border-b border-[var(--theme-border)] px-4 py-3",children:[e.jsxs("div",{className:"min-w-0",children:[e.jsx("p",{className:"text-sm font-medium text-[var(--theme-fg)]",children:"Plugins"}),e.jsx("p",{className:"mt-1 text-xs text-[var(--theme-fg-muted)]",children:K})]}),e.jsxs("div",{className:"flex shrink-0 items-center gap-2",children:[e.jsx("button",{type:"button",onClick:()=>void a.refresh(),disabled:a.loading,className:"rounded-md border border-[var(--theme-border)] bg-[var(--theme-surface-strong)] px-3 py-1.5 text-xs font-medium text-[var(--theme-fg)] transition hover:bg-[var(--theme-hover)] disabled:cursor-not-allowed disabled:text-[var(--theme-fg-muted)]",children:a.loading?"Loading...":"Refresh"}),e.jsx("button",{type:"button","aria-label":"Close plugins panel",onClick:()=>p(!1),className:"inline-flex h-8 w-8 items-center justify-center rounded-full border border-[var(--theme-border-strong)] bg-[var(--theme-surface-strong)] text-[var(--theme-fg)] transition hover:bg-[var(--theme-hover)]",children:e.jsx(Ms,{})})]})]}),e.jsx("div",{className:"min-h-0 flex-1 overflow-y-auto p-4",children:le})]})]}):null]}):e.jsxs("div",{className:"fixed inset-0 z-[70] flex items-start justify-center p-4 pt-[max(env(safe-area-inset-top),1rem)] sm:items-center",children:[e.jsx("button",{type:"button","aria-label":"Close Settings",onClick:s==null?void 0:s.closeSettings,className:"ui-overlay-scrim absolute inset-0 backdrop-blur-sm"}),e.jsx("section",{role:"dialog","aria-modal":"true","aria-label":"Settings",className:"relative z-10 flex max-h-[calc(100vh-2rem)] w-full max-w-4xl flex-col overflow-hidden rounded-lg border border-[var(--theme-border)] bg-[var(--theme-panel)] shadow-[var(--theme-shadow)]",children:T}),g&&v?e.jsx("div",{className:"pointer-events-none fixed inset-0 z-[71] flex items-center justify-center p-4",children:e.jsxs("div",{className:"pointer-events-auto relative z-10 flex max-h-[min(88vh,56rem)] w-full max-w-3xl flex-col overflow-hidden rounded-lg border border-[var(--theme-border)] bg-[var(--theme-panel)] shadow-[var(--theme-shadow)]",children:[e.jsxs("div",{className:"flex items-start justify-between gap-3 border-b border-[var(--theme-border)] px-4 py-3 sm:px-5",children:[e.jsxs("div",{className:"min-w-0",children:[e.jsx("p",{className:"text-sm font-medium text-[var(--theme-fg)]",children:g}),e.jsx("p",{className:"mt-1 break-all font-mono text-xs text-[var(--theme-fg-muted)]",children:v.path})]}),e.jsxs("div",{className:"flex items-center gap-2",children:[v.error?e.jsx("span",{className:"text-xs text-rose-300",children:v.error}):v.saveMessage?e.jsx("span",{className:"text-xs text-emerald-300",children:v.saveMessage}):null,e.jsx("button",{type:"button","aria-label":`Save ${g}`,onClick:()=>void qe(g),disabled:v.loading||v.saving||v.draftContent===v.originalContent,className:"rounded-full bg-[var(--theme-accent-solid)] px-4 py-2 text-sm font-medium text-[var(--theme-accent-solid-fg)] transition hover:bg-[var(--theme-accent-solid-hover)] disabled:cursor-not-allowed disabled:bg-[var(--theme-muted)] disabled:text-[var(--theme-fg-muted)]",children:v.saving?"Saving...":"Save"}),e.jsx("button",{type:"button","aria-label":"Close File Editor",onClick:()=>b(null),className:"inline-flex h-9 w-9 items-center justify-center rounded-full border border-[var(--theme-border-strong)] bg-[var(--theme-surface-strong)] text-[var(--theme-fg)] transition hover:border-[var(--theme-border-contrast)] hover:bg-[var(--theme-hover)]",children:e.jsx(Ms,{})})]})]}),e.jsx("div",{className:"min-h-0 flex-1 overflow-y-auto p-4 sm:p-5",children:e.jsx("textarea",{"aria-label":`Edit ${g}`,value:v.draftContent,onChange:f=>N(j=>({...j,[g]:{...Ut(g),...j[g],draftContent:f.target.value,error:null,saveMessage:null}})),spellCheck:!1,className:"min-h-[28rem] w-full rounded-[1rem] border border-[var(--theme-border)] bg-[var(--theme-surface-strong)] px-3 py-3 font-mono text-[13px] leading-6 text-[var(--theme-fg)] outline-none transition focus:border-[var(--theme-accent-border)]",placeholder:v.loading?"Loading...":`Edit ${g} here`})})]})}):null]})}function Vn({eyebrow:t="Supervisor Access",description:s="Use the admin credentials configured on this Remote Codex server.",onLogin:a}){const[r,o]=n.useState(""),[l,d]=n.useState(""),[u,p]=n.useState(null),[g,b]=n.useState(!1);async function x(N){N.preventDefault(),p(null),b(!0);try{await a({username:r,password:l})}catch(v){v instanceof ce?p(v.payload.message):p("Unable to sign in.")}finally{b(!1)}}return e.jsx("main",{className:"flex min-h-screen items-center justify-center bg-[var(--app-bg)] px-4 py-8 text-[var(--app-fg)]",children:e.jsxs("section",{className:"w-full max-w-sm rounded-lg border border-[var(--theme-border)] bg-[var(--theme-panel)] p-5 shadow-[var(--theme-shadow)] sm:p-6",children:[e.jsxs("div",{className:"mb-5",children:[e.jsx("p",{className:"text-xs font-semibold uppercase tracking-[0.22em] text-[var(--theme-fg-muted)]",children:t}),e.jsx("h1",{className:"mt-2 text-2xl font-semibold tracking-normal text-[var(--theme-fg)]",children:"Sign in"}),e.jsx("p",{className:"mt-2 text-sm leading-6 text-[var(--theme-fg-muted)]",children:s})]}),e.jsxs("form",{onSubmit:x,className:"space-y-4",children:[e.jsxs("label",{className:"block",children:[e.jsx("span",{className:"text-sm font-medium text-[var(--theme-fg-soft)]",children:"Username"}),e.jsx("input",{autoComplete:"username",autoFocus:!0,className:"mt-2 h-11 w-full rounded-lg border border-[var(--theme-border)] bg-[var(--theme-surface)] px-3 text-sm text-[var(--theme-fg)] outline-none transition focus:border-[var(--theme-accent-solid)] focus:ring-2 focus:ring-[var(--theme-accent-border)]",disabled:g,name:"username",onChange:N=>o(N.target.value),value:r})]}),e.jsxs("label",{className:"block",children:[e.jsx("span",{className:"text-sm font-medium text-[var(--theme-fg-soft)]",children:"Password"}),e.jsx("input",{autoComplete:"current-password",className:"mt-2 h-11 w-full rounded-lg border border-[var(--theme-border)] bg-[var(--theme-surface)] px-3 text-sm text-[var(--theme-fg)] outline-none transition focus:border-[var(--theme-accent-solid)] focus:ring-2 focus:ring-[var(--theme-accent-border)]",disabled:g,name:"password",onChange:N=>d(N.target.value),type:"password",value:l})]}),u&&e.jsx("p",{className:"rounded-lg border border-[var(--status-danger-border)] bg-[var(--status-danger-bg)] px-3 py-2 text-sm text-[var(--status-danger-fg)]",children:u}),e.jsx("button",{className:"h-11 w-full rounded-lg bg-[var(--theme-accent-solid)] px-4 text-sm font-semibold text-[var(--theme-accent-solid-fg)] transition hover:bg-[var(--theme-accent-solid-hover)] focus:outline-none focus:ring-2 focus:ring-[var(--theme-accent-border)] disabled:cursor-not-allowed disabled:opacity-60",disabled:g||!r.trim()||!l,type:"submit",children:g?"Signing in...":"Sign in"})]})]})})}function Ws(t,s){return t instanceof ce?t.payload.message:t instanceof Error?t.message:s}function Gn({className:t=""}){var J;const[s,a]=n.useState(null),[r,o]=n.useState(""),[l,d]=n.useState(""),[u,p]=n.useState(""),[g,b]=n.useState(""),[x,N]=n.useState(!0),[v,c]=n.useState(!1),[h,D]=n.useState(!1),[H,O]=n.useState(null),[E,U]=n.useState(null),[G,te]=n.useState(!1);async function Q(){var ee;N(!0),U(null);try{Ze();const i=await Et();a(i),o(((ee=i.user)==null?void 0:ee.username)??"")}catch(i){U(Ws(i,"Unable to load account."))}finally{N(!1)}}n.useEffect(()=>{Q()},[]);async function I(ee){ee.preventDefault(),c(!0),U(null),O(null);try{const i=await si({username:r});a(W=>W!=null&&W.authenticated?{...W,user:i}:W),o(i.username),O("Account updated.")}catch(i){U(Ws(i,"Unable to update account."))}finally{c(!1)}}async function se(ee){ee.preventDefault(),D(!0),U(null),O(null);try{if(u!==g){U("New passwords do not match.");return}await ai({currentPassword:l,newPassword:u}),d(""),p(""),b(""),O("Password changed.")}catch(i){U(Ws(i,"Unable to change password."))}finally{D(!1)}}return e.jsx("div",{className:`space-y-5 ${t}`.trim(),children:x?e.jsx("section",{className:"rounded-lg border border-[var(--theme-border)] bg-[var(--theme-panel)] p-4 text-sm text-[var(--theme-fg-muted)]",children:"Loading account..."}):s!=null&&s.authenticated?e.jsxs(e.Fragment,{children:[E?e.jsx(Wr,{tone:"danger",children:E}):null,H?e.jsx(Wr,{tone:"success",children:H}):null,e.jsxs("section",{className:"rounded-lg border border-[var(--theme-border)] bg-[var(--theme-panel)] p-4",children:[e.jsxs("div",{className:"mb-4",children:[e.jsx("h2",{className:"text-base font-semibold text-[var(--theme-fg)]",children:"Profile"}),e.jsx("p",{className:"mt-1 text-sm text-[var(--theme-fg-muted)]",children:"Username changes apply to future shares and login."})]}),e.jsxs("form",{className:"space-y-4",onSubmit:I,children:[e.jsxs("label",{className:"block text-sm text-[var(--theme-fg-soft)]",children:["Email",e.jsx("input",{className:"relay-input mt-2 w-full",disabled:!0,readOnly:!0,value:((J=s.user)==null?void 0:J.email)??""})]}),e.jsxs("div",{className:"flex flex-col gap-2 sm:flex-row sm:items-end",children:[e.jsxs("label",{className:"block flex-1 text-sm text-[var(--theme-fg-soft)]",children:["Username",e.jsx("input",{className:"relay-input mt-2 w-full",onChange:ee=>o(ee.target.value),value:r})]}),e.jsxs("button",{className:"relay-button-primary inline-flex h-10 items-center justify-center gap-2",disabled:v||!r.trim(),type:"submit",children:[e.jsx(z.Save,{className:"h-4 w-4"}),"Save"]})]}),e.jsxs("button",{className:"relay-button-secondary inline-flex items-center gap-2",onClick:()=>te(!0),type:"button",children:[G?e.jsx(z.CheckCircle2,{className:"h-4 w-4"}):e.jsx(z.MailCheck,{className:"h-4 w-4"}),G?"Verification queued":"Verify email"]})]})]}),e.jsxs("section",{className:"rounded-lg border border-[var(--theme-border)] bg-[var(--theme-panel)] p-4",children:[e.jsxs("div",{className:"mb-4",children:[e.jsx("h2",{className:"text-base font-semibold text-[var(--theme-fg)]",children:"Password"}),e.jsx("p",{className:"mt-1 text-sm text-[var(--theme-fg-muted)]",children:"Use at least 8 characters."})]}),e.jsxs("form",{className:"grid gap-4 sm:grid-cols-3",onSubmit:se,children:[e.jsx(Fs,{label:"Current password",value:l,onChange:d}),e.jsx(Fs,{label:"New password",value:u,onChange:p}),e.jsx(Fs,{label:"Confirm password",value:g,onChange:b}),e.jsxs("button",{className:"relay-button-primary inline-flex h-10 items-center justify-center gap-2 sm:col-span-3 sm:w-fit",disabled:h||!l||u.length<8||!g,type:"submit",children:[e.jsx(z.Save,{className:"h-4 w-4"}),"Change password"]})]})]})]}):e.jsx("section",{className:"rounded-lg border border-[var(--status-danger-border)] bg-[var(--status-danger-bg)] p-4 text-sm text-[var(--status-danger-fg)]",children:"Relay login is required."})})}function Id(){return e.jsx("main",{className:"min-h-screen bg-[var(--app-bg)] px-4 py-6 text-[var(--app-fg)] sm:px-6",children:e.jsxs("div",{className:"mx-auto w-full max-w-4xl space-y-5 pr-12 sm:pr-0",children:[e.jsxs("header",{className:"border-b border-[var(--theme-border)] pb-5",children:[e.jsx(Be,{className:"text-sm text-[var(--theme-accent-strong)]",to:"/relay-devices",children:"Back to relay portal"}),e.jsx("p",{className:"mt-4 text-xs font-semibold uppercase tracking-[0.22em] text-[var(--theme-fg-muted)]",children:"Relay Account"}),e.jsx("h1",{className:"mt-2 text-2xl font-semibold text-[var(--theme-fg)]",children:"Account settings"})]}),e.jsx(Gn,{})]})})}function Fs({label:t,value:s,onChange:a}){return e.jsxs("label",{className:"block text-sm text-[var(--theme-fg-soft)]",children:[t,e.jsx("input",{autoComplete:"new-password",className:"relay-input mt-2 w-full",onChange:r=>a(r.target.value),type:"password",value:s})]})}function Wr({tone:t,children:s}){return e.jsx("div",{className:`rounded-lg border px-3 py-2 text-sm ${t==="danger"?"border-[var(--status-danger-border)] bg-[var(--status-danger-bg)] text-[var(--status-danger-fg)]":"border-[var(--status-success-border)] bg-[var(--status-success-bg)] text-[var(--status-success-fg)]"}`,children:s})}function Ye(t){return t instanceof ce?t.payload.message:t instanceof Error?t.message:"Unable to update relay admin state."}function Pd(){const[t,s]=n.useState(null),[a,r]=n.useState(!0),[o,l]=n.useState(null),[d,u]=n.useState(!1),[p,g]=n.useState(null),[b,x]=n.useState("overview"),[N,v]=n.useState(7),[c,h]=n.useState(null),[D,H]=n.useState(null),[O,E]=n.useState([]),[U,G]=n.useState(null),[te,Q]=n.useState(!1),[I,se]=n.useState(null),[J,ee]=n.useState(null);async function i(P=N,V={}){V.showLoading!==!1&&r(!0),l(null);try{Ze();const Y=await di(P);s(Y),h(Y.settings),v(Y.conversationWindowDays),u(!1)}catch(Y){Y instanceof ce&&(Y.statusCode===401||Y.statusCode===403)?(s(null),u(!0),l(null)):l(Ye(Y))}finally{r(!1)}}n.useEffect(()=>{i()},[]);async function W(P={}){P.showLoading!==!1&&Q(!0),se(null);const[V,Y,Ce]=await Promise.allSettled([ci(),ui(),mi()]);V.status==="fulfilled"?H(V.value):(H(null),se(Ye(V.reason))),Y.status==="fulfilled"?E(Y.value.sandboxes):se(De=>De??Ye(Y.reason)),Ce.status==="fulfilled"?G(Ce.value):(G(null),se(De=>De??Ye(Ce.reason))),P.showLoading!==!1&&Q(!1)}n.useEffect(()=>{b==="hosted"&&W()},[b]),n.useEffect(()=>{if(b!=="hosted")return;const P=O.some(Y=>["requested","creating","starting","provisioning","stopping","deleting"].includes(Y.status)),V=window.setInterval(()=>void W({showLoading:!1}),P?2e3:15e3);return()=>window.clearInterval(V)},[b,O]);async function fe(P,V){ee(P),se(null);try{await V(),await W(),window.setTimeout(()=>void W(),750)}catch(Y){se(Ye(Y))}finally{ee(null)}}const ae=n.useMemo(()=>{const P=(t==null?void 0:t.users)??[],V=(t==null?void 0:t.devices)??[];return{users:P.length,enabledUsers:P.filter(Y=>Y.enabled).length,devices:V.length,onlineDevices:V.filter(Y=>Y.connected).length,conversations:P.reduce((Y,Ce)=>Y+Ce.conversationCount,0),shares:(t==null?void 0:t.shares.filter(Y=>!Y.revokedAt).length)??0}},[t]);async function we(P,V){g(P),l(null);try{const Y=await Ni(P,V);s(Ce=>qr(Ce,Y))}catch(Y){l(Ye(Y))}finally{g(null)}}async function ge(P){g(`delete:${P}`),l(null);try{await ki(P),await i(N,{showLoading:!1})}catch(V){l(Ye(V))}finally{g(null)}}async function Ne(P,V){g(`reset:${P}`),l(null);try{const Y=await Si(P,V);s(Ce=>qr(Ce,Y))}catch(Y){l(Ye(Y))}finally{g(null)}}async function K(P){if(P.preventDefault(),!!c){g("settings"),l(null);try{const V=await ji(c);s(Y=>Y&&{...Y,registrationEnabled:V.registrationEnabled,settings:V.settings}),h(V.settings)}catch(V){l(Ye(V))}finally{g(null)}}}async function M(P,V){g(`${V}:${P}`),l(null);try{V==="approve"?await Ci(P):await Ti(P),await i(N,{showLoading:!1})}catch(Y){l(Ye(Y))}finally{g(null)}}async function ne(P){await Kl(P),await i(N)}return d?e.jsx(Vn,{description:"Use the relay admin credentials for this server. This does not replace your normal relay account.",eyebrow:"Relay Admin",onLogin:ne}):e.jsxs("main",{className:"min-h-screen bg-[var(--app-bg)] px-4 py-6 text-[var(--app-fg)] sm:px-6",children:[e.jsx(Hd,{onLogout:()=>{s(null),u(!0)}}),e.jsxs("div",{className:"mx-auto flex w-full max-w-7xl flex-col gap-5",children:[e.jsxs("header",{className:"flex flex-col gap-4 border-b border-[var(--theme-border)] pb-5 lg:flex-row lg:items-end lg:justify-between",children:[e.jsxs("div",{children:[e.jsx("p",{className:"text-xs font-semibold uppercase tracking-[0.22em] text-[var(--theme-fg-muted)]",children:"Relay Admin"}),e.jsx("h1",{className:"mt-2 text-2xl font-semibold text-[var(--theme-fg)]",children:"Operations panel"}),e.jsx("p",{className:"mt-1 max-w-2xl text-sm text-[var(--theme-fg-muted)]",children:"Accounts, devices, usage, registration policy, and shared thread access."})]}),e.jsxs("div",{className:"flex flex-wrap items-center gap-2",children:[e.jsxs("label",{className:"flex items-center gap-2 text-sm text-[var(--theme-fg-muted)]",children:["Usage window",e.jsxs("select",{className:"relay-input h-10 w-24",onChange:P=>void i(Number(P.target.value)),value:N,children:[e.jsx("option",{value:1,children:"1 day"}),e.jsx("option",{value:7,children:"7 days"}),e.jsx("option",{value:30,children:"30 days"}),e.jsx("option",{value:90,children:"90 days"})]})]}),e.jsx(Be,{className:"relay-button-secondary",to:"/",children:"Relay home"}),e.jsxs("button",{className:"relay-button-secondary inline-flex items-center gap-2",onClick:()=>void i(N),type:"button",children:[e.jsx(z.RefreshCw,{className:"h-4 w-4"}),"Refresh"]})]})]}),o?e.jsx("section",{className:"rounded-lg border border-[var(--status-danger-border)] bg-[var(--status-danger-bg)] p-4 text-sm text-[var(--status-danger-fg)]",children:o}):null,a?e.jsx("section",{className:"rounded-lg border border-[var(--theme-border)] bg-[var(--theme-panel)] p-4 text-sm text-[var(--theme-fg-muted)]",children:"Loading relay admin..."}):t?e.jsxs(e.Fragment,{children:[e.jsxs("section",{className:"grid gap-3 sm:grid-cols-2 xl:grid-cols-4",children:[e.jsx(ls,{icon:e.jsx(z.Users,{className:"h-5 w-5"}),label:"Users",value:ae.users,detail:`${ae.enabledUsers} enabled`}),e.jsx(ls,{icon:e.jsx(z.Database,{className:"h-5 w-5"}),label:"Devices",value:ae.devices,detail:`${ae.onlineDevices} online`}),e.jsx(ls,{icon:e.jsx(z.Clock3,{className:"h-5 w-5"}),label:`Conversations, ${t.conversationWindowDays}d`,value:ae.conversations,detail:"Relay prompt/start events"}),e.jsx(ls,{icon:e.jsx(z.Share2,{className:"h-5 w-5"}),label:"Active shares",value:ae.shares,detail:`${t.pendingRegistrations.length} pending registrations`})]}),e.jsx("nav",{className:"flex gap-2 overflow-x-auto border-b border-[var(--theme-border)] pb-2",children:["overview","users","devices","hosted","shares","settings"].map(P=>e.jsx("button",{className:`rounded-md px-3 py-2 text-sm font-medium ${b===P?"bg-[var(--theme-accent-soft)] text-[var(--theme-fg)]":"text-[var(--theme-fg-muted)] hover:bg-[var(--theme-hover)] hover:text-[var(--theme-fg)]"}`,onClick:()=>x(P),type:"button",children:Zd(P)},P))}),b==="overview"?e.jsx(Bd,{summary:t}):null,b==="users"?e.jsx(Wd,{busyKey:p,onDeleteUser:ge,onResetPassword:Ne,onUpdateUser:we,users:t.users}):null,b==="devices"?e.jsx(Fd,{devices:t.devices,users:t.users}):null,b==="hosted"?e.jsx(Ld,{busyKey:J,capability:D,error:I,loading:te,onAction:fe,onRefresh:W,sandboxes:O,reconciliation:U,users:t.users}):null,b==="shares"?e.jsx(qd,{shares:t.shares}):null,b==="settings"&&c?e.jsx(Vd,{busy:p==="settings",draft:c,onChange:h,onReviewRegistration:M,onSave:K,pending:t.pendingRegistrations,reviewBusyKey:p}):null]}):null]})]})}function Ld({busyKey:t,capability:s,error:a,loading:r,onAction:o,onRefresh:l,reconciliation:d,sandboxes:u,users:p}){var Q;const g=p.filter(I=>I.role==="user"&&I.enabled),[b,x]=n.useState([]),[N,v]=n.useState("Hosted Codex"),[c,h]=n.useState("standard"),[D,H]=n.useState(`model_provider = "OpenAI"
5
+ model = "gpt-5.6-sol"
6
+ review_model = "gpt-5.6-sol"
7
+ model_reasoning_effort = "low"
8
+ disable_response_storage = true
9
+ network_access = "enabled"
10
+
11
+ [model_providers.OpenAI]
12
+ name = "OpenAI"
13
+ base_url = "https://sub.lnz-study.com"
14
+ wire_api = "responses"
15
+ requires_openai_auth = true
16
+
17
+ [features]
18
+ goals = true
19
+ `),[O,E]=n.useState(""),U=(s==null?void 0:s.available)===!0&&b.length>0;async function G(I){if(I.preventDefault(),!U)return;const se=c==="large"?{cpuCount:2,memoryMiB:2048,diskGiB:12}:{cpuCount:1,memoryMiB:1536,diskGiB:10};await o("hosted:create",()=>xi({assignedUserIds:b,deviceName:N,imageVersion:"ubuntu-24.04-v5",resources:se,backends:["codex"],codexFiles:{configToml:D,authJson:O}})),E("")}const te=s!=null&&s.available?"success":s!=null&&s.configured?"warning":"neutral";return e.jsxs("section",{className:"space-y-4","aria-label":"Hosted supervisor VMs",children:[e.jsxs("div",{className:"rounded-lg border border-[var(--theme-border)] bg-[var(--theme-panel)]",children:[e.jsxs("div",{className:"flex flex-col gap-4 p-4 sm:flex-row sm:items-center sm:justify-between",children:[e.jsxs("div",{className:"flex min-w-0 items-start gap-3",children:[e.jsx("span",{className:"rounded-lg bg-[var(--theme-surface)] p-2 text-[var(--theme-fg-soft)]",children:e.jsx(z.Server,{className:"h-5 w-5","aria-hidden":"true"})}),e.jsxs("div",{children:[e.jsxs("div",{className:"flex flex-wrap items-center gap-2",children:[e.jsx("h2",{className:"text-base font-semibold text-[var(--theme-fg)]",children:"Hosted supervisor VMs"}),e.jsx(Ht,{tone:te,children:s!=null&&s.available?"Available":s!=null&&s.configured?"Unavailable":"Disabled"})]}),e.jsx("p",{className:"mt-1 max-w-3xl text-sm text-[var(--theme-fg-muted)]",children:(s==null?void 0:s.reason)??"Incus VMs run one isolated relay supervisor per assigned user."}),s!=null&&s.capacity&&s.limits?e.jsxs("p",{className:"mt-1 text-xs text-[var(--theme-fg-soft)]",children:[s.capacity.runningInstances,"/",s.limits.maxRunningInstances," running ·"," ",s.capacity.totalInstances,"/",s.limits.maxInstances," total"]}):null,s!=null&&s.metrics?e.jsxs("p",{className:"mt-1 text-xs text-[var(--theme-fg-soft)]",children:[s.metrics.cpuCount," CPU · load"," ",s.metrics.load1.toFixed(2)," ·"," ",Math.round(s.metrics.memoryAvailableMiB/1024)," GiB RAM free · ",s.metrics.diskAvailableGiB.toFixed(1)," ","GiB disk free"]}):null,(Q=s==null?void 0:s.alerts)==null?void 0:Q.map(I=>e.jsx("p",{className:"mt-1 text-xs text-amber-700 dark:text-amber-300",role:"alert",children:I.message},I.code))]})]}),e.jsxs("button",{className:"relay-button-secondary inline-flex min-h-11 items-center justify-center gap-2",disabled:r,onClick:()=>void l(),type:"button",children:[e.jsx(z.RefreshCw,{className:`h-4 w-4 ${r?"animate-spin":""}`}),"Check host"]})]}),a?e.jsx("div",{className:"border-t border-[var(--status-danger-border)] bg-[var(--status-danger-bg)] px-4 py-3 text-sm text-[var(--status-danger-fg)]",role:"alert",children:a}):null,e.jsx(Od,{busyKey:t,onAction:o,reconciliation:d}),e.jsxs("details",{className:"border-t border-[var(--theme-border)]",open:u.length===0,children:[e.jsxs("summary",{className:"flex min-h-12 cursor-pointer list-none items-center gap-2 px-4 py-3 text-sm font-medium text-[var(--theme-fg)] hover:bg-[var(--theme-hover)] focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-inset focus-visible:ring-[var(--theme-accent-ring)]",children:[e.jsx(z.Plus,{className:"h-4 w-4"}),"Create hosted VM"]}),e.jsxs("form",{className:"grid gap-4 border-t border-[var(--theme-border)] p-4 lg:grid-cols-2",onSubmit:G,children:[e.jsxs("fieldset",{className:"text-sm text-[var(--theme-fg-soft)]",children:[e.jsx("legend",{children:"Assigned users"}),e.jsx("div",{className:"mt-2 max-h-48 overflow-y-auto rounded-md border border-[var(--theme-border)] bg-[var(--theme-surface)]",children:g.length?g.map(I=>e.jsxs("label",{className:"flex min-h-11 cursor-pointer items-center gap-3 border-b border-[var(--theme-border)] px-3 last:border-b-0 hover:bg-[var(--theme-hover)]",children:[e.jsx("input",{"aria-label":`Assign ${I.username} (${I.email})`,checked:b.includes(I.id),disabled:!(s!=null&&s.available),onChange:se=>x(J=>se.target.checked?[...J,I.id]:J.filter(ee=>ee!==I.id)),type:"checkbox"}),e.jsxs("span",{className:"min-w-0",children:[e.jsx("span",{className:"block font-medium text-[var(--theme-fg)]",children:I.username}),e.jsx("span",{className:"block truncate text-xs text-[var(--theme-fg-muted)]",children:I.email})]})]},I.id)):e.jsx("p",{className:"px-3 py-3 text-xs text-[var(--theme-fg-muted)]",children:"Create and enable a user account before assigning a VM."})}),e.jsxs("span",{className:"mt-1 block text-xs text-[var(--theme-fg-muted)]",children:[b.length," selected · all receive full VM access"]})]}),e.jsxs("label",{className:"text-sm text-[var(--theme-fg-soft)]",children:["Device name",e.jsx("input",{className:"relay-input mt-2 w-full",maxLength:120,onChange:I=>v(I.target.value),required:!0,value:N})]}),e.jsxs("label",{className:"text-sm text-[var(--theme-fg-soft)]",children:["Resources",e.jsxs("select",{className:"relay-input mt-2 w-full",onChange:I=>h(I.target.value),value:c,children:[e.jsx("option",{value:"standard",children:"Standard, 1 CPU · 1.5 GiB · 10 GiB"}),e.jsx("option",{value:"large",children:"Large, 2 CPU · 2 GiB · 12 GiB"})]})]}),e.jsxs("label",{className:"text-sm text-[var(--theme-fg-soft)]",children:["Backends",e.jsxs("select",{className:"relay-input mt-2 w-full",value:"codex",onChange:()=>{},children:[e.jsx("option",{value:"codex",children:"Codex"}),e.jsx("option",{disabled:!0,children:"Claude Code (coming soon)"}),e.jsx("option",{disabled:!0,children:"OpenCode (coming soon)"})]})]}),e.jsxs("details",{className:"rounded-md border border-[var(--theme-border)] lg:col-span-2",open:!0,children:[e.jsx("summary",{className:"cursor-pointer px-3 py-2 text-sm font-medium text-[var(--theme-fg)]",children:"Codex files"}),e.jsxs("div",{className:"space-y-4 border-t border-[var(--theme-border)] p-3",children:[e.jsx(gs,{filename:"config.toml",language:"TOML",onChange:H,value:D}),e.jsx(gs,{filename:"auth.json",language:"JSON",onChange:E,value:O})]})]}),e.jsxs("div",{className:"flex flex-col gap-2 lg:col-span-2 sm:flex-row sm:items-center sm:justify-between",children:[e.jsxs("p",{className:"flex items-center gap-2 text-xs text-[var(--theme-fg-muted)]",children:[e.jsx(z.ShieldCheck,{className:"h-4 w-4"}),"The relay stores only an opaque credential reference."]}),e.jsxs("button",{className:"relay-button-primary inline-flex min-h-11 items-center justify-center gap-2",disabled:!U||!D.trim()||!O.trim()||t==="hosted:create",type:"submit",children:[e.jsx(z.Plus,{className:"h-4 w-4"}),t==="hosted:create"?"Creating…":"Create hosted VM"]})]})]})]})]}),e.jsxs("div",{className:"overflow-hidden rounded-lg border border-[var(--theme-border)] bg-[var(--theme-panel)]",children:[e.jsxs("div",{className:"flex items-center justify-between gap-3 border-b border-[var(--theme-border)] px-4 py-3",children:[e.jsxs("div",{children:[e.jsx("h3",{className:"text-sm font-semibold text-[var(--theme-fg)]",children:"Managed VMs"}),e.jsx("p",{className:"text-xs text-[var(--theme-fg-muted)]",children:"Turn-aware idle stop is 30 minutes after the last terminal activity."})]}),e.jsx("span",{className:"text-sm tabular-nums text-[var(--theme-fg-muted)]",children:u.length})]}),r&&u.length===0?e.jsxs("div",{className:"space-y-3 p-4","aria-label":"Loading hosted VMs",children:[e.jsx("div",{className:"h-14 animate-pulse rounded-md bg-[var(--theme-muted)]"}),e.jsx("div",{className:"h-14 animate-pulse rounded-md bg-[var(--theme-muted)]"})]}):u.length?e.jsx("div",{className:"divide-y divide-[var(--theme-border)]",children:u.map(I=>e.jsx(Ud,{busyKey:t,onAction:o,sandbox:I,users:g},I.id))}):e.jsx("div",{className:"p-6 text-center text-sm text-[var(--theme-fg-muted)]",children:"No hosted VMs yet. Open “Create hosted VM” to assign the first one."})]})]})}function Od({busyKey:t,onAction:s,reconciliation:a}){const r=a?a.missingInstanceSandboxIds.length+a.missingCredentialSandboxIds.length+a.orphanInstances.length+a.orphanCredentials.length:0,o=(a==null?void 0:a.status)==="healthy"?"success":(a==null?void 0:a.status)==="issues"||(a==null?void 0:a.status)==="unavailable"?"warning":"neutral",l=(a==null?void 0:a.status)==="healthy"?"Inventory healthy":(a==null?void 0:a.status)==="issues"?`${r} inventory issue${r===1?"":"s"}`:(a==null?void 0:a.status)==="unavailable"?"Inventory unavailable":"Inventory not checked";return e.jsxs("div",{className:"border-t border-[var(--theme-border)] px-4 py-3",children:[e.jsxs("div",{className:"flex flex-wrap items-center justify-between gap-3",children:[e.jsxs("div",{children:[e.jsxs("div",{className:"flex flex-wrap items-center gap-2",children:[e.jsx("span",{className:"text-sm font-medium text-[var(--theme-fg)]",children:"Relay ↔ Incus inventory"}),e.jsx(Ht,{tone:o,children:l})]}),e.jsx("p",{className:"mt-1 text-xs text-[var(--theme-fg-muted)]",children:"Audit only; resources are deleted only after an explicit admin action and a fresh orphan check."})]}),e.jsxs("button",{className:"relay-button-secondary inline-flex min-h-10 items-center justify-center gap-2",disabled:t==="hosted:reconcile",onClick:()=>void s("hosted:reconcile",hi),type:"button",children:[e.jsx(z.RefreshCw,{className:`h-4 w-4 ${t==="hosted:reconcile"?"animate-spin":""}`}),"Run inventory audit"]})]}),a==null?void 0:a.missingInstanceSandboxIds.map(d=>e.jsxs("p",{className:"mt-2 text-xs text-amber-700 dark:text-amber-300",children:["Missing Incus instance for relay sandbox ",d]},`missing-instance-${d}`)),a==null?void 0:a.missingCredentialSandboxIds.map(d=>e.jsxs("p",{className:"mt-2 text-xs text-amber-700 dark:text-amber-300",children:["Missing credential for relay sandbox ",d]},`missing-credential-${d}`)),a==null?void 0:a.orphanInstances.map(d=>e.jsxs("div",{className:"mt-2 flex flex-wrap items-center justify-between gap-2 rounded-md bg-[var(--theme-surface)] px-3 py-2",children:[e.jsxs("span",{className:"text-xs text-[var(--theme-fg-soft)]",children:["Orphan VM ",d.id," · ",d.status," ·"," ",d.snapshots.length," snapshots"]}),e.jsx("button",{className:"relay-button-danger min-h-9",disabled:t===`hosted:orphan-instance:${d.id}`,onClick:()=>void s(`hosted:orphan-instance:${d.id}`,()=>fi(d.id)),type:"button",children:"Delete orphan VM"})]},d.id)),a==null?void 0:a.orphanCredentials.map(d=>e.jsxs("div",{className:"mt-2 flex flex-wrap items-center justify-between gap-2 rounded-md bg-[var(--theme-surface)] px-3 py-2",children:[e.jsxs("span",{className:"text-xs text-[var(--theme-fg-soft)]",children:["Orphan credential ",d.credentialRef]}),e.jsx("button",{className:"relay-button-danger min-h-9",disabled:t===`hosted:orphan-credential:${d.credentialRef}`,onClick:()=>void s(`hosted:orphan-credential:${d.credentialRef}`,()=>pi(d.credentialRef)),type:"button",children:"Delete orphan credential"})]},d.credentialRef))]})}function Ud({busyKey:t,onAction:s,sandbox:a,users:r}){const[o,l]=n.useState(!1),[d,u]=n.useState(!1),[p,g]=n.useState(""),[b,x]=n.useState(!1),[N,v]=n.useState(()=>Date.now()),c=(t==null?void 0:t.endsWith(a.id))??!1,h=Dd(a.status),D=a.assignedUsers.map(E=>E.userId),H=p.trim().toLowerCase(),O=r.filter(E=>!D.includes(E.id)).filter(E=>H?[E.id,E.username,E.email].some(U=>U.toLowerCase().includes(H)):!1).slice(0,6);return n.useEffect(()=>{if(!a.runningSince)return;const E=window.setInterval(()=>v(Date.now()),3e4);return()=>window.clearInterval(E)},[a.runningSince]),n.useEffect(()=>{if(!b)return;const E=U=>{U.key==="Escape"&&x(!1)};return window.addEventListener("keydown",E),()=>window.removeEventListener("keydown",E)},[b]),e.jsxs("article",{className:"px-4 py-4",children:[e.jsxs("div",{className:"flex flex-col gap-4 xl:flex-row xl:items-start xl:justify-between",children:[e.jsxs("div",{className:"min-w-0",children:[e.jsxs("div",{className:"flex flex-wrap items-center gap-2",children:[e.jsx("h4",{className:"truncate text-sm font-semibold text-[var(--theme-fg)]",children:a.deviceName}),e.jsx(Ht,{tone:h,children:Md(a.status)}),a.activeTurnCount>0?e.jsxs(Ht,{tone:"warning",children:[a.activeTurnCount," active turn",a.activeTurnCount===1?"":"s"]}):null,a.workspaceIsolationEnabled?e.jsx(Ht,{tone:"success",children:"Private workspaces"}):null]}),e.jsxs("p",{className:"mt-1 text-sm text-[var(--theme-fg-soft)]",children:[a.assignedUsers.map(E=>E.username).join(", "),e.jsx("span",{className:"mx-2 text-[var(--theme-fg-muted)]",children:"·"}),a.resources.cpuCount," CPU ·"," ",_d(a.resources.memoryMiB)," ·"," ",a.resources.diskGiB," GiB"]}),e.jsxs("p",{className:"mt-1 text-xs text-[var(--theme-fg-muted)]",children:["Updated ",Xe(a.updatedAt),a.runningSince?` · running for ${tc(a.runningSince,N)}`:"",a.idleDeadlineAt?` · idle stop ${Xe(a.idleDeadlineAt)}`:""]}),a.lastErrorMessage?e.jsx("p",{className:"mt-2 text-sm text-[var(--status-danger-fg)]",role:"status",children:a.lastErrorMessage}):null]}),e.jsxs("div",{className:"flex flex-wrap gap-2",children:[a.status==="stopped"||a.status==="error"?e.jsxs("button",{className:"relay-button-secondary inline-flex min-h-11 items-center gap-2",disabled:c,onClick:()=>void s(`start:${a.id}`,()=>Mr(a.id,a.status==="error"?"retry":"start")),type:"button",children:[a.status==="error"?e.jsx(z.RotateCcw,{className:"h-4 w-4"}):e.jsx(z.Play,{className:"h-4 w-4"}),a.status==="error"?"Retry":"Start"]}):e.jsxs("button",{className:"relay-button-secondary inline-flex min-h-11 items-center gap-2",disabled:c||a.activeTurnCount>0||a.status!=="online",onClick:()=>void s(`stop:${a.id}`,()=>Mr(a.id,"stop")),title:a.activeTurnCount>0?"An active turn prevents stopping.":void 0,type:"button",children:[e.jsx(z.Square,{className:"h-4 w-4"}),"Stop"]}),e.jsxs("button",{className:"relay-button-secondary inline-flex min-h-11 items-center gap-2",disabled:c||a.status!=="online"||a.activeTurnCount>0,onClick:()=>void s(`snapshot:${a.id}`,()=>vi(a.id,`manual-${Date.now()}`)),type:"button",children:[e.jsx(z.Camera,{className:"h-4 w-4"}),"Snapshot"]}),e.jsxs("button",{className:"relay-button-secondary inline-flex min-h-11 items-center gap-2",disabled:c,onClick:()=>x(!0),type:"button",children:[e.jsx(z.Settings,{className:"h-4 w-4"}),"Manage"]}),o?e.jsxs("span",{className:"inline-flex items-center gap-2 rounded-md bg-[var(--status-danger-bg)] p-1",children:[e.jsx("button",{className:"min-h-9 rounded-md px-3 text-sm font-medium text-[var(--status-danger-fg)] hover:bg-[var(--theme-hover)]",disabled:c,onClick:()=>void s(`delete:${a.id}`,()=>wi(a.id)),type:"button",children:"Confirm delete"}),e.jsx("button",{className:"min-h-9 rounded-md px-2 text-sm text-[var(--theme-fg-muted)] hover:bg-[var(--theme-hover)]",onClick:()=>l(!1),type:"button",children:"Cancel"})]}):e.jsx("button",{className:"relay-button-secondary min-h-11 text-[var(--status-danger-fg)]",disabled:c||a.activeTurnCount>0,onClick:()=>l(!0),type:"button",children:"Delete"})]})]}),b?e.jsxs("div",{className:"fixed inset-0 z-50 flex justify-end",role:"presentation",children:[e.jsx("button",{"aria-label":"Close VM management",className:"absolute inset-0 bg-[var(--overlay-scrim)]",onClick:()=>x(!1),type:"button"}),e.jsxs("section",{"aria-label":`Manage ${a.deviceName}`,"aria-modal":"true",className:"relative flex h-full w-full max-w-2xl flex-col border-l border-[var(--theme-border)] bg-[var(--theme-panel)] shadow-2xl shadow-[var(--theme-shadow)]",role:"dialog",children:[e.jsxs("header",{className:"flex min-h-16 items-center justify-between gap-4 border-b border-[var(--theme-border)] px-5",children:[e.jsxs("div",{className:"min-w-0",children:[e.jsxs("h3",{className:"truncate text-base font-semibold text-[var(--theme-fg)]",children:["Manage ",a.deviceName]}),e.jsx("p",{className:"mt-0.5 text-xs text-[var(--theme-fg-muted)]",children:"Access, isolation, credentials, and recovery settings"})]}),e.jsx("button",{"aria-label":"Close VM management",className:"relay-button-secondary inline-flex h-10 w-10 items-center justify-center p-0",onClick:()=>x(!1),type:"button",children:e.jsx(z.X,{className:"h-4 w-4"})})]}),e.jsxs("div",{className:"flex-1 overflow-y-auto p-5",children:[e.jsx("div",{className:"max-w-2xl rounded-md border border-[var(--theme-border)] bg-[var(--theme-surface)] px-3 py-3",children:e.jsxs("label",{className:"flex cursor-pointer items-start justify-between gap-4",children:[e.jsxs("span",{children:[e.jsx("span",{className:"block text-sm font-medium text-[var(--theme-fg)]",children:"Isolate user workspaces"}),e.jsx("span",{className:"mt-1 block text-xs leading-5 text-[var(--theme-fg-muted)]",children:"Each authorized user sees only their own workspaces. Their first visit creates a private workspace and an initial Codex thread."})]}),e.jsx("input",{"aria-label":`Isolate user workspaces for ${a.deviceName}`,checked:a.workspaceIsolationEnabled,className:"mt-1 h-4 w-4 shrink-0 accent-[var(--theme-accent-strong)]",disabled:c,onChange:E=>void s(`settings:${a.id}`,()=>gi(a.id,{workspaceIsolationEnabled:E.target.checked})),type:"checkbox"})]})}),e.jsxs("details",{className:"mt-4",open:!0,children:[e.jsxs("summary",{className:"cursor-pointer text-xs font-medium text-[var(--theme-fg-muted)] hover:text-[var(--theme-fg)] focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-[var(--theme-accent-ring)]",children:["Access · ",a.assignedUsers.length," user",a.assignedUsers.length===1?"":"s"]}),e.jsxs("div",{className:"mt-3 max-w-2xl overflow-hidden rounded-md border border-[var(--theme-border)]",children:[e.jsxs("div",{className:"flex min-h-11 items-center justify-between gap-3 bg-[var(--theme-surface)] px-3",children:[e.jsxs("div",{children:[e.jsx("p",{className:"text-xs font-semibold text-[var(--theme-fg)]",children:"Authorized users"}),e.jsx("p",{className:"text-[11px] text-[var(--theme-fg-muted)]",children:"Full workspace, thread, and VM control"})]}),e.jsx("button",{"aria-expanded":d,"aria-label":"Add authorized user",className:"relay-button-secondary inline-flex h-9 w-9 items-center justify-center p-0",disabled:c,onClick:()=>{u(E=>!E),g("")},type:"button",children:e.jsx(z.Plus,{className:"h-4 w-4"})})]}),d?e.jsxs("div",{className:"border-t border-[var(--theme-border)] p-3",children:[e.jsx("label",{className:"text-xs font-medium text-[var(--theme-fg-soft)]",htmlFor:`invite-user-${a.id}`,children:"Find an account"}),e.jsx("input",{autoFocus:!0,className:"relay-input mt-2 min-h-11 w-full",id:`invite-user-${a.id}`,onChange:E=>g(E.target.value),placeholder:"Account ID, username, or email",value:p}),H?e.jsx("div",{className:"mt-2 overflow-hidden rounded-md border border-[var(--theme-border)]",children:O.length?O.map(E=>e.jsxs("button",{className:"flex min-h-11 w-full items-center justify-between gap-3 border-b border-[var(--theme-border)] px-3 text-left last:border-b-0 hover:bg-[var(--theme-hover)]",disabled:c,onClick:()=>void s(`members:${a.id}`,async()=>{await Dr(a.id,[...D,E.id]),u(!1),g("")}),type:"button",children:[e.jsxs("span",{className:"min-w-0",children:[e.jsx("span",{className:"block text-sm font-medium text-[var(--theme-fg)]",children:E.username}),e.jsxs("span",{className:"block truncate text-xs text-[var(--theme-fg-muted)]",children:[E.email," · ",E.id]})]}),e.jsx("span",{className:"text-xs font-medium text-[var(--theme-accent-strong)]",children:"Add"})]},E.id)):e.jsx("p",{className:"px-3 py-3 text-xs text-[var(--theme-fg-muted)]",children:"No unassigned account matches that search."})}):null]}):null,e.jsx("ul",{className:"divide-y divide-[var(--theme-border)] border-t border-[var(--theme-border)]",children:a.assignedUsers.map(E=>e.jsxs("li",{className:"flex min-h-12 items-center justify-between gap-3 px-3",children:[e.jsxs("span",{className:"min-w-0",children:[e.jsx("span",{className:"block text-sm font-medium text-[var(--theme-fg)]",children:E.username}),e.jsx("span",{className:"block truncate text-xs text-[var(--theme-fg-muted)]",children:E.email})]}),e.jsx("button",{"aria-label":`Remove ${E.username} access`,className:"min-h-9 rounded-md px-3 text-xs font-medium text-[var(--status-danger-fg)] hover:bg-[var(--status-danger-bg)]",disabled:c||D.length===1,onClick:()=>void s(`members:${a.id}`,()=>Dr(a.id,D.filter(U=>U!==E.userId))),title:D.length===1?"A hosted VM must keep at least one authorized user.":void 0,type:"button",children:"Remove"})]},E.userId))})]})]}),e.jsxs("div",{className:"mt-4 rounded-md border border-[var(--theme-border)] bg-[var(--theme-surface)] px-3 py-3 text-xs leading-5 text-[var(--theme-fg-muted)]",children:[e.jsx("span",{className:"font-medium text-[var(--theme-fg)]",children:"Snapshots"})," ","capture the VM disk as a local Incus restore point before risky changes. They are not off-host backups and are not restored automatically."]}),e.jsx($d,{busy:c,onAction:s,sandbox:a})]})]})]}):null]})}function $d({busy:t,onAction:s,sandbox:a}){const[r,o]=n.useState(!1),[l,d]=n.useState(!1),[u,p]=n.useState(null),[g,b]=n.useState(""),[x,N]=n.useState("");async function v(){d(!0),p(null);try{const c=await bi(a.id);b(c.configToml),N(c.authJson)}catch(c){p(Ye(c))}finally{d(!1)}}return e.jsxs("details",{className:"mt-3",onToggle:c=>{const h=c.currentTarget.open;o(h),h&&!g&&!l&&a.status==="online"&&v()},children:[e.jsx("summary",{className:"cursor-pointer text-xs font-medium text-[var(--theme-fg-muted)] hover:text-[var(--theme-fg)] focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-[var(--theme-accent-ring)]",children:"Backend credentials"}),r?e.jsxs("div",{className:"mt-3 max-w-3xl overflow-hidden rounded-md border border-[var(--theme-border)]",children:[e.jsxs("div",{className:"grid gap-3 bg-[var(--theme-surface)] p-3 sm:grid-cols-[12rem_1fr] sm:items-end",children:[e.jsxs("label",{className:"text-xs font-medium text-[var(--theme-fg-soft)]",children:["Backend",e.jsxs("select",{className:"relay-input mt-2 min-h-11 w-full",onChange:()=>{},value:"codex",children:[e.jsx("option",{value:"codex",children:"Codex"}),e.jsx("option",{disabled:!0,children:"Claude Code (coming soon)"}),e.jsx("option",{disabled:!0,children:"OpenCode (coming soon)"})]})]}),e.jsx("p",{className:"text-xs leading-5 text-[var(--theme-fg-muted)]",children:"Files are read from and written directly to this VM. The VM must be online."})]}),a.status!=="online"?e.jsx("p",{className:"border-t border-[var(--theme-border)] px-3 py-3 text-sm text-[var(--status-warning-fg)]",children:"Start the VM before editing backend files."}):l?e.jsx("p",{className:"border-t border-[var(--theme-border)] px-3 py-4 text-sm text-[var(--theme-fg-muted)]",children:"Loading Codex files from the VM…"}):e.jsxs("div",{className:"space-y-4 border-t border-[var(--theme-border)] p-3",children:[u?e.jsx("p",{className:"rounded-md border border-[var(--status-danger-border)] bg-[var(--status-danger-bg)] px-3 py-2 text-sm text-[var(--status-danger-fg)]",children:u}):null,e.jsx(gs,{filename:"~/.codex/config.toml",language:"TOML",onChange:b,value:g}),e.jsx(gs,{filename:"~/.codex/auth.json",language:"JSON",onChange:N,value:x}),e.jsxs("div",{className:"flex justify-end gap-2",children:[e.jsx("button",{className:"relay-button-secondary min-h-11",disabled:t||l,onClick:()=>void v(),type:"button",children:"Reload"}),e.jsx("button",{className:"relay-button-primary min-h-11",disabled:t||!g.trim()||!x.trim(),onClick:()=>void s(`backend:${a.id}`,()=>yi(a.id,{configToml:g,authJson:x})),type:"button",children:"Save to VM"})]})]})]}):null]})}function gs({filename:t,language:s,onChange:a,value:r}){return e.jsxs("div",{children:[e.jsxs("div",{className:"flex min-h-9 items-center justify-between gap-3",children:[e.jsx("label",{className:"text-xs font-semibold text-[var(--theme-fg)]",htmlFor:t,children:t}),e.jsxs("label",{className:"relay-button-secondary inline-flex min-h-9 cursor-pointer items-center px-3 text-xs",children:["Upload ",s,e.jsx("input",{accept:s==="JSON"?".json,application/json":".toml,text/plain",className:"sr-only",onChange:o=>{var d;const l=(d=o.target.files)==null?void 0:d[0];l&&l.text().then(a),o.target.value=""},type:"file"})]})]}),e.jsx("textarea",{className:"relay-input mt-2 min-h-40 w-full resize-y font-mono text-xs leading-5",id:t,onChange:o=>a(o.target.value),spellCheck:!1,value:r})]})}function Ht({children:t,tone:s}){const a={success:"border-[var(--status-success-border)] bg-[var(--status-success-bg)] text-[var(--status-success-fg)]",warning:"border-[var(--status-warning-border)] bg-[var(--status-warning-bg)] text-[var(--status-warning-fg)]",danger:"border-[var(--status-danger-border)] bg-[var(--status-danger-bg)] text-[var(--status-danger-fg)]",neutral:"border-[var(--theme-border)] bg-[var(--theme-surface)] text-[var(--theme-fg-muted)]"}[s];return e.jsx("span",{className:`rounded-full border px-2 py-0.5 text-xs font-medium ${a}`,children:t})}function Dd(t){return t==="online"?"success":t==="error"?"danger":["creating","starting","provisioning","stopping","deleting"].includes(t)?"warning":"neutral"}function Md(t){return t.replace("_"," ").replace(/^./,s=>s.toUpperCase())}function _d(t){return t%1024===0?`${t/1024} GiB`:`${(t/1024).toFixed(1)} GiB`}function ls({icon:t,label:s,value:a,detail:r}){return e.jsx("article",{className:"rounded-lg border border-[var(--theme-border)] bg-[var(--theme-panel)] p-4",children:e.jsxs("div",{className:"flex items-start gap-3",children:[e.jsx("span",{className:"rounded-lg border border-[var(--theme-border)] bg-[var(--theme-surface)] p-2 text-[var(--theme-accent-strong)]",children:t}),e.jsxs("div",{className:"min-w-0",children:[e.jsx("p",{className:"text-xs font-medium uppercase tracking-[0.14em] text-[var(--theme-fg-muted)]",children:s}),e.jsx("p",{className:"mt-1 text-2xl font-semibold text-[var(--theme-fg)]",children:a.toLocaleString()}),e.jsx("p",{className:"mt-1 text-xs text-[var(--theme-fg-muted)]",children:r})]})]})})}function Hd({onLogout:t}){const[s,a]=n.useState(null),[r,o]=n.useState(!1);n.useEffect(()=>{let u=!1;return On().then(p=>{u||a(p.authenticated?p:null)}).catch(()=>{u||a(null)}),()=>{u=!0}},[]);const l=(s==null?void 0:s.user)??null;if(!l)return null;async function d(){await Yl(),a(null),o(!1),t()}return e.jsxs("div",{className:"fixed right-3 top-[calc(env(safe-area-inset-top)+0.55rem)] z-50",children:[e.jsx("button",{"aria-expanded":r,"aria-haspopup":"menu","aria-label":`Relay admin menu for ${l.username}`,className:"inline-flex h-10 w-10 items-center justify-center rounded-full border border-[var(--theme-border)] bg-[var(--theme-panel)] text-sm font-semibold text-[var(--theme-fg)] shadow-lg transition hover:bg-[var(--theme-hover)] focus:outline-none focus:ring-2 focus:ring-[var(--theme-accent-ring)]",onClick:()=>o(u=>!u),type:"button",children:sc(l.username)}),r?e.jsxs("div",{className:"absolute right-0 mt-2 w-64 overflow-hidden rounded-lg border border-[var(--theme-border)] bg-[var(--theme-panel)] p-1 shadow-[var(--theme-shadow)]",role:"menu",children:[e.jsxs("div",{className:"border-b border-[var(--theme-border)] px-3 py-2",children:[e.jsx("p",{className:"truncate text-sm font-medium text-[var(--theme-fg)]",children:l.username}),e.jsx("p",{className:"truncate text-xs text-[var(--theme-fg-muted)]",children:l.email}),e.jsx("p",{className:"mt-1 text-[11px] uppercase tracking-[0.14em] text-[var(--theme-fg-muted)]",children:"Admin session"})]}),e.jsxs("button",{className:"flex w-full items-center gap-2 rounded-lg px-3 py-2 text-left text-sm text-[var(--status-danger-fg)] transition hover:bg-[var(--status-danger-bg)]",onClick:()=>void d(),role:"menuitem",type:"button",children:[e.jsx(z.LogOut,{className:"h-4 w-4"}),"Logout admin"]})]}):null]})}function Bd({summary:t}){const s=[...t.users].sort(ec("lastSeenAt")).slice(0,6),a=t.devices.filter(r=>r.connected);return e.jsxs("section",{className:"grid gap-4 xl:grid-cols-[minmax(0,1fr)_minmax(22rem,0.7fr)]",children:[e.jsx(vt,{title:"Recent users",detail:"Last authenticated relay activity.",children:e.jsx("div",{className:"divide-y divide-[var(--theme-border)]",children:s.map(r=>e.jsxs("div",{className:"flex items-center justify-between gap-3 py-3",children:[e.jsxs("div",{className:"min-w-0",children:[e.jsx("p",{className:"truncate text-sm font-medium text-[var(--theme-fg)]",children:r.username}),e.jsx("p",{className:"truncate text-xs text-[var(--theme-fg-muted)]",children:r.email})]}),e.jsxs("div",{className:"text-right text-xs text-[var(--theme-fg-muted)]",children:[e.jsx("p",{children:Xe(r.lastSeenAt)}),e.jsxs("p",{children:[r.conversationCount," conversations"]})]})]},r.id))})}),e.jsx(vt,{title:"Online devices",detail:"Devices with an active supervisor tunnel.",children:a.length?e.jsx("div",{className:"space-y-3",children:a.map(r=>e.jsx(Gd,{device:r},r.id))}):e.jsx(ks,{children:"No supervisors are connected."})})]})}function Wd({busyKey:t,onDeleteUser:s,onResetPassword:a,onUpdateUser:r,users:o}){const[l,d]=n.useState(""),[u,p]=n.useState({key:"lastSeenAt",direction:"desc"}),[g,b]=n.useState(null),[x,N]=n.useState(null),v=n.useMemo(()=>{const h=Fr(l);return o.filter(D=>h?Fr(`${D.username} ${D.email}`).includes(h):!0).sort((D,H)=>Kd(D,H,u))},[l,u,o]);function c(h){p(D=>({key:h,direction:D.key===h&&D.direction==="desc"?"asc":"desc"}))}return e.jsxs(e.Fragment,{children:[e.jsxs(vt,{title:"Users",detail:"Registered relay accounts. Admin accounts are excluded from workspace and device operations.",children:[e.jsxs("div",{className:"mb-4 flex flex-col gap-3 lg:flex-row lg:items-center lg:justify-between",children:[e.jsxs("label",{className:"relative block min-w-0 flex-1",children:[e.jsx(z.Search,{className:"pointer-events-none absolute left-3 top-1/2 h-4 w-4 -translate-y-1/2 text-[var(--theme-fg-muted)]"}),e.jsx("input",{className:"relay-input w-full pl-9",onChange:h=>d(h.target.value),placeholder:"Search username or email",value:l})]}),e.jsxs("p",{className:"text-sm text-[var(--theme-fg-muted)]",children:[v.length.toLocaleString()," of"," ",o.length.toLocaleString()," users"]})]}),e.jsxs(ba,{minWidth:"68rem",children:[e.jsx("thead",{children:e.jsxs("tr",{children:[e.jsx($t,{active:u.key==="username",direction:u.direction,onClick:()=>c("username"),children:"User"}),e.jsx($t,{active:u.key==="enabled",direction:u.direction,onClick:()=>c("enabled"),children:"Status"}),e.jsx($t,{active:u.key==="lastSeenAt",direction:u.direction,onClick:()=>c("lastSeenAt"),children:"Last used"}),e.jsx($t,{active:u.key==="conversationCount",direction:u.direction,onClick:()=>c("conversationCount"),children:"Conversations"}),e.jsx($t,{active:u.key==="deviceCount",direction:u.direction,onClick:()=>c("deviceCount"),children:"Devices"}),e.jsx(_e,{children:"Role"}),e.jsx(_e,{children:"Actions"})]})}),e.jsx("tbody",{children:v.map(h=>e.jsxs("tr",{children:[e.jsxs(Le,{strong:!0,children:[h.username,e.jsx("div",{className:"text-xs font-normal text-[var(--theme-fg-muted)]",children:h.email})]}),e.jsx(Le,{children:e.jsx(zn,{active:h.enabled,children:h.enabled?"Enabled":"Disabled"})}),e.jsx(Le,{children:Xe(h.lastSeenAt)}),e.jsx(Le,{children:h.conversationCount.toLocaleString()}),e.jsx(Le,{children:h.deviceCount.toLocaleString()}),e.jsx(Le,{children:h.role}),e.jsx(Le,{children:e.jsxs("div",{className:"flex flex-wrap gap-2",children:[e.jsx("button",{className:"relay-button-secondary",disabled:t===h.id||h.role==="admin",onClick:()=>r(h.id,!h.enabled),type:"button",children:h.enabled?"Disable":"Enable"}),e.jsxs("button",{className:"relay-button-secondary inline-flex items-center gap-2",disabled:t===`reset:${h.id}`||h.role==="admin",onClick:()=>b(h),type:"button",children:[e.jsx(z.KeyRound,{className:"h-4 w-4"}),"Reset"]}),e.jsxs("button",{className:"relay-button-secondary inline-flex items-center gap-2 text-[var(--status-danger-fg)]",disabled:t===`delete:${h.id}`||h.role==="admin",onClick:()=>N(h),type:"button",children:[e.jsx(z.Trash2,{className:"h-4 w-4"}),"Delete"]})]})})]},h.id))})]}),v.length?null:e.jsx(ks,{children:"No users match the current search."})]}),g?e.jsx(zd,{busy:t===`reset:${g.id}`,onClose:()=>b(null),onSubmit:async h=>{await a(g.id,h),b(null)},user:g}):null,x?e.jsx(Jd,{busy:t===`delete:${x.id}`,confirmLabel:"Delete user",description:`Delete ${x.username}, their devices, shares, and access history. This cannot be undone.`,onClose:()=>N(null),onConfirm:async()=>{await s(x.id),N(null)},title:"Delete relay user"}):null]})}function Fd({devices:t,users:s}){const[a,r]=n.useState("all"),[o,l]=n.useState("all"),[d,u]=n.useState("all"),[p,g]=n.useState("lastActivity"),[b,x]=n.useState("desc"),N=n.useMemo(()=>s.filter(c=>t.some(h=>h.ownerUserId===c.id)),[t,s]),v=n.useMemo(()=>t.filter(c=>a==="all"||c.ownerUserId===a).filter(c=>o==="all"||(o==="online"?c.connected:!c.connected)).filter(c=>d==="all"||Xd(bs(c),d)).sort((c,h)=>Yd(c,h,p,b)),[d,t,b,a,p,o]);return e.jsxs(vt,{title:"Devices",detail:"Supervisor devices grouped by owner, connection state, activity, and loaded workspace metadata.",children:[e.jsxs("div",{className:"mb-4 grid gap-3 md:grid-cols-2 xl:grid-cols-5",children:[e.jsxs("label",{className:"block text-sm text-[var(--theme-fg-soft)]",children:["Owner",e.jsxs("select",{className:"relay-input mt-2 w-full",onChange:c=>r(c.target.value),value:a,children:[e.jsx("option",{value:"all",children:"All users"}),N.map(c=>e.jsx("option",{value:c.id,children:c.username},c.id))]})]}),e.jsxs("label",{className:"block text-sm text-[var(--theme-fg-soft)]",children:["Status",e.jsxs("select",{className:"relay-input mt-2 w-full",onChange:c=>l(c.target.value),value:o,children:[e.jsx("option",{value:"all",children:"All devices"}),e.jsx("option",{value:"online",children:"Online"}),e.jsx("option",{value:"offline",children:"Offline"})]})]}),e.jsxs("label",{className:"block text-sm text-[var(--theme-fg-soft)]",children:["Last activity",e.jsxs("select",{className:"relay-input mt-2 w-full",onChange:c=>u(c.target.value),value:d,children:[e.jsx("option",{value:"all",children:"Any time"}),e.jsx("option",{value:"24h",children:"Last 24 hours"}),e.jsx("option",{value:"7d",children:"Last 7 days"}),e.jsx("option",{value:"30d",children:"Last 30 days"})]})]}),e.jsxs("label",{className:"block text-sm text-[var(--theme-fg-soft)]",children:["Sort by",e.jsxs("select",{className:"relay-input mt-2 w-full",onChange:c=>g(c.target.value),value:p,children:[e.jsx("option",{value:"lastActivity",children:"Last activity"}),e.jsx("option",{value:"name",children:"Device name"}),e.jsx("option",{value:"ownerUsername",children:"Owner"}),e.jsx("option",{value:"connected",children:"Connection"}),e.jsx("option",{value:"createdAt",children:"Created"}),e.jsx("option",{value:"workspaceCount",children:"Workspaces"}),e.jsx("option",{value:"threadCount",children:"Threads"})]})]}),e.jsxs("label",{className:"block text-sm text-[var(--theme-fg-soft)]",children:["Direction",e.jsxs("select",{className:"relay-input mt-2 w-full",onChange:c=>x(c.target.value),value:b,children:[e.jsx("option",{value:"desc",children:"Descending"}),e.jsx("option",{value:"asc",children:"Ascending"})]})]})]}),e.jsxs(ba,{minWidth:"74rem",children:[e.jsx("thead",{children:e.jsxs("tr",{children:[e.jsx(_e,{children:"Device"}),e.jsx(_e,{children:"Owner"}),e.jsx(_e,{children:"Status"}),e.jsx(_e,{children:"Last activity"}),e.jsx(_e,{children:"Inventory"}),e.jsx(_e,{children:"Network"})]})}),e.jsx("tbody",{children:v.map(c=>{var h,D;return e.jsxs("tr",{children:[e.jsxs(Le,{strong:!0,children:[c.name,e.jsx("div",{className:"text-xs font-normal text-[var(--theme-fg-muted)]",children:c.tokenPreview})]}),e.jsxs(Le,{children:[e.jsx("span",{className:"font-medium text-[var(--theme-fg-soft)]",children:c.ownerUsername}),e.jsx("div",{className:"text-xs text-[var(--theme-fg-muted)]",children:c.ownerEmail})]}),e.jsx(Le,{children:e.jsx(zn,{active:c.connected,children:c.connected?"Online":"Offline"})}),e.jsxs(Le,{children:[Xe(bs(c)),e.jsxs("div",{className:"text-xs text-[var(--theme-fg-muted)]",children:["created ",Xe(c.createdAt)]})]}),e.jsxs(Le,{children:[e.jsxs("span",{children:[c.workspaces.length.toLocaleString()," workspaces"]}),e.jsx("span",{className:"mx-2 text-[var(--theme-fg-muted)]",children:"·"}),e.jsxs("span",{children:[c.threads.length.toLocaleString()," threads"]}),e.jsx("div",{className:"mt-1 truncate text-xs text-[var(--theme-fg-muted)]",children:((h=c.workspaces[0])==null?void 0:h.label)??"No workspace metadata"}),e.jsx("div",{className:"truncate text-xs text-[var(--theme-fg-muted)]",children:((D=c.threads[0])==null?void 0:D.title)??"No thread metadata"})]}),e.jsxs(Le,{children:[c.ipAddress??"IP unavailable",e.jsxs("div",{className:"text-xs text-[var(--theme-fg-muted)]",children:["heartbeat ",Xe(c.lastHeartbeatAt)]})]})]},c.id)})})]}),v.length?null:e.jsx(ks,{children:"No devices match the selected filters."})]})}function qd({shares:t}){return e.jsx(vt,{title:"Share relationships",detail:"Thread grants between relay users. Revoked grants remain visible for audit.",children:e.jsxs(ba,{minWidth:"62rem",children:[e.jsx("thead",{children:e.jsxs("tr",{children:[e.jsx(_e,{children:"Owner"}),e.jsx(_e,{children:"Target"}),e.jsx(_e,{children:"Thread"}),e.jsx(_e,{children:"Device"}),e.jsx(_e,{children:"Permissions"}),e.jsx(_e,{children:"Last access"}),e.jsx(_e,{children:"Status"})]})}),e.jsx("tbody",{children:t.map(s=>e.jsxs("tr",{children:[e.jsx(Le,{strong:!0,children:s.ownerUsername}),e.jsx(Le,{children:s.targetUsername}),e.jsxs(Le,{children:[e.jsx("span",{className:"font-medium text-[var(--theme-fg)]",children:s.threadTitle??s.label??"Thread unavailable"}),e.jsx("div",{className:"text-xs text-[var(--theme-fg-muted)]",children:s.workspaceLabel??"Workspace unavailable"})]}),e.jsx(Le,{children:s.deviceName}),e.jsxs(Le,{children:[s.threadAccess," /"," ",Qd(s.workspaceAccess)]}),e.jsx(Le,{children:Xe(s.lastAccessedAt)}),e.jsx(Le,{children:s.revokedAt?"Revoked":s.expiresAt&&s.expiresAt<=new Date().toISOString()?"Expired":"Active"})]},s.id))})]})})}function Vd({busy:t,draft:s,onChange:a,onReviewRegistration:r,onSave:o,pending:l,reviewBusyKey:d}){return e.jsxs("section",{className:"grid gap-4 xl:grid-cols-[minmax(0,0.9fr)_minmax(0,1.1fr)]",children:[e.jsx(vt,{title:"Registration settings",detail:"Stored in the relay database. Environment password seeds this once if empty.",children:e.jsxs("form",{className:"space-y-4",onSubmit:o,children:[e.jsx(Dt,{checked:s.enabled,label:"Open registration",onChange:u=>a({...s,enabled:u})}),e.jsxs("label",{className:"block text-sm text-[var(--theme-fg-soft)]",children:["Registration password",e.jsx("input",{className:"relay-input mt-2 w-full",onChange:u=>a({...s,registrationPassword:u.target.value}),placeholder:"Leave empty for no invite password",value:s.registrationPassword??""})]}),e.jsx(Dt,{checked:s.approvalRequired,label:"Require admin approval",onChange:u=>a({...s,approvalRequired:u})}),e.jsxs("div",{className:"space-y-3 border-t border-[var(--theme-border)] pt-4",children:[e.jsx(Dt,{checked:s.googleAuthEnabled,disabled:!s.googleAuthAvailable,label:"Enable Google authentication",onChange:u=>a({...s,googleAuthEnabled:u})}),e.jsx(Dt,{checked:s.githubAuthEnabled,disabled:!s.githubAuthAvailable,label:"Enable GitHub authentication",onChange:u=>a({...s,githubAuthEnabled:u})}),e.jsx(Dt,{checked:s.emailVerificationEnabled,disabled:!s.emailVerificationAvailable,label:"Enable email verification",onChange:u=>a({...s,emailVerificationEnabled:u})}),s.emailVerificationAvailable?null:e.jsx("p",{className:"text-xs text-[var(--theme-fg-muted)]",children:"Configure the email provider and verification secret to enable this option."})]}),e.jsxs("button",{className:"relay-button-primary inline-flex items-center gap-2",disabled:t,type:"submit",children:[e.jsx(z.Settings,{className:"h-4 w-4"}),"Save settings"]})]})}),e.jsx(vt,{title:"Pending registrations",detail:"Approve creates the user. Reject keeps an audit trail.",children:l.length?e.jsx("div",{className:"divide-y divide-[var(--theme-border)]",children:l.map(u=>e.jsxs("div",{className:"flex flex-col gap-3 py-3 sm:flex-row sm:items-center sm:justify-between",children:[e.jsxs("div",{className:"min-w-0",children:[e.jsx("p",{className:"truncate text-sm font-medium text-[var(--theme-fg)]",children:u.username}),e.jsxs("p",{className:"truncate text-xs text-[var(--theme-fg-muted)]",children:[u.email," · ",Xe(u.createdAt)]})]}),e.jsxs("div",{className:"flex gap-2",children:[e.jsxs("button",{className:"relay-button-primary inline-flex items-center gap-2",disabled:d===`approve:${u.id}`,onClick:()=>r(u.id,"approve"),type:"button",children:[e.jsx(z.Check,{className:"h-4 w-4"}),"Approve"]}),e.jsx("button",{className:"relay-button-secondary",disabled:d===`reject:${u.id}`,onClick:()=>r(u.id,"reject"),type:"button",children:"Reject"})]})]},u.id))}):e.jsx(ks,{children:"No pending applications."})})]})}function Gd({device:t}){return e.jsxs("div",{className:"grid gap-2 text-xs text-[var(--theme-fg-muted)] sm:grid-cols-2",children:[e.jsxs("p",{children:["Owner:"," ",e.jsx("span",{className:"text-[var(--theme-fg-soft)]",children:t.ownerEmail})]}),e.jsxs("p",{children:["IP:"," ",e.jsx("span",{className:"text-[var(--theme-fg-soft)]",children:t.ipAddress??"unavailable"})]}),e.jsxs("p",{children:["Connected:"," ",e.jsx("span",{className:"text-[var(--theme-fg-soft)]",children:Xe(t.connectedAt)})]}),e.jsxs("p",{children:["Heartbeat:"," ",e.jsx("span",{className:"text-[var(--theme-fg-soft)]",children:Xe(t.lastHeartbeatAt)})]})]})}function vt({aside:t,children:s,detail:a,title:r}){return e.jsxs("section",{className:"rounded-lg border border-[var(--theme-border)] bg-[var(--theme-panel)] p-4",children:[e.jsxs("div",{className:"mb-4 flex items-start justify-between gap-3",children:[e.jsxs("div",{children:[e.jsx("h2",{className:"text-base font-semibold text-[var(--theme-fg)]",children:r}),e.jsx("p",{className:"mt-1 text-sm text-[var(--theme-fg-muted)]",children:a})]}),t]}),s]})}function ba({children:t,minWidth:s}){return e.jsx("div",{className:"overflow-x-auto",children:e.jsx("table",{className:"w-full border-collapse text-left text-sm",style:{minWidth:s},children:t})})}function _e({children:t}){return e.jsx("th",{className:"border-b border-[var(--theme-border)] py-2 pr-3 text-xs font-semibold uppercase tracking-[0.14em] text-[var(--theme-fg-muted)]",children:t})}function $t({active:t,children:s,direction:a,onClick:r}){const o=t?a==="asc"?z.ArrowUp:z.ArrowDown:z.ArrowUpDown;return e.jsx("th",{className:"border-b border-[var(--theme-border)] py-2 pr-3 text-left text-xs font-semibold uppercase tracking-[0.14em] text-[var(--theme-fg-muted)]",children:e.jsxs("button",{className:`inline-flex items-center gap-1.5 rounded-md px-1.5 py-1 transition hover:bg-[var(--theme-hover)] hover:text-[var(--theme-fg)] ${t?"text-[var(--theme-fg)]":""}`,onClick:r,type:"button",children:[s,e.jsx(o,{className:"h-3.5 w-3.5"})]})})}function Le({children:t,strong:s=!1}){return e.jsx("td",{className:`border-b border-[var(--theme-border)] py-3 pr-3 ${s?"font-medium text-[var(--theme-fg)]":"text-[var(--theme-fg-muted)]"}`,children:t})}function Dt({checked:t,disabled:s=!1,label:a,onChange:r}){return e.jsxs("label",{className:`flex items-center gap-3 text-sm ${s?"text-[var(--theme-fg-muted)] opacity-60":"text-[var(--theme-fg-soft)]"}`,children:[e.jsx("input",{checked:t,disabled:s,className:"h-4 w-4 accent-[var(--theme-accent)]",onChange:o=>r(o.target.checked),type:"checkbox"}),a]})}function zn({active:t,children:s}){return e.jsx("span",{className:`rounded-full border px-2 py-0.5 text-xs ${t?"border-[var(--status-success-border)] bg-[var(--status-success-bg)] text-[var(--status-success-fg)]":"border-[var(--theme-border)] bg-[var(--theme-surface)] text-[var(--theme-fg-muted)]"}`,children:s})}function ks({children:t}){return e.jsx("p",{className:"rounded-lg border border-dashed border-[var(--theme-border)] bg-[var(--theme-surface)] p-4 text-sm text-[var(--theme-fg-muted)]",children:t})}function zd({busy:t,onClose:s,onSubmit:a,user:r}){const[o,l]=n.useState(""),[d,u]=n.useState(null);async function p(g){if(g.preventDefault(),u(null),o.length<8){u("Password must be at least 8 characters.");return}await a(o)}return e.jsx("div",{className:"fixed inset-0 z-50 flex items-center justify-center bg-[color-mix(in_oklch,var(--app-bg)_82%,transparent)] px-4 py-8",children:e.jsxs("section",{className:"w-full max-w-md rounded-lg border border-[var(--theme-border)] bg-[var(--theme-panel)] p-5 shadow-2xl shadow-[color-mix(in_oklch,var(--app-fg)_18%,transparent)]",children:[e.jsx("h2",{className:"text-lg font-semibold text-[var(--theme-fg)]",children:"Reset password"}),e.jsxs("p",{className:"mt-1 text-sm text-[var(--theme-fg-muted)]",children:["Set a new relay password for ",r.username,"."]}),e.jsxs("form",{className:"mt-5 space-y-4",onSubmit:p,children:[e.jsxs("label",{className:"block text-sm text-[var(--theme-fg-soft)]",children:["New password",e.jsx("input",{autoFocus:!0,className:"relay-input mt-2 w-full",onChange:g=>l(g.target.value),type:"password",value:o})]}),d?e.jsx("p",{className:"rounded-lg border border-[var(--status-danger-border)] bg-[var(--status-danger-bg)] px-3 py-2 text-sm text-[var(--status-danger-fg)]",children:d}):null,e.jsxs("div",{className:"flex justify-end gap-2",children:[e.jsx("button",{className:"relay-button-secondary",onClick:s,type:"button",children:"Cancel"}),e.jsxs("button",{className:"relay-button-primary inline-flex items-center gap-2",disabled:t,type:"submit",children:[e.jsx(z.KeyRound,{className:"h-4 w-4"}),"Save password"]})]})]})]})})}function Jd({busy:t,confirmLabel:s,description:a,onClose:r,onConfirm:o,title:l}){return e.jsx("div",{className:"fixed inset-0 z-50 flex items-center justify-center bg-[color-mix(in_oklch,var(--app-bg)_82%,transparent)] px-4 py-8",children:e.jsxs("section",{className:"w-full max-w-md rounded-lg border border-[var(--status-danger-border)] bg-[var(--theme-panel)] p-5 shadow-2xl shadow-[color-mix(in_oklch,var(--app-fg)_18%,transparent)]",children:[e.jsx("h2",{className:"text-lg font-semibold text-[var(--theme-fg)]",children:l}),e.jsx("p",{className:"mt-2 text-sm leading-6 text-[var(--theme-fg-muted)]",children:a}),e.jsxs("div",{className:"mt-5 flex justify-end gap-2",children:[e.jsx("button",{className:"relay-button-secondary",onClick:r,type:"button",children:"Cancel"}),e.jsxs("button",{className:"inline-flex h-10 items-center gap-2 rounded-md bg-[var(--action-danger-bg)] px-4 text-sm font-semibold text-[var(--action-danger-fg)] transition hover:bg-[var(--action-danger-bg-hover)] disabled:cursor-not-allowed disabled:opacity-60",disabled:t,onClick:o,type:"button",children:[e.jsx(z.Trash2,{className:"h-4 w-4"}),s]})]})]})})}function Fr(t){return t.trim().toLowerCase()}function Kd(t,s,a){const r=a.direction==="asc"?1:-1;let o=0;return a.key==="username"?o=t.username.localeCompare(s.username):a.key==="enabled"?o=Number(t.enabled)-Number(s.enabled):a.key==="lastSeenAt"?o=vs(t.lastSeenAt,s.lastSeenAt):a.key==="conversationCount"?o=t.conversationCount-s.conversationCount:a.key==="deviceCount"?o=t.deviceCount-s.deviceCount:o=vs(t.createdAt,s.createdAt),o*r||t.username.localeCompare(s.username)}function Yd(t,s,a,r){const o=r==="asc"?1:-1;let l=0;return a==="name"?l=t.name.localeCompare(s.name):a==="ownerUsername"?l=t.ownerUsername.localeCompare(s.ownerUsername):a==="connected"?l=Number(t.connected)-Number(s.connected):a==="lastActivity"?l=vs(bs(t),bs(s)):a==="createdAt"?l=vs(t.createdAt,s.createdAt):a==="workspaceCount"?l=t.workspaces.length-s.workspaces.length:l=t.threads.length-s.threads.length,l*o||t.name.localeCompare(s.name)}function vs(t,s){const a=Date.parse(t??""),r=Date.parse(s??""),o=Number.isFinite(a)?a:-1/0,l=Number.isFinite(r)?r:-1/0;return o-l}function bs(t){return t.lastHeartbeatAt??t.connectedAt??t.createdAt}function Xd(t,s){const a=Date.parse(t??"");if(!Number.isFinite(a))return!1;const r=s==="24h"?24:s==="7d"?168:720;return a>=Date.now()-r*60*60*1e3}function qr(t,s){return t&&{...t,users:t.users.map(a=>a.id===s.id?{...a,...s}:a)}}function Zd(t){switch(t){case"overview":return"Overview";case"users":return"Users";case"devices":return"Devices";case"hosted":return"Hosted VMs";case"shares":return"Shares";case"settings":return"Settings"}}function Qd(t){switch(t){case"write":return"workspace write";case"read":return"workspace read";case"none":default:return"no workspace"}}function ec(t){return(s,a)=>Date.parse(a[t]??"")-Date.parse(s[t]??"")}function Xe(t){return t?new Date(t).toLocaleString():"never"}function tc(t,s){const a=Date.parse(t);if(!Number.isFinite(a))return"unknown";const r=Math.max(0,Math.floor((s-a)/6e4)),o=Math.floor(r/1440),l=Math.floor(r%1440/60),d=r%60;return o>0?`${o}d ${l}h`:l>0?`${l}h ${d}m`:`${d}m`}function sc(t){const s=(t==null?void 0:t.trim())??"";return s?Array.from(s).slice(0,2).join("").toUpperCase():"??"}function ac(t){const s=(t==null?void 0:t.trim())??"";return s?Array.from(s).slice(0,2).join("").toUpperCase():"??"}function ya({className:t="",menuAlign:s="left"}){const a=rt(),r=qt(),[o,l]=n.useState(null),[d,u]=n.useState(!1),[p,g]=n.useState(!1);n.useEffect(()=>{if(!ht())return;let c=!1;return Et().then(h=>{c||l(h.authenticated?h:null)}).catch(()=>{c||l(null)}),()=>{c=!0}},[r.pathname]),n.useEffect(()=>{u(!1),g(!1)},[r.pathname]);const b=(o==null?void 0:o.user)??null,x=n.useMemo(()=>ac(b==null?void 0:b.username),[b==null?void 0:b.username]),N=p&&typeof document<"u"?vn.createPortal(e.jsx("div",{"aria-modal":"true",className:"fixed inset-0 z-[1000] flex items-start justify-center overflow-y-auto bg-black/55 px-4 py-6 backdrop-blur-sm sm:py-10",role:"dialog",children:e.jsxs("section",{className:"w-full max-w-3xl rounded-xl border border-[var(--theme-border)] bg-[var(--theme-panel)] shadow-[var(--theme-shadow)]",children:[e.jsxs("header",{className:"flex items-start justify-between gap-4 border-b border-[var(--theme-border)] px-5 py-4",children:[e.jsxs("div",{children:[e.jsx("p",{className:"text-xs font-semibold uppercase tracking-[0.22em] text-[var(--theme-fg-muted)]",children:"Relay Account"}),e.jsx("h2",{className:"mt-1 text-xl font-semibold text-[var(--theme-fg)]",children:"Account settings"})]}),e.jsx("button",{"aria-label":"Close account settings",className:"inline-flex h-9 w-9 shrink-0 items-center justify-center rounded-full border border-[var(--theme-border)] bg-[var(--theme-surface)] text-[var(--theme-fg)] transition hover:bg-[var(--theme-hover)] focus:outline-none focus:ring-2 focus:ring-[var(--theme-accent-ring)]",onClick:()=>g(!1),type:"button",children:e.jsx(z.X,{className:"h-4 w-4"})})]}),e.jsx("div",{className:"max-h-[min(78vh,48rem)] overflow-y-auto p-5",children:e.jsx(Gn,{})})]})}),document.body):null;if(!ht()||!b)return null;async function v(){await Zl(),l(null),a("/relay-portal")}return e.jsxs("div",{className:`relative z-50 inline-flex shrink-0 ${t}`.trim(),children:[e.jsx("button",{"aria-expanded":d,"aria-haspopup":"menu","aria-label":`Relay account menu for ${b.username}`,className:"inline-flex h-9 w-9 items-center justify-center rounded-full border border-[var(--theme-border)] bg-[var(--theme-surface-strong)] text-sm font-semibold text-[var(--theme-fg)] transition hover:bg-[var(--theme-hover)] focus:outline-none focus:ring-2 focus:ring-[var(--theme-accent-ring)]",onClick:()=>u(c=>!c),type:"button",children:x}),d?e.jsxs("div",{className:`absolute mt-2 w-64 overflow-hidden rounded-lg border border-[var(--theme-border)] bg-[var(--theme-panel)] p-1 shadow-[var(--theme-shadow)] ${s==="right"?"right-0":"left-0"}`,role:"menu",children:[e.jsxs("div",{className:"border-b border-[var(--theme-border)] px-3 py-2",children:[e.jsx("p",{className:"truncate text-sm font-medium text-[var(--theme-fg)]",children:b.username}),e.jsx("p",{className:"truncate text-xs text-[var(--theme-fg-muted)]",children:b.email})]}),e.jsxs("button",{className:"flex w-full items-center gap-2 rounded-lg px-3 py-2 text-left text-sm text-[var(--theme-fg)] transition hover:bg-[var(--theme-hover)]",onClick:()=>{u(!1),g(!0)},role:"menuitem",type:"button",children:[e.jsx(z.Settings,{className:"h-4 w-4"}),"Account settings"]}),e.jsxs(Be,{className:"flex items-center gap-2 rounded-lg px-3 py-2 text-sm text-[var(--theme-fg)] transition hover:bg-[var(--theme-hover)]",role:"menuitem",to:"/relay-devices",children:[e.jsx(z.MonitorSmartphone,{className:"h-4 w-4"}),"Device management"]}),e.jsxs("button",{className:"flex w-full items-center gap-2 rounded-lg px-3 py-2 text-left text-sm text-[var(--status-danger-fg)] transition hover:bg-[var(--status-danger-bg)]",onClick:()=>void v(),role:"menuitem",type:"button",children:[e.jsx(z.LogOut,{className:"h-4 w-4"}),"Logout"]})]}):null,N]})}const rc=3e3,nc={unix:45679,windows:45680};function ut(t,s){return t instanceof ce?t.payload.message:t instanceof Error?t.message:s}function oc(t,s){return t?{...s,sharedWithMe:Vr(t.sharedWithMe,s.sharedWithMe),sharedByMe:Vr(t.sharedByMe,s.sharedByMe),sharedDevicesWithMe:qs(t.sharedDevicesWithMe??[],s.sharedDevicesWithMe??[]),sharedThreadsWithMe:qs(t.sharedThreadsWithMe??[],s.sharedThreadsWithMe??[]),grantsByMe:qs(t.grantsByMe??[],s.grantsByMe??[])}:lc(s)}function lc(t){return{...t,sharedWithMe:t.sharedWithMe.map(ua),sharedByMe:t.sharedByMe.map(ua),sharedDevicesWithMe:(t.sharedDevicesWithMe??[]).map(fs),sharedThreadsWithMe:(t.sharedThreadsWithMe??[]).map(fs),grantsByMe:(t.grantsByMe??[]).map(fs)}}function Vr(t,s){const a=new Map(t.map(r=>[r.id,r]));return s.map(r=>{const o=a.get(r.id);if(!o)return ua(r);const l=ys(r),d=ys(o);return{...r,threadTitle:l??d,workspaceLabel:r.workspaceLabel??o.workspaceLabel}})}function ua(t){return{...t,threadTitle:ys(t)}}function qs(t,s){const a=new Map(t.map(r=>[r.id,r]));return s.map(r=>{var u;const o=a.get(r.id);if(!o)return fs(r);const l=Ft(r),d=Ft(o);return{...r,threadTitle:l??d,workspaceLabel:r.workspaceLabel??o.workspaceLabel,deviceName:((u=r.deviceName)==null?void 0:u.trim())||o.deviceName}})}function fs(t){return{...t,threadTitle:Ft(t)}}function ic(){const t=rt(),[s,a]=ma(),[r,o]=n.useState(null),[l,d]=n.useState(""),[u,p]=n.useState(null),[g,b]=n.useState(null),[x,N]=n.useState(!0),[v,c]=n.useState(null),[h,D]=n.useState(null),[H,O]=n.useState(null),[E,U]=n.useState(null),[G,te]=n.useState(null),[Q,I]=n.useState(null),[se,J]=n.useState(null),[ee,i]=n.useState(null),[W,fe]=n.useState(!1),ae=n.useRef(!1),we=n.useRef(null),ge=n.useRef(null),Ne=n.useCallback(async T=>{const f=(T==null?void 0:T.showLoading)??!0,j=(T==null?void 0:T.clearError)??!0;f&&N(!0),j&&D(null);try{Ze();const $=await Un();ae.current=!0,o(re=>oc(re,$))}catch($){(f||!ae.current)&&D(ut($,"Unable to load devices."))}finally{f&&N(!1)}},[]);n.useEffect(()=>{Ne();const T=window.setInterval(()=>{Ne({showLoading:!1,clearError:!1})},rc);return()=>{window.clearInterval(T)}},[Ne]),n.useEffect(()=>()=>{ge.current!==null&&window.clearTimeout(ge.current)},[]),n.useEffect(()=>{const T=s.get("shareDevice");if(!T||!r||we.current===T)return;const f=r.devices.find($=>$.id===T);if(!f)return;we.current=T,i(f);const j=new URLSearchParams(s);j.delete("shareDevice"),a(j,{replace:!0})},[r,s,a]);async function K(T){T.preventDefault(),c("create"),D(null);try{const f=await ei({name:l});p(f),d(""),fe(!1),await Ne({showLoading:!1})}catch(f){D(ut(f,"Unable to create device."))}finally{c(null)}}async function M(T){if(window.confirm(`Delete relay device "${T.name}"?`)){c(T.id),D(null);try{await ti(T.id),(u==null?void 0:u.device.id)===T.id&&p(null),await Ne({showLoading:!1})}catch(f){D(ut(f,"Unable to delete device."))}finally{c(null)}}}function ne(T){ms(T.id),hs(null),t(sa(T.id))}function P(T){ms(T.deviceId),hs(T.threadId),t(ta(T.threadId,T.deviceId))}function V(T){if(ms(T.deviceId),hs(T.threadId),T.threadId){t(ta(T.threadId,T.deviceId));return}t(sa(T.deviceId))}async function Y(T,f){c(`grant:create:${T.id}`),D(null);try{await oi({...f,deviceId:T.id,scope:"device",workspaceScope:"all",workspaceIds:[]}),i(null),await Ne({showLoading:!1})}catch(j){D(ut(j,"Unable to share device."))}finally{c(null)}}async function Ce(T,f){c(`grant:${T.id}`),D(null);try{await li(T.id,{...f,workspaceId:T.workspaceId,workspaceScope:T.workspaceScope,workspaceIds:T.workspaceIds}),I(null),await Ne({showLoading:!1})}catch(j){D(ut(j,"Unable to update shared access."))}finally{c(null)}}async function De(T){c(`grant:${T.id}`),D(null);try{await ii(T.id),U(f=>f===T.id?null:f),J(null),await Ne({showLoading:!1})}catch(f){D(ut(f,"Unable to remove shared access."))}finally{c(null)}}async function qe(T,f){c(`share:${T.id}`),D(null);try{await ni(T.id,{...f,workspaceId:T.workspaceId}),te(null),await Ne({showLoading:!1})}catch(j){D(ut(j,"Unable to update shared thread."))}finally{c(null)}}async function be(T){c(`share:${T.id}`),D(null);try{await $n(T.id),O(f=>f===T.id?null:f),J(null),await Ne({showLoading:!1})}catch(f){D(ut(f,"Unable to remove shared thread access."))}finally{c(null)}}async function B(T,f){var $;const j=T.token;if(!j){D("This device token is not available. Create a new device token for devices created before token storage was enabled.");return}try{await(($=navigator.clipboard)==null?void 0:$.writeText(Jn(j,f))),b(T.id),ge.current!==null&&window.clearTimeout(ge.current),ge.current=window.setTimeout(()=>{b(re=>re===T.id?null:re),ge.current=null},1600)}catch{}}const L=(r==null?void 0:r.sharedDevicesWithMe)??[],le=(r==null?void 0:r.grantsByMe)??[];return e.jsxs("main",{className:"min-h-screen bg-[var(--app-bg)] px-4 pb-6 text-[var(--app-fg)] sm:px-6",children:[e.jsxs("div",{className:"mx-auto w-full max-w-[1600px] space-y-5",children:[e.jsx("header",{className:"host-topbar sticky top-[env(safe-area-inset-top)] z-30 -mx-4 border-b px-2.5 py-2 backdrop-blur sm:mx-0 sm:rounded-lg sm:border sm:px-4",children:e.jsxs("div",{className:"flex min-w-0 items-center gap-1.5 sm:gap-2",children:[e.jsx(ya,{}),e.jsx(Be,{className:"host-info-pill inline-flex h-8 shrink-0 items-center rounded-md border px-2.5 text-[11px] font-medium uppercase tracking-[0.14em] transition sm:px-3 sm:text-xs sm:tracking-[0.18em]",to:"/",children:"Relay home"}),e.jsx("div",{className:"min-w-0 flex-1 text-right",children:e.jsx("p",{className:"host-page-eyebrow truncate text-[11px] uppercase tracking-[0.24em]",children:"Relay portal"})})]})}),e.jsxs("section",{className:"border-b border-[var(--theme-border)] pb-4",children:[e.jsx("p",{className:"text-xs font-semibold uppercase tracking-[0.22em] text-[var(--theme-fg-muted)]",children:"Relay portal"}),e.jsx("h1",{className:"mt-1 text-2xl font-semibold text-[var(--theme-fg)]",children:"Devices and shared sessions"})]}),h?e.jsx(gc,{tone:"danger",children:h}):null,u?e.jsx(xc,{result:u}):null,e.jsxs("section",{className:"grid gap-4 xl:grid-cols-[minmax(42rem,0.9fr)_minmax(0,1.1fr)]",children:[e.jsxs("section",{className:"rounded-lg border border-[var(--theme-border)] bg-[var(--theme-panel)] p-4",children:[e.jsxs("div",{className:"mb-4 flex items-center justify-between gap-3",children:[e.jsxs("div",{children:[e.jsx("h2",{className:"text-base font-semibold text-[var(--theme-fg)]",children:"Devices"}),e.jsx("p",{className:"mt-1 text-sm text-[var(--theme-fg-muted)]",children:"Connect to an online device before opening workspaces."})]}),e.jsxs("button",{className:"relay-button-secondary inline-flex h-9 shrink-0 items-center gap-2 px-3",onClick:()=>fe(!0),type:"button",children:[e.jsx(z.Plus,{className:"h-4 w-4"}),"Add"]})]}),x?e.jsx("p",{className:"rounded-lg border border-[var(--theme-border)] bg-[var(--theme-surface)] p-4 text-sm text-[var(--theme-fg-muted)]",children:"Loading devices..."}):r!=null&&r.devices.length?e.jsx("div",{className:"space-y-3",children:r.devices.map(T=>e.jsx(pc,{busy:v===T.id,copiedSetup:g===T.id,device:T,onConnect:()=>ne(T),onCopySetup:f=>void B(T,f),onDelete:()=>void M(T),onShare:()=>i(T),setupTokenAvailable:!!T.token},T.id))}):e.jsx("div",{className:"rounded-lg border border-dashed border-[var(--theme-border)] bg-[var(--theme-surface)] p-5 text-sm text-[var(--theme-fg-muted)]",children:"No devices yet. Create a token, then start `remote-codex relay-supervisor` on your private machine."})]}),e.jsxs("div",{className:"space-y-4",children:[e.jsx(Gr,{count:(r==null?void 0:r.sharedWithMe.length)??0,emptyText:"No sessions have been shared with this account yet.",loading:x,loadingText:"Loading shared sessions...",shares:(r==null?void 0:r.sharedWithMe)??[],title:"Shared with me",subtitle:"Sessions another relay user has shared with this account.",renderShare:T=>e.jsx(Jr,{mode:"incoming",share:T,onOpen:()=>P(T)},T.id)}),e.jsx(zr,{emptyText:"No devices have been shared with this account yet.",grants:L,loading:x,loadingText:"Loading shared devices...",title:"Shared devices",subtitle:"Devices another relay user has shared with this account.",renderDevice:T=>e.jsx(Kr,{grants:T.grants,mode:"incoming",onOpen:V},T.deviceId)}),e.jsx(zr,{emptyText:"No devices have been shared by this account yet.",grants:le,loading:x,loadingText:"Loading shared devices...",title:"Shared devices by me",subtitle:"Devices this relay account has shared with other users.",renderDevice:T=>e.jsx(Kr,{busyGrantId:v!=null&&v.startsWith("grant:")?v.slice(6):null,expandedGrantId:E,grants:T.grants,mode:"outgoing",onOpen:V,onEdit:I,onRevoke:f=>J({kind:"grant",grant:f}),onToggleAccess:f=>{U(j=>j===f.id?null:f.id)}},T.deviceId)}),e.jsx(Gr,{count:(r==null?void 0:r.sharedByMe.length)??0,emptyText:"No threads have been shared by this account yet.",loading:x,loadingText:"Loading shared threads...",shares:(r==null?void 0:r.sharedByMe)??[],title:"Shared threads by me",subtitle:"Threads this relay account has shared with other users.",renderShare:T=>e.jsx(Jr,{busy:v===`share:${T.id}`,expanded:H===T.id,mode:"outgoing",share:T,onOpen:()=>P(T),onEdit:()=>te(T),onRevoke:()=>J({kind:"share",share:T}),onToggleAccess:()=>{O(f=>f===T.id?null:T.id)}},T.id)})]})]})]}),W?e.jsx(dc,{busy:v==="create",deviceName:l,onChangeDeviceName:d,onClose:()=>fe(!1),onSubmit:K}):null,G?e.jsx(mc,{busy:v===`share:${G.id}`,share:G,onClose:()=>te(null),onSave:T=>void qe(G,T)}):null,Q?e.jsx(fc,{busy:v===`grant:${Q.id}`,grant:Q,onClose:()=>I(null),onSave:T=>void Ce(Q,T)}):null,ee?e.jsx(hc,{busy:v===`grant:create:${ee.id}`,device:ee,onClose:()=>i(null),onShare:T=>void Y(ee,T)}):null,e.jsx(js,{open:se!==null,title:(se==null?void 0:se.kind)==="grant"?"Revoke shared device access":"Revoke shared thread access",description:se?yc(se):"",confirmLabel:"Revoke access",busyLabel:"Revoking...",busy:Qr(se,v),onCancel:()=>{Qr(se,v)||J(null)},onConfirm:()=>{if(se)return se.kind==="grant"?De(se.grant):be(se.share)}})]})}function dc({busy:t,deviceName:s,onChangeDeviceName:a,onClose:r,onSubmit:o}){return e.jsx("div",{className:"fixed inset-0 z-50 flex items-center justify-center bg-[color-mix(in_oklch,var(--app-bg)_82%,transparent)] px-4 py-6",children:e.jsxs("form",{className:"w-full max-w-md rounded-lg border border-[var(--theme-border)] bg-[var(--theme-panel)] p-5 shadow-2xl",onSubmit:o,children:[e.jsxs("div",{className:"flex items-start justify-between gap-4",children:[e.jsxs("div",{children:[e.jsx("p",{className:"text-xs font-semibold uppercase tracking-[0.22em] text-[var(--theme-fg-muted)]",children:"Relay device"}),e.jsx("h2",{className:"mt-1 text-lg font-semibold text-[var(--theme-fg)]",children:"Add device"}),e.jsx("p",{className:"mt-1 text-sm text-[var(--theme-fg-muted)]",children:"Create a token for one private supervisor."})]}),e.jsx("button",{"aria-label":"Close add device dialog",className:"inline-flex h-9 w-9 shrink-0 items-center justify-center rounded-lg border border-[var(--theme-border)] bg-[var(--theme-surface)] text-[var(--theme-fg-muted)] transition hover:bg-[var(--theme-hover)] hover:text-[var(--theme-fg)]",onClick:r,type:"button",children:e.jsx(z.X,{className:"h-4 w-4"})})]}),e.jsxs("label",{className:"mt-5 block text-sm text-[var(--theme-fg-soft)]",children:["Device name",e.jsx("input",{autoFocus:!0,className:"relay-input mt-2 w-full",onChange:l=>a(l.target.value),placeholder:"MacBook Pro",value:s})]}),e.jsxs("div",{className:"mt-5 flex justify-end gap-2",children:[e.jsx("button",{className:"relay-button-secondary",disabled:t,onClick:r,type:"button",children:"Cancel"}),e.jsxs("button",{className:"relay-button-primary inline-flex items-center gap-2",disabled:t||!s.trim(),type:"submit",children:[e.jsx(z.MonitorSmartphone,{className:"h-4 w-4"}),"Create device token"]})]})]})})}function Gr({count:t,emptyText:s,loading:a,loadingText:r,renderShare:o,shares:l,subtitle:d,title:u}){return e.jsxs("section",{className:"rounded-lg border border-[var(--theme-border)] bg-[var(--theme-panel)] p-4",children:[e.jsxs("div",{className:"mb-4 flex items-center justify-between gap-3",children:[e.jsxs("div",{children:[e.jsx("h2",{className:"text-base font-semibold text-[var(--theme-fg)]",children:u}),e.jsx("p",{className:"mt-1 text-sm text-[var(--theme-fg-muted)]",children:d})]}),e.jsx("span",{className:"rounded-full border border-[var(--theme-border)] px-2 py-0.5 text-xs text-[var(--theme-fg-muted)]",children:t})]}),a?e.jsx("p",{className:"rounded-lg border border-[var(--theme-border)] bg-[var(--theme-surface)] p-4 text-sm text-[var(--theme-fg-muted)]",children:r}):l.length?e.jsx("div",{className:"grid gap-3",children:l.map(p=>o(p))}):e.jsx("div",{className:"rounded-lg border border-dashed border-[var(--theme-border)] bg-[var(--theme-surface)] p-5 text-sm text-[var(--theme-fg-muted)]",children:s})]})}function cc(t){const s=new Map;for(const r of t){const o=s.get(r.deviceId);o?o.push(r):s.set(r.deviceId,[r])}const a={device:0,workspace:1,thread:2};return[...s].map(([r,o])=>({deviceId:r,grants:[...o].sort((l,d)=>a[l.scope]-a[d.scope]||(l.workspaceLabel??"").localeCompare(d.workspaceLabel??"")||(l.threadTitle??"").localeCompare(d.threadTitle??""))}))}function zr({emptyText:t,grants:s,loading:a,loadingText:r,renderDevice:o,subtitle:l,title:d}){const u=cc(s);return e.jsxs("section",{className:"rounded-lg border border-[var(--theme-border)] bg-[var(--theme-panel)] p-4",children:[e.jsxs("div",{className:"mb-4 flex items-center justify-between gap-3",children:[e.jsxs("div",{children:[e.jsx("h2",{className:"text-base font-semibold text-[var(--theme-fg)]",children:d}),e.jsx("p",{className:"mt-1 text-sm text-[var(--theme-fg-muted)]",children:l})]}),e.jsx("span",{className:"rounded-full border border-[var(--theme-border)] px-2 py-0.5 text-xs text-[var(--theme-fg-muted)]",children:u.length})]}),a?e.jsx("p",{className:"rounded-lg border border-[var(--theme-border)] bg-[var(--theme-surface)] p-4 text-sm text-[var(--theme-fg-muted)]",children:r}):u.length?e.jsx("div",{className:"grid gap-3",children:u.map(p=>o(p))}):e.jsx("div",{className:"rounded-lg border border-dashed border-[var(--theme-border)] bg-[var(--theme-surface)] p-5 text-sm text-[var(--theme-fg-muted)]",children:t})]})}function Jr({busy:t=!1,expanded:s=!1,mode:a,onEdit:r,onRevoke:o,onToggleAccess:l,share:d,onOpen:u}){var v,c;const p=wa(d),g=p,b=((v=d.label)==null?void 0:v.trim())||null,x=((c=d.workspaceLabel)==null?void 0:c.trim())||"Workspace unavailable",N=d.lastAccessedAt?`${d.lastAccessedByUsername??"unknown"} at ${Rt(d.lastAccessedAt)}`:"Not accessed yet";return e.jsxs("article",{className:"relative rounded-lg border border-[var(--theme-border)] bg-[var(--theme-surface)] p-3",children:[e.jsxs("div",{className:"flex flex-col gap-3 sm:flex-row sm:items-center sm:justify-between",children:[e.jsxs("div",{className:"min-w-0 flex-1",children:[e.jsx("p",{className:"truncate text-sm font-medium text-[var(--theme-fg)]",children:p}),e.jsxs("div",{className:"mt-1 space-y-0.5 text-xs text-[var(--theme-fg-muted)]",children:[e.jsxs("p",{className:"truncate",children:["Workspace:"," ",e.jsx("span",{className:"text-[var(--theme-fg-soft)]",children:x})]}),e.jsxs("p",{className:"truncate",children:["Thread:"," ",e.jsx("span",{className:"text-[var(--theme-fg-soft)]",children:g})]}),b?e.jsxs("p",{className:"truncate",children:["Label:"," ",e.jsx("span",{className:"text-[var(--theme-fg-soft)]",children:b})]}):null,e.jsx("p",{className:"truncate",children:a==="incoming"?`From ${d.ownerUsername}`:`To ${d.targetUsername}`}),e.jsxs("p",{className:"truncate",children:["Device: ",d.deviceName]})]}),a==="outgoing"?e.jsxs("p",{className:"mt-1 text-xs text-[var(--theme-fg-soft)]",children:["Last access: ",N]}):null,e.jsxs("p",{className:"mt-2 flex flex-wrap gap-1.5 text-[11px] text-[var(--theme-fg-muted)]",children:[e.jsx("span",{className:"rounded-full border border-[var(--theme-border)] px-2 py-0.5",children:d.threadAccess==="read"?"View only":"Collaborator"}),e.jsx("span",{className:"rounded-full border border-[var(--theme-border)] px-2 py-0.5",children:Zn(d.workspaceAccess)})]})]}),a==="incoming"?e.jsx("button",{className:"relay-button-primary inline-flex items-center gap-2",onClick:u,type:"button",children:"Open"}):e.jsxs("div",{className:"flex flex-wrap gap-2",children:[e.jsx("button",{className:"relay-button-primary inline-flex items-center gap-2",onClick:u,type:"button",children:"Open"}),e.jsx("button",{className:"relay-button-secondary inline-flex items-center gap-2",disabled:t,onClick:r,type:"button",children:"Permissions"}),e.jsxs("button",{className:"relay-button-secondary inline-flex items-center gap-2",onClick:l,type:"button",children:["Access",e.jsx(z.ChevronDown,{className:`h-4 w-4 transition-transform ${s?"rotate-180":""}`})]}),e.jsx("button",{className:"relay-button-secondary inline-flex items-center gap-2 text-[var(--status-danger-fg)]",disabled:t,onClick:o,type:"button",children:"Revoke"})]})]}),a==="outgoing"&&s?e.jsx("div",{className:"absolute right-3 top-[calc(100%-0.5rem)] z-20 w-[min(24rem,calc(100vw-3rem))] rounded-lg border border-[var(--theme-border)] bg-[var(--theme-panel)] p-3 shadow-xl",children:d.accessEvents.length?e.jsx("ul",{className:"space-y-2 text-xs text-[var(--theme-fg-muted)]",children:d.accessEvents.map(h=>e.jsxs("li",{className:"flex items-center justify-between gap-3",children:[e.jsxs("span",{className:"min-w-0",children:[e.jsx("span",{className:"block truncate font-medium text-[var(--theme-fg)]",children:Qn(h.kind)}),e.jsx("span",{className:"block truncate",children:h.username})]}),e.jsx("span",{children:Rt(h.accessedAt)})]},h.id))}):e.jsx("p",{className:"text-xs text-[var(--theme-fg-muted)]",children:"This shared thread has not been accessed yet."})}):null]})}function Kr({busyGrantId:t=null,expandedGrantId:s=null,grants:a,mode:r,onEdit:o,onOpen:l,onRevoke:d,onToggleAccess:u}){const p=a[0];if(!p)return null;const g=ja(p);return e.jsxs("article",{className:"rounded-lg border border-[var(--theme-border)] bg-[var(--theme-surface)]",children:[e.jsxs("header",{className:"flex items-center justify-between gap-3 px-3 py-3",children:[e.jsx("p",{className:"min-w-0 truncate text-sm font-semibold text-[var(--theme-fg)]",children:g}),e.jsxs("span",{className:"shrink-0 rounded-full border border-[var(--theme-border)] px-2 py-0.5 text-[11px] text-[var(--theme-fg-muted)]",children:[a.length," ",a.length===1?"share":"shares"]})]}),e.jsx("div",{className:"divide-y divide-[var(--theme-border)] border-t border-[var(--theme-border)] px-3",children:a.map(b=>e.jsx(uc,{busy:t===b.id,expanded:s===b.id,grant:b,mode:r,...o?{onEdit:()=>o(b)}:{},...l?{onOpen:()=>l(b)}:{},...d?{onRevoke:()=>d(b)}:{},...u?{onToggleAccess:()=>u(b)}:{}},b.id))})]})}function uc({busy:t,expanded:s,grant:a,mode:r,onEdit:o,onOpen:l,onRevoke:d,onToggleAccess:u}){var v,c;const p=wc(a),g=((v=a.workspaceLabel)==null?void 0:v.trim())||"Workspace unavailable",b=Ft(a)??"Thread unavailable",x=((c=a.label)==null?void 0:c.trim())||null,N=a.lastAccessedAt?`${a.lastAccessedByUsername??"unknown"} at ${Rt(a.lastAccessedAt)}`:"Not accessed yet";return e.jsxs("div",{className:"relative py-3",children:[e.jsxs("div",{className:"flex flex-col gap-3 sm:flex-row sm:items-center sm:justify-between",children:[e.jsxs("div",{className:"min-w-0 flex-1",children:[e.jsx("div",{className:"flex min-w-0 flex-wrap items-center gap-2",children:e.jsx("span",{className:"rounded-full border border-[var(--theme-border)] px-2 py-0.5 text-[11px] uppercase tracking-[0.12em] text-[var(--theme-fg-muted)]",children:p})}),e.jsxs("div",{className:"mt-1 space-y-0.5 text-xs text-[var(--theme-fg-muted)]",children:[a.scope==="device"?e.jsxs("p",{className:"truncate",children:["Scope:"," ",e.jsx("span",{className:"text-[var(--theme-fg-soft)]",children:Xn(a)})]}):e.jsxs(e.Fragment,{children:[e.jsxs("p",{className:"truncate",children:["Workspace:"," ",e.jsx("span",{className:"text-[var(--theme-fg-soft)]",children:g})]}),a.scope==="thread"?e.jsxs("p",{className:"truncate",children:["Thread:"," ",e.jsx("span",{className:"text-[var(--theme-fg-soft)]",children:b})]}):e.jsxs("p",{className:"truncate",children:["Scope:"," ",e.jsx("span",{className:"text-[var(--theme-fg-soft)]",children:"Entire workspace"})]})]}),x?e.jsxs("p",{className:"truncate",children:["Label:"," ",e.jsx("span",{className:"text-[var(--theme-fg-soft)]",children:x})]}):null,e.jsx("p",{className:"truncate",children:r==="incoming"?`From ${a.ownerUsername}`:`To ${a.targetUsername}`})]}),r==="outgoing"?e.jsxs("p",{className:"mt-1 text-xs text-[var(--theme-fg-soft)]",children:["Last access: ",N]}):null,e.jsxs("p",{className:"mt-2 flex flex-wrap gap-1.5 text-[11px] text-[var(--theme-fg-muted)]",children:[e.jsx("span",{className:"rounded-full border border-[var(--theme-border)] px-2 py-0.5",children:a.threadAccess==="read"?"View only":"Collaborator"}),e.jsx("span",{className:"rounded-full border border-[var(--theme-border)] px-2 py-0.5",children:Zn(a.workspaceAccess)}),a.canCreateThreads?e.jsx("span",{className:"rounded-full border border-[var(--theme-border)] px-2 py-0.5",children:"Can create threads"}):null]})]}),r==="incoming"?e.jsx("button",{className:"relay-button-primary inline-flex items-center gap-2",onClick:l,type:"button",children:"Open"}):e.jsxs("div",{className:"flex flex-wrap gap-2",children:[e.jsx("button",{className:"relay-button-primary inline-flex items-center gap-2",onClick:l,type:"button",children:"Open"}),e.jsx("button",{className:"relay-button-secondary inline-flex items-center gap-2",disabled:t,onClick:o,type:"button",children:"Permissions"}),e.jsxs("button",{className:"relay-button-secondary inline-flex items-center gap-2",onClick:u,type:"button",children:["Access",e.jsx(z.ChevronDown,{className:`h-4 w-4 transition-transform ${s?"rotate-180":""}`})]}),e.jsx("button",{className:"relay-button-secondary inline-flex items-center gap-2 text-[var(--status-danger-fg)]",disabled:t,onClick:d,type:"button",children:"Revoke"})]})]}),r==="outgoing"&&s?e.jsx("div",{className:"absolute right-3 top-[calc(100%-0.5rem)] z-20 w-[min(24rem,calc(100vw-3rem))] rounded-lg border border-[var(--theme-border)] bg-[var(--theme-panel)] p-3 shadow-xl",children:a.accessEvents.length?e.jsx("ul",{className:"space-y-2 text-xs text-[var(--theme-fg-muted)]",children:a.accessEvents.map(h=>e.jsxs("li",{className:"flex items-center justify-between gap-3",children:[e.jsxs("span",{className:"min-w-0",children:[e.jsx("span",{className:"block truncate font-medium text-[var(--theme-fg)]",children:Qn(h.kind)}),e.jsx("span",{className:"block truncate",children:h.username})]}),e.jsx("span",{children:Rt(h.accessedAt)})]},h.id))}):e.jsx("p",{className:"text-xs text-[var(--theme-fg-muted)]",children:"This shared access has not been used yet."})}):null]})}function mc({busy:t,onClose:s,onSave:a,share:r}){const[o,l]=n.useState(r.label??""),[d,u]=n.useState(r.threadAccess),[p,g]=n.useState(r.workspaceAccess),[b,x]=n.useState(Kn(r.expiresAt)),N=!r.workspaceId;function v(c){c.preventDefault(),a({label:o.trim()||null,threadAccess:d,workspaceAccess:N?"none":p,expiresAt:Yn(b)})}return e.jsx("div",{className:"fixed inset-0 z-50 flex items-center justify-center bg-[color-mix(in_oklch,var(--app-bg)_82%,transparent)] px-4 py-6",children:e.jsxs("form",{className:"max-h-[min(42rem,calc(100vh-3rem))] w-full max-w-lg overflow-auto rounded-lg border border-[var(--theme-border)] bg-[var(--theme-panel)] p-5 shadow-2xl",onSubmit:v,children:[e.jsxs("div",{children:[e.jsx("h2",{className:"text-base font-semibold text-[var(--theme-fg)]",children:"Shared thread permissions"}),e.jsxs("p",{className:"mt-1 text-sm text-[var(--theme-fg-muted)]",children:[r.targetUsername," can access ",wa(r),"."]})]}),e.jsxs("div",{className:"mt-5 space-y-4",children:[e.jsxs("label",{className:"block text-sm text-[var(--theme-fg-soft)]",children:["Label",e.jsx("input",{className:"relay-input mt-2 w-full",onChange:c=>l(c.target.value),placeholder:"Optional shared thread label",value:o})]}),e.jsxs("label",{className:"block text-sm text-[var(--theme-fg-soft)]",children:["Thread access",e.jsxs("select",{className:"relay-input mt-2 w-full",onChange:c=>u(c.target.value),value:d,children:[e.jsx("option",{value:"read",children:"View only"}),e.jsx("option",{value:"control",children:"Collaborator"})]})]}),e.jsxs("label",{className:"block text-sm text-[var(--theme-fg-soft)]",children:["Workspace access",e.jsxs("select",{className:"relay-input mt-2 w-full",disabled:N,onChange:c=>g(c.target.value),value:N?"none":p,children:[e.jsx("option",{value:"none",children:"No workspace"}),e.jsx("option",{value:"read",children:"Workspace read"}),e.jsx("option",{value:"write",children:"Workspace write"})]})]}),N?e.jsx("p",{className:"rounded-md border border-[var(--theme-border)] bg-[var(--theme-surface)] px-3 py-2 text-xs text-[var(--theme-fg-muted)]",children:"This share was created without a workspace scope, so only thread access can be changed."}):null,e.jsxs("label",{className:"block text-sm text-[var(--theme-fg-soft)]",children:["Expiration",e.jsx("input",{"aria-label":"Expiration",className:"relay-input mt-2 w-full",onChange:c=>x(c.target.value),type:"datetime-local",value:b}),e.jsx("span",{className:"mt-1 block text-xs text-[var(--theme-fg-muted)]",children:"Leave empty for no expiration."})]})]}),e.jsxs("div",{className:"mt-5 flex justify-end gap-2",children:[e.jsx("button",{className:"relay-button-secondary",disabled:t,onClick:s,type:"button",children:"Cancel"}),e.jsx("button",{className:"relay-button-primary",disabled:t,type:"submit",children:"Save permissions"})]})]})})}function hc({busy:t,device:s,onClose:a,onShare:r}){const[o,l]=n.useState(""),[d,u]=n.useState(""),[p,g]=n.useState("read"),[b,x]=n.useState("read"),[N,v]=n.useState(!1);function c(h){h.preventDefault(),r({targetIdentifier:o.trim(),label:d.trim()||null,threadAccess:p,workspaceAccess:b,canCreateThreads:N})}return e.jsx("div",{className:"fixed inset-0 z-50 flex items-center justify-center bg-[color-mix(in_oklch,var(--app-bg)_82%,transparent)] px-4 py-6",children:e.jsxs("form",{className:"max-h-[min(42rem,calc(100vh-3rem))] w-full max-w-lg overflow-auto rounded-lg border border-[var(--theme-border)] bg-[var(--theme-panel)] p-5 shadow-2xl",onSubmit:c,children:[e.jsxs("div",{className:"flex items-start justify-between gap-4",children:[e.jsxs("div",{children:[e.jsx("p",{className:"text-xs font-semibold uppercase tracking-[0.22em] text-[var(--theme-fg-muted)]",children:"Relay device"}),e.jsxs("h2",{className:"mt-1 text-lg font-semibold text-[var(--theme-fg)]",children:["Share ",s.name]}),e.jsx("p",{className:"mt-1 text-sm text-[var(--theme-fg-muted)]",children:"Give another relay account access to this device and its workspaces."})]}),e.jsx("button",{"aria-label":"Close share device dialog",className:"inline-flex h-9 w-9 shrink-0 items-center justify-center rounded-lg border border-[var(--theme-border)] bg-[var(--theme-surface)] text-[var(--theme-fg-muted)] transition hover:bg-[var(--theme-hover)] hover:text-[var(--theme-fg)]",onClick:a,type:"button",children:e.jsx(z.X,{className:"h-4 w-4"})})]}),e.jsxs("div",{className:"mt-5 space-y-4",children:[e.jsxs("label",{className:"block text-sm text-[var(--theme-fg-soft)]",children:["Relay account",e.jsx("input",{autoFocus:!0,className:"relay-input mt-2 w-full",onChange:h=>l(h.target.value),placeholder:"username or email",value:o})]}),e.jsxs("label",{className:"block text-sm text-[var(--theme-fg-soft)]",children:["Label",e.jsx("input",{className:"relay-input mt-2 w-full",onChange:h=>u(h.target.value),placeholder:"Optional note shown in Shared devices by me",value:d})]}),e.jsxs("div",{className:"grid gap-3 sm:grid-cols-2",children:[e.jsxs("label",{className:"block text-sm text-[var(--theme-fg-soft)]",children:["Thread access",e.jsxs("select",{className:"relay-input mt-2 w-full",onChange:h=>g(h.target.value),value:p,children:[e.jsx("option",{value:"read",children:"View only"}),e.jsx("option",{value:"control",children:"Collaborator"})]})]}),e.jsxs("label",{className:"block text-sm text-[var(--theme-fg-soft)]",children:["Workspace access",e.jsxs("select",{className:"relay-input mt-2 w-full",onChange:h=>x(h.target.value),value:b,children:[e.jsx("option",{value:"none",children:"No workspace"}),e.jsx("option",{value:"read",children:"Workspace read"}),e.jsx("option",{value:"write",children:"Workspace write"})]})]})]}),e.jsxs("label",{className:"flex items-center justify-between gap-3 rounded-lg border border-[var(--theme-border)] bg-[var(--theme-surface)] px-3 py-2 text-sm text-[var(--theme-fg-soft)]",children:["Can create new threads",e.jsx("input",{checked:N,className:"h-4 w-4 accent-[var(--theme-accent)]",onChange:h=>v(h.target.checked),type:"checkbox"})]})]}),e.jsxs("div",{className:"mt-5 flex justify-end gap-2",children:[e.jsx("button",{className:"relay-button-secondary",disabled:t,onClick:a,type:"button",children:"Cancel"}),e.jsxs("button",{className:"relay-button-primary inline-flex items-center gap-2",disabled:t||!o.trim(),type:"submit",children:[e.jsx(z.Share2,{className:"h-4 w-4"}),"Share device"]})]})]})})}function fc({busy:t,grant:s,onClose:a,onSave:r}){const[o,l]=n.useState(s.label??""),[d,u]=n.useState(s.threadAccess),[p,g]=n.useState(s.workspaceAccess),[b,x]=n.useState(s.canCreateThreads),[N,v]=n.useState(Kn(s.expiresAt)),c=s.scope!=="thread",h=s.scope==="thread"&&!s.workspaceId;function D(H){H.preventDefault(),r({label:o.trim()||null,threadAccess:d,workspaceAccess:h?"none":p,canCreateThreads:c?b:!1,expiresAt:Yn(N)})}return e.jsx("div",{className:"fixed inset-0 z-50 flex items-center justify-center bg-[color-mix(in_oklch,var(--app-bg)_82%,transparent)] px-4 py-6",children:e.jsxs("form",{className:"max-h-[min(42rem,calc(100vh-3rem))] w-full max-w-lg overflow-auto rounded-lg border border-[var(--theme-border)] bg-[var(--theme-panel)] p-5 shadow-2xl",onSubmit:D,children:[e.jsxs("div",{children:[e.jsx("h2",{className:"text-base font-semibold text-[var(--theme-fg)]",children:"Shared access permissions"}),e.jsxs("p",{className:"mt-1 text-sm text-[var(--theme-fg-muted)]",children:[s.targetUsername," can access ",ja(s),"."]})]}),e.jsxs("div",{className:"mt-5 space-y-4",children:[e.jsxs("label",{className:"block text-sm text-[var(--theme-fg-soft)]",children:["Label",e.jsx("input",{className:"relay-input mt-2 w-full",onChange:H=>l(H.target.value),placeholder:"Optional shared access label",value:o})]}),e.jsxs("div",{className:"grid gap-3 sm:grid-cols-2",children:[e.jsxs("label",{className:"block text-sm text-[var(--theme-fg-soft)]",children:["Thread access",e.jsxs("select",{className:"relay-input mt-2 w-full",onChange:H=>u(H.target.value),value:d,children:[e.jsx("option",{value:"read",children:"View only"}),e.jsx("option",{value:"control",children:"Collaborator"})]})]}),e.jsxs("label",{className:"block text-sm text-[var(--theme-fg-soft)]",children:["Workspace access",e.jsxs("select",{className:"relay-input mt-2 w-full",disabled:h,onChange:H=>g(H.target.value),value:h?"none":p,children:[e.jsx("option",{value:"none",children:"No workspace"}),e.jsx("option",{value:"read",children:"Workspace read"}),e.jsx("option",{value:"write",children:"Workspace write"})]})]})]}),c?e.jsxs("label",{className:"flex items-center justify-between gap-3 rounded-lg border border-[var(--theme-border)] bg-[var(--theme-surface)] px-3 py-2 text-sm text-[var(--theme-fg-soft)]",children:["Can create new threads",e.jsx("input",{checked:b,className:"h-4 w-4 accent-[var(--theme-accent)]",onChange:H=>x(H.target.checked),type:"checkbox"})]}):null,e.jsxs("label",{className:"block text-sm text-[var(--theme-fg-soft)]",children:["Expiration",e.jsx("input",{"aria-label":"Expiration",className:"relay-input mt-2 w-full",onChange:H=>v(H.target.value),type:"datetime-local",value:N}),e.jsx("span",{className:"mt-1 block text-xs text-[var(--theme-fg-muted)]",children:"Leave empty for no expiration."})]})]}),e.jsxs("div",{className:"mt-5 flex justify-end gap-2",children:[e.jsx("button",{className:"relay-button-secondary",disabled:t,onClick:a,type:"button",children:"Cancel"}),e.jsx("button",{className:"relay-button-primary",disabled:t,type:"submit",children:"Save permissions"})]})]})})}function pc({device:t,busy:s,copiedSetup:a,onConnect:r,onCopySetup:o,onDelete:l,onShare:d,setupTokenAvailable:u}){const[p,g]=n.useState(!1),b=n.useRef(null),x=t.hostedStatus??null,N=t.connected||x==="stopped",v=x?bc(x):t.connected?"Online":"Offline";n.useEffect(()=>{if(!p)return;function h(H){var O;(O=b.current)!=null&&O.contains(H.target)||g(!1)}function D(H){H.key==="Escape"&&g(!1)}return document.addEventListener("mousedown",h),document.addEventListener("keydown",D),()=>{document.removeEventListener("mousedown",h),document.removeEventListener("keydown",D)}},[p]);function c(h){g(!1),o(h)}return e.jsxs("article",{className:"rounded-lg border border-[var(--theme-border)] bg-[var(--theme-surface)] p-3",children:[e.jsxs("div",{className:"flex flex-col gap-3 sm:flex-row sm:items-center sm:justify-between",children:[e.jsxs("div",{className:"min-w-0 flex-1",children:[e.jsxs("div",{className:"flex min-w-0 items-center gap-2",children:[e.jsx("span",{className:`h-2.5 w-2.5 rounded-full ${t.connected?"bg-[var(--status-success-fg)]":"bg-[var(--theme-fg-muted)]"}`}),e.jsx("p",{className:"truncate text-sm font-medium text-[var(--theme-fg)]",children:t.name}),x?e.jsxs("span",{className:"rounded-full border border-[var(--theme-border)] bg-[var(--theme-panel)] px-2 py-0.5 text-[10px] font-medium text-[var(--theme-fg-muted)]",children:["Hosted · ",v]}):null]}),e.jsx("p",{className:"mt-1 font-mono text-xs text-[var(--theme-fg-muted)]",children:t.tokenPreview}),e.jsx("p",{className:"mt-1 text-xs text-[var(--theme-fg-muted)]",children:x==="stopped"?"Stopped. Connect to wake this VM.":x&&x!=="online"?`${v}. The hosted supervisor is not ready yet.`:t.connected?`Online since ${Rt(t.connectedAt)}`:`Offline. Last heartbeat: ${Rt(t.lastHeartbeatAt)}`})]}),e.jsxs("div",{className:"flex shrink-0 flex-wrap items-center gap-2 sm:flex-nowrap",children:[e.jsxs("div",{className:"relative",ref:b,children:[e.jsxs("button",{"aria-expanded":p,"aria-haspopup":"menu",className:"relay-button-secondary inline-flex h-10 items-center gap-2 whitespace-nowrap",onClick:()=>g(h=>!h),title:u?"Choose a platform and copy the relay supervisor setup command":"Device token is not available. Create a new device token for devices created before token storage was enabled.",disabled:!u||!!x,type:"button",children:[e.jsx(z.Copy,{className:"h-4 w-4"}),a?"Copied":"Copy setup",e.jsx(z.ChevronDown,{className:"h-3.5 w-3.5"})]}),p?e.jsxs("div",{"aria-label":`Setup platform for ${t.name}`,className:"absolute left-0 top-full z-20 mt-1 w-52 rounded-lg border border-[var(--theme-border)] bg-[var(--theme-panel)] p-1 shadow-[var(--theme-shadow)] sm:left-auto sm:right-0",role:"menu",children:[e.jsx("button",{className:"flex min-h-10 w-full items-center rounded-md px-3 py-2 text-left text-sm text-[var(--theme-fg)] transition hover:bg-[var(--theme-hover)] focus:outline-none focus:ring-2 focus:ring-[var(--theme-accent-ring)]",onClick:()=>c("unix"),role:"menuitem",type:"button",children:"macOS & Linux"}),e.jsx("button",{className:"flex min-h-10 w-full items-center rounded-md px-3 py-2 text-left text-sm text-[var(--theme-fg)] transition hover:bg-[var(--theme-hover)] focus:outline-none focus:ring-2 focus:ring-[var(--theme-accent-ring)]",onClick:()=>c("windows"),role:"menuitem",type:"button",children:"Windows (PowerShell)"})]}):null]}),e.jsxs("button",{className:"relay-button-primary inline-flex h-10 items-center gap-2 whitespace-nowrap",disabled:!N,onClick:r,type:"button",children:[e.jsx(z.Plug,{className:"h-4 w-4"}),x==="stopped"?"Start & connect":"Connect"]}),e.jsxs("button",{className:"relay-button-secondary inline-flex h-10 items-center gap-2 whitespace-nowrap",onClick:d,type:"button",children:[e.jsx(z.Share2,{className:"h-4 w-4"}),"Share"]}),e.jsx("button",{"aria-label":`Delete ${t.name}`,className:"relay-button-secondary inline-flex h-10 w-10 items-center justify-center px-0",disabled:s||!!x,onClick:l,title:x?"Hosted VMs are managed by a relay admin.":`Delete ${t.name}`,type:"button",children:e.jsx(z.Trash2,{className:"h-4 w-4"})})]})]}),u?null:e.jsx("p",{className:"mt-3 rounded-md border border-[var(--theme-border)] bg-[var(--theme-panel)] px-3 py-2 text-xs text-[var(--theme-fg-muted)]",children:"Token not available for this device. Create a new device token to copy a ready-to-run setup command."})]})}function xc({result:t}){const[s,a]=n.useState("unix"),r=Jn(t.token,s);return e.jsxs("section",{className:"rounded-lg border border-[var(--theme-accent-border)] bg-[var(--theme-accent-soft)] p-4",children:[e.jsxs("h2",{className:"text-base font-semibold text-[var(--theme-fg)]",children:["Token created for ",t.device.name]}),e.jsx("p",{className:"mt-1 text-sm text-[var(--theme-fg-muted)]",children:"Store this token now. It will not be shown again."}),e.jsx(Xr,{label:"Device token",value:t.token}),e.jsxs("div",{className:"mt-3",children:[e.jsxs("div",{className:"mb-1 flex flex-wrap items-center justify-between gap-2",children:[e.jsx("p",{className:"text-xs font-medium uppercase tracking-[0.14em] text-[var(--theme-fg-muted)]",children:"Supervisor command"}),e.jsxs("div",{"aria-label":"Supervisor command platform",className:"inline-flex rounded-lg border border-[var(--theme-border)] bg-[var(--theme-panel)] p-0.5",role:"group",children:[e.jsx(Yr,{active:s==="unix",onClick:()=>a("unix"),children:"macOS & Linux"}),e.jsx(Yr,{active:s==="windows",onClick:()=>a("windows"),children:"Windows"})]})]}),e.jsx(Xr,{copyLabel:`Copy ${s==="windows"?"Windows PowerShell":"macOS and Linux"} supervisor command`,label:s==="windows"?"PowerShell":"Shell",nested:!0,value:r})]})]})}function Yr({active:t,children:s,onClick:a}){return e.jsx("button",{"aria-pressed":t,className:`min-h-8 rounded-md px-2.5 text-xs font-medium transition focus:outline-none focus:ring-2 focus:ring-[var(--theme-accent-ring)] ${t?"bg-[var(--theme-surface-strong)] text-[var(--theme-fg)] shadow-sm":"text-[var(--theme-fg-muted)] hover:bg-[var(--theme-hover)] hover:text-[var(--theme-fg)]"}`,onClick:a,type:"button",children:s})}function Xr({copyLabel:t="Copy",label:s,nested:a=!1,value:r}){async function o(){var l;try{await((l=navigator.clipboard)==null?void 0:l.writeText(r))}catch{}}return e.jsxs("div",{className:a?"":"mt-3",children:[e.jsxs("div",{className:"mb-1 flex items-center justify-between gap-2",children:[e.jsx("p",{className:"text-xs font-medium uppercase tracking-[0.14em] text-[var(--theme-fg-muted)]",children:s}),e.jsxs("button",{"aria-label":t,className:"relay-button-secondary inline-flex items-center gap-1 px-2 py-1 text-xs",onClick:()=>void o(),type:"button",children:[e.jsx(z.Copy,{className:"h-3.5 w-3.5"}),"Copy"]})]}),e.jsx("code",{className:"block break-all rounded-lg border border-[var(--theme-border)] bg-[var(--theme-panel)] px-3 py-2 font-mono text-xs text-[var(--theme-fg)]",children:r})]})}function gc({children:t}){return e.jsx("div",{className:"rounded-lg border border-[var(--status-danger-border)] bg-[var(--status-danger-bg)] px-3 py-2 text-sm text-[var(--status-danger-fg)]",children:t})}function Jn(t,s="unix"){const a=vc(),r=nc[s];return s==="windows"?["Set-ExecutionPolicy -Scope Process -ExecutionPolicy Bypass -Force",`$env:REMOTE_CODEX_RELAY_SERVER_URL=${Vs(a)}`,`$env:REMOTE_CODEX_RELAY_AGENT_TOKEN=${Vs(t)}`,`$env:REMOTE_CODEX_RELAY_SUPERVISOR_PORT=${Vs(String(r))}`,"remote-codex relay-supervisor"].join(`
20
+ `):[`REMOTE_CODEX_RELAY_SERVER_URL=${Zr(a)} \\`,`REMOTE_CODEX_RELAY_AGENT_TOKEN=${Zr(t)} \\`,`REMOTE_CODEX_RELAY_SUPERVISOR_PORT=${r} \\`,"remote-codex relay-supervisor"].join(`
21
+ `)}function Vs(t){return`'${t.replace(/'/g,"''")}'`}function Zr(t){return/^[A-Za-z0-9_./:@%+=,~-]+$/.test(t)?t:`'${t.replace(/'/g,"'\\''")}'`}function vc(){return typeof window>"u"?"wss://relay.example.com":window.location.origin.replace(/^https:\/\//,"wss://").replace(/^http:\/\//,"ws://")}function Rt(t){return t?new Date(t).toLocaleString():"never"}function bc(t){return t.replace("_"," ").replace(/^./,s=>s.toUpperCase())}function Kn(t){if(!t)return"";const s=new Date(t);if(Number.isNaN(s.getTime()))return"";const a=r=>String(r).padStart(2,"0");return[s.getFullYear(),"-",a(s.getMonth()+1),"-",a(s.getDate()),"T",a(s.getHours()),":",a(s.getMinutes())].join("")}function Yn(t){const s=t.trim();if(!s)return null;const a=new Date(s);return Number.isNaN(a.getTime())?null:a.toISOString()}function wa(t){return ys(t)??"Thread unavailable"}function ys(t){var r,o;const s=(r=t.threadTitle)==null?void 0:r.trim();if(!s)return null;const a=(o=t.label)==null?void 0:o.trim();return a&&s===a?null:s}function ja(t){var s;return((s=t.deviceName)==null?void 0:s.trim())||"Shared device"}function Xn(t){var a;if(t.workspaceScope!=="selected")return"Entire device";if((a=t.workspaceLabel)!=null&&a.trim())return`Selected workspace: ${t.workspaceLabel.trim()}`;const s=t.workspaceIds.length;return`${s} selected workspace${s===1?"":"s"}`}function yc(t){var r,o;if(t.kind==="share")return`Revoke ${t.share.targetUsername}'s access to thread ${wa(t.share)}? Their shared link will stop working immediately.`;const s=t.grant,a=s.scope==="thread"?`workspace ${((r=s.workspaceLabel)==null?void 0:r.trim())||"unavailable"}, thread ${Ft(s)??"unavailable"}`:s.scope==="workspace"?`workspace ${((o=s.workspaceLabel)==null?void 0:o.trim())||"unavailable"}`:Xn(s).toLowerCase();return`Revoke ${s.targetUsername}'s access to ${ja(s)}? Scope: ${a}. Access will stop immediately.`}function Qr(t,s){return t?s===`${t.kind}:${t.kind==="grant"?t.grant.id:t.share.id}`:!1}function Ft(t){var r,o,l;if(t.scope!=="thread")return((r=t.threadTitle)==null?void 0:r.trim())||null;const s=(o=t.threadTitle)==null?void 0:o.trim();if(!s)return null;const a=(l=t.label)==null?void 0:l.trim();return a&&s===a?null:s}function wc(t){switch(t.scope){case"device":return"Device";case"workspace":return"Workspace";case"thread":default:return"Thread"}}function Zn(t){switch(t){case"write":return"Workspace write";case"read":return"Workspace read";case"none":default:return"No workspace"}}function Qn(t){switch(t){case"open_device":return"Opened device";case"open_thread":return"Opened thread";case"create_thread":return"Created thread";case"send_prompt":return"Sent prompt";case"read_workspace_file":return"Read workspace";case"write_workspace_file":return"Wrote workspace";case"access":default:return"Access"}}const jc=["REMOTE_CODEX_RELAY_SERVER_URL=wss://remote-codex.example.com \\","REMOTE_CODEX_RELAY_AGENT_TOKEN=rcd_... \\","REMOTE_CODEX_RELAY_SUPERVISOR_PORT=45679 \\","remote-codex relay-supervisor"].join(`
22
+ `);function Nc(){return n.useEffect(()=>{Ze()},[]),e.jsx("main",{className:"min-h-screen bg-[var(--app-bg)] px-4 py-6 text-[var(--app-fg)] sm:px-6",children:e.jsxs("article",{className:"mx-auto w-full max-w-5xl space-y-6",children:[e.jsxs("header",{className:"border-b border-[var(--theme-border)] pb-5",children:[e.jsxs(Be,{className:"relay-button-secondary mb-5 inline-flex items-center gap-2",to:"/",children:[e.jsx(z.ArrowLeft,{className:"h-4 w-4"}),"Back"]}),e.jsx("p",{className:"text-xs font-semibold uppercase tracking-[0.22em] text-[var(--theme-fg-muted)]",children:"Setup guide"}),e.jsx("h1",{className:"mt-2 text-3xl font-semibold tracking-normal text-[var(--theme-fg)]",children:"Remote Codex connection modes and relay setup"}),e.jsx("p",{className:"mt-3 max-w-3xl text-sm leading-6 text-[var(--theme-fg-soft)]",children:"Choose the connection mode first, then follow the relay flow when you need public web or mobile access to a private supervisor machine."})]}),e.jsxs("section",{className:"grid gap-3 md:grid-cols-3",children:[e.jsx(Gs,{title:"Local mode",detail:"Use this on the same machine, emulator, LAN, or Tailscale network. It is simplest and has no relay account."}),e.jsx(Gs,{title:"Server mode",detail:"Use this when you directly expose a supervisor with its own server login. Good for a trusted private server."}),e.jsx(Gs,{title:"Relay mode",detail:"Use this when the backend machine should not accept inbound connections. The supervisor connects out to the relay."})]}),e.jsxs("section",{className:"rounded-lg border border-[var(--theme-border)] bg-[var(--theme-panel)] p-4",children:[e.jsx("h2",{className:"text-lg font-semibold text-[var(--theme-fg)]",children:"Relay setup flow"}),e.jsxs("div",{className:"mt-4 grid gap-3",children:[e.jsx(Nt,{icon:e.jsx(z.KeyRound,{className:"h-4 w-4"}),title:"1. Register or sign in",detail:"Open the relay home page, click Sign in, then create or enter your relay account."}),e.jsx(Nt,{icon:e.jsx(z.MonitorSmartphone,{className:"h-4 w-4"}),title:"2. Create a device",detail:"Go to Devices, choose a readable device name, and create a one-time token for that private supervisor."}),e.jsx(Nt,{icon:e.jsx(z.Copy,{className:"h-4 w-4"}),title:"3. Copy the setup command",detail:"Use Copy setup. The command includes the relay URL, device token, and a less common supervisor port."}),e.jsx(Nt,{icon:e.jsx(z.Play,{className:"h-4 w-4"}),title:"4. Start supervisor on the private machine",detail:"Run the copied command in the workspace host terminal. If tmux is installed, remote-codex keeps it detached by default."}),e.jsx(Nt,{icon:e.jsx(z.RadioTower,{className:"h-4 w-4"}),title:"5. Connect and work",detail:"Return to Devices, wait for Online, then Connect. Workspaces and threads are scoped through that selected device."}),e.jsx(Nt,{icon:e.jsx(z.Share2,{className:"h-4 w-4"}),title:"6. Share a thread when needed",detail:"Inside a thread, open the export/share panel, enter another relay username, and choose thread plus workspace permissions."})]})]}),e.jsxs("section",{className:"grid gap-4 lg:grid-cols-[minmax(0,1fr)_minmax(18rem,0.8fr)]",children:[e.jsxs("div",{className:"rounded-lg border border-[var(--theme-border)] bg-[var(--theme-panel)] p-4",children:[e.jsx("h2",{className:"text-lg font-semibold text-[var(--theme-fg)]",children:"Example supervisor command"}),e.jsx("p",{className:"mt-1 text-sm text-[var(--theme-fg-muted)]",children:"The real command is generated by the relay portal. Keep the token private."}),e.jsx("pre",{className:"mt-4 overflow-x-auto rounded-lg border border-[var(--theme-border)] bg-[var(--theme-surface-strong)] p-3 text-xs leading-5 text-[var(--theme-fg)]",children:e.jsx("code",{children:jc})})]}),e.jsxs("div",{className:"rounded-lg border border-[var(--theme-border)] bg-[var(--theme-panel)] p-4",children:[e.jsx("h2",{className:"text-lg font-semibold text-[var(--theme-fg)]",children:"After setup"}),e.jsxs("ul",{className:"mt-3 space-y-3 text-sm leading-6 text-[var(--theme-fg-muted)]",children:[e.jsxs("li",{className:"flex gap-2",children:[e.jsx(z.CheckCircle2,{className:"mt-1 h-4 w-4 shrink-0 text-[var(--theme-accent-strong)]"}),"Use Devices to switch backend machines."]}),e.jsxs("li",{className:"flex gap-2",children:[e.jsx(z.CheckCircle2,{className:"mt-1 h-4 w-4 shrink-0 text-[var(--theme-accent-strong)]"}),"Use Shared with me to open sessions others shared."]}),e.jsxs("li",{className:"flex gap-2",children:[e.jsx(z.CheckCircle2,{className:"mt-1 h-4 w-4 shrink-0 text-[var(--theme-accent-strong)]"}),"Use Shared by me to review access history, edit permissions, or revoke access."]})]})]})]})]})})}function Gs({detail:t,title:s}){return e.jsxs("article",{className:"rounded-lg border border-[var(--theme-border)] bg-[var(--theme-panel)] p-4",children:[e.jsx("h2",{className:"text-base font-semibold text-[var(--theme-fg)]",children:s}),e.jsx("p",{className:"mt-2 text-sm leading-6 text-[var(--theme-fg-muted)]",children:t})]})}function Nt({detail:t,icon:s,title:a}){return e.jsxs("div",{className:"grid gap-3 rounded-lg border border-[var(--theme-border)] bg-[var(--theme-surface)] p-3 sm:grid-cols-[2rem_minmax(0,1fr)]",children:[e.jsx("span",{className:"inline-flex h-8 w-8 items-center justify-center rounded-lg border border-[var(--theme-border)] bg-[var(--theme-panel)] text-[var(--theme-accent-strong)]",children:s}),e.jsxs("div",{children:[e.jsx("h3",{className:"text-sm font-semibold text-[var(--theme-fg)]",children:a}),e.jsx("p",{className:"mt-1 text-sm leading-6 text-[var(--theme-fg-muted)]",children:t})]})]})}function kc(){const[t,s]=n.useState(null),[a,r]=n.useState(!0);n.useEffect(()=>{let l=!1;return Ze(),Et().then(d=>{l||s(d)}).catch(()=>{l||s(null)}).finally(()=>{l||r(!1)}),()=>{l=!0}},[]);const o=(t==null?void 0:t.authenticated)===!0;return e.jsx("main",{className:"min-h-screen bg-[var(--app-bg)] px-4 py-6 text-[var(--app-fg)] sm:px-6",children:e.jsxs("div",{className:"mx-auto flex w-full max-w-6xl flex-col gap-5",children:[e.jsxs("header",{className:"flex items-center justify-between gap-4 border-b border-[var(--theme-border)] pb-5",children:[e.jsxs(Be,{to:"/",className:"flex min-w-0 items-center gap-3",children:[e.jsx("span",{className:"inline-flex h-9 w-9 shrink-0 items-center justify-center rounded-lg border border-[var(--theme-border)] bg-[var(--theme-surface-strong)] text-sm font-semibold text-[var(--theme-fg)]",children:"RC"}),e.jsxs("span",{className:"min-w-0",children:[e.jsx("span",{className:"block text-sm font-semibold text-[var(--theme-fg)]",children:"Remote Codex Relay"}),e.jsx("span",{className:"block text-xs text-[var(--theme-fg-muted)]",children:"Private supervisor access"})]})]}),e.jsxs("nav",{className:"flex shrink-0 items-center gap-2",children:[e.jsxs(Be,{className:"relay-button-secondary inline-flex items-center gap-2",to:"/relay-guide",children:[e.jsx(z.BookOpen,{className:"h-4 w-4"}),"Guide"]}),e.jsxs(Be,{className:"relay-button-primary inline-flex items-center gap-2",to:o?"/relay-devices":"/relay-portal",children:[a?"Checking...":o?"Open devices":"Sign in",e.jsx(z.ArrowRight,{className:"h-4 w-4"})]})]})]}),e.jsxs("section",{className:"grid gap-4 lg:grid-cols-[minmax(0,1.05fr)_minmax(20rem,0.95fr)]",children:[e.jsxs("div",{className:"rounded-lg border border-[var(--theme-border)] bg-[var(--theme-panel)] p-4 shadow-[var(--theme-shadow)] sm:p-5",children:[e.jsxs("div",{className:"flex flex-col gap-5 sm:flex-row sm:items-start sm:justify-between",children:[e.jsxs("div",{className:"min-w-0",children:[e.jsx("p",{className:"text-xs font-semibold uppercase tracking-[0.22em] text-[var(--theme-fg-muted)]",children:"Relay console"}),e.jsx("h1",{className:"mt-2 max-w-2xl text-2xl font-semibold tracking-normal text-[var(--theme-fg)] sm:text-3xl",children:"Connect a private Codex supervisor."}),e.jsx("p",{className:"mt-3 max-w-2xl text-sm leading-6 text-[var(--theme-fg-soft)]",children:"Register a device, keep the supervisor connected over an outbound tunnel, then open workspaces through web or mobile clients."})]}),e.jsxs("span",{className:`inline-flex shrink-0 items-center gap-2 rounded-full border px-3 py-1.5 text-xs font-medium ${o?"border-[var(--status-success-border)] bg-[var(--status-success-bg)] text-[var(--status-success-fg)]":"border-[var(--theme-border-strong)] bg-[var(--theme-muted)] text-[var(--theme-fg-soft)]"}`,children:[e.jsx("span",{className:"h-1.5 w-1.5 rounded-full bg-current"}),a?"Checking session":o?"Signed in":"Signed out"]})]}),e.jsxs("div",{className:"mt-5 flex flex-wrap gap-2",children:[e.jsxs(Be,{className:"relay-button-primary inline-flex h-11 items-center gap-2 px-4",to:o?"/relay-devices":"/relay-portal",children:[o?"Open devices":"Sign in",e.jsx(z.ArrowRight,{className:"h-4 w-4"})]}),e.jsx(Be,{className:"relay-button-secondary inline-flex h-11 items-center gap-2 px-4",to:"/relay-guide",children:"Setup guide"})]}),e.jsxs("div",{className:"mt-5 grid gap-2 sm:grid-cols-3",children:[e.jsx(Ks,{label:"Mode",value:"Relay"}),e.jsx(Ks,{label:"Client",value:"Web, Android, iOS"}),e.jsx(Ks,{label:"Tunnel",value:"Supervisor outbound"})]})]}),e.jsxs("div",{className:"rounded-lg border border-[var(--theme-border)] bg-[var(--theme-panel)] p-4 shadow-[var(--theme-shadow)]",children:[e.jsxs("div",{className:"mb-4 flex items-center gap-3",children:[e.jsx("span",{className:"inline-flex h-8 w-8 items-center justify-center rounded-lg border border-[var(--theme-border)] bg-[var(--theme-surface-strong)] text-[var(--theme-fg)]",children:e.jsx(z.RadioTower,{className:"h-4 w-4"})}),e.jsxs("div",{children:[e.jsx("h2",{className:"text-sm font-semibold text-[var(--theme-fg)]",children:"Connection path"}),e.jsx("p",{className:"text-xs text-[var(--theme-fg-muted)]",children:"Everything starts from a selected device."})]})]}),e.jsxs("div",{className:"grid gap-3",children:[e.jsx(zs,{icon:e.jsx(z.MonitorSmartphone,{className:"h-4 w-4"}),title:"Create a device token",detail:"Register each workstation once from the relay portal."}),e.jsx(zs,{icon:e.jsx(z.Workflow,{className:"h-4 w-4"}),title:"Start relay-supervisor",detail:"The private machine keeps an outbound WebSocket open."}),e.jsx(zs,{icon:e.jsx(z.ShieldCheck,{className:"h-4 w-4"}),title:"Open workspaces",detail:"Web, Android, and iOS connect through the selected device."})]})]})]}),e.jsxs("section",{className:"grid gap-3 md:grid-cols-3",children:[e.jsx(Js,{title:"Local stays local",detail:"Workspace files and agent execution remain on the supervisor device."}),e.jsx(Js,{title:"Shared sessions",detail:"Share a thread as view-only or collaborator access, with workspace permissions."}),e.jsx(Js,{title:"Mobile first",detail:"Resume threads, monitor long turns, and open shared sessions from Android or iOS."})]})]})})}function zs({detail:t,icon:s,title:a}){return e.jsxs("div",{className:"flex items-start gap-3 rounded-lg border border-[var(--theme-border)] bg-[var(--theme-surface)] p-3",children:[e.jsx("span",{className:"inline-flex h-8 w-8 shrink-0 items-center justify-center rounded-lg border border-[var(--theme-border-strong)] bg-[var(--theme-surface-strong)] text-[var(--theme-fg-soft)]",children:s}),e.jsxs("div",{children:[e.jsx("p",{className:"text-sm font-semibold text-[var(--theme-fg)]",children:a}),e.jsx("p",{className:"mt-1 text-xs leading-5 text-[var(--theme-fg-muted)]",children:t})]})]})}function Js({detail:t,title:s}){return e.jsxs("article",{className:"rounded-lg border border-[var(--theme-border)] bg-[var(--theme-surface)] p-4",children:[e.jsx(z.CheckCircle2,{className:"h-4 w-4 text-[var(--status-success-fg)]"}),e.jsx("h2",{className:"mt-3 text-base font-semibold text-[var(--theme-fg)]",children:s}),e.jsx("p",{className:"mt-1 text-sm leading-6 text-[var(--theme-fg-muted)]",children:t})]})}function Ks({label:t,value:s}){return e.jsxs("div",{className:"rounded-lg border border-[var(--theme-border)] bg-[var(--theme-surface)] px-3 py-2",children:[e.jsx("p",{className:"text-[11px] uppercase tracking-[0.18em] text-[var(--theme-fg-muted)]",children:t}),e.jsx("p",{className:"mt-1 truncate text-sm font-medium text-[var(--theme-fg-soft)]",children:s})]})}function eo(t,s){return t instanceof ce?t.payload.message:t instanceof Error?t.message:s}function Sc(){const t=rt(),s=qt(),[a,r]=n.useState(null),[o,l]=n.useState(!0),[d,u]=n.useState(null);async function p(){var b;l(!0),u(null);try{Ze();const x=await Et();if(r(x),x.authenticated){if(((b=x.user)==null?void 0:b.role)==="admin"){t("/relay-admin",{replace:!0});return}t("/relay-devices",{replace:!0});return}}catch(x){u(eo(x,"Unable to load relay portal."))}finally{l(!1)}}n.useEffect(()=>{p()},[]);async function g(){var x;if(Ze(),((x=(await Et()).user)==null?void 0:x.role)==="admin"){t("/relay-admin",{replace:!0});return}t("/relay-devices",{replace:!0})}return o?e.jsx(Ys,{children:"Checking relay session..."}):a!=null&&a.authenticated?e.jsx(Ys,{children:"Opening relay devices..."}):e.jsx(Ys,{children:e.jsx(Cc,{registrationEnabled:(a==null?void 0:a.registrationEnabled)??!0,settings:a==null?void 0:a.registrationSettings,oauthNotice:new URLSearchParams(s.search).has("oauthPending")?"OAuth registration received. An admin must approve it before you can sign in.":null,oauthError:new URLSearchParams(s.search).get("oauthError"),initialError:d,onAuthenticated:g})})}function Cc({registrationEnabled:t,settings:s,oauthNotice:a,oauthError:r,initialError:o,onAuthenticated:l}){const[d,u]=n.useState("login"),[p,g]=n.useState(""),[b,x]=n.useState(""),[N,v]=n.useState(""),[c,h]=n.useState(""),[D,H]=n.useState(""),[O,E]=n.useState(o??r),[U,G]=n.useState(a),[te,Q]=n.useState(!1);async function I(se){se.preventDefault(),Q(!0),E(null),G(null);try{if(d==="login")await Jl({identifier:p,password:c});else{if(c.length<8){E("Password must be at least 8 characters.");return}if(N.trim().length<3){E("Username must be at least 3 characters.");return}if((await Xl({email:b,username:N,password:c,registrationPassword:D})).pendingApproval){G("Registration request sent. An admin must approve it before you can sign in."),u("login");return}}await l()}catch(J){E(eo(J,"Unable to authenticate with relay."))}finally{Q(!1)}}return e.jsxs("section",{className:"w-full max-w-sm rounded-lg border border-[var(--theme-border)] bg-[var(--theme-panel)] p-5 shadow-xl shadow-[var(--theme-shadow)]",children:[e.jsx("p",{className:"text-xs font-semibold uppercase tracking-[0.22em] text-[var(--theme-fg-muted)]",children:"Relay Access"}),e.jsx("h1",{className:"mt-2 text-2xl font-semibold text-[var(--theme-fg)]",children:d==="login"?"Sign in":"Create account"}),s!=null&&s.googleAuthEnabled||s!=null&&s.githubAuthEnabled?e.jsxs("div",{className:"mt-5 grid gap-2",children:[s.googleAuthEnabled?e.jsx("a",{className:"relay-button-secondary flex h-11 items-center justify-center",href:"/relay/auth/oauth/google/start",children:"Continue with Google"}):null,s.githubAuthEnabled?e.jsx("a",{className:"relay-button-secondary flex h-11 items-center justify-center",href:"/relay/auth/oauth/github/start",children:"Continue with GitHub"}):null,e.jsxs("div",{className:"flex items-center gap-3 py-1 text-xs text-[var(--theme-fg-muted)]",children:[e.jsx("span",{className:"h-px flex-1 bg-[var(--theme-border)]"}),e.jsx("span",{children:"or use password"}),e.jsx("span",{className:"h-px flex-1 bg-[var(--theme-border)]"})]})]}):null,e.jsxs("form",{className:"mt-4 space-y-4",onSubmit:I,children:[d==="login"?e.jsx(Mt,{autoComplete:"username",label:"Email or username",onChange:g,value:p}):e.jsxs(e.Fragment,{children:[e.jsx(Mt,{autoComplete:"email",label:"Email",onChange:x,required:!0,type:"email",value:b}),e.jsx(Mt,{autoComplete:"username",label:"Username",minLength:3,onChange:v,required:!0,value:N}),e.jsx(Mt,{autoComplete:"one-time-code",label:"Registration password",onChange:H,required:!0,type:"password",value:D})]}),e.jsx(Mt,{autoComplete:d==="login"?"current-password":"new-password",label:"Password",onChange:h,required:!0,type:"password",value:c,...d==="register"?{description:"Use at least 8 characters.",minLength:8}:{}}),O?e.jsx(en,{tone:"danger",children:O}):null,U?e.jsx(en,{tone:"accent",children:U}):null,e.jsx("button",{className:"relay-button-primary h-11 w-full",disabled:te,type:"submit",children:te?"Working...":d==="login"?"Sign in":"Register"})]}),e.jsx("button",{className:"mt-4 text-sm text-[var(--theme-accent-strong)] disabled:text-[var(--theme-fg-muted)]",disabled:d==="login"?!t:!1,onClick:()=>u(d==="login"?"register":"login"),type:"button",children:d==="login"?t?"Create relay account":"Registration is disabled":"Use an existing account"})]})}function Ys({children:t}){return e.jsxs("main",{className:"min-h-screen bg-[var(--app-bg)] px-4 py-6 text-[var(--app-fg)] sm:px-6",children:[e.jsx(ya,{}),e.jsx("div",{className:"flex min-h-[calc(100vh-3rem)] items-center justify-center",children:t})]})}function Mt({label:t,value:s,onChange:a,type:r="text",autoComplete:o,description:l,minLength:d,required:u=!1}){return e.jsxs("label",{className:"block text-sm text-[var(--theme-fg-soft)]",children:[t,e.jsx("input",{autoComplete:o,className:"relay-input mt-2 w-full",minLength:d,onChange:p=>a(p.target.value),required:u,type:r,value:s}),l?e.jsx("span",{className:"mt-1.5 block text-xs text-[var(--theme-fg-muted)]",children:l}):null]})}function en({tone:t,children:s}){return e.jsx("div",{className:`rounded-lg border px-3 py-2 text-sm ${t==="danger"?"border-[var(--status-danger-border)] bg-[var(--status-danger-bg)] text-[var(--status-danger-fg)]":"border-[var(--theme-accent-border)] bg-[var(--theme-accent-soft)] text-[var(--theme-fg)]"}`,children:s})}function Tc(t,s){return yl(t,s)}function gt(t,s,a=null){return wl(t,s,a)}function Ec(t,s){return!s||s.items.length===0?t:t.map(a=>{if(a.id!==s.turnId)return a;const r=s.items.filter(p=>p.createdAt);if(r.length===0)return a;const o=new Map(r.map(p=>[p.id,p])),l=new Set;let d=!1;const u=a.items.map(p=>{if(p.createdAt&&p.createdAt!==a.startedAt)return p;let g=o.get(p.id);return!g&&p.kind==="agentMessage"&&(g=r.find(b=>b.kind==="agentMessage"&&!l.has(b.id)&&b.text.trim().length>=8&&p.text.trim().includes(b.text.trim()))),!(g!=null&&g.createdAt)||g.createdAt===a.startedAt?p:(l.add(g.id),d=!0,{...p,createdAt:g.createdAt})});return d?{...a,items:u}:a})}function Rc(t,s){return{...t,pendingRequests:[...t.pendingRequests.filter(a=>a.id!==s.id),s]}}function Ac(t,s){const a=t.pendingRequests.filter(r=>r.id!==s);return a.length===t.pendingRequests.length?t:{...t,pendingRequests:a}}function tn(t,s,a){const r=s.filter(u=>!a.has(u.id)),o=t.filter(u=>!a.has(u.id));if(o.length===0)return r;const l=new Map(r.map(u=>[u.id,u]));return[...o.map(u=>l.get(u.id)??u),...r.filter(u=>!o.some(p=>p.id===u.id))].sort((u,p)=>u.createdAt.localeCompare(p.createdAt))}function Ic(t){if(!t||typeof t!="object")return!1;const s=t;return typeof s.id=="string"&&(s.kind==="requestUserInput"||s.kind==="planDecision")&&typeof s.title=="string"&&typeof s.createdAt=="string"&&Array.isArray(s.questions)}function to(t,s){var l,d;if(!t||t.kind!==s.kind)return s;const a=u=>{let p=u;const g=typeof s.sequence=="number"&&Number.isFinite(s.sequence)?s.sequence:typeof t.sequence=="number"&&Number.isFinite(t.sequence)?t.sequence:null;g!==null&&p.sequence!==g&&(p={...p,sequence:g});const b=typeof s.transcriptOrder=="number"&&Number.isFinite(s.transcriptOrder)?s.transcriptOrder:typeof t.transcriptOrder=="number"&&Number.isFinite(t.transcriptOrder)?t.transcriptOrder:null;return b!==null&&p.transcriptOrder!==b&&(p={...p,transcriptOrder:b}),p};if(t.kind==="agentMessage"&&s.kind==="agentMessage")return a(t.text.length>s.text.length?{...s,text:t.text,sequence:s.sequence??t.sequence??null}:s);const r=((l=t.detailText)==null?void 0:l.trim())||t.text.trim(),o=((d=s.detailText)==null?void 0:d.trim())||s.text.trim();return a(r.length>o.length?t:s)}function Pc(t,s,a){if(!t||s&&s.turnId!==t.turnId)return s;const r=a.find(x=>x.id===t.turnId),o=new Map((r==null?void 0:r.items.map(x=>[x.id,x]))??[]),l=(r==null?void 0:r.items.filter(x=>x.kind==="agentMessage").map(x=>x.text.trim()).filter(Boolean))??[],d=x=>x.kind==="agentMessage"&&x.text.trim().length>0&&l.some(N=>N.includes(x.text.trim()));if(!s){const x=t.items.filter(N=>{const v=o.get(N.id);return v?v.kind!==N.kind||typeof N.sequence=="number"&&Number.isFinite(N.sequence)&&v.sequence!==N.sequence:!d(N)});return x.length===0?null:{...t,items:x}}const u=new Map(t.items.map(x=>[x.id,x])),p=new Map(s.items.map(x=>[x.id,x])),b=[...t.items.map(x=>x.id),...s.items.map(x=>x.id).filter(x=>!u.has(x))].map(x=>{const N=p.get(x),v=u.get(x);if(!N){const c=o.get(x);return!c&&v&&d(v)||c&&c.kind===(v==null?void 0:v.kind)&&!(v&&typeof v.sequence=="number"&&Number.isFinite(v.sequence)&&c.sequence!==v.sequence)?null:v??null}return to(v,N)}).filter(x=>!!x);return b.length===0?null:{turnId:s.turnId,items:b,updatedAt:s.updatedAt.localeCompare(t.updatedAt)>=0?s.updatedAt:t.updatedAt}}function Bt(t,s){const a=t.filter(r=>r.id!==s.id);return[s,...a]}function Lc(t){return`${t.threadId}:${t.objective}:${t.createdAt}`}function Oc(t,s){const a=Date.parse(t.updatedAt)||0,o=(Date.parse(s.updatedAt)||0)>=a?s:t,l=o===s?t:s;return{...o,localGoalId:o.localGoalId??l.localGoalId??null}}function so(t){const s=new Map;for(const a of t){const r=Lc(a),o=s.get(r);s.set(r,o?Oc(o,a):a)}return[...s.values()].sort((a,r)=>Date.parse(r.updatedAt)-Date.parse(a.updatedAt))}function ws(t,s){return so([s,...t])}function Xs(t,s){if(!s)return null;const a=t.find(r=>r.model===s);return a?a.supportedReasoningEfforts.length>1:null}function Uc(){return typeof crypto<"u"&&typeof crypto.randomUUID=="function"?crypto.randomUUID():`client-${Date.now()}-${Math.random().toString(16).slice(2,10)}`}function Na(t,s){return(t==null?void 0:t.items.some(a=>a.kind==="userMessage"&&a.text.trim()===s.trim()))??!1}const $c=/\s*\[(?:PHOTO\s+[^\]]+|localImage)\]\s*/g;function ka(t){return/\[(?:PHOTO\s+[^\]]+|localImage)\]/.test(t)}function sn(t){return t.replace($c," ").replace(/\s+/g," ").trim()}function ao(t,s){const a=sn(s);return a?(t==null?void 0:t.items.some(r=>r.kind==="userMessage"&&sn(r.text)===a))??!1:!1}function ro(t){return(t==null?void 0:t.items.some(s=>s.kind==="userMessage"&&/\[(?:PHOTO\s+\.\/\.temp\/threads\/[^\]]+|localImage)\]/.test(s.text)))??!1}function Dc(t,s){return t.find(a=>Na(a,s))??(ka(s)?t.find(a=>ao(a,s))??null:null)}function Mc(t,s){return t.find(a=>(s.serverTurnId!==null&&a.id===s.serverTurnId||a.id===s.id)&&a.items.some(o=>o.kind==="userMessage")?!0:Na(a,s.prompt)||ka(s.prompt)&&(ao(a,s.prompt)||ro(a)))??null}function _c(t,s,a,r){let o=!1;const l=t.map(d=>d.id!==s?d:(o=!0,{...d,tokenUsage:a,priceEstimate:r}));return o?l:t}function Hc({activeView:t,composerHostRef:s,threadId:a}){const[r,o]=n.useState(!1),[l,d]=n.useState(0),[u,p]=n.useState(0),[g,b]=n.useState(0),[x,N]=n.useState(!1);n.useEffect(()=>{if(typeof window>"u"||typeof window.matchMedia!="function")return;const O=window.matchMedia("(max-width: 639px)"),E=()=>o(O.matches);return E(),O.addEventListener("change",E),()=>{O.removeEventListener("change",E)}},[]),n.useEffect(()=>{var E,U;if(typeof window>"u")return;const O=()=>{const G=window.visualViewport,te=G?Math.max(0,Math.round(window.innerHeight-G.height-G.offsetTop)):0;b(te),document.documentElement.style.setProperty("--thread-detail-keyboard-inset",`${te}px`)};return O(),(E=window.visualViewport)==null||E.addEventListener("resize",O),(U=window.visualViewport)==null||U.addEventListener("scroll",O),window.addEventListener("resize",O),()=>{var G,te;(G=window.visualViewport)==null||G.removeEventListener("resize",O),(te=window.visualViewport)==null||te.removeEventListener("scroll",O),window.removeEventListener("resize",O),document.documentElement.style.removeProperty("--thread-detail-keyboard-inset")}},[]),n.useEffect(()=>{if(typeof document>"u")return;const O=()=>{const E=document.activeElement,U=s.current,G=U==null?void 0:U.querySelector('[aria-label="Prompt"]');N(!!(E&&G&&(E===G||G.contains(E))))};return O(),document.addEventListener("focusin",O),document.addEventListener("focusout",O),()=>{document.removeEventListener("focusin",O),document.removeEventListener("focusout",O)}},[t,s,r,a]),n.useEffect(()=>{const O=s.current;if(!O||typeof ResizeObserver>"u")return;const E=O.querySelector("form")??O,U=()=>{d(Math.max(O.getBoundingClientRect().height,E.getBoundingClientRect().height))};U();const G=new ResizeObserver(()=>{U()});return G.observe(E),()=>{G.disconnect()}},[t,s,r]),n.useEffect(()=>{var G,te;const O=s.current;if(!O||!r||t!=="chat"){p(0);return}const E=()=>{const Q=O.getBoundingClientRect();p(Math.max(0,Math.ceil(window.innerHeight-Q.top)))};E(),window.addEventListener("resize",E),(G=window.visualViewport)==null||G.addEventListener("resize",E),(te=window.visualViewport)==null||te.addEventListener("scroll",E);let U=null;return typeof ResizeObserver<"u"&&(U=new ResizeObserver(E),U.observe(O)),()=>{var Q,I;window.removeEventListener("resize",E),(Q=window.visualViewport)==null||Q.removeEventListener("resize",E),(I=window.visualViewport)==null||I.removeEventListener("scroll",E),U==null||U.disconnect()}},[t,s,r,g,x,a]);const v=r&&t==="chat",c=v&&x?g:0,h=Math.max(l,144),D=Math.max(u,h+c),H=v?D+12:0;return{floatingMobileComposerBottomOffset:c,timelineBottomSpacer:H,useFloatingMobileComposer:v}}const Ge=()=>({status:"idle",data:null,error:null});function Bc({detailRef:t,id:s,navigate:a,setDetail:r,setError:o,setThreads:l}){const[d,u]=n.useState(Ge),[p,g]=n.useState(Ge),[b,x]=n.useState(Ge),[N,v]=n.useState(Ge),[c,h]=n.useState(Ge),[D,H]=n.useState(!1),[O,E]=n.useState(!1),[U,G]=n.useState(()=>new Set),[te,Q]=n.useState(!1),[I,se]=n.useState(!1),[J,ee]=n.useState(Ge);n.useEffect(()=>{u(Ge),g(Ge),x(Ge),v(Ge),h(Ge),H(!1),G(new Set),Q(!1),ee(Ge)},[s]);const i=n.useCallback(async()=>{if(s){ee(B=>({status:"loading",data:B.data,error:null}));try{const B=await Yi(s);ee({status:"ready",data:B,error:null})}catch(B){const L=B instanceof ce?B.payload.message:"Unable to load export turns.";ee(le=>({status:"failed",data:le.data,error:L}))}}},[s]);async function W(B){if(s){o(null),se(!0);try{const{blob:L,filename:le}=await Zi(s,B),T=URL.createObjectURL(L),f=document.createElement("a");f.href=T,f.download=le,document.body.append(f),f.click(),f.remove(),window.setTimeout(()=>URL.revokeObjectURL(T),3e4),Q(!1)}catch(L){const le=L instanceof ce?L.payload.message:"Unable to export transcript.";o(le)}finally{se(!1)}}}async function fe(){if(s){h(B=>{var L;return{status:"loading",data:B.data??((L=t.current)==null?void 0:L.goal)??null,error:null}});try{const B=await md(s);h({status:"ready",data:B.goal,error:null}),r(L=>L&&(B.goal?{...L,goal:B.goal,goalHistory:ws(L.goalHistory??[],B.goal)}:{...L,goal:B.goal}))}catch(B){h(L=>({status:"failed",data:L.data,error:B instanceof ce?B.payload.message:"Unable to load goal."}))}}}async function ae(B){if(s){h(L=>{var le;return{status:"loading",data:L.data??((le=t.current)==null?void 0:le.goal)??null,error:null}});try{const L=await hd(s,B);h({status:"ready",data:L.goal,error:null}),r(le=>le&&(L.goal?{...le,goal:L.goal,goalHistory:ws(le.goalHistory??[],L.goal)}:{...le,goal:L.goal}))}catch(L){throw h(le=>({status:"failed",data:le.data,error:L instanceof ce?L.payload.message:"Unable to update goal."})),L}}}async function we(){if(s){h(B=>{var L;return{status:"loading",data:B.data??((L=t.current)==null?void 0:L.goal)??null,error:null}});try{const B=await fd(s);h({status:"ready",data:null,error:null}),r(L=>L&&(B.goalHistory?{...L,goal:null,goalHistory:B.goalHistory}:{...L,goal:null}))}catch(B){throw h(L=>({status:"failed",data:L.data,error:B instanceof ce?B.payload.message:"Unable to clear goal."})),B}}}async function ge(B){E(!0);try{await ae({status:B})}finally{E(!1)}}async function Ne(){E(!0);try{await we()}finally{E(!1)}}async function K(){if(s){u(B=>({status:"loading",data:B.data,error:null}));try{const B=await xd(s);u({status:"ready",data:B,error:null})}catch(B){u(L=>({status:"failed",data:L.data,error:B instanceof ce?B.payload.message:"Unable to load skills."}))}}}async function M(){if(s){g(B=>({status:"loading",data:B.data,error:null}));try{const B=await gd(s);g({status:"ready",data:B,error:null})}catch(B){g(L=>({status:"failed",data:L.data,error:B instanceof ce?B.payload.message:"Unable to load MCP servers."}))}}}async function ne(){if(s){x(B=>({status:"loading",data:B.data,error:null}));try{const B=await vd(s);x({status:"ready",data:B,error:null})}catch(B){x(L=>({status:"failed",data:L.data,error:B instanceof ce?B.payload.message:"Unable to load hooks."}))}}}async function P(B){if(s){x(L=>({status:"loading",data:L.data,error:null}));try{const L=await bd(s,B);x({status:"ready",data:L,error:null})}catch(L){throw x(le=>({status:"failed",data:le.data,error:L instanceof ce?L.payload.message:"Unable to create hook."})),L}}}async function V(B){if(s){x(L=>({status:"loading",data:L.data,error:null}));try{const L=await yd(s,B);x({status:"ready",data:L,error:null})}catch(L){throw x(le=>({status:"failed",data:le.data,error:L instanceof ce?L.payload.message:"Unable to update hook."})),L}}}async function Y(B){if(s){x(L=>({status:"loading",data:L.data,error:null}));try{const L=await wd(s,B);x({status:"ready",data:L,error:null})}catch(L){throw x(le=>({status:"failed",data:le.data,error:L instanceof ce?L.payload.message:"Unable to trust hook."})),L}}}async function Ce(B){if(s){x(L=>({status:"loading",data:L.data,error:null}));try{const L=await jd(s,B);x({status:"ready",data:L,error:null})}catch(L){throw x(le=>({status:"failed",data:le.data,error:L instanceof ce?L.payload.message:"Unable to untrust hook."})),L}}}async function De(){if(s){v(B=>({status:"loading",data:B.data,error:null}));try{const B=await pd(s);v({status:"ready",data:B,error:null})}catch(B){v(L=>({status:"failed",data:L.data,error:B instanceof ce?B.payload.message:"Unable to load turns for forking."}))}}}async function qe(){if(!s)return;const B=await Br(s,{mode:"latest"});l(L=>Bt(L,B.thread.thread)),a(Fe(B.thread.thread.id))}async function be(B){if(!s)return;const L=await Br(s,{mode:"turn",turnId:B});l(le=>Bt(le,L.thread.thread)),a(Fe(L.thread.thread.id))}return{expandedGoalIds:U,exportBusy:I,exportDialogOpen:te,exportTurnsState:J,forkTurnOptionsState:N,goalActionBusy:O,goalMonitorOpen:D,goalState:c,handleCreateHook:P,handleExportTranscript:W,handleForkLatest:qe,handleForkTurn:be,handleGoalStatusAction:ge,handleOpenForkTurns:De,handleOpenGoal:fe,handleOpenHooks:ne,handleOpenMcp:M,handleOpenSkills:K,handleTerminateGoal:Ne,handleTrustHook:Y,handleUntrustHook:Ce,handleUpdateGoal:ae,handleUpdateHook:V,hooksState:b,loadExportTurns:i,mcpState:p,setExpandedGoalIds:G,setExportDialogOpen:Q,setGoalMonitorOpen:H,setGoalState:h,skillsState:d}}const Wc=5e3;function an(t){return JSON.stringify(t)}function Fc(t,s){return an(t)===an(s)}function qc(t,s){const a=new Map(t.map(l=>[l.id,l]));let r=t.length!==s.length;const o=s.map((l,d)=>{var p;const u=a.get(l.id);return u&&Fc(u,l)?(((p=t[d])==null?void 0:p.id)!==l.id&&(r=!0),u):(r=!0,l)});return r?o:t}function no(t){const{enabled:s,setThreads:a,intervalMs:r=Wc}=t,o=n.useRef(!1),l=n.useCallback(async()=>{if(!(!s||o.current)&&!(typeof document<"u"&&document.visibilityState==="hidden")){o.current=!0;try{const d=await ga();a(u=>qc(u,d))}catch{}finally{o.current=!1}}},[s,a]);n.useEffect(()=>{if(!s||typeof window>"u")return;const d=window.setInterval(()=>{l()},r),u=()=>{document.visibilityState==="visible"&&l()};return document.addEventListener("visibilitychange",u),()=>{window.clearInterval(d),document.removeEventListener("visibilitychange",u)}},[s,r,l])}function Vc({setError:t,workspaceId:s,access:a="write"}){return n.useMemo(()=>!s||a==="none"?null:{listTree:r=>Mi(s,{path:r.path??""}),readFile:r=>_i(s,{path:r.path,...r.offset!==void 0?{offset:r.offset}:{},...r.limit!==void 0?{limit:r.limit}:{}}),getRawFileUrl:r=>Hi(s,{path:r.path}),...a==="write"?{uploadFile:r=>Fi(s,{file:r.file}),writeFile:async r=>{await qi(s,{path:r.path,content:r.content})}}:{},downloadNode:async r=>{t(null);try{const o=await Wi(s,{path:r.path}),l=URL.createObjectURL(o.blob),d=document.createElement("a");d.href=l,d.download=o.filename,document.body.append(d),d.click(),d.remove(),URL.revokeObjectURL(l)}catch(o){t(o instanceof ce?o.payload.message:o instanceof Error?o.message:"Workspace download failed.")}}},[a,t,s])}function mt(t){return t.enabled&&t.capabilities.sessions.resume&&t.capabilities.turns.start}function rn(t,s){var r;const a=t.find(o=>o.provider===s);return a&&mt(a)?a.provider:((r=t.find(mt))==null?void 0:r.provider)??st}function Sa({initialWorkspaceId:t,initialTitle:s="",onCreated:a,onCancel:r,variant:o="panel"}){var ze;const l=Vt(),d=n.useId(),[u,p]=n.useState([]),[g,b]=n.useState([]),[x,N]=n.useState([]),[v,c]=n.useState([]),[h,D]=n.useState((l==null?void 0:l.defaultBackend)??st),[H,O]=n.useState(""),[E,U]=n.useState(""),[G,te]=n.useState(""),[Q,I]=n.useState(null),[se,J]=n.useState(()=>s??""),[ee,i]=n.useState("yolo"),[W,fe]=n.useState(!0),[ae,we]=n.useState(!1),[ge,Ne]=n.useState(null),[K,M]=n.useState(null),[ne,P]=n.useState(null),V=(l==null?void 0:l.defaultBackend)??st,Y=g.find(S=>S.provider===h),Ce=g.some(S=>S.provider==="acp"),De=u.find(S=>S.id===H)??null,qe=v.find(S=>S.model===G)??null,be=h==="acp"&&x.some(S=>S.selectionKind==="agent"),B=x.find(S=>S.model===E)??null,L=!!qe,le=o==="dialog",T=le?"host-form-control mt-1.5 h-10 w-full rounded-lg border px-3 text-sm outline-none transition":"host-form-control mt-2 w-full rounded-lg border px-4 py-3 outline-none transition",f=le?"host-secondary-button rounded-lg border px-3 py-2 text-sm font-medium transition disabled:cursor-not-allowed disabled:opacity-60":"host-secondary-button rounded-lg border px-5 py-3 font-medium transition disabled:cursor-not-allowed disabled:opacity-60",j=le?"ui-action-primary rounded-lg px-4 py-2.5 text-sm font-medium transition disabled:cursor-not-allowed":"ui-action-primary rounded-lg px-5 py-3 font-medium transition disabled:cursor-not-allowed";n.useEffect(()=>{J(s??"")},[s]),n.useEffect(()=>{let S=!1;return Promise.all([xa(),Tt()]).then(([R,oe])=>{var Te;if(S)return;const ye=rn(oe,V);D(ye),b(oe),p(R);const ke=t??null,Se=R.some(nt=>nt.id===ke)?ke:((Te=R[0])==null?void 0:Te.id)??"";O(Se)}).catch(R=>{S||P(R instanceof Error?R.message:"Unable to load creation form data.")}).finally(()=>{S||fe(!1)}),()=>{S=!0}},[V,t]),n.useEffect(()=>{if(!h)return;let S=!1;if(H)return c([]),te(""),I(null),P(null),h==="acp"?(_t(h).then(R=>{S||(N(R),U(oe=>{const ke=R.find(Se=>{var Te;return Se.model===oe&&((Te=Se.acpAgent)==null?void 0:Te.availability)==="ready"})??R.find(Se=>{var Te;return Se.isDefault&&((Te=Se.acpAgent)==null?void 0:Te.availability)==="ready"})??R.find(Se=>{var Te;return((Te=Se.acpAgent)==null?void 0:Te.availability)==="ready"})??null;return(ke==null?void 0:ke.model)??""}))}).catch(R=>{S||(N([]),U(""),P(R instanceof Error?R.message:"Unable to load ACP agents."))}),()=>{S=!0}):(N([]),U(""),ca(h).then(R=>{if(S)return;c(R);const oe=R.find(ye=>ye.isDefault)??R[0]??null;te((oe==null?void 0:oe.model)??""),I((oe==null?void 0:oe.defaultReasoningEffort)??null)}).catch(R=>{S||(c([]),te(""),P(R instanceof Error?R.message:"Unable to load backend models."))}),()=>{S=!0})},[h,H]),n.useEffect(()=>{if(h!=="acp"||!E||!De)return;let S=!1;return c([]),te(""),I(null),pa("acp",{agentId:E,cwd:De.absPath}).then(R=>{if(S)return;c(R);const oe=R.find(ye=>ye.isDefault)??R[0]??null;te((oe==null?void 0:oe.model)??""),I((oe==null?void 0:oe.defaultReasoningEffort)??null)}).catch(R=>{S||P(R instanceof Error?R.message:"Unable to load agent models.")}),()=>{S=!0}},[E,h,De]);async function $(S=h){const R=await Tt();b(R);const oe=R.find(Te=>Te.provider===S),ye=oe&&mt(oe)?S:rn(R,V);if(D(ye),ye==="acp"){const Te=await _t("acp");N(Te);const nt=Te.find(ot=>{var it;return ot.isDefault&&((it=ot.acpAgent)==null?void 0:it.availability)==="ready"})??Te.find(ot=>{var it;return((it=ot.acpAgent)==null?void 0:it.availability)==="ready"})??null;U((nt==null?void 0:nt.model)??"");return}const ke=await ca(ye);c(ke);const Se=ke.find(Te=>Te.isDefault)??ke[0]??null;te((Se==null?void 0:Se.model)??""),I((Se==null?void 0:Se.defaultReasoningEffort)??null)}async function re(S){const R=S.installation.installed?"update":"install";Ne(S.provider),P(null);try{await da(S.provider,R),await $(S.provider)}catch(oe){oe instanceof ce?P(oe.payload.message):P(oe instanceof Error?oe.message:`Unable to ${R} ${S.displayName}.`);try{await $(h)}catch{}}finally{Ne(null)}}async function je(S){var R;M(S.id),P(null);try{await da("acp","install",S.id);const oe=await _t("acp");N(oe);const ye=oe.find(ke=>ke.id===S.id);((R=ye==null?void 0:ye.acpAgent)==null?void 0:R.availability)==="ready"&&U(ye.model),b(await Tt())}catch(oe){P(oe instanceof Error?oe.message:`Unable to install ${S.displayName}.`)}finally{M(null)}}async function Ue(S){S.preventDefault(),we(!0),P(null);try{const R=await ed(se.trim()?{workspaceId:H,provider:h,...h==="acp"?{agentId:E}:{},model:G,...Q?{reasoningEffort:Q}:{},approvalMode:ee,title:se.trim()}:{workspaceId:H,provider:h,...h==="acp"?{agentId:E}:{},model:G,...Q?{reasoningEffort:Q}:{},approvalMode:ee});a(R)}catch(R){R instanceof ce?P(R.payload.message):P(R instanceof Error?R.message:"Unable to create thread.")}finally{we(!1)}}return W?e.jsx("div",{className:"host-empty-state rounded-lg border px-6 py-12 text-center",children:"Loading creation form..."}):e.jsxs("form",{onSubmit:Ue,className:le?"max-h-[min(76vh,36rem)] space-y-3 overflow-y-auto pr-1 text-sm":"space-y-5",children:[le?e.jsxs("div",{className:"pr-8",children:[e.jsx("h2",{className:"text-base font-semibold text-[var(--theme-fg)]",children:"Create New Chat"}),e.jsx("p",{className:"mt-1 text-xs leading-5 text-[var(--theme-fg-muted)]",children:"Choose the workspace, agent, and approval mode for this thread."})]}):null,e.jsxs("div",{children:[e.jsx("label",{className:"host-form-label text-xs font-medium",htmlFor:`${d}-thread-backend`,children:"Backend"}),e.jsxs("select",{id:`${d}-thread-backend`,value:h,onChange:S=>{const R=S.target.value;D(R)},className:T,children:[g.map(S=>e.jsxs("option",{value:S.provider,disabled:!mt(S),children:[S.displayName,mt(S)?"":" (not available)"]},S.provider)),Ce?null:e.jsx("option",{value:"acp",disabled:!0,children:"ACP Agent (enable on device)"})]}),Ce?null:e.jsxs("p",{className:"mt-2 text-xs leading-5 text-[var(--theme-fg-muted)]",children:["ACP is not enabled by this device supervisor. Update and restart Remote Codex, or add",e.jsx("code",{className:"mx-1 font-mono",children:"acp"}),"to ",e.jsx("code",{className:"font-mono",children:"REMOTE_CODEX_ENABLED_AGENT_PROVIDERS"}),"."]}),le?Y&&!mt(Y)?e.jsx("p",{className:"mt-2 text-xs text-[var(--theme-fg-muted)]",children:"Select an available backend before creating a thread."}):null:e.jsx("div",{className:"mt-3 space-y-2",children:g.map(S=>{const R=mt(S),oe=S.provider===h,ye=S.installation.installed?!!S.installation.updateCommand:!!S.installation.installCommand,ke=S.installation.installed?"Update":"Install",Se=ge===S.provider||S.installation.busy;return e.jsxs("div",{className:`rounded-lg border px-4 py-3 transition ${oe?"host-surface-strong":"host-surface"} ${R?"":"opacity-75"}`,children:[e.jsxs("div",{className:"flex flex-wrap items-start gap-3",children:[e.jsxs("button",{type:"button",onClick:()=>{R&&D(S.provider)},disabled:!R||ae||Se,className:"min-w-0 flex-1 text-left disabled:cursor-not-allowed",children:[e.jsxs("div",{className:"flex items-center gap-2",children:[e.jsx("span",{className:"font-medium",children:S.displayName}),oe?e.jsx("span",{className:"host-pill rounded-full px-2 py-0.5 text-xs",children:"Selected"}):null,R?null:e.jsx("span",{className:"host-pill rounded-full px-2 py-0.5 text-xs",children:"Not available"})]}),e.jsx("p",{className:"mt-1 text-sm opacity-75",children:S.installation.installed?`Installed${S.installation.installedVersion?`: ${S.installation.installedVersion}`:""}`:S.installation.lastError??S.status.lastError??"Runtime is not installed."}),!R&&S.installation.lastError?e.jsx("p",{className:"mt-1 text-xs opacity-70",children:S.installation.lastError}):null]}),ye?e.jsx("button",{type:"button",onClick:()=>re(S),disabled:ae||Se||ge!==null,className:"host-secondary-button rounded-lg border px-3 py-2 text-sm font-medium transition disabled:cursor-not-allowed disabled:opacity-60","aria-label":`${ke} ${S.displayName}`,children:Se?`${ke}ing...`:ke}):null]}),!R&&ye?e.jsx("p",{className:"mt-2 text-xs opacity-70",children:"Relay connections install or update the runtime on the selected device."}):null]},S.provider)})}),!le&&Y&&!mt(Y)?e.jsx("p",{className:"mt-2 text-sm opacity-75",children:"Select an available backend, or install this runtime before creating a thread."}):null]}),e.jsxs("div",{children:[e.jsx("label",{className:"host-form-label text-xs font-medium",htmlFor:`${d}-thread-workspace`,children:"Workspace"}),e.jsx("select",{id:`${d}-thread-workspace`,value:H,onChange:S=>O(S.target.value),className:T,children:u.map(S=>e.jsxs("option",{value:S.id,children:[S.label," · ",S.absPath]},S.id))})]}),be?e.jsxs("fieldset",{children:[e.jsx("legend",{className:"host-form-label text-xs font-medium",children:"Agent"}),e.jsx("div",{className:"mt-2 max-h-64 divide-y divide-[var(--theme-border)] overflow-y-auto rounded-lg border border-[var(--theme-border)] bg-[var(--theme-surface)]",role:"radiogroup","aria-label":"Agent",children:x.map(S=>{const R=S.acpAgent,oe=(R==null?void 0:R.availability)==="ready",ye=(R==null?void 0:R.availability)==="adapter_missing",ke=K===S.id||(R==null?void 0:R.busy)===!0,Se=S.model===E,Te=(R==null?void 0:R.availability)==="base_missing"?"Base agent missing":ye?"Adapter needed":(R==null?void 0:R.availability)==="server_unavailable"?"ACP unavailable":"Ready",nt=(R==null?void 0:R.transport)==="native"?"Native ACP":(R==null?void 0:R.transport)==="adapter"?"ACP adapter":"Custom ACP",ot=`${d}-acp-agent-${S.id}-tooltip`;return e.jsxs("div",{className:"group/agent relative flex min-w-0 items-stretch gap-2 px-2 py-2",title:R==null?void 0:R.statusMessage,children:[e.jsxs("button",{type:"button",role:"radio","aria-checked":Se,"aria-disabled":!oe||ae||K!==null,"aria-describedby":ot,onClick:()=>{oe&&!ae&&K===null&&U(S.model)},className:`min-w-0 flex-1 rounded-md px-2.5 py-2 text-left outline-none transition focus-visible:ring-2 focus-visible:ring-[var(--theme-accent-solid)] ${Se?"bg-[var(--theme-surface-strong)] text-[var(--theme-fg)]":oe?"text-[var(--theme-fg)] hover:bg-[var(--theme-hover)]":"cursor-not-allowed text-[var(--theme-fg-muted)] opacity-70"}`,children:[e.jsxs("span",{className:"flex min-w-0 flex-wrap items-center gap-x-2 gap-y-1",children:[e.jsx("span",{className:"truncate font-medium",children:S.displayName}),e.jsx("span",{className:"host-pill rounded-full px-2 py-0.5 text-[0.68rem]",children:Te}),e.jsx("span",{className:"text-[0.68rem] text-[var(--theme-fg-muted)]",children:nt})]}),e.jsxs("span",{className:"mt-1 block truncate font-mono text-[0.68rem] text-[var(--theme-fg-muted)]",children:["Probe: ",(R==null?void 0:R.baseProbeCommand)??"Unavailable"]}),e.jsxs("span",{className:"mt-0.5 block truncate font-mono text-[0.68rem] text-[var(--theme-fg-muted)]",children:["ACP: ",(R==null?void 0:R.serverCommand)??"Unavailable"]})]}),ye&&(R!=null&&R.installCommand)?e.jsx("button",{type:"button",onClick:()=>void je(S),disabled:ae||ke||K!==null,className:"host-secondary-button my-auto shrink-0 rounded-lg border px-3 py-2 text-xs font-medium transition disabled:cursor-not-allowed disabled:opacity-60","aria-label":`Install ACP adapter for ${S.displayName}`,children:ke?"Installing...":"Install adapter"}):null,e.jsxs("span",{id:ot,role:"tooltip",className:"pointer-events-none absolute inset-x-2 bottom-[calc(100%-0.2rem)] z-20 invisible rounded-md border border-[var(--theme-border)] bg-[var(--theme-panel)] px-3 py-2 text-xs leading-5 text-[var(--theme-fg)] opacity-0 shadow-[var(--theme-shadow)] transition group-hover/agent:visible group-hover/agent:opacity-100 group-focus-within/agent:visible group-focus-within/agent:opacity-100",children:[R==null?void 0:R.statusMessage,e.jsxs("span",{className:"mt-1 block font-mono text-[0.68rem] text-[var(--theme-fg-muted)]",children:["Base probe: ",R==null?void 0:R.baseProbeCommand]}),e.jsxs("span",{className:"block font-mono text-[0.68rem] text-[var(--theme-fg-muted)]",children:["ACP probe: ",R==null?void 0:R.serverProbeCommand]})]})]},S.id)})})]}):null,e.jsxs("div",{children:[e.jsx("label",{className:"host-form-label text-xs font-medium",htmlFor:`${d}-thread-model`,children:"Model"}),e.jsxs("select",{id:`${d}-thread-model`,value:G,onChange:S=>{const R=v.find(oe=>oe.model===S.target.value)??null;te(S.target.value),I(oe=>oe&&(R!=null&&R.supportedReasoningEfforts.some(ye=>ye.reasoningEffort===oe))?oe:(R==null?void 0:R.defaultReasoningEffort)??null)},disabled:v.length===0,className:T,children:[v.length===0?e.jsx("option",{value:"",children:"No models available"}):null,v.map(S=>e.jsx("option",{value:S.model,children:S.displayName},S.id))]})]}),qe&&qe.supportedReasoningEfforts.length>0?e.jsxs("div",{children:[e.jsx("label",{className:"host-form-label text-xs font-medium",htmlFor:`${d}-thread-effort`,children:"Reasoning effort"}),e.jsx("select",{id:`${d}-thread-effort`,value:Q??"",onChange:S=>I(S.target.value||null),className:T,children:qe.supportedReasoningEfforts.map(S=>e.jsx("option",{value:S.reasoningEffort,children:S.reasoningEffort},S.reasoningEffort))})]}):null,e.jsxs("div",{children:[e.jsx("label",{className:"host-form-label text-xs font-medium",htmlFor:`${d}-thread-title`,children:"Title"}),e.jsx("input",{id:`${d}-thread-title`,value:se,onChange:S=>J(S.target.value),placeholder:"Optional. Falls back to first prompt.",className:T})]}),e.jsxs("div",{children:[e.jsx("label",{className:"host-form-label text-xs font-medium",htmlFor:`${d}-thread-approval-mode`,children:"Approval mode"}),e.jsxs("select",{id:`${d}-thread-approval-mode`,value:ee,onChange:S=>i(S.target.value),className:T,children:[e.jsx("option",{value:"yolo",children:"yolo"}),e.jsx("option",{value:"guarded",children:"guarded"})]})]}),ne&&e.jsx("div",{className:"host-error rounded-lg border px-4 py-3 text-sm",children:ne}),e.jsxs("div",{className:"flex flex-wrap items-center gap-2 pt-1",children:[e.jsx("button",{type:"submit",disabled:ae||!H||!G||!L||h==="acp"&&((ze=B==null?void 0:B.acpAgent)==null?void 0:ze.availability)!=="ready",className:j,children:ae?"Creating...":"Create Thread"}),r?e.jsx("button",{type:"button",onClick:r,disabled:ae,className:f,children:"Cancel"}):null]})]})}const nn=3,Gc=3,zc=1e3,Jc=2e3,Zs=5500,Kc=3e3,Qs=0,kt=1,is=3,Yc=[],Xc=[],Zc=[],Qc={sessions:{list:!1,read:!1,resume:!1,importLocal:!1,load:!1,close:!1,delete:!1},turns:{start:!1,streamInput:!1,steer:!1,interrupt:!1,compact:!1},branching:{fork:!1,hardRollback:!1,resumeAt:!1,rewindFiles:!1},controls:{planMode:!1,permissionRequests:!1,sandboxMode:!1,performanceMode:!1,goals:!1},management:{models:!1,mcpStatus:!1,skills:!1,hooks:!1,hookTrust:!1,hostConfigFiles:!1,providerSettings:!1},usage:{contextWindow:!1,tokenUsage:!1,costUsd:!1}},eu={workspace:!0,toolUsage:!1,guide:!1,threadGraph:!1,extensions:!1,defaultTab:"workspace"};function ds(t,s){return t instanceof ce?t.payload.message:t instanceof Error?t.message:s}function on(t){return t==="read"?"View only":"Collaborator"}function ln(t){switch(t){case"write":return"Workspace write";case"read":return"Workspace read";case"none":default:return"No workspace"}}function tu(t){var s,a;return((a=(s=t.match(/^\[PHOTO\s+([^\]]+)\]$/))==null?void 0:s[1])==null?void 0:a.trim())??null}function dn(t){return!(t!=null&&t.length)||typeof URL.createObjectURL!="function"?[]:t.flatMap(s=>{if(s.kind!=="photo")return[];const a=tu(s.placeholder);return a?[{path:a,url:URL.createObjectURL(s.file)}]:[]})}function su(t){if(typeof URL.revokeObjectURL=="function")for(const s of t)URL.revokeObjectURL(s.url)}function au(t,s){const a=t.trim().replace(/\\/g,"/").replace(/\/+$/,""),r=s.trim().replace(/\\/g,"/").replace(/\/+$/,"");if(!a)return null;if(!a.startsWith("/"))return a.replace(/^\.\/+/,"").replace(/^\/+/,"");if(a===r)return"";const o=`${r}/`;return a.startsWith(o)?a.slice(o.length):null}function ru(){return e.jsx("svg",{"aria-hidden":"true",viewBox:"0 0 16 16",className:"h-3.5 w-3.5 fill-current",children:e.jsx("path",{d:"M5.75 1.75c-.97 0-1.75.78-1.75 1.75v.25H3.5c-.97 0-1.75.78-1.75 1.75v6c0 .97.78 1.75 1.75 1.75h4.75c.97 0 1.75-.78 1.75-1.75v-.25h.5c.97 0 1.75-.78 1.75-1.75v-6c0-.97-.78-1.75-1.75-1.75h-4.75Zm-.5 2V3.5c0-.28.22-.5.5-.5h4.75c.28 0 .5.22.5.5v6a.5.5 0 0 1-.5.5H10v-4.5c0-.97-.78-1.75-1.75-1.75h-3Zm-1.75 1.25h4.75c.28 0 .5.22.5.5v6a.5.5 0 0 1-.5.5H3.5a.5.5 0 0 1-.5-.5v-6c0-.28.22-.5.5-.5Z"})})}function cs({status:t}){return e.jsxs("svg",{"aria-hidden":"true",viewBox:"0 0 16 16",className:"h-4.5 w-4.5 fill-none stroke-current",strokeWidth:"1.4",strokeLinecap:"round",strokeLinejoin:"round",children:[e.jsx("path",{d:"M2.5 6.75A8.22 8.22 0 0 1 8 4.5c2.14 0 4.1.8 5.5 2.25"}),e.jsx("path",{d:"M4.75 9a4.95 4.95 0 0 1 6.5 0"}),e.jsx("path",{d:"M6.9 11.3a1.9 1.9 0 0 1 2.2 0"}),t==="connected"?e.jsx("path",{d:"m6.7 13.2.9.9 1.7-2"}):t==="offline"?e.jsx("path",{d:"M3 3l10 10"}):t==="detached"?null:e.jsxs(e.Fragment,{children:[e.jsx("path",{d:"M11.8 11.1a2.2 2.2 0 0 1-1.8 2.7"}),e.jsx("path",{d:"m10.7 11.35 1.3-.55-.55-1.3"})]})]})}function nu(t,s){if(!t)return"Thread disconnected";switch(s.status){case"connected":return"Realtime updates connected";case"reconnecting":return"Realtime updates reconnecting";case"offline":return"Browser offline";case"checking":return"Checking realtime connection"}}function cn(){var Tr,Er;const{id:t=""}=Qo(),s=n.useRef(t);s.current=t;const a=qt(),r=rt(),o=Vt(),l=yn(),d=n.useRef(""),u=n.useRef(null),p=n.useRef(null),g=n.useRef(null),b=n.useRef(!1),x=n.useRef(null),N=n.useRef(null),v=n.useRef(typeof navigator>"u"?!0:navigator.onLine),c=n.useRef(!1),h=n.useRef(null),D=n.useRef(null),H=n.useRef(0),O=n.useRef(0),E=n.useRef(Promise.resolve()),U=n.useRef(!1),G=n.useRef(0),te=n.useRef(null),Q=n.useRef(null),I=n.useRef(null),se=n.useRef(!1),J=n.useRef(null),ee=n.useRef(new Set),[i,W]=n.useState(null),[fe,ae]=n.useState([]),[we,ge]=n.useState([]),[Ne,K]=n.useState([]),[M,ne]=n.useState(null),[P,V]=n.useState(null),[Y,Ce]=n.useState(null),[De,qe]=n.useState(0),[be,B]=n.useState(null),[L,le]=n.useState(""),[T,f]=n.useState(null),[j,$]=n.useState(null),re=n.useRef(null),[je,Ue]=n.useState(!0),[ze,S]=n.useState(0),[R,oe]=n.useState(0),[ye,ke]=n.useState(0),[Se,Te]=n.useState(!1),[nt,ot]=n.useState(!1),[it,Ss]=n.useState(!0),[zt,Cs]=n.useState(!1),[ft,dt]=n.useState(!1),[Je,Ca]=n.useState("chat"),[fo,po]=n.useState(null),Ta=l.getThreadPanels().some(m=>m.kind==="terminal");n.useEffect(()=>{re.current=j},[j]);const Ea=n.useMemo(()=>({fetchState:Qi,createShell:ad,terminateShell:rd,updateShell:nd,connectSocket:Ed}),[]),Ra=n.useCallback(m=>Fe(m),[]),Jt=n.useCallback(m=>{r(Fe(m))},[r]),Aa=n.useCallback(m=>xs(m),[]),Ia=n.useCallback(({close:m,closeNavigation:w,currentWorkspaceId:y})=>e.jsx(Sa,{variant:"dialog",initialWorkspaceId:y,onCancel:m,onCreated:C=>{m(),w(),r(Fe(C.id))}}),[r]),Pa=n.useCallback(({threadId:m,path:w})=>Bi(m,{path:w}),[]),[La,Ts]=n.useState({prompt:"",attachments:[]}),[he,Oa]=n.useState(null),[Ua,At]=n.useState(!1),[xo,$a]=n.useState(!1),[go,Da]=n.useState(!1),[Ma,_a]=n.useState(null),[pt,Kt]=n.useState("idle"),[ct,Ha]=n.useState({status:v.current?"checking":"offline",browserOnline:v.current,healthOk:!1,socketOpen:!1,lastHealthyAt:null}),[Ee,We]=n.useState(null),[Yt,bt]=n.useState([]);n.useEffect(()=>{const m=(Ee==null?void 0:Ee.attachmentPreviews)??[];return()=>{su(m)}},[Ee]);const[Qe,Es]=n.useState(null),[Rs,Ba]=n.useState(!1),[vo,ie]=n.useState(null),As=((Tr=be==null?void 0:be.hostConfigFiles.find(m=>{var w;return(w=m.roles)==null?void 0:w.includes("mcp")}))==null?void 0:Tr.name)??null,{exportBusy:Is,exportDialogOpen:Xt,exportTurnsState:Wa,forkTurnOptionsState:bo,goalState:Fa,handleCreateHook:yo,handleExportTranscript:qa,handleForkLatest:wo,handleForkTurn:jo,handleOpenForkTurns:No,handleOpenGoal:ko,handleOpenHooks:So,handleOpenMcp:Co,handleOpenSkills:To,handleTrustHook:Eo,handleUntrustHook:Ro,handleUpdateGoal:Ao,handleUpdateHook:Io,hooksState:Po,loadExportTurns:Va,mcpState:Lo,setExportDialogOpen:Ps,setGoalState:Ls,skillsState:Oo}=Bc({detailRef:I,id:t,navigate:r,setDetail:W,setError:ie,setThreads:ae}),[Os,Zt]=n.useState(!1),[Ga,et]=n.useState({status:"idle",shares:[],error:null}),[Qt,es]=n.useState({status:"idle",access:null,error:null}),za=kn(a.pathname),xt=ht()&&!!za,ue=Qt.access,It=!xt||(ue==null?void 0:ue.kind)==="owner",He=It||(ue==null?void 0:ue.kind)==="shared"&&ue.threadAccess==="control",Ja=xt&&(ue==null?void 0:ue.kind)==="owner",Uo=(i==null?void 0:i.workspace.id)??(i==null?void 0:i.thread.workspaceId)??null,$o=xt?(ue==null?void 0:ue.kind)==="owner"?"write":(ue==null?void 0:ue.kind)==="shared"&&ue.workspaceId&&ue.workspaceId===Uo?ue.workspaceAccess:"none":"write",yt=n.useCallback(async()=>{const m=I.current,w=at();if(!ht()||!m||!w){et({status:"ready",shares:[],error:null});return}et(y=>({...y,status:"loading",error:null}));try{const C=(await Un()).sharedByMe.filter(F=>F.deviceId===w&&F.threadId===m.thread.id).map(F=>({id:F.id,targetUsername:F.targetUsername,label:F.label,threadAccess:F.threadAccess,workspaceAccess:F.workspaceAccess,createdAt:F.createdAt}));et({status:"ready",shares:C,error:null})}catch(y){et(C=>({...C,status:"failed",error:ds(y,"Unable to load active shares.")}))}},[I]),Ka=n.useCallback(async m=>{const w=I.current,y=at();if(!ht()||!w||!y){et(F=>({...F,status:"failed",error:"Relay sharing is only available from a relay device route."}));return}const C=m.workspaceAccess==="none"?null:w.workspace.id??w.thread.workspaceId??null;if(m.workspaceAccess!=="none"&&!C){et(F=>({...F,status:"failed",error:"This thread is not attached to a workspace."}));return}Zt(!0),et(F=>({...F,error:null}));try{await ri({targetIdentifier:m.targetIdentifier,deviceId:y,threadId:w.thread.id,workspaceId:C,label:m.label??null,threadAccess:m.threadAccess,workspaceAccess:m.workspaceAccess}),await yt()}catch(F){const X=ds(F,"Unable to create share.");et(pe=>({...pe,status:"failed",error:X})),ie(X)}finally{Zt(!1)}},[I,yt]),Ya=n.useCallback(async m=>{Zt(!0),et(w=>({...w,error:null}));try{await $n(m),await yt()}catch(w){const y=ds(w,"Unable to revoke share.");et(C=>({...C,status:"failed",error:y})),ie(y)}finally{Zt(!1)}},[yt]),Xa=n.useCallback(()=>{const m=at();m&&(Ps(!1),r(`/relay-devices?shareDevice=${encodeURIComponent(m)}`))},[r]);n.useEffect(()=>{Xt&&yt()},[Xt,yt]),n.useEffect(()=>{const m=I.current,w=at();if(!ht()||!m||!w){es({status:"idle",access:null,error:null});return}let y=!1;return es(C=>({...C,status:"loading",error:null})),Ql({deviceId:w,threadId:m.thread.id}).then(C=>{y||es({status:"ready",access:C,error:null})}).catch(C=>{y||es({status:"failed",access:null,error:ds(C,"Unable to verify relay permissions.")})}),()=>{y=!0}},[i==null?void 0:i.thread.id,i==null?void 0:i.workspace.id,I]),no({enabled:!!t,setThreads:ae});const Za=n.useCallback(()=>{const m=d.current;d.current="",u.current=null,m&&n.startTransition(()=>{le(w=>w+m)})},[]),Qa=n.useCallback(m=>{d.current+=m,u.current===null&&(u.current=window.requestAnimationFrame(()=>{Za()}))},[Za]),er=n.useCallback((m,w)=>{$(y=>{const C=(y==null?void 0:y.turnId)===m?y.items:[],F=C.findIndex(me=>me.id===w.id),X=to(C[F],w),pe=F>=0?C.map((me,ve)=>ve===F?X:me):[...C,X];return{turnId:m,items:pe,updatedAt:new Date().toISOString()}})},[]),tr=n.useCallback((m,w,y,C,F)=>{$(X=>{const pe=(X==null?void 0:X.turnId)===m?X.items:[],me=pe.find(Ie=>Ie.id===w),ve=(me==null?void 0:me.kind)==="agentMessage"?{...me,text:`${me.text}${y}`,sequence:C??me.sequence??null}:{id:w,createdAt:F??new Date().toISOString(),kind:"agentMessage",text:y,sequence:C},q=pe.findIndex(Ie=>Ie.id===w),Oe=q>=0?pe.map((Ie,Pe)=>Pe===q?ve:Ie):[...pe,ve];return{turnId:m,items:Oe,updatedAt:new Date().toISOString()}})},[]),tt=n.useCallback(()=>{d.current="",u.current!==null&&(window.cancelAnimationFrame(u.current),u.current=null)},[]),ts=n.useCallback(m=>{const w=J.current,y=w&&Object.keys(w).length>0?{...m,thread:{...m.thread,...w}}:m,C={...y,turns:Ec(y.turns,re.current)},F=I.current;f(C.livePlan??null);const X=gt((F==null?void 0:F.turns)??[],C.turns,C.thread.activeTurnId);I.current={...C,turns:X},$(q=>Pc(q,C.liveItems??null,X)),Ls(q=>q.status==="idle"?q:{...q,data:C.goal??null});const pe=C.thread.activeTurnId===null&&C.thread.status!=="running";W(q=>q&&!C.goalHistory?{...C,turns:gt(q.turns,C.turns,C.thread.activeTurnId),pendingRequests:tn(q.pendingRequests,C.pendingRequests,ee.current),...q.goalHistory?{goalHistory:q.goalHistory}:{}}:q?{...C,turns:gt(q.turns,C.turns,C.thread.activeTurnId),pendingRequests:tn(q.pendingRequests,C.pendingRequests,ee.current)}:{...C,turns:X}),ae(q=>Bt(q,C.thread));const me=new Map(C.turns.map(q=>[q.id,q])),ve=new Set((C.pendingSteers??[]).map(q=>q.clientRequestId).filter(q=>!!q));bt(q=>q.filter(Oe=>{if(ve.has(Oe.clientRequestId))return!1;const Ie=me.get(Oe.turnId);return!(!Ie||Na(Ie,Oe.prompt)||C.thread.activeTurnId!==Oe.turnId&&Ie.status!=="inProgress")})),We(q=>{var Z;if(!q)return q;if(q.id.startsWith("optimistic-goal-")&&((Z=C.activityNotes)!=null&&Z.some(de=>de.kind==="goal"&&de.text===q.prompt)))return null;const Oe=q.serverTurnId??q.id,Ie=C.turns.some(de=>de.id===Oe),Pe=me.get(Oe)??null,k=Dc(C.turns,q.prompt),_=!!k;if(k&&!q.serverTurnId)return{...q,id:k.id,serverTurnId:k.id,status:q.status==="failed"?q.status:k.status==="inProgress"?"inProgress":q.status};if(Pe&&q.serverTurnId)return Pe.items.some(xe=>xe.kind==="userMessage")?Pe.status==="inProgress"?{...q,id:Pe.id,serverTurnId:Pe.id,status:q.status==="failed"?q.status:"inProgress"}:null:{...q,id:Pe.id,serverTurnId:Pe.id,status:q.status==="failed"?q.status:Pe.status==="inProgress"?"inProgress":Pe.status==="failed"?"failed":"completed"};if(!q.serverTurnId&&ka(q.prompt)&&C.thread.activeTurnId&&C.thread.status==="running"){const de=me.get(C.thread.activeTurnId);if(de&&ro(de))return{...q,id:de.id,serverTurnId:de.id,status:q.status==="failed"?q.status:"inProgress"}}return Ie||pe&&_?null:q}),(pe||Q.current&&C.turns.some(q=>q.id===Q.current))&&(Q.current=null,tt(),le(""),f(null),$(null))},[tt]);n.useEffect(()=>{I.current=i},[i]),n.useEffect(()=>{i!=null&&i.thread.title&&(document.title=i.thread.title)},[i==null?void 0:i.thread.title]),n.useEffect(()=>{const m=i==null?void 0:i.thread.provider;if(!m||m!=="codex"&&m!=="claude"){Ce(null);return}let w=!1;const y=async()=>{var F;try{const X=await Ri(m);w||Ce(((F=X.usage)==null?void 0:F.authKind)==="subscription"&&X.usage.windows.length>0?X.usage:null)}catch{w||Ce(X=>X?{...X,stale:!0}:null)}};y();const C=window.setInterval(y,6e4);return()=>{w=!0,window.clearInterval(C)}},[i==null?void 0:i.thread.lastTurnCompletedAt,i==null?void 0:i.thread.provider,De]);const sr=n.useCallback(async({seedThread:m}={})=>{var k,_,Z;const w=G.current+1;G.current=w;const y=(m==null?void 0:m.provider)??((k=I.current)==null?void 0:k.thread.provider)??"codex",C=(m==null?void 0:m.agentId)??((_=I.current)==null?void 0:_.thread.agentId)??null,F=((Z=I.current)==null?void 0:Z.workspace.absPath)??null,X=y==="acp"&&C&&F?pa(y,{agentId:C,cwd:F}):ca(y),pe=y==="acp"?_t(y):Promise.resolve([]),me=y==="acp"&&C?Ii(y,C):Promise.resolve(null),[ve,q,Oe,Ie,Pe]=await Promise.allSettled([ga(),Mn(y),X,pe,me]);if(G.current===w&&(ve.status==="fulfilled"?ae(m?Bt(ve.value,m):ve.value):m&&ae(de=>Bt(de,m)),q.status==="fulfilled"&&(te.current=y,ne(q.value.status),V(q.value.capabilities),B(q.value.managementSchema)),Oe.status==="fulfilled"&&(te.current=y,ge(Oe.value)),Ie.status==="fulfilled"&&K(Ie.value),Pe.status==="fulfilled"&&Pe.value)){const de=Pe.value;V(de.effectiveCapabilities??Qc),de.effectiveCapabilities||ie(xe=>xe??`The selected ACP agent is ${de.availability.replaceAll("_"," ")}. Install or repair its adapter before continuing.`)}},[]),lt=n.useCallback(async({showLoading:m=!0,clearError:w=!0,reportError:y=!0,limit:C=nn}={})=>{if(O.current>0){U.current=!0;return}const F=H.current+1;H.current=F,m&&Ss(!0),w&&ie(null);try{const X=await _r(t,{limit:C});if(H.current!==F)return;ts(X),te.current!==X.thread.provider&&sr({seedThread:X.thread})}catch(X){if(H.current!==F||!y)return;ie(X instanceof Error?X.message:"Unable to load thread detail.")}finally{H.current===F&&Ss(!1)}},[ts,t,sr]),wt=n.useCallback(m=>{const w=E.current.then(async()=>{O.current+=1,H.current+=1;try{const y=await m();return y.thread.id===s.current&&ts(y),y}finally{O.current-=1,window.setTimeout(()=>{O.current===0&&U.current&&(U.current=!1,lt({showLoading:!1,clearError:!1,reportError:!1}))},0)}});return E.current=w.then(()=>{},()=>{}),w},[ts,lt]),$e=n.useCallback(()=>{var me;const m=((me=p.current)==null?void 0:me.readyState)??is,w=m===kt,y=v.current,C=Date.now(),F=x.current!==null&&C-Date.parse(x.current)<=Zs,X=N.current!==null&&C-N.current<=Zs;let pe;y?w&&X?pe="connected":m===Qs||g.current!==null||F||X||b.current?pe="reconnecting":pe="checking":pe="offline",Ha(ve=>ve.status===pe&&ve.browserOnline===y&&ve.healthOk===F&&ve.socketOpen===w&&ve.lastHealthyAt===x.current?ve:{status:pe,browserOnline:y,healthOk:F,socketOpen:w,lastHealthyAt:x.current})},[]);n.useEffect(()=>{H.current+=1,G.current+=1,W(null),ie(null),Ss(!0),Ts({prompt:"",attachments:[]}),Cs(!1),Kt("idle"),We(null),bt([]),$(null),J.current=null,Q.current=null,ee.current=new Set,x.current=null,N.current=null,c.current=!1,v.current=typeof navigator>"u"?!0:navigator.onLine,Ha({status:v.current?"checking":"offline",browserOnline:v.current,healthOk:!1,socketOpen:!1,lastHealthyAt:null})},[t,za]),n.useEffect(()=>{if(pt==="idle")return;const m=window.setTimeout(()=>{Kt("idle")},pt==="copied"?1200:1600);return()=>{window.clearTimeout(m)}},[pt]),n.useEffect(()=>{if(typeof document>"u")return;const{documentElement:m,body:w}=document;return m.classList.add("thread-detail-scroll-locked"),w.classList.add("thread-detail-scroll-locked"),()=>{m.classList.remove("thread-detail-scroll-locked"),w.classList.remove("thread-detail-scroll-locked")}},[]),n.useEffect(()=>{lt({showLoading:!0,limit:nn})},[lt]),n.useEffect(()=>{let m=!1,w=null;const y=()=>{lt({showLoading:!1,clearError:!1,reportError:!1})},C=()=>{g.current!==null&&(window.clearTimeout(g.current),g.current=null)},F=()=>{m||!v.current||g.current!==null||(g.current=window.setTimeout(()=>{g.current=null,!m&&ve()},zc),$e())},X=()=>{const k=p.current;if(p.current=null,k)try{k.close()}catch{}},pe=k=>{if(k.threadId===t){if(k.type==="thread.output.delta"&&typeof k.payload.delta=="string"){const _=typeof k.payload.turnId=="string"?k.payload.turnId:null,Z=typeof k.payload.itemId=="string"?k.payload.itemId:null,de=typeof k.payload.sequence=="number"&&Number.isFinite(k.payload.sequence)?k.payload.sequence:null;_&&Z?tr(_,Z,k.payload.delta,de,k.payload.createdAt??k.timestamp):Qa(k.payload.delta),_&&We(xe=>xe&&(xe.serverTurnId===null||xe.serverTurnId===_)?{...xe,serverTurnId:_,id:_,status:xe.status==="failed"?xe.status:"inProgress",tokenUsage:xe.tokenUsage}:xe)}if(k.type==="thread.context.updated"){const _=k.payload.contextUsage&&typeof k.payload.contextUsage=="object"?k.payload.contextUsage:null;if(_){const Z=_;W(de=>de&&{...de,thread:{...de.thread,contextUsage:Z}}),ae(de=>de.map(xe=>xe.id===t?{...xe,contextUsage:Z}:xe))}}if(k.type==="thread.turn.token.updated"&&typeof k.payload.turnId=="string"&&k.payload.tokenUsage&&typeof k.payload.tokenUsage=="object"){const _=k.payload.turnId,Z=k.payload.tokenUsage,de=k.payload.priceEstimate&&typeof k.payload.priceEstimate=="object"?k.payload.priceEstimate:null;W(xe=>{if(!xe)return xe;const Ot=_c(xe.turns,_,Z,de);return Ot===xe.turns?xe:{...xe,turns:Ot}}),We(xe=>xe&&(xe.serverTurnId===_||xe.id===_)?{...xe,tokenUsage:Z,priceEstimate:de}:xe)}if(k.type==="thread.turn.started"||k.type==="thread.turn.completed"||k.type==="thread.turn.failed"||k.type==="thread.updated"||k.type==="thread.goal.updated"||k.type==="thread.goal.cleared"||k.type==="thread.request.created"||k.type==="thread.request.resolved"){if(k.type==="thread.goal.updated"){const _=k.payload.goal&&typeof k.payload.goal=="object"?k.payload.goal:null,Z=Array.isArray(k.payload.goalHistory)?k.payload.goalHistory:null;Ls({status:"ready",data:_,error:null}),W(de=>de&&(Z?{...de,goal:_,goalHistory:Z}:_?{...de,goal:_,goalHistory:ws(de.goalHistory??[],_)}:{...de,goal:_}))}if(k.type==="thread.goal.cleared"){const _=Array.isArray(k.payload.goalHistory)?k.payload.goalHistory:null;Ls({status:"ready",data:null,error:null}),W(Z=>Z&&(_?{...Z,goal:null,goalHistory:_}:{...Z,goal:null}))}if(y(),k.type==="thread.turn.started"){tt(),le(""),$(null),Q.current=null;const _=typeof k.payload.turnId=="string"?k.payload.turnId:null;_&&We(Z=>Z&&{...Z,serverTurnId:_,id:_,status:Z.status==="failed"?Z.status:"inProgress",error:null,tokenUsage:Z.tokenUsage})}if(k.type==="thread.turn.completed"||k.type==="thread.turn.failed"){tt(),le("");const _=typeof k.payload.turnId=="string"?k.payload.turnId:null;_&&(Q.current=_,k.type==="thread.turn.failed"&&We(Z=>Z&&(Z.serverTurnId===_||Z.id===_)?{...Z,status:"failed",error:typeof k.payload.error=="string"?k.payload.error:"Unable to complete the turn.",tokenUsage:Z.tokenUsage}:Z))}}if(k.type==="thread.request.created"&&Ic(k.payload.request)&&(ee.current.delete(k.payload.request.id),W(_=>_&&Rc(_,k.payload.request))),k.type==="thread.request.resolved"&&typeof k.payload.requestId=="string"){const _=k.payload.requestId;ee.current.add(_),W(Z=>Z&&Ac(Z,_))}if((k.type==="thread.item.started"||k.type==="thread.item.completed")&&k.payload.item&&typeof k.payload.item=="object"&&typeof k.payload.turnId=="string"){const _=k.payload.turnId,Z=k.payload.item;typeof Z.id=="string"&&typeof Z.text=="string"&&er(_,Z)}k.type==="thread.plan.updated"&&Array.isArray(k.payload.plan)&&f({turnId:String(k.payload.turnId??""),explanation:typeof k.payload.explanation=="string"?k.payload.explanation:null,plan:k.payload.plan})}},me=()=>{const k=p.current;if(!(!k||k.readyState!==kt))try{k.send(JSON.stringify({type:"supervisor.ping",timestamp:new Date().toISOString()}))}catch{c.current=!0,X(),F(),$e()}},ve=()=>{var Z;if(m||!v.current){$e();return}const k=((Z=p.current)==null?void 0:Z.readyState)??is;if(k===Qs||k===kt){$e();return}const _=Fn(pe);p.current=_,$e(),_.addEventListener("message",de=>{if(p.current===_)try{const xe=JSON.parse(de.data);(xe.type==="supervisor.connected"||xe.type==="supervisor.pong")&&(N.current=Date.now(),$e())}catch{}}),_.addEventListener("open",()=>{p.current===_&&(c.current=!0,qe(de=>de+1),y(),me(),$e())}),_.addEventListener("close",()=>{p.current===_&&(p.current=null),c.current=!0,F(),$e()}),_.addEventListener("error",()=>{p.current===_&&(p.current=null),c.current=!0,F(),$e()})},q=async()=>{var k;if(!(m||!v.current||b.current)){b.current=!0,$e();try{await Di();const _=c.current;x.current=new Date().toISOString(),_&&(c.current=!1,y()),(((k=p.current)==null?void 0:k.readyState)??is)!==kt&&ve()}catch{x.current=null,c.current=!0,F()}finally{b.current=!1,$e()}}},Oe=()=>{v.current=!0,c.current=!0,$e(),ve(),q()},Ie=()=>{v.current=!1,x.current=null,N.current=null,c.current=!0,C(),X(),$e()},Pe=()=>{var Z;if(m||!v.current){$e();return}const k=((Z=p.current)==null?void 0:Z.readyState)??is,_=N.current===null?null:Date.now()-N.current;k===kt&&_!==null&&_>Zs?(c.current=!0,X(),F()):k===kt?me():k!==Qs&&ve(),q(),$e()};return window.addEventListener("online",Oe),window.addEventListener("offline",Ie),ve(),q(),w=window.setInterval(Pe,Jc),()=>{m=!0,window.removeEventListener("online",Oe),window.removeEventListener("offline",Ie),C(),w!==null&&window.clearInterval(w),tt(),X()}},[tr,tt,t,lt,Qa,$e,er]),n.useEffect(()=>{if(!((i==null?void 0:i.thread.activeTurnId)!==null||(i==null?void 0:i.thread.status)==="running"||Ee!==null||Yt.length>0||L.length>0||T!==null||j!==null))return;const w=window.setInterval(()=>{lt({showLoading:!1,clearError:!1,reportError:!1})},Kc);return()=>{window.clearInterval(w)}},[i==null?void 0:i.thread.activeTurnId,i==null?void 0:i.thread.status,L.length,j,T,lt,Yt.length,Ee]);const ar=n.useCallback(async()=>{var m;if(!(!i||i.turns.length===0||zt)){Cs(!0),ie(null);try{const w=(m=i.turns[0])==null?void 0:m.id,y=await _r(t,{limit:Gc,...w?{beforeTurnId:w}:{}});W(C=>C?{...C,turns:Tc(C.turns,y.turns),totalTurnCount:Math.max(C.totalTurnCount??C.turns.length,y.totalTurnCount??y.turns.length)}:y)}catch(w){ie(w instanceof Error?w.message:"Unable to load earlier turns.")}finally{Cs(!1)}}},[i,t,zt]);async function Do(m){var Oe,Ie,Pe;if(Je==="shell"){if((i==null?void 0:i.thread.isLoaded)===!1)return await Us({attachShell:!0}),!1;let k=!1;if((he==null?void 0:he.shellInputEnabled)!==!0&&((he==null?void 0:he.loading)===!1&&(he==null?void 0:he.isConnecting)!==!0&&(he==null?void 0:he.status)!=="creating"&&(he==null?void 0:he.status)!=="workspace_missing"&&(await((Oe=h.current)==null?void 0:Oe.toggleConnection()),k=!0),(he==null?void 0:he.isConnecting)===!0))return ie("Connecting to the shell. Try again after it attaches."),!1;if(((Ie=h.current)==null?void 0:Ie.sendCommand(m.prompt))??!1)ie(null);else return ie(k?"Shell is still attaching. Try again after it connects.":"Connect the shell before sending commands."),!1;return!0}if(Pt)return ie(Pt),!1;dt(!0),ie(null),S(k=>k+1);const w=I.current,y=w?{...w.thread,...J.current??{}}:null,C=(y==null?void 0:y.model)??null,F=(y==null?void 0:y.reasoningEffort)??null,X=Uc(),pe=`optimistic-${Date.now()}`,me=`optimistic-steer-${X}`,ve=new Date().toISOString();let q=[];try{let k=I.current;if(k&&!k.thread.isLoaded){const Re={...k.thread,...J.current??{}},Ve=await Hs(t,{...k.thread.model?{model:k.thread.model}:{}}),Me={...Ve,thread:{...Ve.thread,model:Re.model??Ve.thread.model,reasoningEffort:Re.reasoningEffort??Ve.thread.reasoningEffort,collaborationMode:Re.collaborationMode??Ve.thread.collaborationMode}};k=Me,I.current=Me,W(os=>os?{...Me,turns:gt(os.turns,Me.turns,Me.thread.activeTurnId)}:Me),ae(os=>os.map(Rr=>Rr.id===Me.thread.id?Me.thread:Rr))}const _=k?{...k.thread,...J.current??{}}:null,Z=(_==null?void 0:_.status)==="running"?_.activeTurnId:null,de=Je==="chat"&&!!Z;de&&Z?bt(Re=>[...Re,{id:me,clientRequestId:X,turnId:Z,prompt:m.prompt,createdAt:ve,status:"steering"}]):(q=dn(m.attachments),tt(),le(""),We({id:pe,serverTurnId:null,startedAt:ve,status:"sending",error:null,prompt:m.prompt,attachmentPreviews:q,model:C,reasoningEffort:F,reasoningEffortAvailable:Xs(we,C),tokenUsage:null,priceEstimate:null}));const xe={prompt:m.prompt,clientRequestId:X,..._!=null&&_.model?{model:_.model}:{},..._!=null&&_.reasoningEffort?{reasoningEffort:_.reasoningEffort}:{},..._!=null&&_.collaborationMode?{collaborationMode:_.collaborationMode}:{},...(Pe=m.attachments)!=null&&Pe.length?{attachments:m.attachments}:{}},Ot=await ld(t,xe),Ke=J.current&&Object.keys(J.current).length>0?{...Ot,...J.current}:Ot;W(Re=>Re&&{...Re,thread:Ke}),ae(Re=>Re.map(Ve=>Ve.id===Ke.id?Ke:Ve)),de&&Z?Ke.activeTurnId!==null&&Ke.activeTurnId!==Z&&Ke.lastTurnStartedAt!==(_==null?void 0:_.lastTurnStartedAt)?(q=dn(m.attachments),tt(),le(""),f(null),bt(Ve=>Ve.filter(Me=>Me.id!==me)),We({id:pe,serverTurnId:Ke.activeTurnId,startedAt:Ke.lastTurnStartedAt??ve,status:"inProgress",error:null,prompt:m.prompt,attachmentPreviews:q,model:C,reasoningEffort:F,reasoningEffortAvailable:Xs(we,C),tokenUsage:null,priceEstimate:null})):bt(Ve=>Ve.map(Me=>Me.id===me?{...Me,turnId:Ke.activeTurnId??Me.turnId,status:"accepted"}:Me)):(We(Re=>Re&&Re.id===pe?{...Re,id:Ke.activeTurnId??Re.id,serverTurnId:Ke.activeTurnId??Re.serverTurnId,status:"inProgress",error:null,tokenUsage:Re.tokenUsage,priceEstimate:Re.priceEstimate}:Re),f(null)),Ts({prompt:"",attachments:[]})}catch(k){const _=k instanceof ce?k.payload.message:k instanceof Error?k.message:"Unable to send prompt.";k instanceof ce?ie(k.payload.message):ie(_),bt(Z=>Z.filter(de=>de.clientRequestId!==X)),We(Z=>Z&&Z.id===pe?{...Z,status:"failed",error:_}:Z)}finally{dt(!1)}}async function rr(m){if(se.current)return!1;se.current=!0;try{return await Do(m)}finally{se.current=!1}}async function Mo(){const m=I.current;if(!m)return ie("Thread detail is still loading."),!1;if(m.thread.isLoaded)return!0;dt(!0),ie(null);try{const w=await Hs(t,{...m.thread.model?{model:m.thread.model}:{}});return W(y=>y?{...w,turns:gt(y.turns,w.turns,w.thread.activeTurnId)}:w),ae(y=>y.map(C=>C.id===w.thread.id?w.thread:C)),!0}catch(w){return ie(w instanceof Error?w.message:"Unable to connect this thread before setting its goal."),!1}finally{dt(!1)}}async function _o(m){var pe;const w=((pe=m.objective)==null?void 0:pe.trim())??"",y=w?`optimistic-goal-${Date.now()}`:null,C=new Date().toISOString(),F=I.current,X=(F==null?void 0:F.thread)??null;y&&(S(me=>me+1),We({id:y,serverTurnId:null,startedAt:C,status:"sending",error:null,prompt:w,attachmentPreviews:[],model:(X==null?void 0:X.model)??null,reasoningEffort:(X==null?void 0:X.reasoningEffort)??null,reasoningEffortAvailable:Xs(we,(X==null?void 0:X.model)??null),tokenUsage:null,priceEstimate:null}));try{await Ao(m),await lt({showLoading:!1,clearError:!1,reportError:!1}),y&&We(me=>me&&me.id===y?{...me,status:"completed",error:null}:me)}catch(me){const ve=me instanceof ce?me.payload.message:me instanceof Error?me.message:"Unable to set goal.";throw ie(ve),y&&We(q=>q&&q.id===y?{...q,status:"failed",error:ve}:q),me}}async function Ho(){const m=i==null?void 0:i.thread.providerSessionId;if(m)try{await navigator.clipboard.writeText(m),Kt("copied")}catch{Kt("failed")}}async function Us(m){if(i){dt(!0),ie(null),tt(),le("");try{if(i.thread.isLoaded){const y=await od(t);W(C=>C?{...y,turns:gt(C.turns,y.turns,y.thread.activeTurnId)}:y),Oa(null),ae(C=>C.map(F=>F.id===y.thread.id?y.thread:F)),At(!1);return}const w=await Hs(t,{...i.thread.model?{model:i.thread.model}:{}});W(y=>y?{...w,turns:gt(y.turns,w.turns,w.thread.activeTurnId)}:w),ae(y=>y.map(C=>C.id===w.thread.id?w.thread:C)),m!=null&&m.attachShell&&Je==="shell"&&At(!0)}catch(w){ie(w instanceof Error?w.message:"Unable to change connection state.")}finally{dt(!1)}}}async function ss(){var m;if(Je==="shell"){const w=((m=h.current)==null?void 0:m.sendControl("ctrl_c"))??!1;ie(w?null:"Connect the shell before sending Ctrl-C.");return}dt(!0),ie(null);try{const w=i!=null&&i.thread.activeTurnId?await Hr(t,{turnId:i.thread.activeTurnId}):await Hr(t);W(y=>y&&{...y,thread:w}),ae(y=>y.map(C=>C.id===w.id?w:C)),tt(),le("")}catch(w){ie(w instanceof Error?w.message:"Unable to interrupt turn.")}finally{dt(!1)}}async function $s(m){if(!i)return;const w=i,y={...J.current??{},...m.model!==void 0?{model:m.model}:{},...m.reasoningEffort!==void 0?{reasoningEffort:m.reasoningEffort}:{},...m.fastMode!==void 0?{fastMode:m.fastMode}:{},...m.collaborationMode!==void 0?{collaborationMode:m.collaborationMode}:{},...m.sandboxMode!==void 0?{sandboxMode:m.sandboxMode}:{}},C={...i.thread,...y};$a(!0),J.current=y,I.current={...i,thread:C},W(F=>F&&{...F,thread:C}),ae(F=>F.map(X=>X.id===C.id?{...X,...C}:X));try{const F=await cd(t,{...m.model!==void 0?{model:m.model}:{},...m.reasoningEffort!==void 0?{reasoningEffort:m.reasoningEffort}:{},...m.fastMode!==void 0?{fastMode:m.fastMode}:{},...m.collaborationMode!==void 0?{collaborationMode:m.collaborationMode}:{},...m.sandboxMode!==void 0?{sandboxMode:m.sandboxMode}:{}});J.current=null,I.current=w?{...w,thread:F}:null,W(X=>X&&{...X,thread:F}),ae(X=>X.map(pe=>pe.id===F.id?F:pe))}catch(F){J.current=null,I.current=w,W(w),ae(X=>X.map(pe=>pe.id===w.thread.id?w.thread:pe)),ie(F instanceof Error?F.message:"Unable to update thread settings.")}finally{$a(!1)}}const nr=n.useCallback(async(m,w)=>{if((ue==null?void 0:ue.kind)==="shared"&&ue.threadAccess==="read"){ie("This shared session is view only.");return}_a(m),ie(null);try{await wt(async()=>{const y=await Nd(t,m,w);return ee.current.add(m),y})}catch(y){ie(y instanceof Error?y.message:"Unable to answer this request.")}finally{_a(null)}},[t,ue,wt]),or=n.useCallback(m=>Vi(t,m),[t]),lr=n.useCallback(async(m,w)=>{ie(null);try{await wt(()=>id(m,w))}catch(y){throw ie(y instanceof Error?y.message:"Unable to cancel queued prompt."),y}},[wt]),ir=n.useCallback(async(m,w)=>{ie(null);try{await wt(()=>dd(m,w))}catch(y){throw ie(y instanceof Error?y.message:"Unable to steer queued prompt."),y}},[wt]);async function Ds(){if(i){Da(!0),ie(null);try{const m=await ud(t);W(w=>w&&{...w,thread:m}),ae(w=>w.map(y=>y.id===m.id?m:y))}catch(m){ie(m instanceof Error?m.message:"Unable to compact this thread context.")}finally{Da(!1)}}}async function dr(m,w){try{const y=await Bn(m,{title:w});ae(C=>C.map(F=>F.id===y.id?{...F,title:y.title,updatedAt:y.updatedAt}:F)),W(C=>C&&C.thread.id===y.id?{...C,thread:{...C.thread,title:y.title,updatedAt:y.updatedAt}}:C)}catch(y){throw ie(y instanceof Error?y.message:"Unable to rename thread."),y}}async function cr(){if(Qe){Ba(!0),ie(null);try{await Wn(Qe.id),ae(w=>w.filter(y=>y.id!==Qe.id));const m=Qe.id===(i==null?void 0:i.thread.id);if(Es(null),m){const w=fe.find(y=>y.id!==Qe.id&&y.workspaceId===(i==null?void 0:i.thread.workspaceId))??fe.find(y=>y.id!==Qe.id);r(w?Fe(w.id):Wt())}}catch(m){ie(m instanceof Error?m.message:"Unable to delete thread.")}finally{Ba(!1)}}}function ur(){Ca(m=>m==="chat"?(i!=null&&i.thread.isLoaded&&At(!0),"shell"):"chat")}async function mr(){var w;const m=await((w=h.current)==null?void 0:w.copyLastCommandOutput());ie(m?null:"Unable to copy the last shell command output.")}function hr(m){var y,C;const w=m==="clear"?((y=h.current)==null?void 0:y.sendCommand("clear"))??!1:((C=h.current)==null?void 0:C.sendControl(m))??!1;ie(w?null:"Connect the shell before sending control input.")}n.useEffect(()=>{if(!(!Ua||Je!=="shell"||!h.current||(i==null?void 0:i.thread.isLoaded)===!1||(he==null?void 0:he.loading)!==!1)){if((he==null?void 0:he.status)==="attached"){At(!1);return}At(!1),h.current.toggleConnection()}},[Je,i==null?void 0:i.thread.isLoaded,Ua,he==null?void 0:he.loading,he==null?void 0:he.status]),n.useEffect(()=>{if(Je!=="shell")return;const m=window.requestAnimationFrame(()=>{var w;(w=h.current)==null||w.refreshLayout({syncBackendSize:!1})});return()=>{window.cancelAnimationFrame(m)}},[Je]);const Pt=i?i.workspacePathStatus==="missing"?"Restore this workspace path on the current machine before continuing.":xt&&Qt.status==="loading"?"Checking relay permissions...":xt&&Qt.status==="failed"?Qt.error??"Unable to verify relay permissions.":(ue==null?void 0:ue.kind)==="shared"&&ue.threadAccess==="read"?"This shared session is view only.":null:null,{floatingMobileComposerBottomOffset:Bo,timelineBottomSpacer:fr,useFloatingMobileComposer:Wo}=Hc({activeView:Je,composerHostRef:D,threadId:(i==null?void 0:i.thread.id)??t}),Fo=i?e.jsxs("dl",{className:"space-y-4 text-sm",children:[e.jsxs("div",{className:"relative pr-9",children:[e.jsx("dt",{className:"text-[var(--theme-fg-muted)]",children:"Session ID"}),e.jsx("dd",{className:"mt-1 break-all text-[var(--theme-fg)]",children:i.thread.providerSessionId??"Unavailable"}),i.thread.providerSessionId&&e.jsx("button",{type:"button","aria-label":"Copy session ID",title:pt==="copied"?"Copied":pt==="failed"?"Copy failed":"Copy session ID",onClick:()=>void Ho(),className:`thread-mobile-hit-target absolute bottom-0 right-0 inline-flex h-5 w-5 items-center justify-center rounded-full border shadow-sm backdrop-blur transition ${pt==="copied"?"ui-status-info":pt==="failed"?"ui-status-danger":"border-[var(--theme-border)] bg-[var(--theme-surface-strong)] text-[var(--theme-fg-soft)] hover:bg-[var(--theme-hover)] hover:text-[var(--theme-fg)]"}`,children:e.jsx("span",{className:"scale-[0.72]",children:e.jsx(ru,{})})})]}),e.jsxs("div",{children:[e.jsx("dt",{className:"text-[var(--theme-fg-muted)]",children:"Source"}),e.jsx("dd",{className:"mt-1 text-[var(--theme-fg)]",children:i.thread.source==="supervisor"?`${i.thread.provider} supervisor thread`:`Imported local ${i.thread.provider} session`})]}),e.jsxs("div",{children:[e.jsx("dt",{className:"text-[var(--theme-fg-muted)]",children:"Status"}),e.jsx("dd",{className:"mt-1 text-[var(--theme-fg)]",children:rl(i.thread.status)})]}),e.jsxs("div",{children:[e.jsx("dt",{className:"text-[var(--theme-fg-muted)]",children:"Created"}),e.jsx("dd",{className:"mt-1 text-[var(--theme-fg)]",children:Ar(i.thread.createdAt)})]}),e.jsxs("div",{children:[e.jsx("dt",{className:"text-[var(--theme-fg-muted)]",children:"Workspace"}),e.jsx("dd",{className:"mt-1 break-words text-[var(--theme-fg)]",children:i.workspace.absPath})]}),e.jsxs("div",{children:[e.jsx("dt",{className:"text-[var(--theme-fg-muted)]",children:"Workspace path"}),e.jsx("dd",{className:"mt-1 text-[var(--theme-fg)]",children:i.workspacePathStatus==="present"?"Present":"Missing on this machine"})]}),e.jsxs("div",{children:[e.jsx("dt",{className:"text-[var(--theme-fg-muted)]",children:"Active turn"}),e.jsx("dd",{className:"mt-1 text-[var(--theme-fg)]",children:i.thread.activeTurnId??"None"})]})]}):null,qo=null,pr=Ee&&i?Mc(i.turns,Ee):null,xr=n.useMemo(()=>Ee&&!pr?{id:Ee.id,startedAt:Ee.startedAt,status:Ee.status,error:Ee.error,model:Ee.model,reasoningEffort:Ee.reasoningEffort,reasoningEffortAvailable:Ee.reasoningEffortAvailable,tokenUsage:Ee.tokenUsage,priceEstimate:Ee.priceEstimate,items:[{id:`${Ee.id}-user-message`,kind:"userMessage",text:Ee.prompt,attachmentPreviewUrls:Object.fromEntries(Ee.attachmentPreviews.map(m=>[m.path,m.url]))}]}:null,[pr,Ee]),Lt=(i==null?void 0:i.thread.isLoaded)??!1,as=Lt?ct.status==="connected"?"ui-action-success shadow-[var(--theme-shadow)]":ct.status==="reconnecting"?"thread-live-connection-reconnecting ui-status-success shadow-[var(--theme-shadow)]":ct.status==="offline"?"ui-status-danger shadow-[var(--theme-shadow)]":"ui-status-warning shadow-[var(--theme-shadow)]":"host-icon-button border shadow-[var(--theme-shadow)]",gr=nu(Lt,ct),rs=[gr,Lt?null:"Tap to connect this thread",ct.lastHealthyAt?`Last healthy ${Ar(ct.lastHealthyAt)}`:null].filter(Boolean).join(" · "),vr=Lt?e.jsx("div",{role:"status","aria-live":"polite","aria-label":gr,title:rs,className:`inline-flex h-8 w-8 shrink-0 items-center justify-center rounded-full transition ${as}`,children:e.jsx(cs,{status:ct.status})}):e.jsx("button",{type:"button",onClick:()=>void Us(),disabled:ft||!i,"aria-label":ft?"Connecting thread":"Connect thread",title:ft?"Connecting thread":rs,className:`inline-flex h-8 w-8 shrink-0 items-center justify-center rounded-full transition ${as}`,children:e.jsx(cs,{status:"detached"})}),br=Lt?e.jsx("div",{title:rs,className:`hidden lg:inline-flex h-9 w-9 items-center justify-center rounded-full transition ${as}`,children:e.jsx(cs,{status:ct.status})}):e.jsx("button",{type:"button",onClick:()=>void Us(),disabled:ft||!i,title:ft?"Connecting thread":rs,className:`hidden lg:inline-flex h-9 w-9 items-center justify-center rounded-full transition ${as}`,children:e.jsx(cs,{status:"detached"})}),yr=Fa.data??(i==null?void 0:i.goal)??null,wr=(i==null?void 0:i.goalHistory)??[],Vo=yr?ws(wr,yr):so(wr),ns=n.useMemo(()=>(ue==null?void 0:ue.kind)==="shared"?e.jsxs("div",{className:"host-secondary-button inline-flex max-w-[10rem] items-center gap-1.5 rounded-full border px-2.5 py-1 text-[11px] font-medium sm:max-w-[16rem]",title:`${on(ue.threadAccess)} / ${ln(ue.workspaceAccess)}`,children:[e.jsx("span",{children:on(ue.threadAccess)}),e.jsx("span",{className:"host-muted",children:"/"}),e.jsx("span",{className:"truncate",children:ln(ue.workspaceAccess)})]}):null,[ue]),Go=n.useMemo(()=>e.jsx("button",{type:"button","aria-label":"Thread actions",title:"Thread actions",onClick:()=>Ps(!0),disabled:!i,className:"host-icon-button inline-flex h-8 w-8 shrink-0 items-center justify-center rounded-full border shadow-[var(--theme-shadow)] transition disabled:cursor-not-allowed disabled:opacity-50 lg:h-9 lg:w-9",children:e.jsx(z.Share2,{className:"h-4 w-4","aria-hidden":"true"})}),[i]),zo=n.useMemo(()=>e.jsxs("div",{className:"relative flex items-center justify-end gap-1.5",children:[ns,vr]}),[vr,ns]),Jo=n.useMemo(()=>e.jsxs("div",{className:"flex items-center justify-end gap-2",children:[ns,br]}),[br,ns]),Ko=n.useMemo(()=>({livePlan:T,liveItems:j,respondingRequestId:Ma,onRespondToRequest:nr,scrollRequestKey:ze,previousTurnScrollRequestKey:R,nextTurnScrollRequestKey:ye,bottomSpacer:fr,className:"thread-timeline-surface min-h-0 flex-1",onTailVisibilityChange:Ue,onPreviousTurnAvailabilityChange:Te,onNextTurnAvailabilityChange:ot,loadingEarlier:zt,onLoadEarlier:ar,onOpenThread:Jt,answeredRequestNotes:(i==null?void 0:i.answeredRequestNotes)??Yc,activityNotes:(i==null?void 0:i.activityNotes)??Xc,pendingSteers:(i==null?void 0:i.pendingSteers)??Zc,optimisticSteers:Yt,optimisticTurn:xr}),[i==null?void 0:i.answeredRequestNotes,i==null?void 0:i.activityNotes,i==null?void 0:i.pendingSteers,ar,nr,j,T,zt,Jt,Yt,Ma,ze,R,ye,fr,xr]),jr=i?{busy:Je==="chat"?ft:!1,settingsBusy:xo,error:null,model:i.thread.model,agentLabel:((Er=Ne.find(m=>m.model===i.thread.agentId))==null?void 0:Er.displayName)??i.thread.agentId??null,reasoningEffort:i.thread.reasoningEffort,fastMode:i.thread.fastMode??!1,collaborationMode:i.thread.collaborationMode,sandboxMode:i.thread.sandboxMode??null,modelOptions:we,contextUsage:i.thread.contextUsage,subscriptionUsage:Y,capabilities:P,toolboxItems:(be==null?void 0:be.toolboxItems)??[],hookCommandTemplates:(be==null?void 0:be.hookCommandTemplates)??[],mcpConfigFormat:(be==null?void 0:be.mcpConfigFormat)??"none",followTail:je,threadConnected:i.thread.isLoaded,shellAvailable:Ta,disabled:!!Pt,...Pt?{disabledPlaceholder:Pt}:{},shellControlState:he,draftPrompt:La.prompt,draftAttachments:La.attachments,onDraftChange:Ts,canInterrupt:!!(i.thread.activeTurnId&&He),...He?{onInterrupt:ss}:{},...He?{onCompact:Ds,onOpenForkTurns:No,onForkLatest:wo,onForkTurn:jo,onOpenSkills:To,onOpenMcp:Co,onOpenHooks:So,onCreateHook:yo,onUpdateHook:Io,onTrustHook:Eo,onUntrustHook:Ro}:{},goalState:Fa,goalHistory:Vo,...He?{onOpenGoal:ko,onPrepareGoalSubmit:Mo,onUpdateGoal:_o}:{},...As?{...It?{onReadProviderConfig:()=>_n(i.thread.provider,As),onWriteProviderConfig:m=>Hn(i.thread.provider,As,{content:m})}:{}}:{},onToggleFollow:()=>S(m=>m+1),canJumpToPreviousTurn:Se,onJumpToPreviousTurn:()=>oe(m=>m+1),canJumpToNextTurn:nt,onJumpToNextTurn:()=>ke(m=>m+1),...He?{onUpdateSettings:$s}:{},onToggleView:ur,onShellCopy:mr,...He?{onShellControl:hr}:{},compactBusy:go,skillsState:Oo,mcpState:Lo,hooksState:Po,forkTurnOptionsState:bo}:null,Nr=i?{busy:ft,settingsBusy:!1,error:i.thread.isLoaded?(he==null?void 0:he.error)??null:null,followTail:!1,capabilities:P,toolboxItems:(be==null?void 0:be.toolboxItems)??[],hookCommandTemplates:(be==null?void 0:be.hookCommandTemplates)??[],mcpConfigFormat:(be==null?void 0:be.mcpConfigFormat)??"none",threadConnected:i.thread.isLoaded,shellAvailable:Ta,shellControlState:he,canInterrupt:!!(i.thread.isLoaded&&(he!=null&&he.isCommandRunning)&&He),...He?{onInterrupt:ss}:{},onToggleView:ur,onShellCopy:mr,...He?{onShellControl:hr}:{}}:null,kr=n.useCallback(m=>i?Pa({threadId:i.thread.id,path:m}):"",[i==null?void 0:i.thread.id,Pa]),Sr=Vc({setError:ie,workspaceId:(i==null?void 0:i.workspace.id)??null,access:$o}),Cr=n.useCallback(m=>{const w=I.current;if(!w)return;const y=au(m.path,w.workspace.absPath);if(y===null){ie(`Cannot open ${m.path}; it is outside this workspace.`);return}Ca("chat"),po(C=>({path:y,...m.line!==void 0?{line:m.line}:{},requestId:((C==null?void 0:C.requestId)??0)+1}))},[]),Yo=n.useMemo(()=>({openThread:Jt,getThreadHref:Ra,getNewThreadHref:Aa,renderNewThreadDialogContent:Ia,...It?{renameThread:dr}:{},...It?{deleteThread:Es}:{},cancelPendingSteer:lr,...He?{steerPendingPrompt:ir}:{},sendPrompt:rr,...He?{interrupt:ss}:{},...He?{compact:Ds}:{},...He?{updateSettings:$s}:{},loadHistoryItemDetail:or,getImageAssetUrl:kr,openWorkspaceFile:Cr,workspace:Sr,shell:Ea}),[kr,Aa,Ra,Ia,Ds,lr,ir,ss,or,Cr,rr,dr,$s,Ea,Jt,He,It,Sr]),Xo=i!=null&&i.thread.workspaceId?Wt(i.thread.workspaceId):Ns(),Zo=n.useMemo(()=>e.jsxs(e.Fragment,{children:[e.jsx(nl,{open:Xt,busy:Is||Os,turnsState:Wa,shareAvailable:Ja,...xt&&(ue==null?void 0:ue.kind)==="shared"?{shareUnavailableMessage:"Only the owner can share this session."}:{},shareState:Ga,onCancel:()=>{!Is&&!Os&&Ps(!1)},onLoadTurns:Va,onExport:qa,...Ja?{onCreateShare:Ka,onOpenDeviceSharing:Xa,onRevokeShare:Ya}:{}}),e.jsx(js,{open:Qe!==null,title:"Delete Thread",description:Qe?`Delete ${kl(Qe.title)} from supervisor. The backend session id will no longer appear in this workspace list.`:"",confirmLabel:"Delete Thread",busy:Rs,onCancel:()=>{Rs||Es(null)},onConfirm:()=>void cr()})]}),[Qe,Rs,Is,Xt,Wa,Ka,cr,qa,Xa,Ya,Va,xt,Os,Ga]);return e.jsx(ol,{threads:fe,detail:i,status:M,loading:it,error:it?null:vo,plugins:l,adapter:Yo,metaContent:Fo,settingsContent:qo,globalSettingsContent:e.jsx(va,{embedded:!0}),mobileHeaderAction:zo,workspaceReturnHref:Xo,onCloseAppNavigation:(o==null?void 0:o.closeNav)??(()=>{}),threadActionsButton:Go,surfaceActions:Jo,workspaceFeatures:eu,workspaceFocusPathRequest:fo,activeView:Je,liveOutput:L,timelineProps:Ko,timelineComponent:il,useFloatingMobileComposer:Wo,floatingMobileComposerBottomOffset:Bo,composerHostRef:D,shellPanelRef:h,shellPanelComponent:ll,shellEffectiveTheme:(o==null?void 0:o.effectiveTheme)??"dark",shellThemeMode:(o==null?void 0:o.themeMode)??"system",...o!=null&&o.setThemeMode?{onShellThemeModeChange:o.setThemeMode}:{},onShellStateChange:Oa,loadingContent:e.jsx("div",{className:"host-muted flex flex-1 items-center justify-center px-6 py-12 text-center",children:"Loading thread detail..."}),emptyContent:e.jsx("div",{className:"host-muted flex flex-1 items-center justify-center px-6 py-12 text-center",children:"Unable to resolve this thread."}),dialogs:Zo,...jr?{composerProps:jr}:{},...Nr?{shellComposerProps:Nr}:{}})}function un(){const t=rt(),[s,a]=n.useState(""),[r,o]=n.useState(st),[l,d]=n.useState([]),[u,p]=n.useState(!0),[g,b]=n.useState([]),[x,N]=n.useState(null),[v,c]=n.useState(!1),[h,D]=n.useState([]),[H,O]=n.useState(!0),[E,U]=n.useState(null),[G,te]=n.useState(!1),[Q,I]=n.useState(null);n.useEffect(()=>{let i=!1;return p(!0),Tt().then(W=>{var ae,we;if(i)return;d(W);const fe=((ae=W.find(ge=>ge.isDefault&&ge.enabled))==null?void 0:ae.provider)??((we=W.find(ge=>ge.enabled))==null?void 0:we.provider)??st;o(fe)}).catch(()=>{i||d([])}).finally(()=>{i||p(!1)}),()=>{i=!0}},[]),n.useEffect(()=>{let i=!1;return r!=="acp"?(b([]),N(null),c(!1),()=>{i=!0}):(c(!0),_t("acp").then(W=>{i||(b(W),N(fe=>{var ae;return fe&&W.some(we=>we.id===fe)?fe:((ae=W.find(we=>{var ge;return((ge=we.acpAgent)==null?void 0:ge.availability)==="ready"}))==null?void 0:ae.id)??null}))}).catch(()=>{i||(b([]),N(null))}).finally(()=>{i||c(!1)}),()=>{i=!0})},[r]),n.useEffect(()=>{let i=!1;return r==="acp"&&!x?(D([]),O(v),()=>{i=!0}):(O(!0),U(null),sd(r,x).then(W=>{i||D(W)}).catch(W=>{i||(D([]),U(W instanceof Error?W.message:"Unable to list local sessions."))}).finally(()=>{i||O(!1)}),()=>{i=!0})},[x,v,r]);const se=n.useMemo(()=>l.length>0?l:[{provider:st,displayName:Ir[st].displayName,enabled:!0}],[l]),J=h.find(i=>i.sessionId===s.trim())??null;async function ee(i){i.preventDefault();const W=s.trim();if(!W){I("Session ID is required.");return}te(!0),I(null);try{const fe=await td({sessionId:W,provider:r});t(Fe(fe.thread.id))}catch(fe){fe instanceof ce?I(fe.payload.message):I(fe instanceof Error?fe.message:"Unable to import session.")}finally{te(!1)}}return e.jsxs("div",{className:"space-y-6",children:[e.jsxs("div",{children:[e.jsx("p",{className:"host-page-eyebrow text-xs uppercase tracking-[0.3em]",children:"Import Session"}),e.jsx("h2",{className:"host-page-title mt-2 text-3xl font-semibold",children:"Bring in a local backend session"}),e.jsx("p",{className:"host-page-description mt-3 max-w-3xl text-sm leading-6",children:"Select the backend and paste a session ID from this machine. Supervisor will recover the workspace path, reuse an existing workspace when possible, or create one with the last folder name as the default label."}),e.jsx("p",{className:"host-muted mt-2 max-w-3xl text-sm leading-6",children:"Imported history appears immediately, but sending a new prompt still requires a manual Resume / Connect."})]}),e.jsxs("form",{onSubmit:ee,className:"host-panel space-y-5 rounded-lg border p-5 sm:p-6",children:[e.jsxs("div",{children:[e.jsx("label",{htmlFor:"backend-provider",className:"host-form-label text-sm font-medium",children:"Backend"}),e.jsx("select",{id:"backend-provider",value:r,onChange:i=>{o(i.target.value),a("")},disabled:G||u,className:"host-form-control mt-2 w-full rounded-lg border px-4 py-3 outline-none transition",children:se.map(i=>e.jsxs("option",{value:i.provider,children:[i.displayName||Ir[i.provider].displayName,i.enabled?"":" (not ready)"]},i.provider))})]}),r==="acp"&&e.jsxs("div",{children:[e.jsx("label",{htmlFor:"acp-agent",className:"host-form-label text-sm font-medium",children:"ACP agent"}),e.jsxs("select",{id:"acp-agent",value:x??"",onChange:i=>{N(i.target.value||null),a("")},disabled:G||v||g.length===0,className:"host-form-control mt-2 w-full rounded-lg border px-4 py-3 outline-none transition",children:[e.jsx("option",{value:"",children:v?"Loading agents...":"No ready ACP agent"}),g.map(i=>{var W,fe,ae;return e.jsxs("option",{value:i.id,disabled:((W=i.acpAgent)==null?void 0:W.availability)!=="ready",children:[i.displayName,((fe=i.acpAgent)==null?void 0:fe.availability)==="ready"?"":` (${((ae=i.acpAgent)==null?void 0:ae.availability)??"unavailable"})`]},i.id)})]})]}),e.jsxs("div",{children:[e.jsx("label",{htmlFor:"available-session",className:"host-form-label text-sm font-medium",children:"Available sessions"}),e.jsxs("select",{id:"available-session",value:(J==null?void 0:J.sessionId)??"",onChange:i=>a(i.target.value),disabled:G||H||h.length===0,className:"host-form-control mt-2 w-full rounded-lg border px-4 py-3 outline-none transition",children:[e.jsx("option",{value:"",children:H?"Loading sessions...":h.length===0?"No unmanaged sessions found":"Select a session"}),h.map(i=>e.jsxs("option",{value:i.sessionId,children:[i.title," · ",i.sessionId]},i.sessionId))]}),J&&e.jsxs("div",{className:"host-muted mt-2 space-y-1 text-xs",children:[e.jsx("p",{className:"break-all",children:J.cwd}),J.preview&&e.jsx("p",{className:"line-clamp-2",children:J.preview})]}),E&&e.jsx("p",{className:"host-muted mt-2 text-xs",children:"Session discovery unavailable. Manual import is still available."})]}),e.jsxs("div",{children:[e.jsx("label",{htmlFor:"session-id",className:"host-form-label text-sm font-medium",children:"Session ID"}),e.jsx("input",{id:"session-id",value:s,onChange:i=>a(i.target.value),placeholder:"019d6fb7-7033-7a30-a2c7-74d0919e87d4",className:"host-form-control mt-2 w-full rounded-lg border px-4 py-3 outline-none transition"})]}),Q&&e.jsx("div",{className:"host-error rounded-lg border px-4 py-3 text-sm",children:Q}),e.jsx("div",{className:"flex flex-wrap items-center gap-3",children:e.jsx("button",{type:"submit",disabled:G,className:"ui-action-primary rounded-lg px-5 py-3 font-medium transition disabled:cursor-not-allowed",children:G?"Importing...":"Import Session"})})]})]})}function oo({eyebrow:t,title:s,description:a,children:r,maxWidthClassName:o="max-w-2xl"}){return e.jsx("div",{className:"flex min-h-[calc(100vh-2rem)] items-start justify-center py-[calc(env(safe-area-inset-top)+3.75rem)] sm:items-center sm:py-[calc(env(safe-area-inset-top)+2rem)]",children:e.jsxs("section",{className:`host-panel w-full ${o} overflow-hidden rounded-lg border shadow-[var(--theme-shadow)]`,children:[e.jsxs("header",{className:"border-b border-[var(--theme-border)] px-5 py-4 sm:px-6",children:[e.jsx("p",{className:"host-page-eyebrow text-xs uppercase tracking-[0.22em]",children:t}),e.jsx("h1",{className:"host-page-title mt-2 text-xl font-semibold tracking-normal sm:text-2xl",children:s}),a?e.jsx("p",{className:"host-page-description mt-2 max-w-2xl text-sm leading-6",children:a}):null]}),e.jsx("div",{className:"px-5 py-5 sm:px-6",children:r})]})})}function mn(){const t=rt(),[s]=ma(),a=s.get("workspaceId"),r=s.get("title");function o(){if(window.history.length>1){t(-1);return}if(a){t(Wt(a));return}t(Ns())}return e.jsx(oo,{eyebrow:"New Thread",title:"Start a backend session",description:"Choose the workspace, agent or model, and approval mode for the new thread.",maxWidthClassName:"max-w-3xl",children:e.jsx(Sa,{initialWorkspaceId:a,initialTitle:r,onCancel:o,onCreated:l=>t(Fe(l.id))})})}function ou(t){return xs(t)}function lu({getThreadHref:t,onOpenThread:s,getNewThreadHref:a,renderThreadLink:r,onCloseAppNavigation:o,...l}){const d=rt(),u=Vt(),p=o??(u==null?void 0:u.closeNav),g=l.effectiveTheme??(u==null?void 0:u.effectiveTheme),b=l.themeMode??(u==null?void 0:u.themeMode),x=l.onThemeModeChange??(u==null?void 0:u.setThemeMode);return e.jsx(dl,{...l,workspaceReturnHref:l.workspaceReturnHref??Ns(),globalSettingsContent:l.globalSettingsContent??e.jsx(va,{embedded:!0}),...g?{effectiveTheme:g}:{},...b?{themeMode:b}:{},...x?{onThemeModeChange:x}:{},getThreadHref:t??(N=>Fe(N)),onOpenThread:s??(N=>d(Fe(N))),getNewThreadHref:a??ou,renderNewThreadDialogContent:l.renderNewThreadDialogContent??(({close:N,closeNavigation:v,currentWorkspaceId:c})=>e.jsx(Sa,{variant:"dialog",initialWorkspaceId:c,onCancel:N,onCreated:h=>{N(),v(),d(Fe(h.id))}})),renderThreadLink:r??(({thread:N,children:v,className:c,onClick:h})=>e.jsx(Be,{to:Fe(N.id),className:c,onClick:h,children:v})),...p?{onCloseAppNavigation:p}:{}})}function lo({open:t,title:s,label:a,value:r,busy:o=!1,onChange:l,onCancel:d,onSubmit:u}){if(n.useEffect(()=>{if(!t)return;function g(b){b.key==="Escape"&&!o&&d()}return window.addEventListener("keydown",g),()=>{window.removeEventListener("keydown",g)}},[o,d,t]),!t)return null;function p(g){g.preventDefault(),u()}return vn.createPortal(e.jsxs("div",{className:"fixed inset-0 z-[95] flex items-center justify-center p-4 sm:p-6",children:[e.jsx("button",{type:"button","aria-label":"Close rename dialog",onClick:d,disabled:o,className:"ui-overlay-scrim absolute inset-0 backdrop-blur-sm disabled:cursor-not-allowed"}),e.jsxs("form",{role:"dialog","aria-modal":"true","aria-label":s,onSubmit:p,className:"host-dialog relative z-[1] w-full max-w-md rounded-lg border p-5 shadow-[var(--theme-shadow)] sm:p-6",children:[e.jsxs("div",{className:"flex items-start justify-between gap-3",children:[e.jsxs("div",{className:"min-w-0 flex-1",children:[e.jsx("p",{className:"host-page-title text-sm font-medium",children:s}),e.jsx("p",{className:"host-muted mt-1 text-sm",children:"Changes are saved only after confirmation."})]}),e.jsx("button",{type:"button","aria-label":"Close dialog",onClick:d,disabled:o,className:"host-icon-button inline-flex h-9 w-9 shrink-0 items-center justify-center rounded-full border transition disabled:cursor-not-allowed disabled:opacity-60",children:e.jsx("svg",{"aria-hidden":"true",viewBox:"0 0 16 16",className:"h-4 w-4 fill-current",children:e.jsx("path",{d:"M3.22 2.47 8 7.25l4.78-4.78 1.06 1.06L9.06 8.31l4.78 4.78-1.06 1.06L8 9.37l-4.78 4.78-1.06-1.06 4.78-4.78-4.78-4.78 1.06-1.06Z"})})})]}),e.jsxs("div",{className:"mt-5",children:[e.jsx("label",{htmlFor:"rename-dialog-input",className:"host-form-label text-sm font-medium",children:a}),e.jsx("input",{id:"rename-dialog-input","aria-label":a,autoFocus:!0,value:r,onChange:g=>l(g.target.value),className:"host-form-control mt-2 w-full rounded-lg border px-4 py-3 outline-none transition"})]}),e.jsxs("div",{className:"mt-5 flex items-center justify-end gap-2",children:[e.jsx("button",{type:"button",onClick:d,disabled:o,className:"host-secondary-button rounded-lg border px-4 py-2 text-sm font-medium transition disabled:cursor-not-allowed disabled:opacity-60",children:"Cancel"}),e.jsx("button",{type:"submit",disabled:o||!r.trim(),className:"ui-action-success rounded-lg px-4 py-2 text-sm font-medium transition disabled:cursor-not-allowed",children:"Save"})]})]})]}),document.body)}function hn(){const[t]=ma(),s=rt(),a=Vt(),r=t.get("workspaceId"),[o,l]=n.useState([]),[d,u]=n.useState([]),[p,g]=n.useState(null),[b,x]=n.useState(!0),[N,v]=n.useState(null),[c,h]=n.useState(null),[D,H]=n.useState(""),[O,E]=n.useState(null),[U,G]=n.useState(null),[te,Q]=n.useState(!1),I=(a==null?void 0:a.defaultBackend)??st,se=n.useCallback(async()=>{try{return(await Mn(I)).status}catch(M){const P=(await Tt()).find(V=>V.enabled&&V.capabilities.sessions.resume&&V.capabilities.turns.start);if(P)return P.status;throw M}},[I]),J=n.useCallback(async()=>{x(!0),v(null);try{const[M,ne,P]=await Promise.all([se(),ga(),xa()]);g(M),l(ne),u(P)}catch(M){v(M instanceof Error?M.message:"Unable to load threads.")}finally{x(!1)}},[se]);n.useEffect(()=>{if(r===null)return;J();const M=Fn(ne=>{l(P=>P.map(V=>V.id===ne.threadId?{...V,status:ne.type==="thread.updated"&&typeof ne.payload.status=="string"?ne.payload.status:V.status,lastError:(ne.type==="thread.turn.failed"||ne.type==="thread.turn.completed")&&typeof ne.payload.error=="string"?ne.payload.error:V.lastError,title:ne.type==="thread.updated"&&typeof ne.payload.title=="string"?ne.payload.title:V.title}:V))});return()=>{M.close()}},[J,r]);const ee=Object.fromEntries(d.map(M=>[M.id,M.label])),i=d.find(M=>M.id===r)??null,W=n.useMemo(()=>r?o.filter(M=>M.workspaceId===r):[],[r,o]),fe=W.filter(M=>M.status==="running").length,ae=r?xs(r):xs();if(no({enabled:r!==null,setThreads:l}),r===null)return e.jsx(ps,{to:Ns(),replace:!0});function we(){switch(p==null?void 0:p.state){case"ready":return"bg-teal-300 shadow-[0_0_0_3px_rgba(94,234,212,0.14)]";case"starting":return"bg-[var(--status-warning-fg)] shadow-[0_0_0_3px_var(--status-warning-bg)]";case"degraded":case"failed":return"bg-rose-400 shadow-[0_0_0_3px_rgba(251,113,133,0.14)]";default:return"bg-slate-500 shadow-[0_0_0_3px_rgba(100,116,139,0.14)]"}}async function ge(M,ne){try{const P=await Bn(M,{title:ne});l(V=>V.map(Y=>Y.id===P.id?{...Y,title:P.title,updatedAt:P.updatedAt}:Y))}catch(P){throw v(P instanceof Error?P.message:"Unable to rename thread."),P}}async function Ne(){if(!c)return;const M=D.trim();if(M){E(c);try{await ge(c,M),h(null),H("")}finally{E(null)}}}async function K(){if(U){Q(!0);try{await Wn(U.id),l(M=>M.filter(ne=>ne.id!==U.id)),G(null)}catch(M){v(M instanceof Error?M.message:"Unable to delete thread.")}finally{Q(!1)}}}return e.jsx(lu,{threads:o,workspaceLabels:ee,status:p,loading:b,error:N,viewportConstrained:r!==null,showMobileAppMenu:!0,showMobileThreadNavToggle:!1,showMobileNewThreadShortcut:!1,currentWorkspaceId:r,currentWorkspaceLabel:(i==null?void 0:i.label)??null,onRenameThread:ge,onDeleteThread:G,children:e.jsxs(e.Fragment,{children:[e.jsxs("div",{className:"host-panel flex min-h-0 flex-1 flex-col overflow-hidden rounded-lg border shadow-[var(--theme-shadow)]",children:[e.jsx("div",{className:"border-b border-[var(--theme-border)] px-4 py-3 sm:px-6 sm:py-4",children:e.jsxs("div",{className:"flex items-center justify-between gap-3",children:[e.jsx("h2",{className:"host-page-title min-w-0 truncate text-base font-semibold sm:text-lg",title:i?`${i.label} threads`:"All threads",children:i?i.label:"All Threads"}),e.jsx(Be,{to:ae,className:"ui-action-primary inline-flex h-9 shrink-0 items-center rounded-lg px-3.5 text-xs font-medium uppercase tracking-[0.18em] transition",children:"New Thread"})]})}),e.jsx("div",{className:"px-4 py-3 sm:px-6 sm:py-4",children:e.jsxs("article",{className:"host-surface-strong inline-flex min-w-[12rem] max-w-full items-center gap-3 rounded-lg border px-3.5 py-2.5",children:[e.jsx("span",{"aria-hidden":"true",className:`h-2.5 w-2.5 shrink-0 rounded-full ${we()}`}),e.jsxs("div",{className:"min-w-0",children:[e.jsx("p",{className:"host-muted truncate text-[11px] uppercase tracking-[0.22em]",children:"Supervisor"}),e.jsx("p",{className:"host-soft truncate text-sm",children:(p==null?void 0:p.lastError)??((p==null?void 0:p.state)==="ready"?"Ready":(p==null?void 0:p.state)??"Checking")})]})]})}),!b&&!N&&W.length>0&&e.jsxs("div",{className:"flex min-h-0 flex-1 flex-col border-t border-[var(--theme-border)] px-4 py-4 sm:px-6 sm:py-5",children:[e.jsxs("div",{className:"flex items-center gap-2",children:[e.jsx("p",{className:"host-muted text-xs uppercase tracking-[0.28em]",children:"Recent Threads"}),e.jsxs("span",{className:"host-warning-pill rounded-full border px-2 py-0.5 text-[11px] font-medium uppercase tracking-[0.18em]",children:[W.length," total"]}),fe>0&&e.jsxs("span",{className:"host-muted text-xs",children:["· ",fe," running"]})]}),e.jsx("div",{className:"mt-3 min-h-0 flex-1",children:e.jsx(cl,{threads:W,currentWorkspaceId:r,workspaceLabels:ee,onOpenThread:M=>s(Fe(M)),onBeginRenameThread:M=>{h(M.id),H(M.title)},onDeleteThread:M=>G(M),scrollable:!0,maxHeightClassName:"max-h-full",showDeleteButton:!0,showSessionCopyButton:!0})})]}),!b&&!N&&W.length===0&&e.jsx("div",{className:"host-muted border-t border-[var(--theme-border)] px-4 py-6 text-sm sm:px-6",children:"No threads available in this workspace."})]}),e.jsx(lo,{open:c!==null,title:"Rename Thread",label:"Thread Title",value:D,busy:O!==null,onChange:H,onCancel:()=>{h(null),H("")},onSubmit:()=>void Ne()}),e.jsx(js,{open:U!==null,title:"Delete Thread",description:U?`Delete ${bl(U.title)} from supervisor. The backend session id will no longer appear in this workspace list.`:"",confirmLabel:"Delete Thread",busy:te,onCancel:()=>{te||G(null)},onConfirm:()=>void K()})]})})}function fn(t){const s=t.trim(),a=s.replace(/[\\/]+$/,"");if(!a)return"";if(io(s)){const o=(a.split(/[?#]/)[0]??a).split(/[/:]/).filter(Boolean).at(-1)??"";return o.endsWith(".git")?o.slice(0,-4):o}return a.split(/[\\/]/).filter(Boolean).at(-1)??""}function io(t){const s=t.trim();return/^https?:\/\/.+/i.test(s)||/^ssh:\/\/.+/i.test(s)||/^git@[^:]+:.+/.test(s)}function iu({initialPath:t="",initialLabel:s="",submitLabel:a="Save Workspace",error:r,busy:o=!1,surface:l=!0,onSubmit:d}){const u=fn(t),[p,g]=n.useState(t),[b,x]=n.useState(s||u),[N,v]=n.useState(null),c=n.useRef(u);n.useEffect(()=>{const H=fn(p);x(O=>!O.trim()||O===c.current?H:O),c.current=H},[p]);async function h(H){H.preventDefault();const O=p.trim();if(!O){v("Workspace path or Git URL is required.");return}v(null);const E=b.trim(),U=io(O)?"gitUrl":"absPath";await d(E?{[U]:O,label:E}:{[U]:O})}const D=l?"host-panel space-y-5 rounded-lg border p-5 sm:p-6":"space-y-5";return e.jsxs("form",{onSubmit:h,className:D,children:[e.jsxs("div",{children:[e.jsx("label",{htmlFor:"workspace-path",className:"host-form-label text-sm font-medium",children:"Path or Git URL"}),e.jsx("input",{id:"workspace-path",name:"absPath",value:p,onChange:H=>g(H.target.value),placeholder:"test, /Users/name/project, or https://github.com/owner/repo.git",className:"host-form-control mt-2 w-full rounded-lg border px-4 py-3 outline-none transition"}),e.jsx("p",{className:"host-muted mt-2 text-xs",children:"A name such as “test” creates a folder under the configured workspace directory. Absolute paths register existing directories; Git URLs clone a repository."})]}),e.jsxs("div",{children:[e.jsx("label",{htmlFor:"workspace-label",className:"host-form-label text-sm font-medium",children:"Display label"}),e.jsx("input",{id:"workspace-label",name:"label",value:b,onChange:H=>x(H.target.value),placeholder:"Optional override",className:"host-form-control mt-2 w-full rounded-lg border px-4 py-3 outline-none transition"}),e.jsx("p",{className:"host-muted mt-2 text-xs",children:"Defaults to the last folder name. You can override it."})]}),(N||r)&&e.jsx("div",{className:"host-error rounded-lg border px-4 py-3 text-sm",children:N??r}),e.jsx("button",{type:"submit",disabled:o,className:"ui-action-primary rounded-lg px-5 py-3 font-medium transition disabled:cursor-not-allowed",children:o?"Saving...":a})]})}function pn(){const t=rt(),[s,a]=n.useState(null),[r,o]=n.useState(!1),[l,d]=n.useState(null);n.useEffect(()=>{Dn().then(p=>d(p.devHome)).catch(()=>d(null))},[]);async function u(p){o(!0),a(null);try{const g="absPath"in p&&l&&/^[A-Za-z0-9][A-Za-z0-9._-]{0,127}$/.test(p.absPath)?{...p,absPath:`${l.replace(/\/$/,"")}/${p.absPath}`}:p,b=await kd(g);t(Wt(b.id))}catch(g){g instanceof ce?a(g.payload.message):a(g instanceof Error?g.message:"Unable to create workspace.")}finally{o(!1)}}return e.jsx(oo,{eyebrow:"Add Workspace",title:"Create a workspace",description:"Enter a folder name to create it under the workspace directory, register an absolute path, or clone a Git repository.",children:e.jsx(iu,{busy:r,error:s,submitLabel:"Create Workspace",surface:!1,onSubmit:u})})}function xn(t){return Date.parse(t.lastOpenedAt??t.createdAt)}function du(t,s){return t.isFavorite!==s.isFavorite?t.isFavorite?-1:1:xn(s)-xn(t)}function cu(t){return t?new Date(t).toLocaleString():"Never opened"}function uu(t,s=28){return t.length<=s?t:`...${t.slice(-(s-3))}`}function mu({active:t}){return e.jsx("svg",{"aria-hidden":"true",viewBox:"0 0 16 16",className:`h-3.5 w-3.5 fill-current ${t?"rotate-[18deg]":"rotate-[8deg]"}`,children:e.jsx("path",{d:"M10.7 1.75c.34 0 .62.28.62.63v1.24l1.43 1.42c.24.24.24.62 0 .86l-1.1 1.1v2.02c0 .17-.07.33-.19.45l-1.5 1.5v2.28c0 .28-.18.53-.44.6a.62.62 0 0 1-.69-.24L7.2 12.4l-2.83 2.83a.625.625 0 1 1-.88-.88l2.83-2.83-2.2-1.62a.62.62 0 0 1-.24-.69c.08-.26.32-.44.6-.44h2.28l1.5-1.5a.64.64 0 0 1 .45-.18h2.02l1.1-1.11-1.42-1.42H9.07a.63.63 0 0 1-.62-.63c0-.34.28-.62.62-.62h1.63Z"})})}function hu(){return e.jsx("svg",{"aria-hidden":"true",viewBox:"0 0 16 16",className:"h-3.5 w-3.5 fill-current",children:e.jsx("path",{d:"M6.1 1.75h3.8c.75 0 1.4.52 1.57 1.25h2.03c.35 0 .63.28.63.63 0 .34-.28.62-.63.62h-.66l-.62 8.03c-.08 1.09-.99 1.97-2.08 1.97H5.86c-1.09 0-2-.88-2.08-1.97l-.62-8.03H2.5a.62.62 0 1 1 0-1.25h2.03c.17-.73.82-1.25 1.57-1.25Zm0 1.25c-.07 0-.14.03-.19.08A.26.26 0 0 0 5.84 3h4.32a.26.26 0 0 0-.07-.17.26.26 0 0 0-.19-.08H6.1Zm-1.07 1.25.61 7.93c.03.44.4.79.84.79h3.04c.44 0 .81-.35.84-.79l.61-7.93H5.03Zm1.53 1.32c.35 0 .62.28.62.62v4.19a.62.62 0 1 1-1.24 0V6.19c0-.34.28-.62.62-.62Zm2.82 0c.34 0 .62.28.62.62v4.19a.62.62 0 1 1-1.24 0V6.19c0-.34.28-.62.62-.62Z"})})}function gn(){const t=rt(),[s,a]=n.useState([]),[r,o]=n.useState(!0),[l,d]=n.useState(null),[u,p]=n.useState(null),[g,b]=n.useState(null),[x,N]=n.useState(null),[v,c]=n.useState(""),[h,D]=n.useState(null),[H,O]=n.useState(null),[E,U]=n.useState(null),[G,te]=n.useState(!1),[Q,I]=n.useState(!1),[se,J]=n.useState(0);n.useEffect(()=>{let K=!1,M=null;const ne=V=>{var Y;return V.reason instanceof ce&&((Y=V.reason.payload.details)==null?void 0:Y.reason)==="hosted_sandbox_starting"},P=async()=>{const[V,Y]=await Promise.allSettled([xa(),Vl()]);if(!K){if(V.status==="rejected"&&ne(V)||Y.status==="rejected"&&ne(Y)){I(!0),o(!0),b(null),p(null),J(Ce=>Ce+1),M=setTimeout(()=>void P(),1500);return}I(!1),o(!1),V.status==="fulfilled"?(a(V.value),b(null)):b(V.reason instanceof Error?V.reason.message:"Unable to load workspaces."),Y.status==="fulfilled"?(d(Y.value),p(null)):p(Y.reason instanceof Error?Y.reason.message:"Unable to load supervisor config.")}};return P(),()=>{K=!0,M&&clearTimeout(M)}},[]);async function ee(K){const M={...K,isFavorite:!K.isFavorite};a(ne=>ne.map(P=>P.id===K.id?M:P));try{const ne=await Td(K.id,{isFavorite:!K.isFavorite});a(P=>P.map(V=>V.id===ne.id?ne:V))}catch(ne){a(P=>P.map(V=>V.id===K.id?K:V)),b(ne instanceof Error?ne.message:"Unable to update workspace.")}}async function i(K){const M=v.trim();if(M){D(K);try{const ne=await Sd(K,{label:M});a(P=>P.map(V=>V.id===ne.id?ne:V)),N(null),c("")}catch(ne){b(ne instanceof Error?ne.message:"Unable to rename workspace.")}finally{D(null)}}}function W(K){N(K.id),c(K.label)}function fe(){N(null),c("")}function ae(K){t(Wt(K))}async function we(){if(E){te(!0);try{await Cd(E.id,{confirmWorkspaceId:E.id,confirmLabel:E.label}),a(K=>K.filter(M=>M.id!==E.id)),U(null)}catch(K){b(K instanceof Error?K.message:"Unable to delete workspace.")}finally{te(!1)}}}function ge(K,M){(K.key==="Enter"||K.key===" ")&&(K.preventDefault(),ae(M))}const Ne=n.useMemo(()=>[...s].sort(du),[s]);return e.jsxs("div",{className:"space-y-4",children:[e.jsx("div",{className:"host-topbar sticky top-[env(safe-area-inset-top)] z-20 -mx-4 border-b px-2.5 py-2 backdrop-blur sm:mx-0 sm:rounded-lg sm:border sm:px-4",children:e.jsxs("div",{className:"flex min-w-0 items-center gap-1.5 sm:gap-2",children:[e.jsx(ya,{}),e.jsx(Be,{to:Or("/threads/import"),className:"host-info-pill inline-flex h-8 shrink-0 items-center rounded-md border px-2.5 text-[11px] font-medium uppercase tracking-[0.14em] transition sm:px-3 sm:text-xs sm:tracking-[0.18em]",children:"Import"}),e.jsx(Be,{to:Or("/workspaces/new"),className:"ui-action-primary inline-flex h-8 shrink-0 items-center rounded-md px-2.5 text-[11px] font-medium uppercase tracking-[0.14em] transition sm:px-3 sm:text-xs sm:tracking-[0.18em]",children:"Create"}),e.jsx("div",{className:"min-w-0 flex-1 text-right",children:e.jsx("p",{className:"host-page-eyebrow truncate text-[11px] uppercase tracking-[0.24em]",children:"Workspaces"})})]})}),e.jsxs("div",{className:"grid gap-4 xl:grid-cols-[minmax(0,1fr)_20rem]",children:[e.jsxs("section",{className:"min-w-0 space-y-4",children:[Q?e.jsxs("div",{"aria-live":"polite",className:"overflow-hidden rounded-lg border border-[var(--status-warning-border)] bg-[var(--theme-panel)]",role:"status",children:[e.jsxs("div",{className:"px-5 py-5",children:[e.jsx("p",{className:"text-sm font-semibold text-[var(--theme-fg)]",children:"Starting hosted VM"}),e.jsx("p",{className:"mt-1 text-sm text-[var(--theme-fg-muted)]",children:"Waiting for the supervisor to connect. This page will resume automatically."})]}),e.jsx("div",{className:"h-1 overflow-hidden bg-[var(--theme-muted)]",children:e.jsx("div",{className:"h-full w-1/3 animate-pulse bg-[var(--theme-accent-solid)]"})}),e.jsxs("p",{className:"px-5 py-3 text-xs text-[var(--theme-fg-muted)]",children:["Connection check ",se]})]}):r?e.jsx("div",{className:"host-empty-state rounded-lg border px-6 py-12 text-center",children:"Loading workspace registry..."}):null,g&&e.jsx("div",{className:"host-error rounded-lg border px-4 py-4",children:g}),!r&&!g&&s.length===0&&e.jsxs("div",{className:"host-empty-state rounded-lg border border-dashed px-6 py-12 text-center",children:[e.jsx("p",{className:"host-page-title text-lg font-medium",children:"No workspaces yet"}),e.jsx("p",{className:"host-muted mt-2 text-sm",children:"Add a local directory inside the configured workspace root to start building the registry."})]}),!r&&Ne.length>0&&e.jsx("div",{className:"space-y-2 overflow-x-hidden",children:Ne.map(K=>e.jsxs("article",{role:"link",tabIndex:0,onClick:()=>ae(K.id),onKeyDown:M=>ge(M,K.id),className:"host-card relative overflow-hidden rounded-lg border px-4 py-3 transition",children:[e.jsxs("div",{className:"absolute right-2.5 top-2.5 flex items-center gap-1.5",children:[e.jsx("button",{type:"button","aria-label":`Delete workspace ${K.label}`,title:"Delete workspace",onClick:M=>{M.stopPropagation(),U(K)},className:"inline-flex h-7 w-7 items-center justify-center rounded-full border border-[var(--status-danger-border)] bg-[var(--status-danger-bg)] text-[var(--status-danger-fg)] transition hover:bg-[var(--status-danger-border)]",children:e.jsx(hu,{})}),e.jsx("button",{type:"button","aria-label":K.isFavorite?`Unpin workspace ${K.label}`:`Pin workspace ${K.label}`,title:K.isFavorite?"Unpin workspace":"Pin workspace",onClick:M=>{M.stopPropagation(),ee(K)},className:`inline-flex h-7 w-7 items-center justify-center rounded-full border transition ${K.isFavorite?"host-warning-pill":"host-icon-button"}`,children:e.jsx(mu,{active:K.isFavorite})})]}),e.jsx("div",{className:"flex min-w-0 items-start gap-3 pr-[4.6rem]",children:e.jsxs("div",{className:"min-w-0 flex-1",children:[e.jsxs("div",{className:"flex min-w-0 items-center gap-1",children:[e.jsx("p",{className:"host-page-title min-w-0 max-w-full truncate text-base font-semibold sm:text-lg",title:K.label,children:K.label}),e.jsx("button",{type:"button",onClick:M=>{M.stopPropagation(),W(K)},"aria-label":`Rename workspace ${K.label}`,className:"host-muted inline-flex h-4 w-4 shrink-0 items-center justify-center transition hover:text-[var(--theme-fg)]",children:e.jsx("svg",{"aria-hidden":"true",viewBox:"0 0 16 16",className:"h-3 w-3 fill-current",children:e.jsx("path",{d:"m11.9 1.6 2.5 2.5-8.2 8.2-3.3.7.7-3.3 8.3-8.1Zm-7.3 8.7-.3 1.3 1.3-.3 6.9-6.9-1-1-6.9 6.9Zm8.8-7.8-1-1-1 1 1 1 1-1Z"})})})]}),e.jsx("button",{type:"button","aria-label":K.absPath,title:K.absPath,onClick:M=>{M.stopPropagation(),O(K.absPath)},className:"host-muted mt-1 inline-block max-w-full overflow-hidden whitespace-nowrap text-left text-[9px] leading-4 transition hover:text-[var(--theme-fg-soft)]",children:uu(K.absPath)}),e.jsx("div",{className:"host-muted mt-2 flex flex-wrap items-center gap-2 text-xs",children:e.jsxs("span",{className:"min-w-0 truncate",children:["Last opened: ",cu(K.lastOpenedAt)]})})]})})]},K.id))})]}),e.jsx(fu,{config:l,error:u,vmStarting:Q,workspaceCount:s.length})]}),e.jsx(lo,{open:x!==null,title:"Rename Workspace",label:"Workspace Label",value:v,busy:h!==null,onChange:c,onCancel:fe,onSubmit:()=>x?i(x):void 0}),e.jsx(ul,{open:H!==null,title:"Workspace Path",text:H??"",onClose:()=>O(null)}),e.jsx(js,{open:E!==null,title:"Delete Workspace",description:E?`Delete ${E.label} from supervisor. This also removes its threads and local supervisor metadata.`:"",confirmLabel:"Delete Workspace",busy:G,onCancel:()=>{G||U(null)},onConfirm:()=>void we()})]})}function fu({config:t,error:s,vmStarting:a,workspaceCount:r}){return e.jsxs("aside",{className:"space-y-3 xl:sticky xl:top-[calc(env(safe-area-inset-top)+4.25rem)] xl:self-start",children:[e.jsxs("section",{className:"rounded-lg border border-[var(--theme-border)] bg-[var(--theme-panel)] p-4",children:[e.jsx("p",{className:"text-xs font-semibold uppercase tracking-[0.18em] text-[var(--theme-fg-muted)]",children:"Supervisor"}),e.jsxs("dl",{className:"mt-4 space-y-3",children:[e.jsx(us,{label:"Workspace root",value:(t==null?void 0:t.workspaceRoot)??(a?"VM is starting…":"Loading...")}),e.jsx(us,{label:"Environment",value:t?`${t.environment} · ${t.host}:${t.port}`:a?"Connecting automatically…":s??"Loading..."}),e.jsx(us,{label:"Version",value:t?`${t.appName} ${t.appVersion}`:"Loading..."}),e.jsx(us,{label:"Workspaces",value:String(r)})]})]}),s&&!a?e.jsx("section",{className:"rounded-lg border border-[var(--status-warning-border)] bg-[var(--status-warning-bg)] p-4 text-sm text-[var(--status-warning-fg)]",children:"Runtime metadata is unavailable. Workspace actions may still work if a relay device is connected."}):null]})}function us({label:t,value:s}){return e.jsxs("div",{children:[e.jsx("dt",{className:"text-[11px] font-medium uppercase tracking-[0.14em] text-[var(--theme-fg-muted)]",children:t}),e.jsx("dd",{className:"mt-1 break-words font-mono text-xs leading-5 text-[var(--theme-fg)]",children:s})]})}const co="remote-codex-theme-mode",uo="remote-codex-default-backend",mo="remote-codex-auto-collapse-completed-turns";function pu({children:t}){const s=n.useMemo(()=>({fetchPlugins:Gi,importPlugin:zi,updatePlugin:Ji,deletePlugin:Ki}),[]);return e.jsx(ml,{adapter:s,builtinPlugins:hl,children:t})}function xu(){if(typeof window>"u")return"system";const t=window.localStorage.getItem(co);return t==="light"||t==="dark"||t==="system"?t:"system"}function gu(){if(typeof window>"u")return st;const t=window.localStorage.getItem(uo);return gl(t)??st}function vu(){return typeof window>"u"?!0:window.localStorage.getItem(mo)!=="false"}function bu(t){return(t==null?void 0:t.trim())||"Remote Codex"}function yu(t){return t==="/"||t==="/relay-portal"?"Relay Portal":t==="/relay-guide"?"Relay Setup":t==="/relay-admin"?"Relay Admin":t==="/relay-account"?"Account":t==="/relay-devices"?"Devices and Shared Sessions":t==="/workspaces"||/^\/devices\/[^/]+\/workspaces$/.test(t)?"Workspaces":t==="/workspaces/new"||/^\/devices\/[^/]+\/workspaces\/new$/.test(t)?"New Workspace":t==="/threads"||/^\/devices\/[^/]+\/threads$/.test(t)?"Threads":t==="/threads/import"||/^\/devices\/[^/]+\/threads\/import$/.test(t)?"Import Thread":t==="/threads/new"||/^\/devices\/[^/]+\/threads\/new$/.test(t)?"New Thread":/^\/threads\/[^/]+$/.test(t)||/^\/devices\/[^/]+\/threads\/[^/]+$/.test(t)?"Thread":null}function wu(){const t=qt();return n.useEffect(()=>{document.title=bu(yu(t.pathname))},[t.pathname]),null}function ju(){return typeof window<"u"&&typeof window.matchMedia=="function"&&window.matchMedia("(prefers-color-scheme: dark)").matches?"dark":"light"}function Nu({themeMode:t,setThemeMode:s,effectiveTheme:a}){const[r,o]=n.useState(!1),[l,d]=n.useState(!1),[u,p]=n.useState(gu),[g,b]=n.useState(vu),[x,N]=n.useState(null),v=qt(),h=!(/^\/threads\/(?:import|new)$/.test(v.pathname)||/^\/devices\/[^/]+\/threads\/(?:import|new)$/.test(v.pathname))&&(/^\/threads\/[^/]+$/.test(v.pathname)||/^\/devices\/[^/]+\/threads\/[^/]+$/.test(v.pathname)),D=v.pathname==="/threads"||/^\/devices\/[^/]+\/threads$/.test(v.pathname),H=h||D,O=D||h,E=v.pathname==="/workspaces"||/^\/devices\/[^/]+\/workspaces$/.test(v.pathname);n.useEffect(()=>{o(!1)},[v.pathname,v.search]),n.useEffect(()=>{const Q=I=>{const se=I.detail;if(se.state==="connected"){N(null);return}N(J=>({attempt:se.attempt,startedAt:(J==null?void 0:J.startedAt)??Date.now()}))};return window.addEventListener(ia,Q),()=>window.removeEventListener(ia,Q)},[]);function U(Q){p(Q),window.localStorage.setItem(uo,Q)}function G(Q){b(Q),window.localStorage.setItem(mo,Q?"true":"false")}const te={navOpen:r,openNav:()=>o(!0),toggleNav:()=>o(Q=>!Q),closeNav:()=>o(!1),settingsOpen:l,openSettings:()=>{o(!1),d(!0)},closeSettings:()=>d(!1),themeMode:t,setThemeMode:s,effectiveTheme:a,defaultBackend:u,setDefaultBackend:U,autoCollapseCompletedTurns:g,setAutoCollapseCompletedTurns:G};return e.jsxs(fl.Provider,{value:te,children:[e.jsxs("div",{className:`bg-[var(--app-bg)] text-[var(--app-fg)] ${H?"fixed inset-0 overflow-hidden overscroll-none":"min-h-screen"}`,children:[x?e.jsxs("div",{"aria-live":"polite",className:"fixed inset-x-4 top-4 z-[80] mx-auto max-w-2xl overflow-hidden rounded-lg border border-[var(--status-warning-border)] bg-[var(--theme-panel)] shadow-[var(--theme-shadow)]",role:"status",children:[e.jsxs("div",{className:"flex items-center justify-between gap-4 px-4 py-3",children:[e.jsxs("div",{className:"min-w-0",children:[e.jsx("p",{className:"text-sm font-semibold text-[var(--theme-fg)]",children:"Starting hosted VM"}),e.jsx("p",{className:"truncate text-xs text-[var(--theme-fg-muted)]",children:"Waiting for the supervisor. Pages will resume automatically."})]}),e.jsxs("span",{className:"shrink-0 text-xs tabular-nums text-[var(--theme-fg-muted)]",children:["Check ",x.attempt]})]}),e.jsx("div",{className:"h-1 overflow-hidden bg-[var(--theme-muted)]",children:e.jsx("div",{className:"h-full w-1/3 animate-pulse bg-[var(--theme-accent-solid)]"})})]}):null,e.jsx("main",{className:`mx-auto w-full ${O?"max-w-none":"max-w-[1600px]"} ${H?"absolute inset-0 pb-0 sm:pb-4":"pb-4"} ${O?h?"pt-0":D?"pt-[env(safe-area-inset-top)] sm:pt-0":"pt-[calc(env(safe-area-inset-top)+4rem)] sm:pt-4":E?"pt-[env(safe-area-inset-top)] sm:pt-4":"pt-4"} ${H?"overflow-hidden overscroll-none px-0":"px-4 sm:px-6"}`,children:e.jsx("section",{className:`min-w-0 ${H?h?"h-full min-h-0 overflow-hidden overscroll-none":"h-full overflow-hidden overscroll-none":""}`,children:e.jsx(tl,{})})})]}),e.jsx(va,{})]})}function ku({children:t}){const[s,a]=n.useState({status:"checking"});async function r(d){try{const u=await Gl();if(d!=null&&d())return;a(!u.authRequired||u.authenticated?{status:"authenticated"}:{status:"loginRequired",session:u,error:null})}catch(u){if(d!=null&&d())return;if(u instanceof ce&&u.statusCode===401){a({status:"loginRequired",session:{authenticated:!1,username:null,expiresAt:null,mode:"server",authRequired:!0},error:null});return}a({status:"unavailable",error:u instanceof Error?u.message:"Unable to check supervisor access."})}}n.useEffect(()=>{let d=!1;return r(()=>d),()=>{d=!0}},[]);async function o(d){await zl(d),a({status:"authenticated"})}function l(){a({status:"checking"}),r()}return s.status==="checking"?e.jsx("main",{className:"flex min-h-screen items-center justify-center bg-[var(--app-bg)] px-4 text-sm text-[var(--theme-muted)]",children:"Checking supervisor access..."}):s.status==="unavailable"?e.jsx("main",{className:"flex min-h-screen items-center justify-center bg-[var(--app-bg)] px-4 text-[var(--app-fg)]",children:e.jsxs("section",{className:"w-full max-w-md rounded-lg border border-[var(--theme-border)] bg-[var(--theme-panel)] p-5 shadow-[var(--theme-shadow)] sm:p-6",children:[e.jsx("p",{className:"text-xs font-semibold uppercase tracking-[0.22em] text-[var(--theme-fg-muted)]",children:"Supervisor Access"}),e.jsx("h1",{className:"mt-2 text-2xl font-semibold tracking-normal text-[var(--theme-fg)]",children:"Unable to reach supervisor"}),e.jsx("p",{className:"mt-3 text-sm leading-6 text-[var(--theme-fg-muted)]",children:s.error}),e.jsx("button",{className:"mt-5 h-11 rounded-lg bg-[var(--theme-accent-solid)] px-4 text-sm font-semibold text-[var(--theme-accent-solid-fg)] transition hover:bg-[var(--theme-accent-solid-hover)] focus:outline-none focus:ring-2 focus:ring-[var(--theme-accent-border)]",onClick:l,type:"button",children:"Retry"})]})}):s.status==="loginRequired"?e.jsxs(e.Fragment,{children:[s.error&&e.jsx("div",{className:"fixed left-1/2 top-4 z-50 w-[min(28rem,calc(100vw-2rem))] -translate-x-1/2 rounded-lg border border-[var(--status-warning-border)] bg-[var(--status-warning-bg)] px-3 py-2 text-sm text-[var(--status-warning-fg)]",children:s.error}),e.jsx(Vn,{onLogin:o})]}):t}function Su({children:t}){var r;const[s,a]=n.useState({status:"checking"});return n.useEffect(()=>{let o=!1;return Et().then(l=>{o||a(l.authenticated?{status:"authenticated",session:l}:{status:"loginRequired"})}).catch(()=>{o||a({status:"loginRequired"})}),()=>{o=!0}},[]),s.status==="checking"?e.jsx("main",{className:"flex min-h-screen items-center justify-center bg-[var(--app-bg)] px-4 text-sm text-[var(--theme-muted)]",children:"Checking relay access..."}):s.status==="loginRequired"?e.jsx(ps,{to:"/",replace:!0}):((r=s.session.user)==null?void 0:r.role)==="admin"?e.jsx(ps,{to:"/relay-admin",replace:!0}):t}function Cu({children:t}){return ht()?e.jsx(Su,{children:t}):e.jsx(ku,{children:t})}function ho(){return ht()?e.jsx(kc,{}):e.jsx(ps,{to:"/workspaces",replace:!0})}function Tu({themeMode:t,setThemeMode:s,effectiveTheme:a}){return e.jsxs(bn,{children:[e.jsx(Ae,{path:"/",element:e.jsx(ho,{})}),e.jsxs(Ae,{element:e.jsx(Nu,{themeMode:t,setThemeMode:s,effectiveTheme:a}),children:[e.jsx(Ae,{path:"/workspaces",element:e.jsx(gn,{})}),e.jsx(Ae,{path:"/workspaces/new",element:e.jsx(pn,{})}),e.jsx(Ae,{path:"/relay-account",element:e.jsx(Id,{})}),e.jsx(Ae,{path:"/relay-devices",element:e.jsx(ic,{})}),e.jsx(Ae,{path:"/threads",element:e.jsx(hn,{})}),e.jsx(Ae,{path:"/threads/import",element:e.jsx(un,{})}),e.jsx(Ae,{path:"/threads/new",element:e.jsx(mn,{})}),e.jsx(Ae,{path:"/threads/:id",element:e.jsx(cn,{})}),e.jsx(Ae,{path:"/devices/:relayDeviceId/workspaces",element:e.jsx(gn,{})}),e.jsx(Ae,{path:"/devices/:relayDeviceId/workspaces/new",element:e.jsx(pn,{})}),e.jsx(Ae,{path:"/devices/:relayDeviceId/threads",element:e.jsx(hn,{})}),e.jsx(Ae,{path:"/devices/:relayDeviceId/threads/import",element:e.jsx(un,{})}),e.jsx(Ae,{path:"/devices/:relayDeviceId/threads/new",element:e.jsx(mn,{})}),e.jsx(Ae,{path:"/devices/:relayDeviceId/threads/:id",element:e.jsx(cn,{})})]})]})}function Eu(){const[t,s]=n.useState(()=>xu()),[a,r]=n.useState(()=>ju()),o=t==="system"?a:t;return n.useEffect(()=>{if(typeof window>"u"||typeof window.matchMedia!="function")return;const l=window.matchMedia("(prefers-color-scheme: dark)"),d=()=>{r(l.matches?"dark":"light")};return d(),typeof l.addEventListener=="function"?l.addEventListener("change",d):l.addListener(d),()=>{typeof l.removeEventListener=="function"?l.removeEventListener("change",d):l.removeListener(d)}},[]),n.useEffect(()=>{typeof window>"u"||window.localStorage.setItem(co,t)},[t]),n.useEffect(()=>{const l=document.documentElement;l.dataset.themeMode=t,l.dataset.themeEffective=o,l.style.colorScheme=o},[o,t]),e.jsx("div",{className:"theme-shell theme-scrollbar",children:e.jsxs(el,{children:[e.jsx(wu,{}),e.jsx(pu,{children:e.jsxs(bn,{children:[e.jsx(Ae,{path:"/",element:e.jsx(ho,{})}),e.jsx(Ae,{path:"/relay-guide",element:e.jsx(Nc,{})}),e.jsx(Ae,{path:"/relay-portal",element:e.jsx(Sc,{})}),e.jsx(Ae,{path:"/relay-admin",element:e.jsx(Pd,{})}),e.jsx(Ae,{path:"/*",element:e.jsx(Cu,{children:e.jsx(Tu,{themeMode:t,setThemeMode:s,effectiveTheme:o})})})]})})]})})}sl.createRoot(document.getElementById("root")).render(e.jsx(al.StrictMode,{children:e.jsx(Eu,{})}));