Computers now run our own image (computer/, Debian 13): real Google Chrome on amd64 (Debian's Chromium on arm64), headful on Xvnc with no automation flags, so sites like Google treat it as a normal browser. One small Node agent supervises the screen, the session bus, Chrome, Playwright MCP and ttyd, and serves a single token-guarded port. - Browser view: the computer's screen over noVNC, so Chrome shows whole (tabs, address bar, menu, extensions, prompts); Ctrl/Cmd+V pastes the viewer's clipboard (HTTPS or localhost). Cookie-Editor is installed by default. - Shell view (ttyd), for crew managers only. - The /computers/<id>/ proxy passes only the view paths, never the agent's API or MCP. - Per-computer browser settings (super admin): timezone, languages, screen, scale (125% by default, larger text in bots' screenshots), sandbox and extra Chrome / Playwright MCP flags, with unsafe flags refused. - Rebuild computer: pulls the image again and recreates the container; files and logins stay. - Bots' computer tools are the app's own (bash, read/write/edit file) plus Playwright MCP; downloads move into the run's folder, MCP's snapshot and console files point at the tools that read them. - Release workflow builds and pushes ghcr.io/moduletrace/cobble-computer for amd64 and arm64 once per tag. Existing computers are recreated on the new image at boot (files and browser profiles stay); run db:schema for the new browser_settings column (the installer does this). Co-Authored-By: Claude Opus 5.5 <[email protected]>
70 lines
2.1 KiB
TypeScript
70 lines
2.1 KiB
TypeScript
import type { ServerWebSocket } from "bun";
|
|
import type { WebSocketSession } from "@/src/websocket/types";
|
|
|
|
type Socket = ServerWebSocket<WebSocketSession>;
|
|
|
|
/**
|
|
* Bridges a user's websocket on `/computers/<id>/...` to the same path on
|
|
* the computer (the screen's VNC line, the shell's terminal).
|
|
* Messages sent before the computer's side opens are held, and either
|
|
* side closing closes the other.
|
|
*/
|
|
export const computerProxySocket = {
|
|
open(ws: Socket) {
|
|
const proxy = ws.data.proxy;
|
|
|
|
if (!proxy) return;
|
|
|
|
const upstream = new WebSocket(proxy.url, {
|
|
headers: proxy.headers,
|
|
protocols: proxy.protocols,
|
|
} as any);
|
|
|
|
upstream.binaryType = "arraybuffer";
|
|
proxy.upstream = upstream;
|
|
proxy.pending = [];
|
|
|
|
upstream.onopen = () => {
|
|
for (const message of proxy.pending || []) upstream.send(message as string | Uint8Array<ArrayBuffer>);
|
|
proxy.pending = undefined;
|
|
};
|
|
|
|
upstream.onmessage = (event) => {
|
|
ws.send(typeof event.data == "string" ? event.data : new Uint8Array(event.data));
|
|
};
|
|
|
|
upstream.onclose = (event) => {
|
|
ws.close(closeCode({ code: event.code }), event.reason);
|
|
};
|
|
|
|
upstream.onerror = () => {
|
|
ws.close(1011, "The computer isn't answering");
|
|
};
|
|
},
|
|
|
|
message(ws: Socket, message: string | Buffer) {
|
|
const proxy = ws.data.proxy;
|
|
|
|
if (!proxy?.upstream) return;
|
|
|
|
if (proxy.pending) proxy.pending.push(message);
|
|
else if (proxy.upstream.readyState == WebSocket.OPEN) {
|
|
proxy.upstream.send(message as string | Uint8Array<ArrayBuffer>);
|
|
}
|
|
},
|
|
|
|
close(ws: Socket) {
|
|
const upstream = ws.data.proxy?.upstream;
|
|
|
|
if (upstream && upstream.readyState < WebSocket.CLOSING) upstream.close();
|
|
},
|
|
};
|
|
|
|
/**
|
|
* Codes a server may not send itself (no status, abnormal) become a
|
|
* normal close.
|
|
*/
|
|
function closeCode({ code }: { code: number }) {
|
|
return code == 1005 || code == 1006 || code == 1015 ? 1000 : code;
|
|
}
|