@retrivora-ai/rag-engine 1.9.8 → 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/README.md +36 -28
- package/dist/{ILLMProvider-B8ROITYK.d.mts → ILLMProvider-DMxLyTdq.d.mts} +2 -2
- package/dist/{ILLMProvider-B8ROITYK.d.ts → ILLMProvider-DMxLyTdq.d.ts} +2 -2
- package/dist/handlers/index.d.mts +2 -2
- package/dist/handlers/index.d.ts +2 -2
- package/dist/handlers/index.js +248 -74
- package/dist/handlers/index.mjs +254 -74
- package/dist/{index-DNvoi-sV.d.ts → index-CfkqZd2Y.d.ts} +1 -1
- package/dist/{index-BCPKUAVL.d.ts → index-DHsFLJXQ.d.mts} +2 -31
- package/dist/{index-CrxCy36A.d.mts → index-tzwc7UhY.d.ts} +2 -31
- package/dist/{index-B8PbEFSY.d.mts → index-xygonxpW.d.mts} +1 -1
- package/dist/index.css +485 -557
- package/dist/index.d.mts +16 -10
- package/dist/index.d.ts +16 -10
- package/dist/index.js +36 -768
- package/dist/index.mjs +32 -782
- package/dist/server.d.mts +8 -5
- package/dist/server.d.ts +8 -5
- package/dist/server.js +249 -74
- package/dist/server.mjs +255 -74
- package/package.json +3 -2
- package/src/app/page.tsx +2 -0
- package/src/components/ChatWindow.tsx +14 -3
- package/src/components/constants.tsx +224 -0
- package/src/config/RagConfig.ts +2 -2
- package/src/config/serverConfig.ts +14 -1
- package/src/core/ConfigResolver.ts +32 -6
- package/src/core/LicenseVerifier.ts +106 -0
- package/src/core/Pipeline.ts +11 -8
- package/src/core/Retrivora.ts +1 -0
- package/src/handlers/index.ts +84 -48
- package/src/index.ts +3 -5
- package/src/components/AmbientBackground.tsx +0 -29
- package/src/components/ArchitectureCard.tsx +0 -53
- package/src/components/ArchitectureCardsSection.tsx +0 -48
- package/src/components/DocViewer.tsx +0 -97
- package/src/components/Documentation.tsx +0 -141
- package/src/components/Hero.tsx +0 -142
- package/src/components/Lifecycle.tsx +0 -77
- package/src/components/Navbar.tsx +0 -55
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 = (
|
|
2218
|
-
vectorDbOptions.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 = (
|
|
2221
|
-
vectorDbOptions.tables = (
|
|
2222
|
-
vectorDbOptions.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 = (
|
|
2226
|
-
vectorDbOptions.database = (
|
|
2227
|
-
vectorDbOptions.collection = (
|
|
2228
|
-
vectorDbOptions.indexName = (
|
|
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 = (
|
|
2231
|
-
vectorDbOptions.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 = (
|
|
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 = (
|
|
2239
|
+
vectorDbOptions.baseUrl = (_da = readString(env, "CHROMADB_URL")) != null ? _da : "http://localhost:8000";
|
|
2238
2240
|
} else if (vectorProvider === "weaviate") {
|
|
2239
|
-
vectorDbOptions.baseUrl = (
|
|
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 = (
|
|
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 = (
|
|
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 = (
|
|
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: (
|
|
2268
|
-
custom: (
|
|
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: (
|
|
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: (
|
|
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: (
|
|
2290
|
-
apiKey: (
|
|
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: (
|
|
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: (
|
|
2315
|
-
subtitle: (
|
|
2316
|
-
primaryColor: (
|
|
2317
|
-
accentColor: (
|
|
2318
|
-
logoUrl: (
|
|
2319
|
-
placeholder: (
|
|
2320
|
-
showSources: ((
|
|
2321
|
-
welcomeMessage: (
|
|
2322
|
-
visualStyle: (
|
|
2323
|
-
borderRadius: (
|
|
2324
|
-
allowUpload: ((
|
|
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: (
|
|
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: (
|
|
2337
|
-
chunkingStrategy: (
|
|
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:
|
|
2350
|
-
url: (
|
|
2351
|
+
enabled: telemetryEnabled,
|
|
2352
|
+
url: (_Ua = (_Ta = (_Ra = readString(env, "TELEMETRY_URL")) != null ? _Ra : readString(env, "NEXT_PUBLIC_TELEMETRY_URL")) != null ? _Ta : (_Sa = base == null ? void 0 : base.telemetry) == null ? void 0 : _Sa.url) != null ? _Ua : "/api/telemetry"
|
|
2351
2353
|
}
|
|
2352
2354
|
}, readString(env, "GRAPH_DB_PROVIDER") ? {
|
|
2353
2355
|
graphDb: {
|
|
@@ -2429,7 +2431,7 @@ var ConfigResolver = class {
|
|
|
2429
2431
|
}
|
|
2430
2432
|
}
|
|
2431
2433
|
static mergeRetrievalWorkflow(rag, retrieval, workflow) {
|
|
2432
|
-
var _a2, _b, _c, _d, _e;
|
|
2434
|
+
var _a2, _b, _c, _d, _e, _f;
|
|
2433
2435
|
if (!rag && !retrieval && !workflow) return void 0;
|
|
2434
2436
|
const normalized = __spreadValues({}, rag != null ? rag : {});
|
|
2435
2437
|
if (retrieval) {
|
|
@@ -2437,20 +2439,44 @@ var ConfigResolver = class {
|
|
|
2437
2439
|
normalized.scoreThreshold = (_b = retrieval.scoreThreshold) != null ? _b : normalized.scoreThreshold;
|
|
2438
2440
|
normalized.useReranking = (_c = retrieval.useReranking) != null ? _c : normalized.useReranking;
|
|
2439
2441
|
if (retrieval.strategy === "hybrid") normalized.architecture = (_d = normalized.architecture) != null ? _d : "hybrid";
|
|
2440
|
-
if (retrieval.strategy === "agentic") normalized.architecture = "
|
|
2441
|
-
if (retrieval.strategy === "contextual-compression")
|
|
2442
|
+
if (retrieval.strategy === "agentic") normalized.architecture = "multi-agent";
|
|
2443
|
+
if (retrieval.strategy === "contextual-compression") {
|
|
2444
|
+
normalized.useReranking = true;
|
|
2445
|
+
normalized.architecture = (_e = normalized.architecture) != null ? _e : "retrieve-and-rerank";
|
|
2446
|
+
}
|
|
2442
2447
|
}
|
|
2443
2448
|
if (workflow == null ? void 0 : workflow.type) {
|
|
2444
2449
|
const type = workflow.type;
|
|
2445
|
-
if (type === "
|
|
2446
|
-
|
|
2447
|
-
|
|
2450
|
+
if (type === "naive-rag") {
|
|
2451
|
+
normalized.architecture = "naive";
|
|
2452
|
+
normalized.useReranking = false;
|
|
2453
|
+
normalized.useGraphRetrieval = false;
|
|
2454
|
+
} else if (type === "retrieve-and-rerank") {
|
|
2455
|
+
normalized.architecture = "retrieve-and-rerank";
|
|
2456
|
+
normalized.useReranking = true;
|
|
2457
|
+
} else if (type === "multimodal-rag") {
|
|
2458
|
+
normalized.architecture = "multimodal";
|
|
2459
|
+
} else if (type === "graph-rag") {
|
|
2448
2460
|
normalized.architecture = "graph";
|
|
2449
2461
|
normalized.useGraphRetrieval = true;
|
|
2462
|
+
} else if (type === "hybrid-rag") {
|
|
2463
|
+
normalized.architecture = "hybrid";
|
|
2464
|
+
} else if (type === "agentic-router") {
|
|
2465
|
+
normalized.architecture = "agentic-router";
|
|
2466
|
+
} else if (type === "multi-agent-rag" || type === "multi-agent" || type === "agentic" || type === "agentic-rag") {
|
|
2467
|
+
normalized.architecture = "multi-agent";
|
|
2450
2468
|
} else if (type === "simple-rag" || type === "rag") {
|
|
2451
|
-
normalized.architecture = (
|
|
2469
|
+
normalized.architecture = (_f = normalized.architecture) != null ? _f : "naive";
|
|
2452
2470
|
}
|
|
2453
2471
|
}
|
|
2472
|
+
if (normalized.architecture === "retrieve-and-rerank") {
|
|
2473
|
+
normalized.useReranking = true;
|
|
2474
|
+
} else if (normalized.architecture === "graph") {
|
|
2475
|
+
normalized.useGraphRetrieval = true;
|
|
2476
|
+
} else if (normalized.architecture === "naive") {
|
|
2477
|
+
normalized.useReranking = false;
|
|
2478
|
+
normalized.useGraphRetrieval = false;
|
|
2479
|
+
}
|
|
2454
2480
|
return normalized;
|
|
2455
2481
|
}
|
|
2456
2482
|
};
|
|
@@ -4305,6 +4331,19 @@ var LicenseVerifier = class {
|
|
|
4305
4331
|
*/
|
|
4306
4332
|
static verify(licenseKey, currentProjectId, provider, publicKeyOverride) {
|
|
4307
4333
|
const isProduction = process.env.NODE_ENV === "production";
|
|
4334
|
+
const now = Date.now();
|
|
4335
|
+
if (licenseKey) {
|
|
4336
|
+
const cacheKey = `${licenseKey}:${currentProjectId}:${provider || ""}:${publicKeyOverride || ""}`;
|
|
4337
|
+
const cached = this.cache.get(cacheKey);
|
|
4338
|
+
if (cached && now - cached.cachedAt < this.CACHE_TTL_MS) {
|
|
4339
|
+
const currentTimestampSec = Math.floor(now / 1e3);
|
|
4340
|
+
if (cached.payload.expiresAt && currentTimestampSec > cached.payload.expiresAt) {
|
|
4341
|
+
this.cache.delete(cacheKey);
|
|
4342
|
+
} else {
|
|
4343
|
+
return cached.payload;
|
|
4344
|
+
}
|
|
4345
|
+
}
|
|
4346
|
+
}
|
|
4308
4347
|
if (!licenseKey) {
|
|
4309
4348
|
if (isProduction) {
|
|
4310
4349
|
throw new ConfigurationException(
|
|
@@ -4391,6 +4430,10 @@ var LicenseVerifier = class {
|
|
|
4391
4430
|
}
|
|
4392
4431
|
}
|
|
4393
4432
|
}
|
|
4433
|
+
if (licenseKey) {
|
|
4434
|
+
const cacheKey = `${licenseKey}:${currentProjectId}:${provider || ""}:${publicKeyOverride || ""}`;
|
|
4435
|
+
this.cache.set(cacheKey, { payload, cachedAt: now });
|
|
4436
|
+
}
|
|
4394
4437
|
return payload;
|
|
4395
4438
|
} catch (err) {
|
|
4396
4439
|
const message = err instanceof Error ? err.message : String(err);
|
|
@@ -4399,7 +4442,76 @@ var LicenseVerifier = class {
|
|
|
4399
4442
|
);
|
|
4400
4443
|
}
|
|
4401
4444
|
}
|
|
4445
|
+
static async verifyIP(licenseKey) {
|
|
4446
|
+
if (!licenseKey) return;
|
|
4447
|
+
try {
|
|
4448
|
+
const parts = licenseKey.split(".");
|
|
4449
|
+
if (parts.length !== 3) return;
|
|
4450
|
+
const [, payloadB64] = parts;
|
|
4451
|
+
const payload = JSON.parse(
|
|
4452
|
+
Buffer.from(payloadB64, "base64url").toString("utf8")
|
|
4453
|
+
);
|
|
4454
|
+
const tier = (payload.tier || "").toLowerCase();
|
|
4455
|
+
if (tier === "enterprise" || tier === "custom") {
|
|
4456
|
+
return;
|
|
4457
|
+
}
|
|
4458
|
+
if (payload.ipv4 || payload.ipv6) {
|
|
4459
|
+
let currentIpv4 = "";
|
|
4460
|
+
let currentIpv6 = "";
|
|
4461
|
+
try {
|
|
4462
|
+
const res = await fetch("https://api4.ipify.org?format=json", { signal: AbortSignal.timeout(3e3) });
|
|
4463
|
+
const data = await res.json();
|
|
4464
|
+
currentIpv4 = data.ip;
|
|
4465
|
+
} catch (e) {
|
|
4466
|
+
}
|
|
4467
|
+
try {
|
|
4468
|
+
const res = await fetch("https://api6.ipify.org?format=json", { signal: AbortSignal.timeout(3e3) });
|
|
4469
|
+
const data = await res.json();
|
|
4470
|
+
currentIpv6 = data.ip;
|
|
4471
|
+
} catch (e) {
|
|
4472
|
+
}
|
|
4473
|
+
const localIps = [];
|
|
4474
|
+
try {
|
|
4475
|
+
const osModule = require("os");
|
|
4476
|
+
const interfaces = osModule.networkInterfaces();
|
|
4477
|
+
for (const name of Object.keys(interfaces)) {
|
|
4478
|
+
for (const iface of interfaces[name] || []) {
|
|
4479
|
+
if (!iface.internal) {
|
|
4480
|
+
localIps.push(iface.address);
|
|
4481
|
+
}
|
|
4482
|
+
}
|
|
4483
|
+
}
|
|
4484
|
+
} catch (e) {
|
|
4485
|
+
}
|
|
4486
|
+
const isIpv4Match = payload.ipv4 && (currentIpv4 === payload.ipv4 || localIps.includes(payload.ipv4));
|
|
4487
|
+
const isIpv6Match = payload.ipv6 && (currentIpv6 === payload.ipv6 || localIps.includes(payload.ipv6));
|
|
4488
|
+
if (payload.ipv4 && payload.ipv6) {
|
|
4489
|
+
if (!isIpv4Match && !isIpv6Match) {
|
|
4490
|
+
throw new Error(
|
|
4491
|
+
`License key access restricted. This license key was created for a different system (authorized IPv4: ${payload.ipv4}, IPv6: ${payload.ipv6}) and cannot be used on this machine.`
|
|
4492
|
+
);
|
|
4493
|
+
}
|
|
4494
|
+
} else if (payload.ipv4 && !isIpv4Match) {
|
|
4495
|
+
throw new Error(
|
|
4496
|
+
`License key access restricted. This license key was created for a different system (authorized IPv4: ${payload.ipv4}) and cannot be used on this machine.`
|
|
4497
|
+
);
|
|
4498
|
+
} else if (payload.ipv6 && !isIpv6Match) {
|
|
4499
|
+
throw new Error(
|
|
4500
|
+
`License key access restricted. This license key was created for a different system (authorized IPv6: ${payload.ipv6}) and cannot be used on this machine.`
|
|
4501
|
+
);
|
|
4502
|
+
}
|
|
4503
|
+
}
|
|
4504
|
+
} catch (err) {
|
|
4505
|
+
if (err.message.includes("License key access restricted")) {
|
|
4506
|
+
throw new ConfigurationException(`[Retrivora SDK] ${err.message}`);
|
|
4507
|
+
}
|
|
4508
|
+
}
|
|
4509
|
+
}
|
|
4402
4510
|
};
|
|
4511
|
+
// A simple in-memory cache to save CPU overhead of cryptographic signature checks.
|
|
4512
|
+
LicenseVerifier.cache = /* @__PURE__ */ new Map();
|
|
4513
|
+
LicenseVerifier.CACHE_TTL_MS = 60 * 1e3;
|
|
4514
|
+
// Cache verified license for 60 seconds
|
|
4403
4515
|
// Retrivora's Public Key used to verify the license key signature.
|
|
4404
4516
|
// In production, this matches the private key held by Retrivora SaaS.
|
|
4405
4517
|
LicenseVerifier.PUBLIC_KEY = `-----BEGIN PUBLIC KEY-----
|
|
@@ -7360,7 +7472,7 @@ var Pipeline = class {
|
|
|
7360
7472
|
return this.initialised ? this.llmProvider : void 0;
|
|
7361
7473
|
}
|
|
7362
7474
|
async initialize() {
|
|
7363
|
-
var _a2, _b, _c;
|
|
7475
|
+
var _a2, _b, _c, _d;
|
|
7364
7476
|
if (this.initialised) return;
|
|
7365
7477
|
const chartInstruction = `You are a helpful assistant. Use the provided context to answer questions accurately.
|
|
7366
7478
|
|
|
@@ -7403,7 +7515,7 @@ var Pipeline = class {
|
|
|
7403
7515
|
this.entityExtractor = new EntityExtractor(this.llmProvider);
|
|
7404
7516
|
}
|
|
7405
7517
|
await this.vectorDB.initialize();
|
|
7406
|
-
if (((_a2 = this.config.rag) == null ? void 0 : _a2.architecture) === "agentic" || this.config.mcpServers && this.config.mcpServers.length > 0) {
|
|
7518
|
+
if (((_a2 = this.config.rag) == null ? void 0 : _a2.architecture) === "agentic" || ((_b = this.config.rag) == null ? void 0 : _b.architecture) === "multi-agent" || this.config.mcpServers && this.config.mcpServers.length > 0) {
|
|
7407
7519
|
this.mcpRegistry = new MCPRegistry(this.config.mcpServers || []);
|
|
7408
7520
|
this.multiAgentCoordinator = new MultiAgentCoordinator({
|
|
7409
7521
|
llmProvider: this.llmProvider,
|
|
@@ -7415,7 +7527,7 @@ var Pipeline = class {
|
|
|
7415
7527
|
this.agent = new LangChainAgent(this, this.config);
|
|
7416
7528
|
await this.agent.initialize(this.llmProvider);
|
|
7417
7529
|
}
|
|
7418
|
-
if ((
|
|
7530
|
+
if ((_d = (_c = this.config.rag) == null ? void 0 : _c.cag) == null ? void 0 : _d.enabled) {
|
|
7419
7531
|
await this.loadColdContext(this.config.projectId);
|
|
7420
7532
|
}
|
|
7421
7533
|
this.initialised = true;
|
|
@@ -7578,9 +7690,9 @@ ${m.content}`).join("\n\n---\n\n");
|
|
|
7578
7690
|
return { reply, sources };
|
|
7579
7691
|
}
|
|
7580
7692
|
async ask(question, history = [], namespace) {
|
|
7581
|
-
var _a2;
|
|
7693
|
+
var _a2, _b;
|
|
7582
7694
|
await this.initialize();
|
|
7583
|
-
if ((((_a2 = this.config.rag) == null ? void 0 : _a2.architecture) === "agentic" || this.config.mcpServers && this.config.mcpServers.length > 0) && this.multiAgentCoordinator) {
|
|
7695
|
+
if ((((_a2 = this.config.rag) == null ? void 0 : _a2.architecture) === "agentic" || ((_b = this.config.rag) == null ? void 0 : _b.architecture) === "multi-agent" || this.config.mcpServers && this.config.mcpServers.length > 0) && this.multiAgentCoordinator) {
|
|
7584
7696
|
return await this.multiAgentCoordinator.run(question, history);
|
|
7585
7697
|
}
|
|
7586
7698
|
const stream = this.askStream(question, history, namespace);
|
|
@@ -7615,9 +7727,9 @@ ${m.content}`).join("\n\n---\n\n");
|
|
|
7615
7727
|
}
|
|
7616
7728
|
askStream(_0) {
|
|
7617
7729
|
return __asyncGenerator(this, arguments, function* (question, history = [], namespace) {
|
|
7618
|
-
var _a2;
|
|
7730
|
+
var _a2, _b;
|
|
7619
7731
|
yield new __await(this.initialize());
|
|
7620
|
-
if ((((_a2 = this.config.rag) == null ? void 0 : _a2.architecture) === "agentic" || this.config.mcpServers && this.config.mcpServers.length > 0) && this.multiAgentCoordinator) {
|
|
7732
|
+
if ((((_a2 = this.config.rag) == null ? void 0 : _a2.architecture) === "agentic" || ((_b = this.config.rag) == null ? void 0 : _b.architecture) === "multi-agent" || this.config.mcpServers && this.config.mcpServers.length > 0) && this.multiAgentCoordinator) {
|
|
7621
7733
|
const stream2 = this.multiAgentCoordinator.runStream(question, history);
|
|
7622
7734
|
try {
|
|
7623
7735
|
for (var iter = __forAwait(stream2), more, temp, error; more = !(temp = yield new __await(iter.next())).done; more = false) {
|
|
@@ -7666,7 +7778,7 @@ ${m.content}`).join("\n\n---\n\n");
|
|
|
7666
7778
|
*/
|
|
7667
7779
|
askStreamInternal(_0) {
|
|
7668
7780
|
return __asyncGenerator(this, arguments, function* (question, history = [], namespace) {
|
|
7669
|
-
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;
|
|
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;
|
|
7670
7782
|
yield new __await(this.initialize());
|
|
7671
7783
|
const ns = namespace != null ? namespace : this.config.projectId;
|
|
7672
7784
|
const topK = (_b = (_a2 = this.config.rag) == null ? void 0 : _a2.topK) != null ? _b : 5;
|
|
@@ -7689,13 +7801,14 @@ ${m.content}`).join("\n\n---\n\n");
|
|
|
7689
7801
|
const embedStart = performance.now();
|
|
7690
7802
|
const cacheKey = `${ns}::${searchQuery}`;
|
|
7691
7803
|
const cachedVector = this.embeddingCache.get(cacheKey);
|
|
7692
|
-
const
|
|
7804
|
+
const arch = (_h = this.config.rag) == null ? void 0 : _h.architecture;
|
|
7805
|
+
const useGraph = arch !== "naive" && arch !== "retrieve-and-rerank" && this.graphDB && ((_i = this.config.rag) == null ? void 0 : _i.useGraphRetrieval);
|
|
7693
7806
|
const [strategyResult, embeddedVector] = yield new __await(Promise.all([
|
|
7694
7807
|
QueryProcessor.determineRetrievalStrategy(
|
|
7695
7808
|
searchQuery,
|
|
7696
7809
|
useGraph ? this.llmRouter.get("fast") : void 0,
|
|
7697
|
-
(
|
|
7698
|
-
(
|
|
7810
|
+
(_j = this.config.rag) == null ? void 0 : _j.graphKeywords,
|
|
7811
|
+
(_k = this.config.rag) == null ? void 0 : _k.vectorKeywords
|
|
7699
7812
|
),
|
|
7700
7813
|
// Embed immediately regardless of strategy — costs nothing if cached.
|
|
7701
7814
|
// If strategy turns out to be 'graph'-only we just won't use the vector.
|
|
@@ -7705,7 +7818,7 @@ ${m.content}`).join("\n\n---\n\n");
|
|
|
7705
7818
|
if (!cachedVector && queryVector.length > 0) {
|
|
7706
7819
|
this.embeddingCache.set(cacheKey, queryVector);
|
|
7707
7820
|
}
|
|
7708
|
-
const graphData = (strategyResult === "graph" || strategyResult === "both") && this.graphDB && ((
|
|
7821
|
+
const graphData = (strategyResult === "graph" || strategyResult === "both") && this.graphDB && ((_l = this.config.rag) == null ? void 0 : _l.useGraphRetrieval) ? yield new __await(this.graphDB.query(searchQuery)) : void 0;
|
|
7709
7822
|
const hasMetadataFilter = filter.metadata && Object.keys(filter.metadata).length > 0;
|
|
7710
7823
|
const hasNumericPredicates = Array.isArray(filter.__numericPredicates) && filter.__numericPredicates.length > 0;
|
|
7711
7824
|
const wantsExhaustiveList = hasNumericPredicates || hasMetadataFilter || /\b(list|all|show|provide|give|get|browse|find|search|display)\b/i.test(question);
|
|
@@ -7718,7 +7831,8 @@ ${m.content}`).join("\n\n---\n\n");
|
|
|
7718
7831
|
const structuredSources = this.applyStructuredFilters(rawSources, filter);
|
|
7719
7832
|
let fullSources = hasNumericPredicates ? structuredSources : structuredSources.filter((m) => m.score >= scoreThreshold);
|
|
7720
7833
|
const rerankLimit = wantsExhaustiveList ? retrievalLimit : topK;
|
|
7721
|
-
|
|
7834
|
+
const useReranking = arch !== "naive" && (arch === "retrieve-and-rerank" || ((_m = this.config.rag) == null ? void 0 : _m.useReranking));
|
|
7835
|
+
if (!hasNumericPredicates && useReranking) {
|
|
7722
7836
|
fullSources = yield new __await(this.reranker.rerank(fullSources, question, rerankLimit));
|
|
7723
7837
|
} else if (!wantsExhaustiveList) {
|
|
7724
7838
|
fullSources = fullSources.slice(0, topK);
|
|
@@ -7748,7 +7862,7 @@ ${graphContext}
|
|
|
7748
7862
|
VECTOR CONTEXT:
|
|
7749
7863
|
${context}`;
|
|
7750
7864
|
}
|
|
7751
|
-
if ((
|
|
7865
|
+
if ((_o = (_n = this.config.rag) == null ? void 0 : _n.cag) == null ? void 0 : _o.enabled) {
|
|
7752
7866
|
if (!this.coldContexts.has(ns)) {
|
|
7753
7867
|
yield new __await(this.loadColdContext(ns));
|
|
7754
7868
|
}
|
|
@@ -7801,10 +7915,10 @@ ${context}`;
|
|
|
7801
7915
|
let hallucinationScoringPromise = Promise.resolve(void 0);
|
|
7802
7916
|
const restrictionSuffix = "\n\n(IMPORTANT: Format your response beautifully using rich Markdown! Use bolding for emphasis, headings (##) for structure, bullet points for lists, and proper line breaks between paragraphs to make it highly readable. However, NEVER generate Markdown tables, HTML figures, or text charts (the UI renders requested charts separately, so NEVER say you cannot create, display, draw, render, or provide a chart/visualization). If listing products, use simple markdown bullet points or comma-separated names. NEVER use plus signs (+) to separate product names, category names, or list items. For product description/detail questions, provide customer-facing prose only and do NOT list internal catalog fields such as Handle, Body (HTML), Vendor, Type, Tags, Published, Option, Variant, SKU, or raw metadata labels. You CAN use numbers for years/counts like 2006 or 5800, but NEVER put a dollar sign ($) before them.)";
|
|
7803
7917
|
const isClaude37 = this.config.llm.model.includes("claude-3-7-sonnet");
|
|
7804
|
-
const isNativeThinking = isClaude37 && (((
|
|
7918
|
+
const isNativeThinking = isClaude37 && (((_p = this.config.llm.options) == null ? void 0 : _p.thinking) === true || ((_q = this.config.llm.options) == null ? void 0 : _q.thinking) === "enabled" || ((_r = this.config.llm.options) == null ? void 0 : _r.thinking) !== false);
|
|
7805
7919
|
const modelNameLower = this.config.llm.model.toLowerCase();
|
|
7806
7920
|
const isReasoningModel = modelNameLower.includes("-r1") || modelNameLower.includes("deepseek-r1") || modelNameLower.includes("reasoning") || modelNameLower.includes("thinking");
|
|
7807
|
-
const isSimulatedThinking = !isNativeThinking && (((
|
|
7921
|
+
const isSimulatedThinking = !isNativeThinking && (((_s = this.config.llm.options) == null ? void 0 : _s.thinking) === true || ((_t = this.config.llm.options) == null ? void 0 : _t.thinking) === "enabled" || isReasoningModel && ((_u = this.config.llm.options) == null ? void 0 : _u.thinking) !== false);
|
|
7808
7922
|
let finalRestrictionSuffix = restrictionSuffix;
|
|
7809
7923
|
if (isSimulatedThinking) {
|
|
7810
7924
|
finalRestrictionSuffix += "\n\n(IMPORTANT: You must think step-by-step before answering. Write your thinking process inside a `<think>...</think>` block. Write the `<think>` block first, then follow it with your final response. Keep the thinking process thorough and detailed. Example: `<think>Thinking details here...</think>Final answer text here.`)";
|
|
@@ -7812,7 +7926,7 @@ ${context}`;
|
|
|
7812
7926
|
const hardenedHistory = [...history];
|
|
7813
7927
|
const userQuestion = { role: "user", content: question + finalRestrictionSuffix };
|
|
7814
7928
|
const messages = [...hardenedHistory, userQuestion];
|
|
7815
|
-
const systemPrompt = (
|
|
7929
|
+
const systemPrompt = (_v = this.config.llm.systemPrompt) != null ? _v : "";
|
|
7816
7930
|
const userPrompt = messages.map((m) => `${m.role}: ${m.content}`).join("\n");
|
|
7817
7931
|
let fullReply = "";
|
|
7818
7932
|
let thinkingText = "";
|
|
@@ -7923,7 +8037,7 @@ ${context}`;
|
|
|
7923
8037
|
}
|
|
7924
8038
|
yield fullReply;
|
|
7925
8039
|
}
|
|
7926
|
-
const runHallucination = ((
|
|
8040
|
+
const runHallucination = ((_w = this.config.llm.options) == null ? void 0 : _w.hallucinationScoring) === true || this.config.llm.provider !== "ollama" && ((_x = this.config.llm.options) == null ? void 0 : _x.hallucinationScoring) !== false;
|
|
7927
8041
|
if (runHallucination) {
|
|
7928
8042
|
hallucinationScoringPromise = scoreHallucination(this.llmProvider, fullReply, context).catch(() => void 0);
|
|
7929
8043
|
}
|
|
@@ -7932,7 +8046,7 @@ ${context}`;
|
|
|
7932
8046
|
const latency = {
|
|
7933
8047
|
embedMs: Math.round(embedMs),
|
|
7934
8048
|
retrieveMs: Math.round(retrieveMs),
|
|
7935
|
-
rerankMs: ((
|
|
8049
|
+
rerankMs: arch !== "naive" && (arch === "retrieve-and-rerank" || ((_y = this.config.rag) == null ? void 0 : _y.useReranking)) ? Math.round(rerankMs) : void 0,
|
|
7936
8050
|
generateMs: Math.round(generateMs),
|
|
7937
8051
|
totalMs: Math.round(totalMs)
|
|
7938
8052
|
};
|
|
@@ -7945,7 +8059,7 @@ ${context}`;
|
|
|
7945
8059
|
totalTokens: promptTokens + completionTokens,
|
|
7946
8060
|
estimatedCostUsd: estimateCostUsd(promptTokens, completionTokens, this.config.llm.model)
|
|
7947
8061
|
};
|
|
7948
|
-
const awaitHallucination = ((
|
|
8062
|
+
const awaitHallucination = ((_z = this.config.llm.options) == null ? void 0 : _z.awaitHallucination) === true;
|
|
7949
8063
|
const [uiTransformation, hallucinationResult] = yield new __await(Promise.all([
|
|
7950
8064
|
uiTransformationPromise,
|
|
7951
8065
|
awaitHallucination ? hallucinationScoringPromise : Promise.resolve(void 0)
|
|
@@ -7974,8 +8088,9 @@ ${context}`;
|
|
|
7974
8088
|
hallucinationReason: hScore.reason
|
|
7975
8089
|
} : {});
|
|
7976
8090
|
const trace = buildTrace(hallucinationResult);
|
|
7977
|
-
|
|
7978
|
-
|
|
8091
|
+
const isTelemetryActive = (_B = (_A = this.config.telemetry) == null ? void 0 : _A.enabled) != null ? _B : Boolean(this.config.licenseKey);
|
|
8092
|
+
if (isTelemetryActive) {
|
|
8093
|
+
const telemetryUrl = ((_C = this.config.telemetry) == null ? void 0 : _C.url) || "/api/telemetry";
|
|
7979
8094
|
const absoluteUrl = telemetryUrl.startsWith("http") ? telemetryUrl : (process.env.NEXT_PUBLIC_APP_URL || `http://localhost:${process.env.PORT || 3e3}`) + telemetryUrl;
|
|
7980
8095
|
(async () => {
|
|
7981
8096
|
try {
|
|
@@ -8250,6 +8365,7 @@ var Retrivora = class {
|
|
|
8250
8365
|
this.config.projectId,
|
|
8251
8366
|
(_a2 = this.config.vectorDb) == null ? void 0 : _a2.provider
|
|
8252
8367
|
);
|
|
8368
|
+
await LicenseVerifier.verifyIP(this.config.licenseKey);
|
|
8253
8369
|
} catch (err) {
|
|
8254
8370
|
throw wrapError(err, "CONFIGURATION_ERROR");
|
|
8255
8371
|
}
|
|
@@ -9324,6 +9440,43 @@ function getOrCreatePlugin(configOrPlugin) {
|
|
|
9324
9440
|
}
|
|
9325
9441
|
return _g[cacheKey];
|
|
9326
9442
|
}
|
|
9443
|
+
function reportTelemetry(req, plugin, action, status, details, trace) {
|
|
9444
|
+
var _a2;
|
|
9445
|
+
try {
|
|
9446
|
+
const config = plugin.getConfig();
|
|
9447
|
+
const licenseKey = config.licenseKey || process.env.RAG_LICENSE_KEY || process.env.RETRIVORA_LICENSE_KEY || process.env.NEXT_PUBLIC_RETRIVORA_LICENSE_KEY;
|
|
9448
|
+
const telemetryConfig = config.telemetry;
|
|
9449
|
+
const enabled = (_a2 = telemetryConfig == null ? void 0 : telemetryConfig.enabled) != null ? _a2 : Boolean(licenseKey);
|
|
9450
|
+
if (!enabled) return;
|
|
9451
|
+
const telemetryUrl = (telemetryConfig == null ? void 0 : telemetryConfig.url) || process.env.TELEMETRY_URL || process.env.NEXT_PUBLIC_TELEMETRY_URL || "/api/telemetry";
|
|
9452
|
+
const host = req.headers.get("host") || "localhost";
|
|
9453
|
+
let absoluteUrl = telemetryUrl;
|
|
9454
|
+
if (!telemetryUrl.startsWith("http")) {
|
|
9455
|
+
const proto = req.headers.get("x-forwarded-proto") || "http";
|
|
9456
|
+
absoluteUrl = `${proto}://${host}${telemetryUrl}`;
|
|
9457
|
+
}
|
|
9458
|
+
const projectId = config.projectId || "default";
|
|
9459
|
+
fetch(absoluteUrl, {
|
|
9460
|
+
method: "POST",
|
|
9461
|
+
headers: {
|
|
9462
|
+
"Content-Type": "application/json",
|
|
9463
|
+
"x-forwarded-for": req.headers.get("x-forwarded-for") || "",
|
|
9464
|
+
"x-real-ip": req.headers.get("x-real-ip") || ""
|
|
9465
|
+
},
|
|
9466
|
+
body: JSON.stringify({
|
|
9467
|
+
trace,
|
|
9468
|
+
licenseKey,
|
|
9469
|
+
projectId,
|
|
9470
|
+
action,
|
|
9471
|
+
status,
|
|
9472
|
+
details
|
|
9473
|
+
})
|
|
9474
|
+
}).catch((err) => {
|
|
9475
|
+
console.warn("[Retrivora Telemetry] Async report warning:", err.message);
|
|
9476
|
+
});
|
|
9477
|
+
} catch (e) {
|
|
9478
|
+
}
|
|
9479
|
+
}
|
|
9327
9480
|
function sseFrame(payload) {
|
|
9328
9481
|
return `data: ${JSON.stringify(payload)}
|
|
9329
9482
|
|
|
@@ -9366,6 +9519,7 @@ function createChatHandler(configOrPlugin, options) {
|
|
|
9366
9519
|
const storage = new DatabaseStorage(plugin.getConfig());
|
|
9367
9520
|
const onAuthorize = options == null ? void 0 : options.onAuthorize;
|
|
9368
9521
|
return async function POST(req) {
|
|
9522
|
+
var _a2, _b, _c, _d;
|
|
9369
9523
|
const authResult = await checkAuth(req, onAuthorize);
|
|
9370
9524
|
if (authResult) return authResult;
|
|
9371
9525
|
const rateLimited = checkRateLimit(req);
|
|
@@ -9394,12 +9548,14 @@ function createChatHandler(configOrPlugin, options) {
|
|
|
9394
9548
|
uiTransformation: result.ui_transformation,
|
|
9395
9549
|
trace: result.trace
|
|
9396
9550
|
}).catch((err) => console.warn("[createChatHandler] Failed to save assistant message:", err));
|
|
9551
|
+
reportTelemetry(req, plugin, "QUERY_GENERATION", "success", `Tokens: ${((_b = (_a2 = result.trace) == null ? void 0 : _a2.tokens) == null ? void 0 : _b.totalTokens) || 0}, Latency: ${((_d = (_c = result.trace) == null ? void 0 : _c.latency) == null ? void 0 : _d.totalMs) || 0}ms`, result.trace);
|
|
9397
9552
|
return import_server.NextResponse.json(__spreadProps(__spreadValues({}, result), {
|
|
9398
9553
|
messageId: assistantMsgId,
|
|
9399
9554
|
userMessageId: userMsgId
|
|
9400
9555
|
}));
|
|
9401
9556
|
} catch (err) {
|
|
9402
9557
|
const message = err instanceof Error ? err.message : "Internal server error";
|
|
9558
|
+
reportTelemetry(req, plugin, "QUERY_GENERATION", "error", message);
|
|
9403
9559
|
return import_server.NextResponse.json({ error: message }, { status: 500 });
|
|
9404
9560
|
}
|
|
9405
9561
|
};
|
|
@@ -9442,7 +9598,7 @@ function createStreamHandler(configOrPlugin, options) {
|
|
|
9442
9598
|
let isActive = true;
|
|
9443
9599
|
const stream = new ReadableStream({
|
|
9444
9600
|
async start(controller) {
|
|
9445
|
-
var _a2;
|
|
9601
|
+
var _a2, _b, _c, _d, _e;
|
|
9446
9602
|
const enqueue = (text) => {
|
|
9447
9603
|
if (!isActive) return;
|
|
9448
9604
|
try {
|
|
@@ -9499,6 +9655,7 @@ function createStreamHandler(configOrPlugin, options) {
|
|
|
9499
9655
|
uiTransformation,
|
|
9500
9656
|
trace: responseChunk == null ? void 0 : responseChunk.trace
|
|
9501
9657
|
}).catch((err) => console.warn("[createStreamHandler] Failed to save assistant message:", err));
|
|
9658
|
+
reportTelemetry(req, plugin, "QUERY_GENERATION", "success", `Tokens: ${((_c = (_b = responseChunk == null ? void 0 : responseChunk.trace) == null ? void 0 : _b.tokens) == null ? void 0 : _c.totalTokens) || 0}, Latency: ${((_e = (_d = responseChunk == null ? void 0 : responseChunk.trace) == null ? void 0 : _d.latency) == null ? void 0 : _e.totalMs) || 0}ms`, responseChunk == null ? void 0 : responseChunk.trace);
|
|
9502
9659
|
}
|
|
9503
9660
|
}
|
|
9504
9661
|
} catch (temp) {
|
|
@@ -9515,6 +9672,7 @@ function createStreamHandler(configOrPlugin, options) {
|
|
|
9515
9672
|
if (isActive) {
|
|
9516
9673
|
const errorMessage = streamError instanceof Error ? streamError.message : String(streamError);
|
|
9517
9674
|
console.error("[createStreamHandler] Stream error:", streamError);
|
|
9675
|
+
reportTelemetry(req, plugin, "QUERY_GENERATION", "error", errorMessage);
|
|
9518
9676
|
try {
|
|
9519
9677
|
enqueue(sseErrorFrame(errorMessage));
|
|
9520
9678
|
} catch (e) {
|
|
@@ -9551,9 +9709,11 @@ function createIngestHandler(configOrPlugin, options) {
|
|
|
9551
9709
|
return import_server.NextResponse.json({ error: "documents array is required" }, { status: 400 });
|
|
9552
9710
|
}
|
|
9553
9711
|
const results = await plugin.ingest(documents, namespace);
|
|
9712
|
+
reportTelemetry(req, plugin, "DOCUMENT_INGESTION", "success", `Ingested ${documents.length} document(s)`);
|
|
9554
9713
|
return import_server.NextResponse.json({ results });
|
|
9555
9714
|
} catch (err) {
|
|
9556
9715
|
const message = err instanceof Error ? err.message : "Internal server error";
|
|
9716
|
+
reportTelemetry(req, plugin, "DOCUMENT_INGESTION", "error", message);
|
|
9557
9717
|
return import_server.NextResponse.json({ error: message }, { status: 500 });
|
|
9558
9718
|
}
|
|
9559
9719
|
};
|
|
@@ -9652,9 +9812,11 @@ function createUploadHandler(configOrPlugin, options) {
|
|
|
9652
9812
|
}
|
|
9653
9813
|
}
|
|
9654
9814
|
const results = await plugin.ingest(documents, namespace);
|
|
9815
|
+
reportTelemetry(req, plugin, "DOCUMENT_INGESTION", "success", `Uploaded & ingested ${files.length} file(s)`);
|
|
9655
9816
|
return import_server.NextResponse.json({ message: "Upload successful", results });
|
|
9656
9817
|
} catch (err) {
|
|
9657
9818
|
const message = err instanceof Error ? err.message : "Upload failed";
|
|
9819
|
+
reportTelemetry(req, plugin, "DOCUMENT_INGESTION", "error", message);
|
|
9658
9820
|
return import_server.NextResponse.json({ error: message }, { status: 500 });
|
|
9659
9821
|
}
|
|
9660
9822
|
};
|
|
@@ -9662,19 +9824,30 @@ function createUploadHandler(configOrPlugin, options) {
|
|
|
9662
9824
|
function createSuggestionsHandler(configOrPlugin, options) {
|
|
9663
9825
|
const plugin = getOrCreatePlugin(configOrPlugin);
|
|
9664
9826
|
const onAuthorize = options == null ? void 0 : options.onAuthorize;
|
|
9665
|
-
return async function
|
|
9827
|
+
return async function handler(req) {
|
|
9666
9828
|
const authResult = await checkAuth(req, onAuthorize);
|
|
9667
9829
|
if (authResult) return authResult;
|
|
9668
9830
|
try {
|
|
9669
|
-
|
|
9670
|
-
|
|
9831
|
+
let query = "";
|
|
9832
|
+
let namespace = void 0;
|
|
9833
|
+
if (req.method === "POST") {
|
|
9834
|
+
const body = await req.json().catch(() => ({}));
|
|
9835
|
+
query = body.query || "";
|
|
9836
|
+
namespace = body.namespace;
|
|
9837
|
+
} else {
|
|
9838
|
+
const url = new URL(req.url);
|
|
9839
|
+
query = url.searchParams.get("query") || "";
|
|
9840
|
+
namespace = url.searchParams.get("namespace") || void 0;
|
|
9841
|
+
}
|
|
9671
9842
|
if (typeof query !== "string") {
|
|
9672
9843
|
return import_server.NextResponse.json({ error: "query is required" }, { status: 400 });
|
|
9673
9844
|
}
|
|
9674
9845
|
const suggestions = await plugin.getSuggestions(query, namespace);
|
|
9846
|
+
reportTelemetry(req, plugin, "AUTO_SUGGESTIONS", "success", `Fetched ${suggestions.length} suggestions for: ${query.slice(0, 30)}`);
|
|
9675
9847
|
return import_server.NextResponse.json({ suggestions });
|
|
9676
9848
|
} catch (err) {
|
|
9677
9849
|
const message = err instanceof Error ? err.message : "Internal server error";
|
|
9850
|
+
reportTelemetry(req, plugin, "AUTO_SUGGESTIONS", "error", message);
|
|
9678
9851
|
return import_server.NextResponse.json({ error: message }, { status: 500 });
|
|
9679
9852
|
}
|
|
9680
9853
|
};
|
|
@@ -9806,6 +9979,8 @@ function createRagHandler(configOrPlugin, options) {
|
|
|
9806
9979
|
switch (segment) {
|
|
9807
9980
|
case "health":
|
|
9808
9981
|
return healthHandler(req);
|
|
9982
|
+
case "suggestions":
|
|
9983
|
+
return suggestionsHandler(req);
|
|
9809
9984
|
case "history":
|
|
9810
9985
|
return historyHandler(req);
|
|
9811
9986
|
case "feedback":
|