@retrivora-ai/rag-engine 2.1.2 → 2.1.4

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.mjs CHANGED
@@ -576,26 +576,54 @@ function cleanApiKeyOverride(apiKeyOverride) {
576
576
  }
577
577
  return key;
578
578
  }
579
+ async function resolveUserGatewayConfig(apiKeyOverride) {
580
+ var _a2;
581
+ if (!apiKeyOverride || !process.env.NEXT_PUBLIC_SUPABASE_URL || !process.env.SUPABASE_SERVICE_ROLE_KEY) {
582
+ return {};
583
+ }
584
+ try {
585
+ const { createAdminClient } = await import("@/lib/supabase-server");
586
+ const supabase = createAdminClient();
587
+ const { data: licenseRecord } = await supabase.from("licenses").select("project_id, customer_name, tier").eq("license_key", apiKeyOverride.trim()).single();
588
+ if (!licenseRecord) {
589
+ return {};
590
+ }
591
+ const projectId = licenseRecord.project_id;
592
+ const { data: configs } = await supabase.from("gateway_config").select("project_id, default_model, provider_keys, is_active").in("project_id", [projectId, "global"]).eq("is_active", true);
593
+ if (!configs || configs.length === 0) {
594
+ return {};
595
+ }
596
+ const matchedConfig = configs.find((c) => c.project_id === projectId) || configs.find((c) => c.project_id === "global");
597
+ const customGroqKey = (_a2 = matchedConfig == null ? void 0 : matchedConfig.provider_keys) == null ? void 0 : _a2.groq;
598
+ const targetModel = matchedConfig == null ? void 0 : matchedConfig.default_model;
599
+ return { customGroqKey, targetModel };
600
+ } catch (err) {
601
+ console.warn("[LLM Gateway Router] Error resolving user gateway_config:", err.message);
602
+ return {};
603
+ }
604
+ }
579
605
  async function dispatchChatCompletion(req, apiKeyOverride) {
580
- const effectiveKey = cleanApiKeyOverride(apiKeyOverride);
581
- const provider = resolveProvider(req.model);
582
- console.log(`[LLM Gateway Router] Dispatching chat request: model=${req.model}, provider=${provider}, hasGroqKey=${Boolean(process.env.GROQ_API_KEY)}, hasGeminiKey=${Boolean(process.env.GROQ_API_KEY || process.env.GEMINI_API_KEY)}, hasHFToken=${Boolean(process.env.HF_TOKEN)}`);
606
+ const { customGroqKey, targetModel } = await resolveUserGatewayConfig(apiKeyOverride);
607
+ const effectiveKey = customGroqKey || cleanApiKeyOverride(apiKeyOverride);
608
+ const activeModel = req.model || targetModel || "llama-3.1-8b-instant";
609
+ const provider = resolveProvider(activeModel);
610
+ console.log(`[LLM Gateway Router] Dispatching chat request: model=${activeModel}, provider=${provider}, hasCustomKey=${Boolean(customGroqKey)}, hasGlobalGroqKey=${Boolean(process.env.GROQ_API_KEY)}`);
583
611
  try {
584
612
  switch (provider) {
585
613
  case "groq":
586
- return await handleGroqRequest(req, effectiveKey);
614
+ return await handleGroqRequest(__spreadProps(__spreadValues({}, req), { model: activeModel }), effectiveKey);
587
615
  case "openai":
588
- return await handleOpenAIRequest(req, effectiveKey);
616
+ return await handleOpenAIRequest(__spreadProps(__spreadValues({}, req), { model: activeModel }), effectiveKey);
589
617
  case "gemini":
590
- return await handleGeminiRequest(req, effectiveKey);
618
+ return await handleGeminiRequest(__spreadProps(__spreadValues({}, req), { model: activeModel }), effectiveKey);
591
619
  case "anthropic":
592
- return await handleAnthropicRequest(req, effectiveKey);
620
+ return await handleAnthropicRequest(__spreadProps(__spreadValues({}, req), { model: activeModel }), effectiveKey);
593
621
  case "ollama":
594
- return await handleOllamaRequest(req);
622
+ return await handleOllamaRequest(__spreadProps(__spreadValues({}, req), { model: activeModel }));
595
623
  case "huggingface":
596
- return await handleHuggingFaceChatRequest(req, effectiveKey);
624
+ return await handleHuggingFaceChatRequest(__spreadProps(__spreadValues({}, req), { model: activeModel }), effectiveKey);
597
625
  default:
598
- throw new Error(`Unsupported LLM provider for model: ${req.model}`);
626
+ throw new Error(`Unsupported LLM provider for model: ${activeModel}`);
599
627
  }
600
628
  } catch (error) {
601
629
  console.error(`[LLM Gateway Router] Provider '${provider}' failed for model '${req.model}':`, {
@@ -3017,7 +3045,7 @@ function getRagConfig(baseConfig, env = process.env) {
3017
3045
  return getEnvConfig(env, baseConfig);
3018
3046
  }
3019
3047
  function getEnvConfig(env = process.env, base) {
3020
- 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;
3048
+ 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;
3021
3049
  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__";
3022
3050
  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;
3023
3051
  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);
@@ -3025,38 +3053,38 @@ function getEnvConfig(env = process.env, base) {
3025
3053
  const embeddingDimensions = readNumber(env, "EMBEDDING_DIMENSIONS", 768);
3026
3054
  const vectorDbOptions = {};
3027
3055
  if (vectorProvider === "pinecone") {
3028
- vectorDbOptions.apiKey = (_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 : "";
3029
- vectorDbOptions.indexName = (_q = (_n = readString(env, "PINECONE_INDEX")) != null ? _n : (_m = base == null ? void 0 : base.vectorDb) == null ? void 0 : _m.indexName) != null ? _q : (_p = (_o = base == null ? void 0 : base.vectorDb) == null ? void 0 : _o.options) == null ? void 0 : _p.indexName;
3056
+ 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 : "";
3057
+ 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";
3030
3058
  } else if (vectorProvider === "pgvector" || vectorProvider === "postgresql") {
3031
- vectorDbOptions.connectionString = (_v = (_u = (_r = readString(env, "PGVECTOR_CONNECTION_STRING")) != null ? _r : readString(env, "POSTGRES_URL")) != null ? _u : (_t = (_s = base == null ? void 0 : base.vectorDb) == null ? void 0 : _s.options) == null ? void 0 : _t.connectionString) != null ? _v : "";
3032
- vectorDbOptions.tables = (_A = (_x = (_w = readString(env, "VECTOR_DB_TABLES")) != null ? _w : readString(env, "POSTGRES_TABLES")) == null ? void 0 : _x.split(",").map((t) => t.trim())) != null ? _A : (_z = (_y = base == null ? void 0 : base.vectorDb) == null ? void 0 : _y.options) == null ? void 0 : _z.tables;
3033
- vectorDbOptions.searchFields = (_E = (_B = readString(env, "POSTGRES_SEARCH_FIELDS")) == null ? void 0 : _B.split(",").map((f) => f.trim())) != null ? _E : (_D = (_C = base == null ? void 0 : base.vectorDb) == null ? void 0 : _C.options) == null ? void 0 : _D.searchFields;
3059
+ 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 : "";
3060
+ 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;
3061
+ 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;
3034
3062
  vectorDbOptions.dimensions = embeddingDimensions;
3035
3063
  } else if (vectorProvider === "mongodb") {
3036
- vectorDbOptions.uri = (_I = (_H = readString(env, "MONGODB_URI")) != null ? _H : (_G = (_F = base == null ? void 0 : base.vectorDb) == null ? void 0 : _F.options) == null ? void 0 : _G.uri) != null ? _I : "";
3037
- vectorDbOptions.database = (_M = (_L = readString(env, "MONGODB_DB")) != null ? _L : (_K = (_J = base == null ? void 0 : base.vectorDb) == null ? void 0 : _J.options) == null ? void 0 : _K.database) != null ? _M : "";
3038
- vectorDbOptions.collection = (_Q = (_P = readString(env, "MONGODB_COLLECTION")) != null ? _P : (_O = (_N = base == null ? void 0 : base.vectorDb) == null ? void 0 : _N.options) == null ? void 0 : _O.collection) != null ? _Q : "";
3039
- vectorDbOptions.indexName = (_W = (_V = (_S = readString(env, "MONGODB_INDEX_NAME")) != null ? _S : (_R = base == null ? void 0 : base.vectorDb) == null ? void 0 : _R.indexName) != null ? _V : (_U = (_T = base == null ? void 0 : base.vectorDb) == null ? void 0 : _T.options) == null ? void 0 : _U.indexName) != null ? _W : "vector_index";
3064
+ 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 : "";
3065
+ 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 : "";
3066
+ 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 : "";
3067
+ 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";
3040
3068
  } else if (vectorProvider === "qdrant") {
3041
- vectorDbOptions.baseUrl = (__ = (_Z = readString(env, "QDRANT_URL")) != null ? _Z : (_Y = (_X = base == null ? void 0 : base.vectorDb) == null ? void 0 : _X.options) == null ? void 0 : _Y.baseUrl) != null ? __ : "http://localhost:6333";
3042
- vectorDbOptions.apiKey = (_ba = readString(env, "QDRANT_API_KEY")) != null ? _ba : (_aa = (_$ = base == null ? void 0 : base.vectorDb) == null ? void 0 : _$.options) == null ? void 0 : _aa.apiKey;
3069
+ 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";
3070
+ 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;
3043
3071
  vectorDbOptions.dimensions = embeddingDimensions;
3044
3072
  } else if (vectorProvider === "milvus") {
3045
- vectorDbOptions.baseUrl = (_ca = readString(env, "MILVUS_URL")) != null ? _ca : "http://localhost:19530";
3073
+ vectorDbOptions.baseUrl = (_fa = readString(env, "MILVUS_URL")) != null ? _fa : "http://localhost:19530";
3046
3074
  vectorDbOptions.apiKey = readString(env, "MILVUS_API_KEY");
3047
3075
  } else if (vectorProvider === "chromadb") {
3048
- vectorDbOptions.baseUrl = (_da = readString(env, "CHROMADB_URL")) != null ? _da : "http://localhost:8000";
3076
+ vectorDbOptions.baseUrl = (_ga = readString(env, "CHROMADB_URL")) != null ? _ga : "http://localhost:8000";
3049
3077
  } else if (vectorProvider === "weaviate") {
3050
- vectorDbOptions.baseUrl = (_ea = readString(env, "WEAVIATE_URL")) != null ? _ea : "http://localhost:8080";
3078
+ vectorDbOptions.baseUrl = (_ha = readString(env, "WEAVIATE_URL")) != null ? _ha : "http://localhost:8080";
3051
3079
  vectorDbOptions.apiKey = readString(env, "WEAVIATE_API_KEY");
3052
3080
  } else if (vectorProvider === "redis") {
3053
- vectorDbOptions.baseUrl = (_fa = readString(env, "REDIS_URL")) != null ? _fa : "";
3081
+ vectorDbOptions.baseUrl = (_ia = readString(env, "REDIS_URL")) != null ? _ia : "";
3054
3082
  vectorDbOptions.apiKey = readString(env, "REDIS_API_KEY");
3055
3083
  } else if (vectorProvider === "rest") {
3056
- vectorDbOptions.baseUrl = (_ga = readString(env, "VECTOR_DB_REST_URL")) != null ? _ga : "";
3084
+ vectorDbOptions.baseUrl = (_ja = readString(env, "VECTOR_DB_REST_URL")) != null ? _ja : "";
3057
3085
  vectorDbOptions.headers = readString(env, "VECTOR_DB_REST_API_KEY") ? { "api-key": readString(env, "VECTOR_DB_REST_API_KEY") } : {};
3058
3086
  } else if (vectorProvider === "universal_rest") {
3059
- vectorDbOptions.baseUrl = (_ia = (_ha = readString(env, "VECTOR_BASE_URL")) != null ? _ha : readString(env, "VECTOR_DB_REST_URL")) != null ? _ia : "";
3087
+ vectorDbOptions.baseUrl = (_la = (_ka = readString(env, "VECTOR_BASE_URL")) != null ? _ka : readString(env, "VECTOR_DB_REST_URL")) != null ? _la : "";
3060
3088
  vectorDbOptions.profile = readString(env, "VECTOR_UNIVERSAL_PROFILE");
3061
3089
  vectorDbOptions.headers = readString(env, "VECTOR_DB_REST_API_KEY") ? { Authorization: `Bearer ${readString(env, "VECTOR_DB_REST_API_KEY")}` } : {};
3062
3090
  }
@@ -3075,8 +3103,8 @@ function getEnvConfig(env = process.env, base) {
3075
3103
  // Anthropic needs a separate embedding provider; key kept for completeness
3076
3104
  gemini: readString(env, "GEMINI_API_KEY"),
3077
3105
  ollama: void 0,
3078
- universal_rest: (_ja = readString(env, "EMBEDDING_API_KEY")) != null ? _ja : readString(env, "OPENAI_API_KEY"),
3079
- custom: (_ka = readString(env, "EMBEDDING_API_KEY")) != null ? _ka : readString(env, "OPENAI_API_KEY")
3106
+ universal_rest: (_ma = readString(env, "EMBEDDING_API_KEY")) != null ? _ma : readString(env, "OPENAI_API_KEY"),
3107
+ custom: (_na = readString(env, "EMBEDDING_API_KEY")) != null ? _na : readString(env, "OPENAI_API_KEY")
3080
3108
  };
3081
3109
  const DEFAULT_MODEL_BY_PROVIDER = {
3082
3110
  openai: "gpt-4o",
@@ -3097,25 +3125,25 @@ function getEnvConfig(env = process.env, base) {
3097
3125
  return true;
3098
3126
  }
3099
3127
  })();
3100
- const DEFAULT_FREE_GATEWAY = "https://llm.retrivora.com/api/v1";
3128
+ const defaultGatewayUrl = (_pa = (_oa = readString(env, "LITELLM_BASE_URL")) != null ? _oa : readString(env, "LLM_BASE_URL")) != null ? _pa : "https://llm.retrivora.com/api/v1";
3101
3129
  const defaultLlmProvider = isFreeTier ? "universal_rest" : "universal_rest";
3102
- const llmProvider = (_na = (_ma = readEnum(env, "LLM_PROVIDER", defaultLlmProvider, LLM_PROVIDERS)) != null ? _ma : (_la = base == null ? void 0 : base.llm) == null ? void 0 : _la.provider) != null ? _na : defaultLlmProvider;
3103
- const llmBaseUrl = (_qa = (_pa = readString(env, "LLM_BASE_URL")) != null ? _pa : (_oa = base == null ? void 0 : base.llm) == null ? void 0 : _oa.baseUrl) != null ? _qa : DEFAULT_FREE_GATEWAY;
3104
- const llmModel = (_ua = (_sa = readString(env, "LLM_MODEL")) != null ? _sa : (_ra = base == null ? void 0 : base.llm) == null ? void 0 : _ra.model) != null ? _ua : isFreeTier ? "llama-3.1-8b-instant" : (_ta = DEFAULT_MODEL_BY_PROVIDER[llmProvider]) != null ? _ta : "gpt-4o";
3105
- const llmApiKey = (_ya = (_xa = (_va = llmApiKeyByProvider[llmProvider]) != null ? _va : readString(env, "LLM_API_KEY")) != null ? _xa : (_wa = base == null ? void 0 : base.llm) == null ? void 0 : _wa.apiKey) != null ? _ya : "sk-retrivora-cancer-280590";
3106
- const llmProfile = (_Ca = (_Ba = readString(env, "LLM_UNIVERSAL_PROFILE")) != null ? _Ba : (_Aa = (_za = base == null ? void 0 : base.llm) == null ? void 0 : _za.options) == null ? void 0 : _Aa.profile) != null ? _Ca : "litellm";
3130
+ 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;
3131
+ 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;
3132
+ 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";
3133
+ 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;
3134
+ 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";
3107
3135
  const defaultEmbeddingProvider = isFreeTier ? "universal_rest" : "universal_rest";
3108
- const embeddingProvider = (_Fa = (_Ea = readEnum(env, "EMBEDDING_PROVIDER", defaultEmbeddingProvider, EMBEDDING_PROVIDERS)) != null ? _Ea : (_Da = base == null ? void 0 : base.embedding) == null ? void 0 : _Da.provider) != null ? _Fa : defaultEmbeddingProvider;
3109
- const embeddingBaseUrl = (_Ia = (_Ha = readString(env, "EMBEDDING_BASE_URL")) != null ? _Ha : (_Ga = base == null ? void 0 : base.embedding) == null ? void 0 : _Ga.baseUrl) != null ? _Ia : DEFAULT_FREE_GATEWAY;
3110
- const embeddingModel = (_La = (_Ka = readString(env, "EMBEDDING_MODEL")) != null ? _Ka : (_Ja = base == null ? void 0 : base.embedding) == null ? void 0 : _Ja.model) != null ? _La : "text-embedding-004";
3111
- const embeddingApiKey = (_Qa = (_Pa = (_Na = (_Ma = embeddingApiKeyByProvider[embeddingProvider]) != null ? _Ma : readString(env, "EMBEDDING_API_KEY")) != null ? _Na : readString(env, "LLM_API_KEY")) != null ? _Pa : (_Oa = base == null ? void 0 : base.embedding) == null ? void 0 : _Oa.apiKey) != null ? _Qa : "sk-retrivora-cancer-280590";
3112
- const embeddingProfile = (_Ua = (_Ta = readString(env, "EMBEDDING_UNIVERSAL_PROFILE")) != null ? _Ta : (_Sa = (_Ra = base == null ? void 0 : base.embedding) == null ? void 0 : _Ra.options) == null ? void 0 : _Sa.profile) != null ? _Ua : "litellm";
3136
+ 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;
3137
+ 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;
3138
+ 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";
3139
+ 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;
3140
+ 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";
3113
3141
  return __spreadProps(__spreadValues({
3114
3142
  projectId,
3115
3143
  licenseKey,
3116
3144
  vectorDb: {
3117
3145
  provider: vectorProvider,
3118
- indexName: (_Wa = (_Va = readString(env, "VECTOR_DB_INDEX")) != null ? _Va : vectorDbOptions.indexName) != null ? _Wa : "rag-index",
3146
+ indexName: (_gb = (_fb = readString(env, "VECTOR_DB_INDEX")) != null ? _fb : vectorDbOptions.indexName) != null ? _gb : "rag-index",
3119
3147
  options: vectorDbOptions
3120
3148
  },
3121
3149
  llm: {
@@ -3145,30 +3173,30 @@ function getEnvConfig(env = process.env, base) {
3145
3173
  }
3146
3174
  },
3147
3175
  ui: {
3148
- title: (_Ya = (_Xa = readString(env, "NEXT_PUBLIC_UI_TITLE")) != null ? _Xa : readString(env, "UI_TITLE")) != null ? _Ya : "AI Assistant",
3149
- subtitle: (__a = (_Za = readString(env, "NEXT_PUBLIC_UI_SUBTITLE")) != null ? _Za : readString(env, "UI_SUBTITLE")) != null ? __a : "Powered by RAG",
3150
- primaryColor: (_ab = (_$a = readString(env, "NEXT_PUBLIC_PRIMARY_COLOR")) != null ? _$a : readString(env, "UI_PRIMARY_COLOR")) != null ? _ab : "#10b981",
3151
- accentColor: (_cb = (_bb = readString(env, "NEXT_PUBLIC_ACCENT_COLOR")) != null ? _bb : readString(env, "UI_ACCENT_COLOR")) != null ? _cb : "#3b82f6",
3152
- logoUrl: (_db = readString(env, "NEXT_PUBLIC_LOGO_URL")) != null ? _db : readString(env, "UI_LOGO_URL"),
3153
- placeholder: (_fb = (_eb = readString(env, "NEXT_PUBLIC_PLACEHOLDER")) != null ? _eb : readString(env, "UI_PLACEHOLDER")) != null ? _fb : "Ask me anything\u2026",
3154
- showSources: ((_hb = (_gb = readString(env, "NEXT_PUBLIC_SHOW_SOURCES")) != null ? _gb : readString(env, "UI_SHOW_SOURCES")) != null ? _hb : "true") !== "false",
3155
- welcomeMessage: (_jb = (_ib = readString(env, "NEXT_PUBLIC_WELCOME_MESSAGE")) != null ? _ib : readString(env, "UI_WELCOME_MESSAGE")) != null ? _jb : "Hello! I'm your AI assistant. Ask me anything about your documents.",
3156
- visualStyle: (_lb = (_kb = readString(env, "NEXT_PUBLIC_UI_VISUAL_STYLE")) != null ? _kb : readString(env, "UI_VISUAL_STYLE")) != null ? _lb : "glass",
3157
- borderRadius: (_nb = (_mb = readString(env, "NEXT_PUBLIC_UI_BORDER_RADIUS")) != null ? _mb : readString(env, "UI_BORDER_RADIUS")) != null ? _nb : "xl",
3158
- allowUpload: ((_pb = (_ob = readString(env, "NEXT_PUBLIC_ALLOW_UPLOAD")) != null ? _ob : readString(env, "UI_ALLOW_UPLOAD")) != null ? _pb : "false") === "true"
3176
+ title: (_ib = (_hb = readString(env, "NEXT_PUBLIC_UI_TITLE")) != null ? _hb : readString(env, "UI_TITLE")) != null ? _ib : "AI Assistant",
3177
+ subtitle: (_kb = (_jb = readString(env, "NEXT_PUBLIC_UI_SUBTITLE")) != null ? _jb : readString(env, "UI_SUBTITLE")) != null ? _kb : "Powered by RAG",
3178
+ primaryColor: (_mb = (_lb = readString(env, "NEXT_PUBLIC_PRIMARY_COLOR")) != null ? _lb : readString(env, "UI_PRIMARY_COLOR")) != null ? _mb : "#10b981",
3179
+ accentColor: (_ob = (_nb = readString(env, "NEXT_PUBLIC_ACCENT_COLOR")) != null ? _nb : readString(env, "UI_ACCENT_COLOR")) != null ? _ob : "#3b82f6",
3180
+ logoUrl: (_pb = readString(env, "NEXT_PUBLIC_LOGO_URL")) != null ? _pb : readString(env, "UI_LOGO_URL"),
3181
+ placeholder: (_rb = (_qb = readString(env, "NEXT_PUBLIC_PLACEHOLDER")) != null ? _qb : readString(env, "UI_PLACEHOLDER")) != null ? _rb : "Ask me anything\u2026",
3182
+ showSources: ((_tb = (_sb = readString(env, "NEXT_PUBLIC_SHOW_SOURCES")) != null ? _sb : readString(env, "UI_SHOW_SOURCES")) != null ? _tb : "true") !== "false",
3183
+ 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.",
3184
+ visualStyle: (_xb = (_wb = readString(env, "NEXT_PUBLIC_UI_VISUAL_STYLE")) != null ? _wb : readString(env, "UI_VISUAL_STYLE")) != null ? _xb : "glass",
3185
+ borderRadius: (_zb = (_yb = readString(env, "NEXT_PUBLIC_UI_BORDER_RADIUS")) != null ? _yb : readString(env, "UI_BORDER_RADIUS")) != null ? _zb : "xl",
3186
+ allowUpload: ((_Bb = (_Ab = readString(env, "NEXT_PUBLIC_ALLOW_UPLOAD")) != null ? _Ab : readString(env, "UI_ALLOW_UPLOAD")) != null ? _Bb : "false") === "true"
3159
3187
  },
3160
3188
  rag: {
3161
3189
  topK: readNumber(env, "RAG_TOP_K", 5),
3162
3190
  scoreThreshold: readNumber(env, "RAG_SCORE_THRESHOLD", 0),
3163
3191
  chunkSize: readNumber(env, "RAG_CHUNK_SIZE", 1e3),
3164
3192
  chunkOverlap: readNumber(env, "RAG_CHUNK_OVERLAP", 200),
3165
- filterableFields: (_qb = readString(env, "RAG_FILTERABLE_FIELDS")) == null ? void 0 : _qb.split(",").map((f) => f.trim()),
3193
+ filterableFields: (_Cb = readString(env, "RAG_FILTERABLE_FIELDS")) == null ? void 0 : _Cb.split(",").map((f) => f.trim()),
3166
3194
  // Query pipeline toggles — read from .env.local
3167
3195
  useQueryTransformation: readString(env, "RAG_USE_QUERY_TRANSFORMATION") === "true",
3168
3196
  useReranking: readString(env, "RAG_USE_RERANKING") === "true",
3169
3197
  useGraphRetrieval: readString(env, "RAG_USE_GRAPH_RETRIEVAL") === "true",
3170
- architecture: (_rb = readString(env, "RAG_ARCHITECTURE")) != null ? _rb : "simple",
3171
- chunkingStrategy: (_sb = readString(env, "RAG_CHUNKING_STRATEGY")) != null ? _sb : "recursive",
3198
+ architecture: (_Db = readString(env, "RAG_ARCHITECTURE")) != null ? _Db : "simple",
3199
+ chunkingStrategy: (_Eb = readString(env, "RAG_CHUNKING_STRATEGY")) != null ? _Eb : "recursive",
3172
3200
  uiMapping: (() => {
3173
3201
  const raw = readString(env, "RAG_UI_MAPPING");
3174
3202
  if (!raw) return void 0;
@@ -3181,7 +3209,7 @@ function getEnvConfig(env = process.env, base) {
3181
3209
  },
3182
3210
  telemetry: {
3183
3211
  enabled: telemetryEnabled,
3184
- url: (_wb = (_vb = (_tb = readString(env, "TELEMETRY_URL")) != null ? _tb : readString(env, "NEXT_PUBLIC_TELEMETRY_URL")) != null ? _vb : (_ub = base == null ? void 0 : base.telemetry) == null ? void 0 : _ub.url) != null ? _wb : process.env.NODE_ENV === "development" ? "http://localhost:3001/api/telemetry" : "https://retrivora.com/api/telemetry"
3212
+ 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"
3185
3213
  }
3186
3214
  }, readString(env, "GRAPH_DB_PROVIDER") ? {
3187
3215
  graphDb: {
@@ -5220,6 +5248,147 @@ var ConfigValidator = class {
5220
5248
  }
5221
5249
  };
5222
5250
 
5251
+ // package.json
5252
+ var package_default = {
5253
+ name: "@retrivora-ai/rag-engine",
5254
+ version: "2.1.4",
5255
+ description: "Retrivora AI is a plug-and-play AI engine for RAG chat experiences \u2014 generic vector DB + LLM provider, embeddable or standalone.",
5256
+ author: "Abhinav Alkuchi",
5257
+ license: "UNLICENSED",
5258
+ keywords: [
5259
+ "rag",
5260
+ "retrieval-augmented-generation",
5261
+ "chatbot",
5262
+ "vector-database",
5263
+ "pinecone",
5264
+ "pgvector",
5265
+ "postgresql",
5266
+ "milvus",
5267
+ "qdrant",
5268
+ "chromadb",
5269
+ "redis",
5270
+ "weaviate",
5271
+ "mongodb",
5272
+ "openai",
5273
+ "anthropic",
5274
+ "ollama",
5275
+ "nextjs",
5276
+ "react",
5277
+ "ai",
5278
+ "llm",
5279
+ "embeddings"
5280
+ ],
5281
+ main: "dist/index.js",
5282
+ module: "dist/index.mjs",
5283
+ types: "dist/index.d.ts",
5284
+ exports: {
5285
+ ".": {
5286
+ types: "./dist/index.d.ts",
5287
+ require: "./dist/index.js",
5288
+ import: "./dist/index.mjs"
5289
+ },
5290
+ "./style.css": "./dist/index.css",
5291
+ "./handlers": {
5292
+ types: "./dist/handlers/index.d.ts",
5293
+ require: "./dist/handlers/index.js",
5294
+ import: "./dist/handlers/index.mjs"
5295
+ },
5296
+ "./server": {
5297
+ types: "./dist/server.d.ts",
5298
+ require: "./dist/server.js",
5299
+ import: "./dist/server.mjs"
5300
+ }
5301
+ },
5302
+ browser: {
5303
+ child_process: false,
5304
+ fs: false,
5305
+ net: false,
5306
+ tls: false,
5307
+ crypto: false,
5308
+ os: false,
5309
+ path: false,
5310
+ stream: false,
5311
+ http: false,
5312
+ https: false,
5313
+ zlib: false,
5314
+ mongodb: false,
5315
+ pg: false,
5316
+ "pdf-parse": false,
5317
+ mammoth: false
5318
+ },
5319
+ files: [
5320
+ "dist",
5321
+ "src",
5322
+ ".env.example",
5323
+ "README.md",
5324
+ "FREE_TIER_ARCHITECTURE.md"
5325
+ ],
5326
+ scripts: {
5327
+ dev: "npx @tailwindcss/cli -i src/tailwind.css -o src/index.css && tsup src/index.ts src/handlers/index.ts src/server.ts --format cjs,esm --watch --tsconfig tsconfig.build.json --external react,react-dom,next,mongodb,pg,openai,@anthropic-ai/sdk,@pinecone-database/pinecone,axios,lucide-react,mammoth,pdf-parse,xlsx,react-markdown,remark-gfm,next-themes,langchain,@langchain/core,@langchain/openai,llamaindex --inject-style",
5328
+ build: "npm run build:pkg",
5329
+ "build:pkg": "npx @tailwindcss/cli -i src/tailwind.css -o src/index.css && tsup src/index.ts src/handlers/index.ts src/server.ts --format cjs,esm --dts --clean --no-splitting --tsconfig tsconfig.build.json --external react,react-dom,next,mongodb,pg,openai,@anthropic-ai/sdk,@pinecone-database/pinecone,axios,lucide-react,mammoth,pdf-parse,xlsx,react-markdown,remark-gfm,next-themes,langchain,@langchain/core,@langchain/openai,llamaindex --inject-style && npx @tailwindcss/cli -i src/tailwind.css -o dist/index.css",
5330
+ lint: "eslint",
5331
+ clean: "rm -rf dist"
5332
+ },
5333
+ peerDependencies: {
5334
+ next: ">=15.0.0",
5335
+ react: ">=18.0.0",
5336
+ "react-dom": ">=18.0.0"
5337
+ },
5338
+ peerDependenciesMeta: {
5339
+ next: {
5340
+ optional: true
5341
+ }
5342
+ },
5343
+ dependencies: {
5344
+ "@anthropic-ai/sdk": "^0.95.1",
5345
+ "@google/genai": "^0.8.0",
5346
+ "@google/generative-ai": "^0.24.1",
5347
+ "@pinecone-database/pinecone": "^7.2.0",
5348
+ "@types/papaparse": "^5.5.2",
5349
+ axios: "^1.15.0",
5350
+ "lucide-react": "^1.8.0",
5351
+ "next-themes": "^0.4.6",
5352
+ openai: "^6.34.0",
5353
+ papaparse: "^5.5.3",
5354
+ "react-is": "^18.3.1",
5355
+ "react-markdown": "^10.1.0",
5356
+ recharts: "^3.8.1",
5357
+ "remark-gfm": "^4.0.1",
5358
+ xlsx: "^0.18.5"
5359
+ },
5360
+ optionalDependencies: {
5361
+ "@langchain/core": "^1.1.42",
5362
+ "@langchain/openai": "^1.4.5",
5363
+ langchain: "^1.3.5",
5364
+ llamaindex: "^0.11.9",
5365
+ mammoth: "^1.8.0",
5366
+ mongodb: "^7.1.1",
5367
+ "pdf-parse": "^1.1.1",
5368
+ pg: "^8.20.0"
5369
+ },
5370
+ devDependencies: {
5371
+ "@tailwindcss/cli": "^4",
5372
+ "@tailwindcss/postcss": "^4",
5373
+ "@types/estree": "^1.0.9",
5374
+ "@types/node": "^20",
5375
+ "@types/pdf-parse": "^1.1.5",
5376
+ "@types/pg": "^8.20.0",
5377
+ "@types/react": "^19.2.14",
5378
+ "@types/react-dom": "^19.2.3",
5379
+ dotenv: "^17.4.2",
5380
+ eslint: "^9",
5381
+ "eslint-config-next": "16.2.4",
5382
+ next: "16.2.10",
5383
+ tailwindcss: "^4",
5384
+ tsup: "^8.5.1",
5385
+ typescript: "^5"
5386
+ }
5387
+ };
5388
+
5389
+ // src/version.ts
5390
+ var SDK_VERSION = package_default.version || "2.1.3";
5391
+
5223
5392
  // src/rag/DocumentChunker.ts
5224
5393
  var DocumentChunker = class {
5225
5394
  constructor(chunkSize = 1e3, chunkOverlap = 200, separators = ["\n# ", "\n## ", "\n### ", "\n#### ", "\n\n", "\n", " ", ""]) {
@@ -9503,6 +9672,7 @@ ${context}`;
9503
9672
  const telemetryUrl = ((_B = this.config.telemetry) == null ? void 0 : _B.url) || process.env.TELEMETRY_URL || process.env.NEXT_PUBLIC_TELEMETRY_URL || defaultUrl;
9504
9673
  const absoluteUrl = telemetryUrl.startsWith("http") ? telemetryUrl : (process.env.NEXT_PUBLIC_APP_URL || `http://localhost:${process.env.PORT || 3e3}`) + telemetryUrl;
9505
9674
  (async () => {
9675
+ var _a3, _b2, _c2, _d2, _e2;
9506
9676
  try {
9507
9677
  let finalTrace = trace;
9508
9678
  if (!awaitHallucination && runHallucination) {
@@ -9511,6 +9681,12 @@ ${context}`;
9511
9681
  finalTrace = buildTrace(backgroundScoreResult);
9512
9682
  }
9513
9683
  }
9684
+ const modelName = (finalTrace == null ? void 0 : finalTrace.model) || ((_a3 = this.config.llm) == null ? void 0 : _a3.model) || "llama-3.1-8b-instant";
9685
+ const providerName = (finalTrace == null ? void 0 : finalTrace.provider) || ((_b2 = this.config.llm) == null ? void 0 : _b2.provider) || "groq";
9686
+ const tokenCount = Number(((_c2 = finalTrace == null ? void 0 : finalTrace.tokens) == null ? void 0 : _c2.totalTokens) || 0);
9687
+ const costEst = Number(((_d2 = finalTrace == null ? void 0 : finalTrace.tokens) == null ? void 0 : _d2.estimatedCostUsd) || 0);
9688
+ const latencyDuration = Number(((_e2 = finalTrace == null ? void 0 : finalTrace.latency) == null ? void 0 : _e2.totalMs) || 0);
9689
+ console.log(`[Retrivora Pipeline Telemetry] \u{1F4CA} Dispatching RAG telemetry -> Project: "${ns}", Model: "${providerName}/${modelName}", Tokens: ${tokenCount}, Latency: ${latencyDuration}ms`);
9514
9690
  await fetch(absoluteUrl, {
9515
9691
  method: "POST",
9516
9692
  headers: {
@@ -9519,7 +9695,20 @@ ${context}`;
9519
9695
  body: JSON.stringify({
9520
9696
  trace: finalTrace,
9521
9697
  licenseKey: this.config.licenseKey,
9522
- projectId: ns
9698
+ projectId: ns,
9699
+ organization: process.env.RETRIVORA_ORGANIZATION || "default-org",
9700
+ sdkVersion: SDK_VERSION,
9701
+ model: modelName,
9702
+ provider: providerName,
9703
+ tokens: tokenCount,
9704
+ cost: costEst,
9705
+ costUsd: costEst,
9706
+ latencyMs: latencyDuration,
9707
+ status: "success",
9708
+ action: "RAG_QUERY",
9709
+ feature: "RAG",
9710
+ timestamp: (/* @__PURE__ */ new Date()).toISOString(),
9711
+ details: `Org: default-org | Model: ${providerName}/${modelName} | Tokens: ${tokenCount} | Latency: ${latencyDuration}ms | Cost: $${costEst} | SDK: v${SDK_VERSION} | Feature: RAG`
9523
9712
  })
9524
9713
  });
9525
9714
  } catch (err) {
@@ -10915,7 +11104,7 @@ function getOrCreatePlugin(configOrPlugin) {
10915
11104
  return _g[cacheKey];
10916
11105
  }
10917
11106
  function reportTelemetry(req, plugin, action, status, details, trace) {
10918
- var _a2;
11107
+ var _a2, _b, _c, _d, _e, _f, _g2, _h;
10919
11108
  try {
10920
11109
  const config = plugin.getConfig();
10921
11110
  const licenseKey = config.licenseKey || process.env.RAG_LICENSE_KEY || process.env.RETRIVORA_LICENSE_KEY || process.env.NEXT_PUBLIC_RETRIVORA_LICENSE_KEY;
@@ -10924,29 +11113,49 @@ function reportTelemetry(req, plugin, action, status, details, trace) {
10924
11113
  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";
10925
11114
  const telemetryUrl = (telemetryConfig == null ? void 0 : telemetryConfig.url) || process.env.TELEMETRY_URL || process.env.NEXT_PUBLIC_TELEMETRY_URL || defaultUrl;
10926
11115
  const host = req.headers.get("host") || "localhost";
11116
+ const userAgent = req.headers.get("user-agent") || `Retrivora-SDK/${SDK_VERSION}`;
10927
11117
  let absoluteUrl = telemetryUrl;
10928
11118
  if (!telemetryUrl.startsWith("http")) {
10929
11119
  const proto = req.headers.get("x-forwarded-proto") || "http";
10930
11120
  absoluteUrl = `${proto}://${host}${telemetryUrl}`;
10931
11121
  }
10932
11122
  const projectId = config.projectId || "default";
11123
+ const model = (trace == null ? void 0 : trace.model) || ((_b = config.llm) == null ? void 0 : _b.model) || ((_c = config.embedding) == null ? void 0 : _c.model) || "llama-3.1-8b-instant";
11124
+ const provider = (trace == null ? void 0 : trace.provider) || ((_d = config.llm) == null ? void 0 : _d.provider) || ((_e = config.embedding) == null ? void 0 : _e.provider) || "groq";
11125
+ const tokens = Number(((_f = trace == null ? void 0 : trace.tokens) == null ? void 0 : _f.totalTokens) || (trace == null ? void 0 : trace.totalTokens) || 0);
11126
+ const costUsd = Number(((_g2 = trace == null ? void 0 : trace.tokens) == null ? void 0 : _g2.estimatedCostUsd) || (trace == null ? void 0 : trace.costUsd) || 0);
11127
+ const latencyMs = Number(((_h = trace == null ? void 0 : trace.latency) == null ? void 0 : _h.totalMs) || (trace == null ? void 0 : trace.latencyMs) || 0);
11128
+ const payload = {
11129
+ trace,
11130
+ licenseKey,
11131
+ projectId,
11132
+ organization: process.env.RETRIVORA_ORGANIZATION || "default-org",
11133
+ sdkVersion: SDK_VERSION,
11134
+ model,
11135
+ provider,
11136
+ tokens,
11137
+ cost: costUsd,
11138
+ costUsd,
11139
+ latencyMs,
11140
+ status,
11141
+ action,
11142
+ feature: action,
11143
+ userAgent,
11144
+ timestamp: (/* @__PURE__ */ new Date()).toISOString(),
11145
+ details
11146
+ };
11147
+ console.log(`[Retrivora SDK Telemetry] \u{1F4CA} Dispatching telemetry -> Feature: "${action}", Status: "${status}", Project: "${projectId}", Model: "${provider}/${model}", Latency: ${latencyMs}ms`);
10933
11148
  fetch(absoluteUrl, {
10934
11149
  method: "POST",
10935
11150
  headers: {
10936
11151
  "Content-Type": "application/json",
10937
11152
  "x-forwarded-for": req.headers.get("x-forwarded-for") || "",
10938
- "x-real-ip": req.headers.get("x-real-ip") || ""
11153
+ "x-real-ip": req.headers.get("x-real-ip") || "",
11154
+ "user-agent": userAgent
10939
11155
  },
10940
- body: JSON.stringify({
10941
- trace,
10942
- licenseKey,
10943
- projectId,
10944
- action,
10945
- status,
10946
- details
10947
- })
11156
+ body: JSON.stringify(payload)
10948
11157
  }).catch((err) => {
10949
- console.warn("[Retrivora Telemetry] Async report warning:", err.message);
11158
+ console.warn("[Retrivora SDK Telemetry] Async report warning:", err.message);
10950
11159
  });
10951
11160
  } catch (e) {
10952
11161
  }
@@ -11600,6 +11809,7 @@ export {
11600
11809
  Rule6SmallResultSetRule,
11601
11810
  Rule7LargeTableRule,
11602
11811
  RuleEngine,
11812
+ SDK_VERSION,
11603
11813
  TableRendererStrategy,
11604
11814
  TextRendererStrategy,
11605
11815
  UniversalLLMAdapter,
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@retrivora-ai/rag-engine",
3
- "version": "2.1.2",
3
+ "version": "2.1.4",
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",