remote-codex 0.11.2 → 0.11.4

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (37) hide show
  1. package/README.md +4 -0
  2. package/apps/relay-server/dist/index.d.ts +2 -0
  3. package/apps/relay-server/dist/index.js +1254 -0
  4. package/apps/supervisor-api/dist/chunk-ZWZQVPDT.js +27893 -0
  5. package/apps/supervisor-api/dist/index.js +4 -25183
  6. package/apps/supervisor-api/dist/worker-index.d.ts +2 -0
  7. package/apps/supervisor-api/dist/worker-index.js +197 -0
  8. package/apps/supervisor-web/dist/assets/index-CbdWtyx0.js +5 -0
  9. package/apps/supervisor-web/dist/assets/index-Di1JBevU.css +1 -0
  10. package/apps/supervisor-web/dist/assets/thread-ui-ICfwCbte.js +3604 -0
  11. package/apps/supervisor-web/dist/assets/ui-vendor-D1uxdi-d.js +430 -0
  12. package/apps/supervisor-web/dist/index.html +6 -7
  13. package/bin/remote-codex.mjs +593 -21
  14. package/package.json +42 -2
  15. package/packages/agent-runtime/src/types.ts +2 -1
  16. package/packages/codex/src/appServerManager.ts +1 -0
  17. package/packages/codex/src/historyItems.test.ts +45 -0
  18. package/packages/codex/src/historyItems.ts +22 -0
  19. package/packages/codex/src/runtimeAdapter.ts +6 -0
  20. package/packages/codex/src/types.ts +2 -1
  21. package/packages/db/migrations/0018_control_plane.sql +129 -0
  22. package/packages/db/migrations/0019_control_plane_projects.sql +19 -0
  23. package/packages/db/migrations/0020_control_workspace_status.sql +1 -0
  24. package/packages/db/migrations/0021_control_sandbox_lifecycle_fields.sql +3 -0
  25. package/packages/db/migrations/0022_control_sandbox_resource_profile.sql +1 -0
  26. package/packages/db/migrations/0023_control_usage_import_state.sql +18 -0
  27. package/packages/db/migrations/0024_control_auth.sql +23 -0
  28. package/packages/db/migrations/0025_control_harness_credentials.sql +29 -0
  29. package/packages/db/migrations/0026_control_harness_usage_events.sql +27 -0
  30. package/packages/db/src/schema.ts +305 -1
  31. package/packages/shared/src/index.ts +186 -0
  32. package/packages/shared/src/tokens.ts +137 -0
  33. package/apps/supervisor-web/dist/assets/index-CbDzXN9T.css +0 -1
  34. package/apps/supervisor-web/dist/assets/index-DQpHiQXN.js +0 -4
  35. package/apps/supervisor-web/dist/assets/thread-ui-BEieA99i.css +0 -1
  36. package/apps/supervisor-web/dist/assets/thread-ui-CDk3ExRH.js +0 -3516
  37. package/apps/supervisor-web/dist/assets/ui-vendor-CgOZX1B8.js +0 -425
@@ -1,4 +0,0 @@
1
- import{r as o,j as e,u as es,d as Ae,L as ze,e as vr,f as ts,a as yr,N as wr,B as kr,h as jr,i as Pe,O as Nr,k as Sr,c as Tr}from"./react-vendor-o1Xrx7m4.js";import{u as as,t as Cr,f as At,E as Ir,C as Ft,T as Er,a as Rr,b as Pr,c as Or,d as Ar,L as Mr,P as Lr}from"./thread-ui-CDk3ExRH.js";import"./ui-vendor-CgOZX1B8.js";import"./terminal-vendor-CLGgN91S.js";import"./graph-vendor-CGzY-MFv.js";import"./markdown-vendor-hBDTCSB-.js";(function(){const a=document.createElement("link").relList;if(a&&a.supports&&a.supports("modulepreload"))return;for(const m of document.querySelectorAll('link[rel="modulepreload"]'))d(m);new MutationObserver(m=>{for(const h of m)if(h.type==="childList")for(const f of h.addedNodes)f.tagName==="LINK"&&f.rel==="modulepreload"&&d(f)}).observe(document,{childList:!0,subtree:!0});function n(m){const h={};return m.integrity&&(h.integrity=m.integrity),m.referrerPolicy&&(h.referrerPolicy=m.referrerPolicy),m.crossOrigin==="use-credentials"?h.credentials="include":m.crossOrigin==="anonymous"?h.credentials="omit":h.credentials="same-origin",h}function d(m){if(m.ep)return;m.ep=!0;const h=n(m);fetch(m.href,h)}})();const ss=["codex","claude","opencode"],Oe="codex",rs={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"}};function Ur(t){return typeof t=="string"&&ss.includes(t)}function $r(t){return Ur(t)?t:null}const Fa=15;function Dr(t){return t.replace(/\s+/g," ").trim()}function ns(t){const a=Dr(t);if(!a)return"";const n=Array.from(a);return n.length<=Fa?a:`${n.slice(0,Fa).join("")}...`}const os=o.createContext(null);function De(){return o.useContext(os)}class z extends Error{constructor(a,n){super(n.message),this.statusCode=a,this.payload=n}}function Hr(t){return t===400?"bad_request":t===403?"forbidden":t===404?"not_found":t===409?"conflict":t===429||t===503?"service_unavailable":"internal_error"}function Br(t,a){const n=a==null?void 0:a.trim(),d=n?`${t} ${n}`:`${t}`;return t===429?`Too many requests (${d}).`:t===503?`Upstream service unavailable (${d}).`:`Request failed (${d}).`}function qe(t,a,n){const d=typeof(a==null?void 0:a.message)=="string"&&a.message.trim()?a.message.trim():n,m=a!=null&&a.details&&typeof a.details=="object"?a.details:void 0;return{code:(a==null?void 0:a.code)??Hr(t.status),message:d,...m?{details:m}:{}}}async function ls(t){var m,h;const a=Br(t.status,t.statusText),n=((h=(m=t.headers)==null?void 0:m.get)==null?void 0:h.call(m,"content-type"))??"",d=async()=>qe(t,await t.json(),a);if(n.includes("application/json"))try{return await d()}catch{return qe(t,null,a)}try{if(typeof t.text!="function")try{return await d()}catch{return qe(t,null,a)}const f=(await t.text()).trim();if(f.startsWith("{"))try{return qe(t,JSON.parse(f),a)}catch{}return qe(t,f?{message:`${a}
2
- ${f}`}:null,a)}catch{try{return await d()}catch{return qe(t,null,a)}}}async function E(t,a){const n=new Headers(a==null?void 0:a.headers);(a==null?void 0:a.body)!==void 0&&!(a.body instanceof FormData)&&!n.has("Content-Type")&&n.set("Content-Type","application/json");const d=await fetch(t,{headers:n,...a});if(!d.ok){const m=await ls(d);throw new z(d.status,m)}return await d.json()}function Fr(t){const a=String(t);return a.includes("/exports/pdf")?a.includes("format=html")?"remote-codex-transcript.html":"remote-codex-transcript.pdf":"download"}function qr(t){var m;if(!t)return null;const a=t.match(/filename\*=UTF-8''([^;]+)/i);if(a!=null&&a[1])try{return decodeURIComponent(a[1].trim())}catch{return a[1].trim()}const n=t.match(/filename="([^"]+)"/i);if(n!=null&&n[1])return n[1].trim();const d=t.match(/filename=([^;]+)/i);return((m=d==null?void 0:d[1])==null?void 0:m.trim())??null}async function is(t,a){const n=await fetch(t,a);if(!n.ok){const m=await ls(n);throw new z(n.status,m)}const d=qr(n.headers.get("content-disposition"))??Fr(t);return{blob:await n.blob(),filename:d}}function qa(t,a){const n=t.originalName.trim();if(n)return n;const d=t.file.name.trim();return d||(t.kind==="photo"?`photo-${a+1}.jpg`:`file-${a+1}`)}function Wr(){return E("/api/config/runtime")}function _r(){return E("/api/config/workspace-settings",{cache:"no-store"})}function zr(t){return E("/api/config/workspace-settings",{method:"PATCH",body:JSON.stringify(t)})}function ds(){return E("/api/agent-runtimes",{cache:"no-store"})}function cs(t){return E(`/api/agent-runtimes/${encodeURIComponent(t)}/status`,{cache:"no-store"})}function Vr(t){return E(`/api/agent-runtimes/${encodeURIComponent(t)}/restart`,{method:"POST"})}function Gr(t,a){return E(`/api/agent-runtimes/${encodeURIComponent(t)}/install`,{method:"POST",body:JSON.stringify({action:a})})}function Ht(t){return E(`/api/agent-runtimes/${encodeURIComponent(t)}/models`,{cache:"no-store"})}function us(t,a){return E(`/api/config/providers/${encodeURIComponent(t)}/files/${encodeURIComponent(a)}`,{cache:"no-store"})}function ms(t,a,n){return E(`/api/config/providers/${encodeURIComponent(t)}/files/${encodeURIComponent(a)}`,{method:"PATCH",body:JSON.stringify(n)})}function Jr(t){return E(`/api/config/providers/${encodeURIComponent(t)}/archives`,{cache:"no-store"})}function Kr(t,a={}){return E(`/api/config/providers/${encodeURIComponent(t)}/archives`,{method:"POST",body:JSON.stringify(a)})}function Zr(t,a,n){return E(`/api/config/providers/${encodeURIComponent(t)}/archives/${encodeURIComponent(a)}`,{method:"PATCH",body:JSON.stringify(n)})}function Yr(t,a){return E(`/api/config/providers/${encodeURIComponent(t)}/archives/${encodeURIComponent(a)}/apply`,{method:"POST"})}function Qr(){return E("/api/service/build-restart",{method:"POST"})}function Xr(){return E("/healthz",{cache:"no-store"})}function qt(){return E("/api/workspaces")}function en(t){return E(`/api/workspaces/${encodeURIComponent(t)}/files/tree`,{cache:"no-store"})}function tn(t,a){const n=new URLSearchParams({path:a.path});return a.offset!==void 0&&n.set("offset",String(a.offset)),a.limit!==void 0&&n.set("limit",String(a.limit)),E(`/api/workspaces/${encodeURIComponent(t)}/files/preview?${n.toString()}`,{cache:"no-store"})}function an(t,a){const n=new URLSearchParams({path:a.path});return`/api/workspaces/${encodeURIComponent(t)}/files/raw?${n.toString()}`}function sn(t,a){const n=new URLSearchParams({path:a.path});return is(`/api/workspaces/${encodeURIComponent(t)}/files/download?${n.toString()}`,{cache:"no-store"})}function rn(t,a){const n=new FormData;return n.append("file",a.file,a.file.name),E(`/api/workspaces/${encodeURIComponent(t)}/files/upload`,{method:"POST",body:n})}function ps(){return E("/api/threads")}function Wa(t,a={}){const n=new URLSearchParams;return a.limit!==void 0&&n.set("limit",String(a.limit)),a.beforeTurnId&&n.set("beforeTurnId",a.beforeTurnId),E(`/api/threads/${t}${n.size>0?`?${n.toString()}`:""}`)}function nn(t,a){return E(`/api/threads/${t}/items/${encodeURIComponent(a)}/detail`)}function on(){return E("/api/plugins",{cache:"no-store"})}function ln(t){return E("/api/plugins/import",{method:"POST",body:JSON.stringify(t)})}function dn(t,a){return E(`/api/plugins/${encodeURIComponent(t)}`,{method:"PATCH",body:JSON.stringify(a)})}function cn(t){return E(`/api/threads/${t}/export-turns`,{cache:"no-store"})}function un(t,a){var d,m,h;const n=new URLSearchParams;return a.format!==void 0&&n.set("format",a.format),n.set("mode",a.mode),a.limit!==void 0&&n.set("limit",String(a.limit)),a.turnIds!==void 0&&n.set("turnIds",a.turnIds.join(",")),a.profile!==void 0&&n.set("profile",a.profile),((d=a.options)==null?void 0:d.includeTokenAndPrice)!==void 0&&n.set("includeTokenAndPrice",String(a.options.includeTokenAndPrice)),((m=a.options)==null?void 0:m.includeCommandOutput)!==void 0&&n.set("includeCommandOutput",String(a.options.includeCommandOutput)),((h=a.options)==null?void 0:h.includeAbsolutePaths)!==void 0&&n.set("includeAbsolutePaths",String(a.options.includeAbsolutePaths)),`/api/threads/${encodeURIComponent(t)}/exports/pdf?${n.toString()}`}function mn(t,a){return is(un(t,a),{cache:"no-store"})}function pn(t){return E(`/api/threads/${t}/shell`)}function hn(t){return E("/api/threads/start",{method:"POST",body:JSON.stringify(t)})}function fn(t){return E("/api/threads/import",{method:"POST",body:JSON.stringify({sessionId:t})})}function gn(t,a={}){return E(`/api/threads/${t}/shell`,{method:"POST",...Object.keys(a).length>0?{body:JSON.stringify(a)}:{}})}function xn(t){return E(`/api/shells/${t}/terminate`,{method:"POST"})}function bn(t,a){return E(`/api/shells/${t}`,{method:"PATCH",body:JSON.stringify(a)})}function _a(t,a={}){return E(`/api/threads/${t}/resume`,{method:"POST",...Object.keys(a).length>0?{body:JSON.stringify(a)}:{}})}function vn(t){return E(`/api/threads/${t}/disconnect`,{method:"POST"})}function yn(t,a){const n=a.attachments??[];if(n.length===0)return E(`/api/threads/${t}/prompt`,{method:"POST",body:JSON.stringify(a)});const d=new FormData;d.append("prompt",a.prompt),a.clientRequestId!==void 0&&d.append("clientRequestId",a.clientRequestId),a.model!==void 0&&d.append("model",a.model),a.reasoningEffort!==void 0&&a.reasoningEffort!==null&&d.append("reasoningEffort",a.reasoningEffort),a.collaborationMode!==void 0&&d.append("collaborationMode",a.collaborationMode),a.sandboxMode!==void 0&&a.sandboxMode!==null&&d.append("sandboxMode",a.sandboxMode);const m=n.map((h,f)=>({clientId:h.clientId,kind:h.kind,originalName:qa(h,f),placeholder:h.placeholder}));d.append("attachmentManifest",JSON.stringify(m));for(const[h,f]of n.entries())d.append("attachments",f.file,qa(f,h));return E(`/api/threads/${t}/prompt`,{method:"POST",body:d})}function za(t,a={}){return E(`/api/threads/${t}/interrupt`,{method:"POST",body:JSON.stringify(a)})}function hs(t,a){return E(`/api/threads/${t}`,{method:"PATCH",body:JSON.stringify(a)})}function fs(t){return E(`/api/threads/${t}`,{method:"DELETE"})}function wn(t,a){return E(`/api/threads/${t}/settings`,{method:"PATCH",body:JSON.stringify(a)})}function kn(t){return E(`/api/threads/${t}/compact`,{method:"POST"})}function jn(t){return E(`/api/threads/${t}/goal`,{cache:"no-store"})}function Nn(t,a){return E(`/api/threads/${t}/goal`,{method:"PATCH",body:JSON.stringify(a)})}function Sn(t){return E(`/api/threads/${t}/goal`,{method:"DELETE"})}function Tn(t){return E(`/api/threads/${t}/fork-turns`,{cache:"no-store"})}function Va(t,a){return E(`/api/threads/${t}/fork`,{method:"POST",body:JSON.stringify(a)})}function Cn(t){return E(`/api/threads/${t}/skills`,{cache:"no-store"})}function In(t){return E(`/api/threads/${t}/mcp-servers`,{cache:"no-store"})}function En(t){return E(`/api/threads/${t}/hooks`,{cache:"no-store"})}function Rn(t,a){return E(`/api/threads/${t}/hooks`,{method:"POST",body:JSON.stringify(a)})}function Pn(t,a){return E(`/api/threads/${t}/hooks`,{method:"PUT",body:JSON.stringify(a)})}function On(t,a){return E(`/api/threads/${t}/hooks/trust`,{method:"POST",body:JSON.stringify(a)})}function An(t,a){return E(`/api/threads/${t}/hooks/untrust`,{method:"POST",body:JSON.stringify(a)})}function Mn(t,a,n){return E(`/api/threads/${t}/requests/${encodeURIComponent(a)}/respond`,{method:"POST",body:JSON.stringify(n)})}function Ln(t){return E("/api/workspaces",{method:"POST",body:JSON.stringify(t)})}function Un(t,a){return E(`/api/workspaces/${t}`,{method:"PATCH",body:JSON.stringify(a)})}function $n(t){return E(`/api/workspaces/${t}`,{method:"DELETE"})}function Dn(t,a){return E(`/api/workspaces/${t}/favorite`,{method:"POST",body:JSON.stringify(a)})}function gs(t){const a=window.location.protocol==="https:"?"wss:":"ws:",n=new WebSocket(`${a}//${window.location.host}/ws`);return n.addEventListener("message",d=>{try{const m=JSON.parse(d.data);Bn(m)&&t(m)}catch{}}),n}function Hn(t={}){const a=window.location.protocol==="https:"?"wss:":"ws:",n=new WebSocket(`${a}//${window.location.host}/ws`);return n.addEventListener("message",d=>{var m,h;try{const f=JSON.parse(d.data);if(f.type==="supervisor.connected"){(m=t.onConnected)==null||m.call(t,f);return}Fn(f)&&((h=t.onShellEvent)==null||h.call(t,f))}catch{}}),{socket:n,send(d){n.send(JSON.stringify(d))}}}function Bn(t){return"threadId"in t&&t.type.startsWith("thread.")&&typeof t.payload=="object"&&t.payload!==null}function Fn(t){return"shellId"in t&&t.type.startsWith("shell.")&&typeof t.payload=="object"&&t.payload!==null}function qn(){return e.jsx("svg",{"aria-hidden":"true",viewBox:"0 0 16 16",className:"h-4 w-4 fill-current",children:e.jsx("path",{d:"M2 3.25h12v1.5H2Zm0 4h12v1.5H2Zm0 4h12v1.5H2Z"})})}function wt(){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"})})}function Ga(t=!1){return`flex w-full items-center rounded-[0.95rem] px-3 py-2 text-left text-sm transition ${t?"cursor-not-allowed bg-[var(--theme-muted)] text-[var(--theme-fg-muted)]":"text-[var(--theme-fg)] hover:bg-[var(--theme-hover)]"}`}const Wn=[{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."}],xs={hostConfigFiles:[],toolboxItems:[],hookCommandTemplates:[],providerConfigFormat:"none",mcpConfigFormat:"none",configArchives:!1,buildRestart:!1},_n={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"}};function Bt(t){const a=_n[t];return{packageName:a.packageName,installed:t==="codex",installedVersion:null,latestVersion:null,installCommand:a.installCommand,updateCommand:a.updateCommand,busy:!1,lastError:null}}function zn(t,a){return{provider:t,displayName:a,description:`${a} backend descriptor is not available.`,enabled:!1,isDefault:t===Oe,status:{state:"stopped",transport:rs[t].defaultTransport,lastStartedAt:null,lastError:"Backend descriptor is not available.",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:xs,installation:Bt(t)}}function Mt(t){const a=t.installation??Bt(t.provider);return{...t,installation:{...Bt(t.provider),...a}}}const _e=[...ss.map(t=>zn(t,rs[t].displayName))];function Vn(t){var a;return((a=_e.find(n=>n.provider===t))==null?void 0:a.managementSchema)??xs}function Gn(t){const a=new Date(t);return Number.isNaN(a.getTime())?t:a.toLocaleString(void 0,{month:"short",day:"numeric",hour:"2-digit",minute:"2-digit"})}function Jn(t){const a=t.payload.details,n=typeof(a==null?void 0:a.stderr)=="string"&&a.stderr.trim()?a.stderr.trim():typeof(a==null?void 0:a.stdout)=="string"&&a.stdout.trim()?a.stdout.trim():null;return n?`${t.message}
3
- ${n}`:t.message}function Ke(t){return{path:t,exists:!1,originalContent:"",draftContent:"",loading:!1,saving:!1,error:null,saveMessage:null}}function bs({className:t=""}){const a=De();return a?e.jsx("button",{type:"button","aria-label":a.navOpen?"Close Navigation":"Open Navigation","aria-expanded":a.navOpen,"aria-controls":"app-shell-navigation-menu",onClick:a.toggleNav,className:`inline-flex h-10 w-10 shrink-0 items-center justify-center text-[var(--theme-fg)] transition hover:text-[var(--theme-fg-soft)] ${t}`.trim(),children:a.navOpen?e.jsx(wt,{}):e.jsx(qn,{})}):null}function vs({className:t=""}){const a=De(),n=es(),d=Ae(),m=o.useRef(null),h=n.pathname==="/workspaces";return o.useEffect(()=>{if(!(a!=null&&a.navOpen))return;const f=a;function k(C){const j=C.target;if(!j)return;const R=m.current;R!=null&&R.contains(j)||j instanceof Element&&j.closest('[aria-controls="app-shell-navigation-menu"]')||f.closeNav()}return document.addEventListener("pointerdown",k),()=>{document.removeEventListener("pointerdown",k)}},[a]),a!=null&&a.navOpen?e.jsxs("div",{ref:m,id:"app-shell-navigation-menu",onPointerDown:f=>{f.stopPropagation()},onMouseDown:f=>{f.stopPropagation()},onTouchStart:f=>{f.stopPropagation()},className:`rounded-[1.8rem] border border-[var(--theme-border)] bg-[var(--theme-panel)] p-4 shadow-2xl shadow-black/15 backdrop-blur ${t}`.trim(),children:[e.jsxs("div",{children:[e.jsx("p",{className:"text-base font-semibold tracking-wide text-[var(--theme-accent-strong)]",children:"Remote Codex"}),e.jsx("p",{className:"mt-1 text-xs uppercase tracking-[0.24em] text-[var(--theme-fg-muted)]",children:"Navigation"})]}),e.jsxs("nav",{className:"mt-4 flex flex-col gap-1.5 text-sm",children:[e.jsx("button",{type:"button",disabled:h,onClick:()=>{h||(a.closeNav(),d("/workspaces"))},className:Ga(h),children:"Workspaces"}),e.jsx("button",{type:"button",onClick:()=>{a.openSettings()},className:Ga(),children:"Settings"})]})]}):null}function Wt({embedded:t=!1}={}){const a=De(),n=as(),[d,m]=o.useState(""),[h,f]=o.useState({busy:!1,message:null,error:null}),[k,C]=o.useState(!1),[j,R]=o.useState(null),[w,O]=o.useState({}),S=j?w[j]:null,[L,D]=o.useState({busy:!1,message:null,error:null}),[K,ne]=o.useState([]),[re,ee]=o.useState(_e),[U,ie]=o.useState({loading:!1,saving:!1,error:null,operatingProvider:null,operatingAction:null,message:null}),[i,_]=o.useState(null),[se,H]=o.useState({devHomeDraft:"",loading:!1,saving:!1,message:null,error:null}),[Z,V]=o.useState({loading:!1,creating:!1,applyingId:null,renamingId:null,renameDraft:"",message:null,error:null}),T=(a==null?void 0:a.themeMode)??"system",q=t||!!(a!=null&&a.settingsOpen);async function N(){const c=d.trim();if(!(!c||h.busy)){f({busy:!0,message:null,error:null});try{await n.importPluginManifest({manifestJson:c,enabled:!0}),m(""),f({busy:!1,message:"Plugin manifest imported.",error:null})}catch(p){f({busy:!1,message:null,error:p instanceof Error?p.message:"Unable to import plugin manifest."})}}}const W=(a==null?void 0:a.effectiveTheme)??"dark",$=(a==null?void 0:a.defaultBackend)??Oe,je=n.plugins.filter(c=>c.enabled).length,be=n.loading?"Loading...":`${je}/${n.plugins.length} enabled`,I=re.find(c=>c.provider===$)??_e.find(c=>c.provider===$)??_e[0],G=I.managementSchema??Vn(I.provider),Y=G.hostConfigFiles;o.useEffect(()=>{if(!q||t||!a||!G.configArchives)return;const c=a;function p(x){x.key==="Escape"&&c.closeSettings()}return window.addEventListener("keydown",p),()=>{window.removeEventListener("keydown",p)}},[G.configArchives,t,q,a]),o.useEffect(()=>{if(!q)return;let c=!1;return ie(p=>({...p,loading:!0,error:null})),ds().then(p=>{if(c)return;const x=[...p.map(Mt),..._e.filter(M=>!p.some(te=>te.provider===M.provider))];ee(x),ie(M=>({...M,loading:!1}))}).catch(p=>{c||(ee(_e),ie(x=>({...x,loading:!1,error:p instanceof z?p.message:"Unable to load backend settings."})))}),()=>{c=!0}},[q]),o.useEffect(()=>{if(!q)return;let c=!1;return H(p=>({...p,loading:!0,message:null,error:null})),_r().then(p=>{c||(_(p),H(x=>({...x,devHomeDraft:p.devHome,loading:!1})))}).catch(p=>{c||H(x=>({...x,loading:!1,error:p instanceof z?p.message:"Unable to load workspace settings."}))}),()=>{c=!0}},[q]),o.useEffect(()=>{if(!q||!I.capabilities.management.hostConfigFiles)return;let c=!1;async function p(){O(M=>{const te={...M};for(const xe of Y)te[xe.name]={...Ke(xe.name),...M[xe.name],loading:!0,saving:!1,error:null,saveMessage:null};return te});const x=await Promise.allSettled(Y.map(async M=>({name:M.name,result:await us(I.provider,M.name)})));c||O(M=>{var xe,Ie;const te={...M};for(const Ne of x){if(Ne.status==="fulfilled"){const{name:st,result:Ee}=Ne.value;te[st]={path:Ee.path,exists:Ee.exists,originalContent:Ee.content,draftContent:Ee.content,loading:!1,saving:!1,error:null,saveMessage:null};continue}const at=Ne.reason instanceof z?Ne.reason.message:"Unable to load the file.",Le=((xe=Y[x.indexOf(Ne)])==null?void 0:xe.name)??((Ie=Y[0])==null?void 0:Ie.name);Le&&(te[Le]={...Ke(Le),...te[Le],loading:!1,saving:!1,error:at,saveMessage:null})}return te})}return p(),()=>{c=!0}},[I.capabilities.management.hostConfigFiles,I.provider,Y,q]),o.useEffect(()=>{if(!q)return;let c=!1;async function p(){V(x=>({...x,loading:!0,error:null,message:null}));try{const x=await Jr(I.provider);if(c)return;ne(x),V(M=>({...M,loading:!1}))}catch(x){if(c)return;V(M=>({...M,loading:!1,error:x instanceof z?x.message:"Unable to load config archives."}))}}return p(),()=>{c=!0}},[I.provider,G.configArchives,q]);async function de(){if(!(L.busy||U.saving)){D({busy:!0,message:null,error:null});try{const c=await Vr(I.provider),p=Mt(c);D({busy:!1,message:p.status.state==="ready"?`${p.displayName} backend restarted.`:`${p.displayName} backend state: ${p.status.state}`,error:null}),ee(x=>x.map(M=>M.provider===p.provider?p:M))}catch(c){D({busy:!1,message:null,error:c instanceof z?c.message:"Unable to restart the app server."})}}}async function ue(c,p){if(L.busy||U.saving)return;const x=re.find(M=>M.provider===c);ie(M=>({...M,saving:!0,operatingProvider:c,operatingAction:p,message:null,error:null}));try{const M=await Gr(c,p),te=Mt(M);ee(xe=>xe.map(Ie=>Ie.provider===te.provider?te:Ie)),ie(xe=>({...xe,saving:!1,operatingProvider:null,operatingAction:null,message:te.installation.lastError?`${te.displayName} ${p==="install"?"installed":"updated"}, but requires attention:
4
- ${te.installation.lastError}`:`${te.displayName} ${p==="install"?"installed":"updated"}.`,error:null}))}catch(M){ie(te=>({...te,saving:!1,operatingProvider:null,operatingAction:null,message:null,error:M instanceof z?Jn(M):`Unable to ${p} ${(x==null?void 0:x.displayName)??c}.`}))}}async function Nt(){if(!(L.busy||U.saving)){D({busy:!0,message:null,error:null});try{await Qr(),D({busy:!1,message:"Build and restart launched. The page may disconnect briefly.",error:null})}catch(c){D({busy:!1,message:null,error:c instanceof z?c.message:"Unable to launch build and restart."})}}}async function St(){const c=se.devHomeDraft.trim();if(!(!c||se.saving)){H(p=>({...p,saving:!0,message:null,error:null}));try{const p=await zr({devHome:c});_(p),H(x=>({...x,devHomeDraft:p.devHome,saving:!1,message:"Workspace defaults saved."}))}catch(p){H(x=>({...x,saving:!1,error:p instanceof z?p.message:"Unable to save workspace settings."}))}}}async function Qe(c){const p=w[c];if(!(!p||p.saving)){O(x=>({...x,[c]:{...Ke(c),...x[c],saving:!0,error:null,saveMessage:null}}));try{const x=await ms(I.provider,c,{content:p.draftContent});O(M=>({...M,[c]:{path:x.path,exists:x.exists,originalContent:x.content,draftContent:x.content,loading:!1,saving:!1,error:null,saveMessage:"Saved"}}))}catch(x){O(M=>({...M,[c]:{...Ke(c),...M[c],saving:!1,error:x instanceof z?x.message:"Unable to save the file.",saveMessage:null}}))}}}async function Xe(){if(!Z.creating){V(c=>({...c,creating:!0,message:null,error:null}));try{const c=await Kr(I.provider);ne(p=>[c,...p]),V(p=>({...p,creating:!1,message:"Backup created."}))}catch(c){V(p=>({...p,creating:!1,error:c instanceof z?c.message:"Unable to create a config backup."}))}}}async function et(c){if(!Z.applyingId){V(p=>({...p,applyingId:c.id,message:null,error:null}));try{const p=await Yr(I.provider,c.id);V(x=>({...x,applyingId:null,message:p.status.state==="ready"?`Applied "${p.archive.label}" and restarted ${I.displayName}.`:`Applied "${p.archive.label}". ${I.displayName} state: ${p.status.state}.`}))}catch(p){V(x=>({...x,applyingId:null,error:p instanceof z?p.message:"Unable to apply the config archive."}))}}}async function tt(c){const p=Z.renameDraft.trim();if(!(!p||Z.renamingId!==c.id)){V(x=>({...x,message:null,error:null}));try{const x=await Zr(I.provider,c.id,{label:p});ne(M=>M.map(te=>te.id===c.id?x:te)),V(M=>({...M,renamingId:null,renameDraft:"",message:"Backup renamed."}))}catch(x){V(M=>({...M,error:x instanceof z?x.message:"Unable to rename the config backup."}))}}}if(!q)return null;const Me=e.jsxs(e.Fragment,{children:[e.jsxs("div",{className:"mt-3 grid gap-2",children:[n.plugins.map(c=>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:c.name}),e.jsx("span",{className:"mt-1 block text-xs leading-5 text-[var(--theme-fg-muted)]",children:c.description}),e.jsx("span",{className:"mt-2 block text-[10px] uppercase tracking-[0.16em] text-[var(--theme-fg-muted)]",children:[...c.capabilities.artifactTypes.map(p=>p.type),...c.capabilities.threadPanels.map(p=>p.kind??p.id)].join(", ")||"utility"}),e.jsx("span",{className:"mt-1 block text-[10px] uppercase tracking-[0.16em] text-[var(--theme-fg-muted)]",children:c.source==="imported"?"Imported manifest":"Built-in module"})]}),e.jsx("input",{type:"checkbox",checked:c.enabled,onChange:p=>void n.setPluginEnabled(c.id,p.currentTarget.checked),className:"mt-1 h-4 w-4 shrink-0 accent-[var(--theme-accent-solid)]"})]},c.id)),n.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:d,onChange:c=>{m(c.currentTarget.value),(h.message||h.error)&&f({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 N(),disabled:!d.trim()||h.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:h.busy?"Importing...":"Import"})]}),h.error&&e.jsx("p",{className:"mt-2 text-xs text-rose-300",children:h.error}),h.message&&e.jsx("p",{className:"mt-2 text-xs text-emerald-300",children:h.message})]}),n.error&&e.jsx("p",{className:"mt-2 text-xs text-rose-300",children:n.error})]}),He=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:a==null?void 0:a.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(wt,{})})]})}),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:"," ",W,"."]})]})}),e.jsx("div",{className:"mt-3 grid gap-2 sm:grid-cols-3",children:Wn.map(c=>{const p=T===c.value;return e.jsxs("button",{type:"button",onClick:()=>a==null?void 0:a.setThemeMode(c.value),className:`block rounded-[1rem] border px-3 py-2.5 text-left transition ${p?"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:c.label}),p?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:c.description})]},c.value)})})]}),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 n.refresh(),disabled:n.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:n.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:be}),e.jsx("button",{type:"button",onClick:()=>C(!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"})]}):Me]}),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:(i==null?void 0:i.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:se.loading&&!i?"Loading...":(i==null?void 0:i.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:se.devHomeDraft,onChange:c=>H(p=>({...p,devHomeDraft:c.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 St(),disabled:se.loading||se.saving||!se.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:se.saving?"Saving...":"Save"})]})]})]}),se.error?e.jsx("p",{className:"mt-2 text-xs text-rose-300",children:se.error}):se.message?e.jsx("p",{className:"mt-2 text-xs text-emerald-300",children:se.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 de(),disabled:L.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:L.busy?"Restarting...":"Restart"}),e.jsx("button",{type:"button",onClick:()=>void Nt(),disabled:L.busy||U.saving,className:"rounded-full border border-amber-400/35 bg-amber-400/10 px-3 py-1.5 text-xs font-medium text-amber-500 transition hover:bg-amber-400/16 disabled:cursor-not-allowed disabled:border-[var(--theme-border)] disabled:bg-[var(--theme-muted)] disabled:text-[var(--theme-fg-muted)]",children:L.busy?"Working...":"Build and restart"})]})]}),e.jsx("div",{className:"mt-3 grid gap-2",children:re.map(c=>{const p=c.installation,x=!p.installed&&!!p.installCommand,M=p.installed&&!!p.updateCommand,te=U.saving&&U.operatingProvider===c.provider,xe=x?"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:c.displayName}),e.jsx("span",{className:`rounded-full border px-2 py-0.5 text-[10px] uppercase tracking-[0.16em] ${c.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:c.enabled?"Ready":p.installed?c.status.state:"Not installed"})]}),e.jsxs("p",{className:"mt-1 truncate text-xs text-[var(--theme-fg-muted)]",children:["Version:"," ",p.installedVersion??(p.installed?"Installed":"Unavailable"),p.latestVersion?` · Latest: ${p.latestVersion}`:""]}),p.lastError?e.jsx("p",{className:"mt-1 line-clamp-2 text-xs text-rose-300",children:p.lastError}):null]}),x||M?e.jsx("button",{type:"button","aria-label":`${x?"Install":"Update"} ${c.displayName}`,onClick:()=>void ue(c.provider,x?"install":"update"),disabled:L.busy||U.saving||!x&&!M,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:te?U.operatingAction==="install"?"Installing...":"Updating...":xe}):null]},c.provider)})}),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}):U.message?e.jsx("p",{className:`mt-2 whitespace-pre-line text-xs ${U.message.includes("requires attention")?"text-amber-300":"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:[I.displayName," exposes these editable files through its backend schema."]})]})}),e.jsxs("div",{className:"mt-3 grid gap-2 sm:grid-cols-2",children:[Y.map(c=>{const p=w[c.name]??{path:c.name,exists:!1,originalContent:"",draftContent:"",loading:!1},x=p.draftContent!==p.originalContent;return e.jsx("button",{type:"button",onClick:()=>R(c.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:c.label}),e.jsx("p",{className:"mt-1 text-xs leading-5 text-[var(--theme-fg-muted)]",children:c.description})]}),e.jsx("div",{className:"shrink-0",children:p.loading?e.jsx("span",{className:"text-[11px] uppercase tracking-[0.2em] text-[var(--theme-fg-muted)]",children:"Loading"}):x?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"}):p.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"})})]})},c.name)}),Y.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]})]}),G.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 Xe(),disabled:Z.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:Z.creating?"Creating...":"Create backup"})]}),Z.error?e.jsx("p",{className:"mt-2 text-xs text-rose-300",children:Z.error}):Z.message?e.jsx("p",{className:"mt-2 text-xs text-emerald-300",children:Z.message}):null,e.jsx("div",{className:"mt-3 space-y-2",children:Z.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..."}):K.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."}):K.map(c=>{const p=Z.renamingId===c.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:[p?e.jsxs("div",{className:"flex max-w-xl gap-2",children:[e.jsx("input",{"aria-label":`Rename ${c.label}`,value:Z.renameDraft,onChange:x=>V(M=>({...M,renameDraft:x.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 ${c.label}`,onClick:()=>void tt(c),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:()=>V(x=>({...x,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:c.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 ",Gn(c.createdAt)]}),Y.map(x=>{var M;return e.jsxs("span",{className:"rounded-full border border-[var(--theme-border)] bg-[var(--theme-panel)] px-2 py-0.5 font-mono",children:[x.name,":"," ",(M=c.files[x.name])!=null&&M.exists?"saved":"missing"]},x.name)})]})]}),e.jsxs("div",{className:"flex shrink-0 flex-wrap gap-2",children:[e.jsx("button",{type:"button",onClick:()=>V(x=>({...x,renamingId:c.id,renameDraft:c.label,message:null,error:null})),disabled:p,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 et(c),disabled:Z.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:Z.applyingId===c.id?"Applying...":"Apply"})]})]})},c.id)})})]}):null]})})]});return t?e.jsxs("div",{className:"flex min-h-0 flex-col overflow-hidden",children:[He,k?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:()=>C(!1),className:"absolute inset-0 bg-black/35 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-[1.35rem] border border-[var(--theme-border)] bg-[var(--theme-panel)] shadow-2xl shadow-black/25",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:be})]}),e.jsxs("div",{className:"flex shrink-0 items-center gap-2",children:[e.jsx("button",{type:"button",onClick:()=>void n.refresh(),disabled:n.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:n.loading?"Loading...":"Refresh"}),e.jsx("button",{type:"button","aria-label":"Close plugins panel",onClick:()=>C(!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(wt,{})})]})]}),e.jsx("div",{className:"min-h-0 flex-1 overflow-y-auto p-4",children:Me})]})]}):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:a==null?void 0:a.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-[1.8rem] border border-[var(--theme-border)] bg-[var(--theme-panel)] shadow-2xl shadow-black/20",children:He}),j&&S?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-[1.6rem] border border-[var(--theme-border)] bg-[var(--theme-panel)] shadow-2xl shadow-black/25",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:j}),e.jsx("p",{className:"mt-1 break-all font-mono text-xs text-[var(--theme-fg-muted)]",children:S.path})]}),e.jsxs("div",{className:"flex items-center gap-2",children:[S.error?e.jsx("span",{className:"text-xs text-rose-300",children:S.error}):S.saveMessage?e.jsx("span",{className:"text-xs text-emerald-300",children:S.saveMessage}):null,e.jsx("button",{type:"button","aria-label":`Save ${j}`,onClick:()=>void Qe(j),disabled:S.loading||S.saving||S.draftContent===S.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:S.saving?"Saving...":"Save"}),e.jsx("button",{type:"button","aria-label":"Close File Editor",onClick:()=>R(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(wt,{})})]})]}),e.jsx("div",{className:"min-h-0 flex-1 overflow-y-auto p-4 sm:p-5",children:e.jsx("textarea",{"aria-label":`Edit ${j}`,value:S.draftContent,onChange:c=>O(p=>({...p,[j]:{...Ke(j),...p[j],draftContent:c.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:S.loading?"Loading...":`Edit ${j} here`})})]})}):null]})}function Lt({eyebrow:t,title:a,description:n}){return e.jsxs("div",{className:"host-card rounded-3xl border p-5",children:[e.jsx("p",{className:"host-page-eyebrow text-xs uppercase tracking-[0.3em]",children:t}),e.jsx("h2",{className:"host-page-title mt-3 text-xl font-semibold",children:a}),e.jsx("p",{className:"host-page-description mt-2 text-sm leading-6",children:n})]})}function Kn(){const[t,a]=o.useState(null),[n,d]=o.useState(null);return o.useEffect(()=>{Wr().then(a).catch(m=>{d(m instanceof Error?m.message:"Unable to load runtime config.")})},[]),e.jsx("div",{className:"min-h-screen bg-[var(--app-bg)] px-4 py-8 text-[var(--app-fg)] sm:px-6",children:e.jsx("div",{className:"mx-auto max-w-7xl",children:e.jsxs("div",{className:"grid gap-6 lg:grid-cols-[1.2fr_0.8fr]",children:[e.jsxs("section",{className:"host-card rounded-[2rem] border p-8 sm:p-10",children:[e.jsx("p",{className:"text-xs uppercase tracking-[0.35em] text-[var(--theme-accent-strong)]",children:"Local Supervisor"}),e.jsx("h1",{className:"host-page-title mt-4 max-w-3xl text-4xl font-semibold tracking-tight sm:text-6xl",children:"Bring your local workspaces into a mobile-ready control surface."}),e.jsx("p",{className:"host-page-description mt-6 max-w-2xl text-base leading-7 sm:text-lg",children:"Phase 1 focuses on a stable supervisor shell: runtime config, workspace onboarding, database bootstrap, and a read-only file tree that already respects workspace root boundaries."}),e.jsxs("div",{className:"mt-8 flex flex-wrap gap-4",children:[e.jsx(ze,{to:"/workspaces",className:"ui-action-primary rounded-full px-5 py-3 font-medium transition",children:"Enter Workspace Console"}),e.jsx(ze,{to:"/workspaces/new",className:"host-secondary-button rounded-full border px-5 py-3 font-medium transition",children:"Add First Workspace"})]})]}),e.jsxs("section",{className:"grid gap-4",children:[e.jsx(Lt,{eyebrow:"Health",title:n?"API unavailable":"Supervisor reachable",description:n??`Connected to ${(t==null?void 0:t.appName)??"Remote Codex Supervisor"} ${(t==null?void 0:t.appVersion)??""}`.trim()}),e.jsx(Lt,{eyebrow:"Workspace Root",title:(t==null?void 0:t.workspaceRoot)??"Loading root path",description:"The file tree and workspace creation flow stay inside this boundary in Phase 1."}),e.jsx(Lt,{eyebrow:"Environment",title:(t==null?void 0:t.environment)??"Loading environment",description:t?`${t.host}:${t.port}`:"Runtime metadata appears here after bootstrap."})]})]})})})}function Zn(t){return t.sandboxMode??(t.approvalMode==="guarded"?"workspace-write":"danger-full-access")}function Yn(t,a){const n=new Set(a.map(d=>d.id));return[...a,...t.filter(d=>!n.has(d.id))]}function $e(t,a){const n=new Set(a.map(d=>d.id));return[...t.filter(d=>!n.has(d.id)),...a]}function Qn(t,a){return{...t,pendingRequests:[...t.pendingRequests.filter(n=>n.id!==a.id),a]}}function Xn(t,a){const n=t.pendingRequests.filter(d=>d.id!==a);return n.length===t.pendingRequests.length?t:{...t,pendingRequests:n}}function Ja(t,a,n){const d=a.filter(k=>!n.has(k.id)),m=t.filter(k=>!n.has(k.id));if(m.length===0)return d;const h=new Map(d.map(k=>[k.id,k]));return[...m.map(k=>h.get(k.id)??k),...d.filter(k=>!m.some(C=>C.id===k.id))].sort((k,C)=>k.createdAt.localeCompare(C.createdAt))}function eo(t){if(!t||typeof t!="object")return!1;const a=t;return typeof a.id=="string"&&(a.kind==="requestUserInput"||a.kind==="planDecision")&&typeof a.title=="string"&&typeof a.createdAt=="string"&&Array.isArray(a.questions)}function ys(t,a){var h,f;if(!t||t.kind!==a.kind)return a;const n=k=>{let C=k;const j=typeof a.sequence=="number"&&Number.isFinite(a.sequence)?a.sequence:typeof t.sequence=="number"&&Number.isFinite(t.sequence)?t.sequence:null;j!==null&&C.sequence!==j&&(C={...C,sequence:j});const R=typeof a.transcriptOrder=="number"&&Number.isFinite(a.transcriptOrder)?a.transcriptOrder:typeof t.transcriptOrder=="number"&&Number.isFinite(t.transcriptOrder)?t.transcriptOrder:null;return R!==null&&C.transcriptOrder!==R&&(C={...C,transcriptOrder:R}),C};if(t.kind==="agentMessage"&&a.kind==="agentMessage")return n(t.text.length>a.text.length?{...a,text:t.text,sequence:a.sequence??t.sequence??null}:a);const d=((h=t.detailText)==null?void 0:h.trim())||t.text.trim(),m=((f=a.detailText)==null?void 0:f.trim())||a.text.trim();return n(d.length>m.length?t:a)}function to(t,a,n){if(!t||a&&a.turnId!==t.turnId)return a;const d=n.find(w=>w.id===t.turnId),m=new Map((d==null?void 0:d.items.map(w=>[w.id,w]))??[]),h=(d==null?void 0:d.items.filter(w=>w.kind==="agentMessage").map(w=>w.text.trim()).filter(Boolean))??[],f=w=>w.kind==="agentMessage"&&w.text.trim().length>0&&h.some(O=>O.includes(w.text.trim()));if(!a){const w=t.items.filter(O=>{const S=m.get(O.id);return S?S.kind!==O.kind||typeof O.sequence=="number"&&Number.isFinite(O.sequence)&&S.sequence!==O.sequence:!f(O)});return w.length===0?null:{...t,items:w}}const k=new Map(t.items.map(w=>[w.id,w])),C=new Map(a.items.map(w=>[w.id,w])),R=[...t.items.map(w=>w.id),...a.items.map(w=>w.id).filter(w=>!k.has(w))].map(w=>{const O=C.get(w),S=k.get(w);if(!O){const L=m.get(w);return!L&&S&&f(S)||L&&L.kind===(S==null?void 0:S.kind)&&!(S&&typeof S.sequence=="number"&&Number.isFinite(S.sequence)&&L.sequence!==S.sequence)?null:S??null}return ys(S,O)}).filter(w=>!!w);return R.length===0?null:{turnId:a.turnId,items:R,updatedAt:a.updatedAt.localeCompare(t.updatedAt)>=0?a.updatedAt:t.updatedAt}}function Ze(t,a){const n=t.filter(d=>d.id!==a.id);return[a,...n]}function ao(t){return`${t.threadId}:${t.objective}:${t.createdAt}`}function so(t,a){const n=Date.parse(t.updatedAt)||0,m=(Date.parse(a.updatedAt)||0)>=n?a:t,h=m===a?t:a;return{...m,localGoalId:m.localGoalId??h.localGoalId??null}}function ws(t){const a=new Map;for(const n of t){const d=ao(n),m=a.get(d);a.set(d,m?so(m,n):n)}return[...a.values()].sort((n,d)=>Date.parse(d.updatedAt)-Date.parse(n.updatedAt))}function bt(t,a){return ws([a,...t])}function ro(t){const a=new Intl.NumberFormat(void 0,{notation:"compact",maximumFractionDigits:1});return t.tokenBudget===null?`${a.format(t.tokensUsed)} tok`:`${a.format(t.tokensUsed)}/${a.format(t.tokenBudget)} tok`}function no(t){const a=Math.max(0,Math.floor(t/60)),n=Math.floor(a/60),d=a%60;return n>0?`${n}h ${d}m`:`${a}m`}function Ka(t,a){if(!a)return null;const n=t.find(d=>d.model===a);return n?n.supportedReasoningEfforts.length>1:null}function oo(){return typeof crypto<"u"&&typeof crypto.randomUUID=="function"?crypto.randomUUID():`client-${Date.now()}-${Math.random().toString(16).slice(2,10)}`}function Ye(t,a){return(t==null?void 0:t.items.some(n=>n.kind==="userMessage"&&n.text.trim()===a))??!1}function Za(t){return t.replace(/\s*\[PHOTO\s+[^\]]+\]\s*/g," ").replace(/\s+/g," ").trim()}function kt(t,a){const n=Za(a);return n?(t==null?void 0:t.items.some(d=>d.kind==="userMessage"&&Za(d.text)===n))??!1:!1}function Ut(t){return(t==null?void 0:t.items.some(a=>a.kind==="userMessage"&&/\[PHOTO\s+\.\/\.temp\/threads\/[^\]]+\]/.test(a.text)))??!1}function lo(t,a){return t.find(n=>Ye(n,a))??(a.includes("[PHOTO ")?t.find(n=>kt(n,a))??null:null)}function io(t,a,n,d){let m=!1;const h=t.map(f=>f.id!==a?f:(m=!0,{...f,tokenUsage:n,priceEstimate:d}));return m?h:t}const Ya=3,co=10,uo=1e3,mo=2e3,$t=5500,po=3e3,Dt=0,We=1,vt=3,ho=["read-only","workspace-write","danger-full-access"],fo=[],go=[],xo=[],bo={workspace:!0,toolUsage:!1,guide:!1,threadGraph:!1,extensions:!1,defaultTab:"workspace"};function vo(){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 yo(){return e.jsxs("svg",{"aria-hidden":"true",viewBox:"0 0 16 16",className:"h-4 w-4 fill-none stroke-current",strokeWidth:"1.5",strokeLinecap:"round",strokeLinejoin:"round",children:[e.jsx("path",{d:"M4.25 2.25h5.2l2.3 2.3v9.2h-7.5a2 2 0 0 1-2-2v-7.5a2 2 0 0 1 2-2Z"}),e.jsx("path",{d:"M9.25 2.5v2.25h2.25"}),e.jsx("path",{d:"M7 6.75v4"}),e.jsx("path",{d:"m5.45 9.35 1.55 1.55 1.55-1.55"})]})}function yt({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 wo(t,a){if(!t)return"Thread disconnected";switch(a.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 ko(){var Ha;const{id:t=""}=vr(),a=Ae(),n=De(),d=as(),m=o.useRef(""),h=o.useRef(null),f=o.useRef(null),k=o.useRef(null),C=o.useRef(!1),j=o.useRef(null),R=o.useRef(null),w=o.useRef(typeof navigator>"u"?!0:navigator.onLine),O=o.useRef(!1),S=o.useRef(null),L=o.useRef(null),D=o.useRef(0),K=o.useRef(0),ne=o.useRef(null),re=o.useRef(null),ee=o.useRef(null),U=o.useRef(null),ie=o.useRef(new Set),[i,_]=o.useState(null),[se,H]=o.useState([]),[Z,V]=o.useState([]),[T,q]=o.useState(null),[N,W]=o.useState(null),[$,je]=o.useState(null),[be,I]=o.useState(""),[G,Y]=o.useState(null),[de,ue]=o.useState(null),[Nt,St]=o.useState(!0),[Qe,Xe]=o.useState(0),[et,tt]=o.useState(!0),[Me,He]=o.useState(!1),[c,p]=o.useState(!1),[x,M]=o.useState("chat"),te=d.getThreadPanels().some(s=>s.kind==="terminal"),xe=o.useMemo(()=>({fetchState:pn,createShell:gn,terminateShell:xn,updateShell:bn,connectSocket:Hn}),[]),Ie=o.useCallback(s=>`/threads/${s}`,[]),Ne=o.useCallback(s=>{a(`/threads/${s}`)},[a]),at=o.useCallback(s=>s?`/threads/new?workspaceId=${encodeURIComponent(s)}`:"/threads/new",[]),Le=o.useCallback(({threadId:s,path:r})=>`/api/threads/${s}/assets/image?path=${encodeURIComponent(r)}`,[]),[st,Ee]=o.useState({prompt:"",attachments:[]}),[Ve,Ts]=o.useState(!1),[Cs,Is]=o.useState(0),[Es,_t]=o.useState(0),[zt,Rs]=o.useState(0),[Vt,Ps]=o.useState(!1),[B,Gt]=o.useState(null),[Jt,Ge]=o.useState(!1),[Kt,Zt]=o.useState(!1),[Os,Yt]=o.useState(!1),[Qt,Xt]=o.useState(null),[Ue,rt]=o.useState("idle"),[Re,ea]=o.useState({status:w.current?"checking":"offline",browserOnline:w.current,healthOk:!1,socketOpen:!1,lastHealthyAt:null}),[ae,Se]=o.useState(null),[nt,Be]=o.useState([]),[As,ot]=o.useState({status:"idle",data:null,error:null}),[Ms,lt]=o.useState({status:"idle",data:null,error:null}),[Ls,he]=o.useState({status:"idle",data:null,error:null}),[Us,it]=o.useState({status:"idle",data:null,error:null}),[dt,we]=o.useState({status:"idle",data:null,error:null}),[$s,ta]=o.useState(!1),[Tt,ct]=o.useState(!1),[Ds,Hs]=o.useState(()=>new Set),[Bs,ut]=o.useState(!1),[aa,sa]=o.useState(!1),[Fs,mt]=o.useState({status:"idle",data:null,error:null}),[Ce,Ct]=o.useState(null),[ra,na]=o.useState(!1),[qs,Q]=o.useState(null),It=((Ha=$==null?void 0:$.hostConfigFiles.find(s=>{var r;return(r=s.roles)==null?void 0:r.includes("mcp")}))==null?void 0:Ha.name)??null,oa=o.useCallback(()=>{const s=m.current;m.current="",h.current=null,s&&o.startTransition(()=>{I(r=>r+s)})},[]),la=o.useCallback(s=>{m.current+=s,h.current===null&&(h.current=window.requestAnimationFrame(()=>{oa()}))},[oa]),ia=o.useCallback((s,r)=>{ue(l=>{const g=(l==null?void 0:l.turnId)===s?l.items:[],b=g.findIndex(ce=>ce.id===r.id),P=ys(g[b],r),F=b>=0?g.map((ce,y)=>y===b?P:ce):[...g,P];return{turnId:s,items:F,updatedAt:new Date().toISOString()}})},[]),da=o.useCallback((s,r,l,g)=>{ue(b=>{const P=(b==null?void 0:b.turnId)===s?b.items:[],F=P.find(me=>me.id===r),ce=(F==null?void 0:F.kind)==="agentMessage"?{...F,text:`${F.text}${l}`,sequence:g??F.sequence??null}:{id:r,kind:"agentMessage",text:l,sequence:g},y=P.findIndex(me=>me.id===r),ge=y>=0?P.map((me,pe)=>pe===y?ce:me):[...P,ce];return{turnId:s,items:ge,updatedAt:new Date().toISOString()}})},[]),Te=o.useCallback(()=>{m.current="",h.current!==null&&(window.cancelAnimationFrame(h.current),h.current=null)},[]);o.useEffect(()=>{ot({status:"idle",data:null,error:null}),lt({status:"idle",data:null,error:null}),he({status:"idle",data:null,error:null}),it({status:"idle",data:null,error:null}),we({status:"idle",data:null,error:null}),ut(!1),mt({status:"idle",data:null,error:null})},[t]);const Ws=o.useCallback(async()=>{if(t){mt(s=>({status:"loading",data:s.data,error:null}));try{const s=await cn(t);mt({status:"ready",data:s,error:null})}catch(s){const r=s instanceof z?s.payload.message:"Unable to load export turns.";mt(l=>({status:"failed",data:l.data,error:r}))}}},[t]);async function _s(s){if(t){Q(null),sa(!0);try{const{blob:r,filename:l}=await mn(t,s),g=URL.createObjectURL(r),b=document.createElement("a");b.href=g,b.download=l,document.body.append(b),b.click(),b.remove(),window.setTimeout(()=>URL.revokeObjectURL(g),3e4),ut(!1)}catch(r){const l=r instanceof z?r.payload.message:"Unable to export transcript.";Q(l)}finally{sa(!1)}}}async function ca(){if(t){we(s=>{var r;return{status:"loading",data:s.data??((r=ee.current)==null?void 0:r.goal)??null,error:null}});try{const s=await jn(t);we({status:"ready",data:s.goal,error:null}),_(r=>r&&(s.goal?{...r,goal:s.goal,goalHistory:bt(r.goalHistory??[],s.goal)}:{...r,goal:s.goal}))}catch(s){we(r=>({status:"failed",data:r.data,error:s instanceof z?s.payload.message:"Unable to load goal."}))}}}async function ua(s){if(t){we(r=>{var l;return{status:"loading",data:r.data??((l=ee.current)==null?void 0:l.goal)??null,error:null}});try{const r=await Nn(t,s);we({status:"ready",data:r.goal,error:null}),_(l=>l&&(r.goal?{...l,goal:r.goal,goalHistory:bt(l.goalHistory??[],r.goal)}:{...l,goal:r.goal}))}catch(r){throw we(l=>({status:"failed",data:l.data,error:r instanceof z?r.payload.message:"Unable to update goal."})),r}}}async function zs(){if(t){we(s=>{var r;return{status:"loading",data:s.data??((r=ee.current)==null?void 0:r.goal)??null,error:null}});try{const s=await Sn(t);we({status:"ready",data:null,error:null}),_(r=>r&&(s.goalHistory?{...r,goal:null,goalHistory:s.goalHistory}:{...r,goal:null}))}catch(s){throw we(r=>({status:"failed",data:r.data,error:s instanceof z?s.payload.message:"Unable to clear goal."})),s}}}async function ma(s){ct(!0);try{await ua({status:s})}finally{ct(!1)}}async function Vs(){ct(!0);try{await zs()}finally{ct(!1)}}async function Gs(){if(t){ot(s=>({status:"loading",data:s.data,error:null}));try{const s=await Cn(t);ot({status:"ready",data:s,error:null})}catch(s){ot(r=>({status:"failed",data:r.data,error:s instanceof z?s.payload.message:"Unable to load skills."}))}}}async function Js(){if(t){lt(s=>({status:"loading",data:s.data,error:null}));try{const s=await In(t);lt({status:"ready",data:s,error:null})}catch(s){lt(r=>({status:"failed",data:r.data,error:s instanceof z?s.payload.message:"Unable to load MCP servers."}))}}}async function Ks(){if(t){he(s=>({status:"loading",data:s.data,error:null}));try{const s=await En(t);he({status:"ready",data:s,error:null})}catch(s){he(r=>({status:"failed",data:r.data,error:s instanceof z?s.payload.message:"Unable to load hooks."}))}}}async function Zs(s){if(t){he(r=>({status:"loading",data:r.data,error:null}));try{const r=await Rn(t,s);he({status:"ready",data:r,error:null})}catch(r){throw he(l=>({status:"failed",data:l.data,error:r instanceof z?r.payload.message:"Unable to create hook."})),r}}}async function Ys(s){if(t){he(r=>({status:"loading",data:r.data,error:null}));try{const r=await Pn(t,s);he({status:"ready",data:r,error:null})}catch(r){throw he(l=>({status:"failed",data:l.data,error:r instanceof z?r.payload.message:"Unable to update hook."})),r}}}async function Qs(s){if(t){he(r=>({status:"loading",data:r.data,error:null}));try{const r=await On(t,s);he({status:"ready",data:r,error:null})}catch(r){throw he(l=>({status:"failed",data:l.data,error:r instanceof z?r.payload.message:"Unable to trust hook."})),r}}}async function Xs(s){if(t){he(r=>({status:"loading",data:r.data,error:null}));try{const r=await An(t,s);he({status:"ready",data:r,error:null})}catch(r){throw he(l=>({status:"failed",data:l.data,error:r instanceof z?r.payload.message:"Unable to untrust hook."})),r}}}async function er(){if(t){it(s=>({status:"loading",data:s.data,error:null}));try{const s=await Tn(t);it({status:"ready",data:s,error:null})}catch(s){it(r=>({status:"failed",data:r.data,error:s instanceof z?s.payload.message:"Unable to load turns for forking."}))}}}async function tr(){if(!t)return;const s=await Va(t,{mode:"latest"});H(r=>Ze(r,s.thread.thread)),a(`/threads/${s.thread.thread.id}`)}async function ar(s){if(!t)return;const r=await Va(t,{mode:"turn",turnId:s});H(l=>Ze(l,r.thread.thread)),a(`/threads/${r.thread.thread.id}`)}const pa=o.useCallback(s=>{const r=U.current,l=r&&Object.keys(r).length>0?{...s,thread:{...s.thread,...r}}:s,g=ee.current;ee.current=l,Y(l.livePlan??null);const b=g?$e(g.turns,l.turns):l.turns;ue(y=>to(y,l.liveItems??null,b)),we(y=>y.status==="idle"?y:{...y,data:l.goal??null});const P=l.thread.activeTurnId===null&&l.thread.status!=="running";_(y=>y&&!l.goalHistory?{...l,turns:$e(y.turns,l.turns),pendingRequests:Ja(y.pendingRequests,l.pendingRequests,ie.current),...y.goalHistory?{goalHistory:y.goalHistory}:{}}:y?{...l,turns:$e(y.turns,l.turns),pendingRequests:Ja(y.pendingRequests,l.pendingRequests,ie.current)}:l),H(y=>Ze(y,l.thread));const F=new Map(l.turns.map(y=>[y.id,y])),ce=new Set((l.pendingSteers??[]).map(y=>y.clientRequestId).filter(y=>!!y));Be(y=>y.filter(ge=>{if(ce.has(ge.clientRequestId))return!1;const me=F.get(ge.turnId);return!(!me||Ye(me,ge.prompt)||l.thread.activeTurnId!==ge.turnId&&me.status!=="inProgress")})),Se(y=>{if(!y)return y;const ge=y.serverTurnId??y.id,me=l.turns.some(v=>v.id===ge),pe=F.get(ge)??null,X=lo(l.turns,y.prompt),u=!!X;if(X&&!y.serverTurnId)return{...y,id:X.id,serverTurnId:X.id,status:y.status==="failed"?y.status:X.status==="inProgress"?"inProgress":y.status};if(pe&&y.serverTurnId)return Ye(pe,y.prompt)||y.prompt.includes("[PHOTO ")&&(kt(pe,y.prompt)||Ut(pe))?pe.status==="inProgress"?{...y,id:pe.id,serverTurnId:pe.id,status:y.status==="failed"?y.status:"inProgress"}:null:{...y,id:pe.id,serverTurnId:pe.id,status:y.status==="failed"?y.status:"inProgress"};if(!y.serverTurnId&&y.prompt.includes("[PHOTO ")&&l.thread.activeTurnId&&l.thread.status==="running"){const v=F.get(l.thread.activeTurnId);if(v&&Ut(v))return{...y,id:v.id,serverTurnId:v.id,status:y.status==="failed"?y.status:"inProgress"}}return me||P&&u?null:y}),(P||re.current&&l.turns.some(y=>y.id===re.current))&&(re.current=null,Te(),I(""),Y(null),ue(null))},[Te]);o.useEffect(()=>{ee.current=i},[i]);const ha=o.useCallback(async({seedThread:s}={})=>{var F;const r=K.current+1;K.current=r;const l=(s==null?void 0:s.provider)??((F=ee.current)==null?void 0:F.thread.provider)??"codex",[g,b,P]=await Promise.allSettled([ps(),cs(l),Ht(l)]);K.current===r&&(g.status==="fulfilled"?H(s?Ze(g.value,s):g.value):s&&H(ce=>Ze(ce,s)),b.status==="fulfilled"&&(ne.current=l,q(b.value.status),W(b.value.capabilities),je(b.value.managementSchema)),P.status==="fulfilled"&&(ne.current=l,V(P.value)))},[]),Fe=o.useCallback(async({showLoading:s=!0,clearError:r=!0,reportError:l=!0,limit:g=Ya}={})=>{const b=D.current+1;D.current=b,s&&tt(!0),r&&Q(null);try{const P=await Wa(t,{limit:g});if(D.current!==b)return;pa(P),ne.current!==P.thread.provider&&ha({seedThread:P.thread})}catch(P){if(D.current!==b||!l)return;Q(P instanceof Error?P.message:"Unable to load thread detail.")}finally{D.current===b&&tt(!1)}},[pa,t,ha]),fe=o.useCallback(()=>{var ce;const s=((ce=f.current)==null?void 0:ce.readyState)??vt,r=s===We,l=w.current,g=Date.now(),b=j.current!==null&&g-Date.parse(j.current)<=$t,P=R.current!==null&&g-R.current<=$t;let F;l?r&&P?F="connected":s===Dt||k.current!==null||b||P||C.current?F="reconnecting":F="checking":F="offline",ea(y=>y.status===F&&y.browserOnline===l&&y.healthOk===b&&y.socketOpen===r&&y.lastHealthyAt===j.current?y:{status:F,browserOnline:l,healthOk:b,socketOpen:r,lastHealthyAt:j.current})},[]);o.useEffect(()=>{D.current+=1,K.current+=1,_(null),Ee({prompt:"",attachments:[]}),He(!1),rt("idle"),Se(null),Be([]),ue(null),U.current=null,re.current=null,ie.current=new Set,j.current=null,R.current=null,O.current=!1,w.current=typeof navigator>"u"?!0:navigator.onLine,ea({status:w.current?"checking":"offline",browserOnline:w.current,healthOk:!1,socketOpen:!1,lastHealthyAt:null})},[t]),o.useEffect(()=>{if(Ue==="idle")return;const s=window.setTimeout(()=>{rt("idle")},Ue==="copied"?1200:1600);return()=>{window.clearTimeout(s)}},[Ue]),o.useEffect(()=>{if(typeof document>"u")return;const{documentElement:s,body:r}=document;return s.classList.add("thread-detail-scroll-locked"),r.classList.add("thread-detail-scroll-locked"),()=>{s.classList.remove("thread-detail-scroll-locked"),r.classList.remove("thread-detail-scroll-locked")}},[]),o.useEffect(()=>{if(typeof window>"u"||typeof window.matchMedia!="function")return;const s=window.matchMedia("(max-width: 639px)"),r=()=>Ts(s.matches);return r(),s.addEventListener("change",r),()=>{s.removeEventListener("change",r)}},[]),o.useEffect(()=>{var r,l;if(typeof window>"u")return;const s=()=>{const g=window.visualViewport,b=g?Math.max(0,Math.round(window.innerHeight-g.height-g.offsetTop)):0;Rs(b),document.documentElement.style.setProperty("--thread-detail-keyboard-inset",`${b}px`)};return s(),(r=window.visualViewport)==null||r.addEventListener("resize",s),(l=window.visualViewport)==null||l.addEventListener("scroll",s),window.addEventListener("resize",s),()=>{var g,b;(g=window.visualViewport)==null||g.removeEventListener("resize",s),(b=window.visualViewport)==null||b.removeEventListener("scroll",s),window.removeEventListener("resize",s),document.documentElement.style.removeProperty("--thread-detail-keyboard-inset")}},[]),o.useEffect(()=>{if(typeof document>"u")return;const s=()=>{const r=document.activeElement,l=L.current,g=l==null?void 0:l.querySelector('[aria-label="Prompt"]');Ps(!!(r&&g&&(r===g||g.contains(r))))};return s(),document.addEventListener("focusin",s),document.addEventListener("focusout",s),()=>{document.removeEventListener("focusin",s),document.removeEventListener("focusout",s)}},[x,i==null?void 0:i.thread.id,Ve]),o.useEffect(()=>{const s=L.current;if(!s||typeof ResizeObserver>"u")return;const r=s.querySelector("form")??s,l=()=>{Is(Math.max(s.getBoundingClientRect().height,r.getBoundingClientRect().height))};l();const g=new ResizeObserver(()=>{l()});return g.observe(r),()=>{g.disconnect()}},[x,Ve]),o.useEffect(()=>{var g,b;const s=L.current;if(!s||!Ve||x!=="chat"){_t(0);return}const r=()=>{const P=s.getBoundingClientRect();_t(Math.max(0,Math.ceil(window.innerHeight-P.top)))};r(),window.addEventListener("resize",r),(g=window.visualViewport)==null||g.addEventListener("resize",r),(b=window.visualViewport)==null||b.addEventListener("scroll",r);let l=null;return typeof ResizeObserver<"u"&&(l=new ResizeObserver(r),l.observe(s)),()=>{var P,F;window.removeEventListener("resize",r),(P=window.visualViewport)==null||P.removeEventListener("resize",r),(F=window.visualViewport)==null||F.removeEventListener("scroll",r),l==null||l.disconnect()}},[x,i==null?void 0:i.thread.id,Ve,zt,Vt]),o.useEffect(()=>{Fe({showLoading:!0,limit:Ya})},[Fe]),o.useEffect(()=>{let s=!1,r=null;const l=()=>{Fe({showLoading:!1,clearError:!1,reportError:!1})},g=()=>{k.current!==null&&(window.clearTimeout(k.current),k.current=null)},b=()=>{s||!w.current||k.current!==null||(k.current=window.setTimeout(()=>{k.current=null,!s&&y()},uo),fe())},P=()=>{const u=f.current;if(f.current=null,u)try{u.close()}catch{}},F=u=>{if(u.threadId===t){if(u.type==="thread.output.delta"&&typeof u.payload.delta=="string"){const v=typeof u.payload.turnId=="string"?u.payload.turnId:null,A=typeof u.payload.itemId=="string"?u.payload.itemId:null,oe=typeof u.payload.sequence=="number"&&Number.isFinite(u.payload.sequence)?u.payload.sequence:null;v&&A?da(v,A,u.payload.delta,oe):la(u.payload.delta),v&&Se(J=>J&&(J.serverTurnId===null||J.serverTurnId===v)?{...J,serverTurnId:v,id:v,status:J.status==="failed"?J.status:"inProgress",tokenUsage:J.tokenUsage}:J)}if(u.type==="thread.context.updated"){const v=u.payload.contextUsage&&typeof u.payload.contextUsage=="object"?u.payload.contextUsage:null;if(v){const A=v;_(oe=>oe&&{...oe,thread:{...oe.thread,contextUsage:A}}),H(oe=>oe.map(J=>J.id===t?{...J,contextUsage:A}:J))}}if(u.type==="thread.turn.token.updated"&&typeof u.payload.turnId=="string"&&u.payload.tokenUsage&&typeof u.payload.tokenUsage=="object"){const v=u.payload.turnId,A=u.payload.tokenUsage,oe=u.payload.priceEstimate&&typeof u.payload.priceEstimate=="object"?u.payload.priceEstimate:null;_(J=>{if(!J)return J;const ve=io(J.turns,v,A,oe);return ve===J.turns?J:{...J,turns:ve}}),Se(J=>J&&(J.serverTurnId===v||J.id===v)?{...J,tokenUsage:A,priceEstimate:oe}:J)}if(u.type==="thread.turn.started"||u.type==="thread.turn.completed"||u.type==="thread.turn.failed"||u.type==="thread.updated"||u.type==="thread.goal.updated"||u.type==="thread.goal.cleared"||u.type==="thread.request.created"||u.type==="thread.request.resolved"){if(u.type==="thread.goal.updated"){const v=u.payload.goal&&typeof u.payload.goal=="object"?u.payload.goal:null,A=Array.isArray(u.payload.goalHistory)?u.payload.goalHistory:null;we({status:"ready",data:v,error:null}),_(oe=>oe&&(A?{...oe,goal:v,goalHistory:A}:v?{...oe,goal:v,goalHistory:bt(oe.goalHistory??[],v)}:{...oe,goal:v}))}if(u.type==="thread.goal.cleared"){const v=Array.isArray(u.payload.goalHistory)?u.payload.goalHistory:null;we({status:"ready",data:null,error:null}),_(A=>A&&(v?{...A,goal:null,goalHistory:v}:{...A,goal:null}))}if(l(),u.type==="thread.turn.started"){Te(),I(""),ue(null),re.current=null;const v=typeof u.payload.turnId=="string"?u.payload.turnId:null;v&&Se(A=>A&&{...A,serverTurnId:v,id:v,status:A.status==="failed"?A.status:"inProgress",error:null,tokenUsage:A.tokenUsage})}if(u.type==="thread.turn.completed"||u.type==="thread.turn.failed"){Te(),I("");const v=typeof u.payload.turnId=="string"?u.payload.turnId:null;v&&(re.current=v,u.type==="thread.turn.failed"&&Se(A=>A&&(A.serverTurnId===v||A.id===v)?{...A,status:"failed",error:typeof u.payload.error=="string"?u.payload.error:"Unable to complete the turn.",tokenUsage:A.tokenUsage}:A))}}if(u.type==="thread.request.created"&&eo(u.payload.request)&&(ie.current.delete(u.payload.request.id),_(v=>v&&Qn(v,u.payload.request))),u.type==="thread.request.resolved"&&typeof u.payload.requestId=="string"){const v=u.payload.requestId;ie.current.add(v),_(A=>A&&Xn(A,v))}if((u.type==="thread.item.started"||u.type==="thread.item.completed")&&u.payload.item&&typeof u.payload.item=="object"&&typeof u.payload.turnId=="string"){const v=u.payload.turnId,A=u.payload.item;typeof A.id=="string"&&typeof A.text=="string"&&ia(v,A)}u.type==="thread.plan.updated"&&Array.isArray(u.payload.plan)&&Y({turnId:String(u.payload.turnId??""),explanation:typeof u.payload.explanation=="string"?u.payload.explanation:null,plan:u.payload.plan})}},ce=()=>{const u=f.current;if(!(!u||u.readyState!==We))try{u.send(JSON.stringify({type:"supervisor.ping",timestamp:new Date().toISOString()}))}catch{O.current=!0,P(),b(),fe()}},y=()=>{var A;if(s||!w.current){fe();return}const u=((A=f.current)==null?void 0:A.readyState)??vt;if(u===Dt||u===We){fe();return}const v=gs(F);f.current=v,fe(),v.addEventListener("message",oe=>{if(f.current===v)try{const J=JSON.parse(oe.data);(J.type==="supervisor.connected"||J.type==="supervisor.pong")&&(R.current=Date.now(),fe())}catch{}}),v.addEventListener("open",()=>{f.current===v&&(O.current=!0,l(),ce(),fe())}),v.addEventListener("close",()=>{f.current===v&&(f.current=null),O.current=!0,b(),fe()}),v.addEventListener("error",()=>{f.current===v&&(f.current=null),O.current=!0,b(),fe()})},ge=async()=>{var u;if(!(s||!w.current||C.current)){C.current=!0,fe();try{await Xr();const v=O.current;j.current=new Date().toISOString(),v&&(O.current=!1,l()),(((u=f.current)==null?void 0:u.readyState)??vt)!==We&&y()}catch{j.current=null,O.current=!0,b()}finally{C.current=!1,fe()}}},me=()=>{w.current=!0,O.current=!0,fe(),y(),ge()},pe=()=>{w.current=!1,j.current=null,R.current=null,O.current=!0,g(),P(),fe()},X=()=>{var A;if(s||!w.current){fe();return}const u=((A=f.current)==null?void 0:A.readyState)??vt,v=R.current===null?null:Date.now()-R.current;u===We&&v!==null&&v>$t?(O.current=!0,P(),b()):u===We?ce():u!==Dt&&y(),ge(),fe()};return window.addEventListener("online",me),window.addEventListener("offline",pe),y(),ge(),r=window.setInterval(X,mo),()=>{s=!0,window.removeEventListener("online",me),window.removeEventListener("offline",pe),g(),r!==null&&window.clearInterval(r),Te(),P()}},[da,Te,t,Fe,la,fe,ia]),o.useEffect(()=>{if(!((i==null?void 0:i.thread.activeTurnId)!==null||(i==null?void 0:i.thread.status)==="running"||ae!==null||nt.length>0||be.length>0||G!==null||de!==null))return;const r=window.setInterval(()=>{Fe({showLoading:!1,clearError:!1,reportError:!1})},po);return()=>{window.clearInterval(r)}},[i==null?void 0:i.thread.activeTurnId,i==null?void 0:i.thread.status,be.length,de,G,Fe,nt.length,ae]);const fa=o.useCallback(async()=>{var s;if(!(!i||i.turns.length===0||Me)){He(!0),Q(null);try{const r=(s=i.turns[0])==null?void 0:s.id,l=await Wa(t,{limit:co,...r?{beforeTurnId:r}:{}});_(g=>g?{...l,turns:Yn(g.turns,l.turns)}:l),H(g=>g.map(b=>b.id===l.thread.id?l.thread:b))}catch(r){Q(r instanceof Error?r.message:"Unable to load earlier turns.")}finally{He(!1)}}},[i,t,Me]);async function ga(s){var ge,me,pe;if(x==="shell"){if((i==null?void 0:i.thread.isLoaded)===!1)return await Et({attachShell:!0}),!1;let X=!1;if((B==null?void 0:B.shellInputEnabled)!==!0&&((B==null?void 0:B.loading)===!1&&(B==null?void 0:B.isConnecting)!==!0&&(B==null?void 0:B.status)!=="creating"&&(B==null?void 0:B.status)!=="workspace_missing"&&(await((ge=S.current)==null?void 0:ge.toggleConnection()),X=!0),(B==null?void 0:B.isConnecting)===!0))return Q("Connecting to the shell. Try again after it attaches."),!1;if(((me=S.current)==null?void 0:me.sendCommand(s.prompt))??!1)Q(null);else return Q(X?"Shell is still attaching. Try again after it connects.":"Connect the shell before sending commands."),!1;return!0}p(!0),Q(null),Xe(X=>X+1);const r=ee.current,l=r?{...r.thread,...U.current??{}}:null,g=(l==null?void 0:l.model)??null,b=(l==null?void 0:l.reasoningEffort)??null,P=oo(),F=`optimistic-${Date.now()}`,ce=`optimistic-steer-${P}`,y=new Date().toISOString();try{let X=ee.current;if(X&&!X.thread.isLoaded){const le={...X.thread,...U.current??{}},ke=await _a(t,{...X.thread.model?{model:X.thread.model}:{},...X.thread.sandboxMode?{sandboxMode:X.thread.sandboxMode}:{}}),ye={...ke,thread:{...ke.thread,model:le.model??ke.thread.model,reasoningEffort:le.reasoningEffort??ke.thread.reasoningEffort,collaborationMode:le.collaborationMode??ke.thread.collaborationMode,sandboxMode:le.sandboxMode??ke.thread.sandboxMode??null}};X=ye,ee.current=ye,_(xt=>xt?{...ye,turns:$e(xt.turns,ye.turns)}:ye),H(xt=>xt.map(Ba=>Ba.id===ye.thread.id?ye.thread:Ba))}const u=X?{...X.thread,...U.current??{}}:null,v=(u==null?void 0:u.status)==="running"?u.activeTurnId:null,A=x==="chat"&&!!v;A&&v?Be(le=>[...le,{id:ce,clientRequestId:P,turnId:v,prompt:s.prompt,createdAt:y,status:"steering"}]):(Te(),I(""),Se({id:F,serverTurnId:null,startedAt:y,status:"sending",error:null,prompt:s.prompt,model:g,reasoningEffort:b,reasoningEffortAvailable:Ka(Z,g),tokenUsage:null,priceEstimate:null}));const oe={prompt:s.prompt,clientRequestId:P,...u!=null&&u.model?{model:u.model}:{},...u!=null&&u.reasoningEffort?{reasoningEffort:u.reasoningEffort}:{},...u!=null&&u.collaborationMode?{collaborationMode:u.collaborationMode}:{},...u!=null&&u.sandboxMode?{sandboxMode:u.sandboxMode}:{},...(pe=s.attachments)!=null&&pe.length?{attachments:s.attachments}:{}},J=await yn(t,oe),ve=U.current&&Object.keys(U.current).length>0?{...J,...U.current}:J;_(le=>le&&{...le,thread:ve}),H(le=>le.map(ke=>ke.id===ve.id?ve:ke)),A&&v?ve.activeTurnId!==null&&ve.activeTurnId!==v&&ve.lastTurnStartedAt!==(u==null?void 0:u.lastTurnStartedAt)?(Te(),I(""),Y(null),Be(ke=>ke.filter(ye=>ye.id!==ce)),Se({id:F,serverTurnId:ve.activeTurnId,startedAt:ve.lastTurnStartedAt??y,status:"inProgress",error:null,prompt:s.prompt,model:g,reasoningEffort:b,reasoningEffortAvailable:Ka(Z,g),tokenUsage:null,priceEstimate:null})):Be(ke=>ke.map(ye=>ye.id===ce?{...ye,turnId:ve.activeTurnId??ye.turnId,status:"accepted"}:ye)):(Se(le=>le&&le.id===F?{...le,id:ve.activeTurnId??le.id,serverTurnId:ve.activeTurnId??le.serverTurnId,status:"inProgress",error:null,tokenUsage:le.tokenUsage,priceEstimate:le.priceEstimate}:le),Y(null)),Ee({prompt:"",attachments:[]})}catch(X){const u=X instanceof z?X.payload.message:X instanceof Error?X.message:"Unable to send prompt.";X instanceof z?Q(X.payload.message):Q(u),Be(v=>v.filter(A=>A.clientRequestId!==P)),Se(v=>v&&v.id===F?{...v,status:"failed",error:u}:v)}finally{p(!1)}}async function sr(){const s=i==null?void 0:i.thread.providerSessionId;if(s)try{await navigator.clipboard.writeText(s),rt("copied")}catch{rt("failed")}}async function Et(s){if(i){p(!0),Q(null),Te(),I("");try{if(i.thread.isLoaded){const l=await vn(t);_(g=>g?{...l,turns:$e(g.turns,l.turns)}:l),Gt(null),H(g=>g.map(b=>b.id===l.thread.id?l.thread:b)),Ge(!1);return}const r=await _a(t,{...i.thread.model?{model:i.thread.model}:{},...i.thread.sandboxMode?{sandboxMode:i.thread.sandboxMode}:{}});_(l=>l?{...r,turns:$e(l.turns,r.turns)}:r),H(l=>l.map(g=>g.id===r.thread.id?r.thread:g)),s!=null&&s.attachShell&&x==="shell"&&Ge(!0)}catch(r){Q(r instanceof Error?r.message:"Unable to change connection state.")}finally{p(!1)}}}async function pt(){var s;if(x==="shell"){const r=((s=S.current)==null?void 0:s.sendControl("ctrl_c"))??!1;Q(r?null:"Connect the shell before sending Ctrl-C.");return}p(!0),Q(null);try{const r=i!=null&&i.thread.activeTurnId?await za(t,{turnId:i.thread.activeTurnId}):await za(t);_(l=>l&&{...l,thread:r}),H(l=>l.map(g=>g.id===r.id?r:g)),Te(),I("")}catch(r){Q(r instanceof Error?r.message:"Unable to interrupt turn.")}finally{p(!1)}}async function ht(s){if(!i)return;const r=i,l={...U.current??{},...s.model!==void 0?{model:s.model}:{},...s.reasoningEffort!==void 0?{reasoningEffort:s.reasoningEffort}:{},...s.fastMode!==void 0?{fastMode:s.fastMode}:{},...s.collaborationMode!==void 0?{collaborationMode:s.collaborationMode}:{},...s.sandboxMode!==void 0?{sandboxMode:s.sandboxMode}:{}},g={...i.thread,...l};Zt(!0),U.current=l,ee.current={...i,thread:g},_(b=>b&&{...b,thread:g}),H(b=>b.map(P=>P.id===g.id?{...P,...g}:P));try{const b=await wn(t,{...s.model!==void 0?{model:s.model}:{},...s.reasoningEffort!==void 0?{reasoningEffort:s.reasoningEffort}:{},...s.fastMode!==void 0?{fastMode:s.fastMode}:{},...s.collaborationMode!==void 0?{collaborationMode:s.collaborationMode}:{},...s.sandboxMode!==void 0?{sandboxMode:s.sandboxMode}:{}});U.current=null,ee.current=r?{...r,thread:b}:null,_(P=>P&&{...P,thread:b}),H(P=>P.map(F=>F.id===b.id?b:F))}catch(b){U.current=null,ee.current=r,_(r),H(P=>P.map(F=>F.id===r.thread.id?r.thread:F)),Q(b instanceof Error?b.message:"Unable to update thread settings.")}finally{Zt(!1)}}const xa=o.useCallback(async(s,r)=>{Xt(s),Q(null);try{const l=await Mn(t,s,r);_(g=>g?{...l,turns:$e(g.turns,l.turns)}:l),Y(l.livePlan??null),ue(l.liveItems??null)}catch(l){Q(l instanceof Error?l.message:"Unable to answer this request.")}finally{Xt(null)}},[t]),ba=o.useCallback(s=>nn(t,s),[t]);async function Rt(){if(i){Yt(!0),Q(null);try{const s=await kn(t);_(r=>r&&{...r,thread:s}),H(r=>r.map(l=>l.id===s.id?s:l))}catch(s){Q(s instanceof Error?s.message:"Unable to compact this thread context.")}finally{Yt(!1)}}}async function va(s,r){try{const l=await hs(s,{title:r});H(g=>g.map(b=>b.id===l.id?{...b,title:l.title,updatedAt:l.updatedAt}:b)),_(g=>g&&g.thread.id===l.id?{...g,thread:{...g.thread,title:l.title,updatedAt:l.updatedAt}}:g)}catch(l){throw Q(l instanceof Error?l.message:"Unable to rename thread."),l}}async function rr(){if(Ce){na(!0),Q(null);try{await fs(Ce.id),H(r=>r.filter(l=>l.id!==Ce.id));const s=Ce.id===(i==null?void 0:i.thread.id);if(Ct(null),s){const r=se.find(l=>l.id!==Ce.id&&l.workspaceId===(i==null?void 0:i.thread.workspaceId))??se.find(l=>l.id!==Ce.id);a(r?`/threads/${r.id}`:"/threads")}}catch(s){Q(s instanceof Error?s.message:"Unable to delete thread.")}finally{na(!1)}}}function ya(){M(s=>s==="chat"?(i!=null&&i.thread.isLoaded&&Ge(!0),"shell"):"chat")}async function wa(){var r;const s=await((r=S.current)==null?void 0:r.copyLastCommandOutput());Q(s?null:"Unable to copy the last shell command output.")}function ka(s){var l,g;const r=s==="clear"?((l=S.current)==null?void 0:l.sendCommand("clear"))??!1:((g=S.current)==null?void 0:g.sendControl(s))??!1;Q(r?null:"Connect the shell before sending control input.")}o.useEffect(()=>{if(!(!Jt||x!=="shell"||!S.current||(i==null?void 0:i.thread.isLoaded)===!1||(B==null?void 0:B.loading)!==!1)){if((B==null?void 0:B.status)==="attached"){Ge(!1);return}Ge(!1),S.current.toggleConnection()}},[x,i==null?void 0:i.thread.isLoaded,Jt,B==null?void 0:B.loading,B==null?void 0:B.status]),o.useEffect(()=>{if(x!=="shell")return;const s=window.requestAnimationFrame(()=>{var r;(r=S.current)==null||r.refreshLayout({syncBackendSize:!1})});return()=>{window.cancelAnimationFrame(s)}},[x]);const Pt=i&&i.workspacePathStatus==="missing"?"Restore this workspace path on the current machine before continuing.":null,Ot=Ve&&x==="chat",ja=Ot&&Vt?zt:0,nr=Math.max(Cs,144),or=Math.max(Es,nr+ja),Na=Ot?or+12:0,lr=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:Ue==="copied"?"Copied":Ue==="failed"?"Copy failed":"Copy session ID",onClick:()=>void sr(),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 shadow-stone-950/25 backdrop-blur transition ${Ue==="copied"?"ui-status-info":Ue==="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(vo,{})})})]}),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==="local_codex_import"?`Imported local ${i.thread.provider} session`:`${i.thread.provider} supervisor thread`})]}),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:Cr(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:At(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,ir=i&&(N!=null&&N.controls.sandboxMode)?e.jsx("div",{className:"space-y-3",children:e.jsxs("div",{children:[e.jsx("p",{className:"text-xs uppercase tracking-[0.2em] text-[var(--theme-fg-muted)]",children:"Sandbox Mode"}),e.jsx("div",{className:"mt-2 space-y-1.5",children:ho.map(s=>{const r=Zn(i.thread)===s;return e.jsx("button",{type:"button",disabled:Kt,onClick:()=>void ht({sandboxMode:s}),className:`block w-full rounded-xl border px-3 py-2 text-left text-sm transition ${r?"ui-status-warning":"border-[var(--theme-border)] bg-[var(--theme-surface-strong)] text-[var(--theme-fg-soft)] hover:bg-[var(--theme-hover)] hover:text-[var(--theme-fg)]"} disabled:cursor-not-allowed disabled:opacity-60`,children:s},s)})})]})}):null,Sa=(ae==null?void 0:ae.serverTurnId)??null,Ta=ae&&i?i.turns.find(s=>(Ye(s,ae.prompt)||ae.prompt.includes("[PHOTO ")&&(kt(s,ae.prompt)||Ut(s)))&&(Sa&&s.id===Sa||s.id===ae.id||Ye(s,ae.prompt)||ae.prompt.includes("[PHOTO ")&&kt(s,ae.prompt)))??null:null,Ca=o.useMemo(()=>ae&&!Ta?{id:ae.id,startedAt:ae.startedAt,status:ae.status,error:ae.error,model:ae.model,reasoningEffort:ae.reasoningEffort,reasoningEffortAvailable:ae.reasoningEffortAvailable,tokenUsage:ae.tokenUsage,priceEstimate:ae.priceEstimate,items:[{id:`${ae.id}-user-message`,kind:"userMessage",text:ae.prompt}]}:null,[Ta,ae]),Je=(i==null?void 0:i.thread.isLoaded)??!1,ft=Je?Re.status==="connected"?"ui-action-success shadow-lg shadow-stone-950/20":Re.status==="reconnecting"?"thread-live-connection-reconnecting ui-status-success shadow-lg shadow-stone-950/20":Re.status==="offline"?"ui-status-danger shadow-lg shadow-stone-950/20":"ui-status-warning shadow-lg shadow-stone-950/20":"host-icon-button border shadow-lg shadow-black/10",Ia=wo(Je,Re),gt=[Ia,Je?null:"Tap to connect this thread",Re.lastHealthyAt?`Last healthy ${At(Re.lastHealthyAt)}`:null].filter(Boolean).join(" · "),dr=Je?e.jsx("div",{role:"status","aria-live":"polite","aria-label":Ia,title:gt,className:`inline-flex h-8 w-8 shrink-0 items-center justify-center rounded-full transition ${ft}`,children:e.jsx(yt,{status:Re.status})}):e.jsx("button",{type:"button",onClick:()=>void Et(),disabled:c||!i,"aria-label":c?"Connecting thread":"Connect thread",title:c?"Connecting thread":gt,className:`inline-flex h-8 w-8 shrink-0 items-center justify-center rounded-full transition ${ft}`,children:e.jsx(yt,{status:"detached"})}),cr=Je?e.jsx("div",{title:gt,className:`hidden lg:inline-flex h-9 w-9 items-center justify-center rounded-full transition ${ft}`,children:e.jsx(yt,{status:Re.status})}):e.jsx("button",{type:"button",onClick:()=>void Et(),disabled:c||!i,title:c?"Connecting thread":gt,className:`hidden lg:inline-flex h-9 w-9 items-center justify-center rounded-full transition ${ft}`,children:e.jsx(yt,{status:"detached"})}),Ea=dt.data??(i==null?void 0:i.goal)??null,Ra=(i==null?void 0:i.goalHistory)??[],Pa=Ea?bt(Ra,Ea):ws(Ra),Oa=(N==null?void 0:N.controls.goals)??!1,ur=e.jsxs("svg",{"aria-hidden":"true",viewBox:"0 0 16 16",className:"h-4 w-4 fill-none stroke-current",strokeWidth:"1.5",strokeLinecap:"round",strokeLinejoin:"round",children:[e.jsx("circle",{cx:"8",cy:"8",r:"5.5"}),e.jsx("circle",{cx:"8",cy:"8",r:"2"}),e.jsx("path",{d:"M8 1.7v2M8 12.3v2M1.7 8h2M12.3 8h2"})]}),mr=$s&&Oa?e.jsxs("div",{className:"host-dialog w-96 max-w-[calc(100vw-1.5rem)] rounded-3xl border p-3 text-left shadow-2xl shadow-black/20 backdrop-blur-xl",children:[e.jsxs("div",{className:"flex items-center justify-between gap-3",children:[e.jsxs("div",{children:[e.jsx("p",{className:"host-page-title text-sm font-semibold",children:"Goal monitor"}),e.jsx("p",{className:"host-muted text-xs",children:"Current thread only"})]}),e.jsx("button",{type:"button",onClick:()=>ta(!1),className:"host-secondary-button rounded-full border px-2.5 py-1 text-xs transition",children:"Close"})]}),dt.error?e.jsx("p",{className:"host-error mt-3 rounded-2xl border px-3 py-2 text-xs",children:dt.error}):null,e.jsx("div",{className:"mt-3 max-h-[28rem] space-y-2 overflow-auto pr-1",children:Pa.length===0?e.jsx("p",{className:"host-empty-state rounded-2xl border px-3 py-3 text-sm",children:"No goals in this thread yet."}):Pa.map(s=>{const r=`${s.threadId}:${s.objective}:${s.createdAt}`,l=Ds.has(r),g=["active","paused","budgetLimited"].includes(s.status);return e.jsxs("div",{className:`rounded-2xl border px-3 py-3 ${g?"ui-status-info":"host-surface-strong"}`,children:[e.jsxs("div",{className:"flex items-start justify-between gap-3",children:[e.jsx("button",{type:"button",onClick:()=>Hs(b=>{const P=new Set(b);return P.has(r)?P.delete(r):P.add(r),P}),className:"min-w-0 flex-1 text-left",children:e.jsx("p",{className:`text-sm font-medium leading-5 ${l?"":"line-clamp-2"}`,children:s.objective})}),e.jsx("span",{className:"host-muted shrink-0 rounded-full border border-[var(--theme-border)] px-2 py-1 text-[10px] uppercase tracking-[0.14em]",children:s.status})]}),e.jsxs("div",{className:"host-muted mt-2 flex flex-wrap gap-2 text-[11px]",children:[e.jsx("span",{children:no(s.timeUsedSeconds)}),e.jsx("span",{children:ro(s)}),e.jsxs("span",{title:At(s.updatedAt),children:["Updated ",new Date(s.updatedAt).toLocaleTimeString()]})]}),g?e.jsxs("div",{className:"mt-3 flex flex-wrap gap-2",children:[e.jsx("button",{type:"button",disabled:Tt||s.status==="active",onClick:()=>void ma("active"),className:"ui-status-info rounded-full px-3 py-1.5 text-xs transition disabled:cursor-not-allowed disabled:opacity-50",children:"Continue"}),e.jsx("button",{type:"button",disabled:Tt||s.status==="paused",onClick:()=>void ma("paused"),className:"host-secondary-button rounded-full border px-3 py-1.5 text-xs transition disabled:cursor-not-allowed disabled:opacity-50",children:"Pause"}),e.jsx("button",{type:"button",disabled:Tt,onClick:()=>void Vs(),className:"rounded-full border border-[var(--status-danger-border)] px-3 py-1.5 text-xs text-[var(--status-danger-fg)] transition hover:bg-[var(--status-danger-bg)] disabled:cursor-not-allowed disabled:opacity-50",children:"Terminate"})]}):null]},r)})})]}):null,Aa=Oa?e.jsx("button",{type:"button","aria-label":"Open goal monitor",title:"Open goal monitor",onClick:()=>{ta(s=>!s),ca()},className:"ui-status-info inline-flex h-8 w-8 shrink-0 items-center justify-center rounded-full shadow-lg shadow-stone-950/20 transition lg:h-9 lg:w-9",children:ur}):null,Ma=e.jsx("button",{type:"button","aria-label":"Export transcript",title:"Export transcript",onClick:()=>ut(!0),disabled:!i,className:"host-icon-button inline-flex h-8 w-8 shrink-0 items-center justify-center rounded-full border shadow-lg shadow-black/10 transition disabled:cursor-not-allowed disabled:opacity-50 lg:h-9 lg:w-9",children:e.jsx(yo,{})}),pr=e.jsxs("div",{className:"relative flex items-center justify-end gap-1.5",children:[Ma,Aa,dr]}),hr=e.jsxs("div",{className:"flex items-center justify-end gap-2",children:[Ma,Aa,cr]}),fr=o.useMemo(()=>({livePlan:G,liveItems:de,respondingRequestId:Qt,onRespondToRequest:xa,scrollRequestKey:Qe,bottomSpacer:Na,className:"thread-timeline-surface min-h-0 flex-1",onTailVisibilityChange:St,loadingEarlier:Me,onLoadEarlier:fa,onOpenThread:Ne,answeredRequestNotes:(i==null?void 0:i.answeredRequestNotes)??fo,activityNotes:(i==null?void 0:i.activityNotes)??go,pendingSteers:(i==null?void 0:i.pendingSteers)??xo,optimisticSteers:nt,optimisticTurn:Ca}),[i==null?void 0:i.answeredRequestNotes,i==null?void 0:i.activityNotes,i==null?void 0:i.pendingSteers,fa,xa,de,G,Me,Ne,nt,Qt,Qe,Na,Ca]),La=i?{busy:x==="chat"?c:!1,settingsBusy:Kt,error:null,model:i.thread.model,reasoningEffort:i.thread.reasoningEffort,fastMode:i.thread.fastMode??!1,collaborationMode:i.thread.collaborationMode,modelOptions:Z,contextUsage:i.thread.contextUsage,capabilities:N,toolboxItems:($==null?void 0:$.toolboxItems)??[],hookCommandTemplates:($==null?void 0:$.hookCommandTemplates)??[],mcpConfigFormat:($==null?void 0:$.mcpConfigFormat)??"none",followTail:Nt,threadConnected:i.thread.isLoaded,shellAvailable:te,disabled:!!Pt,...Pt?{disabledPlaceholder:Pt}:{},shellControlState:B,draftPrompt:st.prompt,draftAttachments:st.attachments,onDraftChange:Ee,canInterrupt:!!i.thread.activeTurnId,onInterrupt:pt,onCompact:Rt,onOpenForkTurns:er,onForkLatest:tr,onForkTurn:ar,onOpenSkills:Gs,onOpenMcp:Js,onOpenHooks:Ks,onCreateHook:Zs,onUpdateHook:Ys,onTrustHook:Qs,onUntrustHook:Xs,goalState:dt,onOpenGoal:ca,onUpdateGoal:ua,...It?{onReadProviderConfig:()=>us(i.thread.provider,It),onWriteProviderConfig:s=>ms(i.thread.provider,It,{content:s})}:{},onToggleFollow:()=>Xe(s=>s+1),onUpdateSettings:ht,onToggleView:ya,onShellCopy:wa,onShellControl:ka,compactBusy:Os,skillsState:As,mcpState:Ms,hooksState:Ls,forkTurnOptionsState:Us}:null,Ua=i?{busy:c,settingsBusy:!1,error:i.thread.isLoaded?(B==null?void 0:B.error)??null:null,followTail:!1,capabilities:N,toolboxItems:($==null?void 0:$.toolboxItems)??[],hookCommandTemplates:($==null?void 0:$.hookCommandTemplates)??[],mcpConfigFormat:($==null?void 0:$.mcpConfigFormat)??"none",threadConnected:i.thread.isLoaded,shellAvailable:te,shellControlState:B,canInterrupt:!!(i.thread.isLoaded&&(B!=null&&B.isCommandRunning)),onInterrupt:pt,onToggleView:ya,onShellCopy:wa,onShellControl:ka}:null,$a=o.useCallback(s=>i?Le({threadId:i.thread.id,path:s}):"",[i==null?void 0:i.thread.id,Le]),Da=o.useMemo(()=>{const s=(i==null?void 0:i.workspace.id)??null;return s?{listTree:()=>en(s),readFile:r=>tn(s,{path:r.path,...r.offset!==void 0?{offset:r.offset}:{},...r.limit!==void 0?{limit:r.limit}:{}}),getRawFileUrl:r=>an(s,{path:r.path}),uploadFile:r=>rn(s,{file:r.file}),downloadNode:async r=>{if(r.kind!=="file")return;const l=await sn(s,{path:r.path}),g=URL.createObjectURL(l.blob),b=document.createElement("a");b.href=g,b.download=l.filename,document.body.append(b),b.click(),b.remove(),URL.revokeObjectURL(g)}}:null},[i==null?void 0:i.workspace.id]),gr=o.useMemo(()=>({openThread:Ne,getThreadHref:Ie,getNewThreadHref:at,renameThread:va,deleteThread:Ct,sendPrompt:ga,interrupt:pt,compact:Rt,updateSettings:ht,loadHistoryItemDetail:ba,getImageAssetUrl:$a,workspace:Da,shell:xe}),[$a,at,Ie,Rt,pt,ba,ga,va,ht,xe,Ne,Da]),xr=i!=null&&i.thread.workspaceId?`/threads?workspaceId=${encodeURIComponent(i.thread.workspaceId)}`:"/workspaces",br=e.jsxs(e.Fragment,{children:[e.jsx(Ir,{open:Bs,busy:aa,turnsState:Fs,onCancel:()=>{aa||ut(!1)},onLoadTurns:Ws,onExport:_s}),e.jsx(Ft,{open:Ce!==null,title:"Delete Thread",description:Ce?`Delete ${ns(Ce.title)} from supervisor. The backend session id will no longer appear in this workspace list.`:"",confirmLabel:"Delete Thread",busy:ra,onCancel:()=>{ra||Ct(null)},onConfirm:()=>void rr()})]});return e.jsx(Er,{threads:se,detail:i,status:T,loading:et,error:et?null:qs,plugins:d,adapter:gr,metaContent:lr,settingsContent:ir,globalSettingsContent:e.jsx(Wt,{embedded:!0}),mobileHeaderAction:pr,workspaceReturnHref:xr,onCloseAppNavigation:(n==null?void 0:n.closeNav)??(()=>{}),surfaceActions:hr,floatingPanel:mr,workspaceFeatures:bo,activeView:x,liveOutput:be,timelineProps:fr,timelineComponent:Pr,useFloatingMobileComposer:Ot,floatingMobileComposerBottomOffset:ja,composerHostRef:L,shellPanelRef:S,shellPanelComponent:Rr,shellEffectiveTheme:(n==null?void 0:n.effectiveTheme)??"dark",shellThemeMode:(n==null?void 0:n.themeMode)??"system",...n!=null&&n.setThemeMode?{onShellThemeModeChange:n.setThemeMode}:{},onShellStateChange:Gt,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:br,...La?{composerProps:La}:{},...Ua?{shellComposerProps:Ua}:{}})}function jo(){const t=Ae(),[a,n]=o.useState(""),[d,m]=o.useState(!1),[h,f]=o.useState(null);async function k(C){C.preventDefault();const j=a.trim();if(!j){f("Session ID is required.");return}m(!0),f(null);try{const R=await fn(j);t(`/threads/${R.thread.id}`)}catch(R){R instanceof z?f(R.payload.message):f(R instanceof Error?R.message:"Unable to import session.")}finally{m(!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 Codex session"}),e.jsx("p",{className:"host-page-description mt-3 max-w-3xl text-sm leading-6",children:"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:k,className:"host-panel space-y-5 rounded-3xl border p-6",children:[e.jsxs("div",{children:[e.jsx("label",{htmlFor:"session-id",className:"host-form-label text-sm font-medium",children:"Local session ID"}),e.jsx("input",{id:"session-id",value:a,onChange:C=>n(C.target.value),placeholder:"019d6fb7-7033-7a30-a2c7-74d0919e87d4",className:"host-form-control mt-2 w-full rounded-2xl border px-4 py-3 outline-none transition"})]}),h&&e.jsx("div",{className:"host-error rounded-2xl border px-4 py-3 text-sm",children:h}),e.jsx("div",{className:"flex flex-wrap items-center gap-3",children:e.jsx("button",{type:"submit",disabled:d,className:"ui-action-primary rounded-full px-5 py-3 font-medium transition disabled:cursor-not-allowed",children:d?"Importing...":"Import Session"})})]})]})}function jt(t){return t.enabled&&t.capabilities.sessions.resume&&t.capabilities.turns.start}function No(t,a){var d;const n=t.find(m=>m.provider===a);return n&&jt(n)?n.provider:((d=t.find(jt))==null?void 0:d.provider)??Oe}function So(){const t=Ae(),a=De(),[n]=ts(),[d,m]=o.useState([]),[h,f]=o.useState([]),[k,C]=o.useState([]),[j,R]=o.useState((a==null?void 0:a.defaultBackend)??Oe),[w,O]=o.useState(""),[S,L]=o.useState(""),D=n.get("title"),[K,ne]=o.useState(()=>D??""),[re,ee]=o.useState("yolo"),[U,ie]=o.useState(!0),[i,_]=o.useState(!1),[se,H]=o.useState(null),Z=n.get("workspaceId"),V=(a==null?void 0:a.defaultBackend)??Oe;o.useEffect(()=>{let N=!1;return Promise.all([qt(),ds()]).then(async([W,$])=>{var G,Y,de;if(N)return;const je=No($,V);R(je),f($);const be=await Ht(je);if(N)return;m(W),C(be);const I=W.some(ue=>ue.id===Z)?Z:((G=W[0])==null?void 0:G.id)??"";O(I),L(((Y=be.find(ue=>ue.isDefault))==null?void 0:Y.model)??((de=be[0])==null?void 0:de.model)??"")}).catch(W=>{N||H(W instanceof Error?W.message:"Unable to load creation form data.")}).finally(()=>{N||ie(!1)}),()=>{N=!0}},[V,Z]),o.useEffect(()=>{if(!j)return;let N=!1;return C([]),L(""),H(null),Ht(j).then(W=>{var $,je;N||(C(W),L((($=W.find(be=>be.isDefault))==null?void 0:$.model)??((je=W[0])==null?void 0:je.model)??""))}).catch(W=>{N||(C([]),L(""),H(W instanceof Error?W.message:"Unable to load backend models."))}),()=>{N=!0}},[j]);function T(){if(window.history.length>1){t(-1);return}if(Z){t(`/threads?workspaceId=${encodeURIComponent(Z)}`);return}t("/workspaces")}async function q(N){N.preventDefault(),_(!0),H(null);try{const W=await hn(K.trim()?{workspaceId:w,provider:j,model:S,approvalMode:re,title:K.trim()}:{workspaceId:w,provider:j,model:S,approvalMode:re});t(`/threads/${W.id}`)}catch(W){W instanceof z?H(W.payload.message):H(W instanceof Error?W.message:"Unable to create thread.")}finally{_(!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:"New Thread"}),e.jsx("h2",{className:"host-page-title mt-2 text-3xl font-semibold",children:"Start a backend session"}),e.jsx("p",{className:"host-page-description mt-3 max-w-2xl text-sm leading-6",children:"Choose the workspace, model, and approval mode that should back the new thread."})]}),U?e.jsx("div",{className:"host-empty-state rounded-3xl border px-6 py-12 text-center",children:"Loading creation form..."}):e.jsxs("form",{onSubmit:q,className:"host-panel space-y-5 rounded-3xl border p-6",children:[e.jsxs("div",{children:[e.jsx("label",{className:"host-form-label text-sm font-medium",htmlFor:"thread-backend",children:"Backend"}),e.jsx("select",{id:"thread-backend",value:j,onChange:N=>{const W=N.target.value;R(W)},className:"host-form-control mt-2 w-full rounded-2xl border px-4 py-3 outline-none transition",children:h.map(N=>e.jsxs("option",{value:N.provider,disabled:!jt(N),children:[N.displayName,jt(N)?"":" (not available)"]},N.provider))})]}),e.jsxs("div",{children:[e.jsx("label",{className:"host-form-label text-sm font-medium",htmlFor:"thread-workspace",children:"Workspace"}),e.jsx("select",{id:"thread-workspace",value:w,onChange:N=>O(N.target.value),className:"host-form-control mt-2 w-full rounded-2xl border px-4 py-3 outline-none transition",children:d.map(N=>e.jsxs("option",{value:N.id,children:[N.label," · ",N.absPath]},N.id))})]}),e.jsxs("div",{children:[e.jsx("label",{className:"host-form-label text-sm font-medium",htmlFor:"thread-model",children:"Model"}),e.jsxs("select",{id:"thread-model",value:S,onChange:N=>L(N.target.value),disabled:k.length===0,className:"host-form-control mt-2 w-full rounded-2xl border px-4 py-3 outline-none transition",children:[k.length===0?e.jsx("option",{value:"",children:"No models available"}):null,k.map(N=>e.jsxs("option",{value:N.model,children:[N.displayName," · ",N.model]},N.id))]})]}),e.jsxs("div",{children:[e.jsx("label",{className:"host-form-label text-sm font-medium",htmlFor:"thread-title",children:"Title"}),e.jsx("input",{id:"thread-title",value:K,onChange:N=>ne(N.target.value),placeholder:"Optional. Falls back to first prompt.",className:"host-form-control mt-2 w-full rounded-2xl border px-4 py-3 outline-none transition"})]}),e.jsxs("div",{children:[e.jsx("label",{className:"host-form-label text-sm font-medium",htmlFor:"thread-approval-mode",children:"Approval mode"}),e.jsxs("select",{id:"thread-approval-mode",value:re,onChange:N=>ee(N.target.value),className:"host-form-control mt-2 w-full rounded-2xl border px-4 py-3 outline-none transition",children:[e.jsx("option",{value:"yolo",children:"yolo"}),e.jsx("option",{value:"guarded",children:"guarded"})]})]}),se&&e.jsx("div",{className:"host-error rounded-2xl border px-4 py-3 text-sm",children:se}),e.jsxs("div",{className:"flex flex-wrap items-center gap-3",children:[e.jsx("button",{type:"submit",disabled:i||!w||!S,className:"ui-action-primary rounded-full px-5 py-3 font-medium transition disabled:cursor-not-allowed",children:i?"Creating...":"Create Thread"}),e.jsx("button",{type:"button",onClick:T,disabled:i,className:"host-secondary-button rounded-full border px-5 py-3 font-medium transition disabled:cursor-not-allowed disabled:opacity-60",children:"Cancel"})]})]})]})}function To(t){return t?`/threads/new?workspaceId=${encodeURIComponent(t)}`:"/threads/new"}function Co({getThreadHref:t,onOpenThread:a,getNewThreadHref:n,renderThreadLink:d,onCloseAppNavigation:m,...h}){const f=Ae(),k=De(),C=m??(k==null?void 0:k.closeNav),j=h.effectiveTheme??(k==null?void 0:k.effectiveTheme),R=h.themeMode??(k==null?void 0:k.themeMode),w=h.onThemeModeChange??(k==null?void 0:k.setThemeMode);return e.jsx(Or,{...h,workspaceReturnHref:h.workspaceReturnHref??"/workspaces",globalSettingsContent:h.globalSettingsContent??e.jsx(Wt,{embedded:!0}),...j?{effectiveTheme:j}:{},...R?{themeMode:R}:{},...w?{onThemeModeChange:w}:{},getThreadHref:t??(O=>`/threads/${O}`),onOpenThread:a??(O=>f(`/threads/${O}`)),getNewThreadHref:n??To,renderThreadLink:d??(({thread:O,children:S,className:L,onClick:D})=>e.jsx(ze,{to:`/threads/${O.id}`,className:L,onClick:D,children:S})),...C?{onCloseAppNavigation:C}:{}})}function ks({open:t,title:a,label:n,value:d,busy:m=!1,onChange:h,onCancel:f,onSubmit:k}){if(o.useEffect(()=>{if(!t)return;function j(R){R.key==="Escape"&&!m&&f()}return window.addEventListener("keydown",j),()=>{window.removeEventListener("keydown",j)}},[m,f,t]),!t)return null;function C(j){j.preventDefault(),k()}return yr.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:f,disabled:m,className:"ui-overlay-scrim absolute inset-0 backdrop-blur-sm disabled:cursor-not-allowed"}),e.jsxs("form",{role:"dialog","aria-modal":"true","aria-label":a,onSubmit:C,className:"host-dialog relative z-[1] w-full max-w-md rounded-[1.6rem] border p-5 shadow-2xl shadow-black/20 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:a}),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:f,disabled:m,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:n}),e.jsx("input",{id:"rename-dialog-input","aria-label":n,autoFocus:!0,value:d,onChange:j=>h(j.target.value),className:"host-form-control mt-2 w-full rounded-2xl 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:f,disabled:m,className:"host-secondary-button rounded-full 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:m||!d.trim(),className:"ui-action-success rounded-full px-4 py-2 text-sm font-medium transition disabled:cursor-not-allowed",children:"Save"})]})]})]}),document.body)}function Io(){const[t]=ts(),a=Ae(),n=De(),d=t.get("workspaceId"),[m,h]=o.useState([]),[f,k]=o.useState([]),[C,j]=o.useState(null),[R,w]=o.useState(!0),[O,S]=o.useState(null),[L,D]=o.useState(null),[K,ne]=o.useState(""),[re,ee]=o.useState(null),[U,ie]=o.useState(null),[i,_]=o.useState(!1),se=(n==null?void 0:n.defaultBackend)??Oe,H=o.useCallback(async()=>{w(!0),S(null);try{const[I,G,Y]=await Promise.all([cs(se).then(de=>de.status),ps(),qt()]);j(I),h(G),k(Y)}catch(I){S(I instanceof Error?I.message:"Unable to load threads.")}finally{w(!1)}},[se]);o.useEffect(()=>{if(d===null)return;H();const I=gs(G=>{h(Y=>Y.map(de=>de.id===G.threadId?{...de,status:G.type==="thread.updated"&&typeof G.payload.status=="string"?G.payload.status:de.status,lastError:(G.type==="thread.turn.failed"||G.type==="thread.turn.completed")&&typeof G.payload.error=="string"?G.payload.error:de.lastError,title:G.type==="thread.updated"&&typeof G.payload.title=="string"?G.payload.title:de.title}:de))});return()=>{I.close()}},[H,d]);const Z=Object.fromEntries(f.map(I=>[I.id,I.label])),V=f.find(I=>I.id===d)??null,T=o.useMemo(()=>d?m.filter(I=>I.workspaceId===d):[],[d,m]),q=T.filter(I=>I.status==="running").length,N=d?`/threads/new?workspaceId=${encodeURIComponent(d)}`:"/threads/new";if(d===null)return e.jsx(wr,{to:"/workspaces",replace:!0});function W(){switch(C==null?void 0:C.state){case"ready":return"bg-emerald-400 shadow-[0_0_0_3px_rgba(52,211,153,0.14)]";case"starting":return"bg-amber-300 shadow-[0_0_0_3px_rgba(252,211,77,0.12)]";case"degraded":case"failed":return"bg-rose-400 shadow-[0_0_0_3px_rgba(251,113,133,0.14)]";default:return"bg-stone-500 shadow-[0_0_0_3px_rgba(120,113,108,0.14)]"}}async function $(I,G){try{const Y=await hs(I,{title:G});h(de=>de.map(ue=>ue.id===Y.id?{...ue,title:Y.title,updatedAt:Y.updatedAt}:ue))}catch(Y){throw S(Y instanceof Error?Y.message:"Unable to rename thread."),Y}}async function je(){if(!L)return;const I=K.trim();if(I){ee(L);try{await $(L,I),D(null),ne("")}finally{ee(null)}}}async function be(){if(U){_(!0);try{await fs(U.id),h(I=>I.filter(G=>G.id!==U.id)),ie(null)}catch(I){S(I instanceof Error?I.message:"Unable to delete thread.")}finally{_(!1)}}}return e.jsx(Co,{threads:m,workspaceLabels:Z,status:C,loading:R,error:O,viewportConstrained:d!==null,showMobileAppMenu:!0,showMobileThreadNavToggle:!1,showMobileNewThreadShortcut:!1,currentWorkspaceId:d,currentWorkspaceLabel:(V==null?void 0:V.label)??null,onRenameThread:$,onDeleteThread:ie,children:e.jsxs(e.Fragment,{children:[e.jsxs("div",{className:"host-panel flex min-h-0 flex-1 flex-col overflow-hidden rounded-[2rem] border shadow-2xl shadow-black/10",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:V?`${V.label} threads`:"All threads",children:V?V.label:"All Threads"}),e.jsx(ze,{to:N,className:"ui-action-primary inline-flex h-9 shrink-0 items-center rounded-full 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-[1.25rem] 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 ${W()}`}),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:(C==null?void 0:C.lastError)??((C==null?void 0:C.state)==="ready"?"Ready":(C==null?void 0:C.state)??"Checking")})]})]})}),!R&&!O&&T.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:[T.length," total"]}),q>0&&e.jsxs("span",{className:"host-muted text-xs",children:["· ",q," running"]})]}),e.jsx("div",{className:"mt-3 min-h-0 flex-1",children:e.jsx(Ar,{threads:T,currentWorkspaceId:d,workspaceLabels:Z,onOpenThread:I=>a(`/threads/${I}`),onBeginRenameThread:I=>{D(I.id),ne(I.title)},onDeleteThread:I=>ie(I),scrollable:!0,maxHeightClassName:"max-h-full",showDeleteButton:!0,showSessionCopyButton:!0})})]}),!R&&!O&&T.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(ks,{open:L!==null,title:"Rename Thread",label:"Thread Title",value:K,busy:re!==null,onChange:ne,onCancel:()=>{D(null),ne("")},onSubmit:()=>void je()}),e.jsx(Ft,{open:U!==null,title:"Delete Thread",description:U?`Delete ${ns(U.title)} from supervisor. The backend session id will no longer appear in this workspace list.`:"",confirmLabel:"Delete Thread",busy:i,onCancel:()=>{i||ie(null)},onConfirm:()=>void be()})]})})}function Qa(t){const a=t.trim(),n=a.replace(/[\\/]+$/,"");if(!n)return"";if(js(a)){const m=(n.split(/[?#]/)[0]??n).split(/[/:]/).filter(Boolean).at(-1)??"";return m.endsWith(".git")?m.slice(0,-4):m}return n.split(/[\\/]/).filter(Boolean).at(-1)??""}function js(t){const a=t.trim();return/^https?:\/\/.+/i.test(a)||/^ssh:\/\/.+/i.test(a)||/^git@[^:]+:.+/.test(a)}function Eo({initialPath:t="",initialLabel:a="",submitLabel:n="Save Workspace",error:d,busy:m=!1,onSubmit:h}){const f=Qa(t),[k,C]=o.useState(t),[j,R]=o.useState(a||f),[w,O]=o.useState(null),S=o.useRef(f);o.useEffect(()=>{const D=Qa(k);R(K=>!K.trim()||K===S.current?D:K),S.current=D},[k]);async function L(D){D.preventDefault();const K=k.trim();if(!K){O("Workspace path or Git URL is required.");return}O(null);const ne=j.trim(),re=js(K)?"gitUrl":"absPath";await h(ne?{[re]:K,label:ne}:{[re]:K})}return e.jsxs("form",{onSubmit:L,className:"host-panel space-y-5 rounded-3xl border p-6",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:k,onChange:D=>C(D.target.value),placeholder:"/Users/name/project or https://github.com/owner/repo.git",className:"host-form-control mt-2 w-full rounded-2xl border px-4 py-3 outline-none transition"}),e.jsx("p",{className:"host-muted mt-2 text-xs",children:"Absolute paths register local directories. Git URLs clone into the configured dev home."})]}),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:j,onChange:D=>R(D.target.value),placeholder:"Optional override",className:"host-form-control mt-2 w-full rounded-2xl 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."})]}),(w||d)&&e.jsx("div",{className:"host-error rounded-2xl border px-4 py-3 text-sm",children:w??d}),e.jsx("button",{type:"submit",disabled:m,className:"ui-action-primary rounded-full px-5 py-3 font-medium transition disabled:cursor-not-allowed",children:m?"Saving...":n})]})}function Ro(){const t=Ae(),[a,n]=o.useState(null),[d,m]=o.useState(!1);async function h(f){m(!0),n(null);try{const k=await Ln(f);t(`/threads?workspaceId=${encodeURIComponent(k.id)}`)}catch(k){k instanceof z?n(k.payload.message):n(k instanceof Error?k.message:"Unable to create workspace.")}finally{m(!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:"Add Workspace"}),e.jsx("h2",{className:"host-page-title mt-2 text-3xl font-semibold",children:"Create a workspace"}),e.jsx("p",{className:"host-page-description mt-3 max-w-2xl text-sm leading-6",children:"Register an existing local directory, create one missing child directory under dev home, or clone a Git repository into dev home."})]}),e.jsx(Eo,{busy:d,error:a,submitLabel:"Create Workspace",onSubmit:h})]})}function Xa(t){return Date.parse(t.lastOpenedAt??t.createdAt)}function Po(t,a){return t.isFavorite!==a.isFavorite?t.isFavorite?-1:1:Xa(a)-Xa(t)}function Oo(t){return t?new Date(t).toLocaleString():"Never opened"}function Ao(t,a=28){return t.length<=a?t:`...${t.slice(-(a-3))}`}function Mo({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 Lo(){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 Uo(){const t=Ae(),[a,n]=o.useState([]),[d,m]=o.useState(!0),[h,f]=o.useState(null),[k,C]=o.useState(null),[j,R]=o.useState(""),[w,O]=o.useState(null),[S,L]=o.useState(null),[D,K]=o.useState(null),[ne,re]=o.useState(!1);async function ee(){m(!0),f(null);try{n(await qt())}catch(T){f(T instanceof Error?T.message:"Unable to load workspaces.")}finally{m(!1)}}o.useEffect(()=>{ee()},[]);async function U(T){const q={...T,isFavorite:!T.isFavorite};n(N=>N.map(W=>W.id===T.id?q:W));try{const N=await Dn(T.id,{isFavorite:!T.isFavorite});n(W=>W.map($=>$.id===N.id?N:$))}catch(N){n(W=>W.map($=>$.id===T.id?T:$)),f(N instanceof Error?N.message:"Unable to update workspace.")}}async function ie(T){const q=j.trim();if(q){O(T);try{const N=await Un(T,{label:q});n(W=>W.map($=>$.id===N.id?N:$)),C(null),R("")}catch(N){f(N instanceof Error?N.message:"Unable to rename workspace.")}finally{O(null)}}}function i(T){C(T.id),R(T.label)}function _(){C(null),R("")}function se(T){t(`/threads?workspaceId=${encodeURIComponent(T)}`)}async function H(){if(D){re(!0);try{await $n(D.id),n(T=>T.filter(q=>q.id!==D.id)),K(null)}catch(T){f(T instanceof Error?T.message:"Unable to delete workspace.")}finally{re(!1)}}}function Z(T,q){(T.key==="Enter"||T.key===" ")&&(T.preventDefault(),se(q))}const V=o.useMemo(()=>[...a].sort(Po),[a]);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-[1.4rem] sm:border sm:px-4",children:e.jsxs("div",{className:"relative",children:[e.jsxs("div",{className:"flex min-w-0 items-center gap-1.5 sm:gap-2",children:[e.jsx(bs,{}),e.jsx(ze,{to:"/threads/import",className:"host-info-pill inline-flex h-8 shrink-0 items-center rounded-full 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(ze,{to:"/workspaces/new",className:"ui-action-primary inline-flex h-8 shrink-0 items-center rounded-full 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.jsx(vs,{className:"absolute left-0 top-[calc(100%+0.5rem)] z-30 w-[min(22rem,calc(100vw-1rem))]"})]})}),d&&e.jsx("div",{className:"host-empty-state rounded-[1.6rem] border px-6 py-12 text-center",children:"Loading workspace registry..."}),h&&e.jsx("div",{className:"host-error rounded-[1.4rem] border px-4 py-4",children:h}),!d&&!h&&a.length===0&&e.jsxs("div",{className:"host-empty-state rounded-[1.6rem] 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."})]}),!d&&V.length>0&&e.jsx("div",{className:"space-y-2 overflow-x-hidden",children:V.map(T=>e.jsxs("article",{role:"link",tabIndex:0,onClick:()=>se(T.id),onKeyDown:q=>Z(q,T.id),className:"host-card relative overflow-hidden rounded-[1.35rem] 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 ${T.label}`,title:"Delete workspace",onClick:q=>{q.stopPropagation(),K(T)},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(Lo,{})}),e.jsx("button",{type:"button","aria-label":T.isFavorite?`Unpin workspace ${T.label}`:`Pin workspace ${T.label}`,title:T.isFavorite?"Unpin workspace":"Pin workspace",onClick:q=>{q.stopPropagation(),U(T)},className:`inline-flex h-7 w-7 items-center justify-center rounded-full border transition ${T.isFavorite?"host-warning-pill":"host-icon-button"}`,children:e.jsx(Mo,{active:T.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:T.label,children:T.label}),e.jsx("button",{type:"button",onClick:q=>{q.stopPropagation(),i(T)},"aria-label":`Rename workspace ${T.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":T.absPath,title:T.absPath,onClick:q=>{q.stopPropagation(),L(T.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:Ao(T.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: ",Oo(T.lastOpenedAt)]})})]})})]},T.id))}),e.jsx(ks,{open:k!==null,title:"Rename Workspace",label:"Workspace Label",value:j,busy:w!==null,onChange:R,onCancel:_,onSubmit:()=>k?ie(k):void 0}),e.jsx(Mr,{open:S!==null,title:"Workspace Path",text:S??"",onClose:()=>L(null)}),e.jsx(Ft,{open:D!==null,title:"Delete Workspace",description:D?`Delete ${D.label} from supervisor. This also removes its threads and local supervisor metadata.`:"",confirmLabel:"Delete Workspace",busy:ne,onCancel:()=>{ne||K(null)},onConfirm:()=>void H()})]})}const Ns="remote-codex-theme-mode",Ss="remote-codex-default-backend";function $o(){if(typeof window>"u")return"system";const t=window.localStorage.getItem(Ns);return t==="light"||t==="dark"||t==="system"?t:"system"}function Do(){if(typeof window>"u")return Oe;const t=window.localStorage.getItem(Ss);return $r(t)??Oe}function Ho(){return typeof window<"u"&&typeof window.matchMedia=="function"&&window.matchMedia("(prefers-color-scheme: dark)").matches?"dark":"light"}function Bo({themeMode:t,setThemeMode:a,effectiveTheme:n}){const[d,m]=o.useState(!1),[h,f]=o.useState(!1),[k,C]=o.useState(Do),j=es(),R=/^\/threads\/[^/]+$/.test(j.pathname),w=/^\/control-plane\/sessions\/[^/]+$/.test(j.pathname),O=j.pathname==="/threads",S=R||w||O,L=O||R||w,D=R||w,K=j.pathname==="/workspaces",ne=j.pathname.startsWith("/control-plane"),re=K||O||ne;o.useEffect(()=>{m(!1)},[j.pathname,j.search]);function ee(U){C(U),window.localStorage.setItem(Ss,U)}return e.jsxs(os.Provider,{value:{navOpen:d,openNav:()=>m(!0),toggleNav:()=>m(U=>!U),closeNav:()=>m(!1),settingsOpen:h,openSettings:()=>{m(!1),f(!0)},closeSettings:()=>f(!1),themeMode:t,setThemeMode:a,effectiveTheme:n,defaultBackend:k,setDefaultBackend:ee},children:[e.jsxs("div",{className:`bg-[var(--app-bg)] text-[var(--app-fg)] ${S?"fixed inset-0 overflow-hidden overscroll-none":"min-h-screen"}`,children:[!re&&!D&&e.jsxs("div",{className:"fixed left-4 top-4 z-50",children:[e.jsx(bs,{}),e.jsx(vs,{className:"mt-3 w-[min(22rem,calc(100vw-2rem))]"})]}),e.jsx("main",{className:`mx-auto w-full ${L?"max-w-none":"max-w-[1600px]"} ${S?"absolute inset-0 pb-0 sm:pb-4":"pb-4"} ${L?R||w?"pt-0":O?"pt-[env(safe-area-inset-top)] sm:pt-4":"pt-[calc(env(safe-area-inset-top)+4rem)] sm:pt-4":K||ne?"pt-[env(safe-area-inset-top)] sm:pt-4":"pt-4"} ${S?R||w?"overflow-hidden overscroll-none px-0":"overflow-hidden overscroll-none px-0 sm:px-6":"px-4 sm:px-6"}`,children:e.jsx("section",{className:`min-w-0 ${S?R||w?"h-full min-h-0 overflow-hidden overscroll-none":"h-full overflow-hidden overscroll-none":""}`,children:e.jsx(Nr,{})})})]}),e.jsx(Wt,{})]})}function Fo(){const[t,a]=o.useState(()=>$o()),[n,d]=o.useState(()=>Ho()),m=t==="system"?n:t;return o.useEffect(()=>{if(typeof window>"u"||typeof window.matchMedia!="function")return;const h=window.matchMedia("(prefers-color-scheme: dark)"),f=()=>{d(h.matches?"dark":"light")};return f(),typeof h.addEventListener=="function"?h.addEventListener("change",f):h.addListener(f),()=>{typeof h.removeEventListener=="function"?h.removeEventListener("change",f):h.removeListener(f)}},[]),o.useEffect(()=>{typeof window>"u"||window.localStorage.setItem(Ns,t)},[t]),o.useEffect(()=>{const h=document.documentElement;h.dataset.themeMode=t,h.dataset.themeEffective=m,h.style.colorScheme=m},[m,t]),e.jsx("div",{className:"theme-shell theme-scrollbar",children:e.jsx(Lr,{adapter:{fetchPlugins:on,importPlugin:ln,updatePlugin:dn},children:e.jsx(kr,{children:e.jsxs(jr,{children:[e.jsx(Pe,{path:"/",element:e.jsx(Kn,{})}),e.jsxs(Pe,{element:e.jsx(Bo,{themeMode:t,setThemeMode:a,effectiveTheme:m}),children:[e.jsx(Pe,{path:"/workspaces",element:e.jsx(Uo,{})}),e.jsx(Pe,{path:"/workspaces/new",element:e.jsx(Ro,{})}),e.jsx(Pe,{path:"/threads",element:e.jsx(Io,{})}),e.jsx(Pe,{path:"/threads/import",element:e.jsx(jo,{})}),e.jsx(Pe,{path:"/threads/new",element:e.jsx(So,{})}),e.jsx(Pe,{path:"/threads/:id",element:e.jsx(ko,{})})]})]})})})})}Sr.createRoot(document.getElementById("root")).render(e.jsx(Tr.StrictMode,{children:e.jsx(Fo,{})}));
@@ -1 +0,0 @@
1
- .xyz-viewer-plugin{display:flex;min-height:0;height:100%;flex-direction:column;overflow:hidden;border:1px solid rgba(120,113,108,.28);border-radius:14px;background:#fff;color:#1c1917}.xyz-viewer-plugin__header{display:flex;flex:0 0 auto;align-items:center;justify-content:space-between;gap:12px;border-bottom:1px solid rgba(120,113,108,.18);padding:12px 14px}.xyz-viewer-plugin__header h2{margin:0;font-size:14px;font-weight:650;line-height:20px}.xyz-viewer-plugin__header p,.xyz-viewer-plugin__header span{margin:0;color:#78716c;font-size:11px;line-height:16px}.xyz-viewer-plugin__toolbar{display:flex;flex:0 0 auto;align-items:center;justify-content:flex-end;gap:6px;overflow-x:auto;border-bottom:1px solid rgba(120,113,108,.14);padding:8px 10px}.xyz-viewer-plugin__toolbar button,.xyz-viewer-plugin__timeline button{display:inline-flex;width:30px;height:30px;flex:0 0 auto;align-items:center;justify-content:center;border:1px solid rgba(120,113,108,.24);border-radius:8px;background:#fff;color:#44403c;cursor:pointer}.xyz-viewer-plugin__toolbar button:hover,.xyz-viewer-plugin__timeline button:hover{background:#f5f5f4;color:#1c1917}.xyz-viewer-plugin__toolbar button:disabled,.xyz-viewer-plugin__timeline button:disabled{cursor:not-allowed;opacity:.42}.xyz-viewer-plugin__toolbar svg,.xyz-viewer-plugin__timeline svg{width:15px;height:15px}.xyz-viewer-plugin__toolbar-divider{width:1px;height:22px;flex:0 0 auto;background:#78716c2e}.xyz-viewer-plugin__stage{position:relative;min-height:260px;flex:1 1 auto;overflow:hidden;background:#fbfbfb}.xyz-viewer-plugin__canvas{position:absolute;top:0;right:0;bottom:0;left:0}.xyz-viewer-plugin__error,.xyz-viewer-plugin__empty{position:absolute;top:0;right:0;bottom:0;left:0;display:flex;align-items:center;justify-content:center;padding:20px;text-align:center;font-size:13px;line-height:20px}.xyz-viewer-plugin__error{background:#fff1f2;color:#be123c}.xyz-viewer-plugin__empty{color:#78716c}.xyz-viewer-plugin__tooltip{position:fixed;z-index:1000;display:grid;gap:2px;pointer-events:none;border:1px solid rgba(120,113,108,.28);border-radius:8px;background:#fffffff5;box-shadow:0 10px 28px #1c191729;padding:7px 8px;color:#292524;font-size:11px;line-height:15px}.xyz-viewer-plugin__tooltip span{color:#57534e}.xyz-viewer-plugin__timeline{display:grid;grid-template-columns:auto minmax(120px,1fr) auto auto;align-items:center;gap:8px;border-top:1px solid rgba(120,113,108,.14);padding:10px;color:#57534e;font-size:12px}.xyz-viewer-plugin__timeline input{width:100%}.xyz-viewer-plugin__timeline button.is-live{width:auto;padding:0 10px;color:#b91c1c}.xyz-viewer-plugin__status{display:flex;flex:0 0 auto;flex-wrap:wrap;justify-content:space-between;gap:8px 12px;border-top:1px solid rgba(120,113,108,.14);padding:9px 12px;color:#57534e;font-size:11px;line-height:16px}