remote-codex 0.11.20 → 0.11.21
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/apps/supervisor-api/dist/index.js +64 -4
- package/apps/supervisor-web/dist/assets/{index-BdeDlmJY.js → index-BfspE5mQ.js} +1 -1
- package/apps/supervisor-web/dist/assets/{thread-ui-C5nUCiEf.js → thread-ui-CDgAOcDh.js} +33 -26
- package/apps/supervisor-web/dist/index.html +2 -2
- package/package.json +1 -1
- package/packages/claude/src/runtimeAdapter.test.ts +6 -1
- package/packages/claude/src/runtimeAdapter.ts +19 -0
|
@@ -11677,6 +11677,21 @@ var DEFAULT_CLAUDE_MODELS = [
|
|
|
11677
11677
|
],
|
|
11678
11678
|
defaultReasoningEffort: "medium"
|
|
11679
11679
|
},
|
|
11680
|
+
{
|
|
11681
|
+
id: "fable",
|
|
11682
|
+
model: "fable",
|
|
11683
|
+
displayName: "Claude Fable",
|
|
11684
|
+
description: "Claude Code Fable model alias.",
|
|
11685
|
+
isDefault: false,
|
|
11686
|
+
hidden: false,
|
|
11687
|
+
supportedReasoningEfforts: [
|
|
11688
|
+
{ reasoningEffort: "low", description: "Low effort" },
|
|
11689
|
+
{ reasoningEffort: "medium", description: "Medium effort" },
|
|
11690
|
+
{ reasoningEffort: "high", description: "High effort" },
|
|
11691
|
+
{ reasoningEffort: "xhigh", description: "Extra high effort" }
|
|
11692
|
+
],
|
|
11693
|
+
defaultReasoningEffort: "medium"
|
|
11694
|
+
},
|
|
11680
11695
|
{
|
|
11681
11696
|
id: "opus",
|
|
11682
11697
|
model: "opus",
|
|
@@ -11747,6 +11762,7 @@ function withClaudeCodeModelAliases(models) {
|
|
|
11747
11762
|
const output = [...models];
|
|
11748
11763
|
const defaultSonnet = DEFAULT_CLAUDE_MODELS[0];
|
|
11749
11764
|
const oneMillionSonnet = DEFAULT_CLAUDE_MODELS[1];
|
|
11765
|
+
const fable = DEFAULT_CLAUDE_MODELS[2];
|
|
11750
11766
|
const hasSonnetAlias = output.some((model) => model.model === "sonnet");
|
|
11751
11767
|
if (!hasSonnetAlias) {
|
|
11752
11768
|
output.unshift(defaultSonnet);
|
|
@@ -11754,6 +11770,9 @@ function withClaudeCodeModelAliases(models) {
|
|
|
11754
11770
|
if (!output.some((model) => model.model === "sonnet[1m]")) {
|
|
11755
11771
|
output.splice(1, 0, oneMillionSonnet);
|
|
11756
11772
|
}
|
|
11773
|
+
if (!output.some((model) => model.model === "fable")) {
|
|
11774
|
+
output.splice(2, 0, fable);
|
|
11775
|
+
}
|
|
11757
11776
|
return output.map((model, index) => ({
|
|
11758
11777
|
...model,
|
|
11759
11778
|
isDefault: index === 0
|
|
@@ -16814,6 +16833,13 @@ var ThreadLiveStateStore = class {
|
|
|
16814
16833
|
const visibleTurnIds = new Set(visibleTurns.map((turn) => turn.id));
|
|
16815
16834
|
return visibleTurnIds.has(reconciled.turnId) ? reconciled : null;
|
|
16816
16835
|
}
|
|
16836
|
+
getLiveItemsForTurn(localThreadId, turnId) {
|
|
16837
|
+
if (!turnId) {
|
|
16838
|
+
return null;
|
|
16839
|
+
}
|
|
16840
|
+
const current = this.threadLiveItems.get(localThreadId);
|
|
16841
|
+
return current?.turnId === turnId ? current : null;
|
|
16842
|
+
}
|
|
16817
16843
|
upsertLiveItem(localThreadId, turnId, item) {
|
|
16818
16844
|
const current = this.threadLiveItems.get(localThreadId);
|
|
16819
16845
|
const currentItems = current?.turnId === turnId ? current.items : [];
|
|
@@ -17386,12 +17412,20 @@ var ThreadRuntimeEventProjector = class {
|
|
|
17386
17412
|
lastError: null,
|
|
17387
17413
|
lastTurnStartedAt: (/* @__PURE__ */ new Date()).toISOString()
|
|
17388
17414
|
});
|
|
17415
|
+
liveState.setLiveItems(record.id, null);
|
|
17389
17416
|
liveState.resetRecordedTurnItemOrder(record.id, turnId);
|
|
17390
17417
|
for (const item of event.turn.items) {
|
|
17391
|
-
liveState.recordTurnItemOrder(record.id, turnId, item.id);
|
|
17418
|
+
const sequence = liveState.recordTurnItemOrder(record.id, turnId, item.id);
|
|
17419
|
+
const eventTimestamp = (/* @__PURE__ */ new Date()).toISOString();
|
|
17420
|
+
const orderedLiveItem = {
|
|
17421
|
+
...withHistoryItemCreatedAt(item, eventTimestamp),
|
|
17422
|
+
sequence
|
|
17423
|
+
};
|
|
17424
|
+
const transportLiveItem = deferHistoryItemDetailForTransport(orderedLiveItem);
|
|
17425
|
+
callbacks.persistLiveHistoryItem(record.id, turnId, orderedLiveItem);
|
|
17426
|
+
liveState.upsertLiveItem(record.id, turnId, transportLiveItem);
|
|
17392
17427
|
}
|
|
17393
17428
|
liveState.setLivePlan(record.id, null);
|
|
17394
|
-
liveState.setLiveItems(record.id, null);
|
|
17395
17429
|
if (shouldResetThreadContextUsageForTurnStart(callbacks.getThreadContextUsage(record.id))) {
|
|
17396
17430
|
callbacks.resetThreadContextUsage(record.id, true);
|
|
17397
17431
|
}
|
|
@@ -18091,9 +18125,16 @@ var ThreadDetailAssembler = class {
|
|
|
18091
18125
|
remoteSession.turns
|
|
18092
18126
|
);
|
|
18093
18127
|
const visibleTurns = this.input.liveState.visibleRemoteTurns(input.localThreadId, remoteSession.turns).map((turn) => agentTurnToThreadTurnDto(turn, deferredDetails));
|
|
18094
|
-
const
|
|
18128
|
+
const visibleTurnsWithActiveLiveTurn = appendActiveLiveTurnIfMissing(
|
|
18095
18129
|
visibleTurns,
|
|
18096
18130
|
input.localThreadId,
|
|
18131
|
+
updated.providerTurnId,
|
|
18132
|
+
this.input.liveState,
|
|
18133
|
+
input.turnMetadataById
|
|
18134
|
+
);
|
|
18135
|
+
const orderedVisibleTurns = applyLiveAgentMessageOrderingHints(
|
|
18136
|
+
visibleTurnsWithActiveLiveTurn,
|
|
18137
|
+
input.localThreadId,
|
|
18097
18138
|
this.input.liveState
|
|
18098
18139
|
);
|
|
18099
18140
|
const resolvedTurnMetadataById = resolveTurnMetadataByVisibleTurnId(
|
|
@@ -18223,6 +18264,26 @@ function applyLiveAgentMessageOrderingHints(turns, localThreadId, liveState) {
|
|
|
18223
18264
|
} : turn;
|
|
18224
18265
|
});
|
|
18225
18266
|
}
|
|
18267
|
+
function appendActiveLiveTurnIfMissing(turns, localThreadId, providerTurnId, liveState, metadataById) {
|
|
18268
|
+
const displayTurnId = liveState.displayTurnIdForRuntimeTurn(localThreadId, providerTurnId) ?? providerTurnId;
|
|
18269
|
+
if (!displayTurnId || turns.some((turn) => turn.id === displayTurnId)) {
|
|
18270
|
+
return turns;
|
|
18271
|
+
}
|
|
18272
|
+
const liveItems = liveState.getLiveItemsForTurn(localThreadId, displayTurnId);
|
|
18273
|
+
if (!liveItems || liveItems.items.length === 0) {
|
|
18274
|
+
return turns;
|
|
18275
|
+
}
|
|
18276
|
+
return [
|
|
18277
|
+
...turns,
|
|
18278
|
+
{
|
|
18279
|
+
id: displayTurnId,
|
|
18280
|
+
startedAt: metadataById.get(displayTurnId)?.createdAt ?? null,
|
|
18281
|
+
status: "inProgress",
|
|
18282
|
+
error: null,
|
|
18283
|
+
items: sortHistoryItemsBySequence(liveItems.items)
|
|
18284
|
+
}
|
|
18285
|
+
];
|
|
18286
|
+
}
|
|
18226
18287
|
function buildTurnDto(turn, metadata) {
|
|
18227
18288
|
const tokenUsage = parseThreadTurnTokenUsageJson(metadata?.tokenUsageJson);
|
|
18228
18289
|
const displayPrompt = metadata?.displayPrompt?.trim();
|
|
@@ -18764,7 +18825,6 @@ var ThreadPromptTurnCoordinator = class {
|
|
|
18764
18825
|
}
|
|
18765
18826
|
updateThreadRecord(this.db, localThreadId, patch);
|
|
18766
18827
|
this.liveState.setLivePlan(localThreadId, null);
|
|
18767
|
-
this.liveState.setLiveItems(localThreadId, null);
|
|
18768
18828
|
if (shouldResetThreadContextUsageForTurnStart(
|
|
18769
18829
|
this.callbacks.getThreadContextUsage(localThreadId)
|
|
18770
18830
|
)) {
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import{j as e,r,u as ma,d as Pe,L as $e,e as vn,f as Ws,b as yn,N as ha,B as wn,h as zs,i as pe,O as jn,k as Nn,c as kn}from"./react-vendor-CgLzZcV4.js";import{u as Ye,a as Gs,t as Sn,f as Gt,E as Cn,C as fa,T as Tn,b as En,c as In,d as Rn,e as An,L as Pn,P as On,A as Un}from"./thread-ui-
|
|
1
|
+
import{j as e,r,u as ma,d as Pe,L as $e,e as vn,f as Ws,b as yn,N as ha,B as wn,h as zs,i as pe,O as jn,k as Nn,c as kn}from"./react-vendor-CgLzZcV4.js";import{u as Ye,a as Gs,t as Sn,f as Gt,E as Cn,C as fa,T as Tn,b as En,c as In,d as Rn,e as An,L as Pn,P as On,A as Un}from"./thread-ui-CDgAOcDh.js";import{l as Se}from"./ui-vendor-CeKGesq3.js";import"./graph-vendor-DVPtkh3h.js";import"./terminal-vendor-B365Go3Z.js";import"./markdown-vendor-BQJfKm05.js";(function(){const a=document.createElement("link").relList;if(a&&a.supports&&a.supports("modulepreload"))return;for(const l of document.querySelectorAll('link[rel="modulepreload"]'))n(l);new MutationObserver(l=>{for(const i of l)if(i.type==="childList")for(const u of i.addedNodes)u.tagName==="LINK"&&u.rel==="modulepreload"&&n(u)}).observe(document,{childList:!0,subtree:!0});function s(l){const i={};return l.integrity&&(i.integrity=l.integrity),l.referrerPolicy&&(i.referrerPolicy=l.referrerPolicy),l.crossOrigin==="use-credentials"?i.credentials="include":l.crossOrigin==="anonymous"?i.credentials="omit":i.credentials="same-origin",i}function n(l){if(l.ep)return;l.ep=!0;const i=s(l);fetch(l.href,i)}})();var Ln=["codex","claude","opencode"],De="codex",xs={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 Dn(t){return typeof t=="string"&&Ln.includes(t)}function $n(t){return Dn(t)?t:null}var gs=15;function Mn(t){return t.replace(/\s+/g," ").trim()}function Hn(t){const a=Mn(t);if(!a)return"";const s=Array.from(a);return s.length<=gs?a:`${s.slice(0,gs).join("")}...`}const Bn=["codex","claude","opencode"],Vs="codex",Js={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"}},bs=15;function _n(t){return t.replace(/\s+/g," ").trim()}function Fn(t){const a=_n(t);if(!a)return"";const s=Array.from(a);return s.length<=bs?a:`${s.slice(0,bs).join("")}...`}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 Et(){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 Vt(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."}],Ks={hostConfigFiles:[],toolboxItems:[],hookCommandTemplates:[],providerConfigFormat:"none",mcpConfigFormat:"none",configArchives:!1,buildRestart:!1},zn={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 ra(t){const a=zn[t];return{packageName:a.packageName,installed:t==="codex",installedVersion:null,latestVersion:null,installCommand:a.installCommand,updateCommand:a.updateCommand,busy:!1,lastError:null}}function Gn(t,a){return{provider:t,displayName:a,description:`${a} backend descriptor is not available.`,enabled:!1,isDefault:t===Vs,status:{state:"stopped",transport:Js[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:Ks,installation:ra(t)}}function Jt(t){const a=t.installation??ra(t.provider);return{...t,installation:{...ra(t.provider),...a}}}const tt=[...Bn.map(t=>Gn(t,Js[t].displayName))];function Vn(t){var a;return((a=tt.find(s=>s.provider===t))==null?void 0:a.managementSchema)??Ks}function Jn(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 Kn(t){const a=t.payload.details,s=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 s?`${t.message}
|
|
2
2
|
${s}`:t.message}function it(t){return{path:t,exists:!1,originalContent:"",draftContent:"",loading:!1,saving:!1,error:null,saveMessage:null}}const Yn=/^\/devices\/([^/]+)(?:\/|$)/,Zn=/^(?:\/devices\/[^/]+)?\/threads\/([^/?#]+)(?:[/?#]|$)/;function Xn(t){const a=Yn.exec(t);return a?decodeURIComponent(a[1]??""):null}function st(){return typeof window>"u"?null:Xn(window.location.pathname)}function Qn(t){const a=Zn.exec(t);return a?decodeURIComponent(a[1]??""):null}function eo(){return typeof window>"u"?null:Qn(window.location.pathname)}function ft(t,a){if(!a)return t;const s=t.startsWith("/")?t:`/${t}`;return`/devices/${encodeURIComponent(a)}${s}`}function na(t){return ft(t,st())}function Ys(t,a){return ft(`/threads/${encodeURIComponent(t)}`,a)}function Ae(t){return Ys(t,st())}function to(t,a){const s=t?`?workspaceId=${encodeURIComponent(t)}`:"";return ft(`/threads${s}`,a)}function mt(t){return to(t,st())}function ao(t,a){const s=t?`?workspaceId=${encodeURIComponent(t)}`:"";return ft(`/threads/new${s}`,a)}function At(t){return ao(t,st())}function pa(t){return ft("/workspaces",t)}function pt(){return pa(st())}class Y extends Error{constructor(a,s){super(s.message),this.statusCode=a,this.payload=s}}const oa="remote-codex-auth-token",la="remote-codex-relay-token",Zs="remote-codex-relay-mode",ia="remote-codex-relay-device-id",da="remote-codex-relay-thread-id";function Xs(){return typeof window>"u"?null:window.localStorage.getItem(oa)}function so(t){if(!(typeof window>"u")){if(t){window.localStorage.setItem(oa,t);return}window.localStorage.removeItem(oa)}}function Qs(){return typeof window>"u"?null:window.localStorage.getItem(la)}function xa(t){if(!(typeof window>"u")){if(t){window.localStorage.setItem(la,t);return}window.localStorage.removeItem(la)}}function at(){var t;return typeof window>"u"?!1:((t=window.__REMOTE_CODEX_BOOTSTRAP__)==null?void 0:t.mode)==="relay"||window.location.pathname.startsWith("/relay-portal")||window.location.pathname.startsWith("/relay-admin")||window.location.search.includes("relay=1")||window.localStorage.getItem(Zs)==="true"}function rt(){typeof window>"u"||window.localStorage.setItem(Zs,"true")}function ca(){return at()}function er(){return typeof window>"u"?null:st()??window.localStorage.getItem(ia)}function Pt(t){if(!(typeof window>"u")){if(t){window.localStorage.setItem(ia,t);return}window.localStorage.removeItem(ia)}}function ro(){return typeof window>"u"?null:eo()??window.localStorage.getItem(da)}function Ot(t){if(!(typeof window>"u")){if(t){window.localStorage.setItem(da,t);return}window.localStorage.removeItem(da)}}function ga(t){if(!at())return t;if(t.startsWith("/api/")){const a=er();return a?`/relay/devices/${encodeURIComponent(a)}${t}`:`/relay${t}`}return t}function tr(t){return ga(t)}function no(t){return t===400?"bad_request":t===401?"unauthorized":t===403?"forbidden":t===404?"not_found":t===409?"conflict":t===429||t===503?"service_unavailable":"internal_error"}function oo(t,a){const s=a==null?void 0:a.trim(),n=s?`${t} ${s}`:`${t}`;return t===429?`Too many requests (${n}).`:t===503?`Upstream service unavailable (${n}).`:`Request failed (${n}).`}function Qe(t,a,s){const n=typeof(a==null?void 0:a.message)=="string"&&a.message.trim()?a.message.trim():s,l=a!=null&&a.details&&typeof a.details=="object"?a.details:void 0;return{code:(a==null?void 0:a.code)??no(t.status),message:n,...l?{details:l}:{}}}async function ar(t){var l,i;const a=oo(t.status,t.statusText),s=((i=(l=t.headers)==null?void 0:l.get)==null?void 0:i.call(l,"content-type"))??"",n=async()=>Qe(t,await t.json(),a);if(s.includes("application/json"))try{return await n()}catch{return Qe(t,null,a)}try{if(typeof t.text!="function")try{return await n()}catch{return Qe(t,null,a)}const u=(await t.text()).trim();if(u.startsWith("{"))try{return Qe(t,JSON.parse(u),a)}catch{}return Qe(t,u?{message:`${a}
|
|
3
3
|
${u}`}:null,a)}catch{try{return await n()}catch{return Qe(t,null,a)}}}async function U(t,a){const s=new Headers(a==null?void 0:a.headers);(a==null?void 0:a.body)!==void 0&&!(a.body instanceof FormData)&&!s.has("Content-Type")&&s.set("Content-Type","application/json");const n=await fetch(ga(String(t)),rr({...a,headers:s}));if(!n.ok){const l=await ar(n);throw new Y(n.status,l)}return await n.json()}function lo(t){const a=String(t);return a.includes("/exports/pdf")?a.includes("format=html")?"remote-codex-transcript.html":"remote-codex-transcript.pdf":"download"}function io(t){var l;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 s=t.match(/filename="([^"]+)"/i);if(s!=null&&s[1])return s[1].trim();const n=t.match(/filename=([^;]+)/i);return((l=n==null?void 0:n[1])==null?void 0:l.trim())??null}async function sr(t,a){const s=await fetch(ga(String(t)),rr(a));if(!s.ok){const l=await ar(s);throw new Y(s.status,l)}const n=io(s.headers.get("content-disposition"))??lo(t);return{blob:await s.blob(),filename:n}}function rr(t={}){const a=new Headers(t.headers),s=Qs(),n=Xs();return at()&&s&&!a.has("Authorization")?a.set("Authorization",`Bearer ${s}`):n&&!a.has("Authorization")&&a.set("Authorization",`Bearer ${n}`),{...t,credentials:t.credentials??"same-origin",headers:a}}function vs(t,a){const s=t.originalName.trim();if(s)return s;const n=t.file.name.trim();return n||(t.kind==="photo"?`photo-${a+1}.jpg`:`file-${a+1}`)}function co(){return U("/api/config/runtime")}function uo(){return U("/api/auth/session",{cache:"no-store"})}async function mo(t){const a=await U("/api/auth/login",{method:"POST",body:JSON.stringify(t)});return so(a.token??null),a}function ht(){return U("/relay/auth/session",{credentials:"same-origin"})}async function ho(t){rt();const a=await U("/relay/auth/login",{method:"POST",body:JSON.stringify(t)});return xa(a.token),a}async function fo(t){rt();const a=await U("/relay/auth/register",{method:"POST",body:JSON.stringify(t)});return xa(a.token),a}async function nr(){const t=await U("/relay/auth/logout",{method:"POST"});return xa(null),Pt(null),Ot(null),t}function or(){return U("/relay/portal")}function lr(t){return U("/relay/devices",{method:"POST",body:JSON.stringify(t)})}function ir(t){return U(`/relay/devices/${encodeURIComponent(t)}`,{method:"DELETE"})}function po(t){return U("/relay/account",{method:"PATCH",body:JSON.stringify(t)})}function xo(t){return U("/relay/account/password",{method:"PATCH",body:JSON.stringify(t)})}function go(t){return U("/relay/shares",{method:"POST",body:JSON.stringify(t)})}function bo(t){return U(`/relay/shares/${encodeURIComponent(t)}`,{method:"DELETE"})}function vo(){return U("/relay/admin")}function yo(t){return U("/relay/admin/settings/registration",{method:"PATCH",body:JSON.stringify({enabled:t})})}function wo(t,a){return U(`/relay/admin/users/${encodeURIComponent(t)}`,{method:"PATCH",body:JSON.stringify({enabled:a})})}function jo(){return U("/api/config/workspace-settings",{cache:"no-store"})}function No(t){return U("/api/config/workspace-settings",{method:"PATCH",body:JSON.stringify(t)})}function Ut(){return U("/api/agent-runtimes",{cache:"no-store"})}function dr(t){return U(`/api/agent-runtimes/${encodeURIComponent(t)}/status`,{cache:"no-store"})}function ko(t){return U(`/api/agent-runtimes/${encodeURIComponent(t)}/restart`,{method:"POST"})}function cr(t,a){return U(`/api/agent-runtimes/${encodeURIComponent(t)}/install`,{method:"POST",body:JSON.stringify({action:a})})}function It(t){return U(`/api/agent-runtimes/${encodeURIComponent(t)}/models`,{cache:"no-store"})}function ur(t,a){return U(`/api/config/providers/${encodeURIComponent(t)}/files/${encodeURIComponent(a)}`,{cache:"no-store"})}function mr(t,a,s){return U(`/api/config/providers/${encodeURIComponent(t)}/files/${encodeURIComponent(a)}`,{method:"PATCH",body:JSON.stringify(s)})}function So(t){return U(`/api/config/providers/${encodeURIComponent(t)}/archives`,{cache:"no-store"})}function Co(t,a={}){return U(`/api/config/providers/${encodeURIComponent(t)}/archives`,{method:"POST",body:JSON.stringify(a)})}function To(t,a,s){return U(`/api/config/providers/${encodeURIComponent(t)}/archives/${encodeURIComponent(a)}`,{method:"PATCH",body:JSON.stringify(s)})}function Eo(t,a){return U(`/api/config/providers/${encodeURIComponent(t)}/archives/${encodeURIComponent(a)}/apply`,{method:"POST"})}function Io(){return U("/api/service/build-restart",{method:"POST"})}function Ro(){return U("/healthz",{cache:"no-store"})}function ba(){return U("/api/workspaces")}function Ao(t,a={}){const s=new URLSearchParams;a.path&&s.set("path",a.path);const n=s.size>0?`?${s.toString()}`:"";return U(`/api/workspaces/${encodeURIComponent(t)}/files/tree${n}`,{cache:"no-store"})}function Po(t,a){const s=new URLSearchParams({path:a.path});return a.offset!==void 0&&s.set("offset",String(a.offset)),a.limit!==void 0&&s.set("limit",String(a.limit)),U(`/api/workspaces/${encodeURIComponent(t)}/files/preview?${s.toString()}`,{cache:"no-store"})}function Oo(t,a){const s=new URLSearchParams({path:a.path});return tr(`/api/workspaces/${encodeURIComponent(t)}/files/raw?${s.toString()}`)}function Uo(t,a){const s=new URLSearchParams({path:a.path});return tr(`/api/threads/${encodeURIComponent(t)}/assets/image?${s.toString()}`)}function Lo(t,a){const s=new URLSearchParams({path:a.path});return sr(`/api/workspaces/${encodeURIComponent(t)}/files/download?${s.toString()}`,{cache:"no-store"})}function Do(t,a){const s=new FormData;return s.append("file",a.file,a.file.name),U(`/api/workspaces/${encodeURIComponent(t)}/files/upload`,{method:"POST",body:s})}function $o(t,a){return U(`/api/workspaces/${encodeURIComponent(t)}/files`,{method:"PUT",body:JSON.stringify(a)})}function va(){return U("/api/threads")}function ys(t,a={}){const s=new URLSearchParams;return a.limit!==void 0&&s.set("limit",String(a.limit)),a.beforeTurnId&&s.set("beforeTurnId",a.beforeTurnId),U(`/api/threads/${t}${s.size>0?`?${s.toString()}`:""}`)}function Mo(t,a){return U(`/api/threads/${t}/items/${encodeURIComponent(a)}/detail`)}function Ho(){return U("/api/plugins",{cache:"no-store"})}function Bo(t){return U("/api/plugins/import",{method:"POST",body:JSON.stringify(t)})}function _o(t,a){return U(`/api/plugins/${encodeURIComponent(t)}`,{method:"PATCH",body:JSON.stringify(a)})}function Fo(t){return U(`/api/plugins/${encodeURIComponent(t)}`,{method:"DELETE"})}function qo(t){return U(`/api/threads/${t}/export-turns`,{cache:"no-store"})}function Wo(t,a){var n,l,i;const s=new URLSearchParams;return a.format!==void 0&&s.set("format",a.format),s.set("mode",a.mode),a.limit!==void 0&&s.set("limit",String(a.limit)),a.turnIds!==void 0&&s.set("turnIds",a.turnIds.join(",")),a.profile!==void 0&&s.set("profile",a.profile),((n=a.options)==null?void 0:n.includeTokenAndPrice)!==void 0&&s.set("includeTokenAndPrice",String(a.options.includeTokenAndPrice)),((l=a.options)==null?void 0:l.includeCommandOutput)!==void 0&&s.set("includeCommandOutput",String(a.options.includeCommandOutput)),((i=a.options)==null?void 0:i.includeAbsolutePaths)!==void 0&&s.set("includeAbsolutePaths",String(a.options.includeAbsolutePaths)),`/api/threads/${encodeURIComponent(t)}/exports/pdf?${s.toString()}`}function zo(t,a){return sr(Wo(t,a),{cache:"no-store"})}function Go(t){return U(`/api/threads/${t}/shell`)}function Vo(t){return U("/api/threads/start",{method:"POST",body:JSON.stringify(t)})}function Jo(t){return U("/api/threads/import",{method:"POST",body:JSON.stringify(typeof t=="string"?{sessionId:t}:t)})}function Ko(t,a={}){return U(`/api/threads/${t}/shell`,{method:"POST",...Object.keys(a).length>0?{body:JSON.stringify(a)}:{}})}function Yo(t){return U(`/api/shells/${t}/terminate`,{method:"POST"})}function Zo(t,a){return U(`/api/shells/${t}`,{method:"PATCH",body:JSON.stringify(a)})}function ws(t,a={}){return U(`/api/threads/${t}/resume`,{method:"POST",...Object.keys(a).length>0?{body:JSON.stringify(a)}:{}})}function Xo(t){return U(`/api/threads/${t}/disconnect`,{method:"POST"})}function Qo(t,a){const s=a.attachments??[];if(s.length===0)return U(`/api/threads/${t}/prompt`,{method:"POST",body:JSON.stringify(a)});const n=new FormData;n.append("prompt",a.prompt),a.clientRequestId!==void 0&&n.append("clientRequestId",a.clientRequestId),a.model!==void 0&&n.append("model",a.model),a.reasoningEffort!==void 0&&a.reasoningEffort!==null&&n.append("reasoningEffort",a.reasoningEffort),a.collaborationMode!==void 0&&n.append("collaborationMode",a.collaborationMode);const l=s.map((i,u)=>({clientId:i.clientId,kind:i.kind,originalName:vs(i,u),placeholder:i.placeholder}));n.append("attachmentManifest",JSON.stringify(l));for(const[i,u]of s.entries())n.append("attachments",u.file,vs(u,i));return U(`/api/threads/${t}/prompt`,{method:"POST",body:n})}function js(t,a={}){return U(`/api/threads/${t}/interrupt`,{method:"POST",body:JSON.stringify(a)})}function hr(t,a){return U(`/api/threads/${t}`,{method:"PATCH",body:JSON.stringify(a)})}function fr(t){return U(`/api/threads/${t}`,{method:"DELETE"})}function el(t,a){return U(`/api/threads/${t}/pending-steers/${encodeURIComponent(a)}`,{method:"DELETE"})}function tl(t,a){return U(`/api/threads/${t}/settings`,{method:"PATCH",body:JSON.stringify(a)})}function al(t){return U(`/api/threads/${t}/compact`,{method:"POST"})}function sl(t){return U(`/api/threads/${t}/goal`,{cache:"no-store"})}function rl(t,a){return U(`/api/threads/${t}/goal`,{method:"PATCH",body:JSON.stringify(a)})}function nl(t){return U(`/api/threads/${t}/goal`,{method:"DELETE"})}function ol(t){return U(`/api/threads/${t}/fork-turns`,{cache:"no-store"})}function Ns(t,a){return U(`/api/threads/${t}/fork`,{method:"POST",body:JSON.stringify(a)})}function ll(t){return U(`/api/threads/${t}/skills`,{cache:"no-store"})}function il(t){return U(`/api/threads/${t}/mcp-servers`,{cache:"no-store"})}function dl(t){return U(`/api/threads/${t}/hooks`,{cache:"no-store"})}function cl(t,a){return U(`/api/threads/${t}/hooks`,{method:"POST",body:JSON.stringify(a)})}function ul(t,a){return U(`/api/threads/${t}/hooks`,{method:"PUT",body:JSON.stringify(a)})}function ml(t,a){return U(`/api/threads/${t}/hooks/trust`,{method:"POST",body:JSON.stringify(a)})}function hl(t,a){return U(`/api/threads/${t}/hooks/untrust`,{method:"POST",body:JSON.stringify(a)})}function fl(t,a,s){return U(`/api/threads/${t}/requests/${encodeURIComponent(a)}/respond`,{method:"POST",body:JSON.stringify(s)})}function pl(t){return U("/api/workspaces",{method:"POST",body:JSON.stringify(t)})}function xl(t,a){return U(`/api/workspaces/${t}`,{method:"PATCH",body:JSON.stringify(a)})}function gl(t,a){return U(`/api/workspaces/${t}`,{method:"DELETE",body:JSON.stringify(a)})}function bl(t,a){return U(`/api/workspaces/${t}/favorite`,{method:"POST",body:JSON.stringify(a)})}function pr(t){const a=window.location.protocol==="https:"?"wss:":"ws:",s=new WebSocket(xr(a));return s.addEventListener("message",n=>{try{const l=JSON.parse(n.data);yl(l)&&t(l)}catch{}}),s}function vl(t={}){const a=window.location.protocol==="https:"?"wss:":"ws:",s=new WebSocket(xr(a));return s.addEventListener("message",n=>{var l,i;try{const u=JSON.parse(n.data);if(u.type==="supervisor.connected"){(l=t.onConnected)==null||l.call(t,u);return}wl(u)&&((i=t.onShellEvent)==null||i.call(t,u))}catch{}}),{socket:s,send(n){s.send(JSON.stringify(n))}}}function xr(t){const a=new URL(`${t}//${window.location.host}/ws`);if(at()){const i=er();a.pathname=i?`/relay/devices/${encodeURIComponent(i)}/ws`:"/relay/ws"}const s=Xs(),n=Qs(),l=ro();return at()&&n&&a.searchParams.set("relaySession",n),at()&&l&&a.searchParams.set("threadId",l),s&&a.searchParams.set("token",s),a.toString()}function yl(t){return"threadId"in t&&t.type.startsWith("thread.")&&typeof t.payload=="object"&&t.payload!==null}function wl(t){return"shellId"in t&&t.type.startsWith("shell.")&&typeof t.payload=="object"&&t.payload!==null}function ya({embedded:t=!1}={}){const a=Ye(),s=Gs(),[n,l]=r.useState(""),[i,u]=r.useState({busy:!1,message:null,error:null}),[h,g]=r.useState(!1),[b,T]=r.useState(null),[c,I]=r.useState({}),j=b?c[b]:null,[L,P]=r.useState({busy:!1,message:null,error:null}),[q,F]=r.useState([]),[D,R]=r.useState(tt),[w,H]=r.useState({loading:!1,saving:!1,error:null,operatingProvider:null,operatingAction:null,message:null}),[o,B]=r.useState(null),[ae,J]=r.useState({devHomeDraft:"",loading:!1,saving:!1,message:null,error:null}),[Z,W]=r.useState({loading:!1,creating:!1,applyingId:null,renamingId:null,renameDraft:"",message:null,error:null}),le=(a==null?void 0:a.themeMode)??"system",me=t||!!(a!=null&&a.settingsOpen);async function ge(){const m=n.trim();if(!(!m||i.busy)){u({busy:!0,message:null,error:null});try{await s.importPluginManifest({manifestJson:m,enabled:!0}),l(""),u({busy:!1,message:"Plugin manifest imported.",error:null})}catch(x){u({busy:!1,message:null,error:x instanceof Error?x.message:"Unable to import plugin manifest."})}}}const je=(a==null?void 0:a.effectiveTheme)??"dark",C=(a==null?void 0:a.autoCollapseCompletedTurns)??!0,ne=(a==null?void 0:a.defaultBackend)??Vs,de=s.plugins.filter(m=>m.enabled).length,f=s.loading?"Loading...":`${de}/${s.plugins.length} enabled`,S=D.find(m=>m.provider===ne)??tt.find(m=>m.provider===ne)??tt[0],V=S.managementSchema??Vn(S.provider),K=V.hostConfigFiles;r.useEffect(()=>{if(!me||t||!a||!V.configArchives)return;const m=a;function x(A){A.key==="Escape"&&m.closeSettings()}return window.addEventListener("keydown",x),()=>{window.removeEventListener("keydown",x)}},[V.configArchives,t,me,a]),r.useEffect(()=>{if(!me)return;let m=!1;return H(x=>({...x,loading:!0,error:null})),Ut().then(x=>{if(m)return;const A=[...x.map(Jt),...tt.filter(z=>!x.some(ce=>ce.provider===z.provider))];R(A),H(z=>({...z,loading:!1}))}).catch(x=>{m||(R(tt),H(A=>({...A,loading:!1,error:x instanceof Y?x.message:"Unable to load backend settings."})))}),()=>{m=!0}},[me]),r.useEffect(()=>{if(!me)return;let m=!1;return J(x=>({...x,loading:!0,message:null,error:null})),jo().then(x=>{m||(B(x),J(A=>({...A,devHomeDraft:x.devHome,loading:!1})))}).catch(x=>{m||J(A=>({...A,loading:!1,error:x instanceof Y?x.message:"Unable to load workspace settings."}))}),()=>{m=!0}},[me]),r.useEffect(()=>{if(!me||!S.capabilities.management.hostConfigFiles)return;let m=!1;async function x(){I(z=>{const ce={...z};for(const Ne of K)ce[Ne.name]={...it(Ne.name),...z[Ne.name],loading:!0,saving:!1,error:null,saveMessage:null};return ce});const A=await Promise.allSettled(K.map(async z=>({name:z.name,result:await ur(S.provider,z.name)})));m||I(z=>{var Ne,Fe;const ce={...z};for(const qe of A){if(qe.status==="fulfilled"){const{name:gt,result:Ve}=qe.value;ce[gt]={path:Ve.path,exists:Ve.exists,originalContent:Ve.content,draftContent:Ve.content,loading:!1,saving:!1,error:null,saveMessage:null};continue}const xt=qe.reason instanceof Y?qe.reason.message:"Unable to load the file.",Be=((Ne=K[A.indexOf(qe)])==null?void 0:Ne.name)??((Fe=K[0])==null?void 0:Fe.name);Be&&(ce[Be]={...it(Be),...ce[Be],loading:!1,saving:!1,error:xt,saveMessage:null})}return ce})}return x(),()=>{m=!0}},[S.capabilities.management.hostConfigFiles,S.provider,K,me]),r.useEffect(()=>{if(!me)return;let m=!1;async function x(){W(A=>({...A,loading:!0,error:null,message:null}));try{const A=await So(S.provider);if(m)return;F(A),W(z=>({...z,loading:!1}))}catch(A){if(m)return;W(z=>({...z,loading:!1,error:A instanceof Y?A.message:"Unable to load config archives."}))}}return x(),()=>{m=!0}},[S.provider,V.configArchives,me]);async function oe(){if(!(L.busy||w.saving)){P({busy:!0,message:null,error:null});try{const m=await ko(S.provider),x=Jt(m);P({busy:!1,message:x.status.state==="ready"?`${x.displayName} backend restarted.`:`${x.displayName} backend state: ${x.status.state}`,error:null}),R(A=>A.map(z=>z.provider===x.provider?x:z))}catch(m){P({busy:!1,message:null,error:m instanceof Y?m.message:"Unable to restart the app server."})}}}async function ye(m,x){if(L.busy||w.saving)return;const A=D.find(z=>z.provider===m);H(z=>({...z,saving:!0,operatingProvider:m,operatingAction:x,message:null,error:null}));try{const z=await cr(m,x),ce=Jt(z);R(Ne=>Ne.map(Fe=>Fe.provider===ce.provider?ce:Fe)),H(Ne=>({...Ne,saving:!1,operatingProvider:null,operatingAction:null,message:ce.installation.lastError?`${ce.displayName} ${x==="install"?"installed":"updated"}, but requires attention:
|
|
4
4
|
${ce.installation.lastError}`:`${ce.displayName} ${x==="install"?"installed":"updated"}.`,error:null}))}catch(z){H(ce=>({...ce,saving:!1,operatingProvider:null,operatingAction:null,message:null,error:z instanceof Y?Kn(z):`Unable to ${x} ${(A==null?void 0:A.displayName)??m}.`}))}}async function Ie(){if(!(L.busy||w.saving)){P({busy:!0,message:null,error:null});try{await Io(),P({busy:!1,message:"Build and restart launched. The page may disconnect briefly.",error:null})}catch(m){P({busy:!1,message:null,error:m instanceof Y?m.message:"Unable to launch build and restart."})}}}async function Ce(){const m=ae.devHomeDraft.trim();if(!(!m||ae.saving)){J(x=>({...x,saving:!0,message:null,error:null}));try{const x=await No({devHome:m});B(x),J(A=>({...A,devHomeDraft:x.devHome,saving:!1,message:"Workspace defaults saved."}))}catch(x){J(A=>({...A,saving:!1,error:x instanceof Y?x.message:"Unable to save workspace settings."}))}}}async function Me(m){const x=c[m];if(!(!x||x.saving)){I(A=>({...A,[m]:{...it(m),...A[m],saving:!0,error:null,saveMessage:null}}));try{const A=await mr(S.provider,m,{content:x.draftContent});I(z=>({...z,[m]:{path:A.path,exists:A.exists,originalContent:A.content,draftContent:A.content,loading:!1,saving:!1,error:null,saveMessage:"Saved"}}))}catch(A){I(z=>({...z,[m]:{...it(m),...z[m],saving:!1,error:A instanceof Y?A.message:"Unable to save the file.",saveMessage:null}}))}}}async function Oe(){if(!Z.creating){W(m=>({...m,creating:!0,message:null,error:null}));try{const m=await Co(S.provider);F(x=>[m,...x]),W(x=>({...x,creating:!1,message:"Backup created."}))}catch(m){W(x=>({...x,creating:!1,error:m instanceof Y?m.message:"Unable to create a config backup."}))}}}async function O(m){if(!Z.applyingId){W(x=>({...x,applyingId:m.id,message:null,error:null}));try{const x=await Eo(S.provider,m.id);W(A=>({...A,applyingId:null,message:x.status.state==="ready"?`Applied "${x.archive.label}" and restarted ${S.displayName}.`:`Applied "${x.archive.label}". ${S.displayName} state: ${x.status.state}.`}))}catch(x){W(A=>({...A,applyingId:null,error:x instanceof Y?x.message:"Unable to apply the config archive."}))}}}async function k(m){const x=Z.renameDraft.trim();if(!(!x||Z.renamingId!==m.id)){W(A=>({...A,message:null,error:null}));try{const A=await To(S.provider,m.id,{label:x});F(z=>z.map(ce=>ce.id===m.id?A:ce)),W(z=>({...z,renamingId:null,renameDraft:"",message:"Backup renamed."}))}catch(A){W(z=>({...z,error:A instanceof Y?A.message:"Unable to rename the config backup."}))}}}if(!me)return null;const Q=e.jsxs(e.Fragment,{children:[e.jsxs("div",{className:"mt-3 grid gap-2",children:[s.plugins.map(m=>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:m.name}),e.jsx("span",{className:"mt-1 block text-xs leading-5 text-[var(--theme-fg-muted)]",children:m.description}),e.jsx("span",{className:"mt-2 block text-[10px] uppercase tracking-[0.16em] text-[var(--theme-fg-muted)]",children:[...m.capabilities.artifactTypes.map(x=>x.type),...m.capabilities.threadPanels.map(x=>x.kind??x.id)].join(", ")||"utility"}),e.jsx("span",{className:"mt-1 block text-[10px] uppercase tracking-[0.16em] text-[var(--theme-fg-muted)]",children:m.source==="imported"?"Imported manifest":"Built-in module"})]}),e.jsx("input",{type:"checkbox",checked:m.enabled,onChange:x=>void s.setPluginEnabled(m.id,x.currentTarget.checked),className:"mt-1 h-4 w-4 shrink-0 accent-[var(--theme-accent-solid)]"})]},m.id)),s.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:n,onChange:m=>{l(m.currentTarget.value),(i.message||i.error)&&u({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 ge(),disabled:!n.trim()||i.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:i.busy?"Importing...":"Import"})]}),i.error&&e.jsx("p",{className:"mt-2 text-xs text-rose-300",children:i.error}),i.message&&e.jsx("p",{className:"mt-2 text-xs text-emerald-300",children:i.message})]}),s.error&&e.jsx("p",{className:"mt-2 text-xs text-rose-300",children:s.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(Et,{})})]})}),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:"," ",je,"."]})]})}),e.jsx("div",{className:"mt-3 grid gap-2 sm:grid-cols-3",children:Wn.map(m=>{const x=le===m.value;return e.jsxs("button",{type:"button",onClick:()=>a==null?void 0:a.setThemeMode(m.value),className:`block rounded-[1rem] border px-3 py-2.5 text-left transition ${x?"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:m.label}),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:"Active"}):null]}),e.jsx("p",{className:"mt-1 text-xs leading-5 text-[var(--theme-fg-muted)]",children:m.description})]},m.value)})})]}),a!=null&&a.setAutoCollapseCompletedTurns?e.jsx("div",{className:"rounded-[1.1rem] border border-[var(--theme-border)] bg-[var(--theme-surface)] px-3 py-3",children:e.jsxs("div",{className:"flex items-start justify-between gap-4",children:[e.jsxs("div",{className:"min-w-0",children:[e.jsx("p",{className:"text-sm font-medium text-[var(--theme-fg)]",children:"Thread timeline"}),e.jsx("p",{className:"mt-1 text-xs leading-5 text-[var(--theme-fg-muted)]",children:"Collapse completed turns into prompt, elapsed work, and final reply."})]}),e.jsxs("label",{className:"inline-flex min-h-10 shrink-0 items-center gap-2 text-xs font-medium text-[var(--theme-fg-soft)]",children:[e.jsx("input",{type:"checkbox",checked:C,onChange:m=>{var x;return(x=a.setAutoCollapseCompletedTurns)==null?void 0:x.call(a,m.currentTarget.checked)},className:"h-4 w-4 accent-[var(--theme-accent-solid)]"}),e.jsx("span",{children:"Auto collapse"})]})]})}):null,e.jsxs("div",{className:"rounded-[1.1rem] border border-[var(--theme-border)] bg-[var(--theme-surface)] px-3 py-3",children:[e.jsxs("div",{className:"flex items-start justify-between gap-3",children:[e.jsxs("div",{className:"min-w-0",children:[e.jsx("p",{className:"text-sm font-medium text-[var(--theme-fg)]",children:"Plugins"}),e.jsx("p",{className:"mt-1 text-xs leading-5 text-[var(--theme-fg-muted)]",children:"Enable renderers and thread extensions loaded by this supervisor."})]}),e.jsx("button",{type:"button",onClick:()=>void s.refresh(),disabled:s.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:s.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:f}),e.jsx("button",{type:"button",onClick:()=>g(!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"})]}):Q]}),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:(o==null?void 0:o.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:ae.loading&&!o?"Loading...":(o==null?void 0:o.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:ae.devHomeDraft,onChange:m=>J(x=>({...x,devHomeDraft:m.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 Ce(),disabled:ae.loading||ae.saving||!ae.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:ae.saving?"Saving...":"Save"})]})]})]}),ae.error?e.jsx("p",{className:"mt-2 text-xs text-rose-300",children:ae.error}):ae.message?e.jsx("p",{className:"mt-2 text-xs text-emerald-300",children:ae.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 oe(),disabled:L.busy||w.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 Ie(),disabled:L.busy||w.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:D.map(m=>{const x=m.installation,A=!x.installed&&!!x.installCommand,z=x.installed&&!!x.updateCommand,ce=w.saving&&w.operatingProvider===m.provider,Ne=A?"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:m.displayName}),e.jsx("span",{className:`rounded-full border px-2 py-0.5 text-[10px] uppercase tracking-[0.16em] ${m.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:m.enabled?"Ready":x.installed?m.status.state:"Not installed"})]}),e.jsxs("p",{className:"mt-1 truncate text-xs text-[var(--theme-fg-muted)]",children:["Version:"," ",x.installedVersion??(x.installed?"Installed":"Unavailable"),x.latestVersion?` · Latest: ${x.latestVersion}`:""]}),x.lastError?e.jsx("p",{className:"mt-1 line-clamp-2 text-xs text-rose-300",children:x.lastError}):null]}),A||z?e.jsx("button",{type:"button","aria-label":`${A?"Install":"Update"} ${m.displayName}`,onClick:()=>void ye(m.provider,A?"install":"update"),disabled:L.busy||w.saving||!A&&!z,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:ce?w.operatingAction==="install"?"Installing...":"Updating...":Ne}):null]},m.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}):w.message?e.jsx("p",{className:`mt-2 whitespace-pre-line text-xs ${w.message.includes("requires attention")?"text-amber-300":"text-emerald-300"}`,children:w.message}):w.error?e.jsx("p",{className:"mt-2 whitespace-pre-line text-xs text-rose-300",children:w.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:[S.displayName," exposes these editable files through its backend schema."]})]})}),e.jsxs("div",{className:"mt-3 grid gap-2 sm:grid-cols-2",children:[K.map(m=>{const x=c[m.name]??{path:m.name,exists:!1,originalContent:"",draftContent:"",loading:!1},A=x.draftContent!==x.originalContent;return e.jsx("button",{type:"button",onClick:()=>T(m.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:m.label}),e.jsx("p",{className:"mt-1 text-xs leading-5 text-[var(--theme-fg-muted)]",children:m.description})]}),e.jsx("div",{className:"shrink-0",children:x.loading?e.jsx("span",{className:"text-[11px] uppercase tracking-[0.2em] text-[var(--theme-fg-muted)]",children:"Loading"}):A?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"}):x.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"})})]})},m.name)}),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:"This backend does not expose editable host files."}):null]})]}),V.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 Oe(),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..."}):q.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."}):q.map(m=>{const x=Z.renamingId===m.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:[x?e.jsxs("div",{className:"flex max-w-xl gap-2",children:[e.jsx("input",{"aria-label":`Rename ${m.label}`,value:Z.renameDraft,onChange:A=>W(z=>({...z,renameDraft:A.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 ${m.label}`,onClick:()=>void k(m),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:()=>W(A=>({...A,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:m.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 ",Jn(m.createdAt)]}),K.map(A=>{var z;return e.jsxs("span",{className:"rounded-full border border-[var(--theme-border)] bg-[var(--theme-panel)] px-2 py-0.5 font-mono",children:[A.name,":"," ",(z=m.files[A.name])!=null&&z.exists?"saved":"missing"]},A.name)})]})]}),e.jsxs("div",{className:"flex shrink-0 flex-wrap gap-2",children:[e.jsx("button",{type:"button",onClick:()=>W(A=>({...A,renamingId:m.id,renameDraft:m.label,message:null,error:null})),disabled:x,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 O(m),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===m.id?"Applying...":"Apply"})]})]})},m.id)})})]}):null]})})]});return t?e.jsxs("div",{className:"flex min-h-0 flex-col overflow-hidden",children:[He,h?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:()=>g(!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:f})]}),e.jsxs("div",{className:"flex shrink-0 items-center gap-2",children:[e.jsx("button",{type:"button",onClick:()=>void s.refresh(),disabled:s.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:s.loading?"Loading...":"Refresh"}),e.jsx("button",{type:"button","aria-label":"Close plugins panel",onClick:()=>g(!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(Et,{})})]})]}),e.jsx("div",{className:"min-h-0 flex-1 overflow-y-auto p-4",children:Q})]})]}):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}),b&&j?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:b}),e.jsx("p",{className:"mt-1 break-all font-mono text-xs text-[var(--theme-fg-muted)]",children:j.path})]}),e.jsxs("div",{className:"flex items-center gap-2",children:[j.error?e.jsx("span",{className:"text-xs text-rose-300",children:j.error}):j.saveMessage?e.jsx("span",{className:"text-xs text-emerald-300",children:j.saveMessage}):null,e.jsx("button",{type:"button","aria-label":`Save ${b}`,onClick:()=>void Me(b),disabled:j.loading||j.saving||j.draftContent===j.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:j.saving?"Saving...":"Save"}),e.jsx("button",{type:"button","aria-label":"Close File Editor",onClick:()=>T(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(Et,{})})]})]}),e.jsx("div",{className:"min-h-0 flex-1 overflow-y-auto p-4 sm:p-5",children:e.jsx("textarea",{"aria-label":`Edit ${b}`,value:j.draftContent,onChange:m=>I(x=>({...x,[b]:{...it(b),...x[b],draftContent:m.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:j.loading?"Loading...":`Edit ${b} here`})})]})}):null]})}function gr({className:t=""}){const a=Ye();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(Et,{}):e.jsx(qn,{})}):null}function br({className:t=""}){const a=Ye(),s=ma(),n=Pe(),l=r.useRef(null),i=s.pathname==="/workspaces"||/^\/devices\/[^/]+\/workspaces$/.test(s.pathname),u=s.pathname==="/threads/import"||/^\/devices\/[^/]+\/threads\/import$/.test(s.pathname);return r.useEffect(()=>{if(!(a!=null&&a.navOpen))return;const h=a;function g(b){const T=b.target;if(!T)return;const c=l.current;c!=null&&c.contains(T)||T instanceof Element&&T.closest('[aria-controls="app-shell-navigation-menu"]')||h.closeNav()}return document.addEventListener("pointerdown",g),()=>{document.removeEventListener("pointerdown",g)}},[a]),a!=null&&a.navOpen?e.jsxs("div",{ref:l,id:"app-shell-navigation-menu",onPointerDown:h=>{h.stopPropagation()},onMouseDown:h=>{h.stopPropagation()},onTouchStart:h=>{h.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:i,onClick:()=>{i||(a.closeNav(),n(pt()))},className:Vt(i),children:"Workspaces"}),e.jsx("button",{type:"button",disabled:u,onClick:()=>{u||(a.closeNav(),n(na("/threads/import")))},className:Vt(u),children:"Import Session"}),e.jsx("button",{type:"button",onClick:()=>{a.openSettings()},className:Vt(),children:"Settings"})]})]}):null}function jl(t){const a=(t==null?void 0:t.trim())??"";return a?Array.from(a).slice(0,2).join("").toUpperCase():"??"}function wa(){const t=Pe(),a=ma(),[s,n]=r.useState(null),[l,i]=r.useState(!1);r.useEffect(()=>{if(!ca())return;let b=!1;return ht().then(T=>{b||n(T.authenticated?T:null)}).catch(()=>{b||n(null)}),()=>{b=!0}},[a.pathname]),r.useEffect(()=>{i(!1)},[a.pathname]);const u=(s==null?void 0:s.user)??null,h=r.useMemo(()=>jl(u==null?void 0:u.username),[u==null?void 0:u.username]);if(!ca()||!u)return null;async function g(){await nr(),n(null),t("/relay-portal")}return e.jsxs("div",{className:"fixed right-3 top-[calc(env(safe-area-inset-top)+0.55rem)] z-50",children:[e.jsx("button",{"aria-expanded":l,"aria-haspopup":"menu","aria-label":`Relay account menu for ${u.username}`,className:"inline-flex h-10 w-10 items-center justify-center rounded-full border border-[var(--theme-border)] bg-[var(--theme-panel)] text-sm font-semibold text-[var(--theme-fg)] shadow-lg transition hover:bg-[var(--theme-hover)] focus:outline-none focus:ring-2 focus:ring-[var(--theme-accent-ring)]",onClick:()=>i(b=>!b),type:"button",children:h}),l?e.jsxs("div",{className:"absolute right-0 mt-2 w-64 overflow-hidden rounded-xl border border-[var(--theme-border)] bg-[var(--theme-panel)] p-1 shadow-xl",role:"menu",children:[e.jsxs("div",{className:"border-b border-[var(--theme-border)] px-3 py-2",children:[e.jsx("p",{className:"truncate text-sm font-medium text-[var(--theme-fg)]",children:u.username}),e.jsx("p",{className:"truncate text-xs text-[var(--theme-fg-muted)]",children:u.email})]}),e.jsxs($e,{className:"flex items-center gap-2 rounded-lg px-3 py-2 text-sm text-[var(--theme-fg)] transition hover:bg-[var(--theme-hover)]",role:"menuitem",to:"/relay-account",children:[e.jsx(Se.Settings,{className:"h-4 w-4"}),"Account settings"]}),e.jsxs($e,{className:"flex items-center gap-2 rounded-lg px-3 py-2 text-sm text-[var(--theme-fg)] transition hover:bg-[var(--theme-hover)]",role:"menuitem",to:"/relay-devices",children:[e.jsx(Se.MonitorSmartphone,{className:"h-4 w-4"}),"Device management"]}),e.jsxs("button",{className:"flex w-full items-center gap-2 rounded-lg px-3 py-2 text-left text-sm text-[var(--status-danger-fg)] transition hover:bg-[var(--status-danger-bg)]",onClick:()=>void g(),role:"menuitem",type:"button",children:[e.jsx(Se.LogOut,{className:"h-4 w-4"}),"Logout"]})]}):null]})}function Nl({onLogin:t}){const[a,s]=r.useState(""),[n,l]=r.useState(""),[i,u]=r.useState(null),[h,g]=r.useState(!1);async function b(T){T.preventDefault(),u(null),g(!0);try{await t({username:a,password:n})}catch(c){c instanceof Y?u(c.payload.message):u("Unable to sign in.")}finally{g(!1)}}return e.jsx("main",{className:"flex min-h-screen items-center justify-center bg-[var(--app-bg)] px-4 py-8 text-[var(--app-fg)]",children:e.jsxs("section",{className:"w-full max-w-sm rounded-[1.35rem] border border-[var(--theme-border)] bg-[var(--theme-panel)] p-5 shadow-2xl shadow-[color-mix(in_oklch,var(--app-fg)_14%,transparent)] sm:p-6",children:[e.jsxs("div",{className:"mb-5",children:[e.jsx("p",{className:"text-xs font-semibold uppercase tracking-[0.22em] text-[var(--theme-muted)]",children:"Supervisor Access"}),e.jsx("h1",{className:"mt-2 text-2xl font-semibold tracking-normal text-[var(--theme-fg)]",children:"Sign in"}),e.jsx("p",{className:"mt-2 text-sm leading-6 text-[var(--theme-muted)]",children:"Use the admin credentials configured on this Remote Codex server."})]}),e.jsxs("form",{onSubmit:b,className:"space-y-4",children:[e.jsxs("label",{className:"block",children:[e.jsx("span",{className:"text-sm font-medium text-[var(--theme-fg-soft)]",children:"Username"}),e.jsx("input",{autoComplete:"username",autoFocus:!0,className:"mt-2 h-11 w-full rounded-xl border border-[var(--theme-border)] bg-[var(--theme-surface)] px-3 text-sm text-[var(--theme-fg)] outline-none transition focus:border-[var(--theme-accent-solid)] focus:ring-2 focus:ring-[var(--theme-accent-border)]",disabled:h,name:"username",onChange:T=>s(T.target.value),value:a})]}),e.jsxs("label",{className:"block",children:[e.jsx("span",{className:"text-sm font-medium text-[var(--theme-fg-soft)]",children:"Password"}),e.jsx("input",{autoComplete:"current-password",className:"mt-2 h-11 w-full rounded-xl border border-[var(--theme-border)] bg-[var(--theme-surface)] px-3 text-sm text-[var(--theme-fg)] outline-none transition focus:border-[var(--theme-accent-solid)] focus:ring-2 focus:ring-[var(--theme-accent-border)]",disabled:h,name:"password",onChange:T=>l(T.target.value),type:"password",value:n})]}),i&&e.jsx("p",{className:"rounded-xl border border-[var(--status-danger-border)] bg-[var(--status-danger-bg)] px-3 py-2 text-sm text-[var(--status-danger-fg)]",children:i}),e.jsx("button",{className:"h-11 w-full rounded-xl bg-[var(--theme-accent-solid)] px-4 text-sm font-semibold text-[var(--theme-accent-solid-fg)] transition hover:bg-[var(--theme-accent-solid-hover)] focus:outline-none focus:ring-2 focus:ring-[var(--theme-accent-border)] disabled:cursor-not-allowed disabled:opacity-60",disabled:h||!a.trim()||!n,type:"submit",children:h?"Signing in...":"Sign in"})]})]})})}function Kt(t,a){return t instanceof Y?t.payload.message:t instanceof Error?t.message:a}function kl(){var J;const[t,a]=r.useState(null),[s,n]=r.useState(""),[l,i]=r.useState(""),[u,h]=r.useState(""),[g,b]=r.useState(""),[T,c]=r.useState(!0),[I,j]=r.useState(!1),[L,P]=r.useState(!1),[q,F]=r.useState(null),[D,R]=r.useState(null),[w,H]=r.useState(!1);async function o(){var Z;c(!0),R(null);try{rt();const W=await ht();a(W),n(((Z=W.user)==null?void 0:Z.username)??"")}catch(W){R(Kt(W,"Unable to load account."))}finally{c(!1)}}r.useEffect(()=>{o()},[]);async function B(Z){Z.preventDefault(),j(!0),R(null),F(null);try{const W=await po({username:s});a(le=>le!=null&&le.authenticated?{...le,user:W}:le),n(W.username),F("Account updated.")}catch(W){R(Kt(W,"Unable to update account."))}finally{j(!1)}}async function ae(Z){Z.preventDefault(),P(!0),R(null),F(null);try{if(u!==g){R("New passwords do not match.");return}await xo({currentPassword:l,newPassword:u}),i(""),h(""),b(""),F("Password changed.")}catch(W){R(Kt(W,"Unable to change password."))}finally{P(!1)}}return e.jsx("main",{className:"min-h-screen bg-[var(--app-bg)] px-4 py-6 text-[var(--app-fg)] sm:px-6",children:e.jsxs("div",{className:"mx-auto w-full max-w-4xl space-y-5 pr-12 sm:pr-0",children:[e.jsxs("header",{className:"border-b border-[var(--theme-border)] pb-5",children:[e.jsx($e,{className:"text-sm text-[var(--theme-accent-strong)]",to:"/workspaces",children:"Back to workspaces"}),e.jsx("p",{className:"mt-4 text-xs font-semibold uppercase tracking-[0.22em] text-[var(--theme-fg-muted)]",children:"Relay Account"}),e.jsx("h1",{className:"mt-2 text-2xl font-semibold text-[var(--theme-fg)]",children:"Account settings"})]}),T?e.jsx("section",{className:"rounded-lg border border-[var(--theme-border)] bg-[var(--theme-panel)] p-4 text-sm text-[var(--theme-fg-muted)]",children:"Loading account..."}):t!=null&&t.authenticated?e.jsxs(e.Fragment,{children:[D?e.jsx(ks,{tone:"danger",children:D}):null,q?e.jsx(ks,{tone:"success",children:q}):null,e.jsxs("section",{className:"rounded-lg border border-[var(--theme-border)] bg-[var(--theme-panel)] p-4",children:[e.jsxs("div",{className:"mb-4",children:[e.jsx("h2",{className:"text-base font-semibold text-[var(--theme-fg)]",children:"Profile"}),e.jsx("p",{className:"mt-1 text-sm text-[var(--theme-fg-muted)]",children:"Username changes apply to future shares and login."})]}),e.jsxs("form",{className:"space-y-4",onSubmit:B,children:[e.jsxs("label",{className:"block text-sm text-[var(--theme-fg-soft)]",children:["Email",e.jsx("input",{className:"relay-input mt-2 w-full",disabled:!0,readOnly:!0,value:((J=t.user)==null?void 0:J.email)??""})]}),e.jsxs("div",{className:"flex flex-col gap-2 sm:flex-row sm:items-end",children:[e.jsxs("label",{className:"block flex-1 text-sm text-[var(--theme-fg-soft)]",children:["Username",e.jsx("input",{className:"relay-input mt-2 w-full",onChange:Z=>n(Z.target.value),value:s})]}),e.jsxs("button",{className:"relay-button-primary inline-flex h-10 items-center justify-center gap-2",disabled:I||!s.trim(),type:"submit",children:[e.jsx(Se.Save,{className:"h-4 w-4"}),"Save"]})]}),e.jsxs("button",{className:"relay-button-secondary inline-flex items-center gap-2",onClick:()=>H(!0),type:"button",children:[w?e.jsx(Se.CheckCircle2,{className:"h-4 w-4"}):e.jsx(Se.MailCheck,{className:"h-4 w-4"}),w?"Verification queued":"Verify email"]})]})]}),e.jsxs("section",{className:"rounded-lg border border-[var(--theme-border)] bg-[var(--theme-panel)] p-4",children:[e.jsxs("div",{className:"mb-4",children:[e.jsx("h2",{className:"text-base font-semibold text-[var(--theme-fg)]",children:"Password"}),e.jsx("p",{className:"mt-1 text-sm text-[var(--theme-fg-muted)]",children:"Use at least 8 characters."})]}),e.jsxs("form",{className:"grid gap-4 sm:grid-cols-3",onSubmit:ae,children:[e.jsx(Yt,{label:"Current password",value:l,onChange:i}),e.jsx(Yt,{label:"New password",value:u,onChange:h}),e.jsx(Yt,{label:"Confirm password",value:g,onChange:b}),e.jsxs("button",{className:"relay-button-primary inline-flex h-10 items-center justify-center gap-2 sm:col-span-3 sm:w-fit",disabled:L||!l||u.length<8||!g,type:"submit",children:[e.jsx(Se.Save,{className:"h-4 w-4"}),"Change password"]})]})]})]}):e.jsx("section",{className:"rounded-lg border border-[var(--status-danger-border)] bg-[var(--status-danger-bg)] p-4 text-sm text-[var(--status-danger-fg)]",children:"Relay login is required."})]})})}function Yt({label:t,value:a,onChange:s}){return e.jsxs("label",{className:"block text-sm text-[var(--theme-fg-soft)]",children:[t,e.jsx("input",{autoComplete:"new-password",className:"relay-input mt-2 w-full",onChange:n=>s(n.target.value),type:"password",value:a})]})}function ks({tone:t,children:a}){return e.jsx("div",{className:`rounded-lg border px-3 py-2 text-sm ${t==="danger"?"border-[var(--status-danger-border)] bg-[var(--status-danger-bg)] text-[var(--status-danger-fg)]":"border-[var(--status-success-border)] bg-[var(--status-success-bg)] text-[var(--status-success-fg)]"}`,children:a})}function Zt(t){return t instanceof Y?t.payload.message:t instanceof Error?t.message:"Unable to update relay admin state."}function Sl(){const[t,a]=r.useState(null),[s,n]=r.useState(!0),[l,i]=r.useState(null),[u,h]=r.useState(null);async function g(){n(!0),i(null);try{rt(),a(await vo())}catch(c){i(Zt(c))}finally{n(!1)}}r.useEffect(()=>{g()},[]);async function b(c){h("registration"),i(null);try{const I=await yo(c);a(j=>j&&{...j,registrationEnabled:I.registrationEnabled})}catch(I){i(Zt(I))}finally{h(null)}}async function T(c,I){h(c),i(null);try{const j=await wo(c,I);a(L=>L&&{...L,users:L.users.map(P=>P.id===j.id?j:P)})}catch(j){i(Zt(j))}finally{h(null)}}return e.jsxs("main",{className:"min-h-screen bg-[var(--app-bg)] px-4 py-6 text-[var(--app-fg)] sm:px-6",children:[e.jsx(wa,{}),e.jsxs("div",{className:"mx-auto flex w-full max-w-6xl flex-col gap-5",children:[e.jsxs("header",{className:"flex flex-col gap-3 border-b border-[var(--theme-border)] pb-5 sm:flex-row sm:items-end sm:justify-between",children:[e.jsxs("div",{children:[e.jsx("p",{className:"text-xs font-semibold uppercase tracking-[0.22em] text-[var(--theme-fg-muted)]",children:"Relay Admin"}),e.jsx("h1",{className:"mt-2 text-2xl font-semibold text-[var(--theme-fg)]",children:"Users and devices"}),e.jsx("p",{className:"mt-1 text-sm text-[var(--theme-fg-muted)]",children:"Manage relay accounts, registration, and connected devices."})]}),e.jsxs("div",{className:"flex flex-wrap gap-2",children:[e.jsx($e,{className:"relay-button-secondary",to:"/relay-portal",children:"Portal"}),e.jsx("button",{className:"relay-button-secondary",onClick:()=>void g(),type:"button",children:"Refresh"})]})]}),s?e.jsx("section",{className:"rounded-lg border border-[var(--theme-border)] bg-[var(--theme-panel)] p-4 text-sm text-[var(--theme-fg-muted)]",children:"Loading relay admin..."}):l?e.jsx("section",{className:"rounded-lg border border-[var(--status-danger-border)] bg-[var(--status-danger-bg)] p-4 text-sm text-[var(--status-danger-fg)]",children:l}):t?e.jsxs(e.Fragment,{children:[e.jsx("section",{className:"rounded-lg border border-[var(--theme-border)] bg-[var(--theme-panel)] p-4",children:e.jsxs("div",{className:"flex flex-col gap-3 sm:flex-row sm:items-center sm:justify-between",children:[e.jsxs("div",{children:[e.jsx("h2",{className:"text-base font-semibold text-[var(--theme-fg)]",children:"Registration"}),e.jsx("p",{className:"mt-1 text-sm text-[var(--theme-fg-muted)]",children:"New users can create relay accounts without email verification."})]}),e.jsx("button",{className:"relay-button-primary",disabled:u==="registration",onClick:()=>void b(!t.registrationEnabled),type:"button",children:t.registrationEnabled?"Disable":"Enable"})]})}),e.jsxs("section",{className:"rounded-lg border border-[var(--theme-border)] bg-[var(--theme-panel)] p-4",children:[e.jsx("h2",{className:"text-base font-semibold text-[var(--theme-fg)]",children:"Users"}),e.jsx("div",{className:"mt-4 overflow-x-auto",children:e.jsxs("table",{className:"w-full min-w-[44rem] border-collapse text-left text-sm",children:[e.jsx("thead",{className:"text-xs uppercase tracking-[0.16em] text-[var(--theme-fg-muted)]",children:e.jsxs("tr",{children:[e.jsx("th",{className:"border-b border-[var(--theme-border)] py-2 pr-3",children:"User"}),e.jsx("th",{className:"border-b border-[var(--theme-border)] py-2 pr-3",children:"Email"}),e.jsx("th",{className:"border-b border-[var(--theme-border)] py-2 pr-3",children:"Role"}),e.jsx("th",{className:"border-b border-[var(--theme-border)] py-2 pr-3",children:"Status"}),e.jsx("th",{className:"border-b border-[var(--theme-border)] py-2 pr-3",children:"Actions"})]})}),e.jsx("tbody",{children:t.users.map(c=>e.jsxs("tr",{children:[e.jsx("td",{className:"border-b border-[var(--theme-border)] py-3 pr-3 font-medium text-[var(--theme-fg)]",children:c.username}),e.jsx("td",{className:"border-b border-[var(--theme-border)] py-3 pr-3 text-[var(--theme-fg-muted)]",children:c.email}),e.jsx("td",{className:"border-b border-[var(--theme-border)] py-3 pr-3 text-[var(--theme-fg-muted)]",children:c.role}),e.jsx("td",{className:"border-b border-[var(--theme-border)] py-3 pr-3 text-[var(--theme-fg-muted)]",children:c.enabled?"Enabled":"Disabled"}),e.jsx("td",{className:"border-b border-[var(--theme-border)] py-3 pr-3",children:e.jsx("button",{className:"relay-button-secondary",disabled:u===c.id||c.role==="admin",onClick:()=>void T(c.id,!c.enabled),type:"button",children:c.enabled?"Disable":"Enable"})})]},c.id))})]})})]}),e.jsxs("section",{className:"rounded-lg border border-[var(--theme-border)] bg-[var(--theme-panel)] p-4",children:[e.jsx("h2",{className:"text-base font-semibold text-[var(--theme-fg)]",children:"Devices"}),e.jsx("div",{className:"mt-4 grid gap-3 lg:grid-cols-2",children:t.devices.map(c=>e.jsxs("article",{className:"rounded-lg border border-[var(--theme-border)] bg-[var(--theme-surface)] p-3",children:[e.jsxs("div",{className:"flex items-center gap-2",children:[e.jsx("span",{className:`h-2.5 w-2.5 rounded-full ${c.connected?"bg-emerald-500":"bg-[var(--theme-fg-muted)]"}`}),e.jsx("p",{className:"truncate text-sm font-medium text-[var(--theme-fg)]",children:c.name})]}),e.jsx("p",{className:"mt-2 font-mono text-xs text-[var(--theme-fg-muted)]",children:c.id}),e.jsxs("p",{className:"mt-1 text-xs text-[var(--theme-fg-muted)]",children:["Owner: ",c.ownerUserId]})]},c.id))})]})]}):null]})]})}function Xt(t,a){return t instanceof Y?t.payload.message:t instanceof Error?t.message:a}function Cl(){const t=Pe(),[a,s]=r.useState(null),[n,l]=r.useState(""),[i,u]=r.useState(null),[h,g]=r.useState(null),[b,T]=r.useState(!0),[c,I]=r.useState(null),[j,L]=r.useState(null);async function P(){T(!0),L(null);try{rt(),s(await or())}catch(w){L(Xt(w,"Unable to load devices."))}finally{T(!1)}}r.useEffect(()=>{P()},[]);async function q(w){w.preventDefault(),I("create"),L(null);try{const H=await lr({name:n});u(H),l(""),await P()}catch(H){L(Xt(H,"Unable to create device."))}finally{I(null)}}async function F(w){if(window.confirm(`Delete relay device "${w.name}"?`)){I(w.id),L(null);try{await ir(w.id),(i==null?void 0:i.device.id)===w.id&&u(null),await P()}catch(H){L(Xt(H,"Unable to delete device."))}finally{I(null)}}}function D(w){Pt(w.id),Ot(null),t(pa(w.id))}async function R(w){var o;const H=w.token;if(!H){L("This device token is not available. Create a new device token for devices created before token storage was enabled.");return}try{await((o=navigator.clipboard)==null?void 0:o.writeText(vr(H))),g(w.id),window.setTimeout(()=>{g(B=>B===w.id?null:B)},1600)}catch{}}return e.jsx("main",{className:"min-h-screen bg-[var(--app-bg)] px-4 py-6 text-[var(--app-fg)] sm:px-6",children:e.jsxs("div",{className:"mx-auto w-full max-w-6xl space-y-5 pr-12 sm:pr-0",children:[e.jsxs("header",{className:"flex flex-col gap-3 border-b border-[var(--theme-border)] pb-5 sm:flex-row sm:items-end sm:justify-between",children:[e.jsxs("div",{children:[e.jsx($e,{className:"text-sm text-[var(--theme-accent-strong)]",to:"/workspaces",children:"Back to workspaces"}),e.jsx("p",{className:"mt-4 text-xs font-semibold uppercase tracking-[0.22em] text-[var(--theme-fg-muted)]",children:"Relay Devices"}),e.jsx("h1",{className:"mt-2 text-2xl font-semibold text-[var(--theme-fg)]",children:"Device management"})]}),e.jsxs("button",{className:"relay-button-secondary inline-flex items-center gap-2",onClick:()=>void P(),type:"button",children:[e.jsx(Se.RefreshCcw,{className:"h-4 w-4"}),"Refresh"]})]}),j?e.jsx(Il,{tone:"danger",children:j}):null,i?e.jsx(El,{result:i}):null,e.jsxs("section",{className:"grid gap-4 lg:grid-cols-[minmax(20rem,0.8fr)_minmax(0,1.2fr)]",children:[e.jsxs("section",{className:"rounded-lg border border-[var(--theme-border)] bg-[var(--theme-panel)] p-4",children:[e.jsxs("div",{className:"mb-4 flex items-start gap-3",children:[e.jsx("span",{className:"inline-flex h-9 w-9 items-center justify-center rounded-lg border border-[var(--theme-border)] bg-[var(--theme-surface)] text-[var(--theme-fg)]",children:e.jsx(Se.Plus,{className:"h-4 w-4"})}),e.jsxs("div",{children:[e.jsx("h2",{className:"text-base font-semibold text-[var(--theme-fg)]",children:"Add device"}),e.jsx("p",{className:"mt-1 text-sm text-[var(--theme-fg-muted)]",children:"Create a token for one private supervisor."})]})]}),e.jsxs("form",{className:"space-y-3",onSubmit:q,children:[e.jsxs("label",{className:"block text-sm text-[var(--theme-fg-soft)]",children:["Device name",e.jsx("input",{className:"relay-input mt-2 w-full",onChange:w=>l(w.target.value),placeholder:"MacBook Pro",value:n})]}),e.jsxs("button",{className:"relay-button-primary inline-flex h-10 w-full items-center justify-center gap-2",disabled:c==="create"||!n.trim(),type:"submit",children:[e.jsx(Se.MonitorSmartphone,{className:"h-4 w-4"}),"Create device token"]})]})]}),e.jsxs("section",{className:"rounded-lg border border-[var(--theme-border)] bg-[var(--theme-panel)] p-4",children:[e.jsxs("div",{className:"mb-4 flex items-center justify-between gap-3",children:[e.jsxs("div",{children:[e.jsx("h2",{className:"text-base font-semibold text-[var(--theme-fg)]",children:"Devices"}),e.jsx("p",{className:"mt-1 text-sm text-[var(--theme-fg-muted)]",children:"Connect to an online device before opening workspaces."})]}),e.jsx("span",{className:"rounded-full border border-[var(--theme-border)] px-2 py-0.5 text-xs text-[var(--theme-fg-muted)]",children:(a==null?void 0:a.devices.length)??0})]}),b?e.jsx("p",{className:"rounded-lg border border-[var(--theme-border)] bg-[var(--theme-surface)] p-4 text-sm text-[var(--theme-fg-muted)]",children:"Loading devices..."}):a!=null&&a.devices.length?e.jsx("div",{className:"space-y-3",children:a.devices.map(w=>e.jsx(Tl,{busy:c===w.id,copiedSetup:h===w.id,device:w,onConnect:()=>D(w),onCopySetup:()=>void R(w),onDelete:()=>void F(w),setupTokenAvailable:!!w.token},w.id))}):e.jsx("div",{className:"rounded-lg border border-dashed border-[var(--theme-border)] bg-[var(--theme-surface)] p-5 text-sm text-[var(--theme-fg-muted)]",children:"No devices yet. Create a token, then start `remote-codex relay-supervisor` on your private machine."})]})]})]})})}function Tl({device:t,busy:a,copiedSetup:s,onConnect:n,onCopySetup:l,onDelete:i,setupTokenAvailable:u}){return e.jsxs("article",{className:"rounded-lg border border-[var(--theme-border)] bg-[var(--theme-surface)] p-3",children:[e.jsxs("div",{className:"flex flex-col gap-3 sm:flex-row sm:items-center sm:justify-between",children:[e.jsxs("div",{className:"min-w-0",children:[e.jsxs("div",{className:"flex min-w-0 items-center gap-2",children:[e.jsx("span",{className:`h-2.5 w-2.5 rounded-full ${t.connected?"bg-[var(--status-success-fg)]":"bg-[var(--theme-fg-muted)]"}`}),e.jsx("p",{className:"truncate text-sm font-medium text-[var(--theme-fg)]",children:t.name})]}),e.jsx("p",{className:"mt-1 font-mono text-xs text-[var(--theme-fg-muted)]",children:t.tokenPreview}),e.jsx("p",{className:"mt-1 text-xs text-[var(--theme-fg-muted)]",children:t.connected?`Online since ${Ts(t.connectedAt)}`:`Offline. Last heartbeat: ${Ts(t.lastHeartbeatAt)}`})]}),e.jsxs("div",{className:"flex flex-wrap gap-2",children:[e.jsxs("button",{className:"relay-button-secondary inline-flex items-center gap-2",onClick:l,title:u?"Copy relay supervisor setup command":"Device token is not available. Create a new device token for devices created before token storage was enabled.",disabled:!u,type:"button",children:[e.jsx(Se.Copy,{className:"h-4 w-4"}),s?"Copied":"Copy setup"]}),e.jsxs("button",{className:"relay-button-primary inline-flex items-center gap-2",disabled:!t.connected,onClick:n,type:"button",children:[e.jsx(Se.Plug,{className:"h-4 w-4"}),"Connect"]}),e.jsxs("button",{className:"relay-button-secondary inline-flex items-center gap-2",disabled:a,onClick:i,type:"button",children:[e.jsx(Se.Trash2,{className:"h-4 w-4"}),"Delete"]})]})]}),u?null:e.jsx("p",{className:"mt-3 rounded-md border border-[var(--theme-border)] bg-[var(--theme-panel)] px-3 py-2 text-xs text-[var(--theme-fg-muted)]",children:"Token not available for this device. Create a new device token to copy a ready-to-run setup command."})]})}function El({result:t}){const a=vr(t.token);return e.jsxs("section",{className:"rounded-lg border border-[var(--theme-accent-border)] bg-[var(--theme-accent-soft)] p-4",children:[e.jsxs("h2",{className:"text-base font-semibold text-[var(--theme-fg)]",children:["Token created for ",t.device.name]}),e.jsx("p",{className:"mt-1 text-sm text-[var(--theme-fg-muted)]",children:"Store this token now. It will not be shown again."}),e.jsx(Ss,{label:"Device token",value:t.token}),e.jsx(Ss,{label:"Supervisor command",value:a})]})}function Ss({label:t,value:a}){async function s(){var n;try{await((n=navigator.clipboard)==null?void 0:n.writeText(a))}catch{}}return e.jsxs("div",{className:"mt-3",children:[e.jsxs("div",{className:"mb-1 flex items-center justify-between gap-2",children:[e.jsx("p",{className:"text-xs font-medium uppercase tracking-[0.14em] text-[var(--theme-fg-muted)]",children:t}),e.jsxs("button",{className:"relay-button-secondary inline-flex items-center gap-1 px-2 py-1 text-xs",onClick:()=>void s(),type:"button",children:[e.jsx(Se.Copy,{className:"h-3.5 w-3.5"}),"Copy"]})]}),e.jsx("code",{className:"block break-all rounded-lg border border-[var(--theme-border)] bg-[var(--theme-panel)] px-3 py-2 font-mono text-xs text-[var(--theme-fg)]",children:a})]})}function Il({tone:t,children:a}){return e.jsx("div",{className:"rounded-lg border border-[var(--status-danger-border)] bg-[var(--status-danger-bg)] px-3 py-2 text-sm text-[var(--status-danger-fg)]",children:a})}function vr(t){const a=Rl();return[`REMOTE_CODEX_RELAY_SERVER_URL=${Cs(a)} \\`,`REMOTE_CODEX_RELAY_AGENT_TOKEN=${Cs(t)} \\`,"remote-codex relay-supervisor"].join(`
|