Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -198,7 +198,6 @@ func codexProjectServer(server map[string]any) map[string]any {
}
delete(out, "headers")
}
out["experimental_use_rmcp_client"] = true
}
return out
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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" {
Expand Down
9 changes: 9 additions & 0 deletions apps/desktop/scripts/build-native-runtime.d.mts
Original file line number Diff line number Diff line change
@@ -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<string, string>;
}>;
7 changes: 7 additions & 0 deletions apps/desktop/scripts/build-native-runtime.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -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}`);

Expand Down Expand Up @@ -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)
Expand Down
57 changes: 57 additions & 0 deletions apps/desktop/src/main/build-native-runtime.test.ts
Original file line number Diff line number Diff line change
@@ -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<string, string> = {}) => {
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);
});
4 changes: 3 additions & 1 deletion docs/desktop-release.md
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Loading