wolbarg 0.5.5 → 0.5.6

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.
package/dist/index.cjs CHANGED
@@ -472,8 +472,8 @@ var AsyncMutex = class {
472
472
  */
473
473
  async runExclusive(fn) {
474
474
  let release;
475
- const next = new Promise((resolve) => {
476
- release = resolve;
475
+ const next = new Promise((resolve3) => {
476
+ release = resolve3;
477
477
  });
478
478
  const previous = this.chain;
479
479
  this.chain = previous.then(() => next);
@@ -2303,7 +2303,7 @@ function isSqliteBusyError(error) {
2303
2303
  return lower.includes("database is locked") || lower.includes("sqlite_busy") || lower.includes("busy");
2304
2304
  }
2305
2305
  function sleep(ms) {
2306
- return new Promise((resolve) => setTimeout(resolve, ms));
2306
+ return new Promise((resolve3) => setTimeout(resolve3, ms));
2307
2307
  }
2308
2308
  function backoffDelay(attempt, config) {
2309
2309
  const exp = Math.min(
@@ -2576,8 +2576,8 @@ var SqliteStorageProvider = class _SqliteStorageProvider {
2576
2576
  /** Insert a single memory row (coalesced under concurrent writers). */
2577
2577
  async insertMemory(input) {
2578
2578
  this.requireVectorReady();
2579
- return new Promise((resolve, reject) => {
2580
- this.insertQueue.push({ input, resolve, reject });
2579
+ return new Promise((resolve3, reject) => {
2580
+ this.insertQueue.push({ input, resolve: resolve3, reject });
2581
2581
  if (this.insertQueue.length >= INSERT_COALESCE_THRESHOLD) {
2582
2582
  this.insertFlushScheduled = false;
2583
2583
  void this.flushInsertQueue();
@@ -4638,8 +4638,8 @@ var PostgresStorageProvider = class _PostgresStorageProvider {
4638
4638
  /** Insert a single memory row (coalesced under concurrent writers). */
4639
4639
  async insertMemory(input) {
4640
4640
  this.requireVectorReady();
4641
- return new Promise((resolve, reject) => {
4642
- this.insertQueue.push({ input, resolve, reject });
4641
+ return new Promise((resolve3, reject) => {
4642
+ this.insertQueue.push({ input, resolve: resolve3, reject });
4643
4643
  if (this.insertQueue.length >= COALESCE_FLUSH_THRESHOLD) {
4644
4644
  this.clearInsertFlushTimer();
4645
4645
  void this.flushInsertQueue();
@@ -5654,7 +5654,7 @@ function createDatabaseProvider(config) {
5654
5654
  }
5655
5655
 
5656
5656
  // src/version.ts
5657
- var SDK_VERSION = "0.5.5";
5657
+ var SDK_VERSION = "0.5.6";
5658
5658
 
5659
5659
  // src/memory/transfer.ts
5660
5660
  var warnedMissingExportManifest = false;
@@ -11145,9 +11145,279 @@ function percentile(sorted, p) {
11145
11145
  return sorted[idx];
11146
11146
  }
11147
11147
 
11148
+ // src/config/providers.ts
11149
+ var EMBEDDING_PROVIDER_PRESETS = [
11150
+ {
11151
+ id: "openai",
11152
+ label: "OpenAI",
11153
+ defaultBaseUrl: "https://api.openai.com/v1",
11154
+ defaultModel: "text-embedding-3-small",
11155
+ apiKeyEnv: "OPENAI_API_KEY"
11156
+ },
11157
+ {
11158
+ id: "ollama",
11159
+ label: "Ollama (local)",
11160
+ defaultBaseUrl: "http://127.0.0.1:11434/v1",
11161
+ defaultModel: "nomic-embed-text",
11162
+ apiKeyEnv: "OLLAMA_API_KEY",
11163
+ apiKeyHint: "Any non-empty value works locally (e.g. ollama)"
11164
+ },
11165
+ {
11166
+ id: "openrouter",
11167
+ label: "OpenRouter",
11168
+ defaultBaseUrl: "https://openrouter.ai/api/v1",
11169
+ defaultModel: "openai/text-embedding-3-small",
11170
+ apiKeyEnv: "OPENROUTER_API_KEY"
11171
+ },
11172
+ {
11173
+ id: "lmstudio",
11174
+ label: "LM Studio (local)",
11175
+ defaultBaseUrl: "http://127.0.0.1:1234/v1",
11176
+ defaultModel: "text-embedding-nomic-embed-text-v1.5",
11177
+ apiKeyEnv: "LM_STUDIO_API_KEY",
11178
+ apiKeyHint: "Often unused locally \u2014 any non-empty value is fine"
11179
+ },
11180
+ {
11181
+ id: "gemini",
11182
+ label: "Google Gemini",
11183
+ defaultBaseUrl: "https://generativelanguage.googleapis.com/v1beta/openai",
11184
+ defaultModel: "text-embedding-004",
11185
+ apiKeyEnv: "GEMINI_API_KEY"
11186
+ },
11187
+ {
11188
+ id: "together",
11189
+ label: "Together AI",
11190
+ defaultBaseUrl: "https://api.together.xyz/v1",
11191
+ defaultModel: "togethercomputer/m2-bert-80M-8k-retrieval",
11192
+ apiKeyEnv: "TOGETHER_API_KEY"
11193
+ },
11194
+ {
11195
+ id: "vllm",
11196
+ label: "vLLM (local/server)",
11197
+ defaultBaseUrl: "http://127.0.0.1:8000/v1",
11198
+ defaultModel: "text-embedding-ada-002",
11199
+ apiKeyEnv: "VLLM_API_KEY",
11200
+ apiKeyHint: "Only if your server requires auth"
11201
+ },
11202
+ {
11203
+ id: "custom",
11204
+ label: "Custom OpenAI-compatible",
11205
+ defaultBaseUrl: "https://api.openai.com/v1",
11206
+ defaultModel: "text-embedding-3-small",
11207
+ apiKeyEnv: "WOLBARG_EMBEDDING_API_KEY"
11208
+ }
11209
+ ];
11210
+ function getEmbeddingProviderPreset(id) {
11211
+ return EMBEDDING_PROVIDER_PRESETS.find((p) => p.id === id);
11212
+ }
11213
+ var DEFAULT_SQLITE_DB_PATH = ".wolbarg/shared-memory/memory.db";
11214
+ var DEFAULT_ORGANIZATION = "default";
11215
+ var DEFAULT_CONFIG_PATH = ".wolbarg/config.json";
11216
+ var DEFAULT_ENV_PATH = ".wolbarg/.env";
11217
+ function defaultProjectConfig() {
11218
+ return {
11219
+ version: 1,
11220
+ organization: DEFAULT_ORGANIZATION,
11221
+ database: {
11222
+ provider: "sqlite",
11223
+ url: DEFAULT_SQLITE_DB_PATH
11224
+ },
11225
+ paths: {
11226
+ config: DEFAULT_CONFIG_PATH
11227
+ }
11228
+ };
11229
+ }
11230
+ function resolveConfigPath(cwd = process.cwd(), configPath) {
11231
+ const rel = configPath ?? DEFAULT_CONFIG_PATH;
11232
+ return path7.isAbsolute(rel) ? rel : path7.resolve(cwd, rel);
11233
+ }
11234
+ function resolveEnvPath(cwd = process.cwd(), envPath) {
11235
+ const rel = envPath ?? DEFAULT_ENV_PATH;
11236
+ return path7.isAbsolute(rel) ? rel : path7.resolve(cwd, rel);
11237
+ }
11238
+ function loadProjectConfig(cwd = process.cwd(), configPath) {
11239
+ const full = resolveConfigPath(cwd, configPath);
11240
+ if (!fs6.existsSync(full)) return null;
11241
+ const raw = JSON.parse(fs6.readFileSync(full, "utf8"));
11242
+ if (!raw || raw.version !== 1 || !raw.database?.url) {
11243
+ throw new Error(`Invalid Wolbarg config at ${full}`);
11244
+ }
11245
+ return raw;
11246
+ }
11247
+ function saveProjectConfig(config, options = {}) {
11248
+ const cwd = options.cwd ?? process.cwd();
11249
+ const configPath = resolveConfigPath(cwd, options.configPath);
11250
+ const dir = path7.dirname(configPath);
11251
+ if (!fs6.existsSync(dir)) fs6.mkdirSync(dir, { recursive: true });
11252
+ if (fs6.existsSync(configPath) && options.overwrite === false) {
11253
+ throw new Error(`Config already exists: ${configPath} (pass --force to overwrite)`);
11254
+ }
11255
+ const toWrite = {
11256
+ ...config,
11257
+ paths: {
11258
+ config: options.configPath ?? DEFAULT_CONFIG_PATH,
11259
+ ...options.envPath || options.apiKey ? { env: options.envPath ?? DEFAULT_ENV_PATH } : config.paths?.env ? { env: config.paths.env } : {}
11260
+ }
11261
+ };
11262
+ fs6.writeFileSync(configPath, `${JSON.stringify(toWrite, null, 2)}
11263
+ `, "utf8");
11264
+ let envPath;
11265
+ if (options.apiKey && config.embedding?.apiKeyEnv) {
11266
+ envPath = resolveEnvPath(cwd, options.envPath);
11267
+ ensureParent(envPath);
11268
+ upsertEnvVar(envPath, config.embedding.apiKeyEnv, options.apiKey);
11269
+ ensureGitignore(cwd, [DEFAULT_ENV_PATH, ".env"]);
11270
+ }
11271
+ if (config.database.provider === "sqlite" && !config.database.url.includes("://")) {
11272
+ const dbPath = path7.isAbsolute(config.database.url) ? config.database.url : path7.resolve(cwd, config.database.url);
11273
+ ensureParent(dbPath);
11274
+ }
11275
+ return { configPath, envPath };
11276
+ }
11277
+ function ensureParent(filePath) {
11278
+ const dir = path7.dirname(filePath);
11279
+ if (!fs6.existsSync(dir)) fs6.mkdirSync(dir, { recursive: true });
11280
+ }
11281
+ function upsertEnvVar(envPath, key, value) {
11282
+ ensureParent(envPath);
11283
+ let text = fs6.existsSync(envPath) ? fs6.readFileSync(envPath, "utf8") : "";
11284
+ const line = `${key}=${shellQuoteEnv(value)}`;
11285
+ const re = new RegExp(`^${escapeRegExp(key)}=.*$`, "m");
11286
+ if (re.test(text)) {
11287
+ text = text.replace(re, line);
11288
+ } else {
11289
+ if (text && !text.endsWith("\n")) text += "\n";
11290
+ text += `${line}
11291
+ `;
11292
+ }
11293
+ fs6.writeFileSync(envPath, text, "utf8");
11294
+ }
11295
+ function shellQuoteEnv(value) {
11296
+ if (/[\s#"']/.test(value)) {
11297
+ return `"${value.replace(/\\/g, "\\\\").replace(/"/g, '\\"')}"`;
11298
+ }
11299
+ return value;
11300
+ }
11301
+ function escapeRegExp(s) {
11302
+ return s.replace(/[.*+?^${}()|[\]\\]/g, "\\$&");
11303
+ }
11304
+ function ensureGitignore(cwd, entries) {
11305
+ const gi = path7.join(cwd, ".gitignore");
11306
+ let text = fs6.existsSync(gi) ? fs6.readFileSync(gi, "utf8") : "";
11307
+ let changed = false;
11308
+ for (const entry of entries) {
11309
+ if (text.split(/\r?\n/).some((l) => l.trim() === entry)) continue;
11310
+ if (text && !text.endsWith("\n")) text += "\n";
11311
+ text += `${entry}
11312
+ `;
11313
+ changed = true;
11314
+ }
11315
+ if (changed) fs6.writeFileSync(gi, text, "utf8");
11316
+ }
11317
+ function resolveEmbeddingApiKey(config, env = process.env) {
11318
+ const name = config.embedding?.apiKeyEnv;
11319
+ if (!name) return "";
11320
+ return env[name] ?? "";
11321
+ }
11322
+ function assertEmbeddingPreset(provider) {
11323
+ const preset = getEmbeddingProviderPreset(provider);
11324
+ if (!preset) {
11325
+ throw new Error(
11326
+ `Unknown embedding provider "${provider}". Choose one of: ${[
11327
+ "openai",
11328
+ "ollama",
11329
+ "openrouter",
11330
+ "lmstudio",
11331
+ "gemini",
11332
+ "together",
11333
+ "vllm",
11334
+ "custom"
11335
+ ].join(", ")}`
11336
+ );
11337
+ }
11338
+ return preset.id;
11339
+ }
11340
+ function applyEnvFile(envPath, base = {}) {
11341
+ const out = { ...base };
11342
+ if (!fs6.existsSync(envPath)) return out;
11343
+ const text = fs6.readFileSync(envPath, "utf8");
11344
+ for (const rawLine of text.split(/\r?\n/)) {
11345
+ const line = rawLine.trim();
11346
+ if (!line || line.startsWith("#")) continue;
11347
+ const eq = line.indexOf("=");
11348
+ if (eq <= 0) continue;
11349
+ const key = line.slice(0, eq).trim();
11350
+ let value = line.slice(eq + 1).trim();
11351
+ if (value.startsWith('"') && value.endsWith('"') || value.startsWith("'") && value.endsWith("'")) {
11352
+ value = value.slice(1, -1);
11353
+ }
11354
+ if (out[key] === void 0) out[key] = value;
11355
+ }
11356
+ return out;
11357
+ }
11358
+ function projectConfigToWolbargOptions(config, env = process.env) {
11359
+ if (!config.embedding) {
11360
+ throw new Error(
11361
+ "Project config has no embedding section. Re-run `wolbarg init` and configure an embedding provider, or pass embedding explicitly to wolbarg()."
11362
+ );
11363
+ }
11364
+ const apiKey = resolveEmbeddingApiKey(config, env);
11365
+ if (!apiKey) {
11366
+ throw new Error(
11367
+ `Missing API key. Set ${config.embedding.apiKeyEnv} in the environment or in .wolbarg/.env (from wolbarg init).`
11368
+ );
11369
+ }
11370
+ const dbUrl = config.database.url;
11371
+ return {
11372
+ organization: config.organization,
11373
+ database: {
11374
+ provider: config.database.provider,
11375
+ url: dbUrl,
11376
+ connectionString: dbUrl
11377
+ },
11378
+ embedding: {
11379
+ baseUrl: config.embedding.baseUrl,
11380
+ apiKey,
11381
+ model: config.embedding.model
11382
+ }
11383
+ };
11384
+ }
11385
+ function createWolbargFromProjectConfig(options = {}) {
11386
+ const cwd = options.cwd ?? process.cwd();
11387
+ const config = loadProjectConfig(cwd, options.configPath);
11388
+ if (!config) {
11389
+ throw new Error(
11390
+ `No Wolbarg config found. Run \`wolbarg init\` in ${cwd} (expected .wolbarg/config.json).`
11391
+ );
11392
+ }
11393
+ let env = options.env ?? { ...process.env };
11394
+ if (options.loadEnvFile !== false) {
11395
+ const envFile = resolveEnvPath(
11396
+ cwd,
11397
+ config.paths?.env ?? DEFAULT_ENV_PATH
11398
+ );
11399
+ env = applyEnvFile(envFile, env);
11400
+ }
11401
+ if (options.organization) {
11402
+ config.organization = options.organization;
11403
+ }
11404
+ if (config.database.provider === "sqlite" && !config.database.url.includes("://") && !path7.isAbsolute(config.database.url)) {
11405
+ config.database = {
11406
+ ...config.database,
11407
+ url: path7.resolve(cwd, config.database.url)
11408
+ };
11409
+ }
11410
+ return wolbarg(projectConfigToWolbargOptions(config, env));
11411
+ }
11412
+
11148
11413
  exports.CompressionError = CompressionError;
11149
11414
  exports.ConfigurationError = ConfigurationError;
11415
+ exports.DEFAULT_CONFIG_PATH = DEFAULT_CONFIG_PATH;
11416
+ exports.DEFAULT_ENV_PATH = DEFAULT_ENV_PATH;
11417
+ exports.DEFAULT_ORGANIZATION = DEFAULT_ORGANIZATION;
11418
+ exports.DEFAULT_SQLITE_DB_PATH = DEFAULT_SQLITE_DB_PATH;
11150
11419
  exports.DatabaseError = DatabaseError;
11420
+ exports.EMBEDDING_PROVIDER_PRESETS = EMBEDDING_PROVIDER_PRESETS;
11151
11421
  exports.EmbeddingError = EmbeddingError;
11152
11422
  exports.FixedChunkingStrategy = FixedChunkingStrategy;
11153
11423
  exports.GraphCheckpointNotSupportedError = GraphCheckpointNotSupportedError;
@@ -11175,6 +11445,8 @@ exports.ValidationError = ValidationError;
11175
11445
  exports.Wolbarg = Wolbarg;
11176
11446
  exports.WolbargError = WolbargError;
11177
11447
  exports.WolbargLogger = WolbargLogger;
11448
+ exports.applyEnvFile = applyEnvFile;
11449
+ exports.assertEmbeddingPreset = assertEmbeddingPreset;
11178
11450
  exports.bgeReranker = bgeReranker;
11179
11451
  exports.bm25 = bm25;
11180
11452
  exports.cohereReranker = cohereReranker;
@@ -11186,11 +11458,15 @@ exports.createLlmProvider = createLlmProvider;
11186
11458
  exports.createStorageProvider = createStorageProvider;
11187
11459
  exports.createTelemetryProvider = createTelemetryProvider;
11188
11460
  exports.createWolbarg = createWolbarg;
11461
+ exports.createWolbargFromProjectConfig = createWolbargFromProjectConfig;
11189
11462
  exports.crossEncoder = crossEncoder;
11463
+ exports.defaultProjectConfig = defaultProjectConfig;
11190
11464
  exports.geminiEmbedding = geminiEmbedding;
11191
11465
  exports.geminiVision = geminiVision;
11466
+ exports.getEmbeddingProviderPreset = getEmbeddingProviderPreset;
11192
11467
  exports.jinaReranker = jinaReranker;
11193
11468
  exports.lmStudioEmbedding = lmStudioEmbedding;
11469
+ exports.loadProjectConfig = loadProjectConfig;
11194
11470
  exports.meta = meta;
11195
11471
  exports.neo4jGraph = neo4jGraph;
11196
11472
  exports.ollamaEmbedding = ollamaEmbedding;
@@ -11205,7 +11481,12 @@ exports.openaiReranker = openaiReranker;
11205
11481
  exports.openaiVision = openaiVision;
11206
11482
  exports.postgres = postgres;
11207
11483
  exports.postgresConfig = postgresConfig;
11484
+ exports.projectConfigToWolbargOptions = projectConfigToWolbargOptions;
11485
+ exports.resolveConfigPath = resolveConfigPath;
11486
+ exports.resolveEmbeddingApiKey = resolveEmbeddingApiKey;
11487
+ exports.resolveEnvPath = resolveEnvPath;
11208
11488
  exports.runBenchmark = runBenchmark;
11489
+ exports.saveProjectConfig = saveProjectConfig;
11209
11490
  exports.sqlite = sqlite;
11210
11491
  exports.sqliteCheckpoint = sqliteCheckpoint;
11211
11492
  exports.sqliteConfig = sqliteConfig;
@@ -11214,6 +11495,7 @@ exports.sqliteTelemetry = sqliteTelemetry;
11214
11495
  exports.summarizeBenchmark = summarizeBenchmark;
11215
11496
  exports.tesseract = tesseract;
11216
11497
  exports.togetherEmbedding = togetherEmbedding;
11498
+ exports.upsertEnvVar = upsertEnvVar;
11217
11499
  exports.vllmEmbedding = vllmEmbedding;
11218
11500
  exports.wolbarg = wolbarg;
11219
11501
  exports.wrapOperationError = wrapOperationError;