Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
{
"name": "@four-bytes/four-opencode-brain",
"version": "1.7.1",
"version": "1.7.2",
"description": "Unified brain plugin — single SQLite DB for RAG search, memory, and knowledge base",
"license": "Apache-2.0",
"type": "module",
"scripts": {
"build": "NODE_ENV=production bun run scripts/build.ts",
"postinstall": "ln -sf node_modules/node-llama-cpp/llama llama && rm -rf node_modules/node-llama-cpp/bins/linux-x64 && cp -r node_modules/@node-llama-cpp/linux-x64/bins/linux-x64 node_modules/node-llama-cpp/bins/linux-x64",
"postinstall": "if [ \"$BRAIN_EMBED_ENABLE\" = \"true\" ] || [ \"$BRAIN_EMBED_ENABLE\" = \"1\" ]; then ln -sf node_modules/node-llama-cpp/llama llama && rm -rf node_modules/node-llama-cpp/bins/linux-x64 && cp -r node_modules/@node-llama-cpp/linux-x64/bins/linux-x64 node_modules/node-llama-cpp/bins/linux-x64; fi",
"test": "bun test"
},
"keywords": [
Expand Down
6 changes: 5 additions & 1 deletion scripts/build.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,11 +4,15 @@ import { rmSync, renameSync } from "node:fs";
rmSync("dist", { recursive: true, force: true });

// 2. Server build: Bun bundler on clean dist (FIRST — no stale artifacts)
const externals = ["@opencode-ai/*"];
if (process.env.BRAIN_EMBED_ENABLE === "true" || process.env.BRAIN_EMBED_ENABLE === "1") {
externals.push("@node-llama-cpp/*");
}
const server = await Bun.build({
entrypoints: ["src/four-opencode-brain.ts"],
outdir: "dist",
target: "bun",
external: ["@opencode-ai/*", "@node-llama-cpp/*"],
external: externals,
minify: process.env.NODE_ENV === "production",
});

Expand Down
7 changes: 7 additions & 0 deletions src/embed/embeddingService.ts
Original file line number Diff line number Diff line change
Expand Up @@ -105,8 +105,14 @@ export class EmbeddingService {
if (this.initialized) return;
if (this.initPromise) return this.initPromise;

log("debug", "embedding-service", "initialize() called", {
brainEmbedEnable: process.env.BRAIN_EMBED_ENABLE ?? "(unset)",
caller: new Error().stack?.split("\n")[2]?.trim().slice(0, 120),
});

this.initPromise = (async () => {
if (process.env.BRAIN_EMBED_ENABLE !== "true" && process.env.BRAIN_EMBED_ENABLE !== "1") {
log("info", "embedding-service", "BRAIN_EMBED_ENABLE not set — skipping real embedding model, using pseudo-embeddings");
this.initialized = true;
this._available = false;
return;
Expand All @@ -127,6 +133,7 @@ export class EmbeddingService {
this.model = await llama.loadModel({ modelPath: resolvedModelPath });
this.ctx = await this.model.createEmbeddingContext();
this._available = true;
log("info", "embedding-service", "BRAIN_EMBED_ENABLE=1 — real embedding model initialized successfully", { dimensions: this.dimensions || "lazy" });
log("info", "embedding-service", "Real embedding model loaded successfully");
} catch (err) {
this._available = false;
Expand Down
Loading