fix: adding skills config and updating the plugin the config (#4958)

This commit is contained in:
Kartik
2026-04-29 22:19:40 +05:30
committed by GitHub
parent 594b4e65d6
commit ebb9bb2b15
20 changed files with 585 additions and 176 deletions
+3 -1
View File
@@ -16,6 +16,7 @@ vi.mock("../cli/config-file.ts", () => ({
readPluginAuth: vi.fn().mockReturnValue({}),
writePluginAuth: vi.fn(),
writePluginConfigField: vi.fn(),
enableSkillsConfig: vi.fn(),
getBaseUrl: vi.fn().mockReturnValue("https://api.mem0.ai"),
OPENCLAW_CONFIG_FILE: "/mock/.openclaw/openclaw.json",
}));
@@ -42,6 +43,7 @@ import {
readPluginAuth,
writePluginAuth,
writePluginConfigField,
enableSkillsConfig,
getBaseUrl,
} from "../cli/config-file.ts";
import { loadDreamPrompt } from "../skill-loader.ts";
@@ -178,7 +180,7 @@ function createMockCfg() {
topK: 5,
autoCapture: true,
autoRecall: true,
searchThreshold: 0.5,
searchThreshold: 0.1,
customInstructions: "",
customCategories: {},
skills: {},
+6 -6
View File
@@ -44,14 +44,14 @@ describe("mem0ConfigSchema.parse() — defaults", () => {
expect(cfg.userId.length).toBeGreaterThan(0);
});
it("autoCapture defaults to false", () => {
it("autoCapture defaults to true", () => {
const cfg = mem0ConfigSchema.parse({ apiKey: "test-key" });
expect(cfg.autoCapture).toBe(false);
expect(cfg.autoCapture).toBe(true);
});
it("autoRecall defaults to false", () => {
it("autoRecall defaults to true", () => {
const cfg = mem0ConfigSchema.parse({ apiKey: "test-key" });
expect(cfg.autoRecall).toBe(false);
expect(cfg.autoRecall).toBe(true);
});
it("topK defaults to 5", () => {
@@ -59,9 +59,9 @@ describe("mem0ConfigSchema.parse() — defaults", () => {
expect(cfg.topK).toBe(5);
});
it("searchThreshold defaults to 0.5", () => {
it("searchThreshold defaults to 0.1", () => {
const cfg = mem0ConfigSchema.parse({ apiKey: "test-key" });
expect(cfg.searchThreshold).toBe(0.5);
expect(cfg.searchThreshold).toBe(0.1);
});
it("customInstructions defaults to DEFAULT_CUSTOM_INSTRUCTIONS", () => {
+46 -2
View File
@@ -7,6 +7,7 @@ import {
buildOssLlmConfig,
buildOssEmbedderConfig,
buildOssVectorConfig,
collectionNameForDims,
validateOssFlags,
checkQdrantConnectivity,
checkOllamaConnectivity,
@@ -90,9 +91,9 @@ describe("buildOssEmbedderConfig", () => {
expect(result.dims).toBe(768);
});
it("returns unknown dims for custom model", () => {
it("falls back to provider default dims for custom model", () => {
const result = buildOssEmbedderConfig("ollama", { model: "custom-embed" });
expect(result.dims).toBeUndefined();
expect(result.dims).toBe(768);
});
});
@@ -147,6 +148,49 @@ describe("buildOssVectorConfig", () => {
});
});
describe("collectionNameForDims", () => {
it("generates dimension-based collection name", () => {
expect(collectionNameForDims(1536)).toBe("mem0_1536d");
expect(collectionNameForDims(768)).toBe("mem0_768d");
expect(collectionNameForDims(384)).toBe("mem0_384d");
});
});
describe("buildOssVectorConfig dimension safety", () => {
it("sets both dimension and embeddingModelDims when dims provided", () => {
const result = buildOssVectorConfig("qdrant", { dims: 768 });
expect(result.config.dimension).toBe(768);
expect(result.config.embeddingModelDims).toBe(768);
});
it("sets collectionName based on dims", () => {
const result = buildOssVectorConfig("qdrant", { dims: 768 });
expect(result.config.collectionName).toBe("mem0_768d");
});
it("uses different collection names for different dims", () => {
const r1 = buildOssVectorConfig("qdrant", { dims: 1536 });
const r2 = buildOssVectorConfig("qdrant", { dims: 768 });
expect(r1.config.collectionName).not.toBe(r2.config.collectionName);
});
it("omits dimension fields when dims not provided", () => {
const result = buildOssVectorConfig("qdrant", {});
expect(result.config.dimension).toBeUndefined();
expect(result.config.embeddingModelDims).toBeUndefined();
expect(result.config.collectionName).toBeUndefined();
});
it("works with pgvector too", () => {
const result = buildOssVectorConfig("pgvector", {
host: "localhost", port: "5432", user: "me", password: "pw", dbname: "test", dims: 768,
});
expect(result.config.dimension).toBe(768);
expect(result.config.embeddingModelDims).toBe(768);
expect(result.config.collectionName).toBe("mem0_768d");
});
});
describe("checkQdrantConnectivity", () => {
it("returns error for unreachable host", async () => {
const result = await checkQdrantConnectivity("http://localhost:19999");
+1 -1
View File
@@ -34,7 +34,7 @@ function createMockToolDeps(overrides = {}): ToolDeps {
topK: 5,
autoCapture: true,
autoRecall: true,
searchThreshold: 0.5,
searchThreshold: 0.1,
customInstructions: "test",
customCategories: {},
} as any,