@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/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: {
|
|
@@ -2385,7 +2387,7 @@ var ConfigResolver = class {
|
|
|
2385
2387
|
}
|
|
2386
2388
|
}
|
|
2387
2389
|
static mergeRetrievalWorkflow(rag, retrieval, workflow) {
|
|
2388
|
-
var _a2, _b, _c, _d, _e;
|
|
2390
|
+
var _a2, _b, _c, _d, _e, _f;
|
|
2389
2391
|
if (!rag && !retrieval && !workflow) return void 0;
|
|
2390
2392
|
const normalized = __spreadValues({}, rag != null ? rag : {});
|
|
2391
2393
|
if (retrieval) {
|
|
@@ -2393,20 +2395,44 @@ var ConfigResolver = class {
|
|
|
2393
2395
|
normalized.scoreThreshold = (_b = retrieval.scoreThreshold) != null ? _b : normalized.scoreThreshold;
|
|
2394
2396
|
normalized.useReranking = (_c = retrieval.useReranking) != null ? _c : normalized.useReranking;
|
|
2395
2397
|
if (retrieval.strategy === "hybrid") normalized.architecture = (_d = normalized.architecture) != null ? _d : "hybrid";
|
|
2396
|
-
if (retrieval.strategy === "agentic") normalized.architecture = "
|
|
2397
|
-
if (retrieval.strategy === "contextual-compression")
|
|
2398
|
+
if (retrieval.strategy === "agentic") normalized.architecture = "multi-agent";
|
|
2399
|
+
if (retrieval.strategy === "contextual-compression") {
|
|
2400
|
+
normalized.useReranking = true;
|
|
2401
|
+
normalized.architecture = (_e = normalized.architecture) != null ? _e : "retrieve-and-rerank";
|
|
2402
|
+
}
|
|
2398
2403
|
}
|
|
2399
2404
|
if (workflow == null ? void 0 : workflow.type) {
|
|
2400
2405
|
const type = workflow.type;
|
|
2401
|
-
if (type === "
|
|
2402
|
-
|
|
2403
|
-
|
|
2406
|
+
if (type === "naive-rag") {
|
|
2407
|
+
normalized.architecture = "naive";
|
|
2408
|
+
normalized.useReranking = false;
|
|
2409
|
+
normalized.useGraphRetrieval = false;
|
|
2410
|
+
} else if (type === "retrieve-and-rerank") {
|
|
2411
|
+
normalized.architecture = "retrieve-and-rerank";
|
|
2412
|
+
normalized.useReranking = true;
|
|
2413
|
+
} else if (type === "multimodal-rag") {
|
|
2414
|
+
normalized.architecture = "multimodal";
|
|
2415
|
+
} else if (type === "graph-rag") {
|
|
2404
2416
|
normalized.architecture = "graph";
|
|
2405
2417
|
normalized.useGraphRetrieval = true;
|
|
2418
|
+
} else if (type === "hybrid-rag") {
|
|
2419
|
+
normalized.architecture = "hybrid";
|
|
2420
|
+
} else if (type === "agentic-router") {
|
|
2421
|
+
normalized.architecture = "agentic-router";
|
|
2422
|
+
} else if (type === "multi-agent-rag" || type === "multi-agent" || type === "agentic" || type === "agentic-rag") {
|
|
2423
|
+
normalized.architecture = "multi-agent";
|
|
2406
2424
|
} else if (type === "simple-rag" || type === "rag") {
|
|
2407
|
-
normalized.architecture = (
|
|
2425
|
+
normalized.architecture = (_f = normalized.architecture) != null ? _f : "naive";
|
|
2408
2426
|
}
|
|
2409
2427
|
}
|
|
2428
|
+
if (normalized.architecture === "retrieve-and-rerank") {
|
|
2429
|
+
normalized.useReranking = true;
|
|
2430
|
+
} else if (normalized.architecture === "graph") {
|
|
2431
|
+
normalized.useGraphRetrieval = true;
|
|
2432
|
+
} else if (normalized.architecture === "naive") {
|
|
2433
|
+
normalized.useReranking = false;
|
|
2434
|
+
normalized.useGraphRetrieval = false;
|
|
2435
|
+
}
|
|
2410
2436
|
return normalized;
|
|
2411
2437
|
}
|
|
2412
2438
|
};
|
|
@@ -7152,7 +7178,7 @@ var Pipeline = class {
|
|
|
7152
7178
|
return this.initialised ? this.llmProvider : void 0;
|
|
7153
7179
|
}
|
|
7154
7180
|
async initialize() {
|
|
7155
|
-
var _a2, _b, _c;
|
|
7181
|
+
var _a2, _b, _c, _d;
|
|
7156
7182
|
if (this.initialised) return;
|
|
7157
7183
|
const chartInstruction = `You are a helpful assistant. Use the provided context to answer questions accurately.
|
|
7158
7184
|
|
|
@@ -7195,7 +7221,7 @@ var Pipeline = class {
|
|
|
7195
7221
|
this.entityExtractor = new EntityExtractor(this.llmProvider);
|
|
7196
7222
|
}
|
|
7197
7223
|
await this.vectorDB.initialize();
|
|
7198
|
-
if (((_a2 = this.config.rag) == null ? void 0 : _a2.architecture) === "agentic" || this.config.mcpServers && this.config.mcpServers.length > 0) {
|
|
7224
|
+
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) {
|
|
7199
7225
|
this.mcpRegistry = new MCPRegistry(this.config.mcpServers || []);
|
|
7200
7226
|
this.multiAgentCoordinator = new MultiAgentCoordinator({
|
|
7201
7227
|
llmProvider: this.llmProvider,
|
|
@@ -7207,7 +7233,7 @@ var Pipeline = class {
|
|
|
7207
7233
|
this.agent = new LangChainAgent(this, this.config);
|
|
7208
7234
|
await this.agent.initialize(this.llmProvider);
|
|
7209
7235
|
}
|
|
7210
|
-
if ((
|
|
7236
|
+
if ((_d = (_c = this.config.rag) == null ? void 0 : _c.cag) == null ? void 0 : _d.enabled) {
|
|
7211
7237
|
await this.loadColdContext(this.config.projectId);
|
|
7212
7238
|
}
|
|
7213
7239
|
this.initialised = true;
|
|
@@ -7370,9 +7396,9 @@ ${m.content}`).join("\n\n---\n\n");
|
|
|
7370
7396
|
return { reply, sources };
|
|
7371
7397
|
}
|
|
7372
7398
|
async ask(question, history = [], namespace) {
|
|
7373
|
-
var _a2;
|
|
7399
|
+
var _a2, _b;
|
|
7374
7400
|
await this.initialize();
|
|
7375
|
-
if ((((_a2 = this.config.rag) == null ? void 0 : _a2.architecture) === "agentic" || this.config.mcpServers && this.config.mcpServers.length > 0) && this.multiAgentCoordinator) {
|
|
7401
|
+
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) {
|
|
7376
7402
|
return await this.multiAgentCoordinator.run(question, history);
|
|
7377
7403
|
}
|
|
7378
7404
|
const stream = this.askStream(question, history, namespace);
|
|
@@ -7407,9 +7433,9 @@ ${m.content}`).join("\n\n---\n\n");
|
|
|
7407
7433
|
}
|
|
7408
7434
|
askStream(_0) {
|
|
7409
7435
|
return __asyncGenerator(this, arguments, function* (question, history = [], namespace) {
|
|
7410
|
-
var _a2;
|
|
7436
|
+
var _a2, _b;
|
|
7411
7437
|
yield new __await(this.initialize());
|
|
7412
|
-
if ((((_a2 = this.config.rag) == null ? void 0 : _a2.architecture) === "agentic" || this.config.mcpServers && this.config.mcpServers.length > 0) && this.multiAgentCoordinator) {
|
|
7438
|
+
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) {
|
|
7413
7439
|
const stream2 = this.multiAgentCoordinator.runStream(question, history);
|
|
7414
7440
|
try {
|
|
7415
7441
|
for (var iter = __forAwait(stream2), more, temp, error; more = !(temp = yield new __await(iter.next())).done; more = false) {
|
|
@@ -7458,7 +7484,7 @@ ${m.content}`).join("\n\n---\n\n");
|
|
|
7458
7484
|
*/
|
|
7459
7485
|
askStreamInternal(_0) {
|
|
7460
7486
|
return __asyncGenerator(this, arguments, function* (question, history = [], namespace) {
|
|
7461
|
-
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;
|
|
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;
|
|
7462
7488
|
yield new __await(this.initialize());
|
|
7463
7489
|
const ns = namespace != null ? namespace : this.config.projectId;
|
|
7464
7490
|
const topK = (_b = (_a2 = this.config.rag) == null ? void 0 : _a2.topK) != null ? _b : 5;
|
|
@@ -7481,13 +7507,14 @@ ${m.content}`).join("\n\n---\n\n");
|
|
|
7481
7507
|
const embedStart = performance.now();
|
|
7482
7508
|
const cacheKey = `${ns}::${searchQuery}`;
|
|
7483
7509
|
const cachedVector = this.embeddingCache.get(cacheKey);
|
|
7484
|
-
const
|
|
7510
|
+
const arch = (_h = this.config.rag) == null ? void 0 : _h.architecture;
|
|
7511
|
+
const useGraph = arch !== "naive" && arch !== "retrieve-and-rerank" && this.graphDB && ((_i = this.config.rag) == null ? void 0 : _i.useGraphRetrieval);
|
|
7485
7512
|
const [strategyResult, embeddedVector] = yield new __await(Promise.all([
|
|
7486
7513
|
QueryProcessor.determineRetrievalStrategy(
|
|
7487
7514
|
searchQuery,
|
|
7488
7515
|
useGraph ? this.llmRouter.get("fast") : void 0,
|
|
7489
|
-
(
|
|
7490
|
-
(
|
|
7516
|
+
(_j = this.config.rag) == null ? void 0 : _j.graphKeywords,
|
|
7517
|
+
(_k = this.config.rag) == null ? void 0 : _k.vectorKeywords
|
|
7491
7518
|
),
|
|
7492
7519
|
// Embed immediately regardless of strategy — costs nothing if cached.
|
|
7493
7520
|
// If strategy turns out to be 'graph'-only we just won't use the vector.
|
|
@@ -7497,7 +7524,7 @@ ${m.content}`).join("\n\n---\n\n");
|
|
|
7497
7524
|
if (!cachedVector && queryVector.length > 0) {
|
|
7498
7525
|
this.embeddingCache.set(cacheKey, queryVector);
|
|
7499
7526
|
}
|
|
7500
|
-
const graphData = (strategyResult === "graph" || strategyResult === "both") && this.graphDB && ((
|
|
7527
|
+
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;
|
|
7501
7528
|
const hasMetadataFilter = filter.metadata && Object.keys(filter.metadata).length > 0;
|
|
7502
7529
|
const hasNumericPredicates = Array.isArray(filter.__numericPredicates) && filter.__numericPredicates.length > 0;
|
|
7503
7530
|
const wantsExhaustiveList = hasNumericPredicates || hasMetadataFilter || /\b(list|all|show|provide|give|get|browse|find|search|display)\b/i.test(question);
|
|
@@ -7510,7 +7537,8 @@ ${m.content}`).join("\n\n---\n\n");
|
|
|
7510
7537
|
const structuredSources = this.applyStructuredFilters(rawSources, filter);
|
|
7511
7538
|
let fullSources = hasNumericPredicates ? structuredSources : structuredSources.filter((m) => m.score >= scoreThreshold);
|
|
7512
7539
|
const rerankLimit = wantsExhaustiveList ? retrievalLimit : topK;
|
|
7513
|
-
|
|
7540
|
+
const useReranking = arch !== "naive" && (arch === "retrieve-and-rerank" || ((_m = this.config.rag) == null ? void 0 : _m.useReranking));
|
|
7541
|
+
if (!hasNumericPredicates && useReranking) {
|
|
7514
7542
|
fullSources = yield new __await(this.reranker.rerank(fullSources, question, rerankLimit));
|
|
7515
7543
|
} else if (!wantsExhaustiveList) {
|
|
7516
7544
|
fullSources = fullSources.slice(0, topK);
|
|
@@ -7540,7 +7568,7 @@ ${graphContext}
|
|
|
7540
7568
|
VECTOR CONTEXT:
|
|
7541
7569
|
${context}`;
|
|
7542
7570
|
}
|
|
7543
|
-
if ((
|
|
7571
|
+
if ((_o = (_n = this.config.rag) == null ? void 0 : _n.cag) == null ? void 0 : _o.enabled) {
|
|
7544
7572
|
if (!this.coldContexts.has(ns)) {
|
|
7545
7573
|
yield new __await(this.loadColdContext(ns));
|
|
7546
7574
|
}
|
|
@@ -7593,10 +7621,10 @@ ${context}`;
|
|
|
7593
7621
|
let hallucinationScoringPromise = Promise.resolve(void 0);
|
|
7594
7622
|
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.)";
|
|
7595
7623
|
const isClaude37 = this.config.llm.model.includes("claude-3-7-sonnet");
|
|
7596
|
-
const isNativeThinking = isClaude37 && (((
|
|
7624
|
+
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);
|
|
7597
7625
|
const modelNameLower = this.config.llm.model.toLowerCase();
|
|
7598
7626
|
const isReasoningModel = modelNameLower.includes("-r1") || modelNameLower.includes("deepseek-r1") || modelNameLower.includes("reasoning") || modelNameLower.includes("thinking");
|
|
7599
|
-
const isSimulatedThinking = !isNativeThinking && (((
|
|
7627
|
+
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);
|
|
7600
7628
|
let finalRestrictionSuffix = restrictionSuffix;
|
|
7601
7629
|
if (isSimulatedThinking) {
|
|
7602
7630
|
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.`)";
|
|
@@ -7604,7 +7632,7 @@ ${context}`;
|
|
|
7604
7632
|
const hardenedHistory = [...history];
|
|
7605
7633
|
const userQuestion = { role: "user", content: question + finalRestrictionSuffix };
|
|
7606
7634
|
const messages = [...hardenedHistory, userQuestion];
|
|
7607
|
-
const systemPrompt = (
|
|
7635
|
+
const systemPrompt = (_v = this.config.llm.systemPrompt) != null ? _v : "";
|
|
7608
7636
|
const userPrompt = messages.map((m) => `${m.role}: ${m.content}`).join("\n");
|
|
7609
7637
|
let fullReply = "";
|
|
7610
7638
|
let thinkingText = "";
|
|
@@ -7715,7 +7743,7 @@ ${context}`;
|
|
|
7715
7743
|
}
|
|
7716
7744
|
yield fullReply;
|
|
7717
7745
|
}
|
|
7718
|
-
const runHallucination = ((
|
|
7746
|
+
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;
|
|
7719
7747
|
if (runHallucination) {
|
|
7720
7748
|
hallucinationScoringPromise = scoreHallucination(this.llmProvider, fullReply, context).catch(() => void 0);
|
|
7721
7749
|
}
|
|
@@ -7724,7 +7752,7 @@ ${context}`;
|
|
|
7724
7752
|
const latency = {
|
|
7725
7753
|
embedMs: Math.round(embedMs),
|
|
7726
7754
|
retrieveMs: Math.round(retrieveMs),
|
|
7727
|
-
rerankMs: ((
|
|
7755
|
+
rerankMs: arch !== "naive" && (arch === "retrieve-and-rerank" || ((_y = this.config.rag) == null ? void 0 : _y.useReranking)) ? Math.round(rerankMs) : void 0,
|
|
7728
7756
|
generateMs: Math.round(generateMs),
|
|
7729
7757
|
totalMs: Math.round(totalMs)
|
|
7730
7758
|
};
|
|
@@ -7737,7 +7765,7 @@ ${context}`;
|
|
|
7737
7765
|
totalTokens: promptTokens + completionTokens,
|
|
7738
7766
|
estimatedCostUsd: estimateCostUsd(promptTokens, completionTokens, this.config.llm.model)
|
|
7739
7767
|
};
|
|
7740
|
-
const awaitHallucination = ((
|
|
7768
|
+
const awaitHallucination = ((_z = this.config.llm.options) == null ? void 0 : _z.awaitHallucination) === true;
|
|
7741
7769
|
const [uiTransformation, hallucinationResult] = yield new __await(Promise.all([
|
|
7742
7770
|
uiTransformationPromise,
|
|
7743
7771
|
awaitHallucination ? hallucinationScoringPromise : Promise.resolve(void 0)
|
|
@@ -7766,8 +7794,9 @@ ${context}`;
|
|
|
7766
7794
|
hallucinationReason: hScore.reason
|
|
7767
7795
|
} : {});
|
|
7768
7796
|
const trace = buildTrace(hallucinationResult);
|
|
7769
|
-
|
|
7770
|
-
|
|
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";
|
|
7771
7800
|
const absoluteUrl = telemetryUrl.startsWith("http") ? telemetryUrl : (process.env.NEXT_PUBLIC_APP_URL || `http://localhost:${process.env.PORT || 3e3}`) + telemetryUrl;
|
|
7772
7801
|
(async () => {
|
|
7773
7802
|
try {
|
|
@@ -8142,6 +8171,19 @@ var LicenseVerifier = class {
|
|
|
8142
8171
|
*/
|
|
8143
8172
|
static verify(licenseKey, currentProjectId, provider, publicKeyOverride) {
|
|
8144
8173
|
const isProduction = process.env.NODE_ENV === "production";
|
|
8174
|
+
const now = Date.now();
|
|
8175
|
+
if (licenseKey) {
|
|
8176
|
+
const cacheKey = `${licenseKey}:${currentProjectId}:${provider || ""}:${publicKeyOverride || ""}`;
|
|
8177
|
+
const cached = this.cache.get(cacheKey);
|
|
8178
|
+
if (cached && now - cached.cachedAt < this.CACHE_TTL_MS) {
|
|
8179
|
+
const currentTimestampSec = Math.floor(now / 1e3);
|
|
8180
|
+
if (cached.payload.expiresAt && currentTimestampSec > cached.payload.expiresAt) {
|
|
8181
|
+
this.cache.delete(cacheKey);
|
|
8182
|
+
} else {
|
|
8183
|
+
return cached.payload;
|
|
8184
|
+
}
|
|
8185
|
+
}
|
|
8186
|
+
}
|
|
8145
8187
|
if (!licenseKey) {
|
|
8146
8188
|
if (isProduction) {
|
|
8147
8189
|
throw new ConfigurationException(
|
|
@@ -8228,6 +8270,10 @@ var LicenseVerifier = class {
|
|
|
8228
8270
|
}
|
|
8229
8271
|
}
|
|
8230
8272
|
}
|
|
8273
|
+
if (licenseKey) {
|
|
8274
|
+
const cacheKey = `${licenseKey}:${currentProjectId}:${provider || ""}:${publicKeyOverride || ""}`;
|
|
8275
|
+
this.cache.set(cacheKey, { payload, cachedAt: now });
|
|
8276
|
+
}
|
|
8231
8277
|
return payload;
|
|
8232
8278
|
} catch (err) {
|
|
8233
8279
|
const message = err instanceof Error ? err.message : String(err);
|
|
@@ -8236,7 +8282,76 @@ var LicenseVerifier = class {
|
|
|
8236
8282
|
);
|
|
8237
8283
|
}
|
|
8238
8284
|
}
|
|
8285
|
+
static async verifyIP(licenseKey) {
|
|
8286
|
+
if (!licenseKey) return;
|
|
8287
|
+
try {
|
|
8288
|
+
const parts = licenseKey.split(".");
|
|
8289
|
+
if (parts.length !== 3) return;
|
|
8290
|
+
const [, payloadB64] = parts;
|
|
8291
|
+
const payload = JSON.parse(
|
|
8292
|
+
Buffer.from(payloadB64, "base64url").toString("utf8")
|
|
8293
|
+
);
|
|
8294
|
+
const tier = (payload.tier || "").toLowerCase();
|
|
8295
|
+
if (tier === "enterprise" || tier === "custom") {
|
|
8296
|
+
return;
|
|
8297
|
+
}
|
|
8298
|
+
if (payload.ipv4 || payload.ipv6) {
|
|
8299
|
+
let currentIpv4 = "";
|
|
8300
|
+
let currentIpv6 = "";
|
|
8301
|
+
try {
|
|
8302
|
+
const res = await fetch("https://api4.ipify.org?format=json", { signal: AbortSignal.timeout(3e3) });
|
|
8303
|
+
const data = await res.json();
|
|
8304
|
+
currentIpv4 = data.ip;
|
|
8305
|
+
} catch (e) {
|
|
8306
|
+
}
|
|
8307
|
+
try {
|
|
8308
|
+
const res = await fetch("https://api6.ipify.org?format=json", { signal: AbortSignal.timeout(3e3) });
|
|
8309
|
+
const data = await res.json();
|
|
8310
|
+
currentIpv6 = data.ip;
|
|
8311
|
+
} catch (e) {
|
|
8312
|
+
}
|
|
8313
|
+
const localIps = [];
|
|
8314
|
+
try {
|
|
8315
|
+
const osModule = require("os");
|
|
8316
|
+
const interfaces = osModule.networkInterfaces();
|
|
8317
|
+
for (const name of Object.keys(interfaces)) {
|
|
8318
|
+
for (const iface of interfaces[name] || []) {
|
|
8319
|
+
if (!iface.internal) {
|
|
8320
|
+
localIps.push(iface.address);
|
|
8321
|
+
}
|
|
8322
|
+
}
|
|
8323
|
+
}
|
|
8324
|
+
} catch (e) {
|
|
8325
|
+
}
|
|
8326
|
+
const isIpv4Match = payload.ipv4 && (currentIpv4 === payload.ipv4 || localIps.includes(payload.ipv4));
|
|
8327
|
+
const isIpv6Match = payload.ipv6 && (currentIpv6 === payload.ipv6 || localIps.includes(payload.ipv6));
|
|
8328
|
+
if (payload.ipv4 && payload.ipv6) {
|
|
8329
|
+
if (!isIpv4Match && !isIpv6Match) {
|
|
8330
|
+
throw new Error(
|
|
8331
|
+
`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.`
|
|
8332
|
+
);
|
|
8333
|
+
}
|
|
8334
|
+
} else if (payload.ipv4 && !isIpv4Match) {
|
|
8335
|
+
throw new Error(
|
|
8336
|
+
`License key access restricted. This license key was created for a different system (authorized IPv4: ${payload.ipv4}) and cannot be used on this machine.`
|
|
8337
|
+
);
|
|
8338
|
+
} else if (payload.ipv6 && !isIpv6Match) {
|
|
8339
|
+
throw new Error(
|
|
8340
|
+
`License key access restricted. This license key was created for a different system (authorized IPv6: ${payload.ipv6}) and cannot be used on this machine.`
|
|
8341
|
+
);
|
|
8342
|
+
}
|
|
8343
|
+
}
|
|
8344
|
+
} catch (err) {
|
|
8345
|
+
if (err.message.includes("License key access restricted")) {
|
|
8346
|
+
throw new ConfigurationException(`[Retrivora SDK] ${err.message}`);
|
|
8347
|
+
}
|
|
8348
|
+
}
|
|
8349
|
+
}
|
|
8239
8350
|
};
|
|
8351
|
+
// A simple in-memory cache to save CPU overhead of cryptographic signature checks.
|
|
8352
|
+
LicenseVerifier.cache = /* @__PURE__ */ new Map();
|
|
8353
|
+
LicenseVerifier.CACHE_TTL_MS = 60 * 1e3;
|
|
8354
|
+
// Cache verified license for 60 seconds
|
|
8240
8355
|
// Retrivora's Public Key used to verify the license key signature.
|
|
8241
8356
|
// In production, this matches the private key held by Retrivora SaaS.
|
|
8242
8357
|
LicenseVerifier.PUBLIC_KEY = `-----BEGIN PUBLIC KEY-----
|
|
@@ -8937,6 +9052,43 @@ function getOrCreatePlugin(configOrPlugin) {
|
|
|
8937
9052
|
}
|
|
8938
9053
|
return _g[cacheKey];
|
|
8939
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
|
+
}
|
|
8940
9092
|
function sseFrame(payload) {
|
|
8941
9093
|
return `data: ${JSON.stringify(payload)}
|
|
8942
9094
|
|
|
@@ -8979,6 +9131,7 @@ function createChatHandler(configOrPlugin, options) {
|
|
|
8979
9131
|
const storage = new DatabaseStorage(plugin.getConfig());
|
|
8980
9132
|
const onAuthorize = options == null ? void 0 : options.onAuthorize;
|
|
8981
9133
|
return async function POST(req) {
|
|
9134
|
+
var _a2, _b, _c, _d;
|
|
8982
9135
|
const authResult = await checkAuth(req, onAuthorize);
|
|
8983
9136
|
if (authResult) return authResult;
|
|
8984
9137
|
const rateLimited = checkRateLimit(req);
|
|
@@ -9007,12 +9160,14 @@ function createChatHandler(configOrPlugin, options) {
|
|
|
9007
9160
|
uiTransformation: result.ui_transformation,
|
|
9008
9161
|
trace: result.trace
|
|
9009
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);
|
|
9010
9164
|
return import_server.NextResponse.json(__spreadProps(__spreadValues({}, result), {
|
|
9011
9165
|
messageId: assistantMsgId,
|
|
9012
9166
|
userMessageId: userMsgId
|
|
9013
9167
|
}));
|
|
9014
9168
|
} catch (err) {
|
|
9015
9169
|
const message = err instanceof Error ? err.message : "Internal server error";
|
|
9170
|
+
reportTelemetry(req, plugin, "QUERY_GENERATION", "error", message);
|
|
9016
9171
|
return import_server.NextResponse.json({ error: message }, { status: 500 });
|
|
9017
9172
|
}
|
|
9018
9173
|
};
|
|
@@ -9055,7 +9210,7 @@ function createStreamHandler(configOrPlugin, options) {
|
|
|
9055
9210
|
let isActive = true;
|
|
9056
9211
|
const stream = new ReadableStream({
|
|
9057
9212
|
async start(controller) {
|
|
9058
|
-
var _a2;
|
|
9213
|
+
var _a2, _b, _c, _d, _e;
|
|
9059
9214
|
const enqueue = (text) => {
|
|
9060
9215
|
if (!isActive) return;
|
|
9061
9216
|
try {
|
|
@@ -9112,6 +9267,7 @@ function createStreamHandler(configOrPlugin, options) {
|
|
|
9112
9267
|
uiTransformation,
|
|
9113
9268
|
trace: responseChunk == null ? void 0 : responseChunk.trace
|
|
9114
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);
|
|
9115
9271
|
}
|
|
9116
9272
|
}
|
|
9117
9273
|
} catch (temp) {
|
|
@@ -9128,6 +9284,7 @@ function createStreamHandler(configOrPlugin, options) {
|
|
|
9128
9284
|
if (isActive) {
|
|
9129
9285
|
const errorMessage = streamError instanceof Error ? streamError.message : String(streamError);
|
|
9130
9286
|
console.error("[createStreamHandler] Stream error:", streamError);
|
|
9287
|
+
reportTelemetry(req, plugin, "QUERY_GENERATION", "error", errorMessage);
|
|
9131
9288
|
try {
|
|
9132
9289
|
enqueue(sseErrorFrame(errorMessage));
|
|
9133
9290
|
} catch (e) {
|
|
@@ -9164,9 +9321,11 @@ function createIngestHandler(configOrPlugin, options) {
|
|
|
9164
9321
|
return import_server.NextResponse.json({ error: "documents array is required" }, { status: 400 });
|
|
9165
9322
|
}
|
|
9166
9323
|
const results = await plugin.ingest(documents, namespace);
|
|
9324
|
+
reportTelemetry(req, plugin, "DOCUMENT_INGESTION", "success", `Ingested ${documents.length} document(s)`);
|
|
9167
9325
|
return import_server.NextResponse.json({ results });
|
|
9168
9326
|
} catch (err) {
|
|
9169
9327
|
const message = err instanceof Error ? err.message : "Internal server error";
|
|
9328
|
+
reportTelemetry(req, plugin, "DOCUMENT_INGESTION", "error", message);
|
|
9170
9329
|
return import_server.NextResponse.json({ error: message }, { status: 500 });
|
|
9171
9330
|
}
|
|
9172
9331
|
};
|
|
@@ -9265,9 +9424,11 @@ function createUploadHandler(configOrPlugin, options) {
|
|
|
9265
9424
|
}
|
|
9266
9425
|
}
|
|
9267
9426
|
const results = await plugin.ingest(documents, namespace);
|
|
9427
|
+
reportTelemetry(req, plugin, "DOCUMENT_INGESTION", "success", `Uploaded & ingested ${files.length} file(s)`);
|
|
9268
9428
|
return import_server.NextResponse.json({ message: "Upload successful", results });
|
|
9269
9429
|
} catch (err) {
|
|
9270
9430
|
const message = err instanceof Error ? err.message : "Upload failed";
|
|
9431
|
+
reportTelemetry(req, plugin, "DOCUMENT_INGESTION", "error", message);
|
|
9271
9432
|
return import_server.NextResponse.json({ error: message }, { status: 500 });
|
|
9272
9433
|
}
|
|
9273
9434
|
};
|
|
@@ -9275,19 +9436,30 @@ function createUploadHandler(configOrPlugin, options) {
|
|
|
9275
9436
|
function createSuggestionsHandler(configOrPlugin, options) {
|
|
9276
9437
|
const plugin = getOrCreatePlugin(configOrPlugin);
|
|
9277
9438
|
const onAuthorize = options == null ? void 0 : options.onAuthorize;
|
|
9278
|
-
return async function
|
|
9439
|
+
return async function handler(req) {
|
|
9279
9440
|
const authResult = await checkAuth(req, onAuthorize);
|
|
9280
9441
|
if (authResult) return authResult;
|
|
9281
9442
|
try {
|
|
9282
|
-
|
|
9283
|
-
|
|
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
|
+
}
|
|
9284
9454
|
if (typeof query !== "string") {
|
|
9285
9455
|
return import_server.NextResponse.json({ error: "query is required" }, { status: 400 });
|
|
9286
9456
|
}
|
|
9287
9457
|
const suggestions = await plugin.getSuggestions(query, namespace);
|
|
9458
|
+
reportTelemetry(req, plugin, "AUTO_SUGGESTIONS", "success", `Fetched ${suggestions.length} suggestions for: ${query.slice(0, 30)}`);
|
|
9288
9459
|
return import_server.NextResponse.json({ suggestions });
|
|
9289
9460
|
} catch (err) {
|
|
9290
9461
|
const message = err instanceof Error ? err.message : "Internal server error";
|
|
9462
|
+
reportTelemetry(req, plugin, "AUTO_SUGGESTIONS", "error", message);
|
|
9291
9463
|
return import_server.NextResponse.json({ error: message }, { status: 500 });
|
|
9292
9464
|
}
|
|
9293
9465
|
};
|
|
@@ -9419,6 +9591,8 @@ function createRagHandler(configOrPlugin, options) {
|
|
|
9419
9591
|
switch (segment) {
|
|
9420
9592
|
case "health":
|
|
9421
9593
|
return healthHandler(req);
|
|
9594
|
+
case "suggestions":
|
|
9595
|
+
return suggestionsHandler(req);
|
|
9422
9596
|
case "history":
|
|
9423
9597
|
return historyHandler(req);
|
|
9424
9598
|
case "feedback":
|