feat: add backend-local OpenShell host helpers
- execute Docker/Kubectl from dashboard backend on host - add dashboard open endpoint and terminal probe endpoint - wire sandbox action buttons to backend-local helpers
This commit is contained in:
@@ -0,0 +1,13 @@
|
|||||||
|
import { NextResponse } from 'next/server'
|
||||||
|
import { getOpenClawDashboardUrl } from '../../../../lib/openshellHost'
|
||||||
|
|
||||||
|
export async function GET() {
|
||||||
|
const dashboardUrl = getOpenClawDashboardUrl()
|
||||||
|
return NextResponse.json({
|
||||||
|
ok: true,
|
||||||
|
dashboardUrl,
|
||||||
|
openInNewTab: true,
|
||||||
|
loopbackOnly: true,
|
||||||
|
note: 'OpenClaw Dashboard is loopback-only on the host. For remote browser access, add a reverse proxy route or rebind the gateway.'
|
||||||
|
})
|
||||||
|
}
|
||||||
@@ -0,0 +1,29 @@
|
|||||||
|
import { NextResponse } from 'next/server'
|
||||||
|
import { probeSandboxShell } from '../../../../lib/openshellHost'
|
||||||
|
|
||||||
|
export async function GET(request: Request) {
|
||||||
|
try {
|
||||||
|
const { searchParams } = new URL(request.url)
|
||||||
|
const sandboxId = searchParams.get('sandboxId')
|
||||||
|
|
||||||
|
if (!sandboxId) {
|
||||||
|
return NextResponse.json({ error: 'sandboxId is required' }, { status: 400 })
|
||||||
|
}
|
||||||
|
|
||||||
|
const result = await probeSandboxShell(sandboxId)
|
||||||
|
|
||||||
|
return NextResponse.json({
|
||||||
|
ok: true,
|
||||||
|
sandboxId,
|
||||||
|
attached: true,
|
||||||
|
output: result.stdout.trim(),
|
||||||
|
stderr: result.stderr.trim(),
|
||||||
|
note: 'Backend-local terminal probe succeeded. Next step is persistent interactive terminal transport.'
|
||||||
|
})
|
||||||
|
} catch (error) {
|
||||||
|
return NextResponse.json({
|
||||||
|
ok: false,
|
||||||
|
error: error instanceof Error ? error.message : 'Failed to probe terminal attach'
|
||||||
|
}, { status: 500 })
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -178,11 +178,14 @@ export default function SandboxList({
|
|||||||
<button
|
<button
|
||||||
onClick={async () => {
|
onClick={async () => {
|
||||||
try {
|
try {
|
||||||
const res = await fetch('/api/openshell/dashboard')
|
const res = await fetch('/api/openshell/dashboard/open')
|
||||||
const data = await res.json()
|
const data = await res.json()
|
||||||
setDashboardMessage(data.loopbackOnly
|
setDashboardMessage(data.loopbackOnly
|
||||||
? `OpenClaw Dashboard detected at ${data.dashboardUrl}. It is loopback-only, so the next step is adding a proxy/open-in-new-tab bridge.`
|
? `OpenClaw Dashboard detected at ${data.dashboardUrl}. It is loopback-only, so the next step is adding a proxy/open-in-new-tab bridge.`
|
||||||
: `OpenClaw Dashboard: ${data.dashboardUrl}`)
|
: `OpenClaw Dashboard: ${data.dashboardUrl}`)
|
||||||
|
if (data.dashboardUrl) {
|
||||||
|
window.open(data.dashboardUrl, '_blank', 'noopener,noreferrer')
|
||||||
|
}
|
||||||
} catch (error) {
|
} catch (error) {
|
||||||
setDashboardMessage('Failed to resolve OpenClaw Dashboard endpoint.')
|
setDashboardMessage('Failed to resolve OpenClaw Dashboard endpoint.')
|
||||||
}
|
}
|
||||||
@@ -194,9 +197,13 @@ export default function SandboxList({
|
|||||||
<button
|
<button
|
||||||
onClick={async () => {
|
onClick={async () => {
|
||||||
try {
|
try {
|
||||||
const res = await fetch(`/api/openshell/terminal?sandboxId=${encodeURIComponent(selectedSandbox)}`)
|
const res = await fetch(`/api/openshell/terminal/open?sandboxId=${encodeURIComponent(selectedSandbox)}`)
|
||||||
const data = await res.json()
|
const data = await res.json()
|
||||||
setTerminalMessage(data.note || 'Terminal attach route reached.')
|
if (data.ok) {
|
||||||
|
setTerminalMessage(`Terminal probe succeeded for ${selectedSandbox}: ${data.output || 'attached'}`)
|
||||||
|
} else {
|
||||||
|
setTerminalMessage(data.error || 'Failed to attach to OpenShell terminal.')
|
||||||
|
}
|
||||||
} catch (error) {
|
} catch (error) {
|
||||||
setTerminalMessage('Failed to attach to OpenShell terminal.')
|
setTerminalMessage('Failed to attach to OpenShell terminal.')
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -0,0 +1,32 @@
|
|||||||
|
import { execFile } from 'node:child_process'
|
||||||
|
import { promisify } from 'node:util'
|
||||||
|
|
||||||
|
const execFileAsync = promisify(execFile)
|
||||||
|
|
||||||
|
const DOCKER_BIN = '/Applications/Docker.app/Contents/Resources/bin/docker'
|
||||||
|
const OPENSHELL_CONTAINER = 'openshell-cluster-openshell'
|
||||||
|
const OPENSHELL_NAMESPACE = 'agent-sandbox-system'
|
||||||
|
const OPENCLAW_DASHBOARD_URL = 'http://127.0.0.1:18789/'
|
||||||
|
|
||||||
|
export async function dockerExecInOpenShell(command: string) {
|
||||||
|
const { stdout, stderr } = await execFileAsync(DOCKER_BIN, [
|
||||||
|
'exec',
|
||||||
|
OPENSHELL_CONTAINER,
|
||||||
|
'sh',
|
||||||
|
'-lc',
|
||||||
|
command,
|
||||||
|
])
|
||||||
|
return { stdout, stderr }
|
||||||
|
}
|
||||||
|
|
||||||
|
export async function probeSandboxShell(podName: string) {
|
||||||
|
return dockerExecInOpenShell(
|
||||||
|
`kubectl -n ${OPENSHELL_NAMESPACE} exec ${podName} -- sh -lc 'echo OPENSHELL_OK && pwd && whoami'`
|
||||||
|
)
|
||||||
|
}
|
||||||
|
|
||||||
|
export function getOpenClawDashboardUrl() {
|
||||||
|
return OPENCLAW_DASHBOARD_URL
|
||||||
|
}
|
||||||
|
|
||||||
|
export { DOCKER_BIN, OPENSHELL_CONTAINER, OPENSHELL_NAMESPACE }
|
||||||
Reference in New Issue
Block a user