@retrivora-ai/rag-engine 2.3.8 → 2.3.9

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/server.js CHANGED
@@ -330,7 +330,7 @@ var init_package = __esm({
330
330
  "package.json"() {
331
331
  package_default = {
332
332
  name: "@retrivora-ai/rag-engine",
333
- version: "2.3.8",
333
+ version: "2.3.9",
334
334
  description: "Retrivora AI is a plug-and-play AI engine for RAG chat experiences \u2014 generic vector DB + LLM provider, embeddable or standalone.",
335
335
  author: "Abhinav Alkuchi",
336
336
  license: "UNLICENSED",
@@ -525,6 +525,7 @@ var init_ConfigFetcher = __esm({
525
525
  for (const baseUrl of controlPlaneUrls) {
526
526
  try {
527
527
  const url = `${baseUrl}/api/v1/config?projectId=${encodeURIComponent(projectId)}`;
528
+ console.log(`[ConfigFetcher] Fetching config from: ${url}`);
528
529
  const res = await fetch(url, {
529
530
  method: "GET",
530
531
  headers: __spreadValues({
@@ -532,6 +533,10 @@ var init_ConfigFetcher = __esm({
532
533
  "x-sdk-version": SDK_VERSION
533
534
  }, licenseKey ? { "x-license-key": licenseKey } : {})
534
535
  });
536
+ console.log(`[ConfigFetcher] Response status: ${res.status}`);
537
+ if (!res.ok) {
538
+ console.warn(`[ConfigFetcher] Error text: ${await res.text()}`);
539
+ }
535
540
  if (res.ok) {
536
541
  const data = await res.json();
537
542
  if ((data == null ? void 0 : data.success) && (data == null ? void 0 : data.vectorDb)) {
@@ -3142,7 +3147,7 @@ function getRagConfig(baseConfig, env = process.env) {
3142
3147
  return getEnvConfig(env, baseConfig);
3143
3148
  }
3144
3149
  function getEnvConfig(env = process.env, base) {
3145
- 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;
3150
+ 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;
3146
3151
  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;
3147
3152
  const jwtProjectId = (() => {
3148
3153
  if (!licenseKey) return void 0;
@@ -3235,14 +3240,15 @@ function getEnvConfig(env = process.env, base) {
3235
3240
  })();
3236
3241
  const tierBasedLLMModel = isFreeTier2 ? "llama-3.1-8b-instant" : "llama-3.3-70b-versatile";
3237
3242
  const tierBasedEmbeddingModel = isFreeTier2 ? "text-embedding-004" : "text-embedding-004";
3238
- const defaultGatewayUrl = "https://llm.retrivora.com/api/v1";
3243
+ const controlPlaneUrl = (_qa = readString(env, "RETRIVORA_CONTROL_PLANE_URL")) != null ? _qa : readString(env, "NEXT_PUBLIC_RETRIVORA_CONTROL_PLANE_URL");
3244
+ const defaultGatewayUrl = controlPlaneUrl ? `${controlPlaneUrl.replace(/\/$/, "")}/api/v1` : "https://llm.retrivora.com/api/v1";
3239
3245
  const rt = _runtimeConfig;
3240
3246
  const defaultLlmProvider = "universal_rest";
3241
- const llmProvider = (_sa = (_ra = readEnum(env, "LLM_PROVIDER", defaultLlmProvider, LLM_PROVIDERS)) != null ? _ra : (_qa = base == null ? void 0 : base.llm) == null ? void 0 : _qa.provider) != null ? _sa : defaultLlmProvider;
3242
- const llmBaseUrl = (_xa = (_wa = (_va = (_ta = readString(env, "LITELLM_BASE_URL")) != null ? _ta : readString(env, "LLM_BASE_URL")) != null ? _va : (_ua = base == null ? void 0 : base.llm) == null ? void 0 : _ua.baseUrl) != null ? _wa : rt == null ? void 0 : rt.llmBaseUrl) != null ? _xa : defaultGatewayUrl;
3243
- const llmModel = (_Ba = (_Aa = (_za = readString(env, "LLM_MODEL")) != null ? _za : (_ya = base == null ? void 0 : base.llm) == null ? void 0 : _ya.model) != null ? _Aa : rt == null ? void 0 : rt.llmModel) != null ? _Ba : tierBasedLLMModel;
3244
- const llmApiKey = (_Fa = (_Ea = (_Ca = readString(env, "LITELLM_MASTER_KEY")) != null ? _Ca : rt == null ? void 0 : rt.litellmApiKey) != null ? _Ea : (_Da = base == null ? void 0 : base.llm) == null ? void 0 : _Da.apiKey) != null ? _Fa : licenseKey;
3245
- const llmProfile = (_Ja = (_Ia = readString(env, "LLM_UNIVERSAL_PROFILE")) != null ? _Ia : (_Ha = (_Ga = base == null ? void 0 : base.llm) == null ? void 0 : _Ga.options) == null ? void 0 : _Ha.profile) != null ? _Ja : "litellm";
3247
+ const llmProvider = (_ta = (_sa = readEnum(env, "LLM_PROVIDER", defaultLlmProvider, LLM_PROVIDERS)) != null ? _sa : (_ra = base == null ? void 0 : base.llm) == null ? void 0 : _ra.provider) != null ? _ta : defaultLlmProvider;
3248
+ const llmBaseUrl = (_ya = (_xa = (_wa = (_ua = readString(env, "LITELLM_BASE_URL")) != null ? _ua : readString(env, "LLM_BASE_URL")) != null ? _wa : (_va = base == null ? void 0 : base.llm) == null ? void 0 : _va.baseUrl) != null ? _xa : rt == null ? void 0 : rt.llmBaseUrl) != null ? _ya : defaultGatewayUrl;
3249
+ 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;
3250
+ 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;
3251
+ 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";
3246
3252
  console.log("[serverConfig] \u{1F527} LLM Configuration:", {
3247
3253
  baseUrl: llmBaseUrl,
3248
3254
  model: llmModel,
@@ -3251,17 +3257,24 @@ function getEnvConfig(env = process.env, base) {
3251
3257
  source: (rt == null ? void 0 : rt.llmModel) ? "runtime-injected" : "env/fallback"
3252
3258
  });
3253
3259
  const defaultEmbeddingProvider = "universal_rest";
3254
- const embeddingProvider = (_Ma = (_La = readEnum(env, "EMBEDDING_PROVIDER", defaultEmbeddingProvider, EMBEDDING_PROVIDERS)) != null ? _La : (_Ka = base == null ? void 0 : base.embedding) == null ? void 0 : _Ka.provider) != null ? _Ma : defaultEmbeddingProvider;
3255
- const embeddingBaseUrl = (_Ta = (_Sa = (_Ra = (_Qa = (_Oa = (_Na = readString(env, "LITELLM_BASE_URL")) != null ? _Na : readString(env, "EMBEDDING_BASE_URL")) != null ? _Oa : readString(env, "LLM_BASE_URL")) != null ? _Qa : (_Pa = base == null ? void 0 : base.embedding) == null ? void 0 : _Pa.baseUrl) != null ? _Ra : rt == null ? void 0 : rt.embeddingBaseUrl) != null ? _Sa : rt == null ? void 0 : rt.llmBaseUrl) != null ? _Ta : defaultGatewayUrl;
3256
- const embeddingModel = (_Xa = (_Wa = (_Va = readString(env, "EMBEDDING_MODEL")) != null ? _Va : (_Ua = base == null ? void 0 : base.embedding) == null ? void 0 : _Ua.model) != null ? _Wa : rt == null ? void 0 : rt.embeddingModel) != null ? _Xa : tierBasedEmbeddingModel;
3257
- const embeddingApiKey = (_$a = (__a = (_Ya = readString(env, "LITELLM_MASTER_KEY")) != null ? _Ya : rt == null ? void 0 : rt.litellmApiKey) != null ? __a : (_Za = base == null ? void 0 : base.embedding) == null ? void 0 : _Za.apiKey) != null ? _$a : licenseKey;
3258
- const embeddingProfile = (_db = (_cb = readString(env, "EMBEDDING_UNIVERSAL_PROFILE")) != null ? _cb : (_bb = (_ab = base == null ? void 0 : base.embedding) == null ? void 0 : _ab.options) == null ? void 0 : _bb.profile) != null ? _db : "litellm";
3260
+ 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;
3261
+ 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;
3262
+ 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;
3263
+ 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;
3264
+ 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";
3265
+ console.log("[serverConfig] \u{1F527} Embedding Configuration:", {
3266
+ baseUrl: embeddingBaseUrl,
3267
+ model: embeddingModel,
3268
+ provider: embeddingProvider,
3269
+ hasApiKey: !!embeddingApiKey,
3270
+ source: (rt == null ? void 0 : rt.embeddingModel) ? "runtime-injected" : "env/fallback"
3271
+ });
3259
3272
  return __spreadProps(__spreadValues({
3260
3273
  projectId,
3261
3274
  licenseKey,
3262
3275
  vectorDb: {
3263
3276
  provider: vectorProvider,
3264
- indexName: (_fb = (_eb = readString(env, "VECTOR_DB_INDEX")) != null ? _eb : vectorDbOptions.indexName) != null ? _fb : "rag-index",
3277
+ indexName: (_gb = (_fb = readString(env, "VECTOR_DB_INDEX")) != null ? _fb : vectorDbOptions.indexName) != null ? _gb : "rag-index",
3265
3278
  options: vectorDbOptions
3266
3279
  },
3267
3280
  llm: {
@@ -3291,30 +3304,30 @@ function getEnvConfig(env = process.env, base) {
3291
3304
  }
3292
3305
  },
3293
3306
  ui: {
3294
- title: (_hb = (_gb = readString(env, "NEXT_PUBLIC_UI_TITLE")) != null ? _gb : readString(env, "UI_TITLE")) != null ? _hb : "AI Assistant",
3295
- subtitle: (_jb = (_ib = readString(env, "NEXT_PUBLIC_UI_SUBTITLE")) != null ? _ib : readString(env, "UI_SUBTITLE")) != null ? _jb : "Powered by RAG",
3296
- primaryColor: (_lb = (_kb = readString(env, "NEXT_PUBLIC_PRIMARY_COLOR")) != null ? _kb : readString(env, "UI_PRIMARY_COLOR")) != null ? _lb : "#10b981",
3297
- accentColor: (_nb = (_mb = readString(env, "NEXT_PUBLIC_ACCENT_COLOR")) != null ? _mb : readString(env, "UI_ACCENT_COLOR")) != null ? _nb : "#3b82f6",
3298
- logoUrl: (_ob = readString(env, "NEXT_PUBLIC_LOGO_URL")) != null ? _ob : readString(env, "UI_LOGO_URL"),
3299
- placeholder: (_qb = (_pb = readString(env, "NEXT_PUBLIC_PLACEHOLDER")) != null ? _pb : readString(env, "UI_PLACEHOLDER")) != null ? _qb : "Ask me anything\u2026",
3300
- showSources: ((_sb = (_rb = readString(env, "NEXT_PUBLIC_SHOW_SOURCES")) != null ? _rb : readString(env, "UI_SHOW_SOURCES")) != null ? _sb : "true") !== "false",
3301
- welcomeMessage: (_ub = (_tb = readString(env, "NEXT_PUBLIC_WELCOME_MESSAGE")) != null ? _tb : readString(env, "UI_WELCOME_MESSAGE")) != null ? _ub : "Hello! I'm your AI assistant. Ask me anything about your documents.",
3302
- visualStyle: (_wb = (_vb = readString(env, "NEXT_PUBLIC_UI_VISUAL_STYLE")) != null ? _vb : readString(env, "UI_VISUAL_STYLE")) != null ? _wb : "glass",
3303
- borderRadius: (_yb = (_xb = readString(env, "NEXT_PUBLIC_UI_BORDER_RADIUS")) != null ? _xb : readString(env, "UI_BORDER_RADIUS")) != null ? _yb : "xl",
3304
- allowUpload: ((_Ab = (_zb = readString(env, "NEXT_PUBLIC_ALLOW_UPLOAD")) != null ? _zb : readString(env, "UI_ALLOW_UPLOAD")) != null ? _Ab : "false") === "true"
3307
+ title: (_ib = (_hb = readString(env, "NEXT_PUBLIC_UI_TITLE")) != null ? _hb : readString(env, "UI_TITLE")) != null ? _ib : "AI Assistant",
3308
+ subtitle: (_kb = (_jb = readString(env, "NEXT_PUBLIC_UI_SUBTITLE")) != null ? _jb : readString(env, "UI_SUBTITLE")) != null ? _kb : "Powered by RAG",
3309
+ primaryColor: (_mb = (_lb = readString(env, "NEXT_PUBLIC_PRIMARY_COLOR")) != null ? _lb : readString(env, "UI_PRIMARY_COLOR")) != null ? _mb : "#10b981",
3310
+ accentColor: (_ob = (_nb = readString(env, "NEXT_PUBLIC_ACCENT_COLOR")) != null ? _nb : readString(env, "UI_ACCENT_COLOR")) != null ? _ob : "#3b82f6",
3311
+ logoUrl: (_pb = readString(env, "NEXT_PUBLIC_LOGO_URL")) != null ? _pb : readString(env, "UI_LOGO_URL"),
3312
+ placeholder: (_rb = (_qb = readString(env, "NEXT_PUBLIC_PLACEHOLDER")) != null ? _qb : readString(env, "UI_PLACEHOLDER")) != null ? _rb : "Ask me anything\u2026",
3313
+ showSources: ((_tb = (_sb = readString(env, "NEXT_PUBLIC_SHOW_SOURCES")) != null ? _sb : readString(env, "UI_SHOW_SOURCES")) != null ? _tb : "true") !== "false",
3314
+ 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.",
3315
+ visualStyle: (_xb = (_wb = readString(env, "NEXT_PUBLIC_UI_VISUAL_STYLE")) != null ? _wb : readString(env, "UI_VISUAL_STYLE")) != null ? _xb : "glass",
3316
+ borderRadius: (_zb = (_yb = readString(env, "NEXT_PUBLIC_UI_BORDER_RADIUS")) != null ? _yb : readString(env, "UI_BORDER_RADIUS")) != null ? _zb : "xl",
3317
+ allowUpload: ((_Bb = (_Ab = readString(env, "NEXT_PUBLIC_ALLOW_UPLOAD")) != null ? _Ab : readString(env, "UI_ALLOW_UPLOAD")) != null ? _Bb : "false") === "true"
3305
3318
  },
3306
3319
  rag: {
3307
3320
  topK: readNumber(env, "RAG_TOP_K", 5),
3308
3321
  scoreThreshold: readNumber(env, "RAG_SCORE_THRESHOLD", 0),
3309
3322
  chunkSize: readNumber(env, "RAG_CHUNK_SIZE", 1e3),
3310
3323
  chunkOverlap: readNumber(env, "RAG_CHUNK_OVERLAP", 200),
3311
- filterableFields: (_Bb = readString(env, "RAG_FILTERABLE_FIELDS")) == null ? void 0 : _Bb.split(",").map((f) => f.trim()),
3324
+ filterableFields: (_Cb = readString(env, "RAG_FILTERABLE_FIELDS")) == null ? void 0 : _Cb.split(",").map((f) => f.trim()),
3312
3325
  // Query pipeline toggles — read from .env.local
3313
3326
  useQueryTransformation: readString(env, "RAG_USE_QUERY_TRANSFORMATION") === "true",
3314
3327
  useReranking: readString(env, "RAG_USE_RERANKING") === "true",
3315
3328
  useGraphRetrieval: readString(env, "RAG_USE_GRAPH_RETRIEVAL") === "true",
3316
- architecture: (_Cb = readString(env, "RAG_ARCHITECTURE")) != null ? _Cb : "simple",
3317
- chunkingStrategy: (_Db = readString(env, "RAG_CHUNKING_STRATEGY")) != null ? _Db : "recursive",
3329
+ architecture: (_Db = readString(env, "RAG_ARCHITECTURE")) != null ? _Db : "simple",
3330
+ chunkingStrategy: (_Eb = readString(env, "RAG_CHUNKING_STRATEGY")) != null ? _Eb : "recursive",
3318
3331
  uiMapping: (() => {
3319
3332
  const raw = readString(env, "RAG_UI_MAPPING");
3320
3333
  if (!raw) return void 0;
@@ -3327,7 +3340,7 @@ function getEnvConfig(env = process.env, base) {
3327
3340
  },
3328
3341
  telemetry: {
3329
3342
  enabled: telemetryEnabled,
3330
- url: (_Hb = (_Gb = (_Eb = readString(env, "TELEMETRY_URL")) != null ? _Eb : readString(env, "NEXT_PUBLIC_TELEMETRY_URL")) != null ? _Gb : (_Fb = base == null ? void 0 : base.telemetry) == null ? void 0 : _Fb.url) != null ? _Hb : "https://www.retrivora.com/api/telemetry"
3343
+ 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"
3331
3344
  }
3332
3345
  }, readString(env, "GRAPH_DB_PROVIDER") ? {
3333
3346
  graphDb: {
@@ -4677,6 +4690,12 @@ var UniversalLLMAdapter = class {
4677
4690
  this.resolvedHeaders = __spreadValues(__spreadValues({
4678
4691
  "Content-Type": "application/json"
4679
4692
  }, config.apiKey ? { Authorization: `Bearer ${config.apiKey}` } : {}), this.opts.headers || {});
4693
+ console.log("[UniversalLLMAdapter] Initialized with:", {
4694
+ model: this.model,
4695
+ baseUrl: this.baseUrl,
4696
+ hasApiKey: !!this.apiKey,
4697
+ apiKeyPrefix: this.apiKey ? `${this.apiKey.slice(0, 12)}...` : void 0
4698
+ });
4680
4699
  this.http = import_axios2.default.create({
4681
4700
  baseURL: this.baseUrl,
4682
4701
  headers: this.resolvedHeaders,
@@ -4889,14 +4908,21 @@ ${context != null ? context : "None"}` },
4889
4908
  });
4890
4909
  }
4891
4910
  async embed(text) {
4892
- var _a3, _b, _c, _d, _e, _f, _g2;
4911
+ var _a3, _b, _c, _d, _e, _f, _g2, _h;
4893
4912
  const path2 = (_a3 = this.opts.embedPath) != null ? _a3 : "/embeddings";
4894
4913
  const payload = this.opts.embedPayloadTemplate ? buildPayload(this.opts.embedPayloadTemplate, { input: text, model: this.model }) : { input: text, model: this.model };
4895
4914
  try {
4915
+ console.log(`[UniversalLLMAdapter] Posting to embedding endpoint: ${this.baseUrl}${path2}`, {
4916
+ model: this.model,
4917
+ inputLength: typeof text === "string" ? text.length : "unknown"
4918
+ });
4896
4919
  const { data } = await this.http.post(path2, payload);
4897
4920
  const extractPath = (_b = this.opts.embedExtractPath) != null ? _b : "data[0].embedding";
4898
4921
  const vector = resolvePath(data, extractPath);
4899
- if (Array.isArray(vector)) return vector;
4922
+ if (Array.isArray(vector)) {
4923
+ console.log(`[UniversalLLMAdapter] Embedding HTTP request successful. Vector size: ${vector.length}`);
4924
+ return vector;
4925
+ }
4900
4926
  console.warn(
4901
4927
  `[UniversalLLMAdapter] Embedding API returned unexpected format for path '${extractPath}'. Response:`,
4902
4928
  data
@@ -4904,14 +4930,14 @@ ${context != null ? context : "None"}` },
4904
4930
  } catch (err) {
4905
4931
  console.warn(
4906
4932
  `[UniversalLLMAdapter] HTTP embedding request failed: ${(err == null ? void 0 : err.message) || err}`,
4907
- { path: path2, model: this.model }
4933
+ { path: path2, model: this.model, response: (_c = err == null ? void 0 : err.response) == null ? void 0 : _c.data }
4908
4934
  );
4909
4935
  const _g3 = globalThis;
4910
4936
  const dispatchEmbed = _g3.__retrivoraDispatchEmbedding;
4911
4937
  if (typeof dispatchEmbed === "function") {
4912
4938
  try {
4913
4939
  const res = await dispatchEmbed({ input: text, model: this.model }, this.apiKey);
4914
- if ((_d = (_c = res == null ? void 0 : res.data) == null ? void 0 : _c[0]) == null ? void 0 : _d.embedding) {
4940
+ if ((_e = (_d = res == null ? void 0 : res.data) == null ? void 0 : _d[0]) == null ? void 0 : _e.embedding) {
4915
4941
  return res.data[0].embedding;
4916
4942
  }
4917
4943
  } catch (dispatchErr) {
@@ -4920,10 +4946,12 @@ ${context != null ? context : "None"}` },
4920
4946
  }
4921
4947
  }
4922
4948
  try {
4949
+ console.log(`[UniversalLLMAdapter] Retrying embedding request to: ${this.baseUrl}${path2}`);
4923
4950
  const { data } = await this.http.post(path2, payload);
4924
- const extractPath = (_e = this.opts.embedExtractPath) != null ? _e : "data[0].embedding";
4951
+ const extractPath = (_f = this.opts.embedExtractPath) != null ? _f : "data[0].embedding";
4925
4952
  const vector = resolvePath(data, extractPath);
4926
4953
  if (Array.isArray(vector)) {
4954
+ console.log(`[UniversalLLMAdapter] Retry embedding HTTP request successful. Vector size: ${vector.length}`);
4927
4955
  return vector;
4928
4956
  }
4929
4957
  console.error(
@@ -4936,7 +4964,7 @@ ${context != null ? context : "None"}` },
4936
4964
  } catch (err) {
4937
4965
  console.error(
4938
4966
  `[UniversalLLMAdapter] Both embedding attempts failed. Path: ${path2}, Model: ${this.model}`,
4939
- { error: err == null ? void 0 : err.message, statusCode: (_f = err == null ? void 0 : err.response) == null ? void 0 : _f.status, response: (_g2 = err == null ? void 0 : err.response) == null ? void 0 : _g2.data }
4967
+ { error: err == null ? void 0 : err.message, statusCode: (_g2 = err == null ? void 0 : err.response) == null ? void 0 : _g2.status, response: (_h = err == null ? void 0 : err.response) == null ? void 0 : _h.data }
4940
4968
  );
4941
4969
  throw new Error(
4942
4970
  `[UniversalLLMAdapter] Failed to generate embedding after 2 attempts: ${(err == null ? void 0 : err.message) || err}`
@@ -11984,6 +12012,7 @@ function createLicenseHandler(configOrPlugin, options) {
11984
12012
  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 || "";
11985
12013
  const licenseKey = (rawKey || "").trim().replace(/^["']|["']$/g, "").trim();
11986
12014
  const projectId = (body == null ? void 0 : body.projectId) || config.projectId || "";
12015
+ console.log(`[DEBUG] createLicenseHandler: projectId="${projectId}", body.projectId="${body == null ? void 0 : body.projectId}", config.projectId="${config.projectId}"`);
11987
12016
  const payload = await LicenseVerifier.verifyAsync(licenseKey, projectId);
11988
12017
  return import_server.NextResponse.json({
11989
12018
  valid: true,
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.8",
318
+ version: "2.3.9",
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,6 +510,7 @@ 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}`);
513
514
  const res = await fetch(url, {
514
515
  method: "GET",
515
516
  headers: __spreadValues({
@@ -517,6 +518,10 @@ var init_ConfigFetcher = __esm({
517
518
  "x-sdk-version": SDK_VERSION
518
519
  }, licenseKey ? { "x-license-key": licenseKey } : {})
519
520
  });
521
+ console.log(`[ConfigFetcher] Response status: ${res.status}`);
522
+ if (!res.ok) {
523
+ console.warn(`[ConfigFetcher] Error text: ${await res.text()}`);
524
+ }
520
525
  if (res.ok) {
521
526
  const data = await res.json();
522
527
  if ((data == null ? void 0 : data.success) && (data == null ? void 0 : data.vectorDb)) {
@@ -3028,7 +3033,7 @@ function getRagConfig(baseConfig, env = process.env) {
3028
3033
  return getEnvConfig(env, baseConfig);
3029
3034
  }
3030
3035
  function getEnvConfig(env = process.env, base) {
3031
- 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;
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;
3032
3037
  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;
3033
3038
  const jwtProjectId = (() => {
3034
3039
  if (!licenseKey) return void 0;
@@ -3121,14 +3126,15 @@ function getEnvConfig(env = process.env, base) {
3121
3126
  })();
3122
3127
  const tierBasedLLMModel = isFreeTier2 ? "llama-3.1-8b-instant" : "llama-3.3-70b-versatile";
3123
3128
  const tierBasedEmbeddingModel = isFreeTier2 ? "text-embedding-004" : "text-embedding-004";
3124
- const defaultGatewayUrl = "https://llm.retrivora.com/api/v1";
3129
+ const controlPlaneUrl = (_qa = readString(env, "RETRIVORA_CONTROL_PLANE_URL")) != null ? _qa : readString(env, "NEXT_PUBLIC_RETRIVORA_CONTROL_PLANE_URL");
3130
+ const defaultGatewayUrl = controlPlaneUrl ? `${controlPlaneUrl.replace(/\/$/, "")}/api/v1` : "https://llm.retrivora.com/api/v1";
3125
3131
  const rt = _runtimeConfig;
3126
3132
  const defaultLlmProvider = "universal_rest";
3127
- const llmProvider = (_sa = (_ra = readEnum(env, "LLM_PROVIDER", defaultLlmProvider, LLM_PROVIDERS)) != null ? _ra : (_qa = base == null ? void 0 : base.llm) == null ? void 0 : _qa.provider) != null ? _sa : defaultLlmProvider;
3128
- const llmBaseUrl = (_xa = (_wa = (_va = (_ta = readString(env, "LITELLM_BASE_URL")) != null ? _ta : readString(env, "LLM_BASE_URL")) != null ? _va : (_ua = base == null ? void 0 : base.llm) == null ? void 0 : _ua.baseUrl) != null ? _wa : rt == null ? void 0 : rt.llmBaseUrl) != null ? _xa : defaultGatewayUrl;
3129
- const llmModel = (_Ba = (_Aa = (_za = readString(env, "LLM_MODEL")) != null ? _za : (_ya = base == null ? void 0 : base.llm) == null ? void 0 : _ya.model) != null ? _Aa : rt == null ? void 0 : rt.llmModel) != null ? _Ba : tierBasedLLMModel;
3130
- const llmApiKey = (_Fa = (_Ea = (_Ca = readString(env, "LITELLM_MASTER_KEY")) != null ? _Ca : rt == null ? void 0 : rt.litellmApiKey) != null ? _Ea : (_Da = base == null ? void 0 : base.llm) == null ? void 0 : _Da.apiKey) != null ? _Fa : licenseKey;
3131
- const llmProfile = (_Ja = (_Ia = readString(env, "LLM_UNIVERSAL_PROFILE")) != null ? _Ia : (_Ha = (_Ga = base == null ? void 0 : base.llm) == null ? void 0 : _Ga.options) == null ? void 0 : _Ha.profile) != null ? _Ja : "litellm";
3133
+ const llmProvider = (_ta = (_sa = readEnum(env, "LLM_PROVIDER", defaultLlmProvider, LLM_PROVIDERS)) != null ? _sa : (_ra = base == null ? void 0 : base.llm) == null ? void 0 : _ra.provider) != null ? _ta : defaultLlmProvider;
3134
+ const llmBaseUrl = (_ya = (_xa = (_wa = (_ua = readString(env, "LITELLM_BASE_URL")) != null ? _ua : readString(env, "LLM_BASE_URL")) != null ? _wa : (_va = base == null ? void 0 : base.llm) == null ? void 0 : _va.baseUrl) != null ? _xa : rt == null ? void 0 : rt.llmBaseUrl) != null ? _ya : defaultGatewayUrl;
3135
+ 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
+ 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
+ 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";
3132
3138
  console.log("[serverConfig] \u{1F527} LLM Configuration:", {
3133
3139
  baseUrl: llmBaseUrl,
3134
3140
  model: llmModel,
@@ -3137,17 +3143,24 @@ function getEnvConfig(env = process.env, base) {
3137
3143
  source: (rt == null ? void 0 : rt.llmModel) ? "runtime-injected" : "env/fallback"
3138
3144
  });
3139
3145
  const defaultEmbeddingProvider = "universal_rest";
3140
- const embeddingProvider = (_Ma = (_La = readEnum(env, "EMBEDDING_PROVIDER", defaultEmbeddingProvider, EMBEDDING_PROVIDERS)) != null ? _La : (_Ka = base == null ? void 0 : base.embedding) == null ? void 0 : _Ka.provider) != null ? _Ma : defaultEmbeddingProvider;
3141
- const embeddingBaseUrl = (_Ta = (_Sa = (_Ra = (_Qa = (_Oa = (_Na = readString(env, "LITELLM_BASE_URL")) != null ? _Na : readString(env, "EMBEDDING_BASE_URL")) != null ? _Oa : readString(env, "LLM_BASE_URL")) != null ? _Qa : (_Pa = base == null ? void 0 : base.embedding) == null ? void 0 : _Pa.baseUrl) != null ? _Ra : rt == null ? void 0 : rt.embeddingBaseUrl) != null ? _Sa : rt == null ? void 0 : rt.llmBaseUrl) != null ? _Ta : defaultGatewayUrl;
3142
- const embeddingModel = (_Xa = (_Wa = (_Va = readString(env, "EMBEDDING_MODEL")) != null ? _Va : (_Ua = base == null ? void 0 : base.embedding) == null ? void 0 : _Ua.model) != null ? _Wa : rt == null ? void 0 : rt.embeddingModel) != null ? _Xa : tierBasedEmbeddingModel;
3143
- const embeddingApiKey = (_$a = (__a = (_Ya = readString(env, "LITELLM_MASTER_KEY")) != null ? _Ya : rt == null ? void 0 : rt.litellmApiKey) != null ? __a : (_Za = base == null ? void 0 : base.embedding) == null ? void 0 : _Za.apiKey) != null ? _$a : licenseKey;
3144
- const embeddingProfile = (_db = (_cb = readString(env, "EMBEDDING_UNIVERSAL_PROFILE")) != null ? _cb : (_bb = (_ab = base == null ? void 0 : base.embedding) == null ? void 0 : _ab.options) == null ? void 0 : _bb.profile) != null ? _db : "litellm";
3146
+ 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
+ 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
+ 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
+ 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
+ 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
+ });
3145
3158
  return __spreadProps(__spreadValues({
3146
3159
  projectId,
3147
3160
  licenseKey,
3148
3161
  vectorDb: {
3149
3162
  provider: vectorProvider,
3150
- indexName: (_fb = (_eb = readString(env, "VECTOR_DB_INDEX")) != null ? _eb : vectorDbOptions.indexName) != null ? _fb : "rag-index",
3163
+ indexName: (_gb = (_fb = readString(env, "VECTOR_DB_INDEX")) != null ? _fb : vectorDbOptions.indexName) != null ? _gb : "rag-index",
3151
3164
  options: vectorDbOptions
3152
3165
  },
3153
3166
  llm: {
@@ -3177,30 +3190,30 @@ function getEnvConfig(env = process.env, base) {
3177
3190
  }
3178
3191
  },
3179
3192
  ui: {
3180
- title: (_hb = (_gb = readString(env, "NEXT_PUBLIC_UI_TITLE")) != null ? _gb : readString(env, "UI_TITLE")) != null ? _hb : "AI Assistant",
3181
- subtitle: (_jb = (_ib = readString(env, "NEXT_PUBLIC_UI_SUBTITLE")) != null ? _ib : readString(env, "UI_SUBTITLE")) != null ? _jb : "Powered by RAG",
3182
- primaryColor: (_lb = (_kb = readString(env, "NEXT_PUBLIC_PRIMARY_COLOR")) != null ? _kb : readString(env, "UI_PRIMARY_COLOR")) != null ? _lb : "#10b981",
3183
- accentColor: (_nb = (_mb = readString(env, "NEXT_PUBLIC_ACCENT_COLOR")) != null ? _mb : readString(env, "UI_ACCENT_COLOR")) != null ? _nb : "#3b82f6",
3184
- logoUrl: (_ob = readString(env, "NEXT_PUBLIC_LOGO_URL")) != null ? _ob : readString(env, "UI_LOGO_URL"),
3185
- placeholder: (_qb = (_pb = readString(env, "NEXT_PUBLIC_PLACEHOLDER")) != null ? _pb : readString(env, "UI_PLACEHOLDER")) != null ? _qb : "Ask me anything\u2026",
3186
- showSources: ((_sb = (_rb = readString(env, "NEXT_PUBLIC_SHOW_SOURCES")) != null ? _rb : readString(env, "UI_SHOW_SOURCES")) != null ? _sb : "true") !== "false",
3187
- welcomeMessage: (_ub = (_tb = readString(env, "NEXT_PUBLIC_WELCOME_MESSAGE")) != null ? _tb : readString(env, "UI_WELCOME_MESSAGE")) != null ? _ub : "Hello! I'm your AI assistant. Ask me anything about your documents.",
3188
- visualStyle: (_wb = (_vb = readString(env, "NEXT_PUBLIC_UI_VISUAL_STYLE")) != null ? _vb : readString(env, "UI_VISUAL_STYLE")) != null ? _wb : "glass",
3189
- borderRadius: (_yb = (_xb = readString(env, "NEXT_PUBLIC_UI_BORDER_RADIUS")) != null ? _xb : readString(env, "UI_BORDER_RADIUS")) != null ? _yb : "xl",
3190
- allowUpload: ((_Ab = (_zb = readString(env, "NEXT_PUBLIC_ALLOW_UPLOAD")) != null ? _zb : readString(env, "UI_ALLOW_UPLOAD")) != null ? _Ab : "false") === "true"
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"
3191
3204
  },
3192
3205
  rag: {
3193
3206
  topK: readNumber(env, "RAG_TOP_K", 5),
3194
3207
  scoreThreshold: readNumber(env, "RAG_SCORE_THRESHOLD", 0),
3195
3208
  chunkSize: readNumber(env, "RAG_CHUNK_SIZE", 1e3),
3196
3209
  chunkOverlap: readNumber(env, "RAG_CHUNK_OVERLAP", 200),
3197
- filterableFields: (_Bb = readString(env, "RAG_FILTERABLE_FIELDS")) == null ? void 0 : _Bb.split(",").map((f) => f.trim()),
3210
+ filterableFields: (_Cb = readString(env, "RAG_FILTERABLE_FIELDS")) == null ? void 0 : _Cb.split(",").map((f) => f.trim()),
3198
3211
  // Query pipeline toggles — read from .env.local
3199
3212
  useQueryTransformation: readString(env, "RAG_USE_QUERY_TRANSFORMATION") === "true",
3200
3213
  useReranking: readString(env, "RAG_USE_RERANKING") === "true",
3201
3214
  useGraphRetrieval: readString(env, "RAG_USE_GRAPH_RETRIEVAL") === "true",
3202
- architecture: (_Cb = readString(env, "RAG_ARCHITECTURE")) != null ? _Cb : "simple",
3203
- chunkingStrategy: (_Db = readString(env, "RAG_CHUNKING_STRATEGY")) != null ? _Db : "recursive",
3215
+ architecture: (_Db = readString(env, "RAG_ARCHITECTURE")) != null ? _Db : "simple",
3216
+ chunkingStrategy: (_Eb = readString(env, "RAG_CHUNKING_STRATEGY")) != null ? _Eb : "recursive",
3204
3217
  uiMapping: (() => {
3205
3218
  const raw = readString(env, "RAG_UI_MAPPING");
3206
3219
  if (!raw) return void 0;
@@ -3213,7 +3226,7 @@ function getEnvConfig(env = process.env, base) {
3213
3226
  },
3214
3227
  telemetry: {
3215
3228
  enabled: telemetryEnabled,
3216
- url: (_Hb = (_Gb = (_Eb = readString(env, "TELEMETRY_URL")) != null ? _Eb : readString(env, "NEXT_PUBLIC_TELEMETRY_URL")) != null ? _Gb : (_Fb = base == null ? void 0 : base.telemetry) == null ? void 0 : _Fb.url) != null ? _Hb : "https://www.retrivora.com/api/telemetry"
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"
3217
3230
  }
3218
3231
  }, readString(env, "GRAPH_DB_PROVIDER") ? {
3219
3232
  graphDb: {
@@ -4563,6 +4576,12 @@ var UniversalLLMAdapter = class {
4563
4576
  this.resolvedHeaders = __spreadValues(__spreadValues({
4564
4577
  "Content-Type": "application/json"
4565
4578
  }, 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
+ });
4566
4585
  this.http = axios2.create({
4567
4586
  baseURL: this.baseUrl,
4568
4587
  headers: this.resolvedHeaders,
@@ -4775,14 +4794,21 @@ ${context != null ? context : "None"}` },
4775
4794
  });
4776
4795
  }
4777
4796
  async embed(text) {
4778
- var _a3, _b, _c, _d, _e, _f, _g2;
4797
+ var _a3, _b, _c, _d, _e, _f, _g2, _h;
4779
4798
  const path2 = (_a3 = this.opts.embedPath) != null ? _a3 : "/embeddings";
4780
4799
  const payload = this.opts.embedPayloadTemplate ? buildPayload(this.opts.embedPayloadTemplate, { input: text, model: this.model }) : { input: text, model: this.model };
4781
4800
  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
+ });
4782
4805
  const { data } = await this.http.post(path2, payload);
4783
4806
  const extractPath = (_b = this.opts.embedExtractPath) != null ? _b : "data[0].embedding";
4784
4807
  const vector = resolvePath(data, extractPath);
4785
- if (Array.isArray(vector)) return vector;
4808
+ if (Array.isArray(vector)) {
4809
+ console.log(`[UniversalLLMAdapter] Embedding HTTP request successful. Vector size: ${vector.length}`);
4810
+ return vector;
4811
+ }
4786
4812
  console.warn(
4787
4813
  `[UniversalLLMAdapter] Embedding API returned unexpected format for path '${extractPath}'. Response:`,
4788
4814
  data
@@ -4790,14 +4816,14 @@ ${context != null ? context : "None"}` },
4790
4816
  } catch (err) {
4791
4817
  console.warn(
4792
4818
  `[UniversalLLMAdapter] HTTP embedding request failed: ${(err == null ? void 0 : err.message) || err}`,
4793
- { path: path2, model: this.model }
4819
+ { path: path2, model: this.model, response: (_c = err == null ? void 0 : err.response) == null ? void 0 : _c.data }
4794
4820
  );
4795
4821
  const _g3 = globalThis;
4796
4822
  const dispatchEmbed = _g3.__retrivoraDispatchEmbedding;
4797
4823
  if (typeof dispatchEmbed === "function") {
4798
4824
  try {
4799
4825
  const res = await dispatchEmbed({ input: text, model: this.model }, this.apiKey);
4800
- if ((_d = (_c = res == null ? void 0 : res.data) == null ? void 0 : _c[0]) == null ? void 0 : _d.embedding) {
4826
+ if ((_e = (_d = res == null ? void 0 : res.data) == null ? void 0 : _d[0]) == null ? void 0 : _e.embedding) {
4801
4827
  return res.data[0].embedding;
4802
4828
  }
4803
4829
  } catch (dispatchErr) {
@@ -4806,10 +4832,12 @@ ${context != null ? context : "None"}` },
4806
4832
  }
4807
4833
  }
4808
4834
  try {
4835
+ console.log(`[UniversalLLMAdapter] Retrying embedding request to: ${this.baseUrl}${path2}`);
4809
4836
  const { data } = await this.http.post(path2, payload);
4810
- const extractPath = (_e = this.opts.embedExtractPath) != null ? _e : "data[0].embedding";
4837
+ const extractPath = (_f = this.opts.embedExtractPath) != null ? _f : "data[0].embedding";
4811
4838
  const vector = resolvePath(data, extractPath);
4812
4839
  if (Array.isArray(vector)) {
4840
+ console.log(`[UniversalLLMAdapter] Retry embedding HTTP request successful. Vector size: ${vector.length}`);
4813
4841
  return vector;
4814
4842
  }
4815
4843
  console.error(
@@ -4822,7 +4850,7 @@ ${context != null ? context : "None"}` },
4822
4850
  } catch (err) {
4823
4851
  console.error(
4824
4852
  `[UniversalLLMAdapter] Both embedding attempts failed. Path: ${path2}, Model: ${this.model}`,
4825
- { error: err == null ? void 0 : err.message, statusCode: (_f = err == null ? void 0 : err.response) == null ? void 0 : _f.status, response: (_g2 = err == null ? void 0 : err.response) == null ? void 0 : _g2.data }
4853
+ { error: err == null ? void 0 : err.message, statusCode: (_g2 = err == null ? void 0 : err.response) == null ? void 0 : _g2.status, response: (_h = err == null ? void 0 : err.response) == null ? void 0 : _h.data }
4826
4854
  );
4827
4855
  throw new Error(
4828
4856
  `[UniversalLLMAdapter] Failed to generate embedding after 2 attempts: ${(err == null ? void 0 : err.message) || err}`
@@ -11870,6 +11898,7 @@ function createLicenseHandler(configOrPlugin, options) {
11870
11898
  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 || "";
11871
11899
  const licenseKey = (rawKey || "").trim().replace(/^["']|["']$/g, "").trim();
11872
11900
  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}"`);
11873
11902
  const payload = await LicenseVerifier.verifyAsync(licenseKey, projectId);
11874
11903
  return NextResponse.json({
11875
11904
  valid: true,
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@retrivora-ai/rag-engine",
3
- "version": "2.3.8",
3
+ "version": "2.3.9",
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",
@@ -11,6 +11,19 @@ interface FileState {
11
11
  error?: string;
12
12
  }
13
13
 
14
+ function decodeLicenseTier(licenseKey?: string): string {
15
+ if (!licenseKey) return 'free';
16
+ try {
17
+ const parts = licenseKey.split('.');
18
+ if (parts.length >= 2) {
19
+ const base64 = parts[1].replace(/-/g, '+').replace(/_/g, '/');
20
+ const payload = JSON.parse(atob(base64));
21
+ return payload?.tier || 'free';
22
+ }
23
+ } catch { /* ignore */ }
24
+ return 'free';
25
+ }
26
+
14
27
  export function DocumentUpload({ namespace, uploadUrl, retrivoraApiBase, onUploadComplete, className = '' }: DocumentUploadProps) {
15
28
  const { ui, embedding, projectId, licenseKey, headers: configHeaders, retrivoraApiBase: configuredApiBase } = useConfig();
16
29
  const [fileStates, setFileStates] = useState<FileState[]>([]);
@@ -25,7 +38,17 @@ export function DocumentUpload({ namespace, uploadUrl, retrivoraApiBase, onUploa
25
38
  namespaceUsed: string;
26
39
  } | null>(null);
27
40
 
28
- const isFreeTier = !projectId || projectId.includes('free') || projectId.includes('demo');
41
+ const resolvedLicenseKey = licenseKey ||
42
+ configHeaders?.['x-license-key'] ||
43
+ configHeaders?.['X-License-Key'] ||
44
+ configHeaders?.['authorization']?.replace(/^Bearer\s+/i, '') ||
45
+ configHeaders?.['Authorization']?.replace(/^Bearer\s+/i, '');
46
+
47
+ const licenseTier = decodeLicenseTier(resolvedLicenseKey);
48
+ const isFreeTier = !projectId ||
49
+ projectId.includes('free') ||
50
+ projectId.includes('demo') ||
51
+ ['free_trial', 'free_tier', 'free', 'hobby'].includes(licenseTier.toLowerCase());
29
52
 
30
53
  const MULTI_DIMENSION_MODELS: Record<string, number[]> = {
31
54
  'text-embedding-3-small': [512, 1536],
@@ -195,22 +218,18 @@ export function DocumentUpload({ namespace, uploadUrl, retrivoraApiBase, onUploa
195
218
  <select
196
219
  value={dimension}
197
220
  onChange={(e) => setDimension(Number(e.target.value))}
198
- disabled={isUploading}
221
+ disabled={isUploading || availableDimensions.length <= 1}
199
222
  className="px-3 py-1.5 rounded-lg bg-slate-50 dark:bg-white/5 border border-slate-200 dark:border-white/10 text-slate-800 dark:text-white/90 outline-none focus:border-emerald-500 transition-colors text-sm font-medium cursor-pointer"
200
223
  >
201
- {COMMON_DIMENSIONS.map(dim => {
202
- const isDisabled = isFreeTier && dim !== 768;
203
- return (
204
- <option
205
- key={dim}
206
- value={dim}
207
- disabled={isDisabled}
208
- className="bg-white dark:bg-slate-900 text-slate-800 dark:text-white disabled:text-slate-400 dark:disabled:text-white/30"
209
- >
210
- {dim}
211
- </option>
212
- );
213
- })}
224
+ {availableDimensions.map(dim => (
225
+ <option
226
+ key={dim}
227
+ value={dim}
228
+ className="bg-white dark:bg-slate-900 text-slate-800 dark:text-white"
229
+ >
230
+ {dim}
231
+ </option>
232
+ ))}
214
233
  </select>
215
234
  </div>
216
235
  </div>
@@ -233,7 +233,10 @@ export function getEnvConfig(env: Record<string, string | undefined> = process.e
233
233
 
234
234
  // Default gateway: always use LiteLLM at llm.retrivora.com for end-users
235
235
  // End-users provide license key + project ID; the gateway validates and routes internally
236
- const defaultGatewayUrl = 'https://llm.retrivora.com/api/v1';
236
+ const controlPlaneUrl = readString(env, 'RETRIVORA_CONTROL_PLANE_URL') ?? readString(env, 'NEXT_PUBLIC_RETRIVORA_CONTROL_PLANE_URL');
237
+ const defaultGatewayUrl = controlPlaneUrl
238
+ ? `${controlPlaneUrl.replace(/\/$/, '')}/api/v1`
239
+ : 'https://llm.retrivora.com/api/v1';
237
240
 
238
241
  // ── Runtime-injected tier config (from /api/v1/config + /api/v1/credentials) ──
239
242
  // Priority: explicit env var > injected runtime config > static tier fallback
@@ -248,7 +251,7 @@ export function getEnvConfig(env: Record<string, string | undefined> = process.e
248
251
  // llmApiKey: LITELLM_MASTER_KEY env wins, then injected litellm key, then licenseKey
249
252
  const llmApiKey = readString(env, 'LITELLM_MASTER_KEY') ?? rt?.litellmApiKey ?? base?.llm?.apiKey ?? licenseKey;
250
253
  const llmProfile = readString(env, 'LLM_UNIVERSAL_PROFILE') ?? (base?.llm?.options?.profile as string) ?? 'litellm';
251
-
254
+
252
255
  console.log('[serverConfig] 🔧 LLM Configuration:', {
253
256
  baseUrl: llmBaseUrl,
254
257
  model: llmModel,
@@ -256,7 +259,7 @@ export function getEnvConfig(env: Record<string, string | undefined> = process.e
256
259
  hasApiKey: !!llmApiKey,
257
260
  source: rt?.llmModel ? 'runtime-injected' : 'env/fallback',
258
261
  });
259
-
262
+
260
263
  const defaultEmbeddingProvider = 'universal_rest';
261
264
  const embeddingProvider = (readEnum(env, 'EMBEDDING_PROVIDER', defaultEmbeddingProvider, EMBEDDING_PROVIDERS) ?? base?.embedding?.provider ?? defaultEmbeddingProvider) as EmbeddingProvider;
262
265
  const embeddingBaseUrl = readString(env, 'LITELLM_BASE_URL') ?? readString(env, 'EMBEDDING_BASE_URL') ?? readString(env, 'LLM_BASE_URL') ?? base?.embedding?.baseUrl ?? rt?.embeddingBaseUrl ?? rt?.llmBaseUrl ?? defaultGatewayUrl;
@@ -264,6 +267,14 @@ export function getEnvConfig(env: Record<string, string | undefined> = process.e
264
267
  // embeddingApiKey: same key as LLM (LiteLLM gateway handles both)
265
268
  const embeddingApiKey = readString(env, 'LITELLM_MASTER_KEY') ?? rt?.litellmApiKey ?? base?.embedding?.apiKey ?? licenseKey;
266
269
  const embeddingProfile = readString(env, 'EMBEDDING_UNIVERSAL_PROFILE') ?? (base?.embedding?.options?.profile as string) ?? 'litellm';
270
+
271
+ console.log('[serverConfig] 🔧 Embedding Configuration:', {
272
+ baseUrl: embeddingBaseUrl,
273
+ model: embeddingModel,
274
+ provider: embeddingProvider,
275
+ hasApiKey: !!embeddingApiKey,
276
+ source: rt?.embeddingModel ? 'runtime-injected' : 'env/fallback',
277
+ });
267
278
 
268
279
  return {
269
280
  projectId,