@retrivora-ai/rag-engine 2.2.1 → 2.2.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.
@@ -696,7 +696,7 @@ async function dispatchEmbedding(req, apiKeyOverride) {
696
696
  }
697
697
  }
698
698
  const geminiKey = process.env.GEMINI_API_KEY || effectiveKey;
699
- const isGeminiKeyValid = Boolean(geminiKey && (geminiKey.startsWith("AIza") || !geminiKey.startsWith("AQ.")));
699
+ const isGeminiKeyValid = Boolean(geminiKey && !geminiKey.startsWith("eyJ"));
700
700
  if (isGeminiKeyValid) {
701
701
  try {
702
702
  return await handleGeminiEmbedding(req, effectiveKey);
@@ -831,11 +831,14 @@ var init_ConfigFetcher = __esm({
831
831
  if (res.ok) {
832
832
  const data = await res.json();
833
833
  if ((data == null ? void 0 : data.success) && ((_a2 = data == null ? void 0 : data.vectorDb) == null ? void 0 : _a2.apiKey)) {
834
+ const fetchedProjectId = data.projectId || projectId;
834
835
  const config = {
836
+ projectId: fetchedProjectId,
835
837
  vectorDb: {
836
838
  apiKey: data.vectorDb.apiKey,
837
839
  indexName: data.vectorDb.indexName || "retrivora-free",
838
- provider: data.vectorDb.provider || "pinecone"
840
+ provider: data.vectorDb.provider || "pinecone",
841
+ projectId: fetchedProjectId
839
842
  },
840
843
  embedding: {
841
844
  provider: ((_b = data.embedding) == null ? void 0 : _b.provider) || "universal_rest",
@@ -953,8 +956,20 @@ var init_PineconeProvider = __esm({
953
956
  if (this.client) return;
954
957
  let key = this.apiKey || process.env.PINECONE_API_KEY || "";
955
958
  if (!key) {
956
- const projectId = process.env.RAG_PROJECT_ID || process.env.NEXT_PUBLIC_RAG_PROJECT_ID || "my-rag-app";
957
959
  const licenseKey = process.env.RETRIVORA_LICENSE_KEY || process.env.NEXT_PUBLIC_RETRIVORA_LICENSE_KEY;
960
+ const jwtProjectId = (() => {
961
+ if (!licenseKey) return void 0;
962
+ try {
963
+ const parts = licenseKey.split(".");
964
+ if (parts.length >= 2) {
965
+ const payload = JSON.parse(Buffer.from(parts[1], "base64url").toString("utf8"));
966
+ return payload == null ? void 0 : payload.projectId;
967
+ }
968
+ } catch (e) {
969
+ }
970
+ return void 0;
971
+ })();
972
+ const projectId = process.env.RAG_PROJECT_ID || process.env.NEXT_PUBLIC_RAG_PROJECT_ID || jwtProjectId || this.projectId || "default";
958
973
  const remoteConfig = await ConfigFetcher.fetchRemoteVectorConfig(projectId, licenseKey);
959
974
  if (remoteConfig == null ? void 0 : remoteConfig.apiKey) {
960
975
  key = remoteConfig.apiKey;
@@ -962,6 +977,9 @@ var init_PineconeProvider = __esm({
962
977
  if (remoteConfig.indexName) {
963
978
  this.indexName = remoteConfig.indexName;
964
979
  }
980
+ if (remoteConfig.projectId) {
981
+ this.projectId = remoteConfig.projectId;
982
+ }
965
983
  }
966
984
  }
967
985
  if (!key) {
@@ -2964,7 +2982,8 @@ var LicenseVerifier = class {
2964
2982
  };
2965
2983
  }
2966
2984
  try {
2967
- const parts = licenseKey.split(".");
2985
+ const rawToken = licenseKey.replace(/^rtv_/i, "").trim();
2986
+ const parts = rawToken.split(".");
2968
2987
  if (parts.length !== 3) {
2969
2988
  throw new Error("Malformed token structure (expected 3 parts).");
2970
2989
  }
@@ -2988,7 +3007,8 @@ var LicenseVerifier = class {
2988
3007
  if (!payload.projectId) {
2989
3008
  throw new Error('License payload is missing "projectId".');
2990
3009
  }
2991
- if (payload.projectId !== currentProjectId) {
3010
+ const isProjectMatch = payload.projectId === currentProjectId || payload.projectId === `retrivora-${currentProjectId}` || `retrivora-${payload.projectId}` === currentProjectId;
3011
+ if (!isProjectMatch) {
2992
3012
  throw new Error(
2993
3013
  `Project ID mismatch. License is bound to project namespace "${payload.projectId}" but configuration has "${currentProjectId}".`
2994
3014
  );
@@ -3196,46 +3216,58 @@ function readEnum(env, name, fallback, allowed) {
3196
3216
  throw new Error(`[getRagConfig] ${name} must be one of: ${allowed.join(", ")}`);
3197
3217
  }
3198
3218
  function getEnvConfig(env = process.env, base) {
3199
- var _a2, _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;
3200
- const projectId = (_c = (_b = (_a2 = readString(env, "RAG_PROJECT_ID")) != null ? _a2 : readString(env, "NEXT_PUBLIC_PROJECT_ID")) != null ? _b : base == null ? void 0 : base.projectId) != null ? _c : "__default__";
3201
- const licenseKey = (_g2 = (_f = (_e = (_d = readString(env, "RAG_LICENSE_KEY")) != null ? _d : readString(env, "RETRIVORA_LICENSE_KEY")) != null ? _e : readString(env, "NEXT_PUBLIC_RETRIVORA_LICENSE_KEY")) != null ? _f : readString(env, "LICENSE_KEY")) != null ? _g2 : base == null ? void 0 : base.licenseKey;
3202
- const telemetryEnabled = readString(env, "TELEMETRY_ENABLED") === "true" || readString(env, "NEXT_PUBLIC_TELEMETRY_ENABLED") === "true" || ((_h = base == null ? void 0 : base.telemetry) == null ? void 0 : _h.enabled) || Boolean(licenseKey);
3219
+ var _a2, _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;
3220
+ const licenseKey = (_d = (_c = (_b = (_a2 = readString(env, "RAG_LICENSE_KEY")) != null ? _a2 : 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;
3221
+ const jwtProjectId = (() => {
3222
+ if (!licenseKey) return void 0;
3223
+ try {
3224
+ const parts = licenseKey.split(".");
3225
+ if (parts.length >= 2) {
3226
+ const payload = JSON.parse(Buffer.from(parts[1], "base64url").toString("utf8"));
3227
+ return payload == null ? void 0 : payload.projectId;
3228
+ }
3229
+ } catch (e) {
3230
+ }
3231
+ return void 0;
3232
+ })();
3233
+ const projectId = (_i = (_h = (_g2 = (_f = (_e = readString(env, "RAG_PROJECT_ID")) != null ? _e : readString(env, "NEXT_PUBLIC_RAG_PROJECT_ID")) != null ? _f : readString(env, "NEXT_PUBLIC_PROJECT_ID")) != null ? _g2 : base == null ? void 0 : base.projectId) != null ? _h : jwtProjectId) != null ? _i : "default";
3234
+ const telemetryEnabled = readString(env, "TELEMETRY_ENABLED") === "true" || readString(env, "NEXT_PUBLIC_TELEMETRY_ENABLED") === "true" || ((_j = base == null ? void 0 : base.telemetry) == null ? void 0 : _j.enabled) || Boolean(licenseKey);
3203
3235
  const vectorProvider = readEnum(env, "VECTOR_DB_PROVIDER", "pinecone", VECTOR_DB_PROVIDERS);
3204
3236
  const embeddingDimensions = readNumber(env, "EMBEDDING_DIMENSIONS", 768);
3205
3237
  const vectorDbOptions = {};
3206
3238
  if (vectorProvider === "pinecone") {
3207
- vectorDbOptions.apiKey = (_m = (_l = (_k = readString(env, "PINECONE_API_KEY")) != null ? _k : (_j = (_i = base == null ? void 0 : base.vectorDb) == null ? void 0 : _i.options) == null ? void 0 : _j.apiKey) != null ? _l : process.env.PINECONE_API_KEY) != null ? _m : "";
3208
- vectorDbOptions.indexName = (_t = (_s = (_r = (_o = readString(env, "PINECONE_INDEX")) != null ? _o : (_n = base == null ? void 0 : base.vectorDb) == null ? void 0 : _n.indexName) != null ? _r : (_q = (_p = base == null ? void 0 : base.vectorDb) == null ? void 0 : _p.options) == null ? void 0 : _q.indexName) != null ? _s : process.env.PINECONE_INDEX) != null ? _t : "retrivora-free";
3239
+ vectorDbOptions.apiKey = (_o = (_n = (_m = readString(env, "PINECONE_API_KEY")) != null ? _m : (_l = (_k = base == null ? void 0 : base.vectorDb) == null ? void 0 : _k.options) == null ? void 0 : _l.apiKey) != null ? _n : process.env.PINECONE_API_KEY) != null ? _o : "";
3240
+ vectorDbOptions.indexName = (_v = (_u = (_t = (_q = readString(env, "PINECONE_INDEX")) != null ? _q : (_p = base == null ? void 0 : base.vectorDb) == null ? void 0 : _p.indexName) != null ? _t : (_s = (_r = base == null ? void 0 : base.vectorDb) == null ? void 0 : _r.options) == null ? void 0 : _s.indexName) != null ? _u : process.env.PINECONE_INDEX) != null ? _v : "retrivora-free";
3209
3241
  } else if (vectorProvider === "pgvector" || vectorProvider === "postgresql") {
3210
- vectorDbOptions.connectionString = (_y = (_x = (_u = readString(env, "PGVECTOR_CONNECTION_STRING")) != null ? _u : readString(env, "POSTGRES_URL")) != null ? _x : (_w = (_v = base == null ? void 0 : base.vectorDb) == null ? void 0 : _v.options) == null ? void 0 : _w.connectionString) != null ? _y : "";
3211
- vectorDbOptions.tables = (_D = (_A = (_z = readString(env, "VECTOR_DB_TABLES")) != null ? _z : readString(env, "POSTGRES_TABLES")) == null ? void 0 : _A.split(",").map((t) => t.trim())) != null ? _D : (_C = (_B = base == null ? void 0 : base.vectorDb) == null ? void 0 : _B.options) == null ? void 0 : _C.tables;
3212
- vectorDbOptions.searchFields = (_H = (_E = readString(env, "POSTGRES_SEARCH_FIELDS")) == null ? void 0 : _E.split(",").map((f) => f.trim())) != null ? _H : (_G = (_F = base == null ? void 0 : base.vectorDb) == null ? void 0 : _F.options) == null ? void 0 : _G.searchFields;
3242
+ vectorDbOptions.connectionString = (_A = (_z = (_w = readString(env, "PGVECTOR_CONNECTION_STRING")) != null ? _w : readString(env, "POSTGRES_URL")) != null ? _z : (_y = (_x = base == null ? void 0 : base.vectorDb) == null ? void 0 : _x.options) == null ? void 0 : _y.connectionString) != null ? _A : "";
3243
+ vectorDbOptions.tables = (_F = (_C = (_B = readString(env, "VECTOR_DB_TABLES")) != null ? _B : readString(env, "POSTGRES_TABLES")) == null ? void 0 : _C.split(",").map((t) => t.trim())) != null ? _F : (_E = (_D = base == null ? void 0 : base.vectorDb) == null ? void 0 : _D.options) == null ? void 0 : _E.tables;
3244
+ vectorDbOptions.searchFields = (_J = (_G = readString(env, "POSTGRES_SEARCH_FIELDS")) == null ? void 0 : _G.split(",").map((f) => f.trim())) != null ? _J : (_I = (_H = base == null ? void 0 : base.vectorDb) == null ? void 0 : _H.options) == null ? void 0 : _I.searchFields;
3213
3245
  vectorDbOptions.dimensions = embeddingDimensions;
3214
3246
  } else if (vectorProvider === "mongodb") {
3215
- vectorDbOptions.uri = (_L = (_K = readString(env, "MONGODB_URI")) != null ? _K : (_J = (_I = base == null ? void 0 : base.vectorDb) == null ? void 0 : _I.options) == null ? void 0 : _J.uri) != null ? _L : "";
3216
- vectorDbOptions.database = (_P = (_O = readString(env, "MONGODB_DB")) != null ? _O : (_N = (_M = base == null ? void 0 : base.vectorDb) == null ? void 0 : _M.options) == null ? void 0 : _N.database) != null ? _P : "";
3217
- vectorDbOptions.collection = (_T = (_S = readString(env, "MONGODB_COLLECTION")) != null ? _S : (_R = (_Q = base == null ? void 0 : base.vectorDb) == null ? void 0 : _Q.options) == null ? void 0 : _R.collection) != null ? _T : "";
3218
- vectorDbOptions.indexName = (_Z = (_Y = (_V = readString(env, "MONGODB_INDEX_NAME")) != null ? _V : (_U = base == null ? void 0 : base.vectorDb) == null ? void 0 : _U.indexName) != null ? _Y : (_X = (_W = base == null ? void 0 : base.vectorDb) == null ? void 0 : _W.options) == null ? void 0 : _X.indexName) != null ? _Z : "vector_index";
3247
+ vectorDbOptions.uri = (_N = (_M = readString(env, "MONGODB_URI")) != null ? _M : (_L = (_K = base == null ? void 0 : base.vectorDb) == null ? void 0 : _K.options) == null ? void 0 : _L.uri) != null ? _N : "";
3248
+ vectorDbOptions.database = (_R = (_Q = readString(env, "MONGODB_DB")) != null ? _Q : (_P = (_O = base == null ? void 0 : base.vectorDb) == null ? void 0 : _O.options) == null ? void 0 : _P.database) != null ? _R : "";
3249
+ vectorDbOptions.collection = (_V = (_U = readString(env, "MONGODB_COLLECTION")) != null ? _U : (_T = (_S = base == null ? void 0 : base.vectorDb) == null ? void 0 : _S.options) == null ? void 0 : _T.collection) != null ? _V : "";
3250
+ vectorDbOptions.indexName = (_$ = (__ = (_X = readString(env, "MONGODB_INDEX_NAME")) != null ? _X : (_W = base == null ? void 0 : base.vectorDb) == null ? void 0 : _W.indexName) != null ? __ : (_Z = (_Y = base == null ? void 0 : base.vectorDb) == null ? void 0 : _Y.options) == null ? void 0 : _Z.indexName) != null ? _$ : "vector_index";
3219
3251
  } else if (vectorProvider === "qdrant") {
3220
- vectorDbOptions.baseUrl = (_ba = (_aa = readString(env, "QDRANT_URL")) != null ? _aa : (_$ = (__ = base == null ? void 0 : base.vectorDb) == null ? void 0 : __.options) == null ? void 0 : _$.baseUrl) != null ? _ba : "http://localhost:6333";
3221
- vectorDbOptions.apiKey = (_ea = readString(env, "QDRANT_API_KEY")) != null ? _ea : (_da = (_ca = base == null ? void 0 : base.vectorDb) == null ? void 0 : _ca.options) == null ? void 0 : _da.apiKey;
3252
+ vectorDbOptions.baseUrl = (_da = (_ca = readString(env, "QDRANT_URL")) != null ? _ca : (_ba = (_aa = base == null ? void 0 : base.vectorDb) == null ? void 0 : _aa.options) == null ? void 0 : _ba.baseUrl) != null ? _da : "http://localhost:6333";
3253
+ vectorDbOptions.apiKey = (_ga = readString(env, "QDRANT_API_KEY")) != null ? _ga : (_fa = (_ea = base == null ? void 0 : base.vectorDb) == null ? void 0 : _ea.options) == null ? void 0 : _fa.apiKey;
3222
3254
  vectorDbOptions.dimensions = embeddingDimensions;
3223
3255
  } else if (vectorProvider === "milvus") {
3224
- vectorDbOptions.baseUrl = (_fa = readString(env, "MILVUS_URL")) != null ? _fa : "http://localhost:19530";
3256
+ vectorDbOptions.baseUrl = (_ha = readString(env, "MILVUS_URL")) != null ? _ha : "http://localhost:19530";
3225
3257
  vectorDbOptions.apiKey = readString(env, "MILVUS_API_KEY");
3226
3258
  } else if (vectorProvider === "chromadb") {
3227
- vectorDbOptions.baseUrl = (_ga = readString(env, "CHROMADB_URL")) != null ? _ga : "http://localhost:8000";
3259
+ vectorDbOptions.baseUrl = (_ia = readString(env, "CHROMADB_URL")) != null ? _ia : "http://localhost:8000";
3228
3260
  } else if (vectorProvider === "weaviate") {
3229
- vectorDbOptions.baseUrl = (_ha = readString(env, "WEAVIATE_URL")) != null ? _ha : "http://localhost:8080";
3261
+ vectorDbOptions.baseUrl = (_ja = readString(env, "WEAVIATE_URL")) != null ? _ja : "http://localhost:8080";
3230
3262
  vectorDbOptions.apiKey = readString(env, "WEAVIATE_API_KEY");
3231
3263
  } else if (vectorProvider === "redis") {
3232
- vectorDbOptions.baseUrl = (_ia = readString(env, "REDIS_URL")) != null ? _ia : "";
3264
+ vectorDbOptions.baseUrl = (_ka = readString(env, "REDIS_URL")) != null ? _ka : "";
3233
3265
  vectorDbOptions.apiKey = readString(env, "REDIS_API_KEY");
3234
3266
  } else if (vectorProvider === "rest") {
3235
- vectorDbOptions.baseUrl = (_ja = readString(env, "VECTOR_DB_REST_URL")) != null ? _ja : "";
3267
+ vectorDbOptions.baseUrl = (_la = readString(env, "VECTOR_DB_REST_URL")) != null ? _la : "";
3236
3268
  vectorDbOptions.headers = readString(env, "VECTOR_DB_REST_API_KEY") ? { "api-key": readString(env, "VECTOR_DB_REST_API_KEY") } : {};
3237
3269
  } else if (vectorProvider === "universal_rest") {
3238
- vectorDbOptions.baseUrl = (_la = (_ka = readString(env, "VECTOR_BASE_URL")) != null ? _ka : readString(env, "VECTOR_DB_REST_URL")) != null ? _la : "";
3270
+ vectorDbOptions.baseUrl = (_na = (_ma = readString(env, "VECTOR_BASE_URL")) != null ? _ma : readString(env, "VECTOR_DB_REST_URL")) != null ? _na : "";
3239
3271
  vectorDbOptions.profile = readString(env, "VECTOR_UNIVERSAL_PROFILE");
3240
3272
  vectorDbOptions.headers = readString(env, "VECTOR_DB_REST_API_KEY") ? { Authorization: `Bearer ${readString(env, "VECTOR_DB_REST_API_KEY")}` } : {};
3241
3273
  }
@@ -3254,8 +3286,8 @@ function getEnvConfig(env = process.env, base) {
3254
3286
  // Anthropic needs a separate embedding provider; key kept for completeness
3255
3287
  gemini: readString(env, "GEMINI_API_KEY"),
3256
3288
  ollama: void 0,
3257
- universal_rest: (_ma = readString(env, "EMBEDDING_API_KEY")) != null ? _ma : readString(env, "OPENAI_API_KEY"),
3258
- custom: (_na = readString(env, "EMBEDDING_API_KEY")) != null ? _na : readString(env, "OPENAI_API_KEY")
3289
+ universal_rest: (_oa = readString(env, "EMBEDDING_API_KEY")) != null ? _oa : readString(env, "OPENAI_API_KEY"),
3290
+ custom: (_pa = readString(env, "EMBEDDING_API_KEY")) != null ? _pa : readString(env, "OPENAI_API_KEY")
3259
3291
  };
3260
3292
  const DEFAULT_MODEL_BY_PROVIDER = {
3261
3293
  openai: "gpt-4o",
@@ -3276,25 +3308,25 @@ function getEnvConfig(env = process.env, base) {
3276
3308
  return true;
3277
3309
  }
3278
3310
  })();
3279
- const defaultGatewayUrl = (_pa = (_oa = readString(env, "LITELLM_BASE_URL")) != null ? _oa : readString(env, "LLM_BASE_URL")) != null ? _pa : "https://www.retrivora.com/api/v1";
3311
+ const defaultGatewayUrl = (_ra = (_qa = readString(env, "LITELLM_BASE_URL")) != null ? _qa : readString(env, "LLM_BASE_URL")) != null ? _ra : "https://www.retrivora.com/api/v1";
3280
3312
  const defaultLlmProvider = isFreeTier ? "universal_rest" : "universal_rest";
3281
- 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;
3282
- const llmBaseUrl = (_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 : defaultGatewayUrl;
3283
- const llmModel = (_Aa = (_ya = readString(env, "LLM_MODEL")) != null ? _ya : (_xa = base == null ? void 0 : base.llm) == null ? void 0 : _xa.model) != null ? _Aa : isFreeTier ? "llama-3.1-8b-instant" : (_za = DEFAULT_MODEL_BY_PROVIDER[llmProvider]) != null ? _za : "gpt-4o";
3284
- const llmApiKey = (_Ga = (_Fa = (_Da = (_Ca = (_Ba = llmApiKeyByProvider[llmProvider]) != null ? _Ba : readString(env, "LLM_API_KEY")) != null ? _Ca : readString(env, "LITELLM_MASTER_KEY")) != null ? _Da : readString(env, "LITELLM_API_KEY")) != null ? _Fa : (_Ea = base == null ? void 0 : base.llm) == null ? void 0 : _Ea.apiKey) != null ? _Ga : licenseKey;
3285
- 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";
3313
+ const llmProvider = (_ua = (_ta = readEnum(env, "LLM_PROVIDER", defaultLlmProvider, LLM_PROVIDERS)) != null ? _ta : (_sa = base == null ? void 0 : base.llm) == null ? void 0 : _sa.provider) != null ? _ua : defaultLlmProvider;
3314
+ const llmBaseUrl = (_ya = (_xa = (_va = readString(env, "LITELLM_BASE_URL")) != null ? _va : readString(env, "LLM_BASE_URL")) != null ? _xa : (_wa = base == null ? void 0 : base.llm) == null ? void 0 : _wa.baseUrl) != null ? _ya : defaultGatewayUrl;
3315
+ const llmModel = (_Ca = (_Aa = readString(env, "LLM_MODEL")) != null ? _Aa : (_za = base == null ? void 0 : base.llm) == null ? void 0 : _za.model) != null ? _Ca : isFreeTier ? "llama-3.1-8b-instant" : (_Ba = DEFAULT_MODEL_BY_PROVIDER[llmProvider]) != null ? _Ba : "gpt-4o";
3316
+ const llmApiKey = (_Ia = (_Ha = (_Fa = (_Ea = (_Da = llmApiKeyByProvider[llmProvider]) != null ? _Da : readString(env, "LLM_API_KEY")) != null ? _Ea : readString(env, "LITELLM_MASTER_KEY")) != null ? _Fa : readString(env, "LITELLM_API_KEY")) != null ? _Ha : (_Ga = base == null ? void 0 : base.llm) == null ? void 0 : _Ga.apiKey) != null ? _Ia : licenseKey;
3317
+ const llmProfile = (_Ma = (_La = readString(env, "LLM_UNIVERSAL_PROFILE")) != null ? _La : (_Ka = (_Ja = base == null ? void 0 : base.llm) == null ? void 0 : _Ja.options) == null ? void 0 : _Ka.profile) != null ? _Ma : "litellm";
3286
3318
  const defaultEmbeddingProvider = isFreeTier ? "universal_rest" : "universal_rest";
3287
- 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;
3288
- const embeddingBaseUrl = (_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 : defaultGatewayUrl;
3289
- const embeddingModel = (_Va = (_Ua = readString(env, "EMBEDDING_MODEL")) != null ? _Ua : (_Ta = base == null ? void 0 : base.embedding) == null ? void 0 : _Ta.model) != null ? _Va : "text-embedding-004";
3290
- const embeddingApiKey = (_ab = (_$a = (_Za = (_Ya = (_Xa = (_Wa = embeddingApiKeyByProvider[embeddingProvider]) != null ? _Wa : readString(env, "EMBEDDING_API_KEY")) != null ? _Xa : readString(env, "LLM_API_KEY")) != null ? _Ya : readString(env, "LITELLM_MASTER_KEY")) != null ? _Za : readString(env, "LITELLM_API_KEY")) != null ? _$a : (__a = base == null ? void 0 : base.embedding) == null ? void 0 : __a.apiKey) != null ? _ab : licenseKey;
3291
- 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";
3319
+ const embeddingProvider = (_Pa = (_Oa = readEnum(env, "EMBEDDING_PROVIDER", defaultEmbeddingProvider, EMBEDDING_PROVIDERS)) != null ? _Oa : (_Na = base == null ? void 0 : base.embedding) == null ? void 0 : _Na.provider) != null ? _Pa : defaultEmbeddingProvider;
3320
+ const embeddingBaseUrl = (_Ua = (_Ta = (_Ra = (_Qa = readString(env, "LITELLM_BASE_URL")) != null ? _Qa : readString(env, "EMBEDDING_BASE_URL")) != null ? _Ra : readString(env, "LLM_BASE_URL")) != null ? _Ta : (_Sa = base == null ? void 0 : base.embedding) == null ? void 0 : _Sa.baseUrl) != null ? _Ua : defaultGatewayUrl;
3321
+ const embeddingModel = (_Xa = (_Wa = readString(env, "EMBEDDING_MODEL")) != null ? _Wa : (_Va = base == null ? void 0 : base.embedding) == null ? void 0 : _Va.model) != null ? _Xa : "text-embedding-004";
3322
+ const embeddingApiKey = (_cb = (_bb = (_$a = (__a = (_Za = (_Ya = embeddingApiKeyByProvider[embeddingProvider]) != null ? _Ya : readString(env, "EMBEDDING_API_KEY")) != null ? _Za : readString(env, "LLM_API_KEY")) != null ? __a : readString(env, "LITELLM_MASTER_KEY")) != null ? _$a : readString(env, "LITELLM_API_KEY")) != null ? _bb : (_ab = base == null ? void 0 : base.embedding) == null ? void 0 : _ab.apiKey) != null ? _cb : licenseKey;
3323
+ const embeddingProfile = (_gb = (_fb = readString(env, "EMBEDDING_UNIVERSAL_PROFILE")) != null ? _fb : (_eb = (_db = base == null ? void 0 : base.embedding) == null ? void 0 : _db.options) == null ? void 0 : _eb.profile) != null ? _gb : "litellm";
3292
3324
  return __spreadProps(__spreadValues({
3293
3325
  projectId,
3294
3326
  licenseKey,
3295
3327
  vectorDb: {
3296
3328
  provider: vectorProvider,
3297
- indexName: (_gb = (_fb = readString(env, "VECTOR_DB_INDEX")) != null ? _fb : vectorDbOptions.indexName) != null ? _gb : "rag-index",
3329
+ indexName: (_ib = (_hb = readString(env, "VECTOR_DB_INDEX")) != null ? _hb : vectorDbOptions.indexName) != null ? _ib : "rag-index",
3298
3330
  options: vectorDbOptions
3299
3331
  },
3300
3332
  llm: {
@@ -3324,30 +3356,30 @@ function getEnvConfig(env = process.env, base) {
3324
3356
  }
3325
3357
  },
3326
3358
  ui: {
3327
- title: (_ib = (_hb = readString(env, "NEXT_PUBLIC_UI_TITLE")) != null ? _hb : readString(env, "UI_TITLE")) != null ? _ib : "AI Assistant",
3328
- subtitle: (_kb = (_jb = readString(env, "NEXT_PUBLIC_UI_SUBTITLE")) != null ? _jb : readString(env, "UI_SUBTITLE")) != null ? _kb : "Powered by RAG",
3329
- primaryColor: (_mb = (_lb = readString(env, "NEXT_PUBLIC_PRIMARY_COLOR")) != null ? _lb : readString(env, "UI_PRIMARY_COLOR")) != null ? _mb : "#10b981",
3330
- accentColor: (_ob = (_nb = readString(env, "NEXT_PUBLIC_ACCENT_COLOR")) != null ? _nb : readString(env, "UI_ACCENT_COLOR")) != null ? _ob : "#3b82f6",
3331
- logoUrl: (_pb = readString(env, "NEXT_PUBLIC_LOGO_URL")) != null ? _pb : readString(env, "UI_LOGO_URL"),
3332
- placeholder: (_rb = (_qb = readString(env, "NEXT_PUBLIC_PLACEHOLDER")) != null ? _qb : readString(env, "UI_PLACEHOLDER")) != null ? _rb : "Ask me anything\u2026",
3333
- showSources: ((_tb = (_sb = readString(env, "NEXT_PUBLIC_SHOW_SOURCES")) != null ? _sb : readString(env, "UI_SHOW_SOURCES")) != null ? _tb : "true") !== "false",
3334
- 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.",
3335
- visualStyle: (_xb = (_wb = readString(env, "NEXT_PUBLIC_UI_VISUAL_STYLE")) != null ? _wb : readString(env, "UI_VISUAL_STYLE")) != null ? _xb : "glass",
3336
- borderRadius: (_zb = (_yb = readString(env, "NEXT_PUBLIC_UI_BORDER_RADIUS")) != null ? _yb : readString(env, "UI_BORDER_RADIUS")) != null ? _zb : "xl",
3337
- allowUpload: ((_Bb = (_Ab = readString(env, "NEXT_PUBLIC_ALLOW_UPLOAD")) != null ? _Ab : readString(env, "UI_ALLOW_UPLOAD")) != null ? _Bb : "false") === "true"
3359
+ title: (_kb = (_jb = readString(env, "NEXT_PUBLIC_UI_TITLE")) != null ? _jb : readString(env, "UI_TITLE")) != null ? _kb : "AI Assistant",
3360
+ subtitle: (_mb = (_lb = readString(env, "NEXT_PUBLIC_UI_SUBTITLE")) != null ? _lb : readString(env, "UI_SUBTITLE")) != null ? _mb : "Powered by RAG",
3361
+ primaryColor: (_ob = (_nb = readString(env, "NEXT_PUBLIC_PRIMARY_COLOR")) != null ? _nb : readString(env, "UI_PRIMARY_COLOR")) != null ? _ob : "#10b981",
3362
+ accentColor: (_qb = (_pb = readString(env, "NEXT_PUBLIC_ACCENT_COLOR")) != null ? _pb : readString(env, "UI_ACCENT_COLOR")) != null ? _qb : "#3b82f6",
3363
+ logoUrl: (_rb = readString(env, "NEXT_PUBLIC_LOGO_URL")) != null ? _rb : readString(env, "UI_LOGO_URL"),
3364
+ placeholder: (_tb = (_sb = readString(env, "NEXT_PUBLIC_PLACEHOLDER")) != null ? _sb : readString(env, "UI_PLACEHOLDER")) != null ? _tb : "Ask me anything\u2026",
3365
+ showSources: ((_vb = (_ub = readString(env, "NEXT_PUBLIC_SHOW_SOURCES")) != null ? _ub : readString(env, "UI_SHOW_SOURCES")) != null ? _vb : "true") !== "false",
3366
+ 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.",
3367
+ visualStyle: (_zb = (_yb = readString(env, "NEXT_PUBLIC_UI_VISUAL_STYLE")) != null ? _yb : readString(env, "UI_VISUAL_STYLE")) != null ? _zb : "glass",
3368
+ borderRadius: (_Bb = (_Ab = readString(env, "NEXT_PUBLIC_UI_BORDER_RADIUS")) != null ? _Ab : readString(env, "UI_BORDER_RADIUS")) != null ? _Bb : "xl",
3369
+ allowUpload: ((_Db = (_Cb = readString(env, "NEXT_PUBLIC_ALLOW_UPLOAD")) != null ? _Cb : readString(env, "UI_ALLOW_UPLOAD")) != null ? _Db : "false") === "true"
3338
3370
  },
3339
3371
  rag: {
3340
3372
  topK: readNumber(env, "RAG_TOP_K", 5),
3341
3373
  scoreThreshold: readNumber(env, "RAG_SCORE_THRESHOLD", 0),
3342
3374
  chunkSize: readNumber(env, "RAG_CHUNK_SIZE", 1e3),
3343
3375
  chunkOverlap: readNumber(env, "RAG_CHUNK_OVERLAP", 200),
3344
- filterableFields: (_Cb = readString(env, "RAG_FILTERABLE_FIELDS")) == null ? void 0 : _Cb.split(",").map((f) => f.trim()),
3376
+ filterableFields: (_Eb = readString(env, "RAG_FILTERABLE_FIELDS")) == null ? void 0 : _Eb.split(",").map((f) => f.trim()),
3345
3377
  // Query pipeline toggles — read from .env.local
3346
3378
  useQueryTransformation: readString(env, "RAG_USE_QUERY_TRANSFORMATION") === "true",
3347
3379
  useReranking: readString(env, "RAG_USE_RERANKING") === "true",
3348
3380
  useGraphRetrieval: readString(env, "RAG_USE_GRAPH_RETRIEVAL") === "true",
3349
- architecture: (_Db = readString(env, "RAG_ARCHITECTURE")) != null ? _Db : "simple",
3350
- chunkingStrategy: (_Eb = readString(env, "RAG_CHUNKING_STRATEGY")) != null ? _Eb : "recursive",
3381
+ architecture: (_Fb = readString(env, "RAG_ARCHITECTURE")) != null ? _Fb : "simple",
3382
+ chunkingStrategy: (_Gb = readString(env, "RAG_CHUNKING_STRATEGY")) != null ? _Gb : "recursive",
3351
3383
  uiMapping: (() => {
3352
3384
  const raw = readString(env, "RAG_UI_MAPPING");
3353
3385
  if (!raw) return void 0;
@@ -3360,7 +3392,7 @@ function getEnvConfig(env = process.env, base) {
3360
3392
  },
3361
3393
  telemetry: {
3362
3394
  enabled: telemetryEnabled,
3363
- 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 : process.env.NODE_ENV === "development" ? "http://localhost:3001/api/telemetry" : "https://retrivora.com/api/telemetry"
3395
+ url: (_Kb = (_Jb = (_Hb = readString(env, "TELEMETRY_URL")) != null ? _Hb : readString(env, "NEXT_PUBLIC_TELEMETRY_URL")) != null ? _Jb : (_Ib = base == null ? void 0 : base.telemetry) == null ? void 0 : _Ib.url) != null ? _Kb : process.env.NODE_ENV === "development" ? "http://localhost:3001/api/telemetry" : "https://retrivora.com/api/telemetry"
3364
3396
  }
3365
3397
  }, readString(env, "GRAPH_DB_PROVIDER") ? {
3366
3398
  graphDb: {
@@ -5363,7 +5395,7 @@ var ConfigValidator = class {
5363
5395
  // package.json
5364
5396
  var package_default = {
5365
5397
  name: "@retrivora-ai/rag-engine",
5366
- version: "2.2.1",
5398
+ version: "2.2.3",
5367
5399
  description: "Retrivora AI is a plug-and-play AI engine for RAG chat experiences \u2014 generic vector DB + LLM provider, embeddable or standalone.",
5368
5400
  author: "Abhinav Alkuchi",
5369
5401
  license: "UNLICENSED",
@@ -9009,11 +9041,10 @@ SchemaMapper.TARGET_PROPERTIES = {
9009
9041
 
9010
9042
  // src/core/Pipeline.ts
9011
9043
  function formatNamespace(raw) {
9012
- if (!raw || !raw.trim()) return "retrivora-default";
9044
+ if (!raw || !raw.trim()) return "default";
9013
9045
  const trimmed = raw.trim();
9014
- if (trimmed.startsWith("retrivora-")) return trimmed;
9015
- const sanitized = trimmed.toLowerCase().replace(/[^a-z0-9_-]/g, "_").replace(/_+/g, "_").replace(/^_+|_+$/g, "");
9016
- return `retrivora-${sanitized}`;
9046
+ const sanitized = trimmed.replace(/[^a-zA-Z0-9_-]/g, "_").replace(/_+/g, "_").replace(/^_+|_+$/g, "");
9047
+ return sanitized || "default";
9017
9048
  }
9018
9049
  var LRUEmbeddingCache = class {
9019
9050
  constructor(maxSize = 500) {
@@ -10909,7 +10940,7 @@ function reportTelemetry(req, plugin, action, status, details, trace) {
10909
10940
  const licenseKey = config.licenseKey || process.env.RAG_LICENSE_KEY || process.env.RETRIVORA_LICENSE_KEY || process.env.NEXT_PUBLIC_RETRIVORA_LICENSE_KEY;
10910
10941
  const telemetryConfig = config.telemetry;
10911
10942
  const enabled = (_a2 = telemetryConfig == null ? void 0 : telemetryConfig.enabled) != null ? _a2 : Boolean(licenseKey);
10912
- const defaultUrl = process.env.NODE_ENV === "development" && !process.env.TELEMETRY_URL && !process.env.NEXT_PUBLIC_TELEMETRY_URL ? "http://localhost:3001/api/telemetry" : "https://retrivora.com/api/telemetry";
10943
+ const defaultUrl = process.env.NODE_ENV === "development" && !process.env.TELEMETRY_URL && !process.env.NEXT_PUBLIC_TELEMETRY_URL ? "http://localhost:3001/api/telemetry" : "https://www.retrivora.com/api/telemetry";
10913
10944
  const telemetryUrl = (telemetryConfig == null ? void 0 : telemetryConfig.url) || process.env.TELEMETRY_URL || process.env.NEXT_PUBLIC_TELEMETRY_URL || defaultUrl;
10914
10945
  const host = req.headers.get("host") || "localhost";
10915
10946
  const userAgent = req.headers.get("user-agent") || `Retrivora-SDK/${SDK_VERSION}`;