This PR expands `.github/workflows/rust-release.yml` so that it also builds and publishes the `npm` module for `@openai/codex-responses-api-proxy` in addition to `@openai/codex`. Note both `npm` modules are similar, in that they each contain a single `.js` file that is a thin launcher around the appropriate native executable. (Since we have a minimal dependency on Node.js, I also lowered the minimum version from 20 to 16 and verified that works on my machine.) As part of this change, we tighten up some of the docs around `codex-responses-api-proxy` and ensure the details regarding protecting the `OPENAI_API_KEY` in memory match the implementation. To test the `npm` build process, I ran: ``` ./codex-cli/scripts/build_npm_package.py --package codex-responses-api-proxy --version 0.43.0-alpha.3 ``` which stages the `npm` module for `@openai/codex-responses-api-proxy` in a temp directory, using the binary artifacts from https://github.com/openai/codex/releases/tag/rust-v0.43.0-alpha.3.
98 lines
2.2 KiB
JavaScript
Executable File
98 lines
2.2 KiB
JavaScript
Executable File
#!/usr/bin/env node
|
|
// Entry point for the Codex responses API proxy binary.
|
|
|
|
import { spawn } from "node:child_process";
|
|
import path from "path";
|
|
import { fileURLToPath } from "url";
|
|
|
|
const __filename = fileURLToPath(import.meta.url);
|
|
const __dirname = path.dirname(__filename);
|
|
|
|
function determineTargetTriple(platform, arch) {
|
|
switch (platform) {
|
|
case "linux":
|
|
case "android":
|
|
if (arch === "x64") {
|
|
return "x86_64-unknown-linux-musl";
|
|
}
|
|
if (arch === "arm64") {
|
|
return "aarch64-unknown-linux-musl";
|
|
}
|
|
break;
|
|
case "darwin":
|
|
if (arch === "x64") {
|
|
return "x86_64-apple-darwin";
|
|
}
|
|
if (arch === "arm64") {
|
|
return "aarch64-apple-darwin";
|
|
}
|
|
break;
|
|
case "win32":
|
|
if (arch === "x64") {
|
|
return "x86_64-pc-windows-msvc";
|
|
}
|
|
if (arch === "arm64") {
|
|
return "aarch64-pc-windows-msvc";
|
|
}
|
|
break;
|
|
default:
|
|
break;
|
|
}
|
|
return null;
|
|
}
|
|
|
|
const targetTriple = determineTargetTriple(process.platform, process.arch);
|
|
if (!targetTriple) {
|
|
throw new Error(
|
|
`Unsupported platform: ${process.platform} (${process.arch})`,
|
|
);
|
|
}
|
|
|
|
const vendorRoot = path.join(__dirname, "..", "vendor");
|
|
const archRoot = path.join(vendorRoot, targetTriple);
|
|
const binaryBaseName = "codex-responses-api-proxy";
|
|
const binaryPath = path.join(
|
|
archRoot,
|
|
binaryBaseName,
|
|
process.platform === "win32" ? `${binaryBaseName}.exe` : binaryBaseName,
|
|
);
|
|
|
|
const child = spawn(binaryPath, process.argv.slice(2), {
|
|
stdio: "inherit",
|
|
});
|
|
|
|
child.on("error", (err) => {
|
|
console.error(err);
|
|
process.exit(1);
|
|
});
|
|
|
|
const forwardSignal = (signal) => {
|
|
if (!child.killed) {
|
|
try {
|
|
child.kill(signal);
|
|
} catch {
|
|
/* ignore */
|
|
}
|
|
}
|
|
};
|
|
|
|
["SIGINT", "SIGTERM", "SIGHUP"].forEach((sig) => {
|
|
process.on(sig, () => forwardSignal(sig));
|
|
});
|
|
|
|
const childResult = await new Promise((resolve) => {
|
|
child.on("exit", (code, signal) => {
|
|
if (signal) {
|
|
resolve({ type: "signal", signal });
|
|
} else {
|
|
resolve({ type: "code", exitCode: code ?? 1 });
|
|
}
|
|
});
|
|
});
|
|
|
|
if (childResult.type === "signal") {
|
|
process.kill(process.pid, childResult.signal);
|
|
} else {
|
|
process.exit(childResult.exitCode);
|
|
}
|