@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/server.js
CHANGED
|
@@ -330,7 +330,7 @@ var init_package = __esm({
|
|
|
330
330
|
"package.json"() {
|
|
331
331
|
package_default = {
|
|
332
332
|
name: "@retrivora-ai/rag-engine",
|
|
333
|
-
version: "2.3.
|
|
333
|
+
version: "2.3.8",
|
|
334
334
|
description: "Retrivora AI is a plug-and-play AI engine for RAG chat experiences \u2014 generic vector DB + LLM provider, embeddable or standalone.",
|
|
335
335
|
author: "Abhinav Alkuchi",
|
|
336
336
|
license: "UNLICENSED",
|
|
@@ -516,7 +516,12 @@ var init_ConfigFetcher = __esm({
|
|
|
516
516
|
process.env.RETRIVORA_CONTROL_PLANE_URL,
|
|
517
517
|
process.env.NEXT_PUBLIC_RETRIVORA_CONTROL_PLANE_URL,
|
|
518
518
|
CONTROL_PLANE_URL
|
|
519
|
-
].filter((url) =>
|
|
519
|
+
].filter((url) => {
|
|
520
|
+
if (!url) return false;
|
|
521
|
+
const isEnvVar = url === process.env.RETRIVORA_CONTROL_PLANE_URL || url === process.env.NEXT_PUBLIC_RETRIVORA_CONTROL_PLANE_URL;
|
|
522
|
+
if (!isEnvVar && (url.includes("localhost") || url.includes("127.0.0.1"))) return false;
|
|
523
|
+
return true;
|
|
524
|
+
}).map((url) => url.replace(/\/$/, ""));
|
|
520
525
|
for (const baseUrl of controlPlaneUrls) {
|
|
521
526
|
try {
|
|
522
527
|
const url = `${baseUrl}/api/v1/config?projectId=${encodeURIComponent(projectId)}`;
|
|
@@ -537,8 +542,7 @@ var init_ConfigFetcher = __esm({
|
|
|
537
542
|
isActive: data.isActive,
|
|
538
543
|
expiresAt: data.expiresAt,
|
|
539
544
|
vectorDb: {
|
|
540
|
-
// apiKey
|
|
541
|
-
// The SDK uses local PINECONE_API_KEY if available.
|
|
545
|
+
// Fetch apiKey from credentials API if available, else fallback to empty
|
|
542
546
|
apiKey: data.vectorDb.apiKey || "",
|
|
543
547
|
indexName: data.vectorDb.indexName || "retrivora-free",
|
|
544
548
|
provider: data.vectorDb.provider || "pinecone",
|
|
@@ -570,6 +574,32 @@ var init_ConfigFetcher = __esm({
|
|
|
570
574
|
data.projectSettings || data.settings
|
|
571
575
|
)
|
|
572
576
|
};
|
|
577
|
+
if (licenseKey) {
|
|
578
|
+
try {
|
|
579
|
+
const credUrl = `${baseUrl}/api/v1/credentials`;
|
|
580
|
+
const credRes = await fetch(credUrl, {
|
|
581
|
+
method: "POST",
|
|
582
|
+
headers: {
|
|
583
|
+
"Content-Type": "application/json"
|
|
584
|
+
},
|
|
585
|
+
body: JSON.stringify({ licenseKey, projectId: fetchedProjectId })
|
|
586
|
+
});
|
|
587
|
+
if (credRes.ok) {
|
|
588
|
+
const credData = await credRes.json();
|
|
589
|
+
if ((credData == null ? void 0 : credData.success) && (credData == null ? void 0 : credData.credentials)) {
|
|
590
|
+
if (credData.credentials.pineconeApiKey && !config.vectorDb.apiKey) {
|
|
591
|
+
config.vectorDb.apiKey = credData.credentials.pineconeApiKey;
|
|
592
|
+
}
|
|
593
|
+
if (credData.credentials.litellmApiKey) {
|
|
594
|
+
config.llm.apiKey = credData.credentials.litellmApiKey;
|
|
595
|
+
config.embedding.apiKey = credData.credentials.litellmApiKey;
|
|
596
|
+
}
|
|
597
|
+
}
|
|
598
|
+
}
|
|
599
|
+
} catch (e) {
|
|
600
|
+
console.warn("[ConfigFetcher] Failed to fetch credentials:", e);
|
|
601
|
+
}
|
|
602
|
+
}
|
|
573
603
|
this.cache.set(cacheKey, { config, cachedAt: now });
|
|
574
604
|
return config;
|
|
575
605
|
}
|
|
@@ -609,6 +639,14 @@ var init_PineconeProvider = __esm({
|
|
|
609
639
|
const opts = config.options || {};
|
|
610
640
|
this.apiKey = opts.apiKey || process.env.PINECONE_API_KEY || "";
|
|
611
641
|
}
|
|
642
|
+
getControlPlaneUrl() {
|
|
643
|
+
const urls = [
|
|
644
|
+
process.env.RETRIVORA_CONTROL_PLANE_URL,
|
|
645
|
+
process.env.NEXT_PUBLIC_RETRIVORA_CONTROL_PLANE_URL,
|
|
646
|
+
"https://www.retrivora.com"
|
|
647
|
+
].filter((url) => Boolean(url));
|
|
648
|
+
return urls[0].replace(/\/$/, "");
|
|
649
|
+
}
|
|
612
650
|
static getValidator() {
|
|
613
651
|
return {
|
|
614
652
|
validate(config) {
|
|
@@ -672,6 +710,7 @@ var init_PineconeProvider = __esm({
|
|
|
672
710
|
let key = this.apiKey || process.env.PINECONE_API_KEY || "";
|
|
673
711
|
if (!key) {
|
|
674
712
|
const licenseKey = process.env.RETRIVORA_LICENSE_KEY || process.env.NEXT_PUBLIC_RETRIVORA_LICENSE_KEY;
|
|
713
|
+
this.licenseKey = licenseKey;
|
|
675
714
|
const jwtProjectId = (() => {
|
|
676
715
|
if (!licenseKey) return void 0;
|
|
677
716
|
try {
|
|
@@ -685,6 +724,7 @@ var init_PineconeProvider = __esm({
|
|
|
685
724
|
return void 0;
|
|
686
725
|
})();
|
|
687
726
|
const projectId = process.env.RAG_PROJECT_ID || process.env.NEXT_PUBLIC_RAG_PROJECT_ID || jwtProjectId || this.projectId || "default";
|
|
727
|
+
this.projectId = projectId;
|
|
688
728
|
const remoteConfig = await ConfigFetcher.fetchRemoteVectorConfig(projectId, licenseKey);
|
|
689
729
|
if (remoteConfig) {
|
|
690
730
|
if (remoteConfig.apiKey) {
|
|
@@ -730,19 +770,59 @@ var init_PineconeProvider = __esm({
|
|
|
730
770
|
return namespace ? idx.namespace(namespace) : idx.namespace("");
|
|
731
771
|
}
|
|
732
772
|
async upsert(doc, namespace) {
|
|
733
|
-
var _a3;
|
|
773
|
+
var _a3, _b;
|
|
774
|
+
if (!this.client) {
|
|
775
|
+
if (!this.licenseKey) throw new Error("[PineconeProvider] Cannot execute vector operation: Missing API key and License key.");
|
|
776
|
+
const res = await fetch(`${this.getControlPlaneUrl()}/api/v1/vectors/upsert`, {
|
|
777
|
+
method: "POST",
|
|
778
|
+
headers: { "Content-Type": "application/json", "x-license-key": this.licenseKey },
|
|
779
|
+
body: JSON.stringify({
|
|
780
|
+
projectId: this.projectId,
|
|
781
|
+
indexName: this.indexName,
|
|
782
|
+
namespace: namespace || this.projectId,
|
|
783
|
+
records: [{ id: String(doc.id), values: doc.vector, metadata: __spreadValues({ content: doc.content }, (_a3 = doc.metadata) != null ? _a3 : {}) }]
|
|
784
|
+
})
|
|
785
|
+
});
|
|
786
|
+
if (!res.ok) throw new Error(`[PineconeProvider] Proxy upsert failed: ${await res.text()}`);
|
|
787
|
+
return;
|
|
788
|
+
}
|
|
734
789
|
const targetIdx = await this.getActiveIndex(namespace);
|
|
735
790
|
await targetIdx.upsert({
|
|
736
791
|
records: [{
|
|
737
792
|
id: String(doc.id),
|
|
738
793
|
values: doc.vector,
|
|
739
|
-
metadata: __spreadValues({ content: doc.content }, (
|
|
794
|
+
metadata: __spreadValues({ content: doc.content }, (_b = doc.metadata) != null ? _b : {})
|
|
740
795
|
}]
|
|
741
796
|
});
|
|
742
797
|
}
|
|
743
798
|
async batchUpsert(docs, namespace) {
|
|
744
|
-
const targetIdx = await this.getActiveIndex(namespace);
|
|
745
799
|
const BATCH = 100;
|
|
800
|
+
if (!this.client) {
|
|
801
|
+
if (!this.licenseKey) throw new Error("[PineconeProvider] Cannot execute vector operation: Missing API key and License key.");
|
|
802
|
+
for (let i = 0; i < docs.length; i += BATCH) {
|
|
803
|
+
const records = docs.slice(i, i + BATCH).map((d) => {
|
|
804
|
+
var _a3;
|
|
805
|
+
return {
|
|
806
|
+
id: String(d.id),
|
|
807
|
+
values: d.vector,
|
|
808
|
+
metadata: __spreadValues({ content: d.content }, (_a3 = d.metadata) != null ? _a3 : {})
|
|
809
|
+
};
|
|
810
|
+
});
|
|
811
|
+
const res = await fetch(`${this.getControlPlaneUrl()}/api/v1/vectors/upsert`, {
|
|
812
|
+
method: "POST",
|
|
813
|
+
headers: { "Content-Type": "application/json", "x-license-key": this.licenseKey },
|
|
814
|
+
body: JSON.stringify({
|
|
815
|
+
projectId: this.projectId,
|
|
816
|
+
indexName: this.indexName,
|
|
817
|
+
namespace: namespace || this.projectId,
|
|
818
|
+
records
|
|
819
|
+
})
|
|
820
|
+
});
|
|
821
|
+
if (!res.ok) throw new Error(`[PineconeProvider] Proxy batch upsert failed: ${await res.text()}`);
|
|
822
|
+
}
|
|
823
|
+
return;
|
|
824
|
+
}
|
|
825
|
+
const targetIdx = await this.getActiveIndex(namespace);
|
|
746
826
|
for (let i = 0; i < docs.length; i += BATCH) {
|
|
747
827
|
const records = docs.slice(i, i + BATCH).map((d) => {
|
|
748
828
|
var _a3;
|
|
@@ -756,20 +836,46 @@ var init_PineconeProvider = __esm({
|
|
|
756
836
|
}
|
|
757
837
|
}
|
|
758
838
|
async query(vector, topK, namespace, filter) {
|
|
759
|
-
var _a3;
|
|
760
|
-
const targetIdx = await this.getActiveIndex(namespace);
|
|
839
|
+
var _a3, _b;
|
|
761
840
|
const pineconeFilter = this.sanitizeFilter(filter);
|
|
841
|
+
if (!this.client) {
|
|
842
|
+
if (!this.licenseKey) throw new Error("[PineconeProvider] Cannot execute vector operation: Missing API key and License key.");
|
|
843
|
+
const res = await fetch(`${this.getControlPlaneUrl()}/api/v1/vectors/query`, {
|
|
844
|
+
method: "POST",
|
|
845
|
+
headers: { "Content-Type": "application/json", "x-license-key": this.licenseKey },
|
|
846
|
+
body: JSON.stringify({
|
|
847
|
+
projectId: this.projectId,
|
|
848
|
+
indexName: this.indexName,
|
|
849
|
+
namespace: namespace || this.projectId,
|
|
850
|
+
vector,
|
|
851
|
+
topK,
|
|
852
|
+
filter: pineconeFilter
|
|
853
|
+
})
|
|
854
|
+
});
|
|
855
|
+
if (!res.ok) throw new Error(`[PineconeProvider] Proxy query failed: ${await res.text()}`);
|
|
856
|
+
const data = await res.json();
|
|
857
|
+
return ((_a3 = data.matches) != null ? _a3 : []).map((m) => {
|
|
858
|
+
var _a4, _b2;
|
|
859
|
+
return {
|
|
860
|
+
id: m.id,
|
|
861
|
+
score: (_a4 = m.score) != null ? _a4 : 0,
|
|
862
|
+
content: ((_b2 = m.metadata) == null ? void 0 : _b2.content) || "",
|
|
863
|
+
metadata: m.metadata
|
|
864
|
+
};
|
|
865
|
+
});
|
|
866
|
+
}
|
|
867
|
+
const targetIdx = await this.getActiveIndex(namespace);
|
|
762
868
|
const result = await targetIdx.query(__spreadValues({
|
|
763
869
|
vector,
|
|
764
870
|
topK,
|
|
765
871
|
includeMetadata: true
|
|
766
872
|
}, Object.keys(pineconeFilter).length > 0 ? { filter: pineconeFilter } : {}));
|
|
767
|
-
return ((
|
|
768
|
-
var _a4,
|
|
873
|
+
return ((_b = result.matches) != null ? _b : []).map((m) => {
|
|
874
|
+
var _a4, _b2;
|
|
769
875
|
return {
|
|
770
876
|
id: m.id,
|
|
771
877
|
score: (_a4 = m.score) != null ? _a4 : 0,
|
|
772
|
-
content: ((
|
|
878
|
+
content: ((_b2 = m.metadata) == null ? void 0 : _b2.content) || "",
|
|
773
879
|
metadata: m.metadata
|
|
774
880
|
};
|
|
775
881
|
});
|
|
@@ -2579,13 +2685,16 @@ __export(server_exports, {
|
|
|
2579
2685
|
EmbeddingFailedException: () => EmbeddingFailedException,
|
|
2580
2686
|
EmbeddingStrategy: () => EmbeddingStrategy,
|
|
2581
2687
|
EmbeddingStrategyResolver: () => EmbeddingStrategyResolver,
|
|
2688
|
+
EventType: () => EventType,
|
|
2582
2689
|
GroqProvider: () => GroqProvider,
|
|
2583
2690
|
IntentClassifier: () => IntentClassifier,
|
|
2584
2691
|
LLMFactory: () => LLMFactory,
|
|
2585
2692
|
LLM_PROFILES: () => LLM_PROFILES,
|
|
2693
|
+
LicenseConfigResolver: () => LicenseConfigResolver,
|
|
2586
2694
|
LicenseValidationError: () => LicenseValidationError,
|
|
2587
2695
|
LicenseValidator: () => LicenseValidator,
|
|
2588
2696
|
LicenseVerifier: () => LicenseVerifier,
|
|
2697
|
+
LicensedRetrivora: () => LicensedRetrivora,
|
|
2589
2698
|
MilvusProvider: () => MilvusProvider,
|
|
2590
2699
|
MixedRendererStrategy: () => MixedRendererStrategy,
|
|
2591
2700
|
MongoDBProvider: () => MongoDBProvider,
|
|
@@ -2618,6 +2727,7 @@ __export(server_exports, {
|
|
|
2618
2727
|
SDKVersionUnsupportedError: () => SDKVersionUnsupportedError,
|
|
2619
2728
|
SDK_VERSION: () => SDK_VERSION,
|
|
2620
2729
|
TableRendererStrategy: () => TableRendererStrategy,
|
|
2730
|
+
TelemetryService: () => TelemetryService,
|
|
2621
2731
|
TextRendererStrategy: () => TextRendererStrategy,
|
|
2622
2732
|
UniversalLLMAdapter: () => UniversalLLMAdapter,
|
|
2623
2733
|
UniversalVectorProvider: () => UniversalVectorProvider,
|
|
@@ -2633,13 +2743,19 @@ __export(server_exports, {
|
|
|
2633
2743
|
createHistoryHandler: () => createHistoryHandler,
|
|
2634
2744
|
createIngestHandler: () => createIngestHandler,
|
|
2635
2745
|
createRagHandler: () => createRagHandler,
|
|
2746
|
+
createRetrivora: () => createRetrivora,
|
|
2636
2747
|
createSessionsHandler: () => createSessionsHandler,
|
|
2637
2748
|
createStreamHandler: () => createStreamHandler,
|
|
2638
2749
|
createUploadHandler: () => createUploadHandler,
|
|
2639
2750
|
decideVisualization: () => decideVisualization,
|
|
2640
2751
|
getRagConfig: () => getRagConfig,
|
|
2752
|
+
getRuntimeConfig: () => getRuntimeConfig,
|
|
2753
|
+
getTelemetryService: () => getTelemetryService,
|
|
2754
|
+
initializeTelemetryService: () => initializeTelemetryService,
|
|
2755
|
+
injectRuntimeConfig: () => injectRuntimeConfig,
|
|
2641
2756
|
normalizeProjectSettings: () => normalizeProjectSettings,
|
|
2642
2757
|
projectSettingsToUiConfig: () => projectSettingsToUiConfig,
|
|
2758
|
+
shutdownTelemetryService: () => shutdownTelemetryService,
|
|
2643
2759
|
sseErrorFrame: () => sseErrorFrame,
|
|
2644
2760
|
sseFrame: () => sseFrame,
|
|
2645
2761
|
sseMetaFrame: () => sseMetaFrame,
|
|
@@ -2651,9 +2767,6 @@ module.exports = __toCommonJS(server_exports);
|
|
|
2651
2767
|
// src/core/ConfigResolver.ts
|
|
2652
2768
|
init_templateUtils();
|
|
2653
2769
|
|
|
2654
|
-
// src/core/LicenseVerifier.ts
|
|
2655
|
-
var crypto = __toESM(require("crypto"));
|
|
2656
|
-
|
|
2657
2770
|
// src/exceptions/index.ts
|
|
2658
2771
|
var RetrivoraError = class extends Error {
|
|
2659
2772
|
constructor(message, code, details) {
|
|
@@ -2739,29 +2852,18 @@ function wrapError(err, defaultCode, defaultMessage) {
|
|
|
2739
2852
|
}
|
|
2740
2853
|
|
|
2741
2854
|
// src/core/LicenseVerifier.ts
|
|
2742
|
-
var
|
|
2855
|
+
var _LicenseVerifier = class _LicenseVerifier {
|
|
2856
|
+
// Cache verified license for 5 minutes
|
|
2743
2857
|
/**
|
|
2744
|
-
*
|
|
2858
|
+
* Validates the license key asynchronously by calling the Retrivora backend.
|
|
2745
2859
|
*
|
|
2746
2860
|
* @param licenseKey - Base64url signed JWT license key.
|
|
2747
2861
|
* @param currentProjectId - Project namespace ID.
|
|
2748
|
-
* @param
|
|
2862
|
+
* @param provider - Optional provider for tier checks.
|
|
2749
2863
|
*/
|
|
2750
|
-
static
|
|
2864
|
+
static async verifyAsync(licenseKey, currentProjectId, provider) {
|
|
2751
2865
|
const isProduction = process.env.NODE_ENV === "production";
|
|
2752
2866
|
const now = Date.now();
|
|
2753
|
-
if (licenseKey) {
|
|
2754
|
-
const cacheKey = `${licenseKey}:${currentProjectId}:${provider || ""}:${publicKeyOverride || ""}`;
|
|
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;
|
|
2762
|
-
}
|
|
2763
|
-
}
|
|
2764
|
-
}
|
|
2765
2867
|
if (!licenseKey) {
|
|
2766
2868
|
if (isProduction) {
|
|
2767
2869
|
throw new ConfigurationException(
|
|
@@ -2778,52 +2880,61 @@ var LicenseVerifier = class {
|
|
|
2778
2880
|
tier: "hobby"
|
|
2779
2881
|
};
|
|
2780
2882
|
}
|
|
2781
|
-
|
|
2782
|
-
|
|
2783
|
-
|
|
2784
|
-
const
|
|
2785
|
-
if (
|
|
2786
|
-
|
|
2787
|
-
}
|
|
2788
|
-
|
|
2789
|
-
const dataToVerify = `${headerB64}.${payloadB64}`;
|
|
2790
|
-
const publicKey = publicKeyOverride != null ? publicKeyOverride : this.PUBLIC_KEY;
|
|
2791
|
-
const signature = Buffer.from(signatureB64, "base64url");
|
|
2792
|
-
const data = Buffer.from(dataToVerify);
|
|
2793
|
-
const isValid = crypto.verify(
|
|
2794
|
-
"sha256",
|
|
2795
|
-
data,
|
|
2796
|
-
publicKey,
|
|
2797
|
-
signature
|
|
2798
|
-
);
|
|
2799
|
-
if (!isValid) {
|
|
2800
|
-
throw new Error("Signature verification failed.");
|
|
2883
|
+
const cacheKey = `${licenseKey}:${currentProjectId}:${provider || ""}`;
|
|
2884
|
+
const cached = this.cache.get(cacheKey);
|
|
2885
|
+
if (cached && now - cached.cachedAt < this.CACHE_TTL_MS) {
|
|
2886
|
+
const currentTimestampSec = Math.floor(now / 1e3);
|
|
2887
|
+
if (cached.payload.expiresAt && currentTimestampSec > cached.payload.expiresAt) {
|
|
2888
|
+
this.cache.delete(cacheKey);
|
|
2889
|
+
} else {
|
|
2890
|
+
return cached.payload;
|
|
2801
2891
|
}
|
|
2802
|
-
|
|
2803
|
-
|
|
2804
|
-
|
|
2805
|
-
if (
|
|
2806
|
-
|
|
2892
|
+
}
|
|
2893
|
+
try {
|
|
2894
|
+
let baseUrl = typeof process !== "undefined" && process.env.RETRIVORA_CONTROL_PLANE_URL ? process.env.RETRIVORA_CONTROL_PLANE_URL : "https://retrivora.com";
|
|
2895
|
+
if (typeof process !== "undefined" && process.env.TELEMETRY_URL) {
|
|
2896
|
+
baseUrl = process.env.TELEMETRY_URL.replace(/\/api\/telemetry\/?$/, "");
|
|
2807
2897
|
}
|
|
2808
|
-
const
|
|
2809
|
-
|
|
2810
|
-
|
|
2811
|
-
|
|
2812
|
-
|
|
2898
|
+
const endpoint = `${baseUrl}/api/v1/license/validate`;
|
|
2899
|
+
const response = await fetch(endpoint, {
|
|
2900
|
+
method: "POST",
|
|
2901
|
+
headers: {
|
|
2902
|
+
"Content-Type": "application/json",
|
|
2903
|
+
"x-license-key": licenseKey
|
|
2904
|
+
},
|
|
2905
|
+
body: JSON.stringify({
|
|
2906
|
+
licenseKey,
|
|
2907
|
+
projectId: currentProjectId,
|
|
2908
|
+
provider
|
|
2909
|
+
})
|
|
2910
|
+
});
|
|
2911
|
+
if (!response.ok) {
|
|
2912
|
+
let errMessage = `HTTP ${response.status}`;
|
|
2913
|
+
try {
|
|
2914
|
+
const body = await response.json();
|
|
2915
|
+
if (body.message) errMessage = body.message;
|
|
2916
|
+
} catch (e) {
|
|
2917
|
+
}
|
|
2918
|
+
throw new Error(errMessage);
|
|
2813
2919
|
}
|
|
2814
|
-
|
|
2815
|
-
|
|
2920
|
+
const data = await response.json();
|
|
2921
|
+
if (!data.valid) {
|
|
2922
|
+
throw new Error(data.message || "License validation failed by server.");
|
|
2816
2923
|
}
|
|
2817
|
-
|
|
2818
|
-
if (
|
|
2819
|
-
|
|
2820
|
-
`License key has expired. Expiration: ${new Date(
|
|
2821
|
-
payload.expiresAt * 1e3
|
|
2822
|
-
).toDateString()}`
|
|
2823
|
-
);
|
|
2924
|
+
let expiresAtNum = Math.floor(Date.now() / 1e3) + 100 * 365 * 24 * 60 * 60;
|
|
2925
|
+
if (data.expiresAt) {
|
|
2926
|
+
expiresAtNum = Math.floor(new Date(data.expiresAt).getTime() / 1e3);
|
|
2824
2927
|
}
|
|
2928
|
+
const tier = _LicenseVerifier.extractTier(licenseKey);
|
|
2929
|
+
const payload = {
|
|
2930
|
+
projectId: currentProjectId,
|
|
2931
|
+
expiresAt: expiresAtNum,
|
|
2932
|
+
tier,
|
|
2933
|
+
licenseStatus: data.licenseStatus,
|
|
2934
|
+
minimumSupportedVersion: data.minimumSupportedVersion,
|
|
2935
|
+
forceUpgrade: data.forceUpgrade
|
|
2936
|
+
};
|
|
2825
2937
|
if (isProduction && provider) {
|
|
2826
|
-
const tier = (payload.tier || "").toLowerCase();
|
|
2827
2938
|
const normalizedProvider = provider.toLowerCase();
|
|
2828
2939
|
if (tier === "hobby") {
|
|
2829
2940
|
const allowedHobby = ["postgresql", "pgvector", "supabase"];
|
|
@@ -2851,15 +2962,12 @@ var LicenseVerifier = class {
|
|
|
2851
2962
|
}
|
|
2852
2963
|
}
|
|
2853
2964
|
}
|
|
2854
|
-
|
|
2855
|
-
const cacheKey = `${licenseKey}:${currentProjectId}:${provider || ""}:${publicKeyOverride || ""}`;
|
|
2856
|
-
this.cache.set(cacheKey, { payload, cachedAt: now });
|
|
2857
|
-
}
|
|
2965
|
+
this.cache.set(cacheKey, { payload, cachedAt: now });
|
|
2858
2966
|
return payload;
|
|
2859
2967
|
} catch (err) {
|
|
2860
2968
|
const message = err instanceof Error ? err.message : String(err);
|
|
2861
2969
|
throw new ConfigurationException(
|
|
2862
|
-
`[Retrivora SDK] License key validation failed: ${message}`
|
|
2970
|
+
`[Retrivora SDK] License key validation failed via API: ${message}`
|
|
2863
2971
|
);
|
|
2864
2972
|
}
|
|
2865
2973
|
}
|
|
@@ -2928,23 +3036,25 @@ var LicenseVerifier = class {
|
|
|
2928
3036
|
}
|
|
2929
3037
|
}
|
|
2930
3038
|
}
|
|
3039
|
+
static extractTier(licenseKey) {
|
|
3040
|
+
if (!licenseKey) return "hobby";
|
|
3041
|
+
try {
|
|
3042
|
+
const sanitizedKey = licenseKey.trim().replace(/^["']|["']$/g, "").trim();
|
|
3043
|
+
const rawToken = sanitizedKey.replace(/^rtv_/i, "").trim();
|
|
3044
|
+
const parts = rawToken.split(".");
|
|
3045
|
+
if (parts.length === 3) {
|
|
3046
|
+
const decodedPayload = JSON.parse(Buffer.from(parts[1], "base64url").toString("utf8"));
|
|
3047
|
+
if (decodedPayload.tier) return decodedPayload.tier;
|
|
3048
|
+
}
|
|
3049
|
+
} catch (e) {
|
|
3050
|
+
}
|
|
3051
|
+
return "hobby";
|
|
3052
|
+
}
|
|
2931
3053
|
};
|
|
2932
|
-
//
|
|
2933
|
-
|
|
2934
|
-
|
|
2935
|
-
|
|
2936
|
-
// Retrivora's Public Key used to verify the license key signature.
|
|
2937
|
-
// In production, this matches the private key held by Retrivora SaaS.
|
|
2938
|
-
// Rotate this key only when the signing private key is replaced.
|
|
2939
|
-
LicenseVerifier.PUBLIC_KEY = `-----BEGIN PUBLIC KEY-----
|
|
2940
|
-
MIIBIjANBgkqhkiG9w0BAQEFAAOCAQ8AMIIBCgKCAQEAoOQlmDSKfCZaRy06rxwa
|
|
2941
|
-
chuDimlF134xTCitKDTPTPizF23oSn34pGDJakm/0T09JVUX8L/cvhGPe/3lf/g9
|
|
2942
|
-
4Y1q+Gb2KVM17KNGeT1Aj9Ua3BKz/yao/oFhi/r3Zt3cWY13B/Rd6clqY9WshIAV
|
|
2943
|
-
NqZNM8ilTl777cMbyym+6D+mzGXgmnJAO5brddIAI9FPLW0T3Znt8vEqDOIljEkC
|
|
2944
|
-
HCGHeirKABLbjKSJ4hljCa3vVitWqndhiq8CBSJG6HatiSGYotgMWGRY+0EbdlEv
|
|
2945
|
-
OJP4SqafQ3aD6YnL9q1n15QKwxu/uMK+JGM2VxxuyUi9GANtMIkCYy9xya73P4Qc
|
|
2946
|
-
gQIDAQAB
|
|
2947
|
-
-----END PUBLIC KEY-----`;
|
|
3054
|
+
// In-memory cache to save network overhead on hot paths.
|
|
3055
|
+
_LicenseVerifier.cache = /* @__PURE__ */ new Map();
|
|
3056
|
+
_LicenseVerifier.CACHE_TTL_MS = 5 * 60 * 1e3;
|
|
3057
|
+
var LicenseVerifier = _LicenseVerifier;
|
|
2948
3058
|
|
|
2949
3059
|
// src/config/constants.ts
|
|
2950
3060
|
var VECTOR_DB_PROVIDERS = [
|
|
@@ -2992,6 +3102,20 @@ var PROVIDERS_WITH_EMBEDDINGS = [
|
|
|
2992
3102
|
var UI_BORDER_RADIUS_OPTIONS = ["none", "sm", "md", "lg", "xl", "full"];
|
|
2993
3103
|
|
|
2994
3104
|
// src/config/serverConfig.ts
|
|
3105
|
+
var _runtimeConfig = null;
|
|
3106
|
+
function injectRuntimeConfig(config) {
|
|
3107
|
+
_runtimeConfig = config;
|
|
3108
|
+
console.log("[serverConfig] \u2705 Runtime tier config injected:", {
|
|
3109
|
+
tier: config.tier,
|
|
3110
|
+
llmModel: config.llmModel,
|
|
3111
|
+
embeddingModel: config.embeddingModel,
|
|
3112
|
+
llmBaseUrl: config.llmBaseUrl,
|
|
3113
|
+
hasLitellmKey: !!config.litellmApiKey
|
|
3114
|
+
});
|
|
3115
|
+
}
|
|
3116
|
+
function getRuntimeConfig() {
|
|
3117
|
+
return _runtimeConfig;
|
|
3118
|
+
}
|
|
2995
3119
|
function readString(env, name) {
|
|
2996
3120
|
var _a3;
|
|
2997
3121
|
const value = (_a3 = env[name]) == null ? void 0 : _a3.trim();
|
|
@@ -3018,7 +3142,7 @@ function getRagConfig(baseConfig, env = process.env) {
|
|
|
3018
3142
|
return getEnvConfig(env, baseConfig);
|
|
3019
3143
|
}
|
|
3020
3144
|
function getEnvConfig(env = process.env, base) {
|
|
3021
|
-
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
|
|
3145
|
+
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;
|
|
3022
3146
|
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;
|
|
3023
3147
|
const jwtProjectId = (() => {
|
|
3024
3148
|
if (!licenseKey) return void 0;
|
|
@@ -3103,32 +3227,41 @@ function getEnvConfig(env = process.env, base) {
|
|
|
3103
3227
|
const isFreeTier2 = (() => {
|
|
3104
3228
|
if (!licenseKey) return true;
|
|
3105
3229
|
try {
|
|
3106
|
-
const
|
|
3107
|
-
const tier = (payload.tier || "").toLowerCase();
|
|
3230
|
+
const tier = LicenseVerifier.extractTier(licenseKey).toLowerCase();
|
|
3108
3231
|
return tier === "free_trial" || tier === "free_tier" || tier === "free" || tier === "hobby";
|
|
3109
3232
|
} catch (e) {
|
|
3110
3233
|
return true;
|
|
3111
3234
|
}
|
|
3112
3235
|
})();
|
|
3113
|
-
const
|
|
3114
|
-
const
|
|
3115
|
-
const
|
|
3116
|
-
const
|
|
3117
|
-
const
|
|
3118
|
-
const
|
|
3119
|
-
const
|
|
3120
|
-
const
|
|
3121
|
-
const
|
|
3122
|
-
const
|
|
3123
|
-
|
|
3124
|
-
|
|
3125
|
-
|
|
3236
|
+
const tierBasedLLMModel = isFreeTier2 ? "llama-3.1-8b-instant" : "llama-3.3-70b-versatile";
|
|
3237
|
+
const tierBasedEmbeddingModel = isFreeTier2 ? "text-embedding-004" : "text-embedding-004";
|
|
3238
|
+
const defaultGatewayUrl = "https://llm.retrivora.com/api/v1";
|
|
3239
|
+
const rt = _runtimeConfig;
|
|
3240
|
+
const defaultLlmProvider = "universal_rest";
|
|
3241
|
+
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;
|
|
3242
|
+
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;
|
|
3243
|
+
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;
|
|
3244
|
+
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;
|
|
3245
|
+
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";
|
|
3246
|
+
console.log("[serverConfig] \u{1F527} LLM Configuration:", {
|
|
3247
|
+
baseUrl: llmBaseUrl,
|
|
3248
|
+
model: llmModel,
|
|
3249
|
+
provider: llmProvider,
|
|
3250
|
+
hasApiKey: !!llmApiKey,
|
|
3251
|
+
source: (rt == null ? void 0 : rt.llmModel) ? "runtime-injected" : "env/fallback"
|
|
3252
|
+
});
|
|
3253
|
+
const defaultEmbeddingProvider = "universal_rest";
|
|
3254
|
+
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;
|
|
3255
|
+
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;
|
|
3256
|
+
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;
|
|
3257
|
+
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;
|
|
3258
|
+
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";
|
|
3126
3259
|
return __spreadProps(__spreadValues({
|
|
3127
3260
|
projectId,
|
|
3128
3261
|
licenseKey,
|
|
3129
3262
|
vectorDb: {
|
|
3130
3263
|
provider: vectorProvider,
|
|
3131
|
-
indexName: (
|
|
3264
|
+
indexName: (_fb = (_eb = readString(env, "VECTOR_DB_INDEX")) != null ? _eb : vectorDbOptions.indexName) != null ? _fb : "rag-index",
|
|
3132
3265
|
options: vectorDbOptions
|
|
3133
3266
|
},
|
|
3134
3267
|
llm: {
|
|
@@ -3158,30 +3291,30 @@ function getEnvConfig(env = process.env, base) {
|
|
|
3158
3291
|
}
|
|
3159
3292
|
},
|
|
3160
3293
|
ui: {
|
|
3161
|
-
title: (
|
|
3162
|
-
subtitle: (
|
|
3163
|
-
primaryColor: (
|
|
3164
|
-
accentColor: (
|
|
3165
|
-
logoUrl: (
|
|
3166
|
-
placeholder: (
|
|
3167
|
-
showSources: ((
|
|
3168
|
-
welcomeMessage: (
|
|
3169
|
-
visualStyle: (
|
|
3170
|
-
borderRadius: (
|
|
3171
|
-
allowUpload: ((
|
|
3294
|
+
title: (_hb = (_gb = readString(env, "NEXT_PUBLIC_UI_TITLE")) != null ? _gb : readString(env, "UI_TITLE")) != null ? _hb : "AI Assistant",
|
|
3295
|
+
subtitle: (_jb = (_ib = readString(env, "NEXT_PUBLIC_UI_SUBTITLE")) != null ? _ib : readString(env, "UI_SUBTITLE")) != null ? _jb : "Powered by RAG",
|
|
3296
|
+
primaryColor: (_lb = (_kb = readString(env, "NEXT_PUBLIC_PRIMARY_COLOR")) != null ? _kb : readString(env, "UI_PRIMARY_COLOR")) != null ? _lb : "#10b981",
|
|
3297
|
+
accentColor: (_nb = (_mb = readString(env, "NEXT_PUBLIC_ACCENT_COLOR")) != null ? _mb : readString(env, "UI_ACCENT_COLOR")) != null ? _nb : "#3b82f6",
|
|
3298
|
+
logoUrl: (_ob = readString(env, "NEXT_PUBLIC_LOGO_URL")) != null ? _ob : readString(env, "UI_LOGO_URL"),
|
|
3299
|
+
placeholder: (_qb = (_pb = readString(env, "NEXT_PUBLIC_PLACEHOLDER")) != null ? _pb : readString(env, "UI_PLACEHOLDER")) != null ? _qb : "Ask me anything\u2026",
|
|
3300
|
+
showSources: ((_sb = (_rb = readString(env, "NEXT_PUBLIC_SHOW_SOURCES")) != null ? _rb : readString(env, "UI_SHOW_SOURCES")) != null ? _sb : "true") !== "false",
|
|
3301
|
+
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.",
|
|
3302
|
+
visualStyle: (_wb = (_vb = readString(env, "NEXT_PUBLIC_UI_VISUAL_STYLE")) != null ? _vb : readString(env, "UI_VISUAL_STYLE")) != null ? _wb : "glass",
|
|
3303
|
+
borderRadius: (_yb = (_xb = readString(env, "NEXT_PUBLIC_UI_BORDER_RADIUS")) != null ? _xb : readString(env, "UI_BORDER_RADIUS")) != null ? _yb : "xl",
|
|
3304
|
+
allowUpload: ((_Ab = (_zb = readString(env, "NEXT_PUBLIC_ALLOW_UPLOAD")) != null ? _zb : readString(env, "UI_ALLOW_UPLOAD")) != null ? _Ab : "false") === "true"
|
|
3172
3305
|
},
|
|
3173
3306
|
rag: {
|
|
3174
3307
|
topK: readNumber(env, "RAG_TOP_K", 5),
|
|
3175
3308
|
scoreThreshold: readNumber(env, "RAG_SCORE_THRESHOLD", 0),
|
|
3176
3309
|
chunkSize: readNumber(env, "RAG_CHUNK_SIZE", 1e3),
|
|
3177
3310
|
chunkOverlap: readNumber(env, "RAG_CHUNK_OVERLAP", 200),
|
|
3178
|
-
filterableFields: (
|
|
3311
|
+
filterableFields: (_Bb = readString(env, "RAG_FILTERABLE_FIELDS")) == null ? void 0 : _Bb.split(",").map((f) => f.trim()),
|
|
3179
3312
|
// Query pipeline toggles — read from .env.local
|
|
3180
3313
|
useQueryTransformation: readString(env, "RAG_USE_QUERY_TRANSFORMATION") === "true",
|
|
3181
3314
|
useReranking: readString(env, "RAG_USE_RERANKING") === "true",
|
|
3182
3315
|
useGraphRetrieval: readString(env, "RAG_USE_GRAPH_RETRIEVAL") === "true",
|
|
3183
|
-
architecture: (
|
|
3184
|
-
chunkingStrategy: (
|
|
3316
|
+
architecture: (_Cb = readString(env, "RAG_ARCHITECTURE")) != null ? _Cb : "simple",
|
|
3317
|
+
chunkingStrategy: (_Db = readString(env, "RAG_CHUNKING_STRATEGY")) != null ? _Db : "recursive",
|
|
3185
3318
|
uiMapping: (() => {
|
|
3186
3319
|
const raw = readString(env, "RAG_UI_MAPPING");
|
|
3187
3320
|
if (!raw) return void 0;
|
|
@@ -3194,7 +3327,7 @@ function getEnvConfig(env = process.env, base) {
|
|
|
3194
3327
|
},
|
|
3195
3328
|
telemetry: {
|
|
3196
3329
|
enabled: telemetryEnabled,
|
|
3197
|
-
url: (
|
|
3330
|
+
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"
|
|
3198
3331
|
}
|
|
3199
3332
|
}, readString(env, "GRAPH_DB_PROVIDER") ? {
|
|
3200
3333
|
graphDb: {
|
|
@@ -3718,8 +3851,8 @@ var OllamaProvider = class {
|
|
|
3718
3851
|
const baseUrl = config.baseUrl || "http://localhost:11434";
|
|
3719
3852
|
const modelName = config.model;
|
|
3720
3853
|
try {
|
|
3721
|
-
const
|
|
3722
|
-
const { data } = await
|
|
3854
|
+
const axios11 = (await import("axios")).default;
|
|
3855
|
+
const { data } = await axios11.get(`${baseUrl}/api/tags`);
|
|
3723
3856
|
const models = data.models || [];
|
|
3724
3857
|
const hasModel = models.some((m) => m.name === modelName || m.name.startsWith(`${modelName}:`));
|
|
3725
3858
|
return {
|
|
@@ -4551,7 +4684,7 @@ var UniversalLLMAdapter = class {
|
|
|
4551
4684
|
});
|
|
4552
4685
|
}
|
|
4553
4686
|
async chat(messages, context) {
|
|
4554
|
-
var _a3, _b, _c, _d, _e;
|
|
4687
|
+
var _a3, _b, _c, _d, _e, _f, _g2, _h, _i, _j;
|
|
4555
4688
|
const path2 = (_a3 = this.opts.chatPath) != null ? _a3 : "/chat/completions";
|
|
4556
4689
|
const safeMessages = (Array.isArray(messages) ? messages : []).filter((m) => Boolean(m && typeof m === "object")).map((m) => ({
|
|
4557
4690
|
role: m.role || "user",
|
|
@@ -4581,16 +4714,27 @@ ${context != null ? context : "None"}` },
|
|
|
4581
4714
|
};
|
|
4582
4715
|
}
|
|
4583
4716
|
try {
|
|
4717
|
+
console.debug(`[UniversalLLMAdapter] POST ${this.baseUrl}${path2}`);
|
|
4718
|
+
console.debug(`[UniversalLLMAdapter] Model: ${this.model}`);
|
|
4719
|
+
console.debug(`[UniversalLLMAdapter] Auth: Bearer ${((_b = this.apiKey) == null ? void 0 : _b.substring(0, 20)) || "none"}...`);
|
|
4584
4720
|
const { data: data2 } = await this.http.post(path2, payload);
|
|
4585
|
-
const extractPath2 = (
|
|
4586
|
-
const result2 = (
|
|
4721
|
+
const extractPath2 = (_c = this.opts.responseExtractPath) != null ? _c : "choices[0].message.content";
|
|
4722
|
+
const result2 = (_d = resolvePath(data2, extractPath2)) != null ? _d : extractContent(data2);
|
|
4587
4723
|
if (result2 !== void 0) {
|
|
4588
4724
|
return String(result2);
|
|
4589
4725
|
}
|
|
4590
4726
|
} catch (httpErr) {
|
|
4591
|
-
|
|
4592
|
-
|
|
4727
|
+
console.error("[UniversalLLMAdapter] \u274C HTTP chat request failed:", {
|
|
4728
|
+
status: (_e = httpErr == null ? void 0 : httpErr.response) == null ? void 0 : _e.status,
|
|
4729
|
+
statusText: (_f = httpErr == null ? void 0 : httpErr.response) == null ? void 0 : _f.statusText,
|
|
4730
|
+
url: (_g2 = httpErr == null ? void 0 : httpErr.config) == null ? void 0 : _g2.url,
|
|
4731
|
+
errorData: (_h = httpErr == null ? void 0 : httpErr.response) == null ? void 0 : _h.data,
|
|
4732
|
+
message: httpErr == null ? void 0 : httpErr.message
|
|
4733
|
+
});
|
|
4734
|
+
const _g3 = globalThis;
|
|
4735
|
+
const dispatch = _g3.__retrivoraDispatchChat;
|
|
4593
4736
|
if (typeof dispatch === "function") {
|
|
4737
|
+
console.debug("[UniversalLLMAdapter] \u{1F504} Attempting in-process fallback dispatch");
|
|
4594
4738
|
const res = await dispatch({
|
|
4595
4739
|
model: this.model,
|
|
4596
4740
|
messages: formattedMessages,
|
|
@@ -4605,8 +4749,8 @@ ${context != null ? context : "None"}` },
|
|
|
4605
4749
|
throw httpErr;
|
|
4606
4750
|
}
|
|
4607
4751
|
const { data } = await this.http.post(path2, payload);
|
|
4608
|
-
const extractPath = (
|
|
4609
|
-
const result = (
|
|
4752
|
+
const extractPath = (_i = this.opts.responseExtractPath) != null ? _i : "choices[0].message.content";
|
|
4753
|
+
const result = (_j = resolvePath(data, extractPath)) != null ? _j : extractContent(data);
|
|
4610
4754
|
if (result === void 0) {
|
|
4611
4755
|
throw new Error(`[UniversalLLMAdapter] Could not extract text from path '${extractPath}' in response.`);
|
|
4612
4756
|
}
|
|
@@ -4745,36 +4889,70 @@ ${context != null ? context : "None"}` },
|
|
|
4745
4889
|
});
|
|
4746
4890
|
}
|
|
4747
4891
|
async embed(text) {
|
|
4748
|
-
var _a3, _b, _c, _d, _e;
|
|
4892
|
+
var _a3, _b, _c, _d, _e, _f, _g2;
|
|
4749
4893
|
const path2 = (_a3 = this.opts.embedPath) != null ? _a3 : "/embeddings";
|
|
4750
4894
|
const payload = this.opts.embedPayloadTemplate ? buildPayload(this.opts.embedPayloadTemplate, { input: text, model: this.model }) : { input: text, model: this.model };
|
|
4751
4895
|
try {
|
|
4752
|
-
const { data
|
|
4753
|
-
const
|
|
4754
|
-
const
|
|
4755
|
-
if (Array.isArray(
|
|
4756
|
-
|
|
4757
|
-
|
|
4758
|
-
|
|
4896
|
+
const { data } = await this.http.post(path2, payload);
|
|
4897
|
+
const extractPath = (_b = this.opts.embedExtractPath) != null ? _b : "data[0].embedding";
|
|
4898
|
+
const vector = resolvePath(data, extractPath);
|
|
4899
|
+
if (Array.isArray(vector)) return vector;
|
|
4900
|
+
console.warn(
|
|
4901
|
+
`[UniversalLLMAdapter] Embedding API returned unexpected format for path '${extractPath}'. Response:`,
|
|
4902
|
+
data
|
|
4903
|
+
);
|
|
4904
|
+
} catch (err) {
|
|
4905
|
+
console.warn(
|
|
4906
|
+
`[UniversalLLMAdapter] HTTP embedding request failed: ${(err == null ? void 0 : err.message) || err}`,
|
|
4907
|
+
{ path: path2, model: this.model }
|
|
4908
|
+
);
|
|
4909
|
+
const _g3 = globalThis;
|
|
4910
|
+
const dispatchEmbed = _g3.__retrivoraDispatchEmbedding;
|
|
4759
4911
|
if (typeof dispatchEmbed === "function") {
|
|
4760
|
-
|
|
4761
|
-
|
|
4762
|
-
|
|
4912
|
+
try {
|
|
4913
|
+
const res = await dispatchEmbed({ input: text, model: this.model }, this.apiKey);
|
|
4914
|
+
if ((_d = (_c = res == null ? void 0 : res.data) == null ? void 0 : _c[0]) == null ? void 0 : _d.embedding) {
|
|
4915
|
+
return res.data[0].embedding;
|
|
4916
|
+
}
|
|
4917
|
+
} catch (dispatchErr) {
|
|
4918
|
+
console.warn("[UniversalLLMAdapter] In-process dispatch embedding failed:", dispatchErr);
|
|
4763
4919
|
}
|
|
4764
4920
|
}
|
|
4765
4921
|
}
|
|
4766
|
-
|
|
4767
|
-
|
|
4768
|
-
|
|
4769
|
-
|
|
4770
|
-
|
|
4922
|
+
try {
|
|
4923
|
+
const { data } = await this.http.post(path2, payload);
|
|
4924
|
+
const extractPath = (_e = this.opts.embedExtractPath) != null ? _e : "data[0].embedding";
|
|
4925
|
+
const vector = resolvePath(data, extractPath);
|
|
4926
|
+
if (Array.isArray(vector)) {
|
|
4927
|
+
return vector;
|
|
4928
|
+
}
|
|
4929
|
+
console.error(
|
|
4930
|
+
`[UniversalLLMAdapter] Retry embedding failed: unexpected response format for path '${extractPath}'. Response:`,
|
|
4931
|
+
data
|
|
4932
|
+
);
|
|
4933
|
+
throw new Error(
|
|
4934
|
+
`[UniversalLLMAdapter] Could not extract embedding vector. Expected array at '${extractPath}', got: ${typeof vector}. Response keys: ${Object.keys(data || {})}.`
|
|
4935
|
+
);
|
|
4936
|
+
} catch (err) {
|
|
4937
|
+
console.error(
|
|
4938
|
+
`[UniversalLLMAdapter] Both embedding attempts failed. Path: ${path2}, Model: ${this.model}`,
|
|
4939
|
+
{ 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 }
|
|
4940
|
+
);
|
|
4941
|
+
throw new Error(
|
|
4942
|
+
`[UniversalLLMAdapter] Failed to generate embedding after 2 attempts: ${(err == null ? void 0 : err.message) || err}`
|
|
4943
|
+
);
|
|
4771
4944
|
}
|
|
4772
|
-
return vector;
|
|
4773
4945
|
}
|
|
4774
4946
|
async batchEmbed(texts) {
|
|
4775
4947
|
const results = [];
|
|
4776
4948
|
for (const text of texts) {
|
|
4777
|
-
|
|
4949
|
+
try {
|
|
4950
|
+
const vector = await this.embed(text);
|
|
4951
|
+
results.push(vector);
|
|
4952
|
+
} catch (err) {
|
|
4953
|
+
console.warn(`[UniversalLLMAdapter] batchEmbed failed for text (first 50 chars): ${text.slice(0, 50)}...`, err);
|
|
4954
|
+
throw err;
|
|
4955
|
+
}
|
|
4778
4956
|
}
|
|
4779
4957
|
return results;
|
|
4780
4958
|
}
|
|
@@ -9894,7 +10072,7 @@ var Retrivora = class {
|
|
|
9894
10072
|
var _a3;
|
|
9895
10073
|
try {
|
|
9896
10074
|
await ConfigValidator.validateAndThrow(this.config);
|
|
9897
|
-
LicenseVerifier.
|
|
10075
|
+
await LicenseVerifier.verifyAsync(
|
|
9898
10076
|
this.config.licenseKey,
|
|
9899
10077
|
this.config.projectId,
|
|
9900
10078
|
(_a3 = this.config.vectorDb) == null ? void 0 : _a3.provider
|
|
@@ -10260,7 +10438,7 @@ var VectorPlugin = class {
|
|
|
10260
10438
|
this.validationPromise = (async () => {
|
|
10261
10439
|
var _a3;
|
|
10262
10440
|
await ConfigValidator.validateAndThrow(resolvedConfig);
|
|
10263
|
-
LicenseVerifier.
|
|
10441
|
+
await LicenseVerifier.verifyAsync(
|
|
10264
10442
|
resolvedConfig.licenseKey,
|
|
10265
10443
|
resolvedConfig.projectId,
|
|
10266
10444
|
(_a3 = resolvedConfig.vectorDb) == null ? void 0 : _a3.provider
|
|
@@ -10754,7 +10932,7 @@ var DatabaseStorage = class {
|
|
|
10754
10932
|
* In non-production (development / test) environments this is a complete no-op —
|
|
10755
10933
|
* all History and Feedback features are freely accessible for local development.
|
|
10756
10934
|
*/
|
|
10757
|
-
checkPremiumSubscription() {
|
|
10935
|
+
async checkPremiumSubscription() {
|
|
10758
10936
|
if (process.env.NODE_ENV !== "production") {
|
|
10759
10937
|
return;
|
|
10760
10938
|
}
|
|
@@ -10764,7 +10942,7 @@ var DatabaseStorage = class {
|
|
|
10764
10942
|
);
|
|
10765
10943
|
}
|
|
10766
10944
|
try {
|
|
10767
|
-
const payload = LicenseVerifier.
|
|
10945
|
+
const payload = await LicenseVerifier.verifyAsync(this.config.licenseKey, this.config.projectId);
|
|
10768
10946
|
const tier = (payload.tier || "").toLowerCase();
|
|
10769
10947
|
if (tier !== "premium" && tier !== "enterprise" && tier !== "growth" && tier !== "pro" && tier !== "developer_pro" && tier !== "free_trial" && tier !== "free_tier" && tier !== "free" && tier !== "hobby") {
|
|
10770
10948
|
throw new Error(
|
|
@@ -10777,16 +10955,16 @@ var DatabaseStorage = class {
|
|
|
10777
10955
|
);
|
|
10778
10956
|
}
|
|
10779
10957
|
}
|
|
10780
|
-
checkHistoryEnabled() {
|
|
10958
|
+
async checkHistoryEnabled() {
|
|
10781
10959
|
var _a3, _b;
|
|
10782
|
-
this.checkPremiumSubscription();
|
|
10960
|
+
await this.checkPremiumSubscription();
|
|
10783
10961
|
if (((_b = (_a3 = this.config.rag) == null ? void 0 : _a3.history) == null ? void 0 : _b.enabled) === false) {
|
|
10784
10962
|
throw new Error("[Retrivora SDK] Chat History is disabled in RagConfig.");
|
|
10785
10963
|
}
|
|
10786
10964
|
}
|
|
10787
|
-
checkFeedbackEnabled() {
|
|
10965
|
+
async checkFeedbackEnabled() {
|
|
10788
10966
|
var _a3, _b;
|
|
10789
|
-
this.checkPremiumSubscription();
|
|
10967
|
+
await this.checkPremiumSubscription();
|
|
10790
10968
|
if (((_b = (_a3 = this.config.rag) == null ? void 0 : _a3.feedback) == null ? void 0 : _b.enabled) === false) {
|
|
10791
10969
|
throw new Error("[Retrivora SDK] User Feedback is disabled in RagConfig.");
|
|
10792
10970
|
}
|
|
@@ -10892,7 +11070,7 @@ var DatabaseStorage = class {
|
|
|
10892
11070
|
}
|
|
10893
11071
|
// ─── Message History Operations ──────────────────────────────────────────
|
|
10894
11072
|
async saveMessage(sessionId, message) {
|
|
10895
|
-
this.checkHistoryEnabled();
|
|
11073
|
+
await this.checkHistoryEnabled();
|
|
10896
11074
|
const createdAt = (/* @__PURE__ */ new Date()).toISOString();
|
|
10897
11075
|
const msgId = message.id || `msg_${Date.now()}_${Math.random().toString(36).slice(2, 6)}`;
|
|
10898
11076
|
if (this.provider === "postgresql" || this.provider === "pgvector") {
|
|
@@ -10955,7 +11133,7 @@ var DatabaseStorage = class {
|
|
|
10955
11133
|
}
|
|
10956
11134
|
}
|
|
10957
11135
|
async getHistory(sessionId, projectIds) {
|
|
10958
|
-
this.checkHistoryEnabled();
|
|
11136
|
+
await this.checkHistoryEnabled();
|
|
10959
11137
|
if (projectIds && projectIds.length > 0 && !this.sessionInScope(sessionId, projectIds)) {
|
|
10960
11138
|
return [];
|
|
10961
11139
|
}
|
|
@@ -10989,7 +11167,7 @@ var DatabaseStorage = class {
|
|
|
10989
11167
|
}
|
|
10990
11168
|
}
|
|
10991
11169
|
async clearHistory(sessionId, projectIds) {
|
|
10992
|
-
this.checkHistoryEnabled();
|
|
11170
|
+
await this.checkHistoryEnabled();
|
|
10993
11171
|
if (projectIds && projectIds.length > 0 && !this.sessionInScope(sessionId, projectIds)) {
|
|
10994
11172
|
return;
|
|
10995
11173
|
}
|
|
@@ -11025,7 +11203,7 @@ var DatabaseStorage = class {
|
|
|
11025
11203
|
);
|
|
11026
11204
|
}
|
|
11027
11205
|
async listSessions(projectIds) {
|
|
11028
|
-
this.checkHistoryEnabled();
|
|
11206
|
+
await this.checkHistoryEnabled();
|
|
11029
11207
|
let raw = [];
|
|
11030
11208
|
if (this.provider === "postgresql" || this.provider === "pgvector") {
|
|
11031
11209
|
const pool = await this.getPGPool();
|
|
@@ -11044,7 +11222,7 @@ var DatabaseStorage = class {
|
|
|
11044
11222
|
}
|
|
11045
11223
|
// ─── Feedback Operations ──────────────────────────────────────────────────
|
|
11046
11224
|
async saveFeedback(feedback) {
|
|
11047
|
-
this.checkFeedbackEnabled();
|
|
11225
|
+
await this.checkFeedbackEnabled();
|
|
11048
11226
|
const id = `fb_${Date.now()}_${Math.random().toString(36).slice(2, 6)}`;
|
|
11049
11227
|
const createdAt = (/* @__PURE__ */ new Date()).toISOString();
|
|
11050
11228
|
if (this.provider === "postgresql" || this.provider === "pgvector") {
|
|
@@ -11094,7 +11272,7 @@ var DatabaseStorage = class {
|
|
|
11094
11272
|
}
|
|
11095
11273
|
}
|
|
11096
11274
|
async getFeedback(messageId, projectIds) {
|
|
11097
|
-
this.checkFeedbackEnabled();
|
|
11275
|
+
await this.checkFeedbackEnabled();
|
|
11098
11276
|
let item = null;
|
|
11099
11277
|
if (this.provider === "postgresql" || this.provider === "pgvector") {
|
|
11100
11278
|
const pool = await this.getPGPool();
|
|
@@ -11130,7 +11308,7 @@ var DatabaseStorage = class {
|
|
|
11130
11308
|
return item;
|
|
11131
11309
|
}
|
|
11132
11310
|
async listFeedback(projectIds) {
|
|
11133
|
-
this.checkFeedbackEnabled();
|
|
11311
|
+
await this.checkFeedbackEnabled();
|
|
11134
11312
|
let raw = [];
|
|
11135
11313
|
if (this.provider === "postgresql" || this.provider === "pgvector") {
|
|
11136
11314
|
const pool = await this.getPGPool();
|
|
@@ -11280,12 +11458,23 @@ function resolveLicenseKey(req, config, bodyLicenseKey) {
|
|
|
11280
11458
|
var _a3;
|
|
11281
11459
|
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 || "";
|
|
11282
11460
|
}
|
|
11283
|
-
function enforceLicense(req, config, bodyLicenseKey) {
|
|
11461
|
+
async function enforceLicense(req, config, bodyLicenseKey) {
|
|
11284
11462
|
const rawKey = resolveLicenseKey(req, config, bodyLicenseKey);
|
|
11285
11463
|
const licenseKey = (rawKey || "").trim().replace(/^["']|["']$/g, "").trim();
|
|
11286
11464
|
const projectId = config.projectId || "";
|
|
11287
11465
|
try {
|
|
11288
|
-
|
|
11466
|
+
let payload;
|
|
11467
|
+
try {
|
|
11468
|
+
payload = await LicenseVerifier.verifyAsync(licenseKey, projectId);
|
|
11469
|
+
} catch (err) {
|
|
11470
|
+
return {
|
|
11471
|
+
ok: false,
|
|
11472
|
+
response: import_server.NextResponse.json(
|
|
11473
|
+
{ error: `License validation failed: ${err.message}` },
|
|
11474
|
+
{ status: 401 }
|
|
11475
|
+
)
|
|
11476
|
+
};
|
|
11477
|
+
}
|
|
11289
11478
|
return { ok: true, payload };
|
|
11290
11479
|
} catch (err) {
|
|
11291
11480
|
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.";
|
|
@@ -11460,7 +11649,7 @@ function createChatHandler(configOrPlugin, options) {
|
|
|
11460
11649
|
try {
|
|
11461
11650
|
const body = await req.json();
|
|
11462
11651
|
const bodyObj = body != null ? body : {};
|
|
11463
|
-
const licenseCheck = enforceLicense(req, config, bodyObj == null ? void 0 : bodyObj.licenseKey);
|
|
11652
|
+
const licenseCheck = await enforceLicense(req, config, bodyObj == null ? void 0 : bodyObj.licenseKey);
|
|
11464
11653
|
if (!licenseCheck.ok) return licenseCheck.response;
|
|
11465
11654
|
if (isFreeTier(licenseCheck.payload.tier)) {
|
|
11466
11655
|
const estimatedInputTokens = Math.ceil(
|
|
@@ -11554,7 +11743,7 @@ function createStreamHandler(configOrPlugin, options) {
|
|
|
11554
11743
|
});
|
|
11555
11744
|
}
|
|
11556
11745
|
const bodyObj = body != null ? body : {};
|
|
11557
|
-
const licenseCheck = enforceLicense(req, config, bodyObj == null ? void 0 : bodyObj.licenseKey);
|
|
11746
|
+
const licenseCheck = await enforceLicense(req, config, bodyObj == null ? void 0 : bodyObj.licenseKey);
|
|
11558
11747
|
if (!licenseCheck.ok) return licenseCheck.response;
|
|
11559
11748
|
if (isFreeTier(licenseCheck.payload.tier)) {
|
|
11560
11749
|
const estimatedInputTokens = Math.ceil(
|
|
@@ -11719,7 +11908,7 @@ function createIngestHandler(configOrPlugin, options) {
|
|
|
11719
11908
|
const config = plugin.getConfig();
|
|
11720
11909
|
try {
|
|
11721
11910
|
const body = await req.json();
|
|
11722
|
-
const licenseCheck = enforceLicense(req, config, body == null ? void 0 : body.licenseKey);
|
|
11911
|
+
const licenseCheck = await enforceLicense(req, config, body == null ? void 0 : body.licenseKey);
|
|
11723
11912
|
if (!licenseCheck.ok) return licenseCheck.response;
|
|
11724
11913
|
const { documents, namespace } = body;
|
|
11725
11914
|
if (!Array.isArray(documents) || documents.length === 0) {
|
|
@@ -11795,7 +11984,7 @@ function createLicenseHandler(configOrPlugin, options) {
|
|
|
11795
11984
|
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 || "";
|
|
11796
11985
|
const licenseKey = (rawKey || "").trim().replace(/^["']|["']$/g, "").trim();
|
|
11797
11986
|
const projectId = (body == null ? void 0 : body.projectId) || config.projectId || "";
|
|
11798
|
-
const payload = LicenseVerifier.
|
|
11987
|
+
const payload = await LicenseVerifier.verifyAsync(licenseKey, projectId);
|
|
11799
11988
|
return import_server.NextResponse.json({
|
|
11800
11989
|
valid: true,
|
|
11801
11990
|
licenseStatus: "ACTIVE",
|
|
@@ -11825,14 +12014,16 @@ function createUploadHandler(configOrPlugin, options) {
|
|
|
11825
12014
|
const plugin = getOrCreatePlugin(configOrPlugin);
|
|
11826
12015
|
const onAuthorize = options == null ? void 0 : options.onAuthorize;
|
|
11827
12016
|
return async function POST(req, context) {
|
|
12017
|
+
console.log("Upload handler invoked");
|
|
11828
12018
|
const authResult = await checkAuth(req, onAuthorize);
|
|
11829
12019
|
if (authResult) return authResult;
|
|
11830
12020
|
const config = plugin.getConfig();
|
|
11831
|
-
const licenseCheck = enforceLicense(req, config);
|
|
12021
|
+
const licenseCheck = await enforceLicense(req, config);
|
|
11832
12022
|
if (!licenseCheck.ok) return licenseCheck.response;
|
|
11833
12023
|
try {
|
|
11834
12024
|
const formData = await req.formData();
|
|
11835
12025
|
const files = formData.getAll("files");
|
|
12026
|
+
console.log("Files received for upload:", files.map((f) => f.name));
|
|
11836
12027
|
const namespace = formData.get("namespace") || void 0;
|
|
11837
12028
|
const dimensionRaw = formData.get("dimension");
|
|
11838
12029
|
const dimension = dimensionRaw ? parseInt(dimensionRaw, 10) : void 0;
|
|
@@ -11971,7 +12162,7 @@ function createSuggestionsHandler(configOrPlugin, options) {
|
|
|
11971
12162
|
const authResult = await checkAuth(req, onAuthorize);
|
|
11972
12163
|
if (authResult) return authResult;
|
|
11973
12164
|
const config = plugin.getConfig();
|
|
11974
|
-
const licenseCheck = enforceLicense(req, config);
|
|
12165
|
+
const licenseCheck = await enforceLicense(req, config);
|
|
11975
12166
|
if (!licenseCheck.ok) return licenseCheck.response;
|
|
11976
12167
|
let effectiveLicensePayload = licenseCheck.payload;
|
|
11977
12168
|
try {
|
|
@@ -11984,7 +12175,7 @@ function createSuggestionsHandler(configOrPlugin, options) {
|
|
|
11984
12175
|
namespace = body.namespace;
|
|
11985
12176
|
bodyLicenseKey = body.licenseKey;
|
|
11986
12177
|
if (bodyLicenseKey) {
|
|
11987
|
-
const recheck = enforceLicense(req, config, bodyLicenseKey);
|
|
12178
|
+
const recheck = await enforceLicense(req, config, bodyLicenseKey);
|
|
11988
12179
|
if (!recheck.ok) return recheck.response;
|
|
11989
12180
|
effectiveLicensePayload = recheck.payload;
|
|
11990
12181
|
}
|
|
@@ -12275,6 +12466,7 @@ var _LicenseValidator = class _LicenseValidator {
|
|
|
12275
12466
|
retrivoraApiBase,
|
|
12276
12467
|
headers: customHeaders
|
|
12277
12468
|
} = request;
|
|
12469
|
+
const effectiveProjectId = projectId || (typeof process !== "undefined" ? process.env.NEXT_PUBLIC_RETRIVORA_PROJECT_ID || process.env.RETRIVORA_PROJECT_ID : "") || "";
|
|
12278
12470
|
const getHeader = (name) => {
|
|
12279
12471
|
if (!customHeaders) return void 0;
|
|
12280
12472
|
const target = name.toLowerCase();
|
|
@@ -12312,7 +12504,7 @@ var _LicenseValidator = class _LicenseValidator {
|
|
|
12312
12504
|
}, customHeaders || {}),
|
|
12313
12505
|
body: JSON.stringify({
|
|
12314
12506
|
licenseKey: effectiveLicenseKey,
|
|
12315
|
-
projectId,
|
|
12507
|
+
projectId: effectiveProjectId,
|
|
12316
12508
|
sdkVersion,
|
|
12317
12509
|
sdk,
|
|
12318
12510
|
platform
|
|
@@ -12323,7 +12515,7 @@ var _LicenseValidator = class _LicenseValidator {
|
|
|
12323
12515
|
if (!canUseLocalValidationFallback(base)) {
|
|
12324
12516
|
throw err;
|
|
12325
12517
|
}
|
|
12326
|
-
const payload = LicenseVerifier.
|
|
12518
|
+
const payload = await LicenseVerifier.verifyAsync(effectiveLicenseKey, effectiveProjectId);
|
|
12327
12519
|
const fallbackResp = {
|
|
12328
12520
|
valid: true,
|
|
12329
12521
|
licenseStatus: "ACTIVE",
|
|
@@ -12342,7 +12534,7 @@ var _LicenseValidator = class _LicenseValidator {
|
|
|
12342
12534
|
}
|
|
12343
12535
|
if (res && !res.ok && canUseLocalValidationFallback(base, res.status)) {
|
|
12344
12536
|
try {
|
|
12345
|
-
const payload = LicenseVerifier.
|
|
12537
|
+
const payload = await LicenseVerifier.verifyAsync(effectiveLicenseKey, effectiveProjectId);
|
|
12346
12538
|
const fallbackResp = {
|
|
12347
12539
|
valid: true,
|
|
12348
12540
|
licenseStatus: "ACTIVE",
|
|
@@ -12386,6 +12578,583 @@ var _LicenseValidator = class _LicenseValidator {
|
|
|
12386
12578
|
};
|
|
12387
12579
|
_LicenseValidator.SUCCESS_CACHE_TTL_MS = 5 * 60 * 1e3;
|
|
12388
12580
|
var LicenseValidator = _LicenseValidator;
|
|
12581
|
+
|
|
12582
|
+
// src/config/LicenseConfigResolver.ts
|
|
12583
|
+
var import_axios9 = __toESM(require("axios"));
|
|
12584
|
+
var LicenseConfigResolver = class {
|
|
12585
|
+
/**
|
|
12586
|
+
* Validate and resolve configuration from license key
|
|
12587
|
+
* @param licenseKey JWT token from Retrivora (format: rtv_eyJ...)
|
|
12588
|
+
* @param projectId Workspace identifier
|
|
12589
|
+
* @returns Resolved LLM and embedding configs with provider credentials
|
|
12590
|
+
*/
|
|
12591
|
+
static async resolveFromLicense(licenseKey, projectId) {
|
|
12592
|
+
const cacheKey = `${licenseKey}:${projectId}`;
|
|
12593
|
+
const cached = this.configCache.get(cacheKey);
|
|
12594
|
+
if (cached && Date.now() - cached.timestamp < this.CACHE_TTL_MS) {
|
|
12595
|
+
console.log("[LicenseConfigResolver] Using cached config for", projectId);
|
|
12596
|
+
return this.buildConfigs(cached.config, cached.credentials, licenseKey, projectId);
|
|
12597
|
+
}
|
|
12598
|
+
console.log("[LicenseConfigResolver] Fetching tier config from Retrivora...");
|
|
12599
|
+
const tierConfig = await this.fetchTierConfig(licenseKey, projectId);
|
|
12600
|
+
console.log("[LicenseConfigResolver] Fetching provider credentials from Retrivora...");
|
|
12601
|
+
const credentials = await this.fetchProviderCredentials(licenseKey, projectId);
|
|
12602
|
+
this.configCache.set(cacheKey, { config: tierConfig, credentials, timestamp: Date.now() });
|
|
12603
|
+
console.log("[LicenseConfigResolver] \u2705 Successfully resolved config from Retrivora:", {
|
|
12604
|
+
tier: tierConfig.tier,
|
|
12605
|
+
llmModel: tierConfig.llmModel,
|
|
12606
|
+
embeddingModel: tierConfig.embeddingModel
|
|
12607
|
+
});
|
|
12608
|
+
return this.buildConfigs(tierConfig, credentials, licenseKey, projectId);
|
|
12609
|
+
}
|
|
12610
|
+
/**
|
|
12611
|
+
* Fetch tier configuration from Retrivora config API
|
|
12612
|
+
*/
|
|
12613
|
+
static async fetchTierConfig(licenseKey, projectId) {
|
|
12614
|
+
try {
|
|
12615
|
+
const response = await import_axios9.default.post(
|
|
12616
|
+
this.RETRIVORA_CONFIG_URL,
|
|
12617
|
+
{ licenseKey, projectId },
|
|
12618
|
+
{
|
|
12619
|
+
headers: {
|
|
12620
|
+
"Content-Type": "application/json",
|
|
12621
|
+
Authorization: `Bearer ${licenseKey}`,
|
|
12622
|
+
"X-License-Key": licenseKey,
|
|
12623
|
+
"X-Project-ID": projectId
|
|
12624
|
+
},
|
|
12625
|
+
timeout: 1e4
|
|
12626
|
+
}
|
|
12627
|
+
);
|
|
12628
|
+
if (!response.data.success || !response.data.config) {
|
|
12629
|
+
throw new Error(
|
|
12630
|
+
`[LicenseConfigResolver] Config API returned error: ${response.data.error || response.data.message}`
|
|
12631
|
+
);
|
|
12632
|
+
}
|
|
12633
|
+
console.log(`[LicenseConfigResolver] Resolved tier: ${response.data.config.tier}`);
|
|
12634
|
+
return response.data.config;
|
|
12635
|
+
} catch (err) {
|
|
12636
|
+
console.error("[LicenseConfigResolver] Failed to fetch config:", err.message);
|
|
12637
|
+
throw new Error(
|
|
12638
|
+
`[LicenseConfigResolver] Could not validate license key or fetch tier configuration: ${err.message}`
|
|
12639
|
+
);
|
|
12640
|
+
}
|
|
12641
|
+
}
|
|
12642
|
+
/**
|
|
12643
|
+
* Fetch provider credentials from Retrivora credentials API
|
|
12644
|
+
*/
|
|
12645
|
+
static async fetchProviderCredentials(licenseKey, projectId) {
|
|
12646
|
+
try {
|
|
12647
|
+
const response = await import_axios9.default.post(
|
|
12648
|
+
this.RETRIVORA_CREDENTIALS_URL,
|
|
12649
|
+
{ licenseKey, projectId },
|
|
12650
|
+
{
|
|
12651
|
+
headers: {
|
|
12652
|
+
"Content-Type": "application/json",
|
|
12653
|
+
Authorization: `Bearer ${licenseKey}`,
|
|
12654
|
+
"X-License-Key": licenseKey,
|
|
12655
|
+
"X-Project-ID": projectId
|
|
12656
|
+
},
|
|
12657
|
+
timeout: 1e4
|
|
12658
|
+
}
|
|
12659
|
+
);
|
|
12660
|
+
if (!response.data.success || !response.data.credentials) {
|
|
12661
|
+
throw new Error(
|
|
12662
|
+
`[LicenseConfigResolver] Credentials API returned error: ${response.data.error || response.data.message}`
|
|
12663
|
+
);
|
|
12664
|
+
}
|
|
12665
|
+
console.log(`[LicenseConfigResolver] Retrieved provider credentials for project: ${projectId}`);
|
|
12666
|
+
return response.data.credentials;
|
|
12667
|
+
} catch (err) {
|
|
12668
|
+
console.error("[LicenseConfigResolver] Failed to fetch credentials:", err.message);
|
|
12669
|
+
throw new Error(
|
|
12670
|
+
`[LicenseConfigResolver] Could not fetch provider credentials: ${err.message}`
|
|
12671
|
+
);
|
|
12672
|
+
}
|
|
12673
|
+
}
|
|
12674
|
+
/**
|
|
12675
|
+
* Build LLM, embedding, and vector DB configs from tier and credentials
|
|
12676
|
+
*/
|
|
12677
|
+
static buildConfigs(tierConfig, credentials, licenseKey, projectId) {
|
|
12678
|
+
let llmProvider = "gemini";
|
|
12679
|
+
let llmApiKey = credentials.geminiApiKey || licenseKey;
|
|
12680
|
+
if (tierConfig.llmModel.includes("gpt")) {
|
|
12681
|
+
llmProvider = "openai";
|
|
12682
|
+
} else if (tierConfig.llmModel.includes("groq") || tierConfig.llmModel.includes("llama")) {
|
|
12683
|
+
llmProvider = "groq";
|
|
12684
|
+
llmApiKey = credentials.groqApiKey || licenseKey;
|
|
12685
|
+
}
|
|
12686
|
+
const llmConfig = {
|
|
12687
|
+
provider: llmProvider,
|
|
12688
|
+
model: tierConfig.llmModel,
|
|
12689
|
+
apiKey: llmApiKey,
|
|
12690
|
+
maxTokens: tierConfig.maxTokens,
|
|
12691
|
+
temperature: 0.7,
|
|
12692
|
+
options: {}
|
|
12693
|
+
};
|
|
12694
|
+
const embeddingConfig = {
|
|
12695
|
+
provider: "gemini",
|
|
12696
|
+
model: tierConfig.embeddingModel,
|
|
12697
|
+
apiKey: credentials.geminiApiKey || licenseKey,
|
|
12698
|
+
dimensions: tierConfig.embeddingDimensions,
|
|
12699
|
+
options: {}
|
|
12700
|
+
};
|
|
12701
|
+
const vectorDbConfig = {
|
|
12702
|
+
provider: tierConfig.vectorDb.provider,
|
|
12703
|
+
indexName: tierConfig.vectorDb.indexName,
|
|
12704
|
+
options: this.getVectorDbOptions(tierConfig.vectorDb.provider, projectId, credentials)
|
|
12705
|
+
};
|
|
12706
|
+
return { llmConfig, embeddingConfig, vectorDbConfig, tierConfig, credentials };
|
|
12707
|
+
}
|
|
12708
|
+
/**
|
|
12709
|
+
* Get provider-specific vector DB options
|
|
12710
|
+
*/
|
|
12711
|
+
static getVectorDbOptions(provider, projectId, credentials) {
|
|
12712
|
+
switch (provider) {
|
|
12713
|
+
case "pinecone":
|
|
12714
|
+
return {
|
|
12715
|
+
apiKey: credentials.pineconeApiKey,
|
|
12716
|
+
indexName: `retrivora-${projectId}`
|
|
12717
|
+
};
|
|
12718
|
+
case "pgvector":
|
|
12719
|
+
case "postgresql":
|
|
12720
|
+
return {
|
|
12721
|
+
tables: [`documents_${projectId}`]
|
|
12722
|
+
};
|
|
12723
|
+
case "mongodb":
|
|
12724
|
+
return {
|
|
12725
|
+
database: `retrivora_${projectId}`,
|
|
12726
|
+
collection: `vectors_${projectId}`
|
|
12727
|
+
};
|
|
12728
|
+
case "qdrant":
|
|
12729
|
+
return {
|
|
12730
|
+
collection: `retrivora_${projectId}`
|
|
12731
|
+
};
|
|
12732
|
+
default:
|
|
12733
|
+
return {};
|
|
12734
|
+
}
|
|
12735
|
+
}
|
|
12736
|
+
/**
|
|
12737
|
+
* Clear configuration cache (useful for testing or manual refresh)
|
|
12738
|
+
*/
|
|
12739
|
+
static clearCache() {
|
|
12740
|
+
this.configCache.clear();
|
|
12741
|
+
console.log("[LicenseConfigResolver] Configuration cache cleared");
|
|
12742
|
+
}
|
|
12743
|
+
/**
|
|
12744
|
+
* Get cache stats for debugging
|
|
12745
|
+
*/
|
|
12746
|
+
static getCacheStats() {
|
|
12747
|
+
return {
|
|
12748
|
+
size: this.configCache.size,
|
|
12749
|
+
entries: Array.from(this.configCache.keys())
|
|
12750
|
+
};
|
|
12751
|
+
}
|
|
12752
|
+
};
|
|
12753
|
+
LicenseConfigResolver.RETRIVORA_CONFIG_URL = "https://www.retrivora.com/api/v1/config";
|
|
12754
|
+
LicenseConfigResolver.RETRIVORA_CREDENTIALS_URL = "https://www.retrivora.com/api/v1/credentials";
|
|
12755
|
+
LicenseConfigResolver.CACHE_TTL_MS = 36e5;
|
|
12756
|
+
// 1 hour
|
|
12757
|
+
LicenseConfigResolver.configCache = /* @__PURE__ */ new Map();
|
|
12758
|
+
|
|
12759
|
+
// src/telemetry/TelemetryService.ts
|
|
12760
|
+
var import_axios10 = __toESM(require("axios"));
|
|
12761
|
+
var EventType = /* @__PURE__ */ ((EventType2) => {
|
|
12762
|
+
EventType2["EMBEDDING_GENERATED"] = "embedding_generated";
|
|
12763
|
+
EventType2["LLM_CHAT_COMPLETION"] = "llm_chat_completion";
|
|
12764
|
+
EventType2["DOCUMENT_INGESTED"] = "document_ingested";
|
|
12765
|
+
EventType2["QUERY_EXECUTED"] = "query_executed";
|
|
12766
|
+
EventType2["ERROR_OCCURRED"] = "error_occurred";
|
|
12767
|
+
EventType2["CONFIGURATION_LOADED"] = "configuration_loaded";
|
|
12768
|
+
return EventType2;
|
|
12769
|
+
})(EventType || {});
|
|
12770
|
+
var _TelemetryService = class _TelemetryService {
|
|
12771
|
+
constructor(projectId, licenseKey, userTelemetryUrl) {
|
|
12772
|
+
this.batchSize = 10;
|
|
12773
|
+
this.flushIntervalMs = 3e4;
|
|
12774
|
+
// 30 seconds
|
|
12775
|
+
this.eventQueue = [];
|
|
12776
|
+
this.enabled = true;
|
|
12777
|
+
this.projectId = projectId;
|
|
12778
|
+
this.licenseKey = licenseKey;
|
|
12779
|
+
this.userTelemetryUrl = userTelemetryUrl || process.env[_TelemetryService.USER_TELEMETRY_URL_ENV_KEY];
|
|
12780
|
+
this.http = import_axios10.default.create({
|
|
12781
|
+
timeout: 5e3,
|
|
12782
|
+
headers: {
|
|
12783
|
+
"Content-Type": "application/json",
|
|
12784
|
+
"X-License-Key": licenseKey,
|
|
12785
|
+
"X-Project-ID": projectId
|
|
12786
|
+
}
|
|
12787
|
+
});
|
|
12788
|
+
this.startAutoFlush();
|
|
12789
|
+
}
|
|
12790
|
+
/**
|
|
12791
|
+
* Record a telemetry event
|
|
12792
|
+
*/
|
|
12793
|
+
recordEvent(event) {
|
|
12794
|
+
if (!this.enabled) return;
|
|
12795
|
+
const _a3 = event, { licenseKey } = _a3, safeEvent = __objRest(_a3, ["licenseKey"]);
|
|
12796
|
+
const completeEvent = __spreadValues({
|
|
12797
|
+
eventType: event.eventType || "error_occurred" /* ERROR_OCCURRED */,
|
|
12798
|
+
projectId: this.projectId,
|
|
12799
|
+
timestamp: event.timestamp || Date.now()
|
|
12800
|
+
}, safeEvent);
|
|
12801
|
+
this.eventQueue.push(completeEvent);
|
|
12802
|
+
if (this.eventQueue.length >= this.batchSize) {
|
|
12803
|
+
this.flush().catch((err) => {
|
|
12804
|
+
console.warn("[TelemetryService] Flush error:", err.message);
|
|
12805
|
+
});
|
|
12806
|
+
}
|
|
12807
|
+
}
|
|
12808
|
+
/**
|
|
12809
|
+
* Record LLM completion event
|
|
12810
|
+
*/
|
|
12811
|
+
recordLLMCompletion(data) {
|
|
12812
|
+
this.recordEvent({
|
|
12813
|
+
eventType: "llm_chat_completion" /* LLM_CHAT_COMPLETION */,
|
|
12814
|
+
model: data.model,
|
|
12815
|
+
inputTokens: data.inputTokens,
|
|
12816
|
+
outputTokens: data.outputTokens,
|
|
12817
|
+
totalTokens: data.inputTokens + data.outputTokens,
|
|
12818
|
+
durationMs: data.durationMs,
|
|
12819
|
+
operationId: data.operationId,
|
|
12820
|
+
metadata: data.metadata
|
|
12821
|
+
});
|
|
12822
|
+
}
|
|
12823
|
+
/**
|
|
12824
|
+
* Record embedding generation event
|
|
12825
|
+
*/
|
|
12826
|
+
recordEmbeddingGenerated(data) {
|
|
12827
|
+
this.recordEvent({
|
|
12828
|
+
eventType: "embedding_generated" /* EMBEDDING_GENERATED */,
|
|
12829
|
+
embeddingModel: data.embeddingModel,
|
|
12830
|
+
vectorDimensions: data.vectorDimensions,
|
|
12831
|
+
textLength: data.textLength,
|
|
12832
|
+
durationMs: data.durationMs,
|
|
12833
|
+
operationId: data.operationId
|
|
12834
|
+
});
|
|
12835
|
+
}
|
|
12836
|
+
/**
|
|
12837
|
+
* Record document ingestion event
|
|
12838
|
+
*/
|
|
12839
|
+
recordDocumentIngested(data) {
|
|
12840
|
+
this.recordEvent({
|
|
12841
|
+
eventType: "document_ingested" /* DOCUMENT_INGESTED */,
|
|
12842
|
+
documentId: data.documentId,
|
|
12843
|
+
documentName: data.documentName,
|
|
12844
|
+
documentSize: data.documentSize,
|
|
12845
|
+
chunksGenerated: data.chunksGenerated,
|
|
12846
|
+
durationMs: data.durationMs
|
|
12847
|
+
});
|
|
12848
|
+
}
|
|
12849
|
+
/**
|
|
12850
|
+
* Record query execution event
|
|
12851
|
+
*/
|
|
12852
|
+
recordQueryExecuted(data) {
|
|
12853
|
+
this.recordEvent({
|
|
12854
|
+
eventType: "query_executed" /* QUERY_EXECUTED */,
|
|
12855
|
+
queryText: data.queryText,
|
|
12856
|
+
resultCount: data.resultCount,
|
|
12857
|
+
durationMs: data.durationMs,
|
|
12858
|
+
operationId: data.operationId
|
|
12859
|
+
});
|
|
12860
|
+
}
|
|
12861
|
+
/**
|
|
12862
|
+
* Record error event
|
|
12863
|
+
*/
|
|
12864
|
+
recordError(error, context) {
|
|
12865
|
+
this.recordEvent({
|
|
12866
|
+
eventType: "error_occurred" /* ERROR_OCCURRED */,
|
|
12867
|
+
errorCode: error.code || "UNKNOWN",
|
|
12868
|
+
errorMessage: error.message,
|
|
12869
|
+
stackTrace: error.stack,
|
|
12870
|
+
metadata: context
|
|
12871
|
+
});
|
|
12872
|
+
}
|
|
12873
|
+
/**
|
|
12874
|
+
* Flush all queued events to telemetry endpoints
|
|
12875
|
+
*/
|
|
12876
|
+
async flush() {
|
|
12877
|
+
if (this.eventQueue.length === 0) return;
|
|
12878
|
+
const events = this.eventQueue.splice(0, this.batchSize);
|
|
12879
|
+
const payload = {
|
|
12880
|
+
events: events.map((e) => {
|
|
12881
|
+
const eventWithoutKey = __objRest(e, []);
|
|
12882
|
+
return eventWithoutKey;
|
|
12883
|
+
}),
|
|
12884
|
+
batchId: `${this.projectId}_${Date.now()}`
|
|
12885
|
+
};
|
|
12886
|
+
try {
|
|
12887
|
+
await this.http.post(_TelemetryService.RETRIVORA_TELEMETRY_URL, payload);
|
|
12888
|
+
console.log(`[TelemetryService] Flushed ${events.length} events to Retrivora`);
|
|
12889
|
+
} catch (err) {
|
|
12890
|
+
console.warn("[TelemetryService] Failed to send telemetry to Retrivora:", err.message);
|
|
12891
|
+
this.eventQueue.unshift(...events);
|
|
12892
|
+
}
|
|
12893
|
+
if (this.userTelemetryUrl) {
|
|
12894
|
+
try {
|
|
12895
|
+
await import_axios10.default.post(this.userTelemetryUrl, payload, {
|
|
12896
|
+
timeout: 5e3,
|
|
12897
|
+
headers: {
|
|
12898
|
+
"Content-Type": "application/json",
|
|
12899
|
+
"X-Project-ID": this.projectId
|
|
12900
|
+
}
|
|
12901
|
+
});
|
|
12902
|
+
console.log(`[TelemetryService] Flushed ${events.length} events to user telemetry`);
|
|
12903
|
+
} catch (err) {
|
|
12904
|
+
console.warn("[TelemetryService] Failed to send telemetry to user endpoint:", err.message);
|
|
12905
|
+
}
|
|
12906
|
+
}
|
|
12907
|
+
}
|
|
12908
|
+
/**
|
|
12909
|
+
* Start automatic flush interval
|
|
12910
|
+
*/
|
|
12911
|
+
startAutoFlush() {
|
|
12912
|
+
this.flushTimer = setInterval(() => {
|
|
12913
|
+
this.flush().catch((err) => {
|
|
12914
|
+
console.warn("[TelemetryService] Auto-flush error:", err.message);
|
|
12915
|
+
});
|
|
12916
|
+
}, this.flushIntervalMs);
|
|
12917
|
+
}
|
|
12918
|
+
/**
|
|
12919
|
+
* Stop telemetry service and flush remaining events
|
|
12920
|
+
*/
|
|
12921
|
+
async shutdown() {
|
|
12922
|
+
if (this.flushTimer) {
|
|
12923
|
+
clearInterval(this.flushTimer);
|
|
12924
|
+
}
|
|
12925
|
+
await this.flush();
|
|
12926
|
+
this.enabled = false;
|
|
12927
|
+
}
|
|
12928
|
+
/**
|
|
12929
|
+
* Disable telemetry temporarily
|
|
12930
|
+
*/
|
|
12931
|
+
disable() {
|
|
12932
|
+
this.enabled = false;
|
|
12933
|
+
}
|
|
12934
|
+
/**
|
|
12935
|
+
* Enable telemetry
|
|
12936
|
+
*/
|
|
12937
|
+
enable() {
|
|
12938
|
+
this.enabled = true;
|
|
12939
|
+
}
|
|
12940
|
+
/**
|
|
12941
|
+
* Get current queue size (for debugging)
|
|
12942
|
+
*/
|
|
12943
|
+
getQueueSize() {
|
|
12944
|
+
return this.eventQueue.length;
|
|
12945
|
+
}
|
|
12946
|
+
};
|
|
12947
|
+
_TelemetryService.RETRIVORA_TELEMETRY_URL = "https://www.retrivora.com/api/telemetry";
|
|
12948
|
+
_TelemetryService.USER_TELEMETRY_URL_ENV_KEY = "TELEMETRY_URL";
|
|
12949
|
+
var TelemetryService = _TelemetryService;
|
|
12950
|
+
var globalTelemetryService = null;
|
|
12951
|
+
function getTelemetryService() {
|
|
12952
|
+
return globalTelemetryService;
|
|
12953
|
+
}
|
|
12954
|
+
function initializeTelemetryService(projectId, licenseKey, userTelemetryUrl) {
|
|
12955
|
+
globalTelemetryService = new TelemetryService(projectId, licenseKey, userTelemetryUrl);
|
|
12956
|
+
console.log("[TelemetryService] Initialized for project:", projectId);
|
|
12957
|
+
return globalTelemetryService;
|
|
12958
|
+
}
|
|
12959
|
+
async function shutdownTelemetryService() {
|
|
12960
|
+
if (globalTelemetryService) {
|
|
12961
|
+
await globalTelemetryService.shutdown();
|
|
12962
|
+
globalTelemetryService = null;
|
|
12963
|
+
}
|
|
12964
|
+
}
|
|
12965
|
+
|
|
12966
|
+
// src/LicensedRetrivora.ts
|
|
12967
|
+
var LicensedRetrivora = class {
|
|
12968
|
+
constructor(options) {
|
|
12969
|
+
this.initialized = false;
|
|
12970
|
+
this.licenseKey = options.licenseKey;
|
|
12971
|
+
this.projectId = options.projectId;
|
|
12972
|
+
if (options.enableTelemetry !== false) {
|
|
12973
|
+
initializeTelemetryService(this.projectId, this.licenseKey, options.userTelemetryUrl);
|
|
12974
|
+
}
|
|
12975
|
+
}
|
|
12976
|
+
/**
|
|
12977
|
+
* Initialize the SDK by validating license and fetching config
|
|
12978
|
+
*/
|
|
12979
|
+
generateId() {
|
|
12980
|
+
return `${Date.now()}-${Math.random().toString(36).substring(2, 9)}`;
|
|
12981
|
+
}
|
|
12982
|
+
/**
|
|
12983
|
+
* Initialize the SDK by validating license and fetching config
|
|
12984
|
+
*/
|
|
12985
|
+
async initialize() {
|
|
12986
|
+
if (this.initialized) {
|
|
12987
|
+
console.log("[LicensedRetrivora] Already initialized");
|
|
12988
|
+
return;
|
|
12989
|
+
}
|
|
12990
|
+
console.log("[LicensedRetrivora] Initializing with license key...");
|
|
12991
|
+
const operationId = this.generateId();
|
|
12992
|
+
try {
|
|
12993
|
+
const { llmConfig, embeddingConfig, vectorDbConfig, tierConfig } = await LicenseConfigResolver.resolveFromLicense(this.licenseKey, this.projectId);
|
|
12994
|
+
const telemetry = getTelemetryService();
|
|
12995
|
+
if (telemetry) {
|
|
12996
|
+
telemetry.recordEvent({
|
|
12997
|
+
eventType: "configuration_loaded" /* CONFIGURATION_LOADED */,
|
|
12998
|
+
operationId,
|
|
12999
|
+
metadata: {
|
|
13000
|
+
tier: tierConfig.tier,
|
|
13001
|
+
llmModel: tierConfig.llmModel,
|
|
13002
|
+
embeddingModel: tierConfig.embeddingModel,
|
|
13003
|
+
vectorDb: tierConfig.vectorDb.provider
|
|
13004
|
+
}
|
|
13005
|
+
});
|
|
13006
|
+
}
|
|
13007
|
+
this.ragConfig = {
|
|
13008
|
+
projectId: this.projectId,
|
|
13009
|
+
licenseKey: this.licenseKey,
|
|
13010
|
+
llm: llmConfig,
|
|
13011
|
+
embedding: embeddingConfig,
|
|
13012
|
+
vectorDb: vectorDbConfig,
|
|
13013
|
+
rag: {
|
|
13014
|
+
topK: tierConfig.topK,
|
|
13015
|
+
chunkSize: tierConfig.chunkSize,
|
|
13016
|
+
chunkOverlap: tierConfig.chunkOverlap,
|
|
13017
|
+
scoreThreshold: 0
|
|
13018
|
+
},
|
|
13019
|
+
telemetry: {
|
|
13020
|
+
enabled: true,
|
|
13021
|
+
url: "https://www.retrivora.com/api/telemetry"
|
|
13022
|
+
}
|
|
13023
|
+
};
|
|
13024
|
+
this.pipeline = new Pipeline(this.ragConfig);
|
|
13025
|
+
await this.pipeline.initialize();
|
|
13026
|
+
this.initialized = true;
|
|
13027
|
+
console.log(`[LicensedRetrivora] Initialized successfully for tier: ${tierConfig.tier}`);
|
|
13028
|
+
} catch (error) {
|
|
13029
|
+
const telemetry = getTelemetryService();
|
|
13030
|
+
if (telemetry && error instanceof Error) {
|
|
13031
|
+
telemetry.recordError(error, { operationId });
|
|
13032
|
+
await telemetry.flush();
|
|
13033
|
+
}
|
|
13034
|
+
throw error;
|
|
13035
|
+
}
|
|
13036
|
+
}
|
|
13037
|
+
/**
|
|
13038
|
+
* Ingest documents (upload files to vector database)
|
|
13039
|
+
* Returns success/failure status to end-user
|
|
13040
|
+
*/
|
|
13041
|
+
async ingest(documents) {
|
|
13042
|
+
if (!this.initialized || !this.pipeline) {
|
|
13043
|
+
throw new Error("[LicensedRetrivora] SDK not initialized. Call initialize() first.");
|
|
13044
|
+
}
|
|
13045
|
+
const operationId = this.generateId();
|
|
13046
|
+
const telemetry = getTelemetryService();
|
|
13047
|
+
const startTime = Date.now();
|
|
13048
|
+
try {
|
|
13049
|
+
console.log(`[LicensedRetrivora] Starting ingestion of ${documents.length} document(s)`);
|
|
13050
|
+
const results = await this.pipeline.ingest(documents);
|
|
13051
|
+
const durationMs = Date.now() - startTime;
|
|
13052
|
+
if (telemetry) {
|
|
13053
|
+
for (const result of results) {
|
|
13054
|
+
telemetry.recordDocumentIngested({
|
|
13055
|
+
documentId: String(result.docId),
|
|
13056
|
+
documentName: String(result.docId),
|
|
13057
|
+
documentSize: 0,
|
|
13058
|
+
// TODO: track actual size
|
|
13059
|
+
chunksGenerated: result.chunksIngested,
|
|
13060
|
+
durationMs
|
|
13061
|
+
});
|
|
13062
|
+
}
|
|
13063
|
+
}
|
|
13064
|
+
const successCount = results.length;
|
|
13065
|
+
return {
|
|
13066
|
+
success: successCount > 0,
|
|
13067
|
+
message: `Successfully ingested ${successCount} document(s). Data is now available for search.`,
|
|
13068
|
+
documentIds: results.map((r) => String(r.docId))
|
|
13069
|
+
};
|
|
13070
|
+
} catch (error) {
|
|
13071
|
+
const durationMs = Date.now() - startTime;
|
|
13072
|
+
if (telemetry && error instanceof Error) {
|
|
13073
|
+
telemetry.recordError(error, { operationId, durationMs });
|
|
13074
|
+
await telemetry.flush();
|
|
13075
|
+
}
|
|
13076
|
+
console.error("[LicensedRetrivora] Ingestion failed:", error);
|
|
13077
|
+
throw error;
|
|
13078
|
+
}
|
|
13079
|
+
}
|
|
13080
|
+
/**
|
|
13081
|
+
* Execute a user query and get response
|
|
13082
|
+
* Returns only the response text and sources (abstracted from underlying models)
|
|
13083
|
+
*/
|
|
13084
|
+
async query(queryText, options) {
|
|
13085
|
+
var _a3;
|
|
13086
|
+
if (!this.initialized || !this.pipeline) {
|
|
13087
|
+
throw new Error("[LicensedRetrivora] SDK not initialized. Call initialize() first.");
|
|
13088
|
+
}
|
|
13089
|
+
const operationId = this.generateId();
|
|
13090
|
+
const telemetry = getTelemetryService();
|
|
13091
|
+
const startTime = Date.now();
|
|
13092
|
+
try {
|
|
13093
|
+
console.log(`[LicensedRetrivora] Executing query: "${queryText.substring(0, 100)}..."`);
|
|
13094
|
+
const response = await this.pipeline.runNormalQuery(queryText);
|
|
13095
|
+
const durationMs = Date.now() - startTime;
|
|
13096
|
+
if (telemetry) {
|
|
13097
|
+
telemetry.recordQueryExecuted({
|
|
13098
|
+
queryText,
|
|
13099
|
+
resultCount: ((_a3 = response.sources) == null ? void 0 : _a3.length) || 0,
|
|
13100
|
+
durationMs,
|
|
13101
|
+
operationId
|
|
13102
|
+
});
|
|
13103
|
+
}
|
|
13104
|
+
return {
|
|
13105
|
+
reply: response.reply,
|
|
13106
|
+
sources: response.sources
|
|
13107
|
+
};
|
|
13108
|
+
} catch (error) {
|
|
13109
|
+
const durationMs = Date.now() - startTime;
|
|
13110
|
+
if (telemetry && error instanceof Error) {
|
|
13111
|
+
telemetry.recordError(error, { operationId, durationMs });
|
|
13112
|
+
await telemetry.flush();
|
|
13113
|
+
}
|
|
13114
|
+
console.error("[LicensedRetrivora] Query failed:", error);
|
|
13115
|
+
throw error;
|
|
13116
|
+
}
|
|
13117
|
+
}
|
|
13118
|
+
/**
|
|
13119
|
+
* Get license tier information (for UI display if needed)
|
|
13120
|
+
*/
|
|
13121
|
+
async getTierInfo() {
|
|
13122
|
+
if (!this.ragConfig) {
|
|
13123
|
+
throw new Error("[LicensedRetrivora] SDK not initialized.");
|
|
13124
|
+
}
|
|
13125
|
+
return {
|
|
13126
|
+
tier: "Standard",
|
|
13127
|
+
// TODO: fetch from tier config
|
|
13128
|
+
model: this.ragConfig.llm.model,
|
|
13129
|
+
embeddingModel: this.ragConfig.embedding.model
|
|
13130
|
+
};
|
|
13131
|
+
}
|
|
13132
|
+
/**
|
|
13133
|
+
* Cleanup and shutdown
|
|
13134
|
+
*/
|
|
13135
|
+
async shutdown() {
|
|
13136
|
+
await shutdownTelemetryService();
|
|
13137
|
+
this.initialized = false;
|
|
13138
|
+
console.log("[LicensedRetrivora] Shutdown complete");
|
|
13139
|
+
}
|
|
13140
|
+
/**
|
|
13141
|
+
* Check if SDK is initialized
|
|
13142
|
+
*/
|
|
13143
|
+
isInitialized() {
|
|
13144
|
+
return this.initialized;
|
|
13145
|
+
}
|
|
13146
|
+
/**
|
|
13147
|
+
* Get current RAG configuration (for debugging)
|
|
13148
|
+
*/
|
|
13149
|
+
getConfig() {
|
|
13150
|
+
return this.ragConfig;
|
|
13151
|
+
}
|
|
13152
|
+
};
|
|
13153
|
+
async function createRetrivora(options) {
|
|
13154
|
+
const retrivora = new LicensedRetrivora(options);
|
|
13155
|
+
await retrivora.initialize();
|
|
13156
|
+
return retrivora;
|
|
13157
|
+
}
|
|
12389
13158
|
// Annotate the CommonJS export names for ESM import in node:
|
|
12390
13159
|
0 && (module.exports = {
|
|
12391
13160
|
AnthropicProvider,
|
|
@@ -12405,13 +13174,16 @@ var LicenseValidator = _LicenseValidator;
|
|
|
12405
13174
|
EmbeddingFailedException,
|
|
12406
13175
|
EmbeddingStrategy,
|
|
12407
13176
|
EmbeddingStrategyResolver,
|
|
13177
|
+
EventType,
|
|
12408
13178
|
GroqProvider,
|
|
12409
13179
|
IntentClassifier,
|
|
12410
13180
|
LLMFactory,
|
|
12411
13181
|
LLM_PROFILES,
|
|
13182
|
+
LicenseConfigResolver,
|
|
12412
13183
|
LicenseValidationError,
|
|
12413
13184
|
LicenseValidator,
|
|
12414
13185
|
LicenseVerifier,
|
|
13186
|
+
LicensedRetrivora,
|
|
12415
13187
|
MilvusProvider,
|
|
12416
13188
|
MixedRendererStrategy,
|
|
12417
13189
|
MongoDBProvider,
|
|
@@ -12444,6 +13216,7 @@ var LicenseValidator = _LicenseValidator;
|
|
|
12444
13216
|
SDKVersionUnsupportedError,
|
|
12445
13217
|
SDK_VERSION,
|
|
12446
13218
|
TableRendererStrategy,
|
|
13219
|
+
TelemetryService,
|
|
12447
13220
|
TextRendererStrategy,
|
|
12448
13221
|
UniversalLLMAdapter,
|
|
12449
13222
|
UniversalVectorProvider,
|
|
@@ -12459,13 +13232,19 @@ var LicenseValidator = _LicenseValidator;
|
|
|
12459
13232
|
createHistoryHandler,
|
|
12460
13233
|
createIngestHandler,
|
|
12461
13234
|
createRagHandler,
|
|
13235
|
+
createRetrivora,
|
|
12462
13236
|
createSessionsHandler,
|
|
12463
13237
|
createStreamHandler,
|
|
12464
13238
|
createUploadHandler,
|
|
12465
13239
|
decideVisualization,
|
|
12466
13240
|
getRagConfig,
|
|
13241
|
+
getRuntimeConfig,
|
|
13242
|
+
getTelemetryService,
|
|
13243
|
+
initializeTelemetryService,
|
|
13244
|
+
injectRuntimeConfig,
|
|
12467
13245
|
normalizeProjectSettings,
|
|
12468
13246
|
projectSettingsToUiConfig,
|
|
13247
|
+
shutdownTelemetryService,
|
|
12469
13248
|
sseErrorFrame,
|
|
12470
13249
|
sseFrame,
|
|
12471
13250
|
sseMetaFrame,
|