@retrivora-ai/rag-engine 2.3.5 → 2.3.7

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 (41) hide show
  1. package/dist/{BatchProcessor-tVzb9CdE.d.mts → BatchProcessor-BhLczWj5.d.mts} +179 -3
  2. package/dist/{BatchProcessor-CQDtlggz.d.ts → BatchProcessor-C42_RVWO.d.ts} +179 -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 +493 -217
  8. package/dist/handlers/index.mjs +493 -217
  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 +643 -207
  15. package/dist/index.mjs +683 -252
  16. package/dist/server.d.mts +253 -7
  17. package/dist/server.d.ts +253 -7
  18. package/dist/server.js +1145 -230
  19. package/dist/server.mjs +1131 -230
  20. package/package.json +1 -1
  21. package/src/LicensedRetrivora.ts +273 -0
  22. package/src/components/ChatWidget.tsx +44 -19
  23. package/src/components/ChatWindow.tsx +30 -14
  24. package/src/components/ConfigProvider.tsx +86 -6
  25. package/src/components/DocumentUpload.tsx +8 -2
  26. package/src/config/LicenseConfigResolver.ts +296 -0
  27. package/src/config/RagConfig.ts +4 -0
  28. package/src/config/serverConfig.ts +74 -14
  29. package/src/core/ConfigFetcher.ts +10 -1
  30. package/src/core/ConfigResolver.ts +1 -0
  31. package/src/core/LicenseValidator.ts +21 -12
  32. package/src/core/LicenseVerifier.ts +7 -11
  33. package/src/core/ProjectSettings.ts +247 -0
  34. package/src/handlers/index.ts +65 -5
  35. package/src/hooks/useProjectSettings.ts +105 -0
  36. package/src/index.css +9 -0
  37. package/src/index.ts +37 -0
  38. package/src/llm/providers/UniversalLLMAdapter.ts +67 -12
  39. package/src/server.ts +46 -2
  40. package/src/telemetry/TelemetryService.ts +330 -0
  41. package/src/types/props.ts +14 -2
@@ -0,0 +1,296 @@
1
+ /**
2
+ * LicenseConfigResolver — Resolves LLM and embedding configuration
3
+ * based on the user's license tier from Retrivora admin dashboard.
4
+ *
5
+ * The end-user SDK only needs:
6
+ * - licenseKey (JWT token from Retrivora)
7
+ * - projectId (workspace identifier)
8
+ *
9
+ * Configuration includes:
10
+ * 1. Tier-based model selection (/api/v1/config)
11
+ * 2. Provider API credentials (/api/v1/credentials)
12
+ * 3. Vector DB and rate limit settings
13
+ *
14
+ * All provider API keys (Gemini, Groq, Pinecone) are stored on Retrivora backend
15
+ * and never exposed to end-users directly.
16
+ */
17
+
18
+ import axios, { AxiosInstance } from 'axios';
19
+ import { LLMConfig, EmbeddingConfig, VectorDBConfig } from './RagConfig';
20
+
21
+ export interface ProviderCredentials {
22
+ geminiApiKey?: string;
23
+ groqApiKey?: string;
24
+ pineconeApiKey?: string;
25
+ textEmbeddingProvider?: string;
26
+ }
27
+
28
+ export interface LicenseTierConfig {
29
+ tier: 'free_trial' | 'free' | 'hobby' | 'pro' | 'enterprise';
30
+ llmModel: string;
31
+ embeddingModel: string;
32
+ embeddingDimensions: number;
33
+ maxTokens: number;
34
+ chunkSize: number;
35
+ chunkOverlap: number;
36
+ topK: number;
37
+ vectorDb: {
38
+ provider: string;
39
+ indexName: string;
40
+ };
41
+ rateLimit?: {
42
+ requestsPerMinute: number;
43
+ tokensPerDay: number;
44
+ };
45
+ }
46
+
47
+ export interface ProviderCredentials {
48
+ geminiApiKey?: string;
49
+ groqApiKey?: string;
50
+ pineconeApiKey?: string;
51
+ textEmbeddingProvider?: string;
52
+ }
53
+
54
+ export interface ConfigAPIResponse {
55
+ success: boolean;
56
+ config?: LicenseTierConfig;
57
+ error?: string;
58
+ message?: string;
59
+ }
60
+
61
+ export interface CredentialsAPIResponse {
62
+ success: boolean;
63
+ credentials?: ProviderCredentials;
64
+ error?: string;
65
+ message?: string;
66
+ }
67
+
68
+ /**
69
+ * Resolver for license-based configuration.
70
+ * This is called by the end-user SDK after they instantiate with licenseKey + projectId.
71
+ */
72
+ export class LicenseConfigResolver {
73
+ private static readonly RETRIVORA_CONFIG_URL = 'https://www.retrivora.com/api/v1/config';
74
+ private static readonly RETRIVORA_CREDENTIALS_URL = 'https://www.retrivora.com/api/v1/credentials';
75
+ private static readonly CACHE_TTL_MS = 3600000; // 1 hour
76
+ private static configCache = new Map<string, { config: LicenseTierConfig; credentials: ProviderCredentials; timestamp: number }>();
77
+
78
+ /**
79
+ * Validate and resolve configuration from license key
80
+ * @param licenseKey JWT token from Retrivora (format: rtv_eyJ...)
81
+ * @param projectId Workspace identifier
82
+ * @returns Resolved LLM and embedding configs with provider credentials
83
+ */
84
+ static async resolveFromLicense(
85
+ licenseKey: string,
86
+ projectId: string
87
+ ): Promise<{
88
+ llmConfig: LLMConfig;
89
+ embeddingConfig: EmbeddingConfig;
90
+ vectorDbConfig: VectorDBConfig;
91
+ tierConfig: LicenseTierConfig;
92
+ credentials: ProviderCredentials;
93
+ }> {
94
+ // Check cache first
95
+ const cacheKey = `${licenseKey}:${projectId}`;
96
+ const cached = this.configCache.get(cacheKey);
97
+ if (cached && Date.now() - cached.timestamp < this.CACHE_TTL_MS) {
98
+ console.log('[LicenseConfigResolver] Using cached config for', projectId);
99
+ return this.buildConfigs(cached.config, cached.credentials, licenseKey, projectId);
100
+ }
101
+
102
+ // Fetch tier config from /api/v1/config
103
+ console.log('[LicenseConfigResolver] Fetching tier config from Retrivora...');
104
+ const tierConfig = await this.fetchTierConfig(licenseKey, projectId);
105
+
106
+ // Fetch provider credentials from /api/v1/credentials
107
+ console.log('[LicenseConfigResolver] Fetching provider credentials from Retrivora...');
108
+ const credentials = await this.fetchProviderCredentials(licenseKey, projectId);
109
+
110
+ // Cache both
111
+ this.configCache.set(cacheKey, { config: tierConfig, credentials, timestamp: Date.now() });
112
+
113
+ console.log('[LicenseConfigResolver] ✅ Successfully resolved config from Retrivora:', {
114
+ tier: tierConfig.tier,
115
+ llmModel: tierConfig.llmModel,
116
+ embeddingModel: tierConfig.embeddingModel,
117
+ });
118
+
119
+ return this.buildConfigs(tierConfig, credentials, licenseKey, projectId);
120
+ }
121
+
122
+ /**
123
+ * Fetch tier configuration from Retrivora config API
124
+ */
125
+ private static async fetchTierConfig(licenseKey: string, projectId: string): Promise<LicenseTierConfig> {
126
+ try {
127
+ const response = await axios.post<ConfigAPIResponse>(
128
+ this.RETRIVORA_CONFIG_URL,
129
+ { licenseKey, projectId },
130
+ {
131
+ headers: {
132
+ 'Content-Type': 'application/json',
133
+ Authorization: `Bearer ${licenseKey}`,
134
+ 'X-License-Key': licenseKey,
135
+ 'X-Project-ID': projectId,
136
+ },
137
+ timeout: 10000,
138
+ }
139
+ );
140
+
141
+ if (!response.data.success || !response.data.config) {
142
+ throw new Error(
143
+ `[LicenseConfigResolver] Config API returned error: ${response.data.error || response.data.message}`
144
+ );
145
+ }
146
+
147
+ console.log(`[LicenseConfigResolver] Resolved tier: ${response.data.config.tier}`);
148
+ return response.data.config;
149
+ } catch (err: any) {
150
+ console.error('[LicenseConfigResolver] Failed to fetch config:', err.message);
151
+ throw new Error(
152
+ `[LicenseConfigResolver] Could not validate license key or fetch tier configuration: ${err.message}`
153
+ );
154
+ }
155
+ }
156
+
157
+ /**
158
+ * Fetch provider credentials from Retrivora credentials API
159
+ */
160
+ private static async fetchProviderCredentials(licenseKey: string, projectId: string): Promise<ProviderCredentials> {
161
+ try {
162
+ const response = await axios.post<CredentialsAPIResponse>(
163
+ this.RETRIVORA_CREDENTIALS_URL,
164
+ { licenseKey, projectId },
165
+ {
166
+ headers: {
167
+ 'Content-Type': 'application/json',
168
+ Authorization: `Bearer ${licenseKey}`,
169
+ 'X-License-Key': licenseKey,
170
+ 'X-Project-ID': projectId,
171
+ },
172
+ timeout: 10000,
173
+ }
174
+ );
175
+
176
+ if (!response.data.success || !response.data.credentials) {
177
+ throw new Error(
178
+ `[LicenseConfigResolver] Credentials API returned error: ${response.data.error || response.data.message}`
179
+ );
180
+ }
181
+
182
+ console.log(`[LicenseConfigResolver] Retrieved provider credentials for project: ${projectId}`);
183
+ return response.data.credentials;
184
+ } catch (err: any) {
185
+ console.error('[LicenseConfigResolver] Failed to fetch credentials:', err.message);
186
+ throw new Error(
187
+ `[LicenseConfigResolver] Could not fetch provider credentials: ${err.message}`
188
+ );
189
+ }
190
+ }
191
+
192
+ /**
193
+ * Build LLM, embedding, and vector DB configs from tier and credentials
194
+ */
195
+ private static buildConfigs(
196
+ tierConfig: LicenseTierConfig,
197
+ credentials: ProviderCredentials,
198
+ licenseKey: string,
199
+ projectId: string
200
+ ): {
201
+ llmConfig: LLMConfig;
202
+ embeddingConfig: EmbeddingConfig;
203
+ vectorDbConfig: VectorDBConfig;
204
+ tierConfig: LicenseTierConfig;
205
+ credentials: ProviderCredentials;
206
+ } {
207
+ // Determine LLM provider and API key based on model
208
+ let llmProvider: 'gemini' | 'groq' | 'openai' = 'gemini';
209
+ let llmApiKey = credentials.geminiApiKey || licenseKey;
210
+
211
+ if (tierConfig.llmModel.includes('gpt')) {
212
+ llmProvider = 'openai';
213
+ } else if (tierConfig.llmModel.includes('groq') || tierConfig.llmModel.includes('llama')) {
214
+ llmProvider = 'groq';
215
+ llmApiKey = credentials.groqApiKey || licenseKey;
216
+ }
217
+
218
+ const llmConfig: LLMConfig = {
219
+ provider: llmProvider,
220
+ model: tierConfig.llmModel,
221
+ apiKey: llmApiKey,
222
+ maxTokens: tierConfig.maxTokens,
223
+ temperature: 0.7,
224
+ options: {},
225
+ };
226
+
227
+ // Embedding config - use Gemini's embeddings
228
+ const embeddingConfig: EmbeddingConfig = {
229
+ provider: 'gemini',
230
+ model: tierConfig.embeddingModel,
231
+ apiKey: credentials.geminiApiKey || licenseKey,
232
+ dimensions: tierConfig.embeddingDimensions,
233
+ options: {},
234
+ };
235
+
236
+ // Vector DB config - determined by tier from Retrivora
237
+ const vectorDbConfig: VectorDBConfig = {
238
+ provider: tierConfig.vectorDb.provider as any,
239
+ indexName: tierConfig.vectorDb.indexName,
240
+ options: this.getVectorDbOptions(tierConfig.vectorDb.provider, projectId, credentials),
241
+ };
242
+
243
+ return { llmConfig, embeddingConfig, vectorDbConfig, tierConfig, credentials };
244
+ }
245
+
246
+ /**
247
+ * Get provider-specific vector DB options
248
+ */
249
+ private static getVectorDbOptions(
250
+ provider: string,
251
+ projectId: string,
252
+ credentials: ProviderCredentials
253
+ ): Record<string, unknown> {
254
+ switch (provider) {
255
+ case 'pinecone':
256
+ return {
257
+ apiKey: credentials.pineconeApiKey,
258
+ indexName: `retrivora-${projectId}`,
259
+ };
260
+ case 'pgvector':
261
+ case 'postgresql':
262
+ return {
263
+ tables: [`documents_${projectId}`],
264
+ };
265
+ case 'mongodb':
266
+ return {
267
+ database: `retrivora_${projectId}`,
268
+ collection: `vectors_${projectId}`,
269
+ };
270
+ case 'qdrant':
271
+ return {
272
+ collection: `retrivora_${projectId}`,
273
+ };
274
+ default:
275
+ return {};
276
+ }
277
+ }
278
+
279
+ /**
280
+ * Clear configuration cache (useful for testing or manual refresh)
281
+ */
282
+ static clearCache(): void {
283
+ this.configCache.clear();
284
+ console.log('[LicenseConfigResolver] Configuration cache cleared');
285
+ }
286
+
287
+ /**
288
+ * Get cache stats for debugging
289
+ */
290
+ static getCacheStats(): { size: number; entries: string[] } {
291
+ return {
292
+ size: this.configCache.size,
293
+ entries: Array.from(this.configCache.keys()),
294
+ };
295
+ }
296
+ }
@@ -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
 
@@ -26,6 +26,49 @@ import {
26
26
  EMBEDDING_PROVIDERS,
27
27
  } from './constants';
28
28
 
29
+ /**
30
+ * Runtime tier configuration injected from the /api/v1/config + /api/v1/credentials
31
+ * API responses at app startup. This overrides static env-var defaults so that
32
+ * the tier-based model selection from the license is applied to all SDK calls.
33
+ */
34
+ export interface RuntimeTierConfig {
35
+ llmModel?: string;
36
+ embeddingModel?: string;
37
+ /** LiteLLM master key for authenticating with llm.retrivora.com */
38
+ litellmApiKey?: string;
39
+ /** LiteLLM gateway base URL (defaults to https://llm.retrivora.com/api/v1) */
40
+ llmBaseUrl?: string;
41
+ embeddingBaseUrl?: string;
42
+ maxTokens?: number;
43
+ topK?: number;
44
+ chunkSize?: number;
45
+ chunkOverlap?: number;
46
+ tier?: string;
47
+ }
48
+
49
+ /** Module-level store for runtime-injected tier config */
50
+ let _runtimeConfig: RuntimeTierConfig | null = null;
51
+
52
+ /**
53
+ * Inject tier-based config fetched from /api/v1/config + /api/v1/credentials.
54
+ * Call this once after successful license init (e.g. in validate-env.ts).
55
+ */
56
+ export function injectRuntimeConfig(config: RuntimeTierConfig): void {
57
+ _runtimeConfig = config;
58
+ console.log('[serverConfig] ✅ Runtime tier config injected:', {
59
+ tier: config.tier,
60
+ llmModel: config.llmModel,
61
+ embeddingModel: config.embeddingModel,
62
+ llmBaseUrl: config.llmBaseUrl,
63
+ hasLitellmKey: !!config.litellmApiKey,
64
+ });
65
+ }
66
+
67
+ /** Returns the currently injected runtime config, or null if not yet set. */
68
+ export function getRuntimeConfig(): RuntimeTierConfig | null {
69
+ return _runtimeConfig;
70
+ }
71
+
29
72
  function readString(env: Record<string, string | undefined>, name: string): string | undefined {
30
73
  const value = env[name]?.trim();
31
74
  return value ? value : undefined;
@@ -185,25 +228,42 @@ export function getEnvConfig(env: Record<string, string | undefined> = process.e
185
228
  }
186
229
  })();
187
230
 
188
- // Default gateway: retrivora.com/api/v1 acts as a secure proxy that validates the license key
189
- // and forwards to llm.retrivora.com with LITELLM_MASTER_KEY (which end-users never need to know).
190
- const defaultGatewayUrl =
191
- readString(env, 'LITELLM_BASE_URL') ??
192
- readString(env, 'LLM_BASE_URL') ??
193
- 'https://www.retrivora.com/api/v1';
231
+ // Tier-based model selection (resolved from license tier)
232
+ const tierBasedLLMModel = isFreeTier ? 'llama-3.1-8b-instant' : 'llama-3.3-70b-versatile';
233
+ const tierBasedEmbeddingModel = isFreeTier ? 'text-embedding-004' : 'text-embedding-004';
194
234
 
195
- const defaultLlmProvider = isFreeTier ? 'universal_rest' : 'universal_rest';
235
+ // Default gateway: always use LiteLLM at llm.retrivora.com for end-users
236
+ // End-users provide license key + project ID; the gateway validates and routes internally
237
+ const defaultGatewayUrl = 'https://llm.retrivora.com/api/v1';
238
+
239
+ // ── Runtime-injected tier config (from /api/v1/config + /api/v1/credentials) ──
240
+ // Priority: explicit env var > injected runtime config > static tier fallback
241
+ const rt = _runtimeConfig;
242
+
243
+ const defaultLlmProvider = 'universal_rest';
196
244
  const llmProvider = (readEnum(env, 'LLM_PROVIDER', defaultLlmProvider, LLM_PROVIDERS) ?? base?.llm?.provider ?? defaultLlmProvider) as LLMProvider;
197
- const llmBaseUrl = readString(env, 'LITELLM_BASE_URL') ?? readString(env, 'LLM_BASE_URL') ?? base?.llm?.baseUrl ?? defaultGatewayUrl;
198
- const llmModel = readString(env, 'LLM_MODEL') ?? base?.llm?.model ?? (isFreeTier ? 'llama-3.1-8b-instant' : (DEFAULT_MODEL_BY_PROVIDER[llmProvider] ?? 'gpt-4o'));
199
- const llmApiKey = llmApiKeyByProvider[llmProvider] ?? readString(env, 'LLM_API_KEY') ?? readString(env, 'LITELLM_MASTER_KEY') ?? readString(env, 'LITELLM_API_KEY') ?? base?.llm?.apiKey ?? licenseKey;
245
+ // llmBaseUrl: env var wins, then injected gateway URL, then static default
246
+ const llmBaseUrl = readString(env, 'LITELLM_BASE_URL') ?? readString(env, 'LLM_BASE_URL') ?? base?.llm?.baseUrl ?? rt?.llmBaseUrl ?? defaultGatewayUrl;
247
+ // llmModel: env var wins, then injected tier model, then static tier fallback
248
+ const llmModel = readString(env, 'LLM_MODEL') ?? base?.llm?.model ?? rt?.llmModel ?? tierBasedLLMModel;
249
+ // llmApiKey: LITELLM_MASTER_KEY env wins, then injected litellm key, then licenseKey
250
+ const llmApiKey = readString(env, 'LITELLM_MASTER_KEY') ?? rt?.litellmApiKey ?? base?.llm?.apiKey ?? licenseKey;
200
251
  const llmProfile = readString(env, 'LLM_UNIVERSAL_PROFILE') ?? (base?.llm?.options?.profile as string) ?? 'litellm';
201
252
 
202
- const defaultEmbeddingProvider = isFreeTier ? 'universal_rest' : 'universal_rest';
253
+ console.log('[serverConfig] 🔧 LLM Configuration:', {
254
+ baseUrl: llmBaseUrl,
255
+ model: llmModel,
256
+ provider: llmProvider,
257
+ hasApiKey: !!llmApiKey,
258
+ source: rt?.llmModel ? 'runtime-injected' : 'env/fallback',
259
+ });
260
+
261
+ const defaultEmbeddingProvider = 'universal_rest';
203
262
  const embeddingProvider = (readEnum(env, 'EMBEDDING_PROVIDER', defaultEmbeddingProvider, EMBEDDING_PROVIDERS) ?? base?.embedding?.provider ?? defaultEmbeddingProvider) as EmbeddingProvider;
204
- const embeddingBaseUrl = readString(env, 'LITELLM_BASE_URL') ?? readString(env, 'EMBEDDING_BASE_URL') ?? readString(env, 'LLM_BASE_URL') ?? base?.embedding?.baseUrl ?? defaultGatewayUrl;
205
- const embeddingModel = readString(env, 'EMBEDDING_MODEL') ?? base?.embedding?.model ?? 'text-embedding-004';
206
- const embeddingApiKey = embeddingApiKeyByProvider[embeddingProvider] ?? readString(env, 'EMBEDDING_API_KEY') ?? readString(env, 'LLM_API_KEY') ?? readString(env, 'LITELLM_MASTER_KEY') ?? readString(env, 'LITELLM_API_KEY') ?? base?.embedding?.apiKey ?? licenseKey;
263
+ const embeddingBaseUrl = readString(env, 'LITELLM_BASE_URL') ?? readString(env, 'EMBEDDING_BASE_URL') ?? readString(env, 'LLM_BASE_URL') ?? base?.embedding?.baseUrl ?? rt?.embeddingBaseUrl ?? rt?.llmBaseUrl ?? defaultGatewayUrl;
264
+ const embeddingModel = readString(env, 'EMBEDDING_MODEL') ?? base?.embedding?.model ?? rt?.embeddingModel ?? tierBasedEmbeddingModel;
265
+ // embeddingApiKey: same key as LLM (LiteLLM gateway handles both)
266
+ const embeddingApiKey = readString(env, 'LITELLM_MASTER_KEY') ?? rt?.litellmApiKey ?? base?.embedding?.apiKey ?? licenseKey;
207
267
  const embeddingProfile = readString(env, 'EMBEDDING_UNIVERSAL_PROFILE') ?? (base?.embedding?.options?.profile as string) ?? 'litellm';
208
268
 
209
269
  return {
@@ -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 = {
@@ -51,13 +51,13 @@ export class LicenseVerifier {
51
51
  // In production, this matches the private key held by Retrivora SaaS.
52
52
  // Rotate this key only when the signing private key is replaced.
53
53
  private static readonly PUBLIC_KEY = `-----BEGIN PUBLIC KEY-----
54
- MIIBIjANBgkqhkiG9w0BAQEFAAOCAQ8AMIIBCgKCAQEAoOQlmDSKfCZaRy06rxwa
55
- chuDimlF134xTCitKDTPTPizF23oSn34pGDJakm/0T09JVUX8L/cvhGPe/3lf/g9
56
- 4Y1q+Gb2KVM17KNGeT1Aj9Ua3BKz/yao/oFhi/r3Zt3cWY13B/Rd6clqY9WshIAV
57
- NqZNM8ilTl777cMbyym+6D+mzGXgmnJAO5brddIAI9FPLW0T3Znt8vEqDOIljEkC
58
- HCGHeirKABLbjKSJ4hljCa3vVitWqndhiq8CBSJG6HatiSGYotgMWGRY+0EbdlEv
59
- OJP4SqafQ3aD6YnL9q1n15QKwxu/uMK+JGM2VxxuyUi9GANtMIkCYy9xya73P4Qc
60
- gQIDAQAB
54
+ MIIBIjANBgkqhkiG9w0BAQEFAAOCAQ8AMIIBCgKCAQEAyKvvOSYdCimG3b236ebV
55
+ jpG88xQiU8dSiaMahtBJDf4w0AewRj7hMNgmeZ1wyTOj8kVgeGBOolp1Z0QmTr6O
56
+ Tj4EDQ/zjsg12If7hSf3NiwLHCYmMLslyK0aaP6PQoTrYkBv3GNdkMecrIjKCijb
57
+ 6VvDLLF3X696melTVM0z/d2e50BW2AlRw/rf1EqYi10d0BcPo5zje0XETr/WGmqu
58
+ sDiXtsP5MlwkL9X7RQY2uovRa+l/vOAqAfdmJ+OzXuk5P7mDUPb+gCtKnoDbb1tr
59
+ 6UAu733dkUnetAcMqyT3fNPBLO66DCc6m9rGCYYAaG7piMEDwG0/ZySZBFbgllJc
60
+ 6QIDAQAB
61
61
  -----END PUBLIC KEY-----`;
62
62
 
63
63
  /**
@@ -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 || ''}`;