@retrivora-ai/rag-engine 2.3.7 → 2.3.8
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/handlers/index.d.mts +1 -1
- package/dist/handlers/index.d.ts +1 -1
- package/dist/handlers/index.js +227 -117
- package/dist/handlers/index.mjs +229 -119
- package/dist/{index-ejOWsaqb.d.ts → index-BQd6Bax0.d.ts} +1 -1
- package/dist/{index-xxQOFx-u.d.mts → index-C7aHK7_g.d.mts} +1 -1
- package/dist/index.js +114 -87
- package/dist/index.mjs +114 -87
- package/dist/server.d.mts +12 -32
- package/dist/server.d.ts +12 -32
- package/dist/server.js +232 -121
- package/dist/server.mjs +234 -123
- package/package.json +1 -1
- package/src/components/ChatWidget.tsx +0 -1
- package/src/components/ConfigProvider.tsx +2 -1
- package/src/config/serverConfig.ts +1 -2
- package/src/core/ConfigFetcher.ts +36 -3
- package/src/core/DatabaseStorage.ts +13 -13
- package/src/core/LicenseValidator.ts +5 -3
- package/src/core/LicenseVerifier.ts +85 -120
- package/src/core/Retrivora.ts +1 -1
- package/src/core/VectorPlugin.ts +1 -1
- package/src/handlers/index.ts +23 -13
- package/src/providers/vectordb/PineconeProvider.ts +69 -2
package/dist/server.mjs
CHANGED
|
@@ -315,7 +315,7 @@ var init_package = __esm({
|
|
|
315
315
|
"package.json"() {
|
|
316
316
|
package_default = {
|
|
317
317
|
name: "@retrivora-ai/rag-engine",
|
|
318
|
-
version: "2.3.
|
|
318
|
+
version: "2.3.8",
|
|
319
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
320
|
author: "Abhinav Alkuchi",
|
|
321
321
|
license: "UNLICENSED",
|
|
@@ -501,7 +501,12 @@ var init_ConfigFetcher = __esm({
|
|
|
501
501
|
process.env.RETRIVORA_CONTROL_PLANE_URL,
|
|
502
502
|
process.env.NEXT_PUBLIC_RETRIVORA_CONTROL_PLANE_URL,
|
|
503
503
|
CONTROL_PLANE_URL
|
|
504
|
-
].filter((url) =>
|
|
504
|
+
].filter((url) => {
|
|
505
|
+
if (!url) return false;
|
|
506
|
+
const isEnvVar = url === process.env.RETRIVORA_CONTROL_PLANE_URL || url === process.env.NEXT_PUBLIC_RETRIVORA_CONTROL_PLANE_URL;
|
|
507
|
+
if (!isEnvVar && (url.includes("localhost") || url.includes("127.0.0.1"))) return false;
|
|
508
|
+
return true;
|
|
509
|
+
}).map((url) => url.replace(/\/$/, ""));
|
|
505
510
|
for (const baseUrl of controlPlaneUrls) {
|
|
506
511
|
try {
|
|
507
512
|
const url = `${baseUrl}/api/v1/config?projectId=${encodeURIComponent(projectId)}`;
|
|
@@ -522,8 +527,7 @@ var init_ConfigFetcher = __esm({
|
|
|
522
527
|
isActive: data.isActive,
|
|
523
528
|
expiresAt: data.expiresAt,
|
|
524
529
|
vectorDb: {
|
|
525
|
-
// apiKey
|
|
526
|
-
// The SDK uses local PINECONE_API_KEY if available.
|
|
530
|
+
// Fetch apiKey from credentials API if available, else fallback to empty
|
|
527
531
|
apiKey: data.vectorDb.apiKey || "",
|
|
528
532
|
indexName: data.vectorDb.indexName || "retrivora-free",
|
|
529
533
|
provider: data.vectorDb.provider || "pinecone",
|
|
@@ -555,6 +559,32 @@ var init_ConfigFetcher = __esm({
|
|
|
555
559
|
data.projectSettings || data.settings
|
|
556
560
|
)
|
|
557
561
|
};
|
|
562
|
+
if (licenseKey) {
|
|
563
|
+
try {
|
|
564
|
+
const credUrl = `${baseUrl}/api/v1/credentials`;
|
|
565
|
+
const credRes = await fetch(credUrl, {
|
|
566
|
+
method: "POST",
|
|
567
|
+
headers: {
|
|
568
|
+
"Content-Type": "application/json"
|
|
569
|
+
},
|
|
570
|
+
body: JSON.stringify({ licenseKey, projectId: fetchedProjectId })
|
|
571
|
+
});
|
|
572
|
+
if (credRes.ok) {
|
|
573
|
+
const credData = await credRes.json();
|
|
574
|
+
if ((credData == null ? void 0 : credData.success) && (credData == null ? void 0 : credData.credentials)) {
|
|
575
|
+
if (credData.credentials.pineconeApiKey && !config.vectorDb.apiKey) {
|
|
576
|
+
config.vectorDb.apiKey = credData.credentials.pineconeApiKey;
|
|
577
|
+
}
|
|
578
|
+
if (credData.credentials.litellmApiKey) {
|
|
579
|
+
config.llm.apiKey = credData.credentials.litellmApiKey;
|
|
580
|
+
config.embedding.apiKey = credData.credentials.litellmApiKey;
|
|
581
|
+
}
|
|
582
|
+
}
|
|
583
|
+
}
|
|
584
|
+
} catch (e) {
|
|
585
|
+
console.warn("[ConfigFetcher] Failed to fetch credentials:", e);
|
|
586
|
+
}
|
|
587
|
+
}
|
|
558
588
|
this.cache.set(cacheKey, { config, cachedAt: now });
|
|
559
589
|
return config;
|
|
560
590
|
}
|
|
@@ -594,6 +624,14 @@ var init_PineconeProvider = __esm({
|
|
|
594
624
|
const opts = config.options || {};
|
|
595
625
|
this.apiKey = opts.apiKey || process.env.PINECONE_API_KEY || "";
|
|
596
626
|
}
|
|
627
|
+
getControlPlaneUrl() {
|
|
628
|
+
const urls = [
|
|
629
|
+
process.env.RETRIVORA_CONTROL_PLANE_URL,
|
|
630
|
+
process.env.NEXT_PUBLIC_RETRIVORA_CONTROL_PLANE_URL,
|
|
631
|
+
"https://www.retrivora.com"
|
|
632
|
+
].filter((url) => Boolean(url));
|
|
633
|
+
return urls[0].replace(/\/$/, "");
|
|
634
|
+
}
|
|
597
635
|
static getValidator() {
|
|
598
636
|
return {
|
|
599
637
|
validate(config) {
|
|
@@ -657,6 +695,7 @@ var init_PineconeProvider = __esm({
|
|
|
657
695
|
let key = this.apiKey || process.env.PINECONE_API_KEY || "";
|
|
658
696
|
if (!key) {
|
|
659
697
|
const licenseKey = process.env.RETRIVORA_LICENSE_KEY || process.env.NEXT_PUBLIC_RETRIVORA_LICENSE_KEY;
|
|
698
|
+
this.licenseKey = licenseKey;
|
|
660
699
|
const jwtProjectId = (() => {
|
|
661
700
|
if (!licenseKey) return void 0;
|
|
662
701
|
try {
|
|
@@ -670,6 +709,7 @@ var init_PineconeProvider = __esm({
|
|
|
670
709
|
return void 0;
|
|
671
710
|
})();
|
|
672
711
|
const projectId = process.env.RAG_PROJECT_ID || process.env.NEXT_PUBLIC_RAG_PROJECT_ID || jwtProjectId || this.projectId || "default";
|
|
712
|
+
this.projectId = projectId;
|
|
673
713
|
const remoteConfig = await ConfigFetcher.fetchRemoteVectorConfig(projectId, licenseKey);
|
|
674
714
|
if (remoteConfig) {
|
|
675
715
|
if (remoteConfig.apiKey) {
|
|
@@ -715,19 +755,59 @@ var init_PineconeProvider = __esm({
|
|
|
715
755
|
return namespace ? idx.namespace(namespace) : idx.namespace("");
|
|
716
756
|
}
|
|
717
757
|
async upsert(doc, namespace) {
|
|
718
|
-
var _a3;
|
|
758
|
+
var _a3, _b;
|
|
759
|
+
if (!this.client) {
|
|
760
|
+
if (!this.licenseKey) throw new Error("[PineconeProvider] Cannot execute vector operation: Missing API key and License key.");
|
|
761
|
+
const res = await fetch(`${this.getControlPlaneUrl()}/api/v1/vectors/upsert`, {
|
|
762
|
+
method: "POST",
|
|
763
|
+
headers: { "Content-Type": "application/json", "x-license-key": this.licenseKey },
|
|
764
|
+
body: JSON.stringify({
|
|
765
|
+
projectId: this.projectId,
|
|
766
|
+
indexName: this.indexName,
|
|
767
|
+
namespace: namespace || this.projectId,
|
|
768
|
+
records: [{ id: String(doc.id), values: doc.vector, metadata: __spreadValues({ content: doc.content }, (_a3 = doc.metadata) != null ? _a3 : {}) }]
|
|
769
|
+
})
|
|
770
|
+
});
|
|
771
|
+
if (!res.ok) throw new Error(`[PineconeProvider] Proxy upsert failed: ${await res.text()}`);
|
|
772
|
+
return;
|
|
773
|
+
}
|
|
719
774
|
const targetIdx = await this.getActiveIndex(namespace);
|
|
720
775
|
await targetIdx.upsert({
|
|
721
776
|
records: [{
|
|
722
777
|
id: String(doc.id),
|
|
723
778
|
values: doc.vector,
|
|
724
|
-
metadata: __spreadValues({ content: doc.content }, (
|
|
779
|
+
metadata: __spreadValues({ content: doc.content }, (_b = doc.metadata) != null ? _b : {})
|
|
725
780
|
}]
|
|
726
781
|
});
|
|
727
782
|
}
|
|
728
783
|
async batchUpsert(docs, namespace) {
|
|
729
|
-
const targetIdx = await this.getActiveIndex(namespace);
|
|
730
784
|
const BATCH = 100;
|
|
785
|
+
if (!this.client) {
|
|
786
|
+
if (!this.licenseKey) throw new Error("[PineconeProvider] Cannot execute vector operation: Missing API key and License key.");
|
|
787
|
+
for (let i = 0; i < docs.length; i += BATCH) {
|
|
788
|
+
const records = docs.slice(i, i + BATCH).map((d) => {
|
|
789
|
+
var _a3;
|
|
790
|
+
return {
|
|
791
|
+
id: String(d.id),
|
|
792
|
+
values: d.vector,
|
|
793
|
+
metadata: __spreadValues({ content: d.content }, (_a3 = d.metadata) != null ? _a3 : {})
|
|
794
|
+
};
|
|
795
|
+
});
|
|
796
|
+
const res = await fetch(`${this.getControlPlaneUrl()}/api/v1/vectors/upsert`, {
|
|
797
|
+
method: "POST",
|
|
798
|
+
headers: { "Content-Type": "application/json", "x-license-key": this.licenseKey },
|
|
799
|
+
body: JSON.stringify({
|
|
800
|
+
projectId: this.projectId,
|
|
801
|
+
indexName: this.indexName,
|
|
802
|
+
namespace: namespace || this.projectId,
|
|
803
|
+
records
|
|
804
|
+
})
|
|
805
|
+
});
|
|
806
|
+
if (!res.ok) throw new Error(`[PineconeProvider] Proxy batch upsert failed: ${await res.text()}`);
|
|
807
|
+
}
|
|
808
|
+
return;
|
|
809
|
+
}
|
|
810
|
+
const targetIdx = await this.getActiveIndex(namespace);
|
|
731
811
|
for (let i = 0; i < docs.length; i += BATCH) {
|
|
732
812
|
const records = docs.slice(i, i + BATCH).map((d) => {
|
|
733
813
|
var _a3;
|
|
@@ -741,20 +821,46 @@ var init_PineconeProvider = __esm({
|
|
|
741
821
|
}
|
|
742
822
|
}
|
|
743
823
|
async query(vector, topK, namespace, filter) {
|
|
744
|
-
var _a3;
|
|
745
|
-
const targetIdx = await this.getActiveIndex(namespace);
|
|
824
|
+
var _a3, _b;
|
|
746
825
|
const pineconeFilter = this.sanitizeFilter(filter);
|
|
826
|
+
if (!this.client) {
|
|
827
|
+
if (!this.licenseKey) throw new Error("[PineconeProvider] Cannot execute vector operation: Missing API key and License key.");
|
|
828
|
+
const res = await fetch(`${this.getControlPlaneUrl()}/api/v1/vectors/query`, {
|
|
829
|
+
method: "POST",
|
|
830
|
+
headers: { "Content-Type": "application/json", "x-license-key": this.licenseKey },
|
|
831
|
+
body: JSON.stringify({
|
|
832
|
+
projectId: this.projectId,
|
|
833
|
+
indexName: this.indexName,
|
|
834
|
+
namespace: namespace || this.projectId,
|
|
835
|
+
vector,
|
|
836
|
+
topK,
|
|
837
|
+
filter: pineconeFilter
|
|
838
|
+
})
|
|
839
|
+
});
|
|
840
|
+
if (!res.ok) throw new Error(`[PineconeProvider] Proxy query failed: ${await res.text()}`);
|
|
841
|
+
const data = await res.json();
|
|
842
|
+
return ((_a3 = data.matches) != null ? _a3 : []).map((m) => {
|
|
843
|
+
var _a4, _b2;
|
|
844
|
+
return {
|
|
845
|
+
id: m.id,
|
|
846
|
+
score: (_a4 = m.score) != null ? _a4 : 0,
|
|
847
|
+
content: ((_b2 = m.metadata) == null ? void 0 : _b2.content) || "",
|
|
848
|
+
metadata: m.metadata
|
|
849
|
+
};
|
|
850
|
+
});
|
|
851
|
+
}
|
|
852
|
+
const targetIdx = await this.getActiveIndex(namespace);
|
|
747
853
|
const result = await targetIdx.query(__spreadValues({
|
|
748
854
|
vector,
|
|
749
855
|
topK,
|
|
750
856
|
includeMetadata: true
|
|
751
857
|
}, Object.keys(pineconeFilter).length > 0 ? { filter: pineconeFilter } : {}));
|
|
752
|
-
return ((
|
|
753
|
-
var _a4,
|
|
858
|
+
return ((_b = result.matches) != null ? _b : []).map((m) => {
|
|
859
|
+
var _a4, _b2;
|
|
754
860
|
return {
|
|
755
861
|
id: m.id,
|
|
756
862
|
score: (_a4 = m.score) != null ? _a4 : 0,
|
|
757
|
-
content: ((
|
|
863
|
+
content: ((_b2 = m.metadata) == null ? void 0 : _b2.content) || "",
|
|
758
864
|
metadata: m.metadata
|
|
759
865
|
};
|
|
760
866
|
});
|
|
@@ -1733,7 +1839,7 @@ __export(QdrantProvider_exports, {
|
|
|
1733
1839
|
QdrantProvider: () => QdrantProvider
|
|
1734
1840
|
});
|
|
1735
1841
|
import axios4 from "axios";
|
|
1736
|
-
import
|
|
1842
|
+
import crypto from "crypto";
|
|
1737
1843
|
var QdrantProvider;
|
|
1738
1844
|
var init_QdrantProvider = __esm({
|
|
1739
1845
|
"src/providers/vectordb/QdrantProvider.ts"() {
|
|
@@ -1965,7 +2071,7 @@ var init_QdrantProvider = __esm({
|
|
|
1965
2071
|
if (typeof id === "number") return id;
|
|
1966
2072
|
const uuidRegex = /^[0-9a-f]{8}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{12}$/i;
|
|
1967
2073
|
if (uuidRegex.test(id)) return id.toLowerCase();
|
|
1968
|
-
const hash =
|
|
2074
|
+
const hash = crypto.createHash("md5").update(id).digest("hex");
|
|
1969
2075
|
return `${hash.slice(0, 8)}-${hash.slice(8, 12)}-${hash.slice(12, 16)}-${hash.slice(16, 20)}-${hash.slice(20, 32)}`;
|
|
1970
2076
|
}
|
|
1971
2077
|
async disconnect() {
|
|
@@ -2547,9 +2653,6 @@ var init_SimpleGraphProvider = __esm({
|
|
|
2547
2653
|
// src/core/ConfigResolver.ts
|
|
2548
2654
|
init_templateUtils();
|
|
2549
2655
|
|
|
2550
|
-
// src/core/LicenseVerifier.ts
|
|
2551
|
-
import * as crypto from "crypto";
|
|
2552
|
-
|
|
2553
2656
|
// src/exceptions/index.ts
|
|
2554
2657
|
var RetrivoraError = class extends Error {
|
|
2555
2658
|
constructor(message, code, details) {
|
|
@@ -2635,29 +2738,18 @@ function wrapError(err, defaultCode, defaultMessage) {
|
|
|
2635
2738
|
}
|
|
2636
2739
|
|
|
2637
2740
|
// src/core/LicenseVerifier.ts
|
|
2638
|
-
var
|
|
2741
|
+
var _LicenseVerifier = class _LicenseVerifier {
|
|
2742
|
+
// Cache verified license for 5 minutes
|
|
2639
2743
|
/**
|
|
2640
|
-
*
|
|
2744
|
+
* Validates the license key asynchronously by calling the Retrivora backend.
|
|
2641
2745
|
*
|
|
2642
2746
|
* @param licenseKey - Base64url signed JWT license key.
|
|
2643
2747
|
* @param currentProjectId - Project namespace ID.
|
|
2644
|
-
* @param
|
|
2748
|
+
* @param provider - Optional provider for tier checks.
|
|
2645
2749
|
*/
|
|
2646
|
-
static
|
|
2750
|
+
static async verifyAsync(licenseKey, currentProjectId, provider) {
|
|
2647
2751
|
const isProduction = process.env.NODE_ENV === "production";
|
|
2648
2752
|
const now = Date.now();
|
|
2649
|
-
if (licenseKey) {
|
|
2650
|
-
const cacheKey = `${licenseKey}:${currentProjectId}:${provider || ""}:${publicKeyOverride || ""}`;
|
|
2651
|
-
const cached = this.cache.get(cacheKey);
|
|
2652
|
-
if (cached && now - cached.cachedAt < this.CACHE_TTL_MS) {
|
|
2653
|
-
const currentTimestampSec = Math.floor(now / 1e3);
|
|
2654
|
-
if (cached.payload.expiresAt && currentTimestampSec > cached.payload.expiresAt) {
|
|
2655
|
-
this.cache.delete(cacheKey);
|
|
2656
|
-
} else {
|
|
2657
|
-
return cached.payload;
|
|
2658
|
-
}
|
|
2659
|
-
}
|
|
2660
|
-
}
|
|
2661
2753
|
if (!licenseKey) {
|
|
2662
2754
|
if (isProduction) {
|
|
2663
2755
|
throw new ConfigurationException(
|
|
@@ -2674,52 +2766,61 @@ var LicenseVerifier = class {
|
|
|
2674
2766
|
tier: "hobby"
|
|
2675
2767
|
};
|
|
2676
2768
|
}
|
|
2677
|
-
|
|
2678
|
-
|
|
2679
|
-
|
|
2680
|
-
const
|
|
2681
|
-
if (
|
|
2682
|
-
|
|
2683
|
-
}
|
|
2684
|
-
|
|
2685
|
-
const dataToVerify = `${headerB64}.${payloadB64}`;
|
|
2686
|
-
const publicKey = publicKeyOverride != null ? publicKeyOverride : this.PUBLIC_KEY;
|
|
2687
|
-
const signature = Buffer.from(signatureB64, "base64url");
|
|
2688
|
-
const data = Buffer.from(dataToVerify);
|
|
2689
|
-
const isValid = crypto.verify(
|
|
2690
|
-
"sha256",
|
|
2691
|
-
data,
|
|
2692
|
-
publicKey,
|
|
2693
|
-
signature
|
|
2694
|
-
);
|
|
2695
|
-
if (!isValid) {
|
|
2696
|
-
throw new Error("Signature verification failed.");
|
|
2769
|
+
const cacheKey = `${licenseKey}:${currentProjectId}:${provider || ""}`;
|
|
2770
|
+
const cached = this.cache.get(cacheKey);
|
|
2771
|
+
if (cached && now - cached.cachedAt < this.CACHE_TTL_MS) {
|
|
2772
|
+
const currentTimestampSec = Math.floor(now / 1e3);
|
|
2773
|
+
if (cached.payload.expiresAt && currentTimestampSec > cached.payload.expiresAt) {
|
|
2774
|
+
this.cache.delete(cacheKey);
|
|
2775
|
+
} else {
|
|
2776
|
+
return cached.payload;
|
|
2697
2777
|
}
|
|
2698
|
-
|
|
2699
|
-
|
|
2700
|
-
|
|
2701
|
-
if (
|
|
2702
|
-
|
|
2778
|
+
}
|
|
2779
|
+
try {
|
|
2780
|
+
let baseUrl = typeof process !== "undefined" && process.env.RETRIVORA_CONTROL_PLANE_URL ? process.env.RETRIVORA_CONTROL_PLANE_URL : "https://retrivora.com";
|
|
2781
|
+
if (typeof process !== "undefined" && process.env.TELEMETRY_URL) {
|
|
2782
|
+
baseUrl = process.env.TELEMETRY_URL.replace(/\/api\/telemetry\/?$/, "");
|
|
2703
2783
|
}
|
|
2704
|
-
const
|
|
2705
|
-
|
|
2706
|
-
|
|
2707
|
-
|
|
2708
|
-
|
|
2784
|
+
const endpoint = `${baseUrl}/api/v1/license/validate`;
|
|
2785
|
+
const response = await fetch(endpoint, {
|
|
2786
|
+
method: "POST",
|
|
2787
|
+
headers: {
|
|
2788
|
+
"Content-Type": "application/json",
|
|
2789
|
+
"x-license-key": licenseKey
|
|
2790
|
+
},
|
|
2791
|
+
body: JSON.stringify({
|
|
2792
|
+
licenseKey,
|
|
2793
|
+
projectId: currentProjectId,
|
|
2794
|
+
provider
|
|
2795
|
+
})
|
|
2796
|
+
});
|
|
2797
|
+
if (!response.ok) {
|
|
2798
|
+
let errMessage = `HTTP ${response.status}`;
|
|
2799
|
+
try {
|
|
2800
|
+
const body = await response.json();
|
|
2801
|
+
if (body.message) errMessage = body.message;
|
|
2802
|
+
} catch (e) {
|
|
2803
|
+
}
|
|
2804
|
+
throw new Error(errMessage);
|
|
2709
2805
|
}
|
|
2710
|
-
|
|
2711
|
-
|
|
2806
|
+
const data = await response.json();
|
|
2807
|
+
if (!data.valid) {
|
|
2808
|
+
throw new Error(data.message || "License validation failed by server.");
|
|
2712
2809
|
}
|
|
2713
|
-
|
|
2714
|
-
if (
|
|
2715
|
-
|
|
2716
|
-
`License key has expired. Expiration: ${new Date(
|
|
2717
|
-
payload.expiresAt * 1e3
|
|
2718
|
-
).toDateString()}`
|
|
2719
|
-
);
|
|
2810
|
+
let expiresAtNum = Math.floor(Date.now() / 1e3) + 100 * 365 * 24 * 60 * 60;
|
|
2811
|
+
if (data.expiresAt) {
|
|
2812
|
+
expiresAtNum = Math.floor(new Date(data.expiresAt).getTime() / 1e3);
|
|
2720
2813
|
}
|
|
2814
|
+
const tier = _LicenseVerifier.extractTier(licenseKey);
|
|
2815
|
+
const payload = {
|
|
2816
|
+
projectId: currentProjectId,
|
|
2817
|
+
expiresAt: expiresAtNum,
|
|
2818
|
+
tier,
|
|
2819
|
+
licenseStatus: data.licenseStatus,
|
|
2820
|
+
minimumSupportedVersion: data.minimumSupportedVersion,
|
|
2821
|
+
forceUpgrade: data.forceUpgrade
|
|
2822
|
+
};
|
|
2721
2823
|
if (isProduction && provider) {
|
|
2722
|
-
const tier = (payload.tier || "").toLowerCase();
|
|
2723
2824
|
const normalizedProvider = provider.toLowerCase();
|
|
2724
2825
|
if (tier === "hobby") {
|
|
2725
2826
|
const allowedHobby = ["postgresql", "pgvector", "supabase"];
|
|
@@ -2747,15 +2848,12 @@ var LicenseVerifier = class {
|
|
|
2747
2848
|
}
|
|
2748
2849
|
}
|
|
2749
2850
|
}
|
|
2750
|
-
|
|
2751
|
-
const cacheKey = `${licenseKey}:${currentProjectId}:${provider || ""}:${publicKeyOverride || ""}`;
|
|
2752
|
-
this.cache.set(cacheKey, { payload, cachedAt: now });
|
|
2753
|
-
}
|
|
2851
|
+
this.cache.set(cacheKey, { payload, cachedAt: now });
|
|
2754
2852
|
return payload;
|
|
2755
2853
|
} catch (err) {
|
|
2756
2854
|
const message = err instanceof Error ? err.message : String(err);
|
|
2757
2855
|
throw new ConfigurationException(
|
|
2758
|
-
`[Retrivora SDK] License key validation failed: ${message}`
|
|
2856
|
+
`[Retrivora SDK] License key validation failed via API: ${message}`
|
|
2759
2857
|
);
|
|
2760
2858
|
}
|
|
2761
2859
|
}
|
|
@@ -2824,23 +2922,25 @@ var LicenseVerifier = class {
|
|
|
2824
2922
|
}
|
|
2825
2923
|
}
|
|
2826
2924
|
}
|
|
2925
|
+
static extractTier(licenseKey) {
|
|
2926
|
+
if (!licenseKey) return "hobby";
|
|
2927
|
+
try {
|
|
2928
|
+
const sanitizedKey = licenseKey.trim().replace(/^["']|["']$/g, "").trim();
|
|
2929
|
+
const rawToken = sanitizedKey.replace(/^rtv_/i, "").trim();
|
|
2930
|
+
const parts = rawToken.split(".");
|
|
2931
|
+
if (parts.length === 3) {
|
|
2932
|
+
const decodedPayload = JSON.parse(Buffer.from(parts[1], "base64url").toString("utf8"));
|
|
2933
|
+
if (decodedPayload.tier) return decodedPayload.tier;
|
|
2934
|
+
}
|
|
2935
|
+
} catch (e) {
|
|
2936
|
+
}
|
|
2937
|
+
return "hobby";
|
|
2938
|
+
}
|
|
2827
2939
|
};
|
|
2828
|
-
//
|
|
2829
|
-
|
|
2830
|
-
|
|
2831
|
-
|
|
2832
|
-
// Retrivora's Public Key used to verify the license key signature.
|
|
2833
|
-
// In production, this matches the private key held by Retrivora SaaS.
|
|
2834
|
-
// Rotate this key only when the signing private key is replaced.
|
|
2835
|
-
LicenseVerifier.PUBLIC_KEY = `-----BEGIN PUBLIC KEY-----
|
|
2836
|
-
MIIBIjANBgkqhkiG9w0BAQEFAAOCAQ8AMIIBCgKCAQEAyKvvOSYdCimG3b236ebV
|
|
2837
|
-
jpG88xQiU8dSiaMahtBJDf4w0AewRj7hMNgmeZ1wyTOj8kVgeGBOolp1Z0QmTr6O
|
|
2838
|
-
Tj4EDQ/zjsg12If7hSf3NiwLHCYmMLslyK0aaP6PQoTrYkBv3GNdkMecrIjKCijb
|
|
2839
|
-
6VvDLLF3X696melTVM0z/d2e50BW2AlRw/rf1EqYi10d0BcPo5zje0XETr/WGmqu
|
|
2840
|
-
sDiXtsP5MlwkL9X7RQY2uovRa+l/vOAqAfdmJ+OzXuk5P7mDUPb+gCtKnoDbb1tr
|
|
2841
|
-
6UAu733dkUnetAcMqyT3fNPBLO66DCc6m9rGCYYAaG7piMEDwG0/ZySZBFbgllJc
|
|
2842
|
-
6QIDAQAB
|
|
2843
|
-
-----END PUBLIC KEY-----`;
|
|
2940
|
+
// In-memory cache to save network overhead on hot paths.
|
|
2941
|
+
_LicenseVerifier.cache = /* @__PURE__ */ new Map();
|
|
2942
|
+
_LicenseVerifier.CACHE_TTL_MS = 5 * 60 * 1e3;
|
|
2943
|
+
var LicenseVerifier = _LicenseVerifier;
|
|
2844
2944
|
|
|
2845
2945
|
// src/config/constants.ts
|
|
2846
2946
|
var VECTOR_DB_PROVIDERS = [
|
|
@@ -3013,8 +3113,7 @@ function getEnvConfig(env = process.env, base) {
|
|
|
3013
3113
|
const isFreeTier2 = (() => {
|
|
3014
3114
|
if (!licenseKey) return true;
|
|
3015
3115
|
try {
|
|
3016
|
-
const
|
|
3017
|
-
const tier = (payload.tier || "").toLowerCase();
|
|
3116
|
+
const tier = LicenseVerifier.extractTier(licenseKey).toLowerCase();
|
|
3018
3117
|
return tier === "free_trial" || tier === "free_tier" || tier === "free" || tier === "hobby";
|
|
3019
3118
|
} catch (e) {
|
|
3020
3119
|
return true;
|
|
@@ -9859,7 +9958,7 @@ var Retrivora = class {
|
|
|
9859
9958
|
var _a3;
|
|
9860
9959
|
try {
|
|
9861
9960
|
await ConfigValidator.validateAndThrow(this.config);
|
|
9862
|
-
LicenseVerifier.
|
|
9961
|
+
await LicenseVerifier.verifyAsync(
|
|
9863
9962
|
this.config.licenseKey,
|
|
9864
9963
|
this.config.projectId,
|
|
9865
9964
|
(_a3 = this.config.vectorDb) == null ? void 0 : _a3.provider
|
|
@@ -10225,7 +10324,7 @@ var VectorPlugin = class {
|
|
|
10225
10324
|
this.validationPromise = (async () => {
|
|
10226
10325
|
var _a3;
|
|
10227
10326
|
await ConfigValidator.validateAndThrow(resolvedConfig);
|
|
10228
|
-
LicenseVerifier.
|
|
10327
|
+
await LicenseVerifier.verifyAsync(
|
|
10229
10328
|
resolvedConfig.licenseKey,
|
|
10230
10329
|
resolvedConfig.projectId,
|
|
10231
10330
|
(_a3 = resolvedConfig.vectorDb) == null ? void 0 : _a3.provider
|
|
@@ -10719,7 +10818,7 @@ var DatabaseStorage = class {
|
|
|
10719
10818
|
* In non-production (development / test) environments this is a complete no-op —
|
|
10720
10819
|
* all History and Feedback features are freely accessible for local development.
|
|
10721
10820
|
*/
|
|
10722
|
-
checkPremiumSubscription() {
|
|
10821
|
+
async checkPremiumSubscription() {
|
|
10723
10822
|
if (process.env.NODE_ENV !== "production") {
|
|
10724
10823
|
return;
|
|
10725
10824
|
}
|
|
@@ -10729,7 +10828,7 @@ var DatabaseStorage = class {
|
|
|
10729
10828
|
);
|
|
10730
10829
|
}
|
|
10731
10830
|
try {
|
|
10732
|
-
const payload = LicenseVerifier.
|
|
10831
|
+
const payload = await LicenseVerifier.verifyAsync(this.config.licenseKey, this.config.projectId);
|
|
10733
10832
|
const tier = (payload.tier || "").toLowerCase();
|
|
10734
10833
|
if (tier !== "premium" && tier !== "enterprise" && tier !== "growth" && tier !== "pro" && tier !== "developer_pro" && tier !== "free_trial" && tier !== "free_tier" && tier !== "free" && tier !== "hobby") {
|
|
10735
10834
|
throw new Error(
|
|
@@ -10742,16 +10841,16 @@ var DatabaseStorage = class {
|
|
|
10742
10841
|
);
|
|
10743
10842
|
}
|
|
10744
10843
|
}
|
|
10745
|
-
checkHistoryEnabled() {
|
|
10844
|
+
async checkHistoryEnabled() {
|
|
10746
10845
|
var _a3, _b;
|
|
10747
|
-
this.checkPremiumSubscription();
|
|
10846
|
+
await this.checkPremiumSubscription();
|
|
10748
10847
|
if (((_b = (_a3 = this.config.rag) == null ? void 0 : _a3.history) == null ? void 0 : _b.enabled) === false) {
|
|
10749
10848
|
throw new Error("[Retrivora SDK] Chat History is disabled in RagConfig.");
|
|
10750
10849
|
}
|
|
10751
10850
|
}
|
|
10752
|
-
checkFeedbackEnabled() {
|
|
10851
|
+
async checkFeedbackEnabled() {
|
|
10753
10852
|
var _a3, _b;
|
|
10754
|
-
this.checkPremiumSubscription();
|
|
10853
|
+
await this.checkPremiumSubscription();
|
|
10755
10854
|
if (((_b = (_a3 = this.config.rag) == null ? void 0 : _a3.feedback) == null ? void 0 : _b.enabled) === false) {
|
|
10756
10855
|
throw new Error("[Retrivora SDK] User Feedback is disabled in RagConfig.");
|
|
10757
10856
|
}
|
|
@@ -10857,7 +10956,7 @@ var DatabaseStorage = class {
|
|
|
10857
10956
|
}
|
|
10858
10957
|
// ─── Message History Operations ──────────────────────────────────────────
|
|
10859
10958
|
async saveMessage(sessionId, message) {
|
|
10860
|
-
this.checkHistoryEnabled();
|
|
10959
|
+
await this.checkHistoryEnabled();
|
|
10861
10960
|
const createdAt = (/* @__PURE__ */ new Date()).toISOString();
|
|
10862
10961
|
const msgId = message.id || `msg_${Date.now()}_${Math.random().toString(36).slice(2, 6)}`;
|
|
10863
10962
|
if (this.provider === "postgresql" || this.provider === "pgvector") {
|
|
@@ -10920,7 +11019,7 @@ var DatabaseStorage = class {
|
|
|
10920
11019
|
}
|
|
10921
11020
|
}
|
|
10922
11021
|
async getHistory(sessionId, projectIds) {
|
|
10923
|
-
this.checkHistoryEnabled();
|
|
11022
|
+
await this.checkHistoryEnabled();
|
|
10924
11023
|
if (projectIds && projectIds.length > 0 && !this.sessionInScope(sessionId, projectIds)) {
|
|
10925
11024
|
return [];
|
|
10926
11025
|
}
|
|
@@ -10954,7 +11053,7 @@ var DatabaseStorage = class {
|
|
|
10954
11053
|
}
|
|
10955
11054
|
}
|
|
10956
11055
|
async clearHistory(sessionId, projectIds) {
|
|
10957
|
-
this.checkHistoryEnabled();
|
|
11056
|
+
await this.checkHistoryEnabled();
|
|
10958
11057
|
if (projectIds && projectIds.length > 0 && !this.sessionInScope(sessionId, projectIds)) {
|
|
10959
11058
|
return;
|
|
10960
11059
|
}
|
|
@@ -10990,7 +11089,7 @@ var DatabaseStorage = class {
|
|
|
10990
11089
|
);
|
|
10991
11090
|
}
|
|
10992
11091
|
async listSessions(projectIds) {
|
|
10993
|
-
this.checkHistoryEnabled();
|
|
11092
|
+
await this.checkHistoryEnabled();
|
|
10994
11093
|
let raw = [];
|
|
10995
11094
|
if (this.provider === "postgresql" || this.provider === "pgvector") {
|
|
10996
11095
|
const pool = await this.getPGPool();
|
|
@@ -11009,7 +11108,7 @@ var DatabaseStorage = class {
|
|
|
11009
11108
|
}
|
|
11010
11109
|
// ─── Feedback Operations ──────────────────────────────────────────────────
|
|
11011
11110
|
async saveFeedback(feedback) {
|
|
11012
|
-
this.checkFeedbackEnabled();
|
|
11111
|
+
await this.checkFeedbackEnabled();
|
|
11013
11112
|
const id = `fb_${Date.now()}_${Math.random().toString(36).slice(2, 6)}`;
|
|
11014
11113
|
const createdAt = (/* @__PURE__ */ new Date()).toISOString();
|
|
11015
11114
|
if (this.provider === "postgresql" || this.provider === "pgvector") {
|
|
@@ -11059,7 +11158,7 @@ var DatabaseStorage = class {
|
|
|
11059
11158
|
}
|
|
11060
11159
|
}
|
|
11061
11160
|
async getFeedback(messageId, projectIds) {
|
|
11062
|
-
this.checkFeedbackEnabled();
|
|
11161
|
+
await this.checkFeedbackEnabled();
|
|
11063
11162
|
let item = null;
|
|
11064
11163
|
if (this.provider === "postgresql" || this.provider === "pgvector") {
|
|
11065
11164
|
const pool = await this.getPGPool();
|
|
@@ -11095,7 +11194,7 @@ var DatabaseStorage = class {
|
|
|
11095
11194
|
return item;
|
|
11096
11195
|
}
|
|
11097
11196
|
async listFeedback(projectIds) {
|
|
11098
|
-
this.checkFeedbackEnabled();
|
|
11197
|
+
await this.checkFeedbackEnabled();
|
|
11099
11198
|
let raw = [];
|
|
11100
11199
|
if (this.provider === "postgresql" || this.provider === "pgvector") {
|
|
11101
11200
|
const pool = await this.getPGPool();
|
|
@@ -11245,12 +11344,23 @@ function resolveLicenseKey(req, config, bodyLicenseKey) {
|
|
|
11245
11344
|
var _a3;
|
|
11246
11345
|
return req.headers.get("x-license-key") || bodyLicenseKey || ((_a3 = req.headers.get("authorization")) == null ? void 0 : _a3.replace(/^Bearer\s+/i, "")) || config.licenseKey || process.env.NEXT_PUBLIC_RETRIVORA_LICENSE_KEY || process.env.RETRIVORA_LICENSE_KEY || process.env.RAG_LICENSE_KEY || "";
|
|
11247
11346
|
}
|
|
11248
|
-
function enforceLicense(req, config, bodyLicenseKey) {
|
|
11347
|
+
async function enforceLicense(req, config, bodyLicenseKey) {
|
|
11249
11348
|
const rawKey = resolveLicenseKey(req, config, bodyLicenseKey);
|
|
11250
11349
|
const licenseKey = (rawKey || "").trim().replace(/^["']|["']$/g, "").trim();
|
|
11251
11350
|
const projectId = config.projectId || "";
|
|
11252
11351
|
try {
|
|
11253
|
-
|
|
11352
|
+
let payload;
|
|
11353
|
+
try {
|
|
11354
|
+
payload = await LicenseVerifier.verifyAsync(licenseKey, projectId);
|
|
11355
|
+
} catch (err) {
|
|
11356
|
+
return {
|
|
11357
|
+
ok: false,
|
|
11358
|
+
response: NextResponse.json(
|
|
11359
|
+
{ error: `License validation failed: ${err.message}` },
|
|
11360
|
+
{ status: 401 }
|
|
11361
|
+
)
|
|
11362
|
+
};
|
|
11363
|
+
}
|
|
11254
11364
|
return { ok: true, payload };
|
|
11255
11365
|
} catch (err) {
|
|
11256
11366
|
const message = err instanceof Error ? err.message : "Missing or invalid RETRIVORA_LICENSE_KEY. Set NEXT_PUBLIC_RETRIVORA_LICENSE_KEY in your environment or contact your administrator.";
|
|
@@ -11425,7 +11535,7 @@ function createChatHandler(configOrPlugin, options) {
|
|
|
11425
11535
|
try {
|
|
11426
11536
|
const body = await req.json();
|
|
11427
11537
|
const bodyObj = body != null ? body : {};
|
|
11428
|
-
const licenseCheck = enforceLicense(req, config, bodyObj == null ? void 0 : bodyObj.licenseKey);
|
|
11538
|
+
const licenseCheck = await enforceLicense(req, config, bodyObj == null ? void 0 : bodyObj.licenseKey);
|
|
11429
11539
|
if (!licenseCheck.ok) return licenseCheck.response;
|
|
11430
11540
|
if (isFreeTier(licenseCheck.payload.tier)) {
|
|
11431
11541
|
const estimatedInputTokens = Math.ceil(
|
|
@@ -11519,7 +11629,7 @@ function createStreamHandler(configOrPlugin, options) {
|
|
|
11519
11629
|
});
|
|
11520
11630
|
}
|
|
11521
11631
|
const bodyObj = body != null ? body : {};
|
|
11522
|
-
const licenseCheck = enforceLicense(req, config, bodyObj == null ? void 0 : bodyObj.licenseKey);
|
|
11632
|
+
const licenseCheck = await enforceLicense(req, config, bodyObj == null ? void 0 : bodyObj.licenseKey);
|
|
11523
11633
|
if (!licenseCheck.ok) return licenseCheck.response;
|
|
11524
11634
|
if (isFreeTier(licenseCheck.payload.tier)) {
|
|
11525
11635
|
const estimatedInputTokens = Math.ceil(
|
|
@@ -11684,7 +11794,7 @@ function createIngestHandler(configOrPlugin, options) {
|
|
|
11684
11794
|
const config = plugin.getConfig();
|
|
11685
11795
|
try {
|
|
11686
11796
|
const body = await req.json();
|
|
11687
|
-
const licenseCheck = enforceLicense(req, config, body == null ? void 0 : body.licenseKey);
|
|
11797
|
+
const licenseCheck = await enforceLicense(req, config, body == null ? void 0 : body.licenseKey);
|
|
11688
11798
|
if (!licenseCheck.ok) return licenseCheck.response;
|
|
11689
11799
|
const { documents, namespace } = body;
|
|
11690
11800
|
if (!Array.isArray(documents) || documents.length === 0) {
|
|
@@ -11760,7 +11870,7 @@ function createLicenseHandler(configOrPlugin, options) {
|
|
|
11760
11870
|
const rawKey = req.headers.get("x-license-key") || (body == null ? void 0 : body.licenseKey) || ((_a3 = req.headers.get("authorization")) == null ? void 0 : _a3.replace(/^Bearer\s+/i, "")) || config.licenseKey || process.env.NEXT_PUBLIC_RETRIVORA_LICENSE_KEY || process.env.RETRIVORA_LICENSE_KEY || "";
|
|
11761
11871
|
const licenseKey = (rawKey || "").trim().replace(/^["']|["']$/g, "").trim();
|
|
11762
11872
|
const projectId = (body == null ? void 0 : body.projectId) || config.projectId || "";
|
|
11763
|
-
const payload = LicenseVerifier.
|
|
11873
|
+
const payload = await LicenseVerifier.verifyAsync(licenseKey, projectId);
|
|
11764
11874
|
return NextResponse.json({
|
|
11765
11875
|
valid: true,
|
|
11766
11876
|
licenseStatus: "ACTIVE",
|
|
@@ -11794,7 +11904,7 @@ function createUploadHandler(configOrPlugin, options) {
|
|
|
11794
11904
|
const authResult = await checkAuth(req, onAuthorize);
|
|
11795
11905
|
if (authResult) return authResult;
|
|
11796
11906
|
const config = plugin.getConfig();
|
|
11797
|
-
const licenseCheck = enforceLicense(req, config);
|
|
11907
|
+
const licenseCheck = await enforceLicense(req, config);
|
|
11798
11908
|
if (!licenseCheck.ok) return licenseCheck.response;
|
|
11799
11909
|
try {
|
|
11800
11910
|
const formData = await req.formData();
|
|
@@ -11938,7 +12048,7 @@ function createSuggestionsHandler(configOrPlugin, options) {
|
|
|
11938
12048
|
const authResult = await checkAuth(req, onAuthorize);
|
|
11939
12049
|
if (authResult) return authResult;
|
|
11940
12050
|
const config = plugin.getConfig();
|
|
11941
|
-
const licenseCheck = enforceLicense(req, config);
|
|
12051
|
+
const licenseCheck = await enforceLicense(req, config);
|
|
11942
12052
|
if (!licenseCheck.ok) return licenseCheck.response;
|
|
11943
12053
|
let effectiveLicensePayload = licenseCheck.payload;
|
|
11944
12054
|
try {
|
|
@@ -11951,7 +12061,7 @@ function createSuggestionsHandler(configOrPlugin, options) {
|
|
|
11951
12061
|
namespace = body.namespace;
|
|
11952
12062
|
bodyLicenseKey = body.licenseKey;
|
|
11953
12063
|
if (bodyLicenseKey) {
|
|
11954
|
-
const recheck = enforceLicense(req, config, bodyLicenseKey);
|
|
12064
|
+
const recheck = await enforceLicense(req, config, bodyLicenseKey);
|
|
11955
12065
|
if (!recheck.ok) return recheck.response;
|
|
11956
12066
|
effectiveLicensePayload = recheck.payload;
|
|
11957
12067
|
}
|
|
@@ -12242,6 +12352,7 @@ var _LicenseValidator = class _LicenseValidator {
|
|
|
12242
12352
|
retrivoraApiBase,
|
|
12243
12353
|
headers: customHeaders
|
|
12244
12354
|
} = request;
|
|
12355
|
+
const effectiveProjectId = projectId || (typeof process !== "undefined" ? process.env.NEXT_PUBLIC_RETRIVORA_PROJECT_ID || process.env.RETRIVORA_PROJECT_ID : "") || "";
|
|
12245
12356
|
const getHeader = (name) => {
|
|
12246
12357
|
if (!customHeaders) return void 0;
|
|
12247
12358
|
const target = name.toLowerCase();
|
|
@@ -12279,7 +12390,7 @@ var _LicenseValidator = class _LicenseValidator {
|
|
|
12279
12390
|
}, customHeaders || {}),
|
|
12280
12391
|
body: JSON.stringify({
|
|
12281
12392
|
licenseKey: effectiveLicenseKey,
|
|
12282
|
-
projectId,
|
|
12393
|
+
projectId: effectiveProjectId,
|
|
12283
12394
|
sdkVersion,
|
|
12284
12395
|
sdk,
|
|
12285
12396
|
platform
|
|
@@ -12290,7 +12401,7 @@ var _LicenseValidator = class _LicenseValidator {
|
|
|
12290
12401
|
if (!canUseLocalValidationFallback(base)) {
|
|
12291
12402
|
throw err;
|
|
12292
12403
|
}
|
|
12293
|
-
const payload = LicenseVerifier.
|
|
12404
|
+
const payload = await LicenseVerifier.verifyAsync(effectiveLicenseKey, effectiveProjectId);
|
|
12294
12405
|
const fallbackResp = {
|
|
12295
12406
|
valid: true,
|
|
12296
12407
|
licenseStatus: "ACTIVE",
|
|
@@ -12309,7 +12420,7 @@ var _LicenseValidator = class _LicenseValidator {
|
|
|
12309
12420
|
}
|
|
12310
12421
|
if (res && !res.ok && canUseLocalValidationFallback(base, res.status)) {
|
|
12311
12422
|
try {
|
|
12312
|
-
const payload = LicenseVerifier.
|
|
12423
|
+
const payload = await LicenseVerifier.verifyAsync(effectiveLicenseKey, effectiveProjectId);
|
|
12313
12424
|
const fallbackResp = {
|
|
12314
12425
|
valid: true,
|
|
12315
12426
|
licenseStatus: "ACTIVE",
|