@retrivora-ai/rag-engine 2.6.2 → 2.6.3

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.
Files changed (49) hide show
  1. package/dist/ChromaDBProvider-NDA2IBOH.mjs +8 -0
  2. package/dist/MilvusProvider-H6GGL5FQ.mjs +8 -0
  3. package/dist/MongoDBProvider-KC3GF3FH.mjs +8 -0
  4. package/dist/MultiTablePostgresProvider-6LJBFZL2.mjs +9 -0
  5. package/dist/PineconeProvider-22RF2QPF.mjs +10 -0
  6. package/dist/PineconeProvider-HBBIXLT3.mjs +10 -0
  7. package/dist/PostgreSQLProvider-VWFL4OIP.mjs +8 -0
  8. package/dist/QdrantProvider-UU7RGXBI.mjs +8 -0
  9. package/dist/RedisProvider-MIIPSAAE.mjs +8 -0
  10. package/dist/SimpleGraphProvider-HJIS4S7Y.mjs +70 -0
  11. package/dist/UniversalVectorProvider-NO3L255G.mjs +9 -0
  12. package/dist/WeaviateProvider-YRZDZFAC.mjs +8 -0
  13. package/dist/chunk-23PFNEBF.mjs +107 -0
  14. package/dist/chunk-3E4GZGDX.mjs +10851 -0
  15. package/dist/chunk-3SQ4DODU.mjs +238 -0
  16. package/dist/chunk-AHMMUZ4W.mjs +152 -0
  17. package/dist/chunk-ASBNNEVI.mjs +81 -0
  18. package/dist/chunk-AT4TFUQN.mjs +219 -0
  19. package/dist/chunk-BEPLYQBS.mjs +89 -0
  20. package/dist/chunk-G7MJRFCO.mjs +340 -0
  21. package/dist/chunk-IHWKVAUR.mjs +112 -0
  22. package/dist/chunk-IMP6FUCY.mjs +30 -0
  23. package/dist/chunk-LFNV6DEL.mjs +281 -0
  24. package/dist/chunk-MAXMVO7B.mjs +211 -0
  25. package/dist/chunk-MGJ6V2IT.mjs +203 -0
  26. package/dist/chunk-N3TI27LG.mjs +334 -0
  27. package/dist/chunk-NWYE4Q7B.mjs +334 -0
  28. package/dist/chunk-OJMAT4EG.mjs +219 -0
  29. package/dist/chunk-QKZM3RSJ.mjs +10851 -0
  30. package/dist/chunk-QUY3E6HJ.mjs +168 -0
  31. package/dist/chunk-SG6XYLQE.mjs +53 -0
  32. package/dist/chunk-UT6SZZEC.mjs +69 -0
  33. package/dist/chunk-VW3U4MMX.mjs +157 -0
  34. package/dist/chunk-WOJCOTXI.mjs +281 -0
  35. package/dist/chunk-XP6NJMX4.mjs +168 -0
  36. package/dist/chunk-XYBKDJDW.mjs +696 -0
  37. package/dist/handlers/index.d.mts +1 -1
  38. package/dist/handlers/index.d.ts +1 -1
  39. package/dist/handlers/index.js +56 -23
  40. package/dist/handlers/index.mjs +24 -14027
  41. package/dist/{index-D7FuQRSb.d.mts → index-BBbt5A2y.d.mts} +3 -1
  42. package/dist/{index-CFl4KrKq.d.ts → index-BZ_rR6V8.d.ts} +3 -1
  43. package/dist/index.js +12 -4
  44. package/dist/index.mjs +46 -1461
  45. package/dist/server.d.mts +2 -2
  46. package/dist/server.d.ts +2 -2
  47. package/dist/server.js +56 -23
  48. package/dist/server.mjs +377 -14573
  49. package/package.json +1 -1
@@ -1,3 +1,3 @@
1
- export { b as HandlerOptions, d as createChatHandler, e as createFeedbackHandler, f as createHealthHandler, g as createHistoryHandler, h as createIngestHandler, i as createLicenseHandler, j as createRagHandler, k as createSessionsHandler, l as createStreamHandler, m as createSuggestionsHandler, n as createUploadHandler, s as sseErrorFrame, o as sseFrame, p as sseMetaFrame, q as sseObservabilityFrame, r as sseTextFrame, t as sseUIFrame } from '../index-CFl4KrKq.js';
1
+ export { b as HandlerOptions, d as createChatHandler, e as createFeedbackHandler, f as createHealthHandler, g as createHistoryHandler, h as createIngestHandler, i as createLicenseHandler, j as createRagHandler, k as createSessionsHandler, l as createStreamHandler, m as createSuggestionsHandler, n as createUploadHandler, s as sseErrorFrame, o as sseFrame, p as sseMetaFrame, q as sseObservabilityFrame, r as sseTextFrame, t as sseUIFrame } from '../index-BZ_rR6V8.js';
2
2
  import 'next/server';
3
3
  import '../ILLMProvider-CzXcTA6d.js';
@@ -84,6 +84,9 @@ function isRecord(value) {
84
84
  function resolvePath(obj, path2) {
85
85
  if (!path2 || !obj) return void 0;
86
86
  return path2.replace(/\[(\w+)\]/g, ".$1").replace(/^\./, "").split(".").reduce((current, segment) => {
87
+ if (segment === "__proto__" || segment === "constructor" || segment === "prototype") {
88
+ return void 0;
89
+ }
87
90
  if (!isRecord(current) && !Array.isArray(current)) {
88
91
  return void 0;
89
92
  }
@@ -94,8 +97,9 @@ function buildPayload(template, vars) {
94
97
  let raw = template;
95
98
  for (const [key, val] of Object.entries(vars)) {
96
99
  const stringifiedVal = val === void 0 ? "null" : JSON.stringify(val);
97
- raw = raw.replace(new RegExp(`"\\{\\{${key}\\}\\}"`, "g"), () => stringifiedVal);
98
- raw = raw.replace(new RegExp(`\\{\\{${key}\\}\\}`, "g"), () => stringifiedVal);
100
+ const escapedKey = key.replace(/[.*+?^${}()|[\]\\]/g, "\\$&");
101
+ raw = raw.replace(new RegExp(`"\\{\\{${escapedKey}\\}\\}"`, "g"), () => stringifiedVal);
102
+ raw = raw.replace(new RegExp(`\\{\\{${escapedKey}\\}\\}`, "g"), () => stringifiedVal);
99
103
  }
100
104
  try {
101
105
  return JSON.parse(raw);
@@ -318,7 +322,7 @@ var init_package = __esm({
318
322
  "package.json"() {
319
323
  package_default = {
320
324
  name: "@retrivora-ai/rag-engine",
321
- version: "2.6.2",
325
+ version: "2.6.3",
322
326
  description: "Retrivora AI is a plug-and-play AI engine for RAG chat experiences \u2014 generic vector DB + LLM provider, embeddable or standalone.",
323
327
  author: "Abhinav Alkuchi",
324
328
  license: "UNLICENSED",
@@ -1090,13 +1094,14 @@ var init_PostgreSQLProvider = __esm({
1090
1094
  const filterConditions = Object.entries(publicFilter).map(([key, val]) => {
1091
1095
  const paramIdx = params.length + 1;
1092
1096
  params.push(String(val));
1093
- return `metadata->>'${key}' = $${paramIdx}`;
1097
+ return `metadata->>'${key.replace(/[^a-zA-Z0-9_.-]/g, "")}' = $${paramIdx}`;
1094
1098
  }).join(" AND ");
1095
1099
  whereClause = whereClause ? `${whereClause} AND ${filterConditions}` : `WHERE ${filterConditions}`;
1096
1100
  }
1097
1101
  const client = await this.pool.connect();
1098
1102
  try {
1099
- const efSearch = this.config.options.efSearch || Math.max(topK * 10, 40);
1103
+ const rawEfSearch = Number(this.config.options.efSearch) || Math.max(topK * 10, 40);
1104
+ const efSearch = Math.max(1, Math.min(1e3, Math.floor(Number.isFinite(rawEfSearch) ? rawEfSearch : 40)));
1100
1105
  await client.query(`SET LOCAL hnsw.ef_search = ${efSearch}`);
1101
1106
  const result = await client.query(
1102
1107
  `SELECT id, content, metadata, 1 - (embedding <=> $1::vector) AS score
@@ -1240,7 +1245,11 @@ var init_MultiTablePostgresProvider = __esm({
1240
1245
  this.tables = [];
1241
1246
  const rawSearchFields = (_c = (_b = opts.searchFields) != null ? _b : process.env.VECTOR_DB_SEARCH_FIELDS) != null ? _c : ["name", "product_name", "productname", "title"];
1242
1247
  this.searchFields = typeof rawSearchFields === "string" ? rawSearchFields.split(",").map((f) => f.trim()).filter(Boolean) : rawSearchFields;
1243
- this.uploadTable = opts.uploadTable || "document_chunks";
1248
+ const rawUploadTable = opts.uploadTable || "document_chunks";
1249
+ if (!/^[a-zA-Z_][a-zA-Z0-9_]{0,62}$/.test(rawUploadTable)) {
1250
+ throw new Error(`Invalid uploadTable name: ${rawUploadTable}`);
1251
+ }
1252
+ this.uploadTable = rawUploadTable;
1244
1253
  }
1245
1254
  async initialize() {
1246
1255
  this.pool = new import_pg2.Pool({ connectionString: this.connectionString });
@@ -1423,7 +1432,7 @@ var init_MultiTablePostgresProvider = __esm({
1423
1432
  const baseOffset = queryText && dynamicKeywordQuery ? 2 : 1;
1424
1433
  const paramIdx = baseOffset + filterParams.length;
1425
1434
  const synonyms = (_a4 = FIELD_SYNONYMS[key]) != null ? _a4 : [];
1426
- const keysToCheck = [key, ...synonyms];
1435
+ const keysToCheck = [key, ...synonyms].filter((k) => /^[a-zA-Z_][a-zA-Z0-9_]{0,62}$/.test(k));
1427
1436
  const coalesceExprs = keysToCheck.flatMap((k) => [
1428
1437
  `metadata->>'${k}'`,
1429
1438
  `to_jsonb(t)->>'${k}'`
@@ -1440,7 +1449,7 @@ var init_MultiTablePostgresProvider = __esm({
1440
1449
  THEN 1.0 ELSE 0.0 END
1441
1450
  ), 0)
1442
1451
  FROM jsonb_each_text(COALESCE(v.metadata, k.metadata)) AS kv(key, val)
1443
- WHERE key IN (${this.searchFields.map((f) => `'${f}'`).join(", ")})
1452
+ WHERE key IN (${this.searchFields.map((f) => `'${f.replace(/'/g, "''")}'`).join(", ")})
1444
1453
  ) * 3.0` : "";
1445
1454
  sqlQuery = `
1446
1455
  WITH vector_search AS (
@@ -2819,6 +2828,7 @@ var _LicenseVerifier = class _LicenseVerifier {
2819
2828
  * Computes a deterministic hardware fingerprint to enforce node-locked licensing.
2820
2829
  */
2821
2830
  static async generateMachineFingerprint() {
2831
+ if (typeof process !== "undefined" && (process.env.VERCEL || process.env.AWS_LAMBDA_FUNCTION_NAME)) return "browser-client";
2822
2832
  if (typeof window !== "undefined" && typeof navigator !== "undefined") {
2823
2833
  return "browser-client";
2824
2834
  }
@@ -2882,7 +2892,7 @@ var _LicenseVerifier = class _LicenseVerifier {
2882
2892
  }
2883
2893
  }
2884
2894
  try {
2885
- let baseUrl = typeof process !== "undefined" && process.env.RETRIVORA_CONTROL_PLANE_URL ? process.env.RETRIVORA_CONTROL_PLANE_URL : "https://retrivora.com";
2895
+ let baseUrl = typeof process !== "undefined" && process.env.RETRIVORA_CONTROL_PLANE_URL ? process.env.RETRIVORA_CONTROL_PLANE_URL : "https://www.retrivora.com";
2886
2896
  if (typeof process !== "undefined" && process.env.TELEMETRY_URL) {
2887
2897
  baseUrl = process.env.TELEMETRY_URL.replace(/\/api\/telemetry\/?$/, "");
2888
2898
  }
@@ -3168,7 +3178,13 @@ var _DatabaseStorage = class _DatabaseStorage {
3168
3178
  getPGPool() {
3169
3179
  const globalKey = `pg:${this.config.projectId}`;
3170
3180
  if (!_pgInitPromises.has(globalKey)) {
3171
- _pgInitPromises.set(globalKey, this.createPGPool());
3181
+ _pgInitPromises.set(
3182
+ globalKey,
3183
+ this.createPGPool().catch((err) => {
3184
+ _pgInitPromises.delete(globalKey);
3185
+ throw err;
3186
+ })
3187
+ );
3172
3188
  }
3173
3189
  return _pgInitPromises.get(globalKey);
3174
3190
  }
@@ -3725,8 +3741,8 @@ function resolveLicensedNamespace(payload, requestedNamespace) {
3725
3741
  var _a2;
3726
3742
  const allowed = getAllowedNamespaces(payload.projectId);
3727
3743
  const requested = requestedNamespace == null ? void 0 : requestedNamespace.trim();
3728
- const isDevOrFree = process.env.NODE_ENV !== "production" || isFreeTier(payload.tier);
3729
- if (requested && !isDevOrFree && !allowed.has(requested)) {
3744
+ const isDev = process.env.NODE_ENV !== "production";
3745
+ if (requested && !isDev && !allowed.has(requested)) {
3730
3746
  return {
3731
3747
  ok: false,
3732
3748
  response: new Response(JSON.stringify({
@@ -5031,7 +5047,7 @@ var GroqProvider = class {
5031
5047
  return (_i = (_h = (_g2 = completion.choices[0]) == null ? void 0 : _g2.message) == null ? void 0 : _h.content) != null ? _i : "";
5032
5048
  } catch (err) {
5033
5049
  console.warn("[GroqProvider] Groq chat request failed, falling back strictly to Hugging Face Qwen:", (err == null ? void 0 : err.message) || err);
5034
- const hfToken = process.env.HF_TOKEN || process.env.HUGGINGFACE_API_KEY || "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";
5050
+ const hfToken = process.env.HF_TOKEN || process.env.HUGGINGFACE_API_KEY || "";
5035
5051
  try {
5036
5052
  const hfRes = await fetch("https://router.huggingface.co/v1/chat/completions", {
5037
5053
  method: "POST",
@@ -5103,7 +5119,7 @@ var GroqProvider = class {
5103
5119
  }
5104
5120
  } catch (err) {
5105
5121
  console.warn("[GroqProvider] Groq chat stream failed, falling back strictly to Hugging Face Qwen stream:", (err == null ? void 0 : err.message) || err);
5106
- const hfToken = process.env.HF_TOKEN || process.env.HUGGINGFACE_API_KEY || "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";
5122
+ const hfToken = process.env.HF_TOKEN || process.env.HUGGINGFACE_API_KEY || "";
5107
5123
  try {
5108
5124
  const hfRes = yield new __await(fetch("https://router.huggingface.co/v1/chat/completions", {
5109
5125
  method: "POST",
@@ -7489,7 +7505,7 @@ var MCPClient = class {
7489
7505
  }
7490
7506
  const args = this.config.args || [];
7491
7507
  const env = __spreadValues(__spreadValues({}, process.env), this.config.env || {});
7492
- this.childProcess = (0, import_child_process.spawn)(cmd, args, { env, shell: true });
7508
+ this.childProcess = (0, import_child_process.spawn)(cmd, args, { env });
7493
7509
  if (!this.childProcess || !this.childProcess.stdout || !this.childProcess.stdin) {
7494
7510
  throw new Error(`[MCPClient] Failed to spawn stdio child process for "${this.config.name}"`);
7495
7511
  }
@@ -7533,7 +7549,11 @@ var MCPClient = class {
7533
7549
  if (!this.config.url) {
7534
7550
  throw new Error(`[MCPClient] URL is required for sse transport on "${this.config.name}"`);
7535
7551
  }
7536
- this.sseUrl = this.config.url;
7552
+ const parsed = new URL(this.config.url);
7553
+ if (parsed.protocol !== "https:" && parsed.protocol !== "http:") {
7554
+ throw new Error(`[MCPClient] Invalid SSE URL protocol: ${parsed.protocol}`);
7555
+ }
7556
+ this.sseUrl = parsed.toString();
7537
7557
  }
7538
7558
  async sendJsonRpc(method, params) {
7539
7559
  const id = this.getNextMessageId();
@@ -7548,7 +7568,16 @@ var MCPClient = class {
7548
7568
  throw new Error(`[MCPClient] Server "${this.config.name}" is not connected (stdio process missing)`);
7549
7569
  }
7550
7570
  return new Promise((resolve, reject) => {
7551
- this.pendingRequests.set(id, { resolve, reject });
7571
+ const timer = setTimeout(() => {
7572
+ if (this.pendingRequests.delete(id)) reject(new Error(`[MCPClient] Request ${method} (id=${id}) timed out after 30000ms`));
7573
+ }, 3e4);
7574
+ this.pendingRequests.set(id, { resolve: (val) => {
7575
+ clearTimeout(timer);
7576
+ resolve(val);
7577
+ }, reject: (err) => {
7578
+ clearTimeout(timer);
7579
+ reject(err);
7580
+ } });
7552
7581
  this.childProcess.stdin.write(JSON.stringify(request) + "\n", "utf-8");
7553
7582
  });
7554
7583
  } else {
@@ -7887,7 +7916,7 @@ Once you have gathered enough information to fully satisfy the user query, write
7887
7916
  try {
7888
7917
  if (toolName === "document_search") {
7889
7918
  const query = String((_a2 = toolArgs.query) != null ? _a2 : "");
7890
- const { sources } = yield new __await(this.retriever.retrieve(query));
7919
+ const { sources } = yield new __await(this.retriever.retrieve(query, { namespace: typeof toolArgs.namespace === "string" ? toolArgs.namespace : void 0 }));
7891
7920
  const snippets = sources.slice(0, 5).map((s, i) => {
7892
7921
  var _a3;
7893
7922
  return `[${i + 1}] ${String((_a3 = s.content) != null ? _a3 : "").slice(0, 400)}`;
@@ -8362,7 +8391,8 @@ var QueryProcessor = class {
8362
8391
  }
8363
8392
  if (validFields.length > 0) {
8364
8393
  for (const field of validFields) {
8365
- const pattern = new RegExp(`\\b${field}\\s*(?:is|are|:|of)?\\s+["']?([^"\\n?.!,]{1,60})["']?(?=[?.!,]|$)`, "gi");
8394
+ const escapedField = field.replace(/[.*+?^${}()|[\]\\]/g, "\\$&");
8395
+ const pattern = new RegExp(`\\b${escapedField}\\s*(?:is|are|:|of)?\\s+["']?([^"\\n?.!,]{1,60})["']?(?=[?.!,]|$)`, "gi");
8366
8396
  for (const match of question.matchAll(pattern)) {
8367
8397
  const value = match[1];
8368
8398
  if (value && !this.isLikelyPromptPhrase(value)) {
@@ -11989,12 +12019,14 @@ var ProviderHealthCheck = class {
11989
12019
 
11990
12020
  // src/core/VectorPlugin.ts
11991
12021
  var VectorPlugin = class {
11992
- constructor(hostConfig) {
12022
+ constructor(hostConfig, options) {
11993
12023
  const resolvedConfig = ConfigResolver.resolve(hostConfig);
11994
12024
  this.config = resolvedConfig;
11995
12025
  this.validationPromise = (async () => {
11996
12026
  var _a2;
11997
12027
  await ConfigValidator.validateAndThrow(resolvedConfig);
12028
+ const isControlPlane = Boolean(typeof process !== "undefined" && process.env.LITELLM_MASTER_KEY && resolvedConfig.licenseKey === process.env.LITELLM_MASTER_KEY);
12029
+ if ((options == null ? void 0 : options.skipLicenseCheck) || isControlPlane) return;
11998
12030
  await LicenseVerifier.verifyAsync(
11999
12031
  resolvedConfig.licenseKey,
12000
12032
  resolvedConfig.projectId,
@@ -12169,7 +12201,7 @@ function getOrCreatePlugin(configOrPlugin) {
12169
12201
  const key = configHash(configOrPlugin);
12170
12202
  const cached = _pluginCache.get(key);
12171
12203
  if (cached && Date.now() - cached.createdAt < PLUGIN_CACHE_TTL_MS) return cached.plugin;
12172
- const plugin = new VectorPlugin(configOrPlugin);
12204
+ const plugin = new VectorPlugin(configOrPlugin, { skipLicenseCheck: true });
12173
12205
  _pluginCache.set(key, { plugin, createdAt: Date.now() });
12174
12206
  return plugin;
12175
12207
  }
@@ -13914,7 +13946,7 @@ function createFeedbackHandler(configOrPlugin, options) {
13914
13946
  }
13915
13947
  if (scope && scope.length > 0) {
13916
13948
  const matches = scope.some(
13917
- (pid) => pid && (sessionId === pid || sessionId.startsWith(pid) || sessionId.includes(pid))
13949
+ (pid) => pid && (sessionId === pid || sessionId.startsWith(`${pid}:`) || sessionId.startsWith(`${pid}-`) || sessionId.startsWith(`${pid}_`))
13918
13950
  );
13919
13951
  if (!matches) {
13920
13952
  return import_server10.NextResponse.json(
@@ -14024,7 +14056,8 @@ function createRagHandler(configOrPlugin, options) {
14024
14056
  const pathname = url.pathname;
14025
14057
  if (pathname.includes("/license/validate")) return "v1/license/validate";
14026
14058
  if (pathname.endsWith("/upload")) return "upload";
14027
- if (pathname.endsWith("/chat") || pathname.endsWith("/chat-sync")) return "chat";
14059
+ if (pathname.endsWith("/chat-sync")) return "chat-sync";
14060
+ if (pathname.endsWith("/chat")) return "chat";
14028
14061
  if (pathname.endsWith("/health")) return "health";
14029
14062
  if (pathname.endsWith("/suggestions")) return "suggestions";
14030
14063
  if (pathname.endsWith("/feedback")) return "feedback";