@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.mjs
CHANGED
|
@@ -19,6 +19,12 @@ var __spreadValues = (a, b) => {
|
|
|
19
19
|
return a;
|
|
20
20
|
};
|
|
21
21
|
var __spreadProps = (a, b) => __defProps(a, __getOwnPropDescs(b));
|
|
22
|
+
var __require = /* @__PURE__ */ ((x) => typeof require !== "undefined" ? require : typeof Proxy !== "undefined" ? new Proxy(x, {
|
|
23
|
+
get: (a, b) => (typeof require !== "undefined" ? require : a)[b]
|
|
24
|
+
}) : x)(function(x) {
|
|
25
|
+
if (typeof require !== "undefined") return require.apply(this, arguments);
|
|
26
|
+
throw Error('Dynamic require of "' + x + '" is not supported');
|
|
27
|
+
});
|
|
22
28
|
var __objRest = (source, exclude) => {
|
|
23
29
|
var target = {};
|
|
24
30
|
for (var prop in source)
|
|
@@ -2121,46 +2127,48 @@ function getRagConfig(baseConfig, env = process.env) {
|
|
|
2121
2127
|
return getEnvConfig(env, baseConfig);
|
|
2122
2128
|
}
|
|
2123
2129
|
function getEnvConfig(env = process.env, base) {
|
|
2124
|
-
var _a2, _b, _c, _d, _e, _f, _g2, _h, _i, _j, _k, _l, _m, _n, _o, _p, _q, _r, _s, _t, _u, _v, _w, _x, _y, _z, _A, _B, _C, _D, _E, _F, _G, _H, _I, _J, _K, _L, _M, _N, _O, _P, _Q, _R, _S, _T, _U, _V, _W, _X, _Y, _Z, __, _$, _aa, _ba, _ca, _da, _ea, _fa, _ga, _ha, _ia, _ja, _ka, _la, _ma, _na, _oa, _pa, _qa, _ra, _sa, _ta, _ua, _va, _wa, _xa, _ya, _za, _Aa, _Ba, _Ca, _Da, _Ea, _Fa, _Ga, _Ha, _Ia, _Ja, _Ka, _La, _Ma, _Na, _Oa, _Pa, _Qa;
|
|
2130
|
+
var _a2, _b, _c, _d, _e, _f, _g2, _h, _i, _j, _k, _l, _m, _n, _o, _p, _q, _r, _s, _t, _u, _v, _w, _x, _y, _z, _A, _B, _C, _D, _E, _F, _G, _H, _I, _J, _K, _L, _M, _N, _O, _P, _Q, _R, _S, _T, _U, _V, _W, _X, _Y, _Z, __, _$, _aa, _ba, _ca, _da, _ea, _fa, _ga, _ha, _ia, _ja, _ka, _la, _ma, _na, _oa, _pa, _qa, _ra, _sa, _ta, _ua, _va, _wa, _xa, _ya, _za, _Aa, _Ba, _Ca, _Da, _Ea, _Fa, _Ga, _Ha, _Ia, _Ja, _Ka, _La, _Ma, _Na, _Oa, _Pa, _Qa, _Ra, _Sa, _Ta, _Ua;
|
|
2125
2131
|
const projectId = (_c = (_b = (_a2 = readString(env, "RAG_PROJECT_ID")) != null ? _a2 : readString(env, "NEXT_PUBLIC_PROJECT_ID")) != null ? _b : base == null ? void 0 : base.projectId) != null ? _c : "__default__";
|
|
2132
|
+
const licenseKey = (_g2 = (_f = (_e = (_d = readString(env, "RAG_LICENSE_KEY")) != null ? _d : readString(env, "RETRIVORA_LICENSE_KEY")) != null ? _e : readString(env, "NEXT_PUBLIC_RETRIVORA_LICENSE_KEY")) != null ? _f : readString(env, "LICENSE_KEY")) != null ? _g2 : base == null ? void 0 : base.licenseKey;
|
|
2133
|
+
const telemetryEnabled = readString(env, "TELEMETRY_ENABLED") === "true" || readString(env, "NEXT_PUBLIC_TELEMETRY_ENABLED") === "true" || ((_h = base == null ? void 0 : base.telemetry) == null ? void 0 : _h.enabled) || Boolean(licenseKey);
|
|
2126
2134
|
const vectorProvider = readEnum(env, "VECTOR_DB_PROVIDER", "pinecone", VECTOR_DB_PROVIDERS);
|
|
2127
2135
|
const llmProvider = readEnum(env, "LLM_PROVIDER", "openai", LLM_PROVIDERS);
|
|
2128
2136
|
const embeddingProvider = readEnum(env, "EMBEDDING_PROVIDER", "openai", EMBEDDING_PROVIDERS);
|
|
2129
2137
|
const embeddingDimensions = readNumber(env, "EMBEDDING_DIMENSIONS", 1536);
|
|
2130
2138
|
const vectorDbOptions = {};
|
|
2131
2139
|
if (vectorProvider === "pinecone") {
|
|
2132
|
-
vectorDbOptions.apiKey = (
|
|
2133
|
-
vectorDbOptions.indexName = (
|
|
2140
|
+
vectorDbOptions.apiKey = (_l = (_k = readString(env, "PINECONE_API_KEY")) != null ? _k : (_j = (_i = base == null ? void 0 : base.vectorDb) == null ? void 0 : _i.options) == null ? void 0 : _j.apiKey) != null ? _l : "";
|
|
2141
|
+
vectorDbOptions.indexName = (_q = (_n = readString(env, "PINECONE_INDEX")) != null ? _n : (_m = base == null ? void 0 : base.vectorDb) == null ? void 0 : _m.indexName) != null ? _q : (_p = (_o = base == null ? void 0 : base.vectorDb) == null ? void 0 : _o.options) == null ? void 0 : _p.indexName;
|
|
2134
2142
|
} else if (vectorProvider === "pgvector" || vectorProvider === "postgresql") {
|
|
2135
|
-
vectorDbOptions.connectionString = (
|
|
2136
|
-
vectorDbOptions.tables = (
|
|
2137
|
-
vectorDbOptions.searchFields = (
|
|
2143
|
+
vectorDbOptions.connectionString = (_v = (_u = (_r = readString(env, "PGVECTOR_CONNECTION_STRING")) != null ? _r : readString(env, "POSTGRES_URL")) != null ? _u : (_t = (_s = base == null ? void 0 : base.vectorDb) == null ? void 0 : _s.options) == null ? void 0 : _t.connectionString) != null ? _v : "";
|
|
2144
|
+
vectorDbOptions.tables = (_A = (_x = (_w = readString(env, "VECTOR_DB_TABLES")) != null ? _w : readString(env, "POSTGRES_TABLES")) == null ? void 0 : _x.split(",").map((t) => t.trim())) != null ? _A : (_z = (_y = base == null ? void 0 : base.vectorDb) == null ? void 0 : _y.options) == null ? void 0 : _z.tables;
|
|
2145
|
+
vectorDbOptions.searchFields = (_E = (_B = readString(env, "POSTGRES_SEARCH_FIELDS")) == null ? void 0 : _B.split(",").map((f) => f.trim())) != null ? _E : (_D = (_C = base == null ? void 0 : base.vectorDb) == null ? void 0 : _C.options) == null ? void 0 : _D.searchFields;
|
|
2138
2146
|
vectorDbOptions.dimensions = embeddingDimensions;
|
|
2139
2147
|
} else if (vectorProvider === "mongodb") {
|
|
2140
|
-
vectorDbOptions.uri = (
|
|
2141
|
-
vectorDbOptions.database = (
|
|
2142
|
-
vectorDbOptions.collection = (
|
|
2143
|
-
vectorDbOptions.indexName = (
|
|
2148
|
+
vectorDbOptions.uri = (_I = (_H = readString(env, "MONGODB_URI")) != null ? _H : (_G = (_F = base == null ? void 0 : base.vectorDb) == null ? void 0 : _F.options) == null ? void 0 : _G.uri) != null ? _I : "";
|
|
2149
|
+
vectorDbOptions.database = (_M = (_L = readString(env, "MONGODB_DB")) != null ? _L : (_K = (_J = base == null ? void 0 : base.vectorDb) == null ? void 0 : _J.options) == null ? void 0 : _K.database) != null ? _M : "";
|
|
2150
|
+
vectorDbOptions.collection = (_Q = (_P = readString(env, "MONGODB_COLLECTION")) != null ? _P : (_O = (_N = base == null ? void 0 : base.vectorDb) == null ? void 0 : _N.options) == null ? void 0 : _O.collection) != null ? _Q : "";
|
|
2151
|
+
vectorDbOptions.indexName = (_W = (_V = (_S = readString(env, "MONGODB_INDEX_NAME")) != null ? _S : (_R = base == null ? void 0 : base.vectorDb) == null ? void 0 : _R.indexName) != null ? _V : (_U = (_T = base == null ? void 0 : base.vectorDb) == null ? void 0 : _T.options) == null ? void 0 : _U.indexName) != null ? _W : "vector_index";
|
|
2144
2152
|
} else if (vectorProvider === "qdrant") {
|
|
2145
|
-
vectorDbOptions.baseUrl = (
|
|
2146
|
-
vectorDbOptions.apiKey = (
|
|
2153
|
+
vectorDbOptions.baseUrl = (__ = (_Z = readString(env, "QDRANT_URL")) != null ? _Z : (_Y = (_X = base == null ? void 0 : base.vectorDb) == null ? void 0 : _X.options) == null ? void 0 : _Y.baseUrl) != null ? __ : "http://localhost:6333";
|
|
2154
|
+
vectorDbOptions.apiKey = (_ba = readString(env, "QDRANT_API_KEY")) != null ? _ba : (_aa = (_$ = base == null ? void 0 : base.vectorDb) == null ? void 0 : _$.options) == null ? void 0 : _aa.apiKey;
|
|
2147
2155
|
vectorDbOptions.dimensions = embeddingDimensions;
|
|
2148
2156
|
} else if (vectorProvider === "milvus") {
|
|
2149
|
-
vectorDbOptions.baseUrl = (
|
|
2157
|
+
vectorDbOptions.baseUrl = (_ca = readString(env, "MILVUS_URL")) != null ? _ca : "http://localhost:19530";
|
|
2150
2158
|
vectorDbOptions.apiKey = readString(env, "MILVUS_API_KEY");
|
|
2151
2159
|
} else if (vectorProvider === "chromadb") {
|
|
2152
|
-
vectorDbOptions.baseUrl = (
|
|
2160
|
+
vectorDbOptions.baseUrl = (_da = readString(env, "CHROMADB_URL")) != null ? _da : "http://localhost:8000";
|
|
2153
2161
|
} else if (vectorProvider === "weaviate") {
|
|
2154
|
-
vectorDbOptions.baseUrl = (
|
|
2162
|
+
vectorDbOptions.baseUrl = (_ea = readString(env, "WEAVIATE_URL")) != null ? _ea : "http://localhost:8080";
|
|
2155
2163
|
vectorDbOptions.apiKey = readString(env, "WEAVIATE_API_KEY");
|
|
2156
2164
|
} else if (vectorProvider === "redis") {
|
|
2157
|
-
vectorDbOptions.baseUrl = (
|
|
2165
|
+
vectorDbOptions.baseUrl = (_fa = readString(env, "REDIS_URL")) != null ? _fa : "";
|
|
2158
2166
|
vectorDbOptions.apiKey = readString(env, "REDIS_API_KEY");
|
|
2159
2167
|
} else if (vectorProvider === "rest") {
|
|
2160
|
-
vectorDbOptions.baseUrl = (
|
|
2168
|
+
vectorDbOptions.baseUrl = (_ga = readString(env, "VECTOR_DB_REST_URL")) != null ? _ga : "";
|
|
2161
2169
|
vectorDbOptions.headers = readString(env, "VECTOR_DB_REST_API_KEY") ? { "api-key": readString(env, "VECTOR_DB_REST_API_KEY") } : {};
|
|
2162
2170
|
} else if (vectorProvider === "universal_rest") {
|
|
2163
|
-
vectorDbOptions.baseUrl = (
|
|
2171
|
+
vectorDbOptions.baseUrl = (_ia = (_ha = readString(env, "VECTOR_BASE_URL")) != null ? _ha : readString(env, "VECTOR_DB_REST_URL")) != null ? _ia : "";
|
|
2164
2172
|
vectorDbOptions.profile = readString(env, "VECTOR_UNIVERSAL_PROFILE");
|
|
2165
2173
|
vectorDbOptions.headers = readString(env, "VECTOR_DB_REST_API_KEY") ? { Authorization: `Bearer ${readString(env, "VECTOR_DB_REST_API_KEY")}` } : {};
|
|
2166
2174
|
}
|
|
@@ -2179,8 +2187,8 @@ function getEnvConfig(env = process.env, base) {
|
|
|
2179
2187
|
// Anthropic needs a separate embedding provider; key kept for completeness
|
|
2180
2188
|
gemini: readString(env, "GEMINI_API_KEY"),
|
|
2181
2189
|
ollama: void 0,
|
|
2182
|
-
universal_rest: (
|
|
2183
|
-
custom: (
|
|
2190
|
+
universal_rest: (_ja = readString(env, "EMBEDDING_API_KEY")) != null ? _ja : readString(env, "OPENAI_API_KEY"),
|
|
2191
|
+
custom: (_ka = readString(env, "EMBEDDING_API_KEY")) != null ? _ka : readString(env, "OPENAI_API_KEY")
|
|
2184
2192
|
};
|
|
2185
2193
|
const DEFAULT_MODEL_BY_PROVIDER = {
|
|
2186
2194
|
openai: "gpt-4o",
|
|
@@ -2193,16 +2201,16 @@ function getEnvConfig(env = process.env, base) {
|
|
|
2193
2201
|
};
|
|
2194
2202
|
return __spreadProps(__spreadValues({
|
|
2195
2203
|
projectId,
|
|
2196
|
-
licenseKey: (
|
|
2204
|
+
licenseKey: (_ma = (_la = readString(env, "RETRIVORA_LICENSE_KEY")) != null ? _la : readString(env, "LICENSE_KEY")) != null ? _ma : base == null ? void 0 : base.licenseKey,
|
|
2197
2205
|
vectorDb: {
|
|
2198
2206
|
provider: vectorProvider,
|
|
2199
|
-
indexName: (
|
|
2207
|
+
indexName: (_oa = (_na = readString(env, "VECTOR_DB_INDEX")) != null ? _na : vectorDbOptions.indexName) != null ? _oa : "rag-index",
|
|
2200
2208
|
options: vectorDbOptions
|
|
2201
2209
|
},
|
|
2202
2210
|
llm: {
|
|
2203
2211
|
provider: llmProvider,
|
|
2204
|
-
model: (
|
|
2205
|
-
apiKey: (
|
|
2212
|
+
model: (_qa = (_pa = readString(env, "LLM_MODEL")) != null ? _pa : DEFAULT_MODEL_BY_PROVIDER[llmProvider]) != null ? _qa : "gpt-4o",
|
|
2213
|
+
apiKey: (_ra = llmApiKeyByProvider[llmProvider]) != null ? _ra : "",
|
|
2206
2214
|
baseUrl: readString(env, "LLM_BASE_URL"),
|
|
2207
2215
|
systemPrompt: readString(env, "LLM_SYSTEM_PROMPT"),
|
|
2208
2216
|
maxTokens: readNumber(env, "LLM_MAX_TOKENS", 4096),
|
|
@@ -2215,7 +2223,7 @@ function getEnvConfig(env = process.env, base) {
|
|
|
2215
2223
|
},
|
|
2216
2224
|
embedding: {
|
|
2217
2225
|
provider: embeddingProvider,
|
|
2218
|
-
model: (
|
|
2226
|
+
model: (_sa = readString(env, "EMBEDDING_MODEL")) != null ? _sa : "text-embedding-3-small",
|
|
2219
2227
|
apiKey: embeddingApiKeyByProvider[embeddingProvider],
|
|
2220
2228
|
baseUrl: readString(env, "EMBEDDING_BASE_URL"),
|
|
2221
2229
|
dimensions: embeddingDimensions,
|
|
@@ -2226,30 +2234,30 @@ function getEnvConfig(env = process.env, base) {
|
|
|
2226
2234
|
}
|
|
2227
2235
|
},
|
|
2228
2236
|
ui: {
|
|
2229
|
-
title: (
|
|
2230
|
-
subtitle: (
|
|
2231
|
-
primaryColor: (
|
|
2232
|
-
accentColor: (
|
|
2233
|
-
logoUrl: (
|
|
2234
|
-
placeholder: (
|
|
2235
|
-
showSources: ((
|
|
2236
|
-
welcomeMessage: (
|
|
2237
|
-
visualStyle: (
|
|
2238
|
-
borderRadius: (
|
|
2239
|
-
allowUpload: ((
|
|
2237
|
+
title: (_ua = (_ta = readString(env, "NEXT_PUBLIC_UI_TITLE")) != null ? _ta : readString(env, "UI_TITLE")) != null ? _ua : "AI Assistant",
|
|
2238
|
+
subtitle: (_wa = (_va = readString(env, "NEXT_PUBLIC_UI_SUBTITLE")) != null ? _va : readString(env, "UI_SUBTITLE")) != null ? _wa : "Powered by RAG",
|
|
2239
|
+
primaryColor: (_ya = (_xa = readString(env, "NEXT_PUBLIC_PRIMARY_COLOR")) != null ? _xa : readString(env, "UI_PRIMARY_COLOR")) != null ? _ya : "#10b981",
|
|
2240
|
+
accentColor: (_Aa = (_za = readString(env, "NEXT_PUBLIC_ACCENT_COLOR")) != null ? _za : readString(env, "UI_ACCENT_COLOR")) != null ? _Aa : "#3b82f6",
|
|
2241
|
+
logoUrl: (_Ba = readString(env, "NEXT_PUBLIC_LOGO_URL")) != null ? _Ba : readString(env, "UI_LOGO_URL"),
|
|
2242
|
+
placeholder: (_Da = (_Ca = readString(env, "NEXT_PUBLIC_PLACEHOLDER")) != null ? _Ca : readString(env, "UI_PLACEHOLDER")) != null ? _Da : "Ask me anything\u2026",
|
|
2243
|
+
showSources: ((_Fa = (_Ea = readString(env, "NEXT_PUBLIC_SHOW_SOURCES")) != null ? _Ea : readString(env, "UI_SHOW_SOURCES")) != null ? _Fa : "true") !== "false",
|
|
2244
|
+
welcomeMessage: (_Ha = (_Ga = readString(env, "NEXT_PUBLIC_WELCOME_MESSAGE")) != null ? _Ga : readString(env, "UI_WELCOME_MESSAGE")) != null ? _Ha : "Hello! I'm your AI assistant. Ask me anything about your documents.",
|
|
2245
|
+
visualStyle: (_Ja = (_Ia = readString(env, "NEXT_PUBLIC_UI_VISUAL_STYLE")) != null ? _Ia : readString(env, "UI_VISUAL_STYLE")) != null ? _Ja : "glass",
|
|
2246
|
+
borderRadius: (_La = (_Ka = readString(env, "NEXT_PUBLIC_UI_BORDER_RADIUS")) != null ? _Ka : readString(env, "UI_BORDER_RADIUS")) != null ? _La : "xl",
|
|
2247
|
+
allowUpload: ((_Na = (_Ma = readString(env, "NEXT_PUBLIC_ALLOW_UPLOAD")) != null ? _Ma : readString(env, "UI_ALLOW_UPLOAD")) != null ? _Na : "false") === "true"
|
|
2240
2248
|
},
|
|
2241
2249
|
rag: {
|
|
2242
2250
|
topK: readNumber(env, "RAG_TOP_K", 5),
|
|
2243
2251
|
scoreThreshold: readNumber(env, "RAG_SCORE_THRESHOLD", 0),
|
|
2244
2252
|
chunkSize: readNumber(env, "RAG_CHUNK_SIZE", 1e3),
|
|
2245
2253
|
chunkOverlap: readNumber(env, "RAG_CHUNK_OVERLAP", 200),
|
|
2246
|
-
filterableFields: (
|
|
2254
|
+
filterableFields: (_Oa = readString(env, "RAG_FILTERABLE_FIELDS")) == null ? void 0 : _Oa.split(",").map((f) => f.trim()),
|
|
2247
2255
|
// Query pipeline toggles — read from .env.local
|
|
2248
2256
|
useQueryTransformation: readString(env, "RAG_USE_QUERY_TRANSFORMATION") === "true",
|
|
2249
2257
|
useReranking: readString(env, "RAG_USE_RERANKING") === "true",
|
|
2250
2258
|
useGraphRetrieval: readString(env, "RAG_USE_GRAPH_RETRIEVAL") === "true",
|
|
2251
|
-
architecture: (
|
|
2252
|
-
chunkingStrategy: (
|
|
2259
|
+
architecture: (_Pa = readString(env, "RAG_ARCHITECTURE")) != null ? _Pa : "simple",
|
|
2260
|
+
chunkingStrategy: (_Qa = readString(env, "RAG_CHUNKING_STRATEGY")) != null ? _Qa : "recursive",
|
|
2253
2261
|
uiMapping: (() => {
|
|
2254
2262
|
const raw = readString(env, "RAG_UI_MAPPING");
|
|
2255
2263
|
if (!raw) return void 0;
|
|
@@ -2261,8 +2269,8 @@ function getEnvConfig(env = process.env, base) {
|
|
|
2261
2269
|
})()
|
|
2262
2270
|
},
|
|
2263
2271
|
telemetry: {
|
|
2264
|
-
enabled:
|
|
2265
|
-
url: (
|
|
2272
|
+
enabled: telemetryEnabled,
|
|
2273
|
+
url: (_Ua = (_Ta = (_Ra = readString(env, "TELEMETRY_URL")) != null ? _Ra : readString(env, "NEXT_PUBLIC_TELEMETRY_URL")) != null ? _Ta : (_Sa = base == null ? void 0 : base.telemetry) == null ? void 0 : _Sa.url) != null ? _Ua : "/api/telemetry"
|
|
2266
2274
|
}
|
|
2267
2275
|
}, readString(env, "GRAPH_DB_PROVIDER") ? {
|
|
2268
2276
|
graphDb: {
|
|
@@ -2344,7 +2352,7 @@ var ConfigResolver = class {
|
|
|
2344
2352
|
}
|
|
2345
2353
|
}
|
|
2346
2354
|
static mergeRetrievalWorkflow(rag, retrieval, workflow) {
|
|
2347
|
-
var _a2, _b, _c, _d, _e;
|
|
2355
|
+
var _a2, _b, _c, _d, _e, _f;
|
|
2348
2356
|
if (!rag && !retrieval && !workflow) return void 0;
|
|
2349
2357
|
const normalized = __spreadValues({}, rag != null ? rag : {});
|
|
2350
2358
|
if (retrieval) {
|
|
@@ -2352,20 +2360,44 @@ var ConfigResolver = class {
|
|
|
2352
2360
|
normalized.scoreThreshold = (_b = retrieval.scoreThreshold) != null ? _b : normalized.scoreThreshold;
|
|
2353
2361
|
normalized.useReranking = (_c = retrieval.useReranking) != null ? _c : normalized.useReranking;
|
|
2354
2362
|
if (retrieval.strategy === "hybrid") normalized.architecture = (_d = normalized.architecture) != null ? _d : "hybrid";
|
|
2355
|
-
if (retrieval.strategy === "agentic") normalized.architecture = "
|
|
2356
|
-
if (retrieval.strategy === "contextual-compression")
|
|
2363
|
+
if (retrieval.strategy === "agentic") normalized.architecture = "multi-agent";
|
|
2364
|
+
if (retrieval.strategy === "contextual-compression") {
|
|
2365
|
+
normalized.useReranking = true;
|
|
2366
|
+
normalized.architecture = (_e = normalized.architecture) != null ? _e : "retrieve-and-rerank";
|
|
2367
|
+
}
|
|
2357
2368
|
}
|
|
2358
2369
|
if (workflow == null ? void 0 : workflow.type) {
|
|
2359
2370
|
const type = workflow.type;
|
|
2360
|
-
if (type === "
|
|
2361
|
-
|
|
2362
|
-
|
|
2371
|
+
if (type === "naive-rag") {
|
|
2372
|
+
normalized.architecture = "naive";
|
|
2373
|
+
normalized.useReranking = false;
|
|
2374
|
+
normalized.useGraphRetrieval = false;
|
|
2375
|
+
} else if (type === "retrieve-and-rerank") {
|
|
2376
|
+
normalized.architecture = "retrieve-and-rerank";
|
|
2377
|
+
normalized.useReranking = true;
|
|
2378
|
+
} else if (type === "multimodal-rag") {
|
|
2379
|
+
normalized.architecture = "multimodal";
|
|
2380
|
+
} else if (type === "graph-rag") {
|
|
2363
2381
|
normalized.architecture = "graph";
|
|
2364
2382
|
normalized.useGraphRetrieval = true;
|
|
2383
|
+
} else if (type === "hybrid-rag") {
|
|
2384
|
+
normalized.architecture = "hybrid";
|
|
2385
|
+
} else if (type === "agentic-router") {
|
|
2386
|
+
normalized.architecture = "agentic-router";
|
|
2387
|
+
} else if (type === "multi-agent-rag" || type === "multi-agent" || type === "agentic" || type === "agentic-rag") {
|
|
2388
|
+
normalized.architecture = "multi-agent";
|
|
2365
2389
|
} else if (type === "simple-rag" || type === "rag") {
|
|
2366
|
-
normalized.architecture = (
|
|
2390
|
+
normalized.architecture = (_f = normalized.architecture) != null ? _f : "naive";
|
|
2367
2391
|
}
|
|
2368
2392
|
}
|
|
2393
|
+
if (normalized.architecture === "retrieve-and-rerank") {
|
|
2394
|
+
normalized.useReranking = true;
|
|
2395
|
+
} else if (normalized.architecture === "graph") {
|
|
2396
|
+
normalized.useGraphRetrieval = true;
|
|
2397
|
+
} else if (normalized.architecture === "naive") {
|
|
2398
|
+
normalized.useReranking = false;
|
|
2399
|
+
normalized.useGraphRetrieval = false;
|
|
2400
|
+
}
|
|
2369
2401
|
return normalized;
|
|
2370
2402
|
}
|
|
2371
2403
|
};
|
|
@@ -4220,6 +4252,19 @@ var LicenseVerifier = class {
|
|
|
4220
4252
|
*/
|
|
4221
4253
|
static verify(licenseKey, currentProjectId, provider, publicKeyOverride) {
|
|
4222
4254
|
const isProduction = process.env.NODE_ENV === "production";
|
|
4255
|
+
const now = Date.now();
|
|
4256
|
+
if (licenseKey) {
|
|
4257
|
+
const cacheKey = `${licenseKey}:${currentProjectId}:${provider || ""}:${publicKeyOverride || ""}`;
|
|
4258
|
+
const cached = this.cache.get(cacheKey);
|
|
4259
|
+
if (cached && now - cached.cachedAt < this.CACHE_TTL_MS) {
|
|
4260
|
+
const currentTimestampSec = Math.floor(now / 1e3);
|
|
4261
|
+
if (cached.payload.expiresAt && currentTimestampSec > cached.payload.expiresAt) {
|
|
4262
|
+
this.cache.delete(cacheKey);
|
|
4263
|
+
} else {
|
|
4264
|
+
return cached.payload;
|
|
4265
|
+
}
|
|
4266
|
+
}
|
|
4267
|
+
}
|
|
4223
4268
|
if (!licenseKey) {
|
|
4224
4269
|
if (isProduction) {
|
|
4225
4270
|
throw new ConfigurationException(
|
|
@@ -4306,6 +4351,10 @@ var LicenseVerifier = class {
|
|
|
4306
4351
|
}
|
|
4307
4352
|
}
|
|
4308
4353
|
}
|
|
4354
|
+
if (licenseKey) {
|
|
4355
|
+
const cacheKey = `${licenseKey}:${currentProjectId}:${provider || ""}:${publicKeyOverride || ""}`;
|
|
4356
|
+
this.cache.set(cacheKey, { payload, cachedAt: now });
|
|
4357
|
+
}
|
|
4309
4358
|
return payload;
|
|
4310
4359
|
} catch (err) {
|
|
4311
4360
|
const message = err instanceof Error ? err.message : String(err);
|
|
@@ -4314,7 +4363,76 @@ var LicenseVerifier = class {
|
|
|
4314
4363
|
);
|
|
4315
4364
|
}
|
|
4316
4365
|
}
|
|
4366
|
+
static async verifyIP(licenseKey) {
|
|
4367
|
+
if (!licenseKey) return;
|
|
4368
|
+
try {
|
|
4369
|
+
const parts = licenseKey.split(".");
|
|
4370
|
+
if (parts.length !== 3) return;
|
|
4371
|
+
const [, payloadB64] = parts;
|
|
4372
|
+
const payload = JSON.parse(
|
|
4373
|
+
Buffer.from(payloadB64, "base64url").toString("utf8")
|
|
4374
|
+
);
|
|
4375
|
+
const tier = (payload.tier || "").toLowerCase();
|
|
4376
|
+
if (tier === "enterprise" || tier === "custom") {
|
|
4377
|
+
return;
|
|
4378
|
+
}
|
|
4379
|
+
if (payload.ipv4 || payload.ipv6) {
|
|
4380
|
+
let currentIpv4 = "";
|
|
4381
|
+
let currentIpv6 = "";
|
|
4382
|
+
try {
|
|
4383
|
+
const res = await fetch("https://api4.ipify.org?format=json", { signal: AbortSignal.timeout(3e3) });
|
|
4384
|
+
const data = await res.json();
|
|
4385
|
+
currentIpv4 = data.ip;
|
|
4386
|
+
} catch (e) {
|
|
4387
|
+
}
|
|
4388
|
+
try {
|
|
4389
|
+
const res = await fetch("https://api6.ipify.org?format=json", { signal: AbortSignal.timeout(3e3) });
|
|
4390
|
+
const data = await res.json();
|
|
4391
|
+
currentIpv6 = data.ip;
|
|
4392
|
+
} catch (e) {
|
|
4393
|
+
}
|
|
4394
|
+
const localIps = [];
|
|
4395
|
+
try {
|
|
4396
|
+
const osModule = __require("os");
|
|
4397
|
+
const interfaces = osModule.networkInterfaces();
|
|
4398
|
+
for (const name of Object.keys(interfaces)) {
|
|
4399
|
+
for (const iface of interfaces[name] || []) {
|
|
4400
|
+
if (!iface.internal) {
|
|
4401
|
+
localIps.push(iface.address);
|
|
4402
|
+
}
|
|
4403
|
+
}
|
|
4404
|
+
}
|
|
4405
|
+
} catch (e) {
|
|
4406
|
+
}
|
|
4407
|
+
const isIpv4Match = payload.ipv4 && (currentIpv4 === payload.ipv4 || localIps.includes(payload.ipv4));
|
|
4408
|
+
const isIpv6Match = payload.ipv6 && (currentIpv6 === payload.ipv6 || localIps.includes(payload.ipv6));
|
|
4409
|
+
if (payload.ipv4 && payload.ipv6) {
|
|
4410
|
+
if (!isIpv4Match && !isIpv6Match) {
|
|
4411
|
+
throw new Error(
|
|
4412
|
+
`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.`
|
|
4413
|
+
);
|
|
4414
|
+
}
|
|
4415
|
+
} else if (payload.ipv4 && !isIpv4Match) {
|
|
4416
|
+
throw new Error(
|
|
4417
|
+
`License key access restricted. This license key was created for a different system (authorized IPv4: ${payload.ipv4}) and cannot be used on this machine.`
|
|
4418
|
+
);
|
|
4419
|
+
} else if (payload.ipv6 && !isIpv6Match) {
|
|
4420
|
+
throw new Error(
|
|
4421
|
+
`License key access restricted. This license key was created for a different system (authorized IPv6: ${payload.ipv6}) and cannot be used on this machine.`
|
|
4422
|
+
);
|
|
4423
|
+
}
|
|
4424
|
+
}
|
|
4425
|
+
} catch (err) {
|
|
4426
|
+
if (err.message.includes("License key access restricted")) {
|
|
4427
|
+
throw new ConfigurationException(`[Retrivora SDK] ${err.message}`);
|
|
4428
|
+
}
|
|
4429
|
+
}
|
|
4430
|
+
}
|
|
4317
4431
|
};
|
|
4432
|
+
// A simple in-memory cache to save CPU overhead of cryptographic signature checks.
|
|
4433
|
+
LicenseVerifier.cache = /* @__PURE__ */ new Map();
|
|
4434
|
+
LicenseVerifier.CACHE_TTL_MS = 60 * 1e3;
|
|
4435
|
+
// Cache verified license for 60 seconds
|
|
4318
4436
|
// Retrivora's Public Key used to verify the license key signature.
|
|
4319
4437
|
// In production, this matches the private key held by Retrivora SaaS.
|
|
4320
4438
|
LicenseVerifier.PUBLIC_KEY = `-----BEGIN PUBLIC KEY-----
|
|
@@ -7275,7 +7393,7 @@ var Pipeline = class {
|
|
|
7275
7393
|
return this.initialised ? this.llmProvider : void 0;
|
|
7276
7394
|
}
|
|
7277
7395
|
async initialize() {
|
|
7278
|
-
var _a2, _b, _c;
|
|
7396
|
+
var _a2, _b, _c, _d;
|
|
7279
7397
|
if (this.initialised) return;
|
|
7280
7398
|
const chartInstruction = `You are a helpful assistant. Use the provided context to answer questions accurately.
|
|
7281
7399
|
|
|
@@ -7318,7 +7436,7 @@ var Pipeline = class {
|
|
|
7318
7436
|
this.entityExtractor = new EntityExtractor(this.llmProvider);
|
|
7319
7437
|
}
|
|
7320
7438
|
await this.vectorDB.initialize();
|
|
7321
|
-
if (((_a2 = this.config.rag) == null ? void 0 : _a2.architecture) === "agentic" || this.config.mcpServers && this.config.mcpServers.length > 0) {
|
|
7439
|
+
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) {
|
|
7322
7440
|
this.mcpRegistry = new MCPRegistry(this.config.mcpServers || []);
|
|
7323
7441
|
this.multiAgentCoordinator = new MultiAgentCoordinator({
|
|
7324
7442
|
llmProvider: this.llmProvider,
|
|
@@ -7330,7 +7448,7 @@ var Pipeline = class {
|
|
|
7330
7448
|
this.agent = new LangChainAgent(this, this.config);
|
|
7331
7449
|
await this.agent.initialize(this.llmProvider);
|
|
7332
7450
|
}
|
|
7333
|
-
if ((
|
|
7451
|
+
if ((_d = (_c = this.config.rag) == null ? void 0 : _c.cag) == null ? void 0 : _d.enabled) {
|
|
7334
7452
|
await this.loadColdContext(this.config.projectId);
|
|
7335
7453
|
}
|
|
7336
7454
|
this.initialised = true;
|
|
@@ -7493,9 +7611,9 @@ ${m.content}`).join("\n\n---\n\n");
|
|
|
7493
7611
|
return { reply, sources };
|
|
7494
7612
|
}
|
|
7495
7613
|
async ask(question, history = [], namespace) {
|
|
7496
|
-
var _a2;
|
|
7614
|
+
var _a2, _b;
|
|
7497
7615
|
await this.initialize();
|
|
7498
|
-
if ((((_a2 = this.config.rag) == null ? void 0 : _a2.architecture) === "agentic" || this.config.mcpServers && this.config.mcpServers.length > 0) && this.multiAgentCoordinator) {
|
|
7616
|
+
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) {
|
|
7499
7617
|
return await this.multiAgentCoordinator.run(question, history);
|
|
7500
7618
|
}
|
|
7501
7619
|
const stream = this.askStream(question, history, namespace);
|
|
@@ -7530,9 +7648,9 @@ ${m.content}`).join("\n\n---\n\n");
|
|
|
7530
7648
|
}
|
|
7531
7649
|
askStream(_0) {
|
|
7532
7650
|
return __asyncGenerator(this, arguments, function* (question, history = [], namespace) {
|
|
7533
|
-
var _a2;
|
|
7651
|
+
var _a2, _b;
|
|
7534
7652
|
yield new __await(this.initialize());
|
|
7535
|
-
if ((((_a2 = this.config.rag) == null ? void 0 : _a2.architecture) === "agentic" || this.config.mcpServers && this.config.mcpServers.length > 0) && this.multiAgentCoordinator) {
|
|
7653
|
+
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) {
|
|
7536
7654
|
const stream2 = this.multiAgentCoordinator.runStream(question, history);
|
|
7537
7655
|
try {
|
|
7538
7656
|
for (var iter = __forAwait(stream2), more, temp, error; more = !(temp = yield new __await(iter.next())).done; more = false) {
|
|
@@ -7581,7 +7699,7 @@ ${m.content}`).join("\n\n---\n\n");
|
|
|
7581
7699
|
*/
|
|
7582
7700
|
askStreamInternal(_0) {
|
|
7583
7701
|
return __asyncGenerator(this, arguments, function* (question, history = [], namespace) {
|
|
7584
|
-
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;
|
|
7702
|
+
var _a2, _b, _c, _d, _e, _f, _g2, _h, _i, _j, _k, _l, _m, _n, _o, _p, _q, _r, _s, _t, _u, _v, _w, _x, _y, _z, _A, _B, _C;
|
|
7585
7703
|
yield new __await(this.initialize());
|
|
7586
7704
|
const ns = namespace != null ? namespace : this.config.projectId;
|
|
7587
7705
|
const topK = (_b = (_a2 = this.config.rag) == null ? void 0 : _a2.topK) != null ? _b : 5;
|
|
@@ -7604,13 +7722,14 @@ ${m.content}`).join("\n\n---\n\n");
|
|
|
7604
7722
|
const embedStart = performance.now();
|
|
7605
7723
|
const cacheKey = `${ns}::${searchQuery}`;
|
|
7606
7724
|
const cachedVector = this.embeddingCache.get(cacheKey);
|
|
7607
|
-
const
|
|
7725
|
+
const arch = (_h = this.config.rag) == null ? void 0 : _h.architecture;
|
|
7726
|
+
const useGraph = arch !== "naive" && arch !== "retrieve-and-rerank" && this.graphDB && ((_i = this.config.rag) == null ? void 0 : _i.useGraphRetrieval);
|
|
7608
7727
|
const [strategyResult, embeddedVector] = yield new __await(Promise.all([
|
|
7609
7728
|
QueryProcessor.determineRetrievalStrategy(
|
|
7610
7729
|
searchQuery,
|
|
7611
7730
|
useGraph ? this.llmRouter.get("fast") : void 0,
|
|
7612
|
-
(
|
|
7613
|
-
(
|
|
7731
|
+
(_j = this.config.rag) == null ? void 0 : _j.graphKeywords,
|
|
7732
|
+
(_k = this.config.rag) == null ? void 0 : _k.vectorKeywords
|
|
7614
7733
|
),
|
|
7615
7734
|
// Embed immediately regardless of strategy — costs nothing if cached.
|
|
7616
7735
|
// If strategy turns out to be 'graph'-only we just won't use the vector.
|
|
@@ -7620,7 +7739,7 @@ ${m.content}`).join("\n\n---\n\n");
|
|
|
7620
7739
|
if (!cachedVector && queryVector.length > 0) {
|
|
7621
7740
|
this.embeddingCache.set(cacheKey, queryVector);
|
|
7622
7741
|
}
|
|
7623
|
-
const graphData = (strategyResult === "graph" || strategyResult === "both") && this.graphDB && ((
|
|
7742
|
+
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;
|
|
7624
7743
|
const hasMetadataFilter = filter.metadata && Object.keys(filter.metadata).length > 0;
|
|
7625
7744
|
const hasNumericPredicates = Array.isArray(filter.__numericPredicates) && filter.__numericPredicates.length > 0;
|
|
7626
7745
|
const wantsExhaustiveList = hasNumericPredicates || hasMetadataFilter || /\b(list|all|show|provide|give|get|browse|find|search|display)\b/i.test(question);
|
|
@@ -7633,7 +7752,8 @@ ${m.content}`).join("\n\n---\n\n");
|
|
|
7633
7752
|
const structuredSources = this.applyStructuredFilters(rawSources, filter);
|
|
7634
7753
|
let fullSources = hasNumericPredicates ? structuredSources : structuredSources.filter((m) => m.score >= scoreThreshold);
|
|
7635
7754
|
const rerankLimit = wantsExhaustiveList ? retrievalLimit : topK;
|
|
7636
|
-
|
|
7755
|
+
const useReranking = arch !== "naive" && (arch === "retrieve-and-rerank" || ((_m = this.config.rag) == null ? void 0 : _m.useReranking));
|
|
7756
|
+
if (!hasNumericPredicates && useReranking) {
|
|
7637
7757
|
fullSources = yield new __await(this.reranker.rerank(fullSources, question, rerankLimit));
|
|
7638
7758
|
} else if (!wantsExhaustiveList) {
|
|
7639
7759
|
fullSources = fullSources.slice(0, topK);
|
|
@@ -7663,7 +7783,7 @@ ${graphContext}
|
|
|
7663
7783
|
VECTOR CONTEXT:
|
|
7664
7784
|
${context}`;
|
|
7665
7785
|
}
|
|
7666
|
-
if ((
|
|
7786
|
+
if ((_o = (_n = this.config.rag) == null ? void 0 : _n.cag) == null ? void 0 : _o.enabled) {
|
|
7667
7787
|
if (!this.coldContexts.has(ns)) {
|
|
7668
7788
|
yield new __await(this.loadColdContext(ns));
|
|
7669
7789
|
}
|
|
@@ -7716,10 +7836,10 @@ ${context}`;
|
|
|
7716
7836
|
let hallucinationScoringPromise = Promise.resolve(void 0);
|
|
7717
7837
|
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.)";
|
|
7718
7838
|
const isClaude37 = this.config.llm.model.includes("claude-3-7-sonnet");
|
|
7719
|
-
const isNativeThinking = isClaude37 && (((
|
|
7839
|
+
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);
|
|
7720
7840
|
const modelNameLower = this.config.llm.model.toLowerCase();
|
|
7721
7841
|
const isReasoningModel = modelNameLower.includes("-r1") || modelNameLower.includes("deepseek-r1") || modelNameLower.includes("reasoning") || modelNameLower.includes("thinking");
|
|
7722
|
-
const isSimulatedThinking = !isNativeThinking && (((
|
|
7842
|
+
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);
|
|
7723
7843
|
let finalRestrictionSuffix = restrictionSuffix;
|
|
7724
7844
|
if (isSimulatedThinking) {
|
|
7725
7845
|
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.`)";
|
|
@@ -7727,7 +7847,7 @@ ${context}`;
|
|
|
7727
7847
|
const hardenedHistory = [...history];
|
|
7728
7848
|
const userQuestion = { role: "user", content: question + finalRestrictionSuffix };
|
|
7729
7849
|
const messages = [...hardenedHistory, userQuestion];
|
|
7730
|
-
const systemPrompt = (
|
|
7850
|
+
const systemPrompt = (_v = this.config.llm.systemPrompt) != null ? _v : "";
|
|
7731
7851
|
const userPrompt = messages.map((m) => `${m.role}: ${m.content}`).join("\n");
|
|
7732
7852
|
let fullReply = "";
|
|
7733
7853
|
let thinkingText = "";
|
|
@@ -7838,7 +7958,7 @@ ${context}`;
|
|
|
7838
7958
|
}
|
|
7839
7959
|
yield fullReply;
|
|
7840
7960
|
}
|
|
7841
|
-
const runHallucination = ((
|
|
7961
|
+
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;
|
|
7842
7962
|
if (runHallucination) {
|
|
7843
7963
|
hallucinationScoringPromise = scoreHallucination(this.llmProvider, fullReply, context).catch(() => void 0);
|
|
7844
7964
|
}
|
|
@@ -7847,7 +7967,7 @@ ${context}`;
|
|
|
7847
7967
|
const latency = {
|
|
7848
7968
|
embedMs: Math.round(embedMs),
|
|
7849
7969
|
retrieveMs: Math.round(retrieveMs),
|
|
7850
|
-
rerankMs: ((
|
|
7970
|
+
rerankMs: arch !== "naive" && (arch === "retrieve-and-rerank" || ((_y = this.config.rag) == null ? void 0 : _y.useReranking)) ? Math.round(rerankMs) : void 0,
|
|
7851
7971
|
generateMs: Math.round(generateMs),
|
|
7852
7972
|
totalMs: Math.round(totalMs)
|
|
7853
7973
|
};
|
|
@@ -7860,7 +7980,7 @@ ${context}`;
|
|
|
7860
7980
|
totalTokens: promptTokens + completionTokens,
|
|
7861
7981
|
estimatedCostUsd: estimateCostUsd(promptTokens, completionTokens, this.config.llm.model)
|
|
7862
7982
|
};
|
|
7863
|
-
const awaitHallucination = ((
|
|
7983
|
+
const awaitHallucination = ((_z = this.config.llm.options) == null ? void 0 : _z.awaitHallucination) === true;
|
|
7864
7984
|
const [uiTransformation, hallucinationResult] = yield new __await(Promise.all([
|
|
7865
7985
|
uiTransformationPromise,
|
|
7866
7986
|
awaitHallucination ? hallucinationScoringPromise : Promise.resolve(void 0)
|
|
@@ -7889,8 +8009,9 @@ ${context}`;
|
|
|
7889
8009
|
hallucinationReason: hScore.reason
|
|
7890
8010
|
} : {});
|
|
7891
8011
|
const trace = buildTrace(hallucinationResult);
|
|
7892
|
-
|
|
7893
|
-
|
|
8012
|
+
const isTelemetryActive = (_B = (_A = this.config.telemetry) == null ? void 0 : _A.enabled) != null ? _B : Boolean(this.config.licenseKey);
|
|
8013
|
+
if (isTelemetryActive) {
|
|
8014
|
+
const telemetryUrl = ((_C = this.config.telemetry) == null ? void 0 : _C.url) || "/api/telemetry";
|
|
7894
8015
|
const absoluteUrl = telemetryUrl.startsWith("http") ? telemetryUrl : (process.env.NEXT_PUBLIC_APP_URL || `http://localhost:${process.env.PORT || 3e3}`) + telemetryUrl;
|
|
7895
8016
|
(async () => {
|
|
7896
8017
|
try {
|
|
@@ -8165,6 +8286,7 @@ var Retrivora = class {
|
|
|
8165
8286
|
this.config.projectId,
|
|
8166
8287
|
(_a2 = this.config.vectorDb) == null ? void 0 : _a2.provider
|
|
8167
8288
|
);
|
|
8289
|
+
await LicenseVerifier.verifyIP(this.config.licenseKey);
|
|
8168
8290
|
} catch (err) {
|
|
8169
8291
|
throw wrapError(err, "CONFIGURATION_ERROR");
|
|
8170
8292
|
}
|
|
@@ -9239,6 +9361,43 @@ function getOrCreatePlugin(configOrPlugin) {
|
|
|
9239
9361
|
}
|
|
9240
9362
|
return _g[cacheKey];
|
|
9241
9363
|
}
|
|
9364
|
+
function reportTelemetry(req, plugin, action, status, details, trace) {
|
|
9365
|
+
var _a2;
|
|
9366
|
+
try {
|
|
9367
|
+
const config = plugin.getConfig();
|
|
9368
|
+
const licenseKey = config.licenseKey || process.env.RAG_LICENSE_KEY || process.env.RETRIVORA_LICENSE_KEY || process.env.NEXT_PUBLIC_RETRIVORA_LICENSE_KEY;
|
|
9369
|
+
const telemetryConfig = config.telemetry;
|
|
9370
|
+
const enabled = (_a2 = telemetryConfig == null ? void 0 : telemetryConfig.enabled) != null ? _a2 : Boolean(licenseKey);
|
|
9371
|
+
if (!enabled) return;
|
|
9372
|
+
const telemetryUrl = (telemetryConfig == null ? void 0 : telemetryConfig.url) || process.env.TELEMETRY_URL || process.env.NEXT_PUBLIC_TELEMETRY_URL || "/api/telemetry";
|
|
9373
|
+
const host = req.headers.get("host") || "localhost";
|
|
9374
|
+
let absoluteUrl = telemetryUrl;
|
|
9375
|
+
if (!telemetryUrl.startsWith("http")) {
|
|
9376
|
+
const proto = req.headers.get("x-forwarded-proto") || "http";
|
|
9377
|
+
absoluteUrl = `${proto}://${host}${telemetryUrl}`;
|
|
9378
|
+
}
|
|
9379
|
+
const projectId = config.projectId || "default";
|
|
9380
|
+
fetch(absoluteUrl, {
|
|
9381
|
+
method: "POST",
|
|
9382
|
+
headers: {
|
|
9383
|
+
"Content-Type": "application/json",
|
|
9384
|
+
"x-forwarded-for": req.headers.get("x-forwarded-for") || "",
|
|
9385
|
+
"x-real-ip": req.headers.get("x-real-ip") || ""
|
|
9386
|
+
},
|
|
9387
|
+
body: JSON.stringify({
|
|
9388
|
+
trace,
|
|
9389
|
+
licenseKey,
|
|
9390
|
+
projectId,
|
|
9391
|
+
action,
|
|
9392
|
+
status,
|
|
9393
|
+
details
|
|
9394
|
+
})
|
|
9395
|
+
}).catch((err) => {
|
|
9396
|
+
console.warn("[Retrivora Telemetry] Async report warning:", err.message);
|
|
9397
|
+
});
|
|
9398
|
+
} catch (e) {
|
|
9399
|
+
}
|
|
9400
|
+
}
|
|
9242
9401
|
function sseFrame(payload) {
|
|
9243
9402
|
return `data: ${JSON.stringify(payload)}
|
|
9244
9403
|
|
|
@@ -9281,6 +9440,7 @@ function createChatHandler(configOrPlugin, options) {
|
|
|
9281
9440
|
const storage = new DatabaseStorage(plugin.getConfig());
|
|
9282
9441
|
const onAuthorize = options == null ? void 0 : options.onAuthorize;
|
|
9283
9442
|
return async function POST(req) {
|
|
9443
|
+
var _a2, _b, _c, _d;
|
|
9284
9444
|
const authResult = await checkAuth(req, onAuthorize);
|
|
9285
9445
|
if (authResult) return authResult;
|
|
9286
9446
|
const rateLimited = checkRateLimit(req);
|
|
@@ -9309,12 +9469,14 @@ function createChatHandler(configOrPlugin, options) {
|
|
|
9309
9469
|
uiTransformation: result.ui_transformation,
|
|
9310
9470
|
trace: result.trace
|
|
9311
9471
|
}).catch((err) => console.warn("[createChatHandler] Failed to save assistant message:", err));
|
|
9472
|
+
reportTelemetry(req, plugin, "QUERY_GENERATION", "success", `Tokens: ${((_b = (_a2 = result.trace) == null ? void 0 : _a2.tokens) == null ? void 0 : _b.totalTokens) || 0}, Latency: ${((_d = (_c = result.trace) == null ? void 0 : _c.latency) == null ? void 0 : _d.totalMs) || 0}ms`, result.trace);
|
|
9312
9473
|
return NextResponse.json(__spreadProps(__spreadValues({}, result), {
|
|
9313
9474
|
messageId: assistantMsgId,
|
|
9314
9475
|
userMessageId: userMsgId
|
|
9315
9476
|
}));
|
|
9316
9477
|
} catch (err) {
|
|
9317
9478
|
const message = err instanceof Error ? err.message : "Internal server error";
|
|
9479
|
+
reportTelemetry(req, plugin, "QUERY_GENERATION", "error", message);
|
|
9318
9480
|
return NextResponse.json({ error: message }, { status: 500 });
|
|
9319
9481
|
}
|
|
9320
9482
|
};
|
|
@@ -9357,7 +9519,7 @@ function createStreamHandler(configOrPlugin, options) {
|
|
|
9357
9519
|
let isActive = true;
|
|
9358
9520
|
const stream = new ReadableStream({
|
|
9359
9521
|
async start(controller) {
|
|
9360
|
-
var _a2;
|
|
9522
|
+
var _a2, _b, _c, _d, _e;
|
|
9361
9523
|
const enqueue = (text) => {
|
|
9362
9524
|
if (!isActive) return;
|
|
9363
9525
|
try {
|
|
@@ -9414,6 +9576,7 @@ function createStreamHandler(configOrPlugin, options) {
|
|
|
9414
9576
|
uiTransformation,
|
|
9415
9577
|
trace: responseChunk == null ? void 0 : responseChunk.trace
|
|
9416
9578
|
}).catch((err) => console.warn("[createStreamHandler] Failed to save assistant message:", err));
|
|
9579
|
+
reportTelemetry(req, plugin, "QUERY_GENERATION", "success", `Tokens: ${((_c = (_b = responseChunk == null ? void 0 : responseChunk.trace) == null ? void 0 : _b.tokens) == null ? void 0 : _c.totalTokens) || 0}, Latency: ${((_e = (_d = responseChunk == null ? void 0 : responseChunk.trace) == null ? void 0 : _d.latency) == null ? void 0 : _e.totalMs) || 0}ms`, responseChunk == null ? void 0 : responseChunk.trace);
|
|
9417
9580
|
}
|
|
9418
9581
|
}
|
|
9419
9582
|
} catch (temp) {
|
|
@@ -9430,6 +9593,7 @@ function createStreamHandler(configOrPlugin, options) {
|
|
|
9430
9593
|
if (isActive) {
|
|
9431
9594
|
const errorMessage = streamError instanceof Error ? streamError.message : String(streamError);
|
|
9432
9595
|
console.error("[createStreamHandler] Stream error:", streamError);
|
|
9596
|
+
reportTelemetry(req, plugin, "QUERY_GENERATION", "error", errorMessage);
|
|
9433
9597
|
try {
|
|
9434
9598
|
enqueue(sseErrorFrame(errorMessage));
|
|
9435
9599
|
} catch (e) {
|
|
@@ -9466,9 +9630,11 @@ function createIngestHandler(configOrPlugin, options) {
|
|
|
9466
9630
|
return NextResponse.json({ error: "documents array is required" }, { status: 400 });
|
|
9467
9631
|
}
|
|
9468
9632
|
const results = await plugin.ingest(documents, namespace);
|
|
9633
|
+
reportTelemetry(req, plugin, "DOCUMENT_INGESTION", "success", `Ingested ${documents.length} document(s)`);
|
|
9469
9634
|
return NextResponse.json({ results });
|
|
9470
9635
|
} catch (err) {
|
|
9471
9636
|
const message = err instanceof Error ? err.message : "Internal server error";
|
|
9637
|
+
reportTelemetry(req, plugin, "DOCUMENT_INGESTION", "error", message);
|
|
9472
9638
|
return NextResponse.json({ error: message }, { status: 500 });
|
|
9473
9639
|
}
|
|
9474
9640
|
};
|
|
@@ -9567,9 +9733,11 @@ function createUploadHandler(configOrPlugin, options) {
|
|
|
9567
9733
|
}
|
|
9568
9734
|
}
|
|
9569
9735
|
const results = await plugin.ingest(documents, namespace);
|
|
9736
|
+
reportTelemetry(req, plugin, "DOCUMENT_INGESTION", "success", `Uploaded & ingested ${files.length} file(s)`);
|
|
9570
9737
|
return NextResponse.json({ message: "Upload successful", results });
|
|
9571
9738
|
} catch (err) {
|
|
9572
9739
|
const message = err instanceof Error ? err.message : "Upload failed";
|
|
9740
|
+
reportTelemetry(req, plugin, "DOCUMENT_INGESTION", "error", message);
|
|
9573
9741
|
return NextResponse.json({ error: message }, { status: 500 });
|
|
9574
9742
|
}
|
|
9575
9743
|
};
|
|
@@ -9577,19 +9745,30 @@ function createUploadHandler(configOrPlugin, options) {
|
|
|
9577
9745
|
function createSuggestionsHandler(configOrPlugin, options) {
|
|
9578
9746
|
const plugin = getOrCreatePlugin(configOrPlugin);
|
|
9579
9747
|
const onAuthorize = options == null ? void 0 : options.onAuthorize;
|
|
9580
|
-
return async function
|
|
9748
|
+
return async function handler(req) {
|
|
9581
9749
|
const authResult = await checkAuth(req, onAuthorize);
|
|
9582
9750
|
if (authResult) return authResult;
|
|
9583
9751
|
try {
|
|
9584
|
-
|
|
9585
|
-
|
|
9752
|
+
let query = "";
|
|
9753
|
+
let namespace = void 0;
|
|
9754
|
+
if (req.method === "POST") {
|
|
9755
|
+
const body = await req.json().catch(() => ({}));
|
|
9756
|
+
query = body.query || "";
|
|
9757
|
+
namespace = body.namespace;
|
|
9758
|
+
} else {
|
|
9759
|
+
const url = new URL(req.url);
|
|
9760
|
+
query = url.searchParams.get("query") || "";
|
|
9761
|
+
namespace = url.searchParams.get("namespace") || void 0;
|
|
9762
|
+
}
|
|
9586
9763
|
if (typeof query !== "string") {
|
|
9587
9764
|
return NextResponse.json({ error: "query is required" }, { status: 400 });
|
|
9588
9765
|
}
|
|
9589
9766
|
const suggestions = await plugin.getSuggestions(query, namespace);
|
|
9767
|
+
reportTelemetry(req, plugin, "AUTO_SUGGESTIONS", "success", `Fetched ${suggestions.length} suggestions for: ${query.slice(0, 30)}`);
|
|
9590
9768
|
return NextResponse.json({ suggestions });
|
|
9591
9769
|
} catch (err) {
|
|
9592
9770
|
const message = err instanceof Error ? err.message : "Internal server error";
|
|
9771
|
+
reportTelemetry(req, plugin, "AUTO_SUGGESTIONS", "error", message);
|
|
9593
9772
|
return NextResponse.json({ error: message }, { status: 500 });
|
|
9594
9773
|
}
|
|
9595
9774
|
};
|
|
@@ -9721,6 +9900,8 @@ function createRagHandler(configOrPlugin, options) {
|
|
|
9721
9900
|
switch (segment) {
|
|
9722
9901
|
case "health":
|
|
9723
9902
|
return healthHandler(req);
|
|
9903
|
+
case "suggestions":
|
|
9904
|
+
return suggestionsHandler(req);
|
|
9724
9905
|
case "history":
|
|
9725
9906
|
return historyHandler(req);
|
|
9726
9907
|
case "feedback":
|