diff --git a/apps/computer/local-daemon/internal/provider/native/codex_home_config.go b/apps/computer/local-daemon/internal/provider/native/codex_home_config.go index e3505eed..a65bd873 100644 --- a/apps/computer/local-daemon/internal/provider/native/codex_home_config.go +++ b/apps/computer/local-daemon/internal/provider/native/codex_home_config.go @@ -198,7 +198,6 @@ func codexProjectServer(server map[string]any) map[string]any { } delete(out, "headers") } - out["experimental_use_rmcp_client"] = true } return out } diff --git a/apps/computer/local-daemon/internal/provider/native/codex_units_test.go b/apps/computer/local-daemon/internal/provider/native/codex_units_test.go index 4e64b0b5..20461330 100644 --- a/apps/computer/local-daemon/internal/provider/native/codex_units_test.go +++ b/apps/computer/local-daemon/internal/provider/native/codex_units_test.go @@ -113,7 +113,7 @@ func TestCodexManagedProjection(t *testing.T) { servers := parsed["mcp_servers"].(map[string]any) remote := servers["remote"].(map[string]any) if parsed["model"] != "keep" || parsed[codexOAuthStoreKey] != "file" || servers["old"] != nil || remote["type"] != nil || remote["tools"] != nil || remote["headers"] != nil || - remote["http_headers"].(map[string]any)["Authorization"] != "Bearer t" || remote["experimental_use_rmcp_client"] != true { + remote["http_headers"].(map[string]any)["Authorization"] != "Bearer t" || len(remote) != 2 { t.Fatalf("projected = %s", first) } if work := parsed["profiles"].(map[string]any)["work"].(map[string]any); work["mcp_servers"] != nil || work["model"] != "p" { diff --git a/apps/desktop/scripts/build-native-runtime.d.mts b/apps/desktop/scripts/build-native-runtime.d.mts new file mode 100644 index 00000000..c0688f7a --- /dev/null +++ b/apps/desktop/scripts/build-native-runtime.d.mts @@ -0,0 +1,9 @@ +export function copyExternals( + deployed: string, + output: string, + roots: string[], + exclude?: (name: string) => unknown, +): Promise<{ + packages: { package: string; version: string }[]; + excluded: Record; +}>; diff --git a/apps/desktop/scripts/build-native-runtime.mjs b/apps/desktop/scripts/build-native-runtime.mjs index 278ef2ee..702e687f 100644 --- a/apps/desktop/scripts/build-native-runtime.mjs +++ b/apps/desktop/scripts/build-native-runtime.mjs @@ -108,6 +108,12 @@ const OPTIONAL_IMPORTS = new Set([ "utf-8-validate", ]); +// Dependencies the services never load, left out with everything only they +// need. officeparser imports tesseract.js (an OCR engine with about 40 MB of +// wasm) only when a parse asks for OCR, and document-office-extract.ts +// always passes `ocr: false`. +const UNLOADED_PACKAGES = new Set(["tesseract.js"]); + export const runtimeDirectory = (target) => path.join(desktop, "dist/installer/native", `runtime-${target}`); @@ -163,6 +169,7 @@ export async function copyExternals( } }; const visit = async (name, from, required) => { + if (UNLOADED_PACKAGES.has(name)) return; const directory = find(name, from); if (!directory) { if (required) diff --git a/apps/desktop/src/main/build-native-runtime.test.ts b/apps/desktop/src/main/build-native-runtime.test.ts new file mode 100644 index 00000000..da63c6cc --- /dev/null +++ b/apps/desktop/src/main/build-native-runtime.test.ts @@ -0,0 +1,57 @@ +import { + existsSync, + mkdirSync, + mkdtempSync, + rmSync, + writeFileSync, +} from "node:fs"; +import { tmpdir } from "node:os"; +import path from "node:path"; + +import { afterEach, expect, it } from "vitest"; + +import { copyExternals } from "../../scripts/build-native-runtime.mjs"; + +const roots: string[] = []; +afterEach(() => { + for (const root of roots.splice(0)) + rmSync(root, { recursive: true, force: true }); +}); + +// A hoisted node_modules as `pnpm deploy --config.node-linker=hoisted` writes +// it, with officeparser and the dependencies its 8.2.0 manifest declares. +const deployed = () => { + const root = mkdtempSync(path.join(tmpdir(), "build-native-runtime-")); + roots.push(root); + const add = (name: string, dependencies: Record = {}) => { + const directory = path.join(root, "deploy/node_modules", name); + mkdirSync(directory, { recursive: true }); + writeFileSync( + path.join(directory, "package.json"), + JSON.stringify({ name, version: "1.0.0", dependencies }), + ); + writeFileSync(path.join(directory, "index.js"), ""); + }; + add("officeparser", { "pdfjs-dist": "1", "tesseract.js": "1" }); + add("pdfjs-dist"); + add("tesseract.js", { "tesseract.js-core": "1", "node-fetch": "1" }); + add("tesseract.js-core"); + add("node-fetch"); + return root; +}; + +it("leaves out the OCR engine officeparser only loads with OCR on", async () => { + const root = deployed(); + const output = path.join(root, "output"); + const result = await copyExternals(path.join(root, "deploy"), output, [ + "officeparser", + ]); + expect(result.packages.map((item) => item.package).sort()).toEqual([ + "node_modules/officeparser", + "node_modules/pdfjs-dist", + ]); + expect(result.excluded).toEqual({}); + expect(existsSync(path.join(output, "node_modules/officeparser"))).toBe(true); + for (const name of ["tesseract.js", "tesseract.js-core", "node-fetch"]) + expect(existsSync(path.join(output, "node_modules", name))).toBe(false); +}); diff --git a/docs/desktop-release.md b/docs/desktop-release.md index c312bf1a..9ad48983 100644 --- a/docs/desktop-release.md +++ b/docs/desktop-release.md @@ -456,5 +456,7 @@ Node.js into its own folder, removing `com.apple.quarantine` on macOS; packages and needs no registry. On Linux the services need glibc 2.35 (Ubuntu 22.04, Debian 12), like the PostgreSQL build; with an older glibc the desktop leaves them out and Native installs from the network. Model data -(Voice) is not bundled: Node Services downloads it on first use. +(Voice) is not bundled: Node Services downloads it on first use. Dependencies +the services never load are left out too: officeparser imports its OCR +engine, tesseract.js, only for OCR, which document extraction never asks for. Intel Macs have none of this and install from the network.