@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.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 readEnum(env, name, fallback, allowed) {
|
|
|
2121
2127
|
throw new Error(`[getRagConfig] ${name} must be one of: ${allowed.join(", ")}`);
|
|
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
|
};
|
|
@@ -7111,7 +7143,7 @@ var Pipeline = class {
|
|
|
7111
7143
|
return this.initialised ? this.llmProvider : void 0;
|
|
7112
7144
|
}
|
|
7113
7145
|
async initialize() {
|
|
7114
|
-
var _a2, _b, _c;
|
|
7146
|
+
var _a2, _b, _c, _d;
|
|
7115
7147
|
if (this.initialised) return;
|
|
7116
7148
|
const chartInstruction = `You are a helpful assistant. Use the provided context to answer questions accurately.
|
|
7117
7149
|
|
|
@@ -7154,7 +7186,7 @@ var Pipeline = class {
|
|
|
7154
7186
|
this.entityExtractor = new EntityExtractor(this.llmProvider);
|
|
7155
7187
|
}
|
|
7156
7188
|
await this.vectorDB.initialize();
|
|
7157
|
-
if (((_a2 = this.config.rag) == null ? void 0 : _a2.architecture) === "agentic" || this.config.mcpServers && this.config.mcpServers.length > 0) {
|
|
7189
|
+
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) {
|
|
7158
7190
|
this.mcpRegistry = new MCPRegistry(this.config.mcpServers || []);
|
|
7159
7191
|
this.multiAgentCoordinator = new MultiAgentCoordinator({
|
|
7160
7192
|
llmProvider: this.llmProvider,
|
|
@@ -7166,7 +7198,7 @@ var Pipeline = class {
|
|
|
7166
7198
|
this.agent = new LangChainAgent(this, this.config);
|
|
7167
7199
|
await this.agent.initialize(this.llmProvider);
|
|
7168
7200
|
}
|
|
7169
|
-
if ((
|
|
7201
|
+
if ((_d = (_c = this.config.rag) == null ? void 0 : _c.cag) == null ? void 0 : _d.enabled) {
|
|
7170
7202
|
await this.loadColdContext(this.config.projectId);
|
|
7171
7203
|
}
|
|
7172
7204
|
this.initialised = true;
|
|
@@ -7329,9 +7361,9 @@ ${m.content}`).join("\n\n---\n\n");
|
|
|
7329
7361
|
return { reply, sources };
|
|
7330
7362
|
}
|
|
7331
7363
|
async ask(question, history = [], namespace) {
|
|
7332
|
-
var _a2;
|
|
7364
|
+
var _a2, _b;
|
|
7333
7365
|
await this.initialize();
|
|
7334
|
-
if ((((_a2 = this.config.rag) == null ? void 0 : _a2.architecture) === "agentic" || this.config.mcpServers && this.config.mcpServers.length > 0) && this.multiAgentCoordinator) {
|
|
7366
|
+
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) {
|
|
7335
7367
|
return await this.multiAgentCoordinator.run(question, history);
|
|
7336
7368
|
}
|
|
7337
7369
|
const stream = this.askStream(question, history, namespace);
|
|
@@ -7366,9 +7398,9 @@ ${m.content}`).join("\n\n---\n\n");
|
|
|
7366
7398
|
}
|
|
7367
7399
|
askStream(_0) {
|
|
7368
7400
|
return __asyncGenerator(this, arguments, function* (question, history = [], namespace) {
|
|
7369
|
-
var _a2;
|
|
7401
|
+
var _a2, _b;
|
|
7370
7402
|
yield new __await(this.initialize());
|
|
7371
|
-
if ((((_a2 = this.config.rag) == null ? void 0 : _a2.architecture) === "agentic" || this.config.mcpServers && this.config.mcpServers.length > 0) && this.multiAgentCoordinator) {
|
|
7403
|
+
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) {
|
|
7372
7404
|
const stream2 = this.multiAgentCoordinator.runStream(question, history);
|
|
7373
7405
|
try {
|
|
7374
7406
|
for (var iter = __forAwait(stream2), more, temp, error; more = !(temp = yield new __await(iter.next())).done; more = false) {
|
|
@@ -7417,7 +7449,7 @@ ${m.content}`).join("\n\n---\n\n");
|
|
|
7417
7449
|
*/
|
|
7418
7450
|
askStreamInternal(_0) {
|
|
7419
7451
|
return __asyncGenerator(this, arguments, function* (question, history = [], namespace) {
|
|
7420
|
-
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;
|
|
7452
|
+
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;
|
|
7421
7453
|
yield new __await(this.initialize());
|
|
7422
7454
|
const ns = namespace != null ? namespace : this.config.projectId;
|
|
7423
7455
|
const topK = (_b = (_a2 = this.config.rag) == null ? void 0 : _a2.topK) != null ? _b : 5;
|
|
@@ -7440,13 +7472,14 @@ ${m.content}`).join("\n\n---\n\n");
|
|
|
7440
7472
|
const embedStart = performance.now();
|
|
7441
7473
|
const cacheKey = `${ns}::${searchQuery}`;
|
|
7442
7474
|
const cachedVector = this.embeddingCache.get(cacheKey);
|
|
7443
|
-
const
|
|
7475
|
+
const arch = (_h = this.config.rag) == null ? void 0 : _h.architecture;
|
|
7476
|
+
const useGraph = arch !== "naive" && arch !== "retrieve-and-rerank" && this.graphDB && ((_i = this.config.rag) == null ? void 0 : _i.useGraphRetrieval);
|
|
7444
7477
|
const [strategyResult, embeddedVector] = yield new __await(Promise.all([
|
|
7445
7478
|
QueryProcessor.determineRetrievalStrategy(
|
|
7446
7479
|
searchQuery,
|
|
7447
7480
|
useGraph ? this.llmRouter.get("fast") : void 0,
|
|
7448
|
-
(
|
|
7449
|
-
(
|
|
7481
|
+
(_j = this.config.rag) == null ? void 0 : _j.graphKeywords,
|
|
7482
|
+
(_k = this.config.rag) == null ? void 0 : _k.vectorKeywords
|
|
7450
7483
|
),
|
|
7451
7484
|
// Embed immediately regardless of strategy — costs nothing if cached.
|
|
7452
7485
|
// If strategy turns out to be 'graph'-only we just won't use the vector.
|
|
@@ -7456,7 +7489,7 @@ ${m.content}`).join("\n\n---\n\n");
|
|
|
7456
7489
|
if (!cachedVector && queryVector.length > 0) {
|
|
7457
7490
|
this.embeddingCache.set(cacheKey, queryVector);
|
|
7458
7491
|
}
|
|
7459
|
-
const graphData = (strategyResult === "graph" || strategyResult === "both") && this.graphDB && ((
|
|
7492
|
+
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;
|
|
7460
7493
|
const hasMetadataFilter = filter.metadata && Object.keys(filter.metadata).length > 0;
|
|
7461
7494
|
const hasNumericPredicates = Array.isArray(filter.__numericPredicates) && filter.__numericPredicates.length > 0;
|
|
7462
7495
|
const wantsExhaustiveList = hasNumericPredicates || hasMetadataFilter || /\b(list|all|show|provide|give|get|browse|find|search|display)\b/i.test(question);
|
|
@@ -7469,7 +7502,8 @@ ${m.content}`).join("\n\n---\n\n");
|
|
|
7469
7502
|
const structuredSources = this.applyStructuredFilters(rawSources, filter);
|
|
7470
7503
|
let fullSources = hasNumericPredicates ? structuredSources : structuredSources.filter((m) => m.score >= scoreThreshold);
|
|
7471
7504
|
const rerankLimit = wantsExhaustiveList ? retrievalLimit : topK;
|
|
7472
|
-
|
|
7505
|
+
const useReranking = arch !== "naive" && (arch === "retrieve-and-rerank" || ((_m = this.config.rag) == null ? void 0 : _m.useReranking));
|
|
7506
|
+
if (!hasNumericPredicates && useReranking) {
|
|
7473
7507
|
fullSources = yield new __await(this.reranker.rerank(fullSources, question, rerankLimit));
|
|
7474
7508
|
} else if (!wantsExhaustiveList) {
|
|
7475
7509
|
fullSources = fullSources.slice(0, topK);
|
|
@@ -7499,7 +7533,7 @@ ${graphContext}
|
|
|
7499
7533
|
VECTOR CONTEXT:
|
|
7500
7534
|
${context}`;
|
|
7501
7535
|
}
|
|
7502
|
-
if ((
|
|
7536
|
+
if ((_o = (_n = this.config.rag) == null ? void 0 : _n.cag) == null ? void 0 : _o.enabled) {
|
|
7503
7537
|
if (!this.coldContexts.has(ns)) {
|
|
7504
7538
|
yield new __await(this.loadColdContext(ns));
|
|
7505
7539
|
}
|
|
@@ -7552,10 +7586,10 @@ ${context}`;
|
|
|
7552
7586
|
let hallucinationScoringPromise = Promise.resolve(void 0);
|
|
7553
7587
|
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.)";
|
|
7554
7588
|
const isClaude37 = this.config.llm.model.includes("claude-3-7-sonnet");
|
|
7555
|
-
const isNativeThinking = isClaude37 && (((
|
|
7589
|
+
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);
|
|
7556
7590
|
const modelNameLower = this.config.llm.model.toLowerCase();
|
|
7557
7591
|
const isReasoningModel = modelNameLower.includes("-r1") || modelNameLower.includes("deepseek-r1") || modelNameLower.includes("reasoning") || modelNameLower.includes("thinking");
|
|
7558
|
-
const isSimulatedThinking = !isNativeThinking && (((
|
|
7592
|
+
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);
|
|
7559
7593
|
let finalRestrictionSuffix = restrictionSuffix;
|
|
7560
7594
|
if (isSimulatedThinking) {
|
|
7561
7595
|
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.`)";
|
|
@@ -7563,7 +7597,7 @@ ${context}`;
|
|
|
7563
7597
|
const hardenedHistory = [...history];
|
|
7564
7598
|
const userQuestion = { role: "user", content: question + finalRestrictionSuffix };
|
|
7565
7599
|
const messages = [...hardenedHistory, userQuestion];
|
|
7566
|
-
const systemPrompt = (
|
|
7600
|
+
const systemPrompt = (_v = this.config.llm.systemPrompt) != null ? _v : "";
|
|
7567
7601
|
const userPrompt = messages.map((m) => `${m.role}: ${m.content}`).join("\n");
|
|
7568
7602
|
let fullReply = "";
|
|
7569
7603
|
let thinkingText = "";
|
|
@@ -7674,7 +7708,7 @@ ${context}`;
|
|
|
7674
7708
|
}
|
|
7675
7709
|
yield fullReply;
|
|
7676
7710
|
}
|
|
7677
|
-
const runHallucination = ((
|
|
7711
|
+
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;
|
|
7678
7712
|
if (runHallucination) {
|
|
7679
7713
|
hallucinationScoringPromise = scoreHallucination(this.llmProvider, fullReply, context).catch(() => void 0);
|
|
7680
7714
|
}
|
|
@@ -7683,7 +7717,7 @@ ${context}`;
|
|
|
7683
7717
|
const latency = {
|
|
7684
7718
|
embedMs: Math.round(embedMs),
|
|
7685
7719
|
retrieveMs: Math.round(retrieveMs),
|
|
7686
|
-
rerankMs: ((
|
|
7720
|
+
rerankMs: arch !== "naive" && (arch === "retrieve-and-rerank" || ((_y = this.config.rag) == null ? void 0 : _y.useReranking)) ? Math.round(rerankMs) : void 0,
|
|
7687
7721
|
generateMs: Math.round(generateMs),
|
|
7688
7722
|
totalMs: Math.round(totalMs)
|
|
7689
7723
|
};
|
|
@@ -7696,7 +7730,7 @@ ${context}`;
|
|
|
7696
7730
|
totalTokens: promptTokens + completionTokens,
|
|
7697
7731
|
estimatedCostUsd: estimateCostUsd(promptTokens, completionTokens, this.config.llm.model)
|
|
7698
7732
|
};
|
|
7699
|
-
const awaitHallucination = ((
|
|
7733
|
+
const awaitHallucination = ((_z = this.config.llm.options) == null ? void 0 : _z.awaitHallucination) === true;
|
|
7700
7734
|
const [uiTransformation, hallucinationResult] = yield new __await(Promise.all([
|
|
7701
7735
|
uiTransformationPromise,
|
|
7702
7736
|
awaitHallucination ? hallucinationScoringPromise : Promise.resolve(void 0)
|
|
@@ -7725,8 +7759,9 @@ ${context}`;
|
|
|
7725
7759
|
hallucinationReason: hScore.reason
|
|
7726
7760
|
} : {});
|
|
7727
7761
|
const trace = buildTrace(hallucinationResult);
|
|
7728
|
-
|
|
7729
|
-
|
|
7762
|
+
const isTelemetryActive = (_B = (_A = this.config.telemetry) == null ? void 0 : _A.enabled) != null ? _B : Boolean(this.config.licenseKey);
|
|
7763
|
+
if (isTelemetryActive) {
|
|
7764
|
+
const telemetryUrl = ((_C = this.config.telemetry) == null ? void 0 : _C.url) || "/api/telemetry";
|
|
7730
7765
|
const absoluteUrl = telemetryUrl.startsWith("http") ? telemetryUrl : (process.env.NEXT_PUBLIC_APP_URL || `http://localhost:${process.env.PORT || 3e3}`) + telemetryUrl;
|
|
7731
7766
|
(async () => {
|
|
7732
7767
|
try {
|
|
@@ -8101,6 +8136,19 @@ var LicenseVerifier = class {
|
|
|
8101
8136
|
*/
|
|
8102
8137
|
static verify(licenseKey, currentProjectId, provider, publicKeyOverride) {
|
|
8103
8138
|
const isProduction = process.env.NODE_ENV === "production";
|
|
8139
|
+
const now = Date.now();
|
|
8140
|
+
if (licenseKey) {
|
|
8141
|
+
const cacheKey = `${licenseKey}:${currentProjectId}:${provider || ""}:${publicKeyOverride || ""}`;
|
|
8142
|
+
const cached = this.cache.get(cacheKey);
|
|
8143
|
+
if (cached && now - cached.cachedAt < this.CACHE_TTL_MS) {
|
|
8144
|
+
const currentTimestampSec = Math.floor(now / 1e3);
|
|
8145
|
+
if (cached.payload.expiresAt && currentTimestampSec > cached.payload.expiresAt) {
|
|
8146
|
+
this.cache.delete(cacheKey);
|
|
8147
|
+
} else {
|
|
8148
|
+
return cached.payload;
|
|
8149
|
+
}
|
|
8150
|
+
}
|
|
8151
|
+
}
|
|
8104
8152
|
if (!licenseKey) {
|
|
8105
8153
|
if (isProduction) {
|
|
8106
8154
|
throw new ConfigurationException(
|
|
@@ -8187,6 +8235,10 @@ var LicenseVerifier = class {
|
|
|
8187
8235
|
}
|
|
8188
8236
|
}
|
|
8189
8237
|
}
|
|
8238
|
+
if (licenseKey) {
|
|
8239
|
+
const cacheKey = `${licenseKey}:${currentProjectId}:${provider || ""}:${publicKeyOverride || ""}`;
|
|
8240
|
+
this.cache.set(cacheKey, { payload, cachedAt: now });
|
|
8241
|
+
}
|
|
8190
8242
|
return payload;
|
|
8191
8243
|
} catch (err) {
|
|
8192
8244
|
const message = err instanceof Error ? err.message : String(err);
|
|
@@ -8195,7 +8247,76 @@ var LicenseVerifier = class {
|
|
|
8195
8247
|
);
|
|
8196
8248
|
}
|
|
8197
8249
|
}
|
|
8250
|
+
static async verifyIP(licenseKey) {
|
|
8251
|
+
if (!licenseKey) return;
|
|
8252
|
+
try {
|
|
8253
|
+
const parts = licenseKey.split(".");
|
|
8254
|
+
if (parts.length !== 3) return;
|
|
8255
|
+
const [, payloadB64] = parts;
|
|
8256
|
+
const payload = JSON.parse(
|
|
8257
|
+
Buffer.from(payloadB64, "base64url").toString("utf8")
|
|
8258
|
+
);
|
|
8259
|
+
const tier = (payload.tier || "").toLowerCase();
|
|
8260
|
+
if (tier === "enterprise" || tier === "custom") {
|
|
8261
|
+
return;
|
|
8262
|
+
}
|
|
8263
|
+
if (payload.ipv4 || payload.ipv6) {
|
|
8264
|
+
let currentIpv4 = "";
|
|
8265
|
+
let currentIpv6 = "";
|
|
8266
|
+
try {
|
|
8267
|
+
const res = await fetch("https://api4.ipify.org?format=json", { signal: AbortSignal.timeout(3e3) });
|
|
8268
|
+
const data = await res.json();
|
|
8269
|
+
currentIpv4 = data.ip;
|
|
8270
|
+
} catch (e) {
|
|
8271
|
+
}
|
|
8272
|
+
try {
|
|
8273
|
+
const res = await fetch("https://api6.ipify.org?format=json", { signal: AbortSignal.timeout(3e3) });
|
|
8274
|
+
const data = await res.json();
|
|
8275
|
+
currentIpv6 = data.ip;
|
|
8276
|
+
} catch (e) {
|
|
8277
|
+
}
|
|
8278
|
+
const localIps = [];
|
|
8279
|
+
try {
|
|
8280
|
+
const osModule = __require("os");
|
|
8281
|
+
const interfaces = osModule.networkInterfaces();
|
|
8282
|
+
for (const name of Object.keys(interfaces)) {
|
|
8283
|
+
for (const iface of interfaces[name] || []) {
|
|
8284
|
+
if (!iface.internal) {
|
|
8285
|
+
localIps.push(iface.address);
|
|
8286
|
+
}
|
|
8287
|
+
}
|
|
8288
|
+
}
|
|
8289
|
+
} catch (e) {
|
|
8290
|
+
}
|
|
8291
|
+
const isIpv4Match = payload.ipv4 && (currentIpv4 === payload.ipv4 || localIps.includes(payload.ipv4));
|
|
8292
|
+
const isIpv6Match = payload.ipv6 && (currentIpv6 === payload.ipv6 || localIps.includes(payload.ipv6));
|
|
8293
|
+
if (payload.ipv4 && payload.ipv6) {
|
|
8294
|
+
if (!isIpv4Match && !isIpv6Match) {
|
|
8295
|
+
throw new Error(
|
|
8296
|
+
`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.`
|
|
8297
|
+
);
|
|
8298
|
+
}
|
|
8299
|
+
} else if (payload.ipv4 && !isIpv4Match) {
|
|
8300
|
+
throw new Error(
|
|
8301
|
+
`License key access restricted. This license key was created for a different system (authorized IPv4: ${payload.ipv4}) and cannot be used on this machine.`
|
|
8302
|
+
);
|
|
8303
|
+
} else if (payload.ipv6 && !isIpv6Match) {
|
|
8304
|
+
throw new Error(
|
|
8305
|
+
`License key access restricted. This license key was created for a different system (authorized IPv6: ${payload.ipv6}) and cannot be used on this machine.`
|
|
8306
|
+
);
|
|
8307
|
+
}
|
|
8308
|
+
}
|
|
8309
|
+
} catch (err) {
|
|
8310
|
+
if (err.message.includes("License key access restricted")) {
|
|
8311
|
+
throw new ConfigurationException(`[Retrivora SDK] ${err.message}`);
|
|
8312
|
+
}
|
|
8313
|
+
}
|
|
8314
|
+
}
|
|
8198
8315
|
};
|
|
8316
|
+
// A simple in-memory cache to save CPU overhead of cryptographic signature checks.
|
|
8317
|
+
LicenseVerifier.cache = /* @__PURE__ */ new Map();
|
|
8318
|
+
LicenseVerifier.CACHE_TTL_MS = 60 * 1e3;
|
|
8319
|
+
// Cache verified license for 60 seconds
|
|
8199
8320
|
// Retrivora's Public Key used to verify the license key signature.
|
|
8200
8321
|
// In production, this matches the private key held by Retrivora SaaS.
|
|
8201
8322
|
LicenseVerifier.PUBLIC_KEY = `-----BEGIN PUBLIC KEY-----
|
|
@@ -8896,6 +9017,43 @@ function getOrCreatePlugin(configOrPlugin) {
|
|
|
8896
9017
|
}
|
|
8897
9018
|
return _g[cacheKey];
|
|
8898
9019
|
}
|
|
9020
|
+
function reportTelemetry(req, plugin, action, status, details, trace) {
|
|
9021
|
+
var _a2;
|
|
9022
|
+
try {
|
|
9023
|
+
const config = plugin.getConfig();
|
|
9024
|
+
const licenseKey = config.licenseKey || process.env.RAG_LICENSE_KEY || process.env.RETRIVORA_LICENSE_KEY || process.env.NEXT_PUBLIC_RETRIVORA_LICENSE_KEY;
|
|
9025
|
+
const telemetryConfig = config.telemetry;
|
|
9026
|
+
const enabled = (_a2 = telemetryConfig == null ? void 0 : telemetryConfig.enabled) != null ? _a2 : Boolean(licenseKey);
|
|
9027
|
+
if (!enabled) return;
|
|
9028
|
+
const telemetryUrl = (telemetryConfig == null ? void 0 : telemetryConfig.url) || process.env.TELEMETRY_URL || process.env.NEXT_PUBLIC_TELEMETRY_URL || "/api/telemetry";
|
|
9029
|
+
const host = req.headers.get("host") || "localhost";
|
|
9030
|
+
let absoluteUrl = telemetryUrl;
|
|
9031
|
+
if (!telemetryUrl.startsWith("http")) {
|
|
9032
|
+
const proto = req.headers.get("x-forwarded-proto") || "http";
|
|
9033
|
+
absoluteUrl = `${proto}://${host}${telemetryUrl}`;
|
|
9034
|
+
}
|
|
9035
|
+
const projectId = config.projectId || "default";
|
|
9036
|
+
fetch(absoluteUrl, {
|
|
9037
|
+
method: "POST",
|
|
9038
|
+
headers: {
|
|
9039
|
+
"Content-Type": "application/json",
|
|
9040
|
+
"x-forwarded-for": req.headers.get("x-forwarded-for") || "",
|
|
9041
|
+
"x-real-ip": req.headers.get("x-real-ip") || ""
|
|
9042
|
+
},
|
|
9043
|
+
body: JSON.stringify({
|
|
9044
|
+
trace,
|
|
9045
|
+
licenseKey,
|
|
9046
|
+
projectId,
|
|
9047
|
+
action,
|
|
9048
|
+
status,
|
|
9049
|
+
details
|
|
9050
|
+
})
|
|
9051
|
+
}).catch((err) => {
|
|
9052
|
+
console.warn("[Retrivora Telemetry] Async report warning:", err.message);
|
|
9053
|
+
});
|
|
9054
|
+
} catch (e) {
|
|
9055
|
+
}
|
|
9056
|
+
}
|
|
8899
9057
|
function sseFrame(payload) {
|
|
8900
9058
|
return `data: ${JSON.stringify(payload)}
|
|
8901
9059
|
|
|
@@ -8938,6 +9096,7 @@ function createChatHandler(configOrPlugin, options) {
|
|
|
8938
9096
|
const storage = new DatabaseStorage(plugin.getConfig());
|
|
8939
9097
|
const onAuthorize = options == null ? void 0 : options.onAuthorize;
|
|
8940
9098
|
return async function POST(req) {
|
|
9099
|
+
var _a2, _b, _c, _d;
|
|
8941
9100
|
const authResult = await checkAuth(req, onAuthorize);
|
|
8942
9101
|
if (authResult) return authResult;
|
|
8943
9102
|
const rateLimited = checkRateLimit(req);
|
|
@@ -8966,12 +9125,14 @@ function createChatHandler(configOrPlugin, options) {
|
|
|
8966
9125
|
uiTransformation: result.ui_transformation,
|
|
8967
9126
|
trace: result.trace
|
|
8968
9127
|
}).catch((err) => console.warn("[createChatHandler] Failed to save assistant message:", err));
|
|
9128
|
+
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);
|
|
8969
9129
|
return NextResponse.json(__spreadProps(__spreadValues({}, result), {
|
|
8970
9130
|
messageId: assistantMsgId,
|
|
8971
9131
|
userMessageId: userMsgId
|
|
8972
9132
|
}));
|
|
8973
9133
|
} catch (err) {
|
|
8974
9134
|
const message = err instanceof Error ? err.message : "Internal server error";
|
|
9135
|
+
reportTelemetry(req, plugin, "QUERY_GENERATION", "error", message);
|
|
8975
9136
|
return NextResponse.json({ error: message }, { status: 500 });
|
|
8976
9137
|
}
|
|
8977
9138
|
};
|
|
@@ -9014,7 +9175,7 @@ function createStreamHandler(configOrPlugin, options) {
|
|
|
9014
9175
|
let isActive = true;
|
|
9015
9176
|
const stream = new ReadableStream({
|
|
9016
9177
|
async start(controller) {
|
|
9017
|
-
var _a2;
|
|
9178
|
+
var _a2, _b, _c, _d, _e;
|
|
9018
9179
|
const enqueue = (text) => {
|
|
9019
9180
|
if (!isActive) return;
|
|
9020
9181
|
try {
|
|
@@ -9071,6 +9232,7 @@ function createStreamHandler(configOrPlugin, options) {
|
|
|
9071
9232
|
uiTransformation,
|
|
9072
9233
|
trace: responseChunk == null ? void 0 : responseChunk.trace
|
|
9073
9234
|
}).catch((err) => console.warn("[createStreamHandler] Failed to save assistant message:", err));
|
|
9235
|
+
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);
|
|
9074
9236
|
}
|
|
9075
9237
|
}
|
|
9076
9238
|
} catch (temp) {
|
|
@@ -9087,6 +9249,7 @@ function createStreamHandler(configOrPlugin, options) {
|
|
|
9087
9249
|
if (isActive) {
|
|
9088
9250
|
const errorMessage = streamError instanceof Error ? streamError.message : String(streamError);
|
|
9089
9251
|
console.error("[createStreamHandler] Stream error:", streamError);
|
|
9252
|
+
reportTelemetry(req, plugin, "QUERY_GENERATION", "error", errorMessage);
|
|
9090
9253
|
try {
|
|
9091
9254
|
enqueue(sseErrorFrame(errorMessage));
|
|
9092
9255
|
} catch (e) {
|
|
@@ -9123,9 +9286,11 @@ function createIngestHandler(configOrPlugin, options) {
|
|
|
9123
9286
|
return NextResponse.json({ error: "documents array is required" }, { status: 400 });
|
|
9124
9287
|
}
|
|
9125
9288
|
const results = await plugin.ingest(documents, namespace);
|
|
9289
|
+
reportTelemetry(req, plugin, "DOCUMENT_INGESTION", "success", `Ingested ${documents.length} document(s)`);
|
|
9126
9290
|
return NextResponse.json({ results });
|
|
9127
9291
|
} catch (err) {
|
|
9128
9292
|
const message = err instanceof Error ? err.message : "Internal server error";
|
|
9293
|
+
reportTelemetry(req, plugin, "DOCUMENT_INGESTION", "error", message);
|
|
9129
9294
|
return NextResponse.json({ error: message }, { status: 500 });
|
|
9130
9295
|
}
|
|
9131
9296
|
};
|
|
@@ -9224,9 +9389,11 @@ function createUploadHandler(configOrPlugin, options) {
|
|
|
9224
9389
|
}
|
|
9225
9390
|
}
|
|
9226
9391
|
const results = await plugin.ingest(documents, namespace);
|
|
9392
|
+
reportTelemetry(req, plugin, "DOCUMENT_INGESTION", "success", `Uploaded & ingested ${files.length} file(s)`);
|
|
9227
9393
|
return NextResponse.json({ message: "Upload successful", results });
|
|
9228
9394
|
} catch (err) {
|
|
9229
9395
|
const message = err instanceof Error ? err.message : "Upload failed";
|
|
9396
|
+
reportTelemetry(req, plugin, "DOCUMENT_INGESTION", "error", message);
|
|
9230
9397
|
return NextResponse.json({ error: message }, { status: 500 });
|
|
9231
9398
|
}
|
|
9232
9399
|
};
|
|
@@ -9234,19 +9401,30 @@ function createUploadHandler(configOrPlugin, options) {
|
|
|
9234
9401
|
function createSuggestionsHandler(configOrPlugin, options) {
|
|
9235
9402
|
const plugin = getOrCreatePlugin(configOrPlugin);
|
|
9236
9403
|
const onAuthorize = options == null ? void 0 : options.onAuthorize;
|
|
9237
|
-
return async function
|
|
9404
|
+
return async function handler(req) {
|
|
9238
9405
|
const authResult = await checkAuth(req, onAuthorize);
|
|
9239
9406
|
if (authResult) return authResult;
|
|
9240
9407
|
try {
|
|
9241
|
-
|
|
9242
|
-
|
|
9408
|
+
let query = "";
|
|
9409
|
+
let namespace = void 0;
|
|
9410
|
+
if (req.method === "POST") {
|
|
9411
|
+
const body = await req.json().catch(() => ({}));
|
|
9412
|
+
query = body.query || "";
|
|
9413
|
+
namespace = body.namespace;
|
|
9414
|
+
} else {
|
|
9415
|
+
const url = new URL(req.url);
|
|
9416
|
+
query = url.searchParams.get("query") || "";
|
|
9417
|
+
namespace = url.searchParams.get("namespace") || void 0;
|
|
9418
|
+
}
|
|
9243
9419
|
if (typeof query !== "string") {
|
|
9244
9420
|
return NextResponse.json({ error: "query is required" }, { status: 400 });
|
|
9245
9421
|
}
|
|
9246
9422
|
const suggestions = await plugin.getSuggestions(query, namespace);
|
|
9423
|
+
reportTelemetry(req, plugin, "AUTO_SUGGESTIONS", "success", `Fetched ${suggestions.length} suggestions for: ${query.slice(0, 30)}`);
|
|
9247
9424
|
return NextResponse.json({ suggestions });
|
|
9248
9425
|
} catch (err) {
|
|
9249
9426
|
const message = err instanceof Error ? err.message : "Internal server error";
|
|
9427
|
+
reportTelemetry(req, plugin, "AUTO_SUGGESTIONS", "error", message);
|
|
9250
9428
|
return NextResponse.json({ error: message }, { status: 500 });
|
|
9251
9429
|
}
|
|
9252
9430
|
};
|
|
@@ -9378,6 +9556,8 @@ function createRagHandler(configOrPlugin, options) {
|
|
|
9378
9556
|
switch (segment) {
|
|
9379
9557
|
case "health":
|
|
9380
9558
|
return healthHandler(req);
|
|
9559
|
+
case "suggestions":
|
|
9560
|
+
return suggestionsHandler(req);
|
|
9381
9561
|
case "history":
|
|
9382
9562
|
return historyHandler(req);
|
|
9383
9563
|
case "feedback":
|