diff --git a/package.json b/package.json index 874df05..1a9a8a6 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "bgent", - "version": "0.1.9", + "version": "0.1.10", "private": false, "description": "bgent. because agent was taken.", "type": "module", diff --git a/src/lib/adapters/sqlite/sqlite_vss.ts b/src/lib/adapters/sqlite/sqlite_vss.ts index 0139a47..dc3f5bc 100644 --- a/src/lib/adapters/sqlite/sqlite_vss.ts +++ b/src/lib/adapters/sqlite/sqlite_vss.ts @@ -1,7 +1,3 @@ -import { statSync } from "fs"; -import { join } from "path"; -import { arch, platform } from "process"; - // TypeScript definitions export interface Database { loadExtension(file: string, entrypoint?: string | undefined): void; @@ -28,7 +24,9 @@ function platformPackageName(platform: string, arch: string): string { return `sqlite-vss-${os}-${arch}`; } -function loadablePathResolver(name: string): string { +async function loadablePathResolver(name: string): Promise { + const { platform, arch } = await import("process"); + if (!validPlatform(platform, arch)) { throw new Error( `Unsupported platform for sqlite-vss, on a ${platform}-${arch} machine, but not in supported platforms (${supportedPlatforms @@ -37,6 +35,9 @@ function loadablePathResolver(name: string): string { ); } + const { join } = await import("path"); + const { statSync } = await import("fs"); + const packageName = platformPackageName(platform, arch); let loadablePath = join( __dirname, @@ -50,7 +51,7 @@ function loadablePathResolver(name: string): string { `${name}.${extensionSuffix(platform)}`, ); - // if loadable path doesnt exist, check path2 + // if loadable path doesn't exist, check path2 if (!statSync(loadablePath, { throwIfNoEntry: false })) { loadablePath = join( __dirname, @@ -72,23 +73,25 @@ function loadablePathResolver(name: string): string { return loadablePath; } -export function getVectorLoadablePath(): string { +export async function getVectorLoadablePath(): Promise { return loadablePathResolver("vector0"); } -export function getVssLoadablePath(): string { +export async function getVssLoadablePath(): Promise { return loadablePathResolver("vss0"); } -export function loadVector(db: Database): void { - db.loadExtension(getVectorLoadablePath()); +export async function loadVector(db: Database): Promise { + const loadablePath = await getVectorLoadablePath(); + db.loadExtension(loadablePath); } -export function loadVss(db: Database): void { - db.loadExtension(getVssLoadablePath()); +export async function loadVss(db: Database): Promise { + const loadablePath = await getVssLoadablePath(); + db.loadExtension(loadablePath); } -export function load(db: Database): void { - loadVector(db); - loadVss(db); -} +export async function load(db: Database): Promise { + await loadVector(db); + await loadVss(db); +} \ No newline at end of file diff --git a/src/test/createRuntime.ts b/src/test/createRuntime.ts index c7cf06b..a6c0776 100644 --- a/src/test/createRuntime.ts +++ b/src/test/createRuntime.ts @@ -44,7 +44,7 @@ export async function createRuntime({ adapter = new SqliteDatabaseAdapter(new Database(":memory:")); // Load sqlite-vss - load((adapter as SqliteDatabaseAdapter).db); + await load((adapter as SqliteDatabaseAdapter).db); // Create a test user and session user = { id: zeroUuid,