mirror of
https://github.com/nightly-labs/openbot.git
synced 2026-11-26 02:29:31 +08:00
* Support remote desktop on a Linux x64 host in an X11 session Build Sunshine and Moonlight Web for linux-x64 (recipe 14): X11 capture, software encoding, no tray. The Sunshine patch adds an XTest input backend (Xvfb reads no uinput device), links libcap when DRM is off, and adds a vaMapBuffer2 shim for libva 2.20 on Ubuntu 24.04. The gateway accepts a Linux host only in an X11 session. CI builds, publishes and verifies the linux-x64 artifact. The x64 AppImage bundles the runtime, and the hosted server template installs its system libraries. * Pin the recipe 14 remote desktop runtime with the Linux x64 artifact * Keep the hosting developer key on authorized account requests An object spread of a `Headers` object drops its entries, so the key from `withHostingDeveloperKey` did not reach the test Worker, and hosting showed as unavailable in `dev --hosting-test`. Packaged builds send no key. The hosting test stack also sets the dev remote role to "none": a dev role signs in with a code that only the local Worker returns. * Show only connected displays in a remote desktop session Sunshine also lists outputs that have no monitor. On an X server with a dummy driver it lists 16, and 15 got a width of 0, so the Team API refused the session response and remote control did not open. * Run a hosted server's OpenBot on the boat desktop OpenBot now starts on the lightdm session on :0, with openbox, so OpenBot remote desktop and the boat desktop viewer show the same screen. The start waits up to 2 minutes for :0 and then uses Xvfb. * Give the runtime smoke check a local display The runtime now shows only the Sunshine displays that match a local display. The smoke check gave no local display, so it found no display and failed.
158 lines
5.9 KiB
TypeScript
158 lines
5.9 KiB
TypeScript
import { createHash } from "node:crypto";
|
|
import { readFile } from "node:fs/promises";
|
|
import { resolve } from "node:path";
|
|
import { z } from "zod";
|
|
|
|
const commitSchema = z.string().regex(/^[0-9a-f]{40}$/u, "Must use a complete Git commit.");
|
|
const sha256Schema = z.string().regex(/^[0-9a-f]{64}$/u, "Must use a complete SHA-256 value.");
|
|
const cloudflaredArtifactSchema = z.object({
|
|
asset: z.string().min(1),
|
|
assetSha256: sha256Schema,
|
|
binarySha256: sha256Schema,
|
|
executable: z.string().min(1),
|
|
platformDirectory: z.enum(["mac", "win"]),
|
|
});
|
|
const remoteDesktopReleaseArtifactSchema = z.object({
|
|
asset: z.string().min(1),
|
|
sha256: sha256Schema,
|
|
});
|
|
const remoteDesktopArtifactReleaseSchema = z.object({
|
|
repository: z.string().regex(/^[A-Za-z0-9_.-]+\/[A-Za-z0-9_.-]+$/u, "Must use a GitHub owner/repository name."),
|
|
tag: z.string().regex(/^remote-desktop-runtime-[0-9a-f]{64}$/u, "Must use the runtime digest tag."),
|
|
inputDigest: sha256Schema,
|
|
manifestAsset: z.literal("remote-desktop-runtime-manifest.json"),
|
|
manifestSha256: sha256Schema,
|
|
});
|
|
const sourceRuntimeSchema = z.object({
|
|
sourceMode: z.enum(["upstream-with-patch", "openbot-fork"]),
|
|
repository: z.url(),
|
|
version: z.string().min(1),
|
|
commit: commitSchema,
|
|
upstream: z.object({ repository: z.url(), commit: commitSchema }),
|
|
sourceArchive: z.url(),
|
|
sourceSha256: sha256Schema,
|
|
license: z.literal("GPL-3.0"),
|
|
licenseSha256: sha256Schema,
|
|
patch: z.object({ path: z.string().min(1), sha256: sha256Schema }),
|
|
overrides: z.array(
|
|
z.object({
|
|
source: z.string().min(1),
|
|
destination: z.string().min(1),
|
|
sha256: sha256Schema,
|
|
}),
|
|
),
|
|
submodules: z.record(z.string().min(1), commitSchema),
|
|
});
|
|
|
|
const REMOTE_DESKTOP_TARGETS = ["darwin-arm64", "darwin-x64", "win32-x64", "linux-x64"] as const;
|
|
|
|
const nativeRuntimeLockSchema = z.object({
|
|
schemaVersion: z.literal(1),
|
|
cloudflared: z.object({
|
|
repository: z.url(),
|
|
version: z.string().min(1),
|
|
license: z.literal("Apache-2.0"),
|
|
licenseSha256: sha256Schema,
|
|
artifacts: z.object({
|
|
"darwin-arm64": cloudflaredArtifactSchema,
|
|
"win32-x64": cloudflaredArtifactSchema,
|
|
}),
|
|
}),
|
|
remoteDesktop: z.object({
|
|
recipeVersion: z.number().int().positive(),
|
|
sunshine: sourceRuntimeSchema,
|
|
moonlightWeb: sourceRuntimeSchema,
|
|
artifactRelease: remoteDesktopArtifactReleaseSchema.optional(),
|
|
releaseArtifacts: z.partialRecord(z.enum(REMOTE_DESKTOP_TARGETS), remoteDesktopReleaseArtifactSchema),
|
|
targets: z.object({
|
|
"darwin-arm64": z.array(z.string().min(1)).min(1),
|
|
"darwin-x64": z.array(z.string().min(1)).min(1),
|
|
"win32-x64": z.array(z.string().min(1)).min(1),
|
|
"linux-x64": z.array(z.string().min(1)).min(1),
|
|
}),
|
|
}),
|
|
});
|
|
|
|
export type NativeRuntimeLock = z.infer<typeof nativeRuntimeLockSchema>;
|
|
|
|
export async function loadNativeRuntimeLock(sourceRoot = process.cwd()): Promise<NativeRuntimeLock> {
|
|
const path = resolve(sourceRoot, "native-runtime.lock.json");
|
|
const lock = parseNativeRuntimeLock(JSON.parse(await readFile(path, "utf8")));
|
|
await validateRemoteDesktopInputFiles(lock, sourceRoot);
|
|
return lock;
|
|
}
|
|
|
|
export function parseNativeRuntimeLock(value: unknown): NativeRuntimeLock {
|
|
const lock = nativeRuntimeLockSchema.parse(value);
|
|
const release = lock.remoteDesktop.artifactRelease;
|
|
const artifacts = lock.remoteDesktop.releaseArtifacts;
|
|
if (!release) {
|
|
if (Object.keys(artifacts).length > 0) {
|
|
throw new Error("Runtime artifacts require artifactRelease metadata.");
|
|
}
|
|
return lock;
|
|
}
|
|
|
|
for (const target of REMOTE_DESKTOP_TARGETS) {
|
|
if (!artifacts[target]) throw new Error(`The runtime lock is missing the ${target} artifact.`);
|
|
}
|
|
const expectedDigest = createRemoteDesktopInputDigest(lock);
|
|
if (release.inputDigest !== expectedDigest)
|
|
throw new Error("The runtime input digest does not match the build recipe.");
|
|
if (release.tag !== createRemoteDesktopReleaseTag(expectedDigest)) {
|
|
throw new Error("The runtime release tag does not match the input digest.");
|
|
}
|
|
return lock;
|
|
}
|
|
|
|
export function createRemoteDesktopInputDigest(lock: NativeRuntimeLock): string {
|
|
const input = {
|
|
recipeVersion: lock.remoteDesktop.recipeVersion,
|
|
sunshine: lock.remoteDesktop.sunshine,
|
|
moonlightWeb: lock.remoteDesktop.moonlightWeb,
|
|
targets: lock.remoteDesktop.targets,
|
|
};
|
|
return createHash("sha256").update(JSON.stringify(input)).digest("hex");
|
|
}
|
|
|
|
export function createRemoteDesktopReleaseTag(inputDigest: string): string {
|
|
return `remote-desktop-runtime-${inputDigest}`;
|
|
}
|
|
|
|
export function hasPinnedRemoteDesktopArtifacts(lock: NativeRuntimeLock): boolean {
|
|
return Boolean(
|
|
lock.remoteDesktop.artifactRelease &&
|
|
REMOTE_DESKTOP_TARGETS.every((target) => lock.remoteDesktop.releaseArtifacts[target]),
|
|
);
|
|
}
|
|
|
|
async function validateRemoteDesktopInputFiles(lock: NativeRuntimeLock, sourceRoot: string): Promise<void> {
|
|
for (const runtime of [lock.remoteDesktop.sunshine, lock.remoteDesktop.moonlightWeb]) {
|
|
const patchDigest = createHash("sha256")
|
|
.update(await readFile(resolve(sourceRoot, runtime.patch.path)))
|
|
.digest("hex");
|
|
if (patchDigest !== runtime.patch.sha256)
|
|
throw new Error(`Runtime patch checksum failed for ${runtime.patch.path}.`);
|
|
for (const override of runtime.overrides) {
|
|
const overrideDigest = createHash("sha256")
|
|
.update(await readFile(resolve(sourceRoot, override.source)))
|
|
.digest("hex");
|
|
if (overrideDigest !== override.sha256) {
|
|
throw new Error(`Runtime override checksum failed for ${override.source}.`);
|
|
}
|
|
}
|
|
}
|
|
}
|
|
|
|
export function createRemoteDesktopSourceManifest(lock: NativeRuntimeLock) {
|
|
return {
|
|
schemaVersion: 1,
|
|
recipeVersion: lock.remoteDesktop.recipeVersion,
|
|
inputDigest: createRemoteDesktopInputDigest(lock),
|
|
sunshine: lock.remoteDesktop.sunshine,
|
|
moonlightWeb: lock.remoteDesktop.moonlightWeb,
|
|
buildScript: "scripts/build-remote-desktop-runtime.ts",
|
|
targets: lock.remoteDesktop.targets,
|
|
};
|
|
}
|