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
TypeScript a2aai-agentsai-gatewayanthropicclaudeclaude-codeclinecodexcopilotcursordeepseekfree-aigeminikimillm-gatewaymcpopenaiopenai-proxyqwentoken-saver
fix: resolve macOS Electron ABI mismatch and test regressions (#1081)
diegosouzapwd4609762bbb5
diff --git a/electron/main.js b/electron/main.jsindex 173702520f..ac2c8fa7e7 100644--- a/electron/main.js+++ b/electron/main.js@@ -66,22 +66,9 @@ let isServerStopped = false;const getServerUrl = () => `http://localhost:${serverPort}`;function resolveNodeExecutable(env = process.env) {- const candidates = [- env.OMNIROUTE_NODE_PATH,- "/usr/local/bin/node",- "/opt/homebrew/bin/node",- "/opt/local/bin/node",- ].filter(Boolean);-- for (const candidate of candidates) {- try {- if (fs.existsSync(candidate)) return candidate;- } catch {- /* continue */- }- }-- return "node";+ // #1081: Ensure Next.js standalone runs using Electron's Node runtime+ // instead of a randomly found system Node to prevent ABI architecture mismatches.+ return process.execPath;}function resolveDataDir(overridePath, env = process.env) {@@ -550,6 +537,8 @@ function startNextServer() {DATA_DIR: dataDir,PORT: String(serverPort),NODE_ENV: "production",+ ELECTRON_RUN_AS_NODE: "1",+ NODE_PATH: path.join(process.resourcesPath, "app.asar.unpacked", "node_modules"),},stdio: "pipe",});diff --git a/electron/package.json b/electron/package.jsonindex 7d14ff785c..66134251bc 100644--- a/electron/package.json+++ b/electron/package.json@@ -22,6 +22,7 @@"pack": "npm run prepare:bundle && electron-builder --dir"},"dependencies": {+ "better-sqlite3": "^12.8.0","electron-updater": "^6.8.3"},"devDependencies": {diff --git a/open-sse/executors/base.ts b/open-sse/executors/base.tsindex 33606f19b8..f57e4010e0 100644--- a/open-sse/executors/base.ts+++ b/open-sse/executors/base.ts@@ -240,8 +240,8 @@ export class BaseExecutor {return null;}- needsRefresh(credentials: ProviderCredentials) {- if (!credentials.expiresAt) return false;+ needsRefresh(credentials?: ProviderCredentials | null) {+ if (!credentials?.expiresAt) return false;const expiresAtMs = new Date(credentials.expiresAt).getTime();return expiresAtMs - Date.now() < 5 * 60 * 1000;}diff --git a/scripts/prepare-electron-standalone.mjs b/scripts/prepare-electron-standalone.mjsindex cc8cef1cb1..08810062fd 100644--- a/scripts/prepare-electron-standalone.mjs+++ b/scripts/prepare-electron-standalone.mjs@@ -84,9 +84,7 @@ function ensurePackage(pkgPath, sourcePath) {}function removeGeneratedElectronArtifacts() {- const generatedDirs = [- join(ELECTRON_STANDALONE_DIR, "electron", "dist-electron"),- ];+ const generatedDirs = [join(ELECTRON_STANDALONE_DIR, "electron", "dist-electron")];for (const dir of generatedDirs) {rmSync(dir, { recursive: true, force: true });@@ -148,10 +146,7 @@ ensurePackage(join(ROOT, "node_modules", "@swc", "helpers"));-ensurePackage(- join(ELECTRON_STANDALONE_DIR, "node_modules", "better-sqlite3"),- join(ROOT, "node_modules", "better-sqlite3")-);+// removed better-sqlite3 to ensure ABI compatibility via electron-builderconsole.log(`[electron] prepared standalone bundle: ${relative(ROOT, ELECTRON_STANDALONE_DIR) || "."}`diff --git a/src/shared/utils/apiAuth.ts b/src/shared/utils/apiAuth.tsindex 195d3ecd18..c5e7d0c7e4 100644--- a/src/shared/utils/apiAuth.ts+++ b/src/shared/utils/apiAuth.ts@@ -63,16 +63,19 @@ export async function verifyAuth(request: any): Promise<string | null> {}// 2. Check Bearer API key- const authHeader = request.headers.get("authorization");- if (authHeader?.startsWith("Bearer ")) {- const apiKey = authHeader.slice(7);- try {- // Dynamic import to avoid circular dependencies during build- const { validateApiKey } = await import("@/lib/db/apiKeys");- const isValid = await validateApiKey(apiKey);- if (isValid) return null; // ✔ Authenticated via API key- } catch {- // DB not ready or import error — deny access+ const authHeader = request.headers.get("authorization") || request.headers.get("Authorization");+ if (typeof authHeader === "string") {+ const trimmedHeader = authHeader.trim();+ if (trimmedHeader.toLowerCase().startsWith("bearer ")) {+ const apiKey = trimmedHeader.slice(7).trim();+ try {+ // Dynamic import to avoid circular dependencies during build+ const { validateApiKey } = await import("@/lib/db/apiKeys");+ const isValid = await validateApiKey(apiKey);+ if (isValid) return null; // ✔ Authenticated via API key+ } catch {+ // DB not ready or import error — deny access+ }}}@@ -94,14 +97,17 @@ export async function isAuthenticated(request: Request): Promise<boolean> {return true;}// 1. Check API key (for external clients)- const authHeader = request.headers.get("authorization");- if (authHeader?.startsWith("Bearer ")) {- const apiKey = authHeader.slice(7);- try {- const { validateApiKey } = await import("@/lib/db/apiKeys");- if (await validateApiKey(apiKey)) return true;- } catch {- // DB not ready or import error+ const authHeader = request.headers.get("authorization") || request.headers.get("Authorization");+ if (typeof authHeader === "string") {+ const trimmedHeader = authHeader.trim();+ if (trimmedHeader.toLowerCase().startsWith("bearer ")) {+ const apiKey = trimmedHeader.slice(7).trim();+ try {+ const { validateApiKey } = await import("@/lib/db/apiKeys");+ if (await validateApiKey(apiKey)) return true;+ } catch {+ // DB not ready or import error+ }}}diff --git a/src/sse/services/auth.ts b/src/sse/services/auth.tsindex 06d15f29f6..d5d32c03d7 100644--- a/src/sse/services/auth.ts+++ b/src/sse/services/auth.ts@@ -1010,11 +1010,15 @@ export async function clearRecoveredProviderState(/*** Extract API key from request headers+ * Follows management API standard: case-insensitive bearer matching and full trimming*/export function extractApiKey(request: Request) {- const authHeader = request.headers.get("Authorization");- if (authHeader?.startsWith("Bearer ")) {- return authHeader.slice(7);+ const authHeader = request.headers.get("Authorization") || request.headers.get("authorization");+ if (typeof authHeader === "string") {+ const trimmedHeader = authHeader.trim();+ if (trimmedHeader.toLowerCase().startsWith("bearer ")) {+ return trimmedHeader.slice(7).trim();+ }}return null;}diff --git a/tests/unit/chatcore-translation-paths.test.mjs b/tests/unit/chatcore-translation-paths.test.mjsindex eee58c5279..42a9909072 100644--- a/tests/unit/chatcore-translation-paths.test.mjs+++ b/tests/unit/chatcore-translation-paths.test.mjs@@ -930,7 +930,13 @@ test("chatCore fallback proxy mode retries through CLIProxyAPI after retryable nconst { calls, result } = await invokeChatCore({provider: "github",model: "gpt-4o",- credentials: { accessToken: "gh-token", providerSpecificData: {} },+ credentials: {+ accessToken: "gh-token",+ providerSpecificData: {+ copilotToken: "mock-token",+ copilotTokenExpiresAt: Date.now() + 3600000,+ },+ },body: {model: "gpt-4o",messages: [{ role: "user", content: "hello" }],@@ -965,7 +971,13 @@ test("chatCore fallback proxy mode surfaces CLIProxyAPI errors after a retryableconst { calls, result } = await invokeChatCore({provider: "github",model: "gpt-4o",- credentials: { accessToken: "gh-token", providerSpecificData: {} },+ credentials: {+ accessToken: "gh-token",+ providerSpecificData: {+ copilotToken: "mock-token",+ copilotTokenExpiresAt: Date.now() + 3600000,+ },+ },body: {model: "gpt-4o",messages: [{ role: "user", content: "hello" }],@@ -1000,7 +1012,13 @@ test("chatCore fallback proxy mode surfaces CLIProxyAPI errors after native execconst { calls, result } = await invokeChatCore({provider: "github",model: "gpt-4o",- credentials: { accessToken: "gh-token", providerSpecificData: {} },+ credentials: {+ accessToken: "gh-token",+ providerSpecificData: {+ copilotToken: "mock-token",+ copilotTokenExpiresAt: Date.now() + 3600000,+ },+ },body: {model: "gpt-4o",messages: [{ role: "user", content: "hello" }],diff --git a/tests/unit/db-settings-crud.test.mjs b/tests/unit/db-settings-crud.test.mjsindex 54242610ff..7dd75eaba8 100644--- a/tests/unit/db-settings-crud.test.mjs+++ b/tests/unit/db-settings-crud.test.mjs@@ -676,7 +676,11 @@ test("cache metrics and trend coerce null aggregate fields to zero", async () =>db.prepare = (sql) => {const text = String(sql);- if (text.includes("COUNT(*) as totalRequests") && text.includes("tokens_cache_read > 0")) {+ if (+ text.includes("COUNT(*) as totalRequests") &&+ text.includes("SUM(tokens_input) as totalInputTokens") &&+ !text.includes("GROUP BY")+ ) {return {get: () => ({totalRequests: 2,@@ -687,7 +691,7 @@ test("cache metrics and trend coerce null aggregate fields to zero", async () =>};}- if (text.includes("SELECT COUNT(*) as totalRequests") && text.includes("FROM usage_history")) {+ if (text.match(/SELECT\s+COUNT\(\*\)\s+as\s+totalRequests\s+FROM\s+usage_history\s*$/)) {return {get: () => ({totalRequests: 5,@@ -700,7 +704,8 @@ test("cache metrics and trend coerce null aggregate fields to zero", async () =>all: () => [{provider: "openai",- requests: 1,+ totalRequests: 1,+ cachedRequests: 1,inputTokens: null,cachedTokens: null,cacheCreationTokens: null,@@ -753,6 +758,8 @@ test("cache metrics and trend coerce null aggregate fields to zero", async () =>assert.equal(metrics.totalCacheCreationTokens, 0);assert.deepEqual(metrics.byProvider.openai, {requests: 1,+ totalRequests: 1,+ cachedRequests: 1,inputTokens: 0,cachedTokens: 0,cacheCreationTokens: 0,