@retrivora-ai/rag-engine 2.3.6 → 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/{BatchProcessor-Dfn23VAd.d.mts → BatchProcessor-BhLczWj5.d.mts} +100 -2
- package/dist/{BatchProcessor-ByBl-1MA.d.ts → BatchProcessor-C42_RVWO.d.ts} +100 -2
- package/dist/handlers/index.d.mts +1 -1
- package/dist/handlers/index.d.ts +1 -1
- package/dist/handlers/index.js +340 -172
- package/dist/handlers/index.mjs +342 -174
- 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.d.mts +2 -2
- package/dist/index.d.ts +2 -2
- package/dist/index.js +114 -87
- package/dist/index.mjs +114 -87
- package/dist/server.d.mts +263 -37
- package/dist/server.d.ts +263 -37
- package/dist/server.js +957 -178
- package/dist/server.mjs +949 -180
- package/package.json +1 -1
- package/src/LicensedRetrivora.ts +273 -0
- package/src/components/ChatWidget.tsx +0 -1
- package/src/components/ConfigProvider.tsx +2 -1
- package/src/config/LicenseConfigResolver.ts +296 -0
- package/src/config/serverConfig.ts +75 -16
- 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 +25 -11
- package/src/index.ts +9 -0
- package/src/llm/providers/UniversalLLMAdapter.ts +67 -12
- package/src/providers/vectordb/PineconeProvider.ts +69 -2
- package/src/server.ts +23 -1
- package/src/telemetry/TelemetryService.ts +330 -0
package/dist/handlers/index.js
CHANGED
|
@@ -317,7 +317,7 @@ var init_package = __esm({
|
|
|
317
317
|
"package.json"() {
|
|
318
318
|
package_default = {
|
|
319
319
|
name: "@retrivora-ai/rag-engine",
|
|
320
|
-
version: "2.3.
|
|
320
|
+
version: "2.3.8",
|
|
321
321
|
description: "Retrivora AI is a plug-and-play AI engine for RAG chat experiences \u2014 generic vector DB + LLM provider, embeddable or standalone.",
|
|
322
322
|
author: "Abhinav Alkuchi",
|
|
323
323
|
license: "UNLICENSED",
|
|
@@ -503,7 +503,12 @@ var init_ConfigFetcher = __esm({
|
|
|
503
503
|
process.env.RETRIVORA_CONTROL_PLANE_URL,
|
|
504
504
|
process.env.NEXT_PUBLIC_RETRIVORA_CONTROL_PLANE_URL,
|
|
505
505
|
CONTROL_PLANE_URL
|
|
506
|
-
].filter((url) =>
|
|
506
|
+
].filter((url) => {
|
|
507
|
+
if (!url) return false;
|
|
508
|
+
const isEnvVar = url === process.env.RETRIVORA_CONTROL_PLANE_URL || url === process.env.NEXT_PUBLIC_RETRIVORA_CONTROL_PLANE_URL;
|
|
509
|
+
if (!isEnvVar && (url.includes("localhost") || url.includes("127.0.0.1"))) return false;
|
|
510
|
+
return true;
|
|
511
|
+
}).map((url) => url.replace(/\/$/, ""));
|
|
507
512
|
for (const baseUrl of controlPlaneUrls) {
|
|
508
513
|
try {
|
|
509
514
|
const url = `${baseUrl}/api/v1/config?projectId=${encodeURIComponent(projectId)}`;
|
|
@@ -524,8 +529,7 @@ var init_ConfigFetcher = __esm({
|
|
|
524
529
|
isActive: data.isActive,
|
|
525
530
|
expiresAt: data.expiresAt,
|
|
526
531
|
vectorDb: {
|
|
527
|
-
// apiKey
|
|
528
|
-
// The SDK uses local PINECONE_API_KEY if available.
|
|
532
|
+
// Fetch apiKey from credentials API if available, else fallback to empty
|
|
529
533
|
apiKey: data.vectorDb.apiKey || "",
|
|
530
534
|
indexName: data.vectorDb.indexName || "retrivora-free",
|
|
531
535
|
provider: data.vectorDb.provider || "pinecone",
|
|
@@ -557,6 +561,32 @@ var init_ConfigFetcher = __esm({
|
|
|
557
561
|
data.projectSettings || data.settings
|
|
558
562
|
)
|
|
559
563
|
};
|
|
564
|
+
if (licenseKey) {
|
|
565
|
+
try {
|
|
566
|
+
const credUrl = `${baseUrl}/api/v1/credentials`;
|
|
567
|
+
const credRes = await fetch(credUrl, {
|
|
568
|
+
method: "POST",
|
|
569
|
+
headers: {
|
|
570
|
+
"Content-Type": "application/json"
|
|
571
|
+
},
|
|
572
|
+
body: JSON.stringify({ licenseKey, projectId: fetchedProjectId })
|
|
573
|
+
});
|
|
574
|
+
if (credRes.ok) {
|
|
575
|
+
const credData = await credRes.json();
|
|
576
|
+
if ((credData == null ? void 0 : credData.success) && (credData == null ? void 0 : credData.credentials)) {
|
|
577
|
+
if (credData.credentials.pineconeApiKey && !config.vectorDb.apiKey) {
|
|
578
|
+
config.vectorDb.apiKey = credData.credentials.pineconeApiKey;
|
|
579
|
+
}
|
|
580
|
+
if (credData.credentials.litellmApiKey) {
|
|
581
|
+
config.llm.apiKey = credData.credentials.litellmApiKey;
|
|
582
|
+
config.embedding.apiKey = credData.credentials.litellmApiKey;
|
|
583
|
+
}
|
|
584
|
+
}
|
|
585
|
+
}
|
|
586
|
+
} catch (e) {
|
|
587
|
+
console.warn("[ConfigFetcher] Failed to fetch credentials:", e);
|
|
588
|
+
}
|
|
589
|
+
}
|
|
560
590
|
this.cache.set(cacheKey, { config, cachedAt: now });
|
|
561
591
|
return config;
|
|
562
592
|
}
|
|
@@ -596,6 +626,14 @@ var init_PineconeProvider = __esm({
|
|
|
596
626
|
const opts = config.options || {};
|
|
597
627
|
this.apiKey = opts.apiKey || process.env.PINECONE_API_KEY || "";
|
|
598
628
|
}
|
|
629
|
+
getControlPlaneUrl() {
|
|
630
|
+
const urls = [
|
|
631
|
+
process.env.RETRIVORA_CONTROL_PLANE_URL,
|
|
632
|
+
process.env.NEXT_PUBLIC_RETRIVORA_CONTROL_PLANE_URL,
|
|
633
|
+
"https://www.retrivora.com"
|
|
634
|
+
].filter((url) => Boolean(url));
|
|
635
|
+
return urls[0].replace(/\/$/, "");
|
|
636
|
+
}
|
|
599
637
|
static getValidator() {
|
|
600
638
|
return {
|
|
601
639
|
validate(config) {
|
|
@@ -659,6 +697,7 @@ var init_PineconeProvider = __esm({
|
|
|
659
697
|
let key = this.apiKey || process.env.PINECONE_API_KEY || "";
|
|
660
698
|
if (!key) {
|
|
661
699
|
const licenseKey = process.env.RETRIVORA_LICENSE_KEY || process.env.NEXT_PUBLIC_RETRIVORA_LICENSE_KEY;
|
|
700
|
+
this.licenseKey = licenseKey;
|
|
662
701
|
const jwtProjectId = (() => {
|
|
663
702
|
if (!licenseKey) return void 0;
|
|
664
703
|
try {
|
|
@@ -672,6 +711,7 @@ var init_PineconeProvider = __esm({
|
|
|
672
711
|
return void 0;
|
|
673
712
|
})();
|
|
674
713
|
const projectId = process.env.RAG_PROJECT_ID || process.env.NEXT_PUBLIC_RAG_PROJECT_ID || jwtProjectId || this.projectId || "default";
|
|
714
|
+
this.projectId = projectId;
|
|
675
715
|
const remoteConfig = await ConfigFetcher.fetchRemoteVectorConfig(projectId, licenseKey);
|
|
676
716
|
if (remoteConfig) {
|
|
677
717
|
if (remoteConfig.apiKey) {
|
|
@@ -717,19 +757,59 @@ var init_PineconeProvider = __esm({
|
|
|
717
757
|
return namespace ? idx.namespace(namespace) : idx.namespace("");
|
|
718
758
|
}
|
|
719
759
|
async upsert(doc, namespace) {
|
|
720
|
-
var _a3;
|
|
760
|
+
var _a3, _b;
|
|
761
|
+
if (!this.client) {
|
|
762
|
+
if (!this.licenseKey) throw new Error("[PineconeProvider] Cannot execute vector operation: Missing API key and License key.");
|
|
763
|
+
const res = await fetch(`${this.getControlPlaneUrl()}/api/v1/vectors/upsert`, {
|
|
764
|
+
method: "POST",
|
|
765
|
+
headers: { "Content-Type": "application/json", "x-license-key": this.licenseKey },
|
|
766
|
+
body: JSON.stringify({
|
|
767
|
+
projectId: this.projectId,
|
|
768
|
+
indexName: this.indexName,
|
|
769
|
+
namespace: namespace || this.projectId,
|
|
770
|
+
records: [{ id: String(doc.id), values: doc.vector, metadata: __spreadValues({ content: doc.content }, (_a3 = doc.metadata) != null ? _a3 : {}) }]
|
|
771
|
+
})
|
|
772
|
+
});
|
|
773
|
+
if (!res.ok) throw new Error(`[PineconeProvider] Proxy upsert failed: ${await res.text()}`);
|
|
774
|
+
return;
|
|
775
|
+
}
|
|
721
776
|
const targetIdx = await this.getActiveIndex(namespace);
|
|
722
777
|
await targetIdx.upsert({
|
|
723
778
|
records: [{
|
|
724
779
|
id: String(doc.id),
|
|
725
780
|
values: doc.vector,
|
|
726
|
-
metadata: __spreadValues({ content: doc.content }, (
|
|
781
|
+
metadata: __spreadValues({ content: doc.content }, (_b = doc.metadata) != null ? _b : {})
|
|
727
782
|
}]
|
|
728
783
|
});
|
|
729
784
|
}
|
|
730
785
|
async batchUpsert(docs, namespace) {
|
|
731
|
-
const targetIdx = await this.getActiveIndex(namespace);
|
|
732
786
|
const BATCH = 100;
|
|
787
|
+
if (!this.client) {
|
|
788
|
+
if (!this.licenseKey) throw new Error("[PineconeProvider] Cannot execute vector operation: Missing API key and License key.");
|
|
789
|
+
for (let i = 0; i < docs.length; i += BATCH) {
|
|
790
|
+
const records = docs.slice(i, i + BATCH).map((d) => {
|
|
791
|
+
var _a3;
|
|
792
|
+
return {
|
|
793
|
+
id: String(d.id),
|
|
794
|
+
values: d.vector,
|
|
795
|
+
metadata: __spreadValues({ content: d.content }, (_a3 = d.metadata) != null ? _a3 : {})
|
|
796
|
+
};
|
|
797
|
+
});
|
|
798
|
+
const res = await fetch(`${this.getControlPlaneUrl()}/api/v1/vectors/upsert`, {
|
|
799
|
+
method: "POST",
|
|
800
|
+
headers: { "Content-Type": "application/json", "x-license-key": this.licenseKey },
|
|
801
|
+
body: JSON.stringify({
|
|
802
|
+
projectId: this.projectId,
|
|
803
|
+
indexName: this.indexName,
|
|
804
|
+
namespace: namespace || this.projectId,
|
|
805
|
+
records
|
|
806
|
+
})
|
|
807
|
+
});
|
|
808
|
+
if (!res.ok) throw new Error(`[PineconeProvider] Proxy batch upsert failed: ${await res.text()}`);
|
|
809
|
+
}
|
|
810
|
+
return;
|
|
811
|
+
}
|
|
812
|
+
const targetIdx = await this.getActiveIndex(namespace);
|
|
733
813
|
for (let i = 0; i < docs.length; i += BATCH) {
|
|
734
814
|
const records = docs.slice(i, i + BATCH).map((d) => {
|
|
735
815
|
var _a3;
|
|
@@ -743,20 +823,46 @@ var init_PineconeProvider = __esm({
|
|
|
743
823
|
}
|
|
744
824
|
}
|
|
745
825
|
async query(vector, topK, namespace, filter) {
|
|
746
|
-
var _a3;
|
|
747
|
-
const targetIdx = await this.getActiveIndex(namespace);
|
|
826
|
+
var _a3, _b;
|
|
748
827
|
const pineconeFilter = this.sanitizeFilter(filter);
|
|
828
|
+
if (!this.client) {
|
|
829
|
+
if (!this.licenseKey) throw new Error("[PineconeProvider] Cannot execute vector operation: Missing API key and License key.");
|
|
830
|
+
const res = await fetch(`${this.getControlPlaneUrl()}/api/v1/vectors/query`, {
|
|
831
|
+
method: "POST",
|
|
832
|
+
headers: { "Content-Type": "application/json", "x-license-key": this.licenseKey },
|
|
833
|
+
body: JSON.stringify({
|
|
834
|
+
projectId: this.projectId,
|
|
835
|
+
indexName: this.indexName,
|
|
836
|
+
namespace: namespace || this.projectId,
|
|
837
|
+
vector,
|
|
838
|
+
topK,
|
|
839
|
+
filter: pineconeFilter
|
|
840
|
+
})
|
|
841
|
+
});
|
|
842
|
+
if (!res.ok) throw new Error(`[PineconeProvider] Proxy query failed: ${await res.text()}`);
|
|
843
|
+
const data = await res.json();
|
|
844
|
+
return ((_a3 = data.matches) != null ? _a3 : []).map((m) => {
|
|
845
|
+
var _a4, _b2;
|
|
846
|
+
return {
|
|
847
|
+
id: m.id,
|
|
848
|
+
score: (_a4 = m.score) != null ? _a4 : 0,
|
|
849
|
+
content: ((_b2 = m.metadata) == null ? void 0 : _b2.content) || "",
|
|
850
|
+
metadata: m.metadata
|
|
851
|
+
};
|
|
852
|
+
});
|
|
853
|
+
}
|
|
854
|
+
const targetIdx = await this.getActiveIndex(namespace);
|
|
749
855
|
const result = await targetIdx.query(__spreadValues({
|
|
750
856
|
vector,
|
|
751
857
|
topK,
|
|
752
858
|
includeMetadata: true
|
|
753
859
|
}, Object.keys(pineconeFilter).length > 0 ? { filter: pineconeFilter } : {}));
|
|
754
|
-
return ((
|
|
755
|
-
var _a4,
|
|
860
|
+
return ((_b = result.matches) != null ? _b : []).map((m) => {
|
|
861
|
+
var _a4, _b2;
|
|
756
862
|
return {
|
|
757
863
|
id: m.id,
|
|
758
864
|
score: (_a4 = m.score) != null ? _a4 : 0,
|
|
759
|
-
content: ((
|
|
865
|
+
content: ((_b2 = m.metadata) == null ? void 0 : _b2.content) || "",
|
|
760
866
|
metadata: m.metadata
|
|
761
867
|
};
|
|
762
868
|
});
|
|
@@ -2573,9 +2679,6 @@ var import_server = require("next/server");
|
|
|
2573
2679
|
// src/core/ConfigResolver.ts
|
|
2574
2680
|
init_templateUtils();
|
|
2575
2681
|
|
|
2576
|
-
// src/core/LicenseVerifier.ts
|
|
2577
|
-
var crypto = __toESM(require("crypto"));
|
|
2578
|
-
|
|
2579
2682
|
// src/exceptions/index.ts
|
|
2580
2683
|
var RetrivoraError = class extends Error {
|
|
2581
2684
|
constructor(message, code, details) {
|
|
@@ -2651,29 +2754,18 @@ function wrapError(err, defaultCode, defaultMessage) {
|
|
|
2651
2754
|
}
|
|
2652
2755
|
|
|
2653
2756
|
// src/core/LicenseVerifier.ts
|
|
2654
|
-
var
|
|
2757
|
+
var _LicenseVerifier = class _LicenseVerifier {
|
|
2758
|
+
// Cache verified license for 5 minutes
|
|
2655
2759
|
/**
|
|
2656
|
-
*
|
|
2760
|
+
* Validates the license key asynchronously by calling the Retrivora backend.
|
|
2657
2761
|
*
|
|
2658
2762
|
* @param licenseKey - Base64url signed JWT license key.
|
|
2659
2763
|
* @param currentProjectId - Project namespace ID.
|
|
2660
|
-
* @param
|
|
2764
|
+
* @param provider - Optional provider for tier checks.
|
|
2661
2765
|
*/
|
|
2662
|
-
static
|
|
2766
|
+
static async verifyAsync(licenseKey, currentProjectId, provider) {
|
|
2663
2767
|
const isProduction = process.env.NODE_ENV === "production";
|
|
2664
2768
|
const now = Date.now();
|
|
2665
|
-
if (licenseKey) {
|
|
2666
|
-
const cacheKey = `${licenseKey}:${currentProjectId}:${provider || ""}:${publicKeyOverride || ""}`;
|
|
2667
|
-
const cached = this.cache.get(cacheKey);
|
|
2668
|
-
if (cached && now - cached.cachedAt < this.CACHE_TTL_MS) {
|
|
2669
|
-
const currentTimestampSec = Math.floor(now / 1e3);
|
|
2670
|
-
if (cached.payload.expiresAt && currentTimestampSec > cached.payload.expiresAt) {
|
|
2671
|
-
this.cache.delete(cacheKey);
|
|
2672
|
-
} else {
|
|
2673
|
-
return cached.payload;
|
|
2674
|
-
}
|
|
2675
|
-
}
|
|
2676
|
-
}
|
|
2677
2769
|
if (!licenseKey) {
|
|
2678
2770
|
if (isProduction) {
|
|
2679
2771
|
throw new ConfigurationException(
|
|
@@ -2690,52 +2782,61 @@ var LicenseVerifier = class {
|
|
|
2690
2782
|
tier: "hobby"
|
|
2691
2783
|
};
|
|
2692
2784
|
}
|
|
2693
|
-
|
|
2694
|
-
|
|
2695
|
-
|
|
2696
|
-
const
|
|
2697
|
-
if (
|
|
2698
|
-
|
|
2699
|
-
}
|
|
2700
|
-
|
|
2701
|
-
const dataToVerify = `${headerB64}.${payloadB64}`;
|
|
2702
|
-
const publicKey = publicKeyOverride != null ? publicKeyOverride : this.PUBLIC_KEY;
|
|
2703
|
-
const signature = Buffer.from(signatureB64, "base64url");
|
|
2704
|
-
const data = Buffer.from(dataToVerify);
|
|
2705
|
-
const isValid = crypto.verify(
|
|
2706
|
-
"sha256",
|
|
2707
|
-
data,
|
|
2708
|
-
publicKey,
|
|
2709
|
-
signature
|
|
2710
|
-
);
|
|
2711
|
-
if (!isValid) {
|
|
2712
|
-
throw new Error("Signature verification failed.");
|
|
2785
|
+
const cacheKey = `${licenseKey}:${currentProjectId}:${provider || ""}`;
|
|
2786
|
+
const cached = this.cache.get(cacheKey);
|
|
2787
|
+
if (cached && now - cached.cachedAt < this.CACHE_TTL_MS) {
|
|
2788
|
+
const currentTimestampSec = Math.floor(now / 1e3);
|
|
2789
|
+
if (cached.payload.expiresAt && currentTimestampSec > cached.payload.expiresAt) {
|
|
2790
|
+
this.cache.delete(cacheKey);
|
|
2791
|
+
} else {
|
|
2792
|
+
return cached.payload;
|
|
2713
2793
|
}
|
|
2714
|
-
|
|
2715
|
-
|
|
2716
|
-
|
|
2717
|
-
if (
|
|
2718
|
-
|
|
2794
|
+
}
|
|
2795
|
+
try {
|
|
2796
|
+
let baseUrl = typeof process !== "undefined" && process.env.RETRIVORA_CONTROL_PLANE_URL ? process.env.RETRIVORA_CONTROL_PLANE_URL : "https://retrivora.com";
|
|
2797
|
+
if (typeof process !== "undefined" && process.env.TELEMETRY_URL) {
|
|
2798
|
+
baseUrl = process.env.TELEMETRY_URL.replace(/\/api\/telemetry\/?$/, "");
|
|
2719
2799
|
}
|
|
2720
|
-
const
|
|
2721
|
-
|
|
2722
|
-
|
|
2723
|
-
|
|
2724
|
-
|
|
2800
|
+
const endpoint = `${baseUrl}/api/v1/license/validate`;
|
|
2801
|
+
const response = await fetch(endpoint, {
|
|
2802
|
+
method: "POST",
|
|
2803
|
+
headers: {
|
|
2804
|
+
"Content-Type": "application/json",
|
|
2805
|
+
"x-license-key": licenseKey
|
|
2806
|
+
},
|
|
2807
|
+
body: JSON.stringify({
|
|
2808
|
+
licenseKey,
|
|
2809
|
+
projectId: currentProjectId,
|
|
2810
|
+
provider
|
|
2811
|
+
})
|
|
2812
|
+
});
|
|
2813
|
+
if (!response.ok) {
|
|
2814
|
+
let errMessage = `HTTP ${response.status}`;
|
|
2815
|
+
try {
|
|
2816
|
+
const body = await response.json();
|
|
2817
|
+
if (body.message) errMessage = body.message;
|
|
2818
|
+
} catch (e) {
|
|
2819
|
+
}
|
|
2820
|
+
throw new Error(errMessage);
|
|
2725
2821
|
}
|
|
2726
|
-
|
|
2727
|
-
|
|
2822
|
+
const data = await response.json();
|
|
2823
|
+
if (!data.valid) {
|
|
2824
|
+
throw new Error(data.message || "License validation failed by server.");
|
|
2728
2825
|
}
|
|
2729
|
-
|
|
2730
|
-
if (
|
|
2731
|
-
|
|
2732
|
-
`License key has expired. Expiration: ${new Date(
|
|
2733
|
-
payload.expiresAt * 1e3
|
|
2734
|
-
).toDateString()}`
|
|
2735
|
-
);
|
|
2826
|
+
let expiresAtNum = Math.floor(Date.now() / 1e3) + 100 * 365 * 24 * 60 * 60;
|
|
2827
|
+
if (data.expiresAt) {
|
|
2828
|
+
expiresAtNum = Math.floor(new Date(data.expiresAt).getTime() / 1e3);
|
|
2736
2829
|
}
|
|
2830
|
+
const tier = _LicenseVerifier.extractTier(licenseKey);
|
|
2831
|
+
const payload = {
|
|
2832
|
+
projectId: currentProjectId,
|
|
2833
|
+
expiresAt: expiresAtNum,
|
|
2834
|
+
tier,
|
|
2835
|
+
licenseStatus: data.licenseStatus,
|
|
2836
|
+
minimumSupportedVersion: data.minimumSupportedVersion,
|
|
2837
|
+
forceUpgrade: data.forceUpgrade
|
|
2838
|
+
};
|
|
2737
2839
|
if (isProduction && provider) {
|
|
2738
|
-
const tier = (payload.tier || "").toLowerCase();
|
|
2739
2840
|
const normalizedProvider = provider.toLowerCase();
|
|
2740
2841
|
if (tier === "hobby") {
|
|
2741
2842
|
const allowedHobby = ["postgresql", "pgvector", "supabase"];
|
|
@@ -2763,15 +2864,12 @@ var LicenseVerifier = class {
|
|
|
2763
2864
|
}
|
|
2764
2865
|
}
|
|
2765
2866
|
}
|
|
2766
|
-
|
|
2767
|
-
const cacheKey = `${licenseKey}:${currentProjectId}:${provider || ""}:${publicKeyOverride || ""}`;
|
|
2768
|
-
this.cache.set(cacheKey, { payload, cachedAt: now });
|
|
2769
|
-
}
|
|
2867
|
+
this.cache.set(cacheKey, { payload, cachedAt: now });
|
|
2770
2868
|
return payload;
|
|
2771
2869
|
} catch (err) {
|
|
2772
2870
|
const message = err instanceof Error ? err.message : String(err);
|
|
2773
2871
|
throw new ConfigurationException(
|
|
2774
|
-
`[Retrivora SDK] License key validation failed: ${message}`
|
|
2872
|
+
`[Retrivora SDK] License key validation failed via API: ${message}`
|
|
2775
2873
|
);
|
|
2776
2874
|
}
|
|
2777
2875
|
}
|
|
@@ -2840,23 +2938,25 @@ var LicenseVerifier = class {
|
|
|
2840
2938
|
}
|
|
2841
2939
|
}
|
|
2842
2940
|
}
|
|
2941
|
+
static extractTier(licenseKey) {
|
|
2942
|
+
if (!licenseKey) return "hobby";
|
|
2943
|
+
try {
|
|
2944
|
+
const sanitizedKey = licenseKey.trim().replace(/^["']|["']$/g, "").trim();
|
|
2945
|
+
const rawToken = sanitizedKey.replace(/^rtv_/i, "").trim();
|
|
2946
|
+
const parts = rawToken.split(".");
|
|
2947
|
+
if (parts.length === 3) {
|
|
2948
|
+
const decodedPayload = JSON.parse(Buffer.from(parts[1], "base64url").toString("utf8"));
|
|
2949
|
+
if (decodedPayload.tier) return decodedPayload.tier;
|
|
2950
|
+
}
|
|
2951
|
+
} catch (e) {
|
|
2952
|
+
}
|
|
2953
|
+
return "hobby";
|
|
2954
|
+
}
|
|
2843
2955
|
};
|
|
2844
|
-
//
|
|
2845
|
-
|
|
2846
|
-
|
|
2847
|
-
|
|
2848
|
-
// Retrivora's Public Key used to verify the license key signature.
|
|
2849
|
-
// In production, this matches the private key held by Retrivora SaaS.
|
|
2850
|
-
// Rotate this key only when the signing private key is replaced.
|
|
2851
|
-
LicenseVerifier.PUBLIC_KEY = `-----BEGIN PUBLIC KEY-----
|
|
2852
|
-
MIIBIjANBgkqhkiG9w0BAQEFAAOCAQ8AMIIBCgKCAQEAoOQlmDSKfCZaRy06rxwa
|
|
2853
|
-
chuDimlF134xTCitKDTPTPizF23oSn34pGDJakm/0T09JVUX8L/cvhGPe/3lf/g9
|
|
2854
|
-
4Y1q+Gb2KVM17KNGeT1Aj9Ua3BKz/yao/oFhi/r3Zt3cWY13B/Rd6clqY9WshIAV
|
|
2855
|
-
NqZNM8ilTl777cMbyym+6D+mzGXgmnJAO5brddIAI9FPLW0T3Znt8vEqDOIljEkC
|
|
2856
|
-
HCGHeirKABLbjKSJ4hljCa3vVitWqndhiq8CBSJG6HatiSGYotgMWGRY+0EbdlEv
|
|
2857
|
-
OJP4SqafQ3aD6YnL9q1n15QKwxu/uMK+JGM2VxxuyUi9GANtMIkCYy9xya73P4Qc
|
|
2858
|
-
gQIDAQAB
|
|
2859
|
-
-----END PUBLIC KEY-----`;
|
|
2956
|
+
// In-memory cache to save network overhead on hot paths.
|
|
2957
|
+
_LicenseVerifier.cache = /* @__PURE__ */ new Map();
|
|
2958
|
+
_LicenseVerifier.CACHE_TTL_MS = 5 * 60 * 1e3;
|
|
2959
|
+
var LicenseVerifier = _LicenseVerifier;
|
|
2860
2960
|
|
|
2861
2961
|
// src/config/constants.ts
|
|
2862
2962
|
var VECTOR_DB_PROVIDERS = [
|
|
@@ -2904,6 +3004,7 @@ var PROVIDERS_WITH_EMBEDDINGS = [
|
|
|
2904
3004
|
var UI_BORDER_RADIUS_OPTIONS = ["none", "sm", "md", "lg", "xl", "full"];
|
|
2905
3005
|
|
|
2906
3006
|
// src/config/serverConfig.ts
|
|
3007
|
+
var _runtimeConfig = null;
|
|
2907
3008
|
function readString(env, name) {
|
|
2908
3009
|
var _a3;
|
|
2909
3010
|
const value = (_a3 = env[name]) == null ? void 0 : _a3.trim();
|
|
@@ -2927,7 +3028,7 @@ function readEnum(env, name, fallback, allowed) {
|
|
|
2927
3028
|
throw new Error(`[getRagConfig] ${name} must be one of: ${allowed.join(", ")}`);
|
|
2928
3029
|
}
|
|
2929
3030
|
function getEnvConfig(env = process.env, base) {
|
|
2930
|
-
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
|
|
3031
|
+
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;
|
|
2931
3032
|
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;
|
|
2932
3033
|
const jwtProjectId = (() => {
|
|
2933
3034
|
if (!licenseKey) return void 0;
|
|
@@ -3012,32 +3113,41 @@ function getEnvConfig(env = process.env, base) {
|
|
|
3012
3113
|
const isFreeTier2 = (() => {
|
|
3013
3114
|
if (!licenseKey) return true;
|
|
3014
3115
|
try {
|
|
3015
|
-
const
|
|
3016
|
-
const tier = (payload.tier || "").toLowerCase();
|
|
3116
|
+
const tier = LicenseVerifier.extractTier(licenseKey).toLowerCase();
|
|
3017
3117
|
return tier === "free_trial" || tier === "free_tier" || tier === "free" || tier === "hobby";
|
|
3018
3118
|
} catch (e) {
|
|
3019
3119
|
return true;
|
|
3020
3120
|
}
|
|
3021
3121
|
})();
|
|
3022
|
-
const
|
|
3023
|
-
const
|
|
3024
|
-
const
|
|
3025
|
-
const
|
|
3026
|
-
const
|
|
3027
|
-
const
|
|
3028
|
-
const
|
|
3029
|
-
const
|
|
3030
|
-
const
|
|
3031
|
-
const
|
|
3032
|
-
|
|
3033
|
-
|
|
3034
|
-
|
|
3122
|
+
const tierBasedLLMModel = isFreeTier2 ? "llama-3.1-8b-instant" : "llama-3.3-70b-versatile";
|
|
3123
|
+
const tierBasedEmbeddingModel = isFreeTier2 ? "text-embedding-004" : "text-embedding-004";
|
|
3124
|
+
const defaultGatewayUrl = "https://llm.retrivora.com/api/v1";
|
|
3125
|
+
const rt = _runtimeConfig;
|
|
3126
|
+
const defaultLlmProvider = "universal_rest";
|
|
3127
|
+
const llmProvider = (_sa = (_ra = readEnum(env, "LLM_PROVIDER", defaultLlmProvider, LLM_PROVIDERS)) != null ? _ra : (_qa = base == null ? void 0 : base.llm) == null ? void 0 : _qa.provider) != null ? _sa : defaultLlmProvider;
|
|
3128
|
+
const llmBaseUrl = (_xa = (_wa = (_va = (_ta = readString(env, "LITELLM_BASE_URL")) != null ? _ta : readString(env, "LLM_BASE_URL")) != null ? _va : (_ua = base == null ? void 0 : base.llm) == null ? void 0 : _ua.baseUrl) != null ? _wa : rt == null ? void 0 : rt.llmBaseUrl) != null ? _xa : defaultGatewayUrl;
|
|
3129
|
+
const llmModel = (_Ba = (_Aa = (_za = readString(env, "LLM_MODEL")) != null ? _za : (_ya = base == null ? void 0 : base.llm) == null ? void 0 : _ya.model) != null ? _Aa : rt == null ? void 0 : rt.llmModel) != null ? _Ba : tierBasedLLMModel;
|
|
3130
|
+
const llmApiKey = (_Fa = (_Ea = (_Ca = readString(env, "LITELLM_MASTER_KEY")) != null ? _Ca : rt == null ? void 0 : rt.litellmApiKey) != null ? _Ea : (_Da = base == null ? void 0 : base.llm) == null ? void 0 : _Da.apiKey) != null ? _Fa : licenseKey;
|
|
3131
|
+
const llmProfile = (_Ja = (_Ia = readString(env, "LLM_UNIVERSAL_PROFILE")) != null ? _Ia : (_Ha = (_Ga = base == null ? void 0 : base.llm) == null ? void 0 : _Ga.options) == null ? void 0 : _Ha.profile) != null ? _Ja : "litellm";
|
|
3132
|
+
console.log("[serverConfig] \u{1F527} LLM Configuration:", {
|
|
3133
|
+
baseUrl: llmBaseUrl,
|
|
3134
|
+
model: llmModel,
|
|
3135
|
+
provider: llmProvider,
|
|
3136
|
+
hasApiKey: !!llmApiKey,
|
|
3137
|
+
source: (rt == null ? void 0 : rt.llmModel) ? "runtime-injected" : "env/fallback"
|
|
3138
|
+
});
|
|
3139
|
+
const defaultEmbeddingProvider = "universal_rest";
|
|
3140
|
+
const embeddingProvider = (_Ma = (_La = readEnum(env, "EMBEDDING_PROVIDER", defaultEmbeddingProvider, EMBEDDING_PROVIDERS)) != null ? _La : (_Ka = base == null ? void 0 : base.embedding) == null ? void 0 : _Ka.provider) != null ? _Ma : defaultEmbeddingProvider;
|
|
3141
|
+
const embeddingBaseUrl = (_Ta = (_Sa = (_Ra = (_Qa = (_Oa = (_Na = readString(env, "LITELLM_BASE_URL")) != null ? _Na : readString(env, "EMBEDDING_BASE_URL")) != null ? _Oa : readString(env, "LLM_BASE_URL")) != null ? _Qa : (_Pa = base == null ? void 0 : base.embedding) == null ? void 0 : _Pa.baseUrl) != null ? _Ra : rt == null ? void 0 : rt.embeddingBaseUrl) != null ? _Sa : rt == null ? void 0 : rt.llmBaseUrl) != null ? _Ta : defaultGatewayUrl;
|
|
3142
|
+
const embeddingModel = (_Xa = (_Wa = (_Va = readString(env, "EMBEDDING_MODEL")) != null ? _Va : (_Ua = base == null ? void 0 : base.embedding) == null ? void 0 : _Ua.model) != null ? _Wa : rt == null ? void 0 : rt.embeddingModel) != null ? _Xa : tierBasedEmbeddingModel;
|
|
3143
|
+
const embeddingApiKey = (_$a = (__a = (_Ya = readString(env, "LITELLM_MASTER_KEY")) != null ? _Ya : rt == null ? void 0 : rt.litellmApiKey) != null ? __a : (_Za = base == null ? void 0 : base.embedding) == null ? void 0 : _Za.apiKey) != null ? _$a : licenseKey;
|
|
3144
|
+
const embeddingProfile = (_db = (_cb = readString(env, "EMBEDDING_UNIVERSAL_PROFILE")) != null ? _cb : (_bb = (_ab = base == null ? void 0 : base.embedding) == null ? void 0 : _ab.options) == null ? void 0 : _bb.profile) != null ? _db : "litellm";
|
|
3035
3145
|
return __spreadProps(__spreadValues({
|
|
3036
3146
|
projectId,
|
|
3037
3147
|
licenseKey,
|
|
3038
3148
|
vectorDb: {
|
|
3039
3149
|
provider: vectorProvider,
|
|
3040
|
-
indexName: (
|
|
3150
|
+
indexName: (_fb = (_eb = readString(env, "VECTOR_DB_INDEX")) != null ? _eb : vectorDbOptions.indexName) != null ? _fb : "rag-index",
|
|
3041
3151
|
options: vectorDbOptions
|
|
3042
3152
|
},
|
|
3043
3153
|
llm: {
|
|
@@ -3067,30 +3177,30 @@ function getEnvConfig(env = process.env, base) {
|
|
|
3067
3177
|
}
|
|
3068
3178
|
},
|
|
3069
3179
|
ui: {
|
|
3070
|
-
title: (
|
|
3071
|
-
subtitle: (
|
|
3072
|
-
primaryColor: (
|
|
3073
|
-
accentColor: (
|
|
3074
|
-
logoUrl: (
|
|
3075
|
-
placeholder: (
|
|
3076
|
-
showSources: ((
|
|
3077
|
-
welcomeMessage: (
|
|
3078
|
-
visualStyle: (
|
|
3079
|
-
borderRadius: (
|
|
3080
|
-
allowUpload: ((
|
|
3180
|
+
title: (_hb = (_gb = readString(env, "NEXT_PUBLIC_UI_TITLE")) != null ? _gb : readString(env, "UI_TITLE")) != null ? _hb : "AI Assistant",
|
|
3181
|
+
subtitle: (_jb = (_ib = readString(env, "NEXT_PUBLIC_UI_SUBTITLE")) != null ? _ib : readString(env, "UI_SUBTITLE")) != null ? _jb : "Powered by RAG",
|
|
3182
|
+
primaryColor: (_lb = (_kb = readString(env, "NEXT_PUBLIC_PRIMARY_COLOR")) != null ? _kb : readString(env, "UI_PRIMARY_COLOR")) != null ? _lb : "#10b981",
|
|
3183
|
+
accentColor: (_nb = (_mb = readString(env, "NEXT_PUBLIC_ACCENT_COLOR")) != null ? _mb : readString(env, "UI_ACCENT_COLOR")) != null ? _nb : "#3b82f6",
|
|
3184
|
+
logoUrl: (_ob = readString(env, "NEXT_PUBLIC_LOGO_URL")) != null ? _ob : readString(env, "UI_LOGO_URL"),
|
|
3185
|
+
placeholder: (_qb = (_pb = readString(env, "NEXT_PUBLIC_PLACEHOLDER")) != null ? _pb : readString(env, "UI_PLACEHOLDER")) != null ? _qb : "Ask me anything\u2026",
|
|
3186
|
+
showSources: ((_sb = (_rb = readString(env, "NEXT_PUBLIC_SHOW_SOURCES")) != null ? _rb : readString(env, "UI_SHOW_SOURCES")) != null ? _sb : "true") !== "false",
|
|
3187
|
+
welcomeMessage: (_ub = (_tb = readString(env, "NEXT_PUBLIC_WELCOME_MESSAGE")) != null ? _tb : readString(env, "UI_WELCOME_MESSAGE")) != null ? _ub : "Hello! I'm your AI assistant. Ask me anything about your documents.",
|
|
3188
|
+
visualStyle: (_wb = (_vb = readString(env, "NEXT_PUBLIC_UI_VISUAL_STYLE")) != null ? _vb : readString(env, "UI_VISUAL_STYLE")) != null ? _wb : "glass",
|
|
3189
|
+
borderRadius: (_yb = (_xb = readString(env, "NEXT_PUBLIC_UI_BORDER_RADIUS")) != null ? _xb : readString(env, "UI_BORDER_RADIUS")) != null ? _yb : "xl",
|
|
3190
|
+
allowUpload: ((_Ab = (_zb = readString(env, "NEXT_PUBLIC_ALLOW_UPLOAD")) != null ? _zb : readString(env, "UI_ALLOW_UPLOAD")) != null ? _Ab : "false") === "true"
|
|
3081
3191
|
},
|
|
3082
3192
|
rag: {
|
|
3083
3193
|
topK: readNumber(env, "RAG_TOP_K", 5),
|
|
3084
3194
|
scoreThreshold: readNumber(env, "RAG_SCORE_THRESHOLD", 0),
|
|
3085
3195
|
chunkSize: readNumber(env, "RAG_CHUNK_SIZE", 1e3),
|
|
3086
3196
|
chunkOverlap: readNumber(env, "RAG_CHUNK_OVERLAP", 200),
|
|
3087
|
-
filterableFields: (
|
|
3197
|
+
filterableFields: (_Bb = readString(env, "RAG_FILTERABLE_FIELDS")) == null ? void 0 : _Bb.split(",").map((f) => f.trim()),
|
|
3088
3198
|
// Query pipeline toggles — read from .env.local
|
|
3089
3199
|
useQueryTransformation: readString(env, "RAG_USE_QUERY_TRANSFORMATION") === "true",
|
|
3090
3200
|
useReranking: readString(env, "RAG_USE_RERANKING") === "true",
|
|
3091
3201
|
useGraphRetrieval: readString(env, "RAG_USE_GRAPH_RETRIEVAL") === "true",
|
|
3092
|
-
architecture: (
|
|
3093
|
-
chunkingStrategy: (
|
|
3202
|
+
architecture: (_Cb = readString(env, "RAG_ARCHITECTURE")) != null ? _Cb : "simple",
|
|
3203
|
+
chunkingStrategy: (_Db = readString(env, "RAG_CHUNKING_STRATEGY")) != null ? _Db : "recursive",
|
|
3094
3204
|
uiMapping: (() => {
|
|
3095
3205
|
const raw = readString(env, "RAG_UI_MAPPING");
|
|
3096
3206
|
if (!raw) return void 0;
|
|
@@ -3103,7 +3213,7 @@ function getEnvConfig(env = process.env, base) {
|
|
|
3103
3213
|
},
|
|
3104
3214
|
telemetry: {
|
|
3105
3215
|
enabled: telemetryEnabled,
|
|
3106
|
-
url: (
|
|
3216
|
+
url: (_Hb = (_Gb = (_Eb = readString(env, "TELEMETRY_URL")) != null ? _Eb : readString(env, "NEXT_PUBLIC_TELEMETRY_URL")) != null ? _Gb : (_Fb = base == null ? void 0 : base.telemetry) == null ? void 0 : _Fb.url) != null ? _Hb : "https://www.retrivora.com/api/telemetry"
|
|
3107
3217
|
}
|
|
3108
3218
|
}, readString(env, "GRAPH_DB_PROVIDER") ? {
|
|
3109
3219
|
graphDb: {
|
|
@@ -4421,7 +4531,7 @@ var UniversalLLMAdapter = class {
|
|
|
4421
4531
|
});
|
|
4422
4532
|
}
|
|
4423
4533
|
async chat(messages, context) {
|
|
4424
|
-
var _a3, _b, _c, _d, _e;
|
|
4534
|
+
var _a3, _b, _c, _d, _e, _f, _g2, _h, _i, _j;
|
|
4425
4535
|
const path2 = (_a3 = this.opts.chatPath) != null ? _a3 : "/chat/completions";
|
|
4426
4536
|
const safeMessages = (Array.isArray(messages) ? messages : []).filter((m) => Boolean(m && typeof m === "object")).map((m) => ({
|
|
4427
4537
|
role: m.role || "user",
|
|
@@ -4451,16 +4561,27 @@ ${context != null ? context : "None"}` },
|
|
|
4451
4561
|
};
|
|
4452
4562
|
}
|
|
4453
4563
|
try {
|
|
4564
|
+
console.debug(`[UniversalLLMAdapter] POST ${this.baseUrl}${path2}`);
|
|
4565
|
+
console.debug(`[UniversalLLMAdapter] Model: ${this.model}`);
|
|
4566
|
+
console.debug(`[UniversalLLMAdapter] Auth: Bearer ${((_b = this.apiKey) == null ? void 0 : _b.substring(0, 20)) || "none"}...`);
|
|
4454
4567
|
const { data: data2 } = await this.http.post(path2, payload);
|
|
4455
|
-
const extractPath2 = (
|
|
4456
|
-
const result2 = (
|
|
4568
|
+
const extractPath2 = (_c = this.opts.responseExtractPath) != null ? _c : "choices[0].message.content";
|
|
4569
|
+
const result2 = (_d = resolvePath(data2, extractPath2)) != null ? _d : extractContent(data2);
|
|
4457
4570
|
if (result2 !== void 0) {
|
|
4458
4571
|
return String(result2);
|
|
4459
4572
|
}
|
|
4460
4573
|
} catch (httpErr) {
|
|
4461
|
-
|
|
4462
|
-
|
|
4574
|
+
console.error("[UniversalLLMAdapter] \u274C HTTP chat request failed:", {
|
|
4575
|
+
status: (_e = httpErr == null ? void 0 : httpErr.response) == null ? void 0 : _e.status,
|
|
4576
|
+
statusText: (_f = httpErr == null ? void 0 : httpErr.response) == null ? void 0 : _f.statusText,
|
|
4577
|
+
url: (_g2 = httpErr == null ? void 0 : httpErr.config) == null ? void 0 : _g2.url,
|
|
4578
|
+
errorData: (_h = httpErr == null ? void 0 : httpErr.response) == null ? void 0 : _h.data,
|
|
4579
|
+
message: httpErr == null ? void 0 : httpErr.message
|
|
4580
|
+
});
|
|
4581
|
+
const _g3 = globalThis;
|
|
4582
|
+
const dispatch = _g3.__retrivoraDispatchChat;
|
|
4463
4583
|
if (typeof dispatch === "function") {
|
|
4584
|
+
console.debug("[UniversalLLMAdapter] \u{1F504} Attempting in-process fallback dispatch");
|
|
4464
4585
|
const res = await dispatch({
|
|
4465
4586
|
model: this.model,
|
|
4466
4587
|
messages: formattedMessages,
|
|
@@ -4475,8 +4596,8 @@ ${context != null ? context : "None"}` },
|
|
|
4475
4596
|
throw httpErr;
|
|
4476
4597
|
}
|
|
4477
4598
|
const { data } = await this.http.post(path2, payload);
|
|
4478
|
-
const extractPath = (
|
|
4479
|
-
const result = (
|
|
4599
|
+
const extractPath = (_i = this.opts.responseExtractPath) != null ? _i : "choices[0].message.content";
|
|
4600
|
+
const result = (_j = resolvePath(data, extractPath)) != null ? _j : extractContent(data);
|
|
4480
4601
|
if (result === void 0) {
|
|
4481
4602
|
throw new Error(`[UniversalLLMAdapter] Could not extract text from path '${extractPath}' in response.`);
|
|
4482
4603
|
}
|
|
@@ -4615,36 +4736,70 @@ ${context != null ? context : "None"}` },
|
|
|
4615
4736
|
});
|
|
4616
4737
|
}
|
|
4617
4738
|
async embed(text) {
|
|
4618
|
-
var _a3, _b, _c, _d, _e;
|
|
4739
|
+
var _a3, _b, _c, _d, _e, _f, _g2;
|
|
4619
4740
|
const path2 = (_a3 = this.opts.embedPath) != null ? _a3 : "/embeddings";
|
|
4620
4741
|
const payload = this.opts.embedPayloadTemplate ? buildPayload(this.opts.embedPayloadTemplate, { input: text, model: this.model }) : { input: text, model: this.model };
|
|
4621
4742
|
try {
|
|
4622
|
-
const { data
|
|
4623
|
-
const
|
|
4624
|
-
const
|
|
4625
|
-
if (Array.isArray(
|
|
4626
|
-
|
|
4627
|
-
|
|
4628
|
-
|
|
4743
|
+
const { data } = await this.http.post(path2, payload);
|
|
4744
|
+
const extractPath = (_b = this.opts.embedExtractPath) != null ? _b : "data[0].embedding";
|
|
4745
|
+
const vector = resolvePath(data, extractPath);
|
|
4746
|
+
if (Array.isArray(vector)) return vector;
|
|
4747
|
+
console.warn(
|
|
4748
|
+
`[UniversalLLMAdapter] Embedding API returned unexpected format for path '${extractPath}'. Response:`,
|
|
4749
|
+
data
|
|
4750
|
+
);
|
|
4751
|
+
} catch (err) {
|
|
4752
|
+
console.warn(
|
|
4753
|
+
`[UniversalLLMAdapter] HTTP embedding request failed: ${(err == null ? void 0 : err.message) || err}`,
|
|
4754
|
+
{ path: path2, model: this.model }
|
|
4755
|
+
);
|
|
4756
|
+
const _g3 = globalThis;
|
|
4757
|
+
const dispatchEmbed = _g3.__retrivoraDispatchEmbedding;
|
|
4629
4758
|
if (typeof dispatchEmbed === "function") {
|
|
4630
|
-
|
|
4631
|
-
|
|
4632
|
-
|
|
4759
|
+
try {
|
|
4760
|
+
const res = await dispatchEmbed({ input: text, model: this.model }, this.apiKey);
|
|
4761
|
+
if ((_d = (_c = res == null ? void 0 : res.data) == null ? void 0 : _c[0]) == null ? void 0 : _d.embedding) {
|
|
4762
|
+
return res.data[0].embedding;
|
|
4763
|
+
}
|
|
4764
|
+
} catch (dispatchErr) {
|
|
4765
|
+
console.warn("[UniversalLLMAdapter] In-process dispatch embedding failed:", dispatchErr);
|
|
4633
4766
|
}
|
|
4634
4767
|
}
|
|
4635
4768
|
}
|
|
4636
|
-
|
|
4637
|
-
|
|
4638
|
-
|
|
4639
|
-
|
|
4640
|
-
|
|
4769
|
+
try {
|
|
4770
|
+
const { data } = await this.http.post(path2, payload);
|
|
4771
|
+
const extractPath = (_e = this.opts.embedExtractPath) != null ? _e : "data[0].embedding";
|
|
4772
|
+
const vector = resolvePath(data, extractPath);
|
|
4773
|
+
if (Array.isArray(vector)) {
|
|
4774
|
+
return vector;
|
|
4775
|
+
}
|
|
4776
|
+
console.error(
|
|
4777
|
+
`[UniversalLLMAdapter] Retry embedding failed: unexpected response format for path '${extractPath}'. Response:`,
|
|
4778
|
+
data
|
|
4779
|
+
);
|
|
4780
|
+
throw new Error(
|
|
4781
|
+
`[UniversalLLMAdapter] Could not extract embedding vector. Expected array at '${extractPath}', got: ${typeof vector}. Response keys: ${Object.keys(data || {})}.`
|
|
4782
|
+
);
|
|
4783
|
+
} catch (err) {
|
|
4784
|
+
console.error(
|
|
4785
|
+
`[UniversalLLMAdapter] Both embedding attempts failed. Path: ${path2}, Model: ${this.model}`,
|
|
4786
|
+
{ error: err == null ? void 0 : err.message, statusCode: (_f = err == null ? void 0 : err.response) == null ? void 0 : _f.status, response: (_g2 = err == null ? void 0 : err.response) == null ? void 0 : _g2.data }
|
|
4787
|
+
);
|
|
4788
|
+
throw new Error(
|
|
4789
|
+
`[UniversalLLMAdapter] Failed to generate embedding after 2 attempts: ${(err == null ? void 0 : err.message) || err}`
|
|
4790
|
+
);
|
|
4641
4791
|
}
|
|
4642
|
-
return vector;
|
|
4643
4792
|
}
|
|
4644
4793
|
async batchEmbed(texts) {
|
|
4645
4794
|
const results = [];
|
|
4646
4795
|
for (const text of texts) {
|
|
4647
|
-
|
|
4796
|
+
try {
|
|
4797
|
+
const vector = await this.embed(text);
|
|
4798
|
+
results.push(vector);
|
|
4799
|
+
} catch (err) {
|
|
4800
|
+
console.warn(`[UniversalLLMAdapter] batchEmbed failed for text (first 50 chars): ${text.slice(0, 50)}...`, err);
|
|
4801
|
+
throw err;
|
|
4802
|
+
}
|
|
4648
4803
|
}
|
|
4649
4804
|
return results;
|
|
4650
4805
|
}
|
|
@@ -10033,7 +10188,7 @@ var VectorPlugin = class {
|
|
|
10033
10188
|
this.validationPromise = (async () => {
|
|
10034
10189
|
var _a3;
|
|
10035
10190
|
await ConfigValidator.validateAndThrow(resolvedConfig);
|
|
10036
|
-
LicenseVerifier.
|
|
10191
|
+
await LicenseVerifier.verifyAsync(
|
|
10037
10192
|
resolvedConfig.licenseKey,
|
|
10038
10193
|
resolvedConfig.projectId,
|
|
10039
10194
|
(_a3 = resolvedConfig.vectorDb) == null ? void 0 : _a3.provider
|
|
@@ -10306,7 +10461,7 @@ var DatabaseStorage = class {
|
|
|
10306
10461
|
* In non-production (development / test) environments this is a complete no-op —
|
|
10307
10462
|
* all History and Feedback features are freely accessible for local development.
|
|
10308
10463
|
*/
|
|
10309
|
-
checkPremiumSubscription() {
|
|
10464
|
+
async checkPremiumSubscription() {
|
|
10310
10465
|
if (process.env.NODE_ENV !== "production") {
|
|
10311
10466
|
return;
|
|
10312
10467
|
}
|
|
@@ -10316,7 +10471,7 @@ var DatabaseStorage = class {
|
|
|
10316
10471
|
);
|
|
10317
10472
|
}
|
|
10318
10473
|
try {
|
|
10319
|
-
const payload = LicenseVerifier.
|
|
10474
|
+
const payload = await LicenseVerifier.verifyAsync(this.config.licenseKey, this.config.projectId);
|
|
10320
10475
|
const tier = (payload.tier || "").toLowerCase();
|
|
10321
10476
|
if (tier !== "premium" && tier !== "enterprise" && tier !== "growth" && tier !== "pro" && tier !== "developer_pro" && tier !== "free_trial" && tier !== "free_tier" && tier !== "free" && tier !== "hobby") {
|
|
10322
10477
|
throw new Error(
|
|
@@ -10329,16 +10484,16 @@ var DatabaseStorage = class {
|
|
|
10329
10484
|
);
|
|
10330
10485
|
}
|
|
10331
10486
|
}
|
|
10332
|
-
checkHistoryEnabled() {
|
|
10487
|
+
async checkHistoryEnabled() {
|
|
10333
10488
|
var _a3, _b;
|
|
10334
|
-
this.checkPremiumSubscription();
|
|
10489
|
+
await this.checkPremiumSubscription();
|
|
10335
10490
|
if (((_b = (_a3 = this.config.rag) == null ? void 0 : _a3.history) == null ? void 0 : _b.enabled) === false) {
|
|
10336
10491
|
throw new Error("[Retrivora SDK] Chat History is disabled in RagConfig.");
|
|
10337
10492
|
}
|
|
10338
10493
|
}
|
|
10339
|
-
checkFeedbackEnabled() {
|
|
10494
|
+
async checkFeedbackEnabled() {
|
|
10340
10495
|
var _a3, _b;
|
|
10341
|
-
this.checkPremiumSubscription();
|
|
10496
|
+
await this.checkPremiumSubscription();
|
|
10342
10497
|
if (((_b = (_a3 = this.config.rag) == null ? void 0 : _a3.feedback) == null ? void 0 : _b.enabled) === false) {
|
|
10343
10498
|
throw new Error("[Retrivora SDK] User Feedback is disabled in RagConfig.");
|
|
10344
10499
|
}
|
|
@@ -10444,7 +10599,7 @@ var DatabaseStorage = class {
|
|
|
10444
10599
|
}
|
|
10445
10600
|
// ─── Message History Operations ──────────────────────────────────────────
|
|
10446
10601
|
async saveMessage(sessionId, message) {
|
|
10447
|
-
this.checkHistoryEnabled();
|
|
10602
|
+
await this.checkHistoryEnabled();
|
|
10448
10603
|
const createdAt = (/* @__PURE__ */ new Date()).toISOString();
|
|
10449
10604
|
const msgId = message.id || `msg_${Date.now()}_${Math.random().toString(36).slice(2, 6)}`;
|
|
10450
10605
|
if (this.provider === "postgresql" || this.provider === "pgvector") {
|
|
@@ -10507,7 +10662,7 @@ var DatabaseStorage = class {
|
|
|
10507
10662
|
}
|
|
10508
10663
|
}
|
|
10509
10664
|
async getHistory(sessionId, projectIds) {
|
|
10510
|
-
this.checkHistoryEnabled();
|
|
10665
|
+
await this.checkHistoryEnabled();
|
|
10511
10666
|
if (projectIds && projectIds.length > 0 && !this.sessionInScope(sessionId, projectIds)) {
|
|
10512
10667
|
return [];
|
|
10513
10668
|
}
|
|
@@ -10541,7 +10696,7 @@ var DatabaseStorage = class {
|
|
|
10541
10696
|
}
|
|
10542
10697
|
}
|
|
10543
10698
|
async clearHistory(sessionId, projectIds) {
|
|
10544
|
-
this.checkHistoryEnabled();
|
|
10699
|
+
await this.checkHistoryEnabled();
|
|
10545
10700
|
if (projectIds && projectIds.length > 0 && !this.sessionInScope(sessionId, projectIds)) {
|
|
10546
10701
|
return;
|
|
10547
10702
|
}
|
|
@@ -10577,7 +10732,7 @@ var DatabaseStorage = class {
|
|
|
10577
10732
|
);
|
|
10578
10733
|
}
|
|
10579
10734
|
async listSessions(projectIds) {
|
|
10580
|
-
this.checkHistoryEnabled();
|
|
10735
|
+
await this.checkHistoryEnabled();
|
|
10581
10736
|
let raw = [];
|
|
10582
10737
|
if (this.provider === "postgresql" || this.provider === "pgvector") {
|
|
10583
10738
|
const pool = await this.getPGPool();
|
|
@@ -10596,7 +10751,7 @@ var DatabaseStorage = class {
|
|
|
10596
10751
|
}
|
|
10597
10752
|
// ─── Feedback Operations ──────────────────────────────────────────────────
|
|
10598
10753
|
async saveFeedback(feedback) {
|
|
10599
|
-
this.checkFeedbackEnabled();
|
|
10754
|
+
await this.checkFeedbackEnabled();
|
|
10600
10755
|
const id = `fb_${Date.now()}_${Math.random().toString(36).slice(2, 6)}`;
|
|
10601
10756
|
const createdAt = (/* @__PURE__ */ new Date()).toISOString();
|
|
10602
10757
|
if (this.provider === "postgresql" || this.provider === "pgvector") {
|
|
@@ -10646,7 +10801,7 @@ var DatabaseStorage = class {
|
|
|
10646
10801
|
}
|
|
10647
10802
|
}
|
|
10648
10803
|
async getFeedback(messageId, projectIds) {
|
|
10649
|
-
this.checkFeedbackEnabled();
|
|
10804
|
+
await this.checkFeedbackEnabled();
|
|
10650
10805
|
let item = null;
|
|
10651
10806
|
if (this.provider === "postgresql" || this.provider === "pgvector") {
|
|
10652
10807
|
const pool = await this.getPGPool();
|
|
@@ -10682,7 +10837,7 @@ var DatabaseStorage = class {
|
|
|
10682
10837
|
return item;
|
|
10683
10838
|
}
|
|
10684
10839
|
async listFeedback(projectIds) {
|
|
10685
|
-
this.checkFeedbackEnabled();
|
|
10840
|
+
await this.checkFeedbackEnabled();
|
|
10686
10841
|
let raw = [];
|
|
10687
10842
|
if (this.provider === "postgresql" || this.provider === "pgvector") {
|
|
10688
10843
|
const pool = await this.getPGPool();
|
|
@@ -10832,12 +10987,23 @@ function resolveLicenseKey(req, config, bodyLicenseKey) {
|
|
|
10832
10987
|
var _a3;
|
|
10833
10988
|
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 || "";
|
|
10834
10989
|
}
|
|
10835
|
-
function enforceLicense(req, config, bodyLicenseKey) {
|
|
10990
|
+
async function enforceLicense(req, config, bodyLicenseKey) {
|
|
10836
10991
|
const rawKey = resolveLicenseKey(req, config, bodyLicenseKey);
|
|
10837
10992
|
const licenseKey = (rawKey || "").trim().replace(/^["']|["']$/g, "").trim();
|
|
10838
10993
|
const projectId = config.projectId || "";
|
|
10839
10994
|
try {
|
|
10840
|
-
|
|
10995
|
+
let payload;
|
|
10996
|
+
try {
|
|
10997
|
+
payload = await LicenseVerifier.verifyAsync(licenseKey, projectId);
|
|
10998
|
+
} catch (err) {
|
|
10999
|
+
return {
|
|
11000
|
+
ok: false,
|
|
11001
|
+
response: import_server.NextResponse.json(
|
|
11002
|
+
{ error: `License validation failed: ${err.message}` },
|
|
11003
|
+
{ status: 401 }
|
|
11004
|
+
)
|
|
11005
|
+
};
|
|
11006
|
+
}
|
|
10841
11007
|
return { ok: true, payload };
|
|
10842
11008
|
} catch (err) {
|
|
10843
11009
|
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.";
|
|
@@ -11012,7 +11178,7 @@ function createChatHandler(configOrPlugin, options) {
|
|
|
11012
11178
|
try {
|
|
11013
11179
|
const body = await req.json();
|
|
11014
11180
|
const bodyObj = body != null ? body : {};
|
|
11015
|
-
const licenseCheck = enforceLicense(req, config, bodyObj == null ? void 0 : bodyObj.licenseKey);
|
|
11181
|
+
const licenseCheck = await enforceLicense(req, config, bodyObj == null ? void 0 : bodyObj.licenseKey);
|
|
11016
11182
|
if (!licenseCheck.ok) return licenseCheck.response;
|
|
11017
11183
|
if (isFreeTier(licenseCheck.payload.tier)) {
|
|
11018
11184
|
const estimatedInputTokens = Math.ceil(
|
|
@@ -11106,7 +11272,7 @@ function createStreamHandler(configOrPlugin, options) {
|
|
|
11106
11272
|
});
|
|
11107
11273
|
}
|
|
11108
11274
|
const bodyObj = body != null ? body : {};
|
|
11109
|
-
const licenseCheck = enforceLicense(req, config, bodyObj == null ? void 0 : bodyObj.licenseKey);
|
|
11275
|
+
const licenseCheck = await enforceLicense(req, config, bodyObj == null ? void 0 : bodyObj.licenseKey);
|
|
11110
11276
|
if (!licenseCheck.ok) return licenseCheck.response;
|
|
11111
11277
|
if (isFreeTier(licenseCheck.payload.tier)) {
|
|
11112
11278
|
const estimatedInputTokens = Math.ceil(
|
|
@@ -11271,7 +11437,7 @@ function createIngestHandler(configOrPlugin, options) {
|
|
|
11271
11437
|
const config = plugin.getConfig();
|
|
11272
11438
|
try {
|
|
11273
11439
|
const body = await req.json();
|
|
11274
|
-
const licenseCheck = enforceLicense(req, config, body == null ? void 0 : body.licenseKey);
|
|
11440
|
+
const licenseCheck = await enforceLicense(req, config, body == null ? void 0 : body.licenseKey);
|
|
11275
11441
|
if (!licenseCheck.ok) return licenseCheck.response;
|
|
11276
11442
|
const { documents, namespace } = body;
|
|
11277
11443
|
if (!Array.isArray(documents) || documents.length === 0) {
|
|
@@ -11347,7 +11513,7 @@ function createLicenseHandler(configOrPlugin, options) {
|
|
|
11347
11513
|
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 || "";
|
|
11348
11514
|
const licenseKey = (rawKey || "").trim().replace(/^["']|["']$/g, "").trim();
|
|
11349
11515
|
const projectId = (body == null ? void 0 : body.projectId) || config.projectId || "";
|
|
11350
|
-
const payload = LicenseVerifier.
|
|
11516
|
+
const payload = await LicenseVerifier.verifyAsync(licenseKey, projectId);
|
|
11351
11517
|
return import_server.NextResponse.json({
|
|
11352
11518
|
valid: true,
|
|
11353
11519
|
licenseStatus: "ACTIVE",
|
|
@@ -11377,14 +11543,16 @@ function createUploadHandler(configOrPlugin, options) {
|
|
|
11377
11543
|
const plugin = getOrCreatePlugin(configOrPlugin);
|
|
11378
11544
|
const onAuthorize = options == null ? void 0 : options.onAuthorize;
|
|
11379
11545
|
return async function POST(req, context) {
|
|
11546
|
+
console.log("Upload handler invoked");
|
|
11380
11547
|
const authResult = await checkAuth(req, onAuthorize);
|
|
11381
11548
|
if (authResult) return authResult;
|
|
11382
11549
|
const config = plugin.getConfig();
|
|
11383
|
-
const licenseCheck = enforceLicense(req, config);
|
|
11550
|
+
const licenseCheck = await enforceLicense(req, config);
|
|
11384
11551
|
if (!licenseCheck.ok) return licenseCheck.response;
|
|
11385
11552
|
try {
|
|
11386
11553
|
const formData = await req.formData();
|
|
11387
11554
|
const files = formData.getAll("files");
|
|
11555
|
+
console.log("Files received for upload:", files.map((f) => f.name));
|
|
11388
11556
|
const namespace = formData.get("namespace") || void 0;
|
|
11389
11557
|
const dimensionRaw = formData.get("dimension");
|
|
11390
11558
|
const dimension = dimensionRaw ? parseInt(dimensionRaw, 10) : void 0;
|
|
@@ -11523,7 +11691,7 @@ function createSuggestionsHandler(configOrPlugin, options) {
|
|
|
11523
11691
|
const authResult = await checkAuth(req, onAuthorize);
|
|
11524
11692
|
if (authResult) return authResult;
|
|
11525
11693
|
const config = plugin.getConfig();
|
|
11526
|
-
const licenseCheck = enforceLicense(req, config);
|
|
11694
|
+
const licenseCheck = await enforceLicense(req, config);
|
|
11527
11695
|
if (!licenseCheck.ok) return licenseCheck.response;
|
|
11528
11696
|
let effectiveLicensePayload = licenseCheck.payload;
|
|
11529
11697
|
try {
|
|
@@ -11536,7 +11704,7 @@ function createSuggestionsHandler(configOrPlugin, options) {
|
|
|
11536
11704
|
namespace = body.namespace;
|
|
11537
11705
|
bodyLicenseKey = body.licenseKey;
|
|
11538
11706
|
if (bodyLicenseKey) {
|
|
11539
|
-
const recheck = enforceLicense(req, config, bodyLicenseKey);
|
|
11707
|
+
const recheck = await enforceLicense(req, config, bodyLicenseKey);
|
|
11540
11708
|
if (!recheck.ok) return recheck.response;
|
|
11541
11709
|
effectiveLicensePayload = recheck.payload;
|
|
11542
11710
|
}
|