@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/handlers/index.d.mts +1 -1
- package/dist/handlers/index.d.ts +1 -1
- package/dist/handlers/index.js +110 -48
- package/dist/handlers/index.mjs +110 -48
- package/dist/{index-DXd29KMq.d.mts → index-DHsFLJXQ.d.mts} +1 -30
- package/dist/{index-D_bOdJML.d.ts → index-tzwc7UhY.d.ts} +1 -30
- package/dist/index.js +12 -3
- package/dist/index.mjs +12 -3
- package/dist/server.d.mts +2 -2
- package/dist/server.d.ts +2 -2
- package/dist/server.js +110 -48
- package/dist/server.mjs +110 -48
- package/package.json +1 -1
- package/src/components/ChatWindow.tsx +14 -3
- package/src/config/serverConfig.ts +14 -1
- package/src/core/Pipeline.ts +3 -2
- package/src/handlers/index.ts +84 -48
package/dist/server.mjs
CHANGED
|
@@ -2127,46 +2127,48 @@ function getRagConfig(baseConfig, env = process.env) {
|
|
|
2127
2127
|
return getEnvConfig(env, baseConfig);
|
|
2128
2128
|
}
|
|
2129
2129
|
function getEnvConfig(env = process.env, base) {
|
|
2130
|
-
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;
|
|
2130
|
+
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;
|
|
2131
2131
|
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__";
|
|
2132
|
+
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;
|
|
2133
|
+
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);
|
|
2132
2134
|
const vectorProvider = readEnum(env, "VECTOR_DB_PROVIDER", "pinecone", VECTOR_DB_PROVIDERS);
|
|
2133
2135
|
const llmProvider = readEnum(env, "LLM_PROVIDER", "openai", LLM_PROVIDERS);
|
|
2134
2136
|
const embeddingProvider = readEnum(env, "EMBEDDING_PROVIDER", "openai", EMBEDDING_PROVIDERS);
|
|
2135
2137
|
const embeddingDimensions = readNumber(env, "EMBEDDING_DIMENSIONS", 1536);
|
|
2136
2138
|
const vectorDbOptions = {};
|
|
2137
2139
|
if (vectorProvider === "pinecone") {
|
|
2138
|
-
vectorDbOptions.apiKey = (
|
|
2139
|
-
vectorDbOptions.indexName = (
|
|
2140
|
+
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 : "";
|
|
2141
|
+
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;
|
|
2140
2142
|
} else if (vectorProvider === "pgvector" || vectorProvider === "postgresql") {
|
|
2141
|
-
vectorDbOptions.connectionString = (
|
|
2142
|
-
vectorDbOptions.tables = (
|
|
2143
|
-
vectorDbOptions.searchFields = (
|
|
2143
|
+
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 : "";
|
|
2144
|
+
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;
|
|
2145
|
+
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;
|
|
2144
2146
|
vectorDbOptions.dimensions = embeddingDimensions;
|
|
2145
2147
|
} else if (vectorProvider === "mongodb") {
|
|
2146
|
-
vectorDbOptions.uri = (
|
|
2147
|
-
vectorDbOptions.database = (
|
|
2148
|
-
vectorDbOptions.collection = (
|
|
2149
|
-
vectorDbOptions.indexName = (
|
|
2148
|
+
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 : "";
|
|
2149
|
+
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 : "";
|
|
2150
|
+
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 : "";
|
|
2151
|
+
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";
|
|
2150
2152
|
} else if (vectorProvider === "qdrant") {
|
|
2151
|
-
vectorDbOptions.baseUrl = (
|
|
2152
|
-
vectorDbOptions.apiKey = (
|
|
2153
|
+
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";
|
|
2154
|
+
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;
|
|
2153
2155
|
vectorDbOptions.dimensions = embeddingDimensions;
|
|
2154
2156
|
} else if (vectorProvider === "milvus") {
|
|
2155
|
-
vectorDbOptions.baseUrl = (
|
|
2157
|
+
vectorDbOptions.baseUrl = (_ca = readString(env, "MILVUS_URL")) != null ? _ca : "http://localhost:19530";
|
|
2156
2158
|
vectorDbOptions.apiKey = readString(env, "MILVUS_API_KEY");
|
|
2157
2159
|
} else if (vectorProvider === "chromadb") {
|
|
2158
|
-
vectorDbOptions.baseUrl = (
|
|
2160
|
+
vectorDbOptions.baseUrl = (_da = readString(env, "CHROMADB_URL")) != null ? _da : "http://localhost:8000";
|
|
2159
2161
|
} else if (vectorProvider === "weaviate") {
|
|
2160
|
-
vectorDbOptions.baseUrl = (
|
|
2162
|
+
vectorDbOptions.baseUrl = (_ea = readString(env, "WEAVIATE_URL")) != null ? _ea : "http://localhost:8080";
|
|
2161
2163
|
vectorDbOptions.apiKey = readString(env, "WEAVIATE_API_KEY");
|
|
2162
2164
|
} else if (vectorProvider === "redis") {
|
|
2163
|
-
vectorDbOptions.baseUrl = (
|
|
2165
|
+
vectorDbOptions.baseUrl = (_fa = readString(env, "REDIS_URL")) != null ? _fa : "";
|
|
2164
2166
|
vectorDbOptions.apiKey = readString(env, "REDIS_API_KEY");
|
|
2165
2167
|
} else if (vectorProvider === "rest") {
|
|
2166
|
-
vectorDbOptions.baseUrl = (
|
|
2168
|
+
vectorDbOptions.baseUrl = (_ga = readString(env, "VECTOR_DB_REST_URL")) != null ? _ga : "";
|
|
2167
2169
|
vectorDbOptions.headers = readString(env, "VECTOR_DB_REST_API_KEY") ? { "api-key": readString(env, "VECTOR_DB_REST_API_KEY") } : {};
|
|
2168
2170
|
} else if (vectorProvider === "universal_rest") {
|
|
2169
|
-
vectorDbOptions.baseUrl = (
|
|
2171
|
+
vectorDbOptions.baseUrl = (_ia = (_ha = readString(env, "VECTOR_BASE_URL")) != null ? _ha : readString(env, "VECTOR_DB_REST_URL")) != null ? _ia : "";
|
|
2170
2172
|
vectorDbOptions.profile = readString(env, "VECTOR_UNIVERSAL_PROFILE");
|
|
2171
2173
|
vectorDbOptions.headers = readString(env, "VECTOR_DB_REST_API_KEY") ? { Authorization: `Bearer ${readString(env, "VECTOR_DB_REST_API_KEY")}` } : {};
|
|
2172
2174
|
}
|
|
@@ -2185,8 +2187,8 @@ function getEnvConfig(env = process.env, base) {
|
|
|
2185
2187
|
// Anthropic needs a separate embedding provider; key kept for completeness
|
|
2186
2188
|
gemini: readString(env, "GEMINI_API_KEY"),
|
|
2187
2189
|
ollama: void 0,
|
|
2188
|
-
universal_rest: (
|
|
2189
|
-
custom: (
|
|
2190
|
+
universal_rest: (_ja = readString(env, "EMBEDDING_API_KEY")) != null ? _ja : readString(env, "OPENAI_API_KEY"),
|
|
2191
|
+
custom: (_ka = readString(env, "EMBEDDING_API_KEY")) != null ? _ka : readString(env, "OPENAI_API_KEY")
|
|
2190
2192
|
};
|
|
2191
2193
|
const DEFAULT_MODEL_BY_PROVIDER = {
|
|
2192
2194
|
openai: "gpt-4o",
|
|
@@ -2199,16 +2201,16 @@ function getEnvConfig(env = process.env, base) {
|
|
|
2199
2201
|
};
|
|
2200
2202
|
return __spreadProps(__spreadValues({
|
|
2201
2203
|
projectId,
|
|
2202
|
-
licenseKey: (
|
|
2204
|
+
licenseKey: (_ma = (_la = readString(env, "RETRIVORA_LICENSE_KEY")) != null ? _la : readString(env, "LICENSE_KEY")) != null ? _ma : base == null ? void 0 : base.licenseKey,
|
|
2203
2205
|
vectorDb: {
|
|
2204
2206
|
provider: vectorProvider,
|
|
2205
|
-
indexName: (
|
|
2207
|
+
indexName: (_oa = (_na = readString(env, "VECTOR_DB_INDEX")) != null ? _na : vectorDbOptions.indexName) != null ? _oa : "rag-index",
|
|
2206
2208
|
options: vectorDbOptions
|
|
2207
2209
|
},
|
|
2208
2210
|
llm: {
|
|
2209
2211
|
provider: llmProvider,
|
|
2210
|
-
model: (
|
|
2211
|
-
apiKey: (
|
|
2212
|
+
model: (_qa = (_pa = readString(env, "LLM_MODEL")) != null ? _pa : DEFAULT_MODEL_BY_PROVIDER[llmProvider]) != null ? _qa : "gpt-4o",
|
|
2213
|
+
apiKey: (_ra = llmApiKeyByProvider[llmProvider]) != null ? _ra : "",
|
|
2212
2214
|
baseUrl: readString(env, "LLM_BASE_URL"),
|
|
2213
2215
|
systemPrompt: readString(env, "LLM_SYSTEM_PROMPT"),
|
|
2214
2216
|
maxTokens: readNumber(env, "LLM_MAX_TOKENS", 4096),
|
|
@@ -2221,7 +2223,7 @@ function getEnvConfig(env = process.env, base) {
|
|
|
2221
2223
|
},
|
|
2222
2224
|
embedding: {
|
|
2223
2225
|
provider: embeddingProvider,
|
|
2224
|
-
model: (
|
|
2226
|
+
model: (_sa = readString(env, "EMBEDDING_MODEL")) != null ? _sa : "text-embedding-3-small",
|
|
2225
2227
|
apiKey: embeddingApiKeyByProvider[embeddingProvider],
|
|
2226
2228
|
baseUrl: readString(env, "EMBEDDING_BASE_URL"),
|
|
2227
2229
|
dimensions: embeddingDimensions,
|
|
@@ -2232,30 +2234,30 @@ function getEnvConfig(env = process.env, base) {
|
|
|
2232
2234
|
}
|
|
2233
2235
|
},
|
|
2234
2236
|
ui: {
|
|
2235
|
-
title: (
|
|
2236
|
-
subtitle: (
|
|
2237
|
-
primaryColor: (
|
|
2238
|
-
accentColor: (
|
|
2239
|
-
logoUrl: (
|
|
2240
|
-
placeholder: (
|
|
2241
|
-
showSources: ((
|
|
2242
|
-
welcomeMessage: (
|
|
2243
|
-
visualStyle: (
|
|
2244
|
-
borderRadius: (
|
|
2245
|
-
allowUpload: ((
|
|
2237
|
+
title: (_ua = (_ta = readString(env, "NEXT_PUBLIC_UI_TITLE")) != null ? _ta : readString(env, "UI_TITLE")) != null ? _ua : "AI Assistant",
|
|
2238
|
+
subtitle: (_wa = (_va = readString(env, "NEXT_PUBLIC_UI_SUBTITLE")) != null ? _va : readString(env, "UI_SUBTITLE")) != null ? _wa : "Powered by RAG",
|
|
2239
|
+
primaryColor: (_ya = (_xa = readString(env, "NEXT_PUBLIC_PRIMARY_COLOR")) != null ? _xa : readString(env, "UI_PRIMARY_COLOR")) != null ? _ya : "#10b981",
|
|
2240
|
+
accentColor: (_Aa = (_za = readString(env, "NEXT_PUBLIC_ACCENT_COLOR")) != null ? _za : readString(env, "UI_ACCENT_COLOR")) != null ? _Aa : "#3b82f6",
|
|
2241
|
+
logoUrl: (_Ba = readString(env, "NEXT_PUBLIC_LOGO_URL")) != null ? _Ba : readString(env, "UI_LOGO_URL"),
|
|
2242
|
+
placeholder: (_Da = (_Ca = readString(env, "NEXT_PUBLIC_PLACEHOLDER")) != null ? _Ca : readString(env, "UI_PLACEHOLDER")) != null ? _Da : "Ask me anything\u2026",
|
|
2243
|
+
showSources: ((_Fa = (_Ea = readString(env, "NEXT_PUBLIC_SHOW_SOURCES")) != null ? _Ea : readString(env, "UI_SHOW_SOURCES")) != null ? _Fa : "true") !== "false",
|
|
2244
|
+
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.",
|
|
2245
|
+
visualStyle: (_Ja = (_Ia = readString(env, "NEXT_PUBLIC_UI_VISUAL_STYLE")) != null ? _Ia : readString(env, "UI_VISUAL_STYLE")) != null ? _Ja : "glass",
|
|
2246
|
+
borderRadius: (_La = (_Ka = readString(env, "NEXT_PUBLIC_UI_BORDER_RADIUS")) != null ? _Ka : readString(env, "UI_BORDER_RADIUS")) != null ? _La : "xl",
|
|
2247
|
+
allowUpload: ((_Na = (_Ma = readString(env, "NEXT_PUBLIC_ALLOW_UPLOAD")) != null ? _Ma : readString(env, "UI_ALLOW_UPLOAD")) != null ? _Na : "false") === "true"
|
|
2246
2248
|
},
|
|
2247
2249
|
rag: {
|
|
2248
2250
|
topK: readNumber(env, "RAG_TOP_K", 5),
|
|
2249
2251
|
scoreThreshold: readNumber(env, "RAG_SCORE_THRESHOLD", 0),
|
|
2250
2252
|
chunkSize: readNumber(env, "RAG_CHUNK_SIZE", 1e3),
|
|
2251
2253
|
chunkOverlap: readNumber(env, "RAG_CHUNK_OVERLAP", 200),
|
|
2252
|
-
filterableFields: (
|
|
2254
|
+
filterableFields: (_Oa = readString(env, "RAG_FILTERABLE_FIELDS")) == null ? void 0 : _Oa.split(",").map((f) => f.trim()),
|
|
2253
2255
|
// Query pipeline toggles — read from .env.local
|
|
2254
2256
|
useQueryTransformation: readString(env, "RAG_USE_QUERY_TRANSFORMATION") === "true",
|
|
2255
2257
|
useReranking: readString(env, "RAG_USE_RERANKING") === "true",
|
|
2256
2258
|
useGraphRetrieval: readString(env, "RAG_USE_GRAPH_RETRIEVAL") === "true",
|
|
2257
|
-
architecture: (
|
|
2258
|
-
chunkingStrategy: (
|
|
2259
|
+
architecture: (_Pa = readString(env, "RAG_ARCHITECTURE")) != null ? _Pa : "simple",
|
|
2260
|
+
chunkingStrategy: (_Qa = readString(env, "RAG_CHUNKING_STRATEGY")) != null ? _Qa : "recursive",
|
|
2259
2261
|
uiMapping: (() => {
|
|
2260
2262
|
const raw = readString(env, "RAG_UI_MAPPING");
|
|
2261
2263
|
if (!raw) return void 0;
|
|
@@ -2267,8 +2269,8 @@ function getEnvConfig(env = process.env, base) {
|
|
|
2267
2269
|
})()
|
|
2268
2270
|
},
|
|
2269
2271
|
telemetry: {
|
|
2270
|
-
enabled:
|
|
2271
|
-
url: (
|
|
2272
|
+
enabled: telemetryEnabled,
|
|
2273
|
+
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"
|
|
2272
2274
|
}
|
|
2273
2275
|
}, readString(env, "GRAPH_DB_PROVIDER") ? {
|
|
2274
2276
|
graphDb: {
|
|
@@ -7697,7 +7699,7 @@ ${m.content}`).join("\n\n---\n\n");
|
|
|
7697
7699
|
*/
|
|
7698
7700
|
askStreamInternal(_0) {
|
|
7699
7701
|
return __asyncGenerator(this, arguments, function* (question, history = [], namespace) {
|
|
7700
|
-
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;
|
|
7702
|
+
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;
|
|
7701
7703
|
yield new __await(this.initialize());
|
|
7702
7704
|
const ns = namespace != null ? namespace : this.config.projectId;
|
|
7703
7705
|
const topK = (_b = (_a2 = this.config.rag) == null ? void 0 : _a2.topK) != null ? _b : 5;
|
|
@@ -8007,8 +8009,9 @@ ${context}`;
|
|
|
8007
8009
|
hallucinationReason: hScore.reason
|
|
8008
8010
|
} : {});
|
|
8009
8011
|
const trace = buildTrace(hallucinationResult);
|
|
8010
|
-
|
|
8011
|
-
|
|
8012
|
+
const isTelemetryActive = (_B = (_A = this.config.telemetry) == null ? void 0 : _A.enabled) != null ? _B : Boolean(this.config.licenseKey);
|
|
8013
|
+
if (isTelemetryActive) {
|
|
8014
|
+
const telemetryUrl = ((_C = this.config.telemetry) == null ? void 0 : _C.url) || "/api/telemetry";
|
|
8012
8015
|
const absoluteUrl = telemetryUrl.startsWith("http") ? telemetryUrl : (process.env.NEXT_PUBLIC_APP_URL || `http://localhost:${process.env.PORT || 3e3}`) + telemetryUrl;
|
|
8013
8016
|
(async () => {
|
|
8014
8017
|
try {
|
|
@@ -9358,6 +9361,43 @@ function getOrCreatePlugin(configOrPlugin) {
|
|
|
9358
9361
|
}
|
|
9359
9362
|
return _g[cacheKey];
|
|
9360
9363
|
}
|
|
9364
|
+
function reportTelemetry(req, plugin, action, status, details, trace) {
|
|
9365
|
+
var _a2;
|
|
9366
|
+
try {
|
|
9367
|
+
const config = plugin.getConfig();
|
|
9368
|
+
const licenseKey = config.licenseKey || process.env.RAG_LICENSE_KEY || process.env.RETRIVORA_LICENSE_KEY || process.env.NEXT_PUBLIC_RETRIVORA_LICENSE_KEY;
|
|
9369
|
+
const telemetryConfig = config.telemetry;
|
|
9370
|
+
const enabled = (_a2 = telemetryConfig == null ? void 0 : telemetryConfig.enabled) != null ? _a2 : Boolean(licenseKey);
|
|
9371
|
+
if (!enabled) return;
|
|
9372
|
+
const telemetryUrl = (telemetryConfig == null ? void 0 : telemetryConfig.url) || process.env.TELEMETRY_URL || process.env.NEXT_PUBLIC_TELEMETRY_URL || "/api/telemetry";
|
|
9373
|
+
const host = req.headers.get("host") || "localhost";
|
|
9374
|
+
let absoluteUrl = telemetryUrl;
|
|
9375
|
+
if (!telemetryUrl.startsWith("http")) {
|
|
9376
|
+
const proto = req.headers.get("x-forwarded-proto") || "http";
|
|
9377
|
+
absoluteUrl = `${proto}://${host}${telemetryUrl}`;
|
|
9378
|
+
}
|
|
9379
|
+
const projectId = config.projectId || "default";
|
|
9380
|
+
fetch(absoluteUrl, {
|
|
9381
|
+
method: "POST",
|
|
9382
|
+
headers: {
|
|
9383
|
+
"Content-Type": "application/json",
|
|
9384
|
+
"x-forwarded-for": req.headers.get("x-forwarded-for") || "",
|
|
9385
|
+
"x-real-ip": req.headers.get("x-real-ip") || ""
|
|
9386
|
+
},
|
|
9387
|
+
body: JSON.stringify({
|
|
9388
|
+
trace,
|
|
9389
|
+
licenseKey,
|
|
9390
|
+
projectId,
|
|
9391
|
+
action,
|
|
9392
|
+
status,
|
|
9393
|
+
details
|
|
9394
|
+
})
|
|
9395
|
+
}).catch((err) => {
|
|
9396
|
+
console.warn("[Retrivora Telemetry] Async report warning:", err.message);
|
|
9397
|
+
});
|
|
9398
|
+
} catch (e) {
|
|
9399
|
+
}
|
|
9400
|
+
}
|
|
9361
9401
|
function sseFrame(payload) {
|
|
9362
9402
|
return `data: ${JSON.stringify(payload)}
|
|
9363
9403
|
|
|
@@ -9400,6 +9440,7 @@ function createChatHandler(configOrPlugin, options) {
|
|
|
9400
9440
|
const storage = new DatabaseStorage(plugin.getConfig());
|
|
9401
9441
|
const onAuthorize = options == null ? void 0 : options.onAuthorize;
|
|
9402
9442
|
return async function POST(req) {
|
|
9443
|
+
var _a2, _b, _c, _d;
|
|
9403
9444
|
const authResult = await checkAuth(req, onAuthorize);
|
|
9404
9445
|
if (authResult) return authResult;
|
|
9405
9446
|
const rateLimited = checkRateLimit(req);
|
|
@@ -9428,12 +9469,14 @@ function createChatHandler(configOrPlugin, options) {
|
|
|
9428
9469
|
uiTransformation: result.ui_transformation,
|
|
9429
9470
|
trace: result.trace
|
|
9430
9471
|
}).catch((err) => console.warn("[createChatHandler] Failed to save assistant message:", err));
|
|
9472
|
+
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);
|
|
9431
9473
|
return NextResponse.json(__spreadProps(__spreadValues({}, result), {
|
|
9432
9474
|
messageId: assistantMsgId,
|
|
9433
9475
|
userMessageId: userMsgId
|
|
9434
9476
|
}));
|
|
9435
9477
|
} catch (err) {
|
|
9436
9478
|
const message = err instanceof Error ? err.message : "Internal server error";
|
|
9479
|
+
reportTelemetry(req, plugin, "QUERY_GENERATION", "error", message);
|
|
9437
9480
|
return NextResponse.json({ error: message }, { status: 500 });
|
|
9438
9481
|
}
|
|
9439
9482
|
};
|
|
@@ -9476,7 +9519,7 @@ function createStreamHandler(configOrPlugin, options) {
|
|
|
9476
9519
|
let isActive = true;
|
|
9477
9520
|
const stream = new ReadableStream({
|
|
9478
9521
|
async start(controller) {
|
|
9479
|
-
var _a2;
|
|
9522
|
+
var _a2, _b, _c, _d, _e;
|
|
9480
9523
|
const enqueue = (text) => {
|
|
9481
9524
|
if (!isActive) return;
|
|
9482
9525
|
try {
|
|
@@ -9533,6 +9576,7 @@ function createStreamHandler(configOrPlugin, options) {
|
|
|
9533
9576
|
uiTransformation,
|
|
9534
9577
|
trace: responseChunk == null ? void 0 : responseChunk.trace
|
|
9535
9578
|
}).catch((err) => console.warn("[createStreamHandler] Failed to save assistant message:", err));
|
|
9579
|
+
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);
|
|
9536
9580
|
}
|
|
9537
9581
|
}
|
|
9538
9582
|
} catch (temp) {
|
|
@@ -9549,6 +9593,7 @@ function createStreamHandler(configOrPlugin, options) {
|
|
|
9549
9593
|
if (isActive) {
|
|
9550
9594
|
const errorMessage = streamError instanceof Error ? streamError.message : String(streamError);
|
|
9551
9595
|
console.error("[createStreamHandler] Stream error:", streamError);
|
|
9596
|
+
reportTelemetry(req, plugin, "QUERY_GENERATION", "error", errorMessage);
|
|
9552
9597
|
try {
|
|
9553
9598
|
enqueue(sseErrorFrame(errorMessage));
|
|
9554
9599
|
} catch (e) {
|
|
@@ -9585,9 +9630,11 @@ function createIngestHandler(configOrPlugin, options) {
|
|
|
9585
9630
|
return NextResponse.json({ error: "documents array is required" }, { status: 400 });
|
|
9586
9631
|
}
|
|
9587
9632
|
const results = await plugin.ingest(documents, namespace);
|
|
9633
|
+
reportTelemetry(req, plugin, "DOCUMENT_INGESTION", "success", `Ingested ${documents.length} document(s)`);
|
|
9588
9634
|
return NextResponse.json({ results });
|
|
9589
9635
|
} catch (err) {
|
|
9590
9636
|
const message = err instanceof Error ? err.message : "Internal server error";
|
|
9637
|
+
reportTelemetry(req, plugin, "DOCUMENT_INGESTION", "error", message);
|
|
9591
9638
|
return NextResponse.json({ error: message }, { status: 500 });
|
|
9592
9639
|
}
|
|
9593
9640
|
};
|
|
@@ -9686,9 +9733,11 @@ function createUploadHandler(configOrPlugin, options) {
|
|
|
9686
9733
|
}
|
|
9687
9734
|
}
|
|
9688
9735
|
const results = await plugin.ingest(documents, namespace);
|
|
9736
|
+
reportTelemetry(req, plugin, "DOCUMENT_INGESTION", "success", `Uploaded & ingested ${files.length} file(s)`);
|
|
9689
9737
|
return NextResponse.json({ message: "Upload successful", results });
|
|
9690
9738
|
} catch (err) {
|
|
9691
9739
|
const message = err instanceof Error ? err.message : "Upload failed";
|
|
9740
|
+
reportTelemetry(req, plugin, "DOCUMENT_INGESTION", "error", message);
|
|
9692
9741
|
return NextResponse.json({ error: message }, { status: 500 });
|
|
9693
9742
|
}
|
|
9694
9743
|
};
|
|
@@ -9696,19 +9745,30 @@ function createUploadHandler(configOrPlugin, options) {
|
|
|
9696
9745
|
function createSuggestionsHandler(configOrPlugin, options) {
|
|
9697
9746
|
const plugin = getOrCreatePlugin(configOrPlugin);
|
|
9698
9747
|
const onAuthorize = options == null ? void 0 : options.onAuthorize;
|
|
9699
|
-
return async function
|
|
9748
|
+
return async function handler(req) {
|
|
9700
9749
|
const authResult = await checkAuth(req, onAuthorize);
|
|
9701
9750
|
if (authResult) return authResult;
|
|
9702
9751
|
try {
|
|
9703
|
-
|
|
9704
|
-
|
|
9752
|
+
let query = "";
|
|
9753
|
+
let namespace = void 0;
|
|
9754
|
+
if (req.method === "POST") {
|
|
9755
|
+
const body = await req.json().catch(() => ({}));
|
|
9756
|
+
query = body.query || "";
|
|
9757
|
+
namespace = body.namespace;
|
|
9758
|
+
} else {
|
|
9759
|
+
const url = new URL(req.url);
|
|
9760
|
+
query = url.searchParams.get("query") || "";
|
|
9761
|
+
namespace = url.searchParams.get("namespace") || void 0;
|
|
9762
|
+
}
|
|
9705
9763
|
if (typeof query !== "string") {
|
|
9706
9764
|
return NextResponse.json({ error: "query is required" }, { status: 400 });
|
|
9707
9765
|
}
|
|
9708
9766
|
const suggestions = await plugin.getSuggestions(query, namespace);
|
|
9767
|
+
reportTelemetry(req, plugin, "AUTO_SUGGESTIONS", "success", `Fetched ${suggestions.length} suggestions for: ${query.slice(0, 30)}`);
|
|
9709
9768
|
return NextResponse.json({ suggestions });
|
|
9710
9769
|
} catch (err) {
|
|
9711
9770
|
const message = err instanceof Error ? err.message : "Internal server error";
|
|
9771
|
+
reportTelemetry(req, plugin, "AUTO_SUGGESTIONS", "error", message);
|
|
9712
9772
|
return NextResponse.json({ error: message }, { status: 500 });
|
|
9713
9773
|
}
|
|
9714
9774
|
};
|
|
@@ -9840,6 +9900,8 @@ function createRagHandler(configOrPlugin, options) {
|
|
|
9840
9900
|
switch (segment) {
|
|
9841
9901
|
case "health":
|
|
9842
9902
|
return healthHandler(req);
|
|
9903
|
+
case "suggestions":
|
|
9904
|
+
return suggestionsHandler(req);
|
|
9843
9905
|
case "history":
|
|
9844
9906
|
return historyHandler(req);
|
|
9845
9907
|
case "feedback":
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@retrivora-ai/rag-engine",
|
|
3
|
-
"version": "
|
|
3
|
+
"version": "2.0.0",
|
|
4
4
|
"description": "Retrivora AI is a plug-and-play AI engine for RAG chat experiences — generic vector DB + LLM provider, embeddable or standalone.",
|
|
5
5
|
"author": "Abhinav Alkuchi",
|
|
6
6
|
"license": "UNLICENSED",
|
|
@@ -217,11 +217,22 @@ export function ChatWindow({
|
|
|
217
217
|
const timer = setTimeout(async () => {
|
|
218
218
|
setIsSuggesting(true);
|
|
219
219
|
try {
|
|
220
|
-
const
|
|
220
|
+
const base = retrivoraApiBase || '/api/retrivora';
|
|
221
|
+
const primaryUrl = `${base}/suggestions`;
|
|
222
|
+
let response = await fetch(primaryUrl, {
|
|
221
223
|
method: 'POST',
|
|
222
|
-
headers: { 'Content-Type': 'application/json' },
|
|
224
|
+
headers: { 'Content-Type': 'application/json', ...(headers || {}) },
|
|
223
225
|
body: JSON.stringify({ query: input, namespace: projectId }),
|
|
224
226
|
});
|
|
227
|
+
|
|
228
|
+
if (!response.ok && response.status === 404) {
|
|
229
|
+
response = await fetch('/api/suggestions', {
|
|
230
|
+
method: 'POST',
|
|
231
|
+
headers: { 'Content-Type': 'application/json', ...(headers || {}) },
|
|
232
|
+
body: JSON.stringify({ query: input, namespace: projectId }),
|
|
233
|
+
});
|
|
234
|
+
}
|
|
235
|
+
|
|
225
236
|
const data = await response.json();
|
|
226
237
|
if (data.suggestions) {
|
|
227
238
|
setSuggestions(data.suggestions);
|
|
@@ -234,7 +245,7 @@ export function ChatWindow({
|
|
|
234
245
|
}, 800); // 800ms debounce to save costs/latency
|
|
235
246
|
|
|
236
247
|
return () => clearTimeout(timer);
|
|
237
|
-
}, [input, projectId]);
|
|
248
|
+
}, [input, projectId, retrivoraApiBase, headers]);
|
|
238
249
|
|
|
239
250
|
return (
|
|
240
251
|
<div
|
|
@@ -64,6 +64,19 @@ export function getEnvConfig(env: Record<string, string | undefined> = process.e
|
|
|
64
64
|
base?.projectId ??
|
|
65
65
|
'__default__';
|
|
66
66
|
|
|
67
|
+
const licenseKey =
|
|
68
|
+
readString(env, 'RAG_LICENSE_KEY') ??
|
|
69
|
+
readString(env, 'RETRIVORA_LICENSE_KEY') ??
|
|
70
|
+
readString(env, 'NEXT_PUBLIC_RETRIVORA_LICENSE_KEY') ??
|
|
71
|
+
readString(env, 'LICENSE_KEY') ??
|
|
72
|
+
base?.licenseKey;
|
|
73
|
+
|
|
74
|
+
const telemetryEnabled =
|
|
75
|
+
readString(env, 'TELEMETRY_ENABLED') === 'true' ||
|
|
76
|
+
readString(env, 'NEXT_PUBLIC_TELEMETRY_ENABLED') === 'true' ||
|
|
77
|
+
base?.telemetry?.enabled ||
|
|
78
|
+
Boolean(licenseKey);
|
|
79
|
+
|
|
67
80
|
const vectorProvider = readEnum(env, 'VECTOR_DB_PROVIDER', 'pinecone', VECTOR_DB_PROVIDERS);
|
|
68
81
|
const llmProvider = readEnum(env, 'LLM_PROVIDER', 'openai', LLM_PROVIDERS);
|
|
69
82
|
const embeddingProvider = readEnum(env, 'EMBEDDING_PROVIDER', 'openai', EMBEDDING_PROVIDERS);
|
|
@@ -219,7 +232,7 @@ export function getEnvConfig(env: Record<string, string | undefined> = process.e
|
|
|
219
232
|
})(),
|
|
220
233
|
},
|
|
221
234
|
telemetry: {
|
|
222
|
-
enabled:
|
|
235
|
+
enabled: telemetryEnabled,
|
|
223
236
|
url: readString(env, 'TELEMETRY_URL') ?? readString(env, 'NEXT_PUBLIC_TELEMETRY_URL') ?? base?.telemetry?.url ?? '/api/telemetry',
|
|
224
237
|
},
|
|
225
238
|
// Optional graph DB — driven by GRAPH_DB_PROVIDER env var
|
package/src/core/Pipeline.ts
CHANGED
|
@@ -881,8 +881,9 @@ You are a helpful assistant. Use the provided context to answer questions accura
|
|
|
881
881
|
const trace = buildTrace(hallucinationResult);
|
|
882
882
|
|
|
883
883
|
// Asynchronously trigger telemetry logging without blocking response yield
|
|
884
|
-
|
|
885
|
-
|
|
884
|
+
const isTelemetryActive = this.config.telemetry?.enabled ?? Boolean(this.config.licenseKey);
|
|
885
|
+
if (isTelemetryActive) {
|
|
886
|
+
const telemetryUrl = this.config.telemetry?.url || '/api/telemetry';
|
|
886
887
|
const absoluteUrl = telemetryUrl.startsWith('http')
|
|
887
888
|
? telemetryUrl
|
|
888
889
|
: (process.env.NEXT_PUBLIC_APP_URL || `http://localhost:${process.env.PORT || 3000}`) + telemetryUrl;
|