@retrivora-ai/rag-engine 2.3.6 → 2.3.7
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.js +121 -63
- package/dist/handlers/index.mjs +121 -63
- package/dist/index.d.mts +2 -2
- package/dist/index.d.ts +2 -2
- package/dist/index.js +8 -8
- package/dist/index.mjs +8 -8
- package/dist/server.d.mts +251 -5
- package/dist/server.d.ts +251 -5
- package/dist/server.js +733 -65
- package/dist/server.mjs +723 -65
- package/package.json +1 -1
- package/src/LicensedRetrivora.ts +273 -0
- package/src/config/LicenseConfigResolver.ts +296 -0
- package/src/config/serverConfig.ts +74 -14
- package/src/core/LicenseVerifier.ts +7 -7
- package/src/handlers/index.ts +4 -0
- package/src/index.ts +9 -0
- package/src/llm/providers/UniversalLLMAdapter.ts +67 -12
- package/src/server.ts +23 -1
- package/src/telemetry/TelemetryService.ts +330 -0
package/dist/server.mjs
CHANGED
|
@@ -315,7 +315,7 @@ var init_package = __esm({
|
|
|
315
315
|
"package.json"() {
|
|
316
316
|
package_default = {
|
|
317
317
|
name: "@retrivora-ai/rag-engine",
|
|
318
|
-
version: "2.3.
|
|
318
|
+
version: "2.3.7",
|
|
319
319
|
description: "Retrivora AI is a plug-and-play AI engine for RAG chat experiences \u2014 generic vector DB + LLM provider, embeddable or standalone.",
|
|
320
320
|
author: "Abhinav Alkuchi",
|
|
321
321
|
license: "UNLICENSED",
|
|
@@ -2833,13 +2833,13 @@ LicenseVerifier.CACHE_TTL_MS = 60 * 1e3;
|
|
|
2833
2833
|
// In production, this matches the private key held by Retrivora SaaS.
|
|
2834
2834
|
// Rotate this key only when the signing private key is replaced.
|
|
2835
2835
|
LicenseVerifier.PUBLIC_KEY = `-----BEGIN PUBLIC KEY-----
|
|
2836
|
-
|
|
2837
|
-
|
|
2838
|
-
|
|
2839
|
-
|
|
2840
|
-
|
|
2841
|
-
|
|
2842
|
-
|
|
2836
|
+
MIIBIjANBgkqhkiG9w0BAQEFAAOCAQ8AMIIBCgKCAQEAyKvvOSYdCimG3b236ebV
|
|
2837
|
+
jpG88xQiU8dSiaMahtBJDf4w0AewRj7hMNgmeZ1wyTOj8kVgeGBOolp1Z0QmTr6O
|
|
2838
|
+
Tj4EDQ/zjsg12If7hSf3NiwLHCYmMLslyK0aaP6PQoTrYkBv3GNdkMecrIjKCijb
|
|
2839
|
+
6VvDLLF3X696melTVM0z/d2e50BW2AlRw/rf1EqYi10d0BcPo5zje0XETr/WGmqu
|
|
2840
|
+
sDiXtsP5MlwkL9X7RQY2uovRa+l/vOAqAfdmJ+OzXuk5P7mDUPb+gCtKnoDbb1tr
|
|
2841
|
+
6UAu733dkUnetAcMqyT3fNPBLO66DCc6m9rGCYYAaG7piMEDwG0/ZySZBFbgllJc
|
|
2842
|
+
6QIDAQAB
|
|
2843
2843
|
-----END PUBLIC KEY-----`;
|
|
2844
2844
|
|
|
2845
2845
|
// src/config/constants.ts
|
|
@@ -2888,6 +2888,20 @@ var PROVIDERS_WITH_EMBEDDINGS = [
|
|
|
2888
2888
|
var UI_BORDER_RADIUS_OPTIONS = ["none", "sm", "md", "lg", "xl", "full"];
|
|
2889
2889
|
|
|
2890
2890
|
// src/config/serverConfig.ts
|
|
2891
|
+
var _runtimeConfig = null;
|
|
2892
|
+
function injectRuntimeConfig(config) {
|
|
2893
|
+
_runtimeConfig = config;
|
|
2894
|
+
console.log("[serverConfig] \u2705 Runtime tier config injected:", {
|
|
2895
|
+
tier: config.tier,
|
|
2896
|
+
llmModel: config.llmModel,
|
|
2897
|
+
embeddingModel: config.embeddingModel,
|
|
2898
|
+
llmBaseUrl: config.llmBaseUrl,
|
|
2899
|
+
hasLitellmKey: !!config.litellmApiKey
|
|
2900
|
+
});
|
|
2901
|
+
}
|
|
2902
|
+
function getRuntimeConfig() {
|
|
2903
|
+
return _runtimeConfig;
|
|
2904
|
+
}
|
|
2891
2905
|
function readString(env, name) {
|
|
2892
2906
|
var _a3;
|
|
2893
2907
|
const value = (_a3 = env[name]) == null ? void 0 : _a3.trim();
|
|
@@ -2914,7 +2928,7 @@ function getRagConfig(baseConfig, env = process.env) {
|
|
|
2914
2928
|
return getEnvConfig(env, baseConfig);
|
|
2915
2929
|
}
|
|
2916
2930
|
function getEnvConfig(env = process.env, base) {
|
|
2917
|
-
var _a3, _b, _c, _d, _e, _f, _g2, _h, _i, _j, _k, _l, _m, _n, _o, _p, _q, _r, _s, _t, _u, _v, _w, _x, _y, _z, _A, _B, _C, _D, _E, _F, _G, _H, _I, _J, _K, _L, _M, _N, _O, _P, _Q, _R, _S, _T, _U, _V, _W, _X, _Y, _Z, __, _$, _aa, _ba, _ca, _da, _ea, _fa, _ga, _ha, _ia, _ja, _ka, _la, _ma, _na, _oa, _pa, _qa, _ra, _sa, _ta, _ua, _va, _wa, _xa, _ya, _za, _Aa, _Ba, _Ca, _Da, _Ea, _Fa, _Ga, _Ha, _Ia, _Ja, _Ka, _La, _Ma, _Na, _Oa, _Pa, _Qa, _Ra, _Sa, _Ta, _Ua, _Va, _Wa, _Xa, _Ya, _Za, __a, _$a, _ab, _bb, _cb, _db, _eb, _fb, _gb, _hb, _ib, _jb, _kb, _lb, _mb, _nb, _ob, _pb, _qb, _rb, _sb, _tb, _ub, _vb, _wb, _xb, _yb, _zb, _Ab, _Bb, _Cb, _Db, _Eb, _Fb, _Gb, _Hb
|
|
2931
|
+
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;
|
|
2918
2932
|
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;
|
|
2919
2933
|
const jwtProjectId = (() => {
|
|
2920
2934
|
if (!licenseKey) return void 0;
|
|
@@ -3006,25 +3020,35 @@ function getEnvConfig(env = process.env, base) {
|
|
|
3006
3020
|
return true;
|
|
3007
3021
|
}
|
|
3008
3022
|
})();
|
|
3009
|
-
const
|
|
3010
|
-
const
|
|
3011
|
-
const
|
|
3012
|
-
const
|
|
3013
|
-
const
|
|
3014
|
-
const
|
|
3015
|
-
const
|
|
3016
|
-
const
|
|
3017
|
-
const
|
|
3018
|
-
const
|
|
3019
|
-
|
|
3020
|
-
|
|
3021
|
-
|
|
3023
|
+
const tierBasedLLMModel = isFreeTier2 ? "llama-3.1-8b-instant" : "llama-3.3-70b-versatile";
|
|
3024
|
+
const tierBasedEmbeddingModel = isFreeTier2 ? "text-embedding-004" : "text-embedding-004";
|
|
3025
|
+
const defaultGatewayUrl = "https://llm.retrivora.com/api/v1";
|
|
3026
|
+
const rt = _runtimeConfig;
|
|
3027
|
+
const defaultLlmProvider = "universal_rest";
|
|
3028
|
+
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;
|
|
3029
|
+
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;
|
|
3030
|
+
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;
|
|
3031
|
+
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;
|
|
3032
|
+
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";
|
|
3033
|
+
console.log("[serverConfig] \u{1F527} LLM Configuration:", {
|
|
3034
|
+
baseUrl: llmBaseUrl,
|
|
3035
|
+
model: llmModel,
|
|
3036
|
+
provider: llmProvider,
|
|
3037
|
+
hasApiKey: !!llmApiKey,
|
|
3038
|
+
source: (rt == null ? void 0 : rt.llmModel) ? "runtime-injected" : "env/fallback"
|
|
3039
|
+
});
|
|
3040
|
+
const defaultEmbeddingProvider = "universal_rest";
|
|
3041
|
+
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;
|
|
3042
|
+
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;
|
|
3043
|
+
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;
|
|
3044
|
+
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;
|
|
3045
|
+
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";
|
|
3022
3046
|
return __spreadProps(__spreadValues({
|
|
3023
3047
|
projectId,
|
|
3024
3048
|
licenseKey,
|
|
3025
3049
|
vectorDb: {
|
|
3026
3050
|
provider: vectorProvider,
|
|
3027
|
-
indexName: (
|
|
3051
|
+
indexName: (_fb = (_eb = readString(env, "VECTOR_DB_INDEX")) != null ? _eb : vectorDbOptions.indexName) != null ? _fb : "rag-index",
|
|
3028
3052
|
options: vectorDbOptions
|
|
3029
3053
|
},
|
|
3030
3054
|
llm: {
|
|
@@ -3054,30 +3078,30 @@ function getEnvConfig(env = process.env, base) {
|
|
|
3054
3078
|
}
|
|
3055
3079
|
},
|
|
3056
3080
|
ui: {
|
|
3057
|
-
title: (
|
|
3058
|
-
subtitle: (
|
|
3059
|
-
primaryColor: (
|
|
3060
|
-
accentColor: (
|
|
3061
|
-
logoUrl: (
|
|
3062
|
-
placeholder: (
|
|
3063
|
-
showSources: ((
|
|
3064
|
-
welcomeMessage: (
|
|
3065
|
-
visualStyle: (
|
|
3066
|
-
borderRadius: (
|
|
3067
|
-
allowUpload: ((
|
|
3081
|
+
title: (_hb = (_gb = readString(env, "NEXT_PUBLIC_UI_TITLE")) != null ? _gb : readString(env, "UI_TITLE")) != null ? _hb : "AI Assistant",
|
|
3082
|
+
subtitle: (_jb = (_ib = readString(env, "NEXT_PUBLIC_UI_SUBTITLE")) != null ? _ib : readString(env, "UI_SUBTITLE")) != null ? _jb : "Powered by RAG",
|
|
3083
|
+
primaryColor: (_lb = (_kb = readString(env, "NEXT_PUBLIC_PRIMARY_COLOR")) != null ? _kb : readString(env, "UI_PRIMARY_COLOR")) != null ? _lb : "#10b981",
|
|
3084
|
+
accentColor: (_nb = (_mb = readString(env, "NEXT_PUBLIC_ACCENT_COLOR")) != null ? _mb : readString(env, "UI_ACCENT_COLOR")) != null ? _nb : "#3b82f6",
|
|
3085
|
+
logoUrl: (_ob = readString(env, "NEXT_PUBLIC_LOGO_URL")) != null ? _ob : readString(env, "UI_LOGO_URL"),
|
|
3086
|
+
placeholder: (_qb = (_pb = readString(env, "NEXT_PUBLIC_PLACEHOLDER")) != null ? _pb : readString(env, "UI_PLACEHOLDER")) != null ? _qb : "Ask me anything\u2026",
|
|
3087
|
+
showSources: ((_sb = (_rb = readString(env, "NEXT_PUBLIC_SHOW_SOURCES")) != null ? _rb : readString(env, "UI_SHOW_SOURCES")) != null ? _sb : "true") !== "false",
|
|
3088
|
+
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.",
|
|
3089
|
+
visualStyle: (_wb = (_vb = readString(env, "NEXT_PUBLIC_UI_VISUAL_STYLE")) != null ? _vb : readString(env, "UI_VISUAL_STYLE")) != null ? _wb : "glass",
|
|
3090
|
+
borderRadius: (_yb = (_xb = readString(env, "NEXT_PUBLIC_UI_BORDER_RADIUS")) != null ? _xb : readString(env, "UI_BORDER_RADIUS")) != null ? _yb : "xl",
|
|
3091
|
+
allowUpload: ((_Ab = (_zb = readString(env, "NEXT_PUBLIC_ALLOW_UPLOAD")) != null ? _zb : readString(env, "UI_ALLOW_UPLOAD")) != null ? _Ab : "false") === "true"
|
|
3068
3092
|
},
|
|
3069
3093
|
rag: {
|
|
3070
3094
|
topK: readNumber(env, "RAG_TOP_K", 5),
|
|
3071
3095
|
scoreThreshold: readNumber(env, "RAG_SCORE_THRESHOLD", 0),
|
|
3072
3096
|
chunkSize: readNumber(env, "RAG_CHUNK_SIZE", 1e3),
|
|
3073
3097
|
chunkOverlap: readNumber(env, "RAG_CHUNK_OVERLAP", 200),
|
|
3074
|
-
filterableFields: (
|
|
3098
|
+
filterableFields: (_Bb = readString(env, "RAG_FILTERABLE_FIELDS")) == null ? void 0 : _Bb.split(",").map((f) => f.trim()),
|
|
3075
3099
|
// Query pipeline toggles — read from .env.local
|
|
3076
3100
|
useQueryTransformation: readString(env, "RAG_USE_QUERY_TRANSFORMATION") === "true",
|
|
3077
3101
|
useReranking: readString(env, "RAG_USE_RERANKING") === "true",
|
|
3078
3102
|
useGraphRetrieval: readString(env, "RAG_USE_GRAPH_RETRIEVAL") === "true",
|
|
3079
|
-
architecture: (
|
|
3080
|
-
chunkingStrategy: (
|
|
3103
|
+
architecture: (_Cb = readString(env, "RAG_ARCHITECTURE")) != null ? _Cb : "simple",
|
|
3104
|
+
chunkingStrategy: (_Db = readString(env, "RAG_CHUNKING_STRATEGY")) != null ? _Db : "recursive",
|
|
3081
3105
|
uiMapping: (() => {
|
|
3082
3106
|
const raw = readString(env, "RAG_UI_MAPPING");
|
|
3083
3107
|
if (!raw) return void 0;
|
|
@@ -3090,7 +3114,7 @@ function getEnvConfig(env = process.env, base) {
|
|
|
3090
3114
|
},
|
|
3091
3115
|
telemetry: {
|
|
3092
3116
|
enabled: telemetryEnabled,
|
|
3093
|
-
url: (
|
|
3117
|
+
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"
|
|
3094
3118
|
}
|
|
3095
3119
|
}, readString(env, "GRAPH_DB_PROVIDER") ? {
|
|
3096
3120
|
graphDb: {
|
|
@@ -3614,8 +3638,8 @@ var OllamaProvider = class {
|
|
|
3614
3638
|
const baseUrl = config.baseUrl || "http://localhost:11434";
|
|
3615
3639
|
const modelName = config.model;
|
|
3616
3640
|
try {
|
|
3617
|
-
const
|
|
3618
|
-
const { data } = await
|
|
3641
|
+
const axios11 = (await import("axios")).default;
|
|
3642
|
+
const { data } = await axios11.get(`${baseUrl}/api/tags`);
|
|
3619
3643
|
const models = data.models || [];
|
|
3620
3644
|
const hasModel = models.some((m) => m.name === modelName || m.name.startsWith(`${modelName}:`));
|
|
3621
3645
|
return {
|
|
@@ -4447,7 +4471,7 @@ var UniversalLLMAdapter = class {
|
|
|
4447
4471
|
});
|
|
4448
4472
|
}
|
|
4449
4473
|
async chat(messages, context) {
|
|
4450
|
-
var _a3, _b, _c, _d, _e;
|
|
4474
|
+
var _a3, _b, _c, _d, _e, _f, _g2, _h, _i, _j;
|
|
4451
4475
|
const path2 = (_a3 = this.opts.chatPath) != null ? _a3 : "/chat/completions";
|
|
4452
4476
|
const safeMessages = (Array.isArray(messages) ? messages : []).filter((m) => Boolean(m && typeof m === "object")).map((m) => ({
|
|
4453
4477
|
role: m.role || "user",
|
|
@@ -4477,16 +4501,27 @@ ${context != null ? context : "None"}` },
|
|
|
4477
4501
|
};
|
|
4478
4502
|
}
|
|
4479
4503
|
try {
|
|
4504
|
+
console.debug(`[UniversalLLMAdapter] POST ${this.baseUrl}${path2}`);
|
|
4505
|
+
console.debug(`[UniversalLLMAdapter] Model: ${this.model}`);
|
|
4506
|
+
console.debug(`[UniversalLLMAdapter] Auth: Bearer ${((_b = this.apiKey) == null ? void 0 : _b.substring(0, 20)) || "none"}...`);
|
|
4480
4507
|
const { data: data2 } = await this.http.post(path2, payload);
|
|
4481
|
-
const extractPath2 = (
|
|
4482
|
-
const result2 = (
|
|
4508
|
+
const extractPath2 = (_c = this.opts.responseExtractPath) != null ? _c : "choices[0].message.content";
|
|
4509
|
+
const result2 = (_d = resolvePath(data2, extractPath2)) != null ? _d : extractContent(data2);
|
|
4483
4510
|
if (result2 !== void 0) {
|
|
4484
4511
|
return String(result2);
|
|
4485
4512
|
}
|
|
4486
4513
|
} catch (httpErr) {
|
|
4487
|
-
|
|
4488
|
-
|
|
4514
|
+
console.error("[UniversalLLMAdapter] \u274C HTTP chat request failed:", {
|
|
4515
|
+
status: (_e = httpErr == null ? void 0 : httpErr.response) == null ? void 0 : _e.status,
|
|
4516
|
+
statusText: (_f = httpErr == null ? void 0 : httpErr.response) == null ? void 0 : _f.statusText,
|
|
4517
|
+
url: (_g2 = httpErr == null ? void 0 : httpErr.config) == null ? void 0 : _g2.url,
|
|
4518
|
+
errorData: (_h = httpErr == null ? void 0 : httpErr.response) == null ? void 0 : _h.data,
|
|
4519
|
+
message: httpErr == null ? void 0 : httpErr.message
|
|
4520
|
+
});
|
|
4521
|
+
const _g3 = globalThis;
|
|
4522
|
+
const dispatch = _g3.__retrivoraDispatchChat;
|
|
4489
4523
|
if (typeof dispatch === "function") {
|
|
4524
|
+
console.debug("[UniversalLLMAdapter] \u{1F504} Attempting in-process fallback dispatch");
|
|
4490
4525
|
const res = await dispatch({
|
|
4491
4526
|
model: this.model,
|
|
4492
4527
|
messages: formattedMessages,
|
|
@@ -4501,8 +4536,8 @@ ${context != null ? context : "None"}` },
|
|
|
4501
4536
|
throw httpErr;
|
|
4502
4537
|
}
|
|
4503
4538
|
const { data } = await this.http.post(path2, payload);
|
|
4504
|
-
const extractPath = (
|
|
4505
|
-
const result = (
|
|
4539
|
+
const extractPath = (_i = this.opts.responseExtractPath) != null ? _i : "choices[0].message.content";
|
|
4540
|
+
const result = (_j = resolvePath(data, extractPath)) != null ? _j : extractContent(data);
|
|
4506
4541
|
if (result === void 0) {
|
|
4507
4542
|
throw new Error(`[UniversalLLMAdapter] Could not extract text from path '${extractPath}' in response.`);
|
|
4508
4543
|
}
|
|
@@ -4641,36 +4676,70 @@ ${context != null ? context : "None"}` },
|
|
|
4641
4676
|
});
|
|
4642
4677
|
}
|
|
4643
4678
|
async embed(text) {
|
|
4644
|
-
var _a3, _b, _c, _d, _e;
|
|
4679
|
+
var _a3, _b, _c, _d, _e, _f, _g2;
|
|
4645
4680
|
const path2 = (_a3 = this.opts.embedPath) != null ? _a3 : "/embeddings";
|
|
4646
4681
|
const payload = this.opts.embedPayloadTemplate ? buildPayload(this.opts.embedPayloadTemplate, { input: text, model: this.model }) : { input: text, model: this.model };
|
|
4647
4682
|
try {
|
|
4648
|
-
const { data
|
|
4649
|
-
const
|
|
4650
|
-
const
|
|
4651
|
-
if (Array.isArray(
|
|
4652
|
-
|
|
4653
|
-
|
|
4654
|
-
|
|
4683
|
+
const { data } = await this.http.post(path2, payload);
|
|
4684
|
+
const extractPath = (_b = this.opts.embedExtractPath) != null ? _b : "data[0].embedding";
|
|
4685
|
+
const vector = resolvePath(data, extractPath);
|
|
4686
|
+
if (Array.isArray(vector)) return vector;
|
|
4687
|
+
console.warn(
|
|
4688
|
+
`[UniversalLLMAdapter] Embedding API returned unexpected format for path '${extractPath}'. Response:`,
|
|
4689
|
+
data
|
|
4690
|
+
);
|
|
4691
|
+
} catch (err) {
|
|
4692
|
+
console.warn(
|
|
4693
|
+
`[UniversalLLMAdapter] HTTP embedding request failed: ${(err == null ? void 0 : err.message) || err}`,
|
|
4694
|
+
{ path: path2, model: this.model }
|
|
4695
|
+
);
|
|
4696
|
+
const _g3 = globalThis;
|
|
4697
|
+
const dispatchEmbed = _g3.__retrivoraDispatchEmbedding;
|
|
4655
4698
|
if (typeof dispatchEmbed === "function") {
|
|
4656
|
-
|
|
4657
|
-
|
|
4658
|
-
|
|
4699
|
+
try {
|
|
4700
|
+
const res = await dispatchEmbed({ input: text, model: this.model }, this.apiKey);
|
|
4701
|
+
if ((_d = (_c = res == null ? void 0 : res.data) == null ? void 0 : _c[0]) == null ? void 0 : _d.embedding) {
|
|
4702
|
+
return res.data[0].embedding;
|
|
4703
|
+
}
|
|
4704
|
+
} catch (dispatchErr) {
|
|
4705
|
+
console.warn("[UniversalLLMAdapter] In-process dispatch embedding failed:", dispatchErr);
|
|
4659
4706
|
}
|
|
4660
4707
|
}
|
|
4661
4708
|
}
|
|
4662
|
-
|
|
4663
|
-
|
|
4664
|
-
|
|
4665
|
-
|
|
4666
|
-
|
|
4709
|
+
try {
|
|
4710
|
+
const { data } = await this.http.post(path2, payload);
|
|
4711
|
+
const extractPath = (_e = this.opts.embedExtractPath) != null ? _e : "data[0].embedding";
|
|
4712
|
+
const vector = resolvePath(data, extractPath);
|
|
4713
|
+
if (Array.isArray(vector)) {
|
|
4714
|
+
return vector;
|
|
4715
|
+
}
|
|
4716
|
+
console.error(
|
|
4717
|
+
`[UniversalLLMAdapter] Retry embedding failed: unexpected response format for path '${extractPath}'. Response:`,
|
|
4718
|
+
data
|
|
4719
|
+
);
|
|
4720
|
+
throw new Error(
|
|
4721
|
+
`[UniversalLLMAdapter] Could not extract embedding vector. Expected array at '${extractPath}', got: ${typeof vector}. Response keys: ${Object.keys(data || {})}.`
|
|
4722
|
+
);
|
|
4723
|
+
} catch (err) {
|
|
4724
|
+
console.error(
|
|
4725
|
+
`[UniversalLLMAdapter] Both embedding attempts failed. Path: ${path2}, Model: ${this.model}`,
|
|
4726
|
+
{ 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 }
|
|
4727
|
+
);
|
|
4728
|
+
throw new Error(
|
|
4729
|
+
`[UniversalLLMAdapter] Failed to generate embedding after 2 attempts: ${(err == null ? void 0 : err.message) || err}`
|
|
4730
|
+
);
|
|
4667
4731
|
}
|
|
4668
|
-
return vector;
|
|
4669
4732
|
}
|
|
4670
4733
|
async batchEmbed(texts) {
|
|
4671
4734
|
const results = [];
|
|
4672
4735
|
for (const text of texts) {
|
|
4673
|
-
|
|
4736
|
+
try {
|
|
4737
|
+
const vector = await this.embed(text);
|
|
4738
|
+
results.push(vector);
|
|
4739
|
+
} catch (err) {
|
|
4740
|
+
console.warn(`[UniversalLLMAdapter] batchEmbed failed for text (first 50 chars): ${text.slice(0, 50)}...`, err);
|
|
4741
|
+
throw err;
|
|
4742
|
+
}
|
|
4674
4743
|
}
|
|
4675
4744
|
return results;
|
|
4676
4745
|
}
|
|
@@ -11721,6 +11790,7 @@ function createUploadHandler(configOrPlugin, options) {
|
|
|
11721
11790
|
const plugin = getOrCreatePlugin(configOrPlugin);
|
|
11722
11791
|
const onAuthorize = options == null ? void 0 : options.onAuthorize;
|
|
11723
11792
|
return async function POST(req, context) {
|
|
11793
|
+
console.log("Upload handler invoked");
|
|
11724
11794
|
const authResult = await checkAuth(req, onAuthorize);
|
|
11725
11795
|
if (authResult) return authResult;
|
|
11726
11796
|
const config = plugin.getConfig();
|
|
@@ -11729,6 +11799,7 @@ function createUploadHandler(configOrPlugin, options) {
|
|
|
11729
11799
|
try {
|
|
11730
11800
|
const formData = await req.formData();
|
|
11731
11801
|
const files = formData.getAll("files");
|
|
11802
|
+
console.log("Files received for upload:", files.map((f) => f.name));
|
|
11732
11803
|
const namespace = formData.get("namespace") || void 0;
|
|
11733
11804
|
const dimensionRaw = formData.get("dimension");
|
|
11734
11805
|
const dimension = dimensionRaw ? parseInt(dimensionRaw, 10) : void 0;
|
|
@@ -12282,6 +12353,583 @@ var _LicenseValidator = class _LicenseValidator {
|
|
|
12282
12353
|
};
|
|
12283
12354
|
_LicenseValidator.SUCCESS_CACHE_TTL_MS = 5 * 60 * 1e3;
|
|
12284
12355
|
var LicenseValidator = _LicenseValidator;
|
|
12356
|
+
|
|
12357
|
+
// src/config/LicenseConfigResolver.ts
|
|
12358
|
+
import axios9 from "axios";
|
|
12359
|
+
var LicenseConfigResolver = class {
|
|
12360
|
+
/**
|
|
12361
|
+
* Validate and resolve configuration from license key
|
|
12362
|
+
* @param licenseKey JWT token from Retrivora (format: rtv_eyJ...)
|
|
12363
|
+
* @param projectId Workspace identifier
|
|
12364
|
+
* @returns Resolved LLM and embedding configs with provider credentials
|
|
12365
|
+
*/
|
|
12366
|
+
static async resolveFromLicense(licenseKey, projectId) {
|
|
12367
|
+
const cacheKey = `${licenseKey}:${projectId}`;
|
|
12368
|
+
const cached = this.configCache.get(cacheKey);
|
|
12369
|
+
if (cached && Date.now() - cached.timestamp < this.CACHE_TTL_MS) {
|
|
12370
|
+
console.log("[LicenseConfigResolver] Using cached config for", projectId);
|
|
12371
|
+
return this.buildConfigs(cached.config, cached.credentials, licenseKey, projectId);
|
|
12372
|
+
}
|
|
12373
|
+
console.log("[LicenseConfigResolver] Fetching tier config from Retrivora...");
|
|
12374
|
+
const tierConfig = await this.fetchTierConfig(licenseKey, projectId);
|
|
12375
|
+
console.log("[LicenseConfigResolver] Fetching provider credentials from Retrivora...");
|
|
12376
|
+
const credentials = await this.fetchProviderCredentials(licenseKey, projectId);
|
|
12377
|
+
this.configCache.set(cacheKey, { config: tierConfig, credentials, timestamp: Date.now() });
|
|
12378
|
+
console.log("[LicenseConfigResolver] \u2705 Successfully resolved config from Retrivora:", {
|
|
12379
|
+
tier: tierConfig.tier,
|
|
12380
|
+
llmModel: tierConfig.llmModel,
|
|
12381
|
+
embeddingModel: tierConfig.embeddingModel
|
|
12382
|
+
});
|
|
12383
|
+
return this.buildConfigs(tierConfig, credentials, licenseKey, projectId);
|
|
12384
|
+
}
|
|
12385
|
+
/**
|
|
12386
|
+
* Fetch tier configuration from Retrivora config API
|
|
12387
|
+
*/
|
|
12388
|
+
static async fetchTierConfig(licenseKey, projectId) {
|
|
12389
|
+
try {
|
|
12390
|
+
const response = await axios9.post(
|
|
12391
|
+
this.RETRIVORA_CONFIG_URL,
|
|
12392
|
+
{ licenseKey, projectId },
|
|
12393
|
+
{
|
|
12394
|
+
headers: {
|
|
12395
|
+
"Content-Type": "application/json",
|
|
12396
|
+
Authorization: `Bearer ${licenseKey}`,
|
|
12397
|
+
"X-License-Key": licenseKey,
|
|
12398
|
+
"X-Project-ID": projectId
|
|
12399
|
+
},
|
|
12400
|
+
timeout: 1e4
|
|
12401
|
+
}
|
|
12402
|
+
);
|
|
12403
|
+
if (!response.data.success || !response.data.config) {
|
|
12404
|
+
throw new Error(
|
|
12405
|
+
`[LicenseConfigResolver] Config API returned error: ${response.data.error || response.data.message}`
|
|
12406
|
+
);
|
|
12407
|
+
}
|
|
12408
|
+
console.log(`[LicenseConfigResolver] Resolved tier: ${response.data.config.tier}`);
|
|
12409
|
+
return response.data.config;
|
|
12410
|
+
} catch (err) {
|
|
12411
|
+
console.error("[LicenseConfigResolver] Failed to fetch config:", err.message);
|
|
12412
|
+
throw new Error(
|
|
12413
|
+
`[LicenseConfigResolver] Could not validate license key or fetch tier configuration: ${err.message}`
|
|
12414
|
+
);
|
|
12415
|
+
}
|
|
12416
|
+
}
|
|
12417
|
+
/**
|
|
12418
|
+
* Fetch provider credentials from Retrivora credentials API
|
|
12419
|
+
*/
|
|
12420
|
+
static async fetchProviderCredentials(licenseKey, projectId) {
|
|
12421
|
+
try {
|
|
12422
|
+
const response = await axios9.post(
|
|
12423
|
+
this.RETRIVORA_CREDENTIALS_URL,
|
|
12424
|
+
{ licenseKey, projectId },
|
|
12425
|
+
{
|
|
12426
|
+
headers: {
|
|
12427
|
+
"Content-Type": "application/json",
|
|
12428
|
+
Authorization: `Bearer ${licenseKey}`,
|
|
12429
|
+
"X-License-Key": licenseKey,
|
|
12430
|
+
"X-Project-ID": projectId
|
|
12431
|
+
},
|
|
12432
|
+
timeout: 1e4
|
|
12433
|
+
}
|
|
12434
|
+
);
|
|
12435
|
+
if (!response.data.success || !response.data.credentials) {
|
|
12436
|
+
throw new Error(
|
|
12437
|
+
`[LicenseConfigResolver] Credentials API returned error: ${response.data.error || response.data.message}`
|
|
12438
|
+
);
|
|
12439
|
+
}
|
|
12440
|
+
console.log(`[LicenseConfigResolver] Retrieved provider credentials for project: ${projectId}`);
|
|
12441
|
+
return response.data.credentials;
|
|
12442
|
+
} catch (err) {
|
|
12443
|
+
console.error("[LicenseConfigResolver] Failed to fetch credentials:", err.message);
|
|
12444
|
+
throw new Error(
|
|
12445
|
+
`[LicenseConfigResolver] Could not fetch provider credentials: ${err.message}`
|
|
12446
|
+
);
|
|
12447
|
+
}
|
|
12448
|
+
}
|
|
12449
|
+
/**
|
|
12450
|
+
* Build LLM, embedding, and vector DB configs from tier and credentials
|
|
12451
|
+
*/
|
|
12452
|
+
static buildConfigs(tierConfig, credentials, licenseKey, projectId) {
|
|
12453
|
+
let llmProvider = "gemini";
|
|
12454
|
+
let llmApiKey = credentials.geminiApiKey || licenseKey;
|
|
12455
|
+
if (tierConfig.llmModel.includes("gpt")) {
|
|
12456
|
+
llmProvider = "openai";
|
|
12457
|
+
} else if (tierConfig.llmModel.includes("groq") || tierConfig.llmModel.includes("llama")) {
|
|
12458
|
+
llmProvider = "groq";
|
|
12459
|
+
llmApiKey = credentials.groqApiKey || licenseKey;
|
|
12460
|
+
}
|
|
12461
|
+
const llmConfig = {
|
|
12462
|
+
provider: llmProvider,
|
|
12463
|
+
model: tierConfig.llmModel,
|
|
12464
|
+
apiKey: llmApiKey,
|
|
12465
|
+
maxTokens: tierConfig.maxTokens,
|
|
12466
|
+
temperature: 0.7,
|
|
12467
|
+
options: {}
|
|
12468
|
+
};
|
|
12469
|
+
const embeddingConfig = {
|
|
12470
|
+
provider: "gemini",
|
|
12471
|
+
model: tierConfig.embeddingModel,
|
|
12472
|
+
apiKey: credentials.geminiApiKey || licenseKey,
|
|
12473
|
+
dimensions: tierConfig.embeddingDimensions,
|
|
12474
|
+
options: {}
|
|
12475
|
+
};
|
|
12476
|
+
const vectorDbConfig = {
|
|
12477
|
+
provider: tierConfig.vectorDb.provider,
|
|
12478
|
+
indexName: tierConfig.vectorDb.indexName,
|
|
12479
|
+
options: this.getVectorDbOptions(tierConfig.vectorDb.provider, projectId, credentials)
|
|
12480
|
+
};
|
|
12481
|
+
return { llmConfig, embeddingConfig, vectorDbConfig, tierConfig, credentials };
|
|
12482
|
+
}
|
|
12483
|
+
/**
|
|
12484
|
+
* Get provider-specific vector DB options
|
|
12485
|
+
*/
|
|
12486
|
+
static getVectorDbOptions(provider, projectId, credentials) {
|
|
12487
|
+
switch (provider) {
|
|
12488
|
+
case "pinecone":
|
|
12489
|
+
return {
|
|
12490
|
+
apiKey: credentials.pineconeApiKey,
|
|
12491
|
+
indexName: `retrivora-${projectId}`
|
|
12492
|
+
};
|
|
12493
|
+
case "pgvector":
|
|
12494
|
+
case "postgresql":
|
|
12495
|
+
return {
|
|
12496
|
+
tables: [`documents_${projectId}`]
|
|
12497
|
+
};
|
|
12498
|
+
case "mongodb":
|
|
12499
|
+
return {
|
|
12500
|
+
database: `retrivora_${projectId}`,
|
|
12501
|
+
collection: `vectors_${projectId}`
|
|
12502
|
+
};
|
|
12503
|
+
case "qdrant":
|
|
12504
|
+
return {
|
|
12505
|
+
collection: `retrivora_${projectId}`
|
|
12506
|
+
};
|
|
12507
|
+
default:
|
|
12508
|
+
return {};
|
|
12509
|
+
}
|
|
12510
|
+
}
|
|
12511
|
+
/**
|
|
12512
|
+
* Clear configuration cache (useful for testing or manual refresh)
|
|
12513
|
+
*/
|
|
12514
|
+
static clearCache() {
|
|
12515
|
+
this.configCache.clear();
|
|
12516
|
+
console.log("[LicenseConfigResolver] Configuration cache cleared");
|
|
12517
|
+
}
|
|
12518
|
+
/**
|
|
12519
|
+
* Get cache stats for debugging
|
|
12520
|
+
*/
|
|
12521
|
+
static getCacheStats() {
|
|
12522
|
+
return {
|
|
12523
|
+
size: this.configCache.size,
|
|
12524
|
+
entries: Array.from(this.configCache.keys())
|
|
12525
|
+
};
|
|
12526
|
+
}
|
|
12527
|
+
};
|
|
12528
|
+
LicenseConfigResolver.RETRIVORA_CONFIG_URL = "https://www.retrivora.com/api/v1/config";
|
|
12529
|
+
LicenseConfigResolver.RETRIVORA_CREDENTIALS_URL = "https://www.retrivora.com/api/v1/credentials";
|
|
12530
|
+
LicenseConfigResolver.CACHE_TTL_MS = 36e5;
|
|
12531
|
+
// 1 hour
|
|
12532
|
+
LicenseConfigResolver.configCache = /* @__PURE__ */ new Map();
|
|
12533
|
+
|
|
12534
|
+
// src/telemetry/TelemetryService.ts
|
|
12535
|
+
import axios10 from "axios";
|
|
12536
|
+
var EventType = /* @__PURE__ */ ((EventType2) => {
|
|
12537
|
+
EventType2["EMBEDDING_GENERATED"] = "embedding_generated";
|
|
12538
|
+
EventType2["LLM_CHAT_COMPLETION"] = "llm_chat_completion";
|
|
12539
|
+
EventType2["DOCUMENT_INGESTED"] = "document_ingested";
|
|
12540
|
+
EventType2["QUERY_EXECUTED"] = "query_executed";
|
|
12541
|
+
EventType2["ERROR_OCCURRED"] = "error_occurred";
|
|
12542
|
+
EventType2["CONFIGURATION_LOADED"] = "configuration_loaded";
|
|
12543
|
+
return EventType2;
|
|
12544
|
+
})(EventType || {});
|
|
12545
|
+
var _TelemetryService = class _TelemetryService {
|
|
12546
|
+
constructor(projectId, licenseKey, userTelemetryUrl) {
|
|
12547
|
+
this.batchSize = 10;
|
|
12548
|
+
this.flushIntervalMs = 3e4;
|
|
12549
|
+
// 30 seconds
|
|
12550
|
+
this.eventQueue = [];
|
|
12551
|
+
this.enabled = true;
|
|
12552
|
+
this.projectId = projectId;
|
|
12553
|
+
this.licenseKey = licenseKey;
|
|
12554
|
+
this.userTelemetryUrl = userTelemetryUrl || process.env[_TelemetryService.USER_TELEMETRY_URL_ENV_KEY];
|
|
12555
|
+
this.http = axios10.create({
|
|
12556
|
+
timeout: 5e3,
|
|
12557
|
+
headers: {
|
|
12558
|
+
"Content-Type": "application/json",
|
|
12559
|
+
"X-License-Key": licenseKey,
|
|
12560
|
+
"X-Project-ID": projectId
|
|
12561
|
+
}
|
|
12562
|
+
});
|
|
12563
|
+
this.startAutoFlush();
|
|
12564
|
+
}
|
|
12565
|
+
/**
|
|
12566
|
+
* Record a telemetry event
|
|
12567
|
+
*/
|
|
12568
|
+
recordEvent(event) {
|
|
12569
|
+
if (!this.enabled) return;
|
|
12570
|
+
const _a3 = event, { licenseKey } = _a3, safeEvent = __objRest(_a3, ["licenseKey"]);
|
|
12571
|
+
const completeEvent = __spreadValues({
|
|
12572
|
+
eventType: event.eventType || "error_occurred" /* ERROR_OCCURRED */,
|
|
12573
|
+
projectId: this.projectId,
|
|
12574
|
+
timestamp: event.timestamp || Date.now()
|
|
12575
|
+
}, safeEvent);
|
|
12576
|
+
this.eventQueue.push(completeEvent);
|
|
12577
|
+
if (this.eventQueue.length >= this.batchSize) {
|
|
12578
|
+
this.flush().catch((err) => {
|
|
12579
|
+
console.warn("[TelemetryService] Flush error:", err.message);
|
|
12580
|
+
});
|
|
12581
|
+
}
|
|
12582
|
+
}
|
|
12583
|
+
/**
|
|
12584
|
+
* Record LLM completion event
|
|
12585
|
+
*/
|
|
12586
|
+
recordLLMCompletion(data) {
|
|
12587
|
+
this.recordEvent({
|
|
12588
|
+
eventType: "llm_chat_completion" /* LLM_CHAT_COMPLETION */,
|
|
12589
|
+
model: data.model,
|
|
12590
|
+
inputTokens: data.inputTokens,
|
|
12591
|
+
outputTokens: data.outputTokens,
|
|
12592
|
+
totalTokens: data.inputTokens + data.outputTokens,
|
|
12593
|
+
durationMs: data.durationMs,
|
|
12594
|
+
operationId: data.operationId,
|
|
12595
|
+
metadata: data.metadata
|
|
12596
|
+
});
|
|
12597
|
+
}
|
|
12598
|
+
/**
|
|
12599
|
+
* Record embedding generation event
|
|
12600
|
+
*/
|
|
12601
|
+
recordEmbeddingGenerated(data) {
|
|
12602
|
+
this.recordEvent({
|
|
12603
|
+
eventType: "embedding_generated" /* EMBEDDING_GENERATED */,
|
|
12604
|
+
embeddingModel: data.embeddingModel,
|
|
12605
|
+
vectorDimensions: data.vectorDimensions,
|
|
12606
|
+
textLength: data.textLength,
|
|
12607
|
+
durationMs: data.durationMs,
|
|
12608
|
+
operationId: data.operationId
|
|
12609
|
+
});
|
|
12610
|
+
}
|
|
12611
|
+
/**
|
|
12612
|
+
* Record document ingestion event
|
|
12613
|
+
*/
|
|
12614
|
+
recordDocumentIngested(data) {
|
|
12615
|
+
this.recordEvent({
|
|
12616
|
+
eventType: "document_ingested" /* DOCUMENT_INGESTED */,
|
|
12617
|
+
documentId: data.documentId,
|
|
12618
|
+
documentName: data.documentName,
|
|
12619
|
+
documentSize: data.documentSize,
|
|
12620
|
+
chunksGenerated: data.chunksGenerated,
|
|
12621
|
+
durationMs: data.durationMs
|
|
12622
|
+
});
|
|
12623
|
+
}
|
|
12624
|
+
/**
|
|
12625
|
+
* Record query execution event
|
|
12626
|
+
*/
|
|
12627
|
+
recordQueryExecuted(data) {
|
|
12628
|
+
this.recordEvent({
|
|
12629
|
+
eventType: "query_executed" /* QUERY_EXECUTED */,
|
|
12630
|
+
queryText: data.queryText,
|
|
12631
|
+
resultCount: data.resultCount,
|
|
12632
|
+
durationMs: data.durationMs,
|
|
12633
|
+
operationId: data.operationId
|
|
12634
|
+
});
|
|
12635
|
+
}
|
|
12636
|
+
/**
|
|
12637
|
+
* Record error event
|
|
12638
|
+
*/
|
|
12639
|
+
recordError(error, context) {
|
|
12640
|
+
this.recordEvent({
|
|
12641
|
+
eventType: "error_occurred" /* ERROR_OCCURRED */,
|
|
12642
|
+
errorCode: error.code || "UNKNOWN",
|
|
12643
|
+
errorMessage: error.message,
|
|
12644
|
+
stackTrace: error.stack,
|
|
12645
|
+
metadata: context
|
|
12646
|
+
});
|
|
12647
|
+
}
|
|
12648
|
+
/**
|
|
12649
|
+
* Flush all queued events to telemetry endpoints
|
|
12650
|
+
*/
|
|
12651
|
+
async flush() {
|
|
12652
|
+
if (this.eventQueue.length === 0) return;
|
|
12653
|
+
const events = this.eventQueue.splice(0, this.batchSize);
|
|
12654
|
+
const payload = {
|
|
12655
|
+
events: events.map((e) => {
|
|
12656
|
+
const eventWithoutKey = __objRest(e, []);
|
|
12657
|
+
return eventWithoutKey;
|
|
12658
|
+
}),
|
|
12659
|
+
batchId: `${this.projectId}_${Date.now()}`
|
|
12660
|
+
};
|
|
12661
|
+
try {
|
|
12662
|
+
await this.http.post(_TelemetryService.RETRIVORA_TELEMETRY_URL, payload);
|
|
12663
|
+
console.log(`[TelemetryService] Flushed ${events.length} events to Retrivora`);
|
|
12664
|
+
} catch (err) {
|
|
12665
|
+
console.warn("[TelemetryService] Failed to send telemetry to Retrivora:", err.message);
|
|
12666
|
+
this.eventQueue.unshift(...events);
|
|
12667
|
+
}
|
|
12668
|
+
if (this.userTelemetryUrl) {
|
|
12669
|
+
try {
|
|
12670
|
+
await axios10.post(this.userTelemetryUrl, payload, {
|
|
12671
|
+
timeout: 5e3,
|
|
12672
|
+
headers: {
|
|
12673
|
+
"Content-Type": "application/json",
|
|
12674
|
+
"X-Project-ID": this.projectId
|
|
12675
|
+
}
|
|
12676
|
+
});
|
|
12677
|
+
console.log(`[TelemetryService] Flushed ${events.length} events to user telemetry`);
|
|
12678
|
+
} catch (err) {
|
|
12679
|
+
console.warn("[TelemetryService] Failed to send telemetry to user endpoint:", err.message);
|
|
12680
|
+
}
|
|
12681
|
+
}
|
|
12682
|
+
}
|
|
12683
|
+
/**
|
|
12684
|
+
* Start automatic flush interval
|
|
12685
|
+
*/
|
|
12686
|
+
startAutoFlush() {
|
|
12687
|
+
this.flushTimer = setInterval(() => {
|
|
12688
|
+
this.flush().catch((err) => {
|
|
12689
|
+
console.warn("[TelemetryService] Auto-flush error:", err.message);
|
|
12690
|
+
});
|
|
12691
|
+
}, this.flushIntervalMs);
|
|
12692
|
+
}
|
|
12693
|
+
/**
|
|
12694
|
+
* Stop telemetry service and flush remaining events
|
|
12695
|
+
*/
|
|
12696
|
+
async shutdown() {
|
|
12697
|
+
if (this.flushTimer) {
|
|
12698
|
+
clearInterval(this.flushTimer);
|
|
12699
|
+
}
|
|
12700
|
+
await this.flush();
|
|
12701
|
+
this.enabled = false;
|
|
12702
|
+
}
|
|
12703
|
+
/**
|
|
12704
|
+
* Disable telemetry temporarily
|
|
12705
|
+
*/
|
|
12706
|
+
disable() {
|
|
12707
|
+
this.enabled = false;
|
|
12708
|
+
}
|
|
12709
|
+
/**
|
|
12710
|
+
* Enable telemetry
|
|
12711
|
+
*/
|
|
12712
|
+
enable() {
|
|
12713
|
+
this.enabled = true;
|
|
12714
|
+
}
|
|
12715
|
+
/**
|
|
12716
|
+
* Get current queue size (for debugging)
|
|
12717
|
+
*/
|
|
12718
|
+
getQueueSize() {
|
|
12719
|
+
return this.eventQueue.length;
|
|
12720
|
+
}
|
|
12721
|
+
};
|
|
12722
|
+
_TelemetryService.RETRIVORA_TELEMETRY_URL = "https://www.retrivora.com/api/telemetry";
|
|
12723
|
+
_TelemetryService.USER_TELEMETRY_URL_ENV_KEY = "TELEMETRY_URL";
|
|
12724
|
+
var TelemetryService = _TelemetryService;
|
|
12725
|
+
var globalTelemetryService = null;
|
|
12726
|
+
function getTelemetryService() {
|
|
12727
|
+
return globalTelemetryService;
|
|
12728
|
+
}
|
|
12729
|
+
function initializeTelemetryService(projectId, licenseKey, userTelemetryUrl) {
|
|
12730
|
+
globalTelemetryService = new TelemetryService(projectId, licenseKey, userTelemetryUrl);
|
|
12731
|
+
console.log("[TelemetryService] Initialized for project:", projectId);
|
|
12732
|
+
return globalTelemetryService;
|
|
12733
|
+
}
|
|
12734
|
+
async function shutdownTelemetryService() {
|
|
12735
|
+
if (globalTelemetryService) {
|
|
12736
|
+
await globalTelemetryService.shutdown();
|
|
12737
|
+
globalTelemetryService = null;
|
|
12738
|
+
}
|
|
12739
|
+
}
|
|
12740
|
+
|
|
12741
|
+
// src/LicensedRetrivora.ts
|
|
12742
|
+
var LicensedRetrivora = class {
|
|
12743
|
+
constructor(options) {
|
|
12744
|
+
this.initialized = false;
|
|
12745
|
+
this.licenseKey = options.licenseKey;
|
|
12746
|
+
this.projectId = options.projectId;
|
|
12747
|
+
if (options.enableTelemetry !== false) {
|
|
12748
|
+
initializeTelemetryService(this.projectId, this.licenseKey, options.userTelemetryUrl);
|
|
12749
|
+
}
|
|
12750
|
+
}
|
|
12751
|
+
/**
|
|
12752
|
+
* Initialize the SDK by validating license and fetching config
|
|
12753
|
+
*/
|
|
12754
|
+
generateId() {
|
|
12755
|
+
return `${Date.now()}-${Math.random().toString(36).substring(2, 9)}`;
|
|
12756
|
+
}
|
|
12757
|
+
/**
|
|
12758
|
+
* Initialize the SDK by validating license and fetching config
|
|
12759
|
+
*/
|
|
12760
|
+
async initialize() {
|
|
12761
|
+
if (this.initialized) {
|
|
12762
|
+
console.log("[LicensedRetrivora] Already initialized");
|
|
12763
|
+
return;
|
|
12764
|
+
}
|
|
12765
|
+
console.log("[LicensedRetrivora] Initializing with license key...");
|
|
12766
|
+
const operationId = this.generateId();
|
|
12767
|
+
try {
|
|
12768
|
+
const { llmConfig, embeddingConfig, vectorDbConfig, tierConfig } = await LicenseConfigResolver.resolveFromLicense(this.licenseKey, this.projectId);
|
|
12769
|
+
const telemetry = getTelemetryService();
|
|
12770
|
+
if (telemetry) {
|
|
12771
|
+
telemetry.recordEvent({
|
|
12772
|
+
eventType: "configuration_loaded" /* CONFIGURATION_LOADED */,
|
|
12773
|
+
operationId,
|
|
12774
|
+
metadata: {
|
|
12775
|
+
tier: tierConfig.tier,
|
|
12776
|
+
llmModel: tierConfig.llmModel,
|
|
12777
|
+
embeddingModel: tierConfig.embeddingModel,
|
|
12778
|
+
vectorDb: tierConfig.vectorDb.provider
|
|
12779
|
+
}
|
|
12780
|
+
});
|
|
12781
|
+
}
|
|
12782
|
+
this.ragConfig = {
|
|
12783
|
+
projectId: this.projectId,
|
|
12784
|
+
licenseKey: this.licenseKey,
|
|
12785
|
+
llm: llmConfig,
|
|
12786
|
+
embedding: embeddingConfig,
|
|
12787
|
+
vectorDb: vectorDbConfig,
|
|
12788
|
+
rag: {
|
|
12789
|
+
topK: tierConfig.topK,
|
|
12790
|
+
chunkSize: tierConfig.chunkSize,
|
|
12791
|
+
chunkOverlap: tierConfig.chunkOverlap,
|
|
12792
|
+
scoreThreshold: 0
|
|
12793
|
+
},
|
|
12794
|
+
telemetry: {
|
|
12795
|
+
enabled: true,
|
|
12796
|
+
url: "https://www.retrivora.com/api/telemetry"
|
|
12797
|
+
}
|
|
12798
|
+
};
|
|
12799
|
+
this.pipeline = new Pipeline(this.ragConfig);
|
|
12800
|
+
await this.pipeline.initialize();
|
|
12801
|
+
this.initialized = true;
|
|
12802
|
+
console.log(`[LicensedRetrivora] Initialized successfully for tier: ${tierConfig.tier}`);
|
|
12803
|
+
} catch (error) {
|
|
12804
|
+
const telemetry = getTelemetryService();
|
|
12805
|
+
if (telemetry && error instanceof Error) {
|
|
12806
|
+
telemetry.recordError(error, { operationId });
|
|
12807
|
+
await telemetry.flush();
|
|
12808
|
+
}
|
|
12809
|
+
throw error;
|
|
12810
|
+
}
|
|
12811
|
+
}
|
|
12812
|
+
/**
|
|
12813
|
+
* Ingest documents (upload files to vector database)
|
|
12814
|
+
* Returns success/failure status to end-user
|
|
12815
|
+
*/
|
|
12816
|
+
async ingest(documents) {
|
|
12817
|
+
if (!this.initialized || !this.pipeline) {
|
|
12818
|
+
throw new Error("[LicensedRetrivora] SDK not initialized. Call initialize() first.");
|
|
12819
|
+
}
|
|
12820
|
+
const operationId = this.generateId();
|
|
12821
|
+
const telemetry = getTelemetryService();
|
|
12822
|
+
const startTime = Date.now();
|
|
12823
|
+
try {
|
|
12824
|
+
console.log(`[LicensedRetrivora] Starting ingestion of ${documents.length} document(s)`);
|
|
12825
|
+
const results = await this.pipeline.ingest(documents);
|
|
12826
|
+
const durationMs = Date.now() - startTime;
|
|
12827
|
+
if (telemetry) {
|
|
12828
|
+
for (const result of results) {
|
|
12829
|
+
telemetry.recordDocumentIngested({
|
|
12830
|
+
documentId: String(result.docId),
|
|
12831
|
+
documentName: String(result.docId),
|
|
12832
|
+
documentSize: 0,
|
|
12833
|
+
// TODO: track actual size
|
|
12834
|
+
chunksGenerated: result.chunksIngested,
|
|
12835
|
+
durationMs
|
|
12836
|
+
});
|
|
12837
|
+
}
|
|
12838
|
+
}
|
|
12839
|
+
const successCount = results.length;
|
|
12840
|
+
return {
|
|
12841
|
+
success: successCount > 0,
|
|
12842
|
+
message: `Successfully ingested ${successCount} document(s). Data is now available for search.`,
|
|
12843
|
+
documentIds: results.map((r) => String(r.docId))
|
|
12844
|
+
};
|
|
12845
|
+
} catch (error) {
|
|
12846
|
+
const durationMs = Date.now() - startTime;
|
|
12847
|
+
if (telemetry && error instanceof Error) {
|
|
12848
|
+
telemetry.recordError(error, { operationId, durationMs });
|
|
12849
|
+
await telemetry.flush();
|
|
12850
|
+
}
|
|
12851
|
+
console.error("[LicensedRetrivora] Ingestion failed:", error);
|
|
12852
|
+
throw error;
|
|
12853
|
+
}
|
|
12854
|
+
}
|
|
12855
|
+
/**
|
|
12856
|
+
* Execute a user query and get response
|
|
12857
|
+
* Returns only the response text and sources (abstracted from underlying models)
|
|
12858
|
+
*/
|
|
12859
|
+
async query(queryText, options) {
|
|
12860
|
+
var _a3;
|
|
12861
|
+
if (!this.initialized || !this.pipeline) {
|
|
12862
|
+
throw new Error("[LicensedRetrivora] SDK not initialized. Call initialize() first.");
|
|
12863
|
+
}
|
|
12864
|
+
const operationId = this.generateId();
|
|
12865
|
+
const telemetry = getTelemetryService();
|
|
12866
|
+
const startTime = Date.now();
|
|
12867
|
+
try {
|
|
12868
|
+
console.log(`[LicensedRetrivora] Executing query: "${queryText.substring(0, 100)}..."`);
|
|
12869
|
+
const response = await this.pipeline.runNormalQuery(queryText);
|
|
12870
|
+
const durationMs = Date.now() - startTime;
|
|
12871
|
+
if (telemetry) {
|
|
12872
|
+
telemetry.recordQueryExecuted({
|
|
12873
|
+
queryText,
|
|
12874
|
+
resultCount: ((_a3 = response.sources) == null ? void 0 : _a3.length) || 0,
|
|
12875
|
+
durationMs,
|
|
12876
|
+
operationId
|
|
12877
|
+
});
|
|
12878
|
+
}
|
|
12879
|
+
return {
|
|
12880
|
+
reply: response.reply,
|
|
12881
|
+
sources: response.sources
|
|
12882
|
+
};
|
|
12883
|
+
} catch (error) {
|
|
12884
|
+
const durationMs = Date.now() - startTime;
|
|
12885
|
+
if (telemetry && error instanceof Error) {
|
|
12886
|
+
telemetry.recordError(error, { operationId, durationMs });
|
|
12887
|
+
await telemetry.flush();
|
|
12888
|
+
}
|
|
12889
|
+
console.error("[LicensedRetrivora] Query failed:", error);
|
|
12890
|
+
throw error;
|
|
12891
|
+
}
|
|
12892
|
+
}
|
|
12893
|
+
/**
|
|
12894
|
+
* Get license tier information (for UI display if needed)
|
|
12895
|
+
*/
|
|
12896
|
+
async getTierInfo() {
|
|
12897
|
+
if (!this.ragConfig) {
|
|
12898
|
+
throw new Error("[LicensedRetrivora] SDK not initialized.");
|
|
12899
|
+
}
|
|
12900
|
+
return {
|
|
12901
|
+
tier: "Standard",
|
|
12902
|
+
// TODO: fetch from tier config
|
|
12903
|
+
model: this.ragConfig.llm.model,
|
|
12904
|
+
embeddingModel: this.ragConfig.embedding.model
|
|
12905
|
+
};
|
|
12906
|
+
}
|
|
12907
|
+
/**
|
|
12908
|
+
* Cleanup and shutdown
|
|
12909
|
+
*/
|
|
12910
|
+
async shutdown() {
|
|
12911
|
+
await shutdownTelemetryService();
|
|
12912
|
+
this.initialized = false;
|
|
12913
|
+
console.log("[LicensedRetrivora] Shutdown complete");
|
|
12914
|
+
}
|
|
12915
|
+
/**
|
|
12916
|
+
* Check if SDK is initialized
|
|
12917
|
+
*/
|
|
12918
|
+
isInitialized() {
|
|
12919
|
+
return this.initialized;
|
|
12920
|
+
}
|
|
12921
|
+
/**
|
|
12922
|
+
* Get current RAG configuration (for debugging)
|
|
12923
|
+
*/
|
|
12924
|
+
getConfig() {
|
|
12925
|
+
return this.ragConfig;
|
|
12926
|
+
}
|
|
12927
|
+
};
|
|
12928
|
+
async function createRetrivora(options) {
|
|
12929
|
+
const retrivora = new LicensedRetrivora(options);
|
|
12930
|
+
await retrivora.initialize();
|
|
12931
|
+
return retrivora;
|
|
12932
|
+
}
|
|
12285
12933
|
export {
|
|
12286
12934
|
AnthropicProvider,
|
|
12287
12935
|
AuthenticationException,
|
|
@@ -12300,13 +12948,16 @@ export {
|
|
|
12300
12948
|
EmbeddingFailedException,
|
|
12301
12949
|
EmbeddingStrategy,
|
|
12302
12950
|
EmbeddingStrategyResolver,
|
|
12951
|
+
EventType,
|
|
12303
12952
|
GroqProvider,
|
|
12304
12953
|
IntentClassifier,
|
|
12305
12954
|
LLMFactory,
|
|
12306
12955
|
LLM_PROFILES,
|
|
12956
|
+
LicenseConfigResolver,
|
|
12307
12957
|
LicenseValidationError,
|
|
12308
12958
|
LicenseValidator,
|
|
12309
12959
|
LicenseVerifier,
|
|
12960
|
+
LicensedRetrivora,
|
|
12310
12961
|
MilvusProvider,
|
|
12311
12962
|
MixedRendererStrategy,
|
|
12312
12963
|
MongoDBProvider,
|
|
@@ -12339,6 +12990,7 @@ export {
|
|
|
12339
12990
|
SDKVersionUnsupportedError,
|
|
12340
12991
|
SDK_VERSION,
|
|
12341
12992
|
TableRendererStrategy,
|
|
12993
|
+
TelemetryService,
|
|
12342
12994
|
TextRendererStrategy,
|
|
12343
12995
|
UniversalLLMAdapter,
|
|
12344
12996
|
UniversalVectorProvider,
|
|
@@ -12354,13 +13006,19 @@ export {
|
|
|
12354
13006
|
createHistoryHandler,
|
|
12355
13007
|
createIngestHandler,
|
|
12356
13008
|
createRagHandler,
|
|
13009
|
+
createRetrivora,
|
|
12357
13010
|
createSessionsHandler,
|
|
12358
13011
|
createStreamHandler,
|
|
12359
13012
|
createUploadHandler,
|
|
12360
13013
|
decideVisualization,
|
|
12361
13014
|
getRagConfig,
|
|
13015
|
+
getRuntimeConfig,
|
|
13016
|
+
getTelemetryService,
|
|
13017
|
+
initializeTelemetryService,
|
|
13018
|
+
injectRuntimeConfig,
|
|
12362
13019
|
normalizeProjectSettings,
|
|
12363
13020
|
projectSettingsToUiConfig,
|
|
13021
|
+
shutdownTelemetryService,
|
|
12364
13022
|
sseErrorFrame,
|
|
12365
13023
|
sseFrame,
|
|
12366
13024
|
sseMetaFrame,
|