@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
|
@@ -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 : "/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,9 @@ ${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 telemetryUrl = ((_C = this.config.telemetry) == null ? void 0 : _C.url) || "/api/telemetry";
|
|
7797
7800
|
const absoluteUrl = telemetryUrl.startsWith("http") ? telemetryUrl : (process.env.NEXT_PUBLIC_APP_URL || `http://localhost:${process.env.PORT || 3e3}`) + telemetryUrl;
|
|
7798
7801
|
(async () => {
|
|
7799
7802
|
try {
|
|
@@ -9049,6 +9052,43 @@ function getOrCreatePlugin(configOrPlugin) {
|
|
|
9049
9052
|
}
|
|
9050
9053
|
return _g[cacheKey];
|
|
9051
9054
|
}
|
|
9055
|
+
function reportTelemetry(req, plugin, action, status, details, trace) {
|
|
9056
|
+
var _a2;
|
|
9057
|
+
try {
|
|
9058
|
+
const config = plugin.getConfig();
|
|
9059
|
+
const licenseKey = config.licenseKey || process.env.RAG_LICENSE_KEY || process.env.RETRIVORA_LICENSE_KEY || process.env.NEXT_PUBLIC_RETRIVORA_LICENSE_KEY;
|
|
9060
|
+
const telemetryConfig = config.telemetry;
|
|
9061
|
+
const enabled = (_a2 = telemetryConfig == null ? void 0 : telemetryConfig.enabled) != null ? _a2 : Boolean(licenseKey);
|
|
9062
|
+
if (!enabled) return;
|
|
9063
|
+
const telemetryUrl = (telemetryConfig == null ? void 0 : telemetryConfig.url) || process.env.TELEMETRY_URL || process.env.NEXT_PUBLIC_TELEMETRY_URL || "/api/telemetry";
|
|
9064
|
+
const host = req.headers.get("host") || "localhost";
|
|
9065
|
+
let absoluteUrl = telemetryUrl;
|
|
9066
|
+
if (!telemetryUrl.startsWith("http")) {
|
|
9067
|
+
const proto = req.headers.get("x-forwarded-proto") || "http";
|
|
9068
|
+
absoluteUrl = `${proto}://${host}${telemetryUrl}`;
|
|
9069
|
+
}
|
|
9070
|
+
const projectId = config.projectId || "default";
|
|
9071
|
+
fetch(absoluteUrl, {
|
|
9072
|
+
method: "POST",
|
|
9073
|
+
headers: {
|
|
9074
|
+
"Content-Type": "application/json",
|
|
9075
|
+
"x-forwarded-for": req.headers.get("x-forwarded-for") || "",
|
|
9076
|
+
"x-real-ip": req.headers.get("x-real-ip") || ""
|
|
9077
|
+
},
|
|
9078
|
+
body: JSON.stringify({
|
|
9079
|
+
trace,
|
|
9080
|
+
licenseKey,
|
|
9081
|
+
projectId,
|
|
9082
|
+
action,
|
|
9083
|
+
status,
|
|
9084
|
+
details
|
|
9085
|
+
})
|
|
9086
|
+
}).catch((err) => {
|
|
9087
|
+
console.warn("[Retrivora Telemetry] Async report warning:", err.message);
|
|
9088
|
+
});
|
|
9089
|
+
} catch (e) {
|
|
9090
|
+
}
|
|
9091
|
+
}
|
|
9052
9092
|
function sseFrame(payload) {
|
|
9053
9093
|
return `data: ${JSON.stringify(payload)}
|
|
9054
9094
|
|
|
@@ -9091,6 +9131,7 @@ function createChatHandler(configOrPlugin, options) {
|
|
|
9091
9131
|
const storage = new DatabaseStorage(plugin.getConfig());
|
|
9092
9132
|
const onAuthorize = options == null ? void 0 : options.onAuthorize;
|
|
9093
9133
|
return async function POST(req) {
|
|
9134
|
+
var _a2, _b, _c, _d;
|
|
9094
9135
|
const authResult = await checkAuth(req, onAuthorize);
|
|
9095
9136
|
if (authResult) return authResult;
|
|
9096
9137
|
const rateLimited = checkRateLimit(req);
|
|
@@ -9119,12 +9160,14 @@ function createChatHandler(configOrPlugin, options) {
|
|
|
9119
9160
|
uiTransformation: result.ui_transformation,
|
|
9120
9161
|
trace: result.trace
|
|
9121
9162
|
}).catch((err) => console.warn("[createChatHandler] Failed to save assistant message:", err));
|
|
9163
|
+
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
9164
|
return import_server.NextResponse.json(__spreadProps(__spreadValues({}, result), {
|
|
9123
9165
|
messageId: assistantMsgId,
|
|
9124
9166
|
userMessageId: userMsgId
|
|
9125
9167
|
}));
|
|
9126
9168
|
} catch (err) {
|
|
9127
9169
|
const message = err instanceof Error ? err.message : "Internal server error";
|
|
9170
|
+
reportTelemetry(req, plugin, "QUERY_GENERATION", "error", message);
|
|
9128
9171
|
return import_server.NextResponse.json({ error: message }, { status: 500 });
|
|
9129
9172
|
}
|
|
9130
9173
|
};
|
|
@@ -9167,7 +9210,7 @@ function createStreamHandler(configOrPlugin, options) {
|
|
|
9167
9210
|
let isActive = true;
|
|
9168
9211
|
const stream = new ReadableStream({
|
|
9169
9212
|
async start(controller) {
|
|
9170
|
-
var _a2;
|
|
9213
|
+
var _a2, _b, _c, _d, _e;
|
|
9171
9214
|
const enqueue = (text) => {
|
|
9172
9215
|
if (!isActive) return;
|
|
9173
9216
|
try {
|
|
@@ -9224,6 +9267,7 @@ function createStreamHandler(configOrPlugin, options) {
|
|
|
9224
9267
|
uiTransformation,
|
|
9225
9268
|
trace: responseChunk == null ? void 0 : responseChunk.trace
|
|
9226
9269
|
}).catch((err) => console.warn("[createStreamHandler] Failed to save assistant message:", err));
|
|
9270
|
+
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
9271
|
}
|
|
9228
9272
|
}
|
|
9229
9273
|
} catch (temp) {
|
|
@@ -9240,6 +9284,7 @@ function createStreamHandler(configOrPlugin, options) {
|
|
|
9240
9284
|
if (isActive) {
|
|
9241
9285
|
const errorMessage = streamError instanceof Error ? streamError.message : String(streamError);
|
|
9242
9286
|
console.error("[createStreamHandler] Stream error:", streamError);
|
|
9287
|
+
reportTelemetry(req, plugin, "QUERY_GENERATION", "error", errorMessage);
|
|
9243
9288
|
try {
|
|
9244
9289
|
enqueue(sseErrorFrame(errorMessage));
|
|
9245
9290
|
} catch (e) {
|
|
@@ -9276,9 +9321,11 @@ function createIngestHandler(configOrPlugin, options) {
|
|
|
9276
9321
|
return import_server.NextResponse.json({ error: "documents array is required" }, { status: 400 });
|
|
9277
9322
|
}
|
|
9278
9323
|
const results = await plugin.ingest(documents, namespace);
|
|
9324
|
+
reportTelemetry(req, plugin, "DOCUMENT_INGESTION", "success", `Ingested ${documents.length} document(s)`);
|
|
9279
9325
|
return import_server.NextResponse.json({ results });
|
|
9280
9326
|
} catch (err) {
|
|
9281
9327
|
const message = err instanceof Error ? err.message : "Internal server error";
|
|
9328
|
+
reportTelemetry(req, plugin, "DOCUMENT_INGESTION", "error", message);
|
|
9282
9329
|
return import_server.NextResponse.json({ error: message }, { status: 500 });
|
|
9283
9330
|
}
|
|
9284
9331
|
};
|
|
@@ -9377,9 +9424,11 @@ function createUploadHandler(configOrPlugin, options) {
|
|
|
9377
9424
|
}
|
|
9378
9425
|
}
|
|
9379
9426
|
const results = await plugin.ingest(documents, namespace);
|
|
9427
|
+
reportTelemetry(req, plugin, "DOCUMENT_INGESTION", "success", `Uploaded & ingested ${files.length} file(s)`);
|
|
9380
9428
|
return import_server.NextResponse.json({ message: "Upload successful", results });
|
|
9381
9429
|
} catch (err) {
|
|
9382
9430
|
const message = err instanceof Error ? err.message : "Upload failed";
|
|
9431
|
+
reportTelemetry(req, plugin, "DOCUMENT_INGESTION", "error", message);
|
|
9383
9432
|
return import_server.NextResponse.json({ error: message }, { status: 500 });
|
|
9384
9433
|
}
|
|
9385
9434
|
};
|
|
@@ -9387,19 +9436,30 @@ function createUploadHandler(configOrPlugin, options) {
|
|
|
9387
9436
|
function createSuggestionsHandler(configOrPlugin, options) {
|
|
9388
9437
|
const plugin = getOrCreatePlugin(configOrPlugin);
|
|
9389
9438
|
const onAuthorize = options == null ? void 0 : options.onAuthorize;
|
|
9390
|
-
return async function
|
|
9439
|
+
return async function handler(req) {
|
|
9391
9440
|
const authResult = await checkAuth(req, onAuthorize);
|
|
9392
9441
|
if (authResult) return authResult;
|
|
9393
9442
|
try {
|
|
9394
|
-
|
|
9395
|
-
|
|
9443
|
+
let query = "";
|
|
9444
|
+
let namespace = void 0;
|
|
9445
|
+
if (req.method === "POST") {
|
|
9446
|
+
const body = await req.json().catch(() => ({}));
|
|
9447
|
+
query = body.query || "";
|
|
9448
|
+
namespace = body.namespace;
|
|
9449
|
+
} else {
|
|
9450
|
+
const url = new URL(req.url);
|
|
9451
|
+
query = url.searchParams.get("query") || "";
|
|
9452
|
+
namespace = url.searchParams.get("namespace") || void 0;
|
|
9453
|
+
}
|
|
9396
9454
|
if (typeof query !== "string") {
|
|
9397
9455
|
return import_server.NextResponse.json({ error: "query is required" }, { status: 400 });
|
|
9398
9456
|
}
|
|
9399
9457
|
const suggestions = await plugin.getSuggestions(query, namespace);
|
|
9458
|
+
reportTelemetry(req, plugin, "AUTO_SUGGESTIONS", "success", `Fetched ${suggestions.length} suggestions for: ${query.slice(0, 30)}`);
|
|
9400
9459
|
return import_server.NextResponse.json({ suggestions });
|
|
9401
9460
|
} catch (err) {
|
|
9402
9461
|
const message = err instanceof Error ? err.message : "Internal server error";
|
|
9462
|
+
reportTelemetry(req, plugin, "AUTO_SUGGESTIONS", "error", message);
|
|
9403
9463
|
return import_server.NextResponse.json({ error: message }, { status: 500 });
|
|
9404
9464
|
}
|
|
9405
9465
|
};
|
|
@@ -9531,6 +9591,8 @@ function createRagHandler(configOrPlugin, options) {
|
|
|
9531
9591
|
switch (segment) {
|
|
9532
9592
|
case "health":
|
|
9533
9593
|
return healthHandler(req);
|
|
9594
|
+
case "suggestions":
|
|
9595
|
+
return suggestionsHandler(req);
|
|
9534
9596
|
case "history":
|
|
9535
9597
|
return historyHandler(req);
|
|
9536
9598
|
case "feedback":
|