@retrivora-ai/rag-engine 2.1.3 → 2.1.5

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.
@@ -375,6 +375,8 @@ interface ObservabilityTrace {
375
375
  chunks: RetrievedChunk[];
376
376
  latency: LatencyBreakdown;
377
377
  tokens?: TokenUsage;
378
+ model?: string;
379
+ provider?: string;
378
380
  /** 0 = fully grounded, 1 = likely hallucinated. */
379
381
  hallucinationScore?: number;
380
382
  hallucinationReason?: string;
@@ -375,6 +375,8 @@ interface ObservabilityTrace {
375
375
  chunks: RetrievedChunk[];
376
376
  latency: LatencyBreakdown;
377
377
  tokens?: TokenUsage;
378
+ model?: string;
379
+ provider?: string;
378
380
  /** 0 = fully grounded, 1 = likely hallucinated. */
379
381
  hallucinationScore?: number;
380
382
  hallucinationReason?: string;
@@ -1,3 +1,3 @@
1
1
  import 'next/server';
2
- export { o as HandlerOptions, c as createChatHandler, d as createFeedbackHandler, e as createHealthHandler, f as createHistoryHandler, g as createIngestHandler, h as createRagHandler, i as createSessionsHandler, j as createStreamHandler, p as createSuggestionsHandler, k as createUploadHandler, s as sseErrorFrame, l as sseFrame, m as sseMetaFrame, q as sseObservabilityFrame, n as sseTextFrame, r as sseUIFrame } from '../index-BvODr57d.mjs';
3
- import '../ILLMProvider-0rRBYbVW.mjs';
2
+ export { o as HandlerOptions, c as createChatHandler, d as createFeedbackHandler, e as createHealthHandler, f as createHistoryHandler, g as createIngestHandler, h as createRagHandler, i as createSessionsHandler, j as createStreamHandler, p as createSuggestionsHandler, k as createUploadHandler, s as sseErrorFrame, l as sseFrame, m as sseMetaFrame, q as sseObservabilityFrame, n as sseTextFrame, r as sseUIFrame } from '../index-DFc_Ll9z.mjs';
3
+ import '../ILLMProvider-BWa68XX5.mjs';
@@ -1,3 +1,3 @@
1
1
  import 'next/server';
2
- export { o as HandlerOptions, c as createChatHandler, d as createFeedbackHandler, e as createHealthHandler, f as createHistoryHandler, g as createIngestHandler, h as createRagHandler, i as createSessionsHandler, j as createStreamHandler, p as createSuggestionsHandler, k as createUploadHandler, s as sseErrorFrame, l as sseFrame, m as sseMetaFrame, q as sseObservabilityFrame, n as sseTextFrame, r as sseUIFrame } from '../index-BIHHp_f6.js';
3
- import '../ILLMProvider-0rRBYbVW.js';
2
+ export { o as HandlerOptions, c as createChatHandler, d as createFeedbackHandler, e as createHealthHandler, f as createHistoryHandler, g as createIngestHandler, h as createRagHandler, i as createSessionsHandler, j as createStreamHandler, p as createSuggestionsHandler, k as createUploadHandler, s as sseErrorFrame, l as sseFrame, m as sseMetaFrame, q as sseObservabilityFrame, n as sseTextFrame, r as sseUIFrame } from '../index-C6ehmP0b.js';
3
+ import '../ILLMProvider-BWa68XX5.js';
@@ -3080,7 +3080,7 @@ function readEnum(env, name, fallback, allowed) {
3080
3080
  throw new Error(`[getRagConfig] ${name} must be one of: ${allowed.join(", ")}`);
3081
3081
  }
3082
3082
  function getEnvConfig(env = process.env, base) {
3083
- 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;
3083
+ 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;
3084
3084
  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__";
3085
3085
  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;
3086
3086
  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);
@@ -3088,38 +3088,38 @@ function getEnvConfig(env = process.env, base) {
3088
3088
  const embeddingDimensions = readNumber(env, "EMBEDDING_DIMENSIONS", 768);
3089
3089
  const vectorDbOptions = {};
3090
3090
  if (vectorProvider === "pinecone") {
3091
- 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 : "";
3092
- 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;
3091
+ 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 : "";
3092
+ 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";
3093
3093
  } else if (vectorProvider === "pgvector" || vectorProvider === "postgresql") {
3094
- 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 : "";
3095
- 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;
3096
- 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;
3094
+ 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 : "";
3095
+ 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;
3096
+ 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;
3097
3097
  vectorDbOptions.dimensions = embeddingDimensions;
3098
3098
  } else if (vectorProvider === "mongodb") {
3099
- 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 : "";
3100
- 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 : "";
3101
- 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 : "";
3102
- 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";
3099
+ 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 : "";
3100
+ 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 : "";
3101
+ 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 : "";
3102
+ 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";
3103
3103
  } else if (vectorProvider === "qdrant") {
3104
- 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";
3105
- 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;
3104
+ 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";
3105
+ 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;
3106
3106
  vectorDbOptions.dimensions = embeddingDimensions;
3107
3107
  } else if (vectorProvider === "milvus") {
3108
- vectorDbOptions.baseUrl = (_ca = readString(env, "MILVUS_URL")) != null ? _ca : "http://localhost:19530";
3108
+ vectorDbOptions.baseUrl = (_fa = readString(env, "MILVUS_URL")) != null ? _fa : "http://localhost:19530";
3109
3109
  vectorDbOptions.apiKey = readString(env, "MILVUS_API_KEY");
3110
3110
  } else if (vectorProvider === "chromadb") {
3111
- vectorDbOptions.baseUrl = (_da = readString(env, "CHROMADB_URL")) != null ? _da : "http://localhost:8000";
3111
+ vectorDbOptions.baseUrl = (_ga = readString(env, "CHROMADB_URL")) != null ? _ga : "http://localhost:8000";
3112
3112
  } else if (vectorProvider === "weaviate") {
3113
- vectorDbOptions.baseUrl = (_ea = readString(env, "WEAVIATE_URL")) != null ? _ea : "http://localhost:8080";
3113
+ vectorDbOptions.baseUrl = (_ha = readString(env, "WEAVIATE_URL")) != null ? _ha : "http://localhost:8080";
3114
3114
  vectorDbOptions.apiKey = readString(env, "WEAVIATE_API_KEY");
3115
3115
  } else if (vectorProvider === "redis") {
3116
- vectorDbOptions.baseUrl = (_fa = readString(env, "REDIS_URL")) != null ? _fa : "";
3116
+ vectorDbOptions.baseUrl = (_ia = readString(env, "REDIS_URL")) != null ? _ia : "";
3117
3117
  vectorDbOptions.apiKey = readString(env, "REDIS_API_KEY");
3118
3118
  } else if (vectorProvider === "rest") {
3119
- vectorDbOptions.baseUrl = (_ga = readString(env, "VECTOR_DB_REST_URL")) != null ? _ga : "";
3119
+ vectorDbOptions.baseUrl = (_ja = readString(env, "VECTOR_DB_REST_URL")) != null ? _ja : "";
3120
3120
  vectorDbOptions.headers = readString(env, "VECTOR_DB_REST_API_KEY") ? { "api-key": readString(env, "VECTOR_DB_REST_API_KEY") } : {};
3121
3121
  } else if (vectorProvider === "universal_rest") {
3122
- vectorDbOptions.baseUrl = (_ia = (_ha = readString(env, "VECTOR_BASE_URL")) != null ? _ha : readString(env, "VECTOR_DB_REST_URL")) != null ? _ia : "";
3122
+ vectorDbOptions.baseUrl = (_la = (_ka = readString(env, "VECTOR_BASE_URL")) != null ? _ka : readString(env, "VECTOR_DB_REST_URL")) != null ? _la : "";
3123
3123
  vectorDbOptions.profile = readString(env, "VECTOR_UNIVERSAL_PROFILE");
3124
3124
  vectorDbOptions.headers = readString(env, "VECTOR_DB_REST_API_KEY") ? { Authorization: `Bearer ${readString(env, "VECTOR_DB_REST_API_KEY")}` } : {};
3125
3125
  }
@@ -3138,8 +3138,8 @@ function getEnvConfig(env = process.env, base) {
3138
3138
  // Anthropic needs a separate embedding provider; key kept for completeness
3139
3139
  gemini: readString(env, "GEMINI_API_KEY"),
3140
3140
  ollama: void 0,
3141
- universal_rest: (_ja = readString(env, "EMBEDDING_API_KEY")) != null ? _ja : readString(env, "OPENAI_API_KEY"),
3142
- custom: (_ka = readString(env, "EMBEDDING_API_KEY")) != null ? _ka : readString(env, "OPENAI_API_KEY")
3141
+ universal_rest: (_ma = readString(env, "EMBEDDING_API_KEY")) != null ? _ma : readString(env, "OPENAI_API_KEY"),
3142
+ custom: (_na = readString(env, "EMBEDDING_API_KEY")) != null ? _na : readString(env, "OPENAI_API_KEY")
3143
3143
  };
3144
3144
  const DEFAULT_MODEL_BY_PROVIDER = {
3145
3145
  openai: "gpt-4o",
@@ -3160,25 +3160,25 @@ function getEnvConfig(env = process.env, base) {
3160
3160
  return true;
3161
3161
  }
3162
3162
  })();
3163
- const defaultGatewayUrl = (_ma = (_la = readString(env, "LITELLM_BASE_URL")) != null ? _la : readString(env, "LLM_BASE_URL")) != null ? _ma : "https://llm.retrivora.com/api/v1";
3163
+ const defaultGatewayUrl = (_pa = (_oa = readString(env, "LITELLM_BASE_URL")) != null ? _oa : readString(env, "LLM_BASE_URL")) != null ? _pa : "https://llm.retrivora.com/api/v1";
3164
3164
  const defaultLlmProvider = isFreeTier ? "universal_rest" : "universal_rest";
3165
- const llmProvider = (_pa = (_oa = readEnum(env, "LLM_PROVIDER", defaultLlmProvider, LLM_PROVIDERS)) != null ? _oa : (_na = base == null ? void 0 : base.llm) == null ? void 0 : _na.provider) != null ? _pa : defaultLlmProvider;
3166
- const llmBaseUrl = (_ta = (_sa = (_qa = readString(env, "LITELLM_BASE_URL")) != null ? _qa : readString(env, "LLM_BASE_URL")) != null ? _sa : (_ra = base == null ? void 0 : base.llm) == null ? void 0 : _ra.baseUrl) != null ? _ta : defaultGatewayUrl;
3167
- const llmModel = (_xa = (_va = readString(env, "LLM_MODEL")) != null ? _va : (_ua = base == null ? void 0 : base.llm) == null ? void 0 : _ua.model) != null ? _xa : isFreeTier ? "llama-3.1-8b-instant" : (_wa = DEFAULT_MODEL_BY_PROVIDER[llmProvider]) != null ? _wa : "gpt-4o";
3168
- const llmApiKey = (_Da = (_Ca = (_Aa = (_za = (_ya = llmApiKeyByProvider[llmProvider]) != null ? _ya : readString(env, "LLM_API_KEY")) != null ? _za : readString(env, "LITELLM_MASTER_KEY")) != null ? _Aa : readString(env, "LITELLM_API_KEY")) != null ? _Ca : (_Ba = base == null ? void 0 : base.llm) == null ? void 0 : _Ba.apiKey) != null ? _Da : licenseKey;
3169
- const llmProfile = (_Ha = (_Ga = readString(env, "LLM_UNIVERSAL_PROFILE")) != null ? _Ga : (_Fa = (_Ea = base == null ? void 0 : base.llm) == null ? void 0 : _Ea.options) == null ? void 0 : _Fa.profile) != null ? _Ha : "litellm";
3165
+ 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;
3166
+ 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;
3167
+ 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";
3168
+ 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;
3169
+ 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";
3170
3170
  const defaultEmbeddingProvider = isFreeTier ? "universal_rest" : "universal_rest";
3171
- const embeddingProvider = (_Ka = (_Ja = readEnum(env, "EMBEDDING_PROVIDER", defaultEmbeddingProvider, EMBEDDING_PROVIDERS)) != null ? _Ja : (_Ia = base == null ? void 0 : base.embedding) == null ? void 0 : _Ia.provider) != null ? _Ka : defaultEmbeddingProvider;
3172
- const embeddingBaseUrl = (_Pa = (_Oa = (_Ma = (_La = readString(env, "LITELLM_BASE_URL")) != null ? _La : readString(env, "EMBEDDING_BASE_URL")) != null ? _Ma : readString(env, "LLM_BASE_URL")) != null ? _Oa : (_Na = base == null ? void 0 : base.embedding) == null ? void 0 : _Na.baseUrl) != null ? _Pa : defaultGatewayUrl;
3173
- const embeddingModel = (_Sa = (_Ra = readString(env, "EMBEDDING_MODEL")) != null ? _Ra : (_Qa = base == null ? void 0 : base.embedding) == null ? void 0 : _Qa.model) != null ? _Sa : "text-embedding-004";
3174
- const embeddingApiKey = (_Za = (_Ya = (_Wa = (_Va = (_Ua = (_Ta = embeddingApiKeyByProvider[embeddingProvider]) != null ? _Ta : readString(env, "EMBEDDING_API_KEY")) != null ? _Ua : readString(env, "LLM_API_KEY")) != null ? _Va : readString(env, "LITELLM_MASTER_KEY")) != null ? _Wa : readString(env, "LITELLM_API_KEY")) != null ? _Ya : (_Xa = base == null ? void 0 : base.embedding) == null ? void 0 : _Xa.apiKey) != null ? _Za : licenseKey;
3175
- const embeddingProfile = (_bb = (_ab = readString(env, "EMBEDDING_UNIVERSAL_PROFILE")) != null ? _ab : (_$a = (__a = base == null ? void 0 : base.embedding) == null ? void 0 : __a.options) == null ? void 0 : _$a.profile) != null ? _bb : "litellm";
3171
+ 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;
3172
+ 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;
3173
+ 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";
3174
+ 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;
3175
+ 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";
3176
3176
  return __spreadProps(__spreadValues({
3177
3177
  projectId,
3178
3178
  licenseKey,
3179
3179
  vectorDb: {
3180
3180
  provider: vectorProvider,
3181
- indexName: (_db = (_cb = readString(env, "VECTOR_DB_INDEX")) != null ? _cb : vectorDbOptions.indexName) != null ? _db : "rag-index",
3181
+ indexName: (_gb = (_fb = readString(env, "VECTOR_DB_INDEX")) != null ? _fb : vectorDbOptions.indexName) != null ? _gb : "rag-index",
3182
3182
  options: vectorDbOptions
3183
3183
  },
3184
3184
  llm: {
@@ -3208,30 +3208,30 @@ function getEnvConfig(env = process.env, base) {
3208
3208
  }
3209
3209
  },
3210
3210
  ui: {
3211
- title: (_fb = (_eb = readString(env, "NEXT_PUBLIC_UI_TITLE")) != null ? _eb : readString(env, "UI_TITLE")) != null ? _fb : "AI Assistant",
3212
- subtitle: (_hb = (_gb = readString(env, "NEXT_PUBLIC_UI_SUBTITLE")) != null ? _gb : readString(env, "UI_SUBTITLE")) != null ? _hb : "Powered by RAG",
3213
- primaryColor: (_jb = (_ib = readString(env, "NEXT_PUBLIC_PRIMARY_COLOR")) != null ? _ib : readString(env, "UI_PRIMARY_COLOR")) != null ? _jb : "#10b981",
3214
- accentColor: (_lb = (_kb = readString(env, "NEXT_PUBLIC_ACCENT_COLOR")) != null ? _kb : readString(env, "UI_ACCENT_COLOR")) != null ? _lb : "#3b82f6",
3215
- logoUrl: (_mb = readString(env, "NEXT_PUBLIC_LOGO_URL")) != null ? _mb : readString(env, "UI_LOGO_URL"),
3216
- placeholder: (_ob = (_nb = readString(env, "NEXT_PUBLIC_PLACEHOLDER")) != null ? _nb : readString(env, "UI_PLACEHOLDER")) != null ? _ob : "Ask me anything\u2026",
3217
- showSources: ((_qb = (_pb = readString(env, "NEXT_PUBLIC_SHOW_SOURCES")) != null ? _pb : readString(env, "UI_SHOW_SOURCES")) != null ? _qb : "true") !== "false",
3218
- welcomeMessage: (_sb = (_rb = readString(env, "NEXT_PUBLIC_WELCOME_MESSAGE")) != null ? _rb : readString(env, "UI_WELCOME_MESSAGE")) != null ? _sb : "Hello! I'm your AI assistant. Ask me anything about your documents.",
3219
- visualStyle: (_ub = (_tb = readString(env, "NEXT_PUBLIC_UI_VISUAL_STYLE")) != null ? _tb : readString(env, "UI_VISUAL_STYLE")) != null ? _ub : "glass",
3220
- borderRadius: (_wb = (_vb = readString(env, "NEXT_PUBLIC_UI_BORDER_RADIUS")) != null ? _vb : readString(env, "UI_BORDER_RADIUS")) != null ? _wb : "xl",
3221
- allowUpload: ((_yb = (_xb = readString(env, "NEXT_PUBLIC_ALLOW_UPLOAD")) != null ? _xb : readString(env, "UI_ALLOW_UPLOAD")) != null ? _yb : "false") === "true"
3211
+ title: (_ib = (_hb = readString(env, "NEXT_PUBLIC_UI_TITLE")) != null ? _hb : readString(env, "UI_TITLE")) != null ? _ib : "AI Assistant",
3212
+ subtitle: (_kb = (_jb = readString(env, "NEXT_PUBLIC_UI_SUBTITLE")) != null ? _jb : readString(env, "UI_SUBTITLE")) != null ? _kb : "Powered by RAG",
3213
+ primaryColor: (_mb = (_lb = readString(env, "NEXT_PUBLIC_PRIMARY_COLOR")) != null ? _lb : readString(env, "UI_PRIMARY_COLOR")) != null ? _mb : "#10b981",
3214
+ accentColor: (_ob = (_nb = readString(env, "NEXT_PUBLIC_ACCENT_COLOR")) != null ? _nb : readString(env, "UI_ACCENT_COLOR")) != null ? _ob : "#3b82f6",
3215
+ logoUrl: (_pb = readString(env, "NEXT_PUBLIC_LOGO_URL")) != null ? _pb : readString(env, "UI_LOGO_URL"),
3216
+ placeholder: (_rb = (_qb = readString(env, "NEXT_PUBLIC_PLACEHOLDER")) != null ? _qb : readString(env, "UI_PLACEHOLDER")) != null ? _rb : "Ask me anything\u2026",
3217
+ showSources: ((_tb = (_sb = readString(env, "NEXT_PUBLIC_SHOW_SOURCES")) != null ? _sb : readString(env, "UI_SHOW_SOURCES")) != null ? _tb : "true") !== "false",
3218
+ 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.",
3219
+ visualStyle: (_xb = (_wb = readString(env, "NEXT_PUBLIC_UI_VISUAL_STYLE")) != null ? _wb : readString(env, "UI_VISUAL_STYLE")) != null ? _xb : "glass",
3220
+ borderRadius: (_zb = (_yb = readString(env, "NEXT_PUBLIC_UI_BORDER_RADIUS")) != null ? _yb : readString(env, "UI_BORDER_RADIUS")) != null ? _zb : "xl",
3221
+ allowUpload: ((_Bb = (_Ab = readString(env, "NEXT_PUBLIC_ALLOW_UPLOAD")) != null ? _Ab : readString(env, "UI_ALLOW_UPLOAD")) != null ? _Bb : "false") === "true"
3222
3222
  },
3223
3223
  rag: {
3224
3224
  topK: readNumber(env, "RAG_TOP_K", 5),
3225
3225
  scoreThreshold: readNumber(env, "RAG_SCORE_THRESHOLD", 0),
3226
3226
  chunkSize: readNumber(env, "RAG_CHUNK_SIZE", 1e3),
3227
3227
  chunkOverlap: readNumber(env, "RAG_CHUNK_OVERLAP", 200),
3228
- filterableFields: (_zb = readString(env, "RAG_FILTERABLE_FIELDS")) == null ? void 0 : _zb.split(",").map((f) => f.trim()),
3228
+ filterableFields: (_Cb = readString(env, "RAG_FILTERABLE_FIELDS")) == null ? void 0 : _Cb.split(",").map((f) => f.trim()),
3229
3229
  // Query pipeline toggles — read from .env.local
3230
3230
  useQueryTransformation: readString(env, "RAG_USE_QUERY_TRANSFORMATION") === "true",
3231
3231
  useReranking: readString(env, "RAG_USE_RERANKING") === "true",
3232
3232
  useGraphRetrieval: readString(env, "RAG_USE_GRAPH_RETRIEVAL") === "true",
3233
- architecture: (_Ab = readString(env, "RAG_ARCHITECTURE")) != null ? _Ab : "simple",
3234
- chunkingStrategy: (_Bb = readString(env, "RAG_CHUNKING_STRATEGY")) != null ? _Bb : "recursive",
3233
+ architecture: (_Db = readString(env, "RAG_ARCHITECTURE")) != null ? _Db : "simple",
3234
+ chunkingStrategy: (_Eb = readString(env, "RAG_CHUNKING_STRATEGY")) != null ? _Eb : "recursive",
3235
3235
  uiMapping: (() => {
3236
3236
  const raw = readString(env, "RAG_UI_MAPPING");
3237
3237
  if (!raw) return void 0;
@@ -3244,7 +3244,7 @@ function getEnvConfig(env = process.env, base) {
3244
3244
  },
3245
3245
  telemetry: {
3246
3246
  enabled: telemetryEnabled,
3247
- url: (_Fb = (_Eb = (_Cb = readString(env, "TELEMETRY_URL")) != null ? _Cb : readString(env, "NEXT_PUBLIC_TELEMETRY_URL")) != null ? _Eb : (_Db = base == null ? void 0 : base.telemetry) == null ? void 0 : _Db.url) != null ? _Fb : process.env.NODE_ENV === "development" ? "http://localhost:3001/api/telemetry" : "https://retrivora.com/api/telemetry"
3247
+ 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"
3248
3248
  }
3249
3249
  }, readString(env, "GRAPH_DB_PROVIDER") ? {
3250
3250
  graphDb: {
@@ -5244,6 +5244,147 @@ var ConfigValidator = class {
5244
5244
  }
5245
5245
  };
5246
5246
 
5247
+ // package.json
5248
+ var package_default = {
5249
+ name: "@retrivora-ai/rag-engine",
5250
+ version: "2.1.5",
5251
+ description: "Retrivora AI is a plug-and-play AI engine for RAG chat experiences \u2014 generic vector DB + LLM provider, embeddable or standalone.",
5252
+ author: "Abhinav Alkuchi",
5253
+ license: "UNLICENSED",
5254
+ keywords: [
5255
+ "rag",
5256
+ "retrieval-augmented-generation",
5257
+ "chatbot",
5258
+ "vector-database",
5259
+ "pinecone",
5260
+ "pgvector",
5261
+ "postgresql",
5262
+ "milvus",
5263
+ "qdrant",
5264
+ "chromadb",
5265
+ "redis",
5266
+ "weaviate",
5267
+ "mongodb",
5268
+ "openai",
5269
+ "anthropic",
5270
+ "ollama",
5271
+ "nextjs",
5272
+ "react",
5273
+ "ai",
5274
+ "llm",
5275
+ "embeddings"
5276
+ ],
5277
+ main: "dist/index.js",
5278
+ module: "dist/index.mjs",
5279
+ types: "dist/index.d.ts",
5280
+ exports: {
5281
+ ".": {
5282
+ types: "./dist/index.d.ts",
5283
+ require: "./dist/index.js",
5284
+ import: "./dist/index.mjs"
5285
+ },
5286
+ "./style.css": "./dist/index.css",
5287
+ "./handlers": {
5288
+ types: "./dist/handlers/index.d.ts",
5289
+ require: "./dist/handlers/index.js",
5290
+ import: "./dist/handlers/index.mjs"
5291
+ },
5292
+ "./server": {
5293
+ types: "./dist/server.d.ts",
5294
+ require: "./dist/server.js",
5295
+ import: "./dist/server.mjs"
5296
+ }
5297
+ },
5298
+ browser: {
5299
+ child_process: false,
5300
+ fs: false,
5301
+ net: false,
5302
+ tls: false,
5303
+ crypto: false,
5304
+ os: false,
5305
+ path: false,
5306
+ stream: false,
5307
+ http: false,
5308
+ https: false,
5309
+ zlib: false,
5310
+ mongodb: false,
5311
+ pg: false,
5312
+ "pdf-parse": false,
5313
+ mammoth: false
5314
+ },
5315
+ files: [
5316
+ "dist",
5317
+ "src",
5318
+ ".env.example",
5319
+ "README.md",
5320
+ "FREE_TIER_ARCHITECTURE.md"
5321
+ ],
5322
+ scripts: {
5323
+ 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",
5324
+ build: "npm run build:pkg",
5325
+ "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",
5326
+ lint: "eslint",
5327
+ clean: "rm -rf dist"
5328
+ },
5329
+ peerDependencies: {
5330
+ next: ">=15.0.0",
5331
+ react: ">=18.0.0",
5332
+ "react-dom": ">=18.0.0"
5333
+ },
5334
+ peerDependenciesMeta: {
5335
+ next: {
5336
+ optional: true
5337
+ }
5338
+ },
5339
+ dependencies: {
5340
+ "@anthropic-ai/sdk": "^0.95.1",
5341
+ "@google/genai": "^0.8.0",
5342
+ "@google/generative-ai": "^0.24.1",
5343
+ "@pinecone-database/pinecone": "^7.2.0",
5344
+ "@types/papaparse": "^5.5.2",
5345
+ axios: "^1.15.0",
5346
+ "lucide-react": "^1.8.0",
5347
+ "next-themes": "^0.4.6",
5348
+ openai: "^6.34.0",
5349
+ papaparse: "^5.5.3",
5350
+ "react-is": "^18.3.1",
5351
+ "react-markdown": "^10.1.0",
5352
+ recharts: "^3.8.1",
5353
+ "remark-gfm": "^4.0.1",
5354
+ xlsx: "^0.18.5"
5355
+ },
5356
+ optionalDependencies: {
5357
+ "@langchain/core": "^1.1.42",
5358
+ "@langchain/openai": "^1.4.5",
5359
+ langchain: "^1.3.5",
5360
+ llamaindex: "^0.11.9",
5361
+ mammoth: "^1.8.0",
5362
+ mongodb: "^7.1.1",
5363
+ "pdf-parse": "^1.1.1",
5364
+ pg: "^8.20.0"
5365
+ },
5366
+ devDependencies: {
5367
+ "@tailwindcss/cli": "^4",
5368
+ "@tailwindcss/postcss": "^4",
5369
+ "@types/estree": "^1.0.9",
5370
+ "@types/node": "^20",
5371
+ "@types/pdf-parse": "^1.1.5",
5372
+ "@types/pg": "^8.20.0",
5373
+ "@types/react": "^19.2.14",
5374
+ "@types/react-dom": "^19.2.3",
5375
+ dotenv: "^17.4.2",
5376
+ eslint: "^9",
5377
+ "eslint-config-next": "16.2.4",
5378
+ next: "16.2.10",
5379
+ tailwindcss: "^4",
5380
+ tsup: "^8.5.1",
5381
+ typescript: "^5"
5382
+ }
5383
+ };
5384
+
5385
+ // src/version.ts
5386
+ var SDK_VERSION = package_default.version || "2.1.3";
5387
+
5247
5388
  // src/rag/DocumentChunker.ts
5248
5389
  var DocumentChunker = class {
5249
5390
  constructor(chunkSize = 1e3, chunkOverlap = 200, separators = ["\n# ", "\n## ", "\n### ", "\n#### ", "\n\n", "\n", " ", ""]) {
@@ -9513,6 +9654,7 @@ ${context}`;
9513
9654
  const telemetryUrl = ((_B = this.config.telemetry) == null ? void 0 : _B.url) || process.env.TELEMETRY_URL || process.env.NEXT_PUBLIC_TELEMETRY_URL || defaultUrl;
9514
9655
  const absoluteUrl = telemetryUrl.startsWith("http") ? telemetryUrl : (process.env.NEXT_PUBLIC_APP_URL || `http://localhost:${process.env.PORT || 3e3}`) + telemetryUrl;
9515
9656
  (async () => {
9657
+ var _a3, _b2, _c2, _d2, _e2;
9516
9658
  try {
9517
9659
  let finalTrace = trace;
9518
9660
  if (!awaitHallucination && runHallucination) {
@@ -9521,6 +9663,12 @@ ${context}`;
9521
9663
  finalTrace = buildTrace(backgroundScoreResult);
9522
9664
  }
9523
9665
  }
9666
+ const modelName = (finalTrace == null ? void 0 : finalTrace.model) || ((_a3 = this.config.llm) == null ? void 0 : _a3.model) || "llama-3.1-8b-instant";
9667
+ const providerName = (finalTrace == null ? void 0 : finalTrace.provider) || ((_b2 = this.config.llm) == null ? void 0 : _b2.provider) || "groq";
9668
+ const tokenCount = Number(((_c2 = finalTrace == null ? void 0 : finalTrace.tokens) == null ? void 0 : _c2.totalTokens) || 0);
9669
+ const costEst = Number(((_d2 = finalTrace == null ? void 0 : finalTrace.tokens) == null ? void 0 : _d2.estimatedCostUsd) || 0);
9670
+ const latencyDuration = Number(((_e2 = finalTrace == null ? void 0 : finalTrace.latency) == null ? void 0 : _e2.totalMs) || 0);
9671
+ console.log(`[Retrivora Pipeline Telemetry] \u{1F4CA} Dispatching RAG telemetry -> Project: "${ns}", Model: "${providerName}/${modelName}", Tokens: ${tokenCount}, Latency: ${latencyDuration}ms`);
9524
9672
  await fetch(absoluteUrl, {
9525
9673
  method: "POST",
9526
9674
  headers: {
@@ -9529,7 +9677,20 @@ ${context}`;
9529
9677
  body: JSON.stringify({
9530
9678
  trace: finalTrace,
9531
9679
  licenseKey: this.config.licenseKey,
9532
- projectId: ns
9680
+ projectId: ns,
9681
+ organization: process.env.RETRIVORA_ORGANIZATION || "default-org",
9682
+ sdkVersion: SDK_VERSION,
9683
+ model: modelName,
9684
+ provider: providerName,
9685
+ tokens: tokenCount,
9686
+ cost: costEst,
9687
+ costUsd: costEst,
9688
+ latencyMs: latencyDuration,
9689
+ status: "success",
9690
+ action: "RAG_QUERY",
9691
+ feature: "RAG",
9692
+ timestamp: (/* @__PURE__ */ new Date()).toISOString(),
9693
+ details: `Org: default-org | Model: ${providerName}/${modelName} | Tokens: ${tokenCount} | Latency: ${latencyDuration}ms | Cost: $${costEst} | SDK: v${SDK_VERSION} | Feature: RAG`
9533
9694
  })
9534
9695
  });
9535
9696
  } catch (err) {
@@ -10626,7 +10787,7 @@ function getOrCreatePlugin(configOrPlugin) {
10626
10787
  return _g[cacheKey];
10627
10788
  }
10628
10789
  function reportTelemetry(req, plugin, action, status, details, trace) {
10629
- var _a2;
10790
+ var _a2, _b, _c, _d, _e, _f, _g2, _h;
10630
10791
  try {
10631
10792
  const config = plugin.getConfig();
10632
10793
  const licenseKey = config.licenseKey || process.env.RAG_LICENSE_KEY || process.env.RETRIVORA_LICENSE_KEY || process.env.NEXT_PUBLIC_RETRIVORA_LICENSE_KEY;
@@ -10635,29 +10796,49 @@ function reportTelemetry(req, plugin, action, status, details, trace) {
10635
10796
  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";
10636
10797
  const telemetryUrl = (telemetryConfig == null ? void 0 : telemetryConfig.url) || process.env.TELEMETRY_URL || process.env.NEXT_PUBLIC_TELEMETRY_URL || defaultUrl;
10637
10798
  const host = req.headers.get("host") || "localhost";
10799
+ const userAgent = req.headers.get("user-agent") || `Retrivora-SDK/${SDK_VERSION}`;
10638
10800
  let absoluteUrl = telemetryUrl;
10639
10801
  if (!telemetryUrl.startsWith("http")) {
10640
10802
  const proto = req.headers.get("x-forwarded-proto") || "http";
10641
10803
  absoluteUrl = `${proto}://${host}${telemetryUrl}`;
10642
10804
  }
10643
10805
  const projectId = config.projectId || "default";
10806
+ 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";
10807
+ 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";
10808
+ const tokens = Number(((_f = trace == null ? void 0 : trace.tokens) == null ? void 0 : _f.totalTokens) || (trace == null ? void 0 : trace.totalTokens) || 0);
10809
+ const costUsd = Number(((_g2 = trace == null ? void 0 : trace.tokens) == null ? void 0 : _g2.estimatedCostUsd) || (trace == null ? void 0 : trace.costUsd) || 0);
10810
+ const latencyMs = Number(((_h = trace == null ? void 0 : trace.latency) == null ? void 0 : _h.totalMs) || (trace == null ? void 0 : trace.latencyMs) || 0);
10811
+ const payload = {
10812
+ trace,
10813
+ licenseKey,
10814
+ projectId,
10815
+ organization: process.env.RETRIVORA_ORGANIZATION || "default-org",
10816
+ sdkVersion: SDK_VERSION,
10817
+ model,
10818
+ provider,
10819
+ tokens,
10820
+ cost: costUsd,
10821
+ costUsd,
10822
+ latencyMs,
10823
+ status,
10824
+ action,
10825
+ feature: action,
10826
+ userAgent,
10827
+ timestamp: (/* @__PURE__ */ new Date()).toISOString(),
10828
+ details
10829
+ };
10830
+ console.log(`[Retrivora SDK Telemetry] \u{1F4CA} Dispatching telemetry -> Feature: "${action}", Status: "${status}", Project: "${projectId}", Model: "${provider}/${model}", Latency: ${latencyMs}ms`);
10644
10831
  fetch(absoluteUrl, {
10645
10832
  method: "POST",
10646
10833
  headers: {
10647
10834
  "Content-Type": "application/json",
10648
10835
  "x-forwarded-for": req.headers.get("x-forwarded-for") || "",
10649
- "x-real-ip": req.headers.get("x-real-ip") || ""
10836
+ "x-real-ip": req.headers.get("x-real-ip") || "",
10837
+ "user-agent": userAgent
10650
10838
  },
10651
- body: JSON.stringify({
10652
- trace,
10653
- licenseKey,
10654
- projectId,
10655
- action,
10656
- status,
10657
- details
10658
- })
10839
+ body: JSON.stringify(payload)
10659
10840
  }).catch((err) => {
10660
- console.warn("[Retrivora Telemetry] Async report warning:", err.message);
10841
+ console.warn("[Retrivora SDK Telemetry] Async report warning:", err.message);
10661
10842
  });
10662
10843
  } catch (e) {
10663
10844
  }
@@ -10760,12 +10941,19 @@ function createStreamHandler(configOrPlugin, options) {
10760
10941
  const storage = new DatabaseStorage(plugin.getConfig());
10761
10942
  const onAuthorize = options == null ? void 0 : options.onAuthorize;
10762
10943
  return async function POST(req) {
10944
+ var _a2;
10763
10945
  const authResult = await checkAuth(req, onAuthorize);
10764
10946
  if (authResult) return authResult;
10765
10947
  const rateLimited = checkRateLimit(req);
10766
10948
  if (rateLimited) return rateLimited;
10767
10949
  let body;
10768
10950
  try {
10951
+ if ((_a2 = req.headers.get("content-type")) == null ? void 0 : _a2.includes("multipart/form-data")) {
10952
+ return new Response(JSON.stringify({ error: { code: "INVALID_ENDPOINT", message: "Multipart file upload requests must be sent to the /upload endpoint." } }), {
10953
+ status: 400,
10954
+ headers: { "Content-Type": "application/json" }
10955
+ });
10956
+ }
10769
10957
  body = await req.json();
10770
10958
  } catch (e) {
10771
10959
  return new Response(JSON.stringify({ error: { code: "INVALID_JSON", message: "Invalid JSON body" } }), {
@@ -10803,7 +10991,7 @@ function createStreamHandler(configOrPlugin, options) {
10803
10991
  let isActive = true;
10804
10992
  const stream = new ReadableStream({
10805
10993
  async start(controller) {
10806
- var _a2, _b, _c, _d, _e;
10994
+ var _a3, _b, _c, _d, _e;
10807
10995
  const enqueue = (text) => {
10808
10996
  if (!isActive) return;
10809
10997
  try {
@@ -10836,7 +11024,7 @@ function createStreamHandler(configOrPlugin, options) {
10836
11024
  let uiTransformation = responseChunk == null ? void 0 : responseChunk.ui_transformation;
10837
11025
  if (sources.length > 0) {
10838
11026
  try {
10839
- uiTransformation = (_a2 = responseChunk == null ? void 0 : responseChunk.ui_transformation) != null ? _a2 : UITransformer.transform(message, sources, plugin.getConfig());
11027
+ uiTransformation = (_a3 = responseChunk == null ? void 0 : responseChunk.ui_transformation) != null ? _a3 : UITransformer.transform(message, sources, plugin.getConfig());
10840
11028
  if (uiTransformation) {
10841
11029
  enqueue(sseUIFrame(uiTransformation));
10842
11030
  }
@@ -11233,16 +11421,32 @@ function createRagHandler(configOrPlugin, options) {
11233
11421
  return import_server.NextResponse.json({ error: `Method Not Allowed: GET segment "${segment}" not supported.` }, { status: 405 });
11234
11422
  }
11235
11423
  }
11236
- async function getSegment(context) {
11237
- var _a2;
11424
+ async function getSegment(req, context) {
11425
+ var _a2, _b;
11426
+ const contentType = req.headers.get("content-type") || "";
11427
+ if (contentType.includes("multipart/form-data")) {
11428
+ return "upload";
11429
+ }
11430
+ try {
11431
+ const url = new URL(req.url);
11432
+ const pathname = url.pathname;
11433
+ if (pathname.endsWith("/upload")) return "upload";
11434
+ if (pathname.endsWith("/chat") || pathname.endsWith("/chat-sync")) return "chat";
11435
+ if (pathname.endsWith("/health")) return "health";
11436
+ if (pathname.endsWith("/suggestions")) return "suggestions";
11437
+ if (pathname.endsWith("/feedback")) return "feedback";
11438
+ if (pathname.endsWith("/history")) return "history";
11439
+ } catch (e) {
11440
+ }
11238
11441
  const resolvedParams = typeof ((_a2 = context == null ? void 0 : context.params) == null ? void 0 : _a2.then) === "function" ? await context.params : context == null ? void 0 : context.params;
11239
- const segments = (resolvedParams == null ? void 0 : resolvedParams.retrivora) || [];
11240
- return segments.join("/") || "chat";
11442
+ const segments = (resolvedParams == null ? void 0 : resolvedParams.retrivora) || ((_b = resolvedParams == null ? void 0 : resolvedParams.params) == null ? void 0 : _b.retrivora) || [];
11443
+ const joined = segments.join("/");
11444
+ return joined || "chat";
11241
11445
  }
11242
11446
  return {
11243
11447
  GET: async (req, context) => {
11244
11448
  try {
11245
- const segment = await getSegment(context);
11449
+ const segment = await getSegment(req, context);
11246
11450
  return await routeGetRequest(req, segment);
11247
11451
  } catch (err) {
11248
11452
  const msg = err instanceof Error ? err.message : "GET Routing failed";
@@ -11251,7 +11455,7 @@ function createRagHandler(configOrPlugin, options) {
11251
11455
  },
11252
11456
  POST: async (req, context) => {
11253
11457
  try {
11254
- const segment = await getSegment(context);
11458
+ const segment = await getSegment(req, context);
11255
11459
  return await routePostRequest(req, segment);
11256
11460
  } catch (err) {
11257
11461
  const msg = err instanceof Error ? err.message : "POST Routing failed";