@retrivora-ai/rag-engine 1.9.9 → 2.0.1

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 : process.env.NODE_ENV === "development" ? "http://localhost:3001/api/telemetry" : "https://retrivora.com/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,10 @@ ${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 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";
8094
+ const telemetryUrl = ((_C = this.config.telemetry) == null ? void 0 : _C.url) || process.env.TELEMETRY_URL || process.env.NEXT_PUBLIC_TELEMETRY_URL || defaultUrl;
8091
8095
  const absoluteUrl = telemetryUrl.startsWith("http") ? telemetryUrl : (process.env.NEXT_PUBLIC_APP_URL || `http://localhost:${process.env.PORT || 3e3}`) + telemetryUrl;
8092
8096
  (async () => {
8093
8097
  try {
@@ -9437,6 +9441,43 @@ function getOrCreatePlugin(configOrPlugin) {
9437
9441
  }
9438
9442
  return _g[cacheKey];
9439
9443
  }
9444
+ function reportTelemetry(req, plugin, action, status, details, trace) {
9445
+ var _a2;
9446
+ try {
9447
+ const config = plugin.getConfig();
9448
+ const licenseKey = config.licenseKey || process.env.RAG_LICENSE_KEY || process.env.RETRIVORA_LICENSE_KEY || process.env.NEXT_PUBLIC_RETRIVORA_LICENSE_KEY;
9449
+ const telemetryConfig = config.telemetry;
9450
+ const enabled = (_a2 = telemetryConfig == null ? void 0 : telemetryConfig.enabled) != null ? _a2 : Boolean(licenseKey);
9451
+ 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";
9452
+ const telemetryUrl = (telemetryConfig == null ? void 0 : telemetryConfig.url) || process.env.TELEMETRY_URL || process.env.NEXT_PUBLIC_TELEMETRY_URL || defaultUrl;
9453
+ const host = req.headers.get("host") || "localhost";
9454
+ let absoluteUrl = telemetryUrl;
9455
+ if (!telemetryUrl.startsWith("http")) {
9456
+ const proto = req.headers.get("x-forwarded-proto") || "http";
9457
+ absoluteUrl = `${proto}://${host}${telemetryUrl}`;
9458
+ }
9459
+ const projectId = config.projectId || "default";
9460
+ fetch(absoluteUrl, {
9461
+ method: "POST",
9462
+ headers: {
9463
+ "Content-Type": "application/json",
9464
+ "x-forwarded-for": req.headers.get("x-forwarded-for") || "",
9465
+ "x-real-ip": req.headers.get("x-real-ip") || ""
9466
+ },
9467
+ body: JSON.stringify({
9468
+ trace,
9469
+ licenseKey,
9470
+ projectId,
9471
+ action,
9472
+ status,
9473
+ details
9474
+ })
9475
+ }).catch((err) => {
9476
+ console.warn("[Retrivora Telemetry] Async report warning:", err.message);
9477
+ });
9478
+ } catch (e) {
9479
+ }
9480
+ }
9440
9481
  function sseFrame(payload) {
9441
9482
  return `data: ${JSON.stringify(payload)}
9442
9483
 
@@ -9479,6 +9520,7 @@ function createChatHandler(configOrPlugin, options) {
9479
9520
  const storage = new DatabaseStorage(plugin.getConfig());
9480
9521
  const onAuthorize = options == null ? void 0 : options.onAuthorize;
9481
9522
  return async function POST(req) {
9523
+ var _a2, _b, _c, _d;
9482
9524
  const authResult = await checkAuth(req, onAuthorize);
9483
9525
  if (authResult) return authResult;
9484
9526
  const rateLimited = checkRateLimit(req);
@@ -9507,12 +9549,14 @@ function createChatHandler(configOrPlugin, options) {
9507
9549
  uiTransformation: result.ui_transformation,
9508
9550
  trace: result.trace
9509
9551
  }).catch((err) => console.warn("[createChatHandler] Failed to save assistant message:", err));
9552
+ 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
9553
  return import_server.NextResponse.json(__spreadProps(__spreadValues({}, result), {
9511
9554
  messageId: assistantMsgId,
9512
9555
  userMessageId: userMsgId
9513
9556
  }));
9514
9557
  } catch (err) {
9515
9558
  const message = err instanceof Error ? err.message : "Internal server error";
9559
+ reportTelemetry(req, plugin, "QUERY_GENERATION", "error", message);
9516
9560
  return import_server.NextResponse.json({ error: message }, { status: 500 });
9517
9561
  }
9518
9562
  };
@@ -9555,7 +9599,7 @@ function createStreamHandler(configOrPlugin, options) {
9555
9599
  let isActive = true;
9556
9600
  const stream = new ReadableStream({
9557
9601
  async start(controller) {
9558
- var _a2;
9602
+ var _a2, _b, _c, _d, _e;
9559
9603
  const enqueue = (text) => {
9560
9604
  if (!isActive) return;
9561
9605
  try {
@@ -9612,6 +9656,7 @@ function createStreamHandler(configOrPlugin, options) {
9612
9656
  uiTransformation,
9613
9657
  trace: responseChunk == null ? void 0 : responseChunk.trace
9614
9658
  }).catch((err) => console.warn("[createStreamHandler] Failed to save assistant message:", err));
9659
+ 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
9660
  }
9616
9661
  }
9617
9662
  } catch (temp) {
@@ -9628,6 +9673,7 @@ function createStreamHandler(configOrPlugin, options) {
9628
9673
  if (isActive) {
9629
9674
  const errorMessage = streamError instanceof Error ? streamError.message : String(streamError);
9630
9675
  console.error("[createStreamHandler] Stream error:", streamError);
9676
+ reportTelemetry(req, plugin, "QUERY_GENERATION", "error", errorMessage);
9631
9677
  try {
9632
9678
  enqueue(sseErrorFrame(errorMessage));
9633
9679
  } catch (e) {
@@ -9664,9 +9710,11 @@ function createIngestHandler(configOrPlugin, options) {
9664
9710
  return import_server.NextResponse.json({ error: "documents array is required" }, { status: 400 });
9665
9711
  }
9666
9712
  const results = await plugin.ingest(documents, namespace);
9713
+ reportTelemetry(req, plugin, "DOCUMENT_INGESTION", "success", `Ingested ${documents.length} document(s)`);
9667
9714
  return import_server.NextResponse.json({ results });
9668
9715
  } catch (err) {
9669
9716
  const message = err instanceof Error ? err.message : "Internal server error";
9717
+ reportTelemetry(req, plugin, "DOCUMENT_INGESTION", "error", message);
9670
9718
  return import_server.NextResponse.json({ error: message }, { status: 500 });
9671
9719
  }
9672
9720
  };
@@ -9765,9 +9813,11 @@ function createUploadHandler(configOrPlugin, options) {
9765
9813
  }
9766
9814
  }
9767
9815
  const results = await plugin.ingest(documents, namespace);
9816
+ reportTelemetry(req, plugin, "DOCUMENT_INGESTION", "success", `Uploaded & ingested ${files.length} file(s)`);
9768
9817
  return import_server.NextResponse.json({ message: "Upload successful", results });
9769
9818
  } catch (err) {
9770
9819
  const message = err instanceof Error ? err.message : "Upload failed";
9820
+ reportTelemetry(req, plugin, "DOCUMENT_INGESTION", "error", message);
9771
9821
  return import_server.NextResponse.json({ error: message }, { status: 500 });
9772
9822
  }
9773
9823
  };
@@ -9775,19 +9825,30 @@ function createUploadHandler(configOrPlugin, options) {
9775
9825
  function createSuggestionsHandler(configOrPlugin, options) {
9776
9826
  const plugin = getOrCreatePlugin(configOrPlugin);
9777
9827
  const onAuthorize = options == null ? void 0 : options.onAuthorize;
9778
- return async function POST(req) {
9828
+ return async function handler(req) {
9779
9829
  const authResult = await checkAuth(req, onAuthorize);
9780
9830
  if (authResult) return authResult;
9781
9831
  try {
9782
- const body = await req.json();
9783
- const { query, namespace } = body;
9832
+ let query = "";
9833
+ let namespace = void 0;
9834
+ if (req.method === "POST") {
9835
+ const body = await req.json().catch(() => ({}));
9836
+ query = body.query || "";
9837
+ namespace = body.namespace;
9838
+ } else {
9839
+ const url = new URL(req.url);
9840
+ query = url.searchParams.get("query") || "";
9841
+ namespace = url.searchParams.get("namespace") || void 0;
9842
+ }
9784
9843
  if (typeof query !== "string") {
9785
9844
  return import_server.NextResponse.json({ error: "query is required" }, { status: 400 });
9786
9845
  }
9787
9846
  const suggestions = await plugin.getSuggestions(query, namespace);
9847
+ reportTelemetry(req, plugin, "AUTO_SUGGESTIONS", "success", `Fetched ${suggestions.length} suggestions for: ${query.slice(0, 30)}`);
9788
9848
  return import_server.NextResponse.json({ suggestions });
9789
9849
  } catch (err) {
9790
9850
  const message = err instanceof Error ? err.message : "Internal server error";
9851
+ reportTelemetry(req, plugin, "AUTO_SUGGESTIONS", "error", message);
9791
9852
  return import_server.NextResponse.json({ error: message }, { status: 500 });
9792
9853
  }
9793
9854
  };
@@ -9919,6 +9980,8 @@ function createRagHandler(configOrPlugin, options) {
9919
9980
  switch (segment) {
9920
9981
  case "health":
9921
9982
  return healthHandler(req);
9983
+ case "suggestions":
9984
+ return suggestionsHandler(req);
9922
9985
  case "history":
9923
9986
  return historyHandler(req);
9924
9987
  case "feedback":