@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.js
CHANGED
|
@@ -154,11 +154,326 @@ var init_BaseVectorProvider = __esm({
|
|
|
154
154
|
}
|
|
155
155
|
});
|
|
156
156
|
|
|
157
|
+
// src/core/ProjectSettings.ts
|
|
158
|
+
function createDefaultProjectSettings(projectId) {
|
|
159
|
+
return {
|
|
160
|
+
projectId,
|
|
161
|
+
branding: {
|
|
162
|
+
companyName: "Retrivora AI",
|
|
163
|
+
botName: "Retrivora Assistant",
|
|
164
|
+
welcomeMessage: "Hi, I can help you search your knowledge base.",
|
|
165
|
+
primaryColor: "#6366f1",
|
|
166
|
+
secondaryColor: "#8b5cf6",
|
|
167
|
+
fontFamily: "Inter",
|
|
168
|
+
borderRadius: 14,
|
|
169
|
+
logoUrl: "",
|
|
170
|
+
avatarUrl: "",
|
|
171
|
+
customCss: ""
|
|
172
|
+
},
|
|
173
|
+
ai: {
|
|
174
|
+
defaultModel: "llama-3.1-8b-instant",
|
|
175
|
+
embeddingModel: "text-embedding-3-small",
|
|
176
|
+
systemPrompt: "Answer using the connected knowledge base. Cite sources when available.",
|
|
177
|
+
memoryEnabled: true,
|
|
178
|
+
multiModelEnabled: true,
|
|
179
|
+
citationsEnabled: true,
|
|
180
|
+
fileUploadEnabled: true
|
|
181
|
+
},
|
|
182
|
+
auth: {
|
|
183
|
+
mode: "public",
|
|
184
|
+
allowedOrigins: [],
|
|
185
|
+
requireVerifiedEmail: false,
|
|
186
|
+
sessionTtlMinutes: 1440
|
|
187
|
+
},
|
|
188
|
+
widget: {
|
|
189
|
+
position: "bottom-right",
|
|
190
|
+
theme: "light",
|
|
191
|
+
lazyLoad: true,
|
|
192
|
+
autoReconnect: true,
|
|
193
|
+
persistConversations: true,
|
|
194
|
+
showRetrivoraBranding: false
|
|
195
|
+
},
|
|
196
|
+
telemetry: {
|
|
197
|
+
enabled: true,
|
|
198
|
+
collectBrowser: true,
|
|
199
|
+
collectCountry: false,
|
|
200
|
+
redactPii: true,
|
|
201
|
+
retentionDays: 30
|
|
202
|
+
},
|
|
203
|
+
lifecycleHooks: DEFAULT_LIFECYCLE_HOOKS,
|
|
204
|
+
conversationFeatures: DEFAULT_CONVERSATION_FEATURES
|
|
205
|
+
};
|
|
206
|
+
}
|
|
207
|
+
function cleanString(value, fallback, maxLength = 2e3) {
|
|
208
|
+
if (typeof value !== "string") return fallback;
|
|
209
|
+
return value.trim().slice(0, maxLength);
|
|
210
|
+
}
|
|
211
|
+
function cleanBoolean(value, fallback) {
|
|
212
|
+
return typeof value === "boolean" ? value : fallback;
|
|
213
|
+
}
|
|
214
|
+
function cleanNumber(value, fallback, min, max) {
|
|
215
|
+
const num = typeof value === "number" ? value : Number(value);
|
|
216
|
+
if (!Number.isFinite(num)) return fallback;
|
|
217
|
+
return Math.min(Math.max(Math.round(num), min), max);
|
|
218
|
+
}
|
|
219
|
+
function cleanEnum(value, fallback, allowed) {
|
|
220
|
+
return typeof value === "string" && allowed.includes(value) ? value : fallback;
|
|
221
|
+
}
|
|
222
|
+
function cleanStringList(value, fallback, maxItems = 20) {
|
|
223
|
+
if (!Array.isArray(value)) return fallback;
|
|
224
|
+
const cleaned = value.filter((item) => typeof item === "string").map((item) => item.trim()).filter(Boolean).slice(0, maxItems);
|
|
225
|
+
return cleaned.length > 0 ? Array.from(new Set(cleaned)) : fallback;
|
|
226
|
+
}
|
|
227
|
+
function normalizeProjectSettings(projectId, input) {
|
|
228
|
+
const defaults = createDefaultProjectSettings(projectId);
|
|
229
|
+
const branding = (input == null ? void 0 : input.branding) || {};
|
|
230
|
+
const ai = (input == null ? void 0 : input.ai) || {};
|
|
231
|
+
const auth = (input == null ? void 0 : input.auth) || {};
|
|
232
|
+
const widget = (input == null ? void 0 : input.widget) || {};
|
|
233
|
+
const telemetry = (input == null ? void 0 : input.telemetry) || {};
|
|
234
|
+
return {
|
|
235
|
+
projectId,
|
|
236
|
+
branding: {
|
|
237
|
+
companyName: cleanString(branding.companyName, defaults.branding.companyName, 120),
|
|
238
|
+
botName: cleanString(branding.botName, defaults.branding.botName, 120),
|
|
239
|
+
welcomeMessage: cleanString(branding.welcomeMessage, defaults.branding.welcomeMessage, 500),
|
|
240
|
+
primaryColor: cleanString(branding.primaryColor, defaults.branding.primaryColor, 32),
|
|
241
|
+
secondaryColor: cleanString(branding.secondaryColor, defaults.branding.secondaryColor, 32),
|
|
242
|
+
fontFamily: cleanString(branding.fontFamily, defaults.branding.fontFamily, 80),
|
|
243
|
+
borderRadius: cleanNumber(branding.borderRadius, defaults.branding.borderRadius, 0, 32),
|
|
244
|
+
logoUrl: cleanString(branding.logoUrl, defaults.branding.logoUrl, 500),
|
|
245
|
+
avatarUrl: cleanString(branding.avatarUrl, defaults.branding.avatarUrl, 500),
|
|
246
|
+
customCss: cleanString(branding.customCss, defaults.branding.customCss, 5e3)
|
|
247
|
+
},
|
|
248
|
+
ai: {
|
|
249
|
+
defaultModel: cleanString(ai.defaultModel, defaults.ai.defaultModel, 120),
|
|
250
|
+
embeddingModel: cleanString(ai.embeddingModel, defaults.ai.embeddingModel, 120),
|
|
251
|
+
systemPrompt: cleanString(ai.systemPrompt, defaults.ai.systemPrompt, 5e3),
|
|
252
|
+
memoryEnabled: cleanBoolean(ai.memoryEnabled, defaults.ai.memoryEnabled),
|
|
253
|
+
multiModelEnabled: cleanBoolean(ai.multiModelEnabled, defaults.ai.multiModelEnabled),
|
|
254
|
+
citationsEnabled: cleanBoolean(ai.citationsEnabled, defaults.ai.citationsEnabled),
|
|
255
|
+
fileUploadEnabled: cleanBoolean(ai.fileUploadEnabled, defaults.ai.fileUploadEnabled)
|
|
256
|
+
},
|
|
257
|
+
auth: {
|
|
258
|
+
mode: cleanEnum(auth.mode, defaults.auth.mode, ["public", "anonymous", "jwt", "oauth", "okta", "auth0", "supabase", "firebase", "sso", "custom_token"]),
|
|
259
|
+
allowedOrigins: cleanStringList(auth.allowedOrigins, defaults.auth.allowedOrigins, 25),
|
|
260
|
+
requireVerifiedEmail: cleanBoolean(auth.requireVerifiedEmail, defaults.auth.requireVerifiedEmail),
|
|
261
|
+
sessionTtlMinutes: cleanNumber(auth.sessionTtlMinutes, defaults.auth.sessionTtlMinutes, 15, 43200)
|
|
262
|
+
},
|
|
263
|
+
widget: {
|
|
264
|
+
position: cleanEnum(widget.position, defaults.widget.position, ["bottom-right", "bottom-left", "top-right", "top-left"]),
|
|
265
|
+
theme: cleanEnum(widget.theme, defaults.widget.theme, ["light", "dark", "system"]),
|
|
266
|
+
lazyLoad: cleanBoolean(widget.lazyLoad, defaults.widget.lazyLoad),
|
|
267
|
+
autoReconnect: cleanBoolean(widget.autoReconnect, defaults.widget.autoReconnect),
|
|
268
|
+
persistConversations: cleanBoolean(widget.persistConversations, defaults.widget.persistConversations),
|
|
269
|
+
showRetrivoraBranding: cleanBoolean(widget.showRetrivoraBranding, defaults.widget.showRetrivoraBranding)
|
|
270
|
+
},
|
|
271
|
+
telemetry: {
|
|
272
|
+
enabled: cleanBoolean(telemetry.enabled, defaults.telemetry.enabled),
|
|
273
|
+
collectBrowser: cleanBoolean(telemetry.collectBrowser, defaults.telemetry.collectBrowser),
|
|
274
|
+
collectCountry: cleanBoolean(telemetry.collectCountry, defaults.telemetry.collectCountry),
|
|
275
|
+
redactPii: cleanBoolean(telemetry.redactPii, defaults.telemetry.redactPii),
|
|
276
|
+
retentionDays: cleanNumber(telemetry.retentionDays, defaults.telemetry.retentionDays, 1, 365)
|
|
277
|
+
},
|
|
278
|
+
lifecycleHooks: cleanStringList(input == null ? void 0 : input.lifecycleHooks, defaults.lifecycleHooks, 30),
|
|
279
|
+
conversationFeatures: cleanStringList(input == null ? void 0 : input.conversationFeatures, defaults.conversationFeatures, 30),
|
|
280
|
+
updatedAt: input == null ? void 0 : input.updatedAt
|
|
281
|
+
};
|
|
282
|
+
}
|
|
283
|
+
var DEFAULT_LIFECYCLE_HOOKS, DEFAULT_CONVERSATION_FEATURES;
|
|
284
|
+
var init_ProjectSettings = __esm({
|
|
285
|
+
"src/core/ProjectSettings.ts"() {
|
|
286
|
+
"use strict";
|
|
287
|
+
DEFAULT_LIFECYCLE_HOOKS = [
|
|
288
|
+
"beforeInitialize",
|
|
289
|
+
"afterInitialize",
|
|
290
|
+
"beforeSend",
|
|
291
|
+
"afterResponse",
|
|
292
|
+
"onMessage",
|
|
293
|
+
"onCitationClick",
|
|
294
|
+
"onFeedback",
|
|
295
|
+
"onError",
|
|
296
|
+
"onReconnect",
|
|
297
|
+
"onFileUpload"
|
|
298
|
+
];
|
|
299
|
+
DEFAULT_CONVERSATION_FEATURES = [
|
|
300
|
+
"History",
|
|
301
|
+
"Resume",
|
|
302
|
+
"Search",
|
|
303
|
+
"Export",
|
|
304
|
+
"Rename",
|
|
305
|
+
"Delete",
|
|
306
|
+
"Tags",
|
|
307
|
+
"Pinned",
|
|
308
|
+
"Unread",
|
|
309
|
+
"Ratings"
|
|
310
|
+
];
|
|
311
|
+
}
|
|
312
|
+
});
|
|
313
|
+
|
|
314
|
+
// package.json
|
|
315
|
+
var package_default;
|
|
316
|
+
var init_package = __esm({
|
|
317
|
+
"package.json"() {
|
|
318
|
+
package_default = {
|
|
319
|
+
name: "@retrivora-ai/rag-engine",
|
|
320
|
+
version: "2.3.6",
|
|
321
|
+
description: "Retrivora AI is a plug-and-play AI engine for RAG chat experiences \u2014 generic vector DB + LLM provider, embeddable or standalone.",
|
|
322
|
+
author: "Abhinav Alkuchi",
|
|
323
|
+
license: "UNLICENSED",
|
|
324
|
+
keywords: [
|
|
325
|
+
"rag",
|
|
326
|
+
"retrieval-augmented-generation",
|
|
327
|
+
"chatbot",
|
|
328
|
+
"vector-database",
|
|
329
|
+
"pinecone",
|
|
330
|
+
"pgvector",
|
|
331
|
+
"postgresql",
|
|
332
|
+
"milvus",
|
|
333
|
+
"qdrant",
|
|
334
|
+
"chromadb",
|
|
335
|
+
"redis",
|
|
336
|
+
"weaviate",
|
|
337
|
+
"mongodb",
|
|
338
|
+
"openai",
|
|
339
|
+
"anthropic",
|
|
340
|
+
"ollama",
|
|
341
|
+
"nextjs",
|
|
342
|
+
"react",
|
|
343
|
+
"ai",
|
|
344
|
+
"llm",
|
|
345
|
+
"embeddings"
|
|
346
|
+
],
|
|
347
|
+
main: "dist/index.js",
|
|
348
|
+
module: "dist/index.mjs",
|
|
349
|
+
types: "dist/index.d.ts",
|
|
350
|
+
exports: {
|
|
351
|
+
".": {
|
|
352
|
+
types: "./dist/index.d.ts",
|
|
353
|
+
require: "./dist/index.js",
|
|
354
|
+
import: "./dist/index.mjs"
|
|
355
|
+
},
|
|
356
|
+
"./style.css": "./dist/index.css",
|
|
357
|
+
"./index.css": "./dist/index.css",
|
|
358
|
+
"./styles.css": "./dist/index.css",
|
|
359
|
+
"./handlers": {
|
|
360
|
+
types: "./dist/handlers/index.d.ts",
|
|
361
|
+
require: "./dist/handlers/index.js",
|
|
362
|
+
import: "./dist/handlers/index.mjs"
|
|
363
|
+
},
|
|
364
|
+
"./server": {
|
|
365
|
+
types: "./dist/server.d.ts",
|
|
366
|
+
require: "./dist/server.js",
|
|
367
|
+
import: "./dist/server.mjs"
|
|
368
|
+
}
|
|
369
|
+
},
|
|
370
|
+
browser: {
|
|
371
|
+
child_process: false,
|
|
372
|
+
fs: false,
|
|
373
|
+
net: false,
|
|
374
|
+
tls: false,
|
|
375
|
+
crypto: false,
|
|
376
|
+
os: false,
|
|
377
|
+
path: false,
|
|
378
|
+
stream: false,
|
|
379
|
+
http: false,
|
|
380
|
+
https: false,
|
|
381
|
+
zlib: false,
|
|
382
|
+
mongodb: false,
|
|
383
|
+
pg: false,
|
|
384
|
+
"pdf-parse": false,
|
|
385
|
+
mammoth: false
|
|
386
|
+
},
|
|
387
|
+
files: [
|
|
388
|
+
"dist",
|
|
389
|
+
"src",
|
|
390
|
+
".env.example",
|
|
391
|
+
"README.md",
|
|
392
|
+
"FREE_TIER_ARCHITECTURE.md"
|
|
393
|
+
],
|
|
394
|
+
scripts: {
|
|
395
|
+
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",
|
|
396
|
+
build: "npm run build:pkg",
|
|
397
|
+
"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",
|
|
398
|
+
lint: "eslint",
|
|
399
|
+
typecheck: "tsc --noEmit -p tsconfig.build.json",
|
|
400
|
+
clean: "rm -rf dist"
|
|
401
|
+
},
|
|
402
|
+
peerDependencies: {
|
|
403
|
+
next: ">=15.0.0",
|
|
404
|
+
react: ">=18.0.0",
|
|
405
|
+
"react-dom": ">=18.0.0"
|
|
406
|
+
},
|
|
407
|
+
peerDependenciesMeta: {
|
|
408
|
+
next: {
|
|
409
|
+
optional: true
|
|
410
|
+
}
|
|
411
|
+
},
|
|
412
|
+
dependencies: {
|
|
413
|
+
"@anthropic-ai/sdk": "^0.95.1",
|
|
414
|
+
"@google/genai": "^0.8.0",
|
|
415
|
+
"@google/generative-ai": "^0.24.1",
|
|
416
|
+
"@pinecone-database/pinecone": "^7.2.0",
|
|
417
|
+
"@types/papaparse": "^5.5.2",
|
|
418
|
+
axios: "^1.15.0",
|
|
419
|
+
"lucide-react": "^1.8.0",
|
|
420
|
+
"next-themes": "^0.4.6",
|
|
421
|
+
openai: "^6.34.0",
|
|
422
|
+
papaparse: "^5.5.3",
|
|
423
|
+
"react-is": "^18.3.1",
|
|
424
|
+
"react-markdown": "^10.1.0",
|
|
425
|
+
recharts: "^3.8.1",
|
|
426
|
+
"remark-gfm": "^4.0.1",
|
|
427
|
+
xlsx: "^0.18.5"
|
|
428
|
+
},
|
|
429
|
+
optionalDependencies: {
|
|
430
|
+
"@langchain/core": "^1.1.42",
|
|
431
|
+
"@langchain/openai": "^1.4.5",
|
|
432
|
+
langchain: "^1.3.5",
|
|
433
|
+
llamaindex: "^0.11.9",
|
|
434
|
+
mammoth: "^1.8.0",
|
|
435
|
+
mongodb: "^7.1.1",
|
|
436
|
+
"pdf-parse": "^1.1.1",
|
|
437
|
+
pg: "^8.20.0"
|
|
438
|
+
},
|
|
439
|
+
devDependencies: {
|
|
440
|
+
"@tailwindcss/cli": "^4",
|
|
441
|
+
"@tailwindcss/postcss": "^4",
|
|
442
|
+
"@types/estree": "^1.0.9",
|
|
443
|
+
"@types/node": "^20",
|
|
444
|
+
"@types/pdf-parse": "^1.1.5",
|
|
445
|
+
"@types/pg": "^8.20.0",
|
|
446
|
+
"@types/react": "^19.2.14",
|
|
447
|
+
"@types/react-dom": "^19.2.3",
|
|
448
|
+
dotenv: "^17.4.2",
|
|
449
|
+
eslint: "^9",
|
|
450
|
+
"eslint-config-next": "16.2.4",
|
|
451
|
+
next: "16.2.10",
|
|
452
|
+
tailwindcss: "^4",
|
|
453
|
+
tsup: "^8.5.1",
|
|
454
|
+
typescript: "^5"
|
|
455
|
+
}
|
|
456
|
+
};
|
|
457
|
+
}
|
|
458
|
+
});
|
|
459
|
+
|
|
460
|
+
// src/version.ts
|
|
461
|
+
var SDK_VERSION;
|
|
462
|
+
var init_version = __esm({
|
|
463
|
+
"src/version.ts"() {
|
|
464
|
+
"use strict";
|
|
465
|
+
init_package();
|
|
466
|
+
SDK_VERSION = package_default.version || "2.1.3";
|
|
467
|
+
}
|
|
468
|
+
});
|
|
469
|
+
|
|
157
470
|
// src/core/ConfigFetcher.ts
|
|
158
471
|
var CONTROL_PLANE_URL, LLM_PROXY_BASE_URL, ConfigFetcher;
|
|
159
472
|
var init_ConfigFetcher = __esm({
|
|
160
473
|
"src/core/ConfigFetcher.ts"() {
|
|
161
474
|
"use strict";
|
|
475
|
+
init_ProjectSettings();
|
|
476
|
+
init_version();
|
|
162
477
|
CONTROL_PLANE_URL = "https://www.retrivora.com";
|
|
163
478
|
LLM_PROXY_BASE_URL = "https://www.retrivora.com/api/v1";
|
|
164
479
|
ConfigFetcher = class {
|
|
@@ -191,11 +506,12 @@ var init_ConfigFetcher = __esm({
|
|
|
191
506
|
].filter((url) => Boolean(url) && !url.includes("localhost") && !url.includes("127.0.0.1")).map((url) => url.replace(/\/$/, ""));
|
|
192
507
|
for (const baseUrl of controlPlaneUrls) {
|
|
193
508
|
try {
|
|
194
|
-
const url = `${baseUrl}/api/v1/config?projectId=${encodeURIComponent(projectId)}
|
|
509
|
+
const url = `${baseUrl}/api/v1/config?projectId=${encodeURIComponent(projectId)}`;
|
|
195
510
|
const res = await fetch(url, {
|
|
196
511
|
method: "GET",
|
|
197
512
|
headers: __spreadValues({
|
|
198
|
-
"Content-Type": "application/json"
|
|
513
|
+
"Content-Type": "application/json",
|
|
514
|
+
"x-sdk-version": SDK_VERSION
|
|
199
515
|
}, licenseKey ? { "x-license-key": licenseKey } : {})
|
|
200
516
|
});
|
|
201
517
|
if (res.ok) {
|
|
@@ -235,7 +551,11 @@ var init_ConfigFetcher = __esm({
|
|
|
235
551
|
workspace: data.workspace || {
|
|
236
552
|
namespace: fetchedProjectId,
|
|
237
553
|
indexName: data.vectorDb.indexName || "retrivora-free"
|
|
238
|
-
}
|
|
554
|
+
},
|
|
555
|
+
projectSettings: normalizeProjectSettings(
|
|
556
|
+
fetchedProjectId,
|
|
557
|
+
data.projectSettings || data.settings
|
|
558
|
+
)
|
|
239
559
|
};
|
|
240
560
|
this.cache.set(cacheKey, { config, cachedAt: now });
|
|
241
561
|
return config;
|
|
@@ -2342,10 +2662,6 @@ var LicenseVerifier = class {
|
|
|
2342
2662
|
static verify(licenseKey, currentProjectId, provider, publicKeyOverride) {
|
|
2343
2663
|
const isProduction = process.env.NODE_ENV === "production";
|
|
2344
2664
|
const now = Date.now();
|
|
2345
|
-
console.log(`[Retrivora SDK] LicenseVerifier.verify() - licenseKey`, licenseKey);
|
|
2346
|
-
console.log(`[Retrivora SDK] LicenseVerifier.verify() - currentProjectId`, currentProjectId);
|
|
2347
|
-
console.log(`[Retrivora SDK] LicenseVerifier.verify() - provider`, provider);
|
|
2348
|
-
console.log(`[Retrivora SDK] LicenseVerifier.verify() - publicKeyOverride`, publicKeyOverride);
|
|
2349
2665
|
if (licenseKey) {
|
|
2350
2666
|
const cacheKey = `${licenseKey}:${currentProjectId}:${provider || ""}:${publicKeyOverride || ""}`;
|
|
2351
2667
|
const cached = this.cache.get(cacheKey);
|
|
@@ -2836,6 +3152,7 @@ var ConfigResolver = class {
|
|
|
2836
3152
|
options: __spreadValues(__spreadValues({}, envConfig.embedding.options || {}), hostConfig.embedding.options || {})
|
|
2837
3153
|
}) : envConfig.embedding,
|
|
2838
3154
|
ui: hostConfig.ui ? mergeDefined(envConfig.ui, hostConfig.ui) : envConfig.ui,
|
|
3155
|
+
projectSettings: hostConfig.projectSettings || envConfig.projectSettings,
|
|
2839
3156
|
rag: hostConfig.rag ? __spreadValues(__spreadValues({}, envConfig.rag), hostConfig.rag) : envConfig.rag,
|
|
2840
3157
|
telemetry: hostConfig.telemetry ? __spreadValues(__spreadValues({}, envConfig.telemetry), hostConfig.telemetry) : envConfig.telemetry
|
|
2841
3158
|
});
|
|
@@ -4738,149 +5055,8 @@ var ConfigValidator = class {
|
|
|
4738
5055
|
}
|
|
4739
5056
|
};
|
|
4740
5057
|
|
|
4741
|
-
//
|
|
4742
|
-
|
|
4743
|
-
name: "@retrivora-ai/rag-engine",
|
|
4744
|
-
version: "2.3.5",
|
|
4745
|
-
description: "Retrivora AI is a plug-and-play AI engine for RAG chat experiences \u2014 generic vector DB + LLM provider, embeddable or standalone.",
|
|
4746
|
-
author: "Abhinav Alkuchi",
|
|
4747
|
-
license: "UNLICENSED",
|
|
4748
|
-
keywords: [
|
|
4749
|
-
"rag",
|
|
4750
|
-
"retrieval-augmented-generation",
|
|
4751
|
-
"chatbot",
|
|
4752
|
-
"vector-database",
|
|
4753
|
-
"pinecone",
|
|
4754
|
-
"pgvector",
|
|
4755
|
-
"postgresql",
|
|
4756
|
-
"milvus",
|
|
4757
|
-
"qdrant",
|
|
4758
|
-
"chromadb",
|
|
4759
|
-
"redis",
|
|
4760
|
-
"weaviate",
|
|
4761
|
-
"mongodb",
|
|
4762
|
-
"openai",
|
|
4763
|
-
"anthropic",
|
|
4764
|
-
"ollama",
|
|
4765
|
-
"nextjs",
|
|
4766
|
-
"react",
|
|
4767
|
-
"ai",
|
|
4768
|
-
"llm",
|
|
4769
|
-
"embeddings"
|
|
4770
|
-
],
|
|
4771
|
-
main: "dist/index.js",
|
|
4772
|
-
module: "dist/index.mjs",
|
|
4773
|
-
types: "dist/index.d.ts",
|
|
4774
|
-
exports: {
|
|
4775
|
-
".": {
|
|
4776
|
-
types: "./dist/index.d.ts",
|
|
4777
|
-
require: "./dist/index.js",
|
|
4778
|
-
import: "./dist/index.mjs"
|
|
4779
|
-
},
|
|
4780
|
-
"./style.css": "./dist/index.css",
|
|
4781
|
-
"./index.css": "./dist/index.css",
|
|
4782
|
-
"./styles.css": "./dist/index.css",
|
|
4783
|
-
"./handlers": {
|
|
4784
|
-
types: "./dist/handlers/index.d.ts",
|
|
4785
|
-
require: "./dist/handlers/index.js",
|
|
4786
|
-
import: "./dist/handlers/index.mjs"
|
|
4787
|
-
},
|
|
4788
|
-
"./server": {
|
|
4789
|
-
types: "./dist/server.d.ts",
|
|
4790
|
-
require: "./dist/server.js",
|
|
4791
|
-
import: "./dist/server.mjs"
|
|
4792
|
-
}
|
|
4793
|
-
},
|
|
4794
|
-
browser: {
|
|
4795
|
-
child_process: false,
|
|
4796
|
-
fs: false,
|
|
4797
|
-
net: false,
|
|
4798
|
-
tls: false,
|
|
4799
|
-
crypto: false,
|
|
4800
|
-
os: false,
|
|
4801
|
-
path: false,
|
|
4802
|
-
stream: false,
|
|
4803
|
-
http: false,
|
|
4804
|
-
https: false,
|
|
4805
|
-
zlib: false,
|
|
4806
|
-
mongodb: false,
|
|
4807
|
-
pg: false,
|
|
4808
|
-
"pdf-parse": false,
|
|
4809
|
-
mammoth: false
|
|
4810
|
-
},
|
|
4811
|
-
files: [
|
|
4812
|
-
"dist",
|
|
4813
|
-
"src",
|
|
4814
|
-
".env.example",
|
|
4815
|
-
"README.md",
|
|
4816
|
-
"FREE_TIER_ARCHITECTURE.md"
|
|
4817
|
-
],
|
|
4818
|
-
scripts: {
|
|
4819
|
-
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",
|
|
4820
|
-
build: "npm run build:pkg",
|
|
4821
|
-
"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",
|
|
4822
|
-
lint: "eslint",
|
|
4823
|
-
typecheck: "tsc --noEmit -p tsconfig.build.json",
|
|
4824
|
-
clean: "rm -rf dist"
|
|
4825
|
-
},
|
|
4826
|
-
peerDependencies: {
|
|
4827
|
-
next: ">=15.0.0",
|
|
4828
|
-
react: ">=18.0.0",
|
|
4829
|
-
"react-dom": ">=18.0.0"
|
|
4830
|
-
},
|
|
4831
|
-
peerDependenciesMeta: {
|
|
4832
|
-
next: {
|
|
4833
|
-
optional: true
|
|
4834
|
-
}
|
|
4835
|
-
},
|
|
4836
|
-
dependencies: {
|
|
4837
|
-
"@anthropic-ai/sdk": "^0.95.1",
|
|
4838
|
-
"@google/genai": "^0.8.0",
|
|
4839
|
-
"@google/generative-ai": "^0.24.1",
|
|
4840
|
-
"@pinecone-database/pinecone": "^7.2.0",
|
|
4841
|
-
"@types/papaparse": "^5.5.2",
|
|
4842
|
-
axios: "^1.15.0",
|
|
4843
|
-
"lucide-react": "^1.8.0",
|
|
4844
|
-
"next-themes": "^0.4.6",
|
|
4845
|
-
openai: "^6.34.0",
|
|
4846
|
-
papaparse: "^5.5.3",
|
|
4847
|
-
"react-is": "^18.3.1",
|
|
4848
|
-
"react-markdown": "^10.1.0",
|
|
4849
|
-
recharts: "^3.8.1",
|
|
4850
|
-
"remark-gfm": "^4.0.1",
|
|
4851
|
-
xlsx: "^0.18.5"
|
|
4852
|
-
},
|
|
4853
|
-
optionalDependencies: {
|
|
4854
|
-
"@langchain/core": "^1.1.42",
|
|
4855
|
-
"@langchain/openai": "^1.4.5",
|
|
4856
|
-
langchain: "^1.3.5",
|
|
4857
|
-
llamaindex: "^0.11.9",
|
|
4858
|
-
mammoth: "^1.8.0",
|
|
4859
|
-
mongodb: "^7.1.1",
|
|
4860
|
-
"pdf-parse": "^1.1.1",
|
|
4861
|
-
pg: "^8.20.0"
|
|
4862
|
-
},
|
|
4863
|
-
devDependencies: {
|
|
4864
|
-
"@tailwindcss/cli": "^4",
|
|
4865
|
-
"@tailwindcss/postcss": "^4",
|
|
4866
|
-
"@types/estree": "^1.0.9",
|
|
4867
|
-
"@types/node": "^20",
|
|
4868
|
-
"@types/pdf-parse": "^1.1.5",
|
|
4869
|
-
"@types/pg": "^8.20.0",
|
|
4870
|
-
"@types/react": "^19.2.14",
|
|
4871
|
-
"@types/react-dom": "^19.2.3",
|
|
4872
|
-
dotenv: "^17.4.2",
|
|
4873
|
-
eslint: "^9",
|
|
4874
|
-
"eslint-config-next": "16.2.4",
|
|
4875
|
-
next: "16.2.10",
|
|
4876
|
-
tailwindcss: "^4",
|
|
4877
|
-
tsup: "^8.5.1",
|
|
4878
|
-
typescript: "^5"
|
|
4879
|
-
}
|
|
4880
|
-
};
|
|
4881
|
-
|
|
4882
|
-
// src/version.ts
|
|
4883
|
-
var SDK_VERSION = package_default.version || "2.1.3";
|
|
5058
|
+
// src/core/Pipeline.ts
|
|
5059
|
+
init_version();
|
|
4884
5060
|
|
|
4885
5061
|
// src/rag/DocumentChunker.ts
|
|
4886
5062
|
var DocumentChunker = class {
|
|
@@ -10549,6 +10725,7 @@ var DatabaseStorage = class {
|
|
|
10549
10725
|
};
|
|
10550
10726
|
|
|
10551
10727
|
// src/handlers/index.ts
|
|
10728
|
+
init_version();
|
|
10552
10729
|
async function checkAuth(req, onAuthorize) {
|
|
10553
10730
|
if (!onAuthorize) return null;
|
|
10554
10731
|
try {
|
|
@@ -10680,6 +10857,35 @@ function enforceLicense(req, config, bodyLicenseKey) {
|
|
|
10680
10857
|
};
|
|
10681
10858
|
}
|
|
10682
10859
|
}
|
|
10860
|
+
function getAllowedNamespaces(projectId) {
|
|
10861
|
+
const trimmed = projectId.trim();
|
|
10862
|
+
const withoutPrefix = trimmed.startsWith("retrivora-") ? trimmed.replace(/^retrivora-/, "") : trimmed;
|
|
10863
|
+
return new Set([
|
|
10864
|
+
trimmed,
|
|
10865
|
+
withoutPrefix,
|
|
10866
|
+
`retrivora-${withoutPrefix}`
|
|
10867
|
+
].filter(Boolean));
|
|
10868
|
+
}
|
|
10869
|
+
function resolveLicensedNamespace(payload, requestedNamespace) {
|
|
10870
|
+
const allowed = getAllowedNamespaces(payload.projectId);
|
|
10871
|
+
const requested = requestedNamespace == null ? void 0 : requestedNamespace.trim();
|
|
10872
|
+
if (requested && !allowed.has(requested)) {
|
|
10873
|
+
return {
|
|
10874
|
+
ok: false,
|
|
10875
|
+
response: new Response(JSON.stringify({
|
|
10876
|
+
error: {
|
|
10877
|
+
code: "NAMESPACE_FORBIDDEN",
|
|
10878
|
+
message: "Requested namespace is not authorized for this license."
|
|
10879
|
+
}
|
|
10880
|
+
}), {
|
|
10881
|
+
status: 403,
|
|
10882
|
+
headers: { "Content-Type": "application/json" }
|
|
10883
|
+
})
|
|
10884
|
+
};
|
|
10885
|
+
}
|
|
10886
|
+
const defaultNamespace = payload.projectId.startsWith("retrivora-") ? payload.projectId : `retrivora-${payload.projectId}`;
|
|
10887
|
+
return { ok: true, namespace: requested || defaultNamespace };
|
|
10888
|
+
}
|
|
10683
10889
|
var MAX_MESSAGE_LENGTH = 8e3;
|
|
10684
10890
|
function sanitizeInput(raw) {
|
|
10685
10891
|
const stripped = raw.replace(/[\u0000-\u0008\u000B\u000C\u000E-\u001F\u007F-\u009F]/g, "");
|
|
@@ -10840,6 +11046,8 @@ function createChatHandler(configOrPlugin, options) {
|
|
|
10840
11046
|
}
|
|
10841
11047
|
const history = bodyObj.history || (Array.isArray(bodyObj.messages) ? bodyObj.messages.slice(0, -1) : []);
|
|
10842
11048
|
const { namespace, sessionId = "default", messageId, userMessageId } = bodyObj;
|
|
11049
|
+
const namespaceCheck = resolveLicensedNamespace(licenseCheck.payload, namespace);
|
|
11050
|
+
if (!namespaceCheck.ok) return namespaceCheck.response;
|
|
10843
11051
|
const sanitized = sanitizeInput(rawMessage != null ? rawMessage : "");
|
|
10844
11052
|
if (!sanitized.ok) {
|
|
10845
11053
|
return import_server.NextResponse.json({ error: { code: "INVALID_INPUT", message: sanitized.error } }, { status: 400 });
|
|
@@ -10851,7 +11059,7 @@ function createChatHandler(configOrPlugin, options) {
|
|
|
10851
11059
|
role: "user",
|
|
10852
11060
|
content: message
|
|
10853
11061
|
}).catch((err) => console.warn("[createChatHandler] Failed to save user message:", err));
|
|
10854
|
-
const result = await plugin.chat(message, history, namespace);
|
|
11062
|
+
const result = await plugin.chat(message, history, namespaceCheck.namespace);
|
|
10855
11063
|
const assistantMsgId = messageId || `assistant_${Date.now()}_${Math.random().toString(36).slice(2, 6)}`;
|
|
10856
11064
|
await storage.saveMessage(sessionId, {
|
|
10857
11065
|
id: assistantMsgId,
|
|
@@ -10932,6 +11140,8 @@ function createStreamHandler(configOrPlugin, options) {
|
|
|
10932
11140
|
}
|
|
10933
11141
|
const history = bodyObj.history || (Array.isArray(bodyObj.messages) ? bodyObj.messages.slice(0, -1) : []);
|
|
10934
11142
|
const { namespace, sessionId = "default", messageId, userMessageId } = bodyObj;
|
|
11143
|
+
const namespaceCheck = resolveLicensedNamespace(licenseCheck.payload, namespace);
|
|
11144
|
+
if (!namespaceCheck.ok) return namespaceCheck.response;
|
|
10935
11145
|
const sanitized = sanitizeInput(rawMessage != null ? rawMessage : "");
|
|
10936
11146
|
if (!sanitized.ok) {
|
|
10937
11147
|
return new Response(
|
|
@@ -10961,7 +11171,7 @@ function createStreamHandler(configOrPlugin, options) {
|
|
|
10961
11171
|
}
|
|
10962
11172
|
};
|
|
10963
11173
|
try {
|
|
10964
|
-
const pipelineStream = plugin.chatStream(message, history, namespace);
|
|
11174
|
+
const pipelineStream = plugin.chatStream(message, history, namespaceCheck.namespace);
|
|
10965
11175
|
let fullReply = "";
|
|
10966
11176
|
try {
|
|
10967
11177
|
for (var iter = __forAwait(pipelineStream), more, temp, error; more = !(temp = await iter.next()).done; more = false) {
|
|
@@ -11067,6 +11277,8 @@ function createIngestHandler(configOrPlugin, options) {
|
|
|
11067
11277
|
if (!Array.isArray(documents) || documents.length === 0) {
|
|
11068
11278
|
return import_server.NextResponse.json({ error: "documents array is required" }, { status: 400 });
|
|
11069
11279
|
}
|
|
11280
|
+
const namespaceCheck = resolveLicensedNamespace(licenseCheck.payload, namespace);
|
|
11281
|
+
if (!namespaceCheck.ok) return namespaceCheck.response;
|
|
11070
11282
|
if (isFreeTier(licenseCheck.payload.tier)) {
|
|
11071
11283
|
const totalIncomingBytes = documents.reduce(
|
|
11072
11284
|
(sum, d) => sum + Buffer.byteLength(d.content || "", "utf8"),
|
|
@@ -11088,7 +11300,7 @@ function createIngestHandler(configOrPlugin, options) {
|
|
|
11088
11300
|
);
|
|
11089
11301
|
}
|
|
11090
11302
|
}
|
|
11091
|
-
const results = await plugin.ingest(documents, namespace);
|
|
11303
|
+
const results = await plugin.ingest(documents, namespaceCheck.namespace);
|
|
11092
11304
|
reportTelemetry(req, plugin, "DOCUMENT_INGESTION", "success", `Ingested ${documents.length} document(s)`);
|
|
11093
11305
|
return import_server.NextResponse.json({ results });
|
|
11094
11306
|
} catch (err) {
|
|
@@ -11176,6 +11388,8 @@ function createUploadHandler(configOrPlugin, options) {
|
|
|
11176
11388
|
const namespace = formData.get("namespace") || void 0;
|
|
11177
11389
|
const dimensionRaw = formData.get("dimension");
|
|
11178
11390
|
const dimension = dimensionRaw ? parseInt(dimensionRaw, 10) : void 0;
|
|
11391
|
+
const namespaceCheck = resolveLicensedNamespace(licenseCheck.payload, namespace);
|
|
11392
|
+
if (!namespaceCheck.ok) return namespaceCheck.response;
|
|
11179
11393
|
if (!files || files.length === 0) {
|
|
11180
11394
|
return import_server.NextResponse.json({ error: "No files provided" }, { status: 400 });
|
|
11181
11395
|
}
|
|
@@ -11292,7 +11506,7 @@ function createUploadHandler(configOrPlugin, options) {
|
|
|
11292
11506
|
});
|
|
11293
11507
|
}
|
|
11294
11508
|
}
|
|
11295
|
-
const results = await plugin.ingest(documents, namespace);
|
|
11509
|
+
const results = await plugin.ingest(documents, namespaceCheck.namespace);
|
|
11296
11510
|
reportTelemetry(req, plugin, "DOCUMENT_INGESTION", "success", `Uploaded & ingested ${files.length} file(s)`);
|
|
11297
11511
|
return import_server.NextResponse.json({ message: "Upload successful", results });
|
|
11298
11512
|
} catch (err) {
|
|
@@ -11311,6 +11525,7 @@ function createSuggestionsHandler(configOrPlugin, options) {
|
|
|
11311
11525
|
const config = plugin.getConfig();
|
|
11312
11526
|
const licenseCheck = enforceLicense(req, config);
|
|
11313
11527
|
if (!licenseCheck.ok) return licenseCheck.response;
|
|
11528
|
+
let effectiveLicensePayload = licenseCheck.payload;
|
|
11314
11529
|
try {
|
|
11315
11530
|
let query = "";
|
|
11316
11531
|
let namespace = void 0;
|
|
@@ -11323,6 +11538,7 @@ function createSuggestionsHandler(configOrPlugin, options) {
|
|
|
11323
11538
|
if (bodyLicenseKey) {
|
|
11324
11539
|
const recheck = enforceLicense(req, config, bodyLicenseKey);
|
|
11325
11540
|
if (!recheck.ok) return recheck.response;
|
|
11541
|
+
effectiveLicensePayload = recheck.payload;
|
|
11326
11542
|
}
|
|
11327
11543
|
} else {
|
|
11328
11544
|
const url = new URL(req.url);
|
|
@@ -11332,7 +11548,9 @@ function createSuggestionsHandler(configOrPlugin, options) {
|
|
|
11332
11548
|
if (!query || typeof query !== "string" || !query.trim()) {
|
|
11333
11549
|
return import_server.NextResponse.json({ suggestions: [] });
|
|
11334
11550
|
}
|
|
11335
|
-
const
|
|
11551
|
+
const namespaceCheck = resolveLicensedNamespace(effectiveLicensePayload, namespace);
|
|
11552
|
+
if (!namespaceCheck.ok) return namespaceCheck.response;
|
|
11553
|
+
const suggestions = await plugin.getSuggestions(query, namespaceCheck.namespace);
|
|
11336
11554
|
reportTelemetry(req, plugin, "AUTO_SUGGESTIONS", "success", `Fetched ${suggestions.length} suggestions for: ${query.slice(0, 30)}`);
|
|
11337
11555
|
return import_server.NextResponse.json({ suggestions });
|
|
11338
11556
|
} catch (err) {
|