@retrivora-ai/rag-engine 2.3.7 → 2.3.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/handlers/index.d.mts +1 -1
- package/dist/handlers/index.d.ts +1 -1
- package/dist/handlers/index.js +290 -151
- package/dist/handlers/index.mjs +292 -153
- 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.css +0 -15
- package/dist/index.js +148 -105
- package/dist/index.mjs +148 -105
- package/dist/server.d.mts +12 -32
- package/dist/server.d.ts +12 -32
- package/dist/server.js +295 -155
- package/dist/server.mjs +297 -157
- package/package.json +1 -1
- package/src/components/ChatWidget.tsx +0 -1
- package/src/components/ConfigProvider.tsx +2 -1
- package/src/components/DocumentUpload.tsx +34 -15
- package/src/config/serverConfig.ts +15 -5
- package/src/core/ConfigFetcher.ts +42 -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 +25 -13
- package/src/index.css +0 -15
- package/src/llm/providers/UniversalLLMAdapter.ts +18 -2
- package/src/providers/vectordb/PineconeProvider.ts +69 -2
package/dist/server.js
CHANGED
|
@@ -330,7 +330,7 @@ var init_package = __esm({
|
|
|
330
330
|
"package.json"() {
|
|
331
331
|
package_default = {
|
|
332
332
|
name: "@retrivora-ai/rag-engine",
|
|
333
|
-
version: "2.3.
|
|
333
|
+
version: "2.3.9",
|
|
334
334
|
description: "Retrivora AI is a plug-and-play AI engine for RAG chat experiences \u2014 generic vector DB + LLM provider, embeddable or standalone.",
|
|
335
335
|
author: "Abhinav Alkuchi",
|
|
336
336
|
license: "UNLICENSED",
|
|
@@ -516,10 +516,16 @@ var init_ConfigFetcher = __esm({
|
|
|
516
516
|
process.env.RETRIVORA_CONTROL_PLANE_URL,
|
|
517
517
|
process.env.NEXT_PUBLIC_RETRIVORA_CONTROL_PLANE_URL,
|
|
518
518
|
CONTROL_PLANE_URL
|
|
519
|
-
].filter((url) =>
|
|
519
|
+
].filter((url) => {
|
|
520
|
+
if (!url) return false;
|
|
521
|
+
const isEnvVar = url === process.env.RETRIVORA_CONTROL_PLANE_URL || url === process.env.NEXT_PUBLIC_RETRIVORA_CONTROL_PLANE_URL;
|
|
522
|
+
if (!isEnvVar && (url.includes("localhost") || url.includes("127.0.0.1"))) return false;
|
|
523
|
+
return true;
|
|
524
|
+
}).map((url) => url.replace(/\/$/, ""));
|
|
520
525
|
for (const baseUrl of controlPlaneUrls) {
|
|
521
526
|
try {
|
|
522
527
|
const url = `${baseUrl}/api/v1/config?projectId=${encodeURIComponent(projectId)}`;
|
|
528
|
+
console.log(`[ConfigFetcher] Fetching config from: ${url}`);
|
|
523
529
|
const res = await fetch(url, {
|
|
524
530
|
method: "GET",
|
|
525
531
|
headers: __spreadValues({
|
|
@@ -527,6 +533,10 @@ var init_ConfigFetcher = __esm({
|
|
|
527
533
|
"x-sdk-version": SDK_VERSION
|
|
528
534
|
}, licenseKey ? { "x-license-key": licenseKey } : {})
|
|
529
535
|
});
|
|
536
|
+
console.log(`[ConfigFetcher] Response status: ${res.status}`);
|
|
537
|
+
if (!res.ok) {
|
|
538
|
+
console.warn(`[ConfigFetcher] Error text: ${await res.text()}`);
|
|
539
|
+
}
|
|
530
540
|
if (res.ok) {
|
|
531
541
|
const data = await res.json();
|
|
532
542
|
if ((data == null ? void 0 : data.success) && (data == null ? void 0 : data.vectorDb)) {
|
|
@@ -537,8 +547,7 @@ var init_ConfigFetcher = __esm({
|
|
|
537
547
|
isActive: data.isActive,
|
|
538
548
|
expiresAt: data.expiresAt,
|
|
539
549
|
vectorDb: {
|
|
540
|
-
// apiKey
|
|
541
|
-
// The SDK uses local PINECONE_API_KEY if available.
|
|
550
|
+
// Fetch apiKey from credentials API if available, else fallback to empty
|
|
542
551
|
apiKey: data.vectorDb.apiKey || "",
|
|
543
552
|
indexName: data.vectorDb.indexName || "retrivora-free",
|
|
544
553
|
provider: data.vectorDb.provider || "pinecone",
|
|
@@ -570,6 +579,32 @@ var init_ConfigFetcher = __esm({
|
|
|
570
579
|
data.projectSettings || data.settings
|
|
571
580
|
)
|
|
572
581
|
};
|
|
582
|
+
if (licenseKey) {
|
|
583
|
+
try {
|
|
584
|
+
const credUrl = `${baseUrl}/api/v1/credentials`;
|
|
585
|
+
const credRes = await fetch(credUrl, {
|
|
586
|
+
method: "POST",
|
|
587
|
+
headers: {
|
|
588
|
+
"Content-Type": "application/json"
|
|
589
|
+
},
|
|
590
|
+
body: JSON.stringify({ licenseKey, projectId: fetchedProjectId })
|
|
591
|
+
});
|
|
592
|
+
if (credRes.ok) {
|
|
593
|
+
const credData = await credRes.json();
|
|
594
|
+
if ((credData == null ? void 0 : credData.success) && (credData == null ? void 0 : credData.credentials)) {
|
|
595
|
+
if (credData.credentials.pineconeApiKey && !config.vectorDb.apiKey) {
|
|
596
|
+
config.vectorDb.apiKey = credData.credentials.pineconeApiKey;
|
|
597
|
+
}
|
|
598
|
+
if (credData.credentials.litellmApiKey) {
|
|
599
|
+
config.llm.apiKey = credData.credentials.litellmApiKey;
|
|
600
|
+
config.embedding.apiKey = credData.credentials.litellmApiKey;
|
|
601
|
+
}
|
|
602
|
+
}
|
|
603
|
+
}
|
|
604
|
+
} catch (e) {
|
|
605
|
+
console.warn("[ConfigFetcher] Failed to fetch credentials:", e);
|
|
606
|
+
}
|
|
607
|
+
}
|
|
573
608
|
this.cache.set(cacheKey, { config, cachedAt: now });
|
|
574
609
|
return config;
|
|
575
610
|
}
|
|
@@ -609,6 +644,14 @@ var init_PineconeProvider = __esm({
|
|
|
609
644
|
const opts = config.options || {};
|
|
610
645
|
this.apiKey = opts.apiKey || process.env.PINECONE_API_KEY || "";
|
|
611
646
|
}
|
|
647
|
+
getControlPlaneUrl() {
|
|
648
|
+
const urls = [
|
|
649
|
+
process.env.RETRIVORA_CONTROL_PLANE_URL,
|
|
650
|
+
process.env.NEXT_PUBLIC_RETRIVORA_CONTROL_PLANE_URL,
|
|
651
|
+
"https://www.retrivora.com"
|
|
652
|
+
].filter((url) => Boolean(url));
|
|
653
|
+
return urls[0].replace(/\/$/, "");
|
|
654
|
+
}
|
|
612
655
|
static getValidator() {
|
|
613
656
|
return {
|
|
614
657
|
validate(config) {
|
|
@@ -672,6 +715,7 @@ var init_PineconeProvider = __esm({
|
|
|
672
715
|
let key = this.apiKey || process.env.PINECONE_API_KEY || "";
|
|
673
716
|
if (!key) {
|
|
674
717
|
const licenseKey = process.env.RETRIVORA_LICENSE_KEY || process.env.NEXT_PUBLIC_RETRIVORA_LICENSE_KEY;
|
|
718
|
+
this.licenseKey = licenseKey;
|
|
675
719
|
const jwtProjectId = (() => {
|
|
676
720
|
if (!licenseKey) return void 0;
|
|
677
721
|
try {
|
|
@@ -685,6 +729,7 @@ var init_PineconeProvider = __esm({
|
|
|
685
729
|
return void 0;
|
|
686
730
|
})();
|
|
687
731
|
const projectId = process.env.RAG_PROJECT_ID || process.env.NEXT_PUBLIC_RAG_PROJECT_ID || jwtProjectId || this.projectId || "default";
|
|
732
|
+
this.projectId = projectId;
|
|
688
733
|
const remoteConfig = await ConfigFetcher.fetchRemoteVectorConfig(projectId, licenseKey);
|
|
689
734
|
if (remoteConfig) {
|
|
690
735
|
if (remoteConfig.apiKey) {
|
|
@@ -730,19 +775,59 @@ var init_PineconeProvider = __esm({
|
|
|
730
775
|
return namespace ? idx.namespace(namespace) : idx.namespace("");
|
|
731
776
|
}
|
|
732
777
|
async upsert(doc, namespace) {
|
|
733
|
-
var _a3;
|
|
778
|
+
var _a3, _b;
|
|
779
|
+
if (!this.client) {
|
|
780
|
+
if (!this.licenseKey) throw new Error("[PineconeProvider] Cannot execute vector operation: Missing API key and License key.");
|
|
781
|
+
const res = await fetch(`${this.getControlPlaneUrl()}/api/v1/vectors/upsert`, {
|
|
782
|
+
method: "POST",
|
|
783
|
+
headers: { "Content-Type": "application/json", "x-license-key": this.licenseKey },
|
|
784
|
+
body: JSON.stringify({
|
|
785
|
+
projectId: this.projectId,
|
|
786
|
+
indexName: this.indexName,
|
|
787
|
+
namespace: namespace || this.projectId,
|
|
788
|
+
records: [{ id: String(doc.id), values: doc.vector, metadata: __spreadValues({ content: doc.content }, (_a3 = doc.metadata) != null ? _a3 : {}) }]
|
|
789
|
+
})
|
|
790
|
+
});
|
|
791
|
+
if (!res.ok) throw new Error(`[PineconeProvider] Proxy upsert failed: ${await res.text()}`);
|
|
792
|
+
return;
|
|
793
|
+
}
|
|
734
794
|
const targetIdx = await this.getActiveIndex(namespace);
|
|
735
795
|
await targetIdx.upsert({
|
|
736
796
|
records: [{
|
|
737
797
|
id: String(doc.id),
|
|
738
798
|
values: doc.vector,
|
|
739
|
-
metadata: __spreadValues({ content: doc.content }, (
|
|
799
|
+
metadata: __spreadValues({ content: doc.content }, (_b = doc.metadata) != null ? _b : {})
|
|
740
800
|
}]
|
|
741
801
|
});
|
|
742
802
|
}
|
|
743
803
|
async batchUpsert(docs, namespace) {
|
|
744
|
-
const targetIdx = await this.getActiveIndex(namespace);
|
|
745
804
|
const BATCH = 100;
|
|
805
|
+
if (!this.client) {
|
|
806
|
+
if (!this.licenseKey) throw new Error("[PineconeProvider] Cannot execute vector operation: Missing API key and License key.");
|
|
807
|
+
for (let i = 0; i < docs.length; i += BATCH) {
|
|
808
|
+
const records = docs.slice(i, i + BATCH).map((d) => {
|
|
809
|
+
var _a3;
|
|
810
|
+
return {
|
|
811
|
+
id: String(d.id),
|
|
812
|
+
values: d.vector,
|
|
813
|
+
metadata: __spreadValues({ content: d.content }, (_a3 = d.metadata) != null ? _a3 : {})
|
|
814
|
+
};
|
|
815
|
+
});
|
|
816
|
+
const res = await fetch(`${this.getControlPlaneUrl()}/api/v1/vectors/upsert`, {
|
|
817
|
+
method: "POST",
|
|
818
|
+
headers: { "Content-Type": "application/json", "x-license-key": this.licenseKey },
|
|
819
|
+
body: JSON.stringify({
|
|
820
|
+
projectId: this.projectId,
|
|
821
|
+
indexName: this.indexName,
|
|
822
|
+
namespace: namespace || this.projectId,
|
|
823
|
+
records
|
|
824
|
+
})
|
|
825
|
+
});
|
|
826
|
+
if (!res.ok) throw new Error(`[PineconeProvider] Proxy batch upsert failed: ${await res.text()}`);
|
|
827
|
+
}
|
|
828
|
+
return;
|
|
829
|
+
}
|
|
830
|
+
const targetIdx = await this.getActiveIndex(namespace);
|
|
746
831
|
for (let i = 0; i < docs.length; i += BATCH) {
|
|
747
832
|
const records = docs.slice(i, i + BATCH).map((d) => {
|
|
748
833
|
var _a3;
|
|
@@ -756,20 +841,46 @@ var init_PineconeProvider = __esm({
|
|
|
756
841
|
}
|
|
757
842
|
}
|
|
758
843
|
async query(vector, topK, namespace, filter) {
|
|
759
|
-
var _a3;
|
|
760
|
-
const targetIdx = await this.getActiveIndex(namespace);
|
|
844
|
+
var _a3, _b;
|
|
761
845
|
const pineconeFilter = this.sanitizeFilter(filter);
|
|
846
|
+
if (!this.client) {
|
|
847
|
+
if (!this.licenseKey) throw new Error("[PineconeProvider] Cannot execute vector operation: Missing API key and License key.");
|
|
848
|
+
const res = await fetch(`${this.getControlPlaneUrl()}/api/v1/vectors/query`, {
|
|
849
|
+
method: "POST",
|
|
850
|
+
headers: { "Content-Type": "application/json", "x-license-key": this.licenseKey },
|
|
851
|
+
body: JSON.stringify({
|
|
852
|
+
projectId: this.projectId,
|
|
853
|
+
indexName: this.indexName,
|
|
854
|
+
namespace: namespace || this.projectId,
|
|
855
|
+
vector,
|
|
856
|
+
topK,
|
|
857
|
+
filter: pineconeFilter
|
|
858
|
+
})
|
|
859
|
+
});
|
|
860
|
+
if (!res.ok) throw new Error(`[PineconeProvider] Proxy query failed: ${await res.text()}`);
|
|
861
|
+
const data = await res.json();
|
|
862
|
+
return ((_a3 = data.matches) != null ? _a3 : []).map((m) => {
|
|
863
|
+
var _a4, _b2;
|
|
864
|
+
return {
|
|
865
|
+
id: m.id,
|
|
866
|
+
score: (_a4 = m.score) != null ? _a4 : 0,
|
|
867
|
+
content: ((_b2 = m.metadata) == null ? void 0 : _b2.content) || "",
|
|
868
|
+
metadata: m.metadata
|
|
869
|
+
};
|
|
870
|
+
});
|
|
871
|
+
}
|
|
872
|
+
const targetIdx = await this.getActiveIndex(namespace);
|
|
762
873
|
const result = await targetIdx.query(__spreadValues({
|
|
763
874
|
vector,
|
|
764
875
|
topK,
|
|
765
876
|
includeMetadata: true
|
|
766
877
|
}, Object.keys(pineconeFilter).length > 0 ? { filter: pineconeFilter } : {}));
|
|
767
|
-
return ((
|
|
768
|
-
var _a4,
|
|
878
|
+
return ((_b = result.matches) != null ? _b : []).map((m) => {
|
|
879
|
+
var _a4, _b2;
|
|
769
880
|
return {
|
|
770
881
|
id: m.id,
|
|
771
882
|
score: (_a4 = m.score) != null ? _a4 : 0,
|
|
772
|
-
content: ((
|
|
883
|
+
content: ((_b2 = m.metadata) == null ? void 0 : _b2.content) || "",
|
|
773
884
|
metadata: m.metadata
|
|
774
885
|
};
|
|
775
886
|
});
|
|
@@ -2661,9 +2772,6 @@ module.exports = __toCommonJS(server_exports);
|
|
|
2661
2772
|
// src/core/ConfigResolver.ts
|
|
2662
2773
|
init_templateUtils();
|
|
2663
2774
|
|
|
2664
|
-
// src/core/LicenseVerifier.ts
|
|
2665
|
-
var crypto = __toESM(require("crypto"));
|
|
2666
|
-
|
|
2667
2775
|
// src/exceptions/index.ts
|
|
2668
2776
|
var RetrivoraError = class extends Error {
|
|
2669
2777
|
constructor(message, code, details) {
|
|
@@ -2749,29 +2857,18 @@ function wrapError(err, defaultCode, defaultMessage) {
|
|
|
2749
2857
|
}
|
|
2750
2858
|
|
|
2751
2859
|
// src/core/LicenseVerifier.ts
|
|
2752
|
-
var
|
|
2860
|
+
var _LicenseVerifier = class _LicenseVerifier {
|
|
2861
|
+
// Cache verified license for 5 minutes
|
|
2753
2862
|
/**
|
|
2754
|
-
*
|
|
2863
|
+
* Validates the license key asynchronously by calling the Retrivora backend.
|
|
2755
2864
|
*
|
|
2756
2865
|
* @param licenseKey - Base64url signed JWT license key.
|
|
2757
2866
|
* @param currentProjectId - Project namespace ID.
|
|
2758
|
-
* @param
|
|
2867
|
+
* @param provider - Optional provider for tier checks.
|
|
2759
2868
|
*/
|
|
2760
|
-
static
|
|
2869
|
+
static async verifyAsync(licenseKey, currentProjectId, provider) {
|
|
2761
2870
|
const isProduction = process.env.NODE_ENV === "production";
|
|
2762
2871
|
const now = Date.now();
|
|
2763
|
-
if (licenseKey) {
|
|
2764
|
-
const cacheKey = `${licenseKey}:${currentProjectId}:${provider || ""}:${publicKeyOverride || ""}`;
|
|
2765
|
-
const cached = this.cache.get(cacheKey);
|
|
2766
|
-
if (cached && now - cached.cachedAt < this.CACHE_TTL_MS) {
|
|
2767
|
-
const currentTimestampSec = Math.floor(now / 1e3);
|
|
2768
|
-
if (cached.payload.expiresAt && currentTimestampSec > cached.payload.expiresAt) {
|
|
2769
|
-
this.cache.delete(cacheKey);
|
|
2770
|
-
} else {
|
|
2771
|
-
return cached.payload;
|
|
2772
|
-
}
|
|
2773
|
-
}
|
|
2774
|
-
}
|
|
2775
2872
|
if (!licenseKey) {
|
|
2776
2873
|
if (isProduction) {
|
|
2777
2874
|
throw new ConfigurationException(
|
|
@@ -2788,52 +2885,61 @@ var LicenseVerifier = class {
|
|
|
2788
2885
|
tier: "hobby"
|
|
2789
2886
|
};
|
|
2790
2887
|
}
|
|
2791
|
-
|
|
2792
|
-
|
|
2793
|
-
|
|
2794
|
-
const
|
|
2795
|
-
if (
|
|
2796
|
-
|
|
2797
|
-
}
|
|
2798
|
-
|
|
2799
|
-
const dataToVerify = `${headerB64}.${payloadB64}`;
|
|
2800
|
-
const publicKey = publicKeyOverride != null ? publicKeyOverride : this.PUBLIC_KEY;
|
|
2801
|
-
const signature = Buffer.from(signatureB64, "base64url");
|
|
2802
|
-
const data = Buffer.from(dataToVerify);
|
|
2803
|
-
const isValid = crypto.verify(
|
|
2804
|
-
"sha256",
|
|
2805
|
-
data,
|
|
2806
|
-
publicKey,
|
|
2807
|
-
signature
|
|
2808
|
-
);
|
|
2809
|
-
if (!isValid) {
|
|
2810
|
-
throw new Error("Signature verification failed.");
|
|
2888
|
+
const cacheKey = `${licenseKey}:${currentProjectId}:${provider || ""}`;
|
|
2889
|
+
const cached = this.cache.get(cacheKey);
|
|
2890
|
+
if (cached && now - cached.cachedAt < this.CACHE_TTL_MS) {
|
|
2891
|
+
const currentTimestampSec = Math.floor(now / 1e3);
|
|
2892
|
+
if (cached.payload.expiresAt && currentTimestampSec > cached.payload.expiresAt) {
|
|
2893
|
+
this.cache.delete(cacheKey);
|
|
2894
|
+
} else {
|
|
2895
|
+
return cached.payload;
|
|
2811
2896
|
}
|
|
2812
|
-
|
|
2813
|
-
|
|
2814
|
-
|
|
2815
|
-
if (
|
|
2816
|
-
|
|
2897
|
+
}
|
|
2898
|
+
try {
|
|
2899
|
+
let baseUrl = typeof process !== "undefined" && process.env.RETRIVORA_CONTROL_PLANE_URL ? process.env.RETRIVORA_CONTROL_PLANE_URL : "https://retrivora.com";
|
|
2900
|
+
if (typeof process !== "undefined" && process.env.TELEMETRY_URL) {
|
|
2901
|
+
baseUrl = process.env.TELEMETRY_URL.replace(/\/api\/telemetry\/?$/, "");
|
|
2817
2902
|
}
|
|
2818
|
-
const
|
|
2819
|
-
|
|
2820
|
-
|
|
2821
|
-
|
|
2822
|
-
|
|
2903
|
+
const endpoint = `${baseUrl}/api/v1/license/validate`;
|
|
2904
|
+
const response = await fetch(endpoint, {
|
|
2905
|
+
method: "POST",
|
|
2906
|
+
headers: {
|
|
2907
|
+
"Content-Type": "application/json",
|
|
2908
|
+
"x-license-key": licenseKey
|
|
2909
|
+
},
|
|
2910
|
+
body: JSON.stringify({
|
|
2911
|
+
licenseKey,
|
|
2912
|
+
projectId: currentProjectId,
|
|
2913
|
+
provider
|
|
2914
|
+
})
|
|
2915
|
+
});
|
|
2916
|
+
if (!response.ok) {
|
|
2917
|
+
let errMessage = `HTTP ${response.status}`;
|
|
2918
|
+
try {
|
|
2919
|
+
const body = await response.json();
|
|
2920
|
+
if (body.message) errMessage = body.message;
|
|
2921
|
+
} catch (e) {
|
|
2922
|
+
}
|
|
2923
|
+
throw new Error(errMessage);
|
|
2823
2924
|
}
|
|
2824
|
-
|
|
2825
|
-
|
|
2925
|
+
const data = await response.json();
|
|
2926
|
+
if (!data.valid) {
|
|
2927
|
+
throw new Error(data.message || "License validation failed by server.");
|
|
2826
2928
|
}
|
|
2827
|
-
|
|
2828
|
-
if (
|
|
2829
|
-
|
|
2830
|
-
`License key has expired. Expiration: ${new Date(
|
|
2831
|
-
payload.expiresAt * 1e3
|
|
2832
|
-
).toDateString()}`
|
|
2833
|
-
);
|
|
2929
|
+
let expiresAtNum = Math.floor(Date.now() / 1e3) + 100 * 365 * 24 * 60 * 60;
|
|
2930
|
+
if (data.expiresAt) {
|
|
2931
|
+
expiresAtNum = Math.floor(new Date(data.expiresAt).getTime() / 1e3);
|
|
2834
2932
|
}
|
|
2933
|
+
const tier = _LicenseVerifier.extractTier(licenseKey);
|
|
2934
|
+
const payload = {
|
|
2935
|
+
projectId: currentProjectId,
|
|
2936
|
+
expiresAt: expiresAtNum,
|
|
2937
|
+
tier,
|
|
2938
|
+
licenseStatus: data.licenseStatus,
|
|
2939
|
+
minimumSupportedVersion: data.minimumSupportedVersion,
|
|
2940
|
+
forceUpgrade: data.forceUpgrade
|
|
2941
|
+
};
|
|
2835
2942
|
if (isProduction && provider) {
|
|
2836
|
-
const tier = (payload.tier || "").toLowerCase();
|
|
2837
2943
|
const normalizedProvider = provider.toLowerCase();
|
|
2838
2944
|
if (tier === "hobby") {
|
|
2839
2945
|
const allowedHobby = ["postgresql", "pgvector", "supabase"];
|
|
@@ -2861,15 +2967,12 @@ var LicenseVerifier = class {
|
|
|
2861
2967
|
}
|
|
2862
2968
|
}
|
|
2863
2969
|
}
|
|
2864
|
-
|
|
2865
|
-
const cacheKey = `${licenseKey}:${currentProjectId}:${provider || ""}:${publicKeyOverride || ""}`;
|
|
2866
|
-
this.cache.set(cacheKey, { payload, cachedAt: now });
|
|
2867
|
-
}
|
|
2970
|
+
this.cache.set(cacheKey, { payload, cachedAt: now });
|
|
2868
2971
|
return payload;
|
|
2869
2972
|
} catch (err) {
|
|
2870
2973
|
const message = err instanceof Error ? err.message : String(err);
|
|
2871
2974
|
throw new ConfigurationException(
|
|
2872
|
-
`[Retrivora SDK] License key validation failed: ${message}`
|
|
2975
|
+
`[Retrivora SDK] License key validation failed via API: ${message}`
|
|
2873
2976
|
);
|
|
2874
2977
|
}
|
|
2875
2978
|
}
|
|
@@ -2938,23 +3041,25 @@ var LicenseVerifier = class {
|
|
|
2938
3041
|
}
|
|
2939
3042
|
}
|
|
2940
3043
|
}
|
|
3044
|
+
static extractTier(licenseKey) {
|
|
3045
|
+
if (!licenseKey) return "hobby";
|
|
3046
|
+
try {
|
|
3047
|
+
const sanitizedKey = licenseKey.trim().replace(/^["']|["']$/g, "").trim();
|
|
3048
|
+
const rawToken = sanitizedKey.replace(/^rtv_/i, "").trim();
|
|
3049
|
+
const parts = rawToken.split(".");
|
|
3050
|
+
if (parts.length === 3) {
|
|
3051
|
+
const decodedPayload = JSON.parse(Buffer.from(parts[1], "base64url").toString("utf8"));
|
|
3052
|
+
if (decodedPayload.tier) return decodedPayload.tier;
|
|
3053
|
+
}
|
|
3054
|
+
} catch (e) {
|
|
3055
|
+
}
|
|
3056
|
+
return "hobby";
|
|
3057
|
+
}
|
|
2941
3058
|
};
|
|
2942
|
-
//
|
|
2943
|
-
|
|
2944
|
-
|
|
2945
|
-
|
|
2946
|
-
// Retrivora's Public Key used to verify the license key signature.
|
|
2947
|
-
// In production, this matches the private key held by Retrivora SaaS.
|
|
2948
|
-
// Rotate this key only when the signing private key is replaced.
|
|
2949
|
-
LicenseVerifier.PUBLIC_KEY = `-----BEGIN PUBLIC KEY-----
|
|
2950
|
-
MIIBIjANBgkqhkiG9w0BAQEFAAOCAQ8AMIIBCgKCAQEAyKvvOSYdCimG3b236ebV
|
|
2951
|
-
jpG88xQiU8dSiaMahtBJDf4w0AewRj7hMNgmeZ1wyTOj8kVgeGBOolp1Z0QmTr6O
|
|
2952
|
-
Tj4EDQ/zjsg12If7hSf3NiwLHCYmMLslyK0aaP6PQoTrYkBv3GNdkMecrIjKCijb
|
|
2953
|
-
6VvDLLF3X696melTVM0z/d2e50BW2AlRw/rf1EqYi10d0BcPo5zje0XETr/WGmqu
|
|
2954
|
-
sDiXtsP5MlwkL9X7RQY2uovRa+l/vOAqAfdmJ+OzXuk5P7mDUPb+gCtKnoDbb1tr
|
|
2955
|
-
6UAu733dkUnetAcMqyT3fNPBLO66DCc6m9rGCYYAaG7piMEDwG0/ZySZBFbgllJc
|
|
2956
|
-
6QIDAQAB
|
|
2957
|
-
-----END PUBLIC KEY-----`;
|
|
3059
|
+
// In-memory cache to save network overhead on hot paths.
|
|
3060
|
+
_LicenseVerifier.cache = /* @__PURE__ */ new Map();
|
|
3061
|
+
_LicenseVerifier.CACHE_TTL_MS = 5 * 60 * 1e3;
|
|
3062
|
+
var LicenseVerifier = _LicenseVerifier;
|
|
2958
3063
|
|
|
2959
3064
|
// src/config/constants.ts
|
|
2960
3065
|
var VECTOR_DB_PROVIDERS = [
|
|
@@ -3042,7 +3147,7 @@ function getRagConfig(baseConfig, env = process.env) {
|
|
|
3042
3147
|
return getEnvConfig(env, baseConfig);
|
|
3043
3148
|
}
|
|
3044
3149
|
function getEnvConfig(env = process.env, base) {
|
|
3045
|
-
var _a3, _b, _c, _d, _e, _f, _g2, _h, _i, _j, _k, _l, _m, _n, _o, _p, _q, _r, _s, _t, _u, _v, _w, _x, _y, _z, _A, _B, _C, _D, _E, _F, _G, _H, _I, _J, _K, _L, _M, _N, _O, _P, _Q, _R, _S, _T, _U, _V, _W, _X, _Y, _Z, __, _$, _aa, _ba, _ca, _da, _ea, _fa, _ga, _ha, _ia, _ja, _ka, _la, _ma, _na, _oa, _pa, _qa, _ra, _sa, _ta, _ua, _va, _wa, _xa, _ya, _za, _Aa, _Ba, _Ca, _Da, _Ea, _Fa, _Ga, _Ha, _Ia, _Ja, _Ka, _La, _Ma, _Na, _Oa, _Pa, _Qa, _Ra, _Sa, _Ta, _Ua, _Va, _Wa, _Xa, _Ya, _Za, __a, _$a, _ab, _bb, _cb, _db, _eb, _fb, _gb, _hb, _ib, _jb, _kb, _lb, _mb, _nb, _ob, _pb, _qb, _rb, _sb, _tb, _ub, _vb, _wb, _xb, _yb, _zb, _Ab, _Bb, _Cb, _Db, _Eb, _Fb, _Gb, _Hb;
|
|
3150
|
+
var _a3, _b, _c, _d, _e, _f, _g2, _h, _i, _j, _k, _l, _m, _n, _o, _p, _q, _r, _s, _t, _u, _v, _w, _x, _y, _z, _A, _B, _C, _D, _E, _F, _G, _H, _I, _J, _K, _L, _M, _N, _O, _P, _Q, _R, _S, _T, _U, _V, _W, _X, _Y, _Z, __, _$, _aa, _ba, _ca, _da, _ea, _fa, _ga, _ha, _ia, _ja, _ka, _la, _ma, _na, _oa, _pa, _qa, _ra, _sa, _ta, _ua, _va, _wa, _xa, _ya, _za, _Aa, _Ba, _Ca, _Da, _Ea, _Fa, _Ga, _Ha, _Ia, _Ja, _Ka, _La, _Ma, _Na, _Oa, _Pa, _Qa, _Ra, _Sa, _Ta, _Ua, _Va, _Wa, _Xa, _Ya, _Za, __a, _$a, _ab, _bb, _cb, _db, _eb, _fb, _gb, _hb, _ib, _jb, _kb, _lb, _mb, _nb, _ob, _pb, _qb, _rb, _sb, _tb, _ub, _vb, _wb, _xb, _yb, _zb, _Ab, _Bb, _Cb, _Db, _Eb, _Fb, _Gb, _Hb, _Ib;
|
|
3046
3151
|
const licenseKey = (_d = (_c = (_b = (_a3 = readString(env, "RAG_LICENSE_KEY")) != null ? _a3 : readString(env, "RETRIVORA_LICENSE_KEY")) != null ? _b : readString(env, "NEXT_PUBLIC_RETRIVORA_LICENSE_KEY")) != null ? _c : readString(env, "LICENSE_KEY")) != null ? _d : base == null ? void 0 : base.licenseKey;
|
|
3047
3152
|
const jwtProjectId = (() => {
|
|
3048
3153
|
if (!licenseKey) return void 0;
|
|
@@ -3127,8 +3232,7 @@ function getEnvConfig(env = process.env, base) {
|
|
|
3127
3232
|
const isFreeTier2 = (() => {
|
|
3128
3233
|
if (!licenseKey) return true;
|
|
3129
3234
|
try {
|
|
3130
|
-
const
|
|
3131
|
-
const tier = (payload.tier || "").toLowerCase();
|
|
3235
|
+
const tier = LicenseVerifier.extractTier(licenseKey).toLowerCase();
|
|
3132
3236
|
return tier === "free_trial" || tier === "free_tier" || tier === "free" || tier === "hobby";
|
|
3133
3237
|
} catch (e) {
|
|
3134
3238
|
return true;
|
|
@@ -3136,14 +3240,15 @@ function getEnvConfig(env = process.env, base) {
|
|
|
3136
3240
|
})();
|
|
3137
3241
|
const tierBasedLLMModel = isFreeTier2 ? "llama-3.1-8b-instant" : "llama-3.3-70b-versatile";
|
|
3138
3242
|
const tierBasedEmbeddingModel = isFreeTier2 ? "text-embedding-004" : "text-embedding-004";
|
|
3139
|
-
const
|
|
3243
|
+
const controlPlaneUrl = (_qa = readString(env, "RETRIVORA_CONTROL_PLANE_URL")) != null ? _qa : readString(env, "NEXT_PUBLIC_RETRIVORA_CONTROL_PLANE_URL");
|
|
3244
|
+
const defaultGatewayUrl = controlPlaneUrl ? `${controlPlaneUrl.replace(/\/$/, "")}/api/v1` : "https://llm.retrivora.com/api/v1";
|
|
3140
3245
|
const rt = _runtimeConfig;
|
|
3141
3246
|
const defaultLlmProvider = "universal_rest";
|
|
3142
|
-
const llmProvider = (
|
|
3143
|
-
const llmBaseUrl = (
|
|
3144
|
-
const llmModel = (
|
|
3145
|
-
const llmApiKey = (
|
|
3146
|
-
const llmProfile = (
|
|
3247
|
+
const llmProvider = (_ta = (_sa = readEnum(env, "LLM_PROVIDER", defaultLlmProvider, LLM_PROVIDERS)) != null ? _sa : (_ra = base == null ? void 0 : base.llm) == null ? void 0 : _ra.provider) != null ? _ta : defaultLlmProvider;
|
|
3248
|
+
const llmBaseUrl = (_ya = (_xa = (_wa = (_ua = readString(env, "LITELLM_BASE_URL")) != null ? _ua : readString(env, "LLM_BASE_URL")) != null ? _wa : (_va = base == null ? void 0 : base.llm) == null ? void 0 : _va.baseUrl) != null ? _xa : rt == null ? void 0 : rt.llmBaseUrl) != null ? _ya : defaultGatewayUrl;
|
|
3249
|
+
const llmModel = (_Ca = (_Ba = (_Aa = readString(env, "LLM_MODEL")) != null ? _Aa : (_za = base == null ? void 0 : base.llm) == null ? void 0 : _za.model) != null ? _Ba : rt == null ? void 0 : rt.llmModel) != null ? _Ca : tierBasedLLMModel;
|
|
3250
|
+
const llmApiKey = (_Ga = (_Fa = (_Da = readString(env, "LITELLM_MASTER_KEY")) != null ? _Da : rt == null ? void 0 : rt.litellmApiKey) != null ? _Fa : (_Ea = base == null ? void 0 : base.llm) == null ? void 0 : _Ea.apiKey) != null ? _Ga : licenseKey;
|
|
3251
|
+
const llmProfile = (_Ka = (_Ja = readString(env, "LLM_UNIVERSAL_PROFILE")) != null ? _Ja : (_Ia = (_Ha = base == null ? void 0 : base.llm) == null ? void 0 : _Ha.options) == null ? void 0 : _Ia.profile) != null ? _Ka : "litellm";
|
|
3147
3252
|
console.log("[serverConfig] \u{1F527} LLM Configuration:", {
|
|
3148
3253
|
baseUrl: llmBaseUrl,
|
|
3149
3254
|
model: llmModel,
|
|
@@ -3152,17 +3257,24 @@ function getEnvConfig(env = process.env, base) {
|
|
|
3152
3257
|
source: (rt == null ? void 0 : rt.llmModel) ? "runtime-injected" : "env/fallback"
|
|
3153
3258
|
});
|
|
3154
3259
|
const defaultEmbeddingProvider = "universal_rest";
|
|
3155
|
-
const embeddingProvider = (
|
|
3156
|
-
const embeddingBaseUrl = (_Ta = (_Sa = (_Ra = (
|
|
3157
|
-
const embeddingModel = (
|
|
3158
|
-
const embeddingApiKey = (
|
|
3159
|
-
const embeddingProfile = (
|
|
3260
|
+
const embeddingProvider = (_Na = (_Ma = readEnum(env, "EMBEDDING_PROVIDER", defaultEmbeddingProvider, EMBEDDING_PROVIDERS)) != null ? _Ma : (_La = base == null ? void 0 : base.embedding) == null ? void 0 : _La.provider) != null ? _Na : defaultEmbeddingProvider;
|
|
3261
|
+
const embeddingBaseUrl = (_Ua = (_Ta = (_Sa = (_Ra = (_Pa = (_Oa = readString(env, "LITELLM_BASE_URL")) != null ? _Oa : readString(env, "EMBEDDING_BASE_URL")) != null ? _Pa : readString(env, "LLM_BASE_URL")) != null ? _Ra : (_Qa = base == null ? void 0 : base.embedding) == null ? void 0 : _Qa.baseUrl) != null ? _Sa : rt == null ? void 0 : rt.embeddingBaseUrl) != null ? _Ta : rt == null ? void 0 : rt.llmBaseUrl) != null ? _Ua : defaultGatewayUrl;
|
|
3262
|
+
const embeddingModel = (_Ya = (_Xa = (_Wa = readString(env, "EMBEDDING_MODEL")) != null ? _Wa : (_Va = base == null ? void 0 : base.embedding) == null ? void 0 : _Va.model) != null ? _Xa : rt == null ? void 0 : rt.embeddingModel) != null ? _Ya : tierBasedEmbeddingModel;
|
|
3263
|
+
const embeddingApiKey = (_ab = (_$a = (_Za = readString(env, "LITELLM_MASTER_KEY")) != null ? _Za : rt == null ? void 0 : rt.litellmApiKey) != null ? _$a : (__a = base == null ? void 0 : base.embedding) == null ? void 0 : __a.apiKey) != null ? _ab : licenseKey;
|
|
3264
|
+
const embeddingProfile = (_eb = (_db = readString(env, "EMBEDDING_UNIVERSAL_PROFILE")) != null ? _db : (_cb = (_bb = base == null ? void 0 : base.embedding) == null ? void 0 : _bb.options) == null ? void 0 : _cb.profile) != null ? _eb : "litellm";
|
|
3265
|
+
console.log("[serverConfig] \u{1F527} Embedding Configuration:", {
|
|
3266
|
+
baseUrl: embeddingBaseUrl,
|
|
3267
|
+
model: embeddingModel,
|
|
3268
|
+
provider: embeddingProvider,
|
|
3269
|
+
hasApiKey: !!embeddingApiKey,
|
|
3270
|
+
source: (rt == null ? void 0 : rt.embeddingModel) ? "runtime-injected" : "env/fallback"
|
|
3271
|
+
});
|
|
3160
3272
|
return __spreadProps(__spreadValues({
|
|
3161
3273
|
projectId,
|
|
3162
3274
|
licenseKey,
|
|
3163
3275
|
vectorDb: {
|
|
3164
3276
|
provider: vectorProvider,
|
|
3165
|
-
indexName: (
|
|
3277
|
+
indexName: (_gb = (_fb = readString(env, "VECTOR_DB_INDEX")) != null ? _fb : vectorDbOptions.indexName) != null ? _gb : "rag-index",
|
|
3166
3278
|
options: vectorDbOptions
|
|
3167
3279
|
},
|
|
3168
3280
|
llm: {
|
|
@@ -3192,30 +3304,30 @@ function getEnvConfig(env = process.env, base) {
|
|
|
3192
3304
|
}
|
|
3193
3305
|
},
|
|
3194
3306
|
ui: {
|
|
3195
|
-
title: (
|
|
3196
|
-
subtitle: (
|
|
3197
|
-
primaryColor: (
|
|
3198
|
-
accentColor: (
|
|
3199
|
-
logoUrl: (
|
|
3200
|
-
placeholder: (
|
|
3201
|
-
showSources: ((
|
|
3202
|
-
welcomeMessage: (
|
|
3203
|
-
visualStyle: (
|
|
3204
|
-
borderRadius: (
|
|
3205
|
-
allowUpload: ((
|
|
3307
|
+
title: (_ib = (_hb = readString(env, "NEXT_PUBLIC_UI_TITLE")) != null ? _hb : readString(env, "UI_TITLE")) != null ? _ib : "AI Assistant",
|
|
3308
|
+
subtitle: (_kb = (_jb = readString(env, "NEXT_PUBLIC_UI_SUBTITLE")) != null ? _jb : readString(env, "UI_SUBTITLE")) != null ? _kb : "Powered by RAG",
|
|
3309
|
+
primaryColor: (_mb = (_lb = readString(env, "NEXT_PUBLIC_PRIMARY_COLOR")) != null ? _lb : readString(env, "UI_PRIMARY_COLOR")) != null ? _mb : "#10b981",
|
|
3310
|
+
accentColor: (_ob = (_nb = readString(env, "NEXT_PUBLIC_ACCENT_COLOR")) != null ? _nb : readString(env, "UI_ACCENT_COLOR")) != null ? _ob : "#3b82f6",
|
|
3311
|
+
logoUrl: (_pb = readString(env, "NEXT_PUBLIC_LOGO_URL")) != null ? _pb : readString(env, "UI_LOGO_URL"),
|
|
3312
|
+
placeholder: (_rb = (_qb = readString(env, "NEXT_PUBLIC_PLACEHOLDER")) != null ? _qb : readString(env, "UI_PLACEHOLDER")) != null ? _rb : "Ask me anything\u2026",
|
|
3313
|
+
showSources: ((_tb = (_sb = readString(env, "NEXT_PUBLIC_SHOW_SOURCES")) != null ? _sb : readString(env, "UI_SHOW_SOURCES")) != null ? _tb : "true") !== "false",
|
|
3314
|
+
welcomeMessage: (_vb = (_ub = readString(env, "NEXT_PUBLIC_WELCOME_MESSAGE")) != null ? _ub : readString(env, "UI_WELCOME_MESSAGE")) != null ? _vb : "Hello! I'm your AI assistant. Ask me anything about your documents.",
|
|
3315
|
+
visualStyle: (_xb = (_wb = readString(env, "NEXT_PUBLIC_UI_VISUAL_STYLE")) != null ? _wb : readString(env, "UI_VISUAL_STYLE")) != null ? _xb : "glass",
|
|
3316
|
+
borderRadius: (_zb = (_yb = readString(env, "NEXT_PUBLIC_UI_BORDER_RADIUS")) != null ? _yb : readString(env, "UI_BORDER_RADIUS")) != null ? _zb : "xl",
|
|
3317
|
+
allowUpload: ((_Bb = (_Ab = readString(env, "NEXT_PUBLIC_ALLOW_UPLOAD")) != null ? _Ab : readString(env, "UI_ALLOW_UPLOAD")) != null ? _Bb : "false") === "true"
|
|
3206
3318
|
},
|
|
3207
3319
|
rag: {
|
|
3208
3320
|
topK: readNumber(env, "RAG_TOP_K", 5),
|
|
3209
3321
|
scoreThreshold: readNumber(env, "RAG_SCORE_THRESHOLD", 0),
|
|
3210
3322
|
chunkSize: readNumber(env, "RAG_CHUNK_SIZE", 1e3),
|
|
3211
3323
|
chunkOverlap: readNumber(env, "RAG_CHUNK_OVERLAP", 200),
|
|
3212
|
-
filterableFields: (
|
|
3324
|
+
filterableFields: (_Cb = readString(env, "RAG_FILTERABLE_FIELDS")) == null ? void 0 : _Cb.split(",").map((f) => f.trim()),
|
|
3213
3325
|
// Query pipeline toggles — read from .env.local
|
|
3214
3326
|
useQueryTransformation: readString(env, "RAG_USE_QUERY_TRANSFORMATION") === "true",
|
|
3215
3327
|
useReranking: readString(env, "RAG_USE_RERANKING") === "true",
|
|
3216
3328
|
useGraphRetrieval: readString(env, "RAG_USE_GRAPH_RETRIEVAL") === "true",
|
|
3217
|
-
architecture: (
|
|
3218
|
-
chunkingStrategy: (
|
|
3329
|
+
architecture: (_Db = readString(env, "RAG_ARCHITECTURE")) != null ? _Db : "simple",
|
|
3330
|
+
chunkingStrategy: (_Eb = readString(env, "RAG_CHUNKING_STRATEGY")) != null ? _Eb : "recursive",
|
|
3219
3331
|
uiMapping: (() => {
|
|
3220
3332
|
const raw = readString(env, "RAG_UI_MAPPING");
|
|
3221
3333
|
if (!raw) return void 0;
|
|
@@ -3228,7 +3340,7 @@ function getEnvConfig(env = process.env, base) {
|
|
|
3228
3340
|
},
|
|
3229
3341
|
telemetry: {
|
|
3230
3342
|
enabled: telemetryEnabled,
|
|
3231
|
-
url: (
|
|
3343
|
+
url: (_Ib = (_Hb = (_Fb = readString(env, "TELEMETRY_URL")) != null ? _Fb : readString(env, "NEXT_PUBLIC_TELEMETRY_URL")) != null ? _Hb : (_Gb = base == null ? void 0 : base.telemetry) == null ? void 0 : _Gb.url) != null ? _Ib : "https://www.retrivora.com/api/telemetry"
|
|
3232
3344
|
}
|
|
3233
3345
|
}, readString(env, "GRAPH_DB_PROVIDER") ? {
|
|
3234
3346
|
graphDb: {
|
|
@@ -4578,6 +4690,12 @@ var UniversalLLMAdapter = class {
|
|
|
4578
4690
|
this.resolvedHeaders = __spreadValues(__spreadValues({
|
|
4579
4691
|
"Content-Type": "application/json"
|
|
4580
4692
|
}, config.apiKey ? { Authorization: `Bearer ${config.apiKey}` } : {}), this.opts.headers || {});
|
|
4693
|
+
console.log("[UniversalLLMAdapter] Initialized with:", {
|
|
4694
|
+
model: this.model,
|
|
4695
|
+
baseUrl: this.baseUrl,
|
|
4696
|
+
hasApiKey: !!this.apiKey,
|
|
4697
|
+
apiKeyPrefix: this.apiKey ? `${this.apiKey.slice(0, 12)}...` : void 0
|
|
4698
|
+
});
|
|
4581
4699
|
this.http = import_axios2.default.create({
|
|
4582
4700
|
baseURL: this.baseUrl,
|
|
4583
4701
|
headers: this.resolvedHeaders,
|
|
@@ -4790,14 +4908,21 @@ ${context != null ? context : "None"}` },
|
|
|
4790
4908
|
});
|
|
4791
4909
|
}
|
|
4792
4910
|
async embed(text) {
|
|
4793
|
-
var _a3, _b, _c, _d, _e, _f, _g2;
|
|
4911
|
+
var _a3, _b, _c, _d, _e, _f, _g2, _h;
|
|
4794
4912
|
const path2 = (_a3 = this.opts.embedPath) != null ? _a3 : "/embeddings";
|
|
4795
4913
|
const payload = this.opts.embedPayloadTemplate ? buildPayload(this.opts.embedPayloadTemplate, { input: text, model: this.model }) : { input: text, model: this.model };
|
|
4796
4914
|
try {
|
|
4915
|
+
console.log(`[UniversalLLMAdapter] Posting to embedding endpoint: ${this.baseUrl}${path2}`, {
|
|
4916
|
+
model: this.model,
|
|
4917
|
+
inputLength: typeof text === "string" ? text.length : "unknown"
|
|
4918
|
+
});
|
|
4797
4919
|
const { data } = await this.http.post(path2, payload);
|
|
4798
4920
|
const extractPath = (_b = this.opts.embedExtractPath) != null ? _b : "data[0].embedding";
|
|
4799
4921
|
const vector = resolvePath(data, extractPath);
|
|
4800
|
-
if (Array.isArray(vector))
|
|
4922
|
+
if (Array.isArray(vector)) {
|
|
4923
|
+
console.log(`[UniversalLLMAdapter] Embedding HTTP request successful. Vector size: ${vector.length}`);
|
|
4924
|
+
return vector;
|
|
4925
|
+
}
|
|
4801
4926
|
console.warn(
|
|
4802
4927
|
`[UniversalLLMAdapter] Embedding API returned unexpected format for path '${extractPath}'. Response:`,
|
|
4803
4928
|
data
|
|
@@ -4805,14 +4930,14 @@ ${context != null ? context : "None"}` },
|
|
|
4805
4930
|
} catch (err) {
|
|
4806
4931
|
console.warn(
|
|
4807
4932
|
`[UniversalLLMAdapter] HTTP embedding request failed: ${(err == null ? void 0 : err.message) || err}`,
|
|
4808
|
-
{ path: path2, model: this.model }
|
|
4933
|
+
{ path: path2, model: this.model, response: (_c = err == null ? void 0 : err.response) == null ? void 0 : _c.data }
|
|
4809
4934
|
);
|
|
4810
4935
|
const _g3 = globalThis;
|
|
4811
4936
|
const dispatchEmbed = _g3.__retrivoraDispatchEmbedding;
|
|
4812
4937
|
if (typeof dispatchEmbed === "function") {
|
|
4813
4938
|
try {
|
|
4814
4939
|
const res = await dispatchEmbed({ input: text, model: this.model }, this.apiKey);
|
|
4815
|
-
if ((
|
|
4940
|
+
if ((_e = (_d = res == null ? void 0 : res.data) == null ? void 0 : _d[0]) == null ? void 0 : _e.embedding) {
|
|
4816
4941
|
return res.data[0].embedding;
|
|
4817
4942
|
}
|
|
4818
4943
|
} catch (dispatchErr) {
|
|
@@ -4821,10 +4946,12 @@ ${context != null ? context : "None"}` },
|
|
|
4821
4946
|
}
|
|
4822
4947
|
}
|
|
4823
4948
|
try {
|
|
4949
|
+
console.log(`[UniversalLLMAdapter] Retrying embedding request to: ${this.baseUrl}${path2}`);
|
|
4824
4950
|
const { data } = await this.http.post(path2, payload);
|
|
4825
|
-
const extractPath = (
|
|
4951
|
+
const extractPath = (_f = this.opts.embedExtractPath) != null ? _f : "data[0].embedding";
|
|
4826
4952
|
const vector = resolvePath(data, extractPath);
|
|
4827
4953
|
if (Array.isArray(vector)) {
|
|
4954
|
+
console.log(`[UniversalLLMAdapter] Retry embedding HTTP request successful. Vector size: ${vector.length}`);
|
|
4828
4955
|
return vector;
|
|
4829
4956
|
}
|
|
4830
4957
|
console.error(
|
|
@@ -4837,7 +4964,7 @@ ${context != null ? context : "None"}` },
|
|
|
4837
4964
|
} catch (err) {
|
|
4838
4965
|
console.error(
|
|
4839
4966
|
`[UniversalLLMAdapter] Both embedding attempts failed. Path: ${path2}, Model: ${this.model}`,
|
|
4840
|
-
{ error: err == null ? void 0 : err.message, statusCode: (
|
|
4967
|
+
{ error: err == null ? void 0 : err.message, statusCode: (_g2 = err == null ? void 0 : err.response) == null ? void 0 : _g2.status, response: (_h = err == null ? void 0 : err.response) == null ? void 0 : _h.data }
|
|
4841
4968
|
);
|
|
4842
4969
|
throw new Error(
|
|
4843
4970
|
`[UniversalLLMAdapter] Failed to generate embedding after 2 attempts: ${(err == null ? void 0 : err.message) || err}`
|
|
@@ -9973,7 +10100,7 @@ var Retrivora = class {
|
|
|
9973
10100
|
var _a3;
|
|
9974
10101
|
try {
|
|
9975
10102
|
await ConfigValidator.validateAndThrow(this.config);
|
|
9976
|
-
LicenseVerifier.
|
|
10103
|
+
await LicenseVerifier.verifyAsync(
|
|
9977
10104
|
this.config.licenseKey,
|
|
9978
10105
|
this.config.projectId,
|
|
9979
10106
|
(_a3 = this.config.vectorDb) == null ? void 0 : _a3.provider
|
|
@@ -10339,7 +10466,7 @@ var VectorPlugin = class {
|
|
|
10339
10466
|
this.validationPromise = (async () => {
|
|
10340
10467
|
var _a3;
|
|
10341
10468
|
await ConfigValidator.validateAndThrow(resolvedConfig);
|
|
10342
|
-
LicenseVerifier.
|
|
10469
|
+
await LicenseVerifier.verifyAsync(
|
|
10343
10470
|
resolvedConfig.licenseKey,
|
|
10344
10471
|
resolvedConfig.projectId,
|
|
10345
10472
|
(_a3 = resolvedConfig.vectorDb) == null ? void 0 : _a3.provider
|
|
@@ -10833,7 +10960,7 @@ var DatabaseStorage = class {
|
|
|
10833
10960
|
* In non-production (development / test) environments this is a complete no-op —
|
|
10834
10961
|
* all History and Feedback features are freely accessible for local development.
|
|
10835
10962
|
*/
|
|
10836
|
-
checkPremiumSubscription() {
|
|
10963
|
+
async checkPremiumSubscription() {
|
|
10837
10964
|
if (process.env.NODE_ENV !== "production") {
|
|
10838
10965
|
return;
|
|
10839
10966
|
}
|
|
@@ -10843,7 +10970,7 @@ var DatabaseStorage = class {
|
|
|
10843
10970
|
);
|
|
10844
10971
|
}
|
|
10845
10972
|
try {
|
|
10846
|
-
const payload = LicenseVerifier.
|
|
10973
|
+
const payload = await LicenseVerifier.verifyAsync(this.config.licenseKey, this.config.projectId);
|
|
10847
10974
|
const tier = (payload.tier || "").toLowerCase();
|
|
10848
10975
|
if (tier !== "premium" && tier !== "enterprise" && tier !== "growth" && tier !== "pro" && tier !== "developer_pro" && tier !== "free_trial" && tier !== "free_tier" && tier !== "free" && tier !== "hobby") {
|
|
10849
10976
|
throw new Error(
|
|
@@ -10856,16 +10983,16 @@ var DatabaseStorage = class {
|
|
|
10856
10983
|
);
|
|
10857
10984
|
}
|
|
10858
10985
|
}
|
|
10859
|
-
checkHistoryEnabled() {
|
|
10986
|
+
async checkHistoryEnabled() {
|
|
10860
10987
|
var _a3, _b;
|
|
10861
|
-
this.checkPremiumSubscription();
|
|
10988
|
+
await this.checkPremiumSubscription();
|
|
10862
10989
|
if (((_b = (_a3 = this.config.rag) == null ? void 0 : _a3.history) == null ? void 0 : _b.enabled) === false) {
|
|
10863
10990
|
throw new Error("[Retrivora SDK] Chat History is disabled in RagConfig.");
|
|
10864
10991
|
}
|
|
10865
10992
|
}
|
|
10866
|
-
checkFeedbackEnabled() {
|
|
10993
|
+
async checkFeedbackEnabled() {
|
|
10867
10994
|
var _a3, _b;
|
|
10868
|
-
this.checkPremiumSubscription();
|
|
10995
|
+
await this.checkPremiumSubscription();
|
|
10869
10996
|
if (((_b = (_a3 = this.config.rag) == null ? void 0 : _a3.feedback) == null ? void 0 : _b.enabled) === false) {
|
|
10870
10997
|
throw new Error("[Retrivora SDK] User Feedback is disabled in RagConfig.");
|
|
10871
10998
|
}
|
|
@@ -10971,7 +11098,7 @@ var DatabaseStorage = class {
|
|
|
10971
11098
|
}
|
|
10972
11099
|
// ─── Message History Operations ──────────────────────────────────────────
|
|
10973
11100
|
async saveMessage(sessionId, message) {
|
|
10974
|
-
this.checkHistoryEnabled();
|
|
11101
|
+
await this.checkHistoryEnabled();
|
|
10975
11102
|
const createdAt = (/* @__PURE__ */ new Date()).toISOString();
|
|
10976
11103
|
const msgId = message.id || `msg_${Date.now()}_${Math.random().toString(36).slice(2, 6)}`;
|
|
10977
11104
|
if (this.provider === "postgresql" || this.provider === "pgvector") {
|
|
@@ -11034,7 +11161,7 @@ var DatabaseStorage = class {
|
|
|
11034
11161
|
}
|
|
11035
11162
|
}
|
|
11036
11163
|
async getHistory(sessionId, projectIds) {
|
|
11037
|
-
this.checkHistoryEnabled();
|
|
11164
|
+
await this.checkHistoryEnabled();
|
|
11038
11165
|
if (projectIds && projectIds.length > 0 && !this.sessionInScope(sessionId, projectIds)) {
|
|
11039
11166
|
return [];
|
|
11040
11167
|
}
|
|
@@ -11068,7 +11195,7 @@ var DatabaseStorage = class {
|
|
|
11068
11195
|
}
|
|
11069
11196
|
}
|
|
11070
11197
|
async clearHistory(sessionId, projectIds) {
|
|
11071
|
-
this.checkHistoryEnabled();
|
|
11198
|
+
await this.checkHistoryEnabled();
|
|
11072
11199
|
if (projectIds && projectIds.length > 0 && !this.sessionInScope(sessionId, projectIds)) {
|
|
11073
11200
|
return;
|
|
11074
11201
|
}
|
|
@@ -11104,7 +11231,7 @@ var DatabaseStorage = class {
|
|
|
11104
11231
|
);
|
|
11105
11232
|
}
|
|
11106
11233
|
async listSessions(projectIds) {
|
|
11107
|
-
this.checkHistoryEnabled();
|
|
11234
|
+
await this.checkHistoryEnabled();
|
|
11108
11235
|
let raw = [];
|
|
11109
11236
|
if (this.provider === "postgresql" || this.provider === "pgvector") {
|
|
11110
11237
|
const pool = await this.getPGPool();
|
|
@@ -11123,7 +11250,7 @@ var DatabaseStorage = class {
|
|
|
11123
11250
|
}
|
|
11124
11251
|
// ─── Feedback Operations ──────────────────────────────────────────────────
|
|
11125
11252
|
async saveFeedback(feedback) {
|
|
11126
|
-
this.checkFeedbackEnabled();
|
|
11253
|
+
await this.checkFeedbackEnabled();
|
|
11127
11254
|
const id = `fb_${Date.now()}_${Math.random().toString(36).slice(2, 6)}`;
|
|
11128
11255
|
const createdAt = (/* @__PURE__ */ new Date()).toISOString();
|
|
11129
11256
|
if (this.provider === "postgresql" || this.provider === "pgvector") {
|
|
@@ -11173,7 +11300,7 @@ var DatabaseStorage = class {
|
|
|
11173
11300
|
}
|
|
11174
11301
|
}
|
|
11175
11302
|
async getFeedback(messageId, projectIds) {
|
|
11176
|
-
this.checkFeedbackEnabled();
|
|
11303
|
+
await this.checkFeedbackEnabled();
|
|
11177
11304
|
let item = null;
|
|
11178
11305
|
if (this.provider === "postgresql" || this.provider === "pgvector") {
|
|
11179
11306
|
const pool = await this.getPGPool();
|
|
@@ -11209,7 +11336,7 @@ var DatabaseStorage = class {
|
|
|
11209
11336
|
return item;
|
|
11210
11337
|
}
|
|
11211
11338
|
async listFeedback(projectIds) {
|
|
11212
|
-
this.checkFeedbackEnabled();
|
|
11339
|
+
await this.checkFeedbackEnabled();
|
|
11213
11340
|
let raw = [];
|
|
11214
11341
|
if (this.provider === "postgresql" || this.provider === "pgvector") {
|
|
11215
11342
|
const pool = await this.getPGPool();
|
|
@@ -11359,12 +11486,23 @@ function resolveLicenseKey(req, config, bodyLicenseKey) {
|
|
|
11359
11486
|
var _a3;
|
|
11360
11487
|
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 || "";
|
|
11361
11488
|
}
|
|
11362
|
-
function enforceLicense(req, config, bodyLicenseKey) {
|
|
11489
|
+
async function enforceLicense(req, config, bodyLicenseKey) {
|
|
11363
11490
|
const rawKey = resolveLicenseKey(req, config, bodyLicenseKey);
|
|
11364
11491
|
const licenseKey = (rawKey || "").trim().replace(/^["']|["']$/g, "").trim();
|
|
11365
11492
|
const projectId = config.projectId || "";
|
|
11366
11493
|
try {
|
|
11367
|
-
|
|
11494
|
+
let payload;
|
|
11495
|
+
try {
|
|
11496
|
+
payload = await LicenseVerifier.verifyAsync(licenseKey, projectId);
|
|
11497
|
+
} catch (err) {
|
|
11498
|
+
return {
|
|
11499
|
+
ok: false,
|
|
11500
|
+
response: import_server.NextResponse.json(
|
|
11501
|
+
{ error: `License validation failed: ${err.message}` },
|
|
11502
|
+
{ status: 401 }
|
|
11503
|
+
)
|
|
11504
|
+
};
|
|
11505
|
+
}
|
|
11368
11506
|
return { ok: true, payload };
|
|
11369
11507
|
} catch (err) {
|
|
11370
11508
|
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.";
|
|
@@ -11539,7 +11677,7 @@ function createChatHandler(configOrPlugin, options) {
|
|
|
11539
11677
|
try {
|
|
11540
11678
|
const body = await req.json();
|
|
11541
11679
|
const bodyObj = body != null ? body : {};
|
|
11542
|
-
const licenseCheck = enforceLicense(req, config, bodyObj == null ? void 0 : bodyObj.licenseKey);
|
|
11680
|
+
const licenseCheck = await enforceLicense(req, config, bodyObj == null ? void 0 : bodyObj.licenseKey);
|
|
11543
11681
|
if (!licenseCheck.ok) return licenseCheck.response;
|
|
11544
11682
|
if (isFreeTier(licenseCheck.payload.tier)) {
|
|
11545
11683
|
const estimatedInputTokens = Math.ceil(
|
|
@@ -11633,7 +11771,7 @@ function createStreamHandler(configOrPlugin, options) {
|
|
|
11633
11771
|
});
|
|
11634
11772
|
}
|
|
11635
11773
|
const bodyObj = body != null ? body : {};
|
|
11636
|
-
const licenseCheck = enforceLicense(req, config, bodyObj == null ? void 0 : bodyObj.licenseKey);
|
|
11774
|
+
const licenseCheck = await enforceLicense(req, config, bodyObj == null ? void 0 : bodyObj.licenseKey);
|
|
11637
11775
|
if (!licenseCheck.ok) return licenseCheck.response;
|
|
11638
11776
|
if (isFreeTier(licenseCheck.payload.tier)) {
|
|
11639
11777
|
const estimatedInputTokens = Math.ceil(
|
|
@@ -11798,7 +11936,7 @@ function createIngestHandler(configOrPlugin, options) {
|
|
|
11798
11936
|
const config = plugin.getConfig();
|
|
11799
11937
|
try {
|
|
11800
11938
|
const body = await req.json();
|
|
11801
|
-
const licenseCheck = enforceLicense(req, config, body == null ? void 0 : body.licenseKey);
|
|
11939
|
+
const licenseCheck = await enforceLicense(req, config, body == null ? void 0 : body.licenseKey);
|
|
11802
11940
|
if (!licenseCheck.ok) return licenseCheck.response;
|
|
11803
11941
|
const { documents, namespace } = body;
|
|
11804
11942
|
if (!Array.isArray(documents) || documents.length === 0) {
|
|
@@ -11874,7 +12012,8 @@ function createLicenseHandler(configOrPlugin, options) {
|
|
|
11874
12012
|
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 || "";
|
|
11875
12013
|
const licenseKey = (rawKey || "").trim().replace(/^["']|["']$/g, "").trim();
|
|
11876
12014
|
const projectId = (body == null ? void 0 : body.projectId) || config.projectId || "";
|
|
11877
|
-
|
|
12015
|
+
console.log(`[DEBUG] createLicenseHandler: projectId="${projectId}", body.projectId="${body == null ? void 0 : body.projectId}", config.projectId="${config.projectId}"`);
|
|
12016
|
+
const payload = await LicenseVerifier.verifyAsync(licenseKey, projectId);
|
|
11878
12017
|
return import_server.NextResponse.json({
|
|
11879
12018
|
valid: true,
|
|
11880
12019
|
licenseStatus: "ACTIVE",
|
|
@@ -11908,7 +12047,7 @@ function createUploadHandler(configOrPlugin, options) {
|
|
|
11908
12047
|
const authResult = await checkAuth(req, onAuthorize);
|
|
11909
12048
|
if (authResult) return authResult;
|
|
11910
12049
|
const config = plugin.getConfig();
|
|
11911
|
-
const licenseCheck = enforceLicense(req, config);
|
|
12050
|
+
const licenseCheck = await enforceLicense(req, config);
|
|
11912
12051
|
if (!licenseCheck.ok) return licenseCheck.response;
|
|
11913
12052
|
try {
|
|
11914
12053
|
const formData = await req.formData();
|
|
@@ -12052,7 +12191,7 @@ function createSuggestionsHandler(configOrPlugin, options) {
|
|
|
12052
12191
|
const authResult = await checkAuth(req, onAuthorize);
|
|
12053
12192
|
if (authResult) return authResult;
|
|
12054
12193
|
const config = plugin.getConfig();
|
|
12055
|
-
const licenseCheck = enforceLicense(req, config);
|
|
12194
|
+
const licenseCheck = await enforceLicense(req, config);
|
|
12056
12195
|
if (!licenseCheck.ok) return licenseCheck.response;
|
|
12057
12196
|
let effectiveLicensePayload = licenseCheck.payload;
|
|
12058
12197
|
try {
|
|
@@ -12065,7 +12204,7 @@ function createSuggestionsHandler(configOrPlugin, options) {
|
|
|
12065
12204
|
namespace = body.namespace;
|
|
12066
12205
|
bodyLicenseKey = body.licenseKey;
|
|
12067
12206
|
if (bodyLicenseKey) {
|
|
12068
|
-
const recheck = enforceLicense(req, config, bodyLicenseKey);
|
|
12207
|
+
const recheck = await enforceLicense(req, config, bodyLicenseKey);
|
|
12069
12208
|
if (!recheck.ok) return recheck.response;
|
|
12070
12209
|
effectiveLicensePayload = recheck.payload;
|
|
12071
12210
|
}
|
|
@@ -12356,6 +12495,7 @@ var _LicenseValidator = class _LicenseValidator {
|
|
|
12356
12495
|
retrivoraApiBase,
|
|
12357
12496
|
headers: customHeaders
|
|
12358
12497
|
} = request;
|
|
12498
|
+
const effectiveProjectId = projectId || (typeof process !== "undefined" ? process.env.NEXT_PUBLIC_RETRIVORA_PROJECT_ID || process.env.RETRIVORA_PROJECT_ID : "") || "";
|
|
12359
12499
|
const getHeader = (name) => {
|
|
12360
12500
|
if (!customHeaders) return void 0;
|
|
12361
12501
|
const target = name.toLowerCase();
|
|
@@ -12393,7 +12533,7 @@ var _LicenseValidator = class _LicenseValidator {
|
|
|
12393
12533
|
}, customHeaders || {}),
|
|
12394
12534
|
body: JSON.stringify({
|
|
12395
12535
|
licenseKey: effectiveLicenseKey,
|
|
12396
|
-
projectId,
|
|
12536
|
+
projectId: effectiveProjectId,
|
|
12397
12537
|
sdkVersion,
|
|
12398
12538
|
sdk,
|
|
12399
12539
|
platform
|
|
@@ -12404,7 +12544,7 @@ var _LicenseValidator = class _LicenseValidator {
|
|
|
12404
12544
|
if (!canUseLocalValidationFallback(base)) {
|
|
12405
12545
|
throw err;
|
|
12406
12546
|
}
|
|
12407
|
-
const payload = LicenseVerifier.
|
|
12547
|
+
const payload = await LicenseVerifier.verifyAsync(effectiveLicenseKey, effectiveProjectId);
|
|
12408
12548
|
const fallbackResp = {
|
|
12409
12549
|
valid: true,
|
|
12410
12550
|
licenseStatus: "ACTIVE",
|
|
@@ -12423,7 +12563,7 @@ var _LicenseValidator = class _LicenseValidator {
|
|
|
12423
12563
|
}
|
|
12424
12564
|
if (res && !res.ok && canUseLocalValidationFallback(base, res.status)) {
|
|
12425
12565
|
try {
|
|
12426
|
-
const payload = LicenseVerifier.
|
|
12566
|
+
const payload = await LicenseVerifier.verifyAsync(effectiveLicenseKey, effectiveProjectId);
|
|
12427
12567
|
const fallbackResp = {
|
|
12428
12568
|
valid: true,
|
|
12429
12569
|
licenseStatus: "ACTIVE",
|