Improve dashboard portability and installer smoke checks
This commit is contained in:
@@ -1,28 +1,9 @@
|
||||
import { NextResponse } from "next/server"
|
||||
import { execFile } from "node:child_process"
|
||||
import { existsSync } from "node:fs"
|
||||
import { promisify } from "node:util"
|
||||
import { HOST_PATH, OPENSHELL_BIN } from "@/app/lib/hostCommands"
|
||||
|
||||
const execFileAsync = promisify(execFile)
|
||||
const HOME = process.env.HOME || ""
|
||||
const OPENSHELL_BIN_CANDIDATES = [
|
||||
process.env.OPENSHELL_BIN,
|
||||
HOME ? `${HOME}/.local/bin/openshell` : undefined,
|
||||
"/usr/local/bin/openshell",
|
||||
"/opt/homebrew/bin/openshell",
|
||||
].filter((value): value is string => Boolean(value))
|
||||
const OPENSHELL_BIN =
|
||||
OPENSHELL_BIN_CANDIDATES.find((candidate) => existsSync(candidate)) ?? OPENSHELL_BIN_CANDIDATES[0]
|
||||
const HOST_PATH = [
|
||||
`${HOME}/.local/bin`,
|
||||
`${HOME}/.nvm/versions/node/v22.22.2/bin`,
|
||||
`${HOME}/.nvm/versions/node/v22.22.1/bin`,
|
||||
"/usr/local/bin",
|
||||
"/opt/homebrew/bin",
|
||||
"/usr/bin",
|
||||
"/bin",
|
||||
process.env.PATH || "",
|
||||
].filter(Boolean).join(":")
|
||||
|
||||
const PROVIDER_TYPES = new Set(["openai", "anthropic", "nvidia", "generic", "claude", "opencode", "codex", "copilot", "gitlab", "github", "outlook"])
|
||||
|
||||
|
||||
@@ -8,6 +8,15 @@ const TERMINAL_WS_PROXY_PORT = process.env.TERMINAL_WS_PROXY_PORT || ''
|
||||
const PUBLIC_BROWSER_HOST = process.env.PUBLIC_BROWSER_HOST || process.env.PUBLIC_WS_HOST || null
|
||||
const PUBLIC_BASE_URL = process.env.PUBLIC_BASE_URL || null
|
||||
|
||||
function describeTerminalServerError(error: unknown, terminalServerUrl: string) {
|
||||
const message = error instanceof Error ? error.message : String(error || 'unknown error')
|
||||
const cause = error instanceof Error && error.cause instanceof Error ? ` (${error.cause.message})` : ''
|
||||
if (/fetch failed|ECONNREFUSED|ENOTFOUND|EHOSTUNREACH|UND_ERR_SOCKET/i.test(`${message} ${cause}`)) {
|
||||
return `Could not reach the operator terminal bridge at ${terminalServerUrl}. Restart the dashboard so it can auto-start the local bridge, or run npm run terminal-server in this repo. Details: ${message}${cause}`
|
||||
}
|
||||
return message
|
||||
}
|
||||
|
||||
function isNonRoutableHost(candidate: string, protocol = 'http:') {
|
||||
const normalized = candidate.trim()
|
||||
if (!normalized) return true
|
||||
@@ -115,18 +124,26 @@ export async function POST(request: Request) {
|
||||
const terminalServerUrl = authority.terminalServerUrl || TERMINAL_SERVER_URL
|
||||
const resolvedSandboxId = authority.resolvedSandboxId || requestedSandboxId
|
||||
|
||||
const response = await fetch(`${terminalServerUrl}/session`, {
|
||||
method: 'POST',
|
||||
headers: {
|
||||
'Content-Type': 'application/json',
|
||||
},
|
||||
body: JSON.stringify({
|
||||
sandboxId: resolvedSandboxId,
|
||||
sessionId,
|
||||
dashboardSessionId,
|
||||
}),
|
||||
cache: 'no-store',
|
||||
})
|
||||
let response: Response
|
||||
try {
|
||||
response = await fetch(`${terminalServerUrl}/session`, {
|
||||
method: 'POST',
|
||||
headers: {
|
||||
'Content-Type': 'application/json',
|
||||
},
|
||||
body: JSON.stringify({
|
||||
sandboxId: resolvedSandboxId,
|
||||
sessionId,
|
||||
dashboardSessionId,
|
||||
}),
|
||||
cache: 'no-store',
|
||||
})
|
||||
} catch (error) {
|
||||
return NextResponse.json({
|
||||
ok: false,
|
||||
error: describeTerminalServerError(error, terminalServerUrl),
|
||||
}, { status: 502 })
|
||||
}
|
||||
|
||||
const result = await response.json()
|
||||
if (!response.ok) {
|
||||
|
||||
@@ -2,23 +2,9 @@ import { NextResponse } from "next/server"
|
||||
import { execFile, spawn } from "node:child_process"
|
||||
import { promisify } from "node:util"
|
||||
import { inspectSandbox } from "@/app/lib/openshellHost"
|
||||
import { commandExists, HOST_PATH, NEMOCLAW_SETUP, OPENSHELL_BIN } from "@/app/lib/hostCommands"
|
||||
|
||||
const execFileAsync = promisify(execFile)
|
||||
const HOME = process.env.HOME || ""
|
||||
const NEMOCLAW_SETUP = process.env.NEMOCLAW_SETUP || `${HOME}/NemoClaw/scripts/setup.sh`
|
||||
const OPENSHELL_BIN = process.env.OPENSHELL_BIN || `${HOME}/.local/bin/openshell`
|
||||
const HOST_PATH = [
|
||||
`${HOME}/.local/bin`,
|
||||
`${HOME}/.nvm/versions/node/v22.22.2/bin`,
|
||||
`${HOME}/.nvm/versions/node/v22.22.1/bin`,
|
||||
"/opt/homebrew/bin",
|
||||
"/usr/local/bin",
|
||||
"/usr/bin",
|
||||
"/bin",
|
||||
"/usr/sbin",
|
||||
"/sbin",
|
||||
process.env.PATH || "",
|
||||
].filter(Boolean).join(":")
|
||||
|
||||
function validateSandboxName(name: string) {
|
||||
if (!name || typeof name !== "string") throw new Error("sandbox name is required")
|
||||
@@ -55,6 +41,13 @@ function appendNote(...parts: Array<string | false | null | undefined>) {
|
||||
return parts.filter(Boolean).join(" ")
|
||||
}
|
||||
|
||||
function requireNemoClawSetup() {
|
||||
if (NEMOCLAW_SETUP && commandExists(NEMOCLAW_SETUP)) return NEMOCLAW_SETUP
|
||||
throw new Error(
|
||||
"NemoClaw blueprint setup script was not found. Install NemoClaw on this host or set NEMOCLAW_SETUP in .env.local to the absolute path of scripts/setup.sh.",
|
||||
)
|
||||
}
|
||||
|
||||
async function verifySandboxCreation(sandboxName: string): Promise<SandboxVerification> {
|
||||
const startedAt = Date.now()
|
||||
console.log(`[sandbox/create] verify:start sandbox=${sandboxName}`)
|
||||
@@ -320,6 +313,7 @@ export async function POST(request: Request) {
|
||||
}
|
||||
|
||||
if (blueprint === "nemoclaw-blueprint") {
|
||||
const setupPath = requireNemoClawSetup()
|
||||
const env: NodeJS.ProcessEnv = {
|
||||
...process.env,
|
||||
PATH: HOST_PATH,
|
||||
@@ -330,7 +324,7 @@ export async function POST(request: Request) {
|
||||
env.NVIDIA_API_KEY = env.NVIDIA_API_KEY || "optional-local-mode"
|
||||
}
|
||||
|
||||
const result = await runCommand("/bin/bash", [NEMOCLAW_SETUP, sandboxName], env)
|
||||
const result = await runCommand("/bin/bash", [setupPath, sandboxName], env)
|
||||
|
||||
if (!result.ok) {
|
||||
return NextResponse.json({
|
||||
@@ -365,7 +359,7 @@ export async function POST(request: Request) {
|
||||
verification,
|
||||
mode: "nemoclaw-blueprint",
|
||||
enableTailscale,
|
||||
setupPath: NEMOCLAW_SETUP,
|
||||
setupPath,
|
||||
hostPath: HOST_PATH,
|
||||
readiness: {
|
||||
attempts: readiness.attempts,
|
||||
|
||||
@@ -2,23 +2,9 @@ import { NextResponse } from "next/server"
|
||||
import { execFile } from "node:child_process"
|
||||
import { promisify } from "node:util"
|
||||
import { resolveSandboxRef } from "@/app/lib/openshellHost"
|
||||
import { HOST_PATH, NEMOCLAW_BIN, NEMOCLAW_CWD, OPENSHELL_BIN } from "@/app/lib/hostCommands"
|
||||
|
||||
const execFileAsync = promisify(execFile)
|
||||
const HOME = process.env.HOME || ""
|
||||
const OPENSHELL_BIN = process.env.OPENSHELL_BIN || `${HOME}/.local/bin/openshell`
|
||||
const NEMOCLAW_BIN = process.env.NEMOCLAW_BIN || `${HOME}/NemoClaw/bin/nemoclaw.js`
|
||||
const HOST_PATH = [
|
||||
`${HOME}/.local/bin`,
|
||||
`${HOME}/.nvm/versions/node/v22.22.2/bin`,
|
||||
`${HOME}/.nvm/versions/node/v22.22.1/bin`,
|
||||
"/opt/homebrew/bin",
|
||||
"/usr/local/bin",
|
||||
"/usr/bin",
|
||||
"/bin",
|
||||
"/usr/sbin",
|
||||
"/sbin",
|
||||
process.env.PATH || "",
|
||||
].filter(Boolean).join(":")
|
||||
|
||||
function elapsedMs(start: number) {
|
||||
return Date.now() - start
|
||||
@@ -106,7 +92,7 @@ async function cleanupNemoClawSandbox(sandboxName: string) {
|
||||
console.log(`[sandbox/delete] nemoclaw-cleanup:start sandbox=${sandboxName}`)
|
||||
try {
|
||||
const { stdout, stderr } = await execFileAsync(NEMOCLAW_BIN, [sandboxName, "destroy", "--yes"], {
|
||||
cwd: `${HOME}/NemoClaw`,
|
||||
cwd: NEMOCLAW_CWD,
|
||||
env: {
|
||||
...process.env,
|
||||
PATH: HOST_PATH,
|
||||
|
||||
@@ -3,6 +3,7 @@ import { promisify } from "node:util"
|
||||
import { NextResponse } from "next/server"
|
||||
import { listActivity } from "@/app/lib/activityLog"
|
||||
import { listBackupCatalog } from "@/app/lib/backupCatalog"
|
||||
import { HOST_PATH, OPENSHELL_BIN } from "@/app/lib/hostCommands"
|
||||
|
||||
const execFileAsync = promisify(execFile)
|
||||
|
||||
@@ -12,7 +13,7 @@ async function run(command: string, args: string[]) {
|
||||
try {
|
||||
const { stdout, stderr } = await execFileAsync(command, args, {
|
||||
timeout: 10000,
|
||||
env: { ...process.env, NO_COLOR: "1", CLICOLOR: "0", CLICOLOR_FORCE: "0" },
|
||||
env: { ...process.env, PATH: HOST_PATH, NO_COLOR: "1", CLICOLOR: "0", CLICOLOR_FORCE: "0" },
|
||||
})
|
||||
return { ok: true, stdout: stdout.trim(), stderr: stderr.trim() }
|
||||
} catch (error) {
|
||||
@@ -28,7 +29,7 @@ export async function GET() {
|
||||
const [gitHead, gitStatus, sandboxList, activity, backups] = await Promise.all([
|
||||
run("git", ["rev-parse", "--short", "HEAD"]),
|
||||
run("git", ["status", "--short", "--branch"]),
|
||||
run(process.env.OPENSHELL_BIN || `${process.env.HOME || ""}/.local/bin/openshell`, ["sandbox", "list"]),
|
||||
run(OPENSHELL_BIN, ["sandbox", "list"]),
|
||||
listActivity(75),
|
||||
listBackupCatalog(),
|
||||
])
|
||||
|
||||
@@ -1,55 +1,12 @@
|
||||
import { NextResponse } from "next/server"
|
||||
import { execFile } from "node:child_process"
|
||||
import { existsSync } from "node:fs"
|
||||
import { hostname, networkInterfaces } from "node:os"
|
||||
import { promisify } from "node:util"
|
||||
import { HOST_PATH, NEMOCLAW_BIN, NODE_BIN, OPENSHELL_BIN } from "@/app/lib/hostCommands"
|
||||
import { resolveRuntimeAuthority } from "@/app/lib/runtimeAuthority"
|
||||
|
||||
const execFileAsync = promisify(execFile)
|
||||
|
||||
const HOME = process.env.HOME || ""
|
||||
|
||||
const NODE_BIN_CANDIDATES = [
|
||||
process.env.NODE_BIN,
|
||||
HOME ? `${HOME}/.nvm/versions/node/v22.22.2/bin/node` : undefined,
|
||||
HOME ? `${HOME}/.nvm/versions/node/v22.22.1/bin/node` : undefined,
|
||||
"/Users/markmckeen/.nvm/versions/node/v22.22.2/bin/node",
|
||||
"/Users/markmckeen/.nvm/versions/node/v22.22.1/bin/node",
|
||||
"/opt/homebrew/bin/node",
|
||||
"/usr/local/bin/node",
|
||||
"/usr/bin/node",
|
||||
].filter((value): value is string => Boolean(value))
|
||||
const NODE_BIN = NODE_BIN_CANDIDATES.find((candidate) => existsSync(candidate)) ?? NODE_BIN_CANDIDATES[0]
|
||||
const NEMOCLAW_BIN_CANDIDATES = [
|
||||
process.env.NEMOCLAW_BIN,
|
||||
HOME ? `${HOME}/.local/bin/nemoclaw` : undefined,
|
||||
HOME ? `${HOME}/.nemoclaw/source/bin/nemoclaw.js` : undefined,
|
||||
HOME ? `${HOME}/NemoClaw/bin/nemoclaw.js` : undefined,
|
||||
HOME ? `${HOME}/.nvm/versions/node/v22.22.2/bin/nemoclaw` : undefined,
|
||||
"/Users/markmckeen/.local/bin/nemoclaw",
|
||||
"/Users/markmckeen/.nemoclaw/source/bin/nemoclaw.js",
|
||||
"/Users/markmckeen/NemoClaw/bin/nemoclaw.js",
|
||||
"/Users/markmckeen/NemoClaw-mmckeen/bin/nemoclaw.js",
|
||||
"/Users/markmckeen/.nvm/versions/node/v22.22.2/bin/nemoclaw",
|
||||
"/usr/local/bin/nemoclaw",
|
||||
"/opt/homebrew/bin/nemoclaw",
|
||||
].filter((value): value is string => Boolean(value))
|
||||
const NEMOCLAW_BIN =
|
||||
NEMOCLAW_BIN_CANDIDATES.find((candidate) => existsSync(candidate)) ?? NEMOCLAW_BIN_CANDIDATES[0]
|
||||
|
||||
const OPENSHELL_BIN_CANDIDATES = [
|
||||
process.env.OPENSHELL_BIN,
|
||||
HOME ? `${HOME}/.local/bin/openshell` : undefined,
|
||||
"/Users/markmckeen/.local/bin/openshell",
|
||||
"/Users/markmckeen/OpenShell/target/release/openshell",
|
||||
"/Users/markmckeen/openshell/target/release/openshell",
|
||||
"/Users/markmckeen/openshell/scripts/bin/openshell",
|
||||
"/usr/local/bin/openshell",
|
||||
"/opt/homebrew/bin/openshell",
|
||||
].filter((value): value is string => Boolean(value))
|
||||
const OPENSHELL_BIN =
|
||||
OPENSHELL_BIN_CANDIDATES.find((candidate) => existsSync(candidate)) ?? OPENSHELL_BIN_CANDIDATES[0]
|
||||
|
||||
type SandboxSummary = {
|
||||
id: string
|
||||
name: string
|
||||
@@ -191,7 +148,7 @@ function buildNemoClawSummary(output: string | null, defaultSandboxNames: Set<st
|
||||
async function execNemoclaw(args: string[]) {
|
||||
const env = {
|
||||
...process.env,
|
||||
PATH: `${process.env.PATH ?? ""}:${HOME ? `${HOME}/.local/bin:${HOME}/.nvm/versions/node/v22.22.2/bin:${HOME}/.nvm/versions/node/v22.22.1/bin:` : ""}/opt/homebrew/bin:/usr/local/bin:/usr/bin`,
|
||||
PATH: HOST_PATH,
|
||||
NO_COLOR: "1",
|
||||
CLICOLOR: "0",
|
||||
CLICOLOR_FORCE: "0",
|
||||
@@ -209,6 +166,7 @@ async function execOpenShell(args: string[]) {
|
||||
const { stdout, stderr } = await execFileAsync(OPENSHELL_BIN, args, {
|
||||
env: {
|
||||
...process.env,
|
||||
PATH: HOST_PATH,
|
||||
NO_COLOR: "1",
|
||||
CLICOLOR: "0",
|
||||
CLICOLOR_FORCE: "0",
|
||||
|
||||
Reference in New Issue
Block a user