@retrivora-ai/rag-engine 2.3.5 → 2.3.6
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/{BatchProcessor-CQDtlggz.d.ts → BatchProcessor-ByBl-1MA.d.ts} +81 -3
- package/dist/{BatchProcessor-tVzb9CdE.d.mts → BatchProcessor-Dfn23VAd.d.mts} +81 -3
- package/dist/{ILLMProvider-CcJ5N6XD.d.mts → ILLMProvider-B8TAVx3j.d.mts} +63 -1
- package/dist/{ILLMProvider-CcJ5N6XD.d.ts → ILLMProvider-B8TAVx3j.d.ts} +63 -1
- package/dist/handlers/index.d.mts +2 -2
- package/dist/handlers/index.d.ts +2 -2
- package/dist/handlers/index.js +373 -155
- package/dist/handlers/index.mjs +373 -155
- package/dist/{index-BwmyPJHp.d.ts → index-ejOWsaqb.d.ts} +1 -1
- package/dist/{index-CL-zF6bD.d.mts → index-xxQOFx-u.d.mts} +1 -1
- package/dist/index.css +9 -0
- package/dist/index.d.mts +19 -5
- package/dist/index.d.ts +19 -5
- package/dist/index.js +636 -200
- package/dist/index.mjs +676 -245
- package/dist/server.d.mts +6 -6
- package/dist/server.d.ts +6 -6
- package/dist/server.js +413 -166
- package/dist/server.mjs +409 -166
- package/package.json +1 -1
- package/src/components/ChatWidget.tsx +44 -19
- package/src/components/ChatWindow.tsx +30 -14
- package/src/components/ConfigProvider.tsx +86 -6
- package/src/components/DocumentUpload.tsx +8 -2
- package/src/config/RagConfig.ts +4 -0
- package/src/core/ConfigFetcher.ts +10 -1
- package/src/core/ConfigResolver.ts +1 -0
- package/src/core/LicenseValidator.ts +21 -12
- package/src/core/LicenseVerifier.ts +0 -4
- package/src/core/ProjectSettings.ts +247 -0
- package/src/handlers/index.ts +61 -5
- package/src/hooks/useProjectSettings.ts +105 -0
- package/src/index.css +9 -0
- package/src/index.ts +28 -0
- package/src/server.ts +23 -1
- package/src/types/props.ts +14 -2
package/dist/handlers/index.mjs
CHANGED
|
@@ -139,11 +139,326 @@ var init_BaseVectorProvider = __esm({
|
|
|
139
139
|
}
|
|
140
140
|
});
|
|
141
141
|
|
|
142
|
+
// src/core/ProjectSettings.ts
|
|
143
|
+
function createDefaultProjectSettings(projectId) {
|
|
144
|
+
return {
|
|
145
|
+
projectId,
|
|
146
|
+
branding: {
|
|
147
|
+
companyName: "Retrivora AI",
|
|
148
|
+
botName: "Retrivora Assistant",
|
|
149
|
+
welcomeMessage: "Hi, I can help you search your knowledge base.",
|
|
150
|
+
primaryColor: "#6366f1",
|
|
151
|
+
secondaryColor: "#8b5cf6",
|
|
152
|
+
fontFamily: "Inter",
|
|
153
|
+
borderRadius: 14,
|
|
154
|
+
logoUrl: "",
|
|
155
|
+
avatarUrl: "",
|
|
156
|
+
customCss: ""
|
|
157
|
+
},
|
|
158
|
+
ai: {
|
|
159
|
+
defaultModel: "llama-3.1-8b-instant",
|
|
160
|
+
embeddingModel: "text-embedding-3-small",
|
|
161
|
+
systemPrompt: "Answer using the connected knowledge base. Cite sources when available.",
|
|
162
|
+
memoryEnabled: true,
|
|
163
|
+
multiModelEnabled: true,
|
|
164
|
+
citationsEnabled: true,
|
|
165
|
+
fileUploadEnabled: true
|
|
166
|
+
},
|
|
167
|
+
auth: {
|
|
168
|
+
mode: "public",
|
|
169
|
+
allowedOrigins: [],
|
|
170
|
+
requireVerifiedEmail: false,
|
|
171
|
+
sessionTtlMinutes: 1440
|
|
172
|
+
},
|
|
173
|
+
widget: {
|
|
174
|
+
position: "bottom-right",
|
|
175
|
+
theme: "light",
|
|
176
|
+
lazyLoad: true,
|
|
177
|
+
autoReconnect: true,
|
|
178
|
+
persistConversations: true,
|
|
179
|
+
showRetrivoraBranding: false
|
|
180
|
+
},
|
|
181
|
+
telemetry: {
|
|
182
|
+
enabled: true,
|
|
183
|
+
collectBrowser: true,
|
|
184
|
+
collectCountry: false,
|
|
185
|
+
redactPii: true,
|
|
186
|
+
retentionDays: 30
|
|
187
|
+
},
|
|
188
|
+
lifecycleHooks: DEFAULT_LIFECYCLE_HOOKS,
|
|
189
|
+
conversationFeatures: DEFAULT_CONVERSATION_FEATURES
|
|
190
|
+
};
|
|
191
|
+
}
|
|
192
|
+
function cleanString(value, fallback, maxLength = 2e3) {
|
|
193
|
+
if (typeof value !== "string") return fallback;
|
|
194
|
+
return value.trim().slice(0, maxLength);
|
|
195
|
+
}
|
|
196
|
+
function cleanBoolean(value, fallback) {
|
|
197
|
+
return typeof value === "boolean" ? value : fallback;
|
|
198
|
+
}
|
|
199
|
+
function cleanNumber(value, fallback, min, max) {
|
|
200
|
+
const num = typeof value === "number" ? value : Number(value);
|
|
201
|
+
if (!Number.isFinite(num)) return fallback;
|
|
202
|
+
return Math.min(Math.max(Math.round(num), min), max);
|
|
203
|
+
}
|
|
204
|
+
function cleanEnum(value, fallback, allowed) {
|
|
205
|
+
return typeof value === "string" && allowed.includes(value) ? value : fallback;
|
|
206
|
+
}
|
|
207
|
+
function cleanStringList(value, fallback, maxItems = 20) {
|
|
208
|
+
if (!Array.isArray(value)) return fallback;
|
|
209
|
+
const cleaned = value.filter((item) => typeof item === "string").map((item) => item.trim()).filter(Boolean).slice(0, maxItems);
|
|
210
|
+
return cleaned.length > 0 ? Array.from(new Set(cleaned)) : fallback;
|
|
211
|
+
}
|
|
212
|
+
function normalizeProjectSettings(projectId, input) {
|
|
213
|
+
const defaults = createDefaultProjectSettings(projectId);
|
|
214
|
+
const branding = (input == null ? void 0 : input.branding) || {};
|
|
215
|
+
const ai = (input == null ? void 0 : input.ai) || {};
|
|
216
|
+
const auth = (input == null ? void 0 : input.auth) || {};
|
|
217
|
+
const widget = (input == null ? void 0 : input.widget) || {};
|
|
218
|
+
const telemetry = (input == null ? void 0 : input.telemetry) || {};
|
|
219
|
+
return {
|
|
220
|
+
projectId,
|
|
221
|
+
branding: {
|
|
222
|
+
companyName: cleanString(branding.companyName, defaults.branding.companyName, 120),
|
|
223
|
+
botName: cleanString(branding.botName, defaults.branding.botName, 120),
|
|
224
|
+
welcomeMessage: cleanString(branding.welcomeMessage, defaults.branding.welcomeMessage, 500),
|
|
225
|
+
primaryColor: cleanString(branding.primaryColor, defaults.branding.primaryColor, 32),
|
|
226
|
+
secondaryColor: cleanString(branding.secondaryColor, defaults.branding.secondaryColor, 32),
|
|
227
|
+
fontFamily: cleanString(branding.fontFamily, defaults.branding.fontFamily, 80),
|
|
228
|
+
borderRadius: cleanNumber(branding.borderRadius, defaults.branding.borderRadius, 0, 32),
|
|
229
|
+
logoUrl: cleanString(branding.logoUrl, defaults.branding.logoUrl, 500),
|
|
230
|
+
avatarUrl: cleanString(branding.avatarUrl, defaults.branding.avatarUrl, 500),
|
|
231
|
+
customCss: cleanString(branding.customCss, defaults.branding.customCss, 5e3)
|
|
232
|
+
},
|
|
233
|
+
ai: {
|
|
234
|
+
defaultModel: cleanString(ai.defaultModel, defaults.ai.defaultModel, 120),
|
|
235
|
+
embeddingModel: cleanString(ai.embeddingModel, defaults.ai.embeddingModel, 120),
|
|
236
|
+
systemPrompt: cleanString(ai.systemPrompt, defaults.ai.systemPrompt, 5e3),
|
|
237
|
+
memoryEnabled: cleanBoolean(ai.memoryEnabled, defaults.ai.memoryEnabled),
|
|
238
|
+
multiModelEnabled: cleanBoolean(ai.multiModelEnabled, defaults.ai.multiModelEnabled),
|
|
239
|
+
citationsEnabled: cleanBoolean(ai.citationsEnabled, defaults.ai.citationsEnabled),
|
|
240
|
+
fileUploadEnabled: cleanBoolean(ai.fileUploadEnabled, defaults.ai.fileUploadEnabled)
|
|
241
|
+
},
|
|
242
|
+
auth: {
|
|
243
|
+
mode: cleanEnum(auth.mode, defaults.auth.mode, ["public", "anonymous", "jwt", "oauth", "okta", "auth0", "supabase", "firebase", "sso", "custom_token"]),
|
|
244
|
+
allowedOrigins: cleanStringList(auth.allowedOrigins, defaults.auth.allowedOrigins, 25),
|
|
245
|
+
requireVerifiedEmail: cleanBoolean(auth.requireVerifiedEmail, defaults.auth.requireVerifiedEmail),
|
|
246
|
+
sessionTtlMinutes: cleanNumber(auth.sessionTtlMinutes, defaults.auth.sessionTtlMinutes, 15, 43200)
|
|
247
|
+
},
|
|
248
|
+
widget: {
|
|
249
|
+
position: cleanEnum(widget.position, defaults.widget.position, ["bottom-right", "bottom-left", "top-right", "top-left"]),
|
|
250
|
+
theme: cleanEnum(widget.theme, defaults.widget.theme, ["light", "dark", "system"]),
|
|
251
|
+
lazyLoad: cleanBoolean(widget.lazyLoad, defaults.widget.lazyLoad),
|
|
252
|
+
autoReconnect: cleanBoolean(widget.autoReconnect, defaults.widget.autoReconnect),
|
|
253
|
+
persistConversations: cleanBoolean(widget.persistConversations, defaults.widget.persistConversations),
|
|
254
|
+
showRetrivoraBranding: cleanBoolean(widget.showRetrivoraBranding, defaults.widget.showRetrivoraBranding)
|
|
255
|
+
},
|
|
256
|
+
telemetry: {
|
|
257
|
+
enabled: cleanBoolean(telemetry.enabled, defaults.telemetry.enabled),
|
|
258
|
+
collectBrowser: cleanBoolean(telemetry.collectBrowser, defaults.telemetry.collectBrowser),
|
|
259
|
+
collectCountry: cleanBoolean(telemetry.collectCountry, defaults.telemetry.collectCountry),
|
|
260
|
+
redactPii: cleanBoolean(telemetry.redactPii, defaults.telemetry.redactPii),
|
|
261
|
+
retentionDays: cleanNumber(telemetry.retentionDays, defaults.telemetry.retentionDays, 1, 365)
|
|
262
|
+
},
|
|
263
|
+
lifecycleHooks: cleanStringList(input == null ? void 0 : input.lifecycleHooks, defaults.lifecycleHooks, 30),
|
|
264
|
+
conversationFeatures: cleanStringList(input == null ? void 0 : input.conversationFeatures, defaults.conversationFeatures, 30),
|
|
265
|
+
updatedAt: input == null ? void 0 : input.updatedAt
|
|
266
|
+
};
|
|
267
|
+
}
|
|
268
|
+
var DEFAULT_LIFECYCLE_HOOKS, DEFAULT_CONVERSATION_FEATURES;
|
|
269
|
+
var init_ProjectSettings = __esm({
|
|
270
|
+
"src/core/ProjectSettings.ts"() {
|
|
271
|
+
"use strict";
|
|
272
|
+
DEFAULT_LIFECYCLE_HOOKS = [
|
|
273
|
+
"beforeInitialize",
|
|
274
|
+
"afterInitialize",
|
|
275
|
+
"beforeSend",
|
|
276
|
+
"afterResponse",
|
|
277
|
+
"onMessage",
|
|
278
|
+
"onCitationClick",
|
|
279
|
+
"onFeedback",
|
|
280
|
+
"onError",
|
|
281
|
+
"onReconnect",
|
|
282
|
+
"onFileUpload"
|
|
283
|
+
];
|
|
284
|
+
DEFAULT_CONVERSATION_FEATURES = [
|
|
285
|
+
"History",
|
|
286
|
+
"Resume",
|
|
287
|
+
"Search",
|
|
288
|
+
"Export",
|
|
289
|
+
"Rename",
|
|
290
|
+
"Delete",
|
|
291
|
+
"Tags",
|
|
292
|
+
"Pinned",
|
|
293
|
+
"Unread",
|
|
294
|
+
"Ratings"
|
|
295
|
+
];
|
|
296
|
+
}
|
|
297
|
+
});
|
|
298
|
+
|
|
299
|
+
// package.json
|
|
300
|
+
var package_default;
|
|
301
|
+
var init_package = __esm({
|
|
302
|
+
"package.json"() {
|
|
303
|
+
package_default = {
|
|
304
|
+
name: "@retrivora-ai/rag-engine",
|
|
305
|
+
version: "2.3.6",
|
|
306
|
+
description: "Retrivora AI is a plug-and-play AI engine for RAG chat experiences \u2014 generic vector DB + LLM provider, embeddable or standalone.",
|
|
307
|
+
author: "Abhinav Alkuchi",
|
|
308
|
+
license: "UNLICENSED",
|
|
309
|
+
keywords: [
|
|
310
|
+
"rag",
|
|
311
|
+
"retrieval-augmented-generation",
|
|
312
|
+
"chatbot",
|
|
313
|
+
"vector-database",
|
|
314
|
+
"pinecone",
|
|
315
|
+
"pgvector",
|
|
316
|
+
"postgresql",
|
|
317
|
+
"milvus",
|
|
318
|
+
"qdrant",
|
|
319
|
+
"chromadb",
|
|
320
|
+
"redis",
|
|
321
|
+
"weaviate",
|
|
322
|
+
"mongodb",
|
|
323
|
+
"openai",
|
|
324
|
+
"anthropic",
|
|
325
|
+
"ollama",
|
|
326
|
+
"nextjs",
|
|
327
|
+
"react",
|
|
328
|
+
"ai",
|
|
329
|
+
"llm",
|
|
330
|
+
"embeddings"
|
|
331
|
+
],
|
|
332
|
+
main: "dist/index.js",
|
|
333
|
+
module: "dist/index.mjs",
|
|
334
|
+
types: "dist/index.d.ts",
|
|
335
|
+
exports: {
|
|
336
|
+
".": {
|
|
337
|
+
types: "./dist/index.d.ts",
|
|
338
|
+
require: "./dist/index.js",
|
|
339
|
+
import: "./dist/index.mjs"
|
|
340
|
+
},
|
|
341
|
+
"./style.css": "./dist/index.css",
|
|
342
|
+
"./index.css": "./dist/index.css",
|
|
343
|
+
"./styles.css": "./dist/index.css",
|
|
344
|
+
"./handlers": {
|
|
345
|
+
types: "./dist/handlers/index.d.ts",
|
|
346
|
+
require: "./dist/handlers/index.js",
|
|
347
|
+
import: "./dist/handlers/index.mjs"
|
|
348
|
+
},
|
|
349
|
+
"./server": {
|
|
350
|
+
types: "./dist/server.d.ts",
|
|
351
|
+
require: "./dist/server.js",
|
|
352
|
+
import: "./dist/server.mjs"
|
|
353
|
+
}
|
|
354
|
+
},
|
|
355
|
+
browser: {
|
|
356
|
+
child_process: false,
|
|
357
|
+
fs: false,
|
|
358
|
+
net: false,
|
|
359
|
+
tls: false,
|
|
360
|
+
crypto: false,
|
|
361
|
+
os: false,
|
|
362
|
+
path: false,
|
|
363
|
+
stream: false,
|
|
364
|
+
http: false,
|
|
365
|
+
https: false,
|
|
366
|
+
zlib: false,
|
|
367
|
+
mongodb: false,
|
|
368
|
+
pg: false,
|
|
369
|
+
"pdf-parse": false,
|
|
370
|
+
mammoth: false
|
|
371
|
+
},
|
|
372
|
+
files: [
|
|
373
|
+
"dist",
|
|
374
|
+
"src",
|
|
375
|
+
".env.example",
|
|
376
|
+
"README.md",
|
|
377
|
+
"FREE_TIER_ARCHITECTURE.md"
|
|
378
|
+
],
|
|
379
|
+
scripts: {
|
|
380
|
+
dev: "npx @tailwindcss/cli -i src/tailwind.css -o src/index.css && tsup src/index.ts src/handlers/index.ts src/server.ts --format cjs,esm --watch --tsconfig tsconfig.build.json --external react,react-dom,next,mongodb,pg,openai,@anthropic-ai/sdk,@pinecone-database/pinecone,axios,lucide-react,mammoth,pdf-parse,xlsx,react-markdown,remark-gfm,next-themes,langchain,@langchain/core,@langchain/openai,llamaindex --inject-style",
|
|
381
|
+
build: "npm run build:pkg",
|
|
382
|
+
"build:pkg": "npx @tailwindcss/cli -i src/tailwind.css -o src/index.css && tsup src/index.ts src/handlers/index.ts src/server.ts --format cjs,esm --dts --clean --no-splitting --tsconfig tsconfig.build.json --external react,react-dom,next,mongodb,pg,openai,@anthropic-ai/sdk,@pinecone-database/pinecone,axios,lucide-react,mammoth,pdf-parse,xlsx,react-markdown,remark-gfm,next-themes,langchain,@langchain/core,@langchain/openai,llamaindex --inject-style && npx @tailwindcss/cli -i src/tailwind.css -o dist/index.css",
|
|
383
|
+
lint: "eslint",
|
|
384
|
+
typecheck: "tsc --noEmit -p tsconfig.build.json",
|
|
385
|
+
clean: "rm -rf dist"
|
|
386
|
+
},
|
|
387
|
+
peerDependencies: {
|
|
388
|
+
next: ">=15.0.0",
|
|
389
|
+
react: ">=18.0.0",
|
|
390
|
+
"react-dom": ">=18.0.0"
|
|
391
|
+
},
|
|
392
|
+
peerDependenciesMeta: {
|
|
393
|
+
next: {
|
|
394
|
+
optional: true
|
|
395
|
+
}
|
|
396
|
+
},
|
|
397
|
+
dependencies: {
|
|
398
|
+
"@anthropic-ai/sdk": "^0.95.1",
|
|
399
|
+
"@google/genai": "^0.8.0",
|
|
400
|
+
"@google/generative-ai": "^0.24.1",
|
|
401
|
+
"@pinecone-database/pinecone": "^7.2.0",
|
|
402
|
+
"@types/papaparse": "^5.5.2",
|
|
403
|
+
axios: "^1.15.0",
|
|
404
|
+
"lucide-react": "^1.8.0",
|
|
405
|
+
"next-themes": "^0.4.6",
|
|
406
|
+
openai: "^6.34.0",
|
|
407
|
+
papaparse: "^5.5.3",
|
|
408
|
+
"react-is": "^18.3.1",
|
|
409
|
+
"react-markdown": "^10.1.0",
|
|
410
|
+
recharts: "^3.8.1",
|
|
411
|
+
"remark-gfm": "^4.0.1",
|
|
412
|
+
xlsx: "^0.18.5"
|
|
413
|
+
},
|
|
414
|
+
optionalDependencies: {
|
|
415
|
+
"@langchain/core": "^1.1.42",
|
|
416
|
+
"@langchain/openai": "^1.4.5",
|
|
417
|
+
langchain: "^1.3.5",
|
|
418
|
+
llamaindex: "^0.11.9",
|
|
419
|
+
mammoth: "^1.8.0",
|
|
420
|
+
mongodb: "^7.1.1",
|
|
421
|
+
"pdf-parse": "^1.1.1",
|
|
422
|
+
pg: "^8.20.0"
|
|
423
|
+
},
|
|
424
|
+
devDependencies: {
|
|
425
|
+
"@tailwindcss/cli": "^4",
|
|
426
|
+
"@tailwindcss/postcss": "^4",
|
|
427
|
+
"@types/estree": "^1.0.9",
|
|
428
|
+
"@types/node": "^20",
|
|
429
|
+
"@types/pdf-parse": "^1.1.5",
|
|
430
|
+
"@types/pg": "^8.20.0",
|
|
431
|
+
"@types/react": "^19.2.14",
|
|
432
|
+
"@types/react-dom": "^19.2.3",
|
|
433
|
+
dotenv: "^17.4.2",
|
|
434
|
+
eslint: "^9",
|
|
435
|
+
"eslint-config-next": "16.2.4",
|
|
436
|
+
next: "16.2.10",
|
|
437
|
+
tailwindcss: "^4",
|
|
438
|
+
tsup: "^8.5.1",
|
|
439
|
+
typescript: "^5"
|
|
440
|
+
}
|
|
441
|
+
};
|
|
442
|
+
}
|
|
443
|
+
});
|
|
444
|
+
|
|
445
|
+
// src/version.ts
|
|
446
|
+
var SDK_VERSION;
|
|
447
|
+
var init_version = __esm({
|
|
448
|
+
"src/version.ts"() {
|
|
449
|
+
"use strict";
|
|
450
|
+
init_package();
|
|
451
|
+
SDK_VERSION = package_default.version || "2.1.3";
|
|
452
|
+
}
|
|
453
|
+
});
|
|
454
|
+
|
|
142
455
|
// src/core/ConfigFetcher.ts
|
|
143
456
|
var CONTROL_PLANE_URL, LLM_PROXY_BASE_URL, ConfigFetcher;
|
|
144
457
|
var init_ConfigFetcher = __esm({
|
|
145
458
|
"src/core/ConfigFetcher.ts"() {
|
|
146
459
|
"use strict";
|
|
460
|
+
init_ProjectSettings();
|
|
461
|
+
init_version();
|
|
147
462
|
CONTROL_PLANE_URL = "https://www.retrivora.com";
|
|
148
463
|
LLM_PROXY_BASE_URL = "https://www.retrivora.com/api/v1";
|
|
149
464
|
ConfigFetcher = class {
|
|
@@ -176,11 +491,12 @@ var init_ConfigFetcher = __esm({
|
|
|
176
491
|
].filter((url) => Boolean(url) && !url.includes("localhost") && !url.includes("127.0.0.1")).map((url) => url.replace(/\/$/, ""));
|
|
177
492
|
for (const baseUrl of controlPlaneUrls) {
|
|
178
493
|
try {
|
|
179
|
-
const url = `${baseUrl}/api/v1/config?projectId=${encodeURIComponent(projectId)}
|
|
494
|
+
const url = `${baseUrl}/api/v1/config?projectId=${encodeURIComponent(projectId)}`;
|
|
180
495
|
const res = await fetch(url, {
|
|
181
496
|
method: "GET",
|
|
182
497
|
headers: __spreadValues({
|
|
183
|
-
"Content-Type": "application/json"
|
|
498
|
+
"Content-Type": "application/json",
|
|
499
|
+
"x-sdk-version": SDK_VERSION
|
|
184
500
|
}, licenseKey ? { "x-license-key": licenseKey } : {})
|
|
185
501
|
});
|
|
186
502
|
if (res.ok) {
|
|
@@ -220,7 +536,11 @@ var init_ConfigFetcher = __esm({
|
|
|
220
536
|
workspace: data.workspace || {
|
|
221
537
|
namespace: fetchedProjectId,
|
|
222
538
|
indexName: data.vectorDb.indexName || "retrivora-free"
|
|
223
|
-
}
|
|
539
|
+
},
|
|
540
|
+
projectSettings: normalizeProjectSettings(
|
|
541
|
+
fetchedProjectId,
|
|
542
|
+
data.projectSettings || data.settings
|
|
543
|
+
)
|
|
224
544
|
};
|
|
225
545
|
this.cache.set(cacheKey, { config, cachedAt: now });
|
|
226
546
|
return config;
|
|
@@ -2306,10 +2626,6 @@ var LicenseVerifier = class {
|
|
|
2306
2626
|
static verify(licenseKey, currentProjectId, provider, publicKeyOverride) {
|
|
2307
2627
|
const isProduction = process.env.NODE_ENV === "production";
|
|
2308
2628
|
const now = Date.now();
|
|
2309
|
-
console.log(`[Retrivora SDK] LicenseVerifier.verify() - licenseKey`, licenseKey);
|
|
2310
|
-
console.log(`[Retrivora SDK] LicenseVerifier.verify() - currentProjectId`, currentProjectId);
|
|
2311
|
-
console.log(`[Retrivora SDK] LicenseVerifier.verify() - provider`, provider);
|
|
2312
|
-
console.log(`[Retrivora SDK] LicenseVerifier.verify() - publicKeyOverride`, publicKeyOverride);
|
|
2313
2629
|
if (licenseKey) {
|
|
2314
2630
|
const cacheKey = `${licenseKey}:${currentProjectId}:${provider || ""}:${publicKeyOverride || ""}`;
|
|
2315
2631
|
const cached = this.cache.get(cacheKey);
|
|
@@ -2800,6 +3116,7 @@ var ConfigResolver = class {
|
|
|
2800
3116
|
options: __spreadValues(__spreadValues({}, envConfig.embedding.options || {}), hostConfig.embedding.options || {})
|
|
2801
3117
|
}) : envConfig.embedding,
|
|
2802
3118
|
ui: hostConfig.ui ? mergeDefined(envConfig.ui, hostConfig.ui) : envConfig.ui,
|
|
3119
|
+
projectSettings: hostConfig.projectSettings || envConfig.projectSettings,
|
|
2803
3120
|
rag: hostConfig.rag ? __spreadValues(__spreadValues({}, envConfig.rag), hostConfig.rag) : envConfig.rag,
|
|
2804
3121
|
telemetry: hostConfig.telemetry ? __spreadValues(__spreadValues({}, envConfig.telemetry), hostConfig.telemetry) : envConfig.telemetry
|
|
2805
3122
|
});
|
|
@@ -4702,149 +5019,8 @@ var ConfigValidator = class {
|
|
|
4702
5019
|
}
|
|
4703
5020
|
};
|
|
4704
5021
|
|
|
4705
|
-
//
|
|
4706
|
-
|
|
4707
|
-
name: "@retrivora-ai/rag-engine",
|
|
4708
|
-
version: "2.3.5",
|
|
4709
|
-
description: "Retrivora AI is a plug-and-play AI engine for RAG chat experiences \u2014 generic vector DB + LLM provider, embeddable or standalone.",
|
|
4710
|
-
author: "Abhinav Alkuchi",
|
|
4711
|
-
license: "UNLICENSED",
|
|
4712
|
-
keywords: [
|
|
4713
|
-
"rag",
|
|
4714
|
-
"retrieval-augmented-generation",
|
|
4715
|
-
"chatbot",
|
|
4716
|
-
"vector-database",
|
|
4717
|
-
"pinecone",
|
|
4718
|
-
"pgvector",
|
|
4719
|
-
"postgresql",
|
|
4720
|
-
"milvus",
|
|
4721
|
-
"qdrant",
|
|
4722
|
-
"chromadb",
|
|
4723
|
-
"redis",
|
|
4724
|
-
"weaviate",
|
|
4725
|
-
"mongodb",
|
|
4726
|
-
"openai",
|
|
4727
|
-
"anthropic",
|
|
4728
|
-
"ollama",
|
|
4729
|
-
"nextjs",
|
|
4730
|
-
"react",
|
|
4731
|
-
"ai",
|
|
4732
|
-
"llm",
|
|
4733
|
-
"embeddings"
|
|
4734
|
-
],
|
|
4735
|
-
main: "dist/index.js",
|
|
4736
|
-
module: "dist/index.mjs",
|
|
4737
|
-
types: "dist/index.d.ts",
|
|
4738
|
-
exports: {
|
|
4739
|
-
".": {
|
|
4740
|
-
types: "./dist/index.d.ts",
|
|
4741
|
-
require: "./dist/index.js",
|
|
4742
|
-
import: "./dist/index.mjs"
|
|
4743
|
-
},
|
|
4744
|
-
"./style.css": "./dist/index.css",
|
|
4745
|
-
"./index.css": "./dist/index.css",
|
|
4746
|
-
"./styles.css": "./dist/index.css",
|
|
4747
|
-
"./handlers": {
|
|
4748
|
-
types: "./dist/handlers/index.d.ts",
|
|
4749
|
-
require: "./dist/handlers/index.js",
|
|
4750
|
-
import: "./dist/handlers/index.mjs"
|
|
4751
|
-
},
|
|
4752
|
-
"./server": {
|
|
4753
|
-
types: "./dist/server.d.ts",
|
|
4754
|
-
require: "./dist/server.js",
|
|
4755
|
-
import: "./dist/server.mjs"
|
|
4756
|
-
}
|
|
4757
|
-
},
|
|
4758
|
-
browser: {
|
|
4759
|
-
child_process: false,
|
|
4760
|
-
fs: false,
|
|
4761
|
-
net: false,
|
|
4762
|
-
tls: false,
|
|
4763
|
-
crypto: false,
|
|
4764
|
-
os: false,
|
|
4765
|
-
path: false,
|
|
4766
|
-
stream: false,
|
|
4767
|
-
http: false,
|
|
4768
|
-
https: false,
|
|
4769
|
-
zlib: false,
|
|
4770
|
-
mongodb: false,
|
|
4771
|
-
pg: false,
|
|
4772
|
-
"pdf-parse": false,
|
|
4773
|
-
mammoth: false
|
|
4774
|
-
},
|
|
4775
|
-
files: [
|
|
4776
|
-
"dist",
|
|
4777
|
-
"src",
|
|
4778
|
-
".env.example",
|
|
4779
|
-
"README.md",
|
|
4780
|
-
"FREE_TIER_ARCHITECTURE.md"
|
|
4781
|
-
],
|
|
4782
|
-
scripts: {
|
|
4783
|
-
dev: "npx @tailwindcss/cli -i src/tailwind.css -o src/index.css && tsup src/index.ts src/handlers/index.ts src/server.ts --format cjs,esm --watch --tsconfig tsconfig.build.json --external react,react-dom,next,mongodb,pg,openai,@anthropic-ai/sdk,@pinecone-database/pinecone,axios,lucide-react,mammoth,pdf-parse,xlsx,react-markdown,remark-gfm,next-themes,langchain,@langchain/core,@langchain/openai,llamaindex --inject-style",
|
|
4784
|
-
build: "npm run build:pkg",
|
|
4785
|
-
"build:pkg": "npx @tailwindcss/cli -i src/tailwind.css -o src/index.css && tsup src/index.ts src/handlers/index.ts src/server.ts --format cjs,esm --dts --clean --no-splitting --tsconfig tsconfig.build.json --external react,react-dom,next,mongodb,pg,openai,@anthropic-ai/sdk,@pinecone-database/pinecone,axios,lucide-react,mammoth,pdf-parse,xlsx,react-markdown,remark-gfm,next-themes,langchain,@langchain/core,@langchain/openai,llamaindex --inject-style && npx @tailwindcss/cli -i src/tailwind.css -o dist/index.css",
|
|
4786
|
-
lint: "eslint",
|
|
4787
|
-
typecheck: "tsc --noEmit -p tsconfig.build.json",
|
|
4788
|
-
clean: "rm -rf dist"
|
|
4789
|
-
},
|
|
4790
|
-
peerDependencies: {
|
|
4791
|
-
next: ">=15.0.0",
|
|
4792
|
-
react: ">=18.0.0",
|
|
4793
|
-
"react-dom": ">=18.0.0"
|
|
4794
|
-
},
|
|
4795
|
-
peerDependenciesMeta: {
|
|
4796
|
-
next: {
|
|
4797
|
-
optional: true
|
|
4798
|
-
}
|
|
4799
|
-
},
|
|
4800
|
-
dependencies: {
|
|
4801
|
-
"@anthropic-ai/sdk": "^0.95.1",
|
|
4802
|
-
"@google/genai": "^0.8.0",
|
|
4803
|
-
"@google/generative-ai": "^0.24.1",
|
|
4804
|
-
"@pinecone-database/pinecone": "^7.2.0",
|
|
4805
|
-
"@types/papaparse": "^5.5.2",
|
|
4806
|
-
axios: "^1.15.0",
|
|
4807
|
-
"lucide-react": "^1.8.0",
|
|
4808
|
-
"next-themes": "^0.4.6",
|
|
4809
|
-
openai: "^6.34.0",
|
|
4810
|
-
papaparse: "^5.5.3",
|
|
4811
|
-
"react-is": "^18.3.1",
|
|
4812
|
-
"react-markdown": "^10.1.0",
|
|
4813
|
-
recharts: "^3.8.1",
|
|
4814
|
-
"remark-gfm": "^4.0.1",
|
|
4815
|
-
xlsx: "^0.18.5"
|
|
4816
|
-
},
|
|
4817
|
-
optionalDependencies: {
|
|
4818
|
-
"@langchain/core": "^1.1.42",
|
|
4819
|
-
"@langchain/openai": "^1.4.5",
|
|
4820
|
-
langchain: "^1.3.5",
|
|
4821
|
-
llamaindex: "^0.11.9",
|
|
4822
|
-
mammoth: "^1.8.0",
|
|
4823
|
-
mongodb: "^7.1.1",
|
|
4824
|
-
"pdf-parse": "^1.1.1",
|
|
4825
|
-
pg: "^8.20.0"
|
|
4826
|
-
},
|
|
4827
|
-
devDependencies: {
|
|
4828
|
-
"@tailwindcss/cli": "^4",
|
|
4829
|
-
"@tailwindcss/postcss": "^4",
|
|
4830
|
-
"@types/estree": "^1.0.9",
|
|
4831
|
-
"@types/node": "^20",
|
|
4832
|
-
"@types/pdf-parse": "^1.1.5",
|
|
4833
|
-
"@types/pg": "^8.20.0",
|
|
4834
|
-
"@types/react": "^19.2.14",
|
|
4835
|
-
"@types/react-dom": "^19.2.3",
|
|
4836
|
-
dotenv: "^17.4.2",
|
|
4837
|
-
eslint: "^9",
|
|
4838
|
-
"eslint-config-next": "16.2.4",
|
|
4839
|
-
next: "16.2.10",
|
|
4840
|
-
tailwindcss: "^4",
|
|
4841
|
-
tsup: "^8.5.1",
|
|
4842
|
-
typescript: "^5"
|
|
4843
|
-
}
|
|
4844
|
-
};
|
|
4845
|
-
|
|
4846
|
-
// src/version.ts
|
|
4847
|
-
var SDK_VERSION = package_default.version || "2.1.3";
|
|
5022
|
+
// src/core/Pipeline.ts
|
|
5023
|
+
init_version();
|
|
4848
5024
|
|
|
4849
5025
|
// src/rag/DocumentChunker.ts
|
|
4850
5026
|
var DocumentChunker = class {
|
|
@@ -10513,6 +10689,7 @@ var DatabaseStorage = class {
|
|
|
10513
10689
|
};
|
|
10514
10690
|
|
|
10515
10691
|
// src/handlers/index.ts
|
|
10692
|
+
init_version();
|
|
10516
10693
|
async function checkAuth(req, onAuthorize) {
|
|
10517
10694
|
if (!onAuthorize) return null;
|
|
10518
10695
|
try {
|
|
@@ -10644,6 +10821,35 @@ function enforceLicense(req, config, bodyLicenseKey) {
|
|
|
10644
10821
|
};
|
|
10645
10822
|
}
|
|
10646
10823
|
}
|
|
10824
|
+
function getAllowedNamespaces(projectId) {
|
|
10825
|
+
const trimmed = projectId.trim();
|
|
10826
|
+
const withoutPrefix = trimmed.startsWith("retrivora-") ? trimmed.replace(/^retrivora-/, "") : trimmed;
|
|
10827
|
+
return new Set([
|
|
10828
|
+
trimmed,
|
|
10829
|
+
withoutPrefix,
|
|
10830
|
+
`retrivora-${withoutPrefix}`
|
|
10831
|
+
].filter(Boolean));
|
|
10832
|
+
}
|
|
10833
|
+
function resolveLicensedNamespace(payload, requestedNamespace) {
|
|
10834
|
+
const allowed = getAllowedNamespaces(payload.projectId);
|
|
10835
|
+
const requested = requestedNamespace == null ? void 0 : requestedNamespace.trim();
|
|
10836
|
+
if (requested && !allowed.has(requested)) {
|
|
10837
|
+
return {
|
|
10838
|
+
ok: false,
|
|
10839
|
+
response: new Response(JSON.stringify({
|
|
10840
|
+
error: {
|
|
10841
|
+
code: "NAMESPACE_FORBIDDEN",
|
|
10842
|
+
message: "Requested namespace is not authorized for this license."
|
|
10843
|
+
}
|
|
10844
|
+
}), {
|
|
10845
|
+
status: 403,
|
|
10846
|
+
headers: { "Content-Type": "application/json" }
|
|
10847
|
+
})
|
|
10848
|
+
};
|
|
10849
|
+
}
|
|
10850
|
+
const defaultNamespace = payload.projectId.startsWith("retrivora-") ? payload.projectId : `retrivora-${payload.projectId}`;
|
|
10851
|
+
return { ok: true, namespace: requested || defaultNamespace };
|
|
10852
|
+
}
|
|
10647
10853
|
var MAX_MESSAGE_LENGTH = 8e3;
|
|
10648
10854
|
function sanitizeInput(raw) {
|
|
10649
10855
|
const stripped = raw.replace(/[\u0000-\u0008\u000B\u000C\u000E-\u001F\u007F-\u009F]/g, "");
|
|
@@ -10804,6 +11010,8 @@ function createChatHandler(configOrPlugin, options) {
|
|
|
10804
11010
|
}
|
|
10805
11011
|
const history = bodyObj.history || (Array.isArray(bodyObj.messages) ? bodyObj.messages.slice(0, -1) : []);
|
|
10806
11012
|
const { namespace, sessionId = "default", messageId, userMessageId } = bodyObj;
|
|
11013
|
+
const namespaceCheck = resolveLicensedNamespace(licenseCheck.payload, namespace);
|
|
11014
|
+
if (!namespaceCheck.ok) return namespaceCheck.response;
|
|
10807
11015
|
const sanitized = sanitizeInput(rawMessage != null ? rawMessage : "");
|
|
10808
11016
|
if (!sanitized.ok) {
|
|
10809
11017
|
return NextResponse.json({ error: { code: "INVALID_INPUT", message: sanitized.error } }, { status: 400 });
|
|
@@ -10815,7 +11023,7 @@ function createChatHandler(configOrPlugin, options) {
|
|
|
10815
11023
|
role: "user",
|
|
10816
11024
|
content: message
|
|
10817
11025
|
}).catch((err) => console.warn("[createChatHandler] Failed to save user message:", err));
|
|
10818
|
-
const result = await plugin.chat(message, history, namespace);
|
|
11026
|
+
const result = await plugin.chat(message, history, namespaceCheck.namespace);
|
|
10819
11027
|
const assistantMsgId = messageId || `assistant_${Date.now()}_${Math.random().toString(36).slice(2, 6)}`;
|
|
10820
11028
|
await storage.saveMessage(sessionId, {
|
|
10821
11029
|
id: assistantMsgId,
|
|
@@ -10896,6 +11104,8 @@ function createStreamHandler(configOrPlugin, options) {
|
|
|
10896
11104
|
}
|
|
10897
11105
|
const history = bodyObj.history || (Array.isArray(bodyObj.messages) ? bodyObj.messages.slice(0, -1) : []);
|
|
10898
11106
|
const { namespace, sessionId = "default", messageId, userMessageId } = bodyObj;
|
|
11107
|
+
const namespaceCheck = resolveLicensedNamespace(licenseCheck.payload, namespace);
|
|
11108
|
+
if (!namespaceCheck.ok) return namespaceCheck.response;
|
|
10899
11109
|
const sanitized = sanitizeInput(rawMessage != null ? rawMessage : "");
|
|
10900
11110
|
if (!sanitized.ok) {
|
|
10901
11111
|
return new Response(
|
|
@@ -10925,7 +11135,7 @@ function createStreamHandler(configOrPlugin, options) {
|
|
|
10925
11135
|
}
|
|
10926
11136
|
};
|
|
10927
11137
|
try {
|
|
10928
|
-
const pipelineStream = plugin.chatStream(message, history, namespace);
|
|
11138
|
+
const pipelineStream = plugin.chatStream(message, history, namespaceCheck.namespace);
|
|
10929
11139
|
let fullReply = "";
|
|
10930
11140
|
try {
|
|
10931
11141
|
for (var iter = __forAwait(pipelineStream), more, temp, error; more = !(temp = await iter.next()).done; more = false) {
|
|
@@ -11031,6 +11241,8 @@ function createIngestHandler(configOrPlugin, options) {
|
|
|
11031
11241
|
if (!Array.isArray(documents) || documents.length === 0) {
|
|
11032
11242
|
return NextResponse.json({ error: "documents array is required" }, { status: 400 });
|
|
11033
11243
|
}
|
|
11244
|
+
const namespaceCheck = resolveLicensedNamespace(licenseCheck.payload, namespace);
|
|
11245
|
+
if (!namespaceCheck.ok) return namespaceCheck.response;
|
|
11034
11246
|
if (isFreeTier(licenseCheck.payload.tier)) {
|
|
11035
11247
|
const totalIncomingBytes = documents.reduce(
|
|
11036
11248
|
(sum, d) => sum + Buffer.byteLength(d.content || "", "utf8"),
|
|
@@ -11052,7 +11264,7 @@ function createIngestHandler(configOrPlugin, options) {
|
|
|
11052
11264
|
);
|
|
11053
11265
|
}
|
|
11054
11266
|
}
|
|
11055
|
-
const results = await plugin.ingest(documents, namespace);
|
|
11267
|
+
const results = await plugin.ingest(documents, namespaceCheck.namespace);
|
|
11056
11268
|
reportTelemetry(req, plugin, "DOCUMENT_INGESTION", "success", `Ingested ${documents.length} document(s)`);
|
|
11057
11269
|
return NextResponse.json({ results });
|
|
11058
11270
|
} catch (err) {
|
|
@@ -11140,6 +11352,8 @@ function createUploadHandler(configOrPlugin, options) {
|
|
|
11140
11352
|
const namespace = formData.get("namespace") || void 0;
|
|
11141
11353
|
const dimensionRaw = formData.get("dimension");
|
|
11142
11354
|
const dimension = dimensionRaw ? parseInt(dimensionRaw, 10) : void 0;
|
|
11355
|
+
const namespaceCheck = resolveLicensedNamespace(licenseCheck.payload, namespace);
|
|
11356
|
+
if (!namespaceCheck.ok) return namespaceCheck.response;
|
|
11143
11357
|
if (!files || files.length === 0) {
|
|
11144
11358
|
return NextResponse.json({ error: "No files provided" }, { status: 400 });
|
|
11145
11359
|
}
|
|
@@ -11256,7 +11470,7 @@ function createUploadHandler(configOrPlugin, options) {
|
|
|
11256
11470
|
});
|
|
11257
11471
|
}
|
|
11258
11472
|
}
|
|
11259
|
-
const results = await plugin.ingest(documents, namespace);
|
|
11473
|
+
const results = await plugin.ingest(documents, namespaceCheck.namespace);
|
|
11260
11474
|
reportTelemetry(req, plugin, "DOCUMENT_INGESTION", "success", `Uploaded & ingested ${files.length} file(s)`);
|
|
11261
11475
|
return NextResponse.json({ message: "Upload successful", results });
|
|
11262
11476
|
} catch (err) {
|
|
@@ -11275,6 +11489,7 @@ function createSuggestionsHandler(configOrPlugin, options) {
|
|
|
11275
11489
|
const config = plugin.getConfig();
|
|
11276
11490
|
const licenseCheck = enforceLicense(req, config);
|
|
11277
11491
|
if (!licenseCheck.ok) return licenseCheck.response;
|
|
11492
|
+
let effectiveLicensePayload = licenseCheck.payload;
|
|
11278
11493
|
try {
|
|
11279
11494
|
let query = "";
|
|
11280
11495
|
let namespace = void 0;
|
|
@@ -11287,6 +11502,7 @@ function createSuggestionsHandler(configOrPlugin, options) {
|
|
|
11287
11502
|
if (bodyLicenseKey) {
|
|
11288
11503
|
const recheck = enforceLicense(req, config, bodyLicenseKey);
|
|
11289
11504
|
if (!recheck.ok) return recheck.response;
|
|
11505
|
+
effectiveLicensePayload = recheck.payload;
|
|
11290
11506
|
}
|
|
11291
11507
|
} else {
|
|
11292
11508
|
const url = new URL(req.url);
|
|
@@ -11296,7 +11512,9 @@ function createSuggestionsHandler(configOrPlugin, options) {
|
|
|
11296
11512
|
if (!query || typeof query !== "string" || !query.trim()) {
|
|
11297
11513
|
return NextResponse.json({ suggestions: [] });
|
|
11298
11514
|
}
|
|
11299
|
-
const
|
|
11515
|
+
const namespaceCheck = resolveLicensedNamespace(effectiveLicensePayload, namespace);
|
|
11516
|
+
if (!namespaceCheck.ok) return namespaceCheck.response;
|
|
11517
|
+
const suggestions = await plugin.getSuggestions(query, namespaceCheck.namespace);
|
|
11300
11518
|
reportTelemetry(req, plugin, "AUTO_SUGGESTIONS", "success", `Fetched ${suggestions.length} suggestions for: ${query.slice(0, 30)}`);
|
|
11301
11519
|
return NextResponse.json({ suggestions });
|
|
11302
11520
|
} catch (err) {
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { NextRequest } from 'next/server';
|
|
2
|
-
import {
|
|
2
|
+
import { n as RagConfig, I as ILLMProvider, C as ChatMessage, c as ChatResponse, f as IngestDocument } from './ILLMProvider-B8TAVx3j.js';
|
|
3
3
|
|
|
4
4
|
interface ValidationError {
|
|
5
5
|
field: string;
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { NextRequest } from 'next/server';
|
|
2
|
-
import {
|
|
2
|
+
import { n as RagConfig, I as ILLMProvider, C as ChatMessage, c as ChatResponse, f as IngestDocument } from './ILLMProvider-B8TAVx3j.mjs';
|
|
3
3
|
|
|
4
4
|
interface ValidationError {
|
|
5
5
|
field: string;
|