@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/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@retrivora-ai/rag-engine",
3
- "version": "2.3.5",
3
+ "version": "2.3.6",
4
4
  "description": "Retrivora AI is a plug-and-play AI engine for RAG chat experiences — generic vector DB + LLM provider, embeddable or standalone.",
5
5
  "author": "Abhinav Alkuchi",
6
6
  "license": "UNLICENSED",
@@ -67,8 +67,19 @@ const GEMINI_STYLES = `
67
67
  *
68
68
  * @param props - Widget position, callbacks, API overrides, and license overrides
69
69
  */
70
- export function ChatWidget({ position = 'bottom-right', onAddToCart, apiUrl, retrivoraApiBase, licenseKey: licenseKeyProp, headers }: ChatWidgetProps) {
71
- const { ui, projectId } = useConfig();
70
+ export function ChatWidget({ position, onAddToCart, apiUrl, retrivoraApiBase, licenseKey: licenseKeyProp, headers }: ChatWidgetProps) {
71
+ const {
72
+ ui,
73
+ projectId,
74
+ projectSettings,
75
+ licenseKey: contextLicenseKey,
76
+ headers: contextHeaders,
77
+ retrivoraApiBase: contextApiBase,
78
+ } = useConfig();
79
+ const effectivePosition = position || projectSettings?.widget.position || 'bottom-right';
80
+ const effectiveHeaders = headers || contextHeaders;
81
+ const effectiveLicenseKey = licenseKeyProp || contextLicenseKey;
82
+ const effectiveApiBase = retrivoraApiBase || contextApiBase;
72
83
  const [isOpen, setIsOpen] = useState(false);
73
84
  const [hasUnread, setHasUnread] = useState(false);
74
85
  const [dimensions, setDimensions] = useState(DEFAULT_DIMENSIONS);
@@ -80,13 +91,21 @@ export function ChatWidget({ position = 'bottom-right', onAddToCart, apiUrl, ret
80
91
  const [hasMountValidationFailed, setHasMountValidationFailed] = useState(false);
81
92
 
82
93
  const positionClass =
83
- position === 'bottom-left'
94
+ effectivePosition === 'bottom-left'
84
95
  ? 'bottom-6 left-6'
96
+ : effectivePosition === 'top-left'
97
+ ? 'top-6 left-6'
98
+ : effectivePosition === 'top-right'
99
+ ? 'top-6 right-6'
85
100
  : 'bottom-6 right-6';
86
101
 
87
102
  const windowPositionClass =
88
- position === 'bottom-left'
103
+ effectivePosition === 'bottom-left'
89
104
  ? 'bottom-20 left-6'
105
+ : effectivePosition === 'top-left'
106
+ ? 'top-20 left-6'
107
+ : effectivePosition === 'top-right'
108
+ ? 'top-20 right-6'
90
109
  : 'bottom-20 right-6';
91
110
 
92
111
  /**
@@ -95,16 +114,16 @@ export function ChatWidget({ position = 'bottom-right', onAddToCart, apiUrl, ret
95
114
  */
96
115
  const resolveLicenseKey = useCallback((): string => {
97
116
  const getHeader = (name: string) => {
98
- if (!headers) return undefined;
117
+ if (!effectiveHeaders) return undefined;
99
118
  const target = name.toLowerCase();
100
- for (const [k, v] of Object.entries(headers)) {
119
+ for (const [k, v] of Object.entries(effectiveHeaders)) {
101
120
  if (k.toLowerCase() === target) return v;
102
121
  }
103
122
  return undefined;
104
123
  };
105
124
 
106
125
  return (
107
- licenseKeyProp ||
126
+ effectiveLicenseKey ||
108
127
  getHeader('x-license-key') ||
109
128
  getHeader('authorization')?.replace(/^Bearer\s+/i, '') ||
110
129
  (typeof process !== 'undefined'
@@ -112,7 +131,7 @@ export function ChatWidget({ position = 'bottom-right', onAddToCart, apiUrl, ret
112
131
  : '') ||
113
132
  ''
114
133
  );
115
- }, [licenseKeyProp, headers]);
134
+ }, [effectiveLicenseKey, effectiveHeaders]);
116
135
 
117
136
  /**
118
137
  * Proactively validate the license on mount.
@@ -127,8 +146,8 @@ export function ChatWidget({ position = 'bottom-right', onAddToCart, apiUrl, ret
127
146
  await LicenseValidator.getInstance().validate({
128
147
  licenseKey: resolvedLicenseKey,
129
148
  projectId,
130
- retrivoraApiBase,
131
- headers,
149
+ retrivoraApiBase: effectiveApiBase,
150
+ headers: effectiveHeaders,
132
151
  });
133
152
  if (isMounted) {
134
153
  setHasMountValidationFailed(false);
@@ -143,7 +162,7 @@ export function ChatWidget({ position = 'bottom-right', onAddToCart, apiUrl, ret
143
162
  }
144
163
  validateOnMount();
145
164
  return () => { isMounted = false; };
146
- }, [resolveLicenseKey, projectId, retrivoraApiBase, headers]);
165
+ }, [resolveLicenseKey, projectId, effectiveApiBase, effectiveHeaders]);
147
166
 
148
167
  /**
149
168
  * Validates the license key and opens the chat window.
@@ -162,8 +181,8 @@ export function ChatWidget({ position = 'bottom-right', onAddToCart, apiUrl, ret
162
181
  await LicenseValidator.getInstance().validate({
163
182
  licenseKey: resolvedLicenseKey,
164
183
  projectId,
165
- retrivoraApiBase,
166
- headers,
184
+ retrivoraApiBase: effectiveApiBase,
185
+ headers: effectiveHeaders,
167
186
  });
168
187
 
169
188
  setWidgetError(null);
@@ -177,7 +196,7 @@ export function ChatWidget({ position = 'bottom-right', onAddToCart, apiUrl, ret
177
196
  } finally {
178
197
  setIsValidating(false);
179
198
  }
180
- }, [hasMountValidationFailed, widgetError, resolveLicenseKey, projectId, retrivoraApiBase, headers]);
199
+ }, [hasMountValidationFailed, widgetError, resolveLicenseKey, projectId, effectiveApiBase, effectiveHeaders]);
181
200
 
182
201
  /** True when the license has been proven invalid and the widget must be locked. */
183
202
  const isWidgetLocked = hasMountValidationFailed || isValidating;
@@ -259,14 +278,14 @@ export function ChatWidget({ position = 'bottom-right', onAddToCart, apiUrl, ret
259
278
  isMaximized={isMaximized}
260
279
  onAddToCart={onAddToCart}
261
280
  apiUrl={apiUrl}
262
- retrivoraApiBase={retrivoraApiBase}
263
- licenseKey={licenseKeyProp}
264
- headers={headers}
281
+ retrivoraApiBase={effectiveApiBase}
282
+ licenseKey={effectiveLicenseKey}
283
+ headers={effectiveHeaders}
265
284
  />
266
285
  {/* Pointer (Tail) */}
267
286
  <div
268
287
  className={`absolute -bottom-1.5 w-4 h-4 rotate-45 border-r border-b border-slate-200 dark:border-white/10 z-0 ${ui.visualStyle === 'solid' ? 'bg-white dark:bg-[#0f0f1a]' : 'bg-white/90 dark:bg-[#0f0f1a]/90 backdrop-blur-xl'
269
- } ${position === 'bottom-left' ? 'left-5' : 'right-5'}`}
288
+ } ${effectivePosition === 'bottom-left' || effectivePosition === 'top-left' ? 'left-5' : 'right-5'}`}
270
289
  />
271
290
  </div>
272
291
 
@@ -274,7 +293,13 @@ export function ChatWidget({ position = 'bottom-right', onAddToCart, apiUrl, ret
274
293
  {widgetError && !isOpen && (
275
294
  <div
276
295
  className={`fixed z-[9999] max-w-sm p-4 rounded-2xl shadow-2xl border border-rose-200 dark:border-rose-900/60 bg-white/95 dark:bg-[#0f0f1a]/95 backdrop-blur-xl transition-all duration-300 animate-in fade-in slide-in-from-bottom-3 ${
277
- position === 'bottom-left' ? 'bottom-24 left-6' : 'bottom-24 right-6'
296
+ effectivePosition === 'bottom-left'
297
+ ? 'bottom-24 left-6'
298
+ : effectivePosition === 'top-left'
299
+ ? 'top-24 left-6'
300
+ : effectivePosition === 'top-right'
301
+ ? 'top-24 right-6'
302
+ : 'bottom-24 right-6'
278
303
  }`}
279
304
  >
280
305
  <div className="flex items-start gap-3">
@@ -106,7 +106,17 @@ export function ChatWindow({
106
106
  licenseKey: licenseKeyProp,
107
107
  headers
108
108
  }: ChatWindowProps) {
109
- const { ui, projectId } = useConfig();
109
+ const {
110
+ ui,
111
+ projectId,
112
+ licenseKey: contextLicenseKey,
113
+ headers: contextHeaders,
114
+ retrivoraApiBase: contextApiBase,
115
+ projectSettings,
116
+ } = useConfig();
117
+ const effectiveLicenseKey = licenseKeyProp || contextLicenseKey;
118
+ const effectiveHeaders = headers || contextHeaders;
119
+ const effectiveApiBase = retrivoraApiBase || contextApiBase;
110
120
  const [input, setInput] = useState('');
111
121
  const [mounted, setMounted] = useState(false);
112
122
  const [viewportSize, setViewportSize] = useState<'compact' | 'medium' | 'large'>('large');
@@ -116,9 +126,10 @@ export function ChatWindow({
116
126
  const { messages, send, clear, isLoading, error, stop, submitFeedback } = useRagChat(projectId, {
117
127
  namespace: projectId,
118
128
  apiUrl,
119
- retrivoraApiBase,
120
- licenseKey: licenseKeyProp,
121
- headers,
129
+ retrivoraApiBase: effectiveApiBase,
130
+ licenseKey: effectiveLicenseKey,
131
+ headers: effectiveHeaders,
132
+ persist: projectSettings?.widget.persistConversations,
122
133
  });
123
134
 
124
135
  const [suggestions, setSuggestions] = useState<string[]>([]);
@@ -142,16 +153,16 @@ export function ChatWindow({
142
153
  async function validateSessionLicense() {
143
154
  try {
144
155
  const getHeader = (name: string) => {
145
- if (!headers) return undefined;
156
+ if (!effectiveHeaders) return undefined;
146
157
  const target = name.toLowerCase();
147
- for (const [k, v] of Object.entries(headers)) {
158
+ for (const [k, v] of Object.entries(effectiveHeaders)) {
148
159
  if (k.toLowerCase() === target) return v;
149
160
  }
150
161
  return undefined;
151
162
  };
152
163
 
153
164
  const resolvedLicenseKey =
154
- licenseKeyProp ||
165
+ effectiveLicenseKey ||
155
166
  getHeader('x-license-key') ||
156
167
  getHeader('authorization')?.replace(/^Bearer\s+/i, '') ||
157
168
  (typeof process !== 'undefined'
@@ -162,8 +173,8 @@ export function ChatWindow({
162
173
  await LicenseValidator.getInstance().validate({
163
174
  licenseKey: resolvedLicenseKey,
164
175
  projectId,
165
- retrivoraApiBase,
166
- headers,
176
+ retrivoraApiBase: effectiveApiBase,
177
+ headers: effectiveHeaders,
167
178
  });
168
179
 
169
180
  if (isMounted) {
@@ -183,7 +194,7 @@ export function ChatWindow({
183
194
 
184
195
  validateSessionLicense();
185
196
  return () => { isMounted = false; };
186
- }, [retrivoraApiBase, headers, projectId]);
197
+ }, [effectiveApiBase, effectiveHeaders, effectiveLicenseKey, projectId]);
187
198
 
188
199
  // Initialize SpeechRecognition
189
200
  useEffect(() => {
@@ -313,18 +324,23 @@ export function ChatWindow({
313
324
  const timer = setTimeout(async () => {
314
325
  setIsSuggesting(true);
315
326
  try {
316
- const base = retrivoraApiBase || '/api/retrivora';
327
+ const base = effectiveApiBase || '/api/retrivora';
317
328
  const primaryUrl = `${base}/suggestions`;
329
+ const suggestionHeaders = {
330
+ 'Content-Type': 'application/json',
331
+ ...(effectiveLicenseKey ? { 'x-license-key': effectiveLicenseKey } : {}),
332
+ ...(effectiveHeaders || {}),
333
+ };
318
334
  let response = await fetch(primaryUrl, {
319
335
  method: 'POST',
320
- headers: { 'Content-Type': 'application/json', ...(headers || {}) },
336
+ headers: suggestionHeaders,
321
337
  body: JSON.stringify({ query: input, namespace: projectId }),
322
338
  });
323
339
 
324
340
  if (!response.ok && response.status === 404) {
325
341
  response = await fetch('/api/suggestions', {
326
342
  method: 'POST',
327
- headers: { 'Content-Type': 'application/json', ...(headers || {}) },
343
+ headers: suggestionHeaders,
328
344
  body: JSON.stringify({ query: input, namespace: projectId }),
329
345
  });
330
346
  }
@@ -341,7 +357,7 @@ export function ChatWindow({
341
357
  }, 800); // 800ms debounce to save costs/latency
342
358
 
343
359
  return () => clearTimeout(timer);
344
- }, [input, projectId, retrivoraApiBase, headers]);
360
+ }, [input, projectId, effectiveApiBase, effectiveHeaders, effectiveLicenseKey]);
345
361
 
346
362
  return (
347
363
  <div
@@ -7,23 +7,103 @@
7
7
  * Only the UI-safe portions of RagConfig are exposed to the client.
8
8
  */
9
9
 
10
- import React, { createContext, useContext } from 'react';
10
+ import React, { createContext, useContext, useEffect, useMemo, useState } from 'react';
11
11
  import { UIConfig } from '../config/RagConfig';
12
12
  import { mergeDefined } from '../utils/templateUtils';
13
13
  import { ClientConfig, ConfigProviderProps } from '../types';
14
14
  import { DEFAULT_CONFIG } from '../config/uiConstants';
15
+ import { ConfigFetcher } from '../core/ConfigFetcher';
16
+ import { normalizeProjectSettings, projectSettingsToUiConfig } from '../core/ProjectSettings';
15
17
 
16
18
  const ConfigContext = createContext<ClientConfig>(DEFAULT_CONFIG);
17
19
 
20
+ function resolveHeader(headers: Record<string, string> | undefined, name: string): string | undefined {
21
+ if (!headers) return undefined;
22
+ const target = name.toLowerCase();
23
+ for (const [key, value] of Object.entries(headers)) {
24
+ if (key.toLowerCase() === target) return value;
25
+ }
26
+ return undefined;
27
+ }
28
+
18
29
  export function ConfigProvider({
19
30
  config,
20
31
  children,
21
32
  }: ConfigProviderProps) {
22
- const merged: ClientConfig = {
23
- projectId: config?.projectId || DEFAULT_CONFIG.projectId,
24
- ui: mergeDefined(DEFAULT_CONFIG.ui, config?.ui) as Required<UIConfig>,
25
- embedding: config?.embedding,
26
- };
33
+ const projectId = config?.projectId || DEFAULT_CONFIG.projectId;
34
+ const projectSettingsInput = config?.projectSettings;
35
+ const autoLoadProjectSettings = config?.autoLoadProjectSettings;
36
+ const licenseKeyInput = config?.licenseKey;
37
+ const headersInput = config?.headers;
38
+ const retrivoraApiBaseInput = config?.retrivoraApiBase;
39
+ const embeddingInput = config?.embedding;
40
+ const uiInput = config?.ui;
41
+ const explicitSettings = useMemo(
42
+ () => projectSettingsInput
43
+ ? normalizeProjectSettings(projectId, projectSettingsInput)
44
+ : undefined,
45
+ [projectSettingsInput, projectId]
46
+ );
47
+ const [remoteSettings, setRemoteSettings] = useState(explicitSettings);
48
+ const [isLoading, setIsLoading] = useState(false);
49
+
50
+ useEffect(() => {
51
+ let cancelled = false;
52
+ const shouldLoad =
53
+ autoLoadProjectSettings !== false &&
54
+ !explicitSettings &&
55
+ Boolean(licenseKeyInput || resolveHeader(headersInput, 'x-license-key') || resolveHeader(headersInput, 'authorization'));
56
+
57
+ if (!shouldLoad) {
58
+ setRemoteSettings(explicitSettings);
59
+ setIsLoading(false);
60
+ return;
61
+ }
62
+
63
+ const licenseKey =
64
+ licenseKeyInput ||
65
+ resolveHeader(headersInput, 'x-license-key') ||
66
+ resolveHeader(headersInput, 'authorization')?.replace(/^Bearer\s+/i, '') ||
67
+ '';
68
+
69
+ async function loadProjectSettings() {
70
+ setIsLoading(true);
71
+ try {
72
+ const remoteConfig = await ConfigFetcher.fetchRemoteConfig(projectId, licenseKey);
73
+ if (!cancelled) {
74
+ setRemoteSettings(remoteConfig?.projectSettings || explicitSettings);
75
+ }
76
+ } catch {
77
+ if (!cancelled) setRemoteSettings(explicitSettings);
78
+ } finally {
79
+ if (!cancelled) setIsLoading(false);
80
+ }
81
+ }
82
+
83
+ loadProjectSettings();
84
+
85
+ return () => {
86
+ cancelled = true;
87
+ };
88
+ }, [autoLoadProjectSettings, headersInput, licenseKeyInput, explicitSettings, projectId]);
89
+
90
+ const merged: ClientConfig = useMemo(() => {
91
+ const settingsUi = remoteSettings ? projectSettingsToUiConfig(remoteSettings) : undefined;
92
+ return {
93
+ projectId,
94
+ ui: mergeDefined(
95
+ DEFAULT_CONFIG.ui,
96
+ mergeDefined(settingsUi || {}, uiInput)
97
+ ) as Required<UIConfig>,
98
+ embedding: embeddingInput,
99
+ licenseKey: licenseKeyInput,
100
+ headers: headersInput,
101
+ retrivoraApiBase: retrivoraApiBaseInput,
102
+ projectSettings: remoteSettings,
103
+ autoLoadProjectSettings,
104
+ isProjectSettingsLoading: isLoading,
105
+ };
106
+ }, [autoLoadProjectSettings, embeddingInput, headersInput, licenseKeyInput, retrivoraApiBaseInput, uiInput, isLoading, projectId, remoteSettings]);
27
107
 
28
108
  return <ConfigContext.Provider value={merged}>{children}</ConfigContext.Provider>;
29
109
  }
@@ -12,7 +12,7 @@ interface FileState {
12
12
  }
13
13
 
14
14
  export function DocumentUpload({ namespace, uploadUrl, retrivoraApiBase, onUploadComplete, className = '' }: DocumentUploadProps) {
15
- const { ui, embedding, projectId } = useConfig();
15
+ const { ui, embedding, projectId, licenseKey, headers: configHeaders, retrivoraApiBase: configuredApiBase } = useConfig();
16
16
  const [fileStates, setFileStates] = useState<FileState[]>([]);
17
17
  const [isDragging, setIsDragging] = useState(false);
18
18
  const fileInputRef = useRef<HTMLInputElement>(null);
@@ -93,14 +93,19 @@ export function DocumentUpload({ namespace, uploadUrl, retrivoraApiBase, onUploa
93
93
  if (targetNs) formData.append('namespace', targetNs);
94
94
  formData.append('dimension', dimension.toString());
95
95
 
96
- const apiBase = retrivoraApiBase || '/api/retrivora';
96
+ const apiBase = retrivoraApiBase || configuredApiBase || '/api/retrivora';
97
97
  const primaryUrl = uploadUrl || `${apiBase.replace(/\/$/, '')}/upload`;
98
+ const uploadHeaders = {
99
+ ...(configHeaders || {}),
100
+ ...(licenseKey ? { 'x-license-key': licenseKey } : {}),
101
+ };
98
102
 
99
103
  console.log(`[Retrivora SDK] 📤 Initiating upload request to "${primaryUrl}" (Files: ${idleFiles.length}, Namespace: "${targetNs}", Dimension: ${dimension})`);
100
104
 
101
105
  try {
102
106
  let response = await fetch(primaryUrl, {
103
107
  method: 'POST',
108
+ headers: uploadHeaders,
104
109
  body: formData,
105
110
  });
106
111
 
@@ -108,6 +113,7 @@ export function DocumentUpload({ namespace, uploadUrl, retrivoraApiBase, onUploa
108
113
  console.warn(`[Retrivora SDK] ⚠️ Upload endpoint "${primaryUrl}" returned 404. Retrying fallback to "/api/upload"...`);
109
114
  response = await fetch('/api/upload', {
110
115
  method: 'POST',
116
+ headers: uploadHeaders,
111
117
  body: formData,
112
118
  });
113
119
  }
@@ -14,6 +14,7 @@ import {
14
14
  EMBEDDING_PROVIDERS,
15
15
  GRAPH_DB_PROVIDERS,
16
16
  } from './constants';
17
+ import type { ProjectChatSettings } from '../core/ProjectSettings';
17
18
 
18
19
  export type VectorDBProvider = typeof VECTOR_DB_PROVIDERS[number];
19
20
 
@@ -289,6 +290,9 @@ export interface RagConfig {
289
290
  /** Optional UI branding overrides */
290
291
  ui?: UIConfig;
291
292
 
293
+ /** Optional dashboard-managed project chat settings */
294
+ projectSettings?: ProjectChatSettings;
295
+
292
296
  /** Optional RAG pipeline tuning knobs */
293
297
  rag?: RAGConfig;
294
298
 
@@ -8,6 +8,9 @@
8
8
  * forwards to https://llm.retrivora.com with the server-side LITELLM_MASTER_KEY.
9
9
  */
10
10
 
11
+ import { ProjectChatSettings, normalizeProjectSettings } from './ProjectSettings';
12
+ import { SDK_VERSION } from '../version';
13
+
11
14
  export interface RemoteVectorConfig {
12
15
  apiKey: string;
13
16
  indexName: string;
@@ -44,6 +47,7 @@ export interface RemoteConfig {
44
47
  namespace: string;
45
48
  indexName: string;
46
49
  };
50
+ projectSettings?: ProjectChatSettings;
47
51
  }
48
52
 
49
53
  // Legacy alias
@@ -102,11 +106,12 @@ export class ConfigFetcher {
102
106
 
103
107
  for (const baseUrl of controlPlaneUrls) {
104
108
  try {
105
- const url = `${baseUrl}/api/v1/config?projectId=${encodeURIComponent(projectId)}${licenseKey ? `&licenseKey=${encodeURIComponent(licenseKey)}` : ''}`;
109
+ const url = `${baseUrl}/api/v1/config?projectId=${encodeURIComponent(projectId)}`;
106
110
  const res = await fetch(url, {
107
111
  method: 'GET',
108
112
  headers: {
109
113
  'Content-Type': 'application/json',
114
+ 'x-sdk-version': SDK_VERSION,
110
115
  ...(licenseKey ? { 'x-license-key': licenseKey } : {}),
111
116
  },
112
117
  });
@@ -151,6 +156,10 @@ export class ConfigFetcher {
151
156
  namespace: fetchedProjectId,
152
157
  indexName: data.vectorDb.indexName || 'retrivora-free',
153
158
  },
159
+ projectSettings: normalizeProjectSettings(
160
+ fetchedProjectId,
161
+ data.projectSettings || data.settings
162
+ ),
154
163
  };
155
164
  this.cache.set(cacheKey, { config, cachedAt: now });
156
165
  return config;
@@ -60,6 +60,7 @@ export class ConfigResolver {
60
60
  }
61
61
  : envConfig.embedding,
62
62
  ui: hostConfig.ui ? mergeDefined(envConfig.ui, hostConfig.ui) : envConfig.ui,
63
+ projectSettings: hostConfig.projectSettings || envConfig.projectSettings,
63
64
  rag: hostConfig.rag ? { ...envConfig.rag, ...hostConfig.rag } : envConfig.rag,
64
65
  telemetry: hostConfig.telemetry
65
66
  ? {
@@ -55,6 +55,19 @@ interface CachedSuccessValidation {
55
55
  timestamp: number;
56
56
  }
57
57
 
58
+ function canUseLocalValidationFallback(baseUrl: string, status?: number): boolean {
59
+ const explicitFallback =
60
+ typeof process !== 'undefined' &&
61
+ process.env.RETRIVORA_ALLOW_LOCAL_LICENSE_FALLBACK === 'true';
62
+ const isLocalSdkRoute = baseUrl.startsWith('/api/retrivora') || baseUrl.includes('/api/retrivora');
63
+
64
+ if (status !== undefined) {
65
+ return status === 404 && (explicitFallback || isLocalSdkRoute);
66
+ }
67
+
68
+ return explicitFallback || isLocalSdkRoute;
69
+ }
70
+
58
71
  /**
59
72
  * Client-side orchestrator for license validation.
60
73
  *
@@ -139,14 +152,6 @@ export class LicenseValidator {
139
152
  return undefined;
140
153
  };
141
154
 
142
- console.log('LicenseValidator.validate()', request);
143
- console.log('LicenseValidator.validate() - licenseKey', licenseKey);
144
- console.log('LicenseValidator.validate() - projectId', projectId);
145
- console.log('LicenseValidator.validate() - sdkVersion', sdkVersion);
146
- console.log('LicenseValidator.validate() - sdk', sdk);
147
- console.log('LicenseValidator.validate() - platform', platform);
148
- console.log('LicenseValidator.validate() - retrivoraApiBase', retrivoraApiBase);
149
- console.log('LicenseValidator.validate() - customHeaders', customHeaders);
150
155
  const rawKey =
151
156
  licenseKey ||
152
157
  getHeader('x-license-key') ||
@@ -157,7 +162,6 @@ export class LicenseValidator {
157
162
  '';
158
163
 
159
164
  const effectiveLicenseKey = (rawKey || '').trim().replace(/^["']|["']$/g, '').trim();
160
- console.log('LicenseValidator.validate() - effectiveLicenseKey', effectiveLicenseKey);
161
165
 
162
166
  if (!effectiveLicenseKey) {
163
167
  this.purgeCache(effectiveLicenseKey);
@@ -176,7 +180,7 @@ export class LicenseValidator {
176
180
  }
177
181
 
178
182
  // 2. Fetch live validation from Retrivora backend API / local catch-all route
179
- const base = retrivoraApiBase || (typeof process !== 'undefined' ? process.env.NEXT_PUBLIC_RETRIVORA_API_BASE || process.env.RETRIVORA_API_BASE : '') || '/api/retrivora';
183
+ const base = retrivoraApiBase || (typeof process !== 'undefined' ? process.env.NEXT_PUBLIC_RETRIVORA_API_BASE || process.env.RETRIVORA_API_BASE : '') || 'https://www.retrivora.com/api';
180
184
  const validateUrl = `${base.replace(/\/$/, '')}/v1/license/validate`;
181
185
 
182
186
  let res: Response | null = null;
@@ -201,6 +205,9 @@ export class LicenseValidator {
201
205
  } catch (err: any) {
202
206
  // Fallback: If network error occurs, verify locally via RSA LicenseVerifier
203
207
  try {
208
+ if (!canUseLocalValidationFallback(base)) {
209
+ throw err;
210
+ }
204
211
  const payload = LicenseVerifier.verify(effectiveLicenseKey, projectId || '');
205
212
  const fallbackResp: LicenseValidationResponse = {
206
213
  valid: true,
@@ -219,8 +226,10 @@ export class LicenseValidator {
219
226
  }
220
227
  }
221
228
 
222
- if (res && !res.ok) {
223
- // Attempt local verification fallback if API route returned 404 or non-OK response
229
+ if (res && !res.ok && canUseLocalValidationFallback(base, res.status)) {
230
+ // Attempt local verification fallback only for missing local SDK validation routes.
231
+ // Authoritative denials (403 revoked/expired, 426 unsupported SDK, etc.) must not
232
+ // be bypassed by local JWT verification.
224
233
  try {
225
234
  const payload = LicenseVerifier.verify(effectiveLicenseKey, projectId || '');
226
235
  const fallbackResp: LicenseValidationResponse = {
@@ -76,10 +76,6 @@ gQIDAQAB
76
76
  const isProduction = process.env.NODE_ENV === 'production';
77
77
  const now = Date.now();
78
78
 
79
- console.log(`[Retrivora SDK] LicenseVerifier.verify() - licenseKey`, licenseKey);
80
- console.log(`[Retrivora SDK] LicenseVerifier.verify() - currentProjectId`, currentProjectId);
81
- console.log(`[Retrivora SDK] LicenseVerifier.verify() - provider`, provider);
82
- console.log(`[Retrivora SDK] LicenseVerifier.verify() - publicKeyOverride`, publicKeyOverride);
83
79
  // Check verification cache to bypass crypto computations on hot paths
84
80
  if (licenseKey) {
85
81
  const cacheKey = `${licenseKey}:${currentProjectId}:${provider || ''}:${publicKeyOverride || ''}`;