From 63efac07927df060b5691d12a1eb1b791d9c806c Mon Sep 17 00:00:00 2001 From: Johnny Date: Wed, 28 Jan 2026 11:12:42 +0800 Subject: [PATCH] fix(memory-lancedb): lazy-load LanceDB --- extensions/memory-lancedb/index.ts | 23 ++++++++++++++++++++--- 1 file changed, 20 insertions(+), 3 deletions(-) diff --git a/extensions/memory-lancedb/index.ts b/extensions/memory-lancedb/index.ts index 7f9f082c1..e4e34932b 100644 --- a/extensions/memory-lancedb/index.ts +++ b/extensions/memory-lancedb/index.ts @@ -7,11 +7,11 @@ */ import { Type } from "@sinclair/typebox"; -import * as lancedb from "@lancedb/lancedb"; import OpenAI from "openai"; import { randomUUID } from "node:crypto"; import type { ClawdbotPluginApi } from "clawdbot/plugin-sdk"; import { stringEnum } from "clawdbot/plugin-sdk"; +import type { Connection, Table } from "@lancedb/lancedb"; import { MEMORY_CATEGORIES, @@ -44,9 +44,25 @@ type MemorySearchResult = { const TABLE_NAME = "memories"; +type LanceDbModule = typeof import("@lancedb/lancedb"); + +let lancedbModulePromise: Promise | null = null; + +async function loadLanceDb(): Promise { + if (!lancedbModulePromise) { + // Lazily load LanceDB so the plugin module can be imported in environments where + // the platform-native optional dependency isn't available (e.g. CI, unsupported arch). + lancedbModulePromise = import("@lancedb/lancedb").catch((err) => { + lancedbModulePromise = null; + throw err; + }); + } + return await lancedbModulePromise; +} + class MemoryDB { - private db: lancedb.Connection | null = null; - private table: lancedb.Table | null = null; + private db: Connection | null = null; + private table: Table | null = null; private initPromise: Promise | null = null; constructor( @@ -63,6 +79,7 @@ class MemoryDB { } private async doInitialize(): Promise { + const lancedb = await loadLanceDb(); this.db = await lancedb.connect(this.dbPath); const tables = await this.db.tableNames();