@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/handlers/index.d.mts +1 -1
- package/dist/handlers/index.d.ts +1 -1
- package/dist/handlers/index.js +111 -48
- package/dist/handlers/index.mjs +111 -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 +111 -48
- package/dist/server.mjs +111 -48
- package/package.json +1 -1
- package/src/components/ChatWindow.tsx +14 -3
- package/src/config/serverConfig.ts +15 -2
- package/src/core/Pipeline.ts +25 -20
- package/src/handlers/index.ts +92 -54
|
@@ -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-
|
|
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-DHsFLJXQ.mjs';
|
|
3
3
|
import '../ILLMProvider-DMxLyTdq.mjs';
|
package/dist/handlers/index.d.ts
CHANGED
|
@@ -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-
|
|
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-tzwc7UhY.js';
|
|
3
3
|
import '../ILLMProvider-DMxLyTdq.js';
|
package/dist/handlers/index.js
CHANGED
|
@@ -2162,46 +2162,48 @@ function readEnum(env, name, fallback, allowed) {
|
|
|
2162
2162
|
throw new Error(`[getRagConfig] ${name} must be one of: ${allowed.join(", ")}`);
|
|
2163
2163
|
}
|
|
2164
2164
|
function getEnvConfig(env = process.env, base) {
|
|
2165
|
-
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;
|
|
2165
|
+
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;
|
|
2166
2166
|
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__";
|
|
2167
|
+
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;
|
|
2168
|
+
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);
|
|
2167
2169
|
const vectorProvider = readEnum(env, "VECTOR_DB_PROVIDER", "pinecone", VECTOR_DB_PROVIDERS);
|
|
2168
2170
|
const llmProvider = readEnum(env, "LLM_PROVIDER", "openai", LLM_PROVIDERS);
|
|
2169
2171
|
const embeddingProvider = readEnum(env, "EMBEDDING_PROVIDER", "openai", EMBEDDING_PROVIDERS);
|
|
2170
2172
|
const embeddingDimensions = readNumber(env, "EMBEDDING_DIMENSIONS", 1536);
|
|
2171
2173
|
const vectorDbOptions = {};
|
|
2172
2174
|
if (vectorProvider === "pinecone") {
|
|
2173
|
-
vectorDbOptions.apiKey = (
|
|
2174
|
-
vectorDbOptions.indexName = (
|
|
2175
|
+
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 : "";
|
|
2176
|
+
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;
|
|
2175
2177
|
} else if (vectorProvider === "pgvector" || vectorProvider === "postgresql") {
|
|
2176
|
-
vectorDbOptions.connectionString = (
|
|
2177
|
-
vectorDbOptions.tables = (
|
|
2178
|
-
vectorDbOptions.searchFields = (
|
|
2178
|
+
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 : "";
|
|
2179
|
+
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;
|
|
2180
|
+
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;
|
|
2179
2181
|
vectorDbOptions.dimensions = embeddingDimensions;
|
|
2180
2182
|
} else if (vectorProvider === "mongodb") {
|
|
2181
|
-
vectorDbOptions.uri = (
|
|
2182
|
-
vectorDbOptions.database = (
|
|
2183
|
-
vectorDbOptions.collection = (
|
|
2184
|
-
vectorDbOptions.indexName = (
|
|
2183
|
+
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 : "";
|
|
2184
|
+
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 : "";
|
|
2185
|
+
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 : "";
|
|
2186
|
+
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";
|
|
2185
2187
|
} else if (vectorProvider === "qdrant") {
|
|
2186
|
-
vectorDbOptions.baseUrl = (
|
|
2187
|
-
vectorDbOptions.apiKey = (
|
|
2188
|
+
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";
|
|
2189
|
+
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;
|
|
2188
2190
|
vectorDbOptions.dimensions = embeddingDimensions;
|
|
2189
2191
|
} else if (vectorProvider === "milvus") {
|
|
2190
|
-
vectorDbOptions.baseUrl = (
|
|
2192
|
+
vectorDbOptions.baseUrl = (_ca = readString(env, "MILVUS_URL")) != null ? _ca : "http://localhost:19530";
|
|
2191
2193
|
vectorDbOptions.apiKey = readString(env, "MILVUS_API_KEY");
|
|
2192
2194
|
} else if (vectorProvider === "chromadb") {
|
|
2193
|
-
vectorDbOptions.baseUrl = (
|
|
2195
|
+
vectorDbOptions.baseUrl = (_da = readString(env, "CHROMADB_URL")) != null ? _da : "http://localhost:8000";
|
|
2194
2196
|
} else if (vectorProvider === "weaviate") {
|
|
2195
|
-
vectorDbOptions.baseUrl = (
|
|
2197
|
+
vectorDbOptions.baseUrl = (_ea = readString(env, "WEAVIATE_URL")) != null ? _ea : "http://localhost:8080";
|
|
2196
2198
|
vectorDbOptions.apiKey = readString(env, "WEAVIATE_API_KEY");
|
|
2197
2199
|
} else if (vectorProvider === "redis") {
|
|
2198
|
-
vectorDbOptions.baseUrl = (
|
|
2200
|
+
vectorDbOptions.baseUrl = (_fa = readString(env, "REDIS_URL")) != null ? _fa : "";
|
|
2199
2201
|
vectorDbOptions.apiKey = readString(env, "REDIS_API_KEY");
|
|
2200
2202
|
} else if (vectorProvider === "rest") {
|
|
2201
|
-
vectorDbOptions.baseUrl = (
|
|
2203
|
+
vectorDbOptions.baseUrl = (_ga = readString(env, "VECTOR_DB_REST_URL")) != null ? _ga : "";
|
|
2202
2204
|
vectorDbOptions.headers = readString(env, "VECTOR_DB_REST_API_KEY") ? { "api-key": readString(env, "VECTOR_DB_REST_API_KEY") } : {};
|
|
2203
2205
|
} else if (vectorProvider === "universal_rest") {
|
|
2204
|
-
vectorDbOptions.baseUrl = (
|
|
2206
|
+
vectorDbOptions.baseUrl = (_ia = (_ha = readString(env, "VECTOR_BASE_URL")) != null ? _ha : readString(env, "VECTOR_DB_REST_URL")) != null ? _ia : "";
|
|
2205
2207
|
vectorDbOptions.profile = readString(env, "VECTOR_UNIVERSAL_PROFILE");
|
|
2206
2208
|
vectorDbOptions.headers = readString(env, "VECTOR_DB_REST_API_KEY") ? { Authorization: `Bearer ${readString(env, "VECTOR_DB_REST_API_KEY")}` } : {};
|
|
2207
2209
|
}
|
|
@@ -2220,8 +2222,8 @@ function getEnvConfig(env = process.env, base) {
|
|
|
2220
2222
|
// Anthropic needs a separate embedding provider; key kept for completeness
|
|
2221
2223
|
gemini: readString(env, "GEMINI_API_KEY"),
|
|
2222
2224
|
ollama: void 0,
|
|
2223
|
-
universal_rest: (
|
|
2224
|
-
custom: (
|
|
2225
|
+
universal_rest: (_ja = readString(env, "EMBEDDING_API_KEY")) != null ? _ja : readString(env, "OPENAI_API_KEY"),
|
|
2226
|
+
custom: (_ka = readString(env, "EMBEDDING_API_KEY")) != null ? _ka : readString(env, "OPENAI_API_KEY")
|
|
2225
2227
|
};
|
|
2226
2228
|
const DEFAULT_MODEL_BY_PROVIDER = {
|
|
2227
2229
|
openai: "gpt-4o",
|
|
@@ -2234,16 +2236,16 @@ function getEnvConfig(env = process.env, base) {
|
|
|
2234
2236
|
};
|
|
2235
2237
|
return __spreadProps(__spreadValues({
|
|
2236
2238
|
projectId,
|
|
2237
|
-
licenseKey: (
|
|
2239
|
+
licenseKey: (_ma = (_la = readString(env, "RETRIVORA_LICENSE_KEY")) != null ? _la : readString(env, "LICENSE_KEY")) != null ? _ma : base == null ? void 0 : base.licenseKey,
|
|
2238
2240
|
vectorDb: {
|
|
2239
2241
|
provider: vectorProvider,
|
|
2240
|
-
indexName: (
|
|
2242
|
+
indexName: (_oa = (_na = readString(env, "VECTOR_DB_INDEX")) != null ? _na : vectorDbOptions.indexName) != null ? _oa : "rag-index",
|
|
2241
2243
|
options: vectorDbOptions
|
|
2242
2244
|
},
|
|
2243
2245
|
llm: {
|
|
2244
2246
|
provider: llmProvider,
|
|
2245
|
-
model: (
|
|
2246
|
-
apiKey: (
|
|
2247
|
+
model: (_qa = (_pa = readString(env, "LLM_MODEL")) != null ? _pa : DEFAULT_MODEL_BY_PROVIDER[llmProvider]) != null ? _qa : "gpt-4o",
|
|
2248
|
+
apiKey: (_ra = llmApiKeyByProvider[llmProvider]) != null ? _ra : "",
|
|
2247
2249
|
baseUrl: readString(env, "LLM_BASE_URL"),
|
|
2248
2250
|
systemPrompt: readString(env, "LLM_SYSTEM_PROMPT"),
|
|
2249
2251
|
maxTokens: readNumber(env, "LLM_MAX_TOKENS", 4096),
|
|
@@ -2256,7 +2258,7 @@ function getEnvConfig(env = process.env, base) {
|
|
|
2256
2258
|
},
|
|
2257
2259
|
embedding: {
|
|
2258
2260
|
provider: embeddingProvider,
|
|
2259
|
-
model: (
|
|
2261
|
+
model: (_sa = readString(env, "EMBEDDING_MODEL")) != null ? _sa : "text-embedding-3-small",
|
|
2260
2262
|
apiKey: embeddingApiKeyByProvider[embeddingProvider],
|
|
2261
2263
|
baseUrl: readString(env, "EMBEDDING_BASE_URL"),
|
|
2262
2264
|
dimensions: embeddingDimensions,
|
|
@@ -2267,30 +2269,30 @@ function getEnvConfig(env = process.env, base) {
|
|
|
2267
2269
|
}
|
|
2268
2270
|
},
|
|
2269
2271
|
ui: {
|
|
2270
|
-
title: (
|
|
2271
|
-
subtitle: (
|
|
2272
|
-
primaryColor: (
|
|
2273
|
-
accentColor: (
|
|
2274
|
-
logoUrl: (
|
|
2275
|
-
placeholder: (
|
|
2276
|
-
showSources: ((
|
|
2277
|
-
welcomeMessage: (
|
|
2278
|
-
visualStyle: (
|
|
2279
|
-
borderRadius: (
|
|
2280
|
-
allowUpload: ((
|
|
2272
|
+
title: (_ua = (_ta = readString(env, "NEXT_PUBLIC_UI_TITLE")) != null ? _ta : readString(env, "UI_TITLE")) != null ? _ua : "AI Assistant",
|
|
2273
|
+
subtitle: (_wa = (_va = readString(env, "NEXT_PUBLIC_UI_SUBTITLE")) != null ? _va : readString(env, "UI_SUBTITLE")) != null ? _wa : "Powered by RAG",
|
|
2274
|
+
primaryColor: (_ya = (_xa = readString(env, "NEXT_PUBLIC_PRIMARY_COLOR")) != null ? _xa : readString(env, "UI_PRIMARY_COLOR")) != null ? _ya : "#10b981",
|
|
2275
|
+
accentColor: (_Aa = (_za = readString(env, "NEXT_PUBLIC_ACCENT_COLOR")) != null ? _za : readString(env, "UI_ACCENT_COLOR")) != null ? _Aa : "#3b82f6",
|
|
2276
|
+
logoUrl: (_Ba = readString(env, "NEXT_PUBLIC_LOGO_URL")) != null ? _Ba : readString(env, "UI_LOGO_URL"),
|
|
2277
|
+
placeholder: (_Da = (_Ca = readString(env, "NEXT_PUBLIC_PLACEHOLDER")) != null ? _Ca : readString(env, "UI_PLACEHOLDER")) != null ? _Da : "Ask me anything\u2026",
|
|
2278
|
+
showSources: ((_Fa = (_Ea = readString(env, "NEXT_PUBLIC_SHOW_SOURCES")) != null ? _Ea : readString(env, "UI_SHOW_SOURCES")) != null ? _Fa : "true") !== "false",
|
|
2279
|
+
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.",
|
|
2280
|
+
visualStyle: (_Ja = (_Ia = readString(env, "NEXT_PUBLIC_UI_VISUAL_STYLE")) != null ? _Ia : readString(env, "UI_VISUAL_STYLE")) != null ? _Ja : "glass",
|
|
2281
|
+
borderRadius: (_La = (_Ka = readString(env, "NEXT_PUBLIC_UI_BORDER_RADIUS")) != null ? _Ka : readString(env, "UI_BORDER_RADIUS")) != null ? _La : "xl",
|
|
2282
|
+
allowUpload: ((_Na = (_Ma = readString(env, "NEXT_PUBLIC_ALLOW_UPLOAD")) != null ? _Ma : readString(env, "UI_ALLOW_UPLOAD")) != null ? _Na : "false") === "true"
|
|
2281
2283
|
},
|
|
2282
2284
|
rag: {
|
|
2283
2285
|
topK: readNumber(env, "RAG_TOP_K", 5),
|
|
2284
2286
|
scoreThreshold: readNumber(env, "RAG_SCORE_THRESHOLD", 0),
|
|
2285
2287
|
chunkSize: readNumber(env, "RAG_CHUNK_SIZE", 1e3),
|
|
2286
2288
|
chunkOverlap: readNumber(env, "RAG_CHUNK_OVERLAP", 200),
|
|
2287
|
-
filterableFields: (
|
|
2289
|
+
filterableFields: (_Oa = readString(env, "RAG_FILTERABLE_FIELDS")) == null ? void 0 : _Oa.split(",").map((f) => f.trim()),
|
|
2288
2290
|
// Query pipeline toggles — read from .env.local
|
|
2289
2291
|
useQueryTransformation: readString(env, "RAG_USE_QUERY_TRANSFORMATION") === "true",
|
|
2290
2292
|
useReranking: readString(env, "RAG_USE_RERANKING") === "true",
|
|
2291
2293
|
useGraphRetrieval: readString(env, "RAG_USE_GRAPH_RETRIEVAL") === "true",
|
|
2292
|
-
architecture: (
|
|
2293
|
-
chunkingStrategy: (
|
|
2294
|
+
architecture: (_Pa = readString(env, "RAG_ARCHITECTURE")) != null ? _Pa : "simple",
|
|
2295
|
+
chunkingStrategy: (_Qa = readString(env, "RAG_CHUNKING_STRATEGY")) != null ? _Qa : "recursive",
|
|
2294
2296
|
uiMapping: (() => {
|
|
2295
2297
|
const raw = readString(env, "RAG_UI_MAPPING");
|
|
2296
2298
|
if (!raw) return void 0;
|
|
@@ -2302,8 +2304,8 @@ function getEnvConfig(env = process.env, base) {
|
|
|
2302
2304
|
})()
|
|
2303
2305
|
},
|
|
2304
2306
|
telemetry: {
|
|
2305
|
-
enabled:
|
|
2306
|
-
url: (
|
|
2307
|
+
enabled: telemetryEnabled,
|
|
2308
|
+
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"
|
|
2307
2309
|
}
|
|
2308
2310
|
}, readString(env, "GRAPH_DB_PROVIDER") ? {
|
|
2309
2311
|
graphDb: {
|
|
@@ -7482,7 +7484,7 @@ ${m.content}`).join("\n\n---\n\n");
|
|
|
7482
7484
|
*/
|
|
7483
7485
|
askStreamInternal(_0) {
|
|
7484
7486
|
return __asyncGenerator(this, arguments, function* (question, history = [], namespace) {
|
|
7485
|
-
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;
|
|
7487
|
+
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;
|
|
7486
7488
|
yield new __await(this.initialize());
|
|
7487
7489
|
const ns = namespace != null ? namespace : this.config.projectId;
|
|
7488
7490
|
const topK = (_b = (_a2 = this.config.rag) == null ? void 0 : _a2.topK) != null ? _b : 5;
|
|
@@ -7792,8 +7794,10 @@ ${context}`;
|
|
|
7792
7794
|
hallucinationReason: hScore.reason
|
|
7793
7795
|
} : {});
|
|
7794
7796
|
const trace = buildTrace(hallucinationResult);
|
|
7795
|
-
|
|
7796
|
-
|
|
7797
|
+
const isTelemetryActive = (_B = (_A = this.config.telemetry) == null ? void 0 : _A.enabled) != null ? _B : Boolean(this.config.licenseKey);
|
|
7798
|
+
if (isTelemetryActive) {
|
|
7799
|
+
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";
|
|
7800
|
+
const telemetryUrl = ((_C = this.config.telemetry) == null ? void 0 : _C.url) || process.env.TELEMETRY_URL || process.env.NEXT_PUBLIC_TELEMETRY_URL || defaultUrl;
|
|
7797
7801
|
const absoluteUrl = telemetryUrl.startsWith("http") ? telemetryUrl : (process.env.NEXT_PUBLIC_APP_URL || `http://localhost:${process.env.PORT || 3e3}`) + telemetryUrl;
|
|
7798
7802
|
(async () => {
|
|
7799
7803
|
try {
|
|
@@ -9049,6 +9053,43 @@ function getOrCreatePlugin(configOrPlugin) {
|
|
|
9049
9053
|
}
|
|
9050
9054
|
return _g[cacheKey];
|
|
9051
9055
|
}
|
|
9056
|
+
function reportTelemetry(req, plugin, action, status, details, trace) {
|
|
9057
|
+
var _a2;
|
|
9058
|
+
try {
|
|
9059
|
+
const config = plugin.getConfig();
|
|
9060
|
+
const licenseKey = config.licenseKey || process.env.RAG_LICENSE_KEY || process.env.RETRIVORA_LICENSE_KEY || process.env.NEXT_PUBLIC_RETRIVORA_LICENSE_KEY;
|
|
9061
|
+
const telemetryConfig = config.telemetry;
|
|
9062
|
+
const enabled = (_a2 = telemetryConfig == null ? void 0 : telemetryConfig.enabled) != null ? _a2 : Boolean(licenseKey);
|
|
9063
|
+
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";
|
|
9064
|
+
const telemetryUrl = (telemetryConfig == null ? void 0 : telemetryConfig.url) || process.env.TELEMETRY_URL || process.env.NEXT_PUBLIC_TELEMETRY_URL || defaultUrl;
|
|
9065
|
+
const host = req.headers.get("host") || "localhost";
|
|
9066
|
+
let absoluteUrl = telemetryUrl;
|
|
9067
|
+
if (!telemetryUrl.startsWith("http")) {
|
|
9068
|
+
const proto = req.headers.get("x-forwarded-proto") || "http";
|
|
9069
|
+
absoluteUrl = `${proto}://${host}${telemetryUrl}`;
|
|
9070
|
+
}
|
|
9071
|
+
const projectId = config.projectId || "default";
|
|
9072
|
+
fetch(absoluteUrl, {
|
|
9073
|
+
method: "POST",
|
|
9074
|
+
headers: {
|
|
9075
|
+
"Content-Type": "application/json",
|
|
9076
|
+
"x-forwarded-for": req.headers.get("x-forwarded-for") || "",
|
|
9077
|
+
"x-real-ip": req.headers.get("x-real-ip") || ""
|
|
9078
|
+
},
|
|
9079
|
+
body: JSON.stringify({
|
|
9080
|
+
trace,
|
|
9081
|
+
licenseKey,
|
|
9082
|
+
projectId,
|
|
9083
|
+
action,
|
|
9084
|
+
status,
|
|
9085
|
+
details
|
|
9086
|
+
})
|
|
9087
|
+
}).catch((err) => {
|
|
9088
|
+
console.warn("[Retrivora Telemetry] Async report warning:", err.message);
|
|
9089
|
+
});
|
|
9090
|
+
} catch (e) {
|
|
9091
|
+
}
|
|
9092
|
+
}
|
|
9052
9093
|
function sseFrame(payload) {
|
|
9053
9094
|
return `data: ${JSON.stringify(payload)}
|
|
9054
9095
|
|
|
@@ -9091,6 +9132,7 @@ function createChatHandler(configOrPlugin, options) {
|
|
|
9091
9132
|
const storage = new DatabaseStorage(plugin.getConfig());
|
|
9092
9133
|
const onAuthorize = options == null ? void 0 : options.onAuthorize;
|
|
9093
9134
|
return async function POST(req) {
|
|
9135
|
+
var _a2, _b, _c, _d;
|
|
9094
9136
|
const authResult = await checkAuth(req, onAuthorize);
|
|
9095
9137
|
if (authResult) return authResult;
|
|
9096
9138
|
const rateLimited = checkRateLimit(req);
|
|
@@ -9119,12 +9161,14 @@ function createChatHandler(configOrPlugin, options) {
|
|
|
9119
9161
|
uiTransformation: result.ui_transformation,
|
|
9120
9162
|
trace: result.trace
|
|
9121
9163
|
}).catch((err) => console.warn("[createChatHandler] Failed to save assistant message:", err));
|
|
9164
|
+
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);
|
|
9122
9165
|
return import_server.NextResponse.json(__spreadProps(__spreadValues({}, result), {
|
|
9123
9166
|
messageId: assistantMsgId,
|
|
9124
9167
|
userMessageId: userMsgId
|
|
9125
9168
|
}));
|
|
9126
9169
|
} catch (err) {
|
|
9127
9170
|
const message = err instanceof Error ? err.message : "Internal server error";
|
|
9171
|
+
reportTelemetry(req, plugin, "QUERY_GENERATION", "error", message);
|
|
9128
9172
|
return import_server.NextResponse.json({ error: message }, { status: 500 });
|
|
9129
9173
|
}
|
|
9130
9174
|
};
|
|
@@ -9167,7 +9211,7 @@ function createStreamHandler(configOrPlugin, options) {
|
|
|
9167
9211
|
let isActive = true;
|
|
9168
9212
|
const stream = new ReadableStream({
|
|
9169
9213
|
async start(controller) {
|
|
9170
|
-
var _a2;
|
|
9214
|
+
var _a2, _b, _c, _d, _e;
|
|
9171
9215
|
const enqueue = (text) => {
|
|
9172
9216
|
if (!isActive) return;
|
|
9173
9217
|
try {
|
|
@@ -9224,6 +9268,7 @@ function createStreamHandler(configOrPlugin, options) {
|
|
|
9224
9268
|
uiTransformation,
|
|
9225
9269
|
trace: responseChunk == null ? void 0 : responseChunk.trace
|
|
9226
9270
|
}).catch((err) => console.warn("[createStreamHandler] Failed to save assistant message:", err));
|
|
9271
|
+
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);
|
|
9227
9272
|
}
|
|
9228
9273
|
}
|
|
9229
9274
|
} catch (temp) {
|
|
@@ -9240,6 +9285,7 @@ function createStreamHandler(configOrPlugin, options) {
|
|
|
9240
9285
|
if (isActive) {
|
|
9241
9286
|
const errorMessage = streamError instanceof Error ? streamError.message : String(streamError);
|
|
9242
9287
|
console.error("[createStreamHandler] Stream error:", streamError);
|
|
9288
|
+
reportTelemetry(req, plugin, "QUERY_GENERATION", "error", errorMessage);
|
|
9243
9289
|
try {
|
|
9244
9290
|
enqueue(sseErrorFrame(errorMessage));
|
|
9245
9291
|
} catch (e) {
|
|
@@ -9276,9 +9322,11 @@ function createIngestHandler(configOrPlugin, options) {
|
|
|
9276
9322
|
return import_server.NextResponse.json({ error: "documents array is required" }, { status: 400 });
|
|
9277
9323
|
}
|
|
9278
9324
|
const results = await plugin.ingest(documents, namespace);
|
|
9325
|
+
reportTelemetry(req, plugin, "DOCUMENT_INGESTION", "success", `Ingested ${documents.length} document(s)`);
|
|
9279
9326
|
return import_server.NextResponse.json({ results });
|
|
9280
9327
|
} catch (err) {
|
|
9281
9328
|
const message = err instanceof Error ? err.message : "Internal server error";
|
|
9329
|
+
reportTelemetry(req, plugin, "DOCUMENT_INGESTION", "error", message);
|
|
9282
9330
|
return import_server.NextResponse.json({ error: message }, { status: 500 });
|
|
9283
9331
|
}
|
|
9284
9332
|
};
|
|
@@ -9377,9 +9425,11 @@ function createUploadHandler(configOrPlugin, options) {
|
|
|
9377
9425
|
}
|
|
9378
9426
|
}
|
|
9379
9427
|
const results = await plugin.ingest(documents, namespace);
|
|
9428
|
+
reportTelemetry(req, plugin, "DOCUMENT_INGESTION", "success", `Uploaded & ingested ${files.length} file(s)`);
|
|
9380
9429
|
return import_server.NextResponse.json({ message: "Upload successful", results });
|
|
9381
9430
|
} catch (err) {
|
|
9382
9431
|
const message = err instanceof Error ? err.message : "Upload failed";
|
|
9432
|
+
reportTelemetry(req, plugin, "DOCUMENT_INGESTION", "error", message);
|
|
9383
9433
|
return import_server.NextResponse.json({ error: message }, { status: 500 });
|
|
9384
9434
|
}
|
|
9385
9435
|
};
|
|
@@ -9387,19 +9437,30 @@ function createUploadHandler(configOrPlugin, options) {
|
|
|
9387
9437
|
function createSuggestionsHandler(configOrPlugin, options) {
|
|
9388
9438
|
const plugin = getOrCreatePlugin(configOrPlugin);
|
|
9389
9439
|
const onAuthorize = options == null ? void 0 : options.onAuthorize;
|
|
9390
|
-
return async function
|
|
9440
|
+
return async function handler(req) {
|
|
9391
9441
|
const authResult = await checkAuth(req, onAuthorize);
|
|
9392
9442
|
if (authResult) return authResult;
|
|
9393
9443
|
try {
|
|
9394
|
-
|
|
9395
|
-
|
|
9444
|
+
let query = "";
|
|
9445
|
+
let namespace = void 0;
|
|
9446
|
+
if (req.method === "POST") {
|
|
9447
|
+
const body = await req.json().catch(() => ({}));
|
|
9448
|
+
query = body.query || "";
|
|
9449
|
+
namespace = body.namespace;
|
|
9450
|
+
} else {
|
|
9451
|
+
const url = new URL(req.url);
|
|
9452
|
+
query = url.searchParams.get("query") || "";
|
|
9453
|
+
namespace = url.searchParams.get("namespace") || void 0;
|
|
9454
|
+
}
|
|
9396
9455
|
if (typeof query !== "string") {
|
|
9397
9456
|
return import_server.NextResponse.json({ error: "query is required" }, { status: 400 });
|
|
9398
9457
|
}
|
|
9399
9458
|
const suggestions = await plugin.getSuggestions(query, namespace);
|
|
9459
|
+
reportTelemetry(req, plugin, "AUTO_SUGGESTIONS", "success", `Fetched ${suggestions.length} suggestions for: ${query.slice(0, 30)}`);
|
|
9400
9460
|
return import_server.NextResponse.json({ suggestions });
|
|
9401
9461
|
} catch (err) {
|
|
9402
9462
|
const message = err instanceof Error ? err.message : "Internal server error";
|
|
9463
|
+
reportTelemetry(req, plugin, "AUTO_SUGGESTIONS", "error", message);
|
|
9403
9464
|
return import_server.NextResponse.json({ error: message }, { status: 500 });
|
|
9404
9465
|
}
|
|
9405
9466
|
};
|
|
@@ -9531,6 +9592,8 @@ function createRagHandler(configOrPlugin, options) {
|
|
|
9531
9592
|
switch (segment) {
|
|
9532
9593
|
case "health":
|
|
9533
9594
|
return healthHandler(req);
|
|
9595
|
+
case "suggestions":
|
|
9596
|
+
return suggestionsHandler(req);
|
|
9534
9597
|
case "history":
|
|
9535
9598
|
return historyHandler(req);
|
|
9536
9599
|
case "feedback":
|