@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.
Files changed (36) hide show
  1. package/dist/{BatchProcessor-CQDtlggz.d.ts → BatchProcessor-ByBl-1MA.d.ts} +81 -3
  2. package/dist/{BatchProcessor-tVzb9CdE.d.mts → BatchProcessor-Dfn23VAd.d.mts} +81 -3
  3. package/dist/{ILLMProvider-CcJ5N6XD.d.mts → ILLMProvider-B8TAVx3j.d.mts} +63 -1
  4. package/dist/{ILLMProvider-CcJ5N6XD.d.ts → ILLMProvider-B8TAVx3j.d.ts} +63 -1
  5. package/dist/handlers/index.d.mts +2 -2
  6. package/dist/handlers/index.d.ts +2 -2
  7. package/dist/handlers/index.js +373 -155
  8. package/dist/handlers/index.mjs +373 -155
  9. package/dist/{index-BwmyPJHp.d.ts → index-ejOWsaqb.d.ts} +1 -1
  10. package/dist/{index-CL-zF6bD.d.mts → index-xxQOFx-u.d.mts} +1 -1
  11. package/dist/index.css +9 -0
  12. package/dist/index.d.mts +19 -5
  13. package/dist/index.d.ts +19 -5
  14. package/dist/index.js +636 -200
  15. package/dist/index.mjs +676 -245
  16. package/dist/server.d.mts +6 -6
  17. package/dist/server.d.ts +6 -6
  18. package/dist/server.js +413 -166
  19. package/dist/server.mjs +409 -166
  20. package/package.json +1 -1
  21. package/src/components/ChatWidget.tsx +44 -19
  22. package/src/components/ChatWindow.tsx +30 -14
  23. package/src/components/ConfigProvider.tsx +86 -6
  24. package/src/components/DocumentUpload.tsx +8 -2
  25. package/src/config/RagConfig.ts +4 -0
  26. package/src/core/ConfigFetcher.ts +10 -1
  27. package/src/core/ConfigResolver.ts +1 -0
  28. package/src/core/LicenseValidator.ts +21 -12
  29. package/src/core/LicenseVerifier.ts +0 -4
  30. package/src/core/ProjectSettings.ts +247 -0
  31. package/src/handlers/index.ts +61 -5
  32. package/src/hooks/useProjectSettings.ts +105 -0
  33. package/src/index.css +9 -0
  34. package/src/index.ts +28 -0
  35. package/src/server.ts +23 -1
  36. package/src/types/props.ts +14 -2
package/dist/server.js CHANGED
@@ -154,11 +154,339 @@ 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
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();
162
490
  CONTROL_PLANE_URL = "https://www.retrivora.com";
163
491
  LLM_PROXY_BASE_URL = "https://www.retrivora.com/api/v1";
164
492
  ConfigFetcher = class {
@@ -191,11 +519,12 @@ var init_ConfigFetcher = __esm({
191
519
  ].filter((url) => Boolean(url) && !url.includes("localhost") && !url.includes("127.0.0.1")).map((url) => url.replace(/\/$/, ""));
192
520
  for (const baseUrl of controlPlaneUrls) {
193
521
  try {
194
- const url = `${baseUrl}/api/v1/config?projectId=${encodeURIComponent(projectId)}${licenseKey ? `&licenseKey=${encodeURIComponent(licenseKey)}` : ""}`;
522
+ const url = `${baseUrl}/api/v1/config?projectId=${encodeURIComponent(projectId)}`;
195
523
  const res = await fetch(url, {
196
524
  method: "GET",
197
525
  headers: __spreadValues({
198
- "Content-Type": "application/json"
526
+ "Content-Type": "application/json",
527
+ "x-sdk-version": SDK_VERSION
199
528
  }, licenseKey ? { "x-license-key": licenseKey } : {})
200
529
  });
201
530
  if (res.ok) {
@@ -235,7 +564,11 @@ var init_ConfigFetcher = __esm({
235
564
  workspace: data.workspace || {
236
565
  namespace: fetchedProjectId,
237
566
  indexName: data.vectorDb.indexName || "retrivora-free"
238
- }
567
+ },
568
+ projectSettings: normalizeProjectSettings(
569
+ fetchedProjectId,
570
+ data.projectSettings || data.settings
571
+ )
239
572
  };
240
573
  this.cache.set(cacheKey, { config, cachedAt: now });
241
574
  return config;
@@ -2237,6 +2570,7 @@ __export(server_exports, {
2237
2570
  ChartRendererStrategy: () => ChartRendererStrategy,
2238
2571
  ChromaDBProvider: () => ChromaDBProvider,
2239
2572
  ConfigBuilder: () => ConfigBuilder,
2573
+ ConfigFetcher: () => ConfigFetcher,
2240
2574
  ConfigResolver: () => ConfigResolver,
2241
2575
  ConfigValidator: () => ConfigValidator,
2242
2576
  ConfigurationException: () => ConfigurationException,
@@ -2292,6 +2626,7 @@ __export(server_exports, {
2292
2626
  VisualizationDecisionEngine: () => VisualizationDecisionEngine,
2293
2627
  WeaviateProvider: () => WeaviateProvider,
2294
2628
  createChatHandler: () => createChatHandler,
2629
+ createDefaultProjectSettings: () => createDefaultProjectSettings,
2295
2630
  createFeedbackHandler: () => createFeedbackHandler,
2296
2631
  createFromPreset: () => createFromPreset,
2297
2632
  createHealthHandler: () => createHealthHandler,
@@ -2303,6 +2638,8 @@ __export(server_exports, {
2303
2638
  createUploadHandler: () => createUploadHandler,
2304
2639
  decideVisualization: () => decideVisualization,
2305
2640
  getRagConfig: () => getRagConfig,
2641
+ normalizeProjectSettings: () => normalizeProjectSettings,
2642
+ projectSettingsToUiConfig: () => projectSettingsToUiConfig,
2306
2643
  sseErrorFrame: () => sseErrorFrame,
2307
2644
  sseFrame: () => sseFrame,
2308
2645
  sseMetaFrame: () => sseMetaFrame,
@@ -2413,10 +2750,6 @@ var LicenseVerifier = class {
2413
2750
  static verify(licenseKey, currentProjectId, provider, publicKeyOverride) {
2414
2751
  const isProduction = process.env.NODE_ENV === "production";
2415
2752
  const now = Date.now();
2416
- console.log(`[Retrivora SDK] LicenseVerifier.verify() - licenseKey`, licenseKey);
2417
- console.log(`[Retrivora SDK] LicenseVerifier.verify() - currentProjectId`, currentProjectId);
2418
- console.log(`[Retrivora SDK] LicenseVerifier.verify() - provider`, provider);
2419
- console.log(`[Retrivora SDK] LicenseVerifier.verify() - publicKeyOverride`, publicKeyOverride);
2420
2753
  if (licenseKey) {
2421
2754
  const cacheKey = `${licenseKey}:${currentProjectId}:${provider || ""}:${publicKeyOverride || ""}`;
2422
2755
  const cached = this.cache.get(cacheKey);
@@ -2910,6 +3243,7 @@ var ConfigResolver = class {
2910
3243
  options: __spreadValues(__spreadValues({}, envConfig.embedding.options || {}), hostConfig.embedding.options || {})
2911
3244
  }) : envConfig.embedding,
2912
3245
  ui: hostConfig.ui ? mergeDefined(envConfig.ui, hostConfig.ui) : envConfig.ui,
3246
+ projectSettings: hostConfig.projectSettings || envConfig.projectSettings,
2913
3247
  rag: hostConfig.rag ? __spreadValues(__spreadValues({}, envConfig.rag), hostConfig.rag) : envConfig.rag,
2914
3248
  telemetry: hostConfig.telemetry ? __spreadValues(__spreadValues({}, envConfig.telemetry), hostConfig.telemetry) : envConfig.telemetry
2915
3249
  });
@@ -4851,149 +5185,8 @@ var ConfigValidator = class {
4851
5185
  }
4852
5186
  };
4853
5187
 
4854
- // package.json
4855
- var package_default = {
4856
- name: "@retrivora-ai/rag-engine",
4857
- version: "2.3.5",
4858
- description: "Retrivora AI is a plug-and-play AI engine for RAG chat experiences \u2014 generic vector DB + LLM provider, embeddable or standalone.",
4859
- author: "Abhinav Alkuchi",
4860
- license: "UNLICENSED",
4861
- keywords: [
4862
- "rag",
4863
- "retrieval-augmented-generation",
4864
- "chatbot",
4865
- "vector-database",
4866
- "pinecone",
4867
- "pgvector",
4868
- "postgresql",
4869
- "milvus",
4870
- "qdrant",
4871
- "chromadb",
4872
- "redis",
4873
- "weaviate",
4874
- "mongodb",
4875
- "openai",
4876
- "anthropic",
4877
- "ollama",
4878
- "nextjs",
4879
- "react",
4880
- "ai",
4881
- "llm",
4882
- "embeddings"
4883
- ],
4884
- main: "dist/index.js",
4885
- module: "dist/index.mjs",
4886
- types: "dist/index.d.ts",
4887
- exports: {
4888
- ".": {
4889
- types: "./dist/index.d.ts",
4890
- require: "./dist/index.js",
4891
- import: "./dist/index.mjs"
4892
- },
4893
- "./style.css": "./dist/index.css",
4894
- "./index.css": "./dist/index.css",
4895
- "./styles.css": "./dist/index.css",
4896
- "./handlers": {
4897
- types: "./dist/handlers/index.d.ts",
4898
- require: "./dist/handlers/index.js",
4899
- import: "./dist/handlers/index.mjs"
4900
- },
4901
- "./server": {
4902
- types: "./dist/server.d.ts",
4903
- require: "./dist/server.js",
4904
- import: "./dist/server.mjs"
4905
- }
4906
- },
4907
- browser: {
4908
- child_process: false,
4909
- fs: false,
4910
- net: false,
4911
- tls: false,
4912
- crypto: false,
4913
- os: false,
4914
- path: false,
4915
- stream: false,
4916
- http: false,
4917
- https: false,
4918
- zlib: false,
4919
- mongodb: false,
4920
- pg: false,
4921
- "pdf-parse": false,
4922
- mammoth: false
4923
- },
4924
- files: [
4925
- "dist",
4926
- "src",
4927
- ".env.example",
4928
- "README.md",
4929
- "FREE_TIER_ARCHITECTURE.md"
4930
- ],
4931
- scripts: {
4932
- 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",
4933
- build: "npm run build:pkg",
4934
- "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",
4935
- lint: "eslint",
4936
- typecheck: "tsc --noEmit -p tsconfig.build.json",
4937
- clean: "rm -rf dist"
4938
- },
4939
- peerDependencies: {
4940
- next: ">=15.0.0",
4941
- react: ">=18.0.0",
4942
- "react-dom": ">=18.0.0"
4943
- },
4944
- peerDependenciesMeta: {
4945
- next: {
4946
- optional: true
4947
- }
4948
- },
4949
- dependencies: {
4950
- "@anthropic-ai/sdk": "^0.95.1",
4951
- "@google/genai": "^0.8.0",
4952
- "@google/generative-ai": "^0.24.1",
4953
- "@pinecone-database/pinecone": "^7.2.0",
4954
- "@types/papaparse": "^5.5.2",
4955
- axios: "^1.15.0",
4956
- "lucide-react": "^1.8.0",
4957
- "next-themes": "^0.4.6",
4958
- openai: "^6.34.0",
4959
- papaparse: "^5.5.3",
4960
- "react-is": "^18.3.1",
4961
- "react-markdown": "^10.1.0",
4962
- recharts: "^3.8.1",
4963
- "remark-gfm": "^4.0.1",
4964
- xlsx: "^0.18.5"
4965
- },
4966
- optionalDependencies: {
4967
- "@langchain/core": "^1.1.42",
4968
- "@langchain/openai": "^1.4.5",
4969
- langchain: "^1.3.5",
4970
- llamaindex: "^0.11.9",
4971
- mammoth: "^1.8.0",
4972
- mongodb: "^7.1.1",
4973
- "pdf-parse": "^1.1.1",
4974
- pg: "^8.20.0"
4975
- },
4976
- devDependencies: {
4977
- "@tailwindcss/cli": "^4",
4978
- "@tailwindcss/postcss": "^4",
4979
- "@types/estree": "^1.0.9",
4980
- "@types/node": "^20",
4981
- "@types/pdf-parse": "^1.1.5",
4982
- "@types/pg": "^8.20.0",
4983
- "@types/react": "^19.2.14",
4984
- "@types/react-dom": "^19.2.3",
4985
- dotenv: "^17.4.2",
4986
- eslint: "^9",
4987
- "eslint-config-next": "16.2.4",
4988
- next: "16.2.10",
4989
- tailwindcss: "^4",
4990
- tsup: "^8.5.1",
4991
- typescript: "^5"
4992
- }
4993
- };
4994
-
4995
- // src/version.ts
4996
- var SDK_VERSION = package_default.version || "2.1.3";
5188
+ // src/core/Pipeline.ts
5189
+ init_version();
4997
5190
 
4998
5191
  // src/rag/DocumentChunker.ts
4999
5192
  var DocumentChunker = class {
@@ -10229,6 +10422,11 @@ var VectorPlugin = class {
10229
10422
  }
10230
10423
  };
10231
10424
 
10425
+ // src/server.ts
10426
+ init_version();
10427
+ init_ConfigFetcher();
10428
+ init_ProjectSettings();
10429
+
10232
10430
  // src/config/ConfigBuilder.ts
10233
10431
  var ConfigBuilder = class {
10234
10432
  /**
@@ -10975,6 +11173,7 @@ var DatabaseStorage = class {
10975
11173
  };
10976
11174
 
10977
11175
  // src/handlers/index.ts
11176
+ init_version();
10978
11177
  async function checkAuth(req, onAuthorize) {
10979
11178
  if (!onAuthorize) return null;
10980
11179
  try {
@@ -11106,6 +11305,35 @@ function enforceLicense(req, config, bodyLicenseKey) {
11106
11305
  };
11107
11306
  }
11108
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
+ }
11109
11337
  var MAX_MESSAGE_LENGTH = 8e3;
11110
11338
  function sanitizeInput(raw) {
11111
11339
  const stripped = raw.replace(/[\u0000-\u0008\u000B\u000C\u000E-\u001F\u007F-\u009F]/g, "");
@@ -11266,6 +11494,8 @@ function createChatHandler(configOrPlugin, options) {
11266
11494
  }
11267
11495
  const history = bodyObj.history || (Array.isArray(bodyObj.messages) ? bodyObj.messages.slice(0, -1) : []);
11268
11496
  const { namespace, sessionId = "default", messageId, userMessageId } = bodyObj;
11497
+ const namespaceCheck = resolveLicensedNamespace(licenseCheck.payload, namespace);
11498
+ if (!namespaceCheck.ok) return namespaceCheck.response;
11269
11499
  const sanitized = sanitizeInput(rawMessage != null ? rawMessage : "");
11270
11500
  if (!sanitized.ok) {
11271
11501
  return import_server.NextResponse.json({ error: { code: "INVALID_INPUT", message: sanitized.error } }, { status: 400 });
@@ -11277,7 +11507,7 @@ function createChatHandler(configOrPlugin, options) {
11277
11507
  role: "user",
11278
11508
  content: message
11279
11509
  }).catch((err) => console.warn("[createChatHandler] Failed to save user message:", err));
11280
- const result = await plugin.chat(message, history, namespace);
11510
+ const result = await plugin.chat(message, history, namespaceCheck.namespace);
11281
11511
  const assistantMsgId = messageId || `assistant_${Date.now()}_${Math.random().toString(36).slice(2, 6)}`;
11282
11512
  await storage.saveMessage(sessionId, {
11283
11513
  id: assistantMsgId,
@@ -11358,6 +11588,8 @@ function createStreamHandler(configOrPlugin, options) {
11358
11588
  }
11359
11589
  const history = bodyObj.history || (Array.isArray(bodyObj.messages) ? bodyObj.messages.slice(0, -1) : []);
11360
11590
  const { namespace, sessionId = "default", messageId, userMessageId } = bodyObj;
11591
+ const namespaceCheck = resolveLicensedNamespace(licenseCheck.payload, namespace);
11592
+ if (!namespaceCheck.ok) return namespaceCheck.response;
11361
11593
  const sanitized = sanitizeInput(rawMessage != null ? rawMessage : "");
11362
11594
  if (!sanitized.ok) {
11363
11595
  return new Response(
@@ -11387,7 +11619,7 @@ function createStreamHandler(configOrPlugin, options) {
11387
11619
  }
11388
11620
  };
11389
11621
  try {
11390
- const pipelineStream = plugin.chatStream(message, history, namespace);
11622
+ const pipelineStream = plugin.chatStream(message, history, namespaceCheck.namespace);
11391
11623
  let fullReply = "";
11392
11624
  try {
11393
11625
  for (var iter = __forAwait(pipelineStream), more, temp, error; more = !(temp = await iter.next()).done; more = false) {
@@ -11493,6 +11725,8 @@ function createIngestHandler(configOrPlugin, options) {
11493
11725
  if (!Array.isArray(documents) || documents.length === 0) {
11494
11726
  return import_server.NextResponse.json({ error: "documents array is required" }, { status: 400 });
11495
11727
  }
11728
+ const namespaceCheck = resolveLicensedNamespace(licenseCheck.payload, namespace);
11729
+ if (!namespaceCheck.ok) return namespaceCheck.response;
11496
11730
  if (isFreeTier(licenseCheck.payload.tier)) {
11497
11731
  const totalIncomingBytes = documents.reduce(
11498
11732
  (sum, d) => sum + Buffer.byteLength(d.content || "", "utf8"),
@@ -11514,7 +11748,7 @@ function createIngestHandler(configOrPlugin, options) {
11514
11748
  );
11515
11749
  }
11516
11750
  }
11517
- const results = await plugin.ingest(documents, namespace);
11751
+ const results = await plugin.ingest(documents, namespaceCheck.namespace);
11518
11752
  reportTelemetry(req, plugin, "DOCUMENT_INGESTION", "success", `Ingested ${documents.length} document(s)`);
11519
11753
  return import_server.NextResponse.json({ results });
11520
11754
  } catch (err) {
@@ -11602,6 +11836,8 @@ function createUploadHandler(configOrPlugin, options) {
11602
11836
  const namespace = formData.get("namespace") || void 0;
11603
11837
  const dimensionRaw = formData.get("dimension");
11604
11838
  const dimension = dimensionRaw ? parseInt(dimensionRaw, 10) : void 0;
11839
+ const namespaceCheck = resolveLicensedNamespace(licenseCheck.payload, namespace);
11840
+ if (!namespaceCheck.ok) return namespaceCheck.response;
11605
11841
  if (!files || files.length === 0) {
11606
11842
  return import_server.NextResponse.json({ error: "No files provided" }, { status: 400 });
11607
11843
  }
@@ -11718,7 +11954,7 @@ function createUploadHandler(configOrPlugin, options) {
11718
11954
  });
11719
11955
  }
11720
11956
  }
11721
- const results = await plugin.ingest(documents, namespace);
11957
+ const results = await plugin.ingest(documents, namespaceCheck.namespace);
11722
11958
  reportTelemetry(req, plugin, "DOCUMENT_INGESTION", "success", `Uploaded & ingested ${files.length} file(s)`);
11723
11959
  return import_server.NextResponse.json({ message: "Upload successful", results });
11724
11960
  } catch (err) {
@@ -11737,6 +11973,7 @@ function createSuggestionsHandler(configOrPlugin, options) {
11737
11973
  const config = plugin.getConfig();
11738
11974
  const licenseCheck = enforceLicense(req, config);
11739
11975
  if (!licenseCheck.ok) return licenseCheck.response;
11976
+ let effectiveLicensePayload = licenseCheck.payload;
11740
11977
  try {
11741
11978
  let query = "";
11742
11979
  let namespace = void 0;
@@ -11749,6 +11986,7 @@ function createSuggestionsHandler(configOrPlugin, options) {
11749
11986
  if (bodyLicenseKey) {
11750
11987
  const recheck = enforceLicense(req, config, bodyLicenseKey);
11751
11988
  if (!recheck.ok) return recheck.response;
11989
+ effectiveLicensePayload = recheck.payload;
11752
11990
  }
11753
11991
  } else {
11754
11992
  const url = new URL(req.url);
@@ -11758,7 +11996,9 @@ function createSuggestionsHandler(configOrPlugin, options) {
11758
11996
  if (!query || typeof query !== "string" || !query.trim()) {
11759
11997
  return import_server.NextResponse.json({ suggestions: [] });
11760
11998
  }
11761
- const suggestions = await plugin.getSuggestions(query, namespace);
11999
+ const namespaceCheck = resolveLicensedNamespace(effectiveLicensePayload, namespace);
12000
+ if (!namespaceCheck.ok) return namespaceCheck.response;
12001
+ const suggestions = await plugin.getSuggestions(query, namespaceCheck.namespace);
11762
12002
  reportTelemetry(req, plugin, "AUTO_SUGGESTIONS", "success", `Fetched ${suggestions.length} suggestions for: ${query.slice(0, 30)}`);
11763
12003
  return import_server.NextResponse.json({ suggestions });
11764
12004
  } catch (err) {
@@ -11975,6 +12215,15 @@ function createRagHandler(configOrPlugin, options) {
11975
12215
  }
11976
12216
 
11977
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
+ }
11978
12227
  var _LicenseValidator = class _LicenseValidator {
11979
12228
  // 5-minute TTL for successful validation only
11980
12229
  constructor() {
@@ -12034,17 +12283,8 @@ var _LicenseValidator = class _LicenseValidator {
12034
12283
  }
12035
12284
  return void 0;
12036
12285
  };
12037
- console.log("LicenseValidator.validate()", request);
12038
- console.log("LicenseValidator.validate() - licenseKey", licenseKey);
12039
- console.log("LicenseValidator.validate() - projectId", projectId);
12040
- console.log("LicenseValidator.validate() - sdkVersion", sdkVersion);
12041
- console.log("LicenseValidator.validate() - sdk", sdk);
12042
- console.log("LicenseValidator.validate() - platform", platform);
12043
- console.log("LicenseValidator.validate() - retrivoraApiBase", retrivoraApiBase);
12044
- console.log("LicenseValidator.validate() - customHeaders", customHeaders);
12045
12286
  const rawKey = licenseKey || getHeader("x-license-key") || ((_a3 = getHeader("authorization")) == null ? void 0 : _a3.replace(/^Bearer\s+/i, "")) || (typeof process !== "undefined" ? process.env.NEXT_PUBLIC_RETRIVORA_LICENSE_KEY || process.env.RETRIVORA_LICENSE_KEY : "") || "";
12046
12287
  const effectiveLicenseKey = (rawKey || "").trim().replace(/^["']|["']$/g, "").trim();
12047
- console.log("LicenseValidator.validate() - effectiveLicenseKey", effectiveLicenseKey);
12048
12288
  if (!effectiveLicenseKey) {
12049
12289
  this.purgeCache(effectiveLicenseKey);
12050
12290
  throw new LicenseValidationError("Missing RETRIVORA_LICENSE_KEY in request. Set NEXT_PUBLIC_RETRIVORA_LICENSE_KEY in your environment or pass licenseKey as a prop.");
@@ -12058,7 +12298,7 @@ var _LicenseValidator = class _LicenseValidator {
12058
12298
  this.cache.delete(effectiveLicenseKey);
12059
12299
  }
12060
12300
  }
12061
- const base = retrivoraApiBase || (typeof process !== "undefined" ? process.env.NEXT_PUBLIC_RETRIVORA_API_BASE || process.env.RETRIVORA_API_BASE : "") || "/api/retrivora";
12301
+ const base = retrivoraApiBase || (typeof process !== "undefined" ? process.env.NEXT_PUBLIC_RETRIVORA_API_BASE || process.env.RETRIVORA_API_BASE : "") || "https://www.retrivora.com/api";
12062
12302
  const validateUrl = `${base.replace(/\/$/, "")}/v1/license/validate`;
12063
12303
  let res = null;
12064
12304
  try {
@@ -12080,6 +12320,9 @@ var _LicenseValidator = class _LicenseValidator {
12080
12320
  });
12081
12321
  } catch (err) {
12082
12322
  try {
12323
+ if (!canUseLocalValidationFallback(base)) {
12324
+ throw err;
12325
+ }
12083
12326
  const payload = LicenseVerifier.verify(effectiveLicenseKey, projectId || "");
12084
12327
  const fallbackResp = {
12085
12328
  valid: true,
@@ -12097,7 +12340,7 @@ var _LicenseValidator = class _LicenseValidator {
12097
12340
  throw new LicenseValidationError(`License validation request failed: ${(err == null ? void 0 : err.message) || "Network error"}`);
12098
12341
  }
12099
12342
  }
12100
- if (res && !res.ok) {
12343
+ if (res && !res.ok && canUseLocalValidationFallback(base, res.status)) {
12101
12344
  try {
12102
12345
  const payload = LicenseVerifier.verify(effectiveLicenseKey, projectId || "");
12103
12346
  const fallbackResp = {
@@ -12153,6 +12396,7 @@ var LicenseValidator = _LicenseValidator;
12153
12396
  ChartRendererStrategy,
12154
12397
  ChromaDBProvider,
12155
12398
  ConfigBuilder,
12399
+ ConfigFetcher,
12156
12400
  ConfigResolver,
12157
12401
  ConfigValidator,
12158
12402
  ConfigurationException,
@@ -12208,6 +12452,7 @@ var LicenseValidator = _LicenseValidator;
12208
12452
  VisualizationDecisionEngine,
12209
12453
  WeaviateProvider,
12210
12454
  createChatHandler,
12455
+ createDefaultProjectSettings,
12211
12456
  createFeedbackHandler,
12212
12457
  createFromPreset,
12213
12458
  createHealthHandler,
@@ -12219,6 +12464,8 @@ var LicenseValidator = _LicenseValidator;
12219
12464
  createUploadHandler,
12220
12465
  decideVisualization,
12221
12466
  getRagConfig,
12467
+ normalizeProjectSettings,
12468
+ projectSettingsToUiConfig,
12222
12469
  sseErrorFrame,
12223
12470
  sseFrame,
12224
12471
  sseMetaFrame,