Restore version-locked sandbox create flow
This commit is contained in:
+82
-163
@@ -1,10 +1,6 @@
|
||||
import { NextResponse } from "next/server"
|
||||
import { execFile, spawn } from "node:child_process"
|
||||
import { existsSync } from "node:fs"
|
||||
import { readFile, writeFile } from "node:fs/promises"
|
||||
import path from "node:path"
|
||||
import { promisify } from "node:util"
|
||||
import { normalizeInferenceBaseUrlForGateway } from "@/app/lib/inferenceEndpointUrl"
|
||||
import { inspectSandbox } from "@/app/lib/openshellHost"
|
||||
import {
|
||||
commandExists,
|
||||
@@ -16,7 +12,6 @@ import {
|
||||
NEMOCLAW_SETUP_CANDIDATES,
|
||||
NODE_BIN,
|
||||
OPENSHELL_BIN,
|
||||
hostCommandEnv,
|
||||
} from "@/app/lib/hostCommands"
|
||||
|
||||
const execFileAsync = promisify(execFile)
|
||||
@@ -48,161 +43,80 @@ type SandboxVerification = {
|
||||
const AUTHORITATIVE_SUCCESS_PHASE = "Ready"
|
||||
const NO_PENDING_DEVICE_REQUESTS = /no pending device pairing requests/i
|
||||
|
||||
type ConfiguredInferenceRoute = {
|
||||
provider: string
|
||||
model: string
|
||||
}
|
||||
|
||||
function elapsedMs(start: number) {
|
||||
return Date.now() - start
|
||||
}
|
||||
|
||||
function stripAnsi(value: string) {
|
||||
return value.replace(/\x1B\[[0-?]*[ -/]*[@-~]/g, "")
|
||||
}
|
||||
|
||||
function readField(output: string, label: string) {
|
||||
const match = output.match(new RegExp(`^\\s*${label}:\\s*(.+?)\\s*$`, "im"))
|
||||
return match ? match[1].trim() : ""
|
||||
}
|
||||
|
||||
function parseConfiguredInferenceRoute(output: string, label: "Gateway inference" | "System inference"): ConfiguredInferenceRoute | null {
|
||||
const otherLabel = label === "Gateway inference" ? "System inference" : "Gateway inference"
|
||||
const pattern = new RegExp(`${label}:\\s*([\\s\\S]*?)(?:\\n\\s*${otherLabel}:|$)`, "i")
|
||||
const section = output.match(pattern)?.[1] ?? ""
|
||||
if (!section || /Not configured/i.test(section)) return null
|
||||
const provider = readField(section, "Provider")
|
||||
const model = readField(section, "Model")
|
||||
return provider && model ? { provider, model } : null
|
||||
}
|
||||
|
||||
async function resolveConfiguredPrimaryInferenceRoute() {
|
||||
try {
|
||||
const { stdout } = await execFileAsync(OPENSHELL_BIN, ["inference", "get"], {
|
||||
env: hostCommandEnv({
|
||||
OPENSHELL_GATEWAY: process.env.OPENSHELL_GATEWAY || "nemoclaw",
|
||||
}),
|
||||
timeout: 30000,
|
||||
maxBuffer: 5 * 1024 * 1024,
|
||||
})
|
||||
const output = stripAnsi(String(stdout).trim())
|
||||
return parseConfiguredInferenceRoute(output, "Gateway inference") || parseConfiguredInferenceRoute(output, "System inference")
|
||||
} catch {
|
||||
return null
|
||||
}
|
||||
}
|
||||
|
||||
function mapOpenShellProviderToNemoClawProvider(provider: string) {
|
||||
const normalized = provider.trim().toLowerCase()
|
||||
const mappings: Record<string, string> = {
|
||||
"nvidia-inference": "build",
|
||||
"nvidia-prod": "build",
|
||||
"nvidia": "build",
|
||||
"nvidia-nim": "nim-local",
|
||||
"nim-local": "nim-local",
|
||||
"ollama-local": "ollama",
|
||||
"ollama": "ollama",
|
||||
"vllm-local": "vllm",
|
||||
"vllm": "vllm",
|
||||
"openai-api": "openai",
|
||||
"openai": "openai",
|
||||
"anthropic-prod": "anthropic",
|
||||
"anthropic": "anthropic",
|
||||
"compatible-anthropic-endpoint": "anthropicCompatible",
|
||||
"anthropiccompatible": "anthropicCompatible",
|
||||
"compatible-endpoint": "custom",
|
||||
"custom": "custom",
|
||||
}
|
||||
return mappings[normalized] || ""
|
||||
}
|
||||
|
||||
function applyConfiguredInferenceToOnboardEnv(env: NodeJS.ProcessEnv, route: ConfiguredInferenceRoute | null) {
|
||||
if (!route) return null
|
||||
const provider = mapOpenShellProviderToNemoClawProvider(route.provider)
|
||||
if (!provider) return null
|
||||
|
||||
env.NEMOCLAW_PROVIDER = provider
|
||||
env.NEMOCLAW_MODEL = route.model
|
||||
if (provider === "nim-local" || provider === "vllm") {
|
||||
env.NEMOCLAW_EXPERIMENTAL = env.NEMOCLAW_EXPERIMENTAL || "1"
|
||||
}
|
||||
if (provider === "custom") {
|
||||
const endpointUrl = process.env.NEMOCLAW_ENDPOINT_URL || process.env.OPENAI_BASE_URL || process.env.VLLM_BASE_URL || ""
|
||||
const normalizedEndpointUrl = normalizeInferenceBaseUrlForGateway(endpointUrl, "openai")
|
||||
if (normalizedEndpointUrl) env.NEMOCLAW_ENDPOINT_URL = normalizedEndpointUrl
|
||||
const providerKey = process.env.NEMOCLAW_PROVIDER_KEY || process.env.OPENAI_API_KEY || process.env.VLLM_API_KEY || ""
|
||||
if (providerKey) env.NEMOCLAW_PROVIDER_KEY = providerKey
|
||||
}
|
||||
return {
|
||||
openshellProvider: route.provider,
|
||||
nemoclawProvider: provider,
|
||||
model: route.model,
|
||||
}
|
||||
}
|
||||
|
||||
function appendNote(...parts: Array<string | false | null | undefined>) {
|
||||
return parts.filter(Boolean).join(" ")
|
||||
}
|
||||
|
||||
function resolvePreferredNemoClawDockerfile() {
|
||||
const home = process.env.HOME || ""
|
||||
const candidates = [
|
||||
process.env.NEMOCLAW_DOCKERFILE,
|
||||
home ? path.join(home, ".nemoclaw/source/Dockerfile") : undefined,
|
||||
NEMOCLAW_CWD ? path.join(NEMOCLAW_CWD, "Dockerfile") : undefined,
|
||||
home ? path.join(home, "NemoClaw/Dockerfile") : undefined,
|
||||
].filter((candidate): candidate is string => Boolean(candidate))
|
||||
return candidates.find((candidate) => existsSync(candidate)) || null
|
||||
}
|
||||
|
||||
async function relaxKnownNemoClawDockerfileOpenClawPatch(dockerfilePath: string | null) {
|
||||
if (!dockerfilePath) return null
|
||||
try {
|
||||
const source = await readFile(dockerfilePath, "utf8")
|
||||
const strictAssertion = "assert old in src, 'writeConfigFile(params.nextConfig) pattern not found'"
|
||||
if (!source.includes(strictAssertion)) {
|
||||
return { dockerfilePath, patched: false, reason: "no-known-brittle-openclaw-patch" }
|
||||
}
|
||||
|
||||
let next = source.replace(
|
||||
strictAssertion,
|
||||
"print('[nemoclaw] replaceConfigFile shape changed; skipping optional EACCES compatibility patch', file=sys.stderr)",
|
||||
)
|
||||
next = next.replace(
|
||||
/grep -REq\s+--include='\*\.js'\s+'OPENSHELL_SANDBOX\.\*EACCES'\s+"\$rcf_file"\s+\|\|\s+\{\s+echo\s+"ERROR: Patch 4 \(replaceConfigFile EACCES\) not applied"\s+>&2;\s+exit 1;\s+\}/g,
|
||||
"grep -REq --include='*.js' 'OPENSHELL_SANDBOX.*EACCES' \"$rcf_file\" || echo \"WARN: Patch 4 (replaceConfigFile EACCES) not applied; OpenClaw write shape changed\" >&2",
|
||||
)
|
||||
if (next !== source) {
|
||||
await writeFile(dockerfilePath, next)
|
||||
return { dockerfilePath, patched: true, reason: "relaxed-brittle-openclaw-patch" }
|
||||
}
|
||||
return { dockerfilePath, patched: false, reason: "known-patch-present-but-unmodified" }
|
||||
} catch (error) {
|
||||
const message = error instanceof Error ? error.message : String(error ?? "unknown error")
|
||||
return { dockerfilePath, patched: false, reason: `patch-check-failed: ${message}` }
|
||||
}
|
||||
}
|
||||
|
||||
type NemoClawCreateCommand = {
|
||||
file: string
|
||||
args: string[]
|
||||
mode: "cli-onboard" | "legacy-setup"
|
||||
dockerfilePath?: string | null
|
||||
}
|
||||
|
||||
type CreateInferenceMode = "auto" | "vllm" | "nim"
|
||||
|
||||
type CreateInferenceSettings = {
|
||||
mode: CreateInferenceMode
|
||||
model: string
|
||||
hasApiKey: boolean
|
||||
envSummary: string[]
|
||||
}
|
||||
|
||||
function parseCreateInferenceSettings(body: any): CreateInferenceSettings {
|
||||
const raw = body?.createInference && typeof body.createInference === "object" ? body.createInference : {}
|
||||
const requestedMode = typeof raw.mode === "string" ? raw.mode : "auto"
|
||||
const mode: CreateInferenceMode = requestedMode === "vllm" || requestedMode === "nim" ? requestedMode : "auto"
|
||||
const model = typeof raw.model === "string" ? raw.model.trim() : ""
|
||||
const apiKey = typeof raw.apiKey === "string" ? raw.apiKey.trim() : ""
|
||||
|
||||
return {
|
||||
mode,
|
||||
model,
|
||||
hasApiKey: Boolean(apiKey),
|
||||
envSummary: [],
|
||||
}
|
||||
}
|
||||
|
||||
function applyCreateInferenceEnv(env: NodeJS.ProcessEnv, settings: CreateInferenceSettings, body: any) {
|
||||
if (settings.mode === "auto") return settings
|
||||
|
||||
env.NEMOCLAW_EXPERIMENTAL = "1"
|
||||
settings.envSummary.push("NEMOCLAW_EXPERIMENTAL=1")
|
||||
|
||||
if (settings.mode === "vllm") {
|
||||
env.NEMOCLAW_PROVIDER = "vllm"
|
||||
settings.envSummary.push("NEMOCLAW_PROVIDER=vllm")
|
||||
}
|
||||
|
||||
if (settings.mode === "nim") {
|
||||
env.NEMOCLAW_PROVIDER = "nim-local"
|
||||
settings.envSummary.push("NEMOCLAW_PROVIDER=nim-local")
|
||||
const apiKey = typeof body?.createInference?.apiKey === "string" ? body.createInference.apiKey.trim() : ""
|
||||
if (apiKey) {
|
||||
env.NVIDIA_API_KEY = apiKey
|
||||
env.NEMOCLAW_PROVIDER_KEY = apiKey
|
||||
settings.envSummary.push("NVIDIA_API_KEY=<provided>", "NEMOCLAW_PROVIDER_KEY=<provided>")
|
||||
}
|
||||
}
|
||||
|
||||
if (settings.model) {
|
||||
env.NEMOCLAW_MODEL = settings.model
|
||||
settings.envSummary.push(`NEMOCLAW_MODEL=${settings.model}`)
|
||||
}
|
||||
|
||||
return settings
|
||||
}
|
||||
|
||||
function buildNemoClawCreateCommand(): NemoClawCreateCommand {
|
||||
if (NEMOCLAW_BIN && commandExists(NEMOCLAW_BIN)) {
|
||||
const dockerfilePath = resolvePreferredNemoClawDockerfile()
|
||||
const args = [
|
||||
"onboard",
|
||||
"--non-interactive",
|
||||
"--recreate-sandbox",
|
||||
"--yes-i-accept-third-party-software",
|
||||
...(dockerfilePath ? ["--from", dockerfilePath] : []),
|
||||
]
|
||||
const args = ["onboard", "--non-interactive", "--recreate-sandbox", "--yes-i-accept-third-party-software"]
|
||||
return /\.(?:c?m?js|ts)$/i.test(NEMOCLAW_BIN)
|
||||
? { file: NODE_BIN, args: [NEMOCLAW_BIN, ...args], mode: "cli-onboard", dockerfilePath }
|
||||
: { file: NEMOCLAW_BIN, args, mode: "cli-onboard", dockerfilePath }
|
||||
? { file: NODE_BIN, args: [NEMOCLAW_BIN, ...args], mode: "cli-onboard" }
|
||||
: { file: NEMOCLAW_BIN, args, mode: "cli-onboard" }
|
||||
}
|
||||
if (NEMOCLAW_SETUP && commandExists(NEMOCLAW_SETUP)) {
|
||||
return { file: "/bin/bash", args: [NEMOCLAW_SETUP], mode: "legacy-setup" }
|
||||
@@ -380,9 +294,14 @@ async function approveOpenClawDeviceRequests(sandboxName: string) {
|
||||
"sh",
|
||||
"-lc",
|
||||
"openclaw devices approve --latest --json --timeout 10000",
|
||||
], hostCommandEnv({
|
||||
], {
|
||||
...process.env,
|
||||
PATH: HOST_PATH,
|
||||
OPENSHELL_GATEWAY: process.env.OPENSHELL_GATEWAY || "nemoclaw",
|
||||
}), 15000)
|
||||
NO_COLOR: "1",
|
||||
CLICOLOR: "0",
|
||||
CLICOLOR_FORCE: "0",
|
||||
}, 15000)
|
||||
|
||||
const combinedOutput = `${result.stdout}\n${result.stderr}`.trim()
|
||||
const noPending = NO_PENDING_DEVICE_REQUESTS.test(combinedOutput)
|
||||
@@ -466,7 +385,8 @@ export async function POST(request: Request) {
|
||||
const sandboxName = validateSandboxName(typeof body?.sandboxName === "string" ? body.sandboxName.trim() : "")
|
||||
const policy = body?.policy && typeof body.policy === "object" ? body.policy : null
|
||||
const enableTailscale = Boolean(body?.enableTailscale)
|
||||
console.log(`[sandbox/create] request:parsed sandbox=${sandboxName} blueprint=${blueprint} enableTailscale=${enableTailscale} elapsedMs=${elapsedMs(requestStartedAt)}`)
|
||||
const createInference = parseCreateInferenceSettings(body)
|
||||
console.log(`[sandbox/create] request:parsed sandbox=${sandboxName} blueprint=${blueprint} enableTailscale=${enableTailscale} inferenceMode=${createInference.mode} elapsedMs=${elapsedMs(requestStartedAt)}`)
|
||||
|
||||
if (!blueprint) {
|
||||
return NextResponse.json({ ok: false, error: "blueprint is required" }, { status: 400 })
|
||||
@@ -474,24 +394,22 @@ export async function POST(request: Request) {
|
||||
|
||||
if (blueprint === "nemoclaw-blueprint") {
|
||||
const createCommand = buildNemoClawCreateCommand()
|
||||
const dockerfileCompatibility = await relaxKnownNemoClawDockerfileOpenClawPatch(createCommand.dockerfilePath ?? null)
|
||||
const configuredInferenceRoute = await resolveConfiguredPrimaryInferenceRoute()
|
||||
const env: NodeJS.ProcessEnv = hostCommandEnv({
|
||||
const env: NodeJS.ProcessEnv = {
|
||||
...process.env,
|
||||
PATH: HOST_PATH,
|
||||
NEMOCLAW_SANDBOX_NAME: sandboxName,
|
||||
NEMOCLAW_NON_INTERACTIVE: "1",
|
||||
NEMOCLAW_RECREATE_SANDBOX: "1",
|
||||
NEMOCLAW_ACCEPT_THIRD_PARTY_SOFTWARE: "1",
|
||||
OPENSHELL_GATEWAY: process.env.OPENSHELL_GATEWAY || "nemoclaw",
|
||||
})
|
||||
const onboardInference = applyConfiguredInferenceToOnboardEnv(env, configuredInferenceRoute)
|
||||
console.log(
|
||||
`[sandbox/create] inference-default sandbox=${sandboxName} openshellProvider=${onboardInference?.openshellProvider || "unconfigured"} nemoclawProvider=${onboardInference?.nemoclawProvider || "default"} model=${onboardInference?.model || "default"} elapsedMs=${elapsedMs(requestStartedAt)}`,
|
||||
)
|
||||
}
|
||||
|
||||
if (!enableTailscale && !onboardInference) {
|
||||
if (!enableTailscale) {
|
||||
env.NVIDIA_API_KEY = env.NVIDIA_API_KEY || "optional-local-mode"
|
||||
}
|
||||
|
||||
applyCreateInferenceEnv(env, createInference, body)
|
||||
|
||||
const result = await runCommand(
|
||||
createCommand.file,
|
||||
createCommand.mode === "legacy-setup" ? [...createCommand.args, sandboxName] : createCommand.args,
|
||||
@@ -508,10 +426,7 @@ export async function POST(request: Request) {
|
||||
blueprint,
|
||||
sandboxName,
|
||||
enableTailscale,
|
||||
configuredInferenceRoute,
|
||||
onboardInference,
|
||||
createCommand,
|
||||
dockerfileCompatibility,
|
||||
createInference,
|
||||
}, { status: 500 })
|
||||
}
|
||||
|
||||
@@ -536,10 +451,8 @@ export async function POST(request: Request) {
|
||||
verification,
|
||||
mode: "nemoclaw-blueprint",
|
||||
enableTailscale,
|
||||
configuredInferenceRoute,
|
||||
onboardInference,
|
||||
createInference,
|
||||
createCommand,
|
||||
dockerfileCompatibility,
|
||||
hostPath: HOST_PATH,
|
||||
readiness: {
|
||||
attempts: readiness.attempts,
|
||||
@@ -560,7 +473,13 @@ export async function POST(request: Request) {
|
||||
}
|
||||
|
||||
if (blueprint === "custom-sandbox") {
|
||||
const env: NodeJS.ProcessEnv = hostCommandEnv()
|
||||
const env: NodeJS.ProcessEnv = {
|
||||
...process.env,
|
||||
PATH: HOST_PATH,
|
||||
NO_COLOR: "1",
|
||||
CLICOLOR: "0",
|
||||
CLICOLOR_FORCE: "0",
|
||||
}
|
||||
const createAttempt = await runCreateCommandBounded(OPENSHELL_BIN, ["sandbox", "create", "--name", sandboxName], env, 15000)
|
||||
|
||||
if (createAttempt.completed && createAttempt.exitCode !== 0) {
|
||||
|
||||
@@ -7,6 +7,7 @@ type EndpointProtocol = "" | "rest"
|
||||
type EndpointTls = "" | "terminate" | "passthrough"
|
||||
type EndpointEnforcement = "" | "enforce" | "audit"
|
||||
type EndpointAccess = "" | "read-only" | "read-write" | "full"
|
||||
type CreateInferenceMode = "auto" | "vllm" | "nim"
|
||||
|
||||
interface NetworkRule { method: string; path: string }
|
||||
interface NetworkEndpoint { host: string; port: string; protocol: EndpointProtocol; tls: EndpointTls; enforcement: EndpointEnforcement; access: EndpointAccess; rules: NetworkRule[] }
|
||||
@@ -87,6 +88,9 @@ 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 [createInferenceMode, setCreateInferenceMode] = useState<CreateInferenceMode>("vllm")
|
||||
const [createInferenceModel, setCreateInferenceModel] = useState<string>("")
|
||||
const [createNvidiaApiKey, setCreateNvidiaApiKey] = useState<string>("")
|
||||
const [restoreFromBackup, setRestoreFromBackup] = useState<boolean>(false)
|
||||
const [restoreArchive, setRestoreArchive] = useState<File | null>(null)
|
||||
const [restorePath, setRestorePath] = useState<string>('/sandbox')
|
||||
@@ -134,7 +138,12 @@ export default function ConfigurationPanel({ sandboxId, mode = 'existing', onCre
|
||||
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 createInference = {
|
||||
mode: createInferenceMode,
|
||||
model: createInferenceModel.trim(),
|
||||
apiKey: createInferenceMode === 'nim' ? createNvidiaApiKey.trim() : '',
|
||||
}
|
||||
const res = await fetch('/api/sandbox/create', { method: 'POST', headers: { 'Content-Type': 'application/json' }, body: JSON.stringify({ blueprint: selectedBlueprint, sandboxName: sandboxName.trim(), enableTailscale, createInference, 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
|
||||
@@ -188,7 +197,76 @@ 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>}<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>}
|
||||
{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">
|
||||
<div>
|
||||
<h6 className="text-xs font-semibold uppercase tracking-wider text-[var(--foreground)]">Inference at Create</h6>
|
||||
<p className="mt-1 text-xs text-[var(--foreground-dim)]">Choose the provider NemoClaw should use while onboarding this sandbox.</p>
|
||||
</div>
|
||||
<div className="grid grid-cols-1 gap-3 md:grid-cols-3">
|
||||
<label className={`flex items-start gap-3 rounded-sm border p-3 text-sm text-[var(--foreground)] ${createInferenceMode === 'auto' ? 'border-[var(--nvidia-green)] bg-[rgba(118,185,0,0.08)]' : 'border-[var(--border-subtle)] bg-[var(--background-tertiary)]'}`}>
|
||||
<input type="checkbox" checked={createInferenceMode === 'auto'} onChange={() => setCreateInferenceMode('auto')} className="mt-0.5 h-4 w-4 accent-[var(--nvidia-green)]" />
|
||||
<span><span className="block text-xs font-mono uppercase tracking-wider">Auto</span><span className="mt-1 block text-[11px] text-[var(--foreground-dim)]">Let NemoClaw choose.</span></span>
|
||||
</label>
|
||||
<label className={`flex items-start gap-3 rounded-sm border p-3 text-sm text-[var(--foreground)] ${createInferenceMode === 'vllm' ? 'border-[var(--nvidia-green)] bg-[rgba(118,185,0,0.08)]' : 'border-[var(--border-subtle)] bg-[var(--background-tertiary)]'}`}>
|
||||
<input type="checkbox" checked={createInferenceMode === 'vllm'} onChange={() => setCreateInferenceMode('vllm')} className="mt-0.5 h-4 w-4 accent-[var(--nvidia-green)]" />
|
||||
<span><span className="block text-xs font-mono uppercase tracking-wider">Use vLLM in experimental mode</span><span className="mt-1 block text-[11px] text-[var(--foreground-dim)]">Sets NEMOCLAW_EXPERIMENTAL and vLLM.</span></span>
|
||||
</label>
|
||||
<label className={`flex items-start gap-3 rounded-sm border p-3 text-sm text-[var(--foreground)] ${createInferenceMode === 'nim' ? 'border-[var(--nvidia-green)] bg-[rgba(118,185,0,0.08)]' : 'border-[var(--border-subtle)] bg-[var(--background-tertiary)]'}`}>
|
||||
<input type="checkbox" checked={createInferenceMode === 'nim'} onChange={() => setCreateInferenceMode('nim')} className="mt-0.5 h-4 w-4 accent-[var(--nvidia-green)]" />
|
||||
<span><span className="block text-xs font-mono uppercase tracking-wider">Use NVIDIA NIM</span><span className="mt-1 block text-[11px] text-[var(--foreground-dim)]">Uses the experimental local NIM provider.</span></span>
|
||||
</label>
|
||||
</div>
|
||||
{createInferenceMode !== 'auto' && (
|
||||
<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)]">Model</label>
|
||||
<input value={createInferenceModel} onChange={(e) => setCreateInferenceModel(e.target.value)} placeholder={createInferenceMode === 'vllm' ? 'auto-detect from vLLM' : 'model name'} 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>
|
||||
{createInferenceMode === 'nim' && (
|
||||
<div className="space-y-2">
|
||||
<label className="text-[10px] uppercase tracking-wider text-[var(--foreground-dim)]">NVIDIA API Key</label>
|
||||
<input type="password" value={createNvidiaApiKey} onChange={(e) => setCreateNvidiaApiKey(e.target.value)} placeholder="nvapi-..." 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>
|
||||
)}
|
||||
</div>
|
||||
)}
|
||||
</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>
|
||||
|
||||
Reference in New Issue
Block a user