remote-codex 0.11.26 → 0.11.27
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 +108 -8
- package/apps/supervisor-web/dist/assets/{index-CIcJHgFF.js → index-pMPBEcL2.js} +1 -1
- package/apps/supervisor-web/dist/assets/{thread-ui-CaDgVQIY.js → thread-ui-CpukI6ql.js} +32 -32
- package/apps/supervisor-web/dist/index.html +2 -2
- package/package.json +1 -1
- package/packages/claude/src/historyItems.ts +71 -0
- package/packages/claude/src/runtimeAdapter.test.ts +259 -0
- package/packages/claude/src/runtimeAdapter.ts +52 -3
|
@@ -10862,6 +10862,15 @@ var HIDDEN_ASK_USER_QUESTION_CONTINUATION_PREFIX = "The user answered the clarif
|
|
|
10862
10862
|
var SUPPRESSED_ASSISTANT_TEXTS = /* @__PURE__ */ new Set([
|
|
10863
10863
|
"No response requested."
|
|
10864
10864
|
]);
|
|
10865
|
+
var CLAUDE_LIMIT_ERROR_PATTERNS = [
|
|
10866
|
+
/\byou(?:'|’)ve hit your session limit\b/i,
|
|
10867
|
+
/\byou have hit your session limit\b/i,
|
|
10868
|
+
/\b(?:hit|reached|exceeded) (?:the )?(?:session|usage|rate) limit\b/i,
|
|
10869
|
+
/\b(?:session|usage|rate) limit (?:hit|reached|exceeded)\b/i,
|
|
10870
|
+
/\bquota exceeded\b/i,
|
|
10871
|
+
/\bcredit balance (?:is )?(?:too low|insufficient|exhausted)\b/i,
|
|
10872
|
+
/\binsufficient credits?\b/i
|
|
10873
|
+
];
|
|
10865
10874
|
function normalizedToolName(toolName) {
|
|
10866
10875
|
return toolName.replace(/[\s_-]+/g, "").toLowerCase();
|
|
10867
10876
|
}
|
|
@@ -11043,6 +11052,26 @@ function isHiddenContinuationMessage(message) {
|
|
|
11043
11052
|
function shouldSuppressAssistantText(text2) {
|
|
11044
11053
|
return SUPPRESSED_ASSISTANT_TEXTS.has(text2.trim());
|
|
11045
11054
|
}
|
|
11055
|
+
function claudeLimitErrorMessage(text2) {
|
|
11056
|
+
const normalized = text2?.trim();
|
|
11057
|
+
if (!normalized) {
|
|
11058
|
+
return null;
|
|
11059
|
+
}
|
|
11060
|
+
return CLAUDE_LIMIT_ERROR_PATTERNS.some((pattern) => pattern.test(normalized)) ? normalized : null;
|
|
11061
|
+
}
|
|
11062
|
+
function limitErrorFromHistoryItems(items) {
|
|
11063
|
+
for (let index = items.length - 1; index >= 0; index -= 1) {
|
|
11064
|
+
const item = items[index];
|
|
11065
|
+
if (item?.kind !== "agentMessage") {
|
|
11066
|
+
continue;
|
|
11067
|
+
}
|
|
11068
|
+
const error = claudeLimitErrorMessage(item.text);
|
|
11069
|
+
if (error) {
|
|
11070
|
+
return error;
|
|
11071
|
+
}
|
|
11072
|
+
}
|
|
11073
|
+
return null;
|
|
11074
|
+
}
|
|
11046
11075
|
function userMessageToHistoryItem(id, message) {
|
|
11047
11076
|
return {
|
|
11048
11077
|
id,
|
|
@@ -11182,6 +11211,28 @@ function toolResultBlocks(message) {
|
|
|
11182
11211
|
};
|
|
11183
11212
|
}).filter((block) => Boolean(block));
|
|
11184
11213
|
}
|
|
11214
|
+
function xmlTagText(input, tagName) {
|
|
11215
|
+
const match = new RegExp(`<${tagName}>([\\s\\S]*?)</${tagName}>`, "i").exec(input);
|
|
11216
|
+
return match?.[1]?.trim() || null;
|
|
11217
|
+
}
|
|
11218
|
+
function decodeBasicXmlEntities(input) {
|
|
11219
|
+
return input.replace(/"/g, '"').replace(/'/g, "'").replace(/>/g, ">").replace(/</g, "<").replace(/&/g, "&");
|
|
11220
|
+
}
|
|
11221
|
+
function taskNotificationToolResult(message) {
|
|
11222
|
+
const text2 = messageContentText(message).trim();
|
|
11223
|
+
if (!text2.startsWith("<task-notification>") || !text2.includes("</task-notification>")) {
|
|
11224
|
+
return null;
|
|
11225
|
+
}
|
|
11226
|
+
const toolUseId = xmlTagText(text2, "tool-use-id");
|
|
11227
|
+
if (!toolUseId) {
|
|
11228
|
+
return null;
|
|
11229
|
+
}
|
|
11230
|
+
const result = xmlTagText(text2, "result") ?? xmlTagText(text2, "summary") ?? text2;
|
|
11231
|
+
return {
|
|
11232
|
+
toolUseId,
|
|
11233
|
+
result: decodeBasicXmlEntities(result)
|
|
11234
|
+
};
|
|
11235
|
+
}
|
|
11185
11236
|
function suppressedClaudeToolUseIds(message) {
|
|
11186
11237
|
const ids = /* @__PURE__ */ new Set();
|
|
11187
11238
|
for (const block of contentBlocks(message)) {
|
|
@@ -11892,6 +11943,13 @@ function queryResultError(message) {
|
|
|
11892
11943
|
}
|
|
11893
11944
|
return message.errors?.join("\n") || message.stop_reason || "Claude turn failed.";
|
|
11894
11945
|
}
|
|
11946
|
+
function statusForHistoricalItems(items) {
|
|
11947
|
+
const limitError = limitErrorFromHistoryItems(items);
|
|
11948
|
+
return {
|
|
11949
|
+
status: limitError ? "failed" : "completed",
|
|
11950
|
+
error: limitError
|
|
11951
|
+
};
|
|
11952
|
+
}
|
|
11895
11953
|
function assistantMessagePayload(message) {
|
|
11896
11954
|
return message.type === "assistant" ? message.message : null;
|
|
11897
11955
|
}
|
|
@@ -12699,7 +12757,8 @@ var ClaudeRuntimeAdapter = class extends EventEmitter5 {
|
|
|
12699
12757
|
this.deleteActiveTurn(state);
|
|
12700
12758
|
this.emitUsage(state);
|
|
12701
12759
|
const completedAt = (/* @__PURE__ */ new Date()).toISOString();
|
|
12702
|
-
const
|
|
12760
|
+
const limitError = limitErrorFromHistoryItems(orderedItems(state));
|
|
12761
|
+
const status = state.interrupted ? "interrupted" : limitError ? "failed" : terminalStatus ?? "completed";
|
|
12703
12762
|
this.emitRuntimeEvent({
|
|
12704
12763
|
type: "turn.completed",
|
|
12705
12764
|
provider: "claude",
|
|
@@ -12708,7 +12767,7 @@ var ClaudeRuntimeAdapter = class extends EventEmitter5 {
|
|
|
12708
12767
|
providerTurnId: state.providerTurnId,
|
|
12709
12768
|
startedAt: state.startedAt,
|
|
12710
12769
|
status,
|
|
12711
|
-
error: terminalError,
|
|
12770
|
+
error: limitError ?? terminalError,
|
|
12712
12771
|
items: finalizeTurnItems(state, status, completedAt),
|
|
12713
12772
|
rawTurn: rawMessages
|
|
12714
12773
|
})
|
|
@@ -12801,6 +12860,18 @@ var ClaudeRuntimeAdapter = class extends EventEmitter5 {
|
|
|
12801
12860
|
return;
|
|
12802
12861
|
}
|
|
12803
12862
|
if (message.type === "user") {
|
|
12863
|
+
const taskNotification = taskNotificationToolResult(message.message);
|
|
12864
|
+
if (taskNotification && !state.suppressedToolUseIds.has(taskNotification.toolUseId)) {
|
|
12865
|
+
const item = resultForToolUse({
|
|
12866
|
+
toolUseId: taskNotification.toolUseId,
|
|
12867
|
+
result: message.tool_use_result ?? taskNotification.result,
|
|
12868
|
+
previous: state.items.get(taskNotification.toolUseId) ?? null
|
|
12869
|
+
});
|
|
12870
|
+
const nextItem = withHistoryItemCreatedAt(item, messageCreatedAt);
|
|
12871
|
+
addOrUpdateItem(state, nextItem);
|
|
12872
|
+
this.emitItem(state, nextItem, "item.completed");
|
|
12873
|
+
return;
|
|
12874
|
+
}
|
|
12804
12875
|
const rawToolResults = toolResultBlocks(message.message);
|
|
12805
12876
|
const toolResults = rawToolResults.filter(
|
|
12806
12877
|
(toolResult) => !state.suppressedToolUseIds.has(toolResult.toolUseId)
|
|
@@ -13108,6 +13179,24 @@ var ClaudeRuntimeAdapter = class extends EventEmitter5 {
|
|
|
13108
13179
|
};
|
|
13109
13180
|
for (const message of messages) {
|
|
13110
13181
|
if (message.type === "user") {
|
|
13182
|
+
const taskNotification = taskNotificationToolResult(message.message);
|
|
13183
|
+
if (taskNotification) {
|
|
13184
|
+
if (suppressedToolUseIds.has(taskNotification.toolUseId)) {
|
|
13185
|
+
continue;
|
|
13186
|
+
}
|
|
13187
|
+
const previous = current?.itemsById.get(taskNotification.toolUseId) ?? null;
|
|
13188
|
+
upsertCurrentItem(
|
|
13189
|
+
withHistoryItemCreatedAt(
|
|
13190
|
+
resultForToolUse({
|
|
13191
|
+
toolUseId: taskNotification.toolUseId,
|
|
13192
|
+
result: message.tool_use_result ?? taskNotification.result,
|
|
13193
|
+
previous
|
|
13194
|
+
}),
|
|
13195
|
+
sessionMessageTimestamp(message) ?? current?.startedAt
|
|
13196
|
+
)
|
|
13197
|
+
);
|
|
13198
|
+
continue;
|
|
13199
|
+
}
|
|
13111
13200
|
const rawToolResults = toolResultBlocks(message.message);
|
|
13112
13201
|
const toolResults = rawToolResults.filter(
|
|
13113
13202
|
(toolResult) => !suppressedToolUseIds.has(toolResult.toolUseId)
|
|
@@ -13143,10 +13232,12 @@ var ClaudeRuntimeAdapter = class extends EventEmitter5 {
|
|
|
13143
13232
|
}
|
|
13144
13233
|
skippingHiddenInit = false;
|
|
13145
13234
|
if (current && current.items.length > 0) {
|
|
13235
|
+
const outcome = statusForHistoricalItems(current.items);
|
|
13146
13236
|
turns.push(buildAgentTurn({
|
|
13147
13237
|
providerTurnId: current.providerTurnId,
|
|
13148
13238
|
startedAt: current.startedAt,
|
|
13149
|
-
status:
|
|
13239
|
+
status: outcome.status,
|
|
13240
|
+
error: outcome.error,
|
|
13150
13241
|
items: current.items
|
|
13151
13242
|
}));
|
|
13152
13243
|
}
|
|
@@ -13201,10 +13292,12 @@ var ClaudeRuntimeAdapter = class extends EventEmitter5 {
|
|
|
13201
13292
|
}
|
|
13202
13293
|
}
|
|
13203
13294
|
if (current && current.items.length > 0) {
|
|
13295
|
+
const outcome = statusForHistoricalItems(current.items);
|
|
13204
13296
|
turns.push(buildAgentTurn({
|
|
13205
13297
|
providerTurnId: current.providerTurnId,
|
|
13206
13298
|
startedAt: current.startedAt,
|
|
13207
|
-
status:
|
|
13299
|
+
status: outcome.status,
|
|
13300
|
+
error: outcome.error,
|
|
13208
13301
|
items: current.items
|
|
13209
13302
|
}));
|
|
13210
13303
|
}
|
|
@@ -17797,8 +17890,10 @@ var ThreadRuntimeEventProjector = class {
|
|
|
17797
17890
|
}
|
|
17798
17891
|
const turnId = liveState.displayTurnIdForRuntimeTurn(record.id, event.providerTurnId) ?? event.providerTurnId;
|
|
17799
17892
|
updateThreadRecord(db, record.id, {
|
|
17893
|
+
providerTurnId: null,
|
|
17800
17894
|
status: "failed",
|
|
17801
|
-
lastError: event.error
|
|
17895
|
+
lastError: event.error,
|
|
17896
|
+
lastTurnCompletedAt: (/* @__PURE__ */ new Date()).toISOString()
|
|
17802
17897
|
});
|
|
17803
17898
|
liveState.setLivePlan(record.id, null);
|
|
17804
17899
|
liveState.setLiveItems(record.id, null);
|
|
@@ -18278,7 +18373,11 @@ var ThreadDetailAssembler = class {
|
|
|
18278
18373
|
if (input.record.providerTurnId && threadPatch.status === "idle" && activeLiveItems && activeLiveItems.items.length > 0) {
|
|
18279
18374
|
threadPatch.status = "running";
|
|
18280
18375
|
}
|
|
18281
|
-
|
|
18376
|
+
const nextThreadPatch = {
|
|
18377
|
+
...threadPatch,
|
|
18378
|
+
...threadPatch.status !== "running" ? { providerTurnId: null } : {}
|
|
18379
|
+
};
|
|
18380
|
+
this.input.callbacks.updateThreadRecord(input.record.id, nextThreadPatch);
|
|
18282
18381
|
const updated = this.input.callbacks.getUpdatedThreadRecord(input.record.id);
|
|
18283
18382
|
this.input.callbacks.syncAfterRemoteSession(updated.id, remoteSession);
|
|
18284
18383
|
const deferredDetails = /* @__PURE__ */ new Map();
|
|
@@ -19128,6 +19227,7 @@ function buildThreadPatch(remoteSession, model, reasoningEffort) {
|
|
|
19128
19227
|
};
|
|
19129
19228
|
}
|
|
19130
19229
|
function toThreadDto(record, loadedIds, callbacks) {
|
|
19230
|
+
const status = record.status ?? "idle";
|
|
19131
19231
|
return {
|
|
19132
19232
|
id: record.id,
|
|
19133
19233
|
workspaceId: record.workspaceId,
|
|
@@ -19141,10 +19241,10 @@ function toThreadDto(record, loadedIds, callbacks) {
|
|
|
19141
19241
|
collaborationMode: normalizeCollaborationMode(record.collaborationMode),
|
|
19142
19242
|
approvalMode: record.approvalMode ?? "yolo",
|
|
19143
19243
|
sandboxMode: normalizeSandboxMode(record.sandboxMode) ?? defaultSandboxModeForApprovalMode(record.approvalMode ?? "yolo"),
|
|
19144
|
-
status
|
|
19244
|
+
status,
|
|
19145
19245
|
summaryText: record.summaryText ?? null,
|
|
19146
19246
|
lastError: record.lastError ?? null,
|
|
19147
|
-
activeTurnId: record.providerTurnId ?? null,
|
|
19247
|
+
activeTurnId: status === "running" ? record.providerTurnId ?? null : null,
|
|
19148
19248
|
isLoaded: record.isConnected !== false && (record.providerSessionId ? loadedIds.has(record.providerSessionId) : false),
|
|
19149
19249
|
isPinned: record.isPinned,
|
|
19150
19250
|
createdAt: record.createdAt,
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import{j as e,r as n,u as ua,d as He,L as ze,e as fo,f as Mr,b as xo,N as ma,B as go,h as Hr,i as je,O as bo,k as vo,c as yo}from"./react-vendor-CgLzZcV4.js";import{u as ot,a as _r,t as wo,f as Sa,T as jo,C as Ba,b as No,c as ko,d as So,e as Co,g as To,L as Eo,P as Io,A as Ao}from"./thread-ui-
|
|
1
|
+
import{j as e,r as n,u as ua,d as He,L as ze,e as fo,f as Mr,b as xo,N as ma,B as go,h as Hr,i as je,O as bo,k as vo,c as yo}from"./react-vendor-CgLzZcV4.js";import{u as ot,a as _r,t as wo,f as Sa,T as jo,C as Ba,b as No,c as ko,d as So,e as Co,g as To,L as Eo,P as Io,A as Ao}from"./thread-ui-CpukI6ql.js";import{l as ie}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"]'))r(l);new MutationObserver(l=>{for(const o of l)if(o.type==="childList")for(const i of o.addedNodes)i.tagName==="LINK"&&i.rel==="modulepreload"&&r(i)}).observe(document,{childList:!0,subtree:!0});function s(l){const o={};return l.integrity&&(o.integrity=l.integrity),l.referrerPolicy&&(o.referrerPolicy=l.referrerPolicy),l.crossOrigin==="use-credentials"?o.credentials="include":l.crossOrigin==="anonymous"?o.credentials="omit":o.credentials="same-origin",o}function r(l){if(l.ep)return;l.ep=!0;const o=s(l);fetch(l.href,o)}})();var Ro=["codex","claude","opencode"],qe="codex",rr={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 Po(t){return typeof t=="string"&&Ro.includes(t)}function Oo(t){return Po(t)?t:null}var nr=15;function Lo(t){return t.replace(/\s+/g," ").trim()}function Uo(t){const a=Lo(t);if(!a)return"";const s=Array.from(a);return s.length<=nr?a:`${s.slice(0,nr).join("")}...`}const Do=["codex","claude","opencode"],Br="codex",Wr={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"}},or=15;function $o(t){return t.replace(/\s+/g," ").trim()}function Mo(t){const a=$o(t);if(!a)return"";const s=Array.from(a);return s.length<=or?a:`${s.slice(0,or).join("")}...`}function Ho(){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 Qt(){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 Ca(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 _o=[{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."}],Fr={hostConfigFiles:[],toolboxItems:[],hookCommandTemplates:[],providerConfigFormat:"none",mcpConfigFormat:"none",configArchives:!1,buildRestart:!1},Bo={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 La(t){const a=Bo[t];return{packageName:a.packageName,installed:t==="codex",installedVersion:null,latestVersion:null,installCommand:a.installCommand,updateCommand:a.updateCommand,busy:!1,lastError:null}}function Wo(t,a){return{provider:t,displayName:a,description:`${a} backend descriptor is not available.`,enabled:!1,isDefault:t===Br,status:{state:"stopped",transport:Wr[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:Fr,installation:La(t)}}function Ta(t){const a=t.installation??La(t.provider);return{...t,installation:{...La(t.provider),...a}}}const pt=[...Do.map(t=>Wo(t,Wr[t].displayName))];function Fo(t){var a;return((a=pt.find(s=>s.provider===t))==null?void 0:a.managementSchema)??Fr}function qo(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 zo(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 jt(t){return{path:t,exists:!1,originalContent:"",draftContent:"",loading:!1,saving:!1,error:null,saveMessage:null}}const Vo=/^\/devices\/([^/]+)(?:\/|$)/,Go=/^(?:\/devices\/[^/]+)?\/threads\/([^/?#]+)(?:[/?#]|$)/;function qr(t){const a=Vo.exec(t);return a?decodeURIComponent(a[1]??""):null}function Ve(){return typeof window>"u"?null:qr(window.location.pathname)}function Jo(t){const a=Go.exec(t);return a?decodeURIComponent(a[1]??""):null}function Ko(){return typeof window>"u"?null:Jo(window.location.pathname)}function Pt(t,a){if(!a)return t;const s=t.startsWith("/")?t:`/${t}`;return`/devices/${encodeURIComponent(a)}${s}`}function Ua(t){return Pt(t,Ve())}function Wa(t,a){return Pt(`/threads/${encodeURIComponent(t)}`,a)}function Ue(t){return Wa(t,Ve())}function Yo(t,a){const s=t?`?workspaceId=${encodeURIComponent(t)}`:"";return Pt(`/threads${s}`,a)}function Et(t){return Yo(t,Ve())}function Zo(t,a){const s=t?`?workspaceId=${encodeURIComponent(t)}`:"";return Pt(`/threads/new${s}`,a)}function aa(t){return Zo(t,Ve())}function Fa(t){return Pt("/workspaces",t)}function Ot(){return Fa(Ve())}class te extends Error{constructor(a,s){super(s.message),this.statusCode=a,this.payload=s}}const Da="remote-codex-auth-token",$a="remote-codex-relay-token",Ma="remote-codex-relay-admin-token",zr="remote-codex-relay-mode",Ha="remote-codex-relay-device-id",_a="remote-codex-relay-thread-id";function Vr(){return typeof window>"u"?null:window.localStorage.getItem(Da)}function Xo(t){if(!(typeof window>"u")){if(t){window.localStorage.setItem(Da,t);return}window.localStorage.removeItem(Da)}}function Gr(){return typeof window>"u"?null:window.localStorage.getItem($a)}function Qo(){return typeof window>"u"?null:window.localStorage.getItem(Ma)}function qa(t){if(!(typeof window>"u")){if(t){window.localStorage.setItem($a,t);return}window.localStorage.removeItem($a)}}function Jr(t){if(!(typeof window>"u")){if(t){window.localStorage.setItem(Ma,t);return}window.localStorage.removeItem(Ma)}}function xt(){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(zr)==="true"}function Xe(){typeof window>"u"||window.localStorage.setItem(zr,"true")}function rt(){return xt()}function Kr(){return typeof window>"u"?null:Ve()??window.localStorage.getItem(Ha)}function It(t){if(!(typeof window>"u")){if(t){window.localStorage.setItem(Ha,t);return}window.localStorage.removeItem(Ha)}}function el(){return typeof window>"u"?null:Ko()??window.localStorage.getItem(_a)}function At(t){if(!(typeof window>"u")){if(t){window.localStorage.setItem(_a,t);return}window.localStorage.removeItem(_a)}}function za(t){if(!xt())return t;if(t.startsWith("/api/")){const a=Kr();return a?`/relay/devices/${encodeURIComponent(a)}${t}`:`/relay${t}`}return t}function Yr(t){return za(t)}function tl(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 al(t,a){const s=a==null?void 0:a.trim(),r=s?`${t} ${s}`:`${t}`;return t===429?`Too many requests (${r}).`:t===503?`Upstream service unavailable (${r}).`:`Request failed (${r}).`}function ut(t,a,s){const r=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)??tl(t.status),message:r,...l?{details:l}:{}}}async function Zr(t){var l,o;const a=al(t.status,t.statusText),s=((o=(l=t.headers)==null?void 0:l.get)==null?void 0:o.call(l,"content-type"))??"",r=async()=>ut(t,await t.json(),a);if(s.includes("application/json"))try{return await r()}catch{return ut(t,null,a)}try{if(typeof t.text!="function")try{return await r()}catch{return ut(t,null,a)}const i=(await t.text()).trim();if(i.startsWith("{"))try{return ut(t,JSON.parse(i),a)}catch{}return ut(t,i?{message:`${a}
|
|
3
3
|
${i}`}:null,a)}catch{try{return await r()}catch{return ut(t,null,a)}}}async function R(t,a,s={}){const r=new Headers(a==null?void 0:a.headers);(a==null?void 0:a.body)!==void 0&&!(a.body instanceof FormData)&&!r.has("Content-Type")&&r.set("Content-Type","application/json");const l=await fetch(za(String(t)),Qr({...a,headers:r},s.auth));if(!l.ok){const o=await Zr(l);throw new te(l.status,o)}return await l.json()}function sl(t){const a=String(t);return a.includes("/exports/pdf")?a.includes("format=html")?"remote-codex-transcript.html":"remote-codex-transcript.pdf":"download"}function rl(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 r=t.match(/filename=([^;]+)/i);return((l=r==null?void 0:r[1])==null?void 0:l.trim())??null}async function Xr(t,a){const s=await fetch(za(String(t)),Qr(a));if(!s.ok){const l=await Zr(s);throw new te(s.status,l)}const r=rl(s.headers.get("content-disposition"))??sl(t);return{blob:await s.blob(),filename:r}}function Qr(t={},a="default"){const s=new Headers(t.headers),r=xt();if(a!=="none"&&!s.has("Authorization"))if(a==="relay-admin"){const l=Qo();l&&s.set("Authorization",`Bearer ${l}`)}else{const l=Gr(),o=Vr();r&&l?s.set("Authorization",`Bearer ${l}`):!r&&o&&s.set("Authorization",`Bearer ${o}`)}return{...t,credentials:t.credentials??(r?"omit":"same-origin"),headers:s}}function lr(t,a){const s=t.originalName.trim();if(s)return s;const r=t.file.name.trim();return r||(t.kind==="photo"?`photo-${a+1}.jpg`:`file-${a+1}`)}function nl(){return R("/api/config/runtime")}function ol(){return R("/api/auth/session",{cache:"no-store"})}async function ll(t){const a=await R("/api/auth/login",{method:"POST",body:JSON.stringify(t)});return Xo(a.token??null),a}function Rt(){return R("/relay/auth/session",{cache:"no-store"})}async function il(t){Xe();const a=await R("/relay/auth/login",{method:"POST",body:JSON.stringify(t)},{auth:"none"});return qa(a.token),a}function en(){return Xe(),R("/relay/auth/session",{cache:"no-store"},{auth:"relay-admin"})}async function dl(t){Xe();const a=await R("/relay/auth/login",{method:"POST",body:JSON.stringify({identifier:t.username,password:t.password})},{auth:"none"});return Jr(a.token),a}async function cl(){return Jr(null),en()}async function ul(t){Xe();const a=await R("/relay/auth/register",{method:"POST",body:JSON.stringify(t)},{auth:"none"});return qa(a.token??null),a}async function tn(){const t=await R("/relay/auth/logout",{method:"POST"});return qa(null),It(null),At(null),t}function Va(){return R("/relay/portal")}function ml(t){const a=new URLSearchParams({deviceId:t.deviceId});return t.threadId&&a.set("threadId",t.threadId),t.workspaceId&&a.set("workspaceId",t.workspaceId),R(`/relay/access?${a.toString()}`)}function an(t){return R("/relay/devices",{method:"POST",body:JSON.stringify(t)})}function sn(t){return R(`/relay/devices/${encodeURIComponent(t)}`,{method:"DELETE"})}function hl(t){return R("/relay/account",{method:"PATCH",body:JSON.stringify(t)})}function pl(t){return R("/relay/account/password",{method:"PATCH",body:JSON.stringify(t)})}function fl(t){return R("/relay/shares",{method:"POST",body:JSON.stringify(t)})}function rn(t,a){return R(`/relay/shares/${encodeURIComponent(t)}`,{method:"PATCH",body:JSON.stringify(a)})}function Ga(t){return R(`/relay/shares/${encodeURIComponent(t)}`,{method:"DELETE"})}function xl(t){const a=t?`?days=${encodeURIComponent(String(t))}`:"";return R(`/relay/admin${a}`,void 0,{auth:"relay-admin"})}function gl(t){return R("/relay/admin/settings/registration",{method:"PATCH",body:JSON.stringify(t)},{auth:"relay-admin"})}function bl(t,a){return R(`/relay/admin/users/${encodeURIComponent(t)}`,{method:"PATCH",body:JSON.stringify({enabled:a})},{auth:"relay-admin"})}function vl(t){return R(`/relay/admin/users/${encodeURIComponent(t)}`,{method:"DELETE"},{auth:"relay-admin"})}function yl(t,a){return R(`/relay/admin/users/${encodeURIComponent(t)}/reset-password`,{method:"POST",body:JSON.stringify({password:a})},{auth:"relay-admin"})}function wl(t){return R(`/relay/admin/registrations/${encodeURIComponent(t)}/approve`,{method:"POST"},{auth:"relay-admin"})}function jl(t){return R(`/relay/admin/registrations/${encodeURIComponent(t)}/reject`,{method:"POST"},{auth:"relay-admin"})}function Nl(){return R("/api/config/workspace-settings",{cache:"no-store"})}function kl(t){return R("/api/config/workspace-settings",{method:"PATCH",body:JSON.stringify(t)})}function sa(){return R("/api/agent-runtimes",{cache:"no-store"})}function nn(t){return R(`/api/agent-runtimes/${encodeURIComponent(t)}/status`,{cache:"no-store"})}function Sl(t){return R(`/api/agent-runtimes/${encodeURIComponent(t)}/restart`,{method:"POST"})}function on(t,a){return R(`/api/agent-runtimes/${encodeURIComponent(t)}/install`,{method:"POST",body:JSON.stringify({action:a})})}function ea(t){return R(`/api/agent-runtimes/${encodeURIComponent(t)}/models`,{cache:"no-store"})}function ln(t,a){return R(`/api/config/providers/${encodeURIComponent(t)}/files/${encodeURIComponent(a)}`,{cache:"no-store"})}function dn(t,a,s){return R(`/api/config/providers/${encodeURIComponent(t)}/files/${encodeURIComponent(a)}`,{method:"PATCH",body:JSON.stringify(s)})}function Cl(t){return R(`/api/config/providers/${encodeURIComponent(t)}/archives`,{cache:"no-store"})}function Tl(t,a={}){return R(`/api/config/providers/${encodeURIComponent(t)}/archives`,{method:"POST",body:JSON.stringify(a)})}function El(t,a,s){return R(`/api/config/providers/${encodeURIComponent(t)}/archives/${encodeURIComponent(a)}`,{method:"PATCH",body:JSON.stringify(s)})}function Il(t,a){return R(`/api/config/providers/${encodeURIComponent(t)}/archives/${encodeURIComponent(a)}/apply`,{method:"POST"})}function Al(){return R("/api/service/build-restart",{method:"POST"})}function Rl(){return R("/healthz",{cache:"no-store"})}function Ja(){return R("/api/workspaces")}function Pl(t,a={}){const s=new URLSearchParams;a.path&&s.set("path",a.path);const r=s.size>0?`?${s.toString()}`:"";return R(`/api/workspaces/${encodeURIComponent(t)}/files/tree${r}`,{cache:"no-store"})}function Ol(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)),R(`/api/workspaces/${encodeURIComponent(t)}/files/preview?${s.toString()}`,{cache:"no-store"})}function Ll(t,a){const s=new URLSearchParams({path:a.path});return Yr(`/api/workspaces/${encodeURIComponent(t)}/files/raw?${s.toString()}`)}function Ul(t,a){const s=new URLSearchParams({path:a.path});return Yr(`/api/threads/${encodeURIComponent(t)}/assets/image?${s.toString()}`)}function Dl(t,a){const s=new URLSearchParams({path:a.path});return Xr(`/api/workspaces/${encodeURIComponent(t)}/files/download?${s.toString()}`,{cache:"no-store"})}function $l(t,a){const s=new FormData;return s.append("file",a.file,a.file.name),R(`/api/workspaces/${encodeURIComponent(t)}/files/upload`,{method:"POST",body:s})}function Ml(t,a){return R(`/api/workspaces/${encodeURIComponent(t)}/files`,{method:"PUT",body:JSON.stringify(a)})}function Ka(){return R("/api/threads")}function ir(t,a={}){const s=new URLSearchParams;return a.limit!==void 0&&s.set("limit",String(a.limit)),a.beforeTurnId&&s.set("beforeTurnId",a.beforeTurnId),R(`/api/threads/${t}${s.size>0?`?${s.toString()}`:""}`)}function Hl(t,a){return R(`/api/threads/${t}/items/${encodeURIComponent(a)}/detail`)}function _l(){return R("/api/plugins",{cache:"no-store"})}function Bl(t){return R("/api/plugins/import",{method:"POST",body:JSON.stringify(t)})}function Wl(t,a){return R(`/api/plugins/${encodeURIComponent(t)}`,{method:"PATCH",body:JSON.stringify(a)})}function Fl(t){return R(`/api/plugins/${encodeURIComponent(t)}`,{method:"DELETE"})}function ql(t){return R(`/api/threads/${t}/export-turns`,{cache:"no-store"})}function zl(t,a){var r,l,o;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),((r=a.options)==null?void 0:r.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)),((o=a.options)==null?void 0:o.includeAbsolutePaths)!==void 0&&s.set("includeAbsolutePaths",String(a.options.includeAbsolutePaths)),`/api/threads/${encodeURIComponent(t)}/exports/pdf?${s.toString()}`}function Vl(t,a){return Xr(zl(t,a),{cache:"no-store"})}function Gl(t){return R(`/api/threads/${t}/shell`)}function Jl(t){return R("/api/threads/start",{method:"POST",body:JSON.stringify(t)})}function Kl(t){return R("/api/threads/import",{method:"POST",body:JSON.stringify(typeof t=="string"?{sessionId:t}:t)})}function Yl(t,a={}){return R(`/api/threads/${t}/shell`,{method:"POST",...Object.keys(a).length>0?{body:JSON.stringify(a)}:{}})}function Zl(t){return R(`/api/shells/${t}/terminate`,{method:"POST"})}function Xl(t,a){return R(`/api/shells/${t}`,{method:"PATCH",body:JSON.stringify(a)})}function dr(t,a={}){return R(`/api/threads/${t}/resume`,{method:"POST",...Object.keys(a).length>0?{body:JSON.stringify(a)}:{}})}function Ql(t){return R(`/api/threads/${t}/disconnect`,{method:"POST"})}function ei(t,a){const s=a.attachments??[];if(s.length===0)return R(`/api/threads/${t}/prompt`,{method:"POST",body:JSON.stringify(a)});const r=new FormData;r.append("prompt",a.prompt),a.clientRequestId!==void 0&&r.append("clientRequestId",a.clientRequestId),a.model!==void 0&&r.append("model",a.model),a.reasoningEffort!==void 0&&a.reasoningEffort!==null&&r.append("reasoningEffort",a.reasoningEffort),a.collaborationMode!==void 0&&r.append("collaborationMode",a.collaborationMode);const l=s.map((o,i)=>({clientId:o.clientId,kind:o.kind,originalName:lr(o,i),placeholder:o.placeholder}));r.append("attachmentManifest",JSON.stringify(l));for(const[o,i]of s.entries())r.append("attachments",i.file,lr(i,o));return R(`/api/threads/${t}/prompt`,{method:"POST",body:r})}function cr(t,a={}){return R(`/api/threads/${t}/interrupt`,{method:"POST",body:JSON.stringify(a)})}function cn(t,a){return R(`/api/threads/${t}`,{method:"PATCH",body:JSON.stringify(a)})}function un(t){return R(`/api/threads/${t}`,{method:"DELETE"})}function ti(t,a){return R(`/api/threads/${t}/pending-steers/${encodeURIComponent(a)}`,{method:"DELETE"})}function ai(t,a){return R(`/api/threads/${t}/settings`,{method:"PATCH",body:JSON.stringify(a)})}function si(t){return R(`/api/threads/${t}/compact`,{method:"POST"})}function ri(t){return R(`/api/threads/${t}/goal`,{cache:"no-store"})}function ni(t,a){return R(`/api/threads/${t}/goal`,{method:"PATCH",body:JSON.stringify(a)})}function oi(t){return R(`/api/threads/${t}/goal`,{method:"DELETE"})}function li(t){return R(`/api/threads/${t}/fork-turns`,{cache:"no-store"})}function ur(t,a){return R(`/api/threads/${t}/fork`,{method:"POST",body:JSON.stringify(a)})}function ii(t){return R(`/api/threads/${t}/skills`,{cache:"no-store"})}function di(t){return R(`/api/threads/${t}/mcp-servers`,{cache:"no-store"})}function ci(t){return R(`/api/threads/${t}/hooks`,{cache:"no-store"})}function ui(t,a){return R(`/api/threads/${t}/hooks`,{method:"POST",body:JSON.stringify(a)})}function mi(t,a){return R(`/api/threads/${t}/hooks`,{method:"PUT",body:JSON.stringify(a)})}function hi(t,a){return R(`/api/threads/${t}/hooks/trust`,{method:"POST",body:JSON.stringify(a)})}function pi(t,a){return R(`/api/threads/${t}/hooks/untrust`,{method:"POST",body:JSON.stringify(a)})}function fi(t,a,s){return R(`/api/threads/${t}/requests/${encodeURIComponent(a)}/respond`,{method:"POST",body:JSON.stringify(s)})}function xi(t){return R("/api/workspaces",{method:"POST",body:JSON.stringify(t)})}function gi(t,a){return R(`/api/workspaces/${t}`,{method:"PATCH",body:JSON.stringify(a)})}function bi(t,a){return R(`/api/workspaces/${t}`,{method:"DELETE",body:JSON.stringify(a)})}function vi(t,a){return R(`/api/workspaces/${t}/favorite`,{method:"POST",body:JSON.stringify(a)})}function mn(t){const a=window.location.protocol==="https:"?"wss:":"ws:",s=new WebSocket(hn(a));return s.addEventListener("message",r=>{try{const l=JSON.parse(r.data);wi(l)&&t(l)}catch{}}),s}function yi(t={}){const a=window.location.protocol==="https:"?"wss:":"ws:",s=new WebSocket(hn(a));return s.addEventListener("message",r=>{var l,o;try{const i=JSON.parse(r.data);if(i.type==="supervisor.connected"){(l=t.onConnected)==null||l.call(t,i);return}ji(i)&&((o=t.onShellEvent)==null||o.call(t,i))}catch{}}),{socket:s,send(r){s.send(JSON.stringify(r))}}}function hn(t){const a=new URL(`${t}//${window.location.host}/ws`);if(xt()){const o=Kr();a.pathname=o?`/relay/devices/${encodeURIComponent(o)}/ws`:"/relay/ws"}const s=Vr(),r=Gr(),l=el();return xt()&&r&&a.searchParams.set("relaySession",r),xt()&&l&&a.searchParams.set("threadId",l),s&&a.searchParams.set("token",s),a.toString()}function wi(t){return"threadId"in t&&t.type.startsWith("thread.")&&typeof t.payload=="object"&&t.payload!==null}function ji(t){return"shellId"in t&&t.type.startsWith("shell.")&&typeof t.payload=="object"&&t.payload!==null}function Ya({embedded:t=!1}={}){const a=ot(),s=_r(),[r,l]=n.useState(""),[o,i]=n.useState({busy:!1,message:null,error:null}),[d,f]=n.useState(!1),[g,C]=n.useState(null),[h,S]=n.useState({}),k=g?h[g]:null,[p,v]=n.useState({busy:!1,message:null,error:null}),[q,_]=n.useState([]),[D,L]=n.useState(pt),[E,z]=n.useState({loading:!1,saving:!1,error:null,operatingProvider:null,operatingAction:null,message:null}),[Q,c]=n.useState(null),[P,K]=n.useState({devHomeDraft:"",loading:!1,saving:!1,message:null,error:null}),[m,H]=n.useState({loading:!1,creating:!1,applyingId:null,renamingId:null,renameDraft:"",message:null,error:null}),I=(a==null?void 0:a.themeMode)??"system",X=t||!!(a!=null&&a.settingsOpen);async function he(){const x=r.trim();if(!(!x||o.busy)){i({busy:!0,message:null,error:null});try{await s.importPluginManifest({manifestJson:x,enabled:!0}),l(""),i({busy:!1,message:"Plugin manifest imported.",error:null})}catch(w){i({busy:!1,message:null,error:w instanceof Error?w.message:"Unable to import plugin manifest."})}}}const pe=(a==null?void 0:a.effectiveTheme)??"dark",B=(a==null?void 0:a.autoCollapseCompletedTurns)??!0,J=(a==null?void 0:a.defaultBackend)??Br,ue=s.plugins.filter(x=>x.enabled).length,Y=s.loading?"Loading...":`${ue}/${s.plugins.length} enabled`,G=D.find(x=>x.provider===J)??pt.find(x=>x.provider===J)??pt[0],me=G.managementSchema??Fo(G.provider),de=me.hostConfigFiles;n.useEffect(()=>{if(!X||t||!a||!me.configArchives)return;const x=a;function w(M){M.key==="Escape"&&x.closeSettings()}return window.addEventListener("keydown",w),()=>{window.removeEventListener("keydown",w)}},[me.configArchives,t,X,a]),n.useEffect(()=>{if(!X)return;let x=!1;return z(w=>({...w,loading:!0,error:null})),sa().then(w=>{if(x)return;const M=[...w.map(Ta),...pt.filter(V=>!w.some(fe=>fe.provider===V.provider))];L(M),z(V=>({...V,loading:!1}))}).catch(w=>{x||(L(pt),z(M=>({...M,loading:!1,error:w instanceof te?w.message:"Unable to load backend settings."})))}),()=>{x=!0}},[X]),n.useEffect(()=>{if(!X)return;let x=!1;return K(w=>({...w,loading:!0,message:null,error:null})),Nl().then(w=>{x||(c(w),K(M=>({...M,devHomeDraft:w.devHome,loading:!1})))}).catch(w=>{x||K(M=>({...M,loading:!1,error:w instanceof te?w.message:"Unable to load workspace settings."}))}),()=>{x=!0}},[X]),n.useEffect(()=>{if(!X||!G.capabilities.management.hostConfigFiles)return;let x=!1;async function w(){S(V=>{const fe={...V};for(const Re of de)fe[Re.name]={...jt(Re.name),...V[Re.name],loading:!0,saving:!1,error:null,saveMessage:null};return fe});const M=await Promise.allSettled(de.map(async V=>({name:V.name,result:await ln(G.provider,V.name)})));x||S(V=>{var Re,Qe;const fe={...V};for(const Je of M){if(Je.status==="fulfilled"){const{name:lt,result:tt}=Je.value;fe[lt]={path:tt.path,exists:tt.exists,originalContent:tt.content,draftContent:tt.content,loading:!1,saving:!1,error:null,saveMessage:null};continue}const Lt=Je.reason instanceof te?Je.reason.message:"Unable to load the file.",et=((Re=de[M.indexOf(Je)])==null?void 0:Re.name)??((Qe=de[0])==null?void 0:Qe.name);et&&(fe[et]={...jt(et),...fe[et],loading:!1,saving:!1,error:Lt,saveMessage:null})}return fe})}return w(),()=>{x=!0}},[G.capabilities.management.hostConfigFiles,G.provider,de,X]),n.useEffect(()=>{if(!X)return;let x=!1;async function w(){H(M=>({...M,loading:!0,error:null,message:null}));try{const M=await Cl(G.provider);if(x)return;_(M),H(V=>({...V,loading:!1}))}catch(M){if(x)return;H(V=>({...V,loading:!1,error:M instanceof te?M.message:"Unable to load config archives."}))}}return w(),()=>{x=!0}},[G.provider,me.configArchives,X]);async function Ce(){if(!(p.busy||E.saving)){v({busy:!0,message:null,error:null});try{const x=await Sl(G.provider),w=Ta(x);v({busy:!1,message:w.status.state==="ready"?`${w.displayName} backend restarted.`:`${w.displayName} backend state: ${w.status.state}`,error:null}),L(M=>M.map(V=>V.provider===w.provider?w:V))}catch(x){v({busy:!1,message:null,error:x instanceof te?x.message:"Unable to restart the app server."})}}}async function U(x,w){if(p.busy||E.saving)return;const M=D.find(V=>V.provider===x);z(V=>({...V,saving:!0,operatingProvider:x,operatingAction:w,message:null,error:null}));try{const V=await on(x,w),fe=Ta(V);L(Re=>Re.map(Qe=>Qe.provider===fe.provider?fe:Qe)),z(Re=>({...Re,saving:!1,operatingProvider:null,operatingAction:null,message:fe.installation.lastError?`${fe.displayName} ${w==="install"?"installed":"updated"}, but requires attention:
|
|
4
4
|
${fe.installation.lastError}`:`${fe.displayName} ${w==="install"?"installed":"updated"}.`,error:null}))}catch(V){z(fe=>({...fe,saving:!1,operatingProvider:null,operatingAction:null,message:null,error:V instanceof te?zo(V):`Unable to ${w} ${(M==null?void 0:M.displayName)??x}.`}))}}async function ee(){if(!(p.busy||E.saving)){v({busy:!0,message:null,error:null});try{await Al(),v({busy:!1,message:"Build and restart launched. The page may disconnect briefly.",error:null})}catch(x){v({busy:!1,message:null,error:x instanceof te?x.message:"Unable to launch build and restart."})}}}async function ve(){const x=P.devHomeDraft.trim();if(!(!x||P.saving)){K(w=>({...w,saving:!0,message:null,error:null}));try{const w=await kl({devHome:x});c(w),K(M=>({...M,devHomeDraft:w.devHome,saving:!1,message:"Workspace defaults saved."}))}catch(w){K(M=>({...M,saving:!1,error:w instanceof te?w.message:"Unable to save workspace settings."}))}}}async function ke(x){const w=h[x];if(!(!w||w.saving)){S(M=>({...M,[x]:{...jt(x),...M[x],saving:!0,error:null,saveMessage:null}}));try{const M=await dn(G.provider,x,{content:w.draftContent});S(V=>({...V,[x]:{path:M.path,exists:M.exists,originalContent:M.content,draftContent:M.content,loading:!1,saving:!1,error:null,saveMessage:"Saved"}}))}catch(M){S(V=>({...V,[x]:{...jt(x),...V[x],saving:!1,error:M instanceof te?M.message:"Unable to save the file.",saveMessage:null}}))}}}async function we(){if(!m.creating){H(x=>({...x,creating:!0,message:null,error:null}));try{const x=await Tl(G.provider);_(w=>[x,...w]),H(w=>({...w,creating:!1,message:"Backup created."}))}catch(x){H(w=>({...w,creating:!1,error:x instanceof te?x.message:"Unable to create a config backup."}))}}}async function A(x){if(!m.applyingId){H(w=>({...w,applyingId:x.id,message:null,error:null}));try{const w=await Il(G.provider,x.id);H(M=>({...M,applyingId:null,message:w.status.state==="ready"?`Applied "${w.archive.label}" and restarted ${G.displayName}.`:`Applied "${w.archive.label}". ${G.displayName} state: ${w.status.state}.`}))}catch(w){H(M=>({...M,applyingId:null,error:w instanceof te?w.message:"Unable to apply the config archive."}))}}}async function T(x){const w=m.renameDraft.trim();if(!(!w||m.renamingId!==x.id)){H(M=>({...M,message:null,error:null}));try{const M=await El(G.provider,x.id,{label:w});_(V=>V.map(fe=>fe.id===x.id?M:fe)),H(V=>({...V,renamingId:null,renameDraft:"",message:"Backup renamed."}))}catch(M){H(V=>({...V,error:M instanceof te?M.message:"Unable to rename the config backup."}))}}}if(!X)return null;const ae=e.jsxs(e.Fragment,{children:[e.jsxs("div",{className:"mt-3 grid gap-2",children:[s.plugins.map(x=>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:x.name}),e.jsx("span",{className:"mt-1 block text-xs leading-5 text-[var(--theme-fg-muted)]",children:x.description}),e.jsx("span",{className:"mt-2 block text-[10px] uppercase tracking-[0.16em] text-[var(--theme-fg-muted)]",children:[...x.capabilities.artifactTypes.map(w=>w.type),...x.capabilities.threadPanels.map(w=>w.kind??w.id)].join(", ")||"utility"}),e.jsx("span",{className:"mt-1 block text-[10px] uppercase tracking-[0.16em] text-[var(--theme-fg-muted)]",children:x.source==="imported"?"Imported manifest":"Built-in module"})]}),e.jsx("input",{type:"checkbox",checked:x.enabled,onChange:w=>void s.setPluginEnabled(x.id,w.currentTarget.checked),className:"mt-1 h-4 w-4 shrink-0 accent-[var(--theme-accent-solid)]"})]},x.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:r,onChange:x=>{l(x.currentTarget.value),(o.message||o.error)&&i({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 he(),disabled:!r.trim()||o.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:o.busy?"Importing...":"Import"})]}),o.error&&e.jsx("p",{className:"mt-2 text-xs text-rose-300",children:o.error}),o.message&&e.jsx("p",{className:"mt-2 text-xs text-emerald-300",children:o.message})]}),s.error&&e.jsx("p",{className:"mt-2 text-xs text-rose-300",children:s.error})]}),Oe=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(Qt,{})})]})}),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:"," ",pe,"."]})]})}),e.jsx("div",{className:"mt-3 grid gap-2 sm:grid-cols-3",children:_o.map(x=>{const w=I===x.value;return e.jsxs("button",{type:"button",onClick:()=>a==null?void 0:a.setThemeMode(x.value),className:`block rounded-[1rem] border px-3 py-2.5 text-left transition ${w?"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:x.label}),w?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:x.description})]},x.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:B,onChange:x=>{var w;return(w=a.setAutoCollapseCompletedTurns)==null?void 0:w.call(a,x.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:Y}),e.jsx("button",{type:"button",onClick:()=>f(!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"})]}):ae]}),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:(Q==null?void 0:Q.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:P.loading&&!Q?"Loading...":(Q==null?void 0:Q.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:P.devHomeDraft,onChange:x=>K(w=>({...w,devHomeDraft:x.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 ve(),disabled:P.loading||P.saving||!P.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:P.saving?"Saving...":"Save"})]})]})]}),P.error?e.jsx("p",{className:"mt-2 text-xs text-rose-300",children:P.error}):P.message?e.jsx("p",{className:"mt-2 text-xs text-emerald-300",children:P.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 Ce(),disabled:p.busy||E.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:p.busy?"Restarting...":"Restart"}),e.jsx("button",{type:"button",onClick:()=>void ee(),disabled:p.busy||E.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:p.busy?"Working...":"Build and restart"})]})]}),e.jsx("div",{className:"mt-3 grid gap-2",children:D.map(x=>{const w=x.installation,M=!w.installed&&!!w.installCommand,V=w.installed&&!!w.updateCommand,fe=E.saving&&E.operatingProvider===x.provider,Re=M?"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:x.displayName}),e.jsx("span",{className:`rounded-full border px-2 py-0.5 text-[10px] uppercase tracking-[0.16em] ${x.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:x.enabled?"Ready":w.installed?x.status.state:"Not installed"})]}),e.jsxs("p",{className:"mt-1 truncate text-xs text-[var(--theme-fg-muted)]",children:["Version:"," ",w.installedVersion??(w.installed?"Installed":"Unavailable"),w.latestVersion?` · Latest: ${w.latestVersion}`:""]}),w.lastError?e.jsx("p",{className:"mt-1 line-clamp-2 text-xs text-rose-300",children:w.lastError}):null]}),M||V?e.jsx("button",{type:"button","aria-label":`${M?"Install":"Update"} ${x.displayName}`,onClick:()=>void U(x.provider,M?"install":"update"),disabled:p.busy||E.saving||!M&&!V,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:fe?E.operatingAction==="install"?"Installing...":"Updating...":Re}):null]},x.provider)})}),p.error?e.jsx("p",{className:"mt-2 text-xs text-rose-300",children:p.error}):p.message?e.jsx("p",{className:"mt-2 text-xs text-emerald-300",children:p.message}):E.message?e.jsx("p",{className:`mt-2 whitespace-pre-line text-xs ${E.message.includes("requires attention")?"text-amber-300":"text-emerald-300"}`,children:E.message}):E.error?e.jsx("p",{className:"mt-2 whitespace-pre-line text-xs text-rose-300",children:E.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:[G.displayName," exposes these editable files through its backend schema."]})]})}),e.jsxs("div",{className:"mt-3 grid gap-2 sm:grid-cols-2",children:[de.map(x=>{const w=h[x.name]??{path:x.name,exists:!1,originalContent:"",draftContent:"",loading:!1},M=w.draftContent!==w.originalContent;return e.jsx("button",{type:"button",onClick:()=>C(x.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:x.label}),e.jsx("p",{className:"mt-1 text-xs leading-5 text-[var(--theme-fg-muted)]",children:x.description})]}),e.jsx("div",{className:"shrink-0",children:w.loading?e.jsx("span",{className:"text-[11px] uppercase tracking-[0.2em] text-[var(--theme-fg-muted)]",children:"Loading"}):M?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"}):w.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"})})]})},x.name)}),de.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]})]}),me.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 we(),disabled:m.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:m.creating?"Creating...":"Create backup"})]}),m.error?e.jsx("p",{className:"mt-2 text-xs text-rose-300",children:m.error}):m.message?e.jsx("p",{className:"mt-2 text-xs text-emerald-300",children:m.message}):null,e.jsx("div",{className:"mt-3 space-y-2",children:m.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(x=>{const w=m.renamingId===x.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:[w?e.jsxs("div",{className:"flex max-w-xl gap-2",children:[e.jsx("input",{"aria-label":`Rename ${x.label}`,value:m.renameDraft,onChange:M=>H(V=>({...V,renameDraft:M.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 ${x.label}`,onClick:()=>void T(x),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:()=>H(M=>({...M,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:x.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 ",qo(x.createdAt)]}),de.map(M=>{var V;return e.jsxs("span",{className:"rounded-full border border-[var(--theme-border)] bg-[var(--theme-panel)] px-2 py-0.5 font-mono",children:[M.name,":"," ",(V=x.files[M.name])!=null&&V.exists?"saved":"missing"]},M.name)})]})]}),e.jsxs("div",{className:"flex shrink-0 flex-wrap gap-2",children:[e.jsx("button",{type:"button",onClick:()=>H(M=>({...M,renamingId:x.id,renameDraft:x.label,message:null,error:null})),disabled:w,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 A(x),disabled:m.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:m.applyingId===x.id?"Applying...":"Apply"})]})]})},x.id)})})]}):null]})})]});return t?e.jsxs("div",{className:"flex min-h-0 flex-col overflow-hidden",children:[Oe,d?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:()=>f(!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:Y})]}),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:()=>f(!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(Qt,{})})]})]}),e.jsx("div",{className:"min-h-0 flex-1 overflow-y-auto p-4",children:ae})]})]}):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:Oe}),g&&k?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:g}),e.jsx("p",{className:"mt-1 break-all font-mono text-xs text-[var(--theme-fg-muted)]",children:k.path})]}),e.jsxs("div",{className:"flex items-center gap-2",children:[k.error?e.jsx("span",{className:"text-xs text-rose-300",children:k.error}):k.saveMessage?e.jsx("span",{className:"text-xs text-emerald-300",children:k.saveMessage}):null,e.jsx("button",{type:"button","aria-label":`Save ${g}`,onClick:()=>void ke(g),disabled:k.loading||k.saving||k.draftContent===k.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:k.saving?"Saving...":"Save"}),e.jsx("button",{type:"button","aria-label":"Close File Editor",onClick:()=>C(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(Qt,{})})]})]}),e.jsx("div",{className:"min-h-0 flex-1 overflow-y-auto p-4 sm:p-5",children:e.jsx("textarea",{"aria-label":`Edit ${g}`,value:k.draftContent,onChange:x=>S(w=>({...w,[g]:{...jt(g),...w[g],draftContent:x.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:k.loading?"Loading...":`Edit ${g} here`})})]})}):null]})}function pn({className:t=""}){const a=ot();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(Qt,{}):e.jsx(Ho,{})}):null}function fn({className:t=""}){const a=ot(),s=ua(),r=He(),l=n.useRef(null),o=s.pathname==="/workspaces"||/^\/devices\/[^/]+\/workspaces$/.test(s.pathname),i=s.pathname==="/threads/import"||/^\/devices\/[^/]+\/threads\/import$/.test(s.pathname);return n.useEffect(()=>{if(!(a!=null&&a.navOpen))return;const d=a;function f(g){const C=g.target;if(!C)return;const h=l.current;h!=null&&h.contains(C)||C instanceof Element&&C.closest('[aria-controls="app-shell-navigation-menu"]')||d.closeNav()}return document.addEventListener("pointerdown",f),()=>{document.removeEventListener("pointerdown",f)}},[a]),a!=null&&a.navOpen?e.jsxs("div",{ref:l,id:"app-shell-navigation-menu",onPointerDown:d=>{d.stopPropagation()},onMouseDown:d=>{d.stopPropagation()},onTouchStart:d=>{d.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:o,onClick:()=>{o||(a.closeNav(),r(Ot()))},className:Ca(o),children:"Workspaces"}),e.jsx("button",{type:"button",disabled:i,onClick:()=>{i||(a.closeNav(),r(Ua("/threads/import")))},className:Ca(i),children:"Import Session"}),e.jsx("button",{type:"button",onClick:()=>{a.openSettings()},className:Ca(),children:"Settings"})]})]}):null}function Ni(t){const a=(t==null?void 0:t.trim())??"";return a?Array.from(a).slice(0,2).join("").toUpperCase():"??"}function xn(){const t=He(),a=ua(),[s,r]=n.useState(null),[l,o]=n.useState(!1);n.useEffect(()=>{if(!rt())return;let g=!1;return Rt().then(C=>{g||r(C.authenticated?C:null)}).catch(()=>{g||r(null)}),()=>{g=!0}},[a.pathname]),n.useEffect(()=>{o(!1)},[a.pathname]);const i=(s==null?void 0:s.user)??null,d=n.useMemo(()=>Ni(i==null?void 0:i.username),[i==null?void 0:i.username]);if(!rt()||!i)return null;async function f(){await tn(),r(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 ${i.username}`,className:"inline-flex h-10 w-10 items-center justify-center rounded-full border border-[var(--theme-border)] bg-[var(--theme-panel)] text-sm font-semibold text-[var(--theme-fg)] shadow-lg transition hover:bg-[var(--theme-hover)] focus:outline-none focus:ring-2 focus:ring-[var(--theme-accent-ring)]",onClick:()=>o(g=>!g),type:"button",children:d}),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:i.username}),e.jsx("p",{className:"truncate text-xs text-[var(--theme-fg-muted)]",children:i.email})]}),e.jsxs(ze,{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(ie.Settings,{className:"h-4 w-4"}),"Account settings"]}),e.jsxs(ze,{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(ie.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 f(),role:"menuitem",type:"button",children:[e.jsx(ie.LogOut,{className:"h-4 w-4"}),"Logout"]})]}):null]})}function gn({eyebrow:t="Supervisor Access",description:a="Use the admin credentials configured on this Remote Codex server.",onLogin:s}){const[r,l]=n.useState(""),[o,i]=n.useState(""),[d,f]=n.useState(null),[g,C]=n.useState(!1);async function h(S){S.preventDefault(),f(null),C(!0);try{await s({username:r,password:o})}catch(k){k instanceof te?f(k.payload.message):f("Unable to sign in.")}finally{C(!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:t}),e.jsx("h1",{className:"mt-2 text-2xl font-semibold tracking-normal text-[var(--theme-fg)]",children:"Sign in"}),e.jsx("p",{className:"mt-2 text-sm leading-6 text-[var(--theme-muted)]",children:a})]}),e.jsxs("form",{onSubmit:h,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:g,name:"username",onChange:S=>l(S.target.value),value:r})]}),e.jsxs("label",{className:"block",children:[e.jsx("span",{className:"text-sm font-medium text-[var(--theme-fg-soft)]",children:"Password"}),e.jsx("input",{autoComplete:"current-password",className:"mt-2 h-11 w-full rounded-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:g,name:"password",onChange:S=>i(S.target.value),type:"password",value:o})]}),d&&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:d}),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:g||!r.trim()||!o,type:"submit",children:g?"Signing in...":"Sign in"})]})]})})}function Ea(t,a){return t instanceof te?t.payload.message:t instanceof Error?t.message:a}function ki(){var K;const[t,a]=n.useState(null),[s,r]=n.useState(""),[l,o]=n.useState(""),[i,d]=n.useState(""),[f,g]=n.useState(""),[C,h]=n.useState(!0),[S,k]=n.useState(!1),[p,v]=n.useState(!1),[q,_]=n.useState(null),[D,L]=n.useState(null),[E,z]=n.useState(!1);async function Q(){var m;h(!0),L(null);try{Xe();const H=await Rt();a(H),r(((m=H.user)==null?void 0:m.username)??"")}catch(H){L(Ea(H,"Unable to load account."))}finally{h(!1)}}n.useEffect(()=>{Q()},[]);async function c(m){m.preventDefault(),k(!0),L(null),_(null);try{const H=await hl({username:s});a(I=>I!=null&&I.authenticated?{...I,user:H}:I),r(H.username),_("Account updated.")}catch(H){L(Ea(H,"Unable to update account."))}finally{k(!1)}}async function P(m){m.preventDefault(),v(!0),L(null),_(null);try{if(i!==f){L("New passwords do not match.");return}await pl({currentPassword:l,newPassword:i}),o(""),d(""),g(""),_("Password changed.")}catch(H){L(Ea(H,"Unable to change password."))}finally{v(!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(ze,{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"})]}),C?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(mr,{tone:"danger",children:D}):null,q?e.jsx(mr,{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:c,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:((K=t.user)==null?void 0:K.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:m=>r(m.target.value),value:s})]}),e.jsxs("button",{className:"relay-button-primary inline-flex h-10 items-center justify-center gap-2",disabled:S||!s.trim(),type:"submit",children:[e.jsx(ie.Save,{className:"h-4 w-4"}),"Save"]})]}),e.jsxs("button",{className:"relay-button-secondary inline-flex items-center gap-2",onClick:()=>z(!0),type:"button",children:[E?e.jsx(ie.CheckCircle2,{className:"h-4 w-4"}):e.jsx(ie.MailCheck,{className:"h-4 w-4"}),E?"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:P,children:[e.jsx(Ia,{label:"Current password",value:l,onChange:o}),e.jsx(Ia,{label:"New password",value:i,onChange:d}),e.jsx(Ia,{label:"Confirm password",value:f,onChange:g}),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:p||!l||i.length<8||!f,type:"submit",children:[e.jsx(ie.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 Ia({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:r=>s(r.target.value),type:"password",value:a})]})}function mr({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 mt(t){return t instanceof te?t.payload.message:t instanceof Error?t.message:"Unable to update relay admin state."}function Si(){const[t,a]=n.useState(null),[s,r]=n.useState(!0),[l,o]=n.useState(null),[i,d]=n.useState(!1),[f,g]=n.useState(null),[C,h]=n.useState("overview"),[S,k]=n.useState(7),[p,v]=n.useState(null);async function q(P=S,K={}){K.showLoading!==!1&&r(!0),o(null);try{Xe();const m=await xl(P);a(m),v(m.settings),k(m.conversationWindowDays),d(!1)}catch(m){m instanceof te&&(m.statusCode===401||m.statusCode===403)?(a(null),d(!0),o(null)):o(mt(m))}finally{r(!1)}}n.useEffect(()=>{q()},[]);const _=n.useMemo(()=>{const P=(t==null?void 0:t.users)??[],K=(t==null?void 0:t.devices)??[];return{users:P.length,enabledUsers:P.filter(m=>m.enabled).length,devices:K.length,onlineDevices:K.filter(m=>m.connected).length,conversations:P.reduce((m,H)=>m+H.conversationCount,0),shares:(t==null?void 0:t.shares.filter(m=>!m.revokedAt).length)??0}},[t]);async function D(P,K){g(P),o(null);try{const m=await bl(P,K);a(H=>fr(H,m))}catch(m){o(mt(m))}finally{g(null)}}async function L(P){g(`delete:${P}`),o(null);try{await vl(P),await q(S,{showLoading:!1})}catch(K){o(mt(K))}finally{g(null)}}async function E(P,K){g(`reset:${P}`),o(null);try{const m=await yl(P,K);a(H=>fr(H,m))}catch(m){o(mt(m))}finally{g(null)}}async function z(P){if(P.preventDefault(),!!p){g("settings"),o(null);try{const K=await gl(p);a(m=>m&&{...m,registrationEnabled:K.registrationEnabled,settings:K.settings}),v(K.settings)}catch(K){o(mt(K))}finally{g(null)}}}async function Q(P,K){g(`${K}:${P}`),o(null);try{K==="approve"?await wl(P):await jl(P),await q(S,{showLoading:!1})}catch(m){o(mt(m))}finally{g(null)}}async function c(P){await dl(P),await q(S)}return i?e.jsx(gn,{description:"Use the relay admin credentials for this server. This does not replace your normal relay account.",eyebrow:"Relay Admin",onLogin:c}):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(Ci,{onLogout:()=>{a(null),d(!0)}}),e.jsxs("div",{className:"mx-auto flex w-full max-w-7xl flex-col gap-5",children:[e.jsxs("header",{className:"flex flex-col gap-4 border-b border-[var(--theme-border)] pb-5 lg:flex-row lg:items-end lg:justify-between",children:[e.jsxs("div",{children:[e.jsx("p",{className:"text-xs font-semibold uppercase tracking-[0.22em] text-[var(--theme-fg-muted)]",children:"Relay Admin"}),e.jsx("h1",{className:"mt-2 text-2xl font-semibold text-[var(--theme-fg)]",children:"Operations panel"}),e.jsx("p",{className:"mt-1 max-w-2xl text-sm text-[var(--theme-fg-muted)]",children:"Accounts, devices, usage, registration policy, and shared thread access."})]}),e.jsxs("div",{className:"flex flex-wrap items-center gap-2",children:[e.jsxs("label",{className:"flex items-center gap-2 text-sm text-[var(--theme-fg-muted)]",children:["Usage window",e.jsxs("select",{className:"relay-input h-10 w-24",onChange:P=>void q(Number(P.target.value)),value:S,children:[e.jsx("option",{value:1,children:"1 day"}),e.jsx("option",{value:7,children:"7 days"}),e.jsx("option",{value:30,children:"30 days"}),e.jsx("option",{value:90,children:"90 days"})]})]}),e.jsx(ze,{className:"relay-button-secondary",to:"/relay-portal",children:"Portal"}),e.jsxs("button",{className:"relay-button-secondary inline-flex items-center gap-2",onClick:()=>void q(S),type:"button",children:[e.jsx(ie.RefreshCw,{className:"h-4 w-4"}),"Refresh"]})]})]}),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}):null,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..."}):t?e.jsxs(e.Fragment,{children:[e.jsxs("section",{className:"grid gap-3 sm:grid-cols-2 xl:grid-cols-4",children:[e.jsx(Jt,{icon:e.jsx(ie.Users,{className:"h-5 w-5"}),label:"Users",value:_.users,detail:`${_.enabledUsers} enabled`}),e.jsx(Jt,{icon:e.jsx(ie.Database,{className:"h-5 w-5"}),label:"Devices",value:_.devices,detail:`${_.onlineDevices} online`}),e.jsx(Jt,{icon:e.jsx(ie.Clock3,{className:"h-5 w-5"}),label:`Conversations, ${t.conversationWindowDays}d`,value:_.conversations,detail:"Relay prompt/start events"}),e.jsx(Jt,{icon:e.jsx(ie.Share2,{className:"h-5 w-5"}),label:"Active shares",value:_.shares,detail:`${t.pendingRegistrations.length} pending registrations`})]}),e.jsx("nav",{className:"flex gap-2 overflow-x-auto border-b border-[var(--theme-border)] pb-2",children:["overview","users","devices","shares","settings"].map(P=>e.jsx("button",{className:`rounded-md px-3 py-2 text-sm font-medium ${C===P?"bg-[var(--theme-accent-soft)] text-[var(--theme-fg)]":"text-[var(--theme-fg-muted)] hover:bg-[var(--theme-hover)] hover:text-[var(--theme-fg)]"}`,onClick:()=>h(P),type:"button",children:Mi(P)},P))}),C==="overview"?e.jsx(Ti,{summary:t}):null,C==="users"?e.jsx(Ei,{busyKey:f,onDeleteUser:L,onResetPassword:E,onUpdateUser:D,users:t.users}):null,C==="devices"?e.jsx(Ii,{devices:t.devices,users:t.users}):null,C==="shares"?e.jsx(Ai,{shares:t.shares}):null,C==="settings"&&p?e.jsx(Ri,{busy:f==="settings",draft:p,onChange:v,onReviewRegistration:Q,onSave:z,pending:t.pendingRegistrations,reviewBusyKey:f}):null]}):null]})]})}function Jt({icon:t,label:a,value:s,detail:r}){return e.jsx("article",{className:"rounded-lg border border-[var(--theme-border)] bg-[var(--theme-panel)] p-4",children:e.jsxs("div",{className:"flex items-start gap-3",children:[e.jsx("span",{className:"rounded-lg border border-[var(--theme-border)] bg-[var(--theme-surface)] p-2 text-[var(--theme-accent-strong)]",children:t}),e.jsxs("div",{className:"min-w-0",children:[e.jsx("p",{className:"text-xs font-medium uppercase tracking-[0.14em] text-[var(--theme-fg-muted)]",children:a}),e.jsx("p",{className:"mt-1 text-2xl font-semibold text-[var(--theme-fg)]",children:s.toLocaleString()}),e.jsx("p",{className:"mt-1 text-xs text-[var(--theme-fg-muted)]",children:r})]})]})})}function Ci({onLogout:t}){const[a,s]=n.useState(null),[r,l]=n.useState(!1);n.useEffect(()=>{let d=!1;return en().then(f=>{d||s(f.authenticated?f:null)}).catch(()=>{d||s(null)}),()=>{d=!0}},[]);const o=(a==null?void 0:a.user)??null;if(!o)return null;async function i(){await cl(),s(null),l(!1),t()}return e.jsxs("div",{className:"fixed right-3 top-[calc(env(safe-area-inset-top)+0.55rem)] z-50",children:[e.jsx("button",{"aria-expanded":r,"aria-haspopup":"menu","aria-label":`Relay admin menu for ${o.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:()=>l(d=>!d),type:"button",children:Bi(o.username)}),r?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:o.username}),e.jsx("p",{className:"truncate text-xs text-[var(--theme-fg-muted)]",children:o.email}),e.jsx("p",{className:"mt-1 text-[11px] uppercase tracking-[0.14em] text-[var(--theme-fg-muted)]",children:"Admin session"})]}),e.jsxs("button",{className:"flex w-full items-center gap-2 rounded-lg px-3 py-2 text-left text-sm text-[var(--status-danger-fg)] transition hover:bg-[var(--status-danger-bg)]",onClick:()=>void i(),role:"menuitem",type:"button",children:[e.jsx(ie.LogOut,{className:"h-4 w-4"}),"Logout admin"]})]}):null]})}function Ti({summary:t}){const a=[...t.users].sort(_i("lastSeenAt")).slice(0,6),s=t.devices.filter(r=>r.connected);return e.jsxs("section",{className:"grid gap-4 xl:grid-cols-[minmax(0,1fr)_minmax(22rem,0.7fr)]",children:[e.jsx(nt,{title:"Recent users",detail:"Last authenticated relay activity.",children:e.jsx("div",{className:"divide-y divide-[var(--theme-border)]",children:a.map(r=>e.jsxs("div",{className:"flex items-center justify-between gap-3 py-3",children:[e.jsxs("div",{className:"min-w-0",children:[e.jsx("p",{className:"truncate text-sm font-medium text-[var(--theme-fg)]",children:r.username}),e.jsx("p",{className:"truncate text-xs text-[var(--theme-fg-muted)]",children:r.email})]}),e.jsxs("div",{className:"text-right text-xs text-[var(--theme-fg-muted)]",children:[e.jsx("p",{children:Ge(r.lastSeenAt)}),e.jsxs("p",{children:[r.conversationCount," conversations"]})]})]},r.id))})}),e.jsx(nt,{title:"Online devices",detail:"Devices with an active supervisor tunnel.",children:s.length?e.jsx("div",{className:"space-y-3",children:s.map(r=>e.jsx(Pi,{device:r},r.id))}):e.jsx(ha,{children:"No supervisors are connected."})})]})}function Ei({busyKey:t,onDeleteUser:a,onResetPassword:s,onUpdateUser:r,users:l}){const[o,i]=n.useState(""),[d,f]=n.useState({key:"lastSeenAt",direction:"desc"}),[g,C]=n.useState(null),[h,S]=n.useState(null),k=n.useMemo(()=>{const v=pr(o);return l.filter(q=>v?pr(`${q.username} ${q.email}`).includes(v):!0).sort((q,_)=>Ui(q,_,d))},[o,d,l]);function p(v){f(q=>({key:v,direction:q.key===v&&q.direction==="desc"?"asc":"desc"}))}return e.jsxs(e.Fragment,{children:[e.jsxs(nt,{title:"Users",detail:"Registered relay accounts. Admin accounts are excluded from workspace and device operations.",children:[e.jsxs("div",{className:"mb-4 flex flex-col gap-3 lg:flex-row lg:items-center lg:justify-between",children:[e.jsxs("label",{className:"relative block min-w-0 flex-1",children:[e.jsx(ie.Search,{className:"pointer-events-none absolute left-3 top-1/2 h-4 w-4 -translate-y-1/2 text-[var(--theme-fg-muted)]"}),e.jsx("input",{className:"relay-input w-full pl-9",onChange:v=>i(v.target.value),placeholder:"Search username or email",value:o})]}),e.jsxs("p",{className:"text-sm text-[var(--theme-fg-muted)]",children:[k.length.toLocaleString()," of ",l.length.toLocaleString()," users"]})]}),e.jsxs(Za,{minWidth:"68rem",children:[e.jsx("thead",{children:e.jsxs("tr",{children:[e.jsx(Nt,{active:d.key==="username",direction:d.direction,onClick:()=>p("username"),children:"User"}),e.jsx(Nt,{active:d.key==="enabled",direction:d.direction,onClick:()=>p("enabled"),children:"Status"}),e.jsx(Nt,{active:d.key==="lastSeenAt",direction:d.direction,onClick:()=>p("lastSeenAt"),children:"Last used"}),e.jsx(Nt,{active:d.key==="conversationCount",direction:d.direction,onClick:()=>p("conversationCount"),children:"Conversations"}),e.jsx(Nt,{active:d.key==="deviceCount",direction:d.direction,onClick:()=>p("deviceCount"),children:"Devices"}),e.jsx(Ae,{children:"Role"}),e.jsx(Ae,{children:"Actions"})]})}),e.jsx("tbody",{children:k.map(v=>e.jsxs("tr",{children:[e.jsxs(Ne,{strong:!0,children:[v.username,e.jsx("div",{className:"text-xs font-normal text-[var(--theme-fg-muted)]",children:v.email})]}),e.jsx(Ne,{children:e.jsx(bn,{active:v.enabled,children:v.enabled?"Enabled":"Disabled"})}),e.jsx(Ne,{children:Ge(v.lastSeenAt)}),e.jsx(Ne,{children:v.conversationCount.toLocaleString()}),e.jsx(Ne,{children:v.deviceCount.toLocaleString()}),e.jsx(Ne,{children:v.role}),e.jsx(Ne,{children:e.jsxs("div",{className:"flex flex-wrap gap-2",children:[e.jsx("button",{className:"relay-button-secondary",disabled:t===v.id||v.role==="admin",onClick:()=>r(v.id,!v.enabled),type:"button",children:v.enabled?"Disable":"Enable"}),e.jsxs("button",{className:"relay-button-secondary inline-flex items-center gap-2",disabled:t===`reset:${v.id}`||v.role==="admin",onClick:()=>C(v),type:"button",children:[e.jsx(ie.KeyRound,{className:"h-4 w-4"}),"Reset"]}),e.jsxs("button",{className:"relay-button-secondary inline-flex items-center gap-2 text-[var(--status-danger-fg)]",disabled:t===`delete:${v.id}`||v.role==="admin",onClick:()=>S(v),type:"button",children:[e.jsx(ie.Trash2,{className:"h-4 w-4"}),"Delete"]})]})})]},v.id))})]}),k.length?null:e.jsx(ha,{children:"No users match the current search."})]}),g?e.jsx(Oi,{busy:t===`reset:${g.id}`,onClose:()=>C(null),onSubmit:async v=>{await s(g.id,v),C(null)},user:g}):null,h?e.jsx(Li,{busy:t===`delete:${h.id}`,confirmLabel:"Delete user",description:`Delete ${h.username}, their devices, shares, and access history. This cannot be undone.`,onClose:()=>S(null),onConfirm:async()=>{await a(h.id),S(null)},title:"Delete relay user"}):null]})}function Ii({devices:t,users:a}){const[s,r]=n.useState("all"),[l,o]=n.useState("all"),[i,d]=n.useState("all"),[f,g]=n.useState("lastActivity"),[C,h]=n.useState("desc"),S=n.useMemo(()=>a.filter(p=>t.some(v=>v.ownerUserId===p.id)),[t,a]),k=n.useMemo(()=>t.filter(p=>s==="all"||p.ownerUserId===s).filter(p=>l==="all"||(l==="online"?p.connected:!p.connected)).filter(p=>i==="all"||$i(na(p),i)).sort((p,v)=>Di(p,v,f,C)),[i,t,C,s,f,l]);return e.jsxs(nt,{title:"Devices",detail:"Supervisor devices grouped by owner, connection state, activity, and loaded workspace metadata.",children:[e.jsxs("div",{className:"mb-4 grid gap-3 md:grid-cols-2 xl:grid-cols-5",children:[e.jsxs("label",{className:"block text-sm text-[var(--theme-fg-soft)]",children:["Owner",e.jsxs("select",{className:"relay-input mt-2 w-full",onChange:p=>r(p.target.value),value:s,children:[e.jsx("option",{value:"all",children:"All users"}),S.map(p=>e.jsx("option",{value:p.id,children:p.username},p.id))]})]}),e.jsxs("label",{className:"block text-sm text-[var(--theme-fg-soft)]",children:["Status",e.jsxs("select",{className:"relay-input mt-2 w-full",onChange:p=>o(p.target.value),value:l,children:[e.jsx("option",{value:"all",children:"All devices"}),e.jsx("option",{value:"online",children:"Online"}),e.jsx("option",{value:"offline",children:"Offline"})]})]}),e.jsxs("label",{className:"block text-sm text-[var(--theme-fg-soft)]",children:["Last activity",e.jsxs("select",{className:"relay-input mt-2 w-full",onChange:p=>d(p.target.value),value:i,children:[e.jsx("option",{value:"all",children:"Any time"}),e.jsx("option",{value:"24h",children:"Last 24 hours"}),e.jsx("option",{value:"7d",children:"Last 7 days"}),e.jsx("option",{value:"30d",children:"Last 30 days"})]})]}),e.jsxs("label",{className:"block text-sm text-[var(--theme-fg-soft)]",children:["Sort by",e.jsxs("select",{className:"relay-input mt-2 w-full",onChange:p=>g(p.target.value),value:f,children:[e.jsx("option",{value:"lastActivity",children:"Last activity"}),e.jsx("option",{value:"name",children:"Device name"}),e.jsx("option",{value:"ownerUsername",children:"Owner"}),e.jsx("option",{value:"connected",children:"Connection"}),e.jsx("option",{value:"createdAt",children:"Created"}),e.jsx("option",{value:"workspaceCount",children:"Workspaces"}),e.jsx("option",{value:"threadCount",children:"Threads"})]})]}),e.jsxs("label",{className:"block text-sm text-[var(--theme-fg-soft)]",children:["Direction",e.jsxs("select",{className:"relay-input mt-2 w-full",onChange:p=>h(p.target.value),value:C,children:[e.jsx("option",{value:"desc",children:"Descending"}),e.jsx("option",{value:"asc",children:"Ascending"})]})]})]}),e.jsxs(Za,{minWidth:"74rem",children:[e.jsx("thead",{children:e.jsxs("tr",{children:[e.jsx(Ae,{children:"Device"}),e.jsx(Ae,{children:"Owner"}),e.jsx(Ae,{children:"Status"}),e.jsx(Ae,{children:"Last activity"}),e.jsx(Ae,{children:"Inventory"}),e.jsx(Ae,{children:"Network"})]})}),e.jsx("tbody",{children:k.map(p=>{var v,q;return e.jsxs("tr",{children:[e.jsxs(Ne,{strong:!0,children:[p.name,e.jsx("div",{className:"text-xs font-normal text-[var(--theme-fg-muted)]",children:p.tokenPreview})]}),e.jsxs(Ne,{children:[e.jsx("span",{className:"font-medium text-[var(--theme-fg-soft)]",children:p.ownerUsername}),e.jsx("div",{className:"text-xs text-[var(--theme-fg-muted)]",children:p.ownerEmail})]}),e.jsx(Ne,{children:e.jsx(bn,{active:p.connected,children:p.connected?"Online":"Offline"})}),e.jsxs(Ne,{children:[Ge(na(p)),e.jsxs("div",{className:"text-xs text-[var(--theme-fg-muted)]",children:["created ",Ge(p.createdAt)]})]}),e.jsxs(Ne,{children:[e.jsxs("span",{children:[p.workspaces.length.toLocaleString()," workspaces"]}),e.jsx("span",{className:"mx-2 text-[var(--theme-fg-muted)]",children:"·"}),e.jsxs("span",{children:[p.threads.length.toLocaleString()," threads"]}),e.jsx("div",{className:"mt-1 truncate text-xs text-[var(--theme-fg-muted)]",children:((v=p.workspaces[0])==null?void 0:v.label)??"No workspace metadata"}),e.jsx("div",{className:"truncate text-xs text-[var(--theme-fg-muted)]",children:((q=p.threads[0])==null?void 0:q.title)??"No thread metadata"})]}),e.jsxs(Ne,{children:[p.ipAddress??"IP unavailable",e.jsxs("div",{className:"text-xs text-[var(--theme-fg-muted)]",children:["heartbeat ",Ge(p.lastHeartbeatAt)]})]})]},p.id)})})]}),k.length?null:e.jsx(ha,{children:"No devices match the selected filters."})]})}function Ai({shares:t}){return e.jsx(nt,{title:"Share relationships",detail:"Thread grants between relay users. Revoked grants remain visible for audit.",children:e.jsxs(Za,{minWidth:"62rem",children:[e.jsx("thead",{children:e.jsxs("tr",{children:[e.jsx(Ae,{children:"Owner"}),e.jsx(Ae,{children:"Target"}),e.jsx(Ae,{children:"Thread"}),e.jsx(Ae,{children:"Device"}),e.jsx(Ae,{children:"Permissions"}),e.jsx(Ae,{children:"Last access"}),e.jsx(Ae,{children:"Status"})]})}),e.jsx("tbody",{children:t.map(a=>e.jsxs("tr",{children:[e.jsx(Ne,{strong:!0,children:a.ownerUsername}),e.jsx(Ne,{children:a.targetUsername}),e.jsxs(Ne,{children:[e.jsx("span",{className:"font-medium text-[var(--theme-fg)]",children:a.threadTitle??a.label??"Thread unavailable"}),e.jsx("div",{className:"text-xs text-[var(--theme-fg-muted)]",children:a.workspaceLabel??"Workspace unavailable"})]}),e.jsx(Ne,{children:a.deviceName}),e.jsxs(Ne,{children:[a.threadAccess," / ",Hi(a.workspaceAccess)]}),e.jsx(Ne,{children:Ge(a.lastAccessedAt)}),e.jsx(Ne,{children:a.revokedAt?"Revoked":a.expiresAt&&a.expiresAt<=new Date().toISOString()?"Expired":"Active"})]},a.id))})]})})}function Ri({busy:t,draft:a,onChange:s,onReviewRegistration:r,onSave:l,pending:o,reviewBusyKey:i}){return e.jsxs("section",{className:"grid gap-4 xl:grid-cols-[minmax(0,0.9fr)_minmax(0,1.1fr)]",children:[e.jsx(nt,{title:"Registration settings",detail:"Stored in the relay database. Environment password seeds this once if empty.",children:e.jsxs("form",{className:"space-y-4",onSubmit:l,children:[e.jsx(hr,{checked:a.enabled,label:"Open registration",onChange:d=>s({...a,enabled:d})}),e.jsxs("label",{className:"block text-sm text-[var(--theme-fg-soft)]",children:["Registration password",e.jsx("input",{className:"relay-input mt-2 w-full",onChange:d=>s({...a,registrationPassword:d.target.value}),placeholder:"Leave empty for no invite password",value:a.registrationPassword??""})]}),e.jsx(hr,{checked:a.approvalRequired,label:"Require admin approval",onChange:d=>s({...a,approvalRequired:d})}),e.jsxs("button",{className:"relay-button-primary inline-flex items-center gap-2",disabled:t,type:"submit",children:[e.jsx(ie.Settings,{className:"h-4 w-4"}),"Save settings"]})]})}),e.jsx(nt,{title:"Pending registrations",detail:"Approve creates the user. Reject keeps an audit trail.",children:o.length?e.jsx("div",{className:"divide-y divide-[var(--theme-border)]",children:o.map(d=>e.jsxs("div",{className:"flex flex-col gap-3 py-3 sm:flex-row sm:items-center sm:justify-between",children:[e.jsxs("div",{className:"min-w-0",children:[e.jsx("p",{className:"truncate text-sm font-medium text-[var(--theme-fg)]",children:d.username}),e.jsxs("p",{className:"truncate text-xs text-[var(--theme-fg-muted)]",children:[d.email," · ",Ge(d.createdAt)]})]}),e.jsxs("div",{className:"flex gap-2",children:[e.jsxs("button",{className:"relay-button-primary inline-flex items-center gap-2",disabled:i===`approve:${d.id}`,onClick:()=>r(d.id,"approve"),type:"button",children:[e.jsx(ie.Check,{className:"h-4 w-4"}),"Approve"]}),e.jsx("button",{className:"relay-button-secondary",disabled:i===`reject:${d.id}`,onClick:()=>r(d.id,"reject"),type:"button",children:"Reject"})]})]},d.id))}):e.jsx(ha,{children:"No pending applications."})})]})}function Pi({device:t}){return e.jsxs("div",{className:"grid gap-2 text-xs text-[var(--theme-fg-muted)] sm:grid-cols-2",children:[e.jsxs("p",{children:["Owner: ",e.jsx("span",{className:"text-[var(--theme-fg-soft)]",children:t.ownerEmail})]}),e.jsxs("p",{children:["IP: ",e.jsx("span",{className:"text-[var(--theme-fg-soft)]",children:t.ipAddress??"unavailable"})]}),e.jsxs("p",{children:["Connected: ",e.jsx("span",{className:"text-[var(--theme-fg-soft)]",children:Ge(t.connectedAt)})]}),e.jsxs("p",{children:["Heartbeat: ",e.jsx("span",{className:"text-[var(--theme-fg-soft)]",children:Ge(t.lastHeartbeatAt)})]})]})}function nt({aside:t,children:a,detail:s,title:r}){return e.jsxs("section",{className:"rounded-lg border border-[var(--theme-border)] bg-[var(--theme-panel)] p-4",children:[e.jsxs("div",{className:"mb-4 flex items-start justify-between gap-3",children:[e.jsxs("div",{children:[e.jsx("h2",{className:"text-base font-semibold text-[var(--theme-fg)]",children:r}),e.jsx("p",{className:"mt-1 text-sm text-[var(--theme-fg-muted)]",children:s})]}),t]}),a]})}function Za({children:t,minWidth:a}){return e.jsx("div",{className:"overflow-x-auto",children:e.jsx("table",{className:"w-full border-collapse text-left text-sm",style:{minWidth:a},children:t})})}function Ae({children:t}){return e.jsx("th",{className:"border-b border-[var(--theme-border)] py-2 pr-3 text-xs font-semibold uppercase tracking-[0.14em] text-[var(--theme-fg-muted)]",children:t})}function Nt({active:t,children:a,direction:s,onClick:r}){const l=t?s==="asc"?ie.ArrowUp:ie.ArrowDown:ie.ArrowUpDown;return e.jsx("th",{className:"border-b border-[var(--theme-border)] py-2 pr-3 text-left text-xs font-semibold uppercase tracking-[0.14em] text-[var(--theme-fg-muted)]",children:e.jsxs("button",{className:`inline-flex items-center gap-1.5 rounded-md px-1.5 py-1 transition hover:bg-[var(--theme-hover)] hover:text-[var(--theme-fg)] ${t?"text-[var(--theme-fg)]":""}`,onClick:r,type:"button",children:[a,e.jsx(l,{className:"h-3.5 w-3.5"})]})})}function Ne({children:t,strong:a=!1}){return e.jsx("td",{className:`border-b border-[var(--theme-border)] py-3 pr-3 ${a?"font-medium text-[var(--theme-fg)]":"text-[var(--theme-fg-muted)]"}`,children:t})}function hr({checked:t,label:a,onChange:s}){return e.jsxs("label",{className:"flex items-center gap-3 text-sm text-[var(--theme-fg-soft)]",children:[e.jsx("input",{checked:t,className:"h-4 w-4 accent-[var(--theme-accent)]",onChange:r=>s(r.target.checked),type:"checkbox"}),a]})}function bn({active:t,children:a}){return e.jsx("span",{className:`rounded-full border px-2 py-0.5 text-xs ${t?"border-[var(--status-success-border)] bg-[var(--status-success-bg)] text-[var(--status-success-fg)]":"border-[var(--theme-border)] bg-[var(--theme-surface)] text-[var(--theme-fg-muted)]"}`,children:a})}function ha({children:t}){return e.jsx("p",{className:"rounded-lg border border-dashed border-[var(--theme-border)] bg-[var(--theme-surface)] p-4 text-sm text-[var(--theme-fg-muted)]",children:t})}function Oi({busy:t,onClose:a,onSubmit:s,user:r}){const[l,o]=n.useState(""),[i,d]=n.useState(null);async function f(g){if(g.preventDefault(),d(null),l.length<8){d("Password must be at least 8 characters.");return}await s(l)}return e.jsx("div",{className:"fixed inset-0 z-50 flex items-center justify-center bg-[color-mix(in_oklch,var(--app-bg)_82%,transparent)] px-4 py-8",children:e.jsxs("section",{className:"w-full max-w-md rounded-lg border border-[var(--theme-border)] bg-[var(--theme-panel)] p-5 shadow-2xl shadow-[color-mix(in_oklch,var(--app-fg)_18%,transparent)]",children:[e.jsx("h2",{className:"text-lg font-semibold text-[var(--theme-fg)]",children:"Reset password"}),e.jsxs("p",{className:"mt-1 text-sm text-[var(--theme-fg-muted)]",children:["Set a new relay password for ",r.username,"."]}),e.jsxs("form",{className:"mt-5 space-y-4",onSubmit:f,children:[e.jsxs("label",{className:"block text-sm text-[var(--theme-fg-soft)]",children:["New password",e.jsx("input",{autoFocus:!0,className:"relay-input mt-2 w-full",onChange:g=>o(g.target.value),type:"password",value:l})]}),i?e.jsx("p",{className:"rounded-lg border border-[var(--status-danger-border)] bg-[var(--status-danger-bg)] px-3 py-2 text-sm text-[var(--status-danger-fg)]",children:i}):null,e.jsxs("div",{className:"flex justify-end gap-2",children:[e.jsx("button",{className:"relay-button-secondary",onClick:a,type:"button",children:"Cancel"}),e.jsxs("button",{className:"relay-button-primary inline-flex items-center gap-2",disabled:t,type:"submit",children:[e.jsx(ie.KeyRound,{className:"h-4 w-4"}),"Save password"]})]})]})]})})}function Li({busy:t,confirmLabel:a,description:s,onClose:r,onConfirm:l,title:o}){return e.jsx("div",{className:"fixed inset-0 z-50 flex items-center justify-center bg-[color-mix(in_oklch,var(--app-bg)_82%,transparent)] px-4 py-8",children:e.jsxs("section",{className:"w-full max-w-md rounded-lg border border-[var(--status-danger-border)] bg-[var(--theme-panel)] p-5 shadow-2xl shadow-[color-mix(in_oklch,var(--app-fg)_18%,transparent)]",children:[e.jsx("h2",{className:"text-lg font-semibold text-[var(--theme-fg)]",children:o}),e.jsx("p",{className:"mt-2 text-sm leading-6 text-[var(--theme-fg-muted)]",children:s}),e.jsxs("div",{className:"mt-5 flex justify-end gap-2",children:[e.jsx("button",{className:"relay-button-secondary",onClick:r,type:"button",children:"Cancel"}),e.jsxs("button",{className:"inline-flex h-10 items-center gap-2 rounded-md bg-[var(--action-danger-bg)] px-4 text-sm font-semibold text-[var(--action-danger-fg)] transition hover:bg-[var(--action-danger-bg-hover)] disabled:cursor-not-allowed disabled:opacity-60",disabled:t,onClick:l,type:"button",children:[e.jsx(ie.Trash2,{className:"h-4 w-4"}),a]})]})]})})}function pr(t){return t.trim().toLowerCase()}function Ui(t,a,s){const r=s.direction==="asc"?1:-1;let l=0;return s.key==="username"?l=t.username.localeCompare(a.username):s.key==="enabled"?l=Number(t.enabled)-Number(a.enabled):s.key==="lastSeenAt"?l=ra(t.lastSeenAt,a.lastSeenAt):s.key==="conversationCount"?l=t.conversationCount-a.conversationCount:s.key==="deviceCount"?l=t.deviceCount-a.deviceCount:l=ra(t.createdAt,a.createdAt),l*r||t.username.localeCompare(a.username)}function Di(t,a,s,r){const l=r==="asc"?1:-1;let o=0;return s==="name"?o=t.name.localeCompare(a.name):s==="ownerUsername"?o=t.ownerUsername.localeCompare(a.ownerUsername):s==="connected"?o=Number(t.connected)-Number(a.connected):s==="lastActivity"?o=ra(na(t),na(a)):s==="createdAt"?o=ra(t.createdAt,a.createdAt):s==="workspaceCount"?o=t.workspaces.length-a.workspaces.length:o=t.threads.length-a.threads.length,o*l||t.name.localeCompare(a.name)}function ra(t,a){const s=Date.parse(t??""),r=Date.parse(a??""),l=Number.isFinite(s)?s:-1/0,o=Number.isFinite(r)?r:-1/0;return l-o}function na(t){return t.lastHeartbeatAt??t.connectedAt??t.createdAt}function $i(t,a){const s=Date.parse(t??"");if(!Number.isFinite(s))return!1;const r=a==="24h"?24:a==="7d"?168:720;return s>=Date.now()-r*60*60*1e3}function fr(t,a){return t&&{...t,users:t.users.map(s=>s.id===a.id?{...s,...a}:s)}}function Mi(t){switch(t){case"overview":return"Overview";case"users":return"Users";case"devices":return"Devices";case"shares":return"Shares";case"settings":return"Settings"}}function Hi(t){switch(t){case"write":return"workspace write";case"read":return"workspace read";case"none":default:return"no workspace"}}function _i(t){return(a,s)=>Date.parse(s[t]??"")-Date.parse(a[t]??"")}function Ge(t){return t?new Date(t).toLocaleString():"never"}function Bi(t){const a=(t==null?void 0:t.trim())??"";return a?Array.from(a).slice(0,2).join("").toUpperCase():"??"}const Wi=3e3;function kt(t,a){return t instanceof te?t.payload.message:t instanceof Error?t.message:a}function Fi(){const t=He(),[a,s]=n.useState(null),[r,l]=n.useState(""),[o,i]=n.useState(null),[d,f]=n.useState(null),[g,C]=n.useState(!0),[h,S]=n.useState(null),[k,p]=n.useState(null),[v,q]=n.useState(null),[_,D]=n.useState(null),L=n.useRef(!1),E=n.useCallback(async I=>{const X=(I==null?void 0:I.showLoading)??!0,he=(I==null?void 0:I.clearError)??!0;X&&C(!0),he&&p(null);try{Xe();const pe=await Va();L.current=!0,s(pe)}catch(pe){(X||!L.current)&&p(kt(pe,"Unable to load devices."))}finally{X&&C(!1)}},[]);n.useEffect(()=>{E();const I=window.setInterval(()=>{E({showLoading:!1,clearError:!1})},Wi);return()=>{window.clearInterval(I)}},[E]);async function z(I){I.preventDefault(),S("create"),p(null);try{const X=await an({name:r});i(X),l(""),await E({showLoading:!1})}catch(X){p(kt(X,"Unable to create device."))}finally{S(null)}}async function Q(I){if(window.confirm(`Delete relay device "${I.name}"?`)){S(I.id),p(null);try{await sn(I.id),(o==null?void 0:o.device.id)===I.id&&i(null),await E({showLoading:!1})}catch(X){p(kt(X,"Unable to delete device."))}finally{S(null)}}}function c(I){It(I.id),At(null),t(Fa(I.id))}function P(I){It(I.deviceId),At(I.threadId),t(Wa(I.threadId,I.deviceId))}async function K(I,X){S(`share:${I.id}`),p(null);try{await rn(I.id,{...X,workspaceId:I.workspaceId,expiresAt:I.expiresAt}),D(null),await E({showLoading:!1})}catch(he){p(kt(he,"Unable to update shared thread."))}finally{S(null)}}async function m(I){if(window.confirm(`Remove sharing access for "${Xa(I)}"?`)){S(`share:${I.id}`),p(null);try{await Ga(I.id),q(X=>X===I.id?null:X),await E({showLoading:!1})}catch(X){p(kt(X,"Unable to remove shared thread access."))}finally{S(null)}}}async function H(I){var he;const X=I.token;if(!X){p("This device token is not available. Create a new device token for devices created before token storage was enabled.");return}try{await((he=navigator.clipboard)==null?void 0:he.writeText(vn(X))),f(I.id),window.setTimeout(()=>{f(pe=>pe===I.id?null:pe)},1600)}catch{}}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.jsxs("div",{className:"mx-auto w-full max-w-6xl space-y-5 pr-12 sm:pr-0",children:[e.jsx("header",{className:"border-b border-[var(--theme-border)] pb-5",children:e.jsxs("div",{children:[e.jsx(ze,{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"})]})}),k?e.jsx(Gi,{tone:"danger",children:k}):null,o?e.jsx(Vi,{result:o}):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(ie.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:z,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:I=>l(I.target.value),placeholder:"MacBook Pro",value:r})]}),e.jsxs("button",{className:"relay-button-primary inline-flex h-10 w-full items-center justify-center gap-2",disabled:h==="create"||!r.trim(),type:"submit",children:[e.jsx(ie.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})]}),g?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(I=>e.jsx(zi,{busy:h===I.id,copiedSetup:d===I.id,device:I,onConnect:()=>c(I),onCopySetup:()=>void H(I),onDelete:()=>void Q(I),setupTokenAvailable:!!I.token},I.id))}):e.jsx("div",{className:"rounded-lg border border-dashed border-[var(--theme-border)] bg-[var(--theme-surface)] p-5 text-sm text-[var(--theme-fg-muted)]",children:"No devices yet. Create a token, then start `remote-codex relay-supervisor` on your private machine."})]})]}),e.jsx(xr,{count:(a==null?void 0:a.sharedWithMe.length)??0,emptyText:"No sessions have been shared with this account yet.",loading:g,loadingText:"Loading shared sessions...",shares:(a==null?void 0:a.sharedWithMe)??[],title:"Shared with me",subtitle:"Sessions another relay user has shared with this account.",renderShare:I=>e.jsx(gr,{mode:"incoming",share:I,onOpen:()=>P(I)},I.id)}),e.jsx(xr,{count:(a==null?void 0:a.sharedByMe.length)??0,emptyText:"No sessions have been shared by this account yet.",loading:g,loadingText:"Loading shared sessions...",shares:(a==null?void 0:a.sharedByMe)??[],title:"Shared by me",subtitle:"Threads this relay account has shared with other users.",renderShare:I=>e.jsx(gr,{busy:h===`share:${I.id}`,expanded:v===I.id,mode:"outgoing",share:I,onOpen:()=>P(I),onEdit:()=>D(I),onRevoke:()=>void m(I),onToggleAccess:()=>{q(X=>X===I.id?null:I.id)}},I.id)})]}),_?e.jsx(qi,{busy:h===`share:${_.id}`,share:_,onClose:()=>D(null),onSave:I=>void K(_,I)}):null]})}function xr({count:t,emptyText:a,loading:s,loadingText:r,renderShare:l,shares:o,subtitle:i,title:d}){return e.jsxs("section",{className:"rounded-lg border border-[var(--theme-border)] bg-[var(--theme-panel)] p-4",children:[e.jsxs("div",{className:"mb-4 flex items-center justify-between gap-3",children:[e.jsxs("div",{children:[e.jsx("h2",{className:"text-base font-semibold text-[var(--theme-fg)]",children:d}),e.jsx("p",{className:"mt-1 text-sm text-[var(--theme-fg-muted)]",children:i})]}),e.jsx("span",{className:"rounded-full border border-[var(--theme-border)] px-2 py-0.5 text-xs text-[var(--theme-fg-muted)]",children:t})]}),s?e.jsx("p",{className:"rounded-lg border border-[var(--theme-border)] bg-[var(--theme-surface)] p-4 text-sm text-[var(--theme-fg-muted)]",children:r}):o.length?e.jsx("div",{className:"grid gap-3 md:grid-cols-2",children:o.map(f=>l(f))}):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:a})]})}function gr({busy:t=!1,expanded:a=!1,mode:s,onEdit:r,onRevoke:l,onToggleAccess:o,share:i,onOpen:d}){var S;const f=Xa(i),g=f,C=((S=i.workspaceLabel)==null?void 0:S.trim())||"Workspace unavailable",h=i.lastAccessedAt?`${i.lastAccessedByUsername??"unknown"} at ${oa(i.lastAccessedAt)}`:"Not accessed yet";return e.jsxs("article",{className:"relative rounded-lg border border-[var(--theme-border)] bg-[var(--theme-surface)] p-3",children:[e.jsxs("div",{className:"flex flex-col gap-3 sm:flex-row sm:items-center sm:justify-between",children:[e.jsxs("div",{className:"min-w-0",children:[e.jsx("p",{className:"truncate text-sm font-medium text-[var(--theme-fg)]",children:f}),e.jsxs("div",{className:"mt-1 space-y-0.5 text-xs text-[var(--theme-fg-muted)]",children:[e.jsxs("p",{className:"truncate",children:["Workspace: ",e.jsx("span",{className:"text-[var(--theme-fg-soft)]",children:C})]}),e.jsxs("p",{className:"truncate",children:["Thread: ",e.jsx("span",{className:"text-[var(--theme-fg-soft)]",children:g})]}),e.jsx("p",{className:"truncate",children:s==="incoming"?`From ${i.ownerUsername}`:`To ${i.targetUsername}`}),e.jsxs("p",{className:"truncate",children:["Device: ",i.deviceName]})]}),s==="outgoing"?e.jsxs("p",{className:"mt-1 text-xs text-[var(--theme-fg-soft)]",children:["Last access: ",h]}):null,e.jsxs("p",{className:"mt-2 flex flex-wrap gap-1.5 text-[11px] text-[var(--theme-fg-muted)]",children:[e.jsx("span",{className:"rounded-full border border-[var(--theme-border)] px-2 py-0.5",children:i.threadAccess==="read"?"View only":"Collaborator"}),e.jsx("span",{className:"rounded-full border border-[var(--theme-border)] px-2 py-0.5",children:Ki(i.workspaceAccess)})]})]}),s==="incoming"?e.jsx("button",{className:"relay-button-primary inline-flex items-center gap-2",onClick:d,type:"button",children:"Open"}):e.jsxs("div",{className:"flex flex-wrap gap-2",children:[e.jsx("button",{className:"relay-button-primary inline-flex items-center gap-2",onClick:d,type:"button",children:"Open"}),e.jsx("button",{className:"relay-button-secondary inline-flex items-center gap-2",disabled:t,onClick:r,type:"button",children:"Permissions"}),e.jsxs("button",{className:"relay-button-secondary inline-flex items-center gap-2",onClick:o,type:"button",children:["Access",e.jsx(ie.ChevronDown,{className:`h-4 w-4 transition-transform ${a?"rotate-180":""}`})]}),e.jsx("button",{className:"relay-button-secondary inline-flex items-center gap-2 text-[var(--status-danger-fg)]",disabled:t,onClick:l,type:"button",children:"Revoke"})]})]}),s==="outgoing"&&a?e.jsx("div",{className:"absolute right-3 top-[calc(100%-0.5rem)] z-20 w-[min(24rem,calc(100vw-3rem))] rounded-lg border border-[var(--theme-border)] bg-[var(--theme-panel)] p-3 shadow-xl",children:i.accessEvents.length?e.jsx("ul",{className:"space-y-2 text-xs text-[var(--theme-fg-muted)]",children:i.accessEvents.map(k=>e.jsxs("li",{className:"flex items-center justify-between gap-3",children:[e.jsx("span",{className:"font-medium text-[var(--theme-fg)]",children:k.username}),e.jsx("span",{children:oa(k.accessedAt)})]},k.id))}):e.jsx("p",{className:"text-xs text-[var(--theme-fg-muted)]",children:"This shared thread has not been accessed yet."})}):null]})}function qi({busy:t,onClose:a,onSave:s,share:r}){const[l,o]=n.useState(r.label??""),[i,d]=n.useState(r.threadAccess),[f,g]=n.useState(r.workspaceAccess),C=!r.workspaceId;function h(S){S.preventDefault(),s({label:l.trim()||null,threadAccess:i,workspaceAccess:C?"none":f})}return e.jsx("div",{className:"fixed inset-0 z-50 flex items-center justify-center bg-[color-mix(in_oklch,var(--app-bg)_82%,transparent)] px-4 py-6",children:e.jsxs("form",{className:"w-full max-w-lg rounded-lg border border-[var(--theme-border)] bg-[var(--theme-panel)] p-5 shadow-2xl",onSubmit:h,children:[e.jsxs("div",{children:[e.jsx("h2",{className:"text-base font-semibold text-[var(--theme-fg)]",children:"Shared thread permissions"}),e.jsxs("p",{className:"mt-1 text-sm text-[var(--theme-fg-muted)]",children:[r.targetUsername," can access ",Xa(r),"."]})]}),e.jsxs("div",{className:"mt-5 space-y-4",children:[e.jsxs("label",{className:"block text-sm text-[var(--theme-fg-soft)]",children:["Label",e.jsx("input",{className:"relay-input mt-2 w-full",onChange:S=>o(S.target.value),placeholder:"Optional shared thread label",value:l})]}),e.jsxs("label",{className:"block text-sm text-[var(--theme-fg-soft)]",children:["Thread access",e.jsxs("select",{className:"relay-input mt-2 w-full",onChange:S=>d(S.target.value),value:i,children:[e.jsx("option",{value:"read",children:"View only"}),e.jsx("option",{value:"control",children:"Collaborator"})]})]}),e.jsxs("label",{className:"block text-sm text-[var(--theme-fg-soft)]",children:["Workspace access",e.jsxs("select",{className:"relay-input mt-2 w-full",disabled:C,onChange:S=>g(S.target.value),value:C?"none":f,children:[e.jsx("option",{value:"none",children:"No workspace"}),e.jsx("option",{value:"read",children:"Workspace read"}),e.jsx("option",{value:"write",children:"Workspace write"})]})]}),C?e.jsx("p",{className:"rounded-md border border-[var(--theme-border)] bg-[var(--theme-surface)] px-3 py-2 text-xs text-[var(--theme-fg-muted)]",children:"This share was created without a workspace scope, so only thread access can be changed."}):null]}),e.jsxs("div",{className:"mt-5 flex justify-end gap-2",children:[e.jsx("button",{className:"relay-button-secondary",disabled:t,onClick:a,type:"button",children:"Cancel"}),e.jsx("button",{className:"relay-button-primary",disabled:t,type:"submit",children:"Save permissions"})]})]})})}function zi({device:t,busy:a,copiedSetup:s,onConnect:r,onCopySetup:l,onDelete:o,setupTokenAvailable:i}){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 ${oa(t.connectedAt)}`:`Offline. Last heartbeat: ${oa(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:i?"Copy relay supervisor setup command":"Device token is not available. Create a new device token for devices created before token storage was enabled.",disabled:!i,type:"button",children:[e.jsx(ie.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:r,type:"button",children:[e.jsx(ie.Plug,{className:"h-4 w-4"}),"Connect"]}),e.jsxs("button",{className:"relay-button-secondary inline-flex items-center gap-2",disabled:a,onClick:o,type:"button",children:[e.jsx(ie.Trash2,{className:"h-4 w-4"}),"Delete"]})]})]}),i?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 Vi({result:t}){const a=vn(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(br,{label:"Device token",value:t.token}),e.jsx(br,{label:"Supervisor command",value:a})]})}function br({label:t,value:a}){async function s(){var r;try{await((r=navigator.clipboard)==null?void 0:r.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(ie.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 Gi({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 vn(t){const a=Ji();return[`REMOTE_CODEX_RELAY_SERVER_URL=${vr(a)} \\`,`REMOTE_CODEX_RELAY_AGENT_TOKEN=${vr(t)} \\`,"REMOTE_CODEX_RELAY_SUPERVISOR_PORT=45679 \\","remote-codex relay-supervisor"].join(`
|