Skip to content

armgit / raea

Public Imported from GitHub
0

Render Anything Engine: tell your AI what to make. Videos, motion graphics, 3D and games as React and TypeScript, rendered on your own GPU. Rust + Bevy, macOS, Linux and Windows.

raea cloud's Google sign-in can run in a browser on the box, which the person works from the dashboard: Chrome on a virtual display of its own (google-screen.ts), its profile in the sign-in's folder so the Google session goes with it, served over VNC on WS /v1/google-token/ID/screen. Google's last step lands on Antigravity's listener on the box, so the sign-in finishes with nothing pasted; POST /v1/google-token/ID with no address waits for it ({pending} after 25 s). A box without Chrome falls back to the pasted address. setup.sh installs Chrome, Xvfb and x11vnc

shinyobjectz374426411e10
diff --git a/sdk/cloud/deploy/sprites/setup.sh b/sdk/cloud/deploy/sprites/setup.sh
index 99063223..e8dd561f 100644
--- a/sdk/cloud/deploy/sprites/setup.sh
+++ b/sdk/cloud/deploy/sprites/setup.sh
@@ -34,6 +34,15 @@ if [ "$(/opt/raea/bin/raea --version 2> /dev/null)" != "$VERSION" ]; then
rm -f "/tmp/$f" "/tmp/$f.sha256"
fi
+# the Google sign-in's own browser (server/google-screen.ts): Chrome on a virtual display, shown over VNC
+sudo -E apt-get install -y -qq --no-install-recommends xvfb x11vnc fonts-noto-color-emoji > /dev/null
+command -v google-chrome > /dev/null || {
+ say "google chrome"
+ curl -fsSLo /tmp/chrome.deb https://dl.google.com/linux/direct/google-chrome-stable_current_amd64.deb
+ sudo -E apt-get install -y -qq /tmp/chrome.deb > /dev/null
+ rm -f /tmp/chrome.deb
+}
+
# sdk/cloud's server, client and wrapper, as the image has them (image/Dockerfile)
if [ ! -s /tmp/raea-cloud.tgz ]; then
[ -n "$REF" ] || { echo "box: no /tmp/raea-cloud.tgz and no REF to take sdk/cloud from"; exit 2; }
diff --git a/sdk/cloud/server/google-screen.ts b/sdk/cloud/server/google-screen.ts
new file mode 100644
index 00000000..59b26e0c
--- /dev/null
+++ b/sdk/cloud/server/google-screen.ts
@@ -0,0 +1,97 @@
+// The Google sign-in's own browser (11-24, Shane: "I don't want people having to do it themselves"). Antigravity's
+// Google sign-in sends the browser back to 127.0.0.1 on the machine it runs on, so a browser on the person's computer
+// lands on a page that can't load. Here the sign-in runs in a Chrome on the box instead, on a virtual display of its
+// own, and the person sees and works it from the dashboard over VNC (RFB, carried on a WebSocket: main.ts
+// /v1/google-token/ID/screen). Google's last step then lands on Antigravity's listener on the box and the sign-in
+// finishes by itself, 2-step verification and all (checked 11-24 on Shane's account).
+//
+// Each sign-in gets its own display, Chrome profile (in the sign-in's folder, so the Google session it holds is removed
+// with it) and VNC port; all three stop when the sign-in ends. With no Chrome installed there's no screen, and the
+// sign-in falls back to the pasted address.
+import { type ChildProcess, spawn, spawnSync } from "node:child_process"
+import { existsSync } from "node:fs"
+import { connect } from "node:net"
+import path from "node:path"
+
+/** the screen's size: Google's sign-in fits it, and the dashboard's panel scales it */
+export const SCREEN = { width: 960, height: 760 }
+const CHROMES = ["google-chrome", "google-chrome-stable", "chromium", "chromium-browser"]
+
+export interface Screen {
+ /** the VNC server's port on 127.0.0.1 */
+ port: number
+ /** whether it's still up */
+ up(): boolean
+ stop(): void
+}
+
+const which = (bin: string) => spawnSync("sh", ["-c", `command -v ${bin}`], { encoding: "utf8" }).stdout.trim()
+const chrome = () => process.env.RAEA_CHROME || CHROMES.map(which).find(Boolean) || ""
+/** whether this box can show a sign-in: Chrome, a virtual display and a VNC server */
+export const canShow = () => !!chrome() && !!which("Xvfb") && !!which("x11vnc")
+
+const until = async (ok: () => boolean, ms: number) => {
+ for (let t = 0; t < ms && !ok(); t += 100) await new Promise((r) => setTimeout(r, 100))
+ return ok()
+}
+const listening = (port: number) =>
+ new Promise<boolean>((ok) => {
+ const s = connect(port, "127.0.0.1")
+ s.once("connect", () => (s.destroy(), ok(true)))
+ s.once("error", () => ok(false))
+ })
+
+/** the first display number from 100 with no X socket, and its VNC port */
+function freeDisplay(): number {
+ for (let n = 100; n < 400; n++) if (!existsSync(`/tmp/.X11-unix/X${n}`) && !existsSync(`/tmp/.X${n}-lock`)) return n
+ throw new Error("no free display for the sign-in's browser")
+}
+
+/** a Chrome on a display of its own at url, served over VNC on 127.0.0.1; its profile is under dir */
+export async function openScreen(dir: string, url: string): Promise<Screen> {
+ const bin = chrome()
+ if (!bin) throw new Error("no Chrome on this box")
+ const n = freeDisplay()
+ const port = 5900 + n
+ const kids: ChildProcess[] = []
+ const stop = () => {
+ for (const k of kids.reverse()) if (k.exitCode === null && k.signalCode === null) k.kill("SIGTERM")
+ }
+ try {
+ const x = spawn("Xvfb", [`:${n}`, "-screen", "0", `${SCREEN.width}x${SCREEN.height}x24`, "-nolisten", "tcp"], { stdio: "ignore" })
+ kids.push(x)
+ if (!(await until(() => existsSync(`/tmp/.X11-unix/X${n}`) || x.exitCode !== null, 10_000)) || x.exitCode !== null) throw new Error("the virtual display didn't start")
+ const env = { ...process.env, DISPLAY: `:${n}` }
+ // no sandbox: the box's container has no user namespaces for it; the window is an app window (no tabs or address
+ // bar), the whole screen, and keeps its passwords in its profile (no keyring to ask about)
+ kids.push(
+ spawn(
+ bin,
+ [
+ "--no-sandbox",
+ "--disable-gpu",
+ "--disable-dev-shm-usage",
+ "--no-first-run",
+ "--no-default-browser-check",
+ "--password-store=basic",
+ `--user-data-dir=${path.join(dir, "chrome")}`,
+ "--window-position=0,0",
+ `--window-size=${SCREEN.width},${SCREEN.height}`,
+ `--app=${url}`,
+ ],
+ { env, stdio: "ignore" },
+ ),
+ )
+ kids.push(spawn("x11vnc", ["-display", `:${n}`, "-localhost", "-nopw", "-forever", "-shared", "-quiet", "-rfbport", String(port)], { env, stdio: "ignore" }))
+ let ok = false
+ for (let t = 0; t < 10_000 && !ok; t += 200) {
+ ok = await listening(port)
+ if (!ok) await new Promise((r) => setTimeout(r, 200))
+ }
+ if (!ok) throw new Error("the sign-in's screen didn't start")
+ } catch (e) {
+ stop()
+ throw e
+ }
+ return { port, up: () => kids.every((k) => k.exitCode === null && k.signalCode === null), stop }
+}
diff --git a/sdk/cloud/server/google-token.ts b/sdk/cloud/server/google-token.ts
index 310d9588..c8859071 100644
--- a/sdk/cloud/server/google-token.ts
+++ b/sdk/cloud/server/google-token.ts
@@ -11,8 +11,13 @@
// sign-in runs in a folder of its own that's removed when it ends, and one left waiting is stopped after 15 minutes.
// An agent socket that's given the string (x-raea-agent-env RAEA_GOOGLE_CREDENTIAL, main.ts) has it written into its
// own GEMINI_HOME before Antigravity starts.
-// POST /v1/google-token {id, url}: a sign-in started, and the link to open
-// POST /v1/google-token/ID {address} {credential, email?}: the address the browser landed on; or {error}
+// Where the box has a Chrome (google-screen.ts) the sign-in can run in a browser on the box instead, which the person
+// works from the dashboard: Google's last step then reaches Antigravity's listener on its own, and nothing is pasted.
+// POST /v1/google-token {screen?} {id, url, screen}: a sign-in started, the link to open, and whether it
+// runs in the box's own browser (WS /v1/google-token/ID/screen shows it)
+// POST /v1/google-token/ID {address?} {credential, email?}: with the address the browser landed on; with none,
+// once the box's browser has finished it ({pending: true} while it hasn't,
+// after waiting up to 25 s); or {error}
// POST /v1/google-token/check {credential} {ok, said, models, current}: one short turn on a credential or a Gemini
// API key (AIza…)
import { type ChildProcess, spawn } from "node:child_process"
@@ -21,6 +26,7 @@ import { mkdirSync, mkdtempSync, readdirSync, readFileSync, rmSync, statSync, wr
import { tmpdir } from "node:os"
import path from "node:path"
import { spawnFor } from "./agents.ts"
+import { canShow, openScreen, type Screen } from "./google-screen.ts"
export const GOOGLE_AGENT = process.env.RAEA_GOOGLE_AGENT ?? "antigravity-acp"
const PREFIX = "agy1:"
@@ -179,6 +185,8 @@ interface SignIn {
authed: boolean
failed?: string
timer: NodeJS.Timeout
+ /** the box's own browser for it, when it runs there */
+ screen?: Screen
}
const waiting = new Map<string, SignIn>()
@@ -187,6 +195,7 @@ function end(id: string) {
if (!s) return
waiting.delete(id)
clearTimeout(s.timer)
+ s.screen?.stop()
if (s.agy.child.exitCode === null) s.agy.child.kill("SIGTERM")
rmSync(s.dir, { recursive: true, force: true })
}
@@ -195,7 +204,7 @@ const until = async (ok: () => boolean, ms: number) => {
for (let t = 0; t < ms && !ok(); t += 200) await new Promise((r) => setTimeout(r, 200))
}
-export async function startGoogleSignIn(env: NodeJS.ProcessEnv): Promise<{ id: string; url: string }> {
+export async function startGoogleSignIn(env: NodeJS.ProcessEnv, o: { screen?: boolean } = {}): Promise<{ id: string; url: string; screen: boolean }> {
const dir = mkdtempSync(path.join(tmpdir(), "google-sign-in-"))
const home = path.join(dir, ".gemini")
mkdirSync(home, { mode: 0o700 })
@@ -224,16 +233,37 @@ export async function startGoogleSignIn(env: NodeJS.ProcessEnv): Promise<{ id: s
}
s.port = link.port
s.state = link.state
- return { id, url: link.url }
+ // the box's own browser, when asked for and there is one; else the person signs in in theirs and pastes
+ if (o.screen && canShow()) {
+ try {
+ s.screen = await openScreen(dir, link.url)
+ } catch (e) {
+ console.error(`raea-cloud: google sign-in ${id.slice(0, 6)}: no screen, the address is pasted instead:`, (e as Error).message)
+ }
+ }
+ return { id, url: link.url, screen: !!s.screen }
+}
+
+/** the VNC port of a sign-in's own browser, while it's up */
+export function screenPort(id: string): number | undefined {
+ const s = waiting.get(id)
+ return s?.screen?.up() ? s.screen.port : undefined
}
-export async function finishGoogleSignIn(id: string, address: string): Promise<{ credential: string; email?: string }> {
+export async function finishGoogleSignIn(id: string, address?: string): Promise<{ credential: string; email?: string } | { pending: true }> {
const s = waiting.get(id)
if (!s) throw new Error("that sign-in has ended (they last 15 minutes): start again")
- const q = landedQuery(address, s)
- // the browser's visit to Antigravity's listener, made from the box
- const r = await fetch(`http://127.0.0.1:${s.port}${q}`, { signal: AbortSignal.timeout(30_000) }).catch((e: Error) => ({ ok: false, status: 0, statusText: e.message }))
- await until(() => s.authed || !!s.failed || s.agy.ended, 60_000)
+ let r: { ok: boolean; status: number; statusText: string } = { ok: true, status: 200, statusText: "" }
+ if (address) {
+ const q = landedQuery(address, s)
+ // the browser's visit to Antigravity's listener, made from the box
+ r = await fetch(`http://127.0.0.1:${s.port}${q}`, { signal: AbortSignal.timeout(30_000) }).catch((e: Error) => ({ ok: false, status: 0, statusText: e.message }))
+ await until(() => s.authed || !!s.failed || s.agy.ended, 60_000)
+ } else {
+ // the box's own browser finishes it: wait a while, and say it's still going if it hasn't (the caller asks again)
+ await until(() => s.authed || !!s.failed || s.agy.ended, 25_000)
+ if (!s.authed && !s.failed && !s.agy.ended) return { pending: true }
+ }
const credential = s.authed ? packCredential(s.home) : undefined
const why = s.failed ?? (r.ok ? tail(s.agy.out) : `its sign-in page answered ${r.status || r.statusText}`)
console.log(`raea-cloud: google sign-in ${id.slice(0, 6)} ${credential ? "got a credential" : `no credential: ${why}`}`)
diff --git a/sdk/cloud/server/main.ts b/sdk/cloud/server/main.ts
index 9b0a7902..ac8222c5 100644
--- a/sdk/cloud/server/main.ts
+++ b/sdk/cloud/server/main.ts
@@ -14,8 +14,10 @@
// POST /v1/claude-token a Claude subscription sign-in in a browser: {id, url} (claude-token.ts)
// POST /v1/claude-token/ID {code} the code claude.com showed, in: {token}, handed back once and never kept
// POST /v1/claude-token/check {token} one short Claude Code turn on it: {ok, said}
-// POST /v1/google-token a Google AI subscription sign-in (Antigravity): {id, url} (google-token.ts)
-// POST /v1/google-token/ID {address} the address Google's sign-in landed on, in: {credential, email?}, handed back once
+// POST /v1/google-token {screen?} a Google AI subscription sign-in (Antigravity): {id, url, screen} (google-token.ts)
+// POST /v1/google-token/ID {address?} the address Google's sign-in landed on, in (none when it ran in the box's own
+// browser): {credential, email?}, handed back once, or {pending: true}
+// WS /v1/google-token/ID/screen the box's own browser for that sign-in, over VNC (google-screen.ts)
// POST /v1/google-token/check {credential} one short Antigravity turn on it (or a Gemini API key): {ok, said, models}
// WS /v1/acp?agent=ID one agent process per socket: a text frame is one ACP message to its stdin,
// each line it prints is one frame back. A caller signing the agent in as one of
@@ -42,7 +44,8 @@ import { installed, spawnFor } from "./agents.ts"
import { device } from "./gpu.ts"
import * as jobs from "./jobs.ts"
import { checkClaude, finishClaudeSignIn, startClaudeSignIn } from "./claude-token.ts"
-import { checkGoogle, finishGoogleSignIn, startGoogleSignIn, unpackCredential } from "./google-token.ts"
+import { checkGoogle, finishGoogleSignIn, screenPort, startGoogleSignIn, unpackCredential } from "./google-token.ts"
+import { connect as tcp } from "node:net"
import { login, loginState } from "./login.ts"
import { Outside, resolve, WORK } from "./workspace.ts"
@@ -249,7 +252,10 @@ const server = createServer(async (req, res) => {
const b = JSON.parse((await body(req)).toString("utf8") || "{}") as { token?: unknown }
return json(res, await checkClaude(childEnv(), String(b.token ?? "")))
}
- if (url.pathname === "/v1/google-token" && req.method === "POST") return json(res, await startGoogleSignIn(childEnv()))
+ if (url.pathname === "/v1/google-token" && req.method === "POST") {
+ const b = JSON.parse((await body(req)).toString("utf8") || "{}") as { screen?: unknown }
+ return json(res, await startGoogleSignIn(childEnv(), { screen: b.screen === true }))
+ }
if (url.pathname === "/v1/google-token/check" && req.method === "POST") {
const b = JSON.parse((await body(req)).toString("utf8") || "{}") as { credential?: unknown }
return json(res, await checkGoogle(childEnv(), String(b.credential ?? "")))
@@ -257,7 +263,7 @@ const server = createServer(async (req, res) => {
const gt = /^\/v1\/google-token\/([0-9a-f]{24})$/.exec(url.pathname)
if (gt && req.method === "POST") {
const b = JSON.parse((await body(req)).toString("utf8") || "{}") as { address?: unknown }
- return json(res, await finishGoogleSignIn(gt[1], String(b.address ?? "")))
+ return json(res, await finishGoogleSignIn(gt[1], typeof b.address === "string" && b.address.trim() ? b.address : undefined))
}
const ct = /^\/v1\/claude-token\/([0-9a-f]{24})$/.exec(url.pathname)
if (ct && req.method === "POST") {
@@ -279,6 +285,20 @@ const server = createServer(async (req, res) => {
const wss = new WebSocketServer({ noServer: true })
server.on("upgrade", (req, socket, head) => {
const url = new URL(req.url ?? "/", "http://raea-cloud")
+ // a Google sign-in's own browser (google-screen.ts): its VNC stream, both ways, as binary frames
+ const gs = /^\/v1\/google-token\/([0-9a-f]{24})\/screen$/.exec(url.pathname)
+ if (gs) {
+ const port = authorized(req, url) ? screenPort(gs[1]) : undefined
+ if (port === undefined) return socket.end(authorized(req, url) ? "HTTP/1.1 404 Not Found\r\n\r\n" : "HTTP/1.1 401 Unauthorized\r\n\r\n")
+ return wss.handleUpgrade(req, socket, head, (ws) => {
+ const vnc = tcp(port, "127.0.0.1")
+ vnc.on("data", (d) => ws.readyState === ws.OPEN && ws.send(d))
+ ws.on("message", (m) => vnc.write(m as Buffer))
+ vnc.on("close", () => ws.close(1000, "the sign-in's screen closed"))
+ vnc.on("error", () => ws.close(1011, "the sign-in's screen failed"))
+ ws.on("close", () => vnc.destroy())
+ })
+ }
if (url.pathname !== "/v1/acp" || !authorized(req, url)) return socket.end("HTTP/1.1 401 Unauthorized\r\n\r\n")
let a
try {