Skip to content

Never stop coding. Free MIT AI gateway: one endpoint, 375 providers (150+ free), 1,400+ models Kimi, Claude, GPT, Gemini, GLM, DeepSeek, MiniMax. Works with Claude Code, Codex, Cursor, OpenCode, Cline & Copilot. Quota-aware auto-fallback, RTK+Caveman compression saves 15-95% tokens, MCP/A2A, Desktop/PWA. Built by 900+ contributors

fix: resolve Windows machine ID failure due to node-machine-id bundle-time platform detection

Sajid03bd2b6803a6
diff --git a/src/shared/utils/machineId.ts b/src/shared/utils/machineId.ts
index ef405693c3..9d64151a09 100644
--- a/src/shared/utils/machineId.ts
+++ b/src/shared/utils/machineId.ts
@@ -1,17 +1,47 @@
-import { machineIdSync } from "node-machine-id";
+import { execSync } from "child_process";
+
+function getMachineIdRaw(): string {
+ if (process.platform === "win32") {
+ const sysRoot = process.env.SystemRoot || process.env.windir || "C:\\Windows";
+ const output = execSync(
+ `"${sysRoot}\\System32\\REG.exe" QUERY "HKEY_LOCAL_MACHINE\\SOFTWARE\\Microsoft\\Cryptography" /v MachineGuid`,
+ { encoding: "utf8" }
+ );
+ return output
+ .toString()
+ .split("REG_SZ")[1]
+ .replace(/\r+|\n+|\s+/gi, "")
+ .toLowerCase();
+ }
+ if (process.platform === "darwin") {
+ const output = execSync("ioreg -rd1 -c IOPlatformExpertDevice", { encoding: "utf8" });
+ return output
+ .split("IOPlatformUUID")[1]
+ .split("\n")[0]
+ .replace(/\=|\s+|\"/gi, "")
+ .toLowerCase();
+ }
+ const output = execSync(
+ "( cat /var/lib/dbus/machine-id /etc/machine-id 2> /dev/null || hostname ) | head -n 1 || :",
+ { encoding: "utf8" }
+ );
+ return output
+ .toString()
+ .replace(/\r+|\n+|\s+/gi, "")
+ .toLowerCase();
+}
/**
- * Get consistent machine ID using node-machine-id with salt
+ * Get consistent machine ID using native registry/OS query with salt
* This ensures the same physical machine gets the same ID across runs
*
* @param {string} salt - Optional salt to use (defaults to environment variable)
* @returns {Promise<string>} Machine ID (16-character base32)
*/
export async function getConsistentMachineId(salt = null) {
- // For server-side, use node-machine-id with salt
const saltValue = salt || process.env.MACHINE_ID_SALT || "endpoint-proxy-salt";
try {
- const rawMachineId = machineIdSync();
+ const rawMachineId = getMachineIdRaw();
// Create consistent ID using salt
const crypto = await import("crypto");
const hashedMachineId = crypto
@@ -38,9 +68,8 @@ export async function getConsistentMachineId(salt = null) {
* @returns {Promise<string>} Raw machine ID
*/
export async function getRawMachineId() {
- // For server-side, use raw node-machine-id
try {
- return machineIdSync();
+ return getMachineIdRaw();
} catch (error) {
console.log("Error getting raw machine ID:", error);
// Fallback to random ID if node-machine-id fails