polish sandbox workflows
This commit is contained in:
@@ -0,0 +1,35 @@
|
||||
import { NextResponse } from "next/server"
|
||||
import { backupSandboxArchive } from "@/app/lib/sandboxFiles"
|
||||
|
||||
function contentDisposition(fileName: string) {
|
||||
const fallback = fileName.replace(/[^\w.-]/g, "_") || "sandbox-backup.tar.gz"
|
||||
return `attachment; filename="${fallback}"; filename*=UTF-8''${encodeURIComponent(fileName)}`
|
||||
}
|
||||
|
||||
export async function GET(
|
||||
request: Request,
|
||||
{ params }: { params: Promise<{ sandboxId: string }> }
|
||||
) {
|
||||
try {
|
||||
const { sandboxId } = await params
|
||||
const requestUrl = new URL(request.url)
|
||||
const sourcePath = requestUrl.searchParams.get("path") || "/sandbox"
|
||||
const backup = await backupSandboxArchive(sandboxId, sourcePath)
|
||||
|
||||
return new NextResponse(new Uint8Array(backup.bytes), {
|
||||
status: 200,
|
||||
headers: {
|
||||
"cache-control": "no-store",
|
||||
"content-disposition": contentDisposition(backup.fileName),
|
||||
"content-length": String(backup.bytes.byteLength),
|
||||
"content-type": "application/gzip",
|
||||
"x-sandbox-name": backup.sandboxName,
|
||||
"x-sandbox-path": backup.sourcePath,
|
||||
"x-sandbox-backup-created-at": backup.createdAt,
|
||||
},
|
||||
})
|
||||
} catch (error) {
|
||||
const message = error instanceof Error ? error.message : "Failed to create sandbox backup"
|
||||
return NextResponse.json({ ok: false, error: message }, { status: /required|path|large|exist|directory/.test(message) ? 400 : 500 })
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,26 @@
|
||||
import { NextResponse } from "next/server"
|
||||
import { listSandboxFiles } from "@/app/lib/sandboxFiles"
|
||||
|
||||
export async function GET(
|
||||
request: Request,
|
||||
{ params }: { params: Promise<{ sandboxId: string }> }
|
||||
) {
|
||||
try {
|
||||
const { sandboxId } = await params
|
||||
const requestUrl = new URL(request.url)
|
||||
const path = requestUrl.searchParams.get("path") || "/sandbox"
|
||||
const listing = await listSandboxFiles(sandboxId, path)
|
||||
|
||||
return NextResponse.json({
|
||||
ok: true,
|
||||
listing,
|
||||
}, {
|
||||
headers: {
|
||||
"cache-control": "no-store",
|
||||
},
|
||||
})
|
||||
} catch (error) {
|
||||
const message = error instanceof Error ? error.message : "Failed to list sandbox files"
|
||||
return NextResponse.json({ ok: false, error: message }, { status: /required|path|directory|readable/.test(message) ? 400 : 500 })
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,32 @@
|
||||
import { NextResponse } from "next/server"
|
||||
import { restoreSandboxArchive } from "@/app/lib/sandboxFiles"
|
||||
|
||||
export async function POST(
|
||||
request: Request,
|
||||
{ params }: { params: Promise<{ sandboxId: string }> }
|
||||
) {
|
||||
try {
|
||||
const { sandboxId } = await params
|
||||
const form = await request.formData()
|
||||
const file = form.get("archive")
|
||||
const rawTargetPath = form.get("targetPath")
|
||||
const rawReplace = form.get("replace")
|
||||
if (!(file instanceof File)) throw new Error("archive is required")
|
||||
|
||||
const targetPath = typeof rawTargetPath === "string" && rawTargetPath.trim()
|
||||
? rawTargetPath.trim()
|
||||
: "/sandbox"
|
||||
const replace = rawReplace === "true" || rawReplace === "1"
|
||||
const payload = Buffer.from(await file.arrayBuffer())
|
||||
const restored = await restoreSandboxArchive(sandboxId, targetPath, file.name, payload, replace)
|
||||
|
||||
return NextResponse.json({
|
||||
ok: true,
|
||||
restored,
|
||||
note: `Restored ${file.name} into ${restored.targetPath} (${restored.mode}).`,
|
||||
})
|
||||
} catch (error) {
|
||||
const message = error instanceof Error ? error.message : "Failed to restore sandbox backup"
|
||||
return NextResponse.json({ ok: false, error: message }, { status: /required|path|large|unsafe|archive/.test(message) ? 400 : 500 })
|
||||
}
|
||||
}
|
||||
@@ -87,6 +87,10 @@ export default function ConfigurationPanel({ sandboxId, mode = 'existing', onCre
|
||||
const [selectedBlueprint, setSelectedBlueprint] = useState<string>('nemoclaw-blueprint')
|
||||
const [sandboxName, setSandboxName] = useState<string>('')
|
||||
const [enableTailscale, setEnableTailscale] = useState<boolean>(false)
|
||||
const [restoreFromBackup, setRestoreFromBackup] = useState<boolean>(false)
|
||||
const [restoreArchive, setRestoreArchive] = useState<File | null>(null)
|
||||
const [restorePath, setRestorePath] = useState<string>('/sandbox')
|
||||
const [restoreReplace, setRestoreReplace] = useState<boolean>(true)
|
||||
|
||||
useEffect(() => {
|
||||
if (mode === 'create') {
|
||||
@@ -129,12 +133,29 @@ export default function ConfigurationPanel({ sandboxId, mode = 'existing', onCre
|
||||
setSaving(true); setMessage("")
|
||||
if (mode === 'create') {
|
||||
if (!sandboxName.trim()) throw new Error('sandbox name is required')
|
||||
if (restoreFromBackup && !restoreArchive) throw new Error('backup archive is required when restore from backup is enabled')
|
||||
const res = await fetch('/api/sandbox/create', { method: 'POST', headers: { 'Content-Type': 'application/json' }, body: JSON.stringify({ blueprint: selectedBlueprint, sandboxName: sandboxName.trim(), enableTailscale, policy: assembledPolicy, preset: selectedPreset || null }) })
|
||||
const data = await res.json()
|
||||
if (!res.ok) throw new Error([data.error, data.verification?.summary, data.verification?.error, data.stdout, data.stderr].filter(Boolean).join('\n\n'))
|
||||
const createdSandboxId = data.verification?.details?.id || data.verification?.details?.name || data.sandboxName
|
||||
let restoreNote = ''
|
||||
if (restoreFromBackup && restoreArchive && createdSandboxId) {
|
||||
setMessage(`Sandbox '${data.sandboxName}' created. Restoring backup archive...`)
|
||||
const form = new FormData()
|
||||
form.set('archive', restoreArchive)
|
||||
form.set('targetPath', restorePath.trim() || '/sandbox')
|
||||
form.set('replace', restoreReplace ? 'true' : 'false')
|
||||
const restoreRes = await fetch(`/api/sandbox/${encodeURIComponent(createdSandboxId)}/restore`, {
|
||||
method: 'POST',
|
||||
body: form,
|
||||
})
|
||||
const restoreData = await restoreRes.json()
|
||||
if (!restoreRes.ok) throw new Error([`Sandbox '${data.sandboxName}' was created, but backup restore failed.`, restoreData.error].filter(Boolean).join('\n\n'))
|
||||
restoreNote = restoreData.note || `Restored ${restoreArchive.name} into ${restorePath.trim() || '/sandbox'}.`
|
||||
}
|
||||
setMessage([
|
||||
`Sandbox '${data.sandboxName}' created.`,
|
||||
restoreNote,
|
||||
data.verification?.summary,
|
||||
data.note,
|
||||
].filter(Boolean).join('\n\n'))
|
||||
@@ -167,7 +188,7 @@ export default function ConfigurationPanel({ sandboxId, mode = 'existing', onCre
|
||||
</div>
|
||||
)}
|
||||
{loading ? <div className="text-sm text-[var(--foreground-dim)]">Loading policy…</div> : <div className="space-y-8">
|
||||
{mode === 'create' && <section className="space-y-4 rounded-sm border border-[var(--border-subtle)] bg-[var(--background-tertiary)] p-4"><div><h5 className="text-xs uppercase tracking-wider text-[var(--foreground)]">Create Sandbox</h5><p className="text-xs text-[var(--foreground-dim)] mt-1">Choose a template and enter a sandbox name.</p></div><div className="grid grid-cols-1 md:grid-cols-2 gap-4">{blueprints.map((bp) => <button key={bp.id} type="button" onClick={() => setSelectedBlueprint(bp.id)} className={`rounded-sm border p-4 text-left ${selectedBlueprint === bp.id ? 'border-[var(--nvidia-green)] bg-[rgba(118,185,0,0.08)]' : 'border-[var(--border-subtle)] bg-[var(--background)]'}`}><div className="flex items-center justify-between gap-3"><span className="text-sm font-semibold text-[var(--foreground)] uppercase tracking-wider">{bp.label}</span><Badge tone={bp.type === 'custom' ? 'static' : 'dynamic'}>{bp.type}</Badge></div><p className="text-xs text-[var(--foreground-dim)] mt-2">{bp.description}</p></button>)}</div><div><label className="text-xs uppercase tracking-wider text-[var(--foreground-dim)]">Sandbox Name<FieldHelp text="Lowercase letters, numbers, and hyphens only." /></label><input value={sandboxName} onChange={(e) => setSandboxName(e.target.value)} placeholder={selectedBlueprint === 'nemoclaw-blueprint' ? 'my-assistant' : 'custom-sandbox'} className="mt-2 w-full rounded-sm border border-[var(--border-subtle)] bg-[var(--background)] px-3 py-2 text-xs font-mono text-[var(--foreground)]" /></div>{activeBlueprint?.supportsTailscale && <label className="flex items-center gap-3 text-sm text-[var(--foreground)] font-mono"><input type="checkbox" checked={enableTailscale} onChange={(e) => setEnableTailscale(e.target.checked)} /> Enable Tailscale</label>}{enableTailscale && <div className="rounded-sm border border-amber-500/40 bg-amber-500/10 p-3 text-sm text-amber-300">Tailscale-enabled creation requires NVIDIA_API_KEY in the dashboard process environment.</div>}</section>}
|
||||
{mode === 'create' && <section className="space-y-4 rounded-sm border border-[var(--border-subtle)] bg-[var(--background-tertiary)] p-4"><div><h5 className="text-xs uppercase tracking-wider text-[var(--foreground)]">Create Sandbox</h5><p className="text-xs text-[var(--foreground-dim)] mt-1">Choose a template and enter a sandbox name.</p></div><div className="grid grid-cols-1 md:grid-cols-2 gap-4">{blueprints.map((bp) => <button key={bp.id} type="button" onClick={() => setSelectedBlueprint(bp.id)} className={`rounded-sm border p-4 text-left ${selectedBlueprint === bp.id ? 'border-[var(--nvidia-green)] bg-[rgba(118,185,0,0.08)]' : 'border-[var(--border-subtle)] bg-[var(--background)]'}`}><div className="flex items-center justify-between gap-3"><span className="text-sm font-semibold text-[var(--foreground)] uppercase tracking-wider">{bp.label}</span><Badge tone={bp.type === 'custom' ? 'static' : 'dynamic'}>{bp.type}</Badge></div><p className="text-xs text-[var(--foreground-dim)] mt-2">{bp.description}</p></button>)}</div><div><label className="text-xs uppercase tracking-wider text-[var(--foreground-dim)]">Sandbox Name<FieldHelp text="Lowercase letters, numbers, and hyphens only." /></label><input value={sandboxName} onChange={(e) => setSandboxName(e.target.value)} placeholder={selectedBlueprint === 'nemoclaw-blueprint' ? 'my-assistant' : 'custom-sandbox'} className="mt-2 w-full rounded-sm border border-[var(--border-subtle)] bg-[var(--background)] px-3 py-2 text-xs font-mono text-[var(--foreground)]" /></div>{activeBlueprint?.supportsTailscale && <label className="flex items-center gap-3 text-sm text-[var(--foreground)] font-mono"><input type="checkbox" checked={enableTailscale} onChange={(e) => setEnableTailscale(e.target.checked)} /> Enable Tailscale</label>}{enableTailscale && <div className="rounded-sm border border-amber-500/40 bg-amber-500/10 p-3 text-sm text-amber-300">Tailscale-enabled creation requires NVIDIA_API_KEY in the dashboard process environment.</div>}<div className="rounded-sm border border-[var(--border-subtle)] bg-[var(--background)] p-4 space-y-4"><label className="flex items-start gap-3"><input type="checkbox" checked={restoreFromBackup} onChange={(e) => setRestoreFromBackup(e.target.checked)} className="mt-0.5 h-4 w-4 accent-[var(--nvidia-green)]" /><span><span className="block text-xs font-semibold uppercase tracking-wider text-[var(--foreground)]">Restore from Backup</span><span className="mt-1 block text-xs text-[var(--foreground-dim)]">After the sandbox reaches Ready, restore a .tar.gz archive into it.</span></span></label>{restoreFromBackup && <div className="grid grid-cols-1 gap-4 md:grid-cols-2"><div className="space-y-2"><label className="text-[10px] uppercase tracking-wider text-[var(--foreground-dim)]">Backup Archive</label><input type="file" accept=".tar.gz,.tgz,application/gzip,application/x-gzip" onChange={(e) => setRestoreArchive(e.target.files?.[0] || null)} className="block w-full text-xs text-[var(--foreground-dim)] file:mr-3 file:rounded-sm file:border file:border-[var(--border-subtle)] file:bg-[var(--background-tertiary)] file:px-3 file:py-2 file:text-xs file:font-mono file:uppercase file:text-[var(--foreground)]" /></div><div className="space-y-2"><label className="text-[10px] uppercase tracking-wider text-[var(--foreground-dim)]">Restore Target</label><input value={restorePath} onChange={(e) => setRestorePath(e.target.value)} placeholder="/sandbox" className="w-full rounded-sm border border-[var(--border-subtle)] bg-[var(--background-tertiary)] px-3 py-2 text-xs font-mono text-[var(--foreground)]" /></div><label className="md:col-span-2 flex items-start gap-3 rounded-sm border border-[var(--border-subtle)] bg-[var(--background-tertiary)] p-3"><input type="checkbox" checked={restoreReplace} onChange={(e) => setRestoreReplace(e.target.checked)} className="mt-0.5 h-4 w-4 accent-[var(--nvidia-green)]" /><span><span className="block text-xs font-mono uppercase tracking-wider text-[var(--foreground)]">Replace target contents</span><span className="mt-1 block text-[11px] text-[var(--foreground-dim)]">Recommended for cloning from a backup into a fresh sandbox.</span></span></label></div>}</div></section>}
|
||||
<section className="space-y-4"><div className="flex items-center justify-between gap-4 flex-wrap"><div><h5 className="text-xs uppercase tracking-wider text-[var(--foreground)]">Security Presets</h5><p className="text-xs text-[var(--foreground-dim)] mt-1">Use a canned profile for new sandboxes or switch an existing sandbox policy baseline on the fly.</p></div><div className="min-w-[260px]"><select value={selectedPreset} onChange={(e) => { const value = e.target.value as SecurityPresetId | ''; setSelectedPreset(value); if (value) applyPreset(value) }} className="w-full rounded-sm border border-[var(--border-subtle)] bg-[var(--background-tertiary)] px-3 py-2 text-xs font-mono text-[var(--foreground)]"><option value="">Select preset…</option>{SECURITY_PRESETS.map((preset) => <option key={preset.id} value={preset.id}>{preset.label}</option>)}</select></div></div>{activePreset && <div className="rounded-sm border border-[var(--border-subtle)] bg-[var(--background-tertiary)] p-4 space-y-3"><div className="flex items-center gap-3 flex-wrap"><span className="text-sm font-semibold text-[var(--foreground)] uppercase tracking-wider">{activePreset.label}</span></div><p className="text-sm text-[var(--foreground-dim)]">{activePreset.summary}</p></div>}</section>
|
||||
<section className="space-y-4"><div className="flex items-center gap-3"><h5 className="text-xs uppercase tracking-wider text-[var(--foreground)]">Filesystem Policy</h5><Badge tone="static">Static</Badge></div><label className="flex items-center gap-3 text-sm text-[var(--foreground)] font-mono"><input type="checkbox" checked={policy.filesystem_policy.include_workdir} onChange={(e) => setPolicy({ ...policy, filesystem_policy: { ...policy.filesystem_policy, include_workdir: e.target.checked } })} />Include workdir<FieldHelp text="Automatically adds the agent working directory to read_write. Static: changing this requires recreating the sandbox." /></label><div className="grid grid-cols-1 md:grid-cols-2 gap-4"><TextListEditor label="Read-only paths" tooltipText="Absolute paths the sandbox can read but not modify. Paths not listed are inaccessible." value={policy.filesystem_policy.read_only} onChange={(v) => setPolicy({ ...policy, filesystem_policy: { ...policy.filesystem_policy, read_only: v } })} placeholder="/usr\n/lib\n/etc" /><TextListEditor label="Read-write paths" tooltipText="Absolute paths the sandbox can read and write. Keep this scoped; broad paths are rejected." value={policy.filesystem_policy.read_write} onChange={(v) => setPolicy({ ...policy, filesystem_policy: { ...policy.filesystem_policy, read_write: v } })} placeholder="/sandbox\n/tmp" /></div></section>
|
||||
<section className="space-y-4"><div className="flex items-center gap-3"><h5 className="text-xs uppercase tracking-wider text-[var(--foreground)]">Network Policies</h5><Badge tone="dynamic">Dynamic</Badge></div><button onClick={addBlock} className="px-3 py-2 rounded-sm bg-[var(--background-tertiary)] text-xs font-mono uppercase tracking-wider hover:bg-[var(--background-panel)]">Add policy block</button></section>
|
||||
|
||||
@@ -0,0 +1,99 @@
|
||||
"use client"
|
||||
|
||||
const helpSections = [
|
||||
{
|
||||
title: "Daily Flow",
|
||||
items: [
|
||||
"Select a sandbox to reveal operations, file transfer, inference routes, policy, and archive tools.",
|
||||
"Use Operator Terminal after selecting a sandbox; the terminal opens in a separate tab for that sandbox session.",
|
||||
"Use Refresh Inventory when a create, restore, restart, or destroy operation is still settling.",
|
||||
],
|
||||
},
|
||||
{
|
||||
title: "Create And Clone",
|
||||
items: [
|
||||
"Create Sandbox builds a new sandbox from a blueprint or custom OpenShell sandbox template.",
|
||||
"Restore from Backup can hydrate a fresh sandbox immediately after it reaches Ready.",
|
||||
"Wizards includes a guided Clone Sandbox workflow that creates a target sandbox and restores a source backup into it.",
|
||||
"For cloning, keep Replace target contents enabled and restore into /sandbox.",
|
||||
],
|
||||
},
|
||||
{
|
||||
title: "Files",
|
||||
items: [
|
||||
"File Transfer uploads local files into /sandbox or /tmp and downloads regular files back out.",
|
||||
"The file browser lists one directory at a time; select a directory to enter it or use Up to move back.",
|
||||
"Large file transfers are limited by SANDBOX_FILE_TRANSFER_MAX_BYTES, currently defaulting to 128 MiB.",
|
||||
],
|
||||
},
|
||||
{
|
||||
title: "Backup / Restore",
|
||||
items: [
|
||||
"Backup downloads a compressed .tar.gz archive from a sandbox directory, usually /sandbox.",
|
||||
"Restore extracts a .tar.gz archive into the selected sandbox path.",
|
||||
"Replace target contents deletes existing files in the target directory before extraction; merge leaves existing files in place.",
|
||||
],
|
||||
},
|
||||
{
|
||||
title: "Policy And Network",
|
||||
items: [
|
||||
"Sandbox Policy is where pending network permission requests appear for approval or rejection.",
|
||||
"Dynamic network policy changes can apply live; static filesystem policy changes may require recreating the sandbox.",
|
||||
"Inference Routes configure model/provider routing for the selected sandbox.",
|
||||
],
|
||||
},
|
||||
{
|
||||
title: "Safety",
|
||||
items: [
|
||||
"Destroy Sandbox is permanent. Back up anything important first.",
|
||||
"Restore rejects unsafe archive paths, but only restore archives you trust.",
|
||||
"If the UI looks stale after code changes, hard refresh the browser; the dev server is on 192.168.50.81:3000.",
|
||||
],
|
||||
},
|
||||
]
|
||||
|
||||
export default function HelpPanel() {
|
||||
return (
|
||||
<div className="space-y-6">
|
||||
<section className="panel p-8">
|
||||
<p className="text-[10px] font-mono uppercase tracking-wider text-[var(--nvidia-green)]">Operator Guide</p>
|
||||
<h1 className="mt-2 text-xl font-semibold uppercase tracking-wider text-[var(--foreground)]">Help</h1>
|
||||
<p className="mt-2 max-w-3xl text-sm text-[var(--foreground-dim)]">
|
||||
Quick reference for running sandboxes, moving files, preserving work, and cloning a prepared environment.
|
||||
</p>
|
||||
</section>
|
||||
|
||||
<section className="grid grid-cols-1 gap-4 lg:grid-cols-2">
|
||||
{helpSections.map((section) => (
|
||||
<article key={section.title} className="panel p-5">
|
||||
<h2 className="text-sm font-semibold uppercase tracking-wider text-[var(--foreground)]">{section.title}</h2>
|
||||
<ul className="mt-4 space-y-3">
|
||||
{section.items.map((item) => (
|
||||
<li key={item} className="flex gap-3 text-sm leading-6 text-[var(--foreground-dim)]">
|
||||
<span className="mt-2 h-1.5 w-1.5 shrink-0 rounded-full bg-[var(--nvidia-green)]" />
|
||||
<span>{item}</span>
|
||||
</li>
|
||||
))}
|
||||
</ul>
|
||||
</article>
|
||||
))}
|
||||
</section>
|
||||
|
||||
<section className="panel p-5">
|
||||
<h2 className="text-sm font-semibold uppercase tracking-wider text-[var(--foreground)]">Common Paths</h2>
|
||||
<div className="mt-4 grid grid-cols-1 gap-3 md:grid-cols-3">
|
||||
{[
|
||||
["/sandbox", "Primary writable workspace for persisted sandbox contents."],
|
||||
["/tmp", "Scratch space for short-lived files and transfer staging."],
|
||||
["Backup .tar.gz", "Portable archive for cold storage, cloning, and redeploying."],
|
||||
].map(([label, body]) => (
|
||||
<div key={label} className="metric p-4">
|
||||
<p className="font-mono text-xs text-[var(--nvidia-green)]">{label}</p>
|
||||
<p className="mt-2 text-xs leading-5 text-[var(--foreground-dim)]">{body}</p>
|
||||
</div>
|
||||
))}
|
||||
</div>
|
||||
</section>
|
||||
</div>
|
||||
)
|
||||
}
|
||||
@@ -0,0 +1,165 @@
|
||||
"use client"
|
||||
|
||||
import { useState } from "react"
|
||||
import type { SandboxInventoryItem } from "../hooks/useSandboxInventory"
|
||||
|
||||
interface SandboxArchivePanelProps {
|
||||
sandbox: SandboxInventoryItem
|
||||
onRestoreComplete?: () => Promise<void> | void
|
||||
}
|
||||
|
||||
export default function SandboxArchivePanel({ sandbox, onRestoreComplete }: SandboxArchivePanelProps) {
|
||||
const [backupPath, setBackupPath] = useState("/sandbox")
|
||||
const [restorePath, setRestorePath] = useState("/sandbox")
|
||||
const [restoreReplace, setRestoreReplace] = useState(false)
|
||||
const [selectedArchive, setSelectedArchive] = useState<File | null>(null)
|
||||
const [busy, setBusy] = useState<"backup" | "restore" | null>(null)
|
||||
const [message, setMessage] = useState("")
|
||||
|
||||
async function backupSandbox() {
|
||||
if (!backupPath.trim() || busy) return
|
||||
try {
|
||||
setBusy("backup")
|
||||
setMessage("")
|
||||
const pathToBackup = backupPath.trim()
|
||||
const response = await fetch(`/api/sandbox/${encodeURIComponent(sandbox.id)}/backup?${new URLSearchParams({ path: pathToBackup })}`)
|
||||
if (!response.ok) {
|
||||
const data = await response.json().catch(() => ({}))
|
||||
throw new Error(data.error || "Failed to create sandbox backup")
|
||||
}
|
||||
|
||||
const blob = await response.blob()
|
||||
const contentDisposition = response.headers.get("content-disposition") || ""
|
||||
const fileName = decodeURIComponent(contentDisposition.match(/filename\*=UTF-8''([^;]+)/)?.[1] || "")
|
||||
|| contentDisposition.match(/filename="([^"]+)"/)?.[1]
|
||||
|| `${sandbox.name}-backup.tar.gz`
|
||||
const url = window.URL.createObjectURL(blob)
|
||||
const anchor = document.createElement("a")
|
||||
anchor.href = url
|
||||
anchor.download = fileName
|
||||
document.body.appendChild(anchor)
|
||||
anchor.click()
|
||||
anchor.remove()
|
||||
window.URL.revokeObjectURL(url)
|
||||
setMessage(`Created backup for ${pathToBackup}: ${fileName}.`)
|
||||
} catch (error) {
|
||||
setMessage(error instanceof Error ? error.message : "Failed to create sandbox backup")
|
||||
} finally {
|
||||
setBusy(null)
|
||||
}
|
||||
}
|
||||
|
||||
async function restoreSandbox() {
|
||||
if (!selectedArchive || !restorePath.trim() || busy) return
|
||||
try {
|
||||
setBusy("restore")
|
||||
setMessage("")
|
||||
const form = new FormData()
|
||||
form.set("archive", selectedArchive)
|
||||
form.set("targetPath", restorePath.trim())
|
||||
form.set("replace", restoreReplace ? "true" : "false")
|
||||
const response = await fetch(`/api/sandbox/${encodeURIComponent(sandbox.id)}/restore`, {
|
||||
method: "POST",
|
||||
body: form,
|
||||
})
|
||||
const data = await response.json()
|
||||
if (!response.ok) throw new Error(data.error || "Failed to restore sandbox backup")
|
||||
setMessage(data.note || `Restored ${selectedArchive.name} into ${restorePath.trim()}.`)
|
||||
await onRestoreComplete?.()
|
||||
} catch (error) {
|
||||
setMessage(error instanceof Error ? error.message : "Failed to restore sandbox backup")
|
||||
} finally {
|
||||
setBusy(null)
|
||||
}
|
||||
}
|
||||
|
||||
return (
|
||||
<div className="space-y-4">
|
||||
<div className="flex items-start justify-between gap-4 max-lg:flex-col">
|
||||
<div>
|
||||
<h5 className="text-xs font-semibold uppercase tracking-wider text-[var(--foreground)]">Backup / Restore</h5>
|
||||
<p className="mt-1 text-xs text-[var(--foreground-dim)]">
|
||||
Export sandbox contents as a compressed archive, or restore an archive into this sandbox.
|
||||
</p>
|
||||
</div>
|
||||
<span className="status-chip border border-[var(--border-subtle)] bg-[var(--background)] px-2.5 py-1 text-[var(--foreground-dim)]">
|
||||
tar.gz
|
||||
</span>
|
||||
</div>
|
||||
|
||||
<div className="grid grid-cols-1 gap-4 lg:grid-cols-2">
|
||||
<div className="rounded-sm border border-[var(--border-subtle)] bg-[var(--background)] p-4 space-y-3">
|
||||
<div>
|
||||
<h6 className="text-[11px] font-semibold uppercase tracking-wider text-[var(--foreground)]">Backup</h6>
|
||||
<p className="mt-1 text-xs text-[var(--foreground-dim)]">Archive a directory for cold storage or cloning.</p>
|
||||
</div>
|
||||
<label className="block space-y-2">
|
||||
<span className="text-[10px] uppercase tracking-wider text-[var(--foreground-dim)]">Source Directory</span>
|
||||
<input
|
||||
value={backupPath}
|
||||
onChange={(event) => setBackupPath(event.target.value)}
|
||||
placeholder="/sandbox"
|
||||
className="w-full rounded-sm border border-[var(--border-subtle)] bg-[var(--background-tertiary)] px-3 py-2 text-xs font-mono text-[var(--foreground)] focus:outline-none focus:border-[var(--nvidia-green)]"
|
||||
/>
|
||||
</label>
|
||||
<button
|
||||
type="button"
|
||||
onClick={backupSandbox}
|
||||
disabled={!backupPath.trim() || busy !== null}
|
||||
className="rounded-sm bg-[var(--nvidia-green)] px-4 py-2 text-xs font-mono uppercase tracking-wider text-black disabled:opacity-50"
|
||||
>
|
||||
{busy === "backup" ? "Creating Backup..." : "Download Backup"}
|
||||
</button>
|
||||
</div>
|
||||
|
||||
<div className="rounded-sm border border-[var(--border-subtle)] bg-[var(--background)] p-4 space-y-3">
|
||||
<div>
|
||||
<h6 className="text-[11px] font-semibold uppercase tracking-wider text-[var(--foreground)]">Restore</h6>
|
||||
<p className="mt-1 text-xs text-[var(--foreground-dim)]">Merge into the target directory, or replace it first.</p>
|
||||
</div>
|
||||
<input
|
||||
type="file"
|
||||
accept=".tar.gz,.tgz,application/gzip,application/x-gzip"
|
||||
onChange={(event) => setSelectedArchive(event.target.files?.[0] || null)}
|
||||
className="block w-full text-xs text-[var(--foreground-dim)] file:mr-3 file:rounded-sm file:border file:border-[var(--border-subtle)] file:bg-[var(--background-tertiary)] file:px-3 file:py-2 file:text-xs file:font-mono file:uppercase file:text-[var(--foreground)]"
|
||||
/>
|
||||
<label className="block space-y-2">
|
||||
<span className="text-[10px] uppercase tracking-wider text-[var(--foreground-dim)]">Target Directory</span>
|
||||
<input
|
||||
value={restorePath}
|
||||
onChange={(event) => setRestorePath(event.target.value)}
|
||||
placeholder="/sandbox"
|
||||
className="w-full rounded-sm border border-[var(--border-subtle)] bg-[var(--background-tertiary)] px-3 py-2 text-xs font-mono text-[var(--foreground)] focus:outline-none focus:border-[var(--nvidia-green)]"
|
||||
/>
|
||||
</label>
|
||||
<label className="flex items-start gap-3 rounded-sm border border-[var(--border-subtle)] bg-[var(--background-tertiary)] p-3">
|
||||
<input
|
||||
type="checkbox"
|
||||
checked={restoreReplace}
|
||||
onChange={(event) => setRestoreReplace(event.target.checked)}
|
||||
className="mt-0.5 h-4 w-4 accent-[var(--nvidia-green)]"
|
||||
/>
|
||||
<span>
|
||||
<span className="block text-xs font-mono uppercase tracking-wider text-[var(--foreground)]">Replace target contents</span>
|
||||
<span className="mt-1 block text-[11px] text-[var(--foreground-dim)]">Deletes existing files in the target directory before extracting.</span>
|
||||
</span>
|
||||
</label>
|
||||
<button
|
||||
type="button"
|
||||
onClick={restoreSandbox}
|
||||
disabled={!selectedArchive || !restorePath.trim() || busy !== null}
|
||||
className="action-button px-4 py-2"
|
||||
>
|
||||
{busy === "restore" ? "Restoring..." : "Restore Archive"}
|
||||
</button>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
{message && (
|
||||
<div className="rounded-sm border border-[var(--border-subtle)] bg-[var(--background)] p-3 text-xs text-[var(--foreground-dim)] whitespace-pre-wrap">
|
||||
{message}
|
||||
</div>
|
||||
)}
|
||||
</div>
|
||||
)
|
||||
}
|
||||
@@ -1,8 +1,42 @@
|
||||
"use client"
|
||||
|
||||
import { useMemo, useState } from "react"
|
||||
import { useEffect, useMemo, useState } from "react"
|
||||
import type { SandboxInventoryItem } from "../hooks/useSandboxInventory"
|
||||
|
||||
type SandboxFileEntry = {
|
||||
name: string
|
||||
path: string
|
||||
type: "file" | "directory" | "symlink" | "other"
|
||||
size: number | null
|
||||
modifiedAt: string | null
|
||||
}
|
||||
|
||||
type SandboxFileListing = {
|
||||
path: string
|
||||
entries: SandboxFileEntry[]
|
||||
truncated: boolean
|
||||
}
|
||||
|
||||
function formatBytes(bytes: number | null) {
|
||||
if (bytes === null) return "-"
|
||||
if (bytes < 1024) return `${bytes} B`
|
||||
const units = ["KiB", "MiB", "GiB"]
|
||||
let value = bytes / 1024
|
||||
let unitIndex = 0
|
||||
while (value >= 1024 && unitIndex < units.length - 1) {
|
||||
value /= 1024
|
||||
unitIndex += 1
|
||||
}
|
||||
return `${value.toFixed(value >= 10 ? 0 : 1)} ${units[unitIndex]}`
|
||||
}
|
||||
|
||||
function parentPath(currentPath: string) {
|
||||
const trimmed = currentPath.replace(/\/+$/, "")
|
||||
if (trimmed === "/sandbox" || trimmed === "/tmp") return trimmed
|
||||
const parent = trimmed.split("/").slice(0, -1).join("/") || "/sandbox"
|
||||
return parent === "" ? "/sandbox" : parent
|
||||
}
|
||||
|
||||
export default function SandboxFilesPanel({
|
||||
sandbox,
|
||||
embedded = false,
|
||||
@@ -16,6 +50,9 @@ export default function SandboxFilesPanel({
|
||||
const [uploadPath, setUploadPath] = useState("/sandbox/")
|
||||
const [downloadPath, setDownloadPath] = useState("/sandbox/")
|
||||
const [busy, setBusy] = useState<"upload" | "download" | null>(null)
|
||||
const [listPath, setListPath] = useState("/sandbox")
|
||||
const [listing, setListing] = useState<SandboxFileListing | null>(null)
|
||||
const [listingBusy, setListingBusy] = useState(false)
|
||||
const [message, setMessage] = useState("")
|
||||
|
||||
const suggestedUploadPath = useMemo(() => {
|
||||
@@ -23,6 +60,44 @@ export default function SandboxFilesPanel({
|
||||
return uploadPath.endsWith("/") ? `${uploadPath}${selectedFile.name}` : uploadPath
|
||||
}, [selectedFile, uploadPath])
|
||||
|
||||
const sortedEntries = useMemo(() => {
|
||||
return [...(listing?.entries || [])].sort((left, right) => {
|
||||
if (left.type === "directory" && right.type !== "directory") return -1
|
||||
if (left.type !== "directory" && right.type === "directory") return 1
|
||||
return left.name.localeCompare(right.name)
|
||||
})
|
||||
}, [listing])
|
||||
|
||||
async function loadFileList(nextPath = listPath) {
|
||||
if (listingBusy) return
|
||||
try {
|
||||
setListingBusy(true)
|
||||
setMessage("")
|
||||
const response = await fetch(`/api/sandbox/${encodeURIComponent(sandbox.id)}/files/list?${new URLSearchParams({ path: nextPath.trim() || "/sandbox" })}`, {
|
||||
cache: "no-store",
|
||||
})
|
||||
const data = await response.json()
|
||||
if (!response.ok) throw new Error(data.error || "Failed to list sandbox files")
|
||||
setListing(data.listing)
|
||||
setListPath(data.listing.path)
|
||||
} catch (error) {
|
||||
setMessage(error instanceof Error ? error.message : "Failed to list sandbox files")
|
||||
} finally {
|
||||
setListingBusy(false)
|
||||
}
|
||||
}
|
||||
|
||||
useEffect(() => {
|
||||
setListPath("/sandbox")
|
||||
setDownloadPath("/sandbox/")
|
||||
setListing(null)
|
||||
}, [sandbox.id])
|
||||
|
||||
useEffect(() => {
|
||||
loadFileList("/sandbox")
|
||||
// eslint-disable-next-line react-hooks/exhaustive-deps
|
||||
}, [sandbox.id])
|
||||
|
||||
async function uploadFile() {
|
||||
if (!selectedFile || busy) return
|
||||
try {
|
||||
@@ -39,6 +114,7 @@ export default function SandboxFilesPanel({
|
||||
if (!response.ok) throw new Error(data.error || "Failed to upload file")
|
||||
setMessage(data.note || `Uploaded to ${data.uploaded?.path || suggestedUploadPath}.`)
|
||||
setDownloadPath(data.uploaded?.path || suggestedUploadPath)
|
||||
await loadFileList(listPath)
|
||||
} catch (error) {
|
||||
setMessage(error instanceof Error ? error.message : "Failed to upload file")
|
||||
} finally {
|
||||
@@ -46,12 +122,13 @@ export default function SandboxFilesPanel({
|
||||
}
|
||||
}
|
||||
|
||||
async function downloadFile() {
|
||||
if (!downloadPath.trim() || busy) return
|
||||
async function downloadFile(pathOverride?: string) {
|
||||
const pathToDownload = (pathOverride || downloadPath).trim()
|
||||
if (!pathToDownload || busy) return
|
||||
try {
|
||||
setBusy("download")
|
||||
setMessage("")
|
||||
const response = await fetch(`/api/sandbox/${encodeURIComponent(sandbox.id)}/files/download?${new URLSearchParams({ path: downloadPath.trim() })}`)
|
||||
const response = await fetch(`/api/sandbox/${encodeURIComponent(sandbox.id)}/files/download?${new URLSearchParams({ path: pathToDownload })}`)
|
||||
if (!response.ok) {
|
||||
const data = await response.json().catch(() => ({}))
|
||||
throw new Error(data.error || "Failed to download file")
|
||||
@@ -61,7 +138,7 @@ export default function SandboxFilesPanel({
|
||||
const contentDisposition = response.headers.get("content-disposition") || ""
|
||||
const fileName = decodeURIComponent(contentDisposition.match(/filename\*=UTF-8''([^;]+)/)?.[1] || "")
|
||||
|| contentDisposition.match(/filename="([^"]+)"/)?.[1]
|
||||
|| downloadPath.split("/").filter(Boolean).pop()
|
||||
|| pathToDownload.split("/").filter(Boolean).pop()
|
||||
|| "download.bin"
|
||||
const url = window.URL.createObjectURL(blob)
|
||||
const anchor = document.createElement("a")
|
||||
@@ -71,7 +148,7 @@ export default function SandboxFilesPanel({
|
||||
anchor.click()
|
||||
anchor.remove()
|
||||
window.URL.revokeObjectURL(url)
|
||||
setMessage(`Downloaded ${downloadPath.trim()}.`)
|
||||
setMessage(`Downloaded ${pathToDownload}.`)
|
||||
} catch (error) {
|
||||
setMessage(error instanceof Error ? error.message : "Failed to download file")
|
||||
} finally {
|
||||
@@ -79,6 +156,15 @@ export default function SandboxFilesPanel({
|
||||
}
|
||||
}
|
||||
|
||||
const openEntry = (entry: SandboxFileEntry) => {
|
||||
if (entry.type === "directory") {
|
||||
setListPath(entry.path)
|
||||
loadFileList(entry.path)
|
||||
return
|
||||
}
|
||||
setDownloadPath(entry.path)
|
||||
}
|
||||
|
||||
return (
|
||||
<div className={embedded ? "" : "panel p-6"}>
|
||||
{showHeader && (
|
||||
@@ -94,7 +180,7 @@ export default function SandboxFilesPanel({
|
||||
</div>
|
||||
)}
|
||||
|
||||
<div className={`${showHeader ? "mt-5" : ""} grid grid-cols-1 lg:grid-cols-2 gap-5`}>
|
||||
<div className={`${showHeader ? "mt-5" : ""} grid grid-cols-1 xl:grid-cols-[minmax(0,0.9fr)_minmax(0,1.2fr)] gap-5`}>
|
||||
<section className="rounded-sm border border-[var(--border-subtle)] bg-[var(--background-tertiary)] p-4 space-y-4">
|
||||
<div>
|
||||
<h5 className="text-xs font-semibold uppercase tracking-wider text-[var(--foreground)]">Upload</h5>
|
||||
@@ -120,7 +206,7 @@ export default function SandboxFilesPanel({
|
||||
<button
|
||||
onClick={uploadFile}
|
||||
disabled={!selectedFile || busy !== null}
|
||||
className="px-4 py-2 rounded-sm bg-[var(--nvidia-green)] text-white text-xs font-mono uppercase tracking-wider disabled:opacity-50"
|
||||
className="rounded-sm bg-[var(--nvidia-green)] px-4 py-2 text-xs font-mono uppercase tracking-wider text-black disabled:opacity-50"
|
||||
>
|
||||
{busy === "upload" ? "Uploading..." : "Upload File"}
|
||||
</button>
|
||||
@@ -129,8 +215,92 @@ export default function SandboxFilesPanel({
|
||||
<section className="rounded-sm border border-[var(--border-subtle)] bg-[var(--background-tertiary)] p-4 space-y-4">
|
||||
<div>
|
||||
<h5 className="text-xs font-semibold uppercase tracking-wider text-[var(--foreground)]">Download</h5>
|
||||
<p className="mt-1 text-xs text-[var(--foreground-dim)]">Enter a regular file path under /sandbox or /tmp.</p>
|
||||
<p className="mt-1 text-xs text-[var(--foreground-dim)]">Browse sandbox files or enter a regular file path under /sandbox or /tmp.</p>
|
||||
</div>
|
||||
<div className="grid grid-cols-1 gap-2 md:grid-cols-[1fr_auto_auto]">
|
||||
<input
|
||||
value={listPath}
|
||||
onChange={(event) => setListPath(event.target.value)}
|
||||
placeholder="/sandbox"
|
||||
className="w-full rounded-sm border border-[var(--border-subtle)] bg-[var(--background)] px-3 py-2 text-xs font-mono text-[var(--foreground)] focus:outline-none focus:border-[var(--nvidia-green)]"
|
||||
/>
|
||||
<button
|
||||
type="button"
|
||||
onClick={() => loadFileList(listPath)}
|
||||
disabled={listingBusy}
|
||||
className="action-button px-3 py-2"
|
||||
>
|
||||
{listingBusy ? "Loading..." : "List"}
|
||||
</button>
|
||||
<button
|
||||
type="button"
|
||||
onClick={() => loadFileList(parentPath(listPath))}
|
||||
disabled={listingBusy || listPath === "/sandbox" || listPath === "/tmp"}
|
||||
className="action-button px-3 py-2"
|
||||
>
|
||||
Up
|
||||
</button>
|
||||
</div>
|
||||
<div className="overflow-hidden rounded-sm border border-[var(--border-subtle)] bg-[var(--background)]">
|
||||
<div className="grid grid-cols-[1fr_84px_116px_76px] gap-3 border-b border-[var(--border-subtle)] px-3 py-2 text-[10px] uppercase tracking-wider text-[var(--foreground-dim)] max-md:grid-cols-[1fr_72px]">
|
||||
<span>Name</span>
|
||||
<span className="max-md:hidden">Size</span>
|
||||
<span className="max-md:hidden">Modified</span>
|
||||
<span className="text-right">Action</span>
|
||||
</div>
|
||||
<div className="max-h-72 overflow-auto">
|
||||
{listingBusy ? (
|
||||
<div className="px-3 py-8 text-center text-xs font-mono uppercase tracking-wider text-[var(--foreground-dim)]">
|
||||
Reading sandbox directory...
|
||||
</div>
|
||||
) : sortedEntries.length === 0 ? (
|
||||
<div className="px-3 py-8 text-center text-xs text-[var(--foreground-dim)]">
|
||||
{listing ? "No files found in this directory." : "File list has not loaded yet."}
|
||||
</div>
|
||||
) : (
|
||||
sortedEntries.map((entry) => (
|
||||
<div
|
||||
key={entry.path}
|
||||
className="grid grid-cols-[1fr_84px_116px_76px] items-center gap-3 border-b border-[var(--border-subtle)] px-3 py-2 last:border-b-0 hover:bg-[var(--surface-hover)] max-md:grid-cols-[1fr_72px]"
|
||||
>
|
||||
<button
|
||||
type="button"
|
||||
onClick={() => openEntry(entry)}
|
||||
className="min-w-0 text-left"
|
||||
title={entry.path}
|
||||
>
|
||||
<span className="flex min-w-0 items-center gap-2">
|
||||
<span className={`h-2 w-2 shrink-0 rounded-full ${entry.type === "directory" ? "bg-[var(--nvidia-green)]" : "bg-[var(--foreground-dim)]"}`} />
|
||||
<span className="truncate text-xs font-mono text-[var(--foreground)]">{entry.name}</span>
|
||||
</span>
|
||||
</button>
|
||||
<span className="text-xs font-mono text-[var(--foreground-dim)] max-md:hidden">{entry.type === "directory" ? "dir" : formatBytes(entry.size)}</span>
|
||||
<span className="text-xs font-mono text-[var(--foreground-dim)] max-md:hidden">
|
||||
{entry.modifiedAt ? new Date(entry.modifiedAt).toLocaleDateString() : "-"}
|
||||
</span>
|
||||
<button
|
||||
type="button"
|
||||
onClick={() => {
|
||||
setDownloadPath(entry.path)
|
||||
if (entry.type !== "directory") {
|
||||
downloadFile(entry.path)
|
||||
}
|
||||
}}
|
||||
disabled={entry.type === "directory" || busy !== null}
|
||||
className="action-button px-2 py-1 text-right disabled:opacity-30"
|
||||
>
|
||||
Get
|
||||
</button>
|
||||
</div>
|
||||
))
|
||||
)}
|
||||
</div>
|
||||
</div>
|
||||
{listing?.truncated && (
|
||||
<p className="text-[11px] text-[var(--foreground-dim)]">
|
||||
Showing the first 200 entries. Narrow the path to see more.
|
||||
</p>
|
||||
)}
|
||||
<div className="space-y-2">
|
||||
<label className="text-[10px] uppercase tracking-wider text-[var(--foreground-dim)]">Source Path</label>
|
||||
<input
|
||||
@@ -141,9 +311,9 @@ export default function SandboxFilesPanel({
|
||||
/>
|
||||
</div>
|
||||
<button
|
||||
onClick={downloadFile}
|
||||
onClick={() => downloadFile()}
|
||||
disabled={!downloadPath.trim() || busy !== null}
|
||||
className="px-4 py-2 rounded-sm bg-[var(--background)] text-[var(--foreground)] text-xs font-mono uppercase tracking-wider hover:border-[var(--nvidia-green)] border border-[var(--border-subtle)] disabled:opacity-50"
|
||||
className="action-button px-4 py-2"
|
||||
>
|
||||
{busy === "download" ? "Downloading..." : "Download File"}
|
||||
</button>
|
||||
|
||||
@@ -2,6 +2,7 @@
|
||||
import { useEffect, useState } from 'react'
|
||||
import type { ReactNode } from 'react'
|
||||
import ConfigurationPanel from './ConfigurationPanel'
|
||||
import SandboxArchivePanel from './SandboxArchivePanel'
|
||||
import SandboxFilesPanel from './SandboxFilesPanel'
|
||||
import SandboxInferencePanel from './SandboxInferencePanel'
|
||||
import type { NemoClawSummary, SandboxInventoryItem } from '../hooks/useSandboxInventory'
|
||||
@@ -26,7 +27,7 @@ interface SandboxListProps {
|
||||
onInventoryRefresh: () => Promise<SandboxInventoryItem[]>
|
||||
}
|
||||
|
||||
type DrawerKey = 'operations' | 'files' | 'inference' | 'policy'
|
||||
type DrawerKey = 'operations' | 'files' | 'inference' | 'policy' | 'archive'
|
||||
type NetworkRuleRequest = {
|
||||
chunkId: string
|
||||
status: string
|
||||
@@ -121,6 +122,7 @@ export default function SandboxList({
|
||||
files: false,
|
||||
inference: false,
|
||||
policy: false,
|
||||
archive: false,
|
||||
})
|
||||
const [telemetry, setTelemetry] = useState<TelemetryData>({
|
||||
cpu: 0, memory: 0, disk: 0, timestamp: new Date().toISOString()
|
||||
@@ -232,29 +234,34 @@ export default function SandboxList({
|
||||
</div>
|
||||
) : (
|
||||
<>
|
||||
<div className="flex items-center justify-between">
|
||||
<h3 className="text-sm font-semibold text-[var(--foreground)] uppercase tracking-wider">
|
||||
{isDestroyMode ? 'SELECT SANDBOX TO DESTROY' : 'ACTIVE SANDBOXES'}
|
||||
</h3>
|
||||
<span className="text-[10px] text-[var(--foreground-dim)] font-mono">
|
||||
REFRESH: 10s
|
||||
<div className="flex items-end justify-between gap-4">
|
||||
<div>
|
||||
<p className="text-[10px] font-mono uppercase tracking-wider text-[var(--nvidia-green)]">
|
||||
Inventory
|
||||
</p>
|
||||
<h3 className="mt-1 text-sm font-semibold text-[var(--foreground)] uppercase tracking-wider">
|
||||
{isDestroyMode ? 'SELECT SANDBOX TO DESTROY' : 'ACTIVE SANDBOXES'}
|
||||
</h3>
|
||||
</div>
|
||||
<span className="status-chip border border-[var(--border-subtle)] bg-[var(--background-tertiary)] px-2.5 py-1 text-[var(--foreground-dim)]">
|
||||
REFRESH 10s
|
||||
</span>
|
||||
</div>
|
||||
|
||||
<div className="grid grid-cols-1 md:grid-cols-2 lg:grid-cols-3 gap-4">
|
||||
<div className="grid grid-cols-1 gap-4 md:grid-cols-2 xl:grid-cols-3">
|
||||
{sandboxes.map((sandbox) => (
|
||||
<div
|
||||
key={sandbox.id}
|
||||
className={`p-4 rounded-sm text-left transition-all border-2 ${
|
||||
className={`group overflow-hidden rounded border text-left transition-all ${
|
||||
isDestroyMode
|
||||
? 'border-[var(--status-stopped)] hover:bg-[var(--status-stopped-bg)]'
|
||||
? 'border-[var(--status-stopped)] bg-[var(--status-stopped-bg)] hover:shadow-[0_18px_60px_rgba(220,38,38,0.16)]'
|
||||
: selectedSandboxId === sandbox.id
|
||||
? 'bg-[var(--nvidia-green)] text-white border-[var(--nvidia-green)]'
|
||||
: 'panel hover:border-[var(--nvidia-green)]'
|
||||
? 'border-[var(--nvidia-green)] bg-[var(--surface-hover)] shadow-[var(--shadow-glow)]'
|
||||
: 'border-[var(--border-subtle)] bg-[var(--surface-raised)] shadow-[var(--shadow-soft)] hover:border-[var(--nvidia-green)] hover:bg-[var(--surface-hover)]'
|
||||
}`}
|
||||
>
|
||||
<button type="button" onClick={() => onSandboxSelect(sandbox.id)} className="w-full text-left">
|
||||
<div className="flex items-center justify-between mb-3">
|
||||
<button type="button" onClick={() => onSandboxSelect(sandbox.id)} className="w-full p-4 text-left">
|
||||
<div className="flex items-center justify-between gap-3 mb-3">
|
||||
<div className="flex items-center gap-2 min-w-0">
|
||||
{(() => {
|
||||
const feed = permissionFeeds[sandbox.id]
|
||||
@@ -270,22 +277,22 @@ export default function SandboxList({
|
||||
)
|
||||
})()}
|
||||
<span className={`text-sm font-mono font-semibold truncate ${
|
||||
isDestroyMode ? 'text-[var(--status-stopped)]' : ''
|
||||
isDestroyMode ? 'text-[var(--status-stopped)]' : 'text-[var(--foreground)]'
|
||||
}`}>
|
||||
{sandbox.name}
|
||||
</span>
|
||||
{sandbox.isDefault ? (
|
||||
<span className={`rounded-sm border px-1.5 py-0.5 text-[9px] uppercase tracking-wider ${selectedSandboxId === sandbox.id && !isDestroyMode ? 'border-black/30 text-black' : 'border-[var(--border-subtle)] text-[var(--foreground-dim)]'}`}>default</span>
|
||||
<span className="rounded-full border border-[var(--border-subtle)] px-1.5 py-0.5 text-[9px] uppercase tracking-wider text-[var(--foreground-dim)]">default</span>
|
||||
) : null}
|
||||
</div>
|
||||
<div className={`px-2 py-0.5 rounded-sm text-[10px] font-mono uppercase ${
|
||||
<div className={`status-chip shrink-0 px-2.5 py-1 ${
|
||||
isDestroyMode
|
||||
? 'bg-[var(--status-stopped)] text-white animate-pulse'
|
||||
: sandbox.status === 'running' && sandbox.ready
|
||||
? 'bg-[var(--status-running)] text-white'
|
||||
: sandbox.status === 'stopped'
|
||||
? 'bg-[var(--status-stopped)] text-white'
|
||||
: sandbox.status === 'error'
|
||||
? 'bg-[var(--status-running-bg)] text-[var(--status-running)] border border-[var(--status-running)]/40'
|
||||
: sandbox.status === 'stopped'
|
||||
? 'bg-[var(--status-stopped)] text-white'
|
||||
: sandbox.status === 'error'
|
||||
? 'bg-red-500 text-white'
|
||||
: 'bg-[var(--status-pending)] text-white'
|
||||
}`}>
|
||||
@@ -301,13 +308,13 @@ export default function SandboxList({
|
||||
['Sandbox ID', sandbox.id, '140px'],
|
||||
] as Array<[string, string, string]>).map(([label, value, width]) => (
|
||||
<div key={label} className="flex items-center justify-between gap-3">
|
||||
<span className={`text-[10px] uppercase ${selectedSandboxId === sandbox.id && !isDestroyMode ? 'text-black' : 'text-[var(--foreground-dim)]'}`}>{label}</span>
|
||||
<span className={`text-xs font-mono truncate ${selectedSandboxId === sandbox.id && !isDestroyMode ? 'text-black' : ''}`} style={{ maxWidth: width }} title={value}>{value}</span>
|
||||
<span className="text-[10px] uppercase text-[var(--foreground-dim)]">{label}</span>
|
||||
<span className="text-xs font-mono truncate text-[var(--foreground)]" style={{ maxWidth: width }} title={value}>{value}</span>
|
||||
</div>
|
||||
))}
|
||||
</div>
|
||||
</button>
|
||||
<div className="mt-3 pt-3 border-t border-black/10">
|
||||
<div className="border-t border-[var(--border-subtle)] p-3">
|
||||
<select
|
||||
value=""
|
||||
disabled={grantingSandboxId === sandbox.id}
|
||||
@@ -317,7 +324,7 @@ export default function SandboxList({
|
||||
event.currentTarget.value = ''
|
||||
resolvePermissionRequest(sandbox, 'approve', value)
|
||||
}}
|
||||
className={`w-full rounded-sm border px-3 py-2 text-xs font-mono uppercase tracking-wider focus:outline-none ${selectedSandboxId === sandbox.id && !isDestroyMode ? 'border-black/30 bg-white/30 text-black' : 'border-[var(--border-subtle)] bg-[var(--background-tertiary)] text-[var(--foreground)]'}`}
|
||||
className="w-full rounded border border-[var(--border-subtle)] bg-[var(--background-tertiary)] px-3 py-2 text-xs font-mono uppercase tracking-wider text-[var(--foreground)] focus:outline-none focus:ring-1 focus:ring-[var(--nvidia-green)]"
|
||||
>
|
||||
<option value="">
|
||||
{grantingSandboxId === sandbox.id
|
||||
@@ -373,14 +380,14 @@ export default function SandboxList({
|
||||
setDashboardMessage('Failed to resolve OpenClaw Dashboard endpoint.')
|
||||
}
|
||||
}}
|
||||
className="px-3 py-2 rounded-sm bg-[var(--background-tertiary)] text-[var(--foreground)] text-xs font-mono uppercase tracking-wider hover:border-[var(--nvidia-green)] border border-[var(--border-subtle)]"
|
||||
className="action-button px-3 py-2"
|
||||
>
|
||||
Start OpenClaw Gateway Dashboard
|
||||
</button>
|
||||
<button
|
||||
onClick={restartSandbox}
|
||||
disabled={restartInProgress}
|
||||
className="px-3 py-2 rounded-sm bg-[var(--background-tertiary)] text-[var(--foreground)] text-xs font-mono uppercase tracking-wider hover:border-[var(--nvidia-green)] border border-[var(--border-subtle)] disabled:opacity-50"
|
||||
className="action-button px-3 py-2"
|
||||
>
|
||||
{restartInProgress ? 'Restarting Sandbox...' : 'Restart Sandbox'}
|
||||
</button>
|
||||
@@ -388,11 +395,11 @@ export default function SandboxList({
|
||||
onClick={async () => {
|
||||
await onInventoryRefresh()
|
||||
}}
|
||||
className="px-3 py-2 rounded-sm bg-[var(--background-tertiary)] text-[var(--foreground)] text-xs font-mono uppercase tracking-wider hover:border-[var(--nvidia-green)] border border-[var(--border-subtle)]"
|
||||
className="action-button px-3 py-2"
|
||||
>
|
||||
Refresh Inventory
|
||||
</button>
|
||||
<span className="text-[10px] text-[var(--foreground-dim)] font-mono">
|
||||
<span className="status-chip border border-[var(--status-running)]/40 bg-[var(--status-running-bg)] px-2.5 py-1 text-[var(--status-running)]">
|
||||
LIVE
|
||||
</span>
|
||||
</div>
|
||||
@@ -504,6 +511,15 @@ export default function SandboxList({
|
||||
<ConfigurationPanel sandboxId={selectedSandbox.id} mode="existing" embedded showHeader={false} />
|
||||
</div>
|
||||
</DrawerSection>
|
||||
|
||||
<DrawerSection
|
||||
title="Backup / Restore"
|
||||
summary="Download a compressed archive or restore one into this sandbox."
|
||||
open={openDrawers.archive}
|
||||
onToggle={() => toggleDrawer('archive')}
|
||||
>
|
||||
<SandboxArchivePanel sandbox={selectedSandbox} onRestoreComplete={async () => { await onInventoryRefresh() }} />
|
||||
</DrawerSection>
|
||||
</>
|
||||
)}
|
||||
</>
|
||||
|
||||
+47
-31
@@ -3,7 +3,7 @@
|
||||
interface SidebarProps {
|
||||
sandboxesRunning: number
|
||||
sandboxesTotal: number
|
||||
activeView: 'settings' | 'sandboxes'
|
||||
activeView: 'settings' | 'sandboxes' | 'help' | 'wizards'
|
||||
isCreateMode: boolean
|
||||
isDestroyMode: boolean
|
||||
onSandboxesClick: () => void
|
||||
@@ -11,6 +11,8 @@ interface SidebarProps {
|
||||
onDestroyClick: () => void
|
||||
onTerminalClick: () => void
|
||||
onSettingsClick: () => void
|
||||
onWizardsClick: () => void
|
||||
onHelpClick: () => void
|
||||
onExitMode: () => void
|
||||
onLogout: () => void
|
||||
terminalDisabled?: boolean
|
||||
@@ -27,16 +29,26 @@ export default function Sidebar({
|
||||
onDestroyClick,
|
||||
onTerminalClick,
|
||||
onSettingsClick,
|
||||
onWizardsClick,
|
||||
onHelpClick,
|
||||
onExitMode,
|
||||
onLogout,
|
||||
terminalDisabled = false,
|
||||
}: SidebarProps) {
|
||||
const navItemClass = (active = false, danger = false) => `w-full flex items-center gap-3 px-3 py-2.5 rounded transition-colors ${
|
||||
active
|
||||
? danger
|
||||
? 'bg-[var(--status-stopped)] text-white shadow-[0_10px_28px_rgba(220,38,38,0.18)]'
|
||||
: 'bg-[var(--nvidia-green)] text-black shadow-[0_10px_28px_rgba(118,185,0,0.18)]'
|
||||
: 'hover:bg-[var(--background-tertiary)] text-[var(--foreground-dim)] hover:text-[var(--foreground)]'
|
||||
}`
|
||||
|
||||
return (
|
||||
<aside className="fixed left-0 top-0 h-screen w-64 bg-[var(--background-secondary)] border-r border-[var(--border-subtle)] flex flex-col z-20">
|
||||
<div className="p-4 border-b border-[var(--border-subtle)]">
|
||||
<aside className="fixed left-0 top-0 z-20 flex h-screen w-64 flex-col border-r border-[var(--border-subtle)] bg-[var(--background-secondary)]/95 shadow-[12px_0_40px_rgba(0,0,0,0.22)] backdrop-blur lg:w-64 max-lg:bottom-0 max-lg:top-auto max-lg:h-auto max-lg:w-full max-lg:border-r-0 max-lg:border-t max-lg:shadow-[0_-12px_40px_rgba(0,0,0,0.22)]">
|
||||
<div className="p-4 border-b border-[var(--border-subtle)] max-lg:hidden">
|
||||
<div className="flex items-center gap-3">
|
||||
<div className="w-8 h-8 bg-[var(--nvidia-green)] rounded-sm flex items-center justify-center">
|
||||
<svg className="w-5 h-5 text-white" fill="none" stroke="currentColor" viewBox="0 0 24 24">
|
||||
<div className="w-8 h-8 bg-[var(--nvidia-green)] rounded flex items-center justify-center shadow-[0_0_22px_rgba(118,185,0,0.28)]">
|
||||
<svg className="w-5 h-5 text-black" fill="none" stroke="currentColor" viewBox="0 0 24 24">
|
||||
<path strokeLinecap="square" strokeLinejoin="miter" strokeWidth={2} d="M4 7l8-4 8 4v10l-8 4-8-4V7z" />
|
||||
<path strokeLinecap="square" strokeLinejoin="miter" strokeWidth={2} d="M4 7l8 4 8-4M12 11v10" />
|
||||
</svg>
|
||||
@@ -50,14 +62,10 @@ export default function Sidebar({
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<nav className="flex-1 p-2">
|
||||
<nav className="flex-1 p-2 max-lg:grid max-lg:grid-cols-4 max-lg:gap-1 max-lg:overflow-x-auto">
|
||||
<button
|
||||
onClick={onSandboxesClick}
|
||||
className={`w-full flex items-center gap-3 px-3 py-2 rounded-sm transition-colors ${
|
||||
activeView === 'sandboxes' && !isCreateMode && !isDestroyMode
|
||||
? 'bg-[var(--nvidia-green)] text-white'
|
||||
: 'hover:bg-[var(--background-tertiary)] text-[var(--foreground-dim)]'
|
||||
}`}
|
||||
className={navItemClass(activeView === 'sandboxes' && !isCreateMode && !isDestroyMode)}
|
||||
>
|
||||
<svg className="w-4 h-4" fill="none" stroke="currentColor" viewBox="0 0 24 24">
|
||||
<path strokeLinecap="square" strokeLinejoin="miter" strokeWidth={2} d="M20 7l-8-4-8 4m16 0l-8 4m8-4v10l-8 4m0-10L4 7m8 4v10M4 7v10l8 4" />
|
||||
@@ -67,11 +75,7 @@ export default function Sidebar({
|
||||
|
||||
<button
|
||||
onClick={onCreateClick}
|
||||
className={`mt-1 w-full flex items-center gap-3 px-3 py-2 rounded-sm transition-colors ${
|
||||
isCreateMode
|
||||
? 'bg-[var(--nvidia-green)] text-white'
|
||||
: 'hover:bg-[var(--background-tertiary)] text-[var(--foreground-dim)]'
|
||||
}`}
|
||||
className={`mt-1 max-lg:mt-0 ${navItemClass(isCreateMode)}`}
|
||||
>
|
||||
<svg className="w-4 h-4" fill="none" stroke="currentColor" viewBox="0 0 24 24">
|
||||
<path strokeLinecap="square" strokeLinejoin="miter" strokeWidth={2} d="M12 4v16m8-8H4" />
|
||||
@@ -81,11 +85,7 @@ export default function Sidebar({
|
||||
|
||||
<button
|
||||
onClick={onDestroyClick}
|
||||
className={`mt-1 w-full flex items-center gap-3 px-3 py-2 rounded-sm transition-colors ${
|
||||
isDestroyMode
|
||||
? 'bg-[var(--status-stopped)] text-white'
|
||||
: 'hover:bg-[var(--background-tertiary)] text-[var(--foreground-dim)]'
|
||||
}`}
|
||||
className={`mt-1 max-lg:mt-0 ${navItemClass(isDestroyMode, true)}`}
|
||||
>
|
||||
<svg className="w-4 h-4" fill="none" stroke="currentColor" viewBox="0 0 24 24">
|
||||
<path strokeLinecap="square" strokeLinejoin="miter" strokeWidth={2} d="M19 7l-.867 12.142A2 2 0 0116.138 21H7.862a2 2 0 01-1.995-1.858L5 7m5 4v6m4-6v6M4 7h16" />
|
||||
@@ -96,7 +96,7 @@ export default function Sidebar({
|
||||
<button
|
||||
onClick={onTerminalClick}
|
||||
disabled={terminalDisabled}
|
||||
className="mt-1 w-full flex items-center gap-3 px-3 py-2 rounded-sm transition-colors hover:bg-[var(--background-tertiary)] text-[var(--foreground-dim)] disabled:opacity-40 disabled:cursor-not-allowed"
|
||||
className="mt-1 max-lg:mt-0 w-full flex items-center gap-3 px-3 py-2.5 rounded transition-colors hover:bg-[var(--background-tertiary)] text-[var(--foreground-dim)] hover:text-[var(--foreground)] disabled:opacity-40 disabled:cursor-not-allowed"
|
||||
>
|
||||
<svg className="w-4 h-4" fill="none" stroke="currentColor" viewBox="0 0 24 24">
|
||||
<path strokeLinecap="square" strokeLinejoin="miter" strokeWidth={2} d="M4 17l6-6-6-6m8 14h8" />
|
||||
@@ -107,7 +107,7 @@ export default function Sidebar({
|
||||
{(isCreateMode || isDestroyMode) && (
|
||||
<button
|
||||
onClick={onExitMode}
|
||||
className="mt-1 w-full flex items-center gap-3 px-3 py-2 rounded-sm bg-[var(--background-tertiary)] text-[var(--foreground-dim)] hover:bg-[var(--background-panel)] transition-colors"
|
||||
className="mt-1 w-full flex items-center gap-3 px-3 py-2.5 rounded bg-[var(--background-tertiary)] text-[var(--foreground-dim)] hover:bg-[var(--background-panel)] transition-colors max-lg:col-span-2"
|
||||
>
|
||||
<svg className="w-4 h-4" fill="none" stroke="currentColor" viewBox="0 0 24 24">
|
||||
<path strokeLinecap="square" strokeLinejoin="miter" strokeWidth={2} d="M6 18L18 6M6 6l12 12" />
|
||||
@@ -118,11 +118,7 @@ export default function Sidebar({
|
||||
|
||||
<button
|
||||
onClick={onSettingsClick}
|
||||
className={`mt-4 w-full flex items-center gap-3 px-3 py-2 rounded-sm transition-colors ${
|
||||
activeView === 'settings'
|
||||
? 'bg-[var(--nvidia-green)] text-white'
|
||||
: 'hover:bg-[var(--background-tertiary)] text-[var(--foreground-dim)]'
|
||||
}`}
|
||||
className={`mt-4 max-lg:mt-0 ${navItemClass(activeView === 'settings')}`}
|
||||
>
|
||||
<svg className="w-4 h-4" fill="none" stroke="currentColor" viewBox="0 0 24 24">
|
||||
<path strokeLinecap="square" strokeLinejoin="miter" strokeWidth={2} d="M12 6v6l4 2m5-2a9 9 0 11-18 0 9 9 0 0118 0z" />
|
||||
@@ -130,9 +126,29 @@ export default function Sidebar({
|
||||
<span className="text-sm">Inference Endpoints</span>
|
||||
</button>
|
||||
|
||||
<button
|
||||
onClick={onWizardsClick}
|
||||
className={`mt-1 max-lg:mt-0 ${navItemClass(activeView === 'wizards')}`}
|
||||
>
|
||||
<svg className="w-4 h-4" fill="none" stroke="currentColor" viewBox="0 0 24 24" aria-hidden="true">
|
||||
<path strokeLinecap="square" strokeLinejoin="miter" strokeWidth={2} d="M12 3l2.2 4.8L19 10l-4.8 2.2L12 17l-2.2-4.8L5 10l4.8-2.2L12 3zm6 12l.9 2.1L21 18l-2.1.9L18 21l-.9-2.1L15 18l2.1-.9L18 15z" />
|
||||
</svg>
|
||||
<span className="text-sm">Wizards</span>
|
||||
</button>
|
||||
|
||||
<button
|
||||
onClick={onHelpClick}
|
||||
className={`mt-1 max-lg:mt-0 ${navItemClass(activeView === 'help')}`}
|
||||
>
|
||||
<svg className="w-4 h-4" fill="none" stroke="currentColor" viewBox="0 0 24 24" aria-hidden="true">
|
||||
<path strokeLinecap="square" strokeLinejoin="miter" strokeWidth={2} d="M9.09 9a3 3 0 115.82 1c-.64.85-1.91 1.26-2.41 2.32V13m-.5 4h.01M12 3a9 9 0 100 18 9 9 0 000-18z" />
|
||||
</svg>
|
||||
<span className="text-sm">Help</span>
|
||||
</button>
|
||||
|
||||
<a
|
||||
href="/setup-account"
|
||||
className="mt-1 w-full flex items-center gap-3 px-3 py-2 rounded-sm transition-colors hover:bg-[var(--background-tertiary)] text-[var(--foreground-dim)]"
|
||||
className="mt-1 max-lg:mt-0 w-full flex items-center gap-3 px-3 py-2.5 rounded transition-colors hover:bg-[var(--background-tertiary)] text-[var(--foreground-dim)] hover:text-[var(--foreground)]"
|
||||
>
|
||||
<svg className="w-4 h-4" fill="none" stroke="currentColor" viewBox="0 0 24 24" aria-hidden="true">
|
||||
<path strokeLinecap="square" strokeLinejoin="miter" strokeWidth={2} d="M12 12a4 4 0 100-8 4 4 0 000 8zm-7 9a7 7 0 0114 0" />
|
||||
@@ -141,10 +157,10 @@ export default function Sidebar({
|
||||
</a>
|
||||
</nav>
|
||||
|
||||
<div className="p-2 border-t border-[var(--border-subtle)]">
|
||||
<div className="p-2 border-t border-[var(--border-subtle)] max-lg:hidden">
|
||||
<button
|
||||
onClick={onLogout}
|
||||
className="w-full flex items-center gap-3 px-3 py-2 rounded-sm transition-colors hover:bg-[var(--background-tertiary)] text-[var(--foreground-dim)]"
|
||||
className="w-full flex items-center gap-3 px-3 py-2.5 rounded transition-colors hover:bg-[var(--background-tertiary)] text-[var(--foreground-dim)] hover:text-[var(--foreground)]"
|
||||
>
|
||||
<svg className="w-4 h-4" fill="none" stroke="currentColor" viewBox="0 0 24 24" aria-hidden="true">
|
||||
<path strokeLinecap="square" strokeLinejoin="miter" strokeWidth={2} d="M15 12H3m0 0l4-4m-4 4l4 4m5-10h6v12h-6" />
|
||||
|
||||
@@ -0,0 +1,375 @@
|
||||
"use client"
|
||||
|
||||
import { useEffect, useMemo, useState } from "react"
|
||||
import type { SandboxInventoryItem } from "../hooks/useSandboxInventory"
|
||||
|
||||
type BlueprintOption = {
|
||||
id: string
|
||||
label: string
|
||||
description: string
|
||||
supportsTailscale?: boolean
|
||||
}
|
||||
|
||||
type WizardStep = "source" | "target" | "options" | "review" | "run"
|
||||
|
||||
const steps: Array<{ key: WizardStep; label: string }> = [
|
||||
{ key: "source", label: "Source" },
|
||||
{ key: "target", label: "Target" },
|
||||
{ key: "options", label: "Options" },
|
||||
{ key: "review", label: "Review" },
|
||||
{ key: "run", label: "Run" },
|
||||
]
|
||||
|
||||
function contentDispositionFileName(value: string | null, fallback: string) {
|
||||
const header = value || ""
|
||||
return decodeURIComponent(header.match(/filename\*=UTF-8''([^;]+)/)?.[1] || "")
|
||||
|| header.match(/filename="([^"]+)"/)?.[1]
|
||||
|| fallback
|
||||
}
|
||||
|
||||
function defaultCloneName(source?: SandboxInventoryItem) {
|
||||
if (!source) return ""
|
||||
return `${source.name.replace(/[^a-z0-9-]/g, "-").replace(/-+/g, "-").replace(/^-|-$/g, "")}-clone`.slice(0, 63)
|
||||
}
|
||||
|
||||
export default function WizardPanel({
|
||||
sandboxes,
|
||||
onInventoryRefresh,
|
||||
}: {
|
||||
sandboxes: SandboxInventoryItem[]
|
||||
onInventoryRefresh: () => Promise<SandboxInventoryItem[]>
|
||||
}) {
|
||||
const [activeStep, setActiveStep] = useState<WizardStep>("source")
|
||||
const [sourceSandboxId, setSourceSandboxId] = useState("")
|
||||
const [targetName, setTargetName] = useState("")
|
||||
const [blueprints, setBlueprints] = useState<BlueprintOption[]>([])
|
||||
const [selectedBlueprint, setSelectedBlueprint] = useState("custom-sandbox")
|
||||
const [enableTailscale, setEnableTailscale] = useState(false)
|
||||
const [backupPath, setBackupPath] = useState("/sandbox")
|
||||
const [restorePath, setRestorePath] = useState("/sandbox")
|
||||
const [replaceTarget, setReplaceTarget] = useState(true)
|
||||
const [running, setRunning] = useState(false)
|
||||
const [message, setMessage] = useState("")
|
||||
const [runLog, setRunLog] = useState<string[]>([])
|
||||
|
||||
const sourceSandbox = useMemo(
|
||||
() => sandboxes.find((sandbox) => sandbox.id === sourceSandboxId) || null,
|
||||
[sandboxes, sourceSandboxId],
|
||||
)
|
||||
const activeBlueprint = blueprints.find((blueprint) => blueprint.id === selectedBlueprint)
|
||||
const activeIndex = steps.findIndex((step) => step.key === activeStep)
|
||||
|
||||
useEffect(() => {
|
||||
fetch("/api/sandbox/create", { cache: "no-store" })
|
||||
.then((response) => response.json())
|
||||
.then((data) => {
|
||||
if (Array.isArray(data?.blueprints)) setBlueprints(data.blueprints)
|
||||
})
|
||||
.catch(() => {})
|
||||
}, [])
|
||||
|
||||
useEffect(() => {
|
||||
if (!sourceSandboxId && sandboxes[0]) {
|
||||
setSourceSandboxId(sandboxes[0].id)
|
||||
}
|
||||
}, [sandboxes, sourceSandboxId])
|
||||
|
||||
useEffect(() => {
|
||||
if (!targetName && sourceSandbox) {
|
||||
setTargetName(defaultCloneName(sourceSandbox))
|
||||
}
|
||||
}, [sourceSandbox, targetName])
|
||||
|
||||
const canContinue = (() => {
|
||||
if (activeStep === "source") return Boolean(sourceSandbox)
|
||||
if (activeStep === "target") return /^[a-z0-9]([a-z0-9-]*[a-z0-9])?$/.test(targetName) && targetName.length <= 63
|
||||
if (activeStep === "options") return Boolean(backupPath.trim() && restorePath.trim())
|
||||
if (activeStep === "review") return Boolean(sourceSandbox && targetName.trim())
|
||||
return false
|
||||
})()
|
||||
|
||||
const goNext = () => {
|
||||
const next = steps[activeIndex + 1]
|
||||
if (next) setActiveStep(next.key)
|
||||
}
|
||||
|
||||
const goBack = () => {
|
||||
const previous = steps[activeIndex - 1]
|
||||
if (previous) setActiveStep(previous.key)
|
||||
}
|
||||
|
||||
const appendLog = (line: string) => {
|
||||
setRunLog((current) => [...current, line])
|
||||
}
|
||||
|
||||
async function runCloneWizard() {
|
||||
if (!sourceSandbox || running) return
|
||||
try {
|
||||
setRunning(true)
|
||||
setMessage("")
|
||||
setRunLog([])
|
||||
setActiveStep("run")
|
||||
|
||||
appendLog(`Creating target sandbox ${targetName}...`)
|
||||
const createResponse = await fetch("/api/sandbox/create", {
|
||||
method: "POST",
|
||||
headers: { "Content-Type": "application/json" },
|
||||
body: JSON.stringify({
|
||||
blueprint: selectedBlueprint,
|
||||
sandboxName: targetName.trim(),
|
||||
enableTailscale,
|
||||
policy: null,
|
||||
preset: null,
|
||||
}),
|
||||
})
|
||||
const createData = await createResponse.json()
|
||||
if (!createResponse.ok) {
|
||||
throw new Error([createData.error, createData.verification?.summary, createData.verification?.error, createData.stdout, createData.stderr].filter(Boolean).join("\n\n") || "Failed to create target sandbox")
|
||||
}
|
||||
const createdSandboxId = createData.verification?.details?.id || createData.verification?.details?.name || createData.sandboxName
|
||||
appendLog(`Target sandbox ready: ${createdSandboxId}.`)
|
||||
|
||||
appendLog(`Backing up ${sourceSandbox.name}:${backupPath.trim()}...`)
|
||||
const backupResponse = await fetch(`/api/sandbox/${encodeURIComponent(sourceSandbox.id)}/backup?${new URLSearchParams({ path: backupPath.trim() })}`)
|
||||
if (!backupResponse.ok) {
|
||||
const data = await backupResponse.json().catch(() => ({}))
|
||||
throw new Error(data.error || "Failed to create source backup")
|
||||
}
|
||||
const backupBlob = await backupResponse.blob()
|
||||
const backupFileName = contentDispositionFileName(backupResponse.headers.get("content-disposition"), `${sourceSandbox.name}-backup.tar.gz`)
|
||||
appendLog(`Backup captured: ${backupFileName} (${Math.ceil(backupBlob.size / 1024)} KiB).`)
|
||||
|
||||
appendLog(`Restoring backup into ${createdSandboxId}:${restorePath.trim()}...`)
|
||||
const form = new FormData()
|
||||
form.set("archive", new File([backupBlob], backupFileName, { type: "application/gzip" }))
|
||||
form.set("targetPath", restorePath.trim())
|
||||
form.set("replace", replaceTarget ? "true" : "false")
|
||||
const restoreResponse = await fetch(`/api/sandbox/${encodeURIComponent(createdSandboxId)}/restore`, {
|
||||
method: "POST",
|
||||
body: form,
|
||||
})
|
||||
const restoreData = await restoreResponse.json()
|
||||
if (!restoreResponse.ok) throw new Error(restoreData.error || "Failed to restore backup into target sandbox")
|
||||
appendLog(restoreData.note || "Restore complete.")
|
||||
|
||||
appendLog("Refreshing inventory...")
|
||||
await onInventoryRefresh()
|
||||
setMessage(`Clone complete: ${sourceSandbox.name} -> ${targetName.trim()}.`)
|
||||
} catch (error) {
|
||||
const text = error instanceof Error ? error.message : "Clone wizard failed"
|
||||
appendLog(text)
|
||||
setMessage(text)
|
||||
} finally {
|
||||
setRunning(false)
|
||||
}
|
||||
}
|
||||
|
||||
return (
|
||||
<div className="space-y-6">
|
||||
<section className="panel p-8">
|
||||
<p className="text-[10px] font-mono uppercase tracking-wider text-[var(--nvidia-green)]">Guided Tasks</p>
|
||||
<h1 className="mt-2 text-xl font-semibold uppercase tracking-wider text-[var(--foreground)]">Wizards</h1>
|
||||
<p className="mt-2 max-w-3xl text-sm text-[var(--foreground-dim)]">
|
||||
Step-by-step workflows for common operations. The first wizard clones one sandbox into another using backup and restore.
|
||||
</p>
|
||||
</section>
|
||||
|
||||
<section className="panel overflow-hidden">
|
||||
<div className="border-b border-[var(--border-subtle)] p-5">
|
||||
<div className="flex items-center justify-between gap-4 max-md:flex-col max-md:items-start">
|
||||
<div>
|
||||
<h2 className="text-sm font-semibold uppercase tracking-wider text-[var(--foreground)]">Clone Sandbox</h2>
|
||||
<p className="mt-1 text-xs text-[var(--foreground-dim)]">Create a fresh sandbox, back up the source, then restore into the target.</p>
|
||||
</div>
|
||||
<span className="status-chip border border-[var(--border-subtle)] bg-[var(--background-tertiary)] px-2.5 py-1 text-[var(--foreground-dim)]">
|
||||
backup + restore
|
||||
</span>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<div className="border-b border-[var(--border-subtle)] p-4">
|
||||
<div className="grid grid-cols-5 gap-2 max-md:grid-cols-1">
|
||||
{steps.map((step, index) => (
|
||||
<button
|
||||
key={step.key}
|
||||
type="button"
|
||||
onClick={() => setActiveStep(step.key)}
|
||||
className={`rounded-sm border px-3 py-2 text-left text-xs font-mono uppercase tracking-wider ${
|
||||
activeStep === step.key
|
||||
? "border-[var(--nvidia-green)] bg-[var(--surface-hover)] text-[var(--foreground)]"
|
||||
: index < activeIndex
|
||||
? "border-[var(--nvidia-green)]/40 text-[var(--nvidia-green)]"
|
||||
: "border-[var(--border-subtle)] text-[var(--foreground-dim)]"
|
||||
}`}
|
||||
>
|
||||
{index + 1}. {step.label}
|
||||
</button>
|
||||
))}
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<div className="p-5">
|
||||
{activeStep === "source" && (
|
||||
<div className="space-y-4">
|
||||
<div>
|
||||
<h3 className="text-xs font-semibold uppercase tracking-wider text-[var(--foreground)]">Choose Source Sandbox</h3>
|
||||
<p className="mt-1 text-xs text-[var(--foreground-dim)]">This sandbox will be archived from the selected source directory.</p>
|
||||
</div>
|
||||
<div className="grid grid-cols-1 gap-3 md:grid-cols-2 xl:grid-cols-3">
|
||||
{sandboxes.map((sandbox) => (
|
||||
<button
|
||||
key={sandbox.id}
|
||||
type="button"
|
||||
onClick={() => {
|
||||
setSourceSandboxId(sandbox.id)
|
||||
setTargetName(defaultCloneName(sandbox))
|
||||
}}
|
||||
className={`rounded-sm border p-4 text-left ${
|
||||
sourceSandboxId === sandbox.id
|
||||
? "border-[var(--nvidia-green)] bg-[var(--surface-hover)]"
|
||||
: "border-[var(--border-subtle)] bg-[var(--background-tertiary)]"
|
||||
}`}
|
||||
>
|
||||
<div className="flex items-center justify-between gap-3">
|
||||
<span className="truncate text-sm font-mono font-semibold text-[var(--foreground)]">{sandbox.name}</span>
|
||||
<span className="status-chip bg-[var(--status-running-bg)] px-2 py-1 text-[var(--status-running)]">{sandbox.status}</span>
|
||||
</div>
|
||||
<p className="mt-2 truncate text-xs text-[var(--foreground-dim)]">{sandbox.namespace} / {sandbox.sshHostAlias || sandbox.ip}</p>
|
||||
</button>
|
||||
))}
|
||||
</div>
|
||||
{sandboxes.length === 0 && (
|
||||
<div className="rounded-sm border border-[var(--border-subtle)] bg-[var(--background-tertiary)] p-4 text-sm text-[var(--foreground-dim)]">
|
||||
No sandboxes are available to clone yet.
|
||||
</div>
|
||||
)}
|
||||
</div>
|
||||
)}
|
||||
|
||||
{activeStep === "target" && (
|
||||
<div className="space-y-4">
|
||||
<div>
|
||||
<h3 className="text-xs font-semibold uppercase tracking-wider text-[var(--foreground)]">Configure Target Sandbox</h3>
|
||||
<p className="mt-1 text-xs text-[var(--foreground-dim)]">Choose the sandbox blueprint and target name.</p>
|
||||
</div>
|
||||
<div className="grid grid-cols-1 gap-4 md:grid-cols-2">
|
||||
{blueprints.map((blueprint) => (
|
||||
<button
|
||||
key={blueprint.id}
|
||||
type="button"
|
||||
onClick={() => setSelectedBlueprint(blueprint.id)}
|
||||
className={`rounded-sm border p-4 text-left ${selectedBlueprint === blueprint.id ? "border-[var(--nvidia-green)] bg-[var(--surface-hover)]" : "border-[var(--border-subtle)] bg-[var(--background-tertiary)]"}`}
|
||||
>
|
||||
<span className="text-sm font-semibold uppercase tracking-wider text-[var(--foreground)]">{blueprint.label}</span>
|
||||
<p className="mt-2 text-xs text-[var(--foreground-dim)]">{blueprint.description}</p>
|
||||
</button>
|
||||
))}
|
||||
</div>
|
||||
<label className="block space-y-2">
|
||||
<span className="text-[10px] uppercase tracking-wider text-[var(--foreground-dim)]">Target Sandbox Name</span>
|
||||
<input
|
||||
value={targetName}
|
||||
onChange={(event) => setTargetName(event.target.value)}
|
||||
placeholder="source-clone"
|
||||
className="w-full rounded-sm border border-[var(--border-subtle)] bg-[var(--background-tertiary)] px-3 py-2 text-xs font-mono text-[var(--foreground)] focus:outline-none focus:border-[var(--nvidia-green)]"
|
||||
/>
|
||||
</label>
|
||||
{activeBlueprint?.supportsTailscale && (
|
||||
<label className="flex items-center gap-3 text-sm font-mono text-[var(--foreground)]">
|
||||
<input type="checkbox" checked={enableTailscale} onChange={(event) => setEnableTailscale(event.target.checked)} />
|
||||
Enable Tailscale
|
||||
</label>
|
||||
)}
|
||||
</div>
|
||||
)}
|
||||
|
||||
{activeStep === "options" && (
|
||||
<div className="space-y-4">
|
||||
<div>
|
||||
<h3 className="text-xs font-semibold uppercase tracking-wider text-[var(--foreground)]">Clone Options</h3>
|
||||
<p className="mt-1 text-xs text-[var(--foreground-dim)]">Most clones should back up and restore /sandbox.</p>
|
||||
</div>
|
||||
<div className="grid grid-cols-1 gap-4 md:grid-cols-2">
|
||||
<label className="block space-y-2">
|
||||
<span className="text-[10px] uppercase tracking-wider text-[var(--foreground-dim)]">Source Backup Path</span>
|
||||
<input value={backupPath} onChange={(event) => setBackupPath(event.target.value)} className="w-full rounded-sm border border-[var(--border-subtle)] bg-[var(--background-tertiary)] px-3 py-2 text-xs font-mono text-[var(--foreground)]" />
|
||||
</label>
|
||||
<label className="block space-y-2">
|
||||
<span className="text-[10px] uppercase tracking-wider text-[var(--foreground-dim)]">Target Restore Path</span>
|
||||
<input value={restorePath} onChange={(event) => setRestorePath(event.target.value)} className="w-full rounded-sm border border-[var(--border-subtle)] bg-[var(--background-tertiary)] px-3 py-2 text-xs font-mono text-[var(--foreground)]" />
|
||||
</label>
|
||||
</div>
|
||||
<label className="flex items-start gap-3 rounded-sm border border-[var(--border-subtle)] bg-[var(--background-tertiary)] p-3">
|
||||
<input type="checkbox" checked={replaceTarget} onChange={(event) => setReplaceTarget(event.target.checked)} className="mt-0.5 h-4 w-4 accent-[var(--nvidia-green)]" />
|
||||
<span>
|
||||
<span className="block text-xs font-mono uppercase tracking-wider text-[var(--foreground)]">Replace target contents</span>
|
||||
<span className="mt-1 block text-[11px] text-[var(--foreground-dim)]">Recommended for cloning into a new sandbox.</span>
|
||||
</span>
|
||||
</label>
|
||||
</div>
|
||||
)}
|
||||
|
||||
{activeStep === "review" && (
|
||||
<div className="space-y-4">
|
||||
<div>
|
||||
<h3 className="text-xs font-semibold uppercase tracking-wider text-[var(--foreground)]">Review Clone Plan</h3>
|
||||
<p className="mt-1 text-xs text-[var(--foreground-dim)]">The wizard will run these steps in order.</p>
|
||||
</div>
|
||||
<div className="grid grid-cols-1 gap-3 md:grid-cols-2">
|
||||
{[
|
||||
["Source", sourceSandbox?.name || "-"],
|
||||
["Target", targetName || "-"],
|
||||
["Blueprint", activeBlueprint?.label || selectedBlueprint],
|
||||
["Backup Path", backupPath],
|
||||
["Restore Path", restorePath],
|
||||
["Restore Mode", replaceTarget ? "replace" : "merge"],
|
||||
].map(([label, value]) => (
|
||||
<div key={label} className="metric p-4">
|
||||
<p className="text-[10px] uppercase tracking-wider text-[var(--foreground-dim)]">{label}</p>
|
||||
<p className="mt-1 break-words font-mono text-sm text-[var(--foreground)]">{value}</p>
|
||||
</div>
|
||||
))}
|
||||
</div>
|
||||
</div>
|
||||
)}
|
||||
|
||||
{activeStep === "run" && (
|
||||
<div className="space-y-4">
|
||||
<div>
|
||||
<h3 className="text-xs font-semibold uppercase tracking-wider text-[var(--foreground)]">Run Clone</h3>
|
||||
<p className="mt-1 text-xs text-[var(--foreground-dim)]">Progress appears here as each operation completes.</p>
|
||||
</div>
|
||||
<div className="rounded-sm border border-[var(--border-subtle)] bg-[var(--background-tertiary)] p-4">
|
||||
{runLog.length === 0 ? (
|
||||
<p className="text-xs text-[var(--foreground-dim)]">Ready to clone.</p>
|
||||
) : (
|
||||
<div className="space-y-2">
|
||||
{runLog.map((line, index) => (
|
||||
<p key={`${line}-${index}`} className="font-mono text-xs text-[var(--foreground-dim)]">{line}</p>
|
||||
))}
|
||||
</div>
|
||||
)}
|
||||
</div>
|
||||
{message && <div className="rounded-sm border border-[var(--border-subtle)] bg-[var(--background-tertiary)] p-3 text-sm text-[var(--foreground-dim)] whitespace-pre-wrap">{message}</div>}
|
||||
</div>
|
||||
)}
|
||||
</div>
|
||||
|
||||
<div className="flex items-center justify-between gap-3 border-t border-[var(--border-subtle)] p-5">
|
||||
<button type="button" onClick={goBack} disabled={activeIndex === 0 || running} className="action-button px-4 py-2">
|
||||
Back
|
||||
</button>
|
||||
{activeStep === "review" || activeStep === "run" ? (
|
||||
<button type="button" onClick={runCloneWizard} disabled={!sourceSandbox || !targetName.trim() || running} className="rounded-sm bg-[var(--nvidia-green)] px-4 py-2 text-xs font-mono uppercase tracking-wider text-black disabled:opacity-50">
|
||||
{running ? "Running..." : "Start Clone"}
|
||||
</button>
|
||||
) : (
|
||||
<button type="button" onClick={goNext} disabled={!canContinue || running} className="rounded-sm bg-[var(--nvidia-green)] px-4 py-2 text-xs font-mono uppercase tracking-wider text-black disabled:opacity-50">
|
||||
Next
|
||||
</button>
|
||||
)}
|
||||
</div>
|
||||
</section>
|
||||
</div>
|
||||
)
|
||||
}
|
||||
+56
-2
@@ -32,6 +32,10 @@
|
||||
/* Data visualization */
|
||||
--metric-bg: #161616;
|
||||
--metric-border: #2a2a2a;
|
||||
--surface-raised: rgba(30, 30, 30, 0.86);
|
||||
--surface-hover: rgba(118, 185, 0, 0.08);
|
||||
--shadow-soft: 0 18px 60px rgba(0, 0, 0, 0.34);
|
||||
--shadow-glow: 0 0 0 1px rgba(118, 185, 0, 0.22), 0 18px 60px rgba(118, 185, 0, 0.12);
|
||||
}
|
||||
|
||||
html[data-theme="light"] {
|
||||
@@ -46,17 +50,34 @@ html[data-theme="light"] {
|
||||
--border-medium: #a3a3a3;
|
||||
--metric-bg: #fafafa;
|
||||
--metric-border: #e5e5e5;
|
||||
--surface-raised: rgba(255, 255, 255, 0.92);
|
||||
--surface-hover: rgba(93, 150, 0, 0.08);
|
||||
--shadow-soft: 0 18px 46px rgba(23, 23, 23, 0.08);
|
||||
--shadow-glow: 0 0 0 1px rgba(93, 150, 0, 0.22), 0 18px 46px rgba(93, 150, 0, 0.12);
|
||||
}
|
||||
|
||||
body {
|
||||
margin: 0;
|
||||
color: var(--foreground);
|
||||
background: var(--background);
|
||||
background:
|
||||
radial-gradient(circle at 70% 0%, rgba(118, 185, 0, 0.13), transparent 28rem),
|
||||
linear-gradient(180deg, var(--background-secondary), var(--background) 18rem);
|
||||
font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
|
||||
-webkit-font-smoothing: antialiased;
|
||||
-moz-osx-font-smoothing: grayscale;
|
||||
}
|
||||
|
||||
* {
|
||||
scrollbar-color: var(--border-medium) transparent;
|
||||
}
|
||||
|
||||
button,
|
||||
a,
|
||||
select,
|
||||
input {
|
||||
outline-color: var(--nvidia-green);
|
||||
}
|
||||
|
||||
@layer utilities {
|
||||
.text-balance {
|
||||
text-wrap: balance;
|
||||
@@ -102,9 +123,11 @@ body {
|
||||
|
||||
/* Panel styling - technical data panels */
|
||||
.panel {
|
||||
background: var(--background-panel);
|
||||
background: var(--surface-raised);
|
||||
border: 1px solid var(--border-subtle);
|
||||
border-radius: 4px;
|
||||
box-shadow: var(--shadow-soft);
|
||||
backdrop-filter: blur(14px);
|
||||
}
|
||||
|
||||
/* Metric display - data-dense */
|
||||
@@ -113,4 +136,35 @@ body {
|
||||
border: 1px solid var(--metric-border);
|
||||
border-radius: 3px;
|
||||
}
|
||||
|
||||
.action-button {
|
||||
border: 1px solid var(--border-subtle);
|
||||
border-radius: 4px;
|
||||
background: var(--background-tertiary);
|
||||
color: var(--foreground);
|
||||
font-family: ui-monospace, SFMono-Regular, Menlo, Monaco, Consolas, "Liberation Mono", "Courier New", monospace;
|
||||
font-size: 0.75rem;
|
||||
letter-spacing: 0.05em;
|
||||
text-transform: uppercase;
|
||||
transition: border-color 150ms ease, background-color 150ms ease, color 150ms ease, transform 150ms ease;
|
||||
}
|
||||
|
||||
.action-button:hover:not(:disabled) {
|
||||
border-color: var(--nvidia-green);
|
||||
background: var(--surface-hover);
|
||||
transform: translateY(-1px);
|
||||
}
|
||||
|
||||
.action-button:disabled {
|
||||
cursor: not-allowed;
|
||||
opacity: 0.5;
|
||||
}
|
||||
|
||||
.status-chip {
|
||||
border-radius: 999px;
|
||||
font-family: ui-monospace, SFMono-Regular, Menlo, Monaco, Consolas, "Liberation Mono", "Courier New", monospace;
|
||||
font-size: 0.625rem;
|
||||
letter-spacing: 0.05em;
|
||||
text-transform: uppercase;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -16,6 +16,7 @@ const HOST_PATH = [
|
||||
|
||||
const MAX_FILE_BYTES = Number.parseInt(process.env.SANDBOX_FILE_TRANSFER_MAX_BYTES || String(128 * 1024 * 1024), 10)
|
||||
const ALLOWED_ROOTS = ["/sandbox", "/tmp"]
|
||||
const MAX_LIST_ENTRIES = Number.parseInt(process.env.SANDBOX_FILE_LIST_MAX_ENTRIES || "200", 10)
|
||||
|
||||
function shellQuote(value: string) {
|
||||
return `'${value.replace(/'/g, `'\\''`)}'`
|
||||
@@ -26,6 +27,10 @@ function sanitizeFileName(value: string) {
|
||||
return base.replace(/[^\w.@:+-]/g, "_") || "upload.bin"
|
||||
}
|
||||
|
||||
function sanitizeArchiveStem(value: string) {
|
||||
return value.trim().replace(/[^\w.@:+-]/g, "-").replace(/-+/g, "-").replace(/^-|-$/g, "") || "sandbox"
|
||||
}
|
||||
|
||||
export function normalizeSandboxPath(input: string, fallbackFileName?: string) {
|
||||
const raw = input.trim()
|
||||
if (!raw) throw new Error("sandbox path is required")
|
||||
@@ -123,3 +128,117 @@ export async function downloadSandboxFile(sandboxId: string, sourcePath: string)
|
||||
bytes: result.stdout,
|
||||
}
|
||||
}
|
||||
|
||||
export type SandboxFileListEntry = {
|
||||
name: string
|
||||
path: string
|
||||
type: "file" | "directory" | "symlink" | "other"
|
||||
size: number | null
|
||||
modifiedAt: string | null
|
||||
}
|
||||
|
||||
function normalizeFindType(type: string): SandboxFileListEntry["type"] {
|
||||
if (type === "f") return "file"
|
||||
if (type === "d") return "directory"
|
||||
if (type === "l") return "symlink"
|
||||
return "other"
|
||||
}
|
||||
|
||||
export async function listSandboxFiles(sandboxId: string, directoryPath: string) {
|
||||
const sandboxName = await resolveSandboxName(sandboxId)
|
||||
const targetPath = normalizeSandboxPath(directoryPath || "/sandbox")
|
||||
const script = [
|
||||
`test -d ${shellQuote(targetPath)}`,
|
||||
`find ${shellQuote(targetPath)} -mindepth 1 -maxdepth 1 -printf '%y\\t%s\\t%T@\\t%p\\n' | sort -k4 | head -n ${MAX_LIST_ENTRIES}`,
|
||||
].join(" && ")
|
||||
const result = await runSandboxExec(sandboxName, script, undefined, 30000)
|
||||
if (result.code !== 0) throw new Error(result.stderr || "sandbox directory does not exist or is not readable")
|
||||
|
||||
const entries = result.stdout
|
||||
.toString("utf8")
|
||||
.split("\n")
|
||||
.map((line) => line.trimEnd())
|
||||
.filter(Boolean)
|
||||
.map((line): SandboxFileListEntry | null => {
|
||||
const [type, sizeValue, modifiedValue, ...pathParts] = line.split("\t")
|
||||
const entryPath = pathParts.join("\t")
|
||||
if (!entryPath) return null
|
||||
const modifiedSeconds = Number.parseFloat(modifiedValue)
|
||||
return {
|
||||
name: path.posix.basename(entryPath),
|
||||
path: entryPath,
|
||||
type: normalizeFindType(type),
|
||||
size: Number.isFinite(Number.parseInt(sizeValue, 10)) ? Number.parseInt(sizeValue, 10) : null,
|
||||
modifiedAt: Number.isFinite(modifiedSeconds) ? new Date(modifiedSeconds * 1000).toISOString() : null,
|
||||
}
|
||||
})
|
||||
.filter((entry): entry is SandboxFileListEntry => Boolean(entry))
|
||||
|
||||
return {
|
||||
sandboxName,
|
||||
path: targetPath,
|
||||
entries,
|
||||
truncated: entries.length >= MAX_LIST_ENTRIES,
|
||||
}
|
||||
}
|
||||
|
||||
export async function backupSandboxArchive(sandboxId: string, sourcePath: string) {
|
||||
const sandboxName = await resolveSandboxName(sandboxId)
|
||||
const targetPath = normalizeSandboxPath(sourcePath || "/sandbox")
|
||||
const timestamp = new Date().toISOString()
|
||||
const archiveName = `${sanitizeArchiveStem(sandboxName)}-${timestamp.replace(/[:.]/g, "-")}.tar.gz`
|
||||
const script = [
|
||||
`test -d ${shellQuote(targetPath)}`,
|
||||
`tar -C ${shellQuote(targetPath)} -czf - .`,
|
||||
].join(" && ")
|
||||
const result = await runSandboxExec(sandboxName, script, undefined, 120000)
|
||||
if (result.code !== 0) throw new Error(result.stderr || "failed to create sandbox backup archive")
|
||||
if (result.stdout.byteLength > MAX_FILE_BYTES) {
|
||||
throw new Error(`backup archive is too large; max transfer size is ${Math.floor(MAX_FILE_BYTES / 1024 / 1024)} MiB`)
|
||||
}
|
||||
|
||||
return {
|
||||
sandboxName,
|
||||
sourcePath: targetPath,
|
||||
fileName: archiveName,
|
||||
bytes: result.stdout,
|
||||
createdAt: timestamp,
|
||||
}
|
||||
}
|
||||
|
||||
export async function restoreSandboxArchive(
|
||||
sandboxId: string,
|
||||
targetPathInput: string,
|
||||
archiveName: string,
|
||||
payload: Buffer,
|
||||
replace: boolean
|
||||
) {
|
||||
if (payload.byteLength > MAX_FILE_BYTES) {
|
||||
throw new Error(`archive is too large; max transfer size is ${Math.floor(MAX_FILE_BYTES / 1024 / 1024)} MiB`)
|
||||
}
|
||||
|
||||
const sandboxName = await resolveSandboxName(sandboxId)
|
||||
const targetPath = normalizeSandboxPath(targetPathInput || "/sandbox")
|
||||
const safeArchiveName = sanitizeFileName(archiveName || "sandbox-backup.tar.gz")
|
||||
const script = [
|
||||
`tmp_archive="$(mktemp /tmp/openshell-restore.XXXXXX.tar.gz)"`,
|
||||
`cat > "$tmp_archive"`,
|
||||
`tar -tzf "$tmp_archive" >/tmp/openshell-restore-list.$$`,
|
||||
`while IFS= read -r entry; do case "$entry" in ""|/*|../*|*/../*|*"/..") rm -f "$tmp_archive" /tmp/openshell-restore-list.$$; exit 42;; esac; done < /tmp/openshell-restore-list.$$`,
|
||||
`mkdir -p ${shellQuote(targetPath)}`,
|
||||
replace ? `find ${shellQuote(targetPath)} -mindepth 1 -maxdepth 1 -exec rm -rf -- {} +` : `:`,
|
||||
`if grep -q '^payload/' /tmp/openshell-restore-list.$$; then tar -xzf "$tmp_archive" -C ${shellQuote(targetPath)} --strip-components=1 --wildcards 'payload/*'; else tar -xzf "$tmp_archive" -C ${shellQuote(targetPath)}; fi`,
|
||||
`rm -f "$tmp_archive" /tmp/openshell-restore-list.$$`,
|
||||
].join(" && ")
|
||||
const result = await runSandboxExec(sandboxName, script, payload, 120000)
|
||||
if (result.code === 42) throw new Error("archive contains unsafe paths")
|
||||
if (result.code !== 0) throw new Error(result.stderr || "failed to restore sandbox archive")
|
||||
|
||||
return {
|
||||
sandboxName,
|
||||
archiveName: safeArchiveName,
|
||||
targetPath,
|
||||
bytes: payload.byteLength,
|
||||
mode: replace ? "replace" : "merge",
|
||||
}
|
||||
}
|
||||
|
||||
+30
-9
@@ -4,6 +4,8 @@ import Sidebar from './components/Sidebar'
|
||||
import SandboxList from './components/SandboxList'
|
||||
import ConfigurationPanel from './components/ConfigurationPanel'
|
||||
import InferenceEndpointPanel from './components/InferenceEndpointPanel'
|
||||
import HelpPanel from './components/HelpPanel'
|
||||
import WizardPanel from './components/WizardPanel'
|
||||
import { useSandboxInventory } from './hooks/useSandboxInventory'
|
||||
import {
|
||||
createHydrationSafeDashboardSessionState,
|
||||
@@ -18,12 +20,12 @@ export default function Dashboard() {
|
||||
const [dashboardSession, setDashboardSession] = useState(() => createHydrationSafeDashboardSessionState())
|
||||
const [isCreateMode, setIsCreateMode] = useState(false)
|
||||
const [isDestroyMode, setIsDestroyMode] = useState(false)
|
||||
const [activeView, setActiveView] = useState<'settings' | 'sandboxes'>('sandboxes')
|
||||
const [activeView, setActiveView] = useState<'settings' | 'sandboxes' | 'help' | 'wizards'>('sandboxes')
|
||||
const [deletingSandboxId, setDeletingSandboxId] = useState<string | null>(null)
|
||||
const [showDeleteConfirm, setShowDeleteConfirm] = useState(false)
|
||||
const [lifecycleMessage, setLifecycleMessage] = useState<string | null>(null)
|
||||
const [deleteInProgress, setDeleteInProgress] = useState(false)
|
||||
const inventoryEnabled = activeView === 'sandboxes' || isCreateMode || isDestroyMode
|
||||
const inventoryEnabled = activeView === 'sandboxes' || activeView === 'wizards' || isCreateMode || isDestroyMode
|
||||
const { sandboxes, nemoclaw, loading, error, refresh } = useSandboxInventory({
|
||||
enabled: inventoryEnabled,
|
||||
})
|
||||
@@ -202,6 +204,18 @@ export default function Dashboard() {
|
||||
setIsDestroyMode(false)
|
||||
clearSelection()
|
||||
}}
|
||||
onWizardsClick={() => {
|
||||
setActiveView('wizards')
|
||||
setIsCreateMode(false)
|
||||
setIsDestroyMode(false)
|
||||
clearSelection()
|
||||
}}
|
||||
onHelpClick={() => {
|
||||
setActiveView('help')
|
||||
setIsCreateMode(false)
|
||||
setIsDestroyMode(false)
|
||||
clearSelection()
|
||||
}}
|
||||
onExitMode={() => {
|
||||
setIsCreateMode(false)
|
||||
setIsDestroyMode(false)
|
||||
@@ -213,9 +227,9 @@ export default function Dashboard() {
|
||||
}}
|
||||
/>
|
||||
|
||||
<main className="ml-64 transition-all duration-300">
|
||||
<main className="ml-64 min-h-screen transition-all duration-300 max-lg:ml-0 max-lg:pb-28">
|
||||
<div>
|
||||
<div className="p-8">
|
||||
<div className="mx-auto max-w-7xl p-8 max-sm:p-4">
|
||||
{activeView === 'settings' ? (
|
||||
<div className="space-y-6">
|
||||
<div className="panel p-8">
|
||||
@@ -239,6 +253,10 @@ export default function Dashboard() {
|
||||
</div>
|
||||
<InferenceEndpointPanel />
|
||||
</div>
|
||||
) : activeView === 'help' ? (
|
||||
<HelpPanel />
|
||||
) : activeView === 'wizards' ? (
|
||||
<WizardPanel sandboxes={sandboxes} onInventoryRefresh={refresh} />
|
||||
) : isCreateMode ? (
|
||||
<div className="space-y-6">
|
||||
<div className="panel p-8">
|
||||
@@ -304,9 +322,12 @@ export default function Dashboard() {
|
||||
</div>
|
||||
) : (
|
||||
<>
|
||||
<div className="flex items-center justify-between mb-8">
|
||||
<div>
|
||||
<h1 className="text-lg font-semibold text-[var(--foreground)] uppercase tracking-wider">
|
||||
<div className="mb-8 flex items-center justify-between gap-4 rounded border border-[var(--border-subtle)] bg-[var(--surface-raised)]/70 p-5 shadow-[var(--shadow-soft)] backdrop-blur max-sm:flex-col max-sm:items-start">
|
||||
<div className="min-w-0">
|
||||
<p className="text-[10px] font-mono uppercase tracking-wider text-[var(--nvidia-green)]">
|
||||
{sandboxes.filter((sandbox) => sandbox.status === 'running').length} online / {sandboxes.length} total
|
||||
</p>
|
||||
<h1 className="mt-1 text-xl font-semibold text-[var(--foreground)] uppercase tracking-wider">
|
||||
OPENSHELL CONTROL
|
||||
</h1>
|
||||
<p className="text-xs text-[var(--foreground-dim)] mt-1">
|
||||
@@ -315,7 +336,7 @@ export default function Dashboard() {
|
||||
</div>
|
||||
<button
|
||||
onClick={toggleTheme}
|
||||
className="px-4 py-2 rounded-sm bg-[var(--background-tertiary)] text-[var(--foreground)] text-xs font-mono uppercase tracking-wider hover:bg-[var(--background-panel)]"
|
||||
className="action-button px-4 py-2"
|
||||
>
|
||||
{theme === 'dark' ? 'LIGHT' : 'DARK'}
|
||||
</button>
|
||||
@@ -367,7 +388,7 @@ export default function Dashboard() {
|
||||
|
||||
{showDeleteConfirm && (
|
||||
<div className="fixed inset-0 bg-black/80 flex items-center justify-center z-50">
|
||||
<div className="panel p-8 max-w-md border-2 border-[var(--status-stopped)]">
|
||||
<div className="panel w-[min(92vw,28rem)] p-8 border-2 border-[var(--status-stopped)]">
|
||||
<div className="flex items-center gap-4 mb-4">
|
||||
<svg className="w-12 h-12 text-[var(--status-stopped)]" fill="none" stroke="currentColor" viewBox="0 0 24 24">
|
||||
<path strokeLinecap="square" strokeLinejoin="miter" strokeWidth={2} d="M12 9v2m0 4h.01m-6.938 4h13.856c1.54 0 2.502-1.667 1.732-3L13.732 4c-.77-1.333-2.694-1.333-3.464 0L3.34 16c-.77 1.333.192 3 1.732 3z" />
|
||||
|
||||
Reference in New Issue
Block a user