@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/handlers/index.mjs
CHANGED
|
@@ -302,7 +302,7 @@ var init_package = __esm({
|
|
|
302
302
|
"package.json"() {
|
|
303
303
|
package_default = {
|
|
304
304
|
name: "@retrivora-ai/rag-engine",
|
|
305
|
-
version: "2.3.
|
|
305
|
+
version: "2.3.9",
|
|
306
306
|
description: "Retrivora AI is a plug-and-play AI engine for RAG chat experiences \u2014 generic vector DB + LLM provider, embeddable or standalone.",
|
|
307
307
|
author: "Abhinav Alkuchi",
|
|
308
308
|
license: "UNLICENSED",
|
|
@@ -488,10 +488,16 @@ var init_ConfigFetcher = __esm({
|
|
|
488
488
|
process.env.RETRIVORA_CONTROL_PLANE_URL,
|
|
489
489
|
process.env.NEXT_PUBLIC_RETRIVORA_CONTROL_PLANE_URL,
|
|
490
490
|
CONTROL_PLANE_URL
|
|
491
|
-
].filter((url) =>
|
|
491
|
+
].filter((url) => {
|
|
492
|
+
if (!url) return false;
|
|
493
|
+
const isEnvVar = url === process.env.RETRIVORA_CONTROL_PLANE_URL || url === process.env.NEXT_PUBLIC_RETRIVORA_CONTROL_PLANE_URL;
|
|
494
|
+
if (!isEnvVar && (url.includes("localhost") || url.includes("127.0.0.1"))) return false;
|
|
495
|
+
return true;
|
|
496
|
+
}).map((url) => url.replace(/\/$/, ""));
|
|
492
497
|
for (const baseUrl of controlPlaneUrls) {
|
|
493
498
|
try {
|
|
494
499
|
const url = `${baseUrl}/api/v1/config?projectId=${encodeURIComponent(projectId)}`;
|
|
500
|
+
console.log(`[ConfigFetcher] Fetching config from: ${url}`);
|
|
495
501
|
const res = await fetch(url, {
|
|
496
502
|
method: "GET",
|
|
497
503
|
headers: __spreadValues({
|
|
@@ -499,6 +505,10 @@ var init_ConfigFetcher = __esm({
|
|
|
499
505
|
"x-sdk-version": SDK_VERSION
|
|
500
506
|
}, licenseKey ? { "x-license-key": licenseKey } : {})
|
|
501
507
|
});
|
|
508
|
+
console.log(`[ConfigFetcher] Response status: ${res.status}`);
|
|
509
|
+
if (!res.ok) {
|
|
510
|
+
console.warn(`[ConfigFetcher] Error text: ${await res.text()}`);
|
|
511
|
+
}
|
|
502
512
|
if (res.ok) {
|
|
503
513
|
const data = await res.json();
|
|
504
514
|
if ((data == null ? void 0 : data.success) && (data == null ? void 0 : data.vectorDb)) {
|
|
@@ -509,8 +519,7 @@ var init_ConfigFetcher = __esm({
|
|
|
509
519
|
isActive: data.isActive,
|
|
510
520
|
expiresAt: data.expiresAt,
|
|
511
521
|
vectorDb: {
|
|
512
|
-
// apiKey
|
|
513
|
-
// The SDK uses local PINECONE_API_KEY if available.
|
|
522
|
+
// Fetch apiKey from credentials API if available, else fallback to empty
|
|
514
523
|
apiKey: data.vectorDb.apiKey || "",
|
|
515
524
|
indexName: data.vectorDb.indexName || "retrivora-free",
|
|
516
525
|
provider: data.vectorDb.provider || "pinecone",
|
|
@@ -542,6 +551,32 @@ var init_ConfigFetcher = __esm({
|
|
|
542
551
|
data.projectSettings || data.settings
|
|
543
552
|
)
|
|
544
553
|
};
|
|
554
|
+
if (licenseKey) {
|
|
555
|
+
try {
|
|
556
|
+
const credUrl = `${baseUrl}/api/v1/credentials`;
|
|
557
|
+
const credRes = await fetch(credUrl, {
|
|
558
|
+
method: "POST",
|
|
559
|
+
headers: {
|
|
560
|
+
"Content-Type": "application/json"
|
|
561
|
+
},
|
|
562
|
+
body: JSON.stringify({ licenseKey, projectId: fetchedProjectId })
|
|
563
|
+
});
|
|
564
|
+
if (credRes.ok) {
|
|
565
|
+
const credData = await credRes.json();
|
|
566
|
+
if ((credData == null ? void 0 : credData.success) && (credData == null ? void 0 : credData.credentials)) {
|
|
567
|
+
if (credData.credentials.pineconeApiKey && !config.vectorDb.apiKey) {
|
|
568
|
+
config.vectorDb.apiKey = credData.credentials.pineconeApiKey;
|
|
569
|
+
}
|
|
570
|
+
if (credData.credentials.litellmApiKey) {
|
|
571
|
+
config.llm.apiKey = credData.credentials.litellmApiKey;
|
|
572
|
+
config.embedding.apiKey = credData.credentials.litellmApiKey;
|
|
573
|
+
}
|
|
574
|
+
}
|
|
575
|
+
}
|
|
576
|
+
} catch (e) {
|
|
577
|
+
console.warn("[ConfigFetcher] Failed to fetch credentials:", e);
|
|
578
|
+
}
|
|
579
|
+
}
|
|
545
580
|
this.cache.set(cacheKey, { config, cachedAt: now });
|
|
546
581
|
return config;
|
|
547
582
|
}
|
|
@@ -581,6 +616,14 @@ var init_PineconeProvider = __esm({
|
|
|
581
616
|
const opts = config.options || {};
|
|
582
617
|
this.apiKey = opts.apiKey || process.env.PINECONE_API_KEY || "";
|
|
583
618
|
}
|
|
619
|
+
getControlPlaneUrl() {
|
|
620
|
+
const urls = [
|
|
621
|
+
process.env.RETRIVORA_CONTROL_PLANE_URL,
|
|
622
|
+
process.env.NEXT_PUBLIC_RETRIVORA_CONTROL_PLANE_URL,
|
|
623
|
+
"https://www.retrivora.com"
|
|
624
|
+
].filter((url) => Boolean(url));
|
|
625
|
+
return urls[0].replace(/\/$/, "");
|
|
626
|
+
}
|
|
584
627
|
static getValidator() {
|
|
585
628
|
return {
|
|
586
629
|
validate(config) {
|
|
@@ -644,6 +687,7 @@ var init_PineconeProvider = __esm({
|
|
|
644
687
|
let key = this.apiKey || process.env.PINECONE_API_KEY || "";
|
|
645
688
|
if (!key) {
|
|
646
689
|
const licenseKey = process.env.RETRIVORA_LICENSE_KEY || process.env.NEXT_PUBLIC_RETRIVORA_LICENSE_KEY;
|
|
690
|
+
this.licenseKey = licenseKey;
|
|
647
691
|
const jwtProjectId = (() => {
|
|
648
692
|
if (!licenseKey) return void 0;
|
|
649
693
|
try {
|
|
@@ -657,6 +701,7 @@ var init_PineconeProvider = __esm({
|
|
|
657
701
|
return void 0;
|
|
658
702
|
})();
|
|
659
703
|
const projectId = process.env.RAG_PROJECT_ID || process.env.NEXT_PUBLIC_RAG_PROJECT_ID || jwtProjectId || this.projectId || "default";
|
|
704
|
+
this.projectId = projectId;
|
|
660
705
|
const remoteConfig = await ConfigFetcher.fetchRemoteVectorConfig(projectId, licenseKey);
|
|
661
706
|
if (remoteConfig) {
|
|
662
707
|
if (remoteConfig.apiKey) {
|
|
@@ -702,19 +747,59 @@ var init_PineconeProvider = __esm({
|
|
|
702
747
|
return namespace ? idx.namespace(namespace) : idx.namespace("");
|
|
703
748
|
}
|
|
704
749
|
async upsert(doc, namespace) {
|
|
705
|
-
var _a3;
|
|
750
|
+
var _a3, _b;
|
|
751
|
+
if (!this.client) {
|
|
752
|
+
if (!this.licenseKey) throw new Error("[PineconeProvider] Cannot execute vector operation: Missing API key and License key.");
|
|
753
|
+
const res = await fetch(`${this.getControlPlaneUrl()}/api/v1/vectors/upsert`, {
|
|
754
|
+
method: "POST",
|
|
755
|
+
headers: { "Content-Type": "application/json", "x-license-key": this.licenseKey },
|
|
756
|
+
body: JSON.stringify({
|
|
757
|
+
projectId: this.projectId,
|
|
758
|
+
indexName: this.indexName,
|
|
759
|
+
namespace: namespace || this.projectId,
|
|
760
|
+
records: [{ id: String(doc.id), values: doc.vector, metadata: __spreadValues({ content: doc.content }, (_a3 = doc.metadata) != null ? _a3 : {}) }]
|
|
761
|
+
})
|
|
762
|
+
});
|
|
763
|
+
if (!res.ok) throw new Error(`[PineconeProvider] Proxy upsert failed: ${await res.text()}`);
|
|
764
|
+
return;
|
|
765
|
+
}
|
|
706
766
|
const targetIdx = await this.getActiveIndex(namespace);
|
|
707
767
|
await targetIdx.upsert({
|
|
708
768
|
records: [{
|
|
709
769
|
id: String(doc.id),
|
|
710
770
|
values: doc.vector,
|
|
711
|
-
metadata: __spreadValues({ content: doc.content }, (
|
|
771
|
+
metadata: __spreadValues({ content: doc.content }, (_b = doc.metadata) != null ? _b : {})
|
|
712
772
|
}]
|
|
713
773
|
});
|
|
714
774
|
}
|
|
715
775
|
async batchUpsert(docs, namespace) {
|
|
716
|
-
const targetIdx = await this.getActiveIndex(namespace);
|
|
717
776
|
const BATCH = 100;
|
|
777
|
+
if (!this.client) {
|
|
778
|
+
if (!this.licenseKey) throw new Error("[PineconeProvider] Cannot execute vector operation: Missing API key and License key.");
|
|
779
|
+
for (let i = 0; i < docs.length; i += BATCH) {
|
|
780
|
+
const records = docs.slice(i, i + BATCH).map((d) => {
|
|
781
|
+
var _a3;
|
|
782
|
+
return {
|
|
783
|
+
id: String(d.id),
|
|
784
|
+
values: d.vector,
|
|
785
|
+
metadata: __spreadValues({ content: d.content }, (_a3 = d.metadata) != null ? _a3 : {})
|
|
786
|
+
};
|
|
787
|
+
});
|
|
788
|
+
const res = await fetch(`${this.getControlPlaneUrl()}/api/v1/vectors/upsert`, {
|
|
789
|
+
method: "POST",
|
|
790
|
+
headers: { "Content-Type": "application/json", "x-license-key": this.licenseKey },
|
|
791
|
+
body: JSON.stringify({
|
|
792
|
+
projectId: this.projectId,
|
|
793
|
+
indexName: this.indexName,
|
|
794
|
+
namespace: namespace || this.projectId,
|
|
795
|
+
records
|
|
796
|
+
})
|
|
797
|
+
});
|
|
798
|
+
if (!res.ok) throw new Error(`[PineconeProvider] Proxy batch upsert failed: ${await res.text()}`);
|
|
799
|
+
}
|
|
800
|
+
return;
|
|
801
|
+
}
|
|
802
|
+
const targetIdx = await this.getActiveIndex(namespace);
|
|
718
803
|
for (let i = 0; i < docs.length; i += BATCH) {
|
|
719
804
|
const records = docs.slice(i, i + BATCH).map((d) => {
|
|
720
805
|
var _a3;
|
|
@@ -728,20 +813,46 @@ var init_PineconeProvider = __esm({
|
|
|
728
813
|
}
|
|
729
814
|
}
|
|
730
815
|
async query(vector, topK, namespace, filter) {
|
|
731
|
-
var _a3;
|
|
732
|
-
const targetIdx = await this.getActiveIndex(namespace);
|
|
816
|
+
var _a3, _b;
|
|
733
817
|
const pineconeFilter = this.sanitizeFilter(filter);
|
|
818
|
+
if (!this.client) {
|
|
819
|
+
if (!this.licenseKey) throw new Error("[PineconeProvider] Cannot execute vector operation: Missing API key and License key.");
|
|
820
|
+
const res = await fetch(`${this.getControlPlaneUrl()}/api/v1/vectors/query`, {
|
|
821
|
+
method: "POST",
|
|
822
|
+
headers: { "Content-Type": "application/json", "x-license-key": this.licenseKey },
|
|
823
|
+
body: JSON.stringify({
|
|
824
|
+
projectId: this.projectId,
|
|
825
|
+
indexName: this.indexName,
|
|
826
|
+
namespace: namespace || this.projectId,
|
|
827
|
+
vector,
|
|
828
|
+
topK,
|
|
829
|
+
filter: pineconeFilter
|
|
830
|
+
})
|
|
831
|
+
});
|
|
832
|
+
if (!res.ok) throw new Error(`[PineconeProvider] Proxy query failed: ${await res.text()}`);
|
|
833
|
+
const data = await res.json();
|
|
834
|
+
return ((_a3 = data.matches) != null ? _a3 : []).map((m) => {
|
|
835
|
+
var _a4, _b2;
|
|
836
|
+
return {
|
|
837
|
+
id: m.id,
|
|
838
|
+
score: (_a4 = m.score) != null ? _a4 : 0,
|
|
839
|
+
content: ((_b2 = m.metadata) == null ? void 0 : _b2.content) || "",
|
|
840
|
+
metadata: m.metadata
|
|
841
|
+
};
|
|
842
|
+
});
|
|
843
|
+
}
|
|
844
|
+
const targetIdx = await this.getActiveIndex(namespace);
|
|
734
845
|
const result = await targetIdx.query(__spreadValues({
|
|
735
846
|
vector,
|
|
736
847
|
topK,
|
|
737
848
|
includeMetadata: true
|
|
738
849
|
}, Object.keys(pineconeFilter).length > 0 ? { filter: pineconeFilter } : {}));
|
|
739
|
-
return ((
|
|
740
|
-
var _a4,
|
|
850
|
+
return ((_b = result.matches) != null ? _b : []).map((m) => {
|
|
851
|
+
var _a4, _b2;
|
|
741
852
|
return {
|
|
742
853
|
id: m.id,
|
|
743
854
|
score: (_a4 = m.score) != null ? _a4 : 0,
|
|
744
|
-
content: ((
|
|
855
|
+
content: ((_b2 = m.metadata) == null ? void 0 : _b2.content) || "",
|
|
745
856
|
metadata: m.metadata
|
|
746
857
|
};
|
|
747
858
|
});
|
|
@@ -1720,7 +1831,7 @@ __export(QdrantProvider_exports, {
|
|
|
1720
1831
|
QdrantProvider: () => QdrantProvider
|
|
1721
1832
|
});
|
|
1722
1833
|
import axios4 from "axios";
|
|
1723
|
-
import
|
|
1834
|
+
import crypto from "crypto";
|
|
1724
1835
|
var QdrantProvider;
|
|
1725
1836
|
var init_QdrantProvider = __esm({
|
|
1726
1837
|
"src/providers/vectordb/QdrantProvider.ts"() {
|
|
@@ -1952,7 +2063,7 @@ var init_QdrantProvider = __esm({
|
|
|
1952
2063
|
if (typeof id === "number") return id;
|
|
1953
2064
|
const uuidRegex = /^[0-9a-f]{8}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{12}$/i;
|
|
1954
2065
|
if (uuidRegex.test(id)) return id.toLowerCase();
|
|
1955
|
-
const hash =
|
|
2066
|
+
const hash = crypto.createHash("md5").update(id).digest("hex");
|
|
1956
2067
|
return `${hash.slice(0, 8)}-${hash.slice(8, 12)}-${hash.slice(12, 16)}-${hash.slice(16, 20)}-${hash.slice(20, 32)}`;
|
|
1957
2068
|
}
|
|
1958
2069
|
async disconnect() {
|
|
@@ -2537,9 +2648,6 @@ import { NextResponse } from "next/server";
|
|
|
2537
2648
|
// src/core/ConfigResolver.ts
|
|
2538
2649
|
init_templateUtils();
|
|
2539
2650
|
|
|
2540
|
-
// src/core/LicenseVerifier.ts
|
|
2541
|
-
import * as crypto from "crypto";
|
|
2542
|
-
|
|
2543
2651
|
// src/exceptions/index.ts
|
|
2544
2652
|
var RetrivoraError = class extends Error {
|
|
2545
2653
|
constructor(message, code, details) {
|
|
@@ -2615,29 +2723,18 @@ function wrapError(err, defaultCode, defaultMessage) {
|
|
|
2615
2723
|
}
|
|
2616
2724
|
|
|
2617
2725
|
// src/core/LicenseVerifier.ts
|
|
2618
|
-
var
|
|
2726
|
+
var _LicenseVerifier = class _LicenseVerifier {
|
|
2727
|
+
// Cache verified license for 5 minutes
|
|
2619
2728
|
/**
|
|
2620
|
-
*
|
|
2729
|
+
* Validates the license key asynchronously by calling the Retrivora backend.
|
|
2621
2730
|
*
|
|
2622
2731
|
* @param licenseKey - Base64url signed JWT license key.
|
|
2623
2732
|
* @param currentProjectId - Project namespace ID.
|
|
2624
|
-
* @param
|
|
2733
|
+
* @param provider - Optional provider for tier checks.
|
|
2625
2734
|
*/
|
|
2626
|
-
static
|
|
2735
|
+
static async verifyAsync(licenseKey, currentProjectId, provider) {
|
|
2627
2736
|
const isProduction = process.env.NODE_ENV === "production";
|
|
2628
2737
|
const now = Date.now();
|
|
2629
|
-
if (licenseKey) {
|
|
2630
|
-
const cacheKey = `${licenseKey}:${currentProjectId}:${provider || ""}:${publicKeyOverride || ""}`;
|
|
2631
|
-
const cached = this.cache.get(cacheKey);
|
|
2632
|
-
if (cached && now - cached.cachedAt < this.CACHE_TTL_MS) {
|
|
2633
|
-
const currentTimestampSec = Math.floor(now / 1e3);
|
|
2634
|
-
if (cached.payload.expiresAt && currentTimestampSec > cached.payload.expiresAt) {
|
|
2635
|
-
this.cache.delete(cacheKey);
|
|
2636
|
-
} else {
|
|
2637
|
-
return cached.payload;
|
|
2638
|
-
}
|
|
2639
|
-
}
|
|
2640
|
-
}
|
|
2641
2738
|
if (!licenseKey) {
|
|
2642
2739
|
if (isProduction) {
|
|
2643
2740
|
throw new ConfigurationException(
|
|
@@ -2654,52 +2751,61 @@ var LicenseVerifier = class {
|
|
|
2654
2751
|
tier: "hobby"
|
|
2655
2752
|
};
|
|
2656
2753
|
}
|
|
2657
|
-
|
|
2658
|
-
|
|
2659
|
-
|
|
2660
|
-
const
|
|
2661
|
-
if (
|
|
2662
|
-
|
|
2663
|
-
}
|
|
2664
|
-
|
|
2665
|
-
const dataToVerify = `${headerB64}.${payloadB64}`;
|
|
2666
|
-
const publicKey = publicKeyOverride != null ? publicKeyOverride : this.PUBLIC_KEY;
|
|
2667
|
-
const signature = Buffer.from(signatureB64, "base64url");
|
|
2668
|
-
const data = Buffer.from(dataToVerify);
|
|
2669
|
-
const isValid = crypto.verify(
|
|
2670
|
-
"sha256",
|
|
2671
|
-
data,
|
|
2672
|
-
publicKey,
|
|
2673
|
-
signature
|
|
2674
|
-
);
|
|
2675
|
-
if (!isValid) {
|
|
2676
|
-
throw new Error("Signature verification failed.");
|
|
2754
|
+
const cacheKey = `${licenseKey}:${currentProjectId}:${provider || ""}`;
|
|
2755
|
+
const cached = this.cache.get(cacheKey);
|
|
2756
|
+
if (cached && now - cached.cachedAt < this.CACHE_TTL_MS) {
|
|
2757
|
+
const currentTimestampSec = Math.floor(now / 1e3);
|
|
2758
|
+
if (cached.payload.expiresAt && currentTimestampSec > cached.payload.expiresAt) {
|
|
2759
|
+
this.cache.delete(cacheKey);
|
|
2760
|
+
} else {
|
|
2761
|
+
return cached.payload;
|
|
2677
2762
|
}
|
|
2678
|
-
|
|
2679
|
-
|
|
2680
|
-
|
|
2681
|
-
if (
|
|
2682
|
-
|
|
2763
|
+
}
|
|
2764
|
+
try {
|
|
2765
|
+
let baseUrl = typeof process !== "undefined" && process.env.RETRIVORA_CONTROL_PLANE_URL ? process.env.RETRIVORA_CONTROL_PLANE_URL : "https://retrivora.com";
|
|
2766
|
+
if (typeof process !== "undefined" && process.env.TELEMETRY_URL) {
|
|
2767
|
+
baseUrl = process.env.TELEMETRY_URL.replace(/\/api\/telemetry\/?$/, "");
|
|
2683
2768
|
}
|
|
2684
|
-
const
|
|
2685
|
-
|
|
2686
|
-
|
|
2687
|
-
|
|
2688
|
-
|
|
2769
|
+
const endpoint = `${baseUrl}/api/v1/license/validate`;
|
|
2770
|
+
const response = await fetch(endpoint, {
|
|
2771
|
+
method: "POST",
|
|
2772
|
+
headers: {
|
|
2773
|
+
"Content-Type": "application/json",
|
|
2774
|
+
"x-license-key": licenseKey
|
|
2775
|
+
},
|
|
2776
|
+
body: JSON.stringify({
|
|
2777
|
+
licenseKey,
|
|
2778
|
+
projectId: currentProjectId,
|
|
2779
|
+
provider
|
|
2780
|
+
})
|
|
2781
|
+
});
|
|
2782
|
+
if (!response.ok) {
|
|
2783
|
+
let errMessage = `HTTP ${response.status}`;
|
|
2784
|
+
try {
|
|
2785
|
+
const body = await response.json();
|
|
2786
|
+
if (body.message) errMessage = body.message;
|
|
2787
|
+
} catch (e) {
|
|
2788
|
+
}
|
|
2789
|
+
throw new Error(errMessage);
|
|
2689
2790
|
}
|
|
2690
|
-
|
|
2691
|
-
|
|
2791
|
+
const data = await response.json();
|
|
2792
|
+
if (!data.valid) {
|
|
2793
|
+
throw new Error(data.message || "License validation failed by server.");
|
|
2692
2794
|
}
|
|
2693
|
-
|
|
2694
|
-
if (
|
|
2695
|
-
|
|
2696
|
-
`License key has expired. Expiration: ${new Date(
|
|
2697
|
-
payload.expiresAt * 1e3
|
|
2698
|
-
).toDateString()}`
|
|
2699
|
-
);
|
|
2795
|
+
let expiresAtNum = Math.floor(Date.now() / 1e3) + 100 * 365 * 24 * 60 * 60;
|
|
2796
|
+
if (data.expiresAt) {
|
|
2797
|
+
expiresAtNum = Math.floor(new Date(data.expiresAt).getTime() / 1e3);
|
|
2700
2798
|
}
|
|
2799
|
+
const tier = _LicenseVerifier.extractTier(licenseKey);
|
|
2800
|
+
const payload = {
|
|
2801
|
+
projectId: currentProjectId,
|
|
2802
|
+
expiresAt: expiresAtNum,
|
|
2803
|
+
tier,
|
|
2804
|
+
licenseStatus: data.licenseStatus,
|
|
2805
|
+
minimumSupportedVersion: data.minimumSupportedVersion,
|
|
2806
|
+
forceUpgrade: data.forceUpgrade
|
|
2807
|
+
};
|
|
2701
2808
|
if (isProduction && provider) {
|
|
2702
|
-
const tier = (payload.tier || "").toLowerCase();
|
|
2703
2809
|
const normalizedProvider = provider.toLowerCase();
|
|
2704
2810
|
if (tier === "hobby") {
|
|
2705
2811
|
const allowedHobby = ["postgresql", "pgvector", "supabase"];
|
|
@@ -2727,15 +2833,12 @@ var LicenseVerifier = class {
|
|
|
2727
2833
|
}
|
|
2728
2834
|
}
|
|
2729
2835
|
}
|
|
2730
|
-
|
|
2731
|
-
const cacheKey = `${licenseKey}:${currentProjectId}:${provider || ""}:${publicKeyOverride || ""}`;
|
|
2732
|
-
this.cache.set(cacheKey, { payload, cachedAt: now });
|
|
2733
|
-
}
|
|
2836
|
+
this.cache.set(cacheKey, { payload, cachedAt: now });
|
|
2734
2837
|
return payload;
|
|
2735
2838
|
} catch (err) {
|
|
2736
2839
|
const message = err instanceof Error ? err.message : String(err);
|
|
2737
2840
|
throw new ConfigurationException(
|
|
2738
|
-
`[Retrivora SDK] License key validation failed: ${message}`
|
|
2841
|
+
`[Retrivora SDK] License key validation failed via API: ${message}`
|
|
2739
2842
|
);
|
|
2740
2843
|
}
|
|
2741
2844
|
}
|
|
@@ -2804,23 +2907,25 @@ var LicenseVerifier = class {
|
|
|
2804
2907
|
}
|
|
2805
2908
|
}
|
|
2806
2909
|
}
|
|
2910
|
+
static extractTier(licenseKey) {
|
|
2911
|
+
if (!licenseKey) return "hobby";
|
|
2912
|
+
try {
|
|
2913
|
+
const sanitizedKey = licenseKey.trim().replace(/^["']|["']$/g, "").trim();
|
|
2914
|
+
const rawToken = sanitizedKey.replace(/^rtv_/i, "").trim();
|
|
2915
|
+
const parts = rawToken.split(".");
|
|
2916
|
+
if (parts.length === 3) {
|
|
2917
|
+
const decodedPayload = JSON.parse(Buffer.from(parts[1], "base64url").toString("utf8"));
|
|
2918
|
+
if (decodedPayload.tier) return decodedPayload.tier;
|
|
2919
|
+
}
|
|
2920
|
+
} catch (e) {
|
|
2921
|
+
}
|
|
2922
|
+
return "hobby";
|
|
2923
|
+
}
|
|
2807
2924
|
};
|
|
2808
|
-
//
|
|
2809
|
-
|
|
2810
|
-
|
|
2811
|
-
|
|
2812
|
-
// Retrivora's Public Key used to verify the license key signature.
|
|
2813
|
-
// In production, this matches the private key held by Retrivora SaaS.
|
|
2814
|
-
// Rotate this key only when the signing private key is replaced.
|
|
2815
|
-
LicenseVerifier.PUBLIC_KEY = `-----BEGIN PUBLIC KEY-----
|
|
2816
|
-
MIIBIjANBgkqhkiG9w0BAQEFAAOCAQ8AMIIBCgKCAQEAyKvvOSYdCimG3b236ebV
|
|
2817
|
-
jpG88xQiU8dSiaMahtBJDf4w0AewRj7hMNgmeZ1wyTOj8kVgeGBOolp1Z0QmTr6O
|
|
2818
|
-
Tj4EDQ/zjsg12If7hSf3NiwLHCYmMLslyK0aaP6PQoTrYkBv3GNdkMecrIjKCijb
|
|
2819
|
-
6VvDLLF3X696melTVM0z/d2e50BW2AlRw/rf1EqYi10d0BcPo5zje0XETr/WGmqu
|
|
2820
|
-
sDiXtsP5MlwkL9X7RQY2uovRa+l/vOAqAfdmJ+OzXuk5P7mDUPb+gCtKnoDbb1tr
|
|
2821
|
-
6UAu733dkUnetAcMqyT3fNPBLO66DCc6m9rGCYYAaG7piMEDwG0/ZySZBFbgllJc
|
|
2822
|
-
6QIDAQAB
|
|
2823
|
-
-----END PUBLIC KEY-----`;
|
|
2925
|
+
// In-memory cache to save network overhead on hot paths.
|
|
2926
|
+
_LicenseVerifier.cache = /* @__PURE__ */ new Map();
|
|
2927
|
+
_LicenseVerifier.CACHE_TTL_MS = 5 * 60 * 1e3;
|
|
2928
|
+
var LicenseVerifier = _LicenseVerifier;
|
|
2824
2929
|
|
|
2825
2930
|
// src/config/constants.ts
|
|
2826
2931
|
var VECTOR_DB_PROVIDERS = [
|
|
@@ -2892,7 +2997,7 @@ function readEnum(env, name, fallback, allowed) {
|
|
|
2892
2997
|
throw new Error(`[getRagConfig] ${name} must be one of: ${allowed.join(", ")}`);
|
|
2893
2998
|
}
|
|
2894
2999
|
function getEnvConfig(env = process.env, base) {
|
|
2895
|
-
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;
|
|
3000
|
+
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;
|
|
2896
3001
|
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;
|
|
2897
3002
|
const jwtProjectId = (() => {
|
|
2898
3003
|
if (!licenseKey) return void 0;
|
|
@@ -2977,8 +3082,7 @@ function getEnvConfig(env = process.env, base) {
|
|
|
2977
3082
|
const isFreeTier2 = (() => {
|
|
2978
3083
|
if (!licenseKey) return true;
|
|
2979
3084
|
try {
|
|
2980
|
-
const
|
|
2981
|
-
const tier = (payload.tier || "").toLowerCase();
|
|
3085
|
+
const tier = LicenseVerifier.extractTier(licenseKey).toLowerCase();
|
|
2982
3086
|
return tier === "free_trial" || tier === "free_tier" || tier === "free" || tier === "hobby";
|
|
2983
3087
|
} catch (e) {
|
|
2984
3088
|
return true;
|
|
@@ -2986,14 +3090,15 @@ function getEnvConfig(env = process.env, base) {
|
|
|
2986
3090
|
})();
|
|
2987
3091
|
const tierBasedLLMModel = isFreeTier2 ? "llama-3.1-8b-instant" : "llama-3.3-70b-versatile";
|
|
2988
3092
|
const tierBasedEmbeddingModel = isFreeTier2 ? "text-embedding-004" : "text-embedding-004";
|
|
2989
|
-
const
|
|
3093
|
+
const controlPlaneUrl = (_qa = readString(env, "RETRIVORA_CONTROL_PLANE_URL")) != null ? _qa : readString(env, "NEXT_PUBLIC_RETRIVORA_CONTROL_PLANE_URL");
|
|
3094
|
+
const defaultGatewayUrl = controlPlaneUrl ? `${controlPlaneUrl.replace(/\/$/, "")}/api/v1` : "https://llm.retrivora.com/api/v1";
|
|
2990
3095
|
const rt = _runtimeConfig;
|
|
2991
3096
|
const defaultLlmProvider = "universal_rest";
|
|
2992
|
-
const llmProvider = (
|
|
2993
|
-
const llmBaseUrl = (
|
|
2994
|
-
const llmModel = (
|
|
2995
|
-
const llmApiKey = (
|
|
2996
|
-
const llmProfile = (
|
|
3097
|
+
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;
|
|
3098
|
+
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;
|
|
3099
|
+
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;
|
|
3100
|
+
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;
|
|
3101
|
+
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";
|
|
2997
3102
|
console.log("[serverConfig] \u{1F527} LLM Configuration:", {
|
|
2998
3103
|
baseUrl: llmBaseUrl,
|
|
2999
3104
|
model: llmModel,
|
|
@@ -3002,17 +3107,24 @@ function getEnvConfig(env = process.env, base) {
|
|
|
3002
3107
|
source: (rt == null ? void 0 : rt.llmModel) ? "runtime-injected" : "env/fallback"
|
|
3003
3108
|
});
|
|
3004
3109
|
const defaultEmbeddingProvider = "universal_rest";
|
|
3005
|
-
const embeddingProvider = (
|
|
3006
|
-
const embeddingBaseUrl = (_Ta = (_Sa = (_Ra = (
|
|
3007
|
-
const embeddingModel = (
|
|
3008
|
-
const embeddingApiKey = (
|
|
3009
|
-
const embeddingProfile = (
|
|
3110
|
+
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;
|
|
3111
|
+
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;
|
|
3112
|
+
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;
|
|
3113
|
+
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;
|
|
3114
|
+
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";
|
|
3115
|
+
console.log("[serverConfig] \u{1F527} Embedding Configuration:", {
|
|
3116
|
+
baseUrl: embeddingBaseUrl,
|
|
3117
|
+
model: embeddingModel,
|
|
3118
|
+
provider: embeddingProvider,
|
|
3119
|
+
hasApiKey: !!embeddingApiKey,
|
|
3120
|
+
source: (rt == null ? void 0 : rt.embeddingModel) ? "runtime-injected" : "env/fallback"
|
|
3121
|
+
});
|
|
3010
3122
|
return __spreadProps(__spreadValues({
|
|
3011
3123
|
projectId,
|
|
3012
3124
|
licenseKey,
|
|
3013
3125
|
vectorDb: {
|
|
3014
3126
|
provider: vectorProvider,
|
|
3015
|
-
indexName: (
|
|
3127
|
+
indexName: (_gb = (_fb = readString(env, "VECTOR_DB_INDEX")) != null ? _fb : vectorDbOptions.indexName) != null ? _gb : "rag-index",
|
|
3016
3128
|
options: vectorDbOptions
|
|
3017
3129
|
},
|
|
3018
3130
|
llm: {
|
|
@@ -3042,30 +3154,30 @@ function getEnvConfig(env = process.env, base) {
|
|
|
3042
3154
|
}
|
|
3043
3155
|
},
|
|
3044
3156
|
ui: {
|
|
3045
|
-
title: (
|
|
3046
|
-
subtitle: (
|
|
3047
|
-
primaryColor: (
|
|
3048
|
-
accentColor: (
|
|
3049
|
-
logoUrl: (
|
|
3050
|
-
placeholder: (
|
|
3051
|
-
showSources: ((
|
|
3052
|
-
welcomeMessage: (
|
|
3053
|
-
visualStyle: (
|
|
3054
|
-
borderRadius: (
|
|
3055
|
-
allowUpload: ((
|
|
3157
|
+
title: (_ib = (_hb = readString(env, "NEXT_PUBLIC_UI_TITLE")) != null ? _hb : readString(env, "UI_TITLE")) != null ? _ib : "AI Assistant",
|
|
3158
|
+
subtitle: (_kb = (_jb = readString(env, "NEXT_PUBLIC_UI_SUBTITLE")) != null ? _jb : readString(env, "UI_SUBTITLE")) != null ? _kb : "Powered by RAG",
|
|
3159
|
+
primaryColor: (_mb = (_lb = readString(env, "NEXT_PUBLIC_PRIMARY_COLOR")) != null ? _lb : readString(env, "UI_PRIMARY_COLOR")) != null ? _mb : "#10b981",
|
|
3160
|
+
accentColor: (_ob = (_nb = readString(env, "NEXT_PUBLIC_ACCENT_COLOR")) != null ? _nb : readString(env, "UI_ACCENT_COLOR")) != null ? _ob : "#3b82f6",
|
|
3161
|
+
logoUrl: (_pb = readString(env, "NEXT_PUBLIC_LOGO_URL")) != null ? _pb : readString(env, "UI_LOGO_URL"),
|
|
3162
|
+
placeholder: (_rb = (_qb = readString(env, "NEXT_PUBLIC_PLACEHOLDER")) != null ? _qb : readString(env, "UI_PLACEHOLDER")) != null ? _rb : "Ask me anything\u2026",
|
|
3163
|
+
showSources: ((_tb = (_sb = readString(env, "NEXT_PUBLIC_SHOW_SOURCES")) != null ? _sb : readString(env, "UI_SHOW_SOURCES")) != null ? _tb : "true") !== "false",
|
|
3164
|
+
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.",
|
|
3165
|
+
visualStyle: (_xb = (_wb = readString(env, "NEXT_PUBLIC_UI_VISUAL_STYLE")) != null ? _wb : readString(env, "UI_VISUAL_STYLE")) != null ? _xb : "glass",
|
|
3166
|
+
borderRadius: (_zb = (_yb = readString(env, "NEXT_PUBLIC_UI_BORDER_RADIUS")) != null ? _yb : readString(env, "UI_BORDER_RADIUS")) != null ? _zb : "xl",
|
|
3167
|
+
allowUpload: ((_Bb = (_Ab = readString(env, "NEXT_PUBLIC_ALLOW_UPLOAD")) != null ? _Ab : readString(env, "UI_ALLOW_UPLOAD")) != null ? _Bb : "false") === "true"
|
|
3056
3168
|
},
|
|
3057
3169
|
rag: {
|
|
3058
3170
|
topK: readNumber(env, "RAG_TOP_K", 5),
|
|
3059
3171
|
scoreThreshold: readNumber(env, "RAG_SCORE_THRESHOLD", 0),
|
|
3060
3172
|
chunkSize: readNumber(env, "RAG_CHUNK_SIZE", 1e3),
|
|
3061
3173
|
chunkOverlap: readNumber(env, "RAG_CHUNK_OVERLAP", 200),
|
|
3062
|
-
filterableFields: (
|
|
3174
|
+
filterableFields: (_Cb = readString(env, "RAG_FILTERABLE_FIELDS")) == null ? void 0 : _Cb.split(",").map((f) => f.trim()),
|
|
3063
3175
|
// Query pipeline toggles — read from .env.local
|
|
3064
3176
|
useQueryTransformation: readString(env, "RAG_USE_QUERY_TRANSFORMATION") === "true",
|
|
3065
3177
|
useReranking: readString(env, "RAG_USE_RERANKING") === "true",
|
|
3066
3178
|
useGraphRetrieval: readString(env, "RAG_USE_GRAPH_RETRIEVAL") === "true",
|
|
3067
|
-
architecture: (
|
|
3068
|
-
chunkingStrategy: (
|
|
3179
|
+
architecture: (_Db = readString(env, "RAG_ARCHITECTURE")) != null ? _Db : "simple",
|
|
3180
|
+
chunkingStrategy: (_Eb = readString(env, "RAG_CHUNKING_STRATEGY")) != null ? _Eb : "recursive",
|
|
3069
3181
|
uiMapping: (() => {
|
|
3070
3182
|
const raw = readString(env, "RAG_UI_MAPPING");
|
|
3071
3183
|
if (!raw) return void 0;
|
|
@@ -3078,7 +3190,7 @@ function getEnvConfig(env = process.env, base) {
|
|
|
3078
3190
|
},
|
|
3079
3191
|
telemetry: {
|
|
3080
3192
|
enabled: telemetryEnabled,
|
|
3081
|
-
url: (
|
|
3193
|
+
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"
|
|
3082
3194
|
}
|
|
3083
3195
|
}, readString(env, "GRAPH_DB_PROVIDER") ? {
|
|
3084
3196
|
graphDb: {
|
|
@@ -4389,6 +4501,12 @@ var UniversalLLMAdapter = class {
|
|
|
4389
4501
|
this.resolvedHeaders = __spreadValues(__spreadValues({
|
|
4390
4502
|
"Content-Type": "application/json"
|
|
4391
4503
|
}, config.apiKey ? { Authorization: `Bearer ${config.apiKey}` } : {}), this.opts.headers || {});
|
|
4504
|
+
console.log("[UniversalLLMAdapter] Initialized with:", {
|
|
4505
|
+
model: this.model,
|
|
4506
|
+
baseUrl: this.baseUrl,
|
|
4507
|
+
hasApiKey: !!this.apiKey,
|
|
4508
|
+
apiKeyPrefix: this.apiKey ? `${this.apiKey.slice(0, 12)}...` : void 0
|
|
4509
|
+
});
|
|
4392
4510
|
this.http = axios2.create({
|
|
4393
4511
|
baseURL: this.baseUrl,
|
|
4394
4512
|
headers: this.resolvedHeaders,
|
|
@@ -4601,14 +4719,21 @@ ${context != null ? context : "None"}` },
|
|
|
4601
4719
|
});
|
|
4602
4720
|
}
|
|
4603
4721
|
async embed(text) {
|
|
4604
|
-
var _a3, _b, _c, _d, _e, _f, _g2;
|
|
4722
|
+
var _a3, _b, _c, _d, _e, _f, _g2, _h;
|
|
4605
4723
|
const path2 = (_a3 = this.opts.embedPath) != null ? _a3 : "/embeddings";
|
|
4606
4724
|
const payload = this.opts.embedPayloadTemplate ? buildPayload(this.opts.embedPayloadTemplate, { input: text, model: this.model }) : { input: text, model: this.model };
|
|
4607
4725
|
try {
|
|
4726
|
+
console.log(`[UniversalLLMAdapter] Posting to embedding endpoint: ${this.baseUrl}${path2}`, {
|
|
4727
|
+
model: this.model,
|
|
4728
|
+
inputLength: typeof text === "string" ? text.length : "unknown"
|
|
4729
|
+
});
|
|
4608
4730
|
const { data } = await this.http.post(path2, payload);
|
|
4609
4731
|
const extractPath = (_b = this.opts.embedExtractPath) != null ? _b : "data[0].embedding";
|
|
4610
4732
|
const vector = resolvePath(data, extractPath);
|
|
4611
|
-
if (Array.isArray(vector))
|
|
4733
|
+
if (Array.isArray(vector)) {
|
|
4734
|
+
console.log(`[UniversalLLMAdapter] Embedding HTTP request successful. Vector size: ${vector.length}`);
|
|
4735
|
+
return vector;
|
|
4736
|
+
}
|
|
4612
4737
|
console.warn(
|
|
4613
4738
|
`[UniversalLLMAdapter] Embedding API returned unexpected format for path '${extractPath}'. Response:`,
|
|
4614
4739
|
data
|
|
@@ -4616,14 +4741,14 @@ ${context != null ? context : "None"}` },
|
|
|
4616
4741
|
} catch (err) {
|
|
4617
4742
|
console.warn(
|
|
4618
4743
|
`[UniversalLLMAdapter] HTTP embedding request failed: ${(err == null ? void 0 : err.message) || err}`,
|
|
4619
|
-
{ path: path2, model: this.model }
|
|
4744
|
+
{ path: path2, model: this.model, response: (_c = err == null ? void 0 : err.response) == null ? void 0 : _c.data }
|
|
4620
4745
|
);
|
|
4621
4746
|
const _g3 = globalThis;
|
|
4622
4747
|
const dispatchEmbed = _g3.__retrivoraDispatchEmbedding;
|
|
4623
4748
|
if (typeof dispatchEmbed === "function") {
|
|
4624
4749
|
try {
|
|
4625
4750
|
const res = await dispatchEmbed({ input: text, model: this.model }, this.apiKey);
|
|
4626
|
-
if ((
|
|
4751
|
+
if ((_e = (_d = res == null ? void 0 : res.data) == null ? void 0 : _d[0]) == null ? void 0 : _e.embedding) {
|
|
4627
4752
|
return res.data[0].embedding;
|
|
4628
4753
|
}
|
|
4629
4754
|
} catch (dispatchErr) {
|
|
@@ -4632,10 +4757,12 @@ ${context != null ? context : "None"}` },
|
|
|
4632
4757
|
}
|
|
4633
4758
|
}
|
|
4634
4759
|
try {
|
|
4760
|
+
console.log(`[UniversalLLMAdapter] Retrying embedding request to: ${this.baseUrl}${path2}`);
|
|
4635
4761
|
const { data } = await this.http.post(path2, payload);
|
|
4636
|
-
const extractPath = (
|
|
4762
|
+
const extractPath = (_f = this.opts.embedExtractPath) != null ? _f : "data[0].embedding";
|
|
4637
4763
|
const vector = resolvePath(data, extractPath);
|
|
4638
4764
|
if (Array.isArray(vector)) {
|
|
4765
|
+
console.log(`[UniversalLLMAdapter] Retry embedding HTTP request successful. Vector size: ${vector.length}`);
|
|
4639
4766
|
return vector;
|
|
4640
4767
|
}
|
|
4641
4768
|
console.error(
|
|
@@ -4648,7 +4775,7 @@ ${context != null ? context : "None"}` },
|
|
|
4648
4775
|
} catch (err) {
|
|
4649
4776
|
console.error(
|
|
4650
4777
|
`[UniversalLLMAdapter] Both embedding attempts failed. Path: ${path2}, Model: ${this.model}`,
|
|
4651
|
-
{ error: err == null ? void 0 : err.message, statusCode: (
|
|
4778
|
+
{ 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 }
|
|
4652
4779
|
);
|
|
4653
4780
|
throw new Error(
|
|
4654
4781
|
`[UniversalLLMAdapter] Failed to generate embedding after 2 attempts: ${(err == null ? void 0 : err.message) || err}`
|
|
@@ -10053,7 +10180,7 @@ var VectorPlugin = class {
|
|
|
10053
10180
|
this.validationPromise = (async () => {
|
|
10054
10181
|
var _a3;
|
|
10055
10182
|
await ConfigValidator.validateAndThrow(resolvedConfig);
|
|
10056
|
-
LicenseVerifier.
|
|
10183
|
+
await LicenseVerifier.verifyAsync(
|
|
10057
10184
|
resolvedConfig.licenseKey,
|
|
10058
10185
|
resolvedConfig.projectId,
|
|
10059
10186
|
(_a3 = resolvedConfig.vectorDb) == null ? void 0 : _a3.provider
|
|
@@ -10326,7 +10453,7 @@ var DatabaseStorage = class {
|
|
|
10326
10453
|
* In non-production (development / test) environments this is a complete no-op —
|
|
10327
10454
|
* all History and Feedback features are freely accessible for local development.
|
|
10328
10455
|
*/
|
|
10329
|
-
checkPremiumSubscription() {
|
|
10456
|
+
async checkPremiumSubscription() {
|
|
10330
10457
|
if (process.env.NODE_ENV !== "production") {
|
|
10331
10458
|
return;
|
|
10332
10459
|
}
|
|
@@ -10336,7 +10463,7 @@ var DatabaseStorage = class {
|
|
|
10336
10463
|
);
|
|
10337
10464
|
}
|
|
10338
10465
|
try {
|
|
10339
|
-
const payload = LicenseVerifier.
|
|
10466
|
+
const payload = await LicenseVerifier.verifyAsync(this.config.licenseKey, this.config.projectId);
|
|
10340
10467
|
const tier = (payload.tier || "").toLowerCase();
|
|
10341
10468
|
if (tier !== "premium" && tier !== "enterprise" && tier !== "growth" && tier !== "pro" && tier !== "developer_pro" && tier !== "free_trial" && tier !== "free_tier" && tier !== "free" && tier !== "hobby") {
|
|
10342
10469
|
throw new Error(
|
|
@@ -10349,16 +10476,16 @@ var DatabaseStorage = class {
|
|
|
10349
10476
|
);
|
|
10350
10477
|
}
|
|
10351
10478
|
}
|
|
10352
|
-
checkHistoryEnabled() {
|
|
10479
|
+
async checkHistoryEnabled() {
|
|
10353
10480
|
var _a3, _b;
|
|
10354
|
-
this.checkPremiumSubscription();
|
|
10481
|
+
await this.checkPremiumSubscription();
|
|
10355
10482
|
if (((_b = (_a3 = this.config.rag) == null ? void 0 : _a3.history) == null ? void 0 : _b.enabled) === false) {
|
|
10356
10483
|
throw new Error("[Retrivora SDK] Chat History is disabled in RagConfig.");
|
|
10357
10484
|
}
|
|
10358
10485
|
}
|
|
10359
|
-
checkFeedbackEnabled() {
|
|
10486
|
+
async checkFeedbackEnabled() {
|
|
10360
10487
|
var _a3, _b;
|
|
10361
|
-
this.checkPremiumSubscription();
|
|
10488
|
+
await this.checkPremiumSubscription();
|
|
10362
10489
|
if (((_b = (_a3 = this.config.rag) == null ? void 0 : _a3.feedback) == null ? void 0 : _b.enabled) === false) {
|
|
10363
10490
|
throw new Error("[Retrivora SDK] User Feedback is disabled in RagConfig.");
|
|
10364
10491
|
}
|
|
@@ -10464,7 +10591,7 @@ var DatabaseStorage = class {
|
|
|
10464
10591
|
}
|
|
10465
10592
|
// ─── Message History Operations ──────────────────────────────────────────
|
|
10466
10593
|
async saveMessage(sessionId, message) {
|
|
10467
|
-
this.checkHistoryEnabled();
|
|
10594
|
+
await this.checkHistoryEnabled();
|
|
10468
10595
|
const createdAt = (/* @__PURE__ */ new Date()).toISOString();
|
|
10469
10596
|
const msgId = message.id || `msg_${Date.now()}_${Math.random().toString(36).slice(2, 6)}`;
|
|
10470
10597
|
if (this.provider === "postgresql" || this.provider === "pgvector") {
|
|
@@ -10527,7 +10654,7 @@ var DatabaseStorage = class {
|
|
|
10527
10654
|
}
|
|
10528
10655
|
}
|
|
10529
10656
|
async getHistory(sessionId, projectIds) {
|
|
10530
|
-
this.checkHistoryEnabled();
|
|
10657
|
+
await this.checkHistoryEnabled();
|
|
10531
10658
|
if (projectIds && projectIds.length > 0 && !this.sessionInScope(sessionId, projectIds)) {
|
|
10532
10659
|
return [];
|
|
10533
10660
|
}
|
|
@@ -10561,7 +10688,7 @@ var DatabaseStorage = class {
|
|
|
10561
10688
|
}
|
|
10562
10689
|
}
|
|
10563
10690
|
async clearHistory(sessionId, projectIds) {
|
|
10564
|
-
this.checkHistoryEnabled();
|
|
10691
|
+
await this.checkHistoryEnabled();
|
|
10565
10692
|
if (projectIds && projectIds.length > 0 && !this.sessionInScope(sessionId, projectIds)) {
|
|
10566
10693
|
return;
|
|
10567
10694
|
}
|
|
@@ -10597,7 +10724,7 @@ var DatabaseStorage = class {
|
|
|
10597
10724
|
);
|
|
10598
10725
|
}
|
|
10599
10726
|
async listSessions(projectIds) {
|
|
10600
|
-
this.checkHistoryEnabled();
|
|
10727
|
+
await this.checkHistoryEnabled();
|
|
10601
10728
|
let raw = [];
|
|
10602
10729
|
if (this.provider === "postgresql" || this.provider === "pgvector") {
|
|
10603
10730
|
const pool = await this.getPGPool();
|
|
@@ -10616,7 +10743,7 @@ var DatabaseStorage = class {
|
|
|
10616
10743
|
}
|
|
10617
10744
|
// ─── Feedback Operations ──────────────────────────────────────────────────
|
|
10618
10745
|
async saveFeedback(feedback) {
|
|
10619
|
-
this.checkFeedbackEnabled();
|
|
10746
|
+
await this.checkFeedbackEnabled();
|
|
10620
10747
|
const id = `fb_${Date.now()}_${Math.random().toString(36).slice(2, 6)}`;
|
|
10621
10748
|
const createdAt = (/* @__PURE__ */ new Date()).toISOString();
|
|
10622
10749
|
if (this.provider === "postgresql" || this.provider === "pgvector") {
|
|
@@ -10666,7 +10793,7 @@ var DatabaseStorage = class {
|
|
|
10666
10793
|
}
|
|
10667
10794
|
}
|
|
10668
10795
|
async getFeedback(messageId, projectIds) {
|
|
10669
|
-
this.checkFeedbackEnabled();
|
|
10796
|
+
await this.checkFeedbackEnabled();
|
|
10670
10797
|
let item = null;
|
|
10671
10798
|
if (this.provider === "postgresql" || this.provider === "pgvector") {
|
|
10672
10799
|
const pool = await this.getPGPool();
|
|
@@ -10702,7 +10829,7 @@ var DatabaseStorage = class {
|
|
|
10702
10829
|
return item;
|
|
10703
10830
|
}
|
|
10704
10831
|
async listFeedback(projectIds) {
|
|
10705
|
-
this.checkFeedbackEnabled();
|
|
10832
|
+
await this.checkFeedbackEnabled();
|
|
10706
10833
|
let raw = [];
|
|
10707
10834
|
if (this.provider === "postgresql" || this.provider === "pgvector") {
|
|
10708
10835
|
const pool = await this.getPGPool();
|
|
@@ -10852,12 +10979,23 @@ function resolveLicenseKey(req, config, bodyLicenseKey) {
|
|
|
10852
10979
|
var _a3;
|
|
10853
10980
|
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 || "";
|
|
10854
10981
|
}
|
|
10855
|
-
function enforceLicense(req, config, bodyLicenseKey) {
|
|
10982
|
+
async function enforceLicense(req, config, bodyLicenseKey) {
|
|
10856
10983
|
const rawKey = resolveLicenseKey(req, config, bodyLicenseKey);
|
|
10857
10984
|
const licenseKey = (rawKey || "").trim().replace(/^["']|["']$/g, "").trim();
|
|
10858
10985
|
const projectId = config.projectId || "";
|
|
10859
10986
|
try {
|
|
10860
|
-
|
|
10987
|
+
let payload;
|
|
10988
|
+
try {
|
|
10989
|
+
payload = await LicenseVerifier.verifyAsync(licenseKey, projectId);
|
|
10990
|
+
} catch (err) {
|
|
10991
|
+
return {
|
|
10992
|
+
ok: false,
|
|
10993
|
+
response: NextResponse.json(
|
|
10994
|
+
{ error: `License validation failed: ${err.message}` },
|
|
10995
|
+
{ status: 401 }
|
|
10996
|
+
)
|
|
10997
|
+
};
|
|
10998
|
+
}
|
|
10861
10999
|
return { ok: true, payload };
|
|
10862
11000
|
} catch (err) {
|
|
10863
11001
|
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.";
|
|
@@ -11032,7 +11170,7 @@ function createChatHandler(configOrPlugin, options) {
|
|
|
11032
11170
|
try {
|
|
11033
11171
|
const body = await req.json();
|
|
11034
11172
|
const bodyObj = body != null ? body : {};
|
|
11035
|
-
const licenseCheck = enforceLicense(req, config, bodyObj == null ? void 0 : bodyObj.licenseKey);
|
|
11173
|
+
const licenseCheck = await enforceLicense(req, config, bodyObj == null ? void 0 : bodyObj.licenseKey);
|
|
11036
11174
|
if (!licenseCheck.ok) return licenseCheck.response;
|
|
11037
11175
|
if (isFreeTier(licenseCheck.payload.tier)) {
|
|
11038
11176
|
const estimatedInputTokens = Math.ceil(
|
|
@@ -11126,7 +11264,7 @@ function createStreamHandler(configOrPlugin, options) {
|
|
|
11126
11264
|
});
|
|
11127
11265
|
}
|
|
11128
11266
|
const bodyObj = body != null ? body : {};
|
|
11129
|
-
const licenseCheck = enforceLicense(req, config, bodyObj == null ? void 0 : bodyObj.licenseKey);
|
|
11267
|
+
const licenseCheck = await enforceLicense(req, config, bodyObj == null ? void 0 : bodyObj.licenseKey);
|
|
11130
11268
|
if (!licenseCheck.ok) return licenseCheck.response;
|
|
11131
11269
|
if (isFreeTier(licenseCheck.payload.tier)) {
|
|
11132
11270
|
const estimatedInputTokens = Math.ceil(
|
|
@@ -11291,7 +11429,7 @@ function createIngestHandler(configOrPlugin, options) {
|
|
|
11291
11429
|
const config = plugin.getConfig();
|
|
11292
11430
|
try {
|
|
11293
11431
|
const body = await req.json();
|
|
11294
|
-
const licenseCheck = enforceLicense(req, config, body == null ? void 0 : body.licenseKey);
|
|
11432
|
+
const licenseCheck = await enforceLicense(req, config, body == null ? void 0 : body.licenseKey);
|
|
11295
11433
|
if (!licenseCheck.ok) return licenseCheck.response;
|
|
11296
11434
|
const { documents, namespace } = body;
|
|
11297
11435
|
if (!Array.isArray(documents) || documents.length === 0) {
|
|
@@ -11367,7 +11505,8 @@ function createLicenseHandler(configOrPlugin, options) {
|
|
|
11367
11505
|
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 || "";
|
|
11368
11506
|
const licenseKey = (rawKey || "").trim().replace(/^["']|["']$/g, "").trim();
|
|
11369
11507
|
const projectId = (body == null ? void 0 : body.projectId) || config.projectId || "";
|
|
11370
|
-
|
|
11508
|
+
console.log(`[DEBUG] createLicenseHandler: projectId="${projectId}", body.projectId="${body == null ? void 0 : body.projectId}", config.projectId="${config.projectId}"`);
|
|
11509
|
+
const payload = await LicenseVerifier.verifyAsync(licenseKey, projectId);
|
|
11371
11510
|
return NextResponse.json({
|
|
11372
11511
|
valid: true,
|
|
11373
11512
|
licenseStatus: "ACTIVE",
|
|
@@ -11401,7 +11540,7 @@ function createUploadHandler(configOrPlugin, options) {
|
|
|
11401
11540
|
const authResult = await checkAuth(req, onAuthorize);
|
|
11402
11541
|
if (authResult) return authResult;
|
|
11403
11542
|
const config = plugin.getConfig();
|
|
11404
|
-
const licenseCheck = enforceLicense(req, config);
|
|
11543
|
+
const licenseCheck = await enforceLicense(req, config);
|
|
11405
11544
|
if (!licenseCheck.ok) return licenseCheck.response;
|
|
11406
11545
|
try {
|
|
11407
11546
|
const formData = await req.formData();
|
|
@@ -11545,7 +11684,7 @@ function createSuggestionsHandler(configOrPlugin, options) {
|
|
|
11545
11684
|
const authResult = await checkAuth(req, onAuthorize);
|
|
11546
11685
|
if (authResult) return authResult;
|
|
11547
11686
|
const config = plugin.getConfig();
|
|
11548
|
-
const licenseCheck = enforceLicense(req, config);
|
|
11687
|
+
const licenseCheck = await enforceLicense(req, config);
|
|
11549
11688
|
if (!licenseCheck.ok) return licenseCheck.response;
|
|
11550
11689
|
let effectiveLicensePayload = licenseCheck.payload;
|
|
11551
11690
|
try {
|
|
@@ -11558,7 +11697,7 @@ function createSuggestionsHandler(configOrPlugin, options) {
|
|
|
11558
11697
|
namespace = body.namespace;
|
|
11559
11698
|
bodyLicenseKey = body.licenseKey;
|
|
11560
11699
|
if (bodyLicenseKey) {
|
|
11561
|
-
const recheck = enforceLicense(req, config, bodyLicenseKey);
|
|
11700
|
+
const recheck = await enforceLicense(req, config, bodyLicenseKey);
|
|
11562
11701
|
if (!recheck.ok) return recheck.response;
|
|
11563
11702
|
effectiveLicensePayload = recheck.payload;
|
|
11564
11703
|
}
|