@retrivora-ai/rag-engine 1.9.9 → 2.0.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/dist/server.js CHANGED
@@ -2206,46 +2206,48 @@ function getRagConfig(baseConfig, env = process.env) {
2206
2206
  return getEnvConfig(env, baseConfig);
2207
2207
  }
2208
2208
  function getEnvConfig(env = process.env, base) {
2209
- 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;
2209
+ 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;
2210
2210
  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__";
2211
+ 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;
2212
+ 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);
2211
2213
  const vectorProvider = readEnum(env, "VECTOR_DB_PROVIDER", "pinecone", VECTOR_DB_PROVIDERS);
2212
2214
  const llmProvider = readEnum(env, "LLM_PROVIDER", "openai", LLM_PROVIDERS);
2213
2215
  const embeddingProvider = readEnum(env, "EMBEDDING_PROVIDER", "openai", EMBEDDING_PROVIDERS);
2214
2216
  const embeddingDimensions = readNumber(env, "EMBEDDING_DIMENSIONS", 1536);
2215
2217
  const vectorDbOptions = {};
2216
2218
  if (vectorProvider === "pinecone") {
2217
- vectorDbOptions.apiKey = (_g2 = (_f = readString(env, "PINECONE_API_KEY")) != null ? _f : (_e = (_d = base == null ? void 0 : base.vectorDb) == null ? void 0 : _d.options) == null ? void 0 : _e.apiKey) != null ? _g2 : "";
2218
- vectorDbOptions.indexName = (_l = (_i = readString(env, "PINECONE_INDEX")) != null ? _i : (_h = base == null ? void 0 : base.vectorDb) == null ? void 0 : _h.indexName) != null ? _l : (_k = (_j = base == null ? void 0 : base.vectorDb) == null ? void 0 : _j.options) == null ? void 0 : _k.indexName;
2219
+ 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 : "";
2220
+ 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;
2219
2221
  } else if (vectorProvider === "pgvector" || vectorProvider === "postgresql") {
2220
- vectorDbOptions.connectionString = (_q = (_p = (_m = readString(env, "PGVECTOR_CONNECTION_STRING")) != null ? _m : readString(env, "POSTGRES_URL")) != null ? _p : (_o = (_n = base == null ? void 0 : base.vectorDb) == null ? void 0 : _n.options) == null ? void 0 : _o.connectionString) != null ? _q : "";
2221
- vectorDbOptions.tables = (_v = (_s = (_r = readString(env, "VECTOR_DB_TABLES")) != null ? _r : readString(env, "POSTGRES_TABLES")) == null ? void 0 : _s.split(",").map((t) => t.trim())) != null ? _v : (_u = (_t = base == null ? void 0 : base.vectorDb) == null ? void 0 : _t.options) == null ? void 0 : _u.tables;
2222
- vectorDbOptions.searchFields = (_z = (_w = readString(env, "POSTGRES_SEARCH_FIELDS")) == null ? void 0 : _w.split(",").map((f) => f.trim())) != null ? _z : (_y = (_x = base == null ? void 0 : base.vectorDb) == null ? void 0 : _x.options) == null ? void 0 : _y.searchFields;
2222
+ 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 : "";
2223
+ 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;
2224
+ 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;
2223
2225
  vectorDbOptions.dimensions = embeddingDimensions;
2224
2226
  } else if (vectorProvider === "mongodb") {
2225
- vectorDbOptions.uri = (_D = (_C = readString(env, "MONGODB_URI")) != null ? _C : (_B = (_A = base == null ? void 0 : base.vectorDb) == null ? void 0 : _A.options) == null ? void 0 : _B.uri) != null ? _D : "";
2226
- vectorDbOptions.database = (_H = (_G = readString(env, "MONGODB_DB")) != null ? _G : (_F = (_E = base == null ? void 0 : base.vectorDb) == null ? void 0 : _E.options) == null ? void 0 : _F.database) != null ? _H : "";
2227
- vectorDbOptions.collection = (_L = (_K = readString(env, "MONGODB_COLLECTION")) != null ? _K : (_J = (_I = base == null ? void 0 : base.vectorDb) == null ? void 0 : _I.options) == null ? void 0 : _J.collection) != null ? _L : "";
2228
- vectorDbOptions.indexName = (_R = (_Q = (_N = readString(env, "MONGODB_INDEX_NAME")) != 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) != null ? _R : "vector_index";
2227
+ 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 : "";
2228
+ 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 : "";
2229
+ 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 : "";
2230
+ 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";
2229
2231
  } else if (vectorProvider === "qdrant") {
2230
- vectorDbOptions.baseUrl = (_V = (_U = readString(env, "QDRANT_URL")) != null ? _U : (_T = (_S = base == null ? void 0 : base.vectorDb) == null ? void 0 : _S.options) == null ? void 0 : _T.baseUrl) != null ? _V : "http://localhost:6333";
2231
- vectorDbOptions.apiKey = (_Y = readString(env, "QDRANT_API_KEY")) != null ? _Y : (_X = (_W = base == null ? void 0 : base.vectorDb) == null ? void 0 : _W.options) == null ? void 0 : _X.apiKey;
2232
+ 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";
2233
+ 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;
2232
2234
  vectorDbOptions.dimensions = embeddingDimensions;
2233
2235
  } else if (vectorProvider === "milvus") {
2234
- vectorDbOptions.baseUrl = (_Z = readString(env, "MILVUS_URL")) != null ? _Z : "http://localhost:19530";
2236
+ vectorDbOptions.baseUrl = (_ca = readString(env, "MILVUS_URL")) != null ? _ca : "http://localhost:19530";
2235
2237
  vectorDbOptions.apiKey = readString(env, "MILVUS_API_KEY");
2236
2238
  } else if (vectorProvider === "chromadb") {
2237
- vectorDbOptions.baseUrl = (__ = readString(env, "CHROMADB_URL")) != null ? __ : "http://localhost:8000";
2239
+ vectorDbOptions.baseUrl = (_da = readString(env, "CHROMADB_URL")) != null ? _da : "http://localhost:8000";
2238
2240
  } else if (vectorProvider === "weaviate") {
2239
- vectorDbOptions.baseUrl = (_$ = readString(env, "WEAVIATE_URL")) != null ? _$ : "http://localhost:8080";
2241
+ vectorDbOptions.baseUrl = (_ea = readString(env, "WEAVIATE_URL")) != null ? _ea : "http://localhost:8080";
2240
2242
  vectorDbOptions.apiKey = readString(env, "WEAVIATE_API_KEY");
2241
2243
  } else if (vectorProvider === "redis") {
2242
- vectorDbOptions.baseUrl = (_aa = readString(env, "REDIS_URL")) != null ? _aa : "";
2244
+ vectorDbOptions.baseUrl = (_fa = readString(env, "REDIS_URL")) != null ? _fa : "";
2243
2245
  vectorDbOptions.apiKey = readString(env, "REDIS_API_KEY");
2244
2246
  } else if (vectorProvider === "rest") {
2245
- vectorDbOptions.baseUrl = (_ba = readString(env, "VECTOR_DB_REST_URL")) != null ? _ba : "";
2247
+ vectorDbOptions.baseUrl = (_ga = readString(env, "VECTOR_DB_REST_URL")) != null ? _ga : "";
2246
2248
  vectorDbOptions.headers = readString(env, "VECTOR_DB_REST_API_KEY") ? { "api-key": readString(env, "VECTOR_DB_REST_API_KEY") } : {};
2247
2249
  } else if (vectorProvider === "universal_rest") {
2248
- vectorDbOptions.baseUrl = (_da = (_ca = readString(env, "VECTOR_BASE_URL")) != null ? _ca : readString(env, "VECTOR_DB_REST_URL")) != null ? _da : "";
2250
+ vectorDbOptions.baseUrl = (_ia = (_ha = readString(env, "VECTOR_BASE_URL")) != null ? _ha : readString(env, "VECTOR_DB_REST_URL")) != null ? _ia : "";
2249
2251
  vectorDbOptions.profile = readString(env, "VECTOR_UNIVERSAL_PROFILE");
2250
2252
  vectorDbOptions.headers = readString(env, "VECTOR_DB_REST_API_KEY") ? { Authorization: `Bearer ${readString(env, "VECTOR_DB_REST_API_KEY")}` } : {};
2251
2253
  }
@@ -2264,8 +2266,8 @@ function getEnvConfig(env = process.env, base) {
2264
2266
  // Anthropic needs a separate embedding provider; key kept for completeness
2265
2267
  gemini: readString(env, "GEMINI_API_KEY"),
2266
2268
  ollama: void 0,
2267
- universal_rest: (_ea = readString(env, "EMBEDDING_API_KEY")) != null ? _ea : readString(env, "OPENAI_API_KEY"),
2268
- custom: (_fa = readString(env, "EMBEDDING_API_KEY")) != null ? _fa : readString(env, "OPENAI_API_KEY")
2269
+ universal_rest: (_ja = readString(env, "EMBEDDING_API_KEY")) != null ? _ja : readString(env, "OPENAI_API_KEY"),
2270
+ custom: (_ka = readString(env, "EMBEDDING_API_KEY")) != null ? _ka : readString(env, "OPENAI_API_KEY")
2269
2271
  };
2270
2272
  const DEFAULT_MODEL_BY_PROVIDER = {
2271
2273
  openai: "gpt-4o",
@@ -2278,16 +2280,16 @@ function getEnvConfig(env = process.env, base) {
2278
2280
  };
2279
2281
  return __spreadProps(__spreadValues({
2280
2282
  projectId,
2281
- licenseKey: (_ha = (_ga = readString(env, "RETRIVORA_LICENSE_KEY")) != null ? _ga : readString(env, "LICENSE_KEY")) != null ? _ha : base == null ? void 0 : base.licenseKey,
2283
+ licenseKey: (_ma = (_la = readString(env, "RETRIVORA_LICENSE_KEY")) != null ? _la : readString(env, "LICENSE_KEY")) != null ? _ma : base == null ? void 0 : base.licenseKey,
2282
2284
  vectorDb: {
2283
2285
  provider: vectorProvider,
2284
- indexName: (_ja = (_ia = readString(env, "VECTOR_DB_INDEX")) != null ? _ia : vectorDbOptions.indexName) != null ? _ja : "rag-index",
2286
+ indexName: (_oa = (_na = readString(env, "VECTOR_DB_INDEX")) != null ? _na : vectorDbOptions.indexName) != null ? _oa : "rag-index",
2285
2287
  options: vectorDbOptions
2286
2288
  },
2287
2289
  llm: {
2288
2290
  provider: llmProvider,
2289
- model: (_la = (_ka = readString(env, "LLM_MODEL")) != null ? _ka : DEFAULT_MODEL_BY_PROVIDER[llmProvider]) != null ? _la : "gpt-4o",
2290
- apiKey: (_ma = llmApiKeyByProvider[llmProvider]) != null ? _ma : "",
2291
+ model: (_qa = (_pa = readString(env, "LLM_MODEL")) != null ? _pa : DEFAULT_MODEL_BY_PROVIDER[llmProvider]) != null ? _qa : "gpt-4o",
2292
+ apiKey: (_ra = llmApiKeyByProvider[llmProvider]) != null ? _ra : "",
2291
2293
  baseUrl: readString(env, "LLM_BASE_URL"),
2292
2294
  systemPrompt: readString(env, "LLM_SYSTEM_PROMPT"),
2293
2295
  maxTokens: readNumber(env, "LLM_MAX_TOKENS", 4096),
@@ -2300,7 +2302,7 @@ function getEnvConfig(env = process.env, base) {
2300
2302
  },
2301
2303
  embedding: {
2302
2304
  provider: embeddingProvider,
2303
- model: (_na = readString(env, "EMBEDDING_MODEL")) != null ? _na : "text-embedding-3-small",
2305
+ model: (_sa = readString(env, "EMBEDDING_MODEL")) != null ? _sa : "text-embedding-3-small",
2304
2306
  apiKey: embeddingApiKeyByProvider[embeddingProvider],
2305
2307
  baseUrl: readString(env, "EMBEDDING_BASE_URL"),
2306
2308
  dimensions: embeddingDimensions,
@@ -2311,30 +2313,30 @@ function getEnvConfig(env = process.env, base) {
2311
2313
  }
2312
2314
  },
2313
2315
  ui: {
2314
- title: (_pa = (_oa = readString(env, "NEXT_PUBLIC_UI_TITLE")) != null ? _oa : readString(env, "UI_TITLE")) != null ? _pa : "AI Assistant",
2315
- subtitle: (_ra = (_qa = readString(env, "NEXT_PUBLIC_UI_SUBTITLE")) != null ? _qa : readString(env, "UI_SUBTITLE")) != null ? _ra : "Powered by RAG",
2316
- primaryColor: (_ta = (_sa = readString(env, "NEXT_PUBLIC_PRIMARY_COLOR")) != null ? _sa : readString(env, "UI_PRIMARY_COLOR")) != null ? _ta : "#10b981",
2317
- accentColor: (_va = (_ua = readString(env, "NEXT_PUBLIC_ACCENT_COLOR")) != null ? _ua : readString(env, "UI_ACCENT_COLOR")) != null ? _va : "#3b82f6",
2318
- logoUrl: (_wa = readString(env, "NEXT_PUBLIC_LOGO_URL")) != null ? _wa : readString(env, "UI_LOGO_URL"),
2319
- placeholder: (_ya = (_xa = readString(env, "NEXT_PUBLIC_PLACEHOLDER")) != null ? _xa : readString(env, "UI_PLACEHOLDER")) != null ? _ya : "Ask me anything\u2026",
2320
- showSources: ((_Aa = (_za = readString(env, "NEXT_PUBLIC_SHOW_SOURCES")) != null ? _za : readString(env, "UI_SHOW_SOURCES")) != null ? _Aa : "true") !== "false",
2321
- welcomeMessage: (_Ca = (_Ba = readString(env, "NEXT_PUBLIC_WELCOME_MESSAGE")) != null ? _Ba : readString(env, "UI_WELCOME_MESSAGE")) != null ? _Ca : "Hello! I'm your AI assistant. Ask me anything about your documents.",
2322
- visualStyle: (_Ea = (_Da = readString(env, "NEXT_PUBLIC_UI_VISUAL_STYLE")) != null ? _Da : readString(env, "UI_VISUAL_STYLE")) != null ? _Ea : "glass",
2323
- borderRadius: (_Ga = (_Fa = readString(env, "NEXT_PUBLIC_UI_BORDER_RADIUS")) != null ? _Fa : readString(env, "UI_BORDER_RADIUS")) != null ? _Ga : "xl",
2324
- allowUpload: ((_Ia = (_Ha = readString(env, "NEXT_PUBLIC_ALLOW_UPLOAD")) != null ? _Ha : readString(env, "UI_ALLOW_UPLOAD")) != null ? _Ia : "false") === "true"
2316
+ title: (_ua = (_ta = readString(env, "NEXT_PUBLIC_UI_TITLE")) != null ? _ta : readString(env, "UI_TITLE")) != null ? _ua : "AI Assistant",
2317
+ subtitle: (_wa = (_va = readString(env, "NEXT_PUBLIC_UI_SUBTITLE")) != null ? _va : readString(env, "UI_SUBTITLE")) != null ? _wa : "Powered by RAG",
2318
+ primaryColor: (_ya = (_xa = readString(env, "NEXT_PUBLIC_PRIMARY_COLOR")) != null ? _xa : readString(env, "UI_PRIMARY_COLOR")) != null ? _ya : "#10b981",
2319
+ accentColor: (_Aa = (_za = readString(env, "NEXT_PUBLIC_ACCENT_COLOR")) != null ? _za : readString(env, "UI_ACCENT_COLOR")) != null ? _Aa : "#3b82f6",
2320
+ logoUrl: (_Ba = readString(env, "NEXT_PUBLIC_LOGO_URL")) != null ? _Ba : readString(env, "UI_LOGO_URL"),
2321
+ placeholder: (_Da = (_Ca = readString(env, "NEXT_PUBLIC_PLACEHOLDER")) != null ? _Ca : readString(env, "UI_PLACEHOLDER")) != null ? _Da : "Ask me anything\u2026",
2322
+ showSources: ((_Fa = (_Ea = readString(env, "NEXT_PUBLIC_SHOW_SOURCES")) != null ? _Ea : readString(env, "UI_SHOW_SOURCES")) != null ? _Fa : "true") !== "false",
2323
+ welcomeMessage: (_Ha = (_Ga = readString(env, "NEXT_PUBLIC_WELCOME_MESSAGE")) != null ? _Ga : readString(env, "UI_WELCOME_MESSAGE")) != null ? _Ha : "Hello! I'm your AI assistant. Ask me anything about your documents.",
2324
+ visualStyle: (_Ja = (_Ia = readString(env, "NEXT_PUBLIC_UI_VISUAL_STYLE")) != null ? _Ia : readString(env, "UI_VISUAL_STYLE")) != null ? _Ja : "glass",
2325
+ borderRadius: (_La = (_Ka = readString(env, "NEXT_PUBLIC_UI_BORDER_RADIUS")) != null ? _Ka : readString(env, "UI_BORDER_RADIUS")) != null ? _La : "xl",
2326
+ allowUpload: ((_Na = (_Ma = readString(env, "NEXT_PUBLIC_ALLOW_UPLOAD")) != null ? _Ma : readString(env, "UI_ALLOW_UPLOAD")) != null ? _Na : "false") === "true"
2325
2327
  },
2326
2328
  rag: {
2327
2329
  topK: readNumber(env, "RAG_TOP_K", 5),
2328
2330
  scoreThreshold: readNumber(env, "RAG_SCORE_THRESHOLD", 0),
2329
2331
  chunkSize: readNumber(env, "RAG_CHUNK_SIZE", 1e3),
2330
2332
  chunkOverlap: readNumber(env, "RAG_CHUNK_OVERLAP", 200),
2331
- filterableFields: (_Ja = readString(env, "RAG_FILTERABLE_FIELDS")) == null ? void 0 : _Ja.split(",").map((f) => f.trim()),
2333
+ filterableFields: (_Oa = readString(env, "RAG_FILTERABLE_FIELDS")) == null ? void 0 : _Oa.split(",").map((f) => f.trim()),
2332
2334
  // Query pipeline toggles — read from .env.local
2333
2335
  useQueryTransformation: readString(env, "RAG_USE_QUERY_TRANSFORMATION") === "true",
2334
2336
  useReranking: readString(env, "RAG_USE_RERANKING") === "true",
2335
2337
  useGraphRetrieval: readString(env, "RAG_USE_GRAPH_RETRIEVAL") === "true",
2336
- architecture: (_Ka = readString(env, "RAG_ARCHITECTURE")) != null ? _Ka : "simple",
2337
- chunkingStrategy: (_La = readString(env, "RAG_CHUNKING_STRATEGY")) != null ? _La : "recursive",
2338
+ architecture: (_Pa = readString(env, "RAG_ARCHITECTURE")) != null ? _Pa : "simple",
2339
+ chunkingStrategy: (_Qa = readString(env, "RAG_CHUNKING_STRATEGY")) != null ? _Qa : "recursive",
2338
2340
  uiMapping: (() => {
2339
2341
  const raw = readString(env, "RAG_UI_MAPPING");
2340
2342
  if (!raw) return void 0;
@@ -2346,8 +2348,8 @@ function getEnvConfig(env = process.env, base) {
2346
2348
  })()
2347
2349
  },
2348
2350
  telemetry: {
2349
- enabled: readString(env, "TELEMETRY_ENABLED") === "true" || readString(env, "NEXT_PUBLIC_TELEMETRY_ENABLED") === "true" || ((_Ma = base == null ? void 0 : base.telemetry) == null ? void 0 : _Ma.enabled) || false,
2350
- url: (_Qa = (_Pa = (_Na = readString(env, "TELEMETRY_URL")) != null ? _Na : readString(env, "NEXT_PUBLIC_TELEMETRY_URL")) != null ? _Pa : (_Oa = base == null ? void 0 : base.telemetry) == null ? void 0 : _Oa.url) != null ? _Qa : "/api/telemetry"
2351
+ enabled: telemetryEnabled,
2352
+ url: (_Ua = (_Ta = (_Ra = readString(env, "TELEMETRY_URL")) != null ? _Ra : readString(env, "NEXT_PUBLIC_TELEMETRY_URL")) != null ? _Ta : (_Sa = base == null ? void 0 : base.telemetry) == null ? void 0 : _Sa.url) != null ? _Ua : "/api/telemetry"
2351
2353
  }
2352
2354
  }, readString(env, "GRAPH_DB_PROVIDER") ? {
2353
2355
  graphDb: {
@@ -7776,7 +7778,7 @@ ${m.content}`).join("\n\n---\n\n");
7776
7778
  */
7777
7779
  askStreamInternal(_0) {
7778
7780
  return __asyncGenerator(this, arguments, function* (question, history = [], namespace) {
7779
- 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;
7781
+ 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;
7780
7782
  yield new __await(this.initialize());
7781
7783
  const ns = namespace != null ? namespace : this.config.projectId;
7782
7784
  const topK = (_b = (_a2 = this.config.rag) == null ? void 0 : _a2.topK) != null ? _b : 5;
@@ -8086,8 +8088,9 @@ ${context}`;
8086
8088
  hallucinationReason: hScore.reason
8087
8089
  } : {});
8088
8090
  const trace = buildTrace(hallucinationResult);
8089
- if ((_A = this.config.telemetry) == null ? void 0 : _A.enabled) {
8090
- const telemetryUrl = this.config.telemetry.url || "/api/telemetry";
8091
+ const isTelemetryActive = (_B = (_A = this.config.telemetry) == null ? void 0 : _A.enabled) != null ? _B : Boolean(this.config.licenseKey);
8092
+ if (isTelemetryActive) {
8093
+ const telemetryUrl = ((_C = this.config.telemetry) == null ? void 0 : _C.url) || "/api/telemetry";
8091
8094
  const absoluteUrl = telemetryUrl.startsWith("http") ? telemetryUrl : (process.env.NEXT_PUBLIC_APP_URL || `http://localhost:${process.env.PORT || 3e3}`) + telemetryUrl;
8092
8095
  (async () => {
8093
8096
  try {
@@ -9437,6 +9440,43 @@ function getOrCreatePlugin(configOrPlugin) {
9437
9440
  }
9438
9441
  return _g[cacheKey];
9439
9442
  }
9443
+ function reportTelemetry(req, plugin, action, status, details, trace) {
9444
+ var _a2;
9445
+ try {
9446
+ const config = plugin.getConfig();
9447
+ const licenseKey = config.licenseKey || process.env.RAG_LICENSE_KEY || process.env.RETRIVORA_LICENSE_KEY || process.env.NEXT_PUBLIC_RETRIVORA_LICENSE_KEY;
9448
+ const telemetryConfig = config.telemetry;
9449
+ const enabled = (_a2 = telemetryConfig == null ? void 0 : telemetryConfig.enabled) != null ? _a2 : Boolean(licenseKey);
9450
+ if (!enabled) return;
9451
+ const telemetryUrl = (telemetryConfig == null ? void 0 : telemetryConfig.url) || process.env.TELEMETRY_URL || process.env.NEXT_PUBLIC_TELEMETRY_URL || "/api/telemetry";
9452
+ const host = req.headers.get("host") || "localhost";
9453
+ let absoluteUrl = telemetryUrl;
9454
+ if (!telemetryUrl.startsWith("http")) {
9455
+ const proto = req.headers.get("x-forwarded-proto") || "http";
9456
+ absoluteUrl = `${proto}://${host}${telemetryUrl}`;
9457
+ }
9458
+ const projectId = config.projectId || "default";
9459
+ fetch(absoluteUrl, {
9460
+ method: "POST",
9461
+ headers: {
9462
+ "Content-Type": "application/json",
9463
+ "x-forwarded-for": req.headers.get("x-forwarded-for") || "",
9464
+ "x-real-ip": req.headers.get("x-real-ip") || ""
9465
+ },
9466
+ body: JSON.stringify({
9467
+ trace,
9468
+ licenseKey,
9469
+ projectId,
9470
+ action,
9471
+ status,
9472
+ details
9473
+ })
9474
+ }).catch((err) => {
9475
+ console.warn("[Retrivora Telemetry] Async report warning:", err.message);
9476
+ });
9477
+ } catch (e) {
9478
+ }
9479
+ }
9440
9480
  function sseFrame(payload) {
9441
9481
  return `data: ${JSON.stringify(payload)}
9442
9482
 
@@ -9479,6 +9519,7 @@ function createChatHandler(configOrPlugin, options) {
9479
9519
  const storage = new DatabaseStorage(plugin.getConfig());
9480
9520
  const onAuthorize = options == null ? void 0 : options.onAuthorize;
9481
9521
  return async function POST(req) {
9522
+ var _a2, _b, _c, _d;
9482
9523
  const authResult = await checkAuth(req, onAuthorize);
9483
9524
  if (authResult) return authResult;
9484
9525
  const rateLimited = checkRateLimit(req);
@@ -9507,12 +9548,14 @@ function createChatHandler(configOrPlugin, options) {
9507
9548
  uiTransformation: result.ui_transformation,
9508
9549
  trace: result.trace
9509
9550
  }).catch((err) => console.warn("[createChatHandler] Failed to save assistant message:", err));
9551
+ reportTelemetry(req, plugin, "QUERY_GENERATION", "success", `Tokens: ${((_b = (_a2 = result.trace) == null ? void 0 : _a2.tokens) == null ? void 0 : _b.totalTokens) || 0}, Latency: ${((_d = (_c = result.trace) == null ? void 0 : _c.latency) == null ? void 0 : _d.totalMs) || 0}ms`, result.trace);
9510
9552
  return import_server.NextResponse.json(__spreadProps(__spreadValues({}, result), {
9511
9553
  messageId: assistantMsgId,
9512
9554
  userMessageId: userMsgId
9513
9555
  }));
9514
9556
  } catch (err) {
9515
9557
  const message = err instanceof Error ? err.message : "Internal server error";
9558
+ reportTelemetry(req, plugin, "QUERY_GENERATION", "error", message);
9516
9559
  return import_server.NextResponse.json({ error: message }, { status: 500 });
9517
9560
  }
9518
9561
  };
@@ -9555,7 +9598,7 @@ function createStreamHandler(configOrPlugin, options) {
9555
9598
  let isActive = true;
9556
9599
  const stream = new ReadableStream({
9557
9600
  async start(controller) {
9558
- var _a2;
9601
+ var _a2, _b, _c, _d, _e;
9559
9602
  const enqueue = (text) => {
9560
9603
  if (!isActive) return;
9561
9604
  try {
@@ -9612,6 +9655,7 @@ function createStreamHandler(configOrPlugin, options) {
9612
9655
  uiTransformation,
9613
9656
  trace: responseChunk == null ? void 0 : responseChunk.trace
9614
9657
  }).catch((err) => console.warn("[createStreamHandler] Failed to save assistant message:", err));
9658
+ reportTelemetry(req, plugin, "QUERY_GENERATION", "success", `Tokens: ${((_c = (_b = responseChunk == null ? void 0 : responseChunk.trace) == null ? void 0 : _b.tokens) == null ? void 0 : _c.totalTokens) || 0}, Latency: ${((_e = (_d = responseChunk == null ? void 0 : responseChunk.trace) == null ? void 0 : _d.latency) == null ? void 0 : _e.totalMs) || 0}ms`, responseChunk == null ? void 0 : responseChunk.trace);
9615
9659
  }
9616
9660
  }
9617
9661
  } catch (temp) {
@@ -9628,6 +9672,7 @@ function createStreamHandler(configOrPlugin, options) {
9628
9672
  if (isActive) {
9629
9673
  const errorMessage = streamError instanceof Error ? streamError.message : String(streamError);
9630
9674
  console.error("[createStreamHandler] Stream error:", streamError);
9675
+ reportTelemetry(req, plugin, "QUERY_GENERATION", "error", errorMessage);
9631
9676
  try {
9632
9677
  enqueue(sseErrorFrame(errorMessage));
9633
9678
  } catch (e) {
@@ -9664,9 +9709,11 @@ function createIngestHandler(configOrPlugin, options) {
9664
9709
  return import_server.NextResponse.json({ error: "documents array is required" }, { status: 400 });
9665
9710
  }
9666
9711
  const results = await plugin.ingest(documents, namespace);
9712
+ reportTelemetry(req, plugin, "DOCUMENT_INGESTION", "success", `Ingested ${documents.length} document(s)`);
9667
9713
  return import_server.NextResponse.json({ results });
9668
9714
  } catch (err) {
9669
9715
  const message = err instanceof Error ? err.message : "Internal server error";
9716
+ reportTelemetry(req, plugin, "DOCUMENT_INGESTION", "error", message);
9670
9717
  return import_server.NextResponse.json({ error: message }, { status: 500 });
9671
9718
  }
9672
9719
  };
@@ -9765,9 +9812,11 @@ function createUploadHandler(configOrPlugin, options) {
9765
9812
  }
9766
9813
  }
9767
9814
  const results = await plugin.ingest(documents, namespace);
9815
+ reportTelemetry(req, plugin, "DOCUMENT_INGESTION", "success", `Uploaded & ingested ${files.length} file(s)`);
9768
9816
  return import_server.NextResponse.json({ message: "Upload successful", results });
9769
9817
  } catch (err) {
9770
9818
  const message = err instanceof Error ? err.message : "Upload failed";
9819
+ reportTelemetry(req, plugin, "DOCUMENT_INGESTION", "error", message);
9771
9820
  return import_server.NextResponse.json({ error: message }, { status: 500 });
9772
9821
  }
9773
9822
  };
@@ -9775,19 +9824,30 @@ function createUploadHandler(configOrPlugin, options) {
9775
9824
  function createSuggestionsHandler(configOrPlugin, options) {
9776
9825
  const plugin = getOrCreatePlugin(configOrPlugin);
9777
9826
  const onAuthorize = options == null ? void 0 : options.onAuthorize;
9778
- return async function POST(req) {
9827
+ return async function handler(req) {
9779
9828
  const authResult = await checkAuth(req, onAuthorize);
9780
9829
  if (authResult) return authResult;
9781
9830
  try {
9782
- const body = await req.json();
9783
- const { query, namespace } = body;
9831
+ let query = "";
9832
+ let namespace = void 0;
9833
+ if (req.method === "POST") {
9834
+ const body = await req.json().catch(() => ({}));
9835
+ query = body.query || "";
9836
+ namespace = body.namespace;
9837
+ } else {
9838
+ const url = new URL(req.url);
9839
+ query = url.searchParams.get("query") || "";
9840
+ namespace = url.searchParams.get("namespace") || void 0;
9841
+ }
9784
9842
  if (typeof query !== "string") {
9785
9843
  return import_server.NextResponse.json({ error: "query is required" }, { status: 400 });
9786
9844
  }
9787
9845
  const suggestions = await plugin.getSuggestions(query, namespace);
9846
+ reportTelemetry(req, plugin, "AUTO_SUGGESTIONS", "success", `Fetched ${suggestions.length} suggestions for: ${query.slice(0, 30)}`);
9788
9847
  return import_server.NextResponse.json({ suggestions });
9789
9848
  } catch (err) {
9790
9849
  const message = err instanceof Error ? err.message : "Internal server error";
9850
+ reportTelemetry(req, plugin, "AUTO_SUGGESTIONS", "error", message);
9791
9851
  return import_server.NextResponse.json({ error: message }, { status: 500 });
9792
9852
  }
9793
9853
  };
@@ -9919,6 +9979,8 @@ function createRagHandler(configOrPlugin, options) {
9919
9979
  switch (segment) {
9920
9980
  case "health":
9921
9981
  return healthHandler(req);
9982
+ case "suggestions":
9983
+ return suggestionsHandler(req);
9922
9984
  case "history":
9923
9985
  return historyHandler(req);
9924
9986
  case "feedback":