@retrivora-ai/rag-engine 2.3.9 → 2.4.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.
Files changed (47) hide show
  1. package/README.md +1 -1
  2. package/dist/{BatchProcessor-C42_RVWO.d.ts → BatchProcessor-D42E706a.d.ts} +12 -1
  3. package/dist/{BatchProcessor-BhLczWj5.d.mts → BatchProcessor-zbQMaZHm.d.mts} +12 -1
  4. package/dist/{ILLMProvider-B8TAVx3j.d.mts → ILLMProvider-Y6aL5N8J.d.mts} +1 -0
  5. package/dist/{ILLMProvider-B8TAVx3j.d.ts → ILLMProvider-Y6aL5N8J.d.ts} +1 -0
  6. package/dist/handlers/index.d.mts +2 -2
  7. package/dist/handlers/index.d.ts +2 -2
  8. package/dist/handlers/index.js +26 -85
  9. package/dist/handlers/index.mjs +26 -85
  10. package/dist/{index-C7aHK7_g.d.mts → index-59CHg0V3.d.mts} +1 -1
  11. package/dist/{index-BQd6Bax0.d.ts → index-BgKRInpa.d.ts} +1 -1
  12. package/dist/index.css +83 -0
  13. package/dist/index.d.mts +5 -5
  14. package/dist/index.d.ts +5 -5
  15. package/dist/index.js +482 -260
  16. package/dist/index.mjs +494 -269
  17. package/dist/server.d.mts +9 -6
  18. package/dist/server.d.ts +9 -6
  19. package/dist/server.js +34 -118
  20. package/dist/server.mjs +34 -118
  21. package/package.json +1 -1
  22. package/src/LicensedRetrivora.ts +21 -16
  23. package/src/components/ChatWindow.tsx +296 -28
  24. package/src/components/ConfigProvider.tsx +10 -1
  25. package/src/components/DocumentUpload.tsx +28 -29
  26. package/src/components/UIDispatcher.tsx +1 -1
  27. package/src/config/LicenseConfigResolver.ts +14 -12
  28. package/src/config/RagConfig.ts +1 -0
  29. package/src/config/serverConfig.ts +31 -29
  30. package/src/config/uiConstants.ts +1 -0
  31. package/src/core/ConfigFetcher.ts +2 -2
  32. package/src/core/LLMRouter.ts +3 -3
  33. package/src/core/PluginManager.ts +5 -5
  34. package/src/core/mcp.ts +5 -5
  35. package/src/handlers/index.ts +11 -5
  36. package/src/hooks/useRagChat.ts +13 -13
  37. package/src/index.css +83 -0
  38. package/src/llm/LLMFactory.ts +1 -1
  39. package/src/llm/providers/UniversalLLMAdapter.ts +18 -18
  40. package/src/providers/graphdb/SimpleGraphProvider.ts +5 -5
  41. package/src/providers/vectordb/ChromaDBProvider.ts +4 -4
  42. package/src/providers/vectordb/MultiTablePostgresProvider.ts +32 -32
  43. package/src/providers/vectordb/QdrantProvider.ts +17 -17
  44. package/src/telemetry/TelemetryService.ts +12 -12
  45. package/src/types/props.ts +11 -0
  46. package/src/utils/SchemaMapper.ts +1 -1
  47. package/src/utils/UITransformer.ts +1 -1
package/dist/server.mjs CHANGED
@@ -315,7 +315,7 @@ var init_package = __esm({
315
315
  "package.json"() {
316
316
  package_default = {
317
317
  name: "@retrivora-ai/rag-engine",
318
- version: "2.3.9",
318
+ version: "2.4.1",
319
319
  description: "Retrivora AI is a plug-and-play AI engine for RAG chat experiences \u2014 generic vector DB + LLM provider, embeddable or standalone.",
320
320
  author: "Abhinav Alkuchi",
321
321
  license: "UNLICENSED",
@@ -510,7 +510,6 @@ var init_ConfigFetcher = __esm({
510
510
  for (const baseUrl of controlPlaneUrls) {
511
511
  try {
512
512
  const url = `${baseUrl}/api/v1/config?projectId=${encodeURIComponent(projectId)}`;
513
- console.log(`[ConfigFetcher] Fetching config from: ${url}`);
514
513
  const res = await fetch(url, {
515
514
  method: "GET",
516
515
  headers: __spreadValues({
@@ -518,7 +517,6 @@ var init_ConfigFetcher = __esm({
518
517
  "x-sdk-version": SDK_VERSION
519
518
  }, licenseKey ? { "x-license-key": licenseKey } : {})
520
519
  });
521
- console.log(`[ConfigFetcher] Response status: ${res.status}`);
522
520
  if (!res.ok) {
523
521
  console.warn(`[ConfigFetcher] Error text: ${await res.text()}`);
524
522
  }
@@ -1237,9 +1235,6 @@ var init_MultiTablePostgresProvider = __esm({
1237
1235
  if (this.tables.length === 0) {
1238
1236
  console.warn('[MultiTablePostgresProvider] No tables with "embedding" columns found in the database.');
1239
1237
  } else {
1240
- console.log(
1241
- `[MultiTablePostgresProvider] Connected. Searching across ${this.tables.length} table(s): ${this.tables.join(", ")}`
1242
- );
1243
1238
  }
1244
1239
  } finally {
1245
1240
  client.release();
@@ -1361,11 +1356,8 @@ var init_MultiTablePostgresProvider = __esm({
1361
1356
  }
1362
1357
  const vectorLiteral = `[${vector.join(",")}]`;
1363
1358
  const allResults = [];
1364
- console.log(`[MultiTablePostgresProvider] --- Starting Multi-Table Search ---`);
1365
1359
  const queryText = _filter == null ? void 0 : _filter.queryText;
1366
1360
  const entityHints = Array.isArray(_filter == null ? void 0 : _filter.keywords) ? _filter.keywords.map((k) => k.trim().toLowerCase()).filter(Boolean) : [];
1367
- console.log(`[MultiTablePostgresProvider] queryText: "${queryText}"`);
1368
- console.log(`[MultiTablePostgresProvider] entityHints: [${entityHints.join(", ")}]`);
1369
1361
  const getDynamicKeywordQuery = () => {
1370
1362
  if (entityHints.length > 0) {
1371
1363
  return entityHints.map((h) => h.replace(/\s+/g, " & ")).join(" & ");
@@ -1453,9 +1445,7 @@ var init_MultiTablePostgresProvider = __esm({
1453
1445
  }
1454
1446
  const result = await this.pool.query(sqlQuery, params);
1455
1447
  if (result.rowCount && result.rowCount > 0) {
1456
- console.log(` \u2705 Table "${table}": Found ${result.rowCount} potential matches. Top score: ${result.rows[0].hybrid_score.toFixed(4)}`);
1457
1448
  } else {
1458
- console.log(` \u26AA Table "${table}": No relevant matches found.`);
1459
1449
  }
1460
1450
  const tableResults = [];
1461
1451
  for (const row of result.rows) {
@@ -1493,9 +1483,6 @@ var init_MultiTablePostgresProvider = __esm({
1493
1483
  var _a4;
1494
1484
  return ((_a4 = res.metadata) == null ? void 0 : _a4.source_table) === bestMatchTable;
1495
1485
  });
1496
- console.log(`[MultiTablePostgresProvider] --- Search Complete ---`);
1497
- console.log(`[MultiTablePostgresProvider] Final top match from "${bestMatchTable}" with score ${finalSorted[0].score.toFixed(4)}`);
1498
- console.log(`[MultiTablePostgresProvider] Restricting recommendations strictly to table: "${bestMatchTable}"`);
1499
1486
  return finalSorted.slice(0, Math.max(topK, 15));
1500
1487
  }
1501
1488
  async delete(_id, _namespace) {
@@ -1873,13 +1860,11 @@ var init_QdrantProvider = __esm({
1873
1860
  if (this.schemaDiscovered) return;
1874
1861
  await this.ping();
1875
1862
  await this.ensureCollection();
1876
- console.log(`[QdrantProvider] \u{1F50D} Discovering schema for collection "${this.indexName}"...`);
1877
1863
  const discoveredFields = await this.discoverSchema();
1878
1864
  const opts = this.config.options;
1879
1865
  const configFields = opts.filterableFields || [];
1880
1866
  const allFields = [.../* @__PURE__ */ new Set([...discoveredFields, ...configFields])];
1881
1867
  if (allFields.length > 0) {
1882
- console.log(`[QdrantProvider] \u{1F6E0} Ensuring indexes for ${allFields.length} discovered fields...`);
1883
1868
  await Promise.all(
1884
1869
  allFields.map(async (fieldInfo) => {
1885
1870
  const [fieldName, schemaType] = fieldInfo.split(":");
@@ -1887,7 +1872,6 @@ var init_QdrantProvider = __esm({
1887
1872
  })
1888
1873
  );
1889
1874
  } else {
1890
- console.log(`[QdrantProvider] \u2139\uFE0F No fields discovered for indexing.`);
1891
1875
  }
1892
1876
  this.schemaDiscovered = true;
1893
1877
  }
@@ -1931,19 +1915,16 @@ var init_QdrantProvider = __esm({
1931
1915
  var _a3;
1932
1916
  try {
1933
1917
  await this.http.get(`/collections/${this.indexName}`);
1934
- console.log(`[QdrantProvider] \u2705 Collection "${this.indexName}" already exists.`);
1935
1918
  } catch (err) {
1936
1919
  if (axios4.isAxiosError(err) && ((_a3 = err.response) == null ? void 0 : _a3.status) === 404) {
1937
1920
  const opts = this.config.options;
1938
1921
  const dimensionsForCreate = opts.dimensions || 1536;
1939
- console.log(`[QdrantProvider] \u23F3 Creating collection "${this.indexName}" (dimensions: ${dimensionsForCreate})...`);
1940
1922
  await this.http.put(`/collections/${this.indexName}`, {
1941
1923
  vectors: {
1942
1924
  size: dimensionsForCreate,
1943
1925
  distance: "Cosine"
1944
1926
  }
1945
1927
  });
1946
- console.log(`[QdrantProvider] \u2705 Created collection "${this.indexName}"`);
1947
1928
  } else {
1948
1929
  throw err;
1949
1930
  }
@@ -1963,7 +1944,6 @@ var init_QdrantProvider = __esm({
1963
1944
  field_name: fullPath,
1964
1945
  field_schema: schema
1965
1946
  });
1966
- console.log(`[QdrantProvider] \u2705 Ensured ${schema} index for "${fullPath}"`);
1967
1947
  } catch (err) {
1968
1948
  let status;
1969
1949
  if (axios4.isAxiosError(err)) status = (_a3 = err.response) == null ? void 0 : _a3.status;
@@ -2116,15 +2096,12 @@ var init_ChromaDBProvider = __esm({
2116
2096
  try {
2117
2097
  const { data } = await this.http.get(`/api/v1/collections/${this.indexName}`);
2118
2098
  this.collectionId = data.id;
2119
- console.log(`[ChromaDBProvider] \u2705 Collection "${this.indexName}" found (id: ${this.collectionId})`);
2120
2099
  } catch (err) {
2121
2100
  if (axios5.isAxiosError(err) && ((_a3 = err.response) == null ? void 0 : _a3.status) === 404) {
2122
- console.log(`[ChromaDBProvider] \u23F3 Collection "${this.indexName}" not found. Creating...`);
2123
2101
  const { data } = await this.http.post("/api/v1/collections", {
2124
2102
  name: this.indexName
2125
2103
  });
2126
2104
  this.collectionId = data.id;
2127
- console.log(`[ChromaDBProvider] \u2705 Created collection "${this.indexName}" (id: ${this.collectionId})`);
2128
2105
  } else {
2129
2106
  throw err;
2130
2107
  }
@@ -2610,7 +2587,6 @@ var init_SimpleGraphProvider = __esm({
2610
2587
  this.edges = [];
2611
2588
  }
2612
2589
  async initialize() {
2613
- console.log("[SimpleGraphProvider] Initialised in-memory graph store.");
2614
2590
  }
2615
2591
  async addNodes(nodes) {
2616
2592
  for (const node of nodes) {
@@ -2996,13 +2972,6 @@ var UI_BORDER_RADIUS_OPTIONS = ["none", "sm", "md", "lg", "xl", "full"];
2996
2972
  var _runtimeConfig = null;
2997
2973
  function injectRuntimeConfig(config) {
2998
2974
  _runtimeConfig = config;
2999
- console.log("[serverConfig] \u2705 Runtime tier config injected:", {
3000
- tier: config.tier,
3001
- llmModel: config.llmModel,
3002
- embeddingModel: config.embeddingModel,
3003
- llmBaseUrl: config.llmBaseUrl,
3004
- hasLitellmKey: !!config.litellmApiKey
3005
- });
3006
2975
  }
3007
2976
  function getRuntimeConfig() {
3008
2977
  return _runtimeConfig;
@@ -3033,7 +3002,7 @@ function getRagConfig(baseConfig, env = process.env) {
3033
3002
  return getEnvConfig(env, baseConfig);
3034
3003
  }
3035
3004
  function getEnvConfig(env = process.env, base) {
3036
- var _a3, _b, _c, _d, _e, _f, _g2, _h, _i, _j, _k, _l, _m, _n, _o, _p, _q, _r, _s, _t, _u, _v, _w, _x, _y, _z, _A, _B, _C, _D, _E, _F, _G, _H, _I, _J, _K, _L, _M, _N, _O, _P, _Q, _R, _S, _T, _U, _V, _W, _X, _Y, _Z, __, _$, _aa, _ba, _ca, _da, _ea, _fa, _ga, _ha, _ia, _ja, _ka, _la, _ma, _na, _oa, _pa, _qa, _ra, _sa, _ta, _ua, _va, _wa, _xa, _ya, _za, _Aa, _Ba, _Ca, _Da, _Ea, _Fa, _Ga, _Ha, _Ia, _Ja, _Ka, _La, _Ma, _Na, _Oa, _Pa, _Qa, _Ra, _Sa, _Ta, _Ua, _Va, _Wa, _Xa, _Ya, _Za, __a, _$a, _ab, _bb, _cb, _db, _eb, _fb, _gb, _hb, _ib, _jb, _kb, _lb, _mb, _nb, _ob, _pb, _qb, _rb, _sb, _tb, _ub, _vb, _wb, _xb, _yb, _zb, _Ab, _Bb, _Cb, _Db, _Eb, _Fb, _Gb, _Hb, _Ib;
3005
+ var _a3, _b, _c, _d, _e, _f, _g2, _h, _i, _j, _k, _l, _m, _n, _o, _p, _q, _r, _s, _t, _u, _v, _w, _x, _y, _z, _A, _B, _C, _D, _E, _F, _G, _H, _I, _J, _K, _L, _M, _N, _O, _P, _Q, _R, _S, _T, _U, _V, _W, _X, _Y, _Z, __, _$, _aa, _ba, _ca, _da, _ea, _fa, _ga, _ha, _ia, _ja, _ka, _la, _ma, _na, _oa, _pa, _qa, _ra, _sa, _ta, _ua, _va, _wa, _xa, _ya, _za, _Aa, _Ba, _Ca, _Da, _Ea, _Fa, _Ga, _Ha, _Ia, _Ja, _Ka, _La, _Ma, _Na, _Oa, _Pa, _Qa, _Ra, _Sa, _Ta, _Ua, _Va, _Wa, _Xa, _Ya, _Za, __a, _$a, _ab, _bb, _cb, _db, _eb, _fb, _gb, _hb, _ib, _jb, _kb, _lb, _mb, _nb, _ob, _pb, _qb, _rb, _sb, _tb, _ub, _vb, _wb, _xb, _yb, _zb, _Ab, _Bb, _Cb, _Db, _Eb, _Fb, _Gb, _Hb, _Ib, _Jb, _Kb, _Lb, _Mb, _Nb;
3037
3006
  const licenseKey = (_d = (_c = (_b = (_a3 = readString(env, "RAG_LICENSE_KEY")) != null ? _a3 : readString(env, "RETRIVORA_LICENSE_KEY")) != null ? _b : readString(env, "NEXT_PUBLIC_RETRIVORA_LICENSE_KEY")) != null ? _c : readString(env, "LICENSE_KEY")) != null ? _d : base == null ? void 0 : base.licenseKey;
3038
3007
  const jwtProjectId = (() => {
3039
3008
  if (!licenseKey) return void 0;
@@ -3135,26 +3104,12 @@ function getEnvConfig(env = process.env, base) {
3135
3104
  const llmModel = (_Ca = (_Ba = (_Aa = readString(env, "LLM_MODEL")) != null ? _Aa : (_za = base == null ? void 0 : base.llm) == null ? void 0 : _za.model) != null ? _Ba : rt == null ? void 0 : rt.llmModel) != null ? _Ca : tierBasedLLMModel;
3136
3105
  const llmApiKey = (_Ga = (_Fa = (_Da = readString(env, "LITELLM_MASTER_KEY")) != null ? _Da : rt == null ? void 0 : rt.litellmApiKey) != null ? _Fa : (_Ea = base == null ? void 0 : base.llm) == null ? void 0 : _Ea.apiKey) != null ? _Ga : licenseKey;
3137
3106
  const llmProfile = (_Ka = (_Ja = readString(env, "LLM_UNIVERSAL_PROFILE")) != null ? _Ja : (_Ia = (_Ha = base == null ? void 0 : base.llm) == null ? void 0 : _Ha.options) == null ? void 0 : _Ia.profile) != null ? _Ka : "litellm";
3138
- console.log("[serverConfig] \u{1F527} LLM Configuration:", {
3139
- baseUrl: llmBaseUrl,
3140
- model: llmModel,
3141
- provider: llmProvider,
3142
- hasApiKey: !!llmApiKey,
3143
- source: (rt == null ? void 0 : rt.llmModel) ? "runtime-injected" : "env/fallback"
3144
- });
3145
3107
  const defaultEmbeddingProvider = "universal_rest";
3146
3108
  const embeddingProvider = (_Na = (_Ma = readEnum(env, "EMBEDDING_PROVIDER", defaultEmbeddingProvider, EMBEDDING_PROVIDERS)) != null ? _Ma : (_La = base == null ? void 0 : base.embedding) == null ? void 0 : _La.provider) != null ? _Na : defaultEmbeddingProvider;
3147
3109
  const embeddingBaseUrl = (_Ua = (_Ta = (_Sa = (_Ra = (_Pa = (_Oa = readString(env, "LITELLM_BASE_URL")) != null ? _Oa : readString(env, "EMBEDDING_BASE_URL")) != null ? _Pa : readString(env, "LLM_BASE_URL")) != null ? _Ra : (_Qa = base == null ? void 0 : base.embedding) == null ? void 0 : _Qa.baseUrl) != null ? _Sa : rt == null ? void 0 : rt.embeddingBaseUrl) != null ? _Ta : rt == null ? void 0 : rt.llmBaseUrl) != null ? _Ua : defaultGatewayUrl;
3148
3110
  const embeddingModel = (_Ya = (_Xa = (_Wa = readString(env, "EMBEDDING_MODEL")) != null ? _Wa : (_Va = base == null ? void 0 : base.embedding) == null ? void 0 : _Va.model) != null ? _Xa : rt == null ? void 0 : rt.embeddingModel) != null ? _Ya : tierBasedEmbeddingModel;
3149
3111
  const embeddingApiKey = (_ab = (_$a = (_Za = readString(env, "LITELLM_MASTER_KEY")) != null ? _Za : rt == null ? void 0 : rt.litellmApiKey) != null ? _$a : (__a = base == null ? void 0 : base.embedding) == null ? void 0 : __a.apiKey) != null ? _ab : licenseKey;
3150
3112
  const embeddingProfile = (_eb = (_db = readString(env, "EMBEDDING_UNIVERSAL_PROFILE")) != null ? _db : (_cb = (_bb = base == null ? void 0 : base.embedding) == null ? void 0 : _bb.options) == null ? void 0 : _cb.profile) != null ? _eb : "litellm";
3151
- console.log("[serverConfig] \u{1F527} Embedding Configuration:", {
3152
- baseUrl: embeddingBaseUrl,
3153
- model: embeddingModel,
3154
- provider: embeddingProvider,
3155
- hasApiKey: !!embeddingApiKey,
3156
- source: (rt == null ? void 0 : rt.embeddingModel) ? "runtime-injected" : "env/fallback"
3157
- });
3158
3113
  return __spreadProps(__spreadValues({
3159
3114
  projectId,
3160
3115
  licenseKey,
@@ -3168,8 +3123,8 @@ function getEnvConfig(env = process.env, base) {
3168
3123
  model: llmModel,
3169
3124
  apiKey: llmApiKey,
3170
3125
  baseUrl: llmBaseUrl,
3171
- systemPrompt: readString(env, "LLM_SYSTEM_PROMPT"),
3172
- maxTokens: readNumber(env, "LLM_MAX_TOKENS", 4096),
3126
+ systemPrompt: (_hb = readString(env, "LLM_SYSTEM_PROMPT")) != null ? _hb : rt == null ? void 0 : rt.systemPrompt,
3127
+ maxTokens: readNumber(env, "LLM_MAX_TOKENS", (_ib = rt == null ? void 0 : rt.maxTokens) != null ? _ib : 4096),
3173
3128
  temperature: readNumber(env, "LLM_TEMPERATURE", 0.7),
3174
3129
  options: {
3175
3130
  profile: llmProfile,
@@ -3190,30 +3145,30 @@ function getEnvConfig(env = process.env, base) {
3190
3145
  }
3191
3146
  },
3192
3147
  ui: {
3193
- title: (_ib = (_hb = readString(env, "NEXT_PUBLIC_UI_TITLE")) != null ? _hb : readString(env, "UI_TITLE")) != null ? _ib : "AI Assistant",
3194
- subtitle: (_kb = (_jb = readString(env, "NEXT_PUBLIC_UI_SUBTITLE")) != null ? _jb : readString(env, "UI_SUBTITLE")) != null ? _kb : "Powered by RAG",
3195
- primaryColor: (_mb = (_lb = readString(env, "NEXT_PUBLIC_PRIMARY_COLOR")) != null ? _lb : readString(env, "UI_PRIMARY_COLOR")) != null ? _mb : "#10b981",
3196
- accentColor: (_ob = (_nb = readString(env, "NEXT_PUBLIC_ACCENT_COLOR")) != null ? _nb : readString(env, "UI_ACCENT_COLOR")) != null ? _ob : "#3b82f6",
3197
- logoUrl: (_pb = readString(env, "NEXT_PUBLIC_LOGO_URL")) != null ? _pb : readString(env, "UI_LOGO_URL"),
3198
- placeholder: (_rb = (_qb = readString(env, "NEXT_PUBLIC_PLACEHOLDER")) != null ? _qb : readString(env, "UI_PLACEHOLDER")) != null ? _rb : "Ask me anything\u2026",
3199
- showSources: ((_tb = (_sb = readString(env, "NEXT_PUBLIC_SHOW_SOURCES")) != null ? _sb : readString(env, "UI_SHOW_SOURCES")) != null ? _tb : "true") !== "false",
3200
- welcomeMessage: (_vb = (_ub = readString(env, "NEXT_PUBLIC_WELCOME_MESSAGE")) != null ? _ub : readString(env, "UI_WELCOME_MESSAGE")) != null ? _vb : "Hello! I'm your AI assistant. Ask me anything about your documents.",
3201
- visualStyle: (_xb = (_wb = readString(env, "NEXT_PUBLIC_UI_VISUAL_STYLE")) != null ? _wb : readString(env, "UI_VISUAL_STYLE")) != null ? _xb : "glass",
3202
- borderRadius: (_zb = (_yb = readString(env, "NEXT_PUBLIC_UI_BORDER_RADIUS")) != null ? _yb : readString(env, "UI_BORDER_RADIUS")) != null ? _zb : "xl",
3203
- allowUpload: ((_Bb = (_Ab = readString(env, "NEXT_PUBLIC_ALLOW_UPLOAD")) != null ? _Ab : readString(env, "UI_ALLOW_UPLOAD")) != null ? _Bb : "false") === "true"
3148
+ title: (_kb = (_jb = readString(env, "NEXT_PUBLIC_UI_TITLE")) != null ? _jb : readString(env, "UI_TITLE")) != null ? _kb : "AI Assistant",
3149
+ subtitle: (_mb = (_lb = readString(env, "NEXT_PUBLIC_UI_SUBTITLE")) != null ? _lb : readString(env, "UI_SUBTITLE")) != null ? _mb : "Powered by RAG",
3150
+ primaryColor: (_ob = (_nb = readString(env, "NEXT_PUBLIC_PRIMARY_COLOR")) != null ? _nb : readString(env, "UI_PRIMARY_COLOR")) != null ? _ob : "#10b981",
3151
+ accentColor: (_qb = (_pb = readString(env, "NEXT_PUBLIC_ACCENT_COLOR")) != null ? _pb : readString(env, "UI_ACCENT_COLOR")) != null ? _qb : "#3b82f6",
3152
+ logoUrl: (_rb = readString(env, "NEXT_PUBLIC_LOGO_URL")) != null ? _rb : readString(env, "UI_LOGO_URL"),
3153
+ placeholder: (_tb = (_sb = readString(env, "NEXT_PUBLIC_PLACEHOLDER")) != null ? _sb : readString(env, "UI_PLACEHOLDER")) != null ? _tb : "Ask me anything\u2026",
3154
+ showSources: ((_vb = (_ub = readString(env, "NEXT_PUBLIC_SHOW_SOURCES")) != null ? _ub : readString(env, "UI_SHOW_SOURCES")) != null ? _vb : "true") !== "false",
3155
+ welcomeMessage: (_xb = (_wb = readString(env, "NEXT_PUBLIC_WELCOME_MESSAGE")) != null ? _wb : readString(env, "UI_WELCOME_MESSAGE")) != null ? _xb : "Hello! I'm your AI assistant. Ask me anything about your documents.",
3156
+ visualStyle: (_zb = (_yb = readString(env, "NEXT_PUBLIC_UI_VISUAL_STYLE")) != null ? _yb : readString(env, "UI_VISUAL_STYLE")) != null ? _zb : "glass",
3157
+ borderRadius: (_Bb = (_Ab = readString(env, "NEXT_PUBLIC_UI_BORDER_RADIUS")) != null ? _Ab : readString(env, "UI_BORDER_RADIUS")) != null ? _Bb : "xl",
3158
+ allowUpload: ((_Db = (_Cb = readString(env, "NEXT_PUBLIC_ALLOW_UPLOAD")) != null ? _Cb : readString(env, "UI_ALLOW_UPLOAD")) != null ? _Db : "false") === "true"
3204
3159
  },
3205
3160
  rag: {
3206
- topK: readNumber(env, "RAG_TOP_K", 5),
3161
+ topK: readNumber(env, "RAG_TOP_K", (_Eb = rt == null ? void 0 : rt.topK) != null ? _Eb : 5),
3207
3162
  scoreThreshold: readNumber(env, "RAG_SCORE_THRESHOLD", 0),
3208
- chunkSize: readNumber(env, "RAG_CHUNK_SIZE", 1e3),
3209
- chunkOverlap: readNumber(env, "RAG_CHUNK_OVERLAP", 200),
3210
- filterableFields: (_Cb = readString(env, "RAG_FILTERABLE_FIELDS")) == null ? void 0 : _Cb.split(",").map((f) => f.trim()),
3163
+ chunkSize: readNumber(env, "RAG_CHUNK_SIZE", (_Fb = rt == null ? void 0 : rt.chunkSize) != null ? _Fb : 1e3),
3164
+ chunkOverlap: readNumber(env, "RAG_CHUNK_OVERLAP", (_Gb = rt == null ? void 0 : rt.chunkOverlap) != null ? _Gb : 200),
3165
+ filterableFields: (_Hb = readString(env, "RAG_FILTERABLE_FIELDS")) == null ? void 0 : _Hb.split(",").map((f) => f.trim()),
3211
3166
  // Query pipeline toggles — read from .env.local
3212
3167
  useQueryTransformation: readString(env, "RAG_USE_QUERY_TRANSFORMATION") === "true",
3213
3168
  useReranking: readString(env, "RAG_USE_RERANKING") === "true",
3214
3169
  useGraphRetrieval: readString(env, "RAG_USE_GRAPH_RETRIEVAL") === "true",
3215
- architecture: (_Db = readString(env, "RAG_ARCHITECTURE")) != null ? _Db : "simple",
3216
- chunkingStrategy: (_Eb = readString(env, "RAG_CHUNKING_STRATEGY")) != null ? _Eb : "recursive",
3170
+ architecture: (_Ib = readString(env, "RAG_ARCHITECTURE")) != null ? _Ib : "simple",
3171
+ chunkingStrategy: (_Jb = readString(env, "RAG_CHUNKING_STRATEGY")) != null ? _Jb : "recursive",
3217
3172
  uiMapping: (() => {
3218
3173
  const raw = readString(env, "RAG_UI_MAPPING");
3219
3174
  if (!raw) return void 0;
@@ -3226,7 +3181,7 @@ function getEnvConfig(env = process.env, base) {
3226
3181
  },
3227
3182
  telemetry: {
3228
3183
  enabled: telemetryEnabled,
3229
- url: (_Ib = (_Hb = (_Fb = readString(env, "TELEMETRY_URL")) != null ? _Fb : readString(env, "NEXT_PUBLIC_TELEMETRY_URL")) != null ? _Hb : (_Gb = base == null ? void 0 : base.telemetry) == null ? void 0 : _Gb.url) != null ? _Ib : "https://www.retrivora.com/api/telemetry"
3184
+ url: (_Nb = (_Mb = (_Kb = readString(env, "TELEMETRY_URL")) != null ? _Kb : readString(env, "NEXT_PUBLIC_TELEMETRY_URL")) != null ? _Mb : (_Lb = base == null ? void 0 : base.telemetry) == null ? void 0 : _Lb.url) != null ? _Nb : "https://www.retrivora.com/api/telemetry"
3230
3185
  }
3231
3186
  }, readString(env, "GRAPH_DB_PROVIDER") ? {
3232
3187
  graphDb: {
@@ -4576,12 +4531,6 @@ var UniversalLLMAdapter = class {
4576
4531
  this.resolvedHeaders = __spreadValues(__spreadValues({
4577
4532
  "Content-Type": "application/json"
4578
4533
  }, config.apiKey ? { Authorization: `Bearer ${config.apiKey}` } : {}), this.opts.headers || {});
4579
- console.log("[UniversalLLMAdapter] Initialized with:", {
4580
- model: this.model,
4581
- baseUrl: this.baseUrl,
4582
- hasApiKey: !!this.apiKey,
4583
- apiKeyPrefix: this.apiKey ? `${this.apiKey.slice(0, 12)}...` : void 0
4584
- });
4585
4534
  this.http = axios2.create({
4586
4535
  baseURL: this.baseUrl,
4587
4536
  headers: this.resolvedHeaders,
@@ -4798,15 +4747,10 @@ ${context != null ? context : "None"}` },
4798
4747
  const path2 = (_a3 = this.opts.embedPath) != null ? _a3 : "/embeddings";
4799
4748
  const payload = this.opts.embedPayloadTemplate ? buildPayload(this.opts.embedPayloadTemplate, { input: text, model: this.model }) : { input: text, model: this.model };
4800
4749
  try {
4801
- console.log(`[UniversalLLMAdapter] Posting to embedding endpoint: ${this.baseUrl}${path2}`, {
4802
- model: this.model,
4803
- inputLength: typeof text === "string" ? text.length : "unknown"
4804
- });
4805
4750
  const { data } = await this.http.post(path2, payload);
4806
4751
  const extractPath = (_b = this.opts.embedExtractPath) != null ? _b : "data[0].embedding";
4807
4752
  const vector = resolvePath(data, extractPath);
4808
4753
  if (Array.isArray(vector)) {
4809
- console.log(`[UniversalLLMAdapter] Embedding HTTP request successful. Vector size: ${vector.length}`);
4810
4754
  return vector;
4811
4755
  }
4812
4756
  console.warn(
@@ -4832,12 +4776,10 @@ ${context != null ? context : "None"}` },
4832
4776
  }
4833
4777
  }
4834
4778
  try {
4835
- console.log(`[UniversalLLMAdapter] Retrying embedding request to: ${this.baseUrl}${path2}`);
4836
4779
  const { data } = await this.http.post(path2, payload);
4837
4780
  const extractPath = (_f = this.opts.embedExtractPath) != null ? _f : "data[0].embedding";
4838
4781
  const vector = resolvePath(data, extractPath);
4839
4782
  if (Array.isArray(vector)) {
4840
- console.log(`[UniversalLLMAdapter] Retry embedding HTTP request successful. Vector size: ${vector.length}`);
4841
4783
  return vector;
4842
4784
  }
4843
4785
  console.error(
@@ -4901,7 +4843,6 @@ var LLMFactory = class _LLMFactory {
4901
4843
  */
4902
4844
  static register(name, factory) {
4903
4845
  customProviders.set(name.toLowerCase(), factory);
4904
- console.log(`[LLMFactory] Registered custom provider: "${name}"`);
4905
4846
  }
4906
4847
  /**
4907
4848
  * Unregister a previously registered custom provider.
@@ -5681,7 +5622,6 @@ var MCPClient = class {
5681
5622
  });
5682
5623
  await this.sendNotification("notifications/initialized");
5683
5624
  this.initialized = true;
5684
- console.log(`[MCPClient] Connected and initialized server "${this.config.name}" successfully.`);
5685
5625
  } catch (err) {
5686
5626
  this.disconnect();
5687
5627
  throw new Error(`[MCPClient] Failed to initialize server "${this.config.name}": ${err.message}`);
@@ -5707,7 +5647,6 @@ var MCPClient = class {
5707
5647
  console.warn(`[MCPClient] [stderr] [${this.config.name}]:`, data.toString("utf-8"));
5708
5648
  });
5709
5649
  this.childProcess.on("close", (code) => {
5710
- console.log(`[MCPClient] Connection closed for "${this.config.name}" with exit code: ${code}`);
5711
5650
  this.disconnect();
5712
5651
  });
5713
5652
  await new Promise((resolve) => setTimeout(resolve, 100));
@@ -6842,13 +6781,11 @@ var LLMRouter = class {
6842
6781
  const providerFastDefault = (_a3 = FAST_MODEL_DEFAULTS[this.config.llm.provider]) != null ? _a3 : "";
6843
6782
  const fastModelName = envFastModel || providerFastDefault;
6844
6783
  if (fastModelName && fastModelName !== this.config.llm.model) {
6845
- console.log(`[LLMRouter] Fast role \u2192 provider="${this.config.llm.provider}" model="${fastModelName}"`);
6846
6784
  const fastConfig = __spreadProps(__spreadValues({}, this.config.llm), {
6847
6785
  model: fastModelName
6848
6786
  });
6849
6787
  this.models.set("fast", LLMFactory.create(fastConfig, this.config.embedding));
6850
6788
  } else {
6851
- console.log(`[LLMRouter] Fast role \u2192 reusing default model (no lightweight alternative configured).`);
6852
6789
  this.models.set("fast", defaultModel);
6853
6790
  }
6854
6791
  this.models.set("powerful", defaultModel);
@@ -8844,7 +8781,6 @@ var SchemaMapper = class {
8844
8781
  }
8845
8782
  static async _doTrain(llm, cacheKey, keys) {
8846
8783
  var _a3, _b, _c, _d, _e, _f, _g2, _h, _i, _j, _k;
8847
- console.log(`[SchemaMapper] \u{1F9E0} Training on new schema keys: ${keys.join(", ")}`);
8848
8784
  const propertyList = Object.entries(this.TARGET_PROPERTIES).map(([prop, desc]) => `- ${prop} (${desc})`).join("\n");
8849
8785
  const messages = [
8850
8786
  { role: "system", content: "You are a database schema expert. Respond ONLY with valid JSON." },
@@ -11807,7 +11743,6 @@ function createStreamHandler(configOrPlugin, options) {
11807
11743
  },
11808
11744
  cancel(reason) {
11809
11745
  isActive = false;
11810
- console.log("[createStreamHandler] Stream connection closed by client:", reason);
11811
11746
  }
11812
11747
  });
11813
11748
  return new Response(stream, { headers: __spreadProps(__spreadValues({}, SSE_HEADERS), { "x-message-id": assistantMsgId, "x-user-message-id": userMsgId }) });
@@ -11898,7 +11833,6 @@ function createLicenseHandler(configOrPlugin, options) {
11898
11833
  const rawKey = req.headers.get("x-license-key") || (body == null ? void 0 : body.licenseKey) || ((_a3 = req.headers.get("authorization")) == null ? void 0 : _a3.replace(/^Bearer\s+/i, "")) || config.licenseKey || process.env.NEXT_PUBLIC_RETRIVORA_LICENSE_KEY || process.env.RETRIVORA_LICENSE_KEY || "";
11899
11834
  const licenseKey = (rawKey || "").trim().replace(/^["']|["']$/g, "").trim();
11900
11835
  const projectId = (body == null ? void 0 : body.projectId) || config.projectId || "";
11901
- console.log(`[DEBUG] createLicenseHandler: projectId="${projectId}", body.projectId="${body == null ? void 0 : body.projectId}", config.projectId="${config.projectId}"`);
11902
11836
  const payload = await LicenseVerifier.verifyAsync(licenseKey, projectId);
11903
11837
  return NextResponse.json({
11904
11838
  valid: true,
@@ -11929,7 +11863,6 @@ function createUploadHandler(configOrPlugin, options) {
11929
11863
  const plugin = getOrCreatePlugin(configOrPlugin);
11930
11864
  const onAuthorize = options == null ? void 0 : options.onAuthorize;
11931
11865
  return async function POST(req, context) {
11932
- console.log("Upload handler invoked");
11933
11866
  const authResult = await checkAuth(req, onAuthorize);
11934
11867
  if (authResult) return authResult;
11935
11868
  const config = plugin.getConfig();
@@ -11938,7 +11871,6 @@ function createUploadHandler(configOrPlugin, options) {
11938
11871
  try {
11939
11872
  const formData = await req.formData();
11940
11873
  const files = formData.getAll("files");
11941
- console.log("Files received for upload:", files.map((f) => f.name));
11942
11874
  const namespace = formData.get("namespace") || void 0;
11943
11875
  const dimensionRaw = formData.get("dimension");
11944
11876
  const dimension = dimensionRaw ? parseInt(dimensionRaw, 10) : void 0;
@@ -12276,7 +12208,7 @@ function createRagHandler(configOrPlugin, options) {
12276
12208
  }
12277
12209
  }
12278
12210
  async function getSegment(req, context) {
12279
- var _a3, _b;
12211
+ var _a3, _b, _c;
12280
12212
  const contentType = req.headers.get("content-type") || "";
12281
12213
  if (contentType.includes("multipart/form-data")) {
12282
12214
  return "upload";
@@ -12291,10 +12223,12 @@ function createRagHandler(configOrPlugin, options) {
12291
12223
  if (pathname.endsWith("/suggestions")) return "suggestions";
12292
12224
  if (pathname.endsWith("/feedback")) return "feedback";
12293
12225
  if (pathname.endsWith("/history")) return "history";
12226
+ if (pathname.endsWith("/history/clear")) return "history/clear";
12227
+ if (pathname.endsWith("/sessions")) return "sessions";
12294
12228
  } catch (e) {
12295
12229
  }
12296
12230
  const resolvedParams = typeof ((_a3 = context == null ? void 0 : context.params) == null ? void 0 : _a3.then) === "function" ? await context.params : context == null ? void 0 : context.params;
12297
- const segments = (resolvedParams == null ? void 0 : resolvedParams.retrivora) || ((_b = resolvedParams == null ? void 0 : resolvedParams.params) == null ? void 0 : _b.retrivora) || [];
12231
+ const segments = (resolvedParams == null ? void 0 : resolvedParams.retrivora) || ((_b = resolvedParams == null ? void 0 : resolvedParams.params) == null ? void 0 : _b.retrivora) || (resolvedParams == null ? void 0 : resolvedParams.rag) || ((_c = resolvedParams == null ? void 0 : resolvedParams.params) == null ? void 0 : _c.rag) || [];
12298
12232
  const joined = segments.join("/");
12299
12233
  return joined || "chat";
12300
12234
  }
@@ -12507,19 +12441,11 @@ var LicenseConfigResolver = class {
12507
12441
  const cacheKey = `${licenseKey}:${projectId}`;
12508
12442
  const cached = this.configCache.get(cacheKey);
12509
12443
  if (cached && Date.now() - cached.timestamp < this.CACHE_TTL_MS) {
12510
- console.log("[LicenseConfigResolver] Using cached config for", projectId);
12511
12444
  return this.buildConfigs(cached.config, cached.credentials, licenseKey, projectId);
12512
12445
  }
12513
- console.log("[LicenseConfigResolver] Fetching tier config from Retrivora...");
12514
12446
  const tierConfig = await this.fetchTierConfig(licenseKey, projectId);
12515
- console.log("[LicenseConfigResolver] Fetching provider credentials from Retrivora...");
12516
12447
  const credentials = await this.fetchProviderCredentials(licenseKey, projectId);
12517
12448
  this.configCache.set(cacheKey, { config: tierConfig, credentials, timestamp: Date.now() });
12518
- console.log("[LicenseConfigResolver] \u2705 Successfully resolved config from Retrivora:", {
12519
- tier: tierConfig.tier,
12520
- llmModel: tierConfig.llmModel,
12521
- embeddingModel: tierConfig.embeddingModel
12522
- });
12523
12449
  return this.buildConfigs(tierConfig, credentials, licenseKey, projectId);
12524
12450
  }
12525
12451
  /**
@@ -12545,7 +12471,6 @@ var LicenseConfigResolver = class {
12545
12471
  `[LicenseConfigResolver] Config API returned error: ${response.data.error || response.data.message}`
12546
12472
  );
12547
12473
  }
12548
- console.log(`[LicenseConfigResolver] Resolved tier: ${response.data.config.tier}`);
12549
12474
  return response.data.config;
12550
12475
  } catch (err) {
12551
12476
  console.error("[LicenseConfigResolver] Failed to fetch config:", err.message);
@@ -12577,7 +12502,6 @@ var LicenseConfigResolver = class {
12577
12502
  `[LicenseConfigResolver] Credentials API returned error: ${response.data.error || response.data.message}`
12578
12503
  );
12579
12504
  }
12580
- console.log(`[LicenseConfigResolver] Retrieved provider credentials for project: ${projectId}`);
12581
12505
  return response.data.credentials;
12582
12506
  } catch (err) {
12583
12507
  console.error("[LicenseConfigResolver] Failed to fetch credentials:", err.message);
@@ -12602,8 +12526,9 @@ var LicenseConfigResolver = class {
12602
12526
  provider: llmProvider,
12603
12527
  model: tierConfig.llmModel,
12604
12528
  apiKey: llmApiKey,
12605
- maxTokens: tierConfig.maxTokens,
12529
+ maxTokens: tierConfig == null ? void 0 : tierConfig.maxTokens,
12606
12530
  temperature: 0.7,
12531
+ systemPrompt: tierConfig == null ? void 0 : tierConfig.systemPrompt,
12607
12532
  options: {}
12608
12533
  };
12609
12534
  const embeddingConfig = {
@@ -12653,7 +12578,6 @@ var LicenseConfigResolver = class {
12653
12578
  */
12654
12579
  static clearCache() {
12655
12580
  this.configCache.clear();
12656
- console.log("[LicenseConfigResolver] Configuration cache cleared");
12657
12581
  }
12658
12582
  /**
12659
12583
  * Get cache stats for debugging
@@ -12800,7 +12724,6 @@ var _TelemetryService = class _TelemetryService {
12800
12724
  };
12801
12725
  try {
12802
12726
  await this.http.post(_TelemetryService.RETRIVORA_TELEMETRY_URL, payload);
12803
- console.log(`[TelemetryService] Flushed ${events.length} events to Retrivora`);
12804
12727
  } catch (err) {
12805
12728
  console.warn("[TelemetryService] Failed to send telemetry to Retrivora:", err.message);
12806
12729
  this.eventQueue.unshift(...events);
@@ -12814,7 +12737,6 @@ var _TelemetryService = class _TelemetryService {
12814
12737
  "X-Project-ID": this.projectId
12815
12738
  }
12816
12739
  });
12817
- console.log(`[TelemetryService] Flushed ${events.length} events to user telemetry`);
12818
12740
  } catch (err) {
12819
12741
  console.warn("[TelemetryService] Failed to send telemetry to user endpoint:", err.message);
12820
12742
  }
@@ -12868,7 +12790,6 @@ function getTelemetryService() {
12868
12790
  }
12869
12791
  function initializeTelemetryService(projectId, licenseKey, userTelemetryUrl) {
12870
12792
  globalTelemetryService = new TelemetryService(projectId, licenseKey, userTelemetryUrl);
12871
- console.log("[TelemetryService] Initialized for project:", projectId);
12872
12793
  return globalTelemetryService;
12873
12794
  }
12874
12795
  async function shutdownTelemetryService() {
@@ -12899,13 +12820,12 @@ var LicensedRetrivora = class {
12899
12820
  */
12900
12821
  async initialize() {
12901
12822
  if (this.initialized) {
12902
- console.log("[LicensedRetrivora] Already initialized");
12903
12823
  return;
12904
12824
  }
12905
- console.log("[LicensedRetrivora] Initializing with license key...");
12906
12825
  const operationId = this.generateId();
12907
12826
  try {
12908
12827
  const { llmConfig, embeddingConfig, vectorDbConfig, tierConfig } = await LicenseConfigResolver.resolveFromLicense(this.licenseKey, this.projectId);
12828
+ this.tierConfig = tierConfig;
12909
12829
  const telemetry = getTelemetryService();
12910
12830
  if (telemetry) {
12911
12831
  telemetry.recordEvent({
@@ -12939,7 +12859,6 @@ var LicensedRetrivora = class {
12939
12859
  this.pipeline = new Pipeline(this.ragConfig);
12940
12860
  await this.pipeline.initialize();
12941
12861
  this.initialized = true;
12942
- console.log(`[LicensedRetrivora] Initialized successfully for tier: ${tierConfig.tier}`);
12943
12862
  } catch (error) {
12944
12863
  const telemetry = getTelemetryService();
12945
12864
  if (telemetry && error instanceof Error) {
@@ -12961,16 +12880,16 @@ var LicensedRetrivora = class {
12961
12880
  const telemetry = getTelemetryService();
12962
12881
  const startTime = Date.now();
12963
12882
  try {
12964
- console.log(`[LicensedRetrivora] Starting ingestion of ${documents.length} document(s)`);
12965
12883
  const results = await this.pipeline.ingest(documents);
12966
12884
  const durationMs = Date.now() - startTime;
12967
12885
  if (telemetry) {
12968
12886
  for (const result of results) {
12887
+ const origDoc = documents.find((d) => String(d.docId) === String(result.docId));
12888
+ const size = origDoc ? new TextEncoder().encode(origDoc.content).length : 0;
12969
12889
  telemetry.recordDocumentIngested({
12970
12890
  documentId: String(result.docId),
12971
12891
  documentName: String(result.docId),
12972
- documentSize: 0,
12973
- // TODO: track actual size
12892
+ documentSize: size,
12974
12893
  chunksGenerated: result.chunksIngested,
12975
12894
  durationMs
12976
12895
  });
@@ -13005,7 +12924,6 @@ var LicensedRetrivora = class {
13005
12924
  const telemetry = getTelemetryService();
13006
12925
  const startTime = Date.now();
13007
12926
  try {
13008
- console.log(`[LicensedRetrivora] Executing query: "${queryText.substring(0, 100)}..."`);
13009
12927
  const response = await this.pipeline.runNormalQuery(queryText);
13010
12928
  const durationMs = Date.now() - startTime;
13011
12929
  if (telemetry) {
@@ -13034,12 +12952,11 @@ var LicensedRetrivora = class {
13034
12952
  * Get license tier information (for UI display if needed)
13035
12953
  */
13036
12954
  async getTierInfo() {
13037
- if (!this.ragConfig) {
12955
+ if (!this.ragConfig || !this.tierConfig) {
13038
12956
  throw new Error("[LicensedRetrivora] SDK not initialized.");
13039
12957
  }
13040
12958
  return {
13041
- tier: "Standard",
13042
- // TODO: fetch from tier config
12959
+ tier: this.tierConfig.tier,
13043
12960
  model: this.ragConfig.llm.model,
13044
12961
  embeddingModel: this.ragConfig.embedding.model
13045
12962
  };
@@ -13050,7 +12967,6 @@ var LicensedRetrivora = class {
13050
12967
  async shutdown() {
13051
12968
  await shutdownTelemetryService();
13052
12969
  this.initialized = false;
13053
- console.log("[LicensedRetrivora] Shutdown complete");
13054
12970
  }
13055
12971
  /**
13056
12972
  * Check if SDK is initialized
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@retrivora-ai/rag-engine",
3
- "version": "2.3.9",
3
+ "version": "2.4.1",
4
4
  "description": "Retrivora AI is a plug-and-play AI engine for RAG chat experiences — generic vector DB + LLM provider, embeddable or standalone.",
5
5
  "author": "Abhinav Alkuchi",
6
6
  "license": "UNLICENSED",