@retrivora-ai/rag-engine 2.3.4 → 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 +419 -169
- package/dist/handlers/index.mjs +419 -169
- 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 +638 -189
- package/dist/index.mjs +678 -234
- package/dist/server.d.mts +6 -6
- package/dist/server.d.ts +6 -6
- package/dist/server.js +461 -173
- package/dist/server.mjs +457 -173
- package/package.json +2 -2
- 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 +73 -11
- package/src/core/ConfigResolver.ts +1 -0
- package/src/core/LicenseValidator.ts +31 -13
- package/src/core/ProjectSettings.ts +247 -0
- package/src/handlers/index.ts +63 -7
- package/src/hooks/useProjectSettings.ts +105 -0
- package/src/index.css +9 -0
- package/src/index.ts +28 -0
- package/src/providers/vectordb/PineconeProvider.ts +17 -4
- package/src/server.ts +23 -1
- package/src/types/props.ts +14 -2
package/dist/server.js
CHANGED
|
@@ -154,15 +154,355 @@ 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
|
+
function projectSettingsToUiConfig(settings) {
|
|
284
|
+
return {
|
|
285
|
+
title: settings.branding.botName,
|
|
286
|
+
subtitle: settings.branding.companyName,
|
|
287
|
+
primaryColor: settings.branding.primaryColor,
|
|
288
|
+
accentColor: settings.branding.secondaryColor,
|
|
289
|
+
logoUrl: settings.branding.logoUrl || settings.branding.avatarUrl,
|
|
290
|
+
welcomeMessage: settings.branding.welcomeMessage,
|
|
291
|
+
poweredBy: settings.widget.showRetrivoraBranding ? "Retrivora AI" : "",
|
|
292
|
+
allowUpload: settings.ai.fileUploadEnabled,
|
|
293
|
+
borderRadius: settings.branding.borderRadius <= 4 ? "sm" : settings.branding.borderRadius <= 8 ? "md" : settings.branding.borderRadius <= 16 ? "xl" : "full"
|
|
294
|
+
};
|
|
295
|
+
}
|
|
296
|
+
var DEFAULT_LIFECYCLE_HOOKS, DEFAULT_CONVERSATION_FEATURES;
|
|
297
|
+
var init_ProjectSettings = __esm({
|
|
298
|
+
"src/core/ProjectSettings.ts"() {
|
|
299
|
+
"use strict";
|
|
300
|
+
DEFAULT_LIFECYCLE_HOOKS = [
|
|
301
|
+
"beforeInitialize",
|
|
302
|
+
"afterInitialize",
|
|
303
|
+
"beforeSend",
|
|
304
|
+
"afterResponse",
|
|
305
|
+
"onMessage",
|
|
306
|
+
"onCitationClick",
|
|
307
|
+
"onFeedback",
|
|
308
|
+
"onError",
|
|
309
|
+
"onReconnect",
|
|
310
|
+
"onFileUpload"
|
|
311
|
+
];
|
|
312
|
+
DEFAULT_CONVERSATION_FEATURES = [
|
|
313
|
+
"History",
|
|
314
|
+
"Resume",
|
|
315
|
+
"Search",
|
|
316
|
+
"Export",
|
|
317
|
+
"Rename",
|
|
318
|
+
"Delete",
|
|
319
|
+
"Tags",
|
|
320
|
+
"Pinned",
|
|
321
|
+
"Unread",
|
|
322
|
+
"Ratings"
|
|
323
|
+
];
|
|
324
|
+
}
|
|
325
|
+
});
|
|
326
|
+
|
|
327
|
+
// package.json
|
|
328
|
+
var package_default;
|
|
329
|
+
var init_package = __esm({
|
|
330
|
+
"package.json"() {
|
|
331
|
+
package_default = {
|
|
332
|
+
name: "@retrivora-ai/rag-engine",
|
|
333
|
+
version: "2.3.6",
|
|
334
|
+
description: "Retrivora AI is a plug-and-play AI engine for RAG chat experiences \u2014 generic vector DB + LLM provider, embeddable or standalone.",
|
|
335
|
+
author: "Abhinav Alkuchi",
|
|
336
|
+
license: "UNLICENSED",
|
|
337
|
+
keywords: [
|
|
338
|
+
"rag",
|
|
339
|
+
"retrieval-augmented-generation",
|
|
340
|
+
"chatbot",
|
|
341
|
+
"vector-database",
|
|
342
|
+
"pinecone",
|
|
343
|
+
"pgvector",
|
|
344
|
+
"postgresql",
|
|
345
|
+
"milvus",
|
|
346
|
+
"qdrant",
|
|
347
|
+
"chromadb",
|
|
348
|
+
"redis",
|
|
349
|
+
"weaviate",
|
|
350
|
+
"mongodb",
|
|
351
|
+
"openai",
|
|
352
|
+
"anthropic",
|
|
353
|
+
"ollama",
|
|
354
|
+
"nextjs",
|
|
355
|
+
"react",
|
|
356
|
+
"ai",
|
|
357
|
+
"llm",
|
|
358
|
+
"embeddings"
|
|
359
|
+
],
|
|
360
|
+
main: "dist/index.js",
|
|
361
|
+
module: "dist/index.mjs",
|
|
362
|
+
types: "dist/index.d.ts",
|
|
363
|
+
exports: {
|
|
364
|
+
".": {
|
|
365
|
+
types: "./dist/index.d.ts",
|
|
366
|
+
require: "./dist/index.js",
|
|
367
|
+
import: "./dist/index.mjs"
|
|
368
|
+
},
|
|
369
|
+
"./style.css": "./dist/index.css",
|
|
370
|
+
"./index.css": "./dist/index.css",
|
|
371
|
+
"./styles.css": "./dist/index.css",
|
|
372
|
+
"./handlers": {
|
|
373
|
+
types: "./dist/handlers/index.d.ts",
|
|
374
|
+
require: "./dist/handlers/index.js",
|
|
375
|
+
import: "./dist/handlers/index.mjs"
|
|
376
|
+
},
|
|
377
|
+
"./server": {
|
|
378
|
+
types: "./dist/server.d.ts",
|
|
379
|
+
require: "./dist/server.js",
|
|
380
|
+
import: "./dist/server.mjs"
|
|
381
|
+
}
|
|
382
|
+
},
|
|
383
|
+
browser: {
|
|
384
|
+
child_process: false,
|
|
385
|
+
fs: false,
|
|
386
|
+
net: false,
|
|
387
|
+
tls: false,
|
|
388
|
+
crypto: false,
|
|
389
|
+
os: false,
|
|
390
|
+
path: false,
|
|
391
|
+
stream: false,
|
|
392
|
+
http: false,
|
|
393
|
+
https: false,
|
|
394
|
+
zlib: false,
|
|
395
|
+
mongodb: false,
|
|
396
|
+
pg: false,
|
|
397
|
+
"pdf-parse": false,
|
|
398
|
+
mammoth: false
|
|
399
|
+
},
|
|
400
|
+
files: [
|
|
401
|
+
"dist",
|
|
402
|
+
"src",
|
|
403
|
+
".env.example",
|
|
404
|
+
"README.md",
|
|
405
|
+
"FREE_TIER_ARCHITECTURE.md"
|
|
406
|
+
],
|
|
407
|
+
scripts: {
|
|
408
|
+
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",
|
|
409
|
+
build: "npm run build:pkg",
|
|
410
|
+
"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",
|
|
411
|
+
lint: "eslint",
|
|
412
|
+
typecheck: "tsc --noEmit -p tsconfig.build.json",
|
|
413
|
+
clean: "rm -rf dist"
|
|
414
|
+
},
|
|
415
|
+
peerDependencies: {
|
|
416
|
+
next: ">=15.0.0",
|
|
417
|
+
react: ">=18.0.0",
|
|
418
|
+
"react-dom": ">=18.0.0"
|
|
419
|
+
},
|
|
420
|
+
peerDependenciesMeta: {
|
|
421
|
+
next: {
|
|
422
|
+
optional: true
|
|
423
|
+
}
|
|
424
|
+
},
|
|
425
|
+
dependencies: {
|
|
426
|
+
"@anthropic-ai/sdk": "^0.95.1",
|
|
427
|
+
"@google/genai": "^0.8.0",
|
|
428
|
+
"@google/generative-ai": "^0.24.1",
|
|
429
|
+
"@pinecone-database/pinecone": "^7.2.0",
|
|
430
|
+
"@types/papaparse": "^5.5.2",
|
|
431
|
+
axios: "^1.15.0",
|
|
432
|
+
"lucide-react": "^1.8.0",
|
|
433
|
+
"next-themes": "^0.4.6",
|
|
434
|
+
openai: "^6.34.0",
|
|
435
|
+
papaparse: "^5.5.3",
|
|
436
|
+
"react-is": "^18.3.1",
|
|
437
|
+
"react-markdown": "^10.1.0",
|
|
438
|
+
recharts: "^3.8.1",
|
|
439
|
+
"remark-gfm": "^4.0.1",
|
|
440
|
+
xlsx: "^0.18.5"
|
|
441
|
+
},
|
|
442
|
+
optionalDependencies: {
|
|
443
|
+
"@langchain/core": "^1.1.42",
|
|
444
|
+
"@langchain/openai": "^1.4.5",
|
|
445
|
+
langchain: "^1.3.5",
|
|
446
|
+
llamaindex: "^0.11.9",
|
|
447
|
+
mammoth: "^1.8.0",
|
|
448
|
+
mongodb: "^7.1.1",
|
|
449
|
+
"pdf-parse": "^1.1.1",
|
|
450
|
+
pg: "^8.20.0"
|
|
451
|
+
},
|
|
452
|
+
devDependencies: {
|
|
453
|
+
"@tailwindcss/cli": "^4",
|
|
454
|
+
"@tailwindcss/postcss": "^4",
|
|
455
|
+
"@types/estree": "^1.0.9",
|
|
456
|
+
"@types/node": "^20",
|
|
457
|
+
"@types/pdf-parse": "^1.1.5",
|
|
458
|
+
"@types/pg": "^8.20.0",
|
|
459
|
+
"@types/react": "^19.2.14",
|
|
460
|
+
"@types/react-dom": "^19.2.3",
|
|
461
|
+
dotenv: "^17.4.2",
|
|
462
|
+
eslint: "^9",
|
|
463
|
+
"eslint-config-next": "16.2.4",
|
|
464
|
+
next: "16.2.10",
|
|
465
|
+
tailwindcss: "^4",
|
|
466
|
+
tsup: "^8.5.1",
|
|
467
|
+
typescript: "^5"
|
|
468
|
+
}
|
|
469
|
+
};
|
|
470
|
+
}
|
|
471
|
+
});
|
|
472
|
+
|
|
473
|
+
// src/version.ts
|
|
474
|
+
var SDK_VERSION;
|
|
475
|
+
var init_version = __esm({
|
|
476
|
+
"src/version.ts"() {
|
|
477
|
+
"use strict";
|
|
478
|
+
init_package();
|
|
479
|
+
SDK_VERSION = package_default.version || "2.1.3";
|
|
480
|
+
}
|
|
481
|
+
});
|
|
482
|
+
|
|
157
483
|
// src/core/ConfigFetcher.ts
|
|
158
|
-
var ConfigFetcher;
|
|
484
|
+
var CONTROL_PLANE_URL, LLM_PROXY_BASE_URL, ConfigFetcher;
|
|
159
485
|
var init_ConfigFetcher = __esm({
|
|
160
486
|
"src/core/ConfigFetcher.ts"() {
|
|
161
487
|
"use strict";
|
|
488
|
+
init_ProjectSettings();
|
|
489
|
+
init_version();
|
|
490
|
+
CONTROL_PLANE_URL = "https://www.retrivora.com";
|
|
491
|
+
LLM_PROXY_BASE_URL = "https://www.retrivora.com/api/v1";
|
|
162
492
|
ConfigFetcher = class {
|
|
163
493
|
// 5-minute in-memory session cache
|
|
164
494
|
/**
|
|
165
|
-
* Fetch full project configuration (vectorDb + embedding + llm) from Retrivora Control Plane.
|
|
495
|
+
* Fetch full project configuration (vectorDb + embedding + llm + workspace) from Retrivora Control Plane.
|
|
496
|
+
*
|
|
497
|
+
* The SDK calls https://www.retrivora.com/api/v1/config with the project ID and license key.
|
|
498
|
+
* The server validates the license against the database and returns:
|
|
499
|
+
* - validity (tier, isActive, expiresAt)
|
|
500
|
+
* - LLM model info
|
|
501
|
+
* - embedding model info
|
|
502
|
+
* - Pinecone index name and workspace/namespace
|
|
503
|
+
*
|
|
504
|
+
* The Pinecone API key is NOT returned (server-only). The SDK uses local
|
|
505
|
+
* PINECONE_API_KEY if available, or vector operations are handled server-side.
|
|
166
506
|
*/
|
|
167
507
|
static async fetchRemoteConfig(projectId, licenseKey) {
|
|
168
508
|
var _a3, _b, _c, _d, _e, _f, _g2, _h, _i, _j, _k;
|
|
@@ -175,46 +515,60 @@ var init_ConfigFetcher = __esm({
|
|
|
175
515
|
const controlPlaneUrls = [
|
|
176
516
|
process.env.RETRIVORA_CONTROL_PLANE_URL,
|
|
177
517
|
process.env.NEXT_PUBLIC_RETRIVORA_CONTROL_PLANE_URL,
|
|
178
|
-
|
|
179
|
-
|
|
180
|
-
"http://localhost:3000",
|
|
181
|
-
"http://localhost:3001"
|
|
182
|
-
].filter(Boolean);
|
|
518
|
+
CONTROL_PLANE_URL
|
|
519
|
+
].filter((url) => Boolean(url) && !url.includes("localhost") && !url.includes("127.0.0.1")).map((url) => url.replace(/\/$/, ""));
|
|
183
520
|
for (const baseUrl of controlPlaneUrls) {
|
|
184
521
|
try {
|
|
185
|
-
const url = `${baseUrl
|
|
522
|
+
const url = `${baseUrl}/api/v1/config?projectId=${encodeURIComponent(projectId)}`;
|
|
186
523
|
const res = await fetch(url, {
|
|
187
524
|
method: "GET",
|
|
188
525
|
headers: __spreadValues({
|
|
189
|
-
"Content-Type": "application/json"
|
|
526
|
+
"Content-Type": "application/json",
|
|
527
|
+
"x-sdk-version": SDK_VERSION
|
|
190
528
|
}, licenseKey ? { "x-license-key": licenseKey } : {})
|
|
191
529
|
});
|
|
192
530
|
if (res.ok) {
|
|
193
531
|
const data = await res.json();
|
|
194
|
-
if ((data == null ? void 0 : data.success) && (
|
|
532
|
+
if ((data == null ? void 0 : data.success) && (data == null ? void 0 : data.vectorDb)) {
|
|
195
533
|
const fetchedProjectId = data.projectId || projectId;
|
|
196
534
|
const config = {
|
|
197
535
|
projectId: fetchedProjectId,
|
|
536
|
+
tier: data.tier,
|
|
537
|
+
isActive: data.isActive,
|
|
538
|
+
expiresAt: data.expiresAt,
|
|
198
539
|
vectorDb: {
|
|
199
|
-
apiKey
|
|
540
|
+
// apiKey is not returned by the config API — it's a server-only secret.
|
|
541
|
+
// The SDK uses local PINECONE_API_KEY if available.
|
|
542
|
+
apiKey: data.vectorDb.apiKey || "",
|
|
200
543
|
indexName: data.vectorDb.indexName || "retrivora-free",
|
|
201
544
|
provider: data.vectorDb.provider || "pinecone",
|
|
202
|
-
projectId: fetchedProjectId
|
|
545
|
+
projectId: fetchedProjectId,
|
|
546
|
+
namespace: ((_a3 = data.workspace) == null ? void 0 : _a3.namespace) || data.vectorDb.namespace || fetchedProjectId
|
|
203
547
|
},
|
|
204
548
|
embedding: {
|
|
205
549
|
provider: ((_b = data.embedding) == null ? void 0 : _b.provider) || "universal_rest",
|
|
206
550
|
model: ((_c = data.embedding) == null ? void 0 : _c.model) || "text-embedding-004",
|
|
207
|
-
|
|
551
|
+
// Route through www.retrivora.com proxy, not llm.retrivora.com directly.
|
|
552
|
+
baseUrl: ((_d = data.embedding) == null ? void 0 : _d.baseUrl) || LLM_PROXY_BASE_URL,
|
|
208
553
|
apiKey: ((_e = data.embedding) == null ? void 0 : _e.apiKey) || licenseKey || "",
|
|
209
554
|
profile: ((_f = data.embedding) == null ? void 0 : _f.profile) || "litellm"
|
|
210
555
|
},
|
|
211
556
|
llm: {
|
|
212
557
|
provider: ((_g2 = data.llm) == null ? void 0 : _g2.provider) || "universal_rest",
|
|
213
558
|
model: ((_h = data.llm) == null ? void 0 : _h.model) || "llama-3.1-8b-instant",
|
|
214
|
-
|
|
559
|
+
// Route through www.retrivora.com proxy, not llm.retrivora.com directly.
|
|
560
|
+
baseUrl: ((_i = data.llm) == null ? void 0 : _i.baseUrl) || LLM_PROXY_BASE_URL,
|
|
215
561
|
apiKey: ((_j = data.llm) == null ? void 0 : _j.apiKey) || licenseKey || "",
|
|
216
562
|
profile: ((_k = data.llm) == null ? void 0 : _k.profile) || "litellm"
|
|
217
|
-
}
|
|
563
|
+
},
|
|
564
|
+
workspace: data.workspace || {
|
|
565
|
+
namespace: fetchedProjectId,
|
|
566
|
+
indexName: data.vectorDb.indexName || "retrivora-free"
|
|
567
|
+
},
|
|
568
|
+
projectSettings: normalizeProjectSettings(
|
|
569
|
+
fetchedProjectId,
|
|
570
|
+
data.projectSettings || data.settings
|
|
571
|
+
)
|
|
218
572
|
};
|
|
219
573
|
this.cache.set(cacheKey, { config, cachedAt: now });
|
|
220
574
|
return config;
|
|
@@ -332,19 +686,26 @@ var init_PineconeProvider = __esm({
|
|
|
332
686
|
})();
|
|
333
687
|
const projectId = process.env.RAG_PROJECT_ID || process.env.NEXT_PUBLIC_RAG_PROJECT_ID || jwtProjectId || this.projectId || "default";
|
|
334
688
|
const remoteConfig = await ConfigFetcher.fetchRemoteVectorConfig(projectId, licenseKey);
|
|
335
|
-
if (remoteConfig
|
|
336
|
-
|
|
337
|
-
|
|
689
|
+
if (remoteConfig) {
|
|
690
|
+
if (remoteConfig.apiKey) {
|
|
691
|
+
key = remoteConfig.apiKey;
|
|
692
|
+
this.apiKey = key;
|
|
693
|
+
}
|
|
338
694
|
if (remoteConfig.indexName) {
|
|
339
695
|
this.indexName = remoteConfig.indexName;
|
|
340
696
|
}
|
|
341
697
|
if (remoteConfig.projectId) {
|
|
342
698
|
this.projectId = remoteConfig.projectId;
|
|
343
699
|
}
|
|
700
|
+
if (remoteConfig.namespace) {
|
|
701
|
+
this.namespace = remoteConfig.namespace;
|
|
702
|
+
}
|
|
344
703
|
}
|
|
345
704
|
}
|
|
346
705
|
if (!key) {
|
|
347
|
-
console.warn(
|
|
706
|
+
console.warn(
|
|
707
|
+
"[PineconeProvider] Warning: No Pinecone API key available. Set PINECONE_API_KEY in your environment, or ensure the Retrivora Control Plane (https://www.retrivora.com) is reachable for proxy-based vector operations."
|
|
708
|
+
);
|
|
348
709
|
return;
|
|
349
710
|
}
|
|
350
711
|
this.client = new import_pinecone.Pinecone({ apiKey: key });
|
|
@@ -2209,6 +2570,7 @@ __export(server_exports, {
|
|
|
2209
2570
|
ChartRendererStrategy: () => ChartRendererStrategy,
|
|
2210
2571
|
ChromaDBProvider: () => ChromaDBProvider,
|
|
2211
2572
|
ConfigBuilder: () => ConfigBuilder,
|
|
2573
|
+
ConfigFetcher: () => ConfigFetcher,
|
|
2212
2574
|
ConfigResolver: () => ConfigResolver,
|
|
2213
2575
|
ConfigValidator: () => ConfigValidator,
|
|
2214
2576
|
ConfigurationException: () => ConfigurationException,
|
|
@@ -2264,6 +2626,7 @@ __export(server_exports, {
|
|
|
2264
2626
|
VisualizationDecisionEngine: () => VisualizationDecisionEngine,
|
|
2265
2627
|
WeaviateProvider: () => WeaviateProvider,
|
|
2266
2628
|
createChatHandler: () => createChatHandler,
|
|
2629
|
+
createDefaultProjectSettings: () => createDefaultProjectSettings,
|
|
2267
2630
|
createFeedbackHandler: () => createFeedbackHandler,
|
|
2268
2631
|
createFromPreset: () => createFromPreset,
|
|
2269
2632
|
createHealthHandler: () => createHealthHandler,
|
|
@@ -2275,6 +2638,8 @@ __export(server_exports, {
|
|
|
2275
2638
|
createUploadHandler: () => createUploadHandler,
|
|
2276
2639
|
decideVisualization: () => decideVisualization,
|
|
2277
2640
|
getRagConfig: () => getRagConfig,
|
|
2641
|
+
normalizeProjectSettings: () => normalizeProjectSettings,
|
|
2642
|
+
projectSettingsToUiConfig: () => projectSettingsToUiConfig,
|
|
2278
2643
|
sseErrorFrame: () => sseErrorFrame,
|
|
2279
2644
|
sseFrame: () => sseFrame,
|
|
2280
2645
|
sseMetaFrame: () => sseMetaFrame,
|
|
@@ -2878,6 +3243,7 @@ var ConfigResolver = class {
|
|
|
2878
3243
|
options: __spreadValues(__spreadValues({}, envConfig.embedding.options || {}), hostConfig.embedding.options || {})
|
|
2879
3244
|
}) : envConfig.embedding,
|
|
2880
3245
|
ui: hostConfig.ui ? mergeDefined(envConfig.ui, hostConfig.ui) : envConfig.ui,
|
|
3246
|
+
projectSettings: hostConfig.projectSettings || envConfig.projectSettings,
|
|
2881
3247
|
rag: hostConfig.rag ? __spreadValues(__spreadValues({}, envConfig.rag), hostConfig.rag) : envConfig.rag,
|
|
2882
3248
|
telemetry: hostConfig.telemetry ? __spreadValues(__spreadValues({}, envConfig.telemetry), hostConfig.telemetry) : envConfig.telemetry
|
|
2883
3249
|
});
|
|
@@ -4819,149 +5185,8 @@ var ConfigValidator = class {
|
|
|
4819
5185
|
}
|
|
4820
5186
|
};
|
|
4821
5187
|
|
|
4822
|
-
//
|
|
4823
|
-
|
|
4824
|
-
name: "@retrivora-ai/rag-engine",
|
|
4825
|
-
version: "2.3.4",
|
|
4826
|
-
description: "Retrivora AI is a plug-and-play AI engine for RAG chat experiences \u2014 generic vector DB + LLM provider, embeddable or standalone.",
|
|
4827
|
-
author: "Abhinav Alkuchi",
|
|
4828
|
-
license: "UNLICENSED",
|
|
4829
|
-
keywords: [
|
|
4830
|
-
"rag",
|
|
4831
|
-
"retrieval-augmented-generation",
|
|
4832
|
-
"chatbot",
|
|
4833
|
-
"vector-database",
|
|
4834
|
-
"pinecone",
|
|
4835
|
-
"pgvector",
|
|
4836
|
-
"postgresql",
|
|
4837
|
-
"milvus",
|
|
4838
|
-
"qdrant",
|
|
4839
|
-
"chromadb",
|
|
4840
|
-
"redis",
|
|
4841
|
-
"weaviate",
|
|
4842
|
-
"mongodb",
|
|
4843
|
-
"openai",
|
|
4844
|
-
"anthropic",
|
|
4845
|
-
"ollama",
|
|
4846
|
-
"nextjs",
|
|
4847
|
-
"react",
|
|
4848
|
-
"ai",
|
|
4849
|
-
"llm",
|
|
4850
|
-
"embeddings"
|
|
4851
|
-
],
|
|
4852
|
-
main: "dist/index.js",
|
|
4853
|
-
module: "dist/index.mjs",
|
|
4854
|
-
types: "dist/index.d.ts",
|
|
4855
|
-
exports: {
|
|
4856
|
-
".": {
|
|
4857
|
-
types: "./dist/index.d.ts",
|
|
4858
|
-
require: "./dist/index.js",
|
|
4859
|
-
import: "./dist/index.mjs"
|
|
4860
|
-
},
|
|
4861
|
-
"./style.css": "./dist/index.css",
|
|
4862
|
-
"./index.css": "./dist/index.css",
|
|
4863
|
-
"./styles.css": "./dist/index.css",
|
|
4864
|
-
"./handlers": {
|
|
4865
|
-
types: "./dist/handlers/index.d.ts",
|
|
4866
|
-
require: "./dist/handlers/index.js",
|
|
4867
|
-
import: "./dist/handlers/index.mjs"
|
|
4868
|
-
},
|
|
4869
|
-
"./server": {
|
|
4870
|
-
types: "./dist/server.d.ts",
|
|
4871
|
-
require: "./dist/server.js",
|
|
4872
|
-
import: "./dist/server.mjs"
|
|
4873
|
-
}
|
|
4874
|
-
},
|
|
4875
|
-
browser: {
|
|
4876
|
-
child_process: false,
|
|
4877
|
-
fs: false,
|
|
4878
|
-
net: false,
|
|
4879
|
-
tls: false,
|
|
4880
|
-
crypto: false,
|
|
4881
|
-
os: false,
|
|
4882
|
-
path: false,
|
|
4883
|
-
stream: false,
|
|
4884
|
-
http: false,
|
|
4885
|
-
https: false,
|
|
4886
|
-
zlib: false,
|
|
4887
|
-
mongodb: false,
|
|
4888
|
-
pg: false,
|
|
4889
|
-
"pdf-parse": false,
|
|
4890
|
-
mammoth: false
|
|
4891
|
-
},
|
|
4892
|
-
files: [
|
|
4893
|
-
"dist",
|
|
4894
|
-
"src",
|
|
4895
|
-
".env.example",
|
|
4896
|
-
"README.md",
|
|
4897
|
-
"FREE_TIER_ARCHITECTURE.md"
|
|
4898
|
-
],
|
|
4899
|
-
scripts: {
|
|
4900
|
-
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",
|
|
4901
|
-
build: "npm run build:pkg",
|
|
4902
|
-
"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",
|
|
4903
|
-
lint: "eslint",
|
|
4904
|
-
typecheck: "tsc --noEmit -p tsconfig.build.json",
|
|
4905
|
-
clean: "rm -rf dist"
|
|
4906
|
-
},
|
|
4907
|
-
peerDependencies: {
|
|
4908
|
-
next: ">=15.0.0",
|
|
4909
|
-
react: ">=18.0.0",
|
|
4910
|
-
"react-dom": ">=18.0.0"
|
|
4911
|
-
},
|
|
4912
|
-
peerDependenciesMeta: {
|
|
4913
|
-
next: {
|
|
4914
|
-
optional: true
|
|
4915
|
-
}
|
|
4916
|
-
},
|
|
4917
|
-
dependencies: {
|
|
4918
|
-
"@anthropic-ai/sdk": "^0.95.1",
|
|
4919
|
-
"@google/genai": "^0.8.0",
|
|
4920
|
-
"@google/generative-ai": "^0.24.1",
|
|
4921
|
-
"@pinecone-database/pinecone": "^7.2.0",
|
|
4922
|
-
"@types/papaparse": "^5.5.2",
|
|
4923
|
-
axios: "^1.15.0",
|
|
4924
|
-
"lucide-react": "^1.8.0",
|
|
4925
|
-
"next-themes": "^0.4.6",
|
|
4926
|
-
openai: "^6.34.0",
|
|
4927
|
-
papaparse: "^5.5.3",
|
|
4928
|
-
"react-is": "^18.3.1",
|
|
4929
|
-
"react-markdown": "^10.1.0",
|
|
4930
|
-
recharts: "^3.8.1",
|
|
4931
|
-
"remark-gfm": "^4.0.1",
|
|
4932
|
-
xlsx: "^0.18.5"
|
|
4933
|
-
},
|
|
4934
|
-
optionalDependencies: {
|
|
4935
|
-
"@langchain/core": "^1.1.42",
|
|
4936
|
-
"@langchain/openai": "^1.4.5",
|
|
4937
|
-
langchain: "^1.3.5",
|
|
4938
|
-
llamaindex: "^0.11.9",
|
|
4939
|
-
mammoth: "^1.8.0",
|
|
4940
|
-
mongodb: "^7.1.1",
|
|
4941
|
-
"pdf-parse": "^1.1.1",
|
|
4942
|
-
pg: "^8.20.0"
|
|
4943
|
-
},
|
|
4944
|
-
devDependencies: {
|
|
4945
|
-
"@tailwindcss/cli": "^4",
|
|
4946
|
-
"@tailwindcss/postcss": "^4",
|
|
4947
|
-
"@types/estree": "^1.0.9",
|
|
4948
|
-
"@types/node": "^20",
|
|
4949
|
-
"@types/pdf-parse": "^1.1.5",
|
|
4950
|
-
"@types/pg": "^8.20.0",
|
|
4951
|
-
"@types/react": "^19.2.14",
|
|
4952
|
-
"@types/react-dom": "^19.2.3",
|
|
4953
|
-
dotenv: "^17.4.2",
|
|
4954
|
-
eslint: "^9",
|
|
4955
|
-
"eslint-config-next": "16.2.4",
|
|
4956
|
-
next: "16.2.10",
|
|
4957
|
-
tailwindcss: "^4",
|
|
4958
|
-
tsup: "^8.5.1",
|
|
4959
|
-
typescript: "^5"
|
|
4960
|
-
}
|
|
4961
|
-
};
|
|
4962
|
-
|
|
4963
|
-
// src/version.ts
|
|
4964
|
-
var SDK_VERSION = package_default.version || "2.1.3";
|
|
5188
|
+
// src/core/Pipeline.ts
|
|
5189
|
+
init_version();
|
|
4965
5190
|
|
|
4966
5191
|
// src/rag/DocumentChunker.ts
|
|
4967
5192
|
var DocumentChunker = class {
|
|
@@ -10197,6 +10422,11 @@ var VectorPlugin = class {
|
|
|
10197
10422
|
}
|
|
10198
10423
|
};
|
|
10199
10424
|
|
|
10425
|
+
// src/server.ts
|
|
10426
|
+
init_version();
|
|
10427
|
+
init_ConfigFetcher();
|
|
10428
|
+
init_ProjectSettings();
|
|
10429
|
+
|
|
10200
10430
|
// src/config/ConfigBuilder.ts
|
|
10201
10431
|
var ConfigBuilder = class {
|
|
10202
10432
|
/**
|
|
@@ -10943,6 +11173,7 @@ var DatabaseStorage = class {
|
|
|
10943
11173
|
};
|
|
10944
11174
|
|
|
10945
11175
|
// src/handlers/index.ts
|
|
11176
|
+
init_version();
|
|
10946
11177
|
async function checkAuth(req, onAuthorize) {
|
|
10947
11178
|
if (!onAuthorize) return null;
|
|
10948
11179
|
try {
|
|
@@ -11052,7 +11283,7 @@ function resolveLicenseKey(req, config, bodyLicenseKey) {
|
|
|
11052
11283
|
function enforceLicense(req, config, bodyLicenseKey) {
|
|
11053
11284
|
const rawKey = resolveLicenseKey(req, config, bodyLicenseKey);
|
|
11054
11285
|
const licenseKey = (rawKey || "").trim().replace(/^["']|["']$/g, "").trim();
|
|
11055
|
-
const projectId = config.projectId || "
|
|
11286
|
+
const projectId = config.projectId || "";
|
|
11056
11287
|
try {
|
|
11057
11288
|
const payload = LicenseVerifier.verify(licenseKey, projectId);
|
|
11058
11289
|
return { ok: true, payload };
|
|
@@ -11074,6 +11305,35 @@ function enforceLicense(req, config, bodyLicenseKey) {
|
|
|
11074
11305
|
};
|
|
11075
11306
|
}
|
|
11076
11307
|
}
|
|
11308
|
+
function getAllowedNamespaces(projectId) {
|
|
11309
|
+
const trimmed = projectId.trim();
|
|
11310
|
+
const withoutPrefix = trimmed.startsWith("retrivora-") ? trimmed.replace(/^retrivora-/, "") : trimmed;
|
|
11311
|
+
return new Set([
|
|
11312
|
+
trimmed,
|
|
11313
|
+
withoutPrefix,
|
|
11314
|
+
`retrivora-${withoutPrefix}`
|
|
11315
|
+
].filter(Boolean));
|
|
11316
|
+
}
|
|
11317
|
+
function resolveLicensedNamespace(payload, requestedNamespace) {
|
|
11318
|
+
const allowed = getAllowedNamespaces(payload.projectId);
|
|
11319
|
+
const requested = requestedNamespace == null ? void 0 : requestedNamespace.trim();
|
|
11320
|
+
if (requested && !allowed.has(requested)) {
|
|
11321
|
+
return {
|
|
11322
|
+
ok: false,
|
|
11323
|
+
response: new Response(JSON.stringify({
|
|
11324
|
+
error: {
|
|
11325
|
+
code: "NAMESPACE_FORBIDDEN",
|
|
11326
|
+
message: "Requested namespace is not authorized for this license."
|
|
11327
|
+
}
|
|
11328
|
+
}), {
|
|
11329
|
+
status: 403,
|
|
11330
|
+
headers: { "Content-Type": "application/json" }
|
|
11331
|
+
})
|
|
11332
|
+
};
|
|
11333
|
+
}
|
|
11334
|
+
const defaultNamespace = payload.projectId.startsWith("retrivora-") ? payload.projectId : `retrivora-${payload.projectId}`;
|
|
11335
|
+
return { ok: true, namespace: requested || defaultNamespace };
|
|
11336
|
+
}
|
|
11077
11337
|
var MAX_MESSAGE_LENGTH = 8e3;
|
|
11078
11338
|
function sanitizeInput(raw) {
|
|
11079
11339
|
const stripped = raw.replace(/[\u0000-\u0008\u000B\u000C\u000E-\u001F\u007F-\u009F]/g, "");
|
|
@@ -11234,6 +11494,8 @@ function createChatHandler(configOrPlugin, options) {
|
|
|
11234
11494
|
}
|
|
11235
11495
|
const history = bodyObj.history || (Array.isArray(bodyObj.messages) ? bodyObj.messages.slice(0, -1) : []);
|
|
11236
11496
|
const { namespace, sessionId = "default", messageId, userMessageId } = bodyObj;
|
|
11497
|
+
const namespaceCheck = resolveLicensedNamespace(licenseCheck.payload, namespace);
|
|
11498
|
+
if (!namespaceCheck.ok) return namespaceCheck.response;
|
|
11237
11499
|
const sanitized = sanitizeInput(rawMessage != null ? rawMessage : "");
|
|
11238
11500
|
if (!sanitized.ok) {
|
|
11239
11501
|
return import_server.NextResponse.json({ error: { code: "INVALID_INPUT", message: sanitized.error } }, { status: 400 });
|
|
@@ -11245,7 +11507,7 @@ function createChatHandler(configOrPlugin, options) {
|
|
|
11245
11507
|
role: "user",
|
|
11246
11508
|
content: message
|
|
11247
11509
|
}).catch((err) => console.warn("[createChatHandler] Failed to save user message:", err));
|
|
11248
|
-
const result = await plugin.chat(message, history, namespace);
|
|
11510
|
+
const result = await plugin.chat(message, history, namespaceCheck.namespace);
|
|
11249
11511
|
const assistantMsgId = messageId || `assistant_${Date.now()}_${Math.random().toString(36).slice(2, 6)}`;
|
|
11250
11512
|
await storage.saveMessage(sessionId, {
|
|
11251
11513
|
id: assistantMsgId,
|
|
@@ -11326,6 +11588,8 @@ function createStreamHandler(configOrPlugin, options) {
|
|
|
11326
11588
|
}
|
|
11327
11589
|
const history = bodyObj.history || (Array.isArray(bodyObj.messages) ? bodyObj.messages.slice(0, -1) : []);
|
|
11328
11590
|
const { namespace, sessionId = "default", messageId, userMessageId } = bodyObj;
|
|
11591
|
+
const namespaceCheck = resolveLicensedNamespace(licenseCheck.payload, namespace);
|
|
11592
|
+
if (!namespaceCheck.ok) return namespaceCheck.response;
|
|
11329
11593
|
const sanitized = sanitizeInput(rawMessage != null ? rawMessage : "");
|
|
11330
11594
|
if (!sanitized.ok) {
|
|
11331
11595
|
return new Response(
|
|
@@ -11355,7 +11619,7 @@ function createStreamHandler(configOrPlugin, options) {
|
|
|
11355
11619
|
}
|
|
11356
11620
|
};
|
|
11357
11621
|
try {
|
|
11358
|
-
const pipelineStream = plugin.chatStream(message, history, namespace);
|
|
11622
|
+
const pipelineStream = plugin.chatStream(message, history, namespaceCheck.namespace);
|
|
11359
11623
|
let fullReply = "";
|
|
11360
11624
|
try {
|
|
11361
11625
|
for (var iter = __forAwait(pipelineStream), more, temp, error; more = !(temp = await iter.next()).done; more = false) {
|
|
@@ -11461,6 +11725,8 @@ function createIngestHandler(configOrPlugin, options) {
|
|
|
11461
11725
|
if (!Array.isArray(documents) || documents.length === 0) {
|
|
11462
11726
|
return import_server.NextResponse.json({ error: "documents array is required" }, { status: 400 });
|
|
11463
11727
|
}
|
|
11728
|
+
const namespaceCheck = resolveLicensedNamespace(licenseCheck.payload, namespace);
|
|
11729
|
+
if (!namespaceCheck.ok) return namespaceCheck.response;
|
|
11464
11730
|
if (isFreeTier(licenseCheck.payload.tier)) {
|
|
11465
11731
|
const totalIncomingBytes = documents.reduce(
|
|
11466
11732
|
(sum, d) => sum + Buffer.byteLength(d.content || "", "utf8"),
|
|
@@ -11482,7 +11748,7 @@ function createIngestHandler(configOrPlugin, options) {
|
|
|
11482
11748
|
);
|
|
11483
11749
|
}
|
|
11484
11750
|
}
|
|
11485
|
-
const results = await plugin.ingest(documents, namespace);
|
|
11751
|
+
const results = await plugin.ingest(documents, namespaceCheck.namespace);
|
|
11486
11752
|
reportTelemetry(req, plugin, "DOCUMENT_INGESTION", "success", `Ingested ${documents.length} document(s)`);
|
|
11487
11753
|
return import_server.NextResponse.json({ results });
|
|
11488
11754
|
} catch (err) {
|
|
@@ -11528,7 +11794,7 @@ function createLicenseHandler(configOrPlugin, options) {
|
|
|
11528
11794
|
const config = plugin.getConfig();
|
|
11529
11795
|
const rawKey = req.headers.get("x-license-key") || (body == null ? void 0 : body.licenseKey) || ((_a3 = req.headers.get("authorization")) == null ? void 0 : _a3.replace(/^Bearer\s+/i, "")) || config.licenseKey || process.env.NEXT_PUBLIC_RETRIVORA_LICENSE_KEY || process.env.RETRIVORA_LICENSE_KEY || "";
|
|
11530
11796
|
const licenseKey = (rawKey || "").trim().replace(/^["']|["']$/g, "").trim();
|
|
11531
|
-
const projectId = (body == null ? void 0 : body.projectId) || config.projectId || "
|
|
11797
|
+
const projectId = (body == null ? void 0 : body.projectId) || config.projectId || "";
|
|
11532
11798
|
const payload = LicenseVerifier.verify(licenseKey, projectId);
|
|
11533
11799
|
return import_server.NextResponse.json({
|
|
11534
11800
|
valid: true,
|
|
@@ -11570,6 +11836,8 @@ function createUploadHandler(configOrPlugin, options) {
|
|
|
11570
11836
|
const namespace = formData.get("namespace") || void 0;
|
|
11571
11837
|
const dimensionRaw = formData.get("dimension");
|
|
11572
11838
|
const dimension = dimensionRaw ? parseInt(dimensionRaw, 10) : void 0;
|
|
11839
|
+
const namespaceCheck = resolveLicensedNamespace(licenseCheck.payload, namespace);
|
|
11840
|
+
if (!namespaceCheck.ok) return namespaceCheck.response;
|
|
11573
11841
|
if (!files || files.length === 0) {
|
|
11574
11842
|
return import_server.NextResponse.json({ error: "No files provided" }, { status: 400 });
|
|
11575
11843
|
}
|
|
@@ -11686,7 +11954,7 @@ function createUploadHandler(configOrPlugin, options) {
|
|
|
11686
11954
|
});
|
|
11687
11955
|
}
|
|
11688
11956
|
}
|
|
11689
|
-
const results = await plugin.ingest(documents, namespace);
|
|
11957
|
+
const results = await plugin.ingest(documents, namespaceCheck.namespace);
|
|
11690
11958
|
reportTelemetry(req, plugin, "DOCUMENT_INGESTION", "success", `Uploaded & ingested ${files.length} file(s)`);
|
|
11691
11959
|
return import_server.NextResponse.json({ message: "Upload successful", results });
|
|
11692
11960
|
} catch (err) {
|
|
@@ -11705,6 +11973,7 @@ function createSuggestionsHandler(configOrPlugin, options) {
|
|
|
11705
11973
|
const config = plugin.getConfig();
|
|
11706
11974
|
const licenseCheck = enforceLicense(req, config);
|
|
11707
11975
|
if (!licenseCheck.ok) return licenseCheck.response;
|
|
11976
|
+
let effectiveLicensePayload = licenseCheck.payload;
|
|
11708
11977
|
try {
|
|
11709
11978
|
let query = "";
|
|
11710
11979
|
let namespace = void 0;
|
|
@@ -11717,6 +11986,7 @@ function createSuggestionsHandler(configOrPlugin, options) {
|
|
|
11717
11986
|
if (bodyLicenseKey) {
|
|
11718
11987
|
const recheck = enforceLicense(req, config, bodyLicenseKey);
|
|
11719
11988
|
if (!recheck.ok) return recheck.response;
|
|
11989
|
+
effectiveLicensePayload = recheck.payload;
|
|
11720
11990
|
}
|
|
11721
11991
|
} else {
|
|
11722
11992
|
const url = new URL(req.url);
|
|
@@ -11726,7 +11996,9 @@ function createSuggestionsHandler(configOrPlugin, options) {
|
|
|
11726
11996
|
if (!query || typeof query !== "string" || !query.trim()) {
|
|
11727
11997
|
return import_server.NextResponse.json({ suggestions: [] });
|
|
11728
11998
|
}
|
|
11729
|
-
const
|
|
11999
|
+
const namespaceCheck = resolveLicensedNamespace(effectiveLicensePayload, namespace);
|
|
12000
|
+
if (!namespaceCheck.ok) return namespaceCheck.response;
|
|
12001
|
+
const suggestions = await plugin.getSuggestions(query, namespaceCheck.namespace);
|
|
11730
12002
|
reportTelemetry(req, plugin, "AUTO_SUGGESTIONS", "success", `Fetched ${suggestions.length} suggestions for: ${query.slice(0, 30)}`);
|
|
11731
12003
|
return import_server.NextResponse.json({ suggestions });
|
|
11732
12004
|
} catch (err) {
|
|
@@ -11943,6 +12215,15 @@ function createRagHandler(configOrPlugin, options) {
|
|
|
11943
12215
|
}
|
|
11944
12216
|
|
|
11945
12217
|
// src/core/LicenseValidator.ts
|
|
12218
|
+
init_version();
|
|
12219
|
+
function canUseLocalValidationFallback(baseUrl, status) {
|
|
12220
|
+
const explicitFallback = typeof process !== "undefined" && process.env.RETRIVORA_ALLOW_LOCAL_LICENSE_FALLBACK === "true";
|
|
12221
|
+
const isLocalSdkRoute = baseUrl.startsWith("/api/retrivora") || baseUrl.includes("/api/retrivora");
|
|
12222
|
+
if (status !== void 0) {
|
|
12223
|
+
return status === 404 && (explicitFallback || isLocalSdkRoute);
|
|
12224
|
+
}
|
|
12225
|
+
return explicitFallback || isLocalSdkRoute;
|
|
12226
|
+
}
|
|
11946
12227
|
var _LicenseValidator = class _LicenseValidator {
|
|
11947
12228
|
// 5-minute TTL for successful validation only
|
|
11948
12229
|
constructor() {
|
|
@@ -12017,7 +12298,7 @@ var _LicenseValidator = class _LicenseValidator {
|
|
|
12017
12298
|
this.cache.delete(effectiveLicenseKey);
|
|
12018
12299
|
}
|
|
12019
12300
|
}
|
|
12020
|
-
const base = retrivoraApiBase || (typeof process !== "undefined" ? process.env.NEXT_PUBLIC_RETRIVORA_API_BASE || process.env.RETRIVORA_API_BASE : "") || "/api
|
|
12301
|
+
const base = retrivoraApiBase || (typeof process !== "undefined" ? process.env.NEXT_PUBLIC_RETRIVORA_API_BASE || process.env.RETRIVORA_API_BASE : "") || "https://www.retrivora.com/api";
|
|
12021
12302
|
const validateUrl = `${base.replace(/\/$/, "")}/v1/license/validate`;
|
|
12022
12303
|
let res = null;
|
|
12023
12304
|
try {
|
|
@@ -12039,7 +12320,10 @@ var _LicenseValidator = class _LicenseValidator {
|
|
|
12039
12320
|
});
|
|
12040
12321
|
} catch (err) {
|
|
12041
12322
|
try {
|
|
12042
|
-
|
|
12323
|
+
if (!canUseLocalValidationFallback(base)) {
|
|
12324
|
+
throw err;
|
|
12325
|
+
}
|
|
12326
|
+
const payload = LicenseVerifier.verify(effectiveLicenseKey, projectId || "");
|
|
12043
12327
|
const fallbackResp = {
|
|
12044
12328
|
valid: true,
|
|
12045
12329
|
licenseStatus: "ACTIVE",
|
|
@@ -12056,9 +12340,9 @@ var _LicenseValidator = class _LicenseValidator {
|
|
|
12056
12340
|
throw new LicenseValidationError(`License validation request failed: ${(err == null ? void 0 : err.message) || "Network error"}`);
|
|
12057
12341
|
}
|
|
12058
12342
|
}
|
|
12059
|
-
if (res && !res.ok) {
|
|
12343
|
+
if (res && !res.ok && canUseLocalValidationFallback(base, res.status)) {
|
|
12060
12344
|
try {
|
|
12061
|
-
const payload = LicenseVerifier.verify(effectiveLicenseKey, projectId || "
|
|
12345
|
+
const payload = LicenseVerifier.verify(effectiveLicenseKey, projectId || "");
|
|
12062
12346
|
const fallbackResp = {
|
|
12063
12347
|
valid: true,
|
|
12064
12348
|
licenseStatus: "ACTIVE",
|
|
@@ -12112,6 +12396,7 @@ var LicenseValidator = _LicenseValidator;
|
|
|
12112
12396
|
ChartRendererStrategy,
|
|
12113
12397
|
ChromaDBProvider,
|
|
12114
12398
|
ConfigBuilder,
|
|
12399
|
+
ConfigFetcher,
|
|
12115
12400
|
ConfigResolver,
|
|
12116
12401
|
ConfigValidator,
|
|
12117
12402
|
ConfigurationException,
|
|
@@ -12167,6 +12452,7 @@ var LicenseValidator = _LicenseValidator;
|
|
|
12167
12452
|
VisualizationDecisionEngine,
|
|
12168
12453
|
WeaviateProvider,
|
|
12169
12454
|
createChatHandler,
|
|
12455
|
+
createDefaultProjectSettings,
|
|
12170
12456
|
createFeedbackHandler,
|
|
12171
12457
|
createFromPreset,
|
|
12172
12458
|
createHealthHandler,
|
|
@@ -12178,6 +12464,8 @@ var LicenseValidator = _LicenseValidator;
|
|
|
12178
12464
|
createUploadHandler,
|
|
12179
12465
|
decideVisualization,
|
|
12180
12466
|
getRagConfig,
|
|
12467
|
+
normalizeProjectSettings,
|
|
12468
|
+
projectSettingsToUiConfig,
|
|
12181
12469
|
sseErrorFrame,
|
|
12182
12470
|
sseFrame,
|
|
12183
12471
|
sseMetaFrame,
|