mirror of
https://github.com/nightly-labs/openbot.git
synced 2026-11-26 02:29:31 +08:00
* Replace Whisper with Parakeet and show live text while you speak Voice input now uses NVIDIA Parakeet TDT 0.6B v3 (int8 ONNX) through sherpa-onnx in a separate host process. The host loads the model on the first request and stops 60 s after the last use. - The first recording downloads the model (670 MB) with SHA-256 checks and shows the progress in the composer. - The composer shows the words while you speak, about once a second. The final pass replaces them when you stop. - The microphone button changes into a recording bar with a live waveform, cancel, finish, and send. - Packaged builds delete the old Whisper model cache. - Release workflows, package checks, and licenses use the new runtime. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> * Stop the waveform when the recorder stops by itself - Stop the meter, the stream and the elapsed timer when the recorder stops without the user, for example when the microphone is disconnected. - Close the audio context when the meter setup fails. - Do not send the "ready" model status again on each live pass. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> * Fix the unused export and keep the runtime recipe unchanged - Do not export `voiceIO`. Only the voice model service uses it. - Restore the runtime workflow from main. Its model cache step does nothing, because the package build prepares only the voice runtime. An edit to the file forces a full native runtime rebuild. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> * Remove the unused voice assets error text Parakeet reports a missing runtime with its own message, so no code uses `error.voice.assetsUnavailable` now. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> --------- Co-authored-by: Claude Opus 5.5 <noreply@anthropic.com>
310 lines
13 KiB
TypeScript
310 lines
13 KiB
TypeScript
import { spawn } from "node:child_process";
|
|
import { constants, existsSync } from "node:fs";
|
|
import { access, mkdtemp, readdir, readFile, rm } from "node:fs/promises";
|
|
import { tmpdir } from "node:os";
|
|
import { join, resolve } from "node:path";
|
|
import { FuseV1Options, getCurrentFuseWire } from "@electron/fuses";
|
|
import { isDynamicRecord, isNumber, isString } from "@openbot/contracts/runtime-values";
|
|
import { createOpenBotLogger, toLogValue } from "@openbot/logging";
|
|
|
|
const logger = createOpenBotLogger("verify-linux-package");
|
|
|
|
/** The scripts that a server installs from a release (`RELEASE_FILES` in scripts/hosting/openbot-hosted-update). */
|
|
const HOSTED_SCRIPTS = [
|
|
"openbot-hosted-server",
|
|
"openbot-hosted-env",
|
|
"openbot-hosted-update",
|
|
"openbot",
|
|
// Not installed on a server: `install-server.sh` runs it from the unpacked release.
|
|
"openbot-server-setup",
|
|
];
|
|
const HOSTED_UNITS = [
|
|
"openbot.service",
|
|
"openbot-update.service",
|
|
"openbot-update.timer",
|
|
"openbot-update-apply.service",
|
|
"openbot-update-request.path",
|
|
"openbot-update-request.service",
|
|
];
|
|
|
|
const FUSE_DISABLED = 48;
|
|
const FUSE_ENABLED = 49;
|
|
|
|
if (process.platform !== "linux") {
|
|
throw new Error("The Linux package verifier must run on Linux.");
|
|
}
|
|
|
|
/** The verifier checks a build for the host it runs on: CI builds each architecture on its own runner. */
|
|
const LINUX_ARCHITECTURES = {
|
|
x64: { label: "x86-64", elfMachine: 0x3e },
|
|
arm64: { label: "AArch64", elfMachine: 0xb7 },
|
|
} as const;
|
|
const architecture = process.arch;
|
|
if (architecture !== "x64" && architecture !== "arm64") {
|
|
throw new Error(`The Linux package verifier does not support ${architecture}.`);
|
|
}
|
|
const target = LINUX_ARCHITECTURES[architecture];
|
|
|
|
const requireUpdateMetadata = process.argv.includes("--require-update-metadata");
|
|
const appPathArgument = process.argv.slice(2).find((argument) => !argument.startsWith("--"));
|
|
const appPath = resolve(
|
|
appPathArgument ?? (architecture === "x64" ? "dist/linux-unpacked" : "dist/linux-arm64-unpacked"),
|
|
);
|
|
// electron-builder names the Linux binary after `name` in package.json, not `productName`.
|
|
const executablePath = resolve(appPath, "openbot");
|
|
const resourcesPath = resolve(appPath, "resources");
|
|
const asarPath = resolve(resourcesPath, "app.asar");
|
|
|
|
await Promise.all([
|
|
access(executablePath),
|
|
access(resolve(resourcesPath, "app.asar.unpacked/node_modules/effect/package.json")),
|
|
access(resolve(resourcesPath, "app.asar.unpacked/node_modules/effect/dist/index.js")),
|
|
access(asarPath),
|
|
access(resolve(resourcesPath, "managed-skills")),
|
|
access(resolve(resourcesPath, "licenses/Electron-LICENSE")),
|
|
access(resolve(resourcesPath, "licenses/LICENSES.chromium.html")),
|
|
// A hosted server refuses an update to a release without all of its hosting files.
|
|
...["packages.txt", "openbot-hosted.apparmor", ...HOSTED_UNITS].map((file) =>
|
|
access(resolve(resourcesPath, "hosting", file)),
|
|
),
|
|
...HOSTED_SCRIPTS.map((file) => access(resolve(resourcesPath, "hosting", file), constants.X_OK)),
|
|
// Computer Use is the one native runtime the Linux build does ship.
|
|
access(resolve(resourcesPath, `cua-driver/linux/${architecture}/cua-driver`)),
|
|
access(resolve(resourcesPath, `cua-driver/linux/${architecture}/wayland-helper/winrects@cua/extension.js`)),
|
|
access(resolve(resourcesPath, `cua-driver/linux/${architecture}/LICENSE.md`)),
|
|
]);
|
|
await Promise.all(
|
|
["darwin", "win32"].map((name) =>
|
|
assertAbsent(resolve(resourcesPath, "cua-driver", name), "Only this platform's driver ships"),
|
|
),
|
|
);
|
|
|
|
// Voice is not built for Linux. This assertion is the regression guard for the platform split of
|
|
// `extraResources`: if it ever returns to the shared list, the Linux build either fails outright
|
|
// on a missing source or ships a runtime it cannot use.
|
|
await assertAbsent(resolve(resourcesPath, "voice"), "Voice transcription is not available on Linux");
|
|
// The remote desktop runtime is built for x64 only, and only for this platform.
|
|
if (architecture === "x64") {
|
|
await Promise.all(
|
|
["sunshine", "web-server", "streamer", "static/stream.html"].map((name) =>
|
|
access(resolve(resourcesPath, "remote-desktop-runtime/linux/x64", name)),
|
|
),
|
|
);
|
|
await Promise.all(
|
|
["darwin", "win32"].map((name) =>
|
|
assertAbsent(resolve(resourcesPath, "remote-desktop-runtime", name), "Only this platform's runtime ships"),
|
|
),
|
|
);
|
|
} else {
|
|
await assertAbsent(
|
|
resolve(resourcesPath, "remote-desktop-runtime"),
|
|
"Remote desktop is not available on Linux arm64",
|
|
);
|
|
}
|
|
|
|
// Providers and the tunnel are downloaded on demand, exactly as on macOS and Windows.
|
|
await Promise.all(
|
|
["codex", "claude", "grok", "cloudflared"].map((name) =>
|
|
assertAbsent(resolve(resourcesPath, name), "Runtimes must not be packaged"),
|
|
),
|
|
);
|
|
await assertAbsent(
|
|
resolve(resourcesPath, `app.asar.unpacked/node_modules/@anthropic-ai/claude-agent-sdk-linux-${architecture}`),
|
|
"The native Claude runtime must not be duplicated",
|
|
);
|
|
|
|
const packageJson = JSON.parse(await readFile("package.json", "utf8"));
|
|
if (!isDynamicRecord(packageJson)) throw new Error("package.json is not a JSON object.");
|
|
if (!isString(packageJson.version)) throw new Error("package.json version is missing.");
|
|
|
|
// The Linux build has no version resource to read, so the packaged manifest is the record of what
|
|
// was built. It is the same file the running app reports through `app.getVersion()`.
|
|
const packagedManifest = JSON.parse(await readAsarFile(asarPath, "package.json"));
|
|
if (!isDynamicRecord(packagedManifest)) throw new Error("The packaged package.json is not a JSON object.");
|
|
expectEqual(packagedManifest.name, "openbot", "packaged name");
|
|
expectEqual(packagedManifest.productName, "OpenBot", "packaged product name");
|
|
expectEqual(packagedManifest.version, packageJson.version, "packaged version");
|
|
|
|
const executable = await readFile(executablePath);
|
|
if (executable.toString("binary", 0, 4) !== "\x7fELF") throw new Error("The executable has no ELF header.");
|
|
if (executable[4] !== 2) throw new Error("Expected a 64-bit ELF executable.");
|
|
const machine = executable.readUInt16LE(18);
|
|
if (machine !== target.elfMachine) {
|
|
throw new Error(
|
|
`Expected a Linux ${target.label} executable, but its ELF machine type is 0x${machine.toString(16)}.`,
|
|
);
|
|
}
|
|
|
|
const appImages = existsSync("dist") ? await findAppImages() : [];
|
|
for (const appImage of appImages) {
|
|
if (!appImage.startsWith(`OpenBot-${packageJson.version}-`)) {
|
|
throw new Error(`Unexpected AppImage name: ${appImage} (expected OpenBot-${packageJson.version}-<arch>.AppImage)`);
|
|
}
|
|
}
|
|
|
|
const updateMetadataPath = resolve(resourcesPath, "app-update.yml");
|
|
let updateMetadata: string | null = null;
|
|
try {
|
|
updateMetadata = await readFile(updateMetadataPath, "utf8");
|
|
} catch (error) {
|
|
if (requireUpdateMetadata) throw error;
|
|
}
|
|
if (updateMetadata !== null && !updateMetadata.includes("provider: github")) {
|
|
throw new Error("The packaged update provider is not GitHub.");
|
|
}
|
|
|
|
const fuses = await getCurrentFuseWire(executablePath);
|
|
const expectedFuses: Array<[FuseV1Options, number]> = [
|
|
[FuseV1Options.RunAsNode, FUSE_DISABLED],
|
|
[FuseV1Options.EnableCookieEncryption, FUSE_ENABLED],
|
|
[FuseV1Options.EnableNodeOptionsEnvironmentVariable, FUSE_DISABLED],
|
|
[FuseV1Options.EnableNodeCliInspectArguments, FUSE_DISABLED],
|
|
[FuseV1Options.EnableEmbeddedAsarIntegrityValidation, FUSE_ENABLED],
|
|
[FuseV1Options.OnlyLoadAppFromAsar, FUSE_ENABLED],
|
|
[FuseV1Options.LoadBrowserProcessSpecificV8Snapshot, FUSE_DISABLED],
|
|
[FuseV1Options.GrantFileProtocolExtraPrivileges, FUSE_DISABLED],
|
|
];
|
|
for (const [fuse, expected] of expectedFuses) {
|
|
if (fuses[fuse] !== expected) {
|
|
throw new Error(`Unexpected Electron fuse ${FuseV1Options[fuse]}: ${String(fuses[fuse])}`);
|
|
}
|
|
}
|
|
|
|
await verifyLaunch(executablePath);
|
|
|
|
logger.info(`Verified ${appPath}`);
|
|
logger.info(
|
|
`OpenBot ${packageJson.version} · Linux ${architecture} · manifest · no voice or remote desktop · ASAR integrity · hardened fuses · launch`,
|
|
);
|
|
|
|
function expectEqual(actual: unknown, expected: unknown, label: string): void {
|
|
if (actual !== expected) {
|
|
throw new Error(`Unexpected ${label}: ${String(actual)} (expected ${String(expected)})`);
|
|
}
|
|
}
|
|
|
|
async function assertAbsent(path: string, reason: string): Promise<void> {
|
|
try {
|
|
await access(path);
|
|
} catch {
|
|
return;
|
|
}
|
|
throw new Error(`${reason}: ${path}`);
|
|
}
|
|
|
|
async function findAppImages(): Promise<string[]> {
|
|
return (await readdir("dist")).filter((name) => name.endsWith(".AppImage"));
|
|
}
|
|
|
|
/**
|
|
* Reads one top-level file out of an asar archive.
|
|
*
|
|
* The archive opens with four little-endian 32-bit words - a constant `4`, the size of the header
|
|
* block, the size of the JSON inside it, and the length of the JSON string itself - and then the
|
|
* JSON file table, which gives every entry an offset into the data that follows the header block.
|
|
* Doing this here keeps the verifier on the declared dependencies: `@electron/asar` is only a
|
|
* transitive dependency of electron-builder, and reading four words of a stable on-disk format is a
|
|
* smaller commitment than depending on it.
|
|
*/
|
|
async function readAsarFile(archive: string, name: string): Promise<string> {
|
|
const buffer = await readFile(archive);
|
|
const headerSize = buffer.readUInt32LE(4);
|
|
const headerJsonLength = buffer.readUInt32LE(12);
|
|
const header = JSON.parse(buffer.toString("utf8", 16, 16 + headerJsonLength));
|
|
if (!isDynamicRecord(header) || !isDynamicRecord(header.files)) {
|
|
throw new Error(`${archive} has no asar file table.`);
|
|
}
|
|
const entry = header.files[name];
|
|
if (!isDynamicRecord(entry) || !isString(entry.offset) || !isNumber(entry.size)) {
|
|
throw new Error(`${archive} does not contain ${name}.`);
|
|
}
|
|
const start = 8 + headerSize + Number(entry.offset);
|
|
return buffer.toString("utf8", start, start + entry.size);
|
|
}
|
|
|
|
/**
|
|
* Starts the packaged application once and makes sure it stays up.
|
|
*
|
|
* This needs a display, so in CI it runs under `xvfb-run -a`. It cannot be verified on a macOS
|
|
* worktree at all: the verifier refuses to run there, and a headless Electron does not reach
|
|
* `ready` in an agent shell.
|
|
*
|
|
* No `--no-sandbox` here or anywhere else. If the launch fails with a user-namespace error, the
|
|
* host is missing the AppArmor profile, which is a real defect in the install instructions rather
|
|
* than something to switch the sandbox off for.
|
|
*/
|
|
async function verifyLaunch(executable: string): Promise<void> {
|
|
if (!process.env.DISPLAY && !process.env.WAYLAND_DISPLAY) {
|
|
throw new Error("The launch check needs a display. Run it under `xvfb-run -a`.");
|
|
}
|
|
const userDataPath = await mkdtemp(join(tmpdir(), "openbot-package-smoke-"));
|
|
const child = spawn(executable, [`--user-data-dir=${userDataPath}`], {
|
|
env: launchEnvironment(userDataPath),
|
|
stdio: ["ignore", "ignore", "pipe"],
|
|
});
|
|
let stderr = "";
|
|
child.stderr.setEncoding("utf8");
|
|
child.stderr.on("data", (chunk: string) => {
|
|
stderr = `${stderr}${chunk}`.slice(-4_000);
|
|
});
|
|
|
|
try {
|
|
await Promise.race([
|
|
new Promise<never>((_, reject) => {
|
|
child.once("exit", (code, signal) => {
|
|
reject(
|
|
new Error(`Packaged OpenBot exited during launch (${signal ?? `code ${String(code)}`}): ${stderr.trim()}`),
|
|
);
|
|
});
|
|
}),
|
|
new Promise<void>((resolveDelay) => setTimeout(resolveDelay, 3_000)),
|
|
]);
|
|
await verifySecondInstanceExits(executable, userDataPath);
|
|
} finally {
|
|
child.kill("SIGTERM");
|
|
await Promise.race([
|
|
new Promise<void>((resolveExit) => child.once("exit", () => resolveExit())),
|
|
new Promise<void>((resolveDelay) => setTimeout(resolveDelay, 5_000)),
|
|
]);
|
|
child.kill("SIGKILL");
|
|
try {
|
|
await rm(userDataPath, { recursive: true, force: true, maxRetries: 5, retryDelay: 300 });
|
|
} catch (error) {
|
|
logger.warn("Could not remove the temporary Linux profile:", toLogValue(error));
|
|
}
|
|
}
|
|
}
|
|
|
|
function launchEnvironment(userDataPath: string): NodeJS.ProcessEnv {
|
|
return {
|
|
...process.env,
|
|
CODEX_HOME: join(userDataPath, "codex-home"),
|
|
CLAUDE_CONFIG_DIR: join(userDataPath, "claude-home"),
|
|
OPENBOT_CODEX_PATH: join(userDataPath, "missing-codex"),
|
|
OPENBOT_CLAUDE_PATH: join(userDataPath, "missing-claude"),
|
|
OPENBOT_GROK_PATH: join(userDataPath, "missing-grok"),
|
|
};
|
|
}
|
|
|
|
async function verifySecondInstanceExits(executable: string, userDataPath: string): Promise<void> {
|
|
const second = spawn(executable, [`--user-data-dir=${userDataPath}`], {
|
|
env: launchEnvironment(userDataPath),
|
|
stdio: "ignore",
|
|
});
|
|
const result = await Promise.race([
|
|
new Promise<{ code: number | null; signal: NodeJS.Signals | null }>((resolveExit) => {
|
|
second.once("exit", (code, signal) => resolveExit({ code, signal }));
|
|
}),
|
|
new Promise<null>((resolveDelay) => setTimeout(() => resolveDelay(null), 3_000)),
|
|
]);
|
|
if (!result) {
|
|
second.kill();
|
|
throw new Error("A second OpenBot instance did not exit.");
|
|
}
|
|
if (result.code !== 0 || result.signal) {
|
|
throw new Error(
|
|
`A second OpenBot instance exited unexpectedly (${result.signal ?? `code ${String(result.code)}`}).`,
|
|
);
|
|
}
|
|
}
|