@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
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.7",
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);
@@ -2504,13 +2833,13 @@ LicenseVerifier.CACHE_TTL_MS = 60 * 1e3;
2504
2833
  // In production, this matches the private key held by Retrivora SaaS.
2505
2834
  // Rotate this key only when the signing private key is replaced.
2506
2835
  LicenseVerifier.PUBLIC_KEY = `-----BEGIN PUBLIC KEY-----
2507
- MIIBIjANBgkqhkiG9w0BAQEFAAOCAQ8AMIIBCgKCAQEAoOQlmDSKfCZaRy06rxwa
2508
- chuDimlF134xTCitKDTPTPizF23oSn34pGDJakm/0T09JVUX8L/cvhGPe/3lf/g9
2509
- 4Y1q+Gb2KVM17KNGeT1Aj9Ua3BKz/yao/oFhi/r3Zt3cWY13B/Rd6clqY9WshIAV
2510
- NqZNM8ilTl777cMbyym+6D+mzGXgmnJAO5brddIAI9FPLW0T3Znt8vEqDOIljEkC
2511
- HCGHeirKABLbjKSJ4hljCa3vVitWqndhiq8CBSJG6HatiSGYotgMWGRY+0EbdlEv
2512
- OJP4SqafQ3aD6YnL9q1n15QKwxu/uMK+JGM2VxxuyUi9GANtMIkCYy9xya73P4Qc
2513
- gQIDAQAB
2836
+ MIIBIjANBgkqhkiG9w0BAQEFAAOCAQ8AMIIBCgKCAQEAyKvvOSYdCimG3b236ebV
2837
+ jpG88xQiU8dSiaMahtBJDf4w0AewRj7hMNgmeZ1wyTOj8kVgeGBOolp1Z0QmTr6O
2838
+ Tj4EDQ/zjsg12If7hSf3NiwLHCYmMLslyK0aaP6PQoTrYkBv3GNdkMecrIjKCijb
2839
+ 6VvDLLF3X696melTVM0z/d2e50BW2AlRw/rf1EqYi10d0BcPo5zje0XETr/WGmqu
2840
+ sDiXtsP5MlwkL9X7RQY2uovRa+l/vOAqAfdmJ+OzXuk5P7mDUPb+gCtKnoDbb1tr
2841
+ 6UAu733dkUnetAcMqyT3fNPBLO66DCc6m9rGCYYAaG7piMEDwG0/ZySZBFbgllJc
2842
+ 6QIDAQAB
2514
2843
  -----END PUBLIC KEY-----`;
2515
2844
 
2516
2845
  // src/config/constants.ts
@@ -2559,6 +2888,20 @@ var PROVIDERS_WITH_EMBEDDINGS = [
2559
2888
  var UI_BORDER_RADIUS_OPTIONS = ["none", "sm", "md", "lg", "xl", "full"];
2560
2889
 
2561
2890
  // src/config/serverConfig.ts
2891
+ var _runtimeConfig = null;
2892
+ function injectRuntimeConfig(config) {
2893
+ _runtimeConfig = config;
2894
+ console.log("[serverConfig] \u2705 Runtime tier config injected:", {
2895
+ tier: config.tier,
2896
+ llmModel: config.llmModel,
2897
+ embeddingModel: config.embeddingModel,
2898
+ llmBaseUrl: config.llmBaseUrl,
2899
+ hasLitellmKey: !!config.litellmApiKey
2900
+ });
2901
+ }
2902
+ function getRuntimeConfig() {
2903
+ return _runtimeConfig;
2904
+ }
2562
2905
  function readString(env, name) {
2563
2906
  var _a3;
2564
2907
  const value = (_a3 = env[name]) == null ? void 0 : _a3.trim();
@@ -2585,7 +2928,7 @@ function getRagConfig(baseConfig, env = process.env) {
2585
2928
  return getEnvConfig(env, baseConfig);
2586
2929
  }
2587
2930
  function getEnvConfig(env = process.env, base) {
2588
- var _a3, _b, _c, _d, _e, _f, _g2, _h, _i, _j, _k, _l, _m, _n, _o, _p, _q, _r, _s, _t, _u, _v, _w, _x, _y, _z, _A, _B, _C, _D, _E, _F, _G, _H, _I, _J, _K, _L, _M, _N, _O, _P, _Q, _R, _S, _T, _U, _V, _W, _X, _Y, _Z, __, _$, _aa, _ba, _ca, _da, _ea, _fa, _ga, _ha, _ia, _ja, _ka, _la, _ma, _na, _oa, _pa, _qa, _ra, _sa, _ta, _ua, _va, _wa, _xa, _ya, _za, _Aa, _Ba, _Ca, _Da, _Ea, _Fa, _Ga, _Ha, _Ia, _Ja, _Ka, _La, _Ma, _Na, _Oa, _Pa, _Qa, _Ra, _Sa, _Ta, _Ua, _Va, _Wa, _Xa, _Ya, _Za, __a, _$a, _ab, _bb, _cb, _db, _eb, _fb, _gb, _hb, _ib, _jb, _kb, _lb, _mb, _nb, _ob, _pb, _qb, _rb, _sb, _tb, _ub, _vb, _wb, _xb, _yb, _zb, _Ab, _Bb, _Cb, _Db, _Eb, _Fb, _Gb, _Hb, _Ib, _Jb, _Kb;
2931
+ var _a3, _b, _c, _d, _e, _f, _g2, _h, _i, _j, _k, _l, _m, _n, _o, _p, _q, _r, _s, _t, _u, _v, _w, _x, _y, _z, _A, _B, _C, _D, _E, _F, _G, _H, _I, _J, _K, _L, _M, _N, _O, _P, _Q, _R, _S, _T, _U, _V, _W, _X, _Y, _Z, __, _$, _aa, _ba, _ca, _da, _ea, _fa, _ga, _ha, _ia, _ja, _ka, _la, _ma, _na, _oa, _pa, _qa, _ra, _sa, _ta, _ua, _va, _wa, _xa, _ya, _za, _Aa, _Ba, _Ca, _Da, _Ea, _Fa, _Ga, _Ha, _Ia, _Ja, _Ka, _La, _Ma, _Na, _Oa, _Pa, _Qa, _Ra, _Sa, _Ta, _Ua, _Va, _Wa, _Xa, _Ya, _Za, __a, _$a, _ab, _bb, _cb, _db, _eb, _fb, _gb, _hb, _ib, _jb, _kb, _lb, _mb, _nb, _ob, _pb, _qb, _rb, _sb, _tb, _ub, _vb, _wb, _xb, _yb, _zb, _Ab, _Bb, _Cb, _Db, _Eb, _Fb, _Gb, _Hb;
2589
2932
  const licenseKey = (_d = (_c = (_b = (_a3 = readString(env, "RAG_LICENSE_KEY")) != null ? _a3 : readString(env, "RETRIVORA_LICENSE_KEY")) != null ? _b : readString(env, "NEXT_PUBLIC_RETRIVORA_LICENSE_KEY")) != null ? _c : readString(env, "LICENSE_KEY")) != null ? _d : base == null ? void 0 : base.licenseKey;
2590
2933
  const jwtProjectId = (() => {
2591
2934
  if (!licenseKey) return void 0;
@@ -2677,25 +3020,35 @@ function getEnvConfig(env = process.env, base) {
2677
3020
  return true;
2678
3021
  }
2679
3022
  })();
2680
- const defaultGatewayUrl = (_ra = (_qa = readString(env, "LITELLM_BASE_URL")) != null ? _qa : readString(env, "LLM_BASE_URL")) != null ? _ra : "https://www.retrivora.com/api/v1";
2681
- const defaultLlmProvider = isFreeTier2 ? "universal_rest" : "universal_rest";
2682
- const llmProvider = (_ua = (_ta = readEnum(env, "LLM_PROVIDER", defaultLlmProvider, LLM_PROVIDERS)) != null ? _ta : (_sa = base == null ? void 0 : base.llm) == null ? void 0 : _sa.provider) != null ? _ua : defaultLlmProvider;
2683
- const llmBaseUrl = (_ya = (_xa = (_va = readString(env, "LITELLM_BASE_URL")) != null ? _va : readString(env, "LLM_BASE_URL")) != null ? _xa : (_wa = base == null ? void 0 : base.llm) == null ? void 0 : _wa.baseUrl) != null ? _ya : defaultGatewayUrl;
2684
- const llmModel = (_Ca = (_Aa = readString(env, "LLM_MODEL")) != null ? _Aa : (_za = base == null ? void 0 : base.llm) == null ? void 0 : _za.model) != null ? _Ca : isFreeTier2 ? "llama-3.1-8b-instant" : (_Ba = DEFAULT_MODEL_BY_PROVIDER[llmProvider]) != null ? _Ba : "gpt-4o";
2685
- const llmApiKey = (_Ia = (_Ha = (_Fa = (_Ea = (_Da = llmApiKeyByProvider[llmProvider]) != null ? _Da : readString(env, "LLM_API_KEY")) != null ? _Ea : readString(env, "LITELLM_MASTER_KEY")) != null ? _Fa : readString(env, "LITELLM_API_KEY")) != null ? _Ha : (_Ga = base == null ? void 0 : base.llm) == null ? void 0 : _Ga.apiKey) != null ? _Ia : licenseKey;
2686
- const llmProfile = (_Ma = (_La = readString(env, "LLM_UNIVERSAL_PROFILE")) != null ? _La : (_Ka = (_Ja = base == null ? void 0 : base.llm) == null ? void 0 : _Ja.options) == null ? void 0 : _Ka.profile) != null ? _Ma : "litellm";
2687
- const defaultEmbeddingProvider = isFreeTier2 ? "universal_rest" : "universal_rest";
2688
- const embeddingProvider = (_Pa = (_Oa = readEnum(env, "EMBEDDING_PROVIDER", defaultEmbeddingProvider, EMBEDDING_PROVIDERS)) != null ? _Oa : (_Na = base == null ? void 0 : base.embedding) == null ? void 0 : _Na.provider) != null ? _Pa : defaultEmbeddingProvider;
2689
- const embeddingBaseUrl = (_Ua = (_Ta = (_Ra = (_Qa = readString(env, "LITELLM_BASE_URL")) != null ? _Qa : readString(env, "EMBEDDING_BASE_URL")) != null ? _Ra : readString(env, "LLM_BASE_URL")) != null ? _Ta : (_Sa = base == null ? void 0 : base.embedding) == null ? void 0 : _Sa.baseUrl) != null ? _Ua : defaultGatewayUrl;
2690
- const embeddingModel = (_Xa = (_Wa = readString(env, "EMBEDDING_MODEL")) != null ? _Wa : (_Va = base == null ? void 0 : base.embedding) == null ? void 0 : _Va.model) != null ? _Xa : "text-embedding-004";
2691
- const embeddingApiKey = (_cb = (_bb = (_$a = (__a = (_Za = (_Ya = embeddingApiKeyByProvider[embeddingProvider]) != null ? _Ya : readString(env, "EMBEDDING_API_KEY")) != null ? _Za : readString(env, "LLM_API_KEY")) != null ? __a : readString(env, "LITELLM_MASTER_KEY")) != null ? _$a : readString(env, "LITELLM_API_KEY")) != null ? _bb : (_ab = base == null ? void 0 : base.embedding) == null ? void 0 : _ab.apiKey) != null ? _cb : licenseKey;
2692
- const embeddingProfile = (_gb = (_fb = readString(env, "EMBEDDING_UNIVERSAL_PROFILE")) != null ? _fb : (_eb = (_db = base == null ? void 0 : base.embedding) == null ? void 0 : _db.options) == null ? void 0 : _eb.profile) != null ? _gb : "litellm";
3023
+ const tierBasedLLMModel = isFreeTier2 ? "llama-3.1-8b-instant" : "llama-3.3-70b-versatile";
3024
+ const tierBasedEmbeddingModel = isFreeTier2 ? "text-embedding-004" : "text-embedding-004";
3025
+ const defaultGatewayUrl = "https://llm.retrivora.com/api/v1";
3026
+ const rt = _runtimeConfig;
3027
+ const defaultLlmProvider = "universal_rest";
3028
+ const llmProvider = (_sa = (_ra = readEnum(env, "LLM_PROVIDER", defaultLlmProvider, LLM_PROVIDERS)) != null ? _ra : (_qa = base == null ? void 0 : base.llm) == null ? void 0 : _qa.provider) != null ? _sa : defaultLlmProvider;
3029
+ const llmBaseUrl = (_xa = (_wa = (_va = (_ta = readString(env, "LITELLM_BASE_URL")) != null ? _ta : readString(env, "LLM_BASE_URL")) != null ? _va : (_ua = base == null ? void 0 : base.llm) == null ? void 0 : _ua.baseUrl) != null ? _wa : rt == null ? void 0 : rt.llmBaseUrl) != null ? _xa : defaultGatewayUrl;
3030
+ const llmModel = (_Ba = (_Aa = (_za = readString(env, "LLM_MODEL")) != null ? _za : (_ya = base == null ? void 0 : base.llm) == null ? void 0 : _ya.model) != null ? _Aa : rt == null ? void 0 : rt.llmModel) != null ? _Ba : tierBasedLLMModel;
3031
+ const llmApiKey = (_Fa = (_Ea = (_Ca = readString(env, "LITELLM_MASTER_KEY")) != null ? _Ca : rt == null ? void 0 : rt.litellmApiKey) != null ? _Ea : (_Da = base == null ? void 0 : base.llm) == null ? void 0 : _Da.apiKey) != null ? _Fa : licenseKey;
3032
+ const llmProfile = (_Ja = (_Ia = readString(env, "LLM_UNIVERSAL_PROFILE")) != null ? _Ia : (_Ha = (_Ga = base == null ? void 0 : base.llm) == null ? void 0 : _Ga.options) == null ? void 0 : _Ha.profile) != null ? _Ja : "litellm";
3033
+ console.log("[serverConfig] \u{1F527} LLM Configuration:", {
3034
+ baseUrl: llmBaseUrl,
3035
+ model: llmModel,
3036
+ provider: llmProvider,
3037
+ hasApiKey: !!llmApiKey,
3038
+ source: (rt == null ? void 0 : rt.llmModel) ? "runtime-injected" : "env/fallback"
3039
+ });
3040
+ const defaultEmbeddingProvider = "universal_rest";
3041
+ const embeddingProvider = (_Ma = (_La = readEnum(env, "EMBEDDING_PROVIDER", defaultEmbeddingProvider, EMBEDDING_PROVIDERS)) != null ? _La : (_Ka = base == null ? void 0 : base.embedding) == null ? void 0 : _Ka.provider) != null ? _Ma : defaultEmbeddingProvider;
3042
+ const embeddingBaseUrl = (_Ta = (_Sa = (_Ra = (_Qa = (_Oa = (_Na = readString(env, "LITELLM_BASE_URL")) != null ? _Na : readString(env, "EMBEDDING_BASE_URL")) != null ? _Oa : readString(env, "LLM_BASE_URL")) != null ? _Qa : (_Pa = base == null ? void 0 : base.embedding) == null ? void 0 : _Pa.baseUrl) != null ? _Ra : rt == null ? void 0 : rt.embeddingBaseUrl) != null ? _Sa : rt == null ? void 0 : rt.llmBaseUrl) != null ? _Ta : defaultGatewayUrl;
3043
+ const embeddingModel = (_Xa = (_Wa = (_Va = readString(env, "EMBEDDING_MODEL")) != null ? _Va : (_Ua = base == null ? void 0 : base.embedding) == null ? void 0 : _Ua.model) != null ? _Wa : rt == null ? void 0 : rt.embeddingModel) != null ? _Xa : tierBasedEmbeddingModel;
3044
+ const embeddingApiKey = (_$a = (__a = (_Ya = readString(env, "LITELLM_MASTER_KEY")) != null ? _Ya : rt == null ? void 0 : rt.litellmApiKey) != null ? __a : (_Za = base == null ? void 0 : base.embedding) == null ? void 0 : _Za.apiKey) != null ? _$a : licenseKey;
3045
+ const embeddingProfile = (_db = (_cb = readString(env, "EMBEDDING_UNIVERSAL_PROFILE")) != null ? _cb : (_bb = (_ab = base == null ? void 0 : base.embedding) == null ? void 0 : _ab.options) == null ? void 0 : _bb.profile) != null ? _db : "litellm";
2693
3046
  return __spreadProps(__spreadValues({
2694
3047
  projectId,
2695
3048
  licenseKey,
2696
3049
  vectorDb: {
2697
3050
  provider: vectorProvider,
2698
- indexName: (_ib = (_hb = readString(env, "VECTOR_DB_INDEX")) != null ? _hb : vectorDbOptions.indexName) != null ? _ib : "rag-index",
3051
+ indexName: (_fb = (_eb = readString(env, "VECTOR_DB_INDEX")) != null ? _eb : vectorDbOptions.indexName) != null ? _fb : "rag-index",
2699
3052
  options: vectorDbOptions
2700
3053
  },
2701
3054
  llm: {
@@ -2725,30 +3078,30 @@ function getEnvConfig(env = process.env, base) {
2725
3078
  }
2726
3079
  },
2727
3080
  ui: {
2728
- title: (_kb = (_jb = readString(env, "NEXT_PUBLIC_UI_TITLE")) != null ? _jb : readString(env, "UI_TITLE")) != null ? _kb : "AI Assistant",
2729
- subtitle: (_mb = (_lb = readString(env, "NEXT_PUBLIC_UI_SUBTITLE")) != null ? _lb : readString(env, "UI_SUBTITLE")) != null ? _mb : "Powered by RAG",
2730
- primaryColor: (_ob = (_nb = readString(env, "NEXT_PUBLIC_PRIMARY_COLOR")) != null ? _nb : readString(env, "UI_PRIMARY_COLOR")) != null ? _ob : "#10b981",
2731
- accentColor: (_qb = (_pb = readString(env, "NEXT_PUBLIC_ACCENT_COLOR")) != null ? _pb : readString(env, "UI_ACCENT_COLOR")) != null ? _qb : "#3b82f6",
2732
- logoUrl: (_rb = readString(env, "NEXT_PUBLIC_LOGO_URL")) != null ? _rb : readString(env, "UI_LOGO_URL"),
2733
- placeholder: (_tb = (_sb = readString(env, "NEXT_PUBLIC_PLACEHOLDER")) != null ? _sb : readString(env, "UI_PLACEHOLDER")) != null ? _tb : "Ask me anything\u2026",
2734
- showSources: ((_vb = (_ub = readString(env, "NEXT_PUBLIC_SHOW_SOURCES")) != null ? _ub : readString(env, "UI_SHOW_SOURCES")) != null ? _vb : "true") !== "false",
2735
- welcomeMessage: (_xb = (_wb = readString(env, "NEXT_PUBLIC_WELCOME_MESSAGE")) != null ? _wb : readString(env, "UI_WELCOME_MESSAGE")) != null ? _xb : "Hello! I'm your AI assistant. Ask me anything about your documents.",
2736
- visualStyle: (_zb = (_yb = readString(env, "NEXT_PUBLIC_UI_VISUAL_STYLE")) != null ? _yb : readString(env, "UI_VISUAL_STYLE")) != null ? _zb : "glass",
2737
- borderRadius: (_Bb = (_Ab = readString(env, "NEXT_PUBLIC_UI_BORDER_RADIUS")) != null ? _Ab : readString(env, "UI_BORDER_RADIUS")) != null ? _Bb : "xl",
2738
- allowUpload: ((_Db = (_Cb = readString(env, "NEXT_PUBLIC_ALLOW_UPLOAD")) != null ? _Cb : readString(env, "UI_ALLOW_UPLOAD")) != null ? _Db : "false") === "true"
3081
+ title: (_hb = (_gb = readString(env, "NEXT_PUBLIC_UI_TITLE")) != null ? _gb : readString(env, "UI_TITLE")) != null ? _hb : "AI Assistant",
3082
+ subtitle: (_jb = (_ib = readString(env, "NEXT_PUBLIC_UI_SUBTITLE")) != null ? _ib : readString(env, "UI_SUBTITLE")) != null ? _jb : "Powered by RAG",
3083
+ primaryColor: (_lb = (_kb = readString(env, "NEXT_PUBLIC_PRIMARY_COLOR")) != null ? _kb : readString(env, "UI_PRIMARY_COLOR")) != null ? _lb : "#10b981",
3084
+ accentColor: (_nb = (_mb = readString(env, "NEXT_PUBLIC_ACCENT_COLOR")) != null ? _mb : readString(env, "UI_ACCENT_COLOR")) != null ? _nb : "#3b82f6",
3085
+ logoUrl: (_ob = readString(env, "NEXT_PUBLIC_LOGO_URL")) != null ? _ob : readString(env, "UI_LOGO_URL"),
3086
+ placeholder: (_qb = (_pb = readString(env, "NEXT_PUBLIC_PLACEHOLDER")) != null ? _pb : readString(env, "UI_PLACEHOLDER")) != null ? _qb : "Ask me anything\u2026",
3087
+ showSources: ((_sb = (_rb = readString(env, "NEXT_PUBLIC_SHOW_SOURCES")) != null ? _rb : readString(env, "UI_SHOW_SOURCES")) != null ? _sb : "true") !== "false",
3088
+ welcomeMessage: (_ub = (_tb = readString(env, "NEXT_PUBLIC_WELCOME_MESSAGE")) != null ? _tb : readString(env, "UI_WELCOME_MESSAGE")) != null ? _ub : "Hello! I'm your AI assistant. Ask me anything about your documents.",
3089
+ visualStyle: (_wb = (_vb = readString(env, "NEXT_PUBLIC_UI_VISUAL_STYLE")) != null ? _vb : readString(env, "UI_VISUAL_STYLE")) != null ? _wb : "glass",
3090
+ borderRadius: (_yb = (_xb = readString(env, "NEXT_PUBLIC_UI_BORDER_RADIUS")) != null ? _xb : readString(env, "UI_BORDER_RADIUS")) != null ? _yb : "xl",
3091
+ allowUpload: ((_Ab = (_zb = readString(env, "NEXT_PUBLIC_ALLOW_UPLOAD")) != null ? _zb : readString(env, "UI_ALLOW_UPLOAD")) != null ? _Ab : "false") === "true"
2739
3092
  },
2740
3093
  rag: {
2741
3094
  topK: readNumber(env, "RAG_TOP_K", 5),
2742
3095
  scoreThreshold: readNumber(env, "RAG_SCORE_THRESHOLD", 0),
2743
3096
  chunkSize: readNumber(env, "RAG_CHUNK_SIZE", 1e3),
2744
3097
  chunkOverlap: readNumber(env, "RAG_CHUNK_OVERLAP", 200),
2745
- filterableFields: (_Eb = readString(env, "RAG_FILTERABLE_FIELDS")) == null ? void 0 : _Eb.split(",").map((f) => f.trim()),
3098
+ filterableFields: (_Bb = readString(env, "RAG_FILTERABLE_FIELDS")) == null ? void 0 : _Bb.split(",").map((f) => f.trim()),
2746
3099
  // Query pipeline toggles — read from .env.local
2747
3100
  useQueryTransformation: readString(env, "RAG_USE_QUERY_TRANSFORMATION") === "true",
2748
3101
  useReranking: readString(env, "RAG_USE_RERANKING") === "true",
2749
3102
  useGraphRetrieval: readString(env, "RAG_USE_GRAPH_RETRIEVAL") === "true",
2750
- architecture: (_Fb = readString(env, "RAG_ARCHITECTURE")) != null ? _Fb : "simple",
2751
- chunkingStrategy: (_Gb = readString(env, "RAG_CHUNKING_STRATEGY")) != null ? _Gb : "recursive",
3103
+ architecture: (_Cb = readString(env, "RAG_ARCHITECTURE")) != null ? _Cb : "simple",
3104
+ chunkingStrategy: (_Db = readString(env, "RAG_CHUNKING_STRATEGY")) != null ? _Db : "recursive",
2752
3105
  uiMapping: (() => {
2753
3106
  const raw = readString(env, "RAG_UI_MAPPING");
2754
3107
  if (!raw) return void 0;
@@ -2761,7 +3114,7 @@ function getEnvConfig(env = process.env, base) {
2761
3114
  },
2762
3115
  telemetry: {
2763
3116
  enabled: telemetryEnabled,
2764
- url: (_Kb = (_Jb = (_Hb = readString(env, "TELEMETRY_URL")) != null ? _Hb : readString(env, "NEXT_PUBLIC_TELEMETRY_URL")) != null ? _Jb : (_Ib = base == null ? void 0 : base.telemetry) == null ? void 0 : _Ib.url) != null ? _Kb : "https://www.retrivora.com/api/telemetry"
3117
+ url: (_Hb = (_Gb = (_Eb = readString(env, "TELEMETRY_URL")) != null ? _Eb : readString(env, "NEXT_PUBLIC_TELEMETRY_URL")) != null ? _Gb : (_Fb = base == null ? void 0 : base.telemetry) == null ? void 0 : _Fb.url) != null ? _Hb : "https://www.retrivora.com/api/telemetry"
2765
3118
  }
2766
3119
  }, readString(env, "GRAPH_DB_PROVIDER") ? {
2767
3120
  graphDb: {
@@ -2810,6 +3163,7 @@ var ConfigResolver = class {
2810
3163
  options: __spreadValues(__spreadValues({}, envConfig.embedding.options || {}), hostConfig.embedding.options || {})
2811
3164
  }) : envConfig.embedding,
2812
3165
  ui: hostConfig.ui ? mergeDefined(envConfig.ui, hostConfig.ui) : envConfig.ui,
3166
+ projectSettings: hostConfig.projectSettings || envConfig.projectSettings,
2813
3167
  rag: hostConfig.rag ? __spreadValues(__spreadValues({}, envConfig.rag), hostConfig.rag) : envConfig.rag,
2814
3168
  telemetry: hostConfig.telemetry ? __spreadValues(__spreadValues({}, envConfig.telemetry), hostConfig.telemetry) : envConfig.telemetry
2815
3169
  });
@@ -3284,8 +3638,8 @@ var OllamaProvider = class {
3284
3638
  const baseUrl = config.baseUrl || "http://localhost:11434";
3285
3639
  const modelName = config.model;
3286
3640
  try {
3287
- const axios9 = (await import("axios")).default;
3288
- const { data } = await axios9.get(`${baseUrl}/api/tags`);
3641
+ const axios11 = (await import("axios")).default;
3642
+ const { data } = await axios11.get(`${baseUrl}/api/tags`);
3289
3643
  const models = data.models || [];
3290
3644
  const hasModel = models.some((m) => m.name === modelName || m.name.startsWith(`${modelName}:`));
3291
3645
  return {
@@ -4117,7 +4471,7 @@ var UniversalLLMAdapter = class {
4117
4471
  });
4118
4472
  }
4119
4473
  async chat(messages, context) {
4120
- var _a3, _b, _c, _d, _e;
4474
+ var _a3, _b, _c, _d, _e, _f, _g2, _h, _i, _j;
4121
4475
  const path2 = (_a3 = this.opts.chatPath) != null ? _a3 : "/chat/completions";
4122
4476
  const safeMessages = (Array.isArray(messages) ? messages : []).filter((m) => Boolean(m && typeof m === "object")).map((m) => ({
4123
4477
  role: m.role || "user",
@@ -4147,16 +4501,27 @@ ${context != null ? context : "None"}` },
4147
4501
  };
4148
4502
  }
4149
4503
  try {
4504
+ console.debug(`[UniversalLLMAdapter] POST ${this.baseUrl}${path2}`);
4505
+ console.debug(`[UniversalLLMAdapter] Model: ${this.model}`);
4506
+ console.debug(`[UniversalLLMAdapter] Auth: Bearer ${((_b = this.apiKey) == null ? void 0 : _b.substring(0, 20)) || "none"}...`);
4150
4507
  const { data: data2 } = await this.http.post(path2, payload);
4151
- const extractPath2 = (_b = this.opts.responseExtractPath) != null ? _b : "choices[0].message.content";
4152
- const result2 = (_c = resolvePath(data2, extractPath2)) != null ? _c : extractContent(data2);
4508
+ const extractPath2 = (_c = this.opts.responseExtractPath) != null ? _c : "choices[0].message.content";
4509
+ const result2 = (_d = resolvePath(data2, extractPath2)) != null ? _d : extractContent(data2);
4153
4510
  if (result2 !== void 0) {
4154
4511
  return String(result2);
4155
4512
  }
4156
4513
  } catch (httpErr) {
4157
- const _g2 = globalThis;
4158
- const dispatch = _g2.__retrivoraDispatchChat;
4514
+ console.error("[UniversalLLMAdapter] \u274C HTTP chat request failed:", {
4515
+ status: (_e = httpErr == null ? void 0 : httpErr.response) == null ? void 0 : _e.status,
4516
+ statusText: (_f = httpErr == null ? void 0 : httpErr.response) == null ? void 0 : _f.statusText,
4517
+ url: (_g2 = httpErr == null ? void 0 : httpErr.config) == null ? void 0 : _g2.url,
4518
+ errorData: (_h = httpErr == null ? void 0 : httpErr.response) == null ? void 0 : _h.data,
4519
+ message: httpErr == null ? void 0 : httpErr.message
4520
+ });
4521
+ const _g3 = globalThis;
4522
+ const dispatch = _g3.__retrivoraDispatchChat;
4159
4523
  if (typeof dispatch === "function") {
4524
+ console.debug("[UniversalLLMAdapter] \u{1F504} Attempting in-process fallback dispatch");
4160
4525
  const res = await dispatch({
4161
4526
  model: this.model,
4162
4527
  messages: formattedMessages,
@@ -4171,8 +4536,8 @@ ${context != null ? context : "None"}` },
4171
4536
  throw httpErr;
4172
4537
  }
4173
4538
  const { data } = await this.http.post(path2, payload);
4174
- const extractPath = (_d = this.opts.responseExtractPath) != null ? _d : "choices[0].message.content";
4175
- const result = (_e = resolvePath(data, extractPath)) != null ? _e : extractContent(data);
4539
+ const extractPath = (_i = this.opts.responseExtractPath) != null ? _i : "choices[0].message.content";
4540
+ const result = (_j = resolvePath(data, extractPath)) != null ? _j : extractContent(data);
4176
4541
  if (result === void 0) {
4177
4542
  throw new Error(`[UniversalLLMAdapter] Could not extract text from path '${extractPath}' in response.`);
4178
4543
  }
@@ -4311,36 +4676,70 @@ ${context != null ? context : "None"}` },
4311
4676
  });
4312
4677
  }
4313
4678
  async embed(text) {
4314
- var _a3, _b, _c, _d, _e;
4679
+ var _a3, _b, _c, _d, _e, _f, _g2;
4315
4680
  const path2 = (_a3 = this.opts.embedPath) != null ? _a3 : "/embeddings";
4316
4681
  const payload = this.opts.embedPayloadTemplate ? buildPayload(this.opts.embedPayloadTemplate, { input: text, model: this.model }) : { input: text, model: this.model };
4317
4682
  try {
4318
- const { data: data2 } = await this.http.post(path2, payload);
4319
- const extractPath2 = (_b = this.opts.embedExtractPath) != null ? _b : "data[0].embedding";
4320
- const vector2 = resolvePath(data2, extractPath2);
4321
- if (Array.isArray(vector2)) return vector2;
4322
- } catch (e) {
4323
- const _g2 = globalThis;
4324
- const dispatchEmbed = _g2.__retrivoraDispatchEmbedding;
4683
+ const { data } = await this.http.post(path2, payload);
4684
+ const extractPath = (_b = this.opts.embedExtractPath) != null ? _b : "data[0].embedding";
4685
+ const vector = resolvePath(data, extractPath);
4686
+ if (Array.isArray(vector)) return vector;
4687
+ console.warn(
4688
+ `[UniversalLLMAdapter] Embedding API returned unexpected format for path '${extractPath}'. Response:`,
4689
+ data
4690
+ );
4691
+ } catch (err) {
4692
+ console.warn(
4693
+ `[UniversalLLMAdapter] HTTP embedding request failed: ${(err == null ? void 0 : err.message) || err}`,
4694
+ { path: path2, model: this.model }
4695
+ );
4696
+ const _g3 = globalThis;
4697
+ const dispatchEmbed = _g3.__retrivoraDispatchEmbedding;
4325
4698
  if (typeof dispatchEmbed === "function") {
4326
- const res = await dispatchEmbed({ input: text, model: this.model }, this.apiKey);
4327
- if ((_d = (_c = res == null ? void 0 : res.data) == null ? void 0 : _c[0]) == null ? void 0 : _d.embedding) {
4328
- return res.data[0].embedding;
4699
+ try {
4700
+ const res = await dispatchEmbed({ input: text, model: this.model }, this.apiKey);
4701
+ if ((_d = (_c = res == null ? void 0 : res.data) == null ? void 0 : _c[0]) == null ? void 0 : _d.embedding) {
4702
+ return res.data[0].embedding;
4703
+ }
4704
+ } catch (dispatchErr) {
4705
+ console.warn("[UniversalLLMAdapter] In-process dispatch embedding failed:", dispatchErr);
4329
4706
  }
4330
4707
  }
4331
4708
  }
4332
- const { data } = await this.http.post(path2, payload);
4333
- const extractPath = (_e = this.opts.embedExtractPath) != null ? _e : "data[0].embedding";
4334
- const vector = resolvePath(data, extractPath);
4335
- if (!Array.isArray(vector)) {
4336
- throw new Error(`[UniversalLLMAdapter] Could not extract embedding vector from path '${extractPath}' in response.`);
4709
+ try {
4710
+ const { data } = await this.http.post(path2, payload);
4711
+ const extractPath = (_e = this.opts.embedExtractPath) != null ? _e : "data[0].embedding";
4712
+ const vector = resolvePath(data, extractPath);
4713
+ if (Array.isArray(vector)) {
4714
+ return vector;
4715
+ }
4716
+ console.error(
4717
+ `[UniversalLLMAdapter] Retry embedding failed: unexpected response format for path '${extractPath}'. Response:`,
4718
+ data
4719
+ );
4720
+ throw new Error(
4721
+ `[UniversalLLMAdapter] Could not extract embedding vector. Expected array at '${extractPath}', got: ${typeof vector}. Response keys: ${Object.keys(data || {})}.`
4722
+ );
4723
+ } catch (err) {
4724
+ console.error(
4725
+ `[UniversalLLMAdapter] Both embedding attempts failed. Path: ${path2}, Model: ${this.model}`,
4726
+ { error: err == null ? void 0 : err.message, statusCode: (_f = err == null ? void 0 : err.response) == null ? void 0 : _f.status, response: (_g2 = err == null ? void 0 : err.response) == null ? void 0 : _g2.data }
4727
+ );
4728
+ throw new Error(
4729
+ `[UniversalLLMAdapter] Failed to generate embedding after 2 attempts: ${(err == null ? void 0 : err.message) || err}`
4730
+ );
4337
4731
  }
4338
- return vector;
4339
4732
  }
4340
4733
  async batchEmbed(texts) {
4341
4734
  const results = [];
4342
4735
  for (const text of texts) {
4343
- results.push(await this.embed(text));
4736
+ try {
4737
+ const vector = await this.embed(text);
4738
+ results.push(vector);
4739
+ } catch (err) {
4740
+ console.warn(`[UniversalLLMAdapter] batchEmbed failed for text (first 50 chars): ${text.slice(0, 50)}...`, err);
4741
+ throw err;
4742
+ }
4344
4743
  }
4345
4744
  return results;
4346
4745
  }
@@ -4751,149 +5150,8 @@ var ConfigValidator = class {
4751
5150
  }
4752
5151
  };
4753
5152
 
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";
5153
+ // src/core/Pipeline.ts
5154
+ init_version();
4897
5155
 
4898
5156
  // src/rag/DocumentChunker.ts
4899
5157
  var DocumentChunker = class {
@@ -10129,6 +10387,11 @@ var VectorPlugin = class {
10129
10387
  }
10130
10388
  };
10131
10389
 
10390
+ // src/server.ts
10391
+ init_version();
10392
+ init_ConfigFetcher();
10393
+ init_ProjectSettings();
10394
+
10132
10395
  // src/config/ConfigBuilder.ts
10133
10396
  var ConfigBuilder = class {
10134
10397
  /**
@@ -10875,6 +11138,7 @@ var DatabaseStorage = class {
10875
11138
  };
10876
11139
 
10877
11140
  // src/handlers/index.ts
11141
+ init_version();
10878
11142
  async function checkAuth(req, onAuthorize) {
10879
11143
  if (!onAuthorize) return null;
10880
11144
  try {
@@ -11006,6 +11270,35 @@ function enforceLicense(req, config, bodyLicenseKey) {
11006
11270
  };
11007
11271
  }
11008
11272
  }
11273
+ function getAllowedNamespaces(projectId) {
11274
+ const trimmed = projectId.trim();
11275
+ const withoutPrefix = trimmed.startsWith("retrivora-") ? trimmed.replace(/^retrivora-/, "") : trimmed;
11276
+ return new Set([
11277
+ trimmed,
11278
+ withoutPrefix,
11279
+ `retrivora-${withoutPrefix}`
11280
+ ].filter(Boolean));
11281
+ }
11282
+ function resolveLicensedNamespace(payload, requestedNamespace) {
11283
+ const allowed = getAllowedNamespaces(payload.projectId);
11284
+ const requested = requestedNamespace == null ? void 0 : requestedNamespace.trim();
11285
+ if (requested && !allowed.has(requested)) {
11286
+ return {
11287
+ ok: false,
11288
+ response: new Response(JSON.stringify({
11289
+ error: {
11290
+ code: "NAMESPACE_FORBIDDEN",
11291
+ message: "Requested namespace is not authorized for this license."
11292
+ }
11293
+ }), {
11294
+ status: 403,
11295
+ headers: { "Content-Type": "application/json" }
11296
+ })
11297
+ };
11298
+ }
11299
+ const defaultNamespace = payload.projectId.startsWith("retrivora-") ? payload.projectId : `retrivora-${payload.projectId}`;
11300
+ return { ok: true, namespace: requested || defaultNamespace };
11301
+ }
11009
11302
  var MAX_MESSAGE_LENGTH = 8e3;
11010
11303
  function sanitizeInput(raw) {
11011
11304
  const stripped = raw.replace(/[\u0000-\u0008\u000B\u000C\u000E-\u001F\u007F-\u009F]/g, "");
@@ -11166,6 +11459,8 @@ function createChatHandler(configOrPlugin, options) {
11166
11459
  }
11167
11460
  const history = bodyObj.history || (Array.isArray(bodyObj.messages) ? bodyObj.messages.slice(0, -1) : []);
11168
11461
  const { namespace, sessionId = "default", messageId, userMessageId } = bodyObj;
11462
+ const namespaceCheck = resolveLicensedNamespace(licenseCheck.payload, namespace);
11463
+ if (!namespaceCheck.ok) return namespaceCheck.response;
11169
11464
  const sanitized = sanitizeInput(rawMessage != null ? rawMessage : "");
11170
11465
  if (!sanitized.ok) {
11171
11466
  return NextResponse.json({ error: { code: "INVALID_INPUT", message: sanitized.error } }, { status: 400 });
@@ -11177,7 +11472,7 @@ function createChatHandler(configOrPlugin, options) {
11177
11472
  role: "user",
11178
11473
  content: message
11179
11474
  }).catch((err) => console.warn("[createChatHandler] Failed to save user message:", err));
11180
- const result = await plugin.chat(message, history, namespace);
11475
+ const result = await plugin.chat(message, history, namespaceCheck.namespace);
11181
11476
  const assistantMsgId = messageId || `assistant_${Date.now()}_${Math.random().toString(36).slice(2, 6)}`;
11182
11477
  await storage.saveMessage(sessionId, {
11183
11478
  id: assistantMsgId,
@@ -11258,6 +11553,8 @@ function createStreamHandler(configOrPlugin, options) {
11258
11553
  }
11259
11554
  const history = bodyObj.history || (Array.isArray(bodyObj.messages) ? bodyObj.messages.slice(0, -1) : []);
11260
11555
  const { namespace, sessionId = "default", messageId, userMessageId } = bodyObj;
11556
+ const namespaceCheck = resolveLicensedNamespace(licenseCheck.payload, namespace);
11557
+ if (!namespaceCheck.ok) return namespaceCheck.response;
11261
11558
  const sanitized = sanitizeInput(rawMessage != null ? rawMessage : "");
11262
11559
  if (!sanitized.ok) {
11263
11560
  return new Response(
@@ -11287,7 +11584,7 @@ function createStreamHandler(configOrPlugin, options) {
11287
11584
  }
11288
11585
  };
11289
11586
  try {
11290
- const pipelineStream = plugin.chatStream(message, history, namespace);
11587
+ const pipelineStream = plugin.chatStream(message, history, namespaceCheck.namespace);
11291
11588
  let fullReply = "";
11292
11589
  try {
11293
11590
  for (var iter = __forAwait(pipelineStream), more, temp, error; more = !(temp = await iter.next()).done; more = false) {
@@ -11393,6 +11690,8 @@ function createIngestHandler(configOrPlugin, options) {
11393
11690
  if (!Array.isArray(documents) || documents.length === 0) {
11394
11691
  return NextResponse.json({ error: "documents array is required" }, { status: 400 });
11395
11692
  }
11693
+ const namespaceCheck = resolveLicensedNamespace(licenseCheck.payload, namespace);
11694
+ if (!namespaceCheck.ok) return namespaceCheck.response;
11396
11695
  if (isFreeTier(licenseCheck.payload.tier)) {
11397
11696
  const totalIncomingBytes = documents.reduce(
11398
11697
  (sum, d) => sum + Buffer.byteLength(d.content || "", "utf8"),
@@ -11414,7 +11713,7 @@ function createIngestHandler(configOrPlugin, options) {
11414
11713
  );
11415
11714
  }
11416
11715
  }
11417
- const results = await plugin.ingest(documents, namespace);
11716
+ const results = await plugin.ingest(documents, namespaceCheck.namespace);
11418
11717
  reportTelemetry(req, plugin, "DOCUMENT_INGESTION", "success", `Ingested ${documents.length} document(s)`);
11419
11718
  return NextResponse.json({ results });
11420
11719
  } catch (err) {
@@ -11491,6 +11790,7 @@ function createUploadHandler(configOrPlugin, options) {
11491
11790
  const plugin = getOrCreatePlugin(configOrPlugin);
11492
11791
  const onAuthorize = options == null ? void 0 : options.onAuthorize;
11493
11792
  return async function POST(req, context) {
11793
+ console.log("Upload handler invoked");
11494
11794
  const authResult = await checkAuth(req, onAuthorize);
11495
11795
  if (authResult) return authResult;
11496
11796
  const config = plugin.getConfig();
@@ -11499,9 +11799,12 @@ function createUploadHandler(configOrPlugin, options) {
11499
11799
  try {
11500
11800
  const formData = await req.formData();
11501
11801
  const files = formData.getAll("files");
11802
+ console.log("Files received for upload:", files.map((f) => f.name));
11502
11803
  const namespace = formData.get("namespace") || void 0;
11503
11804
  const dimensionRaw = formData.get("dimension");
11504
11805
  const dimension = dimensionRaw ? parseInt(dimensionRaw, 10) : void 0;
11806
+ const namespaceCheck = resolveLicensedNamespace(licenseCheck.payload, namespace);
11807
+ if (!namespaceCheck.ok) return namespaceCheck.response;
11505
11808
  if (!files || files.length === 0) {
11506
11809
  return NextResponse.json({ error: "No files provided" }, { status: 400 });
11507
11810
  }
@@ -11618,7 +11921,7 @@ function createUploadHandler(configOrPlugin, options) {
11618
11921
  });
11619
11922
  }
11620
11923
  }
11621
- const results = await plugin.ingest(documents, namespace);
11924
+ const results = await plugin.ingest(documents, namespaceCheck.namespace);
11622
11925
  reportTelemetry(req, plugin, "DOCUMENT_INGESTION", "success", `Uploaded & ingested ${files.length} file(s)`);
11623
11926
  return NextResponse.json({ message: "Upload successful", results });
11624
11927
  } catch (err) {
@@ -11637,6 +11940,7 @@ function createSuggestionsHandler(configOrPlugin, options) {
11637
11940
  const config = plugin.getConfig();
11638
11941
  const licenseCheck = enforceLicense(req, config);
11639
11942
  if (!licenseCheck.ok) return licenseCheck.response;
11943
+ let effectiveLicensePayload = licenseCheck.payload;
11640
11944
  try {
11641
11945
  let query = "";
11642
11946
  let namespace = void 0;
@@ -11649,6 +11953,7 @@ function createSuggestionsHandler(configOrPlugin, options) {
11649
11953
  if (bodyLicenseKey) {
11650
11954
  const recheck = enforceLicense(req, config, bodyLicenseKey);
11651
11955
  if (!recheck.ok) return recheck.response;
11956
+ effectiveLicensePayload = recheck.payload;
11652
11957
  }
11653
11958
  } else {
11654
11959
  const url = new URL(req.url);
@@ -11658,7 +11963,9 @@ function createSuggestionsHandler(configOrPlugin, options) {
11658
11963
  if (!query || typeof query !== "string" || !query.trim()) {
11659
11964
  return NextResponse.json({ suggestions: [] });
11660
11965
  }
11661
- const suggestions = await plugin.getSuggestions(query, namespace);
11966
+ const namespaceCheck = resolveLicensedNamespace(effectiveLicensePayload, namespace);
11967
+ if (!namespaceCheck.ok) return namespaceCheck.response;
11968
+ const suggestions = await plugin.getSuggestions(query, namespaceCheck.namespace);
11662
11969
  reportTelemetry(req, plugin, "AUTO_SUGGESTIONS", "success", `Fetched ${suggestions.length} suggestions for: ${query.slice(0, 30)}`);
11663
11970
  return NextResponse.json({ suggestions });
11664
11971
  } catch (err) {
@@ -11875,6 +12182,15 @@ function createRagHandler(configOrPlugin, options) {
11875
12182
  }
11876
12183
 
11877
12184
  // src/core/LicenseValidator.ts
12185
+ init_version();
12186
+ function canUseLocalValidationFallback(baseUrl, status) {
12187
+ const explicitFallback = typeof process !== "undefined" && process.env.RETRIVORA_ALLOW_LOCAL_LICENSE_FALLBACK === "true";
12188
+ const isLocalSdkRoute = baseUrl.startsWith("/api/retrivora") || baseUrl.includes("/api/retrivora");
12189
+ if (status !== void 0) {
12190
+ return status === 404 && (explicitFallback || isLocalSdkRoute);
12191
+ }
12192
+ return explicitFallback || isLocalSdkRoute;
12193
+ }
11878
12194
  var _LicenseValidator = class _LicenseValidator {
11879
12195
  // 5-minute TTL for successful validation only
11880
12196
  constructor() {
@@ -11934,17 +12250,8 @@ var _LicenseValidator = class _LicenseValidator {
11934
12250
  }
11935
12251
  return void 0;
11936
12252
  };
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
12253
  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
12254
  const effectiveLicenseKey = (rawKey || "").trim().replace(/^["']|["']$/g, "").trim();
11947
- console.log("LicenseValidator.validate() - effectiveLicenseKey", effectiveLicenseKey);
11948
12255
  if (!effectiveLicenseKey) {
11949
12256
  this.purgeCache(effectiveLicenseKey);
11950
12257
  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 +12265,7 @@ var _LicenseValidator = class _LicenseValidator {
11958
12265
  this.cache.delete(effectiveLicenseKey);
11959
12266
  }
11960
12267
  }
11961
- const base = retrivoraApiBase || (typeof process !== "undefined" ? process.env.NEXT_PUBLIC_RETRIVORA_API_BASE || process.env.RETRIVORA_API_BASE : "") || "/api/retrivora";
12268
+ const base = retrivoraApiBase || (typeof process !== "undefined" ? process.env.NEXT_PUBLIC_RETRIVORA_API_BASE || process.env.RETRIVORA_API_BASE : "") || "https://www.retrivora.com/api";
11962
12269
  const validateUrl = `${base.replace(/\/$/, "")}/v1/license/validate`;
11963
12270
  let res = null;
11964
12271
  try {
@@ -11980,6 +12287,9 @@ var _LicenseValidator = class _LicenseValidator {
11980
12287
  });
11981
12288
  } catch (err) {
11982
12289
  try {
12290
+ if (!canUseLocalValidationFallback(base)) {
12291
+ throw err;
12292
+ }
11983
12293
  const payload = LicenseVerifier.verify(effectiveLicenseKey, projectId || "");
11984
12294
  const fallbackResp = {
11985
12295
  valid: true,
@@ -11997,7 +12307,7 @@ var _LicenseValidator = class _LicenseValidator {
11997
12307
  throw new LicenseValidationError(`License validation request failed: ${(err == null ? void 0 : err.message) || "Network error"}`);
11998
12308
  }
11999
12309
  }
12000
- if (res && !res.ok) {
12310
+ if (res && !res.ok && canUseLocalValidationFallback(base, res.status)) {
12001
12311
  try {
12002
12312
  const payload = LicenseVerifier.verify(effectiveLicenseKey, projectId || "");
12003
12313
  const fallbackResp = {
@@ -12043,6 +12353,583 @@ var _LicenseValidator = class _LicenseValidator {
12043
12353
  };
12044
12354
  _LicenseValidator.SUCCESS_CACHE_TTL_MS = 5 * 60 * 1e3;
12045
12355
  var LicenseValidator = _LicenseValidator;
12356
+
12357
+ // src/config/LicenseConfigResolver.ts
12358
+ import axios9 from "axios";
12359
+ var LicenseConfigResolver = class {
12360
+ /**
12361
+ * Validate and resolve configuration from license key
12362
+ * @param licenseKey JWT token from Retrivora (format: rtv_eyJ...)
12363
+ * @param projectId Workspace identifier
12364
+ * @returns Resolved LLM and embedding configs with provider credentials
12365
+ */
12366
+ static async resolveFromLicense(licenseKey, projectId) {
12367
+ const cacheKey = `${licenseKey}:${projectId}`;
12368
+ const cached = this.configCache.get(cacheKey);
12369
+ if (cached && Date.now() - cached.timestamp < this.CACHE_TTL_MS) {
12370
+ console.log("[LicenseConfigResolver] Using cached config for", projectId);
12371
+ return this.buildConfigs(cached.config, cached.credentials, licenseKey, projectId);
12372
+ }
12373
+ console.log("[LicenseConfigResolver] Fetching tier config from Retrivora...");
12374
+ const tierConfig = await this.fetchTierConfig(licenseKey, projectId);
12375
+ console.log("[LicenseConfigResolver] Fetching provider credentials from Retrivora...");
12376
+ const credentials = await this.fetchProviderCredentials(licenseKey, projectId);
12377
+ this.configCache.set(cacheKey, { config: tierConfig, credentials, timestamp: Date.now() });
12378
+ console.log("[LicenseConfigResolver] \u2705 Successfully resolved config from Retrivora:", {
12379
+ tier: tierConfig.tier,
12380
+ llmModel: tierConfig.llmModel,
12381
+ embeddingModel: tierConfig.embeddingModel
12382
+ });
12383
+ return this.buildConfigs(tierConfig, credentials, licenseKey, projectId);
12384
+ }
12385
+ /**
12386
+ * Fetch tier configuration from Retrivora config API
12387
+ */
12388
+ static async fetchTierConfig(licenseKey, projectId) {
12389
+ try {
12390
+ const response = await axios9.post(
12391
+ this.RETRIVORA_CONFIG_URL,
12392
+ { licenseKey, projectId },
12393
+ {
12394
+ headers: {
12395
+ "Content-Type": "application/json",
12396
+ Authorization: `Bearer ${licenseKey}`,
12397
+ "X-License-Key": licenseKey,
12398
+ "X-Project-ID": projectId
12399
+ },
12400
+ timeout: 1e4
12401
+ }
12402
+ );
12403
+ if (!response.data.success || !response.data.config) {
12404
+ throw new Error(
12405
+ `[LicenseConfigResolver] Config API returned error: ${response.data.error || response.data.message}`
12406
+ );
12407
+ }
12408
+ console.log(`[LicenseConfigResolver] Resolved tier: ${response.data.config.tier}`);
12409
+ return response.data.config;
12410
+ } catch (err) {
12411
+ console.error("[LicenseConfigResolver] Failed to fetch config:", err.message);
12412
+ throw new Error(
12413
+ `[LicenseConfigResolver] Could not validate license key or fetch tier configuration: ${err.message}`
12414
+ );
12415
+ }
12416
+ }
12417
+ /**
12418
+ * Fetch provider credentials from Retrivora credentials API
12419
+ */
12420
+ static async fetchProviderCredentials(licenseKey, projectId) {
12421
+ try {
12422
+ const response = await axios9.post(
12423
+ this.RETRIVORA_CREDENTIALS_URL,
12424
+ { licenseKey, projectId },
12425
+ {
12426
+ headers: {
12427
+ "Content-Type": "application/json",
12428
+ Authorization: `Bearer ${licenseKey}`,
12429
+ "X-License-Key": licenseKey,
12430
+ "X-Project-ID": projectId
12431
+ },
12432
+ timeout: 1e4
12433
+ }
12434
+ );
12435
+ if (!response.data.success || !response.data.credentials) {
12436
+ throw new Error(
12437
+ `[LicenseConfigResolver] Credentials API returned error: ${response.data.error || response.data.message}`
12438
+ );
12439
+ }
12440
+ console.log(`[LicenseConfigResolver] Retrieved provider credentials for project: ${projectId}`);
12441
+ return response.data.credentials;
12442
+ } catch (err) {
12443
+ console.error("[LicenseConfigResolver] Failed to fetch credentials:", err.message);
12444
+ throw new Error(
12445
+ `[LicenseConfigResolver] Could not fetch provider credentials: ${err.message}`
12446
+ );
12447
+ }
12448
+ }
12449
+ /**
12450
+ * Build LLM, embedding, and vector DB configs from tier and credentials
12451
+ */
12452
+ static buildConfigs(tierConfig, credentials, licenseKey, projectId) {
12453
+ let llmProvider = "gemini";
12454
+ let llmApiKey = credentials.geminiApiKey || licenseKey;
12455
+ if (tierConfig.llmModel.includes("gpt")) {
12456
+ llmProvider = "openai";
12457
+ } else if (tierConfig.llmModel.includes("groq") || tierConfig.llmModel.includes("llama")) {
12458
+ llmProvider = "groq";
12459
+ llmApiKey = credentials.groqApiKey || licenseKey;
12460
+ }
12461
+ const llmConfig = {
12462
+ provider: llmProvider,
12463
+ model: tierConfig.llmModel,
12464
+ apiKey: llmApiKey,
12465
+ maxTokens: tierConfig.maxTokens,
12466
+ temperature: 0.7,
12467
+ options: {}
12468
+ };
12469
+ const embeddingConfig = {
12470
+ provider: "gemini",
12471
+ model: tierConfig.embeddingModel,
12472
+ apiKey: credentials.geminiApiKey || licenseKey,
12473
+ dimensions: tierConfig.embeddingDimensions,
12474
+ options: {}
12475
+ };
12476
+ const vectorDbConfig = {
12477
+ provider: tierConfig.vectorDb.provider,
12478
+ indexName: tierConfig.vectorDb.indexName,
12479
+ options: this.getVectorDbOptions(tierConfig.vectorDb.provider, projectId, credentials)
12480
+ };
12481
+ return { llmConfig, embeddingConfig, vectorDbConfig, tierConfig, credentials };
12482
+ }
12483
+ /**
12484
+ * Get provider-specific vector DB options
12485
+ */
12486
+ static getVectorDbOptions(provider, projectId, credentials) {
12487
+ switch (provider) {
12488
+ case "pinecone":
12489
+ return {
12490
+ apiKey: credentials.pineconeApiKey,
12491
+ indexName: `retrivora-${projectId}`
12492
+ };
12493
+ case "pgvector":
12494
+ case "postgresql":
12495
+ return {
12496
+ tables: [`documents_${projectId}`]
12497
+ };
12498
+ case "mongodb":
12499
+ return {
12500
+ database: `retrivora_${projectId}`,
12501
+ collection: `vectors_${projectId}`
12502
+ };
12503
+ case "qdrant":
12504
+ return {
12505
+ collection: `retrivora_${projectId}`
12506
+ };
12507
+ default:
12508
+ return {};
12509
+ }
12510
+ }
12511
+ /**
12512
+ * Clear configuration cache (useful for testing or manual refresh)
12513
+ */
12514
+ static clearCache() {
12515
+ this.configCache.clear();
12516
+ console.log("[LicenseConfigResolver] Configuration cache cleared");
12517
+ }
12518
+ /**
12519
+ * Get cache stats for debugging
12520
+ */
12521
+ static getCacheStats() {
12522
+ return {
12523
+ size: this.configCache.size,
12524
+ entries: Array.from(this.configCache.keys())
12525
+ };
12526
+ }
12527
+ };
12528
+ LicenseConfigResolver.RETRIVORA_CONFIG_URL = "https://www.retrivora.com/api/v1/config";
12529
+ LicenseConfigResolver.RETRIVORA_CREDENTIALS_URL = "https://www.retrivora.com/api/v1/credentials";
12530
+ LicenseConfigResolver.CACHE_TTL_MS = 36e5;
12531
+ // 1 hour
12532
+ LicenseConfigResolver.configCache = /* @__PURE__ */ new Map();
12533
+
12534
+ // src/telemetry/TelemetryService.ts
12535
+ import axios10 from "axios";
12536
+ var EventType = /* @__PURE__ */ ((EventType2) => {
12537
+ EventType2["EMBEDDING_GENERATED"] = "embedding_generated";
12538
+ EventType2["LLM_CHAT_COMPLETION"] = "llm_chat_completion";
12539
+ EventType2["DOCUMENT_INGESTED"] = "document_ingested";
12540
+ EventType2["QUERY_EXECUTED"] = "query_executed";
12541
+ EventType2["ERROR_OCCURRED"] = "error_occurred";
12542
+ EventType2["CONFIGURATION_LOADED"] = "configuration_loaded";
12543
+ return EventType2;
12544
+ })(EventType || {});
12545
+ var _TelemetryService = class _TelemetryService {
12546
+ constructor(projectId, licenseKey, userTelemetryUrl) {
12547
+ this.batchSize = 10;
12548
+ this.flushIntervalMs = 3e4;
12549
+ // 30 seconds
12550
+ this.eventQueue = [];
12551
+ this.enabled = true;
12552
+ this.projectId = projectId;
12553
+ this.licenseKey = licenseKey;
12554
+ this.userTelemetryUrl = userTelemetryUrl || process.env[_TelemetryService.USER_TELEMETRY_URL_ENV_KEY];
12555
+ this.http = axios10.create({
12556
+ timeout: 5e3,
12557
+ headers: {
12558
+ "Content-Type": "application/json",
12559
+ "X-License-Key": licenseKey,
12560
+ "X-Project-ID": projectId
12561
+ }
12562
+ });
12563
+ this.startAutoFlush();
12564
+ }
12565
+ /**
12566
+ * Record a telemetry event
12567
+ */
12568
+ recordEvent(event) {
12569
+ if (!this.enabled) return;
12570
+ const _a3 = event, { licenseKey } = _a3, safeEvent = __objRest(_a3, ["licenseKey"]);
12571
+ const completeEvent = __spreadValues({
12572
+ eventType: event.eventType || "error_occurred" /* ERROR_OCCURRED */,
12573
+ projectId: this.projectId,
12574
+ timestamp: event.timestamp || Date.now()
12575
+ }, safeEvent);
12576
+ this.eventQueue.push(completeEvent);
12577
+ if (this.eventQueue.length >= this.batchSize) {
12578
+ this.flush().catch((err) => {
12579
+ console.warn("[TelemetryService] Flush error:", err.message);
12580
+ });
12581
+ }
12582
+ }
12583
+ /**
12584
+ * Record LLM completion event
12585
+ */
12586
+ recordLLMCompletion(data) {
12587
+ this.recordEvent({
12588
+ eventType: "llm_chat_completion" /* LLM_CHAT_COMPLETION */,
12589
+ model: data.model,
12590
+ inputTokens: data.inputTokens,
12591
+ outputTokens: data.outputTokens,
12592
+ totalTokens: data.inputTokens + data.outputTokens,
12593
+ durationMs: data.durationMs,
12594
+ operationId: data.operationId,
12595
+ metadata: data.metadata
12596
+ });
12597
+ }
12598
+ /**
12599
+ * Record embedding generation event
12600
+ */
12601
+ recordEmbeddingGenerated(data) {
12602
+ this.recordEvent({
12603
+ eventType: "embedding_generated" /* EMBEDDING_GENERATED */,
12604
+ embeddingModel: data.embeddingModel,
12605
+ vectorDimensions: data.vectorDimensions,
12606
+ textLength: data.textLength,
12607
+ durationMs: data.durationMs,
12608
+ operationId: data.operationId
12609
+ });
12610
+ }
12611
+ /**
12612
+ * Record document ingestion event
12613
+ */
12614
+ recordDocumentIngested(data) {
12615
+ this.recordEvent({
12616
+ eventType: "document_ingested" /* DOCUMENT_INGESTED */,
12617
+ documentId: data.documentId,
12618
+ documentName: data.documentName,
12619
+ documentSize: data.documentSize,
12620
+ chunksGenerated: data.chunksGenerated,
12621
+ durationMs: data.durationMs
12622
+ });
12623
+ }
12624
+ /**
12625
+ * Record query execution event
12626
+ */
12627
+ recordQueryExecuted(data) {
12628
+ this.recordEvent({
12629
+ eventType: "query_executed" /* QUERY_EXECUTED */,
12630
+ queryText: data.queryText,
12631
+ resultCount: data.resultCount,
12632
+ durationMs: data.durationMs,
12633
+ operationId: data.operationId
12634
+ });
12635
+ }
12636
+ /**
12637
+ * Record error event
12638
+ */
12639
+ recordError(error, context) {
12640
+ this.recordEvent({
12641
+ eventType: "error_occurred" /* ERROR_OCCURRED */,
12642
+ errorCode: error.code || "UNKNOWN",
12643
+ errorMessage: error.message,
12644
+ stackTrace: error.stack,
12645
+ metadata: context
12646
+ });
12647
+ }
12648
+ /**
12649
+ * Flush all queued events to telemetry endpoints
12650
+ */
12651
+ async flush() {
12652
+ if (this.eventQueue.length === 0) return;
12653
+ const events = this.eventQueue.splice(0, this.batchSize);
12654
+ const payload = {
12655
+ events: events.map((e) => {
12656
+ const eventWithoutKey = __objRest(e, []);
12657
+ return eventWithoutKey;
12658
+ }),
12659
+ batchId: `${this.projectId}_${Date.now()}`
12660
+ };
12661
+ try {
12662
+ await this.http.post(_TelemetryService.RETRIVORA_TELEMETRY_URL, payload);
12663
+ console.log(`[TelemetryService] Flushed ${events.length} events to Retrivora`);
12664
+ } catch (err) {
12665
+ console.warn("[TelemetryService] Failed to send telemetry to Retrivora:", err.message);
12666
+ this.eventQueue.unshift(...events);
12667
+ }
12668
+ if (this.userTelemetryUrl) {
12669
+ try {
12670
+ await axios10.post(this.userTelemetryUrl, payload, {
12671
+ timeout: 5e3,
12672
+ headers: {
12673
+ "Content-Type": "application/json",
12674
+ "X-Project-ID": this.projectId
12675
+ }
12676
+ });
12677
+ console.log(`[TelemetryService] Flushed ${events.length} events to user telemetry`);
12678
+ } catch (err) {
12679
+ console.warn("[TelemetryService] Failed to send telemetry to user endpoint:", err.message);
12680
+ }
12681
+ }
12682
+ }
12683
+ /**
12684
+ * Start automatic flush interval
12685
+ */
12686
+ startAutoFlush() {
12687
+ this.flushTimer = setInterval(() => {
12688
+ this.flush().catch((err) => {
12689
+ console.warn("[TelemetryService] Auto-flush error:", err.message);
12690
+ });
12691
+ }, this.flushIntervalMs);
12692
+ }
12693
+ /**
12694
+ * Stop telemetry service and flush remaining events
12695
+ */
12696
+ async shutdown() {
12697
+ if (this.flushTimer) {
12698
+ clearInterval(this.flushTimer);
12699
+ }
12700
+ await this.flush();
12701
+ this.enabled = false;
12702
+ }
12703
+ /**
12704
+ * Disable telemetry temporarily
12705
+ */
12706
+ disable() {
12707
+ this.enabled = false;
12708
+ }
12709
+ /**
12710
+ * Enable telemetry
12711
+ */
12712
+ enable() {
12713
+ this.enabled = true;
12714
+ }
12715
+ /**
12716
+ * Get current queue size (for debugging)
12717
+ */
12718
+ getQueueSize() {
12719
+ return this.eventQueue.length;
12720
+ }
12721
+ };
12722
+ _TelemetryService.RETRIVORA_TELEMETRY_URL = "https://www.retrivora.com/api/telemetry";
12723
+ _TelemetryService.USER_TELEMETRY_URL_ENV_KEY = "TELEMETRY_URL";
12724
+ var TelemetryService = _TelemetryService;
12725
+ var globalTelemetryService = null;
12726
+ function getTelemetryService() {
12727
+ return globalTelemetryService;
12728
+ }
12729
+ function initializeTelemetryService(projectId, licenseKey, userTelemetryUrl) {
12730
+ globalTelemetryService = new TelemetryService(projectId, licenseKey, userTelemetryUrl);
12731
+ console.log("[TelemetryService] Initialized for project:", projectId);
12732
+ return globalTelemetryService;
12733
+ }
12734
+ async function shutdownTelemetryService() {
12735
+ if (globalTelemetryService) {
12736
+ await globalTelemetryService.shutdown();
12737
+ globalTelemetryService = null;
12738
+ }
12739
+ }
12740
+
12741
+ // src/LicensedRetrivora.ts
12742
+ var LicensedRetrivora = class {
12743
+ constructor(options) {
12744
+ this.initialized = false;
12745
+ this.licenseKey = options.licenseKey;
12746
+ this.projectId = options.projectId;
12747
+ if (options.enableTelemetry !== false) {
12748
+ initializeTelemetryService(this.projectId, this.licenseKey, options.userTelemetryUrl);
12749
+ }
12750
+ }
12751
+ /**
12752
+ * Initialize the SDK by validating license and fetching config
12753
+ */
12754
+ generateId() {
12755
+ return `${Date.now()}-${Math.random().toString(36).substring(2, 9)}`;
12756
+ }
12757
+ /**
12758
+ * Initialize the SDK by validating license and fetching config
12759
+ */
12760
+ async initialize() {
12761
+ if (this.initialized) {
12762
+ console.log("[LicensedRetrivora] Already initialized");
12763
+ return;
12764
+ }
12765
+ console.log("[LicensedRetrivora] Initializing with license key...");
12766
+ const operationId = this.generateId();
12767
+ try {
12768
+ const { llmConfig, embeddingConfig, vectorDbConfig, tierConfig } = await LicenseConfigResolver.resolveFromLicense(this.licenseKey, this.projectId);
12769
+ const telemetry = getTelemetryService();
12770
+ if (telemetry) {
12771
+ telemetry.recordEvent({
12772
+ eventType: "configuration_loaded" /* CONFIGURATION_LOADED */,
12773
+ operationId,
12774
+ metadata: {
12775
+ tier: tierConfig.tier,
12776
+ llmModel: tierConfig.llmModel,
12777
+ embeddingModel: tierConfig.embeddingModel,
12778
+ vectorDb: tierConfig.vectorDb.provider
12779
+ }
12780
+ });
12781
+ }
12782
+ this.ragConfig = {
12783
+ projectId: this.projectId,
12784
+ licenseKey: this.licenseKey,
12785
+ llm: llmConfig,
12786
+ embedding: embeddingConfig,
12787
+ vectorDb: vectorDbConfig,
12788
+ rag: {
12789
+ topK: tierConfig.topK,
12790
+ chunkSize: tierConfig.chunkSize,
12791
+ chunkOverlap: tierConfig.chunkOverlap,
12792
+ scoreThreshold: 0
12793
+ },
12794
+ telemetry: {
12795
+ enabled: true,
12796
+ url: "https://www.retrivora.com/api/telemetry"
12797
+ }
12798
+ };
12799
+ this.pipeline = new Pipeline(this.ragConfig);
12800
+ await this.pipeline.initialize();
12801
+ this.initialized = true;
12802
+ console.log(`[LicensedRetrivora] Initialized successfully for tier: ${tierConfig.tier}`);
12803
+ } catch (error) {
12804
+ const telemetry = getTelemetryService();
12805
+ if (telemetry && error instanceof Error) {
12806
+ telemetry.recordError(error, { operationId });
12807
+ await telemetry.flush();
12808
+ }
12809
+ throw error;
12810
+ }
12811
+ }
12812
+ /**
12813
+ * Ingest documents (upload files to vector database)
12814
+ * Returns success/failure status to end-user
12815
+ */
12816
+ async ingest(documents) {
12817
+ if (!this.initialized || !this.pipeline) {
12818
+ throw new Error("[LicensedRetrivora] SDK not initialized. Call initialize() first.");
12819
+ }
12820
+ const operationId = this.generateId();
12821
+ const telemetry = getTelemetryService();
12822
+ const startTime = Date.now();
12823
+ try {
12824
+ console.log(`[LicensedRetrivora] Starting ingestion of ${documents.length} document(s)`);
12825
+ const results = await this.pipeline.ingest(documents);
12826
+ const durationMs = Date.now() - startTime;
12827
+ if (telemetry) {
12828
+ for (const result of results) {
12829
+ telemetry.recordDocumentIngested({
12830
+ documentId: String(result.docId),
12831
+ documentName: String(result.docId),
12832
+ documentSize: 0,
12833
+ // TODO: track actual size
12834
+ chunksGenerated: result.chunksIngested,
12835
+ durationMs
12836
+ });
12837
+ }
12838
+ }
12839
+ const successCount = results.length;
12840
+ return {
12841
+ success: successCount > 0,
12842
+ message: `Successfully ingested ${successCount} document(s). Data is now available for search.`,
12843
+ documentIds: results.map((r) => String(r.docId))
12844
+ };
12845
+ } catch (error) {
12846
+ const durationMs = Date.now() - startTime;
12847
+ if (telemetry && error instanceof Error) {
12848
+ telemetry.recordError(error, { operationId, durationMs });
12849
+ await telemetry.flush();
12850
+ }
12851
+ console.error("[LicensedRetrivora] Ingestion failed:", error);
12852
+ throw error;
12853
+ }
12854
+ }
12855
+ /**
12856
+ * Execute a user query and get response
12857
+ * Returns only the response text and sources (abstracted from underlying models)
12858
+ */
12859
+ async query(queryText, options) {
12860
+ var _a3;
12861
+ if (!this.initialized || !this.pipeline) {
12862
+ throw new Error("[LicensedRetrivora] SDK not initialized. Call initialize() first.");
12863
+ }
12864
+ const operationId = this.generateId();
12865
+ const telemetry = getTelemetryService();
12866
+ const startTime = Date.now();
12867
+ try {
12868
+ console.log(`[LicensedRetrivora] Executing query: "${queryText.substring(0, 100)}..."`);
12869
+ const response = await this.pipeline.runNormalQuery(queryText);
12870
+ const durationMs = Date.now() - startTime;
12871
+ if (telemetry) {
12872
+ telemetry.recordQueryExecuted({
12873
+ queryText,
12874
+ resultCount: ((_a3 = response.sources) == null ? void 0 : _a3.length) || 0,
12875
+ durationMs,
12876
+ operationId
12877
+ });
12878
+ }
12879
+ return {
12880
+ reply: response.reply,
12881
+ sources: response.sources
12882
+ };
12883
+ } catch (error) {
12884
+ const durationMs = Date.now() - startTime;
12885
+ if (telemetry && error instanceof Error) {
12886
+ telemetry.recordError(error, { operationId, durationMs });
12887
+ await telemetry.flush();
12888
+ }
12889
+ console.error("[LicensedRetrivora] Query failed:", error);
12890
+ throw error;
12891
+ }
12892
+ }
12893
+ /**
12894
+ * Get license tier information (for UI display if needed)
12895
+ */
12896
+ async getTierInfo() {
12897
+ if (!this.ragConfig) {
12898
+ throw new Error("[LicensedRetrivora] SDK not initialized.");
12899
+ }
12900
+ return {
12901
+ tier: "Standard",
12902
+ // TODO: fetch from tier config
12903
+ model: this.ragConfig.llm.model,
12904
+ embeddingModel: this.ragConfig.embedding.model
12905
+ };
12906
+ }
12907
+ /**
12908
+ * Cleanup and shutdown
12909
+ */
12910
+ async shutdown() {
12911
+ await shutdownTelemetryService();
12912
+ this.initialized = false;
12913
+ console.log("[LicensedRetrivora] Shutdown complete");
12914
+ }
12915
+ /**
12916
+ * Check if SDK is initialized
12917
+ */
12918
+ isInitialized() {
12919
+ return this.initialized;
12920
+ }
12921
+ /**
12922
+ * Get current RAG configuration (for debugging)
12923
+ */
12924
+ getConfig() {
12925
+ return this.ragConfig;
12926
+ }
12927
+ };
12928
+ async function createRetrivora(options) {
12929
+ const retrivora = new LicensedRetrivora(options);
12930
+ await retrivora.initialize();
12931
+ return retrivora;
12932
+ }
12046
12933
  export {
12047
12934
  AnthropicProvider,
12048
12935
  AuthenticationException,
@@ -12052,6 +12939,7 @@ export {
12052
12939
  ChartRendererStrategy,
12053
12940
  ChromaDBProvider,
12054
12941
  ConfigBuilder,
12942
+ ConfigFetcher,
12055
12943
  ConfigResolver,
12056
12944
  ConfigValidator,
12057
12945
  ConfigurationException,
@@ -12060,13 +12948,16 @@ export {
12060
12948
  EmbeddingFailedException,
12061
12949
  EmbeddingStrategy,
12062
12950
  EmbeddingStrategyResolver,
12951
+ EventType,
12063
12952
  GroqProvider,
12064
12953
  IntentClassifier,
12065
12954
  LLMFactory,
12066
12955
  LLM_PROFILES,
12956
+ LicenseConfigResolver,
12067
12957
  LicenseValidationError,
12068
12958
  LicenseValidator,
12069
12959
  LicenseVerifier,
12960
+ LicensedRetrivora,
12070
12961
  MilvusProvider,
12071
12962
  MixedRendererStrategy,
12072
12963
  MongoDBProvider,
@@ -12099,6 +12990,7 @@ export {
12099
12990
  SDKVersionUnsupportedError,
12100
12991
  SDK_VERSION,
12101
12992
  TableRendererStrategy,
12993
+ TelemetryService,
12102
12994
  TextRendererStrategy,
12103
12995
  UniversalLLMAdapter,
12104
12996
  UniversalVectorProvider,
@@ -12107,17 +12999,26 @@ export {
12107
12999
  VisualizationDecisionEngine,
12108
13000
  WeaviateProvider,
12109
13001
  createChatHandler,
13002
+ createDefaultProjectSettings,
12110
13003
  createFeedbackHandler,
12111
13004
  createFromPreset,
12112
13005
  createHealthHandler,
12113
13006
  createHistoryHandler,
12114
13007
  createIngestHandler,
12115
13008
  createRagHandler,
13009
+ createRetrivora,
12116
13010
  createSessionsHandler,
12117
13011
  createStreamHandler,
12118
13012
  createUploadHandler,
12119
13013
  decideVisualization,
12120
13014
  getRagConfig,
13015
+ getRuntimeConfig,
13016
+ getTelemetryService,
13017
+ initializeTelemetryService,
13018
+ injectRuntimeConfig,
13019
+ normalizeProjectSettings,
13020
+ projectSettingsToUiConfig,
13021
+ shutdownTelemetryService,
12121
13022
  sseErrorFrame,
12122
13023
  sseFrame,
12123
13024
  sseMetaFrame,