Improve dashboard portability and installer smoke checks
This commit is contained in:
@@ -10,6 +10,10 @@ function quoteEnvValue(value: string) {
|
||||
return JSON.stringify(value)
|
||||
}
|
||||
|
||||
function envKeyMatcher(key: string) {
|
||||
return new RegExp(`^\\s*(?:export\\s+)?${key}\\s*=`)
|
||||
}
|
||||
|
||||
async function readEnvFile() {
|
||||
if (!existsSync(ENV_PATH)) return ""
|
||||
return readFile(ENV_PATH, "utf8")
|
||||
@@ -17,9 +21,22 @@ async function readEnvFile() {
|
||||
|
||||
function upsertEnv(content: string, key: string, value: string) {
|
||||
const line = `${key}=${quoteEnvValue(value)}`
|
||||
const matcher = new RegExp(`^${key}=.*$`, "m")
|
||||
if (matcher.test(content)) return content.replace(matcher, line)
|
||||
return `${content.trimEnd()}${content.trim() ? "\n" : ""}${line}\n`
|
||||
const matcher = envKeyMatcher(key)
|
||||
const lines = content.split(/\r?\n/)
|
||||
let replaced = false
|
||||
const nextLines = lines.filter((existingLine) => {
|
||||
if (!matcher.test(existingLine)) return true
|
||||
if (replaced) return false
|
||||
replaced = true
|
||||
return true
|
||||
}).map((existingLine) => (matcher.test(existingLine) ? line : existingLine))
|
||||
|
||||
if (!replaced) {
|
||||
const trimmed = content.trimEnd()
|
||||
return `${trimmed}${trimmed ? "\n" : ""}${line}\n`
|
||||
}
|
||||
|
||||
return `${nextLines.join("\n").trimEnd()}\n`
|
||||
}
|
||||
|
||||
export function generateToken(bytes = 24) {
|
||||
|
||||
@@ -0,0 +1,79 @@
|
||||
import { existsSync } from "node:fs"
|
||||
import path from "node:path"
|
||||
|
||||
const HOME = process.env.HOME || ""
|
||||
|
||||
function firstExisting(candidates: Array<string | undefined>, fallback: string) {
|
||||
return candidates.filter((value): value is string => Boolean(value)).find((candidate) => existsSync(candidate)) || fallback
|
||||
}
|
||||
|
||||
function pathEntries() {
|
||||
return [
|
||||
process.env.TERMINAL_EXTRA_PATH,
|
||||
HOME ? path.join(HOME, ".local/bin") : undefined,
|
||||
HOME ? path.join(HOME, ".nvm/versions/node/v22.22.2/bin") : undefined,
|
||||
HOME ? path.join(HOME, ".nvm/versions/node/v22.22.1/bin") : undefined,
|
||||
HOME ? path.join(HOME, ".nemoclaw/source/node_modules/.bin") : undefined,
|
||||
HOME ? path.join(HOME, "NemoClaw/node_modules/.bin") : undefined,
|
||||
"/opt/homebrew/bin",
|
||||
"/usr/local/bin",
|
||||
"/usr/bin",
|
||||
"/bin",
|
||||
"/usr/sbin",
|
||||
"/sbin",
|
||||
process.env.PATH,
|
||||
].filter((value): value is string => Boolean(value))
|
||||
}
|
||||
|
||||
export const HOST_PATH = Array.from(new Set(pathEntries())).join(":")
|
||||
|
||||
export const NODE_BIN = firstExisting([
|
||||
process.env.NODE_BIN,
|
||||
HOME ? path.join(HOME, ".nvm/versions/node/v22.22.2/bin/node") : undefined,
|
||||
HOME ? path.join(HOME, ".nvm/versions/node/v22.22.1/bin/node") : undefined,
|
||||
"/opt/homebrew/bin/node",
|
||||
"/usr/local/bin/node",
|
||||
"/usr/bin/node",
|
||||
], "node")
|
||||
|
||||
export const OPENSHELL_BIN = firstExisting([
|
||||
process.env.OPENSHELL_BIN,
|
||||
HOME ? path.join(HOME, ".local/bin/openshell") : undefined,
|
||||
"/opt/homebrew/bin/openshell",
|
||||
"/usr/local/bin/openshell",
|
||||
], "openshell")
|
||||
|
||||
export const OPENCLAW_BIN = firstExisting([
|
||||
process.env.OPENCLAW_BIN,
|
||||
HOME ? path.join(HOME, ".local/bin/openclaw") : undefined,
|
||||
HOME ? path.join(HOME, ".nemoclaw/source/node_modules/.bin/openclaw") : undefined,
|
||||
HOME ? path.join(HOME, "NemoClaw/node_modules/.bin/openclaw") : undefined,
|
||||
"/opt/homebrew/bin/openclaw",
|
||||
"/usr/local/bin/openclaw",
|
||||
], "openclaw")
|
||||
|
||||
export const NEMOCLAW_BIN = firstExisting([
|
||||
process.env.NEMOCLAW_BIN,
|
||||
HOME ? path.join(HOME, ".local/bin/nemoclaw") : undefined,
|
||||
HOME ? path.join(HOME, ".nemoclaw/source/bin/nemoclaw.js") : undefined,
|
||||
HOME ? path.join(HOME, "NemoClaw/bin/nemoclaw.js") : undefined,
|
||||
HOME ? path.join(HOME, ".nvm/versions/node/v22.22.2/bin/nemoclaw") : undefined,
|
||||
"/opt/homebrew/bin/nemoclaw",
|
||||
"/usr/local/bin/nemoclaw",
|
||||
], "nemoclaw")
|
||||
|
||||
export const NEMOCLAW_SETUP = firstExisting([
|
||||
process.env.NEMOCLAW_SETUP,
|
||||
HOME ? path.join(HOME, ".nemoclaw/source/scripts/setup.sh") : undefined,
|
||||
HOME ? path.join(HOME, "NemoClaw/scripts/setup.sh") : undefined,
|
||||
], "")
|
||||
|
||||
export const NEMOCLAW_CWD = firstExisting([
|
||||
process.env.NEMOCLAW_CWD,
|
||||
HOME ? path.join(HOME, ".nemoclaw/source") : undefined,
|
||||
HOME ? path.join(HOME, "NemoClaw") : undefined,
|
||||
], process.cwd())
|
||||
|
||||
export function commandExists(command: string) {
|
||||
return command.includes("/") ? existsSync(command) : true
|
||||
}
|
||||
@@ -1,33 +1,9 @@
|
||||
import { execFile, spawn } from "node:child_process"
|
||||
import { existsSync } from "node:fs"
|
||||
import { promisify } from "node:util"
|
||||
import { HOST_PATH, OPENCLAW_BIN, OPENSHELL_BIN } from "./hostCommands"
|
||||
import { getDefaultOpenClawInstance, getOpenClawDashboardPortForSandbox, resolveOpenClawInstance } from "./openclawInstances"
|
||||
|
||||
const execFileAsync = promisify(execFile)
|
||||
|
||||
const OPENSHELL_BIN_CANDIDATES = [
|
||||
process.env.OPENSHELL_BIN,
|
||||
process.env.HOME ? `${process.env.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 OPENCLAW_BIN_CANDIDATES = [
|
||||
process.env.OPENCLAW_BIN,
|
||||
process.env.HOME ? `${process.env.HOME}/NemoClaw/node_modules/.bin/openclaw` : undefined,
|
||||
process.env.HOME ? `${process.env.HOME}/.local/bin/openclaw` : undefined,
|
||||
"/usr/local/bin/openclaw",
|
||||
"/opt/homebrew/bin/openclaw",
|
||||
].filter((value): value is string => Boolean(value))
|
||||
|
||||
const OPENSHELL_BIN =
|
||||
OPENSHELL_BIN_CANDIDATES.find((candidate) => existsSync(candidate)) ?? OPENSHELL_BIN_CANDIDATES[0]
|
||||
const OPENCLAW_BIN =
|
||||
OPENCLAW_BIN_CANDIDATES.find((candidate) => existsSync(candidate)) ?? OPENCLAW_BIN_CANDIDATES[0] ?? "openclaw"
|
||||
const OPENSHELL_GATEWAY = process.env.OPENSHELL_GATEWAY || "openshell"
|
||||
const OPENSHELL_NAMESPACE = "agent-sandbox-system"
|
||||
const SANDBOX_DASHBOARD_REMOTE_PORT = Number.parseInt(process.env.OPENCLAW_SANDBOX_DASHBOARD_REMOTE_PORT || "18789", 10)
|
||||
@@ -70,6 +46,7 @@ export 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",
|
||||
@@ -80,9 +57,7 @@ export async function execOpenShell(args: string[]) {
|
||||
|
||||
function buildOpenClawEnv() {
|
||||
const pathEntries = [
|
||||
process.env.HOME ? `${process.env.HOME}/NemoClaw/node_modules/.bin` : null,
|
||||
process.env.HOME ? `${process.env.HOME}/.local/bin` : null,
|
||||
process.env.PATH,
|
||||
HOST_PATH,
|
||||
].filter(Boolean)
|
||||
|
||||
return {
|
||||
|
||||
+1
-12
@@ -1,19 +1,8 @@
|
||||
import { spawn } from "node:child_process"
|
||||
import path from "node:path"
|
||||
import { HOST_PATH, OPENSHELL_BIN } from "./hostCommands"
|
||||
import { resolveSandboxRef } from "./openshellHost"
|
||||
|
||||
const HOME = process.env.HOME || ""
|
||||
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`,
|
||||
"/usr/local/bin",
|
||||
"/usr/bin",
|
||||
"/bin",
|
||||
process.env.PATH || "",
|
||||
].filter(Boolean).join(":")
|
||||
|
||||
export const MAX_FILE_BYTES = Number.parseInt(process.env.SANDBOX_FILE_TRANSFER_MAX_BYTES || String(128 * 1024 * 1024), 10)
|
||||
export const MAX_MULTIPART_REQUEST_BYTES = MAX_FILE_BYTES + Math.min(10 * 1024 * 1024, Math.max(1024 * 1024, Math.floor(MAX_FILE_BYTES / 10)))
|
||||
const ALLOWED_ROOTS = ["/sandbox", "/tmp"]
|
||||
|
||||
@@ -1,21 +1,11 @@
|
||||
import { execFile, spawn } from "node:child_process"
|
||||
import { promisify } from "node:util"
|
||||
import { HOST_PATH, OPENSHELL_BIN } from "./hostCommands"
|
||||
import { getSandboxInferenceConfig, type SandboxInferenceRoute } from "./sandboxInferenceStore"
|
||||
|
||||
const execFileAsync = promisify(execFile)
|
||||
const HOME = process.env.HOME || ""
|
||||
const OPENSHELL_BIN = process.env.OPENSHELL_BIN || `${HOME}/.local/bin/openshell`
|
||||
const DOCKER_BIN = process.env.DOCKER_BIN || "docker"
|
||||
const OPENSHELL_CLUSTER_CONTAINER = process.env.OPENSHELL_CLUSTER_CONTAINER || "openshell-cluster-nemoclaw"
|
||||
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",
|
||||
"/usr/bin",
|
||||
"/bin",
|
||||
process.env.PATH || "",
|
||||
].filter(Boolean).join(":")
|
||||
|
||||
function modelEntry(route: SandboxInferenceRoute, openClawModelRef: string, compat: Record<string, unknown> | null) {
|
||||
return {
|
||||
|
||||
@@ -1,19 +1,9 @@
|
||||
import { execFile } from "node:child_process"
|
||||
import { promisify } from "node:util"
|
||||
import { HOST_PATH, OPENSHELL_BIN } from "./hostCommands"
|
||||
import { resolveSandboxRef } from "./openshellHost"
|
||||
|
||||
const execFileAsync = promisify(execFile)
|
||||
const HOME = process.env.HOME || ""
|
||||
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`,
|
||||
"/usr/local/bin",
|
||||
"/usr/bin",
|
||||
"/bin",
|
||||
process.env.PATH || "",
|
||||
].filter(Boolean).join(":")
|
||||
|
||||
export type SandboxNetworkRule = {
|
||||
chunkId: string
|
||||
|
||||
Reference in New Issue
Block a user