@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.mjs CHANGED
@@ -139,11 +139,339 @@ var init_BaseVectorProvider = __esm({
139
139
  }
140
140
  });
141
141
 
142
+ // src/core/ProjectSettings.ts
143
+ function createDefaultProjectSettings(projectId) {
144
+ return {
145
+ projectId,
146
+ branding: {
147
+ companyName: "Retrivora AI",
148
+ botName: "Retrivora Assistant",
149
+ welcomeMessage: "Hi, I can help you search your knowledge base.",
150
+ primaryColor: "#6366f1",
151
+ secondaryColor: "#8b5cf6",
152
+ fontFamily: "Inter",
153
+ borderRadius: 14,
154
+ logoUrl: "",
155
+ avatarUrl: "",
156
+ customCss: ""
157
+ },
158
+ ai: {
159
+ defaultModel: "llama-3.1-8b-instant",
160
+ embeddingModel: "text-embedding-3-small",
161
+ systemPrompt: "Answer using the connected knowledge base. Cite sources when available.",
162
+ memoryEnabled: true,
163
+ multiModelEnabled: true,
164
+ citationsEnabled: true,
165
+ fileUploadEnabled: true
166
+ },
167
+ auth: {
168
+ mode: "public",
169
+ allowedOrigins: [],
170
+ requireVerifiedEmail: false,
171
+ sessionTtlMinutes: 1440
172
+ },
173
+ widget: {
174
+ position: "bottom-right",
175
+ theme: "light",
176
+ lazyLoad: true,
177
+ autoReconnect: true,
178
+ persistConversations: true,
179
+ showRetrivoraBranding: false
180
+ },
181
+ telemetry: {
182
+ enabled: true,
183
+ collectBrowser: true,
184
+ collectCountry: false,
185
+ redactPii: true,
186
+ retentionDays: 30
187
+ },
188
+ lifecycleHooks: DEFAULT_LIFECYCLE_HOOKS,
189
+ conversationFeatures: DEFAULT_CONVERSATION_FEATURES
190
+ };
191
+ }
192
+ function cleanString(value, fallback, maxLength = 2e3) {
193
+ if (typeof value !== "string") return fallback;
194
+ return value.trim().slice(0, maxLength);
195
+ }
196
+ function cleanBoolean(value, fallback) {
197
+ return typeof value === "boolean" ? value : fallback;
198
+ }
199
+ function cleanNumber(value, fallback, min, max) {
200
+ const num = typeof value === "number" ? value : Number(value);
201
+ if (!Number.isFinite(num)) return fallback;
202
+ return Math.min(Math.max(Math.round(num), min), max);
203
+ }
204
+ function cleanEnum(value, fallback, allowed) {
205
+ return typeof value === "string" && allowed.includes(value) ? value : fallback;
206
+ }
207
+ function cleanStringList(value, fallback, maxItems = 20) {
208
+ if (!Array.isArray(value)) return fallback;
209
+ const cleaned = value.filter((item) => typeof item === "string").map((item) => item.trim()).filter(Boolean).slice(0, maxItems);
210
+ return cleaned.length > 0 ? Array.from(new Set(cleaned)) : fallback;
211
+ }
212
+ function normalizeProjectSettings(projectId, input) {
213
+ const defaults = createDefaultProjectSettings(projectId);
214
+ const branding = (input == null ? void 0 : input.branding) || {};
215
+ const ai = (input == null ? void 0 : input.ai) || {};
216
+ const auth = (input == null ? void 0 : input.auth) || {};
217
+ const widget = (input == null ? void 0 : input.widget) || {};
218
+ const telemetry = (input == null ? void 0 : input.telemetry) || {};
219
+ return {
220
+ projectId,
221
+ branding: {
222
+ companyName: cleanString(branding.companyName, defaults.branding.companyName, 120),
223
+ botName: cleanString(branding.botName, defaults.branding.botName, 120),
224
+ welcomeMessage: cleanString(branding.welcomeMessage, defaults.branding.welcomeMessage, 500),
225
+ primaryColor: cleanString(branding.primaryColor, defaults.branding.primaryColor, 32),
226
+ secondaryColor: cleanString(branding.secondaryColor, defaults.branding.secondaryColor, 32),
227
+ fontFamily: cleanString(branding.fontFamily, defaults.branding.fontFamily, 80),
228
+ borderRadius: cleanNumber(branding.borderRadius, defaults.branding.borderRadius, 0, 32),
229
+ logoUrl: cleanString(branding.logoUrl, defaults.branding.logoUrl, 500),
230
+ avatarUrl: cleanString(branding.avatarUrl, defaults.branding.avatarUrl, 500),
231
+ customCss: cleanString(branding.customCss, defaults.branding.customCss, 5e3)
232
+ },
233
+ ai: {
234
+ defaultModel: cleanString(ai.defaultModel, defaults.ai.defaultModel, 120),
235
+ embeddingModel: cleanString(ai.embeddingModel, defaults.ai.embeddingModel, 120),
236
+ systemPrompt: cleanString(ai.systemPrompt, defaults.ai.systemPrompt, 5e3),
237
+ memoryEnabled: cleanBoolean(ai.memoryEnabled, defaults.ai.memoryEnabled),
238
+ multiModelEnabled: cleanBoolean(ai.multiModelEnabled, defaults.ai.multiModelEnabled),
239
+ citationsEnabled: cleanBoolean(ai.citationsEnabled, defaults.ai.citationsEnabled),
240
+ fileUploadEnabled: cleanBoolean(ai.fileUploadEnabled, defaults.ai.fileUploadEnabled)
241
+ },
242
+ auth: {
243
+ mode: cleanEnum(auth.mode, defaults.auth.mode, ["public", "anonymous", "jwt", "oauth", "okta", "auth0", "supabase", "firebase", "sso", "custom_token"]),
244
+ allowedOrigins: cleanStringList(auth.allowedOrigins, defaults.auth.allowedOrigins, 25),
245
+ requireVerifiedEmail: cleanBoolean(auth.requireVerifiedEmail, defaults.auth.requireVerifiedEmail),
246
+ sessionTtlMinutes: cleanNumber(auth.sessionTtlMinutes, defaults.auth.sessionTtlMinutes, 15, 43200)
247
+ },
248
+ widget: {
249
+ position: cleanEnum(widget.position, defaults.widget.position, ["bottom-right", "bottom-left", "top-right", "top-left"]),
250
+ theme: cleanEnum(widget.theme, defaults.widget.theme, ["light", "dark", "system"]),
251
+ lazyLoad: cleanBoolean(widget.lazyLoad, defaults.widget.lazyLoad),
252
+ autoReconnect: cleanBoolean(widget.autoReconnect, defaults.widget.autoReconnect),
253
+ persistConversations: cleanBoolean(widget.persistConversations, defaults.widget.persistConversations),
254
+ showRetrivoraBranding: cleanBoolean(widget.showRetrivoraBranding, defaults.widget.showRetrivoraBranding)
255
+ },
256
+ telemetry: {
257
+ enabled: cleanBoolean(telemetry.enabled, defaults.telemetry.enabled),
258
+ collectBrowser: cleanBoolean(telemetry.collectBrowser, defaults.telemetry.collectBrowser),
259
+ collectCountry: cleanBoolean(telemetry.collectCountry, defaults.telemetry.collectCountry),
260
+ redactPii: cleanBoolean(telemetry.redactPii, defaults.telemetry.redactPii),
261
+ retentionDays: cleanNumber(telemetry.retentionDays, defaults.telemetry.retentionDays, 1, 365)
262
+ },
263
+ lifecycleHooks: cleanStringList(input == null ? void 0 : input.lifecycleHooks, defaults.lifecycleHooks, 30),
264
+ conversationFeatures: cleanStringList(input == null ? void 0 : input.conversationFeatures, defaults.conversationFeatures, 30),
265
+ updatedAt: input == null ? void 0 : input.updatedAt
266
+ };
267
+ }
268
+ function projectSettingsToUiConfig(settings) {
269
+ return {
270
+ title: settings.branding.botName,
271
+ subtitle: settings.branding.companyName,
272
+ primaryColor: settings.branding.primaryColor,
273
+ accentColor: settings.branding.secondaryColor,
274
+ logoUrl: settings.branding.logoUrl || settings.branding.avatarUrl,
275
+ welcomeMessage: settings.branding.welcomeMessage,
276
+ poweredBy: settings.widget.showRetrivoraBranding ? "Retrivora AI" : "",
277
+ allowUpload: settings.ai.fileUploadEnabled,
278
+ borderRadius: settings.branding.borderRadius <= 4 ? "sm" : settings.branding.borderRadius <= 8 ? "md" : settings.branding.borderRadius <= 16 ? "xl" : "full"
279
+ };
280
+ }
281
+ var DEFAULT_LIFECYCLE_HOOKS, DEFAULT_CONVERSATION_FEATURES;
282
+ var init_ProjectSettings = __esm({
283
+ "src/core/ProjectSettings.ts"() {
284
+ "use strict";
285
+ DEFAULT_LIFECYCLE_HOOKS = [
286
+ "beforeInitialize",
287
+ "afterInitialize",
288
+ "beforeSend",
289
+ "afterResponse",
290
+ "onMessage",
291
+ "onCitationClick",
292
+ "onFeedback",
293
+ "onError",
294
+ "onReconnect",
295
+ "onFileUpload"
296
+ ];
297
+ DEFAULT_CONVERSATION_FEATURES = [
298
+ "History",
299
+ "Resume",
300
+ "Search",
301
+ "Export",
302
+ "Rename",
303
+ "Delete",
304
+ "Tags",
305
+ "Pinned",
306
+ "Unread",
307
+ "Ratings"
308
+ ];
309
+ }
310
+ });
311
+
312
+ // package.json
313
+ var package_default;
314
+ var init_package = __esm({
315
+ "package.json"() {
316
+ package_default = {
317
+ name: "@retrivora-ai/rag-engine",
318
+ version: "2.3.6",
319
+ description: "Retrivora AI is a plug-and-play AI engine for RAG chat experiences \u2014 generic vector DB + LLM provider, embeddable or standalone.",
320
+ author: "Abhinav Alkuchi",
321
+ license: "UNLICENSED",
322
+ keywords: [
323
+ "rag",
324
+ "retrieval-augmented-generation",
325
+ "chatbot",
326
+ "vector-database",
327
+ "pinecone",
328
+ "pgvector",
329
+ "postgresql",
330
+ "milvus",
331
+ "qdrant",
332
+ "chromadb",
333
+ "redis",
334
+ "weaviate",
335
+ "mongodb",
336
+ "openai",
337
+ "anthropic",
338
+ "ollama",
339
+ "nextjs",
340
+ "react",
341
+ "ai",
342
+ "llm",
343
+ "embeddings"
344
+ ],
345
+ main: "dist/index.js",
346
+ module: "dist/index.mjs",
347
+ types: "dist/index.d.ts",
348
+ exports: {
349
+ ".": {
350
+ types: "./dist/index.d.ts",
351
+ require: "./dist/index.js",
352
+ import: "./dist/index.mjs"
353
+ },
354
+ "./style.css": "./dist/index.css",
355
+ "./index.css": "./dist/index.css",
356
+ "./styles.css": "./dist/index.css",
357
+ "./handlers": {
358
+ types: "./dist/handlers/index.d.ts",
359
+ require: "./dist/handlers/index.js",
360
+ import: "./dist/handlers/index.mjs"
361
+ },
362
+ "./server": {
363
+ types: "./dist/server.d.ts",
364
+ require: "./dist/server.js",
365
+ import: "./dist/server.mjs"
366
+ }
367
+ },
368
+ browser: {
369
+ child_process: false,
370
+ fs: false,
371
+ net: false,
372
+ tls: false,
373
+ crypto: false,
374
+ os: false,
375
+ path: false,
376
+ stream: false,
377
+ http: false,
378
+ https: false,
379
+ zlib: false,
380
+ mongodb: false,
381
+ pg: false,
382
+ "pdf-parse": false,
383
+ mammoth: false
384
+ },
385
+ files: [
386
+ "dist",
387
+ "src",
388
+ ".env.example",
389
+ "README.md",
390
+ "FREE_TIER_ARCHITECTURE.md"
391
+ ],
392
+ scripts: {
393
+ 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",
394
+ build: "npm run build:pkg",
395
+ "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",
396
+ lint: "eslint",
397
+ typecheck: "tsc --noEmit -p tsconfig.build.json",
398
+ clean: "rm -rf dist"
399
+ },
400
+ peerDependencies: {
401
+ next: ">=15.0.0",
402
+ react: ">=18.0.0",
403
+ "react-dom": ">=18.0.0"
404
+ },
405
+ peerDependenciesMeta: {
406
+ next: {
407
+ optional: true
408
+ }
409
+ },
410
+ dependencies: {
411
+ "@anthropic-ai/sdk": "^0.95.1",
412
+ "@google/genai": "^0.8.0",
413
+ "@google/generative-ai": "^0.24.1",
414
+ "@pinecone-database/pinecone": "^7.2.0",
415
+ "@types/papaparse": "^5.5.2",
416
+ axios: "^1.15.0",
417
+ "lucide-react": "^1.8.0",
418
+ "next-themes": "^0.4.6",
419
+ openai: "^6.34.0",
420
+ papaparse: "^5.5.3",
421
+ "react-is": "^18.3.1",
422
+ "react-markdown": "^10.1.0",
423
+ recharts: "^3.8.1",
424
+ "remark-gfm": "^4.0.1",
425
+ xlsx: "^0.18.5"
426
+ },
427
+ optionalDependencies: {
428
+ "@langchain/core": "^1.1.42",
429
+ "@langchain/openai": "^1.4.5",
430
+ langchain: "^1.3.5",
431
+ llamaindex: "^0.11.9",
432
+ mammoth: "^1.8.0",
433
+ mongodb: "^7.1.1",
434
+ "pdf-parse": "^1.1.1",
435
+ pg: "^8.20.0"
436
+ },
437
+ devDependencies: {
438
+ "@tailwindcss/cli": "^4",
439
+ "@tailwindcss/postcss": "^4",
440
+ "@types/estree": "^1.0.9",
441
+ "@types/node": "^20",
442
+ "@types/pdf-parse": "^1.1.5",
443
+ "@types/pg": "^8.20.0",
444
+ "@types/react": "^19.2.14",
445
+ "@types/react-dom": "^19.2.3",
446
+ dotenv: "^17.4.2",
447
+ eslint: "^9",
448
+ "eslint-config-next": "16.2.4",
449
+ next: "16.2.10",
450
+ tailwindcss: "^4",
451
+ tsup: "^8.5.1",
452
+ typescript: "^5"
453
+ }
454
+ };
455
+ }
456
+ });
457
+
458
+ // src/version.ts
459
+ var SDK_VERSION;
460
+ var init_version = __esm({
461
+ "src/version.ts"() {
462
+ "use strict";
463
+ init_package();
464
+ SDK_VERSION = package_default.version || "2.1.3";
465
+ }
466
+ });
467
+
142
468
  // src/core/ConfigFetcher.ts
143
469
  var CONTROL_PLANE_URL, LLM_PROXY_BASE_URL, ConfigFetcher;
144
470
  var init_ConfigFetcher = __esm({
145
471
  "src/core/ConfigFetcher.ts"() {
146
472
  "use strict";
473
+ init_ProjectSettings();
474
+ init_version();
147
475
  CONTROL_PLANE_URL = "https://www.retrivora.com";
148
476
  LLM_PROXY_BASE_URL = "https://www.retrivora.com/api/v1";
149
477
  ConfigFetcher = class {
@@ -176,11 +504,12 @@ var init_ConfigFetcher = __esm({
176
504
  ].filter((url) => Boolean(url) && !url.includes("localhost") && !url.includes("127.0.0.1")).map((url) => url.replace(/\/$/, ""));
177
505
  for (const baseUrl of controlPlaneUrls) {
178
506
  try {
179
- const url = `${baseUrl}/api/v1/config?projectId=${encodeURIComponent(projectId)}${licenseKey ? `&licenseKey=${encodeURIComponent(licenseKey)}` : ""}`;
507
+ const url = `${baseUrl}/api/v1/config?projectId=${encodeURIComponent(projectId)}`;
180
508
  const res = await fetch(url, {
181
509
  method: "GET",
182
510
  headers: __spreadValues({
183
- "Content-Type": "application/json"
511
+ "Content-Type": "application/json",
512
+ "x-sdk-version": SDK_VERSION
184
513
  }, licenseKey ? { "x-license-key": licenseKey } : {})
185
514
  });
186
515
  if (res.ok) {
@@ -220,7 +549,11 @@ var init_ConfigFetcher = __esm({
220
549
  workspace: data.workspace || {
221
550
  namespace: fetchedProjectId,
222
551
  indexName: data.vectorDb.indexName || "retrivora-free"
223
- }
552
+ },
553
+ projectSettings: normalizeProjectSettings(
554
+ fetchedProjectId,
555
+ data.projectSettings || data.settings
556
+ )
224
557
  };
225
558
  this.cache.set(cacheKey, { config, cachedAt: now });
226
559
  return config;
@@ -2313,10 +2646,6 @@ var LicenseVerifier = class {
2313
2646
  static verify(licenseKey, currentProjectId, provider, publicKeyOverride) {
2314
2647
  const isProduction = process.env.NODE_ENV === "production";
2315
2648
  const now = Date.now();
2316
- console.log(`[Retrivora SDK] LicenseVerifier.verify() - licenseKey`, licenseKey);
2317
- console.log(`[Retrivora SDK] LicenseVerifier.verify() - currentProjectId`, currentProjectId);
2318
- console.log(`[Retrivora SDK] LicenseVerifier.verify() - provider`, provider);
2319
- console.log(`[Retrivora SDK] LicenseVerifier.verify() - publicKeyOverride`, publicKeyOverride);
2320
2649
  if (licenseKey) {
2321
2650
  const cacheKey = `${licenseKey}:${currentProjectId}:${provider || ""}:${publicKeyOverride || ""}`;
2322
2651
  const cached = this.cache.get(cacheKey);
@@ -2810,6 +3139,7 @@ var ConfigResolver = class {
2810
3139
  options: __spreadValues(__spreadValues({}, envConfig.embedding.options || {}), hostConfig.embedding.options || {})
2811
3140
  }) : envConfig.embedding,
2812
3141
  ui: hostConfig.ui ? mergeDefined(envConfig.ui, hostConfig.ui) : envConfig.ui,
3142
+ projectSettings: hostConfig.projectSettings || envConfig.projectSettings,
2813
3143
  rag: hostConfig.rag ? __spreadValues(__spreadValues({}, envConfig.rag), hostConfig.rag) : envConfig.rag,
2814
3144
  telemetry: hostConfig.telemetry ? __spreadValues(__spreadValues({}, envConfig.telemetry), hostConfig.telemetry) : envConfig.telemetry
2815
3145
  });
@@ -4751,149 +5081,8 @@ var ConfigValidator = class {
4751
5081
  }
4752
5082
  };
4753
5083
 
4754
- // package.json
4755
- var package_default = {
4756
- name: "@retrivora-ai/rag-engine",
4757
- version: "2.3.5",
4758
- description: "Retrivora AI is a plug-and-play AI engine for RAG chat experiences \u2014 generic vector DB + LLM provider, embeddable or standalone.",
4759
- author: "Abhinav Alkuchi",
4760
- license: "UNLICENSED",
4761
- keywords: [
4762
- "rag",
4763
- "retrieval-augmented-generation",
4764
- "chatbot",
4765
- "vector-database",
4766
- "pinecone",
4767
- "pgvector",
4768
- "postgresql",
4769
- "milvus",
4770
- "qdrant",
4771
- "chromadb",
4772
- "redis",
4773
- "weaviate",
4774
- "mongodb",
4775
- "openai",
4776
- "anthropic",
4777
- "ollama",
4778
- "nextjs",
4779
- "react",
4780
- "ai",
4781
- "llm",
4782
- "embeddings"
4783
- ],
4784
- main: "dist/index.js",
4785
- module: "dist/index.mjs",
4786
- types: "dist/index.d.ts",
4787
- exports: {
4788
- ".": {
4789
- types: "./dist/index.d.ts",
4790
- require: "./dist/index.js",
4791
- import: "./dist/index.mjs"
4792
- },
4793
- "./style.css": "./dist/index.css",
4794
- "./index.css": "./dist/index.css",
4795
- "./styles.css": "./dist/index.css",
4796
- "./handlers": {
4797
- types: "./dist/handlers/index.d.ts",
4798
- require: "./dist/handlers/index.js",
4799
- import: "./dist/handlers/index.mjs"
4800
- },
4801
- "./server": {
4802
- types: "./dist/server.d.ts",
4803
- require: "./dist/server.js",
4804
- import: "./dist/server.mjs"
4805
- }
4806
- },
4807
- browser: {
4808
- child_process: false,
4809
- fs: false,
4810
- net: false,
4811
- tls: false,
4812
- crypto: false,
4813
- os: false,
4814
- path: false,
4815
- stream: false,
4816
- http: false,
4817
- https: false,
4818
- zlib: false,
4819
- mongodb: false,
4820
- pg: false,
4821
- "pdf-parse": false,
4822
- mammoth: false
4823
- },
4824
- files: [
4825
- "dist",
4826
- "src",
4827
- ".env.example",
4828
- "README.md",
4829
- "FREE_TIER_ARCHITECTURE.md"
4830
- ],
4831
- scripts: {
4832
- 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",
4833
- build: "npm run build:pkg",
4834
- "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",
4835
- lint: "eslint",
4836
- typecheck: "tsc --noEmit -p tsconfig.build.json",
4837
- clean: "rm -rf dist"
4838
- },
4839
- peerDependencies: {
4840
- next: ">=15.0.0",
4841
- react: ">=18.0.0",
4842
- "react-dom": ">=18.0.0"
4843
- },
4844
- peerDependenciesMeta: {
4845
- next: {
4846
- optional: true
4847
- }
4848
- },
4849
- dependencies: {
4850
- "@anthropic-ai/sdk": "^0.95.1",
4851
- "@google/genai": "^0.8.0",
4852
- "@google/generative-ai": "^0.24.1",
4853
- "@pinecone-database/pinecone": "^7.2.0",
4854
- "@types/papaparse": "^5.5.2",
4855
- axios: "^1.15.0",
4856
- "lucide-react": "^1.8.0",
4857
- "next-themes": "^0.4.6",
4858
- openai: "^6.34.0",
4859
- papaparse: "^5.5.3",
4860
- "react-is": "^18.3.1",
4861
- "react-markdown": "^10.1.0",
4862
- recharts: "^3.8.1",
4863
- "remark-gfm": "^4.0.1",
4864
- xlsx: "^0.18.5"
4865
- },
4866
- optionalDependencies: {
4867
- "@langchain/core": "^1.1.42",
4868
- "@langchain/openai": "^1.4.5",
4869
- langchain: "^1.3.5",
4870
- llamaindex: "^0.11.9",
4871
- mammoth: "^1.8.0",
4872
- mongodb: "^7.1.1",
4873
- "pdf-parse": "^1.1.1",
4874
- pg: "^8.20.0"
4875
- },
4876
- devDependencies: {
4877
- "@tailwindcss/cli": "^4",
4878
- "@tailwindcss/postcss": "^4",
4879
- "@types/estree": "^1.0.9",
4880
- "@types/node": "^20",
4881
- "@types/pdf-parse": "^1.1.5",
4882
- "@types/pg": "^8.20.0",
4883
- "@types/react": "^19.2.14",
4884
- "@types/react-dom": "^19.2.3",
4885
- dotenv: "^17.4.2",
4886
- eslint: "^9",
4887
- "eslint-config-next": "16.2.4",
4888
- next: "16.2.10",
4889
- tailwindcss: "^4",
4890
- tsup: "^8.5.1",
4891
- typescript: "^5"
4892
- }
4893
- };
4894
-
4895
- // src/version.ts
4896
- var SDK_VERSION = package_default.version || "2.1.3";
5084
+ // src/core/Pipeline.ts
5085
+ init_version();
4897
5086
 
4898
5087
  // src/rag/DocumentChunker.ts
4899
5088
  var DocumentChunker = class {
@@ -10129,6 +10318,11 @@ var VectorPlugin = class {
10129
10318
  }
10130
10319
  };
10131
10320
 
10321
+ // src/server.ts
10322
+ init_version();
10323
+ init_ConfigFetcher();
10324
+ init_ProjectSettings();
10325
+
10132
10326
  // src/config/ConfigBuilder.ts
10133
10327
  var ConfigBuilder = class {
10134
10328
  /**
@@ -10875,6 +11069,7 @@ var DatabaseStorage = class {
10875
11069
  };
10876
11070
 
10877
11071
  // src/handlers/index.ts
11072
+ init_version();
10878
11073
  async function checkAuth(req, onAuthorize) {
10879
11074
  if (!onAuthorize) return null;
10880
11075
  try {
@@ -11006,6 +11201,35 @@ function enforceLicense(req, config, bodyLicenseKey) {
11006
11201
  };
11007
11202
  }
11008
11203
  }
11204
+ function getAllowedNamespaces(projectId) {
11205
+ const trimmed = projectId.trim();
11206
+ const withoutPrefix = trimmed.startsWith("retrivora-") ? trimmed.replace(/^retrivora-/, "") : trimmed;
11207
+ return new Set([
11208
+ trimmed,
11209
+ withoutPrefix,
11210
+ `retrivora-${withoutPrefix}`
11211
+ ].filter(Boolean));
11212
+ }
11213
+ function resolveLicensedNamespace(payload, requestedNamespace) {
11214
+ const allowed = getAllowedNamespaces(payload.projectId);
11215
+ const requested = requestedNamespace == null ? void 0 : requestedNamespace.trim();
11216
+ if (requested && !allowed.has(requested)) {
11217
+ return {
11218
+ ok: false,
11219
+ response: new Response(JSON.stringify({
11220
+ error: {
11221
+ code: "NAMESPACE_FORBIDDEN",
11222
+ message: "Requested namespace is not authorized for this license."
11223
+ }
11224
+ }), {
11225
+ status: 403,
11226
+ headers: { "Content-Type": "application/json" }
11227
+ })
11228
+ };
11229
+ }
11230
+ const defaultNamespace = payload.projectId.startsWith("retrivora-") ? payload.projectId : `retrivora-${payload.projectId}`;
11231
+ return { ok: true, namespace: requested || defaultNamespace };
11232
+ }
11009
11233
  var MAX_MESSAGE_LENGTH = 8e3;
11010
11234
  function sanitizeInput(raw) {
11011
11235
  const stripped = raw.replace(/[\u0000-\u0008\u000B\u000C\u000E-\u001F\u007F-\u009F]/g, "");
@@ -11166,6 +11390,8 @@ function createChatHandler(configOrPlugin, options) {
11166
11390
  }
11167
11391
  const history = bodyObj.history || (Array.isArray(bodyObj.messages) ? bodyObj.messages.slice(0, -1) : []);
11168
11392
  const { namespace, sessionId = "default", messageId, userMessageId } = bodyObj;
11393
+ const namespaceCheck = resolveLicensedNamespace(licenseCheck.payload, namespace);
11394
+ if (!namespaceCheck.ok) return namespaceCheck.response;
11169
11395
  const sanitized = sanitizeInput(rawMessage != null ? rawMessage : "");
11170
11396
  if (!sanitized.ok) {
11171
11397
  return NextResponse.json({ error: { code: "INVALID_INPUT", message: sanitized.error } }, { status: 400 });
@@ -11177,7 +11403,7 @@ function createChatHandler(configOrPlugin, options) {
11177
11403
  role: "user",
11178
11404
  content: message
11179
11405
  }).catch((err) => console.warn("[createChatHandler] Failed to save user message:", err));
11180
- const result = await plugin.chat(message, history, namespace);
11406
+ const result = await plugin.chat(message, history, namespaceCheck.namespace);
11181
11407
  const assistantMsgId = messageId || `assistant_${Date.now()}_${Math.random().toString(36).slice(2, 6)}`;
11182
11408
  await storage.saveMessage(sessionId, {
11183
11409
  id: assistantMsgId,
@@ -11258,6 +11484,8 @@ function createStreamHandler(configOrPlugin, options) {
11258
11484
  }
11259
11485
  const history = bodyObj.history || (Array.isArray(bodyObj.messages) ? bodyObj.messages.slice(0, -1) : []);
11260
11486
  const { namespace, sessionId = "default", messageId, userMessageId } = bodyObj;
11487
+ const namespaceCheck = resolveLicensedNamespace(licenseCheck.payload, namespace);
11488
+ if (!namespaceCheck.ok) return namespaceCheck.response;
11261
11489
  const sanitized = sanitizeInput(rawMessage != null ? rawMessage : "");
11262
11490
  if (!sanitized.ok) {
11263
11491
  return new Response(
@@ -11287,7 +11515,7 @@ function createStreamHandler(configOrPlugin, options) {
11287
11515
  }
11288
11516
  };
11289
11517
  try {
11290
- const pipelineStream = plugin.chatStream(message, history, namespace);
11518
+ const pipelineStream = plugin.chatStream(message, history, namespaceCheck.namespace);
11291
11519
  let fullReply = "";
11292
11520
  try {
11293
11521
  for (var iter = __forAwait(pipelineStream), more, temp, error; more = !(temp = await iter.next()).done; more = false) {
@@ -11393,6 +11621,8 @@ function createIngestHandler(configOrPlugin, options) {
11393
11621
  if (!Array.isArray(documents) || documents.length === 0) {
11394
11622
  return NextResponse.json({ error: "documents array is required" }, { status: 400 });
11395
11623
  }
11624
+ const namespaceCheck = resolveLicensedNamespace(licenseCheck.payload, namespace);
11625
+ if (!namespaceCheck.ok) return namespaceCheck.response;
11396
11626
  if (isFreeTier(licenseCheck.payload.tier)) {
11397
11627
  const totalIncomingBytes = documents.reduce(
11398
11628
  (sum, d) => sum + Buffer.byteLength(d.content || "", "utf8"),
@@ -11414,7 +11644,7 @@ function createIngestHandler(configOrPlugin, options) {
11414
11644
  );
11415
11645
  }
11416
11646
  }
11417
- const results = await plugin.ingest(documents, namespace);
11647
+ const results = await plugin.ingest(documents, namespaceCheck.namespace);
11418
11648
  reportTelemetry(req, plugin, "DOCUMENT_INGESTION", "success", `Ingested ${documents.length} document(s)`);
11419
11649
  return NextResponse.json({ results });
11420
11650
  } catch (err) {
@@ -11502,6 +11732,8 @@ function createUploadHandler(configOrPlugin, options) {
11502
11732
  const namespace = formData.get("namespace") || void 0;
11503
11733
  const dimensionRaw = formData.get("dimension");
11504
11734
  const dimension = dimensionRaw ? parseInt(dimensionRaw, 10) : void 0;
11735
+ const namespaceCheck = resolveLicensedNamespace(licenseCheck.payload, namespace);
11736
+ if (!namespaceCheck.ok) return namespaceCheck.response;
11505
11737
  if (!files || files.length === 0) {
11506
11738
  return NextResponse.json({ error: "No files provided" }, { status: 400 });
11507
11739
  }
@@ -11618,7 +11850,7 @@ function createUploadHandler(configOrPlugin, options) {
11618
11850
  });
11619
11851
  }
11620
11852
  }
11621
- const results = await plugin.ingest(documents, namespace);
11853
+ const results = await plugin.ingest(documents, namespaceCheck.namespace);
11622
11854
  reportTelemetry(req, plugin, "DOCUMENT_INGESTION", "success", `Uploaded & ingested ${files.length} file(s)`);
11623
11855
  return NextResponse.json({ message: "Upload successful", results });
11624
11856
  } catch (err) {
@@ -11637,6 +11869,7 @@ function createSuggestionsHandler(configOrPlugin, options) {
11637
11869
  const config = plugin.getConfig();
11638
11870
  const licenseCheck = enforceLicense(req, config);
11639
11871
  if (!licenseCheck.ok) return licenseCheck.response;
11872
+ let effectiveLicensePayload = licenseCheck.payload;
11640
11873
  try {
11641
11874
  let query = "";
11642
11875
  let namespace = void 0;
@@ -11649,6 +11882,7 @@ function createSuggestionsHandler(configOrPlugin, options) {
11649
11882
  if (bodyLicenseKey) {
11650
11883
  const recheck = enforceLicense(req, config, bodyLicenseKey);
11651
11884
  if (!recheck.ok) return recheck.response;
11885
+ effectiveLicensePayload = recheck.payload;
11652
11886
  }
11653
11887
  } else {
11654
11888
  const url = new URL(req.url);
@@ -11658,7 +11892,9 @@ function createSuggestionsHandler(configOrPlugin, options) {
11658
11892
  if (!query || typeof query !== "string" || !query.trim()) {
11659
11893
  return NextResponse.json({ suggestions: [] });
11660
11894
  }
11661
- const suggestions = await plugin.getSuggestions(query, namespace);
11895
+ const namespaceCheck = resolveLicensedNamespace(effectiveLicensePayload, namespace);
11896
+ if (!namespaceCheck.ok) return namespaceCheck.response;
11897
+ const suggestions = await plugin.getSuggestions(query, namespaceCheck.namespace);
11662
11898
  reportTelemetry(req, plugin, "AUTO_SUGGESTIONS", "success", `Fetched ${suggestions.length} suggestions for: ${query.slice(0, 30)}`);
11663
11899
  return NextResponse.json({ suggestions });
11664
11900
  } catch (err) {
@@ -11875,6 +12111,15 @@ function createRagHandler(configOrPlugin, options) {
11875
12111
  }
11876
12112
 
11877
12113
  // src/core/LicenseValidator.ts
12114
+ init_version();
12115
+ function canUseLocalValidationFallback(baseUrl, status) {
12116
+ const explicitFallback = typeof process !== "undefined" && process.env.RETRIVORA_ALLOW_LOCAL_LICENSE_FALLBACK === "true";
12117
+ const isLocalSdkRoute = baseUrl.startsWith("/api/retrivora") || baseUrl.includes("/api/retrivora");
12118
+ if (status !== void 0) {
12119
+ return status === 404 && (explicitFallback || isLocalSdkRoute);
12120
+ }
12121
+ return explicitFallback || isLocalSdkRoute;
12122
+ }
11878
12123
  var _LicenseValidator = class _LicenseValidator {
11879
12124
  // 5-minute TTL for successful validation only
11880
12125
  constructor() {
@@ -11934,17 +12179,8 @@ var _LicenseValidator = class _LicenseValidator {
11934
12179
  }
11935
12180
  return void 0;
11936
12181
  };
11937
- console.log("LicenseValidator.validate()", request);
11938
- console.log("LicenseValidator.validate() - licenseKey", licenseKey);
11939
- console.log("LicenseValidator.validate() - projectId", projectId);
11940
- console.log("LicenseValidator.validate() - sdkVersion", sdkVersion);
11941
- console.log("LicenseValidator.validate() - sdk", sdk);
11942
- console.log("LicenseValidator.validate() - platform", platform);
11943
- console.log("LicenseValidator.validate() - retrivoraApiBase", retrivoraApiBase);
11944
- console.log("LicenseValidator.validate() - customHeaders", customHeaders);
11945
12182
  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 : "") || "";
11946
12183
  const effectiveLicenseKey = (rawKey || "").trim().replace(/^["']|["']$/g, "").trim();
11947
- console.log("LicenseValidator.validate() - effectiveLicenseKey", effectiveLicenseKey);
11948
12184
  if (!effectiveLicenseKey) {
11949
12185
  this.purgeCache(effectiveLicenseKey);
11950
12186
  throw new LicenseValidationError("Missing RETRIVORA_LICENSE_KEY in request. Set NEXT_PUBLIC_RETRIVORA_LICENSE_KEY in your environment or pass licenseKey as a prop.");
@@ -11958,7 +12194,7 @@ var _LicenseValidator = class _LicenseValidator {
11958
12194
  this.cache.delete(effectiveLicenseKey);
11959
12195
  }
11960
12196
  }
11961
- const base = retrivoraApiBase || (typeof process !== "undefined" ? process.env.NEXT_PUBLIC_RETRIVORA_API_BASE || process.env.RETRIVORA_API_BASE : "") || "/api/retrivora";
12197
+ const base = retrivoraApiBase || (typeof process !== "undefined" ? process.env.NEXT_PUBLIC_RETRIVORA_API_BASE || process.env.RETRIVORA_API_BASE : "") || "https://www.retrivora.com/api";
11962
12198
  const validateUrl = `${base.replace(/\/$/, "")}/v1/license/validate`;
11963
12199
  let res = null;
11964
12200
  try {
@@ -11980,6 +12216,9 @@ var _LicenseValidator = class _LicenseValidator {
11980
12216
  });
11981
12217
  } catch (err) {
11982
12218
  try {
12219
+ if (!canUseLocalValidationFallback(base)) {
12220
+ throw err;
12221
+ }
11983
12222
  const payload = LicenseVerifier.verify(effectiveLicenseKey, projectId || "");
11984
12223
  const fallbackResp = {
11985
12224
  valid: true,
@@ -11997,7 +12236,7 @@ var _LicenseValidator = class _LicenseValidator {
11997
12236
  throw new LicenseValidationError(`License validation request failed: ${(err == null ? void 0 : err.message) || "Network error"}`);
11998
12237
  }
11999
12238
  }
12000
- if (res && !res.ok) {
12239
+ if (res && !res.ok && canUseLocalValidationFallback(base, res.status)) {
12001
12240
  try {
12002
12241
  const payload = LicenseVerifier.verify(effectiveLicenseKey, projectId || "");
12003
12242
  const fallbackResp = {
@@ -12052,6 +12291,7 @@ export {
12052
12291
  ChartRendererStrategy,
12053
12292
  ChromaDBProvider,
12054
12293
  ConfigBuilder,
12294
+ ConfigFetcher,
12055
12295
  ConfigResolver,
12056
12296
  ConfigValidator,
12057
12297
  ConfigurationException,
@@ -12107,6 +12347,7 @@ export {
12107
12347
  VisualizationDecisionEngine,
12108
12348
  WeaviateProvider,
12109
12349
  createChatHandler,
12350
+ createDefaultProjectSettings,
12110
12351
  createFeedbackHandler,
12111
12352
  createFromPreset,
12112
12353
  createHealthHandler,
@@ -12118,6 +12359,8 @@ export {
12118
12359
  createUploadHandler,
12119
12360
  decideVisualization,
12120
12361
  getRagConfig,
12362
+ normalizeProjectSettings,
12363
+ projectSettingsToUiConfig,
12121
12364
  sseErrorFrame,
12122
12365
  sseFrame,
12123
12366
  sseMetaFrame,