@retrivora-ai/rag-engine 2.2.7 → 2.2.9

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.
package/dist/index.mjs CHANGED
@@ -18,6 +18,12 @@ var __spreadValues = (a, b) => {
18
18
  return a;
19
19
  };
20
20
  var __spreadProps = (a, b) => __defProps(a, __getOwnPropDescs(b));
21
+ var __require = /* @__PURE__ */ ((x) => typeof require !== "undefined" ? require : typeof Proxy !== "undefined" ? new Proxy(x, {
22
+ get: (a, b) => (typeof require !== "undefined" ? require : a)[b]
23
+ }) : x)(function(x) {
24
+ if (typeof require !== "undefined") return require.apply(this, arguments);
25
+ throw Error('Dynamic require of "' + x + '" is not supported');
26
+ });
21
27
  var __objRest = (source, exclude) => {
22
28
  var target = {};
23
29
  for (var prop in source)
@@ -2759,7 +2765,7 @@ function useRagChat(projectId, options = {}) {
2759
2765
  }, [messages]);
2760
2766
  const sendMessage = useCallback(
2761
2767
  async (text, opts) => {
2762
- var _a, _b, _c, _d, _e;
2768
+ var _a, _b, _c, _d, _e, _f;
2763
2769
  const trimmed = text.trim();
2764
2770
  if (!trimmed || isLoading) return;
2765
2771
  lastInputRef.current = trimmed;
@@ -2791,9 +2797,18 @@ function useRagChat(projectId, options = {}) {
2791
2797
  messageId: assistantMessageId,
2792
2798
  userMessageId: userMsgId
2793
2799
  });
2794
- const fetchHeaders = __spreadValues({
2800
+ const getHeader = (headersObj, name) => {
2801
+ if (!headersObj) return void 0;
2802
+ const target = name.toLowerCase();
2803
+ for (const [k, v] of Object.entries(headersObj)) {
2804
+ if (k.toLowerCase() === target) return v;
2805
+ }
2806
+ return void 0;
2807
+ };
2808
+ const resolvedLicenseKey = options.licenseKey || getHeader(options.headers, "x-license-key") || ((_b = getHeader(options.headers, "authorization")) == null ? void 0 : _b.replace(/^Bearer\s+/i, "")) || (typeof process !== "undefined" ? process.env.NEXT_PUBLIC_RETRIVORA_LICENSE_KEY || process.env.RETRIVORA_LICENSE_KEY : "") || "";
2809
+ const fetchHeaders = __spreadValues(__spreadValues({
2795
2810
  "Content-Type": "application/json"
2796
- }, options.headers || {});
2811
+ }, resolvedLicenseKey ? { "x-license-key": resolvedLicenseKey } : {}), options.headers || {});
2797
2812
  let response = await fetch(primaryUrl, {
2798
2813
  method: "POST",
2799
2814
  headers: fetchHeaders,
@@ -2811,10 +2826,10 @@ function useRagChat(projectId, options = {}) {
2811
2826
  }
2812
2827
  if (!response.ok) {
2813
2828
  const errorData = await response.json().catch(() => ({}));
2814
- if (response.status === 403 || response.status === 401 || typeof errorData.error === "string" && errorData.error.toLowerCase().includes("license") || ((_b = errorData.error) == null ? void 0 : _b.type) === "license_revoked") {
2829
+ if (response.status === 403 || response.status === 401 || typeof errorData.error === "string" && errorData.error.toLowerCase().includes("license") || ((_c = errorData.error) == null ? void 0 : _c.type) === "license_revoked") {
2815
2830
  throw new Error("Your Retrivora license is no longer valid. Please contact your administrator or obtain a valid license key.");
2816
2831
  }
2817
- throw new Error(((_c = errorData.error) == null ? void 0 : _c.message) || errorData.error || `Server returned ${response.status}`);
2832
+ throw new Error(((_d = errorData.error) == null ? void 0 : _d.message) || errorData.error || `Server returned ${response.status}`);
2818
2833
  }
2819
2834
  if (!response.body) {
2820
2835
  throw new Error("No response body received from server");
@@ -2878,7 +2893,7 @@ function useRagChat(projectId, options = {}) {
2878
2893
  pendingThinkingRef.current = thinkingContent;
2879
2894
  scheduleFlush(assistantMessageId);
2880
2895
  } else if (frame.type === "metadata") {
2881
- sources = (_d = frame.sources) != null ? _d : [];
2896
+ sources = (_e = frame.sources) != null ? _e : [];
2882
2897
  thinkingMs = frame.thinkingMs;
2883
2898
  } else if (frame.type === "ui_transformation") {
2884
2899
  uiTransformation = frame.data;
@@ -2894,7 +2909,7 @@ function useRagChat(projectId, options = {}) {
2894
2909
  if (frame.type === "text" && frame.text) assistantContent += frame.text;
2895
2910
  else if (frame.type === "thinking" && frame.text) thinkingContent += frame.text;
2896
2911
  else if (frame.type === "metadata") {
2897
- sources = (_e = frame.sources) != null ? _e : [];
2912
+ sources = (_f = frame.sources) != null ? _f : [];
2898
2913
  thinkingMs = frame.thinkingMs;
2899
2914
  } else if (frame.type === "observability") trace = frame.data;
2900
2915
  }
@@ -3034,7 +3049,7 @@ function useRagChat(projectId, options = {}) {
3034
3049
  // package.json
3035
3050
  var package_default = {
3036
3051
  name: "@retrivora-ai/rag-engine",
3037
- version: "2.2.7",
3052
+ version: "2.2.9",
3038
3053
  description: "Retrivora AI is a plug-and-play AI engine for RAG chat experiences \u2014 generic vector DB + LLM provider, embeddable or standalone.",
3039
3054
  author: "Abhinav Alkuchi",
3040
3055
  license: "UNLICENSED",
@@ -3224,6 +3239,213 @@ var LicenseValidationError = class extends RetrivoraError {
3224
3239
  }
3225
3240
  };
3226
3241
 
3242
+ // src/core/LicenseVerifier.ts
3243
+ import * as crypto from "crypto";
3244
+ var LicenseVerifier = class {
3245
+ /**
3246
+ * Decodes, verifies signature, and checks metadata of a license key.
3247
+ *
3248
+ * @param licenseKey - Base64url signed JWT license key.
3249
+ * @param currentProjectId - Project namespace ID.
3250
+ * @param publicKeyOverride - Optional override for unit/integration tests.
3251
+ */
3252
+ static verify(licenseKey, currentProjectId, provider, publicKeyOverride) {
3253
+ const isProduction = process.env.NODE_ENV === "production";
3254
+ const now = Date.now();
3255
+ if (licenseKey) {
3256
+ const cacheKey = `${licenseKey}:${currentProjectId}:${provider || ""}:${publicKeyOverride || ""}`;
3257
+ const cached = this.cache.get(cacheKey);
3258
+ if (cached && now - cached.cachedAt < this.CACHE_TTL_MS) {
3259
+ const currentTimestampSec = Math.floor(now / 1e3);
3260
+ if (cached.payload.expiresAt && currentTimestampSec > cached.payload.expiresAt) {
3261
+ this.cache.delete(cacheKey);
3262
+ } else {
3263
+ return cached.payload;
3264
+ }
3265
+ }
3266
+ }
3267
+ if (!licenseKey) {
3268
+ if (isProduction) {
3269
+ throw new ConfigurationException(
3270
+ "[Retrivora SDK] License key (licenseKey) is required in production environments."
3271
+ );
3272
+ }
3273
+ console.warn(
3274
+ `\x1B[33m[Retrivora SDK] WARNING: Running without a license key. This namespace (${currentProjectId}) is permitted for local development only.\x1B[0m`
3275
+ );
3276
+ return {
3277
+ projectId: currentProjectId,
3278
+ expiresAt: Math.floor(Date.now() / 1e3) + 86400,
3279
+ // Valid for 24h
3280
+ tier: "hobby"
3281
+ };
3282
+ }
3283
+ try {
3284
+ const rawToken = licenseKey.replace(/^rtv_/i, "").trim();
3285
+ const parts = rawToken.split(".");
3286
+ if (parts.length !== 3) {
3287
+ throw new Error("Malformed token structure (expected 3 parts).");
3288
+ }
3289
+ const [headerB64, payloadB64, signatureB64] = parts;
3290
+ const dataToVerify = `${headerB64}.${payloadB64}`;
3291
+ const publicKey = publicKeyOverride != null ? publicKeyOverride : this.PUBLIC_KEY;
3292
+ const signature = Buffer.from(signatureB64, "base64url");
3293
+ const data = Buffer.from(dataToVerify);
3294
+ const isValid = crypto.verify(
3295
+ "sha256",
3296
+ data,
3297
+ publicKey,
3298
+ signature
3299
+ );
3300
+ if (!isValid) {
3301
+ throw new Error("Signature verification failed.");
3302
+ }
3303
+ const payload = JSON.parse(
3304
+ Buffer.from(payloadB64, "base64url").toString("utf8")
3305
+ );
3306
+ if (!payload.projectId) {
3307
+ throw new Error('License payload is missing "projectId".');
3308
+ }
3309
+ const isProjectMatch = payload.projectId === currentProjectId || payload.projectId === `retrivora-${currentProjectId}` || `retrivora-${payload.projectId}` === currentProjectId;
3310
+ if (!isProjectMatch) {
3311
+ throw new Error(
3312
+ `Project ID mismatch. License is bound to project namespace "${payload.projectId}" but configuration has "${currentProjectId}".`
3313
+ );
3314
+ }
3315
+ if (!payload.expiresAt) {
3316
+ throw new Error('License payload is missing expiration ("expiresAt").');
3317
+ }
3318
+ const currentTimestampSec = Math.floor(Date.now() / 1e3);
3319
+ if (currentTimestampSec > payload.expiresAt) {
3320
+ throw new Error(
3321
+ `License key has expired. Expiration: ${new Date(
3322
+ payload.expiresAt * 1e3
3323
+ ).toDateString()}`
3324
+ );
3325
+ }
3326
+ if (isProduction && provider) {
3327
+ const tier = (payload.tier || "").toLowerCase();
3328
+ const normalizedProvider = provider.toLowerCase();
3329
+ if (tier === "hobby") {
3330
+ const allowedHobby = ["postgresql", "pgvector", "supabase"];
3331
+ if (!allowedHobby.includes(normalizedProvider)) {
3332
+ throw new Error(
3333
+ `The database provider "${provider}" is not allowed on the Hobby tier. Hobby tier is restricted to PostgreSQL and Supabase. Please upgrade to a Developer Pro or Enterprise plan.`
3334
+ );
3335
+ }
3336
+ } else if (tier === "pro" || tier === "developer_pro" || tier === "premium" || tier === "growth" || tier === "free_trial" || tier === "free_tier" || tier === "free") {
3337
+ const allowedPro = [
3338
+ "postgresql",
3339
+ "pgvector",
3340
+ "supabase",
3341
+ "pinecone",
3342
+ "qdrant",
3343
+ "mongodb",
3344
+ "milvus",
3345
+ "chroma",
3346
+ "chromadb"
3347
+ ];
3348
+ if (!allowedPro.includes(normalizedProvider)) {
3349
+ throw new Error(
3350
+ `The database provider "${provider}" is not allowed on the Developer Pro tier. Please upgrade to an Enterprise plan.`
3351
+ );
3352
+ }
3353
+ }
3354
+ }
3355
+ if (licenseKey) {
3356
+ const cacheKey = `${licenseKey}:${currentProjectId}:${provider || ""}:${publicKeyOverride || ""}`;
3357
+ this.cache.set(cacheKey, { payload, cachedAt: now });
3358
+ }
3359
+ return payload;
3360
+ } catch (err) {
3361
+ const message = err instanceof Error ? err.message : String(err);
3362
+ throw new ConfigurationException(
3363
+ `[Retrivora SDK] License key validation failed: ${message}`
3364
+ );
3365
+ }
3366
+ }
3367
+ static async verifyIP(licenseKey) {
3368
+ if (!licenseKey) return;
3369
+ try {
3370
+ const parts = licenseKey.split(".");
3371
+ if (parts.length !== 3) return;
3372
+ const [, payloadB64] = parts;
3373
+ const payload = JSON.parse(
3374
+ Buffer.from(payloadB64, "base64url").toString("utf8")
3375
+ );
3376
+ const tier = (payload.tier || "").toLowerCase();
3377
+ if (tier === "enterprise" || tier === "custom") {
3378
+ return;
3379
+ }
3380
+ if (payload.ipv4 || payload.ipv6) {
3381
+ let currentIpv4 = "";
3382
+ let currentIpv6 = "";
3383
+ try {
3384
+ const res = await fetch("https://api4.ipify.org?format=json", { signal: AbortSignal.timeout(3e3) });
3385
+ const data = await res.json();
3386
+ currentIpv4 = data.ip;
3387
+ } catch (e) {
3388
+ }
3389
+ try {
3390
+ const res = await fetch("https://api6.ipify.org?format=json", { signal: AbortSignal.timeout(3e3) });
3391
+ const data = await res.json();
3392
+ currentIpv6 = data.ip;
3393
+ } catch (e) {
3394
+ }
3395
+ const localIps = [];
3396
+ try {
3397
+ const osModule = __require("os");
3398
+ const interfaces = osModule.networkInterfaces();
3399
+ for (const name of Object.keys(interfaces)) {
3400
+ for (const iface of interfaces[name] || []) {
3401
+ if (!iface.internal) {
3402
+ localIps.push(iface.address);
3403
+ }
3404
+ }
3405
+ }
3406
+ } catch (e) {
3407
+ }
3408
+ const isIpv4Match = payload.ipv4 && (currentIpv4 === payload.ipv4 || localIps.includes(payload.ipv4));
3409
+ const isIpv6Match = payload.ipv6 && (currentIpv6 === payload.ipv6 || localIps.includes(payload.ipv6));
3410
+ if (payload.ipv4 && payload.ipv6) {
3411
+ if (!isIpv4Match && !isIpv6Match) {
3412
+ throw new Error(
3413
+ `License key access restricted. This license key was created for a different system (authorized IPv4: ${payload.ipv4}, IPv6: ${payload.ipv6}) and cannot be used on this machine.`
3414
+ );
3415
+ }
3416
+ } else if (payload.ipv4 && !isIpv4Match) {
3417
+ throw new Error(
3418
+ `License key access restricted. This license key was created for a different system (authorized IPv4: ${payload.ipv4}) and cannot be used on this machine.`
3419
+ );
3420
+ } else if (payload.ipv6 && !isIpv6Match) {
3421
+ throw new Error(
3422
+ `License key access restricted. This license key was created for a different system (authorized IPv6: ${payload.ipv6}) and cannot be used on this machine.`
3423
+ );
3424
+ }
3425
+ }
3426
+ } catch (err) {
3427
+ if (err.message.includes("License key access restricted")) {
3428
+ throw new ConfigurationException(`[Retrivora SDK] ${err.message}`);
3429
+ }
3430
+ }
3431
+ }
3432
+ };
3433
+ // A simple in-memory cache to save CPU overhead of cryptographic signature checks.
3434
+ LicenseVerifier.cache = /* @__PURE__ */ new Map();
3435
+ LicenseVerifier.CACHE_TTL_MS = 60 * 1e3;
3436
+ // Cache verified license for 60 seconds
3437
+ // Retrivora's Public Key used to verify the license key signature.
3438
+ // In production, this matches the private key held by Retrivora SaaS.
3439
+ LicenseVerifier.PUBLIC_KEY = `-----BEGIN PUBLIC KEY-----
3440
+ MIIBIjANBgkqhkiG9w0BAQEFAAOCAQ8AMIIBCgKCAQEArMieCkCBtTfByRNOserm
3441
+ XM4T0Am29JyNzB4XQPe+WJJ56CN73H1HLXx9n1ByFcxkEJ9po+SURj5DnvUXwEy+
3442
+ xstx33wDPpVmcMQe33j5CRYS0S4gICiNqIRN7XkTlJtrcXqrmh1/hdOAwfRbjO1T
3443
+ NVtORHwUwWfI/lBLyxUPGtKPed+0fQ7NtcW4o00JXxs3EjCB5BV9CbnXoTjQb/4h
3444
+ iwZof4l8rb7oaNzOsVg0RSyxsETX7Ex5sI0CjBz1p2mYp4oVhw/A/h8Ls7H0XzjC
3445
+ +Eb6BLtsytt5JHoSp0jExLlCpDmpys2L+kETcBVx+IqiXtdN1n6KbkksvEDUVzLI
3446
+ MwIDAQAB
3447
+ -----END PUBLIC KEY-----`;
3448
+
3227
3449
  // src/core/LicenseValidator.ts
3228
3450
  var _LicenseValidator = class _LicenseValidator {
3229
3451
  // 5-minute TTL for successful validation only
@@ -3250,6 +3472,7 @@ var _LicenseValidator = class _LicenseValidator {
3250
3472
  * Validate license status and SDK version against Retrivora License Service
3251
3473
  */
3252
3474
  async validate(request) {
3475
+ var _a;
3253
3476
  const {
3254
3477
  licenseKey,
3255
3478
  projectId,
@@ -3259,33 +3482,42 @@ var _LicenseValidator = class _LicenseValidator {
3259
3482
  retrivoraApiBase,
3260
3483
  headers: customHeaders
3261
3484
  } = request;
3262
- if (!licenseKey) {
3263
- this.purgeCache(licenseKey);
3264
- throw new LicenseValidationError("Missing RETRIVORA_LICENSE_KEY in request.");
3485
+ const getHeader = (name) => {
3486
+ if (!customHeaders) return void 0;
3487
+ const target = name.toLowerCase();
3488
+ for (const [k, v] of Object.entries(customHeaders)) {
3489
+ if (k.toLowerCase() === target) return v;
3490
+ }
3491
+ return void 0;
3492
+ };
3493
+ const effectiveLicenseKey = licenseKey || getHeader("x-license-key") || ((_a = getHeader("authorization")) == null ? void 0 : _a.replace(/^Bearer\s+/i, "")) || (typeof process !== "undefined" ? process.env.NEXT_PUBLIC_RETRIVORA_LICENSE_KEY || process.env.RETRIVORA_LICENSE_KEY : "") || "";
3494
+ if (!effectiveLicenseKey) {
3495
+ this.purgeCache(effectiveLicenseKey);
3496
+ throw new LicenseValidationError("Missing RETRIVORA_LICENSE_KEY in request. Set NEXT_PUBLIC_RETRIVORA_LICENSE_KEY in your environment or pass licenseKey as a prop.");
3265
3497
  }
3266
- const cached = this.cache.get(licenseKey);
3498
+ const cached = this.cache.get(effectiveLicenseKey);
3267
3499
  if (cached) {
3268
3500
  const isFresh = Date.now() - cached.timestamp < _LicenseValidator.SUCCESS_CACHE_TTL_MS;
3269
3501
  if (isFresh && cached.response.valid && cached.response.licenseStatus === "ACTIVE" && !cached.response.forceUpgrade) {
3270
3502
  return cached.response;
3271
3503
  } else {
3272
- this.cache.delete(licenseKey);
3504
+ this.cache.delete(effectiveLicenseKey);
3273
3505
  }
3274
3506
  }
3275
3507
  const base = retrivoraApiBase || (typeof process !== "undefined" ? process.env.NEXT_PUBLIC_RETRIVORA_API_BASE || process.env.RETRIVORA_API_BASE : "") || "/api/retrivora";
3276
3508
  const validateUrl = `${base.replace(/\/$/, "")}/v1/license/validate`;
3277
- let res;
3509
+ let res = null;
3278
3510
  try {
3279
3511
  res = await fetch(validateUrl, {
3280
3512
  method: "POST",
3281
3513
  cache: "no-store",
3282
3514
  headers: __spreadValues({
3283
3515
  "Content-Type": "application/json",
3284
- "x-license-key": licenseKey,
3516
+ "x-license-key": effectiveLicenseKey,
3285
3517
  "x-sdk-version": sdkVersion
3286
3518
  }, customHeaders || {}),
3287
3519
  body: JSON.stringify({
3288
- licenseKey,
3520
+ licenseKey: effectiveLicenseKey,
3289
3521
  projectId,
3290
3522
  sdkVersion,
3291
3523
  sdk,
@@ -3293,8 +3525,40 @@ var _LicenseValidator = class _LicenseValidator {
3293
3525
  })
3294
3526
  });
3295
3527
  } catch (err) {
3296
- this.purgeCache(licenseKey);
3297
- throw new LicenseValidationError(`License validation request failed: ${(err == null ? void 0 : err.message) || "Network error"}`);
3528
+ try {
3529
+ const payload = LicenseVerifier.verify(effectiveLicenseKey, projectId || "my-rag-app");
3530
+ const fallbackResp = {
3531
+ valid: true,
3532
+ licenseStatus: "ACTIVE",
3533
+ minimumSupportedVersion: "2.1.0",
3534
+ latestVersion: SDK_VERSION,
3535
+ forceUpgrade: false,
3536
+ expiresAt: payload.expiresAt ? new Date(payload.expiresAt * 1e3).toISOString() : null,
3537
+ message: "Local license verification active."
3538
+ };
3539
+ this.cache.set(effectiveLicenseKey, { response: fallbackResp, timestamp: Date.now() });
3540
+ return fallbackResp;
3541
+ } catch (e) {
3542
+ this.purgeCache(effectiveLicenseKey);
3543
+ throw new LicenseValidationError(`License validation request failed: ${(err == null ? void 0 : err.message) || "Network error"}`);
3544
+ }
3545
+ }
3546
+ if (res && !res.ok) {
3547
+ try {
3548
+ const payload = LicenseVerifier.verify(effectiveLicenseKey, projectId || "my-rag-app");
3549
+ const fallbackResp = {
3550
+ valid: true,
3551
+ licenseStatus: "ACTIVE",
3552
+ minimumSupportedVersion: "2.1.0",
3553
+ latestVersion: SDK_VERSION,
3554
+ forceUpgrade: false,
3555
+ expiresAt: payload.expiresAt ? new Date(payload.expiresAt * 1e3).toISOString() : null,
3556
+ message: "Local license verification active."
3557
+ };
3558
+ this.cache.set(effectiveLicenseKey, { response: fallbackResp, timestamp: Date.now() });
3559
+ return fallbackResp;
3560
+ } catch (e) {
3561
+ }
3298
3562
  }
3299
3563
  const data = await res.json().catch(() => ({
3300
3564
  valid: false,
@@ -3306,7 +3570,7 @@ var _LicenseValidator = class _LicenseValidator {
3306
3570
  message: "Failed to parse license validation response."
3307
3571
  }));
3308
3572
  if (!res.ok || !data.valid || data.licenseStatus !== "ACTIVE" || data.forceUpgrade) {
3309
- this.purgeCache(licenseKey);
3573
+ this.purgeCache(effectiveLicenseKey);
3310
3574
  if (data.forceUpgrade || res.status === 426) {
3311
3575
  throw new SDKVersionUnsupportedError(
3312
3576
  data.message || `This SDK version (${sdkVersion}) is no longer supported. Upgrade to version ${data.latestVersion || "2.2.6"} or later.`,
@@ -3316,7 +3580,7 @@ var _LicenseValidator = class _LicenseValidator {
3316
3580
  const errMsg = data.message || `License validation failed with status: ${data.licenseStatus}. Access denied.`;
3317
3581
  throw new LicenseValidationError(errMsg, data);
3318
3582
  }
3319
- this.cache.set(licenseKey, {
3583
+ this.cache.set(effectiveLicenseKey, {
3320
3584
  response: data,
3321
3585
  timestamp: Date.now()
3322
3586
  });
@@ -3341,6 +3605,7 @@ function ChatWindow({
3341
3605
  onAddToCart,
3342
3606
  apiUrl,
3343
3607
  retrivoraApiBase,
3608
+ licenseKey: licenseKeyProp,
3344
3609
  headers
3345
3610
  }) {
3346
3611
  var _a;
@@ -3355,6 +3620,7 @@ function ChatWindow({
3355
3620
  namespace: projectId,
3356
3621
  apiUrl,
3357
3622
  retrivoraApiBase,
3623
+ licenseKey: licenseKeyProp,
3358
3624
  headers
3359
3625
  });
3360
3626
  const [suggestions, setSuggestions] = useState6([]);
@@ -3369,9 +3635,17 @@ function ChatWindow({
3369
3635
  async function validateSessionLicense() {
3370
3636
  var _a2;
3371
3637
  try {
3372
- const licenseKey = (headers == null ? void 0 : headers["x-license-key"]) || ((_a2 = headers == null ? void 0 : headers["authorization"]) == null ? void 0 : _a2.replace(/^Bearer\s+/i, "")) || "";
3638
+ const getHeader = (name) => {
3639
+ if (!headers) return void 0;
3640
+ const target = name.toLowerCase();
3641
+ for (const [k, v] of Object.entries(headers)) {
3642
+ if (k.toLowerCase() === target) return v;
3643
+ }
3644
+ return void 0;
3645
+ };
3646
+ const resolvedLicenseKey = licenseKeyProp || getHeader("x-license-key") || ((_a2 = getHeader("authorization")) == null ? void 0 : _a2.replace(/^Bearer\s+/i, "")) || (typeof process !== "undefined" ? process.env.NEXT_PUBLIC_RETRIVORA_LICENSE_KEY || process.env.RETRIVORA_LICENSE_KEY : "") || "";
3373
3647
  await LicenseValidator.getInstance().validate({
3374
- licenseKey,
3648
+ licenseKey: resolvedLicenseKey,
3375
3649
  projectId,
3376
3650
  retrivoraApiBase,
3377
3651
  headers
@@ -3842,7 +4116,7 @@ var GEMINI_STYLES = `
3842
4116
  --circle: shape(evenodd from 13.482% 79.505%, curve by -7.1945% -12.47% with -1.4985% -1.8575% / -6.328% -10.225%, curve by 0.0985% -33.8965% with -4.1645% -10.7945% / -4.1685% -23.0235%, curve by 6.9955% -12.101% with 1.72% -4.3825% / 4.0845% -8.458%, curve by 30.125% -17.119% with 7.339% -9.1825% / 18.4775% -15.5135%, curve by 13.4165% 0.095% with 4.432% -0.6105% / 8.9505% -0.5855%, curve by 29.364% 16.9% with 11.6215% 1.77% / 22.102% 7.9015%, curve by 7.176% 12.4145% with 3.002% 3.7195% / 5.453% 7.968%, curve by -0.0475% 33.8925% with 4.168% 10.756% / 4.2305% 22.942%, curve by -7.1135% 12.2825% with -1.74% 4.4535% / -4.1455% 8.592%, curve by -29.404% 16.9075% with -7.202% 8.954% / -18.019% 15.137%, curve by -14.19% -0.018% with -4.6635% 0.7255% / -9.4575% 0.7205%, curve by -29.226% -16.8875% with -11.573% -1.8065% / -21.9955% -7.9235%, close);
3843
4117
  }
3844
4118
  `;
3845
- function ChatWidget({ position = "bottom-right", onAddToCart, apiUrl, retrivoraApiBase, headers }) {
4119
+ function ChatWidget({ position = "bottom-right", onAddToCart, apiUrl, retrivoraApiBase, licenseKey: licenseKeyProp, headers }) {
3846
4120
  const { ui, projectId } = useConfig();
3847
4121
  const [isOpen, setIsOpen] = useState7(false);
3848
4122
  const [hasUnread, setHasUnread] = useState7(false);
@@ -3859,9 +4133,17 @@ function ChatWidget({ position = "bottom-right", onAddToCart, apiUrl, retrivoraA
3859
4133
  var _a;
3860
4134
  setIsValidating(true);
3861
4135
  try {
3862
- const licenseKey = (headers == null ? void 0 : headers["x-license-key"]) || ((_a = headers == null ? void 0 : headers["authorization"]) == null ? void 0 : _a.replace(/^Bearer\s+/i, "")) || "";
4136
+ const getHeader = (name) => {
4137
+ if (!headers) return void 0;
4138
+ const target = name.toLowerCase();
4139
+ for (const [k, v] of Object.entries(headers)) {
4140
+ if (k.toLowerCase() === target) return v;
4141
+ }
4142
+ return void 0;
4143
+ };
4144
+ const resolvedLicenseKey = licenseKeyProp || getHeader("x-license-key") || ((_a = getHeader("authorization")) == null ? void 0 : _a.replace(/^Bearer\s+/i, "")) || (typeof process !== "undefined" ? process.env.NEXT_PUBLIC_RETRIVORA_LICENSE_KEY || process.env.RETRIVORA_LICENSE_KEY : "") || "";
3863
4145
  await LicenseValidator.getInstance().validate({
3864
- licenseKey,
4146
+ licenseKey: resolvedLicenseKey,
3865
4147
  projectId,
3866
4148
  retrivoraApiBase,
3867
4149
  headers
@@ -3943,6 +4225,7 @@ function ChatWidget({ position = "bottom-right", onAddToCart, apiUrl, retrivoraA
3943
4225
  onAddToCart,
3944
4226
  apiUrl,
3945
4227
  retrivoraApiBase,
4228
+ licenseKey: licenseKeyProp,
3946
4229
  headers
3947
4230
  }
3948
4231
  ),
package/dist/server.d.mts CHANGED
@@ -1,9 +1,9 @@
1
- import { V as VectorDBConfig, L as LLMConfig, d as EmbeddingConfig, i as RagConfig, n as UniversalRagConfig, o as UpsertDocument, q as VectorMatch, G as GraphDBConfig, r as GraphNode, s as Edge, t as GraphSearchResult, I as ILLMProvider, p as VectorDBProvider, g as LLMProvider, e as EmbeddingProvider, R as RAGConfig, m as UIConfig, C as ChatMessage, b as ChatOptions, E as EmbedOptions } from './ILLMProvider-BWa68XX5.mjs';
2
- export { B as BarChartData, u as CarouselProduct, c as ChatResponse, v as IRetriever, f as IngestDocument, h as LatencyBreakdown, w as LineChartDataPoint, M as MessageRole, x as MetricCardData, O as ObservabilityTrace, P as PieChartData, y as Product, j as RagMessage, k as RetrievalConfig, z as RetrievalResult, l as RetrievedChunk, A as RetrivoraChunkMetadata, D as RetrivoraIngestedDocument, S as ScatterPlotDataPoint, F as SuggestionsResponse, H as TableData, T as TokenUsage, J as UITransformationResponse, U as UseRagChatOptions, a as UseRagChatReturn, K as VisualizationType, W as WorkflowConfig } from './ILLMProvider-BWa68XX5.mjs';
3
- import { I as IRenderRule, i as DecisionContext, k as IntentCategory, q as RenderDecision } from './LicenseValidator-B3xpJaVf.mjs';
4
- export { F as ArchitectureCardProps, A as AuthenticationException, G as CarouselRendererStrategy, H as ChartRendererStrategy, e as ChartType, J as ChatViewportSize, C as ChatWidgetProps, a as ChatWindowProps, f as Chunk, g as ChunkOptions, c as ClientConfig, b as ConfigProviderProps, h as ConfigurationException, K as DocumentChunker, D as DocumentUploadProps, E as EmbeddingFailedException, j as IRendererStrategy, l as IntentClassifier, L as LicenseValidationError, m as LicenseValidationRequest, n as LicenseValidationResponse, o as LicenseValidator, M as MessageBubbleProps, N as MixedRendererStrategy, O as Pipeline, Q as PipelineStep, P as ProductCardProps, d as ProductCarouselProps, p as ProviderNotFoundException, T as ProviderPill, R as RateLimitException, U as RenderSectionDecision, r as RenderType, s as RendererRegistry, t as RetrievalException, u as Retrivora, v as RetrivoraError, w as RetrivoraErrorCode, x as RuleEngine, y as SDKVersionUnsupportedError, z as SDK_VERSION, W as Snippet, S as SourceCardProps, X as TableRendererStrategy, Y as TextRendererStrategy, V as VisualizationDecisionEngine, B as decideVisualization, Z as wrapError } from './LicenseValidator-B3xpJaVf.mjs';
5
- import { H as HealthCheckResult, I as IProviderValidator, a as IProviderHealthChecker } from './index-DvbtNz7m.mjs';
6
- export { C as ConfigValidator, V as ValidationError, b as VectorPlugin, c as createChatHandler, d as createFeedbackHandler, e as createHealthHandler, f as createHistoryHandler, g as createIngestHandler, h as createRagHandler, i as createSessionsHandler, j as createStreamHandler, k as createUploadHandler, s as sseErrorFrame, l as sseFrame, m as sseMetaFrame, n as sseTextFrame } from './index-DvbtNz7m.mjs';
1
+ import { V as VectorDBConfig, L as LLMConfig, d as EmbeddingConfig, i as RagConfig, n as UniversalRagConfig, o as UpsertDocument, q as VectorMatch, G as GraphDBConfig, r as GraphNode, s as Edge, t as GraphSearchResult, I as ILLMProvider, p as VectorDBProvider, g as LLMProvider, e as EmbeddingProvider, R as RAGConfig, m as UIConfig, C as ChatMessage, b as ChatOptions, E as EmbedOptions } from './ILLMProvider-teTNQ1lh.mjs';
2
+ export { B as BarChartData, u as CarouselProduct, c as ChatResponse, v as IRetriever, f as IngestDocument, h as LatencyBreakdown, w as LineChartDataPoint, M as MessageRole, x as MetricCardData, O as ObservabilityTrace, P as PieChartData, y as Product, j as RagMessage, k as RetrievalConfig, z as RetrievalResult, l as RetrievedChunk, A as RetrivoraChunkMetadata, D as RetrivoraIngestedDocument, S as ScatterPlotDataPoint, F as SuggestionsResponse, H as TableData, T as TokenUsage, J as UITransformationResponse, U as UseRagChatOptions, a as UseRagChatReturn, K as VisualizationType, W as WorkflowConfig } from './ILLMProvider-teTNQ1lh.mjs';
3
+ import { I as IRenderRule, i as DecisionContext, k as IntentCategory, q as RenderDecision } from './LicenseValidator-CENvo9o2.mjs';
4
+ export { F as ArchitectureCardProps, A as AuthenticationException, G as CarouselRendererStrategy, H as ChartRendererStrategy, e as ChartType, J as ChatViewportSize, C as ChatWidgetProps, a as ChatWindowProps, f as Chunk, g as ChunkOptions, c as ClientConfig, b as ConfigProviderProps, h as ConfigurationException, K as DocumentChunker, D as DocumentUploadProps, E as EmbeddingFailedException, j as IRendererStrategy, l as IntentClassifier, L as LicenseValidationError, m as LicenseValidationRequest, n as LicenseValidationResponse, o as LicenseValidator, M as MessageBubbleProps, N as MixedRendererStrategy, O as Pipeline, Q as PipelineStep, P as ProductCardProps, d as ProductCarouselProps, p as ProviderNotFoundException, T as ProviderPill, R as RateLimitException, U as RenderSectionDecision, r as RenderType, s as RendererRegistry, t as RetrievalException, u as Retrivora, v as RetrivoraError, w as RetrivoraErrorCode, x as RuleEngine, y as SDKVersionUnsupportedError, z as SDK_VERSION, W as Snippet, S as SourceCardProps, X as TableRendererStrategy, Y as TextRendererStrategy, V as VisualizationDecisionEngine, B as decideVisualization, Z as wrapError } from './LicenseValidator-CENvo9o2.mjs';
5
+ import { H as HealthCheckResult, I as IProviderValidator, a as IProviderHealthChecker } from './index-Dmq5lH0j.mjs';
6
+ export { C as ConfigValidator, V as ValidationError, b as VectorPlugin, c as createChatHandler, d as createFeedbackHandler, e as createHealthHandler, f as createHistoryHandler, g as createIngestHandler, h as createRagHandler, i as createSessionsHandler, j as createStreamHandler, k as createUploadHandler, s as sseErrorFrame, l as sseFrame, m as sseMetaFrame, n as sseTextFrame } from './index-Dmq5lH0j.mjs';
7
7
  import 'react';
8
8
  import 'next/server';
9
9
 
package/dist/server.d.ts CHANGED
@@ -1,9 +1,9 @@
1
- import { V as VectorDBConfig, L as LLMConfig, d as EmbeddingConfig, i as RagConfig, n as UniversalRagConfig, o as UpsertDocument, q as VectorMatch, G as GraphDBConfig, r as GraphNode, s as Edge, t as GraphSearchResult, I as ILLMProvider, p as VectorDBProvider, g as LLMProvider, e as EmbeddingProvider, R as RAGConfig, m as UIConfig, C as ChatMessage, b as ChatOptions, E as EmbedOptions } from './ILLMProvider-BWa68XX5.js';
2
- export { B as BarChartData, u as CarouselProduct, c as ChatResponse, v as IRetriever, f as IngestDocument, h as LatencyBreakdown, w as LineChartDataPoint, M as MessageRole, x as MetricCardData, O as ObservabilityTrace, P as PieChartData, y as Product, j as RagMessage, k as RetrievalConfig, z as RetrievalResult, l as RetrievedChunk, A as RetrivoraChunkMetadata, D as RetrivoraIngestedDocument, S as ScatterPlotDataPoint, F as SuggestionsResponse, H as TableData, T as TokenUsage, J as UITransformationResponse, U as UseRagChatOptions, a as UseRagChatReturn, K as VisualizationType, W as WorkflowConfig } from './ILLMProvider-BWa68XX5.js';
3
- import { I as IRenderRule, i as DecisionContext, k as IntentCategory, q as RenderDecision } from './LicenseValidator-D4I4pbSL.js';
4
- export { F as ArchitectureCardProps, A as AuthenticationException, G as CarouselRendererStrategy, H as ChartRendererStrategy, e as ChartType, J as ChatViewportSize, C as ChatWidgetProps, a as ChatWindowProps, f as Chunk, g as ChunkOptions, c as ClientConfig, b as ConfigProviderProps, h as ConfigurationException, K as DocumentChunker, D as DocumentUploadProps, E as EmbeddingFailedException, j as IRendererStrategy, l as IntentClassifier, L as LicenseValidationError, m as LicenseValidationRequest, n as LicenseValidationResponse, o as LicenseValidator, M as MessageBubbleProps, N as MixedRendererStrategy, O as Pipeline, Q as PipelineStep, P as ProductCardProps, d as ProductCarouselProps, p as ProviderNotFoundException, T as ProviderPill, R as RateLimitException, U as RenderSectionDecision, r as RenderType, s as RendererRegistry, t as RetrievalException, u as Retrivora, v as RetrivoraError, w as RetrivoraErrorCode, x as RuleEngine, y as SDKVersionUnsupportedError, z as SDK_VERSION, W as Snippet, S as SourceCardProps, X as TableRendererStrategy, Y as TextRendererStrategy, V as VisualizationDecisionEngine, B as decideVisualization, Z as wrapError } from './LicenseValidator-D4I4pbSL.js';
5
- import { H as HealthCheckResult, I as IProviderValidator, a as IProviderHealthChecker } from './index-B5TTZWkx.js';
6
- export { C as ConfigValidator, V as ValidationError, b as VectorPlugin, c as createChatHandler, d as createFeedbackHandler, e as createHealthHandler, f as createHistoryHandler, g as createIngestHandler, h as createRagHandler, i as createSessionsHandler, j as createStreamHandler, k as createUploadHandler, s as sseErrorFrame, l as sseFrame, m as sseMetaFrame, n as sseTextFrame } from './index-B5TTZWkx.js';
1
+ import { V as VectorDBConfig, L as LLMConfig, d as EmbeddingConfig, i as RagConfig, n as UniversalRagConfig, o as UpsertDocument, q as VectorMatch, G as GraphDBConfig, r as GraphNode, s as Edge, t as GraphSearchResult, I as ILLMProvider, p as VectorDBProvider, g as LLMProvider, e as EmbeddingProvider, R as RAGConfig, m as UIConfig, C as ChatMessage, b as ChatOptions, E as EmbedOptions } from './ILLMProvider-teTNQ1lh.js';
2
+ export { B as BarChartData, u as CarouselProduct, c as ChatResponse, v as IRetriever, f as IngestDocument, h as LatencyBreakdown, w as LineChartDataPoint, M as MessageRole, x as MetricCardData, O as ObservabilityTrace, P as PieChartData, y as Product, j as RagMessage, k as RetrievalConfig, z as RetrievalResult, l as RetrievedChunk, A as RetrivoraChunkMetadata, D as RetrivoraIngestedDocument, S as ScatterPlotDataPoint, F as SuggestionsResponse, H as TableData, T as TokenUsage, J as UITransformationResponse, U as UseRagChatOptions, a as UseRagChatReturn, K as VisualizationType, W as WorkflowConfig } from './ILLMProvider-teTNQ1lh.js';
3
+ import { I as IRenderRule, i as DecisionContext, k as IntentCategory, q as RenderDecision } from './LicenseValidator-CsjJp2PP.js';
4
+ export { F as ArchitectureCardProps, A as AuthenticationException, G as CarouselRendererStrategy, H as ChartRendererStrategy, e as ChartType, J as ChatViewportSize, C as ChatWidgetProps, a as ChatWindowProps, f as Chunk, g as ChunkOptions, c as ClientConfig, b as ConfigProviderProps, h as ConfigurationException, K as DocumentChunker, D as DocumentUploadProps, E as EmbeddingFailedException, j as IRendererStrategy, l as IntentClassifier, L as LicenseValidationError, m as LicenseValidationRequest, n as LicenseValidationResponse, o as LicenseValidator, M as MessageBubbleProps, N as MixedRendererStrategy, O as Pipeline, Q as PipelineStep, P as ProductCardProps, d as ProductCarouselProps, p as ProviderNotFoundException, T as ProviderPill, R as RateLimitException, U as RenderSectionDecision, r as RenderType, s as RendererRegistry, t as RetrievalException, u as Retrivora, v as RetrivoraError, w as RetrivoraErrorCode, x as RuleEngine, y as SDKVersionUnsupportedError, z as SDK_VERSION, W as Snippet, S as SourceCardProps, X as TableRendererStrategy, Y as TextRendererStrategy, V as VisualizationDecisionEngine, B as decideVisualization, Z as wrapError } from './LicenseValidator-CsjJp2PP.js';
5
+ import { H as HealthCheckResult, I as IProviderValidator, a as IProviderHealthChecker } from './index-BPJ3KDYI.js';
6
+ export { C as ConfigValidator, V as ValidationError, b as VectorPlugin, c as createChatHandler, d as createFeedbackHandler, e as createHealthHandler, f as createHistoryHandler, g as createIngestHandler, h as createRagHandler, i as createSessionsHandler, j as createStreamHandler, k as createUploadHandler, s as sseErrorFrame, l as sseFrame, m as sseMetaFrame, n as sseTextFrame } from './index-BPJ3KDYI.js';
7
7
  import 'react';
8
8
  import 'next/server';
9
9