@kodelyth/memory-lancedb 2026.5.42 → 2026.6.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -1,77 +0,0 @@
1
- type LanceDbModule = typeof import("@lancedb/lancedb");
2
-
3
- export type LanceDbRuntimeLogger = {
4
- info?: (message: string) => void;
5
- warn?: (message: string) => void;
6
- };
7
-
8
- type LanceDbRuntimeLoaderDeps = {
9
- platform: NodeJS.Platform;
10
- arch: NodeJS.Architecture;
11
- importBundled: () => Promise<LanceDbModule>;
12
- };
13
-
14
- function buildLoadFailureMessage(error: unknown): string {
15
- return [
16
- "memory-lancedb: bundled @lancedb/lancedb dependency is unavailable.",
17
- "Install or repair the memory-lancedb plugin package dependencies, then restart Klaw.",
18
- String(error),
19
- ].join(" ");
20
- }
21
-
22
- function isUnsupportedNativePlatform(params: {
23
- platform: NodeJS.Platform;
24
- arch: NodeJS.Architecture;
25
- }): boolean {
26
- return params.platform === "darwin" && params.arch === "x64";
27
- }
28
-
29
- function buildUnsupportedNativePlatformMessage(params: {
30
- platform: NodeJS.Platform;
31
- arch: NodeJS.Architecture;
32
- }): string {
33
- return [
34
- `memory-lancedb: LanceDB runtime is unavailable on ${params.platform}-${params.arch}.`,
35
- "The bundled @lancedb/lancedb dependency does not publish a native package for this platform.",
36
- "Disable memory-lancedb or switch to a supported memory backend/platform.",
37
- ].join(" ");
38
- }
39
-
40
- export function createLanceDbRuntimeLoader(overrides: Partial<LanceDbRuntimeLoaderDeps> = {}): {
41
- load: (loggerInstance?: LanceDbRuntimeLogger) => Promise<LanceDbModule>;
42
- } {
43
- const deps: LanceDbRuntimeLoaderDeps = {
44
- platform: overrides.platform ?? process.platform,
45
- arch: overrides.arch ?? process.arch,
46
- importBundled: overrides.importBundled ?? (() => import("@lancedb/lancedb")),
47
- };
48
-
49
- let loadPromise: Promise<LanceDbModule> | null = null;
50
-
51
- return {
52
- async load(_logger?: LanceDbRuntimeLogger): Promise<LanceDbModule> {
53
- if (!loadPromise) {
54
- loadPromise = deps.importBundled().catch((error) => {
55
- loadPromise = null;
56
- if (isUnsupportedNativePlatform({ platform: deps.platform, arch: deps.arch })) {
57
- throw new Error(
58
- buildUnsupportedNativePlatformMessage({
59
- platform: deps.platform,
60
- arch: deps.arch,
61
- }),
62
- { cause: error },
63
- );
64
- }
65
- throw new Error(buildLoadFailureMessage(error), { cause: error });
66
- });
67
- }
68
- return await loadPromise;
69
- },
70
- };
71
- }
72
-
73
- const defaultLoader = createLanceDbRuntimeLoader();
74
-
75
- export async function loadLanceDbModule(logger?: LanceDbRuntimeLogger): Promise<LanceDbModule> {
76
- return await defaultLoader.load(logger);
77
- }
@@ -1,121 +0,0 @@
1
- import { describe, expect, test } from "vitest";
2
- import { installTmpDirHarness } from "./test-helpers.js";
3
-
4
- const OPENAI_API_KEY = process.env.OPENAI_API_KEY ?? "";
5
- const HAS_OPENAI_KEY = Boolean(process.env.OPENAI_API_KEY);
6
- const liveEnabled = HAS_OPENAI_KEY && process.env.KLAW_LIVE_TEST === "1";
7
- const describeLive = liveEnabled ? describe : describe.skip;
8
-
9
- // Live tests that require OpenAI API key and actually use LanceDB
10
- describeLive("memory plugin live tests", () => {
11
- const { getDbPath } = installTmpDirHarness({ prefix: "klaw-memory-live-" });
12
-
13
- test("memory tools work end-to-end", async () => {
14
- const { default: memoryPlugin } = await import("./index.js");
15
- const liveApiKey = OPENAI_API_KEY;
16
-
17
- // Mock plugin API
18
- const registeredTools: any[] = [];
19
- const registeredClis: any[] = [];
20
- const registeredServices: any[] = [];
21
- const registeredHooks: Record<string, any[]> = {};
22
- const logs: string[] = [];
23
-
24
- const mockApi = {
25
- id: "memory-lancedb",
26
- name: "Memory (LanceDB)",
27
- source: "test",
28
- config: {},
29
- pluginConfig: {
30
- embedding: {
31
- apiKey: liveApiKey,
32
- model: "text-embedding-3-small",
33
- },
34
- dbPath: getDbPath(),
35
- autoCapture: false,
36
- autoRecall: false,
37
- },
38
- runtime: {},
39
- logger: {
40
- info: (msg: string) => logs.push(`[info] ${msg}`),
41
- warn: (msg: string) => logs.push(`[warn] ${msg}`),
42
- error: (msg: string) => logs.push(`[error] ${msg}`),
43
- debug: (msg: string) => logs.push(`[debug] ${msg}`),
44
- },
45
- registerTool: (tool: any, opts: any) => {
46
- registeredTools.push({ tool, opts });
47
- },
48
- registerCli: (registrar: any, opts: any) => {
49
- registeredClis.push({ registrar, opts });
50
- },
51
- registerService: (service: any) => {
52
- registeredServices.push(service);
53
- },
54
- on: (hookName: string, handler: any) => {
55
- if (!registeredHooks[hookName]) {
56
- registeredHooks[hookName] = [];
57
- }
58
- registeredHooks[hookName].push(handler);
59
- },
60
- resolvePath: (p: string) => p,
61
- };
62
-
63
- // Register plugin
64
- memoryPlugin.register(mockApi as any);
65
-
66
- // Check registration
67
- expect(registeredTools.length).toBe(3);
68
- expect(registeredTools.map((t) => t.opts?.name)).toContain("memory_recall");
69
- expect(registeredTools.map((t) => t.opts?.name)).toContain("memory_store");
70
- expect(registeredTools.map((t) => t.opts?.name)).toContain("memory_forget");
71
- expect(registeredClis.length).toBe(1);
72
- expect(registeredServices.length).toBe(1);
73
-
74
- // Get tool functions
75
- const storeTool = registeredTools.find((t) => t.opts?.name === "memory_store")?.tool;
76
- const recallTool = registeredTools.find((t) => t.opts?.name === "memory_recall")?.tool;
77
- const forgetTool = registeredTools.find((t) => t.opts?.name === "memory_forget")?.tool;
78
-
79
- // Test store
80
- const storeResult = await storeTool.execute("test-call-1", {
81
- text: "The user prefers dark mode for all applications",
82
- importance: 0.8,
83
- category: "preference",
84
- });
85
-
86
- expect(storeResult.details?.action).toBe("created");
87
- const storedId = storeResult.details?.id;
88
- expect(storedId).toMatch(/.+/);
89
-
90
- // Test recall
91
- const recallResult = await recallTool.execute("test-call-2", {
92
- query: "dark mode preference",
93
- limit: 5,
94
- });
95
-
96
- expect(recallResult.details?.count).toBeGreaterThan(0);
97
- expect(recallResult.details?.memories?.[0]?.text).toContain("dark mode");
98
-
99
- // Test duplicate detection
100
- const duplicateResult = await storeTool.execute("test-call-3", {
101
- text: "The user prefers dark mode for all applications",
102
- });
103
-
104
- expect(duplicateResult.details?.action).toBe("duplicate");
105
-
106
- // Test forget
107
- const forgetResult = await forgetTool.execute("test-call-4", {
108
- memoryId: storedId,
109
- });
110
-
111
- expect(forgetResult.details?.action).toBe("deleted");
112
-
113
- // Verify it's gone
114
- const recallAfterForget = await recallTool.execute("test-call-5", {
115
- query: "dark mode preference",
116
- limit: 5,
117
- });
118
-
119
- expect(recallAfterForget.details?.count).toBe(0);
120
- }, 60000); // 60s timeout for live API calls
121
- });
package/test-helpers.ts DELETED
@@ -1,25 +0,0 @@
1
- import fs from "node:fs/promises";
2
- import path from "node:path";
3
- import { resolvePreferredKlawTmpDir } from "klaw/plugin-sdk/temp-path";
4
- import { afterEach, beforeEach } from "vitest";
5
-
6
- export function installTmpDirHarness(params: { prefix: string }) {
7
- let tmpDir = "";
8
- let dbPath = "";
9
-
10
- beforeEach(async () => {
11
- tmpDir = await fs.mkdtemp(path.join(resolvePreferredKlawTmpDir(), params.prefix));
12
- dbPath = path.join(tmpDir, "lancedb");
13
- });
14
-
15
- afterEach(async () => {
16
- if (tmpDir) {
17
- await fs.rm(tmpDir, { recursive: true, force: true });
18
- }
19
- });
20
-
21
- return {
22
- getTmpDir: () => tmpDir,
23
- getDbPath: () => dbPath,
24
- };
25
- }
package/tsconfig.json DELETED
@@ -1,16 +0,0 @@
1
- {
2
- "extends": "../tsconfig.package-boundary.base.json",
3
- "compilerOptions": {
4
- "rootDir": "."
5
- },
6
- "include": ["./*.ts", "./src/**/*.ts"],
7
- "exclude": [
8
- "./**/*.test.ts",
9
- "./dist/**",
10
- "./node_modules/**",
11
- "./src/test-support/**",
12
- "./src/**/*test-helpers.ts",
13
- "./src/**/*test-harness.ts",
14
- "./src/**/*test-support.ts"
15
- ]
16
- }