diff --git a/electron/package.json b/electron/package.json index 60a0ada9bf..a2bb7614b5 100644 --- a/electron/package.json +++ b/electron/package.json @@ -43,7 +43,8 @@ "appId": "online.omniroute.desktop", "productName": "OmniRoute", "copyright": "Copyright © 2025 OmniRoute", - "buildDependenciesFromSource": true, + "buildDependenciesFromSource": false, + "npmRebuild": false, "directories": { "output": "dist-electron", "buildResources": "assets" diff --git a/open-sse/mcp-server/audit.ts b/open-sse/mcp-server/audit.ts index 40e023212c..da1e4eaf8f 100644 --- a/open-sse/mcp-server/audit.ts +++ b/open-sse/mcp-server/audit.ts @@ -207,7 +207,10 @@ function toString(value: unknown): string { } async function openBetterSqliteAuditDb(dbPath: string): Promise { - const Database = (await import("better-sqlite3")).default as unknown as new ( + const { createRequire } = await import("node:module"); + const _require = createRequire(import.meta.url); + const mod = _require("better-sqlite3"); + const Database = (mod?.default || mod) as unknown as new ( dbPath: string ) => AuditDatabase; return new Database(dbPath); diff --git a/src/lib/db/omp.ts b/src/lib/db/omp.ts index c6356fc42a..34c6b071ea 100644 --- a/src/lib/db/omp.ts +++ b/src/lib/db/omp.ts @@ -3,6 +3,16 @@ import path from "path"; import { createRequire } from "node:module"; const _require = createRequire(import.meta.url); +function getDatabaseClass() { + try { + if (process.versions.bun) { + return _require("bun:sqlite").Database; + } + return _require("better-sqlite3"); + } catch { + return null; + } +} const Database = process.versions.bun ? (_require("bun:sqlite").Database as typeof import("better-sqlite3")) : (_require("better-sqlite3") as typeof import("better-sqlite3")); @@ -15,6 +25,8 @@ const getOmpDir = () => path.join(os.homedir(), ".omp", "agent"); const getOmpDbPath = () => path.join(getOmpDir(), "agent.db"); export function getOmpCredentials(providerId: string) { + const Database = getDatabaseClass(); + if (!Database) return { hasOmniRoute: false, baseUrl: null, apiKey: null }; const dbPath = getOmpDbPath(); try { const db = new Database(dbPath, databaseOptions(true)); @@ -36,6 +48,8 @@ export function getOmpCredentials(providerId: string) { } export function saveOmpCredentials(providerId: string, apiKey: string, baseUrl: string) { + const Database = getDatabaseClass(); + if (!Database) return; const dbPath = getOmpDbPath(); const db = new Database(dbPath, databaseOptions()); @@ -54,6 +68,8 @@ export function saveOmpCredentials(providerId: string, apiKey: string, baseUrl: } export function deleteOmpCredentials(providerId: string) { + const Database = getDatabaseClass(); + if (!Database) return; const dbPath = getOmpDbPath(); const db = new Database(dbPath, databaseOptions()); db.prepare("DELETE FROM auth_credentials WHERE provider = ?").run(providerId);