Merge pull request #10 from mmckeen-nv/codex/sandbox-dashboard-token-fallback
[codex] Add sandbox dashboard token fallback
This commit is contained in:
@@ -263,6 +263,37 @@ function rewriteDashboardBootstrapOrigin(bootstrapUrl: string, dashboardUrl: str
|
||||
return bootstrap.toString()
|
||||
}
|
||||
|
||||
function normalizeDashboardToken(value: string | null | undefined) {
|
||||
const token = value?.trim() || ''
|
||||
if (!token || /\s/.test(token)) return null
|
||||
return token
|
||||
}
|
||||
|
||||
function withDashboardToken(bootstrapUrl: string, token: string | null) {
|
||||
if (!token || hasDashboardToken(bootstrapUrl)) return bootstrapUrl
|
||||
try {
|
||||
const parsed = new URL(bootstrapUrl)
|
||||
const hashParams = new URLSearchParams(parsed.hash.startsWith('#') ? parsed.hash.slice(1) : parsed.hash)
|
||||
hashParams.set('token', token)
|
||||
parsed.hash = hashParams.toString()
|
||||
return parsed.toString()
|
||||
} catch {
|
||||
const separator = bootstrapUrl.includes('#') ? '&' : '#'
|
||||
return `${bootstrapUrl}${separator}token=${encodeURIComponent(token)}`
|
||||
}
|
||||
}
|
||||
|
||||
async function readSandboxOpenClawDashboardToken(sandboxName: string) {
|
||||
const script = [
|
||||
'const fs=require("fs")',
|
||||
'const cfg=JSON.parse(fs.readFileSync("/sandbox/.openclaw/openclaw.json","utf8"))',
|
||||
'const token=cfg?.gateway?.auth?.token||cfg?.gateway?.token||""',
|
||||
'if(token) process.stdout.write(String(token))',
|
||||
].join(';')
|
||||
const { stdout } = await execSandboxSsh(sandboxName, `node -e '${script}'`, 5000)
|
||||
return normalizeDashboardToken(stdout)
|
||||
}
|
||||
|
||||
export async function resolveOpenClawDashboardBootstrap(instanceId?: string | null) {
|
||||
const instance = resolveOpenClawInstance(instanceId)
|
||||
const defaultInstance = getDefaultOpenClawInstance()
|
||||
@@ -277,11 +308,19 @@ export async function resolveOpenClawDashboardBootstrap(instanceId?: string | nu
|
||||
const bootstrapUrl = rawBootstrapUrl
|
||||
? rewriteDashboardBootstrapOrigin(rawBootstrapUrl, instance.dashboardUrl)
|
||||
: null
|
||||
const bootstrapTokenPresent = hasDashboardToken(bootstrapUrl)
|
||||
let tokenizedBootstrapUrl = bootstrapUrl
|
||||
let bootstrapTokenPresent = hasDashboardToken(tokenizedBootstrapUrl)
|
||||
|
||||
if (bootstrapUrl) {
|
||||
if (tokenizedBootstrapUrl && !bootstrapTokenPresent) {
|
||||
await execSandboxSsh(sandboxInstance.sandboxId, 'openclaw dashboard', 15000).catch(() => null)
|
||||
const token = await readSandboxOpenClawDashboardToken(sandboxInstance.sandboxId).catch(() => null)
|
||||
tokenizedBootstrapUrl = withDashboardToken(tokenizedBootstrapUrl, token)
|
||||
bootstrapTokenPresent = hasDashboardToken(tokenizedBootstrapUrl)
|
||||
}
|
||||
|
||||
if (tokenizedBootstrapUrl) {
|
||||
return {
|
||||
bootstrapUrl,
|
||||
bootstrapUrl: tokenizedBootstrapUrl,
|
||||
bootstrapTokenPresent,
|
||||
bootstrapSource: 'openclaw-cli' as const,
|
||||
bootstrapAuthority: bootstrapTokenPresent ? ('tokenized-cli' as const) : ('static-fallback' as const),
|
||||
|
||||
@@ -51,6 +51,9 @@ assert.match(terminalReadinessSource, /const authority = resolveRuntimeAuthority
|
||||
assert.match(telemetrySource, /authoritySource: "runtimeAuthority"/, 'inventory route must declare shared authority source')
|
||||
assert.match(telemetrySource, /authorities: authorities\.map\(/, 'inventory route must expose per-sandbox authority metadata')
|
||||
assert.match(openshellHostSource, /const canMintBootstrapFromCli = instance\.id === defaultInstance\.id/, 'bootstrap minting should only use CLI for the default OpenClaw instance')
|
||||
assert.match(openshellHostSource, /readSandboxOpenClawDashboardToken/, 'sandbox dashboard bootstrap must fall back to the sandbox OpenClaw token when CLI output is bare')
|
||||
assert.match(openshellHostSource, /openclaw dashboard', 15000\)\.catch/, 'sandbox dashboard bootstrap should let OpenClaw initialize before reading the fallback token')
|
||||
assert.match(openshellHostSource, /withDashboardToken\(tokenizedBootstrapUrl, token\)/, 'sandbox dashboard bootstrap should synthesize a tokenized launch URL from the fallback token')
|
||||
assert.match(packageJsonSource, /"dev": "node server\.mjs"/, 'development script must run through the custom server so websocket proxy bridges are active')
|
||||
assert.match(serverSource, /const dashboardWsProxyServer = http\.createServer/, 'custom server must provision a dedicated dashboard websocket sidecar')
|
||||
assert.match(serverSource, /dashboard-sidecar-listening/, 'custom server must expose the dashboard websocket sidecar listener')
|
||||
|
||||
Reference in New Issue
Block a user