@retrivora-ai/rag-engine 2.2.6 → 2.2.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.
@@ -509,7 +509,7 @@ declare class Retrivora {
509
509
  /**
510
510
  * Named SDK exceptions make failures machine-readable for host applications.
511
511
  */
512
- type RetrivoraErrorCode = 'PROVIDER_NOT_FOUND' | 'EMBEDDING_FAILED' | 'RETRIEVAL_FAILED' | 'RATE_LIMITED' | 'CONFIGURATION_ERROR' | 'AUTHENTICATION_ERROR';
512
+ type RetrivoraErrorCode = 'PROVIDER_NOT_FOUND' | 'EMBEDDING_FAILED' | 'RETRIEVAL_FAILED' | 'RATE_LIMITED' | 'CONFIGURATION_ERROR' | 'AUTHENTICATION_ERROR' | 'SDK_VERSION_UNSUPPORTED' | 'LICENSE_VALIDATION_ERROR';
513
513
  declare class RetrivoraError extends Error {
514
514
  readonly code: RetrivoraErrorCode;
515
515
  readonly details?: unknown;
@@ -533,9 +533,49 @@ declare class ConfigurationException extends RetrivoraError {
533
533
  declare class AuthenticationException extends RetrivoraError {
534
534
  constructor(message?: string, details?: unknown);
535
535
  }
536
+ declare class SDKVersionUnsupportedError extends RetrivoraError {
537
+ constructor(message?: string, details?: unknown);
538
+ }
539
+ declare class LicenseValidationError extends RetrivoraError {
540
+ constructor(message?: string, details?: unknown);
541
+ }
536
542
  /**
537
543
  * Wraps any unknown error into an appropriate RetrivoraError subclass.
538
544
  */
539
545
  declare function wrapError(err: unknown, defaultCode: RetrivoraErrorCode, defaultMessage?: string): RetrivoraError;
540
546
 
541
- export { AuthenticationException as A, type ChatViewportSize as B, type ChatWidgetProps as C, type DocumentUploadProps as D, EmbeddingFailedException as E, DocumentChunker as F, MixedRendererStrategy as G, Pipeline as H, type IRenderRule as I, type PipelineStep as J, type ProviderPill as K, type RenderSectionDecision as L, type MessageBubbleProps as M, type Snippet as N, TextRendererStrategy as O, type ProductCardProps as P, wrapError as Q, RateLimitException as R, type SourceCardProps as S, TableRendererStrategy as T, VisualizationDecisionEngine as V, type ChatWindowProps as a, type ConfigProviderProps as b, type ClientConfig as c, type ProductCarouselProps as d, type ChartType as e, type Chunk as f, type ChunkOptions as g, ConfigurationException as h, type DecisionContext as i, type IRendererStrategy as j, type IntentCategory as k, IntentClassifier as l, ProviderNotFoundException as m, type RenderDecision as n, type RenderType as o, RendererRegistry as p, RetrievalException as q, Retrivora as r, RetrivoraError as s, type RetrivoraErrorCode as t, RuleEngine as u, SDK_VERSION as v, decideVisualization as w, type ArchitectureCardProps as x, CarouselRendererStrategy as y, ChartRendererStrategy as z };
547
+ interface LicenseValidationRequest {
548
+ licenseKey: string;
549
+ projectId?: string;
550
+ sdkVersion?: string;
551
+ sdk?: string;
552
+ platform?: string;
553
+ retrivoraApiBase?: string;
554
+ headers?: Record<string, string>;
555
+ }
556
+ interface LicenseValidationResponse {
557
+ valid: boolean;
558
+ licenseStatus: 'ACTIVE' | 'SUSPENDED' | 'TERMINATED' | 'EXPIRED' | 'REVOKED';
559
+ minimumSupportedVersion: string;
560
+ latestVersion: string;
561
+ forceUpgrade: boolean;
562
+ expiresAt: string | null;
563
+ message: string;
564
+ }
565
+ declare class LicenseValidator {
566
+ private static instance;
567
+ private cache;
568
+ private static readonly SUCCESS_CACHE_TTL_MS;
569
+ private constructor();
570
+ static getInstance(): LicenseValidator;
571
+ /**
572
+ * Invalidate local validation cache for a license key
573
+ */
574
+ purgeCache(licenseKey?: string): void;
575
+ /**
576
+ * Validate license status and SDK version against Retrivora License Service
577
+ */
578
+ validate(request: LicenseValidationRequest): Promise<LicenseValidationResponse>;
579
+ }
580
+
581
+ export { AuthenticationException as A, decideVisualization as B, type ChatWidgetProps as C, type DocumentUploadProps as D, EmbeddingFailedException as E, type ArchitectureCardProps as F, CarouselRendererStrategy as G, ChartRendererStrategy as H, type IRenderRule as I, type ChatViewportSize as J, DocumentChunker as K, LicenseValidationError as L, type MessageBubbleProps as M, MixedRendererStrategy as N, Pipeline as O, type ProductCardProps as P, type PipelineStep as Q, RateLimitException as R, type SourceCardProps as S, type ProviderPill as T, type RenderSectionDecision as U, VisualizationDecisionEngine as V, type Snippet as W, TableRendererStrategy as X, TextRendererStrategy as Y, wrapError as Z, type ChatWindowProps as a, type ConfigProviderProps as b, type ClientConfig as c, type ProductCarouselProps as d, type ChartType as e, type Chunk as f, type ChunkOptions as g, ConfigurationException as h, type DecisionContext as i, type IRendererStrategy as j, type IntentCategory as k, IntentClassifier as l, type LicenseValidationRequest as m, type LicenseValidationResponse as n, LicenseValidator as o, ProviderNotFoundException as p, type RenderDecision as q, type RenderType as r, RendererRegistry as s, RetrievalException as t, Retrivora as u, RetrivoraError as v, type RetrivoraErrorCode as w, RuleEngine as x, SDKVersionUnsupportedError as y, SDK_VERSION as z };
@@ -509,7 +509,7 @@ declare class Retrivora {
509
509
  /**
510
510
  * Named SDK exceptions make failures machine-readable for host applications.
511
511
  */
512
- type RetrivoraErrorCode = 'PROVIDER_NOT_FOUND' | 'EMBEDDING_FAILED' | 'RETRIEVAL_FAILED' | 'RATE_LIMITED' | 'CONFIGURATION_ERROR' | 'AUTHENTICATION_ERROR';
512
+ type RetrivoraErrorCode = 'PROVIDER_NOT_FOUND' | 'EMBEDDING_FAILED' | 'RETRIEVAL_FAILED' | 'RATE_LIMITED' | 'CONFIGURATION_ERROR' | 'AUTHENTICATION_ERROR' | 'SDK_VERSION_UNSUPPORTED' | 'LICENSE_VALIDATION_ERROR';
513
513
  declare class RetrivoraError extends Error {
514
514
  readonly code: RetrivoraErrorCode;
515
515
  readonly details?: unknown;
@@ -533,9 +533,49 @@ declare class ConfigurationException extends RetrivoraError {
533
533
  declare class AuthenticationException extends RetrivoraError {
534
534
  constructor(message?: string, details?: unknown);
535
535
  }
536
+ declare class SDKVersionUnsupportedError extends RetrivoraError {
537
+ constructor(message?: string, details?: unknown);
538
+ }
539
+ declare class LicenseValidationError extends RetrivoraError {
540
+ constructor(message?: string, details?: unknown);
541
+ }
536
542
  /**
537
543
  * Wraps any unknown error into an appropriate RetrivoraError subclass.
538
544
  */
539
545
  declare function wrapError(err: unknown, defaultCode: RetrivoraErrorCode, defaultMessage?: string): RetrivoraError;
540
546
 
541
- export { AuthenticationException as A, type ChatViewportSize as B, type ChatWidgetProps as C, type DocumentUploadProps as D, EmbeddingFailedException as E, DocumentChunker as F, MixedRendererStrategy as G, Pipeline as H, type IRenderRule as I, type PipelineStep as J, type ProviderPill as K, type RenderSectionDecision as L, type MessageBubbleProps as M, type Snippet as N, TextRendererStrategy as O, type ProductCardProps as P, wrapError as Q, RateLimitException as R, type SourceCardProps as S, TableRendererStrategy as T, VisualizationDecisionEngine as V, type ChatWindowProps as a, type ConfigProviderProps as b, type ClientConfig as c, type ProductCarouselProps as d, type ChartType as e, type Chunk as f, type ChunkOptions as g, ConfigurationException as h, type DecisionContext as i, type IRendererStrategy as j, type IntentCategory as k, IntentClassifier as l, ProviderNotFoundException as m, type RenderDecision as n, type RenderType as o, RendererRegistry as p, RetrievalException as q, Retrivora as r, RetrivoraError as s, type RetrivoraErrorCode as t, RuleEngine as u, SDK_VERSION as v, decideVisualization as w, type ArchitectureCardProps as x, CarouselRendererStrategy as y, ChartRendererStrategy as z };
547
+ interface LicenseValidationRequest {
548
+ licenseKey: string;
549
+ projectId?: string;
550
+ sdkVersion?: string;
551
+ sdk?: string;
552
+ platform?: string;
553
+ retrivoraApiBase?: string;
554
+ headers?: Record<string, string>;
555
+ }
556
+ interface LicenseValidationResponse {
557
+ valid: boolean;
558
+ licenseStatus: 'ACTIVE' | 'SUSPENDED' | 'TERMINATED' | 'EXPIRED' | 'REVOKED';
559
+ minimumSupportedVersion: string;
560
+ latestVersion: string;
561
+ forceUpgrade: boolean;
562
+ expiresAt: string | null;
563
+ message: string;
564
+ }
565
+ declare class LicenseValidator {
566
+ private static instance;
567
+ private cache;
568
+ private static readonly SUCCESS_CACHE_TTL_MS;
569
+ private constructor();
570
+ static getInstance(): LicenseValidator;
571
+ /**
572
+ * Invalidate local validation cache for a license key
573
+ */
574
+ purgeCache(licenseKey?: string): void;
575
+ /**
576
+ * Validate license status and SDK version against Retrivora License Service
577
+ */
578
+ validate(request: LicenseValidationRequest): Promise<LicenseValidationResponse>;
579
+ }
580
+
581
+ export { AuthenticationException as A, decideVisualization as B, type ChatWidgetProps as C, type DocumentUploadProps as D, EmbeddingFailedException as E, type ArchitectureCardProps as F, CarouselRendererStrategy as G, ChartRendererStrategy as H, type IRenderRule as I, type ChatViewportSize as J, DocumentChunker as K, LicenseValidationError as L, type MessageBubbleProps as M, MixedRendererStrategy as N, Pipeline as O, type ProductCardProps as P, type PipelineStep as Q, RateLimitException as R, type SourceCardProps as S, type ProviderPill as T, type RenderSectionDecision as U, VisualizationDecisionEngine as V, type Snippet as W, TableRendererStrategy as X, TextRendererStrategy as Y, wrapError as Z, type ChatWindowProps as a, type ConfigProviderProps as b, type ClientConfig as c, type ProductCarouselProps as d, type ChartType as e, type Chunk as f, type ChunkOptions as g, ConfigurationException as h, type DecisionContext as i, type IRendererStrategy as j, type IntentCategory as k, IntentClassifier as l, type LicenseValidationRequest as m, type LicenseValidationResponse as n, LicenseValidator as o, ProviderNotFoundException as p, type RenderDecision as q, type RenderType as r, RendererRegistry as s, RetrievalException as t, Retrivora as u, RetrivoraError as v, type RetrivoraErrorCode as w, RuleEngine as x, SDKVersionUnsupportedError as y, SDK_VERSION as z };
@@ -2281,8 +2281,10 @@ function wrapError(err, defaultCode, defaultMessage) {
2281
2281
  if (status === 429 || /rate[- ]?limit/i.test(message) || code === "RATE_LIMIT_EXCEEDED") {
2282
2282
  return new RateLimitException(message, err);
2283
2283
  }
2284
- if (status === 401 || status === 403 || /unauthorized|auth|api[- ]?key/i.test(message) || code === "INVALID_API_KEY") {
2285
- return new AuthenticationException(message, err);
2284
+ if (status === 401 || status === 403 || /unauthorized|auth|license|revoked|terminated|api[- ]?key/i.test(message) || code === "INVALID_API_KEY" || code === "LICENSE_DELETED" || code === "LICENSE_INACTIVE") {
2285
+ const isLicenseError = /403|license|revoked|terminated/i.test(message) || status === 403;
2286
+ const cleanMsg = isLicenseError ? "Your Retrivora license key has been terminated, suspended, or revoked. Access denied." : message;
2287
+ return new AuthenticationException(cleanMsg, err);
2286
2288
  }
2287
2289
  switch (defaultCode) {
2288
2290
  case "PROVIDER_NOT_FOUND":
@@ -4707,7 +4709,7 @@ var ConfigValidator = class {
4707
4709
  // package.json
4708
4710
  var package_default = {
4709
4711
  name: "@retrivora-ai/rag-engine",
4710
- version: "2.2.6",
4712
+ version: "2.2.7",
4711
4713
  description: "Retrivora AI is a plug-and-play AI engine for RAG chat experiences \u2014 generic vector DB + LLM provider, embeddable or standalone.",
4712
4714
  author: "Abhinav Alkuchi",
4713
4715
  license: "UNLICENSED",
@@ -10510,7 +10512,10 @@ function createStreamHandler(configOrPlugin, options) {
10510
10512
  }
10511
10513
  } catch (streamError) {
10512
10514
  if (isActive) {
10513
- const errorMessage = streamError instanceof Error ? streamError.message : String(streamError);
10515
+ let errorMessage = streamError instanceof Error ? streamError.message : String(streamError);
10516
+ if (errorMessage.includes("403") || errorMessage.toLowerCase().includes("license") || errorMessage.toLowerCase().includes("revoked") || errorMessage.toLowerCase().includes("terminated")) {
10517
+ errorMessage = "Your Retrivora license key has been terminated, suspended, or revoked. Access denied.";
10518
+ }
10514
10519
  console.error("[createStreamHandler] Stream error:", streamError);
10515
10520
  reportTelemetry(req, plugin, "QUERY_GENERATION", "error", errorMessage);
10516
10521
  try {
@@ -2246,8 +2246,10 @@ function wrapError(err, defaultCode, defaultMessage) {
2246
2246
  if (status === 429 || /rate[- ]?limit/i.test(message) || code === "RATE_LIMIT_EXCEEDED") {
2247
2247
  return new RateLimitException(message, err);
2248
2248
  }
2249
- if (status === 401 || status === 403 || /unauthorized|auth|api[- ]?key/i.test(message) || code === "INVALID_API_KEY") {
2250
- return new AuthenticationException(message, err);
2249
+ if (status === 401 || status === 403 || /unauthorized|auth|license|revoked|terminated|api[- ]?key/i.test(message) || code === "INVALID_API_KEY" || code === "LICENSE_DELETED" || code === "LICENSE_INACTIVE") {
2250
+ const isLicenseError = /403|license|revoked|terminated/i.test(message) || status === 403;
2251
+ const cleanMsg = isLicenseError ? "Your Retrivora license key has been terminated, suspended, or revoked. Access denied." : message;
2252
+ return new AuthenticationException(cleanMsg, err);
2251
2253
  }
2252
2254
  switch (defaultCode) {
2253
2255
  case "PROVIDER_NOT_FOUND":
@@ -4672,7 +4674,7 @@ var ConfigValidator = class {
4672
4674
  // package.json
4673
4675
  var package_default = {
4674
4676
  name: "@retrivora-ai/rag-engine",
4675
- version: "2.2.6",
4677
+ version: "2.2.7",
4676
4678
  description: "Retrivora AI is a plug-and-play AI engine for RAG chat experiences \u2014 generic vector DB + LLM provider, embeddable or standalone.",
4677
4679
  author: "Abhinav Alkuchi",
4678
4680
  license: "UNLICENSED",
@@ -10475,7 +10477,10 @@ function createStreamHandler(configOrPlugin, options) {
10475
10477
  }
10476
10478
  } catch (streamError) {
10477
10479
  if (isActive) {
10478
- const errorMessage = streamError instanceof Error ? streamError.message : String(streamError);
10480
+ let errorMessage = streamError instanceof Error ? streamError.message : String(streamError);
10481
+ if (errorMessage.includes("403") || errorMessage.toLowerCase().includes("license") || errorMessage.toLowerCase().includes("revoked") || errorMessage.toLowerCase().includes("terminated")) {
10482
+ errorMessage = "Your Retrivora license key has been terminated, suspended, or revoked. Access denied.";
10483
+ }
10479
10484
  console.error("[createStreamHandler] Stream error:", streamError);
10480
10485
  reportTelemetry(req, plugin, "QUERY_GENERATION", "error", errorMessage);
10481
10486
  try {
package/dist/index.d.mts CHANGED
@@ -1,6 +1,6 @@
1
1
  import * as react_jsx_runtime from 'react/jsx-runtime';
2
- import { C as ChatWidgetProps, a as ChatWindowProps, D as DocumentUploadProps, M as MessageBubbleProps, S as SourceCardProps, b as ConfigProviderProps, c as ClientConfig, P as ProductCardProps, d as ProductCarouselProps } from './index-BbJGyNmW.mjs';
3
- export { A as AuthenticationException, e as ChartType, f as Chunk, g as ChunkOptions, h as ConfigurationException, i as DecisionContext, E as EmbeddingFailedException, I as IRenderRule, j as IRendererStrategy, k as IntentCategory, l as IntentClassifier, m as ProviderNotFoundException, R as RateLimitException, n as RenderDecision, o as RenderType, p as RendererRegistry, q as RetrievalException, r as Retrivora, s as RetrivoraError, t as RetrivoraErrorCode, u as RuleEngine, v as SDK_VERSION, V as VisualizationDecisionEngine, w as decideVisualization } from './index-BbJGyNmW.mjs';
2
+ import { C as ChatWidgetProps, a as ChatWindowProps, D as DocumentUploadProps, M as MessageBubbleProps, S as SourceCardProps, b as ConfigProviderProps, c as ClientConfig, P as ProductCardProps, d as ProductCarouselProps } from './LicenseValidator-B3xpJaVf.mjs';
3
+ export { A as AuthenticationException, e as ChartType, f as Chunk, g as ChunkOptions, h as ConfigurationException, i as DecisionContext, E as EmbeddingFailedException, I as IRenderRule, j as IRendererStrategy, k as IntentCategory, l as IntentClassifier, L as LicenseValidationError, m as LicenseValidationRequest, n as LicenseValidationResponse, o as LicenseValidator, p as ProviderNotFoundException, R as RateLimitException, q as RenderDecision, 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, V as VisualizationDecisionEngine, B as decideVisualization } from './LicenseValidator-B3xpJaVf.mjs';
4
4
  import { O as ObservabilityTrace, U as UseRagChatOptions, a as UseRagChatReturn } from './ILLMProvider-BWa68XX5.mjs';
5
5
  export { C as ChatMessage, b as ChatOptions, c as ChatResponse, E as EmbedOptions, d as EmbeddingConfig, e as EmbeddingProvider, I as ILLMProvider, f as IngestDocument, L as LLMConfig, g as LLMProvider, h as LatencyBreakdown, R as RAGConfig, i as RagConfig, j as RagMessage, k as RetrievalConfig, l as RetrievedChunk, T as TokenUsage, m as UIConfig, n as UniversalRagConfig, o as UpsertDocument, V as VectorDBConfig, p as VectorDBProvider, q as VectorMatch, W as WorkflowConfig } from './ILLMProvider-BWa68XX5.mjs';
6
6
  import 'react';
package/dist/index.d.ts CHANGED
@@ -1,6 +1,6 @@
1
1
  import * as react_jsx_runtime from 'react/jsx-runtime';
2
- import { C as ChatWidgetProps, a as ChatWindowProps, D as DocumentUploadProps, M as MessageBubbleProps, S as SourceCardProps, b as ConfigProviderProps, c as ClientConfig, P as ProductCardProps, d as ProductCarouselProps } from './index-BCbeeh74.js';
3
- export { A as AuthenticationException, e as ChartType, f as Chunk, g as ChunkOptions, h as ConfigurationException, i as DecisionContext, E as EmbeddingFailedException, I as IRenderRule, j as IRendererStrategy, k as IntentCategory, l as IntentClassifier, m as ProviderNotFoundException, R as RateLimitException, n as RenderDecision, o as RenderType, p as RendererRegistry, q as RetrievalException, r as Retrivora, s as RetrivoraError, t as RetrivoraErrorCode, u as RuleEngine, v as SDK_VERSION, V as VisualizationDecisionEngine, w as decideVisualization } from './index-BCbeeh74.js';
2
+ import { C as ChatWidgetProps, a as ChatWindowProps, D as DocumentUploadProps, M as MessageBubbleProps, S as SourceCardProps, b as ConfigProviderProps, c as ClientConfig, P as ProductCardProps, d as ProductCarouselProps } from './LicenseValidator-D4I4pbSL.js';
3
+ export { A as AuthenticationException, e as ChartType, f as Chunk, g as ChunkOptions, h as ConfigurationException, i as DecisionContext, E as EmbeddingFailedException, I as IRenderRule, j as IRendererStrategy, k as IntentCategory, l as IntentClassifier, L as LicenseValidationError, m as LicenseValidationRequest, n as LicenseValidationResponse, o as LicenseValidator, p as ProviderNotFoundException, R as RateLimitException, q as RenderDecision, 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, V as VisualizationDecisionEngine, B as decideVisualization } from './LicenseValidator-D4I4pbSL.js';
4
4
  import { O as ObservabilityTrace, U as UseRagChatOptions, a as UseRagChatReturn } from './ILLMProvider-BWa68XX5.js';
5
5
  export { C as ChatMessage, b as ChatOptions, c as ChatResponse, E as EmbedOptions, d as EmbeddingConfig, e as EmbeddingProvider, I as ILLMProvider, f as IngestDocument, L as LLMConfig, g as LLMProvider, h as LatencyBreakdown, R as RAGConfig, i as RagConfig, j as RagMessage, k as RetrievalConfig, l as RetrievedChunk, T as TokenUsage, m as UIConfig, n as UniversalRagConfig, o as UpsertDocument, V as VectorDBConfig, p as VectorDBProvider, q as VectorMatch, W as WorkflowConfig } from './ILLMProvider-BWa68XX5.js';
6
6
  import 'react';
package/dist/index.js CHANGED
@@ -69,6 +69,8 @@ __export(index_exports, {
69
69
  DocumentUpload: () => DocumentUpload,
70
70
  EmbeddingFailedException: () => EmbeddingFailedException,
71
71
  IntentClassifier: () => IntentClassifier,
72
+ LicenseValidationError: () => LicenseValidationError,
73
+ LicenseValidator: () => LicenseValidator,
72
74
  MessageBubble: () => MessageBubble,
73
75
  ObservabilityPanel: () => ObservabilityPanel,
74
76
  ProductCard: () => ProductCard,
@@ -79,6 +81,7 @@ __export(index_exports, {
79
81
  RetrievalException: () => RetrievalException,
80
82
  RetrivoraError: () => RetrivoraError,
81
83
  RuleEngine: () => RuleEngine,
84
+ SDKVersionUnsupportedError: () => SDKVersionUnsupportedError,
82
85
  SDK_VERSION: () => SDK_VERSION,
83
86
  SourceCard: () => SourceCard,
84
87
  VisualizationDecisionEngine: () => VisualizationDecisionEngine,
@@ -2917,7 +2920,10 @@ function useRagChat(projectId, options = {}) {
2917
2920
  console.log("[useRagChat] Streaming stopped by user.");
2918
2921
  return;
2919
2922
  }
2920
- const msg = err instanceof Error ? err.message : "Something went wrong. Please try again.";
2923
+ let msg = err instanceof Error ? err.message : "Something went wrong. Please try again.";
2924
+ if (msg.includes("403") || msg.toLowerCase().includes("license") || msg.toLowerCase().includes("revoked") || msg.toLowerCase().includes("terminated")) {
2925
+ msg = "Your Retrivora license key has been terminated, suspended, or revoked. Access denied.";
2926
+ }
2921
2927
  setError(msg);
2922
2928
  onError == null ? void 0 : onError(msg);
2923
2929
  } finally {
@@ -3029,7 +3035,7 @@ function useRagChat(projectId, options = {}) {
3029
3035
  // package.json
3030
3036
  var package_default = {
3031
3037
  name: "@retrivora-ai/rag-engine",
3032
- version: "2.2.6",
3038
+ version: "2.2.7",
3033
3039
  description: "Retrivora AI is a plug-and-play AI engine for RAG chat experiences \u2014 generic vector DB + LLM provider, embeddable or standalone.",
3034
3040
  author: "Abhinav Alkuchi",
3035
3041
  license: "UNLICENSED",
@@ -3169,6 +3175,158 @@ var package_default = {
3169
3175
  // src/version.ts
3170
3176
  var SDK_VERSION = package_default.version || "2.1.3";
3171
3177
 
3178
+ // src/exceptions/index.ts
3179
+ var RetrivoraError = class extends Error {
3180
+ constructor(message, code, details) {
3181
+ super(message);
3182
+ this.name = new.target.name;
3183
+ this.code = code;
3184
+ this.details = details;
3185
+ }
3186
+ };
3187
+ var ProviderNotFoundException = class extends RetrivoraError {
3188
+ constructor(providerType, provider, details) {
3189
+ super(`Unsupported ${providerType} provider: ${provider}`, "PROVIDER_NOT_FOUND", details);
3190
+ }
3191
+ };
3192
+ var EmbeddingFailedException = class extends RetrivoraError {
3193
+ constructor(message = "Embedding generation failed", details) {
3194
+ super(message, "EMBEDDING_FAILED", details);
3195
+ }
3196
+ };
3197
+ var RetrievalException = class extends RetrivoraError {
3198
+ constructor(message = "Retrieval failed", details) {
3199
+ super(message, "RETRIEVAL_FAILED", details);
3200
+ }
3201
+ };
3202
+ var RateLimitException = class extends RetrivoraError {
3203
+ constructor(message = "Provider rate limit exceeded", details) {
3204
+ super(message, "RATE_LIMITED", details);
3205
+ }
3206
+ };
3207
+ var ConfigurationException = class extends RetrivoraError {
3208
+ constructor(message, details) {
3209
+ super(message, "CONFIGURATION_ERROR", details);
3210
+ }
3211
+ };
3212
+ var AuthenticationException = class extends RetrivoraError {
3213
+ constructor(message = "Provider authentication failed", details) {
3214
+ super(message, "AUTHENTICATION_ERROR", details);
3215
+ }
3216
+ };
3217
+ var SDKVersionUnsupportedError = class extends RetrivoraError {
3218
+ constructor(message = "This SDK version is no longer supported.", details) {
3219
+ super(message, "SDK_VERSION_UNSUPPORTED", details);
3220
+ }
3221
+ };
3222
+ var LicenseValidationError = class extends RetrivoraError {
3223
+ constructor(message = "License validation failed.", details) {
3224
+ super(message, "LICENSE_VALIDATION_ERROR", details);
3225
+ }
3226
+ };
3227
+
3228
+ // src/core/LicenseValidator.ts
3229
+ var _LicenseValidator = class _LicenseValidator {
3230
+ // 5-minute TTL for successful validation only
3231
+ constructor() {
3232
+ this.cache = /* @__PURE__ */ new Map();
3233
+ }
3234
+ static getInstance() {
3235
+ if (!_LicenseValidator.instance) {
3236
+ _LicenseValidator.instance = new _LicenseValidator();
3237
+ }
3238
+ return _LicenseValidator.instance;
3239
+ }
3240
+ /**
3241
+ * Invalidate local validation cache for a license key
3242
+ */
3243
+ purgeCache(licenseKey) {
3244
+ if (licenseKey) {
3245
+ this.cache.delete(licenseKey);
3246
+ } else {
3247
+ this.cache.clear();
3248
+ }
3249
+ }
3250
+ /**
3251
+ * Validate license status and SDK version against Retrivora License Service
3252
+ */
3253
+ async validate(request) {
3254
+ const {
3255
+ licenseKey,
3256
+ projectId,
3257
+ sdkVersion = SDK_VERSION,
3258
+ sdk = "@retrivora-ai/rag-engine",
3259
+ platform = typeof window !== "undefined" ? "browser" : "node",
3260
+ retrivoraApiBase,
3261
+ headers: customHeaders
3262
+ } = request;
3263
+ if (!licenseKey) {
3264
+ this.purgeCache(licenseKey);
3265
+ throw new LicenseValidationError("Missing RETRIVORA_LICENSE_KEY in request.");
3266
+ }
3267
+ const cached = this.cache.get(licenseKey);
3268
+ if (cached) {
3269
+ const isFresh = Date.now() - cached.timestamp < _LicenseValidator.SUCCESS_CACHE_TTL_MS;
3270
+ if (isFresh && cached.response.valid && cached.response.licenseStatus === "ACTIVE" && !cached.response.forceUpgrade) {
3271
+ return cached.response;
3272
+ } else {
3273
+ this.cache.delete(licenseKey);
3274
+ }
3275
+ }
3276
+ const base = retrivoraApiBase || (typeof process !== "undefined" ? process.env.NEXT_PUBLIC_RETRIVORA_API_BASE || process.env.RETRIVORA_API_BASE : "") || "/api/retrivora";
3277
+ const validateUrl = `${base.replace(/\/$/, "")}/v1/license/validate`;
3278
+ let res;
3279
+ try {
3280
+ res = await fetch(validateUrl, {
3281
+ method: "POST",
3282
+ cache: "no-store",
3283
+ headers: __spreadValues({
3284
+ "Content-Type": "application/json",
3285
+ "x-license-key": licenseKey,
3286
+ "x-sdk-version": sdkVersion
3287
+ }, customHeaders || {}),
3288
+ body: JSON.stringify({
3289
+ licenseKey,
3290
+ projectId,
3291
+ sdkVersion,
3292
+ sdk,
3293
+ platform
3294
+ })
3295
+ });
3296
+ } catch (err) {
3297
+ this.purgeCache(licenseKey);
3298
+ throw new LicenseValidationError(`License validation request failed: ${(err == null ? void 0 : err.message) || "Network error"}`);
3299
+ }
3300
+ const data = await res.json().catch(() => ({
3301
+ valid: false,
3302
+ licenseStatus: "REVOKED",
3303
+ minimumSupportedVersion: "2.1.0",
3304
+ latestVersion: SDK_VERSION,
3305
+ forceUpgrade: false,
3306
+ expiresAt: null,
3307
+ message: "Failed to parse license validation response."
3308
+ }));
3309
+ if (!res.ok || !data.valid || data.licenseStatus !== "ACTIVE" || data.forceUpgrade) {
3310
+ this.purgeCache(licenseKey);
3311
+ if (data.forceUpgrade || res.status === 426) {
3312
+ throw new SDKVersionUnsupportedError(
3313
+ data.message || `This SDK version (${sdkVersion}) is no longer supported. Upgrade to version ${data.latestVersion || "2.2.6"} or later.`,
3314
+ data
3315
+ );
3316
+ }
3317
+ const errMsg = data.message || `License validation failed with status: ${data.licenseStatus}. Access denied.`;
3318
+ throw new LicenseValidationError(errMsg, data);
3319
+ }
3320
+ this.cache.set(licenseKey, {
3321
+ response: data,
3322
+ timestamp: Date.now()
3323
+ });
3324
+ return data;
3325
+ }
3326
+ };
3327
+ _LicenseValidator.SUCCESS_CACHE_TTL_MS = 5 * 60 * 1e3;
3328
+ var LicenseValidator = _LicenseValidator;
3329
+
3172
3330
  // src/components/ChatWindow.tsx
3173
3331
  var import_jsx_runtime13 = require("react/jsx-runtime");
3174
3332
  function ChatWindow({
@@ -3212,42 +3370,32 @@ function ChatWindow({
3212
3370
  async function validateSessionLicense() {
3213
3371
  var _a2;
3214
3372
  try {
3215
- const base = retrivoraApiBase || "/api/retrivora";
3216
- const configUrl = `${base.replace(/\/$/, "")}/config?sdkVersion=${SDK_VERSION}`;
3217
- const res = await fetch(configUrl, {
3218
- method: "GET",
3219
- cache: "no-store",
3220
- headers: __spreadValues({
3221
- "Content-Type": "application/json",
3222
- "x-sdk-version": SDK_VERSION
3223
- }, headers || {})
3373
+ 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, "")) || "";
3374
+ await LicenseValidator.getInstance().validate({
3375
+ licenseKey,
3376
+ projectId,
3377
+ retrivoraApiBase,
3378
+ headers
3224
3379
  });
3225
- if (!res.ok) {
3226
- const data = await res.json().catch(() => ({}));
3227
- if (res.status === 426 || data.code === "SDK_VERSION_OUTDATED") {
3228
- if (isMounted) {
3229
- setVersionError(data.error || "Your Retrivora SDK package is outdated. Please update your package to the latest version to continue.");
3230
- }
3231
- } else if (res.status === 403 || res.status === 401 || typeof data.error === "string" && data.error.toLowerCase().includes("license")) {
3232
- if (isMounted) {
3233
- const errMsg = typeof data.error === "string" ? data.error : ((_a2 = data.error) == null ? void 0 : _a2.message) || "Your Retrivora license is no longer valid. Please contact your administrator or obtain a valid license key.";
3234
- setLicenseError(errMsg);
3235
- }
3236
- }
3237
- } else {
3238
- if (isMounted) {
3239
- setLicenseError(null);
3240
- setVersionError(null);
3380
+ if (isMounted) {
3381
+ setLicenseError(null);
3382
+ setVersionError(null);
3383
+ }
3384
+ } catch (err) {
3385
+ if (isMounted) {
3386
+ if ((err == null ? void 0 : err.code) === "SDK_VERSION_UNSUPPORTED") {
3387
+ setVersionError((err == null ? void 0 : err.message) || "SDK version unsupported.");
3388
+ } else {
3389
+ setLicenseError((err == null ? void 0 : err.message) || "License validation failed.");
3241
3390
  }
3242
3391
  }
3243
- } catch (e) {
3244
3392
  }
3245
3393
  }
3246
3394
  validateSessionLicense();
3247
3395
  return () => {
3248
3396
  isMounted = false;
3249
3397
  };
3250
- }, [retrivoraApiBase, headers]);
3398
+ }, [retrivoraApiBase, headers, projectId]);
3251
3399
  (0, import_react12.useEffect)(() => {
3252
3400
  if (typeof window !== "undefined") {
3253
3401
  const win = window;
@@ -3696,7 +3844,7 @@ var GEMINI_STYLES = `
3696
3844
  }
3697
3845
  `;
3698
3846
  function ChatWidget({ position = "bottom-right", onAddToCart, apiUrl, retrivoraApiBase, headers }) {
3699
- const { ui } = useConfig();
3847
+ const { ui, projectId } = useConfig();
3700
3848
  const [isOpen, setIsOpen] = (0, import_react13.useState)(false);
3701
3849
  const [hasUnread, setHasUnread] = (0, import_react13.useState)(false);
3702
3850
  const [dimensions, setDimensions] = (0, import_react13.useState)(DEFAULT_DIMENSIONS);
@@ -3712,36 +3860,19 @@ function ChatWidget({ position = "bottom-right", onAddToCart, apiUrl, retrivoraA
3712
3860
  var _a;
3713
3861
  setIsValidating(true);
3714
3862
  try {
3715
- const base = retrivoraApiBase || "/api/retrivora";
3716
- const configUrl = `${base.replace(/\/$/, "")}/config?sdkVersion=${SDK_VERSION}`;
3717
- const res = await fetch(configUrl, {
3718
- method: "GET",
3719
- cache: "no-store",
3720
- headers: __spreadValues({
3721
- "Content-Type": "application/json",
3722
- "x-sdk-version": SDK_VERSION
3723
- }, headers || {})
3863
+ 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, "")) || "";
3864
+ await LicenseValidator.getInstance().validate({
3865
+ licenseKey,
3866
+ projectId,
3867
+ retrivoraApiBase,
3868
+ headers
3724
3869
  });
3725
- if (!res.ok) {
3726
- const data = await res.json().catch(() => ({}));
3727
- if (res.status === 426 || data.code === "SDK_VERSION_OUTDATED") {
3728
- const msg = data.error || "Your Retrivora SDK package version is outdated. Please update your package to the latest version to continue.";
3729
- setWidgetError(msg);
3730
- setIsOpen(false);
3731
- return;
3732
- }
3733
- if (res.status === 403 || res.status === 401 || typeof data.error === "string" && data.error.toLowerCase().includes("license")) {
3734
- const msg = (typeof data.error === "string" ? data.error : (_a = data.error) == null ? void 0 : _a.message) || "Your Retrivora license is no longer valid. Please contact your administrator or obtain a valid license key.";
3735
- setWidgetError(msg);
3736
- setIsOpen(false);
3737
- return;
3738
- }
3739
- }
3740
3870
  setWidgetError(null);
3741
3871
  setIsOpen(true);
3742
3872
  setHasUnread(false);
3743
- } catch (e) {
3744
- setIsOpen(true);
3873
+ } catch (err) {
3874
+ setWidgetError((err == null ? void 0 : err.message) || "Access denied.");
3875
+ setIsOpen(false);
3745
3876
  } finally {
3746
3877
  setIsValidating(false);
3747
3878
  }
@@ -5880,46 +6011,6 @@ _RendererRegistry.registerStrategy(new CarouselRendererStrategy());
5880
6011
  _RendererRegistry.registerStrategy(new ChartRendererStrategy());
5881
6012
  _RendererRegistry.registerStrategy(new MixedRendererStrategy());
5882
6013
  var RendererRegistry = _RendererRegistry;
5883
-
5884
- // src/exceptions/index.ts
5885
- var RetrivoraError = class extends Error {
5886
- constructor(message, code, details) {
5887
- super(message);
5888
- this.name = new.target.name;
5889
- this.code = code;
5890
- this.details = details;
5891
- }
5892
- };
5893
- var ProviderNotFoundException = class extends RetrivoraError {
5894
- constructor(providerType, provider, details) {
5895
- super(`Unsupported ${providerType} provider: ${provider}`, "PROVIDER_NOT_FOUND", details);
5896
- }
5897
- };
5898
- var EmbeddingFailedException = class extends RetrivoraError {
5899
- constructor(message = "Embedding generation failed", details) {
5900
- super(message, "EMBEDDING_FAILED", details);
5901
- }
5902
- };
5903
- var RetrievalException = class extends RetrivoraError {
5904
- constructor(message = "Retrieval failed", details) {
5905
- super(message, "RETRIEVAL_FAILED", details);
5906
- }
5907
- };
5908
- var RateLimitException = class extends RetrivoraError {
5909
- constructor(message = "Provider rate limit exceeded", details) {
5910
- super(message, "RATE_LIMITED", details);
5911
- }
5912
- };
5913
- var ConfigurationException = class extends RetrivoraError {
5914
- constructor(message, details) {
5915
- super(message, "CONFIGURATION_ERROR", details);
5916
- }
5917
- };
5918
- var AuthenticationException = class extends RetrivoraError {
5919
- constructor(message = "Provider authentication failed", details) {
5920
- super(message, "AUTHENTICATION_ERROR", details);
5921
- }
5922
- };
5923
6014
  // Annotate the CommonJS export names for ESM import in node:
5924
6015
  0 && (module.exports = {
5925
6016
  AuthenticationException,
@@ -5931,6 +6022,8 @@ var AuthenticationException = class extends RetrivoraError {
5931
6022
  DocumentUpload,
5932
6023
  EmbeddingFailedException,
5933
6024
  IntentClassifier,
6025
+ LicenseValidationError,
6026
+ LicenseValidator,
5934
6027
  MessageBubble,
5935
6028
  ObservabilityPanel,
5936
6029
  ProductCard,
@@ -5941,6 +6034,7 @@ var AuthenticationException = class extends RetrivoraError {
5941
6034
  RetrievalException,
5942
6035
  RetrivoraError,
5943
6036
  RuleEngine,
6037
+ SDKVersionUnsupportedError,
5944
6038
  SDK_VERSION,
5945
6039
  SourceCard,
5946
6040
  VisualizationDecisionEngine,