Integrate Docker NemoClaw and Hermes
This commit is contained in:
@@ -66,6 +66,8 @@ type NemoClawCreateCommand = {
|
||||
}
|
||||
|
||||
type CreateInferenceMode = "auto" | "vllm" | "nim"
|
||||
type CreateGpuMode = "none" | "auto" | "required"
|
||||
type NemoClawAgent = "openclaw" | "hermes"
|
||||
|
||||
type CreateInferenceSettings = {
|
||||
mode: CreateInferenceMode
|
||||
@@ -79,6 +81,13 @@ type NemoClawRegistryData = {
|
||||
defaultSandbox?: string | null
|
||||
}
|
||||
|
||||
function parseCreateGpuMode(body: any): CreateGpuMode {
|
||||
const raw = typeof body?.gpuMode === "string"
|
||||
? body.gpuMode
|
||||
: process.env.OPENSHELL_CONTROL_CREATE_GPU_MODE || "none"
|
||||
return raw === "auto" || raw === "required" ? raw : "none"
|
||||
}
|
||||
|
||||
function parseCreateInferenceSettings(body: any): CreateInferenceSettings {
|
||||
const raw = body?.createInference && typeof body.createInference === "object" ? body.createInference : {}
|
||||
const requestedMode = typeof raw.mode === "string" ? raw.mode : "vllm"
|
||||
@@ -124,13 +133,45 @@ function applyCreateInferenceEnv(env: NodeJS.ProcessEnv, settings: CreateInferen
|
||||
return settings
|
||||
}
|
||||
|
||||
function buildNemoClawCreateCommand(): NemoClawCreateCommand {
|
||||
function nemoClawGpuArgs(mode: CreateGpuMode) {
|
||||
if (mode === "required") return ["--gpu"]
|
||||
if (mode === "none") return ["--no-gpu"]
|
||||
return []
|
||||
}
|
||||
|
||||
function nemoClawAgentArgs(agent: NemoClawAgent) {
|
||||
return agent === "hermes" ? ["--agent", "hermes"] : []
|
||||
}
|
||||
|
||||
function isNemoClawOnboardBlueprint(blueprint: string) {
|
||||
return blueprint === "nemoclaw-blueprint" || blueprint === "nemoclaw-hermes"
|
||||
}
|
||||
|
||||
function nemoClawAgentForBlueprint(blueprint: string): NemoClawAgent {
|
||||
return blueprint === "nemoclaw-hermes" ? "hermes" : "openclaw"
|
||||
}
|
||||
|
||||
function openShellGpuArgs(mode: CreateGpuMode) {
|
||||
return mode === "required" ? ["--gpu"] : []
|
||||
}
|
||||
|
||||
function buildNemoClawCreateCommand(gpuMode: CreateGpuMode, agent: NemoClawAgent): NemoClawCreateCommand {
|
||||
if (NEMOCLAW_BIN && commandExists(NEMOCLAW_BIN)) {
|
||||
const args = ["onboard", "--non-interactive", "--recreate-sandbox", "--yes-i-accept-third-party-software"]
|
||||
const args = [
|
||||
"onboard",
|
||||
"--non-interactive",
|
||||
"--recreate-sandbox",
|
||||
"--yes-i-accept-third-party-software",
|
||||
...nemoClawAgentArgs(agent),
|
||||
...nemoClawGpuArgs(gpuMode),
|
||||
]
|
||||
return /\.(?:c?m?js|ts)$/i.test(NEMOCLAW_BIN)
|
||||
? { file: NODE_BIN, args: [NEMOCLAW_BIN, ...args], mode: "cli-onboard" }
|
||||
: { file: NEMOCLAW_BIN, args, mode: "cli-onboard" }
|
||||
}
|
||||
if (agent === "hermes") {
|
||||
throw new Error("Hermes sandbox creation requires the current NemoClaw CLI with --agent hermes support. Set NEMOCLAW_BIN in .env.local.")
|
||||
}
|
||||
if (NEMOCLAW_SETUP && commandExists(NEMOCLAW_SETUP)) {
|
||||
return { file: "/bin/bash", args: [NEMOCLAW_SETUP], mode: "legacy-setup" }
|
||||
}
|
||||
@@ -669,6 +710,14 @@ export async function GET() {
|
||||
source: "~/NemoClaw/nemoclaw-blueprint/blueprint.yaml",
|
||||
supportsTailscale: true,
|
||||
},
|
||||
{
|
||||
id: "nemoclaw-hermes",
|
||||
label: "Fresh Hermes Sandbox",
|
||||
description: "Bootstraps a Hermes Agent sandbox using NemoClaw's Hermes workflow.",
|
||||
type: "blueprint",
|
||||
source: "~/NemoClaw/agents/hermes/Dockerfile",
|
||||
supportsTailscale: false,
|
||||
},
|
||||
{
|
||||
id: "custom-sandbox",
|
||||
label: "New Custom Sandbox",
|
||||
@@ -698,17 +747,21 @@ 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)
|
||||
const gpuMode = parseCreateGpuMode(body)
|
||||
const createInference = parseCreateInferenceSettings(body)
|
||||
console.log(`[sandbox/create] request:parsed sandbox=${sandboxName} blueprint=${blueprint} enableTailscale=${enableTailscale} inferenceMode=${createInference.mode} elapsedMs=${elapsedMs(requestStartedAt)}`)
|
||||
console.log(`[sandbox/create] request:parsed sandbox=${sandboxName} blueprint=${blueprint} enableTailscale=${enableTailscale} gpuMode=${gpuMode} inferenceMode=${createInference.mode} elapsedMs=${elapsedMs(requestStartedAt)}`)
|
||||
|
||||
if (!blueprint) {
|
||||
return NextResponse.json({ ok: false, error: "blueprint is required" }, { status: 400 })
|
||||
}
|
||||
|
||||
if (blueprint === "nemoclaw-blueprint") {
|
||||
const createCommand = buildNemoClawCreateCommand()
|
||||
if (isNemoClawOnboardBlueprint(blueprint)) {
|
||||
const agent = nemoClawAgentForBlueprint(blueprint)
|
||||
const isOpenClawAgent = agent === "openclaw"
|
||||
const createCommand = buildNemoClawCreateCommand(gpuMode, agent)
|
||||
const env: NodeJS.ProcessEnv = hostCommandEnv({
|
||||
NEMOCLAW_SANDBOX_NAME: sandboxName,
|
||||
NEMOCLAW_AGENT: agent,
|
||||
NEMOCLAW_NON_INTERACTIVE: "1",
|
||||
NEMOCLAW_RECREATE_SANDBOX: "1",
|
||||
NEMOCLAW_ACCEPT_THIRD_PARTY_SOFTWARE: "1",
|
||||
@@ -735,8 +788,10 @@ export async function POST(request: Request) {
|
||||
stdout: result.stdout,
|
||||
stderr: result.stderr,
|
||||
blueprint,
|
||||
agent,
|
||||
sandboxName,
|
||||
enableTailscale,
|
||||
gpuMode,
|
||||
createInference,
|
||||
}, { status: 500 })
|
||||
}
|
||||
@@ -748,25 +803,27 @@ export async function POST(request: Request) {
|
||||
error: "Sandbox readiness polling produced no verification result.",
|
||||
}
|
||||
const created = readiness.verified
|
||||
const execApprovalsRepair = created ? await repairOpenClawExecApprovalsFile(sandboxName).catch((error) => ({
|
||||
const execApprovalsRepair = created && isOpenClawAgent ? await repairOpenClawExecApprovalsFile(sandboxName).catch((error) => ({
|
||||
sandboxName,
|
||||
path: "/sandbox/.openclaw/exec-approvals.json",
|
||||
error: error instanceof Error ? error.message : "Failed to repair OpenClaw exec approvals file",
|
||||
})) : null
|
||||
const deviceApproval = created ? await approveOpenClawDeviceRequests(sandboxName) : null
|
||||
const deviceApproval = created && isOpenClawAgent ? await approveOpenClawDeviceRequests(sandboxName) : null
|
||||
console.log(
|
||||
`[sandbox/create] request:complete sandbox=${sandboxName} created=${created} readinessAttempts=${readiness.attempts} deviceApproval=${deviceApproval?.approved ?? false} elapsedMs=${elapsedMs(requestStartedAt)}`,
|
||||
`[sandbox/create] request:complete sandbox=${sandboxName} created=${created} agent=${agent} readinessAttempts=${readiness.attempts} deviceApproval=${deviceApproval?.approved ?? false} elapsedMs=${elapsedMs(requestStartedAt)}`,
|
||||
)
|
||||
|
||||
return NextResponse.json({
|
||||
ok: created,
|
||||
blueprint,
|
||||
agent,
|
||||
sandboxName,
|
||||
created,
|
||||
verified: verification.verified,
|
||||
verification,
|
||||
mode: "nemoclaw-blueprint",
|
||||
mode: blueprint,
|
||||
enableTailscale,
|
||||
gpuMode,
|
||||
createInference,
|
||||
createCommand,
|
||||
hostPath: HOST_PATH,
|
||||
@@ -780,9 +837,16 @@ export async function POST(request: Request) {
|
||||
stderr: result.stderr,
|
||||
note: created
|
||||
? appendNote(
|
||||
enableTailscale
|
||||
? "NemoClaw blueprint workflow completed with Tailscale-enabled prerequisites. Existing healthy OpenShell gateways are reused before any new gateway start is attempted."
|
||||
: "NemoClaw blueprint workflow completed in local/default mode. Existing healthy OpenShell gateways are reused before any new gateway start is attempted.",
|
||||
agent === "hermes"
|
||||
? "NemoClaw Hermes workflow completed. Hermes exposes an API endpoint from the sandbox rather than an OpenClaw browser dashboard."
|
||||
: enableTailscale
|
||||
? "NemoClaw blueprint workflow completed with Tailscale-enabled prerequisites. Existing healthy OpenShell gateways are reused before any new gateway start is attempted."
|
||||
: "NemoClaw blueprint workflow completed in local/default mode. Existing healthy OpenShell gateways are reused before any new gateway start is attempted.",
|
||||
gpuMode === "none"
|
||||
? "GPU passthrough was disabled for this create run."
|
||||
: gpuMode === "required"
|
||||
? "GPU passthrough was required for this create run."
|
||||
: "NemoClaw chose GPU passthrough automatically for this create run.",
|
||||
execApprovalsRepair && "note" in execApprovalsRepair ? execApprovalsRepair.note : false,
|
||||
execApprovalsRepair && "error" in execApprovalsRepair ? `OpenClaw exec approvals repair failed: ${execApprovalsRepair.error}` : false,
|
||||
deviceApproval?.note,
|
||||
@@ -798,7 +862,7 @@ export async function POST(request: Request) {
|
||||
CLICOLOR: "0",
|
||||
CLICOLOR_FORCE: "0",
|
||||
})
|
||||
const createAttempt = await runCreateCommandBounded(OPENSHELL_BIN, ["sandbox", "create", "--name", sandboxName], env, 15000)
|
||||
const createAttempt = await runCreateCommandBounded(OPENSHELL_BIN, ["sandbox", "create", "--name", sandboxName, ...openShellGpuArgs(gpuMode)], env, 15000)
|
||||
|
||||
if (createAttempt.completed && createAttempt.exitCode !== 0) {
|
||||
return NextResponse.json({
|
||||
@@ -808,6 +872,7 @@ export async function POST(request: Request) {
|
||||
stderr: createAttempt.stderr,
|
||||
blueprint,
|
||||
sandboxName,
|
||||
gpuMode,
|
||||
}, { status: 500 })
|
||||
}
|
||||
|
||||
@@ -836,6 +901,7 @@ export async function POST(request: Request) {
|
||||
verified: verification.verified,
|
||||
verification,
|
||||
mode: "custom-sandbox",
|
||||
gpuMode,
|
||||
stdout: createAttempt.stdout,
|
||||
stderr: createAttempt.stderr,
|
||||
createCommand: {
|
||||
@@ -859,6 +925,9 @@ export async function POST(request: Request) {
|
||||
: (policyPrepared
|
||||
? "Custom sandbox created. Policy draft is prepared, but applying it live should be a follow-up action."
|
||||
: "Custom sandbox created."),
|
||||
gpuMode === "required"
|
||||
? "GPU passthrough was requested for this create run."
|
||||
: false,
|
||||
execApprovalsRepair && "note" in execApprovalsRepair ? execApprovalsRepair.note : false,
|
||||
execApprovalsRepair && "error" in execApprovalsRepair ? `OpenClaw exec approvals repair failed: ${execApprovalsRepair.error}` : false,
|
||||
deviceApproval?.note,
|
||||
@@ -881,6 +950,7 @@ export async function POST(request: Request) {
|
||||
"create",
|
||||
"--name",
|
||||
sandboxName,
|
||||
...openShellGpuArgs(gpuMode),
|
||||
"--from",
|
||||
sourceImage,
|
||||
"--policy",
|
||||
@@ -921,6 +991,7 @@ export async function POST(request: Request) {
|
||||
verified: verification.verified,
|
||||
verification,
|
||||
mode: "redeploy-image",
|
||||
gpuMode,
|
||||
stdout: createAttempt.stdout,
|
||||
stderr: createAttempt.stderr,
|
||||
createCommand: {
|
||||
@@ -941,6 +1012,9 @@ export async function POST(request: Request) {
|
||||
note: created
|
||||
? appendNote(
|
||||
`Sandbox created by redeploying the running image from '${source.name}' instead of rebuilding it.`,
|
||||
gpuMode === "required"
|
||||
? "GPU passthrough was requested for this create run."
|
||||
: false,
|
||||
createAttempt.forcedReady
|
||||
? "The dashboard returned as soon as OpenShell reported the redeployed sandbox Ready."
|
||||
: false,
|
||||
|
||||
@@ -1,11 +1,14 @@
|
||||
import { NextResponse } from "next/server"
|
||||
import { execFile } from "node:child_process"
|
||||
import { existsSync, readFileSync } from "node:fs"
|
||||
import { hostname, networkInterfaces } from "node:os"
|
||||
import path from "node:path"
|
||||
import { promisify } from "node:util"
|
||||
import { NEMOCLAW_BIN, NODE_BIN, OPENSHELL_BIN, hostCommandEnv } from "@/app/lib/hostCommands"
|
||||
import { resolveRuntimeAuthority } from "@/app/lib/runtimeAuthority"
|
||||
|
||||
const execFileAsync = promisify(execFile)
|
||||
const NEMOCLAW_REGISTRY_FILE = path.join(process.env.HOME || "/tmp", ".nemoclaw", "sandboxes.json")
|
||||
|
||||
type SandboxSummary = {
|
||||
id: string
|
||||
@@ -16,6 +19,7 @@ type SandboxSummary = {
|
||||
hasSshConfig: boolean
|
||||
source: "openshell"
|
||||
isDefault: boolean
|
||||
agent: string
|
||||
}
|
||||
|
||||
type NemoClawSummary = {
|
||||
@@ -26,6 +30,10 @@ type NemoClawSummary = {
|
||||
source: "nemoclaw-cli" | "none"
|
||||
}
|
||||
|
||||
type NemoClawRegistryData = {
|
||||
sandboxes?: Record<string, { name?: string; agent?: string | null }>
|
||||
}
|
||||
|
||||
type SandboxItem = {
|
||||
metadata: {
|
||||
name: string
|
||||
@@ -145,6 +153,24 @@ function buildNemoClawSummary(output: string | null, defaultSandboxNames: Set<st
|
||||
}
|
||||
}
|
||||
|
||||
function readNemoClawRegistry(): NemoClawRegistryData {
|
||||
try {
|
||||
return existsSync(NEMOCLAW_REGISTRY_FILE)
|
||||
? JSON.parse(readFileSync(NEMOCLAW_REGISTRY_FILE, "utf8"))
|
||||
: {}
|
||||
} catch {
|
||||
return {}
|
||||
}
|
||||
}
|
||||
|
||||
function resolveSandboxAgent(name: string, id: string | null, registry: NemoClawRegistryData) {
|
||||
const entries = registry.sandboxes ?? {}
|
||||
const directEntry = entries[name] || (id ? entries[id] : undefined)
|
||||
const namedEntry = Object.values(entries).find((entry) => entry?.name === name || Boolean(id && entry?.name === id))
|
||||
const agent = directEntry?.agent || namedEntry?.agent
|
||||
return typeof agent === "string" && agent.trim() ? agent.trim() : "openclaw"
|
||||
}
|
||||
|
||||
async function execNemoclaw(args: string[]) {
|
||||
const env = hostCommandEnv({
|
||||
OPENSHELL_GATEWAY: process.env.OPENSHELL_GATEWAY || "nemoclaw",
|
||||
@@ -189,7 +215,7 @@ function readHostIdentity() {
|
||||
return { hostname: hostname(), address: "127.0.0.1", interface: "lo0" }
|
||||
}
|
||||
|
||||
async function readSandbox(name: string, defaultSandboxNames: Set<string>): Promise<{ summary: SandboxSummary; pod: SandboxItem }> {
|
||||
async function readSandbox(name: string, defaultSandboxNames: Set<string>, registry: NemoClawRegistryData): Promise<{ summary: SandboxSummary; pod: SandboxItem }> {
|
||||
try {
|
||||
const [{ stdout: detailsStdout }, { stdout: sshStdout }] = await Promise.all([
|
||||
execOpenShell(["sandbox", "get", name]),
|
||||
@@ -203,6 +229,7 @@ async function readSandbox(name: string, defaultSandboxNames: Set<string>): Prom
|
||||
const sshConfig = sshStdout.trim()
|
||||
const sshHostAlias = parseSshHostAlias(sshConfig, sandboxName)
|
||||
const isDefault = defaultSandboxNames.has(sandboxName)
|
||||
const agent = resolveSandboxAgent(sandboxName, sandboxId, registry)
|
||||
|
||||
return {
|
||||
summary: {
|
||||
@@ -214,6 +241,7 @@ async function readSandbox(name: string, defaultSandboxNames: Set<string>): Prom
|
||||
hasSshConfig: Boolean(sshConfig),
|
||||
source: "openshell",
|
||||
isDefault,
|
||||
agent,
|
||||
},
|
||||
pod: {
|
||||
metadata: {
|
||||
@@ -223,6 +251,7 @@ async function readSandbox(name: string, defaultSandboxNames: Set<string>): Prom
|
||||
"nemoclaw.ai/sandbox-name": sandboxName,
|
||||
...(sandboxId ? { "nemoclaw.ai/sandbox-id": sandboxId } : {}),
|
||||
...(isDefault ? { "nemoclaw.ai/default": "true" } : {}),
|
||||
"nemoclaw.ai/agent": agent,
|
||||
},
|
||||
},
|
||||
spec: {
|
||||
@@ -245,6 +274,7 @@ async function readSandbox(name: string, defaultSandboxNames: Set<string>): Prom
|
||||
} catch (error) {
|
||||
const sandboxName = name
|
||||
const isDefault = defaultSandboxNames.has(sandboxName)
|
||||
const agent = resolveSandboxAgent(sandboxName, sandboxName, registry)
|
||||
return {
|
||||
summary: {
|
||||
id: sandboxName,
|
||||
@@ -255,6 +285,7 @@ async function readSandbox(name: string, defaultSandboxNames: Set<string>): Prom
|
||||
hasSshConfig: false,
|
||||
source: "openshell",
|
||||
isDefault,
|
||||
agent,
|
||||
},
|
||||
pod: {
|
||||
metadata: {
|
||||
@@ -264,6 +295,7 @@ async function readSandbox(name: string, defaultSandboxNames: Set<string>): Prom
|
||||
"nemoclaw.ai/sandbox-name": sandboxName,
|
||||
"nemoclaw.ai/sandbox-id": sandboxName,
|
||||
...(isDefault ? { "nemoclaw.ai/default": "true" } : {}),
|
||||
"nemoclaw.ai/agent": agent,
|
||||
},
|
||||
},
|
||||
spec: {
|
||||
@@ -297,7 +329,8 @@ export async function GET() {
|
||||
])
|
||||
: [null, null]
|
||||
const defaultSandboxNames = parseDefaultSandboxNames(nemoclawListResult?.stdout ?? "")
|
||||
const results = await Promise.all(names.map((name) => readSandbox(name, defaultSandboxNames)))
|
||||
const registry = readNemoClawRegistry()
|
||||
const results = await Promise.all(names.map((name) => readSandbox(name, defaultSandboxNames, registry)))
|
||||
const sandboxes = results.map((result) => result.summary)
|
||||
const items = results.map((result) => result.pod)
|
||||
const nemoclaw = buildNemoClawSummary(nemoclawStatusResult?.stdout ?? null, defaultSandboxNames)
|
||||
|
||||
Reference in New Issue
Block a user